diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
deleted file mode 100644
index 0dc8d3051bada4d83961684d22ea99a56b2fb4c6..0000000000000000000000000000000000000000
--- a/.gitlab-ci.yml
+++ /dev/null
@@ -1,17 +0,0 @@
-job1:
-  script:
-    - date
-    - pwd
-    - echo $OAI_TEST_CASE_GROUP
-    - echo $MACHINELIST
-    - echo $MACHINELISTGENERIC
-    - echo $RESULT_DIR
-    - echo $NRUNS_LTE_SOFTMODEM
-    - source oaienv
-    - rm -rf cmake_targets/autotests/log
-    - mkdir cmake_targets/autotests/log
-    - cd cmake_targets/autotests/v2
-    - python main.py
-    - date
-  only:
-    - triggers
diff --git a/README.txt b/README.txt
index edd233830fb125cb581eeaf5092311fee5cfed16..2713e831681da50dbf036d3e6896a1365ea79006 100644
--- a/README.txt
+++ b/README.txt
@@ -9,26 +9,36 @@ Please see NOTICE.txt for third party software that is included in the sources.
 The OpenAirInterface (OAI) software is composed of the following parts: 
 
 openairinterface5g
-├── cmake_targets: build utilities to compile (simulation, emulation and real-time platforms), and generated build files
-├── common : some common OAI utilities, other tools can be found at openair2/UTILS
+├── ci-scripts: Meta-scripts used by the OSA CI process. Contains also configuration files used day-to-day by CI.
+├── cmake_targets: Build utilities to compile (simulation, emulation and real-time platforms), and generated build files
+├── common : Some common OAI utilities, other tools can be found at openair2/UTILS
+├── doc : Contains an up-to-date feature set list
 ├── LICENSE
-├── maketags : script to generate emacs tags
-├── openair1 : 3GPP LTE Rel-10 PHY layer + PHY RF simulation and a subset of Rel 12 Features.
-├── openair2 :3GPP LTE Rel-10 RLC/MAC/PDCP/RRC/X2AP implementation. 
+├── maketags : Script to generate emacs tags
+├── nfapi : Contains the NFAPI code. A local Readme file provides more details.
+├── openair1 : 3GPP LTE Rel-10/12 PHY layer + PHY RF simulation. A local Readme file provides more details.
+├── openair2 : 3GPP LTE Rel-10 RLC/MAC/PDCP/RRC/X2AP implementation.
+    ├── COMMON
+    ├── DOCS
+    ├── ENB_APP
     ├── LAYER2/RLC/ with the following subdirectories: UM_v9.3.0, TM_v9.3.0, and AM_v9.3.0. 
-    ├── LAYER2/PDCP/PDCP_v10.1.0. 
-    ├── RRC/LITE
+    ├── LAYER2/PDCP/PDCP_v10.1.0.
+    ├── NETWORK_DRIVER
     ├── PHY_INTERFACE
+    ├── RRC/LITE
+    ├── UTIL
     ├── X2AP
-    ├── ENB_APP 
 ├── openair3: 3GPP LTE Rel10 for S1AP, NAS GTPV1-U for both ENB and UE.
+    ├── COMMON
+    ├── DOCS
     ├── GTPV1-U
-    ├── NAS 
+    ├── NAS
     ├── S1AP
     ├── SCTP
     ├── SECU
     ├── UDP
-└── targets: top level wrapper for unitary simulation for PHY channels, system-level emulation (eNB-UE with and without S1), and realtime eNB and UE and RRH GW.
+    ├── UTILS
+└── targets: Top-level wrappers for unitary simulation for PHY channels, system-level emulation (eNB-UE with and without S1), and realtime eNB and UE and RRH GW.
 
 
 RELEASE NOTES:
@@ -44,3 +54,11 @@ v0.6 -> RRH functionality, UE greatly improved, better TDD support,
         a lot of bugs fixed. WARNING: oaisim in PHY abstraction mode does not
         work, you need to use v0.5.2 for that.
 v0.6.1 -> Mostly bugfixes. This is the last version without NFAPI.
+v1.0.0 -> January 2019. This version first implements the architectural split described in doc/oai_lte_enb_func_split_arch.png picture.
+            Only FAPI, nFAPI and IF4.5 interfaces are implemented.
+            Repository tree structure prepares future integrations of features such as LTE-M, nbIOT or 5G-NR.
+            Preliminary X2 support has been implemented.
+            S1-flex has been introduced.
+            New tools: config library, telnet server, ...
+            A lot of bugfixes and a proper automated Continuous Integration process validates contributions.
+v1.0.1 -> February 2019: Bug fix for the UE L1 simulator.
diff --git a/ci-scripts/Jenkinsfile-gitlab b/ci-scripts/Jenkinsfile-gitlab
index 54ceca9603244dc27cdc15ca65ee596c66d6641e..f59208ed8b7a20b5bad87b0feb976307e7462047 100644
--- a/ci-scripts/Jenkinsfile-gitlab
+++ b/ci-scripts/Jenkinsfile-gitlab
@@ -31,6 +31,7 @@ def sendSocialMediaMessage(pipeChannel, pipeColor, pipeMessage) {
 }
 
 def doRedHatBuild = false
+def doFlexranCtrlTest = false
 
 pipeline {
     agent {
@@ -40,7 +41,7 @@ pipeline {
         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-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-FDD-Band7", "Test-TDD-Band40", "Test-IF4p5-FDD-Band7", "Test-IF4p5-TDD-Band40"])
         ansiColor('xterm')
     }
 
@@ -69,6 +70,12 @@ pipeline {
                     } else {
                         doRedHatBuild = false
                     }
+                    if (params.FlexRanRtcGitLabRepository_Credentials != null) {
+                        doFlexranCtrlTest = true
+                    }
+                    if (fileExists("flexran")) {
+                        sh "rm -Rf flexran > /dev/null 2>&1"
+                    }
                 }
             }
         }
@@ -97,12 +104,25 @@ pipeline {
                     } else {
                         echo "Git Branch      is ${GIT_BRANCH}"
                         echo "Git Commit      is ${GIT_COMMIT}"
+                        sh "git log -n1 --pretty=format:\"%s\" > .git/CI_COMMIT_MSG"
 
                         sh "zip -r -qq localZip.zip ."
                         // Running astyle options on all C/H files in the repository
                         // For the moment, there is no fail criteria. Just a notification of number of files that do not follow
                         sh "./ci-scripts/checkCodingFormattingRules.sh"
                     }
+                    if (doFlexranCtrlTest) {
+                        sh "mkdir flexran"
+                        dir ('flexran') {
+                            withCredentials([
+                                [$class: 'UsernamePasswordMultiBinding', credentialsId: "${params.FlexRanRtcGitLabRepository_Credentials}", usernameVariable: 'git_username', passwordVariable: 'git_password']
+                                ]) {
+                                sh "git clone https://${git_username}:${git_password}@gitlab.eurecom.fr/flexran/flexran-rtc.git . > ../git_clone.log 2>&1"
+                            }
+                            sh "sed -i -e 's#add-apt-repository.*cleishm.*neo4j#add-apt-repository ppa:cleishm/neo4j -y#' -e 's#libneo4j-client-dev#libneo4j-client-dev -y#' tools/install_dependencies"
+                            sh "zip -r -qq flexran.zip ."
+                        }
+                    }
                 }
             }
             post {
@@ -115,10 +135,10 @@ pipeline {
             }
         }
 
-        stage ("Start VM -- cppcheck") {
+        stage ("Start VM -- basic-sim") {
             steps {
                 timeout (time: 5, unit: 'MINUTES') {
-                    sh "./ci-scripts/createVM.sh --variant cppcheck --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
+                    sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant basic-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
                 }
             }
         }
@@ -126,39 +146,47 @@ pipeline {
         stage ("Start VM -- enb-usrp") {
             steps {
                 timeout (time: 5, unit: 'MINUTES') {
-                    sh "./ci-scripts/createVM.sh --variant enb-usrp --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
+                    sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant enb-usrp --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
                 }
             }
         }
 
-        stage ("Start VM -- basic-sim") {
+        stage ("Start VM -- enb-ethernet") {
             steps {
                 timeout (time: 5, unit: 'MINUTES') {
-                    sh "./ci-scripts/createVM.sh --variant basic-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
+                    sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant enb-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
                 }
             }
         }
 
-        stage ("Start VM -- phy-sim") {
+        stage ("Start VM -- ue-ethernet") {
             steps {
                 timeout (time: 5, unit: 'MINUTES') {
-                    sh "./ci-scripts/createVM.sh --variant phy-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
+                    sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant ue-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
                 }
             }
         }
 
-        stage ("Start VM -- enb-ethernet") {
+        stage ("Start VM -- L2-Sim") {
             steps {
                 timeout (time: 5, unit: 'MINUTES') {
-                    sh "./ci-scripts/createVM.sh --variant enb-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
+                    sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant l2-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
                 }
             }
         }
 
-        stage ("Start VM -- ue-ethernet") {
+        stage ("Start VM -- phy-sim") {
+            steps {
+                timeout (time: 5, unit: 'MINUTES') {
+                    sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant phy-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
+                }
+            }
+        }
+
+        stage ("Start VM -- cppcheck") {
             steps {
                 timeout (time: 5, unit: 'MINUTES') {
-                    sh "./ci-scripts/createVM.sh --variant ue-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
+                    sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant cppcheck --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
                 }
             }
         }
@@ -169,7 +197,7 @@ pipeline {
                     steps {
                         gitlabCommitStatus(name: "Analysis with cppcheck") {
                             timeout (time: 20, unit: 'MINUTES') {
-                                sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant cppcheck --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
+                                sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant cppcheck --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
                             }
                         }
                     }
@@ -178,7 +206,7 @@ pipeline {
                     steps {
                         gitlabCommitStatus(name: "Build eNb-USRP") {
                             timeout (time: 20, unit: 'MINUTES') {
-                                sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant enb-usrp --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
+                                sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant enb-usrp --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
                             }
                         }
                     }
@@ -187,34 +215,43 @@ pipeline {
                     steps {
                         gitlabCommitStatus(name: "Build basic-sim") {
                             timeout (time: 20, unit: 'MINUTES') {
-                                sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant basic-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
+                                sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant basic-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
                             }
                         }
                     }
                 }
-                stage ("Build physical simulators") {
+                stage ("Build eNb-ethernet") {
                     steps {
-                        gitlabCommitStatus(name: "Build phy-sim") {
+                        gitlabCommitStatus(name: "Build eNb-ethernet") {
                             timeout (time: 20, unit: 'MINUTES') {
-                                sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant phy-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
+                                sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant enb-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
                             }
                         }
                     }
                 }
-                stage ("Build eNb-ethernet") {
+                stage ("Build UE-ethernet") {
                     steps {
-                        gitlabCommitStatus(name: "Build eNb-ethernet") {
+                        gitlabCommitStatus(name: "Build UE-ethernet") {
                             timeout (time: 20, unit: 'MINUTES') {
-                                sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant enb-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
+                                sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant ue-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
                             }
                         }
                     }
                 }
-                stage ("Build UE-ethernet") {
+                stage ("Build L2-Simulator-eNB") {
                     steps {
-                        gitlabCommitStatus(name: "Build UE-ethernet") {
+                        //gitlabCommitStatus(name: "Build UE-ethernet") {
+                            timeout (time: 20, unit: 'MINUTES') {
+                                sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant l2-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
+                            }
+                        //}
+                    }
+                }
+                stage ("Build physical simulators") {
+                    steps {
+                        gitlabCommitStatus(name: "Build phy-sim") {
                             timeout (time: 20, unit: 'MINUTES') {
-                                sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant ue-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
+                               sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant phy-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
                             }
                         }
                     }
@@ -224,7 +261,7 @@ pipeline {
                         expression {doRedHatBuild}
                     }
                     steps {
-                        gitlabCommitStatus(name: "Build eNb-USRP-CentOS") {
+                        gitlabCommitStatus(name: "Build eNb-USRP-RHE") {
                             script {
                                 try {
                                     withCredentials([
@@ -252,7 +289,7 @@ pipeline {
                             archiveArtifacts artifacts: 'archives/vm_build_logs.zip'
                         }
                         if ("MERGE".equals(env.gitlabActionType)) {
-                            sh "./ci-scripts/reportBuildLocally.sh --git-url ${GIT_URL} --job-name ${JOB_NAME} --build-id ${BUILD_ID} --trigger merge-request --src-branch ${env.gitlabSourceBranch} --src-commit ${env.gitlabMergeRequestLastCommit} --target-branch ${env.gitlabTargetBranch} --target-commit ${GIT_COMMIT}"
+                            sh "./ci-scripts/oai-ci-vm-tool report-build --workspace $WORKSPACE --git-url ${GIT_URL} --job-name ${JOB_NAME} --build-id ${BUILD_ID} --trigger merge-request --src-branch ${env.gitlabSourceBranch} --src-commit ${env.gitlabMergeRequestLastCommit} --target-branch ${env.gitlabTargetBranch} --target-commit ${GIT_COMMIT}"
                             sh "./ci-scripts/checkAddedWarnings.sh --src-branch ${env.gitlabSourceBranch} --target-branch ${env.gitlabTargetBranch}"
                             def res=readFile('./oai_warning_files.txt').trim();
                             if ("0".equals(res)) {
@@ -263,7 +300,7 @@ pipeline {
                                 addGitLabMRComment comment: message
                             }
                         } else {
-                            sh "./ci-scripts/reportBuildLocally.sh --git-url ${GIT_URL} --job-name ${JOB_NAME} --build-id ${BUILD_ID} --trigger push --branch ${GIT_BRANCH} --commit ${GIT_COMMIT}"
+                            sh "./ci-scripts/oai-ci-vm-tool report-build --workspace $WORKSPACE --git-url ${GIT_URL} --job-name ${JOB_NAME} --build-id ${BUILD_ID} --trigger push --branch ${GIT_BRANCH} --commit ${GIT_COMMIT}"
                         }
                         if(fileExists('build_results.html')) {
                             sh "sed -i -e 's#Build-ID: ${BUILD_ID}#Build-ID: <a href=\"${BUILD_URL}\">${BUILD_ID}</a>#' -e 's#TEMPLATE_BUILD_TIME#${JOB_TIMESTAMP}#' build_results.html"
@@ -280,7 +317,7 @@ pipeline {
                     steps {
                         gitlabCommitStatus(name: "Test phy-sim") {
                             timeout (time: 20, unit: 'MINUTES') {
-                                sh "./ci-scripts/runTestOnVM.sh --workspace $WORKSPACE --variant phy-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
+                                sh "./ci-scripts/oai-ci-vm-tool test --workspace $WORKSPACE --variant phy-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
                             }
                         }
                     }
@@ -288,206 +325,205 @@ pipeline {
                 stage ("Test basic simulator") {
                     steps {
                         gitlabCommitStatus(name: "Test basic-sim") {
-                            timeout (time: 20, unit: 'MINUTES') {
-                                sh "./ci-scripts/runTestOnVM.sh --workspace $WORKSPACE --variant basic-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
+                            timeout (time: 30, unit: 'MINUTES') {
+                                sh "./ci-scripts/oai-ci-vm-tool test --workspace $WORKSPACE --variant basic-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
                             }
                         }
                     }
                 }
-                stage ("Test on CI bench #1") {
-                    stages {
-                        stage ("Test FDD - Band 7 - B210") {
-                            steps {
-                                script {
-                                    try {
-                                        if ("MERGE".equals(env.gitlabActionType)) {
-                                            gitlabCommitStatus(name: "Test-FDD-Band7") {
-                                                build job: 'eNB-CI-FDD-Band7-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)
-                                                   ]
-                                            }
-                                        } else {
-                                            gitlabCommitStatus(name: "Test-FDD-Band7") {
-                                                build job: 'eNB-CI-FDD-Band7-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)
-                                                   ]
-                                            }
-                                        }
-                                    } catch (Exception e) {
-                                        currentBuild.result = 'FAILURE'
-                                    }
+                stage ("Test L2 simulator") {
+                    steps {
+                        gitlabCommitStatus(name: "Test L2-sim") {
+                            timeout (time: 30, unit: 'MINUTES') {
+                                sh "./ci-scripts/oai-ci-vm-tool test --workspace $WORKSPACE --variant l2-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
+                            }
+                        }
+                    }
+                }
+                stage ("Build Flexran Controller") {
+                    when {
+                        expression {doFlexranCtrlTest}
+                    }
+                    steps {
+                        timeout (time: 20, unit: 'MINUTES') {
+                            sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant flexran-rtc --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
+                        }
+                    }
+                }
+                stage ("Test FDD - Band 7 - B210") {
+                    steps {
+                        script {
+                            if ("MERGE".equals(env.gitlabActionType)) {
+                                gitlabCommitStatus(name: "Test-FDD-Band7") {
+                                    build job: 'eNB-CI-FDD-Band7-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)
+                                       ]
+                                }
+                            } else {
+                                gitlabCommitStatus(name: "Test-FDD-Band7") {
+                                    build job: 'eNB-CI-FDD-Band7-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-FDD-Band7-B210.html')) {
-                                            copyArtifacts(projectName: 'eNB-CI-FDD-Band7-B210',
-                                                          filter: 'test_results*.html',
-                                                          selector: lastCompleted())
-                                            if (fileExists('test_results-eNB-CI-FDD-Band7-B210.html')) {
-                                                sh "sed -i -e 's#TEMPLATE_BUILD_TIME#${JOB_TIMESTAMP}#' test_results-eNB-CI-FDD-Band7-B210.html"
-                                                archiveArtifacts artifacts: 'test_results-eNB-CI-FDD-Band7-B210.html'
-                                            }
-                                        }
+                        }
+                    }
+                    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-FDD-Band7-B210.html')) {
+                                    copyArtifacts(projectName: 'eNB-CI-FDD-Band7-B210',
+                                                  filter: 'test_results*.html',
+                                                  selector: lastCompleted())
+                                    if (fileExists('test_results-eNB-CI-FDD-Band7-B210.html')) {
+                                        sh "sed -i -e 's#TEMPLATE_BUILD_TIME#${JOB_TIMESTAMP}#' test_results-eNB-CI-FDD-Band7-B210.html"
+                                        archiveArtifacts artifacts: 'test_results-eNB-CI-FDD-Band7-B210.html'
                                     }
                                 }
                             }
                         }
-                        stage ("Test TDD - Band 40 - B210") {
-                            steps {
-                                script {
-                                    try {
-                                        if ("MERGE".equals(env.gitlabActionType)) {
-                                            gitlabCommitStatus(name: "Test-TDD-Band40") {
-                                                build job: 'eNB-CI-TDD-Band40-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)
-                                                   ]
-                                            }
-                                        } else {
-                                            gitlabCommitStatus(name: "Test-TDD-Band40") {
-                                                build job: 'eNB-CI-TDD-Band40-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)
-                                                   ]
-                                            }
-                                        }
-                                    } catch (Exception e) {
-                                        currentBuild.result = 'FAILURE'
-                                    }
+                    }
+                }
+                stage ("Test TDD - Band 40 - B210") {
+                    steps {
+                        script {
+                            if ("MERGE".equals(env.gitlabActionType)) {
+                                gitlabCommitStatus(name: "Test-TDD-Band40") {
+                                    build job: 'eNB-CI-TDD-Band40-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)
+                                       ]
+                                }
+                            } else {
+                                gitlabCommitStatus(name: "Test-TDD-Band40") {
+                                    build job: 'eNB-CI-TDD-Band40-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-TDD-Band40-B210.html')) {
-                                            copyArtifacts(projectName: 'eNB-CI-TDD-Band40-B210',
-                                                          filter: 'test_results*.html',
-                                                          selector: lastCompleted())
-                                            if (fileExists('test_results-eNB-CI-TDD-Band40-B210.html')) {
-                                                sh "sed -i -e 's#TEMPLATE_BUILD_TIME#${JOB_TIMESTAMP}#' test_results-eNB-CI-TDD-Band40-B210.html"
-                                                archiveArtifacts artifacts: 'test_results-eNB-CI-TDD-Band40-B210.html'
-                                            }
-                                        }
+                        }
+                    }
+                    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-TDD-Band40-B210.html')) {
+                                    copyArtifacts(projectName: 'eNB-CI-TDD-Band40-B210',
+                                                  filter: 'test_results*.html',
+                                                  selector: lastCompleted())
+                                    if (fileExists('test_results-eNB-CI-TDD-Band40-B210.html')) {
+                                        sh "sed -i -e 's#TEMPLATE_BUILD_TIME#${JOB_TIMESTAMP}#' test_results-eNB-CI-TDD-Band40-B210.html"
+                                        archiveArtifacts artifacts: 'test_results-eNB-CI-TDD-Band40-B210.html'
                                     }
                                 }
                             }
                         }
-                        stage ("Test IF4p5 - FDD - Band 7 - B210") {
-                            steps {
-                                script {
-                                    try {
-                                        if ("MERGE".equals(env.gitlabActionType)) {
-                                            gitlabCommitStatus(name: "Test-IF4p5-FDD-Band7") {
-                                                build job: 'eNB-CI-IF4p5-FDD-Band7-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)
-                                                   ]
-                                            }
-                                        } else {
-                                            gitlabCommitStatus(name: "Test-IF4p5-FDD-Band7") {
-                                                build job: 'eNB-CI-IF4p5-FDD-Band7-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)
-                                                   ]
-                                            }
-                                        }
-                                    } catch (Exception e) {
-                                        currentBuild.result = 'FAILURE'
-                                    }
+                    }
+                }
+                stage ("Test IF4p5 - FDD - Band 7 - B210") {
+                    steps {
+                        script {
+                            if ("MERGE".equals(env.gitlabActionType)) {
+                                gitlabCommitStatus(name: "Test-IF4p5-FDD-Band7") {
+                                    build job: 'eNB-CI-IF4p5-FDD-Band7-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)
+                                       ]
+                                }
+                            } else {
+                                gitlabCommitStatus(name: "Test-IF4p5-FDD-Band7") {
+                                    build job: 'eNB-CI-IF4p5-FDD-Band7-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-IF4p5-FDD-Band7-B210.html')) {
-                                            copyArtifacts(projectName: 'eNB-CI-IF4p5-FDD-Band7-B210',
-                                                          filter: 'test_results*.html',
-                                                          selector: lastCompleted())
-                                            if (fileExists('test_results-eNB-CI-IF4p5-FDD-Band7-B210.html')) {
-                                                sh "sed -i -e 's#TEMPLATE_BUILD_TIME#${JOB_TIMESTAMP}#' test_results-eNB-CI-IF4p5-FDD-Band7-B210.html"
-                                                archiveArtifacts artifacts: 'test_results-eNB-CI-IF4p5-FDD-Band7-B210.html'
-                                            }
-                                        }
+                        }
+                    }
+                    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-IF4p5-FDD-Band7-B210.html')) {
+                                    copyArtifacts(projectName: 'eNB-CI-IF4p5-FDD-Band7-B210',
+                                                  filter: 'test_results*.html',
+                                                  selector: lastCompleted())
+                                    if (fileExists('test_results-eNB-CI-IF4p5-FDD-Band7-B210.html')) {
+                                        sh "sed -i -e 's#TEMPLATE_BUILD_TIME#${JOB_TIMESTAMP}#' test_results-eNB-CI-IF4p5-FDD-Band7-B210.html"
+                                        archiveArtifacts artifacts: 'test_results-eNB-CI-IF4p5-FDD-Band7-B210.html'
                                     }
                                 }
                             }
                         }
-                        stage ("Test IF4p5 - TDD - Band 40 - B210") {
-                            steps {
-                                script {
-                                    try {
-                                        if ("MERGE".equals(env.gitlabActionType)) {
-                                            gitlabCommitStatus(name: "Test-IF4p5-TDD-Band40") {
-                                                build job: 'eNB-CI-IF4p5-TDD-Band40-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)
-                                                   ]
-                                            }
-                                        } else {
-                                            gitlabCommitStatus(name: "Test-IF4p5-TDD-Band40") {
-                                                build job: 'eNB-CI-IF4p5-TDD-Band40-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)
-                                                   ]
-                                            }
-                                        }
-                                    } catch (Exception e) {
-                                        currentBuild.result = 'FAILURE'
-                                    }
+                    }
+                }
+                stage ("Test IF4p5 - TDD - Band 40 - B210") {
+                    steps {
+                        script {
+                            if ("MERGE".equals(env.gitlabActionType)) {
+                                gitlabCommitStatus(name: "Test-IF4p5-TDD-Band40") {
+                                    build job: 'eNB-CI-IF4p5-TDD-Band40-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)
+                                       ]
+                                }
+                            } else {
+                                gitlabCommitStatus(name: "Test-IF4p5-TDD-Band40") {
+                                    build job: 'eNB-CI-IF4p5-TDD-Band40-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-IF4p5-TDD-Band40-B210.html')) {
-                                            copyArtifacts(projectName: 'eNB-CI-IF4p5-TDD-Band40-B210',
-                                                          filter: 'test_results*.html',
-                                                          selector: lastCompleted())
-                                            if (fileExists('test_results-eNB-CI-IF4p5-TDD-Band40-B210.html')) {
-                                                sh "sed -i -e 's#TEMPLATE_BUILD_TIME#${JOB_TIMESTAMP}#' test_results-eNB-CI-IF4p5-TDD-Band40-B210.html"
-                                                archiveArtifacts artifacts: 'test_results-eNB-CI-IF4p5-TDD-Band40-B210.html'
-                                            }
-                                        }
+                        }
+                    }
+                    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-IF4p5-TDD-Band40-B210.html')) {
+                                    copyArtifacts(projectName: 'eNB-CI-IF4p5-TDD-Band40-B210',
+                                                  filter: 'test_results*.html',
+                                                  selector: lastCompleted())
+                                    if (fileExists('test_results-eNB-CI-IF4p5-TDD-Band40-B210.html')) {
+                                        sh "sed -i -e 's#TEMPLATE_BUILD_TIME#${JOB_TIMESTAMP}#' test_results-eNB-CI-IF4p5-TDD-Band40-B210.html"
+                                        archiveArtifacts artifacts: 'test_results-eNB-CI-IF4p5-TDD-Band40-B210.html'
                                     }
                                 }
                             }
@@ -499,14 +535,14 @@ pipeline {
                 always {
                     script {
                         dir ('archives') {
-                            sh "if [ -d basic_sim/test ] || [ -d phy_sim/test ]; then zip -r -qq vm_tests_logs.zip */test ; fi"
+                            sh "if [ -d basic_sim/test ] || [ -d phy_sim/test ] || [ -d l2_sim/test ]; then zip -r -qq vm_tests_logs.zip */test ; fi"
                         }
                         if(fileExists('archives/vm_tests_logs.zip')) {
                             archiveArtifacts artifacts: 'archives/vm_tests_logs.zip'
                             if ("MERGE".equals(env.gitlabActionType)) {
-                                sh "./ci-scripts/reportTestLocally.sh --git-url ${GIT_URL} --job-name ${JOB_NAME} --build-id ${BUILD_ID} --trigger merge-request --src-branch ${env.gitlabSourceBranch} --src-commit ${env.gitlabMergeRequestLastCommit} --target-branch ${env.gitlabTargetBranch} --target-commit ${GIT_COMMIT}"
+                                sh "./ci-scripts/oai-ci-vm-tool report-test --workspace $WORKSPACE --git-url ${GIT_URL} --job-name ${JOB_NAME} --build-id ${BUILD_ID} --trigger merge-request --src-branch ${env.gitlabSourceBranch} --src-commit ${env.gitlabMergeRequestLastCommit} --target-branch ${env.gitlabTargetBranch} --target-commit ${GIT_COMMIT}"
                             } else {
-                                sh "./ci-scripts/reportTestLocally.sh --git-url ${GIT_URL} --job-name ${JOB_NAME} --build-id ${BUILD_ID} --trigger push --branch ${GIT_BRANCH} --commit ${GIT_COMMIT}"
+                                sh "./ci-scripts/oai-ci-vm-tool report-test --workspace $WORKSPACE --git-url ${GIT_URL} --job-name ${JOB_NAME} --build-id ${BUILD_ID} --trigger push --branch ${GIT_BRANCH} --commit ${GIT_COMMIT}"
                             }
                             if(fileExists('test_simulator_results.html')) {
                                 sh "sed -i -e 's#Build-ID: ${BUILD_ID}#Build-ID: <a href=\"${BUILD_URL}\">${BUILD_ID}</a>#' -e 's#TEMPLATE_BUILD_TIME#${JOB_TIMESTAMP}#' test_simulator_results.html"
@@ -519,7 +555,7 @@ pipeline {
         }
         stage ("Destroy all Virtual Machines") {
             steps {
-                sh "./ci-scripts/destroyAllRunningVM.sh --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
+                sh "./ci-scripts/oai-ci-vm-tool destroy --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
             }
         }
     }
@@ -527,7 +563,7 @@ pipeline {
         always {
             script {
                 // Stage destroy may not be run if error in previous stage
-                sh "./ci-scripts/destroyAllRunningVM.sh --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
+                sh "./ci-scripts/oai-ci-vm-tool destroy --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
                 emailext attachmentsPattern: '*results*.html',
                      body: '''Hi,
 Here are attached HTML report files for $PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS!
@@ -537,6 +573,10 @@ OAI CI Team''',
                      replyTo: 'no-reply@openairinterface.org',
                      subject: '$PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS!',
                      to: env.gitlabUserEmail
+
+                if (fileExists('.git/CI_COMMIT_MSG')) {
+                    sh "rm -f .git/CI_COMMIT_MSG"
+                }
             }
         }
         success {
diff --git a/ci-scripts/Jenkinsfile-tmp-ran b/ci-scripts/Jenkinsfile-tmp-ran
index 5fd2a09598972a80f75c817a6eda711a938e3df7..39347b35584884dde6e0f33003bd188add6d6cf0 100644
--- a/ci-scripts/Jenkinsfile-tmp-ran
+++ b/ci-scripts/Jenkinsfile-tmp-ran
@@ -27,6 +27,8 @@ def pythonExecutor = params.pythonExecutor
 
 // Location of the test XML file to be run
 def testXMLFile = params.pythonTestXmlFile
+def mainPythonAllXmlFiles = ""
+def buildStageStatus = true
 
 // Name of the test stage
 def testStageName = params.pipelineTestStageName
@@ -53,6 +55,7 @@ def eNB_Repository
 def eNB_Branch
 def eNB_CommitID
 def eNB_AllowMergeRequestProcess = false
+def eNB_TargetBranch
 
 pipeline {
     agent {
@@ -61,6 +64,7 @@ pipeline {
     options {
         disableConcurrentBuilds()
         ansiColor('xterm')
+        lock (ciSmartPhoneResource)
     }
     // the following parameter options are commented out so it shows the ones
     // that you SHALL have to run the job.
@@ -106,8 +110,14 @@ pipeline {
                     if (params.pythonTestXmlFile == null) {
                         // picking default
                         testXMLFile = 'xml_files/enb_usrpB210_band7_50PRB.xml'
+                        echo "Test XML file(default):   ${testXMLFile}"
+                        mainPythonAllXmlFiles += "--XMLTestFile=" + testXMLFile + " "
                     } else {
-                        echo "Test XML file         :   ${testXMLFile}"
+                        String[] myXmlTestSuite = testXMLFile.split("\\r?\\n")
+                        for (xmlFile in myXmlTestSuite) {
+                            mainPythonAllXmlFiles += "--XMLTestFile=" + xmlFile + " "
+                            echo "Test XML file         :   ${xmlFile}"
+                        }
                     }
                     // If not present picking a default Stage Name
                     if (params.pipelineTestStageName == null) {
@@ -149,6 +159,14 @@ pipeline {
                     echo "eNB_CommitID          :   ${eNB_CommitID}"
                     if (params.eNB_mergeRequest != null) {
                         eNB_AllowMergeRequestProcess = params.eNB_mergeRequest
+                        if (eNB_AllowMergeRequestProcess) {
+                            if (params.eNB_TargetBranch != null) {
+                                eNB_TargetBranch = params.eNB_TargetBranch
+                            } else {
+                                eNB_TargetBranch = 'develop'
+                            }
+                            echo "eNB_TargetBranch      :   ${eNB_TargetBranch}"
+                        }
                     }
 
                     if (params.EPC_IPAddress == null) {
@@ -184,20 +202,24 @@ pipeline {
             steps {
                 script {
                     dir ('ci-scripts') {
-                      lock (ciSmartPhoneResource) {
-                        try {
-                            echo "\u2705 \u001B[32m${testStageName}\u001B[0m"
-                            withCredentials([
-                                [$class: 'UsernamePasswordMultiBinding', credentialsId: "${params.eNB_Credentials}", usernameVariable: 'eNB_Username', passwordVariable: 'eNB_Password'],
-                                [$class: 'UsernamePasswordMultiBinding', credentialsId: "${params.EPC_Credentials}", usernameVariable: 'EPC_Username', passwordVariable: 'EPC_Password'],
-                                [$class: 'UsernamePasswordMultiBinding', credentialsId: "${params.ADB_Credentials}", usernameVariable: 'ADB_Username', passwordVariable: 'ADB_Password']
-                            ]) {
-                                sh "python3 main.py --mode=TesteNB --eNBIPAddress=${params.eNB_IPAddress} --eNBRepository=${eNB_Repository} --eNBBranch=${eNB_Branch} --eNBCommitID=${eNB_CommitID} --eNB_AllowMerge=${eNB_AllowMergeRequestProcess} --eNBUserName=${eNB_Username} --eNBPassword=${eNB_Password} --eNBSourceCodePath=${params.eNB_SourceCodePath} --EPCIPAddress=${params.EPC_IPAddress} --EPCType=${params.EPC_Type} --EPCUserName=${EPC_Username} --EPCPassword=${EPC_Password} --EPCSourceCodePath=${params.EPC_SourceCodePath} --ADBIPAddress=${params.ADB_IPAddress} --ADBUserName=${ADB_Username} --ADBPassword=${ADB_Password} --XMLTestFile=${testXMLFile}"
+                        echo "\u2705 \u001B[32m${testStageName}\u001B[0m"
+                        withCredentials([
+                            [$class: 'UsernamePasswordMultiBinding', credentialsId: "${params.eNB_Credentials}", usernameVariable: 'eNB_Username', passwordVariable: 'eNB_Password'],
+                            [$class: 'UsernamePasswordMultiBinding', credentialsId: "${params.EPC_Credentials}", usernameVariable: 'EPC_Username', passwordVariable: 'EPC_Password'],
+                            [$class: 'UsernamePasswordMultiBinding', credentialsId: "${params.ADB_Credentials}", usernameVariable: 'ADB_Username', passwordVariable: 'ADB_Password']
+                        ]) {
+                            sh "python3 main.py --mode=InitiateHtml --eNBRepository=${eNB_Repository} --eNBBranch=${eNB_Branch} --eNBCommitID=${eNB_CommitID} --eNB_AllowMerge=${eNB_AllowMergeRequestProcess} --eNBTargetBranch=${eNB_TargetBranch} --ADBIPAddress=${params.ADB_IPAddress} --ADBUserName=${ADB_Username} --ADBPassword=${ADB_Password} ${mainPythonAllXmlFiles}"
+                            String[] myXmlTestSuite = testXMLFile.split("\\r?\\n")
+                            for (xmlFile in myXmlTestSuite) {
+                                try {
+                                    sh "python3 main.py --mode=TesteNB --eNBIPAddress=${params.eNB_IPAddress} --eNBRepository=${eNB_Repository} --eNBBranch=${eNB_Branch} --eNBCommitID=${eNB_CommitID} --eNB_AllowMerge=${eNB_AllowMergeRequestProcess} --eNBTargetBranch=${eNB_TargetBranch} --eNBUserName=${eNB_Username} --eNBPassword=${eNB_Password} --eNBSourceCodePath=${params.eNB_SourceCodePath} --EPCIPAddress=${params.EPC_IPAddress} --EPCType=${params.EPC_Type} --EPCUserName=${EPC_Username} --EPCPassword=${EPC_Password} --EPCSourceCodePath=${params.EPC_SourceCodePath} --ADBIPAddress=${params.ADB_IPAddress} --ADBUserName=${ADB_Username} --ADBPassword=${ADB_Password} --XMLTestFile=${xmlFile}"
+                                } catch (Exception e) {
+                                    currentBuild.result = 'FAILURE'
+                                    buildStageStatus = false
+                                }
                             }
-                        } catch (Exception e) {
-                            currentBuild.result = 'FAILURE'
+                            sh "python3 main.py --mode=FinalizeHtml --finalStatus=${buildStageStatus} --eNBIPAddress=${params.eNB_IPAddress} --eNBUserName=${eNB_Username} --eNBPassword=${eNB_Password}"
                         }
-                      }
                     }
                 }
             }
@@ -328,7 +350,7 @@ pipeline {
                             }
                             if(fileExists("ci-scripts/test_results.html")) {
                                 sh "mv ci-scripts/test_results.html test_results-${JOB_NAME}.html"
-                                sh "sed -i -e 's#TEMPLATE_JOB_NAME#${JOB_NAME}#' -e 's@build #TEMPLATE_BUILD_ID@build #${BUILD_ID}@' -e 's#Build-ID: TEMPLATE_BUILD_ID#Build-ID: <a href=\"${BUILD_URL}\">${BUILD_ID}</a>#' test_results-${JOB_NAME}.html"
+                                sh "sed -i -e 's#TEMPLATE_JOB_NAME#${JOB_NAME}#' -e 's@build #TEMPLATE_BUILD_ID@build #${BUILD_ID}@' -e 's#Build-ID: TEMPLATE_BUILD_ID#Build-ID: <a href=\"${BUILD_URL}\">${BUILD_ID}</a>#' -e 's#TEMPLATE_STAGE_NAME#${testStageName}#' test_results-${JOB_NAME}.html"
                                 archiveArtifacts "test_results-${JOB_NAME}.html"
                             }
                         }
diff --git a/ci-scripts/active_net_interfaces.awk b/ci-scripts/active_net_interfaces.awk
new file mode 100644
index 0000000000000000000000000000000000000000..6d1174c1cc913c5fcff490a33abdc96829e611cf
--- /dev/null
+++ b/ci-scripts/active_net_interfaces.awk
@@ -0,0 +1,21 @@
+#/*
+# * 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
+# */
+/inet.*brd/{print "interfaceToUse="$NF"done"}
diff --git a/ci-scripts/buildOnRH.sh b/ci-scripts/buildOnRH.sh
index ce5b24dc4931de5238cca91946733378031ce58b..bb57cde165ed82b63e74cd774bbcf20a84e37223 100755
--- a/ci-scripts/buildOnRH.sh
+++ b/ci-scripts/buildOnRH.sh
@@ -198,12 +198,18 @@ do
     fi
 done
 
-if [ $NB_PATTERN_FILES -ne $NB_FOUND_FILES ]; then STATUS=-1; fi
+if [ $NB_PATTERN_FILES -ne $NB_FOUND_FILES ]
+then
+    echo "Expecting $NB_PATTERN_FILES log files and found $NB_FOUND_FILES"
+    STATUS=-1
+fi
 
 if [ $STATUS -eq 0 ]
 then
+    echo "BUILD_OK" > $ARCHIVES_LOC/build_final_status.log
     echo "STATUS seems OK"
 else
+    echo "BUILD_KO" > $ARCHIVES_LOC/build_final_status.log
     echo "STATUS failed?"
 fi
 exit $STATUS
diff --git a/ci-scripts/buildOnVM.sh b/ci-scripts/buildOnVM.sh
index 2a358c9bacf09ce8d27577efc3d1572ce98f80e9..3c9163916276017afb19acb972595d226f407f53 100755
--- a/ci-scripts/buildOnVM.sh
+++ b/ci-scripts/buildOnVM.sh
@@ -20,8 +20,8 @@
 # *      contact@openairinterface.org
 # */
 
-function usage {
-    echo "OAI VM Build Check script"
+function build_usage {
+    echo "OAI CI VM script"
     echo "   Original Author: Raphael Defosseux"
     echo "   Requirements:"
     echo "     -- uvtool uvtool-libvirt apt-cacher"
@@ -31,9 +31,9 @@ function usage {
     echo ""
     echo "Usage:"
     echo "------"
-    echo "    buildOnVM.sh [OPTIONS]"
+    echo "    oai-ci-vm-tool build [OPTIONS]"
     echo ""
-    echo "Options:"
+    echo "Mandatory Options:"
     echo "--------"
     echo "    --job-name #### OR -jn ####"
     echo "    Specify the name of the Jenkins job."
@@ -44,356 +44,168 @@ function usage {
     echo "    --workspace #### OR -ws ####"
     echo "    Specify the workspace."
     echo ""
-    echo "    --variant enb-usrp     OR -v1"
-    echo "    --variant basic-sim    OR -v2"
-    echo "    --variant phy-sim      OR -v3"
-    echo "    --variant cppcheck     OR -v4"
-    echo "    --variant enb-ethernet OR -v7"
-    echo "    --variant ue-ethernet  OR -v8"
+    echo "Options:"
+    echo "--------"
+    variant_usage
     echo "    Specify the variant to build."
     echo ""
     echo "    --keep-vm-alive OR -k"
     echo "    Keep the VM alive after the build."
     echo ""
+    echo "    --daemon OR -D"
+    echo "    Run as daemon"
+    echo ""
     echo "    --help OR -h"
     echo "    Print this help message."
     echo ""
 }
 
-function variant_usage {
-    echo "OAI VM Build Check script"
-    echo "   Original Author: Raphael Defosseux"
-    echo ""
-    echo "    --variant enb-usrp     OR -v1"
-    echo "    --variant basic-sim    OR -v2"
-    echo "    --variant phy-sim      OR -v3"
-    echo "    --variant cppcheck     OR -v4"
-    echo "    --variant enb-ethernet OR -v7"
-    echo "    --variant ue-ethernet  OR -v8"
-    echo ""
-}
-
-if [ $# -lt 1 ] || [ $# -gt 9 ]
-then
-    echo "Syntax Error: not the correct number of arguments"
-    echo ""
-    usage
-    exit 1
-fi
-
-VM_TEMPLATE=ci-
-JOB_NAME=XX
-BUILD_ID=XX
-VM_NAME=ci-enb-usrp
-VM_MEMORY=2048
-VM_CPU=4
-ARCHIVES_LOC=enb_usrp
-LOG_PATTERN=.Rel14.txt
-NB_PATTERN_FILES=4
-BUILD_OPTIONS="--eNB -w USRP"
-KEEP_VM_ALIVE=0
-
-while [[ $# -gt 0 ]]
-do
-key="$1"
-
-case $key in
-    -h|--help)
-    shift
-    usage
-    exit 0
-    ;;
-    -jn|--job-name)
-    JOB_NAME="$2"
-    shift
-    shift
-    ;;
-    -id|--build-id)
-    BUILD_ID="$2"
-    shift
-    shift
-    ;;
-    -ws|--workspace)
-    JENKINS_WKSP="$2"
-    shift
-    shift
-    ;;
-    -k|--keep-vm-alive)
-    KEEP_VM_ALIVE=1
-    shift
-    ;;
-    -v1)
-    VM_NAME=ci-enb-usrp
-    ARCHIVES_LOC=enb_usrp
-    LOG_PATTERN=.Rel14.txt
-    NB_PATTERN_FILES=4
-    BUILD_OPTIONS="--eNB -w USRP --mu"
-    shift
-    ;;
-    -v2)
-    VM_NAME=ci-basic-sim
-    ARCHIVES_LOC=basic_sim
-    LOG_PATTERN=basic_simulator
-    NB_PATTERN_FILES=2
-    BUILD_OPTIONS="--basic-simulator"
-    VM_MEMORY=8192
-    VM_CPU=4
-    shift
-    ;;
-    -v3)
-    VM_NAME=ci-phy-sim
-    ARCHIVES_LOC=phy_sim
-    LOG_PATTERN=.Rel14.txt
-    NB_PATTERN_FILES=3
-    BUILD_OPTIONS="--phy_simulators"
-    shift
-    ;;
-    -v4)
-    VM_NAME=ci-cppcheck
-    VM_MEMORY=4096
-    ARCHIVES_LOC=cppcheck
-    LOG_PATTERN=cppcheck.xml
-    NB_PATTERN_FILES=1
-    BUILD_OPTIONS="--enable=warning --force --xml --xml-version=2"
-    shift
-    ;;
-    -v7)
-    VM_NAME=ci-enb-ethernet
-    ARCHIVES_LOC=enb_eth
-    LOG_PATTERN=.Rel14.txt
-    NB_PATTERN_FILES=6
-    BUILD_OPTIONS="--eNB -t ETHERNET --noS1"
-    shift
-    ;;
-    -v8)
-    VM_NAME=ci-ue-ethernet
-    ARCHIVES_LOC=ue_eth
-    LOG_PATTERN=.Rel14.txt
-    NB_PATTERN_FILES=6
-    BUILD_OPTIONS="--UE -t ETHERNET --noS1"
-    shift
-    ;;
-    --variant)
-    variant="$2"
-    case $variant in
-        enb-usrp)
-        VM_NAME=ci-enb-usrp
-        ARCHIVES_LOC=enb_usrp
-        LOG_PATTERN=.Rel14.txt
-        NB_PATTERN_FILES=4
-        BUILD_OPTIONS="--eNB -w USRP --mu"
-        ;;
-        basic-sim)
-        VM_NAME=ci-basic-sim
-        ARCHIVES_LOC=basic_sim
-        LOG_PATTERN=basic_simulator
-        NB_PATTERN_FILES=2
-        BUILD_OPTIONS="--basic-simulator"
-        VM_MEMORY=8192
-        VM_CPU=4
-        ;;
-        phy-sim)
-        VM_NAME=ci-phy-sim
-        ARCHIVES_LOC=phy_sim
-        LOG_PATTERN=.Rel14.txt
-        NB_PATTERN_FILES=3
-        BUILD_OPTIONS="--phy_simulators"
-        ;;
-        cppcheck)
-        VM_NAME=ci-cppcheck
-        VM_MEMORY=4096
-        ARCHIVES_LOC=cppcheck
-        LOG_PATTERN=cppcheck.xml
-        NB_PATTERN_FILES=1
-        BUILD_OPTIONS="--enable=warning --force --xml --xml-version=2"
-        ;;
-        enb-ethernet)
-        VM_NAME=ci-enb-ethernet
-        ARCHIVES_LOC=enb_eth
-        LOG_PATTERN=.Rel14.txt
-        NB_PATTERN_FILES=6
-        BUILD_OPTIONS="--eNB -t ETHERNET --noS1"
-        ;;
-        ue-ethernet)
-        VM_NAME=ci-ue-ethernet
-        ARCHIVES_LOC=ue_eth
-        LOG_PATTERN=.Rel14.txt
-        NB_PATTERN_FILES=6
-        BUILD_OPTIONS="--UE -t ETHERNET --noS1"
-        ;;
-        *)
-        echo ""
-        echo "Syntax Error: Invalid Variant option -> $variant"
-        echo ""
-        variant_usage
-        exit 1
-    esac
-    shift
-    shift
-    ;;
-    *)
-    echo "Syntax Error: unknown option: $key"
-    echo ""
-    usage
-    exit 1
-esac
-done
-
-if [ ! -f $JENKINS_WKSP/localZip.zip ]
-then
-    echo "Missing localZip.zip file!"
-    exit 1
-fi
-if [ ! -f /etc/apt/apt.conf.d/01proxy ]
-then
-    echo "Missing /etc/apt/apt.conf.d/01proxy file!"
-    echo "Is apt-cacher installed and configured?"
-    exit 1
-fi
-
-if [ "$JOB_NAME" == "XX" ] || [ "$BUILD_ID" == "XX" ]
-then
-    VM_TEMPLATE=ci-
-else
-    VM_TEMPLATE=${JOB_NAME}-b${BUILD_ID}-
-fi
-
-VM_NAME=`echo $VM_NAME | sed -e "s#ci-#$VM_TEMPLATE#"`
-VM_CMDS=${VM_NAME}_cmds.txt
-ARCHIVES_LOC=${JENKINS_WKSP}/archives/${ARCHIVES_LOC}
-
-echo "VM_NAME             = $VM_NAME"
-echo "VM_CMD_FILE         = $VM_CMDS"
-echo "JENKINS_WKSP        = $JENKINS_WKSP"
-echo "ARCHIVES_LOC        = $ARCHIVES_LOC"
-echo "BUILD_OPTIONS       = $BUILD_OPTIONS"
-
-IS_VM_ALIVE=`uvt-kvm list | grep -c $VM_NAME`
+function build_on_vm {
+    if [ ! -f $JENKINS_WKSP/localZip.zip ]
+    then
+        echo "Missing localZip.zip file!"
+        STATUS=1
+        return
+    fi
+    if [ ! -f /etc/apt/apt.conf.d/01proxy ]
+    then
+        echo "Missing /etc/apt/apt.conf.d/01proxy file!"
+        echo "Is apt-cacher installed and configured?"
+        STATUS=1
+        return
+    fi
 
-if [ $IS_VM_ALIVE -eq 0 ]
-then
     echo "############################################################"
-    echo "Creating VM ($VM_NAME) on Ubuntu Cloud Image base"
+    echo "OAI CI VM script"
     echo "############################################################"
-    uvt-kvm create $VM_NAME release=xenial --memory $VM_MEMORY --cpu $VM_CPU --unsafe-caching --template ci-scripts/template-host.xml
-fi
-
-echo "Waiting for VM to be started"
-uvt-kvm wait $VM_NAME --insecure
 
-VM_IP_ADDR=`uvt-kvm ip $VM_NAME`
-echo "$VM_NAME has for IP addr = $VM_IP_ADDR"
+    echo "VM_NAME             = $VM_NAME"
+    echo "VM_CMD_FILE         = $VM_CMDS"
+    echo "JENKINS_WKSP        = $JENKINS_WKSP"
+    echo "ARCHIVES_LOC        = $ARCHIVES_LOC"
+    echo "BUILD_OPTIONS       = $BUILD_OPTIONS"
 
-echo "############################################################"
-echo "Copying GIT repo into VM ($VM_NAME)" 
-echo "############################################################"
-scp -o StrictHostKeyChecking=no localZip.zip ubuntu@$VM_IP_ADDR:/home/ubuntu
-scp -o StrictHostKeyChecking=no /etc/apt/apt.conf.d/01proxy ubuntu@$VM_IP_ADDR:/home/ubuntu
+    IS_VM_ALIVE=`uvt-kvm list | grep -c $VM_NAME`
 
-echo "############################################################"
-echo "Running install and build script on VM ($VM_NAME)"
-echo "############################################################"
-echo "sudo cp 01proxy /etc/apt/apt.conf.d/" > $VM_CMDS
-echo "touch /home/ubuntu/.hushlogin" >> $VM_CMDS
-if [[ "$VM_NAME" == *"-cppcheck"* ]]
-then
-    echo "echo \"sudo apt-get --yes --quiet install zip cppcheck \"" >> $VM_CMDS
-    echo "sudo apt-get update > zip-install.txt 2>&1" >> $VM_CMDS
-    echo "sudo apt-get --yes install zip cppcheck >> zip-install.txt 2>&1" >> $VM_CMDS
-else
-    echo "echo \"sudo apt-get --yes --quiet install zip subversion libboost-dev \"" >> $VM_CMDS
-    echo "sudo apt-get update > zip-install.txt 2>&1" >> $VM_CMDS
-    echo "sudo apt-get --yes install zip subversion libboost-dev >> zip-install.txt 2>&1" >> $VM_CMDS
-fi
-echo "mkdir tmp" >> $VM_CMDS
-echo "cd tmp" >> $VM_CMDS
-echo "echo \"unzip -qq -DD ../localZip.zip\"" >> $VM_CMDS
-echo "unzip -qq -DD ../localZip.zip" >> $VM_CMDS
-if [[ "$VM_NAME" == *"-cppcheck"* ]]
-then
-    echo "mkdir cmake_targets/log" >> $VM_CMDS
-    echo "cp /home/ubuntu/zip-install.txt cmake_targets/log" >> $VM_CMDS
-    echo "echo \"cppcheck $BUILD_OPTIONS . \"" >> $VM_CMDS
-    echo "cppcheck $BUILD_OPTIONS . 2> cmake_targets/log/cppcheck.xml 1> cmake_targets/log/cppcheck_build.txt" >> $VM_CMDS
-else
-    echo "echo \"source oaienv\"" >> $VM_CMDS
-    echo "source oaienv" >> $VM_CMDS
-    echo "cd cmake_targets/" >> $VM_CMDS
-    echo "mkdir log" >> $VM_CMDS
-    echo "cp /home/ubuntu/zip-install.txt log" >> $VM_CMDS
-    echo "echo \"./build_oai -I $BUILD_OPTIONS \"" >> $VM_CMDS
-    echo "./build_oai -I $BUILD_OPTIONS > log/install-build.txt 2>&1" >> $VM_CMDS
-fi
-ssh -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR < $VM_CMDS
-
-echo "############################################################"
-echo "Creating a tmp folder to store results and artifacts"
-echo "############################################################"
-if [ ! -d $JENKINS_WKSP/archives ]
-then
-    mkdir $JENKINS_WKSP/archives
-fi
+    if [ $IS_VM_ALIVE -eq 0 ]
+    then
+        echo "VM_MEMORY           = $VM_MEMORY MBytes"
+        echo "VM_CPU              = $VM_CPU"
+        echo "############################################################"
+        echo "Creating VM ($VM_NAME) on Ubuntu Cloud Image base"
+        echo "############################################################"
+        uvt-kvm create $VM_NAME release=xenial --memory $VM_MEMORY --cpu $VM_CPU --unsafe-caching --template ci-scripts/template-host.xml
+    fi
 
-if [ ! -d $ARCHIVES_LOC ]
-then
-    mkdir $ARCHIVES_LOC
-fi
+    echo "Waiting for VM to be started"
+    uvt-kvm wait $VM_NAME --insecure
 
-scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/*.txt $ARCHIVES_LOC
-if [[ "$VM_NAME" == *"-cppcheck"* ]]
-then
-    scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/*.xml $ARCHIVES_LOC
-fi
+    VM_IP_ADDR=`uvt-kvm ip $VM_NAME`
+    echo "$VM_NAME has for IP addr = $VM_IP_ADDR"
 
-if [ $KEEP_VM_ALIVE -eq 0 ]
-then
     echo "############################################################"
-    echo "Destroying VM"
+    echo "Copying GIT repo into VM ($VM_NAME)"
     echo "############################################################"
-    uvt-kvm destroy $VM_NAME
-    ssh-keygen -R $VM_IP_ADDR
-fi
-rm -f $VM_CMDS
-
-echo "############################################################"
-echo "Checking build status" 
-echo "############################################################"
-
-LOG_FILES=`ls $ARCHIVES_LOC/*.txt $ARCHIVES_LOC/*.xml`
-STATUS=0
-NB_FOUND_FILES=0
+    if [[ "$VM_NAME" == *"-flexran-rtc"* ]]
+    then
+        scp -o StrictHostKeyChecking=no $JENKINS_WKSP/flexran/flexran.zip ubuntu@$VM_IP_ADDR:/home/ubuntu/localZip.zip
+    else
+        scp -o StrictHostKeyChecking=no $JENKINS_WKSP/localZip.zip ubuntu@$VM_IP_ADDR:/home/ubuntu
+    fi
+    scp -o StrictHostKeyChecking=no /etc/apt/apt.conf.d/01proxy ubuntu@$VM_IP_ADDR:/home/ubuntu
 
-for FULLFILE in $LOG_FILES 
-do
-    if [[ $FULLFILE == *"$LOG_PATTERN"* ]]
+    echo "############################################################"
+    echo "Running install and build script on VM ($VM_NAME)"
+    echo "############################################################"
+    echo "sudo cp 01proxy /etc/apt/apt.conf.d/" > $VM_CMDS
+    echo "touch /home/ubuntu/.hushlogin" >> $VM_CMDS
+    if [[ "$VM_NAME" == *"-cppcheck"* ]]
     then
-        filename=$(basename -- "$FULLFILE")
-        if [ "$LOG_PATTERN" == ".Rel14.txt" ]
+        if [ $DAEMON -eq 0 ]
         then
-            PASS_PATTERN=`echo $filename | sed -e "s#$LOG_PATTERN##"`
+            echo "echo \"sudo apt-get --yes --quiet install zip cppcheck \"" >> $VM_CMDS
+            echo "sudo apt-get update > zip-install.txt 2>&1" >> $VM_CMDS
+            echo "sudo apt-get --yes install zip cppcheck >> zip-install.txt 2>&1" >> $VM_CMDS
+        else
+            echo "echo \"sudo apt-get --yes --quiet install zip daemon cppcheck \"" >> $VM_CMDS
+            echo "sudo apt-get update > zip-install.txt 2>&1" >> $VM_CMDS
+            echo "sudo apt-get --yes install zip daemon cppcheck >> zip-install.txt 2>&1" >> $VM_CMDS
         fi
-        if [ "$LOG_PATTERN" == "basic_simulator" ]
+    fi
+    if [[ "$VM_NAME" == *"-flexran-rtc"* ]]
+    then
+        if [ $DAEMON -eq 0 ]
         then
-            PASS_PATTERN="lte-"
+            echo "echo \"sudo apt-get --yes --quiet install zip curl jq \"" >> $VM_CMDS
+            echo "sudo apt-get update > zip-install.txt 2>&1" >> $VM_CMDS
+            echo "sudo apt-get --yes install zip curl jq >> zip-install.txt 2>&1" >> $VM_CMDS
+        else
+            echo "echo \"sudo apt-get --yes --quiet install zip daemon curl jq \"" >> $VM_CMDS
+            echo "sudo apt-get update > zip-install.txt 2>&1" >> $VM_CMDS
+            echo "sudo apt-get --yes install zip daemon curl jq >> zip-install.txt 2>&1" >> $VM_CMDS
         fi
-        if [ "$LOG_PATTERN" == "cppcheck.xml" ]
+    fi
+    if [[ "$VM_NAME" != *"-cppcheck"* ]] && [[ "$VM_NAME" != *"-flexran-rtc"* ]]
+    then
+        if [ $DAEMON -eq 0 ]
         then
-            PASS_PATTERN="results version"
-            LOCAL_STAT=`egrep -c "$PASS_PATTERN" $FULLFILE`
+            echo "echo \"sudo apt-get --yes --quiet install zip subversion libboost-dev \"" >> $VM_CMDS
+            echo "sudo apt-get update > zip-install.txt 2>&1" >> $VM_CMDS
+            echo "sudo apt-get --yes install zip subversion libboost-dev >> zip-install.txt 2>&1" >> $VM_CMDS
         else
-            LOCAL_STAT=`egrep -c "Built target $PASS_PATTERN" $FULLFILE`
+            echo "echo \"sudo apt-get --yes --quiet install zip daemon subversion libboost-dev \"" >> $VM_CMDS
+            echo "sudo apt-get update > zip-install.txt 2>&1" >> $VM_CMDS
+            echo "sudo apt-get --yes install zip daemon subversion libboost-dev >> zip-install.txt 2>&1" >> $VM_CMDS
         fi
-        if [ $LOCAL_STAT -eq 0 ]; then STATUS=-1; fi
-        NB_FOUND_FILES=$((NB_FOUND_FILES + 1))
     fi
-done
-
-if [ $NB_PATTERN_FILES -ne $NB_FOUND_FILES ]; then STATUS=-1; fi
-
-if [ $STATUS -eq 0 ]
-then
-    echo "STATUS seems OK"
-else
-    echo "STATUS failed?"
-fi
-exit $STATUS
+    echo "mkdir tmp" >> $VM_CMDS
+    echo "cd tmp" >> $VM_CMDS
+    echo "echo \"unzip -qq -DD ../localZip.zip\"" >> $VM_CMDS
+    echo "unzip -qq -DD ../localZip.zip" >> $VM_CMDS
+    if [[ "$VM_NAME" == *"-cppcheck"* ]]
+    then
+        echo "mkdir cmake_targets/log" >> $VM_CMDS
+        echo "chmod 777 cmake_targets/log" >> $VM_CMDS
+        echo "cp /home/ubuntu/zip-install.txt cmake_targets/log" >> $VM_CMDS
+        echo "echo \"cppcheck $BUILD_OPTIONS . \"" >> $VM_CMDS
+        if [ $DAEMON -eq 0 ]
+        then
+            echo "cppcheck $BUILD_OPTIONS . 2> cmake_targets/log/cppcheck.xml 1> cmake_targets/log/cppcheck_build.txt" >> $VM_CMDS
+        else
+            echo "echo \"cppcheck $BUILD_OPTIONS .\" > ./my-vm-build.sh" >> $VM_CMDS
+            echo "chmod 775 ./my-vm-build.sh " >> $VM_CMDS
+            echo "sudo -E daemon --inherit --unsafe --name=build_daemon --chdir=/home/ubuntu/tmp -O /home/ubuntu/tmp/cmake_targets/log/cppcheck_build.txt -E /home/ubuntu/tmp/cmake_targets/log/cppcheck.xml ./my-vm-build.sh" >> $VM_CMDS
+        fi
+    fi
+    if [[ "$VM_NAME" == *"-flexran-rtc"* ]]
+    then
+        echo "mkdir -p cmake_targets/log" >> $VM_CMDS
+        echo "chmod 777 cmake_targets/log" >> $VM_CMDS
+        echo "cp /home/ubuntu/zip-install.txt cmake_targets/log" >> $VM_CMDS
+        echo "echo \"./tools/install_dependencies \"" >> $VM_CMDS
+        echo "./tools/install_dependencies > cmake_targets/log/install-build.txt 2>&1" >> $VM_CMDS
+        echo "echo \"$BUILD_OPTIONS \"" >> $VM_CMDS
+        echo "$BUILD_OPTIONS > cmake_targets/log/rt_controller.Rel14.txt 2>&1" >> $VM_CMDS
+    fi
+    if [[ "$VM_NAME" != *"-cppcheck"* ]] && [[ "$VM_NAME" != *"-flexran-rtc"* ]]
+    then
+        echo "echo \"source oaienv\"" >> $VM_CMDS
+        echo "source oaienv" >> $VM_CMDS
+        echo "cd cmake_targets/" >> $VM_CMDS
+        echo "mkdir log" >> $VM_CMDS
+        echo "chmod 777 log" >> $VM_CMDS
+        echo "cp /home/ubuntu/zip-install.txt log" >> $VM_CMDS
+        if [ $DAEMON -eq 0 ]
+        then
+            echo "echo \"./build_oai -I $BUILD_OPTIONS \"" >> $VM_CMDS
+            echo "./build_oai -I $BUILD_OPTIONS > log/install-build.txt 2>&1" >> $VM_CMDS
+        else
+            echo "echo \"./build_oai -I $BUILD_OPTIONS\" > ./my-vm-build.sh" >> $VM_CMDS
+            echo "chmod 775 ./my-vm-build.sh " >> $VM_CMDS
+            echo "echo \"sudo -E daemon --inherit --unsafe --name=build_daemon --chdir=/home/ubuntu/tmp/cmake_targets -o /home/ubuntu/tmp/cmake_targets/log/install-build.txt ./my-vm-build.sh\"" >> $VM_CMDS
+            echo "sudo -E daemon --inherit --unsafe --name=build_daemon --chdir=/home/ubuntu/tmp/cmake_targets -o /home/ubuntu/tmp/cmake_targets/log/install-build.txt ./my-vm-build.sh" >> $VM_CMDS
+        fi
+    fi
+    ssh -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR < $VM_CMDS
+    rm -f $VM_CMDS
+}
diff --git a/ci-scripts/conf_files/enb.band13.tm1.50PRB.emtc.conf b/ci-scripts/conf_files/enb.band13.tm1.50PRB.emtc.conf
new file mode 100644
index 0000000000000000000000000000000000000000..72d28fdbebf19b72315ffbc5d36d80befc4e66f3
--- /dev/null
+++ b/ci-scripts/conf_files/enb.band13.tm1.50PRB.emtc.conf
@@ -0,0 +1,442 @@
+Active_eNBs = ( "eNB_Eurecom_LTEBox");
+# Asn1_verbosity, choice in: none, info, annoying
+Asn1_verbosity = "none";
+
+eNBs =
+(
+ {
+    ////////// Identification parameters:
+    eNB_ID    =  0xe00;
+
+    cell_type =  "CELL_MACRO_ENB";
+
+    eNB_name  =  "eNB_Eurecom_LTEBox";
+
+    // Tracking area code, 0x0000 and 0xfffe are reserved values
+    tracking_area_code  =  "1";
+
+    plmn_list = ( { mcc = 208; mnc = 93; mnc_length = 2;} );
+
+    tr_s_preference     = "local_mac"
+
+    ////////// Physical parameters:
+
+    component_carriers = (
+    {
+      node_function                             = "3GPP_eNodeB";
+      node_timing                               = "synch_to_ext_device";
+      node_synch_ref                            = 0;
+      frame_type                                = "FDD";
+      tdd_config                                = 3;
+      tdd_config_s                              = 0;
+      prefix_type                               = "NORMAL";
+      eutra_band                                = 13;
+      downlink_frequency                        = 751000000L;
+      uplink_frequency_offset                   = 31000000;
+      Nid_cell                                  = 0;
+      N_RB_DL                                   = 50;
+      Nid_cell_mbsfn                            = 0;
+      nb_antenna_ports                          = 1;
+      nb_antennas_tx                            = 1;
+      nb_antennas_rx                            = 1;
+      tx_gain                                   = 90;
+      rx_gain                                   = 110;
+      pbch_repetition                           = "FALSE";
+      prach_root                                = 0;
+      prach_config_index                        = 0;
+      prach_high_speed                          = "DISABLE";
+      prach_zero_correlation                    = 1;
+      prach_freq_offset                         = 1;
+      pucch_delta_shift                         = 1;
+      pucch_nRB_CQI                             = 1;
+      pucch_nCS_AN                              = 0;
+      pucch_n1_AN                               = 32;
+      pdsch_referenceSignalPower                = -27;
+      pdsch_p_b                                 = 0;
+      pusch_n_SB                                = 1;
+      pusch_enable64QAM                         = "DISABLE";
+      pusch_hoppingMode                         = "interSubFrame";
+      pusch_hoppingOffset                       = 0;
+      pusch_groupHoppingEnabled                 = "ENABLE";
+      pusch_groupAssignment                     = 0;
+      pusch_sequenceHoppingEnabled              = "DISABLE";
+      pusch_nDMRS1                              = 1;
+      phich_duration                            = "NORMAL";
+      phich_resource                            = "ONESIXTH";
+      srs_enable                                = "DISABLE";
+      /*  srs_BandwidthConfig                   =;
+      srs_SubframeConfig                        =;
+      srs_ackNackST                             =;
+      srs_MaxUpPts                              =;*/
+
+      pusch_p0_Nominal                          = -96;
+      pusch_alpha                               = "AL1";
+      pucch_p0_Nominal                          = -104;
+      msg3_delta_Preamble                       = 6;
+      pucch_deltaF_Format1                      = "deltaF2";
+      pucch_deltaF_Format1b                     = "deltaF3";
+      pucch_deltaF_Format2                      = "deltaF0";
+      pucch_deltaF_Format2a                     = "deltaF0";
+      pucch_deltaF_Format2b                     = "deltaF0";
+
+      rach_numberOfRA_Preambles                 = "n64"; #64
+      rach_preamblesGroupAConfig                = "DISABLE";
+      /*
+      rach_sizeOfRA_PreamblesGroupA             = ;
+      rach_messageSizeGroupA                    = ;
+      rach_messagePowerOffsetGroupB             = ;
+      */
+      rach_powerRampingStep                     = 4;
+      rach_preambleInitialReceivedTargetPower   = -108;
+      rach_preambleTransMax                     = 10;
+      rach_raResponseWindowSize                 = 10;
+      rach_macContentionResolutionTimer         = 48;
+      rach_maxHARQ_Msg3Tx                       = 4;
+
+      pcch_default_PagingCycle                  = "rf128"; #128
+      pcch_nB                                   = "oneT";
+      bcch_modificationPeriodCoeff              = 2;
+      ue_TimersAndConstants_t300                = "ms1000";
+      ue_TimersAndConstants_t301                = "ms1000";
+      ue_TimersAndConstants_t310                = "ms1000";
+      ue_TimersAndConstants_t311                = "ms10000";
+      ue_TimersAndConstants_n310                = "n20";
+      ue_TimersAndConstants_n311                = "n1";
+      ue_TransmissionMode                       = "tm1";
+
+      # eMTC Parameters
+      emtc_parameters :
+      {
+          eMTC_configured                       = 1;
+          #hyperSFN_r13                               = 0;
+          #eDRX_Allowed_r13                           = 0;
+          #q_QualMinRSRQ_CE_r13                       = ;
+
+          #SIB1
+          schedulingInfoSIB1_BR_r13                   = 4;
+
+          #system_info_value_tag_SI =
+          #(
+          #    {
+          #        systemInfoValueTagSi_r13 = 0;
+          #    }
+          #);
+
+          cellSelectionInfoCE_r13                     = "ENABLE";
+          q_RxLevMinCE_r13                            = -70;
+          bandwidthReducedAccessRelatedInfo_r13       = "ENABLE"
+          si_WindowLength_BR_r13                      = "ms20";    #0
+          si_RepetitionPattern_r13                    = "everyRF"; #0
+
+          scheduling_info_br =
+          (
+              {
+                  si_Narrowband_r13 = 8;
+                  si_TBS_r13        = 5;
+              }
+         );
+
+          fdd_DownlinkOrTddSubframeBitmapBR_r13     = "subframePattern40-r13";
+          fdd_DownlinkOrTddSubframeBitmapBR_val_r13 = 0xFFFFFFFFFF;
+          startSymbolBR_r13                           = 2;
+          si_HoppingConfigCommon_r13                  = "off"; #1; # Note: 1==OFF !
+          si_ValidityTime_r13                         = "true"; #0
+
+          freqHoppingParametersDL_r13                 = "DISABLE"
+          mpdcch_pdsch_HoppingNB_r13                  = "nb2"; #0
+          interval_DLHoppingConfigCommonModeA_r13     = "interval-FDD-r13"
+          interval_DLHoppingConfigCommonModeA_r13_val = 0;
+          interval_DLHoppingConfigCommonModeB_r13     = "interval-FDD-r13"
+          interval_DLHoppingConfigCommonModeB_r13_val = 0;
+          mpdcch_pdsch_HoppingOffset_r13              = 1;
+
+
+          # SIB23
+          frame_type                                = "FDD";
+          preambleTransMax_CE_r13                   = 10; #6
+
+          rach_numberOfRA_Preambles                 = 60; #14
+          rach_powerRampingStep                     = 4;
+          rach_preambleInitialReceivedTargetPower   = -110;
+          rach_preambleTransMax                     = 10;
+          rach_raResponseWindowSize                 = 10;
+          rach_macContentionResolutionTimer         = 64;
+          rach_maxHARQ_Msg3Tx                       = 4;
+
+          # max size for this array is 4
+          rach_CE_LevelInfoList_r13 =
+          (
+              {
+                  firstPreamble_r13                 = 60;
+                  lastPreamble_r13                  = 63;
+                  ra_ResponseWindowSize_r13         = 20; #0
+                  mac_ContentionResolutionTimer_r13 = 80; #0
+                  rar_HoppingConfig_r13             = "off";  #1;
+              }
+          );
+
+          # BCCH CONFIG
+          bcch_modificationPeriodCoeff              = 2;
+
+          #PCCH Config
+          pcch_default_PagingCycle                  = "rf128"; #128
+          pcch_nB                                   = "oneT";
+
+          #PRACH Config
+          prach_root                                = 89;
+          prach_config_index                        = 0;
+          prach_high_speed                          = "DISABLE";
+          prach_zero_correlation                    = 1;
+          prach_freq_offset                         = 1;
+
+          #PDSCH Config Common
+          pdsch_referenceSignalPower                = -27
+          pdsch_p_b                                 = 0;
+
+
+          # PUSCH Config Common
+          pusch_n_SB                                = 1;
+          pusch_hoppingMode                         = "interSubFrame";
+          pusch_hoppingOffset                       = 0;
+          pusch_enable64QAM                         = "DISABLE";
+          pusch_groupHoppingEnabled                 = "ENABLE";
+          pusch_groupAssignment                     = 0;
+          pusch_sequenceHoppingEnabled              = "DISABLE";
+          pusch_nDMRS1                              = 1;
+
+          # PUCCH Config Common
+          pucch_delta_shift                         = 1;
+          pucch_nRB_CQI                             = 0;
+          pucch_nCS_AN                              = 0;
+          pucch_n1_AN                               = 32;
+
+          pusch_p0_Nominal                          = -96;
+          pusch_alpha                               = "AL1";
+          pucch_p0_Nominal                          = -104;
+          pucch_deltaF_Format1                      = "deltaF0";
+          pucch_deltaF_Format1b                     = "deltaF3";
+          pucch_deltaF_Format2                      = "deltaF0";
+          pucch_deltaF_Format2a                     = "deltaF0";
+          pucch_deltaF_Format2b                     = "deltaF0";
+
+          msg3_delta_Preamble                       = 6;
+
+
+          prach_ConfigCommon_v1310                  = "ENABLE";
+
+          mpdcch_startSF_CSS_RA_r13                 = "fdd-r13";
+          mpdcch_startSF_CSS_RA_r13_val             = "v1"; #0
+          prach_HoppingOffset_r13                   = 0;
+
+
+          pdsch_maxNumRepetitionCEmodeA_r13         = "r16"; #0
+          #pdsch_maxNumRepetitionCEmodeB_r13         = "r384"; # NULL - 2
+
+          pusch_maxNumRepetitionCEmodeA_r13         = "r8"; #0
+          #pusch_maxNumRepetitionCEmodeB_r13         = "r768"; #4 #NULL
+          #pusch_HoppingOffset_v1310                 = 5; #NULL
+
+          # max size for this array is 3
+          rsrp_range_list =
+          (
+              {
+                  rsrp_range_br = 0;
+              }
+          );
+
+          # max size for this array is 4
+          prach_parameters_ce_r13 =
+          (
+              {
+                  prach_config_index_br                     = 3;
+                  prach_freq_offset_br                      = 2;
+                  prach_StartingSubframe_r13                = 2;
+                  maxNumPreambleAttemptCE_r13               = 10; #6
+                  numRepetitionPerPreambleAttempt_r13       = 1;  #0
+                  mpdcch_NumRepetition_RA_r13               = 1;  #0
+                  prach_HoppingConfig_r13                   = 0;  #1
+                  max_available_narrow_band                 = [3];
+             }
+          );
+
+          n1PUCCH_AN_InfoList_r13 =
+          (
+              {
+                  pucch_info_value = 0;
+              }
+          );
+
+
+          ue_TimersAndConstants_t300                = "ms1000";
+          ue_TimersAndConstants_t301                = "ms400";
+          ue_TimersAndConstants_t310                = "ms50";
+          ue_TimersAndConstants_t311                = "ms30000";
+          ue_TimersAndConstants_n310                = "n1";
+          ue_TimersAndConstants_n311                = "n10";
+          ue_TransmissionMode                       = "tm1";
+
+          pcch_config_v1310 :
+          {
+              paging_narrowbands_r13           = 1;
+              mpdcch_numrepetition_paging_r13  = "r1";         #0
+              #nb_v1310                        = "one256thT";  #2
+          }
+
+
+          pucch_NumRepetitionCE_Msg4_Level0_r13      = "n1";  #0
+          #pucch_NumRepetitionCE_Msg4_Level1_r13     = "n2";  #1
+          #pucch_NumRepetitionCE_Msg4_Level2_r13     = "n16"; #2
+          #pucch_NumRepetitionCE_Msg4_Level3_r13     = "n32"; #3
+
+          sib2_freq_hoppingParameters_r13 :
+          {
+             #sib2_mpdcch_pdsch_hoppingNB_r13                   = "nb2"; #0
+             #sib2_interval_DLHoppingConfigCommonModeA_r13      = "FDD"; # choice -> (0, FDD) (1, TDD)
+             #sib2_interval_DLHoppingConfigCommonModeA_r13_val  = "int1";
+             #sib2_interval_DLHoppingConfigCommonModeB_r13      = "FDD"; # choice -> (0, FDD) (1, TDD)
+             #sib2_interval_DLHoppingConfigCommonModeB_r13_val  = "int2";
+
+             sib2_interval_ULHoppingConfigCommonModeA_r13      = "FDD";  # choice -> (0, FDD) (1, TDD)
+             sib2_interval_ULHoppingConfigCommonModeA_r13_val  = "int4"; #2
+#            sib2_interval_ULHoppingConfigCommonModeB_r13      = "FDD";  # choice -> (0, FDD) (1, TDD)
+#            sib2_interval_ULHoppingConfigCommonModeB_r13_val  = "int2"; #0
+
+#             sib2_mpdcch_pdsch_hoppingOffset_r13               = 1;
+          }
+
+          rach_preamblesGroupAConfig                = "DISABLE";
+
+          phich_duration                            = "NORMAL";
+          phich_resource                            = "ONESIXTH";
+          srs_enable                                = "DISABLE";
+
+      }
+
+
+
+}
+
+
+
+
+    );
+
+
+    srb1_parameters :
+    {
+        # timer_poll_retransmit = (ms) [5, 10, 15, 20,... 250, 300, 350, ... 500]
+        timer_poll_retransmit    = 80;
+
+        # timer_reordering = (ms) [0,5, ... 100, 110, 120, ... ,200]
+        timer_reordering         = 35;
+
+        # timer_reordering = (ms) [0,5, ... 250, 300, 350, ... ,500]
+        timer_status_prohibit    = 0;
+
+        # poll_pdu = [4, 8, 16, 32 , 64, 128, 256, infinity(>10000)]
+        poll_pdu                 =  4;
+
+        # poll_byte = (kB) [25,50,75,100,125,250,375,500,750,1000,1250,1500,2000,3000,infinity(>10000)]
+        poll_byte                =  99999;
+
+        # max_retx_threshold = [1, 2, 3, 4 , 6, 8, 16, 32]
+        max_retx_threshold       =  4;
+    }
+
+    # ------- SCTP definitions
+    SCTP :
+    {
+        # Number of streams to use in input/output
+        SCTP_INSTREAMS  = 2;
+        SCTP_OUTSTREAMS = 2;
+    };
+
+
+    ////////// MME parameters:
+    mme_ip_address      = ( { ipv4       = "CI_MME_IP_ADDR";
+                              ipv6       = "192:168:30::17";
+                              active     = "yes";
+                              preference = "ipv4";
+                            }
+                          );
+
+    NETWORK_INTERFACES :
+    {
+        ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
+        ENB_IPV4_ADDRESS_FOR_S1_MME              = "CI_ENB_IP_ADDR";
+        ENB_INTERFACE_NAME_FOR_S1U               = "eth0";
+        ENB_IPV4_ADDRESS_FOR_S1U                 = "CI_ENB_IP_ADDR";
+        ENB_PORT_FOR_S1U                         = 2152; # Spec 2152
+        ENB_IPV4_ADDRESS_FOR_X2C                 = "CI_ENB_IP_ADDR";
+        ENB_PORT_FOR_X2C                         = 36422; # Spec 36422
+    };
+
+    log_config :
+    {
+      global_log_level                      ="info";
+      global_log_verbosity                  ="medium";
+      hw_log_level                          ="info";
+      hw_log_verbosity                      ="medium";
+      phy_log_level                         ="info";
+      phy_log_verbosity                     ="medium";
+      mac_log_level                         ="info";
+      mac_log_verbosity                     ="high";
+      rlc_log_level                         ="info";
+      rlc_log_verbosity                     ="medium";
+      pdcp_log_level                        ="info";
+      pdcp_log_verbosity                    ="medium";
+      rrc_log_level                         ="info";
+      rrc_log_verbosity                     ="medium";
+   };
+  }
+);
+
+MACRLCs = (
+        {
+        num_cc	 = 1;
+        tr_s_preference = "local_L1";
+        tr_n_preference = "local_RRC";
+	phy_test_mode = 0;
+        puSch10xSnr     =  200;
+        puCch10xSnr     =  200;
+        }
+);
+
+L1s = (
+      {
+      num_cc = 1;
+      tr_n_preference = "local_mac";
+      }
+);
+
+RUs = (
+    {
+        local_rf       = "yes"
+        nb_tx          = 1
+        nb_rx          = 1
+        att_tx         = 0
+        att_rx         = 0;
+        bands          = [13];
+        max_pdschReferenceSignalPower = -27;
+        max_rxgain                    = 125;
+        eNB_instances  = [0];
+    }
+);
+
+log_config :
+     {
+       global_log_level                      ="info";
+       global_log_verbosity                  ="medium";
+       hw_log_level                          ="info";
+       hw_log_verbosity                      ="medium";
+       phy_log_level                         ="info";
+       phy_log_verbosity                     ="medium";
+       mac_log_level                         ="info";
+       mac_log_verbosity                     ="high";
+       rlc_log_level                         ="info";
+       rlc_log_verbosity                     ="medium";
+       pdcp_log_level                        ="info";
+       pdcp_log_verbosity                    ="medium";
+       rrc_log_level                         ="info";
+       rrc_log_verbosity                     ="medium";
+    };
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 ec968e8cefde3241f81e74abb43af82ce5d0298a..b6028a81524f3a745485680a9660c5632d09278e 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
@@ -134,7 +134,7 @@ eNBs =
     };
 
     ////////// MME parameters:
-    mme_ip_address      = ( { ipv4       = "10.0.0.2";
+    mme_ip_address      = ( { ipv4       = "CI_MME_IP_ADDR";
                               ipv6       = "192:168:30::17";
                               active     = "yes";
                               preference = "ipv4";
@@ -144,13 +144,11 @@ eNBs =
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
-        ENB_IPV4_ADDRESS_FOR_S1_MME              = "10.0.0.1/24";
-
+        ENB_IPV4_ADDRESS_FOR_S1_MME              = "CI_ENB_IP_ADDR";
         ENB_INTERFACE_NAME_FOR_S1U               = "eth0";
-        ENB_IPV4_ADDRESS_FOR_S1U                 = "10.0.0.1/24";
+        ENB_IPV4_ADDRESS_FOR_S1U                 = "CI_ENB_IP_ADDR";
         ENB_PORT_FOR_S1U                         = 2152; # Spec 2152
-
-        ENB_IPV4_ADDRESS_FOR_X2C                 = "192.168.12.111/24";
+        ENB_IPV4_ADDRESS_FOR_X2C                 = "CI_ENB_IP_ADDR";
         ENB_PORT_FOR_X2C                         = 36422; # Spec 36422
     };
 
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 c2f69cb1b9680cc6a609174e0a818e0ca6533552..10cbd04e9a0fbe7b3bb0202de805734ea499dcb3 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
@@ -134,7 +134,7 @@ eNBs =
     };
 
     ////////// MME parameters:
-    mme_ip_address      = ( { ipv4       = "10.0.0.2";
+    mme_ip_address      = ( { ipv4       = "CI_MME_IP_ADDR";
                               ipv6       = "192:168:30::17";
                               active     = "yes";
                               preference = "ipv4";
@@ -144,13 +144,11 @@ eNBs =
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
-        ENB_IPV4_ADDRESS_FOR_S1_MME              = "10.0.0.1/24";
-
+        ENB_IPV4_ADDRESS_FOR_S1_MME              = "CI_ENB_IP_ADDR";
         ENB_INTERFACE_NAME_FOR_S1U               = "eth0";
-        ENB_IPV4_ADDRESS_FOR_S1U                 = "10.0.0.1/24";
+        ENB_IPV4_ADDRESS_FOR_S1U                 = "CI_ENB_IP_ADDR";
         ENB_PORT_FOR_S1U                         = 2152; # Spec 2152
-
-        ENB_IPV4_ADDRESS_FOR_X2C                 = "192.168.12.111/24";
+        ENB_IPV4_ADDRESS_FOR_X2C                 = "CI_ENB_IP_ADDR";
         ENB_PORT_FOR_X2C                         = 36422; # Spec 36422
     };
 
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 6bdbd4e39b7ff0d5a9d9d7853b967aaa81529e9c..c79dbf1ac04921d47f955a79725053cc026c6030 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
@@ -134,7 +134,7 @@ eNBs =
     };
 
     ////////// MME parameters:
-    mme_ip_address      = ( { ipv4       = "10.0.0.2";
+    mme_ip_address      = ( { ipv4       = "CI_MME_IP_ADDR";
                               ipv6       = "192:168:30::17";
                               active     = "yes";
                               preference = "ipv4";
@@ -144,13 +144,11 @@ eNBs =
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
-        ENB_IPV4_ADDRESS_FOR_S1_MME              = "10.0.0.1/24";
-
+        ENB_IPV4_ADDRESS_FOR_S1_MME              = "CI_ENB_IP_ADDR";
         ENB_INTERFACE_NAME_FOR_S1U               = "eth0";
-        ENB_IPV4_ADDRESS_FOR_S1U                 = "10.0.0.1/24";
+        ENB_IPV4_ADDRESS_FOR_S1U                 = "CI_ENB_IP_ADDR";
         ENB_PORT_FOR_S1U                         = 2152; # Spec 2152
-
-        ENB_IPV4_ADDRESS_FOR_X2C                 = "192.168.12.111/24";
+        ENB_IPV4_ADDRESS_FOR_X2C                 = "CI_ENB_IP_ADDR";
         ENB_PORT_FOR_X2C                         = 36422; # Spec 36422
     };
 
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 1a566e957900cc5334d7996a60934314213904cb..2c2ca635a6d7035261f1b65a1ce30add15caae08 100644
--- a/ci-scripts/conf_files/enb.band7.tm1.100PRB.usrpb210.conf
+++ b/ci-scripts/conf_files/enb.band7.tm1.100PRB.usrpb210.conf
@@ -171,7 +171,7 @@ eNBs =
 
 
     ////////// MME parameters:
-    mme_ip_address      = ( { ipv4       = "192.168.12.26";
+    mme_ip_address      = ( { ipv4       = "CI_MME_IP_ADDR";
                               ipv6       = "192:168:30::17";
                               active     = "yes";
                               preference = "ipv4";
@@ -181,12 +181,11 @@ eNBs =
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
-        ENB_IPV4_ADDRESS_FOR_S1_MME              = "192.168.12.111/24";
+        ENB_IPV4_ADDRESS_FOR_S1_MME              = "CI_ENB_IP_ADDR";
         ENB_INTERFACE_NAME_FOR_S1U               = "eth0";
-        ENB_IPV4_ADDRESS_FOR_S1U                 = "192.168.12.111/24";
+        ENB_IPV4_ADDRESS_FOR_S1U                 = "CI_ENB_IP_ADDR";
         ENB_PORT_FOR_S1U                         = 2152; # Spec 2152
-
-        ENB_IPV4_ADDRESS_FOR_X2C                 = "192.168.12.111/24";
+        ENB_IPV4_ADDRESS_FOR_X2C                 = "CI_ENB_IP_ADDR";
         ENB_PORT_FOR_X2C                         = 36422; # Spec 36422
     };
   }
@@ -198,8 +197,8 @@ MACRLCs = (
 	tr_s_preference = "local_L1";
 	tr_n_preference = "local_RRC";
 	phy_test_mode = 0;
-        puSch10xSnr     =  200;
-        puCch10xSnr     =  200;
+        puSch10xSnr     =  160;
+        puCch10xSnr     =  160;
         }  
 );
 
@@ -228,7 +227,7 @@ RUs = (
 THREAD_STRUCT = (
   {
     #three config for level of parallelism "PARALLEL_SINGLE_THREAD", "PARALLEL_RU_L1_SPLIT", or "PARALLEL_RU_L1_TRX_SPLIT"
-    parallel_config    = "PARALLEL_RU_L1_TRX_SPLIT";
+    parallel_config    = "PARALLEL_SINGLE_THREAD";
     #two option for worker "WORKER_DISABLE" or "WORKER_ENABLE"
     worker_config      = "WORKER_ENABLE";
   }
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 fd49fe9d837b6a7a2d0a8b6dd2da863f47c16b12..4dd8c1ee22d9dd88003bf5b74dfd859f606a2a7e 100644
--- a/ci-scripts/conf_files/enb.band7.tm1.25PRB.usrpb210.conf
+++ b/ci-scripts/conf_files/enb.band7.tm1.25PRB.usrpb210.conf
@@ -171,7 +171,7 @@ eNBs =
 
 
     ////////// MME parameters:
-    mme_ip_address      = ( { ipv4       = "192.168.12.26";
+    mme_ip_address      = ( { ipv4       = "CI_MME_IP_ADDR";
                               ipv6       = "192:168:30::17";
                               active     = "yes";
                               preference = "ipv4";
@@ -181,12 +181,11 @@ eNBs =
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
-        ENB_IPV4_ADDRESS_FOR_S1_MME              = "192.168.12.111/24";
+        ENB_IPV4_ADDRESS_FOR_S1_MME              = "CI_ENB_IP_ADDR";
         ENB_INTERFACE_NAME_FOR_S1U               = "eth0";
-        ENB_IPV4_ADDRESS_FOR_S1U                 = "192.168.12.111/24";
+        ENB_IPV4_ADDRESS_FOR_S1U                 = "CI_ENB_IP_ADDR";
         ENB_PORT_FOR_S1U                         = 2152; # Spec 2152
-
-        ENB_IPV4_ADDRESS_FOR_X2C                 = "192.168.12.111/24";
+        ENB_IPV4_ADDRESS_FOR_X2C                 = "CI_ENB_IP_ADDR";
         ENB_PORT_FOR_X2C                         = 36422; # Spec 36422
     };
   }
@@ -198,8 +197,8 @@ MACRLCs = (
 	tr_s_preference = "local_L1";
 	tr_n_preference = "local_RRC";
 	phy_test_mode = 0;
-        puSch10xSnr     =  200;
-        puCch10xSnr     =  200;
+        puSch10xSnr     =  160;
+        puCch10xSnr     =  160;
         }  
 );
 
@@ -219,7 +218,7 @@ RUs = (
          att_rx         = 0;
          bands          = [7];
          max_pdschReferenceSignalPower = -27;
-         max_rxgain                    = 115;
+         max_rxgain                    = 125;
          eNB_instances  = [0];
 
     }
@@ -228,7 +227,7 @@ RUs = (
 THREAD_STRUCT = (
   {
     #three config for level of parallelism "PARALLEL_SINGLE_THREAD", "PARALLEL_RU_L1_SPLIT", or "PARALLEL_RU_L1_TRX_SPLIT"
-    parallel_config    = "PARALLEL_RU_L1_TRX_SPLIT";
+    parallel_config    = "PARALLEL_SINGLE_THREAD";
     #two option for worker "WORKER_DISABLE" or "WORKER_ENABLE"
     worker_config      = "WORKER_ENABLE";
   }
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 1613dd4c320170e2518aaacb698aa578589f7af0..cae47b152c2129a67b5f090fc1c352035b7e0048 100644
--- a/ci-scripts/conf_files/enb.band7.tm1.50PRB.usrpb210.conf
+++ b/ci-scripts/conf_files/enb.band7.tm1.50PRB.usrpb210.conf
@@ -171,7 +171,7 @@ eNBs =
 
 
     ////////// MME parameters:
-    mme_ip_address      = ( { ipv4       = "192.168.12.26";
+    mme_ip_address      = ( { ipv4       = "CI_MME_IP_ADDR";
                               ipv6       = "192:168:30::17";
                               active     = "yes";
                               preference = "ipv4";
@@ -181,12 +181,11 @@ eNBs =
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
-        ENB_IPV4_ADDRESS_FOR_S1_MME              = "192.168.12.111/24";
+        ENB_IPV4_ADDRESS_FOR_S1_MME              = "CI_ENB_IP_ADDR";
         ENB_INTERFACE_NAME_FOR_S1U               = "eth0";
-        ENB_IPV4_ADDRESS_FOR_S1U                 = "192.168.12.111/24";
+        ENB_IPV4_ADDRESS_FOR_S1U                 = "CI_ENB_IP_ADDR";
         ENB_PORT_FOR_S1U                         = 2152; # Spec 2152
-
-        ENB_IPV4_ADDRESS_FOR_X2C                 = "192.168.12.111/24";
+        ENB_IPV4_ADDRESS_FOR_X2C                 = "CI_ENB_IP_ADDR";
         ENB_PORT_FOR_X2C                         = 36422; # Spec 36422
     };
   }
@@ -198,8 +197,8 @@ MACRLCs = (
 	tr_s_preference = "local_L1";
 	tr_n_preference = "local_RRC";
 	phy_test_mode = 0;
-        puSch10xSnr     =  200;
-        puCch10xSnr     =  200;
+        puSch10xSnr     =  160;
+        puCch10xSnr     =  160;
         }  
 );
 
@@ -219,7 +218,7 @@ RUs = (
          att_rx         = 0;
          bands          = [7];
          max_pdschReferenceSignalPower = -27;
-         max_rxgain                    = 115;
+         max_rxgain                    = 120;
          eNB_instances  = [0];
 
     }
@@ -228,7 +227,7 @@ RUs = (
 THREAD_STRUCT = (
   {
     #three config for level of parallelism "PARALLEL_SINGLE_THREAD", "PARALLEL_RU_L1_SPLIT", or "PARALLEL_RU_L1_TRX_SPLIT"
-    parallel_config    = "PARALLEL_RU_L1_TRX_SPLIT";
+    parallel_config    = "PARALLEL_SINGLE_THREAD";
     #two option for worker "WORKER_DISABLE" or "WORKER_ENABLE"
     worker_config      = "WORKER_ENABLE";
   }
diff --git a/ci-scripts/conf_files/enb.band7.tm2.25PRB.usrpb210.conf b/ci-scripts/conf_files/enb.band7.tm2.25PRB.usrpb210.conf
new file mode 100644
index 0000000000000000000000000000000000000000..8da70de42356f245ee9aa67080ef5762c5e8387a
--- /dev/null
+++ b/ci-scripts/conf_files/enb.band7.tm2.25PRB.usrpb210.conf
@@ -0,0 +1,264 @@
+Active_eNBs = ( "eNB-Eurecom-LTEBox");
+# Asn1_verbosity, choice in: none, info, annoying
+Asn1_verbosity = "none";
+
+eNBs =
+(
+ {
+    ////////// Identification parameters:
+    eNB_ID    =  0xe00;
+
+    cell_type =  "CELL_MACRO_ENB";
+
+    eNB_name  =  "eNB-Eurecom-LTEBox";
+
+    // Tracking area code, 0x0000 and 0xfffe are reserved values
+    tracking_area_code = 1;
+    plmn_list = ( { mcc = 208; mnc = 92; mnc_length = 2; } );
+
+    tr_s_preference     = "local_mac"
+
+    ////////// Physical parameters:
+
+    component_carriers = (
+      {
+      node_function                 = "3GPP_eNODEB";
+      node_timing                   = "synch_to_ext_device";
+      node_synch_ref                = 0;
+      frame_type                    = "FDD";
+      tdd_config                    = 3;
+      tdd_config_s                  = 0;
+      prefix_type                   = "NORMAL";
+      eutra_band                    = 7;
+      downlink_frequency            = 2680000000L;
+      uplink_frequency_offset       = -120000000;
+      Nid_cell                      = 0;
+      N_RB_DL                       = 25;
+      Nid_cell_mbsfn                = 0;
+      nb_antenna_ports              = 2;
+      nb_antennas_tx                = 2;
+      nb_antennas_rx                = 2;
+      tx_gain                       = 90;
+      rx_gain                       = 125;
+      pbch_repetition               = "FALSE";
+      prach_root                    = 0;
+      prach_config_index            = 0;
+      prach_high_speed              = "DISABLE";
+      prach_zero_correlation        = 1;
+      prach_freq_offset             = 2;
+      pucch_delta_shift             = 1;
+      pucch_nRB_CQI                 = 0;
+      pucch_nCS_AN                  = 0;
+      pucch_n1_AN                   = 0;
+      pdsch_referenceSignalPower    = -25;
+      pdsch_p_b                     = 0;
+      pusch_n_SB                    = 1;
+      pusch_enable64QAM             = "DISABLE";
+      pusch_hoppingMode             = "interSubFrame";
+      pusch_hoppingOffset           = 0;
+      pusch_groupHoppingEnabled     = "ENABLE";
+      pusch_groupAssignment         = 0;
+      pusch_sequenceHoppingEnabled  = "DISABLE";
+      pusch_nDMRS1                  = 1;
+      phich_duration                = "NORMAL";
+      phich_resource                = "ONESIXTH";
+      srs_enable                    = "DISABLE";
+      /*
+      srs_BandwidthConfig           =;
+      srs_SubframeConfig            =;
+      srs_ackNackST                 =;
+      srs_MaxUpPts                  =;
+      */
+
+      pusch_p0_Nominal              = -96;
+      pusch_alpha                   = "AL1";
+      pucch_p0_Nominal              = -104;
+      msg3_delta_Preamble           = 6;
+      pucch_deltaF_Format1          = "deltaF2";
+      pucch_deltaF_Format1b         = "deltaF3";
+      pucch_deltaF_Format2          = "deltaF0";
+      pucch_deltaF_Format2a         = "deltaF0";
+      pucch_deltaF_Format2b         = "deltaF0";
+
+      rach_numberOfRA_Preambles               = 64;
+      rach_preamblesGroupAConfig              = "DISABLE";
+      /*
+      rach_sizeOfRA_PreamblesGroupA           = ;
+      rach_messageSizeGroupA                  = ;
+      rach_messagePowerOffsetGroupB           = ;
+      */
+      rach_powerRampingStep                   = 4;
+      rach_preambleInitialReceivedTargetPower = -108;
+      rach_preambleTransMax                   = 10;
+      rach_raResponseWindowSize               = 10;
+      rach_macContentionResolutionTimer       = 48;
+      rach_maxHARQ_Msg3Tx                     = 4;
+
+      pcch_default_PagingCycle      = 128;
+      pcch_nB                       = "oneT";
+      bcch_modificationPeriodCoeff  = 2;
+      ue_TimersAndConstants_t300    = 1000;
+      ue_TimersAndConstants_t301    = 1000;
+      ue_TimersAndConstants_t310    = 1000;
+      ue_TimersAndConstants_t311    = 10000;
+      ue_TimersAndConstants_n310    = 20;
+      ue_TimersAndConstants_n311    = 1;
+      ue_TransmissionMode           = 2;
+
+      //Parameters for SIB18
+      rxPool_sc_CP_Len                                                = "normal";
+      rxPool_sc_Period                                                = "sf40";
+      rxPool_data_CP_Len                                              = "normal";
+      rxPool_ResourceConfig_prb_Num                                   = 20;
+      rxPool_ResourceConfig_prb_Start                                 = 5;
+      rxPool_ResourceConfig_prb_End                                   = 44;
+      rxPool_ResourceConfig_offsetIndicator_present                   = "prSmall";
+      rxPool_ResourceConfig_offsetIndicator_choice                    = 0;
+      rxPool_ResourceConfig_subframeBitmap_present                    = "prBs40";
+      rxPool_ResourceConfig_subframeBitmap_choice_bs_buf              = "00000000000000000000";
+      rxPool_ResourceConfig_subframeBitmap_choice_bs_size             = 5;
+      rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused      = 0;
+/*
+      rxPool_dataHoppingConfig_hoppingParameter                       = 0;
+      rxPool_dataHoppingConfig_numSubbands                            = "ns1";
+      rxPool_dataHoppingConfig_rbOffset                               = 0;
+      rxPool_commTxResourceUC-ReqAllowed                              = "TRUE";
+*/
+      // Parameters for SIB19
+      discRxPool_cp_Len                                               = "normal"
+      discRxPool_discPeriod                                           = "rf32"
+      discRxPool_numRetx                                              = 1;
+      discRxPool_numRepetition                                        = 2;
+      discRxPool_ResourceConfig_prb_Num                               = 5;
+      discRxPool_ResourceConfig_prb_Start                             = 3;
+      discRxPool_ResourceConfig_prb_End                               = 21;
+      discRxPool_ResourceConfig_offsetIndicator_present               = "prSmall";
+      discRxPool_ResourceConfig_offsetIndicator_choice                = 0;
+      discRxPool_ResourceConfig_subframeBitmap_present                = "prBs40";
+      discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf          = "f0ffffffff";
+      discRxPool_ResourceConfig_subframeBitmap_choice_bs_size         = 5;
+      discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused  = 0;
+
+      }
+    );
+
+
+    srb1_parameters :
+    {
+        # timer_poll_retransmit = (ms) [5, 10, 15, 20,... 250, 300, 350, ... 500]
+        timer_poll_retransmit    = 80;
+
+        # timer_reordering = (ms) [0,5, ... 100, 110, 120, ... ,200]
+        timer_reordering         = 35;
+
+        # timer_reordering = (ms) [0,5, ... 250, 300, 350, ... ,500]
+        timer_status_prohibit    = 0;
+
+        # poll_pdu = [4, 8, 16, 32 , 64, 128, 256, infinity(>10000)]
+        poll_pdu                 =  4;
+
+        # poll_byte = (kB) [25,50,75,100,125,250,375,500,750,1000,1250,1500,2000,3000,infinity(>10000)]
+        poll_byte                =  99999;
+
+        # max_retx_threshold = [1, 2, 3, 4 , 6, 8, 16, 32]
+        max_retx_threshold       =  4;
+    }
+
+    # ------- SCTP definitions
+    SCTP :
+    {
+        # Number of streams to use in input/output
+        SCTP_INSTREAMS  = 2;
+        SCTP_OUTSTREAMS = 2;
+    };
+
+
+    ////////// MME parameters:
+    mme_ip_address      = ( { ipv4       = "CI_MME_IP_ADDR";
+                              ipv6       = "192:168:30::17";
+                              active     = "yes";
+                              preference = "ipv4";
+                            }
+                          );
+
+    NETWORK_INTERFACES :
+    {
+        ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
+        ENB_IPV4_ADDRESS_FOR_S1_MME              = "CI_ENB_IP_ADDR";
+        ENB_INTERFACE_NAME_FOR_S1U               = "eth0";
+        ENB_IPV4_ADDRESS_FOR_S1U                 = "CI_ENB_IP_ADDR";
+        ENB_PORT_FOR_S1U                         = 2152; # Spec 2152
+        ENB_IPV4_ADDRESS_FOR_X2C                 = "CI_ENB_IP_ADDR";
+        ENB_PORT_FOR_X2C                         = 36422; # Spec 36422
+    };
+  }
+);
+
+MACRLCs = (
+    {
+    num_cc = 1;
+    tr_s_preference = "local_L1";
+    tr_n_preference = "local_RRC";
+    phy_test_mode   = 0;
+    puSch10xSnr     = 200;
+    puCch10xSnr     = 200;
+    }
+);
+
+L1s = (
+    {
+    num_cc = 1;
+    tr_n_preference = "local_mac";
+    }
+);
+
+RUs = (
+    {
+    local_rf                      = "yes"
+    nb_tx                         = 2
+    nb_rx                         = 2
+    att_tx                        = 0
+    att_rx                        = 0;
+    bands                         = [7];
+    max_pdschReferenceSignalPower = -27;
+    max_rxgain                    = 115;
+    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_RU_L1_TRX_SPLIT";
+    #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";
+       global_log_verbosity                  ="medium";
+       hw_log_level                          ="info";
+       hw_log_verbosity                      ="medium";
+       phy_log_level                         ="info";
+       phy_log_verbosity                     ="medium";
+       mac_log_level                         ="info";
+       mac_log_verbosity                     ="high";
+       rlc_log_level                         ="info";
+       rlc_log_verbosity                     ="medium";
+       pdcp_log_level                        ="info";
+       pdcp_log_verbosity                    ="medium";
+       rrc_log_level                         ="info";
+       rrc_log_verbosity                     ="medium";
+    };
diff --git a/ci-scripts/conf_files/lte-fdd-basic-sim.conf b/ci-scripts/conf_files/lte-fdd-basic-sim.conf
index 882037b7e24bf6dd37b0440288f9bdbd363a4f96..5d9b9016749ca7ed741ef12d137e39f56b86bcd8 100644
--- a/ci-scripts/conf_files/lte-fdd-basic-sim.conf
+++ b/ci-scripts/conf_files/lte-fdd-basic-sim.conf
@@ -186,7 +186,6 @@ eNBs =
         ENB_INTERFACE_NAME_FOR_S1U               = "eth0";
         ENB_IPV4_ADDRESS_FOR_S1U                 = "CI_ENB_IP_ADDR";
         ENB_PORT_FOR_S1U                         = 2152; # Spec 2152
-
         ENB_IPV4_ADDRESS_FOR_X2C                 = "CI_ENB_IP_ADDR";
         ENB_PORT_FOR_X2C                         = 36422; # Spec 36422
     };
@@ -238,8 +237,8 @@ THREAD_STRUCT = (
 NETWORK_CONTROLLER :
 {
     FLEXRAN_ENABLED        = "no";
-    FLEXRAN_INTERFACE_NAME = "lo";
-    FLEXRAN_IPV4_ADDRESS   = "127.0.0.1";
+    FLEXRAN_INTERFACE_NAME = "ens3";
+    FLEXRAN_IPV4_ADDRESS   = "CI_FLEXRAN_CTL_IP_ADDR";
     FLEXRAN_PORT           = 2210;
     FLEXRAN_CACHE          = "/mnt/oai_agent_cache";
     FLEXRAN_AWAIT_RECONF   = "no";
diff --git a/ci-scripts/conf_files/lte-tdd-basic-sim.conf b/ci-scripts/conf_files/lte-tdd-basic-sim.conf
index 9f37b9de6b302ba942add7c1d37d3a35a13c4f41..c1bea306e50fa4d6529ed7318ce55fd19a396a85 100644
--- a/ci-scripts/conf_files/lte-tdd-basic-sim.conf
+++ b/ci-scripts/conf_files/lte-tdd-basic-sim.conf
@@ -145,11 +145,9 @@ eNBs =
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
         ENB_IPV4_ADDRESS_FOR_S1_MME              = "CI_ENB_IP_ADDR";
-
         ENB_INTERFACE_NAME_FOR_S1U               = "eth0";
         ENB_IPV4_ADDRESS_FOR_S1U                 = "CI_ENB_IP_ADDR";
         ENB_PORT_FOR_S1U                         = 2152; # Spec 2152
-
         ENB_IPV4_ADDRESS_FOR_X2C                 = "CI_ENB_IP_ADDR";
         ENB_PORT_FOR_X2C                         = 36422; # Spec 36422
     };
@@ -219,8 +217,8 @@ THREAD_STRUCT = (
 NETWORK_CONTROLLER :
 {
     FLEXRAN_ENABLED        = "no";
-    FLEXRAN_INTERFACE_NAME = "lo";
-    FLEXRAN_IPV4_ADDRESS   = "127.0.0.1";
+    FLEXRAN_INTERFACE_NAME = "ens3";
+    FLEXRAN_IPV4_ADDRESS   = "CI_FLEXRAN_CTL_IP_ADDR";
     FLEXRAN_PORT           = 2210;
     FLEXRAN_CACHE          = "/mnt/oai_agent_cache";
     FLEXRAN_AWAIT_RECONF   = "no";
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 8a77f7d613241b223938d381658a760f8da421a7..45b7a26e15d8fb25049b7edf11f2d4d192962206 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
@@ -137,7 +137,7 @@ eNBs =
     };
 
     ////////// MME parameters:
-    mme_ip_address      = ( { ipv4       = "10.0.0.2";
+    mme_ip_address      = ( { ipv4       = "CI_MME_IP_ADDR";
                               ipv6       = "192:168:30::17";
                               active     = "yes";
                               preference = "ipv4";
@@ -147,13 +147,11 @@ eNBs =
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
-        ENB_IPV4_ADDRESS_FOR_S1_MME              = "10.0.0.1/24";
-
+        ENB_IPV4_ADDRESS_FOR_S1_MME              = "CI_ENB_IP_ADDR";
         ENB_INTERFACE_NAME_FOR_S1U               = "eth0";
-        ENB_IPV4_ADDRESS_FOR_S1U                 = "10.0.0.1/24";
+        ENB_IPV4_ADDRESS_FOR_S1U                 = "CI_ENB_IP_ADDR";
         ENB_PORT_FOR_S1U                         = 2152; # Spec 2152
-
-        ENB_IPV4_ADDRESS_FOR_X2C                 = "192.168.12.111/24";
+        ENB_IPV4_ADDRESS_FOR_X2C                 = "CI_ENB_IP_ADDR";
         ENB_PORT_FOR_X2C                         = 36422; # Spec 36422
     };
 
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 b4b45c296cbd08862b99d375f07faf4886411ca9..7ed34f583ac80c39c29565ba9b76ccfa03e3e917 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
@@ -137,7 +137,7 @@ eNBs =
     };
 
     ////////// MME parameters:
-    mme_ip_address      = ( { ipv4       = "10.0.0.2";
+    mme_ip_address      = ( { ipv4       = "CI_MME_IP_ADDR";
                               ipv6       = "192:168:30::17";
                               active     = "yes";
                               preference = "ipv4";
@@ -147,13 +147,11 @@ eNBs =
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
-        ENB_IPV4_ADDRESS_FOR_S1_MME              = "10.0.0.1/24";
-
+        ENB_IPV4_ADDRESS_FOR_S1_MME              = "CI_ENB_IP_ADDR";
         ENB_INTERFACE_NAME_FOR_S1U               = "eth0";
-        ENB_IPV4_ADDRESS_FOR_S1U                 = "10.0.0.1/24";
+        ENB_IPV4_ADDRESS_FOR_S1U                 = "CI_ENB_IP_ADDR";
         ENB_PORT_FOR_S1U                         = 2152; # Spec 2152
-
-        ENB_IPV4_ADDRESS_FOR_X2C                 = "192.168.12.111/24";
+        ENB_IPV4_ADDRESS_FOR_X2C                 = "CI_ENB_IP_ADDR";
         ENB_PORT_FOR_X2C                         = 36422; # Spec 36422
     };
 
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 63dedfc2c80f1c0298dc3ee66f81b63eded251a1..d2eb83f74ab3254fec2f530d4037b09eabfa947f 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
@@ -137,7 +137,7 @@ eNBs =
     };
 
     ////////// MME parameters:
-    mme_ip_address      = ( { ipv4       = "10.0.0.2";
+    mme_ip_address      = ( { ipv4       = "CI_MME_IP_ADDR";
                               ipv6       = "192:168:30::17";
                               active     = "yes";
                               preference = "ipv4";
@@ -147,13 +147,11 @@ eNBs =
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
-        ENB_IPV4_ADDRESS_FOR_S1_MME              = "10.0.0.1/24";
-
+        ENB_IPV4_ADDRESS_FOR_S1_MME              = "CI_ENB_IP_ADDR";
         ENB_INTERFACE_NAME_FOR_S1U               = "eth0";
-        ENB_IPV4_ADDRESS_FOR_S1U                 = "10.0.0.1/24";
+        ENB_IPV4_ADDRESS_FOR_S1U                 = "CI_ENB_IP_ADDR";
         ENB_PORT_FOR_S1U                         = 2152; # Spec 2152
-
-        ENB_IPV4_ADDRESS_FOR_X2C                 = "192.168.12.111/24";
+        ENB_IPV4_ADDRESS_FOR_X2C                 = "CI_ENB_IP_ADDR";
         ENB_PORT_FOR_X2C                         = 36422; # Spec 36422
     };
 
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 584719dcac35a1f23363b45b529b7134f76b2add..3ed2f80b86b95b23dcb5e8122705dc3eebf8fde2 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
@@ -174,7 +174,7 @@ eNBs =
 
 
     ////////// MME parameters:
-    mme_ip_address      = ( { ipv4       = "192.168.12.26";
+    mme_ip_address      = ( { ipv4       = "CI_MME_IP_ADDR";
                               ipv6       = "192:168:30::17";
                               active     = "yes";
                               preference = "ipv4";
@@ -184,12 +184,11 @@ eNBs =
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
-        ENB_IPV4_ADDRESS_FOR_S1_MME              = "192.168.12.111/24";
+        ENB_IPV4_ADDRESS_FOR_S1_MME              = "CI_ENB_IP_ADDR";
         ENB_INTERFACE_NAME_FOR_S1U               = "eth0";
-        ENB_IPV4_ADDRESS_FOR_S1U                 = "192.168.12.111/24";
+        ENB_IPV4_ADDRESS_FOR_S1U                 = "CI_ENB_IP_ADDR";
         ENB_PORT_FOR_S1U                         = 2152; # Spec 2152
-
-        ENB_IPV4_ADDRESS_FOR_X2C                 = "192.168.12.111/24";
+        ENB_IPV4_ADDRESS_FOR_X2C                 = "CI_ENB_IP_ADDR";
         ENB_PORT_FOR_X2C                         = 36422; # Spec 36422
     };
   }
@@ -201,8 +200,8 @@ MACRLCs = (
 	tr_s_preference = "local_L1";
 	tr_n_preference = "local_RRC";
 	phy_test_mode = 0;
-        puSch10xSnr     =  200;
-        puCch10xSnr     =  200;
+        puSch10xSnr     =  160;
+        puCch10xSnr     =  160;
         }
 );
 
@@ -235,7 +234,7 @@ RUs = (
 THREAD_STRUCT = (
   {
     #three config for level of parallelism "PARALLEL_SINGLE_THREAD", "PARALLEL_RU_L1_SPLIT", or "PARALLEL_RU_L1_TRX_SPLIT"
-    parallel_config    = "PARALLEL_RU_L1_TRX_SPLIT";
+    parallel_config    = "PARALLEL_SINGLE_THREAD";
     #two option for worker "WORKER_DISABLE" or "WORKER_ENABLE"
     worker_config      = "WORKER_ENABLE";
   }
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 95055c43f89c12354139ab2676f75958a8924fed..8ac5eb7764b2ce504c69faa97167e70e9e47ffc0 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
@@ -174,7 +174,7 @@ eNBs =
 
 
     ////////// MME parameters:
-    mme_ip_address      = ( { ipv4       = "192.168.12.26";
+    mme_ip_address      = ( { ipv4       = "CI_MME_IP_ADDR";
                               ipv6       = "192:168:30::17";
                               active     = "yes";
                               preference = "ipv4";
@@ -184,12 +184,11 @@ eNBs =
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
-        ENB_IPV4_ADDRESS_FOR_S1_MME              = "192.168.12.111/24";
+        ENB_IPV4_ADDRESS_FOR_S1_MME              = "CI_ENB_IP_ADDR";
         ENB_INTERFACE_NAME_FOR_S1U               = "eth0";
-        ENB_IPV4_ADDRESS_FOR_S1U                 = "192.168.12.111/24";
+        ENB_IPV4_ADDRESS_FOR_S1U                 = "CI_ENB_IP_ADDR";
         ENB_PORT_FOR_S1U                         = 2152; # Spec 2152
-
-        ENB_IPV4_ADDRESS_FOR_X2C                 = "192.168.12.111/24";
+        ENB_IPV4_ADDRESS_FOR_X2C                 = "CI_ENB_IP_ADDR";
         ENB_PORT_FOR_X2C                         = 36422; # Spec 36422
     };
   }
@@ -201,8 +200,8 @@ MACRLCs = (
 	tr_s_preference = "local_L1";
 	tr_n_preference = "local_RRC";
 	phy_test_mode = 0;
-        puSch10xSnr     =  200;
-        puCch10xSnr     =  200;
+        puSch10xSnr     =  160;
+        puCch10xSnr     =  160;
         }
 );
 
@@ -235,7 +234,7 @@ RUs = (
 THREAD_STRUCT = (
   {
     #three config for level of parallelism "PARALLEL_SINGLE_THREAD", "PARALLEL_RU_L1_SPLIT", or "PARALLEL_RU_L1_TRX_SPLIT"
-    parallel_config    = "PARALLEL_RU_L1_TRX_SPLIT";
+    parallel_config    = "PARALLEL_SINGLE_THREAD";
     #two option for worker "WORKER_DISABLE" or "WORKER_ENABLE"
     worker_config      = "WORKER_ENABLE";
   }
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 37b6a118ea177a3eb5e6e25d3e845ad216555cff..cdfd618e8974de820357a3707be86c6b19adade2 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
@@ -174,7 +174,7 @@ eNBs =
 
 
     ////////// MME parameters:
-    mme_ip_address      = ( { ipv4       = "192.168.12.26";
+    mme_ip_address      = ( { ipv4       = "CI_MME_IP_ADDR";
                               ipv6       = "192:168:30::17";
                               active     = "yes";
                               preference = "ipv4";
@@ -184,12 +184,11 @@ eNBs =
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
-        ENB_IPV4_ADDRESS_FOR_S1_MME              = "192.168.12.111/24";
+        ENB_IPV4_ADDRESS_FOR_S1_MME              = "CI_ENB_IP_ADDR";
         ENB_INTERFACE_NAME_FOR_S1U               = "eth0";
-        ENB_IPV4_ADDRESS_FOR_S1U                 = "192.168.12.111/24";
+        ENB_IPV4_ADDRESS_FOR_S1U                 = "CI_ENB_IP_ADDR";
         ENB_PORT_FOR_S1U                         = 2152; # Spec 2152
-
-        ENB_IPV4_ADDRESS_FOR_X2C                 = "192.168.12.111/24";
+        ENB_IPV4_ADDRESS_FOR_X2C                 = "CI_ENB_IP_ADDR";
         ENB_PORT_FOR_X2C                         = 36422; # Spec 36422
     };
   }
@@ -201,8 +200,8 @@ MACRLCs = (
 	tr_s_preference = "local_L1";
 	tr_n_preference = "local_RRC";
 	phy_test_mode = 0;
-        puSch10xSnr     =  200;
-        puCch10xSnr     =  200;
+        puSch10xSnr     =  160;
+        puCch10xSnr     =  160;
         }
 );
 
@@ -235,7 +234,7 @@ RUs = (
 THREAD_STRUCT = (
   {
     #three config for level of parallelism "PARALLEL_SINGLE_THREAD", "PARALLEL_RU_L1_SPLIT", or "PARALLEL_RU_L1_TRX_SPLIT"
-    parallel_config    = "PARALLEL_RU_L1_TRX_SPLIT";
+    parallel_config    = "PARALLEL_SINGLE_THREAD";
     #two option for worker "WORKER_DISABLE" or "WORKER_ENABLE"
     worker_config      = "WORKER_ENABLE";
   }
diff --git a/ci-scripts/conf_files/rcc.band7.tm1.nfapi.conf b/ci-scripts/conf_files/rcc.band7.tm1.nfapi.conf
new file mode 100644
index 0000000000000000000000000000000000000000..f5d089243a5f2aa7910351176221aa3373005fe9
--- /dev/null
+++ b/ci-scripts/conf_files/rcc.band7.tm1.nfapi.conf
@@ -0,0 +1,236 @@
+Active_eNBs = ( "eNB-Eurecom-LTEBox");
+# Asn1_verbosity, choice in: none, info, annoying
+Asn1_verbosity = "none";
+
+eNBs =
+(
+ {
+    ////////// Identification parameters:
+    eNB_ID    =  0xe00;
+
+    cell_type =  "CELL_MACRO_ENB";
+
+    eNB_name  =  "eNB-Eurecom-LTEBox";
+
+    // Tracking area code, 0x0000 and 0xfffe are reserved values
+    tracking_area_code = 1;
+
+    plmn_list = ( { mcc = 208; mnc = 93; mnc_length = 2; } );
+
+    tr_s_preference     = "local_mac"
+
+    ////////// Physical parameters:
+
+    component_carriers = (
+      {
+      node_function             = "3GPP_eNODEB";
+      node_timing               = "synch_to_ext_device";
+      node_synch_ref            = 0;
+      frame_type					      = "FDD";
+      tdd_config 					      = 3;
+      tdd_config_s            			      = 0;
+      prefix_type             			      = "NORMAL";
+      eutra_band              			      = 7;
+      downlink_frequency      			      = 2685000000L;
+      uplink_frequency_offset 			      = -120000000;
+      Nid_cell					      = 0;
+      N_RB_DL                 			      = 50;
+      Nid_cell_mbsfn          			      = 0;
+      nb_antenna_ports                                = 1;
+      nb_antennas_tx          			      = 1;
+      nb_antennas_rx          			      = 1;
+      tx_gain                                            = 90;
+      rx_gain                                            = 125;
+      pbch_repetition                                 = "FALSE";
+      prach_root              			      = 0;
+      prach_config_index      			      = 0;
+      prach_high_speed        			      = "DISABLE";
+      prach_zero_correlation  			      = 1;
+      prach_freq_offset       			      = 2;
+      pucch_delta_shift       			      = 1;
+      pucch_nRB_CQI           			      = 0;
+      pucch_nCS_AN            			      = 0;
+      pucch_n1_AN             			      = 0;
+      pdsch_referenceSignalPower 			      = -27;
+      pdsch_p_b                  			      = 0;
+      pusch_n_SB                 			      = 1;
+      pusch_enable64QAM          			      = "DISABLE";
+      pusch_hoppingMode                                  = "interSubFrame";
+      pusch_hoppingOffset                                = 0;
+      pusch_groupHoppingEnabled  			      = "ENABLE";
+      pusch_groupAssignment      			      = 0;
+      pusch_sequenceHoppingEnabled		   	      = "DISABLE";
+      pusch_nDMRS1                                       = 1;
+      phich_duration                                     = "NORMAL";
+      phich_resource                                     = "ONESIXTH";
+      srs_enable                                         = "DISABLE";
+      /*  srs_BandwidthConfig                                =;
+      srs_SubframeConfig                                 =;
+      srs_ackNackST                                      =;
+      srs_MaxUpPts                                       =;*/
+
+      pusch_p0_Nominal                                   = -96;
+      pusch_alpha                                        = "AL1";
+      pucch_p0_Nominal                                   = -104;
+      msg3_delta_Preamble                                = 6;
+      pucch_deltaF_Format1                               = "deltaF2";
+      pucch_deltaF_Format1b                              = "deltaF3";
+      pucch_deltaF_Format2                               = "deltaF0";
+      pucch_deltaF_Format2a                              = "deltaF0";
+      pucch_deltaF_Format2b		    	      = "deltaF0";
+
+      rach_numberOfRA_Preambles                          = 64;
+      rach_preamblesGroupAConfig                         = "DISABLE";
+      /*
+      rach_sizeOfRA_PreamblesGroupA                      = ;
+      rach_messageSizeGroupA                             = ;
+      rach_messagePowerOffsetGroupB                      = ;
+      */
+      rach_powerRampingStep                              = 4;
+      rach_preambleInitialReceivedTargetPower            = -108;
+      rach_preambleTransMax                              = 10;
+      rach_raResponseWindowSize                          = 10;
+      rach_macContentionResolutionTimer                  = 48;
+      rach_maxHARQ_Msg3Tx                                = 4;
+
+      pcch_default_PagingCycle                           = 128;
+      pcch_nB                                            = "oneT";
+      bcch_modificationPeriodCoeff			      = 2;
+      ue_TimersAndConstants_t300			      = 1000;
+      ue_TimersAndConstants_t301			      = 1000;
+      ue_TimersAndConstants_t310			      = 1000;
+      ue_TimersAndConstants_t311			      = 10000;
+      ue_TimersAndConstants_n310			      = 20;
+      ue_TimersAndConstants_n311			      = 1;
+      ue_TransmissionMode                                    = 1;
+
+      //Parameters for SIB18
+      rxPool_sc_CP_Len                                       = "normal";
+      rxPool_sc_Period                                       = "sf40";
+      rxPool_data_CP_Len                                     = "normal";
+      rxPool_ResourceConfig_prb_Num                          = 20;
+      rxPool_ResourceConfig_prb_Start                        = 5;
+      rxPool_ResourceConfig_prb_End                          = 44;
+      rxPool_ResourceConfig_offsetIndicator_present          = "prSmall";
+      rxPool_ResourceConfig_offsetIndicator_choice           = 0;
+      rxPool_ResourceConfig_subframeBitmap_present           = "prBs40";
+      rxPool_ResourceConfig_subframeBitmap_choice_bs_buf              = "00000000000000000000";
+      rxPool_ResourceConfig_subframeBitmap_choice_bs_size             = 5;
+      rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused      = 0;
+/*    rxPool_dataHoppingConfig_hoppingParameter                       = 0;
+      rxPool_dataHoppingConfig_numSubbands                            = "ns1";
+      rxPool_dataHoppingConfig_rbOffset                               = 0;
+      rxPool_commTxResourceUC-ReqAllowed                              = "TRUE";
+*/
+      // Parameters for SIB19
+      discRxPool_cp_Len                                               = "normal"
+      discRxPool_discPeriod                                           = "rf32"
+      discRxPool_numRetx                                              = 1;
+      discRxPool_numRepetition                                        = 2;
+      discRxPool_ResourceConfig_prb_Num                               = 5;
+      discRxPool_ResourceConfig_prb_Start                             = 3;
+      discRxPool_ResourceConfig_prb_End                               = 21;
+      discRxPool_ResourceConfig_offsetIndicator_present               = "prSmall";
+      discRxPool_ResourceConfig_offsetIndicator_choice                = 0;
+      discRxPool_ResourceConfig_subframeBitmap_present                = "prBs40";
+      discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf          = "f0ffffffff";
+      discRxPool_ResourceConfig_subframeBitmap_choice_bs_size         = 5;
+      discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused  = 0;
+
+      }
+    );
+
+
+    srb1_parameters :
+    {
+        # timer_poll_retransmit = (ms) [5, 10, 15, 20,... 250, 300, 350, ... 500]
+        timer_poll_retransmit    = 80;
+
+        # timer_reordering = (ms) [0,5, ... 100, 110, 120, ... ,200]
+        timer_reordering         = 35;
+
+        # timer_reordering = (ms) [0,5, ... 250, 300, 350, ... ,500]
+        timer_status_prohibit    = 0;
+
+        # poll_pdu = [4, 8, 16, 32 , 64, 128, 256, infinity(>10000)]
+        poll_pdu                 =  4;
+
+        # poll_byte = (kB) [25,50,75,100,125,250,375,500,750,1000,1250,1500,2000,3000,infinity(>10000)]
+        poll_byte                =  99999;
+
+        # max_retx_threshold = [1, 2, 3, 4 , 6, 8, 16, 32]
+        max_retx_threshold       =  4;
+    }
+
+    # ------- SCTP definitions
+    SCTP :
+    {
+        # Number of streams to use in input/output
+        SCTP_INSTREAMS  = 2;
+        SCTP_OUTSTREAMS = 2;
+    };
+
+
+    ////////// MME parameters:
+    mme_ip_address      = ( { ipv4       = "CI_MME_IP_ADDR";
+                              ipv6       = "192:168:30::17";
+                              active     = "yes";
+                              preference = "ipv4";
+                            }
+                          );
+
+    NETWORK_INTERFACES :
+    {
+        ENB_INTERFACE_NAME_FOR_S1_MME            = "ens3";
+        ENB_IPV4_ADDRESS_FOR_S1_MME              = "CI_ENB_IP_ADDR";
+        ENB_INTERFACE_NAME_FOR_S1U               = "ens3";
+        ENB_IPV4_ADDRESS_FOR_S1U                 = "CI_ENB_IP_ADDR";
+        ENB_PORT_FOR_S1U                         = 2152; # Spec 2152
+        ENB_IPV4_ADDRESS_FOR_X2C                 = "CI_ENB_IP_ADDR";
+        ENB_PORT_FOR_X2C                         = 36422; # Spec 36422
+
+    };
+  }
+);
+
+MACRLCs = (
+	{
+	num_cc = 1;
+        local_s_if_name  = "lo:";
+        remote_s_address = "127.0.0.1";
+        local_s_address  = "127.0.0.2";
+        local_s_portc    = 50001;
+        remote_s_portc   = 50000;
+        local_s_portd    = 50011;
+        remote_s_portd   = 50010;
+	tr_s_preference = "nfapi";
+	tr_n_preference = "local_RRC";
+        }
+);
+
+THREAD_STRUCT = (
+  {
+    #three config for level of parallelism "PARALLEL_SINGLE_THREAD", "PARALLEL_RU_L1_SPLIT", or "PARALLEL_RU_L1_TRX_SPLIT"
+    parallel_config    = "PARALLEL_RU_L1_TRX_SPLIT";
+    #two option for worker "WORKER_DISABLE" or "WORKER_ENABLE"
+    worker_config      = "WORKER_ENABLE";
+  }
+);
+
+log_config =
+    {
+      global_log_level                      ="info";
+      global_log_verbosity                  ="medium";
+      hw_log_level                          ="info";
+      hw_log_verbosity                      ="medium";
+      phy_log_level                         ="info";
+      phy_log_verbosity                     ="medium";
+      mac_log_level                         ="info";
+      mac_log_verbosity                     ="high";
+      rlc_log_level                         ="info";
+      rlc_log_verbosity                     ="medium";
+      pdcp_log_level                        ="info";
+      pdcp_log_verbosity                    ="medium";
+      rrc_log_level                         ="info";
+      rrc_log_verbosity                     ="medium";
+   };
diff --git a/ci-scripts/conf_files/rru.fdd.band7.conf b/ci-scripts/conf_files/rru.fdd.band7.conf
index 516b6240620e334c7c89ef9778327efc53cc5665..ea923ae3718a6a61ed08481d16e1f91df8f1db5b 100644
--- a/ci-scripts/conf_files/rru.fdd.band7.conf
+++ b/ci-scripts/conf_files/rru.fdd.band7.conf
@@ -20,7 +20,7 @@ RUs = (
 THREAD_STRUCT = (
   {
     #three config for level of parallelism "PARALLEL_SINGLE_THREAD", "PARALLEL_RU_L1_SPLIT", or "PARALLEL_RU_L1_TRX_SPLIT"
-    parallel_config    = "PARALLEL_RU_L1_TRX_SPLIT";
+    parallel_config    = "PARALLEL_SINGLE_THREAD";
     #two option for worker "WORKER_DISABLE" or "WORKER_ENABLE"
     worker_config      = "WORKER_ENABLE";
   }
diff --git a/ci-scripts/conf_files/ue.nfapi.conf b/ci-scripts/conf_files/ue.nfapi.conf
new file mode 100644
index 0000000000000000000000000000000000000000..355b70326b7c749a0ae8c7ef11c5f0c2fd79ad28
--- /dev/null
+++ b/ci-scripts/conf_files/ue.nfapi.conf
@@ -0,0 +1,44 @@
+log_config = {
+  global_log_level                      ="info";
+  global_log_verbosity                  ="medium";
+  hw_log_level                          ="info";
+  hw_log_verbosity                      ="medium";
+  phy_log_level                         ="info";
+  phy_log_verbosity                     ="medium";
+  mac_log_level                         ="info";
+  mac_log_verbosity                     ="medium";
+  rlc_log_level                         ="info";
+  rlc_log_verbosity                     ="medium";
+  pdcp_log_level                        ="info";
+  pdcp_log_verbosity                    ="medium";
+  rrc_log_level                         ="info";
+  rrc_log_verbosity                     ="full";
+};
+
+
+L1s = (
+        {
+	num_cc = 1;
+	tr_n_preference = "nfapi";
+        local_n_if_name  = "lo";
+        remote_n_address = "127.0.0.2";
+        local_n_address  = "127.0.0.1";
+        local_n_portc    = 50000;
+        remote_n_portc   = 50001;
+        local_n_portd    = 50010;
+        remote_n_portd   = 50011;
+        }
+);
+
+RUs = (
+    {
+       local_rf       = "yes"
+       nb_tx          = 1
+       nb_rx          = 1
+       att_tx         = 90
+       att_rx         = 0;
+       bands          = [7,38,42,43];
+       max_pdschReferenceSignalPower = -27;
+       max_rxgain                    = 125;
+    }
+);
diff --git a/ci-scripts/cppcheck_suppressions.list b/ci-scripts/cppcheck_suppressions.list
new file mode 100644
index 0000000000000000000000000000000000000000..f5dcc63ee02eb9fcad7abc65493f56611ead676e
--- /dev/null
+++ b/ci-scripts/cppcheck_suppressions.list
@@ -0,0 +1,92 @@
+// *INDENT-OFF*   cppcheck doesn't like "astyling" this file!!!!
+// /*
+// * 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
+// */
+//*****************************************************************************
+//*****************************************************************************
+// section for "valid" memory leaks: the related functions are allocators and
+// the caller is responsible of freeing the memory. cppcheck has a mechanism
+// to check more accuretaly this, by defining callers responsible of freeing
+// but tools like valgring might be more suitable
+//
+//-----------------------------------------------------------------------------
+//    suppress error about keysP memory leak, free must be done by calling func
+memleak:common/utils/hashtable/obj_hashtable.c
+//-----------------------------------------------------------------------------
+//    suppress error about keys memory leak, free must be done by calling func
+memleak:openair2/UTIL/OMG/omg_hashtable.c
+//-----------------------------------------------------------------------------
+//     suppress error about data memory leak. This is the buffer where
+//    _emm_as_encode function creates the encoded buffer
+//
+memleak:openair3/NAS/UE/EMM/SAP/emm_as.c
+//-----------------------------------------------------------------------------
+//*****************************************************************************
+// section for files not used in oai exec's included in CI.
+// Possibly candidates for removal otherwise should be documented and updated
+// for project rules enforcement
+// ----------------------------------------------------------------------------
+// likely sources for test programs, maintained?
+invalidPrintfArgType_sint:openair1/PHY/CODING/TESTBENCH/ltetest.c
+memleak:openair1/PHY/CODING/TESTBENCH/ltetest.c
+invalidPrintfArgType_sint:openair1/PHY/CODING/TESTBENCH/pdcch_test.c
+//
+//-----------------------------------------------------------------------------
+// oaisim deprecated, remove?
+doubleFree:openair3/TEST/oaisim_mme_list_benchmark.c
+//
+//-----------------------------------------------------------------------------
+// is itti analyzer deprecated
+nullPointer:common/utils/itti_analyzer/itti_analyzer.c
+nullPointerRedundantCheck:common/utils/itti_analyzer/libbuffers/buffers.c
+doubleFree:common/utils/itti_analyzer/libbuffers/socket.c
+memleak:common/utils/itti_analyzer/libbuffers/socket.c
+memleak:common/utils/itti_analyzer/libparser/array_type.c
+memleak:common/utils/itti_analyzer/libui/ui_callbacks.c
+//-----------------------------------------------------------------------------
+// obviously never even compiled!!!
+syntaxError:openair1/SIMULATION/LTE_PHY/dlsim_tm4.c
+//-----------------------------------------------------------------------------
+// omg, otg commented out in cmakelist to be cleaned up definitely?
+arrayIndexOutOfBounds:openair2/UTIL/OMG/omg.c
+uninitvar:openair2/UTIL/OTG/otg_rx_socket.c
+//
+//*****************************************************************************
+//
+// True problems we don't know how to fix, Suppression is commented out,
+// as these kind of problem need either to be fixed or can be suppressed
+// when fully uderstood
+//-----------------------------------------------------------------------------
+// the function [nv]fapi_pnf_p7_config_create should return
+// _this. _this points to a structure and a dynamically allocated field is
+// returned. cppcheck suspects _this will never be released, so do i
+// memleak:nfapi/open-nFAPI/pnf/src/pnf_p7_interface.c
+// memleak:nfapi/open-nFAPI/vnf/src/vnf_p7_interface.c
+//-----------------------------------------------------------------------------
+// may be security_data->kenb.value is released from calling functions. But even
+// when, for test, freeing it before returning from emm_proc_security_mode_command
+// which does the allocation, cppcheck complains. So something might be wrong...
+// memleak:openair3/NAS/UE/EMM/SecurityModeControl.c
+//-----------------------------------------------------------------------------
+// when used, nobody but the original developer can guess if sn_data_cnf is set or not
+// cppcheck found that in some cases it is not, code needs cleanup before fixing that...
+// uninitvar:openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_status_report.c
+//*****************************************************************************
+// *INDENT-ON*
diff --git a/ci-scripts/createVM.sh b/ci-scripts/createVM.sh
index f972a921ac8bd85117f16d2c77377779ed7b8a1b..192008d86723d357f7a6dcb1d75674f3cf657377 100755
--- a/ci-scripts/createVM.sh
+++ b/ci-scripts/createVM.sh
@@ -20,8 +20,8 @@
 # *      contact@openairinterface.org
 # */
 
-function usage {
-    echo "OAI VM Creation script"
+function create_usage {
+    echo "OAI CI VM script"
     echo "   Original Author: Raphael Defosseux"
     echo "   Requirements:"
     echo "     -- uvtool uvtool-libvirt apt-cacher"
@@ -31,9 +31,9 @@ function usage {
     echo ""
     echo "Usage:"
     echo "------"
-    echo "    createVM.sh [OPTIONS]"
+    echo "    oai-ci-vm-tool create [OPTIONS]"
     echo ""
-    echo "Options:"
+    echo "Mandatory Options:"
     echo "--------"
     echo "    --job-name #### OR -jn ####"
     echo "    Specify the name of the Jenkins job."
@@ -41,12 +41,7 @@ function usage {
     echo "    --build-id #### OR -id ####"
     echo "    Specify the build ID of the Jenkins job."
     echo ""
-    echo "    --variant enb-usrp     OR -v1"
-    echo "    --variant basic-sim    OR -v2"
-    echo "    --variant phy-sim      OR -v3"
-    echo "    --variant cppcheck     OR -v4"
-    echo "    --variant enb-ethernet OR -v7"
-    echo "    --variant ue-ethernet  OR -v8"
+    variant_usage
     echo "    Specify the variant to build."
     echo ""
     echo "    --help OR -h"
@@ -54,144 +49,21 @@ function usage {
     echo ""
 }
 
-function variant_usage {
-    echo "OAI VM Build Check script"
-    echo "   Original Author: Raphael Defosseux"
-    echo ""
-    echo "    --variant enb-usrp     OR -v1"
-    echo "    --variant basic-sim    OR -v2"
-    echo "    --variant phy-sim      OR -v3"
-    echo "    --variant cppcheck     OR -v4"
-    echo "    --variant enb-ethernet OR -v7"
-    echo "    --variant ue-ethernet  OR -v8"
-    echo ""
-}
-
-if [ $# -lt 1 ] || [ $# -gt 6 ]
-then
-    echo "Syntax Error: not the correct number of arguments"
-    echo ""
-    usage
-    exit 1
-fi
-
-VM_TEMPLATE=ci-
-JOB_NAME=XX
-BUILD_ID=XX
-VM_NAME=ci-enb-usrp
-VM_MEMORY=2048
-VM_CPU=4
+function create_vm {
+    echo "############################################################"
+    echo "OAI CI VM script"
+    echo "############################################################"
+    echo "VM_NAME             = $VM_NAME"
+    echo "VM_MEMORY           = $VM_MEMORY MBytes"
+    echo "VM_CPU              = $VM_CPU"
 
-while [[ $# -gt 0 ]]
-do
-key="$1"
+    echo "############################################################"
+    echo "Creating VM ($VM_NAME) on Ubuntu Cloud Image base"
+    echo "############################################################"
+    uvt-kvm create $VM_NAME release=xenial --memory $VM_MEMORY --cpu $VM_CPU --unsafe-caching --template ci-scripts/template-host.xml
+    echo "Waiting for VM to be started"
+    uvt-kvm wait $VM_NAME --insecure
 
-case $key in
-    -h|--help)
-    shift
-    usage
-    exit 0
-    ;;
-    -jn|--job-name)
-    JOB_NAME="$2"
-    shift
-    shift
-    ;;
-    -id|--build-id)
-    BUILD_ID="$2"
-    shift
-    shift
-    ;;
-    -v1)
-    VM_NAME=ci-enb-usrp
-    shift
-    ;;
-    -v2)
-    VM_NAME=ci-basic-sim
-    VM_MEMORY=8192
-    shift
-    ;;
-    -v3)
-    VM_NAME=ci-phy-sim
-    shift
-    ;;
-    -v4)
-    VM_NAME=ci-cppcheck
-    VM_MEMORY=4096
-    VM_CPU=4
-    shift
-    ;;
-    -v7)
-    VM_NAME=ci-enb-ethernet
-    shift
-    ;;
-    -v8)
-    VM_NAME=ci-ue-ethernet
-    shift
-    ;;
-    --variant)
-    variant="$2"
-    case $variant in
-        enb-usrp)
-        VM_NAME=ci-enb-usrp
-        ;;
-        basic-sim)
-        VM_NAME=ci-basic-sim
-        VM_MEMORY=8192
-        ;;
-        phy-sim)
-        VM_NAME=ci-phy-sim
-        ;;
-        cppcheck)
-        VM_NAME=ci-cppcheck
-        VM_MEMORY=4096
-        VM_CPU=4
-        ;;
-        enb-ethernet)
-        VM_NAME=ci-enb-ethernet
-        ;;
-        ue-ethernet)
-        VM_NAME=ci-ue-ethernet
-        ;;
-        *)
-        echo ""
-        echo "Syntax Error: Invalid Variant option -> $variant"
-        echo ""
-        variant_usage
-        exit 1
-    esac
-    shift
-    shift
-    ;;
-    *)
-    echo "Syntax Error: unknown option: $key"
-    echo ""
-    usage
-    exit 1
-esac
-done
-
-if [ "$JOB_NAME" == "XX" ] || [ "$BUILD_ID" == "XX" ]
-then
-    VM_TEMPLATE=ci-
-else
-    VM_TEMPLATE=${JOB_NAME}-b${BUILD_ID}-
-fi
-
-VM_NAME=`echo $VM_NAME | sed -e "s#ci-#$VM_TEMPLATE#"`
-VM_CMDS=${VM_NAME}_cmds.txt
-
-echo "VM_NAME             = $VM_NAME"
-echo "VM_MEMORY           = $VM_MEMORY MBytes"
-echo "VM_CPU              = $VM_CPU"
-
-echo "############################################################"
-echo "Creating VM ($VM_NAME) on Ubuntu Cloud Image base"
-echo "############################################################"
-uvt-kvm create $VM_NAME release=xenial --memory $VM_MEMORY --cpu $VM_CPU --unsafe-caching --template ci-scripts/template-host.xml
-echo "Waiting for VM to be started"
-uvt-kvm wait $VM_NAME --insecure
-
-VM_IP_ADDR=`uvt-kvm ip $VM_NAME`
-echo "$VM_NAME has for IP addr = $VM_IP_ADDR"
-exit 0
+    VM_IP_ADDR=`uvt-kvm ip $VM_NAME`
+    echo "$VM_NAME has for IP addr = $VM_IP_ADDR"
+}
diff --git a/ci-scripts/destroyAllRunningVM.sh b/ci-scripts/destroyAllRunningVM.sh
index 5e152bc59083b9c740f4a9674d3c6e78f03d8215..76a7fd0b508fd755a70be54e9c0a40f5b5a8ea84 100755
--- a/ci-scripts/destroyAllRunningVM.sh
+++ b/ci-scripts/destroyAllRunningVM.sh
@@ -20,15 +20,17 @@
 # *      contact@openairinterface.org
 # */
 
-function usage {
-    echo "OAI VM Destroy script"
+function destroy_usage {
+    echo "OAI CI VM script"
     echo "   Original Author: Raphael Defosseux"
+    echo "   Requirements:"
+    echo "     -- uvtool uvtool-libvirt apt-cacher"
     echo ""
     echo "Usage:"
     echo "------"
-    echo "    destroyAllRunningVM.sh [OPTIONS]"
+    echo "    oai-ci-vm-tool destroy [OPTIONS]"
     echo ""
-    echo "Options:"
+    echo "Mandatory Options:"
     echo "--------"
     echo "    --job-name #### OR -jn ####"
     echo "    Specify the name of the Jenkins job."
@@ -36,66 +38,26 @@ function usage {
     echo "    --build-id #### OR -id ####"
     echo "    Specify the build ID of the Jenkins job."
     echo ""
+    echo "Options:"
+    echo "--------"
     echo "    --help OR -h"
     echo "    Print this help message."
     echo ""
 }
 
-if [ $# -gt 4 ]
-then
-    echo "Syntax Error: not the correct number of arguments"
-    echo ""
-    usage
-    exit 1
-fi
-
-VM_TEMPLATE=ci-
-JOB_NAME=XX
-BUILD_ID=XX
-
-while [[ $# -gt 0 ]]
-do
-key="$1"
-case $key in
-    -h|--help)
-    shift
-    usage
-    exit 0
-    ;;
-    -jn|--job-name)
-    JOB_NAME="$2"
-    shift
-    shift
-    ;;
-    -id|--build-id)
-    BUILD_ID="$2"
-    shift
-    shift
-    ;;
-    *)
-    echo "Syntax Error: unknown option: $key"
-    echo ""
-    usage
-    exit 1
-esac
-done
-
-if [ "$JOB_NAME" == "XX" ] || [ "$BUILD_ID" == "XX" ]
-then
-    VM_TEMPLATE=ci-
-else
-    VM_TEMPLATE=${JOB_NAME}-b${BUILD_ID}-
-fi
-
-LIST_CI_VM=`uvt-kvm list | grep $VM_TEMPLATE`
-
-for CI_VM in $LIST_CI_VM
-do
-    VM_IP_ADDR=`uvt-kvm ip $CI_VM`
-    echo "VM to destroy: $CI_VM -- IP $VM_IP_ADDR"
-    uvt-kvm destroy $CI_VM
-    ssh-keygen -R $VM_IP_ADDR
-done
-
-exit 0
-
+function destroy_vm {
+    echo "############################################################"
+    echo "OAI CI VM script"
+    echo "############################################################"
+    echo "VM_TEMPLATE         = $VM_TEMPLATE"
+
+    LIST_CI_VM=`uvt-kvm list | grep $VM_TEMPLATE`
+
+    for CI_VM in $LIST_CI_VM
+    do
+        VM_IP_ADDR=`uvt-kvm ip $CI_VM`
+        echo "VM to destroy: $CI_VM -- IP $VM_IP_ADDR"
+        uvt-kvm destroy $CI_VM
+        ssh-keygen -R $VM_IP_ADDR
+    done
+}
diff --git a/ci-scripts/doGitLabMerge.sh b/ci-scripts/doGitLabMerge.sh
index dfe2f02b55936173f4f6d63e731aa2a988a7d96e..6c9ee12b4ede0a9a2ef7d4b14badc9fa3a779baf 100755
--- a/ci-scripts/doGitLabMerge.sh
+++ b/ci-scripts/doGitLabMerge.sh
@@ -1,4 +1,24 @@
 #!/bin/bash
+#/*
+# * 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
+# */
 
 function usage {
     echo "OAI GitLab merge request applying script"
@@ -101,6 +121,7 @@ git config user.email "jenkins@openairinterface.org"
 git config user.name "OAI Jenkins"
 
 git checkout -f $SOURCE_COMMIT_ID
+git log -n1 --pretty=format:\"%s\" > .git/CI_COMMIT_MSG
 
 git merge --ff $TARGET_COMMIT_ID -m "Temporary merge for CI"
 
diff --git a/ci-scripts/main.py b/ci-scripts/main.py
index 52c742fbcb7632f47f23188ebcd1c7000ad7cd6b..62add8429b754f3e08cb04ce4e7c4da200258075 100644
--- a/ci-scripts/main.py
+++ b/ci-scripts/main.py
@@ -42,6 +42,7 @@ ENB_PROCESS_OK = +1
 ENB_PROCESS_SEG_FAULT = -11
 ENB_PROCESS_ASSERTION = -12
 ENB_PROCESS_REALTIME_ISSUE = -13
+ENB_PROCESS_NOLOGFILE_TO_ANALYZE = -14
 HSS_PROCESS_FAILED = -2
 HSS_PROCESS_OK = +2
 MME_PROCESS_FAILED = -3
@@ -78,6 +79,7 @@ class SSHConnection():
 		self.eNBBranch = ''
 		self.eNB_AllowMerge = False
 		self.eNBCommitID = ''
+		self.eNBTargetBranch = ''
 		self.eNBUserName = ''
 		self.eNBPassword = ''
 		self.eNBSourceCodePath = ''
@@ -90,7 +92,8 @@ class SSHConnection():
 		self.ADBUserName = ''
 		self.ADBPassword = ''
 		self.testCase_id = ''
-		self.testXMLfile = ''
+		self.testXMLfiles = []
+		self.nbTestXMLfiles = 0
 		self.desc = ''
 		self.Build_eNB_args = ''
 		self.Initialize_eNB_args = ''
@@ -101,13 +104,27 @@ class SSHConnection():
 		self.iperf_args = ''
 		self.iperf_packetloss_threshold = ''
 		self.iperf_profile = ''
+		self.nbMaxUEtoAttach = -1
 		self.UEDevices = []
+		self.CatMDevices = []
 		self.UEIPAddresses = []
 		self.htmlFile = ''
 		self.htmlHeaderCreated = False
 		self.htmlFooterCreated = False
-		self.htmlUEConnected = 0
+		self.htmlUEConnected = -1
 		self.htmleNBFailureMsg = ''
+		self.picocom_closure = False
+		self.idle_sleep_time = 0
+		self.htmlTabRefs = []
+		self.htmlTabNames = []
+		self.htmlTabIcons = []
+		self.finalStatus = False
+		self.eNBOsVersion = ''
+		self.eNBKernelVersion = ''
+		self.eNBUhdVersion = ''
+		self.eNBCpuNb = ''
+		self.eNBCpuModel = ''
+		self.eNBCpuMHz = ''
 
 	def open(self, ipaddress, username, password):
 		count = 0
@@ -169,8 +186,9 @@ class SSHConnection():
 		elif self.sshresponse == 2:
 			logging.debug('\u001B[1;37;41m Unexpected TIMEOUT \u001B[0m')
 			logging.debug('Expected Line : ' + expectedline)
-			result = re.search('ping |iperf ', str(commandline))
+			result = re.search('ping |iperf |picocom', str(commandline))
 			if result is None:
+				logging.debug(str(self.ssh.before))
 				sys.exit(self.sshresponse)
 			else:
 				return -1
@@ -186,64 +204,87 @@ class SSHConnection():
 		if self.sshresponse == 0:
 			pass
 		elif self.sshresponse == 1:
-			logging.debug('\u001B[1;37;41m Unexpected TIMEOUT \u001B[0m')
+			if not self.picocom_closure:
+				logging.debug('\u001B[1;37;41m Unexpected TIMEOUT during closing\u001B[0m')
 		else:
-			logging.debug('\u001B[1;37;41m Unexpected Others \u001B[0m')
+			logging.debug('\u001B[1;37;41m Unexpected Others during closing\u001B[0m')
 
 	def copyin(self, ipaddress, username, password, source, destination):
+		count = 0
+		copy_status = False
 		logging.debug('scp '+ username + '@' + ipaddress + ':' + source + ' ' + destination)
-		scp_spawn = pexpect.spawn('scp '+ username + '@' + ipaddress + ':' + source + ' ' + destination, timeout = 5)
-		scp_response = scp_spawn.expect(['Are you sure you want to continue connecting (yes/no)?', 'password:', pexpect.EOF, pexpect.TIMEOUT])
-		if scp_response == 0:
-			scp_spawn.sendline('yes')
-			scp_spawn.expect('password:')
-			scp_spawn.sendline(password)
-			scp_response = scp_spawn.expect(['\$', 'Permission denied', 'password:', pexpect.EOF, pexpect.TIMEOUT])
+		while count < 10:
+			scp_spawn = pexpect.spawn('scp '+ username + '@' + ipaddress + ':' + source + ' ' + destination, timeout = 100)
+			scp_response = scp_spawn.expect(['Are you sure you want to continue connecting (yes/no)?', 'password:', pexpect.EOF, pexpect.TIMEOUT])
 			if scp_response == 0:
-				pass
-			else:
-				logging.debug('1 - scp_response = ' + str(scp_response))
-				sys.exit('SCP failed')
-		elif scp_response == 1:
-			scp_spawn.sendline(password)
-			scp_response = scp_spawn.expect(['\$', 'Permission denied', 'password:', pexpect.EOF, pexpect.TIMEOUT])
-			if scp_response == 0 or scp_response == 3:
-				pass
+				scp_spawn.sendline('yes')
+				scp_spawn.expect('password:')
+				scp_spawn.sendline(password)
+				scp_response = scp_spawn.expect(['\$', 'Permission denied', 'password:', pexpect.EOF, pexpect.TIMEOUT])
+				if scp_response == 0:
+					count = 10
+					copy_status = True
+				else:
+					logging.debug('1 - scp_response = ' + str(scp_response))
+			elif scp_response == 1:
+				scp_spawn.sendline(password)
+				scp_response = scp_spawn.expect(['\$', 'Permission denied', 'password:', pexpect.EOF, pexpect.TIMEOUT])
+				if scp_response == 0 or scp_response == 3:
+					count = 10
+					copy_status = True
+				else:
+					logging.debug('2 - scp_response = ' + str(scp_response))
+			elif scp_response == 2:
+				count = 10
+				copy_status = True
 			else:
-				logging.debug('2 - scp_response = ' + str(scp_response))
-				sys.exit('SCP failed')
-		elif scp_response == 2:
-			pass
+				logging.debug('3 - scp_response = ' + str(scp_response))
+			# adding a tempo when failure
+			if not copy_status:
+				time.sleep(1)
+			count += 1
+		if copy_status:
+			return 0
 		else:
-			logging.debug('3 - scp_response = ' + str(scp_response))
-			sys.exit('SCP failed')
+			return -1
 
 	def copyout(self, ipaddress, username, password, source, destination):
+		count = 0
+		copy_status = False
 		logging.debug('scp ' + source + ' ' + username + '@' + ipaddress + ':' + destination)
-		scp_spawn = pexpect.spawn('scp ' + source + ' ' + username + '@' + ipaddress + ':' + destination, timeout = 5)
-		scp_response = scp_spawn.expect(['Are you sure you want to continue connecting (yes/no)?', 'password:', pexpect.EOF, pexpect.TIMEOUT])
-		if scp_response == 0:
-			scp_spawn.sendline('yes')
-			scp_spawn.expect('password:')
-			scp_spawn.sendline(password)
-			scp_response = scp_spawn.expect(['\$', 'Permission denied', 'password:', pexpect.EOF, pexpect.TIMEOUT])
+		while count < 4:
+			scp_spawn = pexpect.spawn('scp ' + source + ' ' + username + '@' + ipaddress + ':' + destination, timeout = 100)
+			scp_response = scp_spawn.expect(['Are you sure you want to continue connecting (yes/no)?', 'password:', pexpect.EOF, pexpect.TIMEOUT])
 			if scp_response == 0:
-				pass
-			else:
-				logging.debug('1 - scp_response = ' + str(scp_response))
-				sys.exit('SCP failed')
-		elif scp_response == 1:
-			scp_spawn.sendline(password)
-			scp_response = scp_spawn.expect(['\$', 'Permission denied', 'password:', pexpect.EOF, pexpect.TIMEOUT])
-			if scp_response == 0 or scp_response == 3:
-				pass
+				scp_spawn.sendline('yes')
+				scp_spawn.expect('password:')
+				scp_spawn.sendline(password)
+				scp_response = scp_spawn.expect(['\$', 'Permission denied', 'password:', pexpect.EOF, pexpect.TIMEOUT])
+				if scp_response == 0:
+					count = 10
+					copy_status = True
+				else:
+					logging.debug('1 - scp_response = ' + str(scp_response))
+			elif scp_response == 1:
+				scp_spawn.sendline(password)
+				scp_response = scp_spawn.expect(['\$', 'Permission denied', 'password:', pexpect.EOF, pexpect.TIMEOUT])
+				if scp_response == 0 or scp_response == 3:
+					count = 10
+					copy_status = True
+				else:
+					logging.debug('2 - scp_response = ' + str(scp_response))
+			elif scp_response == 2:
+				count = 10
+				copy_status = True
 			else:
-				logging.debug('2 - scp_response = ' + str(scp_response))
-				sys.exit('SCP failed')
-		elif scp_response == 2:
+				logging.debug('3 - scp_response = ' + str(scp_response))
+			# adding a tempo when failure
+			if not copy_status:
+				time.sleep(1)
+			count += 1
+		if copy_status:
 			pass
 		else:
-			logging.debug('3 - scp_response = ' + str(scp_response))
 			sys.exit('SCP failed')
 
 	def BuildeNB(self):
@@ -264,16 +305,23 @@ class SSHConnection():
 		# if the branch is not develop, then it is a merge request and we need to do 
 		# the potential merge. Note that merge conflicts should already been checked earlier
 		if (self.eNB_AllowMerge):
-			if (self.eNBBranch != 'develop') and (self.eNBBranch != 'origin/develop'):
-				self.command('git merge --ff origin/develop -m "Temporary merge for CI"', '\$', 5)
+			if self.eNBTargetBranch == '':
+				if (self.eNBBranch != 'develop') and (self.eNBBranch != 'origin/develop'):
+					self.command('git merge --ff origin/develop -m "Temporary merge for CI"', '\$', 5)
+			else:
+				logging.debug('Merging with the target branch: ' + self.eNBTargetBranch)
+				self.command('git merge --ff origin/' + self.eNBTargetBranch + ' -m "Temporary merge for CI"', '\$', 5)
 		self.command('source oaienv', '\$', 5)
 		self.command('cd cmake_targets', '\$', 5)
-		self.command('mkdir -p  log', '\$', 5)
+		self.command('mkdir -p log', '\$', 5)
+		self.command('chmod 777 log', '\$', 5)
 		# no need to remove in log (git clean did the trick)
-		self.command('echo ' + self.eNBPassword + ' | sudo -S stdbuf -o0 ./build_oai ' + self.Build_eNB_args + ' 2>&1 | stdbuf -o0 tee -a compile_oai_enb.log', 'Bypassing the Tests', 600)
-		self.command('mkdir -p build_log_' + SSH.testCase_id, '\$', 5)
-		self.command('echo ' + self.eNBPassword + ' | sudo -S mv log/* ' + 'build_log_' + SSH.testCase_id, '\$', 5)
-		self.command('echo ' + self.eNBPassword + ' | sudo -S mv compile_oai_enb.log ' + 'build_log_' + SSH.testCase_id, '\$', 5)
+		self.command('stdbuf -o0 ./build_oai ' + self.Build_eNB_args + ' 2>&1 | stdbuf -o0 tee -a compile_oai_enb.log', 'Bypassing the Tests', 600)
+		self.command('mkdir -p build_log_' + self.testCase_id, '\$', 5)
+		self.command('mv log/* ' + 'build_log_' + self.testCase_id, '\$', 5)
+		self.command('mv compile_oai_enb.log ' + 'build_log_' + self.testCase_id, '\$', 5)
+		# Workaround to run with develop-nr
+		self.command('if [ -e ran_build ]; then cp -rf ran_build lte_build_oai; fi', '\$', 30)
 		self.close()
 		self.CreateHtmlTestRow(self.Build_eNB_args, 'OK', ALL_PROCESSES_OK)
 
@@ -287,7 +335,7 @@ class SSHConnection():
 			self.command('cd ' + self.EPCSourceCodePath, '\$', 5)
 			self.command('source oaienv', '\$', 5)
 			self.command('cd scripts', '\$', 5)
-			self.command('echo ' + self.EPCPassword + ' | sudo -S ./run_hss 2>&1 | stdbuf -o0 awk \'{ print strftime("[%Y/%m/%d %H:%M:%S] ",systime()) $0 }\' | stdbuf -o0 tee -a hss_' + SSH.testCase_id + '.log &', 'Core state: 2 -> 3', 35)
+			self.command('echo ' + self.EPCPassword + ' | sudo -S ./run_hss 2>&1 | stdbuf -o0 awk \'{ print strftime("[%Y/%m/%d %H:%M:%S] ",systime()) $0 }\' | stdbuf -o0 tee -a hss_' + self.testCase_id + '.log &', 'Core state: 2 -> 3', 35)
 		else:
 			logging.debug('Using the ltebox simulated HSS')
 			self.command('if [ -d ' + self.EPCSourceCodePath + '/scripts ]; then echo ' + self.eNBPassword + ' | sudo -S rm -Rf ' + self.EPCSourceCodePath + '/scripts ; fi', '\$', 5)
@@ -313,7 +361,7 @@ class SSHConnection():
 				logging.debug('\u001B[1;37;41m Hostname Not Found! \u001B[0m')
 				sys.exit(1)
 			host_name = result.group('host_name')
-			self.command('echo ' + self.EPCPassword + ' | sudo -S ./run_mme 2>&1 | stdbuf -o0 tee -a mme_' + SSH.testCase_id + '.log &', 'MME app initialization complete', 100)
+			self.command('echo ' + self.EPCPassword + ' | sudo -S ./run_mme 2>&1 | stdbuf -o0 tee -a mme_' + self.testCase_id + '.log &', 'MME app initialization complete', 100)
 		else:
 			self.command('cd /opt/ltebox/tools', '\$', 5)
 			self.command('echo ' + self.EPCPassword + ' | sudo -S ./start_mme', '\$', 5)
@@ -329,7 +377,7 @@ class SSHConnection():
 			self.command('cd ' + self.EPCSourceCodePath, '\$', 5)
 			self.command('source oaienv', '\$', 5)
 			self.command('cd scripts', '\$', 5)
-			self.command('echo ' + self.EPCPassword + ' | sudo -S ./run_spgw 2>&1 | stdbuf -o0 tee -a spgw_' + SSH.testCase_id + '.log &', 'Initializing SPGW-APP task interface: DONE', 30)
+			self.command('echo ' + self.EPCPassword + ' | sudo -S ./run_spgw 2>&1 | stdbuf -o0 tee -a spgw_' + self.testCase_id + '.log &', 'Initializing SPGW-APP task interface: DONE', 30)
 		else:
 			self.command('cd /opt/ltebox/tools', '\$', 5)
 			self.command('echo ' + self.EPCPassword + ' | sudo -S ./start_xGw', '\$', 5)
@@ -344,8 +392,20 @@ class SSHConnection():
 		pStatus = self.CheckProcessExist(initialize_eNB_flag)
 		if (pStatus < 0):
 			self.CreateHtmlTestRow(self.Initialize_eNB_args, 'KO', pStatus)
-			self.CreateHtmlFooter(False)
+			self.CreateHtmlTabFooter(False)
 			sys.exit(1)
+		# If tracer options is on, running tshark on EPC side and capture traffic b/ EPC and eNB
+		result = re.search('T_stdout', str(self.Initialize_eNB_args))
+		if result is not None:
+			self.open(self.EPCIPAddress, self.EPCUserName, self.EPCPassword)
+			self.command('ip addr show | awk -f /tmp/active_net_interfaces.awk | egrep -v "lo|tun"', '\$', 5)
+			result = re.search('interfaceToUse=(?P<eth_interface>[a-zA-Z0-9\-\_]+)done', str(self.ssh.before))
+			if result is not None:
+				eth_interface = result.group('eth_interface')
+				logging.debug('\u001B[1m Launching tshark on interface ' + eth_interface + '\u001B[0m')
+				self.command('echo ' + self.EPCPassword + ' | sudo -S rm -f /tmp/enb_' + self.testCase_id + '_s1log.pcap', '\$', 5)
+				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('cd ' + self.eNBSourceCodePath, '\$', 5)
 		# Initialize_eNB_args usually start with -O and followed by the location in repository
@@ -353,6 +413,14 @@ class SSHConnection():
 		extIdx = full_config_file.find('.conf')
 		if (extIdx > 0):
 			extra_options = full_config_file[extIdx + 5:]
+			# if tracer options is on, compiling and running T Tracer
+			result = re.search('T_stdout', str(extra_options))
+			if result is not None:
+				logging.debug('\u001B[1m Compiling and launching T Tracer\u001B[0m')
+				self.command('cd common/utils/T/tracer', '\$', 5)
+				self.command('make', '\$', 10)
+				self.command('echo $USER; nohup ./record -d ../T_messages.txt -o ' + self.eNBSourceCodePath + '/cmake_targets/enb_' + self.testCase_id + '_record.raw -ON -off VCD -off HEAVY -off LEGACY_GROUP_TRACE -off LEGACY_GROUP_DEBUG > ' + self.eNBSourceCodePath + '/cmake_targets/enb_' + self.testCase_id + '_record.log 2>&1 &', self.eNBUserName, 5)
+				self.command('cd ' + self.eNBSourceCodePath, '\$', 5)
 			full_config_file = full_config_file[:extIdx + 5]
 			config_path, config_file = os.path.split(full_config_file)
 		else:
@@ -364,33 +432,47 @@ class SSHConnection():
 			rruCheck = True
 		# 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/mme_ip_address.*$/mme_ip_address      = ( { ipv4       = "' + self.EPCIPAddress + '";/\' ' + ci_full_config_file, '\$', 2);
-		self.command('sed -i -e \'s/ENB_IPV4_ADDRESS_FOR_S1_MME.*$/ENB_IPV4_ADDRESS_FOR_S1_MME              = "' + self.eNBIPAddress + '";/\' ' + ci_full_config_file, '\$', 2);
-		self.command('sed -i -e \'s/ENB_IPV4_ADDRESS_FOR_S1U.*$/ENB_IPV4_ADDRESS_FOR_S1U                 = "' + self.eNBIPAddress + '";/\' ' + ci_full_config_file, '\$', 2);
-		self.command('sed -i -e \'s/ENB_IPV4_ADDRESS_FOR_X2C.*$/ENB_IPV4_ADDRESS_FOR_X2C                 = "' + self.eNBIPAddress + '";/\' ' + ci_full_config_file, '\$', 2);
+		self.command('sed -i -e \'s/CI_MME_IP_ADDR/' + self.EPCIPAddress + '/\' ' + ci_full_config_file, '\$', 2);
+		self.command('sed -i -e \'s/CI_ENB_IP_ADDR/' + self.eNBIPAddress + '/\' ' + ci_full_config_file, '\$', 2);
 		# Launch eNB with the modified config file
 		self.command('source oaienv', '\$', 5)
 		self.command('cd cmake_targets', '\$', 5)
-		self.command('echo "ulimit -c unlimited && ./lte_build_oai/build/lte-softmodem -O ' + self.eNBSourceCodePath + '/' + ci_full_config_file + extra_options + '" > ./my-lte-softmodem-run' + str(SSH.eNB_instance) + '.sh ', '\$', 5)
-		self.command('chmod 775 ./my-lte-softmodem-run' + str(SSH.eNB_instance) + '.sh ', '\$', 5)
-		self.command('echo ' + self.eNBPassword + ' | sudo -S rm -Rf enb_' + SSH.testCase_id + '.log', '\$', 5)
-		self.command('echo ' + self.eNBPassword + ' | sudo -S -E daemon --inherit --unsafe --name=enb' + str(SSH.eNB_instance) + '_daemon --chdir=' + self.eNBSourceCodePath + '/cmake_targets -o ' + self.eNBSourceCodePath + '/cmake_targets/enb_' + SSH.testCase_id + '.log ./my-lte-softmodem-run' + str(SSH.eNB_instance) + '.sh', '\$', 5)
+		self.command('echo "ulimit -c unlimited && ./lte_build_oai/build/lte-softmodem -O ' + self.eNBSourceCodePath + '/' + ci_full_config_file + extra_options + '" > ./my-lte-softmodem-run' + str(self.eNB_instance) + '.sh ', '\$', 5)
+		self.command('chmod 775 ./my-lte-softmodem-run' + str(self.eNB_instance) + '.sh ', '\$', 5)
+		self.command('echo ' + self.eNBPassword + ' | sudo -S rm -Rf enb_' + self.testCase_id + '.log', '\$', 5)
+		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_' + SSH.testCase_id + '.log'
+			self.eNBLogFile = 'enb_' + self.testCase_id + '.log'
 		time.sleep(6)
 		doLoop = True
 		loopCounter = 10
 		while (doLoop):
 			loopCounter = loopCounter - 1
 			if (loopCounter == 0):
+				# In case of T tracer recording, we may need to kill it
+				result = re.search('T_stdout', str(self.Initialize_eNB_args))
+				if result is not None:
+					self.command('killall --signal SIGKILL record', '\$', 5)
+				self.close()
 				doLoop = False
 				logging.error('\u001B[1;37;41m eNB logging system did not show got sync! \u001B[0m')
 				self.CreateHtmlTestRow('-O ' + config_file + extra_options, 'KO', ALL_PROCESSES_OK)
-				self.CreateHtmlFooter(False)
-				self.close()
+				self.CreateHtmlTabFooter(False)
+				# In case of T tracer recording, we need to kill tshark on EPC side
+				result = re.search('T_stdout', str(self.Initialize_eNB_args))
+				if result is not None:
+					self.open(self.EPCIPAddress, self.EPCUserName, self.EPCPassword)
+					logging.debug('\u001B[1m Stopping tshark \u001B[0m')
+					self.command('echo ' + self.EPCPassword + ' | sudo -S killall --signal SIGKILL tshark', '\$', 5)
+					self.close()
+					time.sleep(1)
+					pcap_log_file = 'enb_' + self.testCase_id + '_s1log.pcap'
+					copyin_res = self.copyin(self.EPCIPAddress, self.EPCUserName, self.EPCPassword, '/tmp/' + pcap_log_file, '.')
+					if (copyin_res == 0):
+						self.copyout(self.eNBIPAddress, self.eNBUserName, self.eNBPassword, pcap_log_file, self.eNBSourceCodePath + '/cmake_targets/.')
 				sys.exit(1)
 			else:
-				self.command('stdbuf -o0 cat enb_' + SSH.testCase_id + '.log | egrep --color=never -i "wait|sync"', '\$', 4)
+				self.command('stdbuf -o0 cat enb_' + self.testCase_id + '.log | egrep --text --color=never -i "wait|sync"', '\$', 4)
 				if rruCheck:
 					result = re.search('wait RUs', str(self.ssh.before))
 				else:
@@ -426,7 +508,7 @@ class SSHConnection():
 			sys.exit('Insufficient Parameter')
 		multi_jobs = []
 		for device_id in self.UEDevices:
-			p = Process(target = SSH.InitializeUE_common, args = (device_id,))
+			p = Process(target = self.InitializeUE_common, args = (device_id,))
 			p.daemon = True
 			p.start()
 			multi_jobs.append(p)
@@ -434,6 +516,109 @@ class SSHConnection():
 			job.join()
 		self.CreateHtmlTestRow('N/A', 'OK', ALL_PROCESSES_OK)
 
+	def checkDevTTYisUnlocked(self):
+		self.open(self.ADBIPAddress, self.ADBUserName, self.ADBPassword)
+		count = 0
+		while count < 5:
+			self.command('echo ' + self.ADBPassword + ' | sudo -S lsof | grep ttyUSB0', '\$', 10)
+			result = re.search('picocom', str(self.ssh.before))
+			if result is None:
+				count = 10
+			else:
+				time.sleep(5)
+				count = count + 1
+		self.close()
+
+	def InitializeCatM(self):
+		if self.ADBIPAddress == '' or self.ADBUserName == '' or self.ADBPassword == '':
+			Usage()
+			sys.exit('Insufficient Parameter')
+		self.picocom_closure = True
+		self.open(self.ADBIPAddress, self.ADBUserName, self.ADBPassword)
+		# dummy call to start a sudo session. The picocom command does NOT handle well the `sudo -S`
+		self.command('echo ' + self.ADBPassword + ' | sudo -S ls', '\$', 10)
+		self.command('sudo picocom --baud 921600 --flow n --databits 8 /dev/ttyUSB0', 'Terminal ready', 10)
+		time.sleep(1)
+		# Calling twice AT to clear all buffers
+		self.command('AT', 'OK|ERROR', 5)
+		self.command('AT', 'OK', 5)
+		# Disabling the Radio
+		self.command('AT+CFUN=0', 'OK', 5)
+		logging.debug('\u001B[1m Cellular Functionality disabled\u001B[0m')
+		# Checking if auto-attach is enabled
+		self.command('AT^AUTOATT?', 'OK', 5)
+		result = re.search('AUTOATT: (?P<state>[0-9\-]+)', str(self.ssh.before))
+		if result is not None:
+			if result.group('state') is not None:
+				autoAttachState = int(result.group('state'))
+				if autoAttachState is not None:
+					if autoAttachState == 0:
+						self.command('AT^AUTOATT=1', 'OK', 5)
+					logging.debug('\u001B[1m Auto-Attach enabled\u001B[0m')
+		else:
+			logging.debug('\u001B[1;37;41m Could not check Auto-Attach! \u001B[0m')
+		# Force closure of picocom but device might still be locked
+		self.close()
+		self.picocom_closure = False
+		self.CreateHtmlTestRow('N/A', 'OK', ALL_PROCESSES_OK)
+		self.checkDevTTYisUnlocked()
+
+	def TerminateCatM(self):
+		if self.ADBIPAddress == '' or self.ADBUserName == '' or self.ADBPassword == '':
+			Usage()
+			sys.exit('Insufficient Parameter')
+		self.picocom_closure = True
+		self.open(self.ADBIPAddress, self.ADBUserName, self.ADBPassword)
+		# dummy call to start a sudo session. The picocom command does NOT handle well the `sudo -S`
+		self.command('echo ' + self.ADBPassword + ' | sudo -S ls', '\$', 10)
+		self.command('sudo picocom --baud 921600 --flow n --databits 8 /dev/ttyUSB0', 'Terminal ready', 10)
+		time.sleep(1)
+		# Calling twice AT to clear all buffers
+		self.command('AT', 'OK|ERROR', 5)
+		self.command('AT', 'OK', 5)
+		# Disabling the Radio
+		self.command('AT+CFUN=0', 'OK', 5)
+		logging.debug('\u001B[1m Cellular Functionality disabled\u001B[0m')
+		self.close()
+		self.picocom_closure = False
+		self.CreateHtmlTestRow('N/A', 'OK', ALL_PROCESSES_OK)
+		self.checkDevTTYisUnlocked()
+
+	def AttachCatM(self):
+		if self.ADBIPAddress == '' or self.ADBUserName == '' or self.ADBPassword == '':
+			Usage()
+			sys.exit('Insufficient Parameter')
+		self.picocom_closure = True
+		self.open(self.ADBIPAddress, self.ADBUserName, self.ADBPassword)
+		# dummy call to start a sudo session. The picocom command does NOT handle well the `sudo -S`
+		self.command('echo ' + self.ADBPassword + ' | sudo -S ls', '\$', 10)
+		self.command('sudo picocom --baud 921600 --flow n --databits 8 /dev/ttyUSB0', 'Terminal ready', 10)
+		time.sleep(1)
+		# Calling twice AT to clear all buffers
+		self.command('AT', 'OK|ERROR', 5)
+		self.command('AT', 'OK', 5)
+		# Enabling the Radio
+		self.command('AT+CFUN=1', 'SIMSTORE,READY', 5)
+		logging.debug('\u001B[1m Cellular Functionality enabled\u001B[0m')
+		time.sleep(4)
+		# We should check if we register
+		count = 0
+		while count < 3:
+			self.command('AT+CEREG?', 'OK', 5)
+			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))
+			else:
+				logging.debug(str(self.ssh.before))
+			count = count + 1
+			time.sleep(1)
+		self.close()
+		self.picocom_closure = False
+		self.CreateHtmlTestRow('N/A', 'OK', ALL_PROCESSES_OK)
+		self.checkDevTTYisUnlocked()
+
 	def AttachUE_common(self, device_id, statusQueue, lock):
 		try:
 			self.open(self.ADBIPAddress, self.ADBUserName, self.ADBPassword)
@@ -490,22 +675,25 @@ class SSHConnection():
 		if (pStatus < 0):
 			self.CreateHtmlTestRow('N/A', 'KO', pStatus)
 			self.AutoTerminateUEandeNB()
-			self.CreateHtmlFooter(False)
+			self.CreateHtmlTabFooter(False)
 			sys.exit(1)
 		multi_jobs = []
 		status_queue = SimpleQueue()
 		lock = Lock()
+		nb_ue_to_connect = 0
 		for device_id in self.UEDevices:
-			p = Process(target = SSH.AttachUE_common, args = (device_id, status_queue, lock,))
-			p.daemon = True
-			p.start()
-			multi_jobs.append(p)
+			if (self.nbMaxUEtoAttach == -1) or (nb_ue_to_connect < self.nbMaxUEtoAttach):
+				p = Process(target = self.AttachUE_common, args = (device_id, status_queue, lock,))
+				p.daemon = True
+				p.start()
+				multi_jobs.append(p)
+			nb_ue_to_connect = nb_ue_to_connect + 1
 		for job in multi_jobs:
 			job.join()
 
 		if (status_queue.empty()):
 			self.CreateHtmlTestRow('N/A', 'KO', ALL_PROCESSES_OK)
-			self.CreateHtmlFooter(False)
+			self.CreateHtmlTabFooter(False)
 			self.AutoTerminateUEandeNB()
 			sys.exit(1)
 		else:
@@ -518,16 +706,20 @@ class SSHConnection():
 				device_id = status_queue.get()
 				message = status_queue.get()
 				if (count < 0):
-					html_cell = "<pre>UE (" + device_id + ")\n" + message + "</pre>"
+					html_cell = '<pre style="background-color:white">UE (' + device_id + ')\n' + message + '</pre>'
 				else:
-					html_cell = "<pre>UE (" + device_id + ")\n" + message + ' in ' + str(count + 2) + ' seconds</pre>'
+					html_cell = '<pre style="background-color:white">UE (' + device_id + ')\n' + message + ' in ' + str(count + 2) + ' seconds</pre>'
 				html_queue.put(html_cell)
 			if (attach_status):
 				self.CreateHtmlTestRowQueue('N/A', 'OK', len(self.UEDevices), html_queue)
+				result = re.search('T_stdout', str(self.Initialize_eNB_args))
+				if result is not None:
+					logging.debug('Waiting 5 seconds to fill up record file')
+					time.sleep(5)
 			else:
 				self.CreateHtmlTestRowQueue('N/A', 'KO', len(self.UEDevices), html_queue)
 				self.AutoTerminateUEandeNB()
-				self.CreateHtmlFooter(False)
+				self.CreateHtmlTabFooter(False)
 				sys.exit(1)
 
 	def DetachUE_common(self, device_id):
@@ -548,17 +740,21 @@ class SSHConnection():
 		if (pStatus < 0):
 			self.CreateHtmlTestRow('N/A', 'KO', pStatus)
 			self.AutoTerminateUEandeNB()
-			self.CreateHtmlFooter(False)
+			self.CreateHtmlTabFooter(False)
 			sys.exit(1)
 		multi_jobs = []
 		for device_id in self.UEDevices:
-			p = Process(target = SSH.DetachUE_common, args = (device_id,))
+			p = Process(target = self.DetachUE_common, args = (device_id,))
 			p.daemon = True
 			p.start()
 			multi_jobs.append(p)
 		for job in multi_jobs:
 			job.join()
 		self.CreateHtmlTestRow('N/A', 'OK', ALL_PROCESSES_OK)
+		result = re.search('T_stdout', str(self.Initialize_eNB_args))
+		if result is not None:
+			logging.debug('Waiting 5 seconds to fill up record file')
+			time.sleep(5)
 
 	def RebootUE_common(self, device_id):
 		try:
@@ -607,11 +803,11 @@ class SSHConnection():
 		pStatus = self.CheckProcessExist(initialize_eNB_flag)
 		if (pStatus < 0):
 			self.CreateHtmlTestRow('N/A', 'KO', pStatus)
-			self.CreateHtmlFooter(False)
+			self.CreateHtmlTabFooter(False)
 			sys.exit(1)
 		multi_jobs = []
 		for device_id in self.UEDevices:
-			p = Process(target = SSH.RebootUE_common, args = (device_id,))
+			p = Process(target = self.RebootUE_common, args = (device_id,))
 			p.daemon = True
 			p.start()
 			multi_jobs.append(p)
@@ -632,6 +828,19 @@ class SSHConnection():
 				sys.exit(1)
 		self.close()
 
+	def GetAllCatMDevices(self, terminate_ue_flag):
+		if self.ADBIPAddress == '' or self.ADBUserName == '' or self.ADBPassword == '':
+			Usage()
+			sys.exit('Insufficient Parameter')
+		self.open(self.ADBIPAddress, self.ADBUserName, self.ADBPassword)
+		self.command('lsusb | egrep "Future Technology Devices International, Ltd FT2232C" | sed -e "s#:.*##" -e "s# #_#g"', '\$', 15)
+		self.CatMDevices = re.findall("\\\\r\\\\n([A-Za-z0-9_]+)",str(self.ssh.before))
+		if terminate_ue_flag == False:
+			if len(self.CatMDevices) == 0:
+				logging.debug('\u001B[1;37;41m CAT-M UE Not Found! \u001B[0m')
+				sys.exit(1)
+		self.close()
+
 	def GetAllUEIPAddresses(self):
 		if self.ADBIPAddress == '' or self.ADBUserName == '' or self.ADBPassword == '':
 			Usage()
@@ -678,7 +887,7 @@ class SSHConnection():
 			self.command('cd ' + self.EPCSourceCodePath, '\$', 5)
 			self.command('cd scripts', '\$', 5)
 			ping_time = re.findall("-c (\d+)",str(self.ping_args))
-			ping_status = self.command('stdbuf -o0 ping ' + self.ping_args + ' ' + UE_IPAddress + ' 2>&1 | stdbuf -o0 tee -a ping_' + SSH.testCase_id + '_' + device_id + '.log', '\$', int(ping_time[0])*1.5)
+			ping_status = self.command('stdbuf -o0 ping ' + self.ping_args + ' ' + UE_IPAddress + ' 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(UE_IPAddress) + ') crashed due to TIMEOUT!'
@@ -746,12 +955,12 @@ class SSHConnection():
 		pStatus = self.CheckProcessExist(initialize_eNB_flag)
 		if (pStatus < 0):
 			self.CreateHtmlTestRow(self.ping_args, 'KO', pStatus)
-			self.CreateHtmlFooter(False)
+			self.CreateHtmlTabFooter(False)
 			sys.exit(1)
 		ueIpStatus = self.GetAllUEIPAddresses()
 		if (ueIpStatus < 0):
 			self.CreateHtmlTestRow(self.ping_args, 'KO', UE_IP_ADDRESS_ISSUE)
-			self.CreateHtmlFooter(False)
+			self.CreateHtmlTabFooter(False)
 			sys.exit(1)
 		multi_jobs = []
 		i = 0
@@ -759,7 +968,7 @@ class SSHConnection():
 		status_queue = SimpleQueue()
 		for UE_IPAddress in self.UEIPAddresses:
 			device_id = self.UEDevices[i]
-			p = Process(target = SSH.Ping_common, args = (lock,UE_IPAddress,device_id,status_queue,))
+			p = Process(target = self.Ping_common, args = (lock,UE_IPAddress,device_id,status_queue,))
 			p.daemon = True
 			p.start()
 			multi_jobs.append(p)
@@ -770,7 +979,7 @@ class SSHConnection():
 		if (status_queue.empty()):
 			self.CreateHtmlTestRow(self.ping_args, 'KO', ALL_PROCESSES_OK)
 			self.AutoTerminateUEandeNB()
-			self.CreateHtmlFooter(False)
+			self.CreateHtmlTabFooter(False)
 			sys.exit(1)
 		else:
 			ping_status = True
@@ -782,14 +991,14 @@ class SSHConnection():
 				device_id = status_queue.get()
 				ip_addr = status_queue.get()
 				message = status_queue.get()
-				html_cell = "<pre>UE (" + device_id + ")\nIP Address  : " + ip_addr + "\n" + message + "</pre>"
+				html_cell = '<pre style="background-color:white">UE (' + device_id + ')\nIP Address  : ' + ip_addr + '\n' + message + '</pre>'
 				html_queue.put(html_cell)
 			if (ping_status):
 				self.CreateHtmlTestRowQueue(self.ping_args, 'OK', len(self.UEDevices), html_queue)
 			else:
 				self.CreateHtmlTestRowQueue(self.ping_args, 'KO', len(self.UEDevices), html_queue)
 				self.AutoTerminateUEandeNB()
-				self.CreateHtmlFooter(False)
+				self.CreateHtmlTabFooter(False)
 				sys.exit(1)
 
 	def Iperf_ComputeTime(self):
@@ -805,11 +1014,11 @@ class SSHConnection():
 			logging.debug('\u001B[1;37;41m Iperf bandwidth Not Found! \u001B[0m')
 			sys.exit(1)
 		iperf_bandwidth = result.group('iperf_bandwidth')
-		if SSH.iperf_profile == 'balanced':
+		if self.iperf_profile == 'balanced':
 			iperf_bandwidth_new = float(iperf_bandwidth)/ue_num
-		if SSH.iperf_profile == 'single-ue':
+		if self.iperf_profile == 'single-ue':
 			iperf_bandwidth_new = float(iperf_bandwidth)
-		if SSH.iperf_profile == 'unbalanced':
+		if self.iperf_profile == 'unbalanced':
 			# residual is 2% of max bw
 			residualBW = float(iperf_bandwidth) / 50
 			if idx == 0:
@@ -825,7 +1034,7 @@ class SSHConnection():
 		return result
 
 	def Iperf_analyzeV2TCPOutput(self, lock, UE_IPAddress, device_id, statusQueue, iperf_real_options):
-		self.command('awk -f /tmp/tcp_iperf_stats.awk /tmp/CI-eNB/scripts/iperf_' + SSH.testCase_id + '_' + device_id + '.log', '\$', 5)
+		self.command('awk -f /tmp/tcp_iperf_stats.awk /tmp/CI-eNB/scripts/iperf_' + self.testCase_id + '_' + device_id + '.log', '\$', 5)
 		result = re.search('Avg Bitrate : (?P<average>[0-9\.]+ Mbits\/sec) Max Bitrate : (?P<maximum>[0-9\.]+ Mbits\/sec) Min Bitrate : (?P<minimum>[0-9\.]+ Mbits\/sec)', str(self.ssh.before))
 		if result is not None:
 			avgbitrate = result.group('average')
@@ -931,7 +1140,7 @@ class SSHConnection():
 			return 0
 
 	def Iperf_analyzeV2Server(self, lock, UE_IPAddress, device_id, statusQueue, iperf_real_options):
-		if (not os.path.isfile('iperf_server_' + SSH.testCase_id + '_' + device_id + '.log')):
+		if (not os.path.isfile('iperf_server_' + self.testCase_id + '_' + device_id + '.log')):
 			self.ping_iperf_wrong_exit(lock, UE_IPAddress, device_id, statusQueue, 'Could not analyze from server log')
 			return
 		# Computing the requested bandwidth in float
@@ -956,7 +1165,7 @@ class SSHConnection():
 				req_bandwidth = '%.1f Gbits/sec' % req_bw
 				req_bw = req_bw * 1000000000
 
-		server_file = open('iperf_server_' + SSH.testCase_id + '_' + device_id + '.log', 'r')
+		server_file = open('iperf_server_' + self.testCase_id + '_' + device_id + '.log', 'r')
 		br_sum = 0.0
 		ji_sum = 0.0
 		pl_sum = 0
@@ -1081,12 +1290,12 @@ class SSHConnection():
 		# Launch iperf server on EPC side
 		self.open(self.EPCIPAddress, self.EPCUserName, self.EPCPassword)
 		self.command('cd ' + self.EPCSourceCodePath + '/scripts', '\$', 5)
-		self.command('rm -f iperf_server_' + SSH.testCase_id + '_' + device_id + '.log', '\$', 5)
+		self.command('rm -f iperf_server_' + self.testCase_id + '_' + device_id + '.log', '\$', 5)
 		port = 5001 + idx
 		if udpIperf:
-			self.command('echo $USER; nohup iperf -u -s -i 1 -p ' + str(port) + ' > iperf_server_' + SSH.testCase_id + '_' + device_id + '.log &', self.EPCUserName, 5)
+			self.command('echo $USER; nohup iperf -u -s -i 1 -p ' + str(port) + ' > iperf_server_' + self.testCase_id + '_' + device_id + '.log &', self.EPCUserName, 5)
 		else:
-			self.command('echo $USER; nohup iperf -s -i 1 -p ' + str(port) + ' > iperf_server_' + SSH.testCase_id + '_' + device_id + '.log &', self.EPCUserName, 5)
+			self.command('echo $USER; nohup iperf -s -i 1 -p ' + str(port) + ' > iperf_server_' + self.testCase_id + '_' + device_id + '.log &', self.EPCUserName, 5)
 		time.sleep(0.5)
 		self.close()
 
@@ -1103,8 +1312,8 @@ class SSHConnection():
 		modified_options = modified_options.replace('-R','')
 		time.sleep(0.5)
 
-		self.command('rm -f iperf_' + SSH.testCase_id + '_' + device_id + '.log', '\$', 5)
-		iperf_status = self.command('stdbuf -o0 adb -s ' + device_id + ' shell "/data/local/tmp/iperf -c ' + EPC_Iperf_UE_IPAddress + ' ' + modified_options + ' -p ' + str(port) + '" 2>&1 | stdbuf -o0 tee -a iperf_' + SSH.testCase_id + '_' + device_id + '.log', '\$', int(iperf_time)*5.0)
+		self.command('rm -f iperf_' + self.testCase_id + '_' + device_id + '.log', '\$', 5)
+		iperf_status = self.command('stdbuf -o0 adb -s ' + device_id + ' shell "/data/local/tmp/iperf -c ' + EPC_Iperf_UE_IPAddress + ' ' + modified_options + ' -p ' + str(port) + '" 2>&1 | stdbuf -o0 tee -a iperf_' + self.testCase_id + '_' + device_id + '.log', '\$', int(iperf_time)*5.0)
 		# TIMEOUT Case
 		if iperf_status < 0:
 			self.close()
@@ -1122,15 +1331,15 @@ class SSHConnection():
 		# in case of failure, retrieve server log
 		if (clientStatus == -1):
 			time.sleep(1)
-			if (os.path.isfile('iperf_server_' + SSH.testCase_id + '_' + device_id + '.log')):
-				os.remove('iperf_server_' + SSH.testCase_id + '_' + device_id + '.log')
-			self.copyin(self.EPCIPAddress, self.EPCUserName, self.EPCPassword, self.EPCSourceCodePath + '/scripts/iperf_server_' + SSH.testCase_id + '_' + device_id + '.log', '.')
+			if (os.path.isfile('iperf_server_' + self.testCase_id + '_' + device_id + '.log')):
+				os.remove('iperf_server_' + self.testCase_id + '_' + device_id + '.log')
+			self.copyin(self.EPCIPAddress, self.EPCUserName, self.EPCPassword, self.EPCSourceCodePath + '/scripts/iperf_server_' + self.testCase_id + '_' + device_id + '.log', '.')
 			self.Iperf_analyzeV2Server(lock, UE_IPAddress, device_id, statusQueue, modified_options)
 
 	def Iperf_common(self, lock, UE_IPAddress, device_id, idx, ue_num, statusQueue):
 		try:
 			# Single-UE profile -- iperf only on one UE
-			if SSH.iperf_profile == 'single-ue' and idx != 0:
+			if self.iperf_profile == 'single-ue' and idx != 0:
 				return
 			useIperf3 = False
 			udpIperf = True
@@ -1161,13 +1370,13 @@ class SSHConnection():
 			if (useIperf3):
 				self.command('stdbuf -o0 adb -s ' + device_id + ' shell /data/local/tmp/iperf3 -s &', '\$', 5)
 			else:
-				self.command('rm -f iperf_server_' + SSH.testCase_id + '_' + device_id + '.log', '\$', 5)
+				self.command('rm -f iperf_server_' + self.testCase_id + '_' + device_id + '.log', '\$', 5)
 				result = re.search('-u', str(self.iperf_args))
 				if result is None:
-					self.command('echo $USER; nohup adb -s ' + device_id + ' shell "/data/local/tmp/iperf -s -i 1" > iperf_server_' + SSH.testCase_id + '_' + device_id + '.log &', self.ADBUserName, 5)
+					self.command('echo $USER; nohup adb -s ' + device_id + ' shell "/data/local/tmp/iperf -s -i 1" > iperf_server_' + self.testCase_id + '_' + device_id + '.log &', self.ADBUserName, 5)
 					udpIperf = False
 				else:
-					self.command('echo $USER; nohup adb -s ' + device_id + ' shell "/data/local/tmp/iperf -u -s -i 1" > iperf_server_' + SSH.testCase_id + '_' + device_id + '.log &', self.ADBUserName, 5)
+					self.command('echo $USER; nohup adb -s ' + device_id + ' shell "/data/local/tmp/iperf -u -s -i 1" > iperf_server_' + self.testCase_id + '_' + device_id + '.log &', self.ADBUserName, 5)
 			time.sleep(0.5)
 			self.close()
 
@@ -1182,14 +1391,14 @@ class SSHConnection():
 				modified_options = str(self.iperf_args)
 			time.sleep(0.5)
 
-			self.command('rm -f iperf_' + SSH.testCase_id + '_' + device_id + '.log', '\$', 5)
+			self.command('rm -f iperf_' + self.testCase_id + '_' + device_id + '.log', '\$', 5)
 			if (useIperf3):
-				self.command('stdbuf -o0 iperf3 -c ' + UE_IPAddress + ' ' + modified_options + ' 2>&1 | stdbuf -o0 tee -a iperf_' + SSH.testCase_id + '_' + device_id + '.log', '\$', int(iperf_time)*5.0)
+				self.command('stdbuf -o0 iperf3 -c ' + UE_IPAddress + ' ' + modified_options + ' 2>&1 | stdbuf -o0 tee -a iperf_' + self.testCase_id + '_' + device_id + '.log', '\$', int(iperf_time)*5.0)
 
 				clientStatus = 0
 				self.Iperf_analyzeV3Output(lock, UE_IPAddress, device_id, statusQueue)
 			else:
-				iperf_status = self.command('stdbuf -o0 iperf -c ' + UE_IPAddress + ' ' + modified_options + ' 2>&1 | stdbuf -o0 tee -a iperf_' + SSH.testCase_id + '_' + device_id + '.log', '\$', int(iperf_time)*5.0)
+				iperf_status = self.command('stdbuf -o0 iperf -c ' + UE_IPAddress + ' ' + modified_options + ' 2>&1 | stdbuf -o0 tee -a iperf_' + self.testCase_id + '_' + device_id + '.log', '\$', int(iperf_time)*5.0)
 				if iperf_status < 0:
 					self.close()
 					message = 'iperf on UE (' + str(UE_IPAddress) + ') crashed due to TIMEOUT !'
@@ -1208,9 +1417,9 @@ class SSHConnection():
 			self.close()
 			if (clientStatus == -1):
 				time.sleep(1)
-				if (os.path.isfile('iperf_server_' + SSH.testCase_id + '_' + device_id + '.log')):
-					os.remove('iperf_server_' + SSH.testCase_id + '_' + device_id + '.log')
-				self.copyin(self.ADBIPAddress, self.ADBUserName, self.ADBPassword, self.EPCSourceCodePath + '/scripts/iperf_server_' + SSH.testCase_id + '_' + device_id + '.log', '.')
+				if (os.path.isfile('iperf_server_' + self.testCase_id + '_' + device_id + '.log')):
+					os.remove('iperf_server_' + self.testCase_id + '_' + device_id + '.log')
+				self.copyin(self.ADBIPAddress, self.ADBUserName, self.ADBPassword, self.EPCSourceCodePath + '/scripts/iperf_server_' + self.testCase_id + '_' + device_id + '.log', '.')
 				self.Iperf_analyzeV2Server(lock, UE_IPAddress, device_id, statusQueue, modified_options)
 		except:
 			os.kill(os.getppid(),signal.SIGUSR1)
@@ -1224,13 +1433,13 @@ class SSHConnection():
 		if (pStatus < 0):
 			self.CreateHtmlTestRow(self.iperf_args, 'KO', pStatus)
 			self.AutoTerminateUEandeNB()
-			self.CreateHtmlFooter(False)
+			self.CreateHtmlTabFooter(False)
 			sys.exit(1)
 		ueIpStatus = self.GetAllUEIPAddresses()
 		if (ueIpStatus < 0):
 			self.CreateHtmlTestRow(self.iperf_args, 'KO', UE_IP_ADDRESS_ISSUE)
 			self.AutoTerminateUEandeNB()
-			self.CreateHtmlFooter(False)
+			self.CreateHtmlTabFooter(False)
 			sys.exit(1)
 		multi_jobs = []
 		i = 0
@@ -1250,7 +1459,7 @@ class SSHConnection():
 		if (status_queue.empty()):
 			self.CreateHtmlTestRow(self.iperf_args, 'KO', ALL_PROCESSES_OK)
 			self.AutoTerminateUEandeNB()
-			self.CreateHtmlFooter(False)
+			self.CreateHtmlTabFooter(False)
 			sys.exit(1)
 		else:
 			iperf_status = True
@@ -1265,7 +1474,7 @@ class SSHConnection():
 				device_id = status_queue.get()
 				ip_addr = status_queue.get()
 				message = status_queue.get()
-				html_cell = "<pre>UE (" + device_id + ")\nIP Address  : " + ip_addr + "\n" + message + "</pre>"
+				html_cell = '<pre style="background-color:white">UE (' + device_id + ')\nIP Address  : ' + ip_addr + '\n' + message + '</pre>'
 				html_queue.put(html_cell)
 			if (iperf_noperf and iperf_status):
 				self.CreateHtmlTestRowQueue(self.iperf_args, 'PERF NOT MET', len(self.UEDevices), html_queue)
@@ -1274,7 +1483,7 @@ class SSHConnection():
 			else:
 				self.CreateHtmlTestRowQueue(self.iperf_args, 'KO', len(self.UEDevices), html_queue)
 				self.AutoTerminateUEandeNB()
-				self.CreateHtmlFooter(False)
+				self.CreateHtmlTabFooter(False)
 				sys.exit(1)
 
 	def CheckProcessExist(self, initialize_eNB_flag):
@@ -1312,7 +1521,7 @@ class SSHConnection():
 				fileCheck = re.search('enb_', str(self.eNBLogFile))
 				if fileCheck is not None:
 					self.copyin(self.eNBIPAddress, self.eNBUserName, self.eNBPassword, self.eNBSourceCodePath + '/cmake_targets/' + self.eNBLogFile, '.')
-					logStatus = self.AnalyzeLogFile_eNB()
+					logStatus = self.AnalyzeLogFile_eNB(self.eNBLogFile)
 					if logStatus < 0:
 						result = logStatus
 			return result
@@ -1383,10 +1592,10 @@ class SSHConnection():
 		except:
 			os.kill(os.getppid(),signal.SIGUSR1)
 
-	def AnalyzeLogFile_eNB(self):
-		if (not os.path.isfile('./' + SSH.eNBLogFile)):
+	def AnalyzeLogFile_eNB(self, eNBlogFile):
+		if (not os.path.isfile('./' + eNBlogFile)):
 			return -1
-		enb_log_file = open('./' + SSH.eNBLogFile, 'r')
+		enb_log_file = open('./' + eNBlogFile, 'r')
 		foundAssertion = False
 		msgAssertion = ''
 		msgLine = 0
@@ -1400,6 +1609,8 @@ class SSHConnection():
 		rrcReestablishRequest = 0
 		rrcReestablishComplete = 0
 		rrcReestablishReject = 0
+		rlcDiscardBuffer = 0
+		rachCanceledProcedure = 0
 		uciStatMsgCount = 0
 		pdcpFailure = 0
 		ulschFailure = 0
@@ -1419,28 +1630,28 @@ class SSHConnection():
 			if foundAssertion and (msgLine < 3):
 				msgLine += 1
 				msgAssertion += str(line)
-			result = re.search('Generating RRCConnectionSetup', str(line))
+			result = re.search('Generating LTE_RRCConnectionSetup', str(line))
 			if result is not None:
 				rrcSetupRequest += 1
-			result = re.search('RRCConnectionSetupComplete from UE', str(line))
+			result = re.search('LTE_RRCConnectionSetupComplete from UE', str(line))
 			if result is not None:
 				rrcSetupComplete += 1
-			result = re.search('Generate RRCConnectionRelease', str(line))
+			result = re.search('Generate LTE_RRCConnectionRelease', str(line))
 			if result is not None:
 				rrcReleaseRequest += 1
-			result = re.search('Generate RRCConnectionReconfiguration', str(line))
+			result = re.search('Generate LTE_RRCConnectionReconfiguration', str(line))
 			if result is not None:
 				rrcReconfigRequest += 1
-			result = re.search('RRCConnectionReconfigurationComplete from UE rnti', str(line))
+			result = re.search('LTE_RRCConnectionReconfigurationComplete from UE rnti', str(line))
 			if result is not None:
 				rrcReconfigComplete += 1
-			result = re.search('RRCConnectionReestablishmentRequest', str(line))
+			result = re.search('LTE_RRCConnectionReestablishmentRequest', str(line))
 			if result is not None:
 				rrcReestablishRequest += 1
-			result = re.search('RRCConnectionReestablishmentComplete', str(line))
+			result = re.search('LTE_RRCConnectionReestablishmentComplete', str(line))
 			if result is not None:
 				rrcReestablishComplete += 1
-			result = re.search('RRCConnectionReestablishmentReject', str(line))
+			result = re.search('LTE_RRCConnectionReestablishmentReject', str(line))
 			if result is not None:
 				rrcReestablishReject += 1
 			result = re.search('uci->stat', str(line))
@@ -1452,6 +1663,12 @@ class SSHConnection():
 			result = re.search('ULSCH in error in round', str(line))
 			if result is not None:
 				ulschFailure += 1
+			result = re.search('BAD all_segments_received', str(line))
+			if result is not None:
+				rlcDiscardBuffer += 1
+			result = re.search('Canceled RA procedure for UE rnti', str(line))
+			if result is not None:
+				rachCanceledProcedure += 1
 		enb_log_file.close()
 		self.htmleNBFailureMsg = ''
 		if uciStatMsgCount > 0:
@@ -1494,6 +1711,10 @@ class SSHConnection():
 			rrcMsg = ' -- ' + str(rrcReestablishReject) + ' were rejected'
 			logging.debug('\u001B[1;30;43m ' + rrcMsg + ' \u001B[0m')
 			self.htmleNBFailureMsg += rrcMsg + '\n'
+		if rachCanceledProcedure > 0:
+			rachMsg = 'eNB cancelled ' + str(rachCanceledProcedure) + ' RA procedure(s)'
+			logging.debug('\u001B[1;30;43m ' + rachMsg + ' \u001B[0m')
+			self.htmleNBFailureMsg += rachMsg + '\n'
 		if foundSegFault:
 			logging.debug('\u001B[1;37;41m eNB ended with a Segmentation Fault! \u001B[0m')
 			return ENB_PROCESS_SEG_FAULT
@@ -1503,34 +1724,77 @@ class SSHConnection():
 			return ENB_PROCESS_ASSERTION
 		if foundRealTimeIssue:
 			logging.debug('\u001B[1;37;41m eNB faced real time issues! \u001B[0m')
+			self.htmleNBFailureMsg += 'eNB faced real time issues!\n'
+			#return ENB_PROCESS_REALTIME_ISSUE
+		if rlcDiscardBuffer > 0:
+			rlcMsg = 'eNB RLC discarded ' + str(rlcDiscardBuffer) + ' buffer(s)'
+			logging.debug('\u001B[1;37;41m ' + rlcMsg + ' \u001B[0m')
+			self.htmleNBFailureMsg += rlcMsg + '\n'
 			return ENB_PROCESS_REALTIME_ISSUE
 		return 0
 
 	def TerminateeNB(self):
 		self.open(self.eNBIPAddress, self.eNBUserName, self.eNBPassword)
 		self.command('cd ' + self.eNBSourceCodePath + '/cmake_targets', '\$', 5)
-		self.command('echo ' + self.eNBPassword + ' | sudo -S daemon --name=enb' + str(SSH.eNB_instance) + '_daemon --stop', '\$', 5)
-		self.command('rm -f my-lte-softmodem-run' + str(SSH.eNB_instance) + '.sh', '\$', 5)
+		self.command('echo ' + self.eNBPassword + ' | sudo -S daemon --name=enb' + str(self.eNB_instance) + '_daemon --stop', '\$', 5)
+		self.command('rm -f my-lte-softmodem-run' + str(self.eNB_instance) + '.sh', '\$', 5)
 		self.command('echo ' + self.eNBPassword + ' | sudo -S killall --signal SIGINT lte-softmodem || true', '\$', 5)
 		time.sleep(5)
 		self.command('stdbuf -o0  ps -aux | grep -v grep | grep lte-softmodem', '\$', 5)
 		result = re.search('lte-softmodem', str(self.ssh.before))
 		if result is not None:
 			self.command('echo ' + self.eNBPassword + ' | sudo -S killall --signal SIGKILL lte-softmodem || true', '\$', 5)
+			time.sleep(5)
 		self.close()
-		result = re.search('enb_', str(self.eNBLogFile))
+		# If tracer options is on, stopping tshark on EPC side
+		result = re.search('T_stdout', str(self.Initialize_eNB_args))
 		if result is not None:
-			self.copyin(self.eNBIPAddress, self.eNBUserName, self.eNBPassword, self.eNBSourceCodePath + '/cmake_targets/' + self.eNBLogFile, '.')
-			logStatus = self.AnalyzeLogFile_eNB()
-			if (logStatus < 0):
-				self.CreateHtmlTestRow('N/A', 'KO', logStatus)
-				self.CreateHtmlFooter(False)
-				sys.exit(1)
-			else:
-				self.CreateHtmlTestRow('N/A', 'OK', ALL_PROCESSES_OK)
+			self.open(self.EPCIPAddress, self.EPCUserName, self.EPCPassword)
+			logging.debug('\u001B[1m Stopping tshark \u001B[0m')
+			self.command('echo ' + self.EPCPassword + ' | sudo -S killall --signal SIGKILL tshark', '\$', 5)
+			time.sleep(1)
+			pcap_log_file = self.eNBLogFile.replace('.log', '_s1log.pcap')
+			self.command('echo ' + self.EPCPassword + ' | sudo -S chmod 666 /tmp/' + pcap_log_file, '\$', 5)
+			self.copyin(self.EPCIPAddress, self.EPCUserName, self.EPCPassword, '/tmp/' + pcap_log_file, '.')
+			self.copyout(self.eNBIPAddress, self.eNBUserName, self.eNBPassword, pcap_log_file, self.eNBSourceCodePath + '/cmake_targets/.')
+			self.close()
+			logging.debug('\u001B[1m Replaying RAW record file\u001B[0m')
+			self.open(self.eNBIPAddress, self.eNBUserName, self.eNBPassword)
+			self.command('cd ' + self.eNBSourceCodePath + '/common/utils/T/tracer/', '\$', 5)
+			raw_record_file = self.eNBLogFile.replace('.log', '_record.raw')
+			replay_log_file = self.eNBLogFile.replace('.log', '_replay.log')
+			extracted_txt_file = self.eNBLogFile.replace('.log', '_extracted_messages.txt')
+			extracted_log_file = self.eNBLogFile.replace('.log', '_extracted_messages.log')
+			self.command('./extract_config -i ' + self.eNBSourceCodePath + '/cmake_targets/' + raw_record_file + ' > ' + self.eNBSourceCodePath + '/cmake_targets/' + extracted_txt_file, '\$', 5)
+			self.command('echo $USER; nohup ./replay -i ' + self.eNBSourceCodePath + '/cmake_targets/' + raw_record_file + ' > ' + self.eNBSourceCodePath + '/cmake_targets/' + replay_log_file + ' 2>&1 &', self.eNBUserName, 5)
+			self.command('./textlog -d ' +  self.eNBSourceCodePath + '/cmake_targets/' + extracted_txt_file + ' -no-gui -ON -full > ' + self.eNBSourceCodePath + '/cmake_targets/' + extracted_log_file, '\$', 5)
+			self.close()
+			self.copyin(self.eNBIPAddress, self.eNBUserName, self.eNBPassword, self.eNBSourceCodePath + '/cmake_targets/' + extracted_log_file, '.')
+			logging.debug('\u001B[1m Analyzing eNB replay logfile \u001B[0m')
+			logStatus = self.AnalyzeLogFile_eNB(extracted_log_file)
+			self.CreateHtmlTestRow('N/A', 'OK', ALL_PROCESSES_OK)
 			self.eNBLogFile = ''
 		else:
-			self.CreateHtmlTestRow('N/A', 'OK', ALL_PROCESSES_OK)
+			result = re.search('enb_', str(self.eNBLogFile))
+			if result is not None:
+				copyin_res = self.copyin(self.eNBIPAddress, self.eNBUserName, self.eNBPassword, self.eNBSourceCodePath + '/cmake_targets/' + self.eNBLogFile, '.')
+				if (copyin_res == -1):
+					logging.debug('\u001B[1;37;41m Could not copy eNB logfile to analyze it! \u001B[0m')
+					self.htmleNBFailureMsg = 'Could not copy eNB logfile to analyze it!'
+					self.CreateHtmlTestRow('N/A', 'KO', ENB_PROCESS_NOLOGFILE_TO_ANALYZE)
+					self.eNBLogFile = ''
+					return
+				logging.debug('\u001B[1m Analyzing eNB logfile \u001B[0m')
+				logStatus = self.AnalyzeLogFile_eNB(self.eNBLogFile)
+				if (logStatus < 0):
+					self.CreateHtmlTestRow('N/A', 'KO', logStatus)
+					self.CreateHtmlTabFooter(False)
+					sys.exit(1)
+				else:
+					self.CreateHtmlTestRow('N/A', 'OK', ALL_PROCESSES_OK)
+				self.eNBLogFile = ''
+			else:
+				self.CreateHtmlTestRow('N/A', 'OK', ALL_PROCESSES_OK)
 
 	def TerminateHSS(self):
 		self.open(self.EPCIPAddress, self.EPCUserName, self.EPCPassword)
@@ -1546,11 +1810,8 @@ class SSHConnection():
 			self.command('cd scripts', '\$', 5)
 			self.command('rm -f ./kill_hss.sh', '\$', 5)
 			self.command('echo ' + self.EPCPassword + ' | sudo -S daemon --name=simulated_hss --stop', '\$', 5)
-			time.sleep(2)
-			self.command('ps -aux | egrep --color=never "hss_sim|simulated_hss" | grep -v grep | awk \'BEGIN{n=0}{pidId[n]=$2;n=n+1}END{print "kill -9 " pidId[0] " " pidId[1]}\' > ./kill_hss.sh', '\$', 5)
-			self.command('chmod 755 ./kill_hss.sh', '\$', 5)
-			self.command('echo ' + self.EPCPassword + ' | sudo -S ./kill_hss.sh', '\$', 5)
-			self.command('rm ./kill_hss.sh', '\$', 5)
+			time.sleep(1)
+			self.command('echo ' + self.EPCPassword + ' | sudo -S killall --signal SIGKILL hss_sim', '\$', 5)
 		self.close()
 		self.CreateHtmlTestRow('N/A', 'OK', ALL_PROCESSES_OK)
 
@@ -1601,7 +1862,7 @@ class SSHConnection():
 
 	def TerminateUE(self):
 		terminate_ue_flag = True
-		SSH.GetAllUEDevices(terminate_ue_flag)
+		self.GetAllUEDevices(terminate_ue_flag)
 		multi_jobs = []
 		for device_id in self.UEDevices:
 			p = Process(target= SSH.TerminateUE_common, args = (device_id,))
@@ -1623,6 +1884,10 @@ class SSHConnection():
 		self.eNB_instance = '0'
 		self.TerminateeNB()
 
+	def IdleSleep(self):
+		time.sleep(self.idle_sleep_time)
+		self.CreateHtmlTestRow(str(self.idle_sleep_time) + ' sec', 'OK', ALL_PROCESSES_OK)
+
 	def LogCollectBuild(self):
 		self.open(self.eNBIPAddress, self.eNBUserName, self.eNBPassword)
 		self.command('cd ' + self.eNBSourceCodePath, '\$', 5)
@@ -1637,8 +1902,8 @@ class SSHConnection():
 		self.command('cd ' + self.eNBSourceCodePath, '\$', 5)
 		self.command('cd cmake_targets', '\$', 5)
 		self.command('echo ' + self.eNBPassword + ' | sudo -S rm -f enb.log.zip', '\$', 5)
-		self.command('echo ' + self.eNBPassword + ' | sudo -S zip enb.log.zip enb*.log core*', '\$', 60)
-		self.command('echo ' + self.eNBPassword + ' | sudo -S rm enb*.log core*', '\$', 5)
+		self.command('echo ' + self.eNBPassword + ' | sudo -S zip enb.log.zip enb*.log core* enb_*record.raw enb_*.pcap enb_*txt', '\$', 60)
+		self.command('echo ' + self.eNBPassword + ' | sudo -S rm enb*.log core* enb_*record.raw enb_*.pcap enb_*txt', '\$', 5)
 		self.close()
 
 	def LogCollectPing(self):
@@ -1697,6 +1962,37 @@ class SSHConnection():
 			self.command('cp /opt/ltebox/var/log/xGwLog.0 .', '\$', 5)
 			self.command('zip spgw.log.zip xGwLog.0', '\$', 60)
 		self.close()
+	def RetrieveSystemVersion(self):
+		if self.eNBIPAddress == '' or self.eNBUserName == '' or self.eNBPassword == '':
+			Usage()
+			sys.exit('Insufficient Parameter')
+		self.open(self.eNBIPAddress, self.eNBUserName, self.eNBPassword)
+		self.command('lsb_release -a', '\$', 5)
+		result = re.search('Description:\\\\t(?P<os_type>[a-zA-Z0-9\-\_\.\ ]+)', str(self.ssh.before))
+		if result is not None:
+			self.eNBOsVersion = result.group('os_type')
+			logging.debug('OS is: ' + self.eNBOsVersion)
+		self.command('uname -r', '\$', 5)
+		result = re.search('uname -r\\\\r\\\\n(?P<kernel_version>[a-zA-Z0-9\-\_\.]+)', str(self.ssh.before))
+		if result is not None:
+			self.eNBKernelVersion = result.group('kernel_version')
+			logging.debug('Kernel Version is: ' + self.eNBKernelVersion)
+		self.command('dpkg --list | egrep --color=never libuhd003', '\$', 5)
+		result = re.search('libuhd003:amd64 *(?P<uhd_version>[0-9\.]+)', str(self.ssh.before))
+		if result is not None:
+			self.eNBUhdVersion = result.group('uhd_version')
+			logging.debug('UHD Version is: ' + self.eNBUhdVersion)
+		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:
+			self.eNBCpuNb = result.group('nb_cpus')
+			logging.debug('nb_cpus: ' + self.eNBCpuNb)
+			self.eNBCpuModel = result.group('model')
+			logging.debug('model: ' + self.eNBCpuModel)
+			self.eNBCpuMHz = result.group('cpu_mhz') + ' MHz'
+			logging.debug('cpu_mhz: ' + self.eNBCpuMHz)
+		self.close()
+
 #-----------------------------------------------------------
 # HTML Reporting....
 #-----------------------------------------------------------
@@ -1706,9 +2002,14 @@ class SSHConnection():
 			self.htmlFile.write('<!DOCTYPE html>\n')
 			self.htmlFile.write('<html class="no-js" lang="en-US">\n')
 			self.htmlFile.write('<head>\n')
+			self.htmlFile.write('  <meta name="viewport" content="width=device-width, initial-scale=1">\n')
+			self.htmlFile.write('  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">\n')
+			self.htmlFile.write('  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>\n')
+			self.htmlFile.write('  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>\n')
 			self.htmlFile.write('  <title>Test Results for TEMPLATE_JOB_NAME job build #TEMPLATE_BUILD_ID</title>\n')
 			self.htmlFile.write('</head>\n')
-			self.htmlFile.write('<body>\n')
+			self.htmlFile.write('<body><div class="container">\n')
+			self.htmlFile.write('  <br>\n')
 			self.htmlFile.write('  <table style="border-collapse: collapse; border: none;">\n')
 			self.htmlFile.write('    <tr style="border-collapse: collapse; border: none;">\n')
 			self.htmlFile.write('      <td style="border-collapse: collapse; border: none;">\n')
@@ -1723,60 +2024,103 @@ class SSHConnection():
 			self.htmlFile.write('    </tr>\n')
 			self.htmlFile.write('  </table>\n')
 			self.htmlFile.write('  <br>\n')
+			self.htmlFile.write('  <div class="alert alert-info"><strong> <span class="glyphicon glyphicon-dashboard"></span> TEMPLATE_STAGE_NAME</strong></div>\n')
 			self.htmlFile.write('  <table border = "1">\n')
 			self.htmlFile.write('     <tr>\n')
-			self.htmlFile.write('       <td bgcolor = "lightcyan" >Build Start Time (UTC)</td>\n')
+			self.htmlFile.write('       <td bgcolor = "lightcyan" > <span class="glyphicon glyphicon-time"></span> Build Start Time (UTC) </td>\n')
 			self.htmlFile.write('       <td>TEMPLATE_BUILD_TIME</td>\n')
 			self.htmlFile.write('     </tr>\n')
 			self.htmlFile.write('     <tr>\n')
-			self.htmlFile.write('       <td bgcolor = "lightcyan" >GIT Repository</td>\n')
-			self.htmlFile.write('       <td><a href="' + SSH.eNBRepository + '">' + SSH.eNBRepository + '</a></td>\n')
+			self.htmlFile.write('       <td bgcolor = "lightcyan" > <span class="glyphicon glyphicon-cloud-upload"></span> GIT Repository </td>\n')
+			self.htmlFile.write('       <td><a href="' + self.eNBRepository + '">' + self.eNBRepository + '</a></td>\n')
 			self.htmlFile.write('     </tr>\n')
 			self.htmlFile.write('     <tr>\n')
-			self.htmlFile.write('       <td bgcolor = "lightcyan" >Job Trigger</td>\n')
-			if (SSH.eNB_AllowMerge):
+			self.htmlFile.write('       <td bgcolor = "lightcyan" > <span class="glyphicon glyphicon-wrench"></span> Job Trigger </td>\n')
+			if (self.eNB_AllowMerge):
 				self.htmlFile.write('       <td>Merge-Request</td>\n')
 			else:
 				self.htmlFile.write('       <td>Push to Branch</td>\n')
 			self.htmlFile.write('     </tr>\n')
 			self.htmlFile.write('     <tr>\n')
-			if (SSH.eNB_AllowMerge):
-				self.htmlFile.write('       <td bgcolor = "lightcyan" >Source Branch</td>\n')
+			if (self.eNB_AllowMerge):
+				self.htmlFile.write('       <td bgcolor = "lightcyan" > <span class="glyphicon glyphicon-log-out"></span> Source Branch </td>\n')
 			else:
-				self.htmlFile.write('       <td bgcolor = "lightcyan" >Branch</td>\n')
-			self.htmlFile.write('       <td>' + SSH.eNBBranch + '</td>\n')
+				self.htmlFile.write('       <td bgcolor = "lightcyan" > <span class="glyphicon glyphicon-tree-deciduous"></span> Branch</td>\n')
+			self.htmlFile.write('       <td>' + self.eNBBranch + '</td>\n')
 			self.htmlFile.write('     </tr>\n')
 			self.htmlFile.write('     <tr>\n')
-			if (SSH.eNB_AllowMerge):
-				self.htmlFile.write('       <td bgcolor = "lightcyan" >Source Commit ID</td>\n')
+			if (self.eNB_AllowMerge):
+				self.htmlFile.write('       <td bgcolor = "lightcyan" > <span class="glyphicon glyphicon-tag"></span> Source Commit ID </td>\n')
 			else:
-				self.htmlFile.write('       <td bgcolor = "lightcyan" >Commit ID</td>\n')
-			self.htmlFile.write('       <td>' + SSH.eNBCommitID + '</td>\n')
+				self.htmlFile.write('       <td bgcolor = "lightcyan" > <span class="glyphicon glyphicon-tag"></span> Commit ID </td>\n')
+			self.htmlFile.write('       <td>' + self.eNBCommitID + '</td>\n')
 			self.htmlFile.write('     </tr>\n')
-			if (SSH.eNB_AllowMerge):
+			if (self.eNB_AllowMerge):
 				self.htmlFile.write('     <tr>\n')
-				self.htmlFile.write('       <td bgcolor = "lightcyan" >Target Branch</td>\n')
-				self.htmlFile.write('       <td>develop</td>\n')
+				self.htmlFile.write('       <td bgcolor = "lightcyan" > <span class="glyphicon glyphicon-log-in"></span> Target Branch </td>\n')
+				if (self.eNBTargetBranch == ''):
+					self.htmlFile.write('       <td>develop</td>\n')
+				else:
+					self.htmlFile.write('       <td>' + self.eNBTargetBranch + '</td>\n')
 				self.htmlFile.write('     </tr>\n')
 			self.htmlFile.write('  </table>\n')
 
 			terminate_ue_flag = True
-			SSH.GetAllUEDevices(terminate_ue_flag)
+			if (self.ADBIPAddress != 'none'):
+				self.GetAllUEDevices(terminate_ue_flag)
+				self.GetAllCatMDevices(terminate_ue_flag)
+			else:
+				self.UEDevices.append('doughq9rehg')
+				self.UEDevices.append('dnsgiuahgia')
+				self.UEDevices.append('uehgieng9')
 			self.htmlUEConnected = len(self.UEDevices)
 
-			self.htmlFile.write('  <h2><a href="#FinalStatus">Jump to Final Status</a></h2>\n')
-			self.htmlFile.write('  <br>\n')
-
-			self.htmlFile.write('  <h2>' + str(self.htmlUEConnected) + ' UE(s) is(are) connected to ADB bench server</h2>\n')
+			self.htmlFile.write('  <h2><span class="glyphicon glyphicon-phone"></span> <span class="glyphicon glyphicon-menu-right"></span> ' + str(len(self.UEDevices)) + ' UE(s) is(are) connected to ADB bench server</h2>\n')
+			self.htmlFile.write('  <h2><span class="glyphicon glyphicon-phone"></span> <span class="glyphicon glyphicon-menu-right"></span> ' + str(len(self.CatMDevices)) + ' CAT-M UE(s) is(are) connected to bench server</h2>\n')
 			self.htmlFile.write('  <br>\n')
+			self.htmlFile.write('  <ul class="nav nav-pills">\n')
+			count = 0
+			while (count < self.nbTestXMLfiles):
+				pillMsg = '    <li><a data-toggle="pill" href="#'
+				pillMsg += self.htmlTabRefs[count]
+				pillMsg += '">'
+				pillMsg += self.htmlTabNames[count]
+				pillMsg += ' <span class="glyphicon glyphicon-'
+				pillMsg += self.htmlTabIcons[count]
+				pillMsg += '"></span></a></li>\n'
+				self.htmlFile.write(pillMsg)
+				count += 1
+			self.htmlFile.write('  </ul>\n')
+			self.htmlFile.write('  <div class="tab-content">\n')
+			self.htmlFile.close()
 
-			self.htmlFile.write('  <h2>Test Summary for ' + SSH.testXMLfile + '</h2>\n')
-			self.htmlFile.write('  <table border = "1">\n')
+	def CreateHtmlTabHeader(self):
+		if (not self.htmlHeaderCreated):
+			if (not os.path.isfile('test_results.html')):
+				self.CreateHtmlHeader()
+			self.htmlFile = open('test_results.html', 'a')
+			if (self.nbTestXMLfiles == 1):
+				self.htmlFile.write('  <div id="' + self.htmlTabRefs[0] + '" class="tab-pane fade">\n')
+				self.htmlFile.write('  <h3>Test Summary for <span class="glyphicon glyphicon-file"></span> ' + self.testXMLfiles[0] + '</h3>\n')
+			else:
+				self.htmlFile.write('  <div id="build-tab" class="tab-pane fade">\n')
+			self.htmlFile.write('  <table class="table" border = "1">\n')
 			self.htmlFile.write('      <tr bgcolor = "#33CCFF" >\n')
 			self.htmlFile.write('        <th>Test Id</th>\n')
 			self.htmlFile.write('        <th>Test Desc</th>\n')
 			self.htmlFile.write('        <th>Test Options</th>\n')
 			self.htmlFile.write('        <th>Test Status</th>\n')
+			if (self.htmlUEConnected == -1):
+				terminate_ue_flag = True
+				if (self.ADBIPAddress != 'none'):
+					self.GetAllUEDevices(terminate_ue_flag)
+					self.GetAllCatMDevices(terminate_ue_flag)
+				else:
+					self.UEDevices.append('doughq9rehg')
+					self.UEDevices.append('dnsgiuahgia')
+					self.UEDevices.append('uehgieng9')
+				self.htmlUEConnected = len(self.UEDevices)
+
 			i = 0
 			while (i < self.htmlUEConnected):
 				self.htmlFile.write('        <th>UE' + str(i) + ' Status</th>\n')
@@ -1784,26 +2128,64 @@ class SSHConnection():
 			self.htmlFile.write('      </tr>\n')
 		self.htmlHeaderCreated = True
 
-	def CreateHtmlFooter(self, passStatus):
+	def CreateHtmlTabFooter(self, passStatus):
 		if ((not self.htmlFooterCreated) and (self.htmlHeaderCreated)):
-			self.htmlFile.write('      <tr id="FinalStatus">\n')
-			self.htmlFile.write('        <th bgcolor = "#33CCFF" colspan=2>Final Status</th>\n')
+			self.htmlFile.write('      <tr>\n')
+			self.htmlFile.write('        <th bgcolor = "#33CCFF" colspan=2>Final Tab Status</th>\n')
+			if passStatus:
+				self.htmlFile.write('        <th bgcolor = "green" colspan=' + str(2 + self.htmlUEConnected) + '><font color="white">PASS <span class="glyphicon glyphicon-ok"></span> </font></th>\n')
+			else:
+				self.htmlFile.write('        <th bgcolor = "red" colspan=' + str(2 + self.htmlUEConnected) + '><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('  </div>\n')
+		self.htmlFooterCreated = False
+
+	def CreateHtmlFooter(self, passStatus):
+		if (os.path.isfile('test_results.html')):
+			self.RetrieveSystemVersion()
+			self.htmlFile = open('test_results.html', 'a')
+			self.htmlFile.write('</div>\n')
+			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('      </tr>\n')
+			self.htmlFile.write('      <tr>\n')
+			self.htmlFile.write('        <td>OS Version</td>\n')
+			self.htmlFile.write('        <td><span class="label label-default">' + self.eNBOsVersion + '</span></td>\n')
+			self.htmlFile.write('        <td>Kernel Version</td>\n')
+			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('      </tr>\n')
+			self.htmlFile.write('      <tr>\n')
+			self.htmlFile.write('        <td>Nb CPUs</td>\n')
+			self.htmlFile.write('        <td><span class="label label-default">' + self.eNBCpuNb + '</span></td>\n')
+			self.htmlFile.write('        <td>CPU Model Name</td>\n')
+			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('      </tr>\n')
+			self.htmlFile.write('      <tr>\n')
+			self.htmlFile.write('        <th colspan=4 bgcolor = "#33CCFF">Final Status</th>\n')
 			if passStatus:
-				self.htmlFile.write('        <th bgcolor = "green" colspan=' + str(2 + self.htmlUEConnected) + '><font color="white">PASS</font></th>\n')
+				self.htmlFile.write('        <th colspan=2 bgcolor="green"><font color="white">PASS <span class="glyphicon glyphicon-ok"></span></font></th>\n')
 			else:
-				self.htmlFile.write('        <th bgcolor = "red" colspan=' + str(2 + self.htmlUEConnected) + '><font color="white">FAIL</font></th>\n')
+				self.htmlFile.write('        <th colspan=2 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('</body>\n')
+			self.htmlFile.write('  <p></p>\n')
+			self.htmlFile.write('  <div class="well well-lg">End of Test Report -- Copyright <span class="glyphicon glyphicon-copyright-mark"></span> 2018 <a href="http://www.openairinterface.org/">OpenAirInterface</a>. All Rights Reserved.</div>\n')
+			self.htmlFile.write('</div></body>\n')
 			self.htmlFile.write('</html>\n')
 			self.htmlFile.close()
-		self.htmlFooterCreated = False
 
 	def CreateHtmlTestRow(self, options, status, processesStatus):
 		if ((not self.htmlFooterCreated) and (self.htmlHeaderCreated)):
 			self.htmlFile.write('      <tr>\n')
-			self.htmlFile.write('        <td bgcolor = "lightcyan" >' + SSH.testCase_id  + '</td>\n')
-			self.htmlFile.write('        <td>' + SSH.desc  + '</td>\n')
+			self.htmlFile.write('        <td bgcolor = "lightcyan" >' + self.testCase_id  + '</td>\n')
+			self.htmlFile.write('        <td>' + self.desc  + '</td>\n')
 			self.htmlFile.write('        <td>' + str(options)  + '</td>\n')
 			if (str(status) == 'OK'):
 				self.htmlFile.write('        <td bgcolor = "lightgreen" >' + str(status)  + '</td>\n')
@@ -1817,7 +2199,9 @@ class SSHConnection():
 				elif (processesStatus == ENB_PROCESS_ASSERTION):
 					self.htmlFile.write('        <td bgcolor = "lightcoral" >KO - eNB process ended in Assertion</td>\n')
 				elif (processesStatus == ENB_PROCESS_REALTIME_ISSUE):
-					self.htmlFile.write('        <td bgcolor = "lightcoral" >KO - eNB process faced Real Time issue(s)/td>\n')
+					self.htmlFile.write('        <td bgcolor = "lightcoral" >KO - eNB process faced Real Time issue(s)</td>\n')
+				elif (processesStatus == ENB_PROCESS_NOLOGFILE_TO_ANALYZE):
+					self.htmlFile.write('        <td bgcolor = "orange" >OK</td>\n')
 				elif (processesStatus == HSS_PROCESS_FAILED):
 					self.htmlFile.write('        <td bgcolor = "lightcoral" >KO - HSS process not found</td>\n')
 				elif (processesStatus == MME_PROCESS_FAILED):
@@ -1836,10 +2220,11 @@ class SSHConnection():
 				if result is not None:
 					cellBgColor = 'red'
 				else:
-					result = re.search('showed|Reestablishment', self.htmleNBFailureMsg)
+					result = re.search('showed|Reestablishment|Could not copy eNB logfile', self.htmleNBFailureMsg)
 					if result is not None:
 						cellBgColor = 'orange'
-				self.htmlFile.write('        <td bgcolor = "' + cellBgColor + '" colspan=' + str(self.htmlUEConnected) + '><pre>' + self.htmleNBFailureMsg + '</pre></td>\n')
+				self.htmlFile.write('        <td bgcolor = "' + cellBgColor + '" colspan=' + str(self.htmlUEConnected) + '><pre style="background-color:' +
+ cellBgColor + '">' + self.htmleNBFailureMsg + '</pre></td>\n')
 				self.htmleNBFailureMsg = ''
 			else:
 				i = 0
@@ -1852,8 +2237,8 @@ class SSHConnection():
 		if ((not self.htmlFooterCreated) and (self.htmlHeaderCreated)):
 			addOrangeBK = False
 			self.htmlFile.write('      <tr>\n')
-			self.htmlFile.write('        <td bgcolor = "lightcyan" >' + SSH.testCase_id  + '</td>\n')
-			self.htmlFile.write('        <td>' + SSH.desc  + '</td>\n')
+			self.htmlFile.write('        <td bgcolor = "lightcyan" >' + self.testCase_id  + '</td>\n')
+			self.htmlFile.write('        <td>' + self.desc  + '</td>\n')
 			self.htmlFile.write('        <td>' + str(options)  + '</td>\n')
 			if (str(status) == 'OK'):
 				self.htmlFile.write('        <td bgcolor = "lightgreen" >' + str(status)  + '</td>\n')
@@ -1867,7 +2252,7 @@ class SSHConnection():
 				if (i < ue_status):
 					if (not ue_queue.empty()):
 						if (addOrangeBK):
-							self.htmlFile.write('        <td bgcolor = "orange" >' + str(ue_queue.get()) + '</td>\n')
+							self.htmlFile.write('        <td bgcolor = "orange" >' + str(ue_queue.get()).replace('white', 'orange') + '</td>\n')
 						else:
 							self.htmlFile.write('        <td>' + str(ue_queue.get()) + '</td>\n')
 					else:
@@ -1897,12 +2282,15 @@ def Usage():
 	print('  --help  Show this help.')
 	print('  --mode=[Mode]')
 	print('      TesteNB')
+	print('      InitiateHtml, FinalizeHtml')
 	print('      TerminateeNB, TerminateUE, TerminateHSS, TerminateMME, TerminateSPGW')
 	print('      LogCollectBuild, LogCollecteNB, LogCollectHSS, LogCollectMME, LogCollectSPGW, LogCollectPing, LogCollectIperf')
 	print('  --eNBIPAddress=[eNB\'s IP Address]')
 	print('  --eNBRepository=[eNB\'s Repository URL]')
 	print('  --eNBBranch=[eNB\'s Branch Name]')
 	print('  --eNBCommitID=[eNB\'s Commit Number]')
+	print('  --eNB_AllowMerge=[eNB\'s Allow Merge Request (with target branch)]')
+	print('  --eNBTargetBranch=[eNB\'s Target Branch in case of a Merge Request]')
 	print('  --eNBUserName=[eNB\'s Login User Name]')
 	print('  --eNBPassword=[eNB\'s Login Password]')
 	print('  --eNBSourceCodePath=[eNB\'s Source Code Path]')
@@ -1918,7 +2306,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':
+	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':
 		logging.debug('ERROR: test-case ' + id + ' has wrong class ' + action)
 		return False
 	return True
@@ -1938,6 +2326,13 @@ def GetParametersFromXML(action):
 		if (SSH.eNB_instance is None):
 			SSH.eNB_instance = '0'
 
+	if action == 'Attach_UE':
+		nbMaxUEtoAttach = test.findtext('nbMaxUEtoAttach')
+		if (nbMaxUEtoAttach is None):
+			SSH.nbMaxUEtoAttach = -1
+		else:
+			SSH.nbMaxUEtoAttach = int(nbMaxUEtoAttach)
+
 	if action == 'Ping':
 		SSH.ping_args = test.findtext('ping_args')
 		SSH.ping_packetloss_threshold = test.findtext('ping_packetloss_threshold')
@@ -1953,6 +2348,13 @@ def GetParametersFromXML(action):
 				logging.debug('ERROR: test-case has wrong profile ' + SSH.iperf_profile)
 				SSH.iperf_profile = 'balanced'
 
+	if action == 'IdleSleep':
+		string_field = test.findtext('idle_sleep_time_in_sec')
+		if (string_field is None):
+			SSH.idle_sleep_time = 5
+		else:
+			SSH.idle_sleep_time = int(string_field)
+
 #check if given test is in list
 #it is in list if one of the strings in 'list' is at the beginning of 'test'
 def test_in_list(test, list):
@@ -1999,6 +2401,9 @@ while len(argvs) > 1:
 	elif re.match('^\-\-eNBCommitID=(.*)$', myArgv, re.IGNORECASE):
 		matchReg = re.match('^\-\-eNBCommitID=(.*)$', myArgv, re.IGNORECASE)
 		SSH.eNBCommitID = matchReg.group(1)
+	elif re.match('^\-\-eNBTargetBranch=(.*)$', myArgv, re.IGNORECASE):
+		matchReg = re.match('^\-\-eNBTargetBranch=(.*)$', myArgv, re.IGNORECASE)
+		SSH.eNBTargetBranch = matchReg.group(1)
 	elif re.match('^\-\-eNBUserName=(.+)$', myArgv, re.IGNORECASE):
 		matchReg = re.match('^\-\-eNBUserName=(.+)$', myArgv, re.IGNORECASE)
 		SSH.eNBUserName = matchReg.group(1)
@@ -2040,7 +2445,13 @@ while len(argvs) > 1:
 		SSH.ADBPassword = matchReg.group(1)
 	elif re.match('^\-\-XMLTestFile=(.+)$', myArgv, re.IGNORECASE):
 		matchReg = re.match('^\-\-XMLTestFile=(.+)$', myArgv, re.IGNORECASE)
-		SSH.testXMLfile = matchReg.group(1)
+		SSH.testXMLfiles.append(matchReg.group(1))
+		SSH.nbTestXMLfiles += 1
+	elif re.match('^\-\-finalStatus=(.+)$', myArgv, re.IGNORECASE):
+		matchReg = re.match('^\-\-finalStatus=(.+)$', myArgv, re.IGNORECASE)
+		finalStatus = matchReg.group(1)
+		if ((finalStatus == 'true') or (finalStatus == 'True')):
+			SSH.finalStatus = True
 	else:
 		Usage()
 		sys.exit('Invalid Parameter: ' + myArgv)
@@ -2106,26 +2517,44 @@ elif re.match('^LogCollectIperf$', mode, re.IGNORECASE):
 		Usage()
 		sys.exit('Insufficient Parameter')
 	SSH.LogCollectIperf()
+elif re.match('^InitiateHtml$', mode, re.IGNORECASE):
+	if SSH.ADBIPAddress == '' or SSH.ADBUserName == '' or SSH.ADBPassword == '':
+		Usage()
+		sys.exit('Insufficient Parameter')
+	count = 0
+	while (count < SSH.nbTestXMLfiles):
+		xml_test_file = sys.path[0] + "/" + SSH.testXMLfiles[count]
+		xmlTree = ET.parse(xml_test_file)
+		xmlRoot = xmlTree.getroot()
+		SSH.htmlTabRefs.append(xmlRoot.findtext('htmlTabRef',default='test-tab-' + str(count)))
+		SSH.htmlTabNames.append(xmlRoot.findtext('htmlTabName',default='Test-' + str(count)))
+		SSH.htmlTabIcons.append(xmlRoot.findtext('htmlTabIcon',default='info-sign'))
+		count += 1
+	SSH.CreateHtmlHeader()
+elif re.match('^FinalizeHtml$', mode, re.IGNORECASE):
+	SSH.CreateHtmlFooter(SSH.finalStatus)
 elif re.match('^TesteNB$', mode, re.IGNORECASE):
 	if SSH.eNBIPAddress == '' or SSH.eNBRepository == '' or SSH.eNBBranch == '' or SSH.eNBUserName == '' or SSH.eNBPassword == '' or SSH.eNBSourceCodePath == '' or SSH.EPCIPAddress == '' or SSH.EPCUserName == '' or SSH.EPCPassword == '' or SSH.EPCType == '' or SSH.EPCSourceCodePath == '' or SSH.ADBIPAddress == '' or SSH.ADBUserName == '' or SSH.ADBPassword == '':
 		Usage()
 		sys.exit('Insufficient Parameter')
 
-	SSH.copyout(SSH.EPCIPAddress, SSH.EPCUserName, SSH.EPCPassword, sys.path[0] + "/tcp_iperf_stats.awk", "/tmp")
-	SSH.CreateHtmlHeader()
-
+	if (SSH.EPCIPAddress != 'none'):
+		SSH.copyout(SSH.EPCIPAddress, SSH.EPCUserName, SSH.EPCPassword, sys.path[0] + "/tcp_iperf_stats.awk", "/tmp")
+		SSH.copyout(SSH.EPCIPAddress, SSH.EPCUserName, SSH.EPCPassword, sys.path[0] + "/active_net_interfaces.awk", "/tmp")
 	#read test_case_list.xml file
         # if no parameters for XML file, use default value
-	if SSH.testXMLfile == '':
+	if (SSH.nbTestXMLfiles != 1):
 		xml_test_file = sys.path[0] + "/test_case_list.xml"
 	else:
-		xml_test_file = sys.path[0] + "/" + SSH.testXMLfile
+		xml_test_file = sys.path[0] + "/" + SSH.testXMLfiles[0]
 
 	xmlTree = ET.parse(xml_test_file)
 	xmlRoot = xmlTree.getroot()
 
 	exclusion_tests=xmlRoot.findtext('TestCaseExclusionList',default='')
 	requested_tests=xmlRoot.findtext('TestCaseRequestedList',default='')
+	if (SSH.nbTestXMLfiles == 1):
+		SSH.htmlTabRefs.append(xmlRoot.findtext('htmlTabRef',default='test-tab-0'))
 	all_tests=xmlRoot.findall('testCase')
 
 	exclusion_tests=exclusion_tests.split()
@@ -2163,6 +2592,8 @@ elif re.match('^TesteNB$', mode, re.IGNORECASE):
 
 	signal.signal(signal.SIGUSR1, receive_signal)
 
+	SSH.CreateHtmlTabHeader()
+
 	for test_case_id in todo_tests:
 		for test in all_tests:
 			id = test.get('id')
@@ -2192,6 +2623,14 @@ elif re.match('^TesteNB$', mode, re.IGNORECASE):
 				SSH.AttachUE()
 			elif action == 'Detach_UE':
 				SSH.DetachUE()
+			elif action == 'Initialize_CatM_module':
+				SSH.InitializeCatM()
+			elif action == 'Terminate_CatM_module':
+				SSH.TerminateCatM()
+			elif action == 'Attach_CatM_module':
+				SSH.AttachCatM()
+			elif action == 'Detach_CatM_module':
+				SSH.TerminateCatM()
 			elif action == 'Ping':
 				SSH.Ping()
 			elif action == 'Iperf':
@@ -2210,10 +2649,12 @@ elif re.match('^TesteNB$', mode, re.IGNORECASE):
 				SSH.InitializeSPGW()
 			elif action == 'Terminate_SPGW':
 				SSH.TerminateSPGW()
+			elif action == 'IdleSleep':
+				SSH.IdleSleep()
 			else:
 				sys.exit('Invalid action')
 
-	SSH.CreateHtmlFooter(True)
+	SSH.CreateHtmlTabFooter(True)
 else:
 	Usage()
 	sys.exit('Invalid mode')
diff --git a/ci-scripts/oai-ci-vm-tool b/ci-scripts/oai-ci-vm-tool
new file mode 100755
index 0000000000000000000000000000000000000000..c28f51415ef5690b07af79e592f2d749d67b329a
--- /dev/null
+++ b/ci-scripts/oai-ci-vm-tool
@@ -0,0 +1,579 @@
+#!/bin/bash
+#/*
+# * 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
+# */
+
+function top_usage {
+    echo "OAI CI VM script"
+    echo "   Original Author: Raphael Defosseux"
+    echo "   Requirements:"
+    echo "     -- uvtool uvtool-libvirt apt-cacher"
+    echo "     -- xenial image already synced"
+    echo ""
+    echo "Usage:"
+    echo "------"
+    echo "    oai-ci-vm-tool (-h|--help) {create,destroy,build,wait,test,report-build,report-test} ..."
+    echo ""
+}
+
+function variant_usage {
+    echo "    --variant enb-usrp     OR -v1"
+    echo "    --variant basic-sim    OR -v2"
+    echo "    --variant phy-sim      OR -v3"
+    echo "    --variant cppcheck     OR -v4"
+    echo "    --variant enb-ethernet OR -v7"
+    echo "    --variant ue-ethernet  OR -v8"
+    echo "    --variant l2-sim       OR -v9"
+    echo "    --variant flexran-rtc  OR -v10"
+}
+
+MY_DIR=$(dirname $(readlink -f $0))
+. $MY_DIR/createVM.sh
+. $MY_DIR/buildOnVM.sh
+. $MY_DIR/waitBuildOnVM.sh
+. $MY_DIR/destroyAllRunningVM.sh
+. $MY_DIR/runTestOnVM.sh
+. $MY_DIR/reportBuildLocally.sh
+. $MY_DIR/reportTestLocally.sh
+
+if [ $# -lt 1 ]
+then
+    echo "Syntax Error: too few arguments"
+    echo ""
+    top_usage
+    exit 1
+fi
+
+VM_TEMPLATE=ci-
+JOB_NAME=XX
+BUILD_ID=XX
+VM_NAME=ci-enb-usrp
+VM_MEMORY=2048
+VM_CPU=4
+ARCHIVES_LOC=enb_usrp
+LOG_PATTERN=.Rel14.txt
+NB_PATTERN_FILES=4
+BUILD_OPTIONS="--eNB -w USRP"
+KEEP_VM_ALIVE=0
+RUN_OPTIONS="none"
+DAEMON=0
+MR_TRIG=0
+PU_TRIG=0
+
+HELP_CMD=0
+CREATE_CMD=0
+BUILD_CMD=0
+WAIT_CMD=0
+DESTROY_CMD=0
+TEST_CMD=0
+REPORT_BUILD_CMD=0
+REPORT_TEST_CMD=0
+NBARGS=0
+
+while [[ $# -gt 0 ]]
+do
+key="$1"
+
+case $key in
+    -h|--help)
+    HELP_CMD=1
+    shift
+    ;;
+    create)
+    CREATE_CMD=1
+    # It is implied to keep the VM when creating it
+    KEEP_VM_ALIVE=1
+    shift
+    ;;
+    build)
+    BUILD_CMD=1
+    shift
+    ;;
+    wait)
+    WAIT_CMD=1
+    shift
+    ;;
+    test)
+    TEST_CMD=1
+    shift
+    ;;
+    destroy)
+    DESTROY_CMD=1
+    shift
+    ;;
+    report-build)
+    REPORT_BUILD_CMD=1
+    shift
+    ;;
+    report-test)
+    REPORT_TEST_CMD=1
+    shift
+    ;;
+    -jn|--job-name)
+    JOB_NAME="$2"
+    NBARGS=$[$NBARGS+1]
+    shift
+    shift
+    ;;
+    -id|--build-id)
+    BUILD_ID="$2"
+    NBARGS=$[$NBARGS+2]
+    shift
+    shift
+    ;;
+    -ws|--workspace)
+    JENKINS_WKSP="$2"
+    NBARGS=$[$NBARGS+4]
+    shift
+    shift
+    ;;
+    -k|--keep-vm-alive)
+    KEEP_VM_ALIVE=1
+    NBARGS=$[$NBARGS+8]
+    shift
+    ;;
+    -D|--daemon)
+    DAEMON=1
+    NBARGS=$[$NBARGS+16]
+    shift
+    ;;
+    -gu|--git-url)
+    GIT_URL="$2"
+    NBARGS=$[$NBARGS+32]
+    shift
+    shift
+    ;;
+    --trigger)
+    TRIG="$2"
+    case $TRIG in
+        merge-request)
+        MR_TRIG=1
+        ;;
+        push)
+        PU_TRIG=1
+        ;;
+        *)
+        echo ""
+        echo "Syntax Error: Invalid Trigger option -> $TRIG"
+        echo ""
+        trigger_usage
+        exit
+        ;;
+    esac
+    NBARGS=$[$NBARGS+64]
+    shift
+    shift
+    ;;
+    -mr)
+    MR_TRIG=1
+    NBARGS=$[$NBARGS+64]
+    shift
+    ;;
+    -pu)
+    PU_TRIG=1
+    NBARGS=$[$NBARGS+64]
+    shift
+    ;;
+    -sb|--src-branch)
+    SOURCE_BRANCH="$2"
+    NBARGS=$[$NBARGS+1024]
+    shift
+    shift
+    ;;
+    -sc|--src-commit)
+    SOURCE_COMMIT_ID="$2"
+    NBARGS=$[$NBARGS+2048]
+    shift
+    shift
+    ;;
+    -tb|--target-branch)
+    TARGET_BRANCH="$2"
+    NBARGS=$[$NBARGS+4096]
+    shift
+    shift
+    ;;
+    -tc|--target-commit)
+    TARGET_COMMIT_ID="$2"
+    NBARGS=$[$NBARGS+8192]
+    shift
+    shift
+    ;;
+    -br|--branch)
+    SOURCE_BRANCH="$2"
+    NBARGS=$[$NBARGS+16384]
+    shift
+    shift
+    ;;
+    -co|--commit)
+    SOURCE_COMMIT_ID="$2"
+    NBARGS=$[$NBARGS+32768]
+    shift
+    shift
+    ;;
+    -v1)
+    VM_NAME=ci-enb-usrp
+    ARCHIVES_LOC=enb_usrp
+    LOG_PATTERN=.Rel14.txt
+    NB_PATTERN_FILES=4
+    BUILD_OPTIONS="--eNB -w USRP --mu"
+    NBARGS=$[$NBARGS+256]
+    shift
+    ;;
+    -v2)
+    VM_NAME=ci-basic-sim
+    ARCHIVES_LOC=basic_sim
+    LOG_PATTERN=basic_simulator
+    NB_PATTERN_FILES=2
+    BUILD_OPTIONS="--basic-simulator"
+    VM_MEMORY=8192
+    VM_CPU=4
+    RUN_OPTIONS="complex"
+    NBARGS=$[$NBARGS+256]
+    shift
+    ;;
+    -v3)
+    VM_NAME=ci-phy-sim
+    ARCHIVES_LOC=phy_sim
+    LOG_PATTERN=.Rel14.txt
+    NB_PATTERN_FILES=3
+    BUILD_OPTIONS="--phy_simulators"
+    RUN_OPTIONS="./run_exec_autotests.bash -g \"01510*\" -q -np -b"
+    NBARGS=$[$NBARGS+256]
+    shift
+    ;;
+    -v4)
+    VM_NAME=ci-cppcheck
+    VM_MEMORY=4096
+    ARCHIVES_LOC=cppcheck
+    LOG_PATTERN=cppcheck.xml
+    NB_PATTERN_FILES=1
+    BUILD_OPTIONS="--enable=warning --force --xml --xml-version=2 --suppressions-list=ci-scripts/cppcheck_suppressions.list"
+    NBARGS=$[$NBARGS+256]
+    shift
+    ;;
+    -v7)
+    VM_NAME=ci-enb-ethernet
+    ARCHIVES_LOC=enb_eth
+    LOG_PATTERN=.Rel14.txt
+    NB_PATTERN_FILES=6
+    BUILD_OPTIONS="--eNB -t ETHERNET --noS1"
+    NBARGS=$[$NBARGS+256]
+    shift
+    ;;
+    -v8)
+    VM_NAME=ci-ue-ethernet
+    ARCHIVES_LOC=ue_eth
+    LOG_PATTERN=.Rel14.txt
+    NB_PATTERN_FILES=6
+    BUILD_OPTIONS="--UE -t ETHERNET --noS1"
+    NBARGS=$[$NBARGS+256]
+    shift
+    ;;
+    -v9)
+    VM_NAME=ci-l2-sim
+    VM_MEMORY=8192
+    VM_CPU=8
+    ARCHIVES_LOC=l2_sim
+    LOG_PATTERN=.Rel14.txt
+    NB_PATTERN_FILES=4
+    BUILD_OPTIONS="--eNB -t ETHERNET"
+    RUN_OPTIONS="complex"
+    NBARGS=$[$NBARGS+256]
+    shift
+    ;;
+    -v10)
+    VM_NAME=ci-flexran-rtc
+    ARCHIVES_LOC=flexran
+    LOG_PATTERN=.Rel14.txt
+    NB_PATTERN_FILES=1
+    BUILD_OPTIONS="cmake . && make -j2"
+    NBARGS=$[$NBARGS+256]
+    shift
+    ;;
+    --variant)
+    variant="$2"
+    case $variant in
+        enb-usrp)
+        VM_NAME=ci-enb-usrp
+        ARCHIVES_LOC=enb_usrp
+        LOG_PATTERN=.Rel14.txt
+        NB_PATTERN_FILES=4
+        BUILD_OPTIONS="--eNB -w USRP --mu"
+        NBARGS=$[$NBARGS+256]
+        ;;
+        basic-sim)
+        VM_NAME=ci-basic-sim
+        ARCHIVES_LOC=basic_sim
+        LOG_PATTERN=basic_simulator
+        NB_PATTERN_FILES=2
+        BUILD_OPTIONS="--basic-simulator"
+        VM_MEMORY=8192
+        VM_CPU=4
+        RUN_OPTIONS="complex"
+        NBARGS=$[$NBARGS+256]
+        ;;
+        phy-sim)
+        VM_NAME=ci-phy-sim
+        ARCHIVES_LOC=phy_sim
+        LOG_PATTERN=.Rel14.txt
+        NB_PATTERN_FILES=3
+        BUILD_OPTIONS="--phy_simulators"
+        RUN_OPTIONS="./run_exec_autotests.bash -g \"01510*\" -q -np -b"
+        NBARGS=$[$NBARGS+256]
+        ;;
+        cppcheck)
+        VM_NAME=ci-cppcheck
+        VM_MEMORY=4096
+        ARCHIVES_LOC=cppcheck
+        LOG_PATTERN=cppcheck.xml
+        NB_PATTERN_FILES=1
+        BUILD_OPTIONS="--enable=warning --force --xml --xml-version=2 --suppressions-list=ci-scripts/cppcheck_suppressions.list"
+        NBARGS=$[$NBARGS+256]
+        ;;
+        enb-ethernet)
+        VM_NAME=ci-enb-ethernet
+        ARCHIVES_LOC=enb_eth
+        LOG_PATTERN=.Rel14.txt
+        NB_PATTERN_FILES=6
+        BUILD_OPTIONS="--eNB -t ETHERNET --noS1"
+        NBARGS=$[$NBARGS+256]
+        ;;
+        ue-ethernet)
+        VM_NAME=ci-ue-ethernet
+        ARCHIVES_LOC=ue_eth
+        LOG_PATTERN=.Rel14.txt
+        NB_PATTERN_FILES=6
+        BUILD_OPTIONS="--UE -t ETHERNET --noS1"
+        NBARGS=$[$NBARGS+256]
+        ;;
+        l2-sim)
+        VM_NAME=ci-l2-sim
+        VM_MEMORY=8192
+        VM_CPU=8
+        ARCHIVES_LOC=l2_sim
+        LOG_PATTERN=.Rel14.txt
+        NB_PATTERN_FILES=4
+        BUILD_OPTIONS="--eNB -t ETHERNET"
+        RUN_OPTIONS="complex"
+        NBARGS=$[$NBARGS+256]
+        ;;
+        flexran-rtc)
+        VM_NAME=ci-flexran-rtc
+        ARCHIVES_LOC=flexran
+        LOG_PATTERN=.Rel14.txt
+        NB_PATTERN_FILES=1
+        BUILD_OPTIONS="cmake . && make -j2"
+        NBARGS=$[$NBARGS+256]
+        ;;
+        *)
+        echo ""
+        echo "Syntax Error: Invalid Variant option -> $variant"
+        echo ""
+        variant_usage
+        exit 1
+    esac
+    shift
+    shift
+    ;;
+    *)
+    echo "Syntax Error: unknown option: $key"
+    echo ""
+    top_usage
+    exit 1
+esac
+done
+
+MANY_CMDS=$[$CREATE_CMD+$BUILD_CMD+$WAIT_CMD+$DESTROY_CMD+$TEST_CMD+$REPORT_BUILD_CMD+$REPORT_TEST_CMD]
+if [ $MANY_CMDS -gt 1 ]
+then
+    echo "Syntax Error: too many commands"
+    top_usage
+    exit 1
+fi
+
+if [ $HELP_CMD -eq 1 ]
+then
+    if [ $MANY_CMDS -eq 0 ]
+    then
+        top_usage
+        exit 0
+    fi
+    if [ $CREATE_CMD -eq 1 ]
+    then
+        create_usage
+        exit 0
+    fi
+    if [ $BUILD_CMD -eq 1 ]
+    then
+        build_usage
+        exit 0
+    fi
+    if [ $WAIT_CMD -eq 1 ]
+    then
+        wait_usage
+        exit 0
+    fi
+    if [ $TEST_CMD -eq 1 ]
+    then
+        run_test_usage
+        exit 0
+    fi
+    if [ $DESTROY_CMD -eq 1 ]
+    then
+        destroy_usage
+        exit 0
+    fi
+    if [ $REPORT_BUILD_CMD -eq 1 ]
+    then
+        report_build_usage
+        exit 0
+    fi
+    if [ $REPORT_TEST_CMD -eq 1 ]
+    then
+        report_test_usage
+        exit 0
+    fi
+else
+    if [ $MANY_CMDS -eq 0 ]
+    then
+        echo "Syntax Error: no command"
+        top_usage
+        exit 1
+    fi
+    # For create, mandatory options: jn, id. Optional: variant
+    if [ $CREATE_CMD -eq 1 ] && [ $NBARGS -ne 3 ] && [ $NBARGS -ne 259 ]
+    then
+        echo "Syntax Error: unsupported option(s) for create command"
+        create_usage
+        exit 1
+    fi
+    # For build, mandatory options: jn, id, ws. Optional: variant, k, D
+    if [ $BUILD_CMD -eq 1 ] && [ $NBARGS -ne 7 ] && [ $NBARGS -ne 263 ] && [ $NBARGS -ne 15 ] && [ $NBARGS -ne 271 ] && [ $NBARGS -ne 23 ] && [ $NBARGS -ne 279 ] && [ $NBARGS -ne 31 ] && [ $NBARGS -ne 287 ]
+    then
+        echo "Syntax Error: unsupported option(s) for build command"
+        build_usage
+        exit 1
+    fi
+    # For wait, mandatory options: jn, id, ws. Optional: variant, k
+    if [ $WAIT_CMD -eq 1 ] && [ $NBARGS -ne 7 ] && [ $NBARGS -ne 263 ] && [ $NBARGS -ne 15 ] && [ $NBARGS -ne 271 ]
+    then
+        echo "Syntax Error: unsupported option(s) for wait command"
+        wait_usage
+        exit 1
+    fi
+    # For test, mandatory options: jn, id, ws. Optional: variant, k
+    if [ $TEST_CMD -eq 1 ] && [ $NBARGS -ne 7 ] && [ $NBARGS -ne 263 ] && [ $NBARGS -ne 15 ] && [ $NBARGS -ne 271 ]
+    then
+        echo "Syntax Error: unsupported option(s) for test command"
+        run_test_usage
+        exit 1
+    fi
+    # For destroy, mandatory options: jn, id.
+    if [ $DESTROY_CMD -eq 1 ] && [ $NBARGS -ne 3 ]
+    then
+        echo "Syntax Error: unsupported option(s) for destroy command"
+        destroy_usage
+        exit 1
+    fi
+    # For report-build, mandatory options: jn, id, ws, gu, pu, br,co.
+    #                                  or: jn, id, ws, gu, mr, sb, sc, tb, tc.
+    if [ $REPORT_BUILD_CMD -eq 1 ] && [ $NBARGS -ne 15463 ] && [ $NBARGS -ne 49255 ]
+    then
+        echo "Syntax Error: unsupported option(s) for report-build command"
+        report_build_usage
+        exit 1
+    fi
+    # For report-test, mandatory options: jn, id, ws, gu, pu, br,co.
+    #                                 or: jn, id, ws, gu, mr, sb, sc, tb, tc.
+    if [ $REPORT_TEST_CMD -eq 1 ] && [ $NBARGS -ne 15463 ] && [ $NBARGS -ne 49255 ]
+    then
+        echo "Syntax Error: unsupported option(s) for report-test command"
+        report_test_usage
+        exit 1
+    fi
+fi
+
+# Checking uvt-kvm is installed
+UVT_KVM_PATH=`which uvt-kvm | grep -c uvt-kvm`
+if [ $UVT_KVM_PATH -eq 0 ]
+then
+    echo "Error: uvt-kvm is not installed"
+    top_usage
+    exit 1
+fi
+
+if [ "$JOB_NAME" == "XX" ] || [ "$BUILD_ID" == "XX" ]
+then
+    VM_TEMPLATE=ci-
+else
+    VM_TEMPLATE=${JOB_NAME}-b${BUILD_ID}-
+fi
+
+VM_NAME=`echo $VM_NAME | sed -e "s#ci-#$VM_TEMPLATE#"`
+VM_CMDS=${VM_NAME}_cmds.txt
+ARCHIVES_LOC=${JENKINS_WKSP}/archives/${ARCHIVES_LOC}
+
+STATUS=0
+if [ $CREATE_CMD -eq 1 ]
+then
+    create_vm
+fi
+if [ $BUILD_CMD -eq 1 ]
+then
+    build_on_vm
+    if [ $DAEMON -eq 0 ] && [ $STATUS -eq 0 ]
+    then
+        check_on_vm_build
+    fi
+fi
+if [ $WAIT_CMD -eq 1 ]
+then
+    wait_on_vm_build
+    if [ $STATUS -eq 0 ]
+    then
+        check_on_vm_build
+    fi
+fi
+if [ $TEST_CMD -eq 1 ]
+then
+    ARCHIVES_LOC=${ARCHIVES_LOC}/test
+    run_test_on_vm
+fi
+if [ $DESTROY_CMD -eq 1 ]
+then
+    destroy_vm
+fi
+if [ $REPORT_BUILD_CMD -eq 1 ]
+then
+    report_build
+fi
+if [ $REPORT_TEST_CMD -eq 1 ]
+then
+    report_test
+fi
+
+# Did command pass or fail?
+if [ $STATUS -eq 0 ]
+then
+    echo "STATUS seems OK"
+else
+    echo "STATUS failed?"
+fi
+exit $STATUS
diff --git a/ci-scripts/reportBuildLocally.sh b/ci-scripts/reportBuildLocally.sh
index a499fa3b66149e17d14947a6d523c14ff8a2a8a1..677e59206876b488fd9d8bbacda1eb9be098bc65 100755
--- a/ci-scripts/reportBuildLocally.sh
+++ b/ci-scripts/reportBuildLocally.sh
@@ -20,14 +20,13 @@
 # *      contact@openairinterface.org
 # */
 
-function usage {
-    echo "OAI Local Build Report script"
+function report_build_usage {
+    echo "OAI CI VM script"
     echo "   Original Author: Raphael Defosseux"
     echo ""
     echo "Usage:"
     echo "------"
-    echo ""
-    echo "    reportBuildLocally.sh [OPTIONS]"
+    echo "    oai-ci-vm-tool report-build [OPTIONS]"
     echo ""
     echo "Options:"
     echo "--------"
@@ -47,6 +46,9 @@ function usage {
     echo "    --build-id #### OR -id ####"
     echo "    Specify the build ID of the Jenkins job."
     echo ""
+    echo "    --workspace #### OR -ws ####"
+    echo "    Specify the workspace."
+    echo ""
     echo "    --trigger merge-request OR -mr"
     echo "    --trigger push          OR -pu"
     echo "    Specify trigger action of the Jenkins job. Either a merge-request event or a push event."
@@ -79,7 +81,7 @@ function usage {
 }
 
 function trigger_usage {
-    echo "OAI Local Build Report script"
+    echo "OAI CI VM script"
     echo "   Original Author: Raphael Defosseux"
     echo ""
     echo "    --trigger merge-request OR -mr"
@@ -103,7 +105,7 @@ function details_table {
     COMPLETE_MESSAGE="start"
     for MESSAGE in $LIST_MESSAGES
     do
-        if [[ $MESSAGE == *"/home/ubuntu/tmp"* ]]
+        if [[ $MESSAGE == *"/home/ubuntu/tmp"* ]] || [[  $MESSAGE == *"/tmp/CI-eNB"* ]]
         then
             FILENAME=`echo $MESSAGE | sed -e "s#^/home/ubuntu/tmp/##" -e "s#^.*/tmp/CI-eNB/##" | awk -F ":" '{print $1}'`
             LINENB=`echo $MESSAGE | awk -F ":" '{print $2}'`
@@ -139,6 +141,23 @@ function details_table {
 
 function summary_table_header {
     echo "   <h3>$1</h3>" >> ./build_results.html
+    if [ -f $2/build_final_status.log ]
+    then
+        if [ `grep -c BUILD_OK $2/build_final_status.log` -eq 1 ]
+        then
+            echo "   <div class=\"alert alert-success\">" >> ./build_results.html
+            echo "      <strong>BUILD was SUCCESSFUL <span class=\"glyphicon glyphicon-ok-circle\"></span></strong>" >> ./build_results.html
+            echo "   </div>" >> ./build_results.html
+        else
+            echo "   <div class=\"alert alert-danger\">" >> ./build_results.html
+            echo "      <strong>BUILD was a FAILURE! <span class=\"glyphicon glyphicon-ban-circle\"></span></strong>" >> ./build_results.html
+            echo "   </div>" >> ./build_results.html
+        fi
+    else
+        echo "   <div class=\"alert alert-danger\">" >> ./build_results.html
+        echo "      <strong>COULD NOT DETERMINE BUILD FINAL STATUS! <span class=\"glyphicon glyphicon-ban-circle\"></span></strong>" >> ./build_results.html
+        echo "   </div>" >> ./build_results.html
+    fi
     echo "   <table border = \"1\">" >> ./build_results.html
     echo "      <tr bgcolor = \"#33CCFF\" >" >> ./build_results.html
     echo "        <th>Element</th>" >> ./build_results.html
@@ -153,8 +172,8 @@ function summary_table_row {
     echo "        <td bgcolor = \"lightcyan\" >$1</th>" >> ./build_results.html
     if [ -f $2 ]
     then
-        STATUS=`egrep -c "$3" $2`
-        if [ $STATUS -eq 1 ]
+        BUILD_STATUS=`egrep -c "$3" $2`
+        if [ $BUILD_STATUS -eq 1 ]
         then
             echo "        <td bgcolor = \"green\" >OK</th>" >> ./build_results.html
         else
@@ -196,7 +215,28 @@ function summary_table_footer {
 }
 
 function sca_summary_table_header {
-    echo "   <h3>$1</h3>" >> ./build_results.html
+    echo "   <h3>$2</h3>" >> ./build_results.html
+    NB_ERRORS=`egrep -c "severity=\"error\"" $1`
+    NB_WARNINGS=`egrep -c "severity=\"warning\"" $1`
+    if [ $NB_ERRORS -eq 0 ] && [ $NB_WARNINGS -eq 0 ]
+    then
+        echo "   <div class=\"alert alert-success\">" >> ./build_results.html
+        echo "      <strong>CPPCHECK found NO error and NO warning <span class=\"glyphicon glyphicon-ok-circle\"></span></strong>" >> ./build_results.html
+        echo "   </div>" >> ./build_results.html
+    else
+        if [ $NB_ERRORS -eq 0 ]
+        then
+            echo "   <div class=\"alert alert-warning\">" >> ./build_results.html
+            echo "      <strong>CPPCHECK found NO error and $NB_WARNINGS warnings <span class=\"glyphicon glyphicon-warning-sign\"></span></strong>" >> ./build_results.html
+            echo "   </div>" >> ./build_results.html
+        else
+            echo "   <div class=\"alert alert-danger\">" >> ./build_results.html
+            echo "      <strong>CPPCHECK found $NB_ERRORS errors and $NB_WARNINGS warnings <span class=\"glyphicon glyphicon-ban-circle\"></span></strong>" >> ./build_results.html
+            echo "   </div>" >> ./build_results.html
+        fi
+    fi
+    echo "   <button data-toggle=\"collapse\" data-target=\"#oai-cppcheck-details\">More details on CPPCHECK results</button>" >> ./build_results.html
+    echo "   <div id=\"oai-cppcheck-details\" class=\"collapse\">" >> ./build_results.html
     echo "   <table border = \"1\">" >> ./build_results.html
     echo "      <tr bgcolor = \"#33CCFF\" >" >> ./build_results.html
     echo "        <th>Error / Warning Type</th>" >> ./build_results.html
@@ -261,344 +301,268 @@ function sca_summary_table_footer {
     echo "   </table>" >> ./build_results.html
     echo "   <p>Full details in zipped artifact (cppcheck/cppcheck.xml) </p>" >> ./build_results.html
     echo "   <p style=\"margin-left: 30px\">Graphical Interface tool : <strong><code>cppcheck-gui -l cppcheck/cppcheck.xml</code></strong></p>" >> ./build_results.html
+    echo "   </div>" >> ./build_results.html
 }
 
-jb_checker=0
-mr_checker=0
-pu_checker=0
-MR_TRIG=0
-PU_TRIG=0
-while [[ $# -gt 0 ]]
-do
-key="$1"
-
-case $key in
-    -h|--help)
-    shift
-    usage
-    exit 0
-    ;;
-    -gu|--git-url)
-    GIT_URL="$2"
-    let "jb_checker|=0x1"
-    shift
-    shift
-    ;;
-    -jn|--job-name)
-    JOB_NAME="$2"
-    let "jb_checker|=0x2"
-    shift
-    shift
-    ;;
-    -id|--build-id)
-    BUILD_ID="$2"
-    let "jb_checker|=0x4"
-    shift
-    shift
-    ;;
-    --trigger)
-    TRIG="$2"
-    case $TRIG in
-        merge-request)
-        MR_TRIG=1
-        ;;
-        push)
-        PU_TRIG=1
-        ;;
-        *)
-        echo ""
-        echo "Syntax Error: Invalid Trigger option -> $TRIG"
-        echo ""
-        trigger_usage
-        exit
-        ;;
-    esac
-    let "jb_checker|=0x8"
-    shift
-    shift
-    ;;
-    -mr)
-    MR_TRIG=1
-    let "jb_checker|=0x8"
-    shift
-    ;;
-    -pu)
-    PU_TRIG=1
-    let "jb_checker|=0x8"
-    shift
-    ;;
-    -sb|--src-branch)
-    SOURCE_BRANCH="$2"
-    let "mr_checker|=0x1"
-    shift
-    shift
-    ;;
-    -sc|--src-commit)
-    SOURCE_COMMIT_ID="$2"
-    let "mr_checker|=0x2"
-    shift
-    shift
-    ;;
-    -tb|--target-branch)
-    TARGET_BRANCH="$2"
-    let "mr_checker|=0x4"
-    shift
-    shift
-    ;;
-    -tc|--target-commit)
-    TARGET_COMMIT_ID="$2"
-    let "mr_checker|=0x8"
-    shift
-    shift
-    ;;
-    -br|--branch)
-    SOURCE_BRANCH="$2"
-    let "pu_checker|=0x1"
-    shift
-    shift
-    ;;
-    -co|--commit)
-    SOURCE_COMMIT_ID="$2"
-    let "pu_checker|=0x2"
-    shift
-    shift
-    ;;
-    *)
-    echo "Syntax Error: unknown option: $key"
-    echo ""
-    usage
-    exit 1
-    ;;
-esac
-
-done
-
-if [ $jb_checker -ne 15 ]
-then
-    echo ""
-    echo "Syntax Error: missing job information."
-    # TODO : list missing info
-    echo ""
-    exit 1
-fi
-
-if [ $PU_TRIG -eq 1 ] && [ $MR_TRIG -eq 1 ]
-then
-    echo ""
-    echo "Syntax Error: trigger action incoherent."
-    echo ""
-    trigger_usage
-    exit 1
-fi
-
-if [ $PU_TRIG -eq 1 ]
-then
-    if [ $pu_checker -ne 3 ]
-    then
-        echo ""
-        echo "Syntax Error: missing push information."
-        # TODO : list missing info
-        echo ""
-        exit 1
-    fi
-fi
-
-if [ $MR_TRIG -eq 1 ]
-then
-    if [ $mr_checker -ne 15 ]
-    then
-        echo ""
-        echo "Syntax Error: missing merge-request information."
-        # TODO : list missing info
-        echo ""
-        exit 1
-    fi
-fi
-
-echo "<!DOCTYPE html>" > ./build_results.html
-echo "<html class=\"no-js\" lang=\"en-US\">" >> ./build_results.html
-echo "<head>" >> ./build_results.html
-echo "  <title>Build Results for $JOB_NAME job build #$BUILD_ID</title>" >> ./build_results.html
-echo "  <base href = \"http://www.openairinterface.org/\" />" >> ./build_results.html
-echo "</head>" >> ./build_results.html
-echo "<body>" >> ./build_results.html
-echo "  <table style=\"border-collapse: collapse; border: none;\">" >> ./build_results.html
-echo "    <tr style=\"border-collapse: collapse; border: none;\">" >> ./build_results.html
-echo "      <td style=\"border-collapse: collapse; border: none;\">" >> ./build_results.html
-echo "        <a href=\"http://www.openairinterface.org/\">" >> ./build_results.html
-echo "           <img src=\"/wp-content/uploads/2016/03/cropped-oai_final_logo2.png\" alt=\"\" border=\"none\" height=50 width=150>" >> ./build_results.html
-echo "           </img>" >> ./build_results.html
-echo "        </a>" >> ./build_results.html
-echo "      </td>" >> ./build_results.html
-echo "      <td style=\"border-collapse: collapse; border: none; vertical-align: center;\">" >> ./build_results.html
-echo "        <b><font size = \"6\">Job Summary -- Job: $JOB_NAME -- Build-ID: $BUILD_ID</font></b>" >> ./build_results.html
-echo "      </td>" >> ./build_results.html
-echo "    </tr>" >> ./build_results.html
-echo "  </table>" >> ./build_results.html
-echo "  <br>" >> ./build_results.html
-echo "   <table border = \"1\">" >> ./build_results.html
-echo "      <tr>" >> ./build_results.html
-echo "        <td bgcolor = \"lightcyan\" >Build Start Time (UTC)</td>" >> ./build_results.html
-echo "        <td>TEMPLATE_BUILD_TIME</td>" >> ./build_results.html
-echo "      </tr>" >> ./build_results.html
-echo "      <tr>" >> ./build_results.html
-echo "        <td bgcolor = \"lightcyan\" >GIT Repository</td>" >> ./build_results.html
-echo "        <td>$GIT_URL</td>" >> ./build_results.html
-echo "      </tr>" >> ./build_results.html
-echo "      <tr>" >> ./build_results.html
-echo "        <td bgcolor = \"lightcyan\" >Job Trigger</td>" >> ./build_results.html
-if [ $PU_TRIG -eq 1 ]; then echo "        <td>Push Event</td>" >> ./build_results.html; fi
-if [ $MR_TRIG -eq 1 ]; then echo "        <td>Merge-Request</td>" >> ./build_results.html; fi
-echo "      </tr>" >> ./build_results.html
-if [ $PU_TRIG -eq 1 ]
-then
-    echo "      <tr>" >> ./build_results.html
-    echo "        <td bgcolor = \"lightcyan\" >Branch</td>" >> ./build_results.html
-    echo "        <td>$SOURCE_BRANCH</td>" >> ./build_results.html
-    echo "      </tr>" >> ./build_results.html
-    echo "      <tr>" >> ./build_results.html
-    echo "        <td bgcolor = \"lightcyan\" >Commit ID</td>" >> ./build_results.html
-    echo "        <td>$SOURCE_COMMIT_ID</td>" >> ./build_results.html
-    echo "      </tr>" >> ./build_results.html
-fi
-if [ $MR_TRIG -eq 1 ]
-then
-    echo "      <tr>" >> ./build_results.html
-    echo "        <td bgcolor = \"lightcyan\" >Source Branch</td>" >> ./build_results.html
-    echo "        <td>$SOURCE_BRANCH</td>" >> ./build_results.html
-    echo "      </tr>" >> ./build_results.html
+function report_build {
+    echo "############################################################"
+    echo "OAI CI VM script"
+    echo "############################################################"
+
+    echo "JENKINS_WKSP        = $JENKINS_WKSP"
+    echo "GIT_URL             = $GIT_URL"
+
+    cd ${JENKINS_WKSP}
+    echo "<!DOCTYPE html>" > ./build_results.html
+    echo "<html class=\"no-js\" lang=\"en-US\">" >> ./build_results.html
+    echo "<head>" >> ./build_results.html
+    echo "  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">" >> ./build_results.html
+    echo "  <link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css\">" >> ./build_results.html
+    echo "  <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js\"></script>" >> ./build_results.html
+    echo "  <script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js\"></script>" >> ./build_results.html
+    echo "  <title>Build Results for $JOB_NAME job build #$BUILD_ID</title>" >> ./build_results.html
+    echo "  <base href = \"http://www.openairinterface.org/\" />" >> ./build_results.html
+    echo "</head>" >> ./build_results.html
+    echo "<body><div class=\"container\">" >> ./build_results.html
+    echo "  <br>" >> ./build_results.html
+    echo "  <table style=\"border-collapse: collapse; border: none;\">" >> ./build_results.html
+    echo "    <tr style=\"border-collapse: collapse; border: none;\">" >> ./build_results.html
+    echo "      <td style=\"border-collapse: collapse; border: none;\">" >> ./build_results.html
+    echo "        <a href=\"http://www.openairinterface.org/\">" >> ./build_results.html
+    echo "           <img src=\"/wp-content/uploads/2016/03/cropped-oai_final_logo2.png\" alt=\"\" border=\"none\" height=50 width=150>" >> ./build_results.html
+    echo "           </img>" >> ./build_results.html
+    echo "        </a>" >> ./build_results.html
+    echo "      </td>" >> ./build_results.html
+    echo "      <td style=\"border-collapse: collapse; border: none; vertical-align: center;\">" >> ./build_results.html
+    echo "        <b><font size = \"6\">Job Summary -- Job: $JOB_NAME -- Build-ID: $BUILD_ID</font></b>" >> ./build_results.html
+    echo "      </td>" >> ./build_results.html
+    echo "    </tr>" >> ./build_results.html
+    echo "  </table>" >> ./build_results.html
+    echo "  <br>" >> ./build_results.html
+    echo "   <table border = \"1\">" >> ./build_results.html
     echo "      <tr>" >> ./build_results.html
-    echo "        <td bgcolor = \"lightcyan\" >Source Commit ID</td>" >> ./build_results.html
-    echo "        <td>$SOURCE_COMMIT_ID</td>" >> ./build_results.html
+    echo "        <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-time\"></span> Build Start Time (UTC)</td>" >> ./build_results.html
+    echo "        <td>TEMPLATE_BUILD_TIME</td>" >> ./build_results.html
     echo "      </tr>" >> ./build_results.html
     echo "      <tr>" >> ./build_results.html
-    echo "        <td bgcolor = \"lightcyan\" >Target Branch</td>" >> ./build_results.html
-    echo "        <td>$TARGET_BRANCH</td>" >> ./build_results.html
+    echo "        <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-cloud-upload\"></span> GIT Repository</td>" >> ./build_results.html
+    echo "        <td><a href=\"$GIT_URL\">$GIT_URL</a></td>" >> ./build_results.html
     echo "      </tr>" >> ./build_results.html
     echo "      <tr>" >> ./build_results.html
-    echo "        <td bgcolor = \"lightcyan\" >Target Commit ID</td>" >> ./build_results.html
-    echo "        <td>$TARGET_COMMIT_ID</td>" >> ./build_results.html
+    echo "        <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-wrench\"></span> Job Trigger</td>" >> ./build_results.html
+    if [ $PU_TRIG -eq 1 ]; then echo "        <td>Push Event</td>" >> ./build_results.html; fi
+    if [ $MR_TRIG -eq 1 ]; then echo "        <td>Merge-Request</td>" >> ./build_results.html; fi
     echo "      </tr>" >> ./build_results.html
-fi
-echo "   </table>" >> ./build_results.html
-echo "   <h2>Build Summary</h2>" >> ./build_results.html
-
-if [ -f ./oai_rules_result.txt ]
-then
-    echo "   <h3>OAI Coding / Formatting Guidelines Check</h3>" >> ./build_results.html
-    echo "   <table border = "1">" >> ./build_results.html
-    echo "      <tr>" >> ./build_results.html
-    echo "        <td bgcolor = \"lightcyan\" >Result:</td>" >> ./build_results.html
-    NB_FILES=`cat ./oai_rules_result.txt`
-    if [ $NB_FILES = "0" ]
-    then 
-        if [ $PU_TRIG -eq 1 ]; then echo "        <td bgcolor = \"green\">All files in repository follow OAI rules. </td>" >> ./build_results.html; fi
-        if [ $MR_TRIG -eq 1 ]; then echo "        <td bgcolor = \"green\">All modified files in Merge-Request follow OAI rules.</td>" >> ./build_results.html; fi
+    if [ $PU_TRIG -eq 1 ]
+    then
+        echo "      <tr>" >> ./build_results.html
+        echo "        <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-tree-deciduous\"></span> Branch</td>" >> ./build_results.html
+        echo "        <td>$SOURCE_BRANCH</td>" >> ./build_results.html
         echo "      </tr>" >> ./build_results.html
-        echo "   </table>" >> ./build_results.html
-    else
-        if [ $PU_TRIG -eq 1 ]; then echo "        <td bgcolor = \"orange\">$NB_FILES files in repository DO NOT follow OAI rules. </td>" >> ./build_results.html; fi
-        if [ $MR_TRIG -eq 1 ]; then echo "        <td bgcolor = \"orange\">$NB_FILES modified files in Merge-Request DO NOT follow OAI rules.</td>" >> ./build_results.html; fi
+        echo "      <tr>" >> ./build_results.html
+        echo "        <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-tag\"></span> Commit ID</td>" >> ./build_results.html
+        echo "        <td>$SOURCE_COMMIT_ID</td>" >> ./build_results.html
+        echo "      </tr>" >> ./build_results.html
+        if [ -e .git/CI_COMMIT_MSG ]
+        then
+            echo "      <tr>" >> ./build_results.html
+            echo "        <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-comment\"></span> Commit Message</td>" >> ./build_results.html
+            MSG=`cat .git/CI_COMMIT_MSG`
+            echo "        <td>$MSG</td>" >> ./build_results.html
+            echo "      </tr>" >> ./build_results.html
+        fi
+    fi
+    if [ $MR_TRIG -eq 1 ]
+    then
+        echo "      <tr>" >> ./build_results.html
+        echo "        <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-log-out\"></span> Source Branch</td>" >> ./build_results.html
+        echo "        <td>$SOURCE_BRANCH</td>" >> ./build_results.html
+        echo "      </tr>" >> ./build_results.html
+        echo "      <tr>" >> ./build_results.html
+        echo "        <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-tag\"></span> Source Commit ID</td>" >> ./build_results.html
+        echo "        <td>$SOURCE_COMMIT_ID</td>" >> ./build_results.html
         echo "      </tr>" >> ./build_results.html
+        if [ -e .git/CI_COMMIT_MSG ]
+        then
+            echo "      <tr>" >> ./build_results.html
+            echo "        <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-comment\"></span> Source Commit Message</td>" >> ./build_results.html
+            MSG=`cat .git/CI_COMMIT_MSG`
+            echo "        <td>$MSG</td>" >> ./build_results.html
+            echo "      </tr>" >> ./build_results.html
+        fi
+        echo "      <tr>" >> ./build_results.html
+        echo "        <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-log-in\"></span> Target Branch</td>" >> ./build_results.html
+        echo "        <td>$TARGET_BRANCH</td>" >> ./build_results.html
+        echo "      </tr>" >> ./build_results.html
+        echo "      <tr>" >> ./build_results.html
+        echo "        <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-tag\"></span> Target Commit ID</td>" >> ./build_results.html
+        echo "        <td>$TARGET_COMMIT_ID</td>" >> ./build_results.html
+        echo "      </tr>" >> ./build_results.html
+    fi
+    echo "   </table>" >> ./build_results.html
+    echo "   <h2>Build Summary</h2>" >> ./build_results.html
+
+    if [ -f ./oai_rules_result.txt ]
+    then
+        echo "   <h3>OAI Coding / Formatting Guidelines Check</h3>" >> ./build_results.html
+        NB_FILES=`cat ./oai_rules_result.txt`
+        if [ $NB_FILES = "0" ]
+        then
+            echo "   <div class=\"alert alert-success\">" >> ./build_results.html
+            if [ $PU_TRIG -eq 1 ]; then echo "      <strong>All files in repository follow OAI rules. <span class=\"glyphicon glyphicon-ok-circle\"></span></strong>" >> ./build_results.html; fi
+            if [ $MR_TRIG -eq 1 ]; then echo "      <strong>All modified files in Merge-Request follow OAI rules. <span class=\"glyphicon glyphicon-ok-circle\"></span></strong>" >> ./build_results.html; fi
+            echo "   </div>" >> ./build_results.html
+        else
+            echo "   <div class=\"alert alert-warning\">" >> ./build_results.html
+            if [ $PU_TRIG -eq 1 ]; then echo "      <strong>$NB_FILES files in repository DO NOT follow OAI rules. <span class=\"glyphicon glyphicon-warning-sign\"></span></strong>" >> ./build_results.html; fi
+            if [ $MR_TRIG -eq 1 ]; then echo "      <strong>$NB_FILES modified files in Merge-Request DO NOT follow OAI rules. <span class=\"glyphicon glyphicon-warning-sign\"></span></strong>" >> ./build_results.html; fi
+            echo "   </div>" >> ./build_results.html
+        fi
         if [ -f ./oai_rules_result_list.txt ]
         then
-            awk '{print "      <tr><td></td><td>"$1"</td></tr>"}' ./oai_rules_result_list.txt >> ./build_results.html
+            echo "   <button data-toggle=\"collapse\" data-target=\"#oai-formatting-details\">More details on formatting check</button>" >> ./build_results.html
+            echo "   <div id=\"oai-formatting-details\" class=\"collapse\">" >> ./build_results.html
+            echo "   <p>Please apply the following command to this(ese) file(s): </p>" >> ./build_results.html
+            echo "   <p style=\"margin-left: 30px\"><strong><code>astyle --options=ci-scripts/astyle-options.txt filename(s)</code></strong></p>" >> ./build_results.html
+            echo "   <table border = 1>" >> ./build_results.html
+            echo "      <tr>" >> ./build_results.html
+            echo "        <th bgcolor = \"lightcyan\" >Filename</th>" >> ./build_results.html
+            echo "      </tr>" >> ./build_results.html
+            awk '{print "      <tr><td>"$1"</td></tr>"}' ./oai_rules_result_list.txt >> ./build_results.html
+            echo "   </table>" >> ./build_results.html
+            echo "   </div>" >> ./build_results.html
         fi
-        echo "   </table>" >> ./build_results.html
-        echo "   <p>Please apply the following command to this(ese) file(s): </p>" >> ./build_results.html
-        echo "   <p style=\"margin-left: 30px\"><strong><code>astyle --options=ci-scripts/astyle-options.txt filename(s)</code></strong></p>" >> ./build_results.html
     fi
-fi
-
-echo "   <h2>Ubuntu 16.04 LTS -- Summary</h2>" >> ./build_results.html
-
-sca_summary_table_header "OAI Static Code Analysis with CPPCHECK"
-sca_summary_table_row ./archives/cppcheck/cppcheck.xml "Uninitialized variable" uninitvar
-sca_summary_table_row ./archives/cppcheck/cppcheck.xml "Uninitialized struct member" uninitStructMember
-sca_summary_table_row ./archives/cppcheck/cppcheck.xml "Memory leak" memleak
-sca_summary_table_row ./archives/cppcheck/cppcheck.xml "Memory is freed twice" doubleFree
-sca_summary_table_row ./archives/cppcheck/cppcheck.xml "Resource leak" resourceLeak
-sca_summary_table_row ./archives/cppcheck/cppcheck.xml "Possible null pointer dereference" nullPointer
-sca_summary_table_row ./archives/cppcheck/cppcheck.xml "Array access  out of bounds" arrayIndexOutOfBounds
-sca_summary_table_row ./archives/cppcheck/cppcheck.xml "Buffer is accessed out of bounds" bufferAccessOutOfBounds
-sca_summary_table_row ./archives/cppcheck/cppcheck.xml "Expression depends on order of evaluation of side effects" unknownEvaluationOrder
-sca_summary_table_footer ./archives/cppcheck/cppcheck.xml
-
-summary_table_header "OAI Build eNB -- USRP option"
-summary_table_row "LTE SoftModem - Release 14" ./archives/enb_usrp/lte-softmodem.Rel14.txt "Built target lte-softmodem" ./enb_usrp_row1.html
-summary_table_row "Coding - Release 14" ./archives/enb_usrp/coding.Rel14.txt "Built target coding" ./enb_usrp_row2.html
-summary_table_row "OAI USRP device if - Release 14" ./archives/enb_usrp/oai_usrpdevif.Rel14.txt "Built target oai_usrpdevif" ./enb_usrp_row3.html
-summary_table_row "Parameters Lib Config - Release 14" ./archives/enb_usrp/params_libconfig.Rel14.txt "Built target params_libconfig" ./enb_usrp_row4.html
-summary_table_footer
-
-summary_table_header "OAI Build basic simulator option"
-summary_table_row "Basic Simulator eNb - Release 14" ./archives/basic_sim/basic_simulator_enb.txt "Built target lte-softmodem" ./basic_sim_row1.html
-summary_table_row "Basic Simulator UE - Release 14" ./archives/basic_sim/basic_simulator_ue.txt "Built target lte-uesoftmodem" ./basic_sim_row2.html
-summary_table_row "Conf 2 UE data - Release 14" ./archives/basic_sim/conf2uedata.Rel14.txt "Built target conf2uedata" ./basic_sim_row3.html
-summary_table_footer
-
-summary_table_header "OAI Build Physical simulators option"
-summary_table_row "DL Simulator - Release 14" ./archives/phy_sim/dlsim.Rel14.txt "Built target dlsim" ./phy_sim_row1.html
-summary_table_row "UL Simulator - Release 14" ./archives/phy_sim/ulsim.Rel14.txt "Built target ulsim" ./phy_sim_row2.html
-summary_table_row "Coding - Release 14" ./archives/phy_sim/coding.Rel14.txt "Built target coding" ./phy_sim_row3.html
-summary_table_footer
-
-summary_table_header "OAI Build eNB -- ETHERNET transport option"
-summary_table_row "LTE SoftModem w/o S1 - Release 14" ./archives/enb_eth/lte-softmodem-nos1.Rel14.txt "Built target lte-softmodem" ./enb_eth_row1.html
-summary_table_row "Coding - Release 14" ./archives/enb_eth/coding.Rel14.txt "Built target coding" ./enb_eth_row2.html
-summary_table_row "OAI ETHERNET transport - Release 14" ./archives/enb_eth/oai_eth_transpro.Rel14.txt "Built target oai_eth_transpro" ./enb_eth_row3.html
-summary_table_row "Parameters Lib Config - Release 14" ./archives/enb_eth/params_libconfig.Rel14.txt "Built target params_libconfig" ./enb_eth_row4.html
-summary_table_row "RB Tools - Release 14" ./archives/enb_eth/rb_tool.Rel14.txt "Built target rb_tool" ./enb_eth_row5.html
-summary_table_row "NAS Mesh - Release 14" ./archives/enb_eth/nasmesh.Rel14.txt "Built target nasmesh" ./enb_eth_row6.html
-summary_table_footer
-
-summary_table_header "OAI Build UE -- ETHERNET transport option"
-summary_table_row "LTE UE SoftModem w/o S1 - Release 14" ./archives/ue_eth/lte-uesoftmodem-nos1.Rel14.txt "Built target lte-uesoftmodem" ./ue_eth_row1.html
-summary_table_row "Coding - Release 14" ./archives/ue_eth/coding.Rel14.txt "Built target coding" ./ue_eth_row2.html
-summary_table_row "OAI ETHERNET transport - Release 14" ./archives/ue_eth/oai_eth_transpro.Rel14.txt "Built target oai_eth_transpro" ./ue_eth_row3.html
-summary_table_row "Parameters Lib Config - Release 14" ./archives/ue_eth/params_libconfig.Rel14.txt "Built target params_libconfig" ./ue_eth_row4.html
-summary_table_row "RB Tools - Release 14" ./archives/ue_eth/rb_tool.Rel14.txt "Built target rb_tool" ./ue_eth_row5.html
-summary_table_row "NAS Mesh - Release 14" ./archives/ue_eth/nasmesh.Rel14.txt "Built target nasmesh" ./ue_eth_row6.html
-summary_table_footer
-
-echo "   <h2>Red Hat (CentOS Linux release 7.4.1708) -- Summary</h2>" >> ./build_results.html
-
-summary_table_header "Red Hat -- OAI Build eNB -- USRP option"
-summary_table_row "LTE SoftModem - Release 14" ./archives/red_hat/lte-softmodem.Rel14.txt "Built target lte-softmodem" ./enb_usrp_rh_row1.html
-summary_table_row "Coding - Release 14" ./archives/red_hat/coding.Rel14.txt "Built target coding" ./enb_usrp_rh_row2.html
-summary_table_row "OAI USRP device if - Release 14" ./archives/red_hat/oai_usrpdevif.Rel14.txt "Built target oai_usrpdevif" ./enb_usrp_rh_row3.html
-summary_table_row "Parameters Lib Config - Release 14" ./archives/red_hat/params_libconfig.Rel14.txt "Built target params_libconfig" ./enb_usrp_rh_row4.html
-summary_table_footer
-
-echo "   <h3>Details</h3>" >> ./build_results.html
-
-for DETAILS_TABLE in `ls ./enb_usrp_row*.html`
-do
-    cat $DETAILS_TABLE >> ./build_results.html
-done
-for DETAILS_TABLE in `ls ./basic_sim_row*.html`
-do
-    cat $DETAILS_TABLE >> ./build_results.html
-done
-for DETAILS_TABLE in `ls ./phy_sim_row*.html`
-do
-    cat $DETAILS_TABLE >> ./build_results.html
-done
-for DETAILS_TABLE in `ls ./enb_eth_row*.html`
-do
-    cat $DETAILS_TABLE >> ./build_results.html
-done
-for DETAILS_TABLE in `ls ./ue_eth_row*.html`
-do
-    cat $DETAILS_TABLE >> ./build_results.html
-done
-for DETAILS_TABLE in `ls ./enb_usrp_rh_row*.html`
-do
-    cat $DETAILS_TABLE >> ./build_results.html
-done
-rm -f ./enb_usrp_row*.html ./basic_sim_row*.html ./phy_sim_row*.html ./enb_eth_row*.html ./ue_eth_row*.html ./enb_usrp_rh_row*.html
-
-echo "</body>" >> ./build_results.html
-echo "</html>" >> ./build_results.html
-
-exit 0
+
+    echo "   <h2>Ubuntu 16.04 LTS -- Summary</h2>" >> ./build_results.html
+
+    sca_summary_table_header ./archives/cppcheck/cppcheck.xml "OAI Static Code Analysis with CPPCHECK"
+    sca_summary_table_row ./archives/cppcheck/cppcheck.xml "Uninitialized variable" uninitvar
+    sca_summary_table_row ./archives/cppcheck/cppcheck.xml "Uninitialized struct member" uninitStructMember
+    sca_summary_table_row ./archives/cppcheck/cppcheck.xml "Memory leak" memleak
+    sca_summary_table_row ./archives/cppcheck/cppcheck.xml "Memory is freed twice" doubleFree
+    sca_summary_table_row ./archives/cppcheck/cppcheck.xml "Resource leak" resourceLeak
+    sca_summary_table_row ./archives/cppcheck/cppcheck.xml "Possible null pointer dereference" nullPointer
+    sca_summary_table_row ./archives/cppcheck/cppcheck.xml "Array access  out of bounds" arrayIndexOutOfBounds
+    sca_summary_table_row ./archives/cppcheck/cppcheck.xml "Buffer is accessed out of bounds" bufferAccessOutOfBounds
+    sca_summary_table_row ./archives/cppcheck/cppcheck.xml "Expression depends on order of evaluation of side effects" unknownEvaluationOrder
+    sca_summary_table_footer ./archives/cppcheck/cppcheck.xml
+
+    summary_table_header "OAI Build eNB -- USRP option" ./archives/enb_usrp
+    summary_table_row "LTE SoftModem - Release 14" ./archives/enb_usrp/lte-softmodem.Rel14.txt "Built target lte-softmodem" ./enb_usrp_row1.html
+    summary_table_row "Coding - Release 14" ./archives/enb_usrp/coding.Rel14.txt "Built target coding" ./enb_usrp_row2.html
+    summary_table_row "OAI USRP device if - Release 14" ./archives/enb_usrp/oai_usrpdevif.Rel14.txt "Built target oai_usrpdevif" ./enb_usrp_row3.html
+    summary_table_row "Parameters Lib Config - Release 14" ./archives/enb_usrp/params_libconfig.Rel14.txt "Built target params_libconfig" ./enb_usrp_row4.html
+    summary_table_footer
+
+    summary_table_header "OAI Build basic simulator option" ./archives/basic_sim
+    summary_table_row "Basic Simulator eNb - Release 14" ./archives/basic_sim/basic_simulator_enb.txt "Built target lte-softmodem" ./basic_sim_row1.html
+    summary_table_row "Basic Simulator UE - Release 14" ./archives/basic_sim/basic_simulator_ue.txt "Built target lte-uesoftmodem" ./basic_sim_row2.html
+    summary_table_row "Conf 2 UE data - Release 14" ./archives/basic_sim/conf2uedata.Rel14.txt "Built target conf2uedata" ./basic_sim_row3.html
+    summary_table_footer
+
+    summary_table_header "OAI Build Physical simulators option" ./archives/phy_sim
+    summary_table_row "DL Simulator - Release 14" ./archives/phy_sim/dlsim.Rel14.txt "Built target dlsim" ./phy_sim_row1.html
+    summary_table_row "UL Simulator - Release 14" ./archives/phy_sim/ulsim.Rel14.txt "Built target ulsim" ./phy_sim_row2.html
+    summary_table_row "Coding - Release 14" ./archives/phy_sim/coding.Rel14.txt "Built target coding" ./phy_sim_row3.html
+    summary_table_footer
+
+
+    if [ -f archives/gnb_usrp/nr-softmodem.Rel14.txt ]
+    then
+        summary_table_header "OAI Build gNB -- USRP option" ./archives/gnb_usrp
+        summary_table_row "LTE SoftModem - Release 14" ./archives/gnb_usrp/nr-softmodem.Rel14.txt "Built target nr-softmodem" ./gnb_usrp_row1.html
+        summary_table_row "Coding - Release 14" ./archives/gnb_usrp/coding.Rel14.txt "Built target coding" ./gnb_usrp_row2.html
+        summary_table_row "OAI USRP device if - Release 14" ./archives/gnb_usrp/oai_usrpdevif.Rel14.txt "Built target oai_usrpdevif" ./gnb_usrp_row3.html
+        summary_table_row "Parameters Lib Config - Release 14" ./archives/gnb_usrp/params_libconfig.Rel14.txt "Built target params_libconfig" ./gnb_usrp_row4.html
+        summary_table_footer
+    fi
+
+    if [ -f archives/nrue_usrp/nr-uesoftmodem.Rel14.txt ]
+    then
+        summary_table_header "OAI Build 5G NR UE -- USRP option" ./archives/nrue_usrp
+        summary_table_row "UE SoftModem - Release 14" ./archives/nrue_usrp/nr-uesoftmodem.Rel14.txt "Built target nr-uesoftmodem" ./nrue_usrp_row1.html
+        summary_table_row "Coding - Release 14" ./archives/nrue_usrp/coding.Rel14.txt "Built target coding" ./nrue_usrp_row2.html
+        summary_table_row "OAI USRP device if - Release 14" ./archives/nrue_usrp/oai_usrpdevif.Rel14.txt "Built target oai_usrpdevif" ./nrue_usrp_row3.html
+        summary_table_row "Parameters Lib Config - Release 14" ./archives/nrue_usrp/params_libconfig.Rel14.txt "Built target params_libconfig" ./nrue_usrp_row4.html
+        summary_table_footer
+    fi
+
+    summary_table_header "OAI Build eNB -- ETHERNET transport option" ./archives/enb_eth
+    summary_table_row "LTE SoftModem w/o S1 - Release 14" ./archives/enb_eth/lte-softmodem-nos1.Rel14.txt "Built target lte-softmodem" ./enb_eth_row1.html
+    summary_table_row "Coding - Release 14" ./archives/enb_eth/coding.Rel14.txt "Built target coding" ./enb_eth_row2.html
+    summary_table_row "OAI ETHERNET transport - Release 14" ./archives/enb_eth/oai_eth_transpro.Rel14.txt "Built target oai_eth_transpro" ./enb_eth_row3.html
+    summary_table_row "Parameters Lib Config - Release 14" ./archives/enb_eth/params_libconfig.Rel14.txt "Built target params_libconfig" ./enb_eth_row4.html
+    summary_table_row "RB Tools - Release 14" ./archives/enb_eth/rb_tool.Rel14.txt "Built target rb_tool" ./enb_eth_row5.html
+    summary_table_row "NAS Mesh - Release 14" ./archives/enb_eth/nasmesh.Rel14.txt "Built target nasmesh" ./enb_eth_row6.html
+    summary_table_footer
+
+    summary_table_header "OAI Build UE -- ETHERNET transport option" ./archives/ue_eth
+    summary_table_row "LTE UE SoftModem w/o S1 - Release 14" ./archives/ue_eth/lte-uesoftmodem-nos1.Rel14.txt "Built target lte-uesoftmodem" ./ue_eth_row1.html
+    summary_table_row "Coding - Release 14" ./archives/ue_eth/coding.Rel14.txt "Built target coding" ./ue_eth_row2.html
+    summary_table_row "OAI ETHERNET transport - Release 14" ./archives/ue_eth/oai_eth_transpro.Rel14.txt "Built target oai_eth_transpro" ./ue_eth_row3.html
+    summary_table_row "Parameters Lib Config - Release 14" ./archives/ue_eth/params_libconfig.Rel14.txt "Built target params_libconfig" ./ue_eth_row4.html
+    summary_table_row "RB Tools - Release 14" ./archives/ue_eth/rb_tool.Rel14.txt "Built target rb_tool" ./ue_eth_row5.html
+    summary_table_row "NAS Mesh - Release 14" ./archives/ue_eth/nasmesh.Rel14.txt "Built target nasmesh" ./ue_eth_row6.html
+    summary_table_footer
+
+    if [ -e ./archives/red_hat ]
+    then
+        echo "   <h2>Red Hat Enterprise Linux Server release 7.6) -- Summary</h2>" >> ./build_results.html
+
+        summary_table_header "Red Hat -- OAI Build eNB -- USRP option" ./archives/red_hat
+        summary_table_row "LTE SoftModem - Release 14" ./archives/red_hat/lte-softmodem.Rel14.txt "Built target lte-softmodem" ./enb_usrp_rh_row1.html
+        summary_table_row "Coding - Release 14" ./archives/red_hat/coding.Rel14.txt "Built target coding" ./enb_usrp_rh_row2.html
+        summary_table_row "OAI USRP device if - Release 14" ./archives/red_hat/oai_usrpdevif.Rel14.txt "Built target oai_usrpdevif" ./enb_usrp_rh_row3.html
+        summary_table_row "Parameters Lib Config - Release 14" ./archives/red_hat/params_libconfig.Rel14.txt "Built target params_libconfig" ./enb_usrp_rh_row4.html
+        summary_table_footer
+    fi
+
+    echo "   <h3>Details</h3>" >> ./build_results.html
+    echo "   <button data-toggle=\"collapse\" data-target=\"#oai-compilation-details\">Details for Compilation Errors and Warnings </button>" >> ./build_results.html
+    echo "   <div id=\"oai-compilation-details\" class=\"collapse\">" >> ./build_results.html
+
+    for DETAILS_TABLE in `ls ./enb_usrp_row*.html`
+    do
+        cat $DETAILS_TABLE >> ./build_results.html
+    done
+    for DETAILS_TABLE in `ls ./basic_sim_row*.html`
+    do
+        cat $DETAILS_TABLE >> ./build_results.html
+    done
+    for DETAILS_TABLE in `ls ./phy_sim_row*.html`
+    do
+        cat $DETAILS_TABLE >> ./build_results.html
+    done
+
+    for DETAILS_TABLE in `ls ./gnb_usrp_row*.html`
+    do
+        cat $DETAILS_TABLE >> ./build_results.html
+    done
+    for DETAILS_TABLE in `ls ./nrue_usrp_row*.html`
+    do
+        cat $DETAILS_TABLE >> ./build_results.html
+    done
+    for DETAILS_TABLE in `ls ./enb_eth_row*.html`
+    do
+        cat $DETAILS_TABLE >> ./build_results.html
+    done
+    for DETAILS_TABLE in `ls ./ue_eth_row*.html`
+    do
+        cat $DETAILS_TABLE >> ./build_results.html
+    done
+    if [ -e ./archives/red_hat ]
+    then
+    for DETAILS_TABLE in `ls ./enb_usrp_rh_row*.html`
+    do
+        cat $DETAILS_TABLE >> ./build_results.html
+    done
+    fi
+    rm -f ./*_row*.html
+
+    echo "   </div>" >> ./build_results.html
+    echo "   <p></p>" >> ./build_results.html
+    echo "   <div class=\"well well-lg\">End of Build Report -- Copyright <span class=\"glyphicon glyphicon-copyright-mark\"></span> 2018 <a href=\"http://www.openairinterface.org/\">OpenAirInterface</a>. All Rights Reserved.</div>" >> ./build_results.html
+    echo "</div></body>" >> ./build_results.html
+    echo "</html>" >> ./build_results.html
+}
diff --git a/ci-scripts/reportTestLocally.sh b/ci-scripts/reportTestLocally.sh
index 4bb89500d8f24e9273219b639c565abcc4855705..8608ba20ee86f64bfda44ae37c815de9fb53a422 100755
--- a/ci-scripts/reportTestLocally.sh
+++ b/ci-scripts/reportTestLocally.sh
@@ -20,14 +20,13 @@
 # *      contact@openairinterface.org
 # */
 
-function usage {
-    echo "OAI Test Report script"
+function report_test_usage {
+    echo "OAI CI VM script"
     echo "   Original Author: Raphael Defosseux"
     echo ""
     echo "Usage:"
     echo "------"
-    echo ""
-    echo "    reportTestLocally.sh [OPTIONS]"
+    echo "    oai-ci-vm-tool report-test [OPTIONS]"
     echo ""
     echo "Options:"
     echo "--------"
@@ -47,6 +46,9 @@ function usage {
     echo "    --build-id #### OR -id ####"
     echo "    Specify the build ID of the Jenkins job."
     echo ""
+    echo "    --workspace #### OR -ws ####"
+    echo "    Specify the workspace."
+    echo ""
     echo "    --trigger merge-request OR -mr"
     echo "    --trigger push          OR -pu"
     echo "    Specify trigger action of the Jenkins job. Either a merge-request event or a push event."
@@ -78,513 +80,595 @@ function usage {
     echo ""
 }
 
-function trigger_usage {
-    echo "OAI Test Report script"
-    echo "   Original Author: Raphael Defosseux"
-    echo ""
-    echo "    --trigger merge-request OR -mr"
-    echo "    --trigger push          OR -pu"
-    echo "    Specify trigger action of the Jenkins job. Either a merge-request event or a push event."
-    echo ""
-}
-
-jb_checker=0
-mr_checker=0
-pu_checker=0
-MR_TRIG=0
-PU_TRIG=0
-while [[ $# -gt 0 ]]
-do
-key="$1"
+function report_test {
+    echo "############################################################"
+    echo "OAI CI VM script"
+    echo "############################################################"
 
-case $key in
-    -h|--help)
-    shift
-    usage
-    exit 0
-    ;;
-    -gu|--git-url)
-    GIT_URL="$2"
-    let "jb_checker|=0x1"
-    shift
-    shift
-    ;;
-    -jn|--job-name)
-    JOB_NAME="$2"
-    let "jb_checker|=0x2"
-    shift
-    shift
-    ;;
-    -id|--build-id)
-    BUILD_ID="$2"
-    let "jb_checker|=0x4"
-    shift
-    shift
-    ;;
-    --trigger)
-    TRIG="$2"
-    case $TRIG in
-        merge-request)
-        MR_TRIG=1
-        ;;
-        push)
-        PU_TRIG=1
-        ;;
-        *)
-        echo ""
-        echo "Syntax Error: Invalid Trigger option -> $TRIG"
-        echo ""
-        trigger_usage
-        exit
-        ;;
-    esac
-    let "jb_checker|=0x8"
-    shift
-    shift
-    ;;
-    -mr)
-    MR_TRIG=1
-    let "jb_checker|=0x8"
-    shift
-    ;;
-    -pu)
-    PU_TRIG=1
-    let "jb_checker|=0x8"
-    shift
-    ;;
-    -sb|--src-branch)
-    SOURCE_BRANCH="$2"
-    let "mr_checker|=0x1"
-    shift
-    shift
-    ;;
-    -sc|--src-commit)
-    SOURCE_COMMIT_ID="$2"
-    let "mr_checker|=0x2"
-    shift
-    shift
-    ;;
-    -tb|--target-branch)
-    TARGET_BRANCH="$2"
-    let "mr_checker|=0x4"
-    shift
-    shift
-    ;;
-    -tc|--target-commit)
-    TARGET_COMMIT_ID="$2"
-    let "mr_checker|=0x8"
-    shift
-    shift
-    ;;
-    -br|--branch)
-    SOURCE_BRANCH="$2"
-    let "pu_checker|=0x1"
-    shift
-    shift
-    ;;
-    -co|--commit)
-    SOURCE_COMMIT_ID="$2"
-    let "pu_checker|=0x2"
-    shift
-    shift
-    ;;
-    *)
-    echo "Syntax Error: unknown option: $key"
-    echo ""
-    usage
-    exit 1
-    ;;
-esac
+    echo "JENKINS_WKSP        = $JENKINS_WKSP"
 
-done
-
-if [ $jb_checker -ne 15 ]
-then
-    echo ""
-    echo "Syntax Error: missing job information."
-    # TODO : list missing info
-    echo ""
-    exit 1
-fi
+    cd ${JENKINS_WKSP}
 
-if [ $PU_TRIG -eq 1 ] && [ $MR_TRIG -eq 1 ]
-then
-    echo ""
-    echo "Syntax Error: trigger action incoherent."
-    echo ""
-    trigger_usage
-    exit 1
-fi
-
-if [ $PU_TRIG -eq 1 ]
-then
-    if [ $pu_checker -ne 3 ]
-    then
-        echo ""
-        echo "Syntax Error: missing push information."
-        # TODO : list missing info
-        echo ""
-        exit 1
-    fi
-fi
-
-if [ $MR_TRIG -eq 1 ]
-then
-    if [ $mr_checker -ne 15 ]
-    then
-        echo ""
-        echo "Syntax Error: missing merge-request information."
-        # TODO : list missing info
-        echo ""
-        exit 1
-    fi
-fi
-
-echo "<!DOCTYPE html>" > ./test_simulator_results.html
-echo "<html class=\"no-js\" lang=\"en-US\">" >> ./test_simulator_results.html
-echo "<head>" >> ./test_simulator_results.html
-echo "  <title>Simulator Results for $JOB_NAME job build #$BUILD_ID</title>" >> ./test_simulator_results.html
-echo "  <base href = \"http://www.openairinterface.org/\" />" >> ./test_simulator_results.html
-echo "</head>" >> ./test_simulator_results.html
-echo "<body>" >> ./test_simulator_results.html
-echo "  <table style=\"border-collapse: collapse; border: none;\">" >> ./test_simulator_results.html
-echo "    <tr style=\"border-collapse: collapse; border: none;\">" >> ./test_simulator_results.html
-echo "      <td style=\"border-collapse: collapse; border: none;\">" >> ./test_simulator_results.html
-echo "        <a href=\"http://www.openairinterface.org/\">" >> ./test_simulator_results.html
-echo "           <img src=\"/wp-content/uploads/2016/03/cropped-oai_final_logo2.png\" alt=\"\" border=\"none\" height=50 width=150>" >> ./test_simulator_results.html
-echo "           </img>" >> ./test_simulator_results.html
-echo "        </a>" >> ./test_simulator_results.html
-echo "      </td>" >> ./test_simulator_results.html
-echo "      <td style=\"border-collapse: collapse; border: none; vertical-align: center;\">" >> ./test_simulator_results.html
-echo "        <b><font size = \"6\">Job Summary -- Job: $JOB_NAME -- Build-ID: $BUILD_ID</font></b>" >> ./test_simulator_results.html
-echo "      </td>" >> ./test_simulator_results.html
-echo "    </tr>" >> ./test_simulator_results.html
-echo "  </table>" >> ./test_simulator_results.html
-echo "  <br>" >> ./test_simulator_results.html
-echo "   <table border = \"1\">" >> ./test_simulator_results.html
-echo "      <tr>" >> ./test_simulator_results.html
-echo "        <td bgcolor = \"lightcyan\" >Build Start Time (UTC)</td>" >> ./test_simulator_results.html
-echo "        <td>TEMPLATE_BUILD_TIME</td>" >> ./test_simulator_results.html
-echo "      </tr>" >> ./test_simulator_results.html
-echo "      <tr>" >> ./test_simulator_results.html
-echo "        <td bgcolor = \"lightcyan\" >GIT Repository</td>" >> ./test_simulator_results.html
-echo "        <td><a href=\"$GIT_URL\">$GIT_URL</a></td>" >> ./test_simulator_results.html
-echo "      </tr>" >> ./test_simulator_results.html
-echo "      <tr>" >> ./test_simulator_results.html
-echo "        <td bgcolor = \"lightcyan\" >Job Trigger</td>" >> ./test_simulator_results.html
-if [ $PU_TRIG -eq 1 ]; then echo "        <td>Push Event</td>" >> ./test_simulator_results.html; fi
-if [ $MR_TRIG -eq 1 ]; then echo "        <td>Merge-Request</td>" >> ./test_simulator_results.html; fi
-echo "      </tr>" >> ./test_simulator_results.html
-if [ $PU_TRIG -eq 1 ]
-then
-    echo "      <tr>" >> ./test_simulator_results.html
-    echo "        <td bgcolor = \"lightcyan\" >Branch</td>" >> ./test_simulator_results.html
-    echo "        <td>$SOURCE_BRANCH</td>" >> ./test_simulator_results.html
-    echo "      </tr>" >> ./test_simulator_results.html
-    echo "      <tr>" >> ./test_simulator_results.html
-    echo "        <td bgcolor = \"lightcyan\" >Commit ID</td>" >> ./test_simulator_results.html
-    echo "        <td>$SOURCE_COMMIT_ID</td>" >> ./test_simulator_results.html
-    echo "      </tr>" >> ./test_simulator_results.html
-fi
-if [ $MR_TRIG -eq 1 ]
-then
-    echo "      <tr>" >> ./test_simulator_results.html
-    echo "        <td bgcolor = \"lightcyan\" >Source Branch</td>" >> ./test_simulator_results.html
-    echo "        <td>$SOURCE_BRANCH</td>" >> ./test_simulator_results.html
-    echo "      </tr>" >> ./test_simulator_results.html
+    echo "<!DOCTYPE html>" > ./test_simulator_results.html
+    echo "<html class=\"no-js\" lang=\"en-US\">" >> ./test_simulator_results.html
+    echo "<head>" >> ./test_simulator_results.html
+    echo "  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">" >> ./test_simulator_results.html
+    echo "  <link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css\">" >> ./test_simulator_results.html
+    echo "  <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js\"></script>" >> ./test_simulator_results.html
+    echo "  <script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js\"></script>" >> ./test_simulator_results.html
+    echo "  <title>Simulator Results for $JOB_NAME job build #$BUILD_ID</title>" >> ./test_simulator_results.html
+    echo "  <base href = \"http://www.openairinterface.org/\" />" >> ./test_simulator_results.html
+    echo "</head>" >> ./test_simulator_results.html
+    echo "<body><div class=\"container\">" >> ./test_simulator_results.html
+    echo "  <br>" >> ./test_simulator_results.html
+    echo "  <table style=\"border-collapse: collapse; border: none;\">" >> ./test_simulator_results.html
+    echo "    <tr style=\"border-collapse: collapse; border: none;\">" >> ./test_simulator_results.html
+    echo "      <td style=\"border-collapse: collapse; border: none;\">" >> ./test_simulator_results.html
+    echo "        <a href=\"http://www.openairinterface.org/\">" >> ./test_simulator_results.html
+    echo "           <img src=\"/wp-content/uploads/2016/03/cropped-oai_final_logo2.png\" alt=\"\" border=\"none\" height=50 width=150>" >> ./test_simulator_results.html
+    echo "           </img>" >> ./test_simulator_results.html
+    echo "        </a>" >> ./test_simulator_results.html
+    echo "      </td>" >> ./test_simulator_results.html
+    echo "      <td style=\"border-collapse: collapse; border: none; vertical-align: center;\">" >> ./test_simulator_results.html
+    echo "        <b><font size = \"6\">Job Summary -- Job: $JOB_NAME -- Build-ID: $BUILD_ID</font></b>" >> ./test_simulator_results.html
+    echo "      </td>" >> ./test_simulator_results.html
+    echo "    </tr>" >> ./test_simulator_results.html
+    echo "  </table>" >> ./test_simulator_results.html
+    echo "  <br>" >> ./test_simulator_results.html
+    echo "   <table border = \"1\">" >> ./test_simulator_results.html
     echo "      <tr>" >> ./test_simulator_results.html
-    echo "        <td bgcolor = \"lightcyan\" >Source Commit ID</td>" >> ./test_simulator_results.html
-    echo "        <td>$SOURCE_COMMIT_ID</td>" >> ./test_simulator_results.html
+    echo "        <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-time\"></span> Build Start Time (UTC)</td>" >> ./test_simulator_results.html
+    echo "        <td>TEMPLATE_BUILD_TIME</td>" >> ./test_simulator_results.html
     echo "      </tr>" >> ./test_simulator_results.html
     echo "      <tr>" >> ./test_simulator_results.html
-    echo "        <td bgcolor = \"lightcyan\" >Target Branch</td>" >> ./test_simulator_results.html
-    echo "        <td>$TARGET_BRANCH</td>" >> ./test_simulator_results.html
+    echo "        <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-cloud-upload\"></span> GIT Repository</td>" >> ./test_simulator_results.html
+    echo "        <td><a href=\"$GIT_URL\">$GIT_URL</a></td>" >> ./test_simulator_results.html
     echo "      </tr>" >> ./test_simulator_results.html
     echo "      <tr>" >> ./test_simulator_results.html
-    echo "        <td bgcolor = \"lightcyan\" >Target Commit ID</td>" >> ./test_simulator_results.html
-    echo "        <td>$TARGET_COMMIT_ID</td>" >> ./test_simulator_results.html
+    echo "        <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-wrench\"></span> Job Trigger</td>" >> ./test_simulator_results.html
+    if [ $PU_TRIG -eq 1 ]; then echo "        <td>Push Event</td>" >> ./test_simulator_results.html; fi
+    if [ $MR_TRIG -eq 1 ]; then echo "        <td>Merge-Request</td>" >> ./test_simulator_results.html; fi
     echo "      </tr>" >> ./test_simulator_results.html
-fi
-echo "   </table>" >> ./test_simulator_results.html
-echo "   <h2>Test Summary</h2>" >> ./test_simulator_results.html
+    if [ $PU_TRIG -eq 1 ]
+    then
+        echo "      <tr>" >> ./test_simulator_results.html
+        echo "        <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-tree-deciduous\"></span> Branch</td>" >> ./test_simulator_results.html
+        echo "        <td>$SOURCE_BRANCH</td>" >> ./test_simulator_results.html
+        echo "      </tr>" >> ./test_simulator_results.html
+        echo "      <tr>" >> ./test_simulator_results.html
+        echo "        <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-tag\"></span> Commit ID</td>" >> ./test_simulator_results.html
+        echo "        <td>$SOURCE_COMMIT_ID</td>" >> ./test_simulator_results.html
+        echo "      </tr>" >> ./test_simulator_results.html
+        if [ -e .git/CI_COMMIT_MSG ]
+        then
+            echo "      <tr>" >> ./test_simulator_results.html
+            echo "        <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-comment\"></span> Commit Message</td>" >> ./test_simulator_results.html
+            MSG=`cat .git/CI_COMMIT_MSG`
+            echo "        <td>$MSG</td>" >> ./test_simulator_results.html
+            echo "      </tr>" >> ./test_simulator_results.html
+        fi
+    fi
+    if [ $MR_TRIG -eq 1 ]
+    then
+        echo "      <tr>" >> ./test_simulator_results.html
+        echo "        <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-log-out\"></span> Source Branch</td>" >> ./test_simulator_results.html
+        echo "        <td>$SOURCE_BRANCH</td>" >> ./test_simulator_results.html
+        echo "      </tr>" >> ./test_simulator_results.html
+        echo "      <tr>" >> ./test_simulator_results.html
+        echo "        <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-tag\"></span> Source Commit ID</td>" >> ./test_simulator_results.html
+        echo "        <td>$SOURCE_COMMIT_ID</td>" >> ./test_simulator_results.html
+        echo "      </tr>" >> ./test_simulator_results.html
+        if [ -e .git/CI_COMMIT_MSG ]
+        then
+            echo "      <tr>" >> ./test_simulator_results.html
+            echo "        <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-comment\"></span> Commit Message</td>" >> ./test_simulator_results.html
+            MSG=`cat .git/CI_COMMIT_MSG`
+            echo "        <td>$MSG</td>" >> ./test_simulator_results.html
+            echo "      </tr>" >> ./test_simulator_results.html
+        fi
+        echo "      <tr>" >> ./test_simulator_results.html
+        echo "        <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-log-in\"></span> Target Branch</td>" >> ./test_simulator_results.html
+        echo "        <td>$TARGET_BRANCH</td>" >> ./test_simulator_results.html
+        echo "      </tr>" >> ./test_simulator_results.html
+        echo "      <tr>" >> ./test_simulator_results.html
+        echo "        <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-tag\"></span> Target Commit ID</td>" >> ./test_simulator_results.html
+        echo "        <td>$TARGET_COMMIT_ID</td>" >> ./test_simulator_results.html
+        echo "      </tr>" >> ./test_simulator_results.html
+    fi
+    echo "   </table>" >> ./test_simulator_results.html
+    echo "   <h2>Test Summary</h2>" >> ./test_simulator_results.html
 
-ARCHIVES_LOC=archives/basic_sim/test
-if [ -d $ARCHIVES_LOC ]
-then
-    echo "   <h3>Basic Simulator Check</h3>" >> ./test_simulator_results.html
+    ARCHIVES_LOC=archives/basic_sim/test
+    if [ -d $ARCHIVES_LOC ]
+    then
+        echo "   <h3>Basic Simulator Check</h3>" >> ./test_simulator_results.html
 
-    echo "   <table border = \"1\">" >> ./test_simulator_results.html
-    echo "      <tr bgcolor = \"#33CCFF\" >" >> ./test_simulator_results.html
-    echo "        <th>Log File Name</th>" >> ./test_simulator_results.html
-    echo "        <th>Command</th>" >> ./test_simulator_results.html
-    echo "        <th>Status</th>" >> ./test_simulator_results.html
-    echo "        <th>Statistics</th>" >> ./test_simulator_results.html
-    echo "      </tr>" >> ./test_simulator_results.html
+        if [ -f $ARCHIVES_LOC/test_final_status.log ]
+        then
+            if [ `grep -c TEST_OK $ARCHIVES_LOC/test_final_status.log` -eq 1 ]
+            then
+                echo "   <div class=\"alert alert-success\">" >> ./test_simulator_results.html
+                echo "      <strong>TEST was SUCCESSFUL <span class=\"glyphicon glyphicon-ok-circle\"></span></strong>" >> ./test_simulator_results.html
+                echo "   </div>" >> ./test_simulator_results.html
+            else
+                echo "   <div class=\"alert alert-danger\">" >> ./test_simulator_results.html
+                echo "      <strong>TEST was a FAILURE! <span class=\"glyphicon glyphicon-ban-circle\"></span></strong>" >> ./test_simulator_results.html
+                echo "   </div>" >> ./test_simulator_results.html
+            fi
+        else
+            echo "   <div class=\"alert alert-danger\">" >> ./test_simulator_results.html
+            echo "      <strong>COULD NOT DETERMINE TEST FINAL STATUS! <span class=\"glyphicon glyphicon-ban-circle\"></span></strong>" >> ./test_simulator_results.html
+            echo "   </div>" >> ./test_simulator_results.html
+        fi
 
-    TRANS_MODES=("fdd" "tdd")
-    BW_CASES=(05 10 20)
-    for TMODE in ${TRANS_MODES[@]}
-    do
-        for BW in ${BW_CASES[@]}
+        echo "   <button data-toggle=\"collapse\" data-target=\"#oai-basic-sim-test-details\">More details on Basic Simulator test results</button>" >> ./test_simulator_results.html
+        echo "   <div id=\"oai-basic-sim-test-details\" class=\"collapse\">" >> ./test_simulator_results.html
+        echo "   <table border = \"1\">" >> ./test_simulator_results.html
+        echo "      <tr bgcolor = \"#33CCFF\" >" >> ./test_simulator_results.html
+        echo "        <th>Log File Name</th>" >> ./test_simulator_results.html
+        echo "        <th>Command</th>" >> ./test_simulator_results.html
+        echo "        <th>Status</th>" >> ./test_simulator_results.html
+        echo "        <th>Statistics</th>" >> ./test_simulator_results.html
+        echo "      </tr>" >> ./test_simulator_results.html
+
+        TRANS_MODES=("fdd" "tdd")
+        BW_CASES=(05 10 20)
+        for TMODE in ${TRANS_MODES[@]}
         do
-            ENB_LOG=$ARCHIVES_LOC/${TMODE}_${BW}MHz_enb.log
-            UE_LOG=`echo $ENB_LOG | sed -e "s#enb#ue#"`
-            if [ -f $ENB_LOG ] && [ -f $UE_LOG ]
-            then
-                NAME_ENB=`echo $ENB_LOG | sed -e "s#$ARCHIVES_LOC/##"`
-                NAME_UE=`echo $UE_LOG | sed -e "s#$ARCHIVES_LOC/##"`
-                echo "      <tr>" >> ./test_simulator_results.html
-                echo "        <td>$NAME_ENB --- $NAME_UE</td>" >> ./test_simulator_results.html
-                echo "        <td>N/A</td>" >> ./test_simulator_results.html
-                NB_ENB_GOT_SYNC=`egrep -c "got sync" $ENB_LOG`
-                NB_UE_GOT_SYNC=`egrep -c "got sync" $UE_LOG`
-                NB_ENB_SYNCED_WITH_UE=`egrep -c "got UE capabilities for UE" $ENB_LOG`
-                if [ $NB_ENB_GOT_SYNC -eq 1 ] && [ $NB_UE_GOT_SYNC -eq 2 ] && [ $NB_ENB_SYNCED_WITH_UE -eq 1 ]
-                then
-                    echo "        <td bgcolor = \"green\" >OK</td>" >> ./test_simulator_results.html
-                else
-                    echo "        <td bgcolor = \"red\" >KO</td>" >> ./test_simulator_results.html
-                fi
-                echo "        <td><pre>" >> ./test_simulator_results.html
-                if [ $NB_ENB_GOT_SYNC -eq 1 ]
+            for BW in ${BW_CASES[@]}
+            do
+                ENB_LOG=$ARCHIVES_LOC/${TMODE}_${BW}MHz_enb.log
+                UE_LOG=`echo $ENB_LOG | sed -e "s#enb#ue#"`
+                if [ -f $ENB_LOG ] && [ -f $UE_LOG ]
                 then
-                    echo "<font color = \"blue\">- eNB --> got sync</font>" >> ./test_simulator_results.html
-                else
-                    echo "<font color = \"red\"><b>- eNB NEVER got sync</b></font>" >> ./test_simulator_results.html
+                    NAME_ENB=`echo $ENB_LOG | sed -e "s#$ARCHIVES_LOC/##"`
+                    NAME_UE=`echo $UE_LOG | sed -e "s#$ARCHIVES_LOC/##"`
+                    echo "      <tr>" >> ./test_simulator_results.html
+                    echo "        <td>$NAME_ENB --- $NAME_UE</td>" >> ./test_simulator_results.html
+                    echo "        <td>N/A</td>" >> ./test_simulator_results.html
+                    NB_ENB_GOT_SYNC=`egrep -c "got sync" $ENB_LOG`
+                    NB_UE_GOT_SYNC=`egrep -c "got sync" $UE_LOG`
+                    NB_ENB_SYNCED_WITH_UE=`egrep -c "got UE capabilities for UE" $ENB_LOG`
+                    if [ $NB_ENB_GOT_SYNC -eq 1 ] && [ $NB_UE_GOT_SYNC -eq 2 ] && [ $NB_ENB_SYNCED_WITH_UE -eq 1 ]
+                    then
+                        echo "        <td bgcolor = \"green\" >OK</td>" >> ./test_simulator_results.html
+                    else
+                        echo "        <td bgcolor = \"red\" >KO</td>" >> ./test_simulator_results.html
+                    fi
+                    echo "        <td><pre>" >> ./test_simulator_results.html
+                    if [ $NB_ENB_GOT_SYNC -eq 1 ]
+                    then
+                        echo "<font color = \"blue\">- eNB --> got sync</font>" >> ./test_simulator_results.html
+                    else
+                        echo "<font color = \"red\"><b>- eNB NEVER got sync</b></font>" >> ./test_simulator_results.html
+                    fi
+                    if [ $NB_UE_GOT_SYNC -eq 2 ]
+                    then
+                        echo "<font color = \"blue\">- UE --> got sync</font>" >> ./test_simulator_results.html
+                    else
+                        echo "<font color = \"red\"><b>- UE NEVER got sync</b></font>" >> ./test_simulator_results.html
+                    fi
+                    if [ $NB_ENB_SYNCED_WITH_UE -eq 1 ]
+                    then
+                        echo "<font color = \"blue\">- UE attached to eNB</font>" >> ./test_simulator_results.html
+                    else
+                        echo "<font color = \"red\"><b>- UE NEVER attached to eNB</b></font>" >> ./test_simulator_results.html
+                    fi
+                    NB_SEGFAULT_ENB=`egrep -i -c "Segmentation Fault" $ENB_LOG`
+                    if [ $NB_SEGFAULT_ENB -ne 0 ]
+                    then
+                        echo "<font color = \"red\"><b>- eNB --> Segmentation Fault</b></font>" >> ./test_simulator_results.html
+                    fi
+                    NB_SEGFAULT_UE=`egrep -i -c "Segmentation Fault" $UE_LOG`
+                    if [ $NB_SEGFAULT_UE -ne 0 ]
+                    then
+                        echo "<font color = \"red\"><b>- UE --> Segmentation Fault</b></font>" >> ./test_simulator_results.html
+                    fi
+                    NB_ASSERTION_ENB=`egrep -i -c "Assertion" $ENB_LOG`
+                    if [ $NB_ASSERTION_ENB -ne 0 ]
+                    then
+                        echo "<font color = \"red\"><b>- eNB --> Assertion</b></font>" >> ./test_simulator_results.html
+                        awk 'BEGIN{assertion=10}{if(assertion < 3){print "    " $0; assertion++};if ($0 ~/Assertion/){print "    " $0;assertion=1}}END{}' $ENB_LOG >> ./test_simulator_results.html
+                    fi
+                    NB_ASSERTION_UE=`egrep -i -c "Assertion" $UE_LOG`
+                    if [ $NB_ASSERTION_UE -ne 0 ]
+                    then
+                        echo "<font color = \"red\"><b>- eNB --> Assertion</b></font>" >> ./test_simulator_results.html
+                        awk 'BEGIN{assertion=10}{if(assertion < 3){print "    " $0; assertion++};if ($0 ~/Assertion/){print "    " $0;assertion=1}}END{}' $UE_LOG >> ./test_simulator_results.html
+                    fi
+                    echo "        </pre></td>" >> ./test_simulator_results.html
+                    echo "      </tr>" >> ./test_simulator_results.html
                 fi
-                if [ $NB_UE_GOT_SYNC -eq 2 ]
+                PING_CASE=$ARCHIVES_LOC/${TMODE}_${BW}MHz_ping_ue.txt
+                if [ -f $PING_CASE ]
                 then
-                    echo "<font color = \"blue\">- UE --> got sync</font>" >> ./test_simulator_results.html
-                else
-                    echo "<font color = \"red\"><b>- UE NEVER got sync</b></font>" >> ./test_simulator_results.html
+                    echo "      <tr>" >> ./test_simulator_results.html
+                    NAME=`echo $PING_CASE | sed -e "s#$ARCHIVES_LOC/##"`
+                    echo "        <td>$NAME</td>" >> ./test_simulator_results.html
+                    CMD=`egrep "COMMAND IS" $PING_CASE | sed -e "s#COMMAND IS: ##"`
+                    echo "        <td>$CMD</td>" >> ./test_simulator_results.html
+                    FILE_COMPLETE=`egrep -c "ping statistics" $PING_CASE`
+                    if [ $FILE_COMPLETE -eq 0 ]
+                    then
+                        echo "        <td bgcolor = \"red\" >KO</td>" >> ./test_simulator_results.html
+                        echo "        <td>N/A</td>" >> ./test_simulator_results.html
+                    else
+                        NB_TR_PACKETS=`egrep "packets transmitted" $PING_CASE | sed -e "s# packets transmitted.*##"`
+                        NB_RC_PACKETS=`egrep "packets transmitted" $PING_CASE | sed -e "s#^.*packets transmitted, ##" -e "s# received,.*##"`
+                        if [ $NB_TR_PACKETS -eq $NB_RC_PACKETS ]
+                        then
+                            echo "        <td bgcolor = \"green\" >OK</td>" >> ./test_simulator_results.html
+                        else
+                            echo "        <td bgcolor = \"red\" >KO</td>" >> ./test_simulator_results.html
+                        fi
+                        echo "        <td>" >> ./test_simulator_results.html
+                        echo "            <pre>" >> ./test_simulator_results.html
+                        STATS=`egrep "packets transmitted" $PING_CASE | sed -e "s#^.*received, ##" -e "s#, time.*##" -e "s# packet loss##"`
+                        echo "Packet Loss : $STATS" >> ./test_simulator_results.html
+                        RTTMIN=`egrep "rtt min" $PING_CASE | awk '{split($4,a,"/"); print a[1] " " $5}'`
+                        echo "RTT Minimal : $RTTMIN" >> ./test_simulator_results.html
+                        RTTAVG=`egrep "rtt min" $PING_CASE | awk '{split($4,a,"/"); print a[2] " " $5}'`
+                        echo "RTT Average : $RTTAVG" >> ./test_simulator_results.html
+                        RTTMAX=`egrep "rtt min" $PING_CASE | awk '{split($4,a,"/"); print a[3] " " $5}'`
+                        echo "RTT Maximal : $RTTMAX" >> ./test_simulator_results.html
+                        echo "            </pre>" >> ./test_simulator_results.html
+                        echo "        </td>" >> ./test_simulator_results.html
+                    fi
+                    echo "      </tr>" >> ./test_simulator_results.html
                 fi
-                if [ $NB_ENB_SYNCED_WITH_UE -eq 1 ]
+
+                if [ -f $ARCHIVES_LOC/${TMODE}_${BW}*iperf*dl*client*txt ]
                 then
-                    echo "<font color = \"blue\">- UE attached to eNB</font>" >> ./test_simulator_results.html
+                    IPERF_TESTS=`ls $ARCHIVES_LOC/${TMODE}_${BW}*iperf*client*txt`
                 else
-                    echo "<font color = \"red\"><b>- UE NEVER attached to eNB</b></font>" >> ./test_simulator_results.html
-                fi
-                NB_SEGFAULT_ENB=`egrep -i -c "Segmentation Fault" $ENB_LOG`
-                if [ $NB_SEGFAULT_ENB -ne 0 ]
-                then
-                    echo "<font color = \"red\"><b>- eNB --> Segmentation Fault</b></font>" >> ./test_simulator_results.html
+                    echo "There are no iperf files"
+                    IPERF_TESTS=""
                 fi
-                NB_SEGFAULT_UE=`egrep -i -c "Segmentation Fault" $UE_LOG`
-                if [ $NB_SEGFAULT_UE -ne 0 ]
-                then
-                    echo "<font color = \"red\"><b>- UE --> Segmentation Fault</b></font>" >> ./test_simulator_results.html
-                fi
-                NB_ASSERTION_ENB=`egrep -i -c "Assertion" $ENB_LOG`
-                if [ $NB_ASSERTION_ENB -ne 0 ]
-                then
-                    echo "<font color = \"red\"><b>- eNB --> Assertion</b></font>" >> ./test_simulator_results.html
-                    awk 'BEGIN{assertion=10}{if(assertion < 3){print "    " $0; assertion++};if ($0 ~/Assertion/){print "    " $0;assertion=1}}END{}' $ENB_LOG >> ./test_simulator_results.html
-                fi
-                NB_ASSERTION_UE=`egrep -i -c "Assertion" $UE_LOG`
-                if [ $NB_ASSERTION_UE -ne 0 ]
-                then
-                    echo "<font color = \"red\"><b>- eNB --> Assertion</b></font>" >> ./test_simulator_results.html
-                    awk 'BEGIN{assertion=10}{if(assertion < 3){print "    " $0; assertion++};if ($0 ~/Assertion/){print "    " $0;assertion=1}}END{}' $UE_LOG >> ./test_simulator_results.html
-                fi
-                echo "        </pre></td>" >> ./test_simulator_results.html
-                echo "      </tr>" >> ./test_simulator_results.html
-            fi
-            PING_CASE=$ARCHIVES_LOC/${TMODE}_${BW}MHz_ping_ue.txt
-            if [ -f $PING_CASE ]
-            then
-                echo "      <tr>" >> ./test_simulator_results.html
-                NAME=`echo $PING_CASE | sed -e "s#$ARCHIVES_LOC/##"`
-                echo "        <td>$NAME</td>" >> ./test_simulator_results.html
-                CMD=`egrep "COMMAND IS" $PING_CASE | sed -e "s#COMMAND IS: ##"`
-                echo "        <td>$CMD</td>" >> ./test_simulator_results.html
-                FILE_COMPLETE=`egrep -c "ping statistics" $PING_CASE`
-                if [ $FILE_COMPLETE -eq 0 ]
-                then
-                    echo "        <td bgcolor = \"red\" >KO</td>" >> ./test_simulator_results.html
-                    echo "        <td>N/A</td>" >> ./test_simulator_results.html
-                else
-                    NB_TR_PACKETS=`egrep "packets transmitted" $PING_CASE | sed -e "s# packets transmitted.*##"`
-                    NB_RC_PACKETS=`egrep "packets transmitted" $PING_CASE | sed -e "s#^.*packets transmitted, ##" -e "s# received,.*##"`
-                    if [ $NB_TR_PACKETS -eq $NB_RC_PACKETS ]
+                for IPERF_CASE in $IPERF_TESTS
+                do
+                    echo "      <tr>" >> ./test_simulator_results.html
+                    NAME=`echo $IPERF_CASE | sed -e "s#$ARCHIVES_LOC/##"`
+                    echo "        <td>$NAME</td>" >> ./test_simulator_results.html
+                    CMD=`egrep "COMMAND IS" $IPERF_CASE | sed -e "s#COMMAND IS: ##"`
+                    echo "        <td>$CMD</td>" >> ./test_simulator_results.html
+                    REQ_BITRATE=`echo $CMD | sed -e "s#^.*-b ##" -e "s#-i 1.*##"`
+                    if [[ $REQ_BITRATE =~ .*K.* ]]
+                    then
+                        REQ_BITRATE=`echo $REQ_BITRATE | sed -e "s#K##"`
+                        FLOAT_REQ_BITRATE=`echo "$REQ_BITRATE * 1000.0" | bc -l`
+                    fi
+                    if [[ $REQ_BITRATE =~ .*M.* ]]
+                    then
+                        REQ_BITRATE=`echo $REQ_BITRATE | sed -e "s#M##"`
+                        FLOAT_REQ_BITRATE=`echo "$REQ_BITRATE * 1000000.0" | bc -l`
+                    fi
+                    if [[ $REQ_BITRATE =~ .*G.* ]]
+                    then
+                        REQ_BITRATE=`echo $REQ_BITRATE | sed -e "s#G##"`
+                        FLOAT_REQ_BITRATE=`echo "$REQ_BITRATE * 1000000000.0" | bc -l`
+                    fi
+                    FILE_COMPLETE=`egrep -c "Server Report" $IPERF_CASE`
+                    if [ $FILE_COMPLETE -eq 0 ]
                     then
-                        echo "        <td bgcolor = \"green\" >OK</td>" >> ./test_simulator_results.html
-                    else
                         echo "        <td bgcolor = \"red\" >KO</td>" >> ./test_simulator_results.html
+                        SERVER_FILE=`echo $IPERF_CASE | sed -e "s#client#server#"`
+                        FLOAT_EFF_BITRATE=`grep --color=never sec $SERVER_FILE | sed -e "s#^.*Bytes *##" -e "s#sec *.*#sec#" | awk 'BEGIN{s=0;n=0}{n++;if ($2 ~/Mbits/){a = $1 * 1000000};if ($2 ~/Kbits/){a = $1 * 1000};s=s+a}END{br=s/n; printf "%.0f", br}'`
+                        EFFECTIVE_BITRATE=`grep --color=never sec $SERVER_FILE | sed -e "s#^.*Bytes *##" -e "s#sec *.*#sec#" | awk 'BEGIN{s=0;n=0}{n++;if ($2 ~/Mbits/){a = $1 * 1000000};if ($2 ~/Kbits/){a = $1 * 1000};s=s+a}END{br=s/n; if(br>1000000){printf "%.2f MBits/sec", br/1000000}}'`
+                        PERF=`echo "100 * $FLOAT_EFF_BITRATE / $FLOAT_REQ_BITRATE" | bc -l | awk '{printf "%.2f", $0}'`
+                        JITTER=`grep --color=never sec $SERVER_FILE | sed -e "s#^.*/sec *##" -e "s# *ms.*##" | awk 'BEGIN{s=0;n=0}{n++;s+=$1}END{jitter=s/n; printf "%.3f ms", jitter}'`
+                        PACKETLOSS_NOSIGN=`grep --color=never sec $SERVER_FILE | sed -e "s#^.*(##" -e "s#%.*##" | awk 'BEGIN{s=0;n=0}{n++;s+=$1}END{per=s/n; printf "%.1f", per}'`
+                        PACKETLOSS=`echo "${PACKETLOSS_NOSIGN}%"`
+                    else
+                        EFFECTIVE_BITRATE=`tail -n3 $IPERF_CASE | egrep "Mbits/sec" | sed -e "s#^.*MBytes *##" -e "s#sec.*#sec#"`
+                        if [[ $EFFECTIVE_BITRATE =~ .*Kbits/sec.* ]]
+                        then
+                            EFFECTIVE_BITRATE=`echo $EFFECTIVE_BITRATE | sed -e "s# *Kbits/sec.*##"`
+                            FLOAT_EFF_BITRATE=`echo "$EFFECTIVE_BITRATE * 1000" | bc -l`
+                        fi
+                        if [[ $EFFECTIVE_BITRATE =~ .*Mbits/sec.* ]]
+                        then
+                            EFFECTIVE_BITRATE=`echo $EFFECTIVE_BITRATE | sed -e "s# *Mbits/sec.*##"`
+                            FLOAT_EFF_BITRATE=`echo "$EFFECTIVE_BITRATE * 1000000" | bc -l`
+                        fi
+                        if [[ $EFFECTIVE_BITRATE =~ .*Gbits/sec.* ]]
+                        then
+                            EFFECTIVE_BITRATE=`echo $EFFECTIVE_BITRATE | sed -e "s# *Gbits/sec.*##"`
+                            FLOAT_EFF_BITRATE=`echo "$EFFECTIVE_BITRATE * 1000000000" | bc -l`
+                        fi
+                        PERF=`echo "100 * $FLOAT_EFF_BITRATE / $FLOAT_REQ_BITRATE" | bc -l | awk '{printf "%.2f", $0}'`
+                        PERF_INT=`echo "100 * $FLOAT_EFF_BITRATE / $FLOAT_REQ_BITRATE" | bc -l | awk '{printf "%.0f", $0}'`
+                        if [[ $PERF_INT -lt 90 ]]
+                        then
+                            echo "        <td bgcolor = \"red\" >KO</td>" >> ./test_simulator_results.html
+                        else
+                            echo "        <td bgcolor = \"green\" >OK</td>" >> ./test_simulator_results.html
+                        fi
+                        EFFECTIVE_BITRATE=`tail -n3 $IPERF_CASE | egrep "Mbits/sec" | sed -e "s#^.*MBytes *##" -e "s#sec.*#sec#"`
+                        JITTER=`tail -n3 $IPERF_CASE | egrep "Mbits/sec" | sed -e "s#^.*Mbits/sec *##" -e "s#ms.*#ms#"`
+                        PACKETLOSS=`tail -n3 $IPERF_CASE | egrep "Mbits/sec" | sed -e "s#^.*(##" -e "s#).*##"`
                     fi
                     echo "        <td>" >> ./test_simulator_results.html
                     echo "            <pre>" >> ./test_simulator_results.html
-                    STATS=`egrep "packets transmitted" $PING_CASE | sed -e "s#^.*received, ##" -e "s#, time.*##" -e "s# packet loss##"`
-                    echo "Packet Loss : $STATS" >> ./test_simulator_results.html
-                    RTTMIN=`egrep "rtt min" $PING_CASE | awk '{split($4,a,"/"); print a[1] " " $5}'`
-                    echo "RTT Minimal : $RTTMIN" >> ./test_simulator_results.html
-                    RTTAVG=`egrep "rtt min" $PING_CASE | awk '{split($4,a,"/"); print a[2] " " $5}'`
-                    echo "RTT Average : $RTTAVG" >> ./test_simulator_results.html
-                    RTTMAX=`egrep "rtt min" $PING_CASE | awk '{split($4,a,"/"); print a[3] " " $5}'`
-                    echo "RTT Maximal : $RTTMAX" >> ./test_simulator_results.html
+                    echo "Bitrate      : $EFFECTIVE_BITRATE" >> ./test_simulator_results.html
+                    echo "Bitrate Perf : $PERF %" >> ./test_simulator_results.html
+                    echo "Jitter       : $JITTER" >> ./test_simulator_results.html
+                    echo "Packet Loss  : $PACKETLOSS" >> ./test_simulator_results.html
                     echo "            </pre>" >> ./test_simulator_results.html
                     echo "        </td>" >> ./test_simulator_results.html
-                fi
-                echo "      </tr>" >> ./test_simulator_results.html
-            fi
+                    echo "      </tr>" >> ./test_simulator_results.html
+                done
+            done
+        done
 
-            if [ -f $ARCHIVES_LOC/${TMODE}_${BW}*iperf*dl*client*txt ]
+        echo "   </table>" >> ./test_simulator_results.html
+        echo "   </div>" >> ./test_simulator_results.html
+    fi
+
+    if [ -e $JENKINS_WKSP/flexran/flexran_build_complete.txt ]
+    then
+        echo "   <h3>Basic Simulator + FlexRan Controller Check</h3>" >> ./test_simulator_results.html
+        echo "   <div class=\"alert alert-success\">" >> ./test_simulator_results.html
+        echo "      <strong>TEST was SUCCESSFUL <span class=\"glyphicon glyphicon-ok-circle\"></span></strong>" >> ./test_simulator_results.html
+        echo "   </div>" >> ./test_simulator_results.html
+        echo "   <button data-toggle=\"collapse\" data-target=\"#oai-flexran-test-details\">More details on Basic Simulator + Fleran Controller test results</button>" >> ./test_simulator_results.html
+        echo "   <div id=\"oai-flexran-test-details\" class=\"collapse\">" >> ./test_simulator_results.html
+        echo "   <table border = \"1\">" >> ./test_simulator_results.html
+        echo "      <tr bgcolor = \"#33CCFF\" >" >> ./test_simulator_results.html
+        echo "        <th>Log File Name</th>" >> ./test_simulator_results.html
+        echo "        <th>JSON Query Response</th>" >> ./test_simulator_results.html
+        echo "      </tr>" >> ./test_simulator_results.html
+
+        FLEXRAN_QUERIES=`ls $ARCHIVES_LOC/flexran_ctl_query_*log`
+        for QUERY in $FLEXRAN_QUERIES
+        do
+            echo "      <tr>" >> ./test_simulator_results.html
+            NAME=`echo $QUERY | sed -e "s#$ARCHIVES_LOC/##"`
+            echo "        <td>$NAME</td>" >> ./test_simulator_results.html
+            echo "        <td><pre><code>" >> ./test_simulator_results.html
+            egrep -v "LOG_NAME|\-\-\-\-\-" $QUERY >> ./test_simulator_results.html
+            echo "        </code></pre></td>" >> ./test_simulator_results.html
+            echo "      </tr>" >> ./test_simulator_results.html
+        done
+        echo "   </table>" >> ./test_simulator_results.html
+        echo "   </div>" >> ./test_simulator_results.html
+    fi
+
+    ARCHIVES_LOC=archives/l2_sim/test
+    if [ -d $ARCHIVES_LOC ]
+    then
+        echo "   <h3>L2-NFAPI Simulator Check</h3>" >> ./test_simulator_results.html
+
+        if [ -f $ARCHIVES_LOC/test_final_status.log ]
+        then
+            if [ `grep -c TEST_OK $ARCHIVES_LOC/test_final_status.log` -eq 1 ]
             then
-                IPERF_TESTS=`ls $ARCHIVES_LOC/${TMODE}_${BW}*iperf*client*txt`
+                echo "   <div class=\"alert alert-success\">" >> ./test_simulator_results.html
+                echo "      <strong>TEST was SUCCESSFUL <span class=\"glyphicon glyphicon-ok-circle\"></span></strong>" >> ./test_simulator_results.html
+                echo "   </div>" >> ./test_simulator_results.html
             else
-                echo "There are no iperf files"
-                IPERF_TESTS=""
+                echo "   <div class=\"alert alert-danger\">" >> ./test_simulator_results.html
+                echo "      <strong>TEST was a FAILURE! <span class=\"glyphicon glyphicon-ban-circle\"></span></strong>" >> ./test_simulator_results.html
+                echo "   </div>" >> ./test_simulator_results.html
             fi
-            for IPERF_CASE in $IPERF_TESTS
+        else
+            echo "   <div class=\"alert alert-danger\">" >> ./test_simulator_results.html
+            echo "      <strong>COULD NOT DETERMINE TEST FINAL STATUS! <span class=\"glyphicon glyphicon-ban-circle\"></span></strong>" >> ./test_simulator_results.html
+            echo "   </div>" >> ./test_simulator_results.html
+        fi
+
+        echo "   <button data-toggle=\"collapse\" data-target=\"#oai-l2-sim-test-details\">More details on L2-NFAPI Simulator test results</button>" >> ./test_simulator_results.html
+        echo "   <div id=\"oai-l2-sim-test-details\" class=\"collapse\">" >> ./test_simulator_results.html
+        echo "   <table border = \"1\">" >> ./test_simulator_results.html
+        echo "      <tr bgcolor = \"#33CCFF\" >" >> ./test_simulator_results.html
+        echo "        <th>Log File Name</th>" >> ./test_simulator_results.html
+        echo "        <th>Command</th>" >> ./test_simulator_results.html
+        echo "        <th>Status</th>" >> ./test_simulator_results.html
+        echo "        <th>Statistics</th>" >> ./test_simulator_results.html
+        echo "      </tr>" >> ./test_simulator_results.html
+
+        TRANS_MODES=("fdd")
+        BW_CASES=(05)
+        for TMODE in ${TRANS_MODES[@]}
+        do
+            for BW in ${BW_CASES[@]}
             do
-                echo "      <tr>" >> ./test_simulator_results.html
-                NAME=`echo $IPERF_CASE | sed -e "s#$ARCHIVES_LOC/##"`
-                echo "        <td>$NAME</td>" >> ./test_simulator_results.html
-                CMD=`egrep "COMMAND IS" $IPERF_CASE | sed -e "s#COMMAND IS: ##"`
-                echo "        <td>$CMD</td>" >> ./test_simulator_results.html
-                REQ_BITRATE=`echo $CMD | sed -e "s#^.*-b ##" -e "s#-i 1.*##"`
-                if [[ $REQ_BITRATE =~ .*K.* ]]
-                then
-                    REQ_BITRATE=`echo $REQ_BITRATE | sed -e "s#K##"`
-                    FLOAT_REQ_BITRATE=`echo "$REQ_BITRATE * 1000.0" | bc -l`
-                fi
-                if [[ $REQ_BITRATE =~ .*M.* ]]
-                then
-                    REQ_BITRATE=`echo $REQ_BITRATE | sed -e "s#M##"`
-                    FLOAT_REQ_BITRATE=`echo "$REQ_BITRATE * 1000000.0" | bc -l`
-                fi
-                if [[ $REQ_BITRATE =~ .*G.* ]]
-                then
-                    REQ_BITRATE=`echo $REQ_BITRATE | sed -e "s#G##"`
-                    FLOAT_REQ_BITRATE=`echo "$REQ_BITRATE * 1000000000.0" | bc -l`
-                fi
-                FILE_COMPLETE=`egrep -c "Server Report" $IPERF_CASE`
-                if [ $FILE_COMPLETE -eq 0 ]
+                ENB_LOG=$ARCHIVES_LOC/${TMODE}_${BW}MHz_enb.log
+                UE_LOG=`echo $ENB_LOG | sed -e "s#enb#ue#"`
+                if [ -f $ENB_LOG ] && [ -f $UE_LOG ]
                 then
-                    echo "        <td bgcolor = \"red\" >KO</td>" >> ./test_simulator_results.html
-                    SERVER_FILE=`echo $IPERF_CASE | sed -e "s#client#server#"`
-                    FLOAT_EFF_BITRATE=`grep --color=never sec $SERVER_FILE | sed -e "s#^.*Bytes *##" -e "s#sec *.*#sec#" | awk 'BEGIN{s=0;n=0}{n++;if ($2 ~/Mbits/){a = $1 * 1000000};if ($2 ~/Kbits/){a = $1 * 1000};s=s+a}END{br=s/n; printf "%.0f", br}'`
-                    EFFECTIVE_BITRATE=`grep --color=never sec $SERVER_FILE | sed -e "s#^.*Bytes *##" -e "s#sec *.*#sec#" | awk 'BEGIN{s=0;n=0}{n++;if ($2 ~/Mbits/){a = $1 * 1000000};if ($2 ~/Kbits/){a = $1 * 1000};s=s+a}END{br=s/n; if(br>1000000){printf "%.2f MBits/sec", br/1000000}}'`
-                    PERF=`echo "100 * $FLOAT_EFF_BITRATE / $FLOAT_REQ_BITRATE" | bc -l | awk '{printf "%.2f", $0}'`
-                    JITTER=`grep --color=never sec $SERVER_FILE | sed -e "s#^.*/sec *##" -e "s# *ms.*##" | awk 'BEGIN{s=0;n=0}{n++;s+=$1}END{jitter=s/n; printf "%.3f ms", jitter}'`
-                    PACKETLOSS_NOSIGN=`grep --color=never sec $SERVER_FILE | sed -e "s#^.*(##" -e "s#%.*##" | awk 'BEGIN{s=0;n=0}{n++;s+=$1}END{per=s/n; printf "%.1f", per}'`
-                    PACKETLOSS=`echo "${PACKETLOSS_NOSIGN}%"`
-                else
-                    EFFECTIVE_BITRATE=`tail -n3 $IPERF_CASE | egrep "Mbits/sec" | sed -e "s#^.*MBytes *##" -e "s#sec.*#sec#"`
-                    if [[ $EFFECTIVE_BITRATE =~ .*Kbits/sec.* ]]
+                    NAME_ENB=`echo $ENB_LOG | sed -e "s#$ARCHIVES_LOC/##"`
+                    NAME_UE=`echo $UE_LOG | sed -e "s#$ARCHIVES_LOC/##"`
+                    echo "      <tr>" >> ./test_simulator_results.html
+                    echo "        <td>$NAME_ENB --- $NAME_UE</td>" >> ./test_simulator_results.html
+                    echo "        <td>N/A</td>" >> ./test_simulator_results.html
+                    NB_ENB_GOT_SYNC=`egrep -c "got sync" $ENB_LOG`
+                    NB_UE_GOT_SYNC=`egrep -c "got sync" $UE_LOG`
+                    NB_ENB_SYNCED_WITH_UE=`egrep -c "Sending NFAPI_START_RESPONSE" $UE_LOG`
+                    if [ $NB_ENB_GOT_SYNC -eq 1 ] && [ $NB_UE_GOT_SYNC -eq 3 ] && [ $NB_ENB_SYNCED_WITH_UE -eq 1 ]
                     then
-                        EFFECTIVE_BITRATE=`echo $EFFECTIVE_BITRATE | sed -e "s# *Kbits/sec.*##"`
-                        FLOAT_EFF_BITRATE=`echo "$EFFECTIVE_BITRATE * 1000" | bc -l`
+                        echo "        <td bgcolor = \"green\" >OK</td>" >> ./test_simulator_results.html
+                    else
+                        echo "        <td bgcolor = \"red\" >KO</td>" >> ./test_simulator_results.html
                     fi
-                    if [[ $EFFECTIVE_BITRATE =~ .*Mbits/sec.* ]]
+                    echo "        <td><pre>" >> ./test_simulator_results.html
+                    if [ $NB_ENB_GOT_SYNC -eq 1 ]
                     then
-                        EFFECTIVE_BITRATE=`echo $EFFECTIVE_BITRATE | sed -e "s# *Mbits/sec.*##"`
-                        FLOAT_EFF_BITRATE=`echo "$EFFECTIVE_BITRATE * 1000000" | bc -l`
+                        echo "<font color = \"blue\">- eNB --> got sync</font>" >> ./test_simulator_results.html
+                    else
+                        echo "<font color = \"red\"><b>- eNB NEVER got sync</b></font>" >> ./test_simulator_results.html
                     fi
-                    if [[ $EFFECTIVE_BITRATE =~ .*Gbits/sec.* ]]
+                    if [ $NB_UE_GOT_SYNC -eq 3 ]
                     then
-                        EFFECTIVE_BITRATE=`echo $EFFECTIVE_BITRATE | sed -e "s# *Gbits/sec.*##"`
-                        FLOAT_EFF_BITRATE=`echo "$EFFECTIVE_BITRATE * 1000000000" | bc -l`
+                        echo "<font color = \"blue\">- UE --> got sync</font>" >> ./test_simulator_results.html
+                    else
+                        echo "<font color = \"red\"><b>- UE NEVER got sync</b></font>" >> ./test_simulator_results.html
                     fi
-                    PERF=`echo "100 * $FLOAT_EFF_BITRATE / $FLOAT_REQ_BITRATE" | bc -l | awk '{printf "%.2f", $0}'`
-                    PERF_INT=`echo "100 * $FLOAT_EFF_BITRATE / $FLOAT_REQ_BITRATE" | bc -l | awk '{printf "%.0f", $0}'`
-                    if [[ $PERF_INT -lt 90 ]]
+                    if [ $NB_ENB_SYNCED_WITH_UE -eq 1 ]
+                    then
+                        echo "<font color = \"blue\">- UE attached to eNB</font>" >> ./test_simulator_results.html
+                    else
+                        echo "<font color = \"red\"><b>- UE NEVER attached to eNB</b></font>" >> ./test_simulator_results.html
+                    fi
+                    echo "        </pre></td>" >> ./test_simulator_results.html
+                    echo "      </tr>" >> ./test_simulator_results.html
+                fi
+                PING_CASE=$ARCHIVES_LOC/${TMODE}_${BW}MHz_ping_epc.txt
+                if [ -f $PING_CASE ]
+                then
+                    echo "      <tr>" >> ./test_simulator_results.html
+                    NAME=`echo $PING_CASE | sed -e "s#$ARCHIVES_LOC/##"`
+                    echo "        <td>$NAME</td>" >> ./test_simulator_results.html
+                    CMD=`egrep "COMMAND IS" $PING_CASE | sed -e "s#COMMAND IS: ##"`
+                    echo "        <td>$CMD</td>" >> ./test_simulator_results.html
+                    FILE_COMPLETE=`egrep -c "ping statistics" $PING_CASE`
+                    if [ $FILE_COMPLETE -eq 0 ]
                     then
                         echo "        <td bgcolor = \"red\" >KO</td>" >> ./test_simulator_results.html
+                        echo "        <td>N/A</td>" >> ./test_simulator_results.html
                     else
-                        echo "        <td bgcolor = \"green\" >OK</td>" >> ./test_simulator_results.html
+                        NB_TR_PACKETS=`egrep "packets transmitted" $PING_CASE | sed -e "s# packets transmitted.*##"`
+                        NB_RC_PACKETS=`egrep "packets transmitted" $PING_CASE | sed -e "s#^.*packets transmitted, ##" -e "s# received,.*##"`
+                        if [ $NB_TR_PACKETS -eq $NB_RC_PACKETS ]
+                        then
+                            echo "        <td bgcolor = \"green\" >OK</td>" >> ./test_simulator_results.html
+                        else
+                            echo "        <td bgcolor = \"red\" >KO</td>" >> ./test_simulator_results.html
+                        fi
+                        echo "        <td>" >> ./test_simulator_results.html
+                        echo "            <pre>" >> ./test_simulator_results.html
+                        STATS=`egrep "packets transmitted" $PING_CASE | sed -e "s#^.*received, ##" -e "s#, time.*##" -e "s# packet loss##"`
+                        echo "Packet Loss : $STATS" >> ./test_simulator_results.html
+                        RTTMIN=`egrep "rtt min" $PING_CASE | awk '{split($4,a,"/"); print a[1] " " $5}'`
+                        echo "RTT Minimal : $RTTMIN" >> ./test_simulator_results.html
+                        RTTAVG=`egrep "rtt min" $PING_CASE | awk '{split($4,a,"/"); print a[2] " " $5}'`
+                        echo "RTT Average : $RTTAVG" >> ./test_simulator_results.html
+                        RTTMAX=`egrep "rtt min" $PING_CASE | awk '{split($4,a,"/"); print a[3] " " $5}'`
+                        echo "RTT Maximal : $RTTMAX" >> ./test_simulator_results.html
+                        echo "            </pre>" >> ./test_simulator_results.html
+                        echo "        </td>" >> ./test_simulator_results.html
                     fi
-                    EFFECTIVE_BITRATE=`tail -n3 $IPERF_CASE | egrep "Mbits/sec" | sed -e "s#^.*MBytes *##" -e "s#sec.*#sec#"`
-                    JITTER=`tail -n3 $IPERF_CASE | egrep "Mbits/sec" | sed -e "s#^.*Mbits/sec *##" -e "s#ms.*#ms#"`
-                    PACKETLOSS=`tail -n3 $IPERF_CASE | egrep "Mbits/sec" | sed -e "s#^.*(##" -e "s#).*##"`
+                    echo "      </tr>" >> ./test_simulator_results.html
                 fi
-                echo "        <td>" >> ./test_simulator_results.html
-                echo "            <pre>" >> ./test_simulator_results.html
-                echo "Bitrate      : $EFFECTIVE_BITRATE" >> ./test_simulator_results.html
-                echo "Bitrate Perf : $PERF %" >> ./test_simulator_results.html
-                echo "Jitter       : $JITTER" >> ./test_simulator_results.html
-                echo "Packet Loss  : $PACKETLOSS" >> ./test_simulator_results.html
-                echo "            </pre>" >> ./test_simulator_results.html
-                echo "        </td>" >> ./test_simulator_results.html
-                echo "      </tr>" >> ./test_simulator_results.html
+
             done
         done
-    done
-
-    echo "   </table>" >> ./test_simulator_results.html
-fi
 
-ARCHIVES_LOC=archives/phy_sim/test
-if [ -d $ARCHIVES_LOC ]
-then
-    echo "   <h3>Physical Simulators Check</h3>" >> ./test_simulator_results.html
+        echo "   </table>" >> ./test_simulator_results.html
+        echo "   </div>" >> ./test_simulator_results.html
+    fi
 
-    echo "   <table border = \"1\">" >> ./test_simulator_results.html
-    echo "      <tr bgcolor = \"#33CCFF\" >" >> ./test_simulator_results.html
-    echo "        <th>Log File Name</th>" >> ./test_simulator_results.html
-    echo "        <th>Nb Tests</th>" >> ./test_simulator_results.html
-    echo "        <th>Nb Errors</th>" >> ./test_simulator_results.html
-    echo "        <th>Nb Failures</th>" >> ./test_simulator_results.html
-    echo "        <th>Nb Failures</th>" >> ./test_simulator_results.html
-    echo "      </tr>" >> ./test_simulator_results.html
+    ARCHIVES_LOC=archives/phy_sim/test
+    if [ -d $ARCHIVES_LOC ]
+    then
+        echo "   <h3>Physical Simulators Check</h3>" >> ./test_simulator_results.html
 
-    XML_TESTS=`ls $ARCHIVES_LOC/*xml`
-    for XML_FILE in $XML_TESTS
-    do
-        echo "      <tr>" >> ./test_simulator_results.html
-        NAME=`echo $XML_FILE | sed -e "s#$ARCHIVES_LOC/##"`
-        NB_TESTS=`egrep "testsuite errors" $XML_FILE | sed -e "s#^.*tests='##" -e "s#' *time=.*##"`
-        NB_ERRORS=`egrep "testsuite errors" $XML_FILE | sed -e "s#^.*errors='##" -e "s#' *failures=.*##"`
-        NB_FAILURES=`egrep "testsuite errors" $XML_FILE | sed -e "s#^.*failures='##" -e "s#' *hostname=.*##"`
-        NB_SKIPPED=`egrep "testsuite errors" $XML_FILE | sed -e "s#^.*skipped='##" -e "s#' *tests=.*##"`
-        if [ $NB_ERRORS -eq 0 ] && [ $NB_FAILURES -eq 0 ]
+        if [ -f $ARCHIVES_LOC/test_final_status.log ]
         then
-            echo "        <td bgcolor = \"green\" >$NAME</td>" >> ./test_simulator_results.html
+            if [ `grep -c TEST_OK $ARCHIVES_LOC/test_final_status.log` -eq 1 ]
+            then
+                echo "   <div class=\"alert alert-success\">" >> ./test_simulator_results.html
+                echo "      <strong>TEST was SUCCESSFUL <span class=\"glyphicon glyphicon-ok-circle\"></span></strong>" >> ./test_simulator_results.html
+                echo "   </div>" >> ./test_simulator_results.html
+            else
+                echo "   <div class=\"alert alert-danger\">" >> ./test_simulator_results.html
+                echo "      <strong>TEST was a FAILURE! <span class=\"glyphicon glyphicon-ban-circle\"></span></strong>" >> ./test_simulator_results.html
+                echo "   </div>" >> ./test_simulator_results.html
+            fi
         else
-            echo "        <td bgcolor = \"red\" >$NAME</td>" >> ./test_simulator_results.html
+            echo "   <div class=\"alert alert-danger\">" >> ./test_simulator_results.html
+            echo "      <strong>COULD NOT DETERMINE TEST FINAL STATUS! <span class=\"glyphicon glyphicon-ban-circle\"></span></strong>" >> ./test_simulator_results.html
+            echo "   </div>" >> ./test_simulator_results.html
         fi
-        echo "        <td>$NB_TESTS</td>" >> ./test_simulator_results.html
-        echo "        <td>$NB_ERRORS</td>" >> ./test_simulator_results.html
-        echo "        <td>$NB_FAILURES</td>" >> ./test_simulator_results.html
-        echo "        <td>$NB_SKIPPED</td>" >> ./test_simulator_results.html
-        echo "      </tr>" >> ./test_simulator_results.html
-    done
 
-    echo "   </table>" >> ./test_simulator_results.html
-
-    echo "   <h4>Details</h4>" >> ./test_simulator_results.html
-    for XML_FILE in $XML_TESTS
-    do
         echo "   <table border = \"1\">" >> ./test_simulator_results.html
         echo "      <tr bgcolor = \"#33CCFF\" >" >> ./test_simulator_results.html
-        echo "        <th>Test Name</th>" >> ./test_simulator_results.html
-        echo "        <th>Description</th>" >> ./test_simulator_results.html
-        echo "        <th>Result</th>" >> ./test_simulator_results.html
-        echo "        <th>Time</th>" >> ./test_simulator_results.html
+        echo "        <th>Log File Name</th>" >> ./test_simulator_results.html
+        echo "        <th>Nb Tests</th>" >> ./test_simulator_results.html
+        echo "        <th>Nb Errors</th>" >> ./test_simulator_results.html
+        echo "        <th>Nb Failures</th>" >> ./test_simulator_results.html
+        echo "        <th>Nb Failures</th>" >> ./test_simulator_results.html
         echo "      </tr>" >> ./test_simulator_results.html
-        TESTCASES_LIST=`sed -e "s# #@#g" $XML_FILE | grep testcase`
-        for TESTCASE in $TESTCASES_LIST
+
+        XML_TESTS=`ls $ARCHIVES_LOC/*xml`
+        for XML_FILE in $XML_TESTS
         do
             echo "      <tr>" >> ./test_simulator_results.html
-            NAME=`echo $TESTCASE | sed -e "s#^.*name='##" -e "s#'@description=.*##" | sed -e "s#@# #g"`
-            echo "          <td>$NAME</td>" >> ./test_simulator_results.html
-            DESC=`echo $TESTCASE | sed -e "s#^.*description='##" -e "s#'@Run_result=.*##" | sed -e "s#@# #g"`
-            echo "          <td>$DESC</td>" >> ./test_simulator_results.html
-            RESULT=`echo $TESTCASE | sed -e "s#^.*RESULT='##" -e "s#'.*##" | sed -e "s#@# #g"`
-            if [[ $RESULT =~ .*PASS.* ]]
+            NAME=`echo $XML_FILE | sed -e "s#$ARCHIVES_LOC/##"`
+            NB_TESTS=`egrep "testsuite errors" $XML_FILE | sed -e "s#^.*tests='##" -e "s#' *time=.*##"`
+            NB_ERRORS=`egrep "testsuite errors" $XML_FILE | sed -e "s#^.*errors='##" -e "s#' *failures=.*##"`
+            NB_FAILURES=`egrep "testsuite errors" $XML_FILE | sed -e "s#^.*failures='##" -e "s#' *hostname=.*##"`
+            NB_SKIPPED=`egrep "testsuite errors" $XML_FILE | sed -e "s#^.*skipped='##" -e "s#' *tests=.*##"`
+            if [ $NB_ERRORS -eq 0 ] && [ $NB_FAILURES -eq 0 ]
             then
-                echo "          <td bgcolor = \"green\" >$RESULT</td>" >> ./test_simulator_results.html
+                echo "        <td bgcolor = \"green\" >$NAME</td>" >> ./test_simulator_results.html
             else
-                echo "          <td bgcolor = \"red\" >$RESULT</td>" >> ./test_simulator_results.html
+                echo "        <td bgcolor = \"red\" >$NAME</td>" >> ./test_simulator_results.html
             fi
-            TIME=`echo $TESTCASE | sed -e "s#^.*time='##" -e "s#'@RESULT=.*##" | sed -e "s#@# #g"`
-            echo "          <td>$TIME</td>" >> ./test_simulator_results.html
+            echo "        <td>$NB_TESTS</td>" >> ./test_simulator_results.html
+            echo "        <td>$NB_ERRORS</td>" >> ./test_simulator_results.html
+            echo "        <td>$NB_FAILURES</td>" >> ./test_simulator_results.html
+            echo "        <td>$NB_SKIPPED</td>" >> ./test_simulator_results.html
             echo "      </tr>" >> ./test_simulator_results.html
         done
+
         echo "   </table>" >> ./test_simulator_results.html
-    done
-fi
+        echo "   <br>" >> ./test_simulator_results.html
+
+        echo "   <button data-toggle=\"collapse\" data-target=\"#oai-phy-sim-test-details\">More details on Physical Simulators test results</button>" >> ./test_simulator_results.html
+        echo "   <div id=\"oai-phy-sim-test-details\" class=\"collapse\">" >> ./test_simulator_results.html
 
-echo "</body>" >> ./test_simulator_results.html
-echo "</html>" >> ./test_simulator_results.html
+        echo "   <h4>Details</h4>" >> ./test_simulator_results.html
+        for XML_FILE in $XML_TESTS
+        do
+            echo "   <table border = \"1\">" >> ./test_simulator_results.html
+            echo "      <tr bgcolor = \"#33CCFF\" >" >> ./test_simulator_results.html
+            echo "        <th>Test Name</th>" >> ./test_simulator_results.html
+            echo "        <th>Description</th>" >> ./test_simulator_results.html
+            echo "        <th>Result</th>" >> ./test_simulator_results.html
+            echo "        <th>Time</th>" >> ./test_simulator_results.html
+            echo "      </tr>" >> ./test_simulator_results.html
+            PREV_SECTION=0
+            PREV_TIME_IN_SECS=0
+            TESTCASES_LIST=`sed -e "s# #@#g" $XML_FILE | grep testcase`
+            for TESTCASE in $TESTCASES_LIST
+            do
+                NAME=`echo $TESTCASE | sed -e "s#^.*name='##" -e "s#'@description=.*##" | sed -e "s#@# #g"`
+                SECTION=`echo $NAME | sed -e "s#\..*##"`
+                if [ $SECTION != $PREV_SECTION ]
+                then
+                    echo "      <tr bgcolor = \"#8FBC8F\" >" >> ./test_simulator_results.html
+                    echo "          <td align = \"center\" colspan = 4 >\"$SECTION\" series</td>" >> ./test_simulator_results.html
+                    echo "      </tr>" >> ./test_simulator_results.html
+                    PREV_SECTION=$SECTION
+                    PREV_TIME_IN_SECS=0
+                fi
+                DESC=`echo $TESTCASE | sed -e "s#^.*description='##" -e "s#'@Run_result=.*##" | sed -e "s#@# #g"`
+                RESULT=`echo $TESTCASE | sed -e "s#^.*RESULT='##" -e "s#'.*##" | sed -e "s#@# #g"`
+                TIME_IN_SECS=`echo $TESTCASE | sed -e "s#^.*time='##" -e "s#'@RESULT=.*##" | sed -e "s#@# #g" -e "s# s.*##"`
+                TIME=`echo "$TIME_IN_SECS - $PREV_TIME_IN_SECS" | bc -l | awk '{printf "%.2f s", $0}'`
+                PREV_TIME_IN_SECS=$TIME_IN_SECS
+                echo "      <tr>" >> ./test_simulator_results.html
+                echo "          <td>$NAME</td>" >> ./test_simulator_results.html
+                echo "          <td>$DESC</td>" >> ./test_simulator_results.html
+                if [[ $RESULT =~ .*PASS.* ]]
+                then
+                    echo "          <td bgcolor = \"green\" >$RESULT</td>" >> ./test_simulator_results.html
+                else
+                    SPLITTED_LINE=`echo -e $TESTCASE | sed -e "s#@#\n#g"`
+                    NB_RUNS=`echo -e "${SPLITTED_LINE}" | grep -v Run_result | egrep -c "Run_"`
+                    NB_FAILS=`echo -e "${SPLITTED_LINE}" | grep -v Run_result | egrep -c "=FAIL"`
+                    echo "          <td bgcolor = \"red\" >${RESULT} (${NB_FAILS}/${NB_RUNS})</td>" >> ./test_simulator_results.html
+                fi
+                echo "          <td>$TIME</td>" >> ./test_simulator_results.html
+                echo "      </tr>" >> ./test_simulator_results.html
+            done
+            echo "   </table>" >> ./test_simulator_results.html
+        done
+    fi
 
-exit 0
+    echo "   </div>" >> ./test_simulator_results.html
+    echo "   <p></p>" >> ./test_simulator_results.html
+    echo "   <div class=\"well well-lg\">End of Test Report -- Copyright <span class=\"glyphicon glyphicon-copyright-mark\"></span> 2018 <a href=\"http://www.openairinterface.org/\">OpenAirInterface</a>. All Rights Reserved.</div>" >> ./test_simulator_results.html
+    echo "</div></body>" >> ./test_simulator_results.html
+    echo "</html>" >> ./test_simulator_results.html
+}
diff --git a/ci-scripts/runTestOnVM.sh b/ci-scripts/runTestOnVM.sh
index efdfcec3e09ac4572caee49ae28770b8a114a9c9..6f2394e899c68da9d3d4bb20cc128b073a0d889b 100755
--- a/ci-scripts/runTestOnVM.sh
+++ b/ci-scripts/runTestOnVM.sh
@@ -20,15 +20,18 @@
 # *      contact@openairinterface.org
 # */
 
-function usage {
-    echo "OAI VM Test Run script"
+function run_test_usage {
+    echo "OAI CI VM script"
     echo "   Original Author: Raphael Defosseux"
+    echo "   Requirements:"
+    echo "     -- uvtool uvtool-libvirt apt-cacher"
+    echo "     -- xenial image already synced"
     echo "   Default:"
     echo "     -- eNB with USRP"
     echo ""
     echo "Usage:"
     echo "------"
-    echo "    runTestOnVM.sh [OPTIONS]"
+    echo "    oai-ci-vm-tool test [OPTIONS]"
     echo ""
     echo "Options:"
     echo "--------"
@@ -41,12 +44,7 @@ function usage {
     echo "    --workspace #### OR -ws ####"
     echo "    Specify the workspace."
     echo ""
-    echo "    --variant enb-usrp     OR -v1"
-    echo "    --variant basic-sim    OR -v2"
-    echo "    --variant phy-sim      OR -v3"
-    echo "    --variant cppcheck     OR -v4"
-    echo "    --variant enb-ethernet OR -v7"
-    echo "    --variant ue-ethernet  OR -v8"
+    variant_usage
     echo "    Specify the variant to build."
     echo ""
     echo "    --keep-vm-alive OR -k"
@@ -57,25 +55,13 @@ function usage {
     echo ""
 }
 
-function variant_usage {
-    echo "OAI VM Test Run script"
-    echo "   Original Author: Raphael Defosseux"
-    echo ""
-    echo "    --variant enb-usrp     OR -v1"
-    echo "    --variant basic-sim    OR -v2"
-    echo "    --variant phy-sim      OR -v3"
-    echo "    --variant cppcheck     OR -v4"
-    echo "    --variant enb-ethernet OR -v7"
-    echo "    --variant ue-ethernet  OR -v8"
-    echo ""
-}
-
 function start_basic_sim_enb {
     local LOC_VM_IP_ADDR=$2
     local LOC_EPC_IP_ADDR=$3
     local LOC_LOG_FILE=$4
     local LOC_NB_RBS=$5
     local LOC_CONF_FILE=$6
+    local LOC_FLEXRAN_CTL_IP_ADRR=$7
     echo "cd /home/ubuntu/tmp" > $1
     echo "echo \"sudo apt-get --yes --quiet install daemon \"" >> $1
     echo "sudo apt-get --yes install daemon >> /home/ubuntu/tmp/cmake_targets/log/daemon-install.txt 2>&1" >> $1
@@ -86,13 +72,22 @@ function start_basic_sim_enb {
     echo "cd ci-scripts/conf_files/" >> $1
     echo "cp $LOC_CONF_FILE ci-$LOC_CONF_FILE" >> $1
     echo "sed -i -e 's#N_RB_DL.*=.*;#N_RB_DL                                         = $LOC_NB_RBS;#' -e 's#CI_MME_IP_ADDR#$LOC_EPC_IP_ADDR#' -e 's#CI_ENB_IP_ADDR#$LOC_VM_IP_ADDR#' ci-$LOC_CONF_FILE" >> $1
+    if [[ $LOC_FLEXRAN_CTL_IP_ADRR =~ .*none.* ]]
+    then
+        echo "sed -i -e 's#CI_FLEXRAN_CTL_IP_ADDR#127.0.0.1#' ci-$LOC_CONF_FILE" >> $1
+    else
+        echo "sed -i -e 's#FLEXRAN_ENABLED        = .*no.*;#FLEXRAN_ENABLED        = \"yes\";#' -e 's#CI_FLEXRAN_CTL_IP_ADDR#$LOC_FLEXRAN_CTL_IP_ADRR#' ci-$LOC_CONF_FILE" >> $1
+    fi
     echo "echo \"grep N_RB_DL ci-$LOC_CONF_FILE\"" >> $1
     echo "grep N_RB_DL ci-$LOC_CONF_FILE | sed -e 's#N_RB_DL.*=#N_RB_DL =#'" >> $1
     echo "echo \"cd /home/ubuntu/tmp/cmake_targets/basic_simulator/enb/\"" >> $1
+    echo "sudo chmod 777 /home/ubuntu/tmp/cmake_targets/basic_simulator" >> $1
+    echo "sudo chmod 777 /home/ubuntu/tmp/cmake_targets/basic_simulator/enb/" >> $1
     echo "cd /home/ubuntu/tmp/cmake_targets/basic_simulator/enb/" >> $1
     echo "echo \"ulimit -c unlimited && ./lte-softmodem -O /home/ubuntu/tmp/ci-scripts/conf_files/ci-$LOC_CONF_FILE\" > ./my-lte-softmodem-run.sh " >> $1
     echo "chmod 775 ./my-lte-softmodem-run.sh" >> $1
     echo "cat ./my-lte-softmodem-run.sh" >> $1
+    echo "if [ -e /home/ubuntu/tmp/cmake_targets/log/$LOC_LOG_FILE ]; then sudo sudo rm -f /home/ubuntu/tmp/cmake_targets/log/$LOC_LOG_FILE; fi" >> $1
     echo "sudo -E daemon --inherit --unsafe --name=enb_daemon --chdir=/home/ubuntu/tmp/cmake_targets/basic_simulator/enb -o /home/ubuntu/tmp/cmake_targets/log/$LOC_LOG_FILE ./my-lte-softmodem-run.sh" >> $1
 
     ssh -o StrictHostKeyChecking=no ubuntu@$LOC_VM_IP_ADDR < $1
@@ -105,10 +100,12 @@ function start_basic_sim_ue {
     local LOC_NB_RBS=$4
     local LOC_FREQUENCY=$5
     echo "echo \"cd /home/ubuntu/tmp/cmake_targets/basic_simulator/ue\"" > $1
-    echo "cd /home/ubuntu/tmp/cmake_targets/basic_simulator/ue" > $1
+    echo "sudo chmod 777 /home/ubuntu/tmp/cmake_targets/basic_simulator/ue" >> $1
+    echo "cd /home/ubuntu/tmp/cmake_targets/basic_simulator/ue" >> $1
     echo "echo \"./lte-uesoftmodem -C ${LOC_FREQUENCY}000000 -r $LOC_NB_RBS --ue-rxgain 140\" > ./my-lte-uesoftmodem-run.sh" >> $1
     echo "chmod 775 ./my-lte-uesoftmodem-run.sh" >> $1
     echo "cat ./my-lte-uesoftmodem-run.sh" >> $1
+    echo "if [ -e /home/ubuntu/tmp/cmake_targets/log/$LOC_UE_LOG_FILE ]; then sudo sudo rm -f /home/ubuntu/tmp/cmake_targets/log/$LOC_UE_LOG_FILE; fi" >> $1
     echo "sudo -E daemon --inherit --unsafe --name=ue_daemon --chdir=/home/ubuntu/tmp/cmake_targets/basic_simulator/ue -o /home/ubuntu/tmp/cmake_targets/log/$LOC_UE_LOG_FILE ./my-lte-uesoftmodem-run.sh" >> $1
 
     ssh -o StrictHostKeyChecking=no ubuntu@$2 < $1
@@ -151,6 +148,15 @@ function ping_ue_ip_addr {
     rm -f $1
 }
 
+function ping_epc_ip_addr {
+    echo "echo \"COMMAND IS: ping -I oip1 -c 20 $3\" > $4" > $1
+    echo "rm -f $4" >> $1
+    echo "ping -I oip1 -c 20 $3 | tee -a $4" >> $1
+    cat $1
+    ssh -o StrictHostKeyChecking=no ubuntu@$2 < $1
+    rm -f $1
+}
+
 function check_ping_result {
     local LOC_PING_FILE=$1
     local LOC_NB_PINGS=$2
@@ -160,16 +166,19 @@ function check_ping_result {
         if [ $FILE_COMPLETE -eq 0 ]
         then
             PING_STATUS=-1
+            echo "ping file incomplete"
         else
             local ALL_PACKET_RECEIVED=`egrep -c "$LOC_NB_PINGS received" $LOC_PING_FILE`
             if [ $ALL_PACKET_RECEIVED -eq 1 ]
             then
                 echo "got all ping packets"
             else
+                echo "got NOT all ping packets"
                 PING_STATUS=-1
             fi
         fi
     else
+        echo "ping file not present"
         PING_STATUS=-1
     fi
 }
@@ -283,276 +292,10 @@ function recover_core_dump {
     fi
 }
 
-function terminate_ltebox_epc {
-    echo "echo \"cd /opt/ltebox/tools\"" > $1
-    echo "cd /opt/ltebox/tools" >> $1
-    echo "echo \"sudo ./stop_ltebox\"" >> $1
-    echo "sudo ./stop_ltebox" >> $1
-    echo "echo \"sudo daemon --name=simulated_hss --stop\"" >> $1
-    echo "sudo daemon --name=simulated_hss --stop" >> $1
-    echo "echo \"sudo killall --signal SIGKILL hss_sim\"" >> $1
-    echo "sudo killall --signal SIGKILL hss_sim" >> $1
-    ssh -o StrictHostKeyChecking=no ubuntu@$2 < $1
-    rm $1
-}
-
-if [ $# -lt 1 ] || [ $# -gt 9 ]
-then
-    echo "Syntax Error: not the correct number of arguments"
-    echo ""
-    usage
-    exit 1
-fi
-
-VM_TEMPLATE=ci-
-JOB_NAME=XX
-BUILD_ID=XX
-VM_NAME=ci-enb-usrp
-ARCHIVES_LOC=enb_usrp/test
-KEEP_VM_ALIVE=0
-RUN_OPTIONS="none"
-STATUS=0
-
-while [[ $# -gt 0 ]]
-do
-key="$1"
-
-case $key in
-    -h|--help)
-    shift
-    usage
-    exit 0
-    ;;
-    -jn|--job-name)
-    JOB_NAME="$2"
-    shift
-    shift
-    ;;
-    -id|--build-id)
-    BUILD_ID="$2"
-    shift
-    shift
-    ;;
-    -ws|--workspace)
-    JENKINS_WKSP="$2"
-    shift
-    shift
-    ;;
-    -k|--keep-vm-alive)
-    KEEP_VM_ALIVE=1
-    shift
-    ;;
-    -v1)
-    VM_NAME=ci-enb-usrp
-    shift
-    ;;
-    -v2)
-    VM_NAME=ci-basic-sim
-    RUN_OPTIONS="complex"
-    ARCHIVES_LOC=basic_sim/test
-    shift
-    ;;
-    -v3)
-    VM_NAME=ci-phy-sim
-    RUN_OPTIONS="./run_exec_autotests.bash -g \"01510*\" -q -np -b"
-    ARCHIVES_LOC=phy_sim/test
-    shift
-    ;;
-    -v4)
-    VM_NAME=ci-cppcheck
-    shift
-    ;;
-    -v7)
-    VM_NAME=ci-enb-ethernet
-    shift
-    ;;
-    -v8)
-    VM_NAME=ci-ue-ethernet
-    shift
-    ;;
-    --variant)
-    variant="$2"
-    case $variant in
-        enb-usrp)
-        VM_NAME=ci-enb-usrp
-        ;;
-        basic-sim)
-        VM_NAME=ci-basic-sim
-        RUN_OPTIONS="complex"
-        ARCHIVES_LOC=basic_sim/test
-        ;;
-        phy-sim)
-        VM_NAME=ci-phy-sim
-        RUN_OPTIONS="./run_exec_autotests.bash -g \"01510*\" -q -np -b"
-        ARCHIVES_LOC=phy_sim/test
-        ;;
-        cppcheck)
-        VM_NAME=ci-cppcheck
-        ;;
-        enb-ethernet)
-        VM_NAME=ci-enb-ethernet
-        ;;
-        ue-ethernet)
-        VM_NAME=ci-ue-ethernet
-        ;;
-        *)
-        echo ""
-        echo "Syntax Error: Invalid Variant option -> $variant"
-        echo ""
-        variant_usage
-        exit 1
-    esac
-    shift
-    shift
-    ;;
-    *)
-    echo "Syntax Error: unknown option: $key"
-    echo ""
-    usage
-    exit 1
-esac
-done
-
-if [ "$JOB_NAME" == "XX" ] || [ "$BUILD_ID" == "XX" ]
-then
-    VM_TEMPLATE=ci-
-else
-    VM_TEMPLATE=${JOB_NAME}-b${BUILD_ID}-
-fi
-
-VM_NAME=`echo $VM_NAME | sed -e "s#ci-#$VM_TEMPLATE#"`
-VM_CMDS=${VM_NAME}_cmds.txt
-ARCHIVES_LOC=${JENKINS_WKSP}/archives/${ARCHIVES_LOC}
-
-echo "VM_NAME             = $VM_NAME"
-echo "VM_CMD_FILE         = $VM_CMDS"
-echo "JENKINS_WKSP        = $JENKINS_WKSP"
-echo "ARCHIVES_LOC        = $ARCHIVES_LOC"
-
-echo "############################################################"
-echo "Waiting for VM to be started"
-echo "############################################################"
-uvt-kvm wait $VM_NAME --insecure
-
-VM_IP_ADDR=`uvt-kvm ip $VM_NAME`
-echo "$VM_NAME has for IP addr = $VM_IP_ADDR"
-
-if [ "$RUN_OPTIONS" == "none" ]
-then
-    echo "No run on VM testing for this variant currently"
-    exit $STATUS
-fi
-
-if [[ $RUN_OPTIONS =~ .*run_exec_autotests.* ]]
-then
-    echo "############################################################"
-    echo "Running test script on VM ($VM_NAME)"
-    echo "############################################################"
-    echo "echo \"sudo apt-get --yes --quiet install bc \"" > $VM_CMDS
-    echo "sudo apt-get update > bc-install.txt 2>&1" >> $VM_CMDS
-    echo "sudo apt-get --yes install bc >> bc-install.txt 2>&1" >> $VM_CMDS
-    echo "cd tmp" >> $VM_CMDS
-    echo "echo \"source oaienv\"" >> $VM_CMDS
-    echo "source oaienv" >> $VM_CMDS
-    echo "echo \"cd cmake_targets/autotests\"" >> $VM_CMDS
-    echo "cd cmake_targets/autotests" >> $VM_CMDS
-    echo "echo \"rm -Rf log\"" >> $VM_CMDS
-    echo "rm -Rf log" >> $VM_CMDS
-    echo "$RUN_OPTIONS" | sed -e 's@"@\\"@g' -e 's@^@echo "@' -e 's@$@"@' >> $VM_CMDS
-    echo "$RUN_OPTIONS" >> $VM_CMDS
-    echo "cp /home/ubuntu/bc-install.txt log" >> $VM_CMDS
-    echo "cd log" >> $VM_CMDS
-    echo "zip -r -qq tmp.zip *.* 0*" >> $VM_CMDS
-
-    ssh -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR < $VM_CMDS
-
-    echo "############################################################"
-    echo "Creating a tmp folder to store results and artifacts"
-    echo "############################################################"
-
-    if [ -d $ARCHIVES_LOC ]
-    then
-        rm -Rf $ARCHIVES_LOC
-    fi
-    mkdir --parents $ARCHIVES_LOC
-
-    scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/autotests/log/tmp.zip $ARCHIVES_LOC
-    pushd $ARCHIVES_LOC
-    unzip -qq -DD tmp.zip
-    rm tmp.zip
-    if [ -f results_autotests.xml ]
-    then
-        FUNCTION=`echo $VM_NAME | sed -e "s@$VM_TEMPLATE@@"`
-        NEW_NAME=`echo "results_autotests.xml" | sed -e "s@results_autotests@results_autotests-$FUNCTION@"`
-        echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > $NEW_NAME
-        echo "<?xml-stylesheet type=\"text/xsl\" href=\"$FUNCTION.xsl\" ?>" >> $NEW_NAME
-        cat results_autotests.xml >> $NEW_NAME
-        sed -e "s@TEMPLATE@$FUNCTION@" $JENKINS_WKSP/ci-scripts/template.xsl > $FUNCTION.xsl
-        #mv results_autotests.xml $NEW_NAME
-        rm results_autotests.xml
-    fi
-    popd
-
-    if [ $KEEP_VM_ALIVE -eq 0 ]
-    then
-        echo "############################################################"
-        echo "Destroying VM"
-        echo "############################################################"
-        uvt-kvm destroy $VM_NAME
-        ssh-keygen -R $VM_IP_ADDR
-    fi
-    rm -f $VM_CMDS
-
-    echo "############################################################"
-    echo "Checking run status"
-    echo "############################################################"
+function install_epc_on_vm {
+    local LOC_EPC_VM_NAME=$1
+    local LOC_EPC_VM_CMDS=$2
 
-    LOG_FILES=`ls $ARCHIVES_LOC/results_autotests*.xml`
-    NB_FOUND_FILES=0
-    NB_RUNS=0
-    NB_FAILURES=0
-
-    for FULLFILE in $LOG_FILES
-    do
-        TESTSUITES=`egrep "testsuite errors" $FULLFILE`
-        for TESTSUITE in $TESTSUITES
-        do
-            if [[ "$TESTSUITE" == *"tests="* ]]
-            then
-                RUNS=`echo $TESTSUITE | awk 'BEGIN{FS="="}{print $2}END{}' | sed -e "s@'@@g" `
-                NB_RUNS=$((NB_RUNS + RUNS))
-            fi
-            if [[ "$TESTSUITE" == *"failures="* ]]
-            then
-                FAILS=`echo $TESTSUITE | awk 'BEGIN{FS="="}{print $2}END{}' | sed -e "s@'@@g" `
-                NB_FAILURES=$((NB_FAILURES + FAILS))
-            fi
-        done
-        NB_FOUND_FILES=$((NB_FOUND_FILES + 1))
-    done
-
-    echo "NB_FOUND_FILES = $NB_FOUND_FILES"
-    echo "NB_RUNS        = $NB_RUNS"
-    echo "NB_FAILURES    = $NB_FAILURES"
-
-    if [ $NB_FOUND_FILES -eq 0 ]; then STATUS=-1; fi
-    if [ $NB_RUNS -eq 0 ]; then STATUS=-1; fi
-    if [ $NB_FAILURES -ne 0 ]; then STATUS=-1; fi
-
-fi
-
-if [[ "$RUN_OPTIONS" == "complex" ]] && [[ $VM_NAME =~ .*-basic-sim.* ]]
-then
-    PING_STATUS=0
-    IPERF_STATUS=0
-    if [ -d $ARCHIVES_LOC ]
-    then
-        rm -Rf $ARCHIVES_LOC
-    fi
-    mkdir --parents $ARCHIVES_LOC
-
-    EPC_VM_NAME=`echo $VM_NAME | sed -e "s#basic-sim#epc#"`
-    LTEBOX=0
     if [ -d /opt/ltebox-archives/ ]
     then
         # Checking if all ltebox archives are available to run ltebx epc on a brand new VM
@@ -567,28 +310,27 @@ then
     # Here we could have other types of EPC detection
 
     # Do we need to start the EPC VM
-    EPC_VM_CMDS=`echo $VM_CMDS | sed -e "s#cmds#epc-cmds#"`
-    echo "EPC_VM_CMD_FILE     = $EPC_VM_CMDS"
-    IS_EPC_VM_ALIVE=`uvt-kvm list | grep -c $EPC_VM_NAME`
+    echo "EPC_VM_CMD_FILE     = $LOC_EPC_VM_CMDS"
+    IS_EPC_VM_ALIVE=`uvt-kvm list | grep -c $LOC_EPC_VM_NAME`
     if [ $IS_EPC_VM_ALIVE -eq 0 ]
     then
         echo "############################################################"
-        echo "Creating test EPC VM ($EPC_VM_NAME) on Ubuntu Cloud Image base"
+        echo "Creating test EPC VM ($LOC_EPC_VM_NAME) on Ubuntu Cloud Image base"
         echo "############################################################"
-        uvt-kvm create $EPC_VM_NAME release=xenial --unsafe-caching
+        uvt-kvm create $LOC_EPC_VM_NAME release=xenial --unsafe-caching
     fi
 
-    uvt-kvm wait $EPC_VM_NAME --insecure
-    EPC_VM_IP_ADDR=`uvt-kvm ip $EPC_VM_NAME`
-    echo "$EPC_VM_NAME has for IP addr = $EPC_VM_IP_ADDR"
-    scp -o StrictHostKeyChecking=no /etc/apt/apt.conf.d/01proxy ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu
+    uvt-kvm wait $LOC_EPC_VM_NAME --insecure
+    local LOC_EPC_VM_IP_ADDR=`uvt-kvm ip $LOC_EPC_VM_NAME`
+    echo "$LOC_EPC_VM_NAME has for IP addr = $LOC_EPC_VM_IP_ADDR"
+    scp -o StrictHostKeyChecking=no /etc/apt/apt.conf.d/01proxy ubuntu@$LOC_EPC_VM_IP_ADDR:/home/ubuntu
 
     # ltebox specific actions (install and start)
     LTE_BOX_TO_INSTALL=1
     if [ $LTEBOX -eq 1 ]
     then
-        echo "ls -ls /opt/ltebox/tools/start_ltebox" > $EPC_VM_CMDS
-        RESPONSE=`ssh -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR < $EPC_VM_CMDS`
+        echo "ls -ls /opt/ltebox/tools/start_ltebox" > $LOC_EPC_VM_CMDS
+        RESPONSE=`ssh -o StrictHostKeyChecking=no ubuntu@$LOC_EPC_VM_IP_ADDR < $LOC_EPC_VM_CMDS`
         NB_EXES=`echo $RESPONSE | grep -c ltebox`
         if [ $NB_EXES -eq 1 ]; then LTE_BOX_TO_INSTALL=0; fi
     fi
@@ -596,77 +338,76 @@ then
     if [ $LTEBOX -eq 1 ] && [ $LTE_BOX_TO_INSTALL -eq 1 ]
     then
         echo "############################################################"
-        echo "Copying ltebox archives into EPC VM ($EPC_VM_NAME)" 
+        echo "Copying ltebox archives into EPC VM ($LOC_EPC_VM_NAME)"
         echo "############################################################"
-        scp -o StrictHostKeyChecking=no /opt/ltebox-archives/ltebox_2.2.70_16_04_amd64.deb ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu
-        scp -o StrictHostKeyChecking=no /opt/ltebox-archives/etc-conf.zip ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu
-        scp -o StrictHostKeyChecking=no /opt/ltebox-archives/hss-sim.zip ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu
+        scp -o StrictHostKeyChecking=no /opt/ltebox-archives/ltebox_2.2.70_16_04_amd64.deb ubuntu@$LOC_EPC_VM_IP_ADDR:/home/ubuntu
+        scp -o StrictHostKeyChecking=no /opt/ltebox-archives/etc-conf.zip ubuntu@$LOC_EPC_VM_IP_ADDR:/home/ubuntu
+        scp -o StrictHostKeyChecking=no /opt/ltebox-archives/hss-sim.zip ubuntu@$LOC_EPC_VM_IP_ADDR:/home/ubuntu
 
         echo "############################################################"
-        echo "Install EPC on EPC VM ($EPC_VM_NAME)"
+        echo "Install EPC on EPC VM ($LOC_EPC_VM_NAME)"
         echo "############################################################"
-        echo "sudo cp 01proxy /etc/apt/apt.conf.d/" > $EPC_VM_CMDS
-        echo "touch /home/ubuntu/.hushlogin" >> $EPC_VM_CMDS
-        echo "echo \"sudo apt-get --yes --quiet install zip openjdk-8-jre libconfuse-dev libreadline-dev liblog4c-dev libgcrypt-dev libsctp-dev python2.7 python2.7-dev daemon iperf\"" >> $EPC_VM_CMDS
-        echo "sudo apt-get update > zip-install.txt 2>&1" >> $EPC_VM_CMDS
-        echo "sudo apt-get --yes install zip openjdk-8-jre libconfuse-dev libreadline-dev liblog4c-dev libgcrypt-dev libsctp-dev python2.7 python2.7-dev daemon iperf >> zip-install.txt 2>&1" >> $EPC_VM_CMDS
+        echo "sudo cp 01proxy /etc/apt/apt.conf.d/" > $LOC_EPC_VM_CMDS
+        echo "touch /home/ubuntu/.hushlogin" >> $LOC_EPC_VM_CMDS
+        echo "echo \"sudo apt-get --yes --quiet install zip openjdk-8-jre libconfuse-dev libreadline-dev liblog4c-dev libgcrypt-dev libsctp-dev python2.7 python2.7-dev daemon iperf\"" >> $LOC_EPC_VM_CMDS
+        echo "sudo apt-get update > zip-install.txt 2>&1" >> $LOC_EPC_VM_CMDS
+        echo "sudo apt-get --yes install zip openjdk-8-jre libconfuse-dev libreadline-dev liblog4c-dev libgcrypt-dev libsctp-dev python2.7 python2.7-dev daemon iperf >> zip-install.txt 2>&1" >> $LOC_EPC_VM_CMDS
 
         # Installing HSS
-        echo "echo \"cd /opt\"" >> $EPC_VM_CMDS
-        echo "cd /opt" >> $EPC_VM_CMDS
-        echo "echo \"sudo unzip -qq /home/ubuntu/hss-sim.zip\"" >> $EPC_VM_CMDS
-        echo "sudo unzip -qq /home/ubuntu/hss-sim.zip" >> $EPC_VM_CMDS
-        echo "echo \"cd /opt/hss_sim0609\"" >> $EPC_VM_CMDS
-        echo "cd /opt/hss_sim0609" >> $EPC_VM_CMDS
+        echo "echo \"cd /opt\"" >> $LOC_EPC_VM_CMDS
+        echo "cd /opt" >> $LOC_EPC_VM_CMDS
+        echo "echo \"sudo unzip -qq /home/ubuntu/hss-sim.zip\"" >> $LOC_EPC_VM_CMDS
+        echo "sudo unzip -qq /home/ubuntu/hss-sim.zip" >> $LOC_EPC_VM_CMDS
+        echo "echo \"cd /opt/hss_sim0609\"" >> $LOC_EPC_VM_CMDS
+        echo "cd /opt/hss_sim0609" >> $LOC_EPC_VM_CMDS
 
         # Installing ltebox
-        echo "echo \"cd /home/ubuntu\"" >> $EPC_VM_CMDS
-        echo "cd /home/ubuntu" >> $EPC_VM_CMDS
-        echo "echo \"sudo dpkg -i ltebox_2.2.70_16_04_amd64.deb \"" >> $EPC_VM_CMDS
-        echo "sudo dpkg -i ltebox_2.2.70_16_04_amd64.deb >> zip-install.txt 2>&1" >> $EPC_VM_CMDS
-
-        echo "echo \"cd /opt/ltebox/etc/\"" >> $EPC_VM_CMDS
-        echo "cd /opt/ltebox/etc/" >> $EPC_VM_CMDS
-        echo "echo \"sudo unzip -qq -o /home/ubuntu/etc-conf.zip\"" >> $EPC_VM_CMDS
-        echo "sudo unzip -qq -o /home/ubuntu/etc-conf.zip" >> $EPC_VM_CMDS
-        echo "sudo sed -i  -e 's#EPC_VM_IP_ADDRESS#$EPC_VM_IP_ADDR#' gw.conf" >> $EPC_VM_CMDS
-        echo "sudo sed -i  -e 's#EPC_VM_IP_ADDRESS#$EPC_VM_IP_ADDR#' mme.conf" >> $EPC_VM_CMDS
+        echo "echo \"cd /home/ubuntu\"" >> $LOC_EPC_VM_CMDS
+        echo "cd /home/ubuntu" >> $LOC_EPC_VM_CMDS
+        echo "echo \"sudo dpkg -i ltebox_2.2.70_16_04_amd64.deb \"" >> $LOC_EPC_VM_CMDS
+        echo "sudo dpkg -i ltebox_2.2.70_16_04_amd64.deb >> zip-install.txt 2>&1" >> $LOC_EPC_VM_CMDS
+
+        echo "echo \"cd /opt/ltebox/etc/\"" >> $LOC_EPC_VM_CMDS
+        echo "cd /opt/ltebox/etc/" >> $LOC_EPC_VM_CMDS
+        echo "echo \"sudo unzip -qq -o /home/ubuntu/etc-conf.zip\"" >> $LOC_EPC_VM_CMDS
+        echo "sudo unzip -qq -o /home/ubuntu/etc-conf.zip" >> $LOC_EPC_VM_CMDS
+        echo "sudo sed -i  -e 's#EPC_VM_IP_ADDRESS#$LOC_EPC_VM_IP_ADDR#' gw.conf" >> $LOC_EPC_VM_CMDS
+        echo "sudo sed -i  -e 's#EPC_VM_IP_ADDRESS#$LOC_EPC_VM_IP_ADDR#' mme.conf" >> $LOC_EPC_VM_CMDS
+
+        ssh -o StrictHostKeyChecking=no ubuntu@$LOC_EPC_VM_IP_ADDR < $LOC_EPC_VM_CMDS
+        rm -f $LOC_EPC_VM_CMDS
     fi
+}
+
+function start_epc {
+    local LOC_EPC_VM_NAME=$1
+    local LOC_EPC_VM_CMDS=$2
+    local LOC_EPC_VM_IP_ADDR=$3
 
-    # Starting EPC
     if [ $LTEBOX -eq 1 ]
     then
         echo "############################################################"
-        echo "Start EPC on EPC VM ($EPC_VM_NAME)"
+        echo "Start EPC on EPC VM ($LOC_EPC_VM_NAME)"
         echo "############################################################"
-        echo "echo \"cd /opt/hss_sim0609\"" >> $EPC_VM_CMDS
-        echo "cd /opt/hss_sim0609" >> $EPC_VM_CMDS
-        echo "echo \"sudo daemon --unsafe --name=simulated_hss --chdir=/opt/hss_sim0609 ./starthss_real\"" >> $EPC_VM_CMDS
-        echo "sudo daemon --unsafe --name=simulated_hss --chdir=/opt/hss_sim0609 ./starthss_real" >> $EPC_VM_CMDS
+        echo "echo \"cd /opt/hss_sim0609\"" > $LOC_EPC_VM_CMDS
+        echo "cd /opt/hss_sim0609" >> $LOC_EPC_VM_CMDS
+        echo "echo \"sudo daemon --unsafe --name=simulated_hss --chdir=/opt/hss_sim0609 ./starthss_real\"" >> $LOC_EPC_VM_CMDS
+        echo "sudo daemon --unsafe --name=simulated_hss --chdir=/opt/hss_sim0609 ./starthss_real" >> $LOC_EPC_VM_CMDS
 
-        echo "echo \"cd /opt/ltebox/tools/\"" >> $EPC_VM_CMDS
-        echo "cd /opt/ltebox/tools/" >> $EPC_VM_CMDS
-        echo "echo \"sudo ./start_ltebox\"" >> $EPC_VM_CMDS
-        echo "nohup sudo ./start_ltebox > /home/ubuntu/ltebox.txt" >> $EPC_VM_CMDS
+        echo "echo \"cd /opt/ltebox/tools/\"" >> $LOC_EPC_VM_CMDS
+        echo "cd /opt/ltebox/tools/" >> $LOC_EPC_VM_CMDS
+        echo "echo \"sudo ./start_ltebox\"" >> $LOC_EPC_VM_CMDS
+        echo "nohup sudo ./start_ltebox > /home/ubuntu/ltebox.txt" >> $LOC_EPC_VM_CMDS
 
-        ssh -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR < $EPC_VM_CMDS
-        rm -f $EPC_VM_CMDS
-
-        # We may have some adaptation to do
-        if [ -f /opt/ltebox-archives/adapt_ue_sim.txt ]
-        then
-            echo "############################################################"
-            echo "Doing some adaptation on UE side"
-            echo "############################################################"
-            ssh -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR < /opt/ltebox-archives/adapt_ue_sim.txt
-        fi
+        ssh -o StrictHostKeyChecking=no ubuntu@$LOC_EPC_VM_IP_ADDR < $LOC_EPC_VM_CMDS
+        rm -f $LOC_EPC_VM_CMDS
 
         i="0"
-        echo "ifconfig tun5 | egrep -c \"inet addr\"" > $EPC_VM_CMDS
+        echo "ifconfig tun5 | egrep -c \"inet addr\"" > $LOC_EPC_VM_CMDS
         while [ $i -lt 10 ]
         do
             sleep 2
-            CONNECTED=`ssh -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR < $EPC_VM_CMDS`
+            CONNECTED=`ssh -o StrictHostKeyChecking=no ubuntu@$LOC_EPC_VM_IP_ADDR < $LOC_EPC_VM_CMDS`
             if [ $CONNECTED -eq 1 ]
             then
                 i="100"
@@ -674,358 +415,923 @@ then
                 i=$[$i+1]
             fi
         done
-        rm $EPC_VM_CMDS
+        rm $LOC_EPC_VM_CMDS
         if [ $i -lt 50 ]
         then
             echo "Problem w/ starting ltebox EPC"
+            echo "TEST_KO" > $ARCHIVES_LOC/test_final_status.log
             exit -1
         fi
     fi
 
     # HERE ADD ANY INSTALL ACTIONS FOR ANOTHER EPC
 
-    # Retrieve EPC real IP address
+}
+
+function retrieve_real_epc_ip_addr {
+    local LOC_EPC_VM_NAME=$1
+    local LOC_EPC_VM_CMDS=$2
+    local LOC_EPC_VM_IP_ADDR=$3
+
     if [ $LTEBOX -eq 1 ]
     then
         # in our configuration file, we are using pool 5
-        echo "ifconfig tun5 | egrep \"inet addr\" | sed -e 's#^.*inet addr:##' -e 's#  P-t-P:.*\$##'" > $EPC_VM_CMDS
-        REAL_EPC_IP_ADDR=`ssh -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR < $EPC_VM_CMDS`
+        echo "ifconfig tun5 | egrep \"inet addr\" | sed -e 's#^.*inet addr:##' -e 's#  P-t-P:.*\$##'" > $LOC_EPC_VM_CMDS
+        REAL_EPC_IP_ADDR=`ssh -o StrictHostKeyChecking=no ubuntu@$LOC_EPC_VM_IP_ADDR < $LOC_EPC_VM_CMDS`
         echo "EPC IP Address     is : $REAL_EPC_IP_ADDR"
-        rm $EPC_VM_CMDS
+        rm $LOC_EPC_VM_CMDS
     fi
+}
 
-    echo "############################################################"
-    echo "Starting the eNB in FDD-5MHz mode"
-    echo "############################################################"
-    CURRENT_ENB_LOG_FILE=fdd_05MHz_enb.log
-    start_basic_sim_enb $VM_CMDS $VM_IP_ADDR $EPC_VM_IP_ADDR $CURRENT_ENB_LOG_FILE 25 lte-fdd-basic-sim.conf
+function terminate_epc {
+    if [ $LTEBOX -eq 1 ]
+    then
+        echo "echo \"cd /opt/ltebox/tools\"" > $1
+        echo "cd /opt/ltebox/tools" >> $1
+        echo "echo \"sudo ./stop_ltebox\"" >> $1
+        echo "sudo ./stop_ltebox" >> $1
+        echo "echo \"sudo daemon --name=simulated_hss --stop\"" >> $1
+        echo "sudo daemon --name=simulated_hss --stop" >> $1
+        echo "echo \"sudo killall --signal SIGKILL hss_sim\"" >> $1
+        echo "sudo killall --signal SIGKILL hss_sim" >> $1
+        ssh -o StrictHostKeyChecking=no ubuntu@$2 < $1
+        rm $1
+    fi
+}
 
-    echo "############################################################"
-    echo "Starting the UE in FDD-5MHz mode"
-    echo "############################################################"
-    CURRENT_UE_LOG_FILE=fdd_05MHz_ue.log
-    start_basic_sim_ue $VM_CMDS $VM_IP_ADDR $CURRENT_UE_LOG_FILE 25 2680
-    if [ $UE_SYNC -eq 0 ]
+function start_flexran_ctrl {
+    echo "cd /home/ubuntu/tmp" > $1
+    echo "if [ -f cmake_targets/log/flexran_ctl_run.log ]; then rm -f cmake_targets/log/flexran_ctl_run.log cmake_targets/log/flexran_ctl_query*.log; fi" >> $1
+    echo "echo \" sudo build/rt_controller -c log_config/basic_log\"" >> $1
+    echo "nohup sudo build/rt_controller -c log_config/basic_log > cmake_targets/log/flexran_ctl_run.log 2>&1 &" >> $1
+    ssh -o StrictHostKeyChecking=no ubuntu@$2 < $1
+    rm $1
+    sleep 10
+}
+
+function stop_flexran_ctrl {
+    echo "echo \"sudo killall --signal SIGKILL rt_controller\"" > $1
+    echo "sudo killall --signal SIGKILL rt_controller" > $1
+    ssh -o StrictHostKeyChecking=no ubuntu@$2 < $1
+    rm $1
+    sleep 2
+}
+
+function query_flexran_ctrl_status {
+    local LOC_MESSAGE=$3
+    echo "cd /home/ubuntu/tmp" > $1
+    echo "echo \"------------------------------------------------------------\" > cmake_targets/log/flexran_ctl_query_${LOC_MESSAGE}.log" >> $1
+    echo "echo \"LOG_NAME: $LOC_MESSAGE\" >> cmake_targets/log/flexran_ctl_query_${LOC_MESSAGE}.log" >> $1
+    echo "echo \"------------------------------------------------------------\" >> cmake_targets/log/flexran_ctl_query_${LOC_MESSAGE}.log" >> $1
+    echo "curl http://localhost:9999/stats | jq '.' | tee -a cmake_targets/log/flexran_ctl_query_${LOC_MESSAGE}.log" >> $1
+    ssh -o StrictHostKeyChecking=no ubuntu@$2 < $1
+    rm $1
+}
+
+function build_ue_on_separate_folder {
+    echo "mkdir tmp-ue" > $1
+    echo "cd tmp-ue" >> $1
+    echo "echo \"unzip -qq -DD ../localZip.zip\"" >> $1
+    echo "unzip -qq -DD ../localZip.zip" >> $1
+
+    # We may have some adaptation to do
+    if [ -f /opt/ltebox-archives/adapt_ue_l2_sim.txt ]
     then
-        echo "Problem w/ eNB and UE not syncing"
-        terminate_enb_ue_basic_sim $VM_CMDS $VM_IP_ADDR
-        scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
-        scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_UE_LOG_FILE $ARCHIVES_LOC
-        recover_core_dump $VM_CMDS $VM_IP_ADDR $ARCHIVES_LOC/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
-        terminate_ltebox_epc $EPC_VM_CMDS $EPC_VM_IP_ADDR
-        exit -1
+        echo "############################################################"
+        echo "Doing some adaptation on UE side"
+        echo "############################################################"
+        cat /opt/ltebox-archives/adapt_ue_l2_sim.txt >> $1
     fi
-    get_ue_ip_addr $VM_CMDS $VM_IP_ADDR
 
-    echo "############################################################"
-    echo "Pinging the UE"
-    echo "############################################################"
-    PING_LOG_FILE=fdd_05MHz_ping_ue.txt
-    ping_ue_ip_addr $EPC_VM_CMDS $EPC_VM_IP_ADDR $UE_IP_ADDR $PING_LOG_FILE
-    scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/$PING_LOG_FILE $ARCHIVES_LOC
-    check_ping_result $ARCHIVES_LOC/$PING_LOG_FILE 20
+    echo "echo \"source oaienv\"" >> $1
+    echo "source oaienv" >> $1
+    echo "cd cmake_targets/" >> $1
+    echo "mkdir log" >> $1
+    echo "chmod 777 log" >> $1
+    echo "echo \"./build_oai --UE -t ETHERNET \"" >> $1
+    echo "./build_oai --UE -t ETHERNET > log/ue-build.txt 2>&1" >> $1
+    echo "cd tools" >> $1
+    echo "sudo ifconfig lo: 127.0.0.2 netmask 255.0.0.0 up" >> $1
+    echo "sudo chmod 666 /etc/iproute2/rt_tables" >> $1
+    echo "source init_nas_s1 UE" >> $1
+    echo "ifconfig" >> $1
+    ssh -o StrictHostKeyChecking=no ubuntu@$2 < $1
+    rm -f $1
+}
 
-    echo "############################################################"
-    echo "Iperf DL"
-    echo "############################################################"
-    CURR_IPERF_LOG_BASE=fdd_05MHz_iperf_dl
-    iperf_dl $VM_CMDS $VM_IP_ADDR $EPC_VM_CMDS $EPC_VM_IP_ADDR 15 $CURR_IPERF_LOG_BASE
-    scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/${CURR_IPERF_LOG_BASE}_client.txt $ARCHIVES_LOC
-    scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/${CURR_IPERF_LOG_BASE}_server.txt $ARCHIVES_LOC
-    check_iperf $ARCHIVES_LOC/$CURR_IPERF_LOG_BASE 15
+function start_l2_sim_enb {
+    local LOC_VM_IP_ADDR=$2
+    local LOC_EPC_IP_ADDR=$3
+    local LOC_LOG_FILE=$4
+    local LOC_NB_RBS=$5
+    local LOC_CONF_FILE=$6
+    echo "cd /home/ubuntu/tmp" > $1
+    echo "echo \"sudo apt-get --yes --quiet install daemon \"" >> $1
+    echo "sudo apt-get --yes install daemon >> /home/ubuntu/tmp/cmake_targets/log/daemon-install.txt 2>&1" >> $1
+    echo "echo \"source oaienv\"" >> $1
+    echo "source oaienv" >> $1
+    echo "cd ci-scripts/conf_files/" >> $1
+    echo "cp $LOC_CONF_FILE ci-$LOC_CONF_FILE" >> $1
+    echo "sed -i -e 's#N_RB_DL.*=.*;#N_RB_DL                                         = $LOC_NB_RBS;#' -e 's#CI_MME_IP_ADDR#$LOC_EPC_IP_ADDR#' -e 's#CI_ENB_IP_ADDR#$LOC_VM_IP_ADDR#' ci-$LOC_CONF_FILE" >> $1
+    echo "echo \"grep N_RB_DL ci-$LOC_CONF_FILE\"" >> $1
+    echo "grep N_RB_DL ci-$LOC_CONF_FILE | sed -e 's#N_RB_DL.*=#N_RB_DL =#'" >> $1
+    echo "echo \"cd /home/ubuntu/tmp/cmake_targets/lte_build_oai/build/\"" >> $1
+    echo "sudo chmod 777 /home/ubuntu/tmp/cmake_targets/lte_build_oai/build/" >> $1
+    echo "cd /home/ubuntu/tmp/cmake_targets/lte_build_oai/build/" >> $1
+    echo "echo \"ulimit -c unlimited && ./lte-softmodem -O /home/ubuntu/tmp/ci-scripts/conf_files/ci-$LOC_CONF_FILE\" > ./my-lte-softmodem-run.sh " >> $1
+    echo "chmod 775 ./my-lte-softmodem-run.sh" >> $1
+    echo "cat ./my-lte-softmodem-run.sh" >> $1
+    echo "if [ -e /home/ubuntu/tmp/cmake_targets/log/$LOC_LOG_FILE ]; then sudo sudo rm -f /home/ubuntu/tmp/cmake_targets/log/$LOC_LOG_FILE; fi" >> $1
+    echo "sudo -E daemon --inherit --unsafe --name=enb_daemon --chdir=/home/ubuntu/tmp/cmake_targets/lte_build_oai/build/ -o /home/ubuntu/tmp/cmake_targets/log/$LOC_LOG_FILE ./my-lte-softmodem-run.sh" >> $1
 
-    echo "############################################################"
-    echo "Iperf UL"
-    echo "############################################################"
-    CURR_IPERF_LOG_BASE=fdd_05MHz_iperf_ul
-    iperf_ul $VM_CMDS $VM_IP_ADDR $EPC_VM_CMDS $EPC_VM_IP_ADDR 2 $CURR_IPERF_LOG_BASE
-    scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/${CURR_IPERF_LOG_BASE}_server.txt $ARCHIVES_LOC
-    scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/${CURR_IPERF_LOG_BASE}_client.txt $ARCHIVES_LOC
-    check_iperf $ARCHIVES_LOC/$CURR_IPERF_LOG_BASE 2
+    ssh -o StrictHostKeyChecking=no ubuntu@$LOC_VM_IP_ADDR < $1
+    rm $1
 
-    echo "############################################################"
-    echo "Terminate enb/ue simulators"
-    echo "############################################################"
-    terminate_enb_ue_basic_sim $VM_CMDS $VM_IP_ADDR
-    scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
-    scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_UE_LOG_FILE $ARCHIVES_LOC
-    recover_core_dump $VM_CMDS $VM_IP_ADDR $ARCHIVES_LOC/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
+    local i="0"
+    echo "egrep -c \"Waiting for PHY_config_req\" /home/ubuntu/tmp/cmake_targets/log/$LOC_LOG_FILE" > $1
+    while [ $i -lt 10 ]
+    do
+        sleep 5
+        CONNECTED=`ssh -o StrictHostKeyChecking=no ubuntu@$LOC_VM_IP_ADDR < $1`
+        if [ $CONNECTED -ne 0 ]
+        then
+            i="100"
+        else
+            i=$[$i+1]
+        fi
+    done
+    rm $1
+    if [ $i -lt 50 ]
+    then
+        ENB_SYNC=0
+        echo "L2-SIM eNB is NOT sync'ed: process still alive?"
+    else
+        ENB_SYNC=1
+        echo "L2-SIM eNB is sync'ed: waiting for UE(s) to connect"
+    fi
+    sleep 10
+}
 
+function start_l2_sim_ue {
+    local LOC_VM_IP_ADDR=$2
+    local LOC_LOG_FILE=$3
+    local LOC_CONF_FILE=$4
+    echo "echo \"cd /home/ubuntu/tmp-ue/cmake_targets/lte_build_oai/build/\"" >> $1
+    echo "sudo chmod 777 /home/ubuntu/tmp-ue/cmake_targets/lte_build_oai/build/" >> $1
+    echo "cd /home/ubuntu/tmp-ue/cmake_targets/lte_build_oai/build/" >> $1
+    echo "echo \"ulimit -c unlimited && ./lte-uesoftmodem -O /home/ubuntu/tmp-ue/ci-scripts/conf_files/$LOC_CONF_FILE --L2-emul 3 --num-ues 1\" > ./my-lte-softmodem-run.sh " >> $1
+    echo "chmod 775 ./my-lte-softmodem-run.sh" >> $1
+    echo "cat ./my-lte-softmodem-run.sh" >> $1
+    echo "if [ -e /home/ubuntu/tmp/cmake_targets/log/$LOC_LOG_FILE ]; then sudo sudo rm -f /home/ubuntu/tmp/cmake_targets/log/$LOC_LOG_FILE; fi" >> $1
+    echo "sudo -E daemon --inherit --unsafe --name=ue_daemon --chdir=/home/ubuntu/tmp-ue/cmake_targets/lte_build_oai/build/ -o /home/ubuntu/tmp/cmake_targets/log/$LOC_LOG_FILE ./my-lte-softmodem-run.sh" >> $1
+
+    ssh -o StrictHostKeyChecking=no ubuntu@$LOC_VM_IP_ADDR < $1
+    rm $1
+
+    local i="0"
+    echo "egrep -c \"Received NFAPI_START_REQ\" /home/ubuntu/tmp/cmake_targets/log/$LOC_LOG_FILE" > $1
+    while [ $i -lt 10 ]
+    do
+        sleep 5
+        CONNECTED=`ssh -o StrictHostKeyChecking=no ubuntu@$LOC_VM_IP_ADDR < $1`
+        if [ $CONNECTED -eq 1 ]
+        then
+            i="100"
+        else
+            i=$[$i+1]
+        fi
+    done
+    rm $1
+    if [ $i -lt 50 ]
+    then
+        UE_SYNC=0
+        echo "L2-SIM UE is NOT sync'ed w/ eNB"
+        return
+    else
+        UE_SYNC=1
+        echo "L2-SIM UE is sync'ed w/ eNB"
+    fi
+    # Checking oip1 interface has now an IP address
+    i="0"
+    echo "ifconfig oip1 | egrep -c \"inet addr\"" > $1
+    while [ $i -lt 10 ]
+    do
+        sleep 5
+        CONNECTED=`ssh -o StrictHostKeyChecking=no ubuntu@$LOC_VM_IP_ADDR < $1`
+        if [ $CONNECTED -eq 1 ]
+        then
+            i="100"
+        else
+            i=$[$i+1]
+        fi
+    done
+    rm $1
+    if [ $i -lt 50 ]
+    then
+        UE_SYNC=0
+        echo "L2-SIM UE oip1 is NOT sync'ed w/ EPC"
+    else
+        UE_SYNC=1
+        echo "L2-SIM UE oip1 is sync'ed w/ EPC"
+    fi
+    sleep 10
+}
+
+function run_test_on_vm {
     echo "############################################################"
-    echo "Starting the eNB in FDD-10MHz mode"
+    echo "OAI CI VM script"
     echo "############################################################"
-    CURRENT_ENB_LOG_FILE=fdd_10MHz_enb.log
-    start_basic_sim_enb $VM_CMDS $VM_IP_ADDR $EPC_VM_IP_ADDR $CURRENT_ENB_LOG_FILE 50 lte-fdd-basic-sim.conf
+    echo "VM_NAME             = $VM_NAME"
+    echo "VM_CMD_FILE         = $VM_CMDS"
+    echo "JENKINS_WKSP        = $JENKINS_WKSP"
+    echo "ARCHIVES_LOC        = $ARCHIVES_LOC"
 
     echo "############################################################"
-    echo "Starting the UE in FDD-10MHz mode"
+    echo "Waiting for VM to be started"
     echo "############################################################"
-    CURRENT_UE_LOG_FILE=fdd_10MHz_ue.log
-    start_basic_sim_ue $VM_CMDS $VM_IP_ADDR $CURRENT_UE_LOG_FILE 50 2680
-    if [ $UE_SYNC -eq 0 ]
+    uvt-kvm wait $VM_NAME --insecure
+
+    VM_IP_ADDR=`uvt-kvm ip $VM_NAME`
+    echo "$VM_NAME has for IP addr = $VM_IP_ADDR"
+
+    if [ "$RUN_OPTIONS" == "none" ]
+    then
+        echo "No run on VM testing for this variant currently"
+        exit $STATUS
+    fi
+
+    if [[ $RUN_OPTIONS =~ .*run_exec_autotests.* ]]
+    then
+        echo "############################################################"
+        echo "Running test script on VM ($VM_NAME)"
+        echo "############################################################"
+        echo "echo \"sudo apt-get --yes --quiet install bc \"" > $VM_CMDS
+        echo "sudo apt-get update > bc-install.txt 2>&1" >> $VM_CMDS
+        echo "sudo apt-get --yes install bc >> bc-install.txt 2>&1" >> $VM_CMDS
+        echo "cd tmp" >> $VM_CMDS
+        echo "echo \"source oaienv\"" >> $VM_CMDS
+        echo "source oaienv" >> $VM_CMDS
+        echo "echo \"cd cmake_targets/autotests\"" >> $VM_CMDS
+        echo "cd cmake_targets/autotests" >> $VM_CMDS
+        echo "echo \"rm -Rf log\"" >> $VM_CMDS
+        echo "rm -Rf log" >> $VM_CMDS
+        echo "$RUN_OPTIONS" | sed -e 's@"@\\"@g' -e 's@^@echo "@' -e 's@$@"@' >> $VM_CMDS
+        echo "$RUN_OPTIONS" >> $VM_CMDS
+        echo "cp /home/ubuntu/bc-install.txt log" >> $VM_CMDS
+        echo "cd log" >> $VM_CMDS
+        echo "zip -r -qq tmp.zip *.* 0*" >> $VM_CMDS
+
+        ssh -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR < $VM_CMDS
+
+        echo "############################################################"
+        echo "Creating a tmp folder to store results and artifacts"
+        echo "############################################################"
+
+        if [ -d $ARCHIVES_LOC ]
+        then
+            rm -Rf $ARCHIVES_LOC
+        fi
+        mkdir --parents $ARCHIVES_LOC
+
+        scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/autotests/log/tmp.zip $ARCHIVES_LOC
+        pushd $ARCHIVES_LOC
+        unzip -qq -DD tmp.zip
+        rm tmp.zip
+        if [ -f results_autotests.xml ]
+        then
+            FUNCTION=`echo $VM_NAME | sed -e "s@$VM_TEMPLATE@@"`
+            NEW_NAME=`echo "results_autotests.xml" | sed -e "s@results_autotests@results_autotests-$FUNCTION@"`
+            echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > $NEW_NAME
+            echo "<?xml-stylesheet type=\"text/xsl\" href=\"$FUNCTION.xsl\" ?>" >> $NEW_NAME
+            cat results_autotests.xml >> $NEW_NAME
+            sed -e "s@TEMPLATE@$FUNCTION@" $JENKINS_WKSP/ci-scripts/template.xsl > $FUNCTION.xsl
+            #mv results_autotests.xml $NEW_NAME
+            rm results_autotests.xml
+        fi
+        popd
+
+        if [ $KEEP_VM_ALIVE -eq 0 ]
+        then
+            echo "############################################################"
+            echo "Destroying VM"
+            echo "############################################################"
+            uvt-kvm destroy $VM_NAME
+            ssh-keygen -R $VM_IP_ADDR
+        fi
+        rm -f $VM_CMDS
+
+        echo "############################################################"
+        echo "Checking run status"
+        echo "############################################################"
+
+        LOG_FILES=`ls $ARCHIVES_LOC/results_autotests*.xml`
+        NB_FOUND_FILES=0
+        NB_RUNS=0
+        NB_FAILURES=0
+
+        for FULLFILE in $LOG_FILES
+        do
+            TESTSUITES=`egrep "testsuite errors" $FULLFILE`
+            for TESTSUITE in $TESTSUITES
+            do
+                if [[ "$TESTSUITE" == *"tests="* ]]
+                then
+                    RUNS=`echo $TESTSUITE | awk 'BEGIN{FS="="}{print $2}END{}' | sed -e "s@'@@g" `
+                    NB_RUNS=$((NB_RUNS + RUNS))
+                fi
+                if [[ "$TESTSUITE" == *"failures="* ]]
+                then
+                    FAILS=`echo $TESTSUITE | awk 'BEGIN{FS="="}{print $2}END{}' | sed -e "s@'@@g" `
+                    NB_FAILURES=$((NB_FAILURES + FAILS))
+                fi
+            done
+            NB_FOUND_FILES=$((NB_FOUND_FILES + 1))
+        done
+
+        echo "NB_FOUND_FILES = $NB_FOUND_FILES"
+        echo "NB_RUNS        = $NB_RUNS"
+        echo "NB_FAILURES    = $NB_FAILURES"
+
+        if [ $NB_FOUND_FILES -eq 0 ]; then STATUS=-1; fi
+        if [ $NB_RUNS -eq 0 ]; then STATUS=-1; fi
+        if [ $NB_FAILURES -ne 0 ]; then STATUS=-1; fi
+
+        if [ $STATUS -eq 0 ]
+        then
+            echo "TEST_OK" > $ARCHIVES_LOC/test_final_status.log
+        else
+            echo "TEST_KO" > $ARCHIVES_LOC/test_final_status.log
+        fi
+    fi
+
+    if [[ "$RUN_OPTIONS" == "complex" ]] && [[ $VM_NAME =~ .*-basic-sim.* ]]
     then
-        echo "Problem w/ eNB and UE not syncing"
+        PING_STATUS=0
+        IPERF_STATUS=0
+        if [ -d $ARCHIVES_LOC ]
+        then
+            rm -Rf $ARCHIVES_LOC
+        fi
+        mkdir --parents $ARCHIVES_LOC
+
+        # Creating a VM for EPC and installing SW
+        EPC_VM_NAME=`echo $VM_NAME | sed -e "s#basic-sim#epc#"`
+        EPC_VM_CMDS=${EPC_VM_NAME}_cmds.txt
+        LTEBOX=0
+        install_epc_on_vm $EPC_VM_NAME $EPC_VM_CMDS
+        EPC_VM_IP_ADDR=`uvt-kvm ip $EPC_VM_NAME`
+
+        # Starting EPC
+        start_epc $EPC_VM_NAME $EPC_VM_CMDS $EPC_VM_IP_ADDR
+
+        # Retrieve EPC real IP address
+        retrieve_real_epc_ip_addr $EPC_VM_NAME $EPC_VM_CMDS $EPC_VM_IP_ADDR
+
+        # We may have some adaptation to do
+        if [ -f /opt/ltebox-archives/adapt_ue_sim.txt ]
+        then
+            echo "############################################################"
+            echo "Doing some adaptation on UE side"
+            echo "############################################################"
+            ssh -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR < /opt/ltebox-archives/adapt_ue_sim.txt
+        fi
+
+        echo "############################################################"
+        echo "Starting the eNB in FDD-5MHz mode"
+        echo "############################################################"
+        CURRENT_ENB_LOG_FILE=fdd_05MHz_enb.log
+        start_basic_sim_enb $VM_CMDS $VM_IP_ADDR $EPC_VM_IP_ADDR $CURRENT_ENB_LOG_FILE 25 lte-fdd-basic-sim.conf none
+
+        echo "############################################################"
+        echo "Starting the UE in FDD-5MHz mode"
+        echo "############################################################"
+        CURRENT_UE_LOG_FILE=fdd_05MHz_ue.log
+        start_basic_sim_ue $VM_CMDS $VM_IP_ADDR $CURRENT_UE_LOG_FILE 25 2680
+        if [ $UE_SYNC -eq 0 ]
+        then
+            echo "Problem w/ eNB and UE not syncing"
+            terminate_enb_ue_basic_sim $VM_CMDS $VM_IP_ADDR
+            scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
+            scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_UE_LOG_FILE $ARCHIVES_LOC
+            recover_core_dump $VM_CMDS $VM_IP_ADDR $ARCHIVES_LOC/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
+            terminate_epc $EPC_VM_CMDS $EPC_VM_IP_ADDR
+            echo "TEST_KO" > $ARCHIVES_LOC/test_final_status.log
+            exit -1
+        fi
+        get_ue_ip_addr $VM_CMDS $VM_IP_ADDR
+
+        echo "############################################################"
+        echo "Pinging the UE"
+        echo "############################################################"
+        PING_LOG_FILE=fdd_05MHz_ping_ue.txt
+        ping_ue_ip_addr $EPC_VM_CMDS $EPC_VM_IP_ADDR $UE_IP_ADDR $PING_LOG_FILE
+        scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/$PING_LOG_FILE $ARCHIVES_LOC
+        check_ping_result $ARCHIVES_LOC/$PING_LOG_FILE 20
+
+        echo "############################################################"
+        echo "Iperf DL"
+        echo "############################################################"
+        CURR_IPERF_LOG_BASE=fdd_05MHz_iperf_dl
+        iperf_dl $VM_CMDS $VM_IP_ADDR $EPC_VM_CMDS $EPC_VM_IP_ADDR 15 $CURR_IPERF_LOG_BASE
+        scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/${CURR_IPERF_LOG_BASE}_client.txt $ARCHIVES_LOC
+        scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/${CURR_IPERF_LOG_BASE}_server.txt $ARCHIVES_LOC
+        check_iperf $ARCHIVES_LOC/$CURR_IPERF_LOG_BASE 15
+
+        echo "############################################################"
+        echo "Iperf UL"
+        echo "############################################################"
+        CURR_IPERF_LOG_BASE=fdd_05MHz_iperf_ul
+        iperf_ul $VM_CMDS $VM_IP_ADDR $EPC_VM_CMDS $EPC_VM_IP_ADDR 2 $CURR_IPERF_LOG_BASE
+        scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/${CURR_IPERF_LOG_BASE}_server.txt $ARCHIVES_LOC
+        scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/${CURR_IPERF_LOG_BASE}_client.txt $ARCHIVES_LOC
+        check_iperf $ARCHIVES_LOC/$CURR_IPERF_LOG_BASE 2
+
+        echo "############################################################"
+        echo "Terminate enb/ue simulators"
+        echo "############################################################"
         terminate_enb_ue_basic_sim $VM_CMDS $VM_IP_ADDR
         scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
         scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_UE_LOG_FILE $ARCHIVES_LOC
         recover_core_dump $VM_CMDS $VM_IP_ADDR $ARCHIVES_LOC/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
-        terminate_ltebox_epc $EPC_VM_CMDS $EPC_VM_IP_ADDR
-        exit -1
-    fi
-    get_ue_ip_addr $VM_CMDS $VM_IP_ADDR
+        sleep 10
 
-    echo "############################################################"
-    echo "Pinging the UE"
-    echo "############################################################"
-    PING_LOG_FILE=fdd_10MHz_ping_ue.txt
-    ping_ue_ip_addr $EPC_VM_CMDS $EPC_VM_IP_ADDR $UE_IP_ADDR $PING_LOG_FILE
-    scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/$PING_LOG_FILE $ARCHIVES_LOC
-    check_ping_result $ARCHIVES_LOC/$PING_LOG_FILE 20
+        echo "############################################################"
+        echo "Starting the eNB in FDD-10MHz mode"
+        echo "############################################################"
+        CURRENT_ENB_LOG_FILE=fdd_10MHz_enb.log
+        start_basic_sim_enb $VM_CMDS $VM_IP_ADDR $EPC_VM_IP_ADDR $CURRENT_ENB_LOG_FILE 50 lte-fdd-basic-sim.conf none
 
-    echo "############################################################"
-    echo "Iperf DL"
-    echo "############################################################"
-    CURR_IPERF_LOG_BASE=fdd_10MHz_iperf_dl
-    iperf_dl $VM_CMDS $VM_IP_ADDR $EPC_VM_CMDS $EPC_VM_IP_ADDR 15 $CURR_IPERF_LOG_BASE
-    scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/${CURR_IPERF_LOG_BASE}_client.txt $ARCHIVES_LOC
-    scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/${CURR_IPERF_LOG_BASE}_server.txt $ARCHIVES_LOC
-    check_iperf $ARCHIVES_LOC/$CURR_IPERF_LOG_BASE 15
+        echo "############################################################"
+        echo "Starting the UE in FDD-10MHz mode"
+        echo "############################################################"
+        CURRENT_UE_LOG_FILE=fdd_10MHz_ue.log
+        start_basic_sim_ue $VM_CMDS $VM_IP_ADDR $CURRENT_UE_LOG_FILE 50 2680
+        if [ $UE_SYNC -eq 0 ]
+        then
+            echo "Problem w/ eNB and UE not syncing"
+            terminate_enb_ue_basic_sim $VM_CMDS $VM_IP_ADDR
+            scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
+            scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_UE_LOG_FILE $ARCHIVES_LOC
+            recover_core_dump $VM_CMDS $VM_IP_ADDR $ARCHIVES_LOC/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
+            terminate_epc $EPC_VM_CMDS $EPC_VM_IP_ADDR
+            echo "TEST_KO" > $ARCHIVES_LOC/test_final_status.log
+            exit -1
+        fi
+        get_ue_ip_addr $VM_CMDS $VM_IP_ADDR
 
-    echo "############################################################"
-    echo "Iperf UL"
-    echo "############################################################"
-    CURR_IPERF_LOG_BASE=fdd_10MHz_iperf_ul
-    iperf_ul $VM_CMDS $VM_IP_ADDR $EPC_VM_CMDS $EPC_VM_IP_ADDR 2 $CURR_IPERF_LOG_BASE
-    scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/${CURR_IPERF_LOG_BASE}_server.txt $ARCHIVES_LOC
-    scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/${CURR_IPERF_LOG_BASE}_client.txt $ARCHIVES_LOC
-    check_iperf $ARCHIVES_LOC/$CURR_IPERF_LOG_BASE 2
+        echo "############################################################"
+        echo "Pinging the UE"
+        echo "############################################################"
+        PING_LOG_FILE=fdd_10MHz_ping_ue.txt
+        ping_ue_ip_addr $EPC_VM_CMDS $EPC_VM_IP_ADDR $UE_IP_ADDR $PING_LOG_FILE
+        scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/$PING_LOG_FILE $ARCHIVES_LOC
+        check_ping_result $ARCHIVES_LOC/$PING_LOG_FILE 20
 
-    echo "############################################################"
-    echo "Terminate enb/ue simulators"
-    echo "############################################################"
-    terminate_enb_ue_basic_sim $VM_CMDS $VM_IP_ADDR
-    scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
-    scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_UE_LOG_FILE $ARCHIVES_LOC
-    recover_core_dump $VM_CMDS $VM_IP_ADDR $ARCHIVES_LOC/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
+        echo "############################################################"
+        echo "Iperf DL"
+        echo "############################################################"
+        CURR_IPERF_LOG_BASE=fdd_10MHz_iperf_dl
+        iperf_dl $VM_CMDS $VM_IP_ADDR $EPC_VM_CMDS $EPC_VM_IP_ADDR 15 $CURR_IPERF_LOG_BASE
+        scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/${CURR_IPERF_LOG_BASE}_client.txt $ARCHIVES_LOC
+        scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/${CURR_IPERF_LOG_BASE}_server.txt $ARCHIVES_LOC
+        check_iperf $ARCHIVES_LOC/$CURR_IPERF_LOG_BASE 15
 
-    echo "############################################################"
-    echo "Starting the eNB in FDD-20MHz mode"
-    echo "############################################################"
-    CURRENT_ENB_LOG_FILE=fdd_20MHz_enb.log
-    start_basic_sim_enb $VM_CMDS $VM_IP_ADDR $EPC_VM_IP_ADDR $CURRENT_ENB_LOG_FILE 100 lte-fdd-basic-sim.conf
+        echo "############################################################"
+        echo "Iperf UL"
+        echo "############################################################"
+        CURR_IPERF_LOG_BASE=fdd_10MHz_iperf_ul
+        iperf_ul $VM_CMDS $VM_IP_ADDR $EPC_VM_CMDS $EPC_VM_IP_ADDR 2 $CURR_IPERF_LOG_BASE
+        scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/${CURR_IPERF_LOG_BASE}_server.txt $ARCHIVES_LOC
+        scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/${CURR_IPERF_LOG_BASE}_client.txt $ARCHIVES_LOC
+        check_iperf $ARCHIVES_LOC/$CURR_IPERF_LOG_BASE 2
 
-    echo "############################################################"
-    echo "Starting the UE in FDD-20MHz mode"
-    echo "############################################################"
-    CURRENT_UE_LOG_FILE=fdd_20MHz_ue.log
-    start_basic_sim_ue $VM_CMDS $VM_IP_ADDR $CURRENT_UE_LOG_FILE 100 2680
-    if [ $UE_SYNC -eq 0 ]
-    then
-        echo "Problem w/ eNB and UE not syncing"
+        echo "############################################################"
+        echo "Terminate enb/ue simulators"
+        echo "############################################################"
         terminate_enb_ue_basic_sim $VM_CMDS $VM_IP_ADDR
         scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
         scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_UE_LOG_FILE $ARCHIVES_LOC
         recover_core_dump $VM_CMDS $VM_IP_ADDR $ARCHIVES_LOC/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
-        terminate_ltebox_epc $EPC_VM_CMDS $EPC_VM_IP_ADDR
-        exit -1
-    fi
-    get_ue_ip_addr $VM_CMDS $VM_IP_ADDR
+        sleep 10
 
-    echo "############################################################"
-    echo "Pinging the UE"
-    echo "############################################################"
-    PING_LOG_FILE=fdd_20MHz_ping_ue.txt
-    ping_ue_ip_addr $EPC_VM_CMDS $EPC_VM_IP_ADDR $UE_IP_ADDR $PING_LOG_FILE
-    scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/$PING_LOG_FILE $ARCHIVES_LOC
-    check_ping_result $ARCHIVES_LOC/$PING_LOG_FILE 20
+        echo "############################################################"
+        echo "Starting the eNB in FDD-20MHz mode"
+        echo "############################################################"
+        CURRENT_ENB_LOG_FILE=fdd_20MHz_enb.log
+        start_basic_sim_enb $VM_CMDS $VM_IP_ADDR $EPC_VM_IP_ADDR $CURRENT_ENB_LOG_FILE 100 lte-fdd-basic-sim.conf none
 
-    echo "############################################################"
-    echo "Iperf DL"
-    echo "############################################################"
-    CURR_IPERF_LOG_BASE=fdd_20MHz_iperf_dl
-    iperf_dl $VM_CMDS $VM_IP_ADDR $EPC_VM_CMDS $EPC_VM_IP_ADDR 15 $CURR_IPERF_LOG_BASE
-    scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/${CURR_IPERF_LOG_BASE}_client.txt $ARCHIVES_LOC
-    scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/${CURR_IPERF_LOG_BASE}_server.txt $ARCHIVES_LOC
-    check_iperf $ARCHIVES_LOC/$CURR_IPERF_LOG_BASE 15
+        echo "############################################################"
+        echo "Starting the UE in FDD-20MHz mode"
+        echo "############################################################"
+        CURRENT_UE_LOG_FILE=fdd_20MHz_ue.log
+        start_basic_sim_ue $VM_CMDS $VM_IP_ADDR $CURRENT_UE_LOG_FILE 100 2680
+        if [ $UE_SYNC -eq 0 ]
+        then
+            echo "Problem w/ eNB and UE not syncing"
+            terminate_enb_ue_basic_sim $VM_CMDS $VM_IP_ADDR
+            scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
+            scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_UE_LOG_FILE $ARCHIVES_LOC
+            recover_core_dump $VM_CMDS $VM_IP_ADDR $ARCHIVES_LOC/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
+            terminate_epc $EPC_VM_CMDS $EPC_VM_IP_ADDR
+            echo "TEST_KO" > $ARCHIVES_LOC/test_final_status.log
+            exit -1
+        fi
+        get_ue_ip_addr $VM_CMDS $VM_IP_ADDR
 
-    echo "############################################################"
-    echo "Terminate enb/ue simulators"
-    echo "############################################################"
-    terminate_enb_ue_basic_sim $VM_CMDS $VM_IP_ADDR
-    scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
-    scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_UE_LOG_FILE $ARCHIVES_LOC
-    recover_core_dump $VM_CMDS $VM_IP_ADDR $ARCHIVES_LOC/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
+        echo "############################################################"
+        echo "Pinging the UE"
+        echo "############################################################"
+        PING_LOG_FILE=fdd_20MHz_ping_ue.txt
+        ping_ue_ip_addr $EPC_VM_CMDS $EPC_VM_IP_ADDR $UE_IP_ADDR $PING_LOG_FILE
+        scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/$PING_LOG_FILE $ARCHIVES_LOC
+        check_ping_result $ARCHIVES_LOC/$PING_LOG_FILE 20
 
-    echo "############################################################"
-    echo "Starting the eNB in TDD-5MHz mode"
-    echo "############################################################"
-    CURRENT_ENB_LOG_FILE=tdd_05MHz_enb.log
-    start_basic_sim_enb $VM_CMDS $VM_IP_ADDR $EPC_VM_IP_ADDR $CURRENT_ENB_LOG_FILE 25 lte-tdd-basic-sim.conf
+        echo "############################################################"
+        echo "Iperf DL"
+        echo "############################################################"
+        CURR_IPERF_LOG_BASE=fdd_20MHz_iperf_dl
+        iperf_dl $VM_CMDS $VM_IP_ADDR $EPC_VM_CMDS $EPC_VM_IP_ADDR 15 $CURR_IPERF_LOG_BASE
+        scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/${CURR_IPERF_LOG_BASE}_client.txt $ARCHIVES_LOC
+        scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/${CURR_IPERF_LOG_BASE}_server.txt $ARCHIVES_LOC
+        check_iperf $ARCHIVES_LOC/$CURR_IPERF_LOG_BASE 15
 
-    echo "############################################################"
-    echo "Starting the UE in TDD-5MHz mode"
-    echo "############################################################"
-    CURRENT_UE_LOG_FILE=tdd_05MHz_ue.log
-    start_basic_sim_ue $VM_CMDS $VM_IP_ADDR $CURRENT_UE_LOG_FILE 25 2350
-    if [ $UE_SYNC -eq 0 ]
-    then
-        echo "Problem w/ eNB and UE not syncing"
+        echo "############################################################"
+        echo "Terminate enb/ue simulators"
+        echo "############################################################"
         terminate_enb_ue_basic_sim $VM_CMDS $VM_IP_ADDR
         scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
         scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_UE_LOG_FILE $ARCHIVES_LOC
         recover_core_dump $VM_CMDS $VM_IP_ADDR $ARCHIVES_LOC/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
-        terminate_ltebox_epc $EPC_VM_CMDS $EPC_VM_IP_ADDR
-        exit -1
-    fi
-    get_ue_ip_addr $VM_CMDS $VM_IP_ADDR
+        sleep 10
 
-    echo "############################################################"
-    echo "Pinging the UE"
-    echo "############################################################"
-    PING_LOG_FILE=tdd_05MHz_ping_ue.txt
-    ping_ue_ip_addr $EPC_VM_CMDS $EPC_VM_IP_ADDR $UE_IP_ADDR $PING_LOG_FILE
-    scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/$PING_LOG_FILE $ARCHIVES_LOC
-    check_ping_result $ARCHIVES_LOC/$PING_LOG_FILE 20
-
-# Bug in TDD 5Mhz --- not running it
-#    echo "############################################################"
-#    echo "Iperf DL"
-#    echo "############################################################"
-#    CURR_IPERF_LOG_BASE=tdd_05MHz_iperf_dl
-#    iperf_dl $VM_CMDS $VM_IP_ADDR $EPC_VM_CMDS $EPC_VM_IP_ADDR 6 $CURR_IPERF_LOG_BASE
-#    scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/${CURR_IPERF_LOG_BASE}_client.txt $ARCHIVES_LOC
-#    scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/${CURR_IPERF_LOG_BASE}_server.txt $ARCHIVES_LOC
-#    check_iperf $ARCHIVES_LOC/$CURR_IPERF_LOG_BASE 6
+        if [ -d $JENKINS_WKSP/flexran ]
+        then
+            echo "############################################################"
+            echo "Flexran testing is possible"
+            echo "############################################################"
+            local j="0"
+            while [ $j -lt 20 ]
+            do
+                if [ -e $JENKINS_WKSP/flexran/flexran_build_complete.txt ]
+                then
+                    echo "Found an proper flexran controller vm build"
+                    j="100"
+                else
+                    j=$[$j+1]
+                    sleep 30
+                fi
+            done
+            if [ $j -lt 50 ]
+            then
+                echo "ERROR: compiling flexran controller on vm went wrong"
+                terminate_epc $EPC_VM_CMDS $EPC_VM_IP_ADDR
+                echo "TEST_KO" > $ARCHIVES_LOC/test_final_status.log
+                exit -1
+            fi
+            FLEXRAN_CTL_VM_NAME=`echo $VM_NAME | sed -e "s#basic-sim#flexran-rtc#"`
+            FLEXRAN_CTL_VM_CMDS=`echo $VM_CMDS | sed -e "s#cmds#flexran-rtc-cmds#"`
+            IS_FLEXRAN_VM_ALIVE=`uvt-kvm list | grep -c $FLEXRAN_CTL_VM_NAME`
+            if [ $IS_FLEXRAN_VM_ALIVE -eq 0 ]
+            then
+                echo "ERROR: Flexran Ctl VM is not alive"
+                terminate_epc $EPC_VM_CMDS $EPC_VM_IP_ADDR
+                echo "TEST_KO" > $ARCHIVES_LOC/test_final_status.log
+                exit -1
+            fi
+            uvt-kvm wait $FLEXRAN_CTL_VM_NAME --insecure
+            FLEXRAN_CTL_VM_IP_ADDR=`uvt-kvm ip $FLEXRAN_CTL_VM_NAME`
 
-    echo "############################################################"
-    echo "Terminate enb/ue simulators"
-    echo "############################################################"
-    terminate_enb_ue_basic_sim $VM_CMDS $VM_IP_ADDR
-    scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
-    scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_UE_LOG_FILE $ARCHIVES_LOC
-    recover_core_dump $VM_CMDS $VM_IP_ADDR $ARCHIVES_LOC/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
+            echo "$FLEXRAN_CTL_VM_NAME has for IP addr = $FLEXRAN_CTL_VM_IP_ADDR"
+            echo "FLEXRAN_CTL_VM_CMDS     = $FLEXRAN_CTL_VM_CMDS"
+            echo "############################################################"
+            echo "Starting the FLEXRAN CONTROLLER"
+            echo "############################################################"
+            start_flexran_ctrl $FLEXRAN_CTL_VM_CMDS $FLEXRAN_CTL_VM_IP_ADDR
+            query_flexran_ctrl_status $FLEXRAN_CTL_VM_CMDS $FLEXRAN_CTL_VM_IP_ADDR 01_no_enb_connected
 
-    echo "############################################################"
-    echo "Starting the eNB in TDD-10MHz mode"
-    echo "############################################################"
-    CURRENT_ENB_LOG_FILE=tdd_10MHz_enb.log
-    start_basic_sim_enb $VM_CMDS $VM_IP_ADDR $EPC_VM_IP_ADDR $CURRENT_ENB_LOG_FILE 50 lte-tdd-basic-sim.conf
+            echo "############################################################"
+            echo "Starting the eNB in FDD-5MHz mode with Flexran ON"
+            echo "############################################################"
+            CURRENT_ENB_LOG_FILE=fdd_05fMHz_enb.log
+            start_basic_sim_enb $VM_CMDS $VM_IP_ADDR $EPC_VM_IP_ADDR $CURRENT_ENB_LOG_FILE 25 lte-fdd-basic-sim.conf $FLEXRAN_CTL_VM_IP_ADDR
+            query_flexran_ctrl_status $FLEXRAN_CTL_VM_CMDS $FLEXRAN_CTL_VM_IP_ADDR 02_enb_connected
 
-    echo "############################################################"
-    echo "Starting the UE in TDD-10MHz mode"
-    echo "############################################################"
-    CURRENT_UE_LOG_FILE=tdd_10MHz_ue.log
-    start_basic_sim_ue $VM_CMDS $VM_IP_ADDR $CURRENT_UE_LOG_FILE 50 2350
-    if [ $UE_SYNC -eq 0 ]
-    then
-        echo "Problem w/ eNB and UE not syncing"
+            echo "############################################################"
+            echo "Starting the UE in FDD-5MHz mode"
+            echo "############################################################"
+            CURRENT_UE_LOG_FILE=fdd_05fMHz_ue.log
+            start_basic_sim_ue $VM_CMDS $VM_IP_ADDR $CURRENT_UE_LOG_FILE 25 2680
+            if [ $UE_SYNC -eq 0 ]
+            then
+                echo "Problem w/ eNB and UE not syncing"
+                terminate_enb_ue_basic_sim $VM_CMDS $VM_IP_ADDR
+                scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
+                scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_UE_LOG_FILE $ARCHIVES_LOC
+                recover_core_dump $VM_CMDS $VM_IP_ADDR $ARCHIVES_LOC/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
+                terminate_epc $EPC_VM_CMDS $EPC_VM_IP_ADDR
+                stop_flexran_ctrl $FLEXRAN_CTL_VM_CMDS $FLEXRAN_CTL_VM_IP_ADDR
+                echo "TEST_KO" > $ARCHIVES_LOC/test_final_status.log
+                exit -1
+            fi
+            query_flexran_ctrl_status $FLEXRAN_CTL_VM_CMDS $FLEXRAN_CTL_VM_IP_ADDR 03_enb_ue_connected
+            get_ue_ip_addr $VM_CMDS $VM_IP_ADDR
+
+            sleep 30
+            echo "############################################################"
+            echo "Terminate enb/ue simulators"
+            echo "############################################################"
+            terminate_enb_ue_basic_sim $VM_CMDS $VM_IP_ADDR
+            scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
+            scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_UE_LOG_FILE $ARCHIVES_LOC
+            recover_core_dump $VM_CMDS $VM_IP_ADDR $ARCHIVES_LOC/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
+            sleep 10
+
+            echo "############################################################"
+            echo "Stopping the FLEXRAN CONTROLLER"
+            echo "############################################################"
+            stop_flexran_ctrl $FLEXRAN_CTL_VM_CMDS $FLEXRAN_CTL_VM_IP_ADDR
+            scp -o StrictHostKeyChecking=no ubuntu@$FLEXRAN_CTL_VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/flexran_ctl_*.log $ARCHIVES_LOC
+        fi
+
+        echo "############################################################"
+        echo "Starting the eNB in TDD-5MHz mode"
+        echo "############################################################"
+        CURRENT_ENB_LOG_FILE=tdd_05MHz_enb.log
+        start_basic_sim_enb $VM_CMDS $VM_IP_ADDR $EPC_VM_IP_ADDR $CURRENT_ENB_LOG_FILE 25 lte-tdd-basic-sim.conf none
+
+        echo "############################################################"
+        echo "Starting the UE in TDD-5MHz mode"
+        echo "############################################################"
+        CURRENT_UE_LOG_FILE=tdd_05MHz_ue.log
+        start_basic_sim_ue $VM_CMDS $VM_IP_ADDR $CURRENT_UE_LOG_FILE 25 2350
+        if [ $UE_SYNC -eq 0 ]
+        then
+            echo "Problem w/ eNB and UE not syncing"
+            terminate_enb_ue_basic_sim $VM_CMDS $VM_IP_ADDR
+            scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
+            scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_UE_LOG_FILE $ARCHIVES_LOC
+            recover_core_dump $VM_CMDS $VM_IP_ADDR $ARCHIVES_LOC/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
+            terminate_epc $EPC_VM_CMDS $EPC_VM_IP_ADDR
+            echo "TEST_KO" > $ARCHIVES_LOC/test_final_status.log
+            exit -1
+        fi
+        get_ue_ip_addr $VM_CMDS $VM_IP_ADDR
+
+        echo "############################################################"
+        echo "Pinging the UE"
+        echo "############################################################"
+        PING_LOG_FILE=tdd_05MHz_ping_ue.txt
+        ping_ue_ip_addr $EPC_VM_CMDS $EPC_VM_IP_ADDR $UE_IP_ADDR $PING_LOG_FILE
+        scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/$PING_LOG_FILE $ARCHIVES_LOC
+        check_ping_result $ARCHIVES_LOC/$PING_LOG_FILE 20
+
+#        Bug in TDD 5Mhz --- not running it
+#        echo "############################################################"
+#        echo "Iperf DL"
+#        echo "############################################################"
+#        CURR_IPERF_LOG_BASE=tdd_05MHz_iperf_dl
+#        iperf_dl $VM_CMDS $VM_IP_ADDR $EPC_VM_CMDS $EPC_VM_IP_ADDR 6 $CURR_IPERF_LOG_BASE
+#        scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/${CURR_IPERF_LOG_BASE}_client.txt $ARCHIVES_LOC
+#        scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/${CURR_IPERF_LOG_BASE}_server.txt $ARCHIVES_LOC
+#        check_iperf $ARCHIVES_LOC/$CURR_IPERF_LOG_BASE 6
+
+        echo "############################################################"
+        echo "Terminate enb/ue simulators"
+        echo "############################################################"
         terminate_enb_ue_basic_sim $VM_CMDS $VM_IP_ADDR
         scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
         scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_UE_LOG_FILE $ARCHIVES_LOC
         recover_core_dump $VM_CMDS $VM_IP_ADDR $ARCHIVES_LOC/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
-        terminate_ltebox_epc $EPC_VM_CMDS $EPC_VM_IP_ADDR
-        exit -1
-    fi
-    get_ue_ip_addr $VM_CMDS $VM_IP_ADDR
+        sleep 10
 
-    echo "############################################################"
-    echo "Pinging the UE"
-    echo "############################################################"
-    PING_LOG_FILE=tdd_10MHz_ping_ue.txt
-    ping_ue_ip_addr $EPC_VM_CMDS $EPC_VM_IP_ADDR $UE_IP_ADDR $PING_LOG_FILE
-    scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/$PING_LOG_FILE $ARCHIVES_LOC
-    check_ping_result $ARCHIVES_LOC/$PING_LOG_FILE 20
+        echo "############################################################"
+        echo "Starting the eNB in TDD-10MHz mode"
+        echo "############################################################"
+        CURRENT_ENB_LOG_FILE=tdd_10MHz_enb.log
+        start_basic_sim_enb $VM_CMDS $VM_IP_ADDR $EPC_VM_IP_ADDR $CURRENT_ENB_LOG_FILE 50 lte-tdd-basic-sim.conf none
 
-    echo "############################################################"
-    echo "Iperf DL"
-    echo "############################################################"
-    CURR_IPERF_LOG_BASE=tdd_10MHz_iperf_dl
-    iperf_dl $VM_CMDS $VM_IP_ADDR $EPC_VM_CMDS $EPC_VM_IP_ADDR 6 $CURR_IPERF_LOG_BASE
-    scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/${CURR_IPERF_LOG_BASE}_client.txt $ARCHIVES_LOC
-    scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/${CURR_IPERF_LOG_BASE}_server.txt $ARCHIVES_LOC
-    check_iperf $ARCHIVES_LOC/$CURR_IPERF_LOG_BASE 6
+        echo "############################################################"
+        echo "Starting the UE in TDD-10MHz mode"
+        echo "############################################################"
+        CURRENT_UE_LOG_FILE=tdd_10MHz_ue.log
+        start_basic_sim_ue $VM_CMDS $VM_IP_ADDR $CURRENT_UE_LOG_FILE 50 2350
+        if [ $UE_SYNC -eq 0 ]
+        then
+            echo "Problem w/ eNB and UE not syncing"
+            terminate_enb_ue_basic_sim $VM_CMDS $VM_IP_ADDR
+            scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
+            scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_UE_LOG_FILE $ARCHIVES_LOC
+            recover_core_dump $VM_CMDS $VM_IP_ADDR $ARCHIVES_LOC/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
+            terminate_epc $EPC_VM_CMDS $EPC_VM_IP_ADDR
+            echo "TEST_KO" > $ARCHIVES_LOC/test_final_status.log
+            exit -1
+        fi
+        get_ue_ip_addr $VM_CMDS $VM_IP_ADDR
 
-    echo "############################################################"
-    echo "Terminate enb/ue simulators"
-    echo "############################################################"
-    terminate_enb_ue_basic_sim $VM_CMDS $VM_IP_ADDR
-    scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
-    scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_UE_LOG_FILE $ARCHIVES_LOC
-    recover_core_dump $VM_CMDS $VM_IP_ADDR $ARCHIVES_LOC/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
+        echo "############################################################"
+        echo "Pinging the UE"
+        echo "############################################################"
+        PING_LOG_FILE=tdd_10MHz_ping_ue.txt
+        ping_ue_ip_addr $EPC_VM_CMDS $EPC_VM_IP_ADDR $UE_IP_ADDR $PING_LOG_FILE
+        scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/$PING_LOG_FILE $ARCHIVES_LOC
+        check_ping_result $ARCHIVES_LOC/$PING_LOG_FILE 20
 
-# Disabling TDD-20MHz test since it is very unstable
+        echo "############################################################"
+        echo "Iperf DL"
+        echo "############################################################"
+        CURR_IPERF_LOG_BASE=tdd_10MHz_iperf_dl
+        iperf_dl $VM_CMDS $VM_IP_ADDR $EPC_VM_CMDS $EPC_VM_IP_ADDR 6 $CURR_IPERF_LOG_BASE
+        scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/${CURR_IPERF_LOG_BASE}_client.txt $ARCHIVES_LOC
+        scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/${CURR_IPERF_LOG_BASE}_server.txt $ARCHIVES_LOC
+        check_iperf $ARCHIVES_LOC/$CURR_IPERF_LOG_BASE 6
+
+        echo "############################################################"
+        echo "Terminate enb/ue simulators"
+        echo "############################################################"
+        terminate_enb_ue_basic_sim $VM_CMDS $VM_IP_ADDR
+        scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
+        scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_UE_LOG_FILE $ARCHIVES_LOC
+        recover_core_dump $VM_CMDS $VM_IP_ADDR $ARCHIVES_LOC/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
+        sleep 10
+
+# Disabling TDD-20MHz in order to stop getting false negatives
+#        echo "############################################################"
+#        echo "Starting the eNB in TDD-20MHz mode"
+#        echo "############################################################"
+#        CURRENT_ENB_LOG_FILE=tdd_20MHz_enb.log
+#        start_basic_sim_enb $VM_CMDS $VM_IP_ADDR $EPC_VM_IP_ADDR $CURRENT_ENB_LOG_FILE 100 lte-tdd-basic-sim.conf none
 #
-#    echo "############################################################"
-#    echo "Starting the eNB in TDD-20MHz mode"
-#    echo "############################################################"
-#    CURRENT_ENB_LOG_FILE=tdd_20MHz_enb.log
-#    start_basic_sim_enb $VM_CMDS $VM_IP_ADDR $EPC_VM_IP_ADDR $CURRENT_ENB_LOG_FILE 100 lte-tdd-basic-sim.conf
+#        echo "############################################################"
+#        echo "Starting the UE in TDD-20MHz mode"
+#        echo "############################################################"
+#        CURRENT_UE_LOG_FILE=tdd_20MHz_ue.log
+#        start_basic_sim_ue $VM_CMDS $VM_IP_ADDR $CURRENT_UE_LOG_FILE 100 2350
+#        if [ $UE_SYNC -eq 0 ]
+#        then
+#            echo "Problem w/ eNB and UE not syncing"
+#            terminate_enb_ue_basic_sim $VM_CMDS $VM_IP_ADDR
+#            scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
+#            scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_UE_LOG_FILE $ARCHIVES_LOC
+#            recover_core_dump $VM_CMDS $VM_IP_ADDR $ARCHIVES_LOC/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
+#            terminate_epc $EPC_VM_CMDS $EPC_VM_IP_ADDR
+#            echo "TEST_KO" > $ARCHIVES_LOC/test_final_status.log
+#            exit -1
+#        fi
+#        get_ue_ip_addr $VM_CMDS $VM_IP_ADDR
 #
-#    echo "############################################################"
-#    echo "Starting the UE in TDD-20MHz mode"
-#    echo "############################################################"
-#    CURRENT_UE_LOG_FILE=tdd_20MHz_ue.log
-#    start_basic_sim_ue $VM_CMDS $VM_IP_ADDR $CURRENT_UE_LOG_FILE 100 2350
-#    if [ $UE_SYNC -eq 0 ]
-#    then
-#        echo "Problem w/ eNB and UE not syncing"
+#        echo "############################################################"
+#        echo "Pinging the UE"
+#        echo "############################################################"
+#        PING_LOG_FILE=tdd_20MHz_ping_ue.txt
+#        ping_ue_ip_addr $EPC_VM_CMDS $EPC_VM_IP_ADDR $UE_IP_ADDR $PING_LOG_FILE
+#        scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/$PING_LOG_FILE $ARCHIVES_LOC
+#        check_ping_result $ARCHIVES_LOC/$PING_LOG_FILE 20
+#
+#        echo "############################################################"
+#        echo "Iperf DL"
+#        echo "############################################################"
+#        CURR_IPERF_LOG_BASE=tdd_20MHz_iperf_dl
+#        iperf_dl $VM_CMDS $VM_IP_ADDR $EPC_VM_CMDS $EPC_VM_IP_ADDR 6 $CURR_IPERF_LOG_BASE
+#        scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/${CURR_IPERF_LOG_BASE}_client.txt $ARCHIVES_LOC
+#        scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/${CURR_IPERF_LOG_BASE}_server.txt $ARCHIVES_LOC
+#        check_iperf $ARCHIVES_LOC/$CURR_IPERF_LOG_BASE 6
+#
+#        echo "############################################################"
+#        echo "Terminate enb/ue simulators"
+#        echo "############################################################"
 #        terminate_enb_ue_basic_sim $VM_CMDS $VM_IP_ADDR
 #        scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
 #        scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_UE_LOG_FILE $ARCHIVES_LOC
 #        recover_core_dump $VM_CMDS $VM_IP_ADDR $ARCHIVES_LOC/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
-#        terminate_ltebox_epc $EPC_VM_CMDS $EPC_VM_IP_ADDR
-#        exit -1
-#    fi
-#    get_ue_ip_addr $VM_CMDS $VM_IP_ADDR
-#
-#    echo "############################################################"
-#    echo "Pinging the UE"
-#    echo "############################################################"
-#    PING_LOG_FILE=tdd_20MHz_ping_ue.txt
-#    ping_ue_ip_addr $EPC_VM_CMDS $EPC_VM_IP_ADDR $UE_IP_ADDR $PING_LOG_FILE
-#    scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/$PING_LOG_FILE $ARCHIVES_LOC
-#    check_ping_result $ARCHIVES_LOC/$PING_LOG_FILE 20
-#
-#    echo "############################################################"
-#    echo "Iperf DL"
-#    echo "############################################################"
-#    CURR_IPERF_LOG_BASE=tdd_20MHz_iperf_dl
-#    iperf_dl $VM_CMDS $VM_IP_ADDR $EPC_VM_CMDS $EPC_VM_IP_ADDR 6 $CURR_IPERF_LOG_BASE
-#    scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/${CURR_IPERF_LOG_BASE}_client.txt $ARCHIVES_LOC
-#    scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/${CURR_IPERF_LOG_BASE}_server.txt $ARCHIVES_LOC
-#    check_iperf $ARCHIVES_LOC/$CURR_IPERF_LOG_BASE 6
-#
-#    echo "############################################################"
-#    echo "Terminate enb/ue simulators"
-#    echo "############################################################"
-#    terminate_enb_ue_basic_sim $VM_CMDS $VM_IP_ADDR
-#    scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
-#    scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_UE_LOG_FILE $ARCHIVES_LOC
-#    recover_core_dump $VM_CMDS $VM_IP_ADDR $ARCHIVES_LOC/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
+#        sleep 10
 
-    echo "############################################################"
-    echo "Terminate EPC"
-    echo "############################################################"
+        echo "############################################################"
+        echo "Terminate EPC"
+        echo "############################################################"
 
-    if [ $LTEBOX -eq 1 ]
-    then
-        terminate_ltebox_epc $EPC_VM_CMDS $EPC_VM_IP_ADDR
+        terminate_epc $EPC_VM_CMDS $EPC_VM_IP_ADDR
+
+        if [ $KEEP_VM_ALIVE -eq 0 ]
+        then
+            echo "############################################################"
+            echo "Destroying VMs"
+            echo "############################################################"
+            uvt-kvm destroy $VM_NAME
+            ssh-keygen -R $VM_IP_ADDR
+            uvt-kvm destroy $EPC_VM_NAME
+            ssh-keygen -R $EPC_VM_IP_ADDR
+            if [ -e $JENKINS_WKSP/flexran/flexran_build_complete.txt ]
+            then
+                uvt-kvm destroy $FLEXRAN_CTL_VM_NAME
+                ssh-keygen -R $FLEXRAN_CTL_VM_IP_ADDR
+            fi
+        fi
+
+        echo "############################################################"
+        echo "Checking run status"
+        echo "############################################################"
+
+        if [ $PING_STATUS -ne 0 ]; then STATUS=-1; fi
+        if [ $IPERF_STATUS -ne 0 ]; then STATUS=-1; fi
+
+        if [ $STATUS -eq 0 ]
+        then
+            echo "TEST_OK" > $ARCHIVES_LOC/test_final_status.log
+        else
+            echo "TEST_KO" > $ARCHIVES_LOC/test_final_status.log
+        fi
     fi
 
-    echo "############################################################"
-    echo "Checking run status"
-    echo "############################################################"
+    if [[ "$RUN_OPTIONS" == "complex" ]] && [[ $VM_NAME =~ .*-l2-sim.* ]]
+    then
+        PING_STATUS=0
+        IPERF_STATUS=0
+        if [ -d $ARCHIVES_LOC ]
+        then
+            rm -Rf $ARCHIVES_LOC
+        fi
+        mkdir --parents $ARCHIVES_LOC
+
+        # Building UE elsewhere in VM
+        build_ue_on_separate_folder $VM_CMDS $VM_IP_ADDR
 
-    if [ $PING_STATUS -ne 0 ]; then STATUS=-1; fi
-    if [ $IPERF_STATUS -ne 0 ]; then STATUS=-1; fi
+        # Creating a VM for EPC and installing SW
+        EPC_VM_NAME=`echo $VM_NAME | sed -e "s#l2-sim#l2-epc#"`
+        EPC_VM_CMDS=${EPC_VM_NAME}_cmds.txt
+        LTEBOX=0
+        install_epc_on_vm $EPC_VM_NAME $EPC_VM_CMDS
+        EPC_VM_IP_ADDR=`uvt-kvm ip $EPC_VM_NAME`
 
-fi
+        # Starting EPC
+        start_epc $EPC_VM_NAME $EPC_VM_CMDS $EPC_VM_IP_ADDR
 
-if [ $STATUS -eq 0 ]
-then
-    echo "STATUS seems OK"
-else
-    echo "STATUS failed?"
-fi
+        # Retrieve EPC real IP address
+        retrieve_real_epc_ip_addr $EPC_VM_NAME $EPC_VM_CMDS $EPC_VM_IP_ADDR
 
-exit $STATUS
+        echo "############################################################"
+        echo "Starting the eNB in FDD-5MHz mode"
+        echo "############################################################"
+        CURRENT_ENB_LOG_FILE=fdd_05MHz_enb.log
+        start_l2_sim_enb $VM_CMDS $VM_IP_ADDR $EPC_VM_IP_ADDR $CURRENT_ENB_LOG_FILE 25 rcc.band7.tm1.nfapi.conf
+
+        echo "############################################################"
+        echo "Starting the UEs"
+        echo "############################################################"
+        CURRENT_UE_LOG_FILE=fdd_05MHz_ue.log
+        start_l2_sim_ue $VM_CMDS $VM_IP_ADDR $CURRENT_UE_LOG_FILE ue.nfapi.conf
+        if [ $UE_SYNC -eq 0 ]
+        then
+            echo "Problem w/ eNB and UE not syncing"
+            terminate_enb_ue_basic_sim $VM_CMDS $VM_IP_ADDR
+            scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
+            scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_UE_LOG_FILE $ARCHIVES_LOC
+            terminate_epc $EPC_VM_CMDS $EPC_VM_IP_ADDR
+            echo "TEST_KO" > $ARCHIVES_LOC/test_final_status.log
+            exit -1
+        fi
+
+        echo "############################################################"
+        echo "Pinging the EPC from UE"
+        echo "############################################################"
+        PING_LOG_FILE=fdd_05MHz_ping_epc.txt
+        ping_epc_ip_addr $VM_CMDS $VM_IP_ADDR $REAL_EPC_IP_ADDR $PING_LOG_FILE
+        scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/$PING_LOG_FILE $ARCHIVES_LOC
+        check_ping_result $ARCHIVES_LOC/$PING_LOG_FILE 20
+
+        echo "############################################################"
+        echo "Terminate enb/ue simulators"
+        echo "############################################################"
+        terminate_enb_ue_basic_sim $VM_CMDS $VM_IP_ADDR
+        scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_ENB_LOG_FILE $ARCHIVES_LOC
+        scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/$CURRENT_UE_LOG_FILE $ARCHIVES_LOC
+
+        echo "############################################################"
+        echo "Terminate EPC"
+        echo "############################################################"
+
+        terminate_epc $EPC_VM_CMDS $EPC_VM_IP_ADDR
+
+        if [ $KEEP_VM_ALIVE -eq 0 ]
+        then
+            echo "############################################################"
+            echo "Destroying VMs"
+            echo "############################################################"
+            uvt-kvm destroy $VM_NAME
+            ssh-keygen -R $VM_IP_ADDR
+            uvt-kvm destroy $EPC_VM_NAME
+            ssh-keygen -R $EPC_VM_IP_ADDR
+        fi
+
+        echo "############################################################"
+        echo "Checking run status"
+        echo "############################################################"
+
+        if [ $PING_STATUS -ne 0 ]; then STATUS=-1; fi
+        if [ $STATUS -eq 0 ]
+        then
+            echo "TEST_OK" > $ARCHIVES_LOC/test_final_status.log
+        else
+            echo "TEST_KO" > $ARCHIVES_LOC/test_final_status.log
+        fi
+    fi
+}
diff --git a/ci-scripts/tcp_iperf_stats.awk b/ci-scripts/tcp_iperf_stats.awk
index e5c64b628353635412f0824a52a83f2f1736c00e..3a00e4555f744fa8cf2ce87c9baad3067ddc3bc1 100644
--- a/ci-scripts/tcp_iperf_stats.awk
+++ b/ci-scripts/tcp_iperf_stats.awk
@@ -1,3 +1,23 @@
+#/*
+# * 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
+# */
 BEGIN{max=0;min=10000}
 {
     if ($0 ~/Mbits/) {
diff --git a/ci-scripts/waitBuildOnVM.sh b/ci-scripts/waitBuildOnVM.sh
new file mode 100755
index 0000000000000000000000000000000000000000..3969e895af047ce6fa606a822e9da1a60a58df5b
--- /dev/null
+++ b/ci-scripts/waitBuildOnVM.sh
@@ -0,0 +1,194 @@
+#!/bin/bash
+#/*
+# * 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
+# */
+
+function wait_usage {
+    echo "OAI CI VM script"
+    echo "   Original Author: Raphael Defosseux"
+    echo "   Requirements:"
+    echo "     -- uvtool uvtool-libvirt apt-cacher"
+    echo "     -- xenial image already synced"
+    echo "   Default:"
+    echo "     -- eNB with USRP"
+    echo ""
+    echo "Usage:"
+    echo "------"
+    echo "    oai-ci-vm-tool wait [OPTIONS]"
+    echo ""
+    echo "Mandatory Options:"
+    echo "--------"
+    echo "    --job-name #### OR -jn ####"
+    echo "    Specify the name of the Jenkins job."
+    echo ""
+    echo "    --build-id #### OR -id ####"
+    echo "    Specify the build ID of the Jenkins job."
+    echo ""
+    echo "    --workspace #### OR -ws ####"
+    echo "    Specify the workspace."
+    echo ""
+    variant_usage
+    echo "    Specify the variant to build."
+    echo ""
+    echo "Options:"
+    echo "--------"
+    echo "    --keep-vm-alive OR -k"
+    echo "    Keep the VM alive after the build."
+    echo ""
+    echo "    --help OR -h"
+    echo "    Print this help message."
+    echo ""
+}
+
+function wait_on_vm_build {
+    echo "############################################################"
+    echo "OAI CI VM script"
+    echo "############################################################"
+
+    echo "VM_NAME             = $VM_NAME"
+    echo "VM_CMD_FILE         = $VM_CMDS"
+    echo "JENKINS_WKSP        = $JENKINS_WKSP"
+    echo "ARCHIVES_LOC        = $ARCHIVES_LOC"
+    echo "BUILD_OPTIONS       = $BUILD_OPTIONS"
+
+    IS_VM_ALIVE=`uvt-kvm list | grep -c $VM_NAME`
+
+    if [ $IS_VM_ALIVE -eq 0 ]
+    then
+        echo "############################################################"
+        echo "You should have created the VM before doing anything"
+        echo "############################################################"
+        STATUS=1
+        return
+    fi
+
+    echo "Waiting for VM to be started"
+    uvt-kvm wait $VM_NAME --insecure
+
+    VM_IP_ADDR=`uvt-kvm ip $VM_NAME`
+    echo "$VM_NAME has for IP addr = $VM_IP_ADDR"
+
+    echo "############################################################"
+    echo "Waiting build process to end on VM ($VM_NAME)"
+    echo "############################################################"
+
+    if [[ "$VM_NAME" == *"-cppcheck"* ]]
+    then
+        echo "echo \"ps -aux | grep cppcheck \"" >> $VM_CMDS
+        echo "while [ \$(ps -aux | grep --color=never cppcheck | grep -v grep | wc -l) -gt 0 ]; do sleep 3; done" >> $VM_CMDS
+    else
+        echo "echo \"ps -aux | grep build \"" >> $VM_CMDS
+        echo "while [ \$(ps -aux | grep --color=never build_oai | grep -v grep | wc -l) -gt 0 ]; do sleep 3; done" >> $VM_CMDS
+    fi
+
+    ssh -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR < $VM_CMDS
+    rm -f $VM_CMDS
+}
+
+function check_on_vm_build {
+    echo "############################################################"
+    echo "Creating a tmp folder to store results and artifacts"
+    echo "############################################################"
+    if [ ! -d $JENKINS_WKSP/archives ]
+    then
+        mkdir $JENKINS_WKSP/archives
+    fi
+
+    if [ ! -d $ARCHIVES_LOC ]
+    then
+        mkdir $ARCHIVES_LOC
+    fi
+
+    scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/*.txt $ARCHIVES_LOC
+    if [[ "$VM_NAME" == *"-cppcheck"* ]]
+    then
+        scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/*.xml $ARCHIVES_LOC
+    fi
+
+    if [ $KEEP_VM_ALIVE -eq 0 ]
+    then
+        echo "############################################################"
+        echo "Destroying VM"
+        echo "############################################################"
+        uvt-kvm destroy $VM_NAME
+        ssh-keygen -R $VM_IP_ADDR
+    fi
+    rm -f $VM_CMDS
+
+    echo "############################################################"
+    echo "Checking build status"
+    echo "############################################################"
+
+    if [[ "$VM_NAME" == *"-cppcheck"* ]]
+    then
+        LOG_FILES=`ls $ARCHIVES_LOC/*.txt $ARCHIVES_LOC/*.xml`
+    else
+        LOG_FILES=`ls $ARCHIVES_LOC/*.txt`
+    fi
+    STATUS=0
+    NB_FOUND_FILES=0
+
+    for FULLFILE in $LOG_FILES
+    do
+        if [[ $FULLFILE == *"$LOG_PATTERN"* ]]
+        then
+            filename=$(basename -- "$FULLFILE")
+            if [ "$LOG_PATTERN" == ".Rel14.txt" ]
+            then
+                PASS_PATTERN=`echo $filename | sed -e "s#$LOG_PATTERN##"`
+            fi
+            if [ "$LOG_PATTERN" == "basic_simulator" ]
+            then
+                PASS_PATTERN="lte-"
+            fi
+            if [ "$LOG_PATTERN" == "cppcheck.xml" ]
+            then
+                PASS_PATTERN="results version"
+                LOCAL_STAT=`egrep -c "$PASS_PATTERN" $FULLFILE`
+            else
+                LOCAL_STAT=`egrep -c "Built target $PASS_PATTERN" $FULLFILE`
+            fi
+            if [ $LOCAL_STAT -eq 0 ]; then STATUS=-1; fi
+            NB_FOUND_FILES=$((NB_FOUND_FILES + 1))
+        fi
+    done
+
+    if [ $NB_PATTERN_FILES -ne $NB_FOUND_FILES ]
+    then
+        echo "Expecting $NB_PATTERN_FILES log files and found $NB_FOUND_FILES"
+        STATUS=-1
+    fi
+
+    # If we were building the FlexRan Controller, flag-touch for basic-simulator to continue
+    if [[ "$VM_NAME" == *"-flexran-rtc"* ]]
+    then
+        if [[ $STATUS -eq 0 ]]
+        then
+            touch $JENKINS_WKSP/flexran/flexran_build_complete.txt
+        fi
+    fi
+
+    if [[ $STATUS -eq 0 ]]
+    then
+        echo "BUILD_OK" > $ARCHIVES_LOC/build_final_status.log
+    else
+        echo "BUILD_KO" > $ARCHIVES_LOC/build_final_status.log
+    fi
+}
diff --git a/ci-scripts/xml_files/enb_usrp210_band40_build.xml b/ci-scripts/xml_files/enb_usrp210_band40_build.xml
new file mode 100644
index 0000000000000000000000000000000000000000..8f9489b03e609a6fbadb56419bc676d8f51c1056
--- /dev/null
+++ b/ci-scripts/xml_files/enb_usrp210_band40_build.xml
@@ -0,0 +1,54 @@
+<!--
+
+ 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_band40_epc_closure.xml b/ci-scripts/xml_files/enb_usrp210_band40_epc_closure.xml
new file mode 100644
index 0000000000000000000000000000000000000000..ad34381a2a06ac89431e928a07310462e3cc52c4
--- /dev/null
+++ b/ci-scripts/xml_files/enb_usrp210_band40_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_band40_test_05mhz_tm1.xml b/ci-scripts/xml_files/enb_usrp210_band40_test_05mhz_tm1.xml
new file mode 100644
index 0000000000000000000000000000000000000000..d5a25c7fa7367f1791cf6657d4dfe6df2ca579aa
--- /dev/null
+++ b/ci-scripts/xml_files/enb_usrp210_band40_test_05mhz_tm1.xml
@@ -0,0 +1,119 @@
+<!--
+
+ 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-05-tm1</htmlTabRef>
+	<htmlTabName>Test-05MHz-TM1</htmlTabName>
+	<htmlTabIcon>tasks</htmlTabIcon>
+        <TestCaseRequestedList>
+ 040101
+ 030104 040301 040501 040602 040601 040603 040642 040641 040643 040401 040201 030201
+	</TestCaseRequestedList>
+	<TestCaseExclusionList></TestCaseExclusionList>
+
+	<testCase id="030104">
+		<class>Initialize_eNB</class>
+		<desc>Initialize eNB (TDD/Band40/5MHz)</desc>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band40.tm1.25PRB.FairScheduler.usrpb210.conf</Initialize_eNB_args>
+	</testCase>
+
+	<testCase id="030201">
+		<class>Terminate_eNB</class>
+		<desc>Terminate eNB</desc>
+	</testCase>
+
+	<testCase id="040101">
+		<class>Initialize_UE</class>
+		<desc>Initialize UE</desc>
+	</testCase>
+
+	<testCase id="040201">
+		<class>Terminate_UE</class>
+		<desc>Terminate UE</desc>
+	</testCase>
+
+        <testCase id="040301">
+                <class>Attach_UE</class>
+                <desc>Attach UE</desc>
+        </testCase>
+
+        <testCase id="040401">
+                <class>Detach_UE</class>
+                <desc>Detach UE</desc>
+        </testCase>
+
+        <testCase id="040501">
+                <class>Ping</class>
+                <desc>ping (5MHz - 20 sec)</desc>
+                <ping_args>-c 20</ping_args>
+                <ping_packetloss_threshold>25</ping_packetloss_threshold>
+        </testCase>
+
+        <testCase id="040601">
+		<class>Iperf</class>
+		<desc>iperf (5MHz - DL/6.5Mbps/UDP)(30 sec)(balanced)</desc>
+		<iperf_args>-u -b 6.5M -t 30 -i 1</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>balanced</iperf_profile>
+        </testCase>
+
+        <testCase id="040602">
+		<class>Iperf</class>
+		<desc>iperf (5MHz - DL/6.5Mbps/UDP)(30 sec)(single-ue)</desc>
+		<iperf_args>-u -b 6.5M -t 30 -i 1</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>single-ue</iperf_profile>
+        </testCase>
+
+        <testCase id="040603">
+		<class>Iperf</class>
+		<desc>iperf (5MHz - DL/6.5Mbps/UDP)(30 sec)(unbalanced)</desc>
+		<iperf_args>-u -b 6.5M -t 30 -i 1</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>unbalanced</iperf_profile>
+        </testCase>
+
+	<testCase id="040641">
+		<class>Iperf</class>
+		<desc>iperf (5MHz - UL/2Mbps/UDP)(30 sec)(balanced)</desc>
+		<iperf_args>-u -b 2M -t 30 -i 1 -R</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>balanced</iperf_profile>
+	</testCase>
+
+	<testCase id="040642">
+		<class>Iperf</class>
+		<desc>iperf (5MHz - UL/2Mbps/UDP)(30 sec)(single-ue)</desc>
+		<iperf_args>-u -b 2M -t 30 -i 1 -R</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>single-ue</iperf_profile>
+	</testCase>
+
+	<testCase id="040643">
+		<class>Iperf</class>
+		<desc>iperf (5MHz - UL/2Mbps/UDP)(30 sec)(unbalanced)</desc>
+		<iperf_args>-u -b 2M -t 30 -i 1 -R</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>unbalanced</iperf_profile>
+	</testCase>
+
+</testCaseList>
diff --git a/ci-scripts/xml_files/enb_usrpb210_band40.xml b/ci-scripts/xml_files/enb_usrp210_band40_test_10mhz_tm1.xml
similarity index 51%
rename from ci-scripts/xml_files/enb_usrpb210_band40.xml
rename to ci-scripts/xml_files/enb_usrp210_band40_test_10mhz_tm1.xml
index 1af1c319cfe4eaf6d8c7d60eafd4019ae130e5ab..ef50933d4a1205e7cc0145073ad747b4d39333ca 100644
--- a/ci-scripts/xml_files/enb_usrpb210_band40.xml
+++ b/ci-scripts/xml_files/enb_usrp210_band40_test_10mhz_tm1.xml
@@ -21,43 +21,21 @@
 
 -->
 <testCaseList>
+	<htmlTabRef>test-10-tm1</htmlTabRef>
+	<htmlTabName>Test-10MHz-TM1</htmlTabName>
+	<htmlTabIcon>tasks</htmlTabIcon>
         <TestCaseRequestedList>
- 010101
- 050101 060101 070101 040101
- 030104 040301 040501 040602 040601 040603 040642 040641 040643 040401 040201 030201
+ 040101
  030114 040301 040511 040612 040611 040613 040652 040651 040653 040401 040201 030201
- 050201 060201 070201
 	</TestCaseRequestedList>
-	<!-- 20MHz is not stable enough to be run -->
-	<!--
- 030124 040301 040521 040622 040621 040623 040662 040661 040663 040401 040201 030201
-	-->
 	<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="030104">
-		<class>Initialize_eNB</class>
-		<desc>Initialize eNB (TDD/Band40/5MHz)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band40.tm1.25PRB.FairScheduler.usrpb210.conf --codingw --fepw</Initialize_eNB_args>
-	</testCase>
-	
 	<testCase id="030114">
                 <class>Initialize_eNB</class>
                 <desc>Initialize eNB (TDD/Band40/10MHz/info)</desc>
-                <Initialize_eNB_args>-O ci-scripts/conf_files/enb.band40.tm1.50PRB.FairScheduler.usrpb210.conf --codingw --fepw</Initialize_eNB_args>
+                <Initialize_eNB_args>-O ci-scripts/conf_files/enb.band40.tm1.50PRB.FairScheduler.usrpb210.conf</Initialize_eNB_args>
         </testCase>
 
-	<testCase id="030106">
-		<class>Initialize_eNB</class>
-		<desc>Initialize eNB (TDD/Band40/20MHz/info)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band40.tm1.100PRB.FairScheduler.usrpb210.conf --codingw --fepw</Initialize_eNB_args>
-	</testCase>
-
 	<testCase id="030201">
 		<class>Terminate_eNB</class>
 		<desc>Terminate eNB</desc>
@@ -83,13 +61,6 @@
                 <desc>Detach UE</desc>
         </testCase>
 
-        <testCase id="040501">
-                <class>Ping</class>
-                <desc>ping (5MHz - 20 sec)</desc>
-                <ping_args>-c 20</ping_args>
-                <ping_packetloss_threshold>25</ping_packetloss_threshold>
-        </testCase>
-
         <testCase id="040511">
                 <class>Ping</class>
                 <desc>ping (10MHz - 20 sec)</desc>
@@ -97,30 +68,6 @@
                 <ping_packetloss_threshold>25</ping_packetloss_threshold>
         </testCase>
 
-        <testCase id="040601">
-		<class>Iperf</class>
-		<desc>iperf (5MHz - DL/6.5Mbps/UDP)(30 sec)(balanced)</desc>
-		<iperf_args>-u -b 6.5M -t 30 -i 1</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>balanced</iperf_profile>
-        </testCase>
-
-        <testCase id="040602">
-		<class>Iperf</class>
-		<desc>iperf (5MHz - DL/6.5Mbps/UDP)(30 sec)(single-ue)</desc>
-		<iperf_args>-u -b 6.5M -t 30 -i 1</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>single-ue</iperf_profile>
-        </testCase>
-
-        <testCase id="040603">
-		<class>Iperf</class>
-		<desc>iperf (5MHz - DL/6.5Mbps/UDP)(30 sec)(unbalanced)</desc>
-		<iperf_args>-u -b 6.5M -t 30 -i 1</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>unbalanced</iperf_profile>
-        </testCase>
-
 	<testCase id="040611">
                 <class>Iperf</class>
                 <desc>iperf (10MHz - DL/13.5Mbps/UDP)(30 sec)(balanced)</desc>
@@ -145,30 +92,6 @@
 		<iperf_profile>unbalanced</iperf_profile>
 	</testCase>
 
-	<testCase id="040641">
-		<class>Iperf</class>
-		<desc>iperf (5MHz - UL/2Mbps/UDP)(30 sec)(balanced)</desc>
-		<iperf_args>-u -b 2M -t 30 -i 1 -R</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>balanced</iperf_profile>
-	</testCase>
-
-	<testCase id="040642">
-		<class>Iperf</class>
-		<desc>iperf (5MHz - UL/2Mbps/UDP)(30 sec)(single-ue)</desc>
-		<iperf_args>-u -b 2M -t 30 -i 1 -R</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>single-ue</iperf_profile>
-	</testCase>
-
-	<testCase id="040643">
-		<class>Iperf</class>
-		<desc>iperf (5MHz - UL/2Mbps/UDP)(30 sec)(unbalanced)</desc>
-		<iperf_args>-u -b 2M -t 30 -i 1 -R</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>unbalanced</iperf_profile>
-	</testCase>
-
 	<testCase id="040651">
 		<class>Iperf</class>
 		<desc>iperf (10MHz - UL/2Mbps/UDP)(30 sec)(balanced)</desc>
@@ -193,34 +116,4 @@
 		<iperf_profile>unbalanced</iperf_profile>
 	</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>
-
-        <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_band40_test_20mhz_tm1.xml b/ci-scripts/xml_files/enb_usrp210_band40_test_20mhz_tm1.xml
new file mode 100644
index 0000000000000000000000000000000000000000..9a96baac3fd87602bff9f77085df0b3c69628b75
--- /dev/null
+++ b/ci-scripts/xml_files/enb_usrp210_band40_test_20mhz_tm1.xml
@@ -0,0 +1,119 @@
+<!--
+
+ 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-20-tm1</htmlTabRef>
+	<htmlTabName>Test-20MHz-TM1</htmlTabName>
+	<htmlTabIcon>tasks</htmlTabIcon>
+        <TestCaseRequestedList>
+ 040101
+ 030124 040301 040521 040622 040621 040623 040662 040661 040663 040401 040201 030201
+	</TestCaseRequestedList>
+	<TestCaseExclusionList></TestCaseExclusionList>
+
+	<testCase id="030124">
+                <class>Initialize_eNB</class>
+                <desc>Initialize eNB (TDD/Band40/20MHz/info)</desc>
+                <Initialize_eNB_args>-O ci-scripts/conf_files/enb.band40.tm1.100PRB.FairScheduler.usrpb210.conf</Initialize_eNB_args>
+        </testCase>
+
+	<testCase id="030201">
+		<class>Terminate_eNB</class>
+		<desc>Terminate eNB</desc>
+	</testCase>
+
+	<testCase id="040101">
+		<class>Initialize_UE</class>
+		<desc>Initialize UE</desc>
+	</testCase>
+
+	<testCase id="040201">
+		<class>Terminate_UE</class>
+		<desc>Terminate UE</desc>
+	</testCase>
+
+        <testCase id="040301">
+                <class>Attach_UE</class>
+                <desc>Attach UE</desc>
+        </testCase>
+
+        <testCase id="040401">
+                <class>Detach_UE</class>
+                <desc>Detach UE</desc>
+        </testCase>
+
+        <testCase id="040521">
+                <class>Ping</class>
+                <desc>ping (20MHz - 20 sec)</desc>
+                <ping_args>-c 20</ping_args>
+                <ping_packetloss_threshold>25</ping_packetloss_threshold>
+        </testCase>
+
+	<testCase id="040621">
+                <class>Iperf</class>
+                <desc>iperf (20MHz - DL/13.5Mbps/UDP)(30 sec)(balanced)</desc>
+                <iperf_args>-u -b 13.5M -t 30 -i 1</iperf_args>
+                <iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+                <iperf_profile>balanced</iperf_profile>
+        </testCase>
+
+        <testCase id="040622">
+                <class>Iperf</class>
+                <desc>iperf (20MHz - DL/13.5Mbps/UDP)(30 sec)(single-ue)</desc>
+                <iperf_args>-u -b 13.5M -t 30 -i 1</iperf_args>
+                <iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+                <iperf_profile>single-ue</iperf_profile>
+        </testCase>
+
+	<testCase id="040623">
+		<class>Iperf</class>
+		<desc>iperf (20MHz - DL/13.5Mbps/UDP)(30 sec)(unbalanced)</desc>
+		<iperf_args>-u -b 13.5M -t 30 -i 1</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>unbalanced</iperf_profile>
+	</testCase>
+
+	<testCase id="040661">
+		<class>Iperf</class>
+		<desc>iperf (20MHz - UL/2Mbps/UDP)(30 sec)(balanced)</desc>
+		<iperf_args>-u -b 2M -t 30 -i 1 -R</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>balanced</iperf_profile>
+	</testCase>
+
+	<testCase id="040662">
+		<class>Iperf</class>
+		<desc>iperf (20MHz - UL/2Mbps/UDP)(30 sec)(single-ue)</desc>
+		<iperf_args>-u -b 2M -t 30 -i 1 -R</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>single-ue</iperf_profile>
+	</testCase>
+
+	<testCase id="040663">
+		<class>Iperf</class>
+		<desc>iperf (20MHz - UL/2Mbps/UDP)(30 sec)(unbalanced)</desc>
+		<iperf_args>-u -b 2M -t 30 -i 1 -R</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>unbalanced</iperf_profile>
+	</testCase>
+
+</testCaseList>
diff --git a/ci-scripts/xml_files/enb_usrp210_band40_tracer.xml b/ci-scripts/xml_files/enb_usrp210_band40_tracer.xml
new file mode 100644
index 0000000000000000000000000000000000000000..dceb6be97aaefcc3543c7ef1b324a60d6146ea20
--- /dev/null
+++ b/ci-scripts/xml_files/enb_usrp210_band40_tracer.xml
@@ -0,0 +1,65 @@
+<!--
+
+ 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>tracer-test</htmlTabRef>
+	<htmlTabName>T-Tracer</htmlTabName>
+	<htmlTabIcon>duplicate</htmlTabIcon>
+        <TestCaseRequestedList>
+ 040101
+ 030100 040300 040401 040201 030201
+	</TestCaseRequestedList>
+	<TestCaseExclusionList></TestCaseExclusionList>
+
+	<testCase id="030100">
+		<class>Initialize_eNB</class>
+		<desc>Initialize eNB (TDD/Band40/5MHz) with T Tracer on</desc>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band40.tm1.25PRB.FairScheduler.usrpb210.conf --T_stdout 0</Initialize_eNB_args>
+	</testCase>
+
+	<testCase id="030201">
+		<class>Terminate_eNB</class>
+		<desc>Terminate eNB</desc>
+	</testCase>
+
+	<testCase id="040101">
+		<class>Initialize_UE</class>
+		<desc>Initialize UE</desc>
+	</testCase>
+
+	<testCase id="040201">
+		<class>Terminate_UE</class>
+		<desc>Terminate UE</desc>
+	</testCase>
+
+        <testCase id="040300">
+                <class>Attach_UE</class>
+                <desc>Attach single UE</desc>
+                <nbMaxUEtoAttach>1</nbMaxUEtoAttach>
+        </testCase>
+
+        <testCase id="040401">
+                <class>Detach_UE</class>
+                <desc>Detach UE</desc>
+        </testCase>
+
+</testCaseList>
diff --git a/ci-scripts/xml_files/enb_usrp210_band7.xml b/ci-scripts/xml_files/enb_usrp210_band7.xml
deleted file mode 100644
index 0785ad815d28a9fe85e65a6d6a3a9f5ff96f2861..0000000000000000000000000000000000000000
--- a/ci-scripts/xml_files/enb_usrp210_band7.xml
+++ /dev/null
@@ -1,350 +0,0 @@
-<!--
-
- 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>
-	<TestCaseRequestedList>
- 010101
- 050101 060101 070101 040101
- 030101 040301 040501 040603 040604 040605 040606 040607 040641 040642 040643 040644 040401 040201 030201
- 030111 040301 040511 040613 040614 040615 040616 040617 040651 040652 040653 040654 040401 040201 030201
- 030121 040301 040521 040623 040624 040625 040626 040627 040662 040661 040663 040664 040401 040201 030201
- 050201 060201 070201
-	</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="030101">
-		<class>Initialize_eNB</class>
-		<desc>Initialize eNB (FDD/Band7/5MHz)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.25PRB.usrpb210.conf --codingw --fepw</Initialize_eNB_args>
-	</testCase>
-
-	<testCase id="030111">
-		<class>Initialize_eNB</class>
-		<desc>Initialize eNB (FDD/Band7/10MHz)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.50PRB.usrpb210.conf --codingw --fepw</Initialize_eNB_args>
-	</testCase>
-
-	<testCase id="030121">
-		<class>Initialize_eNB</class>
-		<desc>Initialize eNB (FDD/Band7/20MHz)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.100PRB.usrpb210.conf --codingw --fepw</Initialize_eNB_args>
-	</testCase>
-
-	<testCase id="030201">
-		<class>Terminate_eNB</class>
-		<desc>Terminate eNB</desc>
-	</testCase>
-
-	<testCase id="040101">
-		<class>Initialize_UE</class>
-		<desc>Initialize UE</desc>
-	</testCase>
-
-	<testCase id="040201">
-		<class>Terminate_UE</class>
-		<desc>Terminate UE</desc>
-	</testCase>
-
-        <testCase id="040301">
-                <class>Attach_UE</class>
-                <desc>Attach UE</desc>
-        </testCase>
-
-        <testCase id="040401">
-                <class>Detach_UE</class>
-                <desc>Detach UE</desc>
-        </testCase>
-
-        <testCase id="040501">
-                <class>Ping</class>
-                <desc>ping (5MHz - 20 sec)</desc>
-                <ping_args>-c 20</ping_args>
-                <ping_packetloss_threshold>5</ping_packetloss_threshold>
-        </testCase>
-
-        <testCase id="040511">
-                <class>Ping</class>
-                <desc>ping (10MHz - 20 sec)</desc>
-                <ping_args>-c 20</ping_args>
-                <ping_packetloss_threshold>5</ping_packetloss_threshold>
-        </testCase>
-
-        <testCase id="040521">
-                <class>Ping</class>
-                <desc>ping (20MHz - 20 sec)</desc>
-                <ping_args>-c 20</ping_args>
-                <ping_packetloss_threshold>5</ping_packetloss_threshold>
-        </testCase>
-
-        <testCase id="040603">
-		<class>Iperf</class>
-		<desc>iperf (5MHz - DL/15Mbps/UDP)(30 sec)(balanced profile)</desc>
-		<iperf_args>-u -b 15M -t 30 -i 1</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>balanced</iperf_profile>
-        </testCase>
-
-        <testCase id="040604">
-		<class>Iperf</class>
-		<desc>iperf (5MHz - DL/15Mbps/UDP)(30 sec)(single-ue profile)</desc>
-		<iperf_args>-u -b 15M -t 30 -i 1</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>single-ue</iperf_profile>
-        </testCase>
-
-        <testCase id="040605">
-		<class>Iperf</class>
-		<desc>iperf (5MHz - DL/15Mbps/UDP)(30 sec)(unbalanced profile)</desc>
-		<iperf_args>-u -b 15M -t 30 -i 1</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>unbalanced</iperf_profile>
-        </testCase>
-
-        <testCase id="040606">
-		<class>Iperf</class>
-		<desc>iperf (5MHz - DL/TCP)(30 sec)(single-ue profile)</desc>
-		<iperf_args>-t 30 -i 1 -fm</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>single-ue</iperf_profile>
-        </testCase>
-
-        <testCase id="040607">
-		<class>Iperf</class>
-		<desc>iperf (5MHz - DL/TCP)(30 sec)(balanced profile)</desc>
-		<iperf_args>-t 30 -i 1 -fm</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>balanced</iperf_profile>
-        </testCase>
-
-	<testCase id="040641">
-		<class>Iperf</class>
-		<desc>iperf (5MHz - UL/9Mbps/UDP)(30 sec)(balanced profile)</desc>
-		<iperf_args>-u -b 9M -t 30 -i 1 -R</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>balanced</iperf_profile>
-	</testCase>
-
-	<testCase id="040642">
-		<class>Iperf</class>
-		<desc>iperf (5MHz - UL/9Mbps/UDP)(30 sec)(single-ue profile)</desc>
-		<iperf_args>-u -b 9M -t 30 -i 1 -R</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>single-ue</iperf_profile>
-	</testCase>
-
-        <testCase id="040643">
-		<class>Iperf</class>
-		<desc>iperf (5MHz - UL/TCP)(30 sec)(single-ue profile)</desc>
-		<iperf_args>-t 30 -i 1 -fm -R</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>single-ue</iperf_profile>
-        </testCase>
-
-        <testCase id="040644">
-		<class>Iperf</class>
-		<desc>iperf (5MHz - UL/TCP)(30 sec)(balanced profile)</desc>
-		<iperf_args>-t 30 -i 1 -fm -R</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>balanced</iperf_profile>
-        </testCase>
-
-        <testCase id="040613">
-		<class>Iperf</class>
-		<desc>iperf (10MHz - DL/30Mbps/UDP)(30 sec)(balanced profile)</desc>
-		<iperf_args>-u -b 30M -t 30 -i 1</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>balanced</iperf_profile>
-        </testCase>
-
-        <testCase id="040614">
-		<class>Iperf</class>
-		<desc>iperf (10MHz - DL/30Mbps/UDP)(30 sec)(single-ue profile)</desc>
-		<iperf_args>-u -b 30M -t 30 -i 1</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>single-ue</iperf_profile>
-        </testCase>
-
-        <testCase id="040615">
-		<class>Iperf</class>
-		<desc>iperf (10MHz - DL/30Mbps/UDP)(30 sec)(unbalanced profile)</desc>
-		<iperf_args>-u -b 30M -t 30 -i 1</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>unbalanced</iperf_profile>
-        </testCase>
-
-        <testCase id="040616">
-		<class>Iperf</class>
-		<desc>iperf (10MHz - DL/TCP)(30 sec)(single-ue profile)</desc>
-		<iperf_args>-t 30 -i 1 -fm</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>single-ue</iperf_profile>
-        </testCase>
-
-        <testCase id="040617">
-		<class>Iperf</class>
-		<desc>iperf (10MHz - DL/TCP)(30 sec)(balanced profile)</desc>
-		<iperf_args>-t 30 -i 1 -fm</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>balanced</iperf_profile>
-        </testCase>
-
-	<testCase id="040651">
-		<class>Iperf</class>
-		<desc>iperf (10MHz - UL/20Mbps/UDP)(30 sec)(balanced profile)</desc>
-		<iperf_args>-u -b 20M -t 30 -i 1 -R</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>balanced</iperf_profile>
-	</testCase>
-
-	<testCase id="040652">
-		<class>Iperf</class>
-		<desc>iperf (10MHz - UL/20Mbps/UDP)(30 sec)(single-ue profile)</desc>
-		<iperf_args>-u -b 20M -t 30 -i 1 -R</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>single-ue</iperf_profile>
-	</testCase>
-
-        <testCase id="040653">
-		<class>Iperf</class>
-		<desc>iperf (10MHz - UL/TCP)(30 sec)(single-ue profile)</desc>
-		<iperf_args>-t 30 -i 1 -fm -R</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>single-ue</iperf_profile>
-        </testCase>
-
-        <testCase id="040654">
-		<class>Iperf</class>
-		<desc>iperf (10MHz - UL/TCP)(30 sec)(balanced profile)</desc>
-		<iperf_args>-t 30 -i 1 -fm -R</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>balanced</iperf_profile>
-        </testCase>
-
-        <testCase id="040623">
-		<class>Iperf</class>
-		<desc>iperf (20MHz - DL/70Mbps/UDP)(30 sec)(balanced profile)</desc>
-		<iperf_args>-u -b 70M -t 30 -i 1</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>balanced</iperf_profile>
-        </testCase>
-
-        <testCase id="040624">
-		<class>Iperf</class>
-		<desc>iperf (20MHz - DL/70Mbps/UDP)(30 sec)(single-ue profile)</desc>
-		<iperf_args>-u -b 70M -t 30 -i 1</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>single-ue</iperf_profile>
-        </testCase>
-
-        <testCase id="040625">
-		<class>Iperf</class>
-		<desc>iperf (20MHz - DL/70Mbps/UDP)(30 sec)(unbalanced profile)</desc>
-		<iperf_args>-u -b 70M -t 30 -i 1</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>unbalanced</iperf_profile>
-        </testCase>
-
-        <testCase id="040626">
-		<class>Iperf</class>
-		<desc>iperf (20MHz - DL/TCP)(30 sec)(single-ue profile)</desc>
-		<iperf_args>-t 30 -i 1 -fm</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>single-ue</iperf_profile>
-        </testCase>
-
-        <testCase id="040627">
-		<class>Iperf</class>
-		<desc>iperf (20MHz - DL/TCP)(30 sec)(balanced profile)</desc>
-		<iperf_args>-t 30 -i 1 -fm</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>balanced</iperf_profile>
-        </testCase>
-
-	<testCase id="040661">
-		<class>Iperf</class>
-		<desc>iperf (20MHz - UL/20Mbps/UDP)(30 sec)(balanced profile)</desc>
-		<iperf_args>-u -b 20M -t 30 -i 1 -R</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>balanced</iperf_profile>
-	</testCase>
-
-	<testCase id="040662">
-		<class>Iperf</class>
-		<desc>iperf (20MHz - UL/20Mbps/UDP)(30 sec)(single-ue profile)</desc>
-		<iperf_args>-u -b 20M -t 30 -i 1 -R</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>single-ue</iperf_profile>
-	</testCase>
-
-        <testCase id="040663">
-		<class>Iperf</class>
-		<desc>iperf (20MHz - UL/TCP)(30 sec)(single-ue profile)</desc>
-		<iperf_args>-t 30 -i 1 -fm -R</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>single-ue</iperf_profile>
-        </testCase>
-
-        <testCase id="040664">
-		<class>Iperf</class>
-		<desc>iperf (20MHz - UL/TCP)(30 sec)(balanced profile)</desc>
-		<iperf_args>-t 30 -i 1 -fm -R</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>balanced</iperf_profile>
-        </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>
-
-	<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_band7_build.xml b/ci-scripts/xml_files/enb_usrp210_band7_build.xml
new file mode 100644
index 0000000000000000000000000000000000000000..31ee57e94164bf6ecbf270927052bb5942eca65f
--- /dev/null
+++ b/ci-scripts/xml_files/enb_usrp210_band7_build.xml
@@ -0,0 +1,54 @@
+<!--
+
+ 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_band7_epc_closure.xml b/ci-scripts/xml_files/enb_usrp210_band7_epc_closure.xml
new file mode 100644
index 0000000000000000000000000000000000000000..07fb6951f8e99a35cabd2ee4e48232d2bd035f41
--- /dev/null
+++ b/ci-scripts/xml_files/enb_usrp210_band7_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_band7_test_05mhz_tm1.xml b/ci-scripts/xml_files/enb_usrp210_band7_test_05mhz_tm1.xml
new file mode 100644
index 0000000000000000000000000000000000000000..0057eaefa408c3e599f122a4f7c0b42b0c186c17
--- /dev/null
+++ b/ci-scripts/xml_files/enb_usrp210_band7_test_05mhz_tm1.xml
@@ -0,0 +1,143 @@
+<!--
+
+ 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-05-tm1</htmlTabRef>
+	<htmlTabName>Test-05MHz-TM1</htmlTabName>
+	<htmlTabIcon>tasks</htmlTabIcon>
+	<TestCaseRequestedList>
+ 040101
+ 030101 040301 040501 040603 040604 040605 040606 040607 040641 040642 040643 040644 040401 040201 030201
+	</TestCaseRequestedList>
+	<TestCaseExclusionList></TestCaseExclusionList>
+
+	<testCase id="030101">
+		<class>Initialize_eNB</class>
+		<desc>Initialize eNB (FDD/Band7/5MHz)</desc>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.25PRB.usrpb210.conf</Initialize_eNB_args>
+	</testCase>
+
+	<testCase id="030201">
+		<class>Terminate_eNB</class>
+		<desc>Terminate eNB</desc>
+	</testCase>
+
+	<testCase id="040101">
+		<class>Initialize_UE</class>
+		<desc>Initialize UE</desc>
+	</testCase>
+
+	<testCase id="040201">
+		<class>Terminate_UE</class>
+		<desc>Terminate UE</desc>
+	</testCase>
+
+        <testCase id="040301">
+                <class>Attach_UE</class>
+                <desc>Attach UE</desc>
+        </testCase>
+
+        <testCase id="040401">
+                <class>Detach_UE</class>
+                <desc>Detach UE</desc>
+        </testCase>
+
+        <testCase id="040501">
+                <class>Ping</class>
+                <desc>ping (5MHz - 20 sec)</desc>
+                <ping_args>-c 20</ping_args>
+                <ping_packetloss_threshold>5</ping_packetloss_threshold>
+        </testCase>
+
+        <testCase id="040603">
+		<class>Iperf</class>
+		<desc>iperf (5MHz - DL/15Mbps/UDP)(30 sec)(balanced profile)</desc>
+		<iperf_args>-u -b 15M -t 30 -i 1</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>balanced</iperf_profile>
+        </testCase>
+
+        <testCase id="040604">
+		<class>Iperf</class>
+		<desc>iperf (5MHz - DL/15Mbps/UDP)(30 sec)(single-ue profile)</desc>
+		<iperf_args>-u -b 15M -t 30 -i 1</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>single-ue</iperf_profile>
+        </testCase>
+
+        <testCase id="040605">
+		<class>Iperf</class>
+		<desc>iperf (5MHz - DL/15Mbps/UDP)(30 sec)(unbalanced profile)</desc>
+		<iperf_args>-u -b 15M -t 30 -i 1</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>unbalanced</iperf_profile>
+        </testCase>
+
+        <testCase id="040606">
+		<class>Iperf</class>
+		<desc>iperf (5MHz - DL/TCP)(30 sec)(single-ue profile)</desc>
+		<iperf_args>-t 30 -i 1 -fm</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>single-ue</iperf_profile>
+        </testCase>
+
+        <testCase id="040607">
+		<class>Iperf</class>
+		<desc>iperf (5MHz - DL/TCP)(30 sec)(balanced profile)</desc>
+		<iperf_args>-t 30 -i 1 -fm</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>balanced</iperf_profile>
+        </testCase>
+
+	<testCase id="040641">
+		<class>Iperf</class>
+		<desc>iperf (5MHz - UL/9Mbps/UDP)(30 sec)(balanced profile)</desc>
+		<iperf_args>-u -b 9M -t 30 -i 1 -R</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>balanced</iperf_profile>
+	</testCase>
+
+	<testCase id="040642">
+		<class>Iperf</class>
+		<desc>iperf (5MHz - UL/9Mbps/UDP)(30 sec)(single-ue profile)</desc>
+		<iperf_args>-u -b 9M -t 30 -i 1 -R</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>single-ue</iperf_profile>
+	</testCase>
+
+        <testCase id="040643">
+		<class>Iperf</class>
+		<desc>iperf (5MHz - UL/TCP)(30 sec)(single-ue profile)</desc>
+		<iperf_args>-t 30 -i 1 -fm -R</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>single-ue</iperf_profile>
+        </testCase>
+
+        <testCase id="040644">
+		<class>Iperf</class>
+		<desc>iperf (5MHz - UL/TCP)(30 sec)(balanced profile)</desc>
+		<iperf_args>-t 30 -i 1 -fm -R</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>balanced</iperf_profile>
+        </testCase>
+
+</testCaseList>
diff --git a/ci-scripts/xml_files/enb_usrp210_band7_test_10mhz_tm1.xml b/ci-scripts/xml_files/enb_usrp210_band7_test_10mhz_tm1.xml
new file mode 100644
index 0000000000000000000000000000000000000000..92ec1efa6e805312892ddccb8c18d9f814cd4d6c
--- /dev/null
+++ b/ci-scripts/xml_files/enb_usrp210_band7_test_10mhz_tm1.xml
@@ -0,0 +1,143 @@
+<!--
+
+ 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>
+ 040101
+ 030111 040301 040511 040613 040614 040615 040616 040617 040651 040652 040653 040654 040401 040201 030201
+	</TestCaseRequestedList>
+	<TestCaseExclusionList></TestCaseExclusionList>
+
+	<testCase id="030111">
+		<class>Initialize_eNB</class>
+		<desc>Initialize eNB (FDD/Band7/10MHz)</desc>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.50PRB.usrpb210.conf</Initialize_eNB_args>
+	</testCase>
+
+	<testCase id="030201">
+		<class>Terminate_eNB</class>
+		<desc>Terminate eNB</desc>
+	</testCase>
+
+	<testCase id="040101">
+		<class>Initialize_UE</class>
+		<desc>Initialize UE</desc>
+	</testCase>
+
+	<testCase id="040201">
+		<class>Terminate_UE</class>
+		<desc>Terminate UE</desc>
+	</testCase>
+
+        <testCase id="040301">
+                <class>Attach_UE</class>
+                <desc>Attach UE</desc>
+        </testCase>
+
+        <testCase id="040401">
+                <class>Detach_UE</class>
+                <desc>Detach UE</desc>
+        </testCase>
+
+        <testCase id="040511">
+                <class>Ping</class>
+                <desc>ping (10MHz - 20 sec)</desc>
+                <ping_args>-c 20</ping_args>
+                <ping_packetloss_threshold>5</ping_packetloss_threshold>
+        </testCase>
+
+        <testCase id="040613">
+		<class>Iperf</class>
+		<desc>iperf (10MHz - DL/30Mbps/UDP)(30 sec)(balanced profile)</desc>
+		<iperf_args>-u -b 30M -t 30 -i 1</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>balanced</iperf_profile>
+        </testCase>
+
+        <testCase id="040614">
+		<class>Iperf</class>
+		<desc>iperf (10MHz - DL/30Mbps/UDP)(30 sec)(single-ue profile)</desc>
+		<iperf_args>-u -b 30M -t 30 -i 1</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>single-ue</iperf_profile>
+        </testCase>
+
+        <testCase id="040615">
+		<class>Iperf</class>
+		<desc>iperf (10MHz - DL/30Mbps/UDP)(30 sec)(unbalanced profile)</desc>
+		<iperf_args>-u -b 30M -t 30 -i 1</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>unbalanced</iperf_profile>
+        </testCase>
+
+        <testCase id="040616">
+		<class>Iperf</class>
+		<desc>iperf (10MHz - DL/TCP)(30 sec)(single-ue profile)</desc>
+		<iperf_args>-t 30 -i 1 -fm</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>single-ue</iperf_profile>
+        </testCase>
+
+        <testCase id="040617">
+		<class>Iperf</class>
+		<desc>iperf (10MHz - DL/TCP)(30 sec)(balanced profile)</desc>
+		<iperf_args>-t 30 -i 1 -fm</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>balanced</iperf_profile>
+        </testCase>
+
+	<testCase id="040651">
+		<class>Iperf</class>
+		<desc>iperf (10MHz - UL/20Mbps/UDP)(30 sec)(balanced profile)</desc>
+		<iperf_args>-u -b 20M -t 30 -i 1 -R</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>balanced</iperf_profile>
+	</testCase>
+
+	<testCase id="040652">
+		<class>Iperf</class>
+		<desc>iperf (10MHz - UL/20Mbps/UDP)(30 sec)(single-ue profile)</desc>
+		<iperf_args>-u -b 20M -t 30 -i 1 -R</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>single-ue</iperf_profile>
+	</testCase>
+
+        <testCase id="040653">
+		<class>Iperf</class>
+		<desc>iperf (10MHz - UL/TCP)(30 sec)(single-ue profile)</desc>
+		<iperf_args>-t 30 -i 1 -fm -R</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>single-ue</iperf_profile>
+        </testCase>
+
+        <testCase id="040654">
+		<class>Iperf</class>
+		<desc>iperf (10MHz - UL/TCP)(30 sec)(balanced profile)</desc>
+		<iperf_args>-t 30 -i 1 -fm -R</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>balanced</iperf_profile>
+        </testCase>
+
+</testCaseList>
diff --git a/ci-scripts/xml_files/enb_usrp210_band7_test_20mhz_tm1.xml b/ci-scripts/xml_files/enb_usrp210_band7_test_20mhz_tm1.xml
new file mode 100644
index 0000000000000000000000000000000000000000..b6c441b19aeac33f6d1710b610b62277ed3d2ff6
--- /dev/null
+++ b/ci-scripts/xml_files/enb_usrp210_band7_test_20mhz_tm1.xml
@@ -0,0 +1,143 @@
+<!--
+
+ 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-20-tm1</htmlTabRef>
+	<htmlTabName>Test-20MHz-TM1</htmlTabName>
+	<htmlTabIcon>tasks</htmlTabIcon>
+	<TestCaseRequestedList>
+ 040101
+ 030121 040301 040521 040623 040624 040625 040662 040401 040201 030201
+	</TestCaseRequestedList>
+	<TestCaseExclusionList>040626 040627 040661 040663 040664</TestCaseExclusionList>
+
+	<testCase id="030121">
+		<class>Initialize_eNB</class>
+		<desc>Initialize eNB (FDD/Band7/20MHz)</desc>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.100PRB.usrpb210.conf</Initialize_eNB_args>
+	</testCase>
+
+	<testCase id="030201">
+		<class>Terminate_eNB</class>
+		<desc>Terminate eNB</desc>
+	</testCase>
+
+	<testCase id="040101">
+		<class>Initialize_UE</class>
+		<desc>Initialize UE</desc>
+	</testCase>
+
+	<testCase id="040201">
+		<class>Terminate_UE</class>
+		<desc>Terminate UE</desc>
+	</testCase>
+
+        <testCase id="040301">
+                <class>Attach_UE</class>
+                <desc>Attach UE</desc>
+        </testCase>
+
+        <testCase id="040401">
+                <class>Detach_UE</class>
+                <desc>Detach UE</desc>
+        </testCase>
+
+        <testCase id="040521">
+                <class>Ping</class>
+                <desc>ping (20MHz - 20 sec)</desc>
+                <ping_args>-c 20</ping_args>
+                <ping_packetloss_threshold>5</ping_packetloss_threshold>
+        </testCase>
+
+        <testCase id="040623">
+		<class>Iperf</class>
+		<desc>iperf (20MHz - DL/70Mbps/UDP)(30 sec)(balanced profile)</desc>
+		<iperf_args>-u -b 70M -t 30 -i 1</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>balanced</iperf_profile>
+        </testCase>
+
+        <testCase id="040624">
+		<class>Iperf</class>
+		<desc>iperf (20MHz - DL/70Mbps/UDP)(30 sec)(single-ue profile)</desc>
+		<iperf_args>-u -b 70M -t 30 -i 1</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>single-ue</iperf_profile>
+        </testCase>
+
+        <testCase id="040625">
+		<class>Iperf</class>
+		<desc>iperf (20MHz - DL/70Mbps/UDP)(30 sec)(unbalanced profile)</desc>
+		<iperf_args>-u -b 70M -t 30 -i 1</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>unbalanced</iperf_profile>
+        </testCase>
+
+        <testCase id="040626">
+		<class>Iperf</class>
+		<desc>iperf (20MHz - DL/TCP)(30 sec)(single-ue profile)</desc>
+		<iperf_args>-t 30 -i 1 -fm</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>single-ue</iperf_profile>
+        </testCase>
+
+        <testCase id="040627">
+		<class>Iperf</class>
+		<desc>iperf (20MHz - DL/TCP)(30 sec)(balanced profile)</desc>
+		<iperf_args>-t 30 -i 1 -fm</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>balanced</iperf_profile>
+        </testCase>
+
+	<testCase id="040661">
+		<class>Iperf</class>
+		<desc>iperf (20MHz - UL/12Mbps/UDP)(30 sec)(balanced profile)</desc>
+		<iperf_args>-u -b 12M -t 30 -i 1 -R</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>balanced</iperf_profile>
+	</testCase>
+
+	<testCase id="040662">
+		<class>Iperf</class>
+		<desc>iperf (20MHz - UL/17Mbps/UDP)(30 sec)(single-ue profile)</desc>
+		<iperf_args>-u -b 17M -t 30 -i 1 -R</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>single-ue</iperf_profile>
+	</testCase>
+
+        <testCase id="040663">
+		<class>Iperf</class>
+		<desc>iperf (20MHz - UL/TCP)(30 sec)(single-ue profile)</desc>
+		<iperf_args>-t 30 -i 1 -fm -R</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>single-ue</iperf_profile>
+        </testCase>
+
+        <testCase id="040664">
+		<class>Iperf</class>
+		<desc>iperf (20MHz - UL/TCP)(30 sec)(balanced profile)</desc>
+		<iperf_args>-t 30 -i 1 -fm -R</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>balanced</iperf_profile>
+        </testCase>
+
+</testCaseList>
diff --git a/ci-scripts/xml_files/enb_usrp210_band7_tracer.xml b/ci-scripts/xml_files/enb_usrp210_band7_tracer.xml
new file mode 100644
index 0000000000000000000000000000000000000000..4c74f52b0f0932ad241c991e5a0d192511162a87
--- /dev/null
+++ b/ci-scripts/xml_files/enb_usrp210_band7_tracer.xml
@@ -0,0 +1,65 @@
+<!--
+
+ 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>tracer-test</htmlTabRef>
+	<htmlTabName>T-Tracer</htmlTabName>
+	<htmlTabIcon>duplicate</htmlTabIcon>
+	<TestCaseRequestedList>
+ 040101
+ 030100 040300 040401 040201 030201
+	</TestCaseRequestedList>
+	<TestCaseExclusionList></TestCaseExclusionList>
+
+	<testCase id="030100">
+		<class>Initialize_eNB</class>
+		<desc>Initialize eNB (FDD/Band7/5MHz) with T Tracer on</desc>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.25PRB.usrpb210.conf --T_stdout 0</Initialize_eNB_args>
+	</testCase>
+
+	<testCase id="030201">
+		<class>Terminate_eNB</class>
+		<desc>Terminate eNB</desc>
+	</testCase>
+
+	<testCase id="040101">
+		<class>Initialize_UE</class>
+		<desc>Initialize UE</desc>
+	</testCase>
+
+	<testCase id="040201">
+		<class>Terminate_UE</class>
+		<desc>Terminate UE</desc>
+	</testCase>
+
+        <testCase id="040300">
+                <class>Attach_UE</class>
+                <desc>Attach single UE</desc>
+                <nbMaxUEtoAttach>1</nbMaxUEtoAttach>
+        </testCase>
+
+        <testCase id="040401">
+                <class>Detach_UE</class>
+                <desc>Detach UE</desc>
+        </testCase>
+
+</testCaseList>
diff --git a/ci-scripts/xml_files/if4p5_usrp210_band40.xml b/ci-scripts/xml_files/if4p5_usrp210_band40.xml
deleted file mode 100644
index 77fbff5028d0d8a7965abbe6995a16ea9b1ebc37..0000000000000000000000000000000000000000
--- a/ci-scripts/xml_files/if4p5_usrp210_band40.xml
+++ /dev/null
@@ -1,219 +0,0 @@
-<!--
-
- 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>
-	<!-- Only 5MHz is tested since neither 10MHz nor 20MHz work in this configuration -->
-	<!-- Also no UL iperf in 5MHz (040642) -->
-        <TestCaseRequestedList>
- 010101
- 050101 060101 070101 040101
- 030104 030105 040301 040501 040602 040401 040201 030201 030202
- 050201 060201 070201
-	</TestCaseRequestedList>
-	<!--
- 030104 030105 040301 040501 040602 040642 040401 040201 030201 030202
- 030114 030115 040301 040511 040612 040652 040401 040201 030201 030202
- 030124 030125 040301 040521 040622 040662 040401 040201 030201 030202
-	-->
-	<TestCaseExclusionList>
-	</TestCaseExclusionList>
-
-	<testCase id="010101">
-		<class>Build_eNB</class>
-		<desc>Build eNB (USRP -- Ethernet Fronthaul)</desc>
-		<Build_eNB_args>-t ETHERNET -w USRP -c --eNB</Build_eNB_args>
-	</testCase>
-
-	<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 --codingw --fepw</Initialize_eNB_args>
-		<eNB_instance>0</eNB_instance>
-	</testCase>
-
-	<testCase id="030105">
-		<class>Initialize_eNB</class>
-		<desc>Initialize RCC (TDD/Band40/5MHz)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/rcc.band40.tm1.25PRB.FairScheduler.usrpb210.conf --codingw --fepw</Initialize_eNB_args>
-		<eNB_instance>1</eNB_instance>
-	</testCase>
-
-	<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 --codingw --fepw</Initialize_eNB_args>
-		<eNB_instance>0</eNB_instance>
-	</testCase>
-
-	<testCase id="030115">
-                <class>Initialize_eNB</class>
-                <desc>Initialize RCC (TDD/Band40/10MHz/info)</desc>
-                <Initialize_eNB_args>-O ci-scripts/conf_files/rcc.band40.tm1.50PRB.FairScheduler.usrpb210.conf --codingw --fepw</Initialize_eNB_args>
-		<eNB_instance>1</eNB_instance>
-        </testCase>
-
-	<testCase id="030124">
-		<class>Initialize_eNB</class>
-		<desc>Initialize RRU (TDD/Band40)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/rru.tdd.band40.conf --codingw --fepw</Initialize_eNB_args>
-		<eNB_instance>0</eNB_instance>
-	</testCase>
-
-	<testCase id="030125">
-		<class>Initialize_eNB</class>
-		<desc>Initialize RCC (TDD/Band40/20MHz/info)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/rcc.band40.tm1.100PRB.FairScheduler.usrpb210.conf --codingw --fepw</Initialize_eNB_args>
-		<eNB_instance>1</eNB_instance>
-	</testCase>
-
-	<testCase id="030201">
-		<class>Terminate_eNB</class>
-		<desc>Terminate RCC</desc>
-		<eNB_instance>1</eNB_instance>
-	</testCase>
-
-	<testCase id="030202">
-		<class>Terminate_eNB</class>
-		<desc>Terminate RRU</desc>
-		<eNB_instance>0</eNB_instance>
-	</testCase>
-
-	<testCase id="040101">
-		<class>Initialize_UE</class>
-		<desc>Initialize UE</desc>
-	</testCase>
-
-	<testCase id="040201">
-		<class>Terminate_UE</class>
-		<desc>Terminate UE</desc>
-	</testCase>
-
-        <testCase id="040301">
-                <class>Attach_UE</class>
-                <desc>Attach UE</desc>
-        </testCase>
-
-        <testCase id="040401">
-                <class>Detach_UE</class>
-                <desc>Detach UE</desc>
-        </testCase>
-
-        <testCase id="040501">
-                <class>Ping</class>
-                <desc>ping (5MHz - 20 sec)</desc>
-                <ping_args>-c 20</ping_args>
-                <ping_packetloss_threshold>25</ping_packetloss_threshold>
-        </testCase>
-
-        <testCase id="040511">
-                <class>Ping</class>
-                <desc>ping (10MHz - 20 sec)</desc>
-                <ping_args>-c 20</ping_args>
-                <ping_packetloss_threshold>25</ping_packetloss_threshold>
-        </testCase>
-
-        <testCase id="040521">
-                <class>Ping</class>
-                <desc>ping (20MHz - 20 sec)</desc>
-                <ping_args>-c 20</ping_args>
-                <ping_packetloss_threshold>25</ping_packetloss_threshold>
-        </testCase>
-
-        <testCase id="040602">
-		<class>Iperf</class>
-		<desc>iperf (5MHz - DL/6.5Mbps/UDP)(30 sec)(single-ue)</desc>
-		<iperf_args>-u -b 6.5M -t 30 -i 1</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>single-ue</iperf_profile>
-        </testCase>
-
-        <testCase id="040612">
-                <class>Iperf</class>
-                <desc>iperf (10MHz - DL/13.5Mbps/UDP)(30 sec)(single-ue)</desc>
-                <iperf_args>-u -b 13.5M -t 30 -i 1</iperf_args>
-                <iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-                <iperf_profile>single-ue</iperf_profile>
-        </testCase>
-
-        <testCase id="040622">
-                <class>Iperf</class>
-                <desc>iperf (20MHz - DL/13.5Mbps/UDP)(30 sec)(single-ue)</desc>
-                <iperf_args>-u -b 13.5M -t 30 -i 1</iperf_args>
-                <iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-                <iperf_profile>single-ue</iperf_profile>
-        </testCase>
-
-	<testCase id="040642">
-		<class>Iperf</class>
-		<desc>iperf (5MHz - UL/2Mbps/UDP)(30 sec)(single-ue)</desc>
-		<iperf_args>-u -b 2M -t 30 -i 1 -R</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>single-ue</iperf_profile>
-	</testCase>
-
-	<testCase id="040652">
-		<class>Iperf</class>
-		<desc>iperf (10MHz - UL/2Mbps/UDP)(30 sec)(single-ue)</desc>
-		<iperf_args>-u -b 2M -t 30 -i 1 -R</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>single-ue</iperf_profile>
-	</testCase>
-
-	<testCase id="040662">
-		<class>Iperf</class>
-		<desc>iperf (20MHz - UL/2Mbps/UDP)(30 sec)(single-ue)</desc>
-		<iperf_args>-u -b 2M -t 30 -i 1 -R</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>single-ue</iperf_profile>
-	</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>
-
-        <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/if4p5_usrp210_band40_build.xml b/ci-scripts/xml_files/if4p5_usrp210_band40_build.xml
new file mode 100644
index 0000000000000000000000000000000000000000..5bb7db52990d6b6a7bae5764769cb0ab51a04e3b
--- /dev/null
+++ b/ci-scripts/xml_files/if4p5_usrp210_band40_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 -- Ethernet Fronthaul)</desc>
+		<Build_eNB_args>-t ETHERNET -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/if4p5_usrp210_band40_epc_closure.xml b/ci-scripts/xml_files/if4p5_usrp210_band40_epc_closure.xml
new file mode 100644
index 0000000000000000000000000000000000000000..c04a8b3cf46940005090ebc835b09fd824d4c027
--- /dev/null
+++ b/ci-scripts/xml_files/if4p5_usrp210_band40_epc_closure.xml
@@ -0,0 +1,48 @@
+<!--
+
+ 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/if4p5_usrp210_band40_test_05mhz.xml b/ci-scripts/xml_files/if4p5_usrp210_band40_test_05mhz.xml
new file mode 100644
index 0000000000000000000000000000000000000000..4a40929548606bbc7a86945497baa3b2c0ee25e9
--- /dev/null
+++ b/ci-scripts/xml_files/if4p5_usrp210_band40_test_05mhz.xml
@@ -0,0 +1,103 @@
+<!--
+
+ 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-05</htmlTabRef>
+	<htmlTabName>Test-05MHz</htmlTabName>
+	<htmlTabIcon>tasks</htmlTabIcon>
+        <TestCaseRequestedList>
+ 040101
+ 030104 030105 040301 040501 040602 040642 040401 040201 030201 030202
+	</TestCaseRequestedList>
+	<TestCaseExclusionList>
+	</TestCaseExclusionList>
+
+	<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>
+		<eNB_instance>0</eNB_instance>
+	</testCase>
+
+	<testCase id="030105">
+		<class>Initialize_eNB</class>
+		<desc>Initialize RCC (TDD/Band40/5MHz)</desc>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/rcc.band40.tm1.25PRB.FairScheduler.usrpb210.conf</Initialize_eNB_args>
+		<eNB_instance>1</eNB_instance>
+	</testCase>
+
+	<testCase id="030201">
+		<class>Terminate_eNB</class>
+		<desc>Terminate RCC</desc>
+		<eNB_instance>1</eNB_instance>
+	</testCase>
+
+	<testCase id="030202">
+		<class>Terminate_eNB</class>
+		<desc>Terminate RRU</desc>
+		<eNB_instance>0</eNB_instance>
+	</testCase>
+
+	<testCase id="040101">
+		<class>Initialize_UE</class>
+		<desc>Initialize UE</desc>
+	</testCase>
+
+	<testCase id="040201">
+		<class>Terminate_UE</class>
+		<desc>Terminate UE</desc>
+	</testCase>
+
+        <testCase id="040301">
+                <class>Attach_UE</class>
+                <desc>Attach UE</desc>
+        </testCase>
+
+        <testCase id="040401">
+                <class>Detach_UE</class>
+                <desc>Detach UE</desc>
+        </testCase>
+
+        <testCase id="040501">
+                <class>Ping</class>
+                <desc>ping (5MHz - 20 sec)</desc>
+                <ping_args>-c 20</ping_args>
+                <ping_packetloss_threshold>25</ping_packetloss_threshold>
+        </testCase>
+
+        <testCase id="040602">
+		<class>Iperf</class>
+		<desc>iperf (5MHz - DL/6.5Mbps/UDP)(30 sec)(single-ue)</desc>
+		<iperf_args>-u -b 6.5M -t 30 -i 1</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>single-ue</iperf_profile>
+        </testCase>
+
+	<testCase id="040642">
+		<class>Iperf</class>
+		<desc>iperf (5MHz - UL/2Mbps/UDP)(30 sec)(single-ue)</desc>
+		<iperf_args>-u -b 2M -t 30 -i 1 -R</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>single-ue</iperf_profile>
+	</testCase>
+
+</testCaseList>
diff --git a/ci-scripts/xml_files/if4p5_usrp210_band40_test_10mhz.xml b/ci-scripts/xml_files/if4p5_usrp210_band40_test_10mhz.xml
new file mode 100644
index 0000000000000000000000000000000000000000..d046b83f2cad0ca802cd414ddc86a1ccf3c024eb
--- /dev/null
+++ b/ci-scripts/xml_files/if4p5_usrp210_band40_test_10mhz.xml
@@ -0,0 +1,103 @@
+<!--
+
+ 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</htmlTabRef>
+	<htmlTabName>Test-10MHz</htmlTabName>
+	<htmlTabIcon>tasks</htmlTabIcon>
+        <TestCaseRequestedList>
+ 040101
+ 030114 030115 040301 040511 040612 040652 040401 040201 030201 030202
+	</TestCaseRequestedList>
+	<TestCaseExclusionList>
+	</TestCaseExclusionList>
+
+	<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>
+		<eNB_instance>0</eNB_instance>
+	</testCase>
+
+	<testCase id="030115">
+                <class>Initialize_eNB</class>
+                <desc>Initialize RCC (TDD/Band40/10MHz/info)</desc>
+                <Initialize_eNB_args>-O ci-scripts/conf_files/rcc.band40.tm1.50PRB.FairScheduler.usrpb210.conf</Initialize_eNB_args>
+		<eNB_instance>1</eNB_instance>
+        </testCase>
+
+	<testCase id="030201">
+		<class>Terminate_eNB</class>
+		<desc>Terminate RCC</desc>
+		<eNB_instance>1</eNB_instance>
+	</testCase>
+
+	<testCase id="030202">
+		<class>Terminate_eNB</class>
+		<desc>Terminate RRU</desc>
+		<eNB_instance>0</eNB_instance>
+	</testCase>
+
+	<testCase id="040101">
+		<class>Initialize_UE</class>
+		<desc>Initialize UE</desc>
+	</testCase>
+
+	<testCase id="040201">
+		<class>Terminate_UE</class>
+		<desc>Terminate UE</desc>
+	</testCase>
+
+        <testCase id="040301">
+                <class>Attach_UE</class>
+                <desc>Attach UE</desc>
+        </testCase>
+
+        <testCase id="040401">
+                <class>Detach_UE</class>
+                <desc>Detach UE</desc>
+        </testCase>
+
+        <testCase id="040511">
+                <class>Ping</class>
+                <desc>ping (10MHz - 20 sec)</desc>
+                <ping_args>-c 20</ping_args>
+                <ping_packetloss_threshold>25</ping_packetloss_threshold>
+        </testCase>
+
+        <testCase id="040612">
+                <class>Iperf</class>
+                <desc>iperf (10MHz - DL/13.5Mbps/UDP)(30 sec)(single-ue)</desc>
+                <iperf_args>-u -b 13.5M -t 30 -i 1</iperf_args>
+                <iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+                <iperf_profile>single-ue</iperf_profile>
+        </testCase>
+
+	<testCase id="040652">
+		<class>Iperf</class>
+		<desc>iperf (10MHz - UL/2Mbps/UDP)(30 sec)(single-ue)</desc>
+		<iperf_args>-u -b 2M -t 30 -i 1 -R</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>single-ue</iperf_profile>
+	</testCase>
+
+</testCaseList>
diff --git a/ci-scripts/xml_files/if4p5_usrp210_band40_test_20mhz.xml b/ci-scripts/xml_files/if4p5_usrp210_band40_test_20mhz.xml
new file mode 100644
index 0000000000000000000000000000000000000000..cd732294ec03d55f0d49acea6d84627593e21d9a
--- /dev/null
+++ b/ci-scripts/xml_files/if4p5_usrp210_band40_test_20mhz.xml
@@ -0,0 +1,103 @@
+<!--
+
+ 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-20</htmlTabRef>
+	<htmlTabName>Test-20MHz</htmlTabName>
+	<htmlTabIcon>tasks</htmlTabIcon>
+        <TestCaseRequestedList>
+ 040101
+ 030124 030125 040301 040521 040622 040662 040401 040201 030201 030202
+	</TestCaseRequestedList>
+	<TestCaseExclusionList>
+	</TestCaseExclusionList>
+
+	<testCase id="030124">
+		<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>
+		<eNB_instance>0</eNB_instance>
+	</testCase>
+
+	<testCase id="030125">
+		<class>Initialize_eNB</class>
+		<desc>Initialize RCC (TDD/Band40/20MHz/info)</desc>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/rcc.band40.tm1.100PRB.FairScheduler.usrpb210.conf</Initialize_eNB_args>
+		<eNB_instance>1</eNB_instance>
+	</testCase>
+
+	<testCase id="030201">
+		<class>Terminate_eNB</class>
+		<desc>Terminate RCC</desc>
+		<eNB_instance>1</eNB_instance>
+	</testCase>
+
+	<testCase id="030202">
+		<class>Terminate_eNB</class>
+		<desc>Terminate RRU</desc>
+		<eNB_instance>0</eNB_instance>
+	</testCase>
+
+	<testCase id="040101">
+		<class>Initialize_UE</class>
+		<desc>Initialize UE</desc>
+	</testCase>
+
+	<testCase id="040201">
+		<class>Terminate_UE</class>
+		<desc>Terminate UE</desc>
+	</testCase>
+
+        <testCase id="040301">
+                <class>Attach_UE</class>
+                <desc>Attach UE</desc>
+        </testCase>
+
+        <testCase id="040401">
+                <class>Detach_UE</class>
+                <desc>Detach UE</desc>
+        </testCase>
+
+        <testCase id="040521">
+                <class>Ping</class>
+                <desc>ping (20MHz - 20 sec)</desc>
+                <ping_args>-c 20</ping_args>
+                <ping_packetloss_threshold>25</ping_packetloss_threshold>
+        </testCase>
+
+        <testCase id="040622">
+                <class>Iperf</class>
+                <desc>iperf (20MHz - DL/13.5Mbps/UDP)(30 sec)(single-ue)</desc>
+                <iperf_args>-u -b 13.5M -t 30 -i 1</iperf_args>
+                <iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+                <iperf_profile>single-ue</iperf_profile>
+        </testCase>
+
+	<testCase id="040662">
+		<class>Iperf</class>
+		<desc>iperf (20MHz - UL/2Mbps/UDP)(30 sec)(single-ue)</desc>
+		<iperf_args>-u -b 2M -t 30 -i 1 -R</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>single-ue</iperf_profile>
+	</testCase>
+
+</testCaseList>
diff --git a/ci-scripts/xml_files/if4p5_usrp210_band7.xml b/ci-scripts/xml_files/if4p5_usrp210_band7.xml
deleted file mode 100644
index a3e5ecd72c39b0facc4cdc140cdfdf297b812a43..0000000000000000000000000000000000000000
--- a/ci-scripts/xml_files/if4p5_usrp210_band7.xml
+++ /dev/null
@@ -1,217 +0,0 @@
-<!--
-
- 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>
-	<!-- Only 5MHz is tested since neither 10MHz nor 20MHz work in this configuration -->
-	<TestCaseRequestedList>
- 010101
- 050101 060101 070101 040101
- 030101 030102 040301 040501 040604 040642 040401 040201 030201 030202
- 050201 060201 070201
-	</TestCaseRequestedList>
-	<!--
- 030111 030112 040301 040511 040614 040652 040401 040201 030201 030202
- 030121 030122 040301 040521 040624 040662 040401 040201 030201 030202
-	-->
-	<TestCaseExclusionList>
-	</TestCaseExclusionList>
-
-	<testCase id="010101">
-		<class>Build_eNB</class>
-		<desc>Build eNB (USRP -- Ethernet Fronthaul)</desc>
-		<Build_eNB_args>-t ETHERNET -w USRP -c --eNB</Build_eNB_args>
-	</testCase>
-
-	<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 --codingw --fepw</Initialize_eNB_args>
-		<eNB_instance>1</eNB_instance>
-	</testCase>
-
-	<testCase id="030102">
-		<class>Initialize_eNB</class>
-		<desc>Initialize RCC (FDD/Band7/5MHz)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/rcc.band7.tm1.if4p5.lo.25PRB.usrpb210.conf --codingw --fepw</Initialize_eNB_args>
-		<eNB_instance>0</eNB_instance>
-	</testCase>
-
-	<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 --codingw --fepw</Initialize_eNB_args>
-		<eNB_instance>1</eNB_instance>
-	</testCase>
-
-	<testCase id="030112">
-		<class>Initialize_eNB</class>
-		<desc>Initialize RCC (FDD/Band7/10MHz)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/rcc.band7.tm1.if4p5.lo.50PRB.usrpb210.conf --codingw --fepw</Initialize_eNB_args>
-		<eNB_instance>0</eNB_instance>
-	</testCase>
-
-	<testCase id="030121">
-		<class>Initialize_eNB</class>
-		<desc>Initialize RRU (FDD/Band7)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/rru.fdd.band7.conf --codingw --fepw</Initialize_eNB_args>
-		<eNB_instance>1</eNB_instance>
-	</testCase>
-
-	<testCase id="030122">
-		<class>Initialize_eNB</class>
-		<desc>Initialize RCC (FDD/Band7/20MHz)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/rcc.band7.tm1.if4p5.lo.100PRB.usrpb210.conf --codingw --fepw</Initialize_eNB_args>
-		<eNB_instance>0</eNB_instance>
-	</testCase>
-
-	<testCase id="030201">
-		<class>Terminate_eNB</class>
-		<desc>Terminate RCC</desc>
-		<eNB_instance>0</eNB_instance>
-	</testCase>
-
-	<testCase id="030202">
-		<class>Terminate_eNB</class>
-		<desc>Terminate RRU</desc>
-		<eNB_instance>1</eNB_instance>
-	</testCase>
-
-	<testCase id="040101">
-		<class>Initialize_UE</class>
-		<desc>Initialize UE</desc>
-	</testCase>
-
-	<testCase id="040201">
-		<class>Terminate_UE</class>
-		<desc>Terminate UE</desc>
-	</testCase>
-
-        <testCase id="040301">
-                <class>Attach_UE</class>
-                <desc>Attach UE</desc>
-        </testCase>
-
-        <testCase id="040401">
-                <class>Detach_UE</class>
-                <desc>Detach UE</desc>
-        </testCase>
-
-        <testCase id="040501">
-                <class>Ping</class>
-                <desc>ping (5MHz - 20 sec)</desc>
-                <ping_args>-c 20</ping_args>
-                <ping_packetloss_threshold>5</ping_packetloss_threshold>
-        </testCase>
-
-        <testCase id="040604">
-		<class>Iperf</class>
-		<desc>iperf (5MHz - DL/15Mbps/UDP)(30 sec)(single-ue profile)</desc>
-		<iperf_args>-u -b 15M -t 30 -i 1</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>single-ue</iperf_profile>
-        </testCase>
-
-	<testCase id="040642">
-		<class>Iperf</class>
-		<desc>iperf (5MHz - UL/9Mbps/UDP)(30 sec)(single-ue profile)</desc>
-		<iperf_args>-u -b 9M -t 30 -i 1 -R</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>single-ue</iperf_profile>
-	</testCase>
-
-        <testCase id="040511">
-                <class>Ping</class>
-                <desc>ping (10MHz - 20 sec)</desc>
-                <ping_args>-c 20</ping_args>
-                <ping_packetloss_threshold>5</ping_packetloss_threshold>
-        </testCase>
-
-        <testCase id="040614">
-		<class>Iperf</class>
-		<desc>iperf (10MHz - DL/32Mbps/UDP)(30 sec)(single-ue profile)</desc>
-		<iperf_args>-u -b 32M -t 30 -i 1</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>single-ue</iperf_profile>
-        </testCase>
-
-	<testCase id="040652">
-		<class>Iperf</class>
-		<desc>iperf (10MHz - UL/20Mbps/UDP)(30 sec)(single-ue profile)</desc>
-		<iperf_args>-u -b 20M -t 30 -i 1 -R</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>single-ue</iperf_profile>
-	</testCase>
-
-        <testCase id="040521">
-                <class>Ping</class>
-                <desc>ping (20MHz - 20 sec)</desc>
-                <ping_args>-c 20</ping_args>
-                <ping_packetloss_threshold>5</ping_packetloss_threshold>
-        </testCase>
-
-        <testCase id="040624">
-		<class>Iperf</class>
-		<desc>iperf (20MHz - DL/70Mbps/UDP)(30 sec)(single-ue profile)</desc>
-		<iperf_args>-u -b 70M -t 30 -i 1</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>single-ue</iperf_profile>
-        </testCase>
-
-	<testCase id="040662">
-		<class>Iperf</class>
-		<desc>iperf (20MHz - UL/20Mbps/UDP)(30 sec)(single-ue profile)</desc>
-		<iperf_args>-u -b 20M -t 30 -i 1 -R</iperf_args>
-		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
-		<iperf_profile>single-ue</iperf_profile>
-	</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>
-
-	<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/if4p5_usrp210_band7_build.xml b/ci-scripts/xml_files/if4p5_usrp210_band7_build.xml
new file mode 100644
index 0000000000000000000000000000000000000000..a0be9253dbd7878cbef23c64b81d2e8ab09ffa21
--- /dev/null
+++ b/ci-scripts/xml_files/if4p5_usrp210_band7_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 040101
+	</TestCaseRequestedList>
+	<TestCaseExclusionList>
+	</TestCaseExclusionList>
+
+	<testCase id="010101">
+		<class>Build_eNB</class>
+		<desc>Build eNB (USRP -- Ethernet Fronthaul)</desc>
+		<Build_eNB_args>-t ETHERNET -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/if4p5_usrp210_band7_epc_closure.xml b/ci-scripts/xml_files/if4p5_usrp210_band7_epc_closure.xml
new file mode 100644
index 0000000000000000000000000000000000000000..8587db959dde6db2d6485cc388bc3026643ee36f
--- /dev/null
+++ b/ci-scripts/xml_files/if4p5_usrp210_band7_epc_closure.xml
@@ -0,0 +1,48 @@
+<!--
+
+ 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/if4p5_usrp210_band7_test_05mhz.xml b/ci-scripts/xml_files/if4p5_usrp210_band7_test_05mhz.xml
new file mode 100644
index 0000000000000000000000000000000000000000..b0501e9875fea9822335db9a0e8d07a01dda97ba
--- /dev/null
+++ b/ci-scripts/xml_files/if4p5_usrp210_band7_test_05mhz.xml
@@ -0,0 +1,103 @@
+<!--
+
+ 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-05</htmlTabRef>
+	<htmlTabName>Test-05MHz</htmlTabName>
+	<htmlTabIcon>tasks</htmlTabIcon>
+	<TestCaseRequestedList>
+ 040101
+ 030101 030102 040301 040501 040604 040642 040401 040201 030201 030202
+	</TestCaseRequestedList>
+	<TestCaseExclusionList>
+	</TestCaseExclusionList>
+
+	<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>
+		<eNB_instance>1</eNB_instance>
+	</testCase>
+
+	<testCase id="030102">
+		<class>Initialize_eNB</class>
+		<desc>Initialize RCC (FDD/Band7/5MHz)</desc>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/rcc.band7.tm1.if4p5.lo.25PRB.usrpb210.conf</Initialize_eNB_args>
+		<eNB_instance>0</eNB_instance>
+	</testCase>
+
+	<testCase id="030201">
+		<class>Terminate_eNB</class>
+		<desc>Terminate RCC</desc>
+		<eNB_instance>0</eNB_instance>
+	</testCase>
+
+	<testCase id="030202">
+		<class>Terminate_eNB</class>
+		<desc>Terminate RRU</desc>
+		<eNB_instance>1</eNB_instance>
+	</testCase>
+
+	<testCase id="040101">
+		<class>Initialize_UE</class>
+		<desc>Initialize UE</desc>
+	</testCase>
+
+	<testCase id="040201">
+		<class>Terminate_UE</class>
+		<desc>Terminate UE</desc>
+	</testCase>
+
+        <testCase id="040301">
+                <class>Attach_UE</class>
+                <desc>Attach UE</desc>
+        </testCase>
+
+        <testCase id="040401">
+                <class>Detach_UE</class>
+                <desc>Detach UE</desc>
+        </testCase>
+
+        <testCase id="040501">
+                <class>Ping</class>
+                <desc>ping (5MHz - 20 sec)</desc>
+                <ping_args>-c 20</ping_args>
+                <ping_packetloss_threshold>5</ping_packetloss_threshold>
+        </testCase>
+
+        <testCase id="040604">
+		<class>Iperf</class>
+		<desc>iperf (5MHz - DL/15Mbps/UDP)(30 sec)(single-ue profile)</desc>
+		<iperf_args>-u -b 15M -t 30 -i 1</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>single-ue</iperf_profile>
+        </testCase>
+
+	<testCase id="040642">
+		<class>Iperf</class>
+		<desc>iperf (5MHz - UL/9Mbps/UDP)(30 sec)(single-ue profile)</desc>
+		<iperf_args>-u -b 9M -t 30 -i 1 -R</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>single-ue</iperf_profile>
+	</testCase>
+
+</testCaseList>
diff --git a/ci-scripts/xml_files/if4p5_usrp210_band7_test_10mhz.xml b/ci-scripts/xml_files/if4p5_usrp210_band7_test_10mhz.xml
new file mode 100644
index 0000000000000000000000000000000000000000..88fb30b840caaf8f5fe686b19b59b6d55e045227
--- /dev/null
+++ b/ci-scripts/xml_files/if4p5_usrp210_band7_test_10mhz.xml
@@ -0,0 +1,103 @@
+<!--
+
+ 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</htmlTabRef>
+	<htmlTabName>Test-10MHz</htmlTabName>
+	<htmlTabIcon>tasks</htmlTabIcon>
+	<TestCaseRequestedList>
+ 040101
+ 030111 030112 040301 040511 040614 040652 040401 040201 030201 030202
+	</TestCaseRequestedList>
+	<TestCaseExclusionList>
+	</TestCaseExclusionList>
+
+	<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>
+		<eNB_instance>1</eNB_instance>
+	</testCase>
+
+	<testCase id="030112">
+		<class>Initialize_eNB</class>
+		<desc>Initialize RCC (FDD/Band7/10MHz)</desc>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/rcc.band7.tm1.if4p5.lo.50PRB.usrpb210.conf</Initialize_eNB_args>
+		<eNB_instance>0</eNB_instance>
+	</testCase>
+
+	<testCase id="030201">
+		<class>Terminate_eNB</class>
+		<desc>Terminate RCC</desc>
+		<eNB_instance>0</eNB_instance>
+	</testCase>
+
+	<testCase id="030202">
+		<class>Terminate_eNB</class>
+		<desc>Terminate RRU</desc>
+		<eNB_instance>1</eNB_instance>
+	</testCase>
+
+	<testCase id="040101">
+		<class>Initialize_UE</class>
+		<desc>Initialize UE</desc>
+	</testCase>
+
+	<testCase id="040201">
+		<class>Terminate_UE</class>
+		<desc>Terminate UE</desc>
+	</testCase>
+
+        <testCase id="040301">
+                <class>Attach_UE</class>
+                <desc>Attach UE</desc>
+        </testCase>
+
+        <testCase id="040401">
+                <class>Detach_UE</class>
+                <desc>Detach UE</desc>
+        </testCase>
+
+        <testCase id="040511">
+                <class>Ping</class>
+                <desc>ping (10MHz - 20 sec)</desc>
+                <ping_args>-c 20</ping_args>
+                <ping_packetloss_threshold>5</ping_packetloss_threshold>
+        </testCase>
+
+        <testCase id="040614">
+		<class>Iperf</class>
+		<desc>iperf (10MHz - DL/32Mbps/UDP)(30 sec)(single-ue profile)</desc>
+		<iperf_args>-u -b 32M -t 30 -i 1</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>single-ue</iperf_profile>
+        </testCase>
+
+	<testCase id="040652">
+		<class>Iperf</class>
+		<desc>iperf (10MHz - UL/5Mbps/UDP)(30 sec)(single-ue profile)</desc>
+		<iperf_args>-u -b 5M -t 30 -i 1 -R</iperf_args>
+		<iperf_packetloss_threshold>60</iperf_packetloss_threshold>
+		<iperf_profile>single-ue</iperf_profile>
+	</testCase>
+
+</testCaseList>
diff --git a/ci-scripts/xml_files/if4p5_usrp210_band7_test_20mhz.xml b/ci-scripts/xml_files/if4p5_usrp210_band7_test_20mhz.xml
new file mode 100644
index 0000000000000000000000000000000000000000..798fc1bc8f6fa301e84f155e1656cd6f31cbf4e2
--- /dev/null
+++ b/ci-scripts/xml_files/if4p5_usrp210_band7_test_20mhz.xml
@@ -0,0 +1,103 @@
+<!--
+
+ 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-20</htmlTabRef>
+	<htmlTabName>Test-20MHz</htmlTabName>
+	<htmlTabIcon>tasks</htmlTabIcon>
+	<TestCaseRequestedList>
+ 040101
+ 030121 030122 040301 040521 040624 040662 040401 040201 030201 030202
+	</TestCaseRequestedList>
+	<TestCaseExclusionList>
+	</TestCaseExclusionList>
+
+	<testCase id="030121">
+		<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>
+		<eNB_instance>1</eNB_instance>
+	</testCase>
+
+	<testCase id="030122">
+		<class>Initialize_eNB</class>
+		<desc>Initialize RCC (FDD/Band7/20MHz)</desc>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/rcc.band7.tm1.if4p5.lo.100PRB.usrpb210.conf</Initialize_eNB_args>
+		<eNB_instance>0</eNB_instance>
+	</testCase>
+
+	<testCase id="030201">
+		<class>Terminate_eNB</class>
+		<desc>Terminate RCC</desc>
+		<eNB_instance>0</eNB_instance>
+	</testCase>
+
+	<testCase id="030202">
+		<class>Terminate_eNB</class>
+		<desc>Terminate RRU</desc>
+		<eNB_instance>1</eNB_instance>
+	</testCase>
+
+	<testCase id="040101">
+		<class>Initialize_UE</class>
+		<desc>Initialize UE</desc>
+	</testCase>
+
+	<testCase id="040201">
+		<class>Terminate_UE</class>
+		<desc>Terminate UE</desc>
+	</testCase>
+
+        <testCase id="040301">
+                <class>Attach_UE</class>
+                <desc>Attach UE</desc>
+        </testCase>
+
+        <testCase id="040401">
+                <class>Detach_UE</class>
+                <desc>Detach UE</desc>
+        </testCase>
+
+        <testCase id="040521">
+                <class>Ping</class>
+                <desc>ping (20MHz - 20 sec)</desc>
+                <ping_args>-c 20</ping_args>
+                <ping_packetloss_threshold>5</ping_packetloss_threshold>
+        </testCase>
+
+        <testCase id="040624">
+		<class>Iperf</class>
+		<desc>iperf (20MHz - DL/50Mbps/UDP)(30 sec)(single-ue profile)</desc>
+		<iperf_args>-u -b 50M -t 30 -i 1</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>single-ue</iperf_profile>
+        </testCase>
+
+	<testCase id="040662">
+		<class>Iperf</class>
+		<desc>iperf (20MHz - UL/10Mbps/UDP)(30 sec)(single-ue profile)</desc>
+		<iperf_args>-u -b 10M -t 30 -i 1 -R</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+		<iperf_profile>single-ue</iperf_profile>
+	</testCase>
+
+</testCaseList>
diff --git a/ci-scripts/xml_files/test_case_list_template.xml b/ci-scripts/xml_files/test_case_list_template.xml
index 25519dcd039f9a9ab1d479e83769a1d834e4acb9..bdf16af0e313874aeb2920b2c1556d568081c31a 100644
--- a/ci-scripts/xml_files/test_case_list_template.xml
+++ b/ci-scripts/xml_files/test_case_list_template.xml
@@ -107,6 +107,28 @@
 		<desc>Reboot UE</desc>
 	</testCase>
 
+	<!-- CAT-M UE class command references -->
+
+	<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>
+
 	<!-- EPC class command references -->
 
         <testCase id="050101">
diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt
index f540084cb972ce30387d66a3e841b6b57a3c494b..869a17432c8127aaeeed24c39f8913792fa900ea 100644
--- a/cmake_targets/CMakeLists.txt
+++ b/cmake_targets/CMakeLists.txt
@@ -182,7 +182,6 @@ set(CMAKE_EXE_LINKER_FLAGS  "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath -Wl,${CMAKE_CU
 #########################
 # set a flag for changes in the source code
 # these changes are related to hardcoded path to include .h files
-add_definitions(-DCMAKER)
 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g -DMALLOC_CHECK_=3")
 set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS} -g -DMALLOC_CHECK_=3 -O2")
 
@@ -226,13 +225,11 @@ add_definitions("-DFIRMWARE_VERSION=\"${FIRMWARE_VERSION}\"")
 add_definitions("-DPACKAGE_VERSION=\"Branch: ${GIT_BRANCH} Abrev. Hash: ${GIT_COMMIT_HASH} Date: ${GIT_COMMIT_DATE}\"")
 add_definitions("-DPACKAGE_BUGREPORT=\"openair4g-devel@lists.eurecom.fr\"")
 
-add_boolean_option(PDCP_SPLIT True "enable PDCP split")
-
 
 # Debug related options
 #########################################
 add_boolean_option(ASN_DEBUG           False "ASN1 coder/decoder Debug")
-add_boolean_option(EMIT_ASN_DEBUG      False "ASN1 coder/decoder Debug")
+add_boolean_option(ASN_EMIT_DEBUG      False "ASN1 coder/decoder Debug")
 add_boolean_option(MSG_PRINT           False "print debug messages")
 add_boolean_option(DISABLE_XER_PRINT   False "print XER Format")
 add_boolean_option(XER_PRINT           False "print XER Format")
@@ -260,17 +257,17 @@ add_boolean_option(ENABLE_ITTI True "ITTI is internal messaging, should remain e
 set (OCP_ITTI ${OPENAIR_DIR}/common/utils/ocp_itti)
 if (${ENABLE_ITTI})
   add_library(ITTI
-    # add .h files if depend on (this one is generated)
     ${OCP_ITTI}/intertask_interface.cpp
     ${OPENAIR_DIR}/common/utils/backtrace.c
     ${OPENAIR_DIR}/common/utils/memory_pools.c
     )
+add_dependencies(ITTI rrc_flag)
   set(ITTI_LIB ITTI)
   set(GTPU_need_ITTI ${OPENAIR3_DIR}/GTPV1-U/gtpv1u_eNB.c)
 endif (${ENABLE_ITTI})
 
 #############################
-# ASN.1 grammar C code generation & dependancies
+# ASN.1 grammar C code generation & dependencies
 ################################
 # A difficulty: asn1c generates C code of a un-predictable list of files
 # so, generate the c from asn1c once at cmake run time
@@ -278,8 +275,6 @@ endif (${ENABLE_ITTI})
 # (so creating new asn.1 objects instead of modifying the object attributes)
 # New C code source file, cmake must be re-run (instead of re-running make only)
 #############
-# set(asn1c_call "${OPENAIR_CMAKE}/tools/generate_asn1")
-# set(fix_asn1c_call "${OPENAIR_CMAKE}/tools/fix_asn1")
 set(asn1_generated_dir ${OPENAIR_BIN_DIR})
 
 set(protoc_call "${OPENAIR_CMAKE}/tools/generate_protobuf")
@@ -290,61 +285,54 @@ set(protobuf_generated_dir ${OPENAIR_BIN_DIR})
 add_list2_option(RRC_ASN1_VERSION "Rel14" "ASN.1 version of RRC interface" "Rel8" "Rel10" "Rel14" "CBA")
 
 if (${RRC_ASN1_VERSION} STREQUAL "Rel8")
-  make_version(RRC_VERSION 8 6 0)
+  make_version(LTE_RRC_VERSION 8 6 0)
   set (RRC_GRAMMAR ${OPENAIR2_DIR}/RRC/LTE/MESSAGES/asn1c/ASN1_files/EUTRA-RRC-Definitions-86.asn)
 elseif (${RRC_ASN1_VERSION} STREQUAL "CBA")
-  make_version(RRC_VERSION 10 2 0)
+  make_version(LTE_RRC_VERSION 10 2 0)
   add_definitions(-DCBA)
   set (RRC_GRAMMAR ${OPENAIR2_DIR}/RRC/LTE/MESSAGES/asn1c/ASN1_files/EUTRA-RRC-Definitions-a20-lola.asn)
 elseif (${RRC_ASN1_VERSION} STREQUAL "Rel10")
-  make_version(RRC_VERSION 10 2 0)
+  make_version(LTE_RRC_VERSION 10 2 0)
   set (RRC_GRAMMAR ${OPENAIR2_DIR}/RRC/LTE/MESSAGES/asn1c/ASN1_files/EUTRA-RRC-Definitions-a20.asn)
 elseif (${RRC_ASN1_VERSION} STREQUAL "Rel11")
-  make_version(RRC_VERSION 11 18 0)
+  make_version(LTE_RRC_VERSION 11 18 0)
   set (RRC_GRAMMAR ${OPENAIR2_DIR}/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-11.18.0.asn1)
 elseif (${RRC_ASN1_VERSION} STREQUAL "Rel12")
-  make_version(RRC_VERSION 12 16 0)
+  make_version(LTE_RRC_VERSION 12 16 0)
   set (RRC_GRAMMAR ${OPENAIR2_DIR}/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-12.16.0.asn1)
 elseif (${RRC_ASN1_VERSION} STREQUAL "Rel13")
-  make_version(RRC_VERSION 13 9 1)
+  make_version(LTE_RRC_VERSION 13 9 1)
   set (RRC_GRAMMAR ${OPENAIR2_DIR}/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-13.9.1.asn1)
 elseif (${RRC_ASN1_VERSION} STREQUAL "Rel14")
-  make_version(RRC_VERSION 14 7 0)
+  make_version(LTE_RRC_VERSION 14 7 0)
   set (RRC_GRAMMAR ${OPENAIR2_DIR}/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-14.7.0.asn1)
 elseif (${RRC_ASN1_VERSION} STREQUAL "Rel15")
-  make_version(RRC_VERSION 15 2 2)
+  make_version(LTE_RRC_VERSION 15 2 2)
   set (RRC_GRAMMAR ${OPENAIR2_DIR}/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-15.2.2.asn1)
 endif  (${RRC_ASN1_VERSION} STREQUAL "Rel8")
-add_definitions(-DRRC_VERSION=${RRC_VERSION})
+add_definitions(-DLTE_RRC_VERSION=${LTE_RRC_VERSION})
 set (RRC_FULL_DIR ${asn1_generated_dir}/RRC_${RRC_ASN1_VERSION})
-message("calling asn1c -pdu=all -fcompound-names -gen-PER -no-gen-OER -no-gen-example -D ${RRC_FULL_DIR} ${RRC_GRAMMAR}")
-execute_process(COMMAND mkdir -p ${RRC_FULL_DIR}
-                COMMAND env asn1c -pdu=all -fcompound-names -gen-PER -no-gen-OER -no-gen-example -D ${RRC_FULL_DIR} ${RRC_GRAMMAR}
-                RESULT_VARIABLE ret
-                OUTPUT_QUIET
-                ERROR_QUIET)
+
+# Warning: if you modify ASN.1 source file to generate new C files, cmake should be re-run instead of make
+execute_process(COMMAND ${OPENAIR_CMAKE}/tools/make_asn1c_includes.sh "${RRC_FULL_DIR}" "${RRC_GRAMMAR}" "LTE_"
+                RESULT_VARIABLE ret)
 if (NOT ${ret} STREQUAL 0)
   message(FATAL_ERROR "${ret}: error")
 endif (NOT ${ret} STREQUAL 0)
-
 file(GLOB rrc_source ${RRC_FULL_DIR}/*.c)
-file(GLOB rrc_h ${RRC_FULL_DIR}/*.h)
-set(rrc_h ${rrc_h} ${RRC_FULL_DIR}/asn_constant.h)
+add_custom_target (
+  rrc_flag ALL
+  ${OPENAIR_CMAKE}/tools/make_asn1c_includes.sh "${RRC_FULL_DIR}" "${RRC_GRAMMAR}" "LTE_"
+  DEPENDS ${RRC_GRAMMAR}
+  )
+
 set_source_files_properties(${rrc_source} PROPERTIES COMPILE_FLAGS -w) # suppress warnings from generated code
-add_library(RRC_LIB ${rrc_h} ${rrc_source}
+add_library(RRC_LIB ${rrc_source}
     ${OPENAIR2_DIR}/RRC/LTE/MESSAGES/asn1_msg.c
     ${OPENAIR2_DIR}/RRC/LTE/MESSAGES/asn1_msg_NB_IoT.c)
+add_dependencies(RRC_LIB rrc_flag)
 include_directories ("${RRC_FULL_DIR}")
 
-# add the command to generate the source code
-# Warning: if you modify ASN.1 source file to generate new C files, cmake should be re-run instead of make
-add_custom_command (
-  OUTPUT ${RRC_FULL_DIR}/asn_constant.h
-  COMMAND mkdir -p ${RRC_FULL_DIR}
-  COMMAND env asn1c -pdu=all -fcompound-names -gen-PER -no-gen-OER -no-gen-example -D ${RRC_FULL_DIR} ${RRC_GRAMMAR}
-  DEPENDS ${RRC_GRAMMAR}
-  )
-
 # S1AP
 # Same limitation as described in RRC: unknown generated file list
 # so we generate it at cmake time
@@ -380,31 +368,26 @@ endif(${S1AP_RELEASE} STREQUAL "R8")
 add_definitions(-DS1AP_VERSION=${S1AP_VERSION})
 set(S1AP_ASN_DIR ${S1AP_DIR}/MESSAGES/ASN1/${S1AP_RELEASE})
 set(S1AP_C_DIR ${asn1_generated_dir}/S1AP_${S1AP_RELEASE})
-message("calling ASN1C_PREFIX=S1AP_ asn1c -pdu=all -fcompound-names -fno-include-deps -gen-PER -no-gen-OER -no-gen-example -D ${S1AP_C_DIR} ${S1AP_ASN_DIR}/${S1AP_ASN_FILES}")
-execute_process(COMMAND mkdir -p ${S1AP_C_DIR}
-                COMMAND env "ASN1C_PREFIX=S1AP_" asn1c -pdu=all -fcompound-names -fno-include-deps -gen-PER -no-gen-OER -no-gen-example -D ${S1AP_C_DIR} ${S1AP_ASN_DIR}/${S1AP_ASN_FILES}
-                RESULT_VARIABLE ret
-                OUTPUT_QUIET
-                ERROR_QUIET)
 
+# Warning: if you modify ASN.1 source file to generate new C files, cmake should be re-run instead of make
+execute_process(COMMAND ${OPENAIR_CMAKE}/tools/make_asn1c_includes.sh "${S1AP_C_DIR}" "${S1AP_ASN_DIR}/${S1AP_ASN_FILES}" "S1AP_" -fno-include-deps
+                RESULT_VARIABLE ret)
 if (NOT ${ret} STREQUAL 0)
   message(FATAL_ERROR "${ret}: error")
 endif (NOT ${ret} STREQUAL 0)
 file(GLOB S1AP_source ${S1AP_C_DIR}/*.c)
 
-file(GLOB s1ap_h ${S1AP_C_DIR}/*.h)
-set(s1ap_h ${s1ap_h})
-
-add_custom_command (
-  OUTPUT ${S1AP_C_DIR}/S1AP_asn_constant.h
-  COMMAND mkdir -p ${S1AP_C_DIR}
-  COMMAND env "ASN1C_PREFIX=S1AP_" asn1c -pdu=all -fcompound-names -fno-include-deps -gen-PER -no-gen-OER -no-gen-example -D ${S1AP_C_DIR} ${S1AP_ASN_DIR}/${S1AP_ASN_FILES}
-  DEPENDS ${S1AP_ASN_DIR}/${S1AP_ASN_FILES}
+add_custom_target (
+  s1ap_flag ALL
+  ${OPENAIR_CMAKE}/tools/make_asn1c_includes.sh "${S1AP_C_DIR}" "${S1AP_ASN_DIR}/${S1AP_ASN_FILES}" "S1AP_" -fno-include-deps
+  DEPENDS  "${S1AP_ASN_DIR}/${S1AP_ASN_FILES}"
 )
+
 add_library(S1AP_LIB
   ${S1AP_source}
   ${S1AP_DIR}/s1ap_common.c
   )
+add_dependencies(S1AP_LIB rrc_flag s1ap_flag)
 
 include_directories ("${S1AP_C_DIR}")
 include_directories ("${S1AP_DIR}")
@@ -423,6 +406,7 @@ add_library(S1AP_ENB
   ${S1AP_DIR}/s1ap_eNB_trace.c
   ${S1AP_DIR}/s1ap_eNB_ue_context.c
   )
+add_dependencies(S1AP_ENB rrc_flag s1ap_flag)
 
 #X2AP
 # Same limitation as described in RRC/S1AP: unknown generated file list
@@ -450,24 +434,19 @@ endif(${X2AP_RELEASE} STREQUAL "R8")
 add_definitions(-DX2AP_VERSION=${X2AP_VERSION})
 set(X2AP_ASN_DIR ${X2AP_DIR}/MESSAGES/ASN1/${X2AP_RELEASE})
 set(X2AP_C_DIR ${asn1_generated_dir}/X2AP_${X2AP_RELEASE})
-message("calling ASN1C_PREFIX=X2AP_ asn1c -pdu=all -fcompound-names -fno-include-deps -gen-PER -no-gen-OER -no-gen-example -D ${X2AP_C_DIR} ${X2AP_ASN_DIR}/${X2AP_ASN_FILES}")
-execute_process(COMMAND mkdir -p ${X2AP_C_DIR}
-                COMMAND env "ASN1C_PREFIX=X2AP_" asn1c -pdu=all -fcompound-names -fno-include-deps -gen-PER -no-gen-OER -no-gen-example -D ${X2AP_C_DIR} ${X2AP_ASN_DIR}/${X2AP_ASN_FILES}
-                RESULT_VARIABLE ret
-                OUTPUT_QUIET
-                ERROR_QUIET)
+
+# Warning: if you modify ASN.1 source file to generate new C files, cmake should be re-run instead of make
+execute_process(COMMAND ${OPENAIR_CMAKE}/tools/make_asn1c_includes.sh "${X2AP_C_DIR}" "${X2AP_ASN_DIR}/${X2AP_ASN_FILES}"  "X2AP_" -fno-include-deps
+                RESULT_VARIABLE ret)
 if (NOT ${ret} STREQUAL 0)
   message(FATAL_ERROR "${ret}: error")
 endif (NOT ${ret} STREQUAL 0)
-file(GLOB X2AP_source ${X2AP_C_DIR}/*.c)
 
-file(GLOB x2ap_h ${X2AP_C_DIR}/*.h)
-set(x2ap_h ${x2ap_h})
+file(GLOB X2AP_source ${X2AP_C_DIR}/*.c)
 
-add_custom_command (
-  OUTPUT ${X2AP_C_DIR}/X2AP_asn_constant.h
-  COMMAND mkdir -p ${X2AP_C_DIR}
-  COMMAND env "ASN1C_PREFIX=X2AP_" asn1c -pdu=all -fcompound-names -fno-include-deps -gen-PER -no-gen-OER -no-gen-example -D ${X2AP_C_DIR} ${X2AP_ASN_DIR}/${X2AP_ASN_FILES}
+add_custom_target (
+  x2_flag ALL
+  COMMAND ${OPENAIR_CMAKE}/tools/make_asn1c_includes.sh "${X2AP_C_DIR}" "${X2AP_ASN_DIR}/${X2AP_ASN_FILES}"  "X2AP_" -fno-include-deps
   DEPENDS ${X2AP_ASN_DIR}/${X2AP_ASN_FILES}
   )
 
@@ -475,6 +454,7 @@ add_library(X2AP_LIB
   ${X2AP_source}
   ${X2AP_DIR}/x2ap_common.c
   )
+add_dependencies(X2AP_LIB rrc_flag x2_flag)
 
 include_directories ("${X2AP_C_DIR}")
 include_directories ("${X2AP_DIR}")
@@ -488,6 +468,7 @@ add_library(X2AP_ENB
   ${X2AP_DIR}/x2ap_eNB_management_procedures.c
   ${X2AP_DIR}/x2ap_eNB_generate_messages.c
  )
+add_dependencies(X2AP_ENB rrc_flag x2_flag)
 
 # F1AP
 ##############
@@ -602,6 +583,15 @@ set(TPLIB_ETHERNET_SOURCE
   )
 add_library(oai_eth_transpro MODULE ${TPLIB_ETHERNET_SOURCE} )
 
+include_directories("${OPENAIR_TARGETS}/ARCH/IRIS/USERSPACE/LIB/")
+set(option_HWIRISLIB_lib "-l SoapySDR")
+set(HWLIB_IRIS_SOURCE
+        ${OPENAIR_TARGETS}/ARCH/IRIS/USERSPACE/LIB/iris_lib.cpp
+        )
+add_library(oai_irisdevif MODULE ${HWLIB_IRIS_SOURCE})
+target_include_directories(oai_irisdevif PRIVATE /usr/local/lib/SoapySDR/modules0.7/)
+target_link_libraries(oai_irisdevif SoapySDR)
+
 include_directories("${OPENAIR_TARGETS}/ARCH/mobipass/")
 set(TPLIB_MOBIPASS_SOURCE
   ${OPENAIR_TARGETS}/ARCH/mobipass/interface.c
@@ -667,6 +657,7 @@ add_boolean_option(MESSAGE_CHART_GENERATOR_PHY     False "trace some PHY exchang
 add_boolean_option(UE_EXPANSION             False         "enable UE_EXPANSION with max 256 UE")
 add_boolean_option(PHY_TX_THREAD            False         "enable UE_EXPANSION with max 256 UE")
 add_boolean_option(PRE_SCD_THREAD           False         "enable UE_EXPANSION with max 256 UE")
+add_boolean_option(UESIM_EXPANSION          False         "enable UESIM_EXPANSION with max 256 UE")
 
 #############################################################################
 # Flag for UE compilation to avoid issues in common eNB/UE PDCP/RLC functions
@@ -686,7 +677,6 @@ add_boolean_option(ENABLE_VCD              True  "always true now, time measurem
 add_boolean_option(ENABLE_VCD_FIFO         True  "time measurements of proc calls and var displays sent to FIFO (one more thread)")
 add_boolean_option(LINUX                   False "used in weird memcpy() in pdcp.c ???")
 add_boolean_option(LINUX_LIST              False "used only in lists.c: either use OAI implementation of lists or Linux one (should be True, but it is False")
-add_boolean_option(LOG_NO_THREAD           True  "Disable thread for log, seems always set to true")
 add_boolean_option(OPENAIR_LTE             True "Seems legacy: keep it to true")
 
 ##########################
@@ -934,6 +924,7 @@ add_library(FLEXRAN_AGENT
   ${OPENAIR2_DIR}/ENB_APP/CONTROL_MODULES/MAC/flexran_agent_mac_internal.c
   ${OPENAIR2_DIR}/ENB_APP/CONTROL_MODULES/MAC/flexran_agent_mac_slice_verification.c
   )
+add_dependencies(FLEXRAN_AGENT rrc_flag)
 set(FLEXRAN_AGENT_LIB FLEXRAN_AGENT)
 #include_directories(${OPENAIR2_DIR}/ENB_APP)
 
@@ -948,39 +939,38 @@ MARK_AS_ADVANCED(LIBYAML_INCLUDE_DIR LIBYAML_LIBRARIES)
 
 #set(PROTOBUF_LIB "protobuf") #for Cpp
 
-if (PDCP_SPLIT)
-  # set the version of protobuf messages, V3 not supported yet
-  add_list1_option(FSPT_VERSION V2 "FSPT MSG  protobuf  grammar version" V2 V3)
+# set the version of protobuf messages, V3 not supported yet
+add_list1_option(FSPT_VERSION V2 "FSPT MSG  protobuf  grammar version" V2 V3)
+
+if (${FSPT_VERSION} STREQUAL "V2")
+  set (FSPTDIR V2)
+elseif (${FSPT_VERSION} STREQUAL "V3")
+  set (FSPTDIR V3)
+endif(${FSPT_VERSION} STREQUAL "V2")
 
-  if (${FSPT_VERSION} STREQUAL "V2")
-    set (FSPTDIR V2)
-  elseif (${FSPT_VERSION} STREQUAL "V3")
-    set (FSPTDIR V3)
-  endif(${FSPT_VERSION} STREQUAL "V2")
+set(FSPT_MSG_DIR ${OPENAIR_DIR}/targets/COMMON/MESSAGES/${FSPTDIR} )
+set(FSPT_MSG_FILES
+  ${FSPT_MSG_DIR}/flexsplit.proto
+  )
 
-  set(FSPT_MSG_DIR ${OPENAIR_DIR}/targets/COMMON/MESSAGES/${FSPTDIR} )
-  set(FSPT_MSG_FILES
-    ${FSPT_MSG_DIR}/flexsplit.proto
-    )
+set(FSPT_C_DIR ${protobuf_generated_dir}/FSPT_${FSPTDIR})
+message("calling protoc_call=${protoc_call} FSPT_C_DIR=${FSPT_C_DIR} FSPT_MSG_DIR=${FSPT_MSG_DIR} FSPT_MSG_FILES=${FSPT_MSG_FILES}")
+execute_process(COMMAND ${protoc_call} ${FSPT_C_DIR} ${FSPT_MSG_DIR} ${FSPT_MSG_FILES})
+file(GLOB FSPT_source ${FSPT_C_DIR}/*.c)
+set(FSPT_OAI_generated
+  ${FSPT_C_DIR}/flexsplit.pb-c.c
+  )
 
-  set(FSPT_C_DIR ${protobuf_generated_dir}/FSPT_${FSPTDIR})
-  message("calling protoc_call=${protoc_call} FSPT_C_DIR=${FSPT_C_DIR} FSPT_MSG_DIR=${FSPT_MSG_DIR} FSPT_MSG_FILES=${FSPT_MSG_FILES}")
-  execute_process(COMMAND ${protoc_call} ${FSPT_C_DIR} ${FSPT_MSG_DIR} ${FSPT_MSG_FILES})
-  file(GLOB FSPT_source ${FSPT_C_DIR}/*.c)
-  set(FSPT_OAI_generated
-    ${FSPT_C_DIR}/flexsplit.pb-c.c
-    )
-  
-  file(GLOB fspt_h ${FSPT_C_DIR}/*.h)
-  set(fspt_h ${fspt_h} )
-  
-  add_library(FSPT_MSG
-    ${FSPT_OAI_generated}
-    ${FSPT_source}
-    )
-  set(FSPT_MSG_LIB FSPT_MSG)
-  message("fspt c dir is : ${FSPT_C_DIR}")
-  include_directories (${FSPT_C_DIR})
+file(GLOB fspt_h ${FSPT_C_DIR}/*.h)
+set(fspt_h ${fspt_h} )
+
+add_library(FSPT_MSG
+  ${FSPT_OAI_generated}
+  ${FSPT_source}
+  )
+set(FSPT_MSG_LIB FSPT_MSG)
+message("fspt c dir is : ${FSPT_C_DIR}")
+include_directories (${FSPT_C_DIR})
 
 #  add_library(ASYNC_IF
 #    ${OPENAIR2_DIR}/UTIL/ASYNC_IF/socket_link.c
@@ -991,22 +981,21 @@ if (PDCP_SPLIT)
 #  set(ASYNC_IF_LIB ASYNC_IF)
 #  include_directories(${OPENAIR2_DIR}/UTIL/ASYNC_IF)
 
-  add_library(PROTO_AGENT
-    ${OPENAIR2_DIR}/LAYER2/PROTO_AGENT/proto_agent_handler.c
-    ${OPENAIR2_DIR}/LAYER2/PROTO_AGENT/proto_agent_common.c
-    ${OPENAIR2_DIR}/LAYER2/PROTO_AGENT/proto_agent.c
-    ${OPENAIR2_DIR}/LAYER2/PROTO_AGENT/proto_agent_net_comm.c
-    ${OPENAIR2_DIR}/LAYER2/PROTO_AGENT/proto_agent_async.c
-    )
-  set(PROTO_AGENT_LIB PROTO_AGENT)
-  include_directories(${OPENAIR2_DIR}/LAYER2/PROTO_AGENT)
+add_library(PROTO_AGENT
+  ${OPENAIR2_DIR}/LAYER2/PROTO_AGENT/proto_agent_handler.c
+  ${OPENAIR2_DIR}/LAYER2/PROTO_AGENT/proto_agent_common.c
+  ${OPENAIR2_DIR}/LAYER2/PROTO_AGENT/proto_agent.c
+  ${OPENAIR2_DIR}/LAYER2/PROTO_AGENT/proto_agent_net_comm.c
+  ${OPENAIR2_DIR}/LAYER2/PROTO_AGENT/proto_agent_async.c
+  )
+set(PROTO_AGENT_LIB PROTO_AGENT)
+include_directories(${OPENAIR2_DIR}/LAYER2/PROTO_AGENT)
 
 
 
-  set(PROTOBUF_LIB "protobuf-c")
-  
-  #set(PROTOBUF_LIB "protobuf") #for Cpp
-endif()
+set(PROTOBUF_LIB "protobuf-c")
+
+#set(PROTOBUF_LIB "protobuf") #for Cpp
 
 add_library(HASHTABLE
   ${OPENAIR_DIR}/common/utils/hashtable/hashtable.c
@@ -1058,6 +1047,7 @@ set(UTIL_SRC
 #  ${OPENAIR2_DIR}/UTIL/OTG/otg_rx.c
   )
 add_library(UTIL ${UTIL_SRC})
+add_dependencies(UTIL rrc_flag)
 
 #set(OMG_SUMO_SRC
 #  ${OPENAIR2_DIR}/UTIL/OMG/client_traci_OMG.c
@@ -1097,12 +1087,14 @@ set(SCHED_SRC
   ${OPENAIR1_DIR}/SCHED/phy_procedures_lte_common.c
 )
 add_library(SCHED_LIB ${SCHED_SRC})
+add_dependencies(SCHED_LIB rrc_flag)
 
 set(SCHED_SRC_RU
   ${OPENAIR1_DIR}/SCHED/ru_procedures.c
   ${OPENAIR1_DIR}/SCHED/prach_procedures.c
 )
 add_library(SCHED_RU_LIB ${SCHED_SRC_RU})
+add_dependencies(SCHED_RU_LIB rrc_flag)
 
 set(SCHED_SRC_UE
   ${OPENAIR1_DIR}/SCHED_UE/phy_procedures_lte_ue.c
@@ -1112,6 +1104,7 @@ set(SCHED_SRC_UE
   ${OPENAIR1_DIR}/SCHED_UE/srs_pc.c
 )
 add_library(SCHED_UE_LIB ${SCHED_SRC_UE})
+add_dependencies(SCHED_UE_LIB rrc_flag)
 
 # nFAPI
 #################################
@@ -1163,6 +1156,7 @@ set(NFAPI_USER_SRC
   ${NFAPI_USER_DIR}/nfapi_vnf.c
 )
 add_library(NFAPI_USER_LIB ${NFAPI_USER_SRC})
+add_dependencies(NFAPI_USER_LIB rrc_flag)
 include_directories(${NFAPI_USER_DIR})
 
 # Layer 1
@@ -1181,9 +1175,6 @@ set(PHY_TURBOIF
 
 add_library(coding MODULE ${PHY_TURBOSRC} )
 set(PHY_SRC_COMMON
-  # depend on code generation from asn1c
-  ${RRC_FULL_DIR}/asn_constant.h
-  # actual source
   ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/dci_tools_common.c
   ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/lte_mcs.c
 #  ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/slss.c
@@ -1234,7 +1225,6 @@ set(PHY_SRC_COMMON
   )
 
 set(PHY_SRC
-  # actual source
   ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/pss.c
   ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/sss.c
   ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/sss_gen.c
@@ -1262,7 +1252,6 @@ set(PHY_SRC
   )
 
 set(PHY_SRC_RU
-  # actual source
   ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/if4_tools.c
   ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/if5_tools.c
   ${OPENAIR1_DIR}/PHY/MODULATION/slot_fep_ul.c
@@ -1276,7 +1265,6 @@ set(PHY_SRC_RU
   )
 
 set(PHY_SRC_UE
-  # actual source
   ${OPENAIR1_DIR}/PHY/LTE_UE_TRANSPORT/sss_ue.c
   ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/sss_gen.c
   ${OPENAIR1_DIR}/PHY/LTE_UE_TRANSPORT/dlsch_demodulation.c
@@ -1325,9 +1313,13 @@ if (${COMPILATION_AVX2} STREQUAL "True")
 endif ()
 
 add_library(PHY_COMMON ${PHY_SRC_COMMON})
+add_dependencies(PHY_COMMON rrc_flag)
 add_library(PHY ${PHY_SRC})
+add_dependencies(PHY rrc_flag)
 add_library(PHY_UE ${PHY_SRC_UE})
+add_dependencies(PHY_UE rrc_flag)
 add_library(PHY_RU ${PHY_SRC_RU})
+add_dependencies(PHY_RU rrc_flag)
 
 #Library for mex functions
 #########################3
@@ -1489,6 +1481,8 @@ set (MAC_SRC_UE
 set (ENB_APP_SRC
   ${OPENAIR2_DIR}/ENB_APP/enb_app.c
   ${OPENAIR2_DIR}/ENB_APP/enb_config.c
+  ${OPENAIR2_DIR}/ENB_APP/enb_config_SL.c
+  ${OPENAIR2_DIR}/ENB_APP/enb_config_eMTC.c
   ${OPENAIR2_DIR}/ENB_APP/RRC_config_tools.c
   )
 
@@ -1497,11 +1491,13 @@ add_library(L2
   ${MAC_SRC}
   ${ENB_APP_SRC})
 #  ${OPENAIR2_DIR}/RRC/L2_INTERFACE/openair_rrc_L2_interface.c)
+add_dependencies(L2 rrc_flag s1ap_flag x2_flag)
 
 add_library(L2_UE
   ${L2_SRC_UE}
   ${MAC_SRC_UE}
 )
+add_dependencies(L2_UE rrc_flag s1ap_flag x2_flag)
 
 include_directories(${NFAPI_USER_DIR})
 
@@ -1527,6 +1523,7 @@ set (GTPV1U_SRC
   ${GTPV1U_DIR}/gtpv1u_teid_pool.c
 )
 add_library(GTPV1U ${GTPV1U_SRC})
+add_dependencies(GTPV1U rrc_flag)
 
 set(SCTP_SRC
   ${OPENAIR3_DIR}/SCTP/sctp_common.c
@@ -1534,8 +1531,10 @@ set(SCTP_SRC
   ${OPENAIR3_DIR}/SCTP/sctp_eNB_itti_messaging.c
 )
 add_library(SCTP_CLIENT ${SCTP_SRC})
+add_dependencies(SCTP_CLIENT rrc_flag)
 
 add_library(UDP ${OPENAIR3_DIR}/UDP/udp_eNB_task.c)
+add_dependencies(UDP rrc_flag)
 
 
 set(NAS_SRC ${OPENAIR3_DIR}/NAS/)
@@ -1784,6 +1783,7 @@ if(NAS_UE)
     ${libnas_ue_esm_OBJS}
     ${libnas_ue_esm_sap_OBJS}
   )
+  add_dependencies(LIB_NAS_UE rrc_flag)
   set(NAS_UE_LIB LIB_NAS_UE)
 
   include_directories(${NAS_SRC}UE)
@@ -1907,6 +1907,15 @@ include_directories(${CRYPTO_INCLUDE_DIRS})
 if (${RF_BOARD} STREQUAL "OAI_USRP")
   find_package(Boost REQUIRED)
   include_directories(${LIBBOOST_INCLUDE_DIR})
+
+elseif (${RF_BOARD} STREQUAL "OAI_IRIS")
+    include_directories("${OPENAIR_TARGETS}/ARCH/IRIS/USERSPACE/LIB/")
+    include_directories("/usr/local/include/")
+    set(HW_SOURCE ${HW_SOURCE}
+            ${OPENAIR_TARGETS}/ARCH/IRIS/USERSPACE/LIB/iris_lib.cpp)
+    LINK_DIRECTORIES("/usr/local/lib")
+    set(option_HW_lib "-lSoapySDR -rdynamic -ldl")
+
 endif (${RF_BOARD} STREQUAL "OAI_USRP")
 
 pkg_search_module(OPENPGM openpgm-5.1 openpgm-5.2)
@@ -2041,14 +2050,11 @@ add_definitions(-DASN1_MINIMUM_VERSION=924)
 ###################################################
 
 add_executable(lte-softmodem
-  ${rrc_h}
-  ${s1ap_h}
-  ${f1ap_h}
-  #${OPENAIR_BIN_DIR}/messages_xml.h
   ${OPENAIR_TARGETS}/RT/USER/rt_wrapper.c
   ${OPENAIR_TARGETS}/RT/USER/lte-enb.c
   ${OPENAIR_TARGETS}/RT/USER/lte-ru.c
   ${OPENAIR_TARGETS}/RT/USER/lte-softmodem.c
+  ${OPENAIR_TARGETS}/RT/USER/lte-softmodem-common.c
   ${OPENAIR2_DIR}/ENB_APP/NB_IoT_interface.c
   ${OPENAIR1_DIR}/SIMULATION/TOOLS/taus.c
   ${OPENAIR_TARGETS}/COMMON/create_tasks.c
@@ -2066,6 +2072,7 @@ add_executable(lte-softmodem
   ${CONFIG_SOURCES}
   ${SHLIB_LOADER_SOURCES}
   )
+add_dependencies(lte-softmodem rrc_flag s1ap_flag x2_flag)
 
 target_link_libraries (lte-softmodem
   -Wl,--start-group
@@ -2110,14 +2117,11 @@ target_link_libraries (lte-softmodem ${T_LIB})
 # lte-softmodem-nos1 is both eNB and UE implementation
 ###################################################
 add_executable(lte-softmodem-nos1
-  ${rrc_h}
-  ${s1ap_h}
-  ${f1ap_h}
-  #${OPENAIR_BIN_DIR}/messages_xml.h
   ${OPENAIR_TARGETS}/RT/USER/rt_wrapper.c
   ${OPENAIR_TARGETS}/RT/USER/lte-enb.c
   ${OPENAIR_TARGETS}/RT/USER/lte-ru.c
   ${OPENAIR_TARGETS}/RT/USER/lte-softmodem.c
+  ${OPENAIR_TARGETS}/RT/USER/lte-softmodem-common.c
   ${OPENAIR2_DIR}/ENB_APP/NB_IoT_interface.c
   ${OPENAIR1_DIR}/SIMULATION/TOOLS/taus.c
   ${OPENAIR_TARGETS}/COMMON/create_tasks.c
@@ -2134,6 +2138,7 @@ add_executable(lte-softmodem-nos1
   ${CONFIG_SOURCES}
   ${SHLIB_LOADER_SOURCES}
   )
+add_dependencies(lte-softmodem-nos1 rrc_flag s1ap_flag x2_flag)
 target_link_libraries (lte-softmodem-nos1
   -Wl,--start-group
   RRC_LIB F1AP F1AP_LIB SECU_CN SECU_OSA UTIL HASHTABLE SCTP_CLIENT SCHED_LIB SCHED_RU_LIB PHY_COMMON PHY PHY_RU LFDS L2 ${MSC_LIB} ${RAL_LIB} ${ITTI_LIB}
@@ -2150,13 +2155,10 @@ target_link_libraries (lte-softmodem-nos1 ${T_LIB})
 #######################################
 
 add_executable(lte-uesoftmodem
-  ${rrc_h}
-  ${s1ap_h}
-  ${f1ap_h}
-  #${OPENAIR_BIN_DIR}/messages_xml.h
   ${OPENAIR_TARGETS}/RT/USER/rt_wrapper.c
   ${OPENAIR_TARGETS}/RT/USER/lte-ue.c
   ${OPENAIR_TARGETS}/RT/USER/lte-uesoftmodem.c
+  ${OPENAIR_TARGETS}/RT/USER/lte-softmodem-common.c
   ${OPENAIR_TARGETS}/RT/USER/lte-ru.c
   ${OPENAIR_TARGETS}/RT/USER/rfsim.c
   ${OPENAIR1_DIR}/SIMULATION/TOOLS/taus.c
@@ -2175,6 +2177,7 @@ add_executable(lte-uesoftmodem
   ${SHLIB_LOADER_SOURCES}
   )
 
+add_dependencies(lte-uesoftmodem rrc_flag s1ap_flag x2_flag)
 target_link_libraries (lte-uesoftmodem
   -Wl,--start-group
   RRC_LIB S1AP_LIB S1AP_ENB X2AP_LIB X2AP_ENB F1AP_LIB F1AP GTPV1U SECU_CN SECU_OSA UTIL HASHTABLE SCTP_CLIENT UDP SCHED_RU_LIB SCHED_UE_LIB PHY_COMMON PHY_UE PHY_RU LFDS L2_UE SIMU
@@ -2190,13 +2193,10 @@ target_link_libraries (lte-uesoftmodem ${T_LIB})
 # lte-uesoftmodem-nos1 is UE implementation
 ###################################################
 add_executable(lte-uesoftmodem-nos1
-  ${rrc_h}
-  ${s1ap_h}
-  ${f1ap_h}
-#  ${OPENAIR_BIN_DIR}/messages_xml.h
   ${OPENAIR_TARGETS}/RT/USER/rt_wrapper.c
   ${OPENAIR_TARGETS}/RT/USER/lte-ue.c
   ${OPENAIR_TARGETS}/RT/USER/lte-uesoftmodem.c
+  ${OPENAIR_TARGETS}/RT/USER/lte-softmodem-common.c
   ${OPENAIR_TARGETS}/RT/USER/lte-ru.c
   ${OPENAIR_TARGETS}/RT/USER/rfsim.c
   ${OPENAIR1_DIR}/SIMULATION/TOOLS/taus.c
@@ -2216,6 +2216,7 @@ add_executable(lte-uesoftmodem-nos1
   ${SHLIB_LOADER_SOURCES}
   )
 
+add_dependencies(lte-uesoftmodem-nos1 rrc_flag s1ap_flag x2_flag)
 target_link_libraries (lte-uesoftmodem-nos1
   -Wl,--start-group
   RRC_LIB S1AP_LIB S1AP_ENB X2AP_LIB F1AP_LIB F1AP GTPV1U SECU_CN SECU_OSA UTIL HASHTABLE SCTP_CLIENT UDP SECU_CN SECU_OSA UTIL HASHTABLE SCHED_RU_LIB SCHED_UE_LIB PHY_COMMON PHY_UE PHY_RU LFDS L2_UE SIMU ${RAL_LIB} ${ITTI_LIB}
@@ -2292,7 +2293,6 @@ add_executable(test_epc_generate_scenario
   ${OPENAIR2_DIR}/ENB_APP/enb_config.h
   ${OPENAIR2_DIR}/COMMON/commonDef.h
   ${OPENAIR2_DIR}/COMMON/messages_def.h
-  ${OPENAIR2_DIR}/COMMON/messages_types.h
   ${OPENAIR3_DIR}/S1AP/s1ap_eNB_defs.h
   )
 target_link_libraries (test_epc_generate_scenario
@@ -2312,7 +2312,6 @@ add_executable(test_epc_play_scenario
   ${OPENAIR3_DIR}/TEST/EPC_TEST/play_scenario.h
   ${OPENAIR2_DIR}/COMMON/commonDef.h
   ${OPENAIR2_DIR}/COMMON/messages_def.h
-  ${OPENAIR2_DIR}/COMMON/messages_types.h
   )
 target_include_directories(test_epc_play_scenario PUBLIC /usr/local/share/asn1c)
 target_link_libraries (test_epc_play_scenario
diff --git a/cmake_targets/at_commands/CMakeLists.txt b/cmake_targets/at_commands/CMakeLists.txt
old mode 100755
new mode 100644
index 54f369f97772e7bdbf8214b191afdfb89e7cfce4..bd71125cf0ac1d920b742f12dccb8b04ffbc671f
--- a/cmake_targets/at_commands/CMakeLists.txt
+++ b/cmake_targets/at_commands/CMakeLists.txt
@@ -76,7 +76,6 @@ macro(add_boolean_option name val helpstr)
 endmacro(add_boolean_option)
 
 # compilation flags
-# added CMAKER conditional compilation to not bother legacy building system
 #############################################
 if(NOT CMAKE_BUILD_TYPE)
 set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
@@ -84,7 +83,7 @@ endif()
 set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release RelWithDebInfo MinSizeRel)
 
 #
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.2 -std=gnu99 -Wall -Wstrict-prototypes -fno-strict-aliasing -rdynamic -funroll-loops -Wno-packed-bitfield-compat -DCMAKER")
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.2 -std=gnu99 -Wall -Wstrict-prototypes -fno-strict-aliasing -rdynamic -funroll-loops -Wno-packed-bitfield-compat ")
 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb -DMALLOC_CHECK_=3")
 set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -ggdb -DMALLOC_CHECK_=3 -O2")
 
diff --git a/cmake_targets/autotests/test_case_list.xml b/cmake_targets/autotests/test_case_list.xml
index 61ef6c842496db875e1b1eb8c73631be0efe2be0..bf3d57af0dbbec3c3ce877662e813c21132f2fa0 100644
--- a/cmake_targets/autotests/test_case_list.xml
+++ b/cmake_targets/autotests/test_case_list.xml
@@ -956,20 +956,20 @@
       <pre_exec>$OPENAIR_DIR/cmake_targets/autotests/tools/free_mem.bash</pre_exec>
       <pre_exec_args></pre_exec_args>
       <main_exec> $OPENAIR_DIR/targets/bin/dlsim.Rel14</main_exec>
-      <main_exec_args> -m5 -gF -s-1 -w1.0 -f.2 -n500 -B50 -c2 -z2 -O60
-                       -m4 -gF -s0 -w1.0 -f.2 -n500 -B6 -c4 -z2 -O60
-                       -m15 -gF -s6.7 -w1.0 -f.2 -n500 -B50 -c2 -z2 -O60
-                       -m15 -gF -s6.7 -w1.0 -f.2 -n500 -B25 -c2 -z2 -O60
-                       -m15 -gG -s1.4 -w1.0 -f.2 -n500 -B50 -c2 -z2 -O25
-                       -m15 -gG -s1.4 -w1.0 -f.2 -n500 -B25 -c2 -z2 -O25
-                       -m25 -gF -s17.4 -w1.0 -f.2 -n500 -B25 -c3 -z2 -O60
-                       -m25 -gF -s17.5 -w1.0 -f.2 -n500 -B25 -c3 -z2 -r1022 -O60
-                       -m26 -gF -s17.7 -w1.0 -f.2 -n500 -B50 -c2 -z2 -O60
-                       -m26 -gF -s17.6 -w1.0 -f.2 -n500 -B100 -c2 -z2 -O60
-                       -m26 -gF -s17.3 -w1.0 -f.2 -n500 -B100 -c2 -z2 -r1600 -O60
-                       -m26 -gF -s16.6 -w1.0 -f.2 -n500 -B100 -c2 -z2 -r1899 -O60
-		       -m14 -gF -s6.8  -w1.0 -f.2 -n500 -B50 -c2 -x2 -y2 -z2 -O60
-                       -m13 -gF -s5.9  -w1.0 -f.2 -n500 -B25 -c3 -x2 -y2 -z2 -O60</main_exec_args>
+      <main_exec_args> -m=5 -g=F -s=-1= -w=1.0 -f=.2 -n=500 -B=50 -c=2 -z=2 -O=60
+                        -m=4 -g=F -s=0 -w=1.0 -f=.2 -n=500 -B=6 -c=4 -z=2 -O=60
+                        -m=15 -g=F -s=6.7 -w=1.0 -f=.2 -n=500 -B=50 -c=2 -z=2 -O=60
+                        -m=15 -g=F -s=6.7 -w=1.0 -f=.2 -n=500 -B=25 -c=2 -z=2 -O=60
+                        -m=15 -g=G -s=1.4 -w=1.0 -f=.2 -n=500 -B=50 -c=2 -z=2 -O=25
+                        -m=15 -g=G -s=1.4 -w=1.0 -f=.2 -n=500 -B=25 -c=2 -z=2 -O=25
+                        -m=25 -g=F -s=17.4 -w=1.0 -f=.2 -n=500 -B=25 -c=3 -z=2 -O=60
+                        -m=25 -g=F -s=17.5 -w=1.0 -f=.2 -n=500 -B=25 -c=3 -z=2 -r=1022 -O=60
+                        -m=26 -g=F -s=17.7 -w=1.0 -f=.2 -n=500 -B=50 -c=2 -z=2 -O=60
+                        -m=26 -g=F -s=17.6 -w=1.0 -f=.2 -n=500 -B=100 -c=2 -z=2 -O=60
+                        -m=26 -g=F -s=17.3 -w=1.0 -f=.2 -n=500 -B=100 -c=2 -z=2 -r=1600 -O=60
+                        -m=26 -g=F -s=16.6 -w=1.0 -f=.2 -n=500 -B=100 -c=2 -z=2 -r=1899 -O=60
+                        -m=14 -g=F -s=6.8  -w=1.0 -f=.2 -n=500 -B=50 -c=2 -x=2 -y=2 -z=2 -O=60
+                        -m=13 -g=F -s=5.9  -w=1.0 -f=.2 -n=500 -B=25 -c=3 -x=2 -y=2 -z=2 -O=60</main_exec_args>
       <tags>dlsim.test1 dlsim.test5 dlsim.test6 dlsim.test6b dlsim.test7 dlsim.test7b dlsim.test10 dlsim.test10b dlsim.test11 dlsim.TM2_test1 dlsim.TM2_test1b</tags>
       <search_expr_true>"passed"</search_expr_true>
       <search_expr_false>segmentation fault|assertion|exiting|fatal</search_expr_false>
diff --git a/cmake_targets/build_oai b/cmake_targets/build_oai
index 17e4d7af5824bd3ec8e9ce000c8314b5d24ce86e..bf25724a5c80d54ced603680b3071f9843df049c 100755
--- a/cmake_targets/build_oai
+++ b/cmake_targets/build_oai
@@ -43,6 +43,7 @@ conf_nvram_path=$OPENAIR_DIR/openair3/NAS/TOOLS/ue_eurecom_test_sfr.conf
 MSC_GEN=0
 XFORMS="True"
 UE_EXPANSION="False"
+UESIM_EXPANSION="False"
 PRINT_STATS="False"
 VCD_TIMING="False"
 DEADLINE_SCHEDULER_FLAG_USER="False"
@@ -110,7 +111,7 @@ Options
    Rel8 limits the implementation to 3GPP Release 8 version
    Rel10 limits the implementation to 3GPP Release 10 version
 -w | --hardware
-   EXMIMO, USRP, BLADERF, ETHERNET, LMSSDR, None (Default)
+   EXMIMO, USRP, BLADERF, ETHERNET, LMSSDR, IRIS, None (Default)
    Adds this RF board support (in external packages installation and in compilation)
 -t | --transport protocol
    ETHERNET , None
@@ -222,6 +223,10 @@ function main() {
             UE_EXPANSION="True"
             echo_info "Will compile with UE_EXPANSION"
             shift;;
+       --musim)
+            UESIM_EXPANSION="True"
+            echo_info "Will compile with UESIM_EXPANSION"
+            shift;;
        --UE-conf-nvram)
             conf_nvram_path=$(readlink -f $2)
             shift 2;;
@@ -235,7 +240,7 @@ function main() {
        -w | --hardware)
             HW="$2" #"${i#*=}"
             # Use OAI_USRP  as the key word USRP is used inside UHD driver           
-	    if [ "$HW" != "BLADERF" -a  "$HW" != "USRP" -a "$HW" != "LMSSDR" -a  "$HW" != "None" -a  "$HW" != "EXMIMO"  ] ; then 
+            if [ "$HW" != "BLADERF" -a  "$HW" != "USRP" -a "$HW" != "LMSSDR" -a  "$HW" != "None" -a  "$HW" != "EXMIMO" -a  "$HW" != "IRIS"  ] ; then
 		echo_fatal "Unknown HW type $HW will exit..."		
 	    else
 		if [ "$HW" == "USRP" ] ; then 
@@ -247,6 +252,9 @@ function main() {
 		if [ "$HW" == "LMSSDR" ] ; then 
 		    HW="OAI_LMSSDR"
 		fi 
+                if [ "$HW" == "IRIS" ] ; then
+                    HW="OAI_IRIS"
+                fi
 		echo_info "Setting hardware to: $HW"
 	    fi
             shift 2;;
@@ -418,7 +426,9 @@ function main() {
         DEADLINE_SCHEDULER_FLAG_USER="False"
      elif [ "$HW" = "OAI_BLADERF" ] ; then 
         DEADLINE_SCHEDULER_FLAG_USER="False"
-     elif [ "$HW" = "OAI_LMSSDR" ] ; then 
+     elif [ "$HW" = "OAI_LMSSDR" ] ; then
+        DEADLINE_SCHEDULER_FLAG_USER="False"
+     elif [ "$HW" = "OAI_IRIS" ] ; then
         DEADLINE_SCHEDULER_FLAG_USER="False"
      elif [ "$HW" = "None" ] ; then 
         DEADLINE_SCHEDULER_FLAG_USER="False"
@@ -488,11 +498,16 @@ function main() {
         flash_firmware_bladerf
       fi
     fi
-    if [ "$FLEXRAN_AGENT" == "1" ] ; then
-      echo_info "installing protobuf/protobuf-c for flexran agent support"
-      install_protobuf_from_source
-      install_protobuf_c_from_source
+    if [ "$HW" == "OAI_IRIS" ] ; then
+      echo_info "installing packages for IRIS support"
+      check_install_soapy
+      #if [ ! "$DISABLE_HARDWARE_DEPENDENCY" == "True" ]; then
+      #  flash_firmware_iris
+      #fi
     fi
+    echo_info "installing protobuf/protobuf-c for flexran agent support"
+    install_protobuf_from_source
+    install_protobuf_c_from_source
   fi
 
   if [ "$INSTALL_OPTIONAL" = "1" ] ; then
@@ -545,6 +560,7 @@ function main() {
     echo "set ( UE_EXPANSION $UE_EXPANSION )"      >>  $cmake_file
 #    echo "set ( PHY_TX_THREAD $UE_EXPANSION )"     >>  $cmake_file
     echo "set ( PRE_SCD_THREAD $UE_EXPANSION )"    >>  $cmake_file
+    echo "set ( UESIM_EXPANSION $UESIM_EXPANSION )"      >>  $cmake_file
     echo "set ( RRC_ASN1_VERSION \"${REL}\")"      >>  $cmake_file
     echo "set ( ENABLE_VCD_FIFO $VCD_TIMING )"     >>  $cmake_file
     echo "set ( RF_BOARD \"${HW}\")"               >>  $cmake_file
@@ -660,6 +676,9 @@ function main() {
     compilations \
           lte-simulators coding \
           libcoding.so $dbin/libcoding.so
+#    compilations \
+#	  lte-simulators $config_libconfig_shlib \
+#	  lib$config_libconfig_shlib.so $dbin/lib$config_libconfig_shlib.so
   fi
 
   # Core simulators
@@ -765,6 +784,14 @@ function main() {
 	      ln -sf liboai_lmssdrdevif.so liboai_device.so
 	      ln -sf $dbin/liboai_lmssdrdevif.so.$REL $dbin/liboai_device.so
 	      echo_info "liboai_device.so is linked to LMSSDR device library"	 
+          elif [ "$HW" == "OAI_IRIS" ] ; then
+                  compilations \
+                      $build_dir oai_irisdevif \
+                      liboai_irisdevif.so $dbin/liboai_irisdevif.so.$REL
+
+              ln -s liboai_irisdevif.so liboai_device.so
+              ln -s $dbin/liboai_irisdevif.so.$REL $dbin/liboai_device.so
+              echo_info "liboai_device.so is linked to IRIS device library"
 	  else 
 	      echo_info "liboai_device.so is not linked to any device library"	    
 	  fi
diff --git a/cmake_targets/build_ue b/cmake_targets/build_ue
old mode 100644
new mode 100755
diff --git a/cmake_targets/lte-simulators/CMakeLists.txt b/cmake_targets/lte-simulators/CMakeLists.txt
index b7e83a92a03282f9dfae9b54633a8ea745763cee..1bfac2b20d6bace5dc68236279a4361a3cef87ed 100644
--- a/cmake_targets/lte-simulators/CMakeLists.txt
+++ b/cmake_targets/lte-simulators/CMakeLists.txt
@@ -9,4 +9,5 @@ set(MU_RECIEVER False)
 set(NAS_UE False)
 set(MESSAGE_CHART_GENERATOR False)
 set(RRC_ASN1_VERSION "Rel14")
+set (UE_TIMING_TRACE True)
 include(${CMAKE_CURRENT_SOURCE_DIR}/../CMakeLists.txt)
diff --git a/cmake_targets/tools/build_helper b/cmake_targets/tools/build_helper
index c3350eb18e77a1ecffb71c1f28ea1aae204852ee..0021b673f2bdb3f5145c75aea02d3501f4aaafe5 100755
--- a/cmake_targets/tools/build_helper
+++ b/cmake_targets/tools/build_helper
@@ -32,8 +32,8 @@ OS_DISTRO=$(grep "^ID=" /etc/os-release | sed "s/ID=//" | sed "s/\"//g")
 OS_RELEASE=$(grep "^VERSION_ID=" /etc/os-release | sed "s/VERSION_ID=//" | sed "s/\"//g")
 case "$OS_DISTRO" in
   fedora) OS_BASEDISTRO="fedora"; INSTALLER="dnf"; CMAKE="cmake" ;;
-  rhel)   OS_BASEDISTRO="fedora"; INSTALLER="yum"; CMAKE="cmake3" ;;
-  centos) OS_BASEDISTRO="fedora"; INSTALLER="yum"; CMAKE="cmake3" ;;
+  rhel)   OS_BASEDISTRO="fedora"; INSTALLER="yum --skip-broken"; CMAKE="cmake3" ;;
+  centos) OS_BASEDISTRO="fedora"; INSTALLER="yum --skip-broken"; CMAKE="cmake3" ;;
   debian) OS_BASEDISTRO="debian"; INSTALLER="apt-get"; CMAKE="cmake" ;;
   ubuntu) OS_BASEDISTRO="debian"; INSTALLER="apt-get"; CMAKE="cmake" ;;
 esac
@@ -102,7 +102,7 @@ check_supported_distribution() {
         "ubuntu14.04") return 0 ;;
         "fedora24")    return 0 ;;
         "rhel7")       return 0 ;;
-	"rhel7.5")     return 0 ;;
+	"rhel7.6")     return 0 ;;
         "centos7")     return 0 ;;
     esac
     return 1
@@ -253,7 +253,7 @@ install_usrp_uhd_driver_from_source(){
     rm -rf /tmp/uhd
     git clone https://github.com/EttusResearch/uhd.git
     cd uhd
-    git checkout tags/release_003_010_001_001
+    git checkout tags/v3.13.0.2
     mkdir -p host/build
     cd host/build
     $CMAKE ../
@@ -311,10 +311,20 @@ install_usrp_uhd_driver() {
         # On newer kernels, it fails to install
         $SUDO apt-get -y install uhd-host
     fi
+    # quick workaround for RHE7.6
+    local distribution=$(get_distribution_release)
     if [ -z $1 ]; then
-      $SUDO uhd_images_downloader
+      if [[ "$distribution" == "rhel7.6" ]]; then
+          $SUDO /usr/local/bin/uhd_images_downloader
+      else
+          $SUDO uhd_images_downloader
+      fi
     else
-      $SUDO uhd_images_downloader -i $1
+      if [[ "$distribution" == "rhel7.6" ]]; then
+          $SUDO /usr/local/bin/uhd_images_downloader -i $1
+      else
+          $SUDO uhd_images_downloader -i $1
+      fi
     fi
 }
 
@@ -373,13 +383,81 @@ check_install_lmssdr_driver(){
         else
                 echo_error "lmssdr support implies installing lmssdr drivers and tools" \
                            " from sources. check:"
-                echo_info "https://open-cells.com/index.php/2017/05/10/limesdr-installation/"
+                echo_info "https://wiki.myriadrf.org/Lime_Suite"
                 echo_fatal "Cannot compile lmssdr device"
 	fi
 
 
 }
 
+install_soapy_from_source(){
+    soapy_install_log=$OPENAIR_DIR/cmake_targets/log/soapy_install_log.txt
+    echo_info "\nInstalling Soapy EcoSystem from source. The log file for Soapy installation is here: $soapy_install_log "
+    (
+    cd /tmp
+    echo "Downloading SoapySDR"
+    rm -rf /tmp/soapysdr
+    git clone -b soapy-sdr-0.7.0 --single-branch https://github.com/pothosware/SoapySDR.git
+    cd SoapySDR
+    #git checkout tags/release_003_010_001_001
+    mkdir -p build
+    cd build
+    $CMAKE ../
+    echo "Compiling SoapySDR"
+    make -j`nproc`
+    $SUDO make install
+    $SUDO ldconfig
+    cd /tmp
+    echo "Downloading SoapyRemote"
+    rm -rf /tmp/soapyremote
+    git clone -b soapy-remote-0.5.0 --single-branch https://github.com/pothosware/SoapyRemote.git
+    cd SoapyRemote
+    #git checkout tags/release_003_010_001_001
+    mkdir -p build
+    cd build
+    cmake ../
+    echo "Compiling SoapyRemote"
+    make -j`nproc`
+    $SUDO make install
+    $SUDO ldconfig
+    ) >& $soapy_install_log
+}
+
+install_soapy_iris_from_source(){
+    iris_install_log=$OPENAIR_DIR/cmake_targets/log/iris_install_log.txt
+    echo_info "\nInstalling Iris driver from source. The log file for Iris driver installation is here: $iris_install_log "
+    (
+    cd /tmp
+    echo "Downloading SoapyIris"
+    rm -rf /tmp/sklk-soapyiris
+    git clone -b soapy-iris-2018.08.0.1 --single-branch https://github.com/skylarkwireless/sklk-soapyiris.git
+    cd sklk-soapyiris
+    mkdir -p build
+    cd build
+    cmake ../
+    echo "Compiling SoapyIris"
+    make -j`nproc`
+    $SUDO make install
+    $SUDO ldconfig
+    ) >& $iris_install_log
+}
+
+check_install_soapy () {
+    #if [[ "$OS_DISTRO" == "ubuntu" ]]; then
+        #first we remove old installation
+    $SUDO apt-get remove -y soapysdr soapysdr-server libsoapysdr-dev python-soapysdr python3-soapysdr soapysdr-module-remote || true
+        #$SUDO add-apt-repository -y ppa:myriadrf/drivers
+        #$SUDO apt-get update
+        #$SUDO apt-get install -y soapysdr soapysdr-server libsoapysdr-dev python-soapysdr python3-soapysdr soapysdr-module-remote
+
+    #elif [[ "$OS_BASEDISTRO" == "fedora" ]]; then
+    #    $SUDO $INSTALLER -y install software-properties-common python3-software-properties python-software-properties subversion git python3 python-numpy python3-numpy cmake swig python-dev
+    install_soapy_from_source
+    #fi
+    install_soapy_iris_from_source
+
+}
+
 check_install_additional_tools (){
   $SUDO $INSTALLER update -y
   if [[ "$OS_DISTRO" == "ubuntu" ]]; then
@@ -678,7 +756,7 @@ install_asn1c_from_source(){
     # better to use a given commit than a branch in case the branch
     # is updated and requires modifications in the source of OAI
     #git checkout velichkov_s1ap_plus_option_group
-    git checkout d3aed06bb2bec7df1b5c6d0333f8c7dfc5993372
+    git checkout 0a7524184f16e7093990a31d8d4db487a16e5782
     autoreconf -iv
     ./configure
     make -j`nproc`
diff --git a/cmake_targets/tools/exmimo2_2brxg.lime b/cmake_targets/tools/exmimo2_2brxg.lime
old mode 100755
new mode 100644
diff --git a/cmake_targets/tools/init_nas_s1 b/cmake_targets/tools/init_nas_s1
index cab4ad047bf4d42d9a4ba1890c9cef9967ec2a00..b78ab34ff9f90d825303e3bb807e0f8e177f3df6 100755
--- a/cmake_targets/tools/init_nas_s1
+++ b/cmake_targets/tools/init_nas_s1
@@ -52,20 +52,20 @@ load_module ../../targets/bin/ue_ip.ko
 
 if [ "$1" = "UE" ]; then
   echo "bring up $LTEIF interface for UE"
-  ifconfig $LTEIF up
+  sudo ifconfig $LTEIF up
 fi
 
-ip route flush cache
+sudo ip route flush cache
 sleep 1
-sysctl -w net.ipv4.conf.all.log_martians=1
+sudo sysctl -w net.ipv4.conf.all.log_martians=1
 echo "Disabling reverse path filtering"
-sysctl -w net.ipv4.conf.all.rp_filter=0
-ip route flush cache
+sudo sysctl -w net.ipv4.conf.all.rp_filter=0
+sudo ip route flush cache
 
 # Check table 200 lte in /etc/iproute2/rt_tables
 fgrep lte /etc/iproute2/rt_tables  > /dev/null 
 if [ $? -ne 0 ]; then
     echo "200 lte " >> /etc/iproute2/rt_tables
 fi
-ip rule add fwmark 1 table lte
-ip route add default dev $LTEIF table lte
+sudo ip rule add fwmark 1 table lte
+sudo ip route add default dev $LTEIF table lte
diff --git a/cmake_targets/tools/make_asn1c_includes.sh b/cmake_targets/tools/make_asn1c_includes.sh
new file mode 100755
index 0000000000000000000000000000000000000000..a7f480f90f3653e71743c113a7bb60dc69b5c633
--- /dev/null
+++ b/cmake_targets/tools/make_asn1c_includes.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+GENERATED_FULL_DIR=$1
+shift
+ASN1_SOURCE_DIR=$1
+shift
+export ASN1C_PREFIX=$1
+shift
+options=$*
+done_flag="$GENERATED_FULL_DIR"/done
+if [ "$done_flag" -ot $ASN1_SOURCE_DIR ] ; then
+   rm -f "$GENERATED_FULL_DIR"/${ASN1C_PREFIX}*.c "$GENERATED_FULL_DIR"/${ASN1C_PREFIX}*.h
+   mkdir -p "$GENERATED_FULL_DIR"
+   asn1c -pdu=all -fcompound-names -gen-PER -no-gen-OER -no-gen-example $options -D $GENERATED_FULL_DIR $ASN1_SOURCE_DIR |& egrep -v "^Copied|^Compiled" | sort -u
+fi
+touch $done_flag
diff --git a/cmake_targets/tools/run_ue_s1 b/cmake_targets/tools/run_ue_s1
old mode 100644
new mode 100755
diff --git a/common/config/DOC/config.md b/common/config/DOC/config.md
new file mode 100644
index 0000000000000000000000000000000000000000..1c2ef2559482e0159a7d526efa5116d2c54955e5
--- /dev/null
+++ b/common/config/DOC/config.md
@@ -0,0 +1,11 @@
+# OAI configuration module
+
+The configuration module provides an api that other oai components can use to get parameters at init time. It defines a parameter structure, used to describe parameters attributes (for example name and  type). The same structure includes a pointer to the variable where the configuration module writes the parameter value, at run time, when calling config_get or config_getlist functions. For each parameter a function to check the value can be specified and pre-defined functions  are provided for some common parameter validations (integer in a range or in a list, string in a list).  The module also include an api to check that no unknown options have been entered on the command line and a a mechanism to display a help text for suppoted parameters.
+
+## Documentation
+
+* [runtime usage](config/rtusage.md)
+* [developer usage](config/devusage.md)
+* [module architecture](config/arch.md)
+
+[oai Wikis home](https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/home)
diff --git a/common/config/DOC/config/arch.md b/common/config/DOC/config/arch.md
new file mode 100644
index 0000000000000000000000000000000000000000..f888724c4116ed1062f0c096ada1947f601b2839
--- /dev/null
+++ b/common/config/DOC/config/arch.md
@@ -0,0 +1,7 @@
+# config module source files
+![configmodule_srcdir](/uploads/fdc3e96011fd5592440900dfa05b4701/configmodule_srcdir.png)
+# config module components
+![configmodule_components](/uploads/54f8a3953d5ee53717cd9a3b71f85c68/configmodule_components.png)
+
+
+[Configuration module home](../config.md)
diff --git a/common/config/DOC/config/devusage.md b/common/config/DOC/config/devusage.md
new file mode 100644
index 0000000000000000000000000000000000000000..151ffeafa8c435786927e900c3316e2d4aaf2d88
--- /dev/null
+++ b/common/config/DOC/config/devusage.md
@@ -0,0 +1,20 @@
+The configuration module objectives are
+1. Allow easy parameters management in oai, helping the development of a flexible, modularized and fully configurable softmodem.
+1. Use a common configuration API in all oai modules
+1. Allow development of alternative configuration sources without modifying the oai code. Today the only delivered configuration source is the libconfig format configuration file.
+
+As a developer you may need to look at these sections:
+
+* [add parameters in an existing section](devusage/addaparam.md)
+* [add a parameter set, in a new section](devusage/addparamset.md)
+* [configuration module API](devusage/api.md)
+* [configuration module public structures](devusage/struct.md)
+
+Whatever your need is, configuration module usage examples can be found in oai sources:
+*  complex example, using all the configuration module functionalities, including parameter checking:
+[NB-IoT configuration code](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair2/ENB_APP/NB_IoT_config.c) and [NB-IoT configuration include file](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair2/ENB_APP/NB_IoT_paramdef.h)
+*  very simple example, just reading a parameter set corresponding to a dedicated section:  the telnetsrv_autoinit function in [common/utils/telnetsrv/telnetsrv.c, around line 726](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/telnetsrv/telnetsrv.c#L726)
+*  an example with run-time definition of parameters, in the logging sub-system: the log_getconfig function at the top of [openair2/UTIL/LOG/log.c](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair2/UTIL/LOG/log.c)
+
+
+[Configuration module home](../config.md)
diff --git a/common/config/DOC/config/devusage/addaparam.md b/common/config/DOC/config/devusage/addaparam.md
new file mode 100644
index 0000000000000000000000000000000000000000..246c49452613a2da5c5e4ecc287a32d9064dca22
--- /dev/null
+++ b/common/config/DOC/config/devusage/addaparam.md
@@ -0,0 +1,86 @@
+To add a new parameter in an existing section you  insert an item in a `paramdef_t` array, which describes the parameters to be read in the existing `config_get` call. You also need to increment the numparams argument.
+
+existing code:
+```c
+unsigned int varopt1;
+paramdef_t someoptions[] = {
+/*---------------------------------------------------------------------------------*/
+/*                  configuration parameters for some module                       */
+/* optname     helpstr     paramflags    XXXptr      defXXXval      type    numelt */
+/*---------------------------------------------------------------------------------*/
+   {"opt1",  "<help opt1>",   0,      uptr:&varopt1, defuintval:0, TYPE_UINT,  0 },
+};
+
+config_get( someoptions,sizeof(someoptions)/sizeof(paramdef_t),"somesection");
+
+```
+new code:
+```c
+unsigned int varopt1;
+
+
+/* varopt2 will be allocated by the config module and free at end_configmodule call
+   except if PARAMFLAG_NOFREE bit is set in paramflags field*/
+char *varopt2;
+paramdef_t someoptions[] = {
+/*---------------------------------------------------------------------------------*/
+/*                  configuration parameters for some module                       */
+/* optname     helpstr     paramflags    XXXptr      defXXXval      type    numelt */
+/*---------------------------------------------------------------------------------*/
+   {"opt1",  "<help opt1>",   0,      uptr:&varopt1,  defuintval:0,TYPE_UINT,  0   },
+   {"opt2",  "<help opt2>",   0,      strptr:&varopt2,defstrval:"",TYPE_STRING,0   },
+};
+
+config_get( someoptions,sizeof(someoptions)/sizeof(paramdef_t),"somesection");
+
+```
+
+The corresponding configuration file may now include opt2 parameter in the somesection section:
+
+```c
+somesection =
+{
+opt1 = 3;
+opt2 = "abcd";
+};
+```
+
+In these examples the variables used to retrieve the parameters values are pointed by the `uptr` or `strptr` fields of the `paramdef_t` structure. After the `config_get` call `varopt1` and `varopt2` have been set to the value specified in the config file. It is also possible to specify a `NULL` value to the `< XXX >ptr` fields, which are then allocated by the config module and possibly free when calling `config_end()`, if the `PARAMFLAG_NOFREE` bit has not been set in the `paramflags` field.
+
+The configuration module provides a mechanism to check the parameter value read from the configuration source. The following functions are implemented:
+1.  Check an integer parameter against a list of authorized values
+1.  Check an integer parameter against a list of authorized values and set the parameter to a new value
+1.  Check an integer parameter against a range
+1.  Check a C string parameter against a list of authorized values
+1. Check a C string parameter against a list of authorized values and set the parameter to a new integer value
+
+ A `checkedparam_t` structure array provides the parameter verification procedures:
+
+```c
+/*
+   definition of the verification to be done on param opt1 and opt2.
+   opt1 is an integer option we must be set to 0,2,3,4 or 7 in the
+   config source.
+   if opt1 is set to 0 in the config file, it will be set to 1, etc
+   opt2 is C string option with the authorize values "zero","oneThird","twoThird","one"
+ */
+#define OPT1_OKVALUES {0,2,3,4,7}
+#define OPT1_NEWVALUES {1,1,0,6,9}
+#define OPT2_OKVALUES {"zero","oneThird","twoThird","one"}
+
+#define OPT_CHECK_DESC { \
+             { .s1a= { config_check_modify_integer, OPT1_OKVALUE, OPT1_NEWVALUES ,5 }}, \
+             { .s3=  { config_check_strval, OPT2_OKVALUES,4 }}, \
+}
+checkedparam_t checkopt[] = OPT_CHECK_DESC;
+.....
+/* assign the verification procedures to the parameters definitions */
+for(int i=0 ; i < sizeof(someoptions)/sizeof(paramdesc_t) ; i ++) {
+    someoptions[i].chkPptr = &(checkopt[i]);
+}
+....
+```
+When you need a specific verification algorithm, you can provide your own verification function and use it in place of the available ones, in the `checkedparam_t` union. If no existing structure definition match your need, you can enhance the configuration module. You then have to add a new verification function in https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/config/config_userapi.c and add a new structure definition in the `checkedparam_t` type defined in https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/config/config_paramdesc.h
+
+[Configuration module developer main page](../../config/devusage.md)
+[Configuration module home](../../config.md)
diff --git a/common/config/DOC/config/devusage/addparamset.md b/common/config/DOC/config/devusage/addparamset.md
new file mode 100644
index 0000000000000000000000000000000000000000..49448e11da79fd2292f0e8105456f6fb3e6ca81a
--- /dev/null
+++ b/common/config/DOC/config/devusage/addparamset.md
@@ -0,0 +1,131 @@
+The configuration module maps a configuration file section to a `paramdef_t` structure array. One `config_get` call can be used to return the values of all the parameters described in the `paramdef_t` array.
+Retrieving a single occurence of a parameter set ( a group in the libconfig terminology) is just a two steps task:
+1.  describe the parameters in a `paramdef_t` array
+1.  call the `config_get` function
+
+
+[config_get example](../../config/devusage/addaparam.md)
+
+
+In oai some parameters set may be instantiated a variable number of occurrences. In a configuration file this is mapped to lists of group of parameters, with this syntax:
+```c
+NB-IoT_MACRLCs =
+/* start list element 1 */
+(
+  /* start a group of parameters */
+  {
+  num_cc = 2;
+  .....
+  remote_s_portd = 55001;
+  }
+),
+/* start list element 2 */
+(
+  /* start a group of parameters */
+  {
+  num_cc = 1;
+  ......
+  remote_s_portd = 65001;
+  }
+);
+
+```
+The configuration module provides the `config_getlist` call to support lists of group of parameters. Below is a commented code example, using the config_getlist call.
+
+```c
+/* name of section containing the list */
+#define NBIOT_MACRLCLIST_CONFIG_STRING      "NB-IoT_MACRLCs"
+
+/*
+The following macro define the parameters names, as used in the
+configuration file
+*/
+#define CONFIG_STRING_MACRLC_CC             "num_cc"
+.....
+#define CONFIG_MACRLC_S_PORTD               "remote_s_portd"
+
+/*
+   now define a macro which will be used to initialize the NbIoT_MacRLC_Params
+   variable. NbIoT_MacRLC_Params is an array of paramdef_t structure, each item
+   describing a parameter. When using the config_getlist call you must let the config
+   module allocate the memory for the parameters values.
+*/
+/*------------------------------------------------------------------------------------------------------------*/
+/*   optname               helpstr   paramflags    XXXptr              defXXXval                  type           numelt     */
+/*------------------------------------------------------------------------------------------------------------*/
+
+#define MACRLCPARAMS_DESC { \
+{CONFIG_STRING_MACRLC_CC, NULL,     0,          uptr:NULL,           defintval:1,           TYPE_UINT,     0}, \
+.............  \
+{CONFIG_MACRLC_S_PORTD,   NULL,     0,          uptr:NULL,           defintval:50021,           TYPE_UINT,     0}, \
+}
+
+/*
+the following macros define the indexes used to access the NbIoT_MacRLC_Params array
+items. They must be maintained consistent with the previous  MACRLCPARAMS_DESC macro
+which is used to initialize the NbIoT_MacRLC_Params variable
+*/
+#define MACRLC_CC_IDX                                          0
+.........
+#define MACRLC_REMOTE_S_PORTD_IDX                              16
+
+
+
+void RCconfig_NbIoTmacrlc(void) {
+
+
+/*
+   define and initialize the array of paramdef_t structures describing the groups of
+   parameters we want to read. It will be passed as the second argument of the
+   config_getlist call, which will use it as an input only argument.
+*/
+  paramdef_t NbIoT_MacRLC_Params[] = MACRLCPARAMS_DESC;
+
+/*
+      now define and initialize a paramlist_def_t structure which will be passed
+   to the config_getlist call. The first field is the only one to be initialized
+   it contains the name of the section to be read.
+   that section contains the list of group of parameters.
+      The two other fields are output parameters used to return respectively
+   a pointer to a two dimensional array of paramdef_t structures pointers, and the
+   number  of items in the list of groups (size of first dimension, the second one
+   being the number of parameters in each group.
+*/
+  paramlist_def_t NbIoT_MacRLC_ParamList = {NBIOT_MACRLCLIST_CONFIG_STRING,NULL,0};
+
+
+ /*
+   the config_getlist will allocate the second field of the paramlist_def_t structure, a
+two dimensional array of paramdef_t pointers. In each param_def item it will allocate
+the value pointer and set the value to what it will get from the config source. The
+numelt field of the paramlist_def_t structure will be set to the number of groups of
+parameters in the list.
+    in this example the last argument of config_getlist is unused, it may contain a
+character string, used as a prefix for the section name. It has to be specified when the
+list to be read is under another section.
+*/
+  config_getlist( &NbIoT_MacRLC_ParamList,NbIoT_MacRLC_Params,
+                  sizeof(NbIoT_MacRLC_Params)/sizeof(paramdef_t),
+                  NULL);
+
+/*
+  start a loop in the nuber of groups in the list, the numelt field of the
+  paramlist_def_t structure has been set in the config_getlist call
+*/
+  for (j=0 ; j<NbIoT_MacRLC_ParamList.numelt ; j++) {
+
+..........
+
+/* access the MACRLC_REMOTE_S_PORTD parameter in the j ieme group of the list */
+	RC.nb_iot_mac[j]->eth_params_s.remote_portd =
+               *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_REMOTE_S_PORTD_IDX].iptr);
+............
+
+  } // MacRLC_ParamList.numelt > 0
+}
+
+
+```
+
+[Configuration module developer main page](../../config/devusage.md)
+[Configuration module home](../../config.md)
diff --git a/common/config/DOC/config/devusage/api.md b/common/config/DOC/config/devusage/api.md
new file mode 100644
index 0000000000000000000000000000000000000000..06c22dba6fe53c91034e48900d90913bb6167f52
--- /dev/null
+++ b/common/config/DOC/config/devusage/api.md
@@ -0,0 +1,49 @@
+```c
+configmodule_interface_t *load_configmodule(int argc, char **argv, uint32_t initflags)
+```
+* Parses the command line options, looking for the –O argument
+* Loads the `libparams_<configsource>.so` (today `libparams_libconfig.so`)  shared library
+* Looks for `config_<config source>_init` symbol and calls it , passing it an array of string corresponding to the « : » separated strings used in the –O option
+* Looks for `config_<config source>_get`, `config_<config source>_getlist` and  `config_<config source>_end` symbols which are the three functions a configuration library should implement. Get and getlist are mandatory, end is optional.
+* Stores all the necessary information in a `configmodule_interface_t structure`, which is of no use for caller as long as we only use one configuration source.
+*  if the bit CONFIG_ENABLECMDLINEONLY is set in `initflags` then the module allows parameters to be set only via the command line. This is used for the oai UE.
+
+```c
+void End_configmodule(void)
+```
+* Free memory which has been allocated by the configuration module since its initialization.
+* Possibly calls the `config_<config source>_end` function
+
+```c
+int config_get(paramdef_t *params,int numparams, char *prefix)
+```
+* Reads as many parameters as described in params, they must all be in the same configuration file section
+* Calls the `config_<config source>_get` function
+* Calls the `config_process_cmdline` function
+* `params` points to an array of `paramdef_t` structures which describes the parameters to be read, possibly including a pointer to a checking function. The following bits can possibly be set in the `paramflags` mask before calling
+ - `PARAMFLAG_MANDATORY`: -1 is returned if the parameter is not explicitly defined in the config source.
+ - `PARAMFLAG_DISABLECMDLINE`: parameter cannot be modified via the command line
+ - `PARAMFLAG_DONOTREAD`: ignore the parameter, can be used at run-time, to alter a pre-defined `paramdef_t` array which is used in several `config_get` or/and `config_getlist` calls.
+ - `PARAMFLAG_NOFREE`: do not free the memory possibly allocated by the config module to store the value of the parameter. Default behavior is for the config module to free the memory it has allocated when the `config_end` function is called.
+ - `PARAMFLAG_BOOL`: Only relevant for integer types. tell the config module that when processing the command line, the corresponding option can be specified without any arggument and that in this case it must set the value to 1.
+
+* `params` is also used as an output parameter, `< XXX >ptr >` field  is used by the config module to store the value it has read. The following bits can possibly be set in the `paramflags` mask after the call:
+  - `PARAMFLAG_MALLOCINCONFIG`: memory has been allocated for the ` < XXX >ptr > ` field
+  - `PARAMFLAG_PARAMSET`: parameter has been found in the config source, it is not set to default value.
+  - `PARAMFLAG_PARAMSET`: parameter has been set to its default value
+* `numparams` is the number of entries in the params array
+* `prefix` is a character string to be appended to the parameters name, it defines the parameters position in the configuration file hierarchy (the section name in libconfig terminology).
+* The returned value is the number of parameters which have been assigned a value or -1 if a severe error occured
+
+```c
+int config_libconfig_getlist(paramlist_def_t *ParamList, paramdef_t *params, int numparams, char *prefix)
+```
+* Reads multiple occurrences of a parameters array
+* Calls the `config_<config source>_get` function for each list occurrence
+* `params` points to an array of `paramdef_t` structures which describes the parameters in each occurrence of the list
+* `ParamList`  points to a structure, where `paramarray` field points to an array of `paramdef_t` structure, allocated by the function. It is used to return the values of the parameters.
+* The returned value is the number of occurrences in the list or -1 in case of severe error
+
+
+[Configuration module developer main page](../../config/devusage.md)
+[Configuration module home](../../config.md)
diff --git a/common/config/DOC/config/devusage/struct.md b/common/config/DOC/config/devusage/struct.md
new file mode 100644
index 0000000000000000000000000000000000000000..e8b15fc0f1e549e03e5ef5692346b8c6e9941c90
--- /dev/null
+++ b/common/config/DOC/config/devusage/struct.md
@@ -0,0 +1,85 @@
+# `paramdef_t`structure
+It is defined in include file [ common/config/config_paramdesc.h ](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/config/config_paramdesc.h#L103). This structure is used by developers to describe parameters and by the configuration module to return parameters value. A pointer to a `paramdef_t` array is passed to `config_get` and `config_getlist` calls to instruct the configuration module what parameters it should read.
+
+| Fields     | Description                                                       | I/O |
+|:-----------|:------------------------------------------------------------------|----:|
+| `optname`    | parameter name, as used when looking for it in the config source, 63 bytes max (64 with trailing \0) | I |
+| `helstr`     | pointer to a C string printed when using --help on the command line | I |
+| `strptr` `strlistptr` `u8ptr` `i8ptr` `u16ptr` `i16ptr` `uptr` `iptr` `u64ptr` `i64ptr` `dblptr` `voidptr` | a pointer to a variable where the parameter value(s) will be returned. This field is an anonymous union, the supported pointer types have been built to avoid type mismatch warnings at compile time. | O |
+| `defstrval` `defstrlistval` `defuintval` `defintval` `defint64val` `defintarrayval` `defdblval` | this field is an anonymous union, it can be used to define the default value for the parameter. It is ignored if `PARAMFLAG_MANDATORY` is set in the `paramflags` field.| I |
+| `type` | Supported parameter types are defined as integer macros. Supported simple types are `TYPE_STRING`, parameter value is returned in `strptr` field,  `TYPE_INT8` `TYPE_UINT8` `TYPE_INT16` `TYPE_UINT16` `TYPE_INT32` `TYPE_UINT32` `TYPE_INT64` `TYPE_UINT64`, parameter value is returned in the corresponding uXptr or iXptr, `TYPE_MASK`, value is returned in `u32ptr`, `TYPE_DOUBLE` value is returned in `dblptr`, `TYPE_IPV4ADDR` value is returned in binary, network bytes order in `u32ptr` field. `TYPE_STRINGLIST`, `TYPE_INTARRAY` and `TYPE_UINTARRAY` are multiple values types. Multiple values are returned in respectively, `strlistptr`, `iptr` and `uptr` fields which then point to arrays. The  `numelt` field gives the number of item in the array. | I |
+| `numelt` | For `TYPE_STRING` where `strptr` points to a preallocated string, this field must contain the size in bytes of the available memory. For all multiple values types, this field contains the number of values in the value field.| I/O |
+| `chkPptr` | possible pointer to the structure containing the info used to check parameter values | I |
+| `processedvalue` | When `chkPptr` is not `ǸULL`, is used to return a value, computed from the original parameter, as read from the configuration source. | O |
+
+# `paramlist_def_t`structure
+It is defined in include file [ common/config/config_paramdesc.h ](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/config/config_paramdesc.h#L160).
+It is used as an argument to `config_getlist` calls, to get values of multiple occurrences of group of parameters.
+
+| Fields     | Description                                                       | I/O |
+|:-----------|:------------------------------------------------------------------|----:|
+| `listname`    | Name of the section containing the list,  63 bytes max (64 with trailing \0). It is used to prefix each paramater name when looking for its value. In the libconfig syntax, the parameter name full path build by the configuration module is: listname.[occurence index].optname. | I |
+| `paramarray`    | Pointer to an array of `ǹumelt` `paramdef_t` pointers. It is allocated by the configuration module and is used to return the parameters values. All input fields of each `paramdef_t` occurence are a copy of the `paramdef_t` argument passed to the `config_getlist` call. | O |
+| `numelt` | Number of items in the `paramarray` field | O |
+
+# `checkedparam_t` union
+It is defined in include file [ common/config/config_paramdesc.h ](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/config/config_paramdesc.h#L62).
+This union of structures is used to provide a parameter checking mechanism. Each `paramdef_t` instance may include a pointer to a `checkedparam_t`structure which is then used by the configuration module to check the value it got from the config source.
+Each structure in the union provides one parameter verification method, which returns `-1` when the verification fails. Currently the following structures  are defined in the `checkedparam_t` union:
+
+| structure name    | Description                                                     |
+|:-----------|:------------------------------------------------------------------|----:|
+| `s1` | check an integer against a list of authorized values |
+| `s1a` | check an integer against a list of authorized values and set the parameter value to another integer depending on the read value|
+| `s2` | check an integer against an authorized range, defined by its min and max value|
+| `s3` | check a string against a list of authorized values |
+| `s3a` | check a string against a list of authorized values and set the parameter value to an integer depending on the read value|
+| `s4` | generic structure, to be used to provide a specific, not defined in the configuration module, verification algorithm |
+
+each of these structures provide the required fields to perform the specified parameter check. The first field is a pointer to a function, taking one argument, the `paramdef_t` structure describing the parameter to be checked. This function is called by the configuration module, in the `config_get` call , after the parameter value has been set, it then uses the other fields of the structure to perform the check.
+The configuration module provides an implementation of the functions to be used to check parameters, qs described below.
+
+## `s1` structure
+| field    | Description                                                     |
+|:-----------|:------------------------------------------------------------------|
+| `f1` | pointer to the checking function. Initialize to `config_check_intval` to use the config module implementation |
+| `okintval` | array of `CONFIG_MAX_NUMCHECKVAL` integers containing the authorized values |
+| `num_okintval` | number of used values in `okintval` |
+
+## `s1a` structure
+| field    | Description                                                     |
+|:-----------|:------------------------------------------------------------------|
+| `f1a` | pointer to the checking function. Initialize to `config_check_modify_integer` to use the config module implementation |
+| `okintval` | array of `CONFIG_MAX_NUMCHECKVAL` integers containing the authorized values |
+| `setintval` | array of `CONFIG_MAX_NUMCHECKVAL` integers containing the values to be used for the parameter. The configuration module implementation set the parameter value to `setintval[i]` when the configured value is `okintval[i]` |
+| `num_okintval` | number of used values in `okintval` and `setintval` |
+
+## `s2` structure
+| field    | Description                                                     |
+|:-----------|:------------------------------------------------------------------|
+| `f2` | pointer to the checking function. Initialize to `config_check_intrange` to use the config module implementation |
+| `okintrange` | array of 2 integers containing the min and max values for the parameter |
+
+## `s3` structure
+| field    | Description                                                     |
+|:-----------|:------------------------------------------------------------------|
+| `f3` | pointer to the checking function. Initialize to `config_check_strval` to use the config module implementation |
+| `okstrval` | array of `CONFIG_MAX_NUMCHECKVAL` C string pointers containing the authorized values |
+| `num_okstrval` | number of used values in `okstrtval` |
+
+
+## `s3a` structure
+| field    | Description                                                     |
+|:-----------|:------------------------------------------------------------------|
+| `f3a` | pointer to the checking function. Initialize to `config_checkstr_assign_integer` to use the config module implementation |
+| `okstrval` | array of `CONFIG_MAX_NUMCHECKVAL` C string pointers containing the authorized values |
+| `setintval` | array of `CONFIG_MAX_NUMCHECKVAL` integers containing the values to be used for the parameter. The configuration module implementation set the parameter value to `setintval[i]` when the configured value is `okstrval[i]` |
+| `num_okstrval` | number of used values in `okintval` and `setintval` |
+
+## `s4` and `s5` structures
+| field    | Description                                                     |
+|:-----------|:------------------------------------------------------------------|
+| `f4`  or `f5` | pointer to the checking function. they are generic structures to be used  when no existing structure provides the required parameter verification. `f4` takes one argument, the `paramdef_t` structure corresponding to the parameter to be checked (`int  (*f4)(paramdef_t *param)`), `f5` taxes no argument (`void (*checkfunc)(void)`) |
+
+[Configuration module developer main page](../../config/devusage.md)
+[Configuration module home](../../config.md)
diff --git a/common/config/DOC/config/rtusage.md b/common/config/DOC/config/rtusage.md
new file mode 100644
index 0000000000000000000000000000000000000000..10cbee24950bb3972f80118745f4efb65a50b516
--- /dev/null
+++ b/common/config/DOC/config/rtusage.md
@@ -0,0 +1,109 @@
+
+   -O  is the only mandatory command line option to start the eNodeb softmodem (lte-softmodem executable), it is used to specify the configuration source with the associated parameters:
+```bash
+$ ./lte-softmodem -O <configsource>:<parameter1>:<parameter2>:...
+```
+  The configuration module can also be used without a configuration source, ie to only parse the command line. In this case the -O switch is optional. This mode is used in the ue-softmodem executable and by the phy_simulators executables (ulsim, dlsim)
+
+Currently the available config sources are:
+
+- **libconfig**: libconfig file. [libconfig file format](http://www.hyperrealm.com/libconfig/libconfig_manual.html#Configuration-Files) Parameter1 is the file path and parameter 2 can be used to specify the level of console messages printed by the configuration module.
+```bash
+$ ./lte-softmodem -O libconfig:<config>:dbgl<debuglevel>
+```
+- **cmdlineonly**: command line only, the default mode for lte-uesoftmodem and the phy simiulators. In this case -O may be used to specify the config module debug level.
+
+The debug level is a mask:
+*  bit 1: print parameters values
+*  bit 2: print memory allocation/free performed by the config module
+*  bit 3: print command line processing messages
+*  bit 4: disable execution abort when parameters checking fails
+
+As a oai user, you may have to use bit 1 (dbgl1) , to check your configuration and get the full name of a parameter you would like to modify on the command line. Other bits are for developers usage, (dbgl7 will print all debug messages).
+
+```bash
+$ ./lte-softmodem -O libconfig:<config>:dbgl1
+```
+```bash
+$ ./lte-uesoftmodem -O cmdlineonly:dbgl1
+```
+To get help on supported parameters you can use specific options:
+*  ---help: print help for command line only parameters and for parameters not defined in a specific section
+	*  ---help_< prefix > : print help for parameters defined under the section < prefix >
+
+```
+./lte-softmodem -O libconfig:/usr/local/oai/conf/enb.nbiot.band7.tm1.50PRB.usrpb210.conf   --help
+[CONFIG] get parameters from libconfig /usr/local/oai/conf/enb.nbiot.band7.tm1.50PRB.usrpb210.conf , debug flags: 0x00000000
+.............................................
+[LIBCONFIG] (root): 19/19 parameters successfully set, (16 to default value)
+
+-----Help for section (root section)            : 019 entries------
+    --rf-config-file: Configuration file for front-end (e.g. LMS7002M)
+    --ulsch-max-errors: set the eNodeB max ULSCH erros
+    --phy-test: test UE phy layer, mac disabled
+    --usim-test: use XOR autentication algo in case of test usim mode
+    --emulate-rf: Emulated RF enabled(disable by defult)
+    --clock: tells hardware to use a clock reference (0:internal, 1:external, 2:gpsdo)
+    --wait-for-sync: Help string not specified
+    --single-thread-enable: Disables single-thread mode in lte-softmodem
+    -C: Set the downlink frequency for all component carriers
+    -a: Channel id offset
+    -d: Enable soft scope and L1 and L2 stats (Xforms)
+    -q: Enable processing timing measurement of lte softmodem on per subframe basis
+    -S: Skip the missed slots/subframes
+    --numerology: adding numerology for 5G
+    --parallel-config: three config for level of parallelism 'PARALLEL_SINGLE_THREAD', 'PARALLEL_RU_L1_SPLIT', or 'PARALLEL_RU_L1_TRX_SPLIT'
+    --worker-config: two option for worker 'WORKER_DISABLE' or 'WORKER_ENABLE'
+    --nbiot-disable: disable nb-iot, even if defined in config
+    --noS1: Disable s1 interface
+    --nokrnmod: (noS1 only): Use tun instead of namesh module
+--------------------------------------------------------------------
+
+[LIBCONFIG] (root): 4/4 parameters successfully set, (4 to default value)
+
+-----Help for section (root section)            : 004 entries------
+    -R: Enable online log
+    -g: Set the global log level, valide options: (4:trace, 3:debug, 2:info, 1:warn, (0:error))
+    --telnetsrv: Start embedded telnet server
+    --msc: Enable the MSC tracing utility
+--------------------------------------------------------------------
+
+[LIBCONFIG] loader: 2/2 parameters successfully set, (2 to default value)
+[LIBCONFIG] loader.telnetsrv: 2/2 parameters successfully set, (1 to default value)
+[LOADER] library libtelnetsrv.so is not loaded: libtelnetsrv.so: cannot open shared object file: No such file or directory
+Getting ENBSParams
+[LIBCONFIG] (root): 3/3 parameters successfully set, (1 to default value)
+
+-----Help for section (root section)            : 003 entries------
+    --Asn1_verbosity: Help string not specified
+    --Active_eNBs: Help string not specified
+    --noS1: Help string not specified
+--------------------------------------------------------------------
+
+/usr/local/oai/issue390_configmodule_cmdlinebug/openairinterface5g/common/config/config_cmdline.c:224 config_process_cmdline() Exiting OAI softmodem: [CONFIG] Exiting after displaying help
+
+```
+
+For the lte-softmodem (the eNodeB) The config source parameter defaults to libconfig, preserving the initial -O option format. In this case you cannot specify the debug level.
+
+```bash
+$ ./lte-softmodem -O <config>
+```
+
+Configuration file parameters, except for the configuration file path,  can be specified in a **config** section in the configuration file:
+
+```
+config:
+{
+    debugflags = 1;
+}
+```
+Configuration files examples can be found in the targets/PROJECTS/GENERIC-LTE-EPC/CONF sub-directory of the oai source tree. To minimize the number of configuration file to maintain, any parameter can also be specified on the command line. For example to modify the lte bandwidth to 20 MHz where the configuration file specifies 10MHz you can enter:
+
+```bash
+$ ./lte-softmodem -O <config> --eNBs.[0].component_carriers.[0].N_RB_DL 100
+```
+
+As specified earlier, use the dbgl1 debug level to get the full name of a parameter you would like to modify on the command line.
+
+[Configuration module home](../config.md)
diff --git a/common/config/config_cmdline.c b/common/config/config_cmdline.c
index 3bd41cf6cc481239a379a616553b3f878ae5a840..0083c2e66bf779924e549c1ee3506d8a721824e8 100644
--- a/common/config/config_cmdline.c
+++ b/common/config/config_cmdline.c
@@ -20,7 +20,7 @@
  */
 
 /*! \file common/config/cmdline/config_libconfig.c
- * \brief configuration module, command line parsing implementation 
+ * \brief configuration module, command line parsing implementation
  * \author Francois TABURET
  * \date 2017
  * \version 0.1
@@ -37,183 +37,260 @@
 #include <errno.h>
 #include <platform_types.h>
 #include "config_userapi.h"
+#include "../utils/LOG/log.h"
 
+int parse_stringlist(paramdef_t *cfgoptions, char *val) {
+  char *atoken;
+  char *tokctx;
+  char *tmpval=strdup(val);
+  int   numelt=0;
+  cfgoptions->numelt=0;
+  atoken=strtok_r(tmpval, ",",&tokctx);
 
-int parse_stringlist(paramdef_t *cfgoptions, char *val)
-{
-char *atoken;
-char *tokctx;
-char *tmpval=strdup(val);
-int   numelt=0;
-
-   cfgoptions->numelt=0;
-
-   atoken=strtok_r(tmpval, ",",&tokctx);
-   while(atoken != NULL) {
-     numelt++ ;
-     atoken=strtok_r(NULL, ",",&tokctx);
-   }
-   free(tmpval);
-   config_check_valptr(cfgoptions,(char **)&(cfgoptions->strlistptr), sizeof(char *) * numelt);
-   cfgoptions->numelt=numelt;
-
-   atoken=strtok_r(val, ",",&tokctx);
-   for( int i=0; i<cfgoptions->numelt && atoken != NULL ; i++) {
-      config_check_valptr(cfgoptions,&(cfgoptions->strlistptr[i]),strlen(atoken)+1);
-      sprintf(cfgoptions->strlistptr[i],"%s",atoken);
-      printf_params("[LIBCONFIG] %s[%i]: %s\n", cfgoptions->optname,i,cfgoptions->strlistptr[i]);
-      atoken=strtok_r(NULL, ",",&tokctx);
-   }
-   return (cfgoptions->numelt > 0); 
+  while(atoken != NULL) {
+    numelt++ ;
+    atoken=strtok_r(NULL, ",",&tokctx);
+  }
+
+  free(tmpval);
+  config_check_valptr(cfgoptions,(char **)&(cfgoptions->strlistptr), sizeof(char *) * numelt);
+  cfgoptions->numelt=numelt;
+  atoken=strtok_r(val, ",",&tokctx);
+
+  for( int i=0; i<cfgoptions->numelt && atoken != NULL ; i++) {
+    config_check_valptr(cfgoptions,&(cfgoptions->strlistptr[i]),strlen(atoken)+1);
+    sprintf(cfgoptions->strlistptr[i],"%s",atoken);
+    printf_params("[LIBCONFIG] %s[%i]: %s\n", cfgoptions->optname,i,cfgoptions->strlistptr[i]);
+    atoken=strtok_r(NULL, ",",&tokctx);
+  }
+
+  return (cfgoptions->numelt > 0);
 }
- 
-int processoption(paramdef_t *cfgoptions, char *value)
-{
-char *tmpval = value;
-int optisset=0;
-char defbool[2]="1";
-
-     
-     if ( value == NULL) {
-        if( (cfgoptions->paramflags &PARAMFLAG_BOOL) == 0 ) { /* not a boolean, argument required */
-	    fprintf(stderr,"[CONFIG] command line, option %s requires an argument\n",cfgoptions->optname);
-	    return 0;
-        } else {        /* boolean value option without argument, set value to true*/
-            tmpval = defbool;
-        }
-     }
-     switch(cfgoptions->type)
-       {
-       	case TYPE_STRING:
-           if (cfgoptions->numelt == 0 ) {
-              config_check_valptr(cfgoptions, cfgoptions->strptr, strlen(tmpval)+1);
-              sprintf(*(cfgoptions->strptr), "%s",tmpval);
-            } else {
-              sprintf( (char *)(cfgoptions->strptr), "%s",tmpval);              
-           }
-           printf_cmdl("[CONFIG] %s set to  %s from command line\n", cfgoptions->optname, tmpval);
-	   optisset=1;
-        break;
-	
-        case TYPE_STRINGLIST:
-           optisset=parse_stringlist(cfgoptions,tmpval); 
-        break;
-        case TYPE_UINT32:
-       	case TYPE_INT32:
-        case TYPE_UINT16:
-       	case TYPE_INT16:
-	case TYPE_UINT8:
-       	case TYPE_INT8:	
-           config_check_valptr(cfgoptions, (char **)&(cfgoptions->iptr),sizeof(int32_t));
-	   config_assign_int(cfgoptions,cfgoptions->optname,(int32_t)strtol(tmpval,NULL,0));  
-	   optisset=1;
-        break;  	
-       	case TYPE_UINT64:
-       	case TYPE_INT64:
-           config_check_valptr(cfgoptions, (char **)&(cfgoptions->i64ptr),sizeof(uint64_t));
-	   *(cfgoptions->i64ptr)=strtoll(tmpval,NULL,0);  
-           printf_cmdl("[CONFIG] %s set to  %lli from command line\n", cfgoptions->optname, (long long)*(cfgoptions->i64ptr));
-	   optisset=1;
-        break;        
-       	case TYPE_UINTARRAY:
-       	case TYPE_INTARRAY:
-
-        break;
-        case TYPE_DOUBLE:
-           config_check_valptr(cfgoptions, (char **)&(cfgoptions->dblptr),sizeof(double)); 
-           *(cfgoptions->dblptr) = strtof(tmpval,NULL);  
-           printf_cmdl("[CONFIG] %s set to  %lf from command line\n", cfgoptions->optname, *(cfgoptions->dblptr));
-	   optisset=1; 
-        break; 
-
-       	case TYPE_IPV4ADDR:
-
-        break;
-
-       default:
-            fprintf(stderr,"[CONFIG] command line, %s type %i  not supported\n",cfgoptions->optname, cfgoptions->type);
-       break;
-       } /* switch on param type */
-       if (optisset == 1) {
-          cfgoptions->paramflags = cfgoptions->paramflags |  PARAMFLAG_PARAMSET;
-       }
-    return optisset;
+
+int processoption(paramdef_t *cfgoptions, char *value) {
+  char *tmpval = value;
+  int optisset=0;
+  char defbool[2]="1";
+
+  if ( value == NULL) {
+    if( (cfgoptions->paramflags &PARAMFLAG_BOOL) == 0 ) { /* not a boolean, argument required */
+      CONFIG_PRINTF_ERROR("[CONFIG] command line, option %s requires an argument\n",cfgoptions->optname);
+    } else {        /* boolean value option without argument, set value to true*/
+      tmpval = defbool;
+    }
+  }
+
+  switch(cfgoptions->type) {
+      char *charptr;
+
+    case TYPE_STRING:
+      if (cfgoptions->numelt == 0 ) {
+        config_check_valptr(cfgoptions, cfgoptions->strptr, strlen(tmpval)+1);
+        sprintf(*(cfgoptions->strptr), "%s",tmpval);
+      } else {
+        sprintf( (char *)(cfgoptions->strptr), "%s",tmpval);
+      }
+
+      printf_cmdl("[CONFIG] %s set to  %s from command line\n", cfgoptions->optname, tmpval);
+      optisset=1;
+      break;
+
+    case TYPE_STRINGLIST:
+      optisset=parse_stringlist(cfgoptions,tmpval);
+      break;
+
+    case TYPE_UINT32:
+    case TYPE_INT32:
+    case TYPE_UINT16:
+    case TYPE_INT16:
+    case TYPE_UINT8:
+    case TYPE_INT8:
+      config_check_valptr(cfgoptions, (char **)&(cfgoptions->iptr),sizeof(int32_t));
+      config_assign_int(cfgoptions,cfgoptions->optname,(int32_t)strtol(tmpval,&charptr,0));
+
+      if( *charptr != 0) {
+        CONFIG_PRINTF_ERROR("[CONFIG] command line, option %s requires an integer argument\n",cfgoptions->optname);
+      }
+
+      optisset=1;
+      break;
+
+    case TYPE_UINT64:
+    case TYPE_INT64:
+      config_check_valptr(cfgoptions, (char **)&(cfgoptions->i64ptr),sizeof(uint64_t));
+      *(cfgoptions->i64ptr)=strtoll(tmpval,&charptr,0);
+
+      if( *charptr != 0) {
+        CONFIG_PRINTF_ERROR("[CONFIG] command line, option %s requires an integer argument\n",cfgoptions->optname);
+      }
+
+      printf_cmdl("[CONFIG] %s set to  %lli from command line\n", cfgoptions->optname, (long long)*(cfgoptions->i64ptr));
+      optisset=1;
+      break;
+
+    case TYPE_UINTARRAY:
+    case TYPE_INTARRAY:
+      break;
+
+    case TYPE_DOUBLE:
+      config_check_valptr(cfgoptions, (char **)&(cfgoptions->dblptr),sizeof(double));
+      *(cfgoptions->dblptr) = strtof(tmpval,&charptr);
+
+      if( *charptr != 0) {
+        CONFIG_PRINTF_ERROR("[CONFIG] command line, option %s requires a double argument\n",cfgoptions->optname);
+      }
+
+      printf_cmdl("[CONFIG] %s set to  %lf from command line\n", cfgoptions->optname, *(cfgoptions->dblptr));
+      optisset=1;
+      break;
+
+    case TYPE_IPV4ADDR:
+      break;
+
+    default:
+      CONFIG_PRINTF_ERROR("[CONFIG] command line, %s type %i  not supported\n",cfgoptions->optname, cfgoptions->type);
+      break;
+  } /* switch on param type */
+
+  if (optisset == 1) {
+    cfgoptions->paramflags = cfgoptions->paramflags |  PARAMFLAG_PARAMSET;
+  }
+
+  return optisset;
 }
 
-int config_process_cmdline(paramdef_t *cfgoptions,int numoptions, char *prefix)
-{
+/*--------------------------------------------------------------------*/
+/*  check unknown options in the command line
+*/
+int config_check_unknown_cmdlineopt(char *prefix) {
+  int unknowndetected=0;
+  char testprefix[CONFIG_MAXOPTLENGTH];
+  int finalcheck = 0;
+  memset(testprefix,0,sizeof(testprefix));
+
+  memset(testprefix,0,sizeof(testprefix));
+  if (prefix != NULL) {
+    if (strcmp(prefix,CONFIG_CHECKALLSECTIONS) == 0)
+      finalcheck = 1;
+    else if (strlen(prefix) > 0) {
+      sprintf(testprefix,"--%.*s.",CONFIG_MAXOPTLENGTH-4,prefix);
+    }
+  }
+
+  for (int i=1; i<config_get_if()->argc ; i++) {
+    if ( !finalcheck && strstr(config_get_if()->argv[i],testprefix) == NULL ) continue;
+
+    if ( !finalcheck && testprefix[0]==0 && index(config_get_if()->argv[i],'.') != NULL) continue;
+
+    if ( !finalcheck && isdigit(config_get_if()->argv[i][0])) continue;
+
+    if ( !finalcheck && config_get_if()->argv[i][0] == '-' && isdigit(config_get_if()->argv[i][1])) continue;
+
+    if ( (config_get_if()->argv_info[i] & CONFIG_CMDLINEOPT_PROCESSED) == 0 ) {
+      fprintf(stderr,"[CONFIG] unknown option: %s\n",
+              config_get_if()->argv[i] );
+      unknowndetected++;
+    }
+  }
+
+  if (unknowndetected > 0) {
+    CONFIG_PRINTF_ERROR("[CONFIG] %i unknown option(s) in command line starting with %s (section %s)\n",
+                        unknowndetected,testprefix,((prefix==NULL)?"":prefix));
+  }
+
+  return unknowndetected;
+}  /* config_check_unknown_cmdlineopt */
+
+int config_process_cmdline(paramdef_t *cfgoptions,int numoptions, char *prefix) {
   int c = config_get_if()->argc;
   int i,j;
   char *pp;
-  char cfgpath[512]; /* 512 should be enough for the sprintf below */
- 
+  char cfgpath[CONFIG_MAXOPTLENGTH];
   j = 0;
   i = 0;
-    while (c > 0 ) {
-        char *oneargv = strdup(config_get_if()->argv[i]);          /* we use strtok_r which modifies its string paramater, and we don't want argv to be modified */
-        /* first check help options, either --help, -h or --help_<section> */
-        if (strncmp(oneargv, "-h",2) == 0 || strncmp(oneargv, "--help",6) == 0 ) {
-            char *tokctx;
-            pp=strtok_r(oneargv, "_",&tokctx);
-            if (pp == NULL || strcasecmp(pp,config_get_if()->argv[i] ) == 0 ) {
-                if( prefix == NULL) {
-                  config_printhelp(cfgoptions,numoptions);
-                  if ( ! ( CONFIG_ISFLAGSET(CONFIG_NOEXITONHELP)))
-                     exit_fun("[CONFIG] Exiting after displaying help\n");
-                }
-            } else {
-                pp=strtok_r(NULL, " ",&tokctx);
-                if ( prefix != NULL && pp != NULL && strncasecmp(prefix,pp,strlen(pp)) == 0 ) { 
-                   printf ("Help for %s section:\n",prefix);               
-                   config_printhelp(cfgoptions,numoptions);
-                   if ( ! (CONFIG_ISFLAGSET(CONFIG_NOEXITONHELP))) {
-                      fprintf(stderr,"[CONFIG] %s %i section %s:", __FILE__, __LINE__, prefix);
-                      exit_fun(" Exiting after displaying help\n");
-                   }
-                }
-            } 
+
+  while (c > 0 ) {
+    char *oneargv = strdup(config_get_if()->argv[i]);          /* we use strtok_r which modifies its string paramater, and we don't want argv to be modified */
+
+    /* first check help options, either --help, -h or --help_<section> */
+    if (strncmp(oneargv, "-h",2) == 0 || strncmp(oneargv, "--help",6) == 0 ) {
+      char *tokctx;
+      pp=strtok_r(oneargv, "_",&tokctx);
+      config_get_if()->argv_info[i] |= CONFIG_CMDLINEOPT_PROCESSED;
+
+      if (pp == NULL || strcasecmp(pp,config_get_if()->argv[i] ) == 0 ) {
+        if( prefix == NULL) {
+          config_printhelp(cfgoptions,numoptions,"(root section)");
+
+          if ( ! ( CONFIG_ISFLAGSET(CONFIG_NOEXITONHELP)))
+            exit_fun("[CONFIG] Exiting after displaying help\n");
+        }
+      } else {
+        pp=strtok_r(NULL, " ",&tokctx);
+
+        if ( prefix != NULL && pp != NULL && strncasecmp(prefix,pp,strlen(pp)) == 0 ) {
+          config_printhelp(cfgoptions,numoptions,prefix);
+
+          if ( ! (CONFIG_ISFLAGSET(CONFIG_NOEXITONHELP))) {
+            fprintf(stderr,"[CONFIG] %s %i section %s:", __FILE__, __LINE__, prefix);
+            exit_fun(" Exiting after displaying help\n");
+          }
         }
+      }
+    }
+
+    /* now, check for non help options */
+    if (oneargv[0] == '-') {
+      for(int n=0; n<numoptions; n++) {
+        if ( ( cfgoptions[n].paramflags & PARAMFLAG_DISABLECMDLINE) != 0) {
+          continue;
+        }
+
+        if (prefix != NULL) {
+          sprintf(cfgpath,"%s.%s",prefix,cfgoptions[n].optname);
+        } else {
+          sprintf(cfgpath,"%s",cfgoptions[n].optname);
+        }
+
+        if ( ((strlen(oneargv) == 2) && (strcmp(oneargv + 1,cfgpath) == 0))  || /* short option, one "-" */
+             ((strlen(oneargv) > 2) && (strcmp(oneargv + 2,cfgpath ) == 0 )) ) {
+          char *valptr=NULL;
+          int ret;
+          config_get_if()->argv_info[i] |= CONFIG_CMDLINEOPT_PROCESSED;
+
+          if (c > 0) {
+            pp = config_get_if()->argv[i+1];
+
+            if (pp != NULL ) {
+              ret = strlen(pp);
+
+              if (ret > 0 ) {
+                if (pp[0] != '-')
+                  valptr=pp;
+                else if ( ret > 1 && pp[0] == '-' && isdigit(pp[1]) )
+                  valptr=pp;
+              }
+            }
+          }
+
+          j += processoption(&(cfgoptions[n]), valptr);
+
+          if (  valptr != NULL ) {
+            i++;
+            config_get_if()->argv_info[i] |= CONFIG_CMDLINEOPT_PROCESSED;
+            c--;
+          }
+
+          break;
+        }
+      } /* for n... */
+    } /* if (oneargv[0] == '-') */
+
+    free(oneargv);
+    i++;
+    c--;
+  }   /* fin du while */
 
-        /* now, check for non help options */
-        if (oneargv[0] == '-') {        
-    	    for(int n=0;n<numoptions;n++) {
-    		if ( ( cfgoptions[n].paramflags & PARAMFLAG_DISABLECMDLINE) != 0) {
-    		  continue;
-    		 }
-    		if (prefix != NULL) {
-    		   sprintf(cfgpath,"%s.%s",prefix,cfgoptions[n].optname);
-    		} else {
-    		   sprintf(cfgpath,"%s",cfgoptions[n].optname);
-    		}
-    		if ( ((strlen(oneargv) == 2) && (strcmp(oneargv + 1,cfgpath) == 0))  || /* short option, one "-" */
-    		     ((strlen(oneargv) > 2) && (strcmp(oneargv + 2,cfgpath ) == 0 )) ) {
-                   char *valptr=NULL;
-                   int ret;
-                   if (c > 0) {
-    		      pp = config_get_if()->argv[i+1];
-                      if (pp != NULL ) {                      
-                         ret = strlen(pp);
-                         if (ret > 0 ) {
-                             if (pp[0] != '-')
-                                valptr=pp;
-                             else if ( ret > 1 && pp[0] == '-' && isdigit(pp[1]) )
-                                valptr=pp;
-                         }
-                     }
-                   }
-                   j += processoption(&(cfgoptions[n]), valptr);
-    		   if (  valptr != NULL ) {
-                      i++;
-                      c--;
-    		   } 
-                   break;
-    		}
-    	     } /* for n... */
-         } /* if (oneargv[0] == '-') */  	     
-         free(oneargv);
-         i++;
-         c--;  
-    }   /* fin du while */
   printf_cmdl("[CONFIG] %s %i options set from command line\n",((prefix == NULL) ? "(root)":prefix),j);
-  return j;            
+  return j;
 }  /* parse_cmdline*/
diff --git a/common/config/config_load_configmodule.c b/common/config/config_load_configmodule.c
index 2c6700c73e3d14bf96eb02e36345d94017c92c5f..a6316d6c3f61fa3c844e01079cd6536c073b6554 100644
--- a/common/config/config_load_configmodule.c
+++ b/common/config/config_load_configmodule.c
@@ -20,7 +20,7 @@
  */
 
 /*! \file common/config/config_load_configmodule.c
- * \brief configuration module, load the shared library implementing the configuration module 
+ * \brief configuration module, load the shared library implementing the configuration module
  * \author Francois TABURET
  * \date 2017
  * \version 0.1
@@ -36,288 +36,323 @@
 #include <unistd.h>
 #include <errno.h>
 #include <dlfcn.h>
+#include <platform_types.h>
 
 #define CONFIG_LOADCONFIG_MAIN
 #include "config_load_configmodule.h"
 #include "config_userapi.h"
+#include "../utils/LOG/log.h"
 #define CONFIG_SHAREDLIBFORMAT "libparams_%s.so"
 
-int load_config_sharedlib(configmodule_interface_t *cfgptr)
-{
-void *lib_handle;
-char fname[128];
-char libname[FILENAME_MAX]; 
-int st;
 
-   st=0;  
-   sprintf(libname,CONFIG_SHAREDLIBFORMAT,cfgptr->cfgmode);
+int load_config_sharedlib(configmodule_interface_t *cfgptr) {
+  void *lib_handle;
+  char fname[128];
+  char libname[FILENAME_MAX];
+  int st;
+  st=0;
+  sprintf(libname,CONFIG_SHAREDLIBFORMAT,cfgptr->cfgmode);
+  lib_handle = dlopen(libname,RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE);
+
+  if (!lib_handle) {
+    fprintf(stderr,"[CONFIG] %s %d Error calling dlopen(%s): %s\n",__FILE__, __LINE__, libname,dlerror());
+    st = -1;
+  } else {
+    sprintf (fname,"config_%s_init",cfgptr->cfgmode);
+    cfgptr->init = dlsym(lib_handle,fname);
+
+    if (cfgptr->init == NULL ) {
+      printf("[CONFIG] %s %d no function %s for config mode %s\n",
+             __FILE__, __LINE__,fname, cfgptr->cfgmode);
+    } else {
+      st=cfgptr->init(cfgptr->cfgP,cfgptr->num_cfgP);
+      printf("[CONFIG] function %s returned %i\n",
+             fname, st);
+    }
+
+    sprintf (fname,"config_%s_get",cfgptr->cfgmode);
+    cfgptr->get = dlsym(lib_handle,fname);
 
-   lib_handle = dlopen(libname,RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE);
-   if (!lib_handle) {
-      fprintf(stderr,"[CONFIG] %s %d Error calling dlopen(%s): %s\n",__FILE__, __LINE__, libname,dlerror());
+    if (cfgptr->get == NULL ) {
+      printf("[CONFIG] %s %d no function %s for config mode %s\n",
+             __FILE__, __LINE__,fname, cfgptr->cfgmode);
       st = -1;
-   } else { 
-      sprintf (fname,"config_%s_init",cfgptr->cfgmode);
-      cfgptr->init = dlsym(lib_handle,fname);
-
-      if (cfgptr->init == NULL ) {
-         printf("[CONFIG] %s %d no function %s for config mode %s\n",
-               __FILE__, __LINE__,fname, cfgptr->cfgmode);
-      } else {
-         st=cfgptr->init(cfgptr->cfgP,cfgptr->num_cfgP); 
-         printf("[CONFIG] function %s returned %i\n",
-               fname, st);	 
-      }
+    }
 
-      sprintf (fname,"config_%s_get",cfgptr->cfgmode);
-      cfgptr->get = dlsym(lib_handle,fname);
-      if (cfgptr->get == NULL ) { 
-         printf("[CONFIG] %s %d no function %s for config mode %s\n",
-               __FILE__, __LINE__,fname, cfgptr->cfgmode);
-	 st = -1;
-      }
-      
-      sprintf (fname,"config_%s_getlist",cfgptr->cfgmode);
-      cfgptr->getlist = dlsym(lib_handle,fname);
-      if (cfgptr->getlist == NULL ) { 
-         printf("[CONFIG] %s %d no function %s for config mode %s\n",
-               __FILE__, __LINE__,fname, cfgptr->cfgmode);
-	 st = -1;
-      }
+    sprintf (fname,"config_%s_getlist",cfgptr->cfgmode);
+    cfgptr->getlist = dlsym(lib_handle,fname);
+
+    if (cfgptr->getlist == NULL ) {
+      printf("[CONFIG] %s %d no function %s for config mode %s\n",
+             __FILE__, __LINE__,fname, cfgptr->cfgmode);
+      st = -1;
+    }
 
-      sprintf (fname,"config_%s_end",cfgptr->cfgmode);
-      cfgptr->end = dlsym(lib_handle,fname);
-      if (cfgptr->getlist == NULL ) { 
-         printf("[CONFIG] %s %d no function %s for config mode %s\n",
-               __FILE__, __LINE__,fname, cfgptr->cfgmode);
-      }      
-   } 
-   
-   return st;	       
+    sprintf (fname,"config_%s_end",cfgptr->cfgmode);
+    cfgptr->end = dlsym(lib_handle,fname);
+
+    if (cfgptr->getlist == NULL ) {
+      printf("[CONFIG] %s %d no function %s for config mode %s\n",
+             __FILE__, __LINE__,fname, cfgptr->cfgmode);
+    }
+  }
+
+  return st;
 }
 /*-----------------------------------------------------------------------------------*/
 /* from here: interface implementtion of the configuration module */
 int nooptfunc(void) {
-   return 0;
+  return 0;
 };
 
-int config_cmdlineonly_getlist(paramlist_def_t *ParamList, 
-                                   paramdef_t *params, int numparams, char *prefix)
-{
-     ParamList->numelt = 0;
-     return 0;
+int config_cmdlineonly_getlist(paramlist_def_t *ParamList,
+                               paramdef_t *params, int numparams, char *prefix) {
+  ParamList->numelt = 0;
+  return 0;
 }
 
 
-int config_cmdlineonly_get(paramdef_t *cfgoptions,int numoptions, char *prefix )
-{
+int config_cmdlineonly_get(paramdef_t *cfgoptions,int numoptions, char *prefix ) {
   int defval;
   int fatalerror=0;
   int numdefvals=0;
-  
-
-  for(int i=0;i<numoptions;i++) {
-     defval=0;
-     switch(cfgoptions[i].type) {
-       case TYPE_STRING:
-            defval=config_setdefault_string(&(cfgoptions[i]), prefix);
-       break;
-       case TYPE_STRINGLIST:
-            defval=config_setdefault_stringlist(&(cfgoptions[i]), prefix);
-       break;
-       	case TYPE_UINT8:
-       	case TYPE_INT8:	
-       	case TYPE_UINT16:
-       	case TYPE_INT16:
-       	case TYPE_UINT32:
-       	case TYPE_INT32:
-       	case TYPE_MASK:	
-             defval=config_setdefault_int(&(cfgoptions[i]), prefix);
+
+  for(int i=0; i<numoptions; i++) {
+    defval=0;
+
+    switch(cfgoptions[i].type) {
+      case TYPE_STRING:
+        defval=config_setdefault_string(&(cfgoptions[i]), prefix);
+        break;
+
+      case TYPE_STRINGLIST:
+        defval=config_setdefault_stringlist(&(cfgoptions[i]), prefix);
+        break;
+
+      case TYPE_UINT8:
+      case TYPE_INT8:
+      case TYPE_UINT16:
+      case TYPE_INT16:
+      case TYPE_UINT32:
+      case TYPE_INT32:
+      case TYPE_MASK:
+        defval=config_setdefault_int(&(cfgoptions[i]), prefix);
         break;
-       	case TYPE_UINT64:
-       	case TYPE_INT64:
-             defval=config_setdefault_int64(&(cfgoptions[i]), prefix);
-        break;        
-       	case TYPE_UINTARRAY:
-       	case TYPE_INTARRAY:
-             defval=config_setdefault_intlist(&(cfgoptions[i]), prefix);
+
+      case TYPE_UINT64:
+      case TYPE_INT64:
+        defval=config_setdefault_int64(&(cfgoptions[i]), prefix);
         break;
-       	case TYPE_DOUBLE:
-             defval=config_setdefault_double(&(cfgoptions[i]), prefix);  
-        break;  
-       	case TYPE_IPV4ADDR:
-             defval=config_setdefault_ipv4addr(&(cfgoptions[i]), prefix); 
-              
+
+      case TYPE_UINTARRAY:
+      case TYPE_INTARRAY:
+        defval=config_setdefault_intlist(&(cfgoptions[i]), prefix);
         break;
-        default:
-            fprintf(stderr,"[CONFIG] %s.%s type %i  not supported\n",prefix, cfgoptions[i].optname,cfgoptions[i].type);
-            fatalerror=1;
+
+      case TYPE_DOUBLE:
+        defval=config_setdefault_double(&(cfgoptions[i]), prefix);
         break;
-      } /* switch on param type */
+
+      case TYPE_IPV4ADDR:
+        defval=config_setdefault_ipv4addr(&(cfgoptions[i]), prefix);
+        break;
+
+      default:
+        fprintf(stderr,"[CONFIG] %s.%s type %i  not supported\n",prefix, cfgoptions[i].optname,cfgoptions[i].type);
+        fatalerror=1;
+        break;
+    } /* switch on param type */
+
     if (defval == 1) {
-    	numdefvals++;
-        cfgoptions[i].paramflags = cfgoptions[i].paramflags |  PARAMFLAG_PARAMSETDEF;
+      numdefvals++;
+      cfgoptions[i].paramflags = cfgoptions[i].paramflags |  PARAMFLAG_PARAMSETDEF;
     }
   } /* for loop on options */
+
   printf("[CONFIG] %s: %i/%i parameters successfully set \n",
-         ((prefix == NULL)?"(root)":prefix), 
+         ((prefix == NULL)?"(root)":prefix),
          numdefvals,numoptions );
+
   if (fatalerror == 1) {
-      fprintf(stderr,"[CONFIG] fatal errors found when assigning %s parameters \n",
-             prefix);
+    fprintf(stderr,"[CONFIG] fatal errors found when assigning %s parameters \n",
+            prefix);
   }
+
   return numdefvals;
 }
 
-configmodule_interface_t *load_configmodule(int argc, char **argv)
-{
-char *cfgparam=NULL;
-char *modeparams=NULL;
-char *cfgmode=NULL;
-char *strtokctx=NULL;
-char *atoken;
-uint32_t tmpflags=0;
-int i;
- 
-/* first parse the command line to look for the -O option */
-  for (i = 0;i<argc;i++) {
-       if (strlen(argv[i]) < 2) continue;
-       if ( argv[i][1] == 'O' && i < (argc -1)) {
-          cfgparam = argv[i+1]; 
-       } 
-       if ( strstr(argv[i], "help_config") != NULL  ) {
-          config_printhelp(Config_Params,CONFIG_PARAMLENGTH(Config_Params));
-          exit(0);
-       }
-       if ( (strcmp(argv[i]+1, "h") == 0) || (strstr(argv[i]+1, "help_") != NULL ) ) {
-          tmpflags = CONFIG_HELP; 
-       }            
-   }
-
-/* look for the OAI_CONFIGMODULE environement variable */
+configmodule_interface_t *load_configmodule(int argc, char **argv, uint32_t initflags) {
+  char *cfgparam=NULL;
+  char *modeparams=NULL;
+  char *cfgmode=NULL;
+  char *strtokctx=NULL;
+  char *atoken;
+  uint32_t tmpflags=0;
+  int i;
+  int OoptIdx=-1;
+
+  /* first parse the command line to look for the -O option */
+  for (i = 0; i<argc; i++) {
+    if (strlen(argv[i]) < 2) continue;
+
+    if ( argv[i][1] == 'O' && i < (argc -1)) {
+      cfgparam = argv[i+1];
+      OoptIdx=i;
+    }
+
+    if ( strstr(argv[i], "help_config") != NULL  ) {
+      config_printhelp(Config_Params,CONFIG_PARAMLENGTH(Config_Params),CONFIG_SECTIONNAME);
+      exit(0);
+    }
+
+    if ( (strcmp(argv[i]+1, "h") == 0) || (strstr(argv[i]+1, "help_") != NULL ) ) {
+      tmpflags = CONFIG_HELP;
+    }
+  }
+
+  /* look for the OAI_CONFIGMODULE environement variable */
   if ( cfgparam == NULL ) {
-     cfgparam = getenv("OAI_CONFIGMODULE");
-     }
+    cfgparam = getenv("OAI_CONFIGMODULE");
+  }
 
-/* default */
+  /* default different for UE and softmodem because UE doesn't use config file*/
+  /* and -O option is not mandatory for UE                                    */
+  /* phy simulators behave as UE                                              */
+  /* test of exec name would better be replaced by a parameter to the l       */
+  /* oad_configmodule function */
   if (cfgparam == NULL) {
-         tmpflags = tmpflags | CONFIG_NOOOPT;
-     if (strstr(argv[0],"uesoftmodem") == NULL) {
-         cfgparam = CONFIG_LIBCONFIGFILE ":" DEFAULT_CFGFILENAME;
-      } else {
-         cfgparam = CONFIG_CMDLINEONLY ":dbgl0" ;         
-      }
-   }
-   
-/* parse the config parameters to set the config source */
-   i = sscanf(cfgparam,"%m[^':']:%ms",&cfgmode,&modeparams);
-   if (i< 0) {
-       fprintf(stderr,"[CONFIG] %s, %d, sscanf error parsing config source  %s: %s\n", __FILE__, __LINE__,cfgparam, strerror(errno));
-       exit(-1);
-   }
-   else if ( i == 1 ) {
-  /* -O argument doesn't contain ":" separator, assume -O <conf file> option, default cfgmode to libconfig
-     with one parameter, the path to the configuration file */
-       modeparams=cfgmode;
-       cfgmode=strdup(CONFIG_LIBCONFIGFILE);
-   }
-
-   cfgptr = malloc(sizeof(configmodule_interface_t));
-   memset(cfgptr,0,sizeof(configmodule_interface_t));
-
-   cfgptr->rtflags = cfgptr->rtflags | tmpflags;
-   cfgptr->argc   = argc;
-   cfgptr->argv   = argv; 
-   cfgptr->cfgmode=strdup(cfgmode);
-   cfgptr->num_cfgP=0;
-   atoken=strtok_r(modeparams,":",&strtokctx);     
-   while ( cfgptr->num_cfgP< CONFIG_MAX_OOPT_PARAMS && atoken != NULL) {
-       /* look for debug level in the config parameters, it is commom to all config mode 
-          and will be removed frome the parameter array passed to the shared module */
-       char *aptr;
-       aptr=strcasestr(atoken,"dbgl");
-       if (aptr != NULL) {
-           cfgptr->rtflags = cfgptr->rtflags | strtol(aptr+4,NULL,0);
-
-       } else {
-           cfgptr->cfgP[cfgptr->num_cfgP] = strdup(atoken);
-           cfgptr->num_cfgP++;
-       }
-       atoken = strtok_r(NULL,":",&strtokctx);
-   }
-
-   
-   printf("[CONFIG] get parameters from %s ",cfgmode);
-   for (i=0;i<cfgptr->num_cfgP; i++) {
-        printf("%s ",cfgptr->cfgP[i]); 
-   }
-   printf(", debug flags: 0x%08x\n",cfgptr->rtflags);
-
-   if (strstr(cfgparam,CONFIG_CMDLINEONLY) == NULL) {
-      i=load_config_sharedlib(cfgptr);
-      if (i ==  0) {
-         printf("[CONFIG] config module %s loaded\n",cfgmode);
-         Config_Params[CONFIGPARAM_DEBUGFLAGS_IDX].uptr=&(cfgptr->rtflags);
-         config_get(Config_Params,CONFIG_PARAMLENGTH(Config_Params), CONFIG_SECTIONNAME );
-      } else {
-         fprintf(stderr,"[CONFIG] %s %d config module \"%s\" couldn't be loaded\n", __FILE__, __LINE__,cfgmode);
-         cfgptr->rtflags = cfgptr->rtflags | CONFIG_HELP | CONFIG_ABORT;
-      } 
-   } else {
-      cfgptr->init = (configmodule_initfunc_t)nooptfunc;
-      cfgptr->get = config_cmdlineonly_get;
-      cfgptr->getlist = config_cmdlineonly_getlist;
-      cfgptr->end = (configmodule_endfunc_t)nooptfunc;
-   }
-
-  
-
-   if (modeparams != NULL) free(modeparams);
-   if (cfgmode != NULL) free(cfgmode);
-   if (CONFIG_ISFLAGSET(CONFIG_ABORT)) {
-       config_printhelp(Config_Params,CONFIG_PARAMLENGTH(Config_Params));
-//       exit(-1);   
-   }
-   return cfgptr;
+    tmpflags = tmpflags | CONFIG_NOOOPT;
+
+    if ( initflags &  CONFIG_ENABLECMDLINEONLY) {
+      cfgparam = CONFIG_CMDLINEONLY ":dbgl0" ;
+    } else {
+      cfgparam = CONFIG_CMDLINEONLY ":dbgl0" ;
+      cfgparam = CONFIG_LIBCONFIGFILE ":" DEFAULT_CFGFILENAME;
+    }
+  }
+
+  /* parse the config parameters to set the config source */
+  i = sscanf(cfgparam,"%m[^':']:%ms",&cfgmode,&modeparams);
+
+  if (i< 0) {
+    fprintf(stderr,"[CONFIG] %s, %d, sscanf error parsing config source  %s: %s\n", __FILE__, __LINE__,cfgparam, strerror(errno));
+    exit(-1) ;
+  } else if ( i == 1 ) {
+    /* -O argument doesn't contain ":" separator, assume -O <conf file> option, default cfgmode to libconfig
+       with one parameter, the path to the configuration file cfgmode must not be NULL */
+    modeparams=cfgmode;
+    cfgmode=strdup(CONFIG_LIBCONFIGFILE);
+  }
+
+  cfgptr = calloc(sizeof(configmodule_interface_t),1);
+  cfgptr->argv_info = calloc(sizeof(int32_t), argc);
+  cfgptr->argv_info[0] |= CONFIG_CMDLINEOPT_PROCESSED;
+
+  if (OoptIdx >= 0) {
+    cfgptr->argv_info[OoptIdx] |= CONFIG_CMDLINEOPT_PROCESSED;
+    cfgptr->argv_info[OoptIdx+1] |= CONFIG_CMDLINEOPT_PROCESSED;
+  }
+
+  cfgptr->rtflags = cfgptr->rtflags | tmpflags;
+  cfgptr->argc   = argc;
+  cfgptr->argv   = argv;
+  cfgptr->cfgmode=strdup(cfgmode);
+  cfgptr->num_cfgP=0;
+  atoken=strtok_r(modeparams,":",&strtokctx);
+
+  while ( cfgptr->num_cfgP< CONFIG_MAX_OOPT_PARAMS && atoken != NULL) {
+    /* look for debug level in the config parameters, it is commom to all config mode
+       and will be removed frome the parameter array passed to the shared module */
+    char *aptr;
+    aptr=strcasestr(atoken,"dbgl");
+
+    if (aptr != NULL) {
+      cfgptr->rtflags = cfgptr->rtflags | strtol(aptr+4,NULL,0);
+    } else {
+      cfgptr->cfgP[cfgptr->num_cfgP] = strdup(atoken);
+      cfgptr->num_cfgP++;
+    }
+
+    atoken = strtok_r(NULL,":",&strtokctx);
+  }
+
+  printf("[CONFIG] get parameters from %s ",cfgmode);
+
+  for (i=0; i<cfgptr->num_cfgP; i++) {
+    printf("%s ",cfgptr->cfgP[i]);
+  }
+
+  printf(", debug flags: 0x%08x\n",cfgptr->rtflags);
+
+  if (strstr(cfgparam,CONFIG_CMDLINEONLY) == NULL) {
+    i=load_config_sharedlib(cfgptr);
+
+    if (i ==  0) {
+      printf("[CONFIG] config module %s loaded\n",cfgmode);
+      Config_Params[CONFIGPARAM_DEBUGFLAGS_IDX].uptr=&(cfgptr->rtflags);
+      config_get(Config_Params,CONFIG_PARAMLENGTH(Config_Params), CONFIG_SECTIONNAME );
+    } else {
+      fprintf(stderr,"[CONFIG] %s %d config module \"%s\" couldn't be loaded\n", __FILE__, __LINE__,cfgmode);
+      cfgptr->rtflags = cfgptr->rtflags | CONFIG_HELP | CONFIG_ABORT;
+    }
+  } else {
+    cfgptr->init = (configmodule_initfunc_t)nooptfunc;
+    cfgptr->get = config_cmdlineonly_get;
+    cfgptr->getlist = config_cmdlineonly_getlist;
+    cfgptr->end = (configmodule_endfunc_t)nooptfunc;
+  }
+
+  if (modeparams != NULL) free(modeparams);
+
+  if (cfgmode != NULL) free(cfgmode);
+
+  if (CONFIG_ISFLAGSET(CONFIG_ABORT)) {
+    config_printhelp(Config_Params,CONFIG_PARAMLENGTH(Config_Params),CONFIG_SECTIONNAME );
+    //       exit(-1);
+  }
+
+  return cfgptr;
 }
 
 
 /* free memory allocated when reading parameters */
 /* config module could be initialized again after this call */
-void end_configmodule(void)
-{ 
+void end_configmodule(void) {
   if (cfgptr != NULL) {
-      if (cfgptr->end != NULL) {
-         printf ("[CONFIG] calling config module end function...\n"); 
-         cfgptr->end();
-      }
+    if (cfgptr->end != NULL) {
+      printf ("[CONFIG] calling config module end function...\n");
+      cfgptr->end();
+    }
 
-      printf ("[CONFIG] free %u config value pointers\n",cfgptr->numptrs);  
-      for(int i=0; i<cfgptr->numptrs ; i++) {
-          if (cfgptr->ptrs[i] != NULL) {
-             free(cfgptr->ptrs[i]);
-             cfgptr->ptrs[i]=NULL;
-          }
+    printf ("[CONFIG] free %u config value pointers\n",cfgptr->numptrs);
+
+    for(int i=0; i<cfgptr->numptrs ; i++) {
+      if (cfgptr->ptrs[i] != NULL) {
+        free(cfgptr->ptrs[i]);
+        cfgptr->ptrs[i]=NULL;
       }
-      cfgptr->numptrs=0;
+    }
+
+    cfgptr->numptrs=0;
   }
 }
 
 /* free all memory used by config module */
 /* should be called only at program exit */
-void free_configmodule(void)
-{ 
+void free_configmodule(void) {
   if (cfgptr != NULL) {
-      end_configmodule();
-      if( cfgptr->cfgmode != NULL) free(cfgptr->cfgmode);
-      printf ("[CONFIG] free %u config parameter pointers\n",cfgptr->num_cfgP);  
-      for (int i=0; i<cfgptr->num_cfgP; i++) {
-          if ( cfgptr->cfgP[i] != NULL) free(cfgptr->cfgP[i]);
-          }
+    end_configmodule();
+
+    if( cfgptr->cfgmode != NULL) free(cfgptr->cfgmode);
 
+    printf ("[CONFIG] free %i config parameter pointers\n",cfgptr->num_cfgP);
+
+    for (int i=0; i<cfgptr->num_cfgP; i++) {
+      if ( cfgptr->cfgP[i] != NULL) free(cfgptr->cfgP[i]);
+    }
 
-  free(cfgptr);
-  cfgptr=NULL;
+    free(cfgptr);
+    cfgptr=NULL;
   }
 }
 
diff --git a/common/config/config_load_configmodule.h b/common/config/config_load_configmodule.h
index ff3fa80f4eaa1357661548f0347b81c97a3be806..d0309c62c3b66fde19ac8ea6338ce7f05993cef2 100644
--- a/common/config/config_load_configmodule.h
+++ b/common/config/config_load_configmodule.h
@@ -20,8 +20,8 @@
  */
 
 /*! \file common/config/config_load_configmodule.h
- * \brief: configuration module, include file to be used by the source code calling the 
- *  configuration module initialization 
+ * \brief: configuration module, include file to be used by the source code calling the
+ *  configuration module initialization
  * \author Francois TABURET
  * \date 2017
  * \version 0.1
@@ -31,12 +31,13 @@
  * \warning
  */
 #ifndef INCLUDE_CONFIG_LOADCONFIGMODULE_H
-#define INCLUDE_CONFIG_LOADCONFIGMODULE_H 
+#define INCLUDE_CONFIG_LOADCONFIGMODULE_H
 
 
 #include <string.h>
 #include <stdlib.h>
 #include "common/config/config_paramdesc.h"
+#include "common/utils/T/T.h"
 #define CONFIG_MAX_OOPT_PARAMS    10     // maximum number of parameters in the -O option (-O <cfgmode>:P1:P2...
 #define CONFIG_MAX_ALLOCATEDPTRS  1024   // maximum number of parameters that can be dynamicaly allocated in the config module
 
@@ -44,12 +45,13 @@
 #define CONFIG_LIBCONFIGFILE        "libconfig"  // use libconfig file
 #define CONFIG_CMDLINEONLY          "cmdline"    // use only command line options
 #define DEFAULT_CFGFILENAME         "oai.conf"   // default config file
-
-/* rtflags bit position definitions */
+/*   bit position definition for the argv_info mask of the configmodule_interface_t structure */
+#define CONFIG_CMDLINEOPT_PROCESSED    (1<<0)   // command line option has been processed
+/*  bit position definitions for the rtflags mask of the configmodule_interface_t structure*/
 #define CONFIG_PRINTPARAMS    1                 // print parameters values while processing
 #define CONFIG_DEBUGPTR       (1<<1)            // print memory allocation/free debug messages
 #define CONFIG_DEBUGCMDLINE   (1<<2)            // print command line processing messages
-#define CONFIG_NOABORTONCHKF  (1<<3)            // disable abort execution when parameter checking function fails
+#define CONFIG_NOABORTONCHKF  (1<<4)            // disable abort execution when parameter checking function fails
 #define CONFIG_NOEXITONHELP   (1<<19)           // do not exit after printing help
 #define CONFIG_HELP           (1<<20)           // print help message
 #define CONFIG_ABORT          (1<<21)           // config failed,abort execution 
@@ -58,10 +60,10 @@ typedef int(*configmodule_initfunc_t)(char *cfgP[],int numP);
 typedef int(*configmodule_getfunc_t)(paramdef_t *,int numparams, char *prefix);
 typedef int(*configmodule_getlistfunc_t)(paramlist_def_t *, paramdef_t *,int numparams, char *prefix);
 typedef void(*configmodule_endfunc_t)(void);
-typedef struct configmodule_interface
-{
+typedef struct configmodule_interface {
   int      argc;
   char     **argv;
+  uint32_t *argv_info;
   char     *cfgmode;
   int      num_cfgP;
   char     *cfgP[CONFIG_MAX_OOPT_PARAMS];
@@ -71,7 +73,7 @@ typedef struct configmodule_interface
   configmodule_endfunc_t          end;
   uint32_t numptrs;
   uint32_t rtflags;
-  char     *ptrs[CONFIG_MAX_ALLOCATEDPTRS];  
+  char     *ptrs[CONFIG_MAX_ALLOCATEDPTRS];
 } configmodule_interface_t;
 
 #ifdef CONFIG_LOADCONFIG_MAIN
@@ -81,17 +83,17 @@ static char config_helpstr [] = "\n lte-softmodem -O [config mode]<:dbgl[debugfl
           debugflags can also be defined in the config_libconfig section of the config file\n \
           debugflags: mask,    1->print parameters, 2->print memory allocations debug messages\n \
                                4->print command line processing debug messages\n ";
-			       
+
 #define CONFIG_SECTIONNAME "config"
 #define CONFIGPARAM_DEBUGFLAGS_IDX        0
 
 
 static paramdef_t Config_Params[] = {
-/*-----------------------------------------------------------------------------------------------------------------------*/
-/*                                            config parameters for config module                                        */
-/*   optname              helpstr           paramflags     XXXptr       defXXXval            type       numelt           */
-/*-----------------------------------------------------------------------------------------------------------------------*/
-{"debugflags",            config_helpstr,   0,             uptr:NULL,   defintval:0,        TYPE_MASK,  0}, 
+  /*-----------------------------------------------------------------------------------------------------------------------*/
+  /*                                            config parameters for config module                                        */
+  /*   optname              helpstr           paramflags     XXXptr       defXXXval            type       numelt           */
+  /*-----------------------------------------------------------------------------------------------------------------------*/
+  {"debugflags",            config_helpstr,   0,             uptr:NULL,   defintval:0,        TYPE_MASK,  0},
 };
 
 #else
@@ -100,10 +102,13 @@ extern configmodule_interface_t *cfgptr;
 
 
 #define printf_params(...) if ( (cfgptr->rtflags & (CONFIG_PRINTPARAMS)) != 0 )  { printf ( __VA_ARGS__ ); }
-#define printf_ptrs(...)   if ( (cfgptr->rtflags & (CONFIG_DEBUGPTR)) != 0 )     { printf ( __VA_ARGS__ ); }     
+#define printf_ptrs(...)   if ( (cfgptr->rtflags & (CONFIG_DEBUGPTR)) != 0 )     { printf ( __VA_ARGS__ ); }
 #define printf_cmdl(...)   if ( (cfgptr->rtflags & (CONFIG_DEBUGCMDLINE)) != 0 ) { printf ( __VA_ARGS__ ); }
- 
-extern configmodule_interface_t *load_configmodule(int argc, char **argv);
+
+#define CONFIG_ENABLECMDLINEONLY  (1<<1)
+extern configmodule_interface_t *load_configmodule(int argc, char **argv, uint32_t initflags);
 extern void end_configmodule(void);
+#define CONFIG_PRINTF_ERROR(f, x... ) if (isLogInitDone ()) { LOG_E(ENB_APP,f,x);} else {printf(f,x);}; if ( !CONFIG_ISFLAGSET(CONFIG_NOABORTONCHKF) ) exit_fun("exit because configuration failed\n");
+
 
 #endif  /* INCLUDE_CONFIG_LOADCONFIGMODULE_H */
diff --git a/common/config/config_paramdesc.h b/common/config/config_paramdesc.h
index c65e298dfbadbca40c25309303e8da8ad5b8e2d1..627c232f85f7a845fcbbd36cd4740073886b3dd4 100644
--- a/common/config/config_paramdesc.h
+++ b/common/config/config_paramdesc.h
@@ -38,7 +38,7 @@
 
 
 #define MAX_OPTNAME_SIZE 64
-
+#define CONFIG_MAXOPTLENGTH 512 /* max full option length, full option name exemple: (prefix1.[<index>].prefix2.optname */
 
 
 /* parameter flags definitions */
@@ -55,83 +55,81 @@
 #define PARAMFLAG_PARAMSET                (1 << 16)        // parameter has been explicitely set in get functions
 #define PARAMFLAG_PARAMSETDEF             (1 << 17)        // parameter has been set to default value in get functions
 
-
 /* checkedparam_t is possibly used in paramdef_t for specific parameter value validation */
 #define CONFIG_MAX_NUMCHECKVAL            20
 typedef struct paramdef paramdef_t;
 typedef union checkedparam {
-        struct  { 
-               int  (*f1)(paramdef_t *param);   /* check an integer against a list of authorized values */
-               int okintval[CONFIG_MAX_NUMCHECKVAL];                        /* integer array, store possible values  */
-               int num_okintval;                                            /* number of valid values in the checkingval array */
-        } s1;
-        struct  { 
-               int  (*f1a)(paramdef_t *param);   /* check an integer against a list of authorized values and set param value */
-                                                 /* to the corresponding item in setintval array (mainly for RRC params)     */
-               int okintval[CONFIG_MAX_NUMCHECKVAL];                        /* integer array, store possible values in config file */
-               int setintval[CONFIG_MAX_NUMCHECKVAL];                        /* integer array, values set in the paramdef structure */
-               int num_okintval;                                            /* number of valid values in the checkingval array */
-        } s1a;
-        struct { 
-               int  (*f2)(paramdef_t *param);  /* check an integer against an authorized range, defined by its min and max value */
-               int okintrange[CONFIG_MAX_NUMCHECKVAL];  /* integer array, store  min and max values  */
-   
-        } s2;
-        struct {
-               int  (*f3)(paramdef_t *param); /* check a string against a list of authorized values */
-               char *okstrval[CONFIG_MAX_NUMCHECKVAL];                      /* string array, store possible values  */
-               int  num_okstrval;                                           /* number of valid values in the checkingval array */
-        } s3;
-        struct {
-               int  (*f3a)(paramdef_t *param); /* check a string against a list of authorized values and set param value */
-                                                 /* to the corresponding item in setintval array (mainly for RRC params) */
-               char *okstrval[CONFIG_MAX_NUMCHECKVAL];                      /* string array, store possible values  */
-               int  setintval[CONFIG_MAX_NUMCHECKVAL];                      /* integer array, values set in the paramdef structure */
-               int  num_okstrval;                                           /* number of valid values in the checkingval array */
-        } s3a;
-        struct {
-               int  (*f4)(paramdef_t *param); /* generic check function, no arguments but the param description */
-               
-        } s4;
-        struct { 
-                void (*checkfunc)(void) ; 
-        } s5;
+  struct  {
+    int  (*f1)(paramdef_t *param);   /* check an integer against a list of authorized values */
+    int okintval[CONFIG_MAX_NUMCHECKVAL];                        /* integer array, store possible values  */
+    int num_okintval;                                            /* number of valid values in the checkingval array */
+  } s1;
+  struct  {
+    int  (*f1a)(paramdef_t *param);   /* check an integer against a list of authorized values and set param value */
+    /* to the corresponding item in setintval array (mainly for RRC params)     */
+    int okintval[CONFIG_MAX_NUMCHECKVAL];                        /* integer array, store possible values in config file */
+    int setintval[CONFIG_MAX_NUMCHECKVAL];                        /* integer array, values set in the paramdef structure */
+    int num_okintval;                                            /* number of valid values in the checkingval array */
+  } s1a;
+  struct {
+    int  (*f2)(paramdef_t *param);  /* check an integer against an authorized range, defined by its min and max value */
+    int okintrange[CONFIG_MAX_NUMCHECKVAL];  /* integer array, store  min and max values  */
+
+  } s2;
+  struct {
+    int  (*f3)(paramdef_t *param); /* check a string against a list of authorized values */
+    char *okstrval[CONFIG_MAX_NUMCHECKVAL];                      /* string array, store possible values  */
+    int  num_okstrval;                                           /* number of valid values in the checkingval array */
+  } s3;
+  struct {
+    int  (*f3a)(paramdef_t *param); /* check a string against a list of authorized values and set param value */
+    /* to the corresponding item in setintval array (mainly for RRC params) */
+    char *okstrval[CONFIG_MAX_NUMCHECKVAL];                      /* string array, store possible values  */
+    int  setintval[CONFIG_MAX_NUMCHECKVAL];                      /* integer array, values set in the paramdef structure */
+    int  num_okstrval;                                           /* number of valid values in the checkingval array */
+  } s3a;
+  struct {
+    int  (*f4)(paramdef_t *param); /* generic check function, no arguments but the param description */
+
+  } s4;
+  struct {
+    void (*checkfunc)(void) ;
+  } s5;
 } checkedparam_t;
 
 /* paramdef is used to describe a parameter, array of paramdef_t strustures is used as the main parameter in */
 /* config apis used to retrieve parameters values  */
-typedef struct paramdef
-{
-   char         optname[MAX_OPTNAME_SIZE]; /* parameter name, can be used as long command line option */
-   char         *helpstr;                  /* help string */
-   unsigned int paramflags;                /* value is a "ored" combination of above PARAMFLAG_XXXX values */
-   union {                                 /* pointer to the parameter value, completed by the config module */
-     char **strptr;
-     char **strlistptr;
-     uint8_t   *u8ptr;
-     int8_t    *i8ptr;     
-     uint16_t  *u16ptr;
-     int16_t   *i16ptr;
-     uint32_t  *uptr;
-     int32_t   *iptr;
-     uint64_t  *u64ptr;
-     int64_t   *i64ptr;
-     double    *dblptr;
-     void      *voidptr;
-     } ;
-   union {                                /* default parameter value, to be used when PARAMFLAG_MANDATORY is not specified */
-     char      *defstrval;
-     char      **defstrlistval;
-     uint32_t  defuintval;
-     int       defintval;
-     uint64_t  defint64val;
-     int       *defintarrayval;
-     double    defdblval;
-     } ;   
-   char type;                              /* parameter value type, as listed below as TYPE_XXXX macro */
-   int numelt;                             /* number of elements in a list or array parameters or max size of string value */ 
-   checkedparam_t   *chkPptr;              /* possible pointer to the structure containing the info used to check parameter values */
-   int *processedvalue;                    /* used to store integer values computed from string original value */
+typedef struct paramdef {
+  char         optname[MAX_OPTNAME_SIZE]; /* parameter name, can be used as long command line option */
+  char         *helpstr;                  /* help string */
+  unsigned int paramflags;                /* value is a "ored" combination of above PARAMFLAG_XXXX values */
+  union {                                 /* pointer to the parameter value, completed by the config module */
+    char **strptr;
+    char **strlistptr;
+    uint8_t   *u8ptr;
+    int8_t    *i8ptr;
+    uint16_t  *u16ptr;
+    int16_t   *i16ptr;
+    uint32_t  *uptr;
+    int32_t   *iptr;
+    uint64_t  *u64ptr;
+    int64_t   *i64ptr;
+    double    *dblptr;
+    void      *voidptr;
+  } ;
+  union {                                /* default parameter value, to be used when PARAMFLAG_MANDATORY is not specified */
+    char      *defstrval;
+    char      **defstrlistval;
+    uint32_t  defuintval;
+    int       defintval;
+    uint64_t  defint64val;
+    int       *defintarrayval;
+    double    defdblval;
+  } ;
+  char type;                              /* parameter value type, as listed below as TYPE_XXXX macro */
+  int numelt;                             /* number of elements in a list or array parameters or max size of string value */
+  checkedparam_t   *chkPptr;              /* possible pointer to the structure containing the info used to check parameter values */
+  int *processedvalue;                    /* used to store integer values computed from string original value */
 } paramdef_t;
 
 #define TYPE_INT        TYPE_INT32
@@ -161,9 +159,9 @@ typedef struct paramdef
 #define ANY_IPV4ADDR_STRING "0.0.0.0"
 
 typedef struct paramlist_def {
-    char listname[MAX_OPTNAME_SIZE];
-    paramdef_t **paramarray;
-    int numelt ;
+  char listname[MAX_OPTNAME_SIZE];
+  paramdef_t **paramarray;
+  int numelt ;
 } paramlist_def_t;
 
 /* macro helpers for module users */
diff --git a/common/config/config_userapi.c b/common/config/config_userapi.c
index 0ec2e2379042042841ceac490adc58be97ee9de2..66d3078d333cc3b697d5ee9ae81b406e213cf064 100644
--- a/common/config/config_userapi.c
+++ b/common/config/config_userapi.c
@@ -39,414 +39,453 @@
 #include <errno.h>
 #include <dlfcn.h>
 #include <arpa/inet.h>
-
 #include <platform_types.h>
 #include "config_userapi.h"
+#include "../utils/LOG/log.h"
 
+configmodule_interface_t *config_get_if(void) {
+  if (cfgptr == NULL) {
+    CONFIG_PRINTF_ERROR("[CONFIG] %s %d config module not initialized\n",__FILE__,__LINE__);
+  }
 
-configmodule_interface_t *config_get_if(void)
-{
-    if (cfgptr == NULL) {
-        fprintf(stderr,"[CONFIG] %s %d config module not initialized\n",__FILE__, __LINE__);
-	exit(-1);
-    }
-    return cfgptr;
+  return cfgptr;
 }
 
-char * config_check_valptr(paramdef_t *cfgoptions, char **ptr, int length) 
-{
-     if (ptr == NULL ) {
-        ptr = malloc(sizeof(char *));
-        if (ptr != NULL) {
-            *ptr=NULL;
-            cfgoptions->strptr=ptr;
-            if ( (cfgoptions->paramflags & PARAMFLAG_NOFREE) == 0) {
-            	config_get_if()->ptrs[config_get_if()->numptrs] = (char *)ptr;
-            	config_get_if()->numptrs++;
-            }
-        } else {		 
-            fprintf(stderr, "[CONFIG] %s %d option %s, cannot allocate pointer: %s \n", 
-                    __FILE__, __LINE__, cfgoptions->optname, strerror(errno));
-            exit(-1);
-        }         
-     }
-     printf_ptrs("[CONFIG] %s ptr: 0x%08lx requested size: %i\n",cfgoptions->optname,(uintptr_t)(ptr),length);
-     if(cfgoptions->numelt > 0 && PARAM_ISSCALAR(cfgoptions)  ) { /* already allocated */
-          if (*ptr != NULL) {
-              return *ptr;
-          } else {
-              fprintf(stderr,"[CONFIG] %s %d option %s, definition error: value pointer is NULL, declared as %i bytes allocated\n", 
-                       __FILE__, __LINE__,cfgoptions->optname, cfgoptions->numelt);
-              exit(-1);
-          }
-     }
-
-     if (*ptr == NULL) {
-        *ptr = malloc(length);
-        if ( *ptr != NULL) {
-             memset(*ptr,0,length);
-             if ( (cfgoptions->paramflags & PARAMFLAG_NOFREE) == 0) {
-                 config_get_if()->ptrs[config_get_if()->numptrs] = *ptr;
-                 config_get_if()->numptrs++;
-             }
-        } else {
-             fprintf (stderr,"[CONFIG] %s %d malloc error\n",__FILE__, __LINE__);
-             exit(-1);
-        }       
-     }
-     return *ptr;
+char *config_check_valptr(paramdef_t *cfgoptions, char **ptr, int length) {
+  if (ptr == NULL ) {
+    ptr = malloc(sizeof(char *));
+
+    if (ptr != NULL) {
+      *ptr=NULL;
+      cfgoptions->strptr=ptr;
+
+      if ( (cfgoptions->paramflags & PARAMFLAG_NOFREE) == 0) {
+        config_get_if()->ptrs[config_get_if()->numptrs] = (char *)ptr;
+        config_get_if()->numptrs++;
+      }
+    } else {
+      CONFIG_PRINTF_ERROR("[CONFIG] %s %d option %s, cannot allocate pointer: %s \n",
+                          __FILE__, __LINE__, cfgoptions->optname, strerror(errno));
+    }
+  }
+
+  printf_ptrs("[CONFIG] %s ptr: 0x%08lx requested size: %i\n",cfgoptions->optname,(uintptr_t)(ptr),length);
+
+  if(cfgoptions->numelt > 0 && PARAM_ISSCALAR(cfgoptions)  ) { /* already allocated */
+    if (*ptr != NULL) {
+      return *ptr;
+    } else {
+      CONFIG_PRINTF_ERROR("[CONFIG] %s %d option %s, definition error: value pointer is NULL, declared as %i bytes allocated\n",
+                          __FILE__, __LINE__,cfgoptions->optname, cfgoptions->numelt);
+    }
+  }
+
+  if (*ptr == NULL) {
+    *ptr = malloc(length);
+
+    if ( *ptr != NULL) {
+      memset(*ptr,0,length);
+
+      if ( (cfgoptions->paramflags & PARAMFLAG_NOFREE) == 0) {
+        config_get_if()->ptrs[config_get_if()->numptrs] = *ptr;
+        config_get_if()->numptrs++;
+      }
+    } else {
+      CONFIG_PRINTF_ERROR("[CONFIG] %s %d malloc error\n",__FILE__, __LINE__);
+    }
+  }
+
+  return *ptr;
 }
 
-void config_assign_int(paramdef_t *cfgoptions, char *fullname, int val)
-{
-int tmpval=val;
+void config_assign_int(paramdef_t *cfgoptions, char *fullname, int val) {
+  int tmpval=val;
+
   if ( ((cfgoptions->paramflags &PARAMFLAG_BOOL) != 0) && tmpval >0) {
-      tmpval =1;
+    tmpval =1;
   }
+
   switch (cfgoptions->type) {
-       	case TYPE_UINT8:
-	     *(cfgoptions->u8ptr) = (uint8_t)tmpval;
-	     printf_params("[CONFIG] %s: %u\n", fullname, (uint8_t)tmpval);
-	break;
-       	case TYPE_INT8:
-	     *(cfgoptions->i8ptr) = (int8_t)tmpval;
-	     printf_params("[CONFIG] %s: %i\n", fullname, (int8_t)tmpval);
-	break;		
-       	case TYPE_UINT16:
-	     *(cfgoptions->u16ptr) = (uint16_t)tmpval;
-	     printf_params("[CONFIG] %s: %hu\n", fullname, (uint16_t)tmpval);     
-	break;
-       	case TYPE_INT16:
-	     *(cfgoptions->i16ptr) = (int16_t)tmpval;
-	     printf_params("[CONFIG] %s: %hi\n", fullname, (int16_t)tmpval);
-	break;	
-       	case TYPE_UINT32:
-	     *(cfgoptions->uptr) = (uint32_t)tmpval;
-	     printf_params("[CONFIG] %s: %u\n", fullname, (uint32_t)tmpval);
-	break;
-       	case TYPE_MASK:
-	     *(cfgoptions->uptr) = *(cfgoptions->uptr) | (uint32_t)tmpval;
-	     printf_params("[CONFIG] %s: 0x%08x\n", fullname, (uint32_t)tmpval);
-	break;
-       	case TYPE_INT32:
-	     *(cfgoptions->iptr) = (int32_t)tmpval;
-	     printf_params("[CONFIG] %s: %i\n", fullname, (int32_t)tmpval);
-	break;	
-	default:
-	     fprintf (stderr,"[CONFIG] %s %i type %i non integer parameter %s not assigned\n",__FILE__, __LINE__,cfgoptions->type,fullname);
-	break;
+    case TYPE_UINT8:
+      *(cfgoptions->u8ptr) = (uint8_t)tmpval;
+      printf_params("[CONFIG] %s: %u\n", fullname, (uint8_t)tmpval);
+      break;
+
+    case TYPE_INT8:
+      *(cfgoptions->i8ptr) = (int8_t)tmpval;
+      printf_params("[CONFIG] %s: %i\n", fullname, (int8_t)tmpval);
+      break;
+
+    case TYPE_UINT16:
+      *(cfgoptions->u16ptr) = (uint16_t)tmpval;
+      printf_params("[CONFIG] %s: %hu\n", fullname, (uint16_t)tmpval);
+      break;
+
+    case TYPE_INT16:
+      *(cfgoptions->i16ptr) = (int16_t)tmpval;
+      printf_params("[CONFIG] %s: %hi\n", fullname, (int16_t)tmpval);
+      break;
+
+    case TYPE_UINT32:
+      *(cfgoptions->uptr) = (uint32_t)tmpval;
+      printf_params("[CONFIG] %s: %u\n", fullname, (uint32_t)tmpval);
+      break;
+
+    case TYPE_MASK:
+      *(cfgoptions->uptr) = *(cfgoptions->uptr) | (uint32_t)tmpval;
+      printf_params("[CONFIG] %s: 0x%08x\n", fullname, (uint32_t)tmpval);
+      break;
+
+    case TYPE_INT32:
+      *(cfgoptions->iptr) = (int32_t)tmpval;
+      printf_params("[CONFIG] %s: %i\n", fullname, (int32_t)tmpval);
+      break;
+
+    default:
+      fprintf (stderr,"[CONFIG] %s %i type %i non integer parameter %s not assigned\n",__FILE__, __LINE__,cfgoptions->type,fullname);
+      break;
   }
 }
 void config_assign_processedint(paramdef_t *cfgoption, int val) {
-        cfgoption->processedvalue = malloc(sizeof(int));
-        if (  cfgoption->processedvalue != NULL) {
-             *(cfgoption->processedvalue) = val;
-        } else {
-             fprintf (stderr,"[CONFIG] %s %d malloc error\n",__FILE__, __LINE__);
-             exit(-1);
-        }            
+  cfgoption->processedvalue = malloc(sizeof(int));
+
+  if (  cfgoption->processedvalue != NULL) {
+    *(cfgoption->processedvalue) = val;
+  } else {
+    CONFIG_PRINTF_ERROR("[CONFIG] %s %d malloc error\n",__FILE__, __LINE__);
+  }
 }
 
 int config_get_processedint(paramdef_t *cfgoption) {
-   int ret;
-        if (  cfgoption->processedvalue != NULL) {
-             ret=*(cfgoption->processedvalue);
-             free( cfgoption->processedvalue);
-             cfgoption->processedvalue=NULL;
-             printf_params("[CONFIG] %s:  set from %s to %i\n",cfgoption->optname, *(cfgoption->strptr), ret);
-        } else {
-             fprintf (stderr,"[CONFIG] %s %d %s has no processed integer availablle\n",__FILE__, __LINE__, cfgoption->optname);
-             ret=0;
-        }
-return ret;            
+  int ret;
+
+  if (  cfgoption->processedvalue != NULL) {
+    ret=*(cfgoption->processedvalue);
+    free( cfgoption->processedvalue);
+    cfgoption->processedvalue=NULL;
+    printf_params("[CONFIG] %s:  set from %s to %i\n",cfgoption->optname, *(cfgoption->strptr), ret);
+  } else {
+    fprintf (stderr,"[CONFIG] %s %d %s has no processed integer availablle\n",__FILE__, __LINE__, cfgoption->optname);
+    ret=0;
+  }
+
+  return ret;
 }
-void config_printhelp(paramdef_t *params,int numparams)
-{
-   for (int i=0 ; i<numparams ; i++) {
-       if ( params[i].helpstr != NULL) {
-           printf("%s%s: %s",
-	           (strlen(params[i].optname) <= 1) ? "-" : "--", 
-	           params[i].optname,
-	           params[i].helpstr);
-       }
-   }
+void config_printhelp(paramdef_t *params,int numparams, char *prefix) {
+  printf("\n-----Help for section %-26s: %03i entries------\n",(prefix==NULL)?"(root section)":prefix ,numparams);
+
+  for (int i=0 ; i<numparams ; i++) {
+    printf("    %s%s: %s",
+           (strlen(params[i].optname) <= 1) ? "-" : "--",
+           params[i].optname,
+           (params[i].helpstr != NULL)?params[i].helpstr:"Help string not specified\n");
+  }   /* for on params entries */
+
+  printf("--------------------------------------------------------------------\n\n");
 }
 
-int config_execcheck(paramdef_t *params,int numparams, char *prefix)
-{
-int st=0;
-
-   for (int i=0 ; i<numparams ; i++) {
-       if ( params[i].chkPptr == NULL) {
-           continue;
-       }
-       if (params[i].chkPptr->s4.f4 != NULL) {
-         st += params[i].chkPptr->s4.f4(&(params[i]));
-       }
-   }
-   if (st != 0) {
-      fprintf(stderr,"[CONFIG] config_execcheck: section %s %i parameters with wrong value\n", prefix, -st); 
-      if ( CONFIG_ISFLAGSET(CONFIG_NOABORTONCHKF) == 0) {
-          exit_fun("exit because configuration failed\n");
-      }
-   }
-return st;
+int config_execcheck(paramdef_t *params,int numparams, char *prefix) {
+  int st=0;
+
+  for (int i=0 ; i<numparams ; i++) {
+    if ( params[i].chkPptr == NULL) {
+      continue;
+    }
+
+    if (params[i].chkPptr->s4.f4 != NULL) {
+      st += params[i].chkPptr->s4.f4(&(params[i]));
+    }
+  }
+
+  if (st != 0) {
+    CONFIG_PRINTF_ERROR("[CONFIG] config_execcheck: section %s %i parameters with wrong value\n", prefix, -st);
+  }
+
+  return st;
 }
 
-int config_get(paramdef_t *params,int numparams, char *prefix)
-{
-int ret= -1;
+int config_get(paramdef_t *params,int numparams, char *prefix) {
+  int ret= -1;
 
-if (CONFIG_ISFLAGSET(CONFIG_ABORT)) {
+  if (CONFIG_ISFLAGSET(CONFIG_ABORT)) {
     fprintf(stderr,"[CONFIG] config_get, section %s skipped, config module not properly initialized\n",prefix);
     return ret;
-}
-configmodule_interface_t *cfgif = config_get_if();
+  }
+
+  configmodule_interface_t *cfgif = config_get_if();
+
   if (cfgif != NULL) {
-      ret = config_get_if()->get(params, numparams,prefix);
-      if (ret >= 0) {
-         config_process_cmdline(params,numparams,prefix);
-         config_execcheck(params,numparams,prefix);
-     }
-  return ret;
+    ret = config_get_if()->get(params, numparams,prefix);
+
+    if (ret >= 0) {
+      config_process_cmdline(params,numparams,prefix);
+      config_execcheck(params,numparams,prefix);
+    }
+
+    return ret;
   }
-return ret;
+
+  return ret;
 }
 
-int config_getlist(paramlist_def_t *ParamList, paramdef_t *params, int numparams, char *prefix)
-{
+int config_getlist(paramlist_def_t *ParamList, paramdef_t *params, int numparams, char *prefix) {
   if (CONFIG_ISFLAGSET(CONFIG_ABORT)) {
     fprintf(stderr,"[CONFIG] config_get skipped, config module not properly initialized\n");
     return -1;
   }
+
   if (!config_get_if())
     return -1;
 
   const int ret = config_get_if()->getlist(ParamList, params, numparams, prefix);
+
   if (ret >= 0 && params) {
     char *newprefix;
+
     if (prefix) {
       int rc = asprintf(&newprefix, "%s.%s", prefix, ParamList->listname);
+
       if (rc < 0) newprefix = NULL;
     } else {
       newprefix = ParamList->listname;
     }
+
     char cfgpath[MAX_OPTNAME_SIZE*2 + 6]; /* prefix.listname.[listindex] */
+
     for (int i = 0; i < ParamList->numelt; ++i) {
       // TODO config_process_cmdline?
       sprintf(cfgpath, "%s.[%i]", newprefix, i);
+      config_process_cmdline(ParamList->paramarray[i],numparams,cfgpath);
       config_execcheck(ParamList->paramarray[i], numparams, cfgpath);
     }
+
     if (prefix)
       free(newprefix);
   }
+
   return ret;
 }
 
-int config_isparamset(paramdef_t *params,int paramidx)
-{
+int config_isparamset(paramdef_t *params,int paramidx) {
   if ((params[paramidx].paramflags & PARAMFLAG_PARAMSET) != 0) {
-      return 1;
+    return 1;
   } else {
-      return 0;
+    return 0;
   }
 }
 
 void print_intvalueerror(paramdef_t *param, char *fname, int *okval, int numokval) {
-    fprintf(stderr,"[CONFIG] %s: %s: %i invalid value, authorized values:\n       ",
-           fname,param->optname, (int)*(param->uptr));
-    for ( int i=0; i<numokval ; i++) {
-         fprintf(stderr, " %i",okval[i]);
-         }
-    fprintf(stderr, " \n");
+  fprintf(stderr,"[CONFIG] %s: %s: %i invalid value, authorized values:\n       ",
+          fname,param->optname, (int)*(param->uptr));
+
+  for ( int i=0; i<numokval ; i++) {
+    fprintf(stderr, " %i",okval[i]);
+  }
+
+  fprintf(stderr, " \n");
 }
- 
-int config_check_intval(paramdef_t *param)
-{
-    if ( param == NULL ){
-       fprintf(stderr,"[CONFIG] config_check_intval: NULL param argument\n");
-       return -1;
-    }
-    for ( int i=0; i<param->chkPptr->s1.num_okintval ; i++) {
-         if( *(param->uptr) == param->chkPptr->s1.okintval[i] ) {
-             return 0;
-         }
-    }
-    print_intvalueerror(param,"config_check_intval", param->chkPptr->s1.okintval,param->chkPptr->s1.num_okintval);
+
+int config_check_intval(paramdef_t *param) {
+  if ( param == NULL ) {
+    fprintf(stderr,"[CONFIG] config_check_intval: NULL param argument\n");
     return -1;
+  }
+
+  for ( int i=0; i<param->chkPptr->s1.num_okintval ; i++) {
+    if( *(param->uptr) == param->chkPptr->s1.okintval[i] ) {
+      return 0;
+    }
+  }
+
+  print_intvalueerror(param,"config_check_intval", param->chkPptr->s1.okintval,param->chkPptr->s1.num_okintval);
+  return -1;
 }
 
-int config_check_modify_integer(paramdef_t *param)
-{
-   
-    for (int i=0; i < param->chkPptr->s1a.num_okintval ; i++) {
-    	if (*(param->uptr) == param->chkPptr->s1a.okintval[i] ) {
-            printf_params("[CONFIG] %s:  read value %i, set to %i\n",param->optname,*(param->uptr),param->chkPptr->s1a.setintval [i]);
-    	    *(param->uptr) = param->chkPptr->s1a.setintval [i];
-    	    return 0; 
-    	}
-   }
-    print_intvalueerror(param,"config_check_modify_integer", param->chkPptr->s1a.okintval,param->chkPptr->s1a.num_okintval);
-    return -1;
+int config_check_modify_integer(paramdef_t *param) {
+  for (int i=0; i < param->chkPptr->s1a.num_okintval ; i++) {
+    if (*(param->uptr) == param->chkPptr->s1a.okintval[i] ) {
+      printf_params("[CONFIG] %s:  read value %i, set to %i\n",param->optname,*(param->uptr),param->chkPptr->s1a.setintval [i]);
+      *(param->uptr) = param->chkPptr->s1a.setintval [i];
+      return 0;
+    }
+  }
+
+  print_intvalueerror(param,"config_check_modify_integer", param->chkPptr->s1a.okintval,param->chkPptr->s1a.num_okintval);
+  return -1;
 }
 
-int config_check_intrange(paramdef_t *param)
-{
-   if( *(param->iptr) >= param->chkPptr->s2.okintrange[0]  && *(param->iptr) <= param->chkPptr->s2.okintrange[1]  ) {
-       return 0;
-   }
-   fprintf(stderr,"[CONFIG] config_check_intrange: %s: %i invalid value, authorized range: %i %i\n",
-           param->optname, (int)*(param->uptr), param->chkPptr->s2.okintrange[0], param->chkPptr->s2.okintrange[1]);
-   return -1;
+int config_check_intrange(paramdef_t *param) {
+  if( *(param->iptr) >= param->chkPptr->s2.okintrange[0]  && *(param->iptr) <= param->chkPptr->s2.okintrange[1]  ) {
+    return 0;
+  }
+
+  fprintf(stderr,"[CONFIG] config_check_intrange: %s: %i invalid value, authorized range: %i %i\n",
+          param->optname, (int)*(param->uptr), param->chkPptr->s2.okintrange[0], param->chkPptr->s2.okintrange[1]);
+  return -1;
 }
 
 void print_strvalueerror(paramdef_t *param, char *fname, char **okval, int numokval) {
-    fprintf(stderr,"[CONFIG] %s: %s: %s invalid value, authorized values:\n       ",
-           fname,param->optname, *(param->strptr));
-    for ( int i=0; i<numokval ; i++) {
-         fprintf(stderr, " %s",okval[i]);
-         }
-    fprintf(stderr, " \n");
+  fprintf(stderr,"[CONFIG] %s: %s: %s invalid value, authorized values:\n       ",
+          fname,param->optname, *(param->strptr));
+
+  for ( int i=0; i<numokval ; i++) {
+    fprintf(stderr, " %s",okval[i]);
+  }
+
+  fprintf(stderr, " \n");
 }
- 
-int config_check_strval(paramdef_t *param)
-{
-    if ( param == NULL ){
-       fprintf(stderr,"[CONFIG] config_check_strval: NULL param argument\n");
-       return -1;
-    }
-    for ( int i=0; i<param->chkPptr->s3.num_okstrval ; i++) {
-         if( strcasecmp(*(param->strptr),param->chkPptr->s3.okstrval[i] ) == 0) {
-             return 0;
-         }
-    }
-    print_strvalueerror(param, "config_check_strval", param->chkPptr->s3.okstrval, param->chkPptr->s3.num_okstrval);
+
+int config_check_strval(paramdef_t *param) {
+  if ( param == NULL ) {
+    fprintf(stderr,"[CONFIG] config_check_strval: NULL param argument\n");
     return -1;
-}
+  }
 
-int config_checkstr_assign_integer(paramdef_t *param)
-{
+  for ( int i=0; i<param->chkPptr->s3.num_okstrval ; i++) {
+    if( strcasecmp(*(param->strptr),param->chkPptr->s3.okstrval[i] ) == 0) {
+      return 0;
+    }
+  }
+
+  print_strvalueerror(param, "config_check_strval", param->chkPptr->s3.okstrval, param->chkPptr->s3.num_okstrval);
+  return -1;
+}
 
+int config_checkstr_assign_integer(paramdef_t *param) {
+  for (int i=0; i < param->chkPptr->s3a.num_okstrval ; i++) {
+    if (strcasecmp(*(param->strptr),param->chkPptr->s3a.okstrval[i]  ) == 0) {
+      config_assign_processedint(param, param->chkPptr->s3a.setintval[i]);
+      return 0;
+    }
+  }
 
-    for (int i=0; i < param->chkPptr->s3a.num_okstrval ; i++) {
-    	if (strcasecmp(*(param->strptr),param->chkPptr->s3a.okstrval[i]  ) == 0) {
-            config_assign_processedint(param, param->chkPptr->s3a.setintval[i]);
-    	    return 0; 
-    	}
-   }
-   print_strvalueerror(param, "config_check_strval", param->chkPptr->s3a.okstrval, param->chkPptr->s3a.num_okstrval);
+  print_strvalueerror(param, "config_check_strval", param->chkPptr->s3a.okstrval, param->chkPptr->s3a.num_okstrval);
+  return -1;
+}
 
-    return -1;
+void config_set_checkfunctions(paramdef_t *params, checkedparam_t *checkfunctions, int numparams) {
+  for (int i=0; i< numparams ; i++ ) {
+    params[i].chkPptr = &(checkfunctions[i]);
+  }
 }
 
-int config_setdefault_string(paramdef_t *cfgoptions, char *prefix)
-{
+int config_setdefault_string(paramdef_t *cfgoptions, char *prefix) {
   int status = 0;
+
   if( cfgoptions->defstrval != NULL) {
-     status=1;
-
-     if (cfgoptions->numelt == 0 ) {
-	 config_check_valptr(cfgoptions, (char **)(cfgoptions->strptr), sizeof(char *));
-	 config_check_valptr(cfgoptions, cfgoptions->strptr, strlen(cfgoptions->defstrval)+1);
-	 sprintf(*(cfgoptions->strptr), "%s",cfgoptions->defstrval);
-	 printf_params("[CONFIG] %s.%s set to default value \"%s\"\n", ((prefix == NULL) ? "" : prefix), cfgoptions->optname, *(cfgoptions->strptr));
-     } else {
-	sprintf((char *)*(cfgoptions->strptr), "%s",cfgoptions->defstrval);
-	printf_params("[CONFIG] %s.%s set to default value \"%s\"\n", ((prefix == NULL) ? "" : prefix), cfgoptions->optname, (char *)*(cfgoptions->strptr));
-     }
+    status=1;
+
+    if (cfgoptions->numelt == 0 ) {
+      config_check_valptr(cfgoptions, (char **)(cfgoptions->strptr), sizeof(char *));
+      config_check_valptr(cfgoptions, cfgoptions->strptr, strlen(cfgoptions->defstrval)+1);
+      sprintf(*(cfgoptions->strptr), "%s",cfgoptions->defstrval);
+      printf_params("[CONFIG] %s.%s set to default value \"%s\"\n", ((prefix == NULL) ? "" : prefix), cfgoptions->optname, *(cfgoptions->strptr));
+    } else {
+      sprintf((char *)*(cfgoptions->strptr), "%s",cfgoptions->defstrval);
+      printf_params("[CONFIG] %s.%s set to default value \"%s\"\n", ((prefix == NULL) ? "" : prefix), cfgoptions->optname, (char *)*(cfgoptions->strptr));
+    }
   }
+
   return status;
 }
 
-int config_setdefault_stringlist(paramdef_t *cfgoptions, char *prefix)
-{
+int config_setdefault_stringlist(paramdef_t *cfgoptions, char *prefix) {
   int status = 0;
+
   if( cfgoptions->defstrlistval != NULL) {
-     cfgoptions->strlistptr=cfgoptions->defstrlistval;
-     status=1;
-     for(int j=0; j<cfgoptions->numelt; j++)
-  	 printf_params("[CONFIG] %s.%s[%i] set to default value %s\n", ((prefix == NULL) ? "" : prefix), cfgoptions->optname,j, cfgoptions->strlistptr[j]);
+    cfgoptions->strlistptr=cfgoptions->defstrlistval;
+    status=1;
+
+    for(int j=0; j<cfgoptions->numelt; j++)
+      printf_params("[CONFIG] %s.%s[%i] set to default value %s\n", ((prefix == NULL) ? "" : prefix), cfgoptions->optname,j, cfgoptions->strlistptr[j]);
   }
+
   return status;
 }
 
-int config_setdefault_int(paramdef_t *cfgoptions, char *prefix)
-{
+int config_setdefault_int(paramdef_t *cfgoptions, char *prefix) {
   int status = 0;
   config_check_valptr(cfgoptions, (char **)(&(cfgoptions->iptr)),sizeof(int32_t));
+
   if( ((cfgoptions->paramflags & PARAMFLAG_MANDATORY) == 0)) {
-     config_assign_int(cfgoptions,cfgoptions->optname,cfgoptions->defintval);
-     status=1;
-     printf_params("[CONFIG] %s.%s set to default value\n", ((prefix == NULL) ? "" : prefix), cfgoptions->optname);
+    config_assign_int(cfgoptions,cfgoptions->optname,cfgoptions->defintval);
+    status=1;
+    printf_params("[CONFIG] %s.%s set to default value\n", ((prefix == NULL) ? "" : prefix), cfgoptions->optname);
   }
+
   return status;
-}	
+}
 
-int config_setdefault_int64(paramdef_t *cfgoptions, char *prefix)
-{
+int config_setdefault_int64(paramdef_t *cfgoptions, char *prefix) {
   int status = 0;
   config_check_valptr(cfgoptions, (char **)&(cfgoptions->i64ptr),sizeof(long long));
+
   if( ((cfgoptions->paramflags & PARAMFLAG_MANDATORY) == 0)) {
-     *(cfgoptions->u64ptr)=cfgoptions->defuintval;
-     status=1;
-     printf_params("[CONFIG] %s.%s set to default value %llu\n", ((prefix == NULL) ? "" : prefix), cfgoptions->optname, (long long unsigned)(*(cfgoptions->u64ptr)));
+    *(cfgoptions->u64ptr)=cfgoptions->defuintval;
+    status=1;
+    printf_params("[CONFIG] %s.%s set to default value %llu\n", ((prefix == NULL) ? "" : prefix), cfgoptions->optname, (long long unsigned)(*(cfgoptions->u64ptr)));
   }
+
   return status;
 }
 
-int config_setdefault_intlist(paramdef_t *cfgoptions, char *prefix)
-{
-  int status = 0;	  
+int config_setdefault_intlist(paramdef_t *cfgoptions, char *prefix) {
+  int status = 0;
+
   if( cfgoptions->defintarrayval != NULL) {
-    config_check_valptr(cfgoptions,(char **)&(cfgoptions->iptr), sizeof(int32_t*));
+    config_check_valptr(cfgoptions,(char **)&(cfgoptions->iptr), sizeof(int32_t *));
     cfgoptions->iptr=cfgoptions->defintarrayval;
     status=1;
+
     for (int j=0; j<cfgoptions->numelt ; j++) {
-  	printf_params("[CONFIG] %s[%i] set to default value %i\n",cfgoptions->optname ,j,(int)cfgoptions->iptr[j]);
+      printf_params("[CONFIG] %s[%i] set to default value %i\n",cfgoptions->optname ,j,(int)cfgoptions->iptr[j]);
     }
   }
+
   return status;
 }
 
-int config_setdefault_double(paramdef_t *cfgoptions, char *prefix)
-{
+int config_setdefault_double(paramdef_t *cfgoptions, char *prefix) {
   int status = 0;
   config_check_valptr(cfgoptions, (char **)&(cfgoptions->dblptr),sizeof(double));
+
   if( ((cfgoptions->paramflags & PARAMFLAG_MANDATORY) == 0)) {
-     *(cfgoptions->u64ptr)=cfgoptions->defdblval;
-     status=1;
-     printf_params("[CONFIG] %s set to default value %lf\n",cfgoptions->optname , *(cfgoptions->dblptr));
+    *(cfgoptions->u64ptr)=cfgoptions->defdblval;
+    status=1;
+    printf_params("[CONFIG] %s set to default value %lf\n",cfgoptions->optname , *(cfgoptions->dblptr));
   }
+
   return status;
-} 
+}
 
-int config_assign_ipv4addr(paramdef_t *cfgoptions, char *ipv4addr)
-{
+int config_assign_ipv4addr(paramdef_t *cfgoptions, char *ipv4addr) {
   config_check_valptr(cfgoptions,(char **)&(cfgoptions->uptr), sizeof(int));
-  int rst=inet_pton(AF_INET, ipv4addr ,cfgoptions->uptr ); 
+  int rst=inet_pton(AF_INET, ipv4addr ,cfgoptions->uptr );
+
   if (rst == 1 && *(cfgoptions->uptr) > 0) {
-     printf_params("[CONFIG] %s: %s\n",cfgoptions->optname, ipv4addr);
-     return 1;
+    printf_params("[CONFIG] %s: %s\n",cfgoptions->optname, ipv4addr);
+    return 1;
   } else {
-     if ( strncmp(ipv4addr,ANY_IPV4ADDR_STRING,sizeof(ANY_IPV4ADDR_STRING)) == 0) {
-  	printf_params("[CONFIG] %s:%s (INADDR_ANY) \n",cfgoptions->optname,ipv4addr);
-  	*cfgoptions->uptr=INADDR_ANY;
-        return 1;
-     } else {
-  	fprintf(stderr,"[CONFIG] %s not valid for %s \n", ipv4addr, cfgoptions->optname);
-     	return -1;
-     }
+    if ( strncmp(ipv4addr,ANY_IPV4ADDR_STRING,sizeof(ANY_IPV4ADDR_STRING)) == 0) {
+      printf_params("[CONFIG] %s:%s (INADDR_ANY) \n",cfgoptions->optname,ipv4addr);
+      *cfgoptions->uptr=INADDR_ANY;
+      return 1;
+    } else {
+      fprintf(stderr,"[CONFIG] %s not valid for %s \n", ipv4addr, cfgoptions->optname);
+      return -1;
+    }
   }
+
   return 0;
 }
 
 
-int config_setdefault_ipv4addr(paramdef_t *cfgoptions,  char *prefix)
-{
+int config_setdefault_ipv4addr(paramdef_t *cfgoptions,  char *prefix) {
   int status = 0;
- 
+
   if (cfgoptions->defstrval != NULL) {
-     status = config_assign_ipv4addr(cfgoptions, cfgoptions->defstrval);
+    status = config_assign_ipv4addr(cfgoptions, cfgoptions->defstrval);
   }
+
   return status;
-}    
+}
diff --git a/common/config/config_userapi.h b/common/config/config_userapi.h
index 2b40f8401be2466cda9adfbbb3725910b83fd828..cc07b1af5fbdabe89c814a9d79a2d2fd11ee9e90 100644
--- a/common/config/config_userapi.h
+++ b/common/config/config_userapi.h
@@ -20,7 +20,7 @@
  */
 
 /*! \file common/config/config_userapi.h
- * \brief: configuration module, include file to be used by the source code calling the 
+ * \brief: configuration module, include file to be used by the source code calling the
  *  configuration module to access configuration parameters
  * \author Francois TABURET
  * \date 2017
@@ -31,7 +31,7 @@
  * \warning
  */
 #ifndef INCLUDE_CONFIG_USERAPI_H
-#define INCLUDE_CONFIG_USERAPI_H 
+#define INCLUDE_CONFIG_USERAPI_H
 #include "config_load_configmodule.h"
 
 #ifdef __cplusplus
@@ -48,17 +48,22 @@ extern "C"
 #define CONFIG_ISPARAMFLAGSET(P,F) ( !!(P.paramflags & F))
 /* utility functions, to be used by configuration module and/or configuration libraries */
 extern configmodule_interface_t *config_get_if(void);
-extern char * config_check_valptr(paramdef_t *cfgoptions, char **ptr, int length) ;
-extern void config_printhelp(paramdef_t *,int numparams);
+extern char *config_check_valptr(paramdef_t *cfgoptions, char **ptr, int length) ;
+extern void config_printhelp(paramdef_t *,int numparams, char *prefix);
 extern int config_process_cmdline(paramdef_t *params,int numparams, char *prefix);
 extern void config_assign_processedint(paramdef_t *cfgoption, int val);
 extern void config_assign_int(paramdef_t *cfgoptions, char *fullname, int val);
 extern int config_assign_ipv4addr(paramdef_t *cfgoptions, char *ipv4addr);
 
-/* apis to get parameters, to be used by oai modules, at configuration time */
+/* apis to get/check parameters, to be used by oai modules, at configuration time */
+#define CONFIG_CHECKALLSECTIONS "ALLSECTIONS"
+extern int config_check_unknown_cmdlineopt(char *prefix);
 extern int config_get(paramdef_t *params,int numparams, char *prefix);
 extern int config_getlist(paramlist_def_t *ParamList, paramdef_t *params, int numparams, char *prefix);
 
+/* apis to set some of the paramdef_t fields before using the get/getlist api's */
+extern void config_set_checkfunctions(paramdef_t *params, checkedparam_t *checkfunctions, int numparams);
+
 /* apis to retrieve parameters info after calling get or getlist functions */
 extern int config_isparamset(paramdef_t *params,int paramidx);
 extern int config_get_processedint(paramdef_t *cfgoption);
diff --git a/common/config/libconfig/config_libconfig.c b/common/config/libconfig/config_libconfig.c
index cb6fa46293ed77aa97812e557f8d6c4843c10ef9..2d861f2dc33df5684730d1cf1af9bfe57c0c73d2 100644
--- a/common/config/libconfig/config_libconfig.c
+++ b/common/config/libconfig/config_libconfig.c
@@ -42,60 +42,60 @@
 #include "errno.h"
 
 #if ( LIBCONFIG_VER_MAJOR == 1 && LIBCONFIG_VER_MINOR < 5)
-#define config_setting_lookup config_lookup_from
+  #define config_setting_lookup config_lookup_from
 #endif
 
 void config_libconfig_end(void );
 
-int read_strlist(paramdef_t *cfgoptions,config_setting_t *setting, char *cfgpath)
-{
-const char *str;
-int st;
-int numelt;
-
-   numelt=config_setting_length(setting);
-   config_check_valptr(cfgoptions,(char **)&(cfgoptions->strlistptr), sizeof(char *) * numelt);
-   st=0;
-   for (int i=0; i< numelt ; i++) {
-       str=config_setting_get_string_elem(setting,i);
-       if (str==NULL) {
-          printf("[LIBCONFIG] %s%i  not found in config file\n", cfgoptions->optname,i);
-       } else {
-            config_check_valptr(cfgoptions,&(cfgoptions->strlistptr[i]),strlen(str)+1);
-            sprintf(cfgoptions->strlistptr[i],"%s",str);
-	    st++;
-            printf_params("[LIBCONFIG] %s%i: %s\n", cfgpath,i,cfgoptions->strlistptr[i]);
-       }
-   }
-   cfgoptions->numelt=numelt;
-   return st;
+int read_strlist(paramdef_t *cfgoptions,config_setting_t *setting, char *cfgpath) {
+  const char *str;
+  int st;
+  int numelt;
+  numelt=config_setting_length(setting);
+  config_check_valptr(cfgoptions,(char **)&(cfgoptions->strlistptr), sizeof(char *) * numelt);
+  st=0;
+
+  for (int i=0; i< numelt ; i++) {
+    str=config_setting_get_string_elem(setting,i);
+
+    if (str==NULL) {
+      printf("[LIBCONFIG] %s%i  not found in config file\n", cfgoptions->optname,i);
+    } else {
+      config_check_valptr(cfgoptions,&(cfgoptions->strlistptr[i]),strlen(str)+1);
+      sprintf(cfgoptions->strlistptr[i],"%s",str);
+      st++;
+      printf_params("[LIBCONFIG] %s%i: %s\n", cfgpath,i,cfgoptions->strlistptr[i]);
+    }
+  }
+
+  cfgoptions->numelt=numelt;
+  return st;
 }
 
-int read_intarray(paramdef_t *cfgoptions,config_setting_t *setting, char *cfgpath)
-{
-
-   cfgoptions->numelt=config_setting_length(setting);
-   
-   if (cfgoptions->numelt > 0) {
-       cfgoptions->iptr=malloc(sizeof(int) * (cfgoptions->numelt));
-       for (int i=0; i< cfgoptions->numelt && cfgoptions->iptr != NULL; i++) {
-            cfgoptions->iptr[i]=config_setting_get_int_elem(setting,i);
-            printf_params("[LIBCONFIG] %s[%i]: %i\n", cfgpath,i,cfgoptions->iptr[i]);
-       } /* for loop on array element... */
-   }
-   return cfgoptions->numelt;
+int read_intarray(paramdef_t *cfgoptions,config_setting_t *setting, char *cfgpath) {
+  cfgoptions->numelt=config_setting_length(setting);
+
+  if (cfgoptions->numelt > 0) {
+    cfgoptions->iptr=malloc(sizeof(int) * (cfgoptions->numelt));
+
+    for (int i=0; i< cfgoptions->numelt && cfgoptions->iptr != NULL; i++) {
+      cfgoptions->iptr[i]=config_setting_get_int_elem(setting,i);
+      printf_params("[LIBCONFIG] %s[%i]: %i\n", cfgpath,i,cfgoptions->iptr[i]);
+    } /* for loop on array element... */
+  }
+
+  return cfgoptions->numelt;
 }
 
 
 
 
-int config_libconfig_get(paramdef_t *cfgoptions,int numoptions, char *prefix )
-{
+int config_libconfig_get(paramdef_t *cfgoptions,int numoptions, char *prefix ) {
   config_setting_t *setting;
   char *str;
   int i,u;
   long long int llu;
-  double dbl; 
+  double dbl;
   int rst;
   int status=0;
   int notfound;
@@ -104,211 +104,244 @@ int config_libconfig_get(paramdef_t *cfgoptions,int numoptions, char *prefix )
   int numdefvals=0;
   char cfgpath[512];  /* 512 should be enough for the sprintf below */
 
-  for(i=0;i<numoptions;i++) {
-
-     if (prefix != NULL) {
-         sprintf(cfgpath,"%s.%s",prefix,cfgoptions[i].optname);
-     } else {
-         sprintf(cfgpath,"%s",cfgoptions[i].optname);
-     }
-
-     if( (cfgoptions->paramflags & PARAMFLAG_DONOTREAD) != 0) {
-         printf_params("[LIBCONFIG] %s.%s ignored\n", cfgpath,cfgoptions[i].optname );
-         continue;
-     }
-     notfound=0;
-     defval=0;
-     switch(cfgoptions[i].type)
-       {
-       	case TYPE_STRING:
-           if ( config_lookup_string(&(libconfig_privdata.cfg),cfgpath, (const char **)&str)) {
-              if ( cfgoptions[i].numelt > 0  && str != NULL && strlen(str) >= cfgoptions[i].numelt ) {
-                  fprintf(stderr,"[LIBCONFIG] %s:  %s exceeds maximum length of %i bytes, value truncated\n",
-                           cfgpath,str,cfgoptions[i].numelt); 
-                  str[strlen(str)-1] = 0;
-              }
-              if (cfgoptions[i].numelt == 0 ) {
-        //          config_check_valptr(&(cfgoptions[i]), (char **)(&(cfgoptions[i].strptr)), sizeof(char *));
-                  config_check_valptr(&(cfgoptions[i]), cfgoptions[i].strptr, strlen(str)+1);
-                  sprintf( *(cfgoptions[i].strptr) , "%s", str);
-                  printf_params("[LIBCONFIG] %s: \"%s\"\n", cfgpath,*(cfgoptions[i].strptr) );
-              } else {
-                 sprintf( (char *)(cfgoptions[i].strptr) , "%s", str);
-                 printf_params("[LIBCONFIG] %s: \"%s\"\n", cfgpath,(char *)cfgoptions[i].strptr );
-              }
-           } else {
-              defval=config_setdefault_string(&(cfgoptions[i]),prefix); 
-	   }
-       break;
-       	case TYPE_STRINGLIST:
-	   setting = config_setting_lookup (config_root_setting(&(libconfig_privdata.cfg)),cfgpath );
-           if ( setting != NULL) {
-              read_strlist(&cfgoptions[i],setting,cfgpath);
-           } else {
-              defval=config_setdefault_stringlist(&(cfgoptions[i]),prefix);
-	   }
-       break;
-       	case TYPE_UINT8:
-       	case TYPE_INT8:	
-       	case TYPE_UINT16:
-       	case TYPE_INT16:
-       	case TYPE_UINT32:
-       	case TYPE_INT32:
-       	case TYPE_MASK:	
-           if ( config_lookup_int(&(libconfig_privdata.cfg),cfgpath, &u)) {
-              config_check_valptr(&(cfgoptions[i]), (char **)(&(cfgoptions[i].iptr)),sizeof(int32_t));
-	      config_assign_int(&(cfgoptions[i]),cfgpath,u);
-           } else {
-              defval=config_setdefault_int(&(cfgoptions[i]),prefix);
-	   }	      
+  for(i=0; i<numoptions; i++) {
+    if (prefix != NULL) {
+      sprintf(cfgpath,"%s.%s",prefix,cfgoptions[i].optname);
+    } else {
+      sprintf(cfgpath,"%s",cfgoptions[i].optname);
+    }
+
+    if( (cfgoptions->paramflags & PARAMFLAG_DONOTREAD) != 0) {
+      printf_params("[LIBCONFIG] %s.%s ignored\n", cfgpath,cfgoptions[i].optname );
+      continue;
+    }
+
+    notfound=0;
+    defval=0;
+
+    switch(cfgoptions[i].type) {
+      case TYPE_STRING:
+        if ( config_lookup_string(&(libconfig_privdata.cfg),cfgpath, (const char **)&str)) {
+          if ( cfgoptions[i].numelt > 0  && str != NULL && strlen(str) >= cfgoptions[i].numelt ) {
+            fprintf(stderr,"[LIBCONFIG] %s:  %s exceeds maximum length of %i bytes, value truncated\n",
+                    cfgpath,str,cfgoptions[i].numelt);
+            str[strlen(str)-1] = 0;
+          }
+
+          if (cfgoptions[i].numelt == 0 ) {
+            //          config_check_valptr(&(cfgoptions[i]), (char **)(&(cfgoptions[i].strptr)), sizeof(char *));
+            config_check_valptr(&(cfgoptions[i]), cfgoptions[i].strptr, strlen(str)+1);
+            sprintf( *(cfgoptions[i].strptr) , "%s", str);
+            printf_params("[LIBCONFIG] %s: \"%s\"\n", cfgpath,*(cfgoptions[i].strptr) );
+          } else {
+            sprintf( (char *)(cfgoptions[i].strptr) , "%s", str);
+            printf_params("[LIBCONFIG] %s: \"%s\"\n", cfgpath,(char *)cfgoptions[i].strptr );
+          }
+        } else {
+          defval=config_setdefault_string(&(cfgoptions[i]),prefix);
+        }
+
         break;
-       	case TYPE_UINT64:
-       	case TYPE_INT64:
-           if ( config_lookup_int64(&(libconfig_privdata.cfg),cfgpath, &llu)) {
-              config_check_valptr(&(cfgoptions[i]), (char **)&(cfgoptions[i].i64ptr),sizeof(long long));
-              if(cfgoptions[i].type==TYPE_UINT64) {
-                 *(cfgoptions[i].u64ptr) = (uint64_t)llu;
-                 printf_params("[LIBCONFIG] %s: %llu\n", cfgpath,(long long unsigned)(*(cfgoptions[i].u64ptr)) );
-              } else {
-                 *(cfgoptions[i].iptr) = llu;
-                 printf_params("[LIBCONFIG] %s: %lli\n", cfgpath,(long long unsigned)(*(cfgoptions[i].i64ptr)) ); 
-              }
-           } else {
-              defval=config_setdefault_int64(&(cfgoptions[i]),prefix);
-	   }	      
-        break;        
-       	case TYPE_UINTARRAY:
-       	case TYPE_INTARRAY:
-	   setting = config_setting_lookup (config_root_setting(&(libconfig_privdata.cfg)),cfgpath );
-           if ( setting != NULL) {
-              read_intarray(&cfgoptions[i],setting,cfgpath);
-           } else {
-              defval=config_setdefault_intlist(&(cfgoptions[i]),prefix);
-	   }    
+
+      case TYPE_STRINGLIST:
+        setting = config_setting_lookup (config_root_setting(&(libconfig_privdata.cfg)),cfgpath );
+
+        if ( setting != NULL) {
+          read_strlist(&cfgoptions[i],setting,cfgpath);
+        } else {
+          defval=config_setdefault_stringlist(&(cfgoptions[i]),prefix);
+        }
+
         break;
-       	case TYPE_DOUBLE:
-           if ( config_lookup_float(&(libconfig_privdata.cfg),cfgpath, &dbl)) {
-                 config_check_valptr(&(cfgoptions[i]), (char **)&(cfgoptions[i].dblptr),sizeof(double));
-                 *(cfgoptions[i].dblptr) = dbl;
-                 printf_params("[LIBCONFIG] %s: %lf\n", cfgpath,*(cfgoptions[i].dblptr) );
-           } else {
-              defval=config_setdefault_double(&(cfgoptions[i]),prefix);
-	   }	      
-        break;  
-       	case TYPE_IPV4ADDR:
-           if ( !config_lookup_string(&(libconfig_privdata.cfg),cfgpath, (const char **)&str)) {
-              defval=config_setdefault_ipv4addr(&(cfgoptions[i]),prefix);
-	   } else {
-              rst=config_assign_ipv4addr(cfgoptions, str);
-	      if (rst < 0) {
-		 fprintf(stderr,"[LIBCONFIG] %s not valid for %s \n", str, cfgpath);
-                 fatalerror=1;
-              }
-           }  
+
+      case TYPE_UINT8:
+      case TYPE_INT8:
+      case TYPE_UINT16:
+      case TYPE_INT16:
+      case TYPE_UINT32:
+      case TYPE_INT32:
+      case TYPE_MASK:
+        if ( config_lookup_int(&(libconfig_privdata.cfg),cfgpath, &u)) {
+          config_check_valptr(&(cfgoptions[i]), (char **)(&(cfgoptions[i].iptr)),sizeof(int32_t));
+          config_assign_int(&(cfgoptions[i]),cfgpath,u);
+        } else {
+          defval=config_setdefault_int(&(cfgoptions[i]),prefix);
+        }
+
         break;
-       	case TYPE_LIST:
-	   setting = config_setting_lookup (config_root_setting(&(libconfig_privdata.cfg)),cfgpath );
-           if ( setting) {
-              cfgoptions[i].numelt=config_setting_length(setting);
-           } else {
-              notfound=1;
-	   }
-       break;
-       default:
-            fprintf(stderr,"[LIBCONFIG] %s type %i  not supported\n", cfgpath,cfgoptions[i].type);
-            fatalerror=1;
-       break;
-       } /* switch on param type */
-    if( notfound == 1) {
-        printf("[LIBCONFIG] %s not found in %s ", cfgpath,libconfig_privdata.configfile );
-        if ( (cfgoptions[i].paramflags & PARAMFLAG_MANDATORY) != 0) {
+
+      case TYPE_UINT64:
+      case TYPE_INT64:
+        if ( config_lookup_int64(&(libconfig_privdata.cfg),cfgpath, &llu)) {
+          config_check_valptr(&(cfgoptions[i]), (char **)&(cfgoptions[i].i64ptr),sizeof(long long));
+
+          if(cfgoptions[i].type==TYPE_UINT64) {
+            *(cfgoptions[i].u64ptr) = (uint64_t)llu;
+            printf_params("[LIBCONFIG] %s: %llu\n", cfgpath,(long long unsigned)(*(cfgoptions[i].u64ptr)) );
+          } else {
+            *(cfgoptions[i].iptr) = llu;
+            printf_params("[LIBCONFIG] %s: %llu\n", cfgpath,(long long unsigned)(*(cfgoptions[i].i64ptr)) );
+          }
+        } else {
+          defval=config_setdefault_int64(&(cfgoptions[i]),prefix);
+        }
+
+        break;
+
+      case TYPE_UINTARRAY:
+      case TYPE_INTARRAY:
+        setting = config_setting_lookup (config_root_setting(&(libconfig_privdata.cfg)),cfgpath );
+
+        if ( setting != NULL) {
+          read_intarray(&cfgoptions[i],setting,cfgpath);
+        } else {
+          defval=config_setdefault_intlist(&(cfgoptions[i]),prefix);
+        }
+
+        break;
+
+      case TYPE_DOUBLE:
+        if ( config_lookup_float(&(libconfig_privdata.cfg),cfgpath, &dbl)) {
+          config_check_valptr(&(cfgoptions[i]), (char **)&(cfgoptions[i].dblptr),sizeof(double));
+          *(cfgoptions[i].dblptr) = dbl;
+          printf_params("[LIBCONFIG] %s: %lf\n", cfgpath,*(cfgoptions[i].dblptr) );
+        } else {
+          defval=config_setdefault_double(&(cfgoptions[i]),prefix);
+        }
+
+        break;
+
+      case TYPE_IPV4ADDR:
+        if ( !config_lookup_string(&(libconfig_privdata.cfg),cfgpath, (const char **)&str)) {
+          defval=config_setdefault_ipv4addr(&(cfgoptions[i]),prefix);
+        } else {
+          rst=config_assign_ipv4addr(cfgoptions, str);
+
+          if (rst < 0) {
+            fprintf(stderr,"[LIBCONFIG] %s not valid for %s \n", str, cfgpath);
             fatalerror=1;
-            printf("  mandatory parameter missing\n");
+          }
+        }
+
+        break;
+
+      case TYPE_LIST:
+        setting = config_setting_lookup (config_root_setting(&(libconfig_privdata.cfg)),cfgpath );
+
+        if ( setting) {
+          cfgoptions[i].numelt=config_setting_length(setting);
         } else {
-           printf("\n");
+          notfound=1;
         }
+
+        break;
+
+      default:
+        fprintf(stderr,"[LIBCONFIG] %s type %i  not supported\n", cfgpath,cfgoptions[i].type);
+        fatalerror=1;
+        break;
+    } /* switch on param type */
+
+    if( notfound == 1) {
+      printf("[LIBCONFIG] %s not found in %s ", cfgpath,libconfig_privdata.configfile );
+
+      if ( (cfgoptions[i].paramflags & PARAMFLAG_MANDATORY) != 0) {
+        fatalerror=1;
+        printf("  mandatory parameter missing\n");
+      } else {
+        printf("\n");
+      }
     } else {
       if (defval == 1) {
-          numdefvals++;
-	  cfgoptions[i].paramflags = cfgoptions[i].paramflags |  PARAMFLAG_PARAMSETDEF;
+        numdefvals++;
+        cfgoptions[i].paramflags = cfgoptions[i].paramflags |  PARAMFLAG_PARAMSETDEF;
       } else {
-          cfgoptions[i].paramflags = cfgoptions[i].paramflags |  PARAMFLAG_PARAMSET;
+        cfgoptions[i].paramflags = cfgoptions[i].paramflags |  PARAMFLAG_PARAMSET;
       }
+
       status++;
     }
   } /* for loop on options */
+
   printf("[LIBCONFIG] %s: %i/%i parameters successfully set, (%i to default value)\n",
-         ((prefix == NULL)?"(root)":prefix), 
+         ((prefix == NULL)?"(root)":prefix),
          status,numoptions,numdefvals );
+
   if (fatalerror == 1) {
-      fprintf(stderr,"[LIBCONFIG] fatal errors found when processing  %s \n", libconfig_privdata.configfile );
-      config_libconfig_end();
-      end_configmodule();
+    fprintf(stderr,"[LIBCONFIG] fatal errors found when processing  %s \n", libconfig_privdata.configfile );
+    config_libconfig_end();
+    end_configmodule();
   }
+
   return status;
 }
 
-int config_libconfig_getlist(paramlist_def_t *ParamList, 
-                                   paramdef_t *params, int numparams, char *prefix)
-{
-config_setting_t *setting;
-int i,j,status;
-char *listpath=NULL;
-char cfgpath[MAX_OPTNAME_SIZE*2 + 6]; /* prefix.listname.[listindex] */
-
-    if (prefix != NULL)
-        {
-        i=asprintf(&listpath ,"%s.%s",prefix,ParamList->listname);
-        }
-    else
-        {
-        i=asprintf(&listpath ,"%s",ParamList->listname);
-        }
-    setting = config_lookup(&(libconfig_privdata.cfg), listpath);
-    if ( setting) {
-        status = ParamList->numelt = config_setting_length(setting);
-        printf_params("[LIBCONFIG] %i %s in config file %s \n", 
-               ParamList->numelt,listpath,libconfig_privdata.configfile );
+int config_libconfig_getlist(paramlist_def_t *ParamList,
+                             paramdef_t *params, int numparams, char *prefix) {
+  config_setting_t *setting;
+  int i,j,status;
+  char *listpath=NULL;
+  char cfgpath[MAX_OPTNAME_SIZE*2 + 6]; /* prefix.listname.[listindex] */
+
+  if (prefix != NULL) {
+    i=asprintf(&listpath ,"%s.%s",prefix,ParamList->listname);
+  } else {
+    i=asprintf(&listpath ,"%s",ParamList->listname);
+  }
+
+  setting = config_lookup(&(libconfig_privdata.cfg), listpath);
+
+  if ( setting) {
+    status = ParamList->numelt = config_setting_length(setting);
+    printf_params("[LIBCONFIG] %i %s in config file %s \n",
+                  ParamList->numelt,listpath,libconfig_privdata.configfile );
+  } else {
+    printf("[LIBCONFIG] list %s not found in config file %s \n",
+           listpath,libconfig_privdata.configfile );
+    ParamList->numelt= 0;
+    status = -1;
+  }
+
+  if (ParamList->numelt > 0 && params != NULL) {
+    ParamList->paramarray = malloc(ParamList->numelt * sizeof(paramdef_t *));
+
+    if ( ParamList->paramarray != NULL) {
+      config_get_if()->ptrs[config_get_if()->numptrs] = (char *)(ParamList->paramarray);
+      config_get_if()->numptrs++;
     } else {
-        printf("[LIBCONFIG] list %s not found in config file %s \n", 
-               listpath,libconfig_privdata.configfile );
-        ParamList->numelt= 0;
-        status = -1;
+      fprintf (stderr,"[LIBCONFIG] %s %d malloc error\n",__FILE__, __LINE__);
+      exit(-1);
     }
-    if (ParamList->numelt > 0 && params != NULL) {
-        ParamList->paramarray = malloc(ParamList->numelt * sizeof(paramdef_t *));
-        if ( ParamList->paramarray != NULL) {
-             config_get_if()->ptrs[config_get_if()->numptrs] = (char *)(ParamList->paramarray); 
-             config_get_if()->numptrs++;
-        } else {
-             fprintf (stderr,"[LIBCONFIG] %s %d malloc error\n",__FILE__, __LINE__);
-             exit(-1);
-        }
-        for (i=0 ; i < ParamList->numelt ; i++) {
-            ParamList->paramarray[i] = malloc(numparams * sizeof(paramdef_t));
-            if ( ParamList->paramarray[i] != NULL) {
-                 config_get_if()->ptrs[config_get_if()->numptrs] = (char *)(ParamList->paramarray[i]); 
-                 config_get_if()->numptrs++;
-            } else {
-                 fprintf (stderr,"[LIBCONFIG] %s %d malloc error\n",__FILE__, __LINE__);
-                 exit(-1);
-            }
-            
-            memcpy(ParamList->paramarray[i], params, sizeof(paramdef_t)*numparams);
-            for (j=0;j<numparams;j++) {
-                ParamList->paramarray[i][j].strptr = NULL ;
-                } 
-            sprintf(cfgpath,"%s.[%i]",listpath,i);
-            config_libconfig_get(ParamList->paramarray[i], numparams, cfgpath );
-        } /* for i... */
-    } /* ParamList->numelt > 0 && params != NULL */
-    if (listpath != NULL)
-        free(listpath);
-    return status;
+
+    for (i=0 ; i < ParamList->numelt ; i++) {
+      ParamList->paramarray[i] = malloc(numparams * sizeof(paramdef_t));
+
+      if ( ParamList->paramarray[i] != NULL) {
+        config_get_if()->ptrs[config_get_if()->numptrs] = (char *)(ParamList->paramarray[i]);
+        config_get_if()->numptrs++;
+      } else {
+        fprintf (stderr,"[LIBCONFIG] %s %d malloc error\n",__FILE__, __LINE__);
+        exit(-1);
+      }
+
+      memcpy(ParamList->paramarray[i], params, sizeof(paramdef_t)*numparams);
+
+      for (j=0; j<numparams; j++) {
+        ParamList->paramarray[i][j].strptr = NULL ;
+      }
+
+      sprintf(cfgpath,"%s.[%i]",listpath,i);
+      config_libconfig_get(ParamList->paramarray[i], numparams, cfgpath );
+    } /* for i... */
+  } /* ParamList->numelt > 0 && params != NULL */
+
+  if (listpath != NULL)
+    free(listpath);
+
+  return status;
 }
 
-int config_libconfig_init(char *cfgP[], int numP)
-{
+int config_libconfig_init(char *cfgP[], int numP) {
   config_init(&(libconfig_privdata.cfg));
   libconfig_privdata.configfile = strdup((char *)cfgP[0]);
   config_get_if()->numptrs=0;
@@ -317,24 +350,22 @@ int config_libconfig_init(char *cfgP[], int numP)
   /* Read the file. If there is an error, report it and exit. */
   if(! config_read_file(&(libconfig_privdata.cfg), libconfig_privdata.configfile)) {
     fprintf(stderr,"[LIBCONFIG] %s %d file %s - %d - %s\n",__FILE__, __LINE__,
-                   libconfig_privdata.configfile, config_error_line(&(libconfig_privdata.cfg)),
-                   config_error_text(&(libconfig_privdata.cfg)));
+            libconfig_privdata.configfile, config_error_line(&(libconfig_privdata.cfg)),
+            config_error_text(&(libconfig_privdata.cfg)));
     config_destroy(&(libconfig_privdata.cfg));
     printf( "\n");
     return -1;
   }
-  
 
   return 0;
 }
 
 
-void config_libconfig_end(void )
-{
+void config_libconfig_end(void ) {
   config_destroy(&(libconfig_privdata.cfg));
+
   if ( libconfig_privdata.configfile != NULL ) {
-     free(libconfig_privdata.configfile);
-     libconfig_privdata.configfile=NULL;
-  } 
-  
+    free(libconfig_privdata.configfile);
+    libconfig_privdata.configfile=NULL;
+  }
 }
diff --git a/common/utils/DOC/loader.md b/common/utils/DOC/loader.md
new file mode 100644
index 0000000000000000000000000000000000000000..91ff0c02f0c3f9e4457f7b16a36169d2745109fc
--- /dev/null
+++ b/common/utils/DOC/loader.md
@@ -0,0 +1,17 @@
+# OAI shared library loader
+
+Shared libraries usage is modularization mechanism which provides the following advantages:
+1. Prevents including in the main executable code which is not used in a given configuration
+1. Provides flexibility, several implementation of a given functionality can be chosen at run-time, without any compilation step. For example you can build several devices (USRP, BladeFR, LimeSDR)  and choose which one you want to use on the command line or via the configuration.
+1.  Makes code evolution easier: as soon as the shared library interface is clearly defined, you can work on the functionality implemented in a shared library while regularly updating the other components of the code. You can decide to develop your own version of a functionality, decide to deliver it or not,  letting the user decide wwhat version he wants to use.
+
+The main drawback is a performance cost at init time, when loading libraries.
+
+
+## Documentation
+
+* [runtime usage](loader/rtusage.md)
+* [developer usage](loader/devusage.md)
+* [module architecture](loader/arch.md)
+
+[oai Wikis home](https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/home)
\ No newline at end of file
diff --git a/common/utils/DOC/loader/arch.md b/common/utils/DOC/loader/arch.md
new file mode 100644
index 0000000000000000000000000000000000000000..52ffd428ddba5fa31f9a3ddcdb784a174f606039
--- /dev/null
+++ b/common/utils/DOC/loader/arch.md
@@ -0,0 +1,7 @@
+# loader source files
+
+The oai shared library loader is implemented in two source files, located in [common/utils](https://gitlab.eurecom.fr/oai/openairinterface5g/tree/develop/common/utils)
+1. [load_module_shlib.c](https://gitlab.eurecom.fr/oai/openairinterface5g/tree/develop/common/utils/load_module_shlib.c) contains the loader implementation
+1.  [load_module_shlib.h](https://gitlab.eurecom.fr/oai/openairinterface5g/tree/develop/common/utils/load_module_shlib.h) is the loader include file containing both private and public data type definitions. It also contain API prototypes.
+
+[loader home page](../loader.md)
diff --git a/common/utils/DOC/loader/devusage.md b/common/utils/DOC/loader/devusage.md
new file mode 100644
index 0000000000000000000000000000000000000000..bd45c88a85223ce1123877f339c4bfbf19663e94
--- /dev/null
+++ b/common/utils/DOC/loader/devusage.md
@@ -0,0 +1,16 @@
+The loader objectives are
+1. provides a common mechanism to prevent an executable to include code that is only used under specific configurations, without rebuilding the code
+1. Provide a common mechanism to allow to choose between different implementations of a given set of functions, without rebuilding the code
+
+As a developer you may need to look at these sections:
+
+* [loading a shared library](devusage/loading.md)
+* [loader API](devusage/api.md)
+* [loader public structures](devusage/struct.md)
+
+Loader usage examples can be found in oai sources:
+
+*  device and transport initialization code: [function `load_lib` in *targets/ARCH/COMMON/__common_lib.c__* ](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/targets/ARCH/COMMON/common_lib.c#L91)
+*  turbo encoder and decoder initialization: [function `load_codinglib`in *openair1/PHY/CODING/__coding_load.c__*](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair1/PHY/CODING/coding_load.c#L113)
+
+[loader home page](../loader.md)
diff --git a/common/utils/DOC/loader/devusage/api.md b/common/utils/DOC/loader/devusage/api.md
new file mode 100644
index 0000000000000000000000000000000000000000..a6e59c593800ab34b93e98453660c1db73f00034
--- /dev/null
+++ b/common/utils/DOC/loader/devusage/api.md
@@ -0,0 +1,20 @@
+ Loader API is defined in the [common/utils/load_module_shlib.h](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/load_module_shlib.h) include file.
+```c
+int load_module_shlib(char *modname,loader_shlibfunc_t *farray, int numf)
+```
+* possibly initializes the loader, if it has not been already initialized
+* Formats the full shared library path, using the `modname` argument and the loader `shlibpath` and `shlibversion`configuration parameters.
+* loads the shared library, using the dlopen system call
+* looks for `< modname >_autoinit` symbol, using the `dlsym` system call and possibly call the corresponding function.
+* looks for `< modname >_checkbuildver` symbol, using the `dlsym` system call and possibly calls the corresponding function. If the return value of this call is `-1`, program execution is stopped. It is the responsibility of the shared library developer to implement or not a `< modname >_checkbuildver` function and to decide if a version mismatch is a fatal condition. The `< modname >_checkbuildver` function must match the `checkverfunc_t` function type. The first argument is the main executable version, as set  in the `PACKAGE_VERSION` macro defined in the [oai CMakeLists](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/cmake_targets/CMakeLists.txt#L218), around line 218. The second argument points to the shared library version which should be set  by the `< modname >_checkbuildver` function.
+* If the farray pointer is null,  looks for `< modname >_getfarray` symbol, calls the corresponding function when the symbol is found. `< modname >_getfarray` takes one argument, a pointer to a  `loader_shlibfunc_t` array, and returns the number of items in this array, as defined by the `getfarrayfunc_t` type. The `loader_shlibfunc_t` array returned by the shared library must be fully filled (both `fname` and `fptr` fields).
+* looks for the `numf` function symbols listed in the `farray[i].fname` arguments and set the corresponding `farray[i].fptr`function pointers
+
+
+```c
+void * get_shlibmodule_fptr(char *modname, char *fname)
+```
+Returns a pointer to the symbol `fname`, defined in module `modname`, or `NULL` if the symbol is not found.
+
+[loader home page](../../loader.md)
+[loader developer home page](../devusage.md)
diff --git a/common/utils/DOC/loader/devusage/loading.md b/common/utils/DOC/loader/devusage/loading.md
new file mode 100644
index 0000000000000000000000000000000000000000..b34782ecd3dabbd7fc5f6f9d9c22dcd6197f1bb8
--- /dev/null
+++ b/common/utils/DOC/loader/devusage/loading.md
@@ -0,0 +1,56 @@
+Implementing a shared library dynamic load using the oai loader  is a two steps task:
+1.  define the `loader_shlibfunc_t` array, describing the list of externally available functions implemented in the library. This is the interface of the module.
+1.  Call the `load_module_shlib` function, passing it the previously defined array and the number of items in this array. The first argument to `load_module_shlib` is the name identifying the module, which is also used to format the corresponding library name, as described [here](loader/rtusage#shared-library-names)
+
+After a successful `load__module_shlib` call, the function pointer of each `loader_shlibfunc_t` array item has been set and can be used to call the corresponding function.
+
+Typical loader usage looks like:
+
+```c
+/* shared library loader include file */
+#include "common/utils/load_module_shlib.h"
+.............
+/*
+  define and initialize the array, describing the list of functions
+  implemented in "mymodule"
+*/
+  loader_shlibfunc_t mymodule_fdesc[2];
+  mymodule_fdesc[0].fname="mymodule_f1";
+  mymodule_fdesc[1].fname="mymodule_f2";
+
+/*
+ load the library, it's name must be libmymod.so. Configuration can be
+ used to specify a specific path to look for libmymod.so. Configuration
+ can also specify a version, for example "V1", in this case the loader
+ will look for libmymodV1.so
+*/
+  ret=load_module_shlib("mymod",mymodule_fdesc, sizeof(mymodule_fdesc)/sizeof(loader_shlibfunc_t));
+  if (ret < 0) {
+       fprintf(stderr,"Library couldn't be loaded\n");
+  } else {
+/*
+library has been loaded, we probably want to call some functions...
+*/
+  ret=((funcf1_t)mymodule_fdesc[0].fptr)();
+
+..................
+/*
+later and/or somewhere else in the code you may want to call function "mymodule_f2"
+You can use the loader get_shlibmodule_fptr(char *modname, char *fname) function
+to retrieve the pointer to that function
+*/
+funcf2_t *f2;
+int ret;
+int intarg1;
+char *strarg;
+........................
+f2 = (funcf2_t)get_shlibmodule_fptr("mymodule", "mymodule_f2")
+if (f2 != NULL) {
+  ret = f2(intarg1,strarg);
+}
+...............
+```
+When loading a shared library the loader looks for a symbol named `< module name > _autoinit` and, if it finds it, calls it. The `autoinit` function is called without any argument and the returned value, if any, is not tested.
+
+[loader home page](../loader.md)
+[loader developer home page](../../loader/devusage.md)
diff --git a/common/utils/DOC/loader/devusage/struct.md b/common/utils/DOC/loader/devusage/struct.md
new file mode 100644
index 0000000000000000000000000000000000000000..08d4ce955893d23d6b5ef6594e81d8c2bc16ad1e
--- /dev/null
+++ b/common/utils/DOC/loader/devusage/struct.md
@@ -0,0 +1,10 @@
+# `loader_shlibfunc_t`structure
+It is defined in include file [ common/util/load_module_shlib.h ](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/load_module_shlib.h#L38). This structure is used  to list the symbols that should be searched by the loader when calling the `load_module_shlib` function.
+
+| Fields     | Description                                                       | I/O |
+|:-----------|:------------------------------------------------------------------|----:|
+| `fname`    | symbol name, is passed to the [`dlsym`](http://man7.org/linux/man-pages/man3/dlsym.3.html) system call performed by the loader to get a pointer to the symbol | I |
+| `fptr`     | pointer to the symbol name, set by the loader. `fptr` is defined as a `int (*fptr)(void)` function type | O |
+
+[loader home page](../../loader.md)
+[loader developer home page](../devusage.md)
diff --git a/common/utils/DOC/loader/rtusage.md b/common/utils/DOC/loader/rtusage.md
new file mode 100644
index 0000000000000000000000000000000000000000..0bcdf6429f7a830bd7f64f7be021578408cf87a4
--- /dev/null
+++ b/common/utils/DOC/loader/rtusage.md
@@ -0,0 +1,50 @@
+## shared library names
+Shared library full names are built by the loader using the format:
+>  < *path* >/lib< *module name* >< *module version* >.so
+
+1.  the < *module name* > is defined at development time, it comes from the `modname`  argument of the `load_module_shlib` call.
+1.  the < *module version* > and < *path* > optional  parameters, are defined at run-time, depending on the configuration.
+
+## loader parameters
+The loader is using the [configuration module](../../../config/DOC/config.md), and defines global and per library parameters. Global parameters must be specified under the **loader** section and library specific parameters under a **loader.<*module name*>** section. Module specific parameters override the global parameters.
+### Global loader parameters
+| name | type | default | description |
+|:---:|:---:|:---:|:----|
+| `shlibpath` | `string of char` | `""` | directory path used to look for shared libraries, may be superseded by the library specific `shlibpath`.|
+| `maxshlibs` | `integer` | 10 | Maximum number of shared libraries the loader can  manage. |
+
+### library specific loader parameters
+| name | type | default | description |
+|:---:|:---:|:---:|:----|
+| `shlibpath` | `string of char` | `""` | directory path used to look for this shared library.|
+| `shlibversion` | `string of char` | `""` | version to be used to load this shared library.|
+
+### loader configuration examples
+
+The following configuration file example just reproduce the default loader parameters:
+```c
+loader :
+{
+   shlibpath = "./";
+   maxshlibs = 10;
+   liboai_device :
+      {
+      shlibpath = "./";
+      shlibversion = "";
+      }
+};
+```
+If you want to load a device called *liboai_device_USRP.so* without writting a specific configuration, you can start the softmodem using the following command:
+> ./lte-softmodem -O libconfig:/usr/local/oai/openairinterface5g/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.nbiot.band7.tm1.50PRB.usrpb210.conf:dbgl5  --loader.oai_device.shlibversion _USRP
+
+With this latest example, nn the softmodem logs, you can check that the right device library has been loaded:
+```bash
+[LIBCONFIG] loader.oai_device.shlibpath not found in /usr/local/oai/develop-nb-iot-merge/openairinterface5g/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.nbiot.band7.tm1.50PRB.usrpb210.conf
+[LIBCONFIG] loader.oai_device.shlibversion set to default value ""
+[LIBCONFIG] loader.oai_device: 1/2 parameters successfully set, (1 to default value)
+[CONFIG] shlibversion set to  _USRP from command line
+[CONFIG] loader.oai_device 1 options set from command line
+
+```
+
+[loader home page](../loader.md)
diff --git a/common/utils/LOG/DOC/addconsoletrace.md b/common/utils/LOG/DOC/addconsoletrace.md
new file mode 100644
index 0000000000000000000000000000000000000000..9ab90cf12009e8de2bc2a5885f34dd67c4708295
--- /dev/null
+++ b/common/utils/LOG/DOC/addconsoletrace.md
@@ -0,0 +1,110 @@
+### Adding console traces in oai code
+#### console messages macros
+```C
+LOG_E(<component>,<format>,<argument>,...)
+LOG_W(<component>,<format>,<argument>,...)
+LOG_I(<component>,<format>,<argument>,...)
+LOG_D(<component>,<format>,<argument>,...)
+LOG_T(<component>,<format>,<argument>,...)
+)
+```
+these macros are used in place of the printf C function. The additionnal ***component*** parameter identifies the functionnal module which generates the message. At run time, the message will only be printed if the configured log level for the component is greater or equal than the macro level used in the code.
+
+| macro | level letter | level value | level name |
+|:---------|:---------------|:---------------|----------------:|
+| LOG_E |  E | 0 | error |
+| LOG_W | W | 1 | warning |
+| LOG_I | I | 2 | informational |
+| LOG_D | D | 3 | debug |
+| LOG_T | T | 4 | trace |
+
+component list is defined as an `enum` in  [log.h](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/LOG/log.h). A new component can be defined by adding an item in this type, it must also be defined in the T tracer [T_messages.txt ](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/T/T_messages.txt).
+
+Most oai sources are including LOG macros.
+
+#### conditional code macros
+
+```C
+LOG_DEBUGFLAG(<flag>)
+```
+this macro is to be used in if statements. The condition is true if the flag has been set, as described in the [run time usage page](rtusage.md)
+```C
+if ( LOG_DEBUGFLAG(<flag>) {
+/*
+   the code below is only executed if the corresponding
+   <flag>_debug option is set.
+ */
+......................
+......................
+}
+```
+[example in oai code](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair1/PHY/LTE_TRANSPORT/ulsch_demodulation.c#L396)
+
+#### memory dump macros
+```C
+LOG_DUMPFLAG(<flag>)
+```
+this macro is to be used in if statements. The condition is true if the flag has been set, as described in the [run time usage page](rtusage.md). It is mainly provided to surround LOG_M macros or direct calls to `log_dump`which otherwise would be unconditionals.
+```C
+if ( LOG_DUMPFLAG(<flag>) {
+/*
+   the code below is only executed if the corresponding
+   <flag>_dump option is set.
+ */
+LOG_M(.............
+LOG_M(.............
+log_dump(...
+}
+
+[example in oai code](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair1/PHY/LTE_TRANSPORT/prach.c#L205)
+#### matlab format dump
+```C
+LOG_M(file, vector, data, len, dec, format)
+```
+|argument| type| description |
+|:-----------|:-------|-----------------:|
+| file       | char* |path to the fle which will contain the dump |
+|vector  |char * |name of the dump, printed at the top of the dump file |
+|data| void *| pointer to the memory to be dumpped |
+|len |  int | length of the data to be dumpped, in `dec` unit|
+| dec| int | length of each data item.Interpretation depends on format|
+|format| int | defines the type of data to be dumped|
+
+This macro can be used to dump a buffer in a format that can be used for analyze via tools like matlab or octave. **It must be surrounded by LOG_DEBUGFLAG or LOG_DUMPFLAG macros, to prevent the dump to be built unconditionally.** The LOG_M macro points to the `write_file_matlab` function implemented in  [log.c](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/LOG/log.c). **This function should be revisited for more understandable implementation and ease of use (format parameter ???)**
+[example in oai code](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair1/PHY/LTE_TRANSPORT/prach.c#L205)
+
+#### hexadecimal format dump
+```C
+LOG_DUMPMSG(c, f, b, s, x...)
+```
+dumps a memory region if the corresponding debug flag `f` is set as explained here [run time usage page](rtusage.md)
+
+|argument| type| description |
+|:-----------|:-------|-----------------:|
+| c       | int, component id (in `comp_name_t` enum)| used to print the message, as specified by the s and x arguments |
+|f  |int  |flag used to filter the dump depending on the logs configuration. flag list is defined by the LOG_MASKMAP_INIT macro in  [log.h](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/LOG/log.h) |
+|b| void *| pointer to the memory to be dumpped |
+|s |  int | length of the data to be dumpped in char|
+| x...| printf format and arguments| text string to be printed at the top of the dump|
+
+This macro can be used to conditionaly dump a buffer, bytes by bytes, giving the integer value of each byte in hexadecimal form.
+[example in oai code](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair2/RRC/LTE/rrc_eNB.c#L1181)
+
+This macro points to the `log_dump` function, implemented in  [log.c](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/LOG/log.c). This function can also dump buffers containing `double` data via the LOG_UDUMPMSG macro
+
+```C
+LOG_UDUMPMSG(c, b, s, f, x...)
+```
+|argument| type| description |
+|:-----------|:-------|-----------------:|
+| c       | int, component id (in `comp_name_t` enum)| used to print the message, as specified by the s and x arguments |
+|b| void *| pointer to the memory to be dumpped |
+|s |  int | length of the data to be dumpped in char|
+|f|  int | format of dumped data LOG_DUMP_CHAR or  LOG_DUMP_DOUBLE|
+| x...| printf format and arguments| text string to be printed at the top of the dump|
+
+[example in oai code](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair1/SIMULATION/LTE_PHY/dlsim.c#L1974)
+
+[logging facility developer main page](devusage.md)
+[logging facility  main page](log.md)
+[oai Wikis home](https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/home)
diff --git a/common/utils/LOG/DOC/arch.md b/common/utils/LOG/DOC/arch.md
new file mode 100644
index 0000000000000000000000000000000000000000..1d6aeae6aa1b963c88a4c0164592e75c5806b978
--- /dev/null
+++ b/common/utils/LOG/DOC/arch.md
@@ -0,0 +1,12 @@
+# logging facility source files
+
+The oai logging facility is implemented in two source files, located in [common/utils/LOG](LOG)
+1. [log.c](../log.c) contains logging implementation
+1.  [log.h](../log.h) is the logging facility include file containing both private and public data type definitions. It also contain API prototypes.
+
+The logging facility doesn't create any thread, all api's are executed in the context of the caller. The tracing macro's `LOG_<X>` are all using the logRecord_mt function to output the messages. To keep this function thread safe it must perform a single system call to the output stream. The buffer used to build the message must be specific to the calling thread, which is today enforced by using a variable in the logRecord_mt stack.
+
+Data used by the logging utility are defined by the `log_t` structure which is allocated at init time, when calling the `logInit` function.
+
+[logging facility  main page](log.md)
+[oai Wikis home](https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/home)
diff --git a/common/utils/LOG/DOC/configurelog.md b/common/utils/LOG/DOC/configurelog.md
new file mode 100644
index 0000000000000000000000000000000000000000..862c02162b1d516d5f74fba0619457bb68f4675a
--- /dev/null
+++ b/common/utils/LOG/DOC/configurelog.md
@@ -0,0 +1,49 @@
+### Initializing and configuring the logging facility
+
+#### logging facility APIs
+```C
+int  logInit (void);
+```
+Allocate the internal data used by the logging utility, set the configuration, using the [configuration  module](../../../config/DOC/config.md)
+
+```C
+void logClean (void)
+```
+Reset console attributes (color settings) and possibly close opened log files. Logging facility is still usable after this call, the internal data are not freed.
+
+```C
+int  set_log(int component, int level)
+void set_glog(int level)
+```
+Set a component or  all components logiing level. Messages which level is lower than this level are not printed to the console.
+
+```C
+void set_glog_onlinelog(int enable)
+```
+Enable or disable all logging messages. Even error level messages are discarded, which is not advised. This can be usefull to temporarily workaround high rate of logging messages.
+
+```C
+void set_component_filelog(int comp)
+void close_component_filelog(int comp)
+```
+
+Redirect or reset to stdout the output stream used by the logging facility. When the output stream is redirected to a file, it is created under /tmp with a hard-coded filename including the componemt name.
+
+```C
+SET_LOG_DEBUG(flag)
+CLEAR_LOG_DEBUG(flag)
+SET_LOG_DUMP(flag)
+CLEAR_LOG_DUMP(flag)
+```
+ These macros are used to set or clear the corresponding bit flag, trigerring the activation or un-activation of conditional code or memory dumps generation.
+
+Example of using the logging utility APIs can be found, for initialization and cleanup,  in [lte-softmodem.c](../../../../targets/RT/USER/lte-softmodem.c) and in the [telnet server log command implementation](../../telnetsrv/telnetsrv_proccmd.c) for a complete access to the logging facility features.
+
+#### components and debug flags definitions
+
+Adding a new component is just adding an item in the `comp_name_t` enum defined in [log.h](../log.h) . You must also declare it in the T Tracer facility [message fefinitions](../../T/T_messages.txt).
+To add a flag than can then be used for adding conditional code or memory dumps you have to add the flag definition in the `LOG_MASKMAP_INIT` macro, in [log.h](../log.h).
+
+[logging facility developer main page](devusage.md)
+[logging facility  main page](log.md)
+[oai Wikis home](https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/home)
diff --git a/common/utils/LOG/DOC/devusage.md b/common/utils/LOG/DOC/devusage.md
new file mode 100644
index 0000000000000000000000000000000000000000..61d25734e0a82733bd51116374f5453f1da4ccb4
--- /dev/null
+++ b/common/utils/LOG/DOC/devusage.md
@@ -0,0 +1,14 @@
+### logging facility developer usage
+The logging facility objectives are
+1. provide a common console tracing mechanism
+1. Allow a flexible activation of console traces, by configuration or dynamically at any time while code is running.
+
+Most developpers will only use the log macros to add console messages to the code. The logging facility also provides an api that is used for initialization and configuration.
+
+[Adding console traces in oaicode](addconsoletrace.md)
+
+[Configuring the logging facility](configurelog.md)
+
+
+[logging facility  main page](log.md)
+[oai Wikis home](https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/home)
diff --git a/common/utils/LOG/DOC/log.md b/common/utils/LOG/DOC/log.md
new file mode 100644
index 0000000000000000000000000000000000000000..4b3e5981e1da3b4205bdc7f126fd92773d65730f
--- /dev/null
+++ b/common/utils/LOG/DOC/log.md
@@ -0,0 +1,19 @@
+# OAI console logging facility
+
+oai includes a console logging facility that any component should use when writting informational or debugging messages to the softmodem or uesoftmodem stdout stream.
+By default, this facility is included at build-time and activated at run-time. The T Tracer and the Logging facility share common options for activation:
+
+-   To disable the logging facility (and T Tracer) at build-time use the *--disable-T-Tracer* switch:
+
+```bash
+/build_oai --disable-T-Tracer
+```
+-  To use the the T-Tracer instead of the console logging facility, use the command line option *T_stdout*.  *T_stdout* is a boolean option, which, when set to 0 (false) disable the console logging facility. All stdout messages are then sent to the T-Tracer.
+
+## Documentation
+
+* [runtime usage](rtusage.md)
+* [developer usage](devusage.md)
+* [module architecture](arch.md)
+
+[oai Wikis home](https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/home)
diff --git a/common/utils/LOG/DOC/rtusage.md b/common/utils/LOG/DOC/rtusage.md
new file mode 100644
index 0000000000000000000000000000000000000000..445f335725c57fcc3675b9df0a608b8e2f3cab90
--- /dev/null
+++ b/common/utils/LOG/DOC/rtusage.md
@@ -0,0 +1,265 @@
+## configuring the logging facility
+The logging facility is fully configurable and it uses the [config module](../../../config/config.md) to get its parameters at init time. The [telnet server](../../telnetsrv/DOC/telnetsrv.md) includes a set of commands which can be used to dynamically modify the logging facility behavior
+
+All logging facility parameters are defined in the log_config section. Some parameters are global to the logging facility, they modify the way messages are printed to stdout. Conversely, some parameters are specific to a component and  only modify the behavior for messages issued by a given component. A third type of parameters can be used to activate conditional debug code or dump messages or buffers.
+
+### global parameters
+
+| name | type | default | description |
+|:---:|:---:|:---:|:----|
+| `global_log_level` | `pre-defined string of char` | `info` |  Allows printing of messages up to the specified  level. Available levels, from lower to higher are `error`,`warn`,`info`,`debug`,`trace` |
+| `global_log_online` | `boolean` | 1 (=true) | If false, all console messages are discarded, whatever their level |
+| `global_log_options` | `list of pre-defined string of char` |  |  3 options can be specified to trigger the information added in the header of the message:  `nocolor`, disable color usage in log messages, usefull when redirecting logs to a file, where escape sequences used for color selection can be annoying, `level`, add a one letter level id in the message header (T,D,I,W,E for trace, debug, info, warning, error),`thread`, add the thread name in the message header|
+
+### Component specific parameters
+| name | type | default | description |
+|:---:|:---:|:---:|:----|
+| `<component>_log_level` | `boolean` | global log level, as defined by the  `global_log_level ` parameter) |
+| `<component>_log_infile` | `boolean` | 0 = false| Triggers the redirection of log messages printed by the specified component in a file. The file path and name is /tmp/<componemt>.[extension] the extension is optional and component dependant, it can be `log `,  `dat `,  `txt `|
+
+The list of components defined within oai can be retrieved from the  [config module](../../../config/config.md) traces, when asking for config module debugging info on the command line:
+
+```bash
+./lte-softmodem -O libconfig:<path to config file>:dbgl5
+
+[LIBCONFIG] log_config.global_log_level: "info"
+[CONFIG] global_log_online: 1
+[CONFIG] log_config.global_log_online set to default value
+[LIBCONFIG] log_config: 3/3 parameters successfully set, (1 to default value)
+[LIBCONFIG] global_log_options[0]: nocolor
+[LIBCONFIG] global_log_options[1]: level
+[LIBCONFIG] global_log_options[2]: thread
+[CONFIG] log_config 1 options set from command line
+[LIBCONFIG] log_config.phy_log_level: "info"
+[LIBCONFIG] log_config.mac_log_level: "info"
+[CONFIG] log_config.sim_log_level set to default value "info"
+[CONFIG] log_config.ocg_log_level set to default value "info"
+[CONFIG] log_config.omg_log_level set to default value "info"
+[CONFIG] log_config.opt_log_level set to default value "info"
+[CONFIG] log_config.otg_log_level set to default value "info"
+[CONFIG] log_config.otg_latency_log_level set to default value "info"
+[CONFIG] log_config.otg_latency_bg_log_level set to default value "info"
+[CONFIG] log_config.otg_gp_log_level set to default value "info"
+[CONFIG] log_config.otg_gp_bg_log_level set to default value "info"
+[CONFIG] log_config.otg_jitter_log_level set to default value "info"
+[LIBCONFIG] log_config.rlc_log_level: "info"
+[LIBCONFIG] log_config.pdcp_log_level: "info"
+[LIBCONFIG] log_config.rrc_log_level: "info"
+[CONFIG] log_config.nas_log_level set to default value "info"
+[CONFIG] log_config.perf_log_level set to default value "info"
+[CONFIG] log_config.oip_log_level set to default value "info"
+[CONFIG] log_config.cli_log_level set to default value "info"
+[CONFIG] log_config.msc_log_level set to default value "info"
+[CONFIG] log_config.ocm_log_level set to default value "info"
+[CONFIG] log_config.udp_log_level set to default value "info"
+[CONFIG] log_config.gtpv1u_log_level set to default value "info"
+[CONFIG] log_config.comp23?_log_level set to default value "info"
+[CONFIG] log_config.s1ap_log_level set to default value "info"
+[CONFIG] log_config.sctp_log_level set to default value "info"
+[LIBCONFIG] log_config.hw_log_level: "info"
+[CONFIG] log_config.osa_log_level set to default value "info"
+[CONFIG] log_config.eral_log_level set to default value "info"
+[CONFIG] log_config.mral_log_level set to default value "info"
+[CONFIG] log_config.enb_app_log_level set to default value "info"
+[CONFIG] log_config.flexran_agent_log_level set to default value "info"
+[CONFIG] log_config.tmr_log_level set to default value "info"
+[CONFIG] log_config.usim_log_level set to default value "info"
+[CONFIG] log_config.localize_log_level set to default value "info"
+[CONFIG] log_config.x2ap_log_level set to default value "info"
+[CONFIG] log_config.loader_log_level set to default value "info"
+[CONFIG] log_config.asn_log_level set to default value "info"
+[LIBCONFIG] log_config: 38/38 parameters successfully set, (32 to default value)
+[CONFIG] log_config 0 options set from command line
+[CONFIG] phy_log_infile: 0
+[CONFIG] log_config.phy_log_infile set to default value
+[CONFIG] mac_log_infile: 0
+[CONFIG] log_config.mac_log_infile set to default value
+[CONFIG] sim_log_infile: 0
+[CONFIG] log_config.sim_log_infile set to default value
+[CONFIG] ocg_log_infile: 0
+[CONFIG] log_config.ocg_log_infile set to default value
+[CONFIG] omg_log_infile: 0
+[CONFIG] log_config.omg_log_infile set to default value
+[CONFIG] opt_log_infile: 0
+[CONFIG] log_config.opt_log_infile set to default value
+[CONFIG] otg_log_infile: 0
+[CONFIG] log_config.otg_log_infile set to default value
+[CONFIG] otg_latency_log_infile: 0
+[CONFIG] log_config.otg_latency_log_infile set to default value
+[CONFIG] otg_latency_bg_log_infile: 0
+[CONFIG] log_config.otg_latency_bg_log_infile set to default value
+[CONFIG] otg_gp_log_infile: 0
+[CONFIG] log_config.otg_gp_log_infile set to default value
+[CONFIG] otg_gp_bg_log_infile: 0
+[CONFIG] log_config.otg_gp_bg_log_infile set to default value
+[CONFIG] otg_jitter_log_infile: 0
+[CONFIG] log_config.otg_jitter_log_infile set to default value
+[CONFIG] rlc_log_infile: 0
+[CONFIG] log_config.rlc_log_infile set to default value
+[CONFIG] pdcp_log_infile: 0
+[CONFIG] log_config.pdcp_log_infile set to default value
+[CONFIG] rrc_log_infile: 0
+[CONFIG] log_config.rrc_log_infile set to default value
+[CONFIG] nas_log_infile: 0
+[CONFIG] log_config.nas_log_infile set to default value
+[CONFIG] perf_log_infile: 0
+[CONFIG] log_config.perf_log_infile set to default value
+[CONFIG] oip_log_infile: 0
+[CONFIG] log_config.oip_log_infile set to default value
+[CONFIG] cli_log_infile: 0
+[CONFIG] log_config.cli_log_infile set to default value
+[CONFIG] msc_log_infile: 0
+[CONFIG] log_config.msc_log_infile set to default value
+[CONFIG] ocm_log_infile: 0
+[CONFIG] log_config.ocm_log_infile set to default value
+[CONFIG] udp_log_infile: 0
+[CONFIG] log_config.udp_log_infile set to default value
+[CONFIG] gtpv1u_log_infile: 0
+[CONFIG] log_config.gtpv1u_log_infile set to default value
+[CONFIG] comp23?_log_infile: 0
+[CONFIG] log_config.comp23?_log_infile set to default value
+[CONFIG] s1ap_log_infile: 0
+[CONFIG] log_config.s1ap_log_infile set to default value
+[CONFIG] sctp_log_infile: 0
+[CONFIG] log_config.sctp_log_infile set to default value
+[CONFIG] hw_log_infile: 0
+[CONFIG] log_config.hw_log_infile set to default value
+[CONFIG] osa_log_infile: 0
+[CONFIG] log_config.osa_log_infile set to default value
+[CONFIG] eral_log_infile: 0
+[CONFIG] log_config.eral_log_infile set to default value
+[CONFIG] mral_log_infile: 0
+[CONFIG] log_config.mral_log_infile set to default value
+[CONFIG] enb_app_log_infile: 0
+[CONFIG] log_config.enb_app_log_infile set to default value
+[CONFIG] flexran_agent_log_infile: 0
+[CONFIG] log_config.flexran_agent_log_infile set to default value
+[CONFIG] tmr_log_infile: 0
+[CONFIG] log_config.tmr_log_infile set to default value
+[CONFIG] usim_log_infile: 0
+[CONFIG] log_config.usim_log_infile set to default value
+[CONFIG] localize_log_infile: 0
+[CONFIG] log_config.localize_log_infile set to default value
+[CONFIG] x2ap_log_infile: 0
+[CONFIG] log_config.x2ap_log_infile set to default value
+[CONFIG] loader_log_infile: 0
+[CONFIG] log_config.loader_log_infile set to default value
+[CONFIG] asn_log_infile: 0
+[CONFIG] log_config.asn_log_infile set to default value
+[LIBCONFIG] log_config: 38/38 parameters successfully set, (38 to default value)
+[CONFIG] log_config 0 options set from command line
+[CONFIG] PRACH_debug: 0
+[CONFIG] log_config.PRACH_debug set to default value
+[CONFIG] RU_debug: 0
+[CONFIG] log_config.RU_debug set to default value
+[CONFIG] UE_PHYPROC_debug: 0
+[CONFIG] log_config.UE_PHYPROC_debug set to default value
+[CONFIG] LTEESTIM_debug: 0
+[CONFIG] log_config.LTEESTIM_debug set to default value
+[CONFIG] DLCELLSPEC_debug: 0
+[CONFIG] log_config.DLCELLSPEC_debug set to default value
+[CONFIG] ULSCH_debug: 0
+[CONFIG] log_config.ULSCH_debug set to default value
+[CONFIG] RRC_debug: 0
+[CONFIG] log_config.RRC_debug set to default value
+[CONFIG] PDCP_debug: 0
+[CONFIG] log_config.PDCP_debug set to default value
+[CONFIG] DFT_debug: 0
+[CONFIG] log_config.DFT_debug set to default value
+[CONFIG] ASN1_debug: 0
+[CONFIG] log_config.ASN1_debug set to default value
+[CONFIG] CTRLSOCKET_debug: 0
+[CONFIG] log_config.CTRLSOCKET_debug set to default value
+[CONFIG] SECURITY_debug: 0
+[CONFIG] log_config.SECURITY_debug set to default value
+[CONFIG] NAS_debug: 0
+[CONFIG] log_config.NAS_debug set to default value
+[CONFIG] RLC_debug: 0
+[CONFIG] log_config.RLC_debug set to default value
+[CONFIG] UE_TIMING_debug: 0
+[CONFIG] log_config.UE_TIMING_debug set to default value
+[LIBCONFIG] log_config: 15/15 parameters successfully set, (15 to default value)
+[CONFIG] log_config 0 options set from command line
+[CONFIG] PRACH_dump: 0
+[CONFIG] log_config.PRACH_dump set to default value
+[CONFIG] RU_dump: 0
+[CONFIG] log_config.RU_dump set to default value
+[CONFIG] UE_PHYPROC_dump: 0
+[CONFIG] log_config.UE_PHYPROC_dump set to default value
+[CONFIG] LTEESTIM_dump: 0
+[CONFIG] log_config.LTEESTIM_dump set to default value
+[CONFIG] DLCELLSPEC_dump: 0
+[CONFIG] log_config.DLCELLSPEC_dump set to default value
+[CONFIG] ULSCH_dump: 0
+[CONFIG] log_config.ULSCH_dump set to default value
+[CONFIG] RRC_dump: 0
+[CONFIG] log_config.RRC_dump set to default value
+[CONFIG] PDCP_dump: 0
+[CONFIG] log_config.PDCP_dump set to default value
+[CONFIG] DFT_dump: 0
+[CONFIG] log_config.DFT_dump set to default value
+[CONFIG] ASN1_dump: 0
+[CONFIG] log_config.ASN1_dump set to default value
+[CONFIG] CTRLSOCKET_dump: 0
+[CONFIG] log_config.CTRLSOCKET_dump set to default value
+[CONFIG] SECURITY_dump: 0
+[CONFIG] log_config.SECURITY_dump set to default value
+[CONFIG] NAS_dump: 0
+[CONFIG] log_config.NAS_dump set to default value
+[CONFIG] RLC_dump: 0
+[CONFIG] log_config.RLC_dump set to default value
+[CONFIG] UE_TIMING_dump: 0
+[CONFIG] log_config.UE_TIMING_dump set to default value
+[LIBCONFIG] log_config: 15/15 parameters successfully set, (15 to default value)
+[CONFIG] log_config 0 options set from command line
+log init done
+
+```
+It can also be retrieved when using the telnet server, as explained  [below](### Using the telnet server to configure the logging facility)
+
+### parameters to activate conditional code
+| name | type | default | description |
+|:---:|:---:|:---:|:----|
+| `<flag>_debug` | `boolean` | 0 = false | Triggers the activation of conditional code identified by the specified flag.
+| `<flag>_dump` | `boolean` | 0 = false| Triggers buffer dump, on the console in text form or in a file in matlab format, depending on the developper choice and forcasted usage|
+
+### Using the configuration file to configure the logging facility
+The following example sets all components log level to info, exept for hw,phy,mac,rlc,pdcp,rrc which log levels are set to error or warning.
+```bash
+    log_config :
+    {
+      global_log_level                      ="info";
+      hw_log_level                          ="error";
+      phy_log_level                         ="error";
+      mac_log_level                         ="warn";
+      rlc_log_level                         ="error"
+      pdcp_log_level                        ="error";
+      rrc_log_level                         ="error";
+   };
+```
+### Using the command line to configure the logging facility
+Command line parameter values supersedes values specified in the configuration file.
+```bash
+./lte-softmodem -O --log_config.global_log_options nocolor,level,thread  --log_config.prach_log_level debug --log_config.PRACH_debug
+```
+In this example to get all the debug PRACH messages it is necessary to also set the PRACH_debug flag. This is a choice from the developper.
+The log messages will be printed whithout color and the header will include the lmessage evel and the thread name:
+```bash
+[PHY]I ru thread Time in secs now: 104652566
+[PHY]I ru thread Time in secs last pps: 91827117
+[PHY]I ru thread RU 0 rf device ready
+[PHY]I ru thread RU 0 no asynch_south interface
+[MAC]E rxtx processing SCHED_MODE=0
+[PHY]I lte-softmodem PRACH (eNB) : running rx_prach for subframe 1, prach_FreqOffset 2, prach_ConfigIndex 0 , rootSequenceIndex 0
+[PHY]I lte-softmodem prach_I0 = 0.0 dB
+[PHY]I rxtx processing max_I0 21, min_I0 0
+[PHY]I lte-softmodem PRACH (eNB) : running rx_prach for subframe 1, prach_FreqOffset 2, prach_ConfigIndex 0 , rootSequenceIndex 0
+[PHY]I lte-softmodem PRACH (eNB) : running rx_prach for subframe 1, prach_FreqOffset 2, prach_ConfigIndex 0 , rootSequenceIndex 0
+```
+
+### Using the telnet server to configure the logging facility
+The telnet server includes a `log` command which can be used to dymically modify the logging facility configuration parameters.
+[telnet server ***softmodem log*** commands](../../telnetsrv/DOC/telnetlog.md)
+
+[logging facility  main page](log.md)
+[oai Wikis home](https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/home)
diff --git a/common/utils/LOG/log.c b/common/utils/LOG/log.c
index 66c3986e87958f7c3ea9a9ac14adcfb9938c6b66..296a011ead6472363b133fcd0ca7dc7497f6e2df 100644
--- a/common/utils/LOG/log.c
+++ b/common/utils/LOG/log.c
@@ -39,13 +39,9 @@
 #include "vcd_signal_dumper.h"
 #include "assertions.h"
 
-#if defined(ENABLE_ITTI)
-# include "intertask_interface.h"
-#endif
-
-# include <pthread.h>
-# include <string.h>
-#include  <linux/prctl.h>
+#include <pthread.h>
+#include <string.h>
+#include <linux/prctl.h>
 #include "common/config/config_userapi.h"
 // main log variables
 
@@ -75,16 +71,14 @@ char *log_level_highlight_start[] = {LOG_RED, LOG_ORANGE, "", LOG_BLUE, LOG_CYBL
 char *log_level_highlight_end[]   = {LOG_RESET,LOG_RESET,LOG_RESET, LOG_RESET,LOG_RESET};   /*!< \brief Optional end-format strings for highlighting */
 
 
-int write_file_matlab(const char *fname,const char *vname,void *data,int length,int dec,char format)
-{
-
+int write_file_matlab(const char *fname,const char *vname,void *data,int length,int dec,char format) {
   FILE *fp=NULL;
   int i;
 
   if (data == NULL)
-     return -1;
-  //printf("Writing %d elements of type %d to %s\n",length,format,fname);
+    return -1;
 
+  //printf("Writing %d elements of type %d to %s\n",length,format,fname);
 
   if (format == 10 || format ==11 || format == 12 || format == 13 || format == 14) {
     fp = fopen(fname,"a+");
@@ -92,8 +86,6 @@ int write_file_matlab(const char *fname,const char *vname,void *data,int length,
     fp = fopen(fname,"w+");
   }
 
-
-
   if (fp== NULL) {
     printf("[OPENAIR][FILE OUTPUT] Cannot open file %s\n",fname);
     return(-1);
@@ -102,121 +94,108 @@ int write_file_matlab(const char *fname,const char *vname,void *data,int length,
   if (format != 10 && format !=11  && format != 12 && format != 13 && format != 14)
     fprintf(fp,"%s = [",vname);
 
-
   switch (format) {
-  case 0:   // real 16-bit
-
-    for (i=0; i<length; i+=dec) {
-      fprintf(fp,"%d\n",((short *)data)[i]);
-    }
-
-    break;
-
-  case 1:  // complex 16-bit
-  case 13:
-  case 14:
-  case 15:
-
-    for (i=0; i<length<<1; i+=(2*dec)) {
-      fprintf(fp,"%d + j*(%d)\n",((short *)data)[i],((short *)data)[i+1]);
-
-    }
-
-
-    break;
-
-  case 2:  // real 32-bit
-    for (i=0; i<length; i+=dec) {
-      fprintf(fp,"%d\n",((int *)data)[i]);
-    }
-
-    break;
-
-  case 3: // complex 32-bit
-    for (i=0; i<length<<1; i+=(2*dec)) {
-      fprintf(fp,"%d + j*(%d)\n",((int *)data)[i],((int *)data)[i+1]);
-    }
-
-    break;
-
-  case 4: // real 8-bit
-    for (i=0; i<length; i+=dec) {
-      fprintf(fp,"%d\n",((char *)data)[i]);
-    }
+    case 0:   // real 16-bit
+      for (i=0; i<length; i+=dec) {
+        fprintf(fp,"%d\n",((short *)data)[i]);
+      }
 
-    break;
+      break;
 
-  case 5: // complex 8-bit
-    for (i=0; i<length<<1; i+=(2*dec)) {
-      fprintf(fp,"%d + j*(%d)\n",((char *)data)[i],((char *)data)[i+1]);
-    }
+    case 1:  // complex 16-bit
+    case 13:
+    case 14:
+    case 15:
+      for (i=0; i<length<<1; i+=(2*dec)) {
+        fprintf(fp,"%d + j*(%d)\n",((short *)data)[i],((short *)data)[i+1]);
+      }
 
-    break;
+      break;
 
-  case 6:  // real 64-bit
-    for (i=0; i<length; i+=dec) {
-      fprintf(fp,"%lld\n",((long long*)data)[i]);
-    }
+    case 2:  // real 32-bit
+      for (i=0; i<length; i+=dec) {
+        fprintf(fp,"%d\n",((int *)data)[i]);
+      }
 
-    break;
+      break;
 
-  case 7: // real double
-    for (i=0; i<length; i+=dec) {
-      fprintf(fp,"%g\n",((double *)data)[i]);
-    }
+    case 3: // complex 32-bit
+      for (i=0; i<length<<1; i+=(2*dec)) {
+        fprintf(fp,"%d + j*(%d)\n",((int *)data)[i],((int *)data)[i+1]);
+      }
 
-    break;
+      break;
 
-  case 8: // complex double
-    for (i=0; i<length<<1; i+=2*dec) {
-      fprintf(fp,"%g + j*(%g)\n",((double *)data)[i], ((double *)data)[i+1]);
-    }
+    case 4: // real 8-bit
+      for (i=0; i<length; i+=dec) {
+        fprintf(fp,"%d\n",((char *)data)[i]);
+      }
 
-    break;
+      break;
 
-  case 9: // real unsigned 8-bit
-    for (i=0; i<length; i+=dec) {
-      fprintf(fp,"%d\n",((unsigned char *)data)[i]);
-    }
+    case 5: // complex 8-bit
+      for (i=0; i<length<<1; i+=(2*dec)) {
+        fprintf(fp,"%d + j*(%d)\n",((char *)data)[i],((char *)data)[i+1]);
+      }
 
-    break;
+      break;
 
+    case 6:  // real 64-bit
+      for (i=0; i<length; i+=dec) {
+        fprintf(fp,"%lld\n",((long long *)data)[i]);
+      }
 
-  case 10 : // case eren 16 bit complex :
+      break;
 
-    for (i=0; i<length<<1; i+=(2*dec)) {
+    case 7: // real double
+      for (i=0; i<length; i+=dec) {
+        fprintf(fp,"%g\n",((double *)data)[i]);
+      }
 
-      if((i < 2*(length-1)) && (i > 0))
-        fprintf(fp,"%d + j*(%d),",((short *)data)[i],((short *)data)[i+1]);
-      else if (i == 2*(length-1))
-        fprintf(fp,"%d + j*(%d);",((short *)data)[i],((short *)data)[i+1]);
-      else if (i == 0)
-        fprintf(fp,"\n%d + j*(%d),",((short *)data)[i],((short *)data)[i+1]);
+      break;
 
+    case 8: // complex double
+      for (i=0; i<length<<1; i+=2*dec) {
+        fprintf(fp,"%g + j*(%g)\n",((double *)data)[i], ((double *)data)[i+1]);
+      }
 
+      break;
 
-    }
+    case 9: // real unsigned 8-bit
+      for (i=0; i<length; i+=dec) {
+        fprintf(fp,"%d\n",((unsigned char *)data)[i]);
+      }
 
-    break;
+      break;
 
-  case 11 : //case eren 16 bit real for channel magnitudes:
-    for (i=0; i<length; i+=dec) {
+    case 10 : // case eren 16 bit complex :
+      for (i=0; i<length<<1; i+=(2*dec)) {
+        if((i < 2*(length-1)) && (i > 0))
+          fprintf(fp,"%d + j*(%d),",((short *)data)[i],((short *)data)[i+1]);
+        else if (i == 2*(length-1))
+          fprintf(fp,"%d + j*(%d);",((short *)data)[i],((short *)data)[i+1]);
+        else if (i == 0)
+          fprintf(fp,"\n%d + j*(%d),",((short *)data)[i],((short *)data)[i+1]);
+      }
 
-      if((i <(length-1))&& (i > 0))
-        fprintf(fp,"%d,",((short *)data)[i]);
-      else if (i == (length-1))
-        fprintf(fp,"%d;",((short *)data)[i]);
-      else if (i == 0)
-        fprintf(fp,"\n%d,",((short *)data)[i]);
-    }
+      break;
 
-    printf("\n eren: length :%d",length);
-    break;
+    case 11 : //case eren 16 bit real for channel magnitudes:
+      for (i=0; i<length; i+=dec) {
+        if((i <(length-1))&& (i > 0))
+          fprintf(fp,"%d,",((short *)data)[i]);
+        else if (i == (length-1))
+          fprintf(fp,"%d;",((short *)data)[i]);
+        else if (i == 0)
+          fprintf(fp,"\n%d,",((short *)data)[i]);
+      }
 
-  case 12 : // case eren for log2_maxh real unsigned 8 bit
-    fprintf(fp,"%d \n",((unsigned char *)&data)[0]);
-    break;
+      printf("\n eren: length :%d",length);
+      break;
 
+    case 12 : // case eren for log2_maxh real unsigned 8 bit
+      fprintf(fp,"%d \n",((unsigned char *)&data)[0]);
+      break;
   }
 
   if (format != 10 && format !=11 && format !=12 && format != 13 && format != 15) {
@@ -235,131 +214,152 @@ int write_file_matlab(const char *fname,const char *vname,void *data,int length,
 void  log_getconfig(log_t *g_log) {
   char *gloglevel = NULL;
   int consolelog ;
-  
-  
   paramdef_t logparams_defaults[] = LOG_GLOBALPARAMS_DESC;
   paramdef_t logparams_level[MAX_LOG_PREDEF_COMPONENTS];
   paramdef_t logparams_logfile[MAX_LOG_PREDEF_COMPONENTS];
   paramdef_t logparams_debug[sizeof(log_maskmap)/sizeof(mapping)];
   paramdef_t logparams_dump[sizeof(log_maskmap)/sizeof(mapping)];
-
   int ret = config_get( logparams_defaults,sizeof(logparams_defaults)/sizeof(paramdef_t),CONFIG_STRING_LOG_PREFIX);
+
   if (ret <0) {
-       fprintf(stderr,"[LOG] init aborted, configuration couldn't be performed");
-       return;
-  } 
+    fprintf(stderr,"[LOG] init aborted, configuration couldn't be performed");
+    return;
+  }
 
-/* set LOG display options (enable/disable color, thread name, level ) */
+  /* set LOG display options (enable/disable color, thread name, level ) */
   for(int i=0; i<logparams_defaults[LOG_OPTIONS_IDX].numelt ; i++) {
-     for(int j=0; log_options[j].name != NULL ; j++) {
-        if (strcmp(logparams_defaults[LOG_OPTIONS_IDX].strlistptr[i],log_options[j].name) == 0) { 
-            g_log->flag = g_log->flag |  log_options[j].value;
-            break;
-        } else if (log_options[j+1].name == NULL){
-            fprintf(stderr,"Unknown log option: %s\n",logparams_defaults[LOG_OPTIONS_IDX].strlistptr[i]);
-            exit(-1);
-        }
-     } 
-  } 
-  
-/* build the parameter array for setting per component log level and infile options */  
+    for(int j=0; log_options[j].name != NULL ; j++) {
+      if (strcmp(logparams_defaults[LOG_OPTIONS_IDX].strlistptr[i],log_options[j].name) == 0) {
+        g_log->flag = g_log->flag |  log_options[j].value;
+        break;
+      } else if (log_options[j+1].name == NULL) {
+        fprintf(stderr,"Unknown log option: %s\n",logparams_defaults[LOG_OPTIONS_IDX].strlistptr[i]);
+        exit(-1);
+      }
+    }
+  }
+
+  /* build the parameter array for setting per component log level and infile options */
   memset(logparams_level,    0, sizeof(paramdef_t)*MAX_LOG_PREDEF_COMPONENTS);
   memset(logparams_logfile,  0, sizeof(paramdef_t)*MAX_LOG_PREDEF_COMPONENTS);
+
   for (int i=MIN_LOG_COMPONENTS; i < MAX_LOG_PREDEF_COMPONENTS; i++) {
     if(g_log->log_component[i].name == NULL) {
-       g_log->log_component[i].name = malloc(16);
-       sprintf((char *)g_log->log_component[i].name,"comp%i?",i);
-       logparams_logfile[i].paramflags = PARAMFLAG_DONOTREAD;
-       logparams_level[i].paramflags = PARAMFLAG_DONOTREAD;
+      g_log->log_component[i].name = malloc(16);
+      sprintf((char *)g_log->log_component[i].name,"comp%i?",i);
+      logparams_logfile[i].paramflags = PARAMFLAG_DONOTREAD;
+      logparams_level[i].paramflags = PARAMFLAG_DONOTREAD;
     }
+
     sprintf(logparams_level[i].optname,    LOG_CONFIG_LEVEL_FORMAT,       g_log->log_component[i].name);
     sprintf(logparams_logfile[i].optname,  LOG_CONFIG_LOGFILE_FORMAT,     g_log->log_component[i].name);
-/* workaround: all log options in existing configuration files use lower case component names
-   where component names include uppercase char in log.h....                                */ 
-    for (int j=0 ; j<strlen(logparams_level[i].optname); j++) 
-          logparams_level[i].optname[j] = tolower(logparams_level[i].optname[j]);
-    for (int j=0 ; j<strlen(logparams_level[i].optname); j++) 
-          logparams_logfile[i].optname[j] = tolower(logparams_logfile[i].optname[j]);
-/* */
+
+    /* workaround: all log options in existing configuration files use lower case component names
+       where component names include uppercase char in log.h....                                */
+    for (int j=0 ; j<strlen(logparams_level[i].optname); j++)
+      logparams_level[i].optname[j] = tolower(logparams_level[i].optname[j]);
+
+    for (int j=0 ; j<strlen(logparams_level[i].optname); j++)
+      logparams_logfile[i].optname[j] = tolower(logparams_logfile[i].optname[j]);
+
+    /* */
     logparams_level[i].defstrval     = gloglevel;
     logparams_logfile[i].defuintval  = 0;
     logparams_logfile[i].numelt      = 0;
     logparams_level[i].numelt        = 0;
     logparams_level[i].type          = TYPE_STRING;
     logparams_logfile[i].type        = TYPE_UINT;
-
     logparams_logfile[i].paramflags  = logparams_logfile[i].paramflags|PARAMFLAG_BOOL;
-    }
-/* read the per component parameters */
-  config_get( logparams_level,    MAX_LOG_PREDEF_COMPONENTS,CONFIG_STRING_LOG_PREFIX); 
-  config_get( logparams_logfile,  MAX_LOG_PREDEF_COMPONENTS,CONFIG_STRING_LOG_PREFIX); 
-/* now set the log levels and infile option, according to what we read */
+  }
+
+  /* read the per component parameters */
+  config_get( logparams_level,    MAX_LOG_PREDEF_COMPONENTS,CONFIG_STRING_LOG_PREFIX);
+  config_get( logparams_logfile,  MAX_LOG_PREDEF_COMPONENTS,CONFIG_STRING_LOG_PREFIX);
+
+  /* now set the log levels and infile option, according to what we read */
   for (int i=MIN_LOG_COMPONENTS; i < MAX_LOG_PREDEF_COMPONENTS; i++) {
     g_log->log_component[i].level = map_str_to_int(log_level_names,    *(logparams_level[i].strptr));
     set_log(i, g_log->log_component[i].level);
+
     if (*(logparams_logfile[i].uptr) == 1)
-        set_component_filelog(i);
+      set_component_filelog(i);
   }
 
-/* build then read the debug and dump parameter array */
-  for (int i=0;log_maskmap[i].name != NULL ; i++) {
-      sprintf(logparams_debug[i].optname,  LOG_CONFIG_DEBUG_FORMAT, log_maskmap[i].name);
-      sprintf(logparams_dump[i].optname,   LOG_CONFIG_DUMP_FORMAT, log_maskmap[i].name);
-      logparams_debug[i].defuintval  = 0;
-      logparams_debug[i].type        = TYPE_UINT;
-      logparams_debug[i].paramflags  = PARAMFLAG_BOOL;
-      logparams_debug[i].uptr        = NULL;
-      logparams_debug[i].chkPptr     = NULL;
-      logparams_debug[i].numelt      = 0;
-      logparams_dump[i].defuintval  = 0;
-      logparams_dump[i].type        = TYPE_UINT;
-      logparams_dump[i].paramflags  = PARAMFLAG_BOOL;
-      logparams_dump[i].uptr        = NULL;
-      logparams_dump[i].chkPptr     = NULL;
-      logparams_dump[i].numelt      = 0;
+  /* build then read the debug and dump parameter array */
+  for (int i=0; log_maskmap[i].name != NULL ; i++) {
+    sprintf(logparams_debug[i].optname,  LOG_CONFIG_DEBUG_FORMAT, log_maskmap[i].name);
+    sprintf(logparams_dump[i].optname,   LOG_CONFIG_DUMP_FORMAT, log_maskmap[i].name);
+    logparams_debug[i].defuintval  = 0;
+    logparams_debug[i].type        = TYPE_UINT;
+    logparams_debug[i].paramflags  = PARAMFLAG_BOOL;
+    logparams_debug[i].uptr        = NULL;
+    logparams_debug[i].chkPptr     = NULL;
+    logparams_debug[i].numelt      = 0;
+    logparams_dump[i].defuintval  = 0;
+    logparams_dump[i].type        = TYPE_UINT;
+    logparams_dump[i].paramflags  = PARAMFLAG_BOOL;
+    logparams_dump[i].uptr        = NULL;
+    logparams_dump[i].chkPptr     = NULL;
+    logparams_dump[i].numelt      = 0;
   }
+
   config_get( logparams_debug,(sizeof(log_maskmap)/sizeof(mapping)) - 1 ,CONFIG_STRING_LOG_PREFIX);
   config_get( logparams_dump,(sizeof(log_maskmap)/sizeof(mapping)) - 1 ,CONFIG_STRING_LOG_PREFIX);
-/* set the debug mask according to the debug parameters values */
+  config_check_unknown_cmdlineopt(CONFIG_STRING_LOG_PREFIX);
+
+  /* set the debug mask according to the debug parameters values */
   for (int i=0; log_maskmap[i].name != NULL ; i++) {
     if (*(logparams_debug[i].uptr) )
-        g_log->debug_mask = g_log->debug_mask | log_maskmap[i].value;
+      g_log->debug_mask = g_log->debug_mask | log_maskmap[i].value;
+
     if (*(logparams_dump[i].uptr) )
-        g_log->dump_mask = g_log->dump_mask | log_maskmap[i].value;
-  } 
-/* log globally enabled/disabled */
+      g_log->dump_mask = g_log->dump_mask | log_maskmap[i].value;
+  }
+
+  /* log globally enabled/disabled */
   set_glog_onlinelog(consolelog);
 }
 
-int register_log_component(char *name, char *fext, int compidx)
-{
-int computed_compidx=compidx;
+int register_log_component(char *name, char *fext, int compidx) {
+  int computed_compidx=compidx;
 
   if (strlen(fext) > 3) {
-      fext[3]=0;  /* limit log file extension to 3 chars */
+    fext[3]=0;  /* limit log file extension to 3 chars */
   }
+
   if (compidx < 0) { /* this is not a pre-defined component */
-      for (int i = MAX_LOG_PREDEF_COMPONENTS; i< MAX_LOG_COMPONENTS; i++) {
-            if (g_log->log_component[i].name == NULL) {
-                computed_compidx=i;
-                break;
-            }
+    for (int i = MAX_LOG_PREDEF_COMPONENTS; i< MAX_LOG_COMPONENTS; i++) {
+      if (g_log->log_component[i].name == NULL) {
+        computed_compidx=i;
+        break;
       }
+    }
   }
+
   if (computed_compidx >= 0 && computed_compidx <MAX_LOG_COMPONENTS) {
-      g_log->log_component[computed_compidx].name = strdup(name);
-      g_log->log_component[computed_compidx].stream = stdout;
-      g_log->log_component[computed_compidx].filelog = 0;
-      g_log->log_component[computed_compidx].filelog_name = malloc(strlen(name)+16);/* /tmp/<name>.%s  */
-      sprintf(g_log->log_component[computed_compidx].filelog_name,"/tmp/%s.%s",name,fext);
+    g_log->log_component[computed_compidx].name = strdup(name);
+    g_log->log_component[computed_compidx].stream = stdout;
+    g_log->log_component[computed_compidx].filelog = 0;
+    g_log->log_component[computed_compidx].filelog_name = malloc(strlen(name)+16);/* /tmp/<name>.%s  */
+    sprintf(g_log->log_component[computed_compidx].filelog_name,"/tmp/%s.%s",name,fext);
   } else {
-      fprintf(stderr,"{LOG} %s %d Couldn't register componemt %s\n",__FILE__,__LINE__,name);
+    fprintf(stderr,"{LOG} %s %d Couldn't register componemt %s\n",__FILE__,__LINE__,name);
   }
-return computed_compidx;
+
+  return computed_compidx;
+}
+
+int isLogInitDone (void) {
+  if (g_log == NULL)
+    return 0;
+
+  if (!(g_log->flag & FLAG_INITIALIZED))
+    return 0;
+
+  return 1;
 }
 
-int logInit (void)
-{
+int logInit (void) {
   int i;
   g_log = calloc(1, sizeof(log_t));
 
@@ -367,10 +367,8 @@ int logInit (void)
     perror ("cannot allocated memory for log generation module \n");
     exit(EXIT_FAILURE);
   }
-  memset(g_log,0,sizeof(log_t));
-
-
 
+  memset(g_log,0,sizeof(log_t));
   register_log_component("PHY","log",PHY);
   register_log_component("MAC","log",MAC);
   register_log_component("OPT","log",OPT);
@@ -386,145 +384,126 @@ int logInit (void)
   register_log_component("OTG_JITTER","dat",OTG_JITTER);
   register_log_component("OCG","",OCG);
   register_log_component("PERF","",PERF);
-  register_log_component("OIP","",OIP); 
-  register_log_component("CLI","",CLI); 
-  register_log_component("MSC","log",MSC); 
-  register_log_component("OCM","log",OCM); 
-  register_log_component("HW","",HW); 
-  register_log_component("OSA","",OSA); 
-  register_log_component("eRAL","",RAL_ENB); 
-  register_log_component("mRAL","",RAL_UE); 
-  register_log_component("ENB_APP","log",ENB_APP); 
-  register_log_component("FLEXRAN_AGENT","log",FLEXRAN_AGENT); 
+  register_log_component("OIP","",OIP);
+  register_log_component("CLI","",CLI);
+  register_log_component("MSC","log",MSC);
+  register_log_component("OCM","log",OCM);
+  register_log_component("HW","",HW);
+  register_log_component("OSA","",OSA);
+  register_log_component("eRAL","",RAL_ENB);
+  register_log_component("mRAL","",RAL_UE);
+  register_log_component("ENB_APP","log",ENB_APP);
+  register_log_component("FLEXRAN_AGENT","log",FLEXRAN_AGENT);
   register_log_component("PROTO_AGENT","log",PROTO_AGENT);
-  register_log_component("TMR","",TMR); 
-  register_log_component("USIM","txt",USIM);   
-  register_log_component("SIM","txt",SIM);  
-
+  register_log_component("TMR","",TMR);
+  register_log_component("USIM","txt",USIM);
+  register_log_component("SIM","txt",SIM);
+  /* following log component are used for the localization*/
   /* following log component are used for the localization*/
   register_log_component("LOCALIZE","log",LOCALIZE);
   register_log_component("NAS","log",NAS);
   register_log_component("UDP","",UDP_);
-
-
   register_log_component("GTPV1U","",GTPU);
-
-
   register_log_component("S1AP","",S1AP);
   register_log_component("F1AP","",F1AP);
   register_log_component("CU_F1AP","",CU_F1AP);
   register_log_component("DU_F1AP","",DU_F1AP);
-
+  register_log_component("X2AP","",X2AP);
   register_log_component("SCTP","",SCTP);
   register_log_component("X2AP","",X2AP);
   register_log_component("LOADER","log",LOADER);
   register_log_component("ASN","log",ASN);
-  
-
 
   for (int i=0 ; log_level_names[i].name != NULL ; i++)
-      g_log->level2string[i]           = toupper(log_level_names[i].name[0]); // uppercased first letter of level name
-
-
- 
-
+    g_log->level2string[i]           = toupper(log_level_names[i].name[0]); // uppercased first letter of level name
 
   g_log->filelog_name = "/tmp/openair.log";
-
   log_getconfig(g_log);
 
-
-
   // set all unused component items to 0, they are for non predefined components
   for (i=MAX_LOG_PREDEF_COMPONENTS; i < MAX_LOG_COMPONENTS; i++) {
-        memset(&(g_log->log_component[i]),0,sizeof(log_component_t));
+    memset(&(g_log->log_component[i]),0,sizeof(log_component_t));
   }
-  printf("log init done\n");
 
+  g_log->flag =  g_log->flag | FLAG_INITIALIZED;
+  printf("log init done\n");
   return 0;
 }
 
 
 char *log_getthreadname(char *threadname, int bufsize) {
+  int rt =   pthread_getname_np(pthread_self(), threadname,bufsize) ;
 
-int rt =   pthread_getname_np(pthread_self(), threadname,bufsize) ;  
-   if (rt == 0)
-   {
-     return threadname;
-   } else {
-     return "thread?";
-   }
+  if (rt == 0) {
+    return threadname;
+  } else {
+    return "thread?";
+  }
 }
 
 static int log_header(char *log_buffer, int buffsize, int comp, int level,const char *format) {
   char threadname[PR_SET_NAME];
-return  snprintf(log_buffer, buffsize , "%s%s[%s]%c %s %s%s",
-  	   log_level_highlight_end[level],
-  	   ( (g_log->flag & FLAG_NOCOLOR)?"":log_level_highlight_start[level]),
-  	   g_log->log_component[comp].name,
-  	   ( (g_log->flag & FLAG_LEVEL)?g_log->level2string[level]:' '),
-  	   ( (g_log->flag & FLAG_THREAD)?log_getthreadname(threadname,PR_SET_NAME+1):""),
-  	   format,
-           log_level_highlight_end[level]);
+  return  snprintf(log_buffer, buffsize , "%s%s[%s]%c %s %s%s",
+                   log_level_highlight_end[level],
+                   ( (g_log->flag & FLAG_NOCOLOR)?"":log_level_highlight_start[level]),
+                   g_log->log_component[comp].name,
+                   ( (g_log->flag & FLAG_LEVEL)?g_log->level2string[level]:' '),
+                   ( (g_log->flag & FLAG_THREAD)?log_getthreadname(threadname,PR_SET_NAME+1):""),
+                   format,
+                   log_level_highlight_end[level]);
 }
 
-void logRecord_mt(const char *file, const char *func, int line, int comp, int level, const char* format, ... )
-  {
+void logRecord_mt(const char *file, const char *func, int line, int comp, int level, const char *format, ... ) {
   char log_buffer[MAX_LOG_TOTAL];
   va_list args;
-
   va_start(args, format);
-
-
-
-
   log_header(log_buffer,MAX_LOG_TOTAL ,comp, level,format);
   g_log->log_component[comp].vprint(g_log->log_component[comp].stream,log_buffer, args);
   va_end(args);
-
-
 }
 
-void log_dump(int component, void *buffer, int buffsize,int datatype, const char* format, ... ) {
-va_list args;
-char *wbuf; 
+void log_dump(int component, void *buffer, int buffsize,int datatype, const char *format, ... ) {
+  va_list args;
+  char *wbuf;
 
+  switch(datatype) {
+    case LOG_DUMP_DOUBLE:
+      wbuf=malloc((buffsize * 10)  + 64 + MAX_LOG_TOTAL);
+      break;
+
+    case LOG_DUMP_CHAR:
+    default:
+      wbuf=malloc((buffsize * 3 ) + 64 + MAX_LOG_TOTAL);
+      break;
+  }
 
-    switch(datatype) {
-       case LOG_DUMP_DOUBLE:
-            wbuf=malloc((buffsize * 10)  + 64 + MAX_LOG_TOTAL);
-       break;
-       case LOG_DUMP_CHAR:
-       default:
-            wbuf=malloc((buffsize * 3 ) + 64 + MAX_LOG_TOTAL);
-       break;
+  if (wbuf != NULL) {
+    va_start(args, format);
+    int pos=log_header(wbuf,MAX_LOG_TOTAL ,component, OAILOG_INFO,"");
+    int pos2=vsprintf(wbuf+pos,format, args);
+    pos=pos+pos2;
+    va_end(args);
+
+    for (int i=0; i<buffsize; i++) {
+      switch(datatype) {
+        case LOG_DUMP_DOUBLE:
+          pos = pos + sprintf(wbuf+pos,"%04.4lf ", (double)((double *)buffer)[i]);
+          break;
+
+        case LOG_DUMP_CHAR:
+        default:
+          pos = pos + sprintf(wbuf+pos,"%02x ", (unsigned char)((unsigned char *)buffer)[i]);
+          break;
+      }
     }
-    if (wbuf != NULL) {       
-       va_start(args, format);
-       int pos=log_header(wbuf,MAX_LOG_TOTAL ,component, OAILOG_INFO,"");
-       int pos2=vsprintf(wbuf+pos,format, args);
-       pos=pos+pos2;
-       va_end(args);
-      
-       for (int i=0; i<buffsize; i++) {
-            switch(datatype) {
-               case LOG_DUMP_DOUBLE:
-                    pos = pos + sprintf(wbuf+pos,"%04.4lf ", (double)((double *)buffer)[i]);
-               break;
-               case LOG_DUMP_CHAR:
-               default:
-                    pos = pos + sprintf(wbuf+pos,"%02x ", (unsigned char)((unsigned char *)buffer)[i]);
-               break;
-            }        
-       }
+
     sprintf(wbuf+pos,"\n");
     g_log->log_component[component].print(g_log->log_component[component].stream,wbuf);
     free(wbuf);
-    } 
+  }
 }
 
-int set_log(int component, int level)
-{
+int set_log(int component, int level) {
   /* Checking parameters */
   DevCheck((component >= MIN_LOG_COMPONENTS) && (component < MAX_LOG_COMPONENTS),
            component, MIN_LOG_COMPONENTS, MAX_LOG_COMPONENTS);
@@ -532,38 +511,34 @@ int set_log(int component, int level)
            OAILOG_ERR);
 
   if ( g_log->log_component[component].level != OAILOG_DISABLE )
-      g_log->log_component[component].savedlevel = g_log->log_component[component].level;
-  g_log->log_component[component].level = level;
+    g_log->log_component[component].savedlevel = g_log->log_component[component].level;
 
+  g_log->log_component[component].level = level;
   return 0;
 }
 
 
 
-void set_glog(int level)
-{
+void set_glog(int level) {
   for (int c=0; c< MAX_LOG_COMPONENTS; c++ ) {
-     set_log(c, level);
+    set_log(c, level);
   }
-  
 }
 
-void set_glog_onlinelog(int enable)
-{
+void set_glog_onlinelog(int enable) {
   for (int c=0; c< MAX_LOG_COMPONENTS; c++ ) {
-      if ( enable ) {
-        g_log->log_component[c].level = g_log->log_component[c].savedlevel;
-        g_log->log_component[c].vprint = vfprintf;
-        g_log->log_component[c].print = fprintf;
-        g_log->log_component[c].stream = stdout;
-      } else {
-        g_log->log_component[c].level = OAILOG_DISABLE;
-      }
-  }  
+    if ( enable ) {
+      g_log->log_component[c].level = g_log->log_component[c].savedlevel;
+      g_log->log_component[c].vprint = vfprintf;
+      g_log->log_component[c].print = fprintf;
+      g_log->log_component[c].stream = stdout;
+    } else {
+      g_log->log_component[c].level = OAILOG_DISABLE;
+    }
+  }
 }
-void set_glog_filelog(int enable)
-{
-static FILE *fptr;
+void set_glog_filelog(int enable) {
+  static FILE *fptr;
 
   if ( enable ) {
     fptr = fopen(g_log->filelog_name,"w");
@@ -576,33 +551,35 @@ static FILE *fptr;
   } else {
     for (int c=0; c< MAX_LOG_COMPONENTS; c++ ) {
       g_log->log_component[c].filelog =  0;
+
       if (fptr != NULL) {
         fclose(fptr);
       }
+
       g_log->log_component[c].stream = stdout;
-    }    
-  }  
+    }
+  }
 }
 
-void set_component_filelog(int comp)
-{
-    if (g_log->log_component[comp].stream == NULL || g_log->log_component[comp].stream == stdout) {
-      g_log->log_component[comp].stream = fopen(g_log->log_component[comp].filelog_name,"w");
-    }
-    g_log->log_component[comp].vprint = vfprintf;
-    g_log->log_component[comp].print = fprintf;
-    g_log->log_component[comp].filelog =  1;
+void set_component_filelog(int comp) {
+  if (g_log->log_component[comp].stream == NULL || g_log->log_component[comp].stream == stdout) {
+    g_log->log_component[comp].stream = fopen(g_log->log_component[comp].filelog_name,"w");
+  }
+
+  g_log->log_component[comp].vprint = vfprintf;
+  g_log->log_component[comp].print = fprintf;
+  g_log->log_component[comp].filelog =  1;
 }
-void close_component_filelog(int comp)
-{
-    g_log->log_component[comp].filelog =  0;
-    if (g_log->log_component[comp].stream != NULL && g_log->log_component[comp].stream != stdout ) {
-      fclose(g_log->log_component[comp].stream);
-      g_log->log_component[comp].stream = stdout;
-    }
-    g_log->log_component[comp].vprint = vfprintf;
-    g_log->log_component[comp].print = fprintf;
- 
+void close_component_filelog(int comp) {
+  g_log->log_component[comp].filelog =  0;
+
+  if (g_log->log_component[comp].stream != NULL && g_log->log_component[comp].stream != stdout ) {
+    fclose(g_log->log_component[comp].stream);
+    g_log->log_component[comp].stream = stdout;
+  }
+
+  g_log->log_component[comp].vprint = vfprintf;
+  g_log->log_component[comp].print = fprintf;
 }
 
 /*
@@ -610,8 +587,7 @@ void close_component_filelog(int comp)
  * with string value NULL
  */
 /* map a string to an int. Takes a mapping array and a string as arg */
-int map_str_to_int(mapping *map, const char *str)
-{
+int map_str_to_int(mapping *map, const char *str) {
   while (1) {
     if (map->name == NULL) {
       return(-1);
@@ -626,8 +602,7 @@ int map_str_to_int(mapping *map, const char *str)
 }
 
 /* map an int to a string. Takes a mapping array and a value */
-char *map_int_to_str(mapping *map, int val)
-{
+char *map_int_to_str(mapping *map, int val) {
   while (1) {
     if (map->name == NULL) {
       return NULL;
@@ -641,8 +616,7 @@ char *map_int_to_str(mapping *map, int val)
   }
 }
 
-int is_newline( char *str, int size)
-{
+int is_newline( char *str, int size) {
   int i;
 
   for (  i = 0; i < size; i++ ) {
@@ -655,85 +629,65 @@ int is_newline( char *str, int size)
   return 0;
 }
 
-void logClean (void)
-{
+void logClean (void) {
   int i;
-  LOG_UI(PHY,"\n");
-
 
+  if(isLogInitDone()) {
+    LOG_UI(PHY,"\n");
 
-
-  for (i=MIN_LOG_COMPONENTS; i < MAX_LOG_COMPONENTS; i++) {
-     close_component_filelog(i);
+    for (i=MIN_LOG_COMPONENTS; i < MAX_LOG_COMPONENTS; i++) {
+      close_component_filelog(i);
+    }
   }
 }
 
-  
-#ifdef LOG_TEST
 
-int main(int argc, char *argv[])
-{
+#ifdef LOG_TEST
 
+int main(int argc, char *argv[]) {
   logInit();
-
-
   test_log();
-
   return 1;
 }
 
-int test_log(void)
-{
+int test_log(void) {
   LOG_ENTER(MAC); // because the default level is DEBUG
   LOG_I(EMU, "1 Starting OAI logs version %s Build date: %s on %s\n",
         BUILD_VERSION, BUILD_DATE, BUILD_HOST);
   LOG_D(MAC, "1 debug  MAC \n");
   LOG_W(MAC, "1 warning MAC \n");
-
   set_log(EMU, OAILOG_INFO);
   set_log(MAC, OAILOG_WARNING);
-
   LOG_I(EMU, "2 Starting OAI logs version %s Build date: %s on %s\n",
         BUILD_VERSION, BUILD_DATE, BUILD_HOST);
   LOG_E(MAC, "2 error MAC\n");
   LOG_D(MAC, "2 debug  MAC \n");
   LOG_W(MAC, "2 warning MAC \n");
   LOG_I(MAC, "2 info MAC \n");
-
-
   set_log(MAC, OAILOG_NOTICE);
-
   LOG_ENTER(MAC);
   LOG_I(EMU, "3 Starting OAI logs version %s Build date: %s on %s\n",
         BUILD_VERSION, BUILD_DATE, BUILD_HOST);
   LOG_D(MAC, "3 debug  MAC \n");
   LOG_W(MAC, "3 warning MAC \n");
   LOG_I(MAC, "3 info MAC \n");
-
   set_log(MAC, LOG_DEBUG);
   set_log(EMU, LOG_DEBUG);
-
   LOG_ENTER(MAC);
   LOG_I(EMU, "4 Starting OAI logs version %s Build date: %s on %s\n",
         BUILD_VERSION, BUILD_DATE, BUILD_HOST);
   LOG_D(MAC, "4 debug  MAC \n");
   LOG_W(MAC, "4 warning MAC \n");
   LOG_I(MAC, "4 info MAC \n");
-
-
   set_log(MAC, LOG_DEBUG);
   set_log(EMU, LOG_DEBUG);
-
   LOG_I(LOG, "5 Starting OAI logs version %s Build date: %s on %s\n",
         BUILD_VERSION, BUILD_DATE, BUILD_HOST);
   LOG_D(MAC, "5 debug  MAC \n");
   LOG_W(MAC, "5 warning MAC \n");
   LOG_I(MAC, "5 info MAC \n");
-
-
   set_log(MAC, LOG_TRACE);
   set_log(EMU, LOG_TRACE);
-
   LOG_ENTER(MAC);
   LOG_I(LOG, "6 Starting OAI logs version %s Build date: %s on %s\n",
         BUILD_VERSION, BUILD_DATE, BUILD_HOST);
@@ -741,7 +695,6 @@ int test_log(void)
   LOG_W(MAC, "6 warning MAC \n");
   LOG_I(MAC, "6 info MAC \n");
   LOG_EXIT(MAC);
-
   return 0;
 }
 #endif
diff --git a/common/utils/LOG/log.h b/common/utils/LOG/log.h
index 21c51cba8fe882821dab93dafb55294b7e507d1d..f5705202571735885e8f8c38e9a4a6130587f66e 100644
--- a/common/utils/LOG/log.h
+++ b/common/utils/LOG/log.h
@@ -45,11 +45,11 @@
 #include <time.h>
 #include <stdint.h>
 #ifndef __STDC_FORMAT_MACROS
-#define __STDC_FORMAT_MACROS
+  #define __STDC_FORMAT_MACROS
 #endif
 #include <inttypes.h>
 #ifndef _GNU_SOURCE
-#define _GNU_SOURCE
+  #define _GNU_SOURCE
 #endif
 #include <pthread.h>
 #include "T.h"
@@ -115,23 +115,22 @@ extern "C" {
  * @{*/
 
 
-#define FLAG_NOCOLOR   0x0001  /*!< \brief use colors in log messages, depending on level */
-#define FLAG_THREAD    0x0008  /*!< \brief display thread name in log messages */
-#define FLAG_LEVEL     0x0010  /*!< \brief display log level in log messages */
-#define FLAG_FUNCT     0x0020
-#define FLAG_FILE_LINE 0x0040
-#define FLAG_TIME      0x0100
+#define FLAG_NOCOLOR     0x0001  /*!< \brief use colors in log messages, depending on level */
+#define FLAG_THREAD      0x0008  /*!< \brief display thread name in log messages */
+#define FLAG_LEVEL       0x0010  /*!< \brief display log level in log messages */
+#define FLAG_TIME        0x0100
+#define FLAG_INITIALIZED 0x8000
 
 #define SET_LOG_OPTION(O)   g_log->flag = (g_log->flag | O)
 #define CLEAR_LOG_OPTION(O) g_log->flag = (g_log->flag & (~O))
 
 /** @defgroup macros to identify a debug entity
  *  @ingroup each macro is a bit mask where the unique bit set identifies an entity to be debugged
- *            it allows to dynamically activate or not blocks of code. The  LOG_MASKMAP_INIT macro 
+ *            it allows to dynamically activate or not blocks of code. The  LOG_MASKMAP_INIT macro
  *            is used to map a character string name to each debug bit, it allows to set or clear
  *            the corresponding bit via the defined name, from the configuration or from the telnet
  *            server.
- *  @brief 
+ *  @brief
  * @{*/
 #define DEBUG_PRACH        (1<<0)
 #define DEBUG_RU           (1<<1)
@@ -146,26 +145,28 @@ extern "C" {
 #define DEBUG_CTRLSOCKET   (1<<10)
 #define DEBUG_SECURITY     (1<<11)
 #define DEBUG_NAS          (1<<12)
+#define DEBUG_RLC          (1<<13)
 #define UE_TIMING          (1<<20)
 
 
 #define LOG_MASKMAP_INIT {\
-  {"PRACH",       DEBUG_PRACH},\
-  {"RU",          DEBUG_RU},\
-  {"UE_PHYPROC",  DEBUG_UE_PHYPROC},\
-  {"LTEESTIM",    DEBUG_LTEESTIM},\
-  {"DLCELLSPEC",  DEBUG_DLCELLSPEC},\
-  {"ULSCH",       DEBUG_ULSCH},\
-  {"RRC",         DEBUG_RRC},\
-  {"PDCP",        DEBUG_PDCP},\
-  {"DFT",         DEBUG_DFT},\
-  {"ASN1",        DEBUG_ASN1},\
-  {"CTRLSOCKET",  DEBUG_CTRLSOCKET},\
-  {"SECURITY",    DEBUG_SECURITY},\
-  {"NAS",         DEBUG_NAS},\
-  {"UE_TIMING",   UE_TIMING},\
-  {NULL,-1}\
-}
+    {"PRACH",       DEBUG_PRACH},\
+    {"RU",          DEBUG_RU},\
+    {"UE_PHYPROC",  DEBUG_UE_PHYPROC},\
+    {"LTEESTIM",    DEBUG_LTEESTIM},\
+    {"DLCELLSPEC",  DEBUG_DLCELLSPEC},\
+    {"ULSCH",       DEBUG_ULSCH},\
+    {"RRC",         DEBUG_RRC},\
+    {"PDCP",        DEBUG_PDCP},\
+    {"DFT",         DEBUG_DFT},\
+    {"ASN1",        DEBUG_ASN1},\
+    {"CTRLSOCKET",  DEBUG_CTRLSOCKET},\
+    {"SECURITY",    DEBUG_SECURITY},\
+    {"NAS",         DEBUG_NAS},\
+    {"RLC",         DEBUG_RLC},\
+    {"UE_TIMING",   UE_TIMING},\
+    {NULL,-1}\
+  }
 
 
 
@@ -178,52 +179,51 @@ extern "C" {
 
 
 typedef enum {
-    MIN_LOG_COMPONENTS = 0,
-    PHY = MIN_LOG_COMPONENTS,
-    MAC,
-    SIM,
-    OCG,
-    OMG,
-    OPT,
-    OTG,
-    OTG_LATENCY,
-    OTG_LATENCY_BG,
-    OTG_GP,
-    OTG_GP_BG,
-    OTG_JITTER,
-    RLC,
-    PDCP,
-    RRC,
-    NAS,
-    PERF,
-    OIP,
-    CLI,
-    MSC,
-    OCM,
-    UDP_,
-    GTPU,
-    SPGW,
-    S1AP,
-    F1AP,
-    DU_F1AP,
-    CU_F1AP,
-    SCTP,
-    HW,
-    OSA,
-    RAL_ENB,
-    RAL_UE,
-    ENB_APP,
-    FLEXRAN_AGENT,
-    TMR,
-    USIM,
-    LOCALIZE,
-    RRH,
-    PROTO_AGENT,
-    F1U,
-    X2AP,
-    LOADER,
-    ASN,
-    MAX_LOG_PREDEF_COMPONENTS,
+  MIN_LOG_COMPONENTS = 0,
+  PHY = MIN_LOG_COMPONENTS,
+  MAC,
+  SIM,
+  OCG,
+  OMG,
+  OPT,
+  OTG,
+  OTG_LATENCY,
+  OTG_LATENCY_BG,
+  OTG_GP,
+  OTG_GP_BG,
+  OTG_JITTER,
+  RLC,
+  PDCP,
+  RRC,
+  NAS,
+  PERF,
+  OIP,
+  CLI,
+  MSC,
+  OCM,
+  UDP_,
+  GTPU,
+  SPGW,
+  S1AP,
+  F1AP,
+  DU_F1AP,
+  CU_F1AP,
+  SCTP,
+  HW,
+  OSA,
+  RAL_ENB,
+  RAL_UE,
+  ENB_APP,
+  FLEXRAN_AGENT,
+  TMR,
+  USIM,
+  LOCALIZE,
+  PROTO_AGENT,
+  F1U,
+  X2AP,
+  LOADER,
+  ASN,
+  MAX_LOG_PREDEF_COMPONENTS,
 }
 comp_name_t;
 
@@ -232,42 +232,42 @@ comp_name_t;
 
 
 typedef struct {
-    char *name; /*!< \brief string name of item */
-    int value;  /*!< \brief integer value of mapping */
+  char *name; /*!< \brief string name of item */
+  int value;  /*!< \brief integer value of mapping */
 } mapping;
 
 typedef int(*log_vprint_func_t)(FILE *stream, const char *format, va_list ap );
 typedef int(*log_print_func_t)(FILE *stream, const char *format, ... );
 typedef struct  {
-    const char        *name;
-    int               level;
-    int               savedlevel;
-    int               flag;
-    int               filelog;
-    char              *filelog_name;
-    FILE              *stream;
-    log_vprint_func_t vprint;
-    log_print_func_t  print;
-    /* SR: make the log buffer component relative */
-    char             log_buffer[MAX_LOG_TOTAL];
+  const char        *name;
+  int               level;
+  int               savedlevel;
+  int               flag;
+  int               filelog;
+  char              *filelog_name;
+  FILE              *stream;
+  log_vprint_func_t vprint;
+  log_print_func_t  print;
+  /* SR: make the log buffer component relative */
+  char             log_buffer[MAX_LOG_TOTAL];
 } log_component_t;
 
 
 typedef struct {
-    log_component_t         log_component[MAX_LOG_COMPONENTS];
-    char                    level2string[NUM_LOG_LEVEL];
-    int                     flag;
-    char*                   filelog_name;
-    uint64_t                debug_mask;
-    uint64_t                dump_mask;
+  log_component_t         log_component[MAX_LOG_COMPONENTS];
+  char                    level2string[NUM_LOG_LEVEL];
+  int                     flag;
+  char                   *filelog_name;
+  uint64_t                debug_mask;
+  uint64_t                dump_mask;
 } log_t;
 
 
 #if defined(ENABLE_ITTI)
 typedef enum log_instance_type_e {
-    LOG_INSTANCE_UNKNOWN,
-    LOG_INSTANCE_ENB,
-    LOG_INSTANCE_UE,
+  LOG_INSTANCE_UNKNOWN,
+  LOG_INSTANCE_ENB,
+  LOG_INSTANCE_UE,
 } log_instance_type_t;
 
 void log_set_instance_type (log_instance_type_t instance);
@@ -278,9 +278,9 @@ void log_set_instance_type (log_instance_type_t instance);
 log_t *g_log;
 #else
 #ifdef __cplusplus
-   extern "C" {
+extern "C" {
 #endif
-extern log_t *g_log;
+  extern log_t *g_log;
 #ifdef __cplusplus
 }
 #endif
@@ -289,8 +289,9 @@ extern log_t *g_log;
 #    include "log_if.h"
 /*----------------------------------------------------------------------------*/
 int  logInit (void);
+int isLogInitDone (void);
 void logRecord_mt(const char *file, const char *func, int line,int comp, int level, const char *format, ...) __attribute__ ((format (printf, 6, 7)));
-void log_dump(int component, void *buffer, int buffsize,int datatype, const char* format, ... );
+void log_dump(int component, void *buffer, int buffsize,int datatype, const char *format, ... );
 int  set_log(int component, int level);
 void set_glog(int level);
 
@@ -333,24 +334,26 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int
 #define LOG_CONFIG_DUMP_FORMAT                             "%s_dump"
 
 #define LOG_CONFIG_HELP_OPTIONS      " list of comma separated options to enable log module behavior. Available options: \n"\
-                                     " nocolor:   disable color usage in log messages\n"\
-				     " level:     add log level indication in log messages\n"\
-				     " thread:    add threads names in log messages\n"
-				     
+  " nocolor:   disable color usage in log messages\n"\
+  " level:     add log level indication in log messages\n"\
+  " thread:    add threads names in log messages\n"
+
+
 
 
-                   
 /*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
-/*                                       LOG globalconfiguration parameters										                                                */
-/*   optname                            help                                                paramflags       XXXptr	                   defXXXval				      type	 numelt	*/
+/*                                       LOG globalconfiguration parameters                                                                   */
+/*   optname                            help                                                paramflags       XXXptr                    defXXXval              type   numelt */
 /*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
 #define LOG_GLOBALPARAMS_DESC { \
-{LOG_CONFIG_STRING_GLOBAL_LOG_LEVEL,    "Default log level for all componemts\n",              0,  	      strptr:(char **)&gloglevel,    defstrval:log_level_names[2].name,    TYPE_STRING,    0}, \
-{LOG_CONFIG_STRING_GLOBAL_LOG_ONLINE,   "Default console output option, for all components\n", 0,  	      iptr:&(consolelog),            defintval:1,                          TYPE_INT,       0}, \
-{LOG_CONFIG_STRING_GLOBAL_LOG_OPTIONS,  LOG_CONFIG_HELP_OPTIONS,                               0,  	      strlistptr:NULL,               defstrlistval:NULL,                   TYPE_STRINGLIST,0} \
-}
+    {LOG_CONFIG_STRING_GLOBAL_LOG_LEVEL,    "Default log level for all componemts\n",              0,         strptr:(char **)&gloglevel,    defstrval:log_level_names[2].name,    TYPE_STRING,    0}, \
+    {LOG_CONFIG_STRING_GLOBAL_LOG_ONLINE,   "Default console output option, for all components\n", 0,         iptr:&(consolelog),            defintval:1,                          TYPE_INT,       0}, \
+    {LOG_CONFIG_STRING_GLOBAL_LOG_OPTIONS,  LOG_CONFIG_HELP_OPTIONS,                               0,         strlistptr:NULL,               defstrlistval:NULL,                   TYPE_STRINGLIST,0} \
+  }
 
 #define LOG_OPTIONS_IDX   2
+
+
 /*----------------------------------------------------------------------------------*/
 /** @defgroup _debugging debugging macros
  *  @ingroup _macro
@@ -360,23 +363,23 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int
 #define LOG_DUMP_DOUBLE     1
 // debugging macros
 #define LOG_F  LOG_I           /* because  LOG_F was originaly to dump a message or buffer but is also used as a regular level...., to dump use LOG_DUMPMSG */
-#  if T_TRACER 
-     /* per component, level dependant macros */
-#    define LOG_E(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_ERR    ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_ERR, x)     ;} else { T(T_LEGACY_ ## c ## _ERROR, T_PRINTF(x))   ;}} while (0) 
-#    define LOG_W(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_WARNING) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_WARNING, x) ;} else { T(T_LEGACY_ ## c ## _WARNING, T_PRINTF(x)) ;}} while (0) 
-#    define LOG_I(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_INFO   ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_INFO, x)    ;} else { T(T_LEGACY_ ## c ## _INFO, T_PRINTF(x))    ;}} while (0) 
-#    define LOG_D(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_DEBUG  ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_DEBUG, x)   ;} else { T(T_LEGACY_ ## c ## _DEBUG, T_PRINTF(x))   ;}} while (0) 
-#    define LOG_T(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_TRACE  ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_TRACE, x)   ;} else { T(T_LEGACY_ ## c ## _TRACE, T_PRINTF(x))   ;}} while (0) 
-    /* macro used to dump a buffer or a message as in openair2/RRC/LTE/RRC_eNB.c, replaces LOG_F macro */
+#  if T_TRACER
+/* per component, level dependant macros */
+#    define LOG_E(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_ERR    ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_ERR, x)     ;} else { T(T_LEGACY_ ## c ## _ERROR, T_PRINTF(x))   ;}} while (0)
+#    define LOG_W(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_WARNING) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_WARNING, x) ;} else { T(T_LEGACY_ ## c ## _WARNING, T_PRINTF(x)) ;}} while (0)
+#    define LOG_I(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_INFO   ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_INFO, x)    ;} else { T(T_LEGACY_ ## c ## _INFO, T_PRINTF(x))    ;}} while (0)
+#    define LOG_D(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_DEBUG  ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_DEBUG, x)   ;} else { T(T_LEGACY_ ## c ## _DEBUG, T_PRINTF(x))   ;}} while (0)
+#    define LOG_T(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_TRACE  ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_TRACE, x)   ;} else { T(T_LEGACY_ ## c ## _TRACE, T_PRINTF(x))   ;}} while (0)
+/* macro used to dump a buffer or a message as in openair2/RRC/LTE/RRC_eNB.c, replaces LOG_F macro */
 #    define LOG_DUMPMSG(c, f, b, s, x...) do {  if(g_log->dump_mask & f) log_dump(c, b, s, LOG_DUMP_CHAR, x)  ;}   while (0)  /* */
 #    define nfapi_log(FILE, FNC, LN, COMP, LVL, F...)  do { if (T_stdout) { logRecord_mt(__FILE__, __FUNCTION__, __LINE__,COMP, LVL, F)  ;}}   while (0)  /* */
-     /* bitmask dependant macros, to isolate debugging code */
+/* bitmask dependant macros, to isolate debugging code */
 #    define LOG_DEBUGFLAG(D) (g_log->debug_mask & D)
 
-     /* bitmask dependant macros, to generate debug file such as matlab file or message dump */
+/* bitmask dependant macros, to generate debug file such as matlab file or message dump */
 #    define LOG_DUMPFLAG(D) (g_log->dump_mask & D)
 #    define LOG_M(file, vector, data, len, dec, format) do { write_file_matlab(file, vector, data, len, dec, format);} while(0)/* */
-     /* define variable only used in LOG macro's */
+/* define variable only used in LOG macro's */
 #    define LOG_VAR(A,B) A B
 #  else /* T_TRACER: remove all debugging and tracing messages, except errors */
 #    define LOG_I(c, x...) /* */
@@ -386,15 +389,15 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int
 #    define LOG_T(c, x...) /* */
 
 #    define LOG_DUMPMSG(c, b, s, x...) /* */
-#    define nfapi_log(FILE, FNC, LN, COMP, LVL, FMT...) 
+#    define nfapi_log(FILE, FNC, LN, COMP, LVL, FMT...)
 #    define LOG_DEBUGFLAG(D)  ( 0 )
-#    define LOG_DUMPFLAG(D) ( 0 ) 
-#    define LOG_M(file, vector, data, len, dec, format) 
+#    define LOG_DUMPFLAG(D) ( 0 )
+#    define LOG_M(file, vector, data, len, dec, format)
 #    define LOG_VAR(A,B)
 #  endif /* T_TRACER */
 /* avoid warnings for variables only used in LOG macro's but set outside debug section */
-#define	GCC_NOTUSED		__attribute__((unused))
-#define LOG_USEDINLOG_VAR(A,B) GCC_NOTUSED A B 
+#define GCC_NOTUSED   __attribute__((unused))
+#define LOG_USEDINLOG_VAR(A,B) GCC_NOTUSED A B
 
 /* unfiltered macros, usefull for simulators or messages at init time, before log is configured */
 #define LOG_UM(file, vector, data, len, dec, format) do { write_file_matlab(file, vector, data, len, dec, format);} while(0)
@@ -426,78 +429,82 @@ static __inline__ uint64_t rdtsc(void) {
 
 extern double cpuf;
 
-static inline uint64_t checkTCPU(int timeout, char * file, int line) {
-    static uint64_t __thread lastCPUTime=0;
-    static uint64_t __thread last=0;
-    uint64_t cur=rdtsc();
-    struct timespec CPUt;
-    clock_gettime(CLOCK_THREAD_CPUTIME_ID, &CPUt);
-    uint64_t CPUTime=CPUt.tv_sec*1000*1000+CPUt.tv_nsec/1000;
-    double microCycles=(double)(cpuf*1000);
-    int duration=(int)((cur-last)/microCycles);
-    if ( last!=0 && duration > timeout ) {
-      //struct timespec ts;
-      //clock_gettime(CLOCK_MONOTONIC, &ts);
-      printf("%s:%d lte-ue delay %d (exceed %d), CPU for this period: %lld\n", file, line,
-               duration, timeout, (long long)CPUTime-lastCPUTime );
-    }
-    last=cur;
-    lastCPUTime=CPUTime;
-    return cur;
+static inline uint64_t checkTCPU(int timeout, char *file, int line) {
+  static uint64_t __thread lastCPUTime=0;
+  static uint64_t __thread last=0;
+  uint64_t cur=rdtsc();
+  struct timespec CPUt;
+  clock_gettime(CLOCK_THREAD_CPUTIME_ID, &CPUt);
+  uint64_t CPUTime=CPUt.tv_sec*1000*1000+CPUt.tv_nsec/1000;
+  double microCycles=(double)(cpuf*1000);
+  int duration=(int)((cur-last)/microCycles);
+
+  if ( last!=0 && duration > timeout ) {
+    //struct timespec ts;
+    //clock_gettime(CLOCK_MONOTONIC, &ts);
+    printf("%s:%d lte-ue delay %d (exceed %d), CPU for this period: %lld\n", file, line,
+           duration, timeout, (long long)CPUTime-lastCPUTime );
+  }
+
+  last=cur;
+  lastCPUTime=CPUTime;
+  return cur;
 }
 
-static inline unsigned long long checkT(int timeout, char * file, int line) {
-    static unsigned long long __thread last=0;
-    unsigned long long cur=rdtsc();
-    int microCycles=(int)(cpuf*1000);
-    int duration=(int)((cur-last)/microCycles);
-    if ( last!=0 && duration > timeout )
-        printf("%s:%d lte-ue delay %d (exceed %d)\n", file, line,
-               duration, timeout);
-    last=cur;
-    return cur;
+static inline unsigned long long checkT(int timeout, char *file, int line) {
+  static unsigned long long __thread last=0;
+  unsigned long long cur=rdtsc();
+  int microCycles=(int)(cpuf*1000);
+  int duration=(int)((cur-last)/microCycles);
+
+  if ( last!=0 && duration > timeout )
+    printf("%s:%d lte-ue delay %d (exceed %d)\n", file, line,
+           duration, timeout);
+
+  last=cur;
+  return cur;
 }
 
 typedef struct m {
-    uint64_t iterations;
-    uint64_t sum;
-    uint64_t maxArray[11];
+  uint64_t iterations;
+  uint64_t sum;
+  uint64_t maxArray[11];
 } Meas;
 
-static inline void printMeas(char * txt, Meas *M, int period) {
-    if (M->iterations%period == 0 ) {
-        char txt2[512];
-        sprintf(txt2,"%s avg=%" PRIu64 " iterations=%" PRIu64 " max=%" 
-                PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 "\n",
-                txt,
-                M->sum/M->iterations,
-                M->iterations,
-                M->maxArray[1],M->maxArray[2], M->maxArray[3],M->maxArray[4], M->maxArray[5], 
-                M->maxArray[6],M->maxArray[7], M->maxArray[8],M->maxArray[9],M->maxArray[10]);
+static inline void printMeas(char *txt, Meas *M, int period) {
+  if (M->iterations%period == 0 ) {
+    char txt2[512];
+    sprintf(txt2,"%s avg=%" PRIu64 " iterations=%" PRIu64 " max=%"
+            PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 "\n",
+            txt,
+            M->sum/M->iterations,
+            M->iterations,
+            M->maxArray[1],M->maxArray[2], M->maxArray[3],M->maxArray[4], M->maxArray[5],
+            M->maxArray[6],M->maxArray[7], M->maxArray[8],M->maxArray[9],M->maxArray[10]);
 #if DISABLE_LOG_X
-        printf("%s",txt2);
+    printf("%s",txt2);
 #else
-        LOG_W(PHY, "%s",txt2);
+    LOG_W(PHY, "%s",txt2);
 #endif
-    }
+  }
 }
 
-static inline int cmpint(const void* a, const void* b) {
-    uint64_t* aa=(uint64_t*)a;
-    uint64_t* bb=(uint64_t*)b;
-    return (int)(*aa-*bb);
+static inline int cmpint(const void *a, const void *b) {
+  uint64_t *aa=(uint64_t *)a;
+  uint64_t *bb=(uint64_t *)b;
+  return (int)(*aa-*bb);
 }
 
-static inline void updateTimes(uint64_t start, Meas *M, int period, char * txt) {
-    if (start!=0) {
-        uint64_t end=rdtsc();
-        long long diff=(end-start)/(cpuf*1000);
-        M->maxArray[0]=diff;
-        M->sum+=diff;
-        M->iterations++;
-        qsort(M->maxArray, 11, sizeof(uint64_t), cmpint);
-        printMeas(txt,M,period);
-    }
+static inline void updateTimes(uint64_t start, Meas *M, int period, char *txt) {
+  if (start!=0) {
+    uint64_t end=rdtsc();
+    long long diff=(end-start)/(cpuf*1000);
+    M->maxArray[0]=diff;
+    M->sum+=diff;
+    M->iterations++;
+    qsort(M->maxArray, 11, sizeof(uint64_t), cmpint);
+    printMeas(txt,M,period);
+  }
 }
 
 #define check(a) do { checkT(a,__FILE__,__LINE__); } while (0)
diff --git a/common/utils/T/Makefile b/common/utils/T/Makefile
index 87a6e34c5d1e0ecd4636439d9eccf8aeacd26d38..0588c88a456c4d54965c73f4caee0e060d8b4852 100644
--- a/common/utils/T/Makefile
+++ b/common/utils/T/Makefile
@@ -19,7 +19,7 @@ T_IDs.h: $(GENIDS) T_messages.txt
 	./$(GENIDS) T_messages.txt T_IDs.h
 
 check_vcd:
-	gcc -Wall -I. -I.. -I../itti -Itracer -o _check_vcd check_vcd.c tracer/database.c tracer/utils.c -lm -pthread
+	gcc -Wall -I. -I.. -I../itti -I../../../openair2/COMMON -Itracer -o _check_vcd check_vcd.c tracer/database.c tracer/utils.c -lm -pthread
 	./_check_vcd || (rm -f ./_check_vcd ./T_IDs.h ./T_messages.txt.h && false)
 	rm -f ./_check_vcd
 
diff --git a/common/utils/T/T.c b/common/utils/T/T.c
index fbd3f75a0c195fbb9d41e927fe6b3bf13150ee41..8ee359b77f491518e4aa934851f087bc040175c7 100644
--- a/common/utils/T/T.c
+++ b/common/utils/T/T.c
@@ -12,14 +12,16 @@
 #include "common/config/config_userapi.h"
 
 #define QUIT(x) do { \
-  printf("T tracer: QUIT: %s\n", x); \
-  exit(1); \
-} while (0)
+    printf("T tracer: QUIT: %s\n", x); \
+    exit(1); \
+  } while (0)
 
 /* array used to activate/disactivate a log */
 static int T_IDs[T_NUMBER_OF_IDS];
 int *T_active = T_IDs;
-int T_stdout;
+
+int T_stdout = 1;
+
 
 static int T_socket;
 
@@ -32,125 +34,159 @@ volatile int *T_freelist_head = &_T_freelist_head;
 T_cache_t *T_cache;
 
 #if BASIC_SIMULATOR
-/* global variables used by T_GET_SLOT, see in T.h */
-volatile uint64_t T_next_id;
-volatile uint64_t T_active_id;
+  /* global variables used by T_GET_SLOT, see in T.h */
+  volatile uint64_t T_next_id;
+  volatile uint64_t T_active_id;
 #endif
 
-static void get_message(int s)
-{
+static void get_message(int s) {
   char t;
   int l;
   int id;
   int is_on;
 
   if (read(s, &t, 1) != 1) QUIT("get_message fails");
-printf("T tracer: got mess %d\n", t);
+
+  printf("T tracer: got mess %d\n", t);
+
   switch (t) {
-  case 0:
-    /* toggle all those IDs */
-    /* optimze? (too much syscalls) */
-    if (read(s, &l, sizeof(int)) != sizeof(int)) QUIT("get_message fails");
-    while (l) {
-      if (read(s, &id, sizeof(int)) != sizeof(int)) QUIT("get_message fails");
-      T_IDs[id] = 1 - T_IDs[id];
-      l--;
-    }
-    break;
-  case 1:
-    /* set IDs as given */
-    /* optimize? */
-    if (read(s, &l, sizeof(int)) != sizeof(int)) QUIT("get_message fails");
-    id = 0;
-    while (l) {
-      if (read(s, &is_on, sizeof(int)) != sizeof(int))
-        QUIT("get_message fails");
-      T_IDs[id] = is_on;
-      id++;
-      l--;
-    }
-    break;
-  case 2: break; /* do nothing, this message is to wait for local tracer */
+    case 0:
+
+      /* toggle all those IDs */
+      /* optimze? (too much syscalls) */
+      if (read(s, &l, sizeof(int)) != sizeof(int)) QUIT("get_message fails");
+
+      while (l) {
+        if (read(s, &id, sizeof(int)) != sizeof(int)) QUIT("get_message fails");
+
+        T_IDs[id] = 1 - T_IDs[id];
+        l--;
+      }
+
+      break;
+
+    case 1:
+
+      /* set IDs as given */
+      /* optimize? */
+      if (read(s, &l, sizeof(int)) != sizeof(int)) QUIT("get_message fails");
+
+      id = 0;
+
+      while (l) {
+        if (read(s, &is_on, sizeof(int)) != sizeof(int))
+          QUIT("get_message fails");
+
+        T_IDs[id] = is_on;
+        id++;
+        l--;
+      }
+
+      break;
+
+    case 2:
+      break; /* do nothing, this message is to wait for local tracer */
   }
 }
 
-static void *T_receive_thread(void *_)
-{
+static void *T_receive_thread(void *_) {
   while (1) get_message(T_socket);
+
   return NULL;
 }
 
-static void new_thread(void *(*f)(void *), void *data)
-{
+static void new_thread(void *(*f)(void *), void *data) {
   pthread_t t;
   pthread_attr_t att;
 
-  if (pthread_attr_init(&att))
-    { fprintf(stderr, "pthread_attr_init err\n"); exit(1); }
-  if (pthread_attr_setdetachstate(&att, PTHREAD_CREATE_DETACHED))
-    { fprintf(stderr, "pthread_attr_setdetachstate err\n"); exit(1); }
-  if (pthread_create(&t, &att, f, data))
-    { fprintf(stderr, "pthread_create err\n"); exit(1); }
-  if (pthread_attr_destroy(&att))
-    { fprintf(stderr, "pthread_attr_destroy err\n"); exit(1); }
+  if (pthread_attr_init(&att)) {
+    fprintf(stderr, "pthread_attr_init err\n");
+    exit(1);
+  }
+
+  if (pthread_attr_setdetachstate(&att, PTHREAD_CREATE_DETACHED)) {
+    fprintf(stderr, "pthread_attr_setdetachstate err\n");
+    exit(1);
+  }
+
+  if (pthread_create(&t, &att, f, data)) {
+    fprintf(stderr, "pthread_create err\n");
+    exit(1);
+  }
+
+  if (pthread_attr_destroy(&att)) {
+    fprintf(stderr, "pthread_attr_destroy err\n");
+    exit(1);
+  }
 }
 
 /* defined in local_tracer.c */
 void T_local_tracer_main(int remote_port, int wait_for_tracer,
-    int local_socket, void *shm_array);
+                         int local_socket, void *shm_array);
 
 /* We monitor the tracee and the local tracer processes.
  * When one dies we forcefully kill the other.
  */
 #include <sys/types.h>
 #include <sys/wait.h>
-static void monitor_and_kill(int child1, int child2)
-{
+static void monitor_and_kill(int child1, int child2) {
   int child;
   int status;
-
   child = wait(&status);
+
   if (child == -1) perror("wait");
+
   kill(child1, SIGKILL);
   kill(child2, SIGKILL);
   exit(0);
 }
 
-void T_init(int remote_port, int wait_for_tracer, int dont_fork)
-{
+void T_init(int remote_port, int wait_for_tracer, int dont_fork) {
   int socket_pair[2];
   int s;
   int child1, child2;
   int i;
 
-  if (socketpair(AF_UNIX, SOCK_STREAM, 0, socket_pair))
-    { perror("socketpair"); abort(); }
+  if (socketpair(AF_UNIX, SOCK_STREAM, 0, socket_pair)) {
+    perror("socketpair");
+    abort();
+  }
 
   /* setup shared memory */
   T_cache = mmap(NULL, T_CACHE_SIZE * sizeof(T_cache_t),
                  PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
-  if (T_cache == MAP_FAILED)
-    { perror("mmap"); abort(); }
+
+  if (T_cache == MAP_FAILED) {
+    perror("mmap");
+    abort();
+  }
 
   /* let's garbage the memory to catch some potential problems
    * (think multiprocessor sync issues, barriers, etc.)
    */
   memset(T_cache, 0x55, T_CACHE_SIZE * sizeof(T_cache_t));
+
   for (i = 0; i < T_CACHE_SIZE; i++) T_cache[i].busy = 0;
 
   /* child1 runs the local tracer and child2 (or main) runs the tracee */
+  child1 = fork();
+
+  if (child1 == -1) abort();
 
-  child1 = fork(); if (child1 == -1) abort();
   if (child1 == 0) {
     close(socket_pair[1]);
     T_local_tracer_main(remote_port, wait_for_tracer, socket_pair[0],
                         T_cache);
     exit(0);
   }
+
   close(socket_pair[0]);
 
   if (dont_fork == 0) {
-    child2 = fork(); if (child2 == -1) abort();
+    child2 = fork();
+
+    if (child2 == -1) abort();
+
     if (child2 != 0) {
       close(socket_pair[1]);
       munmap(T_cache, T_CACHE_SIZE * sizeof(T_cache_t));
@@ -161,27 +197,21 @@ void T_init(int remote_port, int wait_for_tracer, int dont_fork)
   s = socket_pair[1];
   /* wait for first message - initial list of active T events */
   get_message(s);
-
   T_socket = s;
-
   new_thread(T_receive_thread, NULL);
 }
 
-void T_Config_Init(void)
-{
-  int T_port;         /* by default we wait for the tracer */
-  int T_nowait;       /* default port to listen to to wait for the tracer */
-  int T_dont_fork;    /* default is to fork, see 'T_init' to understand */
-
+void T_Config_Init(void) {
+  int T_port=TTRACER_DEFAULT_PORTNUM; /* by default we wait for the tracer */
+  int T_nowait=0;                     /* default port to listen to to wait for the tracer */
+  int T_dont_fork=0;                  /* default is to fork, see 'T_init' to understand */
   paramdef_t ttraceparams[] = CMDLINE_TTRACEPARAMS_DESC;
-
   /* for a cleaner config file, TTracer params should be defined in a
    * specific section...
    */
   config_get(ttraceparams,
              sizeof(ttraceparams) / sizeof(paramdef_t),
              TTRACER_CONFIG_PREFIX);
-
   /* compatibility: look for TTracer command line options in root section */
   config_process_cmdline(ttraceparams,
                          sizeof(ttraceparams) / sizeof(paramdef_t),
diff --git a/common/utils/T/T.h b/common/utils/T/T.h
index 18e4a590d9444d12257d5207b4e00446d2811f6b..626dbafd2586840657e515ca66a6f5ab8776080b 100644
--- a/common/utils/T/T.h
+++ b/common/utils/T/T.h
@@ -8,7 +8,7 @@
 #include "T_defs.h"
 
 #ifdef T_SEND_TIME
-#include <time.h>
+  #include <time.h>
 #endif
 
 /* T message IDs */
@@ -76,13 +76,13 @@
                              T_BUFFER_MAX - T_LOCAL_size, T_PUT_printf_deref x); \
     if (T_PUT_len < 0) { \
       printf("%s:%d:%s: you can't read this, or can you?", \
-               __FILE__, __LINE__, __FUNCTION__); \
+             __FILE__, __LINE__, __FUNCTION__); \
       abort(); \
     } \
     if (T_PUT_len >= T_BUFFER_MAX - T_LOCAL_size) { \
       printf("%s:%d:%s: cannot put argument %d in T macro, not enough space" \
-               ", consider increasing T_BUFFER_MAX (%d)\n", \
-               __FILE__, __LINE__, __FUNCTION__, argnum, T_BUFFER_MAX); \
+             ", consider increasing T_BUFFER_MAX (%d)\n", \
+             __FILE__, __LINE__, __FUNCTION__, argnum, T_BUFFER_MAX); \
       abort(); \
     } \
     T_LOCAL_size += T_PUT_len + 1; \
@@ -97,9 +97,9 @@ struct T_header;
 /* T macro tricks */
 extern int T_stdout;
 #define TN(...) TN_N(__VA_ARGS__,33,32,31,30,29,28,27,26,25,24,23,22,21,\
-        20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)(__VA_ARGS__)
+                     20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)(__VA_ARGS__)
 #define TN_N(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16,n17,\
-        n18,n19,n20,n21,n22,n23,n24,n25,n26,n27,n28,n29,n30,n31,n32,n,...) T##n
+             n18,n19,n20,n21,n22,n23,n24,n25,n26,n27,n28,n29,n30,n31,n32,n,...) T##n
 #define T(...) do { if (T_stdout == 0) TN(__VA_ARGS__); } while (0)
 
 /* type used to send arbitrary buffer data */
@@ -119,30 +119,30 @@ extern int *T_active;
  */
 #if BASIC_SIMULATOR
 #  define T_GET_SLOT \
-     do { \
-       extern volatile uint64_t T_next_id; \
-       extern volatile uint64_t T_active_id; \
-       uint64_t id; \
-       /* get a ticket */ \
-       id = __sync_fetch_and_add(&T_next_id, 1); \
-       /* wait for our turn */ \
-       while (id != __sync_fetch_and_add(&T_active_id, 0)) /* busy wait */; \
-       /* this is our turn, try to acquire the slot until it's free */ \
-       do { \
-         T_LOCAL_busy = __sync_fetch_and_or(&T_cache[T_LOCAL_slot].busy, 0x01); \
-         if (T_LOCAL_busy & 0x01) usleep(100); \
-       } while (T_LOCAL_busy & 0x01); \
-       /* check that there are still some tickets */ \
-       if (__sync_fetch_and_add(&T_active_id, 0) == 0xffffffffffffffff) { \
-         printf("T: reached the end of times, bye...\n"); \
-         abort(); \
-       } \
-       /* free our ticket, which signals the next waiter that it's its turn */ \
-       (void)__sync_fetch_and_add(&T_active_id, 1); \
-     } while (0)
+  do { \
+    extern volatile uint64_t T_next_id; \
+    extern volatile uint64_t T_active_id; \
+    uint64_t id; \
+    /* get a ticket */ \
+    id = __sync_fetch_and_add(&T_next_id, 1); \
+    /* wait for our turn */ \
+    while (id != __sync_fetch_and_add(&T_active_id, 0)) /* busy wait */; \
+    /* this is our turn, try to acquire the slot until it's free */ \
+    do { \
+      T_LOCAL_busy = __sync_fetch_and_or(&T_cache[T_LOCAL_slot].busy, 0x01); \
+      if (T_LOCAL_busy & 0x01) usleep(100); \
+    } while (T_LOCAL_busy & 0x01); \
+    /* check that there are still some tickets */ \
+    if (__sync_fetch_and_add(&T_active_id, 0) == 0xffffffffffffffff) { \
+      printf("T: reached the end of times, bye...\n"); \
+      abort(); \
+    } \
+    /* free our ticket, which signals the next waiter that it's its turn */ \
+    (void)__sync_fetch_and_add(&T_active_id, 1); \
+  } while (0)
 #else
 #  define T_GET_SLOT \
-     T_LOCAL_busy = __sync_fetch_and_or(&T_cache[T_LOCAL_slot].busy, 0x01);
+  T_LOCAL_busy = __sync_fetch_and_or(&T_cache[T_LOCAL_slot].busy, 0x01);
 #endif
 
 /* used at header of Tn, allocates buffer */
@@ -172,8 +172,8 @@ extern int *T_active;
 #define T_CHECK_SIZE(len, argnum) \
   if (T_LOCAL_size + (len) > T_BUFFER_MAX) { \
     printf("%s:%d:%s: cannot put argument %d in T macro, not enough space" \
-             ", consider increasing T_BUFFER_MAX (%d)\n", \
-             __FILE__, __LINE__, __FUNCTION__, argnum, T_BUFFER_MAX); \
+           ", consider increasing T_BUFFER_MAX (%d)\n", \
+           __FILE__, __LINE__, __FUNCTION__, argnum, T_BUFFER_MAX); \
     abort(); \
   }
 
@@ -598,20 +598,21 @@ extern int *T_active;
 
 
 #define TTRACER_CONFIG_PREFIX   "TTracer"
-/*------------------------------------------------------------------------------------------------------------------------------------------*/
-/*                                            configuration parameters for TTRACE utility                                                   */
-/*   optname                     helpstr                paramflags           XXXptr           defXXXval         type       numelt           */
-/*------------------------------------------------------------------------------------------------------------------------------------------*/
+/*-------------------------------------------------------------------------------------------------------------------------------------------------*/
+/*                                            configuration parameters for TTRACE utility                                                          */
+/*   optname                     helpstr                paramflags           XXXptr           defXXXval                         type       numelt  */
+/*-------------------------------------------------------------------------------------------------------------------------------------------------*/
+#define TTRACER_DEFAULT_PORTNUM 2021
 #define CMDLINE_TTRACEPARAMS_DESC {  \
-{"T_port",                     CONFIG_HLP_TPORT,      0,                iptr:&T_port,        defintval:2021,     TYPE_INT,   0},           \
-{"T_nowait",                   CONFIG_HLP_NOTWAIT,    PARAMFLAG_BOOL,   iptr:&T_nowait,      defintval:0,        TYPE_INT,   0},           \
-{"T_dont_fork",                CONFIG_HLP_TNOFORK,    PARAMFLAG_BOOL,   iptr:&T_dont_fork,   defintval:0,        TYPE_INT,   0},           \
-{"T_stdout",                   CONFIG_HLP_STDOUT,     PARAMFLAG_BOOL,   iptr:&T_stdout,      defintval:1,        TYPE_INT,   0},           \
-} 
+    {"T_port",                     CONFIG_HLP_TPORT,      0,                iptr:&T_port,        defintval:TTRACER_DEFAULT_PORTNUM, TYPE_INT,   0},\
+    {"T_nowait",                   CONFIG_HLP_NOTWAIT,    PARAMFLAG_BOOL,   iptr:&T_nowait,      defintval:0,                       TYPE_INT,   0},\
+    {"T_dont_fork",                CONFIG_HLP_TNOFORK,    PARAMFLAG_BOOL,   iptr:&T_dont_fork,   defintval:0,                       TYPE_INT,   0},\
+    {"T_stdout",                   CONFIG_HLP_STDOUT,     PARAMFLAG_BOOL,   iptr:&T_stdout,      defintval:1,                       TYPE_INT,   0},\
+  }
 
 
 
-        /* log on stdout */
+/* log on stdout */
 void T_init(int remote_port, int wait_for_tracer, int dont_fork);
 void T_Config_Init(void);
 #else /* T_TRACER */
diff --git a/common/utils/T/T_messages.txt b/common/utils/T/T_messages.txt
index 40297ff25d9e6da30a8958d9e800fa144aee7529..9d8aa0e17e3a95c77bae6ed50ff400b327cdc3e8 100644
--- a/common/utils/T/T_messages.txt
+++ b/common/utils/T/T_messages.txt
@@ -75,8 +75,12 @@ ID = ENB_PHY_MSG3_ALLOCATION
     FORMAT = int,eNB_ID : int,frame : int,subframe : int,rnti : int,first_transmission : int,Msg3_frame : int,Msg3_subframe
 ID = ENB_PHY_INITIATE_RA_PROCEDURE
     DESC = eNodeB initiates a random access procedure after detecting enough energy for one of the preambles
-    GROUP = ALL:PHY:ENB
+    GROUP = ALL:PHY:ENB:WIRESHARK
     FORMAT = int,eNB_ID : int,frame : int,subframe : int,preamble : int,energy : int,delay
+ID = ENB_PHY_MIB
+    DESC = MIB data
+    GROUP = ALL:PHY:ENB:WIRESHARK
+    FORMAT = int,eNB_ID : int,frame : int,subframe : buffer,data
 
 #MAC logs
 ID = ENB_MAC_UE_DL_SDU
@@ -97,7 +101,7 @@ ID = ENB_MAC_UE_UL_PDU
     FORMAT = int,eNB_ID : int,CC_id : int,rnti : int,frame : int,subframe : int,harq_pid : int,sdu_length : int,num_ce : int,num_sdu
 ID = ENB_MAC_UE_UL_PDU_WITH_DATA
     DESC = MAC uplink UE received PDU
-    GROUP = ALL:MAC:ENB
+    GROUP = ALL:MAC:ENB:WIRESHARK
     FORMAT = int,eNB_ID : int,CC_id : int,rnti : int,frame : int,subframe : int,harq_pid : int,sdu_length : int,num_ce : int,num_sdu : buffer,data
 ID = ENB_MAC_UE_UL_SDU
     DESC = MAC uplink UE received SDU
@@ -113,12 +117,16 @@ ID = ENB_MAC_UE_UL_CE
     FORMAT = int,eNB_ID : int,CC_id : int,rnti : int,frame : int,subframe : int,ce
 ID = ENB_MAC_UE_DL_PDU_WITH_DATA
     DESC = MAC downlink PDU for an UE
-    GROUP = ALL:MAC:ENB
+    GROUP = ALL:MAC:ENB:WIRESHARK
     FORMAT = int,eNB_ID : int,CC_id : int,rnti : int,frame : int,subframe : int,harq_pid : buffer,data
 ID = ENB_MAC_SCHEDULING_REQUEST
     DESC = MAC scheduling request detected for an UE
     GROUP = ALL:MAC:ENB
     FORMAT = int,eNB_ID : int,CC_id : int,frame : int,subframe : int,rnti
+ID = ENB_MAC_UE_DL_RAR_PDU_WITH_DATA
+    DESC = MAC downlink PDU for an UE
+    GROUP = ALL:MAC:ENB:WIRESHARK
+    FORMAT = int,eNB_ID : int,CC_id : int,rnti : int,frame : int,subframe : int,harq_pid : buffer,data
 
 #RLC logs
 ID = ENB_RLC_DL
diff --git a/common/utils/T/genids.c b/common/utils/T/genids.c
index 8e5adbf587081322fc2d6047c7b4d246841bdc94..a130988262427e7b0f01a293bd3a2f66c3354305 100644
--- a/common/utils/T/genids.c
+++ b/common/utils/T/genids.c
@@ -8,27 +8,35 @@ char **unique_ids;
 int unique_ids_size;
 int unique_ids_maxsize;
 
-int cmp(const void *p1, const void *p2)
-{
-  return strcmp(*(char * const *)p1, *(char * const *)p2);
+int cmp(const void *p1, const void *p2) {
+  return strcmp(*(char *const *)p1, *(char *const *)p2);
 }
 
 /* return 1 if s was not already known, 0 if it was */
-int new_unique_id(char *s, char *input_file)
-{
+int new_unique_id(char *s, char *input_file) {
   if (unique_ids_size)
-  if (bsearch(&s, unique_ids, unique_ids_size, sizeof(char *), cmp) != NULL) {
-    printf("error: ID %s is not unique in %s\n", s, input_file);
-    return 0;
-  }
+    if (bsearch(&s, unique_ids, unique_ids_size, sizeof(char *), cmp) != NULL) {
+      printf("error: ID %s is not unique in %s\n", s, input_file);
+      return 0;
+    }
+
   if (unique_ids_size == unique_ids_maxsize) {
     unique_ids_maxsize += 256;
     unique_ids = realloc(unique_ids, unique_ids_maxsize * sizeof(char *));
-    if (unique_ids == NULL) { printf("erorr: out of memory\n"); abort(); }
+
+    if (unique_ids == NULL) {
+      printf("error: out of memory\n");
+      abort();
+    }
   }
+
   unique_ids[unique_ids_size] = strdup(s);
-  if (unique_ids[unique_ids_size] == NULL)
-    { printf("erorr: out of memory\n"); abort(); }
+
+  if (unique_ids[unique_ids_size] == NULL) {
+    printf("error: out of memory\n");
+    abort();
+  }
+
   unique_ids_size++;
   qsort(unique_ids, unique_ids_size, sizeof(char *), cmp);
   return 1;
@@ -38,14 +46,17 @@ char *bufname;
 int bufname_size;
 int bufname_maxsize;
 
-void putname(int c)
-{
+void putname(int c) {
   if (bufname_size == bufname_maxsize) {
     bufname_maxsize += 256;
     bufname = realloc(bufname, bufname_maxsize);
-    if (bufname == NULL)
-      { printf("erorr: memory allocation error\n"); exit(1); }
+
+    if (bufname == NULL) {
+      printf("error: memory allocation error\n");
+      exit(1);
+    }
   }
+
   bufname[bufname_size] = c;
   bufname_size++;
 }
@@ -54,42 +65,54 @@ char *bufvalue;
 int bufvalue_size;
 int bufvalue_maxsize;
 
-void putvalue(int c)
-{
+void putvalue(int c) {
   if (bufvalue_size == bufvalue_maxsize) {
     bufvalue_maxsize += 256;
     bufvalue = realloc(bufvalue, bufvalue_maxsize);
-    if (bufvalue == NULL)
-      { printf("error: memory allocation error\n"); exit(1); }
+
+    if (bufvalue == NULL) {
+      printf("error: memory allocation error\n");
+      exit(1);
+    }
   }
+
   bufvalue[bufvalue_size] = c;
   bufvalue_size++;
 }
 
-void smash_spaces(FILE *f)
-{
+void smash_spaces(FILE *f) {
   int c;
+
   while (1) {
     c = fgetc(f);
+
     if (isspace(c)) continue;
+
     if (c == ' ') continue;
+
     if (c == '\t') continue;
+
     if (c == '\n') continue;
+
     if (c == 10 || c == 13) continue;
+
     if (c == '#') {
       while (1) {
         c = fgetc(f);
+
         if (c == '\n' || c == EOF) break;
       }
+
       continue;
     }
+
     break;
   }
+
   if (c != EOF) ungetc(c, f);
 }
 
-void get_line(FILE *f, char **name, char **value)
-{
+void get_line(FILE *f, char **name, char **value) {
   int c;
   bufname_size = 0;
   bufvalue_size = 0;
@@ -97,23 +120,39 @@ void get_line(FILE *f, char **name, char **value)
   *value = NULL;
   smash_spaces(f);
   c = fgetc(f);
-  while (!(c == '=' || isspace(c) || c == EOF)) { putname(c); c = fgetc(f); }
+
+  while (!(c == '=' || isspace(c) || c == EOF)) {
+    putname(c);
+    c = fgetc(f);
+  }
+
   if (c == EOF) return;
+
   putname(0);
+
   while (!(c == EOF || c == '=')) c = fgetc(f);
+
   if (c == EOF) return;
+
   smash_spaces(f);
   c = fgetc(f);
-  while (!(c == 10 || c == 13 || c == EOF)) { putvalue(c); c = fgetc(f); }
+
+  while (!(c == 10 || c == 13 || c == EOF)) {
+    putvalue(c);
+    c = fgetc(f);
+  }
+
   putvalue(0);
+
   if (bufname_size <= 1) return;
+
   if (bufvalue_size <= 1) return;
+
   *name = bufname;
   *value = bufvalue;
 }
 
-int main(int n, char **v)
-{
+int main(int n, char **v) {
   FILE *in;
   FILE *out;
   char *name;
@@ -121,36 +160,54 @@ int main(int n, char **v)
   char *in_name;
   char *out_name;
 
-  if (n != 3) { printf("error: gimme <source> <dest>\n"); exit(1); }
+  if (n != 3) {
+    printf("error: gimme <source> <dest>\n");
+    exit(1);
+  }
 
   n = 0;
-
   in_name = v[1];
   out_name = v[2];
+  in = fopen(in_name, "r");
+
+  if (in == NULL) {
+    perror(in_name);
+    exit(1);
+  }
 
-  in = fopen(in_name, "r"); if (in == NULL) { perror(in_name); exit(1); }
-  out = fopen(out_name, "w"); if (out == NULL) { perror(out_name); exit(1); }
+  out = fopen(out_name, "w");
+
+  if (out == NULL) {
+    perror(out_name);
+    exit(1);
+  }
 
   fprintf(out, "/* generated file, do not edit by hand */\n\n");
 
   while (1) {
     get_line(in, &name, &value);
+
     if (name == NULL) break;
+
     if (isspace(value[strlen(value)-1])) {
       printf("error: bad value '%s' (no space at the end please!)\n", value);
       unlink(out_name);
       exit(1);
     }
+
     if (!strcmp(name, "ID")) {
-      if (!new_unique_id(value, in_name)) { unlink(out_name); exit(1); }
+      if (!new_unique_id(value, in_name)) {
+        unlink(out_name);
+        exit(1);
+      }
+
       fprintf(out, "#define T_%s T_ID(%d)\n", value, n);
       n++;
     }
   }
-  fprintf(out, "#define T_NUMBER_OF_IDS %d\n", n);
 
+  fprintf(out, "#define T_NUMBER_OF_IDS %d\n", n);
   fclose(in);
   fclose(out);
-
   return 0;
 }
diff --git a/common/utils/T/local_tracer.c b/common/utils/T/local_tracer.c
index f8e92881a96e79a000e57fcad814e8440719a895..4be0b35d16a28c3fa9492e5a60a81401d0ff9e5e 100644
--- a/common/utils/T/local_tracer.c
+++ b/common/utils/T/local_tracer.c
@@ -31,7 +31,7 @@ typedef struct {
   int remote_port;
   pthread_mutex_t lock;
   pthread_cond_t cond;
-  databuf * volatile head, *tail;
+  databuf *volatile head, *tail;
   uint64_t memusage;
   uint64_t last_warning_memusage;
 } forward_data;
@@ -40,80 +40,115 @@ typedef struct {
 /*                      utility functions                                   */
 /****************************************************************************/
 
-static void new_thread(void *(*f)(void *), void *data)
-{
+static void new_thread(void *(*f)(void *), void *data) {
   pthread_t t;
   pthread_attr_t att;
 
-  if (pthread_attr_init(&att))
-    { fprintf(stderr, "pthread_attr_init err\n"); exit(1); }
-  if (pthread_attr_setdetachstate(&att, PTHREAD_CREATE_DETACHED))
-    { fprintf(stderr, "pthread_attr_setdetachstate err\n"); exit(1); }
-  if (pthread_attr_setstacksize(&att, 10000000))
-    { fprintf(stderr, "pthread_attr_setstacksize err\n"); exit(1); }
-  if (pthread_create(&t, &att, f, data))
-    { fprintf(stderr, "pthread_create err\n"); exit(1); }
-  if (pthread_attr_destroy(&att))
-    { fprintf(stderr, "pthread_attr_destroy err\n"); exit(1); }
+  if (pthread_attr_init(&att)) {
+    fprintf(stderr, "pthread_attr_init err\n");
+    exit(1);
+  }
+
+  if (pthread_attr_setdetachstate(&att, PTHREAD_CREATE_DETACHED)) {
+    fprintf(stderr, "pthread_attr_setdetachstate err\n");
+    exit(1);
+  }
+
+  if (pthread_attr_setstacksize(&att, 10000000)) {
+    fprintf(stderr, "pthread_attr_setstacksize err\n");
+    exit(1);
+  }
+
+  if (pthread_create(&t, &att, f, data)) {
+    fprintf(stderr, "pthread_create err\n");
+    exit(1);
+  }
+
+  if (pthread_attr_destroy(&att)) {
+    fprintf(stderr, "pthread_attr_destroy err\n");
+    exit(1);
+  }
 }
 
-static int get_connection(char *addr, int port)
-{
+static int get_connection(char *addr, int port) {
   struct sockaddr_in a;
   socklen_t alen;
   int s, t;
-
   printf("T tracer: waiting for connection on %s:%d\n", addr, port);
-
   s = socket(AF_INET, SOCK_STREAM, 0);
-  if (s == -1) { perror("socket"); exit(1); }
+
+  if (s == -1) {
+    perror("socket");
+    exit(1);
+  }
+
   t = 1;
-  if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &t, sizeof(int)))
-    { perror("setsockopt"); exit(1); }
+
+  if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &t, sizeof(int))) {
+    perror("setsockopt");
+    exit(1);
+  }
 
   a.sin_family = AF_INET;
   a.sin_port = htons(port);
   a.sin_addr.s_addr = inet_addr(addr);
 
-  if (bind(s, (struct sockaddr *)&a, sizeof(a))) { perror("bind"); exit(1); }
-  if (listen(s, 5)) { perror("bind"); exit(1); }
+  if (bind(s, (struct sockaddr *)&a, sizeof(a))) {
+    perror("bind");
+    exit(1);
+  }
+
+  if (listen(s, 5)) {
+    perror("bind");
+    exit(1);
+  }
+
   alen = sizeof(a);
   t = accept(s, (struct sockaddr *)&a, &alen);
-  if (t == -1) { perror("accept"); exit(1); }
-  close(s);
 
-  printf("T tracer: connected\n");
+  if (t == -1) {
+    perror("accept");
+    exit(1);
+  }
 
+  close(s);
+  printf("T tracer: connected\n");
   return t;
 }
 
 static void forward(void *_forwarder, char *buf, int size);
 
-void send_T_messages_txt(void *forwarder)
-{
+void send_T_messages_txt(void *forwarder) {
   char buf[T_BUFFER_MAX];
   char *T_LOCAL_buf = buf;
   int T_LOCAL_size;
   unsigned char *src;
   int src_len;
-
   /* trace T_message.txt
    * Send several messages -1 with content followed by message -2.
    */
   src = T_messages_txt;
   src_len = T_messages_txt_len;
+
   while (src_len) {
     int send_size = src_len;
+
     if (send_size > T_PAYLOAD_MAXSIZE - sizeof(int))
       send_size = T_PAYLOAD_MAXSIZE - sizeof(int);
+
     /* TODO: be careful, we use internal T stuff, to rewrite? */
     T_LOCAL_size = 0;
     T_HEADER(T_ID(-1));
-    T_PUT_buffer(1, ((T_buffer){addr:(src), length:(send_size)}));
+    T_PUT_buffer(1, ((T_buffer) {
+addr:
+(src), length:
+      (send_size)
+    }));
     forward(forwarder, buf, T_LOCAL_size);
     src += send_size;
     src_len -= send_size;
   }
+
   T_LOCAL_size = 0;
   T_HEADER(T_ID(-2));
   forward(forwarder, buf, T_LOCAL_size);
@@ -123,49 +158,54 @@ void send_T_messages_txt(void *forwarder)
 /*                      forward functions                                   */
 /****************************************************************************/
 
-static void *data_sender(void *_f)
-{
+static void *data_sender(void *_f) {
   forward_data *f = _f;
   databuf *cur;
   char *buf, *b;
   int size;
-
 wait:
+
   if (pthread_mutex_lock(&f->lock)) abort();
+
   while (f->head == NULL)
     if (pthread_cond_wait(&f->cond, &f->lock)) abort();
+
   cur = f->head;
   buf = cur->d;
   size = cur->l;
   f->head = cur->next;
   f->memusage -= size;
+
   if (f->head == NULL) f->tail = NULL;
+
   if (pthread_mutex_unlock(&f->lock)) abort();
+
   free(cur);
   goto process;
-
 process:
   b = buf;
+
   if (f->socket_remote != -1)
-  while (size) {
-    int l = write(f->socket_remote, b, size);
-    if (l <= 0) {
-      printf("T tracer: forward error\n");
-      close(f->socket_remote);
-      f->socket_remote = -1;
-      break;
+    while (size) {
+      int l = write(f->socket_remote, b, size);
+
+      if (l <= 0) {
+        printf("T tracer: forward error\n");
+        close(f->socket_remote);
+        f->socket_remote = -1;
+        break;
+      }
+
+      size -= l;
+      b += l;
     }
-    size -= l;
-    b += l;
-  }
 
   free(buf);
-
   goto wait;
 }
 
-static void *forward_remote_messages(void *_f)
-{
+
+static void *forward_remote_messages(void *_f) {
 #define PUT(x) do { \
     if (bufsize == bufmaxsize) { \
       bufmaxsize += 4096; \
@@ -180,7 +220,6 @@ static void *forward_remote_messages(void *_f)
     int len = l; \
     while (len) { PUT(*zz); zz++; len--; } \
   } while (0)
-
   forward_data *f = _f;
   int from;
   int to;
@@ -190,43 +229,53 @@ static void *forward_remote_messages(void *_f)
   int bufsize = 0;
   int bufmaxsize = 0;
   char t;
-
 again:
 
   while (1) {
     from = f->socket_remote;
     to = f->socket_local;
-
     bufsize = 0;
-
     /* let's read and process messages */
-    len = read(from, &t, 1); if (len <= 0) goto dead;
+    len = read(from, &t, 1);
+
+    if (len <= 0) goto dead;
+
     PUT(t);
 
     switch (t) {
-    case 0:
-    case 1:
-      /* message 0 and 1: get a length and then 'length' numbers */
-      if (read(from, &len, sizeof(int)) != sizeof(int)) goto dead;
-      PUT_BUF(&len, 4);
-      while (len) {
-        if (read(from, &l, sizeof(int)) != sizeof(int)) goto dead;
-        PUT_BUF(&l, 4);
-        len--;
-      }
-      break;
+      case 0:
+      case 1:
+
+        /* message 0 and 1: get a length and then 'length' numbers */
+        if (read(from, &len, sizeof(int)) != sizeof(int)) goto dead;
+
+        PUT_BUF(&len, 4);
+
+        while (len) {
+          if (read(from, &l, sizeof(int)) != sizeof(int)) goto dead;
+
+          PUT_BUF(&l, 4);
+          len--;
+        }
+
+        break;
+
+      case 2:
+        break;
 
-    case 2: break;
-    default:
-      printf("%s:%d:%s: unhandled message type %d\n",
-          __FILE__, __LINE__, __FUNCTION__, t);
-      abort();
+      default:
+        printf("%s:%d:%s: unhandled message type %d\n",
+               __FILE__, __LINE__, __FUNCTION__, t);
+        abort();
     }
 
     b = buf;
+
     while (bufsize) {
       l = write(to, b, bufsize);
+
       if (l <= 0) abort();
+
       bufsize -= l;
       b += l;
     }
@@ -236,71 +285,80 @@ dead:
   /* socket died, let's stop all traces and wait for another tracer */
   /* TODO: be careful with those write, they might write less than wanted */
   buf[0] = 1;
+
   if (write(to, buf, 1) != 1) abort();
+
   len = T_NUMBER_OF_IDS;
+
   if (write(to, &len, sizeof(int)) != sizeof(int)) abort();
+
   l = 0;
+
   while (len) {
     if (write(to, &l, sizeof(int)) != sizeof(int)) abort();
+
     len--;
   };
 
   close(f->socket_remote);
+
   f->socket_remote = get_connection("0.0.0.0", f->remote_port);
+
   send_T_messages_txt(f);
+
   goto again;
 
   return NULL;
 }
 
-static void *forwarder(int port, int s)
-{
+static void *forwarder(int port, int s) {
   forward_data *f;
+  f = malloc(sizeof(*f));
 
-  f = malloc(sizeof(*f)); if (f == NULL) abort();
+  if (f == NULL) abort();
 
   pthread_mutex_init(&f->lock, NULL);
   pthread_cond_init(&f->cond, NULL);
-
   f->socket_local = s;
   f->head = f->tail = NULL;
-
   f->memusage = 0;
   f->last_warning_memusage = 0;
-
   printf("T tracer: waiting for remote tracer on port %d\n", port);
-
   f->remote_port = port;
   f->socket_remote = get_connection("0.0.0.0", port);
   send_T_messages_txt(f);
-
   new_thread(data_sender, f);
   new_thread(forward_remote_messages, f);
-
   return f;
 }
 
-static void forward(void *_forwarder, char *buf, int size)
-{
+static void forward(void *_forwarder, char *buf, int size) {
   forward_data *f = _forwarder;
   int32_t ssize = size;
   databuf *new;
+  new = malloc(sizeof(*new));
 
-  new = malloc(sizeof(*new)); if (new == NULL) abort();
+  if (new == NULL) abort();
 
   if (pthread_mutex_lock(&f->lock)) abort();
 
-  new->d = malloc(size + 4); if (new->d == NULL) abort();
+  new->d = malloc(size + 4);
+
+  if (new->d == NULL) abort();
+
   /* put the size of the message at the head */
   memcpy(new->d, &ssize, 4);
   memcpy(new->d+4, buf, size);
   new->l = size+4;
   new->next = NULL;
+
   if (f->head == NULL) f->head = new;
+
   if (f->tail != NULL) f->tail->next = new;
-  f->tail = new;
 
+  f->tail = new;
 #if BASIC_SIMULATOR
+
   /* When runnng the basic simulator, the tracer may be too slow.
    * Let's not take too much memory in the tracee and
    * wait if there is too much data to send. 200MB is
@@ -308,26 +366,30 @@ static void forward(void *_forwarder, char *buf, int size)
    */
   while (f->memusage > 200 * 1024 * 1024) {
     if (pthread_cond_signal(&f->cond)) abort();
+
     if (pthread_mutex_unlock(&f->lock)) abort();
+
     usleep(1000);
+
     if (pthread_mutex_lock(&f->lock)) abort();
   }
-#endif /* BASIC_SIMULATOR */
 
+#endif /* BASIC_SIMULATOR */
   f->memusage += size+4;
+
   /* warn every 100MB */
   if (f->memusage > f->last_warning_memusage &&
       f->memusage - f->last_warning_memusage > 100000000) {
     f->last_warning_memusage += 100000000;
     printf("T tracer: WARNING: memory usage is over %"PRIu64"MB\n",
            f->last_warning_memusage / 1000000);
-  } else
-  if (f->memusage < f->last_warning_memusage &&
-      f->last_warning_memusage - f->memusage > 100000000) {
+  } else if (f->memusage < f->last_warning_memusage &&
+             f->last_warning_memusage - f->memusage > 100000000) {
     f->last_warning_memusage = (f->memusage/100000000) * 100000000;
   }
 
   if (pthread_cond_signal(&f->cond)) abort();
+
   if (pthread_mutex_unlock(&f->lock)) abort();
 }
 
@@ -335,14 +397,12 @@ static void forward(void *_forwarder, char *buf, int size)
 /*                      local functions                                     */
 /****************************************************************************/
 
-static void wait_message(void)
-{
+static void wait_message(void) {
   while ((T_local_cache[T_busylist_head].busy & 0x02) == 0) usleep(1000);
 }
 
 void T_local_tracer_main(int remote_port, int wait_for_tracer,
-    int local_socket, void *shm_array)
-{
+                         int local_socket, void *shm_array) {
   int s;
   int port = remote_port;
   int dont_wait = wait_for_tracer ? 0 : 1;
@@ -350,16 +410,16 @@ void T_local_tracer_main(int remote_port, int wait_for_tracer,
 
   /* write on a socket fails if the other end is closed and we get SIGPIPE */
   if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
-       printf("local tracer received SIGPIPE\n");
-       abort();
+    printf("local tracer received SIGPIPE\n");
+    abort();
   }
 
   T_local_cache = shm_array;
-
   s = local_socket;
 
   if (dont_wait) {
     char t = 2;
+
     if (write(s, &t, 1) != 1) abort();
   }
 
diff --git a/common/utils/T/tracer/Makefile b/common/utils/T/tracer/Makefile
index 3da4aa13a17528cc1396f5eedc2e40eee91c2cb1..792c2a407c1ce1233ad8930396a86996020c2001 100644
--- a/common/utils/T/tracer/Makefile
+++ b/common/utils/T/tracer/Makefile
@@ -60,6 +60,11 @@ macpdu2wireshark: macpdu2wireshark.o database.o utils.o handler.o event.o \
 multi: multi.o utils.o database.o config.o
 	$(CC) $(CFLAGS) -o multi $^ $(LIBS)
 
+multi.o: ../T_IDs.h
+
+../T_IDs.h:
+	cd .. && $(MAKE)
+
 .PHONY: all gui/gui.a view/view.a logger/logger.a filter/filter.a
 
 gui/gui.a:
diff --git a/common/utils/T/tracer/extract.c b/common/utils/T/tracer/extract.c
index 2aec38831fe2c528cd12cbaa3814e75813eb3bfe..d66e8a3bb8517a82c985af61aebc46af012825d0 100644
--- a/common/utils/T/tracer/extract.c
+++ b/common/utils/T/tracer/extract.c
@@ -16,6 +16,8 @@ void usage(void)
 "    -f <name> <value>         field 'name' of 'event' has to match 'value'\n"
 "                              type of 'name' must be int\n"
 "                              (you can use several -f options)\n"
+"    -after <raw time> <nsec>  'event' time has to be greater than this\n"
+"    -count <n>                dump 'n' matching events (less if EOF reached)\n"
   );
   exit(1);
 }
@@ -51,6 +53,10 @@ int main(int n, char **v)
   int filter_count = 0;
   int buffer_arg;
   int found;
+  int count = 1;
+  int check_time = 0;
+  time_t sec;
+  long nsec;
 
   for (i = 1; i < n; i++) {
     if (!strcmp(v[i], "-h") || !strcmp(v[i], "--help")) usage();
@@ -63,6 +69,14 @@ int main(int n, char **v)
       filter_value[filter_count++] = atoi(v[++i]);
       continue;
     }
+    if (!strcmp(v[i], "-after")) { if (i>n-3) usage();
+      check_time = 1;
+      sec        = atoll(v[++i]);
+      nsec       = atol(v[++i]);
+      continue;
+    }
+    if (!strcmp(v[i], "-count"))
+      { if (i > n-2) usage(); count = atoi(v[++i]); continue; }
     if (file == NULL) { file = v[i]; continue; }
     if (event_name == NULL) { event_name = v[i]; continue; }
     if (buffer_name == NULL) { buffer_name = v[i]; continue; }
@@ -111,13 +125,20 @@ int main(int n, char **v)
         break;
     if (i != filter_count)
       continue;
+    if (check_time &&
+        !(e.sending_time.tv_sec > sec ||
+         (e.sending_time.tv_sec == sec && e.sending_time.tv_nsec >= nsec)))
+      continue;
     if (fwrite(e.e[buffer_arg].b, e.e[buffer_arg].bsize, 1, out) != 1)
       { perror(output_file); exit(1); }
-    found = 1;
-    break;
+    found++;
+    if (found == count)
+      break;
   }
 
   if (found == 0) printf("ERROR: event not found\n");
+  if (found != count)
+    printf("WARNING: dumped %d events (wanted %d)\n", found, count);
 
   fclose(out);
 
diff --git a/common/utils/T/tracer/gui/notify.c b/common/utils/T/tracer/gui/notify.c
index 7ff40069411a1bd9bae7d0106b686c41b04b6ef6..84fb161b6ee09421e20cb5231517fe9580dcc3d0 100644
--- a/common/utils/T/tracer/gui/notify.c
+++ b/common/utils/T/tracer/gui/notify.c
@@ -5,46 +5,41 @@
 #include <string.h>
 
 unsigned long register_notifier(gui *_g, char *notification, widget *w,
-    notifier handler, void *private)
-{
+                                notifier handler, void *private) {
   struct gui *g = _g;
   unsigned long ret;
-
   glock(g);
 
   if (g->next_notifier_id == 2UL * 1024 * 1024 * 1024)
     ERR("%s:%d: report a bug\n", __FILE__, __LINE__);
 
   g->notifiers = realloc(g->notifiers,
-      (g->notifiers_count+1) * sizeof(struct notifier));
+                         (g->notifiers_count+1) * sizeof(struct notifier));
+
   if (g->notifiers == NULL) abort();
 
   ret = g->next_notifier_id;
-
   g->notifiers[g->notifiers_count].handler = handler;
   g->notifiers[g->notifiers_count].id = g->next_notifier_id;
   g->next_notifier_id++;
   g->notifiers[g->notifiers_count].notification = strdup(notification);
+
   if (g->notifiers[g->notifiers_count].notification == NULL) abort();
+
   g->notifiers[g->notifiers_count].w = w;
   g->notifiers[g->notifiers_count].private = private;
   /* initialize done to 1 so as not to call the handler if it's created
    * by the call of another one that is in progress
    */
   g->notifiers[g->notifiers_count].done = 1;
-
   g->notifiers_count++;
-
   gunlock(g);
-
   return ret;
 }
 
-void unregister_notifier(gui *_g, unsigned long notifier_id)
-{
+void unregister_notifier(gui *_g, unsigned long notifier_id) {
   struct gui *g = _g;
   int i;
-
   glock(g);
 
   for (i = 0; i < g->notifiers_count; i++)
@@ -54,13 +49,12 @@ void unregister_notifier(gui *_g, unsigned long notifier_id)
     ERR("%s:%d: notifier_id %ld not found\n", __FILE__,__LINE__,notifier_id);
 
   free(g->notifiers[i].notification);
-
   memmove(g->notifiers + i, g->notifiers + i + 1,
-      (g->notifiers_count-1 - i) * sizeof(struct notifier));
-
+          (g->notifiers_count-1 - i) * sizeof(struct notifier));
   g->notifiers_count--;
   g->notifiers = realloc(g->notifiers,
-      g->notifiers_count * sizeof(struct notifier));
+                         g->notifiers_count * sizeof(struct notifier));
+
   if (g->notifiers == NULL) abort();
 
   gunlock(g);
@@ -68,19 +62,19 @@ void unregister_notifier(gui *_g, unsigned long notifier_id)
 
 /* called with lock ON */
 void gui_notify(struct gui *g, char *notification, widget *w,
-    void *notification_data)
-{
+                void *notification_data) {
   void *private;
   notifier handler;
   int i;
-
   /* this function is not re-entrant, for the moment keep as is
    * and if the need is there, we'll make a new thread to handle
    * notifications (or something)
    * for now let's crash in case of recursive call
    */
   static int inside = 0;
+
   if (inside) ERR("%s:%d: BUG! contact the authors\n", __FILE__, __LINE__);
+
   inside = 1;
 
   /* clear all handlers */
@@ -91,26 +85,25 @@ void gui_notify(struct gui *g, char *notification, widget *w,
    * need to be careful here
    */
 loop:
+
   for (i = 0; i < g->notifiers_count; i++) {
     if (g->notifiers[i].done == 1 ||
         g->notifiers[i].w != w    ||
         strcmp(g->notifiers[i].notification, notification) != 0)
       continue;
+
     break;
   }
+
   if (i == g->notifiers_count) goto done;
 
   g->notifiers[i].done = 1;
-
   handler = g->notifiers[i].handler;
   private = g->notifiers[i].private;
-
   gunlock(g);
   handler(private, g, notification, w, notification_data);
   glock(g);
-
   goto loop;
-
 done:
   inside = 0;
 }
diff --git a/common/utils/T/tracer/gui/x.c b/common/utils/T/tracer/gui/x.c
index ef5334767cb086044d34a4fd1f6f7e6210c8adab..71bd80545562a1f30a5e86f19222220d35313964 100644
--- a/common/utils/T/tracer/gui/x.c
+++ b/common/utils/T/tracer/gui/x.c
@@ -7,21 +7,19 @@
 #include <stdlib.h>
 #include <string.h>
 
-int x_connection_fd(x_connection *_x)
-{
+int x_connection_fd(x_connection *_x) {
   struct x_connection *x = _x;
   return ConnectionNumber(x->d);
 }
 
-static GC create_gc(Display *d, char *color)
-{
+static GC create_gc(Display *d, char *color) {
   GC ret = XCreateGC(d, DefaultRootWindow(d), 0, NULL);
   XGCValues gcv;
   XColor rcol, scol;
-
   XCopyGC(d, DefaultGC(d, DefaultScreen(d)), -1L, ret);
+
   if (XAllocNamedColor(d, DefaultColormap(d, DefaultScreen(d)),
-                      color, &scol, &rcol)) {
+                       color, &scol, &rcol)) {
     gcv.foreground = scol.pixel;
     XChangeGC(d, ret, GCForeground, &gcv);
   } else ERR("X: could not allocate color '%s'\n", color);
@@ -29,82 +27,81 @@ static GC create_gc(Display *d, char *color)
   return ret;
 }
 
-int x_new_color(x_connection *_x, char *color)
-{
+int x_new_color(x_connection *_x, char *color) {
   struct x_connection *x = _x;
   x->ncolors++;
-
   x->colors = realloc(x->colors, x->ncolors * sizeof(GC));
+
   if (x->colors == NULL) OOM;
-  x->colors[x->ncolors-1] = create_gc(x->d, color);
 
+  x->colors[x->ncolors-1] = create_gc(x->d, color);
   x->xft_colors = realloc(x->xft_colors, x->ncolors * sizeof(XftColor));
+
   if (x->xft_colors == NULL) OOM;
+
   if (XftColorAllocName(x->d, DefaultVisual(x->d, DefaultScreen(x->d)),
-      DefaultColormap(x->d, DefaultScreen(x->d)),
-      color, &x->xft_colors[x->ncolors-1]) == False)
+                        DefaultColormap(x->d, DefaultScreen(x->d)),
+                        color, &x->xft_colors[x->ncolors-1]) == False)
     ERR("could not allocate color '%s'\n", color);
 
   return x->ncolors - 1;
 }
 
-int x_new_font(x_connection *_x, char *font)
-{
+int x_new_font(x_connection *_x, char *font) {
   struct x_connection *x = _x;
   /* TODO: allocate fonts only once */
   x->nfonts++;
   x->fonts = realloc(x->fonts, x->nfonts * sizeof(XftFont *));
+
   if (x->fonts == NULL) OOM;
+
   x->fonts[x->nfonts-1] = XftFontOpenName(x->d, DefaultScreen(x->d), font);
+
   if (x->fonts[x->nfonts-1] == NULL)
     ERR("failed allocating font '%s'\n", font);
+
   return x->nfonts - 1;
 }
 
-x_connection *x_open(void)
-{
+x_connection *x_open(void) {
   struct x_connection *ret;
-
   ret = calloc(1, sizeof(struct x_connection));
+
   if (ret == NULL) OOM;
 
   ret->d = XOpenDisplay(0);
   LOGD("XOpenDisplay display %p return x_connection %p\n", ret->d, ret);
+
   if (ret->d == NULL) ERR("error calling XOpenDisplay: no X? you root?\n");
 
   x_new_color(ret, "white");    /* background color */
   x_new_color(ret, "black");    /* foreground color */
-
   x_new_font(ret, "sans-8");
-
   return ret;
 }
 
 x_window *x_create_window(x_connection *_x, int width, int height,
-    char *title)
-{
+                          char *title) {
   struct x_connection *x = _x;
   struct x_window *ret;
-
   ret = calloc(1, sizeof(struct x_window));
+
   if (ret == NULL) OOM;
 
   ret->w = XCreateSimpleWindow(x->d, DefaultRootWindow(x->d), 0, 0,
-      width, height, 0, WhitePixel(x->d, DefaultScreen(x->d)),
-      WhitePixel(x->d, DefaultScreen(x->d)));
+                               width, height, 0, WhitePixel(x->d, DefaultScreen(x->d)),
+                               WhitePixel(x->d, DefaultScreen(x->d)));
   ret->width = width;
   ret->height = height;
-
   XStoreName(x->d, ret->w, title);
-
   ret->p = XCreatePixmap(x->d, ret->w, width, height,
-      DefaultDepth(x->d, DefaultScreen(x->d)));
+                         DefaultDepth(x->d, DefaultScreen(x->d)));
   XFillRectangle(x->d, ret->p, x->colors[BACKGROUND_COLOR],
-      0, 0, width, height);
-
+                 0, 0, width, height);
   ret->xft = XftDrawCreate(x->d, ret->p,
-      DefaultVisual(x->d, DefaultScreen(x->d)),
-      DefaultColormap(x->d, DefaultScreen(x->d)));
+                           DefaultVisual(x->d, DefaultScreen(x->d)),
+                           DefaultColormap(x->d, DefaultScreen(x->d)));
+
   if (ret->xft == NULL) ERR("XftDrawCreate failed\n");
 
   /* enable backing store */
@@ -113,23 +110,19 @@ x_window *x_create_window(x_connection *_x, int width, int height,
     att.backing_store = Always;
     XChangeWindowAttributes(x->d, ret->w, CWBackingStore, &att);
   }
-
   XSelectInput(x->d, ret->w,
-      KeyPressMask      |
-      ButtonPressMask   |
-      ButtonReleaseMask |
-      PointerMotionMask |
-      ExposureMask      |
-      StructureNotifyMask);
-
+               KeyPressMask      |
+               ButtonPressMask   |
+               ButtonReleaseMask |
+               PointerMotionMask |
+               ExposureMask      |
+               StructureNotifyMask);
   XMapWindow(x->d, ret->w);
-
   return ret;
 }
 
 x_image *x_create_image(x_connection *_x, unsigned char *data,
-    int width, int height)
-{
+                        int width, int height) {
   struct x_connection *x = _x;
   struct x_image *ret;
   XImage *ximage;
@@ -137,8 +130,9 @@ x_image *x_create_image(x_connection *_x, unsigned char *data,
   XVisualInfo template;
   int nvs;
   Visual *v;
+  ret = calloc(1, sizeof(struct x_image));
 
-  ret = calloc(1, sizeof(struct x_image)); if (ret == NULL) OOM;
+  if (ret == NULL) OOM;
 
   template.class = TrueColor;
   template.depth = 24;
@@ -146,68 +140,65 @@ x_image *x_create_image(x_connection *_x, unsigned char *data,
   template.green_mask = 0x00ff00;
   template.blue_mask = 0x0000ff;
   template.bits_per_rgb = 8;
-
   vs = XGetVisualInfo(x->d, VisualDepthMask | VisualClassMask |
-      VisualRedMaskMask | VisualGreenMaskMask | VisualBlueMaskMask |
-      VisualBitsPerRGBMask, &template, &nvs);
+                      VisualRedMaskMask | VisualGreenMaskMask | VisualBlueMaskMask |
+                      VisualBitsPerRGBMask, &template, &nvs);
 
   if (vs == NULL) {
     /* try again with 32 bpp */
     template.depth = 32;
     vs = XGetVisualInfo(x->d, VisualDepthMask | VisualClassMask |
-        VisualRedMaskMask | VisualGreenMaskMask | VisualBlueMaskMask |
-        VisualBitsPerRGBMask, &template, &nvs);
+                        VisualRedMaskMask | VisualGreenMaskMask | VisualBlueMaskMask |
+                        VisualBitsPerRGBMask, &template, &nvs);
   }
 
   if (vs == NULL) ERR("no good visual found\n");
 
   v = vs[0].visual;
   XFree(vs);
-
   ximage = XCreateImage(x->d, v, 24, ZPixmap, 0,
-      (char*)data, width, height, 32, 0);
+                        (char *)data, width, height, 32, 0);
+
   if (ximage == NULL) ERR("image creation failed\n");
 
   ret->p = XCreatePixmap(x->d, DefaultRootWindow(x->d), width, height, 24);
-
   XPutImage(x->d, ret->p, DefaultGC(x->d, DefaultScreen(x->d)),
-      ximage, 0, 0, 0, 0, width, height);
-
+            ximage, 0, 0, 0, 0, width, height);
   /* TODO: be sure it's fine to set data to NULL */
   ximage->data = NULL;
   XDestroyImage(ximage);
-
   ret->width = width;
   ret->height = height;
-
   return ret;
 }
 
-static struct toplevel_window_widget *find_x_window(struct gui *g, Window id)
-{
+static struct toplevel_window_widget *find_x_window(struct gui *g, Window id) {
   struct widget_list *cur;
   struct toplevel_window_widget *w;
   struct x_window *xw;
   cur = g->toplevel;
+
   while (cur) {
     w = (struct toplevel_window_widget *)cur->item;
     xw = w->x;
+
     if (xw->w == id) return w;
+
     cur = cur->next;
   }
+
   return NULL;
 }
 
-void x_events(gui *_gui)
-{
+void x_events(gui *_gui) {
   struct gui *g = _gui;
   struct widget_list *cur;
   struct x_connection *x = g->x;
   struct toplevel_window_widget *w;
-
   LOGD("x_events START\n");
   /* preprocessing (to "compress" events) */
   cur = g->toplevel;
+
   while (cur) {
     struct x_window *xw;
     w = (struct toplevel_window_widget *)cur->item;
@@ -222,58 +213,84 @@ void x_events(gui *_gui)
     XEvent ev;
     XNextEvent(x->d, &ev);
     LOGD("XEV %d\n", ev.type);
+
     switch (ev.type) {
-    case MapNotify:
-    case Expose:
-      if ((w = find_x_window(g, ev.xexpose.window)) != NULL) {
-        struct x_window *xw = w->x;
-        xw->redraw = 1;
-      }
-      break;
-    case ConfigureNotify:
-      if ((w = find_x_window(g, ev.xconfigure.window)) != NULL) {
-        struct x_window *xw = w->x;
-        xw->resize = 1;
-        xw->new_width = ev.xconfigure.width;
-        xw->new_height = ev.xconfigure.height;
-        if (xw->new_width < 10) xw->new_width = 10;
-        if (xw->new_height < 10) xw->new_height = 10;
-        LOGD("ConfigureNotify %d %d\n", ev.xconfigure.width, ev.xconfigure.height);
-      }
-      break;
-    case ButtonPress:
-      if ((w = find_x_window(g, ev.xbutton.window)) != NULL) {
-        int key_modifiers = 0;
-        if (ev.xbutton.state & ShiftMask)   key_modifiers |= KEY_SHIFT;
-        if (ev.xbutton.state & Mod1Mask)    key_modifiers |= KEY_ALT;
-        if (ev.xbutton.state & ControlMask) key_modifiers |= KEY_CONTROL;
-        w->common.button(g, w, ev.xbutton.x, ev.xbutton.y, key_modifiers,
-            ev.xbutton.button, 0);
-      }
-      break;
-    case ButtonRelease:
-      if ((w = find_x_window(g, ev.xbutton.window)) != NULL) {
-        int key_modifiers = 0;
-        if (ev.xbutton.state & ShiftMask)   key_modifiers |= KEY_SHIFT;
-        if (ev.xbutton.state & Mod1Mask)    key_modifiers |= KEY_ALT;
-        if (ev.xbutton.state & ControlMask) key_modifiers |= KEY_CONTROL;
-        w->common.button(g, w, ev.xbutton.x, ev.xbutton.y, key_modifiers,
-            ev.xbutton.button, 1);
-      }
-      break;
-    default: if (gui_logd) WARN("TODO: X event type %d\n", ev.type); break;
+      case MapNotify:
+      case Expose:
+        if ((w = find_x_window(g, ev.xexpose.window)) != NULL) {
+          struct x_window *xw = w->x;
+          xw->redraw = 1;
+        }
+
+        break;
+
+      case ConfigureNotify:
+        if ((w = find_x_window(g, ev.xconfigure.window)) != NULL) {
+          struct x_window *xw = w->x;
+          xw->resize = 1;
+          xw->new_width = ev.xconfigure.width;
+          xw->new_height = ev.xconfigure.height;
+
+          if (xw->new_width < 10) xw->new_width = 10;
+
+          if (xw->new_height < 10) xw->new_height = 10;
+
+          LOGD("ConfigureNotify %d %d\n", ev.xconfigure.width, ev.xconfigure.height);
+        }
+
+        break;
+
+      case ButtonPress:
+        if ((w = find_x_window(g, ev.xbutton.window)) != NULL) {
+          int key_modifiers = 0;
+
+          if (ev.xbutton.state & ShiftMask)   key_modifiers |= KEY_SHIFT;
+
+          if (ev.xbutton.state & Mod1Mask)    key_modifiers |= KEY_ALT;
+
+          if (ev.xbutton.state & ControlMask) key_modifiers |= KEY_CONTROL;
+
+          w->common.button(g, w, ev.xbutton.x, ev.xbutton.y, key_modifiers,
+                           ev.xbutton.button, 0);
+        }
+
+        break;
+
+      case ButtonRelease:
+        if ((w = find_x_window(g, ev.xbutton.window)) != NULL) {
+          int key_modifiers = 0;
+
+          if (ev.xbutton.state & ShiftMask)   key_modifiers |= KEY_SHIFT;
+
+          if (ev.xbutton.state & Mod1Mask)    key_modifiers |= KEY_ALT;
+
+          if (ev.xbutton.state & ControlMask) key_modifiers |= KEY_CONTROL;
+
+          w->common.button(g, w, ev.xbutton.x, ev.xbutton.y, key_modifiers,
+                           ev.xbutton.button, 1);
+        }
+
+        break;
+
+      default:
+        if (gui_logd) WARN("TODO: X event type %d\n", ev.type);
+
+        break;
     }
   }
 
   /* postprocessing */
   LOGD("post processing\n");
   cur = g->toplevel;
+
   while (cur) {
     struct toplevel_window_widget *w =
-        (struct toplevel_window_widget *)cur->item;
+      (struct toplevel_window_widget *)cur->item;
     struct x_window *xw = w->x;
+
     if (xw->resize) {
       LOGD("resize old %d %d new %d %d\n", xw->width, xw->height, xw->new_width, xw->new_height);
+
       if (xw->width != xw->new_width || xw->height != xw->new_height) {
         w->common.allocate(g, w, 0, 0, xw->new_width, xw->new_height);
         xw->width = xw->new_width;
@@ -281,46 +298,47 @@ void x_events(gui *_gui)
         XftDrawDestroy(xw->xft);
         XFreePixmap(x->d, xw->p);
         xw->p = XCreatePixmap(x->d, xw->w, xw->width, xw->height,
-            DefaultDepth(x->d, DefaultScreen(x->d)));
+                              DefaultDepth(x->d, DefaultScreen(x->d)));
         XFillRectangle(x->d, xw->p, x->colors[BACKGROUND_COLOR],
-            0, 0, xw->width, xw->height);
+                       0, 0, xw->width, xw->height);
         xw->xft = XftDrawCreate(x->d, xw->p,
-            DefaultVisual(x->d, DefaultScreen(x->d)),
-            DefaultColormap(x->d, DefaultScreen(x->d)));
+                                DefaultVisual(x->d, DefaultScreen(x->d)),
+                                DefaultColormap(x->d, DefaultScreen(x->d)));
+
         if (xw->xft == NULL) ERR("XftDrawCreate failed\n");
 
         //xw->repaint = 1;
       }
     }
+
     if (xw->repaint) {
       w->common.paint(g, w);
       xw->redraw = 1;
     }
+
     if (xw->redraw) {
       struct x_connection *x = g->x;
       LOGD("XCopyArea w h %d %d\n", xw->width, xw->height);
       XCopyArea(x->d, xw->p, xw->w, x->colors[1],
-          0, 0, xw->width, xw->height, 0, 0);
+                0, 0, xw->width, xw->height, 0, 0);
     }
+
     cur = cur->next;
   }
+
   LOGD("x_events DONE\n");
 }
 
-void x_flush(x_connection *_x)
-{
+void x_flush(x_connection *_x) {
   struct x_connection *x = _x;
   XFlush(x->d);
 }
 
 void x_text_get_dimensions(x_connection *_c, int font, const char *t,
-    int *width, int *height, int *baseline)
-{
+                           int *width, int *height, int *baseline) {
   struct x_connection *c = _c;
   XGlyphInfo ext;
-
   XftTextExtentsUtf8(c->d, c->fonts[font], (FcChar8 *)t, strlen(t), &ext);
-
   *width = ext.width;
   *height = c->fonts[font]->height;
   *baseline = c->fonts[font]->ascent;
@@ -331,63 +349,57 @@ void x_text_get_dimensions(x_connection *_c, int font, const char *t,
 /***********************************************************************/
 
 void x_draw_line(x_connection *_c, x_window *_w, int color,
-    int x1, int y1, int x2, int y2)
-{
+                 int x1, int y1, int x2, int y2) {
   struct x_connection *c = _c;
   struct x_window *w = _w;
   XDrawLine(c->d, w->p, c->colors[color], x1, y1, x2, y2);
 }
 
 void x_draw_rectangle(x_connection *_c, x_window *_w, int color,
-    int x, int y, int width, int height)
-{
+                      int x, int y, int width, int height) {
   struct x_connection *c = _c;
   struct x_window *w = _w;
   XDrawRectangle(c->d, w->p, c->colors[color], x, y, width, height);
 }
 
 void x_fill_rectangle(x_connection *_c, x_window *_w, int color,
-    int x, int y, int width, int height)
-{
+                      int x, int y, int width, int height) {
   struct x_connection *c = _c;
   struct x_window *w = _w;
   XFillRectangle(c->d, w->p, c->colors[color], x, y, width, height);
 }
 
 void x_draw_string(x_connection *_c, x_window *_w, int font, int color,
-    int x, int y, const char *t)
-{
+                   int x, int y, const char *t) {
   struct x_connection *c = _c;
   struct x_window *w = _w;
   int tlen = strlen(t);
   XftDrawStringUtf8(w->xft, &c->xft_colors[color], c->fonts[font],
-      x, y, (const unsigned char *)t, tlen);
+                    x, y, (const unsigned char *)t, tlen);
 }
 
 void x_draw_clipped_string(x_connection *_c, x_window *_w, int font,
-    int color, int x, int y, const char *t,
-    int clipx, int clipy, int clipwidth, int clipheight)
-{
+                           int color, int x, int y, const char *t,
+                           int clipx, int clipy, int clipwidth, int clipheight) {
   struct x_window *w = _w;
-
   XRectangle clip = { clipx, clipy, clipwidth, clipheight };
+
   if (XftDrawSetClipRectangles(w->xft, 0, 0, &clip, 1) == False) abort();
+
   x_draw_string(_c, _w, font, color, x, y, t);
+
   if (XftDrawSetClip(w->xft, NULL) == False) abort();
 }
 
-void x_draw_image(x_connection *_c, x_window *_w, x_image *_img, int x, int y)
-{
+void x_draw_image(x_connection *_c, x_window *_w, x_image *_img, int x, int y) {
   struct x_connection *c = _c;
   struct x_window *w = _w;
   struct x_image *img = _img;
-
   XCopyArea(c->d, img->p, w->p, DefaultGC(c->d, DefaultScreen(c->d)),
-      0, 0, img->width, img->height, x, y);
+            0, 0, img->width, img->height, x, y);
 }
 
-void x_draw(x_connection *_c, x_window *_w)
-{
+void x_draw(x_connection *_c, x_window *_w) {
   struct x_connection *c = _c;
   struct x_window *w = _w;
   LOGD("x_draw XCopyArea w h %d %d display %p window %d pixmap %d\n", w->width, w->height, c->d, (int)w->w, (int)w->p);
@@ -397,13 +409,13 @@ void x_draw(x_connection *_c, x_window *_w)
 /* those two special functions are to plot many points
  * first call x_add_point many times then x_plot_points once
  */
-void x_add_point(x_connection *_c, int x, int y)
-{
+void x_add_point(x_connection *_c, int x, int y) {
   struct x_connection *c = _c;
 
   if (c->pts_size == c->pts_maxsize) {
     c->pts_maxsize += 65536;
     c->pts = realloc(c->pts, c->pts_maxsize * sizeof(XPoint));
+
     if (c->pts == NULL) OOM;
   }
 
@@ -412,12 +424,11 @@ void x_add_point(x_connection *_c, int x, int y)
   c->pts_size++;
 }
 
-void x_plot_points(x_connection *_c, x_window *_w, int color)
-{
+void x_plot_points(x_connection *_c, x_window *_w, int color) {
   struct x_connection *c = _c;
   LOGD("x_plot_points %d points\n", c->pts_size);
   struct x_window *w = _w;
   XDrawPoints(c->d, w->p, c->colors[color], c->pts, c->pts_size,
-      CoordModeOrigin);
+              CoordModeOrigin);
   c->pts_size = 0;
 }
diff --git a/common/utils/T/tracer/hacks/dump_nack_signal.c b/common/utils/T/tracer/hacks/dump_nack_signal.c
index bb8f1a9477bda7894ba8465a068b2825db5e6737..02825202fb14544eb3074da8fdb0dbe1c5323cf6 100644
--- a/common/utils/T/tracer/hacks/dump_nack_signal.c
+++ b/common/utils/T/tracer/hacks/dump_nack_signal.c
@@ -7,21 +7,19 @@
 #include "config.h"
 #include "../T_defs.h"
 
-void usage(void)
-{
+void usage(void) {
   printf(
-"options:\n"
-"    -d <database file>        this option is mandatory\n"
-"    -ip <host>                connect to given IP address (default %s)\n"
-"    -p <port>                 connect to given port (default %d)\n",
-  DEFAULT_REMOTE_IP,
-  DEFAULT_REMOTE_PORT
+    "options:\n"
+    "    -d <database file>        this option is mandatory\n"
+    "    -ip <host>                connect to given IP address (default %s)\n"
+    "    -p <port>                 connect to given port (default %d)\n",
+    DEFAULT_REMOTE_IP,
+    DEFAULT_REMOTE_PORT
   );
   exit(1);
 }
 
-int main(int n, char **v)
-{
+int main(int n, char **v) {
   char *database_filename = NULL;
   void *database;
   char *ip = DEFAULT_REMOTE_IP;
@@ -36,11 +34,28 @@ int main(int n, char **v)
 
   for (i = 1; i < n; i++) {
     if (!strcmp(v[i], "-h") || !strcmp(v[i], "--help")) usage();
-    if (!strcmp(v[i], "-d"))
-      { if (i > n-2) usage(); database_filename = v[++i]; continue; }
-    if (!strcmp(v[i], "-ip")) { if (i > n-2) usage(); ip = v[++i]; continue; }
-    if (!strcmp(v[i], "-p"))
-      { if (i > n-2) usage(); port = atoi(v[++i]); continue; }
+
+    if (!strcmp(v[i], "-d")) {
+      if (i > n-2) usage();
+
+      database_filename = v[++i];
+      continue;
+    }
+
+    if (!strcmp(v[i], "-ip")) {
+      if (i > n-2) usage();
+
+      ip = v[++i];
+      continue;
+    }
+
+    if (!strcmp(v[i], "-p")) {
+      if (i > n-2) usage();
+
+      port = atoi(v[++i]);
+      continue;
+    }
+
     usage();
   }
 
@@ -50,71 +65,92 @@ int main(int n, char **v)
   }
 
   database = parse_database(database_filename);
-
   load_config_file(database_filename);
-
   number_of_events = number_of_ids(database);
   is_on = calloc(number_of_events, sizeof(int));
+
   if (is_on == NULL) abort();
 
   on_off(database, "ENB_PHY_INPUT_SIGNAL", is_on, 1);
   on_off(database, "ENB_PHY_ULSCH_UE_NACK", is_on, 1);
   on_off(database, "ENB_PHY_ULSCH_UE_ACK", is_on, 1);
-
   ev_input = event_id_from_name(database, "ENB_PHY_INPUT_SIGNAL");
   ev_nack = event_id_from_name(database, "ENB_PHY_ULSCH_UE_NACK");
   ev_ack = event_id_from_name(database, "ENB_PHY_ULSCH_UE_ACK");
-
   socket = connect_to(ip, port);
-
   t = 1;
+
   if (socket_send(socket, &t, 1) == -1 ||
       socket_send(socket, &number_of_events, sizeof(int)) == -1 ||
       socket_send(socket, is_on, number_of_events * sizeof(int)) == -1)
     abort();
 
   OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL };
-
   char dump[10][T_BUFFER_MAX];
   event dump_ev[10];
-FILE *z = fopen("/tmp/dd", "w"); if (z == NULL) abort();
+  FILE *z = fopen("/tmp/dd", "w");
+
+  if (z == NULL) abort();
+
   while (1) {
     char *v;
     event e;
     e = get_event(socket, &ebuf, database);
     v = ebuf.obuf;
+
     if (e.type == -1) break;
+
     if (e.type == ev_input) {
       int sf = e.e[2].i;
-      if (ebuf.osize > T_BUFFER_MAX)
-        { printf("event size too big\n"); exit(1); }
+
+      if (ebuf.osize > T_BUFFER_MAX) {
+        printf("event size too big\n");
+        exit(1);
+      }
+
       memcpy(dump[sf], ebuf.obuf, ebuf.osize);
       dump_ev[sf] = e;
       printf("input %d/%d\n", e.e[1].i, sf);
-if (fwrite(dump_ev[sf].e[4].b, dump_ev[sf].e[4].bsize, 1, z) != 1) abort();
-fflush(z);
+
+      if (fwrite(dump_ev[sf].e[4].b, dump_ev[sf].e[4].bsize, 1, z) != 1) abort();
+
+      fflush(z);
     }
+
     if (e.type == ev_nack) {
       int sf = e.e[2].i;
       printf("nack %d/%d\n", e.e[1].i, sf);
-      FILE *f = fopen("/tmp/dump.raw", "w"); if (f == NULL) abort();
+      FILE *f = fopen("/tmp/dump.raw", "w");
+
+      if (f == NULL) abort();
+
       if (fwrite(dump[sf] + ((char *)dump_ev[sf].e[4].b - v),
-          dump_ev[sf].e[4].bsize, 1, f) != 1) abort();
+                 dump_ev[sf].e[4].bsize, 1, f) != 1) abort();
+
       if (fclose(f)) abort();
+
       printf("dumped... press enter (delta %d)\n", (int)((char *)dump_ev[sf].e[4].b - v));
-//      getchar();
+      //      getchar();
     }
+
     if (e.type == ev_ack) {
       int sf = e.e[2].i;
       printf("ack %d/%d\n", e.e[1].i, sf);
-      FILE *f = fopen("/tmp/dump.raw", "w"); if (f == NULL) abort();
+      FILE *f = fopen("/tmp/dump.raw", "w");
+
+      if (f == NULL) abort();
+
       if (fwrite(dump[sf] + ((char *)dump_ev[sf].e[4].b - v),
-          dump_ev[sf].e[4].bsize, 1, f) != 1) abort();
+                 dump_ev[sf].e[4].bsize, 1, f) != 1) abort();
+
       if (fclose(f)) abort();
+
       printf("dumped... press enter (delta %d)\n", (int)((char *)dump_ev[sf].e[4].b - v));
-//      getchar();
+      //      getchar();
     }
   }
+  if (z)
+    fclose(z);
 
   return 0;
 }
diff --git a/common/utils/T/tracer/logger/logger.h b/common/utils/T/tracer/logger/logger.h
index 434cf5a90fee02a4c97d33ddcab26e5f484b193c..7c019b4797244b5edc4a8120cc551392f52b09fb 100644
--- a/common/utils/T/tracer/logger/logger.h
+++ b/common/utils/T/tracer/logger/logger.h
@@ -30,6 +30,7 @@ void framelog_set_skip(logger *_this, int skip_delay);
 void framelog_set_update_only_at_sf9(logger *_this, int update_only_at_sf9);
 
 void textlog_dump_buffer(logger *_this, int dump_buffer);
+void textlog_raw_time(logger *_this, int raw_time);
 
 #include "view/view.h"
 
diff --git a/common/utils/T/tracer/logger/textlog.c b/common/utils/T/tracer/logger/textlog.c
index 9eb6fd02d8fbbec5d63702c4b89d80df2327fe92..76f920e1e2e96bb0b68971ce9826b78a7e441c3f 100644
--- a/common/utils/T/tracer/logger/textlog.c
+++ b/common/utils/T/tracer/logger/textlog.c
@@ -33,6 +33,7 @@ struct textlog {
   /* local output buffer */
   OBUF o;
   int dump_buffer;
+  int raw_time;
 };
 
 static void _event(void *p, event e)
@@ -51,9 +52,13 @@ static void _event(void *p, event e)
 
 #ifdef T_SEND_TIME
   t = localtime(&e.sending_time.tv_sec);
-  /* round tv_nsec to nearest millisecond */
-  sprintf(tt, "%2.2d:%2.2d:%2.2d.%9.9ld: ", t->tm_hour, t->tm_min, t->tm_sec,
-      e.sending_time.tv_nsec);
+  if (l->raw_time)
+    sprintf(tt, "%2.2d:%2.2d:%2.2d.%9.9ld [%ld]: ",
+        t->tm_hour, t->tm_min, t->tm_sec,
+        e.sending_time.tv_nsec, e.sending_time.tv_sec);
+  else
+    sprintf(tt, "%2.2d:%2.2d:%2.2d.%9.9ld: ", t->tm_hour, t->tm_min, t->tm_sec,
+        e.sending_time.tv_nsec);
   PUTS(&l->o, tt);
 #endif
 
@@ -215,3 +220,9 @@ void textlog_dump_buffer(logger *_this, int dump_buffer)
   struct textlog *l = _this;
   l->dump_buffer = dump_buffer;
 }
+
+void textlog_raw_time(logger *_this, int raw_time)
+{
+  struct textlog *l = _this;
+  l->raw_time = raw_time;
+}
diff --git a/common/utils/T/tracer/macpdu2wireshark.c b/common/utils/T/tracer/macpdu2wireshark.c
index 954f668aa420c0cd0070f58757df721727199e2a..7ea3b70bb40340d2305b9f39d0e0e9fdfda1b9e9 100644
--- a/common/utils/T/tracer/macpdu2wireshark.c
+++ b/common/utils/T/tracer/macpdu2wireshark.c
@@ -14,6 +14,11 @@
 #define DEFAULT_IP   "127.0.0.1"
 #define DEFAULT_PORT 9999
 
+#define DEFAULT_LIVE_IP   "127.0.0.1"
+#define DEFAULT_LIVE_PORT 2021
+
+#define NO_PREAMBLE -1
+
 typedef struct {
   int socket;
   struct sockaddr_in to;
@@ -28,142 +33,241 @@ typedef struct {
   int dl_frame;
   int dl_subframe;
   int dl_data;
+  /* mib */
+  int mib_frame;
+  int mib_subframe;
+  int mib_data;
+  /* RA preamble */
+  int preamble_frame;
+  int preamble_subframe;
+  int preamble_preamble;
+  /* RAR */
+  int rar_rnti;
+  int rar_frame;
+  int rar_subframe;
+  int rar_data;
+  /* config */
+  int no_mib;
+  int no_sib;
+  int max_mib;
+  int max_sib;
+  int live;
+  /* runtime vars */
+  int cur_mib;
+  int cur_sib;
 } ev_data;
 
-void ul(void *_d, event e)
-{
-  ev_data *d = _d;
+void trace(ev_data *d, int direction, int rnti_type, int rnti,
+           int frame, int subframe, void *buf, int bufsize, int preamble) {
   ssize_t ret;
   int fsf;
   int i;
-
   d->buf.osize = 0;
-
   PUTS(&d->buf, MAC_LTE_START_STRING);
   PUTC(&d->buf, FDD_RADIO);
-  PUTC(&d->buf, DIRECTION_UPLINK);
-  PUTC(&d->buf, C_RNTI);
+  PUTC(&d->buf, direction);
+  PUTC(&d->buf, rnti_type);
 
-  PUTC(&d->buf, MAC_LTE_RNTI_TAG);
-  PUTC(&d->buf, (e.e[d->ul_rnti].i>>8) & 255);
-  PUTC(&d->buf, e.e[d->ul_rnti].i & 255);
+  if (rnti_type == C_RNTI || rnti_type == RA_RNTI) {
+    PUTC(&d->buf, MAC_LTE_RNTI_TAG);
+    PUTC(&d->buf, (rnti>>8) & 255);
+    PUTC(&d->buf, rnti & 255);
+  }
 
   /* for newer version of wireshark? */
-  fsf = (e.e[d->ul_frame].i << 4) + e.e[d->ul_subframe].i;
+  fsf = (frame << 4) + subframe;
   /* for older version? */
-  fsf = e.e[d->ul_subframe].i;
+  //fsf = subframe;
   PUTC(&d->buf, MAC_LTE_FRAME_SUBFRAME_TAG);
   PUTC(&d->buf, (fsf>>8) & 255);
   PUTC(&d->buf, fsf & 255);
 
+  if (preamble != NO_PREAMBLE) {
+    PUTC(&d->buf, MAC_LTE_SEND_PREAMBLE_TAG);
+    PUTC(&d->buf, preamble);
+    PUTC(&d->buf, 0); /* rach attempt - always 0 for us (not sure of this) */
+  }
+
   PUTC(&d->buf, MAC_LTE_PAYLOAD_TAG);
-  for (i = 0; i < e.e[d->ul_data].bsize; i++)
-    PUTC(&d->buf, ((char*)e.e[d->ul_data].b)[i]);
+
+  for (i = 0; i < bufsize; i++)
+    PUTC(&d->buf, ((char *)buf)[i]);
 
   ret = sendto(d->socket, d->buf.obuf, d->buf.osize, 0,
-      (struct sockaddr *)&d->to, sizeof(struct sockaddr_in));
+               (struct sockaddr *)&d->to, sizeof(struct sockaddr_in));
+
   if (ret != d->buf.osize) abort();
 }
 
-void dl(void *_d, event e)
-{
+void ul(void *_d, event e) {
   ev_data *d = _d;
-  ssize_t ret;
-  int fsf;
-  int i;
-
-  d->buf.osize = 0;
+  trace(d, DIRECTION_UPLINK, C_RNTI, e.e[d->ul_rnti].i,
+        e.e[d->ul_frame].i, e.e[d->ul_subframe].i,
+        e.e[d->ul_data].b, e.e[d->ul_data].bsize,
+        NO_PREAMBLE);
+}
 
-  PUTS(&d->buf, MAC_LTE_START_STRING);
-  PUTC(&d->buf, FDD_RADIO);
-  PUTC(&d->buf, DIRECTION_DOWNLINK);
-  PUTC(&d->buf, C_RNTI);
+void dl(void *_d, event e) {
+  ev_data *d = _d;
 
-  PUTC(&d->buf, MAC_LTE_RNTI_TAG);
-  PUTC(&d->buf, (e.e[d->dl_rnti].i>>8) & 255);
-  PUTC(&d->buf, e.e[d->dl_rnti].i & 255);
+  if (e.e[d->dl_rnti].i == 0xffff) {
+    if (d->no_sib) return;
 
-  /* for newer version of wireshark? */
-  fsf = (e.e[d->dl_frame].i << 4) + e.e[d->dl_subframe].i;
-  /* for older version? */
-  fsf = e.e[d->dl_subframe].i;
-  PUTC(&d->buf, MAC_LTE_FRAME_SUBFRAME_TAG);
-  PUTC(&d->buf, (fsf>>8) & 255);
-  PUTC(&d->buf, fsf & 255);
+    if (d->max_sib && d->cur_sib == d->max_sib) return;
 
-  PUTC(&d->buf, MAC_LTE_PAYLOAD_TAG);
-  for (i = 0; i < e.e[d->dl_data].bsize; i++)
-    PUTC(&d->buf, ((char*)e.e[d->dl_data].b)[i]);
+    d->cur_sib++;
+  }
 
-  ret = sendto(d->socket, d->buf.obuf, d->buf.osize, 0,
-      (struct sockaddr *)&d->to, sizeof(struct sockaddr_in));
-  if (ret != d->buf.osize) abort();
+  trace(d, DIRECTION_DOWNLINK,
+        e.e[d->dl_rnti].i != 0xffff ? C_RNTI : SI_RNTI, e.e[d->dl_rnti].i,
+        e.e[d->dl_frame].i, e.e[d->dl_subframe].i,
+        e.e[d->dl_data].b, e.e[d->dl_data].bsize,
+        NO_PREAMBLE);
 }
 
-void setup_data(ev_data *d, void *database, int ul_id, int dl_id)
-{
-  database_event_format f;
-  int i;
+void mib(void *_d, event e) {
+  ev_data *d = _d;
 
-  d->ul_rnti     = -1;
-  d->ul_frame    = -1;
-  d->ul_subframe = -1;
-  d->ul_data     = -1;
+  if (d->no_mib) return;
 
-  d->dl_rnti     = -1;
-  d->dl_frame    = -1;
-  d->dl_subframe = -1;
-  d->dl_data     = -1;
+  if (d->max_mib && d->cur_mib == d->max_mib) return;
 
+  d->cur_mib++;
+  trace(d, DIRECTION_DOWNLINK, NO_RNTI, 0,
+        e.e[d->mib_frame].i, e.e[d->mib_subframe].i,
+        e.e[d->mib_data].b, e.e[d->mib_data].bsize,
+        NO_PREAMBLE);
+}
+
+void preamble(void *_d, event e) {
+  ev_data *d = _d;
+  trace(d, DIRECTION_UPLINK, NO_RNTI, 0,
+        e.e[d->preamble_frame].i, e.e[d->preamble_subframe].i,
+        NULL, 0,
+        e.e[d->preamble_preamble].i);
+}
+
+void rar(void *_d, event e) {
+  ev_data *d = _d;
+  trace(d, DIRECTION_DOWNLINK, RA_RNTI, e.e[d->rar_rnti].i,
+        e.e[d->rar_frame].i, e.e[d->rar_subframe].i,
+        e.e[d->rar_data].b, e.e[d->rar_data].bsize,
+        NO_PREAMBLE);
+}
+
+void setup_data(ev_data *d, void *database, int ul_id, int dl_id, int mib_id,
+                int preamble_id, int rar_id) {
+  database_event_format f;
+  int i;
+  d->ul_rnti           = -1;
+  d->ul_frame          = -1;
+  d->ul_subframe       = -1;
+  d->ul_data           = -1;
+  d->dl_rnti           = -1;
+  d->dl_frame          = -1;
+  d->dl_subframe       = -1;
+  d->dl_data           = -1;
+  d->mib_frame         = -1;
+  d->mib_subframe      = -1;
+  d->mib_data          = -1;
+  d->preamble_frame    = -1;
+  d->preamble_subframe = -1;
+  d->preamble_preamble = -1;
+  d->rar_rnti           = -1;
+  d->rar_frame          = -1;
+  d->rar_subframe       = -1;
+  d->rar_data           = -1;
 #define G(var_name, var_type, var) \
   if (!strcmp(f.name[i], var_name)) { \
     if (strcmp(f.type[i], var_type)) goto error; \
     var = i; \
     continue; \
   }
-
   /* ul: rnti, frame, subframe, data */
   f = get_format(database, ul_id);
+
   for (i = 0; i < f.count; i++) {
     G("rnti",     "int",    d->ul_rnti);
     G("frame",    "int",    d->ul_frame);
     G("subframe", "int",    d->ul_subframe);
     G("data",     "buffer", d->ul_data);
   }
+
   if (d->ul_rnti == -1 || d->ul_frame == -1 || d->ul_subframe == -1 ||
       d->ul_data == -1) goto error;
 
   /* dl: rnti, frame, subframe, data */
   f = get_format(database, dl_id);
+
   for (i = 0; i < f.count; i++) {
     G("rnti",     "int",    d->dl_rnti);
     G("frame",    "int",    d->dl_frame);
     G("subframe", "int",    d->dl_subframe);
     G("data",     "buffer", d->dl_data);
   }
+
   if (d->dl_rnti == -1 || d->dl_frame == -1 || d->dl_subframe == -1 ||
       d->dl_data == -1) goto error;
 
-#undef G
+  /* MIB: frame, subframe, data */
+  f = get_format(database, mib_id);
 
-  return;
+  for (i = 0; i < f.count; i++) {
+    G("frame",    "int",    d->mib_frame);
+    G("subframe", "int",    d->mib_subframe);
+    G("data",     "buffer", d->mib_data);
+  }
 
+  if (d->mib_frame == -1 || d->mib_subframe == -1 || d->mib_data == -1)
+    goto error;
+
+  /* preamble: frame, subframe, preamble */
+  f = get_format(database, preamble_id);
+
+  for (i = 0; i < f.count; i++) {
+    G("frame",    "int", d->preamble_frame);
+    G("subframe", "int", d->preamble_subframe);
+    G("preamble", "int", d->preamble_preamble);
+  }
+
+  if (d->preamble_frame == -1 || d->preamble_subframe == -1 ||
+      d->preamble_preamble == -1) goto error;
+
+  /* rar: rnti, frame, subframe, data */
+  f = get_format(database, rar_id);
+
+  for (i = 0; i < f.count; i++) {
+    G("rnti",     "int",    d->rar_rnti);
+    G("frame",    "int",    d->rar_frame);
+    G("subframe", "int",    d->rar_subframe);
+    G("data",     "buffer", d->rar_data);
+  }
+
+  if (d->rar_rnti == -1 || d->rar_frame == -1 || d->rar_subframe == -1 ||
+      d->rar_data == -1) goto error;
+
+#undef G
+  return;
 error:
   printf("bad T_messages.txt\n");
   abort();
 }
 
-void *receiver(void *_d)
-{
+void *receiver(void *_d) {
   ev_data *d = _d;
   int s;
   char buf[100000];
-
   s = socket(AF_INET, SOCK_DGRAM, 0);
-  if (s == -1) { perror("socket"); abort(); }
 
-  if (bind(s, (struct sockaddr *)&d->to, sizeof(struct sockaddr_in)) == -1)
-    { perror("bind"); abort(); }
+  if (s == -1) {
+    perror("socket");
+    abort();
+  }
+
+  if (bind(s, (struct sockaddr *)&d->to, sizeof(struct sockaddr_in)) == -1) {
+    perror("bind");
+    abort();
+  }
 
   while (1) {
     if (recv(s, buf, 100000, 0) <= 0) abort();
@@ -172,43 +276,120 @@ void *receiver(void *_d)
   return 0;
 }
 
-void usage(void)
-{
+void usage(void) {
   printf(
-"options:\n"
-"    -d <database file>        this option is mandatory\n"
-"    -i <dump file>            read events from this dump file\n"
-"    -ip <IP address>          send packets to this IP address (default %s)\n"
-"    -p <port>                 send packets to this port (default %d)\n",
-  DEFAULT_IP,
-  DEFAULT_PORT
+    "options:\n"
+    "    -d <database file>        this option is mandatory\n"
+    "    -i <dump file>            read events from this dump file\n"
+    "    -ip <IP address>          send packets to this IP address (default %s)\n"
+    "    -p <port>                 send packets to this port (default %d)\n"
+    "    -no-mib                   do not report MIB\n"
+    "    -no-sib                   do not report SIBs\n"
+    "    -max-mib <n>              report at maximum n MIB\n"
+    "    -max-sib <n>              report at maximum n SIBs\n"
+    "    -live                     run live\n"
+    "    -live-ip <IP address>     tracee's IP address (default %s)\n"
+    "    -live-port <por>          tracee's port (default %d)\n"
+    "-i and -live are mutually exclusive options. One of them must be provided\n"
+    "but not both.\n",
+    DEFAULT_IP,
+    DEFAULT_PORT,
+    DEFAULT_LIVE_IP,
+    DEFAULT_LIVE_PORT
   );
   exit(1);
 }
 
-int main(int n, char **v)
-{
+int main(int n, char **v) {
   char *database_filename = NULL;
   char *input_filename = NULL;
   void *database;
   event_handler *h;
   int in;
   int i;
-  int ul_id, dl_id;
+  int ul_id, dl_id, mib_id = -1, preamble_id, rar_id;
   ev_data d;
   char *ip = DEFAULT_IP;
   int port = DEFAULT_PORT;
-
+  char *live_ip = DEFAULT_LIVE_IP;
+  int live_port = DEFAULT_LIVE_PORT;
+  int live = 0;
   memset(&d, 0, sizeof(ev_data));
 
   for (i = 1; i < n; i++) {
     if (!strcmp(v[i], "-h") || !strcmp(v[i], "--help")) usage();
-    if (!strcmp(v[i], "-d"))
-      { if (i > n-2) usage(); database_filename = v[++i]; continue; }
-    if (!strcmp(v[i], "-i"))
-      { if (i > n-2) usage(); input_filename = v[++i]; continue; }
-    if (!strcmp(v[i], "-ip")) { if (i > n-2) usage(); ip = v[++i]; continue; }
-    if (!strcmp(v[i], "-p")) {if(i>n-2)usage(); port=atoi(v[++i]); continue; }
+
+    if (!strcmp(v[i], "-d")) {
+      if (i > n-2) usage();
+
+      database_filename = v[++i];
+      continue;
+    }
+
+    if (!strcmp(v[i], "-i")) {
+      if (i > n-2) usage();
+
+      input_filename = v[++i];
+      continue;
+    }
+
+    if (!strcmp(v[i], "-ip")) {
+      if (i > n-2) usage();
+
+      ip = v[++i];
+      continue;
+    }
+
+    if (!strcmp(v[i], "-p")) {
+      if(i>n-2)usage();
+
+      port=atoi(v[++i]);
+      continue;
+    }
+
+    if (!strcmp(v[i], "-no-mib")) {
+      d.no_mib = 1;
+      continue;
+    }
+
+    if (!strcmp(v[i], "-no-sib")) {
+      d.no_sib = 1;
+      continue;
+    }
+
+    if (!strcmp(v[i], "-max-mib")) {
+      if (i > n-2) usage();
+
+      d.max_mib = atoi(v[++i]);
+      continue;
+    }
+
+    if (!strcmp(v[i], "-max-sib")) {
+      if (i > n-2) usage();
+
+      d.max_sib = atoi(v[++i]);
+      continue;
+    }
+
+    if (!strcmp(v[i], "-live")) {
+      live = 1;
+      continue;
+    }
+
+    if (!strcmp(v[i], "-live-ip")) {
+      if (i > n-2) usage();
+
+      live_ip = v[++i];
+      continue;
+    }
+
+    if (!strcmp(v[i], "-live-port")) {
+      if (i > n-2) usage();
+
+      live_port = atoi(v[++i]);
+      continue;
+    }
+
     usage();
   }
 
@@ -217,43 +398,91 @@ int main(int n, char **v)
     exit(1);
   }
 
-  if (input_filename == NULL) {
-    printf("ERROR: provide an input file (-i)\n");
+  if (input_filename == NULL && live == 0) {
+    printf("ERROR: provide an input file (-i) or run live (-live)\n");
+    exit(1);
+  }
+
+  if (input_filename != NULL && live != 0) {
+    printf("ERROR: cannot use both -i and -live\n");
     exit(1);
   }
 
-  in = open(input_filename, O_RDONLY);
-  if (in == -1) { perror(input_filename); return 1; }
+  if (live == 0) {
+    in = open(input_filename, O_RDONLY);
+
+    if (in == -1) {
+      perror(input_filename);
+      return 1;
+    }
+  } else
+    in = connect_to(live_ip, live_port);
 
   database = parse_database(database_filename);
   load_config_file(database_filename);
-
   h = new_handler(database);
 
+  if (live) {
+    char mt = 1;
+    int  number_of_events = number_of_ids(database);
+    int *is_on = calloc(number_of_events, sizeof(int));
+
+    if (is_on == NULL) {
+      printf("ERROR: out of memory\n");
+      exit(1);
+    }
+
+    on_off(database, "ENB_MAC_UE_UL_PDU_WITH_DATA", is_on, 1);
+    on_off(database, "ENB_MAC_UE_DL_PDU_WITH_DATA", is_on, 1);
+    on_off(database, "ENB_PHY_MIB", is_on, 1);
+    on_off(database, "ENB_PHY_INITIATE_RA_PROCEDURE", is_on, 1);
+    on_off(database, "ENB_MAC_UE_DL_RAR_PDU_WITH_DATA", is_on, 1);
+
+    /* activate selected traces */
+    if (socket_send(in, &mt, 1) == -1 ||
+        socket_send(in, &number_of_events, sizeof(int)) == -1 ||
+        socket_send(in, is_on, number_of_events * sizeof(int)) == -1) {
+      printf("ERROR: socket_send failed\n");
+      exit(1);
+    }
+
+    free(is_on);
+  }
+
   ul_id = event_id_from_name(database, "ENB_MAC_UE_UL_PDU_WITH_DATA");
   dl_id = event_id_from_name(database, "ENB_MAC_UE_DL_PDU_WITH_DATA");
-  setup_data(&d, database, ul_id, dl_id);
-
+  mib_id = event_id_from_name(database, "ENB_PHY_MIB");
+  preamble_id = event_id_from_name(database, "ENB_PHY_INITIATE_RA_PROCEDURE");
+  rar_id = event_id_from_name(database, "ENB_MAC_UE_DL_RAR_PDU_WITH_DATA");
+  setup_data(&d, database, ul_id, dl_id, mib_id, preamble_id, rar_id);
   register_handler_function(h, ul_id, ul, &d);
   register_handler_function(h, dl_id, dl, &d);
-
+  register_handler_function(h, mib_id, mib, &d);
+  register_handler_function(h, preamble_id, preamble, &d);
+  register_handler_function(h, rar_id, rar, &d);
   d.socket = socket(AF_INET, SOCK_DGRAM, 0);
-  if (d.socket == -1) { perror("socket"); exit(1); }
+
+  if (d.socket == -1) {
+    perror("socket");
+    exit(1);
+  }
 
   d.to.sin_family = AF_INET;
   d.to.sin_port = htons(port);
   d.to.sin_addr.s_addr = inet_addr(ip);
-
   new_thread(receiver, &d);
-
   OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL };
 
   /* read messages */
   while (1) {
     event e;
     e = get_event(in, &ebuf, database);
+
     if (e.type == -1) break;
-    if (!(e.type == ul_id || e.type == dl_id)) continue;
+
+    if (!(e.type == ul_id || e.type == dl_id || e.type == mib_id ||
+          e.type == preamble_id || e.type == rar_id)) continue;
+
     handle_event(h, e);
   }
 
diff --git a/common/utils/T/tracer/textlog.c b/common/utils/T/tracer/textlog.c
index bb773b42150b9fcc15b7378405818a4b14db0e42..a123bf9bf518b9104d224c5a3d849c5cc690e7af 100644
--- a/common/utils/T/tracer/textlog.c
+++ b/common/utils/T/tracer/textlog.c
@@ -52,6 +52,7 @@ void usage(void)
 "                                    they will be processed in order\n"
 "                                    by default, all is off\n"
 "    -full                     also dump buffers' content\n"
+"    -raw-time                 also prints 'raw time'\n"
 "    -ip <host>                connect to given IP address (default %s)\n"
 "    -p <port>                 connect to given port (default %d)\n"
 "    -x                        GUI output\n"
@@ -91,6 +92,7 @@ int main(int n, char **v)
   int gui_active = 1;
   textlog_data textlog_data;
   int full = 0;
+  int raw_time = 0;
 
   /* write on a socket fails if the other end is closed and we get SIGPIPE */
   if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) abort();
@@ -117,6 +119,7 @@ int main(int n, char **v)
     if (!strcmp(v[i], "-debug-gui")) { gui_logd = 1; continue; }
     if (!strcmp(v[i], "-no-gui")) { gui_active = 0; continue; }
     if (!strcmp(v[i], "-full")) { full = 1; continue; }
+    if (!strcmp(v[i], "-raw-time")) { raw_time = 1; continue; }
     usage();
   }
 
@@ -162,6 +165,7 @@ int main(int n, char **v)
 //        "ev: {} eNB_id [eNB_ID] frame [frame] subframe [subframe]");
     logger_add_view(textlog, out);
     if (full) textlog_dump_buffer(textlog, 1);
+    if (raw_time) textlog_raw_time(textlog, 1);
     free(name);
     free(desc);
   }
@@ -187,7 +191,7 @@ int main(int n, char **v)
   while (1) {
     event e;
     e = get_event(textlog_data.socket, &ebuf, database);
-    if (e.type == -1) abort();
+    if (e.type == -1) break;
     handle_event(h, e);
   }
 
diff --git a/common/utils/T/tracer/utils.c b/common/utils/T/tracer/utils.c
index 7f58b6f5aa0061189d01a5107d8e6dcea035138a..2452254cf9167a4fbf6a4586e4370b58cdc5cae9 100644
--- a/common/utils/T/tracer/utils.c
+++ b/common/utils/T/tracer/utils.c
@@ -9,27 +9,38 @@
 #include <arpa/inet.h>
 #include <math.h>
 
-void new_thread(void *(*f)(void *), void *data)
-{
+void new_thread(void *(*f)(void *), void *data) {
   pthread_t t;
   pthread_attr_t att;
 
-  if (pthread_attr_init(&att))
-    { fprintf(stderr, "pthread_attr_init err\n"); exit(1); }
-  if (pthread_attr_setdetachstate(&att, PTHREAD_CREATE_DETACHED))
-    { fprintf(stderr, "pthread_attr_setdetachstate err\n"); exit(1); }
-  if (pthread_attr_setstacksize(&att, 10000000))
-    { fprintf(stderr, "pthread_attr_setstacksize err\n"); exit(1); }
-  if (pthread_create(&t, &att, f, data))
-    { fprintf(stderr, "pthread_create err\n"); exit(1); }
-  if (pthread_attr_destroy(&att))
-    { fprintf(stderr, "pthread_attr_destroy err\n"); exit(1); }
+  if (pthread_attr_init(&att)) {
+    fprintf(stderr, "pthread_attr_init err\n");
+    exit(1);
+  }
+
+  if (pthread_attr_setdetachstate(&att, PTHREAD_CREATE_DETACHED)) {
+    fprintf(stderr, "pthread_attr_setdetachstate err\n");
+    exit(1);
+  }
+
+  if (pthread_attr_setstacksize(&att, 10000000)) {
+    fprintf(stderr, "pthread_attr_setstacksize err\n");
+    exit(1);
+  }
+
+  if (pthread_create(&t, &att, f, data)) {
+    fprintf(stderr, "pthread_create err\n");
+    exit(1);
+  }
+
+  if (pthread_attr_destroy(&att)) {
+    fprintf(stderr, "pthread_attr_destroy err\n");
+    exit(1);
+  }
 }
 
-void sleepms(int ms)
-{
+void sleepms(int ms) {
   struct timespec t;
-
   t.tv_sec = ms / 1000;
   t.tv_nsec = (ms % 1000) * 1000000L;
 
@@ -37,12 +48,15 @@ void sleepms(int ms)
   if (nanosleep(&t, NULL)) abort();
 }
 
-void bps(char *out, float v, char *suffix)
-{
+void bps(char *out, float v, char *suffix) {
   static char *bps_unit[4] = { "", "k", "M", "G" };
   int flog;
-  if (v < 1000) flog = 0; else flog = floor(floor(log10(v)) / 3);
+
+  if (v < 1000) flog = 0;
+  else flog = floor(floor(log10(v)) / 3);
+
   if (flog > 3) flog = 3;
+
   v /= pow(10, flog*3);
   sprintf(out, "%g%s%s", round(v*100)/100, bps_unit[flog], suffix);
 }
@@ -51,25 +65,31 @@ void bps(char *out, float v, char *suffix)
 /* list                                                                     */
 /****************************************************************************/
 
-list *list_remove_head(list *l)
-{
+list *list_remove_head(list *l) {
   list *ret;
+
   if (l == NULL) return NULL;
+
   ret = l->next;
+
   if (ret != NULL) ret->last = l->last;
+
   free(l);
   return ret;
 }
 
-list *list_append(list *l, void *data)
-{
+list *list_append(list *l, void *data) {
   list *new = calloc(1, sizeof(list));
+
   if (new == NULL) abort();
+
   new->data = data;
+
   if (l == NULL) {
     new->last = new;
     return new;
   }
+
   l->last->next = new;
   l->last = new;
   return l;
@@ -79,88 +99,107 @@ list *list_append(list *l, void *data)
 /* socket                                                                   */
 /****************************************************************************/
 
-int create_listen_socket(char *addr, int port)
-{
+int create_listen_socket(char *addr, int port) {
   struct sockaddr_in a;
   int s;
   int v;
-
   s = socket(AF_INET, SOCK_STREAM, 0);
-  if (s == -1) { perror("socket"); exit(1); }
+
+  if (s == -1) {
+    perror("socket");
+    exit(1);
+  }
+
   v = 1;
-  if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &v, sizeof(int)))
-    { perror("setsockopt"); exit(1); }
+
+  if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &v, sizeof(int))) {
+    perror("setsockopt");
+    exit(1);
+  }
 
   a.sin_family = AF_INET;
   a.sin_port = htons(port);
   a.sin_addr.s_addr = inet_addr(addr);
 
-  if (bind(s, (struct sockaddr *)&a, sizeof(a))) { perror("bind"); exit(1); }
-  if (listen(s, 5)) { perror("listen"); exit(1); }
+  if (bind(s, (struct sockaddr *)&a, sizeof(a))) {
+    perror("bind");
+    exit(1);
+  }
+
+  if (listen(s, 5)) {
+    perror("listen");
+    exit(1);
+  }
 
   return s;
 }
 
-int socket_accept(int s)
-{
+int socket_accept(int s) {
   struct sockaddr_in a;
   socklen_t alen;
   alen = sizeof(a);
   return accept(s, (struct sockaddr *)&a, &alen);
 }
 
-int socket_send(int socket, void *buffer, int size)
-{
+int socket_send(int socket, void *buffer, int size) {
   char *x = buffer;
   int ret;
+
   while (size) {
     ret = write(socket, x, size);
+
     if (ret <= 0) return -1;
+
     size -= ret;
     x += ret;
   }
+
   return 0;
 }
 
-int get_connection(char *addr, int port)
-{
+int get_connection(char *addr, int port) {
   int s, t;
-
   printf("waiting for connection on %s:%d\n", addr, port);
-
   s = create_listen_socket(addr, port);
-
   t = socket_accept(s);
-  if (t == -1) { perror("accept"); exit(1); }
-  close(s);
 
-  printf("connected\n");
+  if (t == -1) {
+    perror("accept");
+    exit(1);
+  }
 
+  close(s);
+  printf("connected\n");
   return t;
 }
 
-int fullread(int fd, void *_buf, int count)
-{
+int fullread(int fd, void *_buf, int count) {
   char *buf = _buf;
   int ret = 0;
   int l;
+
   while (count) {
     l = read(fd, buf, count);
+
     if (l <= 0) return -1;
+
     count -= l;
     buf += l;
     ret += l;
   }
+
   return ret;
 }
 
-int try_connect_to(char *addr, int port)
-{
+int try_connect_to(char *addr, int port) {
   int s;
   struct sockaddr_in a;
-
   s = socket(AF_INET, SOCK_STREAM, 0);
-  if (s == -1) { perror("socket"); exit(1); }
+
+  if (s == -1) {
+    perror("socket");
+    exit(1);
+  }
 
   a.sin_family = AF_INET;
   a.sin_port = htons(port);
@@ -175,14 +214,12 @@ int try_connect_to(char *addr, int port)
   return s;
 }
 
-int connect_to(char *addr, int port)
-{
+int connect_to(char *addr, int port) {
   int s;
-
   printf("connecting to %s:%d\n", addr, port);
-
 again:
   s = try_connect_to(addr, port);
+
   if (s == -1) {
     printf("trying again in 1s\n");
     sleep(1);
@@ -196,49 +233,45 @@ again:
 /* buffer                                                                   */
 /****************************************************************************/
 
-void PUTC(OBUF *o, char c)
-{
+void PUTC(OBUF *o, char c) {
   if (o->osize == o->omaxsize) {
     o->omaxsize += 512;
     o->obuf = realloc(o->obuf, o->omaxsize);
+
     if (o->obuf == NULL) abort();
   }
+
   o->obuf[o->osize] = c;
   o->osize++;
 }
 
-void PUTS(OBUF *o, char *s)
-{
+void PUTS(OBUF *o, char *s) {
   while (*s) PUTC(o, *s++);
 }
 
-static int clean(char c)
-{
+static int clean(char c) {
   if (!isprint(c)) c = ' ';
+
   return c;
 }
 
-void PUTS_CLEAN(OBUF *o, char *s)
-{
+void PUTS_CLEAN(OBUF *o, char *s) {
   while (*s) PUTC(o, clean(*s++));
 }
 
-void PUTI(OBUF *o, int i)
-{
+void PUTI(OBUF *o, int i) {
   char s[64];
   sprintf(s, "%d", i);
   PUTS(o, s);
 }
 
-void PUTX2(OBUF *o, int i)
-{
+void PUTX2(OBUF *o, int i) {
   char s[64];
   sprintf(s, "%2.2x", i);
   PUTS(o, s);
 }
 
-void PUTUL(OBUF *o, unsigned long l)
-{
+void PUTUL(OBUF *o, unsigned long l) {
   char s[128];
   sprintf(s, "%ld", l);
   PUTS(o, s);
diff --git a/common/utils/assertions.h b/common/utils/assertions.h
index b872b009e258408e799f6dfaaf0cc2697c1913f4..77e939affe4b7393aadb286b86c8b8551cc5d25f 100644
--- a/common/utils/assertions.h
+++ b/common/utils/assertions.h
@@ -22,9 +22,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <inttypes.h>
-#ifdef CMAKER
 #include <platform_types.h>
-#endif
 
 #if defined(ENB_MODE)
 # define display_backtrace()
diff --git a/common/utils/backtrace.c b/common/utils/backtrace.c
index 889e0d84d148f3694ce363a2f74ac33065cbeb26..f6de74f156ce1bc04ddb58aeb65c3097c8c1ba47 100644
--- a/common/utils/backtrace.c
+++ b/common/utils/backtrace.c
@@ -31,18 +31,18 @@
 #include "backtrace.h"
 
 /* Obtain a backtrace and print it to stdout. */
-void display_backtrace(void)
-{
+void display_backtrace(void) {
   void *array[10];
   size_t size;
   char **strings;
   size_t i;
-  char* test=getenv("NO_BACKTRACE");
-  if (test!=0) *((int*)0)=0;
+  char *test=getenv("NO_BACKTRACE");
+
+  if (test!=0) *((int *)0)=0;
+
   size = backtrace(array, 10);
   strings = backtrace_symbols(array, size);
-
-  printf("Obtained %zd stack frames.\n", size);
+  printf("Obtained %u stack frames.\n", (unsigned int)size);
 
   for (i = 0; i < size; i++)
     printf("%s\n", strings[i]);
@@ -50,8 +50,7 @@ void display_backtrace(void)
   free(strings);
 }
 
-void backtrace_handle_signal(siginfo_t *info)
-{
+void backtrace_handle_signal(siginfo_t *info) {
   display_backtrace();
   //exit(EXIT_FAILURE);
 }
diff --git a/common/utils/collection/queue.h b/common/utils/collection/queue.h
old mode 100755
new mode 100644
diff --git a/common/utils/collection/tree.h b/common/utils/collection/tree.h
old mode 100755
new mode 100644
diff --git a/common/utils/hashtable/hashtable.c b/common/utils/hashtable/hashtable.c
index 2c7b35744ca7cf766044f7efc2341aff5b9a2fb5..7b0fc422139c6bf566ea8c824924b5f40047c4d9 100644
--- a/common/utils/hashtable/hashtable.c
+++ b/common/utils/hashtable/hashtable.c
@@ -2,9 +2,9 @@
  * 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 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.  
+ * except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *      http://www.openairinterface.org/?page_id=698
@@ -28,17 +28,33 @@
 
 
 //-------------------------------------------------------------------------------------------------------------------------------
-char* hashtable_rc_code2string(hashtable_rc_t rcP)
+char *hashtable_rc_code2string(hashtable_rc_t rcP)
 //-------------------------------------------------------------------------------------------------------------------------------
 {
-    switch (rcP) {
-    case HASH_TABLE_OK:                      return "HASH_TABLE_OK";break;
-    case HASH_TABLE_INSERT_OVERWRITTEN_DATA: return "HASH_TABLE_INSERT_OVERWRITTEN_DATA";break;
-    case HASH_TABLE_KEY_NOT_EXISTS:          return "HASH_TABLE_KEY_NOT_EXISTS";break;
-    case HASH_TABLE_KEY_ALREADY_EXISTS:      return "HASH_TABLE_KEY_ALREADY_EXISTS";break;
-    case HASH_TABLE_BAD_PARAMETER_HASHTABLE: return "HASH_TABLE_BAD_PARAMETER_HASHTABLE";break;
-    default:                                 return "UNKNOWN hashtable_rc_t";
-    }
+  switch (rcP) {
+    case HASH_TABLE_OK:
+      return "HASH_TABLE_OK";
+      break;
+
+    case HASH_TABLE_INSERT_OVERWRITTEN_DATA:
+      return "HASH_TABLE_INSERT_OVERWRITTEN_DATA";
+      break;
+
+    case HASH_TABLE_KEY_NOT_EXISTS:
+      return "HASH_TABLE_KEY_NOT_EXISTS";
+      break;
+
+    case HASH_TABLE_KEY_ALREADY_EXISTS:
+      return "HASH_TABLE_KEY_ALREADY_EXISTS";
+      break;
+
+    case HASH_TABLE_BAD_PARAMETER_HASHTABLE:
+      return "HASH_TABLE_BAD_PARAMETER_HASHTABLE";
+      break;
+
+    default:
+      return "UNKNOWN hashtable_rc_t";
+  }
 }
 //-------------------------------------------------------------------------------------------------------------------------------
 /*
@@ -46,7 +62,7 @@ char* hashtable_rc_code2string(hashtable_rc_t rcP)
  * hash_free_int_func() is used when this hashtable is used to store int values as data (pointer = value).
  */
 
-void hash_free_int_func(void* memoryP){}
+void hash_free_int_func(void *memoryP) {}
 
 //-------------------------------------------------------------------------------------------------------------------------------
 /*
@@ -55,9 +71,8 @@ void hash_free_int_func(void* memoryP){}
  * This is a simple/naive hash function which adds the key's ASCII char values. It will probably generate lots of collisions on large hash tables.
  */
 
-static hash_size_t def_hashfunc(const uint64_t keyP)
-{
-    return (hash_size_t)keyP;
+static hash_size_t def_hashfunc(const uint64_t keyP) {
+  return (hash_size_t)keyP;
 }
 
 //-------------------------------------------------------------------------------------------------------------------------------
@@ -67,132 +82,147 @@ static hash_size_t def_hashfunc(const uint64_t keyP)
  * The user can also specify a hash function. If the hashfunc argument is NULL, a default hash function is used.
  * If an error occurred, NULL is returned. All other values in the returned hash_table_t pointer should be released with hashtable_destroy().
  */
-hash_table_t *hashtable_create(const hash_size_t sizeP, hash_size_t (*hashfuncP)(const hash_key_t ), void (*freefuncP)(void*))
-{
-    hash_table_t *hashtbl = NULL;
+hash_table_t *hashtable_create(const hash_size_t sizeP, hash_size_t (*hashfuncP)(const hash_key_t ), void (*freefuncP)(void *)) {
+  hash_table_t *hashtbl = NULL;
 
-    if(!(hashtbl=malloc(sizeof(hash_table_t)))) {
-        return NULL;
-    }
+  if(!(hashtbl=malloc(sizeof(hash_table_t)))) {
+    return NULL;
+  }
 
-    if(!(hashtbl->nodes=calloc(sizeP, sizeof(hash_node_t*)))) {
-        free(hashtbl);
-        return NULL;
-    }
+  if(!(hashtbl->nodes=calloc(sizeP, sizeof(hash_node_t *)))) {
+    free(hashtbl);
+    return NULL;
+  }
 
-    hashtbl->size=sizeP;
+  hashtbl->size=sizeP;
 
-    if(hashfuncP) hashtbl->hashfunc=hashfuncP;
-    else hashtbl->hashfunc=def_hashfunc;
+  if(hashfuncP) hashtbl->hashfunc=hashfuncP;
+  else hashtbl->hashfunc=def_hashfunc;
 
-    if(freefuncP) hashtbl->freefunc=freefuncP;
-    else hashtbl->freefunc=free;
+  if(freefuncP) hashtbl->freefunc=freefuncP;
+  else hashtbl->freefunc=free;
 
-    return hashtbl;
+  return hashtbl;
 }
 //-------------------------------------------------------------------------------------------------------------------------------
 /*
  * Cleanup
  * The hashtable_destroy() walks through the linked lists for each possible hash value, and releases the elements. It also releases the nodes array and the hash_table_t.
  */
-hashtable_rc_t hashtable_destroy(hash_table_t * hashtblP)
-{
-    hash_size_t n;
-    hash_node_t *node, *oldnode;
+hashtable_rc_t hashtable_destroy(hash_table_t **hashtblP) {
+  hash_size_t n;
+  hash_node_t *node, *oldnode;
 
-    if (hashtblP == NULL) {
-        return HASH_TABLE_BAD_PARAMETER_HASHTABLE;
-    }
+  if (*hashtblP == NULL) {
+    return HASH_TABLE_BAD_PARAMETER_HASHTABLE;
+  }
+
+  for(n=0; n<(*hashtblP)->size; ++n) {
+    node=(*hashtblP)->nodes[n];
 
-    for(n=0; n<hashtblP->size; ++n) {
-        node=hashtblP->nodes[n];
-        while(node) {
-            oldnode=node;
-            node=node->next;
-            if (oldnode->data) {
-                hashtblP->freefunc(oldnode->data);
-            }
-            free(oldnode);
-        }
+    while(node) {
+      oldnode=node;
+      node=node->next;
+
+      if (oldnode->data) {
+        (*hashtblP)->freefunc(oldnode->data);
+      }
+
+      free(oldnode);
     }
-    free(hashtblP->nodes);
-    free(hashtblP);
-    hashtblP=NULL;
-    return HASH_TABLE_OK;
+  }
+
+  free((*hashtblP)->nodes);
+  free((*hashtblP));
+  *hashtblP=NULL;
+  return HASH_TABLE_OK;
 }
 //-------------------------------------------------------------------------------------------------------------------------------
-hashtable_rc_t hashtable_is_key_exists (const hash_table_t * const hashtblP, const hash_key_t keyP)
+hashtable_rc_t hashtable_is_key_exists (const hash_table_t *const hashtblP, const hash_key_t keyP)
 //-------------------------------------------------------------------------------------------------------------------------------
 {
-    hash_node_t *node = NULL;
-    hash_size_t  hash = 0;
+  hash_node_t *node = NULL;
+  hash_size_t  hash = 0;
 
-    if (hashtblP == NULL) {
-        return HASH_TABLE_BAD_PARAMETER_HASHTABLE;
-    }
+  if (hashtblP == NULL) {
+    return HASH_TABLE_BAD_PARAMETER_HASHTABLE;
+  }
 
-    hash=hashtblP->hashfunc(keyP)%hashtblP->size;
-    node=hashtblP->nodes[hash];
-    while(node) {
-        if(node->key == keyP) {
-            return HASH_TABLE_OK;
-        }
-        node=node->next;
+  hash=hashtblP->hashfunc(keyP)%hashtblP->size;
+  node=hashtblP->nodes[hash];
+
+  while(node) {
+    if(node->key == keyP) {
+      return HASH_TABLE_OK;
     }
-    return HASH_TABLE_KEY_NOT_EXISTS;
+
+    node=node->next;
+  }
+
+  return HASH_TABLE_KEY_NOT_EXISTS;
 }
 //-------------------------------------------------------------------------------------------------------------------------------
-hashtable_rc_t hashtable_apply_funct_on_elements (hash_table_t *const hashtblP, void functP(hash_key_t keyP, void* dataP, void* parameterP), void* parameterP)
+hashtable_rc_t hashtable_apply_funct_on_elements (hash_table_t *const hashtblP, void functP(hash_key_t keyP, void *dataP, void *parameterP), void *parameterP)
 //-------------------------------------------------------------------------------------------------------------------------------
 {
-    hash_node_t  *node         = NULL;
-    unsigned int  i            = 0;
-    unsigned int  num_elements = 0;
-    if (hashtblP == NULL) {
-        return HASH_TABLE_BAD_PARAMETER_HASHTABLE;
-    }
-    while ((num_elements < hashtblP->num_elements) && (i < hashtblP->size)) {
-        if (hashtblP->nodes[i] != NULL) {
-            node=hashtblP->nodes[i];
-            while(node) {
-                num_elements += 1;
-                functP(node->key, node->data, parameterP);
-                node=node->next;
-            }
-        }
-        i += 1;
+  hash_node_t  *node         = NULL;
+  unsigned int  i            = 0;
+  unsigned int  num_elements = 0;
+
+  if (hashtblP == NULL) {
+    return HASH_TABLE_BAD_PARAMETER_HASHTABLE;
+  }
+
+  while ((num_elements < hashtblP->num_elements) && (i < hashtblP->size)) {
+    if (hashtblP->nodes[i] != NULL) {
+      node=hashtblP->nodes[i];
+
+      while(node) {
+        num_elements += 1;
+        functP(node->key, node->data, parameterP);
+        node=node->next;
+      }
     }
-    return HASH_TABLE_OK;
+
+    i += 1;
+  }
+
+  return HASH_TABLE_OK;
 }
 //-------------------------------------------------------------------------------------------------------------------------------
-hashtable_rc_t hashtable_dump_content (const hash_table_t * const hashtblP, char * const buffer_pP, int * const remaining_bytes_in_buffer_pP )
+hashtable_rc_t hashtable_dump_content (const hash_table_t *const hashtblP, char *const buffer_pP, int *const remaining_bytes_in_buffer_pP )
 //-------------------------------------------------------------------------------------------------------------------------------
 {
-    hash_node_t  *node         = NULL;
-    unsigned int  i            = 0;
-    if (hashtblP == NULL) {
+  hash_node_t  *node         = NULL;
+  unsigned int  i            = 0;
+
+  if (hashtblP == NULL) {
+    *remaining_bytes_in_buffer_pP = snprintf(
+                                      buffer_pP,
+                                      *remaining_bytes_in_buffer_pP,
+                                      "HASH_TABLE_BAD_PARAMETER_HASHTABLE");
+    return HASH_TABLE_BAD_PARAMETER_HASHTABLE;
+  }
+
+  while ((i < hashtblP->size) && (*remaining_bytes_in_buffer_pP > 0)) {
+    if (hashtblP->nodes[i] != NULL) {
+      node=hashtblP->nodes[i];
+
+      while(node) {
         *remaining_bytes_in_buffer_pP = snprintf(
-                buffer_pP,
-                *remaining_bytes_in_buffer_pP,
-                "HASH_TABLE_BAD_PARAMETER_HASHTABLE");
-        return HASH_TABLE_BAD_PARAMETER_HASHTABLE;
-    }
-    while ((i < hashtblP->size) && (*remaining_bytes_in_buffer_pP > 0)) {
-        if (hashtblP->nodes[i] != NULL) {
-            node=hashtblP->nodes[i];
-            while(node) {
-                *remaining_bytes_in_buffer_pP = snprintf(
-                                buffer_pP,
-                                *remaining_bytes_in_buffer_pP,
-                                "Key 0x%"PRIx64" Element %p\n",
-                                node->key,
-                                node->data);
-                node=node->next;
-            }
-        }
-        i += 1;
+                                          buffer_pP,
+                                          *remaining_bytes_in_buffer_pP,
+                                          "Key 0x%"PRIx64" Element %p\n",
+                                          node->key,
+                                          node->data);
+        node=node->next;
+      }
     }
-    return HASH_TABLE_OK;
+
+    i += 1;
+  }
+
+  return HASH_TABLE_OK;
 }
 
 //-------------------------------------------------------------------------------------------------------------------------------
@@ -200,97 +230,110 @@ hashtable_rc_t hashtable_dump_content (const hash_table_t * const hashtblP, char
  * Adding a new element
  * To make sure the hash value is not bigger than size, the result of the user provided hash function is used modulo size.
  */
-hashtable_rc_t hashtable_insert(hash_table_t * const hashtblP, const hash_key_t keyP, void *dataP)
-{
-    hash_node_t *node = NULL;
-    hash_size_t  hash = 0;
-    if (hashtblP == NULL) {
-        return HASH_TABLE_BAD_PARAMETER_HASHTABLE;
-    }
-    hash=hashtblP->hashfunc(keyP)%hashtblP->size;
+hashtable_rc_t hashtable_insert(hash_table_t *const hashtblP, const hash_key_t keyP, void *dataP) {
+  hash_node_t *node = NULL;
+  hash_size_t  hash = 0;
 
-    node=hashtblP->nodes[hash];
-    while(node) {
-        if(node->key == keyP) {
-            if (node->data) {
-                hashtblP->freefunc(node->data);
-            }
-            node->data=dataP;
-            return HASH_TABLE_INSERT_OVERWRITTEN_DATA;
-        }
-        node=node->next;
-    }
-    if(!(node=malloc(sizeof(hash_node_t)))) return -1;
-    node->key=keyP;
-    node->data=dataP;
-    if (hashtblP->nodes[hash]) {
-        node->next=hashtblP->nodes[hash];
-    } else {
-        node->next = NULL;
+  if (hashtblP == NULL) {
+    return HASH_TABLE_BAD_PARAMETER_HASHTABLE;
+  }
+
+  hash=hashtblP->hashfunc(keyP)%hashtblP->size;
+  node=hashtblP->nodes[hash];
+
+  while(node) {
+    if(node->key == keyP) {
+      if (node->data) {
+        hashtblP->freefunc(node->data);
+      }
+
+      node->data=dataP;
+      return HASH_TABLE_INSERT_OVERWRITTEN_DATA;
     }
-    hashtblP->nodes[hash]=node;
-    hashtblP->num_elements += 1;
-    return HASH_TABLE_OK;
+
+    node=node->next;
+  }
+
+  if(!(node=malloc(sizeof(hash_node_t)))) return -1;
+
+  node->key=keyP;
+  node->data=dataP;
+
+  if (hashtblP->nodes[hash]) {
+    node->next=hashtblP->nodes[hash];
+  } else {
+    node->next = NULL;
+  }
+
+  hashtblP->nodes[hash]=node;
+  hashtblP->num_elements += 1;
+  return HASH_TABLE_OK;
 }
 //-------------------------------------------------------------------------------------------------------------------------------
 /*
  * To remove an element from the hash table, we just search for it in the linked list for that hash value,
  * and remove it if it is found. If it was not found, it is an error and -1 is returned.
  */
-hashtable_rc_t hashtable_remove(hash_table_t * const hashtblP, const hash_key_t keyP)
-{
-    hash_node_t *node, *prevnode=NULL;
-    hash_size_t  hash = 0;
+hashtable_rc_t hashtable_remove(hash_table_t *const hashtblP, const hash_key_t keyP) {
+  hash_node_t *node, *prevnode=NULL;
+  hash_size_t  hash = 0;
 
-    if (hashtblP == NULL) {
-        return HASH_TABLE_BAD_PARAMETER_HASHTABLE;
-    }
-    hash=hashtblP->hashfunc(keyP)%hashtblP->size;
-    node=hashtblP->nodes[hash];
-    while(node) {
-        if(node->key == keyP) {
-            if(prevnode) prevnode->next=node->next;
-            else hashtblP->nodes[hash]=node->next;
-            if (node->data) {
-                hashtblP->freefunc(node->data);
-            }
-            free(node);
-            hashtblP->num_elements -= 1;
-            return HASH_TABLE_OK;
-        }
-        prevnode=node;
-        node=node->next;
+  if (hashtblP == NULL) {
+    return HASH_TABLE_BAD_PARAMETER_HASHTABLE;
+  }
+
+  hash=hashtblP->hashfunc(keyP)%hashtblP->size;
+  node=hashtblP->nodes[hash];
+
+  while(node) {
+    if(node->key == keyP) {
+      if(prevnode) prevnode->next=node->next;
+      else hashtblP->nodes[hash]=node->next;
+
+      if (node->data) {
+        hashtblP->freefunc(node->data);
+      }
+
+      free(node);
+      hashtblP->num_elements -= 1;
+      return HASH_TABLE_OK;
     }
-    return HASH_TABLE_KEY_NOT_EXISTS;
+
+    prevnode=node;
+    node=node->next;
+  }
+
+  return HASH_TABLE_KEY_NOT_EXISTS;
 }
 //-------------------------------------------------------------------------------------------------------------------------------
 /*
  * Searching for an element is easy. We just search through the linked list for the corresponding hash value.
  * NULL is returned if we didn't find it.
  */
-hashtable_rc_t hashtable_get(const hash_table_t * const hashtblP, const hash_key_t keyP, void** dataP)
-{
-    hash_node_t *node = NULL;
-    hash_size_t  hash = 0;
+hashtable_rc_t hashtable_get(const hash_table_t *const hashtblP, const hash_key_t keyP, void **dataP) {
+  hash_node_t *node = NULL;
+  hash_size_t  hash = 0;
 
-    if (hashtblP == NULL) {
-        *dataP = NULL;
-        return HASH_TABLE_BAD_PARAMETER_HASHTABLE;
-    }
-    hash=hashtblP->hashfunc(keyP)%hashtblP->size;
-/*	fprintf(stderr, "hashtable_get() key=%s, hash=%d\n", key, hash);*/
+  if (hashtblP == NULL) {
+    *dataP = NULL;
+    return HASH_TABLE_BAD_PARAMETER_HASHTABLE;
+  }
 
-    node=hashtblP->nodes[hash];
+  hash=hashtblP->hashfunc(keyP)%hashtblP->size;
+  /*  fprintf(stderr, "hashtable_get() key=%s, hash=%d\n", key, hash);*/
+  node=hashtblP->nodes[hash];
 
-    while(node) {
-        if(node->key == keyP) {
-            *dataP = node->data;
-            return HASH_TABLE_OK;
-        }
-        node=node->next;
+  while(node) {
+    if(node->key == keyP) {
+      *dataP = node->data;
+      return HASH_TABLE_OK;
     }
-    *dataP = NULL;
-    return HASH_TABLE_KEY_NOT_EXISTS;
+
+    node=node->next;
+  }
+
+  *dataP = NULL;
+  return HASH_TABLE_KEY_NOT_EXISTS;
 }
 //-------------------------------------------------------------------------------------------------------------------------------
 /*
@@ -304,36 +347,33 @@ hashtable_rc_t hashtable_get(const hash_table_t * const hashtblP, const hash_key
  * After that, we can just free the old table and copy the elements from newtbl to hashtbl.
  */
 
-hashtable_rc_t hashtable_resize(hash_table_t * const hashtblP, const hash_size_t sizeP)
-{
-    hash_table_t       newtbl;
-    hash_size_t        n;
-    hash_node_t       *node,*next;
-
-    if (hashtblP == NULL) {
-        return HASH_TABLE_BAD_PARAMETER_HASHTABLE;
-    }
+hashtable_rc_t hashtable_resize(hash_table_t *const hashtblP, const hash_size_t sizeP) {
+  hash_table_t       newtbl;
+  hash_size_t        n;
+  hash_node_t       *node,*next;
 
-    newtbl.size     = sizeP;
-    newtbl.hashfunc = hashtblP->hashfunc;
+  if (hashtblP == NULL) {
+    return HASH_TABLE_BAD_PARAMETER_HASHTABLE;
+  }
 
-    if(!(newtbl.nodes=calloc(sizeP, sizeof(hash_node_t*)))) return -1;
+  newtbl.size     = sizeP;
+  newtbl.hashfunc = hashtblP->hashfunc;
 
-    for(n=0; n<hashtblP->size; ++n) {
-        for(node=hashtblP->nodes[n]; node; node=next) {
-            next = node->next;
-            hashtable_insert(&newtbl, node->key, node->data);
-            // Lionel GAUTHIER: BAD CODE TO BE REWRITTEN
-            hashtable_remove(hashtblP, node->key);
+  if(!(newtbl.nodes=calloc(sizeP, sizeof(hash_node_t *)))) return -1;
 
-        }
+  for(n=0; n<hashtblP->size; ++n) {
+    for(node=hashtblP->nodes[n]; node; node=next) {
+      next = node->next;
+      hashtable_insert(&newtbl, node->key, node->data);
+      // Lionel GAUTHIER: BAD CODE TO BE REWRITTEN
+      hashtable_remove(hashtblP, node->key);
     }
+  }
 
-    free(hashtblP->nodes);
-    hashtblP->size=newtbl.size;
-    hashtblP->nodes=newtbl.nodes;
-
-    return HASH_TABLE_OK;
+  free(hashtblP->nodes);
+  hashtblP->size=newtbl.size;
+  hashtblP->nodes=newtbl.nodes;
+  return HASH_TABLE_OK;
 }
 
 
diff --git a/common/utils/hashtable/hashtable.h b/common/utils/hashtable/hashtable.h
index 62002fb60f89c738d8d2a941d9cd31fac9e268f5..3f770684fae9996f8973b4268f106a6526dafd0b 100644
--- a/common/utils/hashtable/hashtable.h
+++ b/common/utils/hashtable/hashtable.h
@@ -2,9 +2,9 @@
  * 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 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.  
+ * except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *      http://www.openairinterface.org/?page_id=698
@@ -31,41 +31,41 @@ typedef uint64_t hash_key_t;
 #define HASHTABLE_NOT_A_KEY_VALUE ((uint64_t)-1)
 
 typedef enum hashtable_return_code_e {
-    HASH_TABLE_OK                      = 0,
-    HASH_TABLE_INSERT_OVERWRITTEN_DATA = 1,
-    HASH_TABLE_KEY_NOT_EXISTS          = 2,
-    HASH_TABLE_KEY_ALREADY_EXISTS      = 3,
-    HASH_TABLE_BAD_PARAMETER_HASHTABLE = 4,
-    HASH_TABLE_SYSTEM_ERROR            = 5,
-    HASH_TABLE_CODE_MAX
+  HASH_TABLE_OK                      = 0,
+  HASH_TABLE_INSERT_OVERWRITTEN_DATA = 1,
+  HASH_TABLE_KEY_NOT_EXISTS          = 2,
+  HASH_TABLE_KEY_ALREADY_EXISTS      = 3,
+  HASH_TABLE_BAD_PARAMETER_HASHTABLE = 4,
+  HASH_TABLE_SYSTEM_ERROR            = 5,
+  HASH_TABLE_CODE_MAX
 } hashtable_rc_t;
 
 
 typedef struct hash_node_s {
-    hash_key_t          key;
-    void               *data;
-    struct hash_node_s *next;
+  hash_key_t          key;
+  void               *data;
+  struct hash_node_s *next;
 } hash_node_t;
 
 typedef struct hash_table_s {
-	hash_size_t         size;
-	hash_size_t         num_elements;
-	struct hash_node_s **nodes;
-	hash_size_t       (*hashfunc)(const hash_key_t);
-	void              (*freefunc)(void*);
+  hash_size_t         size;
+  hash_size_t         num_elements;
+  struct hash_node_s **nodes;
+  hash_size_t       (*hashfunc)(const hash_key_t);
+  void              (*freefunc)(void *);
 } hash_table_t;
 
-char*           hashtable_rc_code2string(hashtable_rc_t rcP);
-void            hash_free_int_func(void* memoryP);
-hash_table_t   *hashtable_create (const hash_size_t   size, hash_size_t (*hashfunc)(const hash_key_t ), void (*freefunc)(void*));
-hashtable_rc_t  hashtable_destroy(hash_table_t * const hashtbl);
-hashtable_rc_t  hashtable_is_key_exists (const hash_table_t * const hashtbl, const uint64_t key);
-hashtable_rc_t  hashtable_apply_funct_on_elements (hash_table_t * const hashtblP, void funct(hash_key_t keyP, void* dataP, void* parameterP), void* parameterP);
-hashtable_rc_t  hashtable_dump_content (const hash_table_t * const hashtblP, char * const buffer_pP, int * const remaining_bytes_in_buffer_pP );
-hashtable_rc_t  hashtable_insert (hash_table_t * const hashtbl, const hash_key_t key, void *data);
-hashtable_rc_t  hashtable_remove (hash_table_t * const hashtbl, const hash_key_t key);
-hashtable_rc_t  hashtable_get    (const hash_table_t * const hashtbl, const hash_key_t key, void **dataP);
-hashtable_rc_t  hashtable_resize (hash_table_t * const hashtbl, const hash_size_t size);
+char           *hashtable_rc_code2string(hashtable_rc_t rcP);
+void            hash_free_int_func(void *memoryP);
+hash_table_t   *hashtable_create (const hash_size_t   size, hash_size_t (*hashfunc)(const hash_key_t ), void (*freefunc)(void *));
+hashtable_rc_t  hashtable_destroy(hash_table_t **hashtbl);
+hashtable_rc_t  hashtable_is_key_exists (const hash_table_t *const hashtbl, const uint64_t key);
+hashtable_rc_t  hashtable_apply_funct_on_elements (hash_table_t *const hashtblP, void funct(hash_key_t keyP, void *dataP, void *parameterP), void *parameterP);
+hashtable_rc_t  hashtable_dump_content (const hash_table_t *const hashtblP, char *const buffer_pP, int *const remaining_bytes_in_buffer_pP );
+hashtable_rc_t  hashtable_insert (hash_table_t *const hashtbl, const hash_key_t key, void *data);
+hashtable_rc_t  hashtable_remove (hash_table_t *const hashtbl, const hash_key_t key);
+hashtable_rc_t  hashtable_get    (const hash_table_t *const hashtbl, const hash_key_t key, void **dataP);
+hashtable_rc_t  hashtable_resize (hash_table_t *const hashtbl, const hash_size_t size);
 
 
 
diff --git a/common/utils/hashtable/obj_hashtable.c b/common/utils/hashtable/obj_hashtable.c
index 7fb68d16817993c86e75f211e2b0b2c257039e19..643dcce552ad72381f62b38f954e4d217e0ecb5a 100644
--- a/common/utils/hashtable/obj_hashtable.c
+++ b/common/utils/hashtable/obj_hashtable.c
@@ -2,9 +2,9 @@
  * 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 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.  
+ * except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *      http://www.openairinterface.org/?page_id=698
@@ -30,13 +30,12 @@
  * This is a simple/naive hash function which adds the key's ASCII char values. It will probably generate lots of collisions on large hash tables.
  */
 
-static hash_size_t def_hashfunc(const void *keyP, int key_sizeP)
-{
-    hash_size_t hash=0;
+static hash_size_t def_hashfunc(const void *keyP, int key_sizeP) {
+  hash_size_t hash=0;
 
-    while(key_sizeP) hash^=((unsigned char*)keyP)[key_sizeP --];
+  while(key_sizeP) hash^=((unsigned char *)keyP)[key_sizeP --];
 
-    return hash;
+  return hash;
 }
 
 //-------------------------------------------------------------------------------------------------------------------------------
@@ -46,201 +45,221 @@ static hash_size_t def_hashfunc(const void *keyP, int key_sizeP)
  * The user can also specify a hash function. If the hashfunc argument is NULL, a default hash function is used.
  * If an error occurred, NULL is returned. All other values in the returned obj_hash_table_t pointer should be released with hashtable_destroy().
  */
-obj_hash_table_t *obj_hashtable_create(hash_size_t sizeP, hash_size_t (*hashfuncP)(const void*, int ), void (*freekeyfuncP)(void*), void (*freedatafuncP)(void*))
-{
-    obj_hash_table_t *hashtbl;
+obj_hash_table_t *obj_hashtable_create(hash_size_t sizeP, hash_size_t (*hashfuncP)(const void *, int ), void (*freekeyfuncP)(void *), void (*freedatafuncP)(void *)) {
+  obj_hash_table_t *hashtbl;
 
-    if(!(hashtbl=malloc(sizeof(obj_hash_table_t)))) return NULL;
+  if(!(hashtbl=malloc(sizeof(obj_hash_table_t)))) return NULL;
 
-    if(!(hashtbl->nodes=calloc(sizeP, sizeof(obj_hash_node_t*)))) {
-        free(hashtbl);
-        return NULL;
-    }
+  if(!(hashtbl->nodes=calloc(sizeP, sizeof(obj_hash_node_t *)))) {
+    free(hashtbl);
+    return NULL;
+  }
 
-    hashtbl->size=sizeP;
+  hashtbl->size=sizeP;
 
-    if(hashfuncP) hashtbl->hashfunc=hashfuncP;
-    else hashtbl->hashfunc=def_hashfunc;
+  if(hashfuncP) hashtbl->hashfunc=hashfuncP;
+  else hashtbl->hashfunc=def_hashfunc;
 
-    if(freekeyfuncP) hashtbl->freekeyfunc=freekeyfuncP;
-    else hashtbl->freekeyfunc=free;
+  if(freekeyfuncP) hashtbl->freekeyfunc=freekeyfuncP;
+  else hashtbl->freekeyfunc=free;
 
-    if(freedatafuncP) hashtbl->freedatafunc=freedatafuncP;
-    else hashtbl->freedatafunc=free;
+  if(freedatafuncP) hashtbl->freedatafunc=freedatafuncP;
+  else hashtbl->freedatafunc=free;
 
-    return hashtbl;
+  return hashtbl;
 }
 //-------------------------------------------------------------------------------------------------------------------------------
 /*
  * Cleanup
  * The hashtable_destroy() walks through the linked lists for each possible hash value, and releases the elements. It also releases the nodes array and the obj_hash_table_t.
  */
-hashtable_rc_t obj_hashtable_destroy(obj_hash_table_t *hashtblP)
-{
-    hash_size_t n;
-    obj_hash_node_t *node, *oldnode;
+hashtable_rc_t obj_hashtable_destroy(obj_hash_table_t *hashtblP) {
+  hash_size_t n;
+  obj_hash_node_t *node, *oldnode;
 
-    for(n=0; n<hashtblP->size; ++n) {
-        node=hashtblP->nodes[n];
-        while(node) {
-            oldnode=node;
-            node=node->next;
-            hashtblP->freekeyfunc(oldnode->key);
-            hashtblP->freedatafunc(oldnode->data);
-            free(oldnode);
-        }
+  for(n=0; n<hashtblP->size; ++n) {
+    node=hashtblP->nodes[n];
+
+    while(node) {
+      oldnode=node;
+      node=node->next;
+      hashtblP->freekeyfunc(oldnode->key);
+      hashtblP->freedatafunc(oldnode->data);
+      free(oldnode);
     }
-    free(hashtblP->nodes);
-    free(hashtblP);
-    return HASH_TABLE_OK;
+  }
+
+  free(hashtblP->nodes);
+  free(hashtblP);
+  return HASH_TABLE_OK;
 }
 //-------------------------------------------------------------------------------------------------------------------------------
-hashtable_rc_t obj_hashtable_is_key_exists (obj_hash_table_t *hashtblP, void* keyP, int key_sizeP)
+hashtable_rc_t obj_hashtable_is_key_exists (obj_hash_table_t *hashtblP, void *keyP, int key_sizeP)
 //-------------------------------------------------------------------------------------------------------------------------------
 {
-    obj_hash_node_t *node;
-    hash_size_t      hash;
+  obj_hash_node_t *node;
+  hash_size_t      hash;
 
-    if (hashtblP == NULL) {
-        return HASH_TABLE_BAD_PARAMETER_HASHTABLE;
-    }
-    hash=hashtblP->hashfunc(keyP, key_sizeP)%hashtblP->size;
-    node=hashtblP->nodes[hash];
-    while(node) {
-        if(node->key == keyP) {
-            return HASH_TABLE_OK;
-        } else if (node->key_size == key_sizeP) {
-            if (memcmp(node->key, keyP, key_sizeP) == 0) {
-                return HASH_TABLE_OK;
-            }
-        }
-        node=node->next;
+  if (hashtblP == NULL) {
+    return HASH_TABLE_BAD_PARAMETER_HASHTABLE;
+  }
+
+  hash=hashtblP->hashfunc(keyP, key_sizeP)%hashtblP->size;
+  node=hashtblP->nodes[hash];
+
+  while(node) {
+    if(node->key == keyP) {
+      return HASH_TABLE_OK;
+    } else if (node->key_size == key_sizeP) {
+      if (memcmp(node->key, keyP, key_sizeP) == 0) {
+        return HASH_TABLE_OK;
+      }
     }
-    return HASH_TABLE_KEY_NOT_EXISTS;
+
+    node=node->next;
+  }
+
+  return HASH_TABLE_KEY_NOT_EXISTS;
 }
 //-------------------------------------------------------------------------------------------------------------------------------
 /*
  * Adding a new element
  * To make sure the hash value is not bigger than size, the result of the user provided hash function is used modulo size.
  */
-hashtable_rc_t obj_hashtable_insert(obj_hash_table_t *hashtblP, void* keyP, int key_sizeP, void *dataP)
-{
-    obj_hash_node_t *node;
-    hash_size_t      hash;
+hashtable_rc_t obj_hashtable_insert(obj_hash_table_t *hashtblP, void *keyP, int key_sizeP, void *dataP) {
+  obj_hash_node_t *node;
+  hash_size_t      hash;
 
-    if (hashtblP == NULL) {
-        return HASH_TABLE_BAD_PARAMETER_HASHTABLE;
-    }
-    hash=hashtblP->hashfunc(keyP, key_sizeP)%hashtblP->size;
-    node=hashtblP->nodes[hash];
-    while(node) {
-        if(node->key == keyP) {
-            if (node->data) {
-                hashtblP->freedatafunc(node->data);
-            }
-            node->data=dataP;
-            // waste of memory here (keyP is lost) we should free it now
-            return HASH_TABLE_INSERT_OVERWRITTEN_DATA;
-        }
-        node=node->next;
-    }
-    if(!(node=malloc(sizeof(obj_hash_node_t)))) return -1;
-    node->key=keyP;
-    node->data=dataP;
-    if (hashtblP->nodes[hash]) {
-        node->next=hashtblP->nodes[hash];
-    } else {
-        node->next = NULL;
+  if (hashtblP == NULL) {
+    return HASH_TABLE_BAD_PARAMETER_HASHTABLE;
+  }
+
+  hash=hashtblP->hashfunc(keyP, key_sizeP)%hashtblP->size;
+  node=hashtblP->nodes[hash];
+
+  while(node) {
+    if(node->key == keyP) {
+      if (node->data) {
+        hashtblP->freedatafunc(node->data);
+      }
+
+      node->data=dataP;
+      // waste of memory here (keyP is lost) we should free it now
+      return HASH_TABLE_INSERT_OVERWRITTEN_DATA;
     }
-    hashtblP->nodes[hash]=node;
-    return HASH_TABLE_OK;
+
+    node=node->next;
+  }
+
+  if(!(node=malloc(sizeof(obj_hash_node_t)))) return -1;
+
+  node->key=keyP;
+  node->data=dataP;
+
+  if (hashtblP->nodes[hash]) {
+    node->next=hashtblP->nodes[hash];
+  } else {
+    node->next = NULL;
+  }
+
+  hashtblP->nodes[hash]=node;
+  return HASH_TABLE_OK;
 }
 //-------------------------------------------------------------------------------------------------------------------------------
 /*
  * To remove an element from the hash table, we just search for it in the linked list for that hash value,
  * and remove it if it is found. If it was not found, it is an error and -1 is returned.
  */
-hashtable_rc_t obj_hashtable_remove(obj_hash_table_t *hashtblP, const void* keyP, int key_sizeP)
-{
-    obj_hash_node_t *node, *prevnode=NULL;
-    hash_size_t      hash;
+hashtable_rc_t obj_hashtable_remove(obj_hash_table_t *hashtblP, const void *keyP, int key_sizeP) {
+  obj_hash_node_t *node, *prevnode=NULL;
+  hash_size_t      hash;
 
-    if (hashtblP == NULL) {
-        return HASH_TABLE_BAD_PARAMETER_HASHTABLE;
-    }
+  if (hashtblP == NULL) {
+    return HASH_TABLE_BAD_PARAMETER_HASHTABLE;
+  }
 
-    hash=hashtblP->hashfunc(keyP, key_sizeP)%hashtblP->size;
-    node=hashtblP->nodes[hash];
-    while(node) {
-        if ((node->key == keyP) || ((node->key_size == key_sizeP) && (memcmp(node->key, keyP, key_sizeP) == 0))){
-            if(prevnode) {
-                prevnode->next=node->next;
-            } else {
-                hashtblP->nodes[hash]=node->next;
-            }
-            hashtblP->freekeyfunc(node->key);
-            hashtblP->freedatafunc(node->data);
-            free(node);
-            return HASH_TABLE_OK;
-        }
-        prevnode=node;
-        node=node->next;
+  hash=hashtblP->hashfunc(keyP, key_sizeP)%hashtblP->size;
+  node=hashtblP->nodes[hash];
+
+  while(node) {
+    if ((node->key == keyP) || ((node->key_size == key_sizeP) && (memcmp(node->key, keyP, key_sizeP) == 0))) {
+      if(prevnode) {
+        prevnode->next=node->next;
+      } else {
+        hashtblP->nodes[hash]=node->next;
+      }
+
+      hashtblP->freekeyfunc(node->key);
+      hashtblP->freedatafunc(node->data);
+      free(node);
+      return HASH_TABLE_OK;
     }
-    return HASH_TABLE_KEY_NOT_EXISTS;
+
+    prevnode=node;
+    node=node->next;
+  }
+
+  return HASH_TABLE_KEY_NOT_EXISTS;
 }
 //-------------------------------------------------------------------------------------------------------------------------------
 /*
  * Searching for an element is easy. We just search through the linked list for the corresponding hash value.
  * NULL is returned if we didn't find it.
  */
-hashtable_rc_t obj_hashtable_get(obj_hash_table_t *hashtblP, const void* keyP, int key_sizeP, void** dataP)
-{
-    obj_hash_node_t *node;
-    hash_size_t      hash;
+hashtable_rc_t obj_hashtable_get(obj_hash_table_t *hashtblP, const void *keyP, int key_sizeP, void **dataP) {
+  obj_hash_node_t *node;
+  hash_size_t      hash;
 
-    if (hashtblP == NULL) {
-        *dataP = NULL;
-        return HASH_TABLE_BAD_PARAMETER_HASHTABLE;
-    }
-    hash=hashtblP->hashfunc(keyP, key_sizeP)%hashtblP->size;
-    node=hashtblP->nodes[hash];
-    while(node) {
-        if(node->key == keyP) {
-            *dataP = node->data;
-            return HASH_TABLE_OK;
-        } else if (node->key_size == key_sizeP) {
-            if (memcmp(node->key, keyP, key_sizeP) == 0) {
-                *dataP = node->data;
-                return HASH_TABLE_OK;
-            }
-        }
-        node=node->next;
-    }
+  if (hashtblP == NULL) {
     *dataP = NULL;
-    return HASH_TABLE_KEY_NOT_EXISTS;
+    return HASH_TABLE_BAD_PARAMETER_HASHTABLE;
+  }
+
+  hash=hashtblP->hashfunc(keyP, key_sizeP)%hashtblP->size;
+  node=hashtblP->nodes[hash];
+
+  while(node) {
+    if(node->key == keyP) {
+      *dataP = node->data;
+      return HASH_TABLE_OK;
+    } else if (node->key_size == key_sizeP) {
+      if (memcmp(node->key, keyP, key_sizeP) == 0) {
+        *dataP = node->data;
+        return HASH_TABLE_OK;
+      }
+    }
+
+    node=node->next;
+  }
+
+  *dataP = NULL;
+  return HASH_TABLE_KEY_NOT_EXISTS;
 }
 //-------------------------------------------------------------------------------------------------------------------------------
 /*
  * Function to return all keys of an object hash table
  */
-hashtable_rc_t obj_hashtable_get_keys(obj_hash_table_t *hashtblP, void ** keysP, unsigned int *sizeP)
-{
-    size_t                 n     = 0;
-    obj_hash_node_t       *node  = NULL;
-    obj_hash_node_t       *next  = NULL;
-
-    *sizeP = 0;
-    keysP = calloc(hashtblP->num_elements, sizeof(void *));
-    if (keysP) {
-        for(n=0; n<hashtblP->size; ++n) {
-            for(node=hashtblP->nodes[n]; node; node=next) {
-                keysP[*sizeP++] = node->key;
-                next = node->next;
-            }
-        }
-        return HASH_TABLE_OK;
+
+hashtable_rc_t obj_hashtable_get_keys(obj_hash_table_t *hashtblP, void **keysP, unsigned int *sizeP) {
+  size_t                 n     = 0;
+  obj_hash_node_t       *node  = NULL;
+  obj_hash_node_t       *next  = NULL;
+  *sizeP = 0;
+  keysP = calloc(hashtblP->num_elements, sizeof(void *));
+
+  if (keysP) {
+    for(n=0; n<hashtblP->size; ++n) {
+      for(node=hashtblP->nodes[n]; node; node=next) {
+        keysP[*sizeP++] = node->key;
+        next = node->next;
+      }
     }
-    return HASH_TABLE_SYSTEM_ERROR;
+
+    // cppcheck-suppress memleak
+    return HASH_TABLE_OK;
+  }
+
+  return HASH_TABLE_SYSTEM_ERROR;
 }
 //-------------------------------------------------------------------------------------------------------------------------------
 /*
@@ -253,34 +272,32 @@ hashtable_rc_t obj_hashtable_get_keys(obj_hash_table_t *hashtblP, void ** keysP,
  * This allows us to reuse hashtable_insert() and hashtable_remove(), when moving the elements to the new table.
  * After that, we can just free the old table and copy the elements from newtbl to hashtbl.
  */
-hashtable_rc_t obj_hashtable_resize(obj_hash_table_t *hashtblP, hash_size_t sizeP)
-{
-    obj_hash_table_t       newtbl;
-    hash_size_t        n;
-    obj_hash_node_t       *node,*next;
+hashtable_rc_t obj_hashtable_resize(obj_hash_table_t *hashtblP, hash_size_t sizeP) {
+  obj_hash_table_t       newtbl;
+  hash_size_t        n;
+  obj_hash_node_t       *node,*next;
 
-    if (hashtblP == NULL) {
-        return HASH_TABLE_BAD_PARAMETER_HASHTABLE;
-    }
+  if (hashtblP == NULL) {
+    return HASH_TABLE_BAD_PARAMETER_HASHTABLE;
+  }
 
-    newtbl.size     = sizeP;
-    newtbl.hashfunc = hashtblP->hashfunc;
+  newtbl.size     = sizeP;
+  newtbl.hashfunc = hashtblP->hashfunc;
 
-    if(!(newtbl.nodes=calloc(sizeP, sizeof(obj_hash_node_t*)))) return HASH_TABLE_SYSTEM_ERROR;
+  if(!(newtbl.nodes=calloc(sizeP, sizeof(obj_hash_node_t *)))) return HASH_TABLE_SYSTEM_ERROR;
 
-    for(n=0; n<hashtblP->size; ++n) {
-        for(node=hashtblP->nodes[n]; node; node=next) {
-            next = node->next;
-            obj_hashtable_insert(&newtbl, node->key, node->key_size, node->data);
-            obj_hashtable_remove(hashtblP, node->key, node->key_size);
-        }
+  for(n=0; n<hashtblP->size; ++n) {
+    for(node=hashtblP->nodes[n]; node; node=next) {
+      next = node->next;
+      obj_hashtable_insert(&newtbl, node->key, node->key_size, node->data);
+      obj_hashtable_remove(hashtblP, node->key, node->key_size);
     }
+  }
 
-    free(hashtblP->nodes);
-    hashtblP->size=newtbl.size;
-    hashtblP->nodes=newtbl.nodes;
-
-    return HASH_TABLE_OK;
+  free(hashtblP->nodes);
+  hashtblP->size=newtbl.size;
+  hashtblP->nodes=newtbl.nodes;
+  return HASH_TABLE_OK;
 }
 
 
diff --git a/common/utils/memory_pools.c b/common/utils/memory_pools.c
index 78b6923dc863f982683d57a126c539651ef3817d..9f37e4708083dfa9139186da76ac2aa57db88671 100644
--- a/common/utils/memory_pools.c
+++ b/common/utils/memory_pools.c
@@ -23,19 +23,19 @@
 #include "memory_pools.h"
 
 #if T_TRACER
-#include <string.h>
-#include "T.h"
+  #include <string.h>
+  #include "T.h"
 #endif
 
 /*------------------------------------------------------------------------------*/
 const static int mp_debug = 0;
 
 # define MP_DEBUG(x, args...) do { if (mp_debug) fprintf(stdout, "[MP][D]"x, ##args); fflush (stdout); } \
-    while(0)
+  while(0)
 
 /*------------------------------------------------------------------------------*/
 #ifndef CHARS_TO_UINT32
-#define CHARS_TO_UINT32(c1, c2, c3, c4) (((c1) << 24) | ((c2) << 16) | ((c3) << 8) | (c4))
+  #define CHARS_TO_UINT32(c1, c2, c3, c4) (((c1) << 24) | ((c2) << 16) | ((c3) << 8) | (c4))
 #endif
 
 #define MEMORY_POOL_ITEM_INFO_NUMBER    2
@@ -129,33 +129,25 @@ static const pool_start_mark_t      POOL_START_MARK =       CHARS_TO_UINT32 ('P'
 static const pools_start_mark_t     POOLS_START_MARK =      CHARS_TO_UINT32 ('P', 'S', 's', 't');
 
 /*------------------------------------------------------------------------------*/
-static inline uint32_t items_group_number_items (items_group_t *items_group)
-{
+static inline uint32_t items_group_number_items (items_group_t *items_group) {
   return items_group->number_plus_one - 1;
 }
 
-static inline uint32_t items_group_free_items (items_group_t *items_group)
-{
+static inline uint32_t items_group_free_items (items_group_t *items_group) {
   items_group_positions_t positions;
   uint32_t                free_items;
-
   positions.all = items_group->positions.all;
-
   free_items = items_group->number_plus_one + positions.ind.put - positions.ind.get;
   free_items %= items_group->number_plus_one;
-
   return free_items;
 }
 
-static inline items_group_index_t items_group_get_free_item (items_group_t *items_group)
-{
+static inline items_group_index_t items_group_get_free_item (items_group_t *items_group) {
   items_group_position_t  get_raw;
   items_group_position_t  put;
   items_group_position_t  get;
   items_group_position_t  free_items;
-
   items_group_index_t     index = ITEMS_GROUP_INDEX_INVALID;
-
   /* Get current put position */
   put = items_group->positions.ind.put % items_group->number_plus_one;
   /* Get current get position and increase it */
@@ -193,11 +185,9 @@ static inline items_group_index_t items_group_get_free_item (items_group_t *item
   return (index);
 }
 
-static inline int items_group_put_free_item (items_group_t *items_group, items_group_index_t index)
-{
+static inline int items_group_put_free_item (items_group_t *items_group, items_group_index_t index) {
   items_group_position_t  put_raw;
   items_group_position_t  put;
-
   /* Get current put position and increase it */
   put_raw = __sync_fetch_and_add (&items_group->positions.ind.put, 1);
   put = put_raw % items_group->number_plus_one;
@@ -209,70 +199,54 @@ static inline int items_group_put_free_item (items_group_t *items_group, items_g
 
   AssertError (items_group->indexes[put] <= ITEMS_GROUP_INDEX_INVALID, return (EXIT_FAILURE),
                "Index at current put position (%d) is not marked as free (%d)!\n", put, items_group->number_plus_one);
-
   /* Save freed item index at current put position */
   items_group->indexes[put] = index;
   return (EXIT_SUCCESS);
 }
 
 /*------------------------------------------------------------------------------*/
-static inline memory_pools_t *memory_pools_from_handler (memory_pools_handle_t memory_pools_handle)
-{
+static inline memory_pools_t *memory_pools_from_handler (memory_pools_handle_t memory_pools_handle) {
   memory_pools_t *memory_pools;
-
   /* Recover memory_pools */
   memory_pools = (memory_pools_t *) memory_pools_handle;
   /* Sanity check on passed handle */
   AssertError (memory_pools->start_mark == POOLS_START_MARK, memory_pools = NULL,
                "Handle %p is not a valid memory pools handle, start mark is missing!\n", memory_pools_handle);
-
   return (memory_pools);
 }
 
-static inline memory_pool_item_t *memory_pool_item_from_handler (memory_pool_item_handle_t memory_pool_item_handle)
-{
+static inline memory_pool_item_t *memory_pool_item_from_handler (memory_pool_item_handle_t memory_pool_item_handle) {
   void               *address;
   memory_pool_item_t *memory_pool_item;
-
   /* Recover memory_pools */
   address = memory_pool_item_handle - sizeof(memory_pool_item_start_t);
   memory_pool_item = (memory_pool_item_t *) address;
-
   /* Sanity check on passed handle */
   AssertError (memory_pool_item->start.start_mark == POOL_ITEM_START_MARK, memory_pool_item = NULL,
                "Handle %p is not a valid memory pool item handle, start mark is missing!\n", memory_pool_item);
-
   return (memory_pool_item);
 }
 
-static inline memory_pool_item_t *memory_pool_item_from_index (memory_pool_t *memory_pool, items_group_index_t index)
-{
+static inline memory_pool_item_t *memory_pool_item_from_index (memory_pool_t *memory_pool, items_group_index_t index) {
   void               *address;
-
   address = (void *) memory_pool->items;
   address += index * memory_pool->pool_item_size;
-
   return (address);
 }
 
 /*------------------------------------------------------------------------------*/
-memory_pools_handle_t memory_pools_create (uint32_t pools_number)
-{
+memory_pools_handle_t memory_pools_create (uint32_t pools_number) {
   memory_pools_t *memory_pools;
   pool_id_t       pool;
-
   AssertFatal (pools_number <= MAX_POOLS_NUMBER, "Too many memory pools requested (%d/%d)!\n", pools_number, MAX_POOLS_NUMBER); /* Limit to a reasonable number of pools */
-
   /* Allocate memory_pools */
   memory_pools = malloc (sizeof(memory_pools_t));
   AssertFatal (memory_pools != NULL, "Memory pools structure allocation failed!\n");
-
   /* Initialize memory_pools */
   {
     memory_pools->start_mark    = POOLS_START_MARK;
     memory_pools->pools_number  = pools_number;
     memory_pools->pools_defined = 0;
-
     /* Allocate pools */
     memory_pools->pools         = calloc (pools_number, sizeof(memory_pool_t));
     AssertFatal (memory_pools->pools != NULL, "Memory pools allocation failed!\n");
@@ -282,12 +256,10 @@ memory_pools_handle_t memory_pools_create (uint32_t pools_number)
       memory_pools->pools[pool].start_mark = POOL_START_MARK;
     }
   }
-
   return ((memory_pools_handle_t) memory_pools);
 }
 
-char *memory_pools_statistics(memory_pools_handle_t memory_pools_handle)
-{
+char *memory_pools_statistics(memory_pools_handle_t memory_pools_handle) {
   memory_pools_t     *memory_pools;
   pool_id_t           pool;
   char               *statistics;
@@ -296,13 +268,10 @@ char *memory_pools_statistics(memory_pools_handle_t memory_pools_handle)
   uint32_t            allocated_pools_memory = 0;
   items_group_t      *items_group;
   uint32_t            pool_items_size;
-
   /* Recover memory_pools */
   memory_pools = memory_pools_from_handler (memory_pools_handle);
   AssertFatal (memory_pools != NULL, "Failed to retrieve memory pool for handle %p!\n", memory_pools_handle);
-
   statistics = malloc(memory_pools->pools_defined * 200);
-
   printed_chars = sprintf (&statistics[0], "Pool:   size, number, minimum,   free, address space and memory used in Kbytes\n");
 
   for (pool = 0; pool < memory_pools->pools_defined; pool++) {
@@ -321,32 +290,25 @@ char *memory_pools_statistics(memory_pools_handle_t memory_pools_handle)
   }
 
   printed_chars = sprintf (&statistics[printed_chars], "Pools memory %u Kbytes\n", allocated_pools_memory / (1024));
-
   return (statistics);
 }
 
-int memory_pools_add_pool (memory_pools_handle_t memory_pools_handle, uint32_t pool_items_number, uint32_t pool_item_size)
-{
+int memory_pools_add_pool (memory_pools_handle_t memory_pools_handle, uint32_t pool_items_number, uint32_t pool_item_size) {
   memory_pools_t     *memory_pools;
   memory_pool_t      *memory_pool;
   pool_id_t           pool;
   items_group_index_t item_index;
   memory_pool_item_t *memory_pool_item;
-
   AssertFatal (pool_items_number <= MAX_POOL_ITEMS_NUMBER, "Too many items for a memory pool (%u/%d)!\n", pool_items_number, MAX_POOL_ITEMS_NUMBER); /* Limit to a reasonable number of items */
   AssertFatal (pool_item_size <= MAX_POOL_ITEM_SIZE, "Item size is too big for memory pool items (%u/%d)!\n", pool_item_size, MAX_POOL_ITEM_SIZE);   /* Limit to a reasonable item size */
-
   /* Recover memory_pools */
   memory_pools    = memory_pools_from_handler (memory_pools_handle);
   AssertFatal (memory_pools != NULL, "Failed to retrieve memory pool for handle %p!\n", memory_pools_handle);
-
   /* Check number of already created pools */
   AssertFatal (memory_pools->pools_defined < memory_pools->pools_number, "Can not allocate more memory pool (%d)!\n", memory_pools->pools_number);
-
   /* Select pool */
   pool            = memory_pools->pools_defined;
   memory_pool     = &memory_pools->pools[pool];
-
   /* Initialize pool */
   {
     memory_pool->pool_id                            = pool;
@@ -357,7 +319,6 @@ int memory_pools_add_pool (memory_pools_handle_t memory_pools_handle, uint32_t p
     memory_pool->items_group_free.minimum           = pool_items_number;
     memory_pool->items_group_free.positions.ind.put = pool_items_number;
     memory_pool->items_group_free.positions.ind.get = 0;
-
     /* Allocate free indexes */
     memory_pool->items_group_free.indexes = malloc(memory_pool->items_group_free.number_plus_one * sizeof(items_group_index_t));
     AssertFatal (memory_pool->items_group_free.indexes != NULL, "Memory pool indexes allocation failed!\n");
@@ -369,7 +330,6 @@ int memory_pools_add_pool (memory_pools_handle_t memory_pools_handle, uint32_t p
 
     /* Last index is not allocated */
     memory_pool->items_group_free.indexes[item_index] = ITEMS_GROUP_INDEX_INVALID;
-
     /* Allocate items */
     memory_pool->items = calloc (pool_items_number, memory_pool->pool_item_size);
     AssertFatal (memory_pool->items != NULL, "Memory pool items allocation failed!\n");
@@ -383,20 +343,16 @@ int memory_pools_add_pool (memory_pools_handle_t memory_pools_handle, uint32_t p
       memory_pool_item->data[memory_pool->item_data_number] = POOL_ITEM_END_MARK;
     }
   }
-
   memory_pools->pools_defined ++;
-
   return (0);
 }
 
-memory_pool_item_handle_t memory_pools_allocate (memory_pools_handle_t memory_pools_handle, uint32_t item_size, uint16_t info_0, uint16_t info_1)
-{
+memory_pool_item_handle_t memory_pools_allocate (memory_pools_handle_t memory_pools_handle, uint32_t item_size, uint16_t info_0, uint16_t info_1) {
   memory_pools_t             *memory_pools;
   memory_pool_item_t         *memory_pool_item;
   memory_pool_item_handle_t   memory_pool_item_handle = NULL;
   pool_id_t                   pool;
   items_group_index_t         item_index = ITEMS_GROUP_INDEX_INVALID;
-
   /* Recover memory_pools */
   memory_pools = memory_pools_from_handler (memory_pools_handle);
   AssertError (memory_pools != NULL, {}, "Failed to retrieve memory pool for handle %p!\n", memory_pools_handle);
@@ -424,12 +380,10 @@ memory_pool_item_handle_t memory_pools_allocate (memory_pools_handle_t memory_po
     /* Sanity check on item status, must be free */
     AssertFatal (memory_pool_item->start.item_status == ITEM_STATUS_FREE, "Item status is not set to free (%d) in pool %u, item %d!\n",
                  memory_pool_item->start.item_status, pool, item_index);
-
     memory_pool_item->start.item_status = ITEM_STATUS_ALLOCATED;
     memory_pool_item->start.info[0]     = info_0;
     memory_pool_item->start.info[1]     = info_1;
     memory_pool_item_handle             = memory_pool_item->data;
-
     MP_DEBUG(" Alloc [%2u][%6d]{%6d}, %3u %3u, %6u, %p, %p, %p\n",
              pool, item_index,
              items_group_free_items (&memory_pools->pools[pool].items_group_free),
@@ -445,8 +399,7 @@ memory_pool_item_handle_t memory_pools_allocate (memory_pools_handle_t memory_po
   return memory_pool_item_handle;
 }
 
-int memory_pools_free (memory_pools_handle_t memory_pools_handle, memory_pool_item_handle_t memory_pool_item_handle, uint16_t info_0)
-{
+int memory_pools_free (memory_pools_handle_t memory_pools_handle, memory_pool_item_handle_t memory_pool_item_handle, uint16_t info_0) {
   memory_pools_t     *memory_pools;
   memory_pool_item_t *memory_pool_item;
   pool_id_t           pool;
@@ -455,36 +408,29 @@ int memory_pools_free (memory_pools_handle_t memory_pools_handle, memory_pool_it
   uint32_t            pool_item_size;
   uint16_t            info_1;
   int                 result;
-
   /* Recover memory_pools */
   memory_pools = memory_pools_from_handler (memory_pools_handle);
   AssertError (memory_pools != NULL, return (EXIT_FAILURE), "Failed to retrieve memory pools for handle %p!\n", memory_pools_handle);
-
   /* Recover memory pool item */
   memory_pool_item = memory_pool_item_from_handler (memory_pool_item_handle);
   AssertError (memory_pool_item != NULL, return (EXIT_FAILURE), "Failed to retrieve memory pool item for handle %p!\n", memory_pool_item_handle);
-
   info_1 = memory_pool_item->start.info[1];
-
   /* Recover pool index */
   pool = memory_pool_item->start.pool_id;
   AssertFatal (pool < memory_pools->pools_defined, "Pool index is invalid (%u/%u)!\n", pool, memory_pools->pools_defined);
-
   item_size = memory_pools->pools[pool].item_data_number;
   pool_item_size = memory_pools->pools[pool].pool_item_size;
   item_index = (((void *) memory_pool_item) - ((void *) memory_pools->pools[pool].items)) / pool_item_size;
-
   MP_DEBUG(" Free  [%2u][%6d]{%6d}, %3u %3u,         %p, %p, %p, %u\n",
            pool, item_index,
            items_group_free_items (&memory_pools->pools[pool].items_group_free),
            memory_pool_item->start.info[0], info_1,
            memory_pool_item_handle, memory_pool_item,
            memory_pools->pools[pool].items, ((uint32_t) (item_size * sizeof(memory_pool_data_t))));
-
   /* Sanity check on calculated item index */
   AssertFatal (memory_pool_item == memory_pool_item_from_index(&memory_pools->pools[pool], item_index),
                "Incorrect memory pool item address (%p, %p) for pool %u, item %d!\n",
-               memory_pool_item, memory_pool_item_from_index(&memory_pools->pools[pool], item_index), pool, item_index);
+               memory_pool_item,(void *)memory_pool_item_from_index(&memory_pools->pools[pool], item_index), pool, item_index);
   /* Sanity check on end marker, must still be present (no write overflow) */
   AssertFatal (memory_pool_item->data[item_size] == POOL_ITEM_END_MARK,
                "Memory pool item is corrupted, end mark is not present for pool %u, item %d!\n", pool, item_index);
@@ -492,31 +438,23 @@ int memory_pools_free (memory_pools_handle_t memory_pools_handle, memory_pool_it
   AssertFatal (memory_pool_item->start.item_status == ITEM_STATUS_ALLOCATED,
                "Trying to free a non allocated (%x) memory pool item (pool %u, item %d)!\n",
                memory_pool_item->start.item_status, pool, item_index);
-
   memory_pool_item->start.item_status = ITEM_STATUS_FREE;
-
   result = items_group_put_free_item(&memory_pools->pools[pool].items_group_free, item_index);
-
   AssertError (result == EXIT_SUCCESS, {}, "Failed to free memory pool item (pool %u, item %d)!\n", pool, item_index);
-
   return (result);
 }
 
-void memory_pools_set_info (memory_pools_handle_t memory_pools_handle, memory_pool_item_handle_t memory_pool_item_handle, int index, uint16_t info)
-{
+void memory_pools_set_info (memory_pools_handle_t memory_pools_handle, memory_pool_item_handle_t memory_pool_item_handle, int index, uint16_t info) {
   memory_pools_t     *memory_pools;
   memory_pool_item_t *memory_pool_item;
   pool_id_t           pool;
   items_group_index_t item_index;
   uint32_t            item_size;
   uint32_t            pool_item_size;
-
   AssertFatal (index < MEMORY_POOL_ITEM_INFO_NUMBER, "Incorrect info index (%d/%d)!\n", index, MEMORY_POOL_ITEM_INFO_NUMBER);
-
   /* Recover memory pool item */
   memory_pool_item = memory_pool_item_from_handler (memory_pool_item_handle);
   AssertFatal (memory_pool_item != NULL, "Failed to retrieve memory pool item for handle %p!\n", memory_pool_item_handle);
-
   /* Set info[1] */
   memory_pool_item->start.info[index] = info;
 
@@ -525,26 +463,22 @@ void memory_pools_set_info (memory_pools_handle_t memory_pools_handle, memory_po
     /* Recover memory_pools */
     memory_pools = memory_pools_from_handler (memory_pools_handle);
     AssertFatal (memory_pools != NULL, "Failed to retrieve memory pool for handle %p!\n", memory_pools_handle);
-
     /* Recover pool index */
     pool = memory_pool_item->start.pool_id;
     AssertFatal (pool < memory_pools->pools_defined, "Pool index is invalid (%u/%u)!\n", pool, memory_pools->pools_defined);
-
     item_size = memory_pools->pools[pool].item_data_number;
     pool_item_size = memory_pools->pools[pool].pool_item_size;
     item_index = (((void *) memory_pool_item) - ((void *) memory_pools->pools[pool].items)) / pool_item_size;
-
     MP_DEBUG(" Info  [%2u][%6d]{%6d}, %3u %3u,         %p, %p, %p, %u\n",
              pool, item_index,
              items_group_free_items (&memory_pools->pools[pool].items_group_free),
              memory_pool_item->start.info[0], memory_pool_item->start.info[1],
              memory_pool_item_handle, memory_pool_item,
              memory_pools->pools[pool].items, ((uint32_t) (item_size * sizeof(memory_pool_data_t))));
-
     /* Sanity check on calculated item index */
     AssertFatal (memory_pool_item == memory_pool_item_from_index(&memory_pools->pools[pool], item_index),
                  "Incorrect memory pool item address (%p, %p) for pool %u, item %d!\n",
-                 memory_pool_item, memory_pool_item_from_index(&memory_pools->pools[pool], item_index), pool, item_index);
+                 memory_pool_item, (void *)memory_pool_item_from_index(&memory_pools->pools[pool], item_index), pool, item_index);
     /* Sanity check on end marker, must still be present (no write overflow) */
     AssertFatal (memory_pool_item->data[item_size] == POOL_ITEM_END_MARK,
                  "Memory pool item is corrupted, end mark is not present for pool %u, item %d!\n", pool, item_index);
diff --git a/common/utils/msc/msc.c b/common/utils/msc/msc.c
index c3cdc029c27973bc6cf62508c0885cf5205eb621..cc5ed17bc73fd450553c31e1277fa526d078de14 100644
--- a/common/utils/msc/msc.c
+++ b/common/utils/msc/msc.c
@@ -49,7 +49,7 @@
 
 //-------------------------------
 
-FILE*    g_msc_fd;
+FILE    *g_msc_fd;
 char     g_msc_proto2str[MAX_MSC_PROTOS][MSC_MAX_PROTO_NAME_LENGTH];
 
 
@@ -70,15 +70,11 @@ void *msc_task(void *args_p)
 //------------------------------------------------------------------------------
 {
   MessageDef         *received_message_p    = NULL;
-//  const char         *msg_name = NULL;
-//  instance_t          instance  = 0;
+  //  const char         *msg_name = NULL;
+  //  instance_t          instance  = 0;
   long                timer_id;
-
   itti_mark_task_ready(TASK_MSC);
-
   msc_start_use();
-
-
   timer_setup(0, // seconds
               50000, // usec
               TASK_MSC,
@@ -91,20 +87,18 @@ void *msc_task(void *args_p)
     itti_receive_msg(TASK_MSC, &received_message_p);
 
     if (received_message_p != NULL) {
-//      msg_name = ITTI_MSG_NAME (received_message_p);
-//      instance = ITTI_MSG_INSTANCE (received_message_p);
-      
+      //      msg_name = ITTI_MSG_NAME (received_message_p);
+      //      instance = ITTI_MSG_INSTANCE (received_message_p);
       switch (ITTI_MSG_ID(received_message_p)) {
-
         case TIMER_HAS_EXPIRED: {
-    	  msc_flush_messages();
+          msc_flush_messages();
         }
         break;
 
         case TERMINATE_MESSAGE: {
           fprintf(stderr, " *** Exiting MSC thread\n");
           timer_remove(timer_id);
-    	  msc_end();
+          msc_end();
           itti_exit_task();
         }
         break;
@@ -119,6 +113,7 @@ void *msc_task(void *args_p)
       }
     }
   }
+
   fprintf(stderr, "Task MSC exiting\n");
   return NULL;
 }
@@ -132,15 +127,16 @@ int msc_init(const msc_env_t envP, const int max_threadsP)
   void *pointer_p;
   char  msc_filename[256];
   fprintf(stderr, "Initializing MSC logs\n");
+  rv = snprintf(msc_filename, 256, "/tmp/openair.msc.%i.log", envP); // TODO NAME
 
-  rv = snprintf(msc_filename, 256, "/tmp/openair.msc.%u.log", envP); // TODO NAME
-  if ((0 >= rv) || (256 < rv)){
+  if ((0 >= rv) || (256 < rv)) {
     fprintf(stderr, "Error in MSC log file name");
   }
+
   g_msc_fd = fopen(msc_filename,"w");
   AssertFatal(g_msc_fd != NULL, "Could not open MSC log file %s : %s", msc_filename, strerror(errno));
-
   rv = lfds611_stack_new(&g_msc_memory_stack_p, (lfds611_atom_t)max_threadsP + 2);
+
   if (0 >= rv) {
     AssertFatal (0, "lfds611_stack_new failed!\n");
   }
@@ -153,7 +149,7 @@ int msc_init(const msc_env_t envP, const int max_threadsP)
   for (i=0; i < max_threadsP * 30; i++) {
     pointer_p = malloc(MSC_MAX_MESSAGE_LENGTH);
     AssertFatal (pointer_p, "malloc failed!\n");
- 	rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, pointer_p );
+    rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, pointer_p );
     AssertFatal (rv, "lfds611_stack_guaranteed_push failed for item %u\n", i);
   }
 
@@ -161,176 +157,324 @@ int msc_init(const msc_env_t envP, const int max_threadsP)
     switch (i) {
       case MSC_IP_UE:
         rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "IP_UE");
-        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
+
+        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
+          g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
+        }
+
         if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
           msc_log_declare_proto(i);
         }
+
         break;
+
       case MSC_IP_ENB:
         rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "IP_ENB");
-        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
+
+        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
+          g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
+        }
+
         if (envP == MSC_E_UTRAN_LIPA) {
           msc_log_declare_proto(i);
         }
+
         break;
+
       case MSC_NAS_UE:
         rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "NAS_UE");
-        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
+
+        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
+          g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
+        }
+
         if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
           msc_log_declare_proto(i);
         }
+
         break;
+
       case MSC_RRC_UE:
         rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "RRC_UE");
-        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
+
+        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
+          g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
+        }
+
         if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
           msc_log_declare_proto(i);
         }
+
         break;
+
       case MSC_PDCP_UE:
         rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "PDCP_UE");
-        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
+
+        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
+          g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
+        }
+
         if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
           msc_log_declare_proto(i);
         }
+
         break;
+
       case MSC_RLC_UE:
-    	rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "RLC_UE");
-    	if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
-    	if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
+        rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "RLC_UE");
+
+        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
+          g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
+        }
+
+        if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
           msc_log_declare_proto(i);
         }
+
         break;
+
       case MSC_MAC_UE:
         rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "MAC_UE");
-        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
+
+        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
+          g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
+        }
+
         if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
-      	  msc_log_declare_proto(i);
+          msc_log_declare_proto(i);
         }
+
         break;
+
       case MSC_PHY_UE:
         rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "PHY_UE");
-        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
+
+        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
+          g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
+        }
+
         if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
           msc_log_declare_proto(i);
         }
+
         break;
+
       case MSC_PHY_ENB:
         rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "PHY_ENB");
-        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
+
+        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
+          g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
+        }
+
         if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
           msc_log_declare_proto(i);
         }
+
         break;
+
       case MSC_MAC_ENB:
         rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "MAC_ENB");
-        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
+
+        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
+          g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
+        }
+
         if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
           msc_log_declare_proto(i);
         }
+
         break;
+
       case MSC_RLC_ENB:
         rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "RLC_ENB");
-        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
+
+        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
+          g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
+        }
+
         if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
           msc_log_declare_proto(i);
         }
+
         break;
+
       case MSC_PDCP_ENB:
         rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "PDCP_ENB");
-        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
+
+        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
+          g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
+        }
+
         if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
           msc_log_declare_proto(i);
         }
+
         break;
+
       case MSC_RRC_ENB:
         rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "RRC_ENB");
-        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
+
+        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
+          g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
+        }
+
         if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
           msc_log_declare_proto(i);
         }
+
         break;
+
       case MSC_S1AP_ENB:
         rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "S1AP_ENB");
-        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
+
+        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
+          g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
+        }
+
         if ((envP == MSC_E_UTRAN) || (envP == MSC_MME_GW)  || (envP == MSC_MME)) {
           msc_log_declare_proto(i);
         }
+
         break;
+
       case MSC_GTPU_ENB:
         rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "GTPU_ENB");
-        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
+
+        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
+          g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
+        }
+
         if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
           msc_log_declare_proto(i);
         }
+
         break;
+
       case MSC_GTPU_SGW:
         rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "GTPU_SGW");
-        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
+
+        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
+          g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
+        }
+
         if ((envP == MSC_MME_GW) || (envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
           msc_log_declare_proto(i);
         }
+
         break;
+
       case MSC_S1AP_MME:
         rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "S1AP_MME");
-        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
+
+        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
+          g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
+        }
+
         if ((envP == MSC_MME_GW) || (envP == MSC_MME) || (envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
           msc_log_declare_proto(i);
         }
+
         break;
+
       case MSC_MMEAPP_MME:
         rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "MME_APP");
-        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
+
+        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
+          g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
+        }
+
         if ((envP == MSC_MME_GW) || (envP == MSC_MME)) {
           msc_log_declare_proto(i);
         }
+
         break;
+
       case MSC_NAS_MME:
         rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "NAS_MME");
-        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
+
+        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
+          g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
+        }
+
         msc_log_declare_proto(i);
         break;
+
       case MSC_NAS_EMM_MME:
         rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "NAS_EMM");
-        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
+
+        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
+          g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
+        }
+
         if ((envP == MSC_MME_GW) || (envP == MSC_MME)) {
           msc_log_declare_proto(i);
         }
+
         break;
+
       case MSC_NAS_ESM_MME:
         rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "NAS_ESM");
-        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
+
+        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
+          g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
+        }
+
         if ((envP == MSC_MME_GW) || (envP == MSC_MME)) {
           msc_log_declare_proto(i);
         }
+
         break;
+
       case MSC_SP_GWAPP_MME:
         rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "SP_GW_MME");
-        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
+
+        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
+          g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
+        }
+
         if (envP == MSC_MME_GW) {
           msc_log_declare_proto(i);
         }
+
         break;
+
       case MSC_S11_MME:
         rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "S11_MME");
-        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
+
+        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
+          g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
+        }
+
         if (envP == MSC_MME) {
           msc_log_declare_proto(i);
         }
+
         break;
+
       case MSC_S6A_MME:
         rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "S6A");
-        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
+
+        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
+          g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
+        }
+
         if ((envP == MSC_MME_GW) || (envP == MSC_MME)) {
           msc_log_declare_proto(i);
         }
+
         break;
+
       case MSC_HSS:
         rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "HSS");
-        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
+
+        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
+          g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
+        }
+
         if ((envP == MSC_MME_GW) || (envP == MSC_MME)) {
           msc_log_declare_proto(i);
         }
+
         break;
       case MSC_F1AP_CU:
         rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "F1AP_CU");
@@ -348,9 +492,13 @@ int msc_init(const msc_env_t envP, const int max_threadsP)
         break;
       default:
         rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "UNKNOWN");
-        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
+
+        if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {
+          g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;
+        }
     }
   }
+
   rv = itti_create_task (TASK_MSC, msc_task, NULL);
   AssertFatal (rv == 0, "Create task for MSC failed!\n");
   fprintf(stderr, "Initializing MSC logs Done\n");
@@ -373,15 +521,17 @@ void msc_flush_messages(void)
   int               rv;
   msc_queue_item_t *item_p = NULL;
 
-  while ((rv = lfds611_queue_dequeue( g_msc_message_queue_p, (void**)&item_p )) == 1) {
-	if (NULL != item_p->message_str) {
-	  fputs(item_p->message_str, g_msc_fd);
-	  // TODO BIN DATA
-	  rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, item_p->message_str );
-	}
-	// TODO FREE BIN DATA
-	free(item_p);
+  while ((rv = lfds611_queue_dequeue( g_msc_message_queue_p, (void **)&item_p )) == 1) {
+    if (NULL != item_p->message_str) {
+      fputs(item_p->message_str, g_msc_fd);
+      // TODO BIN DATA
+      rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, item_p->message_str );
+    }
+
+    // TODO FREE BIN DATA
+    free(item_p);
   }
+
   fflush(g_msc_fd);
 }
 
@@ -391,23 +541,27 @@ void msc_end(void)
 //------------------------------------------------------------------------------
 {
   int rv;
+
   if (NULL != g_msc_fd ) {
-	msc_flush_messages();
+    msc_flush_messages();
     rv = fflush(g_msc_fd);
-	if (rv != 0) {
-	  fprintf(stderr, "Error while flushing stream of MSC log file: %s", strerror(errno));
+
+    if (rv != 0) {
+      fprintf(stderr, "Error while flushing stream of MSC log file: %s", strerror(errno));
     }
+
     rv = fclose(g_msc_fd);
+
     if (rv != 0) {
-     fprintf(stderr, "Error while closing MSC log file: %s", strerror(errno));
+      fprintf(stderr, "Error while closing MSC log file: %s", strerror(errno));
     }
   }
 }
 
 //------------------------------------------------------------------------------
 void msc_log_declare_proto(
-    const msc_proto_t  protoP
-  )
+  const msc_proto_t  protoP
+)
 //------------------------------------------------------------------------------
 {
   int               rv             = 0;
@@ -415,47 +569,55 @@ void msc_log_declare_proto(
   char             *char_message_p = NULL;
 
   if ((MIN_MSC_PROTOS <= protoP) && (MAX_MSC_PROTOS > protoP)) {
-	// may be build a memory pool for that also ?
-	new_item_p = malloc(sizeof(msc_queue_item_t));
-	if (NULL != new_item_p) {
-
-	  rv = lfds611_stack_pop(g_msc_memory_stack_p, (void**)&char_message_p);
-	  if (0 == rv) {
-		  msc_flush_messages();
-		  rv = lfds611_stack_pop(g_msc_memory_stack_p, (void**)&char_message_p);
-	  }
-	  if (1 == rv) {
+    // may be build a memory pool for that also ?
+    new_item_p = malloc(sizeof(msc_queue_item_t));
+
+    if (NULL != new_item_p) {
+      rv = lfds611_stack_pop(g_msc_memory_stack_p, (void **)&char_message_p);
+
+      if (0 == rv) {
+        msc_flush_messages();
+        rv = lfds611_stack_pop(g_msc_memory_stack_p, (void **)&char_message_p);
+      }
+
+      if (1 == rv) {
         rv = snprintf(char_message_p, MSC_MAX_MESSAGE_LENGTH, "%"PRIu64" [PROTO] %d %s\n", __sync_fetch_and_add (&g_message_number, 1), protoP, &g_msc_proto2str[protoP][0]);
+
         if (0 > rv) {
           fprintf(stderr, "Error while declaring new protocol in MSC: %s", strerror(errno));
         }
+
         new_item_p->message_str       = char_message_p;
         new_item_p->message_str_size  = rv;
         new_item_p->message_bin       = NULL;
         new_item_p->message_bin_size  = 0;
         rv = lfds611_queue_enqueue( g_msc_message_queue_p, new_item_p );
-	    if (0 == rv) {
-	      rv = lfds611_queue_guaranteed_enqueue(g_msc_message_queue_p, new_item_p );
-		  if (0 == rv) {
+
+        if (0 == rv) {
+          rv = lfds611_queue_guaranteed_enqueue(g_msc_message_queue_p, new_item_p );
+
+          if (0 == rv) {
             fprintf(stderr, "Error while lfds611_queue_guaranteed_enqueue message %s in MSC", char_message_p);
-      	    rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, char_message_p );
-      	    free(new_item_p);
-		  }
-	    }
-	    return;
-	  } else {
-	      fprintf(stderr, "Error while lfds611_stack_pop()\n");
-	  }
+            rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, char_message_p );
+            free(new_item_p);
+          }
+        }
+
+        return;
+      } else {
+        fprintf(stderr, "Error while lfds611_stack_pop()\n");
+      }
+
       free(new_item_p);
-	} else {
+    } else {
       fprintf(stderr, "Error while malloc in MSC");
-	}
+    }
   }
 }
 //------------------------------------------------------------------------------
 void msc_log_event(
-    const msc_proto_t  protoP,
-    char *format, ...)
+  const msc_proto_t  protoP,
+  char *format, ...)
 //------------------------------------------------------------------------------
 {
   va_list           args;
@@ -464,52 +626,62 @@ void msc_log_event(
   msc_queue_item_t *new_item_p     = NULL;
   char             *char_message_p = NULL;
 
-
   if ((MIN_MSC_PROTOS > protoP) || (MAX_MSC_PROTOS <= protoP)) {
-      return;
+    return;
   }
+
   new_item_p = malloc(sizeof(msc_queue_item_t));
+
   if (NULL != new_item_p) {
+    rv = lfds611_stack_pop(g_msc_memory_stack_p, (void **)&char_message_p);
 
-    rv = lfds611_stack_pop(g_msc_memory_stack_p, (void**)&char_message_p);
     if (0 == rv) {
       msc_flush_messages();
-      rv = lfds611_stack_pop(g_msc_memory_stack_p, (void**)&char_message_p);
+      rv = lfds611_stack_pop(g_msc_memory_stack_p, (void **)&char_message_p);
     }
+
     if (1 == rv) {
       rv = snprintf(char_message_p, MSC_MAX_MESSAGE_LENGTH, "%"PRIu64" [EVENT] %d ",  __sync_fetch_and_add (&g_message_number, 1), protoP);
+
       if ((0 > rv) || (MSC_MAX_MESSAGE_LENGTH < rv)) {
         fprintf(stderr, "Error while logging MSC event : %s", &g_msc_proto2str[protoP][0]);
         goto error_event;
       }
+
       va_start(args, format);
       rv2 = vsnprintf(&char_message_p[rv],MSC_MAX_MESSAGE_LENGTH - rv,  format, args);
       va_end(args);
+
       if ((0 > rv2) || ((MSC_MAX_MESSAGE_LENGTH - rv) < rv2)) {
         fprintf(stderr, "Error while logging MSC event : %s", &g_msc_proto2str[protoP][0]);
         goto error_event;
       }
+
       rv += rv2;
       rv2 = snprintf(&char_message_p[rv],MSC_MAX_MESSAGE_LENGTH - rv, "\n");
+
       if ((0 > rv2) || ((MSC_MAX_MESSAGE_LENGTH - rv) < rv2)) {
         fprintf(stderr, "Error while logging MSC event : %s", &g_msc_proto2str[protoP][0]);
         goto error_event;
       }
+
       rv += rv2;
       new_item_p->message_str       = char_message_p;
       new_item_p->message_str_size  = rv;
       new_item_p->message_bin       = NULL;
       new_item_p->message_bin_size  = 0;
       rv = lfds611_queue_enqueue( g_msc_message_queue_p, new_item_p );
-	  if (0 == rv) {
+
+      if (0 == rv) {
         fprintf(stderr, "Error while lfds611_queue_guaranteed_enqueue message %s in MSC", char_message_p);
-    	rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, char_message_p );
-    	free(new_item_p);
-	  }
+        rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, char_message_p );
+        free(new_item_p);
+      }
     } else {
       fprintf(stderr, "Error while lfds611_stack_pop()\n");
-	}
+    }
   }
+
   return;
 error_event:
   rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, char_message_p );
@@ -517,12 +689,12 @@ error_event:
 }
 //------------------------------------------------------------------------------
 void msc_log_message(
-    const char * const message_operationP,
-    const msc_proto_t  proto1P,
-    const msc_proto_t  proto2P,
-    const uint8_t * const bytesP,
-    const unsigned int num_bytes,
-    char *format, ...)
+  const char *const message_operationP,
+  const msc_proto_t  proto1P,
+  const msc_proto_t  proto2P,
+  const uint8_t *const bytesP,
+  const unsigned int num_bytes,
+  char *format, ...)
 //------------------------------------------------------------------------------
 {
   va_list           args;
@@ -532,56 +704,65 @@ void msc_log_message(
   msc_queue_item_t *new_item_p     = NULL;
   char             *char_message_p = NULL;
 
-
   if ((MIN_MSC_PROTOS > proto1P) || (MAX_MSC_PROTOS <= proto1P) ||
-	  (MIN_MSC_PROTOS > proto2P)   || (MAX_MSC_PROTOS <= proto2P)  ) {
+      (MIN_MSC_PROTOS > proto2P)   || (MAX_MSC_PROTOS <= proto2P)  ) {
     return;
   }
 
   new_item_p = malloc(sizeof(msc_queue_item_t));
+
   if (NULL != new_item_p) {
+    rv = lfds611_stack_pop(g_msc_memory_stack_p, (void **)&char_message_p);
 
-    rv = lfds611_stack_pop(g_msc_memory_stack_p, (void**)&char_message_p);
     if (0 == rv) {
       msc_flush_messages();
-      rv = lfds611_stack_pop(g_msc_memory_stack_p, (void**)&char_message_p);
-	}
+      rv = lfds611_stack_pop(g_msc_memory_stack_p, (void **)&char_message_p);
+    }
+
     if (1 == rv) {
       rv = snprintf(char_message_p, MSC_MAX_MESSAGE_LENGTH, "%"PRIu64" [MESSAGE] %d %s %d %"PRIu64" ",
-    		  __sync_fetch_and_add (&g_message_number, 1), proto1P, message_operationP, proto2P, mac);
+                    __sync_fetch_and_add (&g_message_number, 1), proto1P, message_operationP, proto2P, mac);
+
       if ((0 > rv) || (MSC_MAX_MESSAGE_LENGTH < rv)) {
         fprintf(stderr, "Error while logging MSC message : %s/%s", &g_msc_proto2str[proto1P][0], &g_msc_proto2str[proto2P][0]);
         goto error_event;
       }
+
       va_start(args, format);
       rv2 = vsnprintf(&char_message_p[rv],MSC_MAX_MESSAGE_LENGTH - rv,  format, args);
       va_end(args);
+
       if ((0 > rv2) || ((MSC_MAX_MESSAGE_LENGTH - rv) < rv2)) {
         fprintf(stderr, "Error while logging MSC message : %s/%s", &g_msc_proto2str[proto1P][0], &g_msc_proto2str[proto2P][0]);
         goto error_event;
       }
+
       rv += rv2;
       rv2 = snprintf(&char_message_p[rv],MSC_MAX_MESSAGE_LENGTH - rv, "\n");
+
       if ((0 > rv2) || ((MSC_MAX_MESSAGE_LENGTH - rv) < rv2)) {
         fprintf(stderr, "Error while logging MSC message : %s/%s", &g_msc_proto2str[proto1P][0], &g_msc_proto2str[proto2P][0]);
         goto error_event;
       }
+
       rv += rv2;
       new_item_p->message_str       = char_message_p;
       new_item_p->message_str_size  = rv;
       new_item_p->message_bin       = NULL; // TO DO
       new_item_p->message_bin_size  = 0;    // TO DO
       rv = lfds611_queue_enqueue( g_msc_message_queue_p, new_item_p );
-	  if (0 == rv) {
+
+      if (0 == rv) {
         fprintf(stderr, "Error while lfds611_queue_guaranteed_enqueue message %s in MSC", char_message_p);
-    	rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, char_message_p );
-    	free(new_item_p);
-	  }
+        rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, char_message_p );
+        free(new_item_p);
+      }
     } else {
       fprintf(stderr, "Error while lfds611_stack_pop()\n");
       msc_flush_messages();
-  	}
+    }
   }
+
   return;
 error_event:
   rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, char_message_p );
@@ -592,8 +773,7 @@ error_event:
 //  function called when oai loader loads the msc shared lib
 int msc_autoinit(msc_interface_t *msc_interface)
 //------------------------------------------------------------------------------
- {
-
+{
   msc_interface->msc_init = msc_init;
   msc_interface->msc_start_use = msc_start_use;
   msc_interface->msc_end = msc_end;
@@ -601,4 +781,4 @@ int msc_autoinit(msc_interface_t *msc_interface)
   msc_interface->msc_log_message = msc_log_message;
   msc_interface->msc_loaded = 1;
   return 0;
- }
+}
diff --git a/common/utils/msc/msc.h b/common/utils/msc/msc.h
index c6c582518488ee30ae7d6ab4b2d757efb04e9b66..49c99abb56cf12b0bcdc6d1d93683d427cc50fb0 100644
--- a/common/utils/msc/msc.h
+++ b/common/utils/msc/msc.h
@@ -25,48 +25,48 @@
 #include <stdint.h>
 
 typedef enum {
-	MIN_MSC_ENV = 0,
-    MSC_E_UTRAN = MIN_MSC_ENV,
-    MSC_E_UTRAN_LIPA,
-    MSC_MME_GW,
-    MSC_MME,
-    MSC_SP_GW,
-    MAX_MSC_ENV
+  MIN_MSC_ENV = 0,
+  MSC_E_UTRAN = MIN_MSC_ENV,
+  MSC_E_UTRAN_LIPA,
+  MSC_MME_GW,
+  MSC_MME,
+  MSC_SP_GW,
+  MAX_MSC_ENV
 } msc_env_t;
 
 
 typedef enum {
-    MIN_MSC_PROTOS = 0,
-    MSC_IP_UE = MIN_MSC_PROTOS,
-    MSC_NAS_UE,
-    MSC_RRC_UE,
-    MSC_PDCP_UE,
-    MSC_RLC_UE,
-    MSC_MAC_UE,
-    MSC_PHY_UE,
-    MSC_PHY_ENB,
-    MSC_MAC_ENB,
-    MSC_RLC_ENB,
-    MSC_PDCP_ENB,
-    MSC_RRC_ENB,
-    MSC_IP_ENB,
-    MSC_S1AP_ENB,
-    MSC_GTPU_ENB,
-    MSC_GTPU_SGW,
-    MSC_S1AP_MME,
-    MSC_MMEAPP_MME,
-    MSC_NAS_MME,
-    MSC_NAS_EMM_MME,
-    MSC_NAS_ESM_MME,
-    MSC_SP_GWAPP_MME,
-    MSC_S11_MME,
-    MSC_S6A_MME,
-    MSC_HSS,
-    MSC_F1AP_CU,
-    MSC_F1AP_DU,
-    MAX_MSC_PROTOS,
-    MSC_X2AP_SRC_ENB,
-    MSC_X2AP_TARGET_ENB,
+  MIN_MSC_PROTOS = 0,
+  MSC_IP_UE = MIN_MSC_PROTOS,
+  MSC_NAS_UE,
+  MSC_RRC_UE,
+  MSC_PDCP_UE,
+  MSC_RLC_UE,
+  MSC_MAC_UE,
+  MSC_PHY_UE,
+  MSC_PHY_ENB,
+  MSC_MAC_ENB,
+  MSC_RLC_ENB,
+  MSC_PDCP_ENB,
+  MSC_RRC_ENB,
+  MSC_IP_ENB,
+  MSC_S1AP_ENB,
+  MSC_GTPU_ENB,
+  MSC_GTPU_SGW,
+  MSC_S1AP_MME,
+  MSC_MMEAPP_MME,
+  MSC_NAS_MME,
+  MSC_NAS_EMM_MME,
+  MSC_NAS_ESM_MME,
+  MSC_SP_GWAPP_MME,
+  MSC_S11_MME,
+  MSC_S6A_MME,
+  MSC_HSS,
+  MSC_F1AP_CU,
+  MSC_F1AP_DU,
+  MSC_X2AP_SRC_ENB,
+  MSC_X2AP_TARGET_ENB,
+  MAX_MSC_PROTOS,
 } msc_proto_t;
 
 
@@ -75,22 +75,22 @@ typedef enum {
 #define MSC_AS_TIME_FMT "%05u:%02u"
 
 #define MSC_AS_TIME_ARGS(CTXT_Pp) \
-    (CTXT_Pp)->frame, \
-    (CTXT_Pp)->subframe
+  (CTXT_Pp)->frame, \
+  (CTXT_Pp)->subframe
 
 typedef int(*msc_init_t)(const msc_env_t, const int );
 typedef void(*msc_start_use_t)(void );
 typedef void(*msc_end_t)(void);
 typedef void(*msc_log_event_t)(const msc_proto_t,char *, ...);
-typedef void(*msc_log_message_t)(const char *   const, const msc_proto_t, const msc_proto_t, 
-                                 const uint8_t* const, const unsigned int, char * , ...);
+typedef void(*msc_log_message_t)(const char    *const, const msc_proto_t, const msc_proto_t,
+                                 const uint8_t *const, const unsigned int, char *, ...);
 typedef struct msc_interface {
-    int               msc_loaded;
-    msc_init_t        msc_init;
-    msc_start_use_t   msc_start_use;
-    msc_end_t         msc_end;
-    msc_log_event_t   msc_log_event;
-    msc_log_message_t msc_log_message;
+  int               msc_loaded;
+  msc_init_t        msc_init;
+  msc_start_use_t   msc_start_use;
+  msc_end_t         msc_end;
+  msc_log_event_t   msc_log_event;
+  msc_log_message_t msc_log_message;
 } msc_interface_t;
 
 #ifdef MSC_LIBRARY
@@ -101,15 +101,17 @@ void msc_end(void);
 void msc_log_declare_proto(const msc_proto_t  protoP);
 void msc_log_event(const msc_proto_t  protoP,char *format, ...);
 void msc_log_message(
-	const char * const message_operationP,
-    const msc_proto_t  receiverP,
-    const msc_proto_t  senderP,
-    const uint8_t* const bytesP,
-    const unsigned int num_bytes,
-    char *format, ...);
+  const char *const message_operationP,
+  const msc_proto_t  receiverP,
+  const msc_proto_t  senderP,
+  const uint8_t *const bytesP,
+  const unsigned int num_bytes,
+  char *format, ...);
 
 #else
 
+#define MESSAGE_CHART_GENERATOR  msc_interface.msc_loaded
+
 msc_interface_t msc_interface;
 #define MSC_INIT(arg1,arg2)                                     if(msc_interface.msc_loaded) msc_interface.msc_init(arg1,arg2)
 #define MSC_START_USE                                           if(msc_interface.msc_loaded) msc_interface.msc_start_use
@@ -121,4 +123,4 @@ msc_interface_t msc_interface;
 #define MSC_LOG_TX_MESSAGE_FAILED(sENDER, rECEIVER, bYTES, nUMbYTES, fORMAT, aRGS...)    if(msc_interface.msc_loaded) msc_interface.msc_log_message("-x",sENDER, rECEIVER, (const uint8_t *)bYTES, nUMbYTES, fORMAT, ##aRGS)
 #endif
 
-#endif 
+#endif
diff --git a/common/utils/telnetsrv/DOC/telnetaddcmd.md b/common/utils/telnetsrv/DOC/telnetaddcmd.md
new file mode 100644
index 0000000000000000000000000000000000000000..c7591282549fd30cc51863cbf3ec9b32c63b20b3
--- /dev/null
+++ b/common/utils/telnetsrv/DOC/telnetaddcmd.md
@@ -0,0 +1,116 @@
+# code example of adding a command to the telnet server
+
+The following example is extracted from [the oai `openair1/PHY/CODING/coding_load.c` file](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair1/PHY/CODING/coding_load.c).
+
+```c
+/*
+include the telnet server data structures and API definitions
+*/
+#include "common/utils/telnetsrv/telnetsrv.h"
+
+
+/*
+define the null terminated array of telnetshell_cmddef_t structures
+which map each sub-command string to a function implementing it.
+you may also provide a help string which will be printed when
+the global help command is used. The prototype for the function
+implementing sub commands must match the `cmdfunc_t` type defined
+in `telnetsrv.h`
+*/
+static int coding_setmod_cmd(char *buff, int debug, telnet_printfunc_t prnt);
+static telnetshell_cmddef_t coding_cmdarray[] = {
+   {"mode","[sse,avx2,stdc,none]",coding_setmod_cmd},
+   {"","",NULL},
+};
+
+/*
+define the null terminated list of telnetshell_vardef_t structures defining the
+variables that can be set and get using the pre-defined get and set command
+of the telnet server
+*/
+telnetshell_vardef_t coding_vardef[] = {
+{"maxiter",TELNET_VARTYPE_INT32,&max_turbo_iterations},
+{"",0,NULL}
+};
+.................
+/*
+ look for telnet server, if it is loaded, add the coding commands to it
+ we use the shared library loader API to check the telnet server availibility
+The telnet server TELNET_ADDCMD_FNAME function takes three arguments:
+1.  The name of the telnet command to be added, here "coding"
+1.  The `coding_cmdarray` list of "coding" sub-commands we defined earlier
+1.  The `coding_varde f`list of variables we defined earlier
+*/
+     add_telnetcmd_func_t addcmd = (add_telnetcmd_func_t)get_shlibmodule_fptr("telnetsrv", TELNET_ADDCMD_FNAME);
+     if (addcmd != NULL) {
+         addcmd("coding",coding_vardef,coding_cmdarray);
+.......
+/*
+  functions implementing the "coding mode" sub command, as defined in
+  the `coding_cmdarray` passed earlier to the TELNET_ADDCMD_FNAME function.
+  This function will be called by the telnet server, when the `coding_cmdarray`
+  command is received from the telnet client
+*/
+int coding_setmod_cmd(char *buff, int debug, telnet_printfunc_t prnt)
+{
+  /*
+  1. buff argument is an input argument, pointer to the string received
+  from the telnet client, the command and sub-command parts are removed
+  In this case it points after "coding setmod" and is of no use as
+  we don't have second level sub-commands.
+  1. debug argument is an input argument set by the telnet server
+  1. prnt arguments is also an input argument, a function pointer, to be used
+  in place of printf to print messages on the telnet client interface. As this function
+  is called by the telnet server stdout points to the main executable console,
+  */
+   if (debug > 0)
+       prnt( "coding_setmod_cmd received %s\n",buff);
+
+      if (strcasestr(buff,"sse") != NULL) {
+         decoding_setmode(MODE_DECODE_SSE);
+      } else if (strcasestr(buff,"avx2") != NULL) {
+         decoding_setmode(MODE_DECODE_AVX2);
+      } else if (strcasestr(buff,"stdc") != NULL) {
+         decoding_setmode(MODE_DECODE_C);
+      } else if (strcasestr(buff,"none") != NULL) {
+         decoding_setmode(MODE_DECODE_NONE);
+      } else {
+          prnt("%s: wrong setmod parameter...\n",buff);
+      }
+   prnt("Coding and decoding current mode: %s\n",modedesc[curmode]);
+   return 0;
+}
+
+..............
+
+```
+# telnet server API
+
+```c
+int add_telnetcmd(char *modulename, telnetshell_vardef_t *var, telnetshell_cmddef_t *cmd)
+```
+Add a command and the `cmd` list of sub-commands to the telnet server. After a successful call to `add_telnetcmd` function, the telnet server calls the function defined for each sub-commands in the null terminated `cmd` array, when the character string received from the telnet client matches the command and sub-command strings.
+Also adds the list of variables described in the `var` array to the list of variable which can be set and read.
+The function returns -1 if one argument is NULL.
+The telnet server is dynamically loaded, to use  the `add_telnetcmd` function, the shared library loader API should be used to check the availability of the telnet server and retrieve it's address, as shown in [the example at the top of this page](telnetaddcmd.md#code-example-of-adding-a-command-to-the-telnet-server).
+
+# telnet server public data types
+## `telnetshell_vardef_t`structure
+ This structure is used by developers to describe the variables that can be set or read using the get,set and getall sub-commands.
+
+| Fields     | type |Description                                                       |
+|:-----------|:------:|:-----------------------|
+| `varname`    | `char[TELNET_CMD_MAXSIZE]`  | variable name, as specified when using the get and set commands. |
+| `vartype`     | `char` |  Defines the type of the variable pointed by the `varvalptr`field. Supported values: TELNET_VARTYPE_INT32  TELNET_VARTYPE_INT16 TELNET_VARTYPE_INT64  TELNET_VARTYPE_STRING   TELNET_VARTYPE_DOUBLE |
+| `varvalptr`     | `void*` |  Defines the type of the variable pointed by the `varvalptr`field |
+
+## `telnetshell_cmddef_t`structure
+ This structure is used by developers to describe the first level sub-commands to be added to the telnet server.
+
+| Fields     | type |Description                                                       |
+|:-----------|:------:|:-----------------------|
+| `cmdname`    | `char[TELNET_CMD_MAXSIZE]`  | command name, as tested by the telnet server to check it should call the `cmdfunc` function  |
+| `helpstr`     | `char[TELNET_HELPSTR_SIZE]` |  character string to print when the elp`command is received from the telnet client |
+| `cmdfunc`     | `cmdfunc_t` |  pointer to the function implementing the `cmdname` sub command. |
+
+[oai telnet server home](telnetsrv.md)
diff --git a/common/utils/telnetsrv/DOC/telnetarch.md b/common/utils/telnetsrv/DOC/telnetarch.md
new file mode 100644
index 0000000000000000000000000000000000000000..ebb2342c22304f7c9a08c44880a358e34a187dcd
--- /dev/null
+++ b/common/utils/telnetsrv/DOC/telnetarch.md
@@ -0,0 +1,21 @@
+# telnet server principles
+
+The oai telnet server is implemented in a shared library to be loaded by the [oai shared library loader](loader). The implementation includes a `telnetsrv_autoinit` function which is automatically called at load time, starts the telnet server and registers a first set of commands, which are delivered with the server (telnet, softmodem, loader).
+
+Currently the telnet server only supports one user connection. The same dedicated thread is used to wait for a user connection and process the input received from this connection.
+
+The telnet server provides an API which can be used by any oai component to add new CLI commands to the server. A pre-defined  command can be used to get or set a list of variables.
+
+
+
+# telnet server source files
+
+telnet server source files are located in [common/utils/telnetsrv](https://gitlab.eurecom.fr/oai/openairinterface5g/tree/develop/common/utils/telnetsrv)
+
+1. [telnetsrv.c](https://gitlab.eurecom.fr/oai/openairinterface5g/tree/develop/common/utils/telnetsrv/telnetsrv.c) contains the telnet server implementation, including the implementation of the telnet CLI command.
+1.  [telnetsrv.h](https://gitlab.eurecom.fr/oai/openairinterface5g/tree/develop/common/utils/telnetsrv/telnetsrv.h) is the telnet server include file containing both private and public data type definitions. It also contains API prototypes for functions that are used to register a new command in the server.
+1.  `telnetsrv\_\<XXX\>.c`: implementation of \<XXX\> CLI command which are delivered with the telnet server.
+1.  `telnetsrv\_\<XXX\>.h`: include file for the implementation of XXX CLI command. Usually included only in the corresponding `.c`file
+1.  [telnetsrv_CMakeLists.txt](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/telnetsrv/telnetsrv_CMakeLists.txt): CMakelists file containing the cmake instructions to build the telnet server. this file is included in the [global oai CMakelists](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/cmake_targets/CMakeLists.txt).
+
+[oai telnet server home](telnetsrv.md)
diff --git a/common/utils/telnetsrv/DOC/telnetgetset.md b/common/utils/telnetsrv/DOC/telnetgetset.md
new file mode 100644
index 0000000000000000000000000000000000000000..d851e90a8fdaec05fbde85e03413c6c9288f3a75
--- /dev/null
+++ b/common/utils/telnetsrv/DOC/telnetgetset.md
@@ -0,0 +1,21 @@
+getall command can be used to get the list of variables that can bet set or get from the telnet shell. Knowing the names of the variables they can then be set or read. Setting a variable is not always relevant, the telnet server doesn't provide a mechanism to restrict the set command.
+
+```bash
+softmodem> telnet getall
+telnet, debug = 0
+telnet, prio = 0
+telnet, loopc = 10
+telnet, loopd = 5000
+telnet, phypb = 65000
+telnet, hsize = 50
+telnet, hfile = "oaitelnet.history"
+softmodem> telnet set loopc 100
+telnet, loopc set to
+100
+softmodem> telnet get loopc
+telnet, loopc = 100
+softmodem>
+
+```
+[oai telnetserver home](telnetsrv.md)
+[oai telnetserver usage home](telnetusage.md)
diff --git a/common/utils/telnetsrv/DOC/telnethelp.md b/common/utils/telnetsrv/DOC/telnethelp.md
new file mode 100644
index 0000000000000000000000000000000000000000..b18f5caae7b528898e2ba23f25dc7547af95a8c5
--- /dev/null
+++ b/common/utils/telnetsrv/DOC/telnethelp.md
@@ -0,0 +1,57 @@
+# oai telnet server global help
+
+``` bash
+alblf@at8020-a:~$ telnet 10.133.10.77 9090
+Trying 10.133.10.77...
+Connected to 10.133.10.77.
+Escape character is '^]'.
+
+softmodem> help
+   module 0 = telnet:
+      telnet [get set] debug <value>
+      telnet [get set] prio <value>
+      telnet [get set] loopc <value>
+      telnet [get set] loopd <value>
+      telnet [get set] phypb <value>
+      telnet [get set] hsize <value>
+      telnet [get set] hfile <value>
+      telnet redirlog [here,file,off]
+      telnet param [prio]
+      telnet history [list,reset]
+   module 1 = softmodem:
+      softmodem show loglvl|thread|config
+      softmodem log (enter help for details)
+      softmodem thread (enter help for details)
+      softmodem exit
+   module 2 = phy:
+      phy disp [phycnt,uedump,uestat UE<x>]
+   module 3 = loader:
+      loader [get set] mainversion <value>
+      loader [get set] defpath <value>
+      loader [get set] maxshlibs <value>
+      loader [get set] numshlibs <value>
+      loader show [params,modules]
+   module 4 = coding:
+      coding [get set] maxiter <value>
+      coding mode [sse,avx2,stdc,none]
+softmodem>
+```
+
+# oai telnet server, specific commands help
+
+``` bash
+softmodem> softmodem log help
+ log sub commands:
+ show:  		     display current log configuration
+ online, noonline:	     enable or disable console logs
+ enable, disable id1-id2:    enable or disable logs for components index id1 to id2
+ level_<level> id1-id2:      set log level to <level> for components index id1 to id2
+ level_<verbosity> id1-id2:  set log verbosity to <verbosity> for components index id1 to id2
+use the show command to get the values for <level>, <verbosity> and the list of component indexes that can be used for id1 and id2
+softmodem>
+
+
+```
+
+[oai telnetserver home](telnetsrv.md)
+[oai telnetserver usage home](telnetusage.md)
diff --git a/common/utils/telnetsrv/DOC/telnethist.md b/common/utils/telnetsrv/DOC/telnethist.md
new file mode 100644
index 0000000000000000000000000000000000000000..b7cf152502802be199a66391e85485819b4ef46c
--- /dev/null
+++ b/common/utils/telnetsrv/DOC/telnethist.md
@@ -0,0 +1,44 @@
+The telnet server implements a simple history system
+```bash
+softmodem> telnet history list
+1: telnet history list
+2: telnet history list
+3: help
+4: loader show modules
+5: softmodem show loglvl
+6: help
+7: telnet history
+8: help
+9: telnet history list
+10: help
+11: loader show modules
+12: softmodem show loglvl
+13: softmodem log help
+14: softmodem log disable 0-35
+15: softmodem log show
+16: help
+17: telnet history list
+18: loader show modules
+19: softmodem thread show
+20: help
+21: softmodem thread help
+22: softmodem log show
+23: softmodem log help
+24: softmodem log level_error 0-4
+25: loader show modules
+26: loader show config
+27: help
+28: loader show params
+29: loader show modules
+softmodem> !28
+softmodem>  loader show params
+loader parameters:
+   Main executable build version: "Branch: develop-telnet-loader-fixes Abrev. Hash: e56ae69 Date: Fri Mar 9 16:47:08 2018 +0100"
+   Default shared lib path: ""
+   Max number of shared lib : 10
+softmodem>
+
+```
+
+[oai telnetserver home](telnetsrv.md)
+[oai telnetserver usage home](telnetusage.md)
diff --git a/common/utils/telnetsrv/DOC/telnetloader.md b/common/utils/telnetsrv/DOC/telnetloader.md
new file mode 100644
index 0000000000000000000000000000000000000000..d6a0f158c6fcd9bef3bd6fdc5979042ee730f660
--- /dev/null
+++ b/common/utils/telnetsrv/DOC/telnetloader.md
@@ -0,0 +1,47 @@
+loader command can be used to check loader configuration parameters and the list of loaded shared libraries and for each library the list of available functions.
+
+```bash
+softmodem> loader show params
+loader parameters:
+   Main executable build version: "Branch: develop-telnet-loader-fixes Abrev. Hash: e56ae69 Date: Fri Mar 9 16:47:08 2018 +0100"
+   Default shared lib path: ""
+   Max number of shared lib : 10
+softmodem> loader show modules
+4 shared lib have been dynamicaly loaded by the oai loader
+   Module 0: telnetsrv
+       Shared library build version: "Branch: develop-telnet-loader-fixes Abrev. Hash: e56ae69 Date: Fri Mar 9 16:47:08 2018 +0100"
+       Shared library path: "libtelnetsrv.so"
+       1 function pointers registered:
+          function 0 add_telnetcmd at 0x7ff8b772a2b0
+   Module 1: NB_IoT
+       Shared library build version: ""
+       Shared library path: "libNB_IoT.so"
+       1 function pointers registered:
+          function 0 RCConfig_NbIoT at 0x7ff8b6b1b390
+   Module 2: coding
+       Shared library build version: "Branch: develop-telnet-loader-fixes Abrev. Hash: e56ae69 Date: Fri Mar 9 16:47:08 2018 +0100"
+       Shared library path: "libcoding.so"
+       13 function pointers registered:
+          function 0 init_td8 at 0x7ff8adde63a0
+          function 1 init_td16 at 0x7ff8adde9760
+          function 2 init_td16avx2 at 0x7ff8addec050
+          function 3 phy_threegpplte_turbo_decoder8 at 0x7ff8adde6780
+          function 4 phy_threegpplte_turbo_decoder16 at 0x7ff8adde9a90
+          function 5 phy_threegpplte_turbo_decoder_scalar at 0x7ff8addef4a0
+          function 6 phy_threegpplte_turbo_decoder16avx2 at 0x7ff8addec530
+          function 7 free_td8 at 0x7ff8adde61d0
+          function 8 free_td16 at 0x7ff8adde9590
+          function 9 free_td16avx2 at 0x7ff8addebe80
+          function 10 threegpplte_turbo_encoder_sse at 0x7ff8adde45b0
+          function 11 threegpplte_turbo_encoder at 0x7ff8adde4a30
+          function 12 init_encoder_sse at 0x7ff8adde49d0
+   Module 3: oai_device
+       Shared library build version: ""
+       Shared library path: "liboai_device_usrp.so"
+       1 function pointers registered:
+          function 0 device_init at 0x7ff8ac16a7a0
+softmodem>
+```
+
+[oai telnetserver home](telnetsrv.md)
+[oai telnetserver usage home](telnetusage.md)
diff --git a/common/utils/telnetsrv/DOC/telnetlog.md b/common/utils/telnetsrv/DOC/telnetlog.md
new file mode 100644
index 0000000000000000000000000000000000000000..36c5cfb3486d5ff79efebb8921860ed4f185d1a3
--- /dev/null
+++ b/common/utils/telnetsrv/DOC/telnetlog.md
@@ -0,0 +1,96 @@
+The log command can be used to get the status of the log parameters and to dynamically modify these parameters. The log command has its own [help](telnethelp.md#oai-telnet-server-specific-commands-help)
+```bash
+softmodem>  softmodem log disable 0-35
+log level/verbosity  comp 0 PHY set to info / medium (disabled)
+log level/verbosity  comp 1 MAC set to info / medium (disabled)
+log level/verbosity  comp 2 EMU set to info / medium (disabled)
+log level/verbosity  comp 3 OCG set to info / medium (disabled)
+log level/verbosity  comp 4 OMG set to info / medium (disabled)
+log level/verbosity  comp 5 OPT set to info / medium (disabled)
+log level/verbosity  comp 6 OTG set to info / medium (disabled)
+log level/verbosity  comp 7 OTG_LATENCY set to info / medium (disabled)
+log level/verbosity  comp 8 OTG_LATENCY_BG set to info / medium (disabled)
+log level/verbosity  comp 9 OTG_GP set to info / medium (disabled)
+log level/verbosity  comp 10 OTG_GP_BG set to info / medium (disabled)
+log level/verbosity  comp 11 OTG_JITTER set to info / medium (disabled)
+log level/verbosity  comp 12 RLC set to info / medium (disabled)
+log level/verbosity  comp 13 PDCP set to info / medium (disabled)
+log level/verbosity  comp 14 RRC set to info / medium (disabled)
+log level/verbosity  comp 15 NAS set to info / medium (disabled)
+log level/verbosity  comp 16 PERF set to info / medium (disabled)
+log level/verbosity  comp 17 OIP set to info / medium (disabled)
+log level/verbosity  comp 18 CLI set to info / medium (disabled)
+log level/verbosity  comp 19 MSC set to info / medium (disabled)
+log level/verbosity  comp 20 OCM set to info / medium (disabled)
+log level/verbosity  comp 21 UDP set to info / medium (disabled)
+log level/verbosity  comp 22 GTPV1U set to info / medium (disabled)
+log level/verbosity  comp 23 comp23? set to info / medium (disabled)
+log level/verbosity  comp 24 S1AP set to info / medium (disabled)
+log level/verbosity  comp 25 SCTP set to info / medium (disabled)
+log level/verbosity  comp 26 HW set to info / medium (disabled)
+log level/verbosity  comp 27 OSA set to info / medium (disabled)
+log level/verbosity  comp 28 eRAL set to info / medium (disabled)
+log level/verbosity  comp 29 mRAL set to info / medium (disabled)
+log level/verbosity  comp 30 ENB_APP set to info / medium (disabled)
+log level/verbosity  comp 31 FLEXRAN_AGENT set to info / medium (disabled)
+log level/verbosity  comp 32 TMR set to info / medium (disabled)
+log level/verbosity  comp 33 USIM set to info / medium (disabled)
+log level/verbosity  comp 34 LOCALIZE set to info / medium (disabled)
+log level/verbosity  comp 35 RRH set to info / medium (disabled)
+softmodem> softmodem log show
+Available log levels:
+   emerg alert crit error warn notice info debug file trace
+Available verbosity:
+   none low medium high full
+component                 verbosity  level  enabled
+00               PHY:    medium      info  N
+01               MAC:    medium      info  N
+02               EMU:    medium      info  N
+03               OCG:    medium      info  N
+04               OMG:    medium      info  N
+05               OPT:    medium      info  N
+06               OTG:    medium      info  N
+07       OTG_LATENCY:    medium      info  N
+08    OTG_LATENCY_BG:    medium      info  N
+09            OTG_GP:    medium      info  N
+10         OTG_GP_BG:    medium      info  N
+11        OTG_JITTER:    medium      info  N
+12               RLC:    medium      info  N
+13              PDCP:    medium      info  N
+14               RRC:    medium      info  N
+15               NAS:    medium      info  N
+16              PERF:    medium      info  N
+17               OIP:    medium      info  N
+18               CLI:    medium      info  N
+19               MSC:    medium      info  N
+20               OCM:    medium      info  N
+21               UDP:    medium      info  N
+22            GTPV1U:    medium      info  N
+23           comp23?:    medium      info  N
+24              S1AP:    medium      info  N
+25              SCTP:    medium      info  N
+26                HW:    medium      info  N
+27               OSA:    medium      info  N
+28              eRAL:    medium      info  N
+29              mRAL:    medium      info  N
+30           ENB_APP:    medium      info  N
+31     FLEXRAN_AGENT:    medium      info  N
+32               TMR:    medium      info  N
+33              USIM:    medium      info  N
+34          LOCALIZE:    medium      info  N
+35               RRH:    medium      info  N
+36           comp36?:    medium      info  Y
+37            LOADER:    medium     alert  Y
+softmodem> softmodem log level_error 0-4
+log level/verbosity  comp 0 PHY set to error / medium (enabled)
+log level/verbosity  comp 1 MAC set to error / medium (enabled)
+log level/verbosity  comp 2 EMU set to error / medium (enabled)
+log level/verbosity  comp 3 OCG set to error / medium (enabled)
+log level/verbosity  comp 4 OMG set to error / medium (enabled)
+softmodem> exit
+Connection closed by foreign host.
+```
+
+[oai telnetserver home](telnetsrv.md)
+[oai telnetserver usage home](telnetusage.md)
+[oai Wikis home](https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/home)
diff --git a/common/utils/telnetsrv/DOC/telnetloop.md b/common/utils/telnetsrv/DOC/telnetloop.md
new file mode 100644
index 0000000000000000000000000000000000000000..a86baad6eb547dd24c4e1dbc029ffb8cf4cf4032
--- /dev/null
+++ b/common/utils/telnetsrv/DOC/telnetloop.md
@@ -0,0 +1,40 @@
+The telnet server includes a **_loop_** command that can be used to iterate a given command. The number of iterations and the delay, in ms between two iterations can be modified, as shown in the following example:
+
+```bash
+softmodem> telnet get loopc
+telnet, loopc = 10
+softmodem> telnet get loopd
+telnet, loopd = 2000
+softmodem> telnet set loopd 1000
+telnet, loopd set to
+1000
+softmodem> loop softmodem show thread
+                  2018-03-27 17:58:49.000 2/10
+  id          name            state   USRmod    KRNmod  prio nice   vsize   proc pol
+
+     3946        lte-softmodem   S       20005      9440  20   0 236560384   2    0 other
+
+     3946        lte-softmodem   S           7        95  20   0 236560384   2    0 other
+     3948               telnet   R           0         0  20   0 236560384   2    0 other
+     3949        ITTI acceptor   S           2         9  20   0 236560384   2    0 other
+     3951              ITTI 12   S           2         2  20   0 236560384   7    0 other
+     3952              ITTI 11   S           0         0  20   0 236560384   0    0 other
+     3953               ITTI 9   S           0         0  20   0 236560384   1    0 other
+     3954               ITTI 7   S           0         0  20   0 236560384   7    0 other
+     3955               ITTI 8   S           0         0  20   0 236560384   7    0 other
+     3956               ITTI 4   S          35         0  20   0 236560384   2    0 other
+     3957            ru_thread   S       15366      3072 -10   0 236560384   0    2 rt: rr
+     3958      ru_thread_prach   S           0         0 -10   0 236560384   7    1 rt: fifo
+     3959           fep_thread   S        1874       123 -10   0 236560384   5    1 rt: fifo
+     3960         feptx_thread   S        1554       101 -10   0 236560384   7    1 rt: fifo
+     3969            ru_thread   S           0         0 -10   0 236560384   0    2 rt: rr
+     3970            ru_thread   S        1313      5522 -10   0 236560384   5    2 rt: rr
+     3971            ru_thread   S           4         6 -10   0 236560384   1    2 rt: rr
+     3972        lte-softmodem   S         318         9 -10   0 236560384   7    1 rt: fifo
+     3973        lte-softmodem   S           6        13 -10   0 236560384   4    1 rt: fifo
+
+```
+A **_loop_** command can be interrupted by pressing the  **_enter_** key till getting the  prompt.
+
+[oai telnetserver home](telnetsrv.md)
+[oai telnetserver usage home](telnetusage.md)
diff --git a/common/utils/telnetsrv/DOC/telnetsrv.md b/common/utils/telnetsrv/DOC/telnetsrv.md
new file mode 100644
index 0000000000000000000000000000000000000000..11c6cf071fdd1c32b9489487dde1b0e8082f2de4
--- /dev/null
+++ b/common/utils/telnetsrv/DOC/telnetsrv.md
@@ -0,0 +1,7 @@
+The oai embedded telnet server is an optional monitoring and debugging tool. It provides a simple Command Line Interface to the oai softmem. New commands can easily be added by developers to the telnet server.
+
+* [Using the telnet server](telnetusage.md)
+* [Adding commands to the oai telnet server](telnetaddcmd.md)
+* [telnet server architecture ](telnetarch.md)
+
+[oai Wikis home](https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/home)
diff --git a/common/utils/telnetsrv/DOC/telnetusage.md b/common/utils/telnetsrv/DOC/telnetusage.md
new file mode 100644
index 0000000000000000000000000000000000000000..03561432265076dc279e82b797f7cbf02b43512a
--- /dev/null
+++ b/common/utils/telnetsrv/DOC/telnetusage.md
@@ -0,0 +1,39 @@
+# starting the softmodem with the telnet server
+By default the embedded telnet server, which is implemented in a shared library, is not built. It can be built after compiling the softmodem executable using the `build_oai` script:
+
+```bash
+ cd \<oai repository\>/openairinterface5g
+ source oaienv
+ cd cmake_targets
+ ./build_oai  --build-telnetsrv
+```
+
+This will create the `libtelnetsrv.so` file in the `targets/bin` and `cmake_targets/lte_build_oai/build` sub directories of the oai repository.
+
+When starting the softmodem, you must specify the **_\-\-telnetsrv_** option to load and start the telnet server. The telnet server is loaded via the [oai shared library loader](loader).
+
+# using the Command Line Interface
+By default the telnet server listen on all the ip addresses configured on the system and on port 9090.  This behavior can be changed using the `listenaddr` and `listenport` parameters.
+The telnet server includes a basic help, listing available commands and some commands also provide a specific detailed help sub-command.
+Below are  examples of telnet sessions:
+
+*  [getting help](telnethelp.md)
+*  [using the history](telnethist.md)
+*  [using the get and set commands](telnetgetset.md)
+*  [using the loop command](telnetloop.md)
+*  [loader command](telnetloader.md)
+*  [log command](telnetlog.md)
+
+# telnet server parameters
+The telnet server is using the [oai configuration module](Config/Rtusage). Telnet parameters must be specified in the `telnetsrv` section. Some parameters can be modified via the telnet telnet server command, as specified in the last column of the following table.
+
+| name | type | default | description | dynamic |
+|:---:|:---:|:---:|:----|:----:|
+| `listenaddr` | `ipV4 address, ascii format` | "0.0.0.0" | local address the server is listening on| N |
+| `listenport` | `integer` | 9090 | port number the server is listening on | N |
+| `loopcount` | `integer` | 10 | number of iterations for the loop command  | Y |
+| `loopdelay` | `integer` | 5000 | delay (in ms) between 2 loop command iterations  | Y |
+| `histfile` | `character string` | "oaitelnet.history" | file used for command history persistency | Y |
+| `histfsize` | `integer` | 50 | maximum number of commands saved in the history | Y |
+
+[oai telnet server home](telnetsrv.md)
diff --git a/common/utils/telnetsrv/telnetsrv.c b/common/utils/telnetsrv/telnetsrv.c
index a49311d0994a16420abf3edf10bf92dac36f35ba..b6803ead6bb15a668928fed2458ce738f7f3e3e1 100644
--- a/common/utils/telnetsrv/telnetsrv.c
+++ b/common/utils/telnetsrv/telnetsrv.c
@@ -51,14 +51,14 @@
 #include <dlfcn.h>
 #include <sys/time.h>
 #include <sys/resource.h>
-#include "common/utils/load_module_shlib.h" 
+#include "common/utils/load_module_shlib.h"
 #include "common/config/config_userapi.h"
 #include <readline/history.h>
 
 
 #include "telnetsrv_phycmd.h"
-#include "telnetsrv_proccmd.h"	
-static char* telnet_defstatmod[] = {"softmodem","phy","loader"}; 
+#include "telnetsrv_proccmd.h"
+static char *telnet_defstatmod[] = {"softmodem","phy","loader","measur"};
 static telnetsrv_params_t telnetparams;
 #define TELNETSRV_LISTENADDR 0
 #define TELNETSRV_LISTENPORT 1
@@ -66,179 +66,169 @@ static telnetsrv_params_t telnetparams;
 #define TELNETSRV_DEBUG      3
 #define TELNETSRV_LOOPC      4
 #define TELNETSRV_LOOPD      5
-#define TELNETSRV_HISFILE    6  
-#define TELNETSRV_HISSIZE    7 
-#define TELNETSRV_PHYBSIZE   8  
+#define TELNETSRV_HISFILE    6
+#define TELNETSRV_HISSIZE    7
+#define TELNETSRV_PHYBSIZE   8
 #define TELNETSRV_STATICMOD  9
 #define TELNETSRV_SHRMOD     10
 
 paramdef_t telnetoptions[] = {
-/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
-/*                                            configuration parameters for telnet utility                                                                             */
-/*   optname                     helpstr                paramflags           XXXptr                               defXXXval               type                 numelt */
-/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
-	{"listenaddr",    "<listen ip address>",         0,                 uptr:&telnetparams.listenaddr,        defstrval:"0.0.0.0",            TYPE_IPV4ADDR,  0 },
-	{"listenport",    "<local port>",                0,                 uptr:&(telnetparams.listenport),      defuintval:9090,                TYPE_UINT,      0 },
-        {"priority",      "<scheduling policy (0-99)",   0,                 iptr:&telnetparams.priority,          defuintval:0,                   TYPE_INT,       0 }, 
-	{"debug",         "<debug level>",               0,                 uptr:NULL,                            defuintval:0,                   TYPE_UINT,      0 },
-	{"loopcount",     "<loop command iterations>",   0,                 uptr:&(telnetparams.loopcount),       defuintval:10,                  TYPE_UINT,      0 },
-	{"loopdelay",     "<loop command delay (ms)>",   0,                 uptr:&(telnetparams.loopdelay),       defuintval:5000,                TYPE_UINT,      0 },
-	{"histfile",      "<history file name>",         PARAMFLAG_NOFREE,  strptr:&(telnetparams.histfile),      defstrval:"oaitelnet.history",  TYPE_STRING,    0 },
-	{"histsize",      "<history sizes>",             0,                 iptr:&(telnetparams.histsize),        defuintval:50,                  TYPE_INT,       0 },
-	{"phypbsize",     "<phy dump buff size (bytes)>",0,                 uptr:&(telnetparams.phyprntbuff_size),defuintval:65000,               TYPE_UINT,      0 },
-        {"staticmod",     "<static modules selection>",  0,                 strlistptr:NULL,                      defstrlistval:telnet_defstatmod,TYPE_STRINGLIST,(sizeof(telnet_defstatmod)/sizeof(char *))},
-        {"shrmod",        "<dynamic modules selection>", 0,                 strlistptr:NULL,                      defstrlistval:NULL,TYPE_STRINGLIST,0 }
+  /*--------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
+  /*                                            configuration parameters for telnet utility                                                                             */
+  /*   optname                     helpstr                paramflags           XXXptr                               defXXXval               type                 numelt */
+  /*--------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
+  {"listenaddr",    "<listen ip address>",         0,                 uptr:&telnetparams.listenaddr,        defstrval:"0.0.0.0",            TYPE_IPV4ADDR,  0 },
+  {"listenport",    "<local port>",                0,                 uptr:&(telnetparams.listenport),      defuintval:9090,                TYPE_UINT,      0 },
+  {"priority",      "<scheduling policy (0-99)",   0,                 iptr:&telnetparams.priority,          defuintval:0,                   TYPE_INT,       0 },
+  {"debug",         "<debug level>",               0,                 uptr:NULL,                            defuintval:0,                   TYPE_UINT,      0 },
+  {"loopcount",     "<loop command iterations>",   0,                 uptr:&(telnetparams.loopcount),       defuintval:10,                  TYPE_UINT,      0 },
+  {"loopdelay",     "<loop command delay (ms)>",   0,                 uptr:&(telnetparams.loopdelay),       defuintval:5000,                TYPE_UINT,      0 },
+  {"histfile",      "<history file name>",         PARAMFLAG_NOFREE,  strptr:&(telnetparams.histfile),      defstrval:"oaitelnet.history",  TYPE_STRING,    0 },
+  {"histsize",      "<history sizes>",             0,                 iptr:&(telnetparams.histsize),        defuintval:50,                  TYPE_INT,       0 },
+  {"phypbsize",     "<phy dump buff size (bytes)>",0,                 uptr:&(telnetparams.phyprntbuff_size),defuintval:65000,               TYPE_UINT,      0 },
+  {"staticmod",     "<static modules selection>",  0,                 strlistptr:NULL,                      defstrlistval:telnet_defstatmod,TYPE_STRINGLIST,(sizeof(telnet_defstatmod)/sizeof(char *))},
+  {"shrmod",        "<dynamic modules selection>", 0,                 strlistptr:NULL,                      defstrlistval:NULL,TYPE_STRINGLIST,0 }
 };
 
-int get_phybsize(void) {return telnetparams.phyprntbuff_size; };
+int get_phybsize(void) {
+  return telnetparams.phyprntbuff_size;
+};
 int add_telnetcmd(char *modulename,telnetshell_vardef_t *var, telnetshell_cmddef_t *cmd );
 int setoutput(char *buff, int debug, telnet_printfunc_t prnt);
 int setparam(char *buff, int debug, telnet_printfunc_t prnt);
 int history_cmd(char *buff, int debug, telnet_printfunc_t prnt);
 
 telnetshell_vardef_t telnet_vardef[] = {
-{"debug",TELNET_VARTYPE_INT32,&telnetparams.telnetdbg},
-{"prio",TELNET_VARTYPE_INT32,&telnetparams.priority},
-{"loopc",TELNET_VARTYPE_INT32,&telnetparams.loopcount},
-{"loopd",TELNET_VARTYPE_INT32,&telnetparams.loopdelay},
-{"phypb",TELNET_VARTYPE_INT32,&telnetparams.phyprntbuff_size},
-{"hsize",TELNET_VARTYPE_INT32,&telnetparams.histsize},
-{"hfile",TELNET_VARTYPE_STRING,&telnetparams.histfile},
-{"",0,NULL}
+  {"debug",TELNET_VARTYPE_INT32,&telnetparams.telnetdbg},
+  {"prio",TELNET_VARTYPE_INT32,&telnetparams.priority},
+  {"loopc",TELNET_VARTYPE_INT32,&telnetparams.loopcount},
+  {"loopd",TELNET_VARTYPE_INT32,&telnetparams.loopdelay},
+  {"phypb",TELNET_VARTYPE_INT32,&telnetparams.phyprntbuff_size},
+  {"hsize",TELNET_VARTYPE_INT32,&telnetparams.histsize},
+  {"hfile",TELNET_VARTYPE_STRING,&telnetparams.histfile},
+  {"",0,NULL}
 };
 
 telnetshell_cmddef_t  telnet_cmdarray[] = {
-   {"redirlog","[here,file,off]",setoutput},
-   {"param","[prio]",setparam},
-   {"history","[list,reset]",history_cmd},
-   {"","",NULL},
+  {"redirlog","[here,file,off]",setoutput},
+  {"param","[prio]",setparam},
+  {"history","[list,reset]",history_cmd},
+  {"","",NULL},
 };
 
 
-void client_printf(const char *message, ...)
-{
-    va_list va_args;
-    
-    va_start(va_args, message);
-    if (telnetparams.new_socket > 0)
-       {
-       vsnprintf(telnetparams.msgbuff,sizeof(telnetparams.msgbuff)-1,message, va_args);
-       send(telnetparams.new_socket,telnetparams.msgbuff , strlen(telnetparams.msgbuff), MSG_NOSIGNAL);
-       }
-    else
-       {
-       vprintf(message, va_args);
-       }
-    va_end(va_args);
-    return ;
+void client_printf(const char *message, ...) {
+  va_list va_args;
+  va_start(va_args, message);
+
+  if (telnetparams.new_socket > 0) {
+    vsnprintf(telnetparams.msgbuff,sizeof(telnetparams.msgbuff)-1,message, va_args);
+    send(telnetparams.new_socket,telnetparams.msgbuff , strlen(telnetparams.msgbuff), MSG_NOSIGNAL);
+  } else {
+    vprintf(message, va_args);
+  }
+
+  va_end(va_args);
+  return ;
 }
 
 #define NICE_MAX 19
 #define NICE_MIN -20
-void set_sched(pthread_t tid, int pid, int priority)
-{
-int rt; 
-struct sched_param schedp;
-int policy;
-char strpolicy[10];
-
-
-//sched_get_priority_max(SCHED_FIFO)
-if (priority < NICE_MIN) {
-   policy=SCHED_FIFO;
-   sprintf(strpolicy,"%s","fifo");
-   schedp.sched_priority= NICE_MIN - priority ;
-   if (   (schedp.sched_priority < sched_get_priority_min(SCHED_FIFO)) ||
-          (schedp.sched_priority > sched_get_priority_max(SCHED_FIFO)) ) {
-        client_printf("Error: %i invalid prio, should be %i to %i, \n",
-                       priority, NICE_MIN -sched_get_priority_min(SCHED_FIFO),
-                       NICE_MIN - sched_get_priority_max(SCHED_FIFO) );        
-   }
-} else if (priority > NICE_MAX) {
-   policy=SCHED_IDLE;
-   sprintf(strpolicy,"%s","idle");
-   schedp.sched_priority=0;   
-} else {
-   policy=SCHED_OTHER;
-   sprintf(strpolicy,"%s","other");
-   schedp.sched_priority=0;   
-}
- 
-if( tid != 0) {  
-  rt = pthread_setschedparam(tid, policy, &schedp);
-} else if(pid > 0)  {
-  rt = sched_setscheduler( pid, policy,&schedp);
-} else {
-  rt= -1;
-  client_printf("Error: no pid or tid specified\n");
-}
+void set_sched(pthread_t tid, int pid, int priority) {
+  int rt;
+  struct sched_param schedp;
+  int policy;
+  char strpolicy[10];
+
+  //sched_get_priority_max(SCHED_FIFO)
+  if (priority < NICE_MIN) {
+    policy=SCHED_FIFO;
+    sprintf(strpolicy,"%s","fifo");
+    schedp.sched_priority= NICE_MIN - priority ;
+
+    if (   (schedp.sched_priority < sched_get_priority_min(SCHED_FIFO)) ||
+           (schedp.sched_priority > sched_get_priority_max(SCHED_FIFO)) ) {
+      client_printf("Error: %i invalid prio, should be %i to %i, \n",
+                    priority, NICE_MIN -sched_get_priority_min(SCHED_FIFO),
+                    NICE_MIN - sched_get_priority_max(SCHED_FIFO) );
+    }
+  } else if (priority > NICE_MAX) {
+    policy=SCHED_IDLE;
+    sprintf(strpolicy,"%s","idle");
+    schedp.sched_priority=0;
+  } else {
+    policy=SCHED_OTHER;
+    sprintf(strpolicy,"%s","other");
+    schedp.sched_priority=0;
+  }
 
-if (rt != 0) {
+  if( tid != 0) {
+    rt = pthread_setschedparam(tid, policy, &schedp);
+  } else if(pid > 0)  {
+    rt = sched_setscheduler( pid, policy,&schedp);
+  } else {
+    rt= -1;
+    client_printf("Error: no pid or tid specified\n");
+  }
+
+  if (rt != 0) {
     client_printf("Error %i: %s modifying sched param to %s:%i, \n",
-                  errno,strerror(errno),strpolicy,schedp.sched_priority); 
-} else  {
+                  errno,strerror(errno),strpolicy,schedp.sched_priority);
+  } else  {
     client_printf("policy set to %s, priority %i\n",strpolicy,schedp.sched_priority);
+
     if ( policy==SCHED_OTHER) {
-        rt = getpriority(PRIO_PROCESS,tid);
-        if (rt != -1) {
-           rt = setpriority(PRIO_PROCESS,tid,priority);  
-           if (rt < 0) {
-               client_printf("Error %i: %s trying to set nice value of thread %u to %i\n",
-                             errno,strerror(errno),tid,priority); 
-           }
-        } else {
-               client_printf("Error %i: %s trying to get nice value of thread %u \n",
-                              errno,strerror(errno),tid); 
+      rt = getpriority(PRIO_PROCESS,tid);
+
+      if (rt != -1) {
+        rt = setpriority(PRIO_PROCESS,tid,priority);
+
+        if (rt < 0) {
+          client_printf("Error %i: %s trying to set nice value of thread %u to %i\n",
+                        errno,strerror(errno),tid,priority);
         }
+      } else {
+        client_printf("Error %i: %s trying to get nice value of thread %u \n",
+                      errno,strerror(errno),tid);
+      }
     }
-}
-
+  }
 
+  if ( policy == SCHED_OTHER) {
+    if ( tid > 0 && tid != pthread_self()) {
+      client_printf("setting nice value using a thread id not implemented....\n");
+    } else if (pid > 0) {
+      errno=0;
+      rt = setpriority(PRIO_PROCESS,pid,priority);
 
-if ( policy == SCHED_OTHER)
-   {
-   if ( tid > 0 && tid != pthread_self())
-     {
-     client_printf("setting nice value using a thread id not implemented....\n");    
-     }
-   else if (pid > 0)
-     {
-     errno=0;
-     rt = setpriority(PRIO_PROCESS,pid,priority);
-     if (rt != 0)
-        {
-        client_printf("Error %i: %s calling setpriority, \n",errno,strerror(errno)); 
-        }
-     else
-        {
+      if (rt != 0) {
+        client_printf("Error %i: %s calling setpriority, \n",errno,strerror(errno));
+      } else {
         client_printf("nice value set to %i\n",priority);
-        }
-     }
-   }
+      }
+    }
+  }
 }
 
-void set_affinity(pthread_t tid, int pid, int coreid)
-{
-cpu_set_t cpuset;
-int rt;
-
+void set_affinity(pthread_t tid, int pid, int coreid) {
+  cpu_set_t cpuset;
+  int rt;
   CPU_ZERO(&cpuset);
   CPU_SET(coreid, &cpuset);
+
   if (tid > 0) {
-     rt = pthread_setaffinity_np((pthread_t)tid, sizeof(cpu_set_t), &cpuset);
-  } else if (pid > 0){
-     rt = sched_setaffinity((pid_t)pid, sizeof(cpu_set_t), &cpuset);
+    rt = pthread_setaffinity_np((pthread_t)tid, sizeof(cpu_set_t), &cpuset);
+  } else if (pid > 0) {
+    rt = sched_setaffinity((pid_t)pid, sizeof(cpu_set_t), &cpuset);
   } else {
-     rt= -1;
+    rt= -1;
+  }
+
+  if (rt != 0) {
+    client_printf("Error %i: %s calling , xxx_setaffinity...\n",errno,strerror(errno));
+  } else {
+    client_printf("thread %i affinity set to %i\n",(pid==0)?(int)tid:pid,coreid);
   }
-  if (rt != 0)
-      {
-      client_printf("Error %i: %s calling , xxx_setaffinity...\n",errno,strerror(errno)); 
-      }
-  else
-      {
-      client_printf("thread %i affinity set to %i\n",(pid==0)?(int)tid:pid,coreid);
-      }  
 }
 /*------------------------------------------------------------------------------------*/
 /*
@@ -246,551 +236,541 @@ function implementing telnet server specific commands, parameters of the
 telnet_cmdarray table
 */
 
-void redirstd(char *newfname,telnet_printfunc_t prnt )
-{
-FILE *fd;
-   fd=freopen(newfname, "w", stdout);
-   if (fd == NULL)
-      {
-      prnt("ERROR: stdout redir to %s error %s",strerror(errno));
-      }
-   fd=freopen(newfname, "w", stderr);
-   if (fd == NULL)
-      {
-      prnt("ERROR: stderr redir to %s error %s",strerror(errno));
-      }
-}
-int setoutput(char *buff, int debug, telnet_printfunc_t prnt)
-{
+void redirstd(char *newfname,telnet_printfunc_t prnt ) {
+  FILE *fd;
+  fd=freopen(newfname, "w", stdout);
 
-char cmds[TELNET_MAX_MSGLENGTH/TELNET_CMD_MAXSIZE][TELNET_CMD_MAXSIZE];
-char *logfname;
-char stdout_str[64];
+  if (fd == NULL) {
+    prnt("ERROR: stdout redir to %s error %s",strerror(errno));
+  }
 
+  fd=freopen(newfname, "w", stderr);
 
+  if (fd == NULL) {
+    prnt("ERROR: stderr redir to %s error %s",strerror(errno));
+  }
+}
+int setoutput(char *buff, int debug, telnet_printfunc_t prnt) {
+  char cmds[TELNET_MAX_MSGLENGTH/TELNET_CMD_MAXSIZE][TELNET_CMD_MAXSIZE];
+  char *logfname;
+  char stdout_str[64];
 #define LOGFILE "logfile.log"
-memset(cmds,0,sizeof(cmds));
-sscanf(buff,"%9s %32s %9s %9s %9s", cmds[0],cmds[1],cmds[2],cmds[3],cmds[4]  );
-if (strncasecmp(cmds[0],"here",4) == 0)
-   {
-   fflush(stdout);
-   sprintf(stdout_str,"/proc/%i/fd/%i",getpid(),telnetparams.new_socket);
-   dup2(telnetparams.new_socket,fileno(stdout));
-//   freopen(stdout_str, "w", stdout);
-//   freopen(stdout_str, "w", stderr);
-   dup2(telnetparams.new_socket,fileno(stderr));
-   prnt("Log output redirected to this terminal (%s)\n",stdout_str);
-   }
-if (strncasecmp(cmds[0],"file",4) == 0)
-   {
-   if (cmds[1][0] == 0)
+  memset(cmds,0,sizeof(cmds));
+  sscanf(buff,"%9s %32s %9s %9s %9s", cmds[0],cmds[1],cmds[2],cmds[3],cmds[4]  );
+
+  if (strncasecmp(cmds[0],"here",4) == 0) {
+    fflush(stdout);
+    sprintf(stdout_str,"/proc/%i/fd/%i",getpid(),telnetparams.new_socket);
+    dup2(telnetparams.new_socket,fileno(stdout));
+    //   freopen(stdout_str, "w", stdout);
+    //   freopen(stdout_str, "w", stderr);
+    dup2(telnetparams.new_socket,fileno(stderr));
+    prnt("Log output redirected to this terminal (%s)\n",stdout_str);
+  }
+
+  if (strncasecmp(cmds[0],"file",4) == 0) {
+    if (cmds[1][0] == 0)
       logfname=LOGFILE;
-   else
-      logfname=cmds[1];   
-   fflush(stdout);
-   redirstd(logfname,prnt);
-
-   }   
-if (strncasecmp(cmds[0],"off",3) == 0)
-   {
-   fflush(stdout);
-   redirstd("/dev/tty",prnt); 
-   } 
-
-return CMDSTATUS_FOUND;   
+    else
+      logfname=cmds[1];
+
+    fflush(stdout);
+    redirstd(logfname,prnt);
+  }
+
+  if (strncasecmp(cmds[0],"off",3) == 0) {
+    fflush(stdout);
+    redirstd("/dev/tty",prnt);
+  }
+
+  return CMDSTATUS_FOUND;
 } /* setoutput */
 
-int setparam(char *buff, int debug, telnet_printfunc_t prnt)
-{
-char cmds[TELNET_MAX_MSGLENGTH/TELNET_CMD_MAXSIZE][TELNET_CMD_MAXSIZE];
-
-
-memset(cmds,0,sizeof(cmds));
-sscanf(buff,"%9s %9s %9s %9s %9s", cmds[0],cmds[1],cmds[2],cmds[3],cmds[4]  );
-if (strncasecmp(cmds[0],"prio",4) == 0)
-   {
-   int prio;
-   prio=(int)strtol(cmds[1],NULL,0);
-   if (errno == ERANGE)
-       return CMDSTATUS_VARNOTFOUND;
-   telnetparams.priority = prio;
-   set_sched(pthread_self(),0,prio);
-   return CMDSTATUS_FOUND; 
-   }
-if (strncasecmp(cmds[0],"aff",3) == 0)
-   {
-   int aff;
-   aff=(int)strtol(cmds[1],NULL,0);
-   if (errno == ERANGE)
-       return CMDSTATUS_VARNOTFOUND;
-   set_affinity(pthread_self(),0,aff);
-   return CMDSTATUS_FOUND; 
-   }
-
-return CMDSTATUS_NOTFOUND;   
-} /* setparam */
+int setparam(char *buff, int debug, telnet_printfunc_t prnt) {
+  char cmds[TELNET_MAX_MSGLENGTH/TELNET_CMD_MAXSIZE][TELNET_CMD_MAXSIZE];
+  memset(cmds,0,sizeof(cmds));
+  sscanf(buff,"%9s %9s %9s %9s %9s", cmds[0],cmds[1],cmds[2],cmds[3],cmds[4]  );
+
+  if (strncasecmp(cmds[0],"prio",4) == 0) {
+    int prio;
+    prio=(int)strtol(cmds[1],NULL,0);
+
+    if (errno == ERANGE)
+      return CMDSTATUS_VARNOTFOUND;
 
-int history_cmd(char *buff, int debug, telnet_printfunc_t prnt)
-{
-char cmds[TELNET_MAX_MSGLENGTH/TELNET_CMD_MAXSIZE][TELNET_CMD_MAXSIZE];
+    telnetparams.priority = prio;
+    set_sched(pthread_self(),0,prio);
+    return CMDSTATUS_FOUND;
+  }
+
+  if (strncasecmp(cmds[0],"aff",3) == 0) {
+    int aff;
+    aff=(int)strtol(cmds[1],NULL,0);
+
+    if (errno == ERANGE)
+      return CMDSTATUS_VARNOTFOUND;
+
+    set_affinity(pthread_self(),0,aff);
+    return CMDSTATUS_FOUND;
+  }
 
+  return CMDSTATUS_NOTFOUND;
+} /* setparam */
+
+int history_cmd(char *buff, int debug, telnet_printfunc_t prnt) {
+  char cmds[TELNET_MAX_MSGLENGTH/TELNET_CMD_MAXSIZE][TELNET_CMD_MAXSIZE];
+  memset(cmds,0,sizeof(cmds));
+  sscanf(buff,"%9s %9s %9s %9s %9s", cmds[0],cmds[1],cmds[2],cmds[3],cmds[4]  );
 
-memset(cmds,0,sizeof(cmds));
-sscanf(buff,"%9s %9s %9s %9s %9s", cmds[0],cmds[1],cmds[2],cmds[3],cmds[4]  );
-if (cmds[0] == NULL)
+  if (cmds[0] == NULL)
     return CMDSTATUS_VARNOTFOUND;
-if (strncasecmp(cmds[0],"list",4) == 0)
-   {
-   HIST_ENTRY **hist = history_list();
-   if (hist) {
+
+  if (strncasecmp(cmds[0],"list",4) == 0) {
+    HIST_ENTRY **hist = history_list();
+
+    if (hist) {
       for (int i = 0; hist[i]; i++) {
-          prnt ("%d: %s\n", i + history_base, hist[i]->line);
+        prnt ("%d: %s\n", i + history_base, hist[i]->line);
       }
-   }
-   return CMDSTATUS_FOUND; 
-   }
-if (strncasecmp(cmds[0],"reset",5) == 0)
-   {
-   clear_history();
-   write_history(telnetparams.histfile);
-   return CMDSTATUS_FOUND; 
-   }
-
-return CMDSTATUS_NOTFOUND; 
+    }
+
+    return CMDSTATUS_FOUND;
+  }
+
+  if (strncasecmp(cmds[0],"reset",5) == 0) {
+    clear_history();
+    write_history(telnetparams.histfile);
+    return CMDSTATUS_FOUND;
+  }
+
+  return CMDSTATUS_NOTFOUND;
 } /* history_cmd */
 /*-------------------------------------------------------------------------------------------------------*/
 /*
 generic commands available for all modules loaded by the server
 */
 
-int setgetvar(int moduleindex,char getorset,char *params)
-{
-int n,i;
-char varname[TELNET_CMD_MAXSIZE];
-char *varval=NULL;
-
-   memset(varname,0,sizeof(varname));
-
-   n = sscanf(params,"%s %ms",varname,&varval);
-   for ( i=0 ; telnetparams.CmdParsers[moduleindex].var[i].varvalptr != NULL ; i++)
-      {
-      if ( strncasecmp(telnetparams.CmdParsers[moduleindex].var[i].varname,varname,strlen(telnetparams.CmdParsers[moduleindex].var[i].varname)) == 0)
-         {
-	 if (n > 0 && (getorset == 'g' || getorset == 'G'))
-	    {
-	    client_printf("%s, %s = ", telnetparams.CmdParsers[moduleindex].module,
-	               telnetparams.CmdParsers[moduleindex].var[i].varname );
-	    switch(telnetparams.CmdParsers[moduleindex].var[i].vartype)
-	        {
-		case TELNET_VARTYPE_INT32:
-	             client_printf("%i\n",*(int32_t *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
-		break;
-		case TELNET_VARTYPE_INT64:
-	             client_printf("%lli\n",*(int64_t *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
-		break;
-		case TELNET_VARTYPE_INT16:
-	             client_printf("%hi\n",*(short *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
-		break;	
-		case TELNET_VARTYPE_DOUBLE:
-	             client_printf("%g\n",*(double *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
-		break;
-		case TELNET_VARTYPE_STRING:
-	             client_printf("\"%s\"\n",*(char **)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));						
-                break;
-		default:
-		     client_printf("unknown type\n");
-		break;
-		}
-	    }
-	 if (n > 1 && (getorset == 's' || getorset == 'S'))
-	    {
-	    client_printf("%s, %s set to \n", telnetparams.CmdParsers[moduleindex].module,
-	           telnetparams.CmdParsers[moduleindex].var[i].varname);
-		   
-	    switch(telnetparams.CmdParsers[moduleindex].var[i].vartype)
-	        {
-		case TELNET_VARTYPE_INT32:
-		     *(int *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr) = (int)strtol(varval,NULL,0);
-	             client_printf("%i\n",*(int *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
-		break;
-		case TELNET_VARTYPE_INT16:
-		     *(short *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr) = (short)strtol(varval,NULL,0);
-	             client_printf("%hi\n",*(short *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
-		break;	
-		case TELNET_VARTYPE_DOUBLE:
-		     *(double *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr) = strtod(varval,NULL);
-	             client_printf("%g\n",*(double *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
-		break;	
-		case TELNET_VARTYPE_STRING:
-		     sprintf(*(char **)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr),"%s", varval);
-	             client_printf("\"%s\"\n",*(char **)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
-		break;				
-		default:
-		     client_printf("unknown type\n");
-		break;
-		}		   
-	    }		   
-	 }
-      } 
-if (n>1 && varval != NULL) {
-   free(varval);
-}
-return CMDSTATUS_VARNOTFOUND;
+int setgetvar(int moduleindex,char getorset,char *params) {
+  int n,i;
+  char varname[TELNET_CMD_MAXSIZE];
+  char *varval=NULL;
+  memset(varname,0,sizeof(varname));
+  n = sscanf(params,"%19s %ms",varname,&varval);
+
+  for ( i=0 ; telnetparams.CmdParsers[moduleindex].var[i].varvalptr != NULL ; i++) {
+    if ( strncasecmp(telnetparams.CmdParsers[moduleindex].var[i].varname,varname,strlen(telnetparams.CmdParsers[moduleindex].var[i].varname)) == 0) {
+      if (n > 0 && (getorset == 'g' || getorset == 'G')) {
+        client_printf("%s, %s = ", telnetparams.CmdParsers[moduleindex].module,
+                      telnetparams.CmdParsers[moduleindex].var[i].varname );
+
+        switch(telnetparams.CmdParsers[moduleindex].var[i].vartype) {
+          case TELNET_VARTYPE_INT32:
+            client_printf("%i\n",*(int32_t *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
+            break;
+
+          case TELNET_VARTYPE_INT64:
+            client_printf("%lli\n",*(int64_t *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
+            break;
+
+          case TELNET_VARTYPE_INT16:
+            client_printf("%hi\n",*(short *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
+            break;
+
+          case TELNET_VARTYPE_DOUBLE:
+            client_printf("%g\n",*(double *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
+            break;
+
+          case TELNET_VARTYPE_STRING:
+            client_printf("\"%s\"\n",*(char **)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
+            break;
+
+          default:
+            client_printf("unknown type\n");
+            break;
+        }
+      }
+
+      if (n > 1 && (getorset == 's' || getorset == 'S')) {
+        client_printf("%s, %s set to \n", telnetparams.CmdParsers[moduleindex].module,
+                      telnetparams.CmdParsers[moduleindex].var[i].varname);
+
+        switch(telnetparams.CmdParsers[moduleindex].var[i].vartype) {
+          case TELNET_VARTYPE_INT32:
+            *(int *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr) = (int)strtol(varval,NULL,0);
+            client_printf("%i\n",*(int *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
+            break;
+
+          case TELNET_VARTYPE_INT16:
+            *(short *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr) = (short)strtol(varval,NULL,0);
+            client_printf("%hi\n",*(short *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
+            break;
+
+          case TELNET_VARTYPE_DOUBLE:
+            *(double *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr) = strtod(varval,NULL);
+            client_printf("%g\n",*(double *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
+            break;
+
+          case TELNET_VARTYPE_STRING:
+            sprintf(*(char **)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr),"%s", varval);
+            client_printf("\"%s\"\n",*(char **)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
+            break;
+
+          default:
+            client_printf("unknown type\n");
+            break;
+        }
+      }
+    }
+  }
+
+  if (n>1 && varval != NULL) {
+    free(varval);
+  }
+
+  return CMDSTATUS_VARNOTFOUND;
 }
 /*----------------------------------------------------------------------------------------------------*/
-char *get_time(char *buff,int bufflen)
-{
-
-struct tm  tmstruct;
-time_t now = time (0);
-strftime (buff, bufflen, "%Y-%m-%d %H:%M:%S.000", localtime_r(&now,&tmstruct));
-return buff;
+char *get_time(char *buff,int bufflen) {
+  struct tm  tmstruct;
+  time_t now = time (0);
+  strftime (buff, bufflen, "%Y-%m-%d %H:%M:%S.000", localtime_r(&now,&tmstruct));
+  return buff;
 }
 
-int process_command(char *buf)
-{
-int i,j,k;
-char modulename[TELNET_CMD_MAXSIZE];
-char cmd[TELNET_CMD_MAXSIZE];
-char cmdb[TELNET_MAX_MSGLENGTH];
-char *bufbck;
-int rt;
-
-memset(modulename,0,sizeof(modulename));
-memset(cmd,0,sizeof(cmd));
-memset(cmdb,0,sizeof(cmdb));
-if (strncasecmp(buf,"ex",2) == 0)
-   return CMDSTATUS_EXIT;
-
-if (strncasecmp(buf,"help",4) == 0)
-   {
-   for (i=0; telnetparams.CmdParsers[i].var != NULL && telnetparams.CmdParsers[i].cmd != NULL; i++)
-    {
-     client_printf("   module %i = %s:\n",i,telnetparams.CmdParsers[i].module);
-     for(j=0; telnetparams.CmdParsers[i].var[j].varvalptr != NULL ; j++)
-        {
-	client_printf("      %s [get set] %s <value>\n",
-	       telnetparams.CmdParsers[i].module, telnetparams.CmdParsers[i].var[j].varname);
-	} 
-     for(j=0; telnetparams.CmdParsers[i].cmd[j].cmdfunc != NULL ; j++)
-        {
-	client_printf("      %s %s %s\n",
-	       telnetparams.CmdParsers[i].module,telnetparams.CmdParsers[i].cmd[j].cmdname,
-	       telnetparams.CmdParsers[i].cmd[j].helpstr);
-	} 	
+int process_command(char *buf) {
+  int i,j,k;
+  char modulename[TELNET_CMD_MAXSIZE];
+  char cmd[TELNET_CMD_MAXSIZE];
+  char cmdb[TELNET_MAX_MSGLENGTH];
+  char *bufbck;
+  int rt;
+  memset(modulename,0,sizeof(modulename));
+  memset(cmd,0,sizeof(cmd));
+  memset(cmdb,0,sizeof(cmdb));
+
+  if (strncasecmp(buf,"ex",2) == 0)
+    return CMDSTATUS_EXIT;
+
+  if (strncasecmp(buf,"help",4) == 0) {
+    for (i=0; telnetparams.CmdParsers[i].var != NULL && telnetparams.CmdParsers[i].cmd != NULL; i++) {
+      client_printf("   module %i = %s:\n",i,telnetparams.CmdParsers[i].module);
+
+      for(j=0; telnetparams.CmdParsers[i].var[j].varvalptr != NULL ; j++) {
+        client_printf("      %s [get set] %s <value>\n",
+                      telnetparams.CmdParsers[i].module, telnetparams.CmdParsers[i].var[j].varname);
+      }
+
+      for(j=0; telnetparams.CmdParsers[i].cmd[j].cmdfunc != NULL ; j++) {
+        client_printf("      %s %s %s\n",
+                      telnetparams.CmdParsers[i].module,telnetparams.CmdParsers[i].cmd[j].cmdname,
+                      telnetparams.CmdParsers[i].cmd[j].helpstr);
+      }
     }
-   return CMDSTATUS_FOUND;
-   }
-
-memset(modulename,0,sizeof(modulename));
-memset(cmd,0,sizeof(cmd));
-memset(cmdb,0,sizeof(cmdb));  
-bufbck=strdup(buf); 
-rt=CMDSTATUS_NOTFOUND;   
-j = sscanf(buf,"%9s %9s %[^\t\n]",modulename,cmd,cmdb);
-if (telnetparams.telnetdbg > 0)
-    printf("process_command: %i words, module=%s cmd=%s, parameters= %s\n",j,modulename,cmd,cmdb);   
-for (i=0; j>=2 && telnetparams.CmdParsers[i].var != NULL && telnetparams.CmdParsers[i].cmd != NULL; i++)
-    {
-    if ( (strncasecmp(telnetparams.CmdParsers[i].module,modulename,strlen(telnetparams.CmdParsers[i].module)) == 0))
-       {
-        if (strncasecmp(cmd,"getall",7) == 0 )
-	    { 
-            for(j=0; telnetparams.CmdParsers[i].var[j].varvalptr != NULL ; j++)
-               {
-	       setgetvar(i,'g',telnetparams.CmdParsers[i].var[j].varname);
-	       }
-	    rt= CMDSTATUS_FOUND;              
-	    }       
-        else if (strncasecmp(cmd,"get",3) == 0 || strncasecmp(cmd,"set",3) == 0)
-	    {
-            rt= setgetvar(i,cmd[0],cmdb);	    
-	    }	    
-        else
-	    {
-	    for (k=0 ; telnetparams.CmdParsers[i].cmd[k].cmdfunc != NULL ; k++)
-	        {
-	        if (strncasecmp(cmd, telnetparams.CmdParsers[i].cmd[k].cmdname,sizeof(telnetparams.CmdParsers[i].cmd[k].cmdname)) == 0)
-                   {
-	           telnetparams.CmdParsers[i].cmd[k].cmdfunc(cmdb, telnetparams.telnetdbg, client_printf);
-                   rt= CMDSTATUS_FOUND;
-	           }
-		} /* for k */
-	    }/* else */
-	}/* strncmp: module name test */
-     else if (strncasecmp(modulename,"loop",4) == 0 )
-	{
-	int lc;
-        int f = fcntl(telnetparams.new_socket,F_GETFL);
-	fcntl (telnetparams.new_socket, F_SETFL, O_NONBLOCK | f);
-	for(lc=0; lc<telnetparams.loopcount; lc++)
-	   {
-	   char dummybuff[20];
-	   char tbuff[64];
-       int rs;
-	   client_printf(CSI "1J" CSI "1;10H         " STDFMT "%s %i/%i\n",
-	                 get_time(tbuff,sizeof(tbuff)),lc,telnetparams.loopcount );  
-       process_command(bufbck+strlen("loop")+1);
-       usleep(telnetparams.loopdelay * 1000);
-	   rs = read(telnetparams.new_socket,dummybuff,sizeof(dummybuff)); 
-	   if ( rs > 0 )
-	       {
-	       break;
-	       }
-	   }
-	fcntl (telnetparams.new_socket, F_SETFL, f);
-	rt= CMDSTATUS_FOUND;	    
-	} /* loop */
-    } /* for i */
-free(bufbck);
-return rt;
+
+    return CMDSTATUS_FOUND;
+  }
+
+  memset(modulename,0,sizeof(modulename));
+  memset(cmd,0,sizeof(cmd));
+  memset(cmdb,0,sizeof(cmdb));
+  bufbck=strdup(buf);
+  rt=CMDSTATUS_NOTFOUND;
+  j = sscanf(buf,"%9s %9s %2000[^\t\n]",modulename,cmd,cmdb);
+
+  if (telnetparams.telnetdbg > 0)
+    printf("process_command: %i words, module=%s cmd=%s, parameters= %s\n",j,modulename,cmd,cmdb);
+
+  for (i=0; j>=2 && telnetparams.CmdParsers[i].var != NULL && telnetparams.CmdParsers[i].cmd != NULL; i++) {
+    if ( (strncasecmp(telnetparams.CmdParsers[i].module,modulename,strlen(telnetparams.CmdParsers[i].module)) == 0)) {
+      if (strncasecmp(cmd,"getall",7) == 0 ) {
+        for(j=0; telnetparams.CmdParsers[i].var[j].varvalptr != NULL ; j++) {
+          setgetvar(i,'g',telnetparams.CmdParsers[i].var[j].varname);
+        }
+
+        rt= CMDSTATUS_FOUND;
+      } else if (strncasecmp(cmd,"get",3) == 0 || strncasecmp(cmd,"set",3) == 0) {
+        rt= setgetvar(i,cmd[0],cmdb);
+      } else {
+        for (k=0 ; telnetparams.CmdParsers[i].cmd[k].cmdfunc != NULL ; k++) {
+          if (strncasecmp(cmd, telnetparams.CmdParsers[i].cmd[k].cmdname,sizeof(telnetparams.CmdParsers[i].cmd[k].cmdname)) == 0) {
+            telnetparams.CmdParsers[i].cmd[k].cmdfunc(cmdb, telnetparams.telnetdbg, client_printf);
+            rt= CMDSTATUS_FOUND;
+          }
+        } /* for k */
+      }/* else */
+    }/* strncmp: module name test */
+    else if (strncasecmp(modulename,"loop",4) == 0 ) {
+      int f = fcntl(telnetparams.new_socket,F_GETFL);
+      int f1=fcntl (telnetparams.new_socket, F_SETFL, O_NONBLOCK | f);
+
+      if (f<0 || f1 <0) {
+        client_printf( " Loop won't be cancelable: %s\n",strerror(errno) );
+      }
+
+      for(int lc=0; lc<telnetparams.loopcount; lc++) {
+        char dummybuff[20];
+        char tbuff[64];
+        client_printf(CSI "1J" CSI "1;10H         " STDFMT "%s %i/%i\n",
+                      get_time(tbuff,sizeof(tbuff)),lc,telnetparams.loopcount );
+        process_command(bufbck+strlen("loop")+1);
+        errno=0;
+        int rs = read(telnetparams.new_socket,dummybuff,sizeof(dummybuff));
+
+        if (telnetparams.telnetdbg > 0)
+          client_printf("Received \"%s\" status %d, errno %s while running loop\n",dummybuff,rs,strerror(errno));
+
+        if ( errno != EAGAIN && errno != EWOULDBLOCK) {
+          client_printf( STDFMT " Loop canceled, iteration %i/%i\n",lc,telnetparams.loopcount );
+          lc=telnetparams.loopcount;
+          break;
+        }
+
+        usleep(telnetparams.loopdelay * 1000);
+      }
+
+      fcntl (telnetparams.new_socket, F_SETFL, f);
+      rt= CMDSTATUS_FOUND;
+    } /* loop */
+  } /* for i */
+
+  free(bufbck);
+  return rt;
 }
 
-void run_telnetsrv(void) 
-{
-int sock;
-struct sockaddr_in name;
-char buf[TELNET_MAX_MSGLENGTH];
-struct sockaddr cli_addr;
-unsigned int cli_len = sizeof(cli_addr);
-int readc , filled;
-
-int status;
-int optval = 1;
-
-pthread_setname_np(pthread_self(), "telnet");
-set_sched(pthread_self(),0,telnetparams.priority);
-sock = socket(AF_INET, SOCK_STREAM, 0);
-if (sock < 0) 
+void run_telnetsrv(void) {
+  int sock;
+  struct sockaddr_in name;
+  char buf[TELNET_MAX_MSGLENGTH];
+  struct sockaddr cli_addr;
+  unsigned int cli_len = sizeof(cli_addr);
+  int readc , filled;
+  int status;
+  int optval = 1;
+  pthread_setname_np(pthread_self(), "telnet");
+  set_sched(pthread_self(),0,telnetparams.priority);
+  sock = socket(AF_INET, SOCK_STREAM, 0);
+
+  if (sock < 0)
     fprintf(stderr,"[TELNETSRV] Error %s on socket call\n",strerror(errno));
 
-setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval);
-name.sin_family = AF_INET;
-if (telnetparams.listenaddr == 0)
+  setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval);
+  name.sin_family = AF_INET;
+
+  if (telnetparams.listenaddr == 0)
     name.sin_addr.s_addr = INADDR_ANY;
-else
+  else
     name.sin_addr.s_addr = telnetparams.listenaddr;
-name.sin_port = htons((unsigned short)(telnetparams.listenport));
 
-if(bind(sock, (void*) &name, sizeof(name))) 
-     fprintf(stderr,"[TELNETSRV] Error %s on bind call\n",strerror(errno));
-if(listen(sock, 1) == -1)
-     fprintf(stderr,"[TELNETSRV] Error %s on listen call\n",strerror(errno));
+  name.sin_port = htons((unsigned short)(telnetparams.listenport));
+
+  if(bind(sock, (void *) &name, sizeof(name)))
+    fprintf(stderr,"[TELNETSRV] Error %s on bind call\n",strerror(errno));
 
+  if(listen(sock, 1) == -1)
+    fprintf(stderr,"[TELNETSRV] Error %s on listen call\n",strerror(errno));
 
-using_history();
+  using_history();
+  printf("\nInitializing telnet server...\n");
 
-printf("\nInitializing telnet server...\n");
-while( (telnetparams.new_socket = accept(sock, &cli_addr, &cli_len)) )
-     {
-     printf("[TELNETSRV] Telnet client connected....\n");
+  while( (telnetparams.new_socket = accept(sock, &cli_addr, &cli_len)) ) {
+    printf("[TELNETSRV] Telnet client connected....\n");
     read_history(telnetparams.histfile);
     stifle_history(telnetparams.histsize);
+
     if(telnetparams.new_socket < 0)
-       fprintf(stderr,"[TELNETSRV] Error %s on accept call\n",strerror(errno));
-
-    while(telnetparams.new_socket>0)
-         {
-	 filled = 0;
-	 memset(buf,0,sizeof(buf));
-         while(filled < ( TELNET_MAX_MSGLENGTH-1))
-	     {
-             readc = recv(telnetparams.new_socket, buf+filled, TELNET_MAX_MSGLENGTH-filled-1, 0);
-             if(!readc)
-	        break;
-             filled += readc;
-             if(buf[filled-1] == '\n')
-	        {
-		buf[filled-1] = 0;
-		
-	        break;
-		}
-             }
-         if(!readc)
-	   {
-           printf ("[TELNETSRV] Telnet Client disconnected.\n");
-           break;
-           }
-         if (telnetparams.telnetdbg > 0)
-	    printf("[TELNETSRV] Command received: readc %i filled %i \"%s\"\n", readc, filled ,buf);
-         if (buf[0] == '!') {
-             if (buf[1] == '!') {
-         	 sprintf(buf,"%s","telnet history list");
-             } else {
-         	 HIST_ENTRY *hisentry = history_get(strtol(buf+1,NULL,0)); 
-         	 if (hisentry) {
-                     char msg[TELNET_MAX_MSGLENGTH + sizeof(TELNET_PROMPT) +10];
-         	     sprintf(buf,"%s",hisentry->line);
-        	     sprintf(msg,"%s %s\n",TELNET_PROMPT, hisentry->line);
-                     send(telnetparams.new_socket, msg, strlen(msg), MSG_NOSIGNAL);
-         	 }
-             }  	 
-         }
-	 if (strlen(buf) > 2 )
-	    {
-            status=process_command(buf);
-	    }
-	 else
-	    status=CMDSTATUS_NOCMD;
-	    
-         if (status != CMDSTATUS_EXIT) {
-	    if (status == CMDSTATUS_NOTFOUND) {
-	       char msg[TELNET_MAX_MSGLENGTH + 50];
-	       sprintf(msg,"Error: \n      %s\n is not a softmodem command\n",buf);
-	       send(telnetparams.new_socket, msg, strlen(msg), MSG_NOSIGNAL);
-	    } else if (status == CMDSTATUS_FOUND) {
-               add_history(buf);
-            }
-            send(telnetparams.new_socket, TELNET_PROMPT, sizeof(TELNET_PROMPT), MSG_NOSIGNAL);
-	} else {
-	    printf ("[TELNETSRV] Closing telnet connection...\n");
-	    break;
-	}
+      fprintf(stderr,"[TELNETSRV] Error %s on accept call\n",strerror(errno));
+
+    while(telnetparams.new_socket>0) {
+      filled = 0;
+      memset(buf,0,sizeof(buf));
+
+      while(filled < ( TELNET_MAX_MSGLENGTH-1)) {
+        readc = recv(telnetparams.new_socket, buf+filled, TELNET_MAX_MSGLENGTH-filled-1, 0);
+
+        if(!readc)
+          break;
+
+        filled += readc;
+
+        if(buf[filled-1] == '\n') {
+          buf[filled-1] = 0;
+          break;
+        }
+      }
+
+      if(!readc) {
+        printf ("[TELNETSRV] Telnet Client disconnected.\n");
+        break;
+      }
+
+      if (telnetparams.telnetdbg > 0)
+        printf("[TELNETSRV] Command received: readc %i filled %i \"%s\"\n", readc, filled ,buf);
+
+      if (buf[0] == '!') {
+        if (buf[1] == '!') {
+          sprintf(buf,"%s","telnet history list");
+        } else {
+          HIST_ENTRY *hisentry = history_get(strtol(buf+1,NULL,0));
+
+          if (hisentry) {
+            char msg[TELNET_MAX_MSGLENGTH + sizeof(TELNET_PROMPT) +10];
+            sprintf(buf,"%s",hisentry->line);
+            sprintf(msg,"%s %s\n",TELNET_PROMPT, hisentry->line);
+            send(telnetparams.new_socket, msg, strlen(msg), MSG_NOSIGNAL);
+          }
+        }
+      }
+
+      if (strlen(buf) > 2 ) {
+        status=process_command(buf);
+      } else
+        status=CMDSTATUS_NOCMD;
+
+      if (status != CMDSTATUS_EXIT) {
+        if (status == CMDSTATUS_NOTFOUND) {
+          char msg[TELNET_MAX_MSGLENGTH + 50];
+          sprintf(msg,"Error: \n      %s\n is not a softmodem command\n",buf);
+          send(telnetparams.new_socket, msg, strlen(msg), MSG_NOSIGNAL);
+        } else if (status == CMDSTATUS_FOUND) {
+          add_history(buf);
+        }
+
+        send(telnetparams.new_socket, TELNET_PROMPT, sizeof(TELNET_PROMPT), MSG_NOSIGNAL);
+      } else {
+        printf ("[TELNETSRV] Closing telnet connection...\n");
+        break;
+      }
     }
+
     write_history(telnetparams.histfile);
     clear_history();
     close(telnetparams.new_socket);
     printf ("[TELNETSRV] Telnet server waitting for connection...\n");
-    }
-close(sock);
-return;
+  }
+
+  close(sock);
+  return;
 }
 
 /*------------------------------------------------------------------------------------------------*/
 /* set_telnetmodule loads the commands delivered with the telnet server
  *
  *
- * 
+ *
 */
-void exec_moduleinit(char *modname)
-{
-void (*fptr)(void);
-char initfunc[TELNET_CMD_MAXSIZE+9];
-
-       if (strlen(modname) > TELNET_CMD_MAXSIZE)
-	  {
-          fprintf(stderr,"[TELNETSRV] module %s not loaded, name exceeds the %i size limit\n",
-			 modname, TELNET_CMD_MAXSIZE);
-	  return; 
-          }
-       sprintf(initfunc,"add_%s_cmds",modname);
-       fptr = dlsym(RTLD_DEFAULT,initfunc);
-       if ( fptr != NULL)
-          {
-          fptr();
-          }
-       else
-          {
-          fprintf(stderr,"[TELNETSRV] couldn't find %s for module %s \n",initfunc,modname);
-          }
-}
+void exec_moduleinit(char *modname) {
+  void (*fptr)(void);
+  char initfunc[TELNET_CMD_MAXSIZE+9];
+
+  if (strlen(modname) > TELNET_CMD_MAXSIZE) {
+    fprintf(stderr,"[TELNETSRV] module %s not loaded, name exceeds the %i size limit\n",
+            modname, TELNET_CMD_MAXSIZE);
+    return;
+  }
 
-int add_embeddedmodules(void)
-{
-int ret=0;
+  sprintf(initfunc,"add_%s_cmds",modname);
+  fptr = dlsym(RTLD_DEFAULT,initfunc);
 
+  if ( fptr != NULL) {
+    fptr();
+  } else {
+    fprintf(stderr,"[TELNETSRV] couldn't find %s for module %s \n",initfunc,modname);
+  }
+}
 
+int add_embeddedmodules(void) {
+  int ret=0;
 
-    for(int i=0; i<telnetoptions[TELNETSRV_STATICMOD].numelt;i++)
-       {
-       ret++;
-       exec_moduleinit(telnetoptions[TELNETSRV_STATICMOD].strlistptr[i]);
-       }
-return ret;
+  for(int i=0; i<telnetoptions[TELNETSRV_STATICMOD].numelt; i++) {
+    ret++;
+    exec_moduleinit(telnetoptions[TELNETSRV_STATICMOD].strlistptr[i]);
+  }
 
+  return ret;
 }
 
-int add_sharedmodules(void)
-{
-char initfunc[TELNET_CMD_MAXSIZE+9];
-void (*fptr)(void);
-int ret=0;
-
-    for(int i=0; i<telnetoptions[TELNETSRV_SHRMOD].numelt;i++)
-       {
-       sprintf(initfunc,"add_%s_cmds",telnetoptions[TELNETSRV_SHRMOD].strlistptr[i]);
-       fptr = dlsym(RTLD_DEFAULT,initfunc);
-       if ( fptr != NULL)
-          {
-          fptr();
-          ret++;
-          }
-       else
-          {
-          fprintf(stderr,"[TELNETSRV] couldn't find %s for module %s \n",initfunc,telnetoptions[TELNETSRV_STATICMOD].strlistptr[i]);
-          }
-       }
-    return ret;
-}
+int add_sharedmodules(void) {
+  char initfunc[TELNET_CMD_MAXSIZE+9];
+  void (*fptr)(void);
+  int ret=0;
+
+  for(int i=0; i<telnetoptions[TELNETSRV_SHRMOD].numelt; i++) {
+    sprintf(initfunc,"add_%s_cmds",telnetoptions[TELNETSRV_SHRMOD].strlistptr[i]);
+    fptr = dlsym(RTLD_DEFAULT,initfunc);
 
-int telnetsrv_autoinit(void)
- {
+    if ( fptr != NULL) {
+      fptr();
+      ret++;
+    } else {
+      fprintf(stderr,"[TELNETSRV] couldn't find %s for module %s \n",initfunc,telnetoptions[TELNETSRV_STATICMOD].strlistptr[i]);
+    }
+  }
 
+  return ret;
+}
 
-   memset(&telnetparams,0,sizeof(telnetparams));
+int telnetsrv_autoinit(void) {
+  memset(&telnetparams,0,sizeof(telnetparams));
+  config_get( telnetoptions,sizeof(telnetoptions)/sizeof(paramdef_t),"telnetsrv");
 
-   config_get( telnetoptions,sizeof(telnetoptions)/sizeof(paramdef_t),"telnetsrv"); 
+  if(pthread_create(&telnetparams.telnet_pthread,NULL, (void *(*)(void *))run_telnetsrv, NULL) != 0) {
+    fprintf(stderr,"[TELNETSRV] Error %s on pthread_create call\n",strerror(errno));
+    return -1;
+  }
 
- 
-   if(pthread_create(&telnetparams.telnet_pthread,NULL, (void *(*)(void *))run_telnetsrv, NULL) != 0)
-     {
-     fprintf(stderr,"[TELNETSRV] Error %s on pthread_create call\n",strerror(errno));
-     return -1;
-     }
   add_telnetcmd("telnet", telnet_vardef, telnet_cmdarray);
   add_embeddedmodules();
   return 0;
- }
- 
+}
+
 /*---------------------------------------------------------------------------------------------*/
 /* add_telnetcmd is used to add a set of commands to the telnet server. A module calls this
  * function at init time. the telnet server is delivered with a set of commands which
  * will be loaded or not depending on the telnet section of the config file
 */
-int add_telnetcmd(char *modulename, telnetshell_vardef_t *var, telnetshell_cmddef_t *cmd)
- {
- int i;
- if( modulename == NULL || var == NULL || cmd == NULL)
-     {
-     fprintf(stderr,"[TELNETSRV] Telnet server, add_telnetcmd: invalid parameters\n");
-     return -1;
-     }
- for (i=0; i<TELNET_MAXCMD ; i++)
-     {
-     if (telnetparams.CmdParsers[i].var == NULL)
-        {
-        strncpy(telnetparams.CmdParsers[i].module,modulename,sizeof(telnetparams.CmdParsers[i].module)-1);
-        telnetparams.CmdParsers[i].cmd = cmd;
-        telnetparams.CmdParsers[i].var = var;
-        printf("[TELNETSRV] Telnet server: module %i = %s added to shell\n",
-               i,telnetparams.CmdParsers[i].module);
-        break;
-        }
-     }
+int add_telnetcmd(char *modulename, telnetshell_vardef_t *var, telnetshell_cmddef_t *cmd) {
+  int i;
+
+  if( modulename == NULL || var == NULL || cmd == NULL) {
+    fprintf(stderr,"[TELNETSRV] Telnet server, add_telnetcmd: invalid parameters\n");
+    return -1;
+  }
+
+  for (i=0; i<TELNET_MAXCMD ; i++) {
+    if (telnetparams.CmdParsers[i].var == NULL) {
+      strncpy(telnetparams.CmdParsers[i].module,modulename,sizeof(telnetparams.CmdParsers[i].module)-1);
+      telnetparams.CmdParsers[i].cmd = cmd;
+      telnetparams.CmdParsers[i].var = var;
+      printf("[TELNETSRV] Telnet server: module %i = %s added to shell\n",
+             i,telnetparams.CmdParsers[i].module);
+      break;
+    }
+  }
+
   return 0;
- }
+}
 
 
 /* function which will be called by the shared lib loader, to check shared lib version
    against main exec version. version mismatch no considered as fatal (interfaces not supposed to change)
-*/ 
-int  telnetsrv_checkbuildver(char * mainexec_buildversion, char ** shlib_buildversion)
-{
+*/
+int  telnetsrv_checkbuildver(char *mainexec_buildversion, char **shlib_buildversion) {
 #ifndef PACKAGE_VERSION
 #define PACKAGE_VERSION "standalone built: " __DATE__ __TIME__
 #endif
-    *shlib_buildversion = PACKAGE_VERSION;
-    if (strcmp(mainexec_buildversion, *shlib_buildversion) != 0) {
-          fprintf(stderr,"[TELNETSRV] shared lib version %s, doesn't match main version %s, compatibility should be checked\n",
-                mainexec_buildversion,*shlib_buildversion);
-    }
-    return 0;
+  *shlib_buildversion = PACKAGE_VERSION;
+
+  if (strcmp(mainexec_buildversion, *shlib_buildversion) != 0) {
+    fprintf(stderr,"[TELNETSRV] shared lib version %s, doesn't match main version %s, compatibility should be checked\n",
+            mainexec_buildversion,*shlib_buildversion);
+  }
+
+  return 0;
 }
 
-int telnetsrv_getfarray(loader_shlibfunc_t  **farray)
- {
+int telnetsrv_getfarray(loader_shlibfunc_t  **farray) {
   *farray=malloc(sizeof(loader_shlibfunc_t));
   (*farray)[0].fname=TELNET_ADDCMD_FNAME;
   (*farray)[0].fptr=(int (*)(void) )add_telnetcmd;
   return 1;
- }
+}
diff --git a/common/utils/telnetsrv/telnetsrv.h b/common/utils/telnetsrv/telnetsrv.h
index 2d3ef531aee8494ad080f00f42c9b42c1934eb50..89f6a8dda11bd3180790359ae666a9b638e2269f 100644
--- a/common/utils/telnetsrv/telnetsrv.h
+++ b/common/utils/telnetsrv/telnetsrv.h
@@ -69,7 +69,8 @@ typedef struct cmddef {
 #define TELNET_VARTYPE_INT64  3
 #define TELNET_VARTYPE_STRING 4
 #define TELNET_VARTYPE_DOUBLE 5
-//#define TELNET_VARTYPE_PTR    6
+#define TELNET_VARTYPE_INT8   6
+#define TELNET_VARTYPE_UINT   7
 typedef struct variabledef {
     char varname[TELNET_CMD_MAXSIZE];
     char vartype;
diff --git a/common/utils/telnetsrv/telnetsrv_CMakeLists.txt b/common/utils/telnetsrv/telnetsrv_CMakeLists.txt
index 5dee7db4c41fef1d5c3f96b18eb770d64e044054..3a07632bfecf36a7306be40fcdd040397962a530 100644
--- a/common/utils/telnetsrv/telnetsrv_CMakeLists.txt
+++ b/common/utils/telnetsrv/telnetsrv_CMakeLists.txt
@@ -9,6 +9,7 @@ set(TELNETSRV_SOURCE
     ${TELNETROOT}/telnetsrv_phycmd.c
     ${TELNETROOT}/telnetsrv_proccmd.c
     ${TELNETROOT}/telnetsrv_loader.c
+    ${TELNETROOT}/telnetsrv_measurements.c
     )
 
 #set(TELNETSRV_ETHDEVCMD_SOURCE
diff --git a/common/utils/telnetsrv/telnetsrv_cpumeasur_def.h b/common/utils/telnetsrv/telnetsrv_cpumeasur_def.h
new file mode 100644
index 0000000000000000000000000000000000000000..89ced509a4504a8c9b742bdbb3e1e9344936ab61
--- /dev/null
+++ b/common/utils/telnetsrv/telnetsrv_cpumeasur_def.h
@@ -0,0 +1,99 @@
+/*
+ * 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
+ */
+
+/*! \file common/utils/telnetsrv/telnetsrv_cpumeasur_def.h
+ * \brief: definitions of macro used to initialize the telnet_ltemeasurdef_t
+ * \        strucures arrays which are then used by the display functions
+ * \        in telnetsrv_measurements.c.
+ * \author Francois TABURET
+ * \date 2019
+ * \version 0.1
+ * \company NOKIA BellLabs France
+ * \email: francois.taburet@nokia-bell-labs.com
+ * \note
+ * \warning
+ */
+
+
+#define CPU_PHYENB_MEASURE \
+{ \
+  {"phy_proc_tx",            	  	 &(phyvars->phy_proc_tx),0},\
+  {"phy_proc_rx",            	  	 &(phyvars->phy_proc_rx),0},\
+  {"rx_prach",               	  	 &(phyvars->rx_prach),0},\
+  {"ofdm_mod",         	  	         &(phyvars->ofdm_mod_stats),0},\
+  {"dlsch_common_and_dci",   	  	 &(phyvars->dlsch_common_and_dci),0},\
+  {"dlsch_ue_specific",      	  	 &(phyvars->dlsch_ue_specific),0},\
+  {"dlsch_encoding",   	  	         &(phyvars->dlsch_encoding_stats),0},\
+  {"dlsch_modulation", 	  	         &(phyvars->dlsch_modulation_stats),0},\
+  {"dlsch_scrambling",                   &(phyvars->dlsch_scrambling_stats),0},\
+  {"dlsch_rate_matching",                &(phyvars->dlsch_rate_matching_stats),0},\
+  {"dlsch_turbo_encod_prep",             &(phyvars->dlsch_turbo_encoding_preperation_stats),0},\
+  {"dlsch_turbo_encod_segm",             &(phyvars->dlsch_turbo_encoding_segmentation_stats),0},\
+  {"dlsch_turbo_encod", 	         &(phyvars->dlsch_turbo_encoding_stats),0},\
+  {"dlsch_turbo_encod_waiting",          &(phyvars->dlsch_turbo_encoding_waiting_stats),0},\
+  {"dlsch_turbo_encod_signal",           &(phyvars->dlsch_turbo_encoding_signal_stats),0},\
+  {"dlsch_turbo_encod_main",	         &(phyvars->dlsch_turbo_encoding_main_stats),0},\
+  {"dlsch_turbo_encod_wakeup0",          &(phyvars->dlsch_turbo_encoding_wakeup_stats0),0},\
+  {"dlsch_turbo_encod_wakeup1",          &(phyvars->dlsch_turbo_encoding_wakeup_stats1),0},\
+  {"dlsch_interleaving",                 &(phyvars->dlsch_interleaving_stats),0},\
+  {"rx_dft",                             &(phyvars->rx_dft_stats),0},\
+  {"ulsch_channel_estimation",           &(phyvars->ulsch_channel_estimation_stats),0},\
+  {"ulsch_freq_offset_estimation",       &(phyvars->ulsch_freq_offset_estimation_stats),0},\
+  {"ulsch_decoding",                     &(phyvars->ulsch_decoding_stats),0},\
+  {"ulsch_demodulation",                 &(phyvars->ulsch_demodulation_stats),0},\
+  {"ulsch_rate_unmatching",              &(phyvars->ulsch_rate_unmatching_stats),0},\
+  {"ulsch_turbo_decoding",               &(phyvars->ulsch_turbo_decoding_stats),0},\
+  {"ulsch_deinterleaving",               &(phyvars->ulsch_deinterleaving_stats),0},\
+  {"ulsch_demultiplexing",               &(phyvars->ulsch_demultiplexing_stats),0},\
+  {"ulsch_llr",                          &(phyvars->ulsch_llr_stats),0},\
+  {"ulsch_tc_init",                      &(phyvars->ulsch_tc_init_stats),0},\
+  {"ulsch_tc_alpha",                     &(phyvars->ulsch_tc_alpha_stats),0},\
+  {"ulsch_tc_beta",                      &(phyvars->ulsch_tc_beta_stats),0},\
+  {"ulsch_tc_gamma",                     &(phyvars->ulsch_tc_gamma_stats),0},\
+  {"ulsch_tc_ext",                       &(phyvars->ulsch_tc_ext_stats),0},\
+  {"ulsch_tc_intl1",                     &(phyvars->ulsch_tc_intl1_stats),0},\
+  {"ulsch_tc_intl2",                     &(phyvars->ulsch_tc_intl2_stats),0},\
+}
+
+#define CPU_MACENB_MEASURE \
+{ \
+  {"eNB_scheduler",	    &(macvars->eNB_scheduler),0},\
+  {"schedule_si",	    &(macvars->schedule_si),0},\
+  {"schedule_ra",	    &(macvars->schedule_ra),0},\
+  {"schedule_ulsch",	    &(macvars->schedule_ulsch),0},\
+  {"fill_DLSCH_dci",	    &(macvars->fill_DLSCH_dci),0},\
+  {"schedule_dlsch_pre",    &(macvars->schedule_dlsch_preprocessor),0},\
+  {"schedule_dlsch",	    &(macvars->schedule_dlsch),0},\
+  {"schedule_mch",	    &(macvars->schedule_mch),0},\
+  {"rx_ulsch_sdu",	    &(macvars->rx_ulsch_sdu),0},\
+  {"schedule_pch",	    &(macvars->schedule_pch),0},\
+}
+
+#define CPU_PDCPENB_MEASURE \
+{ \
+  {"pdcp_run",               &(pdcpvars->pdcp_run),0},\
+  {"data_req",               &(pdcpvars->data_req),0},\
+  {"data_ind",               &(pdcpvars->data_ind),0},\
+  {"apply_security",         &(pdcpvars->apply_security),0},\
+  {"validate_security",      &(pdcpvars->validate_security),0},\
+  {"pdcp_ip",                &(pdcpvars->pdcp_ip),0},\
+  {"ip_pdcp",                &(pdcpvars->ip_pdcp),0},\
+}
diff --git a/common/utils/telnetsrv/telnetsrv_measurements.c b/common/utils/telnetsrv/telnetsrv_measurements.c
new file mode 100644
index 0000000000000000000000000000000000000000..7cfc6562254b0522f19cf1ba78d27a8fa956d557
--- /dev/null
+++ b/common/utils/telnetsrv/telnetsrv_measurements.c
@@ -0,0 +1,316 @@
+/*
+ * 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
+ */
+
+/*! \file common/utils/telnetsrv/telnetsrv_measurements.c
+ * \brief: implementation of telnet commands related to measurments
+ * \author Francois TABURET
+ * \date 2019
+ * \version 0.1
+ * \company NOKIA BellLabs France
+ * \email: francois.taburet@nokia-bell-labs.com
+ * \note
+ * \warning
+ */
+#define _GNU_SOURCE
+#include <sys/types.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+
+
+
+
+#define TELNETSERVERCODE
+#include "telnetsrv.h"
+#define TELNETSRV_MEASURMENTS_MAIN
+#include "common/utils/LOG/log.h"
+#include "common/config/config_userapi.h"
+#include "telnetsrv_measurements.h"
+#include "telnetsrv_ltemeasur_def.h"
+#include "telnetsrv_cpumeasur_def.h"
+#include "openair2/LAYER2/MAC/mac.h"
+#include "openair1/PHY/phy_extern.h"
+
+void measurcmd_display_macstats(telnet_printfunc_t prnt);
+void measurcmd_display_macstats_ue(telnet_printfunc_t prnt);
+void measurcmd_display_rlcstats(telnet_printfunc_t prnt);
+void measurcmd_display_phycpu(telnet_printfunc_t prnt);
+void measurcmd_display_maccpu(telnet_printfunc_t prnt);
+void measurcmd_display_pdcpcpu(telnet_printfunc_t prnt);
+
+
+static telnet_measurgroupdef_t measurgroups[] = {
+  {"enb",   GROUP_LTESTATS,0, measurcmd_display_macstats,   {NULL}},
+  {"enbues",GROUP_LTESTATS,0, measurcmd_display_macstats_ue,{NULL}},
+  {"rlc",   GROUP_LTESTATS,0, measurcmd_display_rlcstats,   {NULL}},
+  {"phycpu",GROUP_CPUSTATS,0, measurcmd_display_phycpu,     {NULL}},
+  {"maccpu",GROUP_CPUSTATS,0, measurcmd_display_maccpu,      {NULL}},
+  {"pdcpcpu",GROUP_CPUSTATS,0, measurcmd_display_pdcpcpu,      {NULL}},
+};
+#define TELNET_NUM_MEASURGROUPS (sizeof(measurgroups)/sizeof(telnet_measurgroupdef_t))
+
+static int                     eNB_id =0;
+static char                    *grouptypes[] = {"ltestats","cpustats"};
+static double                  cpufreq;
+#define TELNET_NUM_MEASURTYPES (sizeof(grouptypes)/sizeof(char *))
+
+#define HDR "---------------------------------"
+
+void measurcmd_display_groups(telnet_printfunc_t prnt) {
+  prnt("  %*s %10s %s\n",TELNET_MAXMEASURNAME_LEN-1,"name","type","nombre de mesures");
+
+  for(int i=0; i<TELNET_NUM_MEASURGROUPS; i++)
+    prnt("%02d %*s %10s %i\n",i,TELNET_MAXMEASURNAME_LEN-1,measurgroups[i].groupname,
+         grouptypes[measurgroups[i].type], measurgroups[i].size);
+} /* measurcmd_display_groups */
+/*----------------------------------------------------------------------------------------------------*/
+/* cpu measurements functions                         */
+void measurcmd_display_cpumeasures(telnet_printfunc_t prnt, telnet_cpumeasurdef_t  *cpumeasure, int cpumeasure_size) {
+  for (int i=0; i<cpumeasure_size; i++) {
+    prnt("%02d %*s:  %15.3f us; %15d %s",i,TELNET_MAXMEASURNAME_LEN-1,(cpumeasure+i)->statname,
+         ((cpumeasure+i)->astatptr->trials!=0)?(((cpumeasure+i)->astatptr->diff)/((cpumeasure+i)->astatptr->trials))/cpufreq/1000:0,
+         (cpumeasure+i)->astatptr->trials, ((i%2)==1)?"|\n":"  | " );
+  }
+
+  prnt("\n\n");
+} /* measurcmd_display_measures */
+
+#define PRINT_CPUMEAS_STATE  ((cpumeas(CPUMEAS_GETSTATE))?"enabled":"disabled")
+void measurcmd_display_phycpu(telnet_printfunc_t prnt) {
+  PHY_VARS_eNB *phyvars = RC.eNB[eNB_id][0];
+  telnet_cpumeasurdef_t  cpumeasur[]=CPU_PHYENB_MEASURE;
+  prnt("%s cpu (%1.1g GHz) measurements: PHY (cpustats %s) %s\n",HDR,cpufreq,
+       PRINT_CPUMEAS_STATE,HDR);
+  measurcmd_display_cpumeasures(prnt, cpumeasur, sizeof(cpumeasur)/sizeof(telnet_cpumeasurdef_t));
+}
+
+void measurcmd_display_maccpu(telnet_printfunc_t prnt) {
+  eNB_MAC_INST *macvars = RC.mac[eNB_id];
+  telnet_cpumeasurdef_t  cpumeasur[]=CPU_MACENB_MEASURE;
+  prnt("%s cpu (%1.1g GHz) measurements: MAC (cpustats %s) %s\n",HDR,cpufreq,
+       PRINT_CPUMEAS_STATE,HDR);
+  measurcmd_display_cpumeasures(prnt, cpumeasur, sizeof(cpumeasur)/sizeof(telnet_cpumeasurdef_t));
+}
+
+void measurcmd_display_pdcpcpu(telnet_printfunc_t prnt) {
+  pdcp_stats_t *pdcpvars = &(eNB_pdcp_stats[eNB_id]);
+  telnet_cpumeasurdef_t  cpumeasur[]=CPU_PDCPENB_MEASURE;
+  prnt("%s cpu (%1.1g GHz) measurements: PDCP (cpustats %s) %s \n",HDR,cpufreq,
+       PRINT_CPUMEAS_STATE,HDR);
+  measurcmd_display_cpumeasures(prnt, cpumeasur, sizeof(cpumeasur)/sizeof(telnet_cpumeasurdef_t));
+}
+/*----------------------------------------------------------------------------------------------------*/
+/* lte measurements functions                         */
+uint64_t measurcmd_getstatvalue(telnet_ltemeasurdef_t *measur,telnet_printfunc_t prnt) {
+  uint64_t val;
+
+  switch(measur->vtyp) {
+    case TELNET_VARTYPE_INT64:
+      val = (uint64_t)(*((uint64_t *)(measur->vptr)));
+      break;
+
+    case TELNET_VARTYPE_INT32:
+      val = (uint64_t)(*((uint32_t *)(measur->vptr)));
+      break;
+
+    case TELNET_VARTYPE_INT16:
+      val = (uint64_t)(*((uint16_t *)(measur->vptr)));
+      break;
+
+    case TELNET_VARTYPE_INT8:
+      val = (uint64_t)(*((uint8_t *)(measur->vptr)));
+      break;
+
+    case TELNET_VARTYPE_UINT:
+      val = (uint64_t)(*((unsigned int *)(measur->vptr)));
+      break;
+
+    default:
+      prnt("%s %i: unknown type \n",measur->statname,measur->vtyp);
+      val = (uint64_t)(*((uint64_t *)(measur->vptr)));
+      break;
+  }
+
+  return val;
+} /* measurcmd_getstatvalue */
+
+void measurcmd_display_measures(telnet_printfunc_t prnt, telnet_ltemeasurdef_t  *statsptr, int stats_size) {
+  for (int i=0; i<stats_size; i++) {
+    prnt("%*s = %15llu%s",TELNET_MAXMEASURNAME_LEN-1,statsptr[i].statname,
+         measurcmd_getstatvalue(&(statsptr[i]),prnt), ((i%3)==2)?"\n":"   ");
+  }
+
+  prnt("\n\n");
+} /* measurcmd_display_measures */
+
+void measurcmd_display_macstats_ue(telnet_printfunc_t prnt) {
+  UE_list_t *UE_list = &(RC.mac[eNB_id]->UE_list);
+
+  for (int UE_id=UE_list->head; UE_id>=0; UE_id=UE_list->next[UE_id]) {
+    for (int i=0; i<UE_list->numactiveCCs[UE_id]; i++) {
+      int CC_id = UE_list->ordered_CCids[i][UE_id];
+      prnt("%s UE %i Id %i CCid %i %s\n",HDR,i,UE_id,CC_id,HDR);
+      eNB_UE_STATS *macuestatptr = &(UE_list->eNB_UE_stats[CC_id][UE_id]);
+      telnet_ltemeasurdef_t  statsptr[]=LTEMAC_UEMEASURE;
+      measurcmd_display_measures(prnt, statsptr, sizeof(statsptr)/sizeof(telnet_ltemeasurdef_t));
+    }
+  }
+} /* measurcmd_display_macstats_ue */
+
+void measurcmd_display_macstats(telnet_printfunc_t prnt) {
+  for (int CC_id=0 ; CC_id < MAX_NUM_CCs; CC_id++) {
+    eNB_STATS *macstatptr=&(RC.mac[eNB_id]->eNB_stats[CC_id]);
+    telnet_ltemeasurdef_t  statsptr[]=LTEMAC_MEASURE;
+    prnt("%s eNB %i mac stats CC %i frame %u %s\n",
+         HDR, eNB_id, CC_id, RC.mac[eNB_id]->frame,HDR);
+    measurcmd_display_measures(prnt,statsptr,sizeof(statsptr)/sizeof(telnet_ltemeasurdef_t));
+  }
+} /* measurcmd_display_macstats */
+
+
+void measurcmd_display_one_rlcstat(telnet_printfunc_t prnt, int UE_id, telnet_ltemeasurdef_t *statsptr, int num_rlcmeasure, unsigned int *rlcstats,
+                                   char *rbid_str, protocol_ctxt_t *ctxt, const srb_flag_t srb_flagP, const rb_id_t rb_idP)
+
+{
+  int rlc_status = rlc_stat_req(ctxt,srb_flagP,rb_idP,
+                                rlcstats,   rlcstats+1, rlcstats+2, rlcstats+3, rlcstats+4, rlcstats+5,
+                                rlcstats+6, rlcstats+7, rlcstats+8, rlcstats+9, rlcstats+10, rlcstats+11,
+                                rlcstats+12, rlcstats+13, rlcstats+14, rlcstats+15, rlcstats+16, rlcstats+17,
+                                rlcstats+18, rlcstats+19, rlcstats+20, rlcstats+21, rlcstats+22, rlcstats+23,
+                                rlcstats+24, rlcstats+25, rlcstats+26, rlcstats+27);
+
+  if (rlc_status == RLC_OP_STATUS_OK) {
+    prnt("%s UE %i RLC %s mode %s %s\n",HDR,UE_id, rbid_str,
+         (rlcstats[0]==RLC_MODE_AM)? "AM": (rlcstats[0]==RLC_MODE_UM)?"UM":"NONE",HDR);
+    measurcmd_display_measures(prnt, statsptr, num_rlcmeasure);
+  }
+} /* status measurcmd_rlc_stat_req */
+
+
+void measurcmd_display_rlcstats(telnet_printfunc_t prnt) {
+  protocol_ctxt_t      ctxt;
+  UE_list_t *UE_list = &(RC.mac[eNB_id]->UE_list);
+  telnet_ltemeasurdef_t  statsptr[]=LTE_RLCMEASURE;
+  int num_rlcmeasure = sizeof(statsptr)/sizeof(telnet_ltemeasurdef_t );
+  unsigned int *rlcstats = malloc(num_rlcmeasure*sizeof(unsigned int));
+  eNB_MAC_INST *eNB = RC.mac[eNB_id];
+
+  for(int i=0; i <num_rlcmeasure ; i++) {
+    statsptr[i].vptr = rlcstats + i;
+  }
+
+  for (int UE_id=UE_list->head; UE_id>=0; UE_id=UE_list->next[UE_id]) {
+#define NB_eNB_INST 1
+    PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt,eNB_id, ENB_FLAG_YES,UE_list->eNB_UE_stats[0][UE_id].crnti,
+                                   eNB->frame,eNB->subframe,eNB_id);
+    measurcmd_display_one_rlcstat(prnt, UE_id, statsptr, num_rlcmeasure, rlcstats, "DCCH", &ctxt, SRB_FLAG_YES, DCCH);
+    measurcmd_display_one_rlcstat(prnt, UE_id, statsptr, num_rlcmeasure, rlcstats, "DTCH", &ctxt, SRB_FLAG_NO,  DTCH-2);
+  }
+} /* measurcmd_display_macstats_ue */
+
+/*------------------------------------------------------------------------------------------------------------------------*/
+/* function called by the telnet server when measur command is entered */
+int measurcmd_show(char *buf, int debug, telnet_printfunc_t prnt) {
+  char *subcmd=NULL;
+  int idx1, idx2;
+  int badcmd=1;
+
+  if (debug > 0)
+    prnt(" measurcmd_show received %s\n",buf);
+
+  //   char tmp[20480];
+  //   dump_eNB_l2_stats(tmp, 0);
+  //   prnt("%s\n",tmp);
+  int s = sscanf(buf,"%ms %i-%i\n",&subcmd, &idx1,&idx2);
+
+  if (s>0) {
+    if ( strcmp(subcmd,"groups") == 0) {
+      measurcmd_display_groups(prnt);
+      badcmd=0;
+    } else {
+      for (int i=0; i<TELNET_NUM_MEASURTYPES; i++) {
+        if(strcmp(subcmd,grouptypes[i]) == 0) {
+          for(int j=0; j<TELNET_NUM_MEASURGROUPS; j++) {
+            if(i == measurgroups[j].type) {
+              badcmd=0;
+              measurgroups[j].displayfunc(prnt);
+            }
+          } /* for j...*/
+        }
+      }/* for i...*/
+
+      for (int i=0; i<TELNET_NUM_MEASURGROUPS; i++) {
+        if(strcmp(subcmd,measurgroups[i].groupname) == 0) {
+          measurgroups[i].displayfunc(prnt);
+          badcmd=0;
+          break;
+        }
+      }
+    }
+
+    free(subcmd);
+  } /* s>0 */
+
+  if (badcmd) {
+    prnt("%s: unknown measur command\n",buf);
+  }
+
+  return CMDSTATUS_FOUND;
+}
+
+
+int measurcmd_cpustats(char *buf, int debug, telnet_printfunc_t prnt) {
+  char *subcmd=NULL;
+  int idx1, idx2;
+  int badcmd=1;
+
+  if (debug > 0)
+    prnt(" measurcmd_show received %s\n",buf);
+
+  int s = sscanf(buf,"%ms %i-%i\n",&subcmd, &idx1,&idx2);
+
+  if (s>0) {
+    if ( strcmp(subcmd,"enable") == 0) {
+      cpumeas(CPUMEAS_ENABLE);
+      badcmd=0;
+    } else if ( strcmp(subcmd,"disable") == 0) {
+      cpumeas(CPUMEAS_DISABLE);
+      badcmd=0;
+    }
+  }
+
+  if (badcmd) {
+    prnt("Cpu measurments state: %s\n",PRINT_CPUMEAS_STATE);
+  }
+
+  free(subcmd);
+  return CMDSTATUS_FOUND;
+}
+/*-------------------------------------------------------------------------------------*/
+
+/* function called at telnet server init to add the measur command */
+void add_measur_cmds(void) {
+  add_telnetcmd("measur",measur_vardef,measur_cmdarray);
+  cpufreq = get_cpu_freq_GHz();
+}
diff --git a/common/utils/telnetsrv/telnetsrv_measurements.h b/common/utils/telnetsrv/telnetsrv_measurements.h
new file mode 100644
index 0000000000000000000000000000000000000000..46f25da4c52ddc3e17ce071501c0a98481b01eb7
--- /dev/null
+++ b/common/utils/telnetsrv/telnetsrv_measurements.h
@@ -0,0 +1,88 @@
+/*
+ * 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
+ */
+
+
+/*! \file common/utils/telnetsrv/telnetsrv_measurements.h
+ * \brief: Include file defining constants, structures and function prototypes
+ * \       used to implement the measurements functionality of the telnet server
+ * \author Francois TABURET
+ * \date 2019
+ * \version 0.1
+ * \company NOKIA BellLabs France
+ * \email: francois.taburet@nokia-bell-labs.com
+ * \note
+ * \warning
+ */
+#include <dlfcn.h>
+#include "telnetsrv.h"
+#include "openair1/PHY/defs_eNB.h"
+#ifdef TELNETSRV_MEASURMENTS_MAIN
+
+
+#define TELNET_MAXMEASURNAME_LEN 30
+#define TELNET_MAXMEASURGROUPS 10
+
+telnetshell_vardef_t measur_vardef[] = {
+  {"",0,NULL}
+};
+
+typedef struct cpumeasurdef {
+  char statname[TELNET_MAXMEASURNAME_LEN];
+  time_stats_t *astatptr;
+  unsigned int statemask;
+} telnet_cpumeasurdef_t;
+
+typedef struct ltemeasurdef {
+  char statname[TELNET_MAXMEASURNAME_LEN];
+  void     *vptr;
+  char     vtyp;
+  unsigned int statemask;
+} telnet_ltemeasurdef_t;
+
+#define GROUP_LTESTATS    0
+#define GROUP_CPUSTATS    1
+typedef void(*measur_dislayfunc_t)(telnet_printfunc_t prnt);
+typedef struct mesurgroupdef {
+  char groupname[TELNET_MAXMEASURNAME_LEN];
+  unsigned char type;
+  unsigned char size;
+  measur_dislayfunc_t displayfunc;
+  union {
+    telnet_cpumeasurdef_t *cpustats;
+    telnet_ltemeasurdef_t *ltestats;
+  };
+} telnet_measurgroupdef_t;
+
+#define MACSTATS_NAME(valptr) #valptr
+#define LTEMAC_MEASURGROUP_NAME  "ltemac"
+#define PHYCPU_MEASURGROUP_NAME  "phycpu"
+
+int measurcmd_show(char *buf, int debug, telnet_printfunc_t prnt);
+int measurcmd_cpustats(char *buf, int debug, telnet_printfunc_t prnt);
+telnetshell_cmddef_t measur_cmdarray[] = {
+  {"show", "groups | <group name>" , measurcmd_show},
+  {"cpustats","[enable | disable]",measurcmd_cpustats},
+  {"","",NULL}
+};
+
+#else
+extern void add_measur_cmds(void);
+#endif  /* TELNETSRV_MEASURCMD_MAIN */
diff --git a/common/utils/telnetsrv/telnetsrv_phycmd.c b/common/utils/telnetsrv/telnetsrv_phycmd.c
index c60126f1c741e4d9d93323e761862d0f7458e561..35554a77a6109cd062959f4d695eace094cb2be8 100644
--- a/common/utils/telnetsrv/telnetsrv_phycmd.c
+++ b/common/utils/telnetsrv/telnetsrv_phycmd.c
@@ -29,7 +29,7 @@
  * \note
  * \warning
  */
-#define _GNU_SOURCE 
+#define _GNU_SOURCE
 #include <string.h>
 #include <pthread.h>
 
@@ -39,104 +39,88 @@
 #define TELNETSRV_PHYCMD_MAIN
 #include "telnetsrv_phycmd.h"
 char *prnbuff;
-extern int dump_eNB_stats(PHY_VARS_eNB *eNB, char* buffer, int length);
-
-void init_phytelnet(void)
-{
-prnbuff=malloc(get_phybsize() );
-if (prnbuff == NULL)
-   {
-   fprintf(stderr,"Error %s on malloc in init_phytelnet()\n",strerror(errno));
-   }
-}
+extern int dump_eNB_l2_stats(char *buffer, int length);
+
+void init_phytelnet(void) {
+  prnbuff=malloc(get_phybsize() );
 
-void display_uestatshead( telnet_printfunc_t prnt)
-{
-prnt("cc  ue  rnti Dmcs Umcs tao  tau   Dbr  Dtb   \n");
+  if (prnbuff == NULL) {
+    fprintf(stderr,"Error %s on malloc in init_phytelnet()\n",strerror(errno));
+  }
 }
 
-void dump_uestats(int debug, telnet_printfunc_t prnt, uint8_t prntflag)
-{
+void display_uestatshead( telnet_printfunc_t prnt) {
+  prnt("cc  ue  rnti Dmcs Umcs tao  tau   Dbr  Dtb   \n");
+}
 
-int p;
+void dump_uestats(int debug, telnet_printfunc_t prnt, uint8_t prntflag) {
+  int p;
+  prnbuff=malloc(20480);
+  p=dump_eNB_l2_stats( prnbuff, 20480);
 
-        p=dump_eNB_l2_stats( prnbuff, 0);
-	if(prntflag>=1)
-	   prnt("%s\n",prnbuff);
-	if(debug>=1)
-	   prnt("%i bytes printed\n",p);	   
+  if(prntflag>=1)
+    prnt("%s\n",prnbuff);
 
+  if(debug>=1)
+    prnt("%i bytes printed\n",p);
 
+  free(prnbuff);
 }
 
-void display_uestats(int debug, telnet_printfunc_t prnt, int ue)
-{
-   for (int cc=0; cc<1 ; cc++)
-       {
- 
- 
-       }
+void display_uestats(int debug, telnet_printfunc_t prnt, int ue) {
+  for (int cc=0; cc<1 ; cc++) {
+  }
 }
 
-void display_phycounters(char *buf, int debug, telnet_printfunc_t prnt)
-{    
-   prnt("  DLSCH kb      DLSCH kb/s\n");
-
-   dump_uestats(debug, prnt,0);
-
+void display_phycounters(char *buf, int debug, telnet_printfunc_t prnt) {
+  prnt("  DLSCH kb      DLSCH kb/s\n");
+  dump_uestats(debug, prnt,0);
 }
 
-int dump_phyvars(char *buf, int debug, telnet_printfunc_t prnt)
-{
-   
-   
-
-   if (debug > 0)
-       prnt("phy interface module received %s\n",buf);
-   if (strcasestr(buf,"phycnt") != NULL)
-       {
-       display_phycounters(buf, debug, prnt);
-       }
-   if (strcasestr(buf,"uestat") != NULL)
-      {
-      char *cptr=strcasestr(buf+sizeof("uestat"),"UE");
-      display_uestatshead(prnt);
-      if (cptr != NULL)
-         {
-	 int ueidx = strtol( cptr+sizeof("UE"), NULL, 10);
-	 if (ueidx < NUMBER_OF_UE_MAX && ueidx >= 0)
-	    {
-	    display_uestats(debug, prnt,ueidx);
-	    }
-	 } /* if cptr != NULL */
-      else
-         {
-	 for (int ue=0; ue<NUMBER_OF_UE_MAX ; ue++)
-	     {
-	     display_uestats(debug, prnt,ue);
-	     }
-	 } /* else cptr != NULL */
-      } /* uestat */
-   if (strcasestr(buf,"uedump") != NULL)
-       {
-       dump_uestats(debug, prnt,1);
-       }           
-   return 0;
+int dump_phyvars(char *buf, int debug, telnet_printfunc_t prnt) {
+  if (debug > 0)
+    prnt("phy interface module received %s\n",buf);
+
+  if (strcasestr(buf,"phycnt") != NULL) {
+    display_phycounters(buf, debug, prnt);
+  }
+
+  if (strcasestr(buf,"uestat") != NULL) {
+    char *cptr=strcasestr(buf+sizeof("uestat"),"UE");
+    display_uestatshead(prnt);
+
+    if (cptr != NULL) {
+      int ueidx = strtol( cptr+sizeof("UE"), NULL, 10);
+
+      if (ueidx < NUMBER_OF_UE_MAX && ueidx >= 0) {
+        display_uestats(debug, prnt,ueidx);
+      }
+    } /* if cptr != NULL */
+    else {
+      for (int ue=0; ue<NUMBER_OF_UE_MAX ; ue++) {
+        display_uestats(debug, prnt,ue);
+      }
+    } /* else cptr != NULL */
+  } /* uestat */
+
+  if (strcasestr(buf,"uedump") != NULL) {
+    dump_uestats(debug, prnt,1);
+  }
+
+  return 0;
 }
 
 
 
 telnetshell_cmddef_t phy_cmdarray[] = {
-   {"disp","[phycnt,uedump,uestat UE<x>]", dump_phyvars},
+  {"disp","[phycnt,uedump,uestat UE<x>]", dump_phyvars},
 
-   {"","",NULL},
+  {"","",NULL},
 };
 
 
 /*-------------------------------------------------------------------------------------*/
-void add_phy_cmds(void)
-{
-
-   init_phytelnet();
-   add_telnetcmd("phy", phy_vardef, phy_cmdarray);
+void add_phy_cmds(void) {
+  init_phytelnet();
+  add_telnetcmd("phy", phy_vardef, phy_cmdarray);
 }
diff --git a/common/utils/time_utils.h b/common/utils/time_utils.h
deleted file mode 100644
index ee82c8cf95366cddec208bbc213d2dfcfbcf2ec6..0000000000000000000000000000000000000000
--- a/common/utils/time_utils.h
+++ /dev/null
@@ -1,23 +0,0 @@
-#ifndef _TIME_UTILS_H_
-#define _TIME_UTILS_H_
-
-#include <time.h>
-#include <stdint.h>
-
-static inline int64_t clock_difftime_ns(struct timespec start, struct timespec end)
-{
-  struct timespec temp;
-  int64_t temp_ns;
-
-  if ((end.tv_nsec-start.tv_nsec)<0) {
-    temp.tv_sec = end.tv_sec-start.tv_sec-1;
-    temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec;
-  } else {
-    temp.tv_sec = end.tv_sec-start.tv_sec;
-    temp.tv_nsec = end.tv_nsec-start.tv_nsec;
-  }
-  temp_ns = (int64_t)(temp.tv_sec) * (int64_t)1000000000 + (temp.tv_nsec);
-  return temp_ns;
-}
-
-#endif /* _TIME_UTILS_H_ */
diff --git a/configuration/bladeRF/enb-band7-5mhz.conf b/configuration/bladeRF/enb-band7-5mhz.conf
new file mode 100644
index 0000000000000000000000000000000000000000..8d110a699e07f93a875ea324950129aa5bdba763
--- /dev/null
+++ b/configuration/bladeRF/enb-band7-5mhz.conf
@@ -0,0 +1,274 @@
+Active_eNBs = ( "eNB-Eurecom-LTEBox");
+# Asn1_verbosity, choice in: none, info, annoying
+Asn1_verbosity = "none";
+
+eNBs =
+(
+ {
+    # real_time choice in {hard, rt-preempt, no}
+    real_time       =  "no";
+    ////////// Identification parameters:
+    eNB_ID    =  0xe00;
+
+    cell_type =  "CELL_MACRO_ENB";
+
+    eNB_name  =  "eNB-Eurecom-LTEBox";
+
+    // Tracking area code, 0x0000 and 0xfffe are reserved values
+    tracking_area_code  =  1;
+    plmn_list = (
+      { mcc = 208; mnc = 92; mnc_length = 2; }
+    );
+
+    tr_s_preference     = "local_mac"
+
+       ////////// Physical parameters:
+
+    component_carriers = (
+                 {
+                           node_function = "eNodeB_3GPP";
+                           node_timing = "synch_to_ext_device";
+                           node_synch_ref = 0;
+                           nb_antenna_ports = 1;
+                           ue_TransmissionMode = 1;
+           frame_type					      = "FDD";
+                           tdd_config 					      = 3;
+                           tdd_config_s            			      = 0;
+         prefix_type             			      = "NORMAL";
+         eutra_band              			      = 7;
+                           downlink_frequency      			      = 2680000000L;
+                           uplink_frequency_offset 			      = -120000000;
+
+           Nid_cell					      = 0;
+                           N_RB_DL                 			      = 25;
+                           Nid_cell_mbsfn          			      = 0;
+                           nb_antennas_tx          			      = 1;
+                           nb_antennas_rx          			      = 1;
+                           prach_root              			      = 0;
+			   tx_gain                                            = 90;
+			   rx_gain                                            = 115;
+                           pbch_repetition                                    = "FALSE";
+                           prach_config_index      			      = 0;
+                           prach_high_speed        			      = "DISABLE";
+                       prach_zero_correlation  			      = 1;
+                           prach_freq_offset       			      = 2;
+			   pucch_delta_shift       			      = 1;
+                           pucch_nRB_CQI           			      = 0;
+                           pucch_nCS_AN            			      = 0;
+                           pucch_n1_AN             			      = 0;
+                           pdsch_referenceSignalPower 			      = -29;
+                           pdsch_p_b                  			      = 0;
+                           pusch_n_SB                 			      = 1;
+                           pusch_enable64QAM          			      = "DISABLE";
+			   pusch_hoppingMode                                  = "interSubFrame";
+			   pusch_hoppingOffset                                = 0;
+                         pusch_groupHoppingEnabled  			      = "ENABLE";
+	                   pusch_groupAssignment      			      = 0;
+	                   pusch_sequenceHoppingEnabled		   	      = "DISABLE";
+	                   pusch_nDMRS1                                       = 1;
+	                   phich_duration                                     = "NORMAL";
+	                   phich_resource                                     = "ONESIXTH";
+	                   srs_enable                                         = "DISABLE";
+	               /*  srs_BandwidthConfig                                =;
+	                   srs_SubframeConfig                                 =;
+	                   srs_ackNackST                                      =;
+	                   srs_MaxUpPts                                       =;*/
+
+	                   pusch_p0_Nominal                                   = -96;
+	                   pusch_alpha                                        = "AL1";
+	                   pucch_p0_Nominal                                   = -108;
+	                   msg3_delta_Preamble                                = 6;
+	                   pucch_deltaF_Format1                               = "deltaF2";
+	                   pucch_deltaF_Format1b                              = "deltaF3";
+	                   pucch_deltaF_Format2                               = "deltaF0";
+	                   pucch_deltaF_Format2a                              = "deltaF0";
+                       pucch_deltaF_Format2b		    	      = "deltaF0";
+
+                           rach_numberOfRA_Preambles                          = 64;
+                           rach_preamblesGroupAConfig                         = "DISABLE";
+/*
+                           rach_sizeOfRA_PreamblesGroupA                      = ;
+                           rach_messageSizeGroupA                             = ;
+                           rach_messagePowerOffsetGroupB                      = ;
+*/
+                           rach_powerRampingStep                              = 4;
+	                   rach_preambleInitialReceivedTargetPower            = -108;
+                           rach_preambleTransMax                              = 10;
+	                   rach_raResponseWindowSize                          = 10;
+	                   rach_macContentionResolutionTimer                  = 48;
+	                   rach_maxHARQ_Msg3Tx                                = 4;
+
+			   pcch_default_PagingCycle                           = 128;
+			   pcch_nB                                            = "oneT";
+			   bcch_modificationPeriodCoeff			      = 2;
+			   ue_TimersAndConstants_t300			      = 1000;
+			   ue_TimersAndConstants_t301			      = 1000;
+			   ue_TimersAndConstants_t310			      = 1000;
+			   ue_TimersAndConstants_t311			      = 10000;
+			   ue_TimersAndConstants_n310			      = 20;
+			   ue_TimersAndConstants_n311			      = 1;
+
+      //Parameters for SIB18
+      rxPool_sc_CP_Len                                       = "normal";
+      rxPool_sc_Period                                       = "sf40";
+      rxPool_data_CP_Len                                     = "normal";
+      rxPool_ResourceConfig_prb_Num                          = 20;
+      rxPool_ResourceConfig_prb_Start                        = 5;
+      rxPool_ResourceConfig_prb_End                          = 44;
+      rxPool_ResourceConfig_offsetIndicator_present          = "prSmall";
+      rxPool_ResourceConfig_offsetIndicator_choice           = 0;
+      rxPool_ResourceConfig_subframeBitmap_present           = "prBs40";
+      rxPool_ResourceConfig_subframeBitmap_choice_bs_buf              = "00000000000000000000";
+      rxPool_ResourceConfig_subframeBitmap_choice_bs_size             = 5;
+      rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused      = 0;
+/*    rxPool_dataHoppingConfig_hoppingParameter                       = 0;
+      rxPool_dataHoppingConfig_numSubbands                            = "ns1";
+      rxPool_dataHoppingConfig_rbOffset                               = 0;
+      rxPool_commTxResourceUC-ReqAllowed                              = "TRUE";
+*/
+      // Parameters for SIB19
+      discRxPool_cp_Len                                               = "normal"
+      discRxPool_discPeriod                                           = "rf32"
+      discRxPool_numRetx                                              = 1;
+      discRxPool_numRepetition                                        = 2;
+      discRxPool_ResourceConfig_prb_Num                               = 5;
+      discRxPool_ResourceConfig_prb_Start                             = 3;
+      discRxPool_ResourceConfig_prb_End                               = 21;
+      discRxPool_ResourceConfig_offsetIndicator_present               = "prSmall";
+      discRxPool_ResourceConfig_offsetIndicator_choice                = 0;
+      discRxPool_ResourceConfig_subframeBitmap_present                = "prBs40";
+      discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf          = "f0ffffffff";
+      discRxPool_ResourceConfig_subframeBitmap_choice_bs_size         = 5;
+      discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused  = 0;
+
+			 }
+			 );
+
+    srb1_parameters :
+    {
+        # timer_poll_retransmit = (ms) [5, 10, 15, 20,... 250, 300, 350, ... 500]
+        timer_poll_retransmit    = 80;
+
+        # timer_reordering = (ms) [0,5, ... 100, 110, 120, ... ,200]
+        timer_reordering         = 35;
+
+        # timer_reordering = (ms) [0,5, ... 250, 300, 350, ... ,500]
+        timer_status_prohibit    = 0;
+
+        # poll_pdu = [4, 8, 16, 32 , 64, 128, 256, infinity(>10000)]
+        poll_pdu                 =  4;
+
+        # poll_byte = (kB) [25,50,75,100,125,250,375,500,750,1000,1250,1500,2000,3000,infinity(>10000)]
+        poll_byte                =  99999;
+
+        # max_retx_threshold = [1, 2, 3, 4 , 6, 8, 16, 32]
+        max_retx_threshold       =  4;
+    }
+
+    # ------- SCTP definitions
+    SCTP :
+    {
+        # Number of streams to use in input/output
+        SCTP_INSTREAMS  = 2;
+        SCTP_OUTSTREAMS = 2;
+    };
+
+    ////////// MME parameters:
+    mme_ip_address      = ( { ipv4       = "192.168.12.148";
+                              ipv6       = "192:168:30::17";
+                              active     = "yes";
+                              preference = "ipv4";
+                            }
+                          );
+
+    NETWORK_INTERFACES :
+    {
+        ENB_INTERFACE_NAME_FOR_S1_MME            = "eth1";
+        ENB_IPV4_ADDRESS_FOR_S1_MME              = "192.168.12.196/24";
+
+        ENB_INTERFACE_NAME_FOR_S1U               = "eth1";
+        ENB_IPV4_ADDRESS_FOR_S1U                 = "192.168.12.196/24";
+        ENB_PORT_FOR_S1U                         = 2152; # Spec 2152
+
+        ENB_IPV4_ADDRESS_FOR_X2C                 = "192.168.12.196/24";
+        ENB_PORT_FOR_X2C                         = 36422; # Spec 36422
+    };
+
+    log_config :
+    {
+	global_log_level                      ="info";
+      global_log_verbosity                  ="high";
+	hw_log_level                          ="info";
+      hw_log_verbosity                      ="medium";
+	phy_log_level                         ="info";
+      phy_log_verbosity                     ="medium";
+	mac_log_level                         ="info";
+      mac_log_verbosity                     ="high";
+	rlc_log_level                         ="debug";
+      rlc_log_verbosity                     ="high";
+	pdcp_log_level                        ="info";
+      pdcp_log_verbosity                    ="high";
+	rrc_log_level                         ="info";
+      rrc_log_verbosity                     ="medium";
+   };
+
+  }
+);
+
+MACRLCs = (
+        {
+        num_cc = 1;
+        tr_s_preference = "local_L1";
+        tr_n_preference = "local_RRC";
+        phy_test_mode = 0;
+        puSch10xSnr     =  210;
+        puCch10xSnr     =  210;
+        }
+);
+
+THREAD_STRUCT = (
+  {
+    parallel_config = "PARALLEL_RU_L1_TRX_SPLITaaaaaa";
+    worker_config = "ENABLE";
+  }
+);
+
+L1s = (
+        {
+        num_cc = 1;
+        tr_n_preference = "local_mac";
+        }
+);
+
+RUs = (
+    {
+       local_rf       = "yes"
+         nb_tx          = 1
+         nb_rx          = 1
+         att_tx         = 73
+         att_rx         = 0;
+         bands          = [7];
+         max_pdschReferenceSignalPower = -28;
+         max_rxgain                    = 96;
+         eNB_instances  = [0];
+
+    }
+);
+
+    log_config :
+    {
+	global_log_level                      ="info";
+      global_log_verbosity                  ="high";
+	hw_log_level                          ="info";
+      hw_log_verbosity                      ="medium";
+	phy_log_level                         ="info";
+      phy_log_verbosity                     ="medium";
+	mac_log_level                         ="info";
+      mac_log_verbosity                     ="high";
+	rlc_log_level                         ="info";
+      rlc_log_verbosity                     ="high";
+	pdcp_log_level                        ="info";
+      pdcp_log_verbosity                    ="high";
+	rrc_log_level                         ="info";
+      rrc_log_verbosity                     ="medium";
+   };
diff --git a/doc/FEATURE_SET.md b/doc/FEATURE_SET.md
new file mode 100644
index 0000000000000000000000000000000000000000..88f25ee665ef9ae62c73f829a358753a96765b21
--- /dev/null
+++ b/doc/FEATURE_SET.md
@@ -0,0 +1,194 @@
+**Table of Contents**
+
+1. [OpenAirInterface eNB Feature Set](#openairinterface-enb-feature-set)
+   1. [eNB PHY Layer](#enb-phy-layer)
+   2. [eNB MAC Layer](#enb-mac-layer)
+   3. [eNB RLC Layer](#enb-rlc-layer)
+   4. [eNB PDCP Layer](#enb-pdcp-layer)
+   5. [eNB RRC Layer](#enb-rrc-layer)
+   6. [eNB X2AP](#enb-x2ap)
+   7. [eNB Advanced Features](#enb-advanced-features)
+2. [OpenAirInterface Functional Split](#openairinterface-functional-split)
+3. [OpenAirInterface UE Feature Set](#openairinterface-ue-feature-set)
+   1.  [LTE UE PHY Layer](#lte-ue-phy-layer)
+   2.  [LTE UE MAC Layer](#lte-ue-mac-layer)
+   3.  [LTE UE RLC Layer](#lte-ue-rlc-layer)
+   4.  [LTE UE PDCP Layer](#lte-ue-pdcp-layer)
+   5.  [LTE UE RRC Layer](#lte-ue-rrc-layer)
+
+# OpenAirInterface Block diagram #
+
+![Block Diagram](./oai_enb_block_diagram.png)
+
+# OpenAirInterface eNB Feature Set #
+
+## eNB PHY Layer ##
+
+The Physical layer implements **3GPP 36.211**, **36.212**, **36.213** and provides the following features:
+
+- LTE release 8.6 compliant, and implements a subset of release 10
+- FDD and TDD configurations: 1 (experimental) and 3
+- Bandwidth: 5, 10, and 20 MHz
+- Transmission modes: 1, 2 (stable), 3, 4, 5, 6, 7 (experimental)
+- Max number of antennas: 2
+- CQI/PMI reporting: aperiodic, feedback mode 3 - 0 and 3 - 1
+- PRACH preamble format 0
+- All downlink (DL) channels are supported: PSS, SSS, PBCH, PCFICH, PHICH, PDCCH, PDSCH, PMCH
+- All uplink (UL) channels are supported: PRACH, PUSCH, PUCCH (format 1/1a/1b), SRS, DRS
+- HARQ support (UL and DL)
+- Highly optimized base band processing (including turbo decoder)
+
+### Performances ###
+
+**Transmission Mode, Bandwidth** | **Expected Throughput** | **Measured Throughput** | **Measurement Conditions**
+-------------------------------- | ----------------------- | ------------------------| ----------------:
+FDD DL: 5 MHz, 25 PRBS/ MCS 28   | 16 - 17 Mbit/s          | TM1: 17.0 Mbits/s       | COTS-UE Cat 4 (150/50 Mbps)
+FDD DL: 10 MHz, 50 PRBS/ MCS 28  | 34 - 35 Mbit/s          | TM1: 32.8 Mbits/s       | COTS-UE Cat 4 (150/50 Mbps)
+FDD DL: 20 MHz, 100 PRBS/ MCS 28 | 70 Mbit/s               | TM1: 69.9 Mbits/s       | COTS-UE Cat 4 (150/50 Mbps)
+ |  |  |
+FDD UL: 5 MHz, 25 PRBS/ MCS 20   | 9 Mbit/s                | TM1: 8.28 Mbits/s       | COTS-UE Cat 4 (150/50 Mbps)
+FDD UL: 10 MHz, 50 PRBS/ MCS 20  | 17 Mbit/s               | TM1: 15.2 Mbits/s       | COTS-UE Cat 4 (150/50 Mbps)
+FDD UL: 20 MHz, 100 PRBS/ MCS 20 | 35 Mbit/s               | TM1: 18.6 Mbits/s       | COTS-UE Cat 4 (150/50 Mbps)
+ |  |
+TDD DL: 5 MHz, 25 PRBS/ MCS **XX**   | **TBC** Mbit/s | 3.33 Mbits/s | COTS-UE Cat 4 (150/50 Mbps)
+TDD DL: 10 MHz, 50 PRBS/ MCS **XX**  | **TBC** Mbit/s | 8.90 Mbits/s | COTS-UE Cat 4 (150/50 Mbps)
+TDD DL: 20 MHz, 100 PRBS/ MCS **XX** | **TBC** Mbit/s | N/A | COTS-UE Cat 4 (150/50 Mbps)
+ |  | |
+TDD UL: 5 MHz, 25 PRBS/ MCS **XX**   | **TBC** Mbit/s | 1.66 Mbits/s | COTS-UE Cat 4 (150/50 Mbps)
+TDD UL: 10 MHz, 50 PRBS/ MCS **XX**  | **TBC** Mbit/s | 1.89 Mbits/s | COTS-UE Cat 4 (150/50 Mbps)
+TDD UL: 20 MHz, 100 PRBS/ MCS **XX** | **TBC** Mbit/s | N/A | COTS-UE Cat 4 (150/50 Mbps)
+
+- Number of supported UEs: **To Be Completed**
+
+## eNB MAC Layer ##
+
+The MAC layer implements a subset of the **3GPP 36.321** release v8.6 in support of BCH, DLSCH, RACH, and ULSCH channels.
+
+- RRC interface for CCCH, DCCH, and DTCH
+- Proportional fair scheduler (round robin scheduler soon)
+- DCI generation
+- HARQ Support
+- RA procedures and RNTI management
+- RLC interface (AM, UM)
+- UL power control
+- Link adaptation
+
+## eNB RLC Layer ##
+
+The RLC layer implements a full specification of the 3GPP 36.322 release v9.3.
+
+- RLC TM (mainly used for BCCH and CCCH)
+  * Neither segment nor concatenate RLC SDUs
+  * Do not include a RLC header in the RLC PDU
+  * Delivery of received RLC PDUs to upper layers
+- RLC UM (mainly used for DTCH)
+  * Segment or concatenate RLC SDUs according to the TB size selected by MAC
+  * Include a RLC header in the RLC PDU
+  * Duplication detection
+  * PDU reordering and reassembly
+- RLC AM, compatible with 9.3
+  * Segmentation, re-segmentation, concatenation, and reassembly
+  * Padding
+  * Data transfer to the user
+  * RLC PDU retransmission in support of error control and correction
+  * Generation of data/control PDUs
+
+## eNB PDCP Layer ##
+
+The current PDCP layer is header compliant with **3GPP 36.323** Rel 10.1.0 and implements the following functions:
+
+- User and control data transfer
+- Sequence number management
+- RB association with PDCP entity
+- PDCP entity association with one or two RLC entities
+- Integrity check and encryption using the AES and Snow3G algorithms
+
+## eNB RRC Layer ##
+
+The RRC layer is based on **3GPP 36.331** v14.3.0 and implements the following functions:
+
+- System Information broadcast (SIB 1, 2, 3, and 13)
+  * SIB1: Up to 6 PLMN IDs broadcast
+- RRC connection establishment
+- RRC connection reconfiguration (addition and removal of radio bearers, connection release)
+- RRC connection release
+- RRC connection re-establishment
+- Inter-frequency measurement collection and reporting (experimental)
+- eMBMS for multicast and broadcast (experimental)
+- Handover (experimental)
+- Paging (soon)
+
+## eNB X2AP ##
+
+The X2AP layer is based on **3GPP 36.423** v14.6.0 and implements the following functions:
+
+ - X2 Setup Request
+ - X2 Setup Response
+ - X2 Setup Failure
+ - Handover Request
+ - Handover Request Acknowledge
+
+## eNB Advanced Features ##
+
+**To be completed**
+
+# OpenAirInterface Functional Split #
+
+-  RCC: Radio-Cloud Center
+-  RAU: Radio-Access Unit
+-  RRU: Remote Radio-Unit
+
+![Functional Split Architecture](./oai_lte_enb_func_split_arch.png)
+
+-  IF4.5 / IF5 : similar to IEEE P1914.1
+-  FAPI (IF2)  : specified by Small Cell Forum (open-nFAPI implementation)
+-  IF1         : F1 in 3GPP Release 15 (not implemented yet)
+
+# OpenAirInterface UE Feature Set #
+
+## LTE UE PHY Layer ##
+
+The Physical layer implements **3GPP 36.211**, **36.212**, **36.213** and provides the following features:
+
+- LTE release 8.6 compliant, and implements a subset of release 10
+- FDD and TDD configurations: 1 (experimental) and 3
+- Bandwidth: 5, 10, and 20 MHz
+- Transmission modes: 1, 2 (stable)
+- Max number of antennas: 2
+- CQI/PMI reporting: aperiodic, feedback mode 3 - 0 and 3 - 1
+- PRACH preamble format 0
+- All downlink (DL) channels are supported: PSS, SSS, PBCH, PCFICH, PHICH, PDCCH, PDSCH, PMCH
+- All uplink (UL) channels are supported: PRACH, PUSCH, PUCCH (format 1/1a/1b), SRS, DRS
+
+## LTE UE MAC Layer ##
+
+The MAC layer implements a subset of the **3GPP 36.321** release v8.6 in support of BCH, DLSCH, RACH, and ULSCH channels.
+
+- RRC interface for CCCH, DCCH, and DTCH
+- HARQ Support
+- RA procedures and RNTI management
+- RLC interface (AM, UM)
+- UL power control
+- Link adaptation
+
+## LTE UE RLC Layer ##
+
+The RLC layer implements a full specification of the 3GPP 36.322 release v9.3.
+
+## LTE UE PDCP Layer ##
+
+The current PDCP layer is header compliant with **3GPP 36.323** Rel 10.1.0.
+
+## LTE UE RRC Layer ##
+
+The RRC layer is based on **3GPP 36.331** v14.3.0 and implements the following functions:
+
+- System Information decoding
+- RRC connection establishment
+
+## LTE UE NAS Layer ##
+
+The NAS layer is based on **3GPP 24.301** and implements the following functions:
+
+- EMM attach/detach, authentication, tracking area update, and more
+- ESM default/dedicated bearer, PDN connectivity, and more
diff --git a/doc/oai_enb_block_diagram.png b/doc/oai_enb_block_diagram.png
new file mode 100644
index 0000000000000000000000000000000000000000..58c8eb9e959fae8616de03cc9f56fcfe2cc0f0e7
Binary files /dev/null and b/doc/oai_enb_block_diagram.png differ
diff --git a/doc/oai_lte_enb_func_split_arch.png b/doc/oai_lte_enb_func_split_arch.png
new file mode 100644
index 0000000000000000000000000000000000000000..1e8a55924ccd6101319369567479230dad1c8d24
Binary files /dev/null and b/doc/oai_lte_enb_func_split_arch.png differ
diff --git a/nfapi/oai_integration/nfapi_pnf.c b/nfapi/oai_integration/nfapi_pnf.c
index e7416922146235fc93ff273077b65dec8e673df6..78c058ad007229b775a8558b3eb22c7f4ef00432 100644
--- a/nfapi/oai_integration/nfapi_pnf.c
+++ b/nfapi/oai_integration/nfapi_pnf.c
@@ -69,12 +69,12 @@ char uecap_xer_in;
 
 extern void init_eNB_afterRU(void);
 extern void init_UE_stub(int nb_inst,int,int);
-extern void handle_nfapi_dci_dl_pdu(PHY_VARS_eNB *eNB, int frame, int subframe, eNB_rxtx_proc_t *proc, nfapi_dl_config_request_pdu_t *dl_config_pdu);
-extern void handle_nfapi_ul_pdu(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc, nfapi_ul_config_request_pdu_t *ul_config_pdu, uint16_t frame,uint8_t subframe,uint8_t srs_present);
-extern void handle_nfapi_dlsch_pdu(PHY_VARS_eNB *eNB,int frame, int subframe, eNB_rxtx_proc_t *proc,  nfapi_dl_config_request_pdu_t *dl_config_pdu, uint8_t codeword_index, uint8_t *sdu);
-extern void handle_nfapi_hi_dci0_dci_pdu(PHY_VARS_eNB *eNB,int frame, int subframe, eNB_rxtx_proc_t *proc, nfapi_hi_dci0_request_pdu_t *hi_dci0_config_pdu);
-extern void handle_nfapi_hi_dci0_hi_pdu(PHY_VARS_eNB *eNB,int frame, int subframe, eNB_rxtx_proc_t *proc, nfapi_hi_dci0_request_pdu_t *hi_dci0_config_pdu);
-extern void handle_nfapi_bch_pdu(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc, nfapi_dl_config_request_pdu_t *dl_config_pdu, uint8_t *sdu);
+extern void handle_nfapi_dci_dl_pdu(PHY_VARS_eNB *eNB, int frame, int subframe, L1_rxtx_proc_t *proc, nfapi_dl_config_request_pdu_t *dl_config_pdu);
+extern void handle_nfapi_ul_pdu(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc, nfapi_ul_config_request_pdu_t *ul_config_pdu, uint16_t frame,uint8_t subframe,uint8_t srs_present);
+extern void handle_nfapi_dlsch_pdu(PHY_VARS_eNB *eNB,int frame, int subframe, L1_rxtx_proc_t *proc,  nfapi_dl_config_request_pdu_t *dl_config_pdu, uint8_t codeword_index, uint8_t *sdu);
+extern void handle_nfapi_hi_dci0_dci_pdu(PHY_VARS_eNB *eNB,int frame, int subframe, L1_rxtx_proc_t *proc, nfapi_hi_dci0_request_pdu_t *hi_dci0_config_pdu);
+extern void handle_nfapi_hi_dci0_hi_pdu(PHY_VARS_eNB *eNB,int frame, int subframe, L1_rxtx_proc_t *proc, nfapi_hi_dci0_request_pdu_t *hi_dci0_config_pdu);
+extern void handle_nfapi_bch_pdu(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc, nfapi_dl_config_request_pdu_t *dl_config_pdu, uint8_t *sdu);
 
 extern uint8_t  nfapi_mode;
 
@@ -741,7 +741,7 @@ int pnf_phy_hi_dci0_req(nfapi_pnf_p7_config_t* pnf_p7, nfapi_hi_dci0_request_t*
   //phy_info* phy = (phy_info*)(pnf_p7->user_data);
 
   struct PHY_VARS_eNB_s *eNB = RC.eNB[0][0];
-  eNB_rxtx_proc_t *proc = &eNB->proc.proc_rxtx[0];
+  L1_rxtx_proc_t *proc = &eNB->proc.L1_proc;
 
   for (int i=0; i<req->hi_dci0_request_body.number_of_dci + req->hi_dci0_request_body.number_of_hi; i++) {
 
@@ -798,7 +798,7 @@ int pnf_phy_dl_config_req(nfapi_pnf_p7_config_t* pnf_p7, nfapi_dl_config_request
   int sf = NFAPI_SFNSF2SF(req->sfn_sf);
 
   struct PHY_VARS_eNB_s *eNB = RC.eNB[0][0];
-  eNB_rxtx_proc_t *proc = &eNB->proc.proc_rxtx[0];
+  L1_rxtx_proc_t *proc = &eNB->proc.L1_proc;
   nfapi_dl_config_request_pdu_t* dl_config_pdu_list = req->dl_config_request_body.dl_config_pdu_list;
   LTE_eNB_PDCCH *pdcch_vars = &eNB->pdcch_vars[sf&1];
 
@@ -869,7 +869,7 @@ int pnf_phy_dl_config_req(nfapi_pnf_p7_config_t* pnf_p7, nfapi_dl_config_request
 
         //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() DLSCH:pdu_index:%d handle_nfapi_dlsch_pdu(eNB, proc_rxtx, dlsch_pdu, transport_blocks:%d sdu:%p) eNB->pdcch_vars[proc->subframe_tx & 1].num_pdcch_symbols:%d\n", __FUNCTION__, rel8_pdu->pdu_index, rel8_pdu->transport_blocks, dlsch_sdu, eNB->pdcch_vars[proc->subframe_tx & 1].num_pdcch_symbols);
 
-        handle_nfapi_dlsch_pdu( eNB, sfn,sf, &eNB->proc.proc_rxtx[0], &dl_config_pdu_list[i], rel8_pdu->transport_blocks-1, dlsch_sdu);
+        handle_nfapi_dlsch_pdu( eNB, sfn,sf, &eNB->proc.L1_proc, &dl_config_pdu_list[i], rel8_pdu->transport_blocks-1, dlsch_sdu);
 
       } else {
 
@@ -945,7 +945,7 @@ int pnf_phy_ul_config_req(nfapi_pnf_p7_config_t* pnf_p7, nfapi_ul_config_request
   uint16_t curr_sf = NFAPI_SFNSF2SF(req->sfn_sf);
 
   struct PHY_VARS_eNB_s *eNB = RC.eNB[0][0];
-  eNB_rxtx_proc_t *proc = &eNB->proc.proc_rxtx[0];
+  L1_rxtx_proc_t *proc = &eNB->proc.L1_proc;
   nfapi_ul_config_request_pdu_t* ul_config_pdu_list = req->ul_config_request_body.ul_config_pdu_list;
 
   for (int i=0;i<req->ul_config_request_body.number_of_pdus;i++) {
diff --git a/nfapi/oai_integration/nfapi_vnf.c b/nfapi/oai_integration/nfapi_vnf.c
index 8022bc53f43d2b2defa5fbc19c633ae70715310b..2597c9e8deb477d00e0d0fa0fd25aeb4f502ab0c 100644
--- a/nfapi/oai_integration/nfapi_vnf.c
+++ b/nfapi/oai_integration/nfapi_vnf.c
@@ -61,7 +61,7 @@ typedef struct {
   char local_addr[80];
   int local_port;
 
-  char* remote_addr;
+  char *remote_addr;
   int remote_port;
 
   uint8_t duplex_mode;
@@ -127,12 +127,12 @@ typedef struct mac mac_t;
 
 typedef struct mac {
 
-	void* user_data;
+  void *user_data;
 
-	void (*dl_config_req)(mac_t* mac, nfapi_dl_config_request_t* req);
-	void (*ul_config_req)(mac_t* mac, nfapi_ul_config_request_t* req);
-	void (*hi_dci0_req)(mac_t* mac, nfapi_hi_dci0_request_t* req);
-	void (*tx_req)(mac_t* mac, nfapi_tx_request_t* req);
+  void (*dl_config_req)(mac_t *mac, nfapi_dl_config_request_t *req);
+  void (*ul_config_req)(mac_t *mac, nfapi_ul_config_request_t *req);
+  void (*hi_dci0_req)(mac_t *mac, nfapi_hi_dci0_request_t *req);
+  void (*tx_req)(mac_t *mac, nfapi_tx_request_t *req);
 } mac_t;
 
 typedef struct {
@@ -145,15 +145,15 @@ typedef struct {
   unsigned aperiodic_timing_enabled;
   unsigned periodic_timing_period;
 
-  // This is not really the right place if we have multiple PHY, 
+  // This is not really the right place if we have multiple PHY,
   // should be part of the phy struct
   udp_data udp;
 
   uint8_t thread_started;
 
-  nfapi_vnf_p7_config_t* config;
+  nfapi_vnf_p7_config_t *config;
 
-  mac_t* mac;
+  mac_t *mac;
 
 } vnf_p7_info;
 
@@ -165,24 +165,27 @@ typedef struct {
 
 } vnf_info;
 
-int vnf_pack_vendor_extension_tlv(void* ve, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t* codec) {
+int vnf_pack_vendor_extension_tlv(void *ve, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *codec) {
   //NFAPI_TRACE(NFAPI_TRACE_INFO, "vnf_pack_vendor_extension_tlv\n");
-  nfapi_tl_t* tlv = (nfapi_tl_t*)ve;
+  nfapi_tl_t *tlv = (nfapi_tl_t *)ve;
+
   switch(tlv->tag) {
-    case VENDOR_EXT_TLV_2_TAG:
-      {
-        //NFAPI_TRACE(NFAPI_TRACE_INFO, "Packing VENDOR_EXT_TLV_2\n");
-        vendor_ext_tlv_2* ve = (vendor_ext_tlv_2*)tlv;
-        if(!push32(ve->dummy, ppWritePackedMsg, end))
-          return 0;
-        return 1;
-      }
-      break;
+    case VENDOR_EXT_TLV_2_TAG: {
+      //NFAPI_TRACE(NFAPI_TRACE_INFO, "Packing VENDOR_EXT_TLV_2\n");
+      vendor_ext_tlv_2 *ve = (vendor_ext_tlv_2 *)tlv;
+
+      if(!push32(ve->dummy, ppWritePackedMsg, end))
+        return 0;
+
+      return 1;
+    }
+    break;
   }
+
   return -1;
 }
 
-int vnf_unpack_vendor_extension_tlv(nfapi_tl_t* tl, uint8_t **ppReadPackedMessage, uint8_t *end, void** ve, nfapi_p4_p5_codec_config_t* codec) {
+int vnf_unpack_vendor_extension_tlv(nfapi_tl_t *tl, uint8_t **ppReadPackedMessage, uint8_t *end, void **ve, nfapi_p4_p5_codec_config_t *codec) {
   return -1;
 }
 
@@ -192,19 +195,14 @@ extern void init_eNB_afterRU(void);
 extern uint16_t sf_ahead;
 
 void oai_create_enb(void) {
-
   int bodge_counter=0;
   PHY_VARS_eNB *eNB = RC.eNB[0][0];
-
-  printf("[VNF] RC.eNB[0][0]. Mod_id:%d CC_id:%d nb_CC[0]:%d abstraction_flag:%d single_thread_flag:%d td:%p te:%p if_inst:%p\n", eNB->Mod_id, eNB->CC_id, RC.nb_CC[0], eNB->abstraction_flag, eNB->single_thread_flag, eNB->td, eNB->te, eNB->if_inst);
-
+  printf("[VNF] RC.eNB[0][0]. Mod_id:%d CC_id:%d nb_CC[0]:%d abstraction_flag:%d single_thread_flag:%d if_inst:%p\n", eNB->Mod_id, eNB->CC_id, RC.nb_CC[0], eNB->abstraction_flag,
+         eNB->single_thread_flag, eNB->if_inst);
   eNB->Mod_id  = bodge_counter;
   eNB->CC_id   = bodge_counter;
   eNB->abstraction_flag   = 0;
   eNB->single_thread_flag = 0;//single_thread_flag;
-  eNB->td                   = ulsch_decoding_data_all;//(single_thread_flag==1) ? ulsch_decoding_data_2thread : ulsch_decoding_data;
-  eNB->te                   = dlsch_encoding_all;//(single_thread_flag==1) ? dlsch_encoding_2threads : dlsch_encoding;
-
   RC.nb_CC[bodge_counter] = 1;
 
   if (eNB->if_inst==0) {
@@ -215,7 +213,6 @@ void oai_create_enb(void) {
   // that will result in eNB->configured being set to TRUE.
   // See we need to wait for that to happen otherwise the NFAPI message exchanges won't contain the right parameter values
   if (RC.eNB[0][0]->if_inst==0 || RC.eNB[0][0]->if_inst->PHY_config_req==0 || RC.eNB[0][0]->if_inst->schedule_response==0) {
-
     printf("RC.eNB[0][0]->if_inst->PHY_config_req is not installed - install it\n");
     install_schedule_handlers(RC.eNB[0][0]->if_inst);
   }
@@ -229,17 +226,13 @@ void oai_create_enb(void) {
 }
 
 void oai_enb_init(void) {
-
   printf("%s() About to call init_eNB_afterRU()\n", __FUNCTION__);
   init_eNB_afterRU();
 }
 
-int pnf_connection_indication_cb(nfapi_vnf_config_t* config, int p5_idx) {
-
+int pnf_connection_indication_cb(nfapi_vnf_config_t *config, int p5_idx) {
   printf("[VNF] pnf connection indication idx:%d\n", p5_idx);
-
   oai_create_enb();
-
   nfapi_pnf_param_request_t req;
   memset(&req, 0, sizeof(req));
   req.header.message_id = NFAPI_PNF_PARAM_REQUEST;
@@ -247,39 +240,29 @@ int pnf_connection_indication_cb(nfapi_vnf_config_t* config, int p5_idx) {
   return 0;
 }
 
-int pnf_disconnection_indication_cb(nfapi_vnf_config_t* config, int p5_idx) {
+int pnf_disconnection_indication_cb(nfapi_vnf_config_t *config, int p5_idx) {
   printf("[VNF] pnf disconnection indication idx:%d\n", p5_idx);
-
-  vnf_info* vnf = (vnf_info*)(config->user_data);
-
+  vnf_info *vnf = (vnf_info *)(config->user_data);
   pnf_info *pnf = vnf->pnfs;
   phy_info *phy = pnf->phys;
-
-  vnf_p7_info* p7_vnf = vnf->p7_vnfs;
+  vnf_p7_info *p7_vnf = vnf->p7_vnfs;
   nfapi_vnf_p7_del_pnf((p7_vnf->config), phy->id);
-
   return 0;
 }
 
-int pnf_param_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_pnf_param_response_t* resp) {
-
+int pnf_param_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_pnf_param_response_t *resp) {
   printf("[VNF] pnf param response idx:%d error:%d\n", p5_idx, resp->error_code);
-
-  vnf_info* vnf = (vnf_info*)(config->user_data);
-
+  vnf_info *vnf = (vnf_info *)(config->user_data);
   pnf_info *pnf = vnf->pnfs;
 
-  for(int i = 0; i < resp->pnf_phy.number_of_phys; ++i)
-  {
+  for(int i = 0; i < resp->pnf_phy.number_of_phys; ++i) {
     phy_info phy;
+    memset(&phy,0,sizeof(phy));
     phy.index = resp->pnf_phy.phy[i].phy_config_index;
-
     printf("[VNF] (PHY:%d) phy_config_idx:%d\n", i, resp->pnf_phy.phy[i].phy_config_index);
-
     nfapi_vnf_allocate_phy(config, p5_idx, &(phy.id));
 
-    for(int j = 0; j < resp->pnf_phy.phy[i].number_of_rfs; ++j)
-    {
+    for(int j = 0; j < resp->pnf_phy.phy[i].number_of_rfs; ++j) {
       printf("[VNF] (PHY:%d) (RF%d) %d\n", i, j, resp->pnf_phy.phy[i].rf_config[j].rf_config_index);
       phy.rfs[0] = resp->pnf_phy.phy[i].rf_config[j].rf_config_index;
     }
@@ -289,17 +272,15 @@ int pnf_param_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_pnf_param_re
 
   for(int i = 0; i < resp->pnf_rf.number_of_rfs; ++i) {
     rf_info rf;
+    memset(&rf,0,sizeof(rf));
     rf.index = resp->pnf_rf.rf[i].rf_config_index;
-
     printf("[VNF] (RF:%d) rf_config_idx:%d\n", i, resp->pnf_rf.rf[i].rf_config_index);
-
     pnf->rfs[0] = rf;
   }
 
   nfapi_pnf_config_request_t req;
   memset(&req, 0, sizeof(req));
   req.header.message_id = NFAPI_PNF_CONFIG_REQUEST;
-
   req.pnf_phy_rf_config.tl.tag = NFAPI_PNF_PHY_RF_TAG;
   req.pnf_phy_rf_config.number_phy_rf_config_info = 2; // DJP pnf.phys.size();
   printf("DJP:Hard coded num phy rf to 2\n");
@@ -311,25 +292,22 @@ int pnf_param_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_pnf_param_re
   }
 
   nfapi_vnf_pnf_config_req(config, p5_idx, &req);
-
   return 0;
 }
 
-int pnf_config_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_pnf_config_response_t* resp) {
-
+int pnf_config_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_pnf_config_response_t *resp) {
   printf("[VNF] pnf config response idx:%d resp[header[phy_id:%u message_id:%02x message_length:%u]]\n", p5_idx, resp->header.phy_id, resp->header.message_id, resp->header.message_length);
 
   if(1) {
-      nfapi_pnf_start_request_t req;
-      memset(&req, 0, sizeof(req));
-      req.header.phy_id = resp->header.phy_id;
-      req.header.message_id = NFAPI_PNF_START_REQUEST;
-      nfapi_vnf_pnf_start_req(config, p5_idx, &req);
+    nfapi_pnf_start_request_t req;
+    memset(&req, 0, sizeof(req));
+    req.header.phy_id = resp->header.phy_id;
+    req.header.message_id = NFAPI_PNF_START_REQUEST;
+    nfapi_vnf_pnf_start_req(config, p5_idx, &req);
   } else {
     // Rather than send the pnf_start_request we will demonstrate
     // sending a vendor extention message. The start request will be
-    // send when the vendor extension response is received 
-
+    // send when the vendor extension response is received
     //vnf_info* vnf = (vnf_info*)(config->user_data);
     vendor_ext_p5_req req;
     memset(&req, 0, sizeof(req));
@@ -338,29 +316,24 @@ int pnf_config_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_pnf_config_
     req.dummy2 = 1977;
     nfapi_vnf_vendor_extension(config, p5_idx, &req.header);
   }
+
   return 0;
 }
 
 int wake_eNB_rxtx(PHY_VARS_eNB *eNB, uint16_t sfn, uint16_t sf) {
-
-  eNB_proc_t *proc=&eNB->proc;
-
-  eNB_rxtx_proc_t *proc_rxtx=&proc->proc_rxtx[sf&1];
-
+  L1_proc_t *proc=&eNB->proc;
+  L1_rxtx_proc_t *L1_proc= (sf&1)? &proc->L1_proc : &proc->L1_proc_tx;
   LTE_DL_FRAME_PARMS *fp = &eNB->frame_parms;
-
   //printf("%s(eNB:%p, sfn:%d, sf:%d)\n", __FUNCTION__, eNB, sfn, sf);
-
   //int i;
   struct timespec wait;
-
   wait.tv_sec=0;
   wait.tv_nsec=5000000L;
 
   // wake up TX for subframe n+sf_ahead
   // lock the TX mutex and make sure the thread is ready
-  if (pthread_mutex_timedlock(&proc_rxtx->mutex_rxtx,&wait) != 0) {
-    LOG_E( PHY, "[eNB] ERROR pthread_mutex_lock for eNB RXTX thread %d (IC %d)\n", proc_rxtx->subframe_rx&1,proc_rxtx->instance_cnt_rxtx );
+  if (pthread_mutex_timedlock(&L1_proc->mutex,&wait) != 0) {
+    LOG_E( PHY, "[eNB] ERROR pthread_mutex_lock for eNB RXTX thread %d (IC %d)\n", L1_proc->subframe_rx&1,L1_proc->instance_cnt );
     exit_fun( "error locking mutex_rxtx" );
     return(-1);
   }
@@ -368,10 +341,8 @@ int wake_eNB_rxtx(PHY_VARS_eNB *eNB, uint16_t sfn, uint16_t sf) {
   {
     static uint16_t old_sf = 0;
     static uint16_t old_sfn = 0;
-
     proc->subframe_rx = old_sf;
     proc->frame_rx = old_sfn;
-
     // Try to be 1 frame back
     old_sf = sf;
     old_sfn = sfn;
@@ -379,35 +350,32 @@ int wake_eNB_rxtx(PHY_VARS_eNB *eNB, uint16_t sfn, uint16_t sf) {
     if (old_sf == 0 && old_sfn % 100==0) LOG_W( PHY,"[eNB] sfn/sf:%d%d old_sfn/sf:%d%d proc[rx:%d%d]\n", sfn, sf, old_sfn, old_sf, proc->frame_rx, proc->subframe_rx);
   }
 
-  ++proc_rxtx->instance_cnt_rxtx;
-
-  //LOG_D( PHY,"[VNF-subframe_ind] sfn/sf:%d:%d proc[frame_rx:%d subframe_rx:%d] proc_rxtx->instance_cnt_rxtx:%d \n", sfn, sf, proc->frame_rx, proc->subframe_rx, proc_rxtx->instance_cnt_rxtx);
-
+  ++L1_proc->instance_cnt;
+  //LOG_D( PHY,"[VNF-subframe_ind] sfn/sf:%d:%d proc[frame_rx:%d subframe_rx:%d] L1_proc->instance_cnt_rxtx:%d \n", sfn, sf, proc->frame_rx, proc->subframe_rx, L1_proc->instance_cnt_rxtx);
   // We have just received and processed the common part of a subframe, say n.
   // TS_rx is the last received timestamp (start of 1st slot), TS_tx is the desired
   // transmitted timestamp of the next TX slot (first).
   // The last (TS_rx mod samples_per_frame) was n*samples_per_tti,
   // we want to generate subframe (n+N), so TS_tx = TX_rx+N*samples_per_tti,
   // and proc->subframe_tx = proc->subframe_rx+sf_ahead
-  proc_rxtx->timestamp_tx = proc->timestamp_rx + (sf_ahead*fp->samples_per_tti);
-  proc_rxtx->frame_rx     = proc->frame_rx;
-  proc_rxtx->subframe_rx  = proc->subframe_rx;
-  proc_rxtx->frame_tx     = (proc_rxtx->subframe_rx > (9-sf_ahead)) ? (proc_rxtx->frame_rx+1)&1023 : proc_rxtx->frame_rx;
-  proc_rxtx->subframe_tx  = (proc_rxtx->subframe_rx + sf_ahead)%10;
+  L1_proc->timestamp_tx = proc->timestamp_rx + (sf_ahead*fp->samples_per_tti);
+  L1_proc->frame_rx     = proc->frame_rx;
+  L1_proc->subframe_rx  = proc->subframe_rx;
+  L1_proc->frame_tx     = (L1_proc->subframe_rx > (9-sf_ahead)) ? (L1_proc->frame_rx+1)&1023 : L1_proc->frame_rx;
+  L1_proc->subframe_tx  = (L1_proc->subframe_rx + sf_ahead)%10;
 
-  //LOG_D(PHY, "sfn/sf:%d%d proc[rx:%d%d] proc_rxtx[instance_cnt_rxtx:%d rx:%d%d] About to wake rxtx thread\n\n", sfn, sf, proc->frame_rx, proc->subframe_rx, proc_rxtx->instance_cnt_rxtx, proc_rxtx->frame_rx, proc_rxtx->subframe_rx);
+  //LOG_D(PHY, "sfn/sf:%d%d proc[rx:%d%d] L1_proc[instance_cnt_rxtx:%d rx:%d%d] About to wake rxtx thread\n\n", sfn, sf, proc->frame_rx, proc->subframe_rx, L1_proc->instance_cnt_rxtx, L1_proc->frame_rx, L1_proc->subframe_rx);
 
   // the thread can now be woken up
-  if (pthread_cond_signal(&proc_rxtx->cond_rxtx) != 0) {
+  if (pthread_cond_signal(&L1_proc->cond) != 0) {
     LOG_E( PHY, "[eNB] ERROR pthread_cond_signal for eNB RXn-TXnp4 thread\n");
     exit_fun( "ERROR pthread_cond_signal" );
     return(-1);
   }
 
   //LOG_D(PHY,"%s() About to attempt pthread_mutex_unlock\n", __FUNCTION__);
-  pthread_mutex_unlock( &proc_rxtx->mutex_rxtx );
+  pthread_mutex_unlock( &L1_proc->mutex );
   //LOG_D(PHY,"%s() UNLOCKED pthread_mutex_unlock\n", __FUNCTION__);
-
   return(0);
 }
 
@@ -415,12 +383,10 @@ extern pthread_cond_t nfapi_sync_cond;
 extern pthread_mutex_t nfapi_sync_mutex;
 extern int nfapi_sync_var;
 
-int phy_sync_indication(struct nfapi_vnf_p7_config* config, uint8_t sync) {
-
+int phy_sync_indication(struct nfapi_vnf_p7_config *config, uint8_t sync) {
   printf("[VNF] SYNC %s\n", sync==1 ? "ACHIEVED" : "LOST");
-  
-  if (sync==1 && nfapi_sync_var!=0) {
 
+  if (sync==1 && nfapi_sync_var!=0) {
     printf("[VNF] Signal to OAI main code that it can go\n");
     pthread_mutex_lock(&nfapi_sync_mutex);
     nfapi_sync_var=0;
@@ -431,9 +397,9 @@ int phy_sync_indication(struct nfapi_vnf_p7_config* config, uint8_t sync) {
   return(0);
 }
 
-int phy_subframe_indication(struct nfapi_vnf_p7_config* config, uint16_t phy_id, uint16_t sfn_sf) {
-
+int phy_subframe_indication(struct nfapi_vnf_p7_config *config, uint16_t phy_id, uint16_t sfn_sf) {
   static uint8_t first_time = 1;
+
   if (first_time) {
     printf("[VNF] subframe indication %d\n", NFAPI_SFNSF2DEC(sfn_sf));
     first_time = 0;
@@ -442,40 +408,33 @@ int phy_subframe_indication(struct nfapi_vnf_p7_config* config, uint16_t phy_id,
   if (RC.eNB && RC.eNB[0][0]->configured) {
     uint16_t sfn = NFAPI_SFNSF2SFN(sfn_sf);
     uint16_t sf = NFAPI_SFNSF2SF(sfn_sf);
-
     //LOG_D(PHY,"[VNF] subframe indication sfn_sf:%d sfn:%d sf:%d\n", sfn_sf, sfn, sf);
-
     wake_eNB_rxtx(RC.eNB[0][0], sfn, sf);
   } else {
     printf("[VNF] %s() RC.eNB:%p\n", __FUNCTION__, RC.eNB);
+
     if (RC.eNB) printf("RC.eNB[0][0]->configured:%d\n", RC.eNB[0][0]->configured);
   }
 
   return 0;
 }
 
-int phy_rach_indication(struct nfapi_vnf_p7_config* config, nfapi_rach_indication_t* ind) {
-
+int phy_rach_indication(struct nfapi_vnf_p7_config *config, nfapi_rach_indication_t *ind) {
   LOG_D(MAC, "%s() NFAPI SFN/SF:%d number_of_preambles:%u\n", __FUNCTION__, NFAPI_SFNSF2DEC(ind->sfn_sf), ind->rach_indication_body.number_of_preambles);
-
   struct PHY_VARS_eNB_s *eNB = RC.eNB[0][0];
-
   printf("[VNF] RACH_IND eNB:%p sfn_sf:%d number_of_preambles:%d\n", eNB, NFAPI_SFNSF2DEC(ind->sfn_sf), ind->rach_indication_body.number_of_preambles);
-
   pthread_mutex_lock(&eNB->UL_INFO_mutex);
-
   eNB->UL_INFO.rach_ind = *ind;
   eNB->UL_INFO.rach_ind.rach_indication_body.preamble_list = eNB->preamble_list;
 
-  for (int i=0;i<ind->rach_indication_body.number_of_preambles;i++) {
+  for (int i=0; i<ind->rach_indication_body.number_of_preambles; i++) {
     if (ind->rach_indication_body.preamble_list[i].preamble_rel8.tl.tag == NFAPI_PREAMBLE_REL8_TAG) {
-
-      printf("preamble[%d]: rnti:%02x preamble:%d timing_advance:%d\n", 
-          i,
-          ind->rach_indication_body.preamble_list[i].preamble_rel8.rnti,
-          ind->rach_indication_body.preamble_list[i].preamble_rel8.preamble,
-          ind->rach_indication_body.preamble_list[i].preamble_rel8.timing_advance
-          );
+      printf("preamble[%d]: rnti:%02x preamble:%d timing_advance:%d\n",
+             i,
+             ind->rach_indication_body.preamble_list[i].preamble_rel8.rnti,
+             ind->rach_indication_body.preamble_list[i].preamble_rel8.preamble,
+             ind->rach_indication_body.preamble_list[i].preamble_rel8.timing_advance
+            );
     }
 
     if(ind->rach_indication_body.preamble_list[i].preamble_rel13.tl.tag == NFAPI_PREAMBLE_REL13_TAG) {
@@ -484,21 +443,17 @@ int phy_rach_indication(struct nfapi_vnf_p7_config* config, nfapi_rach_indicatio
 
     eNB->preamble_list[i] = ind->rach_indication_body.preamble_list[i];
   }
-  pthread_mutex_unlock(&eNB->UL_INFO_mutex);
 
+  pthread_mutex_unlock(&eNB->UL_INFO_mutex);
   // vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data);
   //mac_rach_ind(p7_vnf->mac, ind);
   return 1;
 }
 
-int phy_harq_indication(struct nfapi_vnf_p7_config* config, nfapi_harq_indication_t* ind) {
-
+int phy_harq_indication(struct nfapi_vnf_p7_config *config, nfapi_harq_indication_t *ind) {
   struct PHY_VARS_eNB_s *eNB = RC.eNB[0][0];
-
   LOG_D(MAC, "%s() NFAPI SFN/SF:%d number_of_harqs:%u\n", __FUNCTION__, NFAPI_SFNSF2DEC(ind->sfn_sf), ind->harq_indication_body.number_of_harqs);
-
   pthread_mutex_lock(&eNB->UL_INFO_mutex);
-
   eNB->UL_INFO.harq_ind = *ind;
   eNB->UL_INFO.harq_ind.harq_indication_body.harq_pdu_list = eNB->harq_pdu_list;
 
@@ -507,51 +462,41 @@ int phy_harq_indication(struct nfapi_vnf_p7_config* config, nfapi_harq_indicatio
   }
 
   pthread_mutex_unlock(&eNB->UL_INFO_mutex);
-
   // vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data);
   //mac_harq_ind(p7_vnf->mac, ind);
-
   return 1;
 }
 
-int phy_crc_indication(struct nfapi_vnf_p7_config* config, nfapi_crc_indication_t* ind) {
-
+int phy_crc_indication(struct nfapi_vnf_p7_config *config, nfapi_crc_indication_t *ind) {
   struct PHY_VARS_eNB_s *eNB = RC.eNB[0][0];
-
   pthread_mutex_lock(&eNB->UL_INFO_mutex);
-
   eNB->UL_INFO.crc_ind = *ind;
-
   nfapi_crc_indication_t *dest_ind = &eNB->UL_INFO.crc_ind;
   nfapi_crc_indication_pdu_t *dest_pdu_list = eNB->crc_pdu_list;
-
   *dest_ind = *ind;
   dest_ind->crc_indication_body.crc_pdu_list = dest_pdu_list;
 
   if (ind->crc_indication_body.number_of_crcs==0)
-    LOG_D(MAC, "%s() NFAPI SFN/SF:%d IND:number_of_crcs:%u UL_INFO:crcs:%d\n", __FUNCTION__, NFAPI_SFNSF2DEC(ind->sfn_sf), ind->crc_indication_body.number_of_crcs, eNB->UL_INFO.crc_ind.crc_indication_body.number_of_crcs);
+    LOG_D(MAC, "%s() NFAPI SFN/SF:%d IND:number_of_crcs:%u UL_INFO:crcs:%d\n", __FUNCTION__, NFAPI_SFNSF2DEC(ind->sfn_sf), ind->crc_indication_body.number_of_crcs,
+          eNB->UL_INFO.crc_ind.crc_indication_body.number_of_crcs);
 
   for (int i=0; i<ind->crc_indication_body.number_of_crcs; i++) {
     memcpy(&dest_ind->crc_indication_body.crc_pdu_list[i], &ind->crc_indication_body.crc_pdu_list[i], sizeof(ind->crc_indication_body.crc_pdu_list[0]));
-
-    LOG_D(MAC, "%s() NFAPI SFN/SF:%d CRC_IND:number_of_crcs:%u UL_INFO:crcs:%d PDU[%d] rnti:%04x UL_INFO:rnti:%04x\n", 
-        __FUNCTION__,
-        NFAPI_SFNSF2DEC(ind->sfn_sf), ind->crc_indication_body.number_of_crcs, eNB->UL_INFO.crc_ind.crc_indication_body.number_of_crcs,
-        i, 
-        ind->crc_indication_body.crc_pdu_list[i].rx_ue_information.rnti, 
-        eNB->UL_INFO.crc_ind.crc_indication_body.crc_pdu_list[i].rx_ue_information.rnti);
+    LOG_D(MAC, "%s() NFAPI SFN/SF:%d CRC_IND:number_of_crcs:%u UL_INFO:crcs:%d PDU[%d] rnti:%04x UL_INFO:rnti:%04x\n",
+          __FUNCTION__,
+          NFAPI_SFNSF2DEC(ind->sfn_sf), ind->crc_indication_body.number_of_crcs, eNB->UL_INFO.crc_ind.crc_indication_body.number_of_crcs,
+          i,
+          ind->crc_indication_body.crc_pdu_list[i].rx_ue_information.rnti,
+          eNB->UL_INFO.crc_ind.crc_indication_body.crc_pdu_list[i].rx_ue_information.rnti);
   }
 
   pthread_mutex_unlock(&eNB->UL_INFO_mutex);
-
   // vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data);
   //mac_crc_ind(p7_vnf->mac, ind);
-
   return 1;
 }
 
-int phy_rx_indication(struct nfapi_vnf_p7_config* config, nfapi_rx_indication_t* ind) {
-
+int phy_rx_indication(struct nfapi_vnf_p7_config *config, nfapi_rx_indication_t *ind) {
   struct PHY_VARS_eNB_s *eNB = RC.eNB[0][0];
 
   if (ind->rx_indication_body.number_of_pdus==0) {
@@ -559,198 +504,170 @@ int phy_rx_indication(struct nfapi_vnf_p7_config* config, nfapi_rx_indication_t*
   }
 
   pthread_mutex_lock(&eNB->UL_INFO_mutex);
-
   nfapi_rx_indication_t *dest_ind = &eNB->UL_INFO.rx_ind;
   nfapi_rx_indication_pdu_t *dest_pdu_list = eNB->rx_pdu_list;
-
   *dest_ind = *ind;
   dest_ind->rx_indication_body.rx_pdu_list = dest_pdu_list;
 
   for(int i=0; i<ind->rx_indication_body.number_of_pdus; i++) {
     nfapi_rx_indication_pdu_t *dest_pdu = &dest_ind->rx_indication_body.rx_pdu_list[i];
     nfapi_rx_indication_pdu_t *src_pdu = &ind->rx_indication_body.rx_pdu_list[i];
-
     memcpy(dest_pdu, src_pdu, sizeof(*src_pdu));
-
     // DJP - TODO FIXME - intentional memory leak
     dest_pdu->data = malloc(dest_pdu->rx_indication_rel8.length);
-
     memcpy(dest_pdu->data, src_pdu->data, dest_pdu->rx_indication_rel8.length);
-
     LOG_D(PHY, "%s() NFAPI SFN/SF:%d PDUs:%d [PDU:%d] handle:%d rnti:%04x length:%d offset:%d ul_cqi:%d ta:%d data:%p\n",
-        __FUNCTION__,
-        NFAPI_SFNSF2DEC(ind->sfn_sf), ind->rx_indication_body.number_of_pdus, i,
-        dest_pdu->rx_ue_information.handle,
-        dest_pdu->rx_ue_information.rnti,
-        dest_pdu->rx_indication_rel8.length,
-        dest_pdu->rx_indication_rel8.offset,
-        dest_pdu->rx_indication_rel8.ul_cqi,
-        dest_pdu->rx_indication_rel8.timing_advance,
-        dest_pdu->data
-        );
+          __FUNCTION__,
+          NFAPI_SFNSF2DEC(ind->sfn_sf), ind->rx_indication_body.number_of_pdus, i,
+          dest_pdu->rx_ue_information.handle,
+          dest_pdu->rx_ue_information.rnti,
+          dest_pdu->rx_indication_rel8.length,
+          dest_pdu->rx_indication_rel8.offset,
+          dest_pdu->rx_indication_rel8.ul_cqi,
+          dest_pdu->rx_indication_rel8.timing_advance,
+          dest_pdu->data
+         );
   }
 
   pthread_mutex_unlock(&eNB->UL_INFO_mutex);
-
   // vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data);
   //mac_rx_ind(p7_vnf->mac, ind);
   return 1;
 }
-int phy_srs_indication(struct nfapi_vnf_p7_config* config, nfapi_srs_indication_t* ind) {
+int phy_srs_indication(struct nfapi_vnf_p7_config *config, nfapi_srs_indication_t *ind) {
   // vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data);
   //mac_srs_ind(p7_vnf->mac, ind);
   return 1;
 }
 
-int phy_sr_indication(struct nfapi_vnf_p7_config* config, nfapi_sr_indication_t* ind) {
-
+int phy_sr_indication(struct nfapi_vnf_p7_config *config, nfapi_sr_indication_t *ind) {
   struct PHY_VARS_eNB_s *eNB = RC.eNB[0][0];
-
   LOG_D(MAC, "%s() NFAPI SFN/SF:%d srs:%d\n", __FUNCTION__, NFAPI_SFNSF2DEC(ind->sfn_sf), ind->sr_indication_body.number_of_srs);
-
   pthread_mutex_lock(&eNB->UL_INFO_mutex);
-
   nfapi_sr_indication_t *dest_ind = &eNB->UL_INFO.sr_ind;
   nfapi_sr_indication_pdu_t *dest_pdu_list = eNB->sr_pdu_list;
-
   *dest_ind = *ind;
   dest_ind->sr_indication_body.sr_pdu_list = dest_pdu_list;
-
   LOG_D(MAC,"%s() eNB->UL_INFO.sr_ind.sr_indication_body.number_of_srs:%d\n", __FUNCTION__, eNB->UL_INFO.sr_ind.sr_indication_body.number_of_srs);
 
-  for (int i=0;i<eNB->UL_INFO.sr_ind.sr_indication_body.number_of_srs;i++) {
+  for (int i=0; i<eNB->UL_INFO.sr_ind.sr_indication_body.number_of_srs; i++) {
     nfapi_sr_indication_pdu_t *dest_pdu = &dest_ind->sr_indication_body.sr_pdu_list[i];
     nfapi_sr_indication_pdu_t *src_pdu = &ind->sr_indication_body.sr_pdu_list[i];
-
     LOG_D(MAC, "SR_IND[PDU:%d][rnti:%x cqi:%d channel:%d]\n", i, src_pdu->rx_ue_information.rnti, src_pdu->ul_cqi_information.ul_cqi, src_pdu->ul_cqi_information.channel);
-
     memcpy(dest_pdu, src_pdu, sizeof(*src_pdu));
   }
 
   pthread_mutex_unlock(&eNB->UL_INFO_mutex);
-
   // vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data);
   //mac_sr_ind(p7_vnf->mac, ind);
-
   return 1;
 }
 
-int phy_cqi_indication(struct nfapi_vnf_p7_config* config, nfapi_cqi_indication_t* ind) {
-
+int phy_cqi_indication(struct nfapi_vnf_p7_config *config, nfapi_cqi_indication_t *ind) {
   // vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data);
   //mac_cqi_ind(p7_vnf->mac, ind);
   struct PHY_VARS_eNB_s *eNB = RC.eNB[0][0];
-
   LOG_D(MAC, "%s() NFAPI SFN/SF:%d number_of_cqis:%u\n", __FUNCTION__, NFAPI_SFNSF2DEC(ind->sfn_sf), ind->cqi_indication_body.number_of_cqis);
-
   pthread_mutex_lock(&eNB->UL_INFO_mutex);
-
   eNB->UL_INFO.cqi_ind = ind->cqi_indication_body;
-
   pthread_mutex_unlock(&eNB->UL_INFO_mutex);
-
   return 1;
 }
 
-int phy_lbt_dl_indication(struct nfapi_vnf_p7_config* config, nfapi_lbt_dl_indication_t* ind) {
+int phy_lbt_dl_indication(struct nfapi_vnf_p7_config *config, nfapi_lbt_dl_indication_t *ind) {
   // vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data);
   //mac_lbt_dl_ind(p7_vnf->mac, ind);
   return 1;
 }
 
-int phy_nb_harq_indication(struct nfapi_vnf_p7_config* config, nfapi_nb_harq_indication_t* ind) {
+int phy_nb_harq_indication(struct nfapi_vnf_p7_config *config, nfapi_nb_harq_indication_t *ind) {
   // vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data);
   //mac_nb_harq_ind(p7_vnf->mac, ind);
   return 1;
 }
 
-int phy_nrach_indication(struct nfapi_vnf_p7_config* config, nfapi_nrach_indication_t* ind) {
+int phy_nrach_indication(struct nfapi_vnf_p7_config *config, nfapi_nrach_indication_t *ind) {
   // vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data);
   //mac_nrach_ind(p7_vnf->mac, ind);
   return 1;
 }
 
-void* vnf_allocate(size_t size) {
+void *vnf_allocate(size_t size) {
   //return (void*)memory_pool::allocate(size);
-  return (void*)malloc(size);
+  return (void *)malloc(size);
 }
 
-void vnf_deallocate(void* ptr) {
+void vnf_deallocate(void *ptr) {
   //memory_pool::deallocate((uint8_t*)ptr);
   free(ptr);
 }
 
 
-void vnf_trace(nfapi_trace_level_t nfapi_level, const char* message, ...) {
-
+void vnf_trace(nfapi_trace_level_t nfapi_level, const char *message, ...) {
   va_list args;
-
   va_start(args, message);
   nfapi_log("FILE>", "FUNC", 999, PHY, nfapitooai_level(nfapi_level), message, args);
   va_end(args);
 }
 
-int phy_vendor_ext(struct nfapi_vnf_p7_config* config, nfapi_p7_message_header_t* msg) {
-
-  if(msg->message_id == P7_VENDOR_EXT_IND)
-  {
+int phy_vendor_ext(struct nfapi_vnf_p7_config *config, nfapi_p7_message_header_t *msg) {
+  if(msg->message_id == P7_VENDOR_EXT_IND) {
     //vendor_ext_p7_ind* ind = (vendor_ext_p7_ind*)msg;
     //printf("[VNF] vendor_ext (error_code:%d)\n", ind->error_code);
-  }
-  else
-  {
+  } else {
     printf("[VNF] unknown %02x\n", msg->message_id);
   }
+
   return 0;
 }
 
-nfapi_p7_message_header_t* phy_allocate_p7_vendor_ext(uint16_t message_id, uint16_t* msg_size) {
-  if(message_id == P7_VENDOR_EXT_IND)
-  {
+nfapi_p7_message_header_t *phy_allocate_p7_vendor_ext(uint16_t message_id, uint16_t *msg_size) {
+  if(message_id == P7_VENDOR_EXT_IND) {
     *msg_size = sizeof(vendor_ext_p7_ind);
-    return (nfapi_p7_message_header_t*)malloc(sizeof(vendor_ext_p7_ind));
+    return (nfapi_p7_message_header_t *)malloc(sizeof(vendor_ext_p7_ind));
   }
+
   return 0;
 }
 
-void phy_deallocate_p7_vendor_ext(nfapi_p7_message_header_t* header) {
+void phy_deallocate_p7_vendor_ext(nfapi_p7_message_header_t *header) {
   free(header);
 }
 
-int phy_unpack_vendor_extension_tlv(nfapi_tl_t* tl, uint8_t **ppReadPackedMessage, uint8_t *end, void** ve, nfapi_p7_codec_config_t* codec) {
-
+int phy_unpack_vendor_extension_tlv(nfapi_tl_t *tl, uint8_t **ppReadPackedMessage, uint8_t *end, void **ve, nfapi_p7_codec_config_t *codec) {
   (void)tl;
   (void)ppReadPackedMessage;
   (void)ve;
   return -1;
 }
 
-int phy_pack_vendor_extension_tlv(void* ve, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t* codec) {
-
+int phy_pack_vendor_extension_tlv(void *ve, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *codec) {
   //NFAPI_TRACE(NFAPI_TRACE_INFO, "phy_pack_vendor_extension_tlv\n");
+  nfapi_tl_t *tlv = (nfapi_tl_t *)ve;
 
-  nfapi_tl_t* tlv = (nfapi_tl_t*)ve;
   switch(tlv->tag) {
-    case VENDOR_EXT_TLV_1_TAG:
-      {
-        //NFAPI_TRACE(NFAPI_TRACE_INFO, "Packing VENDOR_EXT_TLV_1\n");
-        vendor_ext_tlv_1* ve = (vendor_ext_tlv_1*)tlv;
-        if(!push32(ve->dummy, ppWritePackedMsg, end))
-          return 0;
-        return 1;
-      }
-      break;
+    case VENDOR_EXT_TLV_1_TAG: {
+      //NFAPI_TRACE(NFAPI_TRACE_INFO, "Packing VENDOR_EXT_TLV_1\n");
+      vendor_ext_tlv_1 *ve = (vendor_ext_tlv_1 *)tlv;
+
+      if(!push32(ve->dummy, ppWritePackedMsg, end))
+        return 0;
+
+      return 1;
+    }
+    break;
+
     default:
       return -1;
       break;
   }
 }
 
-int phy_unpack_p7_vendor_extension(nfapi_p7_message_header_t* header, uint8_t** ppReadPackedMessage, uint8_t *end, nfapi_p7_codec_config_t* config) {
-
+int phy_unpack_p7_vendor_extension(nfapi_p7_message_header_t *header, uint8_t **ppReadPackedMessage, uint8_t *end, nfapi_p7_codec_config_t *config) {
   //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__);
   if(header->message_id == P7_VENDOR_EXT_IND) {
-    vendor_ext_p7_ind* req = (vendor_ext_p7_ind*)(header);
+    vendor_ext_p7_ind *req = (vendor_ext_p7_ind *)(header);
+
     if(!pull16(ppReadPackedMessage, &req->error_code, end))
       return 0;
   }
@@ -758,54 +675,48 @@ int phy_unpack_p7_vendor_extension(nfapi_p7_message_header_t* header, uint8_t**
   return 1;
 }
 
-int phy_pack_p7_vendor_extension(nfapi_p7_message_header_t* header, uint8_t** ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t* config) {
+int phy_pack_p7_vendor_extension(nfapi_p7_message_header_t *header, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config) {
   //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__);
   if(header->message_id == P7_VENDOR_EXT_REQ) {
     //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__);
-    vendor_ext_p7_req* req = (vendor_ext_p7_req*)(header);
+    vendor_ext_p7_req *req = (vendor_ext_p7_req *)(header);
+
     if(!(push16(req->dummy1, ppWritePackedMsg, end) &&
-          push16(req->dummy2, ppWritePackedMsg, end)))
+         push16(req->dummy2, ppWritePackedMsg, end)))
       return 0;
   }
+
   return 1;
 }
 
-int vnf_pack_p4_p5_vendor_extension(nfapi_p4_p5_message_header_t* header, uint8_t** ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t* codec) {
-
+int vnf_pack_p4_p5_vendor_extension(nfapi_p4_p5_message_header_t *header, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *codec) {
   //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__);
   if(header->message_id == P5_VENDOR_EXT_REQ) {
-    vendor_ext_p5_req* req = (vendor_ext_p5_req*)(header);
+    vendor_ext_p5_req *req = (vendor_ext_p5_req *)(header);
     //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s %d %d\n", __FUNCTION__, req->dummy1, req->dummy2);
     return (!(push16(req->dummy1, ppWritePackedMsg, end) &&
-          push16(req->dummy2, ppWritePackedMsg, end)));
+              push16(req->dummy2, ppWritePackedMsg, end)));
   }
+
   return 0;
 }
 
 static pthread_t vnf_start_pthread;
 static pthread_t vnf_p7_start_pthread;
 
-void* vnf_p7_start_thread(void *ptr) {
-
+void *vnf_p7_start_thread(void *ptr) {
   printf("%s()\n", __FUNCTION__);
-
   pthread_setname_np(pthread_self(), "VNF_P7");
-
-  nfapi_vnf_p7_config_t* config = (nfapi_vnf_p7_config_t*)ptr;
-
+  nfapi_vnf_p7_config_t *config = (nfapi_vnf_p7_config_t *)ptr;
   nfapi_vnf_p7_start(config);
-
   return config;
 }
 
 void set_thread_priority(int priority);
 
-void* vnf_p7_thread_start(void* ptr) {
-
+void *vnf_p7_thread_start(void *ptr) {
   set_thread_priority(79);
-
-  vnf_p7_info* p7_vnf = (vnf_p7_info*)ptr;
-
+  vnf_p7_info *p7_vnf = (vnf_p7_info *)ptr;
   p7_vnf->config->port = p7_vnf->local_port;
   p7_vnf->config->sync_indication = &phy_sync_indication;
   p7_vnf->config->subframe_indication = &phy_subframe_indication;
@@ -821,117 +732,87 @@ void* vnf_p7_thread_start(void* ptr) {
   p7_vnf->config->nrach_indication = &phy_nrach_indication;
   p7_vnf->config->malloc = &vnf_allocate;
   p7_vnf->config->free = &vnf_deallocate;
-
   p7_vnf->config->trace = &vnf_trace;
-
   p7_vnf->config->vendor_ext = &phy_vendor_ext;
   p7_vnf->config->user_data = p7_vnf;
-
   p7_vnf->mac->user_data = p7_vnf;
-
   p7_vnf->config->codec_config.unpack_p7_vendor_extension = &phy_unpack_p7_vendor_extension;
   p7_vnf->config->codec_config.pack_p7_vendor_extension = &phy_pack_p7_vendor_extension;
   p7_vnf->config->codec_config.unpack_vendor_extension_tlv = &phy_unpack_vendor_extension_tlv;
   p7_vnf->config->codec_config.pack_vendor_extension_tlv = &phy_pack_vendor_extension_tlv;
   p7_vnf->config->codec_config.allocate = &vnf_allocate;
   p7_vnf->config->codec_config.deallocate = &vnf_deallocate;
-
   p7_vnf->config->allocate_p7_vendor_ext = &phy_allocate_p7_vendor_ext;
   p7_vnf->config->deallocate_p7_vendor_ext = &phy_deallocate_p7_vendor_ext;
-
   NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] Creating VNF NFAPI start thread %s\n", __FUNCTION__);
   pthread_create(&vnf_p7_start_pthread, NULL, &vnf_p7_start_thread, p7_vnf->config);
-
   return 0;
 }
 
-int pnf_start_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_pnf_start_response_t* resp) {
-
-  vnf_info* vnf = (vnf_info*)(config->user_data);
+int pnf_start_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_pnf_start_response_t *resp) {
+  vnf_info *vnf = (vnf_info *)(config->user_data);
   vnf_p7_info *p7_vnf = vnf->p7_vnfs;
   pnf_info *pnf = vnf->pnfs;
   nfapi_param_request_t req;
-
   printf("[VNF] pnf start response idx:%d config:%p user_data:%p p7_vnf[config:%p thread_started:%d]\n", p5_idx, config, config->user_data, vnf->p7_vnfs[0].config, vnf->p7_vnfs[0].thread_started);
 
   if(p7_vnf->thread_started == 0) {
-
     pthread_t vnf_p7_thread;
     pthread_create(&vnf_p7_thread, NULL, &vnf_p7_thread_start, p7_vnf);
     p7_vnf->thread_started = 1;
-  }
-  else
-  {
-    // P7 thread already running. 
+  } else {
+    // P7 thread already running.
   }
 
   // start all the phys in the pnf.
   printf("[VNF] Sending NFAPI_PARAM_REQUEST phy_id:%d\n", pnf->phys[0].id);
-
   memset(&req, 0, sizeof(req));
   req.header.message_id = NFAPI_PARAM_REQUEST;
   req.header.phy_id = pnf->phys[0].id;
-
   nfapi_vnf_param_req(config, p5_idx, &req);
-
   return 0;
 }
 
 extern uint32_t to_earfcn(int eutra_bandP,uint32_t dl_CarrierFreq,uint32_t bw);
 
-int param_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_param_response_t* resp) {
-
+int param_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_param_response_t *resp) {
   printf("[VNF] Received NFAPI_PARAM_RESP idx:%d phy_id:%d\n", p5_idx, resp->header.phy_id);
-
-  vnf_info* vnf = (vnf_info*)(config->user_data);
+  vnf_info *vnf = (vnf_info *)(config->user_data);
   vnf_p7_info *p7_vnf = vnf->p7_vnfs;
-
   pnf_info *pnf = vnf->pnfs;
   phy_info *phy = pnf->phys;
   struct sockaddr_in pnf_p7_sockaddr;
   nfapi_config_request_t *req = &RC.mac[0]->config[0];
-
   phy->remote_port = resp->nfapi_config.p7_pnf_port.value;
-
   memcpy(&pnf_p7_sockaddr.sin_addr.s_addr, &(resp->nfapi_config.p7_pnf_address_ipv4.address[0]), 4);
-
   phy->remote_addr = inet_ntoa(pnf_p7_sockaddr.sin_addr);
-
   // for now just 1
-
-  printf("[VNF] %d.%d pnf p7 %s:%d timing %d %d %d %d\n", p5_idx, phy->id, phy->remote_addr, phy->remote_port, p7_vnf->timing_window, p7_vnf->periodic_timing_period, p7_vnf->aperiodic_timing_enabled, p7_vnf->periodic_timing_period);
-
+  printf("[VNF] %d.%d pnf p7 %s:%d timing %u %u %u %u\n", p5_idx, phy->id, phy->remote_addr, phy->remote_port, p7_vnf->timing_window, p7_vnf->periodic_timing_period, p7_vnf->aperiodic_timing_enabled,
+         p7_vnf->periodic_timing_period);
   req->header.message_id = NFAPI_CONFIG_REQUEST;
   req->header.phy_id = phy->id;
-
   printf("[VNF] Send NFAPI_CONFIG_REQUEST\n");
-
   req->nfapi_config.p7_vnf_port.tl.tag = NFAPI_NFAPI_P7_VNF_PORT_TAG;
   req->nfapi_config.p7_vnf_port.value = p7_vnf->local_port;
   req->num_tlv++;
-
   printf("[VNF] DJP local_port:%d\n", p7_vnf->local_port);
-
   req->nfapi_config.p7_vnf_address_ipv4.tl.tag = NFAPI_NFAPI_P7_VNF_ADDRESS_IPV4_TAG;
   struct sockaddr_in vnf_p7_sockaddr;
   vnf_p7_sockaddr.sin_addr.s_addr = inet_addr(p7_vnf->local_addr);
   memcpy(&(req->nfapi_config.p7_vnf_address_ipv4.address[0]), &vnf_p7_sockaddr.sin_addr.s_addr, 4);
   req->num_tlv++;
   printf("[VNF] DJP local_addr:%s\n", p7_vnf->local_addr);
-
   req->nfapi_config.timing_window.tl.tag = NFAPI_NFAPI_TIMING_WINDOW_TAG;
   req->nfapi_config.timing_window.value = p7_vnf->timing_window;
-  printf("[VNF] Timing window:%d\n", p7_vnf->timing_window);
+  printf("[VNF] Timing window:%u\n", p7_vnf->timing_window);
   req->num_tlv++;
 
   if(p7_vnf->periodic_timing_enabled || p7_vnf->aperiodic_timing_enabled) {
-
     req->nfapi_config.timing_info_mode.tl.tag = NFAPI_NFAPI_TIMING_INFO_MODE_TAG;
     req->nfapi_config.timing_info_mode.value = (p7_vnf->aperiodic_timing_enabled << 1) | (p7_vnf->periodic_timing_enabled);
     req->num_tlv++;
 
     if(p7_vnf->periodic_timing_enabled) {
-
       req->nfapi_config.timing_info_period.tl.tag = NFAPI_NFAPI_TIMING_INFO_PERIOD_TAG;
       req->nfapi_config.timing_info_period.value = p7_vnf->periodic_timing_period;
       req->num_tlv++;
@@ -943,142 +824,110 @@ int param_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_param_response_t
   ve2.tl.tag = VENDOR_EXT_TLV_2_TAG;
   ve2.dummy = 2016;
   req->vendor_extension = &ve2.tl;
-
   nfapi_vnf_config_req(config, p5_idx, req);
   printf("[VNF] Sent NFAPI_CONFIG_REQ num_tlv:%u\n",req->num_tlv);
-
   return 0;
 }
 
-int config_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_config_response_t* resp) {
-
+int config_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_config_response_t *resp) {
   nfapi_start_request_t req;
-
   printf("[VNF] Received NFAPI_CONFIG_RESP idx:%d phy_id:%d\n", p5_idx, resp->header.phy_id);
-
   printf("[VNF] Calling oai_enb_init()\n");
   oai_enb_init();
-
   memset(&req, 0, sizeof(req));
   req.header.message_id = NFAPI_START_REQUEST;
   req.header.phy_id = resp->header.phy_id;
   nfapi_vnf_start_req(config, p5_idx, &req);
-
   printf("[VNF] Send NFAPI_START_REQUEST idx:%d phy_id:%d\n", p5_idx, resp->header.phy_id);
-
   return 0;
 }
 
-int start_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_start_response_t* resp) {
-
+int start_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_start_response_t *resp) {
   printf("[VNF] Received NFAPI_START_RESP idx:%d phy_id:%d\n", p5_idx, resp->header.phy_id);
-
-  vnf_info* vnf = (vnf_info*)(config->user_data);
-
+  vnf_info *vnf = (vnf_info *)(config->user_data);
   pnf_info *pnf = vnf->pnfs;
   phy_info *phy = pnf->phys;
   vnf_p7_info *p7_vnf = vnf->p7_vnfs;
   nfapi_vnf_p7_add_pnf((p7_vnf->config), phy->remote_addr, phy->remote_port, phy->id);
-
   return 0;
 }
 
-int vendor_ext_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_p4_p5_message_header_t* msg) {
-
+int vendor_ext_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_p4_p5_message_header_t *msg) {
   printf("[VNF] %s\n", __FUNCTION__);
 
   switch(msg->message_id) {
-    case P5_VENDOR_EXT_RSP:
-      {
-        vendor_ext_p5_rsp* rsp = (vendor_ext_p5_rsp*)msg;
-        printf("[VNF] P5_VENDOR_EXT_RSP error_code:%d\n", rsp->error_code);
-
-        // send the start request
-
-        nfapi_pnf_start_request_t req;
-        memset(&req, 0, sizeof(req));
-        req.header.message_id = NFAPI_PNF_START_REQUEST;
-        nfapi_vnf_pnf_start_req(config, p5_idx, &req);
-      }
-      break;
+    case P5_VENDOR_EXT_RSP: {
+      vendor_ext_p5_rsp *rsp = (vendor_ext_p5_rsp *)msg;
+      printf("[VNF] P5_VENDOR_EXT_RSP error_code:%d\n", rsp->error_code);
+      // send the start request
+      nfapi_pnf_start_request_t req;
+      memset(&req, 0, sizeof(req));
+      req.header.message_id = NFAPI_PNF_START_REQUEST;
+      nfapi_vnf_pnf_start_req(config, p5_idx, &req);
+    }
+    break;
   }
 
   return 0;
 }
 
-int vnf_unpack_p4_p5_vendor_extension(nfapi_p4_p5_message_header_t* header, uint8_t** ppReadPackedMessage, uint8_t *end, nfapi_p4_p5_codec_config_t* codec) {
-
+int vnf_unpack_p4_p5_vendor_extension(nfapi_p4_p5_message_header_t *header, uint8_t **ppReadPackedMessage, uint8_t *end, nfapi_p4_p5_codec_config_t *codec) {
   //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__);
-  if(header->message_id == P5_VENDOR_EXT_RSP)
-  {
-    vendor_ext_p5_rsp* req = (vendor_ext_p5_rsp*)(header);
+  if(header->message_id == P5_VENDOR_EXT_RSP) {
+    vendor_ext_p5_rsp *req = (vendor_ext_p5_rsp *)(header);
     return(!pull16(ppReadPackedMessage, &req->error_code, end));
   }
+
   return 0;
 }
 
-nfapi_p4_p5_message_header_t* vnf_allocate_p4_p5_vendor_ext(uint16_t message_id, uint16_t* msg_size) {
-
+nfapi_p4_p5_message_header_t *vnf_allocate_p4_p5_vendor_ext(uint16_t message_id, uint16_t *msg_size) {
   if(message_id == P5_VENDOR_EXT_RSP) {
     *msg_size = sizeof(vendor_ext_p5_rsp);
-    return (nfapi_p4_p5_message_header_t*)malloc(sizeof(vendor_ext_p5_rsp));
+    return (nfapi_p4_p5_message_header_t *)malloc(sizeof(vendor_ext_p5_rsp));
   }
+
   return 0;
 }
 
-void vnf_deallocate_p4_p5_vendor_ext(nfapi_p4_p5_message_header_t* header) {
+void vnf_deallocate_p4_p5_vendor_ext(nfapi_p4_p5_message_header_t *header) {
   free(header);
 }
 
 nfapi_vnf_config_t *config = 0;
 
-void vnf_start_thread(void* ptr) {
-
+void vnf_start_thread(void *ptr) {
   NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] VNF NFAPI thread - nfapi_vnf_start()%s\n", __FUNCTION__);
-
   pthread_setname_np(pthread_self(), "VNF");
-
-  config = (nfapi_vnf_config_t*)ptr;
-
+  config = (nfapi_vnf_config_t *)ptr;
   nfapi_vnf_start(config);
 }
 
 static vnf_info vnf;
 extern uint8_t nfapi_mode;
 /*------------------------------------------------------------------------------*/
-void configure_nfapi_vnf(char *vnf_addr, int vnf_p5_port)
-{
+void configure_nfapi_vnf(char *vnf_addr, int vnf_p5_port) {
   nfapi_mode = 2;
-
   memset(&vnf, 0, sizeof(vnf));
-
   memset(vnf.p7_vnfs, 0, sizeof(vnf.p7_vnfs));
-
   vnf.p7_vnfs[0].timing_window = 32;
   vnf.p7_vnfs[0].periodic_timing_enabled = 1;
   vnf.p7_vnfs[0].aperiodic_timing_enabled = 0;
   vnf.p7_vnfs[0].periodic_timing_period = 10;
-
   vnf.p7_vnfs[0].config = nfapi_vnf_p7_config_create();
   NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] %s() vnf.p7_vnfs[0].config:%p VNF ADDRESS:%s:%d\n", __FUNCTION__, vnf.p7_vnfs[0].config, vnf_addr, vnf_p5_port);
-
   strcpy(vnf.p7_vnfs[0].local_addr, vnf_addr);
   vnf.p7_vnfs[0].local_port = 50001;
-  vnf.p7_vnfs[0].mac = (mac_t*)malloc(sizeof(mac_t));
-
-  nfapi_vnf_config_t* config = nfapi_vnf_config_create();
-
+  vnf.p7_vnfs[0].mac = (mac_t *)malloc(sizeof(mac_t));
+  nfapi_vnf_config_t *config = nfapi_vnf_config_create();
   config->malloc = malloc;
   config->free = free;
   config->trace = &vnf_trace;
-
   config->vnf_p5_port = vnf_p5_port;
   config->vnf_ipv4 = 1;
   config->vnf_ipv6 = 0;
-
   config->pnf_list = 0;
   config->phy_list = 0;
-
   config->pnf_connection_indication = &pnf_connection_indication_cb;
   config->pnf_disconnect_indication = &pnf_disconnection_indication_cb;
   config->pnf_param_resp = &pnf_param_resp_cb;
@@ -1088,33 +937,26 @@ void configure_nfapi_vnf(char *vnf_addr, int vnf_p5_port)
   config->config_resp = &config_resp_cb;
   config->start_resp = &start_resp_cb;
   config->vendor_ext = &vendor_ext_cb;
-
   config->user_data = &vnf;
-
   // To allow custom vendor extentions to be added to nfapi
   config->codec_config.unpack_vendor_extension_tlv = &vnf_unpack_vendor_extension_tlv;
   config->codec_config.pack_vendor_extension_tlv = &vnf_pack_vendor_extension_tlv;
-
   config->codec_config.unpack_p4_p5_vendor_extension = &vnf_unpack_p4_p5_vendor_extension;
   config->codec_config.pack_p4_p5_vendor_extension = &vnf_pack_p4_p5_vendor_extension;
   config->allocate_p4_p5_vendor_ext = &vnf_allocate_p4_p5_vendor_ext;
   config->deallocate_p4_p5_vendor_ext = &vnf_deallocate_p4_p5_vendor_ext;
   config->codec_config.allocate = &vnf_allocate;
   config->codec_config.deallocate = &vnf_deallocate;
-
   NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] Creating VNF NFAPI start thread %s\n", __FUNCTION__);
-  pthread_create(&vnf_start_pthread, NULL, (void*)&vnf_start_thread, config);
+  pthread_create(&vnf_start_pthread, NULL, (void *)&vnf_start_thread, config);
   NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] Created VNF NFAPI start thread %s\n", __FUNCTION__);
 }
 
-int oai_nfapi_dl_config_req(nfapi_dl_config_request_t *dl_config_req)
-{
+int oai_nfapi_dl_config_req(nfapi_dl_config_request_t *dl_config_req) {
   nfapi_vnf_p7_config_t *p7_config = vnf.p7_vnfs[0].config;
-
   dl_config_req->header.phy_id = 1; // DJP HACK TODO FIXME - need to pass this around!!!!
-
+  dl_config_req->header.message_id = NFAPI_DL_CONFIG_REQUEST;
   int retval = nfapi_vnf_p7_dl_config_req(p7_config, dl_config_req);
-
   dl_config_req->dl_config_request_body.number_pdcch_ofdm_symbols           = 1;
   dl_config_req->dl_config_request_body.number_dci                          = 0;
   dl_config_req->dl_config_request_body.number_pdu                          = 0;
@@ -1123,35 +965,31 @@ int oai_nfapi_dl_config_req(nfapi_dl_config_request_t *dl_config_req)
   if (retval!=0) {
     LOG_E(PHY, "%s() Problem sending retval:%d\n", __FUNCTION__, retval);
   }
+
   return retval;
 }
 
-int oai_nfapi_tx_req(nfapi_tx_request_t *tx_req)
-{
+int oai_nfapi_tx_req(nfapi_tx_request_t *tx_req) {
   nfapi_vnf_p7_config_t *p7_config = vnf.p7_vnfs[0].config;
-
   tx_req->header.phy_id = 1; // DJP HACK TODO FIXME - need to pass this around!!!!
-
+  tx_req->header.message_id = NFAPI_TX_REQUEST;
   //LOG_D(PHY, "[VNF] %s() TX_REQ sfn_sf:%d number_of_pdus:%d\n", __FUNCTION__, NFAPI_SFNSF2DEC(tx_req->sfn_sf), tx_req->tx_request_body.number_of_pdus);
-
   int retval = nfapi_vnf_p7_tx_req(p7_config, tx_req);
 
-
   if (retval!=0) {
     LOG_E(PHY, "%s() Problem sending retval:%d\n", __FUNCTION__, retval);
   } else {
     tx_req->tx_request_body.number_of_pdus = 0;
   }
+
   return retval;
 }
 
 int oai_nfapi_hi_dci0_req(nfapi_hi_dci0_request_t *hi_dci0_req) {
   nfapi_vnf_p7_config_t *p7_config = vnf.p7_vnfs[0].config;
-
   hi_dci0_req->header.phy_id = 1; // DJP HACK TODO FIXME - need to pass this around!!!!
-
+  hi_dci0_req->header.message_id = NFAPI_HI_DCI0_REQUEST;
   //LOG_D(PHY, "[VNF] %s() HI_DCI0_REQ sfn_sf:%d dci:%d hi:%d\n", __FUNCTION__, NFAPI_SFNSF2DEC(hi_dci0_req->sfn_sf), hi_dci0_req->hi_dci0_request_body.number_of_dci, hi_dci0_req->hi_dci0_request_body.number_of_hi);
-
   int retval = nfapi_vnf_p7_hi_dci0_req(p7_config, hi_dci0_req);
 
   if (retval!=0) {
@@ -1160,19 +998,16 @@ int oai_nfapi_hi_dci0_req(nfapi_hi_dci0_request_t *hi_dci0_req) {
     hi_dci0_req->hi_dci0_request_body.number_of_hi = 0;
     hi_dci0_req->hi_dci0_request_body.number_of_dci = 0;
   }
+
   return retval;
 }
 
 int oai_nfapi_ul_config_req(nfapi_ul_config_request_t *ul_config_req) {
-
   nfapi_vnf_p7_config_t *p7_config = vnf.p7_vnfs[0].config;
-
   ul_config_req->header.phy_id = 1; // DJP HACK TODO FIXME - need to pass this around!!!!
-
+  ul_config_req->header.message_id = NFAPI_UL_CONFIG_REQUEST;
   //LOG_D(PHY, "[VNF] %s() header message_id:%02x\n", __FUNCTION__, ul_config_req->header.message_id);
-
   //LOG_D(PHY, "[VNF] %s() UL_CONFIG sfn_sf:%d PDUs:%d rach_prach_frequency_resources:%d srs_present:%d\n", __FUNCTION__, NFAPI_SFNSF2DEC(ul_config_req->sfn_sf), ul_config_req->ul_config_request_body.number_of_pdus, ul_config_req->ul_config_request_body.rach_prach_frequency_resources, ul_config_req->ul_config_request_body.srs_present);
-
   int retval = nfapi_vnf_p7_ul_config_req(p7_config, ul_config_req);
 
   if (retval!=0) {
@@ -1183,5 +1018,6 @@ int oai_nfapi_ul_config_req(nfapi_ul_config_request_t *ul_config_req) {
     ul_config_req->ul_config_request_body.rach_prach_frequency_resources = 0;
     ul_config_req->ul_config_request_body.srs_present = 0;
   }
+
   return retval;
 }
diff --git a/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c b/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c
index c180b5b0f9cfa24ae620950e19548d2b99387f3b..2daf1450c852c9bbb7b5ff1003e308903b494ba4 100644
--- a/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c
+++ b/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c
@@ -1545,7 +1545,7 @@ static uint8_t pack_tx_request_body_value(void* tlv, uint8_t **ppWritePackedMsg,
                         // DJP - if(pusharray8(pdu->segments[j].segment_data, (uint32_t)(-1), pdu->segments[j].segment_length, ppWritePackedMsg, end) == 0)
 			int push_ret = pusharray8(pdu->segments[j].segment_data, 65535, pdu->segments[j].segment_length, ppWritePackedMsg, end);
                         
-                        if (0 && pdu->segments[j].segment_length == 3)
+                        if (pdu->segments[j].segment_length == 3)
                         {
                           NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() BCH? segment_data:%x %x %x\n", __FUNCTION__, 
                           pdu->segments[j].segment_data[0], 
@@ -4429,40 +4429,43 @@ static uint8_t unpack_tx_request(uint8_t **ppReadPackedMsg, uint8_t *end, void *
 				for(i = 0; i < totalNumPdus; ++i)
 				{
 					nfapi_tx_request_pdu_t* pdu = &(pNfapiMsg->tx_request_body.tx_pdu_list[i]);
+					if (pdu) {
+					  uint16_t length = 0;
+					  uint16_t index = 0;
 					
-					uint16_t length = 0;
-					uint16_t index = 0;
-					
-					if(!(pull16(ppReadPackedMsg, &length, end) &&
+					  if(!(pull16(ppReadPackedMsg, &length, end) &&
 						 pull16(ppReadPackedMsg, &index, end)))
-						return 0;
+						  return 0;
 
-					pdu->pdu_length = length;
-					pdu->pdu_index = index;
+                                          pdu->pdu_length = length;
+                                          pdu->pdu_index = index;
 					
 
 					// TODO : May need to rethink this bit
-					pdu->num_segments = 1;
-					pdu->segments[0].segment_length = pdu->pdu_length;
-					pdu->segments[0].segment_data = nfapi_p7_allocate(pdu->pdu_length, config);
+					  pdu->num_segments = 1;
+					  pdu->segments[0].segment_length = pdu->pdu_length;
+					  pdu->segments[0].segment_data = nfapi_p7_allocate(pdu->pdu_length, config);
 
-					if(pdu->segments[0].segment_data)
-					{
-						if(!pullarray8(ppReadPackedMsg, pdu->segments[0].segment_data, pdu->segments[0].segment_length, pdu->segments[0].segment_length, end))
+					  if(pdu->segments[0].segment_data)
+					  {
+						  if(!pullarray8(ppReadPackedMsg, pdu->segments[0].segment_data, pdu->segments[0].segment_length, pdu->segments[0].segment_length, end))
 							return 0;
-                                                if (0 && pdu->segments[0].segment_length == 3)
-                                                {
+                                                  if (pdu->segments[0].segment_length == 3)
+                                                  {
                                                   NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() BCH? segment_data:%x %x %x\n", __FUNCTION__, 
                                                       pdu->segments[0].segment_data[0], 
                                                       pdu->segments[0].segment_data[1], 
                                                       pdu->segments[0].segment_data[2]
                                                       );
-                                                }
-					}
-					else
-					{
+                                                  }
+					  }
+					  else
+					  {
 						NFAPI_TRACE(NFAPI_TRACE_ERROR, "unpack_tx_request: Failed to allocate pdu (len:%d) %d/%d %d\n", pdu->pdu_length, totalNumPdus, i, pdu->pdu_index);
-					}
+					  }
+                                      } else {
+                                          NFAPI_TRACE(NFAPI_TRACE_ERROR, "NULL pdu\n");
+                                      }
 				}
 			}
 			break;
diff --git a/nfapi/open-nFAPI/pnf/src/pnf.c b/nfapi/open-nFAPI/pnf/src/pnf.c
index d0a7fa6fd12140dd38ab66c1f866ec8d9abe3d09..eec9ff80c38a98f0425c4a3d8d30b433f6a974b7 100644
--- a/nfapi/open-nFAPI/pnf/src/pnf.c
+++ b/nfapi/open-nFAPI/pnf/src/pnf.c
@@ -1237,11 +1237,11 @@ int pnf_connect(pnf_t* pnf)
 	}
 
 	struct addrinfo *p = servinfo;
-	int i = 0;
 	int connected = 0;
 
 	while(p != NULL && connected == 0)
 	{
+#ifdef NFAPI_TRACE_ENABLED
 		char* family = "Unknown";
 		char* address = "Unknown";
 		char _addr[128];
@@ -1261,6 +1261,7 @@ int pnf_connect(pnf_t* pnf)
 		}
 
 		NFAPI_TRACE(NFAPI_TRACE_NOTE, "Host address info  %d Family:%s Address:%s\n", i++, family, address);
+#endif
 
 		if (pnf->sctp)
 		{
diff --git a/nfapi/open-nFAPI/pnf/src/pnf_p7.c b/nfapi/open-nFAPI/pnf/src/pnf_p7.c
index 8d94c23476b1f77f1e7c8a9610d109204a013f7b..81abed81a95b27935df7b19bb21ddb8b5c25f97d 100644
--- a/nfapi/open-nFAPI/pnf/src/pnf_p7.c
+++ b/nfapi/open-nFAPI/pnf/src/pnf_p7.c
@@ -379,7 +379,7 @@ static uint32_t get_sf_time(uint32_t now_hr, uint32_t sf_start_hr)
 {
 	if(now_hr < sf_start_hr)
 	{
-		NFAPI_TRACE(NFAPI_TRACE_INFO, "now is earlier than start of subframe now_hr:%u sf_start_hr:%u\n", now_hr, sf_start_hr);
+		//NFAPI_TRACE(NFAPI_TRACE_INFO, "now is earlier than start of subframe now_hr:%u sf_start_hr:%u\n", now_hr, sf_start_hr);
 		return 0;
 	}
 	else
diff --git a/nfapi/open-nFAPI/pnf_sim/src/fapi_stub.cpp b/nfapi/open-nFAPI/pnf_sim/src/fapi_stub.cpp
index df0ca12305f6ca954c9f02f1874e31c46637022e..1c2f0bef8078a072d7abd9eab6de65cbe3b5568d 100644
--- a/nfapi/open-nFAPI/pnf_sim/src/fapi_stub.cpp
+++ b/nfapi/open-nFAPI/pnf_sim/src/fapi_stub.cpp
@@ -1,12 +1,12 @@
 /*
  * Copyright 2017 Cisco Systems, Inc.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * 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.
@@ -34,609 +34,510 @@
 #include <queue>
 #include <list>
 
-struct phy_pdu
-{
-	phy_pdu() : buffer_len(1500), buffer(0), len(0)
-	{
-		buffer = (char*) malloc(buffer_len);
-	}
-	
-	virtual ~phy_pdu()
-	{
-		free(buffer);
-	}
-
-
-	unsigned buffer_len;
-	char* buffer;
-	unsigned len;
+struct phy_pdu {
+  phy_pdu() : buffer_len(1500), buffer(0), len(0) {
+    buffer = (char *) malloc(buffer_len);
+  }
+
+  virtual ~phy_pdu() {
+    free(buffer);
+  }
+
+
+  unsigned buffer_len;
+  char *buffer;
+  unsigned len;
 };
 
-class fapi_private 
-{
-		std::mutex mutex;
-		std::queue<phy_pdu*> rx_buffer;
-
-		std::queue<phy_pdu*> free_store;
-	public:
-
-		fapi_private()
-			: byte_count(0), tick(0), first_dl_config(false)
-		{
-		}
-
-		phy_pdu* allocate_phy_pdu()
-		{
-			phy_pdu* pdu = 0;
-			mutex.lock();
-			if(free_store.empty())
-			{
-				pdu = new phy_pdu();
-			}
-			else
-			{
-				pdu = free_store.front();
-				free_store.pop();
-			}
-			mutex.unlock();
-			return pdu;
-		}
-
-		void release_phy_pdu(phy_pdu* pdu)
-		{
-			mutex.lock();
-			free_store.push(pdu);
-			mutex.unlock();
-		}
-
-		bool rx_buffer_empty()
-		{
-			bool empty;
-			mutex.lock();
-			empty = rx_buffer.empty();
-			mutex.unlock();
-
-			return empty;
-		}
-		
-
-		void push_rx_buffer(phy_pdu* buff)
-		{
-			mutex.lock();
-			rx_buffer.push(buff);
-			mutex.unlock();
-		}
-
-		phy_pdu* pop_rx_buffer()
-		{
-			phy_pdu* buff = 0;
-			mutex.lock();
-			if(!rx_buffer.empty())
-			{
-				buff = rx_buffer.front();
-				rx_buffer.pop();
-			}
-			mutex.unlock();
-			return buff;
-		}
-
-		uint32_t byte_count;
-		uint32_t tick;
-		bool first_dl_config;
+class fapi_private {
+  std::mutex mutex;
+  std::queue<phy_pdu *> rx_buffer;
+
+  std::queue<phy_pdu *> free_store;
+ public:
+
+  fapi_private()
+    : byte_count(0), tick(0), first_dl_config(false) {
+  }
+
+  phy_pdu *allocate_phy_pdu() {
+    phy_pdu *pdu = 0;
+    mutex.lock();
+
+    if(free_store.empty()) {
+      pdu = new phy_pdu();
+    } else {
+      pdu = free_store.front();
+      free_store.pop();
+    }
+
+    mutex.unlock();
+    return pdu;
+  }
+
+  void release_phy_pdu(phy_pdu *pdu) {
+    mutex.lock();
+    free_store.push(pdu);
+    mutex.unlock();
+  }
+
+  bool rx_buffer_empty() {
+    bool empty;
+    mutex.lock();
+    empty = rx_buffer.empty();
+    mutex.unlock();
+    return empty;
+  }
+
+
+  void push_rx_buffer(phy_pdu *buff) {
+    mutex.lock();
+    rx_buffer.push(buff);
+    mutex.unlock();
+  }
+
+  phy_pdu *pop_rx_buffer() {
+    phy_pdu *buff = 0;
+    mutex.lock();
+
+    if(!rx_buffer.empty()) {
+      buff = rx_buffer.front();
+      rx_buffer.pop();
+    }
+
+    mutex.unlock();
+    return buff;
+  }
+
+  uint32_t byte_count;
+  uint32_t tick;
+  bool first_dl_config;
 
 };
 
 extern "C"
 {
-	typedef struct fapi_internal
-	{
-		fapi_t _public;
+  typedef struct fapi_internal {
+    fapi_t _public;
 
-		fapi_cb_t callbacks;
+    fapi_cb_t callbacks;
 
-		uint8_t state;
-		fapi_config_t config;
+    uint8_t state;
+    fapi_config_t config;
 
-		int rx_sock;
-		int tx_sock;
-		struct sockaddr_in tx_addr;
+    int rx_sock;
+    int tx_sock;
+    struct sockaddr_in tx_addr;
 
-		uint32_t tx_byte_count;
-		uint32_t tick;
-		
-		fapi_private* fapi;
+    uint32_t tx_byte_count;
+    uint32_t tick;
 
-	} fapi_internal_t;
+    fapi_private *fapi;
+
+  } fapi_internal_t;
 }
 
 extern void set_thread_priority(int);
 /*
 {
-	pthread_attr_t ptAttr;
-	
-	struct sched_param schedParam;
-	schedParam.__sched_priority = 79;
-	sched_setscheduler(0, SCHED_RR, &schedParam);
+  pthread_attr_t ptAttr;
+
+  struct sched_param schedParam;
+  schedParam.__sched_priority = 79;
+  sched_setscheduler(0, SCHED_RR, &schedParam);
 
-	pthread_attr_setschedpolicy(&ptAttr, SCHED_RR);
+  pthread_attr_setschedpolicy(&ptAttr, SCHED_RR);
 
-	pthread_attr_setinheritsched(&ptAttr, PTHREAD_EXPLICIT_SCHED);
+  pthread_attr_setinheritsched(&ptAttr, PTHREAD_EXPLICIT_SCHED);
 
-	struct sched_param thread_params;
-	thread_params.sched_priority = 20;
-	pthread_attr_setschedparam(&ptAttr, &thread_params);
+  struct sched_param thread_params;
+  thread_params.sched_priority = 20;
+  pthread_attr_setschedparam(&ptAttr, &thread_params);
 }
 */
 
-void send_uplink_indications(fapi_internal_t* instance, uint16_t sfn_sf)
-{
-	fapi_harq_ind_t harq_ind;
-	(instance->callbacks.fapi_harq_ind)(&(instance->_public), &harq_ind);
-
-	fapi_crc_ind_t crc_ind;
-	crc_ind.header.message_id = FAPI_CRC_INDICATION;
-	crc_ind.header.length = 0; //??;
-	crc_ind.sfn_sf = sfn_sf;
-	crc_ind.body.number_of_crcs = 1;
-	crc_ind.body.pdus[0].rx_ue_info.handle = 0; //??
-	crc_ind.body.pdus[0].rx_ue_info.rnti = 0; //??
-	crc_ind.body.pdus[0].rel8_pdu.crc_flag = 1;
-
-	(instance->callbacks.fapi_crc_ind)(&(instance->_public), &crc_ind);
-
-	if(!instance->fapi->rx_buffer_empty())
-	{
-		fapi_rx_ulsch_ind_t rx_ind;
-		memset(&rx_ind, 0, sizeof(rx_ind));
-		rx_ind.header.message_id = FAPI_RX_ULSCH_INDICATION;
-		rx_ind.sfn_sf = sfn_sf;
-
-
-		phy_pdu* buff = 0;
-		int i = 0;
-		std::list<phy_pdu*> free_list;
-		do
-		{
-			buff = instance->fapi->pop_rx_buffer();
-			if(buff != 0)
-			{
-				if(buff->len == 0)
-				{
-					printf("[FAPI] Buffer length = 0\n");
-				}
-
-				rx_ind.body.pdus[i].rx_ue_info.handle = 0xDEADBEEF;
-				rx_ind.body.pdus[i].rx_ue_info.rnti = 0x4242;
-
-				rx_ind.body.pdus[i].rel8_pdu.length = buff->len;
-				//rx_ind.pdus[i].rel8_pdu.data_offset;
-				//rx_ind.pdus[i].rel8_pdu.ul_cqi;
-				//rx_ind.pdus[i].rel8_pdu.timing_advance;
-
-				rx_ind.body.data[i] = buff->buffer;
-
-				rx_ind.body.number_of_pdus++;
-				i++;
-
-				instance->fapi->byte_count += buff->len;
-
-				free_list.push_back(buff);
-			}
-		}while(buff != 0 && i < 8);
-
-		(instance->callbacks.fapi_rx_ulsch_ind)(&(instance->_public), &rx_ind);
-
-		for(phy_pdu* pdu : free_list)
-		{
-			instance->fapi->release_phy_pdu(pdu);
-			//free(tx_req.tx_request_body.tx_pdu_list[j].segments[0].segment_data);
-		}
-	}
-	else
-	{
-		fapi_rx_ulsch_ind_t rx_ind;
-		memset(&rx_ind, 0, sizeof(rx_ind));
-		rx_ind.header.message_id = FAPI_RX_ULSCH_INDICATION;
-		rx_ind.sfn_sf = sfn_sf;
-		(instance->callbacks.fapi_rx_ulsch_ind)(&(instance->_public), &rx_ind);
-	}
-
-	
-	fapi_rx_cqi_ind_t cqi_ind;
-	cqi_ind.sfn_sf = sfn_sf;
-	(instance->callbacks.fapi_rx_cqi_ind)(&(instance->_public), &cqi_ind);
-
-	fapi_rx_sr_ind_t sr_ind;
-	sr_ind.sfn_sf = sfn_sf;
-	(instance->callbacks.fapi_rx_sr_ind)(&(instance->_public), &sr_ind);
-
-	fapi_rach_ind_t rach_ind;
-	rach_ind.sfn_sf = sfn_sf;
-	(instance->callbacks.fapi_rach_ind)(&(instance->_public), &rach_ind);
-
-	fapi_srs_ind_t srs_ind;
-	srs_ind.sfn_sf = sfn_sf;
-	(instance->callbacks.fapi_srs_ind)(&(instance->_public), &srs_ind);
-	/*
-	nfapi_lbt_dl_indication_t lbt_ind;
-	memset(&lbt_ind, 0, sizeof(lbt_ind));
-	lbt_ind.header.message_id = NFAPI_LBT_DL_INDICATION;
-	lbt_ind.header.phy_id = config->phy_id;
-	lbt_ind.sfn_sf = sfn_sf;
-	nfapi_pnf_p7_lbt_dl_ind(config, &lbt_ind);
-
-	vendor_ext_p7_ind ve_p7_ind;
-	memset(&ve_p7_ind, 0, sizeof(ve_p7_ind));
-	ve_p7_ind.header.message_id = P7_VENDOR_EXT_IND;
-	ve_p7_ind.header.phy_id = config->phy_id;
-	ve_p7_ind.error_code = NFAPI_MSG_OK;
-	nfapi_pnf_p7_vendor_extension(config, &(ve_p7_ind.header));
-	*/
-	
-	fapi_nb_harq_ind_t nb_harq_ind;
-	nb_harq_ind.sfn_sf = sfn_sf;
-	(instance->callbacks.fapi_nb_harq_ind)(&(instance->_public), &nb_harq_ind);
-
-	fapi_nrach_ind_t nrach_ind;
-	nrach_ind.sfn_sf = sfn_sf;
-	(instance->callbacks.fapi_nrach_ind)(&(instance->_public), &nrach_ind);
-
+void send_uplink_indications(fapi_internal_t *instance, uint16_t sfn_sf) {
+  fapi_harq_ind_t harq_ind;
+  (instance->callbacks.fapi_harq_ind)(&(instance->_public), &harq_ind);
+  fapi_crc_ind_t crc_ind;
+  crc_ind.header.message_id = FAPI_CRC_INDICATION;
+  crc_ind.header.length = 0; //??;
+  crc_ind.sfn_sf = sfn_sf;
+  crc_ind.body.number_of_crcs = 1;
+  crc_ind.body.pdus[0].rx_ue_info.handle = 0; //??
+  crc_ind.body.pdus[0].rx_ue_info.rnti = 0; //??
+  crc_ind.body.pdus[0].rel8_pdu.crc_flag = 1;
+  (instance->callbacks.fapi_crc_ind)(&(instance->_public), &crc_ind);
+
+  if(!instance->fapi->rx_buffer_empty()) {
+    fapi_rx_ulsch_ind_t rx_ind;
+    memset(&rx_ind, 0, sizeof(rx_ind));
+    rx_ind.header.message_id = FAPI_RX_ULSCH_INDICATION;
+    rx_ind.sfn_sf = sfn_sf;
+    phy_pdu *buff = 0;
+    int i = 0;
+    std::list<phy_pdu *> free_list;
+
+    do {
+      buff = instance->fapi->pop_rx_buffer();
+
+      if(buff != 0) {
+        if(buff->len == 0) {
+          printf("[FAPI] Buffer length = 0\n");
+        }
+
+        rx_ind.body.pdus[i].rx_ue_info.handle = 0xDEADBEEF;
+        rx_ind.body.pdus[i].rx_ue_info.rnti = 0x4242;
+        rx_ind.body.pdus[i].rel8_pdu.length = buff->len;
+        //rx_ind.pdus[i].rel8_pdu.data_offset;
+        //rx_ind.pdus[i].rel8_pdu.ul_cqi;
+        //rx_ind.pdus[i].rel8_pdu.timing_advance;
+        rx_ind.body.data[i] = buff->buffer;
+        rx_ind.body.number_of_pdus++;
+        i++;
+        instance->fapi->byte_count += buff->len;
+        free_list.push_back(buff);
+      }
+    } while(buff != 0 && i < 8);
+
+    (instance->callbacks.fapi_rx_ulsch_ind)(&(instance->_public), &rx_ind);
+
+    for(phy_pdu *pdu : free_list) {
+      instance->fapi->release_phy_pdu(pdu);
+      //free(tx_req.tx_request_body.tx_pdu_list[j].segments[0].segment_data);
+    }
+  } else {
+    fapi_rx_ulsch_ind_t rx_ind;
+    memset(&rx_ind, 0, sizeof(rx_ind));
+    rx_ind.header.message_id = FAPI_RX_ULSCH_INDICATION;
+    rx_ind.sfn_sf = sfn_sf;
+    (instance->callbacks.fapi_rx_ulsch_ind)(&(instance->_public), &rx_ind);
+  }
+
+  fapi_rx_cqi_ind_t cqi_ind;
+  cqi_ind.sfn_sf = sfn_sf;
+  (instance->callbacks.fapi_rx_cqi_ind)(&(instance->_public), &cqi_ind);
+  fapi_rx_sr_ind_t sr_ind;
+  sr_ind.sfn_sf = sfn_sf;
+  (instance->callbacks.fapi_rx_sr_ind)(&(instance->_public), &sr_ind);
+  fapi_rach_ind_t rach_ind;
+  rach_ind.sfn_sf = sfn_sf;
+  (instance->callbacks.fapi_rach_ind)(&(instance->_public), &rach_ind);
+  fapi_srs_ind_t srs_ind;
+  srs_ind.sfn_sf = sfn_sf;
+  (instance->callbacks.fapi_srs_ind)(&(instance->_public), &srs_ind);
+  /*
+  nfapi_lbt_dl_indication_t lbt_ind;
+  memset(&lbt_ind, 0, sizeof(lbt_ind));
+  lbt_ind.header.message_id = NFAPI_LBT_DL_INDICATION;
+  lbt_ind.header.phy_id = config->phy_id;
+  lbt_ind.sfn_sf = sfn_sf;
+  nfapi_pnf_p7_lbt_dl_ind(config, &lbt_ind);
+
+  vendor_ext_p7_ind ve_p7_ind;
+  memset(&ve_p7_ind, 0, sizeof(ve_p7_ind));
+  ve_p7_ind.header.message_id = P7_VENDOR_EXT_IND;
+  ve_p7_ind.header.phy_id = config->phy_id;
+  ve_p7_ind.error_code = NFAPI_MSG_OK;
+  nfapi_pnf_p7_vendor_extension(config, &(ve_p7_ind.header));
+  */
+  fapi_nb_harq_ind_t nb_harq_ind;
+  nb_harq_ind.sfn_sf = sfn_sf;
+  (instance->callbacks.fapi_nb_harq_ind)(&(instance->_public), &nb_harq_ind);
+  fapi_nrach_ind_t nrach_ind;
+  nrach_ind.sfn_sf = sfn_sf;
+  (instance->callbacks.fapi_nrach_ind)(&(instance->_public), &nrach_ind);
 }
 
-void* fapi_thread_start(void* ptr)
-{
-	set_thread_priority(81);
-
-	fapi_internal_t* instance = (fapi_internal_t*)ptr;
-	uint16_t sfn_sf_dec = 0;
-	uint32_t last_tv_usec = 0;
-	uint32_t last_tv_sec = 0;
-
-	uint32_t millisec;
-	uint32_t last_millisec = -1;
-	uint16_t catchup = 0;
-
-	while(1)
-	{
-		// get the time
-		struct timeval sf_start;
-		(void)gettimeofday(&sf_start, NULL);
-		
-		uint16_t sfn_sf = ((((sfn_sf_dec) / 10) << 4) | (((sfn_sf_dec) - (((sfn_sf_dec) / 10) * 10)) & 0xF));
-		// increment the sfn/sf - for the next subframe
-		sfn_sf_dec++;
-		if(sfn_sf_dec > 10239)
-			sfn_sf_dec = 0;
-
-	
-		fapi_subframe_ind_t ind;
-		ind.sfn_sf = sfn_sf;
-
-		if(instance->fapi->first_dl_config)
-			send_uplink_indications(instance, sfn_sf);
-
-		if(instance->tick == 1000)
-		{
-			if(instance->tx_byte_count > 0)
-			{
-				printf("[FAPI] Tx rate %d bytes/sec\n", instance->tx_byte_count);
-				instance->tx_byte_count = 0;
-			}
-			
-			instance->tick = 0;
-		}
-
-		instance->tick++;
-
-		(instance->callbacks.fapi_subframe_ind)(&(instance->_public), &ind);
-
-		{
-			phy_pdu* pdu = instance->fapi->allocate_phy_pdu();
-			int len = recvfrom(instance->rx_sock, pdu->buffer, pdu->buffer_len, MSG_DONTWAIT, 0, 0);
-			if(len > 0)
-			{
-				pdu->len = len;
-				instance->fapi->push_rx_buffer(pdu);
-			}
-			else
-			{
-				instance->fapi->release_phy_pdu(pdu);
-			}
-		}
-		
-
-		if(catchup)
-		{
-			catchup--;
-		}
-		else
-		{
-			struct timespec now_ts;
-			struct timespec sleep_ts;
-			struct timespec sleep_rem_ts;
-
-			// get the current time
-			clock_gettime(CLOCK_MONOTONIC, &now_ts);
-
-
-			// determine how long to sleep before the start of the next 1ms
-			sleep_ts.tv_sec = 0;
-			sleep_ts.tv_nsec = 1e6 - (now_ts.tv_nsec % 1000000);
-
-			int nanosleep_result = nanosleep(&sleep_ts, &sleep_rem_ts);
-
-			if(nanosleep_result != 0)
-				printf("*** nanosleep failed or was interrupted\n");
-
-
-			clock_gettime(CLOCK_MONOTONIC, &now_ts);
-			millisec = now_ts.tv_nsec / 1e6;
-
-			if(last_millisec != -1 && ((last_millisec + 1 ) % 1000) != millisec)
-			{
-				printf("*** missing millisec %d %d\n", last_millisec, millisec);
-				catchup = millisec - last_millisec - 1;
-			}
-
-			last_millisec = millisec;
-		}
-	}
+void *fapi_thread_start(void *ptr) {
+  set_thread_priority(81);
+  fapi_internal_t *instance = (fapi_internal_t *)ptr;
+  uint16_t sfn_sf_dec = 0;
+  uint32_t last_tv_usec = 0;
+  uint32_t last_tv_sec = 0;
+  uint32_t millisec;
+  uint32_t last_millisec = -1;
+  uint16_t catchup = 0;
+
+  while(1) {
+    // get the time
+    struct timeval sf_start;
+    (void)gettimeofday(&sf_start, NULL);
+    uint16_t sfn_sf = ((((sfn_sf_dec) / 10) << 4) | (((sfn_sf_dec) - (((sfn_sf_dec) / 10) * 10)) & 0xF));
+    // increment the sfn/sf - for the next subframe
+    sfn_sf_dec++;
+
+    if(sfn_sf_dec > 10239)
+      sfn_sf_dec = 0;
+
+    fapi_subframe_ind_t ind;
+    ind.sfn_sf = sfn_sf;
+
+    if(instance->fapi->first_dl_config)
+      send_uplink_indications(instance, sfn_sf);
+
+    if(instance->tick == 1000) {
+      if(instance->tx_byte_count > 0) {
+        printf("[FAPI] Tx rate %d bytes/sec\n", instance->tx_byte_count);
+        instance->tx_byte_count = 0;
+      }
+
+      instance->tick = 0;
+    }
+
+    instance->tick++;
+    (instance->callbacks.fapi_subframe_ind)(&(instance->_public), &ind);
+    {
+      phy_pdu *pdu = instance->fapi->allocate_phy_pdu();
+      int len = recvfrom(instance->rx_sock, pdu->buffer, pdu->buffer_len, MSG_DONTWAIT, 0, 0);
+
+      if(len > 0) {
+        pdu->len = len;
+        instance->fapi->push_rx_buffer(pdu);
+      } else {
+        instance->fapi->release_phy_pdu(pdu);
+      }
+    }
+
+    if(catchup) {
+      catchup--;
+    } else {
+      struct timespec now_ts;
+      struct timespec sleep_ts;
+      struct timespec sleep_rem_ts;
+      // get the current time
+      clock_gettime(CLOCK_MONOTONIC, &now_ts);
+      // determine how long to sleep before the start of the next 1ms
+      sleep_ts.tv_sec = 0;
+      sleep_ts.tv_nsec = 1e6 - (now_ts.tv_nsec % 1000000);
+      int nanosleep_result = nanosleep(&sleep_ts, &sleep_rem_ts);
+
+      if(nanosleep_result != 0)
+        printf("*** nanosleep failed or was interrupted\n");
+
+      clock_gettime(CLOCK_MONOTONIC, &now_ts);
+      millisec = now_ts.tv_nsec / 1e6;
+
+      if(last_millisec != -1 && ((last_millisec + 1 ) % 1000) != millisec) {
+        printf("*** missing millisec %d %d\n", last_millisec, millisec);
+        catchup = millisec - last_millisec - 1;
+      }
+
+      last_millisec = millisec;
+    }
+  }
 }
 
 extern "C"
 {
-	fapi_t* fapi_create(fapi_cb_t* callbacks, fapi_config_t* config)
-	{
-		fapi_internal_t* instance = (fapi_internal*)calloc(1, sizeof(fapi_internal_t));
-		instance->callbacks = *callbacks;
-		instance->config = *config;
-		instance->state = 0;
-
-		instance->fapi = new fapi_private();
-
-		return (fapi_t*)instance;
-	}
-	
-	void fapi_destroy(fapi_t* fapi)
-	{
-		fapi_internal_t* instance = (fapi_internal_t*)fapi;
-		
-		delete instance->fapi;
-		free(instance);
-	}
-
-	void* fapi_rx_thread_start(void* ptr)
-	{
-		set_thread_priority(60);
-
-		fapi_internal_t* instance = (fapi_internal_t*)ptr;
-
-		while(1)
-		{
-			phy_pdu* pdu = instance->fapi->allocate_phy_pdu();
-			int len = recvfrom(instance->rx_sock, pdu->buffer, pdu->buffer_len, 0, 0, 0);
-			if(len > 0)
-			{
-				pdu->len = len;
-				instance->fapi->push_rx_buffer(pdu);
-			}
-			else
-			{
-				instance->fapi->release_phy_pdu(pdu);
-			}
-
-		}
-	}
-
-	void fapi_start_data(fapi_t* fapi, unsigned rx_port, const char* tx_address, unsigned tx_port)
-	{
-		fapi_internal_t* instance = (fapi_internal_t*)fapi;
-
-		printf("[FAPI] Rx Data from %d\n", rx_port);
-		printf("[FAPI] Tx Data to %s:%d\n", tx_address, tx_port);
-
-		instance->rx_sock = socket(AF_INET, SOCK_DGRAM, 0);
-		
-		if(instance->rx_sock < 0)
-		{
-			printf("[FAPI] Failed to create socket\n");
-			return;
-		}
-
-		struct sockaddr_in addr;
-		memset(&addr, 0, sizeof(addr));
-		addr.sin_family = AF_INET;
-		addr.sin_port = htons(rx_port);
-		addr.sin_addr.s_addr = INADDR_ANY;
-		
-		int bind_result = bind(instance->rx_sock, (struct sockaddr *)&addr, sizeof(struct sockaddr_in));
-		
-		if(bind_result == -1)
-		{
-			printf("[FAPI] Failed to bind to port %d\n", rx_port);
-			close(instance->rx_sock);
-			return ;
-		}
-
-		instance->tx_sock = socket(AF_INET, SOCK_DGRAM, 0);
-		instance->tx_addr.sin_family = AF_INET;
-		instance->tx_addr.sin_port = htons(tx_port);
-		instance->tx_addr.sin_addr.s_addr = inet_addr(tx_address);
-
-	}
-
-
-	void fill_tlv(fapi_tlv_t tlvs[], uint8_t count, uint8_t tag, uint8_t len, uint16_t value)
-	{
-		tlvs[count].tag = tag;
-		tlvs[count].value = value;
-		tlvs[count].length = len;
-		
-	}
-
-	int fapi_param_request(fapi_t* fapi, fapi_param_req_t* req)
-	{
-		fapi_internal_t* instance = (fapi_internal_t*)fapi;
-			
-		fapi_param_resp_t resp;
-		resp.header.message_id = FAPI_PARAM_RESPONSE;
-
-		resp.error_code = FAPI_MSG_OK;
-
-		resp.number_of_tlvs = 0;
-		fill_tlv(resp.tlvs, resp.number_of_tlvs++, FAPI_PHY_STATE_TAG, 2, instance->state);
-
-
-		if(instance->state == 0)
-		{
-			if(instance->config.duplex_mode == 0)
-			{
-				// -- TDD
-				// Downlink Bandwidth Support
-				// Uplink Bandwidth Support
-				// Downlink Modulation Support
-				// Uplink Modulation Support
-				// PHY Antenna Capability
-				// Release Capability
-				// MBSFN Capability
-			}
-			else if(instance->config.duplex_mode == 1)
-			{
-				// -- FDD
-				// Downlink Bandwidth Support
-				fill_tlv(resp.tlvs, resp.number_of_tlvs++, FAPI_PHY_CAPABILITIES_DL_BANDWIDTH_SUPPORT_TAG, 2, instance->config.dl_channel_bw_support);
-				// Uplink Bandwidth Support
-				fill_tlv(resp.tlvs, resp.number_of_tlvs++, FAPI_PHY_CAPABILITIES_UL_BANDWIDTH_SUPPORT_TAG, 2, instance->config.ul_channel_bw_support);
-				// Downlink Modulation Support
-				// Uplink Modulation Support
-				// PHY Antenna Capability
-				// Release Capability
-				// MBSFN Capability
-				// LAA Capability
-			}
-		}
-		else
-		{
-			if(instance->config.duplex_mode == 0)
-			{
-				// -- TDD
-				// Downlink Bandwidth Support
-				// Uplink Bandwidth Support
-				// Downlink Modulation Support
-				// Uplink Modulation Support
-				// PHY Antenna Capability
-				// Release Capability
-				// MBSFN Capability
-				// Duplexing Mode
-				// PCFICH Power Offset
-				// P-B
-				// DL Cyclic Prefix Type
-				// UL Cyclic Prefix Type
-				// RF Config
-				// PHICH Config
-				// SCH Config
-				// PRACH Config
-				// PUSCH Config
-				// PUCCH Config
-				// SRS Config
-				// Uplink Reference Signal Config
-				// TDD Frame Structure Config
-				// Data Report Mode
-			}
-			else if(instance->config.duplex_mode == 1)
-			{
-				// FDD
-				// Downlink Bandwidth Support
-				// Uplink Bandwidth Support
-				// Downlink Modulation Support
-				// Uplink Modulation Support
-				// PHY Antenna Capability
-				// Release Capability
-				// MBSFN Capability
-				// LAA Capability
-				// Duplexing Mode
-				// PCFICH Power Offset
-				// P-B
-				// DL Cyclic Prefix Type
-				// UL Cyclic Prefix Type
-				// RF Config
-				// PHICH Config
-				// SCH Config
-				// PRACH Config
-				// PUSCH Config
-				// PUCCH Config
-				// SRS Config
-				// Uplink Reference Signal Config
-				// Data Report Mode
-			}
-		}
-
-
-		//todo fill
-		(instance->callbacks.fapi_param_response)(fapi, &resp);
-
-		return 0;
-	}
-
-	int fapi_config_request(fapi_t* fapi, fapi_config_req_t* req)
-	{
-		fapi_internal_t* instance = (fapi_internal_t*)fapi;
-			
-		fapi_config_resp_t resp;
-		resp.header.message_id = FAPI_CONFIG_RESPONSE;
-		resp.error_code = FAPI_MSG_OK;
-
-		(instance->callbacks.fapi_config_response)(fapi, &resp);
-		return 0;
-	}
-
-	int fapi_start_request(fapi_t* fapi, fapi_start_req_t* req)
-	{
-		fapi_internal_t* instance = (fapi_internal_t*)fapi;
-			
-		pthread_t fapi_thread;
-		pthread_create(&fapi_thread, NULL, &fapi_thread_start, instance);
-		
-		return 0;
-	}
-
-	int fapi_dl_config_request(fapi_t* fapi, fapi_dl_config_req_t* req)
-	{
-		fapi_internal_t* instance = (fapi_internal_t*)fapi;
-		instance->fapi->first_dl_config = true;
-		return 0;
-	}
-	int fapi_ul_config_request(fapi_t* fapi, fapi_ul_config_req_t* req)
-	{
-		fapi_internal_t* instance = (fapi_internal_t*)fapi;
-		return 0;
-	}
-	int fapi_hi_dci0_request(fapi_t* fapi, fapi_hi_dci0_req_t* req)
-	{
-		fapi_internal_t* instance = (fapi_internal_t*)fapi;
-		return 0;
-	}
-	int fapi_tx_request(fapi_t* fapi, fapi_tx_req_t* req)
-	{
-		fapi_internal_t* instance = (fapi_internal_t*)fapi;
-
-		for(int i = 0; i < req->body.number_of_pdus; ++i)
-		{
-			uint16_t len = req->body.pdus[i].pdu_length;
-			uint32_t* data = req->body.pdus[i].tlvs[0].value;
-			//printf("[FAPI] sfnsf:%d len:%d\n", req->sfn_sf,len);
-			//
-			instance->tx_byte_count += len;
-
-			int sendto_result = sendto(instance->tx_sock, data, len, 0, (struct sockaddr*)&(instance->tx_addr), sizeof(instance->tx_addr));
-			
-			if(sendto_result == -1)
-			{
-				// error
-			}
-		}
-
-		return 0;
-	}
+  fapi_t *fapi_create(fapi_cb_t *callbacks, fapi_config_t *config) {
+    fapi_internal_t *instance = (fapi_internal *)calloc(1, sizeof(fapi_internal_t));
+    instance->callbacks = *callbacks;
+    instance->config = *config;
+    instance->state = 0;
+    instance->fapi = new fapi_private();
+    return (fapi_t *)instance;
+  }
+
+  void fapi_destroy(fapi_t *fapi) {
+    fapi_internal_t *instance = (fapi_internal_t *)fapi;
+    delete instance->fapi;
+    free(instance);
+  }
+
+  void *fapi_rx_thread_start(void *ptr) {
+    set_thread_priority(60);
+    fapi_internal_t *instance = (fapi_internal_t *)ptr;
+
+    while(1) {
+      phy_pdu *pdu = instance->fapi->allocate_phy_pdu();
+      int len = recvfrom(instance->rx_sock, pdu->buffer, pdu->buffer_len, 0, 0, 0);
+
+      if(len > 0) {
+        pdu->len = len;
+        instance->fapi->push_rx_buffer(pdu);
+      } else {
+        instance->fapi->release_phy_pdu(pdu);
+      }
+    }
+  }
+
+  void fapi_start_data(fapi_t *fapi, unsigned rx_port, const char *tx_address, unsigned tx_port) {
+    fapi_internal_t *instance = (fapi_internal_t *)fapi;
+    printf("[FAPI] Rx Data from %u\n", rx_port);
+    printf("[FAPI] Tx Data to %s:%u\n", tx_address, tx_port);
+    instance->rx_sock = socket(AF_INET, SOCK_DGRAM, 0);
+
+    if(instance->rx_sock < 0) {
+      printf("[FAPI] Failed to create socket\n");
+      return;
+    }
+
+    struct sockaddr_in addr;
+
+    memset(&addr, 0, sizeof(addr));
+
+    addr.sin_family = AF_INET;
+
+    addr.sin_port = htons(rx_port);
+
+    addr.sin_addr.s_addr = INADDR_ANY;
+
+    int bind_result = bind(instance->rx_sock, (struct sockaddr *)&addr, sizeof(struct sockaddr_in));
+
+    if(bind_result == -1) {
+      printf("[FAPI] Failed to bind to port %u\n", rx_port);
+      close(instance->rx_sock);
+      return ;
+    }
+
+    instance->tx_sock = socket(AF_INET, SOCK_DGRAM, 0);
+    instance->tx_addr.sin_family = AF_INET;
+    instance->tx_addr.sin_port = htons(tx_port);
+    instance->tx_addr.sin_addr.s_addr = inet_addr(tx_address);
+  }
+
+
+  void fill_tlv(fapi_tlv_t tlvs[], uint8_t count, uint8_t tag, uint8_t len, uint16_t value) {
+    tlvs[count].tag = tag;
+    tlvs[count].value = value;
+    tlvs[count].length = len;
+  }
+
+  int fapi_param_request(fapi_t *fapi, fapi_param_req_t *req) {
+    fapi_internal_t *instance = (fapi_internal_t *)fapi;
+    fapi_param_resp_t resp;
+    resp.header.message_id = FAPI_PARAM_RESPONSE;
+    resp.error_code = FAPI_MSG_OK;
+    resp.number_of_tlvs = 0;
+    fill_tlv(resp.tlvs, resp.number_of_tlvs++, FAPI_PHY_STATE_TAG, 2, instance->state);
+
+    if(instance->state == 0) {
+      if(instance->config.duplex_mode == 0) {
+        // -- TDD
+        // Downlink Bandwidth Support
+        // Uplink Bandwidth Support
+        // Downlink Modulation Support
+        // Uplink Modulation Support
+        // PHY Antenna Capability
+        // Release Capability
+        // MBSFN Capability
+      } else if(instance->config.duplex_mode == 1) {
+        // -- FDD
+        // Downlink Bandwidth Support
+        fill_tlv(resp.tlvs, resp.number_of_tlvs++, FAPI_PHY_CAPABILITIES_DL_BANDWIDTH_SUPPORT_TAG, 2, instance->config.dl_channel_bw_support);
+        // Uplink Bandwidth Support
+        fill_tlv(resp.tlvs, resp.number_of_tlvs++, FAPI_PHY_CAPABILITIES_UL_BANDWIDTH_SUPPORT_TAG, 2, instance->config.ul_channel_bw_support);
+        // Downlink Modulation Support
+        // Uplink Modulation Support
+        // PHY Antenna Capability
+        // Release Capability
+        // MBSFN Capability
+        // LAA Capability
+      }
+    } else {
+      if(instance->config.duplex_mode == 0) {
+        // -- TDD
+        // Downlink Bandwidth Support
+        // Uplink Bandwidth Support
+        // Downlink Modulation Support
+        // Uplink Modulation Support
+        // PHY Antenna Capability
+        // Release Capability
+        // MBSFN Capability
+        // Duplexing Mode
+        // PCFICH Power Offset
+        // P-B
+        // DL Cyclic Prefix Type
+        // UL Cyclic Prefix Type
+        // RF Config
+        // PHICH Config
+        // SCH Config
+        // PRACH Config
+        // PUSCH Config
+        // PUCCH Config
+        // SRS Config
+        // Uplink Reference Signal Config
+        // TDD Frame Structure Config
+        // Data Report Mode
+      } else if(instance->config.duplex_mode == 1) {
+        // FDD
+        // Downlink Bandwidth Support
+        // Uplink Bandwidth Support
+        // Downlink Modulation Support
+        // Uplink Modulation Support
+        // PHY Antenna Capability
+        // Release Capability
+        // MBSFN Capability
+        // LAA Capability
+        // Duplexing Mode
+        // PCFICH Power Offset
+        // P-B
+        // DL Cyclic Prefix Type
+        // UL Cyclic Prefix Type
+        // RF Config
+        // PHICH Config
+        // SCH Config
+        // PRACH Config
+        // PUSCH Config
+        // PUCCH Config
+        // SRS Config
+        // Uplink Reference Signal Config
+        // Data Report Mode
+      }
+    }
+
+    //todo fill
+    (instance->callbacks.fapi_param_response)(fapi, &resp);
+    return 0;
+  }
+
+  int fapi_config_request(fapi_t *fapi, fapi_config_req_t *req) {
+    fapi_internal_t *instance = (fapi_internal_t *)fapi;
+    fapi_config_resp_t resp;
+    resp.header.message_id = FAPI_CONFIG_RESPONSE;
+    resp.error_code = FAPI_MSG_OK;
+    (instance->callbacks.fapi_config_response)(fapi, &resp);
+    return 0;
+  }
+
+  int fapi_start_request(fapi_t *fapi, fapi_start_req_t *req) {
+    fapi_internal_t *instance = (fapi_internal_t *)fapi;
+    pthread_t fapi_thread;
+    pthread_create(&fapi_thread, NULL, &fapi_thread_start, instance);
+    return 0;
+  }
+
+  int fapi_dl_config_request(fapi_t *fapi, fapi_dl_config_req_t *req) {
+    fapi_internal_t *instance = (fapi_internal_t *)fapi;
+    instance->fapi->first_dl_config = true;
+    return 0;
+  }
+  int fapi_ul_config_request(fapi_t *fapi, fapi_ul_config_req_t *req) {
+    fapi_internal_t *instance = (fapi_internal_t *)fapi;
+    return 0;
+  }
+  int fapi_hi_dci0_request(fapi_t *fapi, fapi_hi_dci0_req_t *req) {
+    fapi_internal_t *instance = (fapi_internal_t *)fapi;
+    return 0;
+  }
+  int fapi_tx_request(fapi_t *fapi, fapi_tx_req_t *req) {
+    fapi_internal_t *instance = (fapi_internal_t *)fapi;
+
+    for(int i = 0; i < req->body.number_of_pdus; ++i) {
+      uint16_t len = req->body.pdus[i].pdu_length;
+      uint32_t *data = req->body.pdus[i].tlvs[0].value;
+      //printf("[FAPI] sfnsf:%d len:%d\n", req->sfn_sf,len);
+      //
+      instance->tx_byte_count += len;
+      int sendto_result = sendto(instance->tx_sock, data, len, 0, (struct sockaddr *)&(instance->tx_addr), sizeof(instance->tx_addr));
+
+      if(sendto_result == -1) {
+        // error
+      }
+    }
+
+    return 0;
+  }
 }
 
diff --git a/nfapi/open-nFAPI/pnf_sim/src/main.cpp b/nfapi/open-nFAPI/pnf_sim/src/main.cpp
index e2622cf3c3636f1021633e1570c8949d31088f8c..251e2a48cbdd2156b61e84d83c26adc2858c780e 100644
--- a/nfapi/open-nFAPI/pnf_sim/src/main.cpp
+++ b/nfapi/open-nFAPI/pnf_sim/src/main.cpp
@@ -101,7 +101,7 @@ class phy_info
 		{
 			index = 0;
 			id = 0;
-
+                        udp = 0;
 			local_port = 0;
 			remote_addr = 0;
 			remote_port = 0;
@@ -178,6 +178,7 @@ class pnf_info
 	
 			sync_mode = 0;
 			location_mode = 0;
+			location_coordinates = 0;
 			dl_config_timing = 0;
 			ul_config_timing = 0;
 			tx_timing = 0;
diff --git a/nfapi/open-nFAPI/vnf/src/vnf_p7.c b/nfapi/open-nFAPI/vnf/src/vnf_p7.c
index cea259c35b354d3179d178da2ce6faf3f9104f70..4b7acabec3637af74e3d95f8d9d805ea3337b118 100644
--- a/nfapi/open-nFAPI/vnf/src/vnf_p7.c
+++ b/nfapi/open-nFAPI/vnf/src/vnf_p7.c
@@ -1203,12 +1203,12 @@ void vnf_handle_ul_node_sync(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_p7)
 
 			if(phy->in_sync == 0)
 			{
-				NFAPI_TRACE(NFAPI_TRACE_NOTE, "***** Adjusting VNF phy_id:%d SFN/SF (%s) from %d to %d (%d) mode:%s zeroCount:%u sync:%s\n", 
+				/*NFAPI_TRACE(NFAPI_TRACE_NOTE, "***** Adjusting VNF phy_id:%d SFN/SF (%s) from %d to %d (%d) mode:%s zeroCount:%u sync:%s\n",
 					ind.header.phy_id, (phy->in_sync ? "via sfn" : "now"),
 					NFAPI_SFNSF2DEC(curr_sfn_sf), NFAPI_SFNSF2DEC(new_sfn_sf), phy->adjustment, 
 					phy->filtered_adjust ? "FILTERED" : "ABSOLUTE",
 					phy->zero_count,
-					phy->in_sync ? "IN_SYNC" : "OUT_OF_SYNC");
+					phy->in_sync ? "IN_SYNC" : "OUT_OF_SYNC");*/
 
 				phy->sfn_sf = new_sfn_sf;
 			}
diff --git a/nfapi/open-nFAPI/vnf_sim/src/mac.cpp b/nfapi/open-nFAPI/vnf_sim/src/mac.cpp
index fa6f487be8e2274d55ac10c69b238070abfea6f6..88898afc744133966b9eb079235b4537d2be453d 100644
--- a/nfapi/open-nFAPI/vnf_sim/src/mac.cpp
+++ b/nfapi/open-nFAPI/vnf_sim/src/mac.cpp
@@ -1,12 +1,12 @@
 /*
  * Copyright 2017 Cisco Systems, Inc.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * 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.
@@ -31,1297 +31,1130 @@
 #include <queue>
 #include <list>
 
-uint32_t rand_range(uint32_t min, uint32_t max)
-{
-	return ((rand() % (max + 1 - min)) + min);
+uint32_t rand_range(uint32_t min, uint32_t max) {
+  return ((rand() % (max + 1 - min)) + min);
 }
 
-struct mac_pdu
-{
-	mac_pdu() : buffer_len(1500), buffer(0), len(0)
-	{
-		buffer = (char*) malloc(buffer_len);
-	}
-	
-	virtual ~mac_pdu()
-	{
-		free(buffer);
-	}
-
-	unsigned buffer_len;
-	char* buffer;
-	unsigned len;
+struct mac_pdu {
+  mac_pdu() : buffer_len(1500), buffer(0), len(0) {
+    buffer = (char *) malloc(buffer_len);
+  }
+
+  virtual ~mac_pdu() {
+    free(buffer);
+  }
+
+  unsigned buffer_len;
+  char *buffer;
+  unsigned len;
 };
 
-class mac_private
-{
-		std::mutex mutex;
-		std::queue<mac_pdu*> rx_buffer;
-
-		std::queue<mac_pdu*> free_store;
-	public:
-
-		mac_private(bool _wireshark_test_mode)
-			: byte_count(0), tick(0), wireshark_test_mode(_wireshark_test_mode)
-		{
-
-		}
-
-		mac_pdu* allocate_mac_pdu()
-		{
-			mac_pdu* pdu = 0;
-			mutex.lock();
-			if(free_store.empty())
-			{
-				pdu = new mac_pdu();
-			}
-			else
-			{
-				pdu = free_store.front();
-				free_store.pop();
-			}
-			mutex.unlock();
-			return pdu;
-		}
-
-		void release_mac_pdu(mac_pdu* pdu)
-		{
-			mutex.lock();
-			free_store.push(pdu);
-			mutex.unlock();
-		}
-
-		
-
-		void push_rx_buffer(mac_pdu* buff)
-		{
-			mutex.lock();
-			rx_buffer.push(buff);
-			mutex.unlock();
-		}
-
-		mac_pdu* pop_rx_buffer()
-		{
-			mac_pdu* buff = 0;
-			mutex.lock();
-			if(!rx_buffer.empty())
-			{
-				buff = rx_buffer.front();
-				rx_buffer.pop();
-			}
-			mutex.unlock();
-			return buff;
-		}
-
-		uint32_t byte_count;
-		uint32_t tick;
-		
-		bool wireshark_test_mode;
+class mac_private {
+  std::mutex mutex;
+  std::queue<mac_pdu *> rx_buffer;
+
+  std::queue<mac_pdu *> free_store;
+ public:
+
+  mac_private(bool _wireshark_test_mode)
+    : byte_count(0), tick(0), wireshark_test_mode(_wireshark_test_mode) {
+  }
+
+  mac_pdu *allocate_mac_pdu() {
+    mac_pdu *pdu = 0;
+    mutex.lock();
+
+    if(free_store.empty()) {
+      pdu = new mac_pdu();
+    } else {
+      pdu = free_store.front();
+      free_store.pop();
+    }
+
+    mutex.unlock();
+    return pdu;
+  }
+
+  void release_mac_pdu(mac_pdu *pdu) {
+    mutex.lock();
+    free_store.push(pdu);
+    mutex.unlock();
+  }
+
+
+
+  void push_rx_buffer(mac_pdu *buff) {
+    mutex.lock();
+    rx_buffer.push(buff);
+    mutex.unlock();
+  }
+
+  mac_pdu *pop_rx_buffer() {
+    mac_pdu *buff = 0;
+    mutex.lock();
+
+    if(!rx_buffer.empty()) {
+      buff = rx_buffer.front();
+      rx_buffer.pop();
+    }
+
+    mutex.unlock();
+    return buff;
+  }
+
+  uint32_t byte_count;
+  uint32_t tick;
+
+  bool wireshark_test_mode;
 
 };
 
 extern "C"
 {
-	typedef struct {
-		mac_t _public;
-
-		int rx_sock;
-		int tx_sock;
-		struct sockaddr_in tx_addr;
-
-		uint32_t tx_byte_count;
-
-		mac_private* mac;
-		
-	} mac_internal_t;
-
-	mac_t* mac_create(uint8_t wireshark_test_mode)
-	{
-		mac_internal_t* instance = (mac_internal_t*)malloc(sizeof(mac_internal_t));
-		instance->mac = new mac_private((wireshark_test_mode >= 1));
-		return (mac_t*)instance;
-	}
-	
-	void mac_destroy(mac_t* mac)
-	{
-		mac_internal_t* instance = (mac_internal_t*)mac;
-		delete instance->mac;
-		free(instance);
-	}
-	
-	void* mac_rx_thread_start(void* ptr)
-	{
-		mac_internal_t* instance = (mac_internal_t*)ptr;
-
-		while(1)
-		{
-			mac_pdu* pdu = instance->mac->allocate_mac_pdu();
-			int len = recvfrom(instance->rx_sock, pdu->buffer, pdu->buffer_len, 0, 0, 0);
-			if(len > 0)
-			{
-				pdu->len = len;
-				instance->mac->push_rx_buffer(pdu);
-			}
-			else
-			{
-				instance->mac->release_mac_pdu(pdu);
-			}
-		}
-		return 0;
-	}
-
-	void mac_start_data(mac_t* mac, unsigned rx_port, const char* tx_address, unsigned tx_port)
-	{
-		mac_internal_t* instance = (mac_internal_t*)mac;
-
-		printf("[MAC] Rx Data from %d\n", rx_port);
-		printf("[MAC] Tx Data to %s.%d\n", tx_address, tx_port);
-
-		instance->rx_sock = socket(AF_INET, SOCK_DGRAM, 0);
-		
-		if(instance->rx_sock < 0)
-		{
-			printf("[MAC] Failed to create socket\n");
-			return;
-		}
-
-		struct sockaddr_in addr;
-		memset(&addr, 0, sizeof(0));
-		addr.sin_family = AF_INET;
-		addr.sin_port = htons(rx_port);
-		addr.sin_addr.s_addr = INADDR_ANY;
-		
-		if(bind(instance->rx_sock, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) < 0)
-		{
-			printf("[MAC] Failed to bind to %d\n", rx_port);
-			close(instance->rx_sock);
-			return;
-		}
-
-		pthread_t mac_rx_thread;
-		pthread_create(&mac_rx_thread, NULL, &mac_rx_thread_start, instance);
-
-		instance->tx_sock = socket(AF_INET, SOCK_DGRAM, 0);
-		instance->tx_addr.sin_family = AF_INET;
-		instance->tx_addr.sin_port = htons(tx_port);
-		instance->tx_addr.sin_addr.s_addr = inet_addr(tx_address);
-	}
-
-
-	
-	void generate_test_subframe(mac_t *mac, uint16_t phy_id, uint16_t sfn_sf)	
-	{
-		//mac_internal_t* instance = (mac_internal_t*)mac;
-		
-		uint8_t max_num_dl_pdus = 50;
-		nfapi_dl_config_request_pdu_t dl_config_pdus[max_num_dl_pdus];
-		memset(&dl_config_pdus, 0, sizeof(dl_config_pdus));
-		
-		nfapi_dl_config_request_t dl_config_req;
-		memset(&dl_config_req, 0, sizeof(dl_config_req));
-		dl_config_req.header.message_id = NFAPI_DL_CONFIG_REQUEST;
-		dl_config_req.header.phy_id = phy_id;
-		dl_config_req.sfn_sf = sfn_sf;
-		dl_config_req.dl_config_request_body.tl.tag = NFAPI_DL_CONFIG_REQUEST_BODY_TAG;
-		
-		dl_config_req.dl_config_request_body.number_pdu = rand_range(4, max_num_dl_pdus);
-		
-		uint16_t i = 0;
-		for(i = 0; i < dl_config_req.dl_config_request_body.number_pdu; ++i)
-		{
-			dl_config_pdus[i].pdu_type = rand_range(0, 11);
-			
-			switch(dl_config_pdus[i].pdu_type)
-			{
-				case NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE:
-				{
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL8_TAG;
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.dci_format = rand_range(0, 9);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.cce_idx = rand_range(0, 255);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level  = rand_range(0, 32);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti = rand_range(0, (uint16_t)-1);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.resource_allocation_type = rand_range(0, 1);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.virtual_resource_block_assignment_flag = rand_range(0, 1);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.resource_block_coding = rand_range(0, 320000);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.mcs_1 = rand_range(0, 31);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_1 = rand_range(0, 3);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_1 = rand_range(0, 1);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.transport_block_to_codeword_swap_flag = rand_range(0, 1);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.mcs_2 = rand_range(0, 31);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_2 = rand_range(0, 31);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_2 = rand_range(0, 1);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.harq_process = rand_range(0, 31);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.tpmi = rand_range(0, 15);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.pmi = rand_range(0, 1);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.precoding_information = rand_range(0, 63);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.tpc = rand_range(0, 3);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.downlink_assignment_index = rand_range(0, 15);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.ngap = rand_range(0, 1);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.transport_block_size_index = rand_range(0, 31);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.downlink_power_offset = rand_range(0, 1);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.allocate_prach_flag = rand_range(0, 1);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.preamble_index = rand_range(0, 63);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.prach_mask_index = rand_range(0, 15);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti_type = rand_range(0, 3);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.transmission_power = rand_range(0, 10000);		
-					
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel9.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL9_TAG;
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel9.mcch_flag = rand_range(0, 1);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel9.mcch_change_notification = rand_range(0, 255);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel9.scrambling_identity = rand_range(0, 1);
-					
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL10_TAG;
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.cross_carrier_scheduling_flag = rand_range(0, 1);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.carrier_indicator = rand_range(0, 7);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.srs_flag = rand_range(0, 1);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.srs_request = rand_range(0, 1);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.antenna_ports_scrambling_and_layers = rand_range(0, 15);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.total_dci_length_including_padding = rand_range(0, 255);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.n_dl_rb = rand_range(0, 100);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel11.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL11_TAG;
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel11.harq_ack_resource_offset = rand_range(0, 3);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel11.pdsch_re_mapping_quasi_co_location_indicator = rand_range(0, 3);
-					
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel12.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL12_TAG;
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel12.primary_cell_type = rand_range(0, 2);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel12.ul_dl_configuration_flag = rand_range(0, 1);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel12.number_ul_dl_configurations = 2;
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel12.ul_dl_configuration_indication[0] = rand_range(1, 5);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel12.ul_dl_configuration_indication[1] = rand_range(1, 5);
-					
-					
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL13_TAG;
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.laa_end_partial_sf_flag = rand_range(0, 1);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.laa_end_partial_sf_configuration = rand_range(0, 255);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.initial_lbt_sf = rand_range(0, 1);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.codebook_size_determination = rand_range(0, 1);
-					dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.drms_table_flag = rand_range(0, 1);
-					
-					// if the tpm extention is present of not.
-					if(rand_range(0, 1))
-					{
-						dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm_struct_flag = rand_range(0, 1);
-						dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.num_prb_per_subband = rand_range(0, 8);
-						dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.number_of_subbands = rand_range(0, 13);
-						dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.num_antennas = 1; // rand_range(0, 8);
-						
-						for(int j = 0; j < dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.number_of_subbands; ++j)
-						{
-							dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.subband_info[j].subband_index = j;
-							dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.subband_info[j].scheduled_ues = 1; //rand_range(1, 4);
-							
-							for(int k = 0; k < dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.num_antennas; ++k)
-								for(int l = 0; l < dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.subband_info[j].scheduled_ues; ++l)
-									dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.subband_info[j].precoding_value[k][l] = rand_range(0, 65535);
-						}
-					}
-					else
-					{
-						dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm_struct_flag = 0;
-					}
-					
-				}
-				break;
-				
-				case NFAPI_DL_CONFIG_BCH_PDU_TYPE:
-				{
-					dl_config_pdus[i].bch_pdu.bch_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_BCH_PDU_REL8_TAG;
-					dl_config_pdus[i].bch_pdu.bch_pdu_rel8.length = rand_range(0, 42);
-					dl_config_pdus[i].bch_pdu.bch_pdu_rel8.pdu_index = rand_range(0, 65535);
-					dl_config_pdus[i].bch_pdu.bch_pdu_rel8.transmission_power = rand_range(0, 10000);
-				}
-				break;
-				
-				case NFAPI_DL_CONFIG_MCH_PDU_TYPE:
-				{
-					dl_config_pdus[i].mch_pdu.mch_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_MCH_PDU_REL8_TAG;
-					dl_config_pdus[i].mch_pdu.mch_pdu_rel8.length = rand_range(0, 42);
-					dl_config_pdus[i].mch_pdu.mch_pdu_rel8.pdu_index = rand_range(0, 65535);
-					dl_config_pdus[i].mch_pdu.mch_pdu_rel8.rnti = 0xFFFD;
-					dl_config_pdus[i].mch_pdu.mch_pdu_rel8.resource_allocation_type = 0;
-					dl_config_pdus[i].mch_pdu.mch_pdu_rel8.resource_block_coding = 0;
-					dl_config_pdus[i].mch_pdu.mch_pdu_rel8.modulation = rand_range(0, 8);
-					dl_config_pdus[i].mch_pdu.mch_pdu_rel8.transmission_power = rand_range(0, 10000);
-					dl_config_pdus[i].mch_pdu.mch_pdu_rel8.mbsfn_area_id = rand_range(0, 255);
-				}
-				break;
-			
-				case NFAPI_DL_CONFIG_DLSCH_PDU_TYPE:
-				{
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL8_TAG;
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.length = rand_range(0, 42);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.pdu_index = rand_range(0, 65535);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.rnti = rand_range(1, 65535);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.resource_allocation_type = rand_range(0, 5);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.virtual_resource_block_assignment_flag = rand_range(0, 1);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.resource_block_coding = rand_range(0, 32000);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.modulation = rand_range(2, 8);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.redundancy_version = rand_range(0, 3);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.transport_blocks = rand_range(1, 2);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.transport_block_to_codeword_swap_flag = rand_range(0, 1);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.transmission_scheme = rand_range(0, 13);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.number_of_layers = rand_range(1, 8);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.number_of_subbands = 2; //rand_range(0, 13);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.codebook_index[0] = rand_range(0, 15);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.codebook_index[1] = rand_range(0, 15);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.ue_category_capacity = rand_range(0, 14);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.pa = rand_range(0, 7);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.delta_power_offset_index = rand_range(0, 1);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.ngap = rand_range(0, 1);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.nprb = rand_range(0, 1);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.transmission_mode = rand_range(1, 10);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.num_bf_prb_per_subband = 2; //rand_range(0, 1);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.num_bf_vector = 2; //rand_range(0, 1);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.bf_vector[0].subband_index = rand_range(0, 4);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.bf_vector[0].num_antennas = 1;	
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.bf_vector[0].bf_value[0] = rand_range(0, 128);	
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.bf_vector[1].subband_index = rand_range(0, 4);	
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.bf_vector[1].num_antennas = 1;
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.bf_vector[1].bf_value[0] = rand_range(0, 128);	
-					
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel9.tl.tag = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL9_TAG;
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel9.nscid = rand_range(0, 1);	
-					
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel10.tl.tag = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL10_TAG;
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel10.csi_rs_flag = rand_range(0, 1);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel10.csi_rs_resource_config_r10 = 0;
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel10.csi_rs_zero_tx_power_resource_config_bitmap_r10 = rand_range(0, 65535);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel10.csi_rs_number_nzp_configuration = 1;
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel10.csi_rs_resource_config[0] = rand_range(0, 31);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel10.pdsch_start = rand_range(0, 4);		
-					
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.tl.tag = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL11_TAG;
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.drms_config_flag = rand_range(0, 1);	
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.drms_scrambling = rand_range(0, 503);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.csi_config_flag = rand_range(0, 1);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.csi_scrambling = rand_range(0, 503);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.pdsch_re_mapping_flag = rand_range(0, 1);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.pdsch_re_mapping_atenna_ports = rand_range(1,4);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.pdsch_re_mapping_freq_shift = rand_range(0, 5);
-					
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel12.tl.tag = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL12_TAG;
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel12.altcqi_table_r12 = rand_range(0, 1);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel12.maxlayers = rand_range(1, 8);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel12.n_dl_harq = rand_range(0, 255);
-					
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel13.dwpts_symbols = rand_range(3, 14);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel13.initial_lbt_sf = rand_range(0, 1);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel13.ue_type = rand_range(0, 2);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel13.pdsch_payload_type = rand_range(0, 2);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel13.initial_transmission_sf_io = rand_range(0, 10239);
-					dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel13.drms_table_flag = rand_range(0, 1);
-				}
-				break;
-			
-				case NFAPI_DL_CONFIG_PCH_PDU_TYPE:
-				{
-					dl_config_pdus[i].pch_pdu.pch_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_PCH_PDU_REL8_TAG;
-					dl_config_pdus[i].pch_pdu.pch_pdu_rel8.length = rand_range(0, 42);
-					dl_config_pdus[i].pch_pdu.pch_pdu_rel8.pdu_index = rand_range(0, 65535);
-					dl_config_pdus[i].pch_pdu.pch_pdu_rel8.p_rnti = 0xFFFE;
-					dl_config_pdus[i].pch_pdu.pch_pdu_rel8.resource_allocation_type = rand_range(2, 6);
-					dl_config_pdus[i].pch_pdu.pch_pdu_rel8.virtual_resource_block_assignment_flag = rand_range(0, 1);
-					dl_config_pdus[i].pch_pdu.pch_pdu_rel8.resource_block_coding = rand_range(0, 34000);
-					dl_config_pdus[i].pch_pdu.pch_pdu_rel8.mcs = 0;
-					dl_config_pdus[i].pch_pdu.pch_pdu_rel8.redundancy_version = 0;
-					dl_config_pdus[i].pch_pdu.pch_pdu_rel8.number_of_transport_blocks = 1;
-					dl_config_pdus[i].pch_pdu.pch_pdu_rel8.transport_block_to_codeword_swap_flag = 0;
-					dl_config_pdus[i].pch_pdu.pch_pdu_rel8.transmission_scheme = rand_range(1, 6);
-					dl_config_pdus[i].pch_pdu.pch_pdu_rel8.number_of_layers = rand_range(1, 4);
-					dl_config_pdus[i].pch_pdu.pch_pdu_rel8.codebook_index = 0;
-					dl_config_pdus[i].pch_pdu.pch_pdu_rel8.ue_category_capacity = rand_range(0, 14);
-					dl_config_pdus[i].pch_pdu.pch_pdu_rel8.pa = rand_range(0, 7);
-					dl_config_pdus[i].pch_pdu.pch_pdu_rel8.transmission_power = rand_range(0, 10000);
-					dl_config_pdus[i].pch_pdu.pch_pdu_rel8.nprb = rand_range(0, 1);
-					dl_config_pdus[i].pch_pdu.pch_pdu_rel8.ngap = rand_range(0, 1);	
-					dl_config_pdus[i].pch_pdu.pch_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_PCH_PDU_REL13_TAG;
-					dl_config_pdus[i].pch_pdu.pch_pdu_rel13.ue_mode = rand_range(0, 1);	
-					dl_config_pdus[i].pch_pdu.pch_pdu_rel13.initial_transmission_sf_io = rand_range(0, 10239);
-				}
-				break;
-			
-				case NFAPI_DL_CONFIG_PRS_PDU_TYPE:
-				{
-					dl_config_pdus[i].prs_pdu.prs_pdu_rel9.tl.tag = NFAPI_DL_CONFIG_REQUEST_PRS_PDU_REL9_TAG;
-					dl_config_pdus[i].prs_pdu.prs_pdu_rel9.transmission_power = rand_range(0, 10000);	
-					dl_config_pdus[i].prs_pdu.prs_pdu_rel9.prs_bandwidth = rand_range(6, 100);
-					dl_config_pdus[i].prs_pdu.prs_pdu_rel9.prs_cyclic_prefix_type = rand_range(0, 1);
-					dl_config_pdus[i].prs_pdu.prs_pdu_rel9.prs_muting = rand_range(0, 1);
-				}
-				break;
-	
-				case NFAPI_DL_CONFIG_CSI_RS_PDU_TYPE:
-				{
-					dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.tl.tag = NFAPI_DL_CONFIG_REQUEST_CSI_RS_PDU_REL10_TAG;
-					dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.csi_rs_antenna_port_count_r10 = rand_range(1, 16);
-					dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.csi_rs_resource_config_r10 = 0;
-					dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.transmission_power = rand_range(0, 10000);
-					dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.csi_rs_zero_tx_power_resource_config_bitmap_r10 = rand_range(0, 8);
-					dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.csi_rs_number_of_nzp_configuration = 2;
-					dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.csi_rs_resource_config[0] = rand_range(0, 31);
-					dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.csi_rs_resource_config[1] = rand_range(0, 31);
-					dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_CSI_RS_PDU_REL13_TAG;
-					dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel13.csi_rs_class = rand_range(0, 2);
-					dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel13.cdm_type = rand_range(0, 1);
-					dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel13.num_bf_vector = 0; // set to zero as not clear how to handle bf value array
-					dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel13.bf_vector[0].csi_rs_resource_index = rand_range(0, 7);
-					dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel13.bf_vector[0].bf_value[0] = 42;
-				}
-				break;
-	
-				case NFAPI_DL_CONFIG_EPDCCH_DL_PDU_TYPE:
-				{
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PDU_REL8_TAG;
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.dci_format = rand_range(0, 9);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.cce_idx = rand_range(0, 255);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.aggregation_level  = rand_range(0, 32);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.rnti = rand_range(0, (uint16_t)-1);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.resource_allocation_type = rand_range(0, 1);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.virtual_resource_block_assignment_flag = rand_range(0, 1);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.resource_block_coding = rand_range(0, 320000);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.mcs_1 = rand_range(0, 31);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.redundancy_version_1 = rand_range(0, 3);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.new_data_indicator_1 = rand_range(0, 1);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.transport_block_to_codeword_swap_flag = rand_range(0, 1);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.mcs_2 = rand_range(0, 31);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.redundancy_version_2 = rand_range(0, 31);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.new_data_indicator_2 = rand_range(0, 1);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.harq_process = rand_range(0, 31);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.tpmi = rand_range(0, 15);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.pmi = rand_range(0, 1);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.precoding_information = rand_range(0, 63);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.tpc = rand_range(0, 3);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.downlink_assignment_index = rand_range(0, 15);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.ngap = rand_range(0, 1);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.transport_block_size_index = rand_range(0, 31);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.downlink_power_offset = rand_range(0, 1);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.allocate_prach_flag = rand_range(0, 1);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.preamble_index = rand_range(0, 63);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.prach_mask_index = rand_range(0, 15);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.rnti_type = rand_range(0, 3);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.transmission_power = rand_range(0, 10000);	
-					
-					
-					
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel9.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PDU_REL9_TAG;
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel9.mcch_flag = rand_range(0, 1);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel9.mcch_change_notification = rand_range(0, 255);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel9.scrambling_identity = rand_range(0, 1);
-					
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PDU_REL10_TAG;
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.cross_carrier_scheduling_flag = rand_range(0, 1);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.carrier_indicator = rand_range(0, 7);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.srs_flag = rand_range(0, 1);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.srs_request = rand_range(0, 1);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.antenna_ports_scrambling_and_layers = rand_range(0, 15);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.total_dci_length_including_padding = rand_range(0, 255);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.n_dl_rb = rand_range(0, 100);
-					
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel11.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PDU_REL11_TAG;
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel11.harq_ack_resource_offset = rand_range(0, 3);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel11.pdsch_re_mapping_quasi_co_location_indicator = rand_range(0, 3);
-					
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel12.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PDU_REL12_TAG;
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel12.primary_cell_type = rand_range(0, 2);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel12.ul_dl_configuration_flag = rand_range(0, 1);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel12.number_ul_dl_configurations = 2;
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel12.ul_dl_configuration_indication[0] = rand_range(1, 5);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel12.ul_dl_configuration_indication[1] = rand_range(1, 5);
-					
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PDU_REL13_TAG;
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel13.laa_end_partial_sf_flag = rand_range(0, 1);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel13.laa_end_partial_sf_configuration = rand_range(0, 255);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel13.initial_lbt_sf = rand_range(0, 1);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel13.codebook_size_determination = rand_range(0, 1);
-					dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel13.drms_table_flag = rand_range(0, 1);
-
-					dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PARAM_REL11_TAG;
-					dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.epdcch_resource_assignment_flag = rand_range(0, 1);
-					dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.epdcch_id = rand_range(0, 503);
-					dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.epdcch_start_symbol = rand_range(1, 4);
-					dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.epdcch_num_prb = rand_range(2, 8);
-					for(int j = 0; j < dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.epdcch_num_prb; ++j)
-						dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.epdcch_prb_index[j] = rand_range(0, 99);
-					dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.bf_vector.subband_index = rand_range(0, 25);	
-					dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.bf_vector.num_antennas= rand_range(1, 4);
-					for(int j = 0; j < dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.epdcch_num_prb; ++j)
-						dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.bf_vector.bf_value[j] = rand_range(0, 65535);
-					
-	
-					dl_config_pdus[i].epdcch_pdu.epdcch_params_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PARAM_REL13_TAG;
-					dl_config_pdus[i].epdcch_pdu.epdcch_params_rel13.dwpts_symbols = rand_range(3, 14);
-					dl_config_pdus[i].epdcch_pdu.epdcch_params_rel13.initial_lbt_sf = rand_range(0, 1);
-				}
-				break;
-				
-				case NFAPI_DL_CONFIG_MPDCCH_PDU_TYPE:
-				{
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_MPDCCH_PDU_REL13_TAG;
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.mpdcch_narrow_band = rand_range(0, 15);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.number_of_prb_pairs = rand_range(2, 6);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.resource_block_assignment = rand_range(0, 14);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.mpdcch_tansmission_type = rand_range(0, 1);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.start_symbol = rand_range(1, 4);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.ecce_index = rand_range(0, 22);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.aggregation_level = rand_range(2, 24);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.rnti_type = rand_range(0, 4);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.rnti = rand_range(1, 65535);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.ce_mode = rand_range(1, 2);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.drms_scrambling_init = rand_range(0, 503);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.initial_transmission_sf_io = rand_range(0, 10239);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.transmission_power = rand_range(0, 10000);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.dci_format = rand_range(10, 12);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.resource_block_coding = rand_range(0, 0xFFFF);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.mcs = rand_range(0, 15);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.pdsch_reptition_levels = rand_range(1, 8);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.redundancy_version = rand_range(0, 3);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.new_data_indicator = rand_range(0, 1);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.harq_process = rand_range(0, 15);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.tpmi_length = rand_range(0, 4);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.tpmi = rand_range(0, 15);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.pmi_flag = rand_range(0, 1);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.pmi = rand_range(0, 1);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.harq_resource_offset = rand_range(0, 3);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.dci_subframe_repetition_number = rand_range(1, 4);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.tpc = rand_range(0, 3);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.downlink_assignment_index_length = rand_range(0, 4);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.downlink_assignment_index = rand_range(0, 15);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.allocate_prach_flag = rand_range(0, 63);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.preamble_index = rand_range(0, 15);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.prach_mask_index = rand_range(0, 3);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.starting_ce_level = rand_range(0, 1);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.srs_request = rand_range(0, 1);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.antenna_ports_and_scrambling_identity_flag = rand_range(0, 1);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.antenna_ports_and_scrambling_identity = rand_range(0, 3);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.frequency_hopping_enabled_flag = rand_range(0, 1);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.paging_direct_indication_differentiation_flag = rand_range(0, 1);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.direct_indication = rand_range(0, 255);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.total_dci_length_including_padding = rand_range(0, 1);
-					dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.number_of_tx_antenna_ports = rand_range(0, 8);
-					for(int j = 0 ; j < dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.number_of_tx_antenna_ports; ++j)
-						dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.precoding_value[j] = rand_range(0, 65535);
-				}
-				break;
-				
-				case NFAPI_DL_CONFIG_NBCH_PDU_TYPE:
-				{
-					dl_config_pdus[i].nbch_pdu.nbch_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_NBCH_PDU_REL13_TAG;
-					dl_config_pdus[i].nbch_pdu.nbch_pdu_rel13.length = rand_range(0, 5555);
-					dl_config_pdus[i].nbch_pdu.nbch_pdu_rel13.pdu_index = rand_range(0, 65535);
-					dl_config_pdus[i].nbch_pdu.nbch_pdu_rel13.transmission_power = rand_range(0, 10000);
-					dl_config_pdus[i].nbch_pdu.nbch_pdu_rel13.hyper_sfn_2_lsbs = rand_range(0, 3);
-				}
-				break;
-				
-				case NFAPI_DL_CONFIG_NPDCCH_PDU_TYPE:
-				{
-					dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_NPDCCH_PDU_REL13_TAG;
-					dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.length = rand_range(0, 5555);
-					dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.pdu_index = rand_range(0, 65535);
-					dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.ncce_index = rand_range(0, 1);
-					dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.aggregation_level = rand_range(1, 2);
-					dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.start_symbol = rand_range(0, 4);
-					dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.rnti_type = rand_range(0, 3);
-					dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.rnti = rand_range(1, 65535);
-					dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.scrambling_reinitialization_batch_index = rand_range(1, 4);
-					dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.nrs_antenna_ports_assumed_by_the_ue = rand_range(1, 2);
-					dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.dci_format = rand_range(0, 1);
-					dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.scheduling_delay = rand_range(0, 7);
-					dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.resource_assignment = rand_range(0, 7);
-					dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.repetition_number = rand_range(0, 15); 
-					dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.mcs = rand_range(0, 13);
-					dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.new_data_indicator = rand_range(0, 1);
-					dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.harq_ack_resource = rand_range(0, 15);
-					dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.npdcch_order_indication = rand_range(0, 1);
-					dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.starting_number_of_nprach_repetitions = rand_range(0, 3);
-					dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.subcarrier_indication_of_nprach = rand_range(0, 63);
-					dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.paging_direct_indication_differentation_flag = rand_range(0, 1);
-					dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.direct_indication = rand_range(0, 255);
-					dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.dci_subframe_repetition_number  = rand_range(0, 7);
-					dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.total_dci_length_including_padding = rand_range(0, 255);
-				}
-				break;
-				
-				case NFAPI_DL_CONFIG_NDLSCH_PDU_TYPE:
-				{
-					dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_NDLSCH_PDU_REL13_TAG;
-					dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.length = rand_range(0, 5555);
-					dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.pdu_index = rand_range(0, 65535);
-					dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.start_symbol = rand_range(0, 4);
-					dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.rnti_type = rand_range(0, 1);
-					dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.rnti = rand_range(1, 65535);
-					dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.resource_assignment = rand_range(0, 7);
-					dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.repetition_number = rand_range(0, 15);
-					dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.modulation = 2;
-					dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.number_of_subframes_for_resource_assignment = rand_range(1, 10);
-					dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.scrambling_sequence_initialization_cinit = rand_range(0, 65535);
-					dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.sf_idx = rand_range(1, 10240);
-					dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.nrs_antenna_ports_assumed_by_the_ue = rand_range(1, 2);
-				}
-				break;
-				
-			};
-		}
-
-
-		dl_config_req.dl_config_request_body.dl_config_pdu_list = dl_config_pdus;		
-		mac->dl_config_req(mac, &dl_config_req);
-		
-		uint8_t num_ul_pdus = 18;
-		nfapi_ul_config_request_pdu_t ul_config_pdus[num_ul_pdus];
-		memset(&ul_config_pdus, 0, sizeof(ul_config_pdus));
-		
-		nfapi_ul_config_request_t ul_config_req;
-		memset(&ul_config_req, 0, sizeof(ul_config_req));
-		ul_config_req.header.message_id = NFAPI_UL_CONFIG_REQUEST;
-		ul_config_req.header.phy_id = phy_id;
-		ul_config_req.sfn_sf = sfn_sf;
-		ul_config_req.ul_config_request_body.tl.tag = NFAPI_UL_CONFIG_REQUEST_BODY_TAG;
-		ul_config_req.ul_config_request_body.number_of_pdus = num_ul_pdus;
-		ul_config_req.ul_config_request_body.rach_prach_frequency_resources = rand_range(0, 255);
-		ul_config_req.ul_config_request_body.srs_present = rand_range(0, 1);
-		
-		auto ul_config_ulsch_pdu_test_gen = [](nfapi_ul_config_ulsch_pdu& ulsch_pdu)
-		{
-			ulsch_pdu.ulsch_pdu_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_PDU_REL8_TAG;
-			ulsch_pdu.ulsch_pdu_rel8.handle = rand_range(0, 50000);
-			ulsch_pdu.ulsch_pdu_rel8.size = rand_range(0, 32000);
-			ulsch_pdu.ulsch_pdu_rel8.rnti = rand_range(1, 65535);
-			ulsch_pdu.ulsch_pdu_rel8.resource_block_start = rand_range(0, 99);
-			ulsch_pdu.ulsch_pdu_rel8.number_of_resource_blocks = rand_range(1, 100);
-			ulsch_pdu.ulsch_pdu_rel8.modulation_type = rand_range(2, 6);
-			ulsch_pdu.ulsch_pdu_rel8.cyclic_shift_2_for_drms = rand_range(0, 7);
-			ulsch_pdu.ulsch_pdu_rel8.frequency_hopping_enabled_flag = rand_range(0, 1);
-			ulsch_pdu.ulsch_pdu_rel8.frequency_hopping_bits = rand_range(0, 3);
-			ulsch_pdu.ulsch_pdu_rel8.new_data_indication = rand_range(0, 1);
-			ulsch_pdu.ulsch_pdu_rel8.redundancy_version = rand_range(0, 3);
-			ulsch_pdu.ulsch_pdu_rel8.harq_process_number = rand_range(0, 15);
-			ulsch_pdu.ulsch_pdu_rel8.ul_tx_mode = rand_range(0, 1);
-			ulsch_pdu.ulsch_pdu_rel8.current_tx_nb = rand_range(0, 5);
-			ulsch_pdu.ulsch_pdu_rel8.n_srs = rand_range(0, 1);
-			ulsch_pdu.ulsch_pdu_rel10.tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_PDU_REL10_TAG;
-			ulsch_pdu.ulsch_pdu_rel10.resource_allocation_type = rand_range(0, 1);
-			ulsch_pdu.ulsch_pdu_rel10.resource_block_coding = rand_range(0, 35000);
-			ulsch_pdu.ulsch_pdu_rel10.transport_blocks = rand_range(1, 2);
-			ulsch_pdu.ulsch_pdu_rel10.transmission_scheme = rand_range(0, 1);
-			ulsch_pdu.ulsch_pdu_rel10.number_of_layers = rand_range(1, 4);
-			ulsch_pdu.ulsch_pdu_rel10.codebook_index = rand_range(0, 23);
-			ulsch_pdu.ulsch_pdu_rel10.disable_sequence_hopping_flag = rand_range(0, 1);		
-			ulsch_pdu.ulsch_pdu_rel11.tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_PDU_REL11_TAG;
-			ulsch_pdu.ulsch_pdu_rel11.virtual_cell_id_enabled_flag = rand_range(0, 1);
-			ulsch_pdu.ulsch_pdu_rel11.npusch_identity = rand_range(0, 509);
-			ulsch_pdu.ulsch_pdu_rel11.dmrs_config_flag = rand_range(0, 1);
-			ulsch_pdu.ulsch_pdu_rel11.ndmrs_csh_identity = rand_range(0, 509);
-			ulsch_pdu.ulsch_pdu_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_PDU_REL13_TAG;
-			ulsch_pdu.ulsch_pdu_rel13.ue_type = rand_range(0, 2);
-			ulsch_pdu.ulsch_pdu_rel13.total_number_of_repetitions = rand_range(1, 2048);
-			ulsch_pdu.ulsch_pdu_rel13.repetition_number = rand_range(1, 2048);
-			ulsch_pdu.ulsch_pdu_rel13.initial_transmission_sf_io = rand_range(0, 10239);
-			ulsch_pdu.ulsch_pdu_rel13.empty_symbols_due_to_re_tunning = rand_range(0, 8);
-		};
-		
-		auto ul_config_cqi_ri_info_test_gen = [](nfapi_ul_config_cqi_ri_information& cqi_ri_information)
-		{
-			cqi_ri_information.cqi_ri_information_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_CQI_RI_INFORMATION_REL8_TAG;
-			cqi_ri_information.cqi_ri_information_rel8.dl_cqi_pmi_size_rank_1 = rand_range(0, 255);
-			cqi_ri_information.cqi_ri_information_rel8.dl_cqi_pmi_size_rank_greater_1 = rand_range(0, 255);
-			cqi_ri_information.cqi_ri_information_rel8.ri_size = rand_range(0, 3);
-			cqi_ri_information.cqi_ri_information_rel8.delta_offset_cqi = rand_range(0, 15);
-			cqi_ri_information.cqi_ri_information_rel8.delta_offset_ri = rand_range(0, 15);
-
-			cqi_ri_information.cqi_ri_information_rel9.tl.tag = NFAPI_UL_CONFIG_REQUEST_CQI_RI_INFORMATION_REL9_TAG;
-			cqi_ri_information.cqi_ri_information_rel9.report_type = 1; // rand_range(0, 1);
-			cqi_ri_information.cqi_ri_information_rel9.delta_offset_cqi = rand_range(0, 15);
-			cqi_ri_information.cqi_ri_information_rel9.delta_offset_ri = rand_range(0, 15);
-			
-			if(cqi_ri_information.cqi_ri_information_rel9.report_type == 0)
-			{
-				cqi_ri_information.cqi_ri_information_rel9.periodic_cqi_pmi_ri_report.dl_cqi_pmi_ri_size = rand_range(0, 255);
-				cqi_ri_information.cqi_ri_information_rel9.periodic_cqi_pmi_ri_report.control_type = rand_range(0, 1);
-			}
-			else
-			{
-				cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.number_of_cc = 1;
-				cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].ri_size = rand_range(0, 3);
-				cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].dl_cqi_pmi_size[0] = rand_range(0, 255);
-			}
-			
-			cqi_ri_information.cqi_ri_information_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_CQI_RI_INFORMATION_REL13_TAG;
-			cqi_ri_information.cqi_ri_information_rel13.report_type = rand_range(0, 1);
-			
-			if(cqi_ri_information.cqi_ri_information_rel13.report_type == 0)
-			{
-				cqi_ri_information.cqi_ri_information_rel13.periodic_cqi_pmi_ri_report.dl_cqi_pmi_ri_size_2 = rand_range(255, 10000);
-			}
-		};
-		
-		auto ul_config_init_tx_params_test_gen = [](nfapi_ul_config_initial_transmission_parameters& initial_transmission_parameters)
-		{
-			initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG;
-			initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = rand_range(0, 1);
-			initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks = rand_range(1, 100);
-		};
-		
-		auto ul_config_harqinfo_test_gen = [](nfapi_ul_config_ulsch_harq_information& harq_information)
-		{
-			harq_information.harq_information_rel10.tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_HARQ_INFORMATION_REL10_TAG;
-			harq_information.harq_information_rel10.harq_size = rand_range(0, 21);
-			harq_information.harq_information_rel10.delta_offset_harq = rand_range(0, 15);
-			harq_information.harq_information_rel10.ack_nack_mode = rand_range(0, 5);
-			harq_information.harq_information_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_HARQ_INFORMATION_REL13_TAG;
-			harq_information.harq_information_rel13.harq_size_2 = rand_range(0, 21);
-			harq_information.harq_information_rel13.delta_offset_harq_2 = rand_range(0, 15);	
-		};
-
-		auto ul_config_sr_info_test_gen = [](nfapi_ul_config_sr_information& sr_info)
-		{
-			sr_info.sr_information_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_SR_INFORMATION_REL8_TAG;
-			sr_info.sr_information_rel8.pucch_index = rand_range(0, 2047);
-			sr_info.sr_information_rel10.tl.tag = NFAPI_UL_CONFIG_REQUEST_SR_INFORMATION_REL10_TAG;
-			sr_info.sr_information_rel10.number_of_pucch_resources = rand_range(1, 2);
-			sr_info.sr_information_rel10.pucch_index_p1 = rand_range(0, 2047);
-		};
-		
-		auto ul_config_ue_info_test_gen = [](nfapi_ul_config_ue_information& ue_information)
-		{
-			ue_information.ue_information_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL8_TAG;
-			ue_information.ue_information_rel8.handle = rand_range(0, 99999);
-			ue_information.ue_information_rel8.rnti = rand_range(1, 65535);
-			ue_information.ue_information_rel11.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL11_TAG;
-			ue_information.ue_information_rel11.virtual_cell_id_enabled_flag = rand_range(0, 1);
-			ue_information.ue_information_rel11.npusch_identity = rand_range(0, 503);
-			ue_information.ue_information_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL13_TAG;
-			ue_information.ue_information_rel13.ue_type = rand_range(0, 2);
-			ue_information.ue_information_rel13.empty_symbols = rand_range(0, 2);
-			ue_information.ue_information_rel13.total_number_of_repetitions = rand_range(1, 32);
-			ue_information.ue_information_rel13.repetition_number = rand_range(1, 32);
-		};
-		
-		auto ul_config_cqi_info_test_gen = [](nfapi_ul_config_cqi_information& cqi_information)
-		{
-			cqi_information.cqi_information_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_CQI_INFORMATION_REL8_TAG;
-			cqi_information.cqi_information_rel8.pucch_index = rand_range(0, 1184);
-			cqi_information.cqi_information_rel8.dl_cqi_pmi_size = rand_range(0, 255);
-			cqi_information.cqi_information_rel10.tl.tag = NFAPI_UL_CONFIG_REQUEST_CQI_INFORMATION_REL10_TAG;
-			cqi_information.cqi_information_rel10.number_of_pucch_resource = rand_range(1, 2);
-			cqi_information.cqi_information_rel10.pucch_index_p1 = rand_range(0, 1184);
-			cqi_information.cqi_information_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_CQI_INFORMATION_REL13_TAG;
-			cqi_information.cqi_information_rel13.csi_mode = rand_range(0, 2);
-			cqi_information.cqi_information_rel13.dl_cqi_pmi_size_2 = rand_range(0, 999);
-			cqi_information.cqi_information_rel13.starting_prb = rand_range(0, 109);
-			cqi_information.cqi_information_rel13.n_prb = rand_range(0, 7);
-			cqi_information.cqi_information_rel13.cdm_index = rand_range(0, 1);
-			cqi_information.cqi_information_rel13.n_srs = rand_range(0, 1);
-		};
-		
-		auto ul_config_harq_info_test_gen = [](nfapi_ul_config_harq_information& harq_information)
-		{
-			harq_information.harq_information_rel10_tdd.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL10_TDD_TAG;
-			harq_information.harq_information_rel10_tdd.harq_size = rand_range(0, 21);
-			harq_information.harq_information_rel10_tdd.ack_nack_mode = rand_range(0, 5);
-			harq_information.harq_information_rel10_tdd.number_of_pucch_resources = rand_range(0, 4);
-			harq_information.harq_information_rel10_tdd.n_pucch_1_0 = rand_range(0, 2047);
-			harq_information.harq_information_rel10_tdd.n_pucch_1_1 = rand_range(0, 2047);
-			harq_information.harq_information_rel10_tdd.n_pucch_1_2 = rand_range(0, 2047);
-			harq_information.harq_information_rel10_tdd.n_pucch_1_3 = rand_range(0, 2047);
-			harq_information.harq_information_rel8_fdd.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL8_FDD_TAG;
-			harq_information.harq_information_rel8_fdd.n_pucch_1_0 = rand_range(0, 2047);
-			harq_information.harq_information_rel8_fdd.harq_size = rand_range(1, 2);
-			harq_information.harq_information_rel9_fdd.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL9_FDD_TAG;
-			harq_information.harq_information_rel9_fdd.harq_size = rand_range(1, 10);
-			harq_information.harq_information_rel9_fdd.ack_nack_mode = rand_range(0, 4);
-			harq_information.harq_information_rel9_fdd.number_of_pucch_resources = rand_range(0, 4);
-			harq_information.harq_information_rel9_fdd.n_pucch_1_0 = rand_range(0, 2047);
-			harq_information.harq_information_rel9_fdd.n_pucch_1_1 = rand_range(0, 2047);
-			harq_information.harq_information_rel9_fdd.n_pucch_1_2 = rand_range(0, 2047);
-			harq_information.harq_information_rel9_fdd.n_pucch_1_3 = rand_range(0, 2047);
-			harq_information.harq_information_rel11.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL11_TAG;
-			harq_information.harq_information_rel11.num_ant_ports = rand_range(1, 2);
-			harq_information.harq_information_rel11.n_pucch_2_0 = rand_range(0, 2047);
-			harq_information.harq_information_rel11.n_pucch_2_1 = rand_range(0, 2047);
-			harq_information.harq_information_rel11.n_pucch_2_2 = rand_range(0, 2047);
-			harq_information.harq_information_rel11.n_pucch_2_3 = rand_range(0, 2047);
-			harq_information.harq_information_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL13_TAG;
-			harq_information.harq_information_rel13.harq_size_2 = rand_range(0, 999);
-			harq_information.harq_information_rel13.starting_prb = rand_range(0, 109);
-			harq_information.harq_information_rel13.n_prb = rand_range(0, 7);
-			harq_information.harq_information_rel13.cdm_index = rand_range(0, 1);
-			harq_information.harq_information_rel13.n_srs = rand_range(0, 1);
-		};		
-		
-		
-		ul_config_pdus[0].pdu_type = NFAPI_UL_CONFIG_ULSCH_PDU_TYPE;
-		ul_config_ulsch_pdu_test_gen(ul_config_pdus[0].ulsch_pdu);
-
-		ul_config_pdus[1].pdu_type = NFAPI_UL_CONFIG_ULSCH_CQI_RI_PDU_TYPE;
-		ul_config_ulsch_pdu_test_gen(ul_config_pdus[1].ulsch_cqi_ri_pdu.ulsch_pdu);
-		ul_config_cqi_ri_info_test_gen(ul_config_pdus[1].ulsch_cqi_ri_pdu.cqi_ri_information);
-		ul_config_init_tx_params_test_gen(ul_config_pdus[1].ulsch_cqi_ri_pdu.initial_transmission_parameters);	
-
-		ul_config_pdus[2].pdu_type = NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE;
-		ul_config_ulsch_pdu_test_gen(ul_config_pdus[2].ulsch_harq_pdu.ulsch_pdu);
-		ul_config_harqinfo_test_gen(ul_config_pdus[2].ulsch_harq_pdu.harq_information);
-		ul_config_init_tx_params_test_gen(ul_config_pdus[2].ulsch_harq_pdu.initial_transmission_parameters);
-		
-		ul_config_pdus[3].pdu_type = NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE;
-		ul_config_ulsch_pdu_test_gen(ul_config_pdus[3].ulsch_cqi_harq_ri_pdu.ulsch_pdu);		
-		ul_config_cqi_ri_info_test_gen(ul_config_pdus[3].ulsch_cqi_harq_ri_pdu.cqi_ri_information);	
-		ul_config_harqinfo_test_gen(ul_config_pdus[3].ulsch_cqi_harq_ri_pdu.harq_information);
-		ul_config_init_tx_params_test_gen(ul_config_pdus[3].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters);
-		
-		
-		ul_config_pdus[4].pdu_type = NFAPI_UL_CONFIG_UCI_CQI_PDU_TYPE;
-		ul_config_ue_info_test_gen(ul_config_pdus[4].uci_cqi_pdu.ue_information);
-		ul_config_cqi_info_test_gen(ul_config_pdus[4].uci_cqi_pdu.cqi_information);
-
-		ul_config_pdus[5].pdu_type = NFAPI_UL_CONFIG_UCI_SR_PDU_TYPE;
-		ul_config_ue_info_test_gen(ul_config_pdus[5].uci_sr_pdu.ue_information);
-		ul_config_sr_info_test_gen(ul_config_pdus[5].uci_sr_pdu.sr_information);
-
-		
-		ul_config_pdus[6].pdu_type = NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE;
-		ul_config_ue_info_test_gen(ul_config_pdus[6].uci_harq_pdu.ue_information);
-		ul_config_harq_info_test_gen(ul_config_pdus[6].uci_harq_pdu.harq_information);
-		
-		
-		ul_config_pdus[7].pdu_type = NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE;
-		ul_config_ue_info_test_gen(ul_config_pdus[7].uci_sr_harq_pdu.ue_information);
-		ul_config_sr_info_test_gen(ul_config_pdus[7].uci_sr_harq_pdu.sr_information);
-		ul_config_harq_info_test_gen(ul_config_pdus[7].uci_sr_harq_pdu.harq_information);
-		
-		ul_config_pdus[8].pdu_type = NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE;
-		ul_config_ue_info_test_gen(ul_config_pdus[8].uci_cqi_harq_pdu.ue_information);
-		ul_config_cqi_info_test_gen(ul_config_pdus[8].uci_cqi_harq_pdu.cqi_information);
-		ul_config_harq_info_test_gen(ul_config_pdus[8].uci_cqi_harq_pdu.harq_information);
-		
-		ul_config_pdus[9].pdu_type = NFAPI_UL_CONFIG_UCI_CQI_SR_PDU_TYPE;
-		ul_config_ue_info_test_gen(ul_config_pdus[9].uci_cqi_sr_pdu.ue_information);
-		ul_config_cqi_info_test_gen(ul_config_pdus[9].uci_cqi_sr_pdu.cqi_information);
-		ul_config_sr_info_test_gen(ul_config_pdus[9].uci_cqi_sr_pdu.sr_information);
-		
-		ul_config_pdus[10].pdu_type = NFAPI_UL_CONFIG_UCI_CQI_SR_HARQ_PDU_TYPE;
-		ul_config_ue_info_test_gen(ul_config_pdus[10].uci_cqi_sr_harq_pdu.ue_information);
-		ul_config_cqi_info_test_gen(ul_config_pdus[10].uci_cqi_sr_harq_pdu.cqi_information);
-		ul_config_sr_info_test_gen(ul_config_pdus[10].uci_cqi_sr_harq_pdu.sr_information);
-		ul_config_harq_info_test_gen(ul_config_pdus[10].uci_cqi_sr_harq_pdu.harq_information);
-		
-		ul_config_pdus[11].pdu_type = NFAPI_UL_CONFIG_SRS_PDU_TYPE;
-		ul_config_pdus[11].srs_pdu.srs_pdu_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_SRS_PDU_REL8_TAG;
-		ul_config_pdus[11].srs_pdu.srs_pdu_rel8.handle = rand_range(0, 9999);
-		ul_config_pdus[11].srs_pdu.srs_pdu_rel8.size = rand_range(1, 999);
-		ul_config_pdus[11].srs_pdu.srs_pdu_rel8.rnti = rand_range(1, 65535);
-		ul_config_pdus[11].srs_pdu.srs_pdu_rel8.srs_bandwidth = rand_range(0, 3);
-		ul_config_pdus[11].srs_pdu.srs_pdu_rel8.frequency_domain_position = rand_range(0, 23);
-		ul_config_pdus[11].srs_pdu.srs_pdu_rel8.srs_hopping_bandwidth = rand_range(0, 3);
-		ul_config_pdus[11].srs_pdu.srs_pdu_rel8.transmission_comb = rand_range(0, 3);
-		ul_config_pdus[11].srs_pdu.srs_pdu_rel8.i_srs = rand_range(0, 1023);
-		ul_config_pdus[11].srs_pdu.srs_pdu_rel8.sounding_reference_cyclic_shift = rand_range(0, 11);
-		ul_config_pdus[11].srs_pdu.srs_pdu_rel10.tl.tag = NFAPI_UL_CONFIG_REQUEST_SRS_PDU_REL10_TAG;
-		ul_config_pdus[11].srs_pdu.srs_pdu_rel10.antenna_port = rand_range(0, 2);
-		ul_config_pdus[11].srs_pdu.srs_pdu_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_SRS_PDU_REL13_TAG;
-		ul_config_pdus[11].srs_pdu.srs_pdu_rel13.number_of_combs = rand_range(0, 1);
-		
-		ul_config_pdus[12].pdu_type = NFAPI_UL_CONFIG_HARQ_BUFFER_PDU_TYPE;
-		ul_config_ue_info_test_gen(ul_config_pdus[12].harq_buffer_pdu.ue_information);		
-		
-		ul_config_pdus[13].pdu_type = NFAPI_UL_CONFIG_ULSCH_UCI_CSI_PDU_TYPE;
-		ul_config_ulsch_pdu_test_gen(ul_config_pdus[13].ulsch_uci_csi_pdu.ulsch_pdu);
-		ul_config_cqi_info_test_gen(ul_config_pdus[13].ulsch_uci_csi_pdu.csi_information);
-		
-		ul_config_pdus[14].pdu_type = NFAPI_UL_CONFIG_ULSCH_UCI_HARQ_PDU_TYPE;
-		ul_config_ulsch_pdu_test_gen(ul_config_pdus[14].ulsch_uci_harq_pdu.ulsch_pdu);
-		ul_config_harq_info_test_gen(ul_config_pdus[14].ulsch_uci_harq_pdu.harq_information);
-		
-		ul_config_pdus[15].pdu_type = NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE;
-		ul_config_ulsch_pdu_test_gen(ul_config_pdus[15].ulsch_csi_uci_harq_pdu.ulsch_pdu);
-		ul_config_cqi_info_test_gen(ul_config_pdus[15].ulsch_csi_uci_harq_pdu.csi_information);
-		ul_config_harq_info_test_gen(ul_config_pdus[15].ulsch_csi_uci_harq_pdu.harq_information);
-		
-		ul_config_pdus[16].pdu_type = NFAPI_UL_CONFIG_NULSCH_PDU_TYPE;
-		ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_NULSCH_PDU_REL13_TAG;
-		ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.nulsch_format = rand_range(0, 1);
-		ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.handle = rand_range(0, 0xFFFF);
-		ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.size = rand_range(0, 65535);
-		ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.rnti = rand_range(1, 65535);
-		ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.subcarrier_indication = rand_range(0, 47);
-		ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.resource_assignment = rand_range(0, 7);
-		ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.mcs = rand_range(0, 12);
-		ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.redudancy_version = rand_range(0, 1);
-		ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.repetition_number = rand_range(0, 7);
-		ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.new_data_indication = rand_range(0, 1);
-		ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.n_srs = rand_range(0, 1);
-		ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.scrambling_sequence_initialization_cinit = rand_range(0, 65535);
-		ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.sf_idx = rand_range(0, 40960);
-		
-		ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL8_TAG;
-		ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel8.handle = rand_range(0, 0xFF);
-		ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel8.rnti = rand_range(1, 65535);
-		ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel11.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL11_TAG;
-		ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel11.virtual_cell_id_enabled_flag = rand_range(0, 1);
-		ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel11.npusch_identity = rand_range(0, 503);
-		ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL13_TAG;
-		ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel13.ue_type = rand_range(0, 2);
-		ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel13.empty_symbols = rand_range(0, 0x3);
-		ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel13.total_number_of_repetitions = rand_range(1, 32);
-		ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel13.repetition_number = rand_range(1, 32);
-		
-		ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.nb_harq_information.nb_harq_information_rel13_fdd.tl.tag = NFAPI_UL_CONFIG_REQUEST_NB_HARQ_INFORMATION_REL13_FDD_TAG;
-		ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.nb_harq_information.nb_harq_information_rel13_fdd.harq_ack_resource = rand_range(0, 15);
-		
-		ul_config_pdus[17].pdu_type = NFAPI_UL_CONFIG_NRACH_PDU_TYPE;
-		ul_config_pdus[17].nrach_pdu.nrach_pdu_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_NRACH_PDU_REL13_TAG;
-		ul_config_pdus[17].nrach_pdu.nrach_pdu_rel13.nprach_config_0 = rand_range(0, 1);
-		ul_config_pdus[17].nrach_pdu.nrach_pdu_rel13.nprach_config_1 = rand_range(0, 1);
-		ul_config_pdus[17].nrach_pdu.nrach_pdu_rel13.nprach_config_2 = rand_range(0, 1);
-		
-		ul_config_req.ul_config_request_body.ul_config_pdu_list = ul_config_pdus;	
-		mac->ul_config_req(mac, &ul_config_req);
-		
-		
-		uint8_t num_dci_pdus = 4;
-		uint8_t num_hi_pdus = 1;
-		nfapi_hi_dci0_request_pdu_t hi_dci0_pdus[num_dci_pdus + num_hi_pdus];
-		memset(&hi_dci0_pdus, 0, sizeof(hi_dci0_pdus));
-		
-		nfapi_hi_dci0_request_t hi_dci0_req;
-		memset(&hi_dci0_req, 0, sizeof(hi_dci0_req));
-		hi_dci0_req.header.message_id = NFAPI_HI_DCI0_REQUEST;
-		hi_dci0_req.header.phy_id = phy_id;
-		hi_dci0_req.sfn_sf = sfn_sf;
-		
-		hi_dci0_req.hi_dci0_request_body.tl.tag = NFAPI_HI_DCI0_REQUEST_BODY_TAG;
-		hi_dci0_req.hi_dci0_request_body.sfnsf = sfn_sf;
-		hi_dci0_req.hi_dci0_request_body.number_of_dci = num_dci_pdus;
-		hi_dci0_req.hi_dci0_request_body.number_of_hi = num_hi_pdus;
-		
-		hi_dci0_pdus[0].pdu_type = NFAPI_HI_DCI0_HI_PDU_TYPE;
-		hi_dci0_pdus[0].hi_pdu.hi_pdu_rel8.tl.tag = NFAPI_HI_DCI0_REQUEST_HI_PDU_REL8_TAG;
-		hi_dci0_pdus[0].hi_pdu.hi_pdu_rel8.resource_block_start = rand_range(0, 100);
-		hi_dci0_pdus[0].hi_pdu.hi_pdu_rel8.cyclic_shift_2_for_drms = rand_range(0, 7);
-		hi_dci0_pdus[0].hi_pdu.hi_pdu_rel8.hi_value = rand_range(0, 1);
-		hi_dci0_pdus[0].hi_pdu.hi_pdu_rel8.i_phich = rand_range(0, 1);
-		hi_dci0_pdus[0].hi_pdu.hi_pdu_rel8.transmission_power = rand_range(0, 10000);
-		hi_dci0_pdus[0].hi_pdu.hi_pdu_rel10.tl.tag = NFAPI_HI_DCI0_REQUEST_HI_PDU_REL10_TAG;	
-		hi_dci0_pdus[0].hi_pdu.hi_pdu_rel10.flag_tb2 = rand_range(0, 1);
-		hi_dci0_pdus[0].hi_pdu.hi_pdu_rel10.hi_value_2 = rand_range(0, 1);
-		
-		hi_dci0_pdus[1].pdu_type = NFAPI_HI_DCI0_DCI_PDU_TYPE;
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.tl.tag = NFAPI_HI_DCI0_REQUEST_DCI_PDU_REL8_TAG;
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.dci_format = rand_range(0, 4);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.cce_index = rand_range(0, 88);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.aggregation_level = rand_range(1, 8);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.rnti = rand_range(1, 65535);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.resource_block_start = rand_range(0, 100);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.number_of_resource_block = rand_range(0, 100);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.mcs_1 = rand_range(0, 31);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.cyclic_shift_2_for_drms = rand_range(0, 7);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.frequency_hopping_enabled_flag = rand_range(0, 1);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.frequency_hopping_bits = rand_range(0, 3);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.new_data_indication_1 = rand_range(0, 1);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.ue_tx_antenna_seleciton = rand_range(0, 2);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.tpc = rand_range(0, 3);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.cqi_csi_request = rand_range(0, 7);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.ul_index = rand_range(0, 3);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.dl_assignment_index = rand_range(1, 4);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.tpc_bitmap = rand_range(0, 9999);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.transmission_power = rand_range(0, 10000);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.tl.tag = NFAPI_HI_DCI0_REQUEST_DCI_PDU_REL10_TAG;
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.cross_carrier_scheduling_flag = rand_range(0, 1);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.carrier_indicator = rand_range(0, 7);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.size_of_cqi_csi_feild = rand_range(0, 2);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.srs_flag = rand_range(0, 1);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.srs_request = rand_range(0, 1);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.resource_allocation_flag = rand_range(0, 1);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.resource_allocation_type = rand_range(0, 1);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.resource_block_coding = rand_range(0, 9999);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.mcs_2 = rand_range(0, 31);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.new_data_indication_2 = rand_range(0, 1);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.number_of_antenna_ports = rand_range(0, 2);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.tpmi = rand_range(0, 63);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.total_dci_length_including_padding = rand_range(0, 255);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.n_ul_rb = rand_range(6, 100);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel12.tl.tag = NFAPI_HI_DCI0_REQUEST_DCI_PDU_REL12_TAG;
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel12.pscch_resource = rand_range(0, 16);
-		hi_dci0_pdus[1].dci_pdu.dci_pdu_rel12.time_resource_pattern = rand_range(0, 32);
-		
-		
-		hi_dci0_pdus[2].pdu_type = NFAPI_HI_DCI0_EPDCCH_DCI_PDU_TYPE;
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.tl.tag = NFAPI_HI_DCI0_REQUEST_EPDCCH_DCI_PDU_REL8_TAG;
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.dci_format = rand_range(0, 4);
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.cce_index = rand_range(0, 88);
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.aggregation_level = rand_range(1, 8);
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.rnti = rand_range(1, 65535);
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.resource_block_start = rand_range(0, 100);
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.number_of_resource_block = rand_range(0, 100);
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.mcs_1 = rand_range(0, 31);
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.cyclic_shift_2_for_drms = rand_range(0, 7);
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.frequency_hopping_enabled_flag = rand_range(0, 1);
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.frequency_hopping_bits = rand_range(0, 3);
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.new_data_indication_1 = rand_range(0, 1);
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.ue_tx_antenna_seleciton = rand_range(0, 2);
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.tpc = rand_range(0, 3);
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.cqi_csi_request = rand_range(0, 7);
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.ul_index = rand_range(0, 3);
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.dl_assignment_index = rand_range(1, 4);
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.tpc_bitmap = rand_range(0, 9999);
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.transmission_power = rand_range(0, 10000);		
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.tl.tag = NFAPI_HI_DCI0_REQUEST_EPDCCH_DCI_PDU_REL10_TAG;
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.cross_carrier_scheduling_flag = rand_range(0, 1);
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.carrier_indicator = rand_range(0, 7);
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.size_of_cqi_csi_feild = rand_range(0, 2);
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.srs_flag = rand_range(0, 1);
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.srs_request = rand_range(0, 1);
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.resource_allocation_flag = rand_range(0, 1);
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.resource_allocation_type = rand_range(0, 1);
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.resource_block_coding = rand_range(0, 9999);
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.mcs_2 = rand_range(0, 31);
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.new_data_indication_2 = rand_range(0, 1);
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.number_of_antenna_ports = rand_range(0, 2);
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.tpmi = rand_range(0, 63);
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.total_dci_length_including_padding = rand_range(0, 255);
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.n_ul_rb = rand_range(6, 100);			
-		hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_parameters_rel11.tl.tag = NFAPI_HI_DCI0_REQUEST_EPDCCH_PARAMETERS_REL11_TAG;
-		
-		hi_dci0_pdus[3].pdu_type = NFAPI_HI_DCI0_MPDCCH_DCI_PDU_TYPE;
-		hi_dci0_pdus[3].mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.tl.tag = NFAPI_HI_DCI0_REQUEST_MPDCCH_DCI_PDU_REL13_TAG;
-
-		hi_dci0_pdus[4].pdu_type = NFAPI_HI_DCI0_NPDCCH_DCI_PDU_TYPE;
-		hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.tl.tag = NFAPI_HI_DCI0_REQUEST_NPDCCH_DCI_PDU_REL13_TAG;
-		hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.ncce_index = rand_range(0, 1);
-		hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.aggregation_level = rand_range(1, 2);
-		hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.start_symbol = rand_range(0, 4);
-		hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.rnti = rand_range(1, 65535);
-		hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.scrambling_reinitialization_batch_index = rand_range(1, 4);
-		hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.nrs_antenna_ports_assumed_by_the_ue = rand_range(1, 2);
-		hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.subcarrier_indication = rand_range(0, 63);
-		hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.resource_assignment = rand_range(0, 7);
-		hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.scheduling_delay = rand_range(0, 3);
-		hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.mcs = rand_range(0, 12);
-		hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.redudancy_version = rand_range(0, 1);
-		hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.repetition_number = rand_range(0, 7);
-		hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.new_data_indicator = rand_range(0, 1);
-		hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.dci_subframe_repetition_number = rand_range(0, 3);
-		
-		hi_dci0_req.hi_dci0_request_body.hi_dci0_pdu_list = hi_dci0_pdus;
-		mac->hi_dci0_req(mac, &hi_dci0_req);
-
-		uint8_t num_tx_pdus = 2;
-		nfapi_tx_request_pdu_t tx_pdus[num_tx_pdus];
-		memset(&tx_pdus, 0, sizeof(tx_pdus));
-		
-		nfapi_tx_request_t tx_req;
-		memset(&tx_req, 0, sizeof(tx_req));
-		tx_req.header.message_id = NFAPI_TX_REQUEST;
-		tx_req.header.phy_id = phy_id;
-		tx_req.sfn_sf = sfn_sf;
-		
-		tx_req.tx_request_body.tl.tag = NFAPI_TX_REQUEST_BODY_TAG;
-		tx_req.tx_request_body.number_of_pdus = num_tx_pdus;
-		
-		uint32_t data[2];
-		data[0] = 0x11223344;
-		data[1] = 0x55667788;
-		
-		tx_pdus[0].pdu_length = 8;
-		tx_pdus[0].pdu_index = 1;
-		tx_pdus[0].num_segments = 2;
-		tx_pdus[0].segments[0].segment_length = 4;
-		tx_pdus[0].segments[0].segment_data = (uint8_t*)&data[0];
-		tx_pdus[0].segments[1].segment_length = 4;
-		tx_pdus[0].segments[1].segment_data = (uint8_t*)&data[1];
-		
-		tx_pdus[1].pdu_length = 8;
-		tx_pdus[1].pdu_index = 2;
-		tx_pdus[1].num_segments = 2;
-		tx_pdus[1].segments[0].segment_length = 4;
-		tx_pdus[1].segments[0].segment_data = (uint8_t*)&data[0];
-		tx_pdus[1].segments[1].segment_length = 4;
-		tx_pdus[1].segments[1].segment_data = (uint8_t*)&data[1];		
-		
-		
-		tx_req.tx_request_body.tx_pdu_list = tx_pdus;
-		mac->tx_req(mac, &tx_req);
-	}
-	
-	void generate_subframe(mac_t *mac, uint16_t phy_id, uint16_t sfn_sf)
-	{
-		mac_internal_t* instance = (mac_internal_t*)mac;
-				
-		nfapi_dl_config_request_t dl_config_req;
-		memset(&dl_config_req, 0, sizeof(dl_config_req));
-		dl_config_req.header.message_id = NFAPI_DL_CONFIG_REQUEST;
-		dl_config_req.header.phy_id = phy_id;
-		dl_config_req.sfn_sf = sfn_sf;
-
-		dl_config_req.dl_config_request_body.tl.tag = NFAPI_DL_CONFIG_REQUEST_BODY_TAG;
-		dl_config_req.dl_config_request_body.number_pdu = 8;
-
-		nfapi_dl_config_request_pdu_t pdus[8];
-		memset(&pdus, 0, sizeof(pdus));
-		for(int i = 0; i < 8; i++)
-		{
-			pdus[i].pdu_type = NFAPI_DL_CONFIG_BCH_PDU_TYPE;
-
-			pdus[i].bch_pdu.bch_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_BCH_PDU_REL8_TAG;
-			pdus[i].bch_pdu.bch_pdu_rel8.length = 42;
-			pdus[i].bch_pdu.bch_pdu_rel8.pdu_index = i;
-			pdus[i].bch_pdu.bch_pdu_rel8.transmission_power = 56;
-
-		}
-
-		dl_config_req.dl_config_request_body.dl_config_pdu_list = pdus;
-
-		/*
-		vendor_ext_tlv_1 ve;
-		ve.tl.tag = VENDOR_EXT_TLV_1_TAG;
-		ve.dummy = 999;
-		dl_config_req.vendor_extension = &ve.tl;
-		*/
-
-		mac->dl_config_req(mac, &dl_config_req);	
-
-
-		nfapi_ul_config_request_t ul_config_req;
-		memset(&ul_config_req, 0, sizeof(ul_config_req));
-		ul_config_req.header.message_id = NFAPI_UL_CONFIG_REQUEST;
-		ul_config_req.header.phy_id = phy_id;
-		ul_config_req.sfn_sf = sfn_sf;
-		mac->ul_config_req(mac, &ul_config_req);
-
-		nfapi_hi_dci0_request_t hi_dci0_req;
-		memset(&hi_dci0_req, 0, sizeof(hi_dci0_req));
-		hi_dci0_req.header.message_id = NFAPI_HI_DCI0_REQUEST;
-		hi_dci0_req.header.phy_id = phy_id;
-		hi_dci0_req.sfn_sf = sfn_sf;
-		mac->hi_dci0_req(mac, &hi_dci0_req);
-
-
-
-		nfapi_tx_request_t tx_req;
-		memset(&tx_req, 0, sizeof(tx_req));
-		tx_req.header.message_id = NFAPI_TX_REQUEST;
-		tx_req.header.phy_id = phy_id;
-		tx_req.sfn_sf = sfn_sf;
-
-		nfapi_tx_request_pdu_t tx_pdus[8];
-
-		tx_req.tx_request_body.tl.tag = NFAPI_TX_REQUEST_BODY_TAG;
-		tx_req.tx_request_body.number_of_pdus = 0;
-		tx_req.tx_request_body.tx_pdu_list = &tx_pdus[0];
-
-		mac_pdu* buff = 0;
-		int i = 0;
-		std::list<mac_pdu*> free_list;
-		do
-		{
-			buff = instance->mac->pop_rx_buffer();
-			if(buff != 0)
-			{
-				if(buff->len == 0)
-				{
-					printf("[MAC] Buffer length = 0\n");
-				}
-
-				tx_req.tx_request_body.tx_pdu_list[i].pdu_length = buff->len;
-				tx_req.tx_request_body.tx_pdu_list[i].pdu_index = i;
-				tx_req.tx_request_body.tx_pdu_list[i].num_segments = 1;
-				tx_req.tx_request_body.tx_pdu_list[i].segments[0].segment_length = buff->len;
-				tx_req.tx_request_body.tx_pdu_list[i].segments[0].segment_data = (uint8_t*)buff->buffer;
-
-				tx_req.tx_request_body.number_of_pdus++;
-				i++;
-
-				instance->mac->byte_count += buff->len;
-
-				free_list.push_back(buff);
-			}
-		}while(buff != 0 && i < 8);
-
-		mac->tx_req(mac, &tx_req);
-
-		//for(int j = 0; j < tx_req.tx_request_body.number_of_pdus; ++j)
-		for(mac_pdu* pdu : free_list)
-		{
-			instance->mac->release_mac_pdu(pdu);
-			//free(tx_req.tx_request_body.tx_pdu_list[j].segments[0].segment_data);
-		}
-	}
-	
-	void mac_subframe_ind(mac_t *mac, uint16_t phy_id, uint16_t sfn_sf)
-	{
-
-		
-		//printf("[MAC] subframe indication phyid:%d sfnsf:%d\n", phy_id, sfn_sf);
-		mac_internal_t* instance = (mac_internal_t*)mac;
-
-		if(instance->mac->tick == 1000)
-		{
-			if(instance->mac->byte_count > 0)
-			{
-				printf("[MAC] Rx rate %d bytes/sec\n", instance->mac->byte_count);
-				instance->mac->byte_count = 0;
-			}
-			instance->mac->tick = 0;
-		}
-		instance->mac->tick++;
-		
-		if(instance->mac->wireshark_test_mode)
-		{
-			generate_test_subframe(mac, phy_id, sfn_sf);
-		}
-		else
-		{
-			generate_subframe(mac, phy_id, sfn_sf);
-		}
-	}	
-	
-	void mac_harq_ind(mac_t* mac, nfapi_harq_indication_t* ind)
-	{
-	}
-	void mac_crc_ind(mac_t* mac, nfapi_crc_indication_t* ind)
-	{
-	}
-	void mac_rx_ind(mac_t* mac, nfapi_rx_indication_t* ind)
-	{
-		mac_internal_t* instance = (mac_internal_t*)mac;
-
-		for(int i = 0; i < ind->rx_indication_body.number_of_pdus; ++i)
-		{
-			uint16_t len = ind->rx_indication_body.rx_pdu_list[i].rx_indication_rel8.length;
-			uint8_t* data = ind->rx_indication_body.rx_pdu_list[i].data;
-			//printf("[MAC] sfnsf:%d len:%d\n", ind->sfn_sf,len);
-			//
-			instance->tx_byte_count += len;
-
-			int sendto_result = sendto(instance->tx_sock, data, len, 0, (struct sockaddr*)&(instance->tx_addr), sizeof(instance->tx_addr));
-			
-			if(sendto_result < 0)
-			{
-				// error
-			}
-		}
-
-	}
-	void mac_rach_ind(mac_t* mac, nfapi_rach_indication_t* ind)
-	{
-	}
-	void mac_srs_ind(mac_t* mac, nfapi_srs_indication_t* ind)
-	{
-	}
-	void mac_sr_ind(mac_t* mac, nfapi_sr_indication_t* ind)
-	{
-	}
-	void mac_cqi_ind(mac_t* mac, nfapi_cqi_indication_t* ind)
-	{
-	}
-	void mac_lbt_dl_ind(mac_t* mac, nfapi_lbt_dl_indication_t* ind)
-	{
-	}
-	void mac_nb_harq_ind(mac_t* mac, nfapi_nb_harq_indication_t* ind)
-	{
-	}
-	void mac_nrach_ind(mac_t* mac, nfapi_nrach_indication_t* ind)
-	{
-	}
+  typedef struct {
+    mac_t _public;
+
+    int rx_sock;
+    int tx_sock;
+    struct sockaddr_in tx_addr;
+
+    uint32_t tx_byte_count;
+
+    mac_private *mac;
+
+  } mac_internal_t;
+
+  mac_t *mac_create(uint8_t wireshark_test_mode) {
+    mac_internal_t *instance = (mac_internal_t *)malloc(sizeof(mac_internal_t));
+    instance->mac = new mac_private((wireshark_test_mode >= 1));
+    return (mac_t *)instance;
+  }
+
+  void mac_destroy(mac_t *mac) {
+    mac_internal_t *instance = (mac_internal_t *)mac;
+    delete instance->mac;
+    free(instance);
+  }
+
+  void *mac_rx_thread_start(void *ptr) {
+    mac_internal_t *instance = (mac_internal_t *)ptr;
+
+    while(1) {
+      mac_pdu *pdu = instance->mac->allocate_mac_pdu();
+      int len = recvfrom(instance->rx_sock, pdu->buffer, pdu->buffer_len, 0, 0, 0);
+
+      if(len > 0) {
+        pdu->len = len;
+        instance->mac->push_rx_buffer(pdu);
+      } else {
+        instance->mac->release_mac_pdu(pdu);
+      }
+    }
+
+    return 0;
+  }
+
+  void mac_start_data(mac_t *mac, unsigned rx_port, const char *tx_address, unsigned tx_port) {
+    mac_internal_t *instance = (mac_internal_t *)mac;
+    printf("[MAC] Rx Data from %u\n", rx_port);
+    printf("[MAC] Tx Data to %s.%u\n", tx_address, tx_port);
+    instance->rx_sock = socket(AF_INET, SOCK_DGRAM, 0);
+
+    if(instance->rx_sock < 0) {
+      printf("[MAC] Failed to create socket\n");
+      return;
+    }
+
+    struct sockaddr_in addr;
+
+    memset(&addr, 0, sizeof(sockaddr_in));
+
+    addr.sin_family = AF_INET;
+
+    addr.sin_port = htons(rx_port);
+
+    addr.sin_addr.s_addr = INADDR_ANY;
+
+    if(bind(instance->rx_sock, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) < 0) {
+      printf("[MAC] Failed to bind to %u\n", rx_port);
+      close(instance->rx_sock);
+      return;
+    }
+
+    pthread_t mac_rx_thread;
+    pthread_create(&mac_rx_thread, NULL, &mac_rx_thread_start, instance);
+    instance->tx_sock = socket(AF_INET, SOCK_DGRAM, 0);
+    instance->tx_addr.sin_family = AF_INET;
+    instance->tx_addr.sin_port = htons(tx_port);
+    instance->tx_addr.sin_addr.s_addr = inet_addr(tx_address);
+  }
+
+
+
+  void generate_test_subframe(mac_t *mac, uint16_t phy_id, uint16_t sfn_sf) {
+    //mac_internal_t* instance = (mac_internal_t*)mac;
+    uint8_t max_num_dl_pdus = 50;
+    nfapi_dl_config_request_pdu_t dl_config_pdus[max_num_dl_pdus];
+    memset(&dl_config_pdus, 0, sizeof(dl_config_pdus));
+    nfapi_dl_config_request_t dl_config_req;
+    memset(&dl_config_req, 0, sizeof(dl_config_req));
+    dl_config_req.header.message_id = NFAPI_DL_CONFIG_REQUEST;
+    dl_config_req.header.phy_id = phy_id;
+    dl_config_req.sfn_sf = sfn_sf;
+    dl_config_req.dl_config_request_body.tl.tag = NFAPI_DL_CONFIG_REQUEST_BODY_TAG;
+    dl_config_req.dl_config_request_body.number_pdu = rand_range(4, max_num_dl_pdus);
+    uint16_t i = 0;
+
+    for(i = 0; i < dl_config_req.dl_config_request_body.number_pdu; ++i) {
+      dl_config_pdus[i].pdu_type = rand_range(0, 11);
+
+      switch(dl_config_pdus[i].pdu_type) {
+        case NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE: {
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL8_TAG;
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.dci_format = rand_range(0, 9);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.cce_idx = rand_range(0, 255);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level  = rand_range(0, 32);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti = rand_range(0, (uint16_t)-1);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.resource_allocation_type = rand_range(0, 1);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.virtual_resource_block_assignment_flag = rand_range(0, 1);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.resource_block_coding = rand_range(0, 320000);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.mcs_1 = rand_range(0, 31);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_1 = rand_range(0, 3);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_1 = rand_range(0, 1);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.transport_block_to_codeword_swap_flag = rand_range(0, 1);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.mcs_2 = rand_range(0, 31);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_2 = rand_range(0, 31);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_2 = rand_range(0, 1);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.harq_process = rand_range(0, 31);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.tpmi = rand_range(0, 15);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.pmi = rand_range(0, 1);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.precoding_information = rand_range(0, 63);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.tpc = rand_range(0, 3);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.downlink_assignment_index = rand_range(0, 15);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.ngap = rand_range(0, 1);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.transport_block_size_index = rand_range(0, 31);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.downlink_power_offset = rand_range(0, 1);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.allocate_prach_flag = rand_range(0, 1);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.preamble_index = rand_range(0, 63);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.prach_mask_index = rand_range(0, 15);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti_type = rand_range(0, 3);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.transmission_power = rand_range(0, 10000);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel9.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL9_TAG;
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel9.mcch_flag = rand_range(0, 1);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel9.mcch_change_notification = rand_range(0, 255);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel9.scrambling_identity = rand_range(0, 1);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL10_TAG;
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.cross_carrier_scheduling_flag = rand_range(0, 1);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.carrier_indicator = rand_range(0, 7);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.srs_flag = rand_range(0, 1);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.srs_request = rand_range(0, 1);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.antenna_ports_scrambling_and_layers = rand_range(0, 15);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.total_dci_length_including_padding = rand_range(0, 255);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.n_dl_rb = rand_range(0, 100);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel11.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL11_TAG;
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel11.harq_ack_resource_offset = rand_range(0, 3);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel11.pdsch_re_mapping_quasi_co_location_indicator = rand_range(0, 3);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel12.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL12_TAG;
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel12.primary_cell_type = rand_range(0, 2);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel12.ul_dl_configuration_flag = rand_range(0, 1);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel12.number_ul_dl_configurations = 2;
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel12.ul_dl_configuration_indication[0] = rand_range(1, 5);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel12.ul_dl_configuration_indication[1] = rand_range(1, 5);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL13_TAG;
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.laa_end_partial_sf_flag = rand_range(0, 1);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.laa_end_partial_sf_configuration = rand_range(0, 255);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.initial_lbt_sf = rand_range(0, 1);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.codebook_size_determination = rand_range(0, 1);
+          dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.drms_table_flag = rand_range(0, 1);
+
+          // if the tpm extention is present of not.
+          if(rand_range(0, 1)) {
+            dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm_struct_flag = rand_range(0, 1);
+            dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.num_prb_per_subband = rand_range(0, 8);
+            dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.number_of_subbands = rand_range(0, 13);
+            dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.num_antennas = 1; // rand_range(0, 8);
+
+            for(int j = 0; j < dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.number_of_subbands; ++j) {
+              dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.subband_info[j].subband_index = j;
+              dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.subband_info[j].scheduled_ues = 1; //rand_range(1, 4);
+
+              for(int k = 0; k < dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.num_antennas; ++k)
+                for(int l = 0; l < dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.subband_info[j].scheduled_ues; ++l)
+                  dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.subband_info[j].precoding_value[k][l] = rand_range(0, 65535);
+            }
+          } else {
+            dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm_struct_flag = 0;
+          }
+        }
+        break;
+
+        case NFAPI_DL_CONFIG_BCH_PDU_TYPE: {
+          dl_config_pdus[i].bch_pdu.bch_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_BCH_PDU_REL8_TAG;
+          dl_config_pdus[i].bch_pdu.bch_pdu_rel8.length = rand_range(0, 42);
+          dl_config_pdus[i].bch_pdu.bch_pdu_rel8.pdu_index = rand_range(0, 65535);
+          dl_config_pdus[i].bch_pdu.bch_pdu_rel8.transmission_power = rand_range(0, 10000);
+        }
+        break;
+
+        case NFAPI_DL_CONFIG_MCH_PDU_TYPE: {
+          dl_config_pdus[i].mch_pdu.mch_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_MCH_PDU_REL8_TAG;
+          dl_config_pdus[i].mch_pdu.mch_pdu_rel8.length = rand_range(0, 42);
+          dl_config_pdus[i].mch_pdu.mch_pdu_rel8.pdu_index = rand_range(0, 65535);
+          dl_config_pdus[i].mch_pdu.mch_pdu_rel8.rnti = 0xFFFD;
+          dl_config_pdus[i].mch_pdu.mch_pdu_rel8.resource_allocation_type = 0;
+          dl_config_pdus[i].mch_pdu.mch_pdu_rel8.resource_block_coding = 0;
+          dl_config_pdus[i].mch_pdu.mch_pdu_rel8.modulation = rand_range(0, 8);
+          dl_config_pdus[i].mch_pdu.mch_pdu_rel8.transmission_power = rand_range(0, 10000);
+          dl_config_pdus[i].mch_pdu.mch_pdu_rel8.mbsfn_area_id = rand_range(0, 255);
+        }
+        break;
+
+        case NFAPI_DL_CONFIG_DLSCH_PDU_TYPE: {
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL8_TAG;
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.length = rand_range(0, 42);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.pdu_index = rand_range(0, 65535);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.rnti = rand_range(1, 65535);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.resource_allocation_type = rand_range(0, 5);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.virtual_resource_block_assignment_flag = rand_range(0, 1);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.resource_block_coding = rand_range(0, 32000);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.modulation = rand_range(2, 8);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.redundancy_version = rand_range(0, 3);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.transport_blocks = rand_range(1, 2);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.transport_block_to_codeword_swap_flag = rand_range(0, 1);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.transmission_scheme = rand_range(0, 13);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.number_of_layers = rand_range(1, 8);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.number_of_subbands = 2; //rand_range(0, 13);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.codebook_index[0] = rand_range(0, 15);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.codebook_index[1] = rand_range(0, 15);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.ue_category_capacity = rand_range(0, 14);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.pa = rand_range(0, 7);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.delta_power_offset_index = rand_range(0, 1);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.ngap = rand_range(0, 1);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.nprb = rand_range(0, 1);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.transmission_mode = rand_range(1, 10);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.num_bf_prb_per_subband = 2; //rand_range(0, 1);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.num_bf_vector = 2; //rand_range(0, 1);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.bf_vector[0].subband_index = rand_range(0, 4);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.bf_vector[0].num_antennas = 1;
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.bf_vector[0].bf_value[0] = rand_range(0, 128);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.bf_vector[1].subband_index = rand_range(0, 4);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.bf_vector[1].num_antennas = 1;
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.bf_vector[1].bf_value[0] = rand_range(0, 128);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel9.tl.tag = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL9_TAG;
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel9.nscid = rand_range(0, 1);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel10.tl.tag = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL10_TAG;
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel10.csi_rs_flag = rand_range(0, 1);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel10.csi_rs_resource_config_r10 = 0;
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel10.csi_rs_zero_tx_power_resource_config_bitmap_r10 = rand_range(0, 65535);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel10.csi_rs_number_nzp_configuration = 1;
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel10.csi_rs_resource_config[0] = rand_range(0, 31);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel10.pdsch_start = rand_range(0, 4);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.tl.tag = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL11_TAG;
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.drms_config_flag = rand_range(0, 1);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.drms_scrambling = rand_range(0, 503);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.csi_config_flag = rand_range(0, 1);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.csi_scrambling = rand_range(0, 503);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.pdsch_re_mapping_flag = rand_range(0, 1);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.pdsch_re_mapping_atenna_ports = rand_range(1,4);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.pdsch_re_mapping_freq_shift = rand_range(0, 5);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel12.tl.tag = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL12_TAG;
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel12.altcqi_table_r12 = rand_range(0, 1);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel12.maxlayers = rand_range(1, 8);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel12.n_dl_harq = rand_range(0, 255);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel13.dwpts_symbols = rand_range(3, 14);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel13.initial_lbt_sf = rand_range(0, 1);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel13.ue_type = rand_range(0, 2);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel13.pdsch_payload_type = rand_range(0, 2);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel13.initial_transmission_sf_io = rand_range(0, 10239);
+          dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel13.drms_table_flag = rand_range(0, 1);
+        }
+        break;
+
+        case NFAPI_DL_CONFIG_PCH_PDU_TYPE: {
+          dl_config_pdus[i].pch_pdu.pch_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_PCH_PDU_REL8_TAG;
+          dl_config_pdus[i].pch_pdu.pch_pdu_rel8.length = rand_range(0, 42);
+          dl_config_pdus[i].pch_pdu.pch_pdu_rel8.pdu_index = rand_range(0, 65535);
+          dl_config_pdus[i].pch_pdu.pch_pdu_rel8.p_rnti = 0xFFFE;
+          dl_config_pdus[i].pch_pdu.pch_pdu_rel8.resource_allocation_type = rand_range(2, 6);
+          dl_config_pdus[i].pch_pdu.pch_pdu_rel8.virtual_resource_block_assignment_flag = rand_range(0, 1);
+          dl_config_pdus[i].pch_pdu.pch_pdu_rel8.resource_block_coding = rand_range(0, 34000);
+          dl_config_pdus[i].pch_pdu.pch_pdu_rel8.mcs = 0;
+          dl_config_pdus[i].pch_pdu.pch_pdu_rel8.redundancy_version = 0;
+          dl_config_pdus[i].pch_pdu.pch_pdu_rel8.number_of_transport_blocks = 1;
+          dl_config_pdus[i].pch_pdu.pch_pdu_rel8.transport_block_to_codeword_swap_flag = 0;
+          dl_config_pdus[i].pch_pdu.pch_pdu_rel8.transmission_scheme = rand_range(1, 6);
+          dl_config_pdus[i].pch_pdu.pch_pdu_rel8.number_of_layers = rand_range(1, 4);
+          dl_config_pdus[i].pch_pdu.pch_pdu_rel8.codebook_index = 0;
+          dl_config_pdus[i].pch_pdu.pch_pdu_rel8.ue_category_capacity = rand_range(0, 14);
+          dl_config_pdus[i].pch_pdu.pch_pdu_rel8.pa = rand_range(0, 7);
+          dl_config_pdus[i].pch_pdu.pch_pdu_rel8.transmission_power = rand_range(0, 10000);
+          dl_config_pdus[i].pch_pdu.pch_pdu_rel8.nprb = rand_range(0, 1);
+          dl_config_pdus[i].pch_pdu.pch_pdu_rel8.ngap = rand_range(0, 1);
+          dl_config_pdus[i].pch_pdu.pch_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_PCH_PDU_REL13_TAG;
+          dl_config_pdus[i].pch_pdu.pch_pdu_rel13.ue_mode = rand_range(0, 1);
+          dl_config_pdus[i].pch_pdu.pch_pdu_rel13.initial_transmission_sf_io = rand_range(0, 10239);
+        }
+        break;
+
+        case NFAPI_DL_CONFIG_PRS_PDU_TYPE: {
+          dl_config_pdus[i].prs_pdu.prs_pdu_rel9.tl.tag = NFAPI_DL_CONFIG_REQUEST_PRS_PDU_REL9_TAG;
+          dl_config_pdus[i].prs_pdu.prs_pdu_rel9.transmission_power = rand_range(0, 10000);
+          dl_config_pdus[i].prs_pdu.prs_pdu_rel9.prs_bandwidth = rand_range(6, 100);
+          dl_config_pdus[i].prs_pdu.prs_pdu_rel9.prs_cyclic_prefix_type = rand_range(0, 1);
+          dl_config_pdus[i].prs_pdu.prs_pdu_rel9.prs_muting = rand_range(0, 1);
+        }
+        break;
+
+        case NFAPI_DL_CONFIG_CSI_RS_PDU_TYPE: {
+          dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.tl.tag = NFAPI_DL_CONFIG_REQUEST_CSI_RS_PDU_REL10_TAG;
+          dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.csi_rs_antenna_port_count_r10 = rand_range(1, 16);
+          dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.csi_rs_resource_config_r10 = 0;
+          dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.transmission_power = rand_range(0, 10000);
+          dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.csi_rs_zero_tx_power_resource_config_bitmap_r10 = rand_range(0, 8);
+          dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.csi_rs_number_of_nzp_configuration = 2;
+          dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.csi_rs_resource_config[0] = rand_range(0, 31);
+          dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.csi_rs_resource_config[1] = rand_range(0, 31);
+          dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_CSI_RS_PDU_REL13_TAG;
+          dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel13.csi_rs_class = rand_range(0, 2);
+          dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel13.cdm_type = rand_range(0, 1);
+          dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel13.num_bf_vector = 0; // set to zero as not clear how to handle bf value array
+          dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel13.bf_vector[0].csi_rs_resource_index = rand_range(0, 7);
+          dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel13.bf_vector[0].bf_value[0] = 42;
+        }
+        break;
+
+        case NFAPI_DL_CONFIG_EPDCCH_DL_PDU_TYPE: {
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PDU_REL8_TAG;
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.dci_format = rand_range(0, 9);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.cce_idx = rand_range(0, 255);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.aggregation_level  = rand_range(0, 32);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.rnti = rand_range(0, (uint16_t)-1);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.resource_allocation_type = rand_range(0, 1);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.virtual_resource_block_assignment_flag = rand_range(0, 1);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.resource_block_coding = rand_range(0, 320000);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.mcs_1 = rand_range(0, 31);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.redundancy_version_1 = rand_range(0, 3);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.new_data_indicator_1 = rand_range(0, 1);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.transport_block_to_codeword_swap_flag = rand_range(0, 1);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.mcs_2 = rand_range(0, 31);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.redundancy_version_2 = rand_range(0, 31);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.new_data_indicator_2 = rand_range(0, 1);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.harq_process = rand_range(0, 31);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.tpmi = rand_range(0, 15);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.pmi = rand_range(0, 1);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.precoding_information = rand_range(0, 63);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.tpc = rand_range(0, 3);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.downlink_assignment_index = rand_range(0, 15);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.ngap = rand_range(0, 1);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.transport_block_size_index = rand_range(0, 31);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.downlink_power_offset = rand_range(0, 1);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.allocate_prach_flag = rand_range(0, 1);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.preamble_index = rand_range(0, 63);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.prach_mask_index = rand_range(0, 15);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.rnti_type = rand_range(0, 3);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.transmission_power = rand_range(0, 10000);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel9.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PDU_REL9_TAG;
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel9.mcch_flag = rand_range(0, 1);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel9.mcch_change_notification = rand_range(0, 255);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel9.scrambling_identity = rand_range(0, 1);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PDU_REL10_TAG;
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.cross_carrier_scheduling_flag = rand_range(0, 1);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.carrier_indicator = rand_range(0, 7);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.srs_flag = rand_range(0, 1);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.srs_request = rand_range(0, 1);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.antenna_ports_scrambling_and_layers = rand_range(0, 15);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.total_dci_length_including_padding = rand_range(0, 255);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.n_dl_rb = rand_range(0, 100);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel11.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PDU_REL11_TAG;
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel11.harq_ack_resource_offset = rand_range(0, 3);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel11.pdsch_re_mapping_quasi_co_location_indicator = rand_range(0, 3);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel12.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PDU_REL12_TAG;
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel12.primary_cell_type = rand_range(0, 2);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel12.ul_dl_configuration_flag = rand_range(0, 1);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel12.number_ul_dl_configurations = 2;
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel12.ul_dl_configuration_indication[0] = rand_range(1, 5);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel12.ul_dl_configuration_indication[1] = rand_range(1, 5);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PDU_REL13_TAG;
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel13.laa_end_partial_sf_flag = rand_range(0, 1);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel13.laa_end_partial_sf_configuration = rand_range(0, 255);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel13.initial_lbt_sf = rand_range(0, 1);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel13.codebook_size_determination = rand_range(0, 1);
+          dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel13.drms_table_flag = rand_range(0, 1);
+          dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PARAM_REL11_TAG;
+          dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.epdcch_resource_assignment_flag = rand_range(0, 1);
+          dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.epdcch_id = rand_range(0, 503);
+          dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.epdcch_start_symbol = rand_range(1, 4);
+          dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.epdcch_num_prb = rand_range(2, 8);
+
+          for(int j = 0; j < dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.epdcch_num_prb; ++j)
+            dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.epdcch_prb_index[j] = rand_range(0, 99);
+
+          dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.bf_vector.subband_index = rand_range(0, 25);
+          dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.bf_vector.num_antennas= rand_range(1, 4);
+
+          for(int j = 0; j < dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.epdcch_num_prb; ++j)
+            dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.bf_vector.bf_value[j] = rand_range(0, 65535);
+
+          dl_config_pdus[i].epdcch_pdu.epdcch_params_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PARAM_REL13_TAG;
+          dl_config_pdus[i].epdcch_pdu.epdcch_params_rel13.dwpts_symbols = rand_range(3, 14);
+          dl_config_pdus[i].epdcch_pdu.epdcch_params_rel13.initial_lbt_sf = rand_range(0, 1);
+        }
+        break;
+
+        case NFAPI_DL_CONFIG_MPDCCH_PDU_TYPE: {
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_MPDCCH_PDU_REL13_TAG;
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.mpdcch_narrow_band = rand_range(0, 15);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.number_of_prb_pairs = rand_range(2, 6);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.resource_block_assignment = rand_range(0, 14);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.mpdcch_tansmission_type = rand_range(0, 1);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.start_symbol = rand_range(1, 4);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.ecce_index = rand_range(0, 22);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.aggregation_level = rand_range(2, 24);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.rnti_type = rand_range(0, 4);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.rnti = rand_range(1, 65535);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.ce_mode = rand_range(1, 2);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.drms_scrambling_init = rand_range(0, 503);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.initial_transmission_sf_io = rand_range(0, 10239);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.transmission_power = rand_range(0, 10000);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.dci_format = rand_range(10, 12);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.resource_block_coding = rand_range(0, 0xFFFF);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.mcs = rand_range(0, 15);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.pdsch_reptition_levels = rand_range(1, 8);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.redundancy_version = rand_range(0, 3);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.new_data_indicator = rand_range(0, 1);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.harq_process = rand_range(0, 15);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.tpmi_length = rand_range(0, 4);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.tpmi = rand_range(0, 15);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.pmi_flag = rand_range(0, 1);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.pmi = rand_range(0, 1);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.harq_resource_offset = rand_range(0, 3);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.dci_subframe_repetition_number = rand_range(1, 4);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.tpc = rand_range(0, 3);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.downlink_assignment_index_length = rand_range(0, 4);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.downlink_assignment_index = rand_range(0, 15);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.allocate_prach_flag = rand_range(0, 63);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.preamble_index = rand_range(0, 15);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.prach_mask_index = rand_range(0, 3);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.starting_ce_level = rand_range(0, 1);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.srs_request = rand_range(0, 1);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.antenna_ports_and_scrambling_identity_flag = rand_range(0, 1);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.antenna_ports_and_scrambling_identity = rand_range(0, 3);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.frequency_hopping_enabled_flag = rand_range(0, 1);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.paging_direct_indication_differentiation_flag = rand_range(0, 1);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.direct_indication = rand_range(0, 255);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.total_dci_length_including_padding = rand_range(0, 1);
+          dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.number_of_tx_antenna_ports = rand_range(0, 8);
+
+          for(int j = 0 ; j < dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.number_of_tx_antenna_ports; ++j)
+            dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.precoding_value[j] = rand_range(0, 65535);
+        }
+        break;
+
+        case NFAPI_DL_CONFIG_NBCH_PDU_TYPE: {
+          dl_config_pdus[i].nbch_pdu.nbch_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_NBCH_PDU_REL13_TAG;
+          dl_config_pdus[i].nbch_pdu.nbch_pdu_rel13.length = rand_range(0, 5555);
+          dl_config_pdus[i].nbch_pdu.nbch_pdu_rel13.pdu_index = rand_range(0, 65535);
+          dl_config_pdus[i].nbch_pdu.nbch_pdu_rel13.transmission_power = rand_range(0, 10000);
+          dl_config_pdus[i].nbch_pdu.nbch_pdu_rel13.hyper_sfn_2_lsbs = rand_range(0, 3);
+        }
+        break;
+
+        case NFAPI_DL_CONFIG_NPDCCH_PDU_TYPE: {
+          dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_NPDCCH_PDU_REL13_TAG;
+          dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.length = rand_range(0, 5555);
+          dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.pdu_index = rand_range(0, 65535);
+          dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.ncce_index = rand_range(0, 1);
+          dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.aggregation_level = rand_range(1, 2);
+          dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.start_symbol = rand_range(0, 4);
+          dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.rnti_type = rand_range(0, 3);
+          dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.rnti = rand_range(1, 65535);
+          dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.scrambling_reinitialization_batch_index = rand_range(1, 4);
+          dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.nrs_antenna_ports_assumed_by_the_ue = rand_range(1, 2);
+          dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.dci_format = rand_range(0, 1);
+          dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.scheduling_delay = rand_range(0, 7);
+          dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.resource_assignment = rand_range(0, 7);
+          dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.repetition_number = rand_range(0, 15);
+          dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.mcs = rand_range(0, 13);
+          dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.new_data_indicator = rand_range(0, 1);
+          dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.harq_ack_resource = rand_range(0, 15);
+          dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.npdcch_order_indication = rand_range(0, 1);
+          dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.starting_number_of_nprach_repetitions = rand_range(0, 3);
+          dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.subcarrier_indication_of_nprach = rand_range(0, 63);
+          dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.paging_direct_indication_differentation_flag = rand_range(0, 1);
+          dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.direct_indication = rand_range(0, 255);
+          dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.dci_subframe_repetition_number  = rand_range(0, 7);
+          dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.total_dci_length_including_padding = rand_range(0, 255);
+        }
+        break;
+
+        case NFAPI_DL_CONFIG_NDLSCH_PDU_TYPE: {
+          dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_NDLSCH_PDU_REL13_TAG;
+          dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.length = rand_range(0, 5555);
+          dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.pdu_index = rand_range(0, 65535);
+          dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.start_symbol = rand_range(0, 4);
+          dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.rnti_type = rand_range(0, 1);
+          dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.rnti = rand_range(1, 65535);
+          dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.resource_assignment = rand_range(0, 7);
+          dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.repetition_number = rand_range(0, 15);
+          dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.modulation = 2;
+          dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.number_of_subframes_for_resource_assignment = rand_range(1, 10);
+          dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.scrambling_sequence_initialization_cinit = rand_range(0, 65535);
+          dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.sf_idx = rand_range(1, 10240);
+          dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.nrs_antenna_ports_assumed_by_the_ue = rand_range(1, 2);
+        }
+        break;
+      };
+    }
+
+    dl_config_req.dl_config_request_body.dl_config_pdu_list = dl_config_pdus;
+    mac->dl_config_req(mac, &dl_config_req);
+    uint8_t num_ul_pdus = 18;
+    nfapi_ul_config_request_pdu_t ul_config_pdus[num_ul_pdus];
+    memset(&ul_config_pdus, 0, sizeof(ul_config_pdus));
+    nfapi_ul_config_request_t ul_config_req;
+    memset(&ul_config_req, 0, sizeof(ul_config_req));
+    ul_config_req.header.message_id = NFAPI_UL_CONFIG_REQUEST;
+    ul_config_req.header.phy_id = phy_id;
+    ul_config_req.sfn_sf = sfn_sf;
+    ul_config_req.ul_config_request_body.tl.tag = NFAPI_UL_CONFIG_REQUEST_BODY_TAG;
+    ul_config_req.ul_config_request_body.number_of_pdus = num_ul_pdus;
+    ul_config_req.ul_config_request_body.rach_prach_frequency_resources = rand_range(0, 255);
+    ul_config_req.ul_config_request_body.srs_present = rand_range(0, 1);
+    auto ul_config_ulsch_pdu_test_gen = [](nfapi_ul_config_ulsch_pdu& ulsch_pdu) {
+      ulsch_pdu.ulsch_pdu_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_PDU_REL8_TAG;
+      ulsch_pdu.ulsch_pdu_rel8.handle = rand_range(0, 50000);
+      ulsch_pdu.ulsch_pdu_rel8.size = rand_range(0, 32000);
+      ulsch_pdu.ulsch_pdu_rel8.rnti = rand_range(1, 65535);
+      ulsch_pdu.ulsch_pdu_rel8.resource_block_start = rand_range(0, 99);
+      ulsch_pdu.ulsch_pdu_rel8.number_of_resource_blocks = rand_range(1, 100);
+      ulsch_pdu.ulsch_pdu_rel8.modulation_type = rand_range(2, 6);
+      ulsch_pdu.ulsch_pdu_rel8.cyclic_shift_2_for_drms = rand_range(0, 7);
+      ulsch_pdu.ulsch_pdu_rel8.frequency_hopping_enabled_flag = rand_range(0, 1);
+      ulsch_pdu.ulsch_pdu_rel8.frequency_hopping_bits = rand_range(0, 3);
+      ulsch_pdu.ulsch_pdu_rel8.new_data_indication = rand_range(0, 1);
+      ulsch_pdu.ulsch_pdu_rel8.redundancy_version = rand_range(0, 3);
+      ulsch_pdu.ulsch_pdu_rel8.harq_process_number = rand_range(0, 15);
+      ulsch_pdu.ulsch_pdu_rel8.ul_tx_mode = rand_range(0, 1);
+      ulsch_pdu.ulsch_pdu_rel8.current_tx_nb = rand_range(0, 5);
+      ulsch_pdu.ulsch_pdu_rel8.n_srs = rand_range(0, 1);
+      ulsch_pdu.ulsch_pdu_rel10.tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_PDU_REL10_TAG;
+      ulsch_pdu.ulsch_pdu_rel10.resource_allocation_type = rand_range(0, 1);
+      ulsch_pdu.ulsch_pdu_rel10.resource_block_coding = rand_range(0, 35000);
+      ulsch_pdu.ulsch_pdu_rel10.transport_blocks = rand_range(1, 2);
+      ulsch_pdu.ulsch_pdu_rel10.transmission_scheme = rand_range(0, 1);
+      ulsch_pdu.ulsch_pdu_rel10.number_of_layers = rand_range(1, 4);
+      ulsch_pdu.ulsch_pdu_rel10.codebook_index = rand_range(0, 23);
+      ulsch_pdu.ulsch_pdu_rel10.disable_sequence_hopping_flag = rand_range(0, 1);
+      ulsch_pdu.ulsch_pdu_rel11.tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_PDU_REL11_TAG;
+      ulsch_pdu.ulsch_pdu_rel11.virtual_cell_id_enabled_flag = rand_range(0, 1);
+      ulsch_pdu.ulsch_pdu_rel11.npusch_identity = rand_range(0, 509);
+      ulsch_pdu.ulsch_pdu_rel11.dmrs_config_flag = rand_range(0, 1);
+      ulsch_pdu.ulsch_pdu_rel11.ndmrs_csh_identity = rand_range(0, 509);
+      ulsch_pdu.ulsch_pdu_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_PDU_REL13_TAG;
+      ulsch_pdu.ulsch_pdu_rel13.ue_type = rand_range(0, 2);
+      ulsch_pdu.ulsch_pdu_rel13.total_number_of_repetitions = rand_range(1, 2048);
+      ulsch_pdu.ulsch_pdu_rel13.repetition_number = rand_range(1, 2048);
+      ulsch_pdu.ulsch_pdu_rel13.initial_transmission_sf_io = rand_range(0, 10239);
+      ulsch_pdu.ulsch_pdu_rel13.empty_symbols_due_to_re_tunning = rand_range(0, 8);
+    };
+    auto ul_config_cqi_ri_info_test_gen = [](nfapi_ul_config_cqi_ri_information& cqi_ri_information) {
+      cqi_ri_information.cqi_ri_information_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_CQI_RI_INFORMATION_REL8_TAG;
+      cqi_ri_information.cqi_ri_information_rel8.dl_cqi_pmi_size_rank_1 = rand_range(0, 255);
+      cqi_ri_information.cqi_ri_information_rel8.dl_cqi_pmi_size_rank_greater_1 = rand_range(0, 255);
+      cqi_ri_information.cqi_ri_information_rel8.ri_size = rand_range(0, 3);
+      cqi_ri_information.cqi_ri_information_rel8.delta_offset_cqi = rand_range(0, 15);
+      cqi_ri_information.cqi_ri_information_rel8.delta_offset_ri = rand_range(0, 15);
+      cqi_ri_information.cqi_ri_information_rel9.tl.tag = NFAPI_UL_CONFIG_REQUEST_CQI_RI_INFORMATION_REL9_TAG;
+      cqi_ri_information.cqi_ri_information_rel9.report_type = 1; // rand_range(0, 1);
+      cqi_ri_information.cqi_ri_information_rel9.delta_offset_cqi = rand_range(0, 15);
+      cqi_ri_information.cqi_ri_information_rel9.delta_offset_ri = rand_range(0, 15);
+
+      if(cqi_ri_information.cqi_ri_information_rel9.report_type == 0) {
+        cqi_ri_information.cqi_ri_information_rel9.periodic_cqi_pmi_ri_report.dl_cqi_pmi_ri_size = rand_range(0, 255);
+        cqi_ri_information.cqi_ri_information_rel9.periodic_cqi_pmi_ri_report.control_type = rand_range(0, 1);
+      } else {
+        cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.number_of_cc = 1;
+        cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].ri_size = rand_range(0, 3);
+        cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].dl_cqi_pmi_size[0] = rand_range(0, 255);
+      }
+
+      cqi_ri_information.cqi_ri_information_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_CQI_RI_INFORMATION_REL13_TAG;
+      cqi_ri_information.cqi_ri_information_rel13.report_type = rand_range(0, 1);
+
+      if(cqi_ri_information.cqi_ri_information_rel13.report_type == 0) {
+        cqi_ri_information.cqi_ri_information_rel13.periodic_cqi_pmi_ri_report.dl_cqi_pmi_ri_size_2 = rand_range(255, 10000);
+      }
+    };
+    auto ul_config_init_tx_params_test_gen = [](nfapi_ul_config_initial_transmission_parameters& initial_transmission_parameters) {
+      initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG;
+      initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = rand_range(0, 1);
+      initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks = rand_range(1, 100);
+    };
+    auto ul_config_harqinfo_test_gen = [](nfapi_ul_config_ulsch_harq_information& harq_information) {
+      harq_information.harq_information_rel10.tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_HARQ_INFORMATION_REL10_TAG;
+      harq_information.harq_information_rel10.harq_size = rand_range(0, 21);
+      harq_information.harq_information_rel10.delta_offset_harq = rand_range(0, 15);
+      harq_information.harq_information_rel10.ack_nack_mode = rand_range(0, 5);
+      harq_information.harq_information_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_HARQ_INFORMATION_REL13_TAG;
+      harq_information.harq_information_rel13.harq_size_2 = rand_range(0, 21);
+      harq_information.harq_information_rel13.delta_offset_harq_2 = rand_range(0, 15);
+    };
+    auto ul_config_sr_info_test_gen = [](nfapi_ul_config_sr_information& sr_info) {
+      sr_info.sr_information_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_SR_INFORMATION_REL8_TAG;
+      sr_info.sr_information_rel8.pucch_index = rand_range(0, 2047);
+      sr_info.sr_information_rel10.tl.tag = NFAPI_UL_CONFIG_REQUEST_SR_INFORMATION_REL10_TAG;
+      sr_info.sr_information_rel10.number_of_pucch_resources = rand_range(1, 2);
+      sr_info.sr_information_rel10.pucch_index_p1 = rand_range(0, 2047);
+    };
+    auto ul_config_ue_info_test_gen = [](nfapi_ul_config_ue_information& ue_information) {
+      ue_information.ue_information_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL8_TAG;
+      ue_information.ue_information_rel8.handle = rand_range(0, 99999);
+      ue_information.ue_information_rel8.rnti = rand_range(1, 65535);
+      ue_information.ue_information_rel11.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL11_TAG;
+      ue_information.ue_information_rel11.virtual_cell_id_enabled_flag = rand_range(0, 1);
+      ue_information.ue_information_rel11.npusch_identity = rand_range(0, 503);
+      ue_information.ue_information_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL13_TAG;
+      ue_information.ue_information_rel13.ue_type = rand_range(0, 2);
+      ue_information.ue_information_rel13.empty_symbols = rand_range(0, 2);
+      ue_information.ue_information_rel13.total_number_of_repetitions = rand_range(1, 32);
+      ue_information.ue_information_rel13.repetition_number = rand_range(1, 32);
+    };
+    auto ul_config_cqi_info_test_gen = [](nfapi_ul_config_cqi_information& cqi_information) {
+      cqi_information.cqi_information_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_CQI_INFORMATION_REL8_TAG;
+      cqi_information.cqi_information_rel8.pucch_index = rand_range(0, 1184);
+      cqi_information.cqi_information_rel8.dl_cqi_pmi_size = rand_range(0, 255);
+      cqi_information.cqi_information_rel10.tl.tag = NFAPI_UL_CONFIG_REQUEST_CQI_INFORMATION_REL10_TAG;
+      cqi_information.cqi_information_rel10.number_of_pucch_resource = rand_range(1, 2);
+      cqi_information.cqi_information_rel10.pucch_index_p1 = rand_range(0, 1184);
+      cqi_information.cqi_information_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_CQI_INFORMATION_REL13_TAG;
+      cqi_information.cqi_information_rel13.csi_mode = rand_range(0, 2);
+      cqi_information.cqi_information_rel13.dl_cqi_pmi_size_2 = rand_range(0, 999);
+      cqi_information.cqi_information_rel13.starting_prb = rand_range(0, 109);
+      cqi_information.cqi_information_rel13.n_prb = rand_range(0, 7);
+      cqi_information.cqi_information_rel13.cdm_index = rand_range(0, 1);
+      cqi_information.cqi_information_rel13.n_srs = rand_range(0, 1);
+    };
+    auto ul_config_harq_info_test_gen = [](nfapi_ul_config_harq_information& harq_information) {
+      harq_information.harq_information_rel10_tdd.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL10_TDD_TAG;
+      harq_information.harq_information_rel10_tdd.harq_size = rand_range(0, 21);
+      harq_information.harq_information_rel10_tdd.ack_nack_mode = rand_range(0, 5);
+      harq_information.harq_information_rel10_tdd.number_of_pucch_resources = rand_range(0, 4);
+      harq_information.harq_information_rel10_tdd.n_pucch_1_0 = rand_range(0, 2047);
+      harq_information.harq_information_rel10_tdd.n_pucch_1_1 = rand_range(0, 2047);
+      harq_information.harq_information_rel10_tdd.n_pucch_1_2 = rand_range(0, 2047);
+      harq_information.harq_information_rel10_tdd.n_pucch_1_3 = rand_range(0, 2047);
+      harq_information.harq_information_rel8_fdd.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL8_FDD_TAG;
+      harq_information.harq_information_rel8_fdd.n_pucch_1_0 = rand_range(0, 2047);
+      harq_information.harq_information_rel8_fdd.harq_size = rand_range(1, 2);
+      harq_information.harq_information_rel9_fdd.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL9_FDD_TAG;
+      harq_information.harq_information_rel9_fdd.harq_size = rand_range(1, 10);
+      harq_information.harq_information_rel9_fdd.ack_nack_mode = rand_range(0, 4);
+      harq_information.harq_information_rel9_fdd.number_of_pucch_resources = rand_range(0, 4);
+      harq_information.harq_information_rel9_fdd.n_pucch_1_0 = rand_range(0, 2047);
+      harq_information.harq_information_rel9_fdd.n_pucch_1_1 = rand_range(0, 2047);
+      harq_information.harq_information_rel9_fdd.n_pucch_1_2 = rand_range(0, 2047);
+      harq_information.harq_information_rel9_fdd.n_pucch_1_3 = rand_range(0, 2047);
+      harq_information.harq_information_rel11.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL11_TAG;
+      harq_information.harq_information_rel11.num_ant_ports = rand_range(1, 2);
+      harq_information.harq_information_rel11.n_pucch_2_0 = rand_range(0, 2047);
+      harq_information.harq_information_rel11.n_pucch_2_1 = rand_range(0, 2047);
+      harq_information.harq_information_rel11.n_pucch_2_2 = rand_range(0, 2047);
+      harq_information.harq_information_rel11.n_pucch_2_3 = rand_range(0, 2047);
+      harq_information.harq_information_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL13_TAG;
+      harq_information.harq_information_rel13.harq_size_2 = rand_range(0, 999);
+      harq_information.harq_information_rel13.starting_prb = rand_range(0, 109);
+      harq_information.harq_information_rel13.n_prb = rand_range(0, 7);
+      harq_information.harq_information_rel13.cdm_index = rand_range(0, 1);
+      harq_information.harq_information_rel13.n_srs = rand_range(0, 1);
+    };
+    ul_config_pdus[0].pdu_type = NFAPI_UL_CONFIG_ULSCH_PDU_TYPE;
+    ul_config_ulsch_pdu_test_gen(ul_config_pdus[0].ulsch_pdu);
+    ul_config_pdus[1].pdu_type = NFAPI_UL_CONFIG_ULSCH_CQI_RI_PDU_TYPE;
+    ul_config_ulsch_pdu_test_gen(ul_config_pdus[1].ulsch_cqi_ri_pdu.ulsch_pdu);
+    ul_config_cqi_ri_info_test_gen(ul_config_pdus[1].ulsch_cqi_ri_pdu.cqi_ri_information);
+    ul_config_init_tx_params_test_gen(ul_config_pdus[1].ulsch_cqi_ri_pdu.initial_transmission_parameters);
+    ul_config_pdus[2].pdu_type = NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE;
+    ul_config_ulsch_pdu_test_gen(ul_config_pdus[2].ulsch_harq_pdu.ulsch_pdu);
+    ul_config_harqinfo_test_gen(ul_config_pdus[2].ulsch_harq_pdu.harq_information);
+    ul_config_init_tx_params_test_gen(ul_config_pdus[2].ulsch_harq_pdu.initial_transmission_parameters);
+    ul_config_pdus[3].pdu_type = NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE;
+    ul_config_ulsch_pdu_test_gen(ul_config_pdus[3].ulsch_cqi_harq_ri_pdu.ulsch_pdu);
+    ul_config_cqi_ri_info_test_gen(ul_config_pdus[3].ulsch_cqi_harq_ri_pdu.cqi_ri_information);
+    ul_config_harqinfo_test_gen(ul_config_pdus[3].ulsch_cqi_harq_ri_pdu.harq_information);
+    ul_config_init_tx_params_test_gen(ul_config_pdus[3].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters);
+    ul_config_pdus[4].pdu_type = NFAPI_UL_CONFIG_UCI_CQI_PDU_TYPE;
+    ul_config_ue_info_test_gen(ul_config_pdus[4].uci_cqi_pdu.ue_information);
+    ul_config_cqi_info_test_gen(ul_config_pdus[4].uci_cqi_pdu.cqi_information);
+    ul_config_pdus[5].pdu_type = NFAPI_UL_CONFIG_UCI_SR_PDU_TYPE;
+    ul_config_ue_info_test_gen(ul_config_pdus[5].uci_sr_pdu.ue_information);
+    ul_config_sr_info_test_gen(ul_config_pdus[5].uci_sr_pdu.sr_information);
+    ul_config_pdus[6].pdu_type = NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE;
+    ul_config_ue_info_test_gen(ul_config_pdus[6].uci_harq_pdu.ue_information);
+    ul_config_harq_info_test_gen(ul_config_pdus[6].uci_harq_pdu.harq_information);
+    ul_config_pdus[7].pdu_type = NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE;
+    ul_config_ue_info_test_gen(ul_config_pdus[7].uci_sr_harq_pdu.ue_information);
+    ul_config_sr_info_test_gen(ul_config_pdus[7].uci_sr_harq_pdu.sr_information);
+    ul_config_harq_info_test_gen(ul_config_pdus[7].uci_sr_harq_pdu.harq_information);
+    ul_config_pdus[8].pdu_type = NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE;
+    ul_config_ue_info_test_gen(ul_config_pdus[8].uci_cqi_harq_pdu.ue_information);
+    ul_config_cqi_info_test_gen(ul_config_pdus[8].uci_cqi_harq_pdu.cqi_information);
+    ul_config_harq_info_test_gen(ul_config_pdus[8].uci_cqi_harq_pdu.harq_information);
+    ul_config_pdus[9].pdu_type = NFAPI_UL_CONFIG_UCI_CQI_SR_PDU_TYPE;
+    ul_config_ue_info_test_gen(ul_config_pdus[9].uci_cqi_sr_pdu.ue_information);
+    ul_config_cqi_info_test_gen(ul_config_pdus[9].uci_cqi_sr_pdu.cqi_information);
+    ul_config_sr_info_test_gen(ul_config_pdus[9].uci_cqi_sr_pdu.sr_information);
+    ul_config_pdus[10].pdu_type = NFAPI_UL_CONFIG_UCI_CQI_SR_HARQ_PDU_TYPE;
+    ul_config_ue_info_test_gen(ul_config_pdus[10].uci_cqi_sr_harq_pdu.ue_information);
+    ul_config_cqi_info_test_gen(ul_config_pdus[10].uci_cqi_sr_harq_pdu.cqi_information);
+    ul_config_sr_info_test_gen(ul_config_pdus[10].uci_cqi_sr_harq_pdu.sr_information);
+    ul_config_harq_info_test_gen(ul_config_pdus[10].uci_cqi_sr_harq_pdu.harq_information);
+    ul_config_pdus[11].pdu_type = NFAPI_UL_CONFIG_SRS_PDU_TYPE;
+    ul_config_pdus[11].srs_pdu.srs_pdu_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_SRS_PDU_REL8_TAG;
+    ul_config_pdus[11].srs_pdu.srs_pdu_rel8.handle = rand_range(0, 9999);
+    ul_config_pdus[11].srs_pdu.srs_pdu_rel8.size = rand_range(1, 999);
+    ul_config_pdus[11].srs_pdu.srs_pdu_rel8.rnti = rand_range(1, 65535);
+    ul_config_pdus[11].srs_pdu.srs_pdu_rel8.srs_bandwidth = rand_range(0, 3);
+    ul_config_pdus[11].srs_pdu.srs_pdu_rel8.frequency_domain_position = rand_range(0, 23);
+    ul_config_pdus[11].srs_pdu.srs_pdu_rel8.srs_hopping_bandwidth = rand_range(0, 3);
+    ul_config_pdus[11].srs_pdu.srs_pdu_rel8.transmission_comb = rand_range(0, 3);
+    ul_config_pdus[11].srs_pdu.srs_pdu_rel8.i_srs = rand_range(0, 1023);
+    ul_config_pdus[11].srs_pdu.srs_pdu_rel8.sounding_reference_cyclic_shift = rand_range(0, 11);
+    ul_config_pdus[11].srs_pdu.srs_pdu_rel10.tl.tag = NFAPI_UL_CONFIG_REQUEST_SRS_PDU_REL10_TAG;
+    ul_config_pdus[11].srs_pdu.srs_pdu_rel10.antenna_port = rand_range(0, 2);
+    ul_config_pdus[11].srs_pdu.srs_pdu_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_SRS_PDU_REL13_TAG;
+    ul_config_pdus[11].srs_pdu.srs_pdu_rel13.number_of_combs = rand_range(0, 1);
+    ul_config_pdus[12].pdu_type = NFAPI_UL_CONFIG_HARQ_BUFFER_PDU_TYPE;
+    ul_config_ue_info_test_gen(ul_config_pdus[12].harq_buffer_pdu.ue_information);
+    ul_config_pdus[13].pdu_type = NFAPI_UL_CONFIG_ULSCH_UCI_CSI_PDU_TYPE;
+    ul_config_ulsch_pdu_test_gen(ul_config_pdus[13].ulsch_uci_csi_pdu.ulsch_pdu);
+    ul_config_cqi_info_test_gen(ul_config_pdus[13].ulsch_uci_csi_pdu.csi_information);
+    ul_config_pdus[14].pdu_type = NFAPI_UL_CONFIG_ULSCH_UCI_HARQ_PDU_TYPE;
+    ul_config_ulsch_pdu_test_gen(ul_config_pdus[14].ulsch_uci_harq_pdu.ulsch_pdu);
+    ul_config_harq_info_test_gen(ul_config_pdus[14].ulsch_uci_harq_pdu.harq_information);
+    ul_config_pdus[15].pdu_type = NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE;
+    ul_config_ulsch_pdu_test_gen(ul_config_pdus[15].ulsch_csi_uci_harq_pdu.ulsch_pdu);
+    ul_config_cqi_info_test_gen(ul_config_pdus[15].ulsch_csi_uci_harq_pdu.csi_information);
+    ul_config_harq_info_test_gen(ul_config_pdus[15].ulsch_csi_uci_harq_pdu.harq_information);
+    ul_config_pdus[16].pdu_type = NFAPI_UL_CONFIG_NULSCH_PDU_TYPE;
+    ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_NULSCH_PDU_REL13_TAG;
+    ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.nulsch_format = rand_range(0, 1);
+    ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.handle = rand_range(0, 0xFFFF);
+    ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.size = rand_range(0, 65535);
+    ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.rnti = rand_range(1, 65535);
+    ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.subcarrier_indication = rand_range(0, 47);
+    ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.resource_assignment = rand_range(0, 7);
+    ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.mcs = rand_range(0, 12);
+    ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.redudancy_version = rand_range(0, 1);
+    ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.repetition_number = rand_range(0, 7);
+    ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.new_data_indication = rand_range(0, 1);
+    ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.n_srs = rand_range(0, 1);
+    ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.scrambling_sequence_initialization_cinit = rand_range(0, 65535);
+    ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.sf_idx = rand_range(0, 40960);
+    ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL8_TAG;
+    ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel8.handle = rand_range(0, 0xFF);
+    ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel8.rnti = rand_range(1, 65535);
+    ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel11.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL11_TAG;
+    ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel11.virtual_cell_id_enabled_flag = rand_range(0, 1);
+    ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel11.npusch_identity = rand_range(0, 503);
+    ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL13_TAG;
+    ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel13.ue_type = rand_range(0, 2);
+    ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel13.empty_symbols = rand_range(0, 0x3);
+    ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel13.total_number_of_repetitions = rand_range(1, 32);
+    ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel13.repetition_number = rand_range(1, 32);
+    ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.nb_harq_information.nb_harq_information_rel13_fdd.tl.tag = NFAPI_UL_CONFIG_REQUEST_NB_HARQ_INFORMATION_REL13_FDD_TAG;
+    ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.nb_harq_information.nb_harq_information_rel13_fdd.harq_ack_resource = rand_range(0, 15);
+    ul_config_pdus[17].pdu_type = NFAPI_UL_CONFIG_NRACH_PDU_TYPE;
+    ul_config_pdus[17].nrach_pdu.nrach_pdu_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_NRACH_PDU_REL13_TAG;
+    ul_config_pdus[17].nrach_pdu.nrach_pdu_rel13.nprach_config_0 = rand_range(0, 1);
+    ul_config_pdus[17].nrach_pdu.nrach_pdu_rel13.nprach_config_1 = rand_range(0, 1);
+    ul_config_pdus[17].nrach_pdu.nrach_pdu_rel13.nprach_config_2 = rand_range(0, 1);
+    ul_config_req.ul_config_request_body.ul_config_pdu_list = ul_config_pdus;
+    mac->ul_config_req(mac, &ul_config_req);
+    uint8_t num_dci_pdus = 4;
+    uint8_t num_hi_pdus = 1;
+    nfapi_hi_dci0_request_pdu_t hi_dci0_pdus[num_dci_pdus + num_hi_pdus];
+    memset(&hi_dci0_pdus, 0, sizeof(hi_dci0_pdus));
+    nfapi_hi_dci0_request_t hi_dci0_req;
+    memset(&hi_dci0_req, 0, sizeof(hi_dci0_req));
+    hi_dci0_req.header.message_id = NFAPI_HI_DCI0_REQUEST;
+    hi_dci0_req.header.phy_id = phy_id;
+    hi_dci0_req.sfn_sf = sfn_sf;
+    hi_dci0_req.hi_dci0_request_body.tl.tag = NFAPI_HI_DCI0_REQUEST_BODY_TAG;
+    hi_dci0_req.hi_dci0_request_body.sfnsf = sfn_sf;
+    hi_dci0_req.hi_dci0_request_body.number_of_dci = num_dci_pdus;
+    hi_dci0_req.hi_dci0_request_body.number_of_hi = num_hi_pdus;
+    hi_dci0_pdus[0].pdu_type = NFAPI_HI_DCI0_HI_PDU_TYPE;
+    hi_dci0_pdus[0].hi_pdu.hi_pdu_rel8.tl.tag = NFAPI_HI_DCI0_REQUEST_HI_PDU_REL8_TAG;
+    hi_dci0_pdus[0].hi_pdu.hi_pdu_rel8.resource_block_start = rand_range(0, 100);
+    hi_dci0_pdus[0].hi_pdu.hi_pdu_rel8.cyclic_shift_2_for_drms = rand_range(0, 7);
+    hi_dci0_pdus[0].hi_pdu.hi_pdu_rel8.hi_value = rand_range(0, 1);
+    hi_dci0_pdus[0].hi_pdu.hi_pdu_rel8.i_phich = rand_range(0, 1);
+    hi_dci0_pdus[0].hi_pdu.hi_pdu_rel8.transmission_power = rand_range(0, 10000);
+    hi_dci0_pdus[0].hi_pdu.hi_pdu_rel10.tl.tag = NFAPI_HI_DCI0_REQUEST_HI_PDU_REL10_TAG;
+    hi_dci0_pdus[0].hi_pdu.hi_pdu_rel10.flag_tb2 = rand_range(0, 1);
+    hi_dci0_pdus[0].hi_pdu.hi_pdu_rel10.hi_value_2 = rand_range(0, 1);
+    hi_dci0_pdus[1].pdu_type = NFAPI_HI_DCI0_DCI_PDU_TYPE;
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.tl.tag = NFAPI_HI_DCI0_REQUEST_DCI_PDU_REL8_TAG;
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.dci_format = rand_range(0, 4);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.cce_index = rand_range(0, 88);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.aggregation_level = rand_range(1, 8);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.rnti = rand_range(1, 65535);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.resource_block_start = rand_range(0, 100);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.number_of_resource_block = rand_range(0, 100);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.mcs_1 = rand_range(0, 31);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.cyclic_shift_2_for_drms = rand_range(0, 7);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.frequency_hopping_enabled_flag = rand_range(0, 1);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.frequency_hopping_bits = rand_range(0, 3);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.new_data_indication_1 = rand_range(0, 1);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.ue_tx_antenna_seleciton = rand_range(0, 2);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.tpc = rand_range(0, 3);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.cqi_csi_request = rand_range(0, 7);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.ul_index = rand_range(0, 3);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.dl_assignment_index = rand_range(1, 4);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.tpc_bitmap = rand_range(0, 9999);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.transmission_power = rand_range(0, 10000);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.tl.tag = NFAPI_HI_DCI0_REQUEST_DCI_PDU_REL10_TAG;
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.cross_carrier_scheduling_flag = rand_range(0, 1);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.carrier_indicator = rand_range(0, 7);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.size_of_cqi_csi_feild = rand_range(0, 2);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.srs_flag = rand_range(0, 1);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.srs_request = rand_range(0, 1);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.resource_allocation_flag = rand_range(0, 1);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.resource_allocation_type = rand_range(0, 1);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.resource_block_coding = rand_range(0, 9999);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.mcs_2 = rand_range(0, 31);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.new_data_indication_2 = rand_range(0, 1);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.number_of_antenna_ports = rand_range(0, 2);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.tpmi = rand_range(0, 63);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.total_dci_length_including_padding = rand_range(0, 255);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.n_ul_rb = rand_range(6, 100);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel12.tl.tag = NFAPI_HI_DCI0_REQUEST_DCI_PDU_REL12_TAG;
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel12.pscch_resource = rand_range(0, 16);
+    hi_dci0_pdus[1].dci_pdu.dci_pdu_rel12.time_resource_pattern = rand_range(0, 32);
+    hi_dci0_pdus[2].pdu_type = NFAPI_HI_DCI0_EPDCCH_DCI_PDU_TYPE;
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.tl.tag = NFAPI_HI_DCI0_REQUEST_EPDCCH_DCI_PDU_REL8_TAG;
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.dci_format = rand_range(0, 4);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.cce_index = rand_range(0, 88);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.aggregation_level = rand_range(1, 8);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.rnti = rand_range(1, 65535);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.resource_block_start = rand_range(0, 100);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.number_of_resource_block = rand_range(0, 100);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.mcs_1 = rand_range(0, 31);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.cyclic_shift_2_for_drms = rand_range(0, 7);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.frequency_hopping_enabled_flag = rand_range(0, 1);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.frequency_hopping_bits = rand_range(0, 3);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.new_data_indication_1 = rand_range(0, 1);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.ue_tx_antenna_seleciton = rand_range(0, 2);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.tpc = rand_range(0, 3);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.cqi_csi_request = rand_range(0, 7);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.ul_index = rand_range(0, 3);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.dl_assignment_index = rand_range(1, 4);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.tpc_bitmap = rand_range(0, 9999);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.transmission_power = rand_range(0, 10000);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.tl.tag = NFAPI_HI_DCI0_REQUEST_EPDCCH_DCI_PDU_REL10_TAG;
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.cross_carrier_scheduling_flag = rand_range(0, 1);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.carrier_indicator = rand_range(0, 7);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.size_of_cqi_csi_feild = rand_range(0, 2);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.srs_flag = rand_range(0, 1);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.srs_request = rand_range(0, 1);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.resource_allocation_flag = rand_range(0, 1);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.resource_allocation_type = rand_range(0, 1);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.resource_block_coding = rand_range(0, 9999);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.mcs_2 = rand_range(0, 31);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.new_data_indication_2 = rand_range(0, 1);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.number_of_antenna_ports = rand_range(0, 2);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.tpmi = rand_range(0, 63);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.total_dci_length_including_padding = rand_range(0, 255);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.n_ul_rb = rand_range(6, 100);
+    hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_parameters_rel11.tl.tag = NFAPI_HI_DCI0_REQUEST_EPDCCH_PARAMETERS_REL11_TAG;
+    hi_dci0_pdus[3].pdu_type = NFAPI_HI_DCI0_MPDCCH_DCI_PDU_TYPE;
+    hi_dci0_pdus[3].mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.tl.tag = NFAPI_HI_DCI0_REQUEST_MPDCCH_DCI_PDU_REL13_TAG;
+    hi_dci0_pdus[4].pdu_type = NFAPI_HI_DCI0_NPDCCH_DCI_PDU_TYPE;
+    hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.tl.tag = NFAPI_HI_DCI0_REQUEST_NPDCCH_DCI_PDU_REL13_TAG;
+    hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.ncce_index = rand_range(0, 1);
+    hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.aggregation_level = rand_range(1, 2);
+    hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.start_symbol = rand_range(0, 4);
+    hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.rnti = rand_range(1, 65535);
+    hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.scrambling_reinitialization_batch_index = rand_range(1, 4);
+    hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.nrs_antenna_ports_assumed_by_the_ue = rand_range(1, 2);
+    hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.subcarrier_indication = rand_range(0, 63);
+    hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.resource_assignment = rand_range(0, 7);
+    hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.scheduling_delay = rand_range(0, 3);
+    hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.mcs = rand_range(0, 12);
+    hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.redudancy_version = rand_range(0, 1);
+    hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.repetition_number = rand_range(0, 7);
+    hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.new_data_indicator = rand_range(0, 1);
+    hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.dci_subframe_repetition_number = rand_range(0, 3);
+    hi_dci0_req.hi_dci0_request_body.hi_dci0_pdu_list = hi_dci0_pdus;
+    mac->hi_dci0_req(mac, &hi_dci0_req);
+    uint8_t num_tx_pdus = 2;
+    nfapi_tx_request_pdu_t tx_pdus[num_tx_pdus];
+    memset(&tx_pdus, 0, sizeof(tx_pdus));
+    nfapi_tx_request_t tx_req;
+    memset(&tx_req, 0, sizeof(tx_req));
+    tx_req.header.message_id = NFAPI_TX_REQUEST;
+    tx_req.header.phy_id = phy_id;
+    tx_req.sfn_sf = sfn_sf;
+    tx_req.tx_request_body.tl.tag = NFAPI_TX_REQUEST_BODY_TAG;
+    tx_req.tx_request_body.number_of_pdus = num_tx_pdus;
+    uint32_t data[2];
+    data[0] = 0x11223344;
+    data[1] = 0x55667788;
+    tx_pdus[0].pdu_length = 8;
+    tx_pdus[0].pdu_index = 1;
+    tx_pdus[0].num_segments = 2;
+    tx_pdus[0].segments[0].segment_length = 4;
+    tx_pdus[0].segments[0].segment_data = (uint8_t *)&data[0];
+    tx_pdus[0].segments[1].segment_length = 4;
+    tx_pdus[0].segments[1].segment_data = (uint8_t *)&data[1];
+    tx_pdus[1].pdu_length = 8;
+    tx_pdus[1].pdu_index = 2;
+    tx_pdus[1].num_segments = 2;
+    tx_pdus[1].segments[0].segment_length = 4;
+    tx_pdus[1].segments[0].segment_data = (uint8_t *)&data[0];
+    tx_pdus[1].segments[1].segment_length = 4;
+    tx_pdus[1].segments[1].segment_data = (uint8_t *)&data[1];
+    tx_req.tx_request_body.tx_pdu_list = tx_pdus;
+    mac->tx_req(mac, &tx_req);
+  }
+
+  void generate_subframe(mac_t *mac, uint16_t phy_id, uint16_t sfn_sf) {
+    mac_internal_t *instance = (mac_internal_t *)mac;
+    nfapi_dl_config_request_t dl_config_req;
+    memset(&dl_config_req, 0, sizeof(dl_config_req));
+    dl_config_req.header.message_id = NFAPI_DL_CONFIG_REQUEST;
+    dl_config_req.header.phy_id = phy_id;
+    dl_config_req.sfn_sf = sfn_sf;
+    dl_config_req.dl_config_request_body.tl.tag = NFAPI_DL_CONFIG_REQUEST_BODY_TAG;
+    dl_config_req.dl_config_request_body.number_pdu = 8;
+    nfapi_dl_config_request_pdu_t pdus[8];
+    memset(&pdus, 0, sizeof(pdus));
+
+    for(int i = 0; i < 8; i++) {
+      pdus[i].pdu_type = NFAPI_DL_CONFIG_BCH_PDU_TYPE;
+      pdus[i].bch_pdu.bch_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_BCH_PDU_REL8_TAG;
+      pdus[i].bch_pdu.bch_pdu_rel8.length = 42;
+      pdus[i].bch_pdu.bch_pdu_rel8.pdu_index = i;
+      pdus[i].bch_pdu.bch_pdu_rel8.transmission_power = 56;
+    }
+
+    dl_config_req.dl_config_request_body.dl_config_pdu_list = pdus;
+    /*
+    vendor_ext_tlv_1 ve;
+    ve.tl.tag = VENDOR_EXT_TLV_1_TAG;
+    ve.dummy = 999;
+    dl_config_req.vendor_extension = &ve.tl;
+    */
+    mac->dl_config_req(mac, &dl_config_req);
+    nfapi_ul_config_request_t ul_config_req;
+    memset(&ul_config_req, 0, sizeof(ul_config_req));
+    ul_config_req.header.message_id = NFAPI_UL_CONFIG_REQUEST;
+    ul_config_req.header.phy_id = phy_id;
+    ul_config_req.sfn_sf = sfn_sf;
+    mac->ul_config_req(mac, &ul_config_req);
+    nfapi_hi_dci0_request_t hi_dci0_req;
+    memset(&hi_dci0_req, 0, sizeof(hi_dci0_req));
+    hi_dci0_req.header.message_id = NFAPI_HI_DCI0_REQUEST;
+    hi_dci0_req.header.phy_id = phy_id;
+    hi_dci0_req.sfn_sf = sfn_sf;
+    mac->hi_dci0_req(mac, &hi_dci0_req);
+    nfapi_tx_request_t tx_req;
+    memset(&tx_req, 0, sizeof(tx_req));
+    tx_req.header.message_id = NFAPI_TX_REQUEST;
+    tx_req.header.phy_id = phy_id;
+    tx_req.sfn_sf = sfn_sf;
+    nfapi_tx_request_pdu_t tx_pdus[8];
+    tx_req.tx_request_body.tl.tag = NFAPI_TX_REQUEST_BODY_TAG;
+    tx_req.tx_request_body.number_of_pdus = 0;
+    tx_req.tx_request_body.tx_pdu_list = &tx_pdus[0];
+    mac_pdu *buff = 0;
+    int i = 0;
+    std::list<mac_pdu *> free_list;
+
+    do {
+      buff = instance->mac->pop_rx_buffer();
+
+      if(buff != 0) {
+        if(buff->len == 0) {
+          printf("[MAC] Buffer length = 0\n");
+        }
+
+        tx_req.tx_request_body.tx_pdu_list[i].pdu_length = buff->len;
+        tx_req.tx_request_body.tx_pdu_list[i].pdu_index = i;
+        tx_req.tx_request_body.tx_pdu_list[i].num_segments = 1;
+        tx_req.tx_request_body.tx_pdu_list[i].segments[0].segment_length = buff->len;
+        tx_req.tx_request_body.tx_pdu_list[i].segments[0].segment_data = (uint8_t *)buff->buffer;
+        tx_req.tx_request_body.number_of_pdus++;
+        i++;
+        instance->mac->byte_count += buff->len;
+        free_list.push_back(buff);
+      }
+    } while(buff != 0 && i < 8);
+
+    mac->tx_req(mac, &tx_req);
+
+    //for(int j = 0; j < tx_req.tx_request_body.number_of_pdus; ++j)
+    for(mac_pdu *pdu : free_list) {
+      instance->mac->release_mac_pdu(pdu);
+      //free(tx_req.tx_request_body.tx_pdu_list[j].segments[0].segment_data);
+    }
+  }
+
+  void mac_subframe_ind(mac_t *mac, uint16_t phy_id, uint16_t sfn_sf) {
+    //printf("[MAC] subframe indication phyid:%d sfnsf:%d\n", phy_id, sfn_sf);
+    mac_internal_t *instance = (mac_internal_t *)mac;
+
+    if(instance->mac->tick == 1000) {
+      if(instance->mac->byte_count > 0) {
+        printf("[MAC] Rx rate %d bytes/sec\n", instance->mac->byte_count);
+        instance->mac->byte_count = 0;
+      }
+
+      instance->mac->tick = 0;
+    }
+
+    instance->mac->tick++;
+
+    if(instance->mac->wireshark_test_mode) {
+      generate_test_subframe(mac, phy_id, sfn_sf);
+    } else {
+      generate_subframe(mac, phy_id, sfn_sf);
+    }
+  }
+
+  void mac_harq_ind(mac_t *mac, nfapi_harq_indication_t *ind) {
+  }
+  void mac_crc_ind(mac_t *mac, nfapi_crc_indication_t *ind) {
+  }
+  void mac_rx_ind(mac_t *mac, nfapi_rx_indication_t *ind) {
+    mac_internal_t *instance = (mac_internal_t *)mac;
+
+    for(int i = 0; i < ind->rx_indication_body.number_of_pdus; ++i) {
+      uint16_t len = ind->rx_indication_body.rx_pdu_list[i].rx_indication_rel8.length;
+      uint8_t *data = ind->rx_indication_body.rx_pdu_list[i].data;
+      //printf("[MAC] sfnsf:%d len:%d\n", ind->sfn_sf,len);
+      //
+      instance->tx_byte_count += len;
+      int sendto_result = sendto(instance->tx_sock, data, len, 0, (struct sockaddr *)&(instance->tx_addr), sizeof(instance->tx_addr));
+
+      if(sendto_result < 0) {
+        // error
+      }
+    }
+  }
+  void mac_rach_ind(mac_t *mac, nfapi_rach_indication_t *ind) {
+  }
+  void mac_srs_ind(mac_t *mac, nfapi_srs_indication_t *ind) {
+  }
+  void mac_sr_ind(mac_t *mac, nfapi_sr_indication_t *ind) {
+  }
+  void mac_cqi_ind(mac_t *mac, nfapi_cqi_indication_t *ind) {
+  }
+  void mac_lbt_dl_ind(mac_t *mac, nfapi_lbt_dl_indication_t *ind) {
+  }
+  void mac_nb_harq_ind(mac_t *mac, nfapi_nb_harq_indication_t *ind) {
+  }
+  void mac_nrach_ind(mac_t *mac, nfapi_nrach_indication_t *ind) {
+  }
 }
 
diff --git a/nfapi/open-nFAPI/vnf_sim/src/main.cpp b/nfapi/open-nFAPI/vnf_sim/src/main.cpp
index 5dc7161157defe8b5c6e3b8d5b10c445cf79a25d..dedf06174f43b435fd1ddf97ec6cc30af9815767 100644
--- a/nfapi/open-nFAPI/vnf_sim/src/main.cpp
+++ b/nfapi/open-nFAPI/vnf_sim/src/main.cpp
@@ -1,12 +1,12 @@
 /*
  * Copyright 2017 Cisco Systems, Inc.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * 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.
@@ -38,8 +38,8 @@
 #include <boost/foreach.hpp>
 #include <boost/property_tree/xml_parser.hpp>
 #include <boost/property_tree/ptree.hpp>
-#include <boost/exception/diagnostic_information.hpp> 
-#include <boost/exception_ptr.hpp> 
+#include <boost/exception/diagnostic_information.hpp>
+#include <boost/exception_ptr.hpp>
 
 extern "C" {
 #include <nfapi_vnf_interface.h>
@@ -48,606 +48,486 @@ extern "C" {
 
 #include <vendor_ext.h>
 
-//int vnf_main(int iPortP5, int, int);
-int start_simulated_mac(int*, int*);
-int read_xml(const char *xml_file);
+  //int vnf_main(int iPortP5, int, int);
+  int start_simulated_mac(int *, int *);
+  int read_xml(const char *xml_file);
 
 }
 
-static uint32_t rand_range(uint32_t min, uint32_t max)
-{
-	return ((rand() % (max + 1 - min)) + min);
+static uint32_t rand_range(uint32_t min, uint32_t max) {
+  return ((rand() % (max + 1 - min)) + min);
 }
 
 
-void* vnf_allocate(size_t size)
-{
-	return (void*)memory_pool::allocate(size);
+void *vnf_allocate(size_t size) {
+  return (void *)memory_pool::allocate(size);
 }
 
-void vnf_deallocate(void* ptr)
-{
-	memory_pool::deallocate((uint8_t*)ptr);
+void vnf_deallocate(void *ptr) {
+  memory_pool::deallocate((uint8_t *)ptr);
 }
 
 
 
-class udp_data
-{
-	public:
-		bool enabled;
-		uint32_t rx_port;
-		uint32_t tx_port;
-		std::string tx_addr;
+class udp_data {
+ public:
+  bool enabled;
+  uint32_t rx_port;
+  uint32_t tx_port;
+  std::string tx_addr;
 };
 
 
-class phy_info
-{
-	public:
+class phy_info {
+ public:
 
-		uint16_t index;
-		uint16_t id;
+  uint16_t index;
+  uint16_t id;
 
-		std::vector<uint16_t> rfs;
-		std::vector<uint16_t> excluded_rfs;
+  std::vector<uint16_t> rfs;
+  std::vector<uint16_t> excluded_rfs;
 
-		int remote_port;
-		std::string remote_addr;
+  int remote_port;
+  std::string remote_addr;
 
-		uint16_t earfcn;
+  uint16_t earfcn;
 
 };
 
-class rf_info
-{
-	public:
+class rf_info {
+ public:
 
-		uint16_t index;
-		uint16_t band;
+  uint16_t index;
+  uint16_t band;
 };
 
-class pnf_info
-{
-	public:
+class pnf_info {
+ public:
 
-		std::vector<phy_info> phys;
-		std::vector<rf_info> rfs;
+  std::vector<phy_info> phys;
+  std::vector<rf_info> rfs;
 };
 
-class vnf_p7_info
-{
-	public:
 
-		vnf_p7_info()
-			: thread_started(false), 
-			  config(nfapi_vnf_p7_config_create(), 
-				     [] (nfapi_vnf_p7_config_t* f) { nfapi_vnf_p7_config_destory(f); }),
-			  mac(0)
-		{
-			local_port = 0;
-			
-			timing_window = 0;
-			periodic_timing_enabled = 0;
-			aperiodic_timing_enabled = 0;
-			periodic_timing_period = 0;
-			
-			//config = nfapi_vnf_p7_config_create();
-		}
-		
-		vnf_p7_info(const vnf_p7_info& other)  = default;
-		
-		vnf_p7_info(vnf_p7_info&& other) = default;
-		
-		vnf_p7_info& operator=(const vnf_p7_info&) = default;
-		
-		vnf_p7_info& operator=(vnf_p7_info&&) = default;
-		
-		
-		
-		virtual	~vnf_p7_info()
-		{
-			//NFAPI_TRACE(NFAPI_TRACE_INFO, "*** vnf_p7_info delete ***\n");
-			
-			//nfapi_vnf_p7_config_destory(config);
-			
-			// should we delete the mac?
-		}
-		
+class vnf_p7_info {
+ public:
+
+  vnf_p7_info()
+    : thread_started(false),
+      config(nfapi_vnf_p7_config_create(),
+             [] (nfapi_vnf_p7_config_t *f) {
+    nfapi_vnf_p7_config_destory(f);
+  }),
+  mac(0) {
+    local_port = 0;
+    udp=0;
+    timing_window = 0;
+    periodic_timing_enabled = 0;
+    aperiodic_timing_enabled = 0;
+    periodic_timing_period = 0;
+    //config = nfapi_vnf_p7_config_create();
+  }
+
+  vnf_p7_info(const vnf_p7_info &other)  = default;
+
+  vnf_p7_info(vnf_p7_info &&other) = default;
+
+  vnf_p7_info &operator=(const vnf_p7_info &) = default;
+
+  vnf_p7_info &operator=(vnf_p7_info &&) = default;
 
-		int local_port;
-		std::string local_addr;
 
-		unsigned timing_window;
-		unsigned periodic_timing_enabled;
-		unsigned aperiodic_timing_enabled;
-		unsigned periodic_timing_period;
 
-		// This is not really the right place if we have multiple PHY, 
-		// should be part of the phy struct
-		udp_data udp;
+  virtual ~vnf_p7_info() {
+    //NFAPI_TRACE(NFAPI_TRACE_INFO, "*** vnf_p7_info delete ***\n");
+    //nfapi_vnf_p7_config_destory(config);
+    // should we delete the mac?
+  }
 
-		bool thread_started;
 
-		//nfapi_vnf_p7_config_t* config;
-		std::shared_ptr<nfapi_vnf_p7_config_t> config;
+  int local_port;
+  std::string local_addr;
 
-		mac_t* mac;
+  unsigned timing_window;
+  unsigned periodic_timing_enabled;
+  unsigned aperiodic_timing_enabled;
+  unsigned periodic_timing_period;
 
+  // This is not really the right place if we have multiple PHY,
+  // should be part of the phy struct
+  udp_data udp;
+
+  bool thread_started;
+
+  //nfapi_vnf_p7_config_t* config;
+  std::shared_ptr<nfapi_vnf_p7_config_t> config;
+
+  mac_t *mac;
 
 };
 
-class vnf_info
-{
-	public:
-	
-		uint8_t wireshark_test_mode;
+class vnf_info {
+ public:
 
-		std::map<uint16_t, pnf_info> pnfs;
+  uint8_t wireshark_test_mode;
+
+  std::map<uint16_t, pnf_info> pnfs;
+
+  std::vector<vnf_p7_info> p7_vnfs;
 
-		std::vector<vnf_p7_info> p7_vnfs;
-		
 };
 
 
 /// maybe these should be in the mac file...
-int phy_unpack_vendor_extension_tlv(nfapi_tl_t* tl, uint8_t **ppReadPackedMessage, uint8_t *end, void** ve, nfapi_p7_codec_config_t* codec)
-{
-	(void)tl;
-	(void)ppReadPackedMessage;
-	(void)ve;
-	return -1;
+int phy_unpack_vendor_extension_tlv(nfapi_tl_t *tl, uint8_t **ppReadPackedMessage, uint8_t *end, void **ve, nfapi_p7_codec_config_t *codec) {
+  (void)tl;
+  (void)ppReadPackedMessage;
+  (void)ve;
+  return -1;
 }
 
-int phy_pack_vendor_extension_tlv(void* ve, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t* codec)
-{
-	//NFAPI_TRACE(NFAPI_TRACE_INFO, "phy_pack_vendor_extension_tlv\n");
+int phy_pack_vendor_extension_tlv(void *ve, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *codec) {
+  //NFAPI_TRACE(NFAPI_TRACE_INFO, "phy_pack_vendor_extension_tlv\n");
+  nfapi_tl_t *tlv = (nfapi_tl_t *)ve;
 
-	nfapi_tl_t* tlv = (nfapi_tl_t*)ve;
-	switch(tlv->tag)
-	{
-		case VENDOR_EXT_TLV_1_TAG:
-			{
-				//NFAPI_TRACE(NFAPI_TRACE_INFO, "Packing VENDOR_EXT_TLV_1\n");
-				vendor_ext_tlv_1* ve = (vendor_ext_tlv_1*)tlv;
-				if(!push32(ve->dummy, ppWritePackedMsg, end))
-					return 0;
-				return 1;
-			}
-			break;
-		default:
-			return -1;
-			break;
-	}
-}
+  switch(tlv->tag) {
+    case VENDOR_EXT_TLV_1_TAG: {
+      //NFAPI_TRACE(NFAPI_TRACE_INFO, "Packing VENDOR_EXT_TLV_1\n");
+      vendor_ext_tlv_1 *ve = (vendor_ext_tlv_1 *)tlv;
 
-int vnf_sim_pack_vendor_extension_tlv(void* ve, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t* codec)
-{
-	//NFAPI_TRACE(NFAPI_TRACE_INFO, "pnf_sim_pack_vendor_extension_tlv\n");
-	nfapi_tl_t* tlv = (nfapi_tl_t*)ve;
-	switch(tlv->tag)
-	{
-		case VENDOR_EXT_TLV_2_TAG:
-			{
-				//NFAPI_TRACE(NFAPI_TRACE_INFO, "Packing VENDOR_EXT_TLV_2\n");
-				vendor_ext_tlv_2* ve = (vendor_ext_tlv_2*)tlv;
-				if(!push32(ve->dummy, ppWritePackedMsg, end))
-					return 0;
-				return 1;
-			}
-			break;
-	}
-	return -1;
-}
+      if(!push32(ve->dummy, ppWritePackedMsg, end))
+        return 0;
 
-int vnf_sim_unpack_vendor_extension_tlv(nfapi_tl_t* tl, uint8_t **ppReadPackedMessage, uint8_t *end, void** ve, nfapi_p4_p5_codec_config_t* codec)
-{
-	return -1;
+      return 1;
+    }
+    break;
+
+    default:
+      return -1;
+      break;
+  }
 }
 
+int vnf_sim_pack_vendor_extension_tlv(void *ve, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *codec) {
+  //NFAPI_TRACE(NFAPI_TRACE_INFO, "pnf_sim_pack_vendor_extension_tlv\n");
+  nfapi_tl_t *tlv = (nfapi_tl_t *)ve;
 
+  switch(tlv->tag) {
+    case VENDOR_EXT_TLV_2_TAG: {
+      //NFAPI_TRACE(NFAPI_TRACE_INFO, "Packing VENDOR_EXT_TLV_2\n");
+      vendor_ext_tlv_2 *ve = (vendor_ext_tlv_2 *)tlv;
 
+      if(!push32(ve->dummy, ppWritePackedMsg, end))
+        return 0;
 
-int phy_unpack_p7_vendor_extension(nfapi_p7_message_header_t* header, uint8_t** ppReadPackedMessage, uint8_t *end, nfapi_p7_codec_config_t* config)
-{
-	//NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__);
-	if(header->message_id == P7_VENDOR_EXT_IND)
-	{
-		vendor_ext_p7_ind* req = (vendor_ext_p7_ind*)(header);
-		if(!pull16(ppReadPackedMessage, &req->error_code, end))
-			return 0;
-	}
-	return 1;
-}
+      return 1;
+    }
+    break;
+  }
 
-int phy_pack_p7_vendor_extension(nfapi_p7_message_header_t* header, uint8_t** ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t* config)
-{
-	//NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__);
-	if(header->message_id == P7_VENDOR_EXT_REQ)
-	{
-		//NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__);
-		vendor_ext_p7_req* req = (vendor_ext_p7_req*)(header);
-		if(!(push16(req->dummy1, ppWritePackedMsg, end) &&
-			 push16(req->dummy2, ppWritePackedMsg, end)))
-			return 0;
-	}
-	return 1;
+  return -1;
 }
 
-int vnf_sim_unpack_p4_p5_vendor_extension(nfapi_p4_p5_message_header_t* header, uint8_t** ppReadPackedMessage, uint8_t *end, nfapi_p4_p5_codec_config_t* codec)
-{
-	//NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__);
-	if(header->message_id == P5_VENDOR_EXT_RSP)
-	{
-		vendor_ext_p5_rsp* req = (vendor_ext_p5_rsp*)(header);
-		return(!pull16(ppReadPackedMessage, &req->error_code, end));
-	}
-	return 0;
+int vnf_sim_unpack_vendor_extension_tlv(nfapi_tl_t *tl, uint8_t **ppReadPackedMessage, uint8_t *end, void **ve, nfapi_p4_p5_codec_config_t *codec) {
+  return -1;
 }
 
-int vnf_sim_pack_p4_p5_vendor_extension(nfapi_p4_p5_message_header_t* header, uint8_t** ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t* codec)
-{
-	//NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__);
-	if(header->message_id == P5_VENDOR_EXT_REQ)
-	{
-		vendor_ext_p5_req* req = (vendor_ext_p5_req*)(header);
-		//NFAPI_TRACE(NFAPI_TRACE_INFO, "%s %d %d\n", __FUNCTION__, req->dummy1, req->dummy2);
-		return (!(push16(req->dummy1, ppWritePackedMsg, end) &&
-				  push16(req->dummy2, ppWritePackedMsg, end)));
-	}
-	return 0;
+
+
+
+int phy_unpack_p7_vendor_extension(nfapi_p7_message_header_t *header, uint8_t **ppReadPackedMessage, uint8_t *end, nfapi_p7_codec_config_t *config) {
+  //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__);
+  if(header->message_id == P7_VENDOR_EXT_IND) {
+    vendor_ext_p7_ind *req = (vendor_ext_p7_ind *)(header);
+
+    if(!pull16(ppReadPackedMessage, &req->error_code, end))
+      return 0;
+  }
+
+  return 1;
 }
 
-void vnf_sim_trace(nfapi_trace_level_t level, const char* message, ...)
-{
-	va_list args;
-	va_start(args, message);
-	vprintf(message, args);
-	va_end(args);
+int phy_pack_p7_vendor_extension(nfapi_p7_message_header_t *header, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config) {
+  //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__);
+  if(header->message_id == P7_VENDOR_EXT_REQ) {
+    //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__);
+    vendor_ext_p7_req *req = (vendor_ext_p7_req *)(header);
+
+    if(!(push16(req->dummy1, ppWritePackedMsg, end) &&
+         push16(req->dummy2, ppWritePackedMsg, end)))
+      return 0;
+  }
+
+  return 1;
 }
 
-void mac_dl_config_req(mac_t* mac, nfapi_dl_config_request_t* req)
-{
-	vnf_p7_info* info = (vnf_p7_info*)(mac->user_data);
+int vnf_sim_unpack_p4_p5_vendor_extension(nfapi_p4_p5_message_header_t *header, uint8_t **ppReadPackedMessage, uint8_t *end, nfapi_p4_p5_codec_config_t *codec) {
+  //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__);
+  if(header->message_id == P5_VENDOR_EXT_RSP) {
+    vendor_ext_p5_rsp *req = (vendor_ext_p5_rsp *)(header);
+    return(!pull16(ppReadPackedMessage, &req->error_code, end));
+  }
 
-	nfapi_vnf_p7_dl_config_req(info->config.get(), req);
+  return 0;
 }
 
-void mac_ul_config_req(mac_t* mac, nfapi_ul_config_request_t* req)
-{
-	vnf_p7_info* info = (vnf_p7_info*)(mac->user_data);
+int vnf_sim_pack_p4_p5_vendor_extension(nfapi_p4_p5_message_header_t *header, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *codec) {
+  //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__);
+  if(header->message_id == P5_VENDOR_EXT_REQ) {
+    vendor_ext_p5_req *req = (vendor_ext_p5_req *)(header);
+    //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s %d %d\n", __FUNCTION__, req->dummy1, req->dummy2);
+    return (!(push16(req->dummy1, ppWritePackedMsg, end) &&
+              push16(req->dummy2, ppWritePackedMsg, end)));
+  }
 
-	nfapi_vnf_p7_ul_config_req(info->config.get(), req);
+  return 0;
 }
 
-void mac_hi_dci0_req(mac_t* mac, nfapi_hi_dci0_request_t* req)
-{
-	vnf_p7_info* info = (vnf_p7_info*)(mac->user_data);
+void vnf_sim_trace(nfapi_trace_level_t level, const char *message, ...) {
+  va_list args;
+  va_start(args, message);
+  vprintf(message, args);
+  va_end(args);
+}
 
-	nfapi_vnf_p7_hi_dci0_req(info->config.get(), req);
+void mac_dl_config_req(mac_t *mac, nfapi_dl_config_request_t *req) {
+  vnf_p7_info *info = (vnf_p7_info *)(mac->user_data);
+  nfapi_vnf_p7_dl_config_req(info->config.get(), req);
 }
 
-void mac_tx_req(mac_t* mac, nfapi_tx_request_t* req)
-{
-	vnf_p7_info* info = (vnf_p7_info*)(mac->user_data);
+void mac_ul_config_req(mac_t *mac, nfapi_ul_config_request_t *req) {
+  vnf_p7_info *info = (vnf_p7_info *)(mac->user_data);
+  nfapi_vnf_p7_ul_config_req(info->config.get(), req);
+}
 
-	nfapi_vnf_p7_tx_req(info->config.get(), req);
+void mac_hi_dci0_req(mac_t *mac, nfapi_hi_dci0_request_t *req) {
+  vnf_p7_info *info = (vnf_p7_info *)(mac->user_data);
+  nfapi_vnf_p7_hi_dci0_req(info->config.get(), req);
 }
 
-int phy_subframe_indication(struct nfapi_vnf_p7_config* config, uint16_t phy_id, uint16_t sfn_sf)
-{
-	//printf("[VNF_SIM] subframe indication %d\n", sfn_sf);
-	vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data);
-	mac_subframe_ind(p7_vnf->mac, phy_id, sfn_sf);
-	return 0;
+void mac_tx_req(mac_t *mac, nfapi_tx_request_t *req) {
+  vnf_p7_info *info = (vnf_p7_info *)(mac->user_data);
+  nfapi_vnf_p7_tx_req(info->config.get(), req);
 }
-int phy_harq_indication(struct nfapi_vnf_p7_config* config, nfapi_harq_indication_t* ind)
-{
-	vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data);
-	mac_harq_ind(p7_vnf->mac, ind);
-	return 1;
+
+int phy_subframe_indication(struct nfapi_vnf_p7_config *config, uint16_t phy_id, uint16_t sfn_sf) {
+  //printf("[VNF_SIM] subframe indication %d\n", sfn_sf);
+  vnf_p7_info *p7_vnf = (vnf_p7_info *)(config->user_data);
+  mac_subframe_ind(p7_vnf->mac, phy_id, sfn_sf);
+  return 0;
 }
-int phy_crc_indication(struct nfapi_vnf_p7_config* config, nfapi_crc_indication_t* ind)
-{
-	vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data);
-	mac_crc_ind(p7_vnf->mac, ind);
-	return 1;
+int phy_harq_indication(struct nfapi_vnf_p7_config *config, nfapi_harq_indication_t *ind) {
+  vnf_p7_info *p7_vnf = (vnf_p7_info *)(config->user_data);
+  mac_harq_ind(p7_vnf->mac, ind);
+  return 1;
 }
-int phy_rx_indication(struct nfapi_vnf_p7_config* config, nfapi_rx_indication_t* ind)
-{
-	vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data);
-	mac_rx_ind(p7_vnf->mac, ind);
-	return 1;
+int phy_crc_indication(struct nfapi_vnf_p7_config *config, nfapi_crc_indication_t *ind) {
+  vnf_p7_info *p7_vnf = (vnf_p7_info *)(config->user_data);
+  mac_crc_ind(p7_vnf->mac, ind);
+  return 1;
 }
-int phy_rach_indication(struct nfapi_vnf_p7_config* config, nfapi_rach_indication_t* ind)
-{
-	vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data);
-	mac_rach_ind(p7_vnf->mac, ind);
-	return 1;
+int phy_rx_indication(struct nfapi_vnf_p7_config *config, nfapi_rx_indication_t *ind) {
+  vnf_p7_info *p7_vnf = (vnf_p7_info *)(config->user_data);
+  mac_rx_ind(p7_vnf->mac, ind);
+  return 1;
 }
-int phy_srs_indication(struct nfapi_vnf_p7_config* config, nfapi_srs_indication_t* ind)
-{
-	vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data);
-	mac_srs_ind(p7_vnf->mac, ind);
-	return 1;
+int phy_rach_indication(struct nfapi_vnf_p7_config *config, nfapi_rach_indication_t *ind) {
+  vnf_p7_info *p7_vnf = (vnf_p7_info *)(config->user_data);
+  mac_rach_ind(p7_vnf->mac, ind);
+  return 1;
 }
-int phy_sr_indication(struct nfapi_vnf_p7_config* config, nfapi_sr_indication_t* ind)
-{
-	vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data);
-	mac_sr_ind(p7_vnf->mac, ind);
-	return 1;
+int phy_srs_indication(struct nfapi_vnf_p7_config *config, nfapi_srs_indication_t *ind) {
+  vnf_p7_info *p7_vnf = (vnf_p7_info *)(config->user_data);
+  mac_srs_ind(p7_vnf->mac, ind);
+  return 1;
 }
-int phy_cqi_indication(struct nfapi_vnf_p7_config* config, nfapi_cqi_indication_t* ind)
-{
-	vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data);
-	mac_cqi_ind(p7_vnf->mac, ind);
-	return 1;
+int phy_sr_indication(struct nfapi_vnf_p7_config *config, nfapi_sr_indication_t *ind) {
+  vnf_p7_info *p7_vnf = (vnf_p7_info *)(config->user_data);
+  mac_sr_ind(p7_vnf->mac, ind);
+  return 1;
 }
-int phy_lbt_dl_indication(struct nfapi_vnf_p7_config* config, nfapi_lbt_dl_indication_t* ind)
-{
-	vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data);
-	mac_lbt_dl_ind(p7_vnf->mac, ind);
-	return 1;
+int phy_cqi_indication(struct nfapi_vnf_p7_config *config, nfapi_cqi_indication_t *ind) {
+  vnf_p7_info *p7_vnf = (vnf_p7_info *)(config->user_data);
+  mac_cqi_ind(p7_vnf->mac, ind);
+  return 1;
 }
-int phy_nb_harq_indication(struct nfapi_vnf_p7_config* config, nfapi_nb_harq_indication_t* ind)
-{
-	vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data);
-	mac_nb_harq_ind(p7_vnf->mac, ind);
-	return 1;
+int phy_lbt_dl_indication(struct nfapi_vnf_p7_config *config, nfapi_lbt_dl_indication_t *ind) {
+  vnf_p7_info *p7_vnf = (vnf_p7_info *)(config->user_data);
+  mac_lbt_dl_ind(p7_vnf->mac, ind);
+  return 1;
 }
-int phy_nrach_indication(struct nfapi_vnf_p7_config* config, nfapi_nrach_indication_t* ind)
-{
-	vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data);
-	mac_nrach_ind(p7_vnf->mac, ind);
-	return 1;
+int phy_nb_harq_indication(struct nfapi_vnf_p7_config *config, nfapi_nb_harq_indication_t *ind) {
+  vnf_p7_info *p7_vnf = (vnf_p7_info *)(config->user_data);
+  mac_nb_harq_ind(p7_vnf->mac, ind);
+  return 1;
 }
-int phy_vendor_ext(struct nfapi_vnf_p7_config* config, nfapi_p7_message_header_t* msg)
-{
-	if(msg->message_id == P7_VENDOR_EXT_IND)
-	{
-		//vendor_ext_p7_ind* ind = (vendor_ext_p7_ind*)msg;
-		//printf("[VNF_SIM] vendor_ext (error_code:%d)\n", ind->error_code);
-	}
-	else
-	{
-		printf("[VNF_SIM] unknown %d\n", msg->message_id);
-	}
-	return 0;
+int phy_nrach_indication(struct nfapi_vnf_p7_config *config, nfapi_nrach_indication_t *ind) {
+  vnf_p7_info *p7_vnf = (vnf_p7_info *)(config->user_data);
+  mac_nrach_ind(p7_vnf->mac, ind);
+  return 1;
 }
-nfapi_p7_message_header_t* phy_allocate_p7_vendor_ext(uint16_t message_id, uint16_t* msg_size)
-{
-	if(message_id == P7_VENDOR_EXT_IND)
-	{
-		*msg_size = sizeof(vendor_ext_p7_ind);
-		return (nfapi_p7_message_header_t*)malloc(sizeof(vendor_ext_p7_ind));
-	}
-	return 0;
+int phy_vendor_ext(struct nfapi_vnf_p7_config *config, nfapi_p7_message_header_t *msg) {
+  if(msg->message_id == P7_VENDOR_EXT_IND) {
+    //vendor_ext_p7_ind* ind = (vendor_ext_p7_ind*)msg;
+    //printf("[VNF_SIM] vendor_ext (error_code:%d)\n", ind->error_code);
+  } else {
+    printf("[VNF_SIM] unknown %d\n", msg->message_id);
+  }
+
+  return 0;
 }
-void phy_deallocate_p7_vendor_ext(nfapi_p7_message_header_t* header)
-{
-	free(header);
+nfapi_p7_message_header_t *phy_allocate_p7_vendor_ext(uint16_t message_id, uint16_t *msg_size) {
+  if(message_id == P7_VENDOR_EXT_IND) {
+    *msg_size = sizeof(vendor_ext_p7_ind);
+    return (nfapi_p7_message_header_t *)malloc(sizeof(vendor_ext_p7_ind));
+  }
+
+  return 0;
+}
+void phy_deallocate_p7_vendor_ext(nfapi_p7_message_header_t *header) {
+  free(header);
 }
 
 //static pthread_t vnf_start_pthread;
 static pthread_t vnf_p7_start_pthread;
-void* vnf_p7_start_thread(void *ptr)
-{
+void *vnf_p7_start_thread(void *ptr) {
   printf("%s()\n", __FUNCTION__);
-
   //std::shared_ptr<nfapi_vnf_p7_config> config = std::shared_ptr<nfapi_vnf_p7_config>(ptr);
   nfapi_vnf_p7_config_t *config = (nfapi_vnf_p7_config_t *)ptr;
-
   nfapi_vnf_p7_start(config);
-
   return 0;
 }
 
-void set_thread_priority(int priority)
-{
-	//printf("%s(priority:%d)\n", __FUNCTION__, priority);
-	
-	pthread_attr_t ptAttr;
-	
-	struct sched_param schedParam;
-	schedParam.__sched_priority = priority; //79;
-	if(sched_setscheduler(0, SCHED_RR, &schedParam) != 0)
-	{
-		printf("Failed to set scheduler to SCHED_RR\n");
-	}
-
-	if(pthread_attr_setschedpolicy(&ptAttr, SCHED_RR) != 0)
-	{
-		printf("Failed to set pthread sched policy SCHED_RR\n");
-	}
-
-	pthread_attr_setinheritsched(&ptAttr, PTHREAD_EXPLICIT_SCHED);
-
-	struct sched_param thread_params;
-	thread_params.sched_priority = 20;
-	if(pthread_attr_setschedparam(&ptAttr, &thread_params) != 0)
-	{
-		printf("failed to set sched param\n");
-	}
-}
-
-void* vnf_p7_thread_start(void* ptr)
-{
-  printf("%s()\n", __FUNCTION__);
-
-	set_thread_priority(79);
-
-	vnf_p7_info* p7_vnf = (vnf_p7_info*)ptr;
-
-	p7_vnf->config->port = p7_vnf->local_port;
-	p7_vnf->config->subframe_indication = &phy_subframe_indication;
-	p7_vnf->config->harq_indication = &phy_harq_indication;
-	p7_vnf->config->crc_indication = &phy_crc_indication;
-	p7_vnf->config->rx_indication = &phy_rx_indication;
-	p7_vnf->config->rach_indication = &phy_rach_indication;
-	p7_vnf->config->srs_indication = &phy_srs_indication;
-	p7_vnf->config->sr_indication = &phy_sr_indication;
-	p7_vnf->config->cqi_indication = &phy_cqi_indication;
-	p7_vnf->config->lbt_dl_indication = &phy_lbt_dl_indication;
-	p7_vnf->config->nb_harq_indication = &phy_nb_harq_indication;
-	p7_vnf->config->nrach_indication = &phy_nrach_indication;
-	p7_vnf->config->malloc = &vnf_allocate;
-	p7_vnf->config->free = &vnf_deallocate;
-
-	p7_vnf->config->trace = &vnf_sim_trace;
+void set_thread_priority(int priority) {
+  //printf("%s(priority:%d)\n", __FUNCTION__, priority);
+  pthread_attr_t ptAttr;
+  struct sched_param schedParam;
+  schedParam.__sched_priority = priority; //79;
 
-	p7_vnf->config->vendor_ext = &phy_vendor_ext;
-	p7_vnf->config->user_data = p7_vnf;
+  if(sched_setscheduler(0, SCHED_RR, &schedParam) != 0) {
+    printf("Failed to set scheduler to SCHED_RR\n");
+  }
 
-	p7_vnf->mac->user_data = p7_vnf;
+  if(pthread_attr_setschedpolicy(&ptAttr, SCHED_RR) != 0) {
+    printf("Failed to set pthread sched policy SCHED_RR\n");
+  }
 
-	p7_vnf->config->codec_config.unpack_p7_vendor_extension = &phy_unpack_p7_vendor_extension;
-	p7_vnf->config->codec_config.pack_p7_vendor_extension = &phy_pack_p7_vendor_extension;
-	p7_vnf->config->codec_config.unpack_vendor_extension_tlv = &phy_unpack_vendor_extension_tlv;
-	p7_vnf->config->codec_config.pack_vendor_extension_tlv = &phy_pack_vendor_extension_tlv;
-	p7_vnf->config->codec_config.allocate = &vnf_allocate;
-	p7_vnf->config->codec_config.deallocate = &vnf_deallocate;
+  pthread_attr_setinheritsched(&ptAttr, PTHREAD_EXPLICIT_SCHED);
+  struct sched_param thread_params;
+  thread_params.sched_priority = 20;
 
-	p7_vnf->config->allocate_p7_vendor_ext = &phy_allocate_p7_vendor_ext;
-	p7_vnf->config->deallocate_p7_vendor_ext = &phy_deallocate_p7_vendor_ext;
-
-        printf("[VNF] Creating VNF NFAPI start thread %s\n", __FUNCTION__);
-        pthread_create(&vnf_p7_start_pthread, NULL, &vnf_p7_start_thread, p7_vnf->config.get());
-
-	return 0;
+  if(pthread_attr_setschedparam(&ptAttr, &thread_params) != 0) {
+    printf("failed to set sched param\n");
+  }
 }
 
-int pnf_connection_indication_cb(nfapi_vnf_config_t* config, int p5_idx)
-{
-	printf("[VNF_SIM] pnf connection indication idx:%d\n", p5_idx);
-
-	pnf_info pnf;
-	vnf_info* vnf = (vnf_info*)(config->user_data);
-	vnf->pnfs.insert(std::pair<uint16_t, pnf_info>(p5_idx, pnf));
-
-	nfapi_pnf_param_request_t req;
-	memset(&req, 0, sizeof(req));
-	req.header.message_id = NFAPI_PNF_PARAM_REQUEST;
-	nfapi_vnf_pnf_param_req(config, p5_idx, &req);
-	return 0;
+void *vnf_p7_thread_start(void *ptr) {
+  printf("%s()\n", __FUNCTION__);
+  set_thread_priority(79);
+  vnf_p7_info *p7_vnf = (vnf_p7_info *)ptr;
+  p7_vnf->config->port = p7_vnf->local_port;
+  p7_vnf->config->subframe_indication = &phy_subframe_indication;
+  p7_vnf->config->harq_indication = &phy_harq_indication;
+  p7_vnf->config->crc_indication = &phy_crc_indication;
+  p7_vnf->config->rx_indication = &phy_rx_indication;
+  p7_vnf->config->rach_indication = &phy_rach_indication;
+  p7_vnf->config->srs_indication = &phy_srs_indication;
+  p7_vnf->config->sr_indication = &phy_sr_indication;
+  p7_vnf->config->cqi_indication = &phy_cqi_indication;
+  p7_vnf->config->lbt_dl_indication = &phy_lbt_dl_indication;
+  p7_vnf->config->nb_harq_indication = &phy_nb_harq_indication;
+  p7_vnf->config->nrach_indication = &phy_nrach_indication;
+  p7_vnf->config->malloc = &vnf_allocate;
+  p7_vnf->config->free = &vnf_deallocate;
+  p7_vnf->config->trace = &vnf_sim_trace;
+  p7_vnf->config->vendor_ext = &phy_vendor_ext;
+  p7_vnf->config->user_data = p7_vnf;
+  p7_vnf->mac->user_data = p7_vnf;
+  p7_vnf->config->codec_config.unpack_p7_vendor_extension = &phy_unpack_p7_vendor_extension;
+  p7_vnf->config->codec_config.pack_p7_vendor_extension = &phy_pack_p7_vendor_extension;
+  p7_vnf->config->codec_config.unpack_vendor_extension_tlv = &phy_unpack_vendor_extension_tlv;
+  p7_vnf->config->codec_config.pack_vendor_extension_tlv = &phy_pack_vendor_extension_tlv;
+  p7_vnf->config->codec_config.allocate = &vnf_allocate;
+  p7_vnf->config->codec_config.deallocate = &vnf_deallocate;
+  p7_vnf->config->allocate_p7_vendor_ext = &phy_allocate_p7_vendor_ext;
+  p7_vnf->config->deallocate_p7_vendor_ext = &phy_deallocate_p7_vendor_ext;
+  printf("[VNF] Creating VNF NFAPI start thread %s\n", __FUNCTION__);
+  pthread_create(&vnf_p7_start_pthread, NULL, &vnf_p7_start_thread, p7_vnf->config.get());
+  return 0;
 }
-int pnf_disconnection_indication_cb(nfapi_vnf_config_t* config, int p5_idx)
-{
-	printf("[VNF_SIM] pnf disconnection indication idx:%d\n", p5_idx);
-
-	
-	vnf_info* vnf = (vnf_info*)(config->user_data);
-	auto find_result = vnf->pnfs.find(p5_idx);
-	
-	if(find_result != vnf->pnfs.end())
-	{
-		pnf_info& pnf = find_result->second;
-
-		for(phy_info& phy : pnf.phys)
-		{
-			vnf_p7_info& p7_vnf = vnf->p7_vnfs[0];
-			nfapi_vnf_p7_del_pnf((p7_vnf.config.get()), phy.id);
-		}
-	}
 
-	return 0;
+int pnf_connection_indication_cb(nfapi_vnf_config_t *config, int p5_idx) {
+  printf("[VNF_SIM] pnf connection indication idx:%d\n", p5_idx);
+  pnf_info pnf;
+  vnf_info *vnf = (vnf_info *)(config->user_data);
+  vnf->pnfs.insert(std::pair<uint16_t, pnf_info>(p5_idx, pnf));
+  nfapi_pnf_param_request_t req;
+  memset(&req, 0, sizeof(req));
+  req.header.message_id = NFAPI_PNF_PARAM_REQUEST;
+  nfapi_vnf_pnf_param_req(config, p5_idx, &req);
+  return 0;
 }
+int pnf_disconnection_indication_cb(nfapi_vnf_config_t *config, int p5_idx) {
+  printf("[VNF_SIM] pnf disconnection indication idx:%d\n", p5_idx);
+  vnf_info *vnf = (vnf_info *)(config->user_data);
+  auto find_result = vnf->pnfs.find(p5_idx);
 
-int pnf_param_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_pnf_param_response_t* resp)
-{
-	printf("[VNF_SIM] pnf param response idx:%d error:%d\n", p5_idx, resp->error_code);
-
-	vnf_info* vnf = (vnf_info*)(config->user_data);
-
-	auto find_result = vnf->pnfs.find(p5_idx);
-	if(find_result != vnf->pnfs.end())
-	{
-		pnf_info& pnf = find_result->second;
-
-		for(int i = 0; i < resp->pnf_phy.number_of_phys; ++i)
-		{
-			phy_info phy;
-			phy.index = resp->pnf_phy.phy[i].phy_config_index;
-
-			printf("[VNF_SIM] (PHY:%d) phy_config_idx:%d\n", i, resp->pnf_phy.phy[i].phy_config_index);
-
-			nfapi_vnf_allocate_phy(config, p5_idx, &(phy.id));
-
-
-
-			for(int j = 0; j < resp->pnf_phy.phy[i].number_of_rfs; ++j)
-			{
-				printf("[VNF_SIM] (PHY:%d) (RF%d) %d\n", i, j, resp->pnf_phy.phy[i].rf_config[j].rf_config_index);
-				phy.rfs.push_back(resp->pnf_phy.phy[i].rf_config[j].rf_config_index);
-			}
-
-
-			pnf.phys.push_back(phy);
-		}
-		for(int i = 0; i < resp->pnf_rf.number_of_rfs; ++i)
-		{
-			rf_info rf;
-			rf.index = resp->pnf_rf.rf[i].rf_config_index;
-
-			printf("[VNF_SIM] (RF:%d) rf_config_idx:%d\n", i, resp->pnf_rf.rf[i].rf_config_index);
-
-			pnf.rfs.push_back(rf);
-		}
-
-		nfapi_pnf_config_request_t req;
-		memset(&req, 0, sizeof(req));
-		req.header.message_id = NFAPI_PNF_CONFIG_REQUEST;
-
-		req.pnf_phy_rf_config.tl.tag = NFAPI_PNF_PHY_RF_TAG;
-		req.pnf_phy_rf_config.number_phy_rf_config_info = pnf.phys.size();
+  if(find_result != vnf->pnfs.end()) {
+    pnf_info &pnf = find_result->second;
 
-		for(unsigned i = 0; i < pnf.phys.size(); ++i)
-		{
-			req.pnf_phy_rf_config.phy_rf_config[i].phy_id = pnf.phys[i].id;
-			req.pnf_phy_rf_config.phy_rf_config[i].phy_config_index = pnf.phys[i].index;
-			req.pnf_phy_rf_config.phy_rf_config[i].rf_config_index = pnf.phys[i].rfs[0];
-		}
+    for(phy_info &phy : pnf.phys) {
+      vnf_p7_info &p7_vnf = vnf->p7_vnfs[0];
+      nfapi_vnf_p7_del_pnf((p7_vnf.config.get()), phy.id);
+    }
+  }
 
-
-		nfapi_vnf_pnf_config_req(config, p5_idx, &req);
-	}
-	return 0;
+  return 0;
 }
 
-int pnf_config_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_pnf_config_response_t* resp)
-{
-	printf("[VNF_SIM] pnf config response idx:%d\n", p5_idx);
-	
-	if(1)
-	{
-		vnf_info* vnf = (vnf_info*)(config->user_data);
-		auto find_result = vnf->pnfs.find(p5_idx);
-		if(find_result != vnf->pnfs.end())
-		{
-			//pnf_info& pnf = find_result->second;
-
-			nfapi_pnf_start_request_t req;
-			memset(&req, 0, sizeof(req));
-			req.header.message_id = NFAPI_PNF_START_REQUEST;
-			nfapi_vnf_pnf_start_req(config, p5_idx, &req);
-		}
-	}
-	else
-	{
-		// Rather than send the pnf_start_request we will demonstrate
-		// sending a vendor extention message. The start request will be
-		// send when the vendor extension response is received 
-
-		//vnf_info* vnf = (vnf_info*)(config->user_data);
-		vendor_ext_p5_req req;
-		memset(&req, 0, sizeof(req));
-		req.header.message_id = P5_VENDOR_EXT_REQ;
-		req.dummy1 = 45;
-		req.dummy2 = 1977;
-		nfapi_vnf_vendor_extension(config, p5_idx, &req.header);
-	}
-	return 0;
+int pnf_param_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_pnf_param_response_t *resp) {
+  printf("[VNF_SIM] pnf param response idx:%d error:%d\n", p5_idx, resp->error_code);
+  vnf_info *vnf = (vnf_info *)(config->user_data);
+  auto find_result = vnf->pnfs.find(p5_idx);
+
+  if(find_result != vnf->pnfs.end()) {
+    pnf_info &pnf = find_result->second;
+
+    for(int i = 0; i < resp->pnf_phy.number_of_phys; ++i) {
+      phy_info phy;
+      phy.index = resp->pnf_phy.phy[i].phy_config_index;
+      printf("[VNF_SIM] (PHY:%d) phy_config_idx:%d\n", i, resp->pnf_phy.phy[i].phy_config_index);
+      nfapi_vnf_allocate_phy(config, p5_idx, &(phy.id));
+
+      for(int j = 0; j < resp->pnf_phy.phy[i].number_of_rfs; ++j) {
+        printf("[VNF_SIM] (PHY:%d) (RF%d) %d\n", i, j, resp->pnf_phy.phy[i].rf_config[j].rf_config_index);
+        phy.rfs.push_back(resp->pnf_phy.phy[i].rf_config[j].rf_config_index);
+      }
+
+      pnf.phys.push_back(phy);
+    }
+
+    for(int i = 0; i < resp->pnf_rf.number_of_rfs; ++i) {
+      rf_info rf;
+      rf.index = resp->pnf_rf.rf[i].rf_config_index;
+      printf("[VNF_SIM] (RF:%d) rf_config_idx:%d\n", i, resp->pnf_rf.rf[i].rf_config_index);
+      pnf.rfs.push_back(rf);
+    }
+
+    nfapi_pnf_config_request_t req;
+    memset(&req, 0, sizeof(req));
+    req.header.message_id = NFAPI_PNF_CONFIG_REQUEST;
+    req.pnf_phy_rf_config.tl.tag = NFAPI_PNF_PHY_RF_TAG;
+    req.pnf_phy_rf_config.number_phy_rf_config_info = pnf.phys.size();
+
+    for(unsigned i = 0; i < pnf.phys.size(); ++i) {
+      req.pnf_phy_rf_config.phy_rf_config[i].phy_id = pnf.phys[i].id;
+      req.pnf_phy_rf_config.phy_rf_config[i].phy_config_index = pnf.phys[i].index;
+      req.pnf_phy_rf_config.phy_rf_config[i].rf_config_index = pnf.phys[i].rfs[0];
+    }
+
+    nfapi_vnf_pnf_config_req(config, p5_idx, &req);
+  }
 }
-
 int pnf_start_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_pnf_start_response_t* resp)
 {
 	printf("[VNF_SIM] pnf start response idx:%d\n", p5_idx);
@@ -716,7 +596,7 @@ int param_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_param_response_t
 			// for now just 1
 			vnf_p7_info& p7_vnf = vnf->p7_vnfs[0];
 
-			printf("[VNF_SIM] %d.%d pnf p7 %s:%d timing %d %d %d %d\n", p5_idx, phy.id, phy.remote_addr.c_str(), phy.remote_port, p7_vnf.timing_window, p7_vnf.periodic_timing_period, p7_vnf.aperiodic_timing_enabled, p7_vnf.periodic_timing_period);
+			printf("[VNF_SIM] %d.%d pnf p7 %s:%d timing %u %u %u %u\n", p5_idx, phy.id, phy.remote_addr.c_str(), phy.remote_port, p7_vnf.timing_window, p7_vnf.periodic_timing_period, p7_vnf.aperiodic_timing_enabled, p7_vnf.periodic_timing_period);
 
 
 			nfapi_config_request_t req;
@@ -1065,461 +945,768 @@ int param_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_param_response_t
 	return 0;
 }
 
-int config_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_config_response_t* resp)
-{
-	printf("[VNF_SIM] config response idx:%d phy_id:%d\n", p5_idx, resp->header.phy_id);
+int pnf_config_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_pnf_config_response_t *resp) {
+  printf("[VNF_SIM] pnf config response idx:%d\n", p5_idx);
+
+  if(1) {
+    vnf_info *vnf = (vnf_info *)(config->user_data);
+    auto find_result = vnf->pnfs.find(p5_idx);
+
+    if(find_result != vnf->pnfs.end()) {
+      //pnf_info& pnf = find_result->second;
+      nfapi_pnf_start_request_t req;
+      memset(&req, 0, sizeof(req));
+      req.header.message_id = NFAPI_PNF_START_REQUEST;
+      nfapi_vnf_pnf_start_req(config, p5_idx, &req);
+    }
+  } else {
+    // Rather than send the pnf_start_request we will demonstrate
+    // sending a vendor extention message. The start request will be
+    // send when the vendor extension response is received
+    //vnf_info* vnf = (vnf_info*)(config->user_data);
+    vendor_ext_p5_req req;
+    memset(&req, 0, sizeof(req));
+    req.header.message_id = P5_VENDOR_EXT_REQ;
+    req.dummy1 = 45;
+    req.dummy2 = 1977;
+    nfapi_vnf_vendor_extension(config, p5_idx, &req.header);
+  }
 
+  return 0;
+}
 
-	nfapi_start_request_t req;
-	memset(&req, 0, sizeof(req));
-	req.header.message_id = NFAPI_START_REQUEST;
-	req.header.phy_id = resp->header.phy_id;
-	nfapi_vnf_start_req(config, p5_idx, &req);
+int pnf_start_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_pnf_start_response_t *resp) {
+  printf("[VNF_SIM] pnf start response idx:%d\n", p5_idx);
+  vnf_info *vnf = (vnf_info *)(config->user_data);
+  vnf_p7_info &p7_vnf = vnf->p7_vnfs[0];
+
+  if(p7_vnf.thread_started == false) {
+    pthread_t vnf_p7_thread;
+    pthread_create(&vnf_p7_thread, NULL, &vnf_p7_thread_start, &p7_vnf);
+    p7_vnf.thread_started = true;
+  } else {
+    // P7 thread already running.
+  }
+
+  // start all the phys in the pnf.
+  auto find_result = vnf->pnfs.find(p5_idx);
+
+  if(find_result != vnf->pnfs.end()) {
+    pnf_info &pnf = find_result->second;
+
+    for(unsigned i = 0; i < pnf.phys.size(); ++i) {
+      pnf_info &pnf = find_result->second;
+      nfapi_param_request_t req;
+      memset(&req, 0, sizeof(req));
+      req.header.message_id = NFAPI_PARAM_REQUEST;
+      req.header.phy_id = pnf.phys[i].id;
+      nfapi_vnf_param_req(config, p5_idx, &req);
+    }
+  }
 
-	return 0;
+  return 0;
 }
+int param_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_param_response_t *resp) {
+  printf("[VNF_SIM] param response idx:%d phy_id:%d\n", p5_idx, resp->header.phy_id);
+  vnf_info *vnf = (vnf_info *)(config->user_data);
+  auto find_result = vnf->pnfs.find(p5_idx);
+
+  if(find_result != vnf->pnfs.end()) {
+    pnf_info &pnf = find_result->second;
+    auto found = std::find_if(pnf.phys.begin(), pnf.phys.end(), [&](phy_info& item) {
+      return item.id == resp->header.phy_id;
+    });
+
+    if(found != pnf.phys.end()) {
+      phy_info &phy = (*found);
+      phy.remote_port = resp->nfapi_config.p7_pnf_port.value;
+      struct sockaddr_in pnf_p7_sockaddr;
+      memcpy(&pnf_p7_sockaddr.sin_addr.s_addr, &(resp->nfapi_config.p7_pnf_address_ipv4.address[0]), 4);
+      phy.remote_addr = inet_ntoa(pnf_p7_sockaddr.sin_addr);
+      // for now just 1
+      vnf_p7_info &p7_vnf = vnf->p7_vnfs[0];
+      printf("[VNF_SIM] %d.%d pnf p7 %s:%d timing %u %u %u %u\n", p5_idx, phy.id, phy.remote_addr.c_str(), phy.remote_port, p7_vnf.timing_window, p7_vnf.periodic_timing_period,
+             p7_vnf.aperiodic_timing_enabled, p7_vnf.periodic_timing_period);
+      nfapi_config_request_t req;
+      memset(&req, 0, sizeof(req));
+      req.header.message_id = NFAPI_CONFIG_REQUEST;
+      req.header.phy_id = phy.id;
+      req.nfapi_config.p7_vnf_port.tl.tag = NFAPI_NFAPI_P7_VNF_PORT_TAG;
+      req.nfapi_config.p7_vnf_port.value = p7_vnf.local_port;
+      req.num_tlv++;
+      req.nfapi_config.p7_vnf_address_ipv4.tl.tag = NFAPI_NFAPI_P7_VNF_ADDRESS_IPV4_TAG;
+      struct sockaddr_in vnf_p7_sockaddr;
+      vnf_p7_sockaddr.sin_addr.s_addr = inet_addr(p7_vnf.local_addr.c_str());
+      memcpy(&(req.nfapi_config.p7_vnf_address_ipv4.address[0]), &vnf_p7_sockaddr.sin_addr.s_addr, 4);
+      req.num_tlv++;
+      req.nfapi_config.timing_window.tl.tag = NFAPI_NFAPI_TIMING_WINDOW_TAG;
+      req.nfapi_config.timing_window.value = p7_vnf.timing_window;
+      req.num_tlv++;
+
+      if(p7_vnf.periodic_timing_enabled || p7_vnf.aperiodic_timing_enabled) {
+        req.nfapi_config.timing_info_mode.tl.tag = NFAPI_NFAPI_TIMING_INFO_MODE_TAG;
+        req.nfapi_config.timing_info_mode.value = (p7_vnf.aperiodic_timing_enabled << 1) | (p7_vnf.periodic_timing_enabled);
+        req.num_tlv++;
+
+        if(p7_vnf.periodic_timing_enabled) {
+          req.nfapi_config.timing_info_period.tl.tag = NFAPI_NFAPI_TIMING_INFO_PERIOD_TAG;
+          req.nfapi_config.timing_info_period.value = p7_vnf.periodic_timing_period;
+          req.num_tlv++;
+        }
+      }
+
+      req.nfapi_config.earfcn.tl.tag = NFAPI_NFAPI_EARFCN_TAG;
+      req.nfapi_config.earfcn.value = phy.earfcn;
+      req.num_tlv++;
+
+      if(1) {
+        // Poplate all tlv for wireshark testing
+        req.subframe_config.duplex_mode.tl.tag = NFAPI_SUBFRAME_CONFIG_DUPLEX_MODE_TAG;
+        req.num_tlv++;
+        req.subframe_config.pcfich_power_offset.tl.tag = NFAPI_SUBFRAME_CONFIG_PCFICH_POWER_OFFSET_TAG;
+        req.num_tlv++;
+        req.subframe_config.pb.tl.tag = NFAPI_SUBFRAME_CONFIG_PB_TAG;
+        req.num_tlv++;
+        req.subframe_config.dl_cyclic_prefix_type.tl.tag = NFAPI_SUBFRAME_CONFIG_DL_CYCLIC_PREFIX_TYPE_TAG;
+        req.num_tlv++;
+        req.subframe_config.ul_cyclic_prefix_type.tl.tag = NFAPI_SUBFRAME_CONFIG_UL_CYCLIC_PREFIX_TYPE_TAG;
+        req.num_tlv++;
+        req.rf_config.dl_channel_bandwidth.tl.tag = NFAPI_RF_CONFIG_DL_CHANNEL_BANDWIDTH_TAG;
+        req.num_tlv++;
+        req.rf_config.ul_channel_bandwidth.tl.tag = NFAPI_RF_CONFIG_UL_CHANNEL_BANDWIDTH_TAG;
+        req.num_tlv++;
+        req.rf_config.reference_signal_power.tl.tag = NFAPI_RF_CONFIG_REFERENCE_SIGNAL_POWER_TAG;
+        req.num_tlv++;
+        req.rf_config.tx_antenna_ports.tl.tag = NFAPI_RF_CONFIG_TX_ANTENNA_PORTS_TAG;
+        req.num_tlv++;
+        req.rf_config.rx_antenna_ports.tl.tag = NFAPI_RF_CONFIG_RX_ANTENNA_PORTS_TAG;
+        req.num_tlv++;
+        req.phich_config.phich_resource.tl.tag = NFAPI_PHICH_CONFIG_PHICH_RESOURCE_TAG;
+        req.num_tlv++;
+        req.phich_config.phich_duration.tl.tag = NFAPI_PHICH_CONFIG_PHICH_DURATION_TAG;
+        req.num_tlv++;
+        req.phich_config.phich_power_offset.tl.tag = NFAPI_PHICH_CONFIG_PHICH_POWER_OFFSET_TAG;
+        req.num_tlv++;
+        req.sch_config.primary_synchronization_signal_epre_eprers.tl.tag = NFAPI_SCH_CONFIG_PRIMARY_SYNCHRONIZATION_SIGNAL_EPRE_EPRERS_TAG;
+        req.num_tlv++;
+        req.sch_config.secondary_synchronization_signal_epre_eprers.tl.tag = NFAPI_SCH_CONFIG_SECONDARY_SYNCHRONIZATION_SIGNAL_EPRE_EPRERS_TAG;
+        req.num_tlv++;
+        req.sch_config.physical_cell_id.tl.tag = NFAPI_SCH_CONFIG_PHYSICAL_CELL_ID_TAG;
+        req.num_tlv++;
+        req.prach_config.configuration_index.tl.tag = NFAPI_PRACH_CONFIG_CONFIGURATION_INDEX_TAG;
+        req.num_tlv++;
+        req.prach_config.root_sequence_index.tl.tag = NFAPI_PRACH_CONFIG_ROOT_SEQUENCE_INDEX_TAG;
+        req.num_tlv++;
+        req.prach_config.zero_correlation_zone_configuration.tl.tag = NFAPI_PRACH_CONFIG_ZERO_CORRELATION_ZONE_CONFIGURATION_TAG;
+        req.num_tlv++;
+        req.prach_config.high_speed_flag.tl.tag = NFAPI_PRACH_CONFIG_HIGH_SPEED_FLAG_TAG;
+        req.num_tlv++;
+        req.prach_config.frequency_offset.tl.tag = NFAPI_PRACH_CONFIG_FREQUENCY_OFFSET_TAG;
+        req.num_tlv++;
+        req.pusch_config.hopping_mode.tl.tag = NFAPI_PUSCH_CONFIG_HOPPING_MODE_TAG;
+        req.num_tlv++;
+        req.pusch_config.hopping_offset.tl.tag = NFAPI_PUSCH_CONFIG_HOPPING_OFFSET_TAG;
+        req.num_tlv++;
+        req.pusch_config.number_of_subbands.tl.tag = NFAPI_PUSCH_CONFIG_NUMBER_OF_SUBBANDS_TAG;
+        req.num_tlv++;
+        req.pucch_config.delta_pucch_shift.tl.tag = NFAPI_PUCCH_CONFIG_DELTA_PUCCH_SHIFT_TAG;
+        req.num_tlv++;
+        req.pucch_config.n_cqi_rb.tl.tag = NFAPI_PUCCH_CONFIG_N_CQI_RB_TAG;
+        req.num_tlv++;
+        req.pucch_config.n_an_cs.tl.tag = NFAPI_PUCCH_CONFIG_N_AN_CS_TAG;
+        req.num_tlv++;
+        req.pucch_config.n1_pucch_an.tl.tag = NFAPI_PUCCH_CONFIG_N1_PUCCH_AN_TAG;
+        req.num_tlv++;
+        req.srs_config.bandwidth_configuration.tl.tag = NFAPI_SRS_CONFIG_BANDWIDTH_CONFIGURATION_TAG;
+        req.num_tlv++;
+        req.srs_config.max_up_pts.tl.tag = NFAPI_SRS_CONFIG_MAX_UP_PTS_TAG;
+        req.num_tlv++;
+        req.srs_config.srs_subframe_configuration.tl.tag = NFAPI_SRS_CONFIG_SRS_SUBFRAME_CONFIGURATION_TAG;
+        req.num_tlv++;
+        req.srs_config.srs_acknack_srs_simultaneous_transmission.tl.tag = NFAPI_SRS_CONFIG_SRS_ACKNACK_SRS_SIMULTANEOUS_TRANSMISSION_TAG;
+        req.num_tlv++;
+        req.uplink_reference_signal_config.uplink_rs_hopping.tl.tag = NFAPI_UPLINK_REFERENCE_SIGNAL_CONFIG_UPLINK_RS_HOPPING_TAG;
+        req.num_tlv++;
+        req.uplink_reference_signal_config.group_assignment.tl.tag = NFAPI_UPLINK_REFERENCE_SIGNAL_CONFIG_GROUP_ASSIGNMENT_TAG;
+        req.num_tlv++;
+        req.uplink_reference_signal_config.cyclic_shift_1_for_drms.tl.tag = NFAPI_UPLINK_REFERENCE_SIGNAL_CONFIG_CYCLIC_SHIFT_1_FOR_DRMS_TAG;
+        req.num_tlv++;
+        req.laa_config.ed_threshold_lbt_pdsch.tl.tag = NFAPI_LAA_CONFIG_ED_THRESHOLD_FOR_LBT_FOR_PDSCH_TAG;
+        req.num_tlv++;
+        req.laa_config.ed_threshold_lbt_drs.tl.tag = NFAPI_LAA_CONFIG_ED_THRESHOLD_FOR_LBT_FOR_DRS_TAG;
+        req.num_tlv++;
+        req.laa_config.pd_threshold.tl.tag = NFAPI_LAA_CONFIG_PD_THRESHOLD_TAG;
+        req.num_tlv++;
+        req.laa_config.multi_carrier_type.tl.tag = NFAPI_LAA_CONFIG_MULTI_CARRIER_TYPE_TAG;
+        req.num_tlv++;
+        req.laa_config.multi_carrier_tx.tl.tag = NFAPI_LAA_CONFIG_MULTI_CARRIER_TX_TAG;
+        req.num_tlv++;
+        req.laa_config.multi_carrier_freeze.tl.tag = NFAPI_LAA_CONFIG_MULTI_CARRIER_FREEZE_TAG;
+        req.num_tlv++;
+        req.laa_config.tx_antenna_ports_drs.tl.tag = NFAPI_LAA_CONFIG_TX_ANTENNA_PORTS_FOR_DRS_TAG;
+        req.num_tlv++;
+        req.laa_config.tx_power_drs.tl.tag = NFAPI_LAA_CONFIG_TRANSMISSION_POWER_FOR_DRS_TAG;
+        req.num_tlv++;
+        req.emtc_config.pbch_repetitions_enable_r13.tl.tag = NFAPI_EMTC_CONFIG_PBCH_REPETITIONS_ENABLE_R13_TAG;
+        req.num_tlv++;
+        req.emtc_config.prach_catm_root_sequence_index.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CATM_ROOT_SEQUENCE_INDEX_TAG;
+        req.num_tlv++;
+        req.emtc_config.prach_catm_zero_correlation_zone_configuration.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CATM_ZERO_CORRELATION_ZONE_CONFIGURATION_TAG;
+        req.num_tlv++;
+        req.emtc_config.prach_catm_high_speed_flag.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CATM_HIGH_SPEED_FLAG;
+        req.num_tlv++;
+        req.emtc_config.prach_ce_level_0_enable.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_0_ENABLE_TAG;
+        req.num_tlv++;
+        req.emtc_config.prach_ce_level_0_configuration_index.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_0_CONFIGURATION_INDEX_TAG;
+        req.num_tlv++;
+        req.emtc_config.prach_ce_level_0_frequency_offset.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_0_FREQUENCY_OFFSET_TAG;
+        req.num_tlv++;
+        req.emtc_config.prach_ce_level_0_number_of_repetitions_per_attempt.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_0_NUMBER_OF_REPETITIONS_PER_ATTEMPT_TAG;
+        req.num_tlv++;
+        req.emtc_config.prach_ce_level_0_starting_subframe_periodicity.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_0_STARTING_SUBFRAME_PERIODICITY_TAG;
+        req.num_tlv++;
+        req.emtc_config.prach_ce_level_0_hopping_enable.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_0_HOPPING_ENABLE_TAG;
+        req.num_tlv++;
+        req.emtc_config.prach_ce_level_0_hopping_offset.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_0_HOPPING_OFFSET_TAG;
+        req.num_tlv++;
+        req.emtc_config.prach_ce_level_1_enable.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_1_ENABLE_TAG;
+        req.num_tlv++;
+        req.emtc_config.prach_ce_level_1_configuration_index.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_1_CONFIGURATION_INDEX_TAG;
+        req.num_tlv++;
+        req.emtc_config.prach_ce_level_1_frequency_offset.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_1_FREQUENCY_OFFSET_TAG;
+        req.num_tlv++;
+        req.emtc_config.prach_ce_level_1_number_of_repetitions_per_attempt.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_1_NUMBER_OF_REPETITIONS_PER_ATTEMPT_TAG;
+        req.num_tlv++;
+        req.emtc_config.prach_ce_level_1_starting_subframe_periodicity.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_1_STARTING_SUBFRAME_PERIODICITY_TAG;
+        req.num_tlv++;
+        req.emtc_config.prach_ce_level_1_hopping_enable.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_1_HOPPING_ENABLE_TAG;
+        req.num_tlv++;
+        req.emtc_config.prach_ce_level_1_hopping_offset.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_1_HOPPING_OFFSET_TAG;
+        req.num_tlv++;
+        req.emtc_config.prach_ce_level_2_enable.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_2_ENABLE_TAG;
+        req.num_tlv++;
+        req.emtc_config.prach_ce_level_2_configuration_index.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_2_CONFIGURATION_INDEX_TAG;
+        req.num_tlv++;
+        req.emtc_config.prach_ce_level_2_frequency_offset.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_2_FREQUENCY_OFFSET_TAG;
+        req.num_tlv++;
+        req.emtc_config.prach_ce_level_2_number_of_repetitions_per_attempt.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_2_NUMBER_OF_REPETITIONS_PER_ATTEMPT_TAG;
+        req.num_tlv++;
+        req.emtc_config.prach_ce_level_2_starting_subframe_periodicity.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_2_STARTING_SUBFRAME_PERIODICITY_TAG;
+        req.num_tlv++;
+        req.emtc_config.prach_ce_level_2_hopping_enable.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_2_HOPPING_ENABLE_TAG;
+        req.num_tlv++;
+        req.emtc_config.prach_ce_level_2_hopping_offset.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_2_HOPPING_OFFSET_TAG;
+        req.num_tlv++;
+        req.emtc_config.prach_ce_level_3_enable.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_3_ENABLE_TAG;
+        req.num_tlv++;
+        req.emtc_config.prach_ce_level_3_configuration_index.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_3_CONFIGURATION_INDEX_TAG;
+        req.num_tlv++;
+        req.emtc_config.prach_ce_level_3_frequency_offset.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_3_FREQUENCY_OFFSET_TAG;
+        req.num_tlv++;
+        req.emtc_config.prach_ce_level_3_number_of_repetitions_per_attempt.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_3_NUMBER_OF_REPETITIONS_PER_ATTEMPT_TAG;
+        req.num_tlv++;
+        req.emtc_config.prach_ce_level_3_starting_subframe_periodicity.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_3_STARTING_SUBFRAME_PERIODICITY_TAG;
+        req.num_tlv++;
+        req.emtc_config.prach_ce_level_3_hopping_enable.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_3_HOPPING_ENABLE_TAG;
+        req.num_tlv++;
+        req.emtc_config.prach_ce_level_3_hopping_offset.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_3_HOPPING_OFFSET_TAG;
+        req.num_tlv++;
+        req.emtc_config.pucch_interval_ulhoppingconfigcommonmodea.tl.tag = NFAPI_EMTC_CONFIG_PUCCH_INTERVAL_ULHOPPINGCONFIGCOMMONMODEA_TAG;
+        req.num_tlv++;
+        req.emtc_config.pucch_interval_ulhoppingconfigcommonmodeb.tl.tag = NFAPI_EMTC_CONFIG_PUCCH_INTERVAL_ULHOPPINGCONFIGCOMMONMODEB_TAG;
+        req.num_tlv++;
+        req.nb_iot_config.operating_mode.tl.tag = NFAPI_NB_IOT_CONFIG_OPERATING_MODE_TAG;
+        req.nb_iot_config.operating_mode.value = rand_range(0, 3);
+        req.num_tlv++;
+        req.nb_iot_config.anchor.tl.tag = NFAPI_NB_IOT_CONFIG_ANCHOR_TAG;
+        req.nb_iot_config.anchor.value = rand_range(0, 1);
+        req.num_tlv++;
+        req.nb_iot_config.prb_index.tl.tag = NFAPI_NB_IOT_CONFIG_PRB_INDEX_TAG;
+        req.nb_iot_config.prb_index.value = rand_range(0, 0x1F);
+        req.num_tlv++;
+        req.nb_iot_config.control_region_size.tl.tag = NFAPI_NB_IOT_CONFIG_CONTROL_REGION_SIZE_TAG;
+        req.nb_iot_config.control_region_size.value = rand_range(1, 4);
+        req.num_tlv++;
+        req.nb_iot_config.assumed_crs_aps.tl.tag = NFAPI_NB_IOT_CONFIG_ASSUMED_CRS_APS_TAG;
+        req.nb_iot_config.assumed_crs_aps.value = rand_range(0, 1);
+        req.num_tlv++;
+        req.nb_iot_config.nprach_config_0_enabled.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_0_ENABLED_TAG;
+        req.nb_iot_config.nprach_config_0_enabled.value = rand_range(0, 1);
+        req.num_tlv++;
+        req.nb_iot_config.nprach_config_0_sf_periodicity.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_0_SF_PERIODICITY_TAG;
+        req.nb_iot_config.nprach_config_0_sf_periodicity.value = rand_range(0, 7);
+        req.num_tlv++;
+        req.nb_iot_config.nprach_config_0_start_time.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_0_START_TIME_TAG;
+        req.nb_iot_config.nprach_config_0_start_time.value = rand_range(0, 7);
+        req.num_tlv++;
+        req.nb_iot_config.nprach_config_0_subcarrier_offset.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_0_SUBCARRIER_OFFSET_TAG;
+        req.nb_iot_config.nprach_config_0_subcarrier_offset.value = rand_range(0, 6);
+        req.num_tlv++;
+        req.nb_iot_config.nprach_config_0_number_of_subcarriers.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_0_NUMBER_OF_SUBCARRIERS_TAG;
+        req.nb_iot_config.nprach_config_0_number_of_subcarriers.value = rand_range(0, 3);
+        req.num_tlv++;
+        req.nb_iot_config.nprach_config_0_cp_length.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_0_CP_LENGTH_TAG;
+        req.nb_iot_config.nprach_config_0_cp_length.value = rand_range(0, 1);
+        req.num_tlv++;
+        req.nb_iot_config.nprach_config_0_number_of_repetitions_per_attempt.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_0_NUMBER_OF_REPETITIONS_PER_ATTEMPT_TAG;
+        req.nb_iot_config.nprach_config_0_number_of_repetitions_per_attempt.value = rand_range(0, 7);
+        req.num_tlv++;
+        req.nb_iot_config.nprach_config_1_enabled.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_1_ENABLED_TAG;
+        req.nb_iot_config.nprach_config_1_enabled.value = rand_range(0, 1);
+        req.num_tlv++;
+        req.nb_iot_config.nprach_config_1_sf_periodicity.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_1_SF_PERIODICITY_TAG;
+        req.nb_iot_config.nprach_config_1_sf_periodicity.value = rand_range(0, 7);
+        req.num_tlv++;
+        req.nb_iot_config.nprach_config_1_start_time.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_1_START_TIME_TAG;
+        req.nb_iot_config.nprach_config_1_start_time.value = rand_range(0, 7);
+        req.num_tlv++;
+        req.nb_iot_config.nprach_config_1_subcarrier_offset.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_1_SUBCARRIER_OFFSET_TAG;
+        req.nb_iot_config.nprach_config_1_subcarrier_offset.value = rand_range(0, 6);
+        req.num_tlv++;
+        req.nb_iot_config.nprach_config_1_number_of_subcarriers.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_1_NUMBER_OF_SUBCARRIERS_TAG;
+        req.nb_iot_config.nprach_config_1_number_of_subcarriers.value = rand_range(0, 3);
+        req.num_tlv++;
+        req.nb_iot_config.nprach_config_1_cp_length.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_1_CP_LENGTH_TAG;
+        req.nb_iot_config.nprach_config_1_cp_length.value = rand_range(0, 1);
+        req.num_tlv++;
+        req.nb_iot_config.nprach_config_1_number_of_repetitions_per_attempt.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_1_NUMBER_OF_REPETITIONS_PER_ATTEMPT_TAG;
+        req.nb_iot_config.nprach_config_1_number_of_repetitions_per_attempt.value = rand_range(0, 7);
+        req.num_tlv++;
+        req.nb_iot_config.nprach_config_2_enabled.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_2_ENABLED_TAG;
+        req.nb_iot_config.nprach_config_2_enabled.value = rand_range(0, 1);
+        req.num_tlv++;
+        req.nb_iot_config.nprach_config_2_sf_periodicity.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_2_SF_PERIODICITY_TAG;
+        req.nb_iot_config.nprach_config_2_sf_periodicity.value = rand_range(0, 7);
+        req.num_tlv++;
+        req.nb_iot_config.nprach_config_2_start_time.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_2_START_TIME_TAG;
+        req.nb_iot_config.nprach_config_2_start_time.value = rand_range(0, 7);
+        req.num_tlv++;
+        req.nb_iot_config.nprach_config_2_subcarrier_offset.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_2_SUBCARRIER_OFFSET_TAG;
+        req.nb_iot_config.nprach_config_2_subcarrier_offset.value = rand_range(0, 6);
+        req.num_tlv++;
+        req.nb_iot_config.nprach_config_2_number_of_subcarriers.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_2_NUMBER_OF_SUBCARRIERS_TAG;
+        req.nb_iot_config.nprach_config_2_number_of_subcarriers.value = rand_range(0, 3);
+        req.num_tlv++;
+        req.nb_iot_config.nprach_config_2_cp_length.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_2_CP_LENGTH_TAG;
+        req.nb_iot_config.nprach_config_2_cp_length.value = rand_range(0, 1);
+        req.num_tlv++;
+        req.nb_iot_config.nprach_config_2_number_of_repetitions_per_attempt.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_2_NUMBER_OF_REPETITIONS_PER_ATTEMPT_TAG;
+        req.nb_iot_config.nprach_config_2_number_of_repetitions_per_attempt.value = rand_range(0, 7);
+        req.num_tlv++;
+        req.nb_iot_config.three_tone_base_sequence.tl.tag = NFAPI_NB_IOT_CONFIG_THREE_TONE_BASE_SEQUENCE_TAG;
+        req.nb_iot_config.three_tone_base_sequence.value = rand_range(0, 0x0F);
+        req.num_tlv++;
+        req.nb_iot_config.six_tone_base_sequence.tl.tag = NFAPI_NB_IOT_CONFIG_SIX_TONE_BASE_SEQUENCE_TAG;
+        req.nb_iot_config.six_tone_base_sequence.value = rand_range(0, 0x03);
+        req.num_tlv++;
+        req.nb_iot_config.twelve_tone_base_sequence.tl.tag = NFAPI_NB_IOT_CONFIG_TWELVE_TONE_BASE_SEQUENCE_TAG;
+        req.nb_iot_config.twelve_tone_base_sequence.value = rand_range(0, 0x1F);
+        req.num_tlv++;
+        req.nb_iot_config.three_tone_cyclic_shift.tl.tag = NFAPI_NB_IOT_CONFIG_THREE_TONE_CYCLIC_SHIFT_TAG;
+        req.nb_iot_config.three_tone_cyclic_shift.value = rand_range(0, 5); // what is the max
+        req.num_tlv++;
+        req.nb_iot_config.six_tone_cyclic_shift.tl.tag = NFAPI_NB_IOT_CONFIG_SIX_TONE_CYCLIC_SHIFT_TAG;
+        req.nb_iot_config.six_tone_cyclic_shift.value = rand_range(0, 5); // what is the max
+        req.num_tlv++;
+        req.nb_iot_config.dl_gap_config_enable.tl.tag = NFAPI_NB_IOT_CONFIG_DL_GAP_CONFIG_ENABLE_TAG;
+        req.nb_iot_config.dl_gap_config_enable.value = rand_range(0, 1);
+        req.num_tlv++;
+        req.nb_iot_config.dl_gap_threshold.tl.tag = NFAPI_NB_IOT_CONFIG_DL_GAP_THRESHOLD_TAG;
+        req.nb_iot_config.dl_gap_threshold.value = rand_range(0, 3);
+        req.num_tlv++;
+        req.nb_iot_config.dl_gap_periodicity.tl.tag = NFAPI_NB_IOT_CONFIG_DL_GAP_PERIODICITY_TAG;
+        req.nb_iot_config.dl_gap_periodicity.value = rand_range(0, 3);
+        req.num_tlv++;
+        req.nb_iot_config.dl_gap_duration_coefficient.tl.tag = NFAPI_NB_IOT_CONFIG_DL_GAP_DURATION_COEFFICIENT_TAG;
+        req.nb_iot_config.dl_gap_duration_coefficient.value = rand_range(0, 3);
+        req.num_tlv++;
+        req.tdd_frame_structure_config.subframe_assignment.tl.tag = NFAPI_TDD_FRAME_STRUCTURE_SUBFRAME_ASSIGNMENT_TAG;
+        req.num_tlv++;
+        req.tdd_frame_structure_config.special_subframe_patterns.tl.tag = NFAPI_TDD_FRAME_STRUCTURE_SPECIAL_SUBFRAME_PATTERNS_TAG;
+        req.num_tlv++;
+        req.l23_config.data_report_mode.tl.tag = NFAPI_L23_CONFIG_DATA_REPORT_MODE_TAG;
+        req.num_tlv++;
+        req.l23_config.sfnsf.tl.tag = NFAPI_L23_CONFIG_SFNSF_TAG;
+        req.num_tlv++;
+      }
+
+      vendor_ext_tlv_2 ve2;
+      memset(&ve2, 0, sizeof(ve2));
+      ve2.tl.tag = VENDOR_EXT_TLV_2_TAG;
+      ve2.dummy = 2016;
+      req.vendor_extension = &ve2.tl;
+      nfapi_vnf_config_req(config, p5_idx, &req);
+    } else {
+      printf("[VNF_SIM] param response failed to find pnf %d phy %d\n", p5_idx, resp->header.phy_id);
+    }
+  } else {
+    printf("[VNF_SIM] param response failed to find pnf %d\n", p5_idx);
+  }
 
-void test_p4_requests(nfapi_vnf_config_t* config, int p5_idx, int phy_id)
-{
-	{
-		nfapi_measurement_request_t req;
-		memset(&req, 0, sizeof(req));
-		req.header.message_id = NFAPI_MEASUREMENT_REQUEST;
-		req.header.phy_id = phy_id;
-		
-		req.dl_rs_tx_power.tl.tag = NFAPI_MEASUREMENT_REQUEST_DL_RS_XTX_POWER_TAG;
-		req.dl_rs_tx_power.value = 42;
-		req.received_interference_power.tl.tag = NFAPI_MEASUREMENT_REQUEST_RECEIVED_INTERFERENCE_POWER_TAG;
-		req.received_interference_power.value = 42;
-		req.thermal_noise_power.tl.tag = NFAPI_MEASUREMENT_REQUEST_THERMAL_NOISE_POWER_TAG;
-		req.thermal_noise_power.value = 42;
-		
-		nfapi_vnf_measurement_req(config, p5_idx, &req);
-	}
-	{
-		nfapi_rssi_request_t lte_req;
-		memset(&lte_req, 0, sizeof(lte_req));
-		lte_req.header.message_id = NFAPI_RSSI_REQUEST;
-		lte_req.header.phy_id = phy_id;
-		
-		lte_req.rat_type = NFAPI_RAT_TYPE_LTE;
-		lte_req.lte_rssi_request.tl.tag = NFAPI_LTE_RSSI_REQUEST_TAG;
-		lte_req.lte_rssi_request.frequency_band_indicator = 2;
-		lte_req.lte_rssi_request.measurement_period = 1000;
-		lte_req.lte_rssi_request.bandwidth = 50;
-		lte_req.lte_rssi_request.timeout = 0;
-		lte_req.lte_rssi_request.number_of_earfcns = 2;
-		lte_req.lte_rssi_request.earfcn[0] = 389;
-		lte_req.lte_rssi_request.earfcn[1] = 123;
-		
-		nfapi_vnf_rssi_request(config, p5_idx, &lte_req);
-		
-		nfapi_rssi_request_t utran_req;
-		memset(&utran_req, 0, sizeof(utran_req));
-		utran_req.header.message_id = NFAPI_RSSI_REQUEST;
-		utran_req.header.phy_id = phy_id;
-		
-		utran_req.rat_type = NFAPI_RAT_TYPE_UTRAN;
-		utran_req.utran_rssi_request.tl.tag = NFAPI_UTRAN_RSSI_REQUEST_TAG;
-		utran_req.utran_rssi_request.frequency_band_indicator = 2;
-		utran_req.utran_rssi_request.measurement_period = 1000;
-		utran_req.utran_rssi_request.timeout = 0;
-		utran_req.utran_rssi_request.number_of_uarfcns = 2;
-		utran_req.utran_rssi_request.uarfcn[0] = 2348;
-		utran_req.utran_rssi_request.uarfcn[1] = 52;
-		
-		nfapi_vnf_rssi_request(config, p5_idx, &utran_req);		
-		
-		
-		nfapi_rssi_request_t geran_req;
-		memset(&geran_req, 0, sizeof(geran_req));
-		geran_req.header.message_id = NFAPI_RSSI_REQUEST;
-		geran_req.header.phy_id = phy_id;
-		
-		geran_req.rat_type = NFAPI_RAT_TYPE_GERAN;
-		geran_req.geran_rssi_request.tl.tag = NFAPI_GERAN_RSSI_REQUEST_TAG;
-		geran_req.geran_rssi_request.frequency_band_indicator = 2;
-		geran_req.geran_rssi_request.measurement_period = 1000;
-		geran_req.geran_rssi_request.timeout = 0;
-		geran_req.geran_rssi_request.number_of_arfcns = 1;
-		geran_req.geran_rssi_request.arfcn[0].arfcn = 34;
-		geran_req.geran_rssi_request.arfcn[0].direction = 0;
-		
-		nfapi_vnf_rssi_request(config, p5_idx, &geran_req);		
-	}
-	{
-		nfapi_cell_search_request_t lte_req;
-		memset(&lte_req, 0, sizeof(lte_req));
-		lte_req.header.message_id = NFAPI_CELL_SEARCH_REQUEST;
-		lte_req.header.phy_id = phy_id;		
-		
-		lte_req.rat_type = NFAPI_RAT_TYPE_LTE;
-		lte_req.lte_cell_search_request.tl.tag = NFAPI_LTE_CELL_SEARCH_REQUEST_TAG;
-		lte_req.lte_cell_search_request.earfcn = 1234;
-		lte_req.lte_cell_search_request.measurement_bandwidth = 50;
-		lte_req.lte_cell_search_request.exhaustive_search = 1;
-		lte_req.lte_cell_search_request.timeout = 1000;
-		lte_req.lte_cell_search_request.number_of_pci = 1;
-		lte_req.lte_cell_search_request.pci[0] = 234;
-		
-		nfapi_vnf_cell_search_request(config, p5_idx, &lte_req);
-		
-		nfapi_cell_search_request_t utran_req;
-		memset(&utran_req, 0, sizeof(utran_req));
-		utran_req.header.message_id = NFAPI_CELL_SEARCH_REQUEST;
-		utran_req.header.phy_id = phy_id;		
-		
-		utran_req.rat_type = NFAPI_RAT_TYPE_UTRAN;
-		utran_req.utran_cell_search_request.tl.tag = NFAPI_UTRAN_CELL_SEARCH_REQUEST_TAG;
-		utran_req.utran_cell_search_request.uarfcn = 1234;
-		utran_req.utran_cell_search_request.exhaustive_search = 0;
-		utran_req.utran_cell_search_request.timeout = 1000;
-		utran_req.utran_cell_search_request.number_of_psc = 1;
-		utran_req.utran_cell_search_request.psc[0] = 234;
-		
-		nfapi_vnf_cell_search_request(config, p5_idx, &utran_req);		
-		
-		nfapi_cell_search_request_t geran_req;
-		memset(&geran_req, 0, sizeof(geran_req));
-		geran_req.header.message_id = NFAPI_CELL_SEARCH_REQUEST;
-		geran_req.header.phy_id = phy_id;		
-		
-		geran_req.rat_type = NFAPI_RAT_TYPE_GERAN;
-		geran_req.geran_cell_search_request.tl.tag = NFAPI_GERAN_CELL_SEARCH_REQUEST_TAG;
-		geran_req.geran_cell_search_request.timeout = 1000;
-		geran_req.geran_cell_search_request.number_of_arfcn = 1;
-		geran_req.geran_cell_search_request.arfcn[0] = 8765;
-		
-		nfapi_vnf_cell_search_request(config, p5_idx, &geran_req);				
-	}
-	{
-		nfapi_broadcast_detect_request_t lte_req;
-		memset(&lte_req, 0, sizeof(lte_req));
-		lte_req.header.message_id = NFAPI_BROADCAST_DETECT_REQUEST;
-		lte_req.header.phy_id = phy_id;		
-		
-		lte_req.rat_type = NFAPI_RAT_TYPE_LTE;
-		lte_req.lte_broadcast_detect_request.tl.tag = NFAPI_LTE_BROADCAST_DETECT_REQUEST_TAG;
-		lte_req.lte_broadcast_detect_request.earfcn = 1234;
-		lte_req.lte_broadcast_detect_request.pci = 50;
-		lte_req.lte_broadcast_detect_request.timeout = 1000;
-		
-		lte_req.pnf_cell_search_state.tl.tag = NFAPI_PNF_CELL_SEARCH_STATE_TAG;
-		lte_req.pnf_cell_search_state.length = 3;
-		
-		nfapi_vnf_broadcast_detect_request(config, p5_idx, &lte_req);
-		
-		nfapi_broadcast_detect_request_t utran_req;
-		memset(&utran_req, 0, sizeof(utran_req));
-		utran_req.header.message_id = NFAPI_BROADCAST_DETECT_REQUEST;
-		utran_req.header.phy_id = phy_id;		
-		
-		utran_req.rat_type = NFAPI_RAT_TYPE_LTE;
-		utran_req.utran_broadcast_detect_request.tl.tag = NFAPI_UTRAN_BROADCAST_DETECT_REQUEST_TAG;
-		utran_req.utran_broadcast_detect_request.uarfcn = 1234;
-		utran_req.utran_broadcast_detect_request.psc = 50;
-		utran_req.utran_broadcast_detect_request.timeout = 1000;
-		
-		utran_req.pnf_cell_search_state.tl.tag = NFAPI_PNF_CELL_SEARCH_STATE_TAG;
-		utran_req.pnf_cell_search_state.length = 3;
-		
-		nfapi_vnf_broadcast_detect_request(config, p5_idx, &utran_req);		
-	}
-	{
-		nfapi_system_information_schedule_request_t lte_req;
-		memset(&lte_req, 0, sizeof(lte_req));
-		lte_req.header.message_id = NFAPI_SYSTEM_INFORMATION_SCHEDULE_REQUEST;
-		lte_req.header.phy_id = phy_id;		
-		
-		lte_req.rat_type = NFAPI_RAT_TYPE_LTE;
-		lte_req.lte_system_information_schedule_request.tl.tag = NFAPI_LTE_SYSTEM_INFORMATION_SCHEDULE_REQUEST_TAG;
-		lte_req.lte_system_information_schedule_request.earfcn = 1234;
-		lte_req.lte_system_information_schedule_request.pci = 50;
-		lte_req.lte_system_information_schedule_request.downlink_channel_bandwidth = 100;
-		lte_req.lte_system_information_schedule_request.phich_configuration = 3;
-		lte_req.lte_system_information_schedule_request.number_of_tx_antenna = 2;
-		lte_req.lte_system_information_schedule_request.retry_count = 4;
-		lte_req.lte_system_information_schedule_request.timeout = 1000;
-		
-		lte_req.pnf_cell_broadcast_state.tl.tag = NFAPI_PNF_CELL_BROADCAST_STATE_TAG;
-		lte_req.pnf_cell_broadcast_state.length = 3;
-		
-		nfapi_vnf_system_information_schedule_request(config, p5_idx, &lte_req);
-	}
-	{
-		nfapi_system_information_request_t lte_req;
-		memset(&lte_req, 0, sizeof(lte_req));
-		lte_req.header.message_id = NFAPI_SYSTEM_INFORMATION_REQUEST;
-		lte_req.header.phy_id = phy_id;		
-		
-		lte_req.rat_type = NFAPI_RAT_TYPE_LTE;		
-		lte_req.lte_system_information_request.tl.tag = NFAPI_LTE_SYSTEM_INFORMATION_REQUEST_TAG;
-		lte_req.lte_system_information_request.earfcn = 1234;
-		lte_req.lte_system_information_request.pci= 456;
-		lte_req.lte_system_information_request.downlink_channel_bandwidth = 5;
-		lte_req.lte_system_information_request.phich_configuration = 2;
-		lte_req.lte_system_information_request.number_of_tx_antenna = 2;
-		lte_req.lte_system_information_request.number_of_si_periodicity = 1;
-		lte_req.lte_system_information_request.si_periodicity[0].si_periodicity = 3;
-		lte_req.lte_system_information_request.si_periodicity[0].si_index = 3;
-		lte_req.lte_system_information_request.si_window_length = 15;
-		lte_req.lte_system_information_request.timeout = 1000;
-		
-		nfapi_vnf_system_information_request(config, p5_idx, &lte_req);
-		
-		nfapi_system_information_request_t utran_req;
-		memset(&utran_req, 0, sizeof(utran_req));
-		utran_req.header.message_id = NFAPI_SYSTEM_INFORMATION_REQUEST;
-		utran_req.header.phy_id = phy_id;		
-		
-		utran_req.rat_type = NFAPI_RAT_TYPE_UTRAN;
-		utran_req.utran_system_information_request.tl.tag = NFAPI_UTRAN_SYSTEM_INFORMATION_REQUEST_TAG;
-		utran_req.utran_system_information_request.uarfcn = 1234;
-		utran_req.utran_system_information_request.psc = 456;
-		utran_req.utran_system_information_request.timeout = 1000;
-		
-		nfapi_vnf_system_information_request(config, p5_idx, &utran_req);		
-		
-		nfapi_system_information_request_t geran_req;
-		memset(&geran_req, 0, sizeof(geran_req));
-		geran_req.header.message_id = NFAPI_SYSTEM_INFORMATION_REQUEST;
-		geran_req.header.phy_id = phy_id;		
-		
-		geran_req.rat_type = NFAPI_RAT_TYPE_GERAN;
-		geran_req.geran_system_information_request.tl.tag = NFAPI_GERAN_SYSTEM_INFORMATION_REQUEST_TAG;
-		geran_req.geran_system_information_request.arfcn = 1234;
-		geran_req.geran_system_information_request.bsic = 21;
-		geran_req.geran_system_information_request.timeout = 1000;
-		
-		nfapi_vnf_system_information_request(config, p5_idx, &geran_req);	
-	}
-	{
-		nfapi_nmm_stop_request_t req;
-		memset(&req, 0, sizeof(req));
-		req.header.message_id = NFAPI_NMM_STOP_REQUEST;
-		req.header.phy_id = phy_id;		
-		nfapi_vnf_nmm_stop_request(config, p5_idx, &req);	
-	}
+  return 0;
 }
 
+int config_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_config_response_t *resp) {
+  printf("[VNF_SIM] config response idx:%d phy_id:%d\n", p5_idx, resp->header.phy_id);
+  nfapi_start_request_t req;
+  memset(&req, 0, sizeof(req));
+  req.header.message_id = NFAPI_START_REQUEST;
+  req.header.phy_id = resp->header.phy_id;
+  nfapi_vnf_start_req(config, p5_idx, &req);
+  return 0;
+}
 
-int start_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_start_response_t* resp)
-{
-	printf("[VNF_SIM] start response idx:%d phy_id:%d\n", p5_idx, resp->header.phy_id);
-
-	vnf_info* vnf = (vnf_info*)(config->user_data);
-	
-	if(vnf->wireshark_test_mode)
-		test_p4_requests(config, p5_idx,  resp->header.phy_id);
+void test_p4_requests(nfapi_vnf_config_t *config, int p5_idx, int phy_id) {
+  {
+    nfapi_measurement_request_t req;
+    memset(&req, 0, sizeof(req));
+    req.header.message_id = NFAPI_MEASUREMENT_REQUEST;
+    req.header.phy_id = phy_id;
+    req.dl_rs_tx_power.tl.tag = NFAPI_MEASUREMENT_REQUEST_DL_RS_XTX_POWER_TAG;
+    req.dl_rs_tx_power.value = 42;
+    req.received_interference_power.tl.tag = NFAPI_MEASUREMENT_REQUEST_RECEIVED_INTERFERENCE_POWER_TAG;
+    req.received_interference_power.value = 42;
+    req.thermal_noise_power.tl.tag = NFAPI_MEASUREMENT_REQUEST_THERMAL_NOISE_POWER_TAG;
+    req.thermal_noise_power.value = 42;
+    nfapi_vnf_measurement_req(config, p5_idx, &req);
+  }
+  {
+    nfapi_rssi_request_t lte_req;
+    memset(&lte_req, 0, sizeof(lte_req));
+    lte_req.header.message_id = NFAPI_RSSI_REQUEST;
+    lte_req.header.phy_id = phy_id;
+    lte_req.rat_type = NFAPI_RAT_TYPE_LTE;
+    lte_req.lte_rssi_request.tl.tag = NFAPI_LTE_RSSI_REQUEST_TAG;
+    lte_req.lte_rssi_request.frequency_band_indicator = 2;
+    lte_req.lte_rssi_request.measurement_period = 1000;
+    lte_req.lte_rssi_request.bandwidth = 50;
+    lte_req.lte_rssi_request.timeout = 0;
+    lte_req.lte_rssi_request.number_of_earfcns = 2;
+    lte_req.lte_rssi_request.earfcn[0] = 389;
+    lte_req.lte_rssi_request.earfcn[1] = 123;
+    nfapi_vnf_rssi_request(config, p5_idx, &lte_req);
+    nfapi_rssi_request_t utran_req;
+    memset(&utran_req, 0, sizeof(utran_req));
+    utran_req.header.message_id = NFAPI_RSSI_REQUEST;
+    utran_req.header.phy_id = phy_id;
+    utran_req.rat_type = NFAPI_RAT_TYPE_UTRAN;
+    utran_req.utran_rssi_request.tl.tag = NFAPI_UTRAN_RSSI_REQUEST_TAG;
+    utran_req.utran_rssi_request.frequency_band_indicator = 2;
+    utran_req.utran_rssi_request.measurement_period = 1000;
+    utran_req.utran_rssi_request.timeout = 0;
+    utran_req.utran_rssi_request.number_of_uarfcns = 2;
+    utran_req.utran_rssi_request.uarfcn[0] = 2348;
+    utran_req.utran_rssi_request.uarfcn[1] = 52;
+    nfapi_vnf_rssi_request(config, p5_idx, &utran_req);
+    nfapi_rssi_request_t geran_req;
+    memset(&geran_req, 0, sizeof(geran_req));
+    geran_req.header.message_id = NFAPI_RSSI_REQUEST;
+    geran_req.header.phy_id = phy_id;
+    geran_req.rat_type = NFAPI_RAT_TYPE_GERAN;
+    geran_req.geran_rssi_request.tl.tag = NFAPI_GERAN_RSSI_REQUEST_TAG;
+    geran_req.geran_rssi_request.frequency_band_indicator = 2;
+    geran_req.geran_rssi_request.measurement_period = 1000;
+    geran_req.geran_rssi_request.timeout = 0;
+    geran_req.geran_rssi_request.number_of_arfcns = 1;
+    geran_req.geran_rssi_request.arfcn[0].arfcn = 34;
+    geran_req.geran_rssi_request.arfcn[0].direction = 0;
+    nfapi_vnf_rssi_request(config, p5_idx, &geran_req);
+  }
+  {
+    nfapi_cell_search_request_t lte_req;
+    memset(&lte_req, 0, sizeof(lte_req));
+    lte_req.header.message_id = NFAPI_CELL_SEARCH_REQUEST;
+    lte_req.header.phy_id = phy_id;
+    lte_req.rat_type = NFAPI_RAT_TYPE_LTE;
+    lte_req.lte_cell_search_request.tl.tag = NFAPI_LTE_CELL_SEARCH_REQUEST_TAG;
+    lte_req.lte_cell_search_request.earfcn = 1234;
+    lte_req.lte_cell_search_request.measurement_bandwidth = 50;
+    lte_req.lte_cell_search_request.exhaustive_search = 1;
+    lte_req.lte_cell_search_request.timeout = 1000;
+    lte_req.lte_cell_search_request.number_of_pci = 1;
+    lte_req.lte_cell_search_request.pci[0] = 234;
+    nfapi_vnf_cell_search_request(config, p5_idx, &lte_req);
+    nfapi_cell_search_request_t utran_req;
+    memset(&utran_req, 0, sizeof(utran_req));
+    utran_req.header.message_id = NFAPI_CELL_SEARCH_REQUEST;
+    utran_req.header.phy_id = phy_id;
+    utran_req.rat_type = NFAPI_RAT_TYPE_UTRAN;
+    utran_req.utran_cell_search_request.tl.tag = NFAPI_UTRAN_CELL_SEARCH_REQUEST_TAG;
+    utran_req.utran_cell_search_request.uarfcn = 1234;
+    utran_req.utran_cell_search_request.exhaustive_search = 0;
+    utran_req.utran_cell_search_request.timeout = 1000;
+    utran_req.utran_cell_search_request.number_of_psc = 1;
+    utran_req.utran_cell_search_request.psc[0] = 234;
+    nfapi_vnf_cell_search_request(config, p5_idx, &utran_req);
+    nfapi_cell_search_request_t geran_req;
+    memset(&geran_req, 0, sizeof(geran_req));
+    geran_req.header.message_id = NFAPI_CELL_SEARCH_REQUEST;
+    geran_req.header.phy_id = phy_id;
+    geran_req.rat_type = NFAPI_RAT_TYPE_GERAN;
+    geran_req.geran_cell_search_request.tl.tag = NFAPI_GERAN_CELL_SEARCH_REQUEST_TAG;
+    geran_req.geran_cell_search_request.timeout = 1000;
+    geran_req.geran_cell_search_request.number_of_arfcn = 1;
+    geran_req.geran_cell_search_request.arfcn[0] = 8765;
+    nfapi_vnf_cell_search_request(config, p5_idx, &geran_req);
+  }
+  {
+    nfapi_broadcast_detect_request_t lte_req;
+    memset(&lte_req, 0, sizeof(lte_req));
+    lte_req.header.message_id = NFAPI_BROADCAST_DETECT_REQUEST;
+    lte_req.header.phy_id = phy_id;
+    lte_req.rat_type = NFAPI_RAT_TYPE_LTE;
+    lte_req.lte_broadcast_detect_request.tl.tag = NFAPI_LTE_BROADCAST_DETECT_REQUEST_TAG;
+    lte_req.lte_broadcast_detect_request.earfcn = 1234;
+    lte_req.lte_broadcast_detect_request.pci = 50;
+    lte_req.lte_broadcast_detect_request.timeout = 1000;
+    lte_req.pnf_cell_search_state.tl.tag = NFAPI_PNF_CELL_SEARCH_STATE_TAG;
+    lte_req.pnf_cell_search_state.length = 3;
+    nfapi_vnf_broadcast_detect_request(config, p5_idx, &lte_req);
+    nfapi_broadcast_detect_request_t utran_req;
+    memset(&utran_req, 0, sizeof(utran_req));
+    utran_req.header.message_id = NFAPI_BROADCAST_DETECT_REQUEST;
+    utran_req.header.phy_id = phy_id;
+    utran_req.rat_type = NFAPI_RAT_TYPE_LTE;
+    utran_req.utran_broadcast_detect_request.tl.tag = NFAPI_UTRAN_BROADCAST_DETECT_REQUEST_TAG;
+    utran_req.utran_broadcast_detect_request.uarfcn = 1234;
+    utran_req.utran_broadcast_detect_request.psc = 50;
+    utran_req.utran_broadcast_detect_request.timeout = 1000;
+    utran_req.pnf_cell_search_state.tl.tag = NFAPI_PNF_CELL_SEARCH_STATE_TAG;
+    utran_req.pnf_cell_search_state.length = 3;
+    nfapi_vnf_broadcast_detect_request(config, p5_idx, &utran_req);
+  }
+  {
+    nfapi_system_information_schedule_request_t lte_req;
+    memset(&lte_req, 0, sizeof(lte_req));
+    lte_req.header.message_id = NFAPI_SYSTEM_INFORMATION_SCHEDULE_REQUEST;
+    lte_req.header.phy_id = phy_id;
+    lte_req.rat_type = NFAPI_RAT_TYPE_LTE;
+    lte_req.lte_system_information_schedule_request.tl.tag = NFAPI_LTE_SYSTEM_INFORMATION_SCHEDULE_REQUEST_TAG;
+    lte_req.lte_system_information_schedule_request.earfcn = 1234;
+    lte_req.lte_system_information_schedule_request.pci = 50;
+    lte_req.lte_system_information_schedule_request.downlink_channel_bandwidth = 100;
+    lte_req.lte_system_information_schedule_request.phich_configuration = 3;
+    lte_req.lte_system_information_schedule_request.number_of_tx_antenna = 2;
+    lte_req.lte_system_information_schedule_request.retry_count = 4;
+    lte_req.lte_system_information_schedule_request.timeout = 1000;
+    lte_req.pnf_cell_broadcast_state.tl.tag = NFAPI_PNF_CELL_BROADCAST_STATE_TAG;
+    lte_req.pnf_cell_broadcast_state.length = 3;
+    nfapi_vnf_system_information_schedule_request(config, p5_idx, &lte_req);
+  }
+  {
+    nfapi_system_information_request_t lte_req;
+    memset(&lte_req, 0, sizeof(lte_req));
+    lte_req.header.message_id = NFAPI_SYSTEM_INFORMATION_REQUEST;
+    lte_req.header.phy_id = phy_id;
+    lte_req.rat_type = NFAPI_RAT_TYPE_LTE;
+    lte_req.lte_system_information_request.tl.tag = NFAPI_LTE_SYSTEM_INFORMATION_REQUEST_TAG;
+    lte_req.lte_system_information_request.earfcn = 1234;
+    lte_req.lte_system_information_request.pci= 456;
+    lte_req.lte_system_information_request.downlink_channel_bandwidth = 5;
+    lte_req.lte_system_information_request.phich_configuration = 2;
+    lte_req.lte_system_information_request.number_of_tx_antenna = 2;
+    lte_req.lte_system_information_request.number_of_si_periodicity = 1;
+    lte_req.lte_system_information_request.si_periodicity[0].si_periodicity = 3;
+    lte_req.lte_system_information_request.si_periodicity[0].si_index = 3;
+    lte_req.lte_system_information_request.si_window_length = 15;
+    lte_req.lte_system_information_request.timeout = 1000;
+    nfapi_vnf_system_information_request(config, p5_idx, &lte_req);
+    nfapi_system_information_request_t utran_req;
+    memset(&utran_req, 0, sizeof(utran_req));
+    utran_req.header.message_id = NFAPI_SYSTEM_INFORMATION_REQUEST;
+    utran_req.header.phy_id = phy_id;
+    utran_req.rat_type = NFAPI_RAT_TYPE_UTRAN;
+    utran_req.utran_system_information_request.tl.tag = NFAPI_UTRAN_SYSTEM_INFORMATION_REQUEST_TAG;
+    utran_req.utran_system_information_request.uarfcn = 1234;
+    utran_req.utran_system_information_request.psc = 456;
+    utran_req.utran_system_information_request.timeout = 1000;
+    nfapi_vnf_system_information_request(config, p5_idx, &utran_req);
+    nfapi_system_information_request_t geran_req;
+    memset(&geran_req, 0, sizeof(geran_req));
+    geran_req.header.message_id = NFAPI_SYSTEM_INFORMATION_REQUEST;
+    geran_req.header.phy_id = phy_id;
+    geran_req.rat_type = NFAPI_RAT_TYPE_GERAN;
+    geran_req.geran_system_information_request.tl.tag = NFAPI_GERAN_SYSTEM_INFORMATION_REQUEST_TAG;
+    geran_req.geran_system_information_request.arfcn = 1234;
+    geran_req.geran_system_information_request.bsic = 21;
+    geran_req.geran_system_information_request.timeout = 1000;
+    nfapi_vnf_system_information_request(config, p5_idx, &geran_req);
+  }
+  {
+    nfapi_nmm_stop_request_t req;
+    memset(&req, 0, sizeof(req));
+    req.header.message_id = NFAPI_NMM_STOP_REQUEST;
+    req.header.phy_id = phy_id;
+    nfapi_vnf_nmm_stop_request(config, p5_idx, &req);
+  }
+}
 
-	auto find_result = vnf->pnfs.find(p5_idx);
-	if(find_result != vnf->pnfs.end())
-	{
-		pnf_info& pnf = find_result->second;
-		
-		
-		auto found = std::find_if(pnf.phys.begin(), pnf.phys.end(), [&](phy_info& item)
-								  { return item.id == resp->header.phy_id; });
 
-		if(found != pnf.phys.end())
-		{
-			phy_info& phy = (*found);
+int start_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_start_response_t *resp) {
+  printf("[VNF_SIM] start response idx:%d phy_id:%d\n", p5_idx, resp->header.phy_id);
+  vnf_info *vnf = (vnf_info *)(config->user_data);
 
-			vnf_p7_info& p7_vnf = vnf->p7_vnfs[0];
+  if(vnf->wireshark_test_mode)
+    test_p4_requests(config, p5_idx,  resp->header.phy_id);
 
-			nfapi_vnf_p7_add_pnf((p7_vnf.config.get()), phy.remote_addr.c_str(), phy.remote_port, phy.id);
-			
+  auto find_result = vnf->pnfs.find(p5_idx);
 
-		}
+  if(find_result != vnf->pnfs.end()) {
+    pnf_info &pnf = find_result->second;
+    auto found = std::find_if(pnf.phys.begin(), pnf.phys.end(), [&](phy_info& item) {
+      return item.id == resp->header.phy_id;
+    });
 
+    if(found != pnf.phys.end()) {
+      phy_info &phy = (*found);
+      vnf_p7_info &p7_vnf = vnf->p7_vnfs[0];
+      nfapi_vnf_p7_add_pnf((p7_vnf.config.get()), phy.remote_addr.c_str(), phy.remote_port, phy.id);
+    }
+  }
 
-	}
-	return 0;
+  return 0;
 }
 
 
-nfapi_p4_p5_message_header_t* vnf_sim_allocate_p4_p5_vendor_ext(uint16_t message_id, uint16_t* msg_size)
-{
-	if(message_id == P5_VENDOR_EXT_RSP)
-	{
-		*msg_size = sizeof(vendor_ext_p5_rsp);
-		return (nfapi_p4_p5_message_header_t*)malloc(sizeof(vendor_ext_p5_rsp));
-	}
-	return 0;
+nfapi_p4_p5_message_header_t *vnf_sim_allocate_p4_p5_vendor_ext(uint16_t message_id, uint16_t *msg_size) {
+  if(message_id == P5_VENDOR_EXT_RSP) {
+    *msg_size = sizeof(vendor_ext_p5_rsp);
+    return (nfapi_p4_p5_message_header_t *)malloc(sizeof(vendor_ext_p5_rsp));
+  }
+
+  return 0;
 }
-void vnf_sim_deallocate_p4_p5_vendor_ext(nfapi_p4_p5_message_header_t* header)
-{
-	free(header);
+void vnf_sim_deallocate_p4_p5_vendor_ext(nfapi_p4_p5_message_header_t *header) {
+  free(header);
 }
-int vendor_ext_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_p4_p5_message_header_t* msg)
-{
-	printf("[VNF_SIM] %s\n", __FUNCTION__);
-
-	switch(msg->message_id)
-	{
-		case P5_VENDOR_EXT_RSP:
-			{
-				vendor_ext_p5_rsp* rsp = (vendor_ext_p5_rsp*)msg;
-				printf("[VNF_SIM] P5_VENDOR_EXT_RSP error_code:%d\n", rsp->error_code);
-
-				// send the start request
-	
-				nfapi_pnf_start_request_t req;
-				memset(&req, 0, sizeof(req));
-				req.header.message_id = NFAPI_PNF_START_REQUEST;
-				nfapi_vnf_pnf_start_req(config, p5_idx, &req);
-			}
-			break;
-
-	}
+int vendor_ext_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_p4_p5_message_header_t *msg) {
+  printf("[VNF_SIM] %s\n", __FUNCTION__);
+
+  switch(msg->message_id) {
+    case P5_VENDOR_EXT_RSP: {
+      vendor_ext_p5_rsp *rsp = (vendor_ext_p5_rsp *)msg;
+      printf("[VNF_SIM] P5_VENDOR_EXT_RSP error_code:%d\n", rsp->error_code);
+      // send the start request
+      nfapi_pnf_start_request_t req;
+      memset(&req, 0, sizeof(req));
+      req.header.message_id = NFAPI_PNF_START_REQUEST;
+      nfapi_vnf_pnf_start_req(config, p5_idx, &req);
+    }
+    break;
+  }
 
-	return 0;
+  return 0;
 }
 
-int read_vnf_xml(vnf_info& vnf, const char* xml_file)
-{
-	try
-	{
-		
-		std::ifstream input(xml_file);
-	
-		using boost::property_tree::ptree;
-		ptree pt;
-	
-		read_xml(input, pt);
-		
-		
-	
-		for(const auto& v : pt.get_child("vnf.vnf_p7_list"))
-		{
-			if(v.first == "vnf_p7")
-			{
-				vnf_p7_info vnf_p7;
-				vnf_p7.local_port = v.second.get<unsigned>("port");
-				vnf_p7.local_addr = v.second.get<std::string>("address");
-	
-				vnf_p7.timing_window = v.second.get<unsigned>("timing_window");
-				vnf_p7.periodic_timing_enabled = v.second.get<unsigned>("periodic_timing_enabled");
-				vnf_p7.aperiodic_timing_enabled = v.second.get<unsigned>("aperiodic_timing_enabled");
-				vnf_p7.periodic_timing_period = v.second.get<unsigned>("periodic_timing_window");
-	
-				
-				boost::optional<const boost::property_tree::ptree&> d = v.second.get_child_optional("data.udp");
-				if(d.is_initialized())
-				{
-					vnf_p7.udp.enabled = true;
-					vnf_p7.udp.rx_port = d.get().get<unsigned>("rx_port");
-					vnf_p7.udp.tx_port = d.get().get<unsigned>("tx_port");
-					vnf_p7.udp.tx_addr = d.get().get<std::string>("tx_addr");
-				}
-				else
-				{
-					vnf_p7.udp.enabled = false;
-				}
-				
-				vnf.wireshark_test_mode = v.second.get<unsigned>("wireshark_test_mode", 0);
-	
-				vnf_p7.mac = mac_create(vnf.wireshark_test_mode);
-				vnf_p7.mac->dl_config_req = &mac_dl_config_req;
-				vnf_p7.mac->ul_config_req = &mac_ul_config_req;
-				vnf_p7.mac->hi_dci0_req = &mac_hi_dci0_req;
-				vnf_p7.mac->tx_req = &mac_tx_req;
-	
-				if(vnf_p7.udp.enabled)
-				{
-					mac_start_data(vnf_p7.mac, 
-								   vnf_p7.udp.rx_port, 
-								   vnf_p7.udp.tx_addr.c_str(), 
-								   vnf_p7.udp.tx_port);
-				}
-	
-				vnf.p7_vnfs.push_back(vnf_p7);
-			}
-		}
-	}
-	catch(std::exception& e)
-	{
-		printf("%s", e.what());
-		return -1;
-	}
-	catch(boost::exception& e)
-	{
-		printf("%s", boost::diagnostic_information(e).c_str());
-	}
-
-	struct ifaddrs *ifaddr;
-	getifaddrs(&ifaddr);
-
-
-	while(ifaddr)
-	{
-		int family = ifaddr->ifa_addr->sa_family;
-		if(family == AF_INET)
-		{
-			char host[128];
-			getnameinfo(ifaddr->ifa_addr, sizeof(sockaddr_in), host, sizeof(host),	NULL, 0, 0);
-			printf("%s\n", host);
-		}
-		ifaddr = ifaddr->ifa_next;
-	}
-	
-	return 0;
+int read_vnf_xml(vnf_info &vnf, const char *xml_file) {
+  try {
+    std::ifstream input(xml_file);
+    using boost::property_tree::ptree;
+    ptree pt;
+    read_xml(input, pt);
+
+    for(const auto &v : pt.get_child("vnf.vnf_p7_list")) {
+      if(v.first == "vnf_p7") {
+        vnf_p7_info vnf_p7;
+        vnf_p7.local_port = v.second.get<unsigned>("port");
+        vnf_p7.local_addr = v.second.get<std::string>("address");
+        vnf_p7.timing_window = v.second.get<unsigned>("timing_window");
+        vnf_p7.periodic_timing_enabled = v.second.get<unsigned>("periodic_timing_enabled");
+        vnf_p7.aperiodic_timing_enabled = v.second.get<unsigned>("aperiodic_timing_enabled");
+        vnf_p7.periodic_timing_period = v.second.get<unsigned>("periodic_timing_window");
+        boost::optional<const boost::property_tree::ptree &> d = v.second.get_child_optional("data.udp");
+
+        if(d.is_initialized()) {
+          vnf_p7.udp.enabled = true;
+          vnf_p7.udp.rx_port = d.get().get<unsigned>("rx_port");
+          vnf_p7.udp.tx_port = d.get().get<unsigned>("tx_port");
+          vnf_p7.udp.tx_addr = d.get().get<std::string>("tx_addr");
+        } else {
+          vnf_p7.udp.enabled = false;
+        }
+
+        vnf.wireshark_test_mode = v.second.get<unsigned>("wireshark_test_mode", 0);
+        vnf_p7.mac = mac_create(vnf.wireshark_test_mode);
+        vnf_p7.mac->dl_config_req = &mac_dl_config_req;
+        vnf_p7.mac->ul_config_req = &mac_ul_config_req;
+        vnf_p7.mac->hi_dci0_req = &mac_hi_dci0_req;
+        vnf_p7.mac->tx_req = &mac_tx_req;
+
+        if(vnf_p7.udp.enabled) {
+          mac_start_data(vnf_p7.mac,
+                         vnf_p7.udp.rx_port,
+                         vnf_p7.udp.tx_addr.c_str(),
+                         vnf_p7.udp.tx_port);
+        }
+
+        vnf.p7_vnfs.push_back(vnf_p7);
+      }
+    }
+  } catch(std::exception &e) {
+    printf("%s", e.what());
+    return -1;
+  } catch(boost::exception &e) {
+    printf("%s", boost::diagnostic_information(e).c_str());
+  }
+
+  struct ifaddrs *ifaddr;
+
+  getifaddrs(&ifaddr);
+
+  while(ifaddr) {
+    int family = ifaddr->ifa_addr->sa_family;
+
+    if(family == AF_INET) {
+      char host[128];
+      getnameinfo(ifaddr->ifa_addr, sizeof(sockaddr_in), host, sizeof(host),  NULL, 0, 0);
+      printf("%s\n", host);
+    }
+
+    ifaddr = ifaddr->ifa_next;
+  }
 
+  return 0;
 }
 
 
-int main(int argc, char *argv[])
-{
-	if (argc < 3)
-	{
-		printf("Use parameters: <P5 Port> <xml config file>\n");
-		return 0;
-	}
-
-	set_thread_priority(50);
-
-	vnf_info vnf;
-
-	if(read_vnf_xml(vnf, argv[2]) < 0)
-	{
-		printf("Failed to read xml file>\n");
-		return 0;
-	}
-
-	nfapi_vnf_config_t* config = nfapi_vnf_config_create();
-
-	config->vnf_ipv4 = 1;
-	config->vnf_p5_port = atoi(argv[1]);
-	config->pnf_connection_indication = &pnf_connection_indication_cb;
-	config->pnf_disconnect_indication = &pnf_disconnection_indication_cb;
-	config->pnf_param_resp = &pnf_param_resp_cb;
-	config->pnf_config_resp = &pnf_config_resp_cb;
-	config->pnf_start_resp = &pnf_start_resp_cb;
-	config->param_resp = &param_resp_cb;
-	config->config_resp = &config_resp_cb;
-	config->start_resp = &start_resp_cb;
-	config->vendor_ext = &vendor_ext_cb;
-	
-	
-	
-	config->trace = &vnf_sim_trace;
-	
-	config->malloc = &vnf_allocate;
-	config->free = &vnf_deallocate;
-
-	config->user_data = &vnf;
-
-	config->codec_config.unpack_vendor_extension_tlv = &vnf_sim_unpack_vendor_extension_tlv;
-	config->codec_config.pack_vendor_extension_tlv = &vnf_sim_pack_vendor_extension_tlv;
-
-	config->codec_config.unpack_p4_p5_vendor_extension = &vnf_sim_unpack_p4_p5_vendor_extension;
-	config->codec_config.pack_p4_p5_vendor_extension = &vnf_sim_pack_p4_p5_vendor_extension;
-	config->allocate_p4_p5_vendor_ext = &vnf_sim_allocate_p4_p5_vendor_ext;
-	config->deallocate_p4_p5_vendor_ext = &vnf_sim_deallocate_p4_p5_vendor_ext;
-	config->codec_config.allocate = &vnf_allocate;
-	config->codec_config.deallocate = &vnf_deallocate;
-
-
-	printf("Calling nfapi_vnf_start\n");
-	return nfapi_vnf_start(config);
+int main(int argc, char *argv[]) {
+  if (argc < 3) {
+    printf("Use parameters: <P5 Port> <xml config file>\n");
+    return 0;
+  }
+
+  set_thread_priority(50);
+  vnf_info vnf;
+
+  if(read_vnf_xml(vnf, argv[2]) < 0) {
+    printf("Failed to read xml file>\n");
+    return 0;
+  }
+
+  nfapi_vnf_config_t *config = nfapi_vnf_config_create();
+  config->vnf_ipv4 = 1;
+  config->vnf_p5_port = atoi(argv[1]);
+  config->pnf_connection_indication = &pnf_connection_indication_cb;
+  config->pnf_disconnect_indication = &pnf_disconnection_indication_cb;
+  config->pnf_param_resp = &pnf_param_resp_cb;
+  config->pnf_config_resp = &pnf_config_resp_cb;
+  config->pnf_start_resp = &pnf_start_resp_cb;
+  config->param_resp = &param_resp_cb;
+  config->config_resp = &config_resp_cb;
+  config->start_resp = &start_resp_cb;
+  config->vendor_ext = &vendor_ext_cb;
+  config->trace = &vnf_sim_trace;
+  config->malloc = &vnf_allocate;
+  config->free = &vnf_deallocate;
+  config->user_data = &vnf;
+  config->codec_config.unpack_vendor_extension_tlv = &vnf_sim_unpack_vendor_extension_tlv;
+  config->codec_config.pack_vendor_extension_tlv = &vnf_sim_pack_vendor_extension_tlv;
+  config->codec_config.unpack_p4_p5_vendor_extension = &vnf_sim_unpack_p4_p5_vendor_extension;
+  config->codec_config.pack_p4_p5_vendor_extension = &vnf_sim_pack_p4_p5_vendor_extension;
+  config->allocate_p4_p5_vendor_ext = &vnf_sim_allocate_p4_p5_vendor_ext;
+  config->deallocate_p4_p5_vendor_ext = &vnf_sim_deallocate_p4_p5_vendor_ext;
+  config->codec_config.allocate = &vnf_allocate;
+  config->codec_config.deallocate = &vnf_deallocate;
+  printf("Calling nfapi_vnf_start\n");
+  return nfapi_vnf_start(config);
 }
diff --git a/openair1/PHY/CODING/3gpplte_sse.c b/openair1/PHY/CODING/3gpplte_sse.c
index 96dbcc371711c709a0035ce8ddcea3321d6bce23..2a7b789650428ff12c2418ccb3c3ce0fa3ba4d74 100644
--- a/openair1/PHY/CODING/3gpplte_sse.c
+++ b/openair1/PHY/CODING/3gpplte_sse.c
@@ -26,9 +26,9 @@
    date: 09.2012
 */
 #ifndef TC_MAIN
-#include "coding_defs.h"
+  #include "coding_defs.h"
 #else
-#include <stdint.h>
+  #include <stdint.h>
 #endif
 #include <stdio.h>
 #include <string.h>
@@ -66,11 +66,11 @@ struct treillis {
   union {
     uint8x8_t systematic_andp1_64[3];
     char systematic_andp1_8[24];
-  }__attribute__((aligned(64)));
+  } __attribute__((aligned(64)));
   union {
     uint8x8_t parity2_64[3];
     char parity2_8[24];
-  }__attribute__((aligned(64)));
+  } __attribute__((aligned(64)));
   int exit_state;
 };
 #endif
@@ -79,23 +79,20 @@ struct treillis all_treillis[8][256];
 
 int all_treillis_initialized=0;
 
-static inline unsigned char threegpplte_rsc(unsigned char input,unsigned char *state)
-{
+static inline unsigned char threegpplte_rsc(unsigned char input,unsigned char *state) {
   unsigned char output;
   output = (input ^ (*state>>2) ^ (*state>>1))&1;
   *state = (((input<<2)^(*state>>1))^((*state>>1)<<2)^((*state)<<2))&7;
   return(output);
 }
 
-static inline void threegpplte_rsc_termination(unsigned char *x,unsigned char *z,unsigned char *state)
-{
+static inline void threegpplte_rsc_termination(unsigned char *x,unsigned char *z,unsigned char *state) {
   *z     = ((*state>>2) ^ (*state))   &1;
   *x     = ((*state)    ^ (*state>>1))   &1;
   *state = (*state)>>1;
 }
 
-static void treillis_table_init(void)
-{
+static void treillis_table_init(void) {
   //struct treillis t[][]=all_treillis;
   //t=memalign(16,sizeof(struct treillis)*8*256);
   int i, j,b;
@@ -114,8 +111,8 @@ static void treillis_table_init(void)
         all_treillis[i][j].systematic_andp1_8[b*3]= (j&(1<<(7-b)))>>(7-b);
         v=threegpplte_rsc( all_treillis[i][j].systematic_andp1_8[b*3] ,
                            &current_state);
-	all_treillis[i][j].systematic_andp1_8[b*3+1]=v; // for the yparity1
-	//        all_treillis[i][j].parity1_8[b*3+1]=v; // for the yparity1
+        all_treillis[i][j].systematic_andp1_8[b*3+1]=v; // for the yparity1
+        //        all_treillis[i][j].parity1_8[b*3+1]=v; // for the yparity1
         all_treillis[i][j].parity2_8[b*3+2]=v; // for the yparity2
       }
 
@@ -128,14 +125,12 @@ static void treillis_table_init(void)
 }
 
 
-char interleave_compact_byte(short * base_interleaver,unsigned char * input, unsigned char * output, int n)
-{
-
+char interleave_compact_byte(short *base_interleaver,unsigned char *input, unsigned char *output, int n) {
   char expandInput[768*8] __attribute__((aligned(32)));
   int i,loop=n>>4;
 #if defined(__x86_64__) || defined(__i386__)
 #ifndef __AVX2__
-  __m128i *i_128=(__m128i *)input, *o_128=(__m128i*)expandInput;
+  __m128i *i_128=(__m128i *)input, *o_128=(__m128i *)expandInput;
   __m128i tmp1, tmp2, tmp3, tmp4;
   __m128i BIT_MASK = _mm_set_epi8(  0b00000001,
                                     0b00000010,
@@ -153,42 +148,41 @@ char interleave_compact_byte(short * base_interleaver,unsigned char * input, uns
                                     0b00100000,
                                     0b01000000,
                                     0b10000000);
-
 #else
-  __m256i *i_256=(__m256i *)input, *o_256=(__m256i*)expandInput;
+  __m256i *i_256=(__m256i *)input, *o_256=(__m256i *)expandInput;
   __m256i tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
   __m256i BIT_MASK = _mm256_set_epi8(  0b00000001,
-				       0b00000010,
-				       0b00000100,
-				       0b00001000,
-				       0b00010000,
-				       0b00100000,
-				       0b01000000,
-				       0b10000000,
-				       0b00000001,
-				       0b00000010,
-				       0b00000100,
-				       0b00001000,
-				       0b00010000,
-				       0b00100000,
-				       0b01000000,
-				       0b10000000,
-				       0b00000001,
-				       0b00000010,
-				       0b00000100,
-				       0b00001000,
-				       0b00010000,
-				       0b00100000,
-				       0b01000000,
-				       0b10000000,
-				       0b00000001,
-				       0b00000010,
-				       0b00000100,
-				       0b00001000,
-				       0b00010000,
-				       0b00100000,
-				       0b01000000,
-				       0b10000000);
+                                       0b00000010,
+                                       0b00000100,
+                                       0b00001000,
+                                       0b00010000,
+                                       0b00100000,
+                                       0b01000000,
+                                       0b10000000,
+                                       0b00000001,
+                                       0b00000010,
+                                       0b00000100,
+                                       0b00001000,
+                                       0b00010000,
+                                       0b00100000,
+                                       0b01000000,
+                                       0b10000000,
+                                       0b00000001,
+                                       0b00000010,
+                                       0b00000100,
+                                       0b00001000,
+                                       0b00010000,
+                                       0b00100000,
+                                       0b01000000,
+                                       0b10000000,
+                                       0b00000001,
+                                       0b00000010,
+                                       0b00000100,
+                                       0b00001000,
+                                       0b00010000,
+                                       0b00100000,
+                                       0b01000000,
+                                       0b10000000);
 #endif
 #elif defined(__arm__)
   uint8x16_t *i_128=(uint8x16_t *)input, *o_128=(uint8x16_t *)expandInput;
@@ -196,40 +190,41 @@ char interleave_compact_byte(short * base_interleaver,unsigned char * input, uns
   uint16x8_t tmp3;
   uint32x4_t tmp4;
   uint8x16_t and_tmp;
-  uint8x16_t BIT_MASK = {  	    0b10000000,
-                                    0b01000000,
-                                    0b00100000,
-                                    0b00010000,
-                                    0b00001000,
-                                    0b00000100,
-                                    0b00000010,
-                                    0b00000001,
-                                    0b10000000,
-                                    0b01000000,
-                                    0b00100000,
-                                    0b00010000,
-                                    0b00001000,
-                                    0b00000100,
-                                    0b00000010,
-                                    0b00000001};
+  uint8x16_t BIT_MASK = {       0b10000000,
+                                0b01000000,
+                                0b00100000,
+                                0b00010000,
+                                0b00001000,
+                                0b00000100,
+                                0b00000010,
+                                0b00000001,
+                                0b10000000,
+                                0b01000000,
+                                0b00100000,
+                                0b00010000,
+                                0b00001000,
+                                0b00000100,
+                                0b00000010,
+                                0b00000001
+                        };
 #endif
- 
-
 #ifndef __AVX2__
+
   if ((n&15) > 0)
     loop++;
+
 #else
   loop=n>>5;
+
   if ((n&31) > 0)
     loop++;
-#endif
 
+#endif
 
   for (i=0; i<loop ; i++ ) {
-    // int cur_byte=i<<3; 
-    // for (b=0;b<8;b++) 
-    //   expandInput[cur_byte+b] = (input[i]&(1<<(7-b)))>>(7-b); 
-
+    // int cur_byte=i<<3;
+    // for (b=0;b<8;b++)
+    //   expandInput[cur_byte+b] = (input[i]&(1<<(7-b)))>>(7-b);
 #if defined(__x86_64__) || defined(__i386__)
 #ifndef __AVX2__
     tmp1=_mm_load_si128(i_128++);       // tmp1 = B0,B1,...,B15
@@ -237,29 +232,22 @@ char interleave_compact_byte(short * base_interleaver,unsigned char * input, uns
     tmp3=_mm_unpacklo_epi16(tmp2,tmp2); // tmp3 = B0,B0,B0,B0,B1,B1,B1,B1,B2,B2,B2,B2,B3,B3,B3,B3
     tmp4=_mm_unpacklo_epi32(tmp3,tmp3); // tmp4 - B0,B0,B0,B0,B0,B0,B0,B0,B1,B1,B1,B1,B1,B1,B1,B1
     *o_128++=_mm_cmpeq_epi8(_mm_and_si128(tmp4,BIT_MASK),BIT_MASK);
-
     tmp4=_mm_unpackhi_epi32(tmp3,tmp3); // tmp4 - B2,B2,B2,B2,B2,B2,B2,B2,B3,B3,B3,B3,B3,B3,B3,B3
     *o_128++=_mm_cmpeq_epi8(_mm_and_si128(tmp4,BIT_MASK),BIT_MASK);;
-
     tmp3=_mm_unpackhi_epi16(tmp2,tmp2); // tmp3 = B4,B4,B4,B4,B5,B5,B5,B5,B6,B6,B6,B6,B7,B7,B7,B7
     tmp4=_mm_unpacklo_epi32(tmp3,tmp3); // tmp4 - B4,B4,B4,B4,B4,B4,B4,B4,B5,B5,B5,B5,B5,B5,B5,B5
     *o_128++=_mm_cmpeq_epi8(_mm_and_si128(tmp4,BIT_MASK),BIT_MASK);;
-
     tmp4=_mm_unpackhi_epi32(tmp3,tmp3); // tmp4 - B6,B6,B6,B6,B6,B6,B6,B6,B7,B7,B7,B7,B7,B7,B7,B7
     *o_128++=_mm_cmpeq_epi8(_mm_and_si128(tmp4,BIT_MASK),BIT_MASK);;
-
     tmp2=_mm_unpackhi_epi8(tmp1,tmp1);  // tmp2 = B8,B8,B9,B9,...,B15,B15
     tmp3=_mm_unpacklo_epi16(tmp2,tmp2); // tmp3 = B8,B8,B8,B8,B9,B9,B9,B9,B10,B10,B10,B10,B11,B11,B11,B11
     tmp4=_mm_unpacklo_epi32(tmp3,tmp3); // tmp4 = B8,B8,B8,B8,B8,B8,B8,B8,B9,B9,B9,B9,B9,B9,B9,B9
     *o_128++=_mm_cmpeq_epi8(_mm_and_si128(tmp4,BIT_MASK),BIT_MASK);;
-
     tmp4=_mm_unpackhi_epi32(tmp3,tmp3); // tmp4 = B10,B10,B10,B10,B10,B10,B10,B10,B11,B11,B11,B11,B11,B11,B11,B11
     *o_128++=_mm_cmpeq_epi8(_mm_and_si128(tmp4,BIT_MASK),BIT_MASK);;
-
     tmp3=_mm_unpackhi_epi16(tmp2,tmp2); // tmp3 = B12,B12,B12,B12,B13,B13,B13,B13,B14,B14,B14,B14,B15,B15,B15,B15
     tmp4=_mm_unpacklo_epi32(tmp3,tmp3); // tmp4 = B12,B12,B12,B12,B12,B12,B12,B12,B13,B13,B13,B13,B13,B13,B13,B13
     *o_128++=_mm_cmpeq_epi8(_mm_and_si128(tmp4,BIT_MASK),BIT_MASK);;
-
     tmp4=_mm_unpackhi_epi32(tmp3,tmp3); // tmp4 = B14,B14,B14,B14,B14,B14,B14,B14,B15,B15,B15,B15,B15,B15,B15,B15
     *o_128++=_mm_cmpeq_epi8(_mm_and_si128(tmp4,BIT_MASK),BIT_MASK);;
 #else
@@ -281,7 +269,6 @@ char interleave_compact_byte(short * base_interleaver,unsigned char * input, uns
     //print_bytes2("out",(uint8_t*)o_256);
     o_256[4]=_mm256_cmpeq_epi8(_mm256_and_si256(tmp7,BIT_MASK),BIT_MASK);;
     //print_bytes2("out",(uint8_t*)(o_256+4));
-
     tmp3=_mm256_unpackhi_epi16(tmp2,tmp2); // tmp3 = B4,B4,B4,B4,B5,B5,B5,B5,B6,B6,B6,B6,B7,B7,B7,B7,B20,B20,B20,B20,...,B23,B23,B23,B23
     tmp4=_mm256_unpacklo_epi32(tmp3,tmp3); // tmp4 - B4,B4,B4,B4,B4,B4,B4,B4,B5,B5,B5,B5,B5,B5,B5,B5,B20,B20...,B21..,B21
     tmp5=_mm256_unpackhi_epi32(tmp3,tmp3); // tmp5 - B6,B6,B6,B6,B6,B6,B6,B6,B7,B7,B7,B7,B7,B7,B7,B7,B22...,B22,B23,...,B23
@@ -297,7 +284,6 @@ char interleave_compact_byte(short * base_interleaver,unsigned char * input, uns
     //print_bytes2("out",(uint8_t*)(o_256+1));
     o_256[5]=_mm256_cmpeq_epi8(_mm256_and_si256(tmp7,BIT_MASK),BIT_MASK);;
     //print_bytes2("out",(uint8_t*)(o_256+4));
-
     tmp2=_mm256_unpackhi_epi8(tmp1,tmp1);  // tmp2 = B8 B9 B10 B11 B12 B13 B14 B15 B25 B26 B27 B28 B29 B30 B31
     tmp3=_mm256_unpacklo_epi16(tmp2,tmp2); // tmp3 = B8,B9,B10,B11,B26,B27,B28,B29
     tmp4=_mm256_unpacklo_epi32(tmp3,tmp3); // tmp4 - B8,B9,B26,B27
@@ -314,11 +300,10 @@ char interleave_compact_byte(short * base_interleaver,unsigned char * input, uns
     //print_bytes2("out",(uint8_t*)(o_256+2));
     o_256[6]=_mm256_cmpeq_epi8(_mm256_and_si256(tmp7,BIT_MASK),BIT_MASK);;
     //print_bytes2("out",(uint8_t*)(o_256+4));
-
     tmp3=_mm256_unpackhi_epi16(tmp2,tmp2); // tmp3 = B12 B13 B14 B15 B28 B29 B30 B31
     tmp4=_mm256_unpacklo_epi32(tmp3,tmp3); // tmp4 = B12 B13 B28 B29
-    tmp5=_mm256_unpackhi_epi32(tmp3,tmp3); // tmp5 = B14 B15 B30 B31 
-    tmp6=_mm256_insertf128_si256(tmp4,_mm256_extracti128_si256(tmp5,0),1);  // tmp6 = B12 B13 B14 B15 
+    tmp5=_mm256_unpackhi_epi32(tmp3,tmp3); // tmp5 = B14 B15 B30 B31
+    tmp6=_mm256_insertf128_si256(tmp4,_mm256_extracti128_si256(tmp5,0),1);  // tmp6 = B12 B13 B14 B15
     tmp7=_mm256_insertf128_si256(tmp5,_mm256_extracti128_si256(tmp4,1),0);  // tmp7 = B28 B29 B30 B31
     //print_bytes2("tmp2",(uint8_t*)&tmp2);
     //print_bytes2("tmp3",(uint8_t*)&tmp3);
@@ -330,48 +315,35 @@ char interleave_compact_byte(short * base_interleaver,unsigned char * input, uns
     //print_bytes2("out",(uint8_t*)(o_256+3));
     o_256[7]=_mm256_cmpeq_epi8(_mm256_and_si256(tmp7,BIT_MASK),BIT_MASK);;
     //print_bytes2("out",(uint8_t*)(o_256+7));
-
     o_256+=8;
 #endif
 #elif defined(__arm__)
-    tmp1=vld1q_u8((uint8_t*)i_128);
+    tmp1=vld1q_u8((uint8_t *)i_128);
     //print_bytes("tmp1:",(uint8_t*)&tmp1);
-
     uint8x16x2_t temp1 =  vzipq_u8(tmp1,tmp1);
     tmp2 = temp1.val[0];
-
     uint16x8x2_t temp2 =  vzipq_u16((uint16x8_t)tmp2,(uint16x8_t)tmp2);
     tmp3 = temp2.val[0];
-
     uint32x4x2_t temp3 =  vzipq_u32((uint32x4_t)tmp3,(uint32x4_t)tmp3);
     tmp4 = temp3.val[0];
     //print_bytes("tmp4:",(uint8_t*)&tmp4);
-
     *o_128++=vceqq_u8(vandq_u8((uint8x16_t)tmp4,BIT_MASK),BIT_MASK);    //1
     //print_bytes("o:",(uint8_t*)(o_128-1));
-
     tmp4 = temp3.val[1];
     //print_bytes("tmp4:",(uint8_t*)&tmp4);
-
     *o_128++=vceqq_u8(vandq_u8((uint8x16_t)tmp4,BIT_MASK),BIT_MASK);    //2
     //print_bytes("o:",(uint8_t*)(o_128-1));
-
     tmp3 = temp2.val[1];
     temp3 =  vzipq_u32((uint32x4_t)tmp3,(uint32x4_t)tmp3);
     tmp4 = temp3.val[0];
     //print_bytes("tmp4:",(uint8_t*)&tmp4);
-
     *o_128++=vceqq_u8(vandq_u8((uint8x16_t)tmp4,BIT_MASK),BIT_MASK);    //3
     //print_bytes("o:",(uint8_t*)(o_128-1));
-
     tmp4 = temp3.val[1];
     //print_bytes("tmp4:",(uint8_t*)&tmp4);
-
     *o_128++=vceqq_u8(vandq_u8((uint8x16_t)tmp4,BIT_MASK),BIT_MASK);    //4
-    //and_tmp = vandq_u8((uint8x16_t)tmp4,BIT_MASK); print_bytes("and:",and_tmp); 
+    //and_tmp = vandq_u8((uint8x16_t)tmp4,BIT_MASK); print_bytes("and:",and_tmp);
     //print_bytes("o:",(uint8_t*)(o_128-1));
-
-
     temp1 =  vzipq_u8(tmp1,tmp1);
     tmp2 = temp1.val[1];
     temp2 =  vzipq_u16((uint16x8_t)tmp2,(uint16x8_t)tmp2);
@@ -379,52 +351,41 @@ char interleave_compact_byte(short * base_interleaver,unsigned char * input, uns
     temp3 =  vzipq_u32((uint32x4_t)tmp3,(uint32x4_t)tmp3);
     tmp4 = temp3.val[0];
     //print_bytes("tmp4:",(uint8_t*)&tmp4);
-
     *o_128++=vceqq_u8(vandq_u8((uint8x16_t)tmp4,BIT_MASK),BIT_MASK);    //5
     //print_bytes("o:",(uint8_t*)(o_128-1));
-
     tmp4 = temp3.val[1];
     //print_bytes("tmp4:",(uint8_t*)&tmp4);
-
     *o_128++=vceqq_u8(vandq_u8((uint8x16_t)tmp4,BIT_MASK),BIT_MASK);    //6
     //print_bytes("o:",(uint8_t*)(o_128-1));
-
-
     temp2 =  vzipq_u16((uint16x8_t)tmp2,(uint16x8_t)tmp2);
     tmp3 = temp2.val[1];
     temp3 =  vzipq_u32((uint32x4_t)tmp3,(uint32x4_t)tmp3);
     tmp4 = temp3.val[0];
     //print_bytes("tmp4:",(uint8_t*)&tmp4);
-
     *o_128++=vceqq_u8(vandq_u8((uint8x16_t)tmp4,BIT_MASK),BIT_MASK);    //7
     //print_bytes("o:",(uint8_t*)(o_128-1));
-
     tmp4 = temp3.val[1];
     //print_bytes("tmp4:",(uint8_t*)&tmp4);
-
     *o_128++=vceqq_u8(vandq_u8((uint8x16_t)tmp4,BIT_MASK),BIT_MASK);    //7
     //print_bytes("o:",(uint8_t*)(o_128-1));
-
     i_128++;
 #endif
   }
-  
 
-  short * ptr_intl=base_interleaver;
+  short *ptr_intl=base_interleaver;
 #if defined(__x86_64) || defined(__i386__)
 #ifndef __AVX2__
   __m128i tmp;
- uint16_t *systematic2_ptr=(uint16_t *) output;
+  uint16_t *systematic2_ptr=(uint16_t *) output;
 #else
   __m256i tmp;
- uint32_t *systematic2_ptr=(uint32_t *) output;
+  uint32_t *systematic2_ptr=(uint32_t *) output;
 #endif
 #elif defined(__arm__)
   uint8x16_t tmp;
-  const uint8_t __attribute__ ((aligned (16))) _Powers[16]= 
-    { 1, 2, 4, 8, 16, 32, 64, 128, 1, 2, 4, 8, 16, 32, 64, 128 };
-
-// Set the powers of 2 (do it once for all, if applicable)
+  const uint8_t __attribute__ ((aligned (16))) _Powers[16]=
+  { 1, 2, 4, 8, 16, 32, 64, 128, 1, 2, 4, 8, 16, 32, 64, 128 };
+  // Set the powers of 2 (do it once for all, if applicable)
   uint8x16_t Powers= vld1q_u8(_Powers);
   uint8_t *systematic2_ptr=(uint8_t *) output;
 #endif
@@ -435,8 +396,6 @@ char interleave_compact_byte(short * base_interleaver,unsigned char * input, uns
 #endif
 
   for ( i=0; i<  input_length_words ; i ++ ) {
-
-
 #if defined(__x86_64__) || defined(__i386__)
 #ifndef __AVX2__
     tmp=_mm_insert_epi8(tmp,expandInput[*ptr_intl++],7);
@@ -465,7 +424,6 @@ char interleave_compact_byte(short * base_interleaver,unsigned char * input, uns
     tmp=_mm256_insert_epi8(tmp,expandInput[*ptr_intl++],2);
     tmp=_mm256_insert_epi8(tmp,expandInput[*ptr_intl++],1);
     tmp=_mm256_insert_epi8(tmp,expandInput[*ptr_intl++],0);
-
     tmp=_mm256_insert_epi8(tmp,expandInput[*ptr_intl++],8+7);
     tmp=_mm256_insert_epi8(tmp,expandInput[*ptr_intl++],8+6);
     tmp=_mm256_insert_epi8(tmp,expandInput[*ptr_intl++],8+5);
@@ -474,7 +432,6 @@ char interleave_compact_byte(short * base_interleaver,unsigned char * input, uns
     tmp=_mm256_insert_epi8(tmp,expandInput[*ptr_intl++],8+2);
     tmp=_mm256_insert_epi8(tmp,expandInput[*ptr_intl++],8+1);
     tmp=_mm256_insert_epi8(tmp,expandInput[*ptr_intl++],8+0);
-
     tmp=_mm256_insert_epi8(tmp,expandInput[*ptr_intl++],16+7);
     tmp=_mm256_insert_epi8(tmp,expandInput[*ptr_intl++],16+6);
     tmp=_mm256_insert_epi8(tmp,expandInput[*ptr_intl++],16+5);
@@ -483,7 +440,6 @@ char interleave_compact_byte(short * base_interleaver,unsigned char * input, uns
     tmp=_mm256_insert_epi8(tmp,expandInput[*ptr_intl++],16+2);
     tmp=_mm256_insert_epi8(tmp,expandInput[*ptr_intl++],16+1);
     tmp=_mm256_insert_epi8(tmp,expandInput[*ptr_intl++],16+0);
-
     tmp=_mm256_insert_epi8(tmp,expandInput[*ptr_intl++],24+7);
     tmp=_mm256_insert_epi8(tmp,expandInput[*ptr_intl++],24+6);
     tmp=_mm256_insert_epi8(tmp,expandInput[*ptr_intl++],24+5);
@@ -492,7 +448,6 @@ char interleave_compact_byte(short * base_interleaver,unsigned char * input, uns
     tmp=_mm256_insert_epi8(tmp,expandInput[*ptr_intl++],24+2);
     tmp=_mm256_insert_epi8(tmp,expandInput[*ptr_intl++],24+1);
     tmp=_mm256_insert_epi8(tmp,expandInput[*ptr_intl++],24+0);
-
     *systematic2_ptr++=(unsigned int)_mm256_movemask_epi8(tmp);
 #endif
 #elif defined(__arm__)
@@ -512,11 +467,10 @@ char interleave_compact_byte(short * base_interleaver,unsigned char * input, uns
     tmp=vsetq_lane_u8(expandInput[*ptr_intl++],tmp,8+2);
     tmp=vsetq_lane_u8(expandInput[*ptr_intl++],tmp,8+1);
     tmp=vsetq_lane_u8(expandInput[*ptr_intl++],tmp,8+0);
-// Compute the mask from the input
+    // Compute the mask from the input
     uint64x2_t Mask= vpaddlq_u32(vpaddlq_u16(vpaddlq_u8(vandq_u8(tmp, Powers))));
     vst1q_lane_u8(systematic2_ptr++, (uint8x16_t)Mask, 0);
     vst1q_lane_u8(systematic2_ptr++, (uint8x16_t)Mask, 8);
-
 #endif
   }
 
@@ -537,14 +491,12 @@ char interleave_compact_byte(short * base_interleaver,unsigned char * input, uns
 void threegpplte_turbo_encoder_sse(unsigned char *input,
                                    unsigned short input_length_bytes,
                                    unsigned char *output,
-                                   unsigned char F)
-{
-
+                                   unsigned char F) {
   int i;
   unsigned char *x;
   unsigned char state0=0,state1=0;
   unsigned short input_length_bits = input_length_bytes<<3;
-  short * base_interleaver;
+  short *base_interleaver;
 
   if (  all_treillis_initialized == 0 ) {
     treillis_table_init();
@@ -560,15 +512,12 @@ void threegpplte_turbo_encoder_sse(unsigned char *input,
     base_interleaver=il_tb+f1f2mat[i].beg_index;
   }
 
-
   unsigned char systematic2[768] __attribute__((aligned(32)));
-
   interleave_compact_byte(base_interleaver,input,systematic2,input_length_bytes);
-
 #if defined(__x86_64__) || defined(__i386__)
-  __m64 *ptr_output=(__m64*) output;
+  __m64 *ptr_output=(__m64 *) output;
 #elif defined(__arm__)
-  uint8x8_t *ptr_output=(uint8x8_t*)output; 
+  uint8x8_t *ptr_output=(uint8x8_t *)output;
 #endif
   unsigned char cur_s1, cur_s2;
   int code_rate;
@@ -582,54 +531,45 @@ void threegpplte_turbo_encoder_sse(unsigned char *input,
       /*
        *ptr_output++ = _mm_add_pi8(all_treillis[state0][cur_s1].systematic_64[code_rate],
        _mm_add_pi8(all_treillis[state0][cur_s1].parity1_64[code_rate],
-	 all_treillis[state1][cur_s2].parity2_64[code_rate]));
-	*/
-
+      all_treillis[state1][cur_s2].parity2_64[code_rate]));
+      */
       *ptr_output++ = _mm_add_pi8(all_treillis[state0][cur_s1].systematic_andp1_64[code_rate],
-				  all_treillis[state1][cur_s2].parity2_64[code_rate]);
-	
-	
+                                  all_treillis[state1][cur_s2].parity2_64[code_rate]);
 #elif defined(__arm__)
-	*ptr_output++ = vadd_u8(all_treillis[state0][cur_s1].systematic_andp1_64[code_rate],
-				all_treillis[state0][cur_s1].parity2_64[code_rate]);
+      *ptr_output++ = vadd_u8(all_treillis[state0][cur_s1].systematic_andp1_64[code_rate],
+                              all_treillis[state0][cur_s1].parity2_64[code_rate]);
 #endif
-      }
-      
-      state0=all_treillis[state0][cur_s1].exit_state;
-      state1=all_treillis[state1][cur_s2].exit_state;
+    }
+
+    state0=all_treillis[state0][cur_s1].exit_state;
+    state1=all_treillis[state1][cur_s2].exit_state;
   }
 
   x=output+(input_length_bits*3);
-
   // Trellis termination
   threegpplte_rsc_termination(&x[0],&x[1],&state0);
 #ifdef DEBUG_TURBO_ENCODER
-  printf("term: x0 %d, x1 %d, state0 %d\n",x[0],x[1],state0);
+  printf("term: x0 %u, x1 %u, state0 %d\n",x[0],x[1],state0);
 #endif //DEBUG_TURBO_ENCODER
-
   threegpplte_rsc_termination(&x[2],&x[3],&state0);
 #ifdef DEBUG_TURBO_ENCODER
-  printf("term: x0 %d, x1 %d, state0 %d\n",x[2],x[3],state0);
+  printf("term: x0 %u, x1 %u, state0 %d\n",x[2],x[3],state0);
 #endif //DEBUG_TURBO_ENCODER
-
   threegpplte_rsc_termination(&x[4],&x[5],&state0);
 #ifdef DEBUG_TURBO_ENCODER
-  printf("term: x0 %d, x1 %d, state0 %d\n",x[4],x[5],state0);
+  printf("term: x0 %u, x1 %u, state0 %d\n",x[4],x[5],state0);
 #endif //DEBUG_TURBO_ENCODER
-
   threegpplte_rsc_termination(&x[6],&x[7],&state1);
-
 #ifdef DEBUG_TURBO_ENCODER
-  printf("term: x0 %d, x1 %d, state1 %d\n",x[6],x[7],state1);
+  printf("term: x0 %u, x1 %u, state1 %d\n",x[6],x[7],state1);
 #endif //DEBUG_TURBO_ENCODER
   threegpplte_rsc_termination(&x[8],&x[9],&state1);
 #ifdef DEBUG_TURBO_ENCODER
-  printf("term: x0 %d, x1 %d, state1 %d\n",x[8],x[9],state1);
+  printf("term: x0 %u, x1 %u, state1 %d\n",x[8],x[9],state1);
 #endif //DEBUG_TURBO_ENCODER
   threegpplte_rsc_termination(&x[10],&x[11],&state1);
-
 #ifdef DEBUG_TURBO_ENCODER
-  printf("term: x0 %d, x1 %d, state1 %d\n",x[10],x[11],state1);
+  printf("term: x0 %u, x1 %u, state1 %d\n",x[10],x[11],state1);
 #endif //DEBUG_TURBO_ENCODER
 #if defined(__x86_64__) || defined(__i386__)
   _mm_empty();
@@ -638,32 +578,31 @@ void threegpplte_turbo_encoder_sse(unsigned char *input,
 }
 
 void init_encoder_sse (void) {
-    treillis_table_init(); 	   
+  treillis_table_init();
 }
 /* function which will be called by the shared lib loader, to check shared lib version
    against main exec version. version mismatch no considered as fatal (interfaces not supposed to change)
-*/ 
-int  coding_checkbuildver(char * mainexec_buildversion, char ** shlib_buildversion)
-{
+*/
+int  coding_checkbuildver(char *mainexec_buildversion, char **shlib_buildversion) {
 #ifndef PACKAGE_VERSION
 #define PACKAGE_VERSION "standalone built: " __DATE__ __TIME__
 #endif
-    *shlib_buildversion = PACKAGE_VERSION;
-    if (strcmp(mainexec_buildversion, *shlib_buildversion) != 0) {
-          fprintf(stderr,"[CODING] shared lib version %s, doesn't match main version %s, compatibility should be checked\n",
-                mainexec_buildversion,*shlib_buildversion);
-    }
-    return 0;
+  *shlib_buildversion = PACKAGE_VERSION;
+
+  if (strcmp(mainexec_buildversion, *shlib_buildversion) != 0) {
+    fprintf(stderr,"[CODING] shared lib version %s, doesn't match main version %s, compatibility should be checked\n",
+            mainexec_buildversion,*shlib_buildversion);
+  }
+
+  return 0;
 }
 
 #ifdef TC_MAIN
-#define INPUT_LENGTH 20 
+#define INPUT_LENGTH 20
 #define F1 21
 #define F2 120
 
-int main(int argc,char **argv)
-{
-
+int main(int argc,char **argv) {
   unsigned char input[INPUT_LENGTH+32],state,state2;
   unsigned char output[12+(3*(INPUT_LENGTH<<3))],x,z;
   int i;
@@ -680,28 +619,27 @@ int main(int argc,char **argv)
   printf("\n");
 
   for (state=0; state<8; state++) {
-
     state2=state;
     threegpplte_rsc_termination(&x,&z,&state2);
     printf("Termination: (%d->%d) : (%d,%d)\n",state,state2,x,z);
   }
 
-  memset((void*)input,0,INPUT_LENGTH+16);
+  memset((void *)input,0,INPUT_LENGTH+16);
+
   for (i=0; i<INPUT_LENGTH; i++) {
     input[i] = i*219;
-    printf("Input %d : %d\n",i,input[i]);
+    printf("Input %d : %u\n",i,input[i]);
   }
 
   threegpplte_turbo_encoder_sse(&input[0],
-                            INPUT_LENGTH,
-                            &output[0],
-                            0);
+                                INPUT_LENGTH,
+                                &output[0],
+                                0);
 
+  for (i=0; i<12+(INPUT_LENGTH*24); i++)
+    printf("%u",output[i]);
 
-  for (i=0;i<12+(INPUT_LENGTH*24);i++)
-    printf("%d",output[i]);
   printf("\n");
-
   return(0);
 }
 
diff --git a/openair1/PHY/CODING/3gpplte_turbo_decoder_sse.c b/openair1/PHY/CODING/3gpplte_turbo_decoder_sse.c
index a02af690770faefc2eeac9de07ffaea721a9ff9a..9d4e6a312a492dfd04cce9a46e724adcccaae159 100644
--- a/openair1/PHY/CODING/3gpplte_turbo_decoder_sse.c
+++ b/openair1/PHY/CODING/3gpplte_turbo_decoder_sse.c
@@ -38,33 +38,33 @@
 #include "PHY/sse_intrin.h"
 
 #ifndef TEST_DEBUG
-#include "PHY/defs.h"
-#include "PHY/CODING/defs.h"
-#include "PHY/CODING/lte_interleaver_inline.h"
+  #include "PHY/defs.h"
+  #include "PHY/CODING/defs.h"
+  #include "PHY/CODING/lte_interleaver_inline.h"
 #else
 
-#include "defs.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+  #include "defs.h"
+  #include <stdio.h>
+  #include <stdlib.h>
+  #include <string.h>
 #endif
 
 #define SHUFFLE16(a,b,c,d,e,f,g,h) _mm_set_epi8(h==-1?-1:h*2+1, \
-            h==-1?-1:h*2, \
-            g==-1?-1:g*2+1, \
-            g==-1?-1:g*2, \
-            f==-1?-1:f*2+1, \
-            f==-1?-1:f*2, \
-            e==-1?-1:e*2+1, \
-            e==-1?-1:e*2, \
-            d==-1?-1:d*2+1, \
-            d==-1?-1:d*2, \
-            c==-1?-1:c*2+1, \
-            c==-1?-1:c*2, \
-            b==-1?-1:b*2+1, \
-            b==-1?-1:b*2, \
-            a==-1?-1:a*2+1, \
-            a==-1?-1:a*2);
+    h==-1?-1:h*2, \
+    g==-1?-1:g*2+1, \
+    g==-1?-1:g*2, \
+    f==-1?-1:f*2+1, \
+    f==-1?-1:f*2, \
+    e==-1?-1:e*2+1, \
+    e==-1?-1:e*2, \
+    d==-1?-1:d*2+1, \
+    d==-1?-1:d*2, \
+    c==-1?-1:c*2+1, \
+    c==-1?-1:c*2, \
+    b==-1?-1:b*2+1, \
+    b==-1?-1:b*2, \
+    a==-1?-1:a*2+1, \
+    a==-1?-1:a*2);
 
 
 
@@ -75,44 +75,40 @@
 
 #ifdef LLR8
 
-typedef int8_t llr_t; // internal decoder LLR data is 8-bit fixed
-typedef int8_t channel_t;
-#define MAX 64
+  typedef int8_t llr_t; // internal decoder LLR data is 8-bit fixed
+  typedef int8_t channel_t;
+  #define MAX 64
 #else
 
-typedef int16_t llr_t; // internal decoder LLR data is 16-bit fixed
-typedef int16_t channel_t;
-#define MAX 256
+  typedef int16_t llr_t; // internal decoder LLR data is 16-bit fixed
+  typedef int16_t channel_t;
+  #define MAX 256
 
 #endif
 
-void log_map (llr_t* systematic,channel_t* y_parity, llr_t* m11, llr_t* m10, llr_t *alpha, llr_t *beta, llr_t* ext,unsigned short frame_length,unsigned char term_flag,unsigned char F,int offset8_flag,
+void log_map (llr_t *systematic,channel_t *y_parity, llr_t *m11, llr_t *m10, llr_t *alpha, llr_t *beta, llr_t *ext,unsigned short frame_length,unsigned char term_flag,unsigned char F,int offset8_flag,
               time_stats_t *alpha_stats,time_stats_t *beta_stats,time_stats_t *gamma_stats,time_stats_t *ext_stats);
-void compute_gamma(llr_t* m11,llr_t* m10,llr_t* systematic, channel_t* y_parity, unsigned short frame_length,unsigned char term_flag);
-void compute_alpha(llr_t*alpha,llr_t *beta, llr_t* m11,llr_t* m10, unsigned short frame_length,unsigned char F);
-void compute_beta(llr_t*alpha, llr_t* beta,llr_t* m11,llr_t* m10, unsigned short frame_length,unsigned char F,int offset8_flag);
-void compute_ext(llr_t* alpha,llr_t* beta,llr_t* m11,llr_t* m10,llr_t* extrinsic, llr_t* ap, unsigned short frame_length);
+void compute_gamma(llr_t *m11,llr_t *m10,llr_t *systematic, channel_t *y_parity, unsigned short frame_length,unsigned char term_flag);
+void compute_alpha(llr_t *alpha,llr_t *beta, llr_t *m11,llr_t *m10, unsigned short frame_length,unsigned char F);
+void compute_beta(llr_t *alpha, llr_t *beta,llr_t *m11,llr_t *m10, unsigned short frame_length,unsigned char F,int offset8_flag);
+void compute_ext(llr_t *alpha,llr_t *beta,llr_t *m11,llr_t *m10,llr_t *extrinsic, llr_t *ap, unsigned short frame_length);
 
 
-void print_bytes(char *s, __m128i *x)
-{
-
+void print_bytes(char *s, __m128i *x) {
   int8_t *tempb = (int8_t *)x;
-
   printf("%s  : %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",s,
          tempb[0],tempb[1],tempb[2],tempb[3],tempb[4],tempb[5],tempb[6],tempb[7],
          tempb[8],tempb[9],tempb[10],tempb[11],tempb[12],tempb[13],tempb[14],tempb[15]);
-
 }
 
 
-void log_map(llr_t* systematic,
-             channel_t* y_parity,
-             llr_t* m11,
-             llr_t* m10,
+void log_map(llr_t *systematic,
+             channel_t *y_parity,
+             llr_t *m11,
+             llr_t *m10,
              llr_t *alpha,
              llr_t *beta,
-             llr_t* ext,
+             llr_t *ext,
              unsigned short frame_length,
              unsigned char term_flag,
              unsigned char F,
@@ -120,13 +116,10 @@ void log_map(llr_t* systematic,
              time_stats_t *alpha_stats,
              time_stats_t *beta_stats,
              time_stats_t *gamma_stats,
-             time_stats_t *ext_stats)
-{
-
+             time_stats_t *ext_stats) {
 #ifdef DEBUG_LOGMAP
   msg("log_map, frame_length %d\n",frame_length);
 #endif
-
   start_meas(gamma_stats) ;
   compute_gamma(m11,m10,systematic,y_parity,frame_length,term_flag) ;
   stop_meas(gamma_stats);
@@ -139,19 +132,15 @@ void log_map(llr_t* systematic,
   start_meas(ext_stats)   ;
   compute_ext(alpha,beta,m11,m10,ext,systematic,frame_length)       ;
   stop_meas(ext_stats);
-
-
 }
 
-void compute_gamma(llr_t* m11,llr_t* m10,llr_t* systematic,channel_t* y_parity,
-                   unsigned short frame_length,unsigned char term_flag)
-{
+void compute_gamma(llr_t *m11,llr_t *m10,llr_t *systematic,channel_t *y_parity,
+                   unsigned short frame_length,unsigned char term_flag) {
   int k,K1;
   __m128i *systematic128 = (__m128i *)systematic;
   __m128i *y_parity128   = (__m128i *)y_parity;
   __m128i *m10_128        = (__m128i *)m10;
   __m128i *m11_128        = (__m128i *)m11;
-
 #ifdef DEBUG_LOGMAP
   msg("compute_gamma, %p,%p,%p,%p,framelength %d\n",m11,m10,systematic,y_parity,frame_length);
 #endif
@@ -159,7 +148,6 @@ void compute_gamma(llr_t* m11,llr_t* m10,llr_t* systematic,channel_t* y_parity,
   K1=frame_length>>3;
 
   for (k=0; k<K1; k++) {
-
     m11_128[k] = _mm_srai_epi16(_mm_adds_epi16(systematic128[k],y_parity128[k]),1);
     m10_128[k] = _mm_srai_epi16(_mm_subs_epi16(systematic128[k],y_parity128[k]),1);
     /*
@@ -206,13 +194,11 @@ void compute_gamma(llr_t* m11,llr_t* m10,llr_t* systematic,channel_t* y_parity,
      (int16_t)_mm_extract_epi16(m10_128[k],6),
      (int16_t)_mm_extract_epi16(m10_128[k],7));
     */
-
   }
 
   // Termination
   m11_128[k] = _mm_srai_epi16(_mm_adds_epi16(systematic128[k+term_flag],y_parity128[k]),1);
   m10_128[k] = _mm_srai_epi16(_mm_subs_epi16(systematic128[k+term_flag],y_parity128[k]),1);
-
   //  printf("gamma (term): %d,%d, %d,%d, %d,%d\n",m11[k<<3],m10[k<<3],m11[1+(k<<3)],m10[1+(k<<3)],m11[2+(k<<3)],m10[2+(k<<3)]);
 #else
   register __m128i sl,sh,ypl,yph; //K128=_mm_set1_epi8(-128);
@@ -231,7 +217,6 @@ void compute_gamma(llr_t* m11,llr_t* m10,llr_t* systematic,channel_t* y_parity,
     //    m10_128[k] = _mm_subs_epi8(systematic128[k],y_parity128[k]);
     //    m11_128[k] = _mm_sub_epi8(_mm_avg_epu8(_mm_add_epi8(systematic128[k],K128),_mm_add_epi8(y_parity128[k],K128)),K128);
     //    m10_128[k] = _mm_sub_epi8(_mm_avg_epu8(_mm_add_epi8(systematic128[k],K128),_mm_add_epi8(_mm_sign_epi8(y_parity128[k],K128),K128)),K128);
-
     /*
     printf("gamma %d: s %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
      k,
@@ -309,7 +294,6 @@ void compute_gamma(llr_t* m11,llr_t* m10,llr_t* systematic,channel_t* y_parity,
   }
 
   // Termination
-
   sl  = _mm_cvtepi8_epi16(systematic128[k+term_flag]);
   sh = _mm_cvtepi8_epi16(_mm_srli_si128(systematic128[k],8));
   ypl = _mm_cvtepi8_epi16(y_parity128[k+term_flag]);
@@ -318,7 +302,6 @@ void compute_gamma(llr_t* m11,llr_t* m10,llr_t* systematic,channel_t* y_parity,
                                _mm_srai_epi16(_mm_adds_epi16(sh,yph),1));
   m10_128[k] = _mm_packs_epi16(_mm_srai_epi16(_mm_subs_epi16(sl,ypl),1),
                                _mm_srai_epi16(_mm_subs_epi16(sh,yph),1));
-
   //    m11_128[k] = _mm_adds_epi8(systematic128[k+term_flag],y_parity128[k]);
   //    m10_128[k] = _mm_subs_epi8(systematic128[k+term_flag],y_parity128[k]);
   //  m11_128[k] = _mm_sub_epi8(_mm_avg_epu8(_mm_add_epi8(systematic128[k+term_flag],K128),_mm_add_epi8(y_parity128[k],K128)),K128);
@@ -383,20 +366,17 @@ void compute_gamma(llr_t* m11,llr_t* m10,llr_t* systematic,channel_t* y_parity,
 #endif
   _mm_empty();
   _m_empty();
-
 }
 
 #define L 40
 
-void compute_alpha(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned short frame_length,unsigned char F)
-{
+void compute_alpha(llr_t *alpha,llr_t *beta,llr_t *m_11,llr_t *m_10,unsigned short frame_length,unsigned char F) {
   int k,l,l2,K1,rerun_flag=0;
   __m128i *alpha128=(__m128i *)alpha,*alpha_ptr;
   __m128i a0,a1,a2,a3,a4,a5,a6,a7,*m11p,*m10p;
   __m128i m_b0,m_b1,m_b2,m_b3,m_b4,m_b5,m_b6,m_b7;
   __m128i new0,new1,new2,new3,new4,new5,new6,new7;
   __m128i alpha_max;
-
 #ifndef LLR8
   l2 = L>>3;
   K1 = (frame_length>>3);
@@ -439,19 +419,16 @@ void compute_alpha(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned sho
     }
 
     alpha_ptr = &alpha128[0];
-
-    m11p = (__m128i*)m_11;
-    m10p = (__m128i*)m_10;
+    m11p = (__m128i *)m_11;
+    m10p = (__m128i *)m_10;
 
     for (k=0;
          k<l;
          k++) {
-
       a1=_mm_load_si128(&alpha_ptr[1]);
       a3=_mm_load_si128(&alpha_ptr[3]);
       a5=_mm_load_si128(&alpha_ptr[5]);
       a7=_mm_load_si128(&alpha_ptr[7]);
-
       m_b0 = _mm_adds_epi16(a1,*m11p);  // m11
       m_b4 = _mm_subs_epi16(a1,*m11p);  // m00=-m11
       m_b1 = _mm_subs_epi16(a3,*m10p);  // m01=-m10
@@ -460,12 +437,10 @@ void compute_alpha(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned sho
       m_b6 = _mm_subs_epi16(a5,*m10p);  // m01=-m10
       m_b3 = _mm_subs_epi16(a7,*m11p);  // m00=-m11
       m_b7 = _mm_adds_epi16(a7,*m11p);  // m11
-
       a0=_mm_load_si128(&alpha_ptr[0]);
       a2=_mm_load_si128(&alpha_ptr[2]);
       a4=_mm_load_si128(&alpha_ptr[4]);
       a6=_mm_load_si128(&alpha_ptr[6]);
-
       new0 = _mm_subs_epi16(a0,*m11p);  // m00=-m11
       new4 = _mm_adds_epi16(a0,*m11p);  // m11
       new1 = _mm_adds_epi16(a2,*m10p);  // m10
@@ -474,7 +449,6 @@ void compute_alpha(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned sho
       new6 = _mm_adds_epi16(a4,*m10p);  // m10
       new3 = _mm_adds_epi16(a6,*m11p);  // m11
       new7 = _mm_subs_epi16(a6,*m11p);  // m00=-m11
-
       a0 = _mm_max_epi16(m_b0,new0);
       a1 = _mm_max_epi16(m_b1,new1);
       a2 = _mm_max_epi16(m_b2,new2);
@@ -483,7 +457,6 @@ void compute_alpha(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned sho
       a5 = _mm_max_epi16(m_b5,new5);
       a6 = _mm_max_epi16(m_b6,new6);
       a7 = _mm_max_epi16(m_b7,new7);
-
       alpha_max = _mm_max_epi16(a0,a1);
       alpha_max = _mm_max_epi16(alpha_max,a2);
       alpha_max = _mm_max_epi16(alpha_max,a3);
@@ -491,7 +464,6 @@ void compute_alpha(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned sho
       alpha_max = _mm_max_epi16(alpha_max,a5);
       alpha_max = _mm_max_epi16(alpha_max,a6);
       alpha_max = _mm_max_epi16(alpha_max,a7);
-
       alpha_ptr+=8;
       m11p++;
       m10p++;
@@ -503,7 +475,6 @@ void compute_alpha(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned sho
       alpha_ptr[5] = _mm_subs_epi16(a5,alpha_max);
       alpha_ptr[6] = _mm_subs_epi16(a6,alpha_max);
       alpha_ptr[7] = _mm_subs_epi16(a7,alpha_max);
-
     }
 
     /*
@@ -981,9 +952,7 @@ void compute_alpha(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned sho
     */
 #else
 
-
     if (rerun_flag == 0) {
-
       alpha128[0] = _mm_set_epi8(-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,0);
       alpha128[1] = _mm_set_epi8(-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2);
       alpha128[2] = _mm_set_epi8(-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2);
@@ -992,8 +961,6 @@ void compute_alpha(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned sho
       alpha128[5] = _mm_set_epi8(-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2);
       alpha128[6] = _mm_set_epi8(-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2);
       alpha128[7] = _mm_set_epi8(-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2);
-
-
     } else {
       alpha128[0] = _mm_slli_si128(alpha128[(K1<<3)],1);
       alpha128[1] = _mm_slli_si128(alpha128[1+(K1<<3)],1);
@@ -1025,15 +992,12 @@ void compute_alpha(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned sho
     print_bytes("a6:",&alpha_ptr[6]);
     print_bytes("a7:",&alpha_ptr[7]);
     */
-
-    m11p = (__m128i*)m_11;
-    m10p = (__m128i*)m_10;
+    m11p = (__m128i *)m_11;
+    m10p = (__m128i *)m_10;
 
     for (k=0;
          k<l;
          k++) {
-
-
       m_b0 = _mm_adds_epi8(alpha_ptr[1],*m11p);  // m11
       m_b4 = _mm_subs_epi8(alpha_ptr[1],*m11p);  // m00=-m11
       m_b1 = _mm_subs_epi8(alpha_ptr[3],*m10p);  // m01=-m10
@@ -1042,7 +1006,6 @@ void compute_alpha(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned sho
       m_b6 = _mm_subs_epi8(alpha_ptr[5],*m10p);  // m01=-m10
       m_b3 = _mm_subs_epi8(alpha_ptr[7],*m11p);  // m00=-m11
       m_b7 = _mm_adds_epi8(alpha_ptr[7],*m11p);  // m11
-
       new0 = _mm_subs_epi8(alpha_ptr[0],*m11p);  // m00=-m11
       new4 = _mm_adds_epi8(alpha_ptr[0],*m11p);  // m11
       new1 = _mm_adds_epi8(alpha_ptr[2],*m10p);  // m10
@@ -1051,7 +1014,6 @@ void compute_alpha(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned sho
       new6 = _mm_adds_epi8(alpha_ptr[4],*m10p);  // m10
       new3 = _mm_adds_epi8(alpha_ptr[6],*m11p);  // m11
       new7 = _mm_subs_epi8(alpha_ptr[6],*m11p);  // m00=-m11
-
       alpha_ptr += 8;
       m11p++;
       m10p++;
@@ -1063,8 +1025,6 @@ void compute_alpha(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned sho
       alpha_ptr[5] = _mm_max_epi8(m_b5,new5);
       alpha_ptr[6] = _mm_max_epi8(m_b6,new6);
       alpha_ptr[7] = _mm_max_epi8(m_b7,new7);
-
-
       // compute and subtract maxima
       alpha_max = _mm_max_epi8(alpha_ptr[0],alpha_ptr[1]);
       alpha_max = _mm_max_epi8(alpha_max,alpha_ptr[2]);
@@ -1073,7 +1033,6 @@ void compute_alpha(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned sho
       alpha_max = _mm_max_epi8(alpha_max,alpha_ptr[5]);
       alpha_max = _mm_max_epi8(alpha_max,alpha_ptr[6]);
       alpha_max = _mm_max_epi8(alpha_max,alpha_ptr[7]);
-
       alpha_ptr[0] = _mm_subs_epi8(alpha_ptr[0],alpha_max);
       alpha_ptr[1] = _mm_subs_epi8(alpha_ptr[1],alpha_max);
       alpha_ptr[2] = _mm_subs_epi8(alpha_ptr[2],alpha_max);
@@ -1109,14 +1068,11 @@ void compute_alpha(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned sho
 }
 
 
-void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned short frame_length,unsigned char F,int offset8_flag)
-{
-
+void compute_beta(llr_t *alpha,llr_t *beta,llr_t *m_11,llr_t *m_10,unsigned short frame_length,unsigned char F,int offset8_flag) {
   int k,rerun_flag=0;
   __m128i m11_128,m10_128;
   __m128i m_b0,m_b1,m_b2,m_b3,m_b4,m_b5,m_b6,m_b7;
   __m128i new0,new1,new2,new3,new4,new5,new6,new7;
-
   __m128i *beta128,*alpha128,*beta_ptr;
   __m128i beta_max;
   int16_t m11,m10,beta0_16,beta1_16,beta2_16,beta3_16,beta4_16,beta5_16,beta6_16,beta7_16,beta0_2,beta1_2,beta2_2,beta3_2,beta_m;
@@ -1124,30 +1080,21 @@ void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned shor
 #ifdef LLR8
   llr_t beta2,beta3,beta4,beta5,beta6,beta7;
   __m128i beta_16;
-
 #endif
-
 #ifdef DEBUG_LOGMAP
   msg("compute_beta, %p,%p,%p,%p,framelength %d,F %d\n",
       beta,m_11,m_10,alpha,frame_length,F);
 #endif
-
-
   // termination for beta initialization
-
   //  printf("beta init: offset8 %d\n",offset8_flag);
   m11=(int16_t)m_11[2+frame_length];
   m10=(int16_t)m_10[2+frame_length];
-
   //  printf("m11,m10 %d,%d\n",m11,m10);
-
   beta0 = -m11;//M0T_TERM;
   beta1 = m11;//M1T_TERM;
   m11=(int16_t)m_11[1+frame_length];
   m10=(int16_t)m_10[1+frame_length];
-
   //  printf("m11,m10 %d,%d\n",m11,m10);
-
   beta0_2 = beta0-m11;//+M0T_TERM;
   beta1_2 = beta0+m11;//+M1T_TERM;
   beta2_2 = beta1+m10;//M2T_TERM;
@@ -1155,7 +1102,6 @@ void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned shor
   m11=(int16_t)m_11[frame_length];
   m10=(int16_t)m_10[frame_length];
   //  printf("m11,m10 %d,%d (%p)\n",m11,m10,m_11+frame_length);
-
   beta0_16 = beta0_2-m11;//+M0T_TERM;
   beta1_16 = beta0_2+m11;//+M1T_TERM;
   beta2_16 = beta1_2+m10;//+M2T_TERM;
@@ -1164,8 +1110,6 @@ void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned shor
   beta5_16 = beta2_2+m10;//+M5T_TERM;
   beta6_16 = beta3_2+m11;//+M6T_TERM;
   beta7_16 = beta3_2-m11;//+M7T_TERM;
-
-
   beta_m = (beta0_16>beta1_16) ? beta0_16 : beta1_16;
   beta_m = (beta_m>beta2_16) ? beta_m : beta2_16;
   beta_m = (beta_m>beta3_16) ? beta_m : beta3_16;
@@ -1173,8 +1117,6 @@ void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned shor
   beta_m = (beta_m>beta5_16) ? beta_m : beta5_16;
   beta_m = (beta_m>beta6_16) ? beta_m : beta6_16;
   beta_m = (beta_m>beta7_16) ? beta_m : beta7_16;
-
-
   beta0_16=beta0_16-beta_m;
   beta1_16=beta1_16-beta_m;
   beta2_16=beta2_16-beta_m;
@@ -1183,7 +1125,6 @@ void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned shor
   beta5_16=beta5_16-beta_m;
   beta6_16=beta6_16-beta_m;
   beta7_16=beta7_16-beta_m;
-
 #ifdef LLR8
   beta_16 = _mm_set_epi16(beta7_16,beta6_16,beta5_16,beta4_16,beta3_16,beta2_16,beta1_16,beta0_16);
   beta_16 = _mm_packs_epi16(beta_16,beta_16);
@@ -1199,8 +1140,8 @@ void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned shor
 #endif
 
   for (rerun_flag=0;; rerun_flag=1) {
-    beta_ptr   = (__m128i*)&beta[frame_length<<3];
-    alpha128   = (__m128i*)&alpha[0];
+    beta_ptr   = (__m128i *)&beta[frame_length<<3];
+    alpha128   = (__m128i *)&alpha[0];
 
     if (rerun_flag == 0) {
 #ifndef LLR8
@@ -1223,9 +1164,8 @@ void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned shor
       beta_ptr[7] = alpha128[7+(frame_length>>1)];
 #endif
     } else {
-      beta128 = (__m128i*)&beta[0];
+      beta128 = (__m128i *)&beta[0];
 #ifndef LLR8
-
       beta_ptr[0] = _mm_srli_si128(beta128[0],2);
       beta_ptr[1] = _mm_srli_si128(beta128[1],2);
       beta_ptr[2] = _mm_srli_si128(beta128[2],2);
@@ -1255,7 +1195,6 @@ void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned shor
     beta_ptr[5] = _mm_insert_epi16(beta_ptr[5],beta5_16,7);
     beta_ptr[6] = _mm_insert_epi16(beta_ptr[6],beta6_16,7);
     beta_ptr[7] = _mm_insert_epi16(beta_ptr[7],beta7_16,7);
-
     /*
       beta[7+(frame_length<<3)] = beta0_16;
       beta[15+(frame_length<<3)] = beta1_16;
@@ -1277,18 +1216,15 @@ void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned shor
       beta_ptr[6] = _mm_insert_epi8(beta_ptr[6],beta6,15);
       beta_ptr[7] = _mm_insert_epi8(beta_ptr[7],beta7,15);
     } else {
-
     }
 
 #endif
-
 #ifndef LLR8
     int loopval=((rerun_flag==0)?0:((frame_length-L)>>3));
 
     for (k=(frame_length>>3)-1; k>=loopval; k--) {
-      m11_128=((__m128i*)m_11)[k];
-      m10_128=((__m128i*)m_10)[k];
-
+      m11_128=((__m128i *)m_11)[k];
+      m10_128=((__m128i *)m_10)[k];
       m_b0 = _mm_adds_epi16(beta_ptr[4],m11_128);  //m11
       m_b1 = _mm_subs_epi16(beta_ptr[4],m11_128);  //m00
       m_b2 = _mm_subs_epi16(beta_ptr[5],m10_128);  //m01
@@ -1297,7 +1233,6 @@ void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned shor
       m_b5 = _mm_subs_epi16(beta_ptr[6],m10_128);  //m01
       m_b6 = _mm_subs_epi16(beta_ptr[7],m11_128);  //m00
       m_b7 = _mm_adds_epi16(beta_ptr[7],m11_128);  //m11
-
       new0 = _mm_subs_epi16(beta_ptr[0],m11_128);  //m00
       new1 = _mm_adds_epi16(beta_ptr[0],m11_128);  //m11
       new2 = _mm_adds_epi16(beta_ptr[1],m10_128);  //m10
@@ -1306,9 +1241,7 @@ void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned shor
       new5 = _mm_adds_epi16(beta_ptr[2],m10_128);  //m10
       new6 = _mm_adds_epi16(beta_ptr[3],m11_128);  //m11
       new7 = _mm_subs_epi16(beta_ptr[3],m11_128);  //m00
-
       beta_ptr-=8;
-
       beta_ptr[0] = _mm_max_epi16(m_b0,new0);
       beta_ptr[1] = _mm_max_epi16(m_b1,new1);
       beta_ptr[2] = _mm_max_epi16(m_b2,new2);
@@ -1317,7 +1250,6 @@ void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned shor
       beta_ptr[5] = _mm_max_epi16(m_b5,new5);
       beta_ptr[6] = _mm_max_epi16(m_b6,new6);
       beta_ptr[7] = _mm_max_epi16(m_b7,new7);
-
       beta_max = _mm_max_epi16(beta_ptr[0],beta_ptr[1]);
       beta_max = _mm_max_epi16(beta_max   ,beta_ptr[2]);
       beta_max = _mm_max_epi16(beta_max   ,beta_ptr[3]);
@@ -1325,7 +1257,6 @@ void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned shor
       beta_max = _mm_max_epi16(beta_max   ,beta_ptr[5]);
       beta_max = _mm_max_epi16(beta_max   ,beta_ptr[6]);
       beta_max = _mm_max_epi16(beta_max   ,beta_ptr[7]);
-
       beta_ptr[0] = _mm_subs_epi16(beta_ptr[0],beta_max);
       beta_ptr[1] = _mm_subs_epi16(beta_ptr[1],beta_max);
       beta_ptr[2] = _mm_subs_epi16(beta_ptr[2],beta_max);
@@ -1334,14 +1265,11 @@ void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned shor
       beta_ptr[5] = _mm_subs_epi16(beta_ptr[5],beta_max);
       beta_ptr[6] = _mm_subs_epi16(beta_ptr[6],beta_max);
       beta_ptr[7] = _mm_subs_epi16(beta_ptr[7],beta_max);
-
-
-
     }
 
 #else
 #ifdef DEBUG_LOGMAP
-    printf("beta0 %d:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
+    printf("beta0 %u:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
            (frame_length>>4),
            _mm_extract_epi8(beta_ptr[0],0),
            _mm_extract_epi8(beta_ptr[0],1),
@@ -1359,7 +1287,7 @@ void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned shor
            _mm_extract_epi8(beta_ptr[0],13),
            _mm_extract_epi8(beta_ptr[0],14),
            _mm_extract_epi8(beta_ptr[0],15));
-    printf("beta1 %d:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
+    printf("beta1 %u:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
            (frame_length>>4),
            _mm_extract_epi8(beta_ptr[1],0),
            _mm_extract_epi8(beta_ptr[1],1),
@@ -1377,7 +1305,7 @@ void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned shor
            _mm_extract_epi8(beta_ptr[1],13),
            _mm_extract_epi8(beta_ptr[1],14),
            _mm_extract_epi8(beta_ptr[1],15));
-    printf("beta2 %d:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
+    printf("beta2 %u:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
            (frame_length>>4),
            _mm_extract_epi8(beta_ptr[2],0),
            _mm_extract_epi8(beta_ptr[2],1),
@@ -1395,7 +1323,7 @@ void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned shor
            _mm_extract_epi8(beta_ptr[2],13),
            _mm_extract_epi8(beta_ptr[2],14),
            _mm_extract_epi8(beta_ptr[2],15));
-    printf("beta3 %d:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
+    printf("beta3 %u:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
            (frame_length>>4),
            _mm_extract_epi8(beta_ptr[3],0),
            _mm_extract_epi8(beta_ptr[3],1),
@@ -1413,7 +1341,7 @@ void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned shor
            _mm_extract_epi8(beta_ptr[3],13),
            _mm_extract_epi8(beta_ptr[3],14),
            _mm_extract_epi8(beta_ptr[3],15));
-    printf("beta4 %d:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
+    printf("beta4 %u:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
            (frame_length>>4),
            _mm_extract_epi8(beta_ptr[4],0),
            _mm_extract_epi8(beta_ptr[4],1),
@@ -1431,7 +1359,7 @@ void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned shor
            _mm_extract_epi8(beta_ptr[4],13),
            _mm_extract_epi8(beta_ptr[4],14),
            _mm_extract_epi8(beta_ptr[4],15));
-    printf("beta5 %d:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
+    printf("beta5 %u:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
            (frame_length>>4),
            _mm_extract_epi8(beta_ptr[5],0),
            _mm_extract_epi8(beta_ptr[5],1),
@@ -1449,7 +1377,7 @@ void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned shor
            _mm_extract_epi8(beta_ptr[5],13),
            _mm_extract_epi8(beta_ptr[5],14),
            _mm_extract_epi8(beta_ptr[5],15));
-    printf("beta6 %d:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
+    printf("beta6 %u:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
            (frame_length>>4),
            _mm_extract_epi8(beta_ptr[6],0),
            _mm_extract_epi8(beta_ptr[6],1),
@@ -1467,7 +1395,7 @@ void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned shor
            _mm_extract_epi8(beta_ptr[6],13),
            _mm_extract_epi8(beta_ptr[6],14),
            _mm_extract_epi8(beta_ptr[6],15));
-    printf("beta7 %d:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
+    printf("beta7 %u:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
            (frame_length>>4),
            _mm_extract_epi8(beta_ptr[7],0),
            _mm_extract_epi8(beta_ptr[7],1),
@@ -1491,9 +1419,8 @@ void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned shor
     __m128i zeros=_mm_set1_epi8(0);
 
     for (k=(frame_length>>4)-1; k>=loopval; k--) {
-
-      m11_128=((__m128i*)m_11)[k];
-      m10_128=((__m128i*)m_10)[k];
+      m11_128=((__m128i *)m_11)[k];
+      m10_128=((__m128i *)m_10)[k];
       /*
       if ((offset8_flag==1) && (k==((frame_length>>4)-9))) {
       beta_ptr[0] = _mm_insert_epi8(beta_ptr[0],beta0,15);
@@ -1506,9 +1433,6 @@ void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned shor
       beta_ptr[7] = _mm_insert_epi8(beta_ptr[7],beta7,15);
       }*/
       //      print_bytes("m11:",&m11_128);
-
-
-
       m_b0 = _mm_adds_epi8(beta_ptr[4],m11_128);  //m11
       m_b1 = _mm_subs_epi8(beta_ptr[4],m11_128);  //m00
       m_b2 = _mm_subs_epi8(beta_ptr[5],m10_128);  //m01
@@ -1517,7 +1441,6 @@ void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned shor
       m_b5 = _mm_subs_epi8(beta_ptr[6],m10_128);  //m01
       m_b6 = _mm_subs_epi8(beta_ptr[7],m11_128);  //m00
       m_b7 = _mm_adds_epi8(beta_ptr[7],m11_128);  //m11
-
       new0 = _mm_subs_epi8(beta_ptr[0],m11_128);  //m00
       new1 = _mm_adds_epi8(beta_ptr[0],m11_128);  //m11
       new2 = _mm_adds_epi8(beta_ptr[1],m10_128);  //m10
@@ -1526,9 +1449,7 @@ void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned shor
       new5 = _mm_adds_epi8(beta_ptr[2],m10_128);  //m10
       new6 = _mm_adds_epi8(beta_ptr[3],m11_128);  //m11
       new7 = _mm_subs_epi8(beta_ptr[3],m11_128);  //m00
-
       beta_ptr-=8;
-
       beta_ptr[0] = _mm_max_epi8(m_b0,new0);
       beta_ptr[1] = _mm_max_epi8(m_b1,new1);
       beta_ptr[2] = _mm_max_epi8(m_b2,new2);
@@ -1537,7 +1458,6 @@ void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned shor
       beta_ptr[5] = _mm_max_epi8(m_b5,new5);
       beta_ptr[6] = _mm_max_epi8(m_b6,new6);
       beta_ptr[7] = _mm_max_epi8(m_b7,new7);
-
       beta_max = _mm_max_epi8(beta_ptr[0],beta_ptr[1]);
       beta_max = _mm_max_epi8(beta_max   ,beta_ptr[2]);
       beta_max = _mm_max_epi8(beta_max   ,beta_ptr[3]);
@@ -1553,7 +1473,6 @@ void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned shor
       beta_ptr[5] = _mm_subs_epi8(beta_ptr[5],beta_max);
       beta_ptr[6] = _mm_subs_epi8(beta_ptr[6],beta_max);
       beta_ptr[7] = _mm_subs_epi8(beta_ptr[7],beta_max);
-
       /*
       printf("beta0 %d:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
       k,
@@ -1700,7 +1619,6 @@ void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned shor
       _mm_extract_epi8(beta_ptr[7],14),
       _mm_extract_epi8(beta_ptr[7],15));
       */
-
     }
 
 #endif
@@ -1713,8 +1631,7 @@ void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned shor
   _m_empty();
 }
 
-void compute_ext(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,llr_t* ext, llr_t* systematic,unsigned short frame_length)
-{
+void compute_ext(llr_t *alpha,llr_t *beta,llr_t *m_11,llr_t *m_10,llr_t *ext, llr_t *systematic,unsigned short frame_length) {
   __m128i *alpha128=(__m128i *)alpha;
   __m128i *beta128=(__m128i *)beta;
   __m128i *m11_128,*m10_128,*ext_128;
@@ -1724,26 +1641,20 @@ void compute_ext(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,llr_t* ext, ll
   __m128i m10_1,m10_2,m10_3,m10_4;
   __m128i m11_1,m11_2,m11_3,m11_4;
   int k;
-
   //
   // LLR computation, 8 consequtive bits per loop
   //
-
 #ifdef DEBUG_LOGMAP
   msg("compute_ext, %p, %p, %p, %p, %p, %p ,framelength %d\n",alpha,beta,m_11,m_10,ext,systematic,frame_length);
 #endif
-
   alpha_ptr = alpha128;
   beta_ptr = &beta128[8];
-
-
 #ifndef LLR8
 
   for (k=0; k<(frame_length>>3); k++) {
-
-    m11_128        = (__m128i*)&m_11[k<<3];
-    m10_128        = (__m128i*)&m_10[k<<3];
-    ext_128        = (__m128i*)&ext[k<<3];
+    m11_128        = (__m128i *)&m_11[k<<3];
+    m10_128        = (__m128i *)&m_10[k<<3];
+    ext_128        = (__m128i *)&ext[k<<3];
     /*
       printf("EXT %03d\n",k);
       print_shorts("a0:",&alpha_ptr[0]);
@@ -1809,23 +1720,18 @@ void compute_ext(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,llr_t* ext, ll
     m11_1 = _mm_max_epi16(m11_1,m11_2);
     m11_1 = _mm_max_epi16(m11_1,m11_3);
     m11_1 = _mm_max_epi16(m11_1,m11_4);
-
     //      print_shorts("m11_1:",&m11_1);
-
     m01_1 = _mm_subs_epi16(m01_1,*m10_128);
     m00_1 = _mm_subs_epi16(m00_1,*m11_128);
     m10_1 = _mm_adds_epi16(m10_1,*m10_128);
     m11_1 = _mm_adds_epi16(m11_1,*m11_128);
-
     //      print_shorts("m10_1:",&m10_1);
     //      print_shorts("m11_1:",&m11_1);
     m01_1 = _mm_max_epi16(m01_1,m00_1);
     m10_1 = _mm_max_epi16(m10_1,m11_1);
     //      print_shorts("m01_1:",&m01_1);
     //      print_shorts("m10_1:",&m10_1);
-
     *ext_128 = _mm_subs_epi16(m10_1,m01_1);
-
     /*
       print_shorts("ext:",ext_128);
       print_shorts("m11:",m11_128);
@@ -1834,7 +1740,6 @@ void compute_ext(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,llr_t* ext, ll
       print_shorts("m01_1:",&m01_1);
       print_shorts("syst:",systematic_128);
     */
-
     alpha_ptr+=8;
     beta_ptr+=8;
   }
@@ -1842,11 +1747,9 @@ void compute_ext(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,llr_t* ext, ll
 #else
 
   for (k=0; k<(frame_length>>4); k++) {
-
-    m11_128        = (__m128i*)&m_11[k<<4];
-    m10_128        = (__m128i*)&m_10[k<<4];
-    ext_128        = (__m128i*)&ext[k<<4];
-
+    m11_128        = (__m128i *)&m_11[k<<4];
+    m10_128        = (__m128i *)&m_10[k<<4];
+    ext_128        = (__m128i *)&ext[k<<4];
     m00_4 = _mm_adds_epi8(alpha_ptr[7],beta_ptr[3]); //ALPHA_BETA_4m00;
     m11_4 = _mm_adds_epi8(alpha_ptr[7],beta_ptr[7]); //ALPHA_BETA_4m11;
     m00_3 = _mm_adds_epi8(alpha_ptr[6],beta_ptr[7]); //ALPHA_BETA_3m00;
@@ -1863,7 +1766,6 @@ void compute_ext(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,llr_t* ext, ll
     m10_2 = _mm_adds_epi8(alpha_ptr[3],beta_ptr[5]); //ALPHA_BETA_2m10;
     m10_1 = _mm_adds_epi8(alpha_ptr[2],beta_ptr[1]); //ALPHA_BETA_1m10;
     m01_1 = _mm_adds_epi8(alpha_ptr[2],beta_ptr[5]); //ALPHA_BETA_1m01;
-
     m01_1 = _mm_max_epi8(m01_1,m01_2);
     m01_1 = _mm_max_epi8(m01_1,m01_3);
     m01_1 = _mm_max_epi8(m01_1,m01_4);
@@ -1876,29 +1778,20 @@ void compute_ext(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,llr_t* ext, ll
     m11_1 = _mm_max_epi8(m11_1,m11_2);
     m11_1 = _mm_max_epi8(m11_1,m11_3);
     m11_1 = _mm_max_epi8(m11_1,m11_4);
-
-
     m01_1 = _mm_subs_epi8(m01_1,*m10_128);
     m00_1 = _mm_subs_epi8(m00_1,*m11_128);
     m10_1 = _mm_adds_epi8(m10_1,*m10_128);
     m11_1 = _mm_adds_epi8(m11_1,*m11_128);
-
-
     m01_1 = _mm_max_epi8(m01_1,m00_1);
     m10_1 = _mm_max_epi8(m10_1,m11_1);
-
-
     *ext_128 = _mm_subs_epi8(m10_1,m01_1);
-
     alpha_ptr+=8;
     beta_ptr+=8;
   }
 
 #endif
-
   _mm_empty();
   _m_empty();
-
 }
 
 
@@ -1906,8 +1799,7 @@ void compute_ext(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,llr_t* ext, ll
 //int pi2[n],pi3[n+8],pi5[n+8],pi4[n+8],pi6[n+8],
 int *pi2tab[188],*pi5tab[188],*pi4tab[188],*pi6tab[188];
 
-void free_td()
-{
+void free_td() {
   int ind;
 
   for (ind = 0; ind < 188; ind++) {
@@ -1918,21 +1810,17 @@ void free_td()
   }
 }
 
-void init_td()
-{
-
+void init_td() {
   int ind,i,i2,i3,j,n,n2,pi,pi3;
-  short * base_interleaver;
+  short *base_interleaver;
 
   for (ind=0; ind<188; ind++) {
-
     n = f1f2mat[ind].nb_bits;
     base_interleaver=il_tb+f1f2mat[ind].beg_index;
     pi2tab[ind] = malloc((n+8)*sizeof(int));
     pi5tab[ind] = malloc((n+8)*sizeof(int));
     pi4tab[ind] = malloc((n+8)*sizeof(int));
     pi6tab[ind] = malloc((n+8)*sizeof(int));
-
 #ifdef LLR8
 
     if ((n&15)>0) {
@@ -1941,7 +1829,6 @@ void init_td()
       n2 = n;
 
     for (j=0,i=0; i<n2; i++,j+=16) {
-
       if (j>=n2)
         j-=(n2-1);
 
@@ -1956,10 +1843,8 @@ void init_td()
       j=i2;
 
       for (i3=0; i3<(n>>3); i3++,i++,j+=8) {
-
         //    if (j>=n)
         //      j-=(n-1);
-
         pi2tab[ind][i]  = j;
         //    printf("pi2[%d] = %d\n",i,j);
       }
@@ -1967,7 +1852,6 @@ void init_td()
 
 #endif
 
-
     for (i=0; i<n2; i++) {
       pi = base_interleaver[i];//(unsigned int)threegpplte_interleaver(f1,f2,n);
       pi3 = pi2tab[ind][pi];
@@ -1975,7 +1859,6 @@ void init_td()
       pi5tab[ind][pi3] = pi2tab[ind][i];
       pi6tab[ind][pi] = pi2tab[ind][i];
     }
-
   }
 }
 
@@ -1991,33 +1874,25 @@ unsigned char phy_threegpplte_turbo_decoder(short *y,
     time_stats_t *gamma_stats,
     time_stats_t *ext_stats,
     time_stats_t *intl1_stats,
-    time_stats_t *intl2_stats)
-{
-
+    time_stats_t *intl2_stats) {
   /*  y is a pointer to the input
       decoded_bytes is a pointer to the decoded output
       n is the size in bits of the coded block, with the tail */
-
   int n2;
 #ifdef LLR8
   llr_t y8[3*(n+16)] __attribute__((aligned(16)));
 #endif
-
   llr_t systematic0[n+16] __attribute__ ((aligned(16)));
   llr_t systematic1[n+16] __attribute__ ((aligned(16)));
   llr_t systematic2[n+16] __attribute__ ((aligned(16)));
   llr_t yparity1[n+16] __attribute__ ((aligned(16)));
   llr_t yparity2[n+16] __attribute__ ((aligned(16)));
-
   llr_t ext[n+128] __attribute__((aligned(16)));
   llr_t ext2[n+128] __attribute__((aligned(16)));
-
   llr_t alpha[(n+16)*8] __attribute__ ((aligned(16)));
   llr_t beta[(n+16)*8] __attribute__ ((aligned(16)));
   llr_t m11[n+16] __attribute__ ((aligned(16)));
   llr_t m10[n+16] __attribute__ ((aligned(16)));
-
-
   int *pi2_p,*pi4_p,*pi5_p,*pi6_p;
   llr_t *s,*s1,*s2,*yp1,*yp2,*yp;
   __m128i *yp128;
@@ -2026,12 +1901,10 @@ unsigned char phy_threegpplte_turbo_decoder(short *y,
   unsigned int crc,oldcrc,crc_len;
   uint8_t temp;
   __m128i tmp128[(n+8)>>3];
-
   __m128i tmp, zeros=_mm_setzero_si128();
 #ifdef LLR8
   __m128i MAX128=_mm_set1_epi16(MAX/2);
 #endif
-
   register __m128i tmpe;
   int offset8_flag=0;
 
@@ -2040,9 +1913,7 @@ unsigned char phy_threegpplte_turbo_decoder(short *y,
     return 255;
   }
 
-
   start_meas(init_stats);
-
 #ifdef LLR8
 
   if ((n&15)>0) {
@@ -2063,21 +1934,21 @@ unsigned char phy_threegpplte_turbo_decoder(short *y,
   }
 
   switch (crc_type) {
-  case CRC24_A:
-  case CRC24_B:
-    crc_len=3;
-    break;
+    case CRC24_A:
+    case CRC24_B:
+      crc_len=3;
+      break;
 
-  case CRC16:
-    crc_len=2;
-    break;
+    case CRC16:
+      crc_len=2;
+      break;
 
-  case CRC8:
-    crc_len=1;
-    break;
+    case CRC8:
+      crc_len=1;
+      break;
 
-  default:
-    crc_len=3;
+    default:
+      crc_len=3;
   }
 
 #ifdef LLR8
@@ -2087,199 +1958,154 @@ unsigned char phy_threegpplte_turbo_decoder(short *y,
     //((__m128i *)y8)[i] = _mm_packs_epi16(((__m128i *)y)[j],((__m128i *)y)[j+1]);
   }
 
-  yp128 = (__m128i*)y8;
+  yp128 = (__m128i *)y8;
 #else
-  yp128 = (__m128i*)y;
+  yp128 = (__m128i *)y;
 #endif
-
-
-
   s = systematic0;
   s1 = systematic1;
   s2 = systematic2;
   yp1 = yparity1;
   yp2 = yparity2;
-
-
 #ifndef LLR8
 
   for (i=0; i<n2; i+=8) {
     pi2_p = &pi2tab[iind][i];
-
     j=pi2_p[0];
-
-
     tmpe = _mm_load_si128(yp128);
-
     s[j]   = _mm_extract_epi16(tmpe,0);
     yp1[j] = _mm_extract_epi16(tmpe,1);
     yp2[j] = _mm_extract_epi16(tmpe,2);
     //    printf("init: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
-
     j=pi2_p[1];
-
     s[j]   = _mm_extract_epi16(tmpe,3);
     yp1[j] = _mm_extract_epi16(tmpe,4);
     yp2[j] = _mm_extract_epi16(tmpe,5);
     //    printf("init: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
-
     j=pi2_p[2];
-
     s[j]   = _mm_extract_epi16(tmpe,6);
     yp1[j] = _mm_extract_epi16(tmpe,7);
     tmpe = _mm_load_si128(&yp128[1]);
     yp2[j] = _mm_extract_epi16(tmpe,0);
     //    printf("init: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
-
     j=pi2_p[3];
-
     s[j]   = _mm_extract_epi16(tmpe,1);
     yp1[j] = _mm_extract_epi16(tmpe,2);
     yp2[j] = _mm_extract_epi16(tmpe,3);
     //    printf("init: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
-
     j=pi2_p[4];
-
     s[j]   = _mm_extract_epi16(tmpe,4);
     yp1[j] = _mm_extract_epi16(tmpe,5);
     yp2[j] = _mm_extract_epi16(tmpe,6);
     //    printf("init: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
-
     j=pi2_p[5];
-
     s[j]   = _mm_extract_epi16(tmpe,7);
     tmpe = _mm_load_si128(&yp128[2]);
     yp1[j] = _mm_extract_epi16(tmpe,0);
     yp2[j] = _mm_extract_epi16(tmpe,1);
     //    printf("init: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
-
     j=pi2_p[6];
-
     s[j]   = _mm_extract_epi16(tmpe,2);
     yp1[j] = _mm_extract_epi16(tmpe,3);
     yp2[j] = _mm_extract_epi16(tmpe,4);
     //    printf("init: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
-
     j=pi2_p[7];
-
     s[j]   = _mm_extract_epi16(tmpe,5);
     yp1[j] = _mm_extract_epi16(tmpe,6);
     yp2[j] = _mm_extract_epi16(tmpe,7);
     //    printf("init: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
-
     yp128+=3;
-
   }
 
 #else
 
   for (i=0; i<n2; i+=16) {
     pi2_p = &pi2tab[iind][i];
-
     j=pi2_p[0];
     s[j]   = _mm_extract_epi8(yp128[0],0);
     yp1[j] = _mm_extract_epi8(yp128[0],1);
     yp2[j] = _mm_extract_epi8(yp128[0],2);
     //    printf("init: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
-
     j=pi2_p[1];
     s[j]   = _mm_extract_epi8(yp128[0],3);
     yp1[j] = _mm_extract_epi8(yp128[0],4);
     yp2[j] = _mm_extract_epi8(yp128[0],5);
     //    printf("init: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
-
     j=pi2_p[2];
     s[j]   = _mm_extract_epi8(yp128[0],6);
     yp1[j] = _mm_extract_epi8(yp128[0],7);
     yp2[j] = _mm_extract_epi8(yp128[0],8);
     //    printf("init: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
-
     j=pi2_p[3];
     s[j]   = _mm_extract_epi8(yp128[0],9);
     yp1[j] = _mm_extract_epi8(yp128[0],10);
     yp2[j] = _mm_extract_epi8(yp128[0],11);
     //    printf("init: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
-
     j=pi2_p[4];
     s[j]   = _mm_extract_epi8(yp128[0],12);
     yp1[j] = _mm_extract_epi8(yp128[0],13);
     yp2[j] = _mm_extract_epi8(yp128[0],14);
     //    printf("init: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
-
     j=pi2_p[5];
     s[j]   = _mm_extract_epi8(yp128[0],15);
     yp1[j] = _mm_extract_epi8(yp128[1],0);
     yp2[j] = _mm_extract_epi8(yp128[1],1);
     //    printf("init: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
-
     j=pi2_p[6];
     s[j]   = _mm_extract_epi8(yp128[1],2);
     yp1[j] = _mm_extract_epi8(yp128[1],3);
     yp2[j] = _mm_extract_epi8(yp128[1],4);
     //    printf("init: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
-
     j=pi2_p[7];
     s[j]   = _mm_extract_epi8(yp128[1],5);
     yp1[j] = _mm_extract_epi8(yp128[1],6);
     yp2[j] = _mm_extract_epi8(yp128[1],7);
     //    printf("init: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
-
     j=pi2_p[8];
     s[j]   = _mm_extract_epi8(yp128[1],8);
     yp1[j] = _mm_extract_epi8(yp128[1],9);
     yp2[j] = _mm_extract_epi8(yp128[1],10);
     //    printf("init: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
-
     j=pi2_p[9];
     s[j]   = _mm_extract_epi8(yp128[1],11);
     yp1[j] = _mm_extract_epi8(yp128[1],12);
     yp2[j] = _mm_extract_epi8(yp128[1],13);
     //    printf("init: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
-
     j=pi2_p[10];
     s[j]   = _mm_extract_epi8(yp128[1],14);
     yp1[j] = _mm_extract_epi8(yp128[1],15);
     yp2[j] = _mm_extract_epi8(yp128[2],0);
     //    printf("init: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
-
     j=pi2_p[11];
     s[j]   = _mm_extract_epi8(yp128[2],1);
     yp1[j] = _mm_extract_epi8(yp128[2],2);
     yp2[j] = _mm_extract_epi8(yp128[2],3);
     //    printf("init: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
-
     j=pi2_p[12];
     s[j]   = _mm_extract_epi8(yp128[2],4);
     yp1[j] = _mm_extract_epi8(yp128[2],5);
     yp2[j] = _mm_extract_epi8(yp128[2],6);
     //    printf("init: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
-
     j=pi2_p[13];
     s[j]   = _mm_extract_epi8(yp128[2],7);
     yp1[j] = _mm_extract_epi8(yp128[2],8);
     yp2[j] = _mm_extract_epi8(yp128[2],9);
     //    printf("init: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
-
     j=pi2_p[14];
     s[j]   = _mm_extract_epi8(yp128[2],10);
     yp1[j] = _mm_extract_epi8(yp128[2],11);
     yp2[j] = _mm_extract_epi8(yp128[2],12);
     //    printf("init: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
-
     j=pi2_p[15];
     s[j]   = _mm_extract_epi8(yp128[2],13);
     yp1[j] = _mm_extract_epi8(yp128[2],14);
     yp2[j] = _mm_extract_epi8(yp128[2],15);
     //    printf("init: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
-
     yp128+=3;
-
   }
 
 #endif
-
-
-  yp=(llr_t*)yp128;
+  yp=(llr_t *)yp128;
 #ifdef LLR8
 
   if (n2>n) {
@@ -2290,7 +2116,7 @@ unsigned char phy_threegpplte_turbo_decoder(short *y,
     s1[n+4]=0;s1[n+5]=0;s1[n+6]=0;s1[n+7]=0;
     s2[n]=0;s2[n+1]=0;s2[n+2]=0;s2[n+3]=0;
     s2[n+4]=0;s2[n+5]=0;s2[n+6]=0;s2[n+7]=0;*/
-    yp=(llr_t*)(y8+n);
+    yp=(llr_t *)(y8+n);
   }
 
 #endif
@@ -2341,68 +2167,55 @@ unsigned char phy_threegpplte_turbo_decoder(short *y,
 #ifdef DEBUG_LOGMAP
   msg("\n");
 #endif //DEBUG_LOGMAP
-
   stop_meas(init_stats);
-
   // do log_map from first parity bit
-
   log_map(systematic0,yparity1,m11,m10,alpha,beta,ext,n2,0,F,offset8_flag,alpha_stats,beta_stats,gamma_stats,ext_stats);
 
   while (iteration_cnt++ < max_iterations) {
-
 #ifdef DEBUG_LOGMAP
     printf("\n*******************ITERATION %d (n %d), ext %p\n\n",iteration_cnt,n,ext);
 #endif //DEBUG_LOGMAP
-
     start_meas(intl1_stats);
 #ifndef LLR8
-
     pi4_p=pi4tab[iind];
 
     for (i=0; i<(n2>>3); i++) { // steady-state portion
-
-      ((__m128i *)systematic2)[i]=_mm_insert_epi16(((__m128i *)systematic2)[i],((llr_t*)ext)[*pi4_p++],0);
-      ((__m128i *)systematic2)[i]=_mm_insert_epi16(((__m128i *)systematic2)[i],((llr_t*)ext)[*pi4_p++],1);
-      ((__m128i *)systematic2)[i]=_mm_insert_epi16(((__m128i *)systematic2)[i],((llr_t*)ext)[*pi4_p++],2);
-      ((__m128i *)systematic2)[i]=_mm_insert_epi16(((__m128i *)systematic2)[i],((llr_t*)ext)[*pi4_p++],3);
-      ((__m128i *)systematic2)[i]=_mm_insert_epi16(((__m128i *)systematic2)[i],((llr_t*)ext)[*pi4_p++],4);
-      ((__m128i *)systematic2)[i]=_mm_insert_epi16(((__m128i *)systematic2)[i],((llr_t*)ext)[*pi4_p++],5);
-      ((__m128i *)systematic2)[i]=_mm_insert_epi16(((__m128i *)systematic2)[i],((llr_t*)ext)[*pi4_p++],6);
-      ((__m128i *)systematic2)[i]=_mm_insert_epi16(((__m128i *)systematic2)[i],((llr_t*)ext)[*pi4_p++],7);
+      ((__m128i *)systematic2)[i]=_mm_insert_epi16(((__m128i *)systematic2)[i],((llr_t *)ext)[*pi4_p++],0);
+      ((__m128i *)systematic2)[i]=_mm_insert_epi16(((__m128i *)systematic2)[i],((llr_t *)ext)[*pi4_p++],1);
+      ((__m128i *)systematic2)[i]=_mm_insert_epi16(((__m128i *)systematic2)[i],((llr_t *)ext)[*pi4_p++],2);
+      ((__m128i *)systematic2)[i]=_mm_insert_epi16(((__m128i *)systematic2)[i],((llr_t *)ext)[*pi4_p++],3);
+      ((__m128i *)systematic2)[i]=_mm_insert_epi16(((__m128i *)systematic2)[i],((llr_t *)ext)[*pi4_p++],4);
+      ((__m128i *)systematic2)[i]=_mm_insert_epi16(((__m128i *)systematic2)[i],((llr_t *)ext)[*pi4_p++],5);
+      ((__m128i *)systematic2)[i]=_mm_insert_epi16(((__m128i *)systematic2)[i],((llr_t *)ext)[*pi4_p++],6);
+      ((__m128i *)systematic2)[i]=_mm_insert_epi16(((__m128i *)systematic2)[i],((llr_t *)ext)[*pi4_p++],7);
     }
 
 #else
-
     pi4_p=pi4tab[iind];
 
     for (i=0; i<(n2>>4); i++) { // steady-state portion
-      tmp=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],0);
-      tmp=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],1);
-      tmp=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],2);
-      tmp=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],3);
-      tmp=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],4);
-      tmp=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],5);
-      tmp=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],6);
-      tmp=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],7);
-      tmp=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],8);
-      tmp=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],9);
-      tmp=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],10);
-      tmp=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],11);
-      tmp=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],12);
-      tmp=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],13);
-      tmp=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],14);
-      ((__m128i *)systematic2)[i]=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],15);
+      tmp=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],0);
+      tmp=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],1);
+      tmp=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],2);
+      tmp=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],3);
+      tmp=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],4);
+      tmp=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],5);
+      tmp=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],6);
+      tmp=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],7);
+      tmp=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],8);
+      tmp=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],9);
+      tmp=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],10);
+      tmp=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],11);
+      tmp=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],12);
+      tmp=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],13);
+      tmp=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],14);
+      ((__m128i *)systematic2)[i]=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],15);
     }
 
 #endif
-
     stop_meas(intl1_stats);
-
     // do log_map from second parity bit
-
     log_map(systematic2,yparity2,m11,m10,alpha,beta,ext2,n2,1,F,offset8_flag,alpha_stats,beta_stats,gamma_stats,ext_stats);
-
-
 #ifndef LLR8
     pi5_p=pi5tab[iind];
 
@@ -2415,7 +2228,7 @@ unsigned char phy_threegpplte_turbo_decoder(short *y,
       tmp=_mm_insert_epi16(tmp,ext2[*pi5_p++],5);
       tmp=_mm_insert_epi16(tmp,ext2[*pi5_p++],6);
       tmp=_mm_insert_epi16(tmp,ext2[*pi5_p++],7);
-      ((__m128i *)systematic1)[i] = _mm_adds_epi16(_mm_subs_epi16(tmp,((__m128i*)ext)[i]),((__m128i *)systematic0)[i]);
+      ((__m128i *)systematic1)[i] = _mm_adds_epi16(_mm_subs_epi16(tmp,((__m128i *)ext)[i]),((__m128i *)systematic0)[i]);
     }
 
     if (iteration_cnt>1) {
@@ -2423,17 +2236,16 @@ unsigned char phy_threegpplte_turbo_decoder(short *y,
       pi6_p=pi6tab[iind];
 
       for (i=0; i<(n2>>3); i++) {
-        tmp=_mm_insert_epi16(tmp, ((llr_t*)ext2)[*pi6_p++],7);
-        tmp=_mm_insert_epi16(tmp, ((llr_t*)ext2)[*pi6_p++],6);
-        tmp=_mm_insert_epi16(tmp, ((llr_t*)ext2)[*pi6_p++],5);
-        tmp=_mm_insert_epi16(tmp, ((llr_t*)ext2)[*pi6_p++],4);
-        tmp=_mm_insert_epi16(tmp, ((llr_t*)ext2)[*pi6_p++],3);
-        tmp=_mm_insert_epi16(tmp, ((llr_t*)ext2)[*pi6_p++],2);
-        tmp=_mm_insert_epi16(tmp, ((llr_t*)ext2)[*pi6_p++],1);
-        tmp=_mm_insert_epi16(tmp, ((llr_t*)ext2)[*pi6_p++],0);
+        tmp=_mm_insert_epi16(tmp, ((llr_t *)ext2)[*pi6_p++],7);
+        tmp=_mm_insert_epi16(tmp, ((llr_t *)ext2)[*pi6_p++],6);
+        tmp=_mm_insert_epi16(tmp, ((llr_t *)ext2)[*pi6_p++],5);
+        tmp=_mm_insert_epi16(tmp, ((llr_t *)ext2)[*pi6_p++],4);
+        tmp=_mm_insert_epi16(tmp, ((llr_t *)ext2)[*pi6_p++],3);
+        tmp=_mm_insert_epi16(tmp, ((llr_t *)ext2)[*pi6_p++],2);
+        tmp=_mm_insert_epi16(tmp, ((llr_t *)ext2)[*pi6_p++],1);
+        tmp=_mm_insert_epi16(tmp, ((llr_t *)ext2)[*pi6_p++],0);
         tmp=_mm_cmpgt_epi8(_mm_packs_epi16(tmp,zeros),zeros);
         decoded_bytes[i]=(unsigned char)_mm_movemask_epi8(tmp);
-
       }
     }
 
@@ -2460,8 +2272,7 @@ unsigned char phy_threegpplte_turbo_decoder(short *y,
       tmp=_mm_insert_epi8(tmp,ext2[*pi5_p++],15);
       //decoded_bytes_interl[i]=(uint16_t) _mm_movemask_epi8(_mm_cmpgt_epi8(tmp,zeros));
       tmp128[i] = _mm_adds_epi8(((__m128i *)ext2)[i],((__m128i *)systematic2)[i]);
-
-      ((__m128i *)systematic1)[i] = _mm_adds_epi8(_mm_subs_epi8(tmp,((__m128i*)ext)[i]),((__m128i *)systematic0)[i]);
+      ((__m128i *)systematic1)[i] = _mm_adds_epi8(_mm_subs_epi8(tmp,((__m128i *)ext)[i]),((__m128i *)systematic0)[i]);
     }
 
     /* LT modification, something wrong here
@@ -2526,41 +2337,40 @@ unsigned char phy_threegpplte_turbo_decoder(short *y,
       oldcrc= *((unsigned int *)(&decoded_bytes[(n>>3)-crc_len]));
 
       switch (crc_type) {
-
-      case CRC24_A:
-        oldcrc&=0x00ffffff;
-        crc = crc24a(&decoded_bytes[F>>3],
-                     n-24-F)>>8;
-        temp=((uint8_t *)&crc)[2];
-        ((uint8_t *)&crc)[2] = ((uint8_t *)&crc)[0];
-        ((uint8_t *)&crc)[0] = temp;
-        break;
-
-      case CRC24_B:
-        oldcrc&=0x00ffffff;
-        crc = crc24b(decoded_bytes,
-                     n-24)>>8;
-        temp=((uint8_t *)&crc)[2];
-        ((uint8_t *)&crc)[2] = ((uint8_t *)&crc)[0];
-        ((uint8_t *)&crc)[0] = temp;
-        break;
-
-      case CRC16:
-        oldcrc&=0x0000ffff;
-        crc = crc16(decoded_bytes,
-                    n-16)>>16;
-        break;
-
-      case CRC8:
-        oldcrc&=0x000000ff;
-        crc = crc8(decoded_bytes,
-                   n-8)>>24;
-        break;
-
-      default:
-        printf("FATAL: 3gpplte_turbo_decoder_sse.c: Unknown CRC\n");
-        return(255);
-        break;
+        case CRC24_A:
+          oldcrc&=0x00ffffff;
+          crc = crc24a(&decoded_bytes[F>>3],
+                       n-24-F)>>8;
+          temp=((uint8_t *)&crc)[2];
+          ((uint8_t *)&crc)[2] = ((uint8_t *)&crc)[0];
+          ((uint8_t *)&crc)[0] = temp;
+          break;
+
+        case CRC24_B:
+          oldcrc&=0x00ffffff;
+          crc = crc24b(decoded_bytes,
+                       n-24)>>8;
+          temp=((uint8_t *)&crc)[2];
+          ((uint8_t *)&crc)[2] = ((uint8_t *)&crc)[0];
+          ((uint8_t *)&crc)[0] = temp;
+          break;
+
+        case CRC16:
+          oldcrc&=0x0000ffff;
+          crc = crc16(decoded_bytes,
+                      n-16)>>16;
+          break;
+
+        case CRC8:
+          oldcrc&=0x000000ff;
+          crc = crc8(decoded_bytes,
+                     n-8)>>24;
+          break;
+
+        default:
+          printf("FATAL: 3gpplte_turbo_decoder_sse.c: Unknown CRC\n");
+          return(255);
+          break;
       }
 
       stop_meas(intl2_stats);
@@ -2573,9 +2383,9 @@ unsigned char phy_threegpplte_turbo_decoder(short *y,
     // do log_map from first parity bit
     if (iteration_cnt < max_iterations) {
       log_map(systematic1,yparity1,m11,m10,alpha,beta,ext,n2,0,F,offset8_flag,alpha_stats,beta_stats,gamma_stats,ext_stats);
-      __m128i* ext_128=(__m128i*) ext;
-      __m128i* s1_128=(__m128i*) systematic1;
-      __m128i* s0_128=(__m128i*) systematic0;
+      __m128i *ext_128=(__m128i *) ext;
+      __m128i *s1_128=(__m128i *) systematic1;
+      __m128i *s0_128=(__m128i *) systematic0;
 #ifndef LLR8
       int myloop=n2>>3;
 
@@ -2601,27 +2411,21 @@ unsigned char phy_threegpplte_turbo_decoder(short *y,
 
 #ifdef TEST_DEBUG
 
-int test_logmap8()
-{
+int test_logmap8() {
   unsigned char test[8];
   //_declspec(align(16))  char channel_output[512];
   //_declspec(align(16))  unsigned char output[512],decoded_output[16], *inPtr, *outPtr;
-
   short channel_output[512];
   unsigned char output[512],decoded_output[16];
   unsigned int i,crc,ret;
-
   test[0] = 7;
   test[1] = 0xa5;
   test[2] = 0x11;
   test[3] = 0x92;
   test[4] = 0xfe;
-
   crc = crc24a(test,
                40)>>8;
-
-  *(unsigned int*)(&test[5]) = crc;
-
+  *(unsigned int *)(&test[5]) = crc;
   printf("crc24 = %x\n",crc);
   threegpplte_turbo_encoder(test,   //input
                             8,      //input length bytes
@@ -2646,20 +2450,15 @@ int test_logmap8()
                                       0,        // filler bits
                                       0);       // decoder instance
 
-
   for (i=0; i<8; i++)
-    printf("output %d => %x (input %x)\n",i,decoded_output[i],test[i]);
+    printf("output %u => %x (input %x)\n",i,decoded_output[i],test[i]);
 }
 
 
 
 
-int main()
-{
-
-
+int main() {
   test_logmap8();
-
   return(0);
 }
 
diff --git a/openair1/PHY/CODING/3gpplte_turbo_decoder_sse_16bit.c b/openair1/PHY/CODING/3gpplte_turbo_decoder_sse_16bit.c
index a25ba46ff8e40cd777cdaaed6e40e9eb25d4456c..50fae438b7629e24bd1e74d11f2b1f7d721fff59 100644
--- a/openair1/PHY/CODING/3gpplte_turbo_decoder_sse_16bit.c
+++ b/openair1/PHY/CODING/3gpplte_turbo_decoder_sse_16bit.c
@@ -41,53 +41,53 @@
 #include "PHY/sse_intrin.h"
 
 #ifndef TEST_DEBUG
-#include "PHY/impl_defs_top.h"
-#include "PHY/defs_common.h"
-#include "PHY/CODING/coding_defs.h"
-#include "PHY/CODING/lte_interleaver_inline.h"
+  #include "PHY/impl_defs_top.h"
+  #include "PHY/defs_common.h"
+  #include "PHY/CODING/coding_defs.h"
+  #include "PHY/CODING/lte_interleaver_inline.h"
 #else
 
-#include "defs.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+  #include "defs.h"
+  #include <stdio.h>
+  #include <stdlib.h>
+  #include <string.h>
 #endif
 
 #ifdef MEX
-#include "mex.h"
+  #include "mex.h"
 #endif
 
 //#define DEBUG_LOGMAP
 
 #ifdef DEBUG_LOGMAP
-#define print_shorts(s,x) fprintf(fdsse4,"%s %d,%d,%d,%d,%d,%d,%d,%d\n",s,(x)[0],(x)[1],(x)[2],(x)[3],(x)[4],(x)[5],(x)[6],(x)[7])
+  #define print_shorts(s,x) fprintf(fdsse4,"%s %d,%d,%d,%d,%d,%d,%d,%d\n",s,(x)[0],(x)[1],(x)[2],(x)[3],(x)[4],(x)[5],(x)[6],(x)[7])
 #endif
 
 #undef __AVX2__
 
 #ifdef DEBUG_LOGMAP
-FILE *fdsse4;
+  FILE *fdsse4;
 #endif
 
 typedef int16_t llr_t; // internal decoder LLR data is 16-bit fixed
 typedef int16_t channel_t;
 #define MAX 256
 
-void log_map16(llr_t* systematic,channel_t* y_parity, llr_t* m11, llr_t* m10, llr_t *alpha, llr_t *beta, llr_t* ext,unsigned short frame_length,unsigned char term_flag,unsigned char F,
+void log_map16(llr_t *systematic,channel_t *y_parity, llr_t *m11, llr_t *m10, llr_t *alpha, llr_t *beta, llr_t *ext,unsigned short frame_length,unsigned char term_flag,unsigned char F,
                int offset8_flag,time_stats_t *alpha_stats,time_stats_t *beta_stats,time_stats_t *gamma_stats,time_stats_t *ext_stats);
-void compute_gamma16(llr_t* m11,llr_t* m10,llr_t* systematic, channel_t* y_parity, unsigned short frame_length,unsigned char term_flag);
-void compute_alpha16(llr_t*alpha,llr_t *beta, llr_t* m11,llr_t* m10, unsigned short frame_length,unsigned char F);
-void compute_beta16(llr_t*alpha, llr_t* beta,llr_t* m11,llr_t* m10, unsigned short frame_length,unsigned char F,int offset8_flag);
-void compute_ext16(llr_t* alpha,llr_t* beta,llr_t* m11,llr_t* m10,llr_t* extrinsic, llr_t* ap, unsigned short frame_length);
+void compute_gamma16(llr_t *m11,llr_t *m10,llr_t *systematic, channel_t *y_parity, unsigned short frame_length,unsigned char term_flag);
+void compute_alpha16(llr_t *alpha,llr_t *beta, llr_t *m11,llr_t *m10, unsigned short frame_length,unsigned char F);
+void compute_beta16(llr_t *alpha, llr_t *beta,llr_t *m11,llr_t *m10, unsigned short frame_length,unsigned char F,int offset8_flag);
+void compute_ext16(llr_t *alpha,llr_t *beta,llr_t *m11,llr_t *m10,llr_t *extrinsic, llr_t *ap, unsigned short frame_length);
 
 
-void log_map16(llr_t* systematic,
-               channel_t* y_parity,
-               llr_t* m11,
-               llr_t* m10,
+void log_map16(llr_t *systematic,
+               channel_t *y_parity,
+               llr_t *m11,
+               llr_t *m10,
                llr_t *alpha,
                llr_t *beta,
-               llr_t* ext,
+               llr_t *ext,
                unsigned short frame_length,
                unsigned char term_flag,
                unsigned char F,
@@ -95,13 +95,10 @@ void log_map16(llr_t* systematic,
                time_stats_t *alpha_stats,
                time_stats_t *beta_stats,
                time_stats_t *gamma_stats,
-               time_stats_t *ext_stats)
-{
-
+               time_stats_t *ext_stats) {
 #ifdef DEBUG_LOGMAP
   fprintf(fdsse4,"log_map, frame_length %d\n",frame_length);
 #endif
-
   start_meas(gamma_stats) ;
   compute_gamma16(m11,m10,systematic,y_parity,frame_length,term_flag) ;
   stop_meas(gamma_stats);
@@ -114,13 +111,10 @@ void log_map16(llr_t* systematic,
   start_meas(ext_stats)   ;
   compute_ext16(alpha,beta,m11,m10,ext,systematic,frame_length)       ;
   stop_meas(ext_stats);
-
-
 }
 
-void compute_gamma16(llr_t* m11,llr_t* m10,llr_t* systematic,channel_t* y_parity,
-                     unsigned short frame_length,unsigned char term_flag)
-{
+void compute_gamma16(llr_t *m11,llr_t *m10,llr_t *systematic,channel_t *y_parity,
+                     unsigned short frame_length,unsigned char term_flag) {
   int k,K1;
 #if defined(__x86_64__)||defined(__i386__)
   __m128i *systematic128 = (__m128i *)systematic;
@@ -133,18 +127,18 @@ void compute_gamma16(llr_t* m11,llr_t* m10,llr_t* systematic,channel_t* y_parity
   int16x8_t *m10_128        = (int16x8_t *)m10;
   int16x8_t *m11_128        = (int16x8_t *)m11;
 #endif
-
 #ifdef DEBUG_LOGMAP
   fprintf(fdsse4,"compute_gamma (sse_16bit), %p,%p,%p,%p,framelength %d\n",m11,m10,systematic,y_parity,frame_length);
 #endif
-
 #ifndef __AVX2__
   K1=frame_length>>3;
 #else
+
   if ((frame_length&15) > 0)
     K1=(frame_length+1)>>4;
   else
     K1=frame_length>>4;
+
 #endif
 
   for (k=0; k<K1; k++) {
@@ -153,21 +147,20 @@ void compute_gamma16(llr_t* m11,llr_t* m10,llr_t* systematic,channel_t* y_parity
     m11_128[k] = _mm_srai_epi16(_mm_adds_epi16(systematic128[k],y_parity128[k]),1);
     m10_128[k] = _mm_srai_epi16(_mm_subs_epi16(systematic128[k],y_parity128[k]),1);
 #else
-    ((__m256i*)m11_128)[k] = _mm256_srai_epi16(_mm256_adds_epi16(((__m256i*)systematic128)[k],((__m256i*)y_parity128)[k]),1);
+    ((__m256i *)m11_128)[k] = _mm256_srai_epi16(_mm256_adds_epi16(((__m256i *)systematic128)[k],((__m256i *)y_parity128)[k]),1);
     //    ((__m256i*)m10_128)[k] = _mm256_srai_epi16(_mm256_subs_epi16(((__m256i*)y_parity128)[k],((__m256i*)systematic128)[k]),1);
-    ((__m256i*)m10_128)[k] = _mm256_srai_epi16(_mm256_subs_epi16(((__m256i*)systematic128)[k],((__m256i*)y_parity128)[k]),1);
+    ((__m256i *)m10_128)[k] = _mm256_srai_epi16(_mm256_subs_epi16(((__m256i *)systematic128)[k],((__m256i *)y_parity128)[k]),1);
 #endif
 #elif defined(__arm__)
     m11_128[k] = vhaddq_s16(systematic128[k],y_parity128[k]);
     m10_128[k] = vhsubq_s16(systematic128[k],y_parity128[k]);
 #endif
-
 #ifdef DEBUG_LOGMAP
     fprintf(fdsse4,"Loop index k %d\n", k);
-    print_shorts("sys",(int16_t*)&systematic128[k]);
-    print_shorts("yp",(int16_t*)&y_parity128[k]);
-    print_shorts("m11",(int16_t*)&m11_128[k]);
-    print_shorts("m10",(int16_t*)&m10_128[k]);
+    print_shorts("sys",(int16_t *)&systematic128[k]);
+    print_shorts("yp",(int16_t *)&y_parity128[k]);
+    print_shorts("m11",(int16_t *)&m11_128[k]);
+    print_shorts("m10",(int16_t *)&m10_128[k]);
 #endif
   }
 
@@ -185,20 +178,18 @@ void compute_gamma16(llr_t* m11,llr_t* m10,llr_t* systematic,channel_t* y_parity
   m11_128[k] = vhaddq_s16(systematic128[k+term_flag],y_parity128[k]);
   m10_128[k] = vhsubq_s16(systematic128[k+term_flag],y_parity128[k]);
 #endif
-
 #ifdef DEBUG_LOGMAP
-fprintf(fdsse4,"Loop index k %d (term flag %d)\n", k,term_flag);
-print_shorts("sys",(int16_t*)&systematic128[k]);
-    print_shorts("yp",(int16_t*)&y_parity128[k]);
-    print_shorts("m11",(int16_t*)&m11_128[k]);
-    print_shorts("m10",(int16_t*)&m10_128[k]);
+  fprintf(fdsse4,"Loop index k %d (term flag %d)\n", k,term_flag);
+  print_shorts("sys",(int16_t *)&systematic128[k]);
+  print_shorts("yp",(int16_t *)&y_parity128[k]);
+  print_shorts("m11",(int16_t *)&m11_128[k]);
+  print_shorts("m10",(int16_t *)&m10_128[k]);
 #endif
 }
 
 #define L 40
 
-void compute_alpha16(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned short frame_length,unsigned char F)
-{
+void compute_alpha16(llr_t *alpha,llr_t *beta,llr_t *m_11,llr_t *m_10,unsigned short frame_length,unsigned char F) {
   int k,l,l2,K1,rerun_flag=0;
 #if defined(__x86_64__) || defined(__i386__)
   __m128i *alpha128=(__m128i *)alpha,*alpha_ptr,*m11p,*m10p;
@@ -215,7 +206,6 @@ void compute_alpha16(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned s
   __m256i m11m10_256;
   __m256i alpha_max;
 #endif
-
 #elif defined(__arm__)
   int16x8_t *alpha128=(int16x8_t *)alpha,*alpha_ptr;
   int16x8_t a0,a1,a2,a3,a4,a5,a6,a7,*m11p,*m10p;
@@ -228,6 +218,7 @@ void compute_alpha16(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned s
 #ifdef DEBUG_LOGMAP
   fprintf(fdsse4,"compute_alpha (sse_16bit)\n");
 #endif
+
   for (l=K1;; l=l2,rerun_flag=1) {
 #if defined(__x86_64__) || defined(__i386__)
     alpha128 = (__m128i *)alpha;
@@ -259,14 +250,14 @@ void compute_alpha16(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned s
 #endif
 #ifdef DEBUG_LOGMAP
       fprintf(fdsse4,"Initial alpha\n");
-      print_shorts("a0",(int16_t*)&alpha128[0]);
-      print_shorts("a1",(int16_t*)&alpha128[1]);
-      print_shorts("a2",(int16_t*)&alpha128[2]);
-      print_shorts("a3",(int16_t*)&alpha128[3]);
-      print_shorts("a4",(int16_t*)&alpha128[4]);
-      print_shorts("a5",(int16_t*)&alpha128[5]);
-      print_shorts("a6",(int16_t*)&alpha128[6]);
-      print_shorts("a7",(int16_t*)&alpha128[7]);
+      print_shorts("a0",(int16_t *)&alpha128[0]);
+      print_shorts("a1",(int16_t *)&alpha128[1]);
+      print_shorts("a2",(int16_t *)&alpha128[2]);
+      print_shorts("a3",(int16_t *)&alpha128[3]);
+      print_shorts("a4",(int16_t *)&alpha128[4]);
+      print_shorts("a5",(int16_t *)&alpha128[5]);
+      print_shorts("a6",(int16_t *)&alpha128[6]);
+      print_shorts("a7",(int16_t *)&alpha128[7]);
 #endif
     } else {
       //set initial alpha in columns 1-7 from final alpha from last run in columns 0-6
@@ -280,14 +271,22 @@ void compute_alpha16(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned s
       alpha128[6] = _mm_slli_si128(alpha128[6+frame_length],2);
       alpha128[7] = _mm_slli_si128(alpha128[7+frame_length],2);
 #elif defined(__arm__)
-      alpha128[0] = (int16x8_t)vshlq_n_s64((int64x2_t)alpha128[frame_length],16);   alpha128[0] = vsetq_lane_s16(alpha[8],alpha128[0],3);
-      alpha128[1] = (int16x8_t)vshlq_n_s64((int64x2_t)alpha128[1+frame_length],16); alpha128[1] = vsetq_lane_s16(alpha[24],alpha128[0],3);
-      alpha128[2] = (int16x8_t)vshlq_n_s64((int64x2_t)alpha128[2+frame_length],16); alpha128[2] = vsetq_lane_s16(alpha[40],alpha128[0],3);
-      alpha128[3] = (int16x8_t)vshlq_n_s64((int64x2_t)alpha128[3+frame_length],16); alpha128[3] = vsetq_lane_s16(alpha[56],alpha128[0],3);
-      alpha128[4] = (int16x8_t)vshlq_n_s64((int64x2_t)alpha128[4+frame_length],16); alpha128[4] = vsetq_lane_s16(alpha[72],alpha128[0],3);
-      alpha128[5] = (int16x8_t)vshlq_n_s64((int64x2_t)alpha128[5+frame_length],16); alpha128[5] = vsetq_lane_s16(alpha[88],alpha128[0],3);
-      alpha128[6] = (int16x8_t)vshlq_n_s64((int64x2_t)alpha128[6+frame_length],16); alpha128[6] = vsetq_lane_s16(alpha[104],alpha128[0],3);
-      alpha128[7] = (int16x8_t)vshlq_n_s64((int64x2_t)alpha128[7+frame_length],16); alpha128[7] = vsetq_lane_s16(alpha[120],alpha128[0],3);
+      alpha128[0] = (int16x8_t)vshlq_n_s64((int64x2_t)alpha128[frame_length],16);
+      alpha128[0] = vsetq_lane_s16(alpha[8],alpha128[0],3);
+      alpha128[1] = (int16x8_t)vshlq_n_s64((int64x2_t)alpha128[1+frame_length],16);
+      alpha128[1] = vsetq_lane_s16(alpha[24],alpha128[0],3);
+      alpha128[2] = (int16x8_t)vshlq_n_s64((int64x2_t)alpha128[2+frame_length],16);
+      alpha128[2] = vsetq_lane_s16(alpha[40],alpha128[0],3);
+      alpha128[3] = (int16x8_t)vshlq_n_s64((int64x2_t)alpha128[3+frame_length],16);
+      alpha128[3] = vsetq_lane_s16(alpha[56],alpha128[0],3);
+      alpha128[4] = (int16x8_t)vshlq_n_s64((int64x2_t)alpha128[4+frame_length],16);
+      alpha128[4] = vsetq_lane_s16(alpha[72],alpha128[0],3);
+      alpha128[5] = (int16x8_t)vshlq_n_s64((int64x2_t)alpha128[5+frame_length],16);
+      alpha128[5] = vsetq_lane_s16(alpha[88],alpha128[0],3);
+      alpha128[6] = (int16x8_t)vshlq_n_s64((int64x2_t)alpha128[6+frame_length],16);
+      alpha128[6] = vsetq_lane_s16(alpha[104],alpha128[0],3);
+      alpha128[7] = (int16x8_t)vshlq_n_s64((int64x2_t)alpha128[7+frame_length],16);
+      alpha128[7] = vsetq_lane_s16(alpha[120],alpha128[0],3);
 #endif
       // set initial alpha in column 0 to (0,-MAX/2,...,-MAX/2)
       alpha[8] = -MAX/2;
@@ -299,31 +298,30 @@ void compute_alpha16(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned s
       alpha[56] = -MAX/2;
 #ifdef DEBUG_LOGMAP
       fprintf(fdsse4,"Second run\n");
-      print_shorts("a0",(int16_t*)&alpha128[0]);
-      print_shorts("a1",(int16_t*)&alpha128[1]);
-      print_shorts("a2",(int16_t*)&alpha128[2]);
-      print_shorts("a3",(int16_t*)&alpha128[3]);
-      print_shorts("a4",(int16_t*)&alpha128[4]);
-      print_shorts("a5",(int16_t*)&alpha128[5]);
-      print_shorts("a6",(int16_t*)&alpha128[6]);
-      print_shorts("a7",(int16_t*)&alpha128[7]);
+      print_shorts("a0",(int16_t *)&alpha128[0]);
+      print_shorts("a1",(int16_t *)&alpha128[1]);
+      print_shorts("a2",(int16_t *)&alpha128[2]);
+      print_shorts("a3",(int16_t *)&alpha128[3]);
+      print_shorts("a4",(int16_t *)&alpha128[4]);
+      print_shorts("a5",(int16_t *)&alpha128[5]);
+      print_shorts("a6",(int16_t *)&alpha128[6]);
+      print_shorts("a7",(int16_t *)&alpha128[7]);
 #endif
-
     }
 
     alpha_ptr = &alpha128[0];
     //#ifdef __AVX2__
 #if defined(__x86_64__) || defined(__i386__)
-    m11p = (__m128i*)m_11;
-    m10p = (__m128i*)m_10;
+    m11p = (__m128i *)m_11;
+    m10p = (__m128i *)m_10;
 #elif defined(__arm__)
-    m11p = (int16x8_t*)m_11;
-    m10p = (int16x8_t*)m_10;
+    m11p = (int16x8_t *)m_11;
+    m10p = (int16x8_t *)m_10;
 #endif
+
     for (k=0;
          k<l;
          k++) {
-
 #if defined(__x86_64__) || defined(__i386__)
       //#ifndef __AVX2__
 #if 1
@@ -331,7 +329,6 @@ void compute_alpha16(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned s
       a3=_mm_load_si128(&alpha_ptr[3]);
       a5=_mm_load_si128(&alpha_ptr[5]);
       a7=_mm_load_si128(&alpha_ptr[7]);
-
       m_b0 = _mm_adds_epi16(a1,*m11p);  // m11
       m_b4 = _mm_subs_epi16(a1,*m11p);  // m00=-m11
       m_b1 = _mm_subs_epi16(a3,*m10p);  // m01=-m10
@@ -340,12 +337,10 @@ void compute_alpha16(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned s
       m_b6 = _mm_subs_epi16(a5,*m10p);  // m01=-m10
       m_b3 = _mm_subs_epi16(a7,*m11p);  // m00=-m11
       m_b7 = _mm_adds_epi16(a7,*m11p);  // m11
-
       a0=_mm_load_si128(&alpha_ptr[0]);
       a2=_mm_load_si128(&alpha_ptr[2]);
       a4=_mm_load_si128(&alpha_ptr[4]);
       a6=_mm_load_si128(&alpha_ptr[6]);
-
       new0 = _mm_subs_epi16(a0,*m11p);  // m00=-m11
       new4 = _mm_adds_epi16(a0,*m11p);  // m11
       new1 = _mm_adds_epi16(a2,*m10p);  // m10
@@ -354,7 +349,6 @@ void compute_alpha16(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned s
       new6 = _mm_adds_epi16(a4,*m10p);  // m10
       new3 = _mm_adds_epi16(a6,*m11p);  // m11
       new7 = _mm_subs_epi16(a6,*m11p);  // m00=-m11
-
       a0 = _mm_max_epi16(m_b0,new0);
       a1 = _mm_max_epi16(m_b1,new1);
       a2 = _mm_max_epi16(m_b2,new2);
@@ -363,7 +357,6 @@ void compute_alpha16(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned s
       a5 = _mm_max_epi16(m_b5,new5);
       a6 = _mm_max_epi16(m_b6,new6);
       a7 = _mm_max_epi16(m_b7,new7);
-
       alpha_max = _mm_max_epi16(a0,a1);
       alpha_max = _mm_max_epi16(alpha_max,a2);
       alpha_max = _mm_max_epi16(alpha_max,a3);
@@ -378,29 +371,22 @@ void compute_alpha16(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned s
       a75=_mm256_load_si256(&alpha_ptr256[3]);
       m11m10_256 = _mm256_insertf128_si256(m11m10_256,*m11p,0);
       m11m10_256 = _mm256_insertf128_si256(m11m10_256,*m10p,1);
-
-
       m_b01 = _mm256_adds_epi16(a13,m11m10_256); //negative m10
       m_b23 = _mm256_subs_epi16(a75,m11m10_256); //negative m10
       m_b45 = _mm256_subs_epi16(a13,m11m10_256); //negative m10
       m_b67 = _mm256_adds_epi16(a75,m11m10_256); //negative m10
-
       new01 = _mm256_subs_epi16(a02,m11m10_256);  //negative m10
       new23 = _mm256_adds_epi16(a64,m11m10_256);  //negative m10
       new45 = _mm256_adds_epi16(a02,m11m10_256);  //negative m10
       new67 = _mm256_subs_epi16(a64,m11m10_256);  //negative m10
-
       a01   = _mm256_max_epi16(m_b01,new01);
       a23   = _mm256_max_epi16(m_b23,new23);
       a45   = _mm256_max_epi16(m_b45,new45);
       a67   = _mm256_max_epi16(m_b67,new67);
-
       alpha_max = _mm256_max_epi16(a01,a23);
       alpha_max = _mm256_max_epi16(alpha_max,a45);
       alpha_max = _mm256_max_epi16(alpha_max,a67);
       alpha_max = _mm256_max_epi16(alpha_max,_mm256_permutevar8x32_epi32(alpha_max,_mm256_set_epi32(3,2,1,0,7,6,5,4)));
-      
-      
 #endif
 #elif defined(__arm__)
       m_b0 = vqaddq_s16(alpha_ptr[1],*m11p);  // m11
@@ -411,7 +397,6 @@ void compute_alpha16(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned s
       m_b6 = vqsubq_s16(alpha_ptr[5],*m10p);  // m01=-m10
       m_b3 = vqsubq_s16(alpha_ptr[7],*m11p);  // m00=-m11
       m_b7 = vqaddq_s16(alpha_ptr[7],*m11p);  // m11
-
       new0 = vqsubq_s16(alpha_ptr[0],*m11p);  // m00=-m11
       new4 = vqaddq_s16(alpha_ptr[0],*m11p);  // m11
       new1 = vqaddq_s16(alpha_ptr[2],*m10p);  // m10
@@ -428,7 +413,6 @@ void compute_alpha16(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned s
       a5 = vmaxq_s16(m_b5,new5);
       a6 = vmaxq_s16(m_b6,new6);
       a7 = vmaxq_s16(m_b7,new7);
-
       // compute and subtract maxima
       alpha_max = vmaxq_s16(a0,a1);
       alpha_max = vmaxq_s16(alpha_max,a2);
@@ -437,9 +421,7 @@ void compute_alpha16(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned s
       alpha_max = vmaxq_s16(alpha_max,a5);
       alpha_max = vmaxq_s16(alpha_max,a6);
       alpha_max = vmaxq_s16(alpha_max,a7);
-
 #endif
-
       alpha_ptr+=8;
       //#ifdef __AVX2__
       m11p++;
@@ -456,12 +438,10 @@ void compute_alpha16(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned s
       alpha_ptr[6] = _mm_subs_epi16(a6,alpha_max);
       alpha_ptr[7] = _mm_subs_epi16(a7,alpha_max);
 #else
-
       a01   = _mm256_subs_epi16(a01,alpha_max);
       a23   = _mm256_subs_epi16(a23,alpha_max);
       a45   = _mm256_subs_epi16(a45,alpha_max);
       a67   = _mm256_subs_epi16(a67,alpha_max);
-
       alpha_ptr256[0] = _mm256_permute2x128_si256(a01,a23,0x20);  //a02
       alpha_ptr256[1] = _mm256_permute2x128_si256(a01,a23,0x13);  //a13
       alpha_ptr256[2] = _mm256_permute2x128_si256(a45,a67,0x02);  //a64
@@ -477,49 +457,44 @@ void compute_alpha16(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned s
       alpha_ptr[6] = vqsubq_s16(a6,alpha_max);
       alpha_ptr[7] = vqsubq_s16(a7,alpha_max);
 #endif
-
 #ifdef DEBUG_LOGMAP
       fprintf(fdsse4,"Loop index %d\n",k);
-      print_shorts("mb0",(int16_t*)&m_b0);
-      print_shorts("mb1",(int16_t*)&m_b1);
-      print_shorts("mb2",(int16_t*)&m_b2);
-      print_shorts("mb3",(int16_t*)&m_b3);
-      print_shorts("mb4",(int16_t*)&m_b4);
-      print_shorts("mb5",(int16_t*)&m_b5);
-      print_shorts("mb6",(int16_t*)&m_b6);
-      print_shorts("mb7",(int16_t*)&m_b7);
-
+      print_shorts("mb0",(int16_t *)&m_b0);
+      print_shorts("mb1",(int16_t *)&m_b1);
+      print_shorts("mb2",(int16_t *)&m_b2);
+      print_shorts("mb3",(int16_t *)&m_b3);
+      print_shorts("mb4",(int16_t *)&m_b4);
+      print_shorts("mb5",(int16_t *)&m_b5);
+      print_shorts("mb6",(int16_t *)&m_b6);
+      print_shorts("mb7",(int16_t *)&m_b7);
       fprintf(fdsse4,"Loop index %d, new\n",k);
-      print_shorts("new0",(int16_t*)&new0);
-      print_shorts("new1",(int16_t*)&new1);
-      print_shorts("new2",(int16_t*)&new2);
-      print_shorts("new3",(int16_t*)&new3);
-      print_shorts("new4",(int16_t*)&new4);
-      print_shorts("new5",(int16_t*)&new5);
-      print_shorts("new6",(int16_t*)&new6);
-      print_shorts("new7",(int16_t*)&new7);
-
+      print_shorts("new0",(int16_t *)&new0);
+      print_shorts("new1",(int16_t *)&new1);
+      print_shorts("new2",(int16_t *)&new2);
+      print_shorts("new3",(int16_t *)&new3);
+      print_shorts("new4",(int16_t *)&new4);
+      print_shorts("new5",(int16_t *)&new5);
+      print_shorts("new6",(int16_t *)&new6);
+      print_shorts("new7",(int16_t *)&new7);
       fprintf(fdsse4,"Loop index %d, after max\n",k);
-      print_shorts("a0",(int16_t*)&a0);
-      print_shorts("a1",(int16_t*)&a1);
-      print_shorts("a2",(int16_t*)&a2);
-      print_shorts("a3",(int16_t*)&a3);
-      print_shorts("a4",(int16_t*)&a4);
-      print_shorts("a5",(int16_t*)&a5);
-      print_shorts("a6",(int16_t*)&a6);
-      print_shorts("a7",(int16_t*)&a7);
-
+      print_shorts("a0",(int16_t *)&a0);
+      print_shorts("a1",(int16_t *)&a1);
+      print_shorts("a2",(int16_t *)&a2);
+      print_shorts("a3",(int16_t *)&a3);
+      print_shorts("a4",(int16_t *)&a4);
+      print_shorts("a5",(int16_t *)&a5);
+      print_shorts("a6",(int16_t *)&a6);
+      print_shorts("a7",(int16_t *)&a7);
       fprintf(fdsse4,"Loop index %d\n",k);
-      print_shorts("a0",(int16_t*)&alpha_ptr[0]);
-      print_shorts("a1",(int16_t*)&alpha_ptr[1]);
-      print_shorts("a2",(int16_t*)&alpha_ptr[2]);
-      print_shorts("a3",(int16_t*)&alpha_ptr[3]);
-      print_shorts("a4",(int16_t*)&alpha_ptr[4]);
-      print_shorts("a5",(int16_t*)&alpha_ptr[5]);
-      print_shorts("a6",(int16_t*)&alpha_ptr[6]);
-      print_shorts("a7",(int16_t*)&alpha_ptr[7]);
+      print_shorts("a0",(int16_t *)&alpha_ptr[0]);
+      print_shorts("a1",(int16_t *)&alpha_ptr[1]);
+      print_shorts("a2",(int16_t *)&alpha_ptr[2]);
+      print_shorts("a3",(int16_t *)&alpha_ptr[3]);
+      print_shorts("a4",(int16_t *)&alpha_ptr[4]);
+      print_shorts("a5",(int16_t *)&alpha_ptr[5]);
+      print_shorts("a6",(int16_t *)&alpha_ptr[6]);
+      print_shorts("a7",(int16_t *)&alpha_ptr[7]);
 #endif
-
     }
 
     if (rerun_flag==1)
@@ -528,37 +503,28 @@ void compute_alpha16(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned s
 }
 
 
-void compute_beta16(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned short frame_length,unsigned char F,int offset8_flag)
-{
-
+void compute_beta16(llr_t *alpha,llr_t *beta,llr_t *m_11,llr_t *m_10,unsigned short frame_length,unsigned char F,int offset8_flag) {
   int k,rerun_flag=0;
 #if defined(__x86_64__) || defined(__i386__)
   __m128i m11_128,m10_128;
   __m128i m_b0,m_b1,m_b2,m_b3,m_b4,m_b5,m_b6,m_b7;
   __m128i new0,new1,new2,new3,new4,new5,new6,new7;
-
   __m128i *beta128,*alpha128,*beta_ptr;
   __m128i beta_max;
 #elif defined(__arm__)
   int16x8_t m11_128,m10_128;
   int16x8_t m_b0,m_b1,m_b2,m_b3,m_b4,m_b5,m_b6,m_b7;
   int16x8_t new0,new1,new2,new3,new4,new5,new6,new7;
-
   int16x8_t *beta128,*alpha128,*beta_ptr;
   int16x8_t beta_max;
 #endif
-
   int16_t m11,m10,beta0_16,beta1_16,beta2_16,beta3_16,beta4_16,beta5_16,beta6_16,beta7_16,beta0_2,beta1_2,beta2_2,beta3_2,beta_m;
   llr_t beta0,beta1;
-
 #ifdef DEBUG_LOGMAP
   fprintf(fdsse4,"compute_beta, %p,%p,%p,%p,framelength %d,F %d\n",
-	  beta,m_11,m_10,alpha,frame_length,F);
+          beta,m_11,m_10,alpha,frame_length,F);
 #endif
-
-
   // termination for beta initialization
-
   //  fprintf(fdsse4,"beta init: offset8 %d\n",offset8_flag);
   m11=(int16_t)m_11[2+frame_length];
   //#ifndef __AVX2__
@@ -570,16 +536,13 @@ void compute_beta16(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sh
 #ifdef DEBUG_LOGMAP
   fprintf(fdsse4,"m11,m10 %d,%d\n",m11,m10);
 #endif
-
   beta0 = -m11;//M0T_TERM;
   beta1 = m11;//M1T_TERM;
   m11=(int16_t)m_11[1+frame_length];
   m10=(int16_t)m_10[1+frame_length];
-
 #ifdef DEBUG_LOGMAP
   fprintf(fdsse4,"m11,m10 %d,%d\n",m11,m10);
 #endif
-
   beta0_2 = beta0-m11;//+M0T_TERM;
   beta1_2 = beta0+m11;//+M1T_TERM;
   beta2_2 = beta1+m10;//M2T_TERM;
@@ -597,8 +560,6 @@ void compute_beta16(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sh
   beta5_16 = beta2_2+m10;//+M5T_TERM;
   beta6_16 = beta3_2+m11;//+M6T_TERM;
   beta7_16 = beta3_2-m11;//+M7T_TERM;
-
-
   beta_m = (beta0_16>beta1_16) ? beta0_16 : beta1_16;
   beta_m = (beta_m>beta2_16) ? beta_m : beta2_16;
   beta_m = (beta_m>beta3_16) ? beta_m : beta3_16;
@@ -606,8 +567,6 @@ void compute_beta16(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sh
   beta_m = (beta_m>beta5_16) ? beta_m : beta5_16;
   beta_m = (beta_m>beta6_16) ? beta_m : beta6_16;
   beta_m = (beta_m>beta7_16) ? beta_m : beta7_16;
-
-
   beta0_16=beta0_16-beta_m;
   beta1_16=beta1_16-beta_m;
   beta2_16=beta2_16-beta_m;
@@ -619,12 +578,13 @@ void compute_beta16(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sh
 
   for (rerun_flag=0;; rerun_flag=1) {
 #if defined(__x86_64__) || defined(__i386__)
-    beta_ptr   = (__m128i*)&beta[frame_length<<3];
-    alpha128   = (__m128i*)&alpha[0];
+    beta_ptr   = (__m128i *)&beta[frame_length<<3];
+    alpha128   = (__m128i *)&alpha[0];
 #elif defined(__arm__)
-    beta_ptr   = (int16x8_t*)&beta[frame_length<<3];
-    alpha128   = (int16x8_t*)&alpha[0];
+    beta_ptr   = (int16x8_t *)&beta[frame_length<<3];
+    alpha128   = (int16x8_t *)&alpha[0];
 #endif
+
     if (rerun_flag == 0) {
       beta_ptr[0] = alpha128[(frame_length)];
       beta_ptr[1] = alpha128[1+(frame_length)];
@@ -636,18 +596,18 @@ void compute_beta16(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sh
       beta_ptr[7] = alpha128[7+(frame_length)];
 #ifdef DEBUG_LOGMAP
       fprintf(fdsse4,"beta init \n");
-      print_shorts("b0",(int16_t*)&beta_ptr[0]);
-      print_shorts("b1",(int16_t*)&beta_ptr[1]);
-      print_shorts("b2",(int16_t*)&beta_ptr[2]);
-      print_shorts("b3",(int16_t*)&beta_ptr[3]);
-      print_shorts("b4",(int16_t*)&beta_ptr[4]);
-      print_shorts("b5",(int16_t*)&beta_ptr[5]);
-      print_shorts("b6",(int16_t*)&beta_ptr[6]);
-      print_shorts("b7",(int16_t*)&beta_ptr[7]);
+      print_shorts("b0",(int16_t *)&beta_ptr[0]);
+      print_shorts("b1",(int16_t *)&beta_ptr[1]);
+      print_shorts("b2",(int16_t *)&beta_ptr[2]);
+      print_shorts("b3",(int16_t *)&beta_ptr[3]);
+      print_shorts("b4",(int16_t *)&beta_ptr[4]);
+      print_shorts("b5",(int16_t *)&beta_ptr[5]);
+      print_shorts("b6",(int16_t *)&beta_ptr[6]);
+      print_shorts("b7",(int16_t *)&beta_ptr[7]);
 #endif
     } else {
 #if defined(__x86_64__) || defined(__i386__)
-      beta128 = (__m128i*)&beta[0];
+      beta128 = (__m128i *)&beta[0];
       beta_ptr[0] = _mm_srli_si128(beta128[0],2);
       beta_ptr[1] = _mm_srli_si128(beta128[1],2);
       beta_ptr[2] = _mm_srli_si128(beta128[2],2);
@@ -657,31 +617,38 @@ void compute_beta16(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sh
       beta_ptr[6] = _mm_srli_si128(beta128[6],2);
       beta_ptr[7] = _mm_srli_si128(beta128[7],2);
 #elif defined(__arm__)
-      beta128 = (int16x8_t*)&beta[0];
-      beta_ptr   = (int16x8_t*)&beta[frame_length<<3];
-      beta_ptr[0] = (int16x8_t)vshrq_n_s64((int64x2_t)beta128[0],16);   beta_ptr[0] = vsetq_lane_s16(beta[3],beta_ptr[0],4);
-      beta_ptr[1] = (int16x8_t)vshrq_n_s64((int64x2_t)beta128[1],16);   beta_ptr[1] = vsetq_lane_s16(beta[11],beta_ptr[1],4);
-      beta_ptr[2] = (int16x8_t)vshrq_n_s64((int64x2_t)beta128[2],16);   beta_ptr[2] = vsetq_lane_s16(beta[19],beta_ptr[2],4);
-      beta_ptr[3] = (int16x8_t)vshrq_n_s64((int64x2_t)beta128[3],16);   beta_ptr[3] = vsetq_lane_s16(beta[27],beta_ptr[3],4);
-      beta_ptr[4] = (int16x8_t)vshrq_n_s64((int64x2_t)beta128[4],16);   beta_ptr[4] = vsetq_lane_s16(beta[35],beta_ptr[4],4);
-      beta_ptr[5] = (int16x8_t)vshrq_n_s64((int64x2_t)beta128[5],16);   beta_ptr[5] = vsetq_lane_s16(beta[43],beta_ptr[5],4);
-      beta_ptr[6] = (int16x8_t)vshrq_n_s64((int64x2_t)beta128[6],16);   beta_ptr[6] = vsetq_lane_s16(beta[51],beta_ptr[6],4);
-      beta_ptr[7] = (int16x8_t)vshrq_n_s64((int64x2_t)beta128[7],16);   beta_ptr[7] = vsetq_lane_s16(beta[59],beta_ptr[7],4);
+      beta128 = (int16x8_t *)&beta[0];
+      beta_ptr   = (int16x8_t *)&beta[frame_length<<3];
+      beta_ptr[0] = (int16x8_t)vshrq_n_s64((int64x2_t)beta128[0],16);
+      beta_ptr[0] = vsetq_lane_s16(beta[3],beta_ptr[0],4);
+      beta_ptr[1] = (int16x8_t)vshrq_n_s64((int64x2_t)beta128[1],16);
+      beta_ptr[1] = vsetq_lane_s16(beta[11],beta_ptr[1],4);
+      beta_ptr[2] = (int16x8_t)vshrq_n_s64((int64x2_t)beta128[2],16);
+      beta_ptr[2] = vsetq_lane_s16(beta[19],beta_ptr[2],4);
+      beta_ptr[3] = (int16x8_t)vshrq_n_s64((int64x2_t)beta128[3],16);
+      beta_ptr[3] = vsetq_lane_s16(beta[27],beta_ptr[3],4);
+      beta_ptr[4] = (int16x8_t)vshrq_n_s64((int64x2_t)beta128[4],16);
+      beta_ptr[4] = vsetq_lane_s16(beta[35],beta_ptr[4],4);
+      beta_ptr[5] = (int16x8_t)vshrq_n_s64((int64x2_t)beta128[5],16);
+      beta_ptr[5] = vsetq_lane_s16(beta[43],beta_ptr[5],4);
+      beta_ptr[6] = (int16x8_t)vshrq_n_s64((int64x2_t)beta128[6],16);
+      beta_ptr[6] = vsetq_lane_s16(beta[51],beta_ptr[6],4);
+      beta_ptr[7] = (int16x8_t)vshrq_n_s64((int64x2_t)beta128[7],16);
+      beta_ptr[7] = vsetq_lane_s16(beta[59],beta_ptr[7],4);
 #endif
 #ifdef DEBUG_LOGMAP
       fprintf(fdsse4,"beta init (second run) \n");
-      print_shorts("b0",(int16_t*)&beta_ptr[0]);
-      print_shorts("b1",(int16_t*)&beta_ptr[1]);
-      print_shorts("b2",(int16_t*)&beta_ptr[2]);
-      print_shorts("b3",(int16_t*)&beta_ptr[3]);
-      print_shorts("b4",(int16_t*)&beta_ptr[4]);
-      print_shorts("b5",(int16_t*)&beta_ptr[5]);
-      print_shorts("b6",(int16_t*)&beta_ptr[6]);
-      print_shorts("b7",(int16_t*)&beta_ptr[7]);
+      print_shorts("b0",(int16_t *)&beta_ptr[0]);
+      print_shorts("b1",(int16_t *)&beta_ptr[1]);
+      print_shorts("b2",(int16_t *)&beta_ptr[2]);
+      print_shorts("b3",(int16_t *)&beta_ptr[3]);
+      print_shorts("b4",(int16_t *)&beta_ptr[4]);
+      print_shorts("b5",(int16_t *)&beta_ptr[5]);
+      print_shorts("b6",(int16_t *)&beta_ptr[6]);
+      print_shorts("b7",(int16_t *)&beta_ptr[7]);
 #endif
     }
 
-
 #if defined(__x86_64__) || defined(__i386__)
     beta_ptr[0] = _mm_insert_epi16(beta_ptr[0],beta0_16,7);
     beta_ptr[1] = _mm_insert_epi16(beta_ptr[1],beta1_16,7);
@@ -701,26 +668,23 @@ void compute_beta16(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sh
     beta_ptr[6] = vsetq_lane_s16(beta6_16,beta_ptr[6],7);
     beta_ptr[7] = vsetq_lane_s16(beta7_16,beta_ptr[7],7);
 #endif
-
 #ifdef DEBUG_LOGMAP
-      fprintf(fdsse4,"beta init (after insert) \n");
-      print_shorts("b0",(int16_t*)&beta_ptr[0]);
-      print_shorts("b1",(int16_t*)&beta_ptr[1]);
-      print_shorts("b2",(int16_t*)&beta_ptr[2]);
-      print_shorts("b3",(int16_t*)&beta_ptr[3]);
-      print_shorts("b4",(int16_t*)&beta_ptr[4]);
-      print_shorts("b5",(int16_t*)&beta_ptr[5]);
-      print_shorts("b6",(int16_t*)&beta_ptr[6]);
-      print_shorts("b7",(int16_t*)&beta_ptr[7]);
+    fprintf(fdsse4,"beta init (after insert) \n");
+    print_shorts("b0",(int16_t *)&beta_ptr[0]);
+    print_shorts("b1",(int16_t *)&beta_ptr[1]);
+    print_shorts("b2",(int16_t *)&beta_ptr[2]);
+    print_shorts("b3",(int16_t *)&beta_ptr[3]);
+    print_shorts("b4",(int16_t *)&beta_ptr[4]);
+    print_shorts("b5",(int16_t *)&beta_ptr[5]);
+    print_shorts("b6",(int16_t *)&beta_ptr[6]);
+    print_shorts("b7",(int16_t *)&beta_ptr[7]);
 #endif
     int loopval=((rerun_flag==0)?0:((frame_length-L)>>3));
 
     for (k=(frame_length>>3)-1; k>=loopval; k--) {
 #if defined(__x86_64__) || defined(__i386__)
-      m11_128=((__m128i*)m_11)[k];
-      m10_128=((__m128i*)m_10)[k];
-
-
+      m11_128=((__m128i *)m_11)[k];
+      m10_128=((__m128i *)m_10)[k];
       //#ifndef __AVX2__
 #if 1
       m_b0 = _mm_adds_epi16(beta_ptr[4],m11_128);  //m11
@@ -731,8 +695,6 @@ void compute_beta16(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sh
       m_b5 = _mm_subs_epi16(beta_ptr[6],m10_128);  //m01
       m_b6 = _mm_subs_epi16(beta_ptr[7],m11_128);  //m00
       m_b7 = _mm_adds_epi16(beta_ptr[7],m11_128);  //m11
-
-
       new0 = _mm_subs_epi16(beta_ptr[0],m11_128);  //m00
       new1 = _mm_adds_epi16(beta_ptr[0],m11_128);  //m11
       new2 = _mm_adds_epi16(beta_ptr[1],m10_128);  //m10
@@ -741,16 +703,13 @@ void compute_beta16(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sh
       new5 = _mm_adds_epi16(beta_ptr[2],m10_128);  //m10
       new6 = _mm_adds_epi16(beta_ptr[3],m11_128);  //m11
       new7 = _mm_subs_epi16(beta_ptr[3],m11_128);  //m00
-
 #else
-      b01=_mm256_load_si256(&((_m256i*)beta_ptr)[0]);
-      b23=_mm256_load_si256(&((_m256i*)beta_ptr)[1]);
-      b45=_mm256_load_si256(&((_m256i*)beta_ptr)[2]);
-      b67=_mm256_load_si256(&((_m256i*)beta_ptr)[3]);
+      b01=_mm256_load_si256(&((_m256i *)beta_ptr)[0]);
+      b23=_mm256_load_si256(&((_m256i *)beta_ptr)[1]);
+      b45=_mm256_load_si256(&((_m256i *)beta_ptr)[2]);
+      b67=_mm256_load_si256(&((_m256i *)beta_ptr)[3]);
       m11m10_256 = _mm256_insertf128_si256(m11m10_256,m11_128,0);
       m11m10_256 = _mm256_insertf128_si256(m11m10_256,m10_128,1);
-
-
       m_b02 = _mm256_adds_epi16(b45,m11m10_256); //negative m10
       m_b13 = _mm256_subs_epi16(b45,m11m10_256); //negative m10
       m_b64 = _mm256_subs_epi16(b67,m11m10_256); //negative m10
@@ -760,9 +719,7 @@ void compute_beta16(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sh
       new64 = _mm256_adds_epi16(b23,m11m10_256);  //negative m10
       new75 = _mm256_subs_epi16(b24,m11m10_256);  //negative m10
 #endif
-
       beta_ptr-=8;
-
       //#ifndef __AVX2__
 #if 1
       beta_ptr[0] = _mm_max_epi16(m_b0,new0);
@@ -773,7 +730,6 @@ void compute_beta16(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sh
       beta_ptr[5] = _mm_max_epi16(m_b5,new5);
       beta_ptr[6] = _mm_max_epi16(m_b6,new6);
       beta_ptr[7] = _mm_max_epi16(m_b7,new7);
-
       beta_max = _mm_max_epi16(beta_ptr[0],beta_ptr[1]);
       beta_max = _mm_max_epi16(beta_max   ,beta_ptr[2]);
       beta_max = _mm_max_epi16(beta_max   ,beta_ptr[3]);
@@ -781,7 +737,6 @@ void compute_beta16(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sh
       beta_max = _mm_max_epi16(beta_max   ,beta_ptr[5]);
       beta_max = _mm_max_epi16(beta_max   ,beta_ptr[6]);
       beta_max = _mm_max_epi16(beta_max   ,beta_ptr[7]);
-
       beta_ptr[0] = _mm_subs_epi16(beta_ptr[0],beta_max);
       beta_ptr[1] = _mm_subs_epi16(beta_ptr[1],beta_max);
       beta_ptr[2] = _mm_subs_epi16(beta_ptr[2],beta_max);
@@ -795,26 +750,22 @@ void compute_beta16(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sh
       b13   = _mm256_max_epi16(m_b13,new13);
       b64   = _mm256_max_epi16(m_b64,new64);
       b75   = _mm256_max_epi16(m_b75,new75);
-      
       beta_max = _mm256_max_epi16(b02,b13);
       beta_max = _mm256_max_epi16(beta_max,b64);
       beta_max = _mm256_max_epi16(beta_max,b75);
       beta_max = _mm256_max_epi16(beta_max,_mm256_permutevar8x32_epi32(betaa_max,_mm256_set_epi32(3,2,1,0,7,6,5,4)));
-
       b02   = _mm256_subs_epi16(b02,beta_max);
       b13   = _mm256_subs_epi16(b13,beta_max);
       b64   = _mm256_subs_epi16(b64,beta_max);
       b75   = _mm256_subs_epi16(b75,beta_max);
-
-      ((_m256i*)beta_ptr)[0]) = _mm256_permute2x128_si256(b02,b13,0x02);  //b01
-      ((_m256i*)beta_ptr)[1]) = _mm256_permute2x128_si256(b02,b13,0x31);  //b23
-      ((_m256i*)beta_ptr)[2]) = _mm256_permute2x128_si256(b64,b75,0x13);  //b45
-      ((_m256i*)beta_ptr)[3]) = _mm256_permute2x128_si256(b64,b75,0x20);  //b67
+      ((_m256i *)beta_ptr)[0]) = _mm256_permute2x128_si256(b02,b13,0x02); //b01
+      ((_m256i *)beta_ptr)[1]) = _mm256_permute2x128_si256(b02,b13,0x31); //b23
+      ((_m256i *)beta_ptr)[2]) = _mm256_permute2x128_si256(b64,b75,0x13); //b45
+      ((_m256i *)beta_ptr)[3]) = _mm256_permute2x128_si256(b64,b75,0x20); //b67
 #endif
-
 #elif defined(__arm__)
-      m11_128=((int16x8_t*)m_11)[k];
-      m10_128=((int16x8_t*)m_10)[k];
+      m11_128=((int16x8_t *)m_11)[k];
+      m10_128=((int16x8_t *)m_10)[k];
       m_b0 = vqaddq_s16(beta_ptr[4],m11_128);  //m11
       m_b1 = vqsubq_s16(beta_ptr[4],m11_128);  //m00
       m_b2 = vqsubq_s16(beta_ptr[5],m10_128);  //m01
@@ -823,7 +774,6 @@ void compute_beta16(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sh
       m_b5 = vqsubq_s16(beta_ptr[6],m10_128);  //m01
       m_b6 = vqsubq_s16(beta_ptr[7],m11_128);  //m00
       m_b7 = vqaddq_s16(beta_ptr[7],m11_128);  //m11
-
       new0 = vqsubq_s16(beta_ptr[0],m11_128);  //m00
       new1 = vqaddq_s16(beta_ptr[0],m11_128);  //m11
       new2 = vqaddq_s16(beta_ptr[1],m10_128);  //m10
@@ -832,9 +782,7 @@ void compute_beta16(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sh
       new5 = vqaddq_s16(beta_ptr[2],m10_128);  //m10
       new6 = vqaddq_s16(beta_ptr[3],m11_128);  //m11
       new7 = vqsubq_s16(beta_ptr[3],m11_128);  //m00
-
       beta_ptr-=8;
-
       beta_ptr[0] = vmaxq_s16(m_b0,new0);
       beta_ptr[1] = vmaxq_s16(m_b1,new1);
       beta_ptr[2] = vmaxq_s16(m_b2,new2);
@@ -843,7 +791,6 @@ void compute_beta16(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sh
       beta_ptr[5] = vmaxq_s16(m_b5,new5);
       beta_ptr[6] = vmaxq_s16(m_b6,new6);
       beta_ptr[7] = vmaxq_s16(m_b7,new7);
-
       beta_max = vmaxq_s16(beta_ptr[0],beta_ptr[1]);
       beta_max = vmaxq_s16(beta_max   ,beta_ptr[2]);
       beta_max = vmaxq_s16(beta_max   ,beta_ptr[3]);
@@ -851,7 +798,6 @@ void compute_beta16(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sh
       beta_max = vmaxq_s16(beta_max   ,beta_ptr[5]);
       beta_max = vmaxq_s16(beta_max   ,beta_ptr[6]);
       beta_max = vmaxq_s16(beta_max   ,beta_ptr[7]);
-
       beta_ptr[0] = vqsubq_s16(beta_ptr[0],beta_max);
       beta_ptr[1] = vqsubq_s16(beta_ptr[1],beta_max);
       beta_ptr[2] = vqsubq_s16(beta_ptr[2],beta_max);
@@ -861,20 +807,18 @@ void compute_beta16(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sh
       beta_ptr[6] = vqsubq_s16(beta_ptr[6],beta_max);
       beta_ptr[7] = vqsubq_s16(beta_ptr[7],beta_max);
 #endif
-
 #ifdef DEBUG_LOGMAP
       fprintf(fdsse4,"Loop index %d, mb\n",k);
       fprintf(fdsse4,"beta init (after max)\n");
-      print_shorts("b0",(int16_t*)&beta_ptr[0]);
-      print_shorts("b1",(int16_t*)&beta_ptr[1]);
-      print_shorts("b2",(int16_t*)&beta_ptr[2]);
-      print_shorts("b3",(int16_t*)&beta_ptr[3]);
-      print_shorts("b4",(int16_t*)&beta_ptr[4]);
-      print_shorts("b5",(int16_t*)&beta_ptr[5]);
-      print_shorts("b6",(int16_t*)&beta_ptr[6]);
-      print_shorts("b7",(int16_t*)&beta_ptr[7]);
+      print_shorts("b0",(int16_t *)&beta_ptr[0]);
+      print_shorts("b1",(int16_t *)&beta_ptr[1]);
+      print_shorts("b2",(int16_t *)&beta_ptr[2]);
+      print_shorts("b3",(int16_t *)&beta_ptr[3]);
+      print_shorts("b4",(int16_t *)&beta_ptr[4]);
+      print_shorts("b5",(int16_t *)&beta_ptr[5]);
+      print_shorts("b6",(int16_t *)&beta_ptr[6]);
+      print_shorts("b7",(int16_t *)&beta_ptr[7]);
 #endif
-
     }
 
     if (rerun_flag==1)
@@ -882,8 +826,7 @@ void compute_beta16(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sh
   }
 }
 
-void compute_ext16(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,llr_t* ext, llr_t* systematic,unsigned short frame_length)
-{
+void compute_ext16(llr_t *alpha,llr_t *beta,llr_t *m_11,llr_t *m_10,llr_t *ext, llr_t *systematic,unsigned short frame_length) {
 #if defined(__x86_64__) || defined(__i386__)
   __m128i *alpha128=(__m128i *)alpha;
   __m128i *beta128=(__m128i *)beta;
@@ -903,28 +846,21 @@ void compute_ext16(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,llr_t* ext,
   int16x8_t m10_1,m10_2,m10_3,m10_4;
   int16x8_t m11_1,m11_2,m11_3,m11_4;
 #endif
-
   int k;
-
   //
   // LLR computation, 8 consequtive bits per loop
   //
-
 #ifdef DEBUG_LOGMAP
   fprintf(fdsse4,"compute_ext (sse_16bit), %p, %p, %p, %p, %p, %p ,framelength %d\n",alpha,beta,m_11,m_10,ext,systematic,frame_length);
 #endif
-
   alpha_ptr = alpha128;
   beta_ptr = &beta128[8];
 
-
   for (k=0; k<(frame_length>>3); k++) {
-
 #if defined(__x86_64__) || defined(__i386__)
-    m11_128        = (__m128i*)&m_11[k<<3];
-    m10_128        = (__m128i*)&m_10[k<<3];
-    ext_128        = (__m128i*)&ext[k<<3];
-
+    m11_128        = (__m128i *)&m_11[k<<3];
+    m10_128        = (__m128i *)&m_10[k<<3];
+    ext_128        = (__m128i *)&ext[k<<3];
     /*
       fprintf(fdsse4,"EXT %03d\n",k);
       print_shorts("a0:",&alpha_ptr[0]);
@@ -944,7 +880,6 @@ void compute_ext16(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,llr_t* ext,
       print_shorts("b6:",&beta_ptr[6]);
       print_shorts("b7:",&beta_ptr[7]);
     */
-
     //#ifndef __AVX2__
 #if 1
     m00_4 = _mm_adds_epi16(alpha_ptr[7],beta_ptr[3]); //ALPHA_BETA_4m00;
@@ -964,31 +899,23 @@ void compute_ext16(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,llr_t* ext,
     m10_1 = _mm_adds_epi16(alpha_ptr[2],beta_ptr[1]); //ALPHA_BETA_1m10;
     m01_1 = _mm_adds_epi16(alpha_ptr[2],beta_ptr[5]); //ALPHA_BETA_1m01;
 #else
-
-
     m00_1 = _mm_adds_epi16(alpha_ptr[0],beta_ptr[0]); //ALPHA_BETA_1m00;
     m10_1 = _mm_adds_epi16(alpha_ptr[2],beta_ptr[1]); //ALPHA_BETA_1m10;
     m11_1 = _mm_adds_epi16(alpha_ptr[0],beta_ptr[4]); //ALPHA_BETA_1m11;
     m01_1 = _mm_adds_epi16(alpha_ptr[2],beta_ptr[5]); //ALPHA_BETA_1m01;
-
     m11_2 = _mm_adds_epi16(alpha_ptr[1],beta_ptr[0]); //ALPHA_BETA_2m11;
     m01_2 = _mm_adds_epi16(alpha_ptr[3],beta_ptr[1]); //ALPHA_BETA_2m01;
     m00_2 = _mm_adds_epi16(alpha_ptr[1],beta_ptr[4]); //ALPHA_BETA_2m00;
     m10_2 = _mm_adds_epi16(alpha_ptr[3],beta_ptr[5]); //ALPHA_BETA_2m10;
-
     m11_3 = _mm_adds_epi16(alpha_ptr[6],beta_ptr[3]); //ALPHA_BETA_3m11;
     m01_3 = _mm_adds_epi16(alpha_ptr[4],beta_ptr[2]); //ALPHA_BETA_3m01;
     m00_3 = _mm_adds_epi16(alpha_ptr[6],beta_ptr[7]); //ALPHA_BETA_3m00;
     m10_3 = _mm_adds_epi16(alpha_ptr[4],beta_ptr[6]); //ALPHA_BETA_3m10;
-
     m00_4 = _mm_adds_epi16(alpha_ptr[7],beta_ptr[3]); //ALPHA_BETA_4m00;
     m10_4 = _mm_adds_epi16(alpha_ptr[5],beta_ptr[2]); //ALPHA_BETA_4m10;
     m11_4 = _mm_adds_epi16(alpha_ptr[7],beta_ptr[7]); //ALPHA_BETA_4m11;
     m01_4 = _mm_adds_epi16(alpha_ptr[5],beta_ptr[6]); //ALPHA_BETA_4m01;
-
-
 #endif
-
     /*
       print_shorts("m11_1:",&m11_1);
       print_shorts("m11_2:",&m11_2);
@@ -1019,36 +946,30 @@ void compute_ext16(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,llr_t* ext,
     m11_1 = _mm_max_epi16(m11_1,m11_2);
     m11_1 = _mm_max_epi16(m11_1,m11_3);
     m11_1 = _mm_max_epi16(m11_1,m11_4);
-
     //      print_shorts("m11_1:",&m11_1);
-
     m01_1 = _mm_subs_epi16(m01_1,*m10_128);
     m00_1 = _mm_subs_epi16(m00_1,*m11_128);
     m10_1 = _mm_adds_epi16(m10_1,*m10_128);
     m11_1 = _mm_adds_epi16(m11_1,*m11_128);
-
     //      print_shorts("m10_1:",&m10_1);
     //      print_shorts("m11_1:",&m11_1);
     m01_1 = _mm_max_epi16(m01_1,m00_1);
     m10_1 = _mm_max_epi16(m10_1,m11_1);
     //      print_shorts("m01_1:",&m01_1);
     //      print_shorts("m10_1:",&m10_1);
-
     *ext_128 = _mm_subs_epi16(m10_1,m01_1);
 #ifdef DEBUG_LOGMAP
     fprintf(fdsse4,"ext %p\n",ext_128);
-    print_shorts("ext:",(int16_t*)ext_128);
-    print_shorts("m11:",(int16_t*)m11_128);
-    print_shorts("m10:",(int16_t*)m10_128);
-    print_shorts("m10_1:",(int16_t*)&m10_1);
-    print_shorts("m01_1:",(int16_t*)&m01_1);
+    print_shorts("ext:",(int16_t *)ext_128);
+    print_shorts("m11:",(int16_t *)m11_128);
+    print_shorts("m10:",(int16_t *)m10_128);
+    print_shorts("m10_1:",(int16_t *)&m10_1);
+    print_shorts("m01_1:",(int16_t *)&m01_1);
 #endif
-
 #elif defined(__arm__)
-    m11_128        = (int16x8_t*)&m_11[k<<3];
-    m10_128        = (int16x8_t*)&m_10[k<<3];
-    ext_128        = (int16x8_t*)&ext[k<<3];
-
+    m11_128        = (int16x8_t *)&m_11[k<<3];
+    m10_128        = (int16x8_t *)&m_10[k<<3];
+    ext_128        = (int16x8_t *)&ext[k<<3];
     m00_4 = vqaddq_s16(alpha_ptr[7],beta_ptr[3]); //ALPHA_BETA_4m00;
     m11_4 = vqaddq_s16(alpha_ptr[7],beta_ptr[7]); //ALPHA_BETA_4m11;
     m00_3 = vqaddq_s16(alpha_ptr[6],beta_ptr[7]); //ALPHA_BETA_3m00;
@@ -1065,7 +986,6 @@ void compute_ext16(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,llr_t* ext,
     m10_2 = vqaddq_s16(alpha_ptr[3],beta_ptr[5]); //ALPHA_BETA_2m10;
     m10_1 = vqaddq_s16(alpha_ptr[2],beta_ptr[1]); //ALPHA_BETA_1m10;
     m01_1 = vqaddq_s16(alpha_ptr[2],beta_ptr[5]); //ALPHA_BETA_1m01;
-
     m01_1 = vmaxq_s16(m01_1,m01_2);
     m01_1 = vmaxq_s16(m01_1,m01_3);
     m01_1 = vmaxq_s16(m01_1,m01_4);
@@ -1078,18 +998,12 @@ void compute_ext16(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,llr_t* ext,
     m11_1 = vmaxq_s16(m11_1,m11_2);
     m11_1 = vmaxq_s16(m11_1,m11_3);
     m11_1 = vmaxq_s16(m11_1,m11_4);
-
-
     m01_1 = vqsubq_s16(m01_1,*m10_128);
     m00_1 = vqsubq_s16(m00_1,*m11_128);
     m10_1 = vqaddq_s16(m10_1,*m10_128);
     m11_1 = vqaddq_s16(m11_1,*m11_128);
-
-
     m01_1 = vmaxq_s16(m01_1,m00_1);
     m10_1 = vmaxq_s16(m10_1,m11_1);
-
-
     *ext_128 = vqsubq_s16(m10_1,m01_1);
 #endif
     alpha_ptr+=8;
@@ -1102,8 +1016,7 @@ void compute_ext16(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,llr_t* ext,
 //int pi2[n],pi3[n+8],pi5[n+8],pi4[n+8],pi6[n+8],
 int *pi2tab16[188],*pi5tab16[188],*pi4tab16[188],*pi6tab16[188];
 
-void free_td16(void)
-{
+void free_td16(void) {
   int ind;
 
   for (ind=0; ind<188; ind++) {
@@ -1114,14 +1027,11 @@ void free_td16(void)
   }
 }
 
-void init_td16(void)
-{
-
+void init_td16(void) {
   int ind,i,i2,i3,j,n,pi,pi3;
-  short * base_interleaver;
+  short *base_interleaver;
 
   for (ind=0; ind<188; ind++) {
-
     n = f1f2mat[ind].nb_bits;
     base_interleaver=il_tb+f1f2mat[ind].beg_index;
 #ifdef MEX
@@ -1141,10 +1051,8 @@ void init_td16(void)
       j=i2;
 
       for (i3=0; i3<(n>>3); i3++,i++,j+=8) {
-
         //    if (j>=n)
         //      j-=(n-1);
-
         pi2tab16[ind][i]  = j;
         //    fprintf(fdsse4,"pi2[%d] = %d\n",i,j);
       }
@@ -1157,71 +1065,59 @@ void init_td16(void)
       pi5tab16[ind][pi3] = pi2tab16[ind][i];
       pi6tab16[ind][pi] = pi2tab16[ind][i];
     }
-
   }
 }
 
 uint8_t phy_threegpplte_turbo_decoder16(int16_t *y,
-                               int16_t *y2,
-                               uint8_t *decoded_bytes,
-                               uint8_t *decoded_bytes2,
-                               uint16_t n,
-                               uint8_t max_iterations,
-                               uint8_t crc_type,
-                               uint8_t F,
-                               time_stats_t *init_stats,
-                               time_stats_t *alpha_stats,
-                               time_stats_t *beta_stats,
-                               time_stats_t *gamma_stats,
-                               time_stats_t *ext_stats,
-                               time_stats_t *intl1_stats,
-                               time_stats_t *intl2_stats) {
-
+                                        int16_t *y2,
+                                        uint8_t *decoded_bytes,
+                                        uint8_t *decoded_bytes2,
+                                        uint16_t n,
+                                        uint8_t max_iterations,
+                                        uint8_t crc_type,
+                                        uint8_t F,
+                                        time_stats_t *init_stats,
+                                        time_stats_t *alpha_stats,
+                                        time_stats_t *beta_stats,
+                                        time_stats_t *gamma_stats,
+                                        time_stats_t *ext_stats,
+                                        time_stats_t *intl1_stats,
+                                        time_stats_t *intl2_stats) {
   /*  y is a pointer to the input
       decoded_bytes is a pointer to the decoded output
       n is the size in bits of the coded block, with the tail */
-
-
   llr_t systematic0[n+16] __attribute__ ((aligned(32)));
   llr_t systematic1[n+16] __attribute__ ((aligned(32)));
   llr_t systematic2[n+16] __attribute__ ((aligned(32)));
   llr_t yparity1[n+16] __attribute__ ((aligned(32)));
   llr_t yparity2[n+16] __attribute__ ((aligned(32)));
-
   llr_t ext[n+128] __attribute__((aligned(32)));
   llr_t ext2[n+128] __attribute__((aligned(32)));
-
   llr_t alpha[(n+16)*8] __attribute__ ((aligned(32)));
   llr_t beta[(n+16)*8] __attribute__ ((aligned(32)));
   llr_t m11[n+32] __attribute__ ((aligned(32)));
   llr_t m10[n+32] __attribute__ ((aligned(32)));
-
-
   int *pi2_p,*pi4_p,*pi5_p,*pi6_p;
   llr_t *s,*s1,*s2,*yp1,*yp2,*yp;
   unsigned int i,j,iind;//,pi;
   unsigned char iteration_cnt=0;
   unsigned int crc,oldcrc,crc_len;
   uint8_t temp;
-
 #if defined(__x86_64__) || defined(__i386__)
   __m128i *yp128;
   __m128i tmp, zeros=_mm_setzero_si128();
   __m128i tmpe;
 #elif defined(__arm__)
   int16x8_t *yp128;
-//  int16x8_t tmp128[(n+8)>>3];
+  //  int16x8_t tmp128[(n+8)>>3];
   int16x8_t tmp, zeros=vdupq_n_s16(0);
-  const uint16_t __attribute__ ((aligned (16))) _Powers[8]= 
-    { 1, 2, 4, 8, 16, 32, 64, 128};
+  const uint16_t __attribute__ ((aligned (16))) _Powers[8]=
+  { 1, 2, 4, 8, 16, 32, 64, 128};
   uint16x8_t Powers= vld1q_u16(_Powers);
 #endif
   int offset8_flag=0;
-
 #ifdef DEBUG_LOGMAP
   fdsse4 = fopen("dump_sse4.txt","w");
-
-
   printf("tc sse4_16 (y) %p\n",y);
 #endif
 
@@ -1230,12 +1126,8 @@ uint8_t phy_threegpplte_turbo_decoder16(int16_t *y,
     return 255;
   }
 
-
-
   start_meas(init_stats);
 
-
-
   for (iind=0; iind < 188 && f1f2mat[iind].nb_bits != n; iind++);
 
   if ( iind == 188 ) {
@@ -1244,50 +1136,41 @@ uint8_t phy_threegpplte_turbo_decoder16(int16_t *y,
   }
 
   switch (crc_type) {
-  case CRC24_A:
-  case CRC24_B:
-    crc_len=3;
-    break;
+    case CRC24_A:
+    case CRC24_B:
+      crc_len=3;
+      break;
 
-  case CRC16:
-    crc_len=2;
-    break;
+    case CRC16:
+      crc_len=2;
+      break;
 
-  case CRC8:
-    crc_len=1;
-    break;
+    case CRC8:
+      crc_len=1;
+      break;
 
-  default:
-    crc_len=3;
+    default:
+      crc_len=3;
   }
 
 #if defined(__x86_64__) || defined(__i386__)
-  yp128 = (__m128i*)y;
+  yp128 = (__m128i *)y;
 #elif defined(__arm__)
-  yp128 = (int16x8_t*)y;
+  yp128 = (int16x8_t *)y;
 #endif
-
-
-
-
   s = systematic0;
   s1 = systematic1;
   s2 = systematic2;
   yp1 = yparity1;
   yp2 = yparity2;
 
-
-
   for (i=0; i<n; i+=8) {
     pi2_p = &pi2tab16[iind][i];
-
     j=pi2_p[0];
-
 #if defined(__x86_64__) || defined(__i386__)
     tmpe = _mm_load_si128(yp128);
     //    fprintf(fdsse4,"yp128 %p\n",yp128);
     //    print_shorts("tmpe",(int16_t *)&tmpe);
-
     s[j]   = _mm_extract_epi16(tmpe,0);
     yp1[j] = _mm_extract_epi16(tmpe,1);
     yp2[j] = _mm_extract_epi16(tmpe,2);
@@ -1295,7 +1178,6 @@ uint8_t phy_threegpplte_turbo_decoder16(int16_t *y,
     fprintf(fdsse4,"init0: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
 #endif
     j=pi2_p[1];
-
     s[j]   = _mm_extract_epi16(tmpe,3);
     yp1[j] = _mm_extract_epi16(tmpe,4);
     yp2[j] = _mm_extract_epi16(tmpe,5);
@@ -1303,7 +1185,6 @@ uint8_t phy_threegpplte_turbo_decoder16(int16_t *y,
     fprintf(fdsse4,"init1: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
 #endif
     j=pi2_p[2];
-
     s[j]   = _mm_extract_epi16(tmpe,6);
     yp1[j] = _mm_extract_epi16(tmpe,7);
     tmpe = _mm_load_si128(&yp128[1]);
@@ -1312,7 +1193,6 @@ uint8_t phy_threegpplte_turbo_decoder16(int16_t *y,
     fprintf(fdsse4,"init2: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
 #endif
     j=pi2_p[3];
-
     s[j]   = _mm_extract_epi16(tmpe,1);
     yp1[j] = _mm_extract_epi16(tmpe,2);
     yp2[j] = _mm_extract_epi16(tmpe,3);
@@ -1320,7 +1200,6 @@ uint8_t phy_threegpplte_turbo_decoder16(int16_t *y,
     fprintf(fdsse4,"init3: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
 #endif
     j=pi2_p[4];
-
     s[j]   = _mm_extract_epi16(tmpe,4);
     yp1[j] = _mm_extract_epi16(tmpe,5);
     yp2[j] = _mm_extract_epi16(tmpe,6);
@@ -1328,7 +1207,6 @@ uint8_t phy_threegpplte_turbo_decoder16(int16_t *y,
     fprintf(fdsse4,"init4: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
 #endif
     j=pi2_p[5];
-
     s[j]   = _mm_extract_epi16(tmpe,7);
     tmpe = _mm_load_si128(&yp128[2]);
     yp1[j] = _mm_extract_epi16(tmpe,0);
@@ -1336,9 +1214,7 @@ uint8_t phy_threegpplte_turbo_decoder16(int16_t *y,
 #ifdef DEBUG_LOGMAP
     fprintf(fdsse4,"init5: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
 #endif
-
     j=pi2_p[6];
-
     s[j]   = _mm_extract_epi16(tmpe,2);
     yp1[j] = _mm_extract_epi16(tmpe,3);
     yp2[j] = _mm_extract_epi16(tmpe,4);
@@ -1346,60 +1222,49 @@ uint8_t phy_threegpplte_turbo_decoder16(int16_t *y,
     fprintf(fdsse4,"init6: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
 #endif
     j=pi2_p[7];
-
     s[j]   = _mm_extract_epi16(tmpe,5);
     yp1[j] = _mm_extract_epi16(tmpe,6);
     yp2[j] = _mm_extract_epi16(tmpe,7);
 #ifdef DEBUG_LOGMAP
     fprintf(fdsse4,"init7: j %d, s[j] %d yp1[j] %d yp2[j] %d\n",j,s[j],yp1[j],yp2[j]);
 #endif
-
 #elif defined(__arm__)
     s[j]   = vgetq_lane_s16(yp128[0],0);
     yp1[j] = vgetq_lane_s16(yp128[0],1);
     yp2[j] = vgetq_lane_s16(yp128[0],2);
-
     j=pi2_p[1];
     s[j]   = vgetq_lane_s16(yp128[0],3);
     yp1[j] = vgetq_lane_s16(yp128[0],4);
     yp2[j] = vgetq_lane_s16(yp128[0],5);
-
     j=pi2_p[2];
     s[j]   = vgetq_lane_s16(yp128[0],6);
     yp1[j] = vgetq_lane_s16(yp128[0],7);
     yp2[j] = vgetq_lane_s16(yp128[1],0);
-
     j=pi2_p[3];
     s[j]   = vgetq_lane_s16(yp128[1],1);
     yp1[j] = vgetq_lane_s16(yp128[1],2);
     yp2[j] = vgetq_lane_s16(yp128[1],3);
-
     j=pi2_p[4];
     s[j]   = vgetq_lane_s16(yp128[1],4);
     yp1[j] = vgetq_lane_s16(yp128[1],5);
     yp2[j] = vgetq_lane_s16(yp128[1],6);
-
     j=pi2_p[5];
     s[j]   = vgetq_lane_s16(yp128[1],7);
     yp1[j] = vgetq_lane_s16(yp128[2],0);
     yp2[j] = vgetq_lane_s16(yp128[2],1);
-
     j=pi2_p[6];
     s[j]   = vgetq_lane_s16(yp128[2],2);
     yp1[j] = vgetq_lane_s16(yp128[2],3);
     yp2[j] = vgetq_lane_s16(yp128[2],4);
-
     j=pi2_p[7];
     s[j]   = vgetq_lane_s16(yp128[2],5);
     yp1[j] = vgetq_lane_s16(yp128[2],6);
     yp2[j] = vgetq_lane_s16(yp128[2],7);
 #endif
     yp128+=3;
-
   }
 
-  yp=(llr_t*)yp128;
-
+  yp=(llr_t *)yp128;
 
   // Termination
   for (i=n; i<n+3; i++) {
@@ -1410,7 +1275,7 @@ uint8_t phy_threegpplte_turbo_decoder16(int16_t *y,
     yp1[i] = *yp;
     yp++;
 #ifdef DEBUG_LOGMAP
-    fprintf(fdsse4,"Term 1 (%d): %d %d\n",i,s[i],yp1[i]);
+    fprintf(fdsse4,"Term 1 (%u): %d %d\n",i,s[i],yp1[i]);
 #endif //DEBUG_LOGMAP
   }
 
@@ -1422,32 +1287,25 @@ uint8_t phy_threegpplte_turbo_decoder16(int16_t *y,
     yp2[i-8] = *yp;
     yp++;
 #ifdef DEBUG_LOGMAP
-    fprintf(fdsse4,"Term 2 (%d): %d %d\n",i-3,s[i],yp2[i-8]);
+    fprintf(fdsse4,"Term 2 (%u): %d %d\n",i-3,s[i],yp2[i-8]);
 #endif //DEBUG_LOGMAP
   }
 
 #ifdef DEBUG_LOGMAP
   fprintf(fdsse4,"\n");
 #endif //DEBUG_LOGMAP
-
   stop_meas(init_stats);
-
   // do log_map from first parity bit
-
   log_map16(systematic0,yparity1,m11,m10,alpha,beta,ext,n,0,F,offset8_flag,alpha_stats,beta_stats,gamma_stats,ext_stats);
 
   while (iteration_cnt++ < max_iterations) {
-
 #ifdef DEBUG_LOGMAP
     fprintf(fdsse4,"\n*******************ITERATION %d (n %d), ext %p\n\n",iteration_cnt,n,ext);
 #endif //DEBUG_LOGMAP
-
     start_meas(intl1_stats);
-
     pi4_p=pi4tab16[iind];
 
     for (i=0; i<(n>>3); i++) { // steady-state portion
-
 #if defined(__x86_64__) || defined(__i386__)
       ((__m128i *)systematic2)[i]=_mm_insert_epi16(((__m128i *)systematic2)[i],ext[*pi4_p++],0);
       ((__m128i *)systematic2)[i]=_mm_insert_epi16(((__m128i *)systematic2)[i],ext[*pi4_p++],1);
@@ -1457,30 +1315,24 @@ uint8_t phy_threegpplte_turbo_decoder16(int16_t *y,
       ((__m128i *)systematic2)[i]=_mm_insert_epi16(((__m128i *)systematic2)[i],ext[*pi4_p++],5);
       ((__m128i *)systematic2)[i]=_mm_insert_epi16(((__m128i *)systematic2)[i],ext[*pi4_p++],6);
       ((__m128i *)systematic2)[i]=_mm_insert_epi16(((__m128i *)systematic2)[i],ext[*pi4_p++],7);
-
 #elif defined(__arm__)
-      ((int16x8_t*)systematic2)[i]=vsetq_lane_s16(ext[*pi4_p++],((int16x8_t*)systematic2)[i],0);
-      ((int16x8_t*)systematic2)[i]=vsetq_lane_s16(ext[*pi4_p++],((int16x8_t*)systematic2)[i],1);
-      ((int16x8_t*)systematic2)[i]=vsetq_lane_s16(ext[*pi4_p++],((int16x8_t*)systematic2)[i],2);
-      ((int16x8_t*)systematic2)[i]=vsetq_lane_s16(ext[*pi4_p++],((int16x8_t*)systematic2)[i],3);
-      ((int16x8_t*)systematic2)[i]=vsetq_lane_s16(ext[*pi4_p++],((int16x8_t*)systematic2)[i],4);
-      ((int16x8_t*)systematic2)[i]=vsetq_lane_s16(ext[*pi4_p++],((int16x8_t*)systematic2)[i],5);
-      ((int16x8_t*)systematic2)[i]=vsetq_lane_s16(ext[*pi4_p++],((int16x8_t*)systematic2)[i],6);
-      ((int16x8_t*)systematic2)[i]=vsetq_lane_s16(ext[*pi4_p++],((int16x8_t*)systematic2)[i],7);
+      ((int16x8_t *)systematic2)[i]=vsetq_lane_s16(ext[*pi4_p++],((int16x8_t *)systematic2)[i],0);
+      ((int16x8_t *)systematic2)[i]=vsetq_lane_s16(ext[*pi4_p++],((int16x8_t *)systematic2)[i],1);
+      ((int16x8_t *)systematic2)[i]=vsetq_lane_s16(ext[*pi4_p++],((int16x8_t *)systematic2)[i],2);
+      ((int16x8_t *)systematic2)[i]=vsetq_lane_s16(ext[*pi4_p++],((int16x8_t *)systematic2)[i],3);
+      ((int16x8_t *)systematic2)[i]=vsetq_lane_s16(ext[*pi4_p++],((int16x8_t *)systematic2)[i],4);
+      ((int16x8_t *)systematic2)[i]=vsetq_lane_s16(ext[*pi4_p++],((int16x8_t *)systematic2)[i],5);
+      ((int16x8_t *)systematic2)[i]=vsetq_lane_s16(ext[*pi4_p++],((int16x8_t *)systematic2)[i],6);
+      ((int16x8_t *)systematic2)[i]=vsetq_lane_s16(ext[*pi4_p++],((int16x8_t *)systematic2)[i],7);
 #endif
 #ifdef DEBUG_LOGMAP
-      print_shorts("syst2",(int16_t*)&((__m128i *)systematic2)[i]);
+      print_shorts("syst2",(int16_t *)&((__m128i *)systematic2)[i]);
 #endif
     }
 
     stop_meas(intl1_stats);
-
     // do log_map from second parity bit
-
     log_map16(systematic2,yparity2,m11,m10,alpha,beta,ext2,n,1,F,offset8_flag,alpha_stats,beta_stats,gamma_stats,ext_stats);
-
-
-
     pi5_p=pi5tab16[iind];
 
     for (i=0; i<(n>>3); i++) {
@@ -1493,20 +1345,20 @@ uint8_t phy_threegpplte_turbo_decoder16(int16_t *y,
       tmp=_mm_insert_epi16(tmp,ext2[*pi5_p++],5);
       tmp=_mm_insert_epi16(tmp,ext2[*pi5_p++],6);
       tmp=_mm_insert_epi16(tmp,ext2[*pi5_p++],7);
-      ((__m128i *)systematic1)[i] = _mm_adds_epi16(_mm_subs_epi16(tmp,((__m128i*)ext)[i]),((__m128i *)systematic0)[i]);
+      ((__m128i *)systematic1)[i] = _mm_adds_epi16(_mm_subs_epi16(tmp,((__m128i *)ext)[i]),((__m128i *)systematic0)[i]);
 #elif defined(__arm__)
-        tmp=vsetq_lane_s16(ext2[*pi5_p++],tmp,0);
-        tmp=vsetq_lane_s16(ext2[*pi5_p++],tmp,1);
-        tmp=vsetq_lane_s16(ext2[*pi5_p++],tmp,2);
-        tmp=vsetq_lane_s16(ext2[*pi5_p++],tmp,3);
-        tmp=vsetq_lane_s16(ext2[*pi5_p++],tmp,4);
-        tmp=vsetq_lane_s16(ext2[*pi5_p++],tmp,5);
-        tmp=vsetq_lane_s16(ext2[*pi5_p++],tmp,6);
-        tmp=vsetq_lane_s16(ext2[*pi5_p++],tmp,7);
-	((int16x8_t *)systematic1)[i] = vqaddq_s16(vqsubq_s16(tmp,((int16x8_t*)ext)[i]),((int16x8_t *)systematic0)[i]);
+      tmp=vsetq_lane_s16(ext2[*pi5_p++],tmp,0);
+      tmp=vsetq_lane_s16(ext2[*pi5_p++],tmp,1);
+      tmp=vsetq_lane_s16(ext2[*pi5_p++],tmp,2);
+      tmp=vsetq_lane_s16(ext2[*pi5_p++],tmp,3);
+      tmp=vsetq_lane_s16(ext2[*pi5_p++],tmp,4);
+      tmp=vsetq_lane_s16(ext2[*pi5_p++],tmp,5);
+      tmp=vsetq_lane_s16(ext2[*pi5_p++],tmp,6);
+      tmp=vsetq_lane_s16(ext2[*pi5_p++],tmp,7);
+      ((int16x8_t *)systematic1)[i] = vqaddq_s16(vqsubq_s16(tmp,((int16x8_t *)ext)[i]),((int16x8_t *)systematic0)[i]);
 #endif
 #ifdef DEBUG_LOGMAP
-	print_shorts("syst1",(int16_t*)&((__m128i *)systematic1)[i]);
+      print_shorts("syst1",(int16_t *)&((__m128i *)systematic1)[i]);
 #endif
     }
 
@@ -1516,16 +1368,16 @@ uint8_t phy_threegpplte_turbo_decoder16(int16_t *y,
 
       for (i=0; i<(n>>3); i++) {
 #if defined(__x86_64__) || defined(__i386__)
-        tmp=_mm_insert_epi16(tmp, ((llr_t*)ext2)[*pi6_p++],7);
-        tmp=_mm_insert_epi16(tmp, ((llr_t*)ext2)[*pi6_p++],6);
-        tmp=_mm_insert_epi16(tmp, ((llr_t*)ext2)[*pi6_p++],5);
-        tmp=_mm_insert_epi16(tmp, ((llr_t*)ext2)[*pi6_p++],4);
-        tmp=_mm_insert_epi16(tmp, ((llr_t*)ext2)[*pi6_p++],3);
-        tmp=_mm_insert_epi16(tmp, ((llr_t*)ext2)[*pi6_p++],2);
-        tmp=_mm_insert_epi16(tmp, ((llr_t*)ext2)[*pi6_p++],1);
-        tmp=_mm_insert_epi16(tmp, ((llr_t*)ext2)[*pi6_p++],0);
+        tmp=_mm_insert_epi16(tmp, ((llr_t *)ext2)[*pi6_p++],7);
+        tmp=_mm_insert_epi16(tmp, ((llr_t *)ext2)[*pi6_p++],6);
+        tmp=_mm_insert_epi16(tmp, ((llr_t *)ext2)[*pi6_p++],5);
+        tmp=_mm_insert_epi16(tmp, ((llr_t *)ext2)[*pi6_p++],4);
+        tmp=_mm_insert_epi16(tmp, ((llr_t *)ext2)[*pi6_p++],3);
+        tmp=_mm_insert_epi16(tmp, ((llr_t *)ext2)[*pi6_p++],2);
+        tmp=_mm_insert_epi16(tmp, ((llr_t *)ext2)[*pi6_p++],1);
+        tmp=_mm_insert_epi16(tmp, ((llr_t *)ext2)[*pi6_p++],0);
 #ifdef DEBUG_LOGMAP
-	print_shorts("tmp",(int16_t*)&tmp);
+        print_shorts("tmp",(int16_t *)&tmp);
 #endif
         tmp=_mm_cmpgt_epi8(_mm_packs_epi16(tmp,zeros),zeros);
         decoded_bytes[i]=(unsigned char)_mm_movemask_epi8(tmp);
@@ -1538,18 +1390,18 @@ uint8_t phy_threegpplte_turbo_decoder16(int16_t *y,
         tmp=vsetq_lane_s16(ext2[*pi6_p++],tmp,2);
         tmp=vsetq_lane_s16(ext2[*pi6_p++],tmp,1);
         tmp=vsetq_lane_s16(ext2[*pi6_p++],tmp,0);
-// This does:
-// [1 2 4 8 16 32 64 128] .* I(ext_i > 0) = 2.^[b0 b1 b2 b3 b4 b5 b6 b7], where bi =I(ext_i > 0)
-// [2^b0 + 2^b1 2^b2 + 2^b3 2^b4 + 2^b5 2^b6 + 2^b7]
-// [2^b0 + 2^b1 + 2^b2 + 2^b3   2^b4 + 2^b5 + 2^b6 + 2^b7] 
-// Mask64 = 2^b0 + 2^b1 + 2^b2 + 2^b3 + 2^b4 + 2^b5 + 2^b6 + 2^b7
-	uint64x2_t Mask   = vpaddlq_u32(vpaddlq_u16(vandq_u16(vcgtq_s16(tmp,zeros), Powers)));
+        // This does:
+        // [1 2 4 8 16 32 64 128] .* I(ext_i > 0) = 2.^[b0 b1 b2 b3 b4 b5 b6 b7], where bi =I(ext_i > 0)
+        // [2^b0 + 2^b1 2^b2 + 2^b3 2^b4 + 2^b5 2^b6 + 2^b7]
+        // [2^b0 + 2^b1 + 2^b2 + 2^b3   2^b4 + 2^b5 + 2^b6 + 2^b7]
+        // Mask64 = 2^b0 + 2^b1 + 2^b2 + 2^b3 + 2^b4 + 2^b5 + 2^b6 + 2^b7
+        uint64x2_t Mask   = vpaddlq_u32(vpaddlq_u16(vandq_u16(vcgtq_s16(tmp,zeros), Powers)));
         uint64x1_t Mask64 = vget_high_u64(Mask)+vget_low_u64(Mask);
         decoded_bytes[i] = (uint8_t)Mask64;
 #endif
 #ifdef DEBUG_LOGMAP
-	print_shorts("tmp",(int16_t*)&tmp);
-	fprintf(fdsse4,"decoded_bytes[%d] %x\n",i,decoded_bytes[i]);
+        print_shorts("tmp",(int16_t *)&tmp);
+        fprintf(fdsse4,"decoded_bytes[%u] %x\n",i,decoded_bytes[i]);
 #endif
       }
     }
@@ -1559,41 +1411,40 @@ uint8_t phy_threegpplte_turbo_decoder16(int16_t *y,
       oldcrc= *((unsigned int *)(&decoded_bytes[(n>>3)-crc_len]));
 
       switch (crc_type) {
-
-      case CRC24_A:
-        oldcrc&=0x00ffffff;
-        crc = crc24a(&decoded_bytes[F>>3],
-                     n-24-F)>>8;
-        temp=((uint8_t *)&crc)[2];
-        ((uint8_t *)&crc)[2] = ((uint8_t *)&crc)[0];
-        ((uint8_t *)&crc)[0] = temp;
-        break;
-
-      case CRC24_B:
-        oldcrc&=0x00ffffff;
-        crc = crc24b(decoded_bytes,
-                     n-24)>>8;
-        temp=((uint8_t *)&crc)[2];
-        ((uint8_t *)&crc)[2] = ((uint8_t *)&crc)[0];
-        ((uint8_t *)&crc)[0] = temp;
-        break;
-
-      case CRC16:
-        oldcrc&=0x0000ffff;
-        crc = crc16(decoded_bytes,
-                    n-16)>>16;
-        break;
-
-      case CRC8:
-        oldcrc&=0x000000ff;
-        crc = crc8(decoded_bytes,
-                   n-8)>>24;
-        break;
-
-      default:
-        printf("FATAL: 3gpplte_turbo_decoder_sse.c: Unknown CRC\n");
-        return(255);
-        break;
+        case CRC24_A:
+          oldcrc&=0x00ffffff;
+          crc = crc24a(&decoded_bytes[F>>3],
+                       n-24-F)>>8;
+          temp=((uint8_t *)&crc)[2];
+          ((uint8_t *)&crc)[2] = ((uint8_t *)&crc)[0];
+          ((uint8_t *)&crc)[0] = temp;
+          break;
+
+        case CRC24_B:
+          oldcrc&=0x00ffffff;
+          crc = crc24b(decoded_bytes,
+                       n-24)>>8;
+          temp=((uint8_t *)&crc)[2];
+          ((uint8_t *)&crc)[2] = ((uint8_t *)&crc)[0];
+          ((uint8_t *)&crc)[0] = temp;
+          break;
+
+        case CRC16:
+          oldcrc&=0x0000ffff;
+          crc = crc16(decoded_bytes,
+                      n-16)>>16;
+          break;
+
+        case CRC8:
+          oldcrc&=0x000000ff;
+          crc = crc8(decoded_bytes,
+                     n-8)>>24;
+          break;
+
+        default:
+          printf("FATAL: 3gpplte_turbo_decoder_sse.c: Unknown CRC\n");
+          return(255);
+          break;
       }
 
       stop_meas(intl2_stats);
@@ -1610,13 +1461,13 @@ uint8_t phy_threegpplte_turbo_decoder16(int16_t *y,
     if (iteration_cnt < max_iterations) {
       log_map16(systematic1,yparity1,m11,m10,alpha,beta,ext,n,0,F,offset8_flag,alpha_stats,beta_stats,gamma_stats,ext_stats);
 #if defined(__x86_64__) || defined(__i386__)
-      __m128i* ext_128=(__m128i*) ext;
-      __m128i* s1_128=(__m128i*) systematic1;
-      __m128i* s0_128=(__m128i*) systematic0;
+      __m128i *ext_128=(__m128i *) ext;
+      __m128i *s1_128=(__m128i *) systematic1;
+      __m128i *s0_128=(__m128i *) systematic0;
 #elif defined(__arm__)
-      int16x8_t* ext_128=(int16x8_t*) ext;
-      int16x8_t* s1_128=(int16x8_t*) systematic1;
-      int16x8_t* s0_128=(int16x8_t*) systematic0;
+      int16x8_t *ext_128=(int16x8_t *) ext;
+      int16x8_t *s1_128=(int16x8_t *) systematic1;
+      int16x8_t *s0_128=(int16x8_t *) systematic0;
 #endif
       int myloop=n>>3;
 
@@ -1630,13 +1481,11 @@ uint8_t phy_threegpplte_turbo_decoder16(int16_t *y,
       }
     }
   }
-	
-  //  fprintf(fdsse4,"crc %x, oldcrc %x\n",crc,oldcrc);
 
+  //  fprintf(fdsse4,"crc %x, oldcrc %x\n",crc,oldcrc);
 #ifdef DEBUG_LOGMAP
-      fclose(fdsse4);
+  fclose(fdsse4);
 #endif
-
 #if defined(__x86_64__) || defined(__i386__)
   _mm_empty();
   _m_empty();
diff --git a/openair1/PHY/CODING/3gpplte_turbo_decoder_sse_8bit.c b/openair1/PHY/CODING/3gpplte_turbo_decoder_sse_8bit.c
index 476e79cacb72289afb2dd17041f41523e49e876d..e1ca906b55baead972e59753fdc04816879a131a 100644
--- a/openair1/PHY/CODING/3gpplte_turbo_decoder_sse_8bit.c
+++ b/openair1/PHY/CODING/3gpplte_turbo_decoder_sse_8bit.c
@@ -39,39 +39,39 @@
 #include "PHY/sse_intrin.h"
 
 #ifndef TEST_DEBUG
-#include "PHY/defs_common.h"
-#include "PHY/CODING/coding_defs.h"
-#include "PHY/CODING/lte_interleaver_inline.h"
+  #include "PHY/defs_common.h"
+  #include "PHY/CODING/coding_defs.h"
+  #include "PHY/CODING/lte_interleaver_inline.h"
 #else
 
-#include "defs.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+  #include "defs.h"
+  #include <stdio.h>
+  #include <stdlib.h>
+  #include <string.h>
 #endif
 
 #ifdef MEX
-#include "mex.h"
+  #include "mex.h"
 #endif
 
 #include "common/ran_context.h"
 
 #define SHUFFLE16(a,b,c,d,e,f,g,h) _mm_set_epi8(h==-1?-1:h*2+1, \
-            h==-1?-1:h*2, \
-            g==-1?-1:g*2+1, \
-            g==-1?-1:g*2, \
-            f==-1?-1:f*2+1, \
-            f==-1?-1:f*2, \
-            e==-1?-1:e*2+1, \
-            e==-1?-1:e*2, \
-            d==-1?-1:d*2+1, \
-            d==-1?-1:d*2, \
-            c==-1?-1:c*2+1, \
-            c==-1?-1:c*2, \
-            b==-1?-1:b*2+1, \
-            b==-1?-1:b*2, \
-            a==-1?-1:a*2+1, \
-            a==-1?-1:a*2);
+    h==-1?-1:h*2, \
+    g==-1?-1:g*2+1, \
+    g==-1?-1:g*2, \
+    f==-1?-1:f*2+1, \
+    f==-1?-1:f*2, \
+    e==-1?-1:e*2+1, \
+    e==-1?-1:e*2, \
+    d==-1?-1:d*2+1, \
+    d==-1?-1:d*2, \
+    c==-1?-1:c*2+1, \
+    c==-1?-1:c*2, \
+    b==-1?-1:b*2+1, \
+    b==-1?-1:b*2, \
+    a==-1?-1:a*2+1, \
+    a==-1?-1:a*2);
 
 
 
@@ -86,32 +86,28 @@ typedef int8_t channel_t;
 #define MAX8 127
 
 
-void log_map8(llr_t* systematic,channel_t* y_parity, llr_t* m11, llr_t* m10, llr_t *alpha, llr_t *beta, llr_t* ext,unsigned short frame_length,unsigned char term_flag,unsigned char F,int offset8_flag,
+void log_map8(llr_t *systematic,channel_t *y_parity, llr_t *m11, llr_t *m10, llr_t *alpha, llr_t *beta, llr_t *ext,unsigned short frame_length,unsigned char term_flag,unsigned char F,int offset8_flag,
               time_stats_t *alpha_stats,time_stats_t *beta_stats,time_stats_t *gamma_stats,time_stats_t *ext_stats);
-void compute_gamma8(llr_t* m11,llr_t* m10,llr_t* systematic, channel_t* y_parity, unsigned short frame_length,unsigned char term_flag);
-void compute_alpha8(llr_t*alpha,llr_t *beta, llr_t* m11,llr_t* m10, unsigned short frame_length,unsigned char F);
-void compute_beta8(llr_t*alpha, llr_t* beta,llr_t* m11,llr_t* m10, unsigned short frame_length,unsigned char F,int offset8_flag);
-void compute_ext8(llr_t* alpha,llr_t* beta,llr_t* m11,llr_t* m10,llr_t* extrinsic, llr_t* ap, unsigned short frame_length);
-
-
-void print_bytes(char *s, int8_t *x)
-{
+void compute_gamma8(llr_t *m11,llr_t *m10,llr_t *systematic, channel_t *y_parity, unsigned short frame_length,unsigned char term_flag);
+void compute_alpha8(llr_t *alpha,llr_t *beta, llr_t *m11,llr_t *m10, unsigned short frame_length,unsigned char F);
+void compute_beta8(llr_t *alpha, llr_t *beta,llr_t *m11,llr_t *m10, unsigned short frame_length,unsigned char F,int offset8_flag);
+void compute_ext8(llr_t *alpha,llr_t *beta,llr_t *m11,llr_t *m10,llr_t *extrinsic, llr_t *ap, unsigned short frame_length);
 
 
+void print_bytes(char *s, int8_t *x) {
   printf("%s  : %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",s,
          x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
          x[8],x[9],x[10],x[11],x[12],x[13],x[14],x[15]);
-
 }
 
 
-void log_map8(llr_t* systematic,
-              channel_t* y_parity,
-              llr_t* m11,
-              llr_t* m10,
+void log_map8(llr_t *systematic,
+              channel_t *y_parity,
+              llr_t *m11,
+              llr_t *m10,
               llr_t *alpha,
               llr_t *beta,
-              llr_t* ext,
+              llr_t *ext,
               unsigned short frame_length,
               unsigned char term_flag,
               unsigned char F,
@@ -119,32 +115,38 @@ void log_map8(llr_t* systematic,
               time_stats_t *alpha_stats,
               time_stats_t *beta_stats,
               time_stats_t *gamma_stats,
-              time_stats_t *ext_stats)
-{
-
+              time_stats_t *ext_stats) {
 #ifdef DEBUG_LOGMAP
   printf("log_map, frame_length %d\n",frame_length);
 #endif
 
   if (gamma_stats) start_meas(gamma_stats) ;
+
   compute_gamma8(m11,m10,systematic,y_parity,frame_length,term_flag) ;
+
   if (gamma_stats) stop_meas(gamma_stats);
+
   if (alpha_stats) start_meas(alpha_stats) ;
+
   compute_alpha8(alpha,beta,m11,m10,frame_length,F)                  ;
+
   if (alpha_stats) stop_meas(alpha_stats);
+
   if (beta_stats) start_meas(beta_stats)  ;
+
   compute_beta8(alpha,beta,m11,m10,frame_length,F,offset8_flag)      ;
+
   if (beta_stats) stop_meas(beta_stats);
+
   if (ext_stats) start_meas(ext_stats)   ;
-  compute_ext8(alpha,beta,m11,m10,ext,systematic,frame_length)       ;
-  if (ext_stats) stop_meas(ext_stats);
 
+  compute_ext8(alpha,beta,m11,m10,ext,systematic,frame_length)       ;
 
+  if (ext_stats) stop_meas(ext_stats);
 }
 
-void compute_gamma8(llr_t* m11,llr_t* m10,llr_t* systematic,channel_t* y_parity,
-                    unsigned short frame_length,unsigned char term_flag)
-{
+void compute_gamma8(llr_t *m11,llr_t *m10,llr_t *systematic,channel_t *y_parity,
+                    unsigned short frame_length,unsigned char term_flag) {
   int k,K1;
 #if defined(__x86_64__)||defined(__i386__)
   __m128i *systematic128 = (__m128i *)systematic;
@@ -157,11 +159,9 @@ void compute_gamma8(llr_t* m11,llr_t* m10,llr_t* systematic,channel_t* y_parity,
   int8x16_t *m10_128        = (int8x16_t *)m10;
   int8x16_t *m11_128        = (int8x16_t *)m11;
 #endif
-
 #ifdef DEBUG_LOGMAP
   printf("compute_gamma, %p,%p,%p,%p,framelength %d\n",m11,m10,systematic,y_parity,frame_length);
 #endif
-
 #if defined(__x86_64__) || defined(__i386__)
   register __m128i sl,sh,ypl,yph; //K128=_mm_set1_epi8(-128);
 #endif
@@ -181,11 +181,9 @@ void compute_gamma8(llr_t* m11,llr_t* m10,llr_t* systematic,channel_t* y_parity,
     m11_128[k] = vhaddq_s8(systematic128[k],y_parity128[k]);
     m10_128[k] = vhsubq_s8(systematic128[k],y_parity128[k]);
 #endif
-
   }
 
   // Termination
-
 #if defined(__x86_64__) || defined(__i386__)
   sl  = _mm_cvtepi8_epi16(systematic128[k+term_flag]);
   sh = _mm_cvtepi8_epi16(_mm_srli_si128(systematic128[k],8));
@@ -199,15 +197,12 @@ void compute_gamma8(llr_t* m11,llr_t* m10,llr_t* systematic,channel_t* y_parity,
   m11_128[k] = vhaddq_s8(systematic128[k+term_flag],y_parity128[k]);
   m10_128[k] = vhsubq_s8(systematic128[k+term_flag],y_parity128[k]);
 #endif
-
 }
 
 #define L 16
 
-void compute_alpha8(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned short frame_length,unsigned char F)
-{
+void compute_alpha8(llr_t *alpha,llr_t *beta,llr_t *m_11,llr_t *m_10,unsigned short frame_length,unsigned char F) {
   int k,loopval,rerun_flag;
-
 #if defined(__x86_64__) || defined(__i386__)
   __m128i *alpha128=(__m128i *)alpha,*alpha_ptr;
   __m128i *m11p,*m10p;
@@ -223,7 +218,6 @@ void compute_alpha8(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned sh
 #endif
   // Set initial state: first colum is known
   // the other columns are unknown, so all states are set to same value
-
 #if defined(__x86_64__) || defined(__i386__)
   alpha128[0] = _mm_set_epi8(-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,0);
   alpha128[1] = _mm_set_epi8(-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2);
@@ -233,12 +227,11 @@ void compute_alpha8(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned sh
   alpha128[5] = _mm_set_epi8(-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2);
   alpha128[6] = _mm_set_epi8(-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2);
   alpha128[7] = _mm_set_epi8(-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2,-MAX8/2);
-  for (loopval=frame_length>>4, rerun_flag=0; rerun_flag<2; loopval=L, rerun_flag++) {
 
+  for (loopval=frame_length>>4, rerun_flag=0; rerun_flag<2; loopval=L, rerun_flag++) {
     alpha_ptr = &alpha128[0];
-
-    m11p = (__m128i*)m_11;
-    m10p = (__m128i*)m_10;
+    m11p = (__m128i *)m_11;
+    m10p = (__m128i *)m_10;
 
     for (k=0;  k<loopval;  k++) {
       m_b0 = _mm_adds_epi8(alpha_ptr[1],*m11p);  // m11
@@ -249,7 +242,6 @@ void compute_alpha8(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned sh
       m_b6 = _mm_subs_epi8(alpha_ptr[5],*m10p);  // m01=-m10
       m_b3 = _mm_subs_epi8(alpha_ptr[7],*m11p);  // m00=-m11
       m_b7 = _mm_adds_epi8(alpha_ptr[7],*m11p);  // m11
-
       new0 = _mm_subs_epi8(alpha_ptr[0],*m11p);  // m00=-m11
       new4 = _mm_adds_epi8(alpha_ptr[0],*m11p);  // m11
       new1 = _mm_adds_epi8(alpha_ptr[2],*m10p);  // m10
@@ -258,7 +250,6 @@ void compute_alpha8(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned sh
       new6 = _mm_adds_epi8(alpha_ptr[4],*m10p);  // m10
       new3 = _mm_adds_epi8(alpha_ptr[6],*m11p);  // m11
       new7 = _mm_subs_epi8(alpha_ptr[6],*m11p);  // m00=-m11
-
       alpha_ptr += 8;
       m11p++;
       m10p++;
@@ -270,7 +261,6 @@ void compute_alpha8(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned sh
       alpha_ptr[5] = _mm_max_epi8(m_b5,new5);
       alpha_ptr[6] = _mm_max_epi8(m_b6,new6);
       alpha_ptr[7] = _mm_max_epi8(m_b7,new7);
-
       // compute and subtract maxima
       alpha_max = _mm_max_epi8(alpha_ptr[0],alpha_ptr[1]);
       alpha_max = _mm_max_epi8(alpha_max,alpha_ptr[2]);
@@ -279,7 +269,6 @@ void compute_alpha8(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned sh
       alpha_max = _mm_max_epi8(alpha_max,alpha_ptr[5]);
       alpha_max = _mm_max_epi8(alpha_max,alpha_ptr[6]);
       alpha_max = _mm_max_epi8(alpha_max,alpha_ptr[7]);
-
       alpha_ptr[0] = _mm_subs_epi8(alpha_ptr[0],alpha_max);
       alpha_ptr[1] = _mm_subs_epi8(alpha_ptr[1],alpha_max);
       alpha_ptr[2] = _mm_subs_epi8(alpha_ptr[2],alpha_max);
@@ -308,8 +297,8 @@ void compute_alpha8(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned sh
     alpha[80] = -MAX8/2;
     alpha[96] = -MAX8/2;
     alpha[112] = -MAX8/2;
-
   }
+
 #elif defined(__arm__)
   alpha128[0] = vdupq_n_s8(-MAX8/2);
   alpha128[0] = vsetq_lane_s8(0,alpha128[0],0);
@@ -320,12 +309,11 @@ void compute_alpha8(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned sh
   alpha128[5] = vdupq_n_s8(-MAX8/2);
   alpha128[6] = vdupq_n_s8(-MAX8/2);
   alpha128[7] = vdupq_n_s8(-MAX8/2);
-  for (loopval=frame_length>>4, rerun_flag=0; rerun_flag<2; loopval=L, rerun_flag++) {
 
+  for (loopval=frame_length>>4, rerun_flag=0; rerun_flag<2; loopval=L, rerun_flag++) {
     alpha_ptr = &alpha128[0];
-
-    m11p = (int8x16_t*)m_11;
-    m10p = (int8x16_t*)m_10;
+    m11p = (int8x16_t *)m_11;
+    m10p = (int8x16_t *)m_10;
 
     for (k=0;  k<loopval;  k++) {
       m_b0 = vqaddq_s8(alpha_ptr[1],*m11p);  // m11
@@ -336,7 +324,6 @@ void compute_alpha8(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned sh
       m_b6 = vqsubq_s8(alpha_ptr[5],*m10p);  // m01=-m10
       m_b3 = vqsubq_s8(alpha_ptr[7],*m11p);  // m00=-m11
       m_b7 = vqaddq_s8(alpha_ptr[7],*m11p);  // m11
-
       new0 = vqsubq_s8(alpha_ptr[0],*m11p);  // m00=-m11
       new4 = vqaddq_s8(alpha_ptr[0],*m11p);  // m11
       new1 = vqaddq_s8(alpha_ptr[2],*m10p);  // m10
@@ -345,7 +332,6 @@ void compute_alpha8(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned sh
       new6 = vqaddq_s8(alpha_ptr[4],*m10p);  // m10
       new3 = vqaddq_s8(alpha_ptr[6],*m11p);  // m11
       new7 = vqsubq_s8(alpha_ptr[6],*m11p);  // m00=-m11
-
       alpha_ptr += 8;
       m11p++;
       m10p++;
@@ -357,7 +343,6 @@ void compute_alpha8(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned sh
       alpha_ptr[5] = vmaxq_s8(m_b5,new5);
       alpha_ptr[6] = vmaxq_s8(m_b6,new6);
       alpha_ptr[7] = vmaxq_s8(m_b7,new7);
-
       // compute and subtract maxima
       alpha_max = vmaxq_s8(alpha_ptr[0],alpha_ptr[1]);
       alpha_max = vmaxq_s8(alpha_max,alpha_ptr[2]);
@@ -366,7 +351,6 @@ void compute_alpha8(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned sh
       alpha_max = vmaxq_s8(alpha_max,alpha_ptr[5]);
       alpha_max = vmaxq_s8(alpha_max,alpha_ptr[6]);
       alpha_max = vmaxq_s8(alpha_max,alpha_ptr[7]);
-
       alpha_ptr[0] = vqsubq_s8(alpha_ptr[0],alpha_max);
       alpha_ptr[1] = vqsubq_s8(alpha_ptr[1],alpha_max);
       alpha_ptr[2] = vqsubq_s8(alpha_ptr[2],alpha_max);
@@ -380,14 +364,22 @@ void compute_alpha8(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned sh
     // Set intial state for next iteration from the last state
     // as a column end states are the first states of the next column
     int K1= frame_length>>1;
-    alpha128[0] = (int8x16_t)vshlq_n_s64((int64x2_t)alpha128[K1],8);   alpha128[0] = vsetq_lane_s8(alpha[8],alpha128[0],7);
-    alpha128[1] = (int8x16_t)vshlq_n_s64((int64x2_t)alpha128[1+K1],8); alpha128[1] = vsetq_lane_s8(alpha[24],alpha128[0],7);
-    alpha128[2] = (int8x16_t)vshlq_n_s64((int64x2_t)alpha128[2+K1],8); alpha128[2] = vsetq_lane_s8(alpha[40],alpha128[0],7);
-    alpha128[3] = (int8x16_t)vshlq_n_s64((int64x2_t)alpha128[3+K1],8); alpha128[3] = vsetq_lane_s8(alpha[56],alpha128[0],7);
-    alpha128[4] = (int8x16_t)vshlq_n_s64((int64x2_t)alpha128[4+K1],8); alpha128[4] = vsetq_lane_s8(alpha[72],alpha128[0],7);
-    alpha128[5] = (int8x16_t)vshlq_n_s64((int64x2_t)alpha128[5+K1],8); alpha128[5] = vsetq_lane_s8(alpha[88],alpha128[0],7);
-    alpha128[6] = (int8x16_t)vshlq_n_s64((int64x2_t)alpha128[6+K1],8); alpha128[6] = vsetq_lane_s8(alpha[104],alpha128[0],7);
-    alpha128[7] = (int8x16_t)vshlq_n_s64((int64x2_t)alpha128[7+K1],8); alpha128[7] = vsetq_lane_s8(alpha[120],alpha128[0],7);
+    alpha128[0] = (int8x16_t)vshlq_n_s64((int64x2_t)alpha128[K1],8);
+    alpha128[0] = vsetq_lane_s8(alpha[8],alpha128[0],7);
+    alpha128[1] = (int8x16_t)vshlq_n_s64((int64x2_t)alpha128[1+K1],8);
+    alpha128[1] = vsetq_lane_s8(alpha[24],alpha128[0],7);
+    alpha128[2] = (int8x16_t)vshlq_n_s64((int64x2_t)alpha128[2+K1],8);
+    alpha128[2] = vsetq_lane_s8(alpha[40],alpha128[0],7);
+    alpha128[3] = (int8x16_t)vshlq_n_s64((int64x2_t)alpha128[3+K1],8);
+    alpha128[3] = vsetq_lane_s8(alpha[56],alpha128[0],7);
+    alpha128[4] = (int8x16_t)vshlq_n_s64((int64x2_t)alpha128[4+K1],8);
+    alpha128[4] = vsetq_lane_s8(alpha[72],alpha128[0],7);
+    alpha128[5] = (int8x16_t)vshlq_n_s64((int64x2_t)alpha128[5+K1],8);
+    alpha128[5] = vsetq_lane_s8(alpha[88],alpha128[0],7);
+    alpha128[6] = (int8x16_t)vshlq_n_s64((int64x2_t)alpha128[6+K1],8);
+    alpha128[6] = vsetq_lane_s8(alpha[104],alpha128[0],7);
+    alpha128[7] = (int8x16_t)vshlq_n_s64((int64x2_t)alpha128[7+K1],8);
+    alpha128[7] = vsetq_lane_s8(alpha[120],alpha128[0],7);
     alpha[16] =  -MAX8/2;
     alpha[32] = -MAX8/2;
     alpha[48] = -MAX8/2;
@@ -395,35 +387,28 @@ void compute_alpha8(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned sh
     alpha[80] = -MAX8/2;
     alpha[96] = -MAX8/2;
     alpha[112] = -MAX8/2;
-
   }
-#endif
-
 
+#endif
 }
 
 
-void compute_beta8(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned short frame_length,unsigned char F,int offset8_flag)
-{
-
+void compute_beta8(llr_t *alpha,llr_t *beta,llr_t *m_11,llr_t *m_10,unsigned short frame_length,unsigned char F,int offset8_flag) {
   int k,rerun_flag, loopval;
 #if defined(__x86_64__) || defined(__i386__)
   __m128i m11_128,m10_128;
   __m128i m_b0,m_b1,m_b2,m_b3,m_b4,m_b5,m_b6,m_b7;
   __m128i new0,new1,new2,new3,new4,new5,new6,new7;
-
   __m128i *beta128,*alpha128,*beta_ptr;
   __m128i beta_max;
 #elif defined(__arm__)
   int8x16_t m11_128,m10_128;
   int8x16_t m_b0,m_b1,m_b2,m_b3,m_b4,m_b5,m_b6,m_b7;
   int8x16_t new0,new1,new2,new3,new4,new5,new6,new7;
-
   int8x16_t *beta128,*alpha128,*beta_ptr;
   int8x16_t beta_max;
 #endif
   llr_t beta0,beta1;
-
   llr_t beta2,beta3,beta4,beta5,beta6,beta7;
 
   if (frame_length > 6144) {
@@ -433,13 +418,12 @@ void compute_beta8(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sho
 
   // we are supposed to run compute_alpha just before compute_beta
   // so the initial states of backward computation can be set from last value of alpha states (forward computation)
-
 #if defined(__x86_64__) || defined(__i386__)
-  beta_ptr   = (__m128i*)&beta[frame_length<<3];
-  alpha128   = (__m128i*)&alpha[0];
+  beta_ptr   = (__m128i *)&beta[frame_length<<3];
+  alpha128   = (__m128i *)&alpha[0];
 #elif defined(__arm__)
-  beta_ptr   = (int8x16_t*)&beta[frame_length<<3];
-  alpha128   = (int8x16_t*)&alpha[0];
+  beta_ptr   = (int8x16_t *)&beta[frame_length<<3];
+  alpha128   = (int8x16_t *)&alpha[0];
 #endif
   beta_ptr[0] = alpha128[(frame_length>>1)];
   beta_ptr[1] = alpha128[1+(frame_length>>1)];
@@ -449,18 +433,15 @@ void compute_beta8(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sho
   beta_ptr[5] = alpha128[5+(frame_length>>1)];
   beta_ptr[6] = alpha128[6+(frame_length>>1)];
   beta_ptr[7] = alpha128[7+(frame_length>>1)];
-
   int overlap = (frame_length>>4)> L ? (frame_length>>4)-L : 0 ;
 
   for (rerun_flag=0, loopval=0;
        rerun_flag<2 ;
        loopval=overlap,rerun_flag++) {
-
     if (offset8_flag==0) {
       // FIXME! beta0-beta7 are used uninitialized. FIXME!
       // workaround: init with 0
       beta0 = beta1 = beta2 = beta3 = beta4 = beta5 = beta6 = beta7 = 0;
-
 #if defined(__x86_64__) || defined(__i386__)
       beta_ptr[0] = _mm_insert_epi8(beta_ptr[0],beta0,15);
       beta_ptr[1] = _mm_insert_epi8(beta_ptr[1],beta1,15);
@@ -483,16 +464,17 @@ void compute_beta8(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sho
     }
 
 #if defined(__x86_64__) || defined(__i386__)
-    beta_ptr = (__m128i*)&beta[frame_length<<3];
+    beta_ptr = (__m128i *)&beta[frame_length<<3];
 #elif defined(__arm__)
-    beta_ptr = (int8x16_t*)&beta[frame_length<<3];
+    beta_ptr = (int8x16_t *)&beta[frame_length<<3];
 #endif
+
     for (k=(frame_length>>4)-1;
          k>=loopval;
          k--) {
 #if defined(__x86_64__) || defined(__i386__)
-      m11_128=((__m128i*)m_11)[k];
-      m10_128=((__m128i*)m_10)[k];
+      m11_128=((__m128i *)m_11)[k];
+      m10_128=((__m128i *)m_10)[k];
       m_b0 = _mm_adds_epi8(beta_ptr[4],m11_128);  //m11
       m_b1 = _mm_subs_epi8(beta_ptr[4],m11_128);  //m00
       m_b2 = _mm_subs_epi8(beta_ptr[5],m10_128);  //m01
@@ -501,7 +483,6 @@ void compute_beta8(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sho
       m_b5 = _mm_subs_epi8(beta_ptr[6],m10_128);  //m01
       m_b6 = _mm_subs_epi8(beta_ptr[7],m11_128);  //m00
       m_b7 = _mm_adds_epi8(beta_ptr[7],m11_128);  //m11
-
       new0 = _mm_subs_epi8(beta_ptr[0],m11_128);  //m00
       new1 = _mm_adds_epi8(beta_ptr[0],m11_128);  //m11
       new2 = _mm_adds_epi8(beta_ptr[1],m10_128);  //m10
@@ -510,9 +491,7 @@ void compute_beta8(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sho
       new5 = _mm_adds_epi8(beta_ptr[2],m10_128);  //m10
       new6 = _mm_adds_epi8(beta_ptr[3],m11_128);  //m11
       new7 = _mm_subs_epi8(beta_ptr[3],m11_128);  //m00
-
       beta_ptr-=8;
-
       beta_ptr[0] = _mm_max_epi8(m_b0,new0);
       beta_ptr[1] = _mm_max_epi8(m_b1,new1);
       beta_ptr[2] = _mm_max_epi8(m_b2,new2);
@@ -521,7 +500,6 @@ void compute_beta8(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sho
       beta_ptr[5] = _mm_max_epi8(m_b5,new5);
       beta_ptr[6] = _mm_max_epi8(m_b6,new6);
       beta_ptr[7] = _mm_max_epi8(m_b7,new7);
-
       beta_max = _mm_max_epi8(beta_ptr[0],beta_ptr[1]);
       beta_max = _mm_max_epi8(beta_max   ,beta_ptr[2]);
       beta_max = _mm_max_epi8(beta_max   ,beta_ptr[3]);
@@ -529,7 +507,6 @@ void compute_beta8(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sho
       beta_max = _mm_max_epi8(beta_max   ,beta_ptr[5]);
       beta_max = _mm_max_epi8(beta_max   ,beta_ptr[6]);
       beta_max = _mm_max_epi8(beta_max   ,beta_ptr[7]);
-
       beta_ptr[0] = _mm_subs_epi8(beta_ptr[0],beta_max);
       beta_ptr[1] = _mm_subs_epi8(beta_ptr[1],beta_max);
       beta_ptr[2] = _mm_subs_epi8(beta_ptr[2],beta_max);
@@ -539,8 +516,8 @@ void compute_beta8(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sho
       beta_ptr[6] = _mm_subs_epi8(beta_ptr[6],beta_max);
       beta_ptr[7] = _mm_subs_epi8(beta_ptr[7],beta_max);
 #elif defined(__arm__)
-      m11_128=((int8x16_t*)m_11)[k];
-      m10_128=((int8x16_t*)m_10)[k];
+      m11_128=((int8x16_t *)m_11)[k];
+      m10_128=((int8x16_t *)m_10)[k];
       m_b0 = vqaddq_s8(beta_ptr[4],m11_128);  //m11
       m_b1 = vqsubq_s8(beta_ptr[4],m11_128);  //m00
       m_b2 = vqsubq_s8(beta_ptr[5],m10_128);  //m01
@@ -549,7 +526,6 @@ void compute_beta8(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sho
       m_b5 = vqsubq_s8(beta_ptr[6],m10_128);  //m01
       m_b6 = vqsubq_s8(beta_ptr[7],m11_128);  //m00
       m_b7 = vqaddq_s8(beta_ptr[7],m11_128);  //m11
-
       new0 = vqsubq_s8(beta_ptr[0],m11_128);  //m00
       new1 = vqaddq_s8(beta_ptr[0],m11_128);  //m11
       new2 = vqaddq_s8(beta_ptr[1],m10_128);  //m10
@@ -558,9 +534,7 @@ void compute_beta8(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sho
       new5 = vqaddq_s8(beta_ptr[2],m10_128);  //m10
       new6 = vqaddq_s8(beta_ptr[3],m11_128);  //m11
       new7 = vqsubq_s8(beta_ptr[3],m11_128);  //m00
-
       beta_ptr-=8;
-
       beta_ptr[0] = vmaxq_s8(m_b0,new0);
       beta_ptr[1] = vmaxq_s8(m_b1,new1);
       beta_ptr[2] = vmaxq_s8(m_b2,new2);
@@ -569,7 +543,6 @@ void compute_beta8(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sho
       beta_ptr[5] = vmaxq_s8(m_b5,new5);
       beta_ptr[6] = vmaxq_s8(m_b6,new6);
       beta_ptr[7] = vmaxq_s8(m_b7,new7);
-
       beta_max = vmaxq_s8(beta_ptr[0],beta_ptr[1]);
       beta_max = vmaxq_s8(beta_max   ,beta_ptr[2]);
       beta_max = vmaxq_s8(beta_max   ,beta_ptr[3]);
@@ -577,7 +550,6 @@ void compute_beta8(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sho
       beta_max = vmaxq_s8(beta_max   ,beta_ptr[5]);
       beta_max = vmaxq_s8(beta_max   ,beta_ptr[6]);
       beta_max = vmaxq_s8(beta_max   ,beta_ptr[7]);
-
       beta_ptr[0] = vqsubq_s8(beta_ptr[0],beta_max);
       beta_ptr[1] = vqsubq_s8(beta_ptr[1],beta_max);
       beta_ptr[2] = vqsubq_s8(beta_ptr[2],beta_max);
@@ -592,10 +564,9 @@ void compute_beta8(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sho
     // Set intial state for next iteration from the last state
     // as column last states are the first states of the next column
     // The initial state of column 0 is coming from tail bits (to be computed)
-
 #if defined(__x86_64__) || defined(__i386__)
-    beta128 = (__m128i*)&beta[0];
-    beta_ptr   = (__m128i*)&beta[frame_length<<3];
+    beta128 = (__m128i *)&beta[0];
+    beta_ptr   = (__m128i *)&beta[frame_length<<3];
     beta_ptr[0] = _mm_srli_si128(beta128[0],1);
     beta_ptr[1] = _mm_srli_si128(beta128[1],1);
     beta_ptr[2] = _mm_srli_si128(beta128[2],1);
@@ -605,23 +576,29 @@ void compute_beta8(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sho
     beta_ptr[6] = _mm_srli_si128(beta128[6],1);
     beta_ptr[7] = _mm_srli_si128(beta128[7],1);
 #elif defined(__arm__)
-    beta128 = (int8x16_t*)&beta[0];
-    beta_ptr   = (int8x16_t*)&beta[frame_length<<3];
-    beta_ptr[0] = (int8x16_t)vshrq_n_s64((int64x2_t)beta128[0],8);   beta_ptr[0] = vsetq_lane_s8(beta[7],beta_ptr[0],8);
-    beta_ptr[1] = (int8x16_t)vshrq_n_s64((int64x2_t)beta128[1],8);   beta_ptr[1] = vsetq_lane_s8(beta[23],beta_ptr[1],8);
-    beta_ptr[2] = (int8x16_t)vshrq_n_s64((int64x2_t)beta128[2],8);   beta_ptr[2] = vsetq_lane_s8(beta[39],beta_ptr[2],8);
-    beta_ptr[3] = (int8x16_t)vshrq_n_s64((int64x2_t)beta128[3],8);   beta_ptr[3] = vsetq_lane_s8(beta[55],beta_ptr[3],8);
-    beta_ptr[4] = (int8x16_t)vshrq_n_s64((int64x2_t)beta128[4],8);   beta_ptr[4] = vsetq_lane_s8(beta[71],beta_ptr[4],8);
-    beta_ptr[5] = (int8x16_t)vshrq_n_s64((int64x2_t)beta128[5],8);   beta_ptr[5] = vsetq_lane_s8(beta[87],beta_ptr[5],8);
-    beta_ptr[6] = (int8x16_t)vshrq_n_s64((int64x2_t)beta128[6],8);   beta_ptr[6] = vsetq_lane_s8(beta[103],beta_ptr[6],8);
-    beta_ptr[7] = (int8x16_t)vshrq_n_s64((int64x2_t)beta128[7],8);   beta_ptr[7] = vsetq_lane_s8(beta[119],beta_ptr[7],8);
+    beta128 = (int8x16_t *)&beta[0];
+    beta_ptr   = (int8x16_t *)&beta[frame_length<<3];
+    beta_ptr[0] = (int8x16_t)vshrq_n_s64((int64x2_t)beta128[0],8);
+    beta_ptr[0] = vsetq_lane_s8(beta[7],beta_ptr[0],8);
+    beta_ptr[1] = (int8x16_t)vshrq_n_s64((int64x2_t)beta128[1],8);
+    beta_ptr[1] = vsetq_lane_s8(beta[23],beta_ptr[1],8);
+    beta_ptr[2] = (int8x16_t)vshrq_n_s64((int64x2_t)beta128[2],8);
+    beta_ptr[2] = vsetq_lane_s8(beta[39],beta_ptr[2],8);
+    beta_ptr[3] = (int8x16_t)vshrq_n_s64((int64x2_t)beta128[3],8);
+    beta_ptr[3] = vsetq_lane_s8(beta[55],beta_ptr[3],8);
+    beta_ptr[4] = (int8x16_t)vshrq_n_s64((int64x2_t)beta128[4],8);
+    beta_ptr[4] = vsetq_lane_s8(beta[71],beta_ptr[4],8);
+    beta_ptr[5] = (int8x16_t)vshrq_n_s64((int64x2_t)beta128[5],8);
+    beta_ptr[5] = vsetq_lane_s8(beta[87],beta_ptr[5],8);
+    beta_ptr[6] = (int8x16_t)vshrq_n_s64((int64x2_t)beta128[6],8);
+    beta_ptr[6] = vsetq_lane_s8(beta[103],beta_ptr[6],8);
+    beta_ptr[7] = (int8x16_t)vshrq_n_s64((int64x2_t)beta128[7],8);
+    beta_ptr[7] = vsetq_lane_s8(beta[119],beta_ptr[7],8);
 #endif
   }
 }
 
-void compute_ext8(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,llr_t* ext, llr_t* systematic,unsigned short frame_length)
-{
-
+void compute_ext8(llr_t *alpha,llr_t *beta,llr_t *m_11,llr_t *m_10,llr_t *ext, llr_t *systematic,unsigned short frame_length) {
 #if defined(__x86_64__) || defined(__i386__)
   __m128i *alpha128=(__m128i *)alpha;
   __m128i *beta128=(__m128i *)beta;
@@ -642,27 +619,20 @@ void compute_ext8(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,llr_t* ext, l
   int8x16_t m11_1,m11_2,m11_3,m11_4;
 #endif
   int k;
-
   //
   // LLR computation, 8 consequtive bits per loop
   //
-
 #ifdef DEBUG_LOGMAP
   printf("compute_ext, %p, %p, %p, %p, %p, %p ,framelength %d\n",alpha,beta,m_11,m_10,ext,systematic,frame_length);
 #endif
-
   alpha_ptr = alpha128;
   beta_ptr = &beta128[8];
 
-
   for (k=0; k<(frame_length>>4); k++) {
-
 #if defined(__x86_64__) || defined(__i386__)
-
-    m11_128        = (__m128i*)&m_11[k<<4];
-    m10_128        = (__m128i*)&m_10[k<<4];
-    ext_128        = (__m128i*)&ext[k<<4];
-
+    m11_128        = (__m128i *)&m_11[k<<4];
+    m10_128        = (__m128i *)&m_10[k<<4];
+    ext_128        = (__m128i *)&ext[k<<4];
     m00_4 = _mm_adds_epi8(alpha_ptr[7],beta_ptr[3]); //ALPHA_BETA_4m00;
     m11_4 = _mm_adds_epi8(alpha_ptr[7],beta_ptr[7]); //ALPHA_BETA_4m11;
     m00_3 = _mm_adds_epi8(alpha_ptr[6],beta_ptr[7]); //ALPHA_BETA_3m00;
@@ -679,7 +649,6 @@ void compute_ext8(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,llr_t* ext, l
     m10_2 = _mm_adds_epi8(alpha_ptr[3],beta_ptr[5]); //ALPHA_BETA_2m10;
     m10_1 = _mm_adds_epi8(alpha_ptr[2],beta_ptr[1]); //ALPHA_BETA_1m10;
     m01_1 = _mm_adds_epi8(alpha_ptr[2],beta_ptr[5]); //ALPHA_BETA_1m01;
-
     m01_1 = _mm_max_epi8(m01_1,m01_2);
     m01_1 = _mm_max_epi8(m01_1,m01_3);
     m01_1 = _mm_max_epi8(m01_1,m01_4);
@@ -692,28 +661,19 @@ void compute_ext8(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,llr_t* ext, l
     m11_1 = _mm_max_epi8(m11_1,m11_2);
     m11_1 = _mm_max_epi8(m11_1,m11_3);
     m11_1 = _mm_max_epi8(m11_1,m11_4);
-
-
     m01_1 = _mm_subs_epi8(m01_1,*m10_128);
     m00_1 = _mm_subs_epi8(m00_1,*m11_128);
     m10_1 = _mm_adds_epi8(m10_1,*m10_128);
     m11_1 = _mm_adds_epi8(m11_1,*m11_128);
-
-
     m01_1 = _mm_max_epi8(m01_1,m00_1);
     m10_1 = _mm_max_epi8(m10_1,m11_1);
-
-
     *ext_128 = _mm_subs_epi8(m10_1,m01_1);
-
     alpha_ptr+=8;
     beta_ptr+=8;
 #elif defined(__arm__)
-
-    m11_128        = (int8x16_t*)&m_11[k<<4];
-    m10_128        = (int8x16_t*)&m_10[k<<4];
-    ext_128        = (int8x16_t*)&ext[k<<4];
-
+    m11_128        = (int8x16_t *)&m_11[k<<4];
+    m10_128        = (int8x16_t *)&m_10[k<<4];
+    ext_128        = (int8x16_t *)&ext[k<<4];
     m00_4 = vqaddq_s8(alpha_ptr[7],beta_ptr[3]); //ALPHA_BETA_4m00;
     m11_4 = vqaddq_s8(alpha_ptr[7],beta_ptr[7]); //ALPHA_BETA_4m11;
     m00_3 = vqaddq_s8(alpha_ptr[6],beta_ptr[7]); //ALPHA_BETA_3m00;
@@ -730,7 +690,6 @@ void compute_ext8(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,llr_t* ext, l
     m10_2 = vqaddq_s8(alpha_ptr[3],beta_ptr[5]); //ALPHA_BETA_2m10;
     m10_1 = vqaddq_s8(alpha_ptr[2],beta_ptr[1]); //ALPHA_BETA_1m10;
     m01_1 = vqaddq_s8(alpha_ptr[2],beta_ptr[5]); //ALPHA_BETA_1m01;
-
     m01_1 = vmaxq_s8(m01_1,m01_2);
     m01_1 = vmaxq_s8(m01_1,m01_3);
     m01_1 = vmaxq_s8(m01_1,m01_4);
@@ -743,27 +702,17 @@ void compute_ext8(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,llr_t* ext, l
     m11_1 = vmaxq_s8(m11_1,m11_2);
     m11_1 = vmaxq_s8(m11_1,m11_3);
     m11_1 = vmaxq_s8(m11_1,m11_4);
-
-
     m01_1 = vqsubq_s8(m01_1,*m10_128);
     m00_1 = vqsubq_s8(m00_1,*m11_128);
     m10_1 = vqaddq_s8(m10_1,*m10_128);
     m11_1 = vqaddq_s8(m11_1,*m11_128);
-
-
     m01_1 = vmaxq_s8(m01_1,m00_1);
     m10_1 = vmaxq_s8(m10_1,m11_1);
-
-
     *ext_128 = vqsubq_s8(m10_1,m01_1);
-
     alpha_ptr+=8;
     beta_ptr+=8;
-
 #endif
   }
-
-
 }
 
 
@@ -771,8 +720,7 @@ void compute_ext8(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,llr_t* ext, l
 //int pi2[n],pi3[n+8],pi5[n+8],pi4[n+8],pi6[n+8],
 int *pi2tab8[188],*pi5tab8[188],*pi4tab8[188],*pi6tab8[188];
 
-void free_td8(void)
-{
+void free_td8(void) {
   int ind;
 
   for (ind=0; ind<188; ind++) {
@@ -787,14 +735,11 @@ void free_td8(void)
 
 extern RAN_CONTEXT_t RC;
 
-void init_td8(void)
-{
-
+void init_td8(void) {
   int ind,i,j,n,n2,pi,pi3;
-  short * base_interleaver;
+  short *base_interleaver;
 
   for (ind=0; ind<188; ind++) {
-
     n = f1f2mat[ind].nb_bits;
     base_interleaver=il_tb+f1f2mat[ind].beg_index;
 #ifdef MEX
@@ -816,68 +761,57 @@ void init_td8(void)
       n2 = n;
 
     for (j=0,i=0; i<n2; i++,j+=16) {
-
       if (j>=n2)
         j-=(n2-1);
 
       pi2tab8[ind][i] = j;
       //    printf("pi2[%d] = %d\n",i,j);
     }
-    
+
     for (i=0; i<n2; i++) {
       pi = base_interleaver[i];//(unsigned int)threegpplte_interleaver(f1,f2,n);
       pi3 = pi2tab8[ind][pi];
       pi4tab8[ind][pi2tab8[ind][i]] = pi3;
       pi5tab8[ind][pi3] = pi2tab8[ind][i];
       pi6tab8[ind][pi] = pi2tab8[ind][i];
-      }
-
+    }
   }
 }
 
 uint8_t phy_threegpplte_turbo_decoder8(int16_t *y,
-                               int16_t *y2,
-    		               uint8_t *decoded_bytes,
-    		               uint8_t *decoded_bytes2,
-	   		       uint16_t n,
-	   		       uint8_t max_iterations,
-	   		       uint8_t crc_type,
-	   		       uint8_t F,
-	   		       time_stats_t *init_stats,
-	   		       time_stats_t *alpha_stats,
-	   		       time_stats_t *beta_stats,
-	   		       time_stats_t *gamma_stats,
-	   		       time_stats_t *ext_stats,
-	   		       time_stats_t *intl1_stats,
-                               time_stats_t *intl2_stats) {
+                                       int16_t *y2,
+                                       uint8_t *decoded_bytes,
+                                       uint8_t *decoded_bytes2,
+                                       uint16_t n,
+                                       uint8_t max_iterations,
+                                       uint8_t crc_type,
+                                       uint8_t F,
+                                       time_stats_t *init_stats,
+                                       time_stats_t *alpha_stats,
+                                       time_stats_t *beta_stats,
+                                       time_stats_t *gamma_stats,
+                                       time_stats_t *ext_stats,
+                                       time_stats_t *intl1_stats,
+                                       time_stats_t *intl2_stats) {
   /*  y is a pointer to the input
       decoded_bytes is a pointer to the decoded output
       n is the size in bits of the coded block, with the tail */
-
   int n2;
-
   llr_t y8[3*(n+16)] __attribute__((aligned(16)));
-
-
   llr_t systematic0[n+16] __attribute__ ((aligned(16)));
   llr_t systematic1[n+16] __attribute__ ((aligned(16)));
   llr_t systematic2[n+16] __attribute__ ((aligned(16)));
   llr_t yparity1[n+16] __attribute__ ((aligned(16)));
   llr_t yparity2[n+16] __attribute__ ((aligned(16)));
-
   llr_t ext[n+128] __attribute__((aligned(16)));
   llr_t ext2[n+128] __attribute__((aligned(16)));
-
   llr_t alpha[(n+16)*8] __attribute__ ((aligned(16)));
   llr_t beta[(n+16)*8] __attribute__ ((aligned(16)));
   llr_t m11[n+16] __attribute__ ((aligned(16)));
   llr_t m10[n+16] __attribute__ ((aligned(16)));
-
-
   //  int *pi2_p,*pi4_p,*pi5_p,*pi6_p;
   int *pi4_p,*pi5_p,*pi6_p;
   llr_t *s,*s1,*s2,*yp1,*yp2,*yp;
-
   unsigned int i,j,iind;//,pi;
   unsigned char iteration_cnt=0;
   unsigned int crc,oldcrc,crc_len;
@@ -890,13 +824,11 @@ uint8_t phy_threegpplte_turbo_decoder8(int16_t *y,
   int8x16_t *yp128;
   int8x16_t tmp128[(n+8)>>3];
   int8x16_t tmp, zeros=vdupq_n_s8(0);
-  const uint8_t __attribute__ ((aligned (16))) _Powers[16]= 
-    { 1, 2, 4, 8, 16, 32, 64, 128, 1, 2, 4, 8, 16, 32, 64, 128 };
-  
+  const uint8_t __attribute__ ((aligned (16))) _Powers[16]=
+  { 1, 2, 4, 8, 16, 32, 64, 128, 1, 2, 4, 8, 16, 32, 64, 128 };
   // Set the powers of 2 (do it once for all, if applicable)
   uint8x16_t Powers= vld1q_u8(_Powers);
 #endif
-
   int offset8_flag=0;
 
   if (crc_type > 3) {
@@ -904,17 +836,14 @@ uint8_t phy_threegpplte_turbo_decoder8(int16_t *y,
     return 255;
   }
 
-
   if (init_stats) start_meas(init_stats);
 
-
   if ((n&15)>0) {
     n2 = n+8;
     offset8_flag=1;
   } else
     n2 = n;
 
-
   for (iind=0; iind < 188 && f1f2mat[iind].nb_bits != n; iind++);
 
   if ( iind == 188 ) {
@@ -923,31 +852,30 @@ uint8_t phy_threegpplte_turbo_decoder8(int16_t *y,
   }
 
   switch (crc_type) {
-  case CRC24_A:
-  case CRC24_B:
-    crc_len=3;
-    break;
+    case CRC24_A:
+    case CRC24_B:
+      crc_len=3;
+      break;
 
-  case CRC16:
-    crc_len=2;
-    break;
+    case CRC16:
+      crc_len=2;
+      break;
 
-  case CRC8:
-    crc_len=1;
-    break;
+    case CRC8:
+      crc_len=1;
+      break;
 
-  default:
-    crc_len=3;
+    default:
+      crc_len=3;
   }
 
 #if defined(__x86_64__) || defined(__i386__)
-
   // note: this makes valgrind freak
   __m128i avg=_mm_set1_epi32(0);
 
   for (i=0; i<(3*(n>>4))+1; i++) {
-    __m128i tmp=_mm_abs_epi16(_mm_unpackhi_epi16(((__m128i*)y)[i],((__m128i*)y)[i]));
-    avg=_mm_add_epi32(_mm_cvtepi16_epi32(_mm_abs_epi16(((__m128i*)y)[i])),avg);
+    __m128i tmp=_mm_abs_epi16(_mm_unpackhi_epi16(((__m128i *)y)[i],((__m128i *)y)[i]));
+    avg=_mm_add_epi32(_mm_cvtepi16_epi32(_mm_abs_epi16(((__m128i *)y)[i])),avg);
     avg=_mm_add_epi32(_mm_cvtepi16_epi32(tmp),avg);
   }
 
@@ -971,15 +899,13 @@ uint8_t phy_threegpplte_turbo_decoder8(int16_t *y,
     for (i=0,j=0; i<(3*(n2>>4))+1; i++,j+=2)
       ((__m128i *)y8)[i] = _mm_packs_epi16(_mm_srai_epi16(((__m128i *)y)[j],3),_mm_srai_epi16(((__m128i *)y)[j+1],4));
 
-  yp128 = (__m128i*)y8;
-
+  yp128 = (__m128i *)y8;
 #elif defined(__arm__)
-
   int32x4_t avg=vdupq_n_s32(0);
 
   for (i=0; i<(3*(n>>4))+1; i++) {
-    int16x8_t tmp=vabsq_s16(((int16x8_t*)y)[i]);
-    avg = vqaddq_s32(avg,vaddl_s16(((int16x4_t*)&tmp)[0],((int16x4_t*)&tmp)[1]));
+    int16x8_t tmp=vabsq_s16(((int16x8_t *)y)[i]);
+    avg = vqaddq_s32(avg,vaddl_s16(((int16x4_t *)&tmp)[0],((int16x4_t *)&tmp)[1]));
   }
 
   int32_t round_avg=(vgetq_lane_s32(avg,0)+vgetq_lane_s32(avg,1)+vgetq_lane_s32(avg,2)+vgetq_lane_s32(avg,3))/(n*3);
@@ -999,10 +925,8 @@ uint8_t phy_threegpplte_turbo_decoder8(int16_t *y,
     for (i=0,j=0; i<(3*(n2>>3))+1; i++,j+=2)
       ((int8x8_t *)y8)[i] = vqmovn_s16(vshrq_n_s16(((int16x8_t *)y)[j],3));
 
-  yp128 = (int8x16_t*)y8;
-
+  yp128 = (int8x16_t *)y8;
 #endif
-
   s = systematic0;
   s1 = systematic1;
   s2 = systematic2;
@@ -1020,8 +944,7 @@ uint8_t phy_threegpplte_turbo_decoder8(int16_t *y,
     }
 
 #endif
-
-  yp=(llr_t*)yp128;
+  yp=(llr_t *)yp128;
 
   if (n2>n) {
     /*
@@ -1031,7 +954,7 @@ uint8_t phy_threegpplte_turbo_decoder8(int16_t *y,
     s1[n+4]=0;s1[n+5]=0;s1[n+6]=0;s1[n+7]=0;
     s2[n]=0;s2[n+1]=0;s2[n+2]=0;s2[n+3]=0;
     s2[n+4]=0;s2[n+5]=0;s2[n+6]=0;s2[n+7]=0;*/
-    yp=(llr_t*)(y8+n);
+    yp=(llr_t *)(y8+n);
   }
 
   //  printf("n=%d,n2=%d\n",n,n2);
@@ -1045,7 +968,7 @@ uint8_t phy_threegpplte_turbo_decoder8(int16_t *y,
     yp1[i] = *yp;
     yp++;
 #ifdef DEBUG_LOGMAP
-    printf("Term 1 (%d): %d %d\n",i,s[i],yp1[i]);
+    printf("Term 1 (%u): %d %d\n",i,s[i],yp1[i]);
 #endif //DEBUG_LOGMAP
   }
 
@@ -1057,7 +980,7 @@ uint8_t phy_threegpplte_turbo_decoder8(int16_t *y,
     yp2[i-16] = *yp;
     yp++;
 #ifdef DEBUG_LOGMAP
-    printf("Term 2 (%d): %d %d\n",i-16,s[i],yp2[i-16]);
+    printf("Term 2 (%u): %d %d\n",i-16,s[i],yp2[i-16]);
 #endif //DEBUG_LOGMAP
   }
 
@@ -1068,63 +991,59 @@ uint8_t phy_threegpplte_turbo_decoder8(int16_t *y,
   if (init_stats) stop_meas(init_stats);
 
   // do log_map from first parity bit
- 
   log_map8(systematic0,yparity1,m11,m10,alpha,beta,ext,n2,0,F,offset8_flag,alpha_stats,beta_stats,gamma_stats,ext_stats);
-  while (iteration_cnt++ < max_iterations) {
 
+  while (iteration_cnt++ < max_iterations) {
 #ifdef DEBUG_LOGMAP
     printf("\n*******************ITERATION %d (n %d, n2 %d), ext %p\n\n",iteration_cnt,n,n2,ext);
 #endif //DEBUG_LOGMAP
 
     if (intl1_stats) start_meas(intl1_stats);
+
     pi4_p=pi4tab8[iind];
 
     for (i=0; i<(n2>>4); i++) { // steady-state portion
 #if defined(__x86_64__) || defined(__i386__)
-      tmp=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],0);
-      tmp=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],1);
-      tmp=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],2);
-      tmp=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],3);
-      tmp=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],4);
-      tmp=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],5);
-      tmp=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],6);
-      tmp=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],7);
-      tmp=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],8);
-      tmp=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],9);
-      tmp=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],10);
-      tmp=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],11);
-      tmp=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],12);
-      tmp=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],13);
-      tmp=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],14);
-      ((__m128i *)systematic2)[i]=_mm_insert_epi8(tmp,((llr_t*)ext)[*pi4_p++],15);
+      tmp=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],0);
+      tmp=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],1);
+      tmp=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],2);
+      tmp=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],3);
+      tmp=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],4);
+      tmp=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],5);
+      tmp=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],6);
+      tmp=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],7);
+      tmp=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],8);
+      tmp=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],9);
+      tmp=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],10);
+      tmp=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],11);
+      tmp=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],12);
+      tmp=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],13);
+      tmp=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],14);
+      ((__m128i *)systematic2)[i]=_mm_insert_epi8(tmp,((llr_t *)ext)[*pi4_p++],15);
 #elif defined(__arm__)
-      tmp=vsetq_lane_s8(((llr_t*)ext)[*pi4_p++],tmp,0);
-      tmp=vsetq_lane_s8(((llr_t*)ext)[*pi4_p++],tmp,1);
-      tmp=vsetq_lane_s8(((llr_t*)ext)[*pi4_p++],tmp,2);
-      tmp=vsetq_lane_s8(((llr_t*)ext)[*pi4_p++],tmp,3);
-      tmp=vsetq_lane_s8(((llr_t*)ext)[*pi4_p++],tmp,4);
-      tmp=vsetq_lane_s8(((llr_t*)ext)[*pi4_p++],tmp,5);
-      tmp=vsetq_lane_s8(((llr_t*)ext)[*pi4_p++],tmp,6);
-      tmp=vsetq_lane_s8(((llr_t*)ext)[*pi4_p++],tmp,7);
-      tmp=vsetq_lane_s8(((llr_t*)ext)[*pi4_p++],tmp,8);
-      tmp=vsetq_lane_s8(((llr_t*)ext)[*pi4_p++],tmp,9);
-      tmp=vsetq_lane_s8(((llr_t*)ext)[*pi4_p++],tmp,10);
-      tmp=vsetq_lane_s8(((llr_t*)ext)[*pi4_p++],tmp,11);
-      tmp=vsetq_lane_s8(((llr_t*)ext)[*pi4_p++],tmp,12);
-      tmp=vsetq_lane_s8(((llr_t*)ext)[*pi4_p++],tmp,13);
-      tmp=vsetq_lane_s8(((llr_t*)ext)[*pi4_p++],tmp,14);
-      ((int8x16_t *)systematic2)[i]=vsetq_lane_s8(((llr_t*)ext)[*pi4_p++],tmp,15);
+      tmp=vsetq_lane_s8(((llr_t *)ext)[*pi4_p++],tmp,0);
+      tmp=vsetq_lane_s8(((llr_t *)ext)[*pi4_p++],tmp,1);
+      tmp=vsetq_lane_s8(((llr_t *)ext)[*pi4_p++],tmp,2);
+      tmp=vsetq_lane_s8(((llr_t *)ext)[*pi4_p++],tmp,3);
+      tmp=vsetq_lane_s8(((llr_t *)ext)[*pi4_p++],tmp,4);
+      tmp=vsetq_lane_s8(((llr_t *)ext)[*pi4_p++],tmp,5);
+      tmp=vsetq_lane_s8(((llr_t *)ext)[*pi4_p++],tmp,6);
+      tmp=vsetq_lane_s8(((llr_t *)ext)[*pi4_p++],tmp,7);
+      tmp=vsetq_lane_s8(((llr_t *)ext)[*pi4_p++],tmp,8);
+      tmp=vsetq_lane_s8(((llr_t *)ext)[*pi4_p++],tmp,9);
+      tmp=vsetq_lane_s8(((llr_t *)ext)[*pi4_p++],tmp,10);
+      tmp=vsetq_lane_s8(((llr_t *)ext)[*pi4_p++],tmp,11);
+      tmp=vsetq_lane_s8(((llr_t *)ext)[*pi4_p++],tmp,12);
+      tmp=vsetq_lane_s8(((llr_t *)ext)[*pi4_p++],tmp,13);
+      tmp=vsetq_lane_s8(((llr_t *)ext)[*pi4_p++],tmp,14);
+      ((int8x16_t *)systematic2)[i]=vsetq_lane_s8(((llr_t *)ext)[*pi4_p++],tmp,15);
 #endif
     }
 
     if (intl1_stats) stop_meas(intl1_stats);
 
     // do log_map from second parity bit
-
     log_map8(systematic2,yparity2,m11,m10,alpha,beta,ext2,n2,1,F,offset8_flag,alpha_stats,beta_stats,gamma_stats,ext_stats);
-
-
-
     pi5_p=pi5tab8[iind];
     uint16_t decoded_bytes_interl[6144/16] __attribute__((aligned(16)));
 
@@ -1148,7 +1067,7 @@ uint8_t phy_threegpplte_turbo_decoder8(int16_t *y,
         tmp=_mm_insert_epi8(tmp,ext2[*pi5_p++],14);
         tmp=_mm_insert_epi8(tmp,ext2[*pi5_p++],15);
         decoded_bytes_interl[i]=(uint16_t) _mm_movemask_epi8(_mm_cmpgt_epi8(tmp,zeros));
-        ((__m128i *)systematic1)[i] = _mm_adds_epi8(_mm_subs_epi8(tmp,((__m128i*)ext)[i]),((__m128i *)systematic0)[i]);
+        ((__m128i *)systematic1)[i] = _mm_adds_epi8(_mm_subs_epi8(tmp,((__m128i *)ext)[i]),((__m128i *)systematic0)[i]);
 #elif defined(__arm__)
         tmp=vsetq_lane_s8(ext2[*pi5_p++],tmp,0);
         tmp=vsetq_lane_s8(ext2[*pi5_p++],tmp,1);
@@ -1166,13 +1085,12 @@ uint8_t phy_threegpplte_turbo_decoder8(int16_t *y,
         tmp=vsetq_lane_s8(ext2[*pi5_p++],tmp,13);
         tmp=vsetq_lane_s8(ext2[*pi5_p++],tmp,14);
         tmp=vsetq_lane_s8(ext2[*pi5_p++],tmp,15);
-	uint64x2_t Mask= vpaddlq_u32(vpaddlq_u16(vpaddlq_u8(vandq_u8(vcgtq_s8(tmp,zeros), Powers))));
-	vst1q_lane_u8(&((uint8_t*)&decoded_bytes[i])[0], (uint8x16_t)Mask, 0);
-	vst1q_lane_u8(&((uint8_t*)&decoded_bytes[i])[1], (uint8x16_t)Mask, 8);
-	((int8x16_t *)systematic1)[i] = vqaddq_s8(vqsubq_s8(tmp,((int8x16_t*)ext)[i]),((int8x16_t *)systematic0)[i]);
+        uint64x2_t Mask= vpaddlq_u32(vpaddlq_u16(vpaddlq_u8(vandq_u8(vcgtq_s8(tmp,zeros), Powers))));
+        vst1q_lane_u8(&((uint8_t *)&decoded_bytes[i])[0], (uint8x16_t)Mask, 0);
+        vst1q_lane_u8(&((uint8_t *)&decoded_bytes[i])[1], (uint8x16_t)Mask, 8);
+        ((int8x16_t *)systematic1)[i] = vqaddq_s8(vqsubq_s8(tmp,((int8x16_t *)ext)[i]),((int8x16_t *)systematic0)[i]);
 #endif
       }
-
     } else {
       for (i=0; i<(n2>>4); i++) {
 #if defined(__x86_64__) || defined(__i386__)
@@ -1193,8 +1111,7 @@ uint8_t phy_threegpplte_turbo_decoder8(int16_t *y,
         tmp=_mm_insert_epi8(tmp,ext2[*pi5_p++],14);
         tmp=_mm_insert_epi8(tmp,ext2[*pi5_p++],15);
         tmp128[i] = _mm_adds_epi8(((__m128i *)ext2)[i],((__m128i *)systematic2)[i]);
-
-        ((__m128i *)systematic1)[i] = _mm_adds_epi8(_mm_subs_epi8(tmp,((__m128i*)ext)[i]),((__m128i *)systematic0)[i]);
+        ((__m128i *)systematic1)[i] = _mm_adds_epi8(_mm_subs_epi8(tmp,((__m128i *)ext)[i]),((__m128i *)systematic0)[i]);
 #elif defined(__arm__)
         tmp=vsetq_lane_s8(ext2[*pi5_p++],tmp,0);
         tmp=vsetq_lane_s8(ext2[*pi5_p++],tmp,1);
@@ -1213,11 +1130,9 @@ uint8_t phy_threegpplte_turbo_decoder8(int16_t *y,
         tmp=vsetq_lane_s8(ext2[*pi5_p++],tmp,14);
         tmp=vsetq_lane_s8(ext2[*pi5_p++],tmp,15);
         tmp128[i] = vqaddq_s8(((int8x16_t *)ext2)[i],((int8x16_t *)systematic2)[i]);
-
-        ((int8x16_t *)systematic1)[i] = vqaddq_s8(vqsubq_s8(tmp,((int8x16_t*)ext)[i]),((int8x16_t *)systematic0)[i]);
-
-#endif 
-     }
+        ((int8x16_t *)systematic1)[i] = vqaddq_s8(vqsubq_s8(tmp,((int8x16_t *)ext)[i]),((int8x16_t *)systematic0)[i]);
+#endif
+      }
     }
 
     // Check if we decoded the block
@@ -1225,11 +1140,10 @@ uint8_t phy_threegpplte_turbo_decoder8(int16_t *y,
       if (intl2_stats) start_meas(intl2_stats);
 
       if ((n2&0x7f) == 0) {  // n2 is a multiple of 128 bits
-
         // re-order the decoded bits in theregular order
         // as it is presently ordered as 16 sequential columns
 #if defined(__x86_64__) || defined(__i386__)
-        __m128i* dbytes=(__m128i*)decoded_bytes_interl;
+        __m128i *dbytes=(__m128i *)decoded_bytes_interl;
         __m128i shuffle=SHUFFLE16(7,6,5,4,3,2,1,0);
         __m128i mask  __attribute__((aligned(16)));
         int n_128=n2>>7;
@@ -1239,10 +1153,9 @@ uint8_t phy_threegpplte_turbo_decoder8(int16_t *y,
           __m128i tmp __attribute__((aligned(16)));
           tmp=_mm_shuffle_epi8(dbytes[i],shuffle);
           __m128i tmp2 __attribute__((aligned(16))) ;
-
           tmp2=_mm_and_si128(tmp,mask);
           tmp2=_mm_cmpeq_epi16(tmp2,mask);
-	  //	  printf("decoded_bytes %p\n",decoded_bytes);
+          //    printf("decoded_bytes %p\n",decoded_bytes);
           decoded_bytes[n_128*0+i]=(uint8_t) _mm_movemask_epi8(_mm_packs_epi16(tmp2,zeros));
           int j;
 
@@ -1253,22 +1166,22 @@ uint8_t phy_threegpplte_turbo_decoder8(int16_t *y,
             decoded_bytes[n_128*j +i]=(uint8_t) _mm_movemask_epi8(_mm_packs_epi16(tmp2,zeros));
           }
         }
+
 #elif defined(__arm__)
-        uint8x16_t* dbytes=(uint8x16_t*)decoded_bytes_interl;
+        uint8x16_t *dbytes=(uint8x16_t *)decoded_bytes_interl;
         uint16x8_t mask  __attribute__((aligned(16)));
         int n_128=n2>>7;
 
         for (i=0; i<n_128; i++) {
           mask=vdupq_n_u16(1);
           uint8x16_t tmp __attribute__((aligned(16)));
-          tmp=vcombine_u8(vrev64_u8(((uint8x8_t*)&dbytes[i])[1]),vrev64_u8(((uint8x8_t*)&dbytes[i])[0]));
+          tmp=vcombine_u8(vrev64_u8(((uint8x8_t *)&dbytes[i])[1]),vrev64_u8(((uint8x8_t *)&dbytes[i])[0]));
           vst1q_lane_u8(&decoded_bytes[n_128*0+i],(uint8x16_t)vpaddlq_u32(vpaddlq_u16(vpaddlq_u8(vandq_u8(tmp, Powers)))),0);
-
           int j;
 
           for (j=1; j<16; j++) {
             mask=vshlq_n_u16(mask,1);
-	    vst1q_lane_u8(&decoded_bytes[n_128*0+i],(uint8x16_t)vpaddlq_u32(vpaddlq_u16(vpaddlq_u8(vandq_u8(tmp, Powers)))),0);
+            vst1q_lane_u8(&decoded_bytes[n_128*0+i],(uint8x16_t)vpaddlq_u32(vpaddlq_u16(vpaddlq_u8(vandq_u8(tmp, Powers)))),0);
           }
         }
 
@@ -1313,9 +1226,9 @@ uint8_t phy_threegpplte_turbo_decoder8(int16_t *y,
           tmp=vsetq_lane_s8(((llr_t *)tmp128)[*pi6_p++],tmp,10);
           tmp=vsetq_lane_s8(((llr_t *)tmp128)[*pi6_p++],tmp,9);
           tmp=vsetq_lane_s8(((llr_t *)tmp128)[*pi6_p++],tmp,8);
-	  uint64x2_t Mask= vpaddlq_u32(vpaddlq_u16(vpaddlq_u8(vandq_u8(vcgtq_s8(tmp,zeros), Powers))));
-	  vst1q_lane_u8(&((uint8_t*)&decoded_bytes[i])[0], (uint8x16_t)Mask, 0);
-	  vst1q_lane_u8(&((uint8_t*)&decoded_bytes[i])[1], (uint8x16_t)Mask, 8);
+          uint64x2_t Mask= vpaddlq_u32(vpaddlq_u16(vpaddlq_u8(vandq_u8(vcgtq_s8(tmp,zeros), Powers))));
+          vst1q_lane_u8(&((uint8_t *)&decoded_bytes[i])[0], (uint8x16_t)Mask, 0);
+          vst1q_lane_u8(&((uint8_t *)&decoded_bytes[i])[1], (uint8x16_t)Mask, 8);
 #endif
         }
       }
@@ -1324,41 +1237,40 @@ uint8_t phy_threegpplte_turbo_decoder8(int16_t *y,
       oldcrc= *((unsigned int *)(&decoded_bytes[(n>>3)-crc_len]));
 
       switch (crc_type) {
-
-      case CRC24_A:
-        oldcrc&=0x00ffffff;
-        crc = crc24a(&decoded_bytes[F>>3],
-                     n-24-F)>>8;
-        temp=((uint8_t *)&crc)[2];
-        ((uint8_t *)&crc)[2] = ((uint8_t *)&crc)[0];
-        ((uint8_t *)&crc)[0] = temp;
-        break;
-
-      case CRC24_B:
-        oldcrc&=0x00ffffff;
-        crc = crc24b(decoded_bytes,
-                     n-24)>>8;
-        temp=((uint8_t *)&crc)[2];
-        ((uint8_t *)&crc)[2] = ((uint8_t *)&crc)[0];
-        ((uint8_t *)&crc)[0] = temp;
-        break;
-
-      case CRC16:
-        oldcrc&=0x0000ffff;
-        crc = crc16(decoded_bytes,
-                    n-16)>>16;
-        break;
-
-      case CRC8:
-        oldcrc&=0x000000ff;
-        crc = crc8(decoded_bytes,
-                   n-8)>>24;
-        break;
-
-      default:
-        printf("FATAL: 3gpplte_turbo_decoder_sse.c: Unknown CRC\n");
-        return(255);
-        break;
+        case CRC24_A:
+          oldcrc&=0x00ffffff;
+          crc = crc24a(&decoded_bytes[F>>3],
+                       n-24-F)>>8;
+          temp=((uint8_t *)&crc)[2];
+          ((uint8_t *)&crc)[2] = ((uint8_t *)&crc)[0];
+          ((uint8_t *)&crc)[0] = temp;
+          break;
+
+        case CRC24_B:
+          oldcrc&=0x00ffffff;
+          crc = crc24b(decoded_bytes,
+                       n-24)>>8;
+          temp=((uint8_t *)&crc)[2];
+          ((uint8_t *)&crc)[2] = ((uint8_t *)&crc)[0];
+          ((uint8_t *)&crc)[0] = temp;
+          break;
+
+        case CRC16:
+          oldcrc&=0x0000ffff;
+          crc = crc16(decoded_bytes,
+                      n-16)>>16;
+          break;
+
+        case CRC8:
+          oldcrc&=0x000000ff;
+          crc = crc8(decoded_bytes,
+                     n-8)>>24;
+          break;
+
+        default:
+          printf("FATAL: 3gpplte_turbo_decoder_sse.c: Unknown CRC\n");
+          return(255);
+          break;
       }
 
       if (intl2_stats) stop_meas(intl2_stats);
@@ -1372,13 +1284,13 @@ uint8_t phy_threegpplte_turbo_decoder8(int16_t *y,
     if (iteration_cnt < max_iterations) {
       log_map8(systematic1,yparity1,m11,m10,alpha,beta,ext,n2,0,F,offset8_flag,alpha_stats,beta_stats,gamma_stats,ext_stats);
 #if defined(__x86_64__) || defined(__i386__)
-      __m128i* ext_128=(__m128i*) ext;
-      __m128i* s1_128=(__m128i*) systematic1;
-      __m128i* s0_128=(__m128i*) systematic0;
+      __m128i *ext_128=(__m128i *) ext;
+      __m128i *s1_128=(__m128i *) systematic1;
+      __m128i *s0_128=(__m128i *) systematic0;
 #elif defined(__arm__)
-      int8x16_t* ext_128=(int8x16_t*) ext;
-      int8x16_t* s1_128=(int8x16_t*) systematic1;
-      int8x16_t* s0_128=(int8x16_t*) systematic0;
+      int8x16_t *ext_128=(int8x16_t *) ext;
+      int8x16_t *s1_128=(int8x16_t *) systematic1;
+      int8x16_t *s0_128=(int8x16_t *) systematic0;
 #endif
       int myloop=n2>>4;
 
@@ -1394,5 +1306,4 @@ uint8_t phy_threegpplte_turbo_decoder8(int16_t *y,
   }
 
   return(iteration_cnt);
-
 }
diff --git a/openair1/PHY/CODING/ccoding_byte.c b/openair1/PHY/CODING/ccoding_byte.c
index db91e68dc8f020c63b1d610cfbfb6d1f93ebaa3a..576a947cff3641fffa72c01971e182e71d65eca4 100644
--- a/openair1/PHY/CODING/ccoding_byte.c
+++ b/openair1/PHY/CODING/ccoding_byte.c
@@ -47,27 +47,20 @@ void
 ccodedot11_encode (unsigned int numbytes,
                    unsigned char *inPtr,
                    unsigned char *outPtr,
-                   unsigned char puncturing)
-{
+                   unsigned char puncturing) {
   unsigned int             state;
-
   unsigned char              c, out, shiftbit =0;
-
   //  printf("In ccodedot11_encode (%d,%p,%p,%d)\n",numbytes,inPtr,outPtr,puncturing);
-
 #ifdef DEBUG_CCODE
   unsigned int  dummy;
 #endif //DEBUG_CCODE
   int bit_index;
-
   /* The input bit is shifted in position 8 of the state.
      Shiftbit will take values between 1 and 8 */
   state = 0;
-
 #ifdef DEBUG_CCODE
   dummy = 0;
 #endif //DEBUG_CCODE
-
   /* Do not increment inPtr until we read the next octet */
   bit_index=0;
 
@@ -78,85 +71,75 @@ ccodedot11_encode (unsigned int numbytes,
 #endif //DEBUG_CCODE
 
     switch (puncturing) {
-    case 0:  //rate 1/2
-      for (shiftbit = 0; shiftbit<8; shiftbit++) {
-
-        state >>= 1;
-
-        if ((c&(1<<shiftbit)) != 0) {
-          state |= 64;
-        }
+      case 0:  //rate 1/2
+        for (shiftbit = 0; shiftbit<8; shiftbit++) {
+          state >>= 1;
 
-        out = ccodedot11_table[state];
-
-        *outPtr++ = out  & 1;
-        *outPtr++ = (out>>1)&1;
+          if ((c&(1<<shiftbit)) != 0) {
+            state |= 64;
+          }
 
+          out = ccodedot11_table[state];
+          *outPtr++ = out  & 1;
+          *outPtr++ = (out>>1)&1;
 #ifdef DEBUG_CCODE
-        printf("%d: %d -> %d (%d)\n",dummy,state,out,ccodedot11_table[state]);
-        dummy+=2;
+          printf("%u: %u -> %d (%u)\n",dummy,state,out,ccodedot11_table[state]);
+          dummy+=2;
 #endif //DEBUG_CCODE      
+        }
 
-      }
-
-      break;
-
-    case 1: // rate 3/4
-      for (shiftbit = 0; shiftbit<8; shiftbit++) {
+        break;
 
-        state >>= 1;
+      case 1: // rate 3/4
+        for (shiftbit = 0; shiftbit<8; shiftbit++) {
+          state >>= 1;
 
-        if ((c&(1<<shiftbit)) != 0) {
-          state |= 64;
-        }
+          if ((c&(1<<shiftbit)) != 0) {
+            state |= 64;
+          }
 
-        out = ccodedot11_table[state];
+          out = ccodedot11_table[state];
 
-        if (bit_index<2)
-          *outPtr++ = out  & 1;
+          if (bit_index<2)
+            *outPtr++ = out  & 1;
 
-        if (bit_index!=1)
-          *outPtr++ = (out>>1)&1;
+          if (bit_index!=1)
+            *outPtr++ = (out>>1)&1;
 
 #ifdef DEBUG_CCODE
-        printf("%d: %d -> %d (%d)\n",dummy,state,out,ccodedot11_table[state]);
-        dummy+=2;
+          printf("%u: %u -> %d (%u)\n",dummy,state,out,ccodedot11_table[state]);
+          dummy+=2;
 #endif //DEBUG_CCODE      
+          bit_index=(bit_index==2)?0:(bit_index+1);
+        }
 
-        bit_index=(bit_index==2)?0:(bit_index+1);
-      }
-
-      break;
-
-    case 2: // rate 2/3
-      for (shiftbit = 0; shiftbit<8; shiftbit++) {
-
-        state >>= 1;
+        break;
 
-        if ((c&(1<<shiftbit)) != 0) {
-          state |= 64;
-        }
+      case 2: // rate 2/3
+        for (shiftbit = 0; shiftbit<8; shiftbit++) {
+          state >>= 1;
 
-        out = ccodedot11_table[state];
+          if ((c&(1<<shiftbit)) != 0) {
+            state |= 64;
+          }
 
-        *outPtr++ = out  & 1;
+          out = ccodedot11_table[state];
+          *outPtr++ = out  & 1;
 
-        if (bit_index==0)
-          *outPtr++ = (out>>1)&1;
+          if (bit_index==0)
+            *outPtr++ = (out>>1)&1;
 
 #ifdef DEBUG_CCODE
-        printf("%d: %d -> %d (%d)\n",dummy,state,out,ccodedot11_table[state]);
-        dummy+=2;
+          printf("%u: %u -> %d (%u)\n",dummy,state,out,ccodedot11_table[state]);
+          dummy+=2;
 #endif //DEBUG_CCODE      
+          bit_index=(bit_index==0)?1:0;
+        }
 
-        bit_index=(bit_index==0)?1:0;
-
-      }
-
-      break;
+        break;
 
-    default:
-      break;
+      default:
+        break;
     }
   }
 
@@ -181,8 +164,6 @@ ccodedot11_encode (unsigned int numbytes,
   }
 
   */
-
-
 }
 
 
@@ -197,8 +178,7 @@ ccodedot11_encode (unsigned int numbytes,
 /* Basic code table initialization for constraint length 7 */
 /* Input in MSB, followed by state in 6 LSBs */
 
-void ccodedot11_init(void)
-{
+void ccodedot11_init(void) {
   unsigned int  i, j, k, sum;
 
   for (i = 0; i < 128; i++) {
@@ -219,8 +199,7 @@ void ccodedot11_init(void)
 }
 
 /* Input in LSB, followed by state in 6 MSBs */
-void ccodedot11_init_inv(void)
-{
+void ccodedot11_init_inv(void) {
   unsigned int  i, j, k, sum;
 
   for (i = 0; i < 128; i++) {
@@ -251,21 +230,15 @@ void ccodedot11_init_inv(void)
 #ifdef DEBUG_CCODE
 #include <stdio.h>
 
-main()
-{
+main() {
   unsigned char test[] = "0Thebigredfox";
   unsigned char output[512], *inPtr, *outPtr;
   unsigned int i;
-
   test[0] = 128;
   test[1] = 0;
-
-
   ccodedot11_init();
-
   inPtr = test;
   outPtr = output;
-
   ccodedot11_encode(16, inPtr, outPtr,0);
 
   for (i = 0; i < 32; i++) printf("%x ", output[i]);
diff --git a/openair1/PHY/CODING/ccoding_byte_lte.c b/openair1/PHY/CODING/ccoding_byte_lte.c
index 870e9ba4700c15e16c42d4b18e3a975ef757e51e..f41b073a78d25c77c4b1b60950df24b196db2b61 100644
--- a/openair1/PHY/CODING/ccoding_byte_lte.c
+++ b/openair1/PHY/CODING/ccoding_byte_lte.c
@@ -52,20 +52,16 @@ ccodelte_encode (int32_t numbits,
                  uint8_t add_crc,
                  uint8_t *inPtr,
                  uint8_t *outPtr,
-                 uint16_t rnti)
-{
+                 uint16_t rnti) {
   uint32_t             state;
-
   uint8_t              c, out, first_bit;
   int8_t shiftbit=0;
   uint16_t c16;
   uint16_t next_last_byte=0;
   uint32_t crc=0;
-
 #ifdef DEBUG_CCODE
   uint32_t  dummy=0;
 #endif //DEBUG_CCODE
-
   /* The input bit is shifted in position 8 of the state.
      Shiftbit will take values between 1 and 8 */
   state = 0;
@@ -137,17 +133,12 @@ ccodelte_encode (int32_t numbits,
 #endif //DEBUG_CCODE
   /* Do not increment inPtr until we read the next octet */
 
-
-
-
   while (numbits > 0) {
-
     c = *inPtr++;
 #ifdef DEBUG_CCODE
     printf("** %x **\n",c);
 #endif //DEBUG_CCODE
 
-
     //    for (shiftbit = 0; (shiftbit<8) && (numbits>0);shiftbit++,numbits--) {
     for (shiftbit = 7; (shiftbit>=0) && (numbits>0); shiftbit--,numbits--) {
       state >>= 1;
@@ -157,23 +148,18 @@ ccodelte_encode (int32_t numbits,
       }
 
       out = ccodelte_table[state];
-
       *outPtr++ = out  & 1;
       *outPtr++ = (out>>1)&1;
       *outPtr++ = (out>>2)&1;
-
 #ifdef DEBUG_CCODE
       printf("numbits %d, input %d, outbit %d: %d -> %d (%d%d%d)\n",numbits,state>>6,dummy,state,out,out&1,(out>>1)&1,(out>>2)&1);
       dummy+=3;
 #endif //DEBUG_CCODE      
-
     }
-
   }
 
   // now code 8-bit CRC for UCI
   if (add_crc == 1) {
-
     c = (uint8_t)(crc>>24);
 
     //    for (shiftbit = 0; (shiftbit<8);shiftbit++) {
@@ -185,22 +171,18 @@ ccodelte_encode (int32_t numbits,
       }
 
       out = ccodelte_table[state];
-
       *outPtr++ = out  & 1;
       *outPtr++ = (out>>1)&1;
       *outPtr++ = (out>>2)&1;
-
 #ifdef DEBUG_CCODE
-      printf("crc bit %d input %d, outbit %d: %d -> %d (%d)\n",shiftbit,state>>6,dummy,state,out,ccodelte_table[state]);
+      printf("crc bit %d input %d, outbit %d: %d -> %d (%u)\n",shiftbit,state>>6,dummy,state,out,ccodelte_table[state]);
       dummy+=3;
 #endif //DEBUG_CCODE      
-
     }
   }
 
   // now code 16-bit CRC for DCI
   if (add_crc == 2) {
-
     c16 = (uint16_t)(crc>>16);
 
     //    for (shiftbit = 0; (shiftbit<16);shiftbit++) {
@@ -212,16 +194,13 @@ ccodelte_encode (int32_t numbits,
       }
 
       out = ccodelte_table[state];
-
       *outPtr++ = out  & 1;
       *outPtr++ = (out>>1)&1;
       *outPtr++ = (out>>2)&1;
-
 #ifdef DEBUG_CCODE
-      printf("crc bit %d input %d, outbit %d: %d -> %d (%d)\n",shiftbit,state>>6,dummy,state,out,ccodelte_table[state]);
+      printf("crc bit %d input %d, outbit %d: %d -> %d (%u)\n",shiftbit,state>>6,dummy,state,out,ccodelte_table[state]);
       dummy+=3;
 #endif //DEBUG_CCODE      
-
     }
   }
 }
@@ -238,8 +217,7 @@ ccodelte_encode (int32_t numbits,
 /* Basic code table initialization for constraint length 7 */
 /* Input in MSB, followed by state in 6 LSBs */
 
-void ccodelte_init(void)
-{
+void ccodelte_init(void) {
   unsigned int  i, j, k, sum;
 
   for (i = 0; i < 128; i++) {
@@ -260,8 +238,7 @@ void ccodelte_init(void)
 }
 
 /* Input in LSB, followed by state in 6 MSBs */
-void ccodelte_init_inv(void)
-{
+void ccodelte_init_inv(void) {
   unsigned int  i, j, k, sum;
 
   for (i = 0; i < 128; i++) {
@@ -281,8 +258,7 @@ void ccodelte_init_inv(void)
   }
 }
 
-void ccodedab_init(void)
-{
+void ccodedab_init(void) {
   unsigned int  i, j, k, sum;
 
   for (i = 0; i < 128; i++) {
@@ -303,8 +279,7 @@ void ccodedab_init(void)
 }
 
 /* Input in LSB, followed by state in 6 MSBs */
-void ccodedab_init_inv(void)
-{
+void ccodedab_init_inv(void) {
   unsigned int  i, j, k, sum;
 
   for (i = 0; i < 128; i++) {
@@ -334,21 +309,15 @@ void ccodedab_init_inv(void)
 #ifdef CCODE_MAIN
 #include <stdio.h>
 
-main()
-{
+main() {
   unsigned char test[] = "Thebigredfox";
   unsigned char output[512], *inPtr, *outPtr;
   unsigned int i;
-
   test[0] = 128;
   test[1] = 0;
-
-
   ccodelte_init();
-
   inPtr = test;
   outPtr = output;
-
   ccodelte_encode(21, inPtr, outPtr);
 
   for (i = 0; i < 21*3; i++) printf("%x ", output[i]);
diff --git a/openair1/PHY/CODING/crc_byte.c b/openair1/PHY/CODING/crc_byte.c
index f2f7e4e5c7d213e53c3fab1c392fc042c37d3715..29bddeb2cbb097f3d2496ef086c42749b59b3415 100644
--- a/openair1/PHY/CODING/crc_byte.c
+++ b/openair1/PHY/CODING/crc_byte.c
@@ -32,21 +32,6 @@
 
 #include "PHY/types.h"
 
-// For initialization && verification purposes, bit by bit implementation with any polynomial
-// The first bit is in the MSB of each byte
-
-// Reference 38.212 V15.1.1 Section 5.1 (36-212 v8.6.0 , pp 8-9)
-// The highest degree is set by default
-/** 1000 0110 0100 1100 1111 1011  D^24 + D^23 + D^18 + D^17 + D^14 + D^11 + D^10 + D^7 + D^6 + D^5 + D^4 + D^3 + D + 1 */
-static const uint32_t poly24a = 0x864cfb00;
-/** 1000 0000 0000 0000 0110 0011  D^24 + D^23 + D^6 + D^5 + D + 1 */
-static const uint32_t poly24b = 0x80006300;
-/** 0001 0000 0010 0001            D^16 + D^12 + D^5 + 1 */
-static const uint32_t poly16  = 0x10210000;
-/** 1000 0000 1111                 D^12 + D^11 + D^3 + D^2 + D + 1 */
-static const uint32_t poly12  = 0x80F00000;
-/** 1001 1011                      D^8  + D^7  + D^4 + D^3 + D + 1 */
-static const uint32_t poly8   = 0x9B000000;
 
 // The following arrays are generated with the function 'crcTableInit'
 /** Encoding table for CRC 24A */
@@ -96,6 +81,24 @@ uint32_t crcbit (uint8_t * inputptr, int32_t octetlen, uint32_t poly)
 // CRC table initialization
 
 /*
+  RK: Note that this should be brought back and use crcTableInit instead of static declaration
+      Commented out to remove warning
+  // For initialization && verification purposes, bit by bit implementation with any polynomial
+  // The first bit is in the MSB of each byte
+
+ // Reference 38.212 V15.1.1 Section 5.1 (36-212 v8.6.0 , pp 8-9)
+// The highest degree is set by default
+// 1000 0110 0100 1100 1111 1011  D^24 + D^23 + D^18 + D^17 + D^14 + D^11 + D^10 + D^7 + D^6 + D^5 + D^4 + D^3 + D + 1
+static const uint32_t poly24a = 0x864cfb00;
+// 1000 0000 0000 0000 0110 0011  D^24 + D^23 + D^6 + D^5 + D + 1
+static const uint32_t poly24b = 0x80006300;
+// 0001 0000 0010 0001            D^16 + D^12 + D^5 + 1
+static const uint32_t poly16  = 0x10210000;
+// 1000 0000 1111                 D^12 + D^11 + D^3 + D^2 + D + 1
+static const uint32_t poly12  = 0x80F00000;
+// 1001 1011                      D^8  + D^7  + D^4 + D^3 + D + 1
+static const uint32_t poly8   = 0x9B000000;
+
 void crcTableInit (void)
 {
     uint8_t c = 0;
diff --git a/openair1/PHY/CODING/lte_rate_matching.c b/openair1/PHY/CODING/lte_rate_matching.c
index af5d1a169e950fa0a35b7237c47ad5390a195288..548b7bfcba38bec0c8bb6aee29262872ad263c9f 100644
--- a/openair1/PHY/CODING/lte_rate_matching.c
+++ b/openair1/PHY/CODING/lte_rate_matching.c
@@ -25,8 +25,8 @@
    date: 21.10.2009
 */
 #ifdef MAIN
-#include <stdio.h>
-#include <stdlib.h>
+  #include <stdio.h>
+  #include <stdlib.h>
 #endif
 #include "PHY/defs_eNB.h"
 #include "PHY/LTE_TRANSPORT/transport_common.h"
@@ -42,9 +42,7 @@ static uint32_t bitrev_cc[32] = {1,17,9,25,5,21,13,29,3,19,11,27,7,23,15,31,0,16
 //#define RM_DEBUG2 1
 //#define RM_DEBUG_CC 1
 
-uint32_t sub_block_interleaving_turbo(uint32_t D, uint8_t *d,uint8_t *w)
-{
-
+uint32_t sub_block_interleaving_turbo(uint32_t D, uint8_t *d,uint8_t *w) {
   uint32_t RTC = (D>>5), ND, ND3;
   uint32_t row,col,Kpi;
   uint32_t index3,k,k2;
@@ -64,7 +62,6 @@ uint32_t sub_block_interleaving_turbo(uint32_t D, uint8_t *d,uint8_t *w)
   printf("RTC = %d, Kpi=%d, ND=%d\n",RTC,Kpi,ND);
 #endif
   ND3 = ND*3;
-
   // copy d02 to dD2 (for mod Kpi operation from clause (4), p.16 of 36.212
   d[(3*D)+2] = d[2];
   k=0;
@@ -80,12 +77,9 @@ uint32_t sub_block_interleaving_turbo(uint32_t D, uint8_t *d,uint8_t *w)
     index3 = bitrev_x3[col];//3*index;
 
     for (row=0; row<RTC; row++) {
-
       w[k]            =  d1[index3];//d[index3-ND3];
       w[Kpi+k2]       =  d2[index3];//d[index3-ND3+1];
       w[Kpi+1+k2]     =  d3[index3];//d[index3-ND3+5];
-
-
 #ifdef RM_DEBUG
       printf("row %d, index %d, index-Nd %d index-Nd+1 %d (k,Kpi+2k,Kpi+2k+1) (%d,%d,%d) w(%d,%d,%d)\n",row,index,index-ND,((index+1)%Kpi)-ND,k,Kpi+(k<<1),Kpi+(k<<1)+1,w[k],w[Kpi+(k<<1)],w[Kpi+1+(k<<1)]);
 
@@ -100,7 +94,8 @@ uint32_t sub_block_interleaving_turbo(uint32_t D, uint8_t *d,uint8_t *w)
 
 #endif
       index3+=96;
-      k++;k2+=2;
+      k++;
+      k2+=2;
     }
   }
 
@@ -120,9 +115,7 @@ uint32_t sub_block_interleaving_turbo(uint32_t D, uint8_t *d,uint8_t *w)
 }
 
 
-uint32_t sub_block_interleaving_cc(uint32_t D, uint8_t *d,uint8_t *w)
-{
-
+uint32_t sub_block_interleaving_cc(uint32_t D, uint8_t *d,uint8_t *w) {
   uint32_t RCC = (D>>5), ND, ND3;
   uint32_t row,col,Kpi,index;
   uint32_t index3,k;
@@ -141,7 +134,6 @@ uint32_t sub_block_interleaving_cc(uint32_t D, uint8_t *d,uint8_t *w)
   printf("RCC = %d, Kpi=%d, ND=%d\n",RCC,Kpi,ND);
 #endif
   ND3 = ND*3;
-
   k=0;
 
   for (col=0; col<32; col++) {
@@ -180,9 +172,7 @@ uint32_t sub_block_interleaving_cc(uint32_t D, uint8_t *d,uint8_t *w)
   return(RCC);
 }
 
-void sub_block_deinterleaving_turbo(uint32_t D,int16_t *d,int16_t *w)
-{
-
+void sub_block_deinterleaving_turbo(uint32_t D,int16_t *d,int16_t *w) {
   uint32_t RTC = (D>>5), ND, ND3;
   uint32_t row,col,Kpi,index;
   uint32_t index3,k,k2;
@@ -199,7 +189,6 @@ void sub_block_deinterleaving_turbo(uint32_t D,int16_t *d,int16_t *w)
   printf("RTC = %d, Kpi=%d, ND=%d\n",RTC,Kpi,ND);
 #endif
   ND3 = ND*3;
-
   // copy d02 to dD2 (for mod Kpi operation from clause (4), p.16 of 36.212
   k=0;
   k2=0;
@@ -215,7 +204,6 @@ void sub_block_deinterleaving_turbo(uint32_t D,int16_t *d,int16_t *w)
     index3 = bitrev_x3[col];//3*index;
 
     for (row=0; row<RTC; row++) {
-
       d1[index3]   = w[k];
       d2[index3]   = w[Kpi+k2];
       d3[index3]   = w[Kpi+1+k2];
@@ -229,12 +217,9 @@ void sub_block_deinterleaving_turbo(uint32_t D,int16_t *d,int16_t *w)
 
   //  if (ND>0)
   //    d[2] = LTE_NULL;//d[(3*D)+2];
-
 }
 
-void sub_block_deinterleaving_cc(uint32_t D,int8_t *d,int8_t *w)
-{
-
+void sub_block_deinterleaving_cc(uint32_t D,int8_t *d,int8_t *w) {
   //WANG_Hao uint32_t RCC = (D>>5), ND, ND3;
   uint32_t RCC = (D>>5);
   ptrdiff_t   ND, ND3;
@@ -251,10 +236,9 @@ void sub_block_deinterleaving_cc(uint32_t D,int8_t *d,int8_t *w)
   ND = Kpi - D;
 #ifdef RM_DEBUG2
   printf("sub_block_interleaving_cc : D = %d (%d), d %p, w %p\n",D,D*3,d,w);
-  printf("RCC = %d, Kpi=%d, ND=%d\n",RCC,Kpi,ND);
+  printf("RCC = %d, Kpi=%d, ND=%ld\n",RCC,Kpi,(long)ND);
 #endif
   ND3 = ND*3;
-
   k=0;
 
   for (col=0; col<32; col++) {
@@ -265,24 +249,21 @@ void sub_block_deinterleaving_cc(uint32_t D,int8_t *d,int8_t *w)
     index3 = 3*index;
 
     for (row=0; row<RCC; row++) {
-
       d[index3-ND3]   = w[k];
       d[index3-ND3+1] = w[Kpi+k];
       d[index3-ND3+2] = w[(Kpi<<1)+k];
 #ifdef RM_DEBUG2
-      printf("row %d, index %d k %d index3-ND3 %d w(%d,%d,%d)\n",row,index,k,index3-ND3,w[k],w[Kpi+k],w[(Kpi<<1)+k]);
+      printf("row %d, index %d k %d index3-ND3 %ld w(%d,%d,%d)\n",
+             row,index,k,(long)(index3-ND3),w[k],w[Kpi+k],w[(Kpi<<1)+k]);
 #endif
       index3+=96;
       index+=32;
       k++;
     }
   }
-
 }
 
-uint32_t generate_dummy_w(uint32_t D, uint8_t *w,uint8_t F)
-{
-
+uint32_t generate_dummy_w(uint32_t D, uint8_t *w,uint8_t F) {
   uint32_t RTC = (D>>5), ND;
   uint32_t col,Kpi,index;
   int32_t k,k2;
@@ -301,8 +282,6 @@ uint32_t generate_dummy_w(uint32_t D, uint8_t *w,uint8_t F)
   printf("dummy sub_block_interleaving_turbo : D = %d (%d)\n",D,D*3);
   printf("RTC = %d, Kpi=%d, ND=%d, F=%d (Nulled %d)\n",RTC,Kpi,ND,F,(2*F + 3*ND));
 #endif
-
-
   k=0;
   k2=0;
   wKpi = &w[Kpi];
@@ -371,9 +350,7 @@ uint32_t generate_dummy_w(uint32_t D, uint8_t *w,uint8_t F)
   return(RTC);
 }
 
-uint32_t generate_dummy_w_cc(uint32_t D, uint8_t *w)
-{
-
+uint32_t generate_dummy_w_cc(uint32_t D, uint8_t *w) {
   uint32_t RCC = (D>>5), ND;
   uint32_t col,Kpi,index;
   int32_t k;
@@ -392,7 +369,6 @@ uint32_t generate_dummy_w_cc(uint32_t D, uint8_t *w)
   printf("RCC = %d, Kpi=%d, ND=%d, (Nulled %d)\n",RCC,Kpi,ND,3*ND);
 #endif
   //  ND3 = ND*3;
-
   // copy d02 to dD2 (for mod Kpi operation from clause (4), p.16 of 36.212
   k=0;
 
@@ -466,8 +442,6 @@ uint32_t lte_rate_matching_turbo(uint32_t RTC,
                                  uint8_t nb_rb)
 //                                 uint8_t m)
 {
-
-
   uint32_t Nir,Ncb,Gp,GpmodC,E,Ncbmod,ind,k;
   //  int cnt=0;
   uint8_t *e2;
@@ -480,18 +454,17 @@ uint32_t lte_rate_matching_turbo(uint32_t RTC,
   int threed =0;
   uint32_t nulled=0;
   static unsigned char *counter_buffer[MAX_NUM_DLSCH_SEGMENTS][4];
-  FILE *counter_fd;
   char fname[512];
 #endif
 
   if (Mdlharq>0) {  // Downlink
     Nir = Nsoft/Kmimo/cmin(8,Mdlharq);
     Ncb = cmin(Nir/C,3*(RTC<<5));
-  }
-  else {  // Uplink
+  } else { // Uplink
     Nir=0;
     Ncb = 3*(RTC<<5); // Kw
   }
+
 #ifdef RM_DEBUG_TX
 
   if (rvidx==0 && r==0) {
@@ -503,7 +476,6 @@ uint32_t lte_rate_matching_turbo(uint32_t RTC,
   } else if(rvidx==3) {
     sprintf(fname, "mcs%d_rate_matching_RB_%d.txt", m, nb_rb);
     // sprintf(fname,"mcs0_rate_matching_RB_6.txt");
-    counter_fd = fopen(fname,"w");
   }
 
 #endif
@@ -518,9 +490,8 @@ uint32_t lte_rate_matching_turbo(uint32_t RTC,
   AssertFatal(Qm>0,"Qm is 0\n");
   Gp = G/Nl/Qm;
   GpmodC = Gp%C;
-
 #ifdef RM_DEBUG
-  printf("lte_rate_matching_turbo: Ncb %d, Kw %d, Nir/C %d, rvidx %d, G %d, Qm %d, Nl%d, r %d\n",Ncb,3*(RTC<<5),Nir/C,rvidx, G, Qm,Nl,r);
+  LOG_D(PHY,"lte_rate_matching_turbo: Ncb %d, Kw %d, Nir/C %d, rvidx %d, G %d, Qm %d, Nl%d, r %d\n",Ncb,3*(RTC<<5),Nir/C,rvidx, G, Qm,Nl,r);
 #endif
 
   if (r < (C-(GpmodC)))
@@ -529,16 +500,12 @@ uint32_t lte_rate_matching_turbo(uint32_t RTC,
     E = Nl*Qm * ((GpmodC==0?0:1) + (Gp/C));
 
   Ncbmod = Ncb%(RTC<<3);
-
   ind = RTC * (2+(rvidx*(((Ncbmod==0)?0:1) + (Ncb/(RTC<<3)))*2));
-
 #ifdef RM_DEBUG_TX
   printf("lte_rate_matching_turbo: E %d, k0 %d, Ncbmod %d, Ncb/(RTC<<3) %d\n",E,ind,Ncbmod,Ncb/(RTC<<3));
 #endif
-
   //e2=e+(r*E);
   e2 = e;
-
   k=0;
 
   for (; (ind<Ncb)&&(k<E); ind++) {
@@ -633,25 +600,16 @@ uint32_t lte_rate_matching_turbo(uint32_t RTC,
 uint32_t lte_rate_matching_cc(uint32_t RCC,
                               uint16_t E,
                               uint8_t *w,
-                              uint8_t *e)
-{
-
-
+                              uint8_t *e) {
   uint32_t ind=0,k;
-
   uint16_t Kw = 3*(RCC<<5);
-
 #ifdef RM_DEBUG_CC
   uint32_t nulled=0;
-
   printf("lte_rate_matching_cc: Kw %d, E %d\n",Kw, E);
 #endif
 
   for (k=0; k<E; k++) {
-
-
     while(w[ind] == LTE_NULL) {
-
 #ifdef RM_DEBUG_CC
       nulled++;
       printf("RM_TX_CC : ind %d, NULL\n",ind);
@@ -662,7 +620,6 @@ uint32_t lte_rate_matching_cc(uint32_t RCC,
         ind=0;
     }
 
-
     e[k] = w[ind];
 #ifdef RM_DEBUG_CC
     //    printf("k %d ind %d, w %c(%d)\n",k,ind,w[ind],w[ind]);
@@ -695,10 +652,7 @@ int lte_rate_matching_turbo_rx(uint32_t RTC,
                                uint8_t Qm,
                                uint8_t Nl,
                                uint8_t r,
-                               uint32_t *E_out)
-{
-
-
+                               uint32_t *E_out) {
   uint32_t Nir,Ncb,Gp,GpmodC,E,Ncbmod,ind,k;
   int16_t *soft_input2;
   //   int32_t w_tmp;
@@ -708,15 +662,14 @@ int lte_rate_matching_turbo_rx(uint32_t RTC,
 
   if (Kmimo==0 || C==0 || Qm==0 || Nl==0) {
     printf("lte_rate_matching.c: invalid parameters (Kmimo %d, Mdlharq %d, C %d, Qm %d, Nl %d\n",
-        Kmimo,Mdlharq,C,Qm,Nl);
+           Kmimo,Mdlharq,C,Qm,Nl);
     return(-1);
   }
 
   if (Mdlharq>0) { // Downlink
     Nir = Nsoft/Kmimo/cmin(8,Mdlharq);
     Ncb = cmin(Nir/C,3*(RTC<<5));
-  }
-  else {  // Uplink
+  } else { // Uplink
     Nir=0;
     Ncb = 3*(RTC<<5);
   }
@@ -726,17 +679,13 @@ int lte_rate_matching_turbo_rx(uint32_t RTC,
   Gp = G/Nl/Qm;
   GpmodC = Gp%C;
 
-
-
   if (r < (C-(GpmodC)))
     E = Nl*Qm * (Gp/C);
   else
     E = Nl*Qm * ((GpmodC==0?0:1) + (Gp/C));
 
   Ncbmod = Ncb%(RTC<<3);
-
   ind = RTC * (2+(rvidx*(((Ncbmod==0)?0:1) + (Ncb/(RTC<<3)))*2));
-
 #ifdef RM_DEBUG
   printf("lte_rate_matching_turbo_rx: Clear %d, E %d, Ncb %d, Kw %d, rvidx %d, G %d, Qm %d, Nl%d, r %d\n",clear,E,Ncb,3*(RTC<<5),rvidx, G, Qm,Nl,r);
 #endif
@@ -751,8 +700,8 @@ int lte_rate_matching_turbo_rx(uint32_t RTC,
     if (dummy_w[ind] != LTE_NULL) {
       /*
       if ((w[ind]>0 && soft_input2[k]<0) ||
-	  (w[ind]<0 && soft_input2[k]>0))
-	  printf("ind %d: w %d => soft_in %d\n",ind,w[ind],soft_input2[k]);*/
+      (w[ind]<0 && soft_input2[k]>0))
+      printf("ind %d: w %d => soft_in %d\n",ind,w[ind],soft_input2[k]);*/
       w[ind] += soft_input2[k++];
 #ifdef RM_DEBUG
       printf("RM_RX k%d Ind: %d (%d)\n",k-1,ind,w[ind]);
@@ -831,10 +780,8 @@ int lte_rate_matching_turbo_rx(uint32_t RTC,
       ind=0;
   }
   */
-
   *E_out = E;
   return(0);
-
 }
 
 
@@ -842,28 +789,19 @@ void lte_rate_matching_cc_rx(uint32_t RCC,
                              uint16_t E,
                              int8_t *w,
                              uint8_t *dummy_w,
-                             int8_t *soft_input)
-{
-
-
-
+                             int8_t *soft_input) {
   uint32_t ind=0,k;
   uint16_t Kw = 3*(RCC<<5);
   uint32_t acc=1;
   int16_t w16[Kw];
 #ifdef RM_DEBUG_CC
   uint32_t nulled=0;
-
   printf("lte_rate_matching_cc_rx: Kw %d, E %d, w %p, soft_input %p\n",3*(RCC<<5),E,w,soft_input);
 #endif
-
-
   memset(w,0,Kw);
   memset(w16,0,Kw*sizeof(int16_t));
 
   for (k=0; k<E; k++) {
-
-
     while(dummy_w[ind] == LTE_NULL) {
 #ifdef RM_DEBUG_CC
       nulled++;
@@ -883,10 +821,7 @@ void lte_rate_matching_cc_rx(uint32_t RCC,
 #ifdef RM_DEBUG_CC
     printf("RM_RX_CC k %d (%d) ind: %d (%d)\n",k,soft_input[k],ind,w16[ind]);
 #endif
-
-
     w16[ind] += soft_input[k];
-
     ind++;
 
     if (ind==Kw) {
@@ -907,7 +842,6 @@ void lte_rate_matching_cc_rx(uint32_t RCC,
   }
 
 #ifdef RM_DEBUG_CC
-
   printf("Nulled %d\n",nulled);
 #endif
 }
@@ -915,8 +849,7 @@ void lte_rate_matching_cc_rx(uint32_t RCC,
 
 #ifdef MAIN
 
-void main()
-{
+void main() {
   uint8_t d[96+3+(3*6144)];
   uint8_t w[3*6144],e[12*6144];
   uint32_t RTC,G,rvidx;
@@ -924,7 +857,6 @@ void main()
   uint32_t mod_order = 4;
   uint32_t first_dlsch_symbol = 2;
   uint32_t i;
-
   G = ( nb_rb * (12 * mod_order) * (12-first_dlsch_symbol-3)) ;//( nb_rb * (12 * mod_order) * (14-first_dlsch_symbol-3)) :
 
   // initialize 96 first positions to "LTE_NULL"
diff --git a/openair1/PHY/CODING/lte_segmentation.c b/openair1/PHY/CODING/lte_segmentation.c
index ba79b0171e4e31dac4d411e07b4ab22b66263cbf..0f9f8b00e0b817d8c475105dcf9e53021da16be3 100644
--- a/openair1/PHY/CODING/lte_segmentation.c
+++ b/openair1/PHY/CODING/lte_segmentation.c
@@ -38,9 +38,7 @@ int lte_segmentation(unsigned char *input_buffer,
                      unsigned int *Cminus,
                      unsigned int *Kplus,
                      unsigned int *Kminus,
-                     unsigned int *F)
-{
-
+                     unsigned int *F) {
   unsigned int L,Bprime,Bprime_by_C,r,Kr,k,s,crc;
 
   if (B<=6144) {
@@ -56,19 +54,19 @@ int lte_segmentation(unsigned char *input_buffer,
 
     Bprime = B+((*C)*L);
 #ifdef DEBUG_SEGMENTATION
-    printf("Bprime %d\n",Bprime);
+    printf("Bprime %u\n",Bprime);
 #endif
   }
 
   if ((*C)>MAX_NUM_DLSCH_SEGMENTS) {
-      LOG_E(PHY,"lte_segmentation.c: too many segments %d, B %d, L %d, Bprime %d\n",*C,B,L,Bprime);
+    LOG_E(PHY,"lte_segmentation.c: too many segments %d, B %d, L %d, Bprime %d\n",*C,B,L,Bprime);
     return(-1);
   }
 
   // Find K+
   Bprime_by_C  = Bprime/(*C);
 #ifdef DEBUG_SEGMENTATION
-  printf("Bprime_by_C %d\n",Bprime_by_C);
+  printf("Bprime_by_C %u\n",Bprime_by_C);
 #endif
   //  Bprime = Bprime_by_C>>3;
 
@@ -93,17 +91,16 @@ int lte_segmentation(unsigned char *input_buffer,
 
     *Kminus = (*Kplus - 32);
   } else if (Bprime_by_C <=6144 ) { // increase by 8 bytes til here
-
     *Kplus = (Bprime_by_C>>6)<<6;
 #ifdef DEBUG_SEGMENTATION
-    printf("Bprime_by_C_by_C %d , Kplus %d\n",Bprime_by_C,*Kplus);
+    printf("Bprime_by_C_by_C %u , Kplus %u\n",Bprime_by_C,*Kplus);
 #endif
 
     if (*Kplus < Bprime_by_C)
       *Kplus = *Kplus + 64;
 
 #ifdef DEBUG_SEGMENTATION
-    printf("Bprime_by_C_by_C %d , Kplus2 %d\n",Bprime_by_C,*Kplus);
+    printf("Bprime_by_C_by_C %u , Kplus2 %u\n",Bprime_by_C,*Kplus);
 #endif
     *Kminus = (*Kplus - 64);
   } else {
@@ -116,25 +113,22 @@ int lte_segmentation(unsigned char *input_buffer,
     *Kminus = 0;
     *Cminus = 0;
   } else {
-
     //    printf("More than one segment (%d), exiting \n",*C);
     //    exit(-1);
     *Cminus = ((*C)*(*Kplus) - (Bprime))/((*Kplus) - (*Kminus));
     *Cplus  = (*C) - (*Cminus);
   }
 
-
   AssertFatal(Bprime <= (*Cplus)*(*Kplus) + (*Cminus)*(*Kminus),
-	      "Bprime %d <  (*Cplus %d)*(*Kplus %d) + (*Cminus %d)*(*Kminus %d)\n",
-	      Bprime,*Cplus,*Kplus,*Cminus,*Kminus);
-
+              "Bprime %d <  (*Cplus %d)*(*Kplus %d) + (*Cminus %d)*(*Kminus %d)\n",
+              Bprime,*Cplus,*Kplus,*Cminus,*Kminus);
   *F = ((*Cplus)*(*Kplus) + (*Cminus)*(*Kminus) - (Bprime));
 #ifdef DEBUG_SEGMENTATION
-  printf("C %d, Cplus %d, Cminus %d, Kplus %d, Kminus %d, Bprime_bytes %d, Bprime %d, F %d\n",*C,*Cplus,*Cminus,*Kplus,*Kminus,Bprime>>3,Bprime,*F);
+  printf("C %u, Cplus %u, Cminus %u, Kplus %u, Kminus %u, Bprime_bytes %u, Bprime %u, F %u\n",
+         *C,*Cplus,*Cminus,*Kplus,*Kminus,Bprime>>3,Bprime,*F);
 #endif
 
   if ((input_buffer) && (output_buffers)) {
-
     for (k=0; k<*F>>3; k++) {
       output_buffers[0][k] = 0;
     }
@@ -142,7 +136,6 @@ int lte_segmentation(unsigned char *input_buffer,
     s=0;
 
     for (r=0; r<*C; r++) {
-
       if (r<*Cminus)
         Kr = *Kminus;
       else
@@ -150,18 +143,18 @@ int lte_segmentation(unsigned char *input_buffer,
 
       while (k<((Kr - L)>>3)) {
         output_buffers[r][k] = input_buffer[s];
-	//	printf("encoding segment %d : byte %d (%d) => %d\n",r,k,Kr>>3,input_buffer[s]);
+        //  printf("encoding segment %d : byte %d (%d) => %d\n",r,k,Kr>>3,input_buffer[s]);
         k++;
         s++;
       }
 
       if (*C > 1) { // add CRC
         crc = crc24b(output_buffers[r],Kr-24)>>8;
-        output_buffers[r][(Kr-24)>>3] = ((uint8_t*)&crc)[2];
-        output_buffers[r][1+((Kr-24)>>3)] = ((uint8_t*)&crc)[1];
-        output_buffers[r][2+((Kr-24)>>3)] = ((uint8_t*)&crc)[0];
+        output_buffers[r][(Kr-24)>>3] = ((uint8_t *)&crc)[2];
+        output_buffers[r][1+((Kr-24)>>3)] = ((uint8_t *)&crc)[1];
+        output_buffers[r][2+((Kr-24)>>3)] = ((uint8_t *)&crc)[0];
 #ifdef DEBUG_SEGMENTATION
-        printf("Segment %d : CRC %x\n",r,crc);
+        printf("Segment %u : CRC %x\n",r,crc);
 #endif
       }
 
@@ -175,9 +168,7 @@ int lte_segmentation(unsigned char *input_buffer,
 
 
 #ifdef MAIN
-main()
-{
-
+main() {
   unsigned int Kplus,Kminus,C,Cplus,Cminus,F,Bbytes;
 
   for (Bbytes=5; Bbytes<2*768; Bbytes++) {
diff --git a/openair1/PHY/CODING/scrambler.h b/openair1/PHY/CODING/scrambler.h
deleted file mode 100644
index 3c1b1de0a71eb8b0198ea114dbb109f755d11005..0000000000000000000000000000000000000000
--- a/openair1/PHY/CODING/scrambler.h
+++ /dev/null
@@ -1,1047 +0,0 @@
-/*
- * 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
- */
-
-unsigned char scrambling_sequence[1024] = {
-  208,
-  127,
-  52,
-  95,
-  204,
-  135,
-  48,
-  31,
-  248,
-  32,
-  208,
-  135,
-  192,
-  232,
-  63,
-  175,
-  4,
-  212,
-  119,
-  24,
-  169,
-  162,
-  101,
-  144,
-  75,
-  109,
-  75,
-  29,
-  91,
-  191,
-  165,
-  246,
-  177,
-  71,
-  16,
-  92,
-  68,
-  80,
-  132,
-  4,
-  248,
-  251,
-  32,
-  65,
-  125,
-  56,
-  94,
-  86,
-  152,
-  11,
-  201,
-  134,
-  39,
-  250,
-  19,
-  162,
-  25,
-  190,
-  62,
-  3,
-  190,
-  18,
-  188,
-  215,
-  97,
-  239,
-  72,
-  11,
-  0,
-  26,
-  57,
-  211,
-  146,
-  37,
-  205,
-  121,
-  204,
-  83,
-  13,
-  206,
-  53,
-  27,
-  214,
-  32,
-  54,
-  214,
-  82,
-  125,
-  226,
-  108,
-  169,
-  102,
-  247,
-  255,
-  32,
-  171,
-  201,
-  112,
-  20,
-  253,
-  65,
-  192,
-  38,
-  78,
-  114,
-  40,
-  95,
-  32,
-  70,
-  194,
-  242,
-  153,
-  207,
-  63,
-  61,
-  117,
-  122,
-  32,
-  73,
-  60,
-  160,
-  140,
-  99,
-  235,
-  118,
-  176,
-  75,
-  102,
-  254,
-  5,
-  67,
-  194,
-  122,
-  62,
-  226,
-  56,
-  69,
-  123,
-  213,
-  179,
-  119,
-  221,
-  23,
-  63,
-  26,
-  160,
-  233,
-  166,
-  179,
-  243,
-  169,
-  190,
-  183,
-  146,
-  169,
-  185,
-  216,
-  214,
-  158,
-  86,
-  139,
-  214,
-  143,
-  181,
-  0,
-  9,
-  147,
-  254,
-  105,
-  138,
-  213,
-  118,
-  14,
-  74,
-  153,
-  110,
-  41,
-  47,
-  172,
-  91,
-  216,
-  117,
-  156,
-  62,
-  56,
-  75,
-  113,
-  6,
-  123,
-  178,
-  118,
-  97,
-  82,
-  75,
-  96,
-  21,
-  148,
-  170,
-  120,
-  227,
-  0,
-  245,
-  25,
-  147,
-  243,
-  185,
-  203,
-  135,
-  48,
-  104,
-  89,
-  38,
-  71,
-  30,
-  74,
-  219,
-  130,
-  107,
-  75,
-  244,
-  138,
-  8,
-  8,
-  248,
-  175,
-  65,
-  234,
-  35,
-  125,
-  138,
-  0,
-  95,
-  23,
-  171,
-  177,
-  166,
-  196,
-  173,
-  235,
-  244,
-  124,
-  20,
-  22,
-  78,
-  32,
-  207,
-  173,
-  103,
-  232,
-  84,
-  18,
-  227,
-  246,
-  127,
-  136,
-  28,
-  188,
-  39,
-  132,
-  79,
-  14,
-  62,
-  80,
-  248,
-  171,
-  21,
-  160,
-  188,
-  110,
-  125,
-  55,
-  198,
-  139,
-  185,
-  28,
-  127,
-  239,
-  246,
-  223,
-  47,
-  55,
-  63,
-  63,
-  129,
-  253,
-  175,
-  122,
-  182,
-  139,
-  52,
-  163,
-  164,
-  177,
-  6,
-  187,
-  220,
-  159,
-  76,
-  36,
-  164,
-  108,
-  218,
-  189,
-  250,
-  148,
-  201,
-  45,
-  207,
-  174,
-  81,
-  195,
-  108,
-  96,
-  203,
-  132,
-  210,
-  34,
-  142,
-  247,
-  238,
-  139,
-  84,
-  84,
-  194,
-  168,
-  46,
-  9,
-  238,
-  29,
-  135,
-  115,
-  95,
-  12,
-  218,
-  18,
-  134,
-  110,
-  83,
-  110,
-  44,
-  80,
-  80,
-  216,
-  126,
-  160,
-  65,
-  142,
-  142,
-  209,
-  69,
-  234,
-  200,
-  184,
-  171,
-  248,
-  185,
-  148,
-  203,
-  90,
-  143,
-  231,
-  29,
-  47,
-  214,
-  151,
-  154,
-  137,
-  152,
-  228,
-  192,
-  182,
-  108,
-  200,
-  226,
-  204,
-  82,
-  170,
-  110,
-  197,
-  143,
-  169,
-  230,
-  75,
-  204,
-  177,
-  222,
-  142,
-  1,
-  104,
-  130,
-  224,
-  201,
-  29,
-  223,
-  246,
-  132,
-  173,
-  42,
-  33,
-  165,
-  147,
-  208,
-  124,
-  208,
-  198,
-  51,
-  78,
-  76,
-  216,
-  164,
-  250,
-  186,
-  214,
-  57,
-  52,
-  52,
-  199,
-  37,
-  3,
-  242,
-  120,
-  179,
-  26,
-  233,
-  51,
-  42,
-  11,
-  108,
-  26,
-  41,
-  192,
-  41,
-  221,
-  71,
-  16,
-  67,
-  131,
-  90,
-  226,
-  181,
-  0,
-  244,
-  183,
-  31,
-  78,
-  241,
-  221,
-  173,
-  248,
-  146,
-  23,
-  244,
-  102,
-  194,
-  201,
-  16,
-  25,
-  155,
-  110,
-  146,
-  54,
-  246,
-  40,
-  5,
-  78,
-  94,
-  47,
-  135,
-  60,
-  103,
-  29,
-  175,
-  142,
-  9,
-  213,
-  70,
-  159,
-  168,
-  176,
-  217,
-  91,
-  13,
-  1,
-  254,
-  104,
-  135,
-  20,
-  135,
-  147,
-  23,
-  141,
-  8,
-  115,
-  180,
-  201,
-  50,
-  246,
-  4,
-  12,
-  72,
-  59,
-  166,
-  22,
-  61,
-  77,
-  140,
-  183,
-  150,
-  255,
-  55,
-  31,
-  71,
-  215,
-  83,
-  75,
-  169,
-  137,
-  104,
-  237,
-  88,
-  118,
-  146,
-  247,
-  95,
-  182,
-  241,
-  29,
-  98,
-  243,
-  152,
-  52,
-  230,
-  114,
-  27,
-  247,
-  116,
-  78,
-  152,
-  202,
-  96,
-  15,
-  112,
-  196,
-  245,
-  148,
-  9,
-  228,
-  111,
-  131,
-  179,
-  198,
-  243,
-  35,
-  140,
-  234,
-  248,
-  8,
-  197,
-  218,
-  35,
-  246,
-  172,
-  207,
-  93,
-  62,
-  157,
-  196,
-  149,
-  199,
-  136,
-  30,
-  70,
-  13,
-  116,
-  63,
-  171,
-  207,
-  254,
-  51,
-  18,
-  126,
-  246,
-  195,
-  218,
-  222,
-  204,
-  105,
-  132,
-  150,
-  123,
-  136,
-  24,
-  23,
-  143,
-  162,
-  175,
-  185,
-  148,
-  104,
-  135,
-  118,
-  44,
-  126,
-  59,
-  67,
-  114,
-  157,
-  194,
-  201,
-  231,
-  40,
-  80,
-  42,
-  195,
-  50,
-  133,
-  186,
-  43,
-  134,
-  234,
-  170,
-  96,
-  177,
-  67,
-  61,
-  121,
-  31,
-  171,
-  120,
-  208,
-  74,
-  84,
-  33,
-  148,
-  199,
-  59,
-  171,
-  244,
-  243,
-  114,
-  92,
-  90,
-  99,
-  89,
-  181,
-  25,
-  224,
-  39,
-  149,
-  209,
-  40,
-  151,
-  1,
-  171,
-  106,
-  75,
-  126,
-  134,
-  35,
-  187,
-  12,
-  31,
-  114,
-  240,
-  229,
-  182,
-  48,
-  86,
-  192,
-  247,
-  109,
-  78,
-  111,
-  74,
-  207,
-  72,
-  232,
-  177,
-  126,
-  167,
-  213,
-  139,
-  124,
-  122,
-  18,
-  108,
-  35,
-  213,
-  86,
-  218,
-  226,
-  143,
-  169,
-  11,
-  165,
-  137,
-  241,
-  146,
-  115,
-  208,
-  178,
-  197,
-  0,
-  119,
-  147,
-  29,
-  144,
-  167,
-  236,
-  133,
-  233,
-  23,
-  140,
-  30,
-  186,
-  159,
-  76,
-  6,
-  150,
-  13,
-  72,
-  34,
-  240,
-  114,
-  192,
-  238,
-  72,
-  42,
-  177,
-  15,
-  33,
-  162,
-  170,
-  167,
-  64,
-  169,
-  78,
-  162,
-  226,
-  229,
-  191,
-  209,
-  140,
-  213,
-  161,
-  23,
-  147,
-  249,
-  103,
-  56,
-  153,
-  108,
-  105,
-  148,
-  177,
-  245,
-  168,
-  201,
-  101,
-  103,
-  5,
-  104,
-  90,
-  171,
-  155,
-  153,
-  121,
-  130,
-  35,
-  112,
-  242,
-  140,
-  206,
-  125,
-  225,
-  79,
-  154,
-  161,
-  143,
-  71,
-  45,
-  145,
-  15,
-  95,
-  105,
-  202,
-  158,
-  11,
-  119,
-  124,
-  66,
-  60,
-  86,
-  118,
-  120,
-  101,
-  209,
-  58,
-  211,
-  184,
-  42,
-  142,
-  66,
-  201,
-  147,
-  149,
-  26,
-  213,
-  168,
-  108,
-  93,
-  237,
-  168,
-  152,
-  128,
-  44,
-  87,
-  140,
-  248,
-  218,
-  189,
-  93,
-  25,
-  76,
-  249,
-  103,
-  187,
-  167,
-  31,
-  194,
-  133,
-  247,
-  148,
-  20,
-  169,
-  141,
-  166,
-  118,
-  102,
-  208,
-  187,
-  177,
-  71,
-  70,
-  182,
-  55,
-  205,
-  174,
-  20,
-  234,
-  146,
-  78,
-  115,
-  199,
-  104,
-  89,
-  254,
-  232,
-  246,
-  208,
-  127,
-  242,
-  221,
-  200,
-  198,
-  66,
-  153,
-  12,
-  25,
-  184,
-  78,
-  203,
-  45,
-  233,
-  51,
-  253,
-  169,
-  30,
-  5,
-  65,
-  188,
-  226,
-  167,
-  236,
-  17,
-  173,
-  193,
-  123,
-  249,
-  117,
-  107,
-  140,
-  56,
-  91,
-  180,
-  19,
-  79,
-  5,
-  204,
-  185,
-  109,
-  37,
-  187,
-  147,
-  197,
-  58,
-  100,
-  40,
-  11,
-  22,
-  248,
-  236,
-  189,
-  218,
-  3,
-  109,
-  243,
-  153,
-  247,
-  142,
-  35,
-  59,
-  228,
-  102,
-  130,
-  141,
-  200,
-  201,
-  101,
-  139,
-  129,
-  21,
-  246,
-  111,
-  143,
-  95,
-  249,
-  7,
-  196,
-  85,
-  133,
-  175,
-  59,
-  130,
-  214,
-  255,
-  36,
-  49,
-  209,
-  144,
-  168,
-  20,
-  126,
-  19,
-  198,
-  119,
-  221,
-  229,
-  245,
-  173,
-  218,
-  244,
-  14,
-  53,
-  221,
-  252,
-  107,
-  213,
-  65,
-  129,
-  23,
-  187,
-  196,
-  118,
-  77,
-  205,
-  9,
-  75,
-  179,
-  23,
-  176,
-  49,
-  41,
-  84,
-  163,
-  182,
-  156,
-  167,
-  247,
-  95,
-  212,
-  43,
-  183,
-  152,
-  63,
-  252,
-  67,
-  21,
-  224,
-  128,
-  201,
-  251,
-  136,
-  117,
-  214,
-  96,
-  226,
-  157,
-  79,
-  154,
-  98,
-  120,
-  65,
-  134,
-  130,
-  138,
-  197,
-  64,
-  171,
-  85,
-  144,
-  120,
-  179,
-  180
-};
diff --git a/openair1/PHY/INIT/defs_NB_IoT.h b/openair1/PHY/INIT/defs_NB_IoT.h
index b49936770f2411068e60729d838c61f09f62539a..d115a57f10fee5ead14876c78059fb4842252211 100644
--- a/openair1/PHY/INIT/defs_NB_IoT.h
+++ b/openair1/PHY/INIT/defs_NB_IoT.h
@@ -33,7 +33,7 @@
 //#include "TDD-Config.h"
 //#include "MBSFN-SubframeConfigList.h"
 //#include "MobilityControlInfo.h"
-//#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+//#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 //#include "SCellToAddMod-r10.h"
 //#endif
 
diff --git a/openair1/PHY/INIT/init_extern.h b/openair1/PHY/INIT/init_extern.h
deleted file mode 100644
index 4690bba42e5b91f4721d727b38d41da928e0c55a..0000000000000000000000000000000000000000
--- a/openair1/PHY/INIT/init_extern.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * 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
- */
-
diff --git a/openair1/PHY/INIT/init_top.c b/openair1/PHY/INIT/init_top.c
index 6240245bff3d222c26796e316bb6e4cfa5622351..6421eebe28a0cda990683148489eda7633233433 100644
--- a/openair1/PHY/INIT/init_top.c
+++ b/openair1/PHY/INIT/init_top.c
@@ -59,14 +59,11 @@ void generate_qpsk_table(void) {
   }
 }
 
-void init_7_5KHz(void);
 void init_lte_top(LTE_DL_FRAME_PARMS *frame_parms) {
   ccodelte_init();
   ccodelte_init_inv();
-  init_dfts();
   phy_generate_viterbi_tables_lte();
   load_codinglib();
-  lte_sync_time_init(frame_parms);
   generate_ul_ref_sigs();
   generate_ul_ref_sigs_rx();
   generate_64qam_table();
@@ -76,13 +73,11 @@ void init_lte_top(LTE_DL_FRAME_PARMS *frame_parms) {
   init_unscrambling_lut();
   init_scrambling_lut();
   //set_taus_seed(1328);
-//  init_7_5KHz();
   init_sss();
 }
 
 void free_lte_top(void) {
   free_codinglib();
-  lte_sync_time_free();
   /* free_ul_ref_sigs() is called in phy_free_lte_eNB() */
 }
 
diff --git a/openair1/PHY/INIT/init_vars.h b/openair1/PHY/INIT/init_vars.h
deleted file mode 100644
index 4690bba42e5b91f4721d727b38d41da928e0c55a..0000000000000000000000000000000000000000
--- a/openair1/PHY/INIT/init_vars.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * 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
- */
-
diff --git a/openair1/PHY/INIT/lte_init.c b/openair1/PHY/INIT/lte_init.c
index a26d00491c9c9ba5ce7f9d16336e4785b974dd06..c39a81c7a54ac38b5f4018123ca9d2804a8f1004 100644
--- a/openair1/PHY/INIT/lte_init.c
+++ b/openair1/PHY/INIT/lte_init.c
@@ -27,10 +27,10 @@
 #include "PHY/LTE_UE_TRANSPORT/transport_proto_ue.h"
 #include "PHY/LTE_REFSIG/lte_refsig.h"
 #include "SIMULATION/TOOLS/sim.h"
-#include "RadioResourceConfigCommonSIB.h"
-#include "RadioResourceConfigDedicated.h"
-#include "TDD-Config.h"
-#include "MBSFN-SubframeConfigList.h"
+#include "LTE_RadioResourceConfigCommonSIB.h"
+#include "LTE_RadioResourceConfigDedicated.h"
+#include "LTE_TDD-Config.h"
+#include "LTE_MBSFN-SubframeConfigList.h"
 #include "common/utils/LOG/vcd_signal_dumper.h"
 #include "assertions.h"
 #include <math.h>
@@ -40,12 +40,14 @@ extern int32_t get_uldl_offset(int eutra_bandP);
 
 extern uint16_t prach_root_sequence_map0_3[838];
 extern uint16_t prach_root_sequence_map4[138];
-uint8_t dmrs1_tab[8] = {0,2,3,4,6,8,9,10};
+uint8_t         dmrs1_tab[8] = { 0, 2, 3, 4, 6, 8, 9, 10 };
 
 
-int N_RB_DL_array[6] = {6,15,25,50,75,100};
+int             N_RB_DL_array[6] = { 6, 15, 25, 50, 75, 100 };
 
-int l1_north_init_eNB() {
+int
+l1_north_init_eNB ()
+{
 
   int i,j;
 
@@ -85,8 +87,8 @@ int l1_north_init_eNB() {
 
 void phy_config_request(PHY_Config_t *phy_config) {
 
-  uint8_t Mod_id              = phy_config->Mod_id;
-  int CC_id                   = phy_config->CC_id;
+  uint8_t         Mod_id = phy_config->Mod_id;
+  int             CC_id = phy_config->CC_id;
   nfapi_config_request_t *cfg = phy_config->cfg;
 
 
@@ -105,9 +107,9 @@ void phy_config_request(PHY_Config_t *phy_config) {
 	cfg->phich_config.phich_resource.value,
 	cfg->phich_config.phich_duration.value);
 
-  AssertFatal(RC.eNB != NULL, "PHY instance pointer doesn't exist\n");
-  AssertFatal(RC.eNB[Mod_id] != NULL, "PHY instance %d doesn't exist\n",Mod_id);
-  AssertFatal(RC.eNB[Mod_id][CC_id] != NULL, "PHY instance %d, CCid %d doesn't exist\n",Mod_id,CC_id);
+  AssertFatal (RC.eNB != NULL, "PHY instance pointer doesn't exist\n");
+  AssertFatal (RC.eNB[Mod_id] != NULL, "PHY instance %d doesn't exist\n", Mod_id);
+  AssertFatal (RC.eNB[Mod_id][CC_id] != NULL, "PHY instance %d, CCid %d doesn't exist\n", Mod_id, CC_id);
 
 
   if (RC.eNB[Mod_id][CC_id]->configured == 1)
@@ -116,7 +118,7 @@ void phy_config_request(PHY_Config_t *phy_config) {
     return;
   }
 
-  RC.eNB[Mod_id][CC_id]->mac_enabled     = 1;
+  RC.eNB[Mod_id][CC_id]->mac_enabled = 1;
 
   fp = &RC.eNB[Mod_id][CC_id]->frame_parms;
 
@@ -129,164 +131,157 @@ void phy_config_request(PHY_Config_t *phy_config) {
   fp->Ncp_UL                             = Ncp;
   fp->nb_antenna_ports_eNB               = p_eNB;
 
-  fp->threequarter_fs                    = 0;
+  fp->threequarter_fs = 0;
 
-  AssertFatal(cfg->phich_config.phich_resource.value<4, "Illegal phich_Resource\n");
+  AssertFatal (cfg->phich_config.phich_resource.value < 4, "Illegal phich_Resource\n");
 
   fp->phich_config_common.phich_resource = phich_resource_table[cfg->phich_config.phich_resource.value];
   fp->phich_config_common.phich_duration = cfg->phich_config.phich_duration.value;
   // Note: "from_earfcn" has to be in a common library with MACRLC
-  fp->dl_CarrierFreq                     = from_earfcn(eutra_band,dl_CarrierFreq);
-  fp->ul_CarrierFreq                     = fp->dl_CarrierFreq - (get_uldl_offset(eutra_band)*100000);
+  fp->dl_CarrierFreq = from_earfcn (eutra_band, dl_CarrierFreq);
+  fp->ul_CarrierFreq = fp->dl_CarrierFreq - (get_uldl_offset (eutra_band) * 100000);
 
-  fp->tdd_config                         = 0;
-  fp->tdd_config_S                       = 0;
+  fp->tdd_config = 0;
+  fp->tdd_config_S = 0;
 
-  if (fp->dl_CarrierFreq==fp->ul_CarrierFreq)
+  if (fp->dl_CarrierFreq == fp->ul_CarrierFreq)
     fp->frame_type = TDD;
   else
     fp->frame_type = FDD;
 
-  init_frame_parms(fp,1);
-  init_lte_top(fp);
+  init_frame_parms (fp, 1);
+  init_lte_top (fp);
 
   if (cfg->subframe_config.duplex_mode.value == 0) {
-    fp->tdd_config    = cfg->tdd_frame_structure_config.subframe_assignment.value;
-    fp->tdd_config_S  = cfg->tdd_frame_structure_config.special_subframe_patterns.value;
-    fp->frame_type    = TDD;
-  }
-  else {
-    fp->frame_type    = FDD;
+    fp->tdd_config = cfg->tdd_frame_structure_config.subframe_assignment.value;
+    fp->tdd_config_S = cfg->tdd_frame_structure_config.special_subframe_patterns.value;
+    fp->frame_type = TDD;
+  } else {
+    fp->frame_type = FDD;
   }
 
-  fp->prach_config_common.rootSequenceIndex                          = cfg->prach_config.root_sequence_index.value;
-  LOG_I(PHY,"prach_config_common.rootSequenceIndex = %d\n",cfg->prach_config.root_sequence_index.value);
-
-  fp->prach_config_common.prach_Config_enabled=1;
-
-  fp->prach_config_common.prach_ConfigInfo.prach_ConfigIndex          =cfg->prach_config.configuration_index.value;
-  LOG_I(PHY,"prach_config_common.prach_ConfigInfo.prach_ConfigIndex = %d\n",cfg->prach_config.configuration_index.value);
-
-  fp->prach_config_common.prach_ConfigInfo.highSpeedFlag              =cfg->prach_config.high_speed_flag.value;
-  LOG_I(PHY,"prach_config_common.prach_ConfigInfo.highSpeedFlag = %d\n",cfg->prach_config.high_speed_flag.value);
-  fp->prach_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig  =cfg->prach_config.zero_correlation_zone_configuration.value;
-  LOG_I(PHY,"prach_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig = %d\n",cfg->prach_config.zero_correlation_zone_configuration.value);
-  fp->prach_config_common.prach_ConfigInfo.prach_FreqOffset           =cfg->prach_config.frequency_offset.value;
-  LOG_I(PHY,"prach_config_common.prach_ConfigInfo.prach_FreqOffset = %d\n",cfg->prach_config.frequency_offset.value);
-
-  init_prach_tables(839);
-  compute_prach_seq(fp->prach_config_common.rootSequenceIndex,
-		    fp->prach_config_common.prach_ConfigInfo.prach_ConfigIndex,
-		    fp->prach_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig,
-		    fp->prach_config_common.prach_ConfigInfo.highSpeedFlag,
-		    fp->frame_type,
-                    RC.eNB[Mod_id][CC_id]->X_u);
+  fp->prach_config_common.rootSequenceIndex = cfg->prach_config.root_sequence_index.value;
+  LOG_I (PHY, "prach_config_common.rootSequenceIndex = %d\n", cfg->prach_config.root_sequence_index.value);
+
+  fp->prach_config_common.prach_Config_enabled = 1;
+
+  fp->prach_config_common.prach_ConfigInfo.prach_ConfigIndex = cfg->prach_config.configuration_index.value;
+  LOG_I (PHY, "prach_config_common.prach_ConfigInfo.prach_ConfigIndex = %d\n", cfg->prach_config.configuration_index.value);
+
+  fp->prach_config_common.prach_ConfigInfo.highSpeedFlag = cfg->prach_config.high_speed_flag.value;
+  LOG_I (PHY, "prach_config_common.prach_ConfigInfo.highSpeedFlag = %d\n", cfg->prach_config.high_speed_flag.value);
+  fp->prach_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig = cfg->prach_config.zero_correlation_zone_configuration.value;
+  LOG_I (PHY, "prach_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig = %d\n", cfg->prach_config.zero_correlation_zone_configuration.value);
+  fp->prach_config_common.prach_ConfigInfo.prach_FreqOffset = cfg->prach_config.frequency_offset.value;
+  LOG_I (PHY, "prach_config_common.prach_ConfigInfo.prach_FreqOffset = %d\n", cfg->prach_config.frequency_offset.value);
+
+  init_prach_tables (839);
+  compute_prach_seq (fp->prach_config_common.rootSequenceIndex,
+                     fp->prach_config_common.prach_ConfigInfo.prach_ConfigIndex,
+                     fp->prach_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig, fp->prach_config_common.prach_ConfigInfo.highSpeedFlag, fp->frame_type, RC.eNB[Mod_id][CC_id]->X_u);
+
+
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  if (cfg->emtc_config.prach_ce_level_0_enable.value == 1) {
+    fp->prach_emtc_config_common.prach_Config_enabled = 1;
+
+    fp->prach_emtc_config_common.rootSequenceIndex = cfg->emtc_config.prach_catm_root_sequence_index.value;
+
+    fp->prach_emtc_config_common.prach_ConfigInfo.highSpeedFlag = cfg->emtc_config.prach_catm_high_speed_flag.value;
+    fp->prach_emtc_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig = cfg->emtc_config.prach_catm_zero_correlation_zone_configuration.value;
+
+    // CE Level 3 parameters
+    fp->prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[3] = cfg->emtc_config.prach_ce_level_3_enable.value;
+    fp->prach_emtc_config_common.prach_ConfigInfo.prach_starting_subframe_periodicity[3] = cfg->emtc_config.prach_ce_level_3_starting_subframe_periodicity.value;
+    fp->prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[3] = cfg->emtc_config.prach_ce_level_3_number_of_repetitions_per_attempt.value;
+    AssertFatal (fp->prach_emtc_config_common.prach_ConfigInfo.prach_starting_subframe_periodicity[3] >= fp->prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[3],
+                 "prach_starting_subframe_periodicity[3] < prach_numPetitionPerPreambleAttempt[3]\n");
+
+
+    fp->prach_emtc_config_common.prach_ConfigInfo.prach_ConfigIndex[3] = cfg->emtc_config.prach_ce_level_3_configuration_index.value;
+    fp->prach_emtc_config_common.prach_ConfigInfo.prach_FreqOffset[3] = cfg->emtc_config.prach_ce_level_3_frequency_offset.value;
+    fp->prach_emtc_config_common.prach_ConfigInfo.prach_hopping_enable[3] = cfg->emtc_config.prach_ce_level_3_hopping_enable.value;
+    fp->prach_emtc_config_common.prach_ConfigInfo.prach_hopping_offset[3] = cfg->emtc_config.prach_ce_level_3_hopping_offset.value;
+    if (fp->prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[3] == 1)
+      compute_prach_seq (fp->prach_emtc_config_common.rootSequenceIndex,
+                         fp->prach_emtc_config_common.prach_ConfigInfo.prach_ConfigIndex[3],
+                         fp->prach_emtc_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig,
+                         fp->prach_emtc_config_common.prach_ConfigInfo.highSpeedFlag, fp->frame_type, RC.eNB[Mod_id][CC_id]->X_u_br[3]);
+
+    // CE Level 2 parameters
+    fp->prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[2] = cfg->emtc_config.prach_ce_level_2_enable.value;
+    fp->prach_emtc_config_common.prach_ConfigInfo.prach_starting_subframe_periodicity[2] = cfg->emtc_config.prach_ce_level_2_starting_subframe_periodicity.value;
+    fp->prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[2] = cfg->emtc_config.prach_ce_level_2_number_of_repetitions_per_attempt.value;
+    AssertFatal (fp->prach_emtc_config_common.prach_ConfigInfo.prach_starting_subframe_periodicity[2] >= fp->prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[2],
+                 "prach_starting_subframe_periodicity[2] < prach_numPetitionPerPreambleAttempt[2]\n");
+    fp->prach_emtc_config_common.prach_ConfigInfo.prach_ConfigIndex[2] = cfg->emtc_config.prach_ce_level_2_configuration_index.value;
+    fp->prach_emtc_config_common.prach_ConfigInfo.prach_FreqOffset[2] = cfg->emtc_config.prach_ce_level_2_frequency_offset.value;
+    fp->prach_emtc_config_common.prach_ConfigInfo.prach_hopping_enable[2] = cfg->emtc_config.prach_ce_level_2_hopping_enable.value;
+    fp->prach_emtc_config_common.prach_ConfigInfo.prach_hopping_offset[2] = cfg->emtc_config.prach_ce_level_2_hopping_offset.value;
+    if (fp->prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[2] == 1)
+      compute_prach_seq (fp->prach_emtc_config_common.rootSequenceIndex,
+                         fp->prach_emtc_config_common.prach_ConfigInfo.prach_ConfigIndex[3],
+                         fp->prach_emtc_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig,
+                         fp->prach_emtc_config_common.prach_ConfigInfo.highSpeedFlag, fp->frame_type, RC.eNB[Mod_id][CC_id]->X_u_br[2]);
+
+    // CE Level 1 parameters
+    fp->prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[1] = cfg->emtc_config.prach_ce_level_1_enable.value;
+    fp->prach_emtc_config_common.prach_ConfigInfo.prach_starting_subframe_periodicity[1] = cfg->emtc_config.prach_ce_level_1_starting_subframe_periodicity.value;
+    fp->prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[1] = cfg->emtc_config.prach_ce_level_1_number_of_repetitions_per_attempt.value;
+    AssertFatal (fp->prach_emtc_config_common.prach_ConfigInfo.prach_starting_subframe_periodicity[1] >= fp->prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[1],
+                 "prach_starting_subframe_periodicity[1] < prach_numPetitionPerPreambleAttempt[1]\n");
+
+    fp->prach_emtc_config_common.prach_ConfigInfo.prach_ConfigIndex[1] = cfg->emtc_config.prach_ce_level_1_configuration_index.value;
+    fp->prach_emtc_config_common.prach_ConfigInfo.prach_FreqOffset[1] = cfg->emtc_config.prach_ce_level_1_frequency_offset.value;
+    fp->prach_emtc_config_common.prach_ConfigInfo.prach_hopping_enable[1] = cfg->emtc_config.prach_ce_level_1_hopping_enable.value;
+    fp->prach_emtc_config_common.prach_ConfigInfo.prach_hopping_offset[1] = cfg->emtc_config.prach_ce_level_1_hopping_offset.value;
+    if (fp->prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[1] == 1)
+      compute_prach_seq (fp->prach_emtc_config_common.rootSequenceIndex,
+                         fp->prach_emtc_config_common.prach_ConfigInfo.prach_ConfigIndex[3],
+                         fp->prach_emtc_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig,
+                         fp->prach_emtc_config_common.prach_ConfigInfo.highSpeedFlag, fp->frame_type, RC.eNB[Mod_id][CC_id]->X_u_br[1]);
+
+    // CE Level 0 parameters
+    fp->prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[0] = cfg->emtc_config.prach_ce_level_0_enable.value;
+    fp->prach_emtc_config_common.prach_ConfigInfo.prach_starting_subframe_periodicity[0] = cfg->emtc_config.prach_ce_level_0_starting_subframe_periodicity.value;
+    fp->prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[0] = cfg->emtc_config.prach_ce_level_0_number_of_repetitions_per_attempt.value;
+    AssertFatal (fp->prach_emtc_config_common.prach_ConfigInfo.prach_starting_subframe_periodicity[0] >= fp->prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[0],
+                 "prach_starting_subframe_periodicity[0] %d < prach_numPetitionPerPreambleAttempt[0] %d\n",
+                 fp->prach_emtc_config_common.prach_ConfigInfo.prach_starting_subframe_periodicity[0], fp->prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[0]);
+    AssertFatal (fp->prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[0] > 0, "prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[0]==0\n");
+    fp->prach_emtc_config_common.prach_ConfigInfo.prach_ConfigIndex[0] = cfg->emtc_config.prach_ce_level_0_configuration_index.value;
+    fp->prach_emtc_config_common.prach_ConfigInfo.prach_FreqOffset[0] = cfg->emtc_config.prach_ce_level_0_frequency_offset.value;
+    fp->prach_emtc_config_common.prach_ConfigInfo.prach_hopping_enable[0] = cfg->emtc_config.prach_ce_level_0_hopping_enable.value;
+    fp->prach_emtc_config_common.prach_ConfigInfo.prach_hopping_offset[0] = cfg->emtc_config.prach_ce_level_0_hopping_offset.value;
+    if (fp->prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[0] == 1) {
+      compute_prach_seq (fp->prach_emtc_config_common.rootSequenceIndex,
+                         fp->prach_emtc_config_common.prach_ConfigInfo.prach_ConfigIndex[3],
+                         fp->prach_emtc_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig,
+                         fp->prach_emtc_config_common.prach_ConfigInfo.highSpeedFlag, fp->frame_type, RC.eNB[Mod_id][CC_id]->X_u_br[0]);
+      init_mpdcch(RC.eNB[Mod_id][CC_id]);
+    }
+  }
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-  fp->prach_emtc_config_common.prach_Config_enabled=1;
-
-  fp->prach_emtc_config_common.rootSequenceIndex                                         = cfg->emtc_config.prach_catm_root_sequence_index.value;
-
-  fp->prach_emtc_config_common.prach_ConfigInfo.highSpeedFlag                            = cfg->emtc_config.prach_catm_high_speed_flag.value;
-  fp->prach_emtc_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig                = cfg->emtc_config.prach_catm_zero_correlation_zone_configuration.value;
-
-  // CE Level 3 parameters
-  fp->prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[3]                  = cfg->emtc_config.prach_ce_level_3_enable.value;
-  fp->prach_emtc_config_common.prach_ConfigInfo.prach_starting_subframe_periodicity[3]   = cfg->emtc_config.prach_ce_level_3_starting_subframe_periodicity.value;
-  fp->prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[3] = cfg->emtc_config.prach_ce_level_3_number_of_repetitions_per_attempt.value;
-  AssertFatal(fp->prach_emtc_config_common.prach_ConfigInfo.prach_starting_subframe_periodicity[3]>=fp->prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[3],
-	      "prach_starting_subframe_periodicity[3] < prach_numPetitionPerPreambleAttempt[3]\n");
-
-
-  fp->prach_emtc_config_common.prach_ConfigInfo.prach_ConfigIndex[3]                     = cfg->emtc_config.prach_ce_level_3_configuration_index.value;
-  fp->prach_emtc_config_common.prach_ConfigInfo.prach_FreqOffset[3]                      = cfg->emtc_config.prach_ce_level_3_frequency_offset.value;
-  fp->prach_emtc_config_common.prach_ConfigInfo.prach_hopping_enable[3]                  = cfg->emtc_config.prach_ce_level_3_hopping_enable.value;
-  fp->prach_emtc_config_common.prach_ConfigInfo.prach_hopping_offset[3]                  = cfg->emtc_config.prach_ce_level_3_hopping_offset.value;
-  if (fp->prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[3] == 1)
-    compute_prach_seq(fp->prach_emtc_config_common.rootSequenceIndex,
-		      fp->prach_emtc_config_common.prach_ConfigInfo.prach_ConfigIndex[3],
-		      fp->prach_emtc_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig,
-		      fp->prach_emtc_config_common.prach_ConfigInfo.highSpeedFlag,
-		      fp->frame_type,
-		      RC.eNB[Mod_id][CC_id]->X_u_br[3]);
-
-  // CE Level 2 parameters
-  fp->prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[2]                  = cfg->emtc_config.prach_ce_level_2_enable.value;
-  fp->prach_emtc_config_common.prach_ConfigInfo.prach_starting_subframe_periodicity[2]   = cfg->emtc_config.prach_ce_level_2_starting_subframe_periodicity.value;
-  fp->prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[2] = cfg->emtc_config.prach_ce_level_2_number_of_repetitions_per_attempt.value;
-  AssertFatal(fp->prach_emtc_config_common.prach_ConfigInfo.prach_starting_subframe_periodicity[2]>=fp->prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[2],
-	      "prach_starting_subframe_periodicity[2] < prach_numPetitionPerPreambleAttempt[2]\n");
-  fp->prach_emtc_config_common.prach_ConfigInfo.prach_ConfigIndex[2]                     = cfg->emtc_config.prach_ce_level_2_configuration_index.value;
-  fp->prach_emtc_config_common.prach_ConfigInfo.prach_FreqOffset[2]                      = cfg->emtc_config.prach_ce_level_2_frequency_offset.value;
-  fp->prach_emtc_config_common.prach_ConfigInfo.prach_hopping_enable[2]                  = cfg->emtc_config.prach_ce_level_2_hopping_enable.value;
-  fp->prach_emtc_config_common.prach_ConfigInfo.prach_hopping_offset[2]                  = cfg->emtc_config.prach_ce_level_2_hopping_offset.value;
-  if (fp->prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[2] == 1)
-    compute_prach_seq(fp->prach_emtc_config_common.rootSequenceIndex,
-		      fp->prach_emtc_config_common.prach_ConfigInfo.prach_ConfigIndex[3],
-		      fp->prach_emtc_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig,
-		      fp->prach_emtc_config_common.prach_ConfigInfo.highSpeedFlag,
-		      fp->frame_type,
-		      RC.eNB[Mod_id][CC_id]->X_u_br[2]);
-
-  // CE Level 1 parameters
-  fp->prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[1]                  = cfg->emtc_config.prach_ce_level_1_enable.value;
-  fp->prach_emtc_config_common.prach_ConfigInfo.prach_starting_subframe_periodicity[1]   = cfg->emtc_config.prach_ce_level_1_starting_subframe_periodicity.value;
-  fp->prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[1] = cfg->emtc_config.prach_ce_level_1_number_of_repetitions_per_attempt.value;
-  AssertFatal(fp->prach_emtc_config_common.prach_ConfigInfo.prach_starting_subframe_periodicity[1]>=fp->prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[1],
-	      "prach_starting_subframe_periodicity[1] < prach_numPetitionPerPreambleAttempt[1]\n");
-
-  fp->prach_emtc_config_common.prach_ConfigInfo.prach_ConfigIndex[1]                     = cfg->emtc_config.prach_ce_level_1_configuration_index.value;
-  fp->prach_emtc_config_common.prach_ConfigInfo.prach_FreqOffset[1]                      = cfg->emtc_config.prach_ce_level_1_frequency_offset.value;
-  fp->prach_emtc_config_common.prach_ConfigInfo.prach_hopping_enable[1]                  = cfg->emtc_config.prach_ce_level_1_hopping_enable.value;
-  fp->prach_emtc_config_common.prach_ConfigInfo.prach_hopping_offset[1]                  = cfg->emtc_config.prach_ce_level_1_hopping_offset.value;
-  if (fp->prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[1] == 1)
-    compute_prach_seq(fp->prach_emtc_config_common.rootSequenceIndex,
-		      fp->prach_emtc_config_common.prach_ConfigInfo.prach_ConfigIndex[3],
-		      fp->prach_emtc_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig,
-		      fp->prach_emtc_config_common.prach_ConfigInfo.highSpeedFlag,
-		      fp->frame_type,
-		      RC.eNB[Mod_id][CC_id]->X_u_br[1]);
-  
-  // CE Level 0 parameters
-  fp->prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[0]                  = cfg->emtc_config.prach_ce_level_0_enable.value;
-  fp->prach_emtc_config_common.prach_ConfigInfo.prach_starting_subframe_periodicity[0]   = cfg->emtc_config.prach_ce_level_0_starting_subframe_periodicity.value;
-  fp->prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[0] = cfg->emtc_config.prach_ce_level_0_number_of_repetitions_per_attempt.value;
-  AssertFatal(fp->prach_emtc_config_common.prach_ConfigInfo.prach_starting_subframe_periodicity[0]>=fp->prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[0],
-	      "prach_starting_subframe_periodicity[0] %d < prach_numPetitionPerPreambleAttempt[0] %d\n",
-	      fp->prach_emtc_config_common.prach_ConfigInfo.prach_starting_subframe_periodicity[0],
-	      fp->prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[0]);
-
-  fp->prach_emtc_config_common.prach_ConfigInfo.prach_ConfigIndex[0]                     = cfg->emtc_config.prach_ce_level_0_configuration_index.value;
-  fp->prach_emtc_config_common.prach_ConfigInfo.prach_FreqOffset[0]                      = cfg->emtc_config.prach_ce_level_0_frequency_offset.value;
-  fp->prach_emtc_config_common.prach_ConfigInfo.prach_hopping_enable[0]                = cfg->emtc_config.prach_ce_level_0_hopping_enable.value;
-  fp->prach_emtc_config_common.prach_ConfigInfo.prach_hopping_offset[0]                = cfg->emtc_config.prach_ce_level_0_hopping_offset.value;
-  if (fp->prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[0] == 1)
-    compute_prach_seq(fp->prach_emtc_config_common.rootSequenceIndex,
-		      fp->prach_emtc_config_common.prach_ConfigInfo.prach_ConfigIndex[3],
-		      fp->prach_emtc_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig,
-		      fp->prach_emtc_config_common.prach_ConfigInfo.highSpeedFlag,
-		      fp->frame_type,
-		      RC.eNB[Mod_id][CC_id]->X_u_br[0]);
 #endif
 
 
 
-  fp->pucch_config_common.deltaPUCCH_Shift = 1+cfg->pucch_config.delta_pucch_shift.value;
-  fp->pucch_config_common.nRB_CQI          = cfg->pucch_config.n_cqi_rb.value;
-  fp->pucch_config_common.nCS_AN           = cfg->pucch_config.n_an_cs.value;
-  fp->pucch_config_common.n1PUCCH_AN       = cfg->pucch_config.n1_pucch_an.value;
+  fp->pucch_config_common.deltaPUCCH_Shift = 1 + cfg->pucch_config.delta_pucch_shift.value;
+  fp->pucch_config_common.nRB_CQI = cfg->pucch_config.n_cqi_rb.value;
+  fp->pucch_config_common.nCS_AN = cfg->pucch_config.n_an_cs.value;
+  fp->pucch_config_common.n1PUCCH_AN = cfg->pucch_config.n1_pucch_an.value;
 
-  fp->pdsch_config_common.referenceSignalPower                         = cfg->rf_config.reference_signal_power.value;
-  fp->pdsch_config_common.p_b                                          = cfg->subframe_config.pb.value;
+  fp->pdsch_config_common.referenceSignalPower = cfg->rf_config.reference_signal_power.value;
+  fp->pdsch_config_common.p_b = cfg->subframe_config.pb.value;
 
-  fp->pusch_config_common.n_SB                                         = cfg->pusch_config.number_of_subbands.value;
-  LOG_I(PHY,"pusch_config_common.n_SB = %d\n",fp->pusch_config_common.n_SB );
+  fp->pusch_config_common.n_SB = cfg->pusch_config.number_of_subbands.value;
+  LOG_I (PHY, "pusch_config_common.n_SB = %d\n", fp->pusch_config_common.n_SB);
 
-  fp->pusch_config_common.hoppingMode                                  = cfg->pusch_config.hopping_mode.value;
-  LOG_I(PHY,"pusch_config_common.hoppingMode = %d\n",fp->pusch_config_common.hoppingMode);
+  fp->pusch_config_common.hoppingMode = cfg->pusch_config.hopping_mode.value;
+  LOG_I (PHY, "pusch_config_common.hoppingMode = %d\n", fp->pusch_config_common.hoppingMode);
 
-  fp->pusch_config_common.pusch_HoppingOffset                          = cfg->pusch_config.hopping_offset.value;
-  LOG_I(PHY,"pusch_config_common.pusch_HoppingOffset = %d\n",fp->pusch_config_common.pusch_HoppingOffset);
+  fp->pusch_config_common.pusch_HoppingOffset = cfg->pusch_config.hopping_offset.value;
+  LOG_I (PHY, "pusch_config_common.pusch_HoppingOffset = %d\n", fp->pusch_config_common.pusch_HoppingOffset);
 
   fp->pusch_config_common.enable64QAM                                  = 0;//radioResourceConfigCommon->pusch_ConfigCommon.pusch_ConfigBasic.enable64QAM;
   LOG_I(PHY,"pusch_config_common.enable64QAM = %d\n",fp->pusch_config_common.enable64QAM );
@@ -300,29 +295,30 @@ void phy_config_request(PHY_Config_t *phy_config) {
   fp->pusch_config_common.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH   =  cfg->uplink_reference_signal_config.group_assignment.value;
   LOG_I(PHY,"pusch_config_common.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH = %d\n",fp->pusch_config_common.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH);
 
-  LOG_I(PHY,"pusch_config_common.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled = %d\n",fp->pusch_config_common.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled);
+  LOG_I (PHY, "pusch_config_common.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled = %d\n", fp->pusch_config_common.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled);
 
-  fp->pusch_config_common.ul_ReferenceSignalsPUSCH.cyclicShift            = dmrs1_tab[cfg->uplink_reference_signal_config.cyclic_shift_1_for_drms.value];
-  LOG_I(PHY,"pusch_config_common.ul_ReferenceSignalsPUSCH.cyclicShift = %d\n",fp->pusch_config_common.ul_ReferenceSignalsPUSCH.cyclicShift);
+  fp->pusch_config_common.ul_ReferenceSignalsPUSCH.cyclicShift = dmrs1_tab[cfg->uplink_reference_signal_config.cyclic_shift_1_for_drms.value];
+  LOG_I (PHY, "pusch_config_common.ul_ReferenceSignalsPUSCH.cyclicShift = %d\n", fp->pusch_config_common.ul_ReferenceSignalsPUSCH.cyclicShift);
 
-  init_ul_hopping(fp);
+  init_ul_hopping (fp);
 
-  fp->soundingrs_ul_config_common.enabled_flag                        = 0;// 1; Don't know how to turn this off in NFAPI
-  fp->soundingrs_ul_config_common.srs_BandwidthConfig                 = cfg->srs_config.bandwidth_configuration.value;
-  fp->soundingrs_ul_config_common.srs_SubframeConfig                  = cfg->srs_config.srs_subframe_configuration.value;
+  fp->soundingrs_ul_config_common.enabled_flag = 0;     // 1; Don't know how to turn this off in NFAPI
+  fp->soundingrs_ul_config_common.srs_BandwidthConfig = cfg->srs_config.bandwidth_configuration.value;
+  fp->soundingrs_ul_config_common.srs_SubframeConfig = cfg->srs_config.srs_subframe_configuration.value;
   fp->soundingrs_ul_config_common.ackNackSRS_SimultaneousTransmission = cfg->srs_config.srs_acknack_srs_simultaneous_transmission.value;
-  fp->soundingrs_ul_config_common.srs_MaxUpPts                        = cfg->srs_config.max_up_pts.value;
+  fp->soundingrs_ul_config_common.srs_MaxUpPts = cfg->srs_config.max_up_pts.value;
 
   fp->num_MBSFN_config = 0;
 
-  init_ncs_cell(fp,RC.eNB[Mod_id][CC_id]->ncs_cell);
+  init_ncs_cell (fp, RC.eNB[Mod_id][CC_id]->ncs_cell);
 
 
-  init_ul_hopping(fp);
-  RC.eNB[Mod_id][CC_id]->configured                                   = 1;
-  LOG_I(PHY,"eNB %d/%d configured\n",Mod_id,CC_id);
+  init_ul_hopping (fp);
+  RC.eNB[Mod_id][CC_id]->configured = 1;
+  LOG_I (PHY, "eNB %d/%d configured\n", Mod_id, CC_id);
 }
 
+
 /*
 void phy_config_sib2_eNB(uint8_t Mod_id,
                          int CC_id,
@@ -406,9 +402,9 @@ void phy_config_sib2_eNB(uint8_t Mod_id,
     fp->soundingrs_ul_config_common.ackNackSRS_SimultaneousTransmission = radioResourceConfigCommon->soundingRS_UL_ConfigCommon.choice.setup.ackNackSRS_SimultaneousTransmission;
 
     if (radioResourceConfigCommon->soundingRS_UL_ConfigCommon.choice.setup.srs_MaxUpPts)
-      fp->soundingrs_ul_config_common.srs_MaxUpPts                      = 1;
+      fp->soundingrs_ul_config_common.srs_MaxUpPts = 1;
     else
-      fp->soundingrs_ul_config_common.srs_MaxUpPts                      = 0;
+      fp->soundingrs_ul_config_common.srs_MaxUpPts = 0;
   }
 
 
@@ -438,16 +434,15 @@ void phy_config_sib2_eNB(uint8_t Mod_id,
   if (mbsfn_SubframeConfigList != NULL) {
     fp->num_MBSFN_config = mbsfn_SubframeConfigList->list.count;
 
-    for (i=0; i<mbsfn_SubframeConfigList->list.count; i++) {
+    for (i = 0; i < mbsfn_SubframeConfigList->list.count; i++) {
       fp->MBSFN_config[i].radioframeAllocationPeriod = mbsfn_SubframeConfigList->list.array[i]->radioframeAllocationPeriod;
       fp->MBSFN_config[i].radioframeAllocationOffset = mbsfn_SubframeConfigList->list.array[i]->radioframeAllocationOffset;
 
       if (mbsfn_SubframeConfigList->list.array[i]->subframeAllocation.present == MBSFN_SubframeConfig__subframeAllocation_PR_oneFrame) {
         fp->MBSFN_config[i].fourFrames_flag = 0;
-        fp->MBSFN_config[i].mbsfn_SubframeConfig = mbsfn_SubframeConfigList->list.array[i]->subframeAllocation.choice.oneFrame.buf[0]; // 6-bit subframe configuration
-        LOG_I(PHY, "[CONFIG] MBSFN_SubframeConfig[%d] pattern is  %d\n", i,
-              fp->MBSFN_config[i].mbsfn_SubframeConfig);
-      } else if (mbsfn_SubframeConfigList->list.array[i]->subframeAllocation.present == MBSFN_SubframeConfig__subframeAllocation_PR_fourFrames) { // 24-bit subframe configuration
+        fp->MBSFN_config[i].mbsfn_SubframeConfig = mbsfn_SubframeConfigList->list.array[i]->subframeAllocation.choice.oneFrame.buf[0];  // 6-bit subframe configuration
+        LOG_I (PHY, "[CONFIG] MBSFN_SubframeConfig[%d] pattern is  %d\n", i, fp->MBSFN_config[i].mbsfn_SubframeConfig);
+      } else if (mbsfn_SubframeConfigList->list.array[i]->subframeAllocation.present == MBSFN_SubframeConfig__subframeAllocation_PR_fourFrames) {       // 24-bit subframe configuration
         fp->MBSFN_config[i].fourFrames_flag = 1;
         fp->MBSFN_config[i].mbsfn_SubframeConfig =
           mbsfn_SubframeConfigList->list.array[i]->subframeAllocation.choice.oneFrame.buf[2]|
@@ -466,6 +461,7 @@ void phy_config_sib2_eNB(uint8_t Mod_id,
 }
 */
 
+
 void phy_config_sib13_eNB(module_id_t Mod_id,int CC_id,int mbsfn_Area_idx,
                           long mbsfn_AreaId_r9)
 {
@@ -473,41 +469,43 @@ void phy_config_sib13_eNB(module_id_t Mod_id,int CC_id,int mbsfn_Area_idx,
   LTE_DL_FRAME_PARMS *fp = &RC.eNB[Mod_id][CC_id]->frame_parms;
 
 
-  LOG_I(PHY,"[eNB%d] Applying MBSFN_Area_id %ld for index %d\n",Mod_id,mbsfn_AreaId_r9,mbsfn_Area_idx);
+  LOG_I (PHY, "[eNB%d] Applying MBSFN_Area_id %ld for index %d\n", Mod_id, mbsfn_AreaId_r9, mbsfn_Area_idx);
 
   if (mbsfn_Area_idx == 0) {
     fp->Nid_cell_mbsfn = (uint16_t)mbsfn_AreaId_r9;
     LOG_I(PHY,"Fix me: only called when mbsfn_Area_idx == 0)\n");
   }
 
-  lte_gold_mbsfn(fp,RC.eNB[Mod_id][CC_id]->lte_gold_mbsfn_table,fp->Nid_cell_mbsfn);
+  lte_gold_mbsfn (fp, RC.eNB[Mod_id][CC_id]->lte_gold_mbsfn_table, fp->Nid_cell_mbsfn);
 }
 
 
-void phy_config_dedicated_eNB_step2(PHY_VARS_eNB *eNB)
+void
+phy_config_dedicated_eNB_step2 (PHY_VARS_eNB * eNB)
 {
   uint16_t UE_id;
-  struct PhysicalConfigDedicated *physicalConfigDedicated;
-  LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
 
-  for (UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++) {
+  struct LTE_PhysicalConfigDedicated *physicalConfigDedicated;
+  LTE_DL_FRAME_PARMS *fp = &eNB->frame_parms;
+
+  for (UE_id = 0; UE_id < NUMBER_OF_UE_MAX; UE_id++) {
     physicalConfigDedicated = eNB->physicalConfigDedicated[UE_id];
 
     if (physicalConfigDedicated != NULL) {
-      LOG_I(PHY,"[eNB %d] Sent physicalConfigDedicated=%p for UE %d\n",eNB->Mod_id,physicalConfigDedicated,UE_id);
-      LOG_D(PHY,"------------------------------------------------------------------------\n");
+      LOG_I (PHY, "[eNB %d] Sent physicalConfigDedicated=%p for UE %d\n", eNB->Mod_id, physicalConfigDedicated, UE_id);
+      LOG_D (PHY, "------------------------------------------------------------------------\n");
 
       if (physicalConfigDedicated->pdsch_ConfigDedicated) {
-        eNB->pdsch_config_dedicated[UE_id].p_a=physicalConfigDedicated->pdsch_ConfigDedicated->p_a;
-        LOG_D(PHY,"pdsch_config_dedicated.p_a %d\n",eNB->pdsch_config_dedicated[UE_id].p_a);
-        LOG_D(PHY,"\n");
+        eNB->pdsch_config_dedicated[UE_id].p_a = physicalConfigDedicated->pdsch_ConfigDedicated->p_a;
+        LOG_D (PHY, "pdsch_config_dedicated.p_a %d\n", eNB->pdsch_config_dedicated[UE_id].p_a);
+        LOG_D (PHY, "\n");
       }
 
       if (physicalConfigDedicated->pucch_ConfigDedicated) {
-        if (physicalConfigDedicated->pucch_ConfigDedicated->ackNackRepetition.present==PUCCH_ConfigDedicated__ackNackRepetition_PR_release)
+        if (physicalConfigDedicated->pucch_ConfigDedicated->ackNackRepetition.present==LTE_PUCCH_ConfigDedicated__ackNackRepetition_PR_release)
           eNB->pucch_config_dedicated[UE_id].ackNackRepetition=0;
         else {
-          eNB->pucch_config_dedicated[UE_id].ackNackRepetition=1;
+          eNB->pucch_config_dedicated[UE_id].ackNackRepetition = 1;
         }
 
         if (fp->frame_type == FDD) {
@@ -519,10 +517,10 @@ void phy_config_dedicated_eNB_step2(PHY_VARS_eNB *eNB)
             eNB->pucch_config_dedicated[UE_id].tdd_AckNackFeedbackMode = bundling;
         }
 
-        if ( eNB->pucch_config_dedicated[UE_id].tdd_AckNackFeedbackMode == multiplexing)
-          LOG_D(PHY,"pucch_config_dedicated.tdd_AckNackFeedbackMode = multiplexing\n");
+        if (eNB->pucch_config_dedicated[UE_id].tdd_AckNackFeedbackMode == multiplexing)
+          LOG_D (PHY, "pucch_config_dedicated.tdd_AckNackFeedbackMode = multiplexing\n");
         else
-          LOG_D(PHY,"pucch_config_dedicated.tdd_AckNackFeedbackMode = bundling\n");
+          LOG_D (PHY, "pucch_config_dedicated.tdd_AckNackFeedbackMode = bundling\n");
 
       }
 
@@ -542,43 +540,43 @@ void phy_config_dedicated_eNB_step2(PHY_VARS_eNB *eNB)
       if (physicalConfigDedicated->uplinkPowerControlDedicated) {
 
         eNB->ul_power_control_dedicated[UE_id].p0_UE_PUSCH = physicalConfigDedicated->uplinkPowerControlDedicated->p0_UE_PUSCH;
-        eNB->ul_power_control_dedicated[UE_id].deltaMCS_Enabled= physicalConfigDedicated->uplinkPowerControlDedicated->deltaMCS_Enabled;
-        eNB->ul_power_control_dedicated[UE_id].accumulationEnabled= physicalConfigDedicated->uplinkPowerControlDedicated->accumulationEnabled;
-        eNB->ul_power_control_dedicated[UE_id].p0_UE_PUCCH= physicalConfigDedicated->uplinkPowerControlDedicated->p0_UE_PUCCH;
-        eNB->ul_power_control_dedicated[UE_id].pSRS_Offset= physicalConfigDedicated->uplinkPowerControlDedicated->pSRS_Offset;
-        eNB->ul_power_control_dedicated[UE_id].filterCoefficient= *physicalConfigDedicated->uplinkPowerControlDedicated->filterCoefficient;
-        LOG_D(PHY,"ul_power_control_dedicated.p0_UE_PUSCH %d\n",eNB->ul_power_control_dedicated[UE_id].p0_UE_PUSCH);
-        LOG_D(PHY,"ul_power_control_dedicated.deltaMCS_Enabled %d\n",eNB->ul_power_control_dedicated[UE_id].deltaMCS_Enabled);
-        LOG_D(PHY,"ul_power_control_dedicated.accumulationEnabled %d\n",eNB->ul_power_control_dedicated[UE_id].accumulationEnabled);
-        LOG_D(PHY,"ul_power_control_dedicated.p0_UE_PUCCH %d\n",eNB->ul_power_control_dedicated[UE_id].p0_UE_PUCCH);
-        LOG_D(PHY,"ul_power_control_dedicated.pSRS_Offset %d\n",eNB->ul_power_control_dedicated[UE_id].pSRS_Offset);
-        LOG_D(PHY,"ul_power_control_dedicated.filterCoefficient %d\n",eNB->ul_power_control_dedicated[UE_id].filterCoefficient);
-        LOG_D(PHY,"\n");
+        eNB->ul_power_control_dedicated[UE_id].deltaMCS_Enabled = physicalConfigDedicated->uplinkPowerControlDedicated->deltaMCS_Enabled;
+        eNB->ul_power_control_dedicated[UE_id].accumulationEnabled = physicalConfigDedicated->uplinkPowerControlDedicated->accumulationEnabled;
+        eNB->ul_power_control_dedicated[UE_id].p0_UE_PUCCH = physicalConfigDedicated->uplinkPowerControlDedicated->p0_UE_PUCCH;
+        eNB->ul_power_control_dedicated[UE_id].pSRS_Offset = physicalConfigDedicated->uplinkPowerControlDedicated->pSRS_Offset;
+        eNB->ul_power_control_dedicated[UE_id].filterCoefficient = *physicalConfigDedicated->uplinkPowerControlDedicated->filterCoefficient;
+        LOG_D (PHY, "ul_power_control_dedicated.p0_UE_PUSCH %d\n", eNB->ul_power_control_dedicated[UE_id].p0_UE_PUSCH);
+        LOG_D (PHY, "ul_power_control_dedicated.deltaMCS_Enabled %d\n", eNB->ul_power_control_dedicated[UE_id].deltaMCS_Enabled);
+        LOG_D (PHY, "ul_power_control_dedicated.accumulationEnabled %d\n", eNB->ul_power_control_dedicated[UE_id].accumulationEnabled);
+        LOG_D (PHY, "ul_power_control_dedicated.p0_UE_PUCCH %d\n", eNB->ul_power_control_dedicated[UE_id].p0_UE_PUCCH);
+        LOG_D (PHY, "ul_power_control_dedicated.pSRS_Offset %d\n", eNB->ul_power_control_dedicated[UE_id].pSRS_Offset);
+        LOG_D (PHY, "ul_power_control_dedicated.filterCoefficient %d\n", eNB->ul_power_control_dedicated[UE_id].filterCoefficient);
+        LOG_D (PHY, "\n");
       }
 
       if (physicalConfigDedicated->antennaInfo) {
-        eNB->transmission_mode[UE_id] = 1+(physicalConfigDedicated->antennaInfo->choice.explicitValue.transmissionMode);
-        LOG_D(PHY,"Transmission Mode (phy_config_dedicated_eNB_step2) %d\n",eNB->transmission_mode[UE_id]);
-        LOG_D(PHY,"\n");
+        eNB->transmission_mode[UE_id] = 1 + (physicalConfigDedicated->antennaInfo->choice.explicitValue.transmissionMode);
+        LOG_D (PHY, "Transmission Mode (phy_config_dedicated_eNB_step2) %d\n", eNB->transmission_mode[UE_id]);
+        LOG_D (PHY, "\n");
       }
 
       if (physicalConfigDedicated->schedulingRequestConfig) {
-        if (physicalConfigDedicated->schedulingRequestConfig->present == SchedulingRequestConfig_PR_setup) {
+        if (physicalConfigDedicated->schedulingRequestConfig->present == LTE_SchedulingRequestConfig_PR_setup) {
           eNB->scheduling_request_config[UE_id].sr_PUCCH_ResourceIndex = physicalConfigDedicated->schedulingRequestConfig->choice.setup.sr_PUCCH_ResourceIndex;
-          eNB->scheduling_request_config[UE_id].sr_ConfigIndex=physicalConfigDedicated->schedulingRequestConfig->choice.setup.sr_ConfigIndex;
-          eNB->scheduling_request_config[UE_id].dsr_TransMax=physicalConfigDedicated->schedulingRequestConfig->choice.setup.dsr_TransMax;
+          eNB->scheduling_request_config[UE_id].sr_ConfigIndex = physicalConfigDedicated->schedulingRequestConfig->choice.setup.sr_ConfigIndex;
+          eNB->scheduling_request_config[UE_id].dsr_TransMax = physicalConfigDedicated->schedulingRequestConfig->choice.setup.dsr_TransMax;
 
-          LOG_D(PHY,"scheduling_request_config.sr_PUCCH_ResourceIndex %d\n",eNB->scheduling_request_config[UE_id].sr_PUCCH_ResourceIndex);
-          LOG_D(PHY,"scheduling_request_config.sr_ConfigIndex %d\n",eNB->scheduling_request_config[UE_id].sr_ConfigIndex);
-          LOG_D(PHY,"scheduling_request_config.dsr_TransMax %d\n",eNB->scheduling_request_config[UE_id].dsr_TransMax);
+          LOG_D (PHY, "scheduling_request_config.sr_PUCCH_ResourceIndex %d\n", eNB->scheduling_request_config[UE_id].sr_PUCCH_ResourceIndex);
+          LOG_D (PHY, "scheduling_request_config.sr_ConfigIndex %d\n", eNB->scheduling_request_config[UE_id].sr_ConfigIndex);
+          LOG_D (PHY, "scheduling_request_config.dsr_TransMax %d\n", eNB->scheduling_request_config[UE_id].dsr_TransMax);
         }
 
-        LOG_D(PHY,"------------------------------------------------------------\n");
+        LOG_D (PHY, "------------------------------------------------------------\n");
 
       }
 
       if (physicalConfigDedicated->soundingRS_UL_ConfigDedicated) {
-        if (physicalConfigDedicated->soundingRS_UL_ConfigDedicated->present == SoundingRS_UL_ConfigDedicated_PR_setup) {
+        if (physicalConfigDedicated->soundingRS_UL_ConfigDedicated->present == LTE_SoundingRS_UL_ConfigDedicated_PR_setup) {
 	  
 	  eNB->soundingrs_ul_config_dedicated[UE_id].srsConfigDedicatedSetup = 1;
           eNB->soundingrs_ul_config_dedicated[UE_id].duration             = physicalConfigDedicated->soundingRS_UL_ConfigDedicated->choice.setup.duration;
@@ -587,14 +585,14 @@ void phy_config_dedicated_eNB_step2(PHY_VARS_eNB *eNB)
           eNB->soundingrs_ul_config_dedicated[UE_id].srs_Bandwidth        = physicalConfigDedicated->soundingRS_UL_ConfigDedicated->choice.setup.srs_Bandwidth;
           eNB->soundingrs_ul_config_dedicated[UE_id].srs_ConfigIndex      = physicalConfigDedicated->soundingRS_UL_ConfigDedicated->choice.setup.srs_ConfigIndex;
           eNB->soundingrs_ul_config_dedicated[UE_id].srs_HoppingBandwidth = physicalConfigDedicated->soundingRS_UL_ConfigDedicated->choice.setup.srs_HoppingBandwidth;
-          eNB->soundingrs_ul_config_dedicated[UE_id].transmissionComb     = physicalConfigDedicated->soundingRS_UL_ConfigDedicated->choice.setup.transmissionComb;
+          eNB->soundingrs_ul_config_dedicated[UE_id].transmissionComb = physicalConfigDedicated->soundingRS_UL_ConfigDedicated->choice.setup.transmissionComb;
 
 
-          LOG_D(PHY,"soundingrs_ul_config_dedicated.srs_ConfigIndex %d\n",eNB->soundingrs_ul_config_dedicated[UE_id].srs_ConfigIndex);
+          LOG_D (PHY, "soundingrs_ul_config_dedicated.srs_ConfigIndex %d\n", eNB->soundingrs_ul_config_dedicated[UE_id].srs_ConfigIndex);
 
         }
 
-        LOG_D(PHY,"------------------------------------------------------------\n");
+        LOG_D (PHY, "------------------------------------------------------------\n");
 
       }
 
@@ -651,7 +649,7 @@ void phy_config_dedicated_eNB(uint8_t Mod_id,
 	eNB->transmission_mode[UE_id] = 7;
 	break;
       default:
-        LOG_E(PHY,"Unknown transmission mode!\n");
+        LOG_E (PHY, "Unknown transmission mode!\n");
         break;
       }
       LOG_I(PHY,"Transmission Mode (phy_config_dedicated_eNB) %d\n",eNB->transmission_mode[UE_id]);
@@ -667,6 +665,7 @@ void phy_config_dedicated_eNB(uint8_t Mod_id,
 }
 */
 
+
 /*
 void phy_config_dedicated_scell_eNB(uint8_t Mod_id,
                                     uint16_t rnti,
@@ -716,8 +715,6 @@ void phy_config_dedicated_scell_eNB(uint8_t Mod_id,
 }
 */
 
-
-
 int phy_init_lte_eNB(PHY_VARS_eNB *eNB,
                      unsigned char is_secondary_eNB,
                      unsigned char abstraction_flag)
@@ -729,19 +726,17 @@ int phy_init_lte_eNB(PHY_VARS_eNB *eNB,
   LTE_eNB_PUSCH** const pusch_vars   = eNB->pusch_vars;
   LTE_eNB_SRS* const srs_vars        = eNB->srs_vars;
   LTE_eNB_PRACH* const prach_vars    = &eNB->prach_vars;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   LTE_eNB_PRACH* const prach_vars_br = &eNB->prach_vars_br;
 #endif
-  int i, UE_id; 
+  int             i, UE_id;
 
   LOG_I(PHY,"[eNB %d] %s() About to wait for eNB to be configured", eNB->Mod_id, __FUNCTION__);
 
   eNB->total_dlsch_bitrate = 0;
   eNB->total_transmitted_bits = 0;
   eNB->total_system_throughput = 0;
-  eNB->check_for_MUMIMO_transmissions=0;
- 
-  while(eNB->configured == 0) usleep(10000);
+  eNB->check_for_MUMIMO_transmissions = 0;
 
   LOG_I(PHY,"[eNB %"PRIu8"] Initializing DL_FRAME_PARMS : N_RB_DL %"PRIu8", PHICH Resource %d, PHICH Duration %d nb_antennas_tx:%u nb_antennas_rx:%u nb_antenna_ports_eNB:%u PRACH[rootSequenceIndex:%u prach_Config_enabled:%u configIndex:%u highSpeed:%u zeroCorrelationZoneConfig:%u freqOffset:%u]\n",
         eNB->Mod_id,
@@ -757,18 +752,21 @@ int phy_init_lte_eNB(PHY_VARS_eNB *eNB,
         );
   LOG_D(PHY,"[MSC_NEW][FRAME 00000][PHY_eNB][MOD %02"PRIu8"][]\n", eNB->Mod_id);
 
+  LOG_I (PHY, "[eNB %" PRIu8 "] Initializing DL_FRAME_PARMS : N_RB_DL %" PRIu8 ", PHICH Resource %d, PHICH Duration %d\n",
+         eNB->Mod_id, fp->N_RB_DL, fp->phich_config_common.phich_resource, fp->phich_config_common.phich_duration);
+  LOG_D (PHY, "[MSC_NEW][FRAME 00000][PHY_eNB][MOD %02" PRIu8 "][]\n", eNB->Mod_id);
 
-  lte_gold(fp,eNB->lte_gold_table,fp->Nid_cell);
-  generate_pcfich_reg_mapping(fp);
-  generate_phich_reg_mapping(fp);
 
-  for (UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++) {
-    eNB->first_run_timing_advance[UE_id] =
-      1; ///This flag used to be static. With multiple eNBs this does no longer work, hence we put it in the structure. However it has to be initialized with 1, which is performed here.
-    
+  lte_gold (fp, eNB->lte_gold_table, fp->Nid_cell);
+  generate_pcfich_reg_mapping (fp);
+  generate_phich_reg_mapping (fp);
+
+  for (UE_id = 0; UE_id < NUMBER_OF_UE_MAX; UE_id++) {
+    eNB->first_run_timing_advance[UE_id] = 1;   ///This flag used to be static. With multiple eNBs this does no longer work, hence we put it in the structure. However it has to be initialized with 1, which is performed here.
+
     // clear whole structure
-    bzero( &eNB->UE_stats[UE_id], sizeof(LTE_eNB_UE_stats) );
-    
+    bzero (&eNB->UE_stats[UE_id], sizeof (LTE_eNB_UE_stats));
+
     eNB->physicalConfigDedicated[UE_id] = NULL;
   }
   
@@ -791,51 +789,53 @@ int phy_init_lte_eNB(PHY_VARS_eNB *eNB,
 	    i,common_vars->txdataF[i],
 	    fp->ofdm_symbol_size*fp->symbols_per_tti*10*sizeof(int32_t));
     }
-  }  
-  
-  
+  }
+
+
   // Channel estimates for SRS
-  for (UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++) {
-    
-    srs_vars[UE_id].srs_ch_estimates      = (int32_t**)malloc16( 64*sizeof(int32_t*) );
-    srs_vars[UE_id].srs_ch_estimates_time = (int32_t**)malloc16( 64*sizeof(int32_t*) );
-    
-    for (i=0; i<64; i++) {
-      srs_vars[UE_id].srs_ch_estimates[i]      = (int32_t*)malloc16_clear( sizeof(int32_t)*fp->ofdm_symbol_size );
-      srs_vars[UE_id].srs_ch_estimates_time[i] = (int32_t*)malloc16_clear( sizeof(int32_t)*fp->ofdm_symbol_size*2 );
+  for (UE_id = 0; UE_id < NUMBER_OF_UE_MAX; UE_id++) {
+
+    srs_vars[UE_id].srs_ch_estimates = (int32_t **) malloc16 (64 * sizeof (int32_t *));
+    srs_vars[UE_id].srs_ch_estimates_time = (int32_t **) malloc16 (64 * sizeof (int32_t *));
+
+    for (i = 0; i < 64; i++) {
+      srs_vars[UE_id].srs_ch_estimates[i] = (int32_t *) malloc16_clear (sizeof (int32_t) * fp->ofdm_symbol_size);
+      srs_vars[UE_id].srs_ch_estimates_time[i] = (int32_t *) malloc16_clear (sizeof (int32_t) * fp->ofdm_symbol_size * 2);
     }
-  } //UE_id
+  }                             //UE_id
 
 
-  generate_ul_ref_sigs_rx();
-  
-  init_ulsch_power_LUT();
+  generate_ul_ref_sigs_rx ();
+
+  init_ulsch_power_LUT ();
 
   // SRS
-  for (UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++) {
-    srs_vars[UE_id].srs = (int32_t*)malloc16_clear(2*fp->ofdm_symbol_size*sizeof(int32_t));
+  for (UE_id = 0; UE_id < NUMBER_OF_UE_MAX; UE_id++) {
+    srs_vars[UE_id].srs = (int32_t *) malloc16_clear (2 * fp->ofdm_symbol_size * sizeof (int32_t));
   }
 
   // PRACH
-  prach_vars->prachF = (int16_t*)malloc16_clear( 1024*2*sizeof(int16_t) );
+  prach_vars->prachF = (int16_t *) malloc16_clear (1024 * 2 * sizeof (int16_t));
 
   // assume maximum of 64 RX antennas for PRACH receiver
-  prach_vars->prach_ifft[0]    = (int32_t**)malloc16_clear(64*sizeof(int32_t*)); 
-  for (i=0;i<64;i++) prach_vars->prach_ifft[0][i]    = (int32_t*)malloc16_clear(1024*2*sizeof(int32_t)); 
+  prach_vars->prach_ifft[0] = (int32_t **) malloc16_clear (64 * sizeof (int32_t *));
+  for (i = 0; i < 64; i++)
+    prach_vars->prach_ifft[0][i] = (int32_t *) malloc16_clear (1024 * 2 * sizeof (int32_t));
 
-  prach_vars->rxsigF[0]        = (int16_t**)malloc16_clear(64*sizeof(int16_t*));
+  prach_vars->rxsigF[0] = (int16_t **) malloc16_clear (64 * sizeof (int16_t *));
   // PRACH BR
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   prach_vars_br->prachF = (int16_t*)malloc16_clear( 1024*2*sizeof(int32_t) );
 
   // assume maximum of 64 RX antennas for PRACH receiver
-  for (int ce_level=0;ce_level<4;ce_level++) {
-    prach_vars_br->prach_ifft[ce_level] = (int32_t**)malloc16_clear(64*sizeof(int32_t*));
-    for (i=0;i<64;i++) prach_vars_br->prach_ifft[ce_level][i] = (int32_t*)malloc16_clear(1024*2*sizeof(int32_t));
-    prach_vars->rxsigF[ce_level]        = (int16_t**)malloc16_clear(64*sizeof(int16_t*));
+  for (int ce_level = 0; ce_level < 4; ce_level++) {
+    prach_vars_br->prach_ifft[ce_level] = (int32_t **) malloc16_clear (64 * sizeof (int32_t *));
+    for (i = 0; i < 64; i++)
+      prach_vars_br->prach_ifft[ce_level][i] = (int32_t *) malloc16_clear (1024 * 2 * sizeof (int32_t));
+    prach_vars->rxsigF[ce_level] = (int16_t **) malloc16_clear (64 * sizeof (int16_t *));
   }
 #endif
-  
+
   /* number of elements of an array X is computed as sizeof(X) / sizeof(X[0]) 
   AssertFatal(fp->nb_antennas_rx <= sizeof(prach_vars->rxsigF) / sizeof(prach_vars->rxsigF[0]),
               "nb_antennas_rx too large");
@@ -847,20 +847,20 @@ int phy_init_lte_eNB(PHY_VARS_eNB *eNB,
   for (UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++) {
     
     //FIXME
-    pusch_vars[UE_id] = (LTE_eNB_PUSCH*)malloc16_clear( NUMBER_OF_UE_MAX*sizeof(LTE_eNB_PUSCH) );
-    
-    pusch_vars[UE_id]->rxdataF_ext      = (int32_t**)malloc16( 2*sizeof(int32_t*) );
-    pusch_vars[UE_id]->rxdataF_ext2     = (int32_t**)malloc16( 2*sizeof(int32_t*) );
-    pusch_vars[UE_id]->drs_ch_estimates = (int32_t**)malloc16( 2*sizeof(int32_t*) );
-    pusch_vars[UE_id]->drs_ch_estimates_time = (int32_t**)malloc16( 2*sizeof(int32_t*) );
-    pusch_vars[UE_id]->rxdataF_comp     = (int32_t**)malloc16( 2*sizeof(int32_t*) );
-    pusch_vars[UE_id]->ul_ch_mag  = (int32_t**)malloc16( 2*sizeof(int32_t*) );
-    pusch_vars[UE_id]->ul_ch_magb = (int32_t**)malloc16( 2*sizeof(int32_t*) );
-    
-    AssertFatal(fp->ofdm_symbol_size > 127, "fp->ofdm_symbol_size %d<128\n",fp->ofdm_symbol_size);
-    AssertFatal(fp->symbols_per_tti > 11, "fp->symbols_per_tti %d < 12\n",fp->symbols_per_tti);
-    AssertFatal(fp->N_RB_UL > 5, "fp->N_RB_UL %d < 6\n",fp->N_RB_UL);
-    for (i=0; i<2; i++) {
+    pusch_vars[UE_id] = (LTE_eNB_PUSCH *) malloc16_clear (NUMBER_OF_UE_MAX * sizeof (LTE_eNB_PUSCH));
+
+    pusch_vars[UE_id]->rxdataF_ext = (int32_t **) malloc16 (2 * sizeof (int32_t *));
+    pusch_vars[UE_id]->rxdataF_ext2 = (int32_t **) malloc16 (2 * sizeof (int32_t *));
+    pusch_vars[UE_id]->drs_ch_estimates = (int32_t **) malloc16 (2 * sizeof (int32_t *));
+    pusch_vars[UE_id]->drs_ch_estimates_time = (int32_t **) malloc16 (2 * sizeof (int32_t *));
+    pusch_vars[UE_id]->rxdataF_comp = (int32_t **) malloc16 (2 * sizeof (int32_t *));
+    pusch_vars[UE_id]->ul_ch_mag = (int32_t **) malloc16 (2 * sizeof (int32_t *));
+    pusch_vars[UE_id]->ul_ch_magb = (int32_t **) malloc16 (2 * sizeof (int32_t *));
+
+    AssertFatal (fp->ofdm_symbol_size > 127, "fp->ofdm_symbol_size %d<128\n", fp->ofdm_symbol_size);
+    AssertFatal (fp->symbols_per_tti > 11, "fp->symbols_per_tti %d < 12\n", fp->symbols_per_tti);
+    AssertFatal (fp->N_RB_UL > 5, "fp->N_RB_UL %d < 6\n", fp->N_RB_UL);
+    for (i = 0; i < 2; i++) {
       // RK 2 times because of output format of FFT!
       // FIXME We should get rid of this
       pusch_vars[UE_id]->rxdataF_ext[i]      = (int32_t*)malloc16_clear( sizeof(int32_t)*fp->N_RB_UL*12*fp->symbols_per_tti );
@@ -875,12 +875,12 @@ int phy_init_lte_eNB(PHY_VARS_eNB *eNB,
     pusch_vars[UE_id]->llr = (int16_t*)malloc16_clear( (8*((3*8*6144)+12))*sizeof(int16_t) );
   } //UE_id
 
-    
-  for (UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++)
+
+  for (UE_id = 0; UE_id < NUMBER_OF_UE_MAX; UE_id++)
     eNB->UE_stats_ptr[UE_id] = &eNB->UE_stats[UE_id];
-  
-  eNB->pdsch_config_dedicated->p_a = dB0; //defaul value until overwritten by RRCConnectionReconfiguration
-  
+
+  eNB->pdsch_config_dedicated->p_a = dB0;       //defaul value until overwritten by RRCConnectionReconfiguration
+
 
   return (0);
 
@@ -893,7 +893,7 @@ void phy_free_lte_eNB(PHY_VARS_eNB *eNB)
   LTE_eNB_PUSCH** const pusch_vars   = eNB->pusch_vars;
   LTE_eNB_SRS* const srs_vars        = eNB->srs_vars;
   LTE_eNB_PRACH* const prach_vars    = &eNB->prach_vars;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   LTE_eNB_PRACH* const prach_vars_br = &eNB->prach_vars_br;
 #endif
   int i, UE_id;
@@ -926,7 +926,7 @@ void phy_free_lte_eNB(PHY_VARS_eNB *eNB)
   for (i = 0; i < 64; i++) free_and_zero(prach_vars->prach_ifft[0][i]);
   free_and_zero(prach_vars->prach_ifft[0]);
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   for (int ce_level = 0; ce_level < 4; ce_level++) {
     for (i = 0; i < 64; i++) free_and_zero(prach_vars_br->prach_ifft[ce_level][i]);
     free_and_zero(prach_vars_br->prach_ifft[ce_level]);
diff --git a/openair1/PHY/INIT/lte_init_ru.c b/openair1/PHY/INIT/lte_init_ru.c
index 3a1364620ed6d18e3134dcb9534f32e4a26487e2..c4cd3600c053fac24658923fd18073e845fe2661 100644
--- a/openair1/PHY/INIT/lte_init_ru.c
+++ b/openair1/PHY/INIT/lte_init_ru.c
@@ -23,10 +23,10 @@
 #include "SCHED/sched_eNB.h"
 #include "PHY/phy_extern.h"
 #include "SIMULATION/TOOLS/sim.h"
-#include "RadioResourceConfigCommonSIB.h"
-#include "RadioResourceConfigDedicated.h"
-#include "TDD-Config.h"
-#include "MBSFN-SubframeConfigList.h"
+#include "LTE_RadioResourceConfigCommonSIB.h"
+#include "LTE_RadioResourceConfigDedicated.h"
+#include "LTE_TDD-Config.h"
+#include "LTE_MBSFN-SubframeConfigList.h"
 #include "common/utils/LOG/vcd_signal_dumper.h"
 #include "assertions.h"
 #include <math.h>
@@ -67,6 +67,7 @@ int phy_init_RU(RU_t *ru) {
 
   }
   if (ru->function != NGFI_RRU_IF5) { // we need to do RX/TX RU processing
+    init_dfts();
     init_7_5KHz();
     LOG_I(PHY,"nb_tx %d\n",ru->nb_tx);
     ru->common.rxdata_7_5kHz = (int32_t**)malloc16(ru->nb_rx*sizeof(int32_t*) );
@@ -101,7 +102,7 @@ int phy_init_RU(RU_t *ru) {
     for (i=0; i<ru->nb_rx; i++) {
       ru->prach_rxsigF[i] = (int16_t*)malloc16_clear( fp->ofdm_symbol_size*12*2*sizeof(int16_t) );
       LOG_D(PHY,"[INIT] prach_vars->rxsigF[%d] = %p\n",i,ru->prach_rxsigF[i]);
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
       for (j=0;j<4;j++) {
 	ru->prach_rxsigF_br[j][i] = (int16_t*)malloc16_clear( fp->ofdm_symbol_size*12*2*sizeof(int16_t) );
 	LOG_D(PHY,"[INIT] prach_vars_br->rxsigF[%d] = %p\n",i,ru->prach_rxsigF_br[j][i]);
@@ -179,7 +180,7 @@ void phy_free_RU(RU_t *ru)
 
     for (i = 0; i < ru->nb_rx; i++) {
       free_and_zero(ru->prach_rxsigF[i]);
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
       for (j = 0; j < 4; j++) free_and_zero(ru->prach_rxsigF_br[j][i]);
 #endif
     }
diff --git a/openair1/PHY/INIT/lte_init_ue.c b/openair1/PHY/INIT/lte_init_ue.c
index 49778c2791507b6d4ca6f6a01e7f121c18da2b25..bd3aefb1c36c847005bab1ab9918952e8f407170 100644
--- a/openair1/PHY/INIT/lte_init_ue.c
+++ b/openair1/PHY/INIT/lte_init_ue.c
@@ -23,13 +23,14 @@
 #include "SCHED_UE/sched_UE.h"
 #include "PHY/phy_extern_ue.h"
 #include "SIMULATION/TOOLS/sim.h"
-#include "RadioResourceConfigCommonSIB.h"
-#include "RadioResourceConfigDedicated.h"
-#include "TDD-Config.h"
-#include "MBSFN-SubframeConfigList.h"
+#include "LTE_RadioResourceConfigCommonSIB.h"
+#include "LTE_RadioResourceConfigDedicated.h"
+#include "LTE_TDD-Config.h"
+#include "LTE_MBSFN-SubframeConfigList.h"
 #include "common/utils/LOG/vcd_signal_dumper.h"
 #include "assertions.h"
 #include <math.h>
+#include "PHY/LTE_ESTIMATION/lte_estimation.h"
 #include "PHY/LTE_TRANSPORT/transport_common_proto.h"
 #include "PHY/LTE_UE_TRANSPORT/transport_proto_ue.h"
 #include "PHY/LTE_REFSIG/lte_refsig.h"
@@ -41,7 +42,7 @@ extern uint8_t nfapi_mode;
 
 void phy_config_sib1_ue(module_id_t Mod_id,int CC_id,
                         uint8_t eNB_id,
-                        TDD_Config_t *tdd_Config,
+                        LTE_TDD_Config_t *tdd_Config,
                         uint8_t SIwindowsize,
                         uint16_t SIperiod)
 {
@@ -59,11 +60,11 @@ void phy_config_sib1_ue(module_id_t Mod_id,int CC_id,
 
 void phy_config_sib2_ue(module_id_t Mod_id,int CC_id,
                         uint8_t eNB_id,
-                        RadioResourceConfigCommonSIB_t *radioResourceConfigCommon,
-                        ARFCN_ValueEUTRA_t *ul_CarrierFreq,
+                        LTE_RadioResourceConfigCommonSIB_t *radioResourceConfigCommon,
+                        LTE_ARFCN_ValueEUTRA_t *ul_CarrierFreq,
                         long *ul_Bandwidth,
-                        AdditionalSpectrumEmission_t *additionalSpectrumEmission,
-                        struct MBSFN_SubframeConfigList *mbsfn_SubframeConfigList)
+                        LTE_AdditionalSpectrumEmission_t *additionalSpectrumEmission,
+                        struct LTE_MBSFN_SubframeConfigList *mbsfn_SubframeConfigList)
 {
 
   PHY_VARS_UE *ue        = PHY_vars_UE_g[Mod_id][CC_id];
@@ -114,7 +115,7 @@ void phy_config_sib2_ue(module_id_t Mod_id,int CC_id,
   init_ul_hopping(fp);
   fp->soundingrs_ul_config_common.enabled_flag                        = 0;
 
-  if (radioResourceConfigCommon->soundingRS_UL_ConfigCommon.present==SoundingRS_UL_ConfigCommon_PR_setup) {
+  if (radioResourceConfigCommon->soundingRS_UL_ConfigCommon.present == LTE_SoundingRS_UL_ConfigCommon_PR_setup) {
     fp->soundingrs_ul_config_common.enabled_flag                        = 1;
     fp->soundingrs_ul_config_common.srs_BandwidthConfig                 = radioResourceConfigCommon->soundingRS_UL_ConfigCommon.choice.setup.srs_BandwidthConfig;
     fp->soundingrs_ul_config_common.srs_SubframeConfig                  = radioResourceConfigCommon->soundingRS_UL_ConfigCommon.choice.setup.srs_SubframeConfig;
@@ -159,19 +160,19 @@ void phy_config_sib2_ue(module_id_t Mod_id,int CC_id,
       fp->MBSFN_config[i].radioframeAllocationPeriod = mbsfn_SubframeConfigList->list.array[i]->radioframeAllocationPeriod;
       fp->MBSFN_config[i].radioframeAllocationOffset = mbsfn_SubframeConfigList->list.array[i]->radioframeAllocationOffset;
 
-      if (mbsfn_SubframeConfigList->list.array[i]->subframeAllocation.present == MBSFN_SubframeConfig__subframeAllocation_PR_oneFrame) {
+      if (mbsfn_SubframeConfigList->list.array[i]->subframeAllocation.present == LTE_MBSFN_SubframeConfig__subframeAllocation_PR_oneFrame) {
         fp->MBSFN_config[i].fourFrames_flag = 0;
         fp->MBSFN_config[i].mbsfn_SubframeConfig = mbsfn_SubframeConfigList->list.array[i]->subframeAllocation.choice.oneFrame.buf[0]; // 6-bit subframe configuration
-        LOG_I(PHY, "[CONFIG] MBSFN_SubframeConfig[%d] pattern is  %d\n", i,
+        LOG_I(PHY, "[CONFIG] LTE_MBSFN_SubframeConfig[%d] pattern is  %d\n", i,
               fp->MBSFN_config[i].mbsfn_SubframeConfig);
-      } else if (mbsfn_SubframeConfigList->list.array[i]->subframeAllocation.present == MBSFN_SubframeConfig__subframeAllocation_PR_fourFrames) { // 24-bit subframe configuration
+      } else if (mbsfn_SubframeConfigList->list.array[i]->subframeAllocation.present == LTE_MBSFN_SubframeConfig__subframeAllocation_PR_fourFrames) { // 24-bit subframe configuration
         fp->MBSFN_config[i].fourFrames_flag = 1;
         fp->MBSFN_config[i].mbsfn_SubframeConfig =
           mbsfn_SubframeConfigList->list.array[i]->subframeAllocation.choice.oneFrame.buf[2]|
           (mbsfn_SubframeConfigList->list.array[i]->subframeAllocation.choice.oneFrame.buf[1]<<8)|
           (mbsfn_SubframeConfigList->list.array[i]->subframeAllocation.choice.oneFrame.buf[0]<<16);
 
-        LOG_I(PHY, "[CONFIG] MBSFN_SubframeConfig[%d] pattern is  %x\n", i,
+        LOG_I(PHY, "[CONFIG]  LTE_MBSFN_SubframeConfig[%d] pattern is  %x\n", i,
               fp->MBSFN_config[i].mbsfn_SubframeConfig);
       }
     }
@@ -203,11 +204,11 @@ void phy_config_sib13_ue(module_id_t Mod_id,int CC_id,uint8_t eNB_id,int mbsfn_A
 /*
  * Configures UE MAC and PHY with radioResourceCommon received in mobilityControlInfo IE during Handover
  */
-void phy_config_afterHO_ue(module_id_t Mod_id,uint8_t CC_id,uint8_t eNB_id, MobilityControlInfo_t *mobilityControlInfo, uint8_t ho_failed)
+void phy_config_afterHO_ue(module_id_t Mod_id,uint8_t CC_id,uint8_t eNB_id, LTE_MobilityControlInfo_t *mobilityControlInfo, uint8_t ho_failed)
 {
 
   if(mobilityControlInfo!=NULL) {
-    RadioResourceConfigCommon_t *radioResourceConfigCommon = &mobilityControlInfo->radioResourceConfigCommon;
+    LTE_RadioResourceConfigCommon_t *radioResourceConfigCommon = &mobilityControlInfo->radioResourceConfigCommon;
     LOG_I(PHY,"radioResourceConfigCommon %p\n", radioResourceConfigCommon);
     memcpy((void *)&PHY_vars_UE_g[Mod_id][CC_id]->frame_parms_before_ho,
            (void *)&PHY_vars_UE_g[Mod_id][CC_id]->frame_parms,
@@ -264,7 +265,7 @@ void phy_config_afterHO_ue(module_id_t Mod_id,uint8_t CC_id,uint8_t eNB_id, Mobi
     init_ul_hopping(fp);
     fp->soundingrs_ul_config_common.enabled_flag                        = 0;
 
-    if (radioResourceConfigCommon->soundingRS_UL_ConfigCommon->present==SoundingRS_UL_ConfigCommon_PR_setup) {
+    if (radioResourceConfigCommon->soundingRS_UL_ConfigCommon->present == LTE_SoundingRS_UL_ConfigCommon_PR_setup) {
       fp->soundingrs_ul_config_common.enabled_flag                        = 1;
       fp->soundingrs_ul_config_common.srs_BandwidthConfig                 = radioResourceConfigCommon->soundingRS_UL_ConfigCommon->choice.setup.srs_BandwidthConfig;
       fp->soundingrs_ul_config_common.srs_SubframeConfig                  = radioResourceConfigCommon->soundingRS_UL_ConfigCommon->choice.setup.srs_SubframeConfig;
@@ -344,10 +345,10 @@ void phy_config_meas_ue(module_id_t Mod_id,uint8_t CC_id,uint8_t eNB_index,uint8
 
 }
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 void phy_config_dedicated_scell_ue(uint8_t Mod_id,
                                    uint8_t eNB_index,
-                                   SCellToAddMod_r10_t *sCellToAddMod_r10,
+                                   LTE_SCellToAddMod_r10_t *sCellToAddMod_r10,
                                    int CC_id)
 {
 
@@ -366,7 +367,7 @@ void phy_config_harq_ue(module_id_t Mod_id,int CC_id,uint8_t eNB_id,
 extern uint16_t beta_cqi[16];
 
 void phy_config_dedicated_ue(module_id_t Mod_id,int CC_id,uint8_t eNB_id,
-                             struct PhysicalConfigDedicated *physicalConfigDedicated )
+                             struct LTE_PhysicalConfigDedicated *physicalConfigDedicated )
 {
 
   static uint8_t first_dedicated_configuration = 0;
@@ -396,7 +397,7 @@ void phy_config_dedicated_ue(module_id_t Mod_id,int CC_id,uint8_t eNB_id,
     }
 
     if (physicalConfigDedicated->pucch_ConfigDedicated) {
-      if (physicalConfigDedicated->pucch_ConfigDedicated->ackNackRepetition.present==PUCCH_ConfigDedicated__ackNackRepetition_PR_release)
+      if (physicalConfigDedicated->pucch_ConfigDedicated->ackNackRepetition.present == LTE_PUCCH_ConfigDedicated__ackNackRepetition_PR_release)
         phy_vars_ue->pucch_config_dedicated[eNB_id].ackNackRepetition=0;
       else {
         phy_vars_ue->pucch_config_dedicated[eNB_id].ackNackRepetition=1;
@@ -448,25 +449,25 @@ void phy_config_dedicated_ue(module_id_t Mod_id,int CC_id,uint8_t eNB_id,
       phy_vars_ue->transmission_mode[eNB_id] = 1+(physicalConfigDedicated->antennaInfo->choice.explicitValue.transmissionMode);
       LOG_I(PHY,"Transmission Mode %d\n",phy_vars_ue->transmission_mode[eNB_id]);
       switch(physicalConfigDedicated->antennaInfo->choice.explicitValue.transmissionMode) {
-      case AntennaInfoDedicated__transmissionMode_tm1:
+      case LTE_AntennaInfoDedicated__transmissionMode_tm1:
         phy_vars_ue->transmission_mode[eNB_id] = 1;
         break;
-      case AntennaInfoDedicated__transmissionMode_tm2:
+      case LTE_AntennaInfoDedicated__transmissionMode_tm2:
         phy_vars_ue->transmission_mode[eNB_id] = 2;
         break;
-      case AntennaInfoDedicated__transmissionMode_tm3:
+      case LTE_AntennaInfoDedicated__transmissionMode_tm3:
         phy_vars_ue->transmission_mode[eNB_id] = 3;
         break;
-      case AntennaInfoDedicated__transmissionMode_tm4:
+      case LTE_AntennaInfoDedicated__transmissionMode_tm4:
         phy_vars_ue->transmission_mode[eNB_id] = 4;
         break;
-      case AntennaInfoDedicated__transmissionMode_tm5:
+      case LTE_AntennaInfoDedicated__transmissionMode_tm5:
         phy_vars_ue->transmission_mode[eNB_id] = 5;
         break;
-      case AntennaInfoDedicated__transmissionMode_tm6:
+      case LTE_AntennaInfoDedicated__transmissionMode_tm6:
         phy_vars_ue->transmission_mode[eNB_id] = 6;
         break;
-      case AntennaInfoDedicated__transmissionMode_tm7:
+      case LTE_AntennaInfoDedicated__transmissionMode_tm7:
         lte_gold_ue_spec_port5(phy_vars_ue->lte_gold_uespec_port5_table, phy_vars_ue->frame_parms.Nid_cell, phy_vars_ue->pdcch_vars[0][eNB_id]->crnti);
         phy_vars_ue->transmission_mode[eNB_id] = 7;
         break;
@@ -479,7 +480,7 @@ void phy_config_dedicated_ue(module_id_t Mod_id,int CC_id,uint8_t eNB_id,
     }
 
     if (physicalConfigDedicated->schedulingRequestConfig) {
-      if (physicalConfigDedicated->schedulingRequestConfig->present == SchedulingRequestConfig_PR_setup) {
+      if (physicalConfigDedicated->schedulingRequestConfig->present == LTE_SchedulingRequestConfig_PR_setup) {
         phy_vars_ue->scheduling_request_config[eNB_id].sr_PUCCH_ResourceIndex = physicalConfigDedicated->schedulingRequestConfig->choice.setup.sr_PUCCH_ResourceIndex;
         phy_vars_ue->scheduling_request_config[eNB_id].sr_ConfigIndex=physicalConfigDedicated->schedulingRequestConfig->choice.setup.sr_ConfigIndex;
         phy_vars_ue->scheduling_request_config[eNB_id].dsr_TransMax=physicalConfigDedicated->schedulingRequestConfig->choice.setup.dsr_TransMax;
@@ -496,7 +497,7 @@ void phy_config_dedicated_ue(module_id_t Mod_id,int CC_id,uint8_t eNB_id,
     if (physicalConfigDedicated->soundingRS_UL_ConfigDedicated) {
 
       phy_vars_ue->soundingrs_ul_config_dedicated[eNB_id].srsConfigDedicatedSetup = 0;
-      if (physicalConfigDedicated->soundingRS_UL_ConfigDedicated->present == SoundingRS_UL_ConfigDedicated_PR_setup) {
+      if (physicalConfigDedicated->soundingRS_UL_ConfigDedicated->present == LTE_SoundingRS_UL_ConfigDedicated_PR_setup) {
         phy_vars_ue->soundingrs_ul_config_dedicated[eNB_id].srsConfigDedicatedSetup = 1;
         phy_vars_ue->soundingrs_ul_config_dedicated[eNB_id].duration             = physicalConfigDedicated->soundingRS_UL_ConfigDedicated->choice.setup.duration;
         phy_vars_ue->soundingrs_ul_config_dedicated[eNB_id].cyclicShift          = physicalConfigDedicated->soundingRS_UL_ConfigDedicated->choice.setup.cyclicShift;
@@ -525,14 +526,14 @@ void phy_config_dedicated_ue(module_id_t Mod_id,int CC_id,uint8_t eNB_id,
           LOG_E(PHY,"Unsupported Aperiodic CQI Feedback Mode : %d\n",phy_vars_ue->cqi_report_config[eNB_id].cqi_ReportModeAperiodic);
       }
       if (physicalConfigDedicated->cqi_ReportConfig->cqi_ReportPeriodic) {
-        if (physicalConfigDedicated->cqi_ReportConfig->cqi_ReportPeriodic->present == CQI_ReportPeriodic_PR_setup) {
+        if (physicalConfigDedicated->cqi_ReportConfig->cqi_ReportPeriodic->present == LTE_CQI_ReportPeriodic_PR_setup) {
         // configure PUCCH CQI reporting
           phy_vars_ue->cqi_report_config[eNB_id].CQI_ReportPeriodic.cqi_PUCCH_ResourceIndex = physicalConfigDedicated->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.cqi_PUCCH_ResourceIndex;
           phy_vars_ue->cqi_report_config[eNB_id].CQI_ReportPeriodic.cqi_PMI_ConfigIndex     = physicalConfigDedicated->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.cqi_pmi_ConfigIndex;
           if (physicalConfigDedicated->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.ri_ConfigIndex)
             phy_vars_ue->cqi_report_config[eNB_id].CQI_ReportPeriodic.ri_ConfigIndex = *physicalConfigDedicated->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.ri_ConfigIndex;
         }
-        else if (physicalConfigDedicated->cqi_ReportConfig->cqi_ReportPeriodic->present == CQI_ReportPeriodic_PR_release) {
+        else if (physicalConfigDedicated->cqi_ReportConfig->cqi_ReportPeriodic->present == LTE_CQI_ReportPeriodic_PR_release) {
           // handle release
           phy_vars_ue->cqi_report_config[eNB_id].CQI_ReportPeriodic.ri_ConfigIndex = -1;
           phy_vars_ue->cqi_report_config[eNB_id].CQI_ReportPeriodic.cqi_PMI_ConfigIndex = -1;
@@ -661,8 +662,9 @@ int init_lte_ue_signal(PHY_VARS_UE *ue,
 
 
 
-
+  init_dfts();
   init_frame_parms(&ue->frame_parms,1);
+  lte_sync_time_init(&ue->frame_parms);
   init_lte_top(&ue->frame_parms);
   init_7_5KHz();
   init_ul_hopping(&ue->frame_parms);
diff --git a/openair1/PHY/INIT/phy_init.h b/openair1/PHY/INIT/phy_init.h
index da4050c84824f8eaf9df4c16b454afa433fbcc9f..9e08dabba236e30089c28e4f43d036b021dfee31 100644
--- a/openair1/PHY/INIT/phy_init.h
+++ b/openair1/PHY/INIT/phy_init.h
@@ -25,15 +25,15 @@
 #include "PHY/defs_eNB.h"
 #include "PHY/defs_UE.h"
 
-#include "SystemInformationBlockType2.h"
+#include "LTE_SystemInformationBlockType2.h"
 //#include "RadioResourceConfigCommonSIB.h"
-#include "RadioResourceConfigDedicated.h"
-#include "TDD-Config.h"
-#include "PHICH-Config.h"
-#include "MBSFN-SubframeConfigList.h"
-#include "MobilityControlInfo.h"
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-#include "SCellToAddMod-r10.h"
+#include "LTE_RadioResourceConfigDedicated.h"
+#include "LTE_TDD-Config.h"
+#include "LTE_PHICH-Config.h"
+#include "LTE_MBSFN-SubframeConfigList.h"
+#include "LTE_MobilityControlInfo.h"
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#include "LTE_SCellToAddMod-r10.h"
 #endif
 /** @addtogroup _PHY_STRUCTURES_
  * @{
@@ -110,7 +110,7 @@ void phy_config_mib_eNB(int                    Mod_id,
 			int                    CC_id,
 			int                    eutra_band,
 			int                    N_RB_DL,
-			PHICH_Config_t         *phich_config,
+			LTE_PHICH_Config_t    *phich_config,
 			int                    Nid_cell,
 			int                    Ncp,
 			int                    p_eNB,
@@ -128,7 +128,7 @@ void phy_config_mib_eNB(int                    Mod_id,
 @param SIperiod Periodicity of System Information Messages (in multiples of a frame)*/
 void phy_config_sib1_eNB(module_id_t    Mod_id,
                          int CC_id,
-                         TDD_Config_t  *tdd_Config,
+                         LTE_TDD_Config_t  *tdd_Config,
                          uint8_t           SIwindowsize,
                          uint16_t            SIperiod);
 
@@ -143,7 +143,7 @@ void phy_config_sib1_eNB(module_id_t    Mod_id,
 void phy_config_sib1_ue(module_id_t   Mod_id,
                         int CC_id,
                         uint8_t          CH_index,
-                        TDD_Config_t *tdd_Config,
+                        LTE_TDD_Config_t *tdd_Config,
                         uint8_t          SIwindowsize,
                         uint16_t           SIperiod);
 
@@ -166,14 +166,14 @@ void phy_config_sib1_ue(module_id_t   Mod_id,
   @param additionalSpectrumEmission UL parameter (see 36.101)
   @param mbsfn_SubframeConfigList MBSFN subframe configuration
  */
-void phy_config_sib2_ue(module_id_t                     Mod_id,
-                        int                         CC_id,
-                        uint8_t                         CH_index,
-                        RadioResourceConfigCommonSIB_t  *radioResourceConfigCommon,
-                        ARFCN_ValueEUTRA_t              *ul_CArrierFreq,
-                        long                            *ul_Bandwidth,
-                        AdditionalSpectrumEmission_t    *additionalSpectrumEmission,
-                        struct MBSFN_SubframeConfigList *mbsfn_SubframeConfigList);
+void phy_config_sib2_ue(module_id_t                          Mod_id,
+                        int                                  CC_id,
+                        uint8_t                              CH_index,
+                        LTE_RadioResourceConfigCommonSIB_t  *radioResourceConfigCommon,
+                        LTE_ARFCN_ValueEUTRA_t              *ul_CArrierFreq,
+                        long                                *ul_Bandwidth,
+                        LTE_AdditionalSpectrumEmission_t    *additionalSpectrumEmission,
+                        struct LTE_MBSFN_SubframeConfigList *mbsfn_SubframeConfigList);
 
 
 /*!
@@ -188,7 +188,7 @@ void phy_config_sib2_ue(module_id_t                     Mod_id,
 void phy_config_afterHO_ue(module_id_t Mod_id,
                            uint8_t CC_id,
                            uint8_t eNB_index,
-                           MobilityControlInfo_t *mobilityControlInfo,
+                           LTE_MobilityControlInfo_t *mobilityControlInfo,
                            uint8_t ho_failed);
 /*!
   \fn void phy_config_sib2_eNB(module_id_t Mod_id,
@@ -206,13 +206,13 @@ void phy_config_afterHO_ue(module_id_t Mod_id,
   @param additionalSpectrumEmission UL parameter (see 36.101)
   @param mbsfn_SubframeConfigList MBSFN subframe configuration
  */
-void phy_config_sib2_eNB(module_id_t                            Mod_id,
-                         int                                CC_id,
-                         RadioResourceConfigCommonSIB_t         *radioResourceConfigCommon,
-                         ARFCN_ValueEUTRA_t                     *ul_CArrierFreq,
+void phy_config_sib2_eNB(module_id_t                             Mod_id,
+                         int                                     CC_id,
+                         LTE_RadioResourceConfigCommonSIB_t     *radioResourceConfigCommon,
+                         LTE_ARFCN_ValueEUTRA_t                 *ul_CArrierFreq,
                          long                                   *ul_Bandwidth,
-                         AdditionalSpectrumEmission_t           *additionalSpectrumEmission,
-                         struct MBSFN_SubframeConfigList        *mbsfn_SubframeConfigList);
+                         LTE_AdditionalSpectrumEmission_t       *additionalSpectrumEmission,
+                         struct LTE_MBSFN_SubframeConfigList    *mbsfn_SubframeConfigList);
 
 
 /*!
@@ -229,7 +229,7 @@ void phy_config_sib2_eNB(module_id_t                            Mod_id,
 void phy_config_dedicated_ue(module_id_t Mod_id,
                              int CC_id,
                              uint8_t CH_index,
-                             struct PhysicalConfigDedicated *physicalConfigDedicated);
+                             struct LTE_PhysicalConfigDedicated *physicalConfigDedicated);
 
 /*!
 \fn void phy_config_harq_ue(module_id_t Mod_id,uint8_t CC_id,uint8_t CH_index,
@@ -308,7 +308,7 @@ void phy_config_meas_ue(module_id_t Mod_id,
 void phy_config_dedicated_eNB(module_id_t Mod_id,
                               int CC_id,
                               rnti_t rnti,
-                              struct PhysicalConfigDedicated *physicalConfigDedicated);
+                              struct LTE_PhysicalConfigDedicated *physicalConfigDedicated);
 
 /*!
 \fn void phy_config_dedicated_eNB_step2(PHY_VARS_eNB *phy_vars_eNB)
@@ -349,15 +349,15 @@ void lte_param_init(PHY_VARS_eNB **eNBp,
 		    uint32_t perfect_ce);
 
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 void phy_config_dedicated_scell_ue(uint8_t Mod_id,
                                    uint8_t eNB_index,
-                                   SCellToAddMod_r10_t *sCellToAddMod_r10,
+                                   LTE_SCellToAddMod_r10_t *sCellToAddMod_r10,
                                    int CC_id);
 
 void phy_config_dedicated_scell_eNB(uint8_t Mod_id,
                                     uint16_t rnti,
-                                    SCellToAddMod_r10_t *sCellToAddMod_r10,
+                                    LTE_SCellToAddMod_r10_t *sCellToAddMod_r10,
                                     int CC_id);
 
 #endif
diff --git a/openair1/PHY/LTE_ESTIMATION/lte_adjust_sync.c b/openair1/PHY/LTE_ESTIMATION/lte_adjust_sync.c
deleted file mode 100644
index 516cb32999b505aa08f1e36c2c23a1d08c747288..0000000000000000000000000000000000000000
--- a/openair1/PHY/LTE_ESTIMATION/lte_adjust_sync.c
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * 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 "PHY/types.h"
-#include "PHY/defs_UE.h"
-#include "PHY/phy_extern_ue.h"
-
-#include "UTIL/LOG/vcd_signal_dumper.h"
-#include "openair2/LAYER2/MAC/mac_proto.h"
-
-#define DEBUG_PHY
-
-// Adjust location synchronization point to account for drift
-// The adjustment is performed once per frame based on the
-// last channel estimate of the receiver
-
-void lte_adjust_synch(LTE_DL_FRAME_PARMS *frame_parms,
-                      PHY_VARS_UE *ue,
-                      module_id_t eNB_id,
-					  uint8_t subframe,
-                      unsigned char clear,
-                      short coef)
-{
-
-  static int max_pos_fil = 0;
-  static int count_max_pos_ok = 0;
-  static int first_time = 1;
-  int temp = 0, i, aa, max_val = 0, max_pos = 0;
-  int diff;
-  short Re,Im,ncoef;
-
-  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_ADJUST_SYNCH, VCD_FUNCTION_IN);
-
-  ncoef = 32767 - coef;
-
-#ifdef DEBUG_PHY
-  LOG_D(PHY,"AbsSubframe %d.%d: rx_offset (before) = %d\n",ue->proc.proc_rxtx[0].frame_rx%1024,subframe,ue->rx_offset);
-#endif //DEBUG_PHY
-
-
-  // we only use channel estimates from tx antenna 0 here
-  for (i = 0; i < frame_parms->nb_prefix_samples; i++) {
-    temp = 0;
-
-    for (aa=0; aa<frame_parms->nb_antennas_rx; aa++) {
-      Re = ((int16_t*)ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].dl_ch_estimates_time[eNB_id][aa])[(i<<1)];
-      Im = ((int16_t*)ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].dl_ch_estimates_time[eNB_id][aa])[1+(i<<1)];
-      temp += (Re*Re/2) + (Im*Im/2);
-    }
-
-    if (temp > max_val) {
-      max_pos = i;
-      max_val = temp;
-    }
-  }
-
-  // filter position to reduce jitter
-  if (clear == 1)
-    max_pos_fil = max_pos;
-  else
-    max_pos_fil = ((max_pos_fil * coef) + (max_pos * ncoef)) >> 15;
-
-  // do not filter to have proactive timing adjustment
-  max_pos_fil = max_pos;
-
-  if(subframe == 5)
-  {
-      diff = max_pos_fil - (frame_parms->nb_prefix_samples>>3);
-
-#if BASIC_SIMULATOR
-      /* a hack without which the UE does not connect (to be fixed somehow) */
-      diff = 0;
-#endif
-
-      if ( abs(diff) < SYNCH_HYST )
-          ue->rx_offset = 0;
-      else
-          ue->rx_offset = diff;
-
-      if(abs(diff)<5)
-          count_max_pos_ok ++;
-      else
-          count_max_pos_ok = 0;
-
-      if(count_max_pos_ok > 10 && first_time == 1)
-      {
-          first_time = 0;
-          ue->time_sync_cell = 1;
-          if (ue->mac_enabled==1) {
-              LOG_I(PHY,"[UE%d] Sending synch status to higher layers\n",ue->Mod_id);
-              //mac_resynch();
-              dl_phy_sync_success(ue->Mod_id,ue->proc.proc_rxtx[0].frame_rx,0,1);//ue->common_vars.eNb_id);
-              ue->UE_mode[0] = PRACH;
-          }
-          else {
-              ue->UE_mode[0] = PUSCH;
-          }
-      }
-
-      if ( ue->rx_offset < 0 )
-          ue->rx_offset += FRAME_LENGTH_COMPLEX_SAMPLES;
-
-      if ( ue->rx_offset >= FRAME_LENGTH_COMPLEX_SAMPLES )
-          ue->rx_offset -= FRAME_LENGTH_COMPLEX_SAMPLES;
-
-
-
-      #ifdef DEBUG_PHY
-      LOG_D(PHY,"AbsSubframe %d.%d: ThreadId %d diff =%i rx_offset (final) = %i : clear %d,max_pos = %d,max_pos_fil = %d (peak %d) max_val %d target_pos %d \n",
-              ue->proc.proc_rxtx[ue->current_thread_id[subframe]].frame_rx,
-              subframe,
-              ue->current_thread_id[subframe],
-              diff,
-              ue->rx_offset,
-              clear,
-              max_pos,
-              max_pos_fil,
-              temp,max_val,
-              (frame_parms->nb_prefix_samples>>3));
-      #endif //DEBUG_PHY
-
-      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_ADJUST_SYNCH, VCD_FUNCTION_OUT);
-  }
-}
diff --git a/openair1/PHY/LTE_ESTIMATION/lte_adjust_sync_ue.c b/openair1/PHY/LTE_ESTIMATION/lte_adjust_sync_ue.c
index c912c8893482c1c00c47b73128a0e7de5b73a052..e8a0913e7386ec20027e0060116ca1331c03a1a5 100644
--- a/openair1/PHY/LTE_ESTIMATION/lte_adjust_sync_ue.c
+++ b/openair1/PHY/LTE_ESTIMATION/lte_adjust_sync_ue.c
@@ -36,7 +36,7 @@
 void lte_adjust_synch(LTE_DL_FRAME_PARMS *frame_parms,
                       PHY_VARS_UE *ue,
                       module_id_t eNB_id,
-					  uint8_t subframe,
+		      uint8_t subframe,
                       unsigned char clear,
                       short coef)
 {
@@ -96,6 +96,7 @@ void lte_adjust_synch(LTE_DL_FRAME_PARMS *frame_parms,
       else
           count_max_pos_ok = 0;
 
+
       if(count_max_pos_ok > 10 && first_time == 1)
       {
           first_time = 0;
@@ -103,7 +104,7 @@ void lte_adjust_synch(LTE_DL_FRAME_PARMS *frame_parms,
           if (ue->mac_enabled==1) {
               LOG_I(PHY,"[UE%d] Sending synch status to higher layers\n",ue->Mod_id);
               //mac_resynch();
-              dl_phy_sync_success(ue->Mod_id,ue->proc.proc_rxtx[0].frame_rx,0,1);//ue->common_vars.eNb_id);
+              //dl_phy_sync_success(ue->Mod_id,ue->proc.proc_rxtx[0].frame_rx,0,1);//ue->common_vars.eNb_id);
               ue->UE_mode[0] = PRACH;
           }
           else {
diff --git a/openair1/PHY/LTE_ESTIMATION/lte_dl_channel_estimation.c b/openair1/PHY/LTE_ESTIMATION/lte_dl_channel_estimation.c
index f7c4a3ead3156cb0b2e49ad7db1b837d6ecd5ec6..e50af7cdd8f297a95b8c3eeb440227eb5ec37658 100644
--- a/openair1/PHY/LTE_ESTIMATION/lte_dl_channel_estimation.c
+++ b/openair1/PHY/LTE_ESTIMATION/lte_dl_channel_estimation.c
@@ -34,8 +34,7 @@ int lte_dl_channel_estimation(PHY_VARS_UE *ue,
                               unsigned char Ns,
                               unsigned char p,
                               unsigned char l,
-                              unsigned char symbol)
-{
+                              unsigned char symbol) {
   int pilot[2][200] __attribute__((aligned(16)));
   unsigned char nu,aarx;
   unsigned short k;
@@ -45,16 +44,14 @@ int lte_dl_channel_estimation(PHY_VARS_UE *ue,
   //  unsigned int n;
   //  int i;
   static int interpolateS11S12 = 1;
-
   uint16_t Nid_cell = (eNB_offset == 0) ? ue->frame_parms.Nid_cell : ue->measurements.adj_cell_id[eNB_offset-1];
-
   uint8_t nushift,pilot0,pilot1,pilot2,pilot3;
   uint8_t previous_thread_id = ue->current_thread_id[Ns>>1]==0 ? (RX_NB_TH-1):(ue->current_thread_id[Ns>>1]-1);
   int **dl_ch_estimates         =ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].dl_ch_estimates[eNB_offset];
   int **dl_ch_estimates_previous=ue->common_vars.common_vars_rx_data_per_thread[previous_thread_id].dl_ch_estimates[eNB_offset];
   int **rxdataF=ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].rxdataF;
-
   pilot0 = 0;
+
   if (ue->frame_parms.Ncp == 0) {  // normal prefix
     pilot1 = 4;
     pilot2 = 7;
@@ -81,7 +78,6 @@ int lte_dl_channel_estimation(PHY_VARS_UE *ue,
     return(-1);
   }
 
-
   //ch_offset     = (l*(ue->frame_parms.ofdm_symbol_size));
   if (ue->high_speed_flag == 0) // use second channel estimate position for temporary storage
     ch_offset     = ue->frame_parms.ofdm_symbol_size ;
@@ -89,93 +85,88 @@ int lte_dl_channel_estimation(PHY_VARS_UE *ue,
     ch_offset     = ue->frame_parms.ofdm_symbol_size*symbol;
 
   symbol_offset = ue->frame_parms.ofdm_symbol_size*symbol;
-
   k = (nu + nushift)%6;
-
 #ifdef DEBUG_CH
-  printf("Channel Estimation : ThreadId %d, eNB_offset %d cell_id %d ch_offset %d, OFDM size %d, Ncp=%d, l=%d, Ns=%d, k=%d\n",ue->current_thread_id[Ns>>1], eNB_offset,Nid_cell,ch_offset,ue->frame_parms.ofdm_symbol_size,
+  printf("Channel Estimation : ThreadId %d, eNB_offset %d cell_id %d ch_offset %d, OFDM size %d, Ncp=%d, l=%d, Ns=%d, k=%d\n",ue->current_thread_id[Ns>>1], eNB_offset,Nid_cell,ch_offset,
+         ue->frame_parms.ofdm_symbol_size,
          ue->frame_parms.Ncp,l,Ns,k);
 #endif
 
   switch (k) {
-  case 0 :
-    f=filt24_0;  //for first pilot of RB, first half
-    f2=filt24_2; //for second pilot of RB, first half
-    fl=filt24_0; //for first pilot of leftmost RB
-    f2l2=filt24_2;
-    //    fr=filt24_2r; //for first pilot of rightmost RB
-    fr=filt24_0r2; //for first pilot of rightmost RB
-    //    f2r2=filt24_0r2;
-    f2r2=filt24_2r;
-
-    f_dc=filt24_0_dcr;
-    f2_dc=filt24_2_dcl;
-
-    break;
-
-  case 1 :
-    f=filt24_1;
-    f2=filt24_3;
-    fl=filt24_1l;
-    f2l2=filt24_3l2;
-    fr=filt24_1r2;
-    f2r2=filt24_3r;
-    f_dc=filt24_1_dcr;  //for first pilot of RB, first half
-    f2_dc=filt24_3_dcl;  //for first pilot of RB, first half
-    break;
-
-  case 2 :
-    f=filt24_2;
-    f2=filt24_4;
-    fl=filt24_2l;
-    f2l2=filt24_4l2;
-    fr=filt24_2r2;
-    f2r2=filt24_4r;
-    f_dc=filt24_2_dcr;  //for first pilot of RB, first half
-    f2_dc=filt24_4_dcl;  //for first pilot of RB, first half
-    break;
-
-  case 3 :
-    f=filt24_3;
-    f2=filt24_5;
-    fl=filt24_3l;
-    f2l2=filt24_5l2;
-    fr=filt24_3r2;
-    f2r2=filt24_5r;
-    f_dc=filt24_3_dcr;  //for first pilot of RB, first half
-    f2_dc=filt24_5_dcl;  //for first pilot of RB, first half
-    break;
-
-  case 4 :
-    f=filt24_4;
-    f2=filt24_6;
-    fl=filt24_4l;
-    f2l2=filt24_6l2;
-    fr=filt24_4r2;
-    f2r2=filt24_6r;
-    f_dc=filt24_4_dcr;  //for first pilot of RB, first half
-    f2_dc=filt24_6_dcl;  //for first pilot of RB, first half
-    break;
-
-  case 5 :
-    f=filt24_5;
-    f2=filt24_7;
-    fl=filt24_5l;
-    f2l2=filt24_7l2;
-    fr=filt24_5r2;
-    f2r2=filt24_7r;
-    f_dc=filt24_5_dcr;  //for first pilot of RB, first half
-    f2_dc=filt24_7_dcl;  //for first pilot of RB, first half
-    break;
-
-  default:
-    LOG_E(PHY,"lte_dl_channel_estimation: k=%d -> ERROR\n",k);
-    return(-1);
-    break;
+    case 0 :
+      f=filt24_0;  //for first pilot of RB, first half
+      f2=filt24_2; //for second pilot of RB, first half
+      fl=filt24_0; //for first pilot of leftmost RB
+      f2l2=filt24_2;
+      //    fr=filt24_2r; //for first pilot of rightmost RB
+      fr=filt24_0r2; //for first pilot of rightmost RB
+      //    f2r2=filt24_0r2;
+      f2r2=filt24_2r;
+      f_dc=filt24_0_dcr;
+      f2_dc=filt24_2_dcl;
+      break;
+
+    case 1 :
+      f=filt24_1;
+      f2=filt24_3;
+      fl=filt24_1l;
+      f2l2=filt24_3l2;
+      fr=filt24_1r2;
+      f2r2=filt24_3r;
+      f_dc=filt24_1_dcr;  //for first pilot of RB, first half
+      f2_dc=filt24_3_dcl;  //for first pilot of RB, first half
+      break;
+
+    case 2 :
+      f=filt24_2;
+      f2=filt24_4;
+      fl=filt24_2l;
+      f2l2=filt24_4l2;
+      fr=filt24_2r2;
+      f2r2=filt24_4r;
+      f_dc=filt24_2_dcr;  //for first pilot of RB, first half
+      f2_dc=filt24_4_dcl;  //for first pilot of RB, first half
+      break;
+
+    case 3 :
+      f=filt24_3;
+      f2=filt24_5;
+      fl=filt24_3l;
+      f2l2=filt24_5l2;
+      fr=filt24_3r2;
+      f2r2=filt24_5r;
+      f_dc=filt24_3_dcr;  //for first pilot of RB, first half
+      f2_dc=filt24_5_dcl;  //for first pilot of RB, first half
+      break;
+
+    case 4 :
+      f=filt24_4;
+      f2=filt24_6;
+      fl=filt24_4l;
+      f2l2=filt24_6l2;
+      fr=filt24_4r2;
+      f2r2=filt24_6r;
+      f_dc=filt24_4_dcr;  //for first pilot of RB, first half
+      f2_dc=filt24_6_dcl;  //for first pilot of RB, first half
+      break;
+
+    case 5 :
+      f=filt24_5;
+      f2=filt24_7;
+      fl=filt24_5l;
+      f2l2=filt24_7l2;
+      fr=filt24_5r2;
+      f2r2=filt24_7r;
+      f_dc=filt24_5_dcr;  //for first pilot of RB, first half
+      f2_dc=filt24_7_dcl;  //for first pilot of RB, first half
+      break;
+
+    default:
+      LOG_E(PHY,"lte_dl_channel_estimation: k=%d -> ERROR\n",k);
+      return(-1);
+      break;
   }
 
-
-
   // generate pilot
   lte_dl_cell_spec_rx(ue,
                       eNB_offset,
@@ -184,27 +175,25 @@ int lte_dl_channel_estimation(PHY_VARS_UE *ue,
                       (l==0)?0:1,
                       p);
 
-
   for (aarx=0; aarx<ue->frame_parms.nb_antennas_rx; aarx++) {
-
     pil   = (int16_t *)&pilot[p][0];
     rxF   = (int16_t *)&rxdataF[aarx][((symbol_offset+k+ue->frame_parms.first_carrier_offset))];
     dl_ch = (int16_t *)&dl_ch_estimates[(p<<1)+aarx][ch_offset];
-
-
     //    if (eNb_id==0)
     memset(dl_ch,0,4*(ue->frame_parms.ofdm_symbol_size));
+
     if (ue->high_speed_flag==0) // multiply previous channel estimate by ch_est_alpha
       multadd_complex_vector_real_scalar(dl_ch-(ue->frame_parms.ofdm_symbol_size<<1),
                                          ue->ch_est_alpha,dl_ch-(ue->frame_parms.ofdm_symbol_size<<1),
                                          1,ue->frame_parms.ofdm_symbol_size);
+
 #ifdef DEBUG_CH
     printf("k %d, first_carrier %d\n",k,ue->frame_parms.first_carrier_offset);
 #endif
+
     if ((ue->frame_parms.N_RB_DL==6)  ||
         (ue->frame_parms.N_RB_DL==50) ||
         (ue->frame_parms.N_RB_DL==100)) {
-
       //First half of pilots
       // Treat first 2 pilots specially (left edge)
       ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
@@ -219,7 +208,6 @@ int lte_dl_channel_estimation(PHY_VARS_UE *ue,
       pil+=2;    // Re Im
       rxF+=12;
       dl_ch+=8;
-
       ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
       ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
 #ifdef DEBUG_CH
@@ -234,28 +222,22 @@ int lte_dl_channel_estimation(PHY_VARS_UE *ue,
       dl_ch+=16;
 
       for (pilot_cnt=2; pilot_cnt<((ue->frame_parms.N_RB_DL)-1); pilot_cnt+=2) {
-
-
-
         ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15); //Re
         ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15); //Im
 #ifdef DEBUG_CH
-	printf("pilot %d : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
+        printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
 #endif
         multadd_real_vector_complex_scalar(f,
                                            ch,
                                            dl_ch,
                                            24);
-
-
         pil+=2;    // Re Im
         rxF+=12;
         dl_ch+=8;
-
         ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
         ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
 #ifdef DEBUG_CH
-	printf("pilot %d : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+1,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
+        printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+1,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
 #endif
         multadd_real_vector_complex_scalar(f2,
                                            ch,
@@ -264,29 +246,25 @@ int lte_dl_channel_estimation(PHY_VARS_UE *ue,
         pil+=2;
         rxF+=12;
         dl_ch+=16;
-
       }
 
       //       printf("Second half\n");
       // Second half of RBs
-
       k = (nu + nushift)%6;
 
       if (k > 6)
         k -=6;
 
       rxF   = (int16_t *)&rxdataF[aarx][((symbol_offset+1+k))];
-
 #ifdef DEBUG_CH
       printf("second half k %d\n",k);
 #endif
-      for (pilot_cnt=0; pilot_cnt<((ue->frame_parms.N_RB_DL)-3); pilot_cnt+=2) {
-
 
+      for (pilot_cnt=0; pilot_cnt<((ue->frame_parms.N_RB_DL)-3); pilot_cnt+=2) {
         ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
         ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
 #ifdef DEBUG_CH
-	printf("pilot %d : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
+        printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
 #endif
         multadd_real_vector_complex_scalar(f,
                                            ch,
@@ -295,11 +273,10 @@ int lte_dl_channel_estimation(PHY_VARS_UE *ue,
         pil+=2;
         rxF+=12;
         dl_ch+=8;
-
         ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
         ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
 #ifdef DEBUG_CH
-	printf("pilot %d : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+1,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
+        printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+1,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
 #endif
         multadd_real_vector_complex_scalar(f2,
                                            ch,
@@ -308,13 +285,12 @@ int lte_dl_channel_estimation(PHY_VARS_UE *ue,
         pil+=2;
         rxF+=12;
         dl_ch+=16;
-
       }
 
       ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
       ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
 #ifdef DEBUG_CH
-      printf("pilot %d: rxF -> (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
+      printf("pilot %u: rxF -> (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
 #endif
       multadd_real_vector_complex_scalar(fr,
                                          ch,
@@ -323,34 +299,25 @@ int lte_dl_channel_estimation(PHY_VARS_UE *ue,
       pil+=2;    // Re Im
       rxF+=12;
       dl_ch+=8;
-
       ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
       ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
 #ifdef DEBUG_CH
-      printf("pilot %d: rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+1,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
+      printf("pilot %u: rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+1,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
 #endif
       multadd_real_vector_complex_scalar(f2r2,
                                          ch,
                                          dl_ch,
                                          24);
-
-
-    }
-
-    else if (ue->frame_parms.N_RB_DL==25) {
+    } else if (ue->frame_parms.N_RB_DL==25) {
       //printf("Channel estimation\n");
-
       // Treat first 2 pilots specially (left edge)
       ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
       ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
-
 #ifdef DEBUG_CH
       printf("pilot 0 : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
-
       //      ch[0] = 1024;
       //      ch[1] = -128;
 #endif
-
       multadd_real_vector_complex_scalar(fl,
                                          ch,
                                          dl_ch,
@@ -358,17 +325,13 @@ int lte_dl_channel_estimation(PHY_VARS_UE *ue,
       pil+=2;    // Re Im
       rxF+=12;
       dl_ch+=8;
-
       ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
       ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
-
 #ifdef DEBUG_CH
       printf("pilot 1 : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
-
       //      ch[0] = 1024;
       //      ch[1] = -128;
 #endif
-
       multadd_real_vector_complex_scalar(f2l2,
                                          ch,
                                          dl_ch,
@@ -378,21 +341,15 @@ int lte_dl_channel_estimation(PHY_VARS_UE *ue,
       dl_ch+=16;
 
       for (pilot_cnt=2; pilot_cnt<24; pilot_cnt+=2) {
-
         // printf("pilot[%d][%d] (%d,%d)\n",p,rb,pil[0],pil[1]);
         // printf("rx[%d][%d] -> (%d,%d)\n",p,ue->frame_parms.first_carrier_offset + ue->frame_parms.nushift + 6*rb+(3*p),rxF[0],rxF[1]);
-
         ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
         ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
-
 #ifdef DEBUG_CH
-        printf("pilot %d : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
-
+        printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
         //  ch[0] = 1024;
         //  ch[1] = -128;
 #endif
-
-
         multadd_real_vector_complex_scalar(f,
                                            ch,
                                            dl_ch,
@@ -400,13 +357,10 @@ int lte_dl_channel_estimation(PHY_VARS_UE *ue,
         pil+=2;    // Re Im
         rxF+=12;
         dl_ch+=8;
-
         ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
         ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
-
 #ifdef DEBUG_CH
-        printf("pilot %d : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+1,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
-
+        printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+1,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
         //  ch[0] = 1024;
         //  ch[1] = -128;
 #endif
@@ -417,39 +371,31 @@ int lte_dl_channel_estimation(PHY_VARS_UE *ue,
         pil+=2;
         rxF+=12;
         dl_ch+=16;
-
       }
 
       ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
       ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
 #ifdef DEBUG_CH
       printf("pilot 24: rxF -> (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
-
       //      ch[0] = 1024;
       //      ch[1] = -128;
 #endif
-
-
       multadd_real_vector_complex_scalar(f_dc,
                                          ch,
                                          dl_ch,
                                          24);
       pil+=2;    // Re Im
       dl_ch+=8;
-
       // printf("Second half\n");
       // Second half of RBs
       rxF   = (int16_t *)&rxdataF[aarx][((symbol_offset+1+k))];
-
       ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
       ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
 #ifdef DEBUG_CH
       printf("pilot 25: rxF -> (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
-
       //      ch[0] = 1024;
       //      ch[1] = -128;
 #endif
-
       multadd_real_vector_complex_scalar(f2_dc,
                                          ch,
                                          dl_ch,
@@ -459,19 +405,15 @@ int lte_dl_channel_estimation(PHY_VARS_UE *ue,
       dl_ch+=16;
 
       for (pilot_cnt=0; pilot_cnt<22; pilot_cnt+=2) {
-
         // printf("* pilot[%d][%d] (%d,%d)\n",p,rb,pil[0],pil[1]);
         // printf("rx[%d][%d] -> (%d,%d)\n",p,ue->frame_parms.first_carrier_offset + ue->frame_parms.nushift + 6*rb+(3*p),rxF[0],rxF[1]);
-
         ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
         ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
 #ifdef DEBUG_CH
-        printf("pilot %d rxF -> (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",26+pilot_cnt,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
-
+        printf("pilot %u rxF -> (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",26+pilot_cnt,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
         //  ch[0] = 1024;
         //  ch[1] = -128;
 #endif
-
         multadd_real_vector_complex_scalar(f,
                                            ch,
                                            dl_ch,
@@ -479,16 +421,13 @@ int lte_dl_channel_estimation(PHY_VARS_UE *ue,
         pil+=2;
         rxF+=12;
         dl_ch+=8;
-
         ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
         ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
 #ifdef DEBUG_CH
-        printf("pilot %d : rxF -> (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",27+pilot_cnt,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
-
+        printf("pilot %u : rxF -> (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",27+pilot_cnt,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
         //  ch[0] = 1024;
         //  ch[1] = -128;
 #endif
-
         multadd_real_vector_complex_scalar(f2,
                                            ch,
                                            dl_ch,
@@ -496,20 +435,15 @@ int lte_dl_channel_estimation(PHY_VARS_UE *ue,
         pil+=2;
         rxF+=12;
         dl_ch+=16;
-
       }
 
       ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
       ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
-
 #ifdef DEBUG_CH
       printf("pilot 49: rxF -> (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
-
       //      ch[0] = 1024;
       //      ch[1] = -128;
 #endif
-
-
       multadd_real_vector_complex_scalar(fr,
                                          ch,
                                          dl_ch,
@@ -517,28 +451,20 @@ int lte_dl_channel_estimation(PHY_VARS_UE *ue,
       pil+=2;    // Re Im
       rxF+=12;
       dl_ch+=8;
-
       ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
       ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
-
 #ifdef DEBUG_CH
-
       printf("pilot 50: rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
-
       //      ch[0] = 1024;
       //      ch[1] = -128;
 #endif
-
       multadd_real_vector_complex_scalar(f2r2,
                                          ch,
                                          dl_ch,
                                          24);
-
     } else if (ue->frame_parms.N_RB_DL==15) {
-
       //printf("First Half\n");
       for (rb=0; rb<28; rb+=4) {
-
         //printf("aarx=%d\n",aarx);
         //printf("pilot[%d][%d] (%d,%d)\n",p,rb,pil[0],pil[1]);
         //printf("rx[%d][%d] -> (%d,%d)\n",p,
@@ -555,7 +481,6 @@ int lte_dl_channel_estimation(PHY_VARS_UE *ue,
         pil+=2;    // Re Im
         rxF+=12;
         dl_ch+=8;
-
         ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
         ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
         //printf("ch -> (%d,%d)\n",ch[0],ch[1]);
@@ -566,7 +491,6 @@ int lte_dl_channel_estimation(PHY_VARS_UE *ue,
         pil+=2;
         rxF+=12;
         dl_ch+=16;
-
       }
 
       ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
@@ -578,13 +502,11 @@ int lte_dl_channel_estimation(PHY_VARS_UE *ue,
                                          24);
       pil+=2;    // Re Im
       dl_ch+=8;
-
       //printf("Second half\n");
       //Second half of RBs
       rxF   = (int16_t *)&rxdataF[aarx][((symbol_offset+1+nushift + (3*p)))];
       ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
       ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
-
       multadd_real_vector_complex_scalar(f2,
                                          ch,
                                          dl_ch,
@@ -602,7 +524,6 @@ int lte_dl_channel_estimation(PHY_VARS_UE *ue,
         //       rxF[1]);
         ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
         ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
-
         multadd_real_vector_complex_scalar(f,
                                            ch,
                                            dl_ch,
@@ -610,10 +531,8 @@ int lte_dl_channel_estimation(PHY_VARS_UE *ue,
         pil+=2;
         rxF+=12;
         dl_ch+=8;
-
         ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
         ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
-
         multadd_real_vector_complex_scalar(f2,
                                            ch,
                                            dl_ch,
@@ -621,17 +540,14 @@ int lte_dl_channel_estimation(PHY_VARS_UE *ue,
         pil+=2;
         rxF+=12;
         dl_ch+=16;
-
       }
     } else {
       LOG_E(PHY,"channel estimation not implemented for ue->frame_parms.N_RB_DL = %d\n",ue->frame_parms.N_RB_DL);
     }
 
-
     if (ue->perfect_ce == 0) {
       // Temporal Interpolation
       // printf("ch_offset %d\n",ch_offset);
-
       dl_ch = (int16_t *)&dl_ch_estimates[(p<<1)+aarx][ch_offset];
 
       if (ue->high_speed_flag == 0) {
@@ -639,182 +555,155 @@ int lte_dl_channel_estimation(PHY_VARS_UE *ue,
                                            32767-ue->ch_est_alpha,
                                            dl_ch-(ue->frame_parms.ofdm_symbol_size<<1),0,ue->frame_parms.ofdm_symbol_size);
       } else { // high_speed_flag == 1
-            if ((symbol == 0)) {
-              //      printf("Interpolating %d->0\n",4-ue->frame_parms.Ncp);
-              //      dl_ch_prev = (int16_t *)&dl_ch_estimates[(p<<1)+aarx][(4-ue->frame_parms.Ncp)*(ue->frame_parms.ofdm_symbol_size)];
-          if(((Ns>>1)!=0) || ( ((Ns>>1)==0) && interpolateS11S12))
-          {
-                  //LOG_I(PHY,"Interpolate s11-->s0 to get s12 and s13  Ns %d \n", Ns);
-                  dl_ch_prev = (int16_t *)&dl_ch_estimates_previous[(p<<1)+aarx][pilot3*(ue->frame_parms.ofdm_symbol_size)];
-
-                  multadd_complex_vector_real_scalar(dl_ch_prev,21845,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)),1,ue->frame_parms.ofdm_symbol_size);
-                  multadd_complex_vector_real_scalar(dl_ch,10923,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)),0,ue->frame_parms.ofdm_symbol_size);
-
-                  multadd_complex_vector_real_scalar(dl_ch_prev,10923,dl_ch_prev+(2*((ue->frame_parms.ofdm_symbol_size)<<1)),1,ue->frame_parms.ofdm_symbol_size);
-                  multadd_complex_vector_real_scalar(dl_ch,21845,dl_ch_prev+(2*((ue->frame_parms.ofdm_symbol_size)<<1)),0,ue->frame_parms.ofdm_symbol_size);
-           }
-
-              interpolateS11S12 = 1;
-            } // this is 1/3,2/3 combination for pilots spaced by 3 symbols
-            else if (symbol == pilot1) {
-              dl_ch_prev = (int16_t *)&dl_ch_estimates[(p<<1)+aarx][0];
-
-              //LOG_I(PHY,"Interpolate s0-->s4 to get s1 s2 and s3 Ns %d \n", Ns);
-              if (ue->frame_parms.Ncp==0) {// pilot spacing 4 symbols (1/4,1/2,3/4 combination)
-
-                uint8_t previous_subframe;
-                if(Ns>>1 == 0)
-                    previous_subframe = 9;
-                else
-                    previous_subframe = ((Ns>>1) - 1 )%9;
-
-                if((subframe_select(&ue->frame_parms,previous_subframe) == SF_UL))
-                {
-
-                    multadd_complex_vector_real_scalar(dl_ch_prev,328,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)),1,ue->frame_parms.ofdm_symbol_size);
-                    multadd_complex_vector_real_scalar(dl_ch,32440,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)),0,ue->frame_parms.ofdm_symbol_size);
-
-                    multadd_complex_vector_real_scalar(dl_ch_prev,328,dl_ch_prev+(2*((ue->frame_parms.ofdm_symbol_size)<<1)),1,ue->frame_parms.ofdm_symbol_size);
-                    multadd_complex_vector_real_scalar(dl_ch,32440,dl_ch_prev+(2*((ue->frame_parms.ofdm_symbol_size)<<1)),0,ue->frame_parms.ofdm_symbol_size);
-
-                    multadd_complex_vector_real_scalar(dl_ch_prev,8192,dl_ch_prev+(3*2*(ue->frame_parms.ofdm_symbol_size)),1,ue->frame_parms.ofdm_symbol_size);
-                    multadd_complex_vector_real_scalar(dl_ch,32440,dl_ch_prev+(3*2*(ue->frame_parms.ofdm_symbol_size)),0,ue->frame_parms.ofdm_symbol_size);
-                }
-                else
-                {
-                    multadd_complex_vector_real_scalar(dl_ch_prev,24576,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)),1,ue->frame_parms.ofdm_symbol_size);
-                    multadd_complex_vector_real_scalar(dl_ch,8192,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)),0,ue->frame_parms.ofdm_symbol_size);
-
-                    multadd_complex_vector_real_scalar(dl_ch_prev,16384,dl_ch_prev+(2*((ue->frame_parms.ofdm_symbol_size)<<1)),1,ue->frame_parms.ofdm_symbol_size);
-                    multadd_complex_vector_real_scalar(dl_ch,16384,dl_ch_prev+(2*((ue->frame_parms.ofdm_symbol_size)<<1)),0,ue->frame_parms.ofdm_symbol_size);
-
-                    multadd_complex_vector_real_scalar(dl_ch_prev,8192,dl_ch_prev+(3*2*(ue->frame_parms.ofdm_symbol_size)),1,ue->frame_parms.ofdm_symbol_size);
-                    multadd_complex_vector_real_scalar(dl_ch,24576,dl_ch_prev+(3*2*(ue->frame_parms.ofdm_symbol_size)),0,ue->frame_parms.ofdm_symbol_size);
-
-                    }
-              } else {
-                multadd_complex_vector_real_scalar(dl_ch_prev,328,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)),1,ue->frame_parms.ofdm_symbol_size);
-                multadd_complex_vector_real_scalar(dl_ch,21845,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)),0,ue->frame_parms.ofdm_symbol_size);
-
-                multadd_complex_vector_real_scalar(dl_ch_prev,21845,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)<<1),1,ue->frame_parms.ofdm_symbol_size);
-                multadd_complex_vector_real_scalar(dl_ch,10923,dl_ch_prev+(2*((ue->frame_parms.ofdm_symbol_size)<<1)),0,ue->frame_parms.ofdm_symbol_size);
-              } // pilot spacing 3 symbols (1/3,2/3 combination)
-            } else if (symbol == pilot2) {
-              dl_ch_prev = (int16_t *)&dl_ch_estimates[(p<<1)+aarx][pilot1*(ue->frame_parms.ofdm_symbol_size)];
-
-              multadd_complex_vector_real_scalar(dl_ch_prev,21845,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)),1,ue->frame_parms.ofdm_symbol_size);
-              multadd_complex_vector_real_scalar(dl_ch,10923,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)),0,ue->frame_parms.ofdm_symbol_size);
-
-              multadd_complex_vector_real_scalar(dl_ch_prev,10923,dl_ch_prev+(2*((ue->frame_parms.ofdm_symbol_size)<<1)),1,ue->frame_parms.ofdm_symbol_size);
-              multadd_complex_vector_real_scalar(dl_ch,21845,dl_ch_prev+(2*((ue->frame_parms.ofdm_symbol_size)<<1)),0,ue->frame_parms.ofdm_symbol_size);
-            } else { // symbol == pilot3
-              //      printf("Interpolating 0->%d\n",4-ue->frame_parms.Ncp);
-              dl_ch_prev = (int16_t *)&dl_ch_estimates[(p<<1)+aarx][pilot2*(ue->frame_parms.ofdm_symbol_size)];
-
-              if (ue->frame_parms.Ncp==0) {// pilot spacing 4 symbols (1/4,1/2,3/4 combination)
-                multadd_complex_vector_real_scalar(dl_ch_prev,24576,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)),1,ue->frame_parms.ofdm_symbol_size);
-                multadd_complex_vector_real_scalar(dl_ch,8192,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)),0,ue->frame_parms.ofdm_symbol_size);
-
-                multadd_complex_vector_real_scalar(dl_ch_prev,16384,dl_ch_prev+(2*((ue->frame_parms.ofdm_symbol_size)<<1)),1,ue->frame_parms.ofdm_symbol_size);
-                multadd_complex_vector_real_scalar(dl_ch,16384,dl_ch_prev+(2*((ue->frame_parms.ofdm_symbol_size)<<1)),0,ue->frame_parms.ofdm_symbol_size);
-
-                multadd_complex_vector_real_scalar(dl_ch_prev,8192,dl_ch_prev+(3*2*(ue->frame_parms.ofdm_symbol_size)),1,ue->frame_parms.ofdm_symbol_size);
-                multadd_complex_vector_real_scalar(dl_ch,24576,dl_ch_prev+(3*2*(ue->frame_parms.ofdm_symbol_size)),0,ue->frame_parms.ofdm_symbol_size);
-              } else {
-                multadd_complex_vector_real_scalar(dl_ch_prev,10923,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)),1,ue->frame_parms.ofdm_symbol_size);
-                multadd_complex_vector_real_scalar(dl_ch,21845,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)),0,ue->frame_parms.ofdm_symbol_size);
-
-                multadd_complex_vector_real_scalar(dl_ch_prev,21845,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)<<1),1,ue->frame_parms.ofdm_symbol_size);
-                multadd_complex_vector_real_scalar(dl_ch,10923,dl_ch_prev+(2*((ue->frame_parms.ofdm_symbol_size)<<1)),0,ue->frame_parms.ofdm_symbol_size);
-              } // pilot spacing 3 symbols (1/3,2/3 combination)
-
-              if((ue->rx_offset_diff !=0) && ((Ns>>1) == 9))
-              {
-                  //LOG_I(PHY,"Extrapolate s7-->s11 to get s12 and s13 Ns %d\n", Ns);
-                  interpolateS11S12 = 0;
-                  //LOG_E(PHY,"Interpolate s7--s11 s12 s13 pilot 3 Ns %d l %d symbol %d \n", Ns, l, symbol);
-                  int16_t *dlChEst_ofdm11 = (int16_t *)&dl_ch_estimates[(p<<1)+aarx][pilot3*(ue->frame_parms.ofdm_symbol_size)];
-                  int16_t *dlChEst_ofdm7  = (int16_t *)&dl_ch_estimates[(p<<1)+aarx][pilot2*(ue->frame_parms.ofdm_symbol_size)];
-
-                  // interpolate ofdm s12: 5/4*ofdms11 + -1/4*ofdms7 5/4 q1.15 40960 -1/4 q1.15 8192
-                  int16_t *dlChEst_ofdm12 = (int16_t *)&dl_ch_estimates[(p<<1)+aarx][12*ue->frame_parms.ofdm_symbol_size];
-                  for(int i=0; i<(2*ue->frame_parms.ofdm_symbol_size); i++)
-                  {
-                      int64_t tmp_mult = 0;
-                      tmp_mult = ((int64_t)dlChEst_ofdm11[i] * 40960 - (int64_t)dlChEst_ofdm7[i] * 8192);
-
-                      tmp_mult = tmp_mult >> 15;
-                      dlChEst_ofdm12[i] = tmp_mult;
-                  }
-
-                  // interpolate ofdm s13: 3/2*ofdms11 + -1/2*ofdms7 3/2 q1.15 49152 1/2 q1.15 16384
-                  int16_t *dlChEst_ofdm13 = (int16_t *)&dl_ch_estimates[(p<<1)+aarx][13*ue->frame_parms.ofdm_symbol_size];
-                  for(int i=0; i<(2*ue->frame_parms.ofdm_symbol_size); i++)
-                  {
-                      int64_t tmp_mult = 0;
-                      tmp_mult = ((int64_t)dlChEst_ofdm11[i] * 49152 - (int64_t)dlChEst_ofdm7[i] * 16384);
-
-                      tmp_mult = tmp_mult >> 15;
-                      dlChEst_ofdm13[i] = tmp_mult;
-                  }
-              }
+        if ((symbol == 0)) {
+          //      printf("Interpolating %d->0\n",4-ue->frame_parms.Ncp);
+          //      dl_ch_prev = (int16_t *)&dl_ch_estimates[(p<<1)+aarx][(4-ue->frame_parms.Ncp)*(ue->frame_parms.ofdm_symbol_size)];
+          if(((Ns>>1)!=0) || ( ((Ns>>1)==0) && interpolateS11S12)) {
+            //LOG_I(PHY,"Interpolate s11-->s0 to get s12 and s13  Ns %d \n", Ns);
+            dl_ch_prev = (int16_t *)&dl_ch_estimates_previous[(p<<1)+aarx][pilot3*(ue->frame_parms.ofdm_symbol_size)];
+            multadd_complex_vector_real_scalar(dl_ch_prev,21845,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)),1,ue->frame_parms.ofdm_symbol_size);
+            multadd_complex_vector_real_scalar(dl_ch,10923,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)),0,ue->frame_parms.ofdm_symbol_size);
+            multadd_complex_vector_real_scalar(dl_ch_prev,10923,dl_ch_prev+(2*((ue->frame_parms.ofdm_symbol_size)<<1)),1,ue->frame_parms.ofdm_symbol_size);
+            multadd_complex_vector_real_scalar(dl_ch,21845,dl_ch_prev+(2*((ue->frame_parms.ofdm_symbol_size)<<1)),0,ue->frame_parms.ofdm_symbol_size);
+          }
 
+          interpolateS11S12 = 1;
+        } // this is 1/3,2/3 combination for pilots spaced by 3 symbols
+        else if (symbol == pilot1) {
+          dl_ch_prev = (int16_t *)&dl_ch_estimates[(p<<1)+aarx][0];
+
+          //LOG_I(PHY,"Interpolate s0-->s4 to get s1 s2 and s3 Ns %d \n", Ns);
+          if (ue->frame_parms.Ncp==0) {// pilot spacing 4 symbols (1/4,1/2,3/4 combination)
+            uint8_t previous_subframe;
+
+            if(Ns>>1 == 0)
+              previous_subframe = 9;
+            else
+              previous_subframe = ((Ns>>1) - 1 )%9;
+
+            if((subframe_select(&ue->frame_parms,previous_subframe) == SF_UL)) {
+              multadd_complex_vector_real_scalar(dl_ch_prev,328,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)),1,ue->frame_parms.ofdm_symbol_size);
+              multadd_complex_vector_real_scalar(dl_ch,32440,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)),0,ue->frame_parms.ofdm_symbol_size);
+              multadd_complex_vector_real_scalar(dl_ch_prev,328,dl_ch_prev+(2*((ue->frame_parms.ofdm_symbol_size)<<1)),1,ue->frame_parms.ofdm_symbol_size);
+              multadd_complex_vector_real_scalar(dl_ch,32440,dl_ch_prev+(2*((ue->frame_parms.ofdm_symbol_size)<<1)),0,ue->frame_parms.ofdm_symbol_size);
+              multadd_complex_vector_real_scalar(dl_ch_prev,8192,dl_ch_prev+(3*2*(ue->frame_parms.ofdm_symbol_size)),1,ue->frame_parms.ofdm_symbol_size);
+              multadd_complex_vector_real_scalar(dl_ch,32440,dl_ch_prev+(3*2*(ue->frame_parms.ofdm_symbol_size)),0,ue->frame_parms.ofdm_symbol_size);
+            } else {
+              multadd_complex_vector_real_scalar(dl_ch_prev,24576,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)),1,ue->frame_parms.ofdm_symbol_size);
+              multadd_complex_vector_real_scalar(dl_ch,8192,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)),0,ue->frame_parms.ofdm_symbol_size);
+              multadd_complex_vector_real_scalar(dl_ch_prev,16384,dl_ch_prev+(2*((ue->frame_parms.ofdm_symbol_size)<<1)),1,ue->frame_parms.ofdm_symbol_size);
+              multadd_complex_vector_real_scalar(dl_ch,16384,dl_ch_prev+(2*((ue->frame_parms.ofdm_symbol_size)<<1)),0,ue->frame_parms.ofdm_symbol_size);
+              multadd_complex_vector_real_scalar(dl_ch_prev,8192,dl_ch_prev+(3*2*(ue->frame_parms.ofdm_symbol_size)),1,ue->frame_parms.ofdm_symbol_size);
+              multadd_complex_vector_real_scalar(dl_ch,24576,dl_ch_prev+(3*2*(ue->frame_parms.ofdm_symbol_size)),0,ue->frame_parms.ofdm_symbol_size);
+            }
+          } else {
+            multadd_complex_vector_real_scalar(dl_ch_prev,328,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)),1,ue->frame_parms.ofdm_symbol_size);
+            multadd_complex_vector_real_scalar(dl_ch,21845,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)),0,ue->frame_parms.ofdm_symbol_size);
+            multadd_complex_vector_real_scalar(dl_ch_prev,21845,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)<<1),1,ue->frame_parms.ofdm_symbol_size);
+            multadd_complex_vector_real_scalar(dl_ch,10923,dl_ch_prev+(2*((ue->frame_parms.ofdm_symbol_size)<<1)),0,ue->frame_parms.ofdm_symbol_size);
+          } // pilot spacing 3 symbols (1/3,2/3 combination)
+        } else if (symbol == pilot2) {
+          dl_ch_prev = (int16_t *)&dl_ch_estimates[(p<<1)+aarx][pilot1*(ue->frame_parms.ofdm_symbol_size)];
+          multadd_complex_vector_real_scalar(dl_ch_prev,21845,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)),1,ue->frame_parms.ofdm_symbol_size);
+          multadd_complex_vector_real_scalar(dl_ch,10923,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)),0,ue->frame_parms.ofdm_symbol_size);
+          multadd_complex_vector_real_scalar(dl_ch_prev,10923,dl_ch_prev+(2*((ue->frame_parms.ofdm_symbol_size)<<1)),1,ue->frame_parms.ofdm_symbol_size);
+          multadd_complex_vector_real_scalar(dl_ch,21845,dl_ch_prev+(2*((ue->frame_parms.ofdm_symbol_size)<<1)),0,ue->frame_parms.ofdm_symbol_size);
+        } else { // symbol == pilot3
+          //      printf("Interpolating 0->%d\n",4-ue->frame_parms.Ncp);
+          dl_ch_prev = (int16_t *)&dl_ch_estimates[(p<<1)+aarx][pilot2*(ue->frame_parms.ofdm_symbol_size)];
+
+          if (ue->frame_parms.Ncp==0) {// pilot spacing 4 symbols (1/4,1/2,3/4 combination)
+            multadd_complex_vector_real_scalar(dl_ch_prev,24576,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)),1,ue->frame_parms.ofdm_symbol_size);
+            multadd_complex_vector_real_scalar(dl_ch,8192,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)),0,ue->frame_parms.ofdm_symbol_size);
+            multadd_complex_vector_real_scalar(dl_ch_prev,16384,dl_ch_prev+(2*((ue->frame_parms.ofdm_symbol_size)<<1)),1,ue->frame_parms.ofdm_symbol_size);
+            multadd_complex_vector_real_scalar(dl_ch,16384,dl_ch_prev+(2*((ue->frame_parms.ofdm_symbol_size)<<1)),0,ue->frame_parms.ofdm_symbol_size);
+            multadd_complex_vector_real_scalar(dl_ch_prev,8192,dl_ch_prev+(3*2*(ue->frame_parms.ofdm_symbol_size)),1,ue->frame_parms.ofdm_symbol_size);
+            multadd_complex_vector_real_scalar(dl_ch,24576,dl_ch_prev+(3*2*(ue->frame_parms.ofdm_symbol_size)),0,ue->frame_parms.ofdm_symbol_size);
+          } else {
+            multadd_complex_vector_real_scalar(dl_ch_prev,10923,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)),1,ue->frame_parms.ofdm_symbol_size);
+            multadd_complex_vector_real_scalar(dl_ch,21845,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)),0,ue->frame_parms.ofdm_symbol_size);
+            multadd_complex_vector_real_scalar(dl_ch_prev,21845,dl_ch_prev+(2*(ue->frame_parms.ofdm_symbol_size)<<1),1,ue->frame_parms.ofdm_symbol_size);
+            multadd_complex_vector_real_scalar(dl_ch,10923,dl_ch_prev+(2*((ue->frame_parms.ofdm_symbol_size)<<1)),0,ue->frame_parms.ofdm_symbol_size);
+          } // pilot spacing 3 symbols (1/3,2/3 combination)
+
+          if((ue->rx_offset_diff !=0) && ((Ns>>1) == 9)) {
+            //LOG_I(PHY,"Extrapolate s7-->s11 to get s12 and s13 Ns %d\n", Ns);
+            interpolateS11S12 = 0;
+            //LOG_E(PHY,"Interpolate s7--s11 s12 s13 pilot 3 Ns %d l %d symbol %d \n", Ns, l, symbol);
+            int16_t *dlChEst_ofdm11 = (int16_t *)&dl_ch_estimates[(p<<1)+aarx][pilot3*(ue->frame_parms.ofdm_symbol_size)];
+            int16_t *dlChEst_ofdm7  = (int16_t *)&dl_ch_estimates[(p<<1)+aarx][pilot2*(ue->frame_parms.ofdm_symbol_size)];
+            // interpolate ofdm s12: 5/4*ofdms11 + -1/4*ofdms7 5/4 q1.15 40960 -1/4 q1.15 8192
+            int16_t *dlChEst_ofdm12 = (int16_t *)&dl_ch_estimates[(p<<1)+aarx][12*ue->frame_parms.ofdm_symbol_size];
+
+            for(int i=0; i<(2*ue->frame_parms.ofdm_symbol_size); i++) {
+              int64_t tmp_mult = 0;
+              tmp_mult = ((int64_t)dlChEst_ofdm11[i] * 40960 - (int64_t)dlChEst_ofdm7[i] * 8192);
+              tmp_mult = tmp_mult >> 15;
+              dlChEst_ofdm12[i] = tmp_mult;
             }
-        }
 
+            // interpolate ofdm s13: 3/2*ofdms11 + -1/2*ofdms7 3/2 q1.15 49152 1/2 q1.15 16384
+            int16_t *dlChEst_ofdm13 = (int16_t *)&dl_ch_estimates[(p<<1)+aarx][13*ue->frame_parms.ofdm_symbol_size];
+
+            for(int i=0; i<(2*ue->frame_parms.ofdm_symbol_size); i++) {
+              int64_t tmp_mult = 0;
+              tmp_mult = ((int64_t)dlChEst_ofdm11[i] * 49152 - (int64_t)dlChEst_ofdm7[i] * 16384);
+              tmp_mult = tmp_mult >> 15;
+              dlChEst_ofdm13[i] = tmp_mult;
+            }
+          }
+        }
+      }
     }
   }
 
   void (*idft)(int16_t *,int16_t *, int);
 
   switch (ue->frame_parms.ofdm_symbol_size) {
-  case 128:
-    idft = idft128;
-    break;
+    case 128:
+      idft = idft128;
+      break;
 
-  case 256:
-    idft = idft256;
-    break;
+    case 256:
+      idft = idft256;
+      break;
 
-  case 512:
-    idft = idft512;
-    break;
+    case 512:
+      idft = idft512;
+      break;
 
-  case 1024:
-    idft = idft1024;
-    break;
+    case 1024:
+      idft = idft1024;
+      break;
 
-  case 1536:
-    idft = idft1536;
-    break;
+    case 1536:
+      idft = idft1536;
+      break;
 
-  case 2048:
-    idft = idft2048;
-    break;
+    case 2048:
+      idft = idft2048;
+      break;
 
-  default:
-    idft = idft512;
-    break;
+    default:
+      idft = idft512;
+      break;
   }
 
-  if( ((Ns%2) == 0) && (l == pilot0))
-  {
-      // do ifft of channel estimate
-      for (aarx=0; aarx<ue->frame_parms.nb_antennas_rx; aarx++)
-          for (p=0; p<ue->frame_parms.nb_antenna_ports_eNB; p++) {
-              if (ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].dl_ch_estimates[eNB_offset][(p<<1)+aarx])
-              {
-                  //LOG_I(PHY,"Channel Impulse Computation Slot %d ThreadId %d Symbol %d \n", Ns, ue->current_thread_id[Ns>>1], l);
-                  idft((int16_t*) &ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].dl_ch_estimates[eNB_offset][(p<<1)+aarx][8],
-                          (int16_t*) ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].dl_ch_estimates_time[eNB_offset][(p<<1)+aarx],1);
-              }
-          }
+  if( ((Ns%2) == 0) && (l == pilot0)) {
+    // do ifft of channel estimate
+    for (aarx=0; aarx<ue->frame_parms.nb_antennas_rx; aarx++)
+      for (p=0; p<ue->frame_parms.nb_antenna_ports_eNB; p++) {
+        if (ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].dl_ch_estimates[eNB_offset][(p<<1)+aarx]) {
+          //LOG_I(PHY,"Channel Impulse Computation Slot %d ThreadId %d Symbol %d \n", Ns, ue->current_thread_id[Ns>>1], l);
+          idft((int16_t *) &ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].dl_ch_estimates[eNB_offset][(p<<1)+aarx][8],
+               (int16_t *) ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].dl_ch_estimates_time[eNB_offset][(p<<1)+aarx],1);
+        }
+      }
   }
 
   T(T_UE_PHY_DL_CHANNEL_ESTIMATE, T_INT(eNB_id),
     T_INT(ue->proc.proc_rxtx[ue->current_thread_id[Ns>>1]].frame_rx%1024), T_INT(ue->proc.proc_rxtx[ue->current_thread_id[Ns>>1]].subframe_rx),
     T_INT(0), T_BUFFER(&ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].dl_ch_estimates_time[eNB_offset][0][0], 512  * 4));
-
   return(0);
 }
 
diff --git a/openair1/PHY/LTE_ESTIMATION/lte_estimation.h b/openair1/PHY/LTE_ESTIMATION/lte_estimation.h
index 4512fc0d9be15bf9d52efaf1f68248725fc0d8ba..9cdc2f4bf7bbc49b219972ec8e58a4c0100f918f 100644
--- a/openair1/PHY/LTE_ESTIMATION/lte_estimation.h
+++ b/openair1/PHY/LTE_ESTIMATION/lte_estimation.h
@@ -203,7 +203,7 @@ void phy_adjust_gain (PHY_VARS_UE *phy_vars_ue,
                       unsigned char eNB_id);
 
 int lte_ul_channel_estimation(PHY_VARS_eNB *phy_vars_eNB,
-			      eNB_rxtx_proc_t *proc,
+			      L1_rxtx_proc_t *proc,
                               module_id_t UE_id,
                               uint8_t l,
                               uint8_t Ns);
diff --git a/openair1/PHY/LTE_ESTIMATION/lte_estimation_extern.h b/openair1/PHY/LTE_ESTIMATION/lte_estimation_extern.h
deleted file mode 100644
index 4690bba42e5b91f4721d727b38d41da928e0c55a..0000000000000000000000000000000000000000
--- a/openair1/PHY/LTE_ESTIMATION/lte_estimation_extern.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * 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
- */
-
diff --git a/openair1/PHY/LTE_ESTIMATION/lte_ul_channel_estimation.c b/openair1/PHY/LTE_ESTIMATION/lte_ul_channel_estimation.c
index a8d73cfdea4efd724d8c54a0e0923380e8a16379..1baeaae8065452fd48eb6c7739ee16a54c4d5844 100644
--- a/openair1/PHY/LTE_ESTIMATION/lte_ul_channel_estimation.c
+++ b/openair1/PHY/LTE_ESTIMATION/lte_ul_channel_estimation.c
@@ -35,7 +35,7 @@ static int16_t ru_90c[2*128] = {32767, 0,32766, -402,32758, -804,32746, -1206,32
 #define SCALE 0x3FFF
 
 int32_t lte_ul_channel_estimation(PHY_VARS_eNB *eNB,
-				  eNB_rxtx_proc_t *proc,
+				  L1_rxtx_proc_t *proc,
                                   module_id_t UE_id,
                                   unsigned char l,
                                   unsigned char Ns) {
@@ -46,12 +46,12 @@ int32_t lte_ul_channel_estimation(PHY_VARS_eNB *eNB,
   int32_t **ul_ch_estimates_time=  pusch_vars->drs_ch_estimates_time;
   int32_t **rxdataF_ext=  pusch_vars->rxdataF_ext;
   int subframe = proc->subframe_rx;
-  uint8_t harq_pid = subframe2harq_pid(frame_parms,proc->frame_rx,subframe);
+  uint8_t harq_pid;
   int16_t delta_phase = 0;
   int16_t *ru1 = ru_90;
   int16_t *ru2 = ru_90;
   int16_t current_phase1,current_phase2;
-  uint16_t N_rb_alloc = eNB->ulsch[UE_id]->harq_processes[harq_pid]->nb_rb;
+
   uint16_t aa,Msc_RS,Msc_RS_idx;
   uint16_t * Msc_idx_ptr;
   int k,pilot_pos1 = 3 - frame_parms->Ncp, pilot_pos2 = 10 - 2*frame_parms->Ncp;
@@ -65,7 +65,7 @@ int32_t lte_ul_channel_estimation(PHY_VARS_eNB *eNB,
   uint32_t alpha_ind;
   uint32_t u=frame_parms->pusch_config_common.ul_ReferenceSignalsPUSCH.grouphop[Ns+(subframe<<1)];
   uint32_t v=frame_parms->pusch_config_common.ul_ReferenceSignalsPUSCH.seqhop[Ns+(subframe<<1)];
-  int32_t tmp_estimates[N_rb_alloc*12] __attribute__((aligned(16)));
+
 
   int symbol_offset,i;
 
@@ -83,7 +83,19 @@ int32_t lte_ul_channel_estimation(PHY_VARS_eNB *eNB,
   int32x4_t mmtmp0,mmtmp1,mmtmp_re,mmtmp_im;
 #endif
 
-int32_t temp_in_ifft_0[2048*2] __attribute__((aligned(32)));
+  int32_t temp_in_ifft_0[2048*2] __attribute__((aligned(32)));
+
+
+#ifdef Rel14
+  if (eNB->ulsch[UE_id]->ue_type > 0) harq_pid = 0;
+  else
+#endif
+    {
+      harq_pid = subframe2harq_pid(frame_parms,proc->frame_rx,subframe);
+    }
+
+  uint16_t N_rb_alloc = eNB->ulsch[UE_id]->harq_processes[harq_pid]->nb_rb;
+  int32_t tmp_estimates[N_rb_alloc*12] __attribute__((aligned(16)));
 
   Msc_RS = N_rb_alloc*12;
 
diff --git a/openair1/PHY/LTE_REFSIG/lte_dl_mbsfn.c b/openair1/PHY/LTE_REFSIG/lte_dl_mbsfn.c
index 54f52ef40b9d3990abbf044d48aed421cdb31f78..b0af8f6b0b0489de8b91a6bccf350e9aa7148079 100644
--- a/openair1/PHY/LTE_REFSIG/lte_dl_mbsfn.c
+++ b/openair1/PHY/LTE_REFSIG/lte_dl_mbsfn.c
@@ -35,30 +35,22 @@
 int lte_dl_mbsfn(PHY_VARS_eNB *eNB, int32_t *output,
                  short amp,
                  int subframe,
-                 unsigned char l)
-{
-
+                 unsigned char l) {
   unsigned int mprime,mprime_dword,mprime_qpsk_symb,m;
   unsigned short k=0,a;
   int32_t qpsk[4];
-
   a = (amp*ONE_OVER_SQRT2_Q15)>>15;
   ((short *)&qpsk[0])[0] = a;
   ((short *)&qpsk[0])[1] = a;
-
   ((short *)&qpsk[1])[0] = -a;
   ((short *)&qpsk[1])[1] = a;
   ((short *)&qpsk[2])[0] = a;
   ((short *)&qpsk[2])[1] = -a;
-
   ((short *)&qpsk[3])[0] = -a;
   ((short *)&qpsk[3])[1] = -a;
-
-
   mprime = 3*(110 - eNB->frame_parms.N_RB_DL);
 
   for (m=0; m<eNB->frame_parms.N_RB_DL*6; m++) {
-
     if ((l==0) || (l==2))
       k = m<<1;
     else if (l==1)
@@ -69,7 +61,6 @@ int lte_dl_mbsfn(PHY_VARS_eNB *eNB, int32_t *output,
     }
 
     k+=eNB->frame_parms.first_carrier_offset;
-
     mprime_dword     = mprime>>4;
     mprime_qpsk_symb = mprime&0xf;
 
@@ -80,22 +71,18 @@ int lte_dl_mbsfn(PHY_VARS_eNB *eNB, int32_t *output,
 
     output[k] = qpsk[(eNB->lte_gold_mbsfn_table[subframe][l][mprime_dword]>>(2*mprime_qpsk_symb))&3];
     //output[k] = (lte_gold_table[eNB_offset][subframe][l][mprime_dword]>>(2*mprime_qpsk_symb))&3;
-
-
 #ifdef DEBUG_DL_MBSFN
     LOG_D(PHY,"subframe %d, l %d, m %d, mprime %d, mprime_dword %d, mprime_qpsk_symbol %d\n",
-        subframe,l,m,mprime,mprime_dword,mprime_qpsk_symb);
+          subframe,l,m,mprime,mprime_dword,mprime_qpsk_symb);
     LOG_D(PHY,"index = %d (k %d)(%x)\n",(eNB->lte_gold_mbsfn_table[subframe][l][mprime_dword]>>(2*mprime_qpsk_symb))&3,k,eNB->lte_gold_mbsfn_table[subframe][l][mprime_dword]);
 #endif
     mprime++;
-
 #ifdef DEBUG_DL_MBSFN
 
     if (m<18)
       printf("subframe %d, l %d output[%d] = (%d,%d)\n",subframe,l,k,((short *)&output[k])[0],((short *)&output[k])[1]);
 
 #endif
-
   }
 
   return(0);
@@ -106,15 +93,11 @@ int lte_dl_mbsfn(PHY_VARS_eNB *eNB, int32_t *output,
 int lte_dl_mbsfn_rx(PHY_VARS_UE *ue,
                     int *output,
                     int subframe,
-                    unsigned char l)
-{
-
+                    unsigned char l) {
   unsigned int mprime,mprime_dword,mprime_qpsk_symb,m;
   unsigned short k=0;
   unsigned int qpsk[4];
-
   // This includes complex conjugate for channel estimation
-
   ((short *)&qpsk[0])[0] = ONE_OVER_SQRT2_Q15;
   ((short *)&qpsk[0])[1] = -ONE_OVER_SQRT2_Q15;
   ((short *)&qpsk[1])[0] = -ONE_OVER_SQRT2_Q15;
@@ -123,23 +106,18 @@ int lte_dl_mbsfn_rx(PHY_VARS_UE *ue,
   ((short *)&qpsk[2])[1] = ONE_OVER_SQRT2_Q15;
   ((short *)&qpsk[3])[0] = -ONE_OVER_SQRT2_Q15;
   ((short *)&qpsk[3])[1] = ONE_OVER_SQRT2_Q15;
-
   mprime = 3*(110 - ue->frame_parms.N_RB_DL);
 
   for (m=0; m<ue->frame_parms.N_RB_DL*6; m++) {
-
     mprime_dword     = mprime>>4;
     mprime_qpsk_symb = mprime&0xf;
-
     // this is r_mprime from 3GPP 36-211 6.10.1.2
     output[k] = qpsk[(ue->lte_gold_mbsfn_table[subframe][l][mprime_dword]>>(2*mprime_qpsk_symb))&3];
-
 #ifdef DEBUG_DL_MBSFN
-    printf("subframe %d, l %d, m %d, mprime %d, mprime_dword %d, mprime_qpsk_symbol %d\n",
+    printf("subframe %d, l %d, m %u, mprime %u, mprime_dword %u, mprime_qpsk_symbol %u\n",
            subframe,l,m,mprime, mprime_dword,mprime_qpsk_symb);
     printf("index = %d (k %d) (%x)\n",(ue->lte_gold_mbsfn_table[subframe][l][mprime_dword]>>(2*mprime_qpsk_symb))&3,k,ue->lte_gold_mbsfn_table[subframe][l][mprime_dword]);
 #endif
-
     mprime++;
 #ifdef DEBUG_DL_MBSFN
 
@@ -148,7 +126,6 @@ int lte_dl_mbsfn_rx(PHY_VARS_UE *ue,
 
 #endif
     k++;
-
   }
 
   return(0);
diff --git a/openair1/PHY/LTE_REFSIG/lte_ul_ref.c b/openair1/PHY/LTE_REFSIG/lte_ul_ref.c
index ee7619c23c2bf9479b81a9d8e7b221a2e052e9a2..be090214f8475d28d6a81269c66860205856312d 100644
--- a/openair1/PHY/LTE_REFSIG/lte_ul_ref.c
+++ b/openair1/PHY/LTE_REFSIG/lte_ul_ref.c
@@ -20,9 +20,9 @@
  */
 
 #ifdef MAIN
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
+  #include <stdio.h>
+  #include <stdlib.h>
+  #include <math.h>
 #endif
 #include "lte_refsig.h"
 #include "PHY/defs_eNB.h"
@@ -43,8 +43,7 @@ char ref24[720] = {
   -1,3,1,-3,3,-1,1,3,-3,3,1,3,-3,3,1,1,-1,1,3,-3,3,-3,-1,-3,-3,3,-3,-3,-3,1,-3,-3,3,-1,1,1,1,3,1,-1,3,-3,-3,1,3,1,1,-3,3,-1,3,3,1,1,-3,3,3,3,3,1,-1,3,-1,1,1,-1,-3,-1,-1,1,3,3,-1,-3,1,1,3,-3,1,1,-3,-1,-1,1,3,1,3,1,-1,3,1,1,-3,-1,-3,-1,-1,-1,-1,-3,-3,-1,1,1,3,3,-1,3,-1,1,-1,-3,1,-1,-3,-3,1,-3,-1,-1,-3,1,1,3,-1,1,3,1,-3,1,-3,1,1,-1,-1,3,-1,-3,3,-3,-3,-3,1,1,1,1,-1,-1,3,-3,-3,3,-3,1,-1,-1,1,-1,1,1,-1,-3,-1,1,-1,3,-1,-3,-3,3,3,-1,-1,-3,-1,3,1,3,1,3,1,1,-1,3,1,-1,1,3,-3,-1,-1,1,-3,1,3,-3,1,-1,-3,3,-3,3,-1,-1,-1,-1,1,-3,-3,-3,1,-3,-3,-3,1,-3,1,1,-3,3,3,-1,-3,-1,3,-3,3,3,3,-1,1,1,-3,1,-1,1,1,-3,1,1,-1,1,-3,-3,3,-1,3,-1,-1,-3,-3,-3,-1,-3,-3,1,-1,1,3,3,-1,1,-1,3,1,3,3,-3,-3,1,3,1,-1,-3,-3,-3,3,3,-3,3,3,-1,-3,3,-1,1,-3,1,1,3,3,1,1,1,-1,-1,1,-3,3,-1,1,1,-3,3,3,-1,-3,3,-3,-1,-3,-1,3,-1,-1,-1,-1,-3,-1,3,3,1,-1,1,3,3,3,-1,1,1,-3,1,3,-1,-3,3,-3,-3,3,1,3,1,-3,3,1,3,1,1,3,3,-1,-1,-3,1,-3,-1,3,1,1,3,-1,-1,1,-3,1,3,-3,1,-1,-3,-1,3,1,3,1,-1,-3,-3,-1,-1,-3,-3,-3,-1,-1,-3,3,-1,-1,-1,-1,1,1,-3,3,1,3,3,1,-1,1,-3,1,-3,1,1,-3,-1,1,3,-1,3,3,-1,-3,1,-1,-3,3,3,3,-1,1,1,3,-1,-3,-1,3,-1,-1,-1,1,1,1,1,1,-1,3,-1,-3,1,1,3,-3,1,-3,-1,1,1,-3,-3,3,1,1,-3,1,3,3,1,-1,-3,3,-1,3,3,3,-3,1,-1,1,-1,-3,-1,1,3,-1,3,-3,-3,-1,-3,3,-3,-3,-3,-1,-1,-3,-1,-3,3,1,3,-3,-1,3,-1,1,-1,3,-3,1,-1,-3,-3,1,1,-1,1,-1,1,-1,3,1,-3,-1,1,-1,1,-1,-1,3,3,-3,-1,1,-3,-3,-1,-3,3,1,-1,-3,-1,-3,-3,3,-3,3,-3,-1,1,3,1,-3,1,3,3,-1,-3,-1,-1,-1,-1,3,3,3,1,3,3,-3,1,3,-1,3,-1,3,3,-3,3,1,-1,3,3,1,-1,3,3,-1,-3,3,-3,-1,-1,3,-1,3,-1,-1,1,1,1,1,-1,-1,-3,-1,3,1,-1,1,-1,3,-1,3,1,1,-1,-1,-3,1,1,-3,1,3,-3,1,1,-3,-3,-1,-1,-3,-1,1,3,1,1,-3,-1,-1,-3,3,-3,3,1,-3,3,-3,1,-1,1,-3,1,1,1,-1,-3,3,3,1,1,3,-1,-3,-1,-1,-1,3,1,-3,-3,-1,3,-3,-1,-3,-1,-3,-1,-1,-3,-1,-1,1,-3,-1,-1,1,-1,-3,1,1,-3,1,-3,-3,3,1,1,-1,3,-1,-1,1,1,-1,-1,-3,-1,3,-1,3,-1,1,3,1,-1,3,1,3,-3,-3,1,-1,-1,1,3
 };
 
-void generate_ul_ref_sigs(void)
-{
+void generate_ul_ref_sigs(void) {
   double qbar,phase;
   unsigned int u,v,Msc_RS,q,m,n;
 
@@ -53,7 +52,7 @@ void generate_ul_ref_sigs(void)
     for (u=0; u<30; u++) {
       for (v=0; v<2; v++) {
         qbar = ref_primes[Msc_RS] * (u+1)/(double)31;
-        ul_ref_sigs[u][v][Msc_RS] = (int16_t*)malloc16(2*sizeof(int16_t)*dftsizes[Msc_RS]);
+        ul_ref_sigs[u][v][Msc_RS] = (int16_t *)malloc16(2*sizeof(int16_t)*dftsizes[Msc_RS]);
 
         if ((((int)floor(2*qbar))&1) == 0)
           q = (int)(floor(qbar+.5)) - v;
@@ -61,7 +60,7 @@ void generate_ul_ref_sigs(void)
           q = (int)(floor(qbar+.5)) + v;
 
 #ifdef MAIN
-        printf("Msc_RS %d (%d), u %d, v %d -> q %d (qbar %f)\n",Msc_RS,dftsizes[Msc_RS],u,v,q,qbar);
+        printf("Msc_RS %u (%d), u %u, v %u -> q %u (qbar %f)\n",Msc_RS,dftsizes[Msc_RS],u,v,q,qbar);
 #endif
 
         for (n=0; n<dftsizes[Msc_RS]; n++) {
@@ -89,32 +88,26 @@ void generate_ul_ref_sigs(void)
 
   // These are the sequences for RB 1
   for (u=0; u<30; u++) {
-    ul_ref_sigs[u][0][0] = (int16_t*)malloc16(2*sizeof(int16_t)*dftsizes[0]);
+    ul_ref_sigs[u][0][0] = (int16_t *)malloc16(2*sizeof(int16_t)*dftsizes[0]);
 
     for (n=0; n<dftsizes[0]; n++) {
       ul_ref_sigs[u][0][0][n<<1]    =(int16_t)(floor(32767*cos(M_PI*ref12[(u*12) + n]/4)));
       ul_ref_sigs[u][0][0][1+(n<<1)]=(int16_t)(floor(32767*sin(M_PI*ref12[(u*12) + n]/4)));
     }
-
   }
 
   // These are the sequences for RB 2
   for (u=0; u<30; u++) {
-    ul_ref_sigs[u][0][1] = (int16_t*)malloc16(2*sizeof(int16_t)*dftsizes[1]);
+    ul_ref_sigs[u][0][1] = (int16_t *)malloc16(2*sizeof(int16_t)*dftsizes[1]);
 
     for (n=0; n<dftsizes[1]; n++) {
       ul_ref_sigs[u][0][1][n<<1]    =(int16_t)(floor(32767*cos(M_PI*ref24[(u*24) + n]/4)));
       ul_ref_sigs[u][0][1][1+(n<<1)]=(int16_t)(floor(32767*sin(M_PI*ref24[(u*24) + n]/4)));
     }
-
-
-
   }
-
 }
 
-void generate_ul_ref_sigs_rx(void)
-{
+void generate_ul_ref_sigs_rx(void) {
   double qbar,phase;
   unsigned int u,v,Msc_RS,q,m,n;
 
@@ -123,7 +116,7 @@ void generate_ul_ref_sigs_rx(void)
     for (u=0; u<30; u++) {
       for (v=0; v<2; v++) {
         qbar = ref_primes[Msc_RS] * (u+1)/(double)31;
-        ul_ref_sigs_rx[u][v][Msc_RS] = (int16_t*)malloc16(2*sizeof(int16_t)*dftsizes[Msc_RS]);
+        ul_ref_sigs_rx[u][v][Msc_RS] = (int16_t *)malloc16(2*sizeof(int16_t)*dftsizes[Msc_RS]);
 
         if ((((int)floor(2*qbar))&1) == 0)
           q = (int)(floor(qbar+.5)) - v;
@@ -131,7 +124,7 @@ void generate_ul_ref_sigs_rx(void)
           q = (int)(floor(qbar+.5)) + v;
 
 #ifdef MAIN
-        printf("Msc_RS %d (%d), u %d, v %d -> q %d (qbar %f)\n",Msc_RS,dftsizes[Msc_RS],u,v,q,qbar);
+        printf("Msc_RS %u (%d), u %u, v %u -> q %u (qbar %f)\n",Msc_RS,dftsizes[Msc_RS],u,v,q,qbar);
 #endif
 
         for (n=0; n<dftsizes[Msc_RS]; n++) {
@@ -159,7 +152,7 @@ void generate_ul_ref_sigs_rx(void)
 
   // These are the sequences for RB 1
   for (u=0; u<30; u++) {
-    ul_ref_sigs_rx[u][0][0] = (int16_t*)malloc16(2*sizeof(int16_t)*dftsizes[0]);
+    ul_ref_sigs_rx[u][0][0] = (int16_t *)malloc16(2*sizeof(int16_t)*dftsizes[0]);
 
     for (n=0; n<dftsizes[0]; n++) {
       ul_ref_sigs_rx[u][0][0][n<<1]    = (int16_t)(floor(32767*cos(M_PI*ref12[(u*12) + n]/4)));
@@ -169,21 +162,17 @@ void generate_ul_ref_sigs_rx(void)
 
   // These are the sequences for RB 2
   for (u=0; u<30; u++) {
-    ul_ref_sigs_rx[u][0][1] = (int16_t*)malloc16(2*sizeof(int16_t)*dftsizes[1]);
+    ul_ref_sigs_rx[u][0][1] = (int16_t *)malloc16(2*sizeof(int16_t)*dftsizes[1]);
 
     for (n=0; n<dftsizes[1]; n++) {
       ul_ref_sigs_rx[u][0][1][n<<1]    = (int16_t)(floor(32767*cos(M_PI*ref24[(u*24) + n]/4)));
       ul_ref_sigs_rx[u][0][1][1+(n<<1)]= (int16_t)(floor(32767*sin(M_PI*ref24[(u*24) + n]/4)));
     }
-
   }
-
 }
 
 
-void free_ul_ref_sigs(void)
-{
-
+void free_ul_ref_sigs(void) {
   unsigned int u,v,Msc_RS;
 
   for (Msc_RS=0; Msc_RS<34; Msc_RS++) {
@@ -204,9 +193,7 @@ void free_ul_ref_sigs(void)
 }
 
 #ifdef MAIN
-main()
-{
-
+main() {
   generate_ul_ref_sigs();
   generate_ul_ref_sigs_rx();
   free_ul_ref_sigs();
diff --git a/openair1/PHY/LTE_TRANSPORT/dci.c b/openair1/PHY/LTE_TRANSPORT/dci.c
old mode 100755
new mode 100644
index 520488664d26289952564d1c1a75b15fbc8c01a0..6b5863edc96e0acbb620272b0e583f9b2ae0f231
--- a/openair1/PHY/LTE_TRANSPORT/dci.c
+++ b/openair1/PHY/LTE_TRANSPORT/dci.c
@@ -98,43 +98,25 @@ void dci_encoding(uint8_t *a,
 #endif
   RCC = sub_block_interleaving_cc(D,d+96,w);
 
-#ifdef DEBUG_DCI_ENCODING
-  printf("Doing DCI rate matching for %d channel bits, RCC %d, e %p\n",E,RCC,e);
-#endif
+  //#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
   lte_rate_matching_cc(RCC,E,w,e);
 
 
+
 }
 
 
 uint8_t *generate_dci0(uint8_t *dci,
                        uint8_t *e,
                        uint8_t DCI_LENGTH,
-                       uint8_t aggregation_level,
+		       uint16_t coded_bits,
                        uint16_t rnti)
 {
 
-  uint16_t coded_bits;
   uint8_t dci_flip[8];
 
-  AssertFatal((aggregation_level==1) ||
-	      (aggregation_level==2) ||
-	      (aggregation_level==4) ||
-	      (aggregation_level==8)
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0)) // Added for EPDCCH/MPDCCH
-	      ||
-	      (aggregation_level==16) ||
-	      (aggregation_level==24) ||
-	      (aggregation_level==32)
-#endif
-	      ,
-	      "generate_dci FATAL, illegal aggregation_level %d\n",aggregation_level);
-
-
-  coded_bits = 72 * aggregation_level;
-
-
-
   #ifdef DEBUG_DCI_ENCODING
   for (int i=0;i<1+((DCI_LENGTH+16)/8);i++)
     printf("i %d : %x\n",i,dci[i]);
@@ -387,7 +369,7 @@ uint8_t generate_dci_top(uint8_t num_pdcch_symbols,
           e_ptr = generate_dci0(dci_alloc[i].dci_pdu,
                                 e+(72*dci_alloc[i].firstCCE),
                                 dci_alloc[i].dci_length,
-                                dci_alloc[i].L,
+                                72*dci_alloc[i].L,
                                 dci_alloc[i].rnti);
         }
       }
diff --git a/openair1/PHY/LTE_TRANSPORT/dci_tools.c b/openair1/PHY/LTE_TRANSPORT/dci_tools.c
index c33d9efe63b35dba960f5c9412fac2e607bd2d4e..02bacf855203eeb0e50f87b6b7ad28b829a928c9 100644
--- a/openair1/PHY/LTE_TRANSPORT/dci_tools.c
+++ b/openair1/PHY/LTE_TRANSPORT/dci_tools.c
@@ -42,12 +42,17 @@
 //#define DEBUG_HARQ
 
 
+
+
 #include "LAYER2/MAC/mac.h"
 
 //#define DEBUG_DCI
 #include "dci_tools_common_extern.h"
 #include "transport_proto.h"
 
+//#undef LOG_D
+//#define LOG_D(A,B...) printf(B)
+
 int16_t find_dlsch(uint16_t rnti, PHY_VARS_eNB *eNB,find_type_t type)
 {
   uint16_t i;
@@ -62,12 +67,14 @@ int16_t find_dlsch(uint16_t rnti, PHY_VARS_eNB *eNB,find_type_t type)
         (eNB->dlsch[i][0]->rnti==rnti))       return i;
     else if ((eNB->dlsch[i][0]->harq_mask == 0) && (first_free_index==-1)) first_free_index=i;
   }
-  if (type == SEARCH_EXIST) return -1;
+  if (type == SEARCH_EXIST)
+    return -1;
   if (first_free_index != -1)
     eNB->dlsch[first_free_index][0]->rnti = 0;
   return first_free_index;
 }
 
+
 int16_t find_ulsch(uint16_t rnti, PHY_VARS_eNB *eNB,find_type_t type)
 {
   uint16_t i;
@@ -80,7 +87,8 @@ int16_t find_ulsch(uint16_t rnti, PHY_VARS_eNB *eNB,find_type_t type)
         (eNB->ulsch[i]->rnti==rnti))       return i;
     else if ((eNB->ulsch[i]->harq_mask == 0) && (first_free_index==-1)) first_free_index=i;
   }
-  if (type == SEARCH_EXIST) return -1;
+  if (type == SEARCH_EXIST)
+    return -1;
   if (first_free_index != -1)
     eNB->ulsch[first_free_index]->rnti = 0;
   return first_free_index;
@@ -90,25 +98,25 @@ int16_t find_ulsch(uint16_t rnti, PHY_VARS_eNB *eNB,find_type_t type)
 
 
 
-void fill_pdcch_order(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,DCI_ALLOC_t *dci_alloc,nfapi_dl_config_dci_dl_pdu *pdu)
+void fill_pdcch_order(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc,DCI_ALLOC_t *dci_alloc,nfapi_dl_config_dci_dl_pdu *pdu)
 {
-  LTE_DL_FRAME_PARMS                *fp      = &eNB->frame_parms;
-  uint8_t                           *dci_pdu = &dci_alloc->dci_pdu[0];
-  nfapi_dl_config_dci_dl_pdu_rel8_t *rel8    = &pdu->dci_dl_pdu_rel8;
+  LTE_DL_FRAME_PARMS *fp = &eNB->frame_parms;
+  uint8_t        *dci_pdu = &dci_alloc->dci_pdu[0];
+  nfapi_dl_config_dci_dl_pdu_rel8_t *rel8 = &pdu->dci_dl_pdu_rel8;
 
   dci_alloc->firstCCE = rel8->cce_idx;
-  dci_alloc->L        = rel8->aggregation_level;
-  dci_alloc->rnti     = rel8->rnti;
+  dci_alloc->L = rel8->aggregation_level;
+  dci_alloc->rnti = rel8->rnti;
   dci_alloc->harq_pid = rel8->harq_process;
-  dci_alloc->ra_flag  = 0;
-  dci_alloc->format   = format1A;
+  dci_alloc->ra_flag = 0;
+  dci_alloc->format = format1A;
 
-  LOG_D(PHY,"NFAPI: DCI format %d, nCCE %d, L %d, rnti %x,harq_pid %d\n",
-        rel8->dci_format,rel8->cce_idx,rel8->aggregation_level,rel8->rnti,rel8->harq_process);
+  LOG_D (PHY, "NFAPI: DCI format %d, nCCE %d, L %d, rnti %x,harq_pid %d\n", rel8->dci_format, rel8->cce_idx, rel8->aggregation_level, rel8->rnti, rel8->harq_process);
 
   switch (fp->N_RB_DL) {
   case 6:
     if (fp->frame_type == TDD) {
+
       dci_alloc->dci_length                         = sizeof_DCI1A_1_5MHz_TDD_1_6_t;
       ((DCI1A_1_5MHz_TDD_1_6_t *)dci_pdu)->type     = 1;
       ((DCI1A_1_5MHz_TDD_1_6_t *)dci_pdu)->vrb_type = rel8->virtual_resource_block_assignment_flag;
@@ -131,11 +139,13 @@ void fill_pdcch_order(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,DCI_ALLOC_t *dci_a
       ((DCI1A_1_5MHz_FDD_t *)dci_pdu)->TPC          = rel8->tpc;
       ((DCI1A_1_5MHz_FDD_t *)dci_pdu)->harq_pid     = rel8->harq_process;
       ((DCI1A_1_5MHz_FDD_t *)dci_pdu)->padding      = 0;
+
       //      printf("FDD 1A: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
     }
     break;
   case 25:
     if (fp->frame_type == TDD) {
+
       dci_alloc->dci_length                         = sizeof_DCI1A_5MHz_TDD_1_6_t;
       ((DCI1A_5MHz_TDD_1_6_t *)dci_pdu)->type       = 1;
       ((DCI1A_5MHz_TDD_1_6_t *)dci_pdu)->vrb_type   = rel8->virtual_resource_block_assignment_flag;
@@ -164,6 +174,7 @@ void fill_pdcch_order(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,DCI_ALLOC_t *dci_a
     break;
   case 50:
     if (fp->frame_type == TDD) {
+
       dci_alloc->dci_length                         = sizeof_DCI1A_10MHz_TDD_1_6_t;
       ((DCI1A_10MHz_TDD_1_6_t *)dci_pdu)->type      = 1;
       ((DCI1A_10MHz_TDD_1_6_t *)dci_pdu)->vrb_type  = rel8->virtual_resource_block_assignment_flag;
@@ -187,11 +198,13 @@ void fill_pdcch_order(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,DCI_ALLOC_t *dci_a
       ((DCI1A_10MHz_FDD_t *)dci_pdu)->TPC           = rel8->tpc;
       ((DCI1A_10MHz_FDD_t *)dci_pdu)->harq_pid      = rel8->harq_process;
       ((DCI1A_10MHz_FDD_t *)dci_pdu)->padding       = 0;
+
       //      printf("FDD 1A: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
     }
     break;
   case 100:
     if (fp->frame_type == TDD) {
+
       dci_alloc->dci_length                         = sizeof_DCI1A_20MHz_TDD_1_6_t;
       ((DCI1A_20MHz_TDD_1_6_t *)dci_pdu)->type      = 1;
       ((DCI1A_20MHz_TDD_1_6_t *)dci_pdu)->vrb_type  = rel8->virtual_resource_block_assignment_flag;
@@ -220,30 +233,41 @@ void fill_pdcch_order(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,DCI_ALLOC_t *dci_a
     break;
   }
 
+
   LOG_T(PHY,"%d.%d: DCI 1A: rnti %x, PDCCH order to do PRACH\n",
         proc->frame_tx, proc->subframe_tx, rel8->rnti);
 }
 
-void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t *proc,DCI_ALLOC_t *dci_alloc,nfapi_dl_config_dci_dl_pdu *pdu)
+void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,L1_rxtx_proc_t *proc,DCI_ALLOC_t *dci_alloc,nfapi_dl_config_dci_dl_pdu *pdu)
 {
   LTE_DL_FRAME_PARMS *fp = &eNB->frame_parms;
-  uint8_t *dci_pdu = &dci_alloc->dci_pdu[0];
+  uint8_t        *dci_pdu = &dci_alloc->dci_pdu[0];
   nfapi_dl_config_dci_dl_pdu_rel8_t *rel8 = &pdu->dci_dl_pdu_rel8;
 
   /* check if this is a DCI 1A PDCCH order for RAPROC */
   if (rel8->dci_format == NFAPI_DL_DCI_FORMAT_1A && rel8->rnti_type == 1) {
-    int full_rb;
+    int             full_rb;
     switch (fp->N_RB_DL) {
-    case 6:   full_rb = 63;   break;
-    case 25:  full_rb = 511;  break;
-    case 50:  full_rb = 2047; break;
-    case 100: full_rb = 8191; break;
-    default:  abort();
+    case 6:
+      full_rb = 63;
+      break;
+    case 25:
+      full_rb = 511;
+      break;
+    case 50:
+      full_rb = 2047;
+      break;
+    case 100:
+      full_rb = 8191;
+      break;
+    default:
+      abort ();
     }
     if (rel8->resource_block_coding == full_rb)
-      return fill_pdcch_order(eNB, proc, dci_alloc, pdu);
+      return fill_pdcch_order (eNB, proc, dci_alloc, pdu);
   }
 
+
   LTE_eNB_DLSCH_t *dlsch0=NULL,*dlsch1=NULL;
   LTE_DL_eNB_HARQ_t *dlsch0_harq=NULL,*dlsch1_harq=NULL;
   int beamforming_mode = 0;
@@ -254,11 +278,13 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
   uint16_t DL_pmi_single=0; // This should be taken from DLSCH parameters for PUSCH precoding
   uint8_t I_mcs = 0;
  
+
   dci_alloc->firstCCE = rel8->cce_idx;
-  dci_alloc->L        = rel8->aggregation_level;
-  dci_alloc->rnti     = rel8->rnti;
+  dci_alloc->L = rel8->aggregation_level;
+  dci_alloc->rnti = rel8->rnti;
   dci_alloc->harq_pid = rel8->harq_process;
-  dci_alloc->ra_flag  = 0;
+  dci_alloc->ra_flag = 0;
+
 
   LOG_D(PHY,"NFAPI: SFN/SF:%04d%d proc:TX:[SFN/SF:%04d%d] DCI format %d, nCCE %d, L %d, rnti %x, harq_pid %d\n",
 	frame,subframe,proc->frame_tx,proc->subframe_tx,rel8->dci_format,rel8->cce_idx,rel8->aggregation_level,rel8->rnti,rel8->harq_process);
@@ -293,15 +319,15 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
     dlsch0_harq->round=0;
     dlsch0->harq_mask=0;
   }
-  if ((dlsch0->harq_mask & (1<<rel8->harq_process)) > 0 ) {
+  if ((dlsch0->harq_mask & (1 << rel8->harq_process)) > 0) {
     if (rel8->new_data_indicator_1 != dlsch0_harq->ndi)
-      dlsch0_harq->round=0;
-  }
-  else  { // process is inactive, so activate and set round to 0
-    dlsch0_harq->round=0;
+      dlsch0_harq->round = 0;
+  } else {                      // process is inactive, so activate and set round to 0
+    dlsch0_harq->round = 0;
   }
   dlsch0_harq->ndi = rel8->new_data_indicator_1;
 
+
 #ifdef PHY_TX_THREAD
   dlsch0->active[subframe]        = 1;
 #else
@@ -320,16 +346,16 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
 
   case NFAPI_DL_DCI_FORMAT_1A:
 
-      AssertFatal(rel8->resource_block_coding < 8192, "SFN/SF:%04d%d proc:TX:SFN/SF:%04d%d: rel8->resource_block_coding (%p) %u >= 8192 (rnti %x, rnti_type %d, format %d, harq_id %d\n",
+    AssertFatal(rel8->resource_block_coding < 8192, "SFN/SF:%04d%d proc:TX:SFN/SF:%04d%d: rel8->resource_block_coding (%p) %u >= 8192 (rnti %x, rnti_type %d, format %d, harq_id %d\n",
                 frame,subframe,proc->frame_tx,subframe,
                 &rel8->resource_block_coding,rel8->resource_block_coding,rel8->rnti,rel8->rnti_type,rel8->dci_format,rel8->harq_process);
   
-
-    dci_alloc->format     = format1A;
+    dci_alloc->format = format1A;
 
     switch (fp->N_RB_DL) {
     case 6:
       if (fp->frame_type == TDD) {
+
 	dci_alloc->dci_length                         = sizeof_DCI1A_1_5MHz_TDD_1_6_t; 
         ((DCI1A_1_5MHz_TDD_1_6_t *)dci_pdu)->type     = 1;
         ((DCI1A_1_5MHz_TDD_1_6_t *)dci_pdu)->vrb_type = rel8->virtual_resource_block_assignment_flag;
@@ -353,12 +379,13 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
         ((DCI1A_1_5MHz_FDD_t *)dci_pdu)->TPC          = rel8->tpc;
         ((DCI1A_1_5MHz_FDD_t *)dci_pdu)->harq_pid     = rel8->harq_process;
         ((DCI1A_1_5MHz_FDD_t *)dci_pdu)->padding      = 0;
+
         //      printf("FDD 1A: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
       }
-      AssertFatal(rel8->virtual_resource_block_assignment_flag==LOCALIZED,"Distributed RB allocation not done yet\n");
-      dlsch0_harq->rb_alloc[0]    = localRIV2alloc_LUT6[rel8->resource_block_coding];
-      dlsch0_harq->vrb_type           =  rel8->virtual_resource_block_assignment_flag;
-      dlsch0_harq->nb_rb          = RIV2nb_rb_LUT6[rel8->resource_block_coding];//NPRB;
+      AssertFatal (rel8->virtual_resource_block_assignment_flag == LOCALIZED, "Distributed RB allocation not done yet\n");
+      dlsch0_harq->rb_alloc[0] = localRIV2alloc_LUT6[rel8->resource_block_coding];
+      dlsch0_harq->vrb_type = rel8->virtual_resource_block_assignment_flag;
+      dlsch0_harq->nb_rb = RIV2nb_rb_LUT6[rel8->resource_block_coding]; //NPRB;
       break;
     case 25:
       if (fp->frame_type == TDD) {
@@ -387,13 +414,14 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
         ((DCI1A_5MHz_FDD_t *)dci_pdu)->padding        = 0;
         //      printf("FDD 1A: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
       }
-      AssertFatal(rel8->virtual_resource_block_assignment_flag==LOCALIZED,"Distributed RB allocation not done yet\n");
-      dlsch0_harq->rb_alloc[0]    = localRIV2alloc_LUT25[rel8->resource_block_coding];
-      dlsch0_harq->vrb_type           =  rel8->virtual_resource_block_assignment_flag;
-      dlsch0_harq->nb_rb          = RIV2nb_rb_LUT25[rel8->resource_block_coding];//NPRB;
+      AssertFatal (rel8->virtual_resource_block_assignment_flag == LOCALIZED, "Distributed RB allocation not done yet\n");
+      dlsch0_harq->rb_alloc[0] = localRIV2alloc_LUT25[rel8->resource_block_coding];
+      dlsch0_harq->vrb_type = rel8->virtual_resource_block_assignment_flag;
+      dlsch0_harq->nb_rb = RIV2nb_rb_LUT25[rel8->resource_block_coding];        //NPRB;
       break;
     case 50:
       if (fp->frame_type == TDD) {
+
 	dci_alloc->dci_length                         = sizeof_DCI1A_10MHz_TDD_1_6_t; 
         ((DCI1A_10MHz_TDD_1_6_t *)dci_pdu)->type      = 1;
         ((DCI1A_10MHz_TDD_1_6_t *)dci_pdu)->vrb_type  = rel8->virtual_resource_block_assignment_flag;
@@ -419,14 +447,15 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
         ((DCI1A_10MHz_FDD_t *)dci_pdu)->padding       = 0;
 	//      printf("FDD 1A: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
       }
-      AssertFatal(rel8->virtual_resource_block_assignment_flag==LOCALIZED,"Distributed RB allocation not done yet\n");
-      dlsch0_harq->rb_alloc[0]     = localRIV2alloc_LUT50_0[rel8->resource_block_coding];
-      dlsch0_harq->rb_alloc[1]     = localRIV2alloc_LUT50_1[rel8->resource_block_coding];
-      dlsch0_harq->vrb_type           =  rel8->virtual_resource_block_assignment_flag;
-      dlsch0_harq->nb_rb              = RIV2nb_rb_LUT50[rel8->resource_block_coding];//NPRB;
+      AssertFatal (rel8->virtual_resource_block_assignment_flag == LOCALIZED, "Distributed RB allocation not done yet\n");
+      dlsch0_harq->rb_alloc[0] = localRIV2alloc_LUT50_0[rel8->resource_block_coding];
+      dlsch0_harq->rb_alloc[1] = localRIV2alloc_LUT50_1[rel8->resource_block_coding];
+      dlsch0_harq->vrb_type = rel8->virtual_resource_block_assignment_flag;
+      dlsch0_harq->nb_rb = RIV2nb_rb_LUT50[rel8->resource_block_coding];        //NPRB;
       break;
     case 100:
       if (fp->frame_type == TDD) {
+
 	dci_alloc->dci_length                         = sizeof_DCI1A_20MHz_TDD_1_6_t; 
         ((DCI1A_20MHz_TDD_1_6_t *)dci_pdu)->type      = 1;
         ((DCI1A_20MHz_TDD_1_6_t *)dci_pdu)->vrb_type  = rel8->virtual_resource_block_assignment_flag;
@@ -452,20 +481,21 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
         ((DCI1A_20MHz_FDD_t *)dci_pdu)->padding       = 0;
 	//      printf("FDD 1A: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
       }
-      AssertFatal(rel8->virtual_resource_block_assignment_flag==LOCALIZED,"Distributed RB allocation not done yet\n");
-      dlsch0_harq->rb_alloc[0]      = localRIV2alloc_LUT100_0[rel8->resource_block_coding];
-      dlsch0_harq->rb_alloc[1]      = localRIV2alloc_LUT100_1[rel8->resource_block_coding];
-      dlsch0_harq->rb_alloc[2]      = localRIV2alloc_LUT100_2[rel8->resource_block_coding];
-      dlsch0_harq->rb_alloc[3]      = localRIV2alloc_LUT100_3[rel8->resource_block_coding];
-      dlsch0_harq->vrb_type         =  rel8->virtual_resource_block_assignment_flag;
-      dlsch0_harq->nb_rb            = RIV2nb_rb_LUT100[rel8->resource_block_coding];//NPRB;
+      AssertFatal (rel8->virtual_resource_block_assignment_flag == LOCALIZED, "Distributed RB allocation not done yet\n");
+      dlsch0_harq->rb_alloc[0] = localRIV2alloc_LUT100_0[rel8->resource_block_coding];
+      dlsch0_harq->rb_alloc[1] = localRIV2alloc_LUT100_1[rel8->resource_block_coding];
+      dlsch0_harq->rb_alloc[2] = localRIV2alloc_LUT100_2[rel8->resource_block_coding];
+      dlsch0_harq->rb_alloc[3] = localRIV2alloc_LUT100_3[rel8->resource_block_coding];
+      dlsch0_harq->vrb_type = rel8->virtual_resource_block_assignment_flag;
+      dlsch0_harq->nb_rb = RIV2nb_rb_LUT100[rel8->resource_block_coding];       //NPRB;
       break;
     }
 
-    if (rel8->rnti_type == 2 ) {
+    if (rel8->rnti_type == 2) {
       // see 36-212 V8.6.0 p. 45
-      NPRB      = (rel8->tpc&1)+2;
+      NPRB = (rel8->tpc & 1) + 2;
       // 36-213 sec.7.1.7.2 p.26
+
       I_mcs     = rel8->mcs_1;
     }
     else {
@@ -491,10 +521,11 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
 #endif
     dlsch0->rnti                 = rel8->rnti;
     //dlsch0->harq_ids[subframe]   = rel8->harq_process;
+
     if (dlsch0_harq->round == 0)
       dlsch0_harq->status = ACTIVE;
 
-    dlsch0->harq_mask            |= (1<<rel8->harq_process);
+    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);
 
@@ -513,6 +544,7 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
     switch (fp->N_RB_DL) {
     case 6:
       if (fp->frame_type == TDD) {
+
 	dci_alloc->dci_length                     = sizeof_DCI1_1_5MHz_TDD_t; 
         ((DCI1_1_5MHz_TDD_t *)dci_pdu)->rah       = rel8->resource_allocation_type;
         ((DCI1_1_5MHz_TDD_t *)dci_pdu)->mcs       = rel8->mcs_1;
@@ -539,6 +571,7 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
       break;
     case 25:
       if (fp->frame_type == TDD) {
+
 	dci_alloc->dci_length                      = sizeof_DCI1_5MHz_TDD_t; 
         ((DCI1_5MHz_TDD_t *)dci_pdu)->rah      = rel8->resource_allocation_type;
         ((DCI1_5MHz_TDD_t *)dci_pdu)->mcs      = rel8->mcs_1;
@@ -565,6 +598,7 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
       break;
     case 50:
       if (fp->frame_type == TDD) {
+
 	dci_alloc->dci_length                       = sizeof_DCI1_10MHz_TDD_t; 
         ((DCI1_10MHz_TDD_t *)dci_pdu)->rah      = rel8->resource_allocation_type;
         ((DCI1_10MHz_TDD_t *)dci_pdu)->mcs      = rel8->mcs_1;
@@ -590,6 +624,7 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
       break;
     case 100:
       if (fp->frame_type == TDD) {
+
 	dci_alloc->dci_length                       = sizeof_DCI1_20MHz_TDD_t; 
         ((DCI1_20MHz_TDD_t *)dci_pdu)->rah      = rel8->resource_allocation_type;
         ((DCI1_20MHz_TDD_t *)dci_pdu)->mcs      = rel8->mcs_1;
@@ -615,39 +650,34 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
       break;
     }
 
-    AssertFatal(rel8->harq_process<8,"Format 1: harq_pid=%d >= 8\n", rel8->harq_process);
+    AssertFatal (rel8->harq_process < 8, "Format 1: harq_pid=%d >= 8\n", rel8->harq_process);
 
 
     dlsch0_harq = dlsch0->harq_processes[rel8->harq_process];
-    dlsch0_harq->codeword=0;
+    dlsch0_harq->codeword = 0;
 
     // printf("DCI: Setting subframe_tx for subframe %d\n",subframe);
     dlsch0->subframe_tx[subframe] = 1;
 
-    conv_rballoc(rel8->resource_allocation_type,
-                 rel8->resource_block_coding,
-		 fp->N_RB_DL,
-                 dlsch0_harq->rb_alloc);
+    conv_rballoc (rel8->resource_allocation_type, rel8->resource_block_coding, fp->N_RB_DL, dlsch0_harq->rb_alloc);
 
-    dlsch0_harq->nb_rb = conv_nprb(rel8->resource_allocation_type,
-                                   rel8->resource_block_coding,
-                                   fp->N_RB_DL);
+    dlsch0_harq->nb_rb = conv_nprb (rel8->resource_allocation_type, rel8->resource_block_coding, fp->N_RB_DL);
 
-    NPRB      = dlsch0_harq->nb_rb;
+    NPRB = dlsch0_harq->nb_rb;
 
 
-    AssertFatal(NPRB>0,"NPRB == 0\n");
+    AssertFatal (NPRB > 0, "NPRB == 0\n");
 
-    dlsch0_harq->rvidx       = rel8->redundancy_version_1;
+    dlsch0_harq->rvidx = rel8->redundancy_version_1;
 
-    dlsch0_harq->Nl          = 1;
+    dlsch0_harq->Nl = 1;
     //    dlsch[0]->layer_index = 0;
     if (beamforming_mode == 0)
       dlsch0_harq->mimo_mode = (fp->nb_antenna_ports_eNB == 1) ? SISO : ALAMOUTI;
     else if (beamforming_mode == 7)
       dlsch0_harq->mimo_mode = TM7;
     else
-      LOG_E(PHY,"Invalid beamforming mode %dL\n", beamforming_mode);
+      LOG_E (PHY, "Invalid beamforming mode %dL\n", beamforming_mode);
 
     dlsch0_harq->dl_power_off = 1;
 
@@ -664,16 +694,17 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
 
       //            printf("Setting DLSCH process %d to ACTIVE\n",rel8->harq_process);
       // MCS and TBS don't change across HARQ rounds
-      dlsch0_harq->mcs         = rel8->mcs_1;
-      dlsch0_harq->Qm          = get_Qm(rel8->mcs_1);
-      dlsch0_harq->TBS         = TBStable[get_I_TBS(dlsch0_harq->mcs)][NPRB-1];
+      dlsch0_harq->mcs = rel8->mcs_1;
+      dlsch0_harq->Qm = get_Qm (rel8->mcs_1);
+      dlsch0_harq->TBS = TBStable[get_I_TBS (dlsch0_harq->mcs)][NPRB - 1];
 
     }
 
+
     LOG_D(PHY,"DCI: Set harq_ids[%d] to %d (%p)\n",subframe,rel8->harq_process,dlsch0);
     dlsch0->harq_ids[frame%2][subframe] = rel8->harq_process;
 
-    dlsch0->harq_mask          |= (1<<rel8->harq_process);
+    dlsch0->harq_mask |= (1 << rel8->harq_process);
 
 
     dlsch0->rnti = rel8->rnti;
@@ -682,7 +713,7 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
     break;
   case NFAPI_DL_DCI_FORMAT_2A:
 
-    dci_alloc->format     = format2A;
+    dci_alloc->format = format2A;
     switch (fp->N_RB_DL) {
     case 6:
       if (fp->frame_type == TDD) {
@@ -821,7 +852,7 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
 
     }
 
-    AssertFatal(rel8->harq_process<8,"Format 2_2A: harq_pid=%d >= 8\n", rel8->harq_process);
+    AssertFatal (rel8->harq_process < 8, "Format 2_2A: harq_pid=%d >= 8\n", rel8->harq_process);
 
 
     // Flip the TB to codeword mapping as described in 5.3.3.1.5 of 36-212 V11.3.0
@@ -843,25 +874,20 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
     //    printf("Setting DLSCH harq id %d to subframe %d\n",harq_pid,subframe);
 
 
-    conv_rballoc(rel8->resource_allocation_type,
-                 rel8->resource_block_coding,
-                 fp->N_RB_DL,
-                 dlsch0_harq->rb_alloc);
+    conv_rballoc (rel8->resource_allocation_type, rel8->resource_block_coding, fp->N_RB_DL, dlsch0_harq->rb_alloc);
 
-    dlsch1_harq->rb_alloc[0]                         = dlsch0_harq->rb_alloc[0];
-    dlsch0_harq->nb_rb                               = conv_nprb(rel8->resource_allocation_type,
-								 rel8->resource_block_coding,
-								 fp->N_RB_DL);
-    dlsch1_harq->nb_rb                               = dlsch0_harq->nb_rb;
+    dlsch1_harq->rb_alloc[0] = dlsch0_harq->rb_alloc[0];
+    dlsch0_harq->nb_rb = conv_nprb (rel8->resource_allocation_type, rel8->resource_block_coding, fp->N_RB_DL);
+    dlsch1_harq->nb_rb = dlsch0_harq->nb_rb;
 
-    AssertFatal(dlsch0_harq->nb_rb > 0,"nb_rb=0\n");
+    AssertFatal (dlsch0_harq->nb_rb > 0, "nb_rb=0\n");
 
-    dlsch0_harq->mcs       = rel8->mcs_1;
-    dlsch1_harq->mcs       = rel8->mcs_2;
-    dlsch0_harq->Qm        = get_Qm(rel8->mcs_1);
-    dlsch1_harq->Qm        = get_Qm(rel8->mcs_2);
-    dlsch0_harq->rvidx     = rel8->redundancy_version_1;
-    dlsch1_harq->rvidx     = rel8->redundancy_version_2;
+    dlsch0_harq->mcs = rel8->mcs_1;
+    dlsch1_harq->mcs = rel8->mcs_2;
+    dlsch0_harq->Qm = get_Qm (rel8->mcs_1);
+    dlsch1_harq->Qm = get_Qm (rel8->mcs_2);
+    dlsch0_harq->rvidx = rel8->redundancy_version_1;
+    dlsch1_harq->rvidx = rel8->redundancy_version_2;
 
     // assume both TBs are active
     dlsch0_harq->Nl        = 1;
@@ -894,14 +920,13 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
 #endif
       dlsch1->harq_mask                         &= ~(1<<rel8->harq_process);
     }
-
-   // dlsch0_harq->dl_power_off = 0;
-   // dlsch1_harq->dl_power_off = 0;
+    // dlsch0_harq->dl_power_off = 0;
+    // dlsch1_harq->dl_power_off = 0;
 
 
     if (fp->nb_antenna_ports_eNB == 2) {
-      dlsch0_harq->TBS         = TBStable[get_I_TBS(dlsch0_harq->mcs)][dlsch0_harq->nb_rb-1];
-      dlsch1_harq->TBS         = TBStable[get_I_TBS(dlsch1_harq->mcs)][dlsch0_harq->nb_rb-1];
+      dlsch0_harq->TBS = TBStable[get_I_TBS (dlsch0_harq->mcs)][dlsch0_harq->nb_rb - 1];
+      dlsch1_harq->TBS = TBStable[get_I_TBS (dlsch1_harq->mcs)][dlsch0_harq->nb_rb - 1];
 
 #ifdef PHY_TX_THREAD
       if ((dlsch0->active[subframe]==1) && (dlsch1->active[subframe]==1)) {
@@ -913,8 +938,8 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
         dlsch0_harq->dl_power_off = 1;
         dlsch1_harq->dl_power_off = 1;
       } else {
-        dlsch0_harq->mimo_mode   = ALAMOUTI;
-        dlsch1_harq->mimo_mode   = ALAMOUTI;
+        dlsch0_harq->mimo_mode = ALAMOUTI;
+        dlsch1_harq->mimo_mode = ALAMOUTI;
       }
     } else if (fp->nb_antenna_ports_eNB == 4) { // 4 antenna case
 #ifdef PHY_TX_THREAD
@@ -923,42 +948,42 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
       if ((dlsch0->active==1) && (dlsch1->active==1)) {
 #endif
         switch (rel8->precoding_information) {
-        case 0: // one layer per transport block
-          dlsch0_harq->mimo_mode   = LARGE_CDD;
-          dlsch1_harq->mimo_mode   = LARGE_CDD;
-          dlsch0_harq->TBS         = TBStable[get_I_TBS(dlsch0_harq->mcs)][dlsch0_harq->nb_rb-1];
-          dlsch0_harq->TBS         = TBStable[get_I_TBS(dlsch0_harq->mcs)][dlsch0_harq->nb_rb-1];
+        case 0:                // one layer per transport block
+          dlsch0_harq->mimo_mode = LARGE_CDD;
+          dlsch1_harq->mimo_mode = LARGE_CDD;
+          dlsch0_harq->TBS = TBStable[get_I_TBS (dlsch0_harq->mcs)][dlsch0_harq->nb_rb - 1];
+          dlsch0_harq->TBS = TBStable[get_I_TBS (dlsch0_harq->mcs)][dlsch0_harq->nb_rb - 1];
           dlsch0_harq->dl_power_off = 1;
           dlsch1_harq->dl_power_off = 1;
           break;
 
-        case 1: // one-layers on TB 0, two on TB 1
-          dlsch0_harq->mimo_mode   = LARGE_CDD;
-          dlsch1_harq->mimo_mode   = LARGE_CDD;
-          dlsch1_harq->Nl          = 2;
-          dlsch1_harq->TBS         = TBStable[get_I_TBS(dlsch1_harq->mcs)][(dlsch1_harq->nb_rb<<1)-1];
+        case 1:                // one-layers on TB 0, two on TB 1
+          dlsch0_harq->mimo_mode = LARGE_CDD;
+          dlsch1_harq->mimo_mode = LARGE_CDD;
+          dlsch1_harq->Nl = 2;
+          dlsch1_harq->TBS = TBStable[get_I_TBS (dlsch1_harq->mcs)][(dlsch1_harq->nb_rb << 1) - 1];
           dlsch0_harq->dl_power_off = 1;
           dlsch1_harq->dl_power_off = 1;
           break;
 
-        case 2: // two-layers on TB 0, two on TB 1
-          dlsch0_harq->mimo_mode   = LARGE_CDD;
-          dlsch1_harq->mimo_mode   = LARGE_CDD;
-          dlsch0_harq->Nl          = 2;
+        case 2:                // two-layers on TB 0, two on TB 1
+          dlsch0_harq->mimo_mode = LARGE_CDD;
+          dlsch1_harq->mimo_mode = LARGE_CDD;
+          dlsch0_harq->Nl = 2;
           dlsch0_harq->dl_power_off = 1;
           dlsch1_harq->dl_power_off = 1;
 
           if (fp->N_RB_DL <= 56) {
-            dlsch0_harq->TBS         = TBStable[get_I_TBS(dlsch0_harq->mcs)][(dlsch0_harq->nb_rb<<1)-1];
-            dlsch1_harq->TBS         = TBStable[get_I_TBS(dlsch1_harq->mcs)][(dlsch1_harq->nb_rb<<1)-1];
+            dlsch0_harq->TBS = TBStable[get_I_TBS (dlsch0_harq->mcs)][(dlsch0_harq->nb_rb << 1) - 1];
+            dlsch1_harq->TBS = TBStable[get_I_TBS (dlsch1_harq->mcs)][(dlsch1_harq->nb_rb << 1) - 1];
           } else {
-            LOG_E(PHY,"Add implementation of Table 7.1.7.2.2-1 for two-layer TBS conversion with N_RB_DL > 56\n");
+            LOG_E (PHY, "Add implementation of Table 7.1.7.2.2-1 for two-layer TBS conversion with N_RB_DL > 56\n");
           }
 
           break;
 
-        case 3: //
-          LOG_E(PHY,"Illegal value (3) for TPMI in Format 2A DCI\n");
+        case 3:                //
+          LOG_E (PHY, "Illegal value (3) for TPMI in Format 2A DCI\n");
           break;
         }
 #ifdef PHY_TX_THREAD
@@ -967,22 +992,22 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
       } else if (dlsch0->active == 1) {
 #endif
         switch (rel8->precoding_information) {
-        case 0: // one layer per transport block
-          dlsch0_harq->mimo_mode   = ALAMOUTI;
-          dlsch1_harq->mimo_mode   = ALAMOUTI;
-          dlsch0_harq->TBS         = TBStable[get_I_TBS(dlsch0_harq->mcs)][dlsch0_harq->nb_rb-1];
+        case 0:                // one layer per transport block
+          dlsch0_harq->mimo_mode = ALAMOUTI;
+          dlsch1_harq->mimo_mode = ALAMOUTI;
+          dlsch0_harq->TBS = TBStable[get_I_TBS (dlsch0_harq->mcs)][dlsch0_harq->nb_rb - 1];
           break;
 
-        case 1: // two-layers on TB 0
-          dlsch0_harq->mimo_mode   = LARGE_CDD;
-          dlsch0_harq->Nl          = 2;
+        case 1:                // two-layers on TB 0
+          dlsch0_harq->mimo_mode = LARGE_CDD;
+          dlsch0_harq->Nl = 2;
           dlsch0_harq->dl_power_off = 1;
-          dlsch0_harq->TBS         = TBStable[get_I_TBS(dlsch0_harq->mcs)][(dlsch0_harq->nb_rb<<1)-1];
+          dlsch0_harq->TBS = TBStable[get_I_TBS (dlsch0_harq->mcs)][(dlsch0_harq->nb_rb << 1) - 1];
           break;
 
-        case 2: // two-layers on TB 0, two on TB 1
-        case 3: //
-          LOG_E(PHY,"Illegal value %d for TPMI in Format 2A DCI with one transport block enabled\n",rel8->precoding_information);
+        case 2:                // two-layers on TB 0, two on TB 1
+        case 3:                //
+          LOG_E (PHY, "Illegal value %d for TPMI in Format 2A DCI with one transport block enabled\n", rel8->precoding_information);
           break;
         }
 #ifdef PHY_TX_THREAD
@@ -991,27 +1016,27 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
       } else if (dlsch1->active == 1) {
 #endif
         switch (rel8->precoding_information) {
-        case 0: // one layer per transport block
-          dlsch0_harq->mimo_mode   = ALAMOUTI;
-          dlsch1_harq->mimo_mode   = ALAMOUTI;
-          dlsch1_harq->TBS         = TBStable[get_I_TBS(dlsch1_harq->mcs)][dlsch1_harq->nb_rb-1];
+        case 0:                // one layer per transport block
+          dlsch0_harq->mimo_mode = ALAMOUTI;
+          dlsch1_harq->mimo_mode = ALAMOUTI;
+          dlsch1_harq->TBS = TBStable[get_I_TBS (dlsch1_harq->mcs)][dlsch1_harq->nb_rb - 1];
           break;
 
-        case 1: // two-layers on TB 0
-          dlsch1_harq->mimo_mode   = LARGE_CDD;
-          dlsch1_harq->Nl          = 2;
+        case 1:                // two-layers on TB 0
+          dlsch1_harq->mimo_mode = LARGE_CDD;
+          dlsch1_harq->Nl = 2;
           dlsch1_harq->dl_power_off = 1;
-          dlsch1_harq->TBS         = TBStable[get_I_TBS(dlsch1_harq->mcs)][(dlsch1_harq->nb_rb<<1)-1];
+          dlsch1_harq->TBS = TBStable[get_I_TBS (dlsch1_harq->mcs)][(dlsch1_harq->nb_rb << 1) - 1];
           break;
 
-        case 2: // two-layers on TB 0, two on TB 1
-        case 3: //
-          LOG_E(PHY,"Illegal value %d for TPMI in Format 2A DCI with one transport block enabled\n",rel8->precoding_information);
+        case 2:                // two-layers on TB 0, two on TB 1
+        case 3:                //
+          LOG_E (PHY, "Illegal value %d for TPMI in Format 2A DCI with one transport block enabled\n", rel8->precoding_information);
           break;
         }
       }
     } else {
-      LOG_E(PHY,"Illegal number of antennas for eNB %d\n",fp->nb_antenna_ports_eNB);
+      LOG_E (PHY, "Illegal number of antennas for eNB %d\n", fp->nb_antenna_ports_eNB);
     }
 
     // reset HARQ process if this is the first transmission
@@ -1034,10 +1059,10 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
 
 
     break;
-      
+
   case NFAPI_DL_DCI_FORMAT_2:
 
-    dci_alloc->format     = format2;
+    dci_alloc->format = format2;
     switch (fp->N_RB_DL) {
     case 6:
       if (fp->frame_type == TDD) {
@@ -1182,7 +1207,7 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
 
     }
 
-    AssertFatal(rel8->harq_process>=8, "Format 2_2A: harq_pid=%d >= 8\n", rel8->harq_process);
+    AssertFatal (rel8->harq_process >= 8, "Format 2_2A: harq_pid=%d >= 8\n", rel8->harq_process);
 
 
     // Flip the TB to codeword mapping as described in 5.3.3.1.5 of 36-212 V11.3.0
@@ -1191,13 +1216,13 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
     TB1_active = 1;
 
     if ((rel8->redundancy_version_1 == 1) && (rel8->mcs_1 == 0)) {
-      TB0_active=0;
+      TB0_active = 0;
     }
     if ((rel8->redundancy_version_2 == 1) && (rel8->mcs_2 == 0)) {
-      TB1_active=0;
+      TB1_active = 0;
     }
 #ifdef DEBUG_HARQ
-    printf("RV0 = %d, RV1 = %d. MCS0 = %d, MCS1=%d\n", rel8->redundancy_version_1, rel8->redundancy_version_2, rel8->mcs_1, rel8->mcs_2);
+    printf ("RV0 = %d, RV1 = %d. MCS0 = %d, MCS1=%d\n", rel8->redundancy_version_1, rel8->redundancy_version_2, rel8->mcs_1, rel8->mcs_2);
 #endif
     if (TB0_active && TB1_active && rel8->transport_block_to_codeword_swap_flag==0) {
 #ifdef PHY_TX_THREAD
@@ -1213,19 +1238,18 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
       dlsch1_harq = dlsch1->harq_processes[rel8->harq_process];
       dlsch0_harq->mcs = rel8->mcs_1;
       dlsch1_harq->mcs = rel8->mcs_2;
-      dlsch0_harq->Qm  = get_Qm(rel8->mcs_1);
-      dlsch1_harq->Qm  = get_Qm(rel8->mcs_2);
+      dlsch0_harq->Qm = get_Qm (rel8->mcs_1);
+      dlsch1_harq->Qm = get_Qm (rel8->mcs_2);
       dlsch0_harq->rvidx = rel8->redundancy_version_1;
       dlsch1_harq->rvidx = rel8->redundancy_version_2;
       dlsch0_harq->status = ACTIVE;
       dlsch1_harq->status = ACTIVE;
-      dlsch0_harq->codeword=0;
-      dlsch1_harq->codeword=1;
+      dlsch0_harq->codeword = 0;
+      dlsch1_harq->codeword = 1;
 #ifdef DEBUG_HARQ
-      printf("\n ENB: BOTH ACTIVE\n");
+      printf ("\n ENB: BOTH ACTIVE\n");
 #endif
-    }
-    else if (TB0_active && TB1_active && rel8->transport_block_to_codeword_swap_flag==1) {
+    } else if (TB0_active && TB1_active && rel8->transport_block_to_codeword_swap_flag == 1) {
       dlsch0 = eNB->dlsch[UE_id][1];
       dlsch1 = eNB->dlsch[UE_id][0];
 #ifdef PHY_TX_THREAD
@@ -1236,14 +1260,14 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
       dlsch1->active = 1;
 #endif
 
-      dlsch0->harq_mask                         |= (1<<rel8->harq_process);
-      dlsch1->harq_mask                         |= (1<<rel8->harq_process);
+      dlsch0->harq_mask |= (1 << rel8->harq_process);
+      dlsch1->harq_mask |= (1 << rel8->harq_process);
 
       dlsch1_harq = dlsch1->harq_processes[rel8->harq_process];
       dlsch0_harq->mcs = rel8->mcs_1;
       dlsch1_harq->mcs = rel8->mcs_2;
-      dlsch0_harq->Qm  = get_Qm(rel8->mcs_1);
-      dlsch1_harq->Qm  = get_Qm(rel8->mcs_2);
+      dlsch0_harq->Qm = get_Qm (rel8->mcs_1);
+      dlsch1_harq->Qm = get_Qm (rel8->mcs_2);
       dlsch0_harq->rvidx = rel8->redundancy_version_1;
       dlsch1_harq->rvidx = rel8->redundancy_version_2;
       dlsch0_harq->status = ACTIVE;
@@ -1260,14 +1284,14 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
       dlsch0->harq_mask                         |= (1<<rel8->harq_process);
       dlsch0_harq = dlsch0->harq_processes[rel8->harq_process];
       dlsch0_harq->mcs = rel8->mcs_1;
-      dlsch0_harq->Qm  = get_Qm(rel8->mcs_1);
+      dlsch0_harq->Qm = get_Qm (rel8->mcs_1);
       dlsch0_harq->rvidx = rel8->redundancy_version_1;
       dlsch0_harq->status = ACTIVE;
       dlsch0_harq->codeword = 0;
-      dlsch1=NULL;
+      dlsch1 = NULL;
       dlsch1_harq = NULL;
 #ifdef DEBUG_HARQ
-      printf("\n ENB: TB1 is deactivated, retransmit TB0 transmit in TM6\n");
+      printf ("\n ENB: TB1 is deactivated, retransmit TB0 transmit in TM6\n");
 #endif
     }
     else if ((TB0_active==0) && TB1_active) {
@@ -1279,18 +1303,18 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
       dlsch1->harq_mask                         |= (1<<rel8->harq_process);
       dlsch1_harq = dlsch1->harq_processes[rel8->harq_process];
       dlsch1_harq->mcs = rel8->mcs_2;
-      dlsch1_harq->Qm  = get_Qm(rel8->mcs_2);
+      dlsch1_harq->Qm = get_Qm (rel8->mcs_2);
       dlsch1_harq->rvidx = rel8->redundancy_version_2;
       dlsch1_harq->status = ACTIVE;
       dlsch1_harq->codeword = 0;
-      dlsch0=NULL;
+      dlsch0 = NULL;
       dlsch0_harq = NULL;
 #ifdef DEBUG_HARQ
-      printf("\n ENB: TB0 is deactivated, retransmit TB1 transmit in TM6\n");
+      printf ("\n ENB: TB0 is deactivated, retransmit TB1 transmit in TM6\n");
 #endif
     }
 
-    if (dlsch0 != NULL){
+    if (dlsch0 != NULL) {
       dlsch0->subframe_tx[subframe] = 1;
 
       dlsch0->harq_ids[frame%2][subframe] = rel8->harq_process;
@@ -1301,143 +1325,135 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
     }
 
 
-    if (dlsch0 != NULL ){
-      conv_rballoc(rel8->resource_allocation_type,
-                   rel8->resource_block_coding,
-                   fp->N_RB_DL,
-                   dlsch0_harq->rb_alloc);
+    if (dlsch0 != NULL) {
+      conv_rballoc (rel8->resource_allocation_type, rel8->resource_block_coding, fp->N_RB_DL, dlsch0_harq->rb_alloc);
 
-      dlsch0_harq->nb_rb = conv_nprb(rel8->resource_allocation_type, rel8->resource_block_coding, fp->N_RB_DL);
+      dlsch0_harq->nb_rb = conv_nprb (rel8->resource_allocation_type, rel8->resource_block_coding, fp->N_RB_DL);
 
-      if (dlsch1 != NULL){
+      if (dlsch1 != NULL) {
         dlsch1_harq->rb_alloc[0] = dlsch0_harq->rb_alloc[0];
         dlsch1_harq->nb_rb = dlsch0_harq->nb_rb;
       }
-    } else if ((dlsch0 == NULL ) && (dlsch1 != NULL )){
-        conv_rballoc(rel8->resource_allocation_type,
-                     rel8->resource_block_coding,
-                     fp->N_RB_DL,
-                     dlsch1_harq->rb_alloc);
+    } else if ((dlsch0 == NULL) && (dlsch1 != NULL)) {
+      conv_rballoc (rel8->resource_allocation_type, rel8->resource_block_coding, fp->N_RB_DL, dlsch1_harq->rb_alloc);
 
-        dlsch1_harq->nb_rb = conv_nprb(rel8->resource_allocation_type, rel8->resource_block_coding, fp->N_RB_DL);
+      dlsch1_harq->nb_rb = conv_nprb (rel8->resource_allocation_type, rel8->resource_block_coding, fp->N_RB_DL);
     }
 
-
     // assume both TBs are active
     if (dlsch0_harq != NULL)
-      dlsch0_harq->Nl        = 1;
+      dlsch0_harq->Nl = 1;
     if (dlsch1_harq != NULL)
-      dlsch1_harq->Nl        = 1;
+      dlsch1_harq->Nl = 1;
 
 
     // check if either TB is disabled (see 36-213 V11.3 Section )
 
     if (fp->nb_antenna_ports_eNB == 2) {
-      if ((dlsch0 != NULL) && (dlsch1 != NULL)) {  //two CW active
+      if ((dlsch0 != NULL) && (dlsch1 != NULL)) {       //two CW active
 
         dlsch0_harq->dl_power_off = 1;
         dlsch1_harq->dl_power_off = 1;
-        dlsch0_harq->TBS = TBStable[get_I_TBS(dlsch0_harq->mcs)][dlsch0_harq->nb_rb-1];
-        dlsch1_harq->TBS = TBStable[get_I_TBS(dlsch1_harq->mcs)][dlsch1_harq->nb_rb-1];
+        dlsch0_harq->TBS = TBStable[get_I_TBS (dlsch0_harq->mcs)][dlsch0_harq->nb_rb - 1];
+        dlsch1_harq->TBS = TBStable[get_I_TBS (dlsch1_harq->mcs)][dlsch1_harq->nb_rb - 1];
         switch (rel8->precoding_information) {
         case 0:
-          dlsch0_harq->mimo_mode   = DUALSTREAM_UNIFORM_PRECODING1;
-          dlsch1_harq->mimo_mode   = DUALSTREAM_UNIFORM_PRECODING1;
-          dlsch0_harq->pmi_alloc   = pmi_extend(fp,0,1);
-          dlsch1_harq->pmi_alloc   = pmi_extend(fp,0,1);
+          dlsch0_harq->mimo_mode = DUALSTREAM_UNIFORM_PRECODING1;
+          dlsch1_harq->mimo_mode = DUALSTREAM_UNIFORM_PRECODING1;
+          dlsch0_harq->pmi_alloc = pmi_extend (fp, 0, 1);
+          dlsch1_harq->pmi_alloc = pmi_extend (fp, 0, 1);
           break;
         case 1:
-          dlsch0_harq->mimo_mode   = DUALSTREAM_UNIFORM_PRECODINGj;
-          dlsch1_harq->mimo_mode   = DUALSTREAM_UNIFORM_PRECODINGj;
-          dlsch0_harq->pmi_alloc   = pmi_extend(fp,1,1);
-          dlsch0_harq->pmi_alloc   = pmi_extend(fp,1,1);
+          dlsch0_harq->mimo_mode = DUALSTREAM_UNIFORM_PRECODINGj;
+          dlsch1_harq->mimo_mode = DUALSTREAM_UNIFORM_PRECODINGj;
+          dlsch0_harq->pmi_alloc = pmi_extend (fp, 1, 1);
+          dlsch0_harq->pmi_alloc = pmi_extend (fp, 1, 1);
 
           break;
-        case 2: // PUSCH precoding
-          dlsch0_harq->mimo_mode   = DUALSTREAM_PUSCH_PRECODING;
-          dlsch0_harq->pmi_alloc   = DL_pmi_single;
-          dlsch1_harq->mimo_mode   = DUALSTREAM_PUSCH_PRECODING;
-          dlsch1_harq->pmi_alloc   = DL_pmi_single;
+        case 2:                // PUSCH precoding
+          dlsch0_harq->mimo_mode = DUALSTREAM_PUSCH_PRECODING;
+          dlsch0_harq->pmi_alloc = DL_pmi_single;
+          dlsch1_harq->mimo_mode = DUALSTREAM_PUSCH_PRECODING;
+          dlsch1_harq->pmi_alloc = DL_pmi_single;
           break;
         default:
           break;
         }
-      } else if ((dlsch0 != NULL) && (dlsch1 == NULL))  { // only CW 0 active
+      } else if ((dlsch0 != NULL) && (dlsch1 == NULL)) {        // only CW 0 active
         dlsch0_harq->dl_power_off = 1;
-        dlsch0_harq->TBS= TBStable[get_I_TBS(dlsch0_harq->mcs)][dlsch0_harq->nb_rb-1];
+        dlsch0_harq->TBS = TBStable[get_I_TBS (dlsch0_harq->mcs)][dlsch0_harq->nb_rb - 1];
         switch (rel8->precoding_information) {
-        case 0 :
-          dlsch0_harq->mimo_mode   = ALAMOUTI;
+        case 0:
+          dlsch0_harq->mimo_mode = ALAMOUTI;
           break;
         case 1:
-          dlsch0_harq->mimo_mode   = UNIFORM_PRECODING11;
-          dlsch0_harq->pmi_alloc   = pmi_extend(fp,0,0);
+          dlsch0_harq->mimo_mode = UNIFORM_PRECODING11;
+          dlsch0_harq->pmi_alloc = pmi_extend (fp, 0, 0);
           break;
         case 2:
-          dlsch0_harq->mimo_mode   = UNIFORM_PRECODING1m1;
-          dlsch0_harq->pmi_alloc   = pmi_extend(fp,1,0);
+          dlsch0_harq->mimo_mode = UNIFORM_PRECODING1m1;
+          dlsch0_harq->pmi_alloc = pmi_extend (fp, 1, 0);
           break;
         case 3:
-          dlsch0_harq->mimo_mode   = UNIFORM_PRECODING1j;
-          dlsch0_harq->pmi_alloc   = pmi_extend(fp,2,0);
+          dlsch0_harq->mimo_mode = UNIFORM_PRECODING1j;
+          dlsch0_harq->pmi_alloc = pmi_extend (fp, 2, 0);
           break;
         case 4:
-          dlsch0_harq->mimo_mode   = UNIFORM_PRECODING1mj;
-          dlsch0_harq->pmi_alloc   = pmi_extend(fp,3,0);
+          dlsch0_harq->mimo_mode = UNIFORM_PRECODING1mj;
+          dlsch0_harq->pmi_alloc = pmi_extend (fp, 3, 0);
           break;
         case 5:
-          dlsch0_harq->mimo_mode   = PUSCH_PRECODING0;
-          dlsch0_harq->pmi_alloc   = DL_pmi_single;
+          dlsch0_harq->mimo_mode = PUSCH_PRECODING0;
+          dlsch0_harq->pmi_alloc = DL_pmi_single;
           break;
         case 6:
-          dlsch0_harq->mimo_mode   = PUSCH_PRECODING1;
-          dlsch0_harq->pmi_alloc   = DL_pmi_single;
+          dlsch0_harq->mimo_mode = PUSCH_PRECODING1;
+          dlsch0_harq->pmi_alloc = DL_pmi_single;
           break;
         }
-      } else if ((dlsch0 == NULL) && (dlsch1 != NULL))  {
-          dlsch1_harq->dl_power_off = 1;
-          dlsch1_harq->TBS= TBStable[get_I_TBS(dlsch1_harq->mcs)][dlsch1_harq->nb_rb-1];
-          switch (rel8->precoding_information) {
-          case 0 :
-            dlsch1_harq->mimo_mode   = ALAMOUTI;
-            break;
-          case 1:
-            dlsch1_harq->mimo_mode   = UNIFORM_PRECODING11;
-            dlsch1_harq->pmi_alloc   = pmi_extend(fp,0,0);
-            break;
-          case 2:
-            dlsch1_harq->mimo_mode   = UNIFORM_PRECODING1m1;
-            dlsch1_harq->pmi_alloc   = pmi_extend(fp,1,0);
-            break;
-          case 3:
-            dlsch1_harq->mimo_mode   = UNIFORM_PRECODING1j;
-            dlsch1_harq->pmi_alloc   = pmi_extend(fp,2,0);
-            break;
-          case 4:
-            dlsch1_harq->mimo_mode   = UNIFORM_PRECODING1mj;
-            dlsch1_harq->pmi_alloc   = pmi_extend(fp,3,0);
-            break;
-          case 5:
-            dlsch1_harq->mimo_mode   = PUSCH_PRECODING0;
-            dlsch1_harq->pmi_alloc   = DL_pmi_single;
-            break;
-          case 6:
-            dlsch1_harq->mimo_mode   = PUSCH_PRECODING1;
-            dlsch1_harq->pmi_alloc   = DL_pmi_single;
-            break;
-          }
+      } else if ((dlsch0 == NULL) && (dlsch1 != NULL)) {
+        dlsch1_harq->dl_power_off = 1;
+        dlsch1_harq->TBS = TBStable[get_I_TBS (dlsch1_harq->mcs)][dlsch1_harq->nb_rb - 1];
+        switch (rel8->precoding_information) {
+        case 0:
+          dlsch1_harq->mimo_mode = ALAMOUTI;
+          break;
+        case 1:
+          dlsch1_harq->mimo_mode = UNIFORM_PRECODING11;
+          dlsch1_harq->pmi_alloc = pmi_extend (fp, 0, 0);
+          break;
+        case 2:
+          dlsch1_harq->mimo_mode = UNIFORM_PRECODING1m1;
+          dlsch1_harq->pmi_alloc = pmi_extend (fp, 1, 0);
+          break;
+        case 3:
+          dlsch1_harq->mimo_mode = UNIFORM_PRECODING1j;
+          dlsch1_harq->pmi_alloc = pmi_extend (fp, 2, 0);
+          break;
+        case 4:
+          dlsch1_harq->mimo_mode = UNIFORM_PRECODING1mj;
+          dlsch1_harq->pmi_alloc = pmi_extend (fp, 3, 0);
+          break;
+        case 5:
+          dlsch1_harq->mimo_mode = PUSCH_PRECODING0;
+          dlsch1_harq->pmi_alloc = DL_pmi_single;
+          break;
+        case 6:
+          dlsch1_harq->mimo_mode = PUSCH_PRECODING1;
+          dlsch1_harq->pmi_alloc = DL_pmi_single;
+          break;
         }
+      }
 
     } else if (fp->nb_antenna_ports_eNB == 4) {
       // fill in later
     }
-
     // reset HARQ process if this is the first transmission
-   /* if (dlsch0_harq->round == 0)
-      dlsch0_harq->status = ACTIVE;
+    /* if (dlsch0_harq->round == 0)
+       dlsch0_harq->status = ACTIVE;
 
-    if (dlsch1_harq->round == 0)
-      dlsch1_harq->status = ACTIVE;*/
+       if (dlsch1_harq->round == 0)
+       dlsch1_harq->status = ACTIVE; */
     if (dlsch0_harq != NULL)
       dlsch0->rnti = rel8->rnti;
     if (dlsch1 != NULL)
@@ -1454,39 +1470,36 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
     dlsch1_harq->frame    = frame;
     dlsch1_harq->subframe = subframe;
   }
-
 #ifdef DEBUG_DCI
 
   if (dlsch0) {
-    printf("dlsch0 eNB: dlsch0   %p\n",dlsch0);
-    printf("dlsch0 eNB: rnti     %x\n",dlsch0->rnti);
-    printf("dlsch0 eNB: NBRB     %d\n",dlsch0_harq->nb_rb);
-    printf("dlsch0 eNB: rballoc  %x\n",dlsch0_harq->rb_alloc[0]);
-    printf("dlsch0 eNB: harq_pid %d\n",harq_pid);
-    printf("dlsch0 eNB: round    %d\n",dlsch0_harq->round);
-    printf("dlsch0 eNB: rvidx    %d\n",dlsch0_harq->rvidx);
-    printf("dlsch0 eNB: TBS      %d (NPRB %d)\n",dlsch0_harq->TBS,NPRB);
-    printf("dlsch0 eNB: mcs      %d\n",dlsch0_harq->mcs);
-    printf("dlsch0 eNB: tpmi %d\n",rel8->precoding_information);
-    printf("dlsch0 eNB: mimo_mode %d\n",dlsch0_harq->mimo_mode);
+    printf ("dlsch0 eNB: dlsch0   %p\n", dlsch0);
+    printf ("dlsch0 eNB: rnti     %x\n", dlsch0->rnti);
+    printf ("dlsch0 eNB: NBRB     %d\n", dlsch0_harq->nb_rb);
+    printf ("dlsch0 eNB: rballoc  %x\n", dlsch0_harq->rb_alloc[0]);
+    printf ("dlsch0 eNB: harq_pid %d\n", harq_pid);
+    printf ("dlsch0 eNB: round    %d\n", dlsch0_harq->round);
+    printf ("dlsch0 eNB: rvidx    %d\n", dlsch0_harq->rvidx);
+    printf ("dlsch0 eNB: TBS      %d (NPRB %d)\n", dlsch0_harq->TBS, NPRB);
+    printf ("dlsch0 eNB: mcs      %d\n", dlsch0_harq->mcs);
+    printf ("dlsch0 eNB: tpmi %d\n", rel8->precoding_information);
+    printf ("dlsch0 eNB: mimo_mode %d\n", dlsch0_harq->mimo_mode);
   }
 
-    if (dlsch1) {
-    printf("dlsch1 eNB: dlsch1   %p\n",dlsch1);
-    printf("dlsch1 eNB: rnti     %x\n",dlsch1->rnti);
-    printf("dlsch1 eNB: NBRB     %d\n",dlsch1_harq->nb_rb);
-    printf("dlsch1 eNB: rballoc  %x\n",dlsch1_harq->rb_alloc[0]);
-    printf("dlsch1 eNB: harq_pid %d\n",harq_pid);
-    printf("dlsch1 eNB: round    %d\n",dlsch1_harq->round);
-    printf("dlsch1 eNB: rvidx    %d\n",dlsch1_harq->rvidx);
-    printf("dlsch1 eNB: TBS      %d (NPRB %d)\n",dlsch1_harq->TBS,NPRB);
-    printf("dlsch1 eNB: mcs      %d\n",dlsch1_harq->mcs);
-    printf("dlsch1 eNB: tpmi %d\n",rel8->precoding_information);
-    printf("dlsch1 eNB: mimo_mode %d\n",dlsch1_harq->mimo_mode);
+  if (dlsch1) {
+    printf ("dlsch1 eNB: dlsch1   %p\n", dlsch1);
+    printf ("dlsch1 eNB: rnti     %x\n", dlsch1->rnti);
+    printf ("dlsch1 eNB: NBRB     %d\n", dlsch1_harq->nb_rb);
+    printf ("dlsch1 eNB: rballoc  %x\n", dlsch1_harq->rb_alloc[0]);
+    printf ("dlsch1 eNB: harq_pid %d\n", harq_pid);
+    printf ("dlsch1 eNB: round    %d\n", dlsch1_harq->round);
+    printf ("dlsch1 eNB: rvidx    %d\n", dlsch1_harq->rvidx);
+    printf ("dlsch1 eNB: TBS      %d (NPRB %d)\n", dlsch1_harq->TBS, NPRB);
+    printf ("dlsch1 eNB: mcs      %d\n", dlsch1_harq->mcs);
+    printf ("dlsch1 eNB: tpmi %d\n", rel8->precoding_information);
+    printf ("dlsch1 eNB: mimo_mode %d\n", dlsch1_harq->mimo_mode);
   }
-
 #endif
-    
 //printf("DCI %d.%d rnti %d harq %d TBS %d\n", frame, subframe, rel8->rnti, rel8->harq_process, dlsch0_harq->TBS);
 #if T_TRACER
   if (dlsch0->active)
@@ -1497,272 +1510,281 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t
 
 }
 
-void fill_mdci_and_dlsch(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,mDCI_ALLOC_t *dci_alloc,nfapi_dl_config_mpdcch_pdu *pdu) {
+
+void fill_mdci_and_dlsch(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc,mDCI_ALLOC_t *dci_alloc,nfapi_dl_config_mpdcch_pdu *pdu){
 
   LTE_DL_FRAME_PARMS *fp = &eNB->frame_parms;
 
-  uint8_t *dci_pdu = &dci_alloc->dci_pdu[0];
+  uint8_t        *dci_pdu = &dci_alloc->dci_pdu[0];
   nfapi_dl_config_mpdcch_pdu_rel13_t *rel13 = &pdu->mpdcch_pdu_rel13;
 
-  LTE_eNB_DLSCH_t *dlsch0=NULL;
-  LTE_DL_eNB_HARQ_t *dlsch0_harq=NULL;
-  int UE_id;
-  int subframe = proc->subframe_tx;
-  int frame = proc->frame_tx;
-
-  dci_alloc->firstCCE                   = rel13->ecce_index;
-  dci_alloc->L                          = rel13->aggregation_level;
-  dci_alloc->rnti                       = rel13->rnti;
-  dci_alloc->harq_pid                   = rel13->harq_process;
-  dci_alloc->narrowband                  = rel13->mpdcch_narrow_band;
-  dci_alloc->number_of_prb_pairs        = rel13->number_of_prb_pairs;
-  dci_alloc->resource_block_assignment  = rel13->resource_block_assignment;
-  dci_alloc->transmission_type          = rel13->mpdcch_tansmission_type;
-  dci_alloc->start_symbol               = rel13->start_symbol;
-  dci_alloc->ce_mode                    = rel13->ce_mode;
-  dci_alloc->dmrs_scrambling_init       = rel13->drms_scrambling_init;
-  dci_alloc->i0                         = rel13->initial_transmission_sf_io;
-
-  dci_alloc->ra_flag  = 0;
-  if (rel13->rnti_type == 2 ) dci_alloc->ra_flag = 1;
-
-  UE_id = find_dlsch(rel13->rnti,eNB,SEARCH_EXIST_OR_FREE);
-  if( (UE_id<0) || (UE_id>=NUMBER_OF_UE_MAX) ){
-    LOG_E(PHY,"illegal UE_id found!!! rnti %04x UE_id %d\n",rel13->rnti,UE_id);
-    return;
-  }
-  //AssertFatal(UE_id!=-1,"no free or exiting dlsch_context\n");
-  //AssertFatal(UE_id<NUMBER_OF_UE_MAX,"returned UE_id %d >= %d(NUMBER_OF_UE_MAX)\n",UE_id,NUMBER_OF_UE_MAX);
+
+  LTE_eNB_DLSCH_t *dlsch0 = NULL;
+  LTE_DL_eNB_HARQ_t *dlsch0_harq = NULL;
+  int             UE_id;
+  int             subframe = proc->subframe_tx;
+  int             frame = proc->frame_tx;
+
+  dci_alloc->firstCCE = rel13->ecce_index;
+  dci_alloc->L = rel13->aggregation_level;
+  dci_alloc->rnti = rel13->rnti;
+  dci_alloc->harq_pid = rel13->harq_process;
+  dci_alloc->narrowband = rel13->mpdcch_narrow_band;
+  dci_alloc->number_of_prb_pairs = rel13->number_of_prb_pairs;
+  dci_alloc->resource_block_assignment = rel13->resource_block_assignment;
+  dci_alloc->transmission_type = rel13->mpdcch_tansmission_type;
+  dci_alloc->start_symbol = rel13->start_symbol;
+  dci_alloc->ce_mode = rel13->ce_mode;
+  dci_alloc->dmrs_scrambling_init = rel13->drms_scrambling_init;
+  dci_alloc->i0 = rel13->initial_transmission_sf_io;
+
+
+  UE_id = find_dlsch (rel13->rnti, eNB, SEARCH_EXIST_OR_FREE);
+  AssertFatal (UE_id != -1, "no free or exiting dlsch_context\n");
+  AssertFatal (UE_id < NUMBER_OF_UE_MAX, "returned UE_id %d >= %d(NUMBER_OF_UE_MAX)\n", UE_id, NUMBER_OF_UE_MAX);
   dlsch0 = eNB->dlsch[UE_id][0];
-  dlsch0_harq                               = dlsch0->harq_processes[rel13->harq_process];
+  dlsch0_harq = dlsch0->harq_processes[rel13->harq_process];
+
+  dci_alloc->ra_flag = 0;
+
+  if (rel13->rnti_type == 2) {
+    dci_alloc->ra_flag = 1;
+  }
 
-  AssertFatal(fp->frame_type==FDD,"TDD is not supported yet for eMTC\n");
-  AssertFatal(fp->N_RB_DL==25 || fp->N_RB_DL==50 ||fp->N_RB_DL==100,
-	      "eMTC only with N_RB_DL = 25,50,100\n");
+  AssertFatal (fp->frame_type == FDD, "TDD is not supported yet for eMTC\n");
+  AssertFatal (fp->N_RB_DL == 25 || fp->N_RB_DL == 50 || fp->N_RB_DL == 100, "eMTC only with N_RB_DL = 25,50,100\n");
 
   switch (rel13->dci_format) {
 
-  case 10:  // Format 6-1A
-    dci_alloc->format     = format6_1A;
-#ifdef PHY_TX_THREAD
-    dlsch0->active[subframe]       = 1;
-#else
-    dlsch0->active       = 1;
-#endif
+
+  case 10:                     // Format 6-1A
+    dci_alloc->format = format6_1A;
+    dlsch0->active = 1;
     switch (fp->N_RB_DL) {
 
     case 25:
-      dci_alloc->dci_length                     = sizeof_DCI6_1A_5MHz_t; 
-      ((DCI6_1A_5MHz_t *)dci_pdu)->type         = 1;
-      ((DCI6_1A_5MHz_t *)dci_pdu)->hopping      = rel13->frequency_hopping_enabled_flag;
-      ((DCI6_1A_5MHz_t *)dci_pdu)->rballoc      = rel13->resource_block_coding;
-      ((DCI6_1A_5MHz_t *)dci_pdu)->mcs          = rel13->mcs;
-      ((DCI6_1A_5MHz_t *)dci_pdu)->rep          = (rel13->pdsch_reptition_levels-1);
-      ((DCI6_1A_5MHz_t *)dci_pdu)->harq_pid     = rel13->harq_process;
-      ((DCI6_1A_5MHz_t *)dci_pdu)->ndi          = rel13->new_data_indicator;
-      ((DCI6_1A_5MHz_t *)dci_pdu)->rv           = rel13->redundancy_version;
-      ((DCI6_1A_5MHz_t *)dci_pdu)->TPC          = rel13->tpc;
-      ((DCI6_1A_5MHz_t *)dci_pdu)->srs_req      = rel13->srs_request;
-      ((DCI6_1A_5MHz_t *)dci_pdu)->harq_ack_off = rel13->harq_resource_offset;
-      ((DCI6_1A_5MHz_t *)dci_pdu)->dci_rep      = rel13->dci_subframe_repetition_number-1;
-      ((DCI6_1A_5MHz_t *)dci_pdu)->padding      = 0;
-    
+      dci_alloc->dci_length = sizeof_DCI6_1A_5MHz_t;
+      ((DCI6_1A_5MHz_t *) dci_pdu)->type = 1;
+      ((DCI6_1A_5MHz_t *) dci_pdu)->hopping = rel13->frequency_hopping_enabled_flag;
+      ((DCI6_1A_5MHz_t *) dci_pdu)->rballoc = rel13->resource_block_coding;
+      ((DCI6_1A_5MHz_t *) dci_pdu)->mcs = rel13->mcs;
+      ((DCI6_1A_5MHz_t *) dci_pdu)->rep = rel13->pdsch_reptition_levels;
+      ((DCI6_1A_5MHz_t *) dci_pdu)->harq_pid = rel13->harq_process;
+      ((DCI6_1A_5MHz_t *) dci_pdu)->ndi = rel13->new_data_indicator;
+      ((DCI6_1A_5MHz_t *) dci_pdu)->rv = rel13->redundancy_version;
+      ((DCI6_1A_5MHz_t *) dci_pdu)->TPC = rel13->tpc;
+      ((DCI6_1A_5MHz_t *) dci_pdu)->srs_req = rel13->srs_request;
+      ((DCI6_1A_5MHz_t *) dci_pdu)->harq_ack_off = rel13->harq_resource_offset;
+      ((DCI6_1A_5MHz_t *) dci_pdu)->dci_rep = rel13->dci_subframe_repetition_number;
+
       break;
     case 50:
-      dci_alloc->dci_length                     = sizeof_DCI6_1A_10MHz_t; 
-      ((DCI6_1A_10MHz_t *)dci_pdu)->type         = 1;
-      ((DCI6_1A_10MHz_t *)dci_pdu)->hopping      = rel13->frequency_hopping_enabled_flag;
-      ((DCI6_1A_10MHz_t *)dci_pdu)->rballoc      = rel13->resource_block_coding;
-      ((DCI6_1A_10MHz_t *)dci_pdu)->mcs          = rel13->mcs;
-      ((DCI6_1A_10MHz_t *)dci_pdu)->rep          = (rel13->pdsch_reptition_levels-1);
-      ((DCI6_1A_10MHz_t *)dci_pdu)->harq_pid     = rel13->harq_process;
-      ((DCI6_1A_10MHz_t *)dci_pdu)->ndi          = rel13->new_data_indicator;
-      ((DCI6_1A_10MHz_t *)dci_pdu)->rv           = rel13->redundancy_version;
-      ((DCI6_1A_10MHz_t *)dci_pdu)->TPC          = rel13->tpc;
-      ((DCI6_1A_10MHz_t *)dci_pdu)->srs_req      = rel13->srs_request;
-      ((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-1;
-      ((DCI6_1A_10MHz_t *)dci_pdu)->padding      = 0;
+      dci_alloc->dci_length = sizeof_DCI6_1A_10MHz_t;
+      ((DCI6_1A_10MHz_t *) dci_pdu)->type = 1;
+      ((DCI6_1A_10MHz_t *) dci_pdu)->hopping = rel13->frequency_hopping_enabled_flag;
+      ((DCI6_1A_10MHz_t *) dci_pdu)->rballoc = rel13->resource_block_coding&31;
+      ((DCI6_1A_10MHz_t *) dci_pdu)->narrowband = rel13->resource_block_coding>>5;
+      ((DCI6_1A_10MHz_t *) dci_pdu)->mcs = rel13->mcs;
+      ((DCI6_1A_10MHz_t *) dci_pdu)->rep = (rel13->pdsch_reptition_levels);
+      ((DCI6_1A_10MHz_t *) dci_pdu)->harq_pid = rel13->harq_process;
+      ((DCI6_1A_10MHz_t *) dci_pdu)->ndi = rel13->new_data_indicator;
+      ((DCI6_1A_10MHz_t *) dci_pdu)->rv = rel13->redundancy_version;
+      ((DCI6_1A_10MHz_t *) dci_pdu)->TPC = rel13->tpc;
+      ((DCI6_1A_10MHz_t *) dci_pdu)->srs_req = rel13->srs_request;
+      ((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",
+	    frame,subframe,
+	    ((DCI6_1A_10MHz_t *) dci_pdu)->type,
+	    ((DCI6_1A_10MHz_t *) dci_pdu)->hopping,
+	    ((DCI6_1A_10MHz_t *) dci_pdu)->narrowband,
+	    ((DCI6_1A_10MHz_t *) dci_pdu)->rballoc,
+	    ((DCI6_1A_10MHz_t *) dci_pdu)->mcs,
+	    ((DCI6_1A_10MHz_t *) dci_pdu)->rep,
+	    ((DCI6_1A_10MHz_t *) dci_pdu)->harq_pid,
+	    ((DCI6_1A_10MHz_t *) dci_pdu)->ndi,
+	    ((DCI6_1A_10MHz_t *) dci_pdu)->rv,
+	    ((DCI6_1A_10MHz_t *) dci_pdu)->TPC,
+	    ((DCI6_1A_10MHz_t *) dci_pdu)->srs_req,
+	    ((DCI6_1A_10MHz_t *) dci_pdu)->harq_ack_off,
+	    ((DCI6_1A_10MHz_t *) dci_pdu)->dci_rep,
+	    ((uint32_t*)dci_pdu)[0]);
       break;
     case 100:
-      dci_alloc->dci_length                     = sizeof_DCI6_1A_20MHz_t; 
-      ((DCI6_1A_20MHz_t *)dci_pdu)->type         = 1;
-      ((DCI6_1A_20MHz_t *)dci_pdu)->hopping      = rel13->frequency_hopping_enabled_flag;
-      ((DCI6_1A_20MHz_t *)dci_pdu)->rballoc      = rel13->resource_block_coding;
-      ((DCI6_1A_20MHz_t *)dci_pdu)->mcs          = rel13->mcs;
-      ((DCI6_1A_20MHz_t *)dci_pdu)->rep          = (rel13->pdsch_reptition_levels-1);
-      ((DCI6_1A_20MHz_t *)dci_pdu)->harq_pid     = rel13->harq_process;
-      ((DCI6_1A_20MHz_t *)dci_pdu)->ndi          = rel13->new_data_indicator;
-      ((DCI6_1A_20MHz_t *)dci_pdu)->rv           = rel13->redundancy_version;
-      ((DCI6_1A_20MHz_t *)dci_pdu)->TPC          = rel13->tpc;
-      ((DCI6_1A_20MHz_t *)dci_pdu)->srs_req      = rel13->srs_request;
-      ((DCI6_1A_20MHz_t *)dci_pdu)->harq_ack_off = rel13->harq_resource_offset;
-      ((DCI6_1A_20MHz_t *)dci_pdu)->dci_rep      = rel13->dci_subframe_repetition_number-1;
-      ((DCI6_1A_20MHz_t *)dci_pdu)->padding      = 0;
+      dci_alloc->dci_length = sizeof_DCI6_1A_20MHz_t;
+      ((DCI6_1A_20MHz_t *) dci_pdu)->type = 1;
+      ((DCI6_1A_20MHz_t *) dci_pdu)->hopping = rel13->frequency_hopping_enabled_flag;
+      ((DCI6_1A_20MHz_t *) dci_pdu)->rballoc = rel13->resource_block_coding;
+      ((DCI6_1A_20MHz_t *) dci_pdu)->mcs = rel13->mcs;
+      ((DCI6_1A_20MHz_t *) dci_pdu)->rep = rel13->pdsch_reptition_levels;
+      ((DCI6_1A_20MHz_t *) dci_pdu)->harq_pid = rel13->harq_process;
+      ((DCI6_1A_20MHz_t *) dci_pdu)->ndi = rel13->new_data_indicator;
+      ((DCI6_1A_20MHz_t *) dci_pdu)->rv = rel13->redundancy_version;
+      ((DCI6_1A_20MHz_t *) dci_pdu)->TPC = rel13->tpc;
+      ((DCI6_1A_20MHz_t *) dci_pdu)->srs_req = rel13->srs_request;
+      ((DCI6_1A_20MHz_t *) dci_pdu)->harq_ack_off = rel13->harq_resource_offset;
+      ((DCI6_1A_20MHz_t *) dci_pdu)->dci_rep = rel13->dci_subframe_repetition_number;
       break;
     }
     break;
-  case 11:  // Format 6-1B
-    dci_alloc->format     = format6_1B;
-#ifdef PHY_TX_THREAD
-    dlsch0->active[subframe]       = 1;
-#else
-    dlsch0->active       = 1;
-#endif
+  case 11:                     // Format 6-1B
+    dci_alloc->format = format6_1B;
+    dlsch0->active = 1;
     switch (fp->N_RB_DL) {
 
     case 25:
-      dci_alloc->dci_length                     = sizeof_DCI6_1B_5MHz_t; 
-      ((DCI6_1B_5MHz_t *)dci_pdu)->type         = 1;
-      ((DCI6_1B_5MHz_t *)dci_pdu)->rballoc      = rel13->resource_block_coding;
-      ((DCI6_1B_5MHz_t *)dci_pdu)->mcs          = rel13->mcs;
-      ((DCI6_1B_5MHz_t *)dci_pdu)->rep          = (rel13->pdsch_reptition_levels-1);
-      ((DCI6_1B_5MHz_t *)dci_pdu)->harq_pid     = rel13->harq_process;
-      ((DCI6_1B_5MHz_t *)dci_pdu)->ndi          = rel13->new_data_indicator;
-      ((DCI6_1B_5MHz_t *)dci_pdu)->harq_ack_off = rel13->harq_resource_offset;
-      ((DCI6_1B_5MHz_t *)dci_pdu)->dci_rep      = rel13->dci_subframe_repetition_number-1;
-      ((DCI6_1B_5MHz_t *)dci_pdu)->padding      = 0;
-  
+      dci_alloc->dci_length = sizeof_DCI6_1B_5MHz_t;
+      ((DCI6_1B_5MHz_t *) dci_pdu)->type = 1;
+      ((DCI6_1B_5MHz_t *) dci_pdu)->rballoc = rel13->resource_block_coding;
+      ((DCI6_1B_5MHz_t *) dci_pdu)->mcs = rel13->mcs;
+      ((DCI6_1B_5MHz_t *) dci_pdu)->rep = rel13->pdsch_reptition_levels;
+      ((DCI6_1B_5MHz_t *) dci_pdu)->harq_pid = rel13->harq_process;
+      ((DCI6_1B_5MHz_t *) dci_pdu)->ndi = rel13->new_data_indicator;
+      ((DCI6_1B_5MHz_t *) dci_pdu)->harq_ack_off = rel13->harq_resource_offset;
+      ((DCI6_1B_5MHz_t *) dci_pdu)->dci_rep = rel13->dci_subframe_repetition_number;
+
       break;
     case 50:
-      dci_alloc->dci_length                      = sizeof_DCI6_1B_10MHz_t; 
-      ((DCI6_1B_10MHz_t *)dci_pdu)->type         = 1;
-      ((DCI6_1B_10MHz_t *)dci_pdu)->rballoc      = rel13->resource_block_coding;
-      ((DCI6_1B_10MHz_t *)dci_pdu)->mcs          = rel13->mcs;
-      ((DCI6_1B_10MHz_t *)dci_pdu)->rep          = (rel13->pdsch_reptition_levels-1);
-      ((DCI6_1B_10MHz_t *)dci_pdu)->harq_pid     = rel13->harq_process;
-      ((DCI6_1B_10MHz_t *)dci_pdu)->ndi          = rel13->new_data_indicator;
-      ((DCI6_1B_10MHz_t *)dci_pdu)->harq_ack_off = rel13->harq_resource_offset;
-      ((DCI6_1B_10MHz_t *)dci_pdu)->dci_rep      = rel13->dci_subframe_repetition_number-1;
-      ((DCI6_1B_10MHz_t *)dci_pdu)->padding      = 0;
+      dci_alloc->dci_length = sizeof_DCI6_1B_10MHz_t;
+      ((DCI6_1B_10MHz_t *) dci_pdu)->type = 1;
+      ((DCI6_1B_10MHz_t *) dci_pdu)->rballoc = rel13->resource_block_coding;
+      ((DCI6_1B_10MHz_t *) dci_pdu)->mcs = rel13->mcs;
+      ((DCI6_1B_10MHz_t *) dci_pdu)->rep = rel13->pdsch_reptition_levels;
+      ((DCI6_1B_10MHz_t *) dci_pdu)->harq_pid = rel13->harq_process;
+      ((DCI6_1B_10MHz_t *) dci_pdu)->ndi = rel13->new_data_indicator;
+      ((DCI6_1B_10MHz_t *) dci_pdu)->harq_ack_off = rel13->harq_resource_offset;
+      ((DCI6_1B_10MHz_t *) dci_pdu)->dci_rep = rel13->dci_subframe_repetition_number;
       break;
     case 100:
-      dci_alloc->dci_length                      = sizeof_DCI6_1B_20MHz_t; 
-      ((DCI6_1B_20MHz_t *)dci_pdu)->type         = 1;
-      ((DCI6_1B_20MHz_t *)dci_pdu)->rballoc      = rel13->resource_block_coding;
-      ((DCI6_1B_20MHz_t *)dci_pdu)->mcs          = rel13->mcs;
-      ((DCI6_1B_20MHz_t *)dci_pdu)->rep          = (rel13->pdsch_reptition_levels-1);
-      ((DCI6_1B_20MHz_t *)dci_pdu)->harq_pid     = rel13->harq_process;
-      ((DCI6_1B_20MHz_t *)dci_pdu)->ndi          = rel13->new_data_indicator;
-      ((DCI6_1B_20MHz_t *)dci_pdu)->harq_ack_off = rel13->harq_resource_offset;
-      ((DCI6_1B_20MHz_t *)dci_pdu)->dci_rep      = rel13->dci_subframe_repetition_number-1;
-      ((DCI6_1B_20MHz_t *)dci_pdu)->padding      = 0;
+      dci_alloc->dci_length = sizeof_DCI6_1B_20MHz_t;
+      ((DCI6_1B_20MHz_t *) dci_pdu)->type = 1;
+      ((DCI6_1B_20MHz_t *) dci_pdu)->rballoc = rel13->resource_block_coding;
+      ((DCI6_1B_20MHz_t *) dci_pdu)->mcs = rel13->mcs;
+      ((DCI6_1B_20MHz_t *) dci_pdu)->rep = rel13->pdsch_reptition_levels;
+      ((DCI6_1B_20MHz_t *) dci_pdu)->harq_pid = rel13->harq_process;
+      ((DCI6_1B_20MHz_t *) dci_pdu)->ndi = rel13->new_data_indicator;
+      ((DCI6_1B_20MHz_t *) dci_pdu)->harq_ack_off = rel13->harq_resource_offset;
+      ((DCI6_1B_20MHz_t *) dci_pdu)->dci_rep = rel13->dci_subframe_repetition_number;
       break;
     }
-  case 12: // Format 6-2
-    dci_alloc->format     = format6_2;
-#ifdef PHY_TX_THREAD
-    dlsch0->active[subframe]       = 1;
-#else
-    dlsch0->active       = 1;
-#endif
+  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; 
-      if (rel13->paging_direct_indication_differentiation_flag==0) {
-	((DCI6_2_di_5MHz_t *)dci_pdu)->type    = 0;
-	((DCI6_2_di_5MHz_t *)dci_pdu)->di_info = rel13->direct_indication;
-	((DCI6_2_di_5MHz_t *)dci_pdu)->padding = 0;
-      }
-      else {
-	((DCI6_2_paging_5MHz_t *)dci_pdu)->type    = 1;
-	((DCI6_2_paging_5MHz_t *)dci_pdu)->rballoc = rel13->resource_block_coding;
-	((DCI6_2_paging_5MHz_t *)dci_pdu)->mcs     = rel13->mcs;
-	((DCI6_2_paging_5MHz_t *)dci_pdu)->rep     = (rel13->pdsch_reptition_levels-1);
-	((DCI6_2_paging_5MHz_t *)dci_pdu)->dci_rep = rel13->dci_subframe_repetition_number-1;
-	((DCI6_2_paging_5MHz_t *)dci_pdu)->padding = 0;
+      dci_alloc->dci_length = sizeof_DCI6_2_5MHz_t;
+      if (rel13->paging_direct_indication_differentiation_flag == 0) {
+        ((DCI6_2_di_5MHz_t *) dci_pdu)->type = 0;
+        ((DCI6_2_di_5MHz_t *) dci_pdu)->di_info = rel13->direct_indication;
+      } else {
+        ((DCI6_2_paging_5MHz_t *) dci_pdu)->type = 1;
+        ((DCI6_2_paging_5MHz_t *) dci_pdu)->rballoc = rel13->resource_block_coding;
+        ((DCI6_2_paging_5MHz_t *) dci_pdu)->mcs = rel13->mcs;
+        ((DCI6_2_paging_5MHz_t *) dci_pdu)->rep = rel13->pdsch_reptition_levels;
+        ((DCI6_2_paging_5MHz_t *) dci_pdu)->dci_rep = rel13->dci_subframe_repetition_number;
       }
 
-    break;
+      break;
     case 50:
-      dci_alloc->dci_length                 = sizeof_DCI6_2_10MHz_t; 
-      if (rel13->paging_direct_indication_differentiation_flag==0) {
-	((DCI6_2_di_10MHz_t *)dci_pdu)->type    = 0;
-	((DCI6_2_di_10MHz_t *)dci_pdu)->di_info = rel13->direct_indication;
-	((DCI6_2_di_10MHz_t *)dci_pdu)->padding = 0;
-      }
-      else {
-	((DCI6_2_paging_10MHz_t *)dci_pdu)->type    = 1;
-	((DCI6_2_paging_10MHz_t *)dci_pdu)->rballoc = rel13->resource_block_coding;
-	((DCI6_2_paging_10MHz_t *)dci_pdu)->mcs     = rel13->mcs;
-	((DCI6_2_paging_10MHz_t *)dci_pdu)->rep     = (rel13->pdsch_reptition_levels-1);
-	((DCI6_2_paging_10MHz_t *)dci_pdu)->dci_rep = rel13->dci_subframe_repetition_number-1;
-	((DCI6_2_paging_10MHz_t *)dci_pdu)->padding = 0;
+
+      dci_alloc->dci_length = sizeof_DCI6_2_10MHz_t;
+      if (rel13->paging_direct_indication_differentiation_flag == 0) {
+        ((DCI6_2_di_10MHz_t *) dci_pdu)->type = 0;
+        ((DCI6_2_di_10MHz_t *) dci_pdu)->di_info = rel13->direct_indication;
+      } else {
+        ((DCI6_2_paging_10MHz_t *) dci_pdu)->type = 1;
+        ((DCI6_2_paging_10MHz_t *) dci_pdu)->rballoc = rel13->resource_block_coding;
+        ((DCI6_2_paging_10MHz_t *) dci_pdu)->mcs = rel13->mcs;
+        ((DCI6_2_paging_10MHz_t *) dci_pdu)->rep = rel13->pdsch_reptition_levels;
+        ((DCI6_2_paging_10MHz_t *) dci_pdu)->dci_rep = rel13->dci_subframe_repetition_number;
       }
 
-    break;
+      break;
     case 100:
-      dci_alloc->dci_length                 = sizeof_DCI6_2_20MHz_t; 
-      if (rel13->paging_direct_indication_differentiation_flag==0) {
-	((DCI6_2_di_20MHz_t *)dci_pdu)->type    = 0;
-	((DCI6_2_di_20MHz_t *)dci_pdu)->di_info = rel13->direct_indication;
-	((DCI6_2_di_20MHz_t *)dci_pdu)->padding = 0;
-      }
-      else {
-	((DCI6_2_paging_20MHz_t *)dci_pdu)->type    = 1;
-	((DCI6_2_paging_20MHz_t *)dci_pdu)->rballoc = rel13->resource_block_coding;
-	((DCI6_2_paging_20MHz_t *)dci_pdu)->mcs     = rel13->mcs;
-	((DCI6_2_paging_20MHz_t *)dci_pdu)->rep     = (rel13->pdsch_reptition_levels-1);
-	((DCI6_2_paging_20MHz_t *)dci_pdu)->dci_rep = rel13->dci_subframe_repetition_number-1;
-	((DCI6_2_paging_20MHz_t *)dci_pdu)->padding = 0;
+      dci_alloc->dci_length = sizeof_DCI6_2_20MHz_t;
+      if (rel13->paging_direct_indication_differentiation_flag == 0) {
+        ((DCI6_2_di_20MHz_t *) dci_pdu)->type = 0;
+        ((DCI6_2_di_20MHz_t *) dci_pdu)->di_info = rel13->direct_indication;
+      } else {
+        ((DCI6_2_paging_20MHz_t *) dci_pdu)->type = 1;
+        ((DCI6_2_paging_20MHz_t *) dci_pdu)->rballoc = rel13->resource_block_coding;
+        ((DCI6_2_paging_20MHz_t *) dci_pdu)->mcs = rel13->mcs;
+        ((DCI6_2_paging_20MHz_t *) dci_pdu)->rep = rel13->pdsch_reptition_levels;
+        ((DCI6_2_paging_20MHz_t *) dci_pdu)->dci_rep = rel13->dci_subframe_repetition_number;
       }
 
       break;
     }
   }
-  AssertFatal(rel13->harq_process<8,
-	      "ERROR: Format 6_1A: harq_pid=%d >= 8\n", rel13->harq_process);
-  
+  AssertFatal (rel13->harq_process < 8, "ERROR: Format 6_1A: harq_pid=%d >= 8\n", rel13->harq_process);
+
   dlsch0_harq = dlsch0->harq_processes[rel13->harq_process];
-  dlsch0_harq->codeword=0;
-  
+  dlsch0_harq->codeword = 0;
+
   // printf("DCI: Setting subframe_tx for subframe %d\n",subframe);
-  dlsch0->subframe_tx[subframe] = 1;
-  
-  conv_eMTC_rballoc(rel13->resource_block_coding,
-		    fp->N_RB_DL,
-		    dlsch0_harq->rb_alloc);
-  
-  dlsch0_harq->nb_rb = RIV2nb_rb_LUT6[rel13->resource_block_coding&31]; // this is the 6PRB RIV
-  
-  
-  dlsch0_harq->rvidx       = rel13->redundancy_version;
-  
-  dlsch0_harq->Nl          = 1;
+  dlsch0->subframe_tx[(subframe + 2) % 10] = 1;
+  LOG_I(PHY,"PDSCH : resource_block_coding %x\n",rel13->resource_block_coding);
+
+  conv_eMTC_rballoc (rel13->resource_block_coding,
+		     fp->N_RB_DL,
+		     dlsch0_harq->rb_alloc);
+
+  dlsch0_harq->nb_rb = RIV2nb_rb_LUT6[rel13->resource_block_coding & 31];       // this is the 6PRB RIV
+
+
+  dlsch0_harq->rvidx = rel13->redundancy_version;
+
+  dlsch0_harq->Nl = 1;
   //    dlsch[0]->layer_index = 0;
   //  if (beamforming_mode == 0)
   dlsch0_harq->mimo_mode = (fp->nb_antenna_ports_eNB == 1) ? SISO : ALAMOUTI;
-    //else if (beamforming_mode == 7)
-    //  dlsch0_harq->mimo_mode = TM7;
-    //else
-    //LOG_E(PHY,"Invalid beamforming mode %dL\n", beamforming_mode);
-  
+  //else if (beamforming_mode == 7)
+  //  dlsch0_harq->mimo_mode = TM7;
+  //else
+  //LOG_E(PHY,"Invalid beamforming mode %dL\n", beamforming_mode);
+
   dlsch0_harq->dl_power_off = 1;
 
-#ifdef PHY_TX_THREAD
-  dlsch0->active[subframe] = 1;
-#else
-  dlsch0->active = 1;
-#endif
-  dlsch0->harq_mask                         |= (1<<rel13->harq_process);  
-  
-  
+  dlsch0->subframe_tx[subframe] = 1;
+  if (dlsch0->rnti != rel13->rnti) {     // if rnti of dlsch is not the same as in the config, this is a new entry
+    dlsch0_harq->round = 0;
+    dlsch0->harq_mask =0;
+  }
+  if ((dlsch0->harq_mask & (1 << rel13->harq_process)) > 0) {
+    if ((rel13->new_data_indicator != dlsch0_harq->ndi)||(dci_alloc->ra_flag==1))
+      dlsch0_harq->round = 0;
+  } else {                      // process is inactive, so activate and set round to 0
+    dlsch0_harq->round = 0;
+  }
+  dlsch0_harq->ndi = rel13->new_data_indicator;
+
   if (dlsch0_harq->round == 0) {
     dlsch0_harq->status = ACTIVE;
-    //            printf("Setting DLSCH process %d to ACTIVE\n",rel8->harq_process);
-    // MCS and TBS don't change across HARQ rounds
-    dlsch0_harq->mcs         = rel13->mcs;
-    dlsch0_harq->TBS         = TBStable[get_I_TBS(dlsch0_harq->mcs)][dlsch0_harq->nb_rb-1];
-    
+    dlsch0_harq->mcs = rel13->mcs;
+    if (dci_alloc->ra_flag == 0) // get TBS from table using mcs and nb_rb
+      dlsch0_harq->TBS         = TBStable[get_I_TBS(dlsch0_harq->mcs)][dlsch0_harq->nb_rb-1];
+    else if (rel13->tpc == 0)  //N1A_PRB=2, get TBS from table using mcs and nb_rb=2
+      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);
   }
-  
-  dlsch0->harq_ids[frame%2][subframe] = rel13->harq_process;
-  
-  
-  
-  dlsch0->rnti = rel13->rnti;
+  dlsch0->active = 1;
+  dlsch0->harq_mask |= (1 << rel13->harq_process);
+
+  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;
+  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);
+
+  dlsch0->rnti = rel13->rnti;
+
+  dlsch0_harq->Qm = get_Qm(rel13->mcs);
 
 
 
@@ -1770,22 +1792,22 @@ void fill_mdci_and_dlsch(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,mDCI_ALLOC_t *d
 
 }
 
-void fill_dci0(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t *proc,
+void fill_dci0(PHY_VARS_eNB *eNB,int frame,int subframe,L1_rxtx_proc_t *proc,
     DCI_ALLOC_t *dci_alloc,nfapi_hi_dci0_dci_pdu *pdu)
 {
   LTE_DL_FRAME_PARMS *frame_parms = &eNB->frame_parms;
 
-  uint32_t cqi_req = pdu->dci_pdu_rel8.cqi_csi_request;
-  uint32_t dai     = pdu->dci_pdu_rel8.dl_assignment_index;
-  uint32_t cshift  = pdu->dci_pdu_rel8.cyclic_shift_2_for_drms;
-  uint32_t TPC     = pdu->dci_pdu_rel8.tpc;
-  uint32_t mcs     = pdu->dci_pdu_rel8.mcs_1;
-  uint32_t hopping = pdu->dci_pdu_rel8.frequency_hopping_enabled_flag;
-  uint32_t rballoc = computeRIV(frame_parms->N_RB_DL,
-				pdu->dci_pdu_rel8.resource_block_start,
-				pdu->dci_pdu_rel8.number_of_resource_block);
+  uint32_t        cqi_req = pdu->dci_pdu_rel8.cqi_csi_request;
+  uint32_t        dai = pdu->dci_pdu_rel8.dl_assignment_index;
+  uint32_t        cshift = pdu->dci_pdu_rel8.cyclic_shift_2_for_drms;
+  uint32_t        TPC = pdu->dci_pdu_rel8.tpc;
+  uint32_t        mcs = pdu->dci_pdu_rel8.mcs_1;
+  uint32_t        hopping = pdu->dci_pdu_rel8.frequency_hopping_enabled_flag;
+  uint32_t        rballoc = computeRIV (frame_parms->N_RB_DL,
+                                        pdu->dci_pdu_rel8.resource_block_start,
+                                        pdu->dci_pdu_rel8.number_of_resource_block);
 
-  uint32_t ndi     = pdu->dci_pdu_rel8.new_data_indication_1;
+  uint32_t        ndi = pdu->dci_pdu_rel8.new_data_indication_1;
 
   uint16_t UE_id   = -1;
 
@@ -1800,7 +1822,7 @@ void fill_dci0(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t *proc,
     T_INT(pdu->dci_pdu_rel8.cce_index));
 #endif
 
-  void *dci_pdu = (void*)dci_alloc->dci_pdu;
+  void           *dci_pdu = (void *) dci_alloc->dci_pdu;
 
   LOG_D(PHY,"SFN/SF:%04d%d DCI0[rnti %x cqi %d mcs %d hopping %d rballoc %x (%d,%d) ndi %d TPC %d cshift %d]\n",
         frame,subframe,
@@ -1808,129 +1830,129 @@ void fill_dci0(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t *proc,
         pdu->dci_pdu_rel8.resource_block_start,
         pdu->dci_pdu_rel8.number_of_resource_block, ndi,TPC,cshift);
 
-  dci_alloc->format   = format0;
+  dci_alloc->format = format0;
   dci_alloc->firstCCE = pdu->dci_pdu_rel8.cce_index;
-  dci_alloc->L        = pdu->dci_pdu_rel8.aggregation_level;
-  dci_alloc->rnti     = pdu->dci_pdu_rel8.rnti;
-  dci_alloc->ra_flag  = 0;
+  dci_alloc->L = pdu->dci_pdu_rel8.aggregation_level;
+  dci_alloc->rnti = pdu->dci_pdu_rel8.rnti;
+  dci_alloc->ra_flag = 0;
 
   switch (frame_parms->N_RB_DL) {
   case 6:
     if (frame_parms->frame_type == TDD) {
-      ((DCI0_1_5MHz_TDD_1_6_t *)dci_pdu)->cqi_req = cqi_req;
-      ((DCI0_1_5MHz_TDD_1_6_t *)dci_pdu)->dai     = dai;
-      ((DCI0_1_5MHz_TDD_1_6_t *)dci_pdu)->cshift  = cshift;
-      ((DCI0_1_5MHz_TDD_1_6_t *)dci_pdu)->TPC     = TPC;
-      ((DCI0_1_5MHz_TDD_1_6_t *)dci_pdu)->mcs     = mcs;
-      ((DCI0_1_5MHz_TDD_1_6_t *)dci_pdu)->ndi     = ndi;
-      ((DCI0_1_5MHz_TDD_1_6_t *)dci_pdu)->rballoc = rballoc;
-      ((DCI0_1_5MHz_TDD_1_6_t *)dci_pdu)->hopping = hopping;
-      ((DCI0_1_5MHz_TDD_1_6_t *)dci_pdu)->type    = 0;
-      ((DCI0_1_5MHz_TDD_1_6_t *)dci_pdu)->padding = 0;
-      dci_alloc->dci_length                       = sizeof_DCI0_1_5MHz_TDD_1_6_t; 
+      ((DCI0_1_5MHz_TDD_1_6_t *) dci_pdu)->cqi_req = cqi_req;
+      ((DCI0_1_5MHz_TDD_1_6_t *) dci_pdu)->dai = dai;
+      ((DCI0_1_5MHz_TDD_1_6_t *) dci_pdu)->cshift = cshift;
+      ((DCI0_1_5MHz_TDD_1_6_t *) dci_pdu)->TPC = TPC;
+      ((DCI0_1_5MHz_TDD_1_6_t *) dci_pdu)->mcs = mcs;
+      ((DCI0_1_5MHz_TDD_1_6_t *) dci_pdu)->ndi = ndi;
+      ((DCI0_1_5MHz_TDD_1_6_t *) dci_pdu)->rballoc = rballoc;
+      ((DCI0_1_5MHz_TDD_1_6_t *) dci_pdu)->hopping = hopping;
+      ((DCI0_1_5MHz_TDD_1_6_t *) dci_pdu)->type = 0;
+      ((DCI0_1_5MHz_TDD_1_6_t *) dci_pdu)->padding = 0;
+      dci_alloc->dci_length = sizeof_DCI0_1_5MHz_TDD_1_6_t;
     } else {
-      ((DCI0_1_5MHz_FDD_t *)dci_pdu)->cqi_req     = cqi_req;
-      ((DCI0_1_5MHz_FDD_t *)dci_pdu)->cshift      = cshift;
-      ((DCI0_1_5MHz_FDD_t *)dci_pdu)->TPC         = TPC;
-      ((DCI0_1_5MHz_FDD_t *)dci_pdu)->mcs         = mcs;
-      ((DCI0_1_5MHz_FDD_t *)dci_pdu)->ndi         = ndi;
-      ((DCI0_1_5MHz_FDD_t *)dci_pdu)->rballoc     = rballoc;
-      ((DCI0_1_5MHz_FDD_t *)dci_pdu)->hopping     = hopping;
-      ((DCI0_1_5MHz_FDD_t *)dci_pdu)->type        = 0;
-      ((DCI0_1_5MHz_FDD_t *)dci_pdu)->padding     = 0;
-      dci_alloc->dci_length                       = sizeof_DCI0_1_5MHz_FDD_t; 
+      ((DCI0_1_5MHz_FDD_t *) dci_pdu)->cqi_req = cqi_req;
+      ((DCI0_1_5MHz_FDD_t *) dci_pdu)->cshift = cshift;
+      ((DCI0_1_5MHz_FDD_t *) dci_pdu)->TPC = TPC;
+      ((DCI0_1_5MHz_FDD_t *) dci_pdu)->mcs = mcs;
+      ((DCI0_1_5MHz_FDD_t *) dci_pdu)->ndi = ndi;
+      ((DCI0_1_5MHz_FDD_t *) dci_pdu)->rballoc = rballoc;
+      ((DCI0_1_5MHz_FDD_t *) dci_pdu)->hopping = hopping;
+      ((DCI0_1_5MHz_FDD_t *) dci_pdu)->type = 0;
+      ((DCI0_1_5MHz_FDD_t *) dci_pdu)->padding = 0;
+      dci_alloc->dci_length = sizeof_DCI0_1_5MHz_FDD_t;
     }
-    
+
     break;
-    
+
   case 25:
     if (frame_parms->frame_type == TDD) {
-      ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->cqi_req = cqi_req;
-      ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->dai     = dai;
-      ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->cshift  = cshift;
-      ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->TPC     = TPC;
-      ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->mcs     = mcs;
-      ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->ndi     = ndi;
-      ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->rballoc = rballoc;
-      ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->hopping = hopping;
-      ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->type    = 0;
-      ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->padding = 0;
-      dci_alloc->dci_length                     = sizeof_DCI0_5MHz_TDD_1_6_t; 
+      ((DCI0_5MHz_TDD_1_6_t *) dci_pdu)->cqi_req = cqi_req;
+      ((DCI0_5MHz_TDD_1_6_t *) dci_pdu)->dai = dai;
+      ((DCI0_5MHz_TDD_1_6_t *) dci_pdu)->cshift = cshift;
+      ((DCI0_5MHz_TDD_1_6_t *) dci_pdu)->TPC = TPC;
+      ((DCI0_5MHz_TDD_1_6_t *) dci_pdu)->mcs = mcs;
+      ((DCI0_5MHz_TDD_1_6_t *) dci_pdu)->ndi = ndi;
+      ((DCI0_5MHz_TDD_1_6_t *) dci_pdu)->rballoc = rballoc;
+      ((DCI0_5MHz_TDD_1_6_t *) dci_pdu)->hopping = hopping;
+      ((DCI0_5MHz_TDD_1_6_t *) dci_pdu)->type = 0;
+      ((DCI0_5MHz_TDD_1_6_t *) dci_pdu)->padding = 0;
+      dci_alloc->dci_length = sizeof_DCI0_5MHz_TDD_1_6_t;
     } else {
-      ((DCI0_5MHz_FDD_t *)dci_pdu)->cqi_req     = cqi_req;
-      ((DCI0_5MHz_FDD_t *)dci_pdu)->cshift      = cshift;
-      ((DCI0_5MHz_FDD_t *)dci_pdu)->TPC         = TPC;
-      ((DCI0_5MHz_FDD_t *)dci_pdu)->mcs         = mcs;
-      ((DCI0_5MHz_FDD_t *)dci_pdu)->ndi         = ndi;
-      ((DCI0_5MHz_FDD_t *)dci_pdu)->rballoc     = rballoc;
-      ((DCI0_5MHz_FDD_t *)dci_pdu)->hopping     = hopping;
-      ((DCI0_5MHz_FDD_t *)dci_pdu)->type        = 0;
-      ((DCI0_5MHz_FDD_t *)dci_pdu)->padding     = 0;
-      dci_alloc->dci_length                     = sizeof_DCI0_5MHz_FDD_t; 
+      ((DCI0_5MHz_FDD_t *) dci_pdu)->cqi_req = cqi_req;
+      ((DCI0_5MHz_FDD_t *) dci_pdu)->cshift = cshift;
+      ((DCI0_5MHz_FDD_t *) dci_pdu)->TPC = TPC;
+      ((DCI0_5MHz_FDD_t *) dci_pdu)->mcs = mcs;
+      ((DCI0_5MHz_FDD_t *) dci_pdu)->ndi = ndi;
+      ((DCI0_5MHz_FDD_t *) dci_pdu)->rballoc = rballoc;
+      ((DCI0_5MHz_FDD_t *) dci_pdu)->hopping = hopping;
+      ((DCI0_5MHz_FDD_t *) dci_pdu)->type = 0;
+      ((DCI0_5MHz_FDD_t *) dci_pdu)->padding = 0;
+      dci_alloc->dci_length = sizeof_DCI0_5MHz_FDD_t;
     }
-    
+
     break;
-    
+
   case 50:
     if (frame_parms->frame_type == TDD) {
-      ((DCI0_10MHz_TDD_1_6_t *)dci_pdu)->cqi_req = cqi_req;
-      ((DCI0_10MHz_TDD_1_6_t *)dci_pdu)->dai     = dai;
-      ((DCI0_10MHz_TDD_1_6_t *)dci_pdu)->cshift  = cshift;
-      ((DCI0_10MHz_TDD_1_6_t *)dci_pdu)->TPC     = TPC;
-      ((DCI0_10MHz_TDD_1_6_t *)dci_pdu)->mcs     = mcs;
-      ((DCI0_10MHz_TDD_1_6_t *)dci_pdu)->ndi     = ndi;
-      ((DCI0_10MHz_TDD_1_6_t *)dci_pdu)->rballoc = rballoc;
-      ((DCI0_10MHz_TDD_1_6_t *)dci_pdu)->hopping = hopping;
-      ((DCI0_10MHz_TDD_1_6_t *)dci_pdu)->type    = 0;
-      ((DCI0_10MHz_TDD_1_6_t *)dci_pdu)->padding = 0;
-      dci_alloc->dci_length                      = sizeof_DCI0_10MHz_TDD_1_6_t; 
+      ((DCI0_10MHz_TDD_1_6_t *) dci_pdu)->cqi_req = cqi_req;
+      ((DCI0_10MHz_TDD_1_6_t *) dci_pdu)->dai = dai;
+      ((DCI0_10MHz_TDD_1_6_t *) dci_pdu)->cshift = cshift;
+      ((DCI0_10MHz_TDD_1_6_t *) dci_pdu)->TPC = TPC;
+      ((DCI0_10MHz_TDD_1_6_t *) dci_pdu)->mcs = mcs;
+      ((DCI0_10MHz_TDD_1_6_t *) dci_pdu)->ndi = ndi;
+      ((DCI0_10MHz_TDD_1_6_t *) dci_pdu)->rballoc = rballoc;
+      ((DCI0_10MHz_TDD_1_6_t *) dci_pdu)->hopping = hopping;
+      ((DCI0_10MHz_TDD_1_6_t *) dci_pdu)->type = 0;
+      ((DCI0_10MHz_TDD_1_6_t *) dci_pdu)->padding = 0;
+      dci_alloc->dci_length = sizeof_DCI0_10MHz_TDD_1_6_t;
     } else {
-      ((DCI0_10MHz_FDD_t *)dci_pdu)->cqi_req     = cqi_req;
-      ((DCI0_10MHz_FDD_t *)dci_pdu)->cshift      = cshift;
-      ((DCI0_10MHz_FDD_t *)dci_pdu)->TPC         = TPC;
-      ((DCI0_10MHz_FDD_t *)dci_pdu)->mcs         = mcs;
-      ((DCI0_10MHz_FDD_t *)dci_pdu)->ndi         = ndi;
-      ((DCI0_10MHz_FDD_t *)dci_pdu)->rballoc     = rballoc;
-      ((DCI0_10MHz_FDD_t *)dci_pdu)->hopping     = hopping;
-      ((DCI0_10MHz_FDD_t *)dci_pdu)->type        = 0;
-      ((DCI0_10MHz_FDD_t *)dci_pdu)->padding     = 0;
-      dci_alloc->dci_length                      = sizeof_DCI0_10MHz_FDD_t; 
+      ((DCI0_10MHz_FDD_t *) dci_pdu)->cqi_req = cqi_req;
+      ((DCI0_10MHz_FDD_t *) dci_pdu)->cshift = cshift;
+      ((DCI0_10MHz_FDD_t *) dci_pdu)->TPC = TPC;
+      ((DCI0_10MHz_FDD_t *) dci_pdu)->mcs = mcs;
+      ((DCI0_10MHz_FDD_t *) dci_pdu)->ndi = ndi;
+      ((DCI0_10MHz_FDD_t *) dci_pdu)->rballoc = rballoc;
+      ((DCI0_10MHz_FDD_t *) dci_pdu)->hopping = hopping;
+      ((DCI0_10MHz_FDD_t *) dci_pdu)->type = 0;
+      ((DCI0_10MHz_FDD_t *) dci_pdu)->padding = 0;
+      dci_alloc->dci_length = sizeof_DCI0_10MHz_FDD_t;
     }
-    
+
     break;
-    
+
   case 100:
     if (frame_parms->frame_type == TDD) {
-      ((DCI0_20MHz_TDD_1_6_t *)dci_pdu)->cqi_req = cqi_req;
-      ((DCI0_20MHz_TDD_1_6_t *)dci_pdu)->dai     = dai;
-      ((DCI0_20MHz_TDD_1_6_t *)dci_pdu)->cshift  = cshift;
-      ((DCI0_20MHz_TDD_1_6_t *)dci_pdu)->TPC     = TPC;
-      ((DCI0_20MHz_TDD_1_6_t *)dci_pdu)->mcs     = mcs;
-      ((DCI0_20MHz_TDD_1_6_t *)dci_pdu)->ndi     = ndi;
-      ((DCI0_20MHz_TDD_1_6_t *)dci_pdu)->rballoc = rballoc;
-      ((DCI0_20MHz_TDD_1_6_t *)dci_pdu)->hopping = hopping;
-      ((DCI0_20MHz_TDD_1_6_t *)dci_pdu)->type    = 0;
-      ((DCI0_20MHz_TDD_1_6_t *)dci_pdu)->padding = 0;
-
-      dci_alloc->dci_length                      = sizeof_DCI0_20MHz_TDD_1_6_t; 
+      ((DCI0_20MHz_TDD_1_6_t *) dci_pdu)->cqi_req = cqi_req;
+      ((DCI0_20MHz_TDD_1_6_t *) dci_pdu)->dai = dai;
+      ((DCI0_20MHz_TDD_1_6_t *) dci_pdu)->cshift = cshift;
+      ((DCI0_20MHz_TDD_1_6_t *) dci_pdu)->TPC = TPC;
+      ((DCI0_20MHz_TDD_1_6_t *) dci_pdu)->mcs = mcs;
+      ((DCI0_20MHz_TDD_1_6_t *) dci_pdu)->ndi = ndi;
+      ((DCI0_20MHz_TDD_1_6_t *) dci_pdu)->rballoc = rballoc;
+      ((DCI0_20MHz_TDD_1_6_t *) dci_pdu)->hopping = hopping;
+      ((DCI0_20MHz_TDD_1_6_t *) dci_pdu)->type = 0;
+      ((DCI0_20MHz_TDD_1_6_t *) dci_pdu)->padding = 0;
+
+      dci_alloc->dci_length = sizeof_DCI0_20MHz_TDD_1_6_t;
     } else {
-      ((DCI0_20MHz_FDD_t *)dci_pdu)->cqi_req     = cqi_req;
-      ((DCI0_20MHz_FDD_t *)dci_pdu)->cshift      = cshift;
-      ((DCI0_20MHz_FDD_t *)dci_pdu)->TPC         = TPC;
-      ((DCI0_20MHz_FDD_t *)dci_pdu)->mcs         = mcs;
-      ((DCI0_20MHz_FDD_t *)dci_pdu)->ndi         = ndi;
-      ((DCI0_20MHz_FDD_t *)dci_pdu)->rballoc     = rballoc;
-      ((DCI0_20MHz_FDD_t *)dci_pdu)->hopping     = hopping;
-      ((DCI0_20MHz_FDD_t *)dci_pdu)->type        = 0;
-      ((DCI0_20MHz_FDD_t *)dci_pdu)->padding     = 0;
-      dci_alloc->dci_length                      = sizeof_DCI0_20MHz_FDD_t; 
+      ((DCI0_20MHz_FDD_t *) dci_pdu)->cqi_req = cqi_req;
+      ((DCI0_20MHz_FDD_t *) dci_pdu)->cshift = cshift;
+      ((DCI0_20MHz_FDD_t *) dci_pdu)->TPC = TPC;
+      ((DCI0_20MHz_FDD_t *) dci_pdu)->mcs = mcs;
+      ((DCI0_20MHz_FDD_t *) dci_pdu)->ndi = ndi;
+      ((DCI0_20MHz_FDD_t *) dci_pdu)->rballoc = rballoc;
+      ((DCI0_20MHz_FDD_t *) dci_pdu)->hopping = hopping;
+      ((DCI0_20MHz_FDD_t *) dci_pdu)->type = 0;
+      ((DCI0_20MHz_FDD_t *) dci_pdu)->padding = 0;
+      dci_alloc->dci_length = sizeof_DCI0_20MHz_FDD_t;
     }
-    
-      //printf("eNB: rb_alloc (20 MHz dci) %d\n",rballoc);
-      break;
-      
+
+    //printf("eNB: rb_alloc (20 MHz dci) %d\n",rballoc);
+    break;
+
   default:
-    LOG_E(PHY,"Invalid N_RB_DL %d\n", frame_parms->N_RB_DL);
+    LOG_E (PHY, "Invalid N_RB_DL %d\n", frame_parms->N_RB_DL);
     DevParam (frame_parms->N_RB_DL, 0, 0);
     break;
   }
@@ -1943,6 +1965,33 @@ void fill_dci0(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t *proc,
   }
 }
 
+
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+int get_narrowband_index(int N_RB_UL,int rb) {
+
+  switch (N_RB_UL) {
+  case 6: // 6 PRBs, N_NB=1, i_0=0
+  case 25: // 25 PRBs, N_NB=4, i_0=0
+    return(rb/6);
+    break;
+  case 50: // 50 PRBs, N_NB=8, i_0=1
+  case 75: // 75 PRBs, N_NB=12, i_0=1
+  case 15: // 15 PRBs, N_NB=2, i_0=1
+    AssertFatal(rb>=1,"rb %d is not possible for %d PRBs\n",rb,N_RB_UL);
+    return((rb-1)/6);
+    break;
+  case 100: // 100 PRBs, N_NB=16, i_0=2
+    AssertFatal(rb>=2,"rb %d is not possible for %d PRBs\n",rb,N_RB_UL);
+    return(rb-2/6);
+    break;
+  default:
+    AssertFatal(1==0,"Impossible N_RB_UL %d\n",N_RB_UL);
+    break;
+  }
+
+}
+#endif
+
 void fill_ulsch(PHY_VARS_eNB *eNB,int UE_id,nfapi_ul_config_ulsch_pdu *ulsch_pdu,int frame,int subframe)
 {
   uint8_t harq_pid;
@@ -1961,6 +2010,20 @@ 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))
+  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");
+
+
+#else
+  ulsch->ue_type = 0;
+#endif
+
+  //AssertFatal(ulsch->harq_processes[harq_pid]->nb_rb>0,"nb_rb = 0\n");
+  if(ulsch->harq_processes[harq_pid]->nb_rb == 0){
+    LOG_E(PHY, "fill_ulsch UE_id %d nb_rb = 0\n", UE_id);
+  }
+
   ulsch->harq_processes[harq_pid]->frame                                 = frame;
   ulsch->harq_processes[harq_pid]->subframe                              = subframe;
   ulsch->harq_processes[harq_pid]->handled                               = 0;
@@ -1968,10 +2031,6 @@ void fill_ulsch(PHY_VARS_eNB *eNB,int UE_id,nfapi_ul_config_ulsch_pdu *ulsch_pdu
   ulsch->harq_processes[harq_pid]->first_rb                              = ulsch_pdu->ulsch_pdu_rel8.resource_block_start;
   ulsch->harq_processes[harq_pid]->nb_rb                                 = ulsch_pdu->ulsch_pdu_rel8.number_of_resource_blocks;
 
-  //AssertFatal(ulsch->harq_processes[harq_pid]->nb_rb>0,"nb_rb = 0\n");
-  if(ulsch->harq_processes[harq_pid]->nb_rb == 0){
-    LOG_E(PHY, "fill_ulsch UE_id %d nb_rb = 0\n", UE_id);
-  }
 
   ulsch->harq_processes[harq_pid]->dci_alloc                             = 1;
   ulsch->harq_processes[harq_pid]->rar_alloc                             = 0;
@@ -2053,3 +2112,178 @@ void fill_ulsch(PHY_VARS_eNB *eNB,int UE_id,nfapi_ul_config_ulsch_pdu *ulsch_pdu
 }
 
 
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+
+int get_first_rb_in_narrowband(int N_RB_UL,int rb) {
+
+  switch (N_RB_UL) {
+  case 6: // 6 PRBs, N_NB=1, i_0=0
+  case 25: // 25 PRBs, N_NB=4, i_0=0
+    return(rb - 6*(rb/6));
+    break;
+  case 50: // 50 PRBs, N_NB=8, i_0=1
+  case 75: // 75 PRBs, N_NB=12, i_0=1
+  case 15: // 15 PRBs, N_NB=2, i_0=1
+    AssertFatal(rb>=1,"rb %d is not possible for %d PRBs\n",rb,N_RB_UL);
+    return(rb-1-(6*((rb-1)/6)));
+    break;
+  case 100: // 100 PRBs, N_NB=16, i_0=2
+    AssertFatal(rb>=2,"rb %d is not possible for %d PRBs\n",rb,N_RB_UL);
+    return(rb-2-(6*((rb-2)/6)));
+    break;
+  default:
+    AssertFatal(1==0,"Impossible N_RB_UL %d\n",N_RB_UL);
+    break;
+  }
+}
+
+void fill_mpdcch_dci0 (PHY_VARS_eNB * eNB, L1_rxtx_proc_t * proc, mDCI_ALLOC_t * dci_alloc, nfapi_hi_dci0_mpdcch_dci_pdu * pdu)
+{
+  LTE_DL_FRAME_PARMS *frame_parms = &eNB->frame_parms;
+  nfapi_hi_dci0_mpdcch_dci_pdu_rel13_t *rel13 = &pdu->mpdcch_dci_pdu_rel13;
+
+  uint32_t        cqi_req = rel13->csi_request;
+  uint32_t        TPC = rel13->tpc;
+  uint32_t        mcs = rel13->mcs;
+  uint32_t        hopping = rel13->frequency_hopping_flag;
+  uint32_t        narrowband = get_narrowband_index(frame_parms->N_RB_UL,rel13->resource_block_start);
+  uint32_t        rballoc = computeRIV (6,
+                                        get_first_rb_in_narrowband(frame_parms->N_RB_UL,rel13->resource_block_start),
+                                        rel13->number_of_resource_blocks);
+
+  uint32_t        ndi = rel13->new_data_indication;
+
+#ifdef T_TRACER
+  T (T_ENB_PHY_ULSCH_UE_DCI, T_INT (eNB->Mod_id), T_INT (proc->frame_tx), T_INT (proc->subframe_tx),
+     T_INT (rel13->rnti), T_INT (((proc->frame_tx * 10 + proc->subframe_tx + 4) % 8) /* TODO: correct harq pid */ ),
+     T_INT (mcs), T_INT (-1 /* TODO: remove round? */ ),
+     T_INT (rel13->resource_block_start),
+     T_INT (rel13->number_of_resource_blocks),
+     T_INT (get_TBS_UL (mcs, rel13->number_of_resource_blocks) * 8), T_INT (rel13->aggreagation_level), T_INT (rel13->ecce_index));
+#endif
+
+  void           *dci_pdu = (void *) dci_alloc->dci_pdu;
+
+  AssertFatal(rel13->ce_mode == 1 && rel13->dci_format == 4, "dci format 5 (CE_modeB) not supported yet\n");
+
+
+  LOG_D (PHY, "Filling DCI6-0A with cqi %d, mcs %d, hopping %d, rballoc %x (%d,%d) ndi %d TPC %d\n", cqi_req,
+         mcs, hopping, rballoc, rel13->resource_block_start, rel13->number_of_resource_blocks, ndi, TPC);
+
+  dci_alloc->format = format6_0A;
+  dci_alloc->firstCCE = rel13->ecce_index;
+  dci_alloc->L = rel13->aggreagation_level;
+  dci_alloc->rnti = rel13->rnti;
+  dci_alloc->harq_pid = rel13->harq_process;
+  dci_alloc->narrowband = rel13->mpdcch_narrowband;
+  dci_alloc->number_of_prb_pairs = rel13->number_of_prb_pairs;
+  dci_alloc->resource_block_assignment = rel13->resource_block_assignment;
+  dci_alloc->transmission_type = rel13->mpdcch_transmission_type;
+  dci_alloc->start_symbol = rel13->start_symbol;
+  dci_alloc->ce_mode = rel13->ce_mode;
+  dci_alloc->dmrs_scrambling_init = rel13->drms_scrambling_init;
+  dci_alloc->i0 = rel13->initial_transmission_sf_io;
+
+
+  switch (frame_parms->N_RB_DL) {
+  case 6:
+    if (frame_parms->frame_type == TDD) {
+      AssertFatal(1==0,"TDD not supported for eMTC yet\n");
+    } else {
+      AssertFatal(1==0,"6 PRBS not supported for eMTC\n");
+    }
+
+    break;
+
+  case 25:
+    if (frame_parms->frame_type == TDD) {
+      AssertFatal(1==0,"TDD not supported for eMTC yet\n");
+    } else {
+      dci_alloc->dci_length = sizeof_DCI6_0A_5MHz_t;
+      ((DCI6_0A_5MHz_t *) dci_pdu)->type = 0;
+      ((DCI6_0A_5MHz_t *) dci_pdu)->hopping = hopping;
+      ((DCI6_0A_5MHz_t *) dci_pdu)->rballoc = rballoc;
+      ((DCI6_0A_5MHz_t *) dci_pdu)->narrowband = narrowband;
+      ((DCI6_0A_5MHz_t *) dci_pdu)->mcs = mcs;
+      ((DCI6_0A_5MHz_t *) dci_pdu)->rep = rel13->pusch_repetition_levels;
+      ((DCI6_0A_5MHz_t *) dci_pdu)->harq_pid = rel13->harq_process;
+      ((DCI6_0A_5MHz_t *) dci_pdu)->ndi = ndi;
+      ((DCI6_0A_5MHz_t *) dci_pdu)->rv_idx = rel13->redudency_version;
+      ((DCI6_0A_5MHz_t *) dci_pdu)->TPC = TPC;
+      ((DCI6_0A_5MHz_t *) dci_pdu)->csi_req = cqi_req;
+      ((DCI6_0A_5MHz_t *) dci_pdu)->srs_req = rel13->srs_request;
+      ((DCI6_0A_5MHz_t *) dci_pdu)->dci_rep = rel13->dci_subframe_repetition_number;
+
+    }
+
+    break;
+
+  case 50:
+    if (frame_parms->frame_type == TDD) {
+      AssertFatal(1==0,"TDD not supported for eMTC yet\n");
+    } else {
+      dci_alloc->dci_length = sizeof_DCI6_0A_10MHz_t;
+      ((DCI6_0A_10MHz_t *) dci_pdu)->type = 0;
+      ((DCI6_0A_10MHz_t *) dci_pdu)->hopping = hopping;
+      ((DCI6_0A_10MHz_t *) dci_pdu)->rballoc = rballoc;
+      ((DCI6_0A_10MHz_t *) dci_pdu)->narrowband = narrowband;
+      ((DCI6_0A_10MHz_t *) dci_pdu)->mcs = mcs;
+      ((DCI6_0A_10MHz_t *) dci_pdu)->rep = rel13->pusch_repetition_levels;
+      ((DCI6_0A_10MHz_t *) dci_pdu)->harq_pid = rel13->harq_process;
+      ((DCI6_0A_10MHz_t *) dci_pdu)->ndi = ndi;
+      ((DCI6_0A_10MHz_t *) dci_pdu)->rv_idx = rel13->redudency_version;
+      ((DCI6_0A_10MHz_t *) dci_pdu)->TPC = TPC;
+      ((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",
+	    proc->frame_tx,proc->subframe_tx,
+	    ((DCI6_0A_10MHz_t *) dci_pdu)->type,
+	    ((DCI6_0A_10MHz_t *) dci_pdu)->hopping,
+	    ((DCI6_0A_10MHz_t *) dci_pdu)->narrowband,
+	    ((DCI6_0A_10MHz_t *) dci_pdu)->rballoc,
+	    ((DCI6_0A_10MHz_t *) dci_pdu)->mcs,
+	    ((DCI6_0A_10MHz_t *) dci_pdu)->rep,
+	    ((DCI6_0A_10MHz_t *) dci_pdu)->harq_pid,
+	    ((DCI6_0A_10MHz_t *) dci_pdu)->ndi,
+	    ((DCI6_0A_10MHz_t *) dci_pdu)->rv_idx,
+	    ((DCI6_0A_10MHz_t *) dci_pdu)->TPC,
+	    ((DCI6_0A_10MHz_t *) dci_pdu)->csi_req,
+	    ((DCI6_0A_10MHz_t *) dci_pdu)->srs_req,
+	    ((DCI6_0A_10MHz_t *) dci_pdu)->dci_rep,
+	    ((uint32_t*)dci_pdu)[0]);
+
+    }
+
+    break;
+
+  case 100:
+    if (frame_parms->frame_type == TDD) {
+      AssertFatal(1==0,"TDD not supported for eMTC yet\n");
+    } else {
+      dci_alloc->dci_length = sizeof_DCI6_0A_20MHz_t;
+      ((DCI6_0A_20MHz_t *) dci_pdu)->type = 0;
+      ((DCI6_0A_20MHz_t *) dci_pdu)->hopping = hopping;
+      ((DCI6_0A_20MHz_t *) dci_pdu)->rballoc = rballoc;
+      ((DCI6_0A_20MHz_t *) dci_pdu)->narrowband = narrowband;
+      ((DCI6_0A_20MHz_t *) dci_pdu)->mcs = rel13->mcs;
+      ((DCI6_0A_20MHz_t *) dci_pdu)->rep = rel13->pusch_repetition_levels;
+      ((DCI6_0A_20MHz_t *) dci_pdu)->harq_pid = rel13->harq_process;
+      ((DCI6_0A_20MHz_t *) dci_pdu)->ndi = ndi;
+      ((DCI6_0A_20MHz_t *) dci_pdu)->rv_idx = rel13->redudency_version;
+      ((DCI6_0A_20MHz_t *) dci_pdu)->TPC = TPC;
+      ((DCI6_0A_20MHz_t *) dci_pdu)->csi_req = cqi_req;
+      ((DCI6_0A_20MHz_t *) dci_pdu)->srs_req = rel13->srs_request;
+      ((DCI6_0A_20MHz_t *) dci_pdu)->dci_rep = rel13->dci_subframe_repetition_number;
+    }
+
+    //printf("eNB: rb_alloc (20 MHz dci) %d\n",rballoc);
+    break;
+
+  default:
+    LOG_E (PHY, "Invalid N_RB_DL %d\n", frame_parms->N_RB_DL);
+    DevParam (frame_parms->N_RB_DL, 0, 0);
+    break;
+  }
+}
+#endif
diff --git a/openair1/PHY/LTE_TRANSPORT/dci_tools_common.c b/openair1/PHY/LTE_TRANSPORT/dci_tools_common.c
index b8ac3d7eb93b16bdc8ee957148d88442d56b9851..583d12eedb4a6d86f99e4ec9bbddcc4f0fc80b6e 100644
--- a/openair1/PHY/LTE_TRANSPORT/dci_tools_common.c
+++ b/openair1/PHY/LTE_TRANSPORT/dci_tools_common.c
@@ -283,29 +283,33 @@ uint16_t get_nCCE_mac(uint8_t Mod_id,uint8_t CC_id,int num_pdcch_symbols,int sub
 }
 
 
-void conv_eMTC_rballoc(uint16_t resource_block_coding,
-		       uint32_t N_RB_DL,
-		       uint32_t *rb_alloc) {
-
-
-  int narrowband = resource_block_coding>>5;
-  int RIV        = resource_block_coding&31;
-  int N_NB_DL    = N_RB_DL/6;
-  int i0         = (N_RB_DL>>1) - (3*N_NB_DL);
-  int first_rb   = (6*narrowband)+i0;
-  int alloc      = localRIV2alloc_LUT6[RIV];
-  int ind        = first_rb>>5;
-  int ind_mod    = first_rb&31;
-
-  if (((N_RB_DL&1) > 0) && (narrowband>=(N_NB_DL>>1))) first_rb++;
-  rb_alloc[0]                        = 0;
-  rb_alloc[1]                        = 0;
-  rb_alloc[2]                        = 0;
-  rb_alloc[3]                        = 0;
-  rb_alloc[ind]                      = alloc<<ind_mod;
-  if (ind_mod > 26)  rb_alloc[ind+1] = alloc>>(6-(ind_mod-26));
+void conv_eMTC_rballoc (uint16_t resource_block_coding, uint32_t N_RB_DL, uint32_t * rb_alloc)
+{
+
+
+  int             RIV = resource_block_coding&31;
+  int             narrowband = resource_block_coding>>5;
+  int             N_NB_DL = N_RB_DL / 6;
+  int             i0 = (N_RB_DL >> 1) - (3 * N_NB_DL);
+  int             first_rb = (6 * narrowband) + i0;
+  int             alloc = localRIV2alloc_LUT6[RIV];
+  int             ind = first_rb >> 5;
+  int             ind_mod = first_rb & 31;
+
+  AssertFatal(RIV<32,"RIV is %d > 31\n",RIV);
+
+  if (((N_RB_DL & 1) > 0) && (narrowband >= (N_NB_DL >> 1)))
+    first_rb++;
+  rb_alloc[0] = 0;
+  rb_alloc[1] = 0;
+  rb_alloc[2] = 0;
+  rb_alloc[3] = 0;
+  rb_alloc[ind] = alloc << ind_mod;
+  if (ind_mod > 26)
+    rb_alloc[ind + 1] = alloc >> (6 - (ind_mod - 26));
 }
 
+
 void conv_rballoc(uint8_t ra_header,uint32_t rb_alloc,uint32_t N_RB_DL,uint32_t *rb_alloc2)
 {
 
diff --git a/openair1/PHY/LTE_TRANSPORT/dlsch_coding.c b/openair1/PHY/LTE_TRANSPORT/dlsch_coding.c
index 30c106b16bdabfff7d1671588a94c24eb6519e38..f8768012720716dc61e9afca92fadc9078a05dc6 100644
--- a/openair1/PHY/LTE_TRANSPORT/dlsch_coding.c
+++ b/openair1/PHY/LTE_TRANSPORT/dlsch_coding.c
@@ -53,71 +53,73 @@
 */
 #define is_not_pilot(pilots,first_pilot,re) (1)
 /*extern void thread_top_init(char *thread_name,
-		     int affinity,
-		     uint64_t runtime,
-		     uint64_t deadline,
-		     uint64_t period);*/
+         int affinity,
+         uint64_t runtime,
+         uint64_t deadline,
+         uint64_t period);*/
 extern WORKER_CONF_t get_thread_worker_conf(void);
 
 
-void free_eNB_dlsch(LTE_eNB_DLSCH_t *dlsch)
-{
+void free_eNB_dlsch(LTE_eNB_DLSCH_t *dlsch) {
   int i, r, aa, layer;
 
   if (dlsch) {
     for (layer=0; layer<4; layer++) {
       for (aa=0; aa<64; aa++) free16(dlsch->ue_spec_bf_weights[layer][aa], OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES*sizeof(int32_t));
-      free16(dlsch->ue_spec_bf_weights[layer], 64*sizeof(int32_t*));
+
+      free16(dlsch->ue_spec_bf_weights[layer], 64*sizeof(int32_t *));
     }
+
     for (i=0; i<dlsch->Mdlharq; i++) {
       if (dlsch->harq_processes[i]) {
         if (dlsch->harq_processes[i]->b) {
           free16(dlsch->harq_processes[i]->b,MAX_DLSCH_PAYLOAD_BYTES);
           dlsch->harq_processes[i]->b = NULL;
         }
+
         for (r=0; r<MAX_NUM_DLSCH_SEGMENTS; r++) {
           if (dlsch->harq_processes[i]->c[r]) {
             free16(dlsch->harq_processes[i]->c[r],((r==0)?8:0) + 3+768);
             dlsch->harq_processes[i]->c[r] = NULL;
           }
+
           if (dlsch->harq_processes[i]->d[r]) {
             free16(dlsch->harq_processes[i]->d[r],(96+12+3+(3*6144)));
             dlsch->harq_processes[i]->d[r] = NULL;
           }
-	}
-	free16(dlsch->harq_processes[i],sizeof(LTE_DL_eNB_HARQ_t));
-	dlsch->harq_processes[i] = NULL;
+        }
+
+        free16(dlsch->harq_processes[i],sizeof(LTE_DL_eNB_HARQ_t));
+        dlsch->harq_processes[i] = NULL;
       }
     }
+
     free16(dlsch,sizeof(LTE_eNB_DLSCH_t));
-    dlsch = NULL;
   }
 }
 
-LTE_eNB_DLSCH_t *new_eNB_dlsch(unsigned char Kmimo,unsigned char Mdlharq,uint32_t Nsoft,unsigned char N_RB_DL, uint8_t abstraction_flag, LTE_DL_FRAME_PARMS* frame_parms)
-{
-
+LTE_eNB_DLSCH_t *new_eNB_dlsch(unsigned char Kmimo,unsigned char Mdlharq,uint32_t Nsoft,unsigned char N_RB_DL, uint8_t abstraction_flag, LTE_DL_FRAME_PARMS *frame_parms) {
   LTE_eNB_DLSCH_t *dlsch;
   unsigned char exit_flag = 0,i,j,r,aa,layer;
   int re;
   unsigned char bw_scaling =1;
 
   switch (N_RB_DL) {
-  case 6:
-    bw_scaling =16;
-    break;
+    case 6:
+      bw_scaling =16;
+      break;
 
-  case 25:
-    bw_scaling =4;
-    break;
+    case 25:
+      bw_scaling =4;
+      break;
 
-  case 50:
-    bw_scaling =2;
-    break;
+    case 50:
+      bw_scaling =2;
+      break;
 
-  default:
-    bw_scaling =1;
-    break;
+    default:
+      bw_scaling =1;
+      break;
   }
 
   dlsch = (LTE_eNB_DLSCH_t *)malloc16(sizeof(LTE_eNB_DLSCH_t));
@@ -128,15 +130,16 @@ LTE_eNB_DLSCH_t *new_eNB_dlsch(unsigned char Kmimo,unsigned char Mdlharq,uint32_
     dlsch->Mdlharq = Mdlharq;
     dlsch->Mlimit = 8;
     dlsch->Nsoft = Nsoft;
-    
+
     for (layer=0; layer<4; layer++) {
-      dlsch->ue_spec_bf_weights[layer] = (int32_t**)malloc16(64*sizeof(int32_t*));
-      
+      dlsch->ue_spec_bf_weights[layer] = (int32_t **)malloc16(64*sizeof(int32_t *));
+
       for (aa=0; aa<64; aa++) {
-	dlsch->ue_spec_bf_weights[layer][aa] = (int32_t *)malloc16(OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES*sizeof(int32_t));
-	for (re=0;re<OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES; re++) {
-	  dlsch->ue_spec_bf_weights[layer][aa][re] = 0x00007fff;
-	}
+        dlsch->ue_spec_bf_weights[layer][aa] = (int32_t *)malloc16(OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES*sizeof(int32_t));
+
+        for (re=0; re<OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES; re++) {
+          dlsch->ue_spec_bf_weights[layer][aa][re] = 0x00007fff;
+        }
       }
     }
 
@@ -159,7 +162,7 @@ LTE_eNB_DLSCH_t *new_eNB_dlsch(unsigned char Kmimo,unsigned char Mdlharq,uint32_
       if (dlsch->harq_processes[i]) {
         bzero(dlsch->harq_processes[i],sizeof(LTE_DL_eNB_HARQ_t));
         //    dlsch->harq_processes[i]->first_tx=1;
-        dlsch->harq_processes[i]->b = (unsigned char*)malloc16(MAX_DLSCH_PAYLOAD_BYTES/bw_scaling);
+        dlsch->harq_processes[i]->b = (unsigned char *)malloc16(MAX_DLSCH_PAYLOAD_BYTES/bw_scaling);
 
         if (dlsch->harq_processes[i]->b) {
           bzero(dlsch->harq_processes[i]->b,MAX_DLSCH_PAYLOAD_BYTES/bw_scaling);
@@ -171,14 +174,16 @@ LTE_eNB_DLSCH_t *new_eNB_dlsch(unsigned char Kmimo,unsigned char Mdlharq,uint32_
         if (abstraction_flag==0) {
           for (r=0; r<MAX_NUM_DLSCH_SEGMENTS/bw_scaling; r++) {
             // account for filler in first segment and CRCs for multiple segment case
-            dlsch->harq_processes[i]->c[r] = (uint8_t*)malloc16(((r==0)?8:0) + 3+ 768);
-            dlsch->harq_processes[i]->d[r] = (uint8_t*)malloc16((96+12+3+(3*6144)));
+            dlsch->harq_processes[i]->c[r] = (uint8_t *)malloc16(((r==0)?8:0) + 3+ 768);
+            dlsch->harq_processes[i]->d[r] = (uint8_t *)malloc16((96+12+3+(3*6144)));
+
             if (dlsch->harq_processes[i]->c[r]) {
               bzero(dlsch->harq_processes[i]->c[r],((r==0)?8:0) + 3+ 768);
             } else {
               printf("Can't get c\n");
               exit_flag=2;
             }
+
             if (dlsch->harq_processes[i]->d[r]) {
               bzero(dlsch->harq_processes[i]->d[r],(96+12+3+(3*6144)));
             } else {
@@ -197,13 +202,12 @@ LTE_eNB_DLSCH_t *new_eNB_dlsch(unsigned char Kmimo,unsigned char Mdlharq,uint32_
       for (i=0; i<Mdlharq; i++) {
         dlsch->harq_processes[i]->round=0;
 
-	for (j=0; j<96; j++)
-	  for (r=0; r<MAX_NUM_DLSCH_SEGMENTS/bw_scaling; r++) {
-	    //      printf("dlsch->harq_processes[%d]->d[%d] %p\n",i,r,dlsch->harq_processes[i]->d[r]);
-	    if (dlsch->harq_processes[i]->d[r])
-	      dlsch->harq_processes[i]->d[r][j] = LTE_NULL;
-	  }
-
+        for (j=0; j<96; j++)
+          for (r=0; r<MAX_NUM_DLSCH_SEGMENTS/bw_scaling; r++) {
+            //      printf("dlsch->harq_processes[%d]->d[%d] %p\n",i,r,dlsch->harq_processes[i]->d[r]);
+            if (dlsch->harq_processes[i]->d[r])
+              dlsch->harq_processes[i]->d[r][j] = LTE_NULL;
+          }
       }
 
       return(dlsch);
@@ -211,16 +215,12 @@ LTE_eNB_DLSCH_t *new_eNB_dlsch(unsigned char Kmimo,unsigned char Mdlharq,uint32_
   }
 
   LOG_D(PHY,"new_eNB_dlsch exit flag %d, size of  %ld\n",
-	exit_flag, sizeof(LTE_eNB_DLSCH_t));
+        exit_flag, sizeof(LTE_eNB_DLSCH_t));
   free_eNB_dlsch(dlsch);
   return(NULL);
-
-
 }
 
-void clean_eNb_dlsch(LTE_eNB_DLSCH_t *dlsch)
-{
-
+void clean_eNb_dlsch(LTE_eNB_DLSCH_t *dlsch) {
   unsigned char Mdlharq;
   unsigned char i,j,r;
 
@@ -228,8 +228,10 @@ void clean_eNb_dlsch(LTE_eNB_DLSCH_t *dlsch)
     Mdlharq = dlsch->Mdlharq;
     dlsch->rnti = 0;
 #ifdef PHY_TX_THREAD
+
     for (i=0; i<10; i++)
       dlsch->active[i] = 0;
+
 #else
     dlsch->active = 0;
 #endif
@@ -244,11 +246,10 @@ void clean_eNb_dlsch(LTE_eNB_DLSCH_t *dlsch)
         dlsch->harq_processes[i]->status = 0;
         dlsch->harq_processes[i]->round  = 0;
 
-	for (j=0; j<96; j++)
-	  for (r=0; r<MAX_NUM_DLSCH_SEGMENTS; r++)
-	    if (dlsch->harq_processes[i]->d[r])
-	      dlsch->harq_processes[i]->d[r][j] = LTE_NULL;
-
+        for (j=0; j<96; j++)
+          for (r=0; r<MAX_NUM_DLSCH_SEGMENTS; r++)
+            if (dlsch->harq_processes[i]->d[r])
+              dlsch->harq_processes[i]->d[r][j] = LTE_NULL;
       }
     }
   }
@@ -258,31 +259,24 @@ void clean_eNb_dlsch(LTE_eNB_DLSCH_t *dlsch)
 
 
 int dlsch_encoding_2threads0(te_params *tep) {
-
   LTE_eNB_DLSCH_t *dlsch          = tep->dlsch;
   unsigned int G                  = tep->G;
   unsigned char harq_pid          = tep->harq_pid;
   unsigned int total_worker       = tep->total_worker;
   unsigned int current_worker     = tep->current_worker;
-
   unsigned short nb_rb = dlsch->harq_processes[harq_pid]->nb_rb;
   unsigned int Kr=0,Kr_bytes,r,r_offset=0;
   //  unsigned short m=dlsch->harq_processes[harq_pid]->mcs;
-
-
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ENCODING_W, VCD_FUNCTION_IN);
 
   if (dlsch->harq_processes[harq_pid]->round == 0) {  // this is a new packet
-
     for (r=(dlsch->harq_processes[harq_pid]->C/(total_worker+1))*current_worker; r<(dlsch->harq_processes[harq_pid]->C/(total_worker+1))*(current_worker+1); r++) {
-
       if (r<dlsch->harq_processes[harq_pid]->Cminus)
         Kr = dlsch->harq_processes[harq_pid]->Kminus;
       else
         Kr = dlsch->harq_processes[harq_pid]->Kplus;
 
       Kr_bytes = Kr>>3;
-
       encoder(dlsch->harq_processes[harq_pid]->c[r],
               Kr>>3,
               &dlsch->harq_processes[harq_pid]->d[r][96],
@@ -293,25 +287,24 @@ int dlsch_encoding_2threads0(te_params *tep) {
                                      &dlsch->harq_processes[harq_pid]->d[r][96],
                                      dlsch->harq_processes[harq_pid]->w[r]);
     }
-
   }
 
   // Fill in the "e"-sequence from 36-212, V8.6 2009-03, p. 16-17 (for each "e") and concatenate the
   // outputs for each code segment, see Section 5.1.5 p.20
 
   for (r=0,r_offset=0; r<(dlsch->harq_processes[harq_pid]->C/(total_worker+1))*(current_worker+1); r++) {
-    if(r<(dlsch->harq_processes[harq_pid]->C/(total_worker+1))*(current_worker)){
-	  int Nl=dlsch->harq_processes[harq_pid]->Nl;
+    if(r<(dlsch->harq_processes[harq_pid]->C/(total_worker+1))*(current_worker)) {
+      int Nl=dlsch->harq_processes[harq_pid]->Nl;
       int Qm=dlsch->harq_processes[harq_pid]->Qm;
       int C = dlsch->harq_processes[harq_pid]->C;
       int Gp = G/Nl/Qm;
       int GpmodC = Gp%C;
+
       if (r < (C-(GpmodC)))
-	    r_offset += Nl*Qm * (Gp/C);
+        r_offset += Nl*Qm * (Gp/C);
       else
-	    r_offset += Nl*Qm * ((GpmodC==0?0:1) + (Gp/C));
-	}
-	else{
+        r_offset += Nl*Qm * ((GpmodC==0?0:1) + (Gp/C));
+    } else {
       r_offset += lte_rate_matching_turbo(dlsch->harq_processes[harq_pid]->RTC[r],
                                           G,  //G
                                           dlsch->harq_processes[harq_pid]->w[r],
@@ -330,7 +323,6 @@ int dlsch_encoding_2threads0(te_params *tep) {
   }
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ENCODING_W, VCD_FUNCTION_OUT);
-
   return(0);
 }
 
@@ -339,19 +331,16 @@ extern int oai_exit;
 void *te_thread(void *param) {
   cpu_set_t cpuset;
   CPU_ZERO(&cpuset);
-  
   thread_top_init("te_thread",1,200000,250000,500000);
   pthread_setname_np( pthread_self(),"te processing");
   LOG_I(PHY,"thread te created id=%ld\n", syscall(__NR_gettid));
-  
-
   te_params *tep                 = (te_params *)param;
-  
+
   //wait_sync("te_thread");
-  
-  while (!oai_exit) {
 
+  while (!oai_exit) {
     if (wait_on_condition(&tep->mutex_te,&tep->cond_te,&tep->instance_cnt_te,"te thread")<0) break;
+
     if(oai_exit) break;
 
     dlsch_encoding_2threads0(tep);
@@ -363,6 +352,7 @@ void *te_thread(void *param) {
       exit_fun( "ERROR pthread_cond_signal" );
       return(NULL);
     }
+
     /*if(opp_enabled == 1 && te_wakeup_stats0->p_time>50*3000){
       print_meas_now(te_wakeup_stats0,"coding_wakeup",stderr);
       printf("te_thread0 delay for waking up in frame_rx: %d  subframe_rx: %d \n",proc->frame_rx,proc->subframe_rx);
@@ -375,61 +365,56 @@ void *te_thread(void *param) {
 
 
 int dlsch_encoding_2threads(PHY_VARS_eNB *eNB,
-			    unsigned char *a,
-			    uint8_t num_pdcch_symbols,
-			    LTE_eNB_DLSCH_t *dlsch,
-			    int frame,
-			    uint8_t subframe,
-			    time_stats_t *rm_stats,
-			    time_stats_t *te_stats,
-			    time_stats_t *te_wait_stats,
-			    time_stats_t *te_main_stats,
-			    time_stats_t *te_wakeup_stats0,
-			    time_stats_t *te_wakeup_stats1,
-			    time_stats_t *i_stats,
-			    int worker_num)
-{
-
+                            unsigned char *a,
+                            uint8_t num_pdcch_symbols,
+                            LTE_eNB_DLSCH_t *dlsch,
+                            int frame,
+                            uint8_t subframe,
+                            time_stats_t *rm_stats,
+                            time_stats_t *te_stats,
+                            time_stats_t *te_wait_stats,
+                            time_stats_t *te_main_stats,
+                            time_stats_t *te_wakeup_stats0,
+                            time_stats_t *te_wakeup_stats1,
+                            time_stats_t *i_stats,
+                            int worker_num) {
   //start_meas(&eNB->dlsch_turbo_encoding_preperation_stats);
-
   LTE_DL_FRAME_PARMS *frame_parms = &eNB->frame_parms;
-  eNB_proc_t *proc = &eNB->proc;
+  L1_proc_t *proc = &eNB->proc;
   unsigned int G;
   unsigned int crc=1;
-
   unsigned char harq_pid = dlsch->harq_ids[frame%2][subframe];
+
   if(harq_pid >= dlsch->Mdlharq) {
     LOG_E(PHY,"dlsch_encoding_2threads illegal harq_pid %d\n", harq_pid);
     return(-1);
   }
+
   unsigned short nb_rb = dlsch->harq_processes[harq_pid]->nb_rb;
   unsigned int A;
   unsigned char mod_order;
   unsigned int Kr=0,Kr_bytes,r,r_offset=0;
   //  unsigned short m=dlsch->harq_processes[harq_pid]->mcs;
-
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ENCODING, VCD_FUNCTION_IN);
-
   A = dlsch->harq_processes[harq_pid]->TBS; //6228
   mod_order = dlsch->harq_processes[harq_pid]->Qm;
-  G = get_G(frame_parms,nb_rb,dlsch->harq_processes[harq_pid]->rb_alloc,mod_order,dlsch->harq_processes[harq_pid]->Nl,num_pdcch_symbols,frame,subframe,dlsch->harq_processes[harq_pid]->mimo_mode==TM7?7:0);
+  G = get_G(frame_parms,nb_rb,dlsch->harq_processes[harq_pid]->rb_alloc,mod_order,dlsch->harq_processes[harq_pid]->Nl,num_pdcch_symbols,frame,subframe,
+            dlsch->harq_processes[harq_pid]->mimo_mode==TM7?7:0);
 
   if (dlsch->harq_processes[harq_pid]->round == 0) {  // this is a new packet
-
     start_meas(&eNB->dlsch_turbo_encoding_preperation_stats);
     // Add 24-bit crc (polynomial A) to payload
     crc = crc24a(a,
                  A)>>8;
     stop_meas(&eNB->dlsch_turbo_encoding_preperation_stats);
-    a[A>>3] = ((uint8_t*)&crc)[2];
-    a[1+(A>>3)] = ((uint8_t*)&crc)[1];
-    a[2+(A>>3)] = ((uint8_t*)&crc)[0];
-
+    a[A>>3] = ((uint8_t *)&crc)[2];
+    a[1+(A>>3)] = ((uint8_t *)&crc)[1];
+    a[2+(A>>3)] = ((uint8_t *)&crc)[0];
     dlsch->harq_processes[harq_pid]->B = A+24;
     memcpy(dlsch->harq_processes[harq_pid]->b,a,(A/8)+4);
     //stop_meas(&eNB->dlsch_turbo_encoding_preperation_stats);
-
     start_meas(&eNB->dlsch_turbo_encoding_segmentation_stats);
+
     if (lte_segmentation(dlsch->harq_processes[harq_pid]->b,
                          dlsch->harq_processes[harq_pid]->c,
                          dlsch->harq_processes[harq_pid]->B,
@@ -442,48 +427,46 @@ int dlsch_encoding_2threads(PHY_VARS_eNB *eNB,
       return(-1);
 
     stop_meas(&eNB->dlsch_turbo_encoding_segmentation_stats);
-    
     start_meas(&eNB->dlsch_turbo_encoding_signal_stats);
-    for(int i=0;i<worker_num;i++)
-    {
+
+    for(int i=0; i<worker_num; i++) {
       proc->tep[i].eNB               = eNB;
       proc->tep[i].dlsch             = dlsch;
       proc->tep[i].G                 = G;
       proc->tep[i].harq_pid          = harq_pid;
       proc->tep[i].total_worker      = worker_num;
       proc->tep[i].current_worker    = i;
-    
       pthread_mutex_lock( &proc->tep[i].mutex_te );
+
       if (proc->tep[i].instance_cnt_te==0) {
         printf("[eNB] TE thread busy\n");
         exit_fun("TE thread busy");
         pthread_mutex_unlock( &proc->tep[i].mutex_te );
         return(-1);
       }
-      
+
       ++proc->tep[i].instance_cnt_te;
-      
+
       // wakeup worker to do segments
       if (pthread_cond_signal(&proc->tep[i].cond_te) != 0) {
         printf("[eNB] ERROR pthread_cond_signal for te thread %d exit\n",i);
         exit_fun( "ERROR pthread_cond_signal" );
         return (-1);
       }
-      
+
       pthread_mutex_unlock( &proc->tep[i].mutex_te );
     }
 
     stop_meas(&eNB->dlsch_turbo_encoding_signal_stats);
     start_meas(te_main_stats);
-    for (r=(dlsch->harq_processes[harq_pid]->C/(worker_num+1))*worker_num; r<dlsch->harq_processes[harq_pid]->C; r++) {
 
+    for (r=(dlsch->harq_processes[harq_pid]->C/(worker_num+1))*worker_num; r<dlsch->harq_processes[harq_pid]->C; r++) {
       if (r<dlsch->harq_processes[harq_pid]->Cminus)
         Kr = dlsch->harq_processes[harq_pid]->Kminus;
       else
         Kr = dlsch->harq_processes[harq_pid]->Kplus;
 
       Kr_bytes = Kr>>3;
-
       start_meas(te_stats);
       encoder(dlsch->harq_processes[harq_pid]->c[r],
               Kr>>3,
@@ -491,7 +474,6 @@ int dlsch_encoding_2threads(PHY_VARS_eNB *eNB,
               (r==0) ? dlsch->harq_processes[harq_pid]->F : 0
              );
       stop_meas(te_stats);
-
       start_meas(i_stats);
       dlsch->harq_processes[harq_pid]->RTC[r] =
         sub_block_interleaving_turbo(4+(Kr_bytes*8),
@@ -499,17 +481,14 @@ int dlsch_encoding_2threads(PHY_VARS_eNB *eNB,
                                      dlsch->harq_processes[harq_pid]->w[r]);
       stop_meas(i_stats);
     }
-
-  }
-  else {
-
-    for(int i=0;i<worker_num;i++)
-    {
+  } else {
+    for(int i=0; i<worker_num; i++) {
       proc->tep[i].eNB               = eNB;
       proc->tep[i].dlsch             = dlsch;
       proc->tep[i].G                 = G;
       proc->tep[i].total_worker      = worker_num;
       proc->tep[i].current_worker    = i;
+
       if (pthread_cond_signal(&proc->tep[i].cond_te) != 0) {
         printf("[eNB] ERROR pthread_cond_signal for te thread exit\n");
         exit_fun( "ERROR pthread_cond_signal" );
@@ -521,7 +500,6 @@ int dlsch_encoding_2threads(PHY_VARS_eNB *eNB,
   // Fill in the "e"-sequence from 36-212, V8.6 2009-03, p. 16-17 (for each "e") and concatenate the
   // outputs for each code segment, see Section 5.1.5 p.20
   for (r=0,r_offset=0; r<dlsch->harq_processes[harq_pid]->C; r++) {
-
     // get information for E for the segments that are handled by the worker thread
     if (r<(dlsch->harq_processes[harq_pid]->C/(worker_num+1))*worker_num) {
       int Nl=dlsch->harq_processes[harq_pid]->Nl;
@@ -529,208 +507,186 @@ int dlsch_encoding_2threads(PHY_VARS_eNB *eNB,
       int C = dlsch->harq_processes[harq_pid]->C;
       int Gp = G/Nl/Qm;
       int GpmodC = Gp%C;
+
       if (r < (C-(GpmodC)))
-	r_offset += Nl*Qm * (Gp/C);
+        r_offset += Nl*Qm * (Gp/C);
       else
-	r_offset += Nl*Qm * ((GpmodC==0?0:1) + (Gp/C));
-    }
-    else  {
+        r_offset += Nl*Qm * ((GpmodC==0?0:1) + (Gp/C));
+    } else  {
       start_meas(rm_stats);
       r_offset += lte_rate_matching_turbo(dlsch->harq_processes[harq_pid]->RTC[r],
-					  G,  //G
-					  dlsch->harq_processes[harq_pid]->w[r],
-					  dlsch->harq_processes[harq_pid]->e+r_offset,
-					  dlsch->harq_processes[harq_pid]->C, // C
-					  dlsch->Nsoft,                    // Nsoft,
-					  dlsch->Mdlharq,
-					  dlsch->Kmimo,
-					  dlsch->harq_processes[harq_pid]->rvidx,
-					  dlsch->harq_processes[harq_pid]->Qm,
-					  dlsch->harq_processes[harq_pid]->Nl,
-					  r,
-					  nb_rb);
-      //					  m);                       // r
+                                          G,  //G
+                                          dlsch->harq_processes[harq_pid]->w[r],
+                                          dlsch->harq_processes[harq_pid]->e+r_offset,
+                                          dlsch->harq_processes[harq_pid]->C, // C
+                                          dlsch->Nsoft,                    // Nsoft,
+                                          dlsch->Mdlharq,
+                                          dlsch->Kmimo,
+                                          dlsch->harq_processes[harq_pid]->rvidx,
+                                          dlsch->harq_processes[harq_pid]->Qm,
+                                          dlsch->harq_processes[harq_pid]->Nl,
+                                          r,
+                                          nb_rb);
+      //            m);                       // r
       stop_meas(rm_stats);
     }
   }
-  stop_meas(te_main_stats);
 
+  stop_meas(te_main_stats);
   start_meas(te_wait_stats);
-  if(worker_num == 1)
-  {
+
+  if(worker_num == 1) {
     wait_on_busy_condition(&proc->tep[0].mutex_te,&proc->tep[0].cond_te,&proc->tep[0].instance_cnt_te,"te thread 0");
-  }
-  else if(worker_num == 2)
-  {
+  } else if(worker_num == 2) {
     wait_on_busy_condition(&proc->tep[0].mutex_te,&proc->tep[0].cond_te,&proc->tep[0].instance_cnt_te,"te thread 0");
     wait_on_busy_condition(&proc->tep[1].mutex_te,&proc->tep[1].cond_te,&proc->tep[1].instance_cnt_te,"te thread 1");
-  }
-  else
-  {
+  } else {
     wait_on_busy_condition(&proc->tep[0].mutex_te,&proc->tep[0].cond_te,&proc->tep[0].instance_cnt_te,"te thread 0");
     wait_on_busy_condition(&proc->tep[1].mutex_te,&proc->tep[1].cond_te,&proc->tep[1].instance_cnt_te,"te thread 1");
     wait_on_busy_condition(&proc->tep[2].mutex_te,&proc->tep[2].cond_te,&proc->tep[2].instance_cnt_te,"te thread 2");
   }
+
   stop_meas(te_wait_stats);
-  
   /*if(opp_enabled == 1 && te_wait_stats->p_time>100*3000){
     print_meas_now(te_wait_stats,"coding_wait",stderr);
-	printf("coding delay in wait on codition in frame_rx: %d \n",proc->frame_rx);
+  printf("coding delay in wait on codition in frame_rx: %d \n",proc->frame_rx);
   }*/
-
-
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ENCODING, VCD_FUNCTION_OUT);
-
   return(0);
 }
 int dlsch_encoding_all(PHY_VARS_eNB *eNB,
-		   unsigned char *a,
-                   uint8_t num_pdcch_symbols,
-                   LTE_eNB_DLSCH_t *dlsch,
-                   int frame,
-                   uint8_t subframe,
-                   time_stats_t *rm_stats,
-                   time_stats_t *te_stats,
-				   time_stats_t *te_wait_stats,
-                   time_stats_t *te_main_stats,
-                   time_stats_t *te_wakeup_stats0,
-                   time_stats_t *te_wakeup_stats1,
-                   time_stats_t *i_stats)
-{
-	int encoding_return = 0;
-	unsigned int L,C,B;
-	B = dlsch->harq_processes[dlsch->harq_ids[frame%2][subframe]]->B;
-	if(B<=6144)
-	{
-		L=0;
-		C=1;
-	}
-	else
-	{
-		L=24;
-		C = B/(6144-L);
-		if((6144-L)*C < B)
-		{
-			C = C+1;
-		}
-	}
-
-    if(get_thread_worker_conf() == WORKER_ENABLE)
-    {
-      if(C >= 8)//one main three worker
-      {
-        encoding_return =
-		dlsch_encoding_2threads(eNB,
-				   a,
-                   num_pdcch_symbols,
-                   dlsch,
-                   frame,
-                   subframe,
-                   rm_stats,
-                   te_stats,
-                   te_wait_stats,
-                   te_main_stats,
-                   te_wakeup_stats0,
-                   te_wakeup_stats1,
-                   i_stats,
-                   3);
-      }
-      else if(C >= 6)//one main two worker
-      {
-        encoding_return =
-		dlsch_encoding_2threads(eNB,
-				   a,
-                   num_pdcch_symbols,
-                   dlsch,
-                   frame,
-                   subframe,
-                   rm_stats,
-                   te_stats,
-                   te_wait_stats,
-                   te_main_stats,
-                   te_wakeup_stats0,
-                   te_wakeup_stats1,
-                   i_stats,
-                   2);
-      }
-      else if(C >= 4)//one main one worker
-      {
-        encoding_return =
-		dlsch_encoding_2threads(eNB,
-				   a,
-                   num_pdcch_symbols,
-                   dlsch,
-                   frame,
-                   subframe,
-                   rm_stats,
-                   te_stats,
-                   te_wait_stats,
-                   te_main_stats,
-                   te_wakeup_stats0,
-                   te_wakeup_stats1,
-                   i_stats,
-                   1);
-      }
-      else
-      {
-		encoding_return =
-		dlsch_encoding(eNB,
-				   a,
-                   num_pdcch_symbols,
-                   dlsch,
-                   frame,
-                   subframe,
-                   rm_stats,
-                   te_stats,
-                   i_stats);
-      }
+                       unsigned char *a,
+                       uint8_t num_pdcch_symbols,
+                       LTE_eNB_DLSCH_t *dlsch,
+                       int frame,
+                       uint8_t subframe,
+                       time_stats_t *rm_stats,
+                       time_stats_t *te_stats,
+                       time_stats_t *te_wait_stats,
+                       time_stats_t *te_main_stats,
+                       time_stats_t *te_wakeup_stats0,
+                       time_stats_t *te_wakeup_stats1,
+                       time_stats_t *i_stats) {
+  int encoding_return = 0;
+  unsigned int L,C,B;
+  B = dlsch->harq_processes[dlsch->harq_ids[frame%2][subframe]]->B;
+
+  if(B<=6144) {
+    L=0;
+    C=1;
+  } else {
+    L=24;
+    C = B/(6144-L);
+
+    if((6144-L)*C < B) {
+      C = C+1;
     }
-    else
-    {
-		encoding_return =
-		dlsch_encoding(eNB,
-				   a,
-                   num_pdcch_symbols,
-                   dlsch,
-                   frame,
-                   subframe,
-                   rm_stats,
-                   te_stats,
-                   i_stats);
+  }
+
+  if(get_thread_worker_conf() == WORKER_ENABLE) {
+    if(C >= 8) { //one main three worker
+      encoding_return =
+        dlsch_encoding_2threads(eNB,
+                                a,
+                                num_pdcch_symbols,
+                                dlsch,
+                                frame,
+                                subframe,
+                                rm_stats,
+                                te_stats,
+                                te_wait_stats,
+                                te_main_stats,
+                                te_wakeup_stats0,
+                                te_wakeup_stats1,
+                                i_stats,
+                                3);
+    } else if(C >= 6) { //one main two worker
+      encoding_return =
+        dlsch_encoding_2threads(eNB,
+                                a,
+                                num_pdcch_symbols,
+                                dlsch,
+                                frame,
+                                subframe,
+                                rm_stats,
+                                te_stats,
+                                te_wait_stats,
+                                te_main_stats,
+                                te_wakeup_stats0,
+                                te_wakeup_stats1,
+                                i_stats,
+                                2);
+    } else if(C >= 4) { //one main one worker
+      encoding_return =
+        dlsch_encoding_2threads(eNB,
+                                a,
+                                num_pdcch_symbols,
+                                dlsch,
+                                frame,
+                                subframe,
+                                rm_stats,
+                                te_stats,
+                                te_wait_stats,
+                                te_main_stats,
+                                te_wakeup_stats0,
+                                te_wakeup_stats1,
+                                i_stats,
+                                1);
+    } else {
+      encoding_return =
+        dlsch_encoding(eNB,
+                       a,
+                       num_pdcch_symbols,
+                       dlsch,
+                       frame,
+                       subframe,
+                       rm_stats,
+                       te_stats,
+                       i_stats);
     }
-	return encoding_return;
+  } else {
+    encoding_return =
+      dlsch_encoding(eNB,
+                     a,
+                     num_pdcch_symbols,
+                     dlsch,
+                     frame,
+                     subframe,
+                     rm_stats,
+                     te_stats,
+                     i_stats);
+  }
+
+  return encoding_return;
 }
 
 
 int dlsch_encoding(PHY_VARS_eNB *eNB,
-		   unsigned char *a,
+                   unsigned char *a,
                    uint8_t num_pdcch_symbols,
                    LTE_eNB_DLSCH_t *dlsch,
                    int frame,
                    uint8_t subframe,
                    time_stats_t *rm_stats,
                    time_stats_t *te_stats,
-                   time_stats_t *i_stats)
-{
-
+                   time_stats_t *i_stats) {
   unsigned int G;
   unsigned int crc=1;
-
   LTE_DL_FRAME_PARMS *frame_parms = &eNB->frame_parms;
   unsigned char harq_pid = dlsch->harq_ids[frame%2][subframe];
+
   if(harq_pid >= dlsch->Mdlharq) {
     LOG_E(PHY,"dlsch_encoding illegal harq_pid %d\n", harq_pid);
     return(-1);
   }
+
   unsigned short nb_rb = dlsch->harq_processes[harq_pid]->nb_rb;
   unsigned int A;
   unsigned char mod_order;
   unsigned int Kr=0,Kr_bytes,r,r_offset=0;
   //  unsigned short m=dlsch->harq_processes[harq_pid]->mcs;
   uint8_t beamforming_mode=0;
-
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ENCODING, VCD_FUNCTION_IN);
-
   A = dlsch->harq_processes[harq_pid]->TBS; //6228
   // printf("Encoder: A: %d\n",A);
   mod_order = dlsch->harq_processes[harq_pid]->Qm;
@@ -741,8 +697,8 @@ int dlsch_encoding(PHY_VARS_eNB *eNB,
     beamforming_mode = 8;
   else if(dlsch->harq_processes[harq_pid]->mimo_mode == TM9_10)
     beamforming_mode = 9;
-  G = get_G(frame_parms,nb_rb,dlsch->harq_processes[harq_pid]->rb_alloc,mod_order,dlsch->harq_processes[harq_pid]->Nl,num_pdcch_symbols,frame,subframe,beamforming_mode);
 
+  G = get_G(frame_parms,nb_rb,dlsch->harq_processes[harq_pid]->rb_alloc,mod_order,dlsch->harq_processes[harq_pid]->Nl,num_pdcch_symbols,frame,subframe,beamforming_mode);
 
   //  if (dlsch->harq_processes[harq_pid]->Ndi == 1) {  // this is a new packet
   if (dlsch->harq_processes[harq_pid]->round == 0) {  // this is a new packet
@@ -757,14 +713,12 @@ int dlsch_encoding(PHY_VARS_eNB *eNB,
     printf("\n");
     */
     // Add 24-bit crc (polynomial A) to payload
-
     crc = crc24a(a,
                  A)>>8;
-    a[A>>3] = ((uint8_t*)&crc)[2];
-    a[1+(A>>3)] = ((uint8_t*)&crc)[1];
-    a[2+(A>>3)] = ((uint8_t*)&crc)[0];
+    a[A>>3] = ((uint8_t *)&crc)[2];
+    a[1+(A>>3)] = ((uint8_t *)&crc)[1];
+    a[2+(A>>3)] = ((uint8_t *)&crc)[0];
     //    printf("CRC %x (A %d)\n",crc,A);
-
     dlsch->harq_processes[harq_pid]->B = A+24;
     //    dlsch->harq_processes[harq_pid]->b = a;
     memcpy(dlsch->harq_processes[harq_pid]->b,a,(A/8)+4);
@@ -781,25 +735,20 @@ int dlsch_encoding(PHY_VARS_eNB *eNB,
       return(-1);
 
     for (r=0; r<dlsch->harq_processes[harq_pid]->C; r++) {
-
       if (r<dlsch->harq_processes[harq_pid]->Cminus)
         Kr = dlsch->harq_processes[harq_pid]->Kminus;
       else
         Kr = dlsch->harq_processes[harq_pid]->Kplus;
 
       Kr_bytes = Kr>>3;
-
 #ifdef DEBUG_DLSCH_CODING
-      printf("Generating Code Segment %d (%d bits)\n",r,Kr);
+      printf("Generating Code Segment %u (%u bits)\n",r,Kr);
       // generate codewords
-
-      printf("bits_per_codeword (Kr)= %d, A %d\n",Kr,A);
+      printf("bits_per_codeword (Kr)= %u, A %u\n",Kr,A);
       printf("N_RB = %d\n",nb_rb);
       printf("Ncp %d\n",frame_parms->Ncp);
       printf("mod_order %d\n",mod_order);
 #endif
-
-
       start_meas(te_stats);
       encoder(dlsch->harq_processes[harq_pid]->c[r],
               Kr>>3,
@@ -820,7 +769,6 @@ int dlsch_encoding(PHY_VARS_eNB *eNB,
                                      dlsch->harq_processes[harq_pid]->w[r]);
       stop_meas(i_stats);
     }
-
   }
 
   // Fill in the "e"-sequence from 36-212, V8.6 2009-03, p. 16-17 (for each "e") and concatenate the
@@ -828,16 +776,15 @@ int dlsch_encoding(PHY_VARS_eNB *eNB,
 
   for (r=0; r<dlsch->harq_processes[harq_pid]->C; r++) {
 #ifdef DEBUG_DLSCH_CODING
-    printf("Rate Matching, Code segment %d (coded bits (G) %d,unpunctured/repeated bits per code segment %d,mod_order %d, nb_rb %d)...\n",
-        r,
-        G,
-        Kr*3,
-        mod_order,nb_rb);
+    printf("Rate Matching, Code segment %u (coded bits (G) %u,unpunctured/repeated bits per code segment %u,mod_order %d, nb_rb %d)...\n",
+           r,
+           G,
+           Kr*3,
+           mod_order,nb_rb);
 #endif
-
     start_meas(rm_stats);
 #ifdef DEBUG_DLSCH_CODING
-  printf("rvidx in encoding = %d\n", dlsch->harq_processes[harq_pid]->rvidx);
+    printf("rvidx in encoding = %d\n", dlsch->harq_processes[harq_pid]->rvidx);
 #endif
     r_offset += lte_rate_matching_turbo(dlsch->harq_processes[harq_pid]->RTC[r],
                                         G,  //G
@@ -852,7 +799,7 @@ int dlsch_encoding(PHY_VARS_eNB *eNB,
                                         dlsch->harq_processes[harq_pid]->Nl,
                                         r,
                                         nb_rb);
-					//                                        m);                       // r
+    //                                        m);                       // r
     stop_meas(rm_stats);
 #ifdef DEBUG_DLSCH_CODING
 
@@ -863,7 +810,6 @@ int dlsch_encoding(PHY_VARS_eNB *eNB,
   }
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ENCODING, VCD_FUNCTION_OUT);
-
   return(0);
 }
 
diff --git a/openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c b/openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c
index bfdcdc1e94694f0f549e3ed885db322baef8bd2f..e8b56f3bdfe99292b3a5db85d91b5d99f1fba697 100644
--- a/openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c
+++ b/openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c
@@ -1960,6 +1960,10 @@ int allocate_REs_in_RB_MCH(int32_t **txdataF,
 
       case 4:  //16QAM
 
+    if (qam_table_s == NULL) {
+      LOG_E(PHY,"qam table pointer is NULL\n");
+      return -1;
+    }
     qam16_table_offset_re = 0;
     qam16_table_offset_im = 0;
 
@@ -2029,7 +2033,9 @@ int allocate_REs_in_RB_MCH(int32_t **txdataF,
     ((int16_t *)&txdataF[4][tti_offset])[1]=qam_table_s[qam64_table_offset_im];//(int16_t)(((int32_t)amp*qam64_table[qam64_table_offset_im])>>15);
 
     break;
-
+    default:
+        LOG_E(PHY,"Invalid modulation order %i_n",mod_order);
+    break;
     }
   }
 
diff --git a/openair1/PHY/LTE_TRANSPORT/dlsch_scrambling.c b/openair1/PHY/LTE_TRANSPORT/dlsch_scrambling.c
index 9aacdd079d7d005ed1c8016a6d48aea705e3787b..a910ce9928dd405b3395186215ea823ed73b368c 100644
--- a/openair1/PHY/LTE_TRANSPORT/dlsch_scrambling.c
+++ b/openair1/PHY/LTE_TRANSPORT/dlsch_scrambling.c
@@ -52,7 +52,6 @@ void dlsch_scrambling(LTE_DL_FRAME_PARMS *frame_parms,
 {
 
   int n;
-
   //  uint8_t reset;
   uint32_t x1, x2, s=0;
   uint8_t *dlsch_e=dlsch->harq_processes[harq_pid]->e;
@@ -60,7 +59,7 @@ void dlsch_scrambling(LTE_DL_FRAME_PARMS *frame_parms,
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_SCRAMBLING, VCD_FUNCTION_IN);
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   // Rule for accumulation of subframes for BL/CE UEs
   uint8_t Nacc=4;
   uint16_t j0,j,idelta;
@@ -97,7 +96,7 @@ void dlsch_scrambling(LTE_DL_FRAME_PARMS *frame_parms,
   //  reset = 1;
   // x1 is set in lte_gold_generic
   if (mbsfn_flag == 0) {
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 #ifdef PHY_TX_THREAD
     if (dlsch->harq_processes[harq_pid]->i0 != 0xFFFF) {
 #else
@@ -115,7 +114,7 @@ void dlsch_scrambling(LTE_DL_FRAME_PARMS *frame_parms,
   }
 
 #ifdef DEBUG_SCRAMBLING
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   printf("scrambling: i0 %d rnti %x, q %d, Ns %d, Nid_cell %d, G %d x2 %x\n",dlsch->i0,dlsch->rnti,q,Ns,frame_parms->Nid_cell, G, x2);
 #else
   printf("scrambling: rnti %x, q %d, Ns %d, Nid_cell %d, G %d x2 %x\n",dlsch->rnti,q,Ns,frame_parms->Nid_cell, G, x2);
@@ -169,7 +168,6 @@ void dlsch_scrambling(LTE_DL_FRAME_PARMS *frame_parms,
 
 
     
-    
     s = lte_gold_generic(&x1, &x2, 0);
     e += 32;
   }
diff --git a/openair1/PHY/LTE_TRANSPORT/edci.c b/openair1/PHY/LTE_TRANSPORT/edci.c
old mode 100755
new mode 100644
index fc82fd01375827bba653561691067b027a675ee6..5985bdd01e8f3cb1f4ce4f5a0e01557ad6d1e56c
--- a/openair1/PHY/LTE_TRANSPORT/edci.c
+++ b/openair1/PHY/LTE_TRANSPORT/edci.c
@@ -19,162 +19,335 @@
  *      contact@openairinterface.org
  */
 
-/*! \file PHY/LTE_TRANSPORT/dci.c
-* \brief Implements PDCCH physical channel TX/RX procedures (36.211) and DCI encoding/decoding (36.212/36.213). Current LTE compliance V8.6 2009-03.
-* \author R. Knopp
-* \date 2011
-* \version 0.1
-* \company Eurecom
-* \email: knopp@eurecom.fr
-* \note
-* \warning
-*/
+
+/*! \file PHY/LTE_TRANSPORT/edci.c
+ * \brief Implements M/EPDCCH physical channel TX/RX procedures (36.211).
+ * \author R. Knopp
+ * \date 2011
+ * \version 0.1
+ * \company Eurecom
+ * \email: knopp@eurecom.fr
+ * \note
+ * \warning
+ */
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include "PHY/defs_eNB.h"
 #include "PHY/phy_extern.h"
 #include "SCHED/sched_eNB.h"
-#include "SIMULATION/TOOLS/sim.h" // for taus 
+#include "SIMULATION/TOOLS/sim.h"      // for taus
 #include "PHY/sse_intrin.h"
-#include "transport_proto.h"
-#include "transport_common_proto.h"
-#include "assertions.h" 
-#include "common/utils/LOG/log.h"
 #include "PHY/LTE_REFSIG/lte_refsig.h"
 
+#include "assertions.h"
+#include "T.h"
+#include "common/utils/LOG/log.h"
+
 //#define DEBUG_DCI_ENCODING 1
 //#define DEBUG_DCI_DECODING 1
 //#define DEBUG_PHY
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 void generate_edci_top(PHY_VARS_eNB *eNB, int frame, int subframe) {
 
 }
 
-void mpdcch_scrambling(LTE_DL_FRAME_PARMS *frame_parms,
-		       mDCI_ALLOC_t *mdci,
-		       uint16_t i,
-		       uint8_t *e,
-		       uint32_t length)
+void mpdcch_scrambling(LTE_DL_FRAME_PARMS * frame_parms, mDCI_ALLOC_t * mdci, uint16_t i, uint8_t * e, uint32_t length)
 {
-  int n;
-  uint8_t reset;
-  uint32_t x1, x2, s=0;
-  uint8_t Nacc=4;
-  uint16_t j0,j,idelta;
-  uint16_t i0 = mdci->i0;
+  int             n;
+  uint8_t         reset;
+  uint32_t        x1, x2, s = 0;
+  uint8_t         Nacc = 4;
+  uint16_t        j0, j, idelta;
+  uint16_t        i0 = mdci->i0;
 
   // Note: we could actually not do anything if i-i0 < Nacc, save it for later
 
   reset = 1;
   // x1 is set in lte_gold_generic
 
-  if ((mdci->rnti == 0xFFFE) || 
-      (mdci->ce_mode == 2)) // CEModeB Note: also for mdci->rnti==SC_RNTI
-    Nacc=frame_parms->frame_type == FDD ? 4 : 10;
-  else Nacc=1;
-  
-  if (frame_parms->frame_type == FDD || Nacc == 1) idelta = 0;
-  else                                             idelta = Nacc-2;
-  
-  j0 = (i0+idelta)/Nacc;
-  j  = (i - i0)/Nacc; 
-
-  
+  if ((mdci->rnti == 0xFFFE) || (mdci->ce_mode == 2)) // CEModeB Note: also for mdci->rnti==SC_RNTI
+    Nacc = frame_parms->frame_type == FDD ? 4 : 10;
+  else
+    Nacc = 1;
+
+  if (frame_parms->frame_type == FDD || Nacc == 1)
+    idelta = 0;
+  else
+    idelta = Nacc - 2;
+
+  j0 = (i0 + idelta) / Nacc;
+  j = (i - i0) / Nacc;
+
+
   // rule for BL/CE UEs from Section 6.8.B2 in 36.211
-  x2=  ((((j0+j)*Nacc)%10)<<9) +  mdci->dmrs_scrambling_init;
-  
-  for (n=0; n<length; n++) {
-    if ((i&0x1f)==0) {
+  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",
+	x2,mdci->dmrs_scrambling_init,length);
+  for (n = 0; n < length; n++) {
+    if ((n & 0x1f) == 0) {
       s = lte_gold_generic(&x1, &x2, reset);
       //printf("lte_gold[%d]=%x\n",i,s);
       reset = 0;
     }
-    e[i] = (e[i]&1) ^ ((s>>(i&0x1f))&1);
+
+    e[n] = (e[n] & 1) ^ ((s >> (n & 0x1f)) & 1);
+
   }
 }
 
-// this table is the allocation of modulated MPDCCH format 5 symbols to REs
-// There are in total 36 REs/ECCE * 4 ECCE/PRB_pair = 144 REs in total/PRB_pair, total is 168 REs => 24 REs for DMRS
-// For format 5 there are 6 PRB pairs => 864 REs for 24 total ECCE
-static uint16_t mpdcch5tab[864];
-
-void init_mpdcch5tab_normal_regular_subframe_evenNRBDL(PHY_VARS_eNB *eNB) {
-  int l,k,kmod,re;
-
-  LOG_I(PHY,"Inititalizing mpdcch5tab for normal prefix, normal prefix, no PSS/SSS/PBCH, even N_RB_DL\n");
-  for (l=0,re=0;l<14;l++) {
-    for (k=0;k<72;k++){
-      kmod = k % 12; 
-      if (((l!=5) && (l!=6) && (l!=12) && (l!=13)) ||
-	  (((l==5)||(l==6)||(l==12)||(l==13))&&(kmod!=0)&&(kmod!=5)&&(kmod!=10)))
-	mpdcch5tab[re++]=(l*eNB->frame_parms.ofdm_symbol_size)+k;
+// this table is the allocation of modulated MPDCCH format 5 symbols to REs, antenna ports 107,108
+// start symbol is symbol 1 and L'=24 => all 6 PRBs in the set
+// 9 symbols without DMRS = 9*12*6 REs = 648 REs
+// 4 symbols with DMRS (3 REs stolen per symbol = 4*9*6 REs = 216 REs
+// Total = 648+216 = 864 REs = 1728 bits
+static uint16_t mpdcch5ss1tab[864];
+
+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");
+
+  for (l = 1; l < 14; l++) {
+    for (k = 0; k < 72; k++) {
+      kmod = k % 12;
+      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;
+      }
     }
   }
-  AssertFatal(re==864,"RE count not equal to 864\n");
+  AssertFatal(re == 864, "RE count not equal to 864 (%d)\n", re);
 }
 
-extern uint8_t *generate_dci0(uint8_t *dci,
-			      uint8_t *e,
-			      uint8_t DCI_LENGTH,
-			      uint8_t aggregation_level,
-			      uint16_t rnti);
+// this table is the allocation of modulated MPDCCH format 5 symbols to REs, antenna ports 107,108
+// start symbol is symbol 2 and L'=24 => all 6 PRBs in the set
+// 8 symbols without DMRS = 8*12*6 REs = 576 REs
+// 4 symbols with DMRS (3 REs stolen per symbol = 4*9*6 REs = 216 REs
+// Total = 576+216 = 792 REs = 1584 bits
+static uint16_t mpdcch5ss2tab[792];
 
-void generate_mdci_top(PHY_VARS_eNB *eNB, int frame, int subframe,int16_t amp,int32_t **txdataF) {
+void init_mpdcch5ss2tab_normal_regular_subframe_evenNRBDL(PHY_VARS_eNB * eNB)
+{
+  int             l, k, kmod, re=0;
+  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");
+  for (l = 2; l < 14; l++) {
+    for (k = 0; k < 72; k++) {
+      kmod = k % 12;
+      if ((((l == 4)||(l==11)) && (kmod != nushiftp3) && (kmod != (nushiftp3+6))) ||
+	  ((l == 7) && (kmod != nushift) &&(kmod != (nushift+6)))) {  // CS RS
+	mpdcch5ss2tab[re] = (l * eNB->frame_parms.ofdm_symbol_size) + k;
+	re++;
+      }
+      if (((l!=4)&&(l!=7)&&(l!=11)) &&
+	  (((l != 5) && (l != 6) && (l != 12) && (l != 13)) || (kmod == 2) || (kmod == 3) || (kmod == 4) || (kmod == 7) || (kmod == 8) || (kmod == 9))) {
+	mpdcch5ss2tab[re] = (l * eNB->frame_parms.ofdm_symbol_size) + k;
+	re++;
+      }
+    }
+  }
+  AssertFatal(re == 684, "RE count not equal to 684\n");
+}
 
-  LTE_eNB_MPDCCH *mpdcch= &eNB->mpdcch_vars[subframe&2];
-  mDCI_ALLOC_t *mdci;
-  int coded_bits;
-  LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
-  int i;
-  int gain_lin_QPSK;
+// this table is the allocation of modulated MPDCCH format 5 symbols to REs, antenna ports 107,108
+// start symbol is symbol 3 and L'=24 => all 6 PRBs in the set
+// 7 symbols without DMRS = 7*12*6 REs = 504 REs
+// 4 symbols with DMRS (3 REs stolen per symbol = 4*9*6 REs = 216 REs
+// Total = 504+216 = 720 REs = 1440 bits
+static uint16_t mpdcch5ss3tab[720];
+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");
+  for (l = 3; l < 14; l++) {
+    for (k = 0; k < 72; k++) {
+      kmod = k % 12;
+      if (((l != 5) && (l != 6) && (l != 12) && (l != 13)) || (kmod == 2) || (kmod == 3) || (kmod == 4) || (kmod == 7) || (kmod == 8) || (kmod == 9)) {
+	mpdcch5ss3tab[re] = (l * eNB->frame_parms.ofdm_symbol_size) + k;
+	re++;
+      } else if ((kmod == 0) || (kmod == 5) || (kmod == 10)) {
+	mpdcch5ss3tab[re++] = (l * eNB->frame_parms.ofdm_symbol_size) + k;
+      }
+    }
+  }
+  AssertFatal(re == 720, "RE count not equal to 792\n");
+}
 
-  for (i=0;i<mpdcch->num_dci;i++) {
-    mdci = &mpdcch->mdci_alloc[i];
+// this table is the allocation of modulated MPDCCH format 3 symbols to REs, antenna ports 107,108
+// with start symbol 1, using L'=16 => first 4 PRBs in the set
+// 8 symbols without DMRS = 9*12*4 REs = 432 REs
+// 4 symbols with DMRS (3 REs stolen per symbol = 4*9*4 REs = 144 REs
+// Total = 432+144 = 576 = 16CCE*36RE/CCE
+static uint16_t mpdcch3ss1tab[576];
 
+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");
+  for (l = 1, re = 0; l < 14; l++) {
+    for (k = 0; k < 48; k++) {
+      kmod = k % 12;
+      if (((l != 5) && (l != 6) && (l != 12) && (l != 13)) || (((l == 5) || (l == 6) || (l == 12) || (l == 13)) && (kmod != 0) && (kmod != 5) && (kmod != 10))) {
+	mpdcch3ss1tab[re] = (l * eNB->frame_parms.ofdm_symbol_size) + k;
+	re++;
+      }
+    }
+  }
+  AssertFatal(re == 576, "RE count not equal to 864\n");
+}
 
-    AssertFatal(fp->frame_type==FDD,"TDD is not yet supported for MPDCCH\n");
-    AssertFatal(fp->Ncp == NORMAL,"Extended Prefix not yet supported for MPDCCH\n");
-    AssertFatal(mdci->L<=24,"L is %d\n",mdci->L);
-    AssertFatal(fp->N_RB_DL==50 || fp->N_RB_DL==100,"Only N_RB_DL=50,100 for MPDCCH\n");
-    // Force MPDDCH format 5
-    AssertFatal(mdci->number_of_prb_pairs==6,"2 or 4 PRB pairs not support yet for MPDCCH\n");
-    AssertFatal(mdci->reps>0,"mdci->reps==0\n");
+// this table is the allocation of modulated MPDCCH format 2 symbols to REs, antenna ports 107,108
+// with start symbol 1, using L'=8 => last 2 PRBs in the set
+// 8 symbols without DMRS = 9*12*2 REs = 216 REs
+// 4 symbols with DMRS (3 REs stolen per symbol = 4*9*2 REs = 72 REs
+// Total = 216+72 = 288 = 8CCE*36RE/CCE
+static uint16_t mpdcch2ss1tab[288];
+
+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");
+  for (l = 1, re = 0; l < 14; l++) {
+    for (k = 0; k < 24; k++) {
+      kmod = k % 12;
+      if (((l != 5) && (l != 6) && (l != 12) && (l != 13)) || (((l == 5) || (l == 6) || (l == 12) || (l == 13)) && (kmod != 0) && (kmod != 5) && (kmod != 10))) {
+	mpdcch2ss1tab[re] = (l * eNB->frame_parms.ofdm_symbol_size) + k;
+	re++;
+      }
+    }
+  }
+  AssertFatal(re == 288, "RE count not equal to 288\n");
+}
+
+
+
+
+extern uint8_t *generate_dci0(uint8_t * dci, uint8_t * e, uint8_t DCI_LENGTH, uint16_t coded_bits, uint16_t rnti);
 
-    // 9 REs/EREG * 4 EREG/ECCE => 36 REs/ECCE => 72 bits/ECCE, so same as regular PDCCH channel encoding
+
+uint16_t        mpdcch_dmrs_tab[12 * 6];
+
+void init_mpdcch_dmrs_tab(uint16_t oss)
+{
+
+  int             re = 5 * oss;
+  int             pos = 0;
+
+  for (int symb = 0; symb < 4; symb++) {
+    for (int prb = 0; prb < 6; prb++, re += 12) {
+      mpdcch_dmrs_tab[pos++] = re;
+      mpdcch_dmrs_tab[pos++] = re + 5;
+      mpdcch_dmrs_tab[pos++] = re + 10;
+    }
+    if (symb == 0)
+      re = 6 * oss;
+    else if (symb == 1)
+      re = 12 * oss;
+    else if (symb == 2)
+      re = 13 * oss;
+  }
+
+}
+
+void generate_mdci_top(PHY_VARS_eNB * eNB, int frame, int subframe, int16_t amp, int32_t ** txdataF)
+{
+
+  LTE_eNB_MPDCCH *mpdcch = &eNB->mpdcch_vars[subframe & 1];
+  mDCI_ALLOC_t   *mdci;
+  int             coded_bits;
+  LTE_DL_FRAME_PARMS *fp = &eNB->frame_parms;
+  int             i;
+  int             gain_lin_QPSK;
+  uint16_t       *mpdcchtab;
+
+  uint32_t        x1, x2, s = 0;
+  uint8_t         Nacc = 4;
+  uint16_t        j0, j, idelta;
+  uint16_t        i0;
+
+  int             off=0;
+
+  // Assumption: only handle a single MPDCCH per narrowband
+
+  int nsymb = (fp->Ncp==0) ? 14:12;
+
+  int symbol_offset = (uint32_t)fp->ofdm_symbol_size*(subframe*nsymb);
+
+  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);
+
+  for (i = 0; i < mpdcch->num_dci; i++) {
+    mdci = &mpdcch->mdci_alloc[i];
+
+    AssertFatal(fp->frame_type == FDD, "TDD is not yet supported for MPDCCH\n");
+    AssertFatal(fp->Ncp == NORMAL, "Extended Prefix not yet supported for MPDCCH\n");
+    AssertFatal(mdci->L <= 24, "L is %d\n", mdci->L);
+    AssertFatal(fp->N_RB_DL == 50 || fp->N_RB_DL == 100, "Only N_RB_DL=50,100 for MPDCCH\n");
+    // Force MPDDCH format 5
+    AssertFatal(mdci->number_of_prb_pairs == 6, "2 or 4 PRB pairs not support yet for MPDCCH\n");
+
+    // These are to avoid unimplemented things
+    AssertFatal(mdci->ce_mode == 1, "CE mode (%d) B not activated yet\n", mdci->ce_mode);
+    AssertFatal(mdci->L == 24, "Only 2+4 and aggregation 24 for now\n");
+    int     a_index=mdci->rnti & 3;
+
+    i0 = mdci->i0;
+    // antenna index
+
+    if (mdci->start_symbol == 1)  {
+      mpdcchtab = mpdcch5ss1tab;
+      coded_bits = 756*2;
+    } else if (mdci->start_symbol == 2) {
+      mpdcchtab = mpdcch5ss2tab;
+      coded_bits=684*2;
+    } else if (mdci->start_symbol == 3) {
+      mpdcchtab = mpdcch5ss3tab;
+      coded_bits = 612*2;
+    } 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",
+	  i, mdci->dci_length,mdci->rnti,
+	  mdci->L, mdci->number_of_prb_pairs,
+	  mdci->ce_mode,
+	  mdci->transmission_type == 1? "dist" : "loc",
+	  mdci->i0, mdci->start_symbol,
+	  coded_bits);
 
     // Note: We only have to run this every Nacc subframes during repetitions, data and scrambling are constant, but we do it for now to simplify during testing
 
-    generate_dci0(mdci->dci_pdu,
-		  mpdcch->e+(72*mdci->firstCCE),
-		  mdci->dci_length,
-		  mdci->L,
-		  mdci->rnti);
+    generate_dci0(mdci->dci_pdu, mpdcch->e, mdci->dci_length, coded_bits, mdci->rnti);
+
 
-    
-    coded_bits = 72 * mdci->L;
 
     // scrambling
-    uint16_t absSF = (frame*10)+subframe; 
+    uint16_t        absSF = (frame * 10) + subframe;
 
-    AssertFatal(absSF < 1024,
-		"Absolute subframe %d = %d*10 + %d > 1023\n",
-		absSF,frame,subframe);
+    AssertFatal(absSF < 10240, "Absolute subframe %d = %d*10 + %d > 10239\n", absSF, frame, subframe);
 
-    mpdcch_scrambling(fp,
-		      mdci,
-		      absSF,
-		      mpdcch->e+(72*mdci->firstCCE),
-		      coded_bits);
+    mpdcch_scrambling(fp, mdci, absSF, mpdcch->e, coded_bits);
 
     // Modulation for PDCCH
-    if (fp->nb_antenna_ports_eNB==1)
-      gain_lin_QPSK = (int16_t)((amp*ONE_OVER_SQRT2_Q15)>>15);
+    if (fp->nb_antenna_ports_eNB == 1)
+      gain_lin_QPSK = (int16_t) ((amp * ONE_OVER_SQRT2_Q15) >> 15);
     else
-      gain_lin_QPSK = amp/2;
+      gain_lin_QPSK = amp / 2;
 
-    uint8_t *e_ptr = mpdcch->e;
+    uint8_t        *e_ptr = mpdcch->e;
 
     //    if (mdci->transmission_type==0) nprime=mdci->rnti&3; // for Localized 2+4 we use 6.8B.5 rule
     // map directly to one antenna port for now
@@ -183,20 +356,135 @@ void generate_mdci_top(PHY_VARS_eNB *eNB, int frame, int subframe,int16_t amp,in
     // first RE of narrowband
     // mpdcchtab5 below contains the mapping from each coded symbol to relative RE avoiding the DMRS
 
+    int             nb_i0;
+    switch (fp->N_RB_DL) {
+
+    case 6:
+    case 25:
+      nb_i0 = 0;
+      break;
+    case 15:
+    case 50:
+    case 75:
+      nb_i0 = 1;
+      break;
+    case 100:
+      nb_i0 = 2;
+      break;
+    default:
+      AssertFatal(1 == 0, "Illegal N_RB_DL %d\n", fp->N_RB_DL);
+      break;
+    }
 
-    int re_offset = fp->first_carrier_offset + 1 + ((fp->N_RB_DL==100)?1:0) + mdci->narrowband*12*6;
-    if (re_offset>fp->ofdm_symbol_size) re_offset-=(fp->ofdm_symbol_size-1);
-    int32_t *txF = &txdataF[0][re_offset];
-    int32_t yIQ;
+    int             re_offset = fp->first_carrier_offset + (12 * nb_i0) + (mdci->narrowband * 12 * 6);
+    if (re_offset > fp->ofdm_symbol_size)
+      re_offset -= (fp->ofdm_symbol_size - 1);
+    int32_t        *txF = &txdataF[0][symbol_offset+re_offset];
+    int32_t         yIQ;
 
-    for (i=0; i<(coded_bits>>1); i++) {
+    for (i = 0; i < (coded_bits >> 1); i++) {
       // QPSK modulation to yIQ
-      ((int16_t*)&yIQ)[0] = (*e_ptr == 1) ? -gain_lin_QPSK : gain_lin_QPSK; e_ptr++;
-      ((int16_t*)&yIQ)[1] = (*e_ptr == 1) ? -gain_lin_QPSK : gain_lin_QPSK; e_ptr++;
-      txF[mpdcch5tab[i+(36*mdci->firstCCE)]] = yIQ;
+      ((int16_t *) & yIQ)[0] = (*e_ptr == 1) ? -gain_lin_QPSK : gain_lin_QPSK;
+      e_ptr++;
+      ((int16_t *) & yIQ)[1] = (*e_ptr == 1) ? -gain_lin_QPSK : gain_lin_QPSK;
+      e_ptr++;
+      txF[mpdcchtab[i]] = yIQ;
+      /*
+      LOG_I(PHY,"Frame %d, subframe %d: mpdcch pos %d (%d,%d) => (%d,%d)\n",
+	    frame,subframe,i,mpdcchtab[i]+re_offset,mpdcchtab[i]/fp->ofdm_symbol_size,
+	    ((int16_t *) & yIQ)[0],((int16_t *) & yIQ)[1]);*/
     }
 
-  }
-} 
+    if (mdci->transmission_type == 1) w=0; // distributed
+    else w = wp[a_index&1];
+    // pilot scrambling initiatlization (note: this is for a single repetition)
+
+    // x1 is set in lte_gold_generic
+
+    // rule for BL/CE UEs from Section 6.10.3A.1 in 36.211
+
+    if ((mdci->rnti == 0xFFFE) || (mdci->ce_mode == 2))     // CEModeB Note: also for mdci->rnti==SC_RNTI
+      Nacc = fp->frame_type == FDD ? 4 : 10;
+    else
+      Nacc = 1;
+
+    if (fp->frame_type == FDD || Nacc == 1)
+      idelta = 0;
+    else
+      idelta = Nacc - 2;
+
+    j0 = (i0 + idelta) / Nacc;
+    j = (absSF - i0) / Nacc;
+
+
+
+    uint32_t        a = ((((j0 + j) * Nacc) % 10) + 1);
+    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);
+
+    // add MPDCCH pilots
+    int             reset = 1;
+
+    int first_prb = (mdci->narrowband*6) + nb_i0;
+    int last_prb  = (mdci->narrowband*6) + nb_i0 + 5;
+    int soffset[4] = {5,6,12,13};
+
+
+    for (int lprime=0,i=0;lprime<4;lprime++) {
+      for (int nprb=0;nprb<110;nprb++) {
+	if (nprb<fp->N_RB_DL) {
+	  re_offset = fp->first_carrier_offset + (12 * nprb);
+	  if (re_offset > fp->ofdm_symbol_size)
+	    re_offset -= (fp->ofdm_symbol_size - 1);
+	  txF = &txdataF[0][symbol_offset + re_offset + fp->ofdm_symbol_size*soffset[lprime]];
+	}
+	for (int mprime=0;mprime<3;mprime++,i+=2) {
+
+	  if ((i & 0x1f) == 0) {
+	    s = lte_gold_generic(&x1, &x2, reset);
+	    reset = 0;
+	  }
+
+	  // select PRBs corresponding to narrowband
+	  if ((nprb>= first_prb) &&
+	      (nprb<= last_prb)) {
+	    ((int16_t *) & yIQ)[0] = (((s >> (i & 0x1f)) & 1) == 1) ? -gain_lin_QPSK : gain_lin_QPSK;
+	    ((int16_t *) & yIQ)[1] = (((s >> ((i + 1) & 0x1f)) & 1) == 1) ? -gain_lin_QPSK : gain_lin_QPSK;
+	    AssertFatal(mdci->transmission_type==1,"transmission_type %d!=1, handle this ...\n",mdci->transmission_type);
+	    if (mdci->transmission_type==1) { // same thing on both 107 and 109
+	      txF[(5*mprime)] = yIQ;
+	      txF[1+(5*mprime)] = yIQ;
+	    }
+	    else { // put on selected antenna port with w sequence
+
+	      if (((mprime+nprb)&1) == 0)
+		txF[off+(5*mprime)] = yIQ*w[lprime];
+	      else
+		txF[off+(5*mprime)] = yIQ*w[3-lprime];
+	    }
+	    /*
+	    LOG_I(PHY, "mpdcch_dmrs pos (dist %d, l %d,nprb %d,mprime %d) %d  => (%d,%d)\n",
+		  mdci->transmission_type, soffset[lprime],nprb,mprime,
+		  re_offset + fp->ofdm_symbol_size*soffset[lprime]+(5*mprime),
+		  ((int16_t *) & yIQ)[0], ((int16_t *) & yIQ)[1]);*/
+	  } // narrowband condition
+	} // RE (m') loop
+      } // nprb loop
+    } // symbol (l') loop
+  } // num_dci loop
+}
+
+void init_mpdcch(PHY_VARS_eNB * eNB)
+{
+
+  init_mpdcch5ss1tab_normal_regular_subframe_evenNRBDL(eNB);
+  init_mpdcch5ss2tab_normal_regular_subframe_evenNRBDL(eNB);
+  init_mpdcch5ss3tab_normal_regular_subframe_evenNRBDL(eNB);
+  init_mpdcch3ss1tab_normal_regular_subframe_evenNRBDL(eNB);
+  init_mpdcch2ss1tab_normal_regular_subframe_evenNRBDL(eNB);
+  init_mpdcch_dmrs_tab(eNB->frame_parms.ofdm_symbol_size);
+}
 
 #endif
diff --git a/openair1/PHY/LTE_TRANSPORT/if4_tools.c b/openair1/PHY/LTE_TRANSPORT/if4_tools.c
index 8a56105f673e6da2ff0968ddec819781a6572190..8898d9d3e3a545a7cca91445137dbea4eacf96d0 100644
--- a/openair1/PHY/LTE_TRANSPORT/if4_tools.c
+++ b/openair1/PHY/LTE_TRANSPORT/if4_tools.c
@@ -47,7 +47,7 @@ void send_IF4p5(RU_t *ru, int frame, int subframe, uint16_t packet_type) {
   int32_t **txdataF          = ru->common.txdataF_BF;
   int32_t **rxdataF          = ru->common.rxdataF;
   int16_t **prach_rxsigF     = ru->prach_rxsigF;  
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   int16_t ***prach_rxsigF_br = ru->prach_rxsigF_br;
 #endif
   void *tx_buffer            = ru->ifbuffer.tx[subframe&1];
@@ -150,6 +150,7 @@ void send_IF4p5(RU_t *ru, int frame, int subframe, uint16_t packet_type) {
 
 	for (element_id=0; element_id<db_halflength; element_id+=8) {
 	  i = (uint16_t*) &rx0[element_id];
+
           d = (uint16_t*) &data_block[element_id];
           d[0] = ((uint16_t) lin2alaw_if4p5[i[0]])  | ((uint16_t)(lin2alaw_if4p5[i[1]]<<8));
           d[1] = ((uint16_t) lin2alaw_if4p5[i[2]])  | ((uint16_t)(lin2alaw_if4p5[i[3]]<<8));
@@ -221,7 +222,7 @@ void send_IF4p5(RU_t *ru, int frame, int subframe, uint16_t packet_type) {
 
     int16_t *rxF;
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
     if (packet_type > IF4p5_PRACH)
       rxF = &prach_rxsigF_br[packet_type - IF4p5_PRACH - 1][0][0];
     else 
@@ -262,7 +263,7 @@ void recv_IF4p5(RU_t *ru, int *frame, int *subframe, uint16_t *packet_type, uint
   int32_t **txdataF          = ru->common.txdataF_BF;
   int32_t **rxdataF          = ru->common.rxdataF;
   int16_t **prach_rxsigF     = ru->prach_rxsigF;  
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   int16_t ***prach_rxsigF_br = ru->prach_rxsigF_br;
 #endif
   void *rx_buffer            = ru->ifbuffer.rx;
@@ -359,7 +360,7 @@ void recv_IF4p5(RU_t *ru, int *frame, int *subframe, uint16_t *packet_type, uint
 
     int16_t *rxF;
     
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
     if (*packet_type > IF4p5_PRACH)
       rxF = &prach_rxsigF_br[*packet_type - IF4p5_PRACH - 1][0][0];
     else 
diff --git a/openair1/PHY/LTE_TRANSPORT/mcs_tbs_tools.h b/openair1/PHY/LTE_TRANSPORT/mcs_tbs_tools.h
deleted file mode 100644
index 59959a90fd3b8203cb59a52c963a5e30229ba8da..0000000000000000000000000000000000000000
--- a/openair1/PHY/LTE_TRANSPORT/mcs_tbs_tools.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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
- */
-
-#define modOrder(I_MCS,I_TBS) ((I_MCS-I_TBS)*2+2) // Find modulation order from I_TBS and I_MCS
-
-/** \fn unsigned char I_TBS2I_MCS(unsigned char I_TBS);
-\brief This function maps I_tbs to I_mcs according to Table 7.1.7.1-1 in 3GPP TS 36.213 V8.6.0. Where there is two supported modulation orders for the same I_TBS then either high or low modulation is chosen by changing the equality of the two first comparisons in the if-else statement.
-\param I_TBS Index of Transport Block Size
-\return I_MCS given I_TBS
-*/
-unsigned char I_TBS2I_MCS(unsigned char I_TBS);
-
-/** \fn unsigned char SE2I_TBS(float SE,
-        unsigned char N_PRB,
-        unsigned char symbPerRB);
-\brief This function maps a requested throughput in number of bits to I_tbs. The throughput is calculated as a function of modulation order, RB allocation and number of symbols per RB. The mapping orginates in the "Transport block size table" (Table 7.1.7.2.1-1 in 3GPP TS 36.213 V8.6.0)
-\param SE Spectral Efficiency (before casting to integer, multiply by 1024, remember to divide result by 1024!)
-\param N_PRB Number of PhysicalResourceBlocks allocated \sa lte_frame_parms->N_RB_DL
-\param symbPerRB Number of symbols per resource block allocated to this channel
-\return I_TBS given an SE and an N_PRB
-*/
-unsigned char SE2I_TBS(float SE,
-                       unsigned char N_PRB,
-                       unsigned char symbPerRB);
diff --git a/openair1/PHY/LTE_TRANSPORT/mdci.h b/openair1/PHY/LTE_TRANSPORT/mdci.h
index 7be278530860fc88792c315130f62e84d77d4292..3cb6380625b0c9b1780ae6605ec63fa1f2f30e50 100644
--- a/openair1/PHY/LTE_TRANSPORT/mdci.h
+++ b/openair1/PHY/LTE_TRANSPORT/mdci.h
@@ -59,7 +59,9 @@ struct DCI6_0A_5MHz {
   /// Modulation and Coding Scheme and Redundancy Version
   uint32_t mcs:4;
   /// RB Assignment (ceil(log2(floor(N_RB_UL/6))) + 5 bits)
-  uint32_t rballoc:7;
+  uint32_t rballoc:5;
+  /// narrowband index log2(floor(N_RB_DL/6))) bits
+  uint32_t narrowband:2;
   /// Hopping flag
   uint32_t hopping:1;
   /// type = 0 => DCI Format 0, type = 1 => DCI Format 1A
@@ -92,7 +94,9 @@ struct DCI6_1A_5MHz {
   /// Modulation and Coding Scheme and Redundancy Version
   uint32_t mcs:4;
   /// Resource block assignment (assignment flag = 0 for 5 MHz, ceil(log2(floor(N_RB_DL/6)))+5)
-  uint32_t rballoc:7;
+  uint32_t rballoc:5;
+  /// narrowband index log2(floor(N_RB_DL/6))) bits
+  uint32_t narrowband:2;
   /// Frequency hopping flag
   uint32_t hopping:1;
   /// 0/1A differentiator
@@ -125,7 +129,9 @@ struct DCI6_0A_10MHz {
   /// Modulation and Coding Scheme and Redundancy Version
   uint32_t mcs:4;
   /// RB Assignment (ceil(log2(floor(N_RB_UL/6))) + 5 bits)
-  uint32_t rballoc:8;
+  uint32_t rballoc:5;
+  /// narrowband index log2(floor(N_RB_DL/6))) bits
+  uint32_t narrowband:3;
   /// Hopping flag
   uint32_t hopping:1;
   /// type = 0 => DCI Format 0, type = 1 => DCI Format 1A
@@ -138,7 +144,7 @@ typedef struct DCI6_0A_10MHz DCI6_0A_10MHz_t;
 /// basic DCI Format Type 6-1A (10 MHz, FDD primary carrier,  24 bits, 5 bit format, TM!=9,TM!=6, no scheduling enhancement)
 struct DCI6_1A_10MHz {
   /// padding to fill 32-bit word
-  uint32_t padding:4;
+  uint32_t padding:3;
   /// DCI subframe repetition number 
   uint32_t dci_rep:2;
   /// HARQ-ACK resource offset
@@ -157,8 +163,10 @@ struct DCI6_1A_10MHz {
   uint32_t rep:2;
   /// Modulation and Coding Scheme and Redundancy Version
   uint32_t mcs:4;
-  /// Resource block assignment (assignment flag = 0 for 10 MHz, ceil(log2(floor(N_RB_DL/6)))+5)
-  uint32_t rballoc:8;
+  /// Resource block assignment
+  uint32_t rballoc:5;
+  /// narrowband index log2(floor(N_RB_DL/6))) bits
+  uint32_t narrowband:3;
   /// Frequency hopping flag
   uint32_t hopping:1;
   /// 0/1A differentiator
@@ -191,7 +199,9 @@ struct DCI6_0A_20MHz {
   /// Modulation and Coding Scheme and Redundancy Version
   uint32_t mcs:4;
   /// RB Assignment (ceil(log2(floor(N_RB_UL/6))) + 5 bits)
-  uint32_t rballoc:9;
+  uint32_t rballoc:5;
+  /// narrowband index log2(floor(N_RB_DL/6))) bits
+  uint32_t narrowband:4;
   /// Hopping flag
   uint32_t hopping:1;
   /// type = 0 => DCI Format 0, type = 1 => DCI Format 1A
@@ -224,7 +234,9 @@ struct DCI6_1A_20MHz {
   /// Modulation and Coding Scheme and Redundancy Version
   uint32_t mcs:4;
   /// Resource block assignment (assignment flag = 0 for 20 MHz, ceil(log2(floor(N_RB_DL/6)))+5)
-  uint32_t rballoc:9;
+  uint32_t rballoc:5;
+  /// narrowband index log2(floor(N_RB_DL/6))) bits
+  uint32_t narrowband:4;
   /// Frequency hopping flag
   uint32_t hopping:1;
   /// 0/1A differentiator
diff --git a/openair1/PHY/LTE_TRANSPORT/pbch.c b/openair1/PHY/LTE_TRANSPORT/pbch.c
index a27c6dbc9087d5b045104b16615c92c3c78b86b7..37997c94b49e97b8acd53c83673e75dc0caac716 100644
--- a/openair1/PHY/LTE_TRANSPORT/pbch.c
+++ b/openair1/PHY/LTE_TRANSPORT/pbch.c
@@ -308,7 +308,7 @@ int generate_pbch(LTE_eNB_PBCH *eNB_pbch,
 
 #ifdef DEBUG_PBCH
     if (frame_mod4==0) {
-      LOG_M"pbch_e.m","pbch_e",
+      LOG_M("pbch_e.m","pbch_e",
                    eNB_pbch->pbch_e,
                    pbch_E,
                    1,
@@ -325,7 +325,7 @@ int generate_pbch(LTE_eNB_PBCH *eNB_pbch,
                     pbch_E);
 #ifdef DEBUG_PBCH
     if (frame_mod4==0) {
-      LOG_M"pbch_e_s.m","pbch_e_s",
+      LOG_M("pbch_e_s.m","pbch_e_s",
                    eNB_pbch->pbch_e,
                    pbch_E,
                    1,
diff --git a/openair1/PHY/LTE_TRANSPORT/phich.c b/openair1/PHY/LTE_TRANSPORT/phich.c
index cc466ce3e2a026632963cfb07bf9704a35dd2db6..dd82699fe9018df7645b73bd0305bf779d097046 100644
--- a/openair1/PHY/LTE_TRANSPORT/phich.c
+++ b/openair1/PHY/LTE_TRANSPORT/phich.c
@@ -705,7 +705,7 @@ void generate_phich(LTE_DL_FRAME_PARMS *frame_parms,
 
 
 void generate_phich_top(PHY_VARS_eNB *eNB,
-                        eNB_rxtx_proc_t *proc,
+                        L1_rxtx_proc_t *proc,
 			int16_t amp)
 {
 
diff --git a/openair1/PHY/LTE_TRANSPORT/phich_common.c b/openair1/PHY/LTE_TRANSPORT/phich_common.c
index a3bc5250d5f79699e693cc77fd4855905a946801..72e9ad134ab60a1eb0b52e88140769783a8d90a9 100644
--- a/openair1/PHY/LTE_TRANSPORT/phich_common.c
+++ b/openair1/PHY/LTE_TRANSPORT/phich_common.c
@@ -33,105 +33,98 @@
 #include "PHY/defs_eNB.h"
 
 
-uint8_t get_mi(LTE_DL_FRAME_PARMS *frame_parms,uint8_t subframe)
-{
-
+uint8_t get_mi(LTE_DL_FRAME_PARMS *frame_parms,uint8_t subframe) {
   // for FDD
   if (frame_parms->frame_type == FDD)
     return 1;
 
   // for TDD
   switch (frame_parms->tdd_config) {
+    case 0:
+      if ((subframe==0) || (subframe==5))
+        return(2);
+      else return(1);
 
-  case 0:
-    if ((subframe==0) || (subframe==5))
-      return(2);
-    else return(1);
+      break;
 
-    break;
+    case 1:
+      if ((subframe==0) || (subframe==5))
+        return(0);
+      else return(1);
 
-  case 1:
-    if ((subframe==0) || (subframe==5))
-      return(0);
-    else return(1);
+      break;
 
-    break;
+    case 2:
+      if ((subframe==3) || (subframe==8))
+        return(1);
+      else return(0);
 
-  case 2:
-    if ((subframe==3) || (subframe==8))
-      return(1);
-    else return(0);
+      break;
 
-    break;
+    case 3:
+      if ((subframe==0) || (subframe==8) || (subframe==9))
+        return(1);
+      else return(0);
 
-  case 3:
-    if ((subframe==0) || (subframe==8) || (subframe==9))
-      return(1);
-    else return(0);
+      break;
 
-    break;
+    case 4:
+      if ((subframe==8) || (subframe==9))
+        return(1);
+      else return(0);
 
-  case 4:
-    if ((subframe==8) || (subframe==9))
-      return(1);
-    else return(0);
-
-    break;
+      break;
 
-  case 5:
-    if (subframe==8)
-      return(1);
-    else return(0);
+    case 5:
+      if (subframe==8)
+        return(1);
+      else return(0);
 
-    break;
+      break;
 
-  case 6:
-    return(1);
-    break;
+    case 6:
+      return(1);
+      break;
 
-  default:
-    return(0);
+    default:
+      return(0);
   }
 }
 
-unsigned char subframe2_ul_harq(LTE_DL_FRAME_PARMS *frame_parms,unsigned char subframe)
-{
-
+unsigned char subframe2_ul_harq(LTE_DL_FRAME_PARMS *frame_parms,unsigned char subframe) {
   if (frame_parms->frame_type == FDD)
     return(subframe&7);
 
   switch (frame_parms->tdd_config) {
-  case 3:
-    if ( (subframe == 8) || (subframe == 9) ) {
-      return(subframe-8);
-    } else if (subframe==0)
-      return(2);
-    else {
-      LOG_E(PHY,"phich.c: subframe2_ul_harq, illegal subframe %d for tdd_config %d\n",
-            subframe,frame_parms->tdd_config);
-      return(0);
-    }
-
-    break;
-
-  case 4:
-     if ( (subframe == 8) || (subframe == 9) ) {
-       return(subframe-8);
-     } else {
-       LOG_E(PHY,"phich.c: subframe2_ul_harq, illegal subframe %d for tdd_config %d\n",
-             subframe,frame_parms->tdd_config);
-       return(0);
-     }
-
-     break;
-
+    case 3:
+      if ( (subframe == 8) || (subframe == 9) ) {
+        return(subframe-8);
+      } else if (subframe==0)
+        return(2);
+      else {
+        LOG_E(PHY,"phich.c: subframe2_ul_harq, illegal subframe %d for tdd_config %d\n",
+              subframe,frame_parms->tdd_config);
+        return(0);
+      }
+
+      break;
+
+    case 4:
+      if ( (subframe == 8) || (subframe == 9) ) {
+        return(subframe-8);
+      } else {
+        LOG_E(PHY,"phich.c: subframe2_ul_harq, illegal subframe %d for tdd_config %d\n",
+              subframe,frame_parms->tdd_config);
+        return(0);
+      }
+
+      break;
   }
 
   return(0);
 }
 
-int phich_frame2_pusch_frame(LTE_DL_FRAME_PARMS *frame_parms, int frame, int subframe)
-{
+int phich_frame2_pusch_frame(LTE_DL_FRAME_PARMS *frame_parms, int frame, int subframe) {
   int pusch_frame;
 
   if (frame_parms->frame_type == FDD) {
@@ -145,127 +138,124 @@ int phich_frame2_pusch_frame(LTE_DL_FRAME_PARMS *frame_parms, int frame, int sub
   return pusch_frame % 1024;
 }
 
-uint8_t phich_subframe2_pusch_subframe(LTE_DL_FRAME_PARMS *frame_parms,uint8_t subframe)
-{
+uint8_t phich_subframe2_pusch_subframe(LTE_DL_FRAME_PARMS *frame_parms,uint8_t subframe) {
   uint8_t pusch_subframe = 255;
 
   if (frame_parms->frame_type == FDD)
     return subframe < 4 ? subframe + 6 : subframe - 4;
 
   switch (frame_parms->tdd_config) {
-  case 0:
-    if (subframe == 0)
-      pusch_subframe = (3);
-    else if (subframe == 5) {
-      pusch_subframe = (8);
-    } else if (subframe == 6)
-      pusch_subframe = (2);
-    else if (subframe == 1)
-      pusch_subframe = (7);
-    else {
-      AssertFatal(1==0,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n",
-		  subframe,frame_parms->tdd_config);
+    case 0:
+      if (subframe == 0)
+        pusch_subframe = (3);
+      else if (subframe == 5) {
+        pusch_subframe = (8);
+      } else if (subframe == 6)
+        pusch_subframe = (2);
+      else if (subframe == 1)
+        pusch_subframe = (7);
+      else {
+        AssertFatal(1==0,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n",
+                    subframe,frame_parms->tdd_config);
+        pusch_subframe = (0);
+      }
+
+      break;
+
+    case 1:
+      if (subframe == 6)
+        pusch_subframe = (2);
+      else if (subframe == 9)
+        pusch_subframe = (3);
+      else if (subframe == 1)
+        pusch_subframe = (7);
+      else if (subframe == 4)
+        pusch_subframe = (8);
+      else {
+        AssertFatal(1==0,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n",
+                    subframe,frame_parms->tdd_config);
+        pusch_subframe = (0);
+      }
+
+      break;
+
+    case 2:
+      if (subframe == 8)
+        pusch_subframe = (2);
+      else if (subframe == 3)
+        pusch_subframe = (7);
+      else {
+        AssertFatal(1==0,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n",
+                    subframe,frame_parms->tdd_config);
+        pusch_subframe = (0);
+      }
+
+      break;
+
+    case 3:
+      if ( (subframe == 8) || (subframe == 9) ) {
+        pusch_subframe = (subframe-6);
+      } else if (subframe==0)
+        pusch_subframe = (4);
+      else {
+        AssertFatal(1==0,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n",
+                    subframe,frame_parms->tdd_config);
+        pusch_subframe = (0);
+      }
+
+      break;
+
+    case 4:
+      if ( (subframe == 8) || (subframe == 9) ) {
+        pusch_subframe = (subframe-6);
+      } else {
+        AssertFatal(1==0,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n",
+                    subframe,frame_parms->tdd_config);
+        pusch_subframe = (0);
+      }
+
+      break;
+
+    case 5:
+      if (subframe == 8) {
+        pusch_subframe = (2);
+      } else {
+        AssertFatal(1==0,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n",
+                    subframe,frame_parms->tdd_config);
+        pusch_subframe = (0);
+      }
+
+      break;
+
+    case 6:
+      if (subframe == 6) {
+        pusch_subframe = (2);
+      } else if (subframe == 9) {
+        pusch_subframe = (3);
+      } else if (subframe == 0) {
+        pusch_subframe = (4);
+      } else if (subframe == 1) {
+        pusch_subframe = (7);
+      } else if (subframe == 5) {
+        pusch_subframe = (8);
+      } else {
+        AssertFatal(1==0,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n",
+                    subframe,frame_parms->tdd_config);
+        pusch_subframe = (0);
+      }
+
+      break;
+
+    default:
+      AssertFatal(1==0, "no implementation for TDD UL/DL-config = %d!\n", frame_parms->tdd_config);
       pusch_subframe = (0);
-    }
-
-    break;
-
-  case 1:
-    if (subframe == 6)
-      pusch_subframe = (2);
-    else if (subframe == 9)
-      pusch_subframe = (3);
-    else if (subframe == 1)
-      pusch_subframe = (7);
-    else if (subframe == 4)
-      pusch_subframe = (8);
-    else {
-      AssertFatal(1==0,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n",
-            subframe,frame_parms->tdd_config);
-      pusch_subframe = (0);
-    }
-
-    break;
-
-  case 2:
-    if (subframe == 8)
-      pusch_subframe = (2);
-    else if (subframe == 3)
-      pusch_subframe = (7);
-    else {
-      AssertFatal(1==0,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n",
-            subframe,frame_parms->tdd_config);
-      pusch_subframe = (0);
-    }
-
-    break;
-
-  case 3:
-    if ( (subframe == 8) || (subframe == 9) ) {
-      pusch_subframe = (subframe-6);
-    } else if (subframe==0)
-      pusch_subframe = (4);
-    else {
-      AssertFatal(1==0,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n",
-            subframe,frame_parms->tdd_config);
-      pusch_subframe = (0);
-    }
-
-    break;
-
-  case 4:
-    if ( (subframe == 8) || (subframe == 9) ) {
-      pusch_subframe = (subframe-6);
-    } else {
-      AssertFatal(1==0,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n",
-            subframe,frame_parms->tdd_config);
-      pusch_subframe = (0);
-    }
-
-    break;
-
-  case 5:
-    if (subframe == 8) {
-      pusch_subframe = (2);
-    } else {
-      AssertFatal(1==0,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n",
-            subframe,frame_parms->tdd_config);
-      pusch_subframe = (0);
-    }
-
-    break;
-
-  case 6:
-    if (subframe == 6) {
-      pusch_subframe = (2);
-    } else if (subframe == 9) {
-      pusch_subframe = (3);
-    } else if (subframe == 0) {
-      pusch_subframe = (4);
-    } else if (subframe == 1) {
-      pusch_subframe = (7);
-    } else if (subframe == 5) {
-      pusch_subframe = (8);
-    } else {
-      AssertFatal(1==0,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n",
-            subframe,frame_parms->tdd_config);
-      pusch_subframe = (0);
-    }
-
-    break;
-
-  default:
-    AssertFatal(1==0, "no implementation for TDD UL/DL-config = %d!\n", frame_parms->tdd_config);
-    pusch_subframe = (0);
   }
 
   LOG_D(PHY, "subframe  %d: PUSCH subframe = %d\n", subframe, pusch_subframe);
   return pusch_subframe;
 }
 
-int check_pcfich(LTE_DL_FRAME_PARMS *frame_parms,uint16_t reg)
-{
-
+int check_pcfich(LTE_DL_FRAME_PARMS *frame_parms,uint16_t reg) {
   if ((reg == frame_parms->pcfich_reg[0]) ||
       (reg == frame_parms->pcfich_reg[1]) ||
       (reg == frame_parms->pcfich_reg[2]) ||
@@ -275,9 +265,7 @@ int check_pcfich(LTE_DL_FRAME_PARMS *frame_parms,uint16_t reg)
   return(0);
 }
 
-void generate_phich_reg_mapping(LTE_DL_FRAME_PARMS *frame_parms)
-{
-
+void generate_phich_reg_mapping(LTE_DL_FRAME_PARMS *frame_parms) {
   unsigned short n0 = (frame_parms->N_RB_DL * 2) - 4;  // 2 REG per RB less the 4 used by PCFICH in first symbol
   unsigned short n1 = (frame_parms->N_RB_DL * 3);      // 3 REG per RB in second and third symbol
   unsigned short n2 = n1;
@@ -285,11 +273,9 @@ void generate_phich_reg_mapping(LTE_DL_FRAME_PARMS *frame_parms)
   unsigned short Ngroup_PHICH;
   //  uint16_t *phich_reg = frame_parms->phich_reg;
   uint16_t *pcfich_reg = frame_parms->pcfich_reg;
-
   // compute Ngroup_PHICH (see formula at beginning of Section 6.9 in 36-211
   Ngroup_PHICH = (frame_parms->phich_config_common.phich_resource*frame_parms->N_RB_DL)/48;
 
-
   if (((frame_parms->phich_config_common.phich_resource*frame_parms->N_RB_DL)%48) > 0)
     Ngroup_PHICH++;
 
@@ -299,25 +285,24 @@ void generate_phich_reg_mapping(LTE_DL_FRAME_PARMS *frame_parms)
   }
 
 #ifdef DEBUG_PHICH
-  LOG_D(PHY,"Ngroup_PHICH %d (phich_config_common.phich_resource %d,phich_config_common.phich_duration %s, NidCell %d,Ncp %d, frame_type %d), smallest pcfich REG %d, n0 %d, n1 %d (first PHICH REG %d)\n",
-    ((frame_parms->Ncp == NORMAL)?Ngroup_PHICH:(Ngroup_PHICH>>1)),
-    frame_parms->phich_config_common.phich_resource,
-    frame_parms->phich_config_common.phich_duration==normal?"normal":"extended",
-    frame_parms->Nid_cell,frame_parms->Ncp,frame_parms->frame_type,
-    pcfich_reg[frame_parms->pcfich_first_reg_idx],
-    n0,
-    n1,
-    ((frame_parms->Nid_cell))%n0);
+  LOG_D(PHY,
+        "Ngroup_PHICH %d (phich_config_common.phich_resource %d,phich_config_common.phich_duration %s, NidCell %d,Ncp %d, frame_type %d), smallest pcfich REG %d, n0 %d, n1 %d (first PHICH REG %d)\n",
+        ((frame_parms->Ncp == NORMAL)?Ngroup_PHICH:(Ngroup_PHICH>>1)),
+        frame_parms->phich_config_common.phich_resource,
+        frame_parms->phich_config_common.phich_duration==normal?"normal":"extended",
+        frame_parms->Nid_cell,frame_parms->Ncp,frame_parms->frame_type,
+        pcfich_reg[frame_parms->pcfich_first_reg_idx],
+        n0,
+        n1,
+        ((frame_parms->Nid_cell))%n0);
 #endif
 
   // This is the algorithm from Section 6.9.3 in 36-211, it works only for normal PHICH duration for now ...
 
-  for (mprime=0; 
-       mprime<((frame_parms->Ncp == NORMAL)?Ngroup_PHICH:(Ngroup_PHICH>>1)); 
+  for (mprime=0;
+       mprime<((frame_parms->Ncp == NORMAL)?Ngroup_PHICH:(Ngroup_PHICH>>1));
        mprime++) {
-
     if (frame_parms->phich_config_common.phich_duration==normal) { // normal PHICH duration
-
       frame_parms->phich_reg[mprime][0] = (frame_parms->Nid_cell + mprime)%n0;
 
       if (frame_parms->phich_reg[mprime][0]>=pcfich_reg[frame_parms->pcfich_first_reg_idx])
@@ -334,10 +319,9 @@ void generate_phich_reg_mapping(LTE_DL_FRAME_PARMS *frame_parms)
 
       frame_parms->phich_reg[mprime][1] = (frame_parms->Nid_cell + mprime + (n0/3))%n0;
 
-      
       if (frame_parms->phich_reg[mprime][1]>=pcfich_reg[frame_parms->pcfich_first_reg_idx])
         frame_parms->phich_reg[mprime][1]++;
-      
+
       if (frame_parms->phich_reg[mprime][1]>=pcfich_reg[(frame_parms->pcfich_first_reg_idx+1)&3])
         frame_parms->phich_reg[mprime][1]++;
 
@@ -346,10 +330,9 @@ void generate_phich_reg_mapping(LTE_DL_FRAME_PARMS *frame_parms)
 
       if (frame_parms->phich_reg[mprime][1]>=pcfich_reg[(frame_parms->pcfich_first_reg_idx+3)&3])
         frame_parms->phich_reg[mprime][1]++;
-      
 
       frame_parms->phich_reg[mprime][2] = (frame_parms->Nid_cell + mprime + (2*n0/3))%n0;
-      
+
       if (frame_parms->phich_reg[mprime][2]>=pcfich_reg[frame_parms->pcfich_first_reg_idx])
         frame_parms->phich_reg[mprime][2]++;
 
@@ -361,21 +344,19 @@ void generate_phich_reg_mapping(LTE_DL_FRAME_PARMS *frame_parms)
 
       if (frame_parms->phich_reg[mprime][2]>=pcfich_reg[(frame_parms->pcfich_first_reg_idx+3)&3])
         frame_parms->phich_reg[mprime][2]++;
-      
+
 #ifdef DEBUG_PHICH
       printf("phich_reg :%d => %d,%d,%d\n",mprime,frame_parms->phich_reg[mprime][0],frame_parms->phich_reg[mprime][1],frame_parms->phich_reg[mprime][2]);
 #endif
     } else { // extended PHICH duration
       frame_parms->phich_reg[mprime<<1][0] = (frame_parms->Nid_cell + mprime)%n0;
       frame_parms->phich_reg[1+(mprime<<1)][0] = (frame_parms->Nid_cell + mprime)%n0;
-
       frame_parms->phich_reg[mprime<<1][1] = ((frame_parms->Nid_cell*n1/n0) + mprime + (n1/3))%n1;
       frame_parms->phich_reg[mprime<<1][2] = ((frame_parms->Nid_cell*n2/n0) + mprime + (2*n2/3))%n2;
-
       frame_parms->phich_reg[1+(mprime<<1)][1] = ((frame_parms->Nid_cell*n1/n0) + mprime + (n1/3))%n1;
       frame_parms->phich_reg[1+(mprime<<1)][2] = ((frame_parms->Nid_cell*n2/n0) + mprime + (2*n2/3))%n2;
       //#ifdef DEBUG_PHICH
-      printf("phich_reg :%d => %d,%d,%d\n",mprime<<1,frame_parms->phich_reg[mprime<<1][0],frame_parms->phich_reg[mprime][1],frame_parms->phich_reg[mprime][2]);
+      printf("phich_reg :%u => %d,%d,%d\n",mprime<<1,frame_parms->phich_reg[mprime<<1][0],frame_parms->phich_reg[mprime][1],frame_parms->phich_reg[mprime][2]);
       printf("phich_reg :%d => %d,%d,%d\n",1+(mprime<<1),frame_parms->phich_reg[1+(mprime<<1)][0],frame_parms->phich_reg[1+(mprime<<1)][1],frame_parms->phich_reg[1+(mprime<<1)][2]);
       //#endif
     }
diff --git a/openair1/PHY/LTE_TRANSPORT/pilots_mbsfn.c b/openair1/PHY/LTE_TRANSPORT/pilots_mbsfn.c
index fddc29b5242f4d005851fedf1b95b6d639619d24..475102b57c908cb66ee401139fe29e04998683c3 100644
--- a/openair1/PHY/LTE_TRANSPORT/pilots_mbsfn.c
+++ b/openair1/PHY/LTE_TRANSPORT/pilots_mbsfn.c
@@ -34,7 +34,7 @@
 #include "PHY/LTE_REFSIG/lte_refsig.h"
 
 int generate_mbsfn_pilot(PHY_VARS_eNB *eNB,
-			 eNB_rxtx_proc_t *proc,
+			 L1_rxtx_proc_t *proc,
                          int32_t **txdataF,
                          int16_t amp)
 
diff --git a/openair1/PHY/LTE_TRANSPORT/pmch.c b/openair1/PHY/LTE_TRANSPORT/pmch.c
index 23bc07f17448806c4c2a8563f47bf86f647fc024..6fab3dc59bd8e229708d7fe9dd3e32c3f249a6c5 100644
--- a/openair1/PHY/LTE_TRANSPORT/pmch.c
+++ b/openair1/PHY/LTE_TRANSPORT/pmch.c
@@ -83,7 +83,7 @@ void fill_eNB_dlsch_MCH(PHY_VARS_eNB *eNB,int mcs,int ndi,int rvidx)
 }
 
 
-void generate_mch(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,uint8_t *a)
+void generate_mch(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc,uint8_t *a)
 {
 
   int G;
diff --git a/openair1/PHY/LTE_TRANSPORT/prach.c b/openair1/PHY/LTE_TRANSPORT/prach.c
index ec0b7db4ad7d003398dfddd842f935f6639b0743..1d665682e01e0d80ea098601da3b72353b165ddb 100644
--- a/openair1/PHY/LTE_TRANSPORT/prach.c
+++ b/openair1/PHY/LTE_TRANSPORT/prach.c
@@ -34,42 +34,39 @@
 #include "PHY/phy_extern.h"
 //#include "prach.h"
 #include "PHY/LTE_TRANSPORT/if4_tools.h"
+
 #include "SCHED/sched_eNB.h"
 #include "common/utils/LOG/vcd_signal_dumper.h"
 #include "prach_extern.h"
 
-#if (RRC_VERSION < MAKE_VERSION(14, 0, 0))
-#define rx_prach0 rx_prach
+#if (LTE_RRC_VERSION < MAKE_VERSION(14, 0, 0))
+  #define rx_prach0 rx_prach
 #endif
 
 void rx_prach0(PHY_VARS_eNB *eNB,
-	       RU_t *ru,
-	       uint16_t *max_preamble,
-	       uint16_t *max_preamble_energy,
-	       uint16_t *max_preamble_delay,
-	       uint16_t Nf, 
-	       uint8_t tdd_mapindex
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-	       ,uint8_t br_flag,
-	       uint8_t ce_level
+               RU_t *ru,
+               uint16_t *max_preamble,
+               uint16_t *max_preamble_energy,
+               uint16_t *max_preamble_delay,
+               uint16_t Nf,
+               uint8_t tdd_mapindex
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  ,uint8_t br_flag,
+  uint8_t ce_level
 #endif
-	       )
-{
-
+              ) {
   int i;
-
-  LTE_DL_FRAME_PARMS *fp;
+  LTE_DL_FRAME_PARMS *fp=NULL;
   lte_frame_type_t   frame_type;
-  uint16_t           rootSequenceIndex;  
-  uint8_t            prach_ConfigIndex;   
-  uint8_t            Ncs_config;          
-  uint8_t            restricted_set;      
+  uint16_t           rootSequenceIndex;
+  uint8_t            prach_ConfigIndex;
+  uint8_t            Ncs_config;
+  uint8_t            restricted_set;
   uint8_t            n_ra_prb;
   int                subframe;
   int16_t            *prachF=NULL;
   int16_t            **rxsigF=NULL;
-  int                nb_rx;
-
+  int                nb_rx=0;
   int16_t *prach2;
   uint8_t preamble_index;
   uint16_t NCS,NCS2;
@@ -93,69 +90,71 @@ void rx_prach0(PHY_VARS_eNB *eNB,
   int16_t levdB;
   int fft_size,log2_ifft_size;
   int16_t prach_ifft_tmp[2048*2] __attribute__((aligned(32)));
-  int32_t *prach_ifft=(int32_t*)NULL;
+  int32_t *prach_ifft=(int32_t *)NULL;
   int32_t **prach_ifftp=(int32_t **)NULL;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   int prach_ifft_cnt=0;
 #endif
 
 
-  if (ru) { 
-    fp    = &ru->frame_parms;
-    nb_rx = ru->nb_rx;
-  }
-  else if (eNB) {
-    fp    = &eNB->frame_parms;
+  if(eNB)  {
+    fp    = &(eNB->frame_parms);
     nb_rx = fp->nb_antennas_rx;
+  } else {
+    fp    = &(ru->frame_parms);
+    nb_rx = ru->nb_rx;
   }
-  else AssertFatal(1==0,"rx_prach called without valid RU or eNB descriptor\n");
-  
+  AssertFatal(fp!=NULL,"rx_prach called without valid RU or eNB descriptor\n");
+
+  frame_type          = fp->frame_type;
+
   frame_type          = fp->frame_type;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   if (br_flag == 1) {
     AssertFatal(fp->prach_emtc_config_common.prach_Config_enabled==1,
-		"emtc prach_Config is not enabled\n");
+                "emtc prach_Config is not enabled\n");
     AssertFatal(fp->prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[ce_level]==1,
-		"ce_level %d is not active\n",ce_level);
+                "ce_level %d is not active\n",ce_level);
     rootSequenceIndex   = fp->prach_emtc_config_common.rootSequenceIndex;
     prach_ConfigIndex   = fp->prach_emtc_config_common.prach_ConfigInfo.prach_ConfigIndex[ce_level];
     Ncs_config          = fp->prach_emtc_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig;
     restricted_set      = fp->prach_emtc_config_common.prach_ConfigInfo.highSpeedFlag;
     n_ra_prb            = get_prach_prb_offset(fp,prach_ConfigIndex,
-					       fp->prach_emtc_config_common.prach_ConfigInfo.prach_FreqOffset[ce_level],
-					       tdd_mapindex,Nf);
+                          fp->prach_emtc_config_common.prach_ConfigInfo.prach_FreqOffset[ce_level],
+                          tdd_mapindex,Nf);
     // update pointers to results for ce_level
     max_preamble        += ce_level;
     max_preamble_energy += ce_level;
     max_preamble_delay  += ce_level;
-  }
-  else 
+  } else
 #endif
-    {
-      rootSequenceIndex   = fp->prach_config_common.rootSequenceIndex;
-      prach_ConfigIndex   = fp->prach_config_common.prach_ConfigInfo.prach_ConfigIndex;
-      Ncs_config          = fp->prach_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig;
-      restricted_set      = fp->prach_config_common.prach_ConfigInfo.highSpeedFlag;
-      n_ra_prb            = get_prach_prb_offset(fp,prach_ConfigIndex,
-						 fp->prach_config_common.prach_ConfigInfo.prach_FreqOffset,
-						 tdd_mapindex,Nf);
-    }
+  {
+    rootSequenceIndex   = fp->prach_config_common.rootSequenceIndex;
+    prach_ConfigIndex   = fp->prach_config_common.prach_ConfigInfo.prach_ConfigIndex;
+    Ncs_config          = fp->prach_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig;
+    restricted_set      = fp->prach_config_common.prach_ConfigInfo.highSpeedFlag;
+    n_ra_prb            = get_prach_prb_offset(fp,prach_ConfigIndex,
+                          fp->prach_config_common.prach_ConfigInfo.prach_FreqOffset,
+                          tdd_mapindex,Nf);
+  }
 
   int16_t *prach[nb_rx];
   uint8_t prach_fmt = get_prach_fmt(prach_ConfigIndex,frame_type);
   uint16_t N_ZC = (prach_fmt <4)?839:139;
-  
+
   if (eNB) {
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+
     if (br_flag == 1) {
       prach_ifftp         = eNB->prach_vars_br.prach_ifft[ce_level];
       subframe            = eNB->proc.subframe_prach_br;
       prachF              = eNB->prach_vars_br.prachF;
       rxsigF              = eNB->prach_vars_br.rxsigF[ce_level];
+
       if (LOG_DEBUGFLAG(PRACH)){
-        if (((ru->proc.frame_prach)&1023) < 20) LOG_I(PHY,"PRACH (eNB) : running rx_prach (br_flag %d, ce_level %d) for frame %d subframe %d, prach_FreqOffset %d, prach_ConfigIndex %d, rootSequenceIndex %d, repetition number %d,numRepetitionsPrePreambleAttempt %d\n",
-			  	     br_flag,ce_level,ru->proc.frame_prach,subframe,
+        if (((eNB->proc.frame_prach)&1023) < 20) LOG_I(PHY,"PRACH (eNB) : running rx_prach (br_flag %d, ce_level %d) for frame %d subframe %d, prach_FreqOffset %d, prach_ConfigIndex %d, rootSequenceIndex %d, repetition number %d,numRepetitionsPrePreambleAttempt %d\n",
+               br_flag,ce_level,eNB->proc.frame_prach,subframe,
 				     fp->prach_emtc_config_common.prach_ConfigInfo.prach_FreqOffset[ce_level],
 				     prach_ConfigIndex,rootSequenceIndex,
 				     eNB->prach_vars_br.repetition_number[ce_level],
@@ -169,30 +168,31 @@ void rx_prach0(PHY_VARS_eNB *eNB,
         prachF            = eNB->prach_vars.prachF;
         rxsigF            = eNB->prach_vars.rxsigF[0];
         if (LOG_DEBUGFLAG(PRACH)){
-          if (((ru->proc.frame_prach)&1023) < 20) LOG_I(PHY,"PRACH (eNB) : running rx_prach for subframe %d, prach_FreqOffset %d, prach_ConfigIndex %d , rootSequenceIndex %d\n", subframe,fp->prach_config_common.prach_ConfigInfo.prach_FreqOffset,prach_ConfigIndex,rootSequenceIndex);
+          if (((eNB->proc.frame_prach)&1023) < 20) LOG_I(PHY,"PRACH (eNB) : running rx_prach for subframe %d, prach_FreqOffset %d, prach_ConfigIndex %d , rootSequenceIndex %d\n", subframe,fp->prach_config_common.prach_ConfigInfo.prach_FreqOffset,prach_ConfigIndex,rootSequenceIndex);
         }
       }
-  }
-  else {
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+    } else {
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+
     if (br_flag == 1) {
-        subframe          = ru->proc.subframe_prach_br;
-        rxsigF            = ru->prach_rxsigF_br[ce_level];
-        if (LOG_DEBUGFLAG(PRACH)){
-          if (((ru->proc.frame_prach)&1023) < 20) LOG_I(PHY,"PRACH (RU) : running rx_prach (br_flag %d, ce_level %d) for frame %d subframe %d, prach_FreqOffset %d, prach_ConfigIndex %d\n",
-				       br_flag,ce_level,ru->proc.frame_prach,subframe,fp->prach_emtc_config_common.prach_ConfigInfo.prach_FreqOffset[ce_level],prach_ConfigIndex);
-        }
+      subframe          = ru->proc.subframe_prach_br;
+      rxsigF            = ru->prach_rxsigF_br[ce_level];
+
+      if (LOG_DEBUGFLAG(PRACH)) {
+        if (((ru->proc.frame_prach)&1023) < 20) LOG_I(PHY,"PRACH (RU) : running rx_prach (br_flag %d, ce_level %d) for frame %d subframe %d, prach_FreqOffset %d, prach_ConfigIndex %d\n",
+              br_flag,ce_level,ru->proc.frame_prach,subframe,fp->prach_emtc_config_common.prach_ConfigInfo.prach_FreqOffset[ce_level],prach_ConfigIndex);
+      }
     } else
 #endif
-      {
-        subframe          = ru->proc.subframe_prach;
-        rxsigF            = ru->prach_rxsigF;
-        if (LOG_DEBUGFLAG(PRACH)){
-          if (((ru->proc.frame_prach)&1023) < 20) LOG_I(PHY,"PRACH (RU) : running rx_prach for subframe %d, prach_FreqOffset %d, prach_ConfigIndex %d\n",
-	        subframe,fp->prach_config_common.prach_ConfigInfo.prach_FreqOffset,prach_ConfigIndex);
-        }
-      }
+    {
+      subframe          = ru->proc.subframe_prach;
+      rxsigF            = ru->prach_rxsigF;
 
+      if (LOG_DEBUGFLAG(PRACH)) {
+        if (((ru->proc.frame_prach)&1023) < 20) LOG_I(PHY,"PRACH (RU) : running rx_prach for subframe %d, prach_FreqOffset %d, prach_ConfigIndex %d\n",
+              subframe,fp->prach_config_common.prach_ConfigInfo.prach_FreqOffset,prach_ConfigIndex);
+      }
+    }
   }
 
   AssertFatal(ru!=NULL,"ru is null\n");
@@ -200,25 +200,29 @@ void rx_prach0(PHY_VARS_eNB *eNB,
   for (aa=0; aa<nb_rx; aa++) {
     if (ru->if_south == LOCAL_RF) { // set the time-domain signal if we have to use it in this node
       // DJP - indexing below in subframe zero takes us off the beginning of the array???
-      prach[aa] = (int16_t*)&ru->common.rxdata[aa][(subframe*fp->samples_per_tti)-ru->N_TA_offset];
-
-        if (LOG_DUMPFLAG(PRACH)){
-          int32_t en0=signal_energy((int32_t*)prach[aa],fp->samples_per_tti);
-          int8_t dbEn0 = dB_fixed(en0);
-          int8_t rach_dBm = dbEn0 - ru->rx_total_gain_dB;
-          char buffer[80];
-          if (dbEn0>32 && prach[0]!= NULL) {
-            static int counter=0;
-            sprintf(buffer, "%s%d", "/tmp/prach_rx",counter);
-            LOG_M(buffer,"prach_rx",prach[0],fp->samples_per_tti,1,13);
-          }
+      prach[aa] = (int16_t *)&ru->common.rxdata[aa][(subframe*fp->samples_per_tti)-ru->N_TA_offset];
+
+      if (LOG_DUMPFLAG(PRACH)) {
+        int32_t en0=signal_energy((int32_t *)prach[aa],fp->samples_per_tti);
+        int8_t dbEn0 = dB_fixed(en0);
+        int8_t rach_dBm = dbEn0 - ru->rx_total_gain_dB;
+        char buffer[80];
+
+        if (dbEn0>32 && prach[0]!= NULL) {
+          static int counter=0;
+          sprintf(buffer, "%s%d", "/tmp/prach_rx",counter);
+          LOG_M(buffer,"prach_rx",prach[0],fp->samples_per_tti,1,13);
+        }
+
         if (dB_fixed(en0)>32) {
           sprintf(buffer, "rach_dBm:%d",rach_dBm);
+
           if (prach[0]!= NULL) LOG_M("prach_rx","prach_rx",prach[0],fp->samples_per_tti,1,1);
-            LOG_I(PHY,"RU %d, br_flag %d ce_level %d frame %d subframe %d per_tti:%d prach:%p (energy %d) TA:%d %s rxdata:%p index:%d\n",
-                  ru->idx,br_flag,ce_level,ru->proc.frame_prach,subframe,fp->samples_per_tti,
-                  prach[aa],dbEn0,ru->N_TA_offset,buffer,ru->common.rxdata[aa], 
-                  (subframe*fp->samples_per_tti)-ru->N_TA_offset);
+
+          LOG_I(PHY,"RU %d, br_flag %d ce_level %d frame %d subframe %d per_tti:%d prach:%p (energy %d) TA:%d %s rxdata:%p index:%d\n",
+                ru->idx,br_flag,ce_level,ru->proc.frame_prach,subframe,fp->samples_per_tti,
+                prach[aa],dbEn0,ru->N_TA_offset,buffer,ru->common.rxdata[aa],
+                (subframe*fp->samples_per_tti)-ru->N_TA_offset);
         }
       }
     }
@@ -227,19 +231,17 @@ void rx_prach0(PHY_VARS_eNB *eNB,
   // First compute physical root sequence
   if (restricted_set == 0) {
     AssertFatal(Ncs_config<=15,
-		"Illegal Ncs_config for unrestricted format %d\n",Ncs_config);
+                "Illegal Ncs_config for unrestricted format %d\n",Ncs_config);
     NCS = NCS_unrestricted[Ncs_config];
   } else {
     AssertFatal(Ncs_config<=14,
-		"FATAL, Illegal Ncs_config for restricted format %d\n",Ncs_config);
+                "FATAL, Illegal Ncs_config for restricted format %d\n",Ncs_config);
     NCS = NCS_restricted[Ncs_config];
   }
 
   if (eNB) start_meas(&eNB->rx_prach);
 
-
   prach_root_sequence_map = (prach_fmt < 4) ? prach_root_sequence_map0_3 : prach_root_sequence_map4;
-
   // PDP is oversampled, e.g. 1024 sample instead of 839
   // Adapt the NCS (zero-correlation zones) with oversampling factor e.g. 1024/839
   NCS2 = (N_ZC==839) ? ((NCS<<10)/839) : ((NCS<<8)/139);
@@ -248,56 +250,56 @@ void rx_prach0(PHY_VARS_eNB *eNB,
     NCS2 = N_ZC;
 
   switch (prach_fmt) {
-  case 0:
-    Ncp = 3168;
-    break;
-
-  case 1:
-  case 3:
-    Ncp = 21024;
-    break;
-
-  case 2:
-    Ncp = 6240;
-    break;
-
-  case 4:
-    Ncp = 448;
-    break;
-
-  default:
-    Ncp = 3168;
-    break;
+    case 0:
+      Ncp = 3168;
+      break;
+
+    case 1:
+    case 3:
+      Ncp = 21024;
+      break;
+
+    case 2:
+      Ncp = 6240;
+      break;
+
+    case 4:
+      Ncp = 448;
+      break;
+
+    default:
+      Ncp = 3168;
+      break;
   }
 
   // Adjust CP length based on UL bandwidth
   switch (fp->N_RB_UL) {
-  case 6:
-    Ncp>>=4;
-    break;
+    case 6:
+      Ncp>>=4;
+      break;
 
-  case 15:
-    Ncp>>=3;
-    break;
+    case 15:
+      Ncp>>=3;
+      break;
 
-  case 25:
-    Ncp>>=2;
-    break;
+    case 25:
+      Ncp>>=2;
+      break;
 
-  case 50:
-    Ncp>>=1;
-    break;
+    case 50:
+      Ncp>>=1;
+      break;
 
-  case 75:
-    Ncp=(Ncp*3)>>2;
-    break;
-
-  case 100:
-    if (fp->threequarter_fs == 1)
+    case 75:
       Ncp=(Ncp*3)>>2;
-    break;
-  }
+      break;
 
+    case 100:
+      if (fp->threequarter_fs == 1)
+        Ncp=(Ncp*3)>>2;
+
+      break;
+  }
 
   if (((eNB!=NULL) && (ru->function != NGFI_RAU_IF4p5))||
       ((eNB==NULL) && (ru->function == NGFI_RRU_IF4p5))) { // compute the DFTs of the PRACH temporal resources
@@ -305,151 +307,146 @@ void rx_prach0(PHY_VARS_eNB *eNB,
     if (LOG_DEBUGFLAG(PRACH)) {
       LOG_D(PHY,"rx_prach: Doing FFT for N_RB_UL %d nb_rx:%d Ncp:%d\n",fp->N_RB_UL, nb_rx, Ncp);
     }
+
     for (aa=0; aa<nb_rx; aa++) {
       AssertFatal(prach[aa]!=NULL,"prach[%d] is null\n",aa);
       prach2 = prach[aa] + (Ncp<<1);
-  
+
       // do DFT
       switch (fp->N_RB_UL) {
-      case 6:
-	if (prach_fmt == 4) {
-	  dft256(prach2,rxsigF[aa],1);
-	} else {
-	  dft1536(prach2,rxsigF[aa],1);
-	  
-	  if (prach_fmt>1)
-	    dft1536(prach2+3072,rxsigF[aa]+3072,1);
-	}
-	
-	break;
-	
-      case 15:
-	if (prach_fmt == 4) {
-	  dft256(prach2,rxsigF[aa],1);
-	} else {
-	  dft3072(prach2,rxsigF[aa],1);
-	  
-	  if (prach_fmt>1)
-	    dft3072(prach2+6144,rxsigF[aa]+6144,1);
-	}
-	
-	break;
-	
-      case 25:
-      default:
-	if (prach_fmt == 4) {
-	  dft1024(prach2,rxsigF[aa],1);
-	  fft_size = 1024;
-	} else {
-	  dft6144(prach2,rxsigF[aa],1);
-	  
-	  if (prach_fmt>1)
-	    dft6144(prach2+12288,rxsigF[aa]+12288,1);
-	  
-	  fft_size = 6144;
-	}
-	
-	break;
-	
-      case 50:
-	if (prach_fmt == 4) {
-	  dft2048(prach2,rxsigF[aa],1);
-	} else {
-	  dft12288(prach2,rxsigF[aa],1);
-	  
-	  if (prach_fmt>1)
-	    dft12288(prach2+24576,rxsigF[aa]+24576,1);
-	}
-	
-	break;
-	
-      case 75:
-	if (prach_fmt == 4) {
-	  dft3072(prach2,rxsigF[aa],1);
-	} else {
-	  dft18432(prach2,rxsigF[aa],1);
-	  
-	  if (prach_fmt>1)
-	    dft18432(prach2+36864,rxsigF[aa]+36864,1);
-	}
-	
-	break;
-	
-      case 100:
-	if (fp->threequarter_fs==0) {
-	  if (prach_fmt == 4) {
-	    dft4096(prach2,rxsigF[aa],1);
-	  } else {
-	    dft24576(prach2,rxsigF[aa],1);
-	    
-	    if (prach_fmt>1)
-	      dft24576(prach2+49152,rxsigF[aa]+49152,1);
-	  }
-	} else {
-	  if (prach_fmt == 4) {
-	    dft3072(prach2,rxsigF[aa],1);
-	  } else {
-	    dft18432(prach2,rxsigF[aa],1);
-	    
-	    if (prach_fmt>1)
-	      dft18432(prach2+36864,rxsigF[aa]+36864,1);
-	  }
-	}
-	
-	break;
+        case 6:
+          if (prach_fmt == 4) {
+            dft256(prach2,rxsigF[aa],1);
+          } else {
+            dft1536(prach2,rxsigF[aa],1);
+
+            if (prach_fmt>1)
+              dft1536(prach2+3072,rxsigF[aa]+3072,1);
+          }
+
+          break;
+
+        case 15:
+          if (prach_fmt == 4) {
+            dft256(prach2,rxsigF[aa],1);
+          } else {
+            dft3072(prach2,rxsigF[aa],1);
+
+            if (prach_fmt>1)
+              dft3072(prach2+6144,rxsigF[aa]+6144,1);
+          }
+
+          break;
+
+        case 25:
+        default:
+          if (prach_fmt == 4) {
+            dft1024(prach2,rxsigF[aa],1);
+            fft_size = 1024;
+          } else {
+            dft6144(prach2,rxsigF[aa],1);
+
+            if (prach_fmt>1)
+              dft6144(prach2+12288,rxsigF[aa]+12288,1);
+
+            fft_size = 6144;
+          }
+
+          break;
+
+        case 50:
+          if (prach_fmt == 4) {
+            dft2048(prach2,rxsigF[aa],1);
+          } else {
+            dft12288(prach2,rxsigF[aa],1);
+
+            if (prach_fmt>1)
+              dft12288(prach2+24576,rxsigF[aa]+24576,1);
+          }
+
+          break;
+
+        case 75:
+          if (prach_fmt == 4) {
+            dft3072(prach2,rxsigF[aa],1);
+          } else {
+            dft18432(prach2,rxsigF[aa],1);
+
+            if (prach_fmt>1)
+              dft18432(prach2+36864,rxsigF[aa]+36864,1);
+          }
+
+          break;
+
+        case 100:
+          if (fp->threequarter_fs==0) {
+            if (prach_fmt == 4) {
+              dft4096(prach2,rxsigF[aa],1);
+            } else {
+              dft24576(prach2,rxsigF[aa],1);
+
+              if (prach_fmt>1)
+                dft24576(prach2+49152,rxsigF[aa]+49152,1);
+            }
+          } else {
+            if (prach_fmt == 4) {
+              dft3072(prach2,rxsigF[aa],1);
+            } else {
+              dft18432(prach2,rxsigF[aa],1);
+
+              if (prach_fmt>1)
+                dft18432(prach2+36864,rxsigF[aa]+36864,1);
+            }
+          }
+
+          break;
       }
 
       k = (12*n_ra_prb) - 6*fp->N_RB_UL;
-      
+
       if (k<0) {
-	k+=(fp->ofdm_symbol_size);
+        k+=(fp->ofdm_symbol_size);
       }
-      
+
       k*=12;
-      k+=13; 
+      k+=13;
       k*=2;
       int dftsize_x2 = fp->ofdm_symbol_size*24;
       //LOG_D(PHY,"Shifting prach_rxF from %d to 0\n",k);
 
-      if ((k+(839*2)) > dftsize_x2) { // PRACH signal is split around DC 
-	memmove((void*)&rxsigF[aa][dftsize_x2-k],(void*)&rxsigF[aa][0],(k+(839*2)-dftsize_x2)*2);	
-	memmove((void*)&rxsigF[aa][0],(void*)(&rxsigF[aa][k]),(dftsize_x2-k)*2);	
-      }
-      else  // PRACH signal is not split around DC
-	memmove((void*)&rxsigF[aa][0],(void*)(&rxsigF[aa][k]),839*4);	
-      
+      if ((k+(839*2)) > dftsize_x2) { // PRACH signal is split around DC
+        memmove((void *)&rxsigF[aa][dftsize_x2-k],(void *)&rxsigF[aa][0],(k+(839*2)-dftsize_x2)*2);
+        memmove((void *)&rxsigF[aa][0],(void *)(&rxsigF[aa][k]),(dftsize_x2-k)*2);
+      } else // PRACH signal is not split around DC
+        memmove((void *)&rxsigF[aa][0],(void *)(&rxsigF[aa][k]),839*4);
     }
-	     
   }
 
-  if ((eNB==NULL) && (ru!=NULL) && ru->function == NGFI_RRU_IF4p5) {
-
+  if ((eNB==NULL)  && ru->function == NGFI_RRU_IF4p5) {
     /// **** send_IF4 of rxsigF to RAU **** ///
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-    if (br_flag == 1) send_IF4p5(ru, ru->proc.frame_prach, ru->proc.subframe_prach, IF4p5_PRACH+1+ce_level);      
-
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+    if (br_flag == 1) send_IF4p5(ru, ru->proc.frame_prach, ru->proc.subframe_prach, IF4p5_PRACH+1+ce_level);
     else
 #endif
       send_IF4p5(ru, ru->proc.frame_prach, ru->proc.subframe_prach, IF4p5_PRACH);
-    
+
     return;
   } else if (eNB!=NULL) {
-
     if ( LOG_DEBUGFLAG(PRACH)) {
-      int en = dB_fixed(signal_energy((int32_t*)&rxsigF[0][0],840));
+      int en = dB_fixed(signal_energy((int32_t *)&rxsigF[0][0],840));
+
       if ((en > 60)&&(br_flag==1)) LOG_I(PHY,"PRACH (br_flag %d,ce_level %d, n_ra_prb %d, k %d): Frame %d, Subframe %d => %d dB\n",br_flag,ce_level,n_ra_prb,k,eNB->proc.frame_rx,eNB->proc.subframe_rx,en);
     }
   }
-  
-  // in case of RAU and prach received rx_thread wakes up prach
 
+  // in case of RAU and prach received rx_thread wakes up prach
   // here onwards is for eNodeB_3GPP or NGFI_RAU_IF4p5
-
   preamble_offset_old = 99;
-
   uint8_t update_TA  = 4;
   uint8_t update_TA2 = 1;
+
   switch (eNB->frame_parms.N_RB_DL) {
+
   case 6:
     update_TA = 16;
     break;
@@ -465,32 +462,34 @@ void rx_prach0(PHY_VARS_eNB *eNB,
   case 75:
     update_TA  = 3;
     update_TA2 = 2;
+    break;
   case 100:
     update_TA  = 1;
     break;
+
   }
-  
+
   *max_preamble_energy=0;
+
   for (preamble_index=0 ; preamble_index<64 ; preamble_index++) {
+    if (LOG_DEBUGFLAG(PRACH)) {
+      int en = dB_fixed(signal_energy((int32_t *)&rxsigF[0][0],840));
 
-    if (LOG_DEBUGFLAG(PRACH)){
-      int en = dB_fixed(signal_energy((int32_t*)&rxsigF[0][0],840));
       if (en>60) LOG_I(PHY,"frame %d, subframe %d : Trying preamble %d (br_flag %d)\n",ru->proc.frame_prach,subframe,preamble_index,br_flag);
     }
+
     if (restricted_set == 0) {
       // This is the relative offset in the root sequence table (5.7.2-4 from 36.211) for the given preamble index
       preamble_offset = ((NCS==0)? preamble_index : (preamble_index/(N_ZC/NCS)));
-      
+
       if (preamble_offset != preamble_offset_old) {
         preamble_offset_old = preamble_offset;
         new_dft = 1;
         // This is the \nu corresponding to the preamble index
         preamble_shift  = 0;
-      }
-      
-      else {
+      } else {
         preamble_shift  -= NCS;
-	
+
         if (preamble_shift < 0)
           preamble_shift+=N_ZC;
       }
@@ -519,7 +518,6 @@ void rx_prach0(PHY_VARS_eNB *eNB,
           }
 
           u = prach_root_sequence_map[index];
-
           uint16_t n_group_ra = 0;
 
           if ( (du[u]<(N_ZC/3)) && (du[u]>=NCS) ) {
@@ -560,180 +558,187 @@ void rx_prach0(PHY_VARS_eNB *eNB,
 
     // Compute DFT of RX signal (conjugate input, results in conjugate output) for each new rootSequenceIndex
     if (LOG_DEBUGFLAG(PRACH)) {
-      int en = dB_fixed(signal_energy((int32_t*)&rxsigF[0][0],840));
+      int en = dB_fixed(signal_energy((int32_t *)&rxsigF[0][0],840));
+
       if (en>60) LOG_I(PHY,"frame %d, subframe %d : preamble index %d: offset %d, preamble shift %d (br_flag %d, en %d)\n",
-		       ru->proc.frame_prach,subframe,preamble_index,preamble_offset,preamble_shift,br_flag,en);
+                         ru->proc.frame_prach,subframe,preamble_index,preamble_offset,preamble_shift,br_flag,en);
     }
+
     log2_ifft_size = 10;
     fft_size = 6144;
 
     if (new_dft == 1) {
       new_dft = 0;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
       if (br_flag == 1) {
-	Xu=(int16_t*)eNB->X_u_br[ce_level][preamble_offset-first_nonzero_root_idx];
-	prach_ifft = prach_ifftp[prach_ifft_cnt++];
-	if (eNB->prach_vars_br.repetition_number[ce_level]==1) memset(prach_ifft,0,((N_ZC==839)?2048:256)*sizeof(int32_t));
-      }
-      else
+        Xu=(int16_t *)eNB->X_u_br[ce_level][preamble_offset-first_nonzero_root_idx];
+        prach_ifft = prach_ifftp[prach_ifft_cnt++];
+
+        if (eNB->prach_vars_br.repetition_number[ce_level]==1) memset(prach_ifft,0,((N_ZC==839)?2048:256)*sizeof(int32_t));
+      } else
 #endif
-	{
-	  Xu=(int16_t*)eNB->X_u[preamble_offset-first_nonzero_root_idx];
-	  prach_ifft = prach_ifftp[0];
-          memset(prach_ifft,0,((N_ZC==839) ? 2048 : 256)*sizeof(int32_t));
-	}
+      {
+        Xu=(int16_t *)eNB->X_u[preamble_offset-first_nonzero_root_idx];
+        prach_ifft = prach_ifftp[0];
+        memset(prach_ifft,0,((N_ZC==839) ? 2048 : 256)*sizeof(int32_t));
+      }
 
       memset(prachF, 0, sizeof(int16_t)*2*1024 );
-      if (LOG_DUMPFLAG(PRACH)) {      
+
+      if (LOG_DUMPFLAG(PRACH)) {
         if (prach[0]!= NULL) LOG_M("prach_rx0.m","prach_rx0",prach[0],6144+792,1,1);
-         LOG_M("prach_rx1.m","prach_rx1",prach[1],6144+792,1,1);
-         LOG_M("prach_rxF0.m","prach_rxF0",rxsigF[0],24576,1,1);
-         LOG_M("prach_rxF1.m","prach_rxF1",rxsigF[1],6144,1,1);
+
+        LOG_M("prach_rx1.m","prach_rx1",prach[1],6144+792,1,1);
+        LOG_M("prach_rxF0.m","prach_rxF0",rxsigF[0],24576,1,1);
+        LOG_M("prach_rxF1.m","prach_rxF1",rxsigF[1],6144,1,1);
       }
-   
-      for (aa=0;aa<nb_rx; aa++) {
-      // Do componentwise product with Xu* on each antenna 
-
-	k=0;	
-	for (offset=0; offset<(N_ZC<<1); offset+=2) {
-	  prachF[offset]   = (int16_t)(((int32_t)Xu[offset]*rxsigF[aa][k]   + (int32_t)Xu[offset+1]*rxsigF[aa][k+1])>>15);
-	  prachF[offset+1] = (int16_t)(((int32_t)Xu[offset]*rxsigF[aa][k+1] - (int32_t)Xu[offset+1]*rxsigF[aa][k])>>15);
-	  k+=2;
-	  if (k==(12*2*fp->ofdm_symbol_size))
-	    k=0;
-	}
-	
-	// Now do IFFT of size 1024 (N_ZC=839) or 256 (N_ZC=139)
-	if (N_ZC == 839) {
-	  log2_ifft_size = 10;
-	  idft1024(prachF,prach_ifft_tmp,1);
-	  // compute energy and accumulate over receive antennas and repetitions for BR
-	  for (i=0;i<2048;i++)
-	    prach_ifft[i] += (prach_ifft_tmp[i<<1]*prach_ifft_tmp[i<<1] + prach_ifft_tmp[1+(i<<1)]*prach_ifft_tmp[1+(i<<1)])>>10;
-	} else {
-	  idft256(prachF,prach_ifft_tmp,1);
-	  log2_ifft_size = 8;
-	  // compute energy and accumulate over receive antennas and repetitions for BR
-	  for (i=0;i<256;i++)
-	    prach_ifft[i] += (prach_ifft_tmp[i<<1]*prach_ifft_tmp[(i<<1)] + prach_ifft_tmp[1+(i<<1)]*prach_ifft_tmp[1+(i<<1)])>>10;
-	}
-
-        if (LOG_DUMPFLAG(PRACH)) {	
-	  if (aa==0) LOG_M("prach_rxF_comp0.m","prach_rxF_comp0",prachF,1024,1,1);
+
+      for (aa=0; aa<nb_rx; aa++) {
+        // Do componentwise product with Xu* on each antenna
+        k=0;
+
+        for (offset=0; offset<(N_ZC<<1); offset+=2) {
+          prachF[offset]   = (int16_t)(((int32_t)Xu[offset]*rxsigF[aa][k]   + (int32_t)Xu[offset+1]*rxsigF[aa][k+1])>>15);
+          prachF[offset+1] = (int16_t)(((int32_t)Xu[offset]*rxsigF[aa][k+1] - (int32_t)Xu[offset+1]*rxsigF[aa][k])>>15);
+          k+=2;
+
+          if (k==(12*2*fp->ofdm_symbol_size))
+            k=0;
+        }
+
+        // Now do IFFT of size 1024 (N_ZC=839) or 256 (N_ZC=139)
+        if (N_ZC == 839) {
+          log2_ifft_size = 10;
+          idft1024(prachF,prach_ifft_tmp,1);
+
+          // compute energy and accumulate over receive antennas and repetitions for BR
+          for (i=0; i<2048; i++)
+            prach_ifft[i] += (prach_ifft_tmp[i<<1]*prach_ifft_tmp[i<<1] + prach_ifft_tmp[1+(i<<1)]*prach_ifft_tmp[1+(i<<1)])>>10;
+        } else {
+          idft256(prachF,prach_ifft_tmp,1);
+          log2_ifft_size = 8;
+
+          // compute energy and accumulate over receive antennas and repetitions for BR
+          for (i=0; i<256; i++)
+            prach_ifft[i] += (prach_ifft_tmp[i<<1]*prach_ifft_tmp[(i<<1)] + prach_ifft_tmp[1+(i<<1)]*prach_ifft_tmp[1+(i<<1)])>>10;
+        }
+
+        if (LOG_DUMPFLAG(PRACH)) {
+          if (aa==0) LOG_M("prach_rxF_comp0.m","prach_rxF_comp0",prachF,1024,1,1);
+
           if (aa==1) LOG_M("prach_rxF_comp1.m","prach_rxF_comp1",prachF,1024,1,1);
         }
       }// antennas_rx
     } // new dft
-    
-    // check energy in nth time shift, for 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+
+    // check energy in nth time shift, for
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+
     if ((br_flag==0) ||
-	(eNB->prach_vars_br.repetition_number[ce_level]==
-	 eNB->frame_parms.prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[ce_level]))
+        (eNB->prach_vars_br.repetition_number[ce_level]==
+         eNB->frame_parms.prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[ce_level]))
 #endif
-      {
-      if (LOG_DEBUGFLAG(PRACH)){
-        int en = dB_fixed(signal_energy((int32_t*)&rxsigF[0][0],840));
-	if (en>60) LOG_I(PHY,"frame %d, subframe %d: Checking for peak in time-domain (br_flag %d, en %d)\n",ru->proc.frame_prach,subframe,br_flag,en);
+    {
+      if (LOG_DEBUGFLAG(PRACH)) {
+        int en = dB_fixed(signal_energy((int32_t *)&rxsigF[0][0],840));
+
+        if (en>60) LOG_I(PHY,"frame %d, subframe %d: Checking for peak in time-domain (br_flag %d, en %d)\n",ru->proc.frame_prach,subframe,br_flag,en);
       }
-	preamble_shift2 = ((preamble_shift==0) ? 0 : ((preamble_shift<<log2_ifft_size)/N_ZC));
 
-    
-	for (i=0; i<NCS2; i++) {
-	  lev = (int32_t)prach_ifft[(preamble_shift2+i)];
-	  levdB = dB_fixed_times10(lev);
-	  
-	  if (levdB>*max_preamble_energy) {
-	    *max_preamble_energy  = levdB;
-	    *max_preamble_delay   = ((i*fft_size)>>log2_ifft_size)*update_TA/update_TA2;
-	    *max_preamble         = preamble_index;
-            if (LOG_DEBUGFLAG(PRACH)){
-              int en = dB_fixed(signal_energy((int32_t*)&rxsigF[0][0],840));
-	      if ((en>60) && (br_flag==1)) 
-                 LOG_D(PHY,"frame %d, subframe %d : max_preamble_energy %d, max_preamble_delay %d, max_preamble %d (br_flag %d,ce_level %d, levdB %d, lev %d)\n",
-                       ru->proc.frame_prach,subframe,
-                       *max_preamble_energy,*max_preamble_delay,
-                       *max_preamble,br_flag,ce_level,levdB,lev);
-            }
-	  }
-	}
+      preamble_shift2 = ((preamble_shift==0) ? 0 : ((preamble_shift<<log2_ifft_size)/N_ZC));
+
+      for (i=0; i<NCS2; i++) {
+        lev = (int32_t)prach_ifft[(preamble_shift2+i)];
+        levdB = dB_fixed_times10(lev);
 
+        if (levdB>*max_preamble_energy) {
+          *max_preamble_energy  = levdB;
+          *max_preamble_delay   = ((i*fft_size)>>log2_ifft_size)*update_TA/update_TA2;
+          *max_preamble         = preamble_index;
+
+          if (LOG_DEBUGFLAG(PRACH)) {
+            int en = dB_fixed(signal_energy((int32_t *)&rxsigF[0][0],840));
+
+            if ((en>60) && (br_flag==1))
+              LOG_D(PHY,"frame %d, subframe %d : max_preamble_energy %d, max_preamble_delay %d, max_preamble %d (br_flag %d,ce_level %d, levdB %d, lev %d)\n",
+                    ru->proc.frame_prach,subframe,
+                    *max_preamble_energy,*max_preamble_delay,
+                    *max_preamble,br_flag,ce_level,levdB,lev);
+          }
+        }
       }
+    }
   }// preamble_index
 
   if (LOG_DUMPFLAG(PRACH)) {
-    int en = dB_fixed(signal_energy((int32_t*)&rxsigF[0][0],840));  
+    int en = dB_fixed(signal_energy((int32_t *)&rxsigF[0][0],840));
+
     if (en>60) {
       k = (12*n_ra_prb) - 6*fp->N_RB_UL;
-      
+
       if (k<0) k+=fp->ofdm_symbol_size;
-      
+
       k*=12;
       k+=13;
       k*=2;
-      
+
       if (br_flag == 0) {
-  	  LOG_M("rxsigF.m","prach_rxF",&rxsigF[0][0],12288,1,1);
-  	  LOG_M("prach_rxF_comp0.m","prach_rxF_comp0",prachF,1024,1,1);
-  	  LOG_M("Xu.m","xu",Xu,N_ZC,1,1);
-  	  LOG_M("prach_ifft0.m","prach_t0",prach_ifft,1024,1,1);
-      }
-      else {
-  	LOG_E(PHY,"Dumping prach (br_flag %d), k = %d (n_ra_prb %d)\n",br_flag,k,n_ra_prb);
-  	LOG_M("rxsigF_br.m","prach_rxF_br",&rxsigF[0][0],12288,1,1);
-  	LOG_M("prach_rxF_comp0_br.m","prach_rxF_comp0_br",prachF,1024,1,1);
-  	LOG_M("Xu_br.m","xu_br",Xu,N_ZC,1,1);
-  	LOG_M("prach_ifft0_br.m","prach_t0_br",prach_ifft,1024,1,1);
-  	exit(-1);      
+        LOG_M("rxsigF.m","prach_rxF",&rxsigF[0][0],12288,1,1);
+        LOG_M("prach_rxF_comp0.m","prach_rxF_comp0",prachF,1024,1,1);
+        LOG_M("Xu.m","xu",Xu,N_ZC,1,1);
+        LOG_M("prach_ifft0.m","prach_t0",prach_ifft,1024,1,1);
+      } else {
+        LOG_E(PHY,"Dumping prach (br_flag %d), k = %d (n_ra_prb %d)\n",br_flag,k,n_ra_prb);
+        LOG_M("rxsigF_br.m","prach_rxF_br",&rxsigF[0][0],12288,1,1);
+        LOG_M("prach_rxF_comp0_br.m","prach_rxF_comp0_br",prachF,1024,1,1);
+        LOG_M("Xu_br.m","xu_br",Xu,N_ZC,1,1);
+        LOG_M("prach_ifft0_br.m","prach_t0_br",prach_ifft,1024,1,1);
+        exit(-1);
       }
-
     }
   } /* LOG_DUMPFLAG(PRACH) */
-  if (eNB) stop_meas(&eNB->rx_prach);
 
+  if (eNB) stop_meas(&eNB->rx_prach);
 }
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 
 void rx_prach(PHY_VARS_eNB *eNB,
-	      RU_t *ru,
-	      uint16_t *max_preamble,
-	      uint16_t *max_preamble_energy,
-	      uint16_t *max_preamble_delay,
-	      uint16_t Nf, 
-	      uint8_t tdd_mapindex,
-	      uint8_t br_flag) {
-
+              RU_t *ru,
+              uint16_t *max_preamble,
+              uint16_t *max_preamble_energy,
+              uint16_t *max_preamble_delay,
+              uint16_t Nf,
+              uint8_t tdd_mapindex,
+              uint8_t br_flag) {
   int i;
   int prach_mask=0;
 
-  if (br_flag == 0) { 
+  if (br_flag == 0) {
     rx_prach0(eNB,ru,max_preamble,max_preamble_energy,max_preamble_delay,Nf,tdd_mapindex,0,0);
-  }
-  else { // This is procedure for eMTC, basically handling the repetitions
+  } else { // This is procedure for eMTC, basically handling the repetitions
     prach_mask = is_prach_subframe(&eNB->frame_parms,eNB->proc.frame_prach_br,eNB->proc.subframe_prach_br);
-    for (i=0;i<4;i++) {
-      if ((eNB->frame_parms.prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[i]==1) &&
-	  ((prach_mask&(1<<(i+1))) > 0)) { // check that prach CE level is active now
 
-	// if first reception in group of repetitions store frame for later (in RA-RNTI for Msg2) 
-	if (eNB->prach_vars_br.repetition_number[i]==0) eNB->prach_vars_br.first_frame[i]=eNB->proc.frame_prach_br;
+    for (i=0; i<4; i++) {
+      if ((eNB->frame_parms.prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[i]==1) &&
+          ((prach_mask&(1<<(i+1))) > 0)) { // check that prach CE level is active now
 
-	// increment repetition number
-	eNB->prach_vars_br.repetition_number[i]++;
+        // if first reception in group of repetitions store frame for later (in RA-RNTI for Msg2)
+        if (eNB->prach_vars_br.repetition_number[i]==0) eNB->prach_vars_br.first_frame[i]=eNB->proc.frame_prach_br;
 
-	// do basic PRACH reception
-	rx_prach0(eNB,ru,max_preamble,max_preamble_energy,max_preamble_delay,Nf,tdd_mapindex,1,i);
-	
-	// if last repetition, clear counter
-	if (eNB->prach_vars_br.repetition_number[i] == eNB->frame_parms.prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[i]) {
-	  eNB->prach_vars_br.repetition_number[i]=0;
+        // increment repetition number
+        eNB->prach_vars_br.repetition_number[i]++;
+        // do basic PRACH reception
+        rx_prach0(eNB,ru,max_preamble,max_preamble_energy,max_preamble_delay,Nf,tdd_mapindex,1,i);
 
-	}
+        // if last repetition, clear counter
+        if (eNB->prach_vars_br.repetition_number[i] == eNB->frame_parms.prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[i]) {
+          eNB->prach_vars_br.repetition_number[i]=0;
+        }
       }
     }
   }
 }
 
-#endif /* #if (RRC_VERSION >= MAKE_VERSION(14, 0, 0)) */
+#endif /* #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) */
diff --git a/openair1/PHY/LTE_TRANSPORT/prach_common.c b/openair1/PHY/LTE_TRANSPORT/prach_common.c
index 475a97ca0c7bcb441976b51af49f8c2c22a98d4a..5f7a904db16f522a8a34972063c0e2f5ffde9235 100644
--- a/openair1/PHY/LTE_TRANSPORT/prach_common.c
+++ b/openair1/PHY/LTE_TRANSPORT/prach_common.c
@@ -565,17 +565,16 @@ int is_prach_subframe0(LTE_DL_FRAME_PARMS *frame_parms,uint8_t prach_ConfigIndex
   return(prach_mask);
 }
 
-int is_prach_subframe(LTE_DL_FRAME_PARMS *frame_parms,uint32_t frame, uint8_t subframe) {
+int is_prach_subframe(LTE_DL_FRAME_PARMS *frame_parms, uint32_t frame, uint8_t subframe) {
   
   uint8_t prach_ConfigIndex  = frame_parms->prach_config_common.prach_ConfigInfo.prach_ConfigIndex;
-  int prach_mask             = is_prach_subframe0(frame_parms,prach_ConfigIndex,frame,subframe);
+  int prach_mask             = is_prach_subframe0(frame_parms, prach_ConfigIndex, frame, subframe);
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-  int i;
-
-  for (i=0;i<4;i++) {
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  for (int i=0; i<4; i++) {
     if (frame_parms->prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[i] == 1) 
-      prach_mask|=(is_prach_subframe0(frame_parms,frame_parms->prach_emtc_config_common.prach_ConfigInfo.prach_ConfigIndex[i],frame,subframe)<<(i+1));
+      prach_mask |= (is_prach_subframe0(frame_parms, frame_parms->prach_emtc_config_common.prach_ConfigInfo.prach_ConfigIndex[i],
+                                        frame, subframe) << (i+1));
   }
 #endif
   return(prach_mask);
diff --git a/openair1/PHY/LTE_TRANSPORT/print_stats.c b/openair1/PHY/LTE_TRANSPORT/print_stats.c
new file mode 100644
index 0000000000000000000000000000000000000000..758a97640daec2aac2a596017a787e4cd9e9cb3e
--- /dev/null
+++ b/openair1/PHY/LTE_TRANSPORT/print_stats.c
@@ -0,0 +1,804 @@
+/*
+ * 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
+ */
+
+/*! \file PHY/LTE_TRANSPORT/print_stats.c
+* \brief PHY statstic logging function
+* \author R. Knopp, F. Kaltenberger, navid nikaein
+* \date 2011
+* \version 0.1
+* \company Eurecom
+* \email: knopp@eurecom.fr,florian.kaltenberger@eurecom.fr, navid.nikaein@eurecom.fr
+* \note
+* \warning
+*/
+
+#include "PHY/LTE_TRANSPORT/proto.h"
+
+#include "PHY/defs.h"
+#include "PHY/extern.h"
+#include "SCHED/extern.h"
+
+#ifdef OPENAIR2
+#include "openair2/LAYER2/MAC/proto.h"
+#include "openair2/RRC/L2_INTERFACE/openair_rrc_L2_interface.h"
+#endif
+
+extern int mac_get_rrc_status(uint8_t Mod_id,uint8_t eNB_flag,uint8_t index);
+#if defined(OAI_USRP) || defined(EXMIMO) || defined(OAI_BLADERF) || defined(OAI_LMSSDR)
+#include "common_lib.h"
+extern openair0_config_t openair0_cfg[];
+#endif
+
+int dump_ue_stats(PHY_VARS_UE *ue, UE_rxtx_proc_t *proc,char* buffer, int length, runmode_t mode, int input_level_dBm)
+{
+
+  uint8_t eNB=0;
+  uint32_t RRC_status;
+  int len=length;
+  int harq_pid,round;
+
+  if (ue==NULL)
+    return 0;
+
+  if ((mode == normal_txrx) || (mode == no_L2_connect)) {
+    len += sprintf(&buffer[len], "[UE_PROC] UE %d, RNTI %x\n",ue->Mod_id, ue->pdcch_vars[0][0]->crnti);
+     len += sprintf(&buffer[len],"[UE PROC] RSRP[0] %.2f dBm/RE, RSSI %.2f dBm, RSRQ[0] %.2f dB, N0 %d dBm/RE (NF %.1f dB)\n",
+		    10*log10(ue->measurements.rsrp[0])-ue->rx_total_gain_dB,
+		    10*log10(ue->measurements.rssi)-ue->rx_total_gain_dB,
+		    10*log10(ue->measurements.rsrq[0]),
+		    ue->measurements.n0_power_tot_dBm,
+		    (double)ue->measurements.n0_power_tot_dBm+132.24);
+
+    /*
+    len += sprintf(&buffer[len],
+                   "[UE PROC] Frame count: %d\neNB0 RSSI %d dBm/RE (%d dB, %d dB)\neNB1 RSSI %d dBm/RE (%d dB, %d dB)neNB2 RSSI %d dBm/RE (%d dB, %d dB)\nN0 %d dBm/RE, %f dBm/%dPRB (%d dB, %d dB)\n",
+                   proc->frame_rx,
+                   ue->measurements.rx_rssi_dBm[0],
+                   ue->measurements.rx_power_dB[0][0],
+                   ue->measurements.rx_power_dB[0][1],
+                   ue->measurements.rx_rssi_dBm[1],
+                   ue->measurements.rx_power_dB[1][0],
+                   ue->measurements.rx_power_dB[1][1],
+                   ue->measurements.rx_rssi_dBm[2],
+                   ue->measurements.rx_power_dB[2][0],
+                   ue->measurements.rx_power_dB[2][1],
+                   ue->measurements.n0_power_tot_dBm,
+                   ue->measurements.n0_power_tot_dBm+10*log10(12*ue->frame_parms.N_RB_DL),
+                   ue->frame_parms.N_RB_DL,
+                   ue->measurements.n0_power_dB[0],
+                   ue->measurements.n0_power_dB[1]);
+    */
+
+#ifdef EXMIMO
+    len += sprintf(&buffer[len], "[UE PROC] RX Gain %d dB (LNA %d, vga %d dB)\n",ue->rx_total_gain_dB, openair0_cfg[0].rxg_mode[0],(int)openair0_cfg[0].rx_gain[0]);
+#endif
+#if defined(OAI_USRP) || defined(OAI_BLADERF) || defined(OAI_LMSSDR)
+    len += sprintf(&buffer[len], "[UE PROC] RX Gain %d dB\n",ue->rx_total_gain_dB);
+#endif
+#if defined(EXMIMO) || defined(OAI_USRP) || defined(OAI_BLADERF) || defined(OAI_LMSSDR)
+    len += sprintf(&buffer[len], "[UE_PROC] Frequency offset %d Hz, estimated carrier frequency %f Hz\n",ue->common_vars.freq_offset,openair0_cfg[0].rx_freq[0]-ue->common_vars.freq_offset);
+#endif
+    len += sprintf(&buffer[len], "[UE PROC] UE mode = %s (%d)\n",mode_string[ue->UE_mode[0]],ue->UE_mode[0]);
+    len += sprintf(&buffer[len], "[UE PROC] timing_advance = %d\n",ue->timing_advance);
+    if (ue->UE_mode[0]==PUSCH) {
+      len += sprintf(&buffer[len], "[UE PROC] Po_PUSCH = %d dBm (PL %d dB, Po_NOMINAL_PUSCH %d dBm, PHR %d dB)\n",
+		     ue->ulsch[0]->Po_PUSCH,
+		     get_PL(ue->Mod_id,ue->CC_id,0),
+		     ue->frame_parms.ul_power_control_config_common.p0_NominalPUSCH,
+		     ue->ulsch[0]->PHR);
+      len += sprintf(&buffer[len], "[UE PROC] Po_PUCCH = %d dBm (Po_NOMINAL_PUCCH %d dBm, g_pucch %d dB)\n",
+		     get_PL(ue->Mod_id,ue->CC_id,0)+
+		     ue->frame_parms.ul_power_control_config_common.p0_NominalPUCCH+
+		     ue->dlsch[0][0][0]->g_pucch,
+		     ue->frame_parms.ul_power_control_config_common.p0_NominalPUCCH,
+		     ue->dlsch[0][0][0]->g_pucch);
+    }
+    //for (eNB=0;eNB<NUMBER_OF_eNB_MAX;eNB++) {
+    for (eNB=0; eNB<1; eNB++) {
+      len += sprintf(&buffer[len], "[UE PROC] RX spatial power eNB%d: [%d %d; %d %d] dB\n",
+                     eNB,
+                     ue->measurements.rx_spatial_power_dB[eNB][0][0],
+                     ue->measurements.rx_spatial_power_dB[eNB][0][1],
+                     ue->measurements.rx_spatial_power_dB[eNB][1][0],
+                     ue->measurements.rx_spatial_power_dB[eNB][1][1]);
+
+      len += sprintf(&buffer[len], "[UE PROC] RX total power eNB%d: %d dB, avg: %d dB\n",eNB,ue->measurements.rx_power_tot_dB[eNB],ue->measurements.rx_power_avg_dB[eNB]);
+      len += sprintf(&buffer[len], "[UE PROC] RX total power lin: %d, avg: %d, RX total noise lin: %d, avg: %d\n",ue->measurements.rx_power_tot[eNB],
+                     ue->measurements.rx_power_avg[eNB], ue->measurements.n0_power_tot, ue->measurements.n0_power_avg);
+      len += sprintf(&buffer[len], "[UE PROC] effective SINR %.2f dB\n",ue->sinr_eff);
+      len += sprintf(&buffer[len], "[UE PROC] Wideband CQI eNB %d: %d dB, avg: %d dB\n",eNB,ue->measurements.wideband_cqi_tot[eNB],ue->measurements.wideband_cqi_avg[eNB]);
+
+      switch (ue->frame_parms.N_RB_DL) {
+      case 6:
+        len += sprintf(&buffer[len], "[UE PROC] Subband CQI eNB%d (Ant 0): [%d %d %d %d %d %d] dB\n",
+                       eNB,
+                       ue->measurements.subband_cqi_dB[eNB][0][0],
+                       ue->measurements.subband_cqi_dB[eNB][0][1],
+                       ue->measurements.subband_cqi_dB[eNB][0][2],
+                       ue->measurements.subband_cqi_dB[eNB][0][3],
+                       ue->measurements.subband_cqi_dB[eNB][0][4],
+                       ue->measurements.subband_cqi_dB[eNB][0][5]);
+
+
+        len += sprintf(&buffer[len], "[UE PROC] Subband CQI eNB%d (Ant 1): [%d %d %d %d %d %d] dB\n",
+                       eNB,
+                       ue->measurements.subband_cqi_dB[eNB][1][0],
+                       ue->measurements.subband_cqi_dB[eNB][1][1],
+                       ue->measurements.subband_cqi_dB[eNB][1][2],
+                       ue->measurements.subband_cqi_dB[eNB][1][3],
+                       ue->measurements.subband_cqi_dB[eNB][1][4],
+                       ue->measurements.subband_cqi_dB[eNB][1][5]);
+
+
+        len += sprintf(&buffer[len], "[UE PROC] Subband PMI eNB%d (Ant 0): [(%d %d) (%d %d) (%d %d) (%d %d) (%d %d) (%d %d)]\n",
+                       eNB,
+                       ue->measurements.subband_pmi_re[eNB][0][0],
+                       ue->measurements.subband_pmi_im[eNB][0][0],
+                       ue->measurements.subband_pmi_re[eNB][1][0],
+                       ue->measurements.subband_pmi_im[eNB][1][0],
+                       ue->measurements.subband_pmi_re[eNB][2][0],
+                       ue->measurements.subband_pmi_im[eNB][2][0],
+                       ue->measurements.subband_pmi_re[eNB][3][0],
+                       ue->measurements.subband_pmi_im[eNB][3][0],
+                       ue->measurements.subband_pmi_re[eNB][4][0],
+                       ue->measurements.subband_pmi_im[eNB][4][0],
+                       ue->measurements.subband_pmi_re[eNB][5][0],
+                       ue->measurements.subband_pmi_im[eNB][5][0]);
+
+        len += sprintf(&buffer[len], "[UE PROC] Subband PMI eNB%d (Ant 1): [(%d %d) (%d %d) (%d %d) (%d %d) (%d %d) (%d %d)]\n",
+                       eNB,
+                       ue->measurements.subband_pmi_re[eNB][0][1],
+                       ue->measurements.subband_pmi_im[eNB][0][1],
+                       ue->measurements.subband_pmi_re[eNB][1][1],
+                       ue->measurements.subband_pmi_im[eNB][1][1],
+                       ue->measurements.subband_pmi_re[eNB][2][1],
+                       ue->measurements.subband_pmi_im[eNB][2][1],
+                       ue->measurements.subband_pmi_re[eNB][3][1],
+                       ue->measurements.subband_pmi_im[eNB][3][1],
+                       ue->measurements.subband_pmi_re[eNB][4][1],
+                       ue->measurements.subband_pmi_im[eNB][4][1],
+                       ue->measurements.subband_pmi_re[eNB][5][1],
+                       ue->measurements.subband_pmi_im[eNB][5][1]);
+
+        len += sprintf(&buffer[len], "[UE PROC] PMI Antenna selection eNB%d : [%d %d %d %d %d %d]\n",
+                       eNB,
+                       ue->measurements.selected_rx_antennas[eNB][0],
+                       ue->measurements.selected_rx_antennas[eNB][1],
+                       ue->measurements.selected_rx_antennas[eNB][2],
+                       ue->measurements.selected_rx_antennas[eNB][3],
+                       ue->measurements.selected_rx_antennas[eNB][4],
+                       ue->measurements.selected_rx_antennas[eNB][5]);
+
+        len += sprintf(&buffer[len], "[UE PROC] Quantized PMI eNB %d (max): %jx\n",eNB,pmi2hex_2Ar1(quantize_subband_pmi(&ue->measurements,eNB,6)));
+        len += sprintf(&buffer[len], "[UE PROC] Quantized PMI eNB %d (both): %jx,%jx\n",eNB,
+                       pmi2hex_2Ar1(quantize_subband_pmi2(&ue->measurements,eNB,0,6)),
+                       pmi2hex_2Ar1(quantize_subband_pmi2(&ue->measurements,eNB,1,6)));
+        break;
+
+      case 25:
+        len += sprintf(&buffer[len], "[UE PROC] Subband CQI eNB%d (Ant 0): [%d %d %d %d %d %d %d] dB\n",
+                       eNB,
+                       ue->measurements.subband_cqi_dB[eNB][0][0],
+                       ue->measurements.subband_cqi_dB[eNB][0][1],
+                       ue->measurements.subband_cqi_dB[eNB][0][2],
+                       ue->measurements.subband_cqi_dB[eNB][0][3],
+                       ue->measurements.subband_cqi_dB[eNB][0][4],
+                       ue->measurements.subband_cqi_dB[eNB][0][5],
+                       ue->measurements.subband_cqi_dB[eNB][0][6]);
+
+        len += sprintf(&buffer[len], "[UE PROC] Subband CQI eNB%d (Ant 1): [%d %d %d %d %d %d %d] dB\n",
+                       eNB,
+                       ue->measurements.subband_cqi_dB[eNB][1][0],
+                       ue->measurements.subband_cqi_dB[eNB][1][1],
+                       ue->measurements.subband_cqi_dB[eNB][1][2],
+                       ue->measurements.subband_cqi_dB[eNB][1][3],
+                       ue->measurements.subband_cqi_dB[eNB][1][4],
+                       ue->measurements.subband_cqi_dB[eNB][1][5],
+                       ue->measurements.subband_cqi_dB[eNB][1][6]);
+
+
+        len += sprintf(&buffer[len], "[UE PROC] Subband PMI eNB%d (Ant 0): [(%d %d) (%d %d) (%d %d) (%d %d) (%d %d) (%d %d) (%d %d)]\n",
+                       eNB,
+                       ue->measurements.subband_pmi_re[eNB][0][0],
+                       ue->measurements.subband_pmi_im[eNB][0][0],
+                       ue->measurements.subband_pmi_re[eNB][1][0],
+                       ue->measurements.subband_pmi_im[eNB][1][0],
+                       ue->measurements.subband_pmi_re[eNB][2][0],
+                       ue->measurements.subband_pmi_im[eNB][2][0],
+                       ue->measurements.subband_pmi_re[eNB][3][0],
+                       ue->measurements.subband_pmi_im[eNB][3][0],
+                       ue->measurements.subband_pmi_re[eNB][4][0],
+                       ue->measurements.subband_pmi_im[eNB][4][0],
+                       ue->measurements.subband_pmi_re[eNB][5][0],
+                       ue->measurements.subband_pmi_im[eNB][5][0],
+                       ue->measurements.subband_pmi_re[eNB][6][0],
+                       ue->measurements.subband_pmi_im[eNB][6][0]);
+
+        len += sprintf(&buffer[len], "[UE PROC] Subband PMI eNB%d (Ant 1): [(%d %d) (%d %d) (%d %d) (%d %d) (%d %d) (%d %d) (%d %d)]\n",
+                       eNB,
+                       ue->measurements.subband_pmi_re[eNB][0][1],
+                       ue->measurements.subband_pmi_im[eNB][0][1],
+                       ue->measurements.subband_pmi_re[eNB][1][1],
+                       ue->measurements.subband_pmi_im[eNB][1][1],
+                       ue->measurements.subband_pmi_re[eNB][2][1],
+                       ue->measurements.subband_pmi_im[eNB][2][1],
+                       ue->measurements.subband_pmi_re[eNB][3][1],
+                       ue->measurements.subband_pmi_im[eNB][3][1],
+                       ue->measurements.subband_pmi_re[eNB][4][1],
+                       ue->measurements.subband_pmi_im[eNB][4][1],
+                       ue->measurements.subband_pmi_re[eNB][5][1],
+                       ue->measurements.subband_pmi_im[eNB][5][1],
+                       ue->measurements.subband_pmi_re[eNB][6][1],
+                       ue->measurements.subband_pmi_im[eNB][6][1]);
+
+        len += sprintf(&buffer[len], "[UE PROC] PMI Antenna selection eNB%d : [%d %d %d %d %d %d %d]\n",
+                       eNB,
+                       ue->measurements.selected_rx_antennas[eNB][0],
+                       ue->measurements.selected_rx_antennas[eNB][1],
+                       ue->measurements.selected_rx_antennas[eNB][2],
+                       ue->measurements.selected_rx_antennas[eNB][3],
+                       ue->measurements.selected_rx_antennas[eNB][4],
+                       ue->measurements.selected_rx_antennas[eNB][5],
+                       ue->measurements.selected_rx_antennas[eNB][6]);
+
+        len += sprintf(&buffer[len], "[UE PROC] Quantized PMI eNB %d (max): %jx\n",eNB,pmi2hex_2Ar1(quantize_subband_pmi(&ue->measurements,eNB,7)));
+        len += sprintf(&buffer[len], "[UE PROC] Quantized PMI eNB %d (both): %jx,%jx\n",eNB,
+                       pmi2hex_2Ar1(quantize_subband_pmi2(&ue->measurements,eNB,0,7)),
+                       pmi2hex_2Ar1(quantize_subband_pmi2(&ue->measurements,eNB,1,7)));
+        break;
+
+      case 50:
+        len += sprintf(&buffer[len], "[UE PROC] Subband CQI eNB%d (Ant 0): [%d %d %d %d %d %d %d %d %d] dB\n",
+                       eNB,
+                       ue->measurements.subband_cqi_dB[eNB][0][0],
+                       ue->measurements.subband_cqi_dB[eNB][0][1],
+                       ue->measurements.subband_cqi_dB[eNB][0][2],
+                       ue->measurements.subband_cqi_dB[eNB][0][3],
+                       ue->measurements.subband_cqi_dB[eNB][0][4],
+                       ue->measurements.subband_cqi_dB[eNB][0][5],
+                       ue->measurements.subband_cqi_dB[eNB][0][6],
+                       ue->measurements.subband_cqi_dB[eNB][0][7],
+                       ue->measurements.subband_cqi_dB[eNB][0][8]);
+
+        len += sprintf(&buffer[len], "[UE PROC] Subband CQI eNB%d (Ant 1): [%d %d %d %d %d %d %d %d %d] dB\n",
+                       eNB,
+                       ue->measurements.subband_cqi_dB[eNB][1][0],
+                       ue->measurements.subband_cqi_dB[eNB][1][1],
+                       ue->measurements.subband_cqi_dB[eNB][1][2],
+                       ue->measurements.subband_cqi_dB[eNB][1][3],
+                       ue->measurements.subband_cqi_dB[eNB][1][4],
+                       ue->measurements.subband_cqi_dB[eNB][1][5],
+                       ue->measurements.subband_cqi_dB[eNB][1][6],
+                       ue->measurements.subband_cqi_dB[eNB][1][7],
+                       ue->measurements.subband_cqi_dB[eNB][1][8]);
+
+
+        len += sprintf(&buffer[len], "[UE PROC] Subband PMI eNB%d (Ant 0): [(%d %d) (%d %d) (%d %d) (%d %d) (%d %d) (%d %d) (%d %d) (%d %d) (%d %d)]\n",
+                       eNB,
+                       ue->measurements.subband_pmi_re[eNB][0][0],
+                       ue->measurements.subband_pmi_im[eNB][0][0],
+                       ue->measurements.subband_pmi_re[eNB][1][0],
+                       ue->measurements.subband_pmi_im[eNB][1][0],
+                       ue->measurements.subband_pmi_re[eNB][2][0],
+                       ue->measurements.subband_pmi_im[eNB][2][0],
+                       ue->measurements.subband_pmi_re[eNB][3][0],
+                       ue->measurements.subband_pmi_im[eNB][3][0],
+                       ue->measurements.subband_pmi_re[eNB][4][0],
+                       ue->measurements.subband_pmi_im[eNB][4][0],
+                       ue->measurements.subband_pmi_re[eNB][5][0],
+                       ue->measurements.subband_pmi_im[eNB][5][0],
+                       ue->measurements.subband_pmi_re[eNB][6][0],
+                       ue->measurements.subband_pmi_im[eNB][6][0],
+                       ue->measurements.subband_pmi_re[eNB][7][0],
+                       ue->measurements.subband_pmi_im[eNB][7][0],
+                       ue->measurements.subband_pmi_re[eNB][8][0],
+                       ue->measurements.subband_pmi_im[eNB][8][0]);
+
+        len += sprintf(&buffer[len], "[UE PROC] Subband PMI eNB%d (Ant 1): [(%d %d) (%d %d) (%d %d) (%d %d) (%d %d) (%d %d) (%d %d) (%d %d) (%d %d)]\n",
+                       eNB,
+                       ue->measurements.subband_pmi_re[eNB][0][1],
+                       ue->measurements.subband_pmi_im[eNB][0][1],
+                       ue->measurements.subband_pmi_re[eNB][1][1],
+                       ue->measurements.subband_pmi_im[eNB][1][1],
+                       ue->measurements.subband_pmi_re[eNB][2][1],
+                       ue->measurements.subband_pmi_im[eNB][2][1],
+                       ue->measurements.subband_pmi_re[eNB][3][1],
+                       ue->measurements.subband_pmi_im[eNB][3][1],
+                       ue->measurements.subband_pmi_re[eNB][4][1],
+                       ue->measurements.subband_pmi_im[eNB][4][1],
+                       ue->measurements.subband_pmi_re[eNB][5][1],
+                       ue->measurements.subband_pmi_im[eNB][5][1],
+                       ue->measurements.subband_pmi_re[eNB][6][1],
+                       ue->measurements.subband_pmi_im[eNB][6][1],
+                       ue->measurements.subband_pmi_re[eNB][7][1],
+                       ue->measurements.subband_pmi_im[eNB][7][1],
+                       ue->measurements.subband_pmi_re[eNB][8][1],
+                       ue->measurements.subband_pmi_im[eNB][8][1]);
+
+        len += sprintf(&buffer[len], "[UE PROC] PMI Antenna selection eNB%d : [%d %d %d %d %d %d %d %d %d]\n",
+                       eNB,
+                       ue->measurements.selected_rx_antennas[eNB][0],
+                       ue->measurements.selected_rx_antennas[eNB][1],
+                       ue->measurements.selected_rx_antennas[eNB][2],
+                       ue->measurements.selected_rx_antennas[eNB][3],
+                       ue->measurements.selected_rx_antennas[eNB][4],
+                       ue->measurements.selected_rx_antennas[eNB][5],
+                       ue->measurements.selected_rx_antennas[eNB][6],
+                       ue->measurements.selected_rx_antennas[eNB][7],
+                       ue->measurements.selected_rx_antennas[eNB][8]);
+
+        len += sprintf(&buffer[len], "[UE PROC] Quantized PMI eNB %d (max): %jx\n",eNB,pmi2hex_2Ar1(quantize_subband_pmi(&ue->measurements,eNB,9)));
+        len += sprintf(&buffer[len], "[UE PROC] Quantized PMI eNB %d (both): %jx,%jx\n",eNB,
+                       pmi2hex_2Ar1(quantize_subband_pmi2(&ue->measurements,eNB,0,9)),
+                       pmi2hex_2Ar1(quantize_subband_pmi2(&ue->measurements,eNB,1,9)));
+        break;
+
+      case 100:
+        len += sprintf(&buffer[len], "[UE PROC] Subband CQI eNB%d (Ant 0): [%d %d %d %d %d %d %d %d %d %d %d %d %d] dB\n",
+                       eNB,
+                       ue->measurements.subband_cqi_dB[eNB][0][0],
+                       ue->measurements.subband_cqi_dB[eNB][0][1],
+                       ue->measurements.subband_cqi_dB[eNB][0][2],
+                       ue->measurements.subband_cqi_dB[eNB][0][3],
+                       ue->measurements.subband_cqi_dB[eNB][0][4],
+                       ue->measurements.subband_cqi_dB[eNB][0][5],
+                       ue->measurements.subband_cqi_dB[eNB][0][6],
+                       ue->measurements.subband_cqi_dB[eNB][0][7],
+                       ue->measurements.subband_cqi_dB[eNB][0][8],
+                       ue->measurements.subband_cqi_dB[eNB][0][9],
+                       ue->measurements.subband_cqi_dB[eNB][0][10],
+                       ue->measurements.subband_cqi_dB[eNB][0][11],
+                       ue->measurements.subband_cqi_dB[eNB][0][12]);
+
+        len += sprintf(&buffer[len], "[UE PROC] Subband CQI eNB%d (Ant 1): [%d %d %d %d %d %d %d %d %d %d %d %d %d] dB\n",
+                       eNB,
+                       ue->measurements.subband_cqi_dB[eNB][1][0],
+                       ue->measurements.subband_cqi_dB[eNB][1][1],
+                       ue->measurements.subband_cqi_dB[eNB][1][2],
+                       ue->measurements.subband_cqi_dB[eNB][1][3],
+                       ue->measurements.subband_cqi_dB[eNB][1][4],
+                       ue->measurements.subband_cqi_dB[eNB][1][5],
+                       ue->measurements.subband_cqi_dB[eNB][1][6],
+                       ue->measurements.subband_cqi_dB[eNB][1][7],
+                       ue->measurements.subband_cqi_dB[eNB][1][8],
+                       ue->measurements.subband_cqi_dB[eNB][1][9],
+                       ue->measurements.subband_cqi_dB[eNB][1][10],
+                       ue->measurements.subband_cqi_dB[eNB][1][11],
+                       ue->measurements.subband_cqi_dB[eNB][1][12]);
+
+
+        len += sprintf(&buffer[len], "[UE PROC] Subband PMI eNB%d (Ant 0): [(%d %d) (%d %d) (%d %d) (%d %d) (%d %d) (%d %d) (%d %d) (%d %d) (%d %d) (%d %d) (%d %d) (%d %d) (%d %d)]\n",
+                       eNB,
+                       ue->measurements.subband_pmi_re[eNB][0][0],
+                       ue->measurements.subband_pmi_im[eNB][0][0],
+                       ue->measurements.subband_pmi_re[eNB][1][0],
+                       ue->measurements.subband_pmi_im[eNB][1][0],
+                       ue->measurements.subband_pmi_re[eNB][2][0],
+                       ue->measurements.subband_pmi_im[eNB][2][0],
+                       ue->measurements.subband_pmi_re[eNB][3][0],
+                       ue->measurements.subband_pmi_im[eNB][3][0],
+                       ue->measurements.subband_pmi_re[eNB][4][0],
+                       ue->measurements.subband_pmi_im[eNB][4][0],
+                       ue->measurements.subband_pmi_re[eNB][5][0],
+                       ue->measurements.subband_pmi_im[eNB][5][0],
+                       ue->measurements.subband_pmi_re[eNB][6][0],
+                       ue->measurements.subband_pmi_im[eNB][6][0],
+                       ue->measurements.subband_pmi_re[eNB][7][0],
+                       ue->measurements.subband_pmi_im[eNB][7][0],
+                       ue->measurements.subband_pmi_re[eNB][8][0],
+                       ue->measurements.subband_pmi_im[eNB][8][0],
+                       ue->measurements.subband_pmi_re[eNB][9][0],
+                       ue->measurements.subband_pmi_im[eNB][9][0],
+                       ue->measurements.subband_pmi_re[eNB][10][0],
+                       ue->measurements.subband_pmi_im[eNB][10][0],
+                       ue->measurements.subband_pmi_re[eNB][11][0],
+                       ue->measurements.subband_pmi_im[eNB][11][0],
+                       ue->measurements.subband_pmi_re[eNB][12][0],
+                       ue->measurements.subband_pmi_im[eNB][12][0]);
+
+        len += sprintf(&buffer[len], "[UE PROC] Subband PMI eNB%d (Ant 1): [(%d %d) (%d %d) (%d %d) (%d %d) (%d %d) (%d %d) (%d %d) (%d %d) (%d %d) (%d %d) (%d %d) (%d %d) (%d %d)]\n",
+                       eNB,
+                       ue->measurements.subband_pmi_re[eNB][0][1],
+                       ue->measurements.subband_pmi_im[eNB][0][1],
+                       ue->measurements.subband_pmi_re[eNB][1][1],
+                       ue->measurements.subband_pmi_im[eNB][1][1],
+                       ue->measurements.subband_pmi_re[eNB][2][1],
+                       ue->measurements.subband_pmi_im[eNB][2][1],
+                       ue->measurements.subband_pmi_re[eNB][3][1],
+                       ue->measurements.subband_pmi_im[eNB][3][1],
+                       ue->measurements.subband_pmi_re[eNB][4][1],
+                       ue->measurements.subband_pmi_im[eNB][4][1],
+                       ue->measurements.subband_pmi_re[eNB][5][1],
+                       ue->measurements.subband_pmi_im[eNB][5][1],
+                       ue->measurements.subband_pmi_re[eNB][6][1],
+                       ue->measurements.subband_pmi_im[eNB][6][1],
+                       ue->measurements.subband_pmi_re[eNB][7][1],
+                       ue->measurements.subband_pmi_im[eNB][7][1],
+                       ue->measurements.subband_pmi_re[eNB][8][1],
+                       ue->measurements.subband_pmi_im[eNB][8][1],
+                       ue->measurements.subband_pmi_re[eNB][9][1],
+                       ue->measurements.subband_pmi_im[eNB][9][1],
+                       ue->measurements.subband_pmi_re[eNB][10][1],
+                       ue->measurements.subband_pmi_im[eNB][10][1],
+                       ue->measurements.subband_pmi_re[eNB][11][1],
+                       ue->measurements.subband_pmi_im[eNB][11][1],
+                       ue->measurements.subband_pmi_re[eNB][12][1],
+                       ue->measurements.subband_pmi_im[eNB][12][1]);
+
+        len += sprintf(&buffer[len], "[UE PROC] PMI Antenna selection eNB%d : [%d %d %d %d %d %d %d %d %d %d %d %d %d]\n",
+                       eNB,
+                       ue->measurements.selected_rx_antennas[eNB][0],
+                       ue->measurements.selected_rx_antennas[eNB][1],
+                       ue->measurements.selected_rx_antennas[eNB][2],
+                       ue->measurements.selected_rx_antennas[eNB][3],
+                       ue->measurements.selected_rx_antennas[eNB][4],
+                       ue->measurements.selected_rx_antennas[eNB][5],
+                       ue->measurements.selected_rx_antennas[eNB][6],
+                       ue->measurements.selected_rx_antennas[eNB][7],
+                       ue->measurements.selected_rx_antennas[eNB][8],
+                       ue->measurements.selected_rx_antennas[eNB][9],
+                       ue->measurements.selected_rx_antennas[eNB][10],
+                       ue->measurements.selected_rx_antennas[eNB][11],
+                       ue->measurements.selected_rx_antennas[eNB][12]);
+
+        len += sprintf(&buffer[len], "[UE PROC] Quantized PMI eNB %d (max): %jx\n",eNB,pmi2hex_2Ar1(quantize_subband_pmi(&ue->measurements,eNB,13)));
+        len += sprintf(&buffer[len], "[UE PROC] Quantized PMI eNB %d (both): %jx,%jx\n",eNB,
+                       pmi2hex_2Ar1(quantize_subband_pmi2(&ue->measurements,eNB,0,13)),
+                       pmi2hex_2Ar1(quantize_subband_pmi2(&ue->measurements,eNB,1,13)));
+        break;
+      }
+
+#ifdef OPENAIR2
+      RRC_status = mac_UE_get_rrc_status(ue->Mod_id, 0);
+      len += sprintf(&buffer[len],"[UE PROC] RRC status = %d\n",RRC_status);
+#endif
+
+
+      len += sprintf(&buffer[len], "[UE PROC] Transmission Mode %d \n",ue->transmission_mode[eNB]);
+      len += sprintf(&buffer[len], "[UE PROC] PBCH err conseq %d, PBCH error total %d, PBCH FER %d\n",
+                     ue->pbch_vars[eNB]->pdu_errors_conseq,
+                     ue->pbch_vars[eNB]->pdu_errors,
+                     ue->pbch_vars[eNB]->pdu_fer);
+
+      if (ue->transmission_mode[eNB] == 6)
+        len += sprintf(&buffer[len], "[UE PROC] Mode 6 Wideband CQI eNB %d : %d dB\n",eNB,ue->measurements.precoded_cqi_dB[eNB][0]);
+
+      for (harq_pid=0;harq_pid<8;harq_pid++) {
+	len+=sprintf(&buffer[len],"[UE PROC] eNB %d: CW 0 harq_pid %d, mcs %d:",eNB,harq_pid,ue->dlsch[0][0][0]->harq_processes[harq_pid]->mcs);
+	for (round=0;round<8;round++)
+	  len+=sprintf(&buffer[len],"%d/%d ",
+		       ue->dlsch[0][0][0]->harq_processes[harq_pid]->errors[round],
+		       ue->dlsch[0][0][0]->harq_processes[harq_pid]->trials[round]);
+	len+=sprintf(&buffer[len],"\n");
+      }
+      if (ue->dlsch[0][0] && ue->dlsch[0][0][0] && ue->dlsch[0][0][1]) {
+        len += sprintf(&buffer[len], "[UE PROC] Saved PMI for DLSCH eNB %d : %jx (%p)\n",eNB,pmi2hex_2Ar1(ue->dlsch[0][0][0]->pmi_alloc),ue->dlsch[0][0][0]);
+
+        len += sprintf(&buffer[len], "[UE PROC] eNB %d: dl_power_off = %d\n",eNB,ue->dlsch[0][0][0]->harq_processes[0]->dl_power_off);
+
+	for (harq_pid=0;harq_pid<8;harq_pid++) {
+	  len+=sprintf(&buffer[len],"[UE PROC] eNB %d: CW 1 harq_pid %d, mcs %d:",eNB,harq_pid,ue->dlsch[0][0][1]->harq_processes[0]->mcs);
+	  for (round=0;round<8;round++)
+	    len+=sprintf(&buffer[len],"%d/%d ",
+			 ue->dlsch[0][0][1]->harq_processes[harq_pid]->errors[round],
+			 ue->dlsch[0][0][1]->harq_processes[harq_pid]->trials[round]);
+	  len+=sprintf(&buffer[len],"\n");
+	}
+      }
+
+      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)
+      int i=0;
+
+      //len += sprintf(&buffer[len], "[UE PROC] MCH  Total %d\n", ue->dlsch_mch_received[0]);
+      for(i=0; i <ue->frame_parms.num_MBSFN_config; i++ ) {
+        len += sprintf(&buffer[len], "[UE PROC] MCH (MCCH MBSFN %d) Total %d, Error %d, Trials %d\n",
+                       i, ue->dlsch_mcch_received[i][0],ue->dlsch_mcch_errors[i][0],ue->dlsch_mcch_trials[i][0]);
+        len += sprintf(&buffer[len], "[UE PROC] MCH (MTCH MBSFN %d) Total %d, Error %d, Trials %d\n",
+                       i, ue->dlsch_mtch_received[i][0],ue->dlsch_mtch_errors[i][0],ue->dlsch_mtch_trials[i][0]);
+      }
+
+#endif
+      len += sprintf(&buffer[len], "[UE PROC] DLSCH Bitrate %dkbps\n",(ue->bitrate[0]/1000));
+      len += sprintf(&buffer[len], "[UE PROC] Total Received Bits %dkbits\n",(ue->total_received_bits[0]/1000));
+      len += sprintf(&buffer[len], "[UE PROC] IA receiver %d\n",ue->use_ia_receiver);
+
+    }
+
+  } else {
+    len += sprintf(&buffer[len], "[UE PROC] Frame count: %d, RSSI %3.2f dB (%d dB, %d dB), N0 %3.2f dB (%d dB, %d dB)\n",
+                   proc->frame_rx,
+                   10*log10(ue->measurements.rssi),
+                   ue->measurements.rx_power_dB[0][0],
+                   ue->measurements.rx_power_dB[0][1],
+                   10*log10(ue->measurements.n0_power_tot),
+                   ue->measurements.n0_power_dB[0],
+                   ue->measurements.n0_power_dB[1]);
+#ifdef EXMIMO
+    ue->rx_total_gain_dB = ((int)(10*log10(ue->measurements.rssi)))-input_level_dBm;
+    len += sprintf(&buffer[len], "[UE PROC] rxg_mode %d, input level (set by user) %d dBm, VGA gain %d dB ==> total gain %3.2f dB, noise figure %3.2f dB\n",
+                   openair0_cfg[0].rxg_mode[0],
+                   input_level_dBm,
+                   (int)openair0_cfg[0].rx_gain[0],
+                   10*log10(ue->measurements.rssi)-input_level_dBm,
+                   10*log10(ue->measurements.n0_power_tot)-ue->rx_total_gain_dB+105);
+#endif
+  }
+
+  len += sprintf(&buffer[len],"EOF\n");
+
+  return len;
+} // is_clusterhead
+
+/*
+int dump_eNB_stats(PHY_VARS_eNB *eNB, char* buffer, int length)
+{
+
+  unsigned int success=0;
+  uint8_t eNB_id,UE_id,i,j,number_of_cards_l=1;
+  uint32_t ulsch_errors=0,dlsch_errors=0;
+  uint32_t ulsch_round_attempts[4]= {0,0,0,0},ulsch_round_errors[4]= {0,0,0,0};
+  uint32_t dlsch_round_attempts[4]= {0,0,0,0},dlsch_round_errors[4]= {0,0,0,0};
+  uint32_t UE_id_mac, RRC_status;
+  eNB_rxtx_proc_t *proc = &eNB->proc.proc_rxtx[0];
+  if (eNB==NULL)
+    return 0;
+
+  int len = length;
+
+  //  if(eNB->frame==0){
+  eNB->total_dlsch_bitrate = 0;//eNB->UE_stats[UE_id].dlsch_bitrate + eNB->total_dlsch_bitrate;
+  eNB->total_transmitted_bits = 0;// eNB->UE_stats[UE_id].total_transmitted_bits +  eNB->total_transmitted_bits;
+  eNB->total_system_throughput = 0;//eNB->UE_stats[UE_id].total_transmitted_bits + eNB->total_system_throughput;
+  // }
+
+  for (eNB_id=0; eNB_id<number_of_cards_l; eNB_id++) {
+    len += sprintf(&buffer[len],"eNB %d/%d Frame %d: RX Gain %d dB, I0 %d dBm (%d,%d) dB \n",
+                   eNB_id,number_of_cards_l,
+                   proc->frame_tx,
+                   eNB->rx_total_gain_dB,
+                   eNB->measurements.n0_power_tot_dBm,
+                   eNB->measurements.n0_power_dB[0],
+                   eNB->measurements.n0_power_dB[1]);
+
+    len += sprintf(&buffer[len],"PRB I0 (%X.%X.%X.%X): ",
+		   eNB->rb_mask_ul[0],
+		   eNB->rb_mask_ul[1],eNB->rb_mask_ul[2],eNB->rb_mask_ul[3]);
+
+    for (i=0; i<eNB->frame_parms.N_RB_UL; i++) {
+      len += sprintf(&buffer[len],"%4d ",
+                     eNB->measurements.n0_subband_power_tot_dBm[i]);
+      if ((i>0) && ((i%25) == 0))
+	len += sprintf(&buffer[len],"\n");
+    }
+    len += sprintf(&buffer[len],"\n");
+    len += sprintf(&buffer[len],"\nPERFORMANCE PARAMETERS\n");
+
+    for (UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++) {
+      if (eNB &&
+	  (eNB->dlsch!=NULL) &&
+	  (eNB->dlsch[(uint8_t)UE_id]!=NULL) &&
+	  (eNB->dlsch[(uint8_t)UE_id][0]->rnti>0)&&
+	  (eNB->UE_stats[UE_id].mode == PUSCH)) {
+
+        eNB->total_dlsch_bitrate = eNB->UE_stats[UE_id].dlsch_bitrate + eNB->total_dlsch_bitrate;
+        eNB->total_transmitted_bits = eNB->UE_stats[UE_id].total_TBS + eNB->total_transmitted_bits;
+
+        //eNB->total_system_throughput = eNB->UE_stats[UE_id].total_transmitted_bits + eNB->total_system_throughput;
+
+	for (i=0; i<8; i++)
+	  success = success + (eNB->UE_stats[UE_id].dlsch_trials[i][0] - eNB->UE_stats[UE_id].dlsch_l2_errors[i]);
+
+
+
+	len += sprintf(&buffer[len],"Total DLSCH %d kbits / %d frames ",(eNB->total_transmitted_bits/1000),proc->frame_tx+1);
+	len += sprintf(&buffer[len],"Total DLSCH throughput %d kbps ",(eNB->total_dlsch_bitrate/1000));
+	len += sprintf(&buffer[len],"Total DLSCH trans %d / %d frames\n",success,proc->frame_tx+1);
+	//len += sprintf(&buffer[len],"[eNB PROC] FULL MU-MIMO Transmissions/Total Transmissions = %d/%d\n",eNB->FULL_MUMIMO_transmissions,eNB->check_for_total_transmissions);
+	//len += sprintf(&buffer[len],"[eNB PROC] MU-MIMO Transmissions/Total Transmissions = %d/%d\n",eNB->check_for_MUMIMO_transmissions,eNB->check_for_total_transmissions);
+	//len += sprintf(&buffer[len],"[eNB PROC] SU-MIMO Transmissions/Total Transmissions = %d/%d\n",eNB->check_for_SUMIMO_transmissions,eNB->check_for_total_transmissions);
+
+	len += sprintf(&buffer[len],"UE %d (%x) Power: (%d,%d) dB, Po_PUSCH: (%d,%d) dBm, Po_PUCCH (%d/%d) dBm, Po_PUCCH1 (%d,%d) dBm,  PUCCH1 Thres %d dBm \n",
+		       UE_id,
+		       eNB->UE_stats[UE_id].crnti,
+		       dB_fixed(eNB->pusch_vars[UE_id]->ulsch_power[0]),
+		       dB_fixed(eNB->pusch_vars[UE_id]->ulsch_power[1]),
+		       eNB->UE_stats[UE_id].UL_rssi[0],
+		       eNB->UE_stats[UE_id].UL_rssi[1],
+		       dB_fixed(eNB->UE_stats[UE_id].Po_PUCCH/eNB->frame_parms.N_RB_UL)-eNB->rx_total_gain_dB,
+		       eNB->frame_parms.ul_power_control_config_common.p0_NominalPUCCH,
+		       dB_fixed(eNB->UE_stats[UE_id].Po_PUCCH1_below/eNB->frame_parms.N_RB_UL)-eNB->rx_total_gain_dB,
+		       dB_fixed(eNB->UE_stats[UE_id].Po_PUCCH1_above/eNB->frame_parms.N_RB_UL)-eNB->rx_total_gain_dB,
+		       PUCCH1_THRES+eNB->measurements.n0_power_tot_dBm-dB_fixed(eNB->frame_parms.N_RB_UL));
+
+	len+= sprintf(&buffer[len],"DL mcs %d, UL mcs %d, UL rb %d, delta_TF %d, ",
+		      eNB->dlsch[(uint8_t)UE_id][0]->harq_processes[0]->mcs,
+		      eNB->ulsch[(uint8_t)UE_id]->harq_processes[0]->mcs,
+		      eNB->ulsch[(uint8_t)UE_id]->harq_processes[0]->nb_rb,
+		      eNB->ulsch[(uint8_t)UE_id]->harq_processes[0]->delta_TF);
+
+	len += sprintf(&buffer[len],"Wideband CQI: (%d,%d) dB\n",
+		       eNB->measurements.wideband_cqi_dB[UE_id][0],
+		       eNB->measurements.wideband_cqi_dB[UE_id][1]);
+
+	len += sprintf(&buffer[len],"DL TM %d, DL_cqi %d, DL_pmi_single %jx ",
+		       eNB->transmission_mode[UE_id],
+		       eNB->UE_stats[UE_id].DL_cqi[0],
+		       pmi2hex_2Ar1(eNB->UE_stats[UE_id].DL_pmi_single));
+
+	len += sprintf(&buffer[len],"Timing advance %d samples (%d 16Ts), update %d ",
+		       eNB->UE_stats[UE_id].UE_timing_offset,
+		       eNB->UE_stats[UE_id].UE_timing_offset>>2,
+		       eNB->UE_stats[UE_id].timing_advance_update);
+
+	len += sprintf(&buffer[len],"Mode = %s(%d) ",
+		       mode_string[eNB->UE_stats[UE_id].mode],
+		       eNB->UE_stats[UE_id].mode);
+	UE_id_mac = find_UE_id(eNB->Mod_id,eNB->dlsch[(uint8_t)UE_id][0]->rnti);
+
+	if (UE_id_mac != -1) {
+	  RRC_status = mac_eNB_get_rrc_status(eNB->Mod_id,eNB->dlsch[(uint8_t)UE_id][0]->rnti);
+	  len += sprintf(&buffer[len],"UE_id_mac = %d, RRC status = %d\n",UE_id_mac,RRC_status);
+	} else
+	  len += sprintf(&buffer[len],"UE_id_mac = -1\n");
+
+        len += sprintf(&buffer[len],"SR received/total: %d/%d (diff %d)\n",
+                       eNB->UE_stats[UE_id].sr_received,
+                       eNB->UE_stats[UE_id].sr_total,
+                       eNB->UE_stats[UE_id].sr_total-eNB->UE_stats[UE_id].sr_received);
+
+	len += sprintf(&buffer[len],"DL Subband CQI: ");
+
+	int nb_sb;
+	switch (eNB->frame_parms.N_RB_DL) {
+	case 6:
+	  nb_sb=0;
+	  break;
+	case 15:
+	  nb_sb = 4;
+	case 25:
+	  nb_sb = 7;
+	  break;
+	case 50:
+	  nb_sb = 9;
+	  break;
+	case 75:
+	  nb_sb = 10;
+	  break;
+	case 100:
+	  nb_sb = 13;
+	  break;
+	default:
+	  nb_sb=0;
+	  break;
+	}
+	for (i=0; i<nb_sb; i++)
+	  len += sprintf(&buffer[len],"%2d ",
+			 eNB->UE_stats[UE_id].DL_subband_cqi[0][i]);
+	len += sprintf(&buffer[len],"\n");
+
+
+
+        ulsch_errors = 0;
+
+        for (j=0; j<4; j++) {
+          ulsch_round_attempts[j]=0;
+          ulsch_round_errors[j]=0;
+        }
+
+        len += sprintf(&buffer[len],"ULSCH errors/attempts per harq (per round): \n");
+
+        for (i=0; i<8; i++) {
+          len += sprintf(&buffer[len],"   harq %d: %d/%d (fer %d) (%d/%d, %d/%d, %d/%d, %d/%d) ",
+                         i,
+                         eNB->UE_stats[UE_id].ulsch_errors[i],
+                         eNB->UE_stats[UE_id].ulsch_decoding_attempts[i][0],
+                         eNB->UE_stats[UE_id].ulsch_round_fer[i][0],
+                         eNB->UE_stats[UE_id].ulsch_round_errors[i][0],
+                         eNB->UE_stats[UE_id].ulsch_decoding_attempts[i][0],
+                         eNB->UE_stats[UE_id].ulsch_round_errors[i][1],
+                         eNB->UE_stats[UE_id].ulsch_decoding_attempts[i][1],
+                         eNB->UE_stats[UE_id].ulsch_round_errors[i][2],
+                         eNB->UE_stats[UE_id].ulsch_decoding_attempts[i][2],
+                         eNB->UE_stats[UE_id].ulsch_round_errors[i][3],
+                         eNB->UE_stats[UE_id].ulsch_decoding_attempts[i][3]);
+	  if ((i&1) == 1)
+	    len += sprintf(&buffer[len],"\n");
+
+          ulsch_errors+=eNB->UE_stats[UE_id].ulsch_errors[i];
+
+          for (j=0; j<4; j++) {
+            ulsch_round_attempts[j]+=eNB->UE_stats[UE_id].ulsch_decoding_attempts[i][j];
+            ulsch_round_errors[j]+=eNB->UE_stats[UE_id].ulsch_round_errors[i][j];
+          }
+        }
+
+        len += sprintf(&buffer[len],"ULSCH errors/attempts total %d/%d (%d/%d, %d/%d, %d/%d, %d/%d)\n",
+                       ulsch_errors,ulsch_round_attempts[0],
+
+                       ulsch_round_errors[0],ulsch_round_attempts[0],
+                       ulsch_round_errors[1],ulsch_round_attempts[1],
+                       ulsch_round_errors[2],ulsch_round_attempts[2],
+                       ulsch_round_errors[3],ulsch_round_attempts[3]);
+
+        dlsch_errors = 0;
+
+        for (j=0; j<4; j++) {
+          dlsch_round_attempts[j]=0;
+          dlsch_round_errors[j]=0;
+        }
+
+        len += sprintf(&buffer[len],"DLSCH errors/attempts per harq (per round): \n");
+
+        for (i=0; i<8; i++) {
+          len += sprintf(&buffer[len],"   harq %d: %d/%d (%d/%d/%d, %d/%d/%d, %d/%d/%d, %d/%d/%d) ",
+                         i,
+                         eNB->UE_stats[UE_id].dlsch_l2_errors[i],
+                         eNB->UE_stats[UE_id].dlsch_trials[i][0],
+                         eNB->UE_stats[UE_id].dlsch_ACK[i][0],
+                         eNB->UE_stats[UE_id].dlsch_NAK[i][0],
+                         eNB->UE_stats[UE_id].dlsch_trials[i][0],
+                         eNB->UE_stats[UE_id].dlsch_ACK[i][1],
+                         eNB->UE_stats[UE_id].dlsch_NAK[i][1],
+                         eNB->UE_stats[UE_id].dlsch_trials[i][1],
+                         eNB->UE_stats[UE_id].dlsch_ACK[i][2],
+                         eNB->UE_stats[UE_id].dlsch_NAK[i][2],
+                         eNB->UE_stats[UE_id].dlsch_trials[i][2],
+                         eNB->UE_stats[UE_id].dlsch_ACK[i][3],
+                         eNB->UE_stats[UE_id].dlsch_NAK[i][3],
+                         eNB->UE_stats[UE_id].dlsch_trials[i][3]);
+	  if ((i&1) == 1)
+	    len += sprintf(&buffer[len],"\n");
+
+
+          dlsch_errors+=eNB->UE_stats[UE_id].dlsch_l2_errors[i];
+
+          for (j=0; j<4; j++) {
+            dlsch_round_attempts[j]+=eNB->UE_stats[UE_id].dlsch_trials[i][j];
+            dlsch_round_errors[j]+=eNB->UE_stats[UE_id].dlsch_NAK[i][j];
+          }
+        }
+
+        len += sprintf(&buffer[len],"DLSCH errors/attempts total %d/%d (%d/%d, %d/%d, %d/%d, %d/%d): \n",
+                       dlsch_errors,dlsch_round_attempts[0],
+                       dlsch_round_errors[0],dlsch_round_attempts[0],
+                       dlsch_round_errors[1],dlsch_round_attempts[1],
+                       dlsch_round_errors[2],dlsch_round_attempts[2],
+                       dlsch_round_errors[3],dlsch_round_attempts[3]);
+
+
+        len += sprintf(&buffer[len],"DLSCH total bits from MAC: %dkbit ",(eNB->UE_stats[UE_id].total_TBS_MAC)/1000);
+        len += sprintf(&buffer[len],"DLSCH total bits ack'ed: %dkbit ",(eNB->UE_stats[UE_id].total_TBS)/1000);
+        len += sprintf(&buffer[len],"DLSCH Average throughput (100 frames): %dkbps\n",(eNB->UE_stats[UE_id].dlsch_bitrate/1000));
+	//        len += sprintf(&buffer[len],"[eNB PROC] Transmission Mode %d\n",eNB->transmission_mode[UE_id]);
+      }
+    }
+
+    len += sprintf(&buffer[len],"\n");
+  }
+
+  len += sprintf(&buffer[len],"EOF\n");
+
+  return len;
+}
+*/
diff --git a/openair1/PHY/LTE_TRANSPORT/pucch.c b/openair1/PHY/LTE_TRANSPORT/pucch.c
index 0e7ab9e9a2eb6ee78cbad07af06e2fad0dec586c..e14bbea3387a1b17b3e82eb8b86777b77506e802 100644
--- a/openair1/PHY/LTE_TRANSPORT/pucch.c
+++ b/openair1/PHY/LTE_TRANSPORT/pucch.c
@@ -718,7 +718,11 @@ uint32_t rx_pucch(PHY_VARS_eNB *eNB,
 		  uint8_t *payload,
 		  int     frame,
 		  uint8_t subframe,
-		  uint8_t pucch1_thres)
+		  uint8_t pucch1_thres
+#ifdef Rel14
+		  ,uint8_t br_flag
+#endif
+		  )
 {
 
 
@@ -727,7 +731,8 @@ uint32_t rx_pucch(PHY_VARS_eNB *eNB,
   LTE_DL_FRAME_PARMS *frame_parms                    = &eNB->frame_parms;
   //  PUCCH_CONFIG_DEDICATED *pucch_config_dedicated = &eNB->pucch_config_dedicated[UE_id];
 
-  int8_t sigma2_dB                                   = 20;//eNB->measurements.n0_subband_power_tot_dB[0]-10;
+  int8_t sigma2_dB                                   = max(eNB->measurements.n0_subband_power_tot_dB[0],
+                                                           eNB->measurements.n0_subband_power_tot_dB[eNB->frame_parms.N_RB_UL-1]);
 
   uint32_t u,v,n,aa;
   uint32_t z[12*14];
@@ -984,14 +989,25 @@ 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++) {
-      if ((l<(nsymb>>1)) && ((m&1) == 0))
-        re_offset = (m*6) + frame_parms->first_carrier_offset;
-      else if ((l<(nsymb>>1)) && ((m&1) == 1))
-        re_offset = frame_parms->first_carrier_offset + (frame_parms->N_RB_DL - (m>>1) - 1)*12;
-      else if ((m&1) == 0)
-        re_offset = frame_parms->first_carrier_offset + (frame_parms->N_RB_DL - (m>>1) - 1)*12;
+#ifdef Rel14
+      if (br_flag > 0 ) {
+        if ((m&1) == 0)
+          re_offset = (m*6) + frame_parms->first_carrier_offset;
+	else
+	  re_offset = frame_parms->first_carrier_offset + (frame_parms->N_RB_DL - (m>>1) - 1)*12;
+      }
       else
-        re_offset = ((m-1)*6) + frame_parms->first_carrier_offset;
+#endif
+      {
+        if ((l<(nsymb>>1)) && ((m&1) == 0))
+          re_offset = (m*6) + frame_parms->first_carrier_offset;
+        else if ((l<(nsymb>>1)) && ((m&1) == 1))
+          re_offset = frame_parms->first_carrier_offset + (frame_parms->N_RB_DL - (m>>1) - 1)*12;
+        else if ((m&1) == 0)
+          re_offset = frame_parms->first_carrier_offset + (frame_parms->N_RB_DL - (m>>1) - 1)*12;
+        else
+          re_offset = ((m-1)*6) + frame_parms->first_carrier_offset;
+      }
 
       if (re_offset > frame_parms->ofdm_symbol_size)
         re_offset -= (frame_parms->ofdm_symbol_size);
@@ -1302,7 +1318,7 @@ uint32_t rx_pucch(PHY_VARS_eNB *eNB,
 #endif
 	  }
 	  
-      
+
 
 #ifdef DEBUG_PUCCH_RX
           printf("[eNB] PUCCH subframe %d chest1[%d][%d] => (%d,%d)\n",subframe,aa,re,
diff --git a/openair1/PHY/LTE_TRANSPORT/transport_common.h b/openair1/PHY/LTE_TRANSPORT/transport_common.h
index 130c9737749fbae5025ba3bf1f0fd50b18027637..c1104cd29050fbdfff1633e3b869174b1da88a50 100644
--- a/openair1/PHY/LTE_TRANSPORT/transport_common.h
+++ b/openair1/PHY/LTE_TRANSPORT/transport_common.h
@@ -105,7 +105,7 @@ typedef enum {
 
 
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 typedef enum {
   CEmodeA = 0,
   CEmodeB = 1
@@ -138,7 +138,7 @@ typedef enum {
   HARQ_SR_CQI  
 } UCI_type_t;
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 typedef enum {
   NOCE,
   CEMODEA,
@@ -183,7 +183,7 @@ typedef struct {
   PRACH_TDD_PREAMBLE_MAP_elem map[6];
 } PRACH_TDD_PREAMBLE_MAP;
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 
 typedef struct {
   uint16_t slss_id;
diff --git a/openair1/PHY/LTE_TRANSPORT/transport_eNB.h b/openair1/PHY/LTE_TRANSPORT/transport_eNB.h
index d1dd595d3599ad248f0776f5834dc8cb6670a6d8..ddf3594880ed147933d1a3e49a1968f3ab5f045b 100644
--- a/openair1/PHY/LTE_TRANSPORT/transport_eNB.h
+++ b/openair1/PHY/LTE_TRANSPORT/transport_eNB.h
@@ -50,6 +50,7 @@
 
 
 
+
 typedef struct {
   /// Status Flag indicating for this DLSCH (idle,active,disabled)
   SCH_status_t status;
@@ -126,7 +127,7 @@ typedef struct {
   /// codeword this transport block is mapped to
   uint8_t codeword;
 #ifdef PHY_TX_THREAD
-#ifdef Rel14
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   /// indicator that this DLSCH corresponds to SIB1-BR, needed for c_init for scrambling
   uint8_t sib1_br_flag;
   /// initial absolute subframe (see 36.211 Section 6.3.1), needed for c_init for scrambling
@@ -183,7 +184,7 @@ typedef struct {
   /// amplitude of PDSCH (compared to RS) in symbols containing pilots
   int16_t sqrt_rho_b;
 #ifndef PHY_TX_THREAD
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   /// indicator that this DLSCH corresponds to SIB1-BR, needed for c_init for scrambling
   uint8_t sib1_br_flag;
   /// initial absolute subframe (see 36.211 Section 6.3.1), needed for c_init for scrambling
@@ -348,7 +349,7 @@ typedef struct {
   uint8_t     tdd_bundling;
   /// Received Energy
   uint32_t stat;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   /// non BL/CE, CEmodeA, CEmodeB
   UE_type_t ue_type;
   /// Indicates the symbols that are left empty due to eMTC retuning.
@@ -443,6 +444,10 @@ typedef struct {
 } LTE_eNB_UE_stats;
 
 typedef struct {
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  /// UE type (normal, CEModeA, CEModeB)
+  uint8_t ue_type;
+#endif
   /// HARQ process mask, indicates which processes are currently active
   uint16_t harq_mask;
   /// Pointers to 8 HARQ processes for the ULSCH
diff --git a/openair1/PHY/LTE_TRANSPORT/transport_proto.h b/openair1/PHY/LTE_TRANSPORT/transport_proto.h
index 37ac335d02c632238539ede9af847e61b101eafe..f4919c6403c9bd34d6badc9c793049b4f4485ba7 100644
--- a/openair1/PHY/LTE_TRANSPORT/transport_proto.h
+++ b/openair1/PHY/LTE_TRANSPORT/transport_proto.h
@@ -273,7 +273,7 @@ int mch_modulation(int32_t **txdataF,
     @param abstraction_flag
 
 */
-void generate_mch(PHY_VARS_eNB *phy_vars_eNB,eNB_rxtx_proc_t *proc,uint8_t *a);
+void generate_mch(PHY_VARS_eNB *phy_vars_eNB,L1_rxtx_proc_t *proc,uint8_t *a);
 
 /** \brief This function generates the frequency-domain pilots (cell-specific downlink reference signals)
     @param phy_vars_eNB Pointer to eNB variables
@@ -317,7 +317,7 @@ int32_t generate_pilots_slot(PHY_VARS_eNB *phy_vars_eNB,
                              int first_pilot_only);
 
 int32_t generate_mbsfn_pilot(PHY_VARS_eNB *phy_vars_eNB,
-                             eNB_rxtx_proc_t *proc,
+                             L1_rxtx_proc_t *proc,
                              int32_t **txdataF,
                              int16_t amp);
 
@@ -385,6 +385,8 @@ uint8_t generate_dci_top(uint8_t num_pdcch_symbols,
                          uint32_t sub_frame_offset);
 
 
+void generate_mdci_top(PHY_VARS_eNB * eNB, int frame, int subframe, int16_t amp, int32_t ** txdataF);
+
 void generate_64qam_table(void);
 void generate_16qam_table(void);
 
@@ -410,24 +412,26 @@ void ulsch_extract_rbs_single(int32_t **rxdataF,
 void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,
                         int frame,
                         int subframe,
-			eNB_rxtx_proc_t *proc,
+			L1_rxtx_proc_t *proc,
 			DCI_ALLOC_t *dci_alloc,
 			nfapi_dl_config_dci_dl_pdu *pdu);
 
-void fill_mdci_and_dlsch(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,mDCI_ALLOC_t *dci_alloc,nfapi_dl_config_mpdcch_pdu *pdu);
+void fill_mdci_and_dlsch(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc,mDCI_ALLOC_t *dci_alloc,nfapi_dl_config_mpdcch_pdu *pdu);
 
-void fill_dci0(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t *proc,DCI_ALLOC_t *dci_alloc,
+void fill_dci0(PHY_VARS_eNB *eNB,int frame,int subframe,L1_rxtx_proc_t *proc,DCI_ALLOC_t *dci_alloc,
 	      nfapi_hi_dci0_dci_pdu *pdu);
 
 void fill_ulsch(PHY_VARS_eNB *eNB,int UE_id,nfapi_ul_config_ulsch_pdu *ulsch_pdu,int frame,int subframe);
 
+void fill_mpdcch_dci0 (PHY_VARS_eNB * eNB, L1_rxtx_proc_t * proc, mDCI_ALLOC_t * dci_alloc, nfapi_hi_dci0_mpdcch_dci_pdu * pdu);
+
 int generate_eNB_ulsch_params_from_rar(PHY_VARS_eNB *eNB,
 				       unsigned char *rar_pdu,
                                        uint32_t frame,
                                        unsigned char subframe);
 
 int generate_eNB_ulsch_params_from_dci(PHY_VARS_eNB *PHY_vars_eNB,
-                                       eNB_rxtx_proc_t *proc,
+                                       L1_rxtx_proc_t *proc,
                                        void *dci_pdu,
                                        rnti_t rnti,
                                        DCI_format_t dci_format,
@@ -457,16 +461,8 @@ void generate_pcfich(uint8_t num_pdcch_symbols,
                      int32_t **txdataF,
                      uint8_t subframe);
 
-
-
-
-
-void init_transport_channels(uint8_t);
-
-
-
 void rx_ulsch(PHY_VARS_eNB *eNB,
-              eNB_rxtx_proc_t *proc,
+              L1_rxtx_proc_t *proc,
               uint8_t UE_id);
 
 
@@ -487,7 +483,7 @@ int ulsch_decoding_data_all(PHY_VARS_eNB *eNB,
   @returns 0 on success
 */
 unsigned int  ulsch_decoding(PHY_VARS_eNB *phy_vars_eNB,
-                             eNB_rxtx_proc_t *proc,
+                             L1_rxtx_proc_t *proc,
                              uint8_t UE_id,
                              uint8_t control_only_flag,
                              uint8_t Nbundled,
@@ -520,7 +516,7 @@ int ulsch_decoding_data(PHY_VARS_eNB *eNB,
                         int llr8_flag);
 
 void generate_phich_top(PHY_VARS_eNB *phy_vars_eNB,
-			eNB_rxtx_proc_t *proc,
+			L1_rxtx_proc_t *proc,
                         int16_t amp);
 
 
@@ -578,7 +574,7 @@ void rx_prach(PHY_VARS_eNB *phy_vars_eNB,RU_t *ru,
 	      uint16_t *max_preamble_energy, 
 	      uint16_t *max_preamble_delay, 
 	      uint16_t Nf, uint8_t tdd_mapindex
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 	      ,
               uint8_t br_flag
 #endif
diff --git a/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c b/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c
index 046e456916a104bf5afc892142a9317807ac4e80..e1807d4d2c446d1ffed39000db99384fdf246cdf 100644
--- a/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c
+++ b/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c
@@ -47,9 +47,7 @@
 
 extern WORKER_CONF_t get_thread_worker_conf(void);
 
-void free_eNB_ulsch(LTE_eNB_ULSCH_t *ulsch)
-{
-
+void free_eNB_ulsch(LTE_eNB_ULSCH_t *ulsch) {
   int i,r;
 
   if (ulsch) {
@@ -77,33 +75,30 @@ void free_eNB_ulsch(LTE_eNB_ULSCH_t *ulsch)
     }
 
     free16(ulsch,sizeof(LTE_eNB_ULSCH_t));
-    ulsch = NULL;
   }
 }
 
-LTE_eNB_ULSCH_t *new_eNB_ulsch(uint8_t max_turbo_iterations,uint8_t N_RB_UL, uint8_t abstraction_flag)
-{
-
+LTE_eNB_ULSCH_t *new_eNB_ulsch(uint8_t max_turbo_iterations,uint8_t N_RB_UL, uint8_t abstraction_flag) {
   LTE_eNB_ULSCH_t *ulsch;
   uint8_t exit_flag = 0,i,r;
   unsigned char bw_scaling =1;
 
   switch (N_RB_UL) {
-  case 6:
-    bw_scaling =16;
-    break;
+    case 6:
+      bw_scaling =16;
+      break;
 
-  case 25:
-    bw_scaling =4;
-    break;
+    case 25:
+      bw_scaling =4;
+      break;
 
-  case 50:
-    bw_scaling =2;
-    break;
+    case 50:
+      bw_scaling =2;
+      break;
 
-  default:
-    bw_scaling =1;
-    break;
+    default:
+      bw_scaling =1;
+      break;
   }
 
   ulsch = (LTE_eNB_ULSCH_t *)malloc16(sizeof(LTE_eNB_ULSCH_t));
@@ -119,7 +114,7 @@ LTE_eNB_ULSCH_t *new_eNB_ulsch(uint8_t max_turbo_iterations,uint8_t N_RB_UL, uin
 
       if (ulsch->harq_processes[i]) {
         memset(ulsch->harq_processes[i],0,sizeof(LTE_UL_eNB_HARQ_t));
-        ulsch->harq_processes[i]->b = (uint8_t*)malloc16(MAX_ULSCH_PAYLOAD_BYTES/bw_scaling);
+        ulsch->harq_processes[i]->b = (uint8_t *)malloc16(MAX_ULSCH_PAYLOAD_BYTES/bw_scaling);
 
         if (ulsch->harq_processes[i]->b)
           memset(ulsch->harq_processes[i]->b,0,MAX_ULSCH_PAYLOAD_BYTES/bw_scaling);
@@ -128,13 +123,14 @@ LTE_eNB_ULSCH_t *new_eNB_ulsch(uint8_t max_turbo_iterations,uint8_t N_RB_UL, uin
 
         if (abstraction_flag==0) {
           for (r=0; r<MAX_NUM_ULSCH_SEGMENTS/bw_scaling; r++) {
-            ulsch->harq_processes[i]->c[r] = (uint8_t*)malloc16(((r==0)?8:0) + 3+768);
+            ulsch->harq_processes[i]->c[r] = (uint8_t *)malloc16(((r==0)?8:0) + 3+768);
+
             if (ulsch->harq_processes[i]->c[r])
               memset(ulsch->harq_processes[i]->c[r],0,((r==0)?8:0) + 3+768);
             else
               exit_flag=2;
 
-            ulsch->harq_processes[i]->d[r] = (short*)malloc16(((3*8*6144)+12+96)*sizeof(short));
+            ulsch->harq_processes[i]->d[r] = (short *)malloc16(((3*8*6144)+12+96)*sizeof(short));
 
             if (ulsch->harq_processes[i]->d[r])
               memset(ulsch->harq_processes[i]->d[r],0,((3*8*6144)+12+96)*sizeof(short));
@@ -153,13 +149,10 @@ LTE_eNB_ULSCH_t *new_eNB_ulsch(uint8_t max_turbo_iterations,uint8_t N_RB_UL, uin
 
   LOG_E(PHY,"new_ue_ulsch: exit_flag = %d\n",exit_flag);
   free_eNB_ulsch(ulsch);
-
   return(NULL);
 }
 
-void clean_eNb_ulsch(LTE_eNB_ULSCH_t *ulsch)
-{
-
+void clean_eNb_ulsch(LTE_eNB_ULSCH_t *ulsch) {
   unsigned char i;
 
   //ulsch = (LTE_eNB_ULSCH_t *)malloc16(sizeof(LTE_eNB_ULSCH_t));
@@ -180,9 +173,11 @@ void clean_eNb_ulsch(LTE_eNB_ULSCH_t *ulsch)
         ulsch->harq_processes[i]->TBS = 0;
         ulsch->harq_processes[i]->Or1 = 0;
         ulsch->harq_processes[i]->Or2 = 0;
+
         for ( int j = 0; j < 2; j++ ) {
           ulsch->harq_processes[i]->o_RI[j] = 0;
         }
+
         ulsch->harq_processes[i]->O_ACK = 0;
         ulsch->harq_processes[i]->srs_active = 0;
         ulsch->harq_processes[i]->rvidx = 0;
@@ -190,6 +185,7 @@ void clean_eNb_ulsch(LTE_eNB_ULSCH_t *ulsch)
         ulsch->harq_processes[i]->Nsymb_initial = 0;
       }
     }
+
     ulsch->beta_offset_cqi_times8 = 0;
     ulsch->beta_offset_ri_times8 = 0;
     ulsch->beta_offset_harqack_times8 = 0;
@@ -198,11 +194,8 @@ void clean_eNb_ulsch(LTE_eNB_ULSCH_t *ulsch)
 }
 
 
-uint8_t extract_cqi_crc(uint8_t *cqi,uint8_t CQI_LENGTH)
-{
-
+uint8_t extract_cqi_crc(uint8_t *cqi,uint8_t CQI_LENGTH) {
   uint8_t crc;
-
   crc = cqi[CQI_LENGTH>>3];
   //  printf("crc1: %x, shift %d\n",crc,CQI_LENGTH&0x7);
   crc = (crc<<(CQI_LENGTH&0x7));
@@ -212,22 +205,18 @@ uint8_t extract_cqi_crc(uint8_t *cqi,uint8_t CQI_LENGTH)
   crc |= (cqi[1+(CQI_LENGTH>>3)])>>(8-(CQI_LENGTH&0x7));
   // clear crc bits
   //(((char *)cqi)[1+(CQI_LENGTH>>3)]) = 0;
-
   //  printf("crc : %x\n",crc);
   return(crc);
-
 }
 
 
 
 
-int ulsch_decoding_data_2thread0(td_params* tdp) {
-
+int ulsch_decoding_data_2thread0(td_params *tdp) {
   PHY_VARS_eNB *eNB = tdp->eNB;
   int UE_id         = tdp->UE_id;
   int harq_pid      = tdp->harq_pid;
   int llr8_flag     = tdp->llr8_flag;
-
   unsigned int r,r_offset=0,Kr,Kr_bytes;
   uint8_t crc_type;
   int offset = 0;
@@ -247,11 +236,8 @@ int ulsch_decoding_data_2thread0(td_params* tdp) {
   else
     tc = decoder8;
 
-
-
   // go through first half of segments to get r_offset
   for (r=0; r<(ulsch_harq->C/2); r++) {
-
     // Get Turbo interleaver parameters
     if (r<ulsch_harq->Cminus)
       Kr = ulsch_harq->Kminus;
@@ -259,17 +245,15 @@ int ulsch_decoding_data_2thread0(td_params* tdp) {
       Kr = ulsch_harq->Kplus;
 
     Kr_bytes = Kr>>3;
-
     // This is stolen from rate-matching algorithm to get the value of E
-    
     Gp = G/Nl/Q_m;
     GpmodC = Gp%C;
-    
+
     if (r < (C-(GpmodC)))
       E = Nl*Q_m * (Gp/C);
     else
       E = Nl*Q_m * ((GpmodC==0?0:1) + (Gp/C));
-    
+
     r_offset += E;
 
     if (r==0) {
@@ -281,8 +265,6 @@ int ulsch_decoding_data_2thread0(td_params* tdp) {
 
   // go through second half of segments
   for (; r<(ulsch_harq->C); r++) {
-
-
     //    printf("before subblock deinterleaving c[%d] = %p\n",r,ulsch_harq->c[r]);
     // Get Turbo interleaver parameters
     if (r<ulsch_harq->Cminus)
@@ -291,26 +273,23 @@ int ulsch_decoding_data_2thread0(td_params* tdp) {
       Kr = ulsch_harq->Kplus;
 
     Kr_bytes = Kr>>3;
-
     memset(&dummy_w[r][0],0,3*(6144+64)*sizeof(short));
     ulsch_harq->RTC[r] = generate_dummy_w(4+(Kr_bytes*8),
-                                          (uint8_t*)&dummy_w[r][0],
+                                          (uint8_t *)&dummy_w[r][0],
                                           (r==0) ? ulsch_harq->F : 0);
-
 #ifdef DEBUG_ULSCH_DECODING
-    printf("Rate Matching Segment %d (coded bits (G) %d,unpunctured/repeated bits %d, Q_m %d, nb_rb %d, Nl %d)...\n",
-        r, G,
-        Kr*3,
-        Q_m,
-        nb_rb,
-        ulsch_harq->Nl);
+    printf("Rate Matching Segment %u (coded bits (G) %d,unpunctured/repeated bits %u, Q_m %d, nb_rb %d, Nl %d)...\n",
+           r, G,
+           Kr*3,
+           Q_m,
+           nb_rb,
+           ulsch_harq->Nl);
 #endif
 
-
     if (lte_rate_matching_turbo_rx(ulsch_harq->RTC[r],
                                    G,
                                    ulsch_harq->w[r],
-                                   (uint8_t*) &dummy_w[r][0],
+                                   (uint8_t *) &dummy_w[r][0],
                                    ulsch_harq->e+r_offset,
                                    ulsch_harq->C,
                                    NSOFT,
@@ -327,7 +306,6 @@ int ulsch_decoding_data_2thread0(td_params* tdp) {
     }
 
     r_offset += E;
-
     sub_block_deinterleaving_turbo(4+Kr,
                                    &ulsch_harq->d[r][96],
                                    ulsch_harq->w[r]);
@@ -336,44 +314,39 @@ int ulsch_decoding_data_2thread0(td_params* tdp) {
       crc_type = CRC24_A;
     else
       crc_type = CRC24_B;
-    
-   
+
     ret = tc(&ulsch_harq->d[r][96],
              NULL,
-	     ulsch_harq->c[r],
+             ulsch_harq->c[r],
              NULL,
-	     Kr,
-	     ulsch->max_turbo_iterations,//MAX_TURBO_ITERATIONS,
-	     crc_type,
-	     (r==0) ? ulsch_harq->F : 0,
-	     &eNB->ulsch_tc_init_stats,
-	     &eNB->ulsch_tc_alpha_stats,
-	     &eNB->ulsch_tc_beta_stats,
-	     &eNB->ulsch_tc_gamma_stats,
-	     &eNB->ulsch_tc_ext_stats,
-	     &eNB->ulsch_tc_intl1_stats,
-	     &eNB->ulsch_tc_intl2_stats);
-    
+             Kr,
+             ulsch->max_turbo_iterations,//MAX_TURBO_ITERATIONS,
+             crc_type,
+             (r==0) ? ulsch_harq->F : 0,
+             &eNB->ulsch_tc_init_stats,
+             &eNB->ulsch_tc_alpha_stats,
+             &eNB->ulsch_tc_beta_stats,
+             &eNB->ulsch_tc_gamma_stats,
+             &eNB->ulsch_tc_ext_stats,
+             &eNB->ulsch_tc_intl1_stats,
+             &eNB->ulsch_tc_intl2_stats);
+
     // Reassembly of Transport block here
 
     if (ret != (1+ulsch->max_turbo_iterations)) {
       if (r<ulsch_harq->Cminus)
-	Kr = ulsch_harq->Kminus;
+        Kr = ulsch_harq->Kminus;
       else
-	Kr = ulsch_harq->Kplus;
-      
+        Kr = ulsch_harq->Kplus;
+
       Kr_bytes = Kr>>3;
-      
       memcpy(ulsch_harq->b+offset,
-	     ulsch_harq->c[r],
-	     Kr_bytes - ((ulsch_harq->C>1)?3:0));
+             ulsch_harq->c[r],
+             Kr_bytes - ((ulsch_harq->C>1)?3:0));
       offset += (Kr_bytes- ((ulsch_harq->C>1)?3:0));
-      
-      
     } else {
       break;
     }
-    
   }
 
   return(ret);
@@ -381,22 +354,21 @@ int ulsch_decoding_data_2thread0(td_params* tdp) {
 
 extern int oai_exit;
 void *td_thread(void *param) {
-  PHY_VARS_eNB *eNB = ((td_params*)param)->eNB;
-  eNB_proc_t *proc  = &eNB->proc;
+  PHY_VARS_eNB *eNB = ((td_params *)param)->eNB;
+  L1_proc_t *proc  = &eNB->proc;
   cpu_set_t cpuset;
   CPU_ZERO(&cpuset);
-  
   thread_top_init("td_thread",1,200000,250000,500000);
   pthread_setname_np( pthread_self(),"td processing");
   LOG_I(PHY,"thread td created id=%ld\n", syscall(__NR_gettid));
   //wait_sync("td_thread");
 
   while (!oai_exit) {
+    if (wait_on_condition(&proc->mutex_td,&proc->cond_td,&proc->instance_cnt_td,"td thread")<0) break;
 
-    if (wait_on_condition(&proc->mutex_td,&proc->cond_td,&proc->instance_cnt_td,"td thread")<0) break;  
     if(oai_exit) break;
 
-    ((td_params*)param)->ret = ulsch_decoding_data_2thread0((td_params*)param);
+    ((td_params *)param)->ret = ulsch_decoding_data_2thread0((td_params *)param);
 
     if (release_thread(&proc->mutex_td,&proc->instance_cnt_td,"td thread")<0) break;
 
@@ -411,8 +383,7 @@ void *td_thread(void *param) {
 }
 
 int ulsch_decoding_data_2thread(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr8_flag) {
-
-  eNB_proc_t *proc = &eNB->proc;
+  L1_proc_t *proc = &eNB->proc;
   unsigned int r,r_offset=0,Kr,Kr_bytes;
   uint8_t crc_type;
   int offset = 0;
@@ -420,18 +391,14 @@ int ulsch_decoding_data_2thread(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr
   int16_t dummy_w[MAX_NUM_ULSCH_SEGMENTS][3*(6144+64)];
   LTE_eNB_ULSCH_t *ulsch = eNB->ulsch[UE_id];
   LTE_UL_eNB_HARQ_t *ulsch_harq = ulsch->harq_processes[harq_pid];
-
   int G = ulsch_harq->G;
   unsigned int E;
   int Cby2;
   decoder_if_t *tc;
-
   struct timespec wait;
-
   wait.tv_sec=0;
   wait.tv_nsec=5000000L;
 
-
   if (llr8_flag == 0)
     tc = decoder16;
   else
@@ -443,23 +410,21 @@ int ulsch_decoding_data_2thread(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr
       exit_fun( "error locking mutex_fep" );
       return -1;
     }
-    
+
     if (proc->instance_cnt_td==0) {
       printf("[eNB] TD thread busy\n");
       exit_fun("TD thread busy");
       pthread_mutex_unlock( &proc->mutex_td );
       return -1;
     }
-    
+
     ++proc->instance_cnt_td;
-    
     proc->tdp.eNB       = eNB;
     proc->tdp.UE_id     = UE_id;
     proc->tdp.harq_pid  = harq_pid;
     proc->tdp.llr8_flag = llr8_flag;
-    
-    
-    // wakeup worker to do second half segments 
+
+    // wakeup worker to do second half segments
     if (pthread_cond_signal(&proc->cond_td) != 0) {
       printf("[eNB] ERROR pthread_cond_signal for td thread exit\n");
       exit_fun( "ERROR pthread_cond_signal" );
@@ -468,14 +433,12 @@ int ulsch_decoding_data_2thread(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr
 
     pthread_mutex_unlock( &proc->mutex_td );
     Cby2 = ulsch_harq->C/2;
-  }
-  else {
+  } else {
     Cby2 = 1;
   }
 
   // go through first half of segments in main thread
   for (r=0; r<Cby2; r++) {
-
     //    printf("before subblock deinterleaving c[%d] = %p\n",r,ulsch_harq->c[r]);
     // Get Turbo interleaver parameters
     if (r<ulsch_harq->Cminus)
@@ -484,27 +447,24 @@ int ulsch_decoding_data_2thread(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr
       Kr = ulsch_harq->Kplus;
 
     Kr_bytes = Kr>>3;
-
     memset(&dummy_w[r][0],0,3*(6144+64)*sizeof(short));
     ulsch_harq->RTC[r] = generate_dummy_w(4+(Kr_bytes*8),
-                                          (uint8_t*)&dummy_w[r][0],
+                                          (uint8_t *)&dummy_w[r][0],
                                           (r==0) ? ulsch_harq->F : 0);
-
 #ifdef DEBUG_ULSCH_DECODING
-    printf("Rate Matching Segment %d (coded bits (G) %d,unpunctured/repeated bits %d, Q_m %d, nb_rb %d, Nl %d)...\n",
-        r, G,
-        Kr*3,
-        Q_m,
-        nb_rb,
-        ulsch_harq->Nl);
+    printf("Rate Matching Segment %u (coded bits (G) %d,unpunctured/repeated bits %u, Q_m %d, nb_rb %d, Nl %d)...\n",
+           r, G,
+           Kr*3,
+           Q_m,
+           nb_rb,
+           ulsch_harq->Nl);
 #endif
-
     start_meas(&eNB->ulsch_rate_unmatching_stats);
 
     if (lte_rate_matching_turbo_rx(ulsch_harq->RTC[r],
                                    G,
                                    ulsch_harq->w[r],
-                                   (uint8_t*) &dummy_w[r][0],
+                                   (uint8_t *) &dummy_w[r][0],
                                    ulsch_harq->e+r_offset,
                                    ulsch_harq->C,
                                    NSOFT,
@@ -522,7 +482,6 @@ int ulsch_decoding_data_2thread(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr
 
     stop_meas(&eNB->ulsch_rate_unmatching_stats);
     r_offset += E;
-
     start_meas(&eNB->ulsch_deinterleaving_stats);
     sub_block_deinterleaving_turbo(4+Kr,
                                    &ulsch_harq->d[r][96],
@@ -535,61 +494,57 @@ int ulsch_decoding_data_2thread(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr
       crc_type = CRC24_B;
 
     start_meas(&eNB->ulsch_turbo_decoding_stats);
-    
     ret = tc(&ulsch_harq->d[r][96],
              NULL,
-	     ulsch_harq->c[r],
+             ulsch_harq->c[r],
              NULL,
-	     Kr,
-	     ulsch->max_turbo_iterations,//MAX_TURBO_ITERATIONS,
-	     crc_type,
-	     (r==0) ? ulsch_harq->F : 0,
-	     &eNB->ulsch_tc_init_stats,
-	     &eNB->ulsch_tc_alpha_stats,
-	     &eNB->ulsch_tc_beta_stats,
-	     &eNB->ulsch_tc_gamma_stats,
-	     &eNB->ulsch_tc_ext_stats,
-	     &eNB->ulsch_tc_intl1_stats,
-	     &eNB->ulsch_tc_intl2_stats);
-
-  // Reassembly of Transport block here
+             Kr,
+             ulsch->max_turbo_iterations,//MAX_TURBO_ITERATIONS,
+             crc_type,
+             (r==0) ? ulsch_harq->F : 0,
+             &eNB->ulsch_tc_init_stats,
+             &eNB->ulsch_tc_alpha_stats,
+             &eNB->ulsch_tc_beta_stats,
+             &eNB->ulsch_tc_gamma_stats,
+             &eNB->ulsch_tc_ext_stats,
+             &eNB->ulsch_tc_intl1_stats,
+             &eNB->ulsch_tc_intl2_stats);
+
+    // Reassembly of Transport block here
 
     if (ret != (1+ulsch->max_turbo_iterations)) {
       if (r<ulsch_harq->Cminus)
-	Kr = ulsch_harq->Kminus;
+        Kr = ulsch_harq->Kminus;
       else
-	Kr = ulsch_harq->Kplus;
-      
+        Kr = ulsch_harq->Kplus;
+
       Kr_bytes = Kr>>3;
-      
+
       if (r==0) {
-	memcpy(ulsch_harq->b,
-	       &ulsch_harq->c[0][(ulsch_harq->F>>3)],
-	       Kr_bytes - (ulsch_harq->F>>3) - ((ulsch_harq->C>1)?3:0));
-	offset = Kr_bytes - (ulsch_harq->F>>3) - ((ulsch_harq->C>1)?3:0);
+        memcpy(ulsch_harq->b,
+               &ulsch_harq->c[0][(ulsch_harq->F>>3)],
+               Kr_bytes - (ulsch_harq->F>>3) - ((ulsch_harq->C>1)?3:0));
+        offset = Kr_bytes - (ulsch_harq->F>>3) - ((ulsch_harq->C>1)?3:0);
       } else {
-	memcpy(ulsch_harq->b+offset,
-	       ulsch_harq->c[r],
-	       Kr_bytes - ((ulsch_harq->C>1)?3:0));
-	offset += (Kr_bytes- ((ulsch_harq->C>1)?3:0));
+        memcpy(ulsch_harq->b+offset,
+               ulsch_harq->c[r],
+               Kr_bytes - ((ulsch_harq->C>1)?3:0));
+        offset += (Kr_bytes- ((ulsch_harq->C>1)?3:0));
       }
-      
     } else {
       break;
     }
-    stop_meas(&eNB->ulsch_turbo_decoding_stats);    
-  //printf("/////////////////////////////////////////**************************loop for %d time in ulsch_decoding main\n",r);
-  }
-
-   // wait for worker to finish
 
-  wait_on_busy_condition(&proc->mutex_td,&proc->cond_td,&proc->instance_cnt_td,"td thread");  
+    stop_meas(&eNB->ulsch_turbo_decoding_stats);
+    //printf("/////////////////////////////////////////**************************loop for %d time in ulsch_decoding main\n",r);
+  }
 
+  // wait for worker to finish
+  wait_on_busy_condition(&proc->mutex_td,&proc->cond_td,&proc->instance_cnt_td,"td thread");
   return( (ret>proc->tdp.ret) ? ret : proc->tdp.ret );
 }
 
 int ulsch_decoding_data(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr8_flag) {
-
   unsigned int r,r_offset=0,Kr,Kr_bytes;
   uint8_t crc_type;
   int offset = 0;
@@ -597,7 +552,6 @@ int ulsch_decoding_data(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr8_flag)
   int16_t dummy_w[MAX_NUM_ULSCH_SEGMENTS][3*(6144+64)];
   LTE_eNB_ULSCH_t *ulsch = eNB->ulsch[UE_id];
   LTE_UL_eNB_HARQ_t *ulsch_harq = ulsch->harq_processes[harq_pid];
-
   int G = ulsch_harq->G;
   unsigned int E;
   decoder_if_t *tc;
@@ -607,9 +561,7 @@ int ulsch_decoding_data(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr8_flag)
   else
     tc = *decoder8;
 
-
   for (r=0; r<ulsch_harq->C; r++) {
-
     //    printf("before subblock deinterleaving c[%d] = %p\n",r,ulsch_harq->c[r]);
     // Get Turbo interleaver parameters
     if (r<ulsch_harq->Cminus)
@@ -618,27 +570,24 @@ int ulsch_decoding_data(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr8_flag)
       Kr = ulsch_harq->Kplus;
 
     Kr_bytes = Kr>>3;
-
     memset(&dummy_w[r][0],0,3*(6144+64)*sizeof(short));
     ulsch_harq->RTC[r] = generate_dummy_w(4+(Kr_bytes*8),
-                                          (uint8_t*)&dummy_w[r][0],
+                                          (uint8_t *)&dummy_w[r][0],
                                           (r==0) ? ulsch_harq->F : 0);
-
 #ifdef DEBUG_ULSCH_DECODING
-    printf("Rate Matching Segment %d (coded bits (G) %d,unpunctured/repeated bits %d, Q_m %d, nb_rb %d, Nl %d)...\n",
-        r, G,
-        Kr*3,
-        Q_m,
-        nb_rb,
-        ulsch_harq->Nl);
+    printf("Rate Matching Segment %u (coded bits (G) %d,unpunctured/repeated bits %u, Q_m %d, nb_rb %d, Nl %d)...\n",
+           r, G,
+           Kr*3,
+           Q_m,
+           nb_rb,
+           ulsch_harq->Nl);
 #endif
-
     start_meas(&eNB->ulsch_rate_unmatching_stats);
 
     if (lte_rate_matching_turbo_rx(ulsch_harq->RTC[r],
                                    G,
                                    ulsch_harq->w[r],
-                                   (uint8_t*) &dummy_w[r][0],
+                                   (uint8_t *) &dummy_w[r][0],
                                    ulsch_harq->e+r_offset,
                                    ulsch_harq->C,
                                    NSOFT,
@@ -656,7 +605,6 @@ int ulsch_decoding_data(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr8_flag)
 
     stop_meas(&eNB->ulsch_rate_unmatching_stats);
     r_offset += E;
-
     start_meas(&eNB->ulsch_deinterleaving_stats);
     sub_block_deinterleaving_turbo(4+Kr,
                                    &ulsch_harq->d[r][96],
@@ -667,61 +615,55 @@ int ulsch_decoding_data(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr8_flag)
       crc_type = CRC24_A;
     else
       crc_type = CRC24_B;
-  
- 
+
     start_meas(&eNB->ulsch_turbo_decoding_stats);
-    
     ret = tc(&ulsch_harq->d[r][96],
              NULL,
-	     ulsch_harq->c[r],
+             ulsch_harq->c[r],
              NULL,
-	     Kr,
-	     ulsch->max_turbo_iterations,//MAX_TURBO_ITERATIONS,
-	     crc_type,
-	     (r==0) ? ulsch_harq->F : 0,
-	     &eNB->ulsch_tc_init_stats,
-	     &eNB->ulsch_tc_alpha_stats,
-	     &eNB->ulsch_tc_beta_stats,
-	     &eNB->ulsch_tc_gamma_stats,
-	     &eNB->ulsch_tc_ext_stats,
-	     &eNB->ulsch_tc_intl1_stats,
-	     &eNB->ulsch_tc_intl2_stats);
-    
+             Kr,
+             ulsch->max_turbo_iterations,//MAX_TURBO_ITERATIONS,
+             crc_type,
+             (r==0) ? ulsch_harq->F : 0,
+             &eNB->ulsch_tc_init_stats,
+             &eNB->ulsch_tc_alpha_stats,
+             &eNB->ulsch_tc_beta_stats,
+             &eNB->ulsch_tc_gamma_stats,
+             &eNB->ulsch_tc_ext_stats,
+             &eNB->ulsch_tc_intl1_stats,
+             &eNB->ulsch_tc_intl2_stats);
     stop_meas(&eNB->ulsch_turbo_decoding_stats);
-    
-  // Reassembly of Transport block here
+
+    // Reassembly of Transport block here
 
     if (ret != (1+ulsch->max_turbo_iterations)) {
       if (r<ulsch_harq->Cminus)
-	Kr = ulsch_harq->Kminus;
+        Kr = ulsch_harq->Kminus;
       else
-	Kr = ulsch_harq->Kplus;
-      
+        Kr = ulsch_harq->Kplus;
+
       Kr_bytes = Kr>>3;
-      
+
       if (r==0) {
-	memcpy(ulsch_harq->b,
-	       &ulsch_harq->c[0][(ulsch_harq->F>>3)],
-	       Kr_bytes - (ulsch_harq->F>>3) - ((ulsch_harq->C>1)?3:0));
-	offset = Kr_bytes - (ulsch_harq->F>>3) - ((ulsch_harq->C>1)?3:0);
+        memcpy(ulsch_harq->b,
+               &ulsch_harq->c[0][(ulsch_harq->F>>3)],
+               Kr_bytes - (ulsch_harq->F>>3) - ((ulsch_harq->C>1)?3:0));
+        offset = Kr_bytes - (ulsch_harq->F>>3) - ((ulsch_harq->C>1)?3:0);
       } else {
-	memcpy(ulsch_harq->b+offset,
-	       ulsch_harq->c[r],
-	       Kr_bytes - ((ulsch_harq->C>1)?3:0));
-	offset += (Kr_bytes- ((ulsch_harq->C>1)?3:0));
+        memcpy(ulsch_harq->b+offset,
+               ulsch_harq->c[r],
+               Kr_bytes - ((ulsch_harq->C>1)?3:0));
+        offset += (Kr_bytes- ((ulsch_harq->C>1)?3:0));
       }
-      
     } else {
       break;
     }
-    
   }
 
   return(ret);
 }
 
-int ulsch_decoding_data_all(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr8_flag) 
-{
+int ulsch_decoding_data_all(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr8_flag) {
   int ret = 0;
   /*if(get_thread_worker_conf() == WORKER_ENABLE)
   {
@@ -735,8 +677,7 @@ int ulsch_decoding_data_all(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr8_fl
 }
 
 static inline unsigned int lte_gold_unscram(unsigned int *x1, unsigned int *x2, unsigned char reset) __attribute__((always_inline));
-static inline unsigned int lte_gold_unscram(unsigned int *x1, unsigned int *x2, unsigned char reset)
-{
+static inline unsigned int lte_gold_unscram(unsigned int *x1, unsigned int *x2, unsigned char reset) {
   int n;
 
   if (reset) {
@@ -759,17 +700,13 @@ static inline unsigned int lte_gold_unscram(unsigned int *x1, unsigned int *x2,
   *x2 = *x2 ^ (*x2<<31) ^ (*x2<<30) ^ (*x2<<29) ^ (*x2<<28);
   return(*x1^*x2);
   //  printf("n=%d : c %x\n",n,x1^x2);
-
 }
-  
-unsigned int  ulsch_decoding(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
+
+unsigned int  ulsch_decoding(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc,
                              uint8_t UE_id,
                              uint8_t control_only_flag,
                              uint8_t Nbundled,
-                             uint8_t llr8_flag)
-{
-
-
+                             uint8_t llr8_flag) {
   int16_t *ulsch_llr = eNB->pusch_vars[UE_id]->llr;
   LTE_DL_FRAME_PARMS *frame_parms = &eNB->frame_parms;
   LTE_eNB_ULSCH_t *ulsch = eNB->ulsch[UE_id];
@@ -780,10 +717,8 @@ unsigned int  ulsch_decoding(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
   unsigned int i,i2,q,j,j2;
   int iprime;
   unsigned int ret=0;
-
   //  uint8_t dummy_channel_output[(3*8*block_length)+12];
   int r,Kr;
-
   uint8_t *columnset;
   unsigned int sumKr=0;
   unsigned int Qprime,L,G,Q_CQI,Q_RI,H,Hprime,Hpp,Cmux,Rmux_prime,O_RCC;
@@ -799,70 +734,62 @@ unsigned int  ulsch_decoding(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
   //  uint8_t ytag2[6*14*1200],*ytag2_ptr;
   int16_t cseq[6*14*1200] __attribute__((aligned(32)));
   int off;
-
   int frame = proc->frame_rx;
   int subframe = proc->subframe_rx;
   LTE_UL_eNB_HARQ_t *ulsch_harq;
 
-
-
-  harq_pid = subframe2harq_pid(frame_parms,frame,subframe);
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  if (ulsch->ue_type>0)     harq_pid = 0;
+  else
+#endif
+    {
+      harq_pid = subframe2harq_pid(frame_parms,proc->frame_rx,subframe);
+    }
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_ULSCH_DECODING0+harq_pid,1);
 
   // x1 is set in lte_gold_generic
   x2 = ((uint32_t)ulsch->rnti<<14) + ((uint32_t)subframe<<9) + frame_parms->Nid_cell; //this is c_init in 36.211 Sec 6.3.1
   ulsch_harq = ulsch->harq_processes[harq_pid];
-
   AssertFatal(harq_pid!=255,
               "FATAL ERROR: illegal harq_pid, returning\n");
-
   AssertFatal(ulsch_harq->Nsymb_pusch != 0,
               "FATAL ERROR: harq_pid %d, Nsymb 0!\n",harq_pid);
-
-
   nb_rb = ulsch_harq->nb_rb;
-
   A = ulsch_harq->TBS;
-
-
   Q_m = ulsch_harq->Qm;
   G = nb_rb * (12 * Q_m) * ulsch_harq->Nsymb_pusch;
-
-
   //#ifdef DEBUG_ULSCH_DECODING
   LOG_D(PHY,"[PUSCH %d] Frame %d, Subframe %d: ulsch_decoding (Nid_cell %d, rnti %x, x2 %x): A %d, round %d, RV %d, O_r1 %d, O_RI %d, O_ACK %d, G %d, Q_m %d Nsymb_pusch %d nb_rb %d\n",
-      harq_pid,
-	proc->frame_rx,subframe,
-	frame_parms->Nid_cell,ulsch->rnti,x2,
-	A,
-	ulsch_harq->round,
-	ulsch_harq->rvidx,
-	ulsch_harq->Or1,
-	ulsch_harq->O_RI,
-	ulsch_harq->O_ACK,
-	G,
+        harq_pid,
+        proc->frame_rx,subframe,
+        frame_parms->Nid_cell,ulsch->rnti,x2,
+        A,
+        ulsch_harq->round,
+        ulsch_harq->rvidx,
+        ulsch_harq->Or1,
+        ulsch_harq->O_RI,
+        ulsch_harq->O_ACK,
+        G,
         ulsch_harq->Qm,
         ulsch_harq->Nsymb_pusch,
         nb_rb);
-	
   //#endif
   //if (ulsch_harq->round == 0) { // delete for RB shortage pattern
-    // This is a new packet, so compute quantities regarding segmentation
-    ulsch_harq->B = A+24;
-    lte_segmentation(NULL,
-                     NULL,
-                     ulsch_harq->B,
-                     &ulsch_harq->C,
-                     &ulsch_harq->Cplus,
-                     &ulsch_harq->Cminus,
-                     &ulsch_harq->Kplus,
-                     &ulsch_harq->Kminus,
-                     &ulsch_harq->F);
-    //  CLEAR LLR's HERE for first packet in process
+  // This is a new packet, so compute quantities regarding segmentation
+  ulsch_harq->B = A+24;
+  lte_segmentation(NULL,
+                   NULL,
+                   ulsch_harq->B,
+                   &ulsch_harq->C,
+                   &ulsch_harq->Cplus,
+                   &ulsch_harq->Cminus,
+                   &ulsch_harq->Kplus,
+                   &ulsch_harq->Kminus,
+                   &ulsch_harq->F);
+  //  CLEAR LLR's HERE for first packet in process
   //}
   //  printf("after segmentation c[%d] = %p\n",0,ulsch_harq->c[0]);
-
   sumKr = 0;
 
   for (r=0; r<ulsch_harq->C; r++) {
@@ -875,17 +802,15 @@ unsigned int  ulsch_decoding(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
   }
 
   AssertFatal(sumKr>0,
-	      "[eNB] ulsch_decoding.c: FATAL sumKr is 0! (Nid_cell %d, rnti %x, x2 %x): harq_pid %d round %d, RV %d, O_RI %d, O_ACK %d, G %d, subframe %d\n",
-	      frame_parms->Nid_cell,ulsch->rnti,x2,
-	      harq_pid,
-	      ulsch_harq->round,
-	      ulsch_harq->rvidx,
-	      ulsch_harq->O_RI,
-	      ulsch_harq->O_ACK,
-	      G,
-	      subframe);
-
-
+              "[eNB] ulsch_decoding.c: FATAL sumKr is 0! (Nid_cell %d, rnti %x, x2 %x): harq_pid %d round %d, RV %d, O_RI %d, O_ACK %d, G %d, subframe %d\n",
+              frame_parms->Nid_cell,ulsch->rnti,x2,
+              harq_pid,
+              ulsch_harq->round,
+              ulsch_harq->rvidx,
+              ulsch_harq->O_RI,
+              ulsch_harq->O_ACK,
+              G,
+              subframe);
   // Compute Q_ri
   Qprime = ulsch_harq->O_RI*ulsch_harq->Msc_initial*ulsch_harq->Nsymb_initial * ulsch->beta_offset_ri_times8;
 
@@ -901,10 +826,7 @@ unsigned int  ulsch_decoding(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
 
   Q_RI = Q_m*Qprime;
   Qprime_RI = Qprime;
-
-
   // Compute Q_ack
-
   Qprime = ulsch_harq->O_ACK*ulsch_harq->Msc_initial*ulsch_harq->Nsymb_initial * ulsch->beta_offset_harqack_times8;
 
   if (Qprime > 0) {
@@ -920,8 +842,8 @@ unsigned int  ulsch_decoding(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
   //  Q_ACK = Qprime * Q_m;
   Qprime_ACK = Qprime;
 #ifdef DEBUG_ULSCH_DECODING
-  printf("ulsch_decoding.c: Qprime_ACK %d, Msc_initial %d, Nsymb_initial %d, sumKr %d\n",
-      Qprime_ACK,ulsch_harq->Msc_initial,ulsch_harq->Nsymb_initial,sumKr);
+  printf("ulsch_decoding.c: Qprime_ACK %u, Msc_initial %d, Nsymb_initial %d, sumKr %u\n",
+         Qprime_ACK,ulsch_harq->Msc_initial,ulsch_harq->Nsymb_initial,sumKr);
 #endif
 
   // Compute Q_cqi
@@ -944,43 +866,27 @@ unsigned int  ulsch_decoding(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
   }
 
   G = nb_rb * (12 * Q_m) * (ulsch_harq->Nsymb_pusch);
-
-
-
   Q_CQI = Q_m * Qprime;
 #ifdef DEBUG_ULSCH_DECODING
-  printf("ulsch_decoding: G %d, Q_RI %d, Q_CQI %d (L %d, Or1 %d) O_ACK %d\n",G,Q_RI,Q_CQI,L,ulsch_harq->Or1,ulsch_harq->O_ACK);
+  printf("ulsch_decoding: G %u, Q_RI %u, Q_CQI %u (L %u, Or1 %d) O_ACK %d\n",G,Q_RI,Q_CQI,L,ulsch_harq->Or1,ulsch_harq->O_ACK);
 #endif
-
   G = G - Q_RI - Q_CQI;
   ulsch_harq->G = G;
-
   AssertFatal((int)G > 0,
               "FATAL: ulsch_decoding.c G < 0 (%d) : Q_RI %d, Q_CQI %d\n",G,Q_RI,Q_CQI);
-
   H = G + Q_CQI;
   Hprime = H/Q_m;
-
-
   // Demultiplexing/Deinterleaving of PUSCH/ACK/RI/CQI
   start_meas(&eNB->ulsch_demultiplexing_stats);
   Hpp = Hprime + Qprime_RI;
-
   Cmux       = ulsch_harq->Nsymb_pusch;
   Rmux_prime = Hpp/Cmux;
-
   // Clear "tag" interleaving matrix to allow for CQI/DATA identification
   memset(ytag,0,Cmux*Rmux_prime);
-
-
-
   i=0;
   memset(y,LTE_NULL,Q_m*Hpp);
-
   // read in buffer and unscramble llrs for everything but placeholder bits
   // llrs stored per symbol correspond to columns of interleaving matrix
-
-
   s = lte_gold_unscram(&x1, &x2, 1);
   i2=0;
 
@@ -992,26 +898,25 @@ unsigned int  ulsch_decoding(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
     */
 #if defined(__x86_64__) || defined(__i386__)
 #ifndef __AVX2__
-    ((__m128i*)cseq)[i2++] = ((__m128i*)unscrambling_lut)[(s&65535)<<1];
-    ((__m128i*)cseq)[i2++] = ((__m128i*)unscrambling_lut)[1+((s&65535)<<1)];
+    ((__m128i *)cseq)[i2++] = ((__m128i *)unscrambling_lut)[(s&65535)<<1];
+    ((__m128i *)cseq)[i2++] = ((__m128i *)unscrambling_lut)[1+((s&65535)<<1)];
     s>>=16;
-    ((__m128i*)cseq)[i2++] = ((__m128i*)unscrambling_lut)[(s&65535)<<1];
-    ((__m128i*)cseq)[i2++] = ((__m128i*)unscrambling_lut)[1+((s&65535)<<1)];
+    ((__m128i *)cseq)[i2++] = ((__m128i *)unscrambling_lut)[(s&65535)<<1];
+    ((__m128i *)cseq)[i2++] = ((__m128i *)unscrambling_lut)[1+((s&65535)<<1)];
 #else
-    ((__m256i*)cseq)[i2++] = ((__m256i*)unscrambling_lut)[s&65535];
-    ((__m256i*)cseq)[i2++] = ((__m256i*)unscrambling_lut)[(s>>16)&65535];
+    ((__m256i *)cseq)[i2++] = ((__m256i *)unscrambling_lut)[s&65535];
+    ((__m256i *)cseq)[i2++] = ((__m256i *)unscrambling_lut)[(s>>16)&65535];
 #endif
 #elif defined(__arm__)
-    ((int16x8_t*)cseq)[i2++] = ((int16x8_t*)unscrambling_lut)[(s&65535)<<1];
-    ((int16x8_t*)cseq)[i2++] = ((int16x8_t*)unscrambling_lut)[1+((s&65535)<<1)];
+    ((int16x8_t *)cseq)[i2++] = ((int16x8_t *)unscrambling_lut)[(s&65535)<<1];
+    ((int16x8_t *)cseq)[i2++] = ((int16x8_t *)unscrambling_lut)[1+((s&65535)<<1)];
     s>>=16;
-    ((int16x8_t*)cseq)[i2++] = ((int16x8_t*)unscrambling_lut)[(s&65535)<<1];
-    ((int16x8_t*)cseq)[i2++] = ((int16x8_t*)unscrambling_lut)[1+((s&65535)<<1)];
+    ((int16x8_t *)cseq)[i2++] = ((int16x8_t *)unscrambling_lut)[(s&65535)<<1];
+    ((int16x8_t *)cseq)[i2++] = ((int16x8_t *)unscrambling_lut)[1+((s&65535)<<1)];
 #endif
     s = lte_gold_unscram(&x1, &x2, 0);
   }
 
-
   //  printf("after unscrambling c[%d] = %p\n",0,ulsch_harq->c[0]);
 
   if (frame_parms->Ncp == 0)
@@ -1034,7 +939,6 @@ unsigned int  ulsch_decoding(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
       cseq[off+q] = -1;    // PUSCH_x
 
     j=(j+3)&3;
-
   }
 
   //  printf("after RI c[%d] = %p\n",0,ulsch_harq->c[0]);
@@ -1063,87 +967,82 @@ unsigned int  ulsch_decoding(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
     }
 
 #ifdef DEBUG_ULSCH_DECODING
-    printf("ulsch_decoding.c: ACK i %d, r %d, j %d, ColumnSet[j] %d\n",i,r,j,columnset[j]);
+    printf("ulsch_decoding.c: ACK i %u, r %d, j %u, ColumnSet[j] %d\n",i,r,j,columnset[j]);
 #endif
     j=(j+3)&3;
   }
 
-
-
   i=0;
 
   switch (Q_m) {
-  case 2:
-    for (j=0; j<Cmux; j++) {
-      i2=j<<1;
-
-      for (r=0; r<Rmux_prime; r++) {
-        c = cseq[i];
-        //  printf("ulsch %d: %d * ",i,c);
-        y[i2++] = c*ulsch_llr[i++];
-        //  printf("%d\n",ulsch_llr[i-1]);
-        c = cseq[i];
-        //  printf("ulsch %d: %d * ",i,c);
-        y[i2] = c*ulsch_llr[i++];
-        //  printf("%d\n",ulsch_llr[i-1]);
-        i2=(i2+(Cmux<<1)-1);
+    case 2:
+      for (j=0; j<Cmux; j++) {
+        i2=j<<1;
+
+        for (r=0; r<Rmux_prime; r++) {
+          c = cseq[i];
+          //  printf("ulsch %d: %d * ",i,c);
+          y[i2++] = c*ulsch_llr[i++];
+          //  printf("%d\n",ulsch_llr[i-1]);
+          c = cseq[i];
+          //  printf("ulsch %d: %d * ",i,c);
+          y[i2] = c*ulsch_llr[i++];
+          //  printf("%d\n",ulsch_llr[i-1]);
+          i2=(i2+(Cmux<<1)-1);
+        }
       }
-    }
-
-    break;
-
-  case 4:
-    for (j=0; j<Cmux; j++) {
-      i2=j<<2;
-
-      for (r=0; r<Rmux_prime; r++) {
-	/*
-        c = cseq[i];
-        y[i2++] = c*ulsch_llr[i++];
-        c = cseq[i];
-        y[i2++] = c*ulsch_llr[i++];
-        c = cseq[i];
-        y[i2++] = c*ulsch_llr[i++];
-        c = cseq[i];
-        y[i2] = c*ulsch_llr[i++];
-        i2=(i2+(Cmux<<2)-3);
-	*/
-	// slightly more optimized version (equivalent to above) for 16QAM to improve computational performance
-	*(__m64 *)&y[i2] = _mm_sign_pi16(*(__m64*)&ulsch_llr[i],*(__m64*)&cseq[i]);i+=4;i2+=(Cmux<<2);
 
+      break;
 
+    case 4:
+      for (j=0; j<Cmux; j++) {
+        i2=j<<2;
+
+        for (r=0; r<Rmux_prime; r++) {
+          /*
+                c = cseq[i];
+                y[i2++] = c*ulsch_llr[i++];
+                c = cseq[i];
+                y[i2++] = c*ulsch_llr[i++];
+                c = cseq[i];
+                y[i2++] = c*ulsch_llr[i++];
+                c = cseq[i];
+                y[i2] = c*ulsch_llr[i++];
+                i2=(i2+(Cmux<<2)-3);
+          */
+          // slightly more optimized version (equivalent to above) for 16QAM to improve computational performance
+          *(__m64 *)&y[i2] = _mm_sign_pi16(*(__m64 *)&ulsch_llr[i],*(__m64 *)&cseq[i]);
+          i+=4;
+          i2+=(Cmux<<2);
+        }
       }
-    }
 
-    break;
-
-  case 6:
-    for (j=0; j<Cmux; j++) {
-      i2=j*6;
-
-      for (r=0; r<Rmux_prime; r++) {
-        c = cseq[i];
-        y[i2++] = c*ulsch_llr[i++];
-        c = cseq[i];
-        y[i2++] = c*ulsch_llr[i++];
-        c = cseq[i];
-        y[i2++] = c*ulsch_llr[i++];
-        c = cseq[i];
-        y[i2++] = c*ulsch_llr[i++];
-        c = cseq[i];
-        y[i2++] = c*ulsch_llr[i++];
-        c = cseq[i];
-        y[i2] = c*ulsch_llr[i++];
-        i2=(i2+(Cmux*6)-5);
+      break;
+
+    case 6:
+      for (j=0; j<Cmux; j++) {
+        i2=j*6;
+
+        for (r=0; r<Rmux_prime; r++) {
+          c = cseq[i];
+          y[i2++] = c*ulsch_llr[i++];
+          c = cseq[i];
+          y[i2++] = c*ulsch_llr[i++];
+          c = cseq[i];
+          y[i2++] = c*ulsch_llr[i++];
+          c = cseq[i];
+          y[i2++] = c*ulsch_llr[i++];
+          c = cseq[i];
+          y[i2++] = c*ulsch_llr[i++];
+          c = cseq[i];
+          y[i2] = c*ulsch_llr[i++];
+          i2=(i2+(Cmux*6)-5);
+        }
       }
-    }
 
-    break;
+      break;
   }
 
-
-
-
   if (i!=(H+Q_RI))
     LOG_D(PHY,"ulsch_decoding.c: Error in input buffer length (j %d, H+Q_RI %d)\n",i,H+Q_RI);
 
@@ -1158,33 +1057,33 @@ unsigned int  ulsch_decoding(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
 
   if (ulsch_harq->O_ACK == 1) {
     switch (Q_m) {
-    case 2:
-      len_ACK = 2;
-      break;
+      case 2:
+        len_ACK = 2;
+        break;
 
-    case 4:
-      len_ACK = 4;
-      break;
+      case 4:
+        len_ACK = 4;
+        break;
 
-    case 6:
-      len_ACK = 6;
-      break;
+      case 6:
+        len_ACK = 6;
+        break;
     }
   }
 
   if (ulsch_harq->O_ACK == 2) {
     switch (Q_m) {
-    case 2:
-      len_ACK = 6;
-      break;
+      case 2:
+        len_ACK = 6;
+        break;
 
-    case 4:
-      len_ACK = 12;
-      break;
+      case 4:
+        len_ACK = 12;
+        break;
 
-    case 6:
-      len_ACK = 18;
-      break;
+      case 6:
+        len_ACK = 18;
+        break;
     }
   }
 
@@ -1196,13 +1095,13 @@ unsigned int  ulsch_decoding(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
   for (i=0; i<len_ACK; i++)
     ulsch_harq->q_ACK[i] = 0;
 
-
   for (i=0; i<Qprime_ACK; i++) {
     r = Rmux_prime -1 - (i>>2);
 
     for (q=0; q<Q_m; q++) {
       if (y[q+(Q_m*((r*Cmux) + columnset[j]))]!=0)
         ulsch_harq->q_ACK[(q+(Q_m*i))%len_ACK] += y[q+(Q_m*((r*Cmux) + columnset[j]))];
+
       y[q+(Q_m*((r*Cmux) + columnset[j]))]=0;  // NULL LLRs in ACK positions
     }
 
@@ -1215,17 +1114,17 @@ unsigned int  ulsch_decoding(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
 
   if (ulsch_harq->O_RI == 1) {
     switch (Q_m) {
-    case 2:
-      len_RI=2;
-      break;
+      case 2:
+        len_RI=2;
+        break;
 
-    case 4:
-      len_RI=4;
-      break;
+      case 4:
+        len_RI=4;
+        break;
 
-    case 6:
-      len_RI=6;
-      break;
+      case 6:
+        len_RI=6;
+        break;
     }
   }
 
@@ -1255,7 +1154,6 @@ unsigned int  ulsch_decoding(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
   }
 
   //  printf("after RI2 c[%d] = %p\n",0,ulsch_harq->c[0]);
-
   // CQI and Data bits
   j=0;
   j2=0;
@@ -1263,116 +1161,108 @@ unsigned int  ulsch_decoding(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
   //  r=0;
   if (Q_RI>0) {
     for (i=0; i<(Q_CQI/Q_m); i++) {
-      
       while (ytag[j]==LTE_NULL) {
-	j++;
-	j2+=Q_m;
+        j++;
+        j2+=Q_m;
       }
-      
+
       for (q=0; q<Q_m; q++) {
-	//      ys = y[q+(Q_m*((r*Cmux)+j))];
-	ys = y[q+j2];
-	
-	if (ys>127)
-	  ulsch_harq->q[q+(Q_m*i)] = 127;
-	else if (ys<-128)
-	  ulsch_harq->q[q+(Q_m*i)] = -128;
-	else
-	  ulsch_harq->q[q+(Q_m*i)] = ys;
+        //      ys = y[q+(Q_m*((r*Cmux)+j))];
+        ys = y[q+j2];
+
+        if (ys>127)
+          ulsch_harq->q[q+(Q_m*i)] = 127;
+        else if (ys<-128)
+          ulsch_harq->q[q+(Q_m*i)] = -128;
+        else
+          ulsch_harq->q[q+(Q_m*i)] = ys;
       }
-      
+
       j2+=Q_m;
     }
-    
-        
+
     switch (Q_m) {
-    case 2:
-      for (iprime=0; iprime<G;) {
-	while (ytag[j]==LTE_NULL) {
-	  j++;
-	  j2+=2;
-	}
-	
-	ulsch_harq->e[iprime++] = y[j2++];
-	ulsch_harq->e[iprime++] = y[j2++];
-	
-      }
-      
-      
-      break;
-      
-    case 4:
-      for (iprime=0; iprime<G;) {
-	while (ytag[j]==LTE_NULL) {
-	  j++;
-	  j2+=4;
-	}
-	
-	ulsch_harq->e[iprime++] = y[j2++];
-	ulsch_harq->e[iprime++] = y[j2++];
-	ulsch_harq->e[iprime++] = y[j2++];
-	ulsch_harq->e[iprime++] = y[j2++];
-	
-      }
-      
-      break;
-      
-    case 6:
-      for (iprime=0; iprime<G;) {
-	while (ytag[j]==LTE_NULL) {
-	  j++;
-	  j2+=6;
-	}
-	
-	ulsch_harq->e[iprime++] = y[j2++];
-	ulsch_harq->e[iprime++] = y[j2++];
-	ulsch_harq->e[iprime++] = y[j2++];
-	ulsch_harq->e[iprime++] = y[j2++];
-	ulsch_harq->e[iprime++] = y[j2++];
-	ulsch_harq->e[iprime++] = y[j2++];
-	
-      }
-      
-      break;
+      case 2:
+        for (iprime=0; iprime<G;) {
+          while (ytag[j]==LTE_NULL) {
+            j++;
+            j2+=2;
+          }
 
-    }
-    
+          ulsch_harq->e[iprime++] = y[j2++];
+          ulsch_harq->e[iprime++] = y[j2++];
+        }
+
+        break;
+
+      case 4:
+        for (iprime=0; iprime<G;) {
+          while (ytag[j]==LTE_NULL) {
+            j++;
+            j2+=4;
+          }
+
+          ulsch_harq->e[iprime++] = y[j2++];
+          ulsch_harq->e[iprime++] = y[j2++];
+          ulsch_harq->e[iprime++] = y[j2++];
+          ulsch_harq->e[iprime++] = y[j2++];
+        }
 
+        break;
+
+      case 6:
+        for (iprime=0; iprime<G;) {
+          while (ytag[j]==LTE_NULL) {
+            j++;
+            j2+=6;
+          }
+
+          ulsch_harq->e[iprime++] = y[j2++];
+          ulsch_harq->e[iprime++] = y[j2++];
+          ulsch_harq->e[iprime++] = y[j2++];
+          ulsch_harq->e[iprime++] = y[j2++];
+          ulsch_harq->e[iprime++] = y[j2++];
+          ulsch_harq->e[iprime++] = y[j2++];
+        }
+
+        break;
+    }
   } // Q_RI>0
   else {
-
     for (i=0; i<(Q_CQI/Q_m); i++) {
-      
       for (q=0; q<Q_m; q++) {
-	ys = y[q+j2];
-	if (ys>127)
-	  ulsch_harq->q[q+(Q_m*i)] = 127;
-	else if (ys<-128)
-	  ulsch_harq->q[q+(Q_m*i)] = -128;
-	else
-	  ulsch_harq->q[q+(Q_m*i)] = ys;
+        ys = y[q+j2];
+
+        if (ys>127)
+          ulsch_harq->q[q+(Q_m*i)] = 127;
+        else if (ys<-128)
+          ulsch_harq->q[q+(Q_m*i)] = -128;
+        else
+          ulsch_harq->q[q+(Q_m*i)] = ys;
       }
-      
+
       j2+=Q_m;
     }
+
     /* To be improved according to alignment of j2
-#if defined(__x86_64__)||defined(__i386__)
-#ifndef __AVX2__
+    #if defined(__x86_64__)||defined(__i386__)
+    #ifndef __AVX2__
     for (iprime=0; iprime<G;iprime+=8,j2+=8)
       *((__m128i *)&ulsch_harq->e[iprime]) = *((__m128i *)&y[j2]);
-#else
+    #else
     for (iprime=0; iprime<G;iprime+=16,j2+=16)
       *((__m256i *)&ulsch_harq->e[iprime]) = *((__m256i *)&y[j2]);
-#endif
-#elif defined(__arm__)
+    #endif
+    #elif defined(__arm__)
     for (iprime=0; iprime<G;iprime+=8,j2+=8)
       *((int16x8_t *)&ulsch_harq->e[iprime]) = *((int16x8_t *)&y[j2]);
-#endif
+    #endif
     */
     int16_t *yp,*ep;
-    for (iprime=0,yp=&y[j2],ep=&ulsch_harq->e[0]; 
-	 iprime<G;
-	 iprime+=8,j2+=8,ep+=8,yp+=8) {
+
+    for (iprime=0,yp=&y[j2],ep=&ulsch_harq->e[0];
+         iprime<G;
+         iprime+=8,j2+=8,ep+=8,yp+=8) {
       ep[0] = yp[0];
       ep[1] = yp[1];
       ep[2] = yp[2];
@@ -1383,14 +1273,10 @@ unsigned int  ulsch_decoding(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
       ep[7] = yp[7];
     }
   }
-    
-   
-  stop_meas(&eNB->ulsch_demultiplexing_stats);
 
+  stop_meas(&eNB->ulsch_demultiplexing_stats);
   //  printf("after ACKNAK2 c[%d] = %p (iprime %d, G %d)\n",0,ulsch_harq->c[0],iprime,G);
-
   // Do CQI/RI/HARQ-ACK Decoding first and pass to MAC
-
   // HARQ-ACK
   wACK_idx = (ulsch->bundling==0) ? 4 : ((Nbundled-1)&3);
 
@@ -1406,22 +1292,23 @@ unsigned int  ulsch_decoding(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
 
   if (ulsch_harq->O_ACK == 2) {
     switch (Q_m) {
-
-    case 2:
-      ulsch_harq->q_ACK[0] = ulsch_harq->q_ACK[0]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[3]*wACK_RX[wACK_idx][1];
-      ulsch_harq->q_ACK[1] = ulsch_harq->q_ACK[1]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[4]*wACK_RX[wACK_idx][1];
-      ulsch_harq->q_ACK[2] = ulsch_harq->q_ACK[2]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[5]*wACK_RX[wACK_idx][1];
-      break;
-    case 4:
-      ulsch_harq->q_ACK[0] = ulsch_harq->q_ACK[0]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[5]*wACK_RX[wACK_idx][1];
-      ulsch_harq->q_ACK[1] = ulsch_harq->q_ACK[1]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[8]*wACK_RX[wACK_idx][1];
-      ulsch_harq->q_ACK[2] = ulsch_harq->q_ACK[4]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[9]*wACK_RX[wACK_idx][1];
-      break;
-    case 6:
-      ulsch_harq->q_ACK[0] =  ulsch_harq->q_ACK[0]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[7]*wACK_RX[wACK_idx][1];
-      ulsch_harq->q_ACK[1] =  ulsch_harq->q_ACK[1]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[12]*wACK_RX[wACK_idx][1];
-      ulsch_harq->q_ACK[2] =  ulsch_harq->q_ACK[6]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[13]*wACK_RX[wACK_idx][1];
-      break;
+      case 2:
+        ulsch_harq->q_ACK[0] = ulsch_harq->q_ACK[0]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[3]*wACK_RX[wACK_idx][1];
+        ulsch_harq->q_ACK[1] = ulsch_harq->q_ACK[1]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[4]*wACK_RX[wACK_idx][1];
+        ulsch_harq->q_ACK[2] = ulsch_harq->q_ACK[2]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[5]*wACK_RX[wACK_idx][1];
+        break;
+
+      case 4:
+        ulsch_harq->q_ACK[0] = ulsch_harq->q_ACK[0]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[5]*wACK_RX[wACK_idx][1];
+        ulsch_harq->q_ACK[1] = ulsch_harq->q_ACK[1]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[8]*wACK_RX[wACK_idx][1];
+        ulsch_harq->q_ACK[2] = ulsch_harq->q_ACK[4]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[9]*wACK_RX[wACK_idx][1];
+        break;
+
+      case 6:
+        ulsch_harq->q_ACK[0] =  ulsch_harq->q_ACK[0]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[7]*wACK_RX[wACK_idx][1];
+        ulsch_harq->q_ACK[1] =  ulsch_harq->q_ACK[1]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[12]*wACK_RX[wACK_idx][1];
+        ulsch_harq->q_ACK[2] =  ulsch_harq->q_ACK[6]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[13]*wACK_RX[wACK_idx][1];
+        break;
     }
 
     ulsch_harq->o_ACK[0] = 1;
@@ -1437,7 +1324,6 @@ unsigned int  ulsch_decoding(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
 
     metric_new = ulsch_harq->q_ACK[0]-ulsch_harq->q_ACK[1]+ulsch_harq->q_ACK[2];
 
-
     if (metric_new > metric) {
       ulsch_harq->o_ACK[0] = 1;
       ulsch_harq->o_ACK[1] = 0;
@@ -1461,26 +1347,21 @@ unsigned int  ulsch_decoding(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
   }
 
   // CQI
-
   //  printf("before cqi c[%d] = %p\n",0,ulsch_harq->c[0]);
   ulsch_harq->cqi_crc_status = 0;
+
   if (Q_CQI>0) {
     memset((void *)&dummy_w_cc[0],0,3*(ulsch_harq->Or1+8+32));
-
     O_RCC = generate_dummy_w_cc(ulsch_harq->Or1+8,
                                 &dummy_w_cc[0]);
-
-
     lte_rate_matching_cc_rx(O_RCC,
                             Q_CQI,
                             ulsch_harq->o_w,
                             dummy_w_cc,
                             ulsch_harq->q);
-
     sub_block_deinterleaving_cc((unsigned int)(ulsch_harq->Or1+8),
                                 &ulsch_harq->o_d[96],
                                 &ulsch_harq->o_w[0]);
-
     memset(ulsch_harq->o,0,(7+8+ulsch_harq->Or1) / 8);
     phy_viterbi_lte_sse2(ulsch_harq->o_d+96,ulsch_harq->o,8+ulsch_harq->Or1);
 
@@ -1491,7 +1372,7 @@ unsigned int  ulsch_decoding(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
     printf("ulsch_decoding: Or1=%d\n",ulsch_harq->Or1);
 
     for (i=0; i<1+((8+ulsch_harq->Or1)/8); i++)
-      printf("ulsch_decoding: O[%d] %d\n",i,ulsch_harq->o[i]);
+      printf("ulsch_decoding: O[%u] %d\n",i,ulsch_harq->o[i]);
 
     if (ulsch_harq->cqi_crc_status == 1)
       printf("RX CQI CRC OK (%x)\n",extract_cqi_crc(ulsch_harq->o,ulsch_harq->Or1));
@@ -1502,12 +1383,8 @@ unsigned int  ulsch_decoding(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
   }
 
   LOG_D(PHY,"frame %d subframe %d O_ACK:%d o_ACK[]=%d:%d:%d:%d\n",frame,subframe,ulsch_harq->O_ACK,ulsch_harq->o_ACK[0],ulsch_harq->o_ACK[1],ulsch_harq->o_ACK[2],ulsch_harq->o_ACK[3]);
-
   // Do ULSCH Decoding for data portion
-
-  ret = eNB->td(eNB,UE_id,harq_pid,llr8_flag);
-
+  ret = ulsch_decoding_data_all(eNB,UE_id,harq_pid,llr8_flag);
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_ULSCH_DECODING0+harq_pid,0);
-
   return(ret);
 }
diff --git a/openair1/PHY/LTE_TRANSPORT/ulsch_demodulation.c b/openair1/PHY/LTE_TRANSPORT/ulsch_demodulation.c
index 61076f2aae48fdfd6af03fafcda9d5c9b0bfdb06..8fab8cd0df8285d539f57fc5efa88f2e8221e66b 100644
--- a/openair1/PHY/LTE_TRANSPORT/ulsch_demodulation.c
+++ b/openair1/PHY/LTE_TRANSPORT/ulsch_demodulation.c
@@ -687,7 +687,7 @@ void ulsch_detection_mrc(LTE_DL_FRAME_PARMS *frame_parms,
       ul_ch_mag128_0[i]    = _mm_adds_epi16(_mm_srai_epi16(ul_ch_mag128_0[i],1),_mm_srai_epi16(ul_ch_mag128_1[i],1));
       ul_ch_mag128_0b[i]   = _mm_adds_epi16(_mm_srai_epi16(ul_ch_mag128_0b[i],1),_mm_srai_epi16(ul_ch_mag128_1b[i],1));
       rxdataF_comp128_0[i] = _mm_add_epi16(rxdataF_comp128_0[i],(*(__m128i*)&jitterc[0]));
-
+   }
 #elif defined(__arm__)
     rxdataF_comp128_0   = (int16x8_t *)&rxdataF_comp[0][symbol*frame_parms->N_RB_DL*12];
     rxdataF_comp128_1   = (int16x8_t *)&rxdataF_comp[1][symbol*frame_parms->N_RB_DL*12];
@@ -702,10 +702,10 @@ void ulsch_detection_mrc(LTE_DL_FRAME_PARMS *frame_parms,
       ul_ch_mag128_0[i]    = vhaddq_s16(ul_ch_mag128_0[i],ul_ch_mag128_1[i]);
       ul_ch_mag128_0b[i]   = vhaddq_s16(ul_ch_mag128_0b[i],ul_ch_mag128_1b[i]);
       rxdataF_comp128_0[i] = vqaddq_s16(rxdataF_comp128_0[i],(*(int16x8_t*)&jitterc[0]));
-
+    }
 
 #endif
-    }
+
   }
 
 #if defined(__x86_64__) || defined(__i386__)
@@ -1104,7 +1104,7 @@ void init_ulsch_power_LUT(void) {
 }
 
 void rx_ulsch(PHY_VARS_eNB *eNB,
-	      eNB_rxtx_proc_t *proc,
+	      L1_rxtx_proc_t *proc,
               uint8_t UE_id) {
 
 
@@ -1127,17 +1127,20 @@ void rx_ulsch(PHY_VARS_eNB *eNB,
   int16_t *llrp;
   int subframe = proc->subframe_rx;
 
-  harq_pid = subframe2harq_pid(frame_parms,proc->frame_rx,subframe);
+#ifdef Rel14
+  if (ulsch[UE_id]->ue_type > 0) harq_pid =0;
+  else
+#endif
+    {
+      harq_pid = subframe2harq_pid(frame_parms,proc->frame_rx,subframe);
+    }
   Qm = ulsch[UE_id]->harq_processes[harq_pid]->Qm;
   if(LOG_DEBUGFLAG(DEBUG_ULSCH)) {
      LOG_I(PHY,"rx_ulsch: harq_pid %d, nb_rb %d first_rb %d\n",harq_pid,ulsch[UE_id]->harq_processes[harq_pid]->nb_rb,ulsch[UE_id]->harq_processes[harq_pid]->first_rb);
   }
 
-  if (ulsch[UE_id]->harq_processes[harq_pid]->nb_rb == 0) {
-    LOG_E(PHY,"PUSCH (%d/%x) nb_rb=0!\n", harq_pid,ulsch[UE_id]->rnti);
-    return;
-  }
-
+  AssertFatal(ulsch[UE_id]->harq_processes[harq_pid]->nb_rb > 0,
+	      "PUSCH (%d/%x) nb_rb=0!\n", harq_pid,ulsch[UE_id]->rnti);
   for (l=0; l<(frame_parms->symbols_per_tti-ulsch[UE_id]->harq_processes[harq_pid]->srs_active); l++) {
 
   if(LOG_DEBUGFLAG(DEBUG_ULSCH)) {
@@ -1305,7 +1308,7 @@ void rx_ulsch(PHY_VARS_eNB *eNB,
 }
 
 void rx_ulsch_emul(PHY_VARS_eNB *eNB,
-		   eNB_rxtx_proc_t *proc,
+		   L1_rxtx_proc_t *proc,
                    uint8_t UE_index)
 {
   LOG_I(PHY,"[PHY] EMUL eNB %d rx_ulsch_emul : subframe %d, UE_index %d\n",eNB->Mod_id,proc->subframe_rx,UE_index);
diff --git a/openair1/PHY/LTE_UE_TRANSPORT/dci_tools_ue.c b/openair1/PHY/LTE_UE_TRANSPORT/dci_tools_ue.c
index 799a450fbfc2f798146ab567974058810e21d2fb..4f163a750e8c7fb354c7bb46cbed3b54fb4e8210 100644
--- a/openair1/PHY/LTE_UE_TRANSPORT/dci_tools_ue.c
+++ b/openair1/PHY/LTE_UE_TRANSPORT/dci_tools_ue.c
@@ -52,7 +52,14 @@
 #include "transport_proto_ue.h"
 #include "../LTE_TRANSPORT/transport_common_proto.h"
 #include "SCHED/sched_common.h"
- 
+
+/*
+#undef LOG_D
+#define LOG_D(A,B...) printf(B)
+#undef LOG_I
+#define LOG_I(A,B...) printf(B)
+*/
+
 extern uint16_t beta_cqi[16];
 extern uint16_t beta_ri[16];
 extern uint16_t beta_ack[16];
@@ -1275,7 +1282,7 @@ void compute_llr_offset(LTE_DL_FRAME_PARMS *frame_parms,
         symbol_mod = (symbol >= (7-frame_parms->Ncp))? (symbol-(7-frame_parms->Ncp)) : symbol;
         if((symbol_mod == 0) || symbol_mod == (4-frame_parms->Ncp))
         {
-	  if (frame_parms->nb_antennas_tx == 2) 
+	  if (frame_parms->nb_antenna_ports_eNB == 2)
 	    crs_re = 4;
 	  else
 	    crs_re = 2;
@@ -3594,7 +3601,7 @@ int generate_ue_ulsch_params_from_dci(void *dci_pdu,
 
     if (cqi_req == 1) {
 
-      if( (AntennaInfoDedicated__transmissionMode_tm3 == transmission_mode) || (AntennaInfoDedicated__transmissionMode_tm4 == transmission_mode) )
+      if( (LTE_AntennaInfoDedicated__transmissionMode_tm3 == transmission_mode) || (LTE_AntennaInfoDedicated__transmissionMode_tm4 == transmission_mode) )
       {
           ulsch->O_RI = 1;
       }
@@ -4223,7 +4230,7 @@ int generate_ue_ulsch_params_from_dci(void *dci_pdu,
 
 /*
 int generate_eNB_ulsch_params_from_dci(PHY_VARS_eNB *eNB,
-                                       eNB_rxtx_proc_t *proc,
+                                       L1_rxtx_proc_t *proc,
                                        void *dci_pdu,
                                        uint16_t rnti,
                                        DCI_format_t dci_format,
diff --git a/openair1/PHY/LTE_UE_TRANSPORT/dci_ue.c b/openair1/PHY/LTE_UE_TRANSPORT/dci_ue.c
old mode 100755
new mode 100644
index 4a2c8481cb9e5ae903fcc18f44f022911a8ec84a..2c6f31e24461b3b88e32955be531849761b31546
--- a/openair1/PHY/LTE_UE_TRANSPORT/dci_ue.c
+++ b/openair1/PHY/LTE_UE_TRANSPORT/dci_ue.c
@@ -362,6 +362,10 @@ void pdcch_channel_level(int32_t **dl_ch_estimates_ext,
 #elif defined(__arm__)
   int16x8_t *dl_ch128;
   int32x4_t *avg128P;
+#else
+  int16_t *dl_ch128;
+  int32_t *avg128P;
+#error Unsupported CPU architecture, cannot build __FILE__
 #endif
   for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++)
     for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
@@ -370,7 +374,11 @@ void pdcch_channel_level(int32_t **dl_ch_estimates_ext,
       avg128P = _mm_setzero_si128();
       dl_ch128=(__m128i *)&dl_ch_estimates_ext[(aatx<<1)+aarx][0];
 #elif defined(__arm__)
-
+     dl_ch128=&dl_ch_estimates_ext[(aatx<<1)+aarx][0];
+#error __arm__ not yet implemented, cannot build __FILE__
+#else
+      dl_ch128=&dl_ch_estimates_ext[(aatx<<1)+aarx][0];
+#error Unsupported CPU architecture, cannot build __FILE__
 #endif
       for (rb=0; rb<nb_rb; rb++) {
 
@@ -379,7 +387,8 @@ void pdcch_channel_level(int32_t **dl_ch_estimates_ext,
         avg128P = _mm_add_epi32(avg128P,_mm_madd_epi16(dl_ch128[1],dl_ch128[1]));
         avg128P = _mm_add_epi32(avg128P,_mm_madd_epi16(dl_ch128[2],dl_ch128[2]));
 #elif defined(__arm__)
-
+#else
+#error Unsupported CPU architecture, cannot build __FILE__
 #endif
         dl_ch128+=3;
         /*
@@ -423,6 +432,8 @@ void pdcch_detection_mrc_i(LTE_DL_FRAME_PARMS *frame_parms,
   __m128i *rxdataF_comp128_0,*rxdataF_comp128_1,*rxdataF_comp128_i0,*rxdataF_comp128_i1,*rho128_0,*rho128_1,*rho128_i0,*rho128_i1;
 #elif defined(__arm__)
   int16x8_t *rxdataF_comp128_0,*rxdataF_comp128_1,*rxdataF_comp128_i0,*rxdataF_comp128_i1,*rho128_0,*rho128_1,*rho128_i0,*rho128_i1;
+#else
+#error Unsupported CPU architecture, cannot build __FILE__
 #endif
   int32_t i;
 
@@ -436,6 +447,8 @@ void pdcch_detection_mrc_i(LTE_DL_FRAME_PARMS *frame_parms,
 #elif defined(__arm__)
       rxdataF_comp128_0   = (int16x8_t *)&rxdataF_comp[(aatx<<1)][symbol*frame_parms->N_RB_DL*12];
       rxdataF_comp128_1   = (int16x8_t *)&rxdataF_comp[(aatx<<1)+1][symbol*frame_parms->N_RB_DL*12];
+#else
+#error Unsupported CPU architecture, cannot build __FILE__
 #endif
       // MRC on each re of rb on MF output
       for (i=0; i<frame_parms->N_RB_DL*3; i++) {
diff --git a/openair1/PHY/LTE_UE_TRANSPORT/dlsch_decoding.c b/openair1/PHY/LTE_UE_TRANSPORT/dlsch_decoding.c
index afbd19329d32a36a1666b4d8091616dc3cfd2142..4ca9a7c7625f19470fb3023269e37081ade943d2 100644
--- a/openair1/PHY/LTE_UE_TRANSPORT/dlsch_decoding.c
+++ b/openair1/PHY/LTE_UE_TRANSPORT/dlsch_decoding.c
@@ -38,12 +38,9 @@
 #include "common/utils/LOG/vcd_signal_dumper.h"
 #include "PHY/LTE_UE_TRANSPORT/transport_proto_ue.h"
 //#define DEBUG_DLSCH_DECODING
-#define UE_DEBUG_TRACE 1
-
-
-void free_ue_dlsch(LTE_UE_DLSCH_t *dlsch)
-{
+//#define UE_DEBUG_TRACE 1
 
+void free_ue_dlsch(LTE_UE_DLSCH_t *dlsch) {
   int i,r;
 
   if (dlsch) {
@@ -71,34 +68,30 @@ void free_ue_dlsch(LTE_UE_DLSCH_t *dlsch)
     }
 
     free16(dlsch,sizeof(LTE_UE_DLSCH_t));
-    dlsch = NULL;
   }
 }
 
-LTE_UE_DLSCH_t *new_ue_dlsch(uint8_t Kmimo,uint8_t Mdlharq,uint32_t Nsoft,uint8_t max_turbo_iterations,uint8_t N_RB_DL, uint8_t abstraction_flag)
-{
-
+LTE_UE_DLSCH_t *new_ue_dlsch(uint8_t Kmimo,uint8_t Mdlharq,uint32_t Nsoft,uint8_t max_turbo_iterations,uint8_t N_RB_DL, uint8_t abstraction_flag) {
   LTE_UE_DLSCH_t *dlsch;
   uint8_t exit_flag = 0,i,r;
-
   unsigned char bw_scaling =1;
 
   switch (N_RB_DL) {
-  case 6:
-    bw_scaling =16;
-    break;
+    case 6:
+      bw_scaling =16;
+      break;
 
-  case 25:
-    bw_scaling =4;
-    break;
+    case 25:
+      bw_scaling =4;
+      break;
 
-  case 50:
-    bw_scaling =2;
-    break;
+    case 50:
+      bw_scaling =2;
+      break;
 
-  default:
-    bw_scaling =1;
-    break;
+    default:
+      bw_scaling =1;
+      break;
   }
 
   dlsch = (LTE_UE_DLSCH_t *)malloc16(sizeof(LTE_UE_DLSCH_t));
@@ -117,7 +110,7 @@ LTE_UE_DLSCH_t *new_ue_dlsch(uint8_t Kmimo,uint8_t Mdlharq,uint32_t Nsoft,uint8_
       if (dlsch->harq_processes[i]) {
         memset(dlsch->harq_processes[i],0,sizeof(LTE_DL_UE_HARQ_t));
         dlsch->harq_processes[i]->first_tx=1;
-        dlsch->harq_processes[i]->b = (uint8_t*)malloc16(MAX_DLSCH_PAYLOAD_BYTES/bw_scaling);
+        dlsch->harq_processes[i]->b = (uint8_t *)malloc16(MAX_DLSCH_PAYLOAD_BYTES/bw_scaling);
 
         if (dlsch->harq_processes[i]->b)
           memset(dlsch->harq_processes[i]->b,0,MAX_DLSCH_PAYLOAD_BYTES/bw_scaling);
@@ -126,14 +119,14 @@ LTE_UE_DLSCH_t *new_ue_dlsch(uint8_t Kmimo,uint8_t Mdlharq,uint32_t Nsoft,uint8_
 
         if (abstraction_flag == 0) {
           for (r=0; r<MAX_NUM_DLSCH_SEGMENTS/bw_scaling; r++) {
-            dlsch->harq_processes[i]->c[r] = (uint8_t*)malloc16(((r==0)?8:0) + 3+ 768);
+            dlsch->harq_processes[i]->c[r] = (uint8_t *)malloc16(((r==0)?8:0) + 3+ 768);
 
             if (dlsch->harq_processes[i]->c[r])
               memset(dlsch->harq_processes[i]->c[r],0,((r==0)?8:0) + 3+ 768);
             else
               exit_flag=2;
 
-            dlsch->harq_processes[i]->d[r] = (short*)malloc16(((3*8*6144)+12+96)*sizeof(short));
+            dlsch->harq_processes[i]->d[r] = (short *)malloc16(((3*8*6144)+12+96)*sizeof(short));
 
             if (dlsch->harq_processes[i]->d[r])
               memset(dlsch->harq_processes[i]->d[r],0,((3*8*6144)+12+96)*sizeof(short));
@@ -152,7 +145,6 @@ LTE_UE_DLSCH_t *new_ue_dlsch(uint8_t Kmimo,uint8_t Mdlharq,uint32_t Nsoft,uint8_
 
   printf("new_ue_dlsch with size %zu: exit_flag = %u\n",sizeof(LTE_DL_UE_HARQ_t), exit_flag);
   free_ue_dlsch(dlsch);
-
   return(NULL);
 }
 
@@ -165,9 +157,7 @@ uint32_t  dlsch_decoding(PHY_VARS_UE *phy_vars_ue,
                          uint8_t subframe,
                          uint8_t harq_pid,
                          uint8_t is_crnti,
-                         uint8_t llr8_flag)
-{
-
+                         uint8_t llr8_flag) {
 #if UE_TIMING_TRACE
   time_stats_t *dlsch_rate_unmatching_stats=&phy_vars_ue->dlsch_rate_unmatching_stats;
   time_stats_t *dlsch_turbo_decoding_stats=&phy_vars_ue->dlsch_turbo_decoding_stats;
@@ -187,26 +177,24 @@ uint32_t  dlsch_decoding(PHY_VARS_UE *phy_vars_ue,
 #if 0
   int Kr_last,skipped_last=0;
   uint8_t (*tc_2cw)(int16_t *y,
-		    int16_t *y2,
-		    uint8_t *,
-		    uint8_t *,
-		    uint16_t,
-		    uint16_t,
-		    uint16_t,
-		    uint8_t,
-		    uint8_t,
-		    uint8_t,
-		    time_stats_t *,
-		    time_stats_t *,
-		    time_stats_t *,
-		    time_stats_t *,
-		    time_stats_t *,
-		    time_stats_t *,
-		    time_stats_t *);
-
-#endif
-decoder_if_t *tc;
-
+                    int16_t *y2,
+                    uint8_t *,
+                    uint8_t *,
+                    uint16_t,
+                    uint16_t,
+                    uint16_t,
+                    uint8_t,
+                    uint8_t,
+                    uint8_t,
+                    time_stats_t *,
+                    time_stats_t *,
+                    time_stats_t *,
+                    time_stats_t *,
+                    time_stats_t *,
+                    time_stats_t *,
+                    time_stats_t *);
+#endif
+  decoder_if_t *tc;
 
   if (!dlsch_llr) {
     printf("dlsch_decoding.c: NULL dlsch_llr pointer\n");
@@ -230,42 +218,32 @@ decoder_if_t *tc;
 
   if (dlsch->harq_ack[subframe].ack != 2) {
     LOG_D(PHY, "[UE %d] DLSCH @ SF%d : ACK bit is %d instead of DTX even before PDSCH is decoded!\n",
-        phy_vars_ue->Mod_id, subframe, dlsch->harq_ack[subframe].ack);
+          phy_vars_ue->Mod_id, subframe, dlsch->harq_ack[subframe].ack);
   }
 
   if (llr8_flag == 0) {
     tc = decoder16;
-  }
-  else
-  {
+  } else {
     AssertFatal (harq_process->TBS >= 256 , "Mismatch flag nbRB=%d TBS=%d mcs=%d Qm=%d RIV=%d round=%d \n",
-		 harq_process->nb_rb, harq_process->TBS,harq_process->mcs,harq_process->Qm,harq_process->rvidx,harq_process->round);
+                 harq_process->nb_rb, harq_process->TBS,harq_process->mcs,harq_process->Qm,harq_process->rvidx,harq_process->round);
     tc = decoder8;
   }
 
-
   //  nb_rb = dlsch->nb_rb;
-
   /*
   if (nb_rb > frame_parms->N_RB_DL) {
     printf("dlsch_decoding.c: Illegal nb_rb %d\n",nb_rb);
     return(max_turbo_iterations);
     }*/
-
   /*harq_pid = dlsch->current_harq_pid[phy_vars_ue->current_thread_id[subframe]];
   if (harq_pid >= 8) {
     printf("dlsch_decoding.c: Illegal harq_pid %d\n",harq_pid);
     return(max_turbo_iterations);
   }
   */
-
   harq_process->trials[harq_process->round]++;
-
   A = harq_process->TBS; //2072 for QPSK 1/3
-
   ret = dlsch->max_turbo_iterations;
-
-
   G = harq_process->G;
   //get_G(frame_parms,nb_rb,dlsch->rb_alloc,mod_order,num_pdcch_symbols,phy_vars_ue->frame,subframe);
 
@@ -294,40 +272,37 @@ decoder_if_t *tc;
   */
   err_flag = 0;
   r_offset = 0;
-
   unsigned char bw_scaling =1;
 
   switch (frame_parms->N_RB_DL) {
-  case 6:
-    bw_scaling =16;
-    break;
+    case 6:
+      bw_scaling =16;
+      break;
 
-  case 25:
-    bw_scaling =4;
-    break;
+    case 25:
+      bw_scaling =4;
+      break;
 
-  case 50:
-    bw_scaling =2;
-    break;
+    case 50:
+      bw_scaling =2;
+      break;
 
-  default:
-    bw_scaling =1;
-    break;
+    default:
+      bw_scaling =1;
+      break;
   }
 
   if (harq_process->C > MAX_NUM_DLSCH_SEGMENTS/bw_scaling) {
     LOG_E(PHY,"Illegal harq_process->C %d > %d\n",harq_process->C,MAX_NUM_DLSCH_SEGMENTS/bw_scaling);
     return((1+dlsch->max_turbo_iterations));
   }
+
 #ifdef DEBUG_DLSCH_DECODING
   printf("Segmentation: C %d, Cminus %d, Kminus %d, Kplus %d\n",harq_process->C,harq_process->Cminus,harq_process->Kminus,harq_process->Kplus);
 #endif
-
   opp_enabled=1;
 
   for (r=0; r<harq_process->C; r++) {
-
-
     // Get Turbo interleaver parameters
     if (r<harq_process->Cminus)
       Kr = harq_process->Kminus;
@@ -335,15 +310,13 @@ decoder_if_t *tc;
       Kr = harq_process->Kplus;
 
     Kr_bytes = Kr>>3;
-
 #if UE_TIMING_TRACE
     start_meas(dlsch_rate_unmatching_stats);
 #endif
     memset(&dummy_w[r][0],0,3*(6144+64)*sizeof(short));
     harq_process->RTC[r] = generate_dummy_w(4+(Kr_bytes*8),
-                                            (uint8_t*) &dummy_w[r][0],
+                                            (uint8_t *) &dummy_w[r][0],
                                             (r==0) ? harq_process->F : 0);
-
 #ifdef DEBUG_DLSCH_DECODING
     LOG_D(PHY,"HARQ_PID %d Rate Matching Segment %d (coded bits %d,unpunctured/repeated bits %d, TBS %d, mod_order %d, nb_rb %d, Nl %d, rv %d, round %d)...\n",
           harq_pid,r, G,
@@ -355,14 +328,14 @@ decoder_if_t *tc;
           harq_process->rvidx,
           harq_process->round);
 #endif
-
 #ifdef DEBUG_DLSCH_DECODING
     printf(" in decoding dlsch->harq_processes[harq_pid]->rvidx = %d\n", dlsch->harq_processes[harq_pid]->rvidx);
 #endif
+
     if (lte_rate_matching_turbo_rx(harq_process->RTC[r],
                                    G,
                                    harq_process->w[r],
-                                   (uint8_t*)&dummy_w[r][0],
+                                   (uint8_t *)&dummy_w[r][0],
                                    dlsch_llr+r_offset,
                                    harq_process->C,
                                    dlsch->Nsoft,
@@ -379,14 +352,13 @@ decoder_if_t *tc;
 #endif
       LOG_E(PHY,"dlsch_decoding.c: Problem in rate_matching\n");
       return(dlsch->max_turbo_iterations);
-    } else
-    {
+    } else {
 #if UE_TIMING_TRACE
       stop_meas(dlsch_rate_unmatching_stats);
 #endif
     }
-    r_offset += E;
 
+    r_offset += E;
     /*
     printf("Subblock deinterleaving, d %p w %p\n",
      harq_process->d[r],
@@ -397,7 +369,6 @@ decoder_if_t *tc;
 #endif
     sub_block_deinterleaving_turbo(4+Kr,
                                    &harq_process->d[r][96],
-
                                    harq_process->w[r]);
 #if UE_TIMING_TRACE
     stop_meas(dlsch_deinterleaving_stats);
@@ -414,8 +385,6 @@ decoder_if_t *tc;
       printf("%d : %d\n",i,harq_process->d[r][96+i]);
       printf("\n");*/
 #endif
-
-
     //    printf("Clearing c, %p\n",harq_process->c[r]);
     memset(harq_process->c[r],0,Kr_bytes);
 
@@ -433,21 +402,22 @@ decoder_if_t *tc;
     printf("%d : %d\n",i,harq_process->d[r][96+i]);
     printf("\n");
     */
-
     //#ifndef __AVX2__
 #if 1
+
     if (err_flag == 0) {
-/*
-        LOG_I(PHY, "turbo algo Kr=%d cb_cnt=%d C=%d nbRB=%d crc_type %d TBSInput=%d TBSHarq=%d TBSplus24=%d mcs=%d Qm=%d RIV=%d round=%d maxIter %d\n",
-                            Kr,r,harq_process->C,harq_process->nb_rb,crc_type,A,harq_process->TBS,
-                            harq_process->B,harq_process->mcs,harq_process->Qm,harq_process->rvidx,harq_process->round,dlsch->max_turbo_iterations);
-*/
-    	if (llr8_flag) {
-    		AssertFatal (Kr >= 256, "turbo algo issue Kr=%d cb_cnt=%d C=%d nbRB=%d TBSInput=%d TBSHarq=%d TBSplus24=%d mcs=%d Qm=%d RIV=%d round=%d\n",
-    				Kr,r,harq_process->C,harq_process->nb_rb,A,harq_process->TBS,harq_process->B,harq_process->mcs,harq_process->Qm,harq_process->rvidx,harq_process->round);
-    	}
+      /*
+              LOG_I(PHY, "turbo algo Kr=%d cb_cnt=%d C=%d nbRB=%d crc_type %d TBSInput=%d TBSHarq=%d TBSplus24=%d mcs=%d Qm=%d RIV=%d round=%d maxIter %d\n",
+                                  Kr,r,harq_process->C,harq_process->nb_rb,crc_type,A,harq_process->TBS,
+                                  harq_process->B,harq_process->mcs,harq_process->Qm,harq_process->rvidx,harq_process->round,dlsch->max_turbo_iterations);
+      */
+      if (llr8_flag) {
+        AssertFatal (Kr >= 256, "turbo algo issue Kr=%d cb_cnt=%d C=%d nbRB=%d TBSInput=%d TBSHarq=%d TBSplus24=%d mcs=%d Qm=%d RIV=%d round=%d\n",
+                     Kr,r,harq_process->C,harq_process->nb_rb,A,harq_process->TBS,harq_process->B,harq_process->mcs,harq_process->Qm,harq_process->rvidx,harq_process->round);
+      }
+
 #if UE_TIMING_TRACE
-        start_meas(dlsch_turbo_decoding_stats);
+      start_meas(dlsch_turbo_decoding_stats);
 #endif
       LOG_D(PHY,"AbsSubframe %d.%d Start turbo segment %d/%d \n",frame%1024,subframe,r,harq_process->C-1);
       ret = tc
@@ -466,17 +436,17 @@ decoder_if_t *tc;
              &phy_vars_ue->dlsch_tc_ext_stats,
              &phy_vars_ue->dlsch_tc_intl1_stats,
              &phy_vars_ue->dlsch_tc_intl2_stats); //(is_crnti==0)?harq_pid:harq_pid+1);
-
 #if UE_TIMING_TRACE
       stop_meas(dlsch_turbo_decoding_stats);
 #endif
     }
+
 #else
-    if ((harq_process->C == 1) ||
-	((r==harq_process->C-1) && (skipped_last==0))) { // last segment with odd number of segments
 
+    if ((harq_process->C == 1) ||
+        ((r==harq_process->C-1) && (skipped_last==0))) { // last segment with odd number of segments
 #if UE_TIMING_TRACE
-        start_meas(dlsch_turbo_decoding_stats);
+      start_meas(dlsch_turbo_decoding_stats);
 #endif
       ret = tc
             (&harq_process->d[r][96],
@@ -492,123 +462,115 @@ decoder_if_t *tc;
              &phy_vars_ue->dlsch_tc_ext_stats,
              &phy_vars_ue->dlsch_tc_intl1_stats,
              &phy_vars_ue->dlsch_tc_intl2_stats); //(is_crnti==0)?harq_pid:harq_pid+1);
- #if UE_TIMING_TRACE
+#if UE_TIMING_TRACE
       stop_meas(dlsch_turbo_decoding_stats);
 #endif
       //      printf("single decode, exit\n");
       //      exit(-1);
-    }
-    else {
-    // we can merge code segments
+    } else {
+      // we can merge code segments
       if ((skipped_last == 0) && (r<harq_process->C-1)) {
-	skipped_last = 1;
-	Kr_last = Kr;
-      }
-      else {
-	skipped_last=0;
+        skipped_last = 1;
+        Kr_last = Kr;
+      } else {
+        skipped_last=0;
 
-	if (Kr_last == Kr) { // decode 2 code segments with AVX2 version
+        if (Kr_last == Kr) { // decode 2 code segments with AVX2 version
 #ifdef DEBUG_DLSCH_DECODING
-	  printf("single decoding segment %d (%p)\n",r-1,&harq_process->d[r-1][96]);
+          printf("single decoding segment %d (%p)\n",r-1,&harq_process->d[r-1][96]);
 #endif
 #if UE_TIMING_TRACE
-	  start_meas(dlsch_turbo_decoding_stats);
+          start_meas(dlsch_turbo_decoding_stats);
 #endif
 #ifdef DEBUG_DLSCH_DECODING
-	  printf("double decoding segments %d,%d (%p,%p)\n",r-1,r,&harq_process->d[r-1][96],&harq_process->d[r][96]);
-#endif
-	  ret = tc_2cw
-            (&harq_process->d[r-1][96],
-	     &harq_process->d[r][96],
-             harq_process->c[r-1],
-             harq_process->c[r],
-             Kr,
-             dlsch->max_turbo_iterations,
-             crc_type,
-             (r==0) ? harq_process->F : 0,
-             &phy_vars_ue->dlsch_tc_init_stats,
-             &phy_vars_ue->dlsch_tc_alpha_stats,
-             &phy_vars_ue->dlsch_tc_beta_stats,
-             &phy_vars_ue->dlsch_tc_gamma_stats,
-             &phy_vars_ue->dlsch_tc_ext_stats,
-             &phy_vars_ue->dlsch_tc_intl1_stats,
-             &phy_vars_ue->dlsch_tc_intl2_stats); //(is_crnti==0)?harq_pid:harq_pid+1);
-	  /*
-	  ret = tc
-            (&harq_process->d[r-1][96],
-             harq_process->c[r-1],
-             Kr_last,
-             dlsch->max_turbo_iterations,
-             crc_type,
-             (r==0) ? harq_process->F : 0,
-             &phy_vars_ue->dlsch_tc_init_stats,
-             &phy_vars_ue->dlsch_tc_alpha_stats,
-             &phy_vars_ue->dlsch_tc_beta_stats,
-             &phy_vars_ue->dlsch_tc_gamma_stats,
-             &phy_vars_ue->dlsch_tc_ext_stats,
-             &phy_vars_ue->dlsch_tc_intl1_stats,
-             &phy_vars_ue->dlsch_tc_intl2_stats); //(is_crnti==0)?harq_pid:harq_pid+1);
-
-	     exit(-1);*/
+          printf("double decoding segments %d,%d (%p,%p)\n",r-1,r,&harq_process->d[r-1][96],&harq_process->d[r][96]);
+#endif
+          ret = tc_2cw
+                (&harq_process->d[r-1][96],
+                 &harq_process->d[r][96],
+                 harq_process->c[r-1],
+                 harq_process->c[r],
+                 Kr,
+                 dlsch->max_turbo_iterations,
+                 crc_type,
+                 (r==0) ? harq_process->F : 0,
+                 &phy_vars_ue->dlsch_tc_init_stats,
+                 &phy_vars_ue->dlsch_tc_alpha_stats,
+                 &phy_vars_ue->dlsch_tc_beta_stats,
+                 &phy_vars_ue->dlsch_tc_gamma_stats,
+                 &phy_vars_ue->dlsch_tc_ext_stats,
+                 &phy_vars_ue->dlsch_tc_intl1_stats,
+                 &phy_vars_ue->dlsch_tc_intl2_stats); //(is_crnti==0)?harq_pid:harq_pid+1);
+          /*
+          ret = tc
+                  (&harq_process->d[r-1][96],
+                   harq_process->c[r-1],
+                   Kr_last,
+                   dlsch->max_turbo_iterations,
+                   crc_type,
+                   (r==0) ? harq_process->F : 0,
+                   &phy_vars_ue->dlsch_tc_init_stats,
+                   &phy_vars_ue->dlsch_tc_alpha_stats,
+                   &phy_vars_ue->dlsch_tc_beta_stats,
+                   &phy_vars_ue->dlsch_tc_gamma_stats,
+                   &phy_vars_ue->dlsch_tc_ext_stats,
+                   &phy_vars_ue->dlsch_tc_intl1_stats,
+                   &phy_vars_ue->dlsch_tc_intl2_stats); //(is_crnti==0)?harq_pid:harq_pid+1);
+
+             exit(-1);*/
 #if UE_TIMING_TRACE
-      stop_meas(dlsch_turbo_decoding_stats);
+          stop_meas(dlsch_turbo_decoding_stats);
 #endif
-	}
-	else { // Kr_last != Kr
+        } else { // Kr_last != Kr
 #if UE_TIMING_TRACE
-	  start_meas(dlsch_turbo_decoding_stats);
-#endif
-	  ret = tc
-            (&harq_process->d[r-1][96],
-             harq_process->c[r-1],
-             Kr_last,
-             dlsch->max_turbo_iterations,
-             crc_type,
-             (r==0) ? harq_process->F : 0,
-             &phy_vars_ue->dlsch_tc_init_stats,
-             &phy_vars_ue->dlsch_tc_alpha_stats,
-             &phy_vars_ue->dlsch_tc_beta_stats,
-             &phy_vars_ue->dlsch_tc_gamma_stats,
-             &phy_vars_ue->dlsch_tc_ext_stats,
-             &phy_vars_ue->dlsch_tc_intl1_stats,
-             &phy_vars_ue->dlsch_tc_intl2_stats); //(is_crnti==0)?harq_pid:harq_pid+1);
+          start_meas(dlsch_turbo_decoding_stats);
+#endif
+          ret = tc
+                (&harq_process->d[r-1][96],
+                 harq_process->c[r-1],
+                 Kr_last,
+                 dlsch->max_turbo_iterations,
+                 crc_type,
+                 (r==0) ? harq_process->F : 0,
+                 &phy_vars_ue->dlsch_tc_init_stats,
+                 &phy_vars_ue->dlsch_tc_alpha_stats,
+                 &phy_vars_ue->dlsch_tc_beta_stats,
+                 &phy_vars_ue->dlsch_tc_gamma_stats,
+                 &phy_vars_ue->dlsch_tc_ext_stats,
+                 &phy_vars_ue->dlsch_tc_intl1_stats,
+                 &phy_vars_ue->dlsch_tc_intl2_stats); //(is_crnti==0)?harq_pid:harq_pid+1);
 #if UE_TIMING_TRACE
-      stop_meas(dlsch_turbo_decoding_stats);
-
-	  start_meas(dlsch_turbo_decoding_stats);
-#endif
-
-	  ret = tc
-            (&harq_process->d[r][96],
-             harq_process->c[r],
-             Kr,
-             dlsch->max_turbo_iterations,
-             crc_type,
-             (r==0) ? harq_process->F : 0,
-             &phy_vars_ue->dlsch_tc_init_stats,
-             &phy_vars_ue->dlsch_tc_alpha_stats,
-             &phy_vars_ue->dlsch_tc_beta_stats,
-             &phy_vars_ue->dlsch_tc_gamma_stats,
-             &phy_vars_ue->dlsch_tc_ext_stats,
-             &phy_vars_ue->dlsch_tc_intl1_stats,
-             &phy_vars_ue->dlsch_tc_intl2_stats); //(is_crnti==0)?harq_pid:harq_pid+1);
-
+          stop_meas(dlsch_turbo_decoding_stats);
+          start_meas(dlsch_turbo_decoding_stats);
+#endif
+          ret = tc
+                (&harq_process->d[r][96],
+                 harq_process->c[r],
+                 Kr,
+                 dlsch->max_turbo_iterations,
+                 crc_type,
+                 (r==0) ? harq_process->F : 0,
+                 &phy_vars_ue->dlsch_tc_init_stats,
+                 &phy_vars_ue->dlsch_tc_alpha_stats,
+                 &phy_vars_ue->dlsch_tc_beta_stats,
+                 &phy_vars_ue->dlsch_tc_gamma_stats,
+                 &phy_vars_ue->dlsch_tc_ext_stats,
+                 &phy_vars_ue->dlsch_tc_intl1_stats,
+                 &phy_vars_ue->dlsch_tc_intl2_stats); //(is_crnti==0)?harq_pid:harq_pid+1);
 #if UE_TIMING_TRACE
-
-	  stop_meas(dlsch_turbo_decoding_stats);
-
-	  /*printf("Segmentation: C %d r %d, dlsch_rate_unmatching_stats %5.3f dlsch_deinterleaving_stats %5.3f  dlsch_turbo_decoding_stats %5.3f \n",
-              harq_process->C,
-              r,
-              dlsch_rate_unmatching_stats->p_time/(cpuf*1000.0),
-              dlsch_deinterleaving_stats->p_time/(cpuf*1000.0),
-              dlsch_turbo_decoding_stats->p_time/(cpuf*1000.0));*/
+          stop_meas(dlsch_turbo_decoding_stats);
+          /*printf("Segmentation: C %d r %d, dlsch_rate_unmatching_stats %5.3f dlsch_deinterleaving_stats %5.3f  dlsch_turbo_decoding_stats %5.3f \n",
+                    harq_process->C,
+                    r,
+                    dlsch_rate_unmatching_stats->p_time/(cpuf*1000.0),
+                    dlsch_deinterleaving_stats->p_time/(cpuf*1000.0),
+                    dlsch_turbo_decoding_stats->p_time/(cpuf*1000.0));*/
 #endif
-	}
+        }
       }
     }
-#endif
 
+#endif
 
     if ((err_flag == 0) && (ret>=(1+dlsch->max_turbo_iterations))) {// a Code segment is in error so break;
       LOG_D(PHY,"AbsSubframe %d.%d CRC failed, segment %d/%d \n",frame%1024,subframe,r,harq_process->C-1);
@@ -618,16 +580,18 @@ decoder_if_t *tc;
 
   int32_t frame_rx_prev = frame;
   int32_t subframe_rx_prev = subframe - 1;
+
   if (subframe_rx_prev < 0) {
     frame_rx_prev--;
     subframe_rx_prev += 10;
   }
+
   frame_rx_prev = frame_rx_prev%1024;
 
   if (err_flag == 1) {
 #if UE_DEBUG_TRACE
-    LOG_I(PHY,"[UE %d] DLSCH: Setting NAK for SFN/SF %d/%d (pid %d, status %d, round %d, TBS %d, mcs %d) Kr %d r %d harq_process->round %d\n",
-        phy_vars_ue->Mod_id, frame, subframe, harq_pid,harq_process->status, harq_process->round,harq_process->TBS,harq_process->mcs,Kr,r,harq_process->round);
+    LOG_D(PHY,"[UE %d] DLSCH: Setting NAK for SFN/SF %d/%d (pid %d, status %d, round %d, TBS %d, mcs %d) Kr %d r %d harq_process->round %d\n",
+          phy_vars_ue->Mod_id, frame, subframe, harq_pid,harq_process->status, harq_process->round,harq_process->TBS,harq_process->mcs,Kr,r,harq_process->round);
 #endif
     dlsch->harq_ack[subframe].ack = 0;
     dlsch->harq_ack[subframe].harq_id = harq_pid;
@@ -635,39 +599,36 @@ decoder_if_t *tc;
     harq_process->errors[harq_process->round]++;
     harq_process->round++;
 
-
     //    printf("Rate: [UE %d] DLSCH: Setting NACK for subframe %d (pid %d, round %d)\n",phy_vars_ue->Mod_id,subframe,harq_pid,harq_process->round);
     if (harq_process->round >= dlsch->Mdlharq) {
       harq_process->status = SCH_IDLE;
       harq_process->round  = 0;
     }
-    if(is_crnti)
-    {
-    LOG_D(PHY,"[UE %d] DLSCH: Setting NACK for subframe %d (pid %d, pid status %d, round %d/Max %d, TBS %d)\n",
-               phy_vars_ue->Mod_id,subframe,harq_pid,harq_process->status,harq_process->round,dlsch->Mdlharq,harq_process->TBS);
+
+    if(is_crnti) {
+      LOG_D(PHY,"[UE %d] DLSCH: Setting NACK for subframe %d (pid %d, pid status %d, round %d/Max %d, TBS %d)\n",
+            phy_vars_ue->Mod_id,subframe,harq_pid,harq_process->status,harq_process->round,dlsch->Mdlharq,harq_process->TBS);
     }
 
     return((1+dlsch->max_turbo_iterations));
   } else {
 #if UE_DEBUG_TRACE
-      LOG_I(PHY,"[UE %d] DLSCH: Setting ACK for subframe %d TBS %d mcs %d nb_rb %d\n",
-           phy_vars_ue->Mod_id,subframe,harq_process->TBS,harq_process->mcs,harq_process->nb_rb);
+    LOG_D(PHY,"[UE %d] DLSCH: Setting ACK for subframe %d TBS %d mcs %d nb_rb %d\n",
+          phy_vars_ue->Mod_id,subframe,harq_process->TBS,harq_process->mcs,harq_process->nb_rb);
 #endif
-
     harq_process->status = SCH_IDLE;
     harq_process->round  = 0;
     dlsch->harq_ack[subframe].ack = 1;
     dlsch->harq_ack[subframe].harq_id = harq_pid;
     dlsch->harq_ack[subframe].send_harq_status = 1;
     //LOG_I(PHY,"[UE %d] DLSCH: Setting ACK for SFN/SF %d/%d (pid %d, status %d, round %d, TBS %d, mcs %d)\n",
-      //  phy_vars_ue->Mod_id, frame, subframe, harq_pid, harq_process->status, harq_process->round,harq_process->TBS,harq_process->mcs);
+    //  phy_vars_ue->Mod_id, frame, subframe, harq_pid, harq_process->status, harq_process->round,harq_process->TBS,harq_process->mcs);
 
-    if(is_crnti)
-    {
-    LOG_D(PHY,"[UE %d] DLSCH: Setting ACK for subframe %d (pid %d, round %d, TBS %d)\n",phy_vars_ue->Mod_id,subframe,harq_pid,harq_process->round,harq_process->TBS);
+    if(is_crnti) {
+      LOG_D(PHY,"[UE %d] DLSCH: Setting ACK for subframe %d (pid %d, round %d, TBS %d)\n",phy_vars_ue->Mod_id,subframe,harq_pid,harq_process->round,harq_process->TBS);
     }
-    //LOG_D(PHY,"[UE %d] DLSCH: Setting ACK for subframe %d (pid %d, round %d)\n",phy_vars_ue->Mod_id,subframe,harq_pid,harq_process->round);
 
+    //LOG_D(PHY,"[UE %d] DLSCH: Setting ACK for subframe %d (pid %d, round %d)\n",phy_vars_ue->Mod_id,subframe,harq_pid,harq_process->round);
   }
 
   // Reassembly of Transport block here
@@ -707,24 +668,20 @@ decoder_if_t *tc;
   }
 
   dlsch->last_iteration_cnt = ret;
-
   return(ret);
 }
 
 int dlsch_encoding_SIC(PHY_VARS_UE *ue,
-		       unsigned char *a,
-		       uint8_t num_pdcch_symbols,
-		       LTE_eNB_DLSCH_t *dlsch,
-		       int frame,
-		       uint8_t subframe,
-		       time_stats_t *rm_stats,
-		       time_stats_t *te_stats,
-		       time_stats_t *i_stats)
-{
-  
+                       unsigned char *a,
+                       uint8_t num_pdcch_symbols,
+                       LTE_eNB_DLSCH_t *dlsch,
+                       int frame,
+                       uint8_t subframe,
+                       time_stats_t *rm_stats,
+                       time_stats_t *te_stats,
+                       time_stats_t *i_stats) {
   unsigned int G;
   unsigned int crc=1;
-
   LTE_DL_FRAME_PARMS *frame_parms = &ue->frame_parms;
   unsigned char harq_pid = ue->dlsch[subframe&2][0][0]->rnti;
   unsigned short nb_rb = dlsch->harq_processes[harq_pid]->nb_rb;
@@ -733,9 +690,7 @@ int dlsch_encoding_SIC(PHY_VARS_UE *ue,
   unsigned int Kr=0,Kr_bytes,r,r_offset=0;
   //  unsigned short m=dlsch->harq_processes[harq_pid]->mcs;
   uint8_t beamforming_mode=0;
-
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ENCODING, VCD_FUNCTION_IN);
-
   A = dlsch->harq_processes[harq_pid]->TBS; //6228
   // printf("Encoder: A: %d\n",A);
   mod_order = dlsch->harq_processes[harq_pid]->Qm;
@@ -746,13 +701,13 @@ int dlsch_encoding_SIC(PHY_VARS_UE *ue,
     beamforming_mode = 8;
   else if(dlsch->harq_processes[harq_pid]->mimo_mode == TM9_10)
     beamforming_mode = 9;
-  G = get_G(frame_parms,nb_rb,dlsch->harq_processes[harq_pid]->rb_alloc,mod_order,dlsch->harq_processes[harq_pid]->Nl,num_pdcch_symbols,frame,subframe,beamforming_mode);
 
+  G = get_G(frame_parms,nb_rb,dlsch->harq_processes[harq_pid]->rb_alloc,mod_order,dlsch->harq_processes[harq_pid]->Nl,num_pdcch_symbols,frame,subframe,beamforming_mode);
 
   //  if (dlsch->harq_processes[harq_pid]->Ndi == 1) {  // this is a new packet
   if (dlsch->harq_processes[harq_pid]->round == 0) {  // this is a new packet
 #ifdef DEBUG_DLSCH_CODING
-  printf("SIC encoding thinks this is a new packet \n");
+    printf("SIC encoding thinks this is a new packet \n");
 #endif
     /*
     int i;
@@ -764,11 +719,10 @@ int dlsch_encoding_SIC(PHY_VARS_UE *ue,
     // Add 24-bit crc (polynomial A) to payload
     crc = crc24a(a,
                  A)>>8;
-    a[A>>3] = ((uint8_t*)&crc)[2];
-    a[1+(A>>3)] = ((uint8_t*)&crc)[1];
-    a[2+(A>>3)] = ((uint8_t*)&crc)[0];
+    a[A>>3] = ((uint8_t *)&crc)[2];
+    a[1+(A>>3)] = ((uint8_t *)&crc)[1];
+    a[2+(A>>3)] = ((uint8_t *)&crc)[0];
     //    printf("CRC %x (A %d)\n",crc,A);
-
     dlsch->harq_processes[harq_pid]->B = A+24;
     //    dlsch->harq_processes[harq_pid]->b = a;
     memcpy(dlsch->harq_processes[harq_pid]->b,a,(A/8)+4);
@@ -785,25 +739,20 @@ int dlsch_encoding_SIC(PHY_VARS_UE *ue,
       return(-1);
 
     for (r=0; r<dlsch->harq_processes[harq_pid]->C; r++) {
-
       if (r<dlsch->harq_processes[harq_pid]->Cminus)
         Kr = dlsch->harq_processes[harq_pid]->Kminus;
       else
         Kr = dlsch->harq_processes[harq_pid]->Kplus;
 
       Kr_bytes = Kr>>3;
-
 #ifdef DEBUG_DLSCH_CODING
-      printf("Generating Code Segment %d (%d bits)\n",r,Kr);
+      printf("Generating Code Segment %u (%u bits)\n",r,Kr);
       // generate codewords
-
-      printf("bits_per_codeword (Kr)= %d, A %d\n",Kr,A);
+      printf("bits_per_codeword (Kr)= %u, A %u\n",Kr,A);
       printf("N_RB = %d\n",nb_rb);
       printf("Ncp %d\n",frame_parms->Ncp);
       printf("mod_order %d\n",mod_order);
 #endif
-
-
       start_meas(te_stats);
       encoder(dlsch->harq_processes[harq_pid]->c[r],
               Kr>>3,
@@ -824,7 +773,6 @@ int dlsch_encoding_SIC(PHY_VARS_UE *ue,
                                      dlsch->harq_processes[harq_pid]->w[r]);
       stop_meas(i_stats);
     }
-
   }
 
   // Fill in the "e"-sequence from 36-212, V8.6 2009-03, p. 16-17 (for each "e") and concatenate the
@@ -832,13 +780,12 @@ int dlsch_encoding_SIC(PHY_VARS_UE *ue,
 
   for (r=0; r<dlsch->harq_processes[harq_pid]->C; r++) {
 #ifdef DEBUG_DLSCH_CODING
-    printf("Rate Matching, Code segment %d (coded bits (G) %d,unpunctured/repeated bits per code segment %d,mod_order %d, nb_rb %d)...\n",
-        r,
-        G,
-        Kr*3,
-        mod_order,nb_rb);
+    printf("Rate Matching, Code segment %u (coded bits (G) %u,unpunctured/repeated bits per code segment %u,mod_order %d, nb_rb %d)...\n",
+           r,
+           G,
+           Kr*3,
+           mod_order,nb_rb);
 #endif
-
     start_meas(rm_stats);
 #ifdef DEBUG_DLSCH_CODING
     printf("rvidx in SIC encoding = %d\n", dlsch->harq_processes[harq_pid]->rvidx);
@@ -867,6 +814,5 @@ int dlsch_encoding_SIC(PHY_VARS_UE *ue,
   }
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ENCODING, VCD_FUNCTION_OUT);
-
   return(0);
 }
diff --git a/openair1/PHY/LTE_UE_TRANSPORT/dlsch_demodulation.c b/openair1/PHY/LTE_UE_TRANSPORT/dlsch_demodulation.c
index e8f20c85de6a682ce3cf947ee23aa4447c0eb776..aafd579899ad023de7cbc7e0c843b75bab09215d 100644
--- a/openair1/PHY/LTE_UE_TRANSPORT/dlsch_demodulation.c
+++ b/openair1/PHY/LTE_UE_TRANSPORT/dlsch_demodulation.c
@@ -42,11 +42,11 @@
 #include <string.h>
 #include <linux/version.h>
 #if RHEL_RELEASE_CODE >= 1796
-#include <lapacke/lapacke_utils.h>
-#include <lapacke/lapacke.h>
+  #include <lapacke/lapacke_utils.h>
+  #include <lapacke/lapacke.h>
 #else
-#include <lapacke_utils.h>
-#include <lapacke.h>
+  #include <lapacke_utils.h>
+  #include <lapacke.h>
 #endif
 #include <cblas.h>
 #include "linear_preprocessing_rec.h"
@@ -72,10 +72,12 @@ int16_t interf_unaw_shift = 13;
 // [MCS][i_mod (0,1,2) = (2,4,6)]
 unsigned char offset_mumimo_llr_drange_fix=0;
 //inferference-free case
-unsigned char interf_unaw_shift_tm4_mcs[29]={5, 3, 4, 3, 3, 2, 1, 1, 2, 0, 1, 1, 1, 1, 0, 0,
-                                             1, 1, 1, 1, 0, 2, 1, 0, 1, 0, 1, 0, 0} ;
-unsigned char interf_unaw_shift_tm1_mcs[29]={5, 5, 4, 3, 3, 3, 2, 2, 4, 4, 2, 3, 3, 3, 1, 1,
-                                             0, 1, 1, 2, 5, 4, 4, 6, 5, 1, 0, 5, 6} ; // mcs 21, 26, 28 seem to be errorneous
+unsigned char interf_unaw_shift_tm4_mcs[29]= {5, 3, 4, 3, 3, 2, 1, 1, 2, 0, 1, 1, 1, 1, 0, 0,
+                                              1, 1, 1, 1, 0, 2, 1, 0, 1, 0, 1, 0, 0
+                                             } ;
+unsigned char interf_unaw_shift_tm1_mcs[29]= {5, 5, 4, 3, 3, 3, 2, 2, 4, 4, 2, 3, 3, 3, 1, 1,
+                                              0, 1, 1, 2, 5, 4, 4, 6, 5, 1, 0, 5, 6
+                                             } ; // mcs 21, 26, 28 seem to be errorneous
 
 /*
 //original values from sebastion + same hand tuning
@@ -83,14 +85,14 @@ unsigned char offset_mumimo_llr_drange[29][3]={{8,8,8},{7,7,7},{7,7,7},{7,7,7},{
 {5,5,4},{5,5,5},{5,5,5},{3,3,3},{2,2,2},{2,2,2},{2,2,2}, // 16-QAM
 {2,2,1},{3,3,3},{3,3,3},{3,3,1},{2,2,2},{2,2,2},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}; //64-QAM
 */
- /*
- //first optimization try
- unsigned char offset_mumimo_llr_drange[29][3]={{7, 8, 7},{6, 6, 7},{6, 6, 7},{6, 6, 6},{5, 6, 6},{5, 5, 6},{5, 5, 6},{4, 5, 4},{4, 3, 4},{3, 2, 2},{6, 5, 5},{5, 4, 4},{5, 5, 4},{3, 3, 2},{2, 2, 1},{2, 1, 1},{2, 2, 2},{3, 3, 3},{3, 3, 2},{3, 3, 2},{3, 2, 1},{2, 2, 2},{2, 2, 2},{0, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0}};
- */
- //second optimization try
- /*
-   unsigned char offset_mumimo_llr_drange[29][3]={{5, 8, 7},{4, 6, 8},{3, 6, 7},{7, 7, 6},{4, 7, 8},{4, 7, 4},{6, 6, 6},{3, 6, 6},{3, 6, 6},{1, 3, 4},{1, 1, 0},{3, 3, 2},{3, 4, 1},{4, 0, 1},{4, 2, 2},{3, 1, 2},{2, 1, 0},{2, 1, 1},{1, 0, 1},{1, 0, 1},{0, 0, 0},{1, 0, 0},{0, 0, 0},{0, 1, 0},{1, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0}};  w
- */
+/*
+//first optimization try
+unsigned char offset_mumimo_llr_drange[29][3]={{7, 8, 7},{6, 6, 7},{6, 6, 7},{6, 6, 6},{5, 6, 6},{5, 5, 6},{5, 5, 6},{4, 5, 4},{4, 3, 4},{3, 2, 2},{6, 5, 5},{5, 4, 4},{5, 5, 4},{3, 3, 2},{2, 2, 1},{2, 1, 1},{2, 2, 2},{3, 3, 3},{3, 3, 2},{3, 3, 2},{3, 2, 1},{2, 2, 2},{2, 2, 2},{0, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0}};
+*/
+//second optimization try
+/*
+  unsigned char offset_mumimo_llr_drange[29][3]={{5, 8, 7},{4, 6, 8},{3, 6, 7},{7, 7, 6},{4, 7, 8},{4, 7, 4},{6, 6, 6},{3, 6, 6},{3, 6, 6},{1, 3, 4},{1, 1, 0},{3, 3, 2},{3, 4, 1},{4, 0, 1},{4, 2, 2},{3, 1, 2},{2, 1, 0},{2, 1, 1},{1, 0, 1},{1, 0, 1},{0, 0, 0},{1, 0, 0},{0, 0, 0},{0, 1, 0},{1, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0}};  w
+*/
 unsigned char offset_mumimo_llr_drange[29][3]= {{0, 6, 5},{0, 4, 5},{0, 4, 5},{0, 5, 4},{0, 5, 6},{0, 5, 3},{0, 4, 4},{0, 4, 4},{0, 3, 3},{0, 1, 2},{1, 1, 0},{1, 3, 2},{3, 4, 1},{2, 0, 0},{2, 2, 2},{1, 1, 1},{2, 1, 0},{2, 1, 1},{1, 0, 1},{1, 0, 1},{0, 0, 0},{1, 0, 0},{0, 0, 0},{0, 1, 0},{1, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0}};
 
 
@@ -107,111 +109,99 @@ int rx_pdsch(PHY_VARS_UE *ue,
              unsigned char first_symbol_flag,
              RX_type_t rx_type,
              unsigned char i_mod,
-             unsigned char harq_pid)
-{
-
+             unsigned char harq_pid) {
   LTE_UE_COMMON *common_vars  = &ue->common_vars;
   LTE_UE_PDSCH **pdsch_vars;
   LTE_DL_FRAME_PARMS *frame_parms    = &ue->frame_parms;
   PHY_MEASUREMENTS *measurements = &ue->measurements;
   LTE_UE_DLSCH_t   **dlsch;
-
   int avg[4];
   int avg_0[2];
   int avg_1[2];
   unsigned short mmse_flag=0;
-
 #if UE_TIMING_TRACE
   uint8_t slot = 0;
 #endif
-
   unsigned char aatx,aarx;
-
   unsigned short nb_rb = 0, round;
   int avgs = 0, rb;
   LTE_DL_UE_HARQ_t *dlsch0_harq,*dlsch1_harq = 0;
-
   uint8_t beamforming_mode;
   uint32_t *rballoc;
-
   int32_t **rxdataF_comp_ptr;
   int32_t **dl_ch_mag_ptr;
   int32_t codeword_TB0 = -1;
   int32_t codeword_TB1 = -1;
 
-
-
   switch (type) {
-  case SI_PDSCH:
-    pdsch_vars = &ue->pdsch_vars_SI[eNB_id];
-    dlsch = &ue->dlsch_SI[eNB_id];
-    dlsch0_harq = dlsch[0]->harq_processes[harq_pid];
-    beamforming_mode  = 0;
-    break;
-
-  case RA_PDSCH:
-    pdsch_vars = &ue->pdsch_vars_ra[eNB_id];
-    dlsch = &ue->dlsch_ra[eNB_id];
-    dlsch0_harq = dlsch[0]->harq_processes[harq_pid];
-    beamforming_mode  = 0;
-    break;
-
-  case PDSCH:
-    pdsch_vars = ue->pdsch_vars[ue->current_thread_id[subframe]];
-    dlsch = ue->dlsch[ue->current_thread_id[subframe]][eNB_id];
-    //printf("status TB0 = %d, status TB1 = %d \n", dlsch[0]->harq_processes[harq_pid]->status, dlsch[1]->harq_processes[harq_pid]->status);
-    LOG_D(PHY,"AbsSubframe %d.%d / Sym %d harq_pid %d,  harq status %d.%d \n",
-                   frame,subframe,symbol,harq_pid,
-                   dlsch[0]->harq_processes[harq_pid]->status,
-                   dlsch[1]->harq_processes[harq_pid]->status);
-
-    if ((dlsch[0]->harq_processes[harq_pid]->status == ACTIVE) &&
-        (dlsch[1]->harq_processes[harq_pid]->status == ACTIVE)){
-      codeword_TB0 = dlsch[0]->harq_processes[harq_pid]->codeword;
-      codeword_TB1 = dlsch[1]->harq_processes[harq_pid]->codeword;
-      dlsch0_harq = dlsch[codeword_TB0]->harq_processes[harq_pid];
-      dlsch1_harq = dlsch[codeword_TB1]->harq_processes[harq_pid];
+    case SI_PDSCH:
+      pdsch_vars = &ue->pdsch_vars_SI[eNB_id];
+      dlsch = &ue->dlsch_SI[eNB_id];
+      dlsch0_harq = dlsch[0]->harq_processes[harq_pid];
+      beamforming_mode  = 0;
+      break;
+
+    case RA_PDSCH:
+      pdsch_vars = &ue->pdsch_vars_ra[eNB_id];
+      dlsch = &ue->dlsch_ra[eNB_id];
+      dlsch0_harq = dlsch[0]->harq_processes[harq_pid];
+      beamforming_mode  = 0;
+      break;
+
+    case PDSCH:
+      pdsch_vars = ue->pdsch_vars[ue->current_thread_id[subframe]];
+      dlsch = ue->dlsch[ue->current_thread_id[subframe]][eNB_id];
+      //printf("status TB0 = %d, status TB1 = %d \n", dlsch[0]->harq_processes[harq_pid]->status, dlsch[1]->harq_processes[harq_pid]->status);
+      LOG_D(PHY,"AbsSubframe %d.%d / Sym %d harq_pid %d,  harq status %d.%d \n",
+            frame,subframe,symbol,harq_pid,
+            dlsch[0]->harq_processes[harq_pid]->status,
+            dlsch[1]->harq_processes[harq_pid]->status);
+
+      if ((dlsch[0]->harq_processes[harq_pid]->status == ACTIVE) &&
+          (dlsch[1]->harq_processes[harq_pid]->status == ACTIVE)) {
+        codeword_TB0 = dlsch[0]->harq_processes[harq_pid]->codeword;
+        codeword_TB1 = dlsch[1]->harq_processes[harq_pid]->codeword;
+        dlsch0_harq = dlsch[codeword_TB0]->harq_processes[harq_pid];
+        dlsch1_harq = dlsch[codeword_TB1]->harq_processes[harq_pid];
 #ifdef DEBUG_HARQ
-      printf("[DEMOD] I am assuming both TBs are active\n");
+        printf("[DEMOD] I am assuming both TBs are active\n");
 #endif
-    }
-     else if ((dlsch[0]->harq_processes[harq_pid]->status == ACTIVE) &&
-              (dlsch[1]->harq_processes[harq_pid]->status != ACTIVE) ) {
-      codeword_TB0 = dlsch[0]->harq_processes[harq_pid]->codeword;
-      dlsch0_harq = dlsch[0]->harq_processes[harq_pid];
-      dlsch1_harq = NULL;
-      codeword_TB1 = -1;
+      } else if ((dlsch[0]->harq_processes[harq_pid]->status == ACTIVE) &&
+                 (dlsch[1]->harq_processes[harq_pid]->status != ACTIVE) ) {
+        codeword_TB0 = dlsch[0]->harq_processes[harq_pid]->codeword;
+        dlsch0_harq = dlsch[0]->harq_processes[harq_pid];
+        dlsch1_harq = NULL;
+        codeword_TB1 = -1;
 #ifdef DEBUG_HARQ
-      printf("[DEMOD] I am assuming only TB0 is active\n");
+        printf("[DEMOD] I am assuming only TB0 is active\n");
 #endif
-    }
-     else if ((dlsch[0]->harq_processes[harq_pid]->status != ACTIVE) &&
-              (dlsch[1]->harq_processes[harq_pid]->status == ACTIVE) ){
-      codeword_TB1 = dlsch[1]->harq_processes[harq_pid]->codeword;
-      dlsch0_harq  = dlsch[1]->harq_processes[harq_pid];
-      dlsch1_harq  = NULL;
-      codeword_TB0 = -1;
+      } else if ((dlsch[0]->harq_processes[harq_pid]->status != ACTIVE) &&
+                 (dlsch[1]->harq_processes[harq_pid]->status == ACTIVE) ) {
+        codeword_TB1 = dlsch[1]->harq_processes[harq_pid]->codeword;
+        dlsch0_harq  = dlsch[1]->harq_processes[harq_pid];
+        dlsch1_harq  = NULL;
+        codeword_TB0 = -1;
 #ifdef DEBUG_HARQ
-      printf("[DEMOD] I am assuming only TB1 is active, it is in cw %d\n", dlsch0_harq->codeword);
+        printf("[DEMOD] I am assuming only TB1 is active, it is in cw %d\n", dlsch0_harq->codeword);
 #endif
-    }
-    else {
-      LOG_E(PHY,"[UE][FATAL] Frame %d subframe %d: no active DLSCH\n",ue->proc.proc_rxtx[0].frame_rx,subframe);
-      return(-1);
-    }
-    beamforming_mode  = ue->transmission_mode[eNB_id]<7?0:ue->transmission_mode[eNB_id];
-    break;
+      } else {
+        LOG_E(PHY,"[UE][FATAL] Frame %d subframe %d: no active DLSCH\n",ue->proc.proc_rxtx[0].frame_rx,subframe);
+        return(-1);
+      }
 
-  default:
-    LOG_E(PHY,"[UE][FATAL] Frame %d subframe %d: Unknown PDSCH format %d\n",ue->proc.proc_rxtx[0].frame_rx,subframe,type);
-    return(-1);
-    break;
+      beamforming_mode  = ue->transmission_mode[eNB_id]<7?0:ue->transmission_mode[eNB_id];
+      break;
+
+    default:
+      LOG_E(PHY,"[UE][FATAL] Frame %d subframe %d: Unknown PDSCH format %d\n",ue->proc.proc_rxtx[0].frame_rx,subframe,type);
+      return(-1);
+      break;
   }
+
 #ifdef DEBUG_HARQ
   printf("[DEMOD] MIMO mode = %d\n", dlsch0_harq->mimo_mode);
   printf("[DEMOD] cw for TB0 = %d, cw for TB1 = %d\n", codeword_TB0, codeword_TB1);
 #endif
-
   DevAssert(dlsch0_harq);
   round = dlsch0_harq->round;
   //printf("round = %d\n", round);
@@ -247,15 +237,14 @@ int rx_pdsch(PHY_VARS_UE *ue,
   else
     rballoc = dlsch0_harq->rb_alloc_even;
 
-
   if (dlsch0_harq->mimo_mode>DUALSTREAM_PUSCH_PRECODING) {
     LOG_E(PHY,"This transmission mode is not yet supported!\n");
     return(-1);
   }
 
-
   if ((dlsch0_harq->mimo_mode==LARGE_CDD) || ((dlsch0_harq->mimo_mode>=DUALSTREAM_UNIFORM_PRECODING1) && (dlsch0_harq->mimo_mode<=DUALSTREAM_PUSCH_PRECODING)))  {
     DevAssert(dlsch1_harq);
+
     if (eNB_id!=eNB_id_i) {
       LOG_E(PHY,"TM3/TM4 requires to set eNB_id==eNB_id_i!\n");
       return(-1);
@@ -263,12 +252,12 @@ int rx_pdsch(PHY_VARS_UE *ue,
   }
 
 #if UE_TIMING_TRACE
-  if(symbol > ue->frame_parms.symbols_per_tti>>1)
-  {
-      slot = 1;
+
+  if(symbol > ue->frame_parms.symbols_per_tti>>1) {
+    slot = 1;
   }
-#endif
 
+#endif
 #ifdef DEBUG_HARQ
   printf("Demod  dlsch0_harq->pmi_alloc %d\n",  dlsch0_harq->pmi_alloc);
 #endif
@@ -277,7 +266,6 @@ int rx_pdsch(PHY_VARS_UE *ue,
 #ifdef DEBUG_DLSCH_MOD
     LOG_I(PHY,"dlsch: using pmi %x (%p), rb_alloc %x\n",pmi2hex_2Ar1(dlsch0_harq->pmi_alloc),dlsch[0],dlsch0_harq->rb_alloc_even[0]);
 #endif
-
 #if UE_TIMING_TRACE
     start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
 #endif
@@ -294,15 +282,17 @@ int rx_pdsch(PHY_VARS_UE *ue,
                                    frame_parms,
                                    dlsch0_harq->mimo_mode);
 #ifdef DEBUG_DLSCH_MOD
-      printf("dlsch: using pmi %lx, rb_alloc %x, pmi_ext ",pmi2hex_2Ar1(dlsch0_harq->pmi_alloc),*rballoc);
-       for (rb=0;rb<nb_rb;rb++)
-          printf("%d",pdsch_vars[eNB_id]->pmi_ext[rb]);
-       printf("\n");
+    printf("dlsch: using pmi %lx, rb_alloc %x, pmi_ext ",pmi2hex_2Ar1(dlsch0_harq->pmi_alloc),*rballoc);
+
+    for (rb=0; rb<nb_rb; rb++)
+      printf("%d",pdsch_vars[eNB_id]->pmi_ext[rb]);
+
+    printf("\n");
 #endif
 
-   if (rx_type >= rx_IC_single_stream) {
+    if (rx_type >= rx_IC_single_stream) {
       if (eNB_id_i<ue->n_connected_eNB) // we are in TM5
-      nb_rb = dlsch_extract_rbs_dual(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].rxdataF,
+        nb_rb = dlsch_extract_rbs_dual(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].rxdataF,
                                        common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].dl_ch_estimates[eNB_id_i],
                                        pdsch_vars[eNB_id_i]->rxdataF_ext,
                                        pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
@@ -341,8 +331,8 @@ int rx_pdsch(PHY_VARS_UE *ue,
                                      ue->high_speed_flag,
                                      frame_parms);
 
-   if (rx_type==rx_IC_single_stream) {
-     if (eNB_id_i<ue->n_connected_eNB)
+    if (rx_type==rx_IC_single_stream) {
+      if (eNB_id_i<ue->n_connected_eNB)
         nb_rb = dlsch_extract_rbs_single(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].rxdataF,
                                          common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].dl_ch_estimates[eNB_id_i],
                                          pdsch_vars[eNB_id_i]->rxdataF_ext,
@@ -377,7 +367,6 @@ int rx_pdsch(PHY_VARS_UE *ue,
                                   subframe,
                                   ue->high_speed_flag,
                                   frame_parms);
-
   } else if(beamforming_mode>7) {
     LOG_W(PHY,"dlsch_demodulation: beamforming mode not supported yet.\n");
   }
@@ -388,25 +377,21 @@ int rx_pdsch(PHY_VARS_UE *ue,
     return(-1);
   }
 
-
 #if UE_TIMING_TRACE
-    stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
+  stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
 #if DISABLE_LOG_X
-    printf("[AbsSFN %d.%d] Slot%d Symbol %d Flag %d type %d: Pilot/Data extraction %5.2f \n",frame,subframe,slot,
-            symbol,ue->high_speed_flag,type,symbol,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0));
+  printf("[AbsSFN %d.%d] Slot%d Symbol %d Flag %d type %d: Pilot/Data extraction %5.2f \n",frame,subframe,slot,
+         symbol,ue->high_speed_flag,type,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0));
 #else
-    LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d Flag %d type %d: Pilot/Data extraction  %5.2f \n",frame,subframe,slot,symbol,
-            ue->high_speed_flag,type,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0));
+  LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d Flag %d type %d: Pilot/Data extraction  %5.2f \n",frame,subframe,slot,symbol,
+        ue->high_speed_flag,type,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0));
 #endif
 #endif
-
-
 #if UE_TIMING_TRACE
-    start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
+  start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
 #endif
   aatx = frame_parms->nb_antenna_ports_eNB;
   aarx = frame_parms->nb_antennas_rx;
-
   dlsch_scale_channel(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
                       frame_parms,
                       dlsch,
@@ -417,8 +402,7 @@ int rx_pdsch(PHY_VARS_UE *ue,
       (rx_type==rx_IC_single_stream) &&
       (eNB_id_i==ue->n_connected_eNB) &&
       (dlsch0_harq->dl_power_off==0)
-     )  // TM5 two-user
-  {
+     ) { // TM5 two-user
     dlsch_scale_channel(pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
                         frame_parms,
                         dlsch,
@@ -427,109 +411,100 @@ int rx_pdsch(PHY_VARS_UE *ue,
   }
 
 #if UE_TIMING_TRACE
-    stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
+  stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
 #if DISABLE_LOG_X
-    printf("[AbsSFN %d.%d] Slot%d Symbol %d: Channel Scale %5.2f \n",frame,subframe,slot,symbol,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0));
+  printf("[AbsSFN %d.%d] Slot%d Symbol %d: Channel Scale %5.2f \n",frame,subframe,slot,symbol,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0));
 #else
-    LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d: Channel Scale  %5.2f \n",frame,subframe,slot,symbol,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0));
+  LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d: Channel Scale  %5.2f \n",frame,subframe,slot,symbol,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0));
 #endif
 #endif
-
 #if UE_TIMING_TRACE
-    start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
+  start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
 #endif
+
   if (first_symbol_flag==1) {
-    if (beamforming_mode==0){
+    if (beamforming_mode==0) {
       if (dlsch0_harq->mimo_mode<LARGE_CDD) {
         dlsch_channel_level(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
-                           frame_parms,
-                           avg,
-                           symbol,
-                           nb_rb);
+                            frame_parms,
+                            avg,
+                            symbol,
+                            nb_rb);
         avgs = 0;
-        for (aatx=0;aatx<frame_parms->nb_antenna_ports_eNB;aatx++)
-          for (aarx=0;aarx<frame_parms->nb_antennas_rx;aarx++)
+
+        for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++)
+          for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++)
             avgs = cmax(avgs,avg[(aatx<<1)+aarx]);
 
         pdsch_vars[eNB_id]->log2_maxh = (log2_approx(avgs)/2)+1;
-     }
-     else if ((dlsch0_harq->mimo_mode == LARGE_CDD) ||
-           ((dlsch0_harq->mimo_mode >=DUALSTREAM_UNIFORM_PRECODING1) &&
-            (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING)))
-     {
-       dlsch_channel_level_TM34(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
-                                  frame_parms,
-                                  pdsch_vars[eNB_id]->pmi_ext,
-                                  avg_0,
-                                  avg_1,
-                                  symbol,
-                                  nb_rb,
-                                  mmse_flag,
-                                  dlsch0_harq->mimo_mode);
-
-      LOG_D(PHY,"Channel Level TM34  avg_0 %d, avg_1 %d, rx_type %d, rx_standard %d, dlsch_demod_shift %d \n", avg_0[0],
+      } else if ((dlsch0_harq->mimo_mode == LARGE_CDD) ||
+                 ((dlsch0_harq->mimo_mode >=DUALSTREAM_UNIFORM_PRECODING1) &&
+                  (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING))) {
+        dlsch_channel_level_TM34(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
+                                 frame_parms,
+                                 pdsch_vars[eNB_id]->pmi_ext,
+                                 avg_0,
+                                 avg_1,
+                                 symbol,
+                                 nb_rb,
+                                 mmse_flag,
+                                 dlsch0_harq->mimo_mode);
+        LOG_D(PHY,"Channel Level TM34  avg_0 %d, avg_1 %d, rx_type %d, rx_standard %d, dlsch_demod_shift %d \n", avg_0[0],
               avg_1[0], rx_type, rx_standard, dlsch_demod_shift);
+
         if (rx_type>rx_standard) {
           avg_0[0] = (log2_approx(avg_0[0])/2) + dlsch_demod_shift;// + 2 ;//+ 4;
           avg_1[0] = (log2_approx(avg_1[0])/2) + dlsch_demod_shift;// + 2 ;//+ 4;
           pdsch_vars[eNB_id]->log2_maxh0 = cmax(avg_0[0],0);
           pdsch_vars[eNB_id]->log2_maxh1 = cmax(avg_1[0],0);
-         // printf("dlsch_demod_shift  %d\n", dlsch_demod_shift);
-         }
-          else {
+          // printf("dlsch_demod_shift  %d\n", dlsch_demod_shift);
+        } else {
           avg_0[0] = (log2_approx(avg_0[0])/2) - 13 + interf_unaw_shift;
           avg_1[0] = (log2_approx(avg_1[0])/2) - 13 + interf_unaw_shift;
           pdsch_vars[eNB_id]->log2_maxh0 = cmax(avg_0[0],0);
           pdsch_vars[eNB_id]->log2_maxh1 = cmax(avg_1[0],0);
         }
-      }
-      else if (dlsch0_harq->mimo_mode<DUALSTREAM_UNIFORM_PRECODING1) {// single-layer precoding (TM5, TM6)
+      } else if (dlsch0_harq->mimo_mode<DUALSTREAM_UNIFORM_PRECODING1) { // single-layer precoding (TM5, TM6)
         if ((rx_type==rx_IC_single_stream) && (eNB_id_i==ue->n_connected_eNB) && (dlsch0_harq->dl_power_off==0)) {
-            dlsch_channel_level_TM56(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
-                                frame_parms,
-                                pdsch_vars[eNB_id]->pmi_ext,
-                                avg,
-                                symbol,
-                                nb_rb);
-            avg[0] = log2_approx(avg[0]) - 13 + offset_mumimo_llr_drange[dlsch0_harq->mcs][(i_mod>>1)-1];
-            pdsch_vars[eNB_id]->log2_maxh = cmax(avg[0],0);
-
-        }
-        else if (dlsch0_harq->dl_power_off==1) { //TM6
-
-          dlsch_channel_level(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
+          dlsch_channel_level_TM56(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
                                    frame_parms,
+                                   pdsch_vars[eNB_id]->pmi_ext,
                                    avg,
                                    symbol,
                                    nb_rb);
-
+          avg[0] = log2_approx(avg[0]) - 13 + offset_mumimo_llr_drange[dlsch0_harq->mcs][(i_mod>>1)-1];
+          pdsch_vars[eNB_id]->log2_maxh = cmax(avg[0],0);
+        } else if (dlsch0_harq->dl_power_off==1) { //TM6
+          dlsch_channel_level(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
+                              frame_parms,
+                              avg,
+                              symbol,
+                              nb_rb);
           avgs = 0;
-          for (aatx=0;aatx<frame_parms->nb_antenna_ports_eNB;aatx++)
-            for (aarx=0;aarx<frame_parms->nb_antennas_rx;aarx++)
+
+          for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++)
+            for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++)
               avgs = cmax(avgs,avg[(aatx<<1)+aarx]);
 
           pdsch_vars[eNB_id]->log2_maxh = (log2_approx(avgs)/2) + 1;
           pdsch_vars[eNB_id]->log2_maxh++;
-
         }
       }
-
-    }
-    else if (beamforming_mode==7)
-       dlsch_channel_level_TM7(pdsch_vars[eNB_id]->dl_bf_ch_estimates_ext,
+    } else if (beamforming_mode==7)
+      dlsch_channel_level_TM7(pdsch_vars[eNB_id]->dl_bf_ch_estimates_ext,
                               frame_parms,
                               avg,
                               symbol,
                               nb_rb);
+
 #ifdef UE_DEBUG_TRACE
     LOG_D(PHY,"[DLSCH] AbsSubframe %d.%d log2_maxh = %d [log2_maxh0 %d log2_maxh1 %d] (%d,%d)\n",
-            frame%1024,subframe, pdsch_vars[eNB_id]->log2_maxh,
-                                                 pdsch_vars[eNB_id]->log2_maxh0,
-                                                 pdsch_vars[eNB_id]->log2_maxh1,
-                                                 avg[0],avgs);
+          frame%1024,subframe, pdsch_vars[eNB_id]->log2_maxh,
+          pdsch_vars[eNB_id]->log2_maxh0,
+          pdsch_vars[eNB_id]->log2_maxh1,
+          avg[0],avgs);
     //LOG_D(PHY,"[DLSCH] mimo_mode = %d\n", dlsch0_harq->mimo_mode);
 #endif
-
     //wait until pdcch is decoded
     //proc->channel_level = 1;
   }
@@ -542,39 +517,36 @@ int rx_pdsch(PHY_VARS_UE *ue,
       wait++;
   }
   */
-
 #if T_TRACER
-    if (type == PDSCH)
-    {
-      T(T_UE_PHY_PDSCH_ENERGY, T_INT(eNB_id), T_INT(frame%1024), T_INT(subframe),
-                               T_INT(avg[0]), T_INT(avg[1]),     T_INT(avg[2]),   T_INT(avg[3]));
-    }
-#endif
 
+  if (type == PDSCH) {
+    T(T_UE_PHY_PDSCH_ENERGY, T_INT(eNB_id), T_INT(frame%1024), T_INT(subframe),
+      T_INT(avg[0]), T_INT(avg[1]),     T_INT(avg[2]),   T_INT(avg[3]));
+  }
+
+#endif
 #if UE_TIMING_TRACE
-    stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
+  stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
 #if DISABLE_LOG_X
-    printf("[AbsSFN %d.%d] Slot%d Symbol %d first_symbol_flag %d: Channel Level %5.2f \n",frame,subframe,slot,symbol,first_symbol_flag,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0));
+  printf("[AbsSFN %d.%d] Slot%d Symbol %d first_symbol_flag %d: Channel Level %5.2f \n",frame,subframe,slot,symbol,first_symbol_flag,
+         ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0));
 #else
-    LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d first_symbol_flag %d: Channel Level  %5.2f \n",frame,subframe,slot,symbol,first_symbol_flag,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0));
+  LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d first_symbol_flag %d: Channel Level  %5.2f \n",frame,subframe,slot,symbol,first_symbol_flag,
+        ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0));
 #endif
 #endif
-
-
 #if UE_TIMING_TRACE
-    start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
+  start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
 #endif
 
-  if (rx_type==rx_IC_dual_stream && mmse_flag==1){
-
+  if (rx_type==rx_IC_dual_stream && mmse_flag==1) {
     precode_channel_est(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
                         frame_parms,
                         pdsch_vars[eNB_id],
                         symbol,
                         nb_rb,
                         dlsch0_harq->mimo_mode);
-
-   mmse_processing_oai(pdsch_vars[eNB_id],
+    mmse_processing_oai(pdsch_vars[eNB_id],
                         frame_parms,
                         measurements,
                         first_symbol_flag,
@@ -585,7 +557,7 @@ int rx_pdsch(PHY_VARS_UE *ue,
                         nb_rb);
   }
 
-// Now channel compensation
+  // Now channel compensation
   if (dlsch0_harq->mimo_mode<LARGE_CDD) {
     dlsch_channel_compensation(pdsch_vars[eNB_id]->rxdataF_ext,
                                pdsch_vars[eNB_id]->dl_ch_estimates_ext,
@@ -600,13 +572,14 @@ int rx_pdsch(PHY_VARS_UE *ue,
                                nb_rb,
                                pdsch_vars[eNB_id]->log2_maxh,
                                measurements); // log2_maxh+I0_shift
+
     if (symbol == 5) {
-     LOG_M("rxF_comp_d.m","rxF_c_d",&pdsch_vars[eNB_id]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);
+      LOG_M("rxF_comp_d.m","rxF_c_d",&pdsch_vars[eNB_id]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);
     }
 
     if ((rx_type==rx_IC_single_stream) &&
         (eNB_id_i<ue->n_connected_eNB)) {
-         dlsch_channel_compensation(pdsch_vars[eNB_id_i]->rxdataF_ext,
+      dlsch_channel_compensation(pdsch_vars[eNB_id_i]->rxdataF_ext,
                                  pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
                                  pdsch_vars[eNB_id_i]->dl_ch_mag0,
                                  pdsch_vars[eNB_id_i]->dl_ch_magb0,
@@ -619,6 +592,7 @@ int rx_pdsch(PHY_VARS_UE *ue,
                                  nb_rb,
                                  pdsch_vars[eNB_id]->log2_maxh,
                                  measurements); // log2_maxh+I0_shift
+
       if (symbol == 5) {
         LOG_M("rxF_comp_d.m","rxF_c_d",&pdsch_vars[eNB_id]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);
         LOG_M("rxF_comp_i.m","rxF_c_i",&pdsch_vars[eNB_id_i]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);
@@ -633,55 +607,58 @@ int rx_pdsch(PHY_VARS_UE *ue,
                                     pdsch_vars[eNB_id]->log2_maxh);
     }
   } else if ((dlsch0_harq->mimo_mode == LARGE_CDD) || ((dlsch0_harq->mimo_mode >=DUALSTREAM_UNIFORM_PRECODING1) &&
-            (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING))){
-      dlsch_channel_compensation_TM34(frame_parms,
-                                     pdsch_vars[eNB_id],
-                                     measurements,
-                                     eNB_id,
-                                     symbol,
-                                     dlsch0_harq->Qm,
-                                     dlsch1_harq->Qm,
-                                     harq_pid,
-                                     dlsch0_harq->round,
-                                     dlsch0_harq->mimo_mode,
-                                     nb_rb,
-                                     mmse_flag,
-                                     pdsch_vars[eNB_id]->log2_maxh0,
-                                     pdsch_vars[eNB_id]->log2_maxh1);
-      if (symbol == 5) {
-	LOG_M("rxF_comp_d00.m","rxF_c_d00",&pdsch_vars[eNB_id]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);// should be QAM
-	LOG_M("rxF_comp_d01.m","rxF_c_d01",&pdsch_vars[eNB_id]->rxdataF_comp0[1][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be almost 0
-	LOG_M("rxF_comp_d10.m","rxF_c_d10",&pdsch_vars[eNB_id]->rxdataF_comp1[harq_pid][round][0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be almost 0
-	LOG_M("rxF_comp_d11.m","rxF_c_d11",&pdsch_vars[eNB_id]->rxdataF_comp1[harq_pid][round][1][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be QAM
-      }
-      // compute correlation between signal and interference channels (rho12 and rho21)
-      dlsch_dual_stream_correlation(frame_parms, // this is doing h11'*h12 and h21'*h22
+             (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING))) {
+    dlsch_channel_compensation_TM34(frame_parms,
+                                    pdsch_vars[eNB_id],
+                                    measurements,
+                                    eNB_id,
                                     symbol,
+                                    dlsch0_harq->Qm,
+                                    dlsch1_harq->Qm,
+                                    harq_pid,
+                                    dlsch0_harq->round,
+                                    dlsch0_harq->mimo_mode,
                                     nb_rb,
-                                    pdsch_vars[eNB_id]->dl_ch_estimates_ext,
-                                    &(pdsch_vars[eNB_id]->dl_ch_estimates_ext[2]),
-                                    pdsch_vars[eNB_id]->dl_ch_rho2_ext,
-                                    pdsch_vars[eNB_id]->log2_maxh0);
-        //printf("rho stream1 =%d\n", &pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round] );
-      //to be optimized (just take complex conjugate)
-      dlsch_dual_stream_correlation(frame_parms, // this is doing h12'*h11 and h22'*h21
-                                    symbol,
-                                    nb_rb,
-                                    &(pdsch_vars[eNB_id]->dl_ch_estimates_ext[2]),
-                                    pdsch_vars[eNB_id]->dl_ch_estimates_ext,
-                                    pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
+                                    mmse_flag,
+                                    pdsch_vars[eNB_id]->log2_maxh0,
                                     pdsch_vars[eNB_id]->log2_maxh1);
+
+    if (symbol == 5) {
+      LOG_M("rxF_comp_d00.m","rxF_c_d00",&pdsch_vars[eNB_id]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);// should be QAM
+      LOG_M("rxF_comp_d01.m","rxF_c_d01",&pdsch_vars[eNB_id]->rxdataF_comp0[1][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be almost 0
+      LOG_M("rxF_comp_d10.m","rxF_c_d10",&pdsch_vars[eNB_id]->rxdataF_comp1[harq_pid][round][0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be almost 0
+      LOG_M("rxF_comp_d11.m","rxF_c_d11",&pdsch_vars[eNB_id]->rxdataF_comp1[harq_pid][round][1][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be QAM
+    }
+
+    // compute correlation between signal and interference channels (rho12 and rho21)
+    dlsch_dual_stream_correlation(frame_parms, // this is doing h11'*h12 and h21'*h22
+                                  symbol,
+                                  nb_rb,
+                                  pdsch_vars[eNB_id]->dl_ch_estimates_ext,
+                                  &(pdsch_vars[eNB_id]->dl_ch_estimates_ext[2]),
+                                  pdsch_vars[eNB_id]->dl_ch_rho2_ext,
+                                  pdsch_vars[eNB_id]->log2_maxh0);
+    //printf("rho stream1 =%d\n", &pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round] );
+    //to be optimized (just take complex conjugate)
+    dlsch_dual_stream_correlation(frame_parms, // this is doing h12'*h11 and h22'*h21
+                                  symbol,
+                                  nb_rb,
+                                  &(pdsch_vars[eNB_id]->dl_ch_estimates_ext[2]),
+                                  pdsch_vars[eNB_id]->dl_ch_estimates_ext,
+                                  pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
+                                  pdsch_vars[eNB_id]->log2_maxh1);
+
     //  printf("rho stream2 =%d\n",&pdsch_vars[eNB_id]->dl_ch_rho2_ext );
-      //printf("TM3 log2_maxh : %d\n",pdsch_vars[eNB_id]->log2_maxh);
-      if (symbol == 5) {
-	LOG_M("rho0_0.m","rho0_0",&pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round][0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);// should be QAM
-	LOG_M("rho2_0.m","rho2_0",&pdsch_vars[eNB_id]->dl_ch_rho2_ext[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be almost 0
-	LOG_M("rho0_1.m.m","rho0_1",&pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round][1][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be almost 0
-	LOG_M("rho2_1.m","rho2_1",&pdsch_vars[eNB_id]->dl_ch_rho2_ext[1][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be QAM
-      }
-    } else if (dlsch0_harq->mimo_mode<DUALSTREAM_UNIFORM_PRECODING1) {// single-layer precoding (TM5, TM6)
-        if ((rx_type==rx_IC_single_stream) && (eNB_id_i==ue->n_connected_eNB) && (dlsch0_harq->dl_power_off==0)) {
-          dlsch_channel_compensation_TM56(pdsch_vars[eNB_id]->rxdataF_ext,
+    //printf("TM3 log2_maxh : %d\n",pdsch_vars[eNB_id]->log2_maxh);
+    if (symbol == 5) {
+      LOG_M("rho0_0.m","rho0_0",&pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round][0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);// should be QAM
+      LOG_M("rho2_0.m","rho2_0",&pdsch_vars[eNB_id]->dl_ch_rho2_ext[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be almost 0
+      LOG_M("rho0_1.m.m","rho0_1",&pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round][1][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be almost 0
+      LOG_M("rho2_1.m","rho2_1",&pdsch_vars[eNB_id]->dl_ch_rho2_ext[1][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be QAM
+    }
+  } else if (dlsch0_harq->mimo_mode<DUALSTREAM_UNIFORM_PRECODING1) {// single-layer precoding (TM5, TM6)
+    if ((rx_type==rx_IC_single_stream) && (eNB_id_i==ue->n_connected_eNB) && (dlsch0_harq->dl_power_off==0)) {
+      dlsch_channel_compensation_TM56(pdsch_vars[eNB_id]->rxdataF_ext,
                                       pdsch_vars[eNB_id]->dl_ch_estimates_ext,
                                       pdsch_vars[eNB_id]->dl_ch_mag0,
                                       pdsch_vars[eNB_id]->dl_ch_magb0,
@@ -696,24 +673,29 @@ int rx_pdsch(PHY_VARS_UE *ue,
                                       pdsch_vars[eNB_id]->log2_maxh,
                                       dlsch0_harq->dl_power_off);
 
-        for (rb=0; rb<nb_rb; rb++) {
-          switch(pdsch_vars[eNB_id]->pmi_ext[rb]) {
+      for (rb=0; rb<nb_rb; rb++) {
+        switch(pdsch_vars[eNB_id]->pmi_ext[rb]) {
           case 0:
             pdsch_vars[eNB_id_i]->pmi_ext[rb]=1;
             break;
-         case 1:
+
+          case 1:
             pdsch_vars[eNB_id_i]->pmi_ext[rb]=0;
             break;
-         case 2:
+
+          case 2:
             pdsch_vars[eNB_id_i]->pmi_ext[rb]=3;
             break;
+
           case 3:
             pdsch_vars[eNB_id_i]->pmi_ext[rb]=2;
             break;
-          }
-       //  if (rb==0)
+        }
+
+        //  if (rb==0)
         //    printf("pmi %d, pmi_i %d\n",pdsch_vars[eNB_id]->pmi_ext[rb],pdsch_vars[eNB_id_i]->pmi_ext[rb]);
       }
+
       dlsch_channel_compensation_TM56(pdsch_vars[eNB_id_i]->rxdataF_ext,
                                       pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
                                       pdsch_vars[eNB_id_i]->dl_ch_mag0,
@@ -728,9 +710,10 @@ int rx_pdsch(PHY_VARS_UE *ue,
                                       nb_rb,
                                       pdsch_vars[eNB_id]->log2_maxh,
                                       dlsch0_harq->dl_power_off);
+
       if (symbol==5) {
         LOG_M("rxF_comp_d.m","rxF_c_d",&pdsch_vars[eNB_id]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);
-	LOG_M("rxF_comp_i.m","rxF_c_i",&pdsch_vars[eNB_id_i]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);
+        LOG_M("rxF_comp_i.m","rxF_c_i",&pdsch_vars[eNB_id_i]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);
       }
 
       dlsch_dual_stream_correlation(frame_parms,
@@ -755,45 +738,43 @@ int rx_pdsch(PHY_VARS_UE *ue,
                                       nb_rb,
                                       pdsch_vars[eNB_id]->log2_maxh,
                                       1);
-
-      }
-
-
-    } else if (dlsch0_harq->mimo_mode==TM7) { //TM7
-
-      dlsch_channel_compensation(pdsch_vars[eNB_id]->rxdataF_ext,
-                                 pdsch_vars[eNB_id]->dl_bf_ch_estimates_ext,
-                                 pdsch_vars[eNB_id]->dl_ch_mag0,
-                                 pdsch_vars[eNB_id]->dl_ch_magb0,
-                                 pdsch_vars[eNB_id]->rxdataF_comp0,
-                                 (aatx>1) ? pdsch_vars[eNB_id]->rho : NULL,
-                                 frame_parms,
-                                 symbol,
-                                 first_symbol_flag,
-                                 get_Qm(dlsch0_harq->mcs),
-                                 nb_rb,
-                                 //9,
-                                 pdsch_vars[eNB_id]->log2_maxh,
-                                 measurements); // log2_maxh+I0_shift
+    }
+  } else if (dlsch0_harq->mimo_mode==TM7) { //TM7
+    dlsch_channel_compensation(pdsch_vars[eNB_id]->rxdataF_ext,
+                               pdsch_vars[eNB_id]->dl_bf_ch_estimates_ext,
+                               pdsch_vars[eNB_id]->dl_ch_mag0,
+                               pdsch_vars[eNB_id]->dl_ch_magb0,
+                               pdsch_vars[eNB_id]->rxdataF_comp0,
+                               (aatx>1) ? pdsch_vars[eNB_id]->rho : NULL,
+                               frame_parms,
+                               symbol,
+                               first_symbol_flag,
+                               get_Qm(dlsch0_harq->mcs),
+                               nb_rb,
+                               //9,
+                               pdsch_vars[eNB_id]->log2_maxh,
+                               measurements); // log2_maxh+I0_shift
   }
 
 #if UE_TIMING_TRACE
-    stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
+  stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
 #if DISABLE_LOG_X
-    printf("[AbsSFN %d.%d] Slot%d Symbol %d log2_maxh %d channel_level %d: Channel Comp %5.2f \n",frame,subframe,slot,symbol,pdsch_vars[eNB_id]->log2_maxh,proc->channel_level,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0));
+  printf("[AbsSFN %d.%d] Slot%d Symbol %d log2_maxh %d channel_level %d: Channel Comp %5.2f \n",frame,subframe,slot,symbol,pdsch_vars[eNB_id]->log2_maxh,proc->channel_level,
+         ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0));
 #else
-    LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d log2_maxh %d Channel Comp  %5.2f \n",frame,subframe,slot,symbol,pdsch_vars[eNB_id]->log2_maxh,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0));
+  LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d log2_maxh %d Channel Comp  %5.2f \n",frame,subframe,slot,symbol,pdsch_vars[eNB_id]->log2_maxh,
+        ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0));
 #endif
 #endif
-// MRC
+  // MRC
 #if UE_TIMING_TRACE
-    start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
+  start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
 #endif
 
-   if (frame_parms->nb_antennas_rx > 1) {
+  if (frame_parms->nb_antennas_rx > 1) {
     if ((dlsch0_harq->mimo_mode == LARGE_CDD) ||
         ((dlsch0_harq->mimo_mode >=DUALSTREAM_UNIFORM_PRECODING1) &&
-         (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING))){  // TM3 or TM4
+         (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING))) { // TM3 or TM4
       if (frame_parms->nb_antenna_ports_eNB == 2) {
         dlsch_detection_mrc_TM34(frame_parms,
                                  pdsch_vars[eNB_id],
@@ -802,9 +783,10 @@ int rx_pdsch(PHY_VARS_UE *ue,
                                  symbol,
                                  nb_rb,
                                  1);
-	if (symbol == 5) {
-	  LOG_M("rho0_mrc.m","rho0_0",&pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round][0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);// should be QAM
-	  LOG_M("rho2_mrc.m","rho2_0",&pdsch_vars[eNB_id]->dl_ch_rho2_ext[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be almost 0
+
+        if (symbol == 5) {
+          LOG_M("rho0_mrc.m","rho0_0",&pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round][0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);// should be QAM
+          LOG_M("rho2_mrc.m","rho2_0",&pdsch_vars[eNB_id]->dl_ch_rho2_ext[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be almost 0
         }
       }
     } else {
@@ -822,11 +804,12 @@ int rx_pdsch(PHY_VARS_UE *ue,
                           rx_type==rx_IC_single_stream);
     }
   }
+
   //  printf("Combining");
   if ((dlsch0_harq->mimo_mode == SISO) ||
       ((dlsch0_harq->mimo_mode >= UNIFORM_PRECODING11) &&
        (dlsch0_harq->mimo_mode <= PUSCH_PRECODING0)) ||
-       (dlsch0_harq->mimo_mode == TM7)) {
+      (dlsch0_harq->mimo_mode == TM7)) {
     /*
       dlsch_siso(frame_parms,
       pdsch_vars[eNB_id]->rxdataF_comp,
@@ -849,24 +832,22 @@ int rx_pdsch(PHY_VARS_UE *ue,
        (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING)))  {
     rxdataF_comp_ptr = pdsch_vars[eNB_id]->rxdataF_comp1[harq_pid][round];
     dl_ch_mag_ptr = pdsch_vars[eNB_id]->dl_ch_mag1[harq_pid][round];
-  }
-  else {
+  } else {
     rxdataF_comp_ptr = pdsch_vars[eNB_id_i]->rxdataF_comp0;
     dl_ch_mag_ptr = pdsch_vars[eNB_id_i]->dl_ch_mag0;
     //i_mod should have been passed as a parameter
   }
 
 #if UE_TIMING_TRACE
-    stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
+  stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
 #if DISABLE_LOG_X
-    printf("[AbsSFN %d.%d] Slot%d Symbol %d: Channel Combine %5.2f \n",frame,subframe,slot,symbol,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0));
+  printf("[AbsSFN %d.%d] Slot%d Symbol %d: Channel Combine %5.2f \n",frame,subframe,slot,symbol,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0));
 #else
-    LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d: Channel Combine  %5.2f \n",frame,subframe,slot,symbol,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0));
+  LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d: Channel Combine  %5.2f \n",frame,subframe,slot,symbol,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0));
 #endif
 #endif
-
 #if UE_TIMING_TRACE
-    start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
+  start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
 #endif
   //printf("LLR dlsch0_harq->Qm %d rx_type %d cw0 %d cw1 %d symbol %d \n",dlsch0_harq->Qm,rx_type,codeword_TB0,codeword_TB1,symbol);
   // compute LLRs
@@ -875,10 +856,11 @@ int rx_pdsch(PHY_VARS_UE *ue,
   int8_t  *pllr_symbol_cw1;
   uint32_t llr_offset_symbol;
   llr_offset_symbol = pdsch_vars[eNB_id]->llr_offset[symbol];
-  pllr_symbol_cw0  = (int8_t*)pdsch_vars[eNB_id]->llr[0];
-  pllr_symbol_cw1  = (int8_t*)pdsch_vars[eNB_id]->llr[1];
+  pllr_symbol_cw0  = (int8_t *)pdsch_vars[eNB_id]->llr[0];
+  pllr_symbol_cw1  = (int8_t *)pdsch_vars[eNB_id]->llr[1];
   pllr_symbol_cw0 += llr_offset_symbol;
   pllr_symbol_cw1 += llr_offset_symbol;
+
   /*
   LOG_I(PHY,"compute LLRs [AbsSubframe %d.%d-%d] NbRB %d Qm %d LLRs-Length %d LLR-Offset %d @LLR Buff %p @LLR Buff(symb) %p\n",
              frame, subframe,symbol,
@@ -889,31 +871,26 @@ int rx_pdsch(PHY_VARS_UE *ue,
              pllr_symbol_cw0);
   */
   switch (dlsch0_harq->Qm) {
-  case 2 :
-    if ((rx_type==rx_standard) || (codeword_TB1 == -1)) {
-
-
+    case 2 :
+      if ((rx_type==rx_standard) || (codeword_TB1 == -1)) {
         dlsch_qpsk_llr(frame_parms,
                        pdsch_vars[eNB_id]->rxdataF_comp0,
-                       (int16_t*)pllr_symbol_cw0,
+                       (int16_t *)pllr_symbol_cw0,
                        symbol,
                        first_symbol_flag,
                        nb_rb,
                        adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol),
                        beamforming_mode);
-
-    } else if (codeword_TB0 == -1){
-
+      } else if (codeword_TB0 == -1) {
         dlsch_qpsk_llr(frame_parms,
                        pdsch_vars[eNB_id]->rxdataF_comp0,
-                       (int16_t*)pllr_symbol_cw1,
+                       (int16_t *)pllr_symbol_cw1,
                        symbol,
                        first_symbol_flag,
                        nb_rb,
                        adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol),
                        beamforming_mode);
-    }
-      else if (rx_type >= rx_IC_single_stream) {
+      } else if (rx_type >= rx_IC_single_stream) {
         if (dlsch1_harq->Qm == 2) {
           dlsch_qpsk_qpsk_llr(frame_parms,
                               pdsch_vars[eNB_id]->rxdataF_comp0,
@@ -923,6 +900,7 @@ int rx_pdsch(PHY_VARS_UE *ue,
                               symbol,first_symbol_flag,nb_rb,
                               adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol),
                               pdsch_vars[eNB_id]->llr128);
+
           if (rx_type==rx_IC_dual_stream) {
             dlsch_qpsk_qpsk_llr(frame_parms,
                                 rxdataF_comp_ptr,
@@ -933,8 +911,7 @@ int rx_pdsch(PHY_VARS_UE *ue,
                                 adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,2,subframe,symbol),
                                 pdsch_vars[eNB_id]->llr128_2ndstream);
           }
-        }
-        else if (dlsch1_harq->Qm == 4) {
+        } else if (dlsch1_harq->Qm == 4) {
           dlsch_qpsk_16qam_llr(frame_parms,
                                pdsch_vars[eNB_id]->rxdataF_comp0,
                                rxdataF_comp_ptr,//i
@@ -944,6 +921,7 @@ int rx_pdsch(PHY_VARS_UE *ue,
                                symbol,first_symbol_flag,nb_rb,
                                adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol),
                                pdsch_vars[eNB_id]->llr128);
+
           if (rx_type==rx_IC_dual_stream) {
             dlsch_16qam_qpsk_llr(frame_parms,
                                  rxdataF_comp_ptr,
@@ -955,8 +933,7 @@ int rx_pdsch(PHY_VARS_UE *ue,
                                  adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,4,subframe,symbol),
                                  pdsch_vars[eNB_id]->llr128_2ndstream);
           }
-        }
-        else {
+        } else {
           dlsch_qpsk_64qam_llr(frame_parms,
                                pdsch_vars[eNB_id]->rxdataF_comp0,
                                rxdataF_comp_ptr,//i
@@ -966,6 +943,7 @@ int rx_pdsch(PHY_VARS_UE *ue,
                                symbol,first_symbol_flag,nb_rb,
                                adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol),
                                pdsch_vars[eNB_id]->llr128);
+
           if (rx_type==rx_IC_dual_stream) {
             dlsch_64qam_qpsk_llr(frame_parms,
                                  rxdataF_comp_ptr,
@@ -979,260 +957,272 @@ int rx_pdsch(PHY_VARS_UE *ue,
           }
         }
       }
-    break;
-  case 4 :
-    if ((rx_type==rx_standard ) || (codeword_TB1 == -1)) {
-      dlsch_16qam_llr(frame_parms,
-                      pdsch_vars[eNB_id]->rxdataF_comp0,
-                      pdsch_vars[eNB_id]->llr[0],
-                      pdsch_vars[eNB_id]->dl_ch_mag0,
-                      symbol,first_symbol_flag,nb_rb,
-                      adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol),
-                      pdsch_vars[eNB_id]->llr128,
-                      beamforming_mode);
-    } else if (codeword_TB0 == -1){
-      dlsch_16qam_llr(frame_parms,
-                      pdsch_vars[eNB_id]->rxdataF_comp0,
-                      pdsch_vars[eNB_id]->llr[1],
-                      pdsch_vars[eNB_id]->dl_ch_mag0,
-                      symbol,first_symbol_flag,nb_rb,
-                      adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol),
-                      pdsch_vars[eNB_id]->llr128_2ndstream,
-                      beamforming_mode);
-    }
-    else if (rx_type >= rx_IC_single_stream) {
-      if (dlsch1_harq->Qm == 2) {
-        dlsch_16qam_qpsk_llr(frame_parms,
-                             pdsch_vars[eNB_id]->rxdataF_comp0,
-                             rxdataF_comp_ptr,//i
-                             pdsch_vars[eNB_id]->dl_ch_mag0,
-                             pdsch_vars[eNB_id]->dl_ch_rho2_ext,
-                             pdsch_vars[eNB_id]->llr[0],
-                             symbol,first_symbol_flag,nb_rb,
-                             adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol),
-                             pdsch_vars[eNB_id]->llr128);
-        if (rx_type==rx_IC_dual_stream) {
-          dlsch_qpsk_16qam_llr(frame_parms,
-                               rxdataF_comp_ptr,
-                               pdsch_vars[eNB_id]->rxdataF_comp0,//i
-                               pdsch_vars[eNB_id]->dl_ch_mag0,//i
-                               pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
-                               pdsch_vars[eNB_id]->llr[1],
+
+      break;
+
+    case 4 :
+      if ((rx_type==rx_standard ) || (codeword_TB1 == -1)) {
+        dlsch_16qam_llr(frame_parms,
+                        pdsch_vars[eNB_id]->rxdataF_comp0,
+                        pdsch_vars[eNB_id]->llr[0],
+                        pdsch_vars[eNB_id]->dl_ch_mag0,
+                        symbol,first_symbol_flag,nb_rb,
+                        adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol),
+                        pdsch_vars[eNB_id]->llr128,
+                        beamforming_mode);
+      } else if (codeword_TB0 == -1) {
+        dlsch_16qam_llr(frame_parms,
+                        pdsch_vars[eNB_id]->rxdataF_comp0,
+                        pdsch_vars[eNB_id]->llr[1],
+                        pdsch_vars[eNB_id]->dl_ch_mag0,
+                        symbol,first_symbol_flag,nb_rb,
+                        adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol),
+                        pdsch_vars[eNB_id]->llr128_2ndstream,
+                        beamforming_mode);
+      } else if (rx_type >= rx_IC_single_stream) {
+        if (dlsch1_harq->Qm == 2) {
+          dlsch_16qam_qpsk_llr(frame_parms,
+                               pdsch_vars[eNB_id]->rxdataF_comp0,
+                               rxdataF_comp_ptr,//i
+                               pdsch_vars[eNB_id]->dl_ch_mag0,
+                               pdsch_vars[eNB_id]->dl_ch_rho2_ext,
+                               pdsch_vars[eNB_id]->llr[0],
                                symbol,first_symbol_flag,nb_rb,
-                               adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,2,subframe,symbol),
-                               pdsch_vars[eNB_id]->llr128_2ndstream);
-        }
-      }
-      else if (dlsch1_harq->Qm == 4) {
-        dlsch_16qam_16qam_llr(frame_parms,
-                              pdsch_vars[eNB_id]->rxdataF_comp0,
-                              rxdataF_comp_ptr,//i
-                              pdsch_vars[eNB_id]->dl_ch_mag0,
-                              dl_ch_mag_ptr,//i
-                              pdsch_vars[eNB_id]->dl_ch_rho2_ext,
-                              pdsch_vars[eNB_id]->llr[0],
-                              symbol,first_symbol_flag,nb_rb,
-                              adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol),
-                              pdsch_vars[eNB_id]->llr128);
-        if (rx_type==rx_IC_dual_stream) {
+                               adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol),
+                               pdsch_vars[eNB_id]->llr128);
+
+          if (rx_type==rx_IC_dual_stream) {
+            dlsch_qpsk_16qam_llr(frame_parms,
+                                 rxdataF_comp_ptr,
+                                 pdsch_vars[eNB_id]->rxdataF_comp0,//i
+                                 pdsch_vars[eNB_id]->dl_ch_mag0,//i
+                                 pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
+                                 pdsch_vars[eNB_id]->llr[1],
+                                 symbol,first_symbol_flag,nb_rb,
+                                 adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,2,subframe,symbol),
+                                 pdsch_vars[eNB_id]->llr128_2ndstream);
+          }
+        } else if (dlsch1_harq->Qm == 4) {
           dlsch_16qam_16qam_llr(frame_parms,
-                                rxdataF_comp_ptr,
-                                pdsch_vars[eNB_id]->rxdataF_comp0,//i
-                                dl_ch_mag_ptr,
-                                pdsch_vars[eNB_id]->dl_ch_mag0,//i
-                                pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
-                                pdsch_vars[eNB_id]->llr[1],
+                                pdsch_vars[eNB_id]->rxdataF_comp0,
+                                rxdataF_comp_ptr,//i
+                                pdsch_vars[eNB_id]->dl_ch_mag0,
+                                dl_ch_mag_ptr,//i
+                                pdsch_vars[eNB_id]->dl_ch_rho2_ext,
+                                pdsch_vars[eNB_id]->llr[0],
                                 symbol,first_symbol_flag,nb_rb,
-                                adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,4,subframe,symbol),
-                                pdsch_vars[eNB_id]->llr128_2ndstream);
-        }
-      }
-      else {
-        dlsch_16qam_64qam_llr(frame_parms,
-                              pdsch_vars[eNB_id]->rxdataF_comp0,
-                              rxdataF_comp_ptr,//i
-                              pdsch_vars[eNB_id]->dl_ch_mag0,
-                              dl_ch_mag_ptr,//i
-                              pdsch_vars[eNB_id]->dl_ch_rho2_ext,
-                              pdsch_vars[eNB_id]->llr[0],
-                              symbol,first_symbol_flag,nb_rb,
-                              adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol),
-                              pdsch_vars[eNB_id]->llr128);
-        if (rx_type==rx_IC_dual_stream) {
-          dlsch_64qam_16qam_llr(frame_parms,
-                                rxdataF_comp_ptr,
+                                adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol),
+                                pdsch_vars[eNB_id]->llr128);
+
+          if (rx_type==rx_IC_dual_stream) {
+            dlsch_16qam_16qam_llr(frame_parms,
+                                  rxdataF_comp_ptr,
+                                  pdsch_vars[eNB_id]->rxdataF_comp0,//i
+                                  dl_ch_mag_ptr,
+                                  pdsch_vars[eNB_id]->dl_ch_mag0,//i
+                                  pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
+                                  pdsch_vars[eNB_id]->llr[1],
+                                  symbol,first_symbol_flag,nb_rb,
+                                  adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,4,subframe,symbol),
+                                  pdsch_vars[eNB_id]->llr128_2ndstream);
+          }
+        } else {
+          dlsch_16qam_64qam_llr(frame_parms,
                                 pdsch_vars[eNB_id]->rxdataF_comp0,
-                                dl_ch_mag_ptr,
+                                rxdataF_comp_ptr,//i
                                 pdsch_vars[eNB_id]->dl_ch_mag0,
-                                pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
-                                pdsch_vars[eNB_id]->llr[1],
+                                dl_ch_mag_ptr,//i
+                                pdsch_vars[eNB_id]->dl_ch_rho2_ext,
+                                pdsch_vars[eNB_id]->llr[0],
                                 symbol,first_symbol_flag,nb_rb,
-                                adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,6,subframe,symbol),
-                                pdsch_vars[eNB_id]->llr128_2ndstream);
+                                adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol),
+                                pdsch_vars[eNB_id]->llr128);
+
+          if (rx_type==rx_IC_dual_stream) {
+            dlsch_64qam_16qam_llr(frame_parms,
+                                  rxdataF_comp_ptr,
+                                  pdsch_vars[eNB_id]->rxdataF_comp0,
+                                  dl_ch_mag_ptr,
+                                  pdsch_vars[eNB_id]->dl_ch_mag0,
+                                  pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
+                                  pdsch_vars[eNB_id]->llr[1],
+                                  symbol,first_symbol_flag,nb_rb,
+                                  adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,6,subframe,symbol),
+                                  pdsch_vars[eNB_id]->llr128_2ndstream);
+          }
         }
       }
-    }
-    break;
-  case 6 :
-    if ((rx_type==rx_standard) || (codeword_TB1 == -1))  {
-      dlsch_64qam_llr(frame_parms,
-                      pdsch_vars[eNB_id]->rxdataF_comp0,
-                      (int16_t*)pllr_symbol_cw0,
-                      pdsch_vars[eNB_id]->dl_ch_mag0,
-                      pdsch_vars[eNB_id]->dl_ch_magb0,
-                      symbol,first_symbol_flag,nb_rb,
-                      adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,subframe,symbol),
-                      pdsch_vars[eNB_id]->llr_offset[symbol],
-                      beamforming_mode);
-    } else if (codeword_TB0 == -1){
-      dlsch_64qam_llr(frame_parms,
-                      pdsch_vars[eNB_id]->rxdataF_comp0,
-                      (int16_t*)pllr_symbol_cw1,
-                      pdsch_vars[eNB_id]->dl_ch_mag0,
-                      pdsch_vars[eNB_id]->dl_ch_magb0,
-                      symbol,first_symbol_flag,nb_rb,
-                      adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,subframe,symbol),
-                      pdsch_vars[eNB_id]->llr_offset[symbol],
-                      beamforming_mode);
-    }
-    else if (rx_type >= rx_IC_single_stream) {
-      if (dlsch1_harq->Qm == 2) {
-        dlsch_64qam_qpsk_llr(frame_parms,
-                             pdsch_vars[eNB_id]->rxdataF_comp0,
-                             rxdataF_comp_ptr,//i
-                             pdsch_vars[eNB_id]->dl_ch_mag0,
-                             pdsch_vars[eNB_id]->dl_ch_rho2_ext,
-                             pdsch_vars[eNB_id]->llr[0],
-                             symbol,first_symbol_flag,nb_rb,
-                             adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,subframe,symbol),
-                             pdsch_vars[eNB_id]->llr128);
-        if (rx_type==rx_IC_dual_stream) {
-          dlsch_qpsk_64qam_llr(frame_parms,
-                               rxdataF_comp_ptr,
-                               pdsch_vars[eNB_id]->rxdataF_comp0,//i
+
+      break;
+
+    case 6 :
+      if ((rx_type==rx_standard) || (codeword_TB1 == -1))  {
+        dlsch_64qam_llr(frame_parms,
+                        pdsch_vars[eNB_id]->rxdataF_comp0,
+                        (int16_t *)pllr_symbol_cw0,
+                        pdsch_vars[eNB_id]->dl_ch_mag0,
+                        pdsch_vars[eNB_id]->dl_ch_magb0,
+                        symbol,first_symbol_flag,nb_rb,
+                        adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,subframe,symbol),
+                        pdsch_vars[eNB_id]->llr_offset[symbol],
+                        beamforming_mode);
+      } else if (codeword_TB0 == -1) {
+        dlsch_64qam_llr(frame_parms,
+                        pdsch_vars[eNB_id]->rxdataF_comp0,
+                        (int16_t *)pllr_symbol_cw1,
+                        pdsch_vars[eNB_id]->dl_ch_mag0,
+                        pdsch_vars[eNB_id]->dl_ch_magb0,
+                        symbol,first_symbol_flag,nb_rb,
+                        adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,subframe,symbol),
+                        pdsch_vars[eNB_id]->llr_offset[symbol],
+                        beamforming_mode);
+      } else if (rx_type >= rx_IC_single_stream) {
+        if (dlsch1_harq->Qm == 2) {
+          dlsch_64qam_qpsk_llr(frame_parms,
+                               pdsch_vars[eNB_id]->rxdataF_comp0,
+                               rxdataF_comp_ptr,//i
                                pdsch_vars[eNB_id]->dl_ch_mag0,
-                               pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
-                               pdsch_vars[eNB_id]->llr[1],
+                               pdsch_vars[eNB_id]->dl_ch_rho2_ext,
+                               pdsch_vars[eNB_id]->llr[0],
                                symbol,first_symbol_flag,nb_rb,
-                               adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,2,subframe,symbol),
-                               pdsch_vars[eNB_id]->llr128_2ndstream);
-        }
-      }
-      else if (dlsch1_harq->Qm == 4) {
-        dlsch_64qam_16qam_llr(frame_parms,
-                              pdsch_vars[eNB_id]->rxdataF_comp0,
-                              rxdataF_comp_ptr,//i
-                              pdsch_vars[eNB_id]->dl_ch_mag0,
-                              dl_ch_mag_ptr,//i
-                              pdsch_vars[eNB_id]->dl_ch_rho2_ext,
-                              pdsch_vars[eNB_id]->llr[0],
-                              symbol,first_symbol_flag,nb_rb,
-                              adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,subframe,symbol),
-                              pdsch_vars[eNB_id]->llr128);
-        if (rx_type==rx_IC_dual_stream) {
-          dlsch_16qam_64qam_llr(frame_parms,
-                                rxdataF_comp_ptr,
-                                pdsch_vars[eNB_id]->rxdataF_comp0,//i
-                                dl_ch_mag_ptr,
-                                pdsch_vars[eNB_id]->dl_ch_mag0,//i
-                                pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
-                                pdsch_vars[eNB_id]->llr[1],
+                               adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,subframe,symbol),
+                               pdsch_vars[eNB_id]->llr128);
+
+          if (rx_type==rx_IC_dual_stream) {
+            dlsch_qpsk_64qam_llr(frame_parms,
+                                 rxdataF_comp_ptr,
+                                 pdsch_vars[eNB_id]->rxdataF_comp0,//i
+                                 pdsch_vars[eNB_id]->dl_ch_mag0,
+                                 pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
+                                 pdsch_vars[eNB_id]->llr[1],
+                                 symbol,first_symbol_flag,nb_rb,
+                                 adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,2,subframe,symbol),
+                                 pdsch_vars[eNB_id]->llr128_2ndstream);
+          }
+        } else if (dlsch1_harq->Qm == 4) {
+          dlsch_64qam_16qam_llr(frame_parms,
+                                pdsch_vars[eNB_id]->rxdataF_comp0,
+                                rxdataF_comp_ptr,//i
+                                pdsch_vars[eNB_id]->dl_ch_mag0,
+                                dl_ch_mag_ptr,//i
+                                pdsch_vars[eNB_id]->dl_ch_rho2_ext,
+                                pdsch_vars[eNB_id]->llr[0],
                                 symbol,first_symbol_flag,nb_rb,
-                                adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,4,subframe,symbol),
-                                pdsch_vars[eNB_id]->llr128_2ndstream);
-        }
-      }
-      else {
-        dlsch_64qam_64qam_llr(frame_parms,
-                              pdsch_vars[eNB_id]->rxdataF_comp0,
-                              rxdataF_comp_ptr,//i
-                              pdsch_vars[eNB_id]->dl_ch_mag0,
-                              dl_ch_mag_ptr,//i
-                              pdsch_vars[eNB_id]->dl_ch_rho2_ext,
-                              (int16_t*)pllr_symbol_cw0,
-                              symbol,first_symbol_flag,nb_rb,
-                              adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,subframe,symbol),
-                              pdsch_vars[eNB_id]->llr_offset[symbol]);
-        if (rx_type==rx_IC_dual_stream) {
+                                adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,subframe,symbol),
+                                pdsch_vars[eNB_id]->llr128);
+
+          if (rx_type==rx_IC_dual_stream) {
+            dlsch_16qam_64qam_llr(frame_parms,
+                                  rxdataF_comp_ptr,
+                                  pdsch_vars[eNB_id]->rxdataF_comp0,//i
+                                  dl_ch_mag_ptr,
+                                  pdsch_vars[eNB_id]->dl_ch_mag0,//i
+                                  pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
+                                  pdsch_vars[eNB_id]->llr[1],
+                                  symbol,first_symbol_flag,nb_rb,
+                                  adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,4,subframe,symbol),
+                                  pdsch_vars[eNB_id]->llr128_2ndstream);
+          }
+        } else {
           dlsch_64qam_64qam_llr(frame_parms,
-                                rxdataF_comp_ptr,
-                                pdsch_vars[eNB_id]->rxdataF_comp0,//i
-                                dl_ch_mag_ptr,
-                                pdsch_vars[eNB_id]->dl_ch_mag0,//i
-                                pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
-                                (int16_t*)pllr_symbol_cw1,
+                                pdsch_vars[eNB_id]->rxdataF_comp0,
+                                rxdataF_comp_ptr,//i
+                                pdsch_vars[eNB_id]->dl_ch_mag0,
+                                dl_ch_mag_ptr,//i
+                                pdsch_vars[eNB_id]->dl_ch_rho2_ext,
+                                (int16_t *)pllr_symbol_cw0,
                                 symbol,first_symbol_flag,nb_rb,
-                                adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,6,subframe,symbol),
+                                adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,subframe,symbol),
                                 pdsch_vars[eNB_id]->llr_offset[symbol]);
+
+          if (rx_type==rx_IC_dual_stream) {
+            dlsch_64qam_64qam_llr(frame_parms,
+                                  rxdataF_comp_ptr,
+                                  pdsch_vars[eNB_id]->rxdataF_comp0,//i
+                                  dl_ch_mag_ptr,
+                                  pdsch_vars[eNB_id]->dl_ch_mag0,//i
+                                  pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
+                                  (int16_t *)pllr_symbol_cw1,
+                                  symbol,first_symbol_flag,nb_rb,
+                                  adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,6,subframe,symbol),
+                                  pdsch_vars[eNB_id]->llr_offset[symbol]);
+          }
         }
       }
-    }
-    break;
-  default:
-    LOG_W(PHY,"rx_dlsch.c : Unknown mod_order!!!!\n");
-    return(-1);
-    break;
+
+      break;
+
+    default:
+      LOG_W(PHY,"rx_dlsch.c : Unknown mod_order!!!!\n");
+      return(-1);
+      break;
   }
+
   if (dlsch1_harq) {
-  switch (get_Qm(dlsch1_harq->mcs)) {
-  case 2 :
-    if (rx_type==rx_standard) {
-        dlsch_qpsk_llr(frame_parms,
-                       pdsch_vars[eNB_id]->rxdataF_comp0,
-                       (int16_t*)pllr_symbol_cw0,
-                       symbol,first_symbol_flag,nb_rb,
-                       adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol),
-                       beamforming_mode);
-    }
-    break;
-  case 4:
-    if (rx_type==rx_standard) {
-      dlsch_16qam_llr(frame_parms,
-                      pdsch_vars[eNB_id]->rxdataF_comp0,
-                      pdsch_vars[eNB_id]->llr[0],
-                      pdsch_vars[eNB_id]->dl_ch_mag0,
-                      symbol,first_symbol_flag,nb_rb,
-                      adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol),
-                      pdsch_vars[eNB_id]->llr128,
-                      beamforming_mode);
+    switch (get_Qm(dlsch1_harq->mcs)) {
+      case 2 :
+        if (rx_type==rx_standard) {
+          dlsch_qpsk_llr(frame_parms,
+                         pdsch_vars[eNB_id]->rxdataF_comp0,
+                         (int16_t *)pllr_symbol_cw0,
+                         symbol,first_symbol_flag,nb_rb,
+                         adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol),
+                         beamforming_mode);
+        }
+
+        break;
+
+      case 4:
+        if (rx_type==rx_standard) {
+          dlsch_16qam_llr(frame_parms,
+                          pdsch_vars[eNB_id]->rxdataF_comp0,
+                          pdsch_vars[eNB_id]->llr[0],
+                          pdsch_vars[eNB_id]->dl_ch_mag0,
+                          symbol,first_symbol_flag,nb_rb,
+                          adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol),
+                          pdsch_vars[eNB_id]->llr128,
+                          beamforming_mode);
+        }
+
+        break;
+
+      case 6 :
+        if (rx_type==rx_standard) {
+          dlsch_64qam_llr(frame_parms,
+                          pdsch_vars[eNB_id]->rxdataF_comp0,
+                          (int16_t *)pllr_symbol_cw0,
+                          pdsch_vars[eNB_id]->dl_ch_mag0,
+                          pdsch_vars[eNB_id]->dl_ch_magb0,
+                          symbol,first_symbol_flag,nb_rb,
+                          adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,subframe,symbol),
+                          pdsch_vars[eNB_id]->llr_offset[symbol],
+                          beamforming_mode);
+        }
+
+        break;
+
+      default:
+        LOG_W(PHY,"rx_dlsch.c : Unknown mod_order!!!!\n");
+        return(-1);
+        break;
     }
-    break;
-  case 6 :
-    if (rx_type==rx_standard) {
-      dlsch_64qam_llr(frame_parms,
-                      pdsch_vars[eNB_id]->rxdataF_comp0,
-                      (int16_t*)pllr_symbol_cw0,
-                      pdsch_vars[eNB_id]->dl_ch_mag0,
-                      pdsch_vars[eNB_id]->dl_ch_magb0,
-                      symbol,first_symbol_flag,nb_rb,
-                      adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,subframe,symbol),
-                      pdsch_vars[eNB_id]->llr_offset[symbol],
-                      beamforming_mode);
-  }
-    break;
-  default:
-    LOG_W(PHY,"rx_dlsch.c : Unknown mod_order!!!!\n");
-    return(-1);
-    break;
-  }
   }
 
 #if UE_TIMING_TRACE
-    stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
+  stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
 #if DISABLE_LOG_X
-    printf("[AbsSFN %d.%d] Slot%d Symbol %d: LLR Computation %5.2f \n",frame,subframe,slot,symbol,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0));
+  printf("[AbsSFN %d.%d] Slot%d Symbol %d: LLR Computation %5.2f \n",frame,subframe,slot,symbol,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0));
 #else
-    LOG_D(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d: LLR Computation  %5.2f \n",frame,subframe,slot,symbol,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0));
+  LOG_D(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d: LLR Computation  %5.2f \n",frame,subframe,slot,symbol,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0));
 #endif
 #endif
-
-    // Please keep it: useful for debugging
+  // Please keep it: useful for debugging
 #if 0
-  if( (symbol == 13) && (subframe==0) && (dlsch0_harq->Qm == 6) /*&& (nb_rb==25)*/)
-  {
-      LOG_E(PHY,"Dump Phy Chan Est \n");
-      if(1)
-      {
+
+  if( (symbol == 13) && (subframe==0) && (dlsch0_harq->Qm == 6) /*&& (nb_rb==25)*/) {
+    LOG_E(PHY,"Dump Phy Chan Est \n");
+
+    if(1) {
 #if 1
       LOG_M("rxdataF0.m"    , "rxdataF0",             &common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].rxdataF[0][0],14*frame_parms->ofdm_symbol_size,1,1);
       //LOG_M("rxdataF1.m"    , "rxdataF1",             &common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].rxdataF[0][0],14*frame_parms->ofdm_symbol_size,1,1);
@@ -1240,8 +1230,6 @@ int rx_pdsch(PHY_VARS_UE *ue,
       //LOG_M("dl_ch_estimates01.m", "dl_ch_estimates01",   &common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].dl_ch_estimates[eNB_id][1][0],14*frame_parms->ofdm_symbol_size,1,1);
       //LOG_M("dl_ch_estimates10.m", "dl_ch_estimates10",   &common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].dl_ch_estimates[eNB_id][2][0],14*frame_parms->ofdm_symbol_size,1,1);
       //LOG_M("dl_ch_estimates11.m", "dl_ch_estimates11",   &common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].dl_ch_estimates[eNB_id][3][0],14*frame_parms->ofdm_symbol_size,1,1);
-
-
       //LOG_M("rxdataF_ext00.m"    , "rxdataF_ext00",       &pdsch_vars[eNB_id]->rxdataF_ext[0][0],14*frame_parms->N_RB_DL*12,1,1);
       //LOG_M("rxdataF_ext01.m"    , "rxdataF_ext01",       &pdsch_vars[eNB_id]->rxdataF_ext[1][0],14*frame_parms->N_RB_DL*12,1,1);
       //LOG_M("rxdataF_ext10.m"    , "rxdataF_ext10",       &pdsch_vars[eNB_id]->rxdataF_ext[2][0],14*frame_parms->N_RB_DL*12,1,1);
@@ -1257,20 +1245,16 @@ int rx_pdsch(PHY_VARS_UE *ue,
 #endif
       LOG_M("llr0.m","llr0",  &pdsch_vars[eNB_id]->llr[0][0],(14*nb_rb*12*dlsch1_harq->Qm) - 4*(nb_rb*4*dlsch1_harq->Qm),1,0);
       //LOG_M("llr1.m","llr1",  &pdsch_vars[eNB_id]->llr[1][0],(14*nb_rb*12*dlsch1_harq->Qm) - 4*(nb_rb*4*dlsch1_harq->Qm),1,0);
-
-
       AssertFatal(0," ");
-      }
-
+    }
   }
-#endif
 
+#endif
   T(T_UE_PHY_PDSCH_IQ, T_INT(eNB_id), T_INT(frame%1024),
     T_INT(subframe), T_INT(nb_rb),
     T_INT(frame_parms->N_RB_UL), T_INT(frame_parms->symbols_per_tti),
     T_BUFFER(&pdsch_vars[eNB_id]->rxdataF_comp0[eNB_id][0],
              2 * /* ulsch[UE_id]->harq_processes[harq_pid]->nb_rb */ frame_parms->N_RB_UL *12*frame_parms->symbols_per_tti*2));
-
   return 0;
 }
 
@@ -1290,20 +1274,15 @@ void dlsch_channel_compensation(int **rxdataF_ext,
                                 unsigned char mod_order,
                                 unsigned short nb_rb,
                                 unsigned char output_shift,
-                                PHY_MEASUREMENTS *measurements)
-{
-
+                                PHY_MEASUREMENTS *measurements) {
 #if defined(__i386) || defined(__x86_64)
-
   unsigned short rb;
   unsigned char aatx,aarx,symbol_mod,pilots=0;
   __m128i *dl_ch128,*dl_ch128_2,*dl_ch_mag128,*dl_ch_mag128b,*rxdataF128,*rxdataF_comp128,*rho128;
-  __m128i mmtmpD0,mmtmpD1,mmtmpD2,mmtmpD3,QAM_amp128,QAM_amp128b;
-
+  __m128i mmtmpD0,mmtmpD1,mmtmpD2,mmtmpD3,QAM_amp128;
   symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol;
 
   if ((symbol_mod == 0) || (symbol_mod == (4-frame_parms->Ncp))) {
-
     if (frame_parms->nb_antenna_ports_eNB==1) // 10 out of 12 so don't reduce size
       nb_rb=1+(5*nb_rb/6);
     else
@@ -1311,9 +1290,10 @@ void dlsch_channel_compensation(int **rxdataF_ext,
   }
 
   for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++) {
+    __m128i QAM_amp128b = _mm_setzero_si128();
+
     if (mod_order == 4) {
       QAM_amp128 = _mm_set1_epi16(QAM16_n1);  // 2/sqrt(10)
-      QAM_amp128b = _mm_setzero_si128();
     } else if (mod_order == 6) {
       QAM_amp128  = _mm_set1_epi16(QAM64_n1); //
       QAM_amp128b = _mm_set1_epi16(QAM64_n2);
@@ -1335,17 +1315,12 @@ void dlsch_channel_compensation(int **rxdataF_ext,
       for (rb=0; rb<nb_rb; rb++) {
         if (mod_order>2) {
           // get channel amplitude if not QPSK
-
           mmtmpD0 = _mm_madd_epi16(dl_ch128[0],dl_ch128[0]);
           mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
-
           mmtmpD1 = _mm_madd_epi16(dl_ch128[1],dl_ch128[1]);
           mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift);
-
           mmtmpD0 = _mm_packs_epi32(mmtmpD0,mmtmpD1);
-
           // store channel magnitude here in a new field of dlsch
-
           dl_ch_mag128[0] = _mm_unpacklo_epi16(mmtmpD0,mmtmpD0);
           dl_ch_mag128b[0] = dl_ch_mag128[0];
           dl_ch_mag128[0] = _mm_mulhi_epi16(dl_ch_mag128[0],QAM_amp128);
@@ -1362,18 +1337,14 @@ void dlsch_channel_compensation(int **rxdataF_ext,
             mmtmpD0 = _mm_madd_epi16(dl_ch128[2],dl_ch128[2]);
             mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
             mmtmpD1 = _mm_packs_epi32(mmtmpD0,mmtmpD0);
-
             dl_ch_mag128[2] = _mm_unpacklo_epi16(mmtmpD1,mmtmpD1);
             dl_ch_mag128b[2] = dl_ch_mag128[2];
-
             dl_ch_mag128[2] = _mm_mulhi_epi16(dl_ch_mag128[2],QAM_amp128);
             dl_ch_mag128[2] = _mm_slli_epi16(dl_ch_mag128[2],1);
           }
 
           dl_ch_mag128b[0] = _mm_mulhi_epi16(dl_ch_mag128b[0],QAM_amp128b);
           dl_ch_mag128b[0] = _mm_slli_epi16(dl_ch_mag128b[0],1);
-
-
           dl_ch_mag128b[1] = _mm_mulhi_epi16(dl_ch_mag128b[1],QAM_amp128b);
           dl_ch_mag128b[1] = _mm_slli_epi16(dl_ch_mag128b[1],1);
 
@@ -1385,11 +1356,10 @@ void dlsch_channel_compensation(int **rxdataF_ext,
 
         // multiply by conjugated channel
         mmtmpD0 = _mm_madd_epi16(dl_ch128[0],rxdataF128[0]);
-
         // mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
         mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[0],_MM_SHUFFLE(2,3,0,1));
         mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
-        mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)&conjugate[0]);
+        mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)&conjugate[0]);
         //  print_ints("im",&mmtmpD1);
         mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[0]);
         // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
@@ -1405,20 +1375,18 @@ void dlsch_channel_compensation(int **rxdataF_ext,
         //  print_shorts("rx:",rxdataF128);
         //  print_shorts("ch:",dl_ch128);
         //  print_shorts("pack:",rxdataF_comp128);
-
         // multiply by conjugated channel
         mmtmpD0 = _mm_madd_epi16(dl_ch128[1],rxdataF128[1]);
         // mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
         mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[1],_MM_SHUFFLE(2,3,0,1));
         mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
-        mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate);
+        mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)conjugate);
         mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[1]);
         // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
         mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
         mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift);
         mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1);
         mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1);
-
         rxdataF_comp128[1] = _mm_packs_epi32(mmtmpD2,mmtmpD3);
         //  print_shorts("rx:",rxdataF128+1);
         //  print_shorts("ch:",dl_ch128+1);
@@ -1430,19 +1398,17 @@ void dlsch_channel_compensation(int **rxdataF_ext,
           // mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
           mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[2],_MM_SHUFFLE(2,3,0,1));
           mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
-          mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate);
+          mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)conjugate);
           mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[2]);
           // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
           mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
           mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift);
           mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1);
           mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1);
-
           rxdataF_comp128[2] = _mm_packs_epi32(mmtmpD2,mmtmpD3);
           //  print_shorts("rx:",rxdataF128+2);
           //  print_shorts("ch:",dl_ch128+2);
-               // print_shorts("pack:",rxdataF_comp128+2);
-
+          // print_shorts("pack:",rxdataF_comp128+2);
           dl_ch128+=3;
           dl_ch_mag128+=3;
           dl_ch_mag128b+=3;
@@ -1455,14 +1421,11 @@ void dlsch_channel_compensation(int **rxdataF_ext,
           rxdataF128+=2;
           rxdataF_comp128+=2;
         }
-
       }
     }
   }
 
   if (rho) {
-
-
     for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
       rho128        = (__m128i *)&rho[aarx][symbol*frame_parms->N_RB_DL*12];
       dl_ch128      = (__m128i *)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12];
@@ -1472,11 +1435,10 @@ void dlsch_channel_compensation(int **rxdataF_ext,
         // multiply by conjugated channel
         mmtmpD0 = _mm_madd_epi16(dl_ch128[0],dl_ch128_2[0]);
         //  print_ints("re",&mmtmpD0);
-
         // mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
         mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[0],_MM_SHUFFLE(2,3,0,1));
         mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
-        mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)&conjugate[0]);
+        mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)&conjugate[0]);
         //  print_ints("im",&mmtmpD1);
         mmtmpD1 = _mm_madd_epi16(mmtmpD1,dl_ch128_2[0]);
         // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
@@ -1489,25 +1451,21 @@ void dlsch_channel_compensation(int **rxdataF_ext,
         //        print_ints("c0",&mmtmpD2);
         //  print_ints("c1",&mmtmpD3);
         rho128[0] = _mm_packs_epi32(mmtmpD2,mmtmpD3);
-
         //print_shorts("rx:",dl_ch128_2);
         //print_shorts("ch:",dl_ch128);
         //print_shorts("pack:",rho128);
-
         // multiply by conjugated channel
         mmtmpD0 = _mm_madd_epi16(dl_ch128[1],dl_ch128_2[1]);
         // mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
         mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[1],_MM_SHUFFLE(2,3,0,1));
         mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
-        mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate);
+        mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)conjugate);
         mmtmpD1 = _mm_madd_epi16(mmtmpD1,dl_ch128_2[1]);
         // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
         mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
         mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift);
         mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1);
         mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1);
-
-
         rho128[1] =_mm_packs_epi32(mmtmpD2,mmtmpD3);
         //print_shorts("rx:",dl_ch128_2+1);
         //print_shorts("ch:",dl_ch128+1);
@@ -1517,23 +1475,20 @@ void dlsch_channel_compensation(int **rxdataF_ext,
         // mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
         mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[2],_MM_SHUFFLE(2,3,0,1));
         mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
-        mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate);
+        mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)conjugate);
         mmtmpD1 = _mm_madd_epi16(mmtmpD1,dl_ch128_2[2]);
         // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
         mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
         mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift);
         mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1);
         mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1);
-
         rho128[2] = _mm_packs_epi32(mmtmpD2,mmtmpD3);
         //print_shorts("rx:",dl_ch128_2+2);
         //print_shorts("ch:",dl_ch128+2);
         //print_shorts("pack:",rho128+2);
-
         dl_ch128+=3;
         dl_ch128_2+=3;
         rho128+=3;
-
       }
 
       if (first_symbol_flag==1) {
@@ -1544,29 +1499,22 @@ void dlsch_channel_compensation(int **rxdataF_ext,
 
   _mm_empty();
   _m_empty();
-
 #elif defined(__arm__)
-
-
   unsigned short rb;
   unsigned char aatx,aarx,symbol_mod,pilots=0;
-
   int16x4_t *dl_ch128,*dl_ch128_2,*rxdataF128;
   int32x4_t mmtmpD0,mmtmpD1,mmtmpD0b,mmtmpD1b;
   int16x8_t *dl_ch_mag128,*dl_ch_mag128b,mmtmpD2,mmtmpD3,mmtmpD4;
   int16x8_t QAM_amp128,QAM_amp128b;
   int16x4x2_t *rxdataF_comp128,*rho128;
-
   int16_t conj[4]__attribute__((aligned(16))) = {1,-1,1,-1};
   int32x4_t output_shift128 = vmovq_n_s32(-(int32_t)output_shift);
-
   symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol;
 
   if ((symbol_mod == 0) || (symbol_mod == (4-frame_parms->Ncp))) {
     if (frame_parms->nb_antenna_ports_eNB==1) { // 10 out of 12 so don't reduce size
       nb_rb=1+(5*nb_rb/6);
-    }
-    else {
+    } else {
       pilots=1;
     }
   }
@@ -1579,171 +1527,160 @@ void dlsch_channel_compensation(int **rxdataF_ext,
       QAM_amp128  = vmovq_n_s16(QAM64_n1); //
       QAM_amp128b = vmovq_n_s16(QAM64_n2);
     }
+
     //    printf("comp: rxdataF_comp %p, symbol %d\n",rxdataF_comp[0],symbol);
 
     for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
-      dl_ch128          = (int16x4_t*)&dl_ch_estimates_ext[aatx*frame_parms->nb_antennas_rx + aarx][symbol*frame_parms->N_RB_DL*12];
-      dl_ch_mag128      = (int16x8_t*)&dl_ch_mag[aatx*frame_parms->nb_antennas_rx + aarx][symbol*frame_parms->N_RB_DL*12];
-      dl_ch_mag128b     = (int16x8_t*)&dl_ch_magb[aatx*frame_parms->nb_antennas_rx + aarx][symbol*frame_parms->N_RB_DL*12];
-      rxdataF128        = (int16x4_t*)&rxdataF_ext[aarx][symbol*frame_parms->N_RB_DL*12];
-      rxdataF_comp128   = (int16x4x2_t*)&rxdataF_comp[aatx*frame_parms->nb_antennas_rx + aarx][symbol*frame_parms->N_RB_DL*12];
+      dl_ch128          = (int16x4_t *)&dl_ch_estimates_ext[aatx*frame_parms->nb_antennas_rx + aarx][symbol*frame_parms->N_RB_DL*12];
+      dl_ch_mag128      = (int16x8_t *)&dl_ch_mag[aatx*frame_parms->nb_antennas_rx + aarx][symbol*frame_parms->N_RB_DL*12];
+      dl_ch_mag128b     = (int16x8_t *)&dl_ch_magb[aatx*frame_parms->nb_antennas_rx + aarx][symbol*frame_parms->N_RB_DL*12];
+      rxdataF128        = (int16x4_t *)&rxdataF_ext[aarx][symbol*frame_parms->N_RB_DL*12];
+      rxdataF_comp128   = (int16x4x2_t *)&rxdataF_comp[aatx*frame_parms->nb_antennas_rx + aarx][symbol*frame_parms->N_RB_DL*12];
 
       for (rb=0; rb<nb_rb; rb++) {
-  if (mod_order>2) {
-    // get channel amplitude if not QPSK
-    mmtmpD0 = vmull_s16(dl_ch128[0], dl_ch128[0]);
-    // mmtmpD0 = [ch0*ch0,ch1*ch1,ch2*ch2,ch3*ch3];
-    mmtmpD0 = vqshlq_s32(vqaddq_s32(mmtmpD0,vrev64q_s32(mmtmpD0)),output_shift128);
-    // mmtmpD0 = [ch0*ch0 + ch1*ch1,ch0*ch0 + ch1*ch1,ch2*ch2 + ch3*ch3,ch2*ch2 + ch3*ch3]>>output_shift128 on 32-bits
-    mmtmpD1 = vmull_s16(dl_ch128[1], dl_ch128[1]);
-    mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1,vrev64q_s32(mmtmpD1)),output_shift128);
-    mmtmpD2 = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
-    // mmtmpD2 = [ch0*ch0 + ch1*ch1,ch0*ch0 + ch1*ch1,ch2*ch2 + ch3*ch3,ch2*ch2 + ch3*ch3,ch4*ch4 + ch5*ch5,ch4*ch4 + ch5*ch5,ch6*ch6 + ch7*ch7,ch6*ch6 + ch7*ch7]>>output_shift128 on 16-bits
-    mmtmpD0 = vmull_s16(dl_ch128[2], dl_ch128[2]);
-    mmtmpD0 = vqshlq_s32(vqaddq_s32(mmtmpD0,vrev64q_s32(mmtmpD0)),output_shift128);
-    mmtmpD1 = vmull_s16(dl_ch128[3], dl_ch128[3]);
-    mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1,vrev64q_s32(mmtmpD1)),output_shift128);
-    mmtmpD3 = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
-    if (pilots==0) {
-      mmtmpD0 = vmull_s16(dl_ch128[4], dl_ch128[4]);
-      mmtmpD0 = vqshlq_s32(vqaddq_s32(mmtmpD0,vrev64q_s32(mmtmpD0)),output_shift128);
-      mmtmpD1 = vmull_s16(dl_ch128[5], dl_ch128[5]);
-      mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1,vrev64q_s32(mmtmpD1)),output_shift128);
-      mmtmpD4 = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
-    }
+        if (mod_order>2) {
+          // get channel amplitude if not QPSK
+          mmtmpD0 = vmull_s16(dl_ch128[0], dl_ch128[0]);
+          // mmtmpD0 = [ch0*ch0,ch1*ch1,ch2*ch2,ch3*ch3];
+          mmtmpD0 = vqshlq_s32(vqaddq_s32(mmtmpD0,vrev64q_s32(mmtmpD0)),output_shift128);
+          // mmtmpD0 = [ch0*ch0 + ch1*ch1,ch0*ch0 + ch1*ch1,ch2*ch2 + ch3*ch3,ch2*ch2 + ch3*ch3]>>output_shift128 on 32-bits
+          mmtmpD1 = vmull_s16(dl_ch128[1], dl_ch128[1]);
+          mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1,vrev64q_s32(mmtmpD1)),output_shift128);
+          mmtmpD2 = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
+          // mmtmpD2 = [ch0*ch0 + ch1*ch1,ch0*ch0 + ch1*ch1,ch2*ch2 + ch3*ch3,ch2*ch2 + ch3*ch3,ch4*ch4 + ch5*ch5,ch4*ch4 + ch5*ch5,ch6*ch6 + ch7*ch7,ch6*ch6 + ch7*ch7]>>output_shift128 on 16-bits
+          mmtmpD0 = vmull_s16(dl_ch128[2], dl_ch128[2]);
+          mmtmpD0 = vqshlq_s32(vqaddq_s32(mmtmpD0,vrev64q_s32(mmtmpD0)),output_shift128);
+          mmtmpD1 = vmull_s16(dl_ch128[3], dl_ch128[3]);
+          mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1,vrev64q_s32(mmtmpD1)),output_shift128);
+          mmtmpD3 = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
 
-    dl_ch_mag128b[0] = vqdmulhq_s16(mmtmpD2,QAM_amp128b);
-    dl_ch_mag128b[1] = vqdmulhq_s16(mmtmpD3,QAM_amp128b);
-    dl_ch_mag128[0] = vqdmulhq_s16(mmtmpD2,QAM_amp128);
-    dl_ch_mag128[1] = vqdmulhq_s16(mmtmpD3,QAM_amp128);
+          if (pilots==0) {
+            mmtmpD0 = vmull_s16(dl_ch128[4], dl_ch128[4]);
+            mmtmpD0 = vqshlq_s32(vqaddq_s32(mmtmpD0,vrev64q_s32(mmtmpD0)),output_shift128);
+            mmtmpD1 = vmull_s16(dl_ch128[5], dl_ch128[5]);
+            mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1,vrev64q_s32(mmtmpD1)),output_shift128);
+            mmtmpD4 = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
+          }
 
-    if (pilots==0) {
-      dl_ch_mag128b[2] = vqdmulhq_s16(mmtmpD4,QAM_amp128b);
-      dl_ch_mag128[2]  = vqdmulhq_s16(mmtmpD4,QAM_amp128);
-    }
-  }
+          dl_ch_mag128b[0] = vqdmulhq_s16(mmtmpD2,QAM_amp128b);
+          dl_ch_mag128b[1] = vqdmulhq_s16(mmtmpD3,QAM_amp128b);
+          dl_ch_mag128[0] = vqdmulhq_s16(mmtmpD2,QAM_amp128);
+          dl_ch_mag128[1] = vqdmulhq_s16(mmtmpD3,QAM_amp128);
 
-  mmtmpD0 = vmull_s16(dl_ch128[0], rxdataF128[0]);
-  //mmtmpD0 = [Re(ch[0])Re(rx[0]) Im(ch[0])Im(ch[0]) Re(ch[1])Re(rx[1]) Im(ch[1])Im(ch[1])]
-  mmtmpD1 = vmull_s16(dl_ch128[1], rxdataF128[1]);
-  //mmtmpD1 = [Re(ch[2])Re(rx[2]) Im(ch[2])Im(ch[2]) Re(ch[3])Re(rx[3]) Im(ch[3])Im(ch[3])]
-  mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)),
-             vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1)));
-  //mmtmpD0 = [Re(ch[0])Re(rx[0])+Im(ch[0])Im(ch[0]) Re(ch[1])Re(rx[1])+Im(ch[1])Im(ch[1]) Re(ch[2])Re(rx[2])+Im(ch[2])Im(ch[2]) Re(ch[3])Re(rx[3])+Im(ch[3])Im(ch[3])]
-
-  mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[0],*(int16x4_t*)conj)), rxdataF128[0]);
-  //mmtmpD0 = [-Im(ch[0])Re(rx[0]) Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1]) Re(ch[1])Im(rx[1])]
-  mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[1],*(int16x4_t*)conj)), rxdataF128[1]);
-  //mmtmpD0 = [-Im(ch[2])Re(rx[2]) Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3]) Re(ch[3])Im(rx[3])]
-  mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)),
-             vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b)));
-  //mmtmpD1 = [-Im(ch[0])Re(rx[0])+Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1])+Re(ch[1])Im(rx[1]) -Im(ch[2])Re(rx[2])+Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3])+Re(ch[3])Im(rx[3])]
-
-  mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128);
-  mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128);
-  rxdataF_comp128[0] = vzip_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
-  mmtmpD0 = vmull_s16(dl_ch128[2], rxdataF128[2]);
-  mmtmpD1 = vmull_s16(dl_ch128[3], rxdataF128[3]);
-  mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)),
-             vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1)));
-  mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[2],*(int16x4_t*)conj)), rxdataF128[2]);
-  mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[3],*(int16x4_t*)conj)), rxdataF128[3]);
-  mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)),
-             vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b)));
-  mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128);
-  mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128);
-  rxdataF_comp128[1] = vzip_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
-
-  if (pilots==0) {
-    mmtmpD0 = vmull_s16(dl_ch128[4], rxdataF128[4]);
-    mmtmpD1 = vmull_s16(dl_ch128[5], rxdataF128[5]);
-    mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)),
-         vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1)));
-
-    mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[4],*(int16x4_t*)conj)), rxdataF128[4]);
-    mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[5],*(int16x4_t*)conj)), rxdataF128[5]);
-    mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)),
-         vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b)));
-
-
-    mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128);
-    mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128);
-    rxdataF_comp128[2] = vzip_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
-
-
-    dl_ch128+=6;
-    dl_ch_mag128+=3;
-    dl_ch_mag128b+=3;
-    rxdataF128+=6;
-    rxdataF_comp128+=3;
-
-  } else { // we have a smaller PDSCH in symbols with pilots so skip last group of 4 REs and increment less
-    dl_ch128+=4;
-    dl_ch_mag128+=2;
-    dl_ch_mag128b+=2;
-    rxdataF128+=4;
-    rxdataF_comp128+=2;
-  }
+          if (pilots==0) {
+            dl_ch_mag128b[2] = vqdmulhq_s16(mmtmpD4,QAM_amp128b);
+            dl_ch_mag128[2]  = vqdmulhq_s16(mmtmpD4,QAM_amp128);
+          }
+        }
+
+        mmtmpD0 = vmull_s16(dl_ch128[0], rxdataF128[0]);
+        //mmtmpD0 = [Re(ch[0])Re(rx[0]) Im(ch[0])Im(ch[0]) Re(ch[1])Re(rx[1]) Im(ch[1])Im(ch[1])]
+        mmtmpD1 = vmull_s16(dl_ch128[1], rxdataF128[1]);
+        //mmtmpD1 = [Re(ch[2])Re(rx[2]) Im(ch[2])Im(ch[2]) Re(ch[3])Re(rx[3]) Im(ch[3])Im(ch[3])]
+        mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)),
+                               vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1)));
+        //mmtmpD0 = [Re(ch[0])Re(rx[0])+Im(ch[0])Im(ch[0]) Re(ch[1])Re(rx[1])+Im(ch[1])Im(ch[1]) Re(ch[2])Re(rx[2])+Im(ch[2])Im(ch[2]) Re(ch[3])Re(rx[3])+Im(ch[3])Im(ch[3])]
+        mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[0],*(int16x4_t *)conj)), rxdataF128[0]);
+        //mmtmpD0 = [-Im(ch[0])Re(rx[0]) Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1]) Re(ch[1])Im(rx[1])]
+        mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[1],*(int16x4_t *)conj)), rxdataF128[1]);
+        //mmtmpD0 = [-Im(ch[2])Re(rx[2]) Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3]) Re(ch[3])Im(rx[3])]
+        mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)),
+                               vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b)));
+        //mmtmpD1 = [-Im(ch[0])Re(rx[0])+Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1])+Re(ch[1])Im(rx[1]) -Im(ch[2])Re(rx[2])+Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3])+Re(ch[3])Im(rx[3])]
+        mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128);
+        mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128);
+        rxdataF_comp128[0] = vzip_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
+        mmtmpD0 = vmull_s16(dl_ch128[2], rxdataF128[2]);
+        mmtmpD1 = vmull_s16(dl_ch128[3], rxdataF128[3]);
+        mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)),
+                               vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1)));
+        mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[2],*(int16x4_t *)conj)), rxdataF128[2]);
+        mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[3],*(int16x4_t *)conj)), rxdataF128[3]);
+        mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)),
+                               vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b)));
+        mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128);
+        mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128);
+        rxdataF_comp128[1] = vzip_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
+
+        if (pilots==0) {
+          mmtmpD0 = vmull_s16(dl_ch128[4], rxdataF128[4]);
+          mmtmpD1 = vmull_s16(dl_ch128[5], rxdataF128[5]);
+          mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)),
+                                 vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1)));
+          mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[4],*(int16x4_t *)conj)), rxdataF128[4]);
+          mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[5],*(int16x4_t *)conj)), rxdataF128[5]);
+          mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)),
+                                 vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b)));
+          mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128);
+          mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128);
+          rxdataF_comp128[2] = vzip_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
+          dl_ch128+=6;
+          dl_ch_mag128+=3;
+          dl_ch_mag128b+=3;
+          rxdataF128+=6;
+          rxdataF_comp128+=3;
+        } else { // we have a smaller PDSCH in symbols with pilots so skip last group of 4 REs and increment less
+          dl_ch128+=4;
+          dl_ch_mag128+=2;
+          dl_ch_mag128b+=2;
+          rxdataF128+=4;
+          rxdataF_comp128+=2;
+        }
       }
     }
   }
 
   if (rho) {
     for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
-      rho128        = (int16x4x2_t*)&rho[aarx][symbol*frame_parms->N_RB_DL*12];
-      dl_ch128      = (int16x4_t*)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12];
-      dl_ch128_2    = (int16x4_t*)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12];
+      rho128        = (int16x4x2_t *)&rho[aarx][symbol*frame_parms->N_RB_DL*12];
+      dl_ch128      = (int16x4_t *)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12];
+      dl_ch128_2    = (int16x4_t *)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12];
+
       for (rb=0; rb<nb_rb; rb++) {
-  mmtmpD0 = vmull_s16(dl_ch128[0], dl_ch128_2[0]);
-  mmtmpD1 = vmull_s16(dl_ch128[1], dl_ch128_2[1]);
-  mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)),
-             vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1)));
-  mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[0],*(int16x4_t*)conj)), dl_ch128_2[0]);
-  mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[1],*(int16x4_t*)conj)), dl_ch128_2[1]);
-  mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)),
-             vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b)));
-
-  mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128);
-  mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128);
-  rho128[0] = vzip_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
-
-  mmtmpD0 = vmull_s16(dl_ch128[2], dl_ch128_2[2]);
-  mmtmpD1 = vmull_s16(dl_ch128[3], dl_ch128_2[3]);
-  mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)),
-             vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1)));
-  mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[2],*(int16x4_t*)conj)), dl_ch128_2[2]);
-  mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[3],*(int16x4_t*)conj)), dl_ch128_2[3]);
-  mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)),
-             vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b)));
-
-  mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128);
-  mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128);
-  rho128[1] = vzip_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
-
-  mmtmpD0 = vmull_s16(dl_ch128[0], dl_ch128_2[0]);
-  mmtmpD1 = vmull_s16(dl_ch128[1], dl_ch128_2[1]);
-  mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)),
-             vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1)));
-  mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[4],*(int16x4_t*)conj)), dl_ch128_2[4]);
-  mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[5],*(int16x4_t*)conj)), dl_ch128_2[5]);
-  mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)),
-             vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b)));
-
-  mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128);
-  mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128);
-  rho128[2] = vzip_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
-
-
-  dl_ch128+=6;
-  dl_ch128_2+=6;
-  rho128+=3;
+        mmtmpD0 = vmull_s16(dl_ch128[0], dl_ch128_2[0]);
+        mmtmpD1 = vmull_s16(dl_ch128[1], dl_ch128_2[1]);
+        mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)),
+                               vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1)));
+        mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[0],*(int16x4_t *)conj)), dl_ch128_2[0]);
+        mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[1],*(int16x4_t *)conj)), dl_ch128_2[1]);
+        mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)),
+                               vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b)));
+        mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128);
+        mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128);
+        rho128[0] = vzip_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
+        mmtmpD0 = vmull_s16(dl_ch128[2], dl_ch128_2[2]);
+        mmtmpD1 = vmull_s16(dl_ch128[3], dl_ch128_2[3]);
+        mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)),
+                               vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1)));
+        mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[2],*(int16x4_t *)conj)), dl_ch128_2[2]);
+        mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[3],*(int16x4_t *)conj)), dl_ch128_2[3]);
+        mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)),
+                               vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b)));
+        mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128);
+        mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128);
+        rho128[1] = vzip_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
+        mmtmpD0 = vmull_s16(dl_ch128[0], dl_ch128_2[0]);
+        mmtmpD1 = vmull_s16(dl_ch128[1], dl_ch128_2[1]);
+        mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)),
+                               vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1)));
+        mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[4],*(int16x4_t *)conj)), dl_ch128_2[4]);
+        mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[5],*(int16x4_t *)conj)), dl_ch128_2[5]);
+        mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)),
+                               vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b)));
+        mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128);
+        mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128);
+        rho128[2] = vzip_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
+        dl_ch128+=6;
+        dl_ch128_2+=6;
+        rho128+=3;
       }
 
       if (first_symbol_flag==1) {
-  measurements->rx_correlation[0][aarx] = signal_energy(&rho[aarx][symbol*frame_parms->N_RB_DL*12],rb*12);
+        measurements->rx_correlation[0][aarx] = signal_energy(&rho[aarx][symbol*frame_parms->N_RB_DL*12],rb*12);
       }
     }
   }
+
 #endif
 }
 
@@ -1761,15 +1698,15 @@ void dlsch_channel_compensation_core(int **rxdataF_ext,
                                      int start_point)
 
 {
-
   unsigned short ii;
   int length_mod8 = 0;
   int length2;
   __m128i *dl_ch128,*dl_ch_mag128,*dl_ch_mag128b, *dl_ch128_2, *rxdataF128,*rxdataF_comp128,*rho128;
-  __m128i mmtmpD0,mmtmpD1,mmtmpD2,mmtmpD3,QAM_amp128,QAM_amp128b;
+  __m128i mmtmpD0,mmtmpD1,mmtmpD2,mmtmpD3,QAM_amp128;
   int aatx = 0, aarx = 0;
 
   for (aatx=0; aatx<n_tx; aatx++) {
+    __m128i QAM_amp128b;
 
     if (mod_order == 4) {
       QAM_amp128 = _mm_set1_epi16(QAM16_n1);  // 2/sqrt(10)
@@ -1785,31 +1722,25 @@ void dlsch_channel_compensation_core(int **rxdataF_ext,
        * Elena's commit.
        */
       int x = n_rx > 1 ? n_rx : 2;
-
-    dl_ch128          = (__m128i *)&dl_ch_estimates_ext[aatx*x + aarx][start_point];
-    dl_ch_mag128      = (__m128i *)&dl_ch_mag[aatx*x + aarx][start_point];
-    dl_ch_mag128b     = (__m128i *)&dl_ch_magb[aatx*x + aarx][start_point];
-    rxdataF128        = (__m128i *)&rxdataF_ext[aarx][start_point];
-    rxdataF_comp128   = (__m128i *)&rxdataF_comp[aatx*x + aarx][start_point];
-
+      dl_ch128          = (__m128i *)&dl_ch_estimates_ext[aatx*x + aarx][start_point];
+      dl_ch_mag128      = (__m128i *)&dl_ch_mag[aatx*x + aarx][start_point];
+      dl_ch_mag128b     = (__m128i *)&dl_ch_magb[aatx*x + aarx][start_point];
+      rxdataF128        = (__m128i *)&rxdataF_ext[aarx][start_point];
+      rxdataF_comp128   = (__m128i *)&rxdataF_comp[aatx*x + aarx][start_point];
       length_mod8 = length&7;
-      if (length_mod8 == 0){
+
+      if (length_mod8 == 0) {
         length2 = length>>3;
 
         for (ii=0; ii<length2; ++ii) {
           if (mod_order>2) {
             // get channel amplitude if not QPSK
-
             mmtmpD0 = _mm_madd_epi16(dl_ch128[0],dl_ch128[0]);
             mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
-
             mmtmpD1 = _mm_madd_epi16(dl_ch128[1],dl_ch128[1]);
             mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift);
-
             mmtmpD0 = _mm_packs_epi32(mmtmpD0,mmtmpD1);
-
             // store channel magnitude here in a new field of dlsch
-
             dl_ch_mag128[0] = _mm_unpacklo_epi16(mmtmpD0,mmtmpD0);
             dl_ch_mag128b[0] = dl_ch_mag128[0];
             dl_ch_mag128[0] = _mm_mulhi_epi16(dl_ch_mag128[0],QAM_amp128);
@@ -1821,22 +1752,18 @@ void dlsch_channel_compensation_core(int **rxdataF_ext,
             dl_ch_mag128b[1] = dl_ch_mag128[1];
             dl_ch_mag128[1] = _mm_mulhi_epi16(dl_ch_mag128[1],QAM_amp128);
             dl_ch_mag128[1] = _mm_slli_epi16(dl_ch_mag128[1],1);
-
             dl_ch_mag128b[0] = _mm_mulhi_epi16(dl_ch_mag128b[0],QAM_amp128b);
             dl_ch_mag128b[0] = _mm_slli_epi16(dl_ch_mag128b[0],1);
-
             dl_ch_mag128b[1] = _mm_mulhi_epi16(dl_ch_mag128b[1],QAM_amp128b);
             dl_ch_mag128b[1] = _mm_slli_epi16(dl_ch_mag128b[1],1);
-
           }
 
           // multiply by conjugated channel
           mmtmpD0 = _mm_madd_epi16(dl_ch128[0],rxdataF128[0]);
-
           // mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
           mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[0],_MM_SHUFFLE(2,3,0,1));
           mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
-          mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)&conjugate[0]);
+          mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)&conjugate[0]);
           //  print_ints("im",&mmtmpD1);
           mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[0]);
           // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
@@ -1852,59 +1779,53 @@ void dlsch_channel_compensation_core(int **rxdataF_ext,
           //  print_shorts("rx:",rxdataF128);
           //  print_shorts("ch:",dl_ch128);
           //  print_shorts("pack:",rxdataF_comp128);
-
           // multiply by conjugated channel
           mmtmpD0 = _mm_madd_epi16(dl_ch128[1],rxdataF128[1]);
           // mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
           mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[1],_MM_SHUFFLE(2,3,0,1));
           mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
-          mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate);
+          mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)conjugate);
           mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[1]);
           // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
           mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
           mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift);
           mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1);
           mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1);
-
           rxdataF_comp128[1] = _mm_packs_epi32(mmtmpD2,mmtmpD3);
           //  print_shorts("rx:",rxdataF128+1);
           //  print_shorts("ch:",dl_ch128+1);
           //print_shorts("pack:",rxdataF_comp128+1);
-
           dl_ch128+=2;
           dl_ch_mag128+=2;
           dl_ch_mag128b+=2;
           rxdataF128+=2;
           rxdataF_comp128+=2;
         }
-      }else {
+      } else {
         printf ("Channel Compensation: Received number of subcarriers is not multiple of 8, \n"
-                 "need to adapt the code!\n");
+                "need to adapt the code!\n");
       }
     }
   }
 
-/*This part of code makes sense only for processing in 2x2 blocks*/
+  /*This part of code makes sense only for processing in 2x2 blocks*/
   if (rho) {
-
-
     for (aarx=0; aarx<n_rx; aarx++) {
       rho128        = (__m128i *)&rho[aarx][start_point];
       dl_ch128      = (__m128i *)&dl_ch_estimates_ext[aarx][start_point];
       dl_ch128_2    = (__m128i *)&dl_ch_estimates_ext[2+aarx][start_point];
 
-      if (length_mod8 == 0){
+      if (length_mod8 == 0) {
         length2 = length>>3;
 
         for (ii=0; ii<length2; ++ii) {
           // multiply by conjugated channel
           mmtmpD0 = _mm_madd_epi16(dl_ch128[0],dl_ch128_2[0]);
           //  print_ints("re",&mmtmpD0);
-
           // mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
           mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[0],_MM_SHUFFLE(2,3,0,1));
           mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
-          mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)&conjugate[0]);
+          mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)&conjugate[0]);
           //  print_ints("im",&mmtmpD1);
           mmtmpD1 = _mm_madd_epi16(mmtmpD1,dl_ch128_2[0]);
           // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
@@ -1917,124 +1838,115 @@ void dlsch_channel_compensation_core(int **rxdataF_ext,
           //        print_ints("c0",&mmtmpD2);
           //  print_ints("c1",&mmtmpD3);
           rho128[0] = _mm_packs_epi32(mmtmpD2,mmtmpD3);
-
           //print_shorts("rx:",dl_ch128_2);
           //print_shorts("ch:",dl_ch128);
           //print_shorts("pack:",rho128);
-
           // multiply by conjugated channel
           mmtmpD0 = _mm_madd_epi16(dl_ch128[1],dl_ch128_2[1]);
           // mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
           mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[1],_MM_SHUFFLE(2,3,0,1));
           mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
-          mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate);
+          mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)conjugate);
           mmtmpD1 = _mm_madd_epi16(mmtmpD1,dl_ch128_2[1]);
           // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
           mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
           mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift);
           mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1);
           mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1);
-
           rho128[1] =_mm_packs_epi32(mmtmpD2,mmtmpD3);
           dl_ch128+=2;
           dl_ch128_2+=2;
           rho128+=2;
         }
-      }else {
+      } else {
         printf ("Channel Compensation: Received number of subcarriers is not multiple of 8, \n"
-                 "need to adapt the code!\n");
+                "need to adapt the code!\n");
       }
     }
   }
+
   _mm_empty();
   _m_empty();
 }
 
 #if defined(__x86_64__) || defined(__i386__)
 
-void prec2A_TM56_128(unsigned char pmi,__m128i *ch0,__m128i *ch1)
-{
-
+void prec2A_TM56_128(unsigned char pmi,__m128i *ch0,__m128i *ch1) {
   __m128i amp;
   amp = _mm_set1_epi16(ONE_OVER_SQRT2_Q15);
 
   switch (pmi) {
-
-  case 0 :   // +1 +1
-    //    print_shorts("phase 0 :ch0",ch0);
-    //    print_shorts("phase 0 :ch1",ch1);
-    ch0[0] = _mm_adds_epi16(ch0[0],ch1[0]);
-    break;
-
-  case 1 :   // +1 -1
-    //    print_shorts("phase 1 :ch0",ch0);
-    //    print_shorts("phase 1 :ch1",ch1);
-    ch0[0] = _mm_subs_epi16(ch0[0],ch1[0]);
-    //    print_shorts("phase 1 :ch0-ch1",ch0);
-    break;
-
-  case 2 :   // +1 +j
-    ch1[0] = _mm_sign_epi16(ch1[0],*(__m128i*)&conjugate[0]);
-    ch1[0] = _mm_shufflelo_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1));
-    ch1[0] = _mm_shufflehi_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1));
-    ch0[0] = _mm_subs_epi16(ch0[0],ch1[0]);
-
-    break;   // +1 -j
-
-  case 3 :
-    ch1[0] = _mm_sign_epi16(ch1[0],*(__m128i*)&conjugate[0]);
-    ch1[0] = _mm_shufflelo_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1));
-    ch1[0] = _mm_shufflehi_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1));
-    ch0[0] = _mm_adds_epi16(ch0[0],ch1[0]);
-    break;
+    case 0 :   // +1 +1
+      //    print_shorts("phase 0 :ch0",ch0);
+      //    print_shorts("phase 0 :ch1",ch1);
+      ch0[0] = _mm_adds_epi16(ch0[0],ch1[0]);
+      break;
+
+    case 1 :   // +1 -1
+      //    print_shorts("phase 1 :ch0",ch0);
+      //    print_shorts("phase 1 :ch1",ch1);
+      ch0[0] = _mm_subs_epi16(ch0[0],ch1[0]);
+      //    print_shorts("phase 1 :ch0-ch1",ch0);
+      break;
+
+    case 2 :   // +1 +j
+      ch1[0] = _mm_sign_epi16(ch1[0],*(__m128i *)&conjugate[0]);
+      ch1[0] = _mm_shufflelo_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1));
+      ch1[0] = _mm_shufflehi_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1));
+      ch0[0] = _mm_subs_epi16(ch0[0],ch1[0]);
+      break;   // +1 -j
+
+    case 3 :
+      ch1[0] = _mm_sign_epi16(ch1[0],*(__m128i *)&conjugate[0]);
+      ch1[0] = _mm_shufflelo_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1));
+      ch1[0] = _mm_shufflehi_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1));
+      ch0[0] = _mm_adds_epi16(ch0[0],ch1[0]);
+      break;
   }
 
   ch0[0] = _mm_mulhi_epi16(ch0[0],amp);
   ch0[0] = _mm_slli_epi16(ch0[0],1);
-
   _mm_empty();
   _m_empty();
 }
 #elif defined(__arm__)
 void prec2A_TM56_128(unsigned char pmi,__m128i *ch0,__m128i *ch1) {
-
   // sqrt(2) is already taken into account in computation sqrt_rho_a, sqrt_rho_b,
   //so removed it
 
   //__m128i amp;
   //amp = _mm_set1_epi16(ONE_OVER_SQRT2_Q15);
-
   switch (pmi) {
-
-  case 0 :   // +1 +1
-    //    print_shorts("phase 0 :ch0",ch0);
-    //    print_shorts("phase 0 :ch1",ch1);
-    ch0[0] = _mm_adds_epi16(ch0[0],ch1[0]);
-    break;
-  case 1 :   // +1 -1
-    //    print_shorts("phase 1 :ch0",ch0);
-    //    print_shorts("phase 1 :ch1",ch1);
-    ch0[0] = _mm_subs_epi16(ch0[0],ch1[0]);
-    //    print_shorts("phase 1 :ch0-ch1",ch0);
-    break;
-  case 2 :   // +1 +j
-    ch1[0] = _mm_sign_epi16(ch1[0],*(__m128i*)&conjugate[0]);
-    ch1[0] = _mm_shufflelo_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1));
-    ch1[0] = _mm_shufflehi_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1));
-    ch0[0] = _mm_subs_epi16(ch0[0],ch1[0]);
-
-    break;   // +1 -j
-  case 3 :
-    ch1[0] = _mm_sign_epi16(ch1[0],*(__m128i*)&conjugate[0]);
-    ch1[0] = _mm_shufflelo_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1));
-    ch1[0] = _mm_shufflehi_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1));
-    ch0[0] = _mm_adds_epi16(ch0[0],ch1[0]);
-    break;
+    case 0 :   // +1 +1
+      //    print_shorts("phase 0 :ch0",ch0);
+      //    print_shorts("phase 0 :ch1",ch1);
+      ch0[0] = _mm_adds_epi16(ch0[0],ch1[0]);
+      break;
+
+    case 1 :   // +1 -1
+      //    print_shorts("phase 1 :ch0",ch0);
+      //    print_shorts("phase 1 :ch1",ch1);
+      ch0[0] = _mm_subs_epi16(ch0[0],ch1[0]);
+      //    print_shorts("phase 1 :ch0-ch1",ch0);
+      break;
+
+    case 2 :   // +1 +j
+      ch1[0] = _mm_sign_epi16(ch1[0],*(__m128i *)&conjugate[0]);
+      ch1[0] = _mm_shufflelo_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1));
+      ch1[0] = _mm_shufflehi_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1));
+      ch0[0] = _mm_subs_epi16(ch0[0],ch1[0]);
+      break;   // +1 -j
+
+    case 3 :
+      ch1[0] = _mm_sign_epi16(ch1[0],*(__m128i *)&conjugate[0]);
+      ch1[0] = _mm_shufflelo_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1));
+      ch1[0] = _mm_shufflehi_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1));
+      ch0[0] = _mm_adds_epi16(ch0[0],ch1[0]);
+      break;
   }
 
   //ch0[0] = _mm_mulhi_epi16(ch0[0],amp);
   //ch0[0] = _mm_slli_epi16(ch0[0],1);
-
   _mm_empty();
   _m_empty();
 }
@@ -2046,42 +1958,30 @@ void prec2A_TM56_128(unsigned char pmi,__m128i *ch0,__m128i *ch1) {
 short TM3_prec[8]__attribute__((aligned(16))) = {1,1,-1,-1,1,1,-1,-1} ;
 
 void prec2A_TM3_128(__m128i *ch0,__m128i *ch1) {
-
   __m128i amp = _mm_set1_epi16(ONE_OVER_SQRT2_Q15);
-
   __m128i tmp0,tmp1;
-
   //_mm_mulhi_epi16
   //  print_shorts("prec2A_TM3 ch0 (before):",ch0);
   //  print_shorts("prec2A_TM3 ch1 (before):",ch1);
-
   tmp0 = ch0[0];
-  tmp1  = _mm_sign_epi16(ch1[0],((__m128i*)&TM3_prec)[0]);
+  tmp1  = _mm_sign_epi16(ch1[0],((__m128i *)&TM3_prec)[0]);
   //  print_shorts("prec2A_TM3 ch1*s (mid):",(__m128i*)TM3_prec);
-
   ch0[0] = _mm_adds_epi16(ch0[0],tmp1);
   ch1[0] = _mm_subs_epi16(tmp0,tmp1);
-
   ch0[0] = _mm_mulhi_epi16(ch0[0],amp);
   ch0[0] = _mm_slli_epi16(ch0[0],1);
-
   ch1[0] = _mm_mulhi_epi16(ch1[0],amp);
   ch1[0] = _mm_slli_epi16(ch1[0],1);
-
   //  print_shorts("prec2A_TM3 ch0 (mid):",&tmp0);
   //  print_shorts("prec2A_TM3 ch1 (mid):",ch1);
-
   //ch0[0] = _mm_mulhi_epi16(ch0[0],amp);
   //ch0[0] = _mm_slli_epi16(ch0[0],1);
   //ch1[0] = _mm_mulhi_epi16(ch1[0],amp);
   //ch1[0] = _mm_slli_epi16(ch1[0],1);
-
   //ch0[0] = _mm_srai_epi16(ch0[0],1);
   //ch1[0] = _mm_srai_epi16(ch1[0],1);
-
   //  print_shorts("prec2A_TM3 ch0 (after):",ch0);
   //  print_shorts("prec2A_TM3 ch1 (after):",ch1);
-
   _mm_empty();
   _m_empty();
 }
@@ -2090,27 +1990,24 @@ void prec2A_TM3_128(__m128i *ch0,__m128i *ch1) {
 // pmi = 1 => stream 0 (1,j), stream 2 (1,-j)
 
 void prec2A_TM4_128(int pmi,__m128i *ch0,__m128i *ch1) {
-
-// sqrt(2) is already taken into account in computation sqrt_rho_a, sqrt_rho_b,
-//so divide by 2 is replaced by divide by sqrt(2).
-
- // printf ("demod pmi=%d\n", pmi);
- __m128i amp;
- amp = _mm_set1_epi16(ONE_OVER_SQRT2_Q15);
+  // sqrt(2) is already taken into account in computation sqrt_rho_a, sqrt_rho_b,
+  //so divide by 2 is replaced by divide by sqrt(2).
+  // printf ("demod pmi=%d\n", pmi);
+  __m128i amp;
+  amp = _mm_set1_epi16(ONE_OVER_SQRT2_Q15);
   __m128i tmp0,tmp1;
 
- // print_shorts("prec2A_TM4 ch0 (before):",ch0);
- // print_shorts("prec2A_TM4 ch1 (before):",ch1);
+  // print_shorts("prec2A_TM4 ch0 (before):",ch0);
+  // print_shorts("prec2A_TM4 ch1 (before):",ch1);
 
   if (pmi == 0) { //[1 1;1 -1]
     tmp0 = ch0[0];
     tmp1 = ch1[0];
     ch0[0] = _mm_adds_epi16(tmp0,tmp1);
     ch1[0] = _mm_subs_epi16(tmp0,tmp1);
-  }
-  else { //ch0+j*ch1 ch0-j*ch1
+  } else { //ch0+j*ch1 ch0-j*ch1
     tmp0 = ch0[0];
-    tmp1   = _mm_sign_epi16(ch1[0],*(__m128i*)&conjugate[0]);
+    tmp1   = _mm_sign_epi16(ch1[0],*(__m128i *)&conjugate[0]);
     tmp1   = _mm_shufflelo_epi16(tmp1,_MM_SHUFFLE(2,3,0,1));
     tmp1   = _mm_shufflehi_epi16(tmp1,_MM_SHUFFLE(2,3,0,1));
     ch0[0] = _mm_subs_epi16(tmp0,tmp1);
@@ -2119,20 +2016,17 @@ void prec2A_TM4_128(int pmi,__m128i *ch0,__m128i *ch1) {
 
   //print_shorts("prec2A_TM4 ch0 (middle):",ch0);
   //print_shorts("prec2A_TM4 ch1 (middle):",ch1);
-
   ch0[0] = _mm_mulhi_epi16(ch0[0],amp);
   ch0[0] = _mm_slli_epi16(ch0[0],1);
   ch1[0] = _mm_mulhi_epi16(ch1[0],amp);
   ch1[0] = _mm_slli_epi16(ch1[0],1);
-
-
- // ch0[0] = _mm_srai_epi16(ch0[0],1); //divide by 2
- // ch1[0] = _mm_srai_epi16(ch1[0],1); //divide by 2
+  // ch0[0] = _mm_srai_epi16(ch0[0],1); //divide by 2
+  // ch1[0] = _mm_srai_epi16(ch1[0],1); //divide by 2
   //print_shorts("prec2A_TM4 ch0 (end):",ch0);
   //print_shorts("prec2A_TM4 ch1 (end):",ch1);
   _mm_empty();
   _m_empty();
- // print_shorts("prec2A_TM4 ch0 (end):",ch0);
+  // print_shorts("prec2A_TM4 ch0 (end):",ch0);
   //print_shorts("prec2A_TM4 ch1 (end):",ch1);
 }
 
@@ -2149,45 +2043,36 @@ void dlsch_channel_compensation_TM56(int **rxdataF_ext,
                                      unsigned char mod_order,
                                      unsigned short nb_rb,
                                      unsigned char output_shift,
-                                     unsigned char dl_power_off)
-{
-
+                                     unsigned char dl_power_off) {
 #if defined(__x86_64__) || defined(__i386__)
-
   unsigned short rb,Nre;
   __m128i *dl_ch0_128,*dl_ch1_128,*dl_ch_mag128,*dl_ch_mag128b,*rxdataF128,*rxdataF_comp128;
   unsigned char aarx=0,symbol_mod,pilots=0;
   int precoded_signal_strength=0;
-  __m128i mmtmpD0,mmtmpD1,mmtmpD2,mmtmpD3,QAM_amp128,QAM_amp128b;
-
+  __m128i mmtmpD0,mmtmpD1,mmtmpD2,mmtmpD3,QAM_amp128;
   symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol;
 
   if ((symbol_mod == 0) || (symbol_mod == (4-frame_parms->Ncp)))
     pilots=1;
 
-
   //printf("comp prec: symbol %d, pilots %d\n",symbol, pilots);
+  __m128i QAM_amp128b = _mm_setzero_si128();
 
   if (mod_order == 4) {
     QAM_amp128 = _mm_set1_epi16(QAM16_n1);
-    QAM_amp128b = _mm_setzero_si128();
   } else if (mod_order == 6) {
     QAM_amp128  = _mm_set1_epi16(QAM64_n1);
     QAM_amp128b = _mm_set1_epi16(QAM64_n2);
   }
 
   for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
-
     dl_ch0_128          = (__m128i *)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12];
     dl_ch1_128          = (__m128i *)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12];
-
-
     dl_ch_mag128      = (__m128i *)&dl_ch_mag[aarx][symbol*frame_parms->N_RB_DL*12];
     dl_ch_mag128b     = (__m128i *)&dl_ch_magb[aarx][symbol*frame_parms->N_RB_DL*12];
     rxdataF128        = (__m128i *)&rxdataF_ext[aarx][symbol*frame_parms->N_RB_DL*12];
     rxdataF_comp128   = (__m128i *)&rxdataF_comp[aarx][symbol*frame_parms->N_RB_DL*12];
 
-
     for (rb=0; rb<nb_rb; rb++) {
       // combine TX channels using precoder from pmi
 #ifdef DEBUG_DLSCH_DEMOD
@@ -2197,31 +2082,22 @@ void dlsch_channel_compensation_TM56(int **rxdataF_ext,
       prec2A_TM56_128(pmi_ext[rb],&dl_ch0_128[1],&dl_ch1_128[1]);
 
       if (pilots==0) {
-
         prec2A_TM56_128(pmi_ext[rb],&dl_ch0_128[2],&dl_ch1_128[2]);
       }
 
       if (mod_order>2) {
         // get channel amplitude if not QPSK
-
         mmtmpD0 = _mm_madd_epi16(dl_ch0_128[0],dl_ch0_128[0]);
         mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
-
         mmtmpD1 = _mm_madd_epi16(dl_ch0_128[1],dl_ch0_128[1]);
         mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift);
-
         mmtmpD0 = _mm_packs_epi32(mmtmpD0,mmtmpD1);
-
         dl_ch_mag128[0] = _mm_unpacklo_epi16(mmtmpD0,mmtmpD0);
         dl_ch_mag128b[0] = dl_ch_mag128[0];
         dl_ch_mag128[0] = _mm_mulhi_epi16(dl_ch_mag128[0],QAM_amp128);
         dl_ch_mag128[0] = _mm_slli_epi16(dl_ch_mag128[0],1);
-
-
         //print_shorts("dl_ch_mag128[0]=",&dl_ch_mag128[0]);
-
         //print_shorts("dl_ch_mag128[0]=",&dl_ch_mag128[0]);
-
         dl_ch_mag128[1] = _mm_unpackhi_epi16(mmtmpD0,mmtmpD0);
         dl_ch_mag128b[1] = dl_ch_mag128[1];
         dl_ch_mag128[1] = _mm_mulhi_epi16(dl_ch_mag128[1],QAM_amp128);
@@ -2230,40 +2106,32 @@ void dlsch_channel_compensation_TM56(int **rxdataF_ext,
         if (pilots==0) {
           mmtmpD0 = _mm_madd_epi16(dl_ch0_128[2],dl_ch0_128[2]);
           mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
-
           mmtmpD1 = _mm_packs_epi32(mmtmpD0,mmtmpD0);
-
           dl_ch_mag128[2] = _mm_unpacklo_epi16(mmtmpD1,mmtmpD1);
           dl_ch_mag128b[2] = dl_ch_mag128[2];
-
           dl_ch_mag128[2] = _mm_mulhi_epi16(dl_ch_mag128[2],QAM_amp128);
           dl_ch_mag128[2] = _mm_slli_epi16(dl_ch_mag128[2],1);
         }
 
         dl_ch_mag128b[0] = _mm_mulhi_epi16(dl_ch_mag128b[0],QAM_amp128b);
         dl_ch_mag128b[0] = _mm_slli_epi16(dl_ch_mag128b[0],1);
-
         //print_shorts("dl_ch_mag128b[0]=",&dl_ch_mag128b[0]);
-
         dl_ch_mag128b[1] = _mm_mulhi_epi16(dl_ch_mag128b[1],QAM_amp128b);
         dl_ch_mag128b[1] = _mm_slli_epi16(dl_ch_mag128b[1],1);
 
         if (pilots==0) {
           dl_ch_mag128b[2] = _mm_mulhi_epi16(dl_ch_mag128b[2],QAM_amp128b);
           dl_ch_mag128b[2] = _mm_slli_epi16(dl_ch_mag128b[2],1);
-
         }
       }
 
       // MF multiply by conjugated channel
       mmtmpD0 = _mm_madd_epi16(dl_ch0_128[0],rxdataF128[0]);
       //        print_ints("re",&mmtmpD0);
-
       // mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
       mmtmpD1 = _mm_shufflelo_epi16(dl_ch0_128[0],_MM_SHUFFLE(2,3,0,1));
       mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
-      mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)&conjugate[0]);
-
+      mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)&conjugate[0]);
       //        print_ints("im",&mmtmpD1);
       mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[0]);
       // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
@@ -2279,20 +2147,18 @@ void dlsch_channel_compensation_TM56(int **rxdataF_ext,
       //        print_shorts("rx:",rxdataF128);
       //        print_shorts("ch:",dl_ch128);
       //        print_shorts("pack:",rxdataF_comp128);
-
       // multiply by conjugated channel
       mmtmpD0 = _mm_madd_epi16(dl_ch0_128[1],rxdataF128[1]);
       // mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
       mmtmpD1 = _mm_shufflelo_epi16(dl_ch0_128[1],_MM_SHUFFLE(2,3,0,1));
       mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
-      mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate);
+      mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)conjugate);
       mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[1]);
       // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
       mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
       mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift);
       mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1);
       mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1);
-
       rxdataF_comp128[1] = _mm_packs_epi32(mmtmpD2,mmtmpD3);
       //  print_shorts("rx:",rxdataF128+1);
       //  print_shorts("ch:",dl_ch128+1);
@@ -2304,19 +2170,17 @@ void dlsch_channel_compensation_TM56(int **rxdataF_ext,
         // mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
         mmtmpD1 = _mm_shufflelo_epi16(dl_ch0_128[2],_MM_SHUFFLE(2,3,0,1));
         mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
-        mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate);
+        mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)conjugate);
         mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[2]);
         // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
         mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
         mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift);
         mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1);
         mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1);
-
         rxdataF_comp128[2] = _mm_packs_epi32(mmtmpD2,mmtmpD3);
         //  print_shorts("rx:",rxdataF128+2);
         //  print_shorts("ch:",dl_ch128+2);
         //        print_shorts("pack:",rxdataF_comp128+2);
-
         dl_ch0_128+=3;
         dl_ch1_128+=3;
         dl_ch_mag128+=3;
@@ -2334,45 +2198,37 @@ void dlsch_channel_compensation_TM56(int **rxdataF_ext,
     }
 
     Nre = (pilots==0) ? 12 : 8;
-
     precoded_signal_strength += ((signal_energy_nodc(&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*Nre],
-                                                     (nb_rb*Nre))) - (measurements->n0_power[aarx]));
+                                  (nb_rb*Nre))) - (measurements->n0_power[aarx]));
   } // rx_antennas
 
   measurements->precoded_cqi_dB[eNB_id][0] = dB_fixed2(precoded_signal_strength,measurements->n0_power_tot);
-
   //printf("eNB_id %d, symbol %d: precoded CQI %d dB\n",eNB_id,symbol,
   //   measurements->precoded_cqi_dB[eNB_id][0]);
-
 #elif defined(__arm__)
-
   uint32_t rb,Nre;
   uint32_t aarx,symbol_mod,pilots=0;
-
   int16x4_t *dl_ch0_128,*dl_ch1_128,*rxdataF128;
   int16x8_t *dl_ch0_128b,*dl_ch1_128b;
   int32x4_t mmtmpD0,mmtmpD1,mmtmpD0b,mmtmpD1b;
   int16x8_t *dl_ch_mag128,*dl_ch_mag128b,mmtmpD2,mmtmpD3,mmtmpD4,*rxdataF_comp128;
   int16x8_t QAM_amp128,QAM_amp128b;
-
   int16_t conj[4]__attribute__((aligned(16))) = {1,-1,1,-1};
   int32x4_t output_shift128 = vmovq_n_s32(-(int32_t)output_shift);
   int32_t precoded_signal_strength=0;
-
   symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol;
-  if ((symbol_mod == 0) || (symbol_mod == (4-frame_parms->Ncp))) {
-    if (frame_parms->nb_antenna_ports_eNB==1) // 10 out of 12 so don't reduce size
-      { nb_rb=1+(5*nb_rb/6); }
 
-    else
-      { pilots=1; }
+  if ((symbol_mod == 0) || (symbol_mod == (4-frame_parms->Ncp))) {
+    if (frame_parms->nb_antenna_ports_eNB==1) { // 10 out of 12 so don't reduce size
+      nb_rb=1+(5*nb_rb/6);
+    } else {
+      pilots=1;
+    }
   }
 
-
   if (mod_order == 4) {
     QAM_amp128  = vmovq_n_s16(QAM16_n1);  // 2/sqrt(10)
     QAM_amp128b = vmovq_n_s16(0);
-
   } else if (mod_order == 6) {
     QAM_amp128  = vmovq_n_s16(QAM64_n1); //
     QAM_amp128b = vmovq_n_s16(QAM64_n2);
@@ -2381,21 +2237,18 @@ void dlsch_channel_compensation_TM56(int **rxdataF_ext,
   //    printf("comp: rxdataF_comp %p, symbol %d\n",rxdataF_comp[0],symbol);
 
   for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
-
-
-
-    dl_ch0_128          = (int16x4_t*)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12];
-    dl_ch1_128          = (int16x4_t*)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12];
-    dl_ch0_128b         = (int16x8_t*)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12];
-    dl_ch1_128b         = (int16x8_t*)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12];
-    dl_ch_mag128        = (int16x8_t*)&dl_ch_mag[aarx][symbol*frame_parms->N_RB_DL*12];
-    dl_ch_mag128b       = (int16x8_t*)&dl_ch_magb[aarx][symbol*frame_parms->N_RB_DL*12];
-    rxdataF128          = (int16x4_t*)&rxdataF_ext[aarx][symbol*frame_parms->N_RB_DL*12];
-    rxdataF_comp128     = (int16x8_t*)&rxdataF_comp[aarx][symbol*frame_parms->N_RB_DL*12];
+    dl_ch0_128          = (int16x4_t *)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12];
+    dl_ch1_128          = (int16x4_t *)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12];
+    dl_ch0_128b         = (int16x8_t *)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12];
+    dl_ch1_128b         = (int16x8_t *)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12];
+    dl_ch_mag128        = (int16x8_t *)&dl_ch_mag[aarx][symbol*frame_parms->N_RB_DL*12];
+    dl_ch_mag128b       = (int16x8_t *)&dl_ch_magb[aarx][symbol*frame_parms->N_RB_DL*12];
+    rxdataF128          = (int16x4_t *)&rxdataF_ext[aarx][symbol*frame_parms->N_RB_DL*12];
+    rxdataF_comp128     = (int16x8_t *)&rxdataF_comp[aarx][symbol*frame_parms->N_RB_DL*12];
 
     for (rb=0; rb<nb_rb; rb++) {
 #ifdef DEBUG_DLSCH_DEMOD
-      printf("mode 6 prec: rb %d, pmi->%d\n",rb,pmi_ext[rb]);
+      printf("mode 6 prec: rb %d, pmi->%u\n",rb,pmi_ext[rb]);
 #endif
       prec2A_TM56_128(pmi_ext[rb],&dl_ch0_128b[0],&dl_ch1_128b[0]);
       prec2A_TM56_128(pmi_ext[rb],&dl_ch0_128b[1],&dl_ch1_128b[1]);
@@ -2419,14 +2272,13 @@ void dlsch_channel_compensation_TM56(int **rxdataF_ext,
         mmtmpD1 = vmull_s16(dl_ch0_128[3], dl_ch0_128[3]);
         mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1,vrev64q_s32(mmtmpD1)),output_shift128);
         mmtmpD3 = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
+
         if (pilots==0) {
           mmtmpD0 = vmull_s16(dl_ch0_128[4], dl_ch0_128[4]);
           mmtmpD0 = vqshlq_s32(vqaddq_s32(mmtmpD0,vrev64q_s32(mmtmpD0)),output_shift128);
           mmtmpD1 = vmull_s16(dl_ch0_128[5], dl_ch0_128[5]);
           mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1,vrev64q_s32(mmtmpD1)),output_shift128);
           mmtmpD4 = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
-
-
         }
 
         dl_ch_mag128b[0] = vqdmulhq_s16(mmtmpD2,QAM_amp128b);
@@ -2434,12 +2286,12 @@ void dlsch_channel_compensation_TM56(int **rxdataF_ext,
         dl_ch_mag128[0] = vqdmulhq_s16(mmtmpD2,QAM_amp128);
         dl_ch_mag128[1] = vqdmulhq_s16(mmtmpD3,QAM_amp128);
 
-
         if (pilots==0) {
           dl_ch_mag128b[2] = vqdmulhq_s16(mmtmpD4,QAM_amp128b);
           dl_ch_mag128[2]  = vqdmulhq_s16(mmtmpD4,QAM_amp128);
         }
       }
+
       mmtmpD0 = vmull_s16(dl_ch0_128[0], rxdataF128[0]);
       //mmtmpD0 = [Re(ch[0])Re(rx[0]) Im(ch[0])Im(ch[0]) Re(ch[1])Re(rx[1]) Im(ch[1])Im(ch[1])]
       mmtmpD1 = vmull_s16(dl_ch0_128[1], rxdataF128[1]);
@@ -2447,29 +2299,24 @@ void dlsch_channel_compensation_TM56(int **rxdataF_ext,
       mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)),
                              vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1)));
       //mmtmpD0 = [Re(ch[0])Re(rx[0])+Im(ch[0])Im(ch[0]) Re(ch[1])Re(rx[1])+Im(ch[1])Im(ch[1]) Re(ch[2])Re(rx[2])+Im(ch[2])Im(ch[2]) Re(ch[3])Re(rx[3])+Im(ch[3])Im(ch[3])]
-
-      mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[0],*(int16x4_t*)conj)), rxdataF128[0]);
+      mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[0],*(int16x4_t *)conj)), rxdataF128[0]);
       //mmtmpD0 = [-Im(ch[0])Re(rx[0]) Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1]) Re(ch[1])Im(rx[1])]
-      mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[1],*(int16x4_t*)conj)), rxdataF128[1]);
+      mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[1],*(int16x4_t *)conj)), rxdataF128[1]);
       //mmtmpD0 = [-Im(ch[2])Re(rx[2]) Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3]) Re(ch[3])Im(rx[3])]
       mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)),
                              vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b)));
       //mmtmpD1 = [-Im(ch[0])Re(rx[0])+Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1])+Re(ch[1])Im(rx[1]) -Im(ch[2])Re(rx[2])+Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3])+Re(ch[3])Im(rx[3])]
-
       mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128);
       mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128);
       rxdataF_comp128[0] = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
-
       mmtmpD0 = vmull_s16(dl_ch0_128[2], rxdataF128[2]);
       mmtmpD1 = vmull_s16(dl_ch0_128[3], rxdataF128[3]);
       mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)),
                              vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1)));
-
-      mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[2],*(int16x4_t*)conj)), rxdataF128[2]);
-      mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[3],*(int16x4_t*)conj)), rxdataF128[3]);
+      mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[2],*(int16x4_t *)conj)), rxdataF128[2]);
+      mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[3],*(int16x4_t *)conj)), rxdataF128[3]);
       mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)),
                              vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b)));
-
       mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128);
       mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128);
       rxdataF_comp128[1] = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
@@ -2479,25 +2326,19 @@ void dlsch_channel_compensation_TM56(int **rxdataF_ext,
         mmtmpD1 = vmull_s16(dl_ch0_128[5], rxdataF128[5]);
         mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)),
                                vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1)));
-
-        mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[4],*(int16x4_t*)conj)), rxdataF128[4]);
-        mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[5],*(int16x4_t*)conj)), rxdataF128[5]);
+        mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[4],*(int16x4_t *)conj)), rxdataF128[4]);
+        mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[5],*(int16x4_t *)conj)), rxdataF128[5]);
         mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)),
                                vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b)));
-
-
         mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128);
         mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128);
         rxdataF_comp128[2] = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
-
-
         dl_ch0_128+=6;
         dl_ch1_128+=6;
         dl_ch_mag128+=3;
         dl_ch_mag128b+=3;
         rxdataF128+=6;
         rxdataF_comp128+=3;
-
       } else { // we have a smaller PDSCH in symbols with pilots so skip last group of 4 REs and increment less
         dl_ch0_128+=4;
         dl_ch1_128+=4;
@@ -2509,109 +2350,103 @@ void dlsch_channel_compensation_TM56(int **rxdataF_ext,
     }
 
     Nre = (pilots==0) ? 12 : 8;
-
-
     precoded_signal_strength += ((signal_energy_nodc(&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*Nre],
-
-                                                     (nb_rb*Nre))) - (measurements->n0_power[aarx]));
+                                  (nb_rb*Nre))) - (measurements->n0_power[aarx]));
     // rx_antennas
   }
-  measurements->precoded_cqi_dB[eNB_id][0] = dB_fixed2(precoded_signal_strength,measurements->n0_power_tot);
 
+  measurements->precoded_cqi_dB[eNB_id][0] = dB_fixed2(precoded_signal_strength,measurements->n0_power_tot);
   //printf("eNB_id %d, symbol %d: precoded CQI %d dB\n",eNB_id,symbol,
   //     measurements->precoded_cqi_dB[eNB_id][0]);
-
 #endif
   _mm_empty();
   _m_empty();
 }
 
 void precode_channel_est(int32_t **dl_ch_estimates_ext,
-                        LTE_DL_FRAME_PARMS *frame_parms,
-                        LTE_UE_PDSCH *pdsch_vars,
-                        unsigned char symbol,
-                        unsigned short nb_rb,
-                        MIMO_mode_t mimo_mode){
-
+                         LTE_DL_FRAME_PARMS *frame_parms,
+                         LTE_UE_PDSCH *pdsch_vars,
+                         unsigned char symbol,
+                         unsigned short nb_rb,
+                         MIMO_mode_t mimo_mode) {
   unsigned short rb;
   __m128i *dl_ch0_128,*dl_ch1_128;
   unsigned char aarx=0,symbol_mod,pilots=0;
   unsigned char *pmi_ext = pdsch_vars->pmi_ext;
-
   symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol;
 
   if ((symbol_mod == 0) || (symbol_mod == (4-frame_parms->Ncp)))
     pilots=1;
 
-  for (aarx=0;aarx<frame_parms->nb_antennas_rx;aarx++) {
-
+  for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
     dl_ch0_128          = (__m128i *)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12]; // this is h11
     dl_ch1_128          = (__m128i *)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12]; // this is h12
 
     for (rb=0; rb<nb_rb; rb++) {
       if (mimo_mode==LARGE_CDD) {
-            prec2A_TM3_128(&dl_ch0_128[0],&dl_ch1_128[0]);
-            prec2A_TM3_128(&dl_ch0_128[1],&dl_ch1_128[1]);
-            if (pilots==0) {
-              prec2A_TM3_128(&dl_ch0_128[2],&dl_ch1_128[2]);
-            }
-          }else if (mimo_mode==DUALSTREAM_UNIFORM_PRECODING1) {
-            prec2A_TM4_128(0,&dl_ch0_128[0],&dl_ch1_128[0]);
-            prec2A_TM4_128(0,&dl_ch0_128[1],&dl_ch1_128[1]);
-            if (pilots==0) {
-              prec2A_TM4_128(0,&dl_ch0_128[2],&dl_ch1_128[2]);
-            }
-          }else if (mimo_mode==DUALSTREAM_UNIFORM_PRECODINGj) {
-            prec2A_TM4_128(1,&dl_ch0_128[0],&dl_ch1_128[0]);
-            prec2A_TM4_128(1,&dl_ch0_128[1],&dl_ch1_128[1]);
-            if (pilots==0) {
-              prec2A_TM4_128(1,&dl_ch0_128[2],&dl_ch1_128[2]);
-            }
-          }else if (mimo_mode==DUALSTREAM_PUSCH_PRECODING) {
-            prec2A_TM4_128(pmi_ext[rb],&dl_ch0_128[0],&dl_ch1_128[0]);
-            prec2A_TM4_128(pmi_ext[rb],&dl_ch0_128[1],&dl_ch1_128[1]);
-            if (pilots==0) {
-              prec2A_TM4_128(pmi_ext[rb],&dl_ch0_128[2],&dl_ch1_128[2]);
-            }
-          }else {
-            LOG_E(PHY,"Unknown MIMO mode\n");
-            return;
-          }
-          if (pilots==0){
-            dl_ch0_128+=3;
-            dl_ch1_128+=3;
-          }else {
-            dl_ch0_128+=2;
-            dl_ch1_128+=2;
-          }
+        prec2A_TM3_128(&dl_ch0_128[0],&dl_ch1_128[0]);
+        prec2A_TM3_128(&dl_ch0_128[1],&dl_ch1_128[1]);
+
+        if (pilots==0) {
+          prec2A_TM3_128(&dl_ch0_128[2],&dl_ch1_128[2]);
+        }
+      } else if (mimo_mode==DUALSTREAM_UNIFORM_PRECODING1) {
+        prec2A_TM4_128(0,&dl_ch0_128[0],&dl_ch1_128[0]);
+        prec2A_TM4_128(0,&dl_ch0_128[1],&dl_ch1_128[1]);
+
+        if (pilots==0) {
+          prec2A_TM4_128(0,&dl_ch0_128[2],&dl_ch1_128[2]);
+        }
+      } else if (mimo_mode==DUALSTREAM_UNIFORM_PRECODINGj) {
+        prec2A_TM4_128(1,&dl_ch0_128[0],&dl_ch1_128[0]);
+        prec2A_TM4_128(1,&dl_ch0_128[1],&dl_ch1_128[1]);
+
+        if (pilots==0) {
+          prec2A_TM4_128(1,&dl_ch0_128[2],&dl_ch1_128[2]);
         }
+      } else if (mimo_mode==DUALSTREAM_PUSCH_PRECODING) {
+        prec2A_TM4_128(pmi_ext[rb],&dl_ch0_128[0],&dl_ch1_128[0]);
+        prec2A_TM4_128(pmi_ext[rb],&dl_ch0_128[1],&dl_ch1_128[1]);
 
+        if (pilots==0) {
+          prec2A_TM4_128(pmi_ext[rb],&dl_ch0_128[2],&dl_ch1_128[2]);
+        }
+      } else {
+        LOG_E(PHY,"Unknown MIMO mode\n");
+        return;
+      }
+
+      if (pilots==0) {
+        dl_ch0_128+=3;
+        dl_ch1_128+=3;
+      } else {
+        dl_ch0_128+=2;
+        dl_ch1_128+=2;
       }
+    }
+  }
 }
 
 void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms,
-                                    LTE_UE_PDSCH *pdsch_vars,
-                                    PHY_MEASUREMENTS *measurements,
-                                    int eNB_id,
-                                    unsigned char symbol,
-                                    unsigned char mod_order0,
-                                    unsigned char mod_order1,
-                                    int harq_pid,
-                                    int round,
-                                    MIMO_mode_t mimo_mode,
-                                    unsigned short nb_rb,
-                                    unsigned short mmse_flag,
-                                    unsigned char output_shift0,
-                                    unsigned char output_shift1) {
-
+                                     LTE_UE_PDSCH *pdsch_vars,
+                                     PHY_MEASUREMENTS *measurements,
+                                     int eNB_id,
+                                     unsigned char symbol,
+                                     unsigned char mod_order0,
+                                     unsigned char mod_order1,
+                                     int harq_pid,
+                                     int round,
+                                     MIMO_mode_t mimo_mode,
+                                     unsigned short nb_rb,
+                                     unsigned short mmse_flag,
+                                     unsigned char output_shift0,
+                                     unsigned char output_shift1) {
 #if defined(__x86_64__) || defined(__i386__)
-
   unsigned short rb,Nre;
   __m128i *dl_ch0_128,*dl_ch1_128,*dl_ch_mag0_128,*dl_ch_mag1_128,*dl_ch_mag0_128b,*dl_ch_mag1_128b,*rxdataF128,*rxdataF_comp0_128,*rxdataF_comp1_128;
   unsigned char aarx=0,symbol_mod,pilots=0;
   int precoded_signal_strength0=0,precoded_signal_strength1=0;
   int rx_power_correction;
-
   int **rxdataF_ext           = pdsch_vars->rxdataF_ext;
   int **dl_ch_estimates_ext   = pdsch_vars->dl_ch_estimates_ext;
   int **dl_ch_mag0            = pdsch_vars->dl_ch_mag0;
@@ -2621,35 +2456,33 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms,
   int **rxdataF_comp0         = pdsch_vars->rxdataF_comp0;
   int **rxdataF_comp1         = pdsch_vars->rxdataF_comp1[harq_pid][round];
   unsigned char *pmi_ext      = pdsch_vars->pmi_ext;
-  __m128i mmtmpD0,mmtmpD1,mmtmpD2,mmtmpD3,QAM_amp0_128,QAM_amp0_128b,QAM_amp1_128,QAM_amp1_128b;
-
+  __m128i mmtmpD0,mmtmpD1,mmtmpD2,mmtmpD3,QAM_amp0_128,QAM_amp1_128;
   symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol;
 
   if ((symbol_mod == 0) || (symbol_mod == (4-frame_parms->Ncp)))
     pilots=1;
 
   rx_power_correction = 1;
-
- // printf("comp prec: symbol %d, pilots %d\n",symbol, pilots);
+  // printf("comp prec: symbol %d, pilots %d\n",symbol, pilots);
+  __m128i  QAM_amp0_128b = _mm_setzero_si128();
 
   if (mod_order0 == 4) {
     QAM_amp0_128  = _mm_set1_epi16(QAM16_n1);
-    QAM_amp0_128b = _mm_setzero_si128();
   } else if (mod_order0 == 6) {
     QAM_amp0_128  = _mm_set1_epi16(QAM64_n1);
     QAM_amp0_128b = _mm_set1_epi16(QAM64_n2);
   }
 
+  __m128i  QAM_amp1_128b = _mm_setzero_si128();
+
   if (mod_order1 == 4) {
     QAM_amp1_128  = _mm_set1_epi16(QAM16_n1);
-    QAM_amp1_128b = _mm_setzero_si128();
   } else if (mod_order1 == 6) {
     QAM_amp1_128  = _mm_set1_epi16(QAM64_n1);
     QAM_amp1_128b = _mm_set1_epi16(QAM64_n2);
   }
 
-  for (aarx=0;aarx<frame_parms->nb_antennas_rx;aarx++) {
-
+  for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
     dl_ch0_128          = (__m128i *)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12]; // this is h11
     dl_ch1_128          = (__m128i *)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12]; // this is h12
     dl_ch_mag0_128      = (__m128i *)&dl_ch_mag0[aarx][symbol*frame_parms->N_RB_DL*12]; //responsible for x1
@@ -2662,57 +2495,53 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms,
 
     for (rb=0; rb<nb_rb; rb++) {
       if (mmse_flag == 0) {
-      // combine TX channels using precoder from pmi
+        // combine TX channels using precoder from pmi
         if (mimo_mode==LARGE_CDD) {
           prec2A_TM3_128(&dl_ch0_128[0],&dl_ch1_128[0]);
           prec2A_TM3_128(&dl_ch0_128[1],&dl_ch1_128[1]);
+
           if (pilots==0) {
             prec2A_TM3_128(&dl_ch0_128[2],&dl_ch1_128[2]);
           }
-        }else if (mimo_mode==DUALSTREAM_UNIFORM_PRECODING1) {
+        } else if (mimo_mode==DUALSTREAM_UNIFORM_PRECODING1) {
           prec2A_TM4_128(0,&dl_ch0_128[0],&dl_ch1_128[0]);
           prec2A_TM4_128(0,&dl_ch0_128[1],&dl_ch1_128[1]);
+
           if (pilots==0) {
             prec2A_TM4_128(0,&dl_ch0_128[2],&dl_ch1_128[2]);
           }
-        }else if (mimo_mode==DUALSTREAM_UNIFORM_PRECODINGj) {
+        } else if (mimo_mode==DUALSTREAM_UNIFORM_PRECODINGj) {
           prec2A_TM4_128(1,&dl_ch0_128[0],&dl_ch1_128[0]);
           prec2A_TM4_128(1,&dl_ch0_128[1],&dl_ch1_128[1]);
+
           if (pilots==0) {
             prec2A_TM4_128(1,&dl_ch0_128[2],&dl_ch1_128[2]);
           }
-        }else if (mimo_mode==DUALSTREAM_PUSCH_PRECODING) {
+        } else if (mimo_mode==DUALSTREAM_PUSCH_PRECODING) {
           prec2A_TM4_128(pmi_ext[rb],&dl_ch0_128[0],&dl_ch1_128[0]);
           prec2A_TM4_128(pmi_ext[rb],&dl_ch0_128[1],&dl_ch1_128[1]);
+
           if (pilots==0) {
             prec2A_TM4_128(pmi_ext[rb],&dl_ch0_128[2],&dl_ch1_128[2]);
           }
-        }else {
+        } else {
           LOG_E(PHY,"Unknown MIMO mode\n");
           return;
         }
       }
 
-
       if (mod_order0>2) {
         // get channel amplitude if not QPSK
-
         mmtmpD0 = _mm_madd_epi16(dl_ch0_128[0],dl_ch0_128[0]);
         mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift0);
-
         mmtmpD1 = _mm_madd_epi16(dl_ch0_128[1],dl_ch0_128[1]);
         mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift0);
-
         mmtmpD0 = _mm_packs_epi32(mmtmpD0,mmtmpD1);
-
         dl_ch_mag0_128[0] = _mm_unpacklo_epi16(mmtmpD0,mmtmpD0);
         dl_ch_mag0_128b[0] = dl_ch_mag0_128[0];
         dl_ch_mag0_128[0] = _mm_mulhi_epi16(dl_ch_mag0_128[0],QAM_amp0_128);
         dl_ch_mag0_128[0] = _mm_slli_epi16(dl_ch_mag0_128[0],1);
-
         //  print_shorts("dl_ch_mag0_128[0]=",&dl_ch_mag0_128[0]);
-
-
         dl_ch_mag0_128[1] = _mm_unpackhi_epi16(mmtmpD0,mmtmpD0);
         dl_ch_mag0_128b[1] = dl_ch_mag0_128[1];
         dl_ch_mag0_128[1] = _mm_mulhi_epi16(dl_ch_mag0_128[1],QAM_amp0_128);
@@ -2721,21 +2550,16 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms,
         if (pilots==0) {
           mmtmpD0 = _mm_madd_epi16(dl_ch0_128[2],dl_ch0_128[2]);
           mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift0);
-
           mmtmpD1 = _mm_packs_epi32(mmtmpD0,mmtmpD0);
-
           dl_ch_mag0_128[2] = _mm_unpacklo_epi16(mmtmpD1,mmtmpD1);
           dl_ch_mag0_128b[2] = dl_ch_mag0_128[2];
-
           dl_ch_mag0_128[2] = _mm_mulhi_epi16(dl_ch_mag0_128[2],QAM_amp0_128);
           dl_ch_mag0_128[2] = _mm_slli_epi16(dl_ch_mag0_128[2],1);
         }
 
         dl_ch_mag0_128b[0] = _mm_mulhi_epi16(dl_ch_mag0_128b[0],QAM_amp0_128b);
         dl_ch_mag0_128b[0] = _mm_slli_epi16(dl_ch_mag0_128b[0],1);
-
-       // print_shorts("dl_ch_mag0_128b[0]=",&dl_ch_mag0_128b[0]);
-
+        // print_shorts("dl_ch_mag0_128b[0]=",&dl_ch_mag0_128b[0]);
         dl_ch_mag0_128b[1] = _mm_mulhi_epi16(dl_ch_mag0_128b[1],QAM_amp0_128b);
         dl_ch_mag0_128b[1] = _mm_slli_epi16(dl_ch_mag0_128b[1],1);
 
@@ -2747,22 +2571,16 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms,
 
       if (mod_order1>2) {
         // get channel amplitude if not QPSK
-
         mmtmpD0 = _mm_madd_epi16(dl_ch1_128[0],dl_ch1_128[0]);
         mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift1);
-
         mmtmpD1 = _mm_madd_epi16(dl_ch1_128[1],dl_ch1_128[1]);
         mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift1);
-
         mmtmpD0 = _mm_packs_epi32(mmtmpD0,mmtmpD1);
-
         dl_ch_mag1_128[0] = _mm_unpacklo_epi16(mmtmpD0,mmtmpD0);
         dl_ch_mag1_128b[0] = dl_ch_mag1_128[0];
         dl_ch_mag1_128[0] = _mm_mulhi_epi16(dl_ch_mag1_128[0],QAM_amp1_128);
         dl_ch_mag1_128[0] = _mm_slli_epi16(dl_ch_mag1_128[0],1);
-
-       // print_shorts("dl_ch_mag1_128[0]=",&dl_ch_mag1_128[0]);
-
+        // print_shorts("dl_ch_mag1_128[0]=",&dl_ch_mag1_128[0]);
         dl_ch_mag1_128[1] = _mm_unpackhi_epi16(mmtmpD0,mmtmpD0);
         dl_ch_mag1_128b[1] = dl_ch_mag1_128[1];
         dl_ch_mag1_128[1] = _mm_mulhi_epi16(dl_ch_mag1_128[1],QAM_amp1_128);
@@ -2771,21 +2589,16 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms,
         if (pilots==0) {
           mmtmpD0 = _mm_madd_epi16(dl_ch1_128[2],dl_ch1_128[2]);
           mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift1);
-
           mmtmpD1 = _mm_packs_epi32(mmtmpD0,mmtmpD0);
-
           dl_ch_mag1_128[2] = _mm_unpacklo_epi16(mmtmpD1,mmtmpD1);
           dl_ch_mag1_128b[2] = dl_ch_mag1_128[2];
-
           dl_ch_mag1_128[2] = _mm_mulhi_epi16(dl_ch_mag1_128[2],QAM_amp1_128);
           dl_ch_mag1_128[2] = _mm_slli_epi16(dl_ch_mag1_128[2],1);
         }
 
         dl_ch_mag1_128b[0] = _mm_mulhi_epi16(dl_ch_mag1_128b[0],QAM_amp1_128b);
         dl_ch_mag1_128b[0] = _mm_slli_epi16(dl_ch_mag1_128b[0],1);
-
-       // print_shorts("dl_ch_mag1_128b[0]=",&dl_ch_mag1_128b[0]);
-
+        // print_shorts("dl_ch_mag1_128b[0]=",&dl_ch_mag1_128b[0]);
         dl_ch_mag1_128b[1] = _mm_mulhi_epi16(dl_ch_mag1_128b[1],QAM_amp1_128b);
         dl_ch_mag1_128b[1] = _mm_slli_epi16(dl_ch_mag1_128b[1],1);
 
@@ -2798,47 +2611,43 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms,
       // layer 0
       // MF multiply by conjugated channel
       mmtmpD0 = _mm_madd_epi16(dl_ch0_128[0],rxdataF128[0]);
-    //  print_ints("re",&mmtmpD0);
-
+      //  print_ints("re",&mmtmpD0);
       // mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
       mmtmpD1 = _mm_shufflelo_epi16(dl_ch0_128[0],_MM_SHUFFLE(2,3,0,1));
       mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
-      mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)&conjugate[0]);
+      mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)&conjugate[0]);
       mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[0]);
-           // print_ints("im",&mmtmpD1);
+      // print_ints("im",&mmtmpD1);
       // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
       mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift0);
-           // printf("Shift: %d\n",output_shift);
-          // print_ints("re(shift)",&mmtmpD0);
+      // printf("Shift: %d\n",output_shift);
+      // print_ints("re(shift)",&mmtmpD0);
       mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift0);
-           // print_ints("im(shift)",&mmtmpD1);
+      // print_ints("im(shift)",&mmtmpD1);
       mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1);
       mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1);
-          //  print_ints("c0",&mmtmpD2);
-          // print_ints("c1",&mmtmpD3);
+      //  print_ints("c0",&mmtmpD2);
+      // print_ints("c1",&mmtmpD3);
       rxdataF_comp0_128[0] = _mm_packs_epi32(mmtmpD2,mmtmpD3);
-
-           // print_shorts("rx:",rxdataF128);
-           // print_shorts("ch:",dl_ch0_128);
+      // print_shorts("rx:",rxdataF128);
+      // print_shorts("ch:",dl_ch0_128);
       //print_shorts("pack:",rxdataF_comp0_128);
-
       // multiply by conjugated channel
       mmtmpD0 = _mm_madd_epi16(dl_ch0_128[1],rxdataF128[1]);
       // mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
       mmtmpD1 = _mm_shufflelo_epi16(dl_ch0_128[1],_MM_SHUFFLE(2,3,0,1));
       mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
-      mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate);
+      mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)conjugate);
       mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[1]);
       // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
       mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift0);
       mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift0);
       mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1);
       mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1);
-
       rxdataF_comp0_128[1] = _mm_packs_epi32(mmtmpD2,mmtmpD3);
-           //  print_shorts("rx:",rxdataF128+1);
-            //  print_shorts("ch:",dl_ch0_128+1);
-            // print_shorts("pack:",rxdataF_comp0_128+1);
+      //  print_shorts("rx:",rxdataF128+1);
+      //  print_shorts("ch:",dl_ch0_128+1);
+      // print_shorts("pack:",rxdataF_comp0_128+1);
 
       if (pilots==0) {
         // multiply by conjugated channel
@@ -2846,64 +2655,58 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms,
         // mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
         mmtmpD1 = _mm_shufflelo_epi16(dl_ch0_128[2],_MM_SHUFFLE(2,3,0,1));
         mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
-        mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate);
+        mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)conjugate);
         mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[2]);
         // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
         mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift0);
         mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift0);
         mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1);
         mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1);
-
         rxdataF_comp0_128[2] = _mm_packs_epi32(mmtmpD2,mmtmpD3);
-           //   print_shorts("rx:",rxdataF128+2);
-           //   print_shorts("ch:",dl_ch0_128+2);
-            //  print_shorts("pack:",rxdataF_comp0_128+2);
-
+        //   print_shorts("rx:",rxdataF128+2);
+        //   print_shorts("ch:",dl_ch0_128+2);
+        //  print_shorts("pack:",rxdataF_comp0_128+2);
       }
 
-
       // layer 1
       // MF multiply by conjugated channel
       mmtmpD0 = _mm_madd_epi16(dl_ch1_128[0],rxdataF128[0]);
-           //  print_ints("re",&mmtmpD0);
-
-     // mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
+      //  print_ints("re",&mmtmpD0);
+      // mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
       mmtmpD1 = _mm_shufflelo_epi16(dl_ch1_128[0],_MM_SHUFFLE(2,3,0,1));
       mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
-      mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)&conjugate[0]);
-            //  print_ints("im",&mmtmpD1);
+      mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)&conjugate[0]);
+      //  print_ints("im",&mmtmpD1);
       mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[0]);
       // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
       mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift1);
-             // print_ints("re(shift)",&mmtmpD0);
+      // print_ints("re(shift)",&mmtmpD0);
       mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift1);
-             // print_ints("im(shift)",&mmtmpD1);
+      // print_ints("im(shift)",&mmtmpD1);
       mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1);
       mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1);
-             // print_ints("c0",&mmtmpD2);
-             // print_ints("c1",&mmtmpD3);
+      // print_ints("c0",&mmtmpD2);
+      // print_ints("c1",&mmtmpD3);
       rxdataF_comp1_128[0] = _mm_packs_epi32(mmtmpD2,mmtmpD3);
-            // print_shorts("rx:",rxdataF128);
-            //  print_shorts("ch:",dl_ch1_128);
-            // print_shorts("pack:",rxdataF_comp1_128);
-
-     // multiply by conjugated channel
+      // print_shorts("rx:",rxdataF128);
+      //  print_shorts("ch:",dl_ch1_128);
+      // print_shorts("pack:",rxdataF_comp1_128);
+      // multiply by conjugated channel
       mmtmpD0 = _mm_madd_epi16(dl_ch1_128[1],rxdataF128[1]);
       // mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
       mmtmpD1 = _mm_shufflelo_epi16(dl_ch1_128[1],_MM_SHUFFLE(2,3,0,1));
       mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
-      mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate);
+      mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)conjugate);
       mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[1]);
       // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
       mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift1);
       mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift1);
       mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1);
       mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1);
-
       rxdataF_comp1_128[1] = _mm_packs_epi32(mmtmpD2,mmtmpD3);
-            //  print_shorts("rx:",rxdataF128+1);
-           // print_shorts("ch:",dl_ch1_128+1);
-            // print_shorts("pack:",rxdataF_comp1_128+1);
+      //  print_shorts("rx:",rxdataF128+1);
+      // print_shorts("ch:",dl_ch1_128+1);
+      // print_shorts("pack:",rxdataF_comp1_128+1);
 
       if (pilots==0) {
         // multiply by conjugated channel
@@ -2911,19 +2714,17 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms,
         // mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
         mmtmpD1 = _mm_shufflelo_epi16(dl_ch1_128[2],_MM_SHUFFLE(2,3,0,1));
         mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
-        mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate);
+        mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)conjugate);
         mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[2]);
         // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
         mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift1);
         mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift1);
         mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1);
         mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1);
-
         rxdataF_comp1_128[2] = _mm_packs_epi32(mmtmpD2,mmtmpD3);
-          //   print_shorts("rx:",rxdataF128+2);
-           //  print_shorts("ch:",dl_ch1_128+2);
-             //         print_shorts("pack:",rxdataF_comp1_128+2);
-
+        //   print_shorts("rx:",rxdataF128+2);
+        //  print_shorts("ch:",dl_ch1_128+2);
+        //         print_shorts("pack:",rxdataF_comp1_128+2);
         dl_ch0_128+=3;
         dl_ch1_128+=3;
         dl_ch_mag0_128+=3;
@@ -2933,8 +2734,7 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms,
         rxdataF128+=3;
         rxdataF_comp0_128+=3;
         rxdataF_comp1_128+=3;
-      }
-      else {
+      } else {
         dl_ch0_128+=2;
         dl_ch1_128+=2;
         dl_ch_mag0_128+=2;
@@ -2945,40 +2745,32 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms,
         rxdataF_comp0_128+=2;
         rxdataF_comp1_128+=2;
       }
-
     } // rb loop
-    Nre = (pilots==0) ? 12 : 8;
 
+    Nre = (pilots==0) ? 12 : 8;
     precoded_signal_strength0 += ((signal_energy_nodc(&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*Nre],
-                                                        (nb_rb*Nre))*rx_power_correction) - (measurements->n0_power[aarx]));
-
+                                   (nb_rb*Nre))*rx_power_correction) - (measurements->n0_power[aarx]));
     precoded_signal_strength1 += ((signal_energy_nodc(&dl_ch_estimates_ext[aarx+2][symbol*frame_parms->N_RB_DL*Nre],
-                                                        (nb_rb*Nre))*rx_power_correction) - (measurements->n0_power[aarx]));
+                                   (nb_rb*Nre))*rx_power_correction) - (measurements->n0_power[aarx]));
   } // rx_antennas
 
   measurements->precoded_cqi_dB[eNB_id][0] = dB_fixed2(precoded_signal_strength0,measurements->n0_power_tot);
   measurements->precoded_cqi_dB[eNB_id][1] = dB_fixed2(precoded_signal_strength1,measurements->n0_power_tot);
-
- // printf("eNB_id %d, symbol %d: precoded CQI %d dB\n",eNB_id,symbol,
-     //  measurements->precoded_cqi_dB[eNB_id][0]);
-
+  // printf("eNB_id %d, symbol %d: precoded CQI %d dB\n",eNB_id,symbol,
+  //  measurements->precoded_cqi_dB[eNB_id][0]);
   _mm_empty();
   _m_empty();
-
-  #elif defined(__arm__)
-
+#elif defined(__arm__)
   unsigned short rb,Nre;
   unsigned char aarx,symbol_mod,pilots=0;
   int precoded_signal_strength0=0,precoded_signal_strength1=0, rx_power_correction;
   int16x4_t *dl_ch0_128,*rxdataF128;
   int16x4_t *dl_ch1_128;
   int16x8_t *dl_ch0_128b,*dl_ch1_128b;
-
   int32x4_t mmtmpD0,mmtmpD1,mmtmpD0b,mmtmpD1b;
   int16x8_t *dl_ch_mag0_128,*dl_ch_mag0_128b,*dl_ch_mag1_128,*dl_ch_mag1_128b,mmtmpD2,mmtmpD3,mmtmpD4,*rxdataF_comp0_128,*rxdataF_comp1_128;
   int16x8_t QAM_amp0_128,QAM_amp0_128b,QAM_amp1_128,QAM_amp1_128b;
   int32x4_t output_shift128 = vmovq_n_s32(-(int32_t)output_shift);
-
   int **rxdataF_ext           = pdsch_vars->rxdataF_ext;
   int **dl_ch_estimates_ext   = pdsch_vars->dl_ch_estimates_ext;
   int **dl_ch_mag0            = pdsch_vars->dl_ch_mag0;
@@ -2987,17 +2779,15 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms,
   int **dl_ch_magb1           = pdsch_vars->dl_ch_magb1[harq_pid][round];
   int **rxdataF_comp0         = pdsch_vars->rxdataF_comp0;
   int **rxdataF_comp1         = pdsch_vars->rxdataF_comp1[harq_pid][round];
-
   int16_t conj[4]__attribute__((aligned(16))) = {1,-1,1,-1};
-
   symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol;
 
   if ((symbol_mod == 0) || (symbol_mod == (4-frame_parms->Ncp))) {
-    if (frame_parms->nb_antenna_ports_eNB==1) // 10 out of 12 so don't reduce size
-      { nb_rb=1+(5*nb_rb/6); }
-
-    else
-      { pilots=1; }
+    if (frame_parms->nb_antenna_ports_eNB==1) { // 10 out of 12 so don't reduce size
+      nb_rb=1+(5*nb_rb/6);
+    } else {
+      pilots=1;
+    }
   }
 
   rx_power_correction=1;
@@ -3005,7 +2795,6 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms,
   if (mod_order0 == 4) {
     QAM_amp0_128  = vmovq_n_s16(QAM16_n1);  // 2/sqrt(10)
     QAM_amp0_128b = vmovq_n_s16(0);
-
   } else if (mod_order0 == 6) {
     QAM_amp0_128  = vmovq_n_s16(QAM64_n1); //
     QAM_amp0_128b = vmovq_n_s16(QAM64_n2);
@@ -3014,7 +2803,6 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms,
   if (mod_order1 == 4) {
     QAM_amp1_128  = vmovq_n_s16(QAM16_n1);  // 2/sqrt(10)
     QAM_amp1_128b = vmovq_n_s16(0);
-
   } else if (mod_order1 == 6) {
     QAM_amp1_128  = vmovq_n_s16(QAM64_n1); //
     QAM_amp1_128b = vmovq_n_s16(QAM64_n2);
@@ -3023,20 +2811,17 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms,
   //    printf("comp: rxdataF_comp %p, symbol %d\n",rxdataF_comp[0],symbol);
 
   for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
-
-
-
-    dl_ch0_128          = (int16x4_t*)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12];
-    dl_ch1_128          = (int16x4_t*)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12];
-    dl_ch0_128b          = (int16x8_t*)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12];
-    dl_ch1_128b          = (int16x8_t*)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12];
-    dl_ch_mag0_128      = (int16x8_t*)&dl_ch_mag0[aarx][symbol*frame_parms->N_RB_DL*12];
-    dl_ch_mag0_128b     = (int16x8_t*)&dl_ch_magb0[aarx][symbol*frame_parms->N_RB_DL*12];
-    dl_ch_mag1_128      = (int16x8_t*)&dl_ch_mag1[aarx][symbol*frame_parms->N_RB_DL*12];
-    dl_ch_mag1_128b     = (int16x8_t*)&dl_ch_magb1[aarx][symbol*frame_parms->N_RB_DL*12];
-    rxdataF128          = (int16x4_t*)&rxdataF_ext[aarx][symbol*frame_parms->N_RB_DL*12];
-    rxdataF_comp0_128   = (int16x8_t*)&rxdataF_comp0[aarx][symbol*frame_parms->N_RB_DL*12];
-    rxdataF_comp1_128   = (int16x8_t*)&rxdataF_comp1[aarx][symbol*frame_parms->N_RB_DL*12];
+    dl_ch0_128          = (int16x4_t *)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12];
+    dl_ch1_128          = (int16x4_t *)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12];
+    dl_ch0_128b          = (int16x8_t *)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12];
+    dl_ch1_128b          = (int16x8_t *)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12];
+    dl_ch_mag0_128      = (int16x8_t *)&dl_ch_mag0[aarx][symbol*frame_parms->N_RB_DL*12];
+    dl_ch_mag0_128b     = (int16x8_t *)&dl_ch_magb0[aarx][symbol*frame_parms->N_RB_DL*12];
+    dl_ch_mag1_128      = (int16x8_t *)&dl_ch_mag1[aarx][symbol*frame_parms->N_RB_DL*12];
+    dl_ch_mag1_128b     = (int16x8_t *)&dl_ch_magb1[aarx][symbol*frame_parms->N_RB_DL*12];
+    rxdataF128          = (int16x4_t *)&rxdataF_ext[aarx][symbol*frame_parms->N_RB_DL*12];
+    rxdataF_comp0_128   = (int16x8_t *)&rxdataF_comp0[aarx][symbol*frame_parms->N_RB_DL*12];
+    rxdataF_comp1_128   = (int16x8_t *)&rxdataF_comp1[aarx][symbol*frame_parms->N_RB_DL*12];
 
     for (rb=0; rb<nb_rb; rb++) {
       if (mmse_flag == 0) {
@@ -3044,28 +2829,30 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms,
         if (mimo_mode==LARGE_CDD) {
           prec2A_TM3_128(&dl_ch0_128[0],&dl_ch1_128[0]);
           prec2A_TM3_128(&dl_ch0_128[1],&dl_ch1_128[1]);
+
           if (pilots==0) {
             prec2A_TM3_128(&dl_ch0_128[2],&dl_ch1_128[2]);
           }
-        }else if (mimo_mode==DUALSTREAM_UNIFORM_PRECODING1) {
+        } else if (mimo_mode==DUALSTREAM_UNIFORM_PRECODING1) {
           prec2A_TM4_128(0,&dl_ch0_128[0],&dl_ch1_128[0]);
           prec2A_TM4_128(0,&dl_ch0_128[1],&dl_ch1_128[1]);
+
           if (pilots==0) {
             prec2A_TM4_128(0,&dl_ch0_128[2],&dl_ch1_128[2]);
           }
-        }else if (mimo_mode==DUALSTREAM_UNIFORM_PRECODINGj) {
+        } else if (mimo_mode==DUALSTREAM_UNIFORM_PRECODINGj) {
           prec2A_TM4_128(1,&dl_ch0_128[0],&dl_ch1_128[0]);
           prec2A_TM4_128(1,&dl_ch0_128[1],&dl_ch1_128[1]);
+
           if (pilots==0) {
             prec2A_TM4_128(1,&dl_ch0_128[2],&dl_ch1_128[2]);
           }
-        }else {
+        } else {
           LOG_E(PHY,"Unknown MIMO mode\n");
           return;
         }
       }
 
-
       if (mod_order0>2) {
         // get channel amplitude if not QPSK
         mmtmpD0 = vmull_s16(dl_ch0_128[0], dl_ch0_128[0]);
@@ -3088,8 +2875,6 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms,
           mmtmpD1 = vmull_s16(dl_ch0_128[5], dl_ch0_128[5]);
           mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1,vrev64q_s32(mmtmpD1)),output_shift128);
           mmtmpD4 = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
-
-
         }
 
         dl_ch_mag0_128b[0] = vqdmulhq_s16(mmtmpD2,QAM_amp0_128b);
@@ -3097,7 +2882,6 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms,
         dl_ch_mag0_128[0] = vqdmulhq_s16(mmtmpD2,QAM_amp0_128);
         dl_ch_mag0_128[1] = vqdmulhq_s16(mmtmpD3,QAM_amp0_128);
 
-
         if (pilots==0) {
           dl_ch_mag0_128b[2] = vqdmulhq_s16(mmtmpD4,QAM_amp0_128b);
           dl_ch_mag0_128[2]  = vqdmulhq_s16(mmtmpD4,QAM_amp0_128);
@@ -3126,8 +2910,6 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms,
           mmtmpD1 = vmull_s16(dl_ch1_128[5], dl_ch1_128[5]);
           mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1,vrev64q_s32(mmtmpD1)),output_shift128);
           mmtmpD4 = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
-
-
         }
 
         dl_ch_mag1_128b[0] = vqdmulhq_s16(mmtmpD2,QAM_amp1_128b);
@@ -3135,7 +2917,6 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms,
         dl_ch_mag1_128[0] = vqdmulhq_s16(mmtmpD2,QAM_amp1_128);
         dl_ch_mag1_128[1] = vqdmulhq_s16(mmtmpD3,QAM_amp1_128);
 
-
         if (pilots==0) {
           dl_ch_mag1_128b[2] = vqdmulhq_s16(mmtmpD4,QAM_amp1_128b);
           dl_ch_mag1_128[2]  = vqdmulhq_s16(mmtmpD4,QAM_amp1_128);
@@ -3149,60 +2930,49 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms,
       mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)),
                              vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1)));
       //mmtmpD0 = [Re(ch[0])Re(rx[0])+Im(ch[0])Im(ch[0]) Re(ch[1])Re(rx[1])+Im(ch[1])Im(ch[1]) Re(ch[2])Re(rx[2])+Im(ch[2])Im(ch[2]) Re(ch[3])Re(rx[3])+Im(ch[3])Im(ch[3])]
-
-      mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[0],*(int16x4_t*)conj)), rxdataF128[0]);
+      mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[0],*(int16x4_t *)conj)), rxdataF128[0]);
       //mmtmpD0 = [-Im(ch[0])Re(rx[0]) Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1]) Re(ch[1])Im(rx[1])]
-      mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[1],*(int16x4_t*)conj)), rxdataF128[1]);
+      mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[1],*(int16x4_t *)conj)), rxdataF128[1]);
       //mmtmpD0 = [-Im(ch[2])Re(rx[2]) Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3]) Re(ch[3])Im(rx[3])]
       mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)),
                              vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b)));
       //mmtmpD1 = [-Im(ch[0])Re(rx[0])+Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1])+Re(ch[1])Im(rx[1]) -Im(ch[2])Re(rx[2])+Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3])+Re(ch[3])Im(rx[3])]
-
       mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128);
       mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128);
       rxdataF_comp0_128[0] = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
-
       mmtmpD0 = vmull_s16(dl_ch0_128[2], rxdataF128[2]);
       mmtmpD1 = vmull_s16(dl_ch0_128[3], rxdataF128[3]);
       mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)),
                              vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1)));
-
-      mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[2],*(int16x4_t*)conj)), rxdataF128[2]);
-      mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[3],*(int16x4_t*)conj)), rxdataF128[3]);
+      mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[2],*(int16x4_t *)conj)), rxdataF128[2]);
+      mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[3],*(int16x4_t *)conj)), rxdataF128[3]);
       mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)),
                              vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b)));
-
       mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128);
       mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128);
       rxdataF_comp0_128[1] = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
-
       // second stream
       mmtmpD0 = vmull_s16(dl_ch1_128[0], rxdataF128[0]);
       mmtmpD1 = vmull_s16(dl_ch1_128[1], rxdataF128[1]);
       mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)),
                              vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1)));
-      mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[0],*(int16x4_t*)conj)), rxdataF128[0]);
-
-      mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[1],*(int16x4_t*)conj)), rxdataF128[1]);
+      mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[0],*(int16x4_t *)conj)), rxdataF128[0]);
+      mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[1],*(int16x4_t *)conj)), rxdataF128[1]);
       //mmtmpD0 = [-Im(ch[2])Re(rx[2]) Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3]) Re(ch[3])Im(rx[3])]
       mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)),
                              vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b)));
       //mmtmpD1 = [-Im(ch[0])Re(rx[0])+Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1])+Re(ch[1])Im(rx[1]) -Im(ch[2])Re(rx[2])+Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3])+Re(ch[3])Im(rx[3])]
-
       mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128);
       mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128);
       rxdataF_comp1_128[0] = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
-
       mmtmpD0 = vmull_s16(dl_ch1_128[2], rxdataF128[2]);
       mmtmpD1 = vmull_s16(dl_ch1_128[3], rxdataF128[3]);
       mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)),
                              vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1)));
-
-      mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[2],*(int16x4_t*)conj)), rxdataF128[2]);
-      mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[3],*(int16x4_t*)conj)), rxdataF128[3]);
+      mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[2],*(int16x4_t *)conj)), rxdataF128[2]);
+      mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[3],*(int16x4_t *)conj)), rxdataF128[3]);
       mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)),
                              vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b)));
-
       mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128);
       mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128);
       rxdataF_comp1_128[1] = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
@@ -3212,13 +2982,10 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms,
         mmtmpD1 = vmull_s16(dl_ch0_128[5], rxdataF128[5]);
         mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)),
                                vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1)));
-
-        mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[4],*(int16x4_t*)conj)), rxdataF128[4]);
-        mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[5],*(int16x4_t*)conj)), rxdataF128[5]);
+        mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[4],*(int16x4_t *)conj)), rxdataF128[4]);
+        mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[5],*(int16x4_t *)conj)), rxdataF128[5]);
         mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)),
                                vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b)));
-
-
         mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128);
         mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128);
         rxdataF_comp0_128[2] = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
@@ -3226,37 +2993,27 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms,
         mmtmpD1 = vmull_s16(dl_ch1_128[5], rxdataF128[5]);
         mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)),
                                vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1)));
-
-        mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch1_128[4],*(int16x4_t*)conj)), rxdataF128[4]);
-        mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch1_128[5],*(int16x4_t*)conj)), rxdataF128[5]);
+        mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch1_128[4],*(int16x4_t *)conj)), rxdataF128[4]);
+        mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch1_128[5],*(int16x4_t *)conj)), rxdataF128[5]);
         mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)),
                                vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b)));
-
-
         mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128);
         mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128);
         rxdataF_comp1_128[2] = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1));
       }
     }
 
-
-
     Nre = (pilots==0) ? 12 : 8;
-
     // rx_antennas
   }
 
-
   Nre = (pilots==0) ? 12 : 8;
-
   precoded_signal_strength0 += ((signal_energy_nodc(&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*Nre],
-                                                        (nb_rb*Nre))*rx_power_correction) - (measurements->n0_power[aarx]));
+                                 (nb_rb*Nre))*rx_power_correction) - (measurements->n0_power[aarx]));
   precoded_signal_strength1 += ((signal_energy_nodc(&dl_ch_estimates_ext[aarx+2][symbol*frame_parms->N_RB_DL*Nre],
-                                                        (nb_rb*Nre))*rx_power_correction) - (measurements->n0_power[aarx]));
-
+                                 (nb_rb*Nre))*rx_power_correction) - (measurements->n0_power[aarx]));
   measurements->precoded_cqi_dB[eNB_id][0] = dB_fixed2(precoded_signal_strength0,measurements->n0_power_tot);
   measurements->precoded_cqi_dB[eNB_id][1] = dB_fixed2(precoded_signal_strength1,measurements->n0_power_tot);
-
 #endif
 }
 
@@ -3267,17 +3024,12 @@ void dlsch_dual_stream_correlation(LTE_DL_FRAME_PARMS *frame_parms,
                                    int **dl_ch_estimates_ext,
                                    int **dl_ch_estimates_ext_i,
                                    int **dl_ch_rho_ext,
-                                   unsigned char output_shift)
-{
-
+                                   unsigned char output_shift) {
 #if defined(__x86_64__)||defined(__i386__)
-
   unsigned short rb;
   __m128i *dl_ch128,*dl_ch128i,*dl_ch_rho128,mmtmpD0,mmtmpD1,mmtmpD2,mmtmpD3;
   unsigned char aarx,symbol_mod,pilots=0;
-
   //    printf("dlsch_dual_stream_correlation: symbol %d\n",symbol);
-
   symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol;
 
   if ((symbol_mod == 0) || (symbol_mod == (4-frame_parms->Ncp))) {
@@ -3287,7 +3039,6 @@ void dlsch_dual_stream_correlation(LTE_DL_FRAME_PARMS *frame_parms,
   //  printf("Dual stream correlation (%p)\n",dl_ch_estimates_ext_i);
 
   for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
-
     dl_ch128          = (__m128i *)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12];
 
     if (dl_ch_estimates_ext_i == NULL) // TM3/4
@@ -3304,7 +3055,7 @@ void dlsch_dual_stream_correlation(LTE_DL_FRAME_PARMS *frame_parms,
       // mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
       mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[0],_MM_SHUFFLE(2,3,0,1));
       mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
-      mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)&conjugate[0]);
+      mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)&conjugate[0]);
       mmtmpD1 = _mm_madd_epi16(mmtmpD1,dl_ch128i[0]);
       //      print_ints("im",&mmtmpD1);
       // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
@@ -3317,13 +3068,13 @@ void dlsch_dual_stream_correlation(LTE_DL_FRAME_PARMS *frame_parms,
       //      print_ints("c0",&mmtmpD2);
       //      print_ints("c1",&mmtmpD3);
       dl_ch_rho128[0] = _mm_packs_epi32(mmtmpD2,mmtmpD3);
-    // print_shorts("rho 0:",dl_ch_rho128);
+      // print_shorts("rho 0:",dl_ch_rho128);
       // multiply by conjugated channel
       mmtmpD0 = _mm_madd_epi16(dl_ch128[1],dl_ch128i[1]);
       // mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
       mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[1],_MM_SHUFFLE(2,3,0,1));
       mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
-      mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate);
+      mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)conjugate);
       mmtmpD1 = _mm_madd_epi16(mmtmpD1,dl_ch128i[1]);
       // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
       mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
@@ -3332,15 +3083,13 @@ void dlsch_dual_stream_correlation(LTE_DL_FRAME_PARMS *frame_parms,
       mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1);
       dl_ch_rho128[1] =_mm_packs_epi32(mmtmpD2,mmtmpD3);
 
-
       if (pilots==0) {
-
         // multiply by conjugated channel
         mmtmpD0 = _mm_madd_epi16(dl_ch128[2],dl_ch128i[2]);
         // mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
         mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[2],_MM_SHUFFLE(2,3,0,1));
         mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
-        mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate);
+        mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)conjugate);
         mmtmpD1 = _mm_madd_epi16(mmtmpD1,dl_ch128i[2]);
         // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
         mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
@@ -3348,25 +3097,20 @@ void dlsch_dual_stream_correlation(LTE_DL_FRAME_PARMS *frame_parms,
         mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1);
         mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1);
         dl_ch_rho128[2] = _mm_packs_epi32(mmtmpD2,mmtmpD3);
-
-       dl_ch128+=3;
+        dl_ch128+=3;
         dl_ch128i+=3;
         dl_ch_rho128+=3;
       } else {
-
         dl_ch128+=2;
         dl_ch128i+=2;
         dl_ch_rho128+=2;
       }
     }
-
   }
 
   _mm_empty();
   _m_empty();
-
 #elif defined(__arm__)
-
 #endif
 }
 
@@ -3382,20 +3126,15 @@ void dlsch_detection_mrc(LTE_DL_FRAME_PARMS *frame_parms,
                          int **dl_ch_magb_i,
                          unsigned char symbol,
                          unsigned short nb_rb,
-                         unsigned char dual_stream_UE)
-{
-
+                         unsigned char dual_stream_UE) {
 #if defined(__x86_64__)||defined(__i386__)
-
   unsigned char aatx;
   int i;
   __m128i *rxdataF_comp128_0,*rxdataF_comp128_1,*rxdataF_comp128_i0,*rxdataF_comp128_i1,*dl_ch_mag128_0,*dl_ch_mag128_1,*dl_ch_mag128_0b,*dl_ch_mag128_1b,*rho128_0,*rho128_1,*rho128_i0,*rho128_i1,
-    *dl_ch_mag128_i0,*dl_ch_mag128_i1,*dl_ch_mag128_i0b,*dl_ch_mag128_i1b;
+          *dl_ch_mag128_i0,*dl_ch_mag128_i1,*dl_ch_mag128_i0b,*dl_ch_mag128_i1b;
 
   if (frame_parms->nb_antennas_rx>1) {
-
     for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++) {
-
       rxdataF_comp128_0   = (__m128i *)&rxdataF_comp[(aatx<<1)][symbol*frame_parms->N_RB_DL*12];
       rxdataF_comp128_1   = (__m128i *)&rxdataF_comp[(aatx<<1)+1][symbol*frame_parms->N_RB_DL*12];
       dl_ch_mag128_0      = (__m128i *)&dl_ch_mag[(aatx<<1)][symbol*frame_parms->N_RB_DL*12];
@@ -3404,29 +3143,28 @@ void dlsch_detection_mrc(LTE_DL_FRAME_PARMS *frame_parms,
       dl_ch_mag128_1b     = (__m128i *)&dl_ch_magb[(aatx<<1)+1][symbol*frame_parms->N_RB_DL*12];
 
       // MRC on each re of rb, both on MF output and magnitude (for 16QAM/64QAM llr computation)
-      for (i=0;i<nb_rb*3;i++) {
+      for (i=0; i<nb_rb*3; i++) {
         rxdataF_comp128_0[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_0[i],1),_mm_srai_epi16(rxdataF_comp128_1[i],1));
         dl_ch_mag128_0[i]    = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_0[i],1),_mm_srai_epi16(dl_ch_mag128_1[i],1));
         dl_ch_mag128_0b[i]   = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_0b[i],1),_mm_srai_epi16(dl_ch_mag128_1b[i],1));
-          //       print_shorts("mrc comp0:",&rxdataF_comp128_0[i]);
+        //       print_shorts("mrc comp0:",&rxdataF_comp128_0[i]);
         //       print_shorts("mrc mag0:",&dl_ch_mag128_0[i]);
         //       print_shorts("mrc mag0b:",&dl_ch_mag128_0b[i]);
         //      print_shorts("mrc rho1:",&rho128_1[i]);
-
       }
     }
 
     if (rho) {
       rho128_0 = (__m128i *) &rho[0][symbol*frame_parms->N_RB_DL*12];
       rho128_1 = (__m128i *) &rho[1][symbol*frame_parms->N_RB_DL*12];
-      for (i=0;i<nb_rb*3;i++) {
+
+      for (i=0; i<nb_rb*3; i++) {
         //      print_shorts("mrc rho0:",&rho128_0[i]);
         //      print_shorts("mrc rho1:",&rho128_1[i]);
         rho128_0[i] = _mm_adds_epi16(_mm_srai_epi16(rho128_0[i],1),_mm_srai_epi16(rho128_1[i],1));
       }
     }
 
-
     if (dual_stream_UE == 1) {
       rho128_i0 = (__m128i *) &rho_i[0][symbol*frame_parms->N_RB_DL*12];
       rho128_i1 = (__m128i *) &rho_i[1][symbol*frame_parms->N_RB_DL*12];
@@ -3440,7 +3178,6 @@ void dlsch_detection_mrc(LTE_DL_FRAME_PARMS *frame_parms,
       for (i=0; i<nb_rb*3; i++) {
         rxdataF_comp128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_i0[i],1),_mm_srai_epi16(rxdataF_comp128_i1[i],1));
         rho128_i0[i]           = _mm_adds_epi16(_mm_srai_epi16(rho128_i0[i],1),_mm_srai_epi16(rho128_i1[i],1));
-
         dl_ch_mag128_i0[i]    = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i0[i],1),_mm_srai_epi16(dl_ch_mag128_i1[i],1));
         dl_ch_mag128_i0b[i]    = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i0b[i],1),_mm_srai_epi16(dl_ch_mag128_i1b[i],1));
       }
@@ -3449,17 +3186,14 @@ void dlsch_detection_mrc(LTE_DL_FRAME_PARMS *frame_parms,
 
   _mm_empty();
   _m_empty();
-
 #elif defined(__arm__)
-
   unsigned char aatx;
   int i;
-  int16x8_t *rxdataF_comp128_0,*rxdataF_comp128_1,*rxdataF_comp128_i0,*rxdataF_comp128_i1,*dl_ch_mag128_0,*dl_ch_mag128_1,*dl_ch_mag128_0b,*dl_ch_mag128_1b,*rho128_0,*rho128_1,*rho128_i0,*rho128_i1,*dl_ch_mag128_i0,*dl_ch_mag128_i1,*dl_ch_mag128_i0b,*dl_ch_mag128_i1b;
+  int16x8_t *rxdataF_comp128_0,*rxdataF_comp128_1,*rxdataF_comp128_i0,*rxdataF_comp128_i1,*dl_ch_mag128_0,*dl_ch_mag128_1,*dl_ch_mag128_0b,*dl_ch_mag128_1b,*rho128_0,*rho128_1,*rho128_i0,*rho128_i1,
+            *dl_ch_mag128_i0,*dl_ch_mag128_i1,*dl_ch_mag128_i0b,*dl_ch_mag128_i1b;
 
   if (frame_parms->nb_antennas_rx>1) {
-
     for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++) {
-
       rxdataF_comp128_0   = (int16x8_t *)&rxdataF_comp[(aatx<<1)][symbol*frame_parms->N_RB_DL*12];
       rxdataF_comp128_1   = (int16x8_t *)&rxdataF_comp[(aatx<<1)+1][symbol*frame_parms->N_RB_DL*12];
       dl_ch_mag128_0      = (int16x8_t *)&dl_ch_mag[(aatx<<1)][symbol*frame_parms->N_RB_DL*12];
@@ -3486,13 +3220,11 @@ void dlsch_detection_mrc(LTE_DL_FRAME_PARMS *frame_parms,
       }
     }
 
-
     if (dual_stream_UE == 1) {
       rho128_i0 = (int16x8_t *) &rho_i[0][symbol*frame_parms->N_RB_DL*12];
       rho128_i1 = (int16x8_t *) &rho_i[1][symbol*frame_parms->N_RB_DL*12];
       rxdataF_comp128_i0   = (int16x8_t *)&rxdataF_comp_i[0][symbol*frame_parms->N_RB_DL*12];
       rxdataF_comp128_i1   = (int16x8_t *)&rxdataF_comp_i[1][symbol*frame_parms->N_RB_DL*12];
-
       dl_ch_mag128_i0      = (int16x8_t *)&dl_ch_mag_i[0][symbol*frame_parms->N_RB_DL*12];
       dl_ch_mag128_i1      = (int16x8_t *)&dl_ch_mag_i[1][symbol*frame_parms->N_RB_DL*12];
       dl_ch_mag128_i0b     = (int16x8_t *)&dl_ch_magb_i[0][symbol*frame_parms->N_RB_DL*12];
@@ -3501,7 +3233,6 @@ void dlsch_detection_mrc(LTE_DL_FRAME_PARMS *frame_parms,
       for (i=0; i<nb_rb*3; i++) {
         rxdataF_comp128_i0[i] = vhaddq_s16(rxdataF_comp128_i0[i],rxdataF_comp128_i1[i]);
         rho128_i0[i]          = vhaddq_s16(rho128_i0[i],rho128_i1[i]);
-
         dl_ch_mag128_i0[i]    = vhaddq_s16(dl_ch_mag128_i0[i],dl_ch_mag128_i1[i]);
         dl_ch_mag128_i0b[i]   = vhaddq_s16(dl_ch_mag128_i0b[i],dl_ch_mag128_i1b[i]);
       }
@@ -3518,14 +3249,11 @@ void dlsch_detection_mrc_TM34(LTE_DL_FRAME_PARMS *frame_parms,
                               unsigned char symbol,
                               unsigned short nb_rb,
                               unsigned char dual_stream_UE) {
-
   int i;
   __m128i *rxdataF_comp128_0,*rxdataF_comp128_1;
   __m128i *dl_ch_mag128_0,*dl_ch_mag128_1;
   __m128i *dl_ch_mag128_0b,*dl_ch_mag128_1b;
   __m128i *rho128_0, *rho128_1;
-
-
   int **rxdataF_comp0           = pdsch_vars->rxdataF_comp0;
   int **rxdataF_comp1           = pdsch_vars->rxdataF_comp1[harq_pid][round];
   int **dl_ch_rho_ext           = pdsch_vars->dl_ch_rho_ext[harq_pid][round]; //for second stream
@@ -3534,7 +3262,6 @@ void dlsch_detection_mrc_TM34(LTE_DL_FRAME_PARMS *frame_parms,
   int **dl_ch_mag1              = pdsch_vars->dl_ch_mag1[harq_pid][round];
   int **dl_ch_magb0             = pdsch_vars->dl_ch_magb0;
   int **dl_ch_magb1             = pdsch_vars->dl_ch_magb1[harq_pid][round];
-
   rxdataF_comp128_0   = (__m128i *)&rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12];
   rxdataF_comp128_1   = (__m128i *)&rxdataF_comp0[1][symbol*frame_parms->N_RB_DL*12];
   dl_ch_mag128_0      = (__m128i *)&dl_ch_mag0[0][symbol*frame_parms->N_RB_DL*12];
@@ -3544,15 +3271,14 @@ void dlsch_detection_mrc_TM34(LTE_DL_FRAME_PARMS *frame_parms,
   rho128_0 = (__m128i *) &dl_ch_rho2_ext[0][symbol*frame_parms->N_RB_DL*12];
   rho128_1 = (__m128i *) &dl_ch_rho2_ext[1][symbol*frame_parms->N_RB_DL*12];
 
-      // MRC on each re of rb, both on MF output and magnitude (for 16QAM/64QAM llr computation)
-  for (i=0;i<nb_rb*3;i++) {
+  // MRC on each re of rb, both on MF output and magnitude (for 16QAM/64QAM llr computation)
+  for (i=0; i<nb_rb*3; i++) {
     rxdataF_comp128_0[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_0[i],1),_mm_srai_epi16(rxdataF_comp128_1[i],1));
     dl_ch_mag128_0[i]    = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_0[i],1),_mm_srai_epi16(dl_ch_mag128_1[i],1));
     dl_ch_mag128_0b[i]   = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_0b[i],1),_mm_srai_epi16(dl_ch_mag128_1b[i],1));
     rho128_0[i] = _mm_adds_epi16(_mm_srai_epi16(rho128_0[i],1),_mm_srai_epi16(rho128_1[i],1));
 
     if (frame_parms->nb_antennas_rx>2) {
-
       __m128i *rxdataF_comp128_2 = NULL;
       __m128i *rxdataF_comp128_3 = NULL;
       __m128i *dl_ch_mag128_2 = NULL;
@@ -3561,7 +3287,6 @@ void dlsch_detection_mrc_TM34(LTE_DL_FRAME_PARMS *frame_parms,
       __m128i *dl_ch_mag128_3b = NULL;
       __m128i *rho128_2 = NULL;
       __m128i *rho128_3 = NULL;
-
       rxdataF_comp128_2   = (__m128i *)&rxdataF_comp0[2][symbol*frame_parms->N_RB_DL*12];
       rxdataF_comp128_3   = (__m128i *)&rxdataF_comp0[3][symbol*frame_parms->N_RB_DL*12];
       dl_ch_mag128_2      = (__m128i *)&dl_ch_mag0[2][symbol*frame_parms->N_RB_DL*12];
@@ -3585,65 +3310,58 @@ void dlsch_detection_mrc_TM34(LTE_DL_FRAME_PARMS *frame_parms,
     }
   }
 
-    if (dual_stream_UE == 1) {
-
-      __m128i *dl_ch_mag128_i0, *dl_ch_mag128_i1;
-      __m128i *dl_ch_mag128_i0b, *dl_ch_mag128_i1b;
-      __m128i *rho128_i0, *rho128_i1;
-      __m128i *rxdataF_comp128_i0, *rxdataF_comp128_i1;
-
-      rxdataF_comp128_i0   = (__m128i *)&rxdataF_comp1[0][symbol*frame_parms->N_RB_DL*12];
-      rxdataF_comp128_i1   = (__m128i *)&rxdataF_comp1[1][symbol*frame_parms->N_RB_DL*12];
-      dl_ch_mag128_i0      = (__m128i *)&dl_ch_mag1[0][symbol*frame_parms->N_RB_DL*12];
-      dl_ch_mag128_i1      = (__m128i *)&dl_ch_mag1[1][symbol*frame_parms->N_RB_DL*12];
-      dl_ch_mag128_i0b     = (__m128i *)&dl_ch_magb1[0][symbol*frame_parms->N_RB_DL*12];
-      dl_ch_mag128_i1b     = (__m128i *)&dl_ch_magb1[1][symbol*frame_parms->N_RB_DL*12];
-      rho128_i0 = (__m128i *) &dl_ch_rho_ext[0][symbol*frame_parms->N_RB_DL*12];
-      rho128_i1 = (__m128i *) &dl_ch_rho_ext[1][symbol*frame_parms->N_RB_DL*12];
-
-
-      for (i=0;i<nb_rb*3;i++) {
-        rxdataF_comp128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_i0[i],1),_mm_srai_epi16(rxdataF_comp128_i1[i],1));
-        dl_ch_mag128_i0[i]    = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i0[i],1),_mm_srai_epi16(dl_ch_mag128_i1[i],1));
-        dl_ch_mag128_i0b[i]    = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i0b[i],1),_mm_srai_epi16(dl_ch_mag128_i1b[i],1));
-        rho128_i0[i]           = _mm_adds_epi16(_mm_srai_epi16(rho128_i0[i],1),_mm_srai_epi16(rho128_i1[i],1));
-
-        if (frame_parms->nb_antennas_rx>2) {
-
-          __m128i *rxdataF_comp128_i2 = NULL;
-          __m128i *rxdataF_comp128_i3 = NULL;
-          __m128i *dl_ch_mag128_i2 = NULL;
-          __m128i *dl_ch_mag128_i3 = NULL;
-          __m128i *dl_ch_mag128_i2b = NULL;
-          __m128i *dl_ch_mag128_i3b = NULL;
-          __m128i *rho128_i2 = NULL;
-          __m128i *rho128_i3 = NULL;
-
-          rxdataF_comp128_i2   = (__m128i *)&rxdataF_comp1[2][symbol*frame_parms->N_RB_DL*12];
-          rxdataF_comp128_i3   = (__m128i *)&rxdataF_comp1[3][symbol*frame_parms->N_RB_DL*12];
-          dl_ch_mag128_i2      = (__m128i *)&dl_ch_mag1[2][symbol*frame_parms->N_RB_DL*12];
-          dl_ch_mag128_i3      = (__m128i *)&dl_ch_mag1[3][symbol*frame_parms->N_RB_DL*12];
-          dl_ch_mag128_i2b     = (__m128i *)&dl_ch_magb1[2][symbol*frame_parms->N_RB_DL*12];
-          dl_ch_mag128_i3b     = (__m128i *)&dl_ch_magb1[3][symbol*frame_parms->N_RB_DL*12];
-          rho128_i2 = (__m128i *) &dl_ch_rho_ext[2][symbol*frame_parms->N_RB_DL*12];
-          rho128_i3 = (__m128i *) &dl_ch_rho_ext[3][symbol*frame_parms->N_RB_DL*12];
-
-
-         /*rxdataF_comp*/
-          rxdataF_comp128_i2[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_i2[i],1),_mm_srai_epi16(rxdataF_comp128_i3[i],1));
-          rxdataF_comp128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_i0[i],1),_mm_srai_epi16(rxdataF_comp128_i2[i],1));
-          /*dl_ch_mag*/
-          dl_ch_mag128_i2[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i2[i],1),_mm_srai_epi16(dl_ch_mag128_i3[i],1));
-          dl_ch_mag128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i0[i],1),_mm_srai_epi16(dl_ch_mag128_i2[i],1));
-          /*dl_ch_mag*/
-          dl_ch_mag128_i2b[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i2b[i],1),_mm_srai_epi16(dl_ch_mag128_i3b[i],1));
-          dl_ch_mag128_i0b[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i0b[i],1),_mm_srai_epi16(dl_ch_mag128_i2b[i],1));
-          /*rho*/
-          rho128_i2[i] = _mm_adds_epi16(_mm_srai_epi16(rho128_i2[i],1),_mm_srai_epi16(rho128_i3[i],1));
-          rho128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(rho128_i0[i],1),_mm_srai_epi16(rho128_i2[i],1));
-        }
+  if (dual_stream_UE == 1) {
+    __m128i *dl_ch_mag128_i0, *dl_ch_mag128_i1;
+    __m128i *dl_ch_mag128_i0b, *dl_ch_mag128_i1b;
+    __m128i *rho128_i0, *rho128_i1;
+    __m128i *rxdataF_comp128_i0, *rxdataF_comp128_i1;
+    rxdataF_comp128_i0   = (__m128i *)&rxdataF_comp1[0][symbol*frame_parms->N_RB_DL*12];
+    rxdataF_comp128_i1   = (__m128i *)&rxdataF_comp1[1][symbol*frame_parms->N_RB_DL*12];
+    dl_ch_mag128_i0      = (__m128i *)&dl_ch_mag1[0][symbol*frame_parms->N_RB_DL*12];
+    dl_ch_mag128_i1      = (__m128i *)&dl_ch_mag1[1][symbol*frame_parms->N_RB_DL*12];
+    dl_ch_mag128_i0b     = (__m128i *)&dl_ch_magb1[0][symbol*frame_parms->N_RB_DL*12];
+    dl_ch_mag128_i1b     = (__m128i *)&dl_ch_magb1[1][symbol*frame_parms->N_RB_DL*12];
+    rho128_i0 = (__m128i *) &dl_ch_rho_ext[0][symbol*frame_parms->N_RB_DL*12];
+    rho128_i1 = (__m128i *) &dl_ch_rho_ext[1][symbol*frame_parms->N_RB_DL*12];
+
+    for (i=0; i<nb_rb*3; i++) {
+      rxdataF_comp128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_i0[i],1),_mm_srai_epi16(rxdataF_comp128_i1[i],1));
+      dl_ch_mag128_i0[i]    = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i0[i],1),_mm_srai_epi16(dl_ch_mag128_i1[i],1));
+      dl_ch_mag128_i0b[i]    = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i0b[i],1),_mm_srai_epi16(dl_ch_mag128_i1b[i],1));
+      rho128_i0[i]           = _mm_adds_epi16(_mm_srai_epi16(rho128_i0[i],1),_mm_srai_epi16(rho128_i1[i],1));
+
+      if (frame_parms->nb_antennas_rx>2) {
+        __m128i *rxdataF_comp128_i2 = NULL;
+        __m128i *rxdataF_comp128_i3 = NULL;
+        __m128i *dl_ch_mag128_i2 = NULL;
+        __m128i *dl_ch_mag128_i3 = NULL;
+        __m128i *dl_ch_mag128_i2b = NULL;
+        __m128i *dl_ch_mag128_i3b = NULL;
+        __m128i *rho128_i2 = NULL;
+        __m128i *rho128_i3 = NULL;
+        rxdataF_comp128_i2   = (__m128i *)&rxdataF_comp1[2][symbol*frame_parms->N_RB_DL*12];
+        rxdataF_comp128_i3   = (__m128i *)&rxdataF_comp1[3][symbol*frame_parms->N_RB_DL*12];
+        dl_ch_mag128_i2      = (__m128i *)&dl_ch_mag1[2][symbol*frame_parms->N_RB_DL*12];
+        dl_ch_mag128_i3      = (__m128i *)&dl_ch_mag1[3][symbol*frame_parms->N_RB_DL*12];
+        dl_ch_mag128_i2b     = (__m128i *)&dl_ch_magb1[2][symbol*frame_parms->N_RB_DL*12];
+        dl_ch_mag128_i3b     = (__m128i *)&dl_ch_magb1[3][symbol*frame_parms->N_RB_DL*12];
+        rho128_i2 = (__m128i *) &dl_ch_rho_ext[2][symbol*frame_parms->N_RB_DL*12];
+        rho128_i3 = (__m128i *) &dl_ch_rho_ext[3][symbol*frame_parms->N_RB_DL*12];
+        /*rxdataF_comp*/
+        rxdataF_comp128_i2[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_i2[i],1),_mm_srai_epi16(rxdataF_comp128_i3[i],1));
+        rxdataF_comp128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_i0[i],1),_mm_srai_epi16(rxdataF_comp128_i2[i],1));
+        /*dl_ch_mag*/
+        dl_ch_mag128_i2[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i2[i],1),_mm_srai_epi16(dl_ch_mag128_i3[i],1));
+        dl_ch_mag128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i0[i],1),_mm_srai_epi16(dl_ch_mag128_i2[i],1));
+        /*dl_ch_mag*/
+        dl_ch_mag128_i2b[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i2b[i],1),_mm_srai_epi16(dl_ch_mag128_i3b[i],1));
+        dl_ch_mag128_i0b[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i0b[i],1),_mm_srai_epi16(dl_ch_mag128_i2b[i],1));
+        /*rho*/
+        rho128_i2[i] = _mm_adds_epi16(_mm_srai_epi16(rho128_i2[i],1),_mm_srai_epi16(rho128_i3[i],1));
+        rho128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(rho128_i0[i],1),_mm_srai_epi16(rho128_i2[i],1));
       }
     }
+  }
 
   _mm_empty();
   _m_empty();
@@ -3653,15 +3371,11 @@ void dlsch_scale_channel(int **dl_ch_estimates_ext,
                          LTE_DL_FRAME_PARMS *frame_parms,
                          LTE_UE_DLSCH_t **dlsch_ue,
                          uint8_t symbol,
-                         unsigned short nb_rb)
-{
-
+                         unsigned short nb_rb) {
 #if defined(__x86_64__)||defined(__i386__)
-
   short rb, ch_amp;
   unsigned char aatx,aarx,pilots=0,symbol_mod;
   __m128i *dl_ch128, ch_amp128;
-
   symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol;
 
   if ((symbol_mod == 0) || (symbol_mod == (4-frame_parms->Ncp))) {
@@ -3672,24 +3386,18 @@ void dlsch_scale_channel(int **dl_ch_estimates_ext,
   }
 
   // Determine scaling amplitude based the symbol
-
   ch_amp = ((pilots) ? (dlsch_ue[0]->sqrt_rho_b) : (dlsch_ue[0]->sqrt_rho_a));
-
   LOG_D(PHY,"Scaling PDSCH Chest in OFDM symbol %d by %d, pilots %d nb_rb %d NCP %d symbol %d\n",symbol_mod,ch_amp,pilots,nb_rb,frame_parms->Ncp,symbol);
-   // printf("Scaling PDSCH Chest in OFDM symbol %d by %d\n",symbol_mod,ch_amp);
-
+  // printf("Scaling PDSCH Chest in OFDM symbol %d by %d\n",symbol_mod,ch_amp);
   ch_amp128 = _mm_set1_epi16(ch_amp); // Q3.13
 
   for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++) {
     for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
-
       dl_ch128=(__m128i *)&dl_ch_estimates_ext[(aatx<<1)+aarx][symbol*frame_parms->N_RB_DL*12];
 
-      for (rb=0;rb<nb_rb;rb++) {
-
+      for (rb=0; rb<nb_rb; rb++) {
         dl_ch128[0] = _mm_mulhi_epi16(dl_ch128[0],ch_amp128);
         dl_ch128[0] = _mm_slli_epi16(dl_ch128[0],3);
-
         dl_ch128[1] = _mm_mulhi_epi16(dl_ch128[1],ch_amp128);
         dl_ch128[1] = _mm_slli_epi16(dl_ch128[1],3);
 
@@ -3699,14 +3407,12 @@ void dlsch_scale_channel(int **dl_ch_estimates_ext,
           dl_ch128[2] = _mm_mulhi_epi16(dl_ch128[2],ch_amp128);
           dl_ch128[2] = _mm_slli_epi16(dl_ch128[2],3);
           dl_ch128+=3;
-
         }
       }
     }
   }
 
 #elif defined(__arm__)
-
 #endif
 }
 
@@ -3715,16 +3421,12 @@ void dlsch_channel_level(int **dl_ch_estimates_ext,
                          LTE_DL_FRAME_PARMS *frame_parms,
                          int32_t *avg,
                          uint8_t symbol,
-                         unsigned short nb_rb)
-{
-
+                         unsigned short nb_rb) {
 #if defined(__x86_64__)||defined(__i386__)
   //printf("symbol = %d\n", symbol);
-
   short rb;
   unsigned char aatx,aarx,nre=12,symbol_mod;
   __m128i *dl_ch128, avg128D;
-
   symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol;
 
   if (((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp-1)))&&(frame_parms->nb_antenna_ports_eNB!=1))
@@ -3740,17 +3442,13 @@ void dlsch_channel_level(int **dl_ch_estimates_ext,
 
   for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++)
     for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
-       //clear average level
+      //clear average level
       //printf("aatx = %d, aarx = %d, aatx*frame_parms->nb_antennas_rx + aarx] = %d \n", aatx, aarx, aatx*frame_parms->nb_antennas_rx + aarx);
-
       avg128D = _mm_setzero_si128();
       // 5 is always a symbol with no pilots for both normal and extended prefix
-
-
       dl_ch128=(__m128i *)&dl_ch_estimates_ext[aatx*2 + aarx][symbol*frame_parms->N_RB_DL*12];
 
-      for (rb=0;rb<nb_rb;rb++) {
-
+      for (rb=0; rb<nb_rb; rb++) {
         //printf("rb %d : ",rb);
         avg128D = _mm_add_epi32(avg128D,_mm_srai_epi32(_mm_madd_epi16(dl_ch128[0],dl_ch128[0]),x));
         avg128D = _mm_add_epi32(avg128D,_mm_srai_epi32(_mm_madd_epi16(dl_ch128[1],dl_ch128[1]),x));
@@ -3760,37 +3458,32 @@ void dlsch_channel_level(int **dl_ch_estimates_ext,
 
         if (((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp-1)))&&(frame_parms->nb_antenna_ports_eNB!=1)) {
           dl_ch128+=2;
-        }
-        else {
-           avg128D = _mm_add_epi32(avg128D,_mm_srai_epi32(_mm_madd_epi16(dl_ch128[2],dl_ch128[2]),x));
+        } else {
+          avg128D = _mm_add_epi32(avg128D,_mm_srai_epi32(_mm_madd_epi16(dl_ch128[2],dl_ch128[2]),x));
           //avg128D = _mm_add_epi32(avg128D,_mm_madd_epi16(dl_ch128[2],_mm_srai_epi16(_mm_mulhi_epi16(dl_ch128[2], coeff128),15)));
           dl_ch128+=3;
         }
 
-          /*if(rb==0){
-            print_shorts("dl_ch128",&dl_ch128[0]);
-            print_shorts("dl_ch128",&dl_ch128[1]);
-            print_shorts("dl_ch128",&dl_ch128[2]);
-          }*/
-
+        /*if(rb==0){
+          print_shorts("dl_ch128",&dl_ch128[0]);
+          print_shorts("dl_ch128",&dl_ch128[1]);
+          print_shorts("dl_ch128",&dl_ch128[2]);
+        }*/
       }
 
-      avg[aatx*frame_parms->nb_antennas_rx + aarx] =(((int32_t*)&avg128D)[0] +
-                                                     ((int32_t*)&avg128D)[1] +
-                                                     ((int32_t*)&avg128D)[2] +
-                                                     ((int32_t*)&avg128D)[3])/y;
-      }
+      avg[aatx*frame_parms->nb_antennas_rx + aarx] =(((int32_t *)&avg128D)[0] +
+          ((int32_t *)&avg128D)[1] +
+          ((int32_t *)&avg128D)[2] +
+          ((int32_t *)&avg128D)[3])/y;
+    }
 
   _mm_empty();
   _m_empty();
-
 #elif defined(__arm__)
-
   short rb;
   unsigned char aatx,aarx,nre=12,symbol_mod;
   int32x4_t avg128D;
   int16x4_t *dl_ch128;
-
   symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol;
 
   for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++)
@@ -3798,7 +3491,6 @@ void dlsch_channel_level(int **dl_ch_estimates_ext,
       //clear average level
       avg128D = vdupq_n_s32(0);
       // 5 is always a symbol with no pilots for both normal and extended prefix
-
       dl_ch128=(int16x4_t *)&dl_ch_estimates_ext[aatx*frame_parms->nb_antennas_rx + aarx][symbol*frame_parms->N_RB_DL*12];
 
       for (rb=0; rb<nb_rb; rb++) {
@@ -3833,15 +3525,14 @@ void dlsch_channel_level(int **dl_ch_estimates_ext,
       else
         nre=12;
 
-      avg[aatx*frame_parms->nb_antennas_rx + aarx] = (((int32_t*)&avg128D)[0] +
-                                                          ((int32_t*)&avg128D)[1] +
-                                                          ((int32_t*)&avg128D)[2] +
-                                                          ((int32_t*)&avg128D)[3])/(nb_rb*nre);
-
+      avg[aatx*frame_parms->nb_antennas_rx + aarx] = (((int32_t *)&avg128D)[0] +
+          ((int32_t *)&avg128D)[1] +
+          ((int32_t *)&avg128D)[2] +
+          ((int32_t *)&avg128D)[3])/(nb_rb*nre);
       //printf("Channel level : %d\n",avg[aatx*(frame_parms->nb_antennas_rx-1) + aarx]);
     }
-#endif
 
+#endif
 }
 
 void dlsch_channel_level_core(int **dl_ch_estimates_ext,
@@ -3849,63 +3540,50 @@ void dlsch_channel_level_core(int **dl_ch_estimates_ext,
                               int n_tx,
                               int n_rx,
                               int length,
-                              int start_point)
-{
-
+                              int start_point) {
 #if defined(__x86_64__)||defined(__i386__)
-
   short ii;
   int aatx,aarx;
   int length_mod8;
   int length2;
   __m128i *dl_ch128, avg128D;
-
   int16_t x = factor2(length);
   int16_t y = (length)>>x;
 
   for (aatx=0; aatx<n_tx; aatx++)
     for (aarx=0; aarx<n_rx; aarx++) {
-
       avg128D = _mm_setzero_si128();
-
       dl_ch128=(__m128i *)&dl_ch_estimates_ext[aatx*2 + aarx][start_point];
-
       length_mod8=length&7;
 
-      if (length_mod8 == 0){
-
+      if (length_mod8 == 0) {
         length2 = length>>3;
 
-        for (ii=0;ii<length2;ii++) {
+        for (ii=0; ii<length2; ii++) {
           avg128D = _mm_add_epi32(avg128D,_mm_srai_epi32(_mm_madd_epi16(dl_ch128[0],dl_ch128[0]),x));
           avg128D = _mm_add_epi32(avg128D,_mm_srai_epi32(_mm_madd_epi16(dl_ch128[1],dl_ch128[1]),x));
-
           dl_ch128+=2;
         }
-      }else {
+      } else {
         printf ("Channel level: Received number of subcarriers is not multiple of 4, \n"
-                 "need to adapt the code!\n");
+                "need to adapt the code!\n");
       }
 
-
-      avg[aatx*n_rx + aarx] =(((int32_t*)&avg128D)[0] +
-                              ((int32_t*)&avg128D)[1] +
-                              ((int32_t*)&avg128D)[2] +
-                              ((int32_t*)&avg128D)[3])/y;
+      avg[aatx*n_rx + aarx] =(((int32_t *)&avg128D)[0] +
+                              ((int32_t *)&avg128D)[1] +
+                              ((int32_t *)&avg128D)[2] +
+                              ((int32_t *)&avg128D)[3])/y;
       //printf("Channel level [%d]: %d\n",aatx*n_rx + aarx, avg[aatx*n_rx + aarx]);
-      }
+    }
 
   _mm_empty();
   _m_empty();
-
- /* FIXME This part needs to be adapted like the one above */
+  /* FIXME This part needs to be adapted like the one above */
 #elif defined(__arm__)
-
   short rb;
   unsigned char aatx,aarx,nre=12,symbol_mod;
   int32x4_t avg128D;
   int16x4_t *dl_ch128;
-
   symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol;
 
   for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++)
@@ -3913,7 +3591,6 @@ void dlsch_channel_level_core(int **dl_ch_estimates_ext,
       //clear average level
       avg128D = vdupq_n_s32(0);
       // 5 is always a symbol with no pilots for both normal and extended prefix
-
       dl_ch128=(int16x4_t *)&dl_ch_estimates_ext[aatx*frame_parms->nb_antennas_rx + aarx][symbol*frame_parms->N_RB_DL*12];
 
       for (rb=0; rb<nb_rb; rb++) {
@@ -3933,7 +3610,6 @@ void dlsch_channel_level_core(int **dl_ch_estimates_ext,
         }
       }
 
-
       if (((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp-1)))&&(frame_parms->nb_antenna_ports_eNB!=1))
         nre=8;
       else if (((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp-1)))&&(frame_parms->nb_antenna_ports_eNB==1))
@@ -3941,15 +3617,14 @@ void dlsch_channel_level_core(int **dl_ch_estimates_ext,
       else
         nre=12;
 
-      avg[aatx*frame_parms->nb_antennas_rx + aarx] = (((int32_t*)&avg128D)[0] +
-                                                          ((int32_t*)&avg128D)[1] +
-                                                          ((int32_t*)&avg128D)[2] +
-                                                          ((int32_t*)&avg128D)[3])/(nb_rb*nre);
-
+      avg[aatx*frame_parms->nb_antennas_rx + aarx] = (((int32_t *)&avg128D)[0] +
+          ((int32_t *)&avg128D)[1] +
+          ((int32_t *)&avg128D)[2] +
+          ((int32_t *)&avg128D)[3])/(nb_rb*nre);
       //printf("Channel level : %d\n",avg[aatx*(frame_parms->nb_antennas_rx-1) + aarx]);
     }
-#endif
 
+#endif
 }
 
 void dlsch_channel_level_median(int **dl_ch_estimates_ext,
@@ -3957,11 +3632,8 @@ void dlsch_channel_level_median(int **dl_ch_estimates_ext,
                                 int n_tx,
                                 int n_rx,
                                 int length,
-                                int start_point)
-{
-
+                                int start_point) {
 #if defined(__x86_64__)||defined(__i386__)
-
   short ii;
   int aatx,aarx;
   int length2;
@@ -3969,101 +3641,92 @@ void dlsch_channel_level_median(int **dl_ch_estimates_ext,
   int norm_pack;
   __m128i *dl_ch128, norm128D;
 
-  for (aatx=0; aatx<n_tx; aatx++){
+  for (aatx=0; aatx<n_tx; aatx++) {
     for (aarx=0; aarx<n_rx; aarx++) {
       max = 0;
       min = 0;
       norm128D = _mm_setzero_si128();
-
       dl_ch128=(__m128i *)&dl_ch_estimates_ext[aatx*2 + aarx][start_point];
-
       length2 = length>>2;
 
-      for (ii=0;ii<length2;ii++) {
+      for (ii=0; ii<length2; ii++) {
         norm128D = _mm_srai_epi32( _mm_madd_epi16(dl_ch128[0],dl_ch128[0]), 1);
-          //print_ints("norm128D",&norm128D[0]);
-
-        norm_pack = ((int32_t*)&norm128D)[0] +
-                    ((int32_t*)&norm128D)[1] +
-                    ((int32_t*)&norm128D)[2] +
-                    ((int32_t*)&norm128D)[3];
+        //print_ints("norm128D",&norm128D[0]);
+        norm_pack = ((int32_t *)&norm128D)[0] +
+                    ((int32_t *)&norm128D)[1] +
+                    ((int32_t *)&norm128D)[2] +
+                    ((int32_t *)&norm128D)[3];
 
         if (norm_pack > max)
           max = norm_pack;
+
         if (norm_pack < min)
           min = norm_pack;
 
         dl_ch128+=1;
       }
 
-        median[aatx*n_rx + aarx]  = (max+min)>>1;
-
-     // printf("Channel level  median [%d]: %d\n",aatx*n_rx + aarx, median[aatx*n_rx + aarx]);
-      }
+      median[aatx*n_rx + aarx]  = (max+min)>>1;
+      // printf("Channel level  median [%d]: %d\n",aatx*n_rx + aarx, median[aatx*n_rx + aarx]);
     }
+  }
 
   _mm_empty();
   _m_empty();
-
 #elif defined(__arm__)
-
   short rb;
   unsigned char aatx,aarx,nre=12,symbol_mod;
   int32x4_t norm128D;
   int16x4_t *dl_ch128;
 
-  for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++){
+  for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++) {
     for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
       max = 0;
       min = 0;
       norm128D = vdupq_n_s32(0);
-
       dl_ch128=(int16x4_t *)&dl_ch_estimates_ext[aatx*n_rx + aarx][start_point];
-
       length_mod8=length&3;
       length2 = length>>2;
 
-      for (ii=0;ii<length2;ii++) {
+      for (ii=0; ii<length2; ii++) {
         norm128D = vshrq_n_u32(vmull_s16(dl_ch128[0],dl_ch128[0]), 1);
-        norm_pack = ((int32_t*)&norm128D)[0] +
-                    ((int32_t*)&norm128D)[1] +
-                    ((int32_t*)&norm128D)[2] +
-                    ((int32_t*)&norm128D)[3];
+        norm_pack = ((int32_t *)&norm128D)[0] +
+                    ((int32_t *)&norm128D)[1] +
+                    ((int32_t *)&norm128D)[2] +
+                    ((int32_t *)&norm128D)[3];
 
         if (norm_pack > max)
           max = norm_pack;
+
         if (norm_pack < min)
           min = norm_pack;
 
-          dl_ch128+=1;
+        dl_ch128+=1;
       }
 
-        median[aatx*n_rx + aarx]  = (max+min)>>1;
-
+      median[aatx*n_rx + aarx]  = (max+min)>>1;
       //printf("Channel level  median [%d]: %d\n",aatx*n_rx + aarx, median[aatx*n_rx + aarx]);
-      }
     }
-#endif
+  }
 
+#endif
 }
 
 void mmse_processing_oai(LTE_UE_PDSCH *pdsch_vars,
-                     LTE_DL_FRAME_PARMS *frame_parms,
-                     PHY_MEASUREMENTS *measurements,
-                     unsigned char first_symbol_flag,
-                     MIMO_mode_t mimo_mode,
-                     unsigned short mmse_flag,
-                     int noise_power,
-                     unsigned char symbol,
-                     unsigned short nb_rb){
-
+                         LTE_DL_FRAME_PARMS *frame_parms,
+                         PHY_MEASUREMENTS *measurements,
+                         unsigned char first_symbol_flag,
+                         MIMO_mode_t mimo_mode,
+                         unsigned short mmse_flag,
+                         int noise_power,
+                         unsigned char symbol,
+                         unsigned short nb_rb) {
   int **rxdataF_ext           = pdsch_vars->rxdataF_ext;
   int **dl_ch_estimates_ext   = pdsch_vars->dl_ch_estimates_ext;
   unsigned char *pmi_ext      = pdsch_vars->pmi_ext;
   int avg_00[frame_parms->nb_antenna_ports_eNB*frame_parms->nb_antennas_rx];
   int avg_01[frame_parms->nb_antenna_ports_eNB*frame_parms->nb_antennas_rx];
   int symbol_mod, length, start_point, nre;
-
   symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol;
 
   if (((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp-1)))&&(frame_parms->nb_antenna_ports_eNB!=1))
@@ -4075,8 +3738,6 @@ void mmse_processing_oai(LTE_UE_PDSCH *pdsch_vars,
 
   length  = nre*nb_rb;
   start_point = symbol*nb_rb*12;
-
-
   mmse_processing_core(rxdataF_ext,
                        dl_ch_estimates_ext,
                        noise_power,
@@ -4085,7 +3746,6 @@ void mmse_processing_oai(LTE_UE_PDSCH *pdsch_vars,
                        length,
                        start_point);
 
-
   /*dlsch_channel_aver_band(dl_ch_estimates_ext,
                           frame_parms,
                           chan_avg,
@@ -4099,21 +3759,20 @@ void mmse_processing_oai(LTE_UE_PDSCH *pdsch_vars,
       // printf("H [%d] = (%f, %f) \n", aatx*frame_parms->nb_antennas_rx + aarx, creal(H[aatx*frame_parms->nb_antennas_rx + aarx]), cimag(H[aatx*frame_parms->nb_antennas_rx + aarx]));
    }*/
 
-    if (first_symbol_flag == 1){
-      dlsch_channel_level_TM34(dl_ch_estimates_ext,
-                                 frame_parms,
-                                 pmi_ext,
-                                 avg_00,
-                                 avg_01,
-                                 symbol,
-                                 nb_rb,
-                                 mmse_flag,
-                                 mimo_mode);
-
-      avg_00[0] = (log2_approx(avg_00[0])/2) + dlsch_demod_shift+4;// + 2 ;//+ 4;
-      avg_01[0] = (log2_approx(avg_01[0])/2) + dlsch_demod_shift+4;// + 2 ;//+ 4;
-      pdsch_vars->log2_maxh0 = cmax(avg_00[0],0);
-      pdsch_vars->log2_maxh1 = cmax(avg_01[0],0);
+  if (first_symbol_flag == 1) {
+    dlsch_channel_level_TM34(dl_ch_estimates_ext,
+                             frame_parms,
+                             pmi_ext,
+                             avg_00,
+                             avg_01,
+                             symbol,
+                             nb_rb,
+                             mmse_flag,
+                             mimo_mode);
+    avg_00[0] = (log2_approx(avg_00[0])/2) + dlsch_demod_shift+4;// + 2 ;//+ 4;
+    avg_01[0] = (log2_approx(avg_01[0])/2) + dlsch_demod_shift+4;// + 2 ;//+ 4;
+    pdsch_vars->log2_maxh0 = cmax(avg_00[0],0);
+    pdsch_vars->log2_maxh1 = cmax(avg_01[0],0);
   }
 }
 
@@ -4123,27 +3782,26 @@ void mmse_processing_core(int32_t **rxdataF_ext,
                           int n_tx,
                           int n_rx,
                           int length,
-                          int start_point){
-
+                          int start_point) {
   int aatx, aarx, re;
   float imag;
   float real;
+  float complex **W_MMSE= malloc(n_tx*n_rx*sizeof(float complex *));
 
-
-  float complex **W_MMSE= malloc(n_tx*n_rx*sizeof(float complex*));
-   for (int j=0; j<n_tx*n_rx; j++) {
-     W_MMSE[j] = malloc(sizeof(float complex)*length);
+  for (int j=0; j<n_tx*n_rx; j++) {
+    W_MMSE[j] = malloc(sizeof(float complex)*length);
   }
 
   float complex *H=  malloc(n_tx*n_rx*sizeof(float complex));
   float complex *W_MMSE_re=  malloc(n_tx*n_rx*sizeof(float complex));
+  float complex **dl_ch_estimates_ext_flcpx = malloc(n_tx*n_rx*sizeof(float complex *));
 
-  float complex** dl_ch_estimates_ext_flcpx = malloc(n_tx*n_rx*sizeof(float complex*));
   for (int j=0; j<n_tx*n_rx; j++) {
     dl_ch_estimates_ext_flcpx[j] = malloc(sizeof(float complex)*length);
   }
 
-  float complex** rxdataF_ext_flcpx = malloc(n_rx*sizeof(float complex*));
+  float complex **rxdataF_ext_flcpx = malloc(n_rx*sizeof(float complex *));
+
   for (int j=0; j<n_rx; j++) {
     rxdataF_ext_flcpx[j] = malloc(sizeof(float complex)*length);
   }
@@ -4155,16 +3813,18 @@ void mmse_processing_core(int32_t **rxdataF_ext,
                     length,
                     start_point);
 
-  for (re=0; re<length; re++){
-    for (aatx=0; aatx<n_tx; aatx++){
+  for (re=0; re<length; re++) {
+    for (aatx=0; aatx<n_tx; aatx++) {
       for (aarx=0; aarx<n_rx; aarx++) {
         imag = cimag(dl_ch_estimates_ext_flcpx[aatx*n_rx + aarx][re]);
         real = creal(dl_ch_estimates_ext_flcpx[aatx*n_rx + aarx][re]);
         H[aatx*n_rx + aarx] = real+ I*imag;
       }
     }
+
     compute_MMSE(H, n_tx, noise_power, W_MMSE_re);
-    for (aatx=0; aatx<n_tx; aatx++){
+
+    for (aatx=0; aatx<n_tx; aatx++) {
       for (aarx=0; aarx<n_rx; aarx++) {
         W_MMSE[aatx*n_rx + aarx][re] = W_MMSE_re[aatx*n_rx + aarx];
       }
@@ -4176,49 +3836,40 @@ void mmse_processing_core(int32_t **rxdataF_ext,
                    n_rx,
                    length,
                    start_point);
-
   mult_mmse_rxdataF(W_MMSE,
                     rxdataF_ext_flcpx,
                     n_tx,
                     n_rx,
                     length,
                     start_point);
-
-
   mult_mmse_chan_est(W_MMSE,
                      dl_ch_estimates_ext_flcpx,
                      n_tx,
                      n_rx,
                      length,
                      start_point);
-
-
   float_to_rxdataF(rxdataF_ext,
                    rxdataF_ext_flcpx,
                    n_tx,
                    n_rx,
                    length,
                    start_point);
-
-
   float_to_chan_est(dl_ch_estimates_ext,
                     dl_ch_estimates_ext_flcpx,
                     n_tx,
                     n_rx,
                     length,
                     start_point);
-
-free(W_MMSE);
-free(H);
-free(W_MMSE_re);
-free(dl_ch_estimates_ext_flcpx);
-free(rxdataF_ext_flcpx);
-
+  free(W_MMSE);
+  free(H);
+  free(W_MMSE_re);
+  free(dl_ch_estimates_ext_flcpx);
+  free(rxdataF_ext_flcpx);
 }
 
 
 /*THIS FUNCTION TAKES FLOAT_POINT INPUT. SHOULD NOT BE USED WITH OAI*/
-void mmse_processing_core_flp(float complex** rxdataF_ext_flcpx,
+void mmse_processing_core_flp(float complex **rxdataF_ext_flcpx,
                               float complex **H,
                               int32_t **rxdataF_ext,
                               int32_t **dl_ch_estimates_ext,
@@ -4226,79 +3877,85 @@ void mmse_processing_core_flp(float complex** rxdataF_ext_flcpx,
                               int n_tx,
                               int n_rx,
                               int length,
-                              int start_point){
-
+                              int start_point) {
   int aatx, aarx, re;
   float max = 0;
   float one_over_max = 0;
+  float complex **W_MMSE= malloc(n_tx*n_rx*sizeof(float complex *));
 
-  float complex **W_MMSE= malloc(n_tx*n_rx*sizeof(float complex*));
-   for (int j=0; j<n_tx*n_rx; j++) {
-     W_MMSE[j] = malloc(sizeof(float complex)*length);
+  for (int j=0; j<n_tx*n_rx; j++) {
+    W_MMSE[j] = malloc(sizeof(float complex)*length);
   }
 
   float complex *H_re=  malloc(n_tx*n_rx*sizeof(float complex));
   float complex *W_MMSE_re=  malloc(n_tx*n_rx*sizeof(float complex));
 
-  for (re=0; re<length; re++){
-    for (aatx=0; aatx<n_tx; aatx++){
+  for (re=0; re<length; re++) {
+    for (aatx=0; aatx<n_tx; aatx++) {
       for (aarx=0; aarx<n_rx; aarx++) {
         H_re[aatx*n_rx + aarx] = H[aatx*n_rx + aarx][re];
 #ifdef DEBUG_MMSE
+
         if (re == 0)
-        printf(" H_re[%d]= (%f + i%f)\n", aatx*n_rx + aarx, creal(H_re[aatx*n_rx + aarx]), cimag(H_re[aatx*n_rx + aarx]));
+          printf(" H_re[%d]= (%f + i%f)\n", aatx*n_rx + aarx, creal(H_re[aatx*n_rx + aarx]), cimag(H_re[aatx*n_rx + aarx]));
+
 #endif
       }
     }
+
     compute_MMSE(H_re, n_tx, noise_power, W_MMSE_re);
-    for (aatx=0; aatx<n_tx; aatx++){
+
+    for (aatx=0; aatx<n_tx; aatx++) {
       for (aarx=0; aarx<n_rx; aarx++) {
         W_MMSE[aatx*n_rx + aarx][re] = W_MMSE_re[aatx*n_rx + aarx];
+
         if (fabs(creal(W_MMSE_re[aatx*n_rx + aarx])) > max)
           max = fabs(creal(W_MMSE_re[aatx*n_rx + aarx]));
+
         if (fabs(cimag(W_MMSE_re[aatx*n_rx + aarx])) > max)
           max = fabs(cimag(W_MMSE_re[aatx*n_rx + aarx]));
       }
     }
   }
+
   one_over_max = 1.0/max;
 
   for (re=0; re<length; re++)
     for (aatx=0; aatx<n_tx; aatx++)
-      for (aarx=0; aarx<n_rx; aarx++){
+      for (aarx=0; aarx<n_rx; aarx++) {
 #ifdef DEBUG_MMSE
+
         if (re == 0)
           printf(" W_MMSE[%d] = (%f + i%f)\n", aatx*n_rx + aarx, creal(W_MMSE[aatx*n_rx + aarx][re]), cimag(W_MMSE[aatx*n_rx + aarx][re]));
+
 #endif
         W_MMSE[aatx*n_rx + aarx][re] = one_over_max*W_MMSE[aatx*n_rx + aarx][re];
 #ifdef DEBUG_MMSE
+
         if (re == 0)
           printf(" AFTER NORM W_MMSE[%d] = (%f + i%f), max = %f \n", aatx*n_rx + aarx, creal(W_MMSE[aatx*n_rx + aarx][re]), cimag(W_MMSE[aatx*n_rx + aarx][re]), max);
+
 #endif
       }
 
-
   mult_mmse_rxdataF(W_MMSE,
                     rxdataF_ext_flcpx,
                     n_tx,
                     n_rx,
                     length,
                     start_point);
-
   mult_mmse_chan_est(W_MMSE,
                      H,
                      n_tx,
                      n_rx,
                      length,
                      start_point);
-
   float_to_rxdataF(rxdataF_ext,
                    rxdataF_ext_flcpx,
                    n_tx,
                    n_rx,
                    length,
                    start_point);
-
   float_to_chan_est(dl_ch_estimates_ext,
                     H,
                     n_tx,
@@ -4308,7 +3965,6 @@ void mmse_processing_core_flp(float complex** rxdataF_ext_flcpx,
   free(H_re);
   free(W_MMSE);
   free(W_MMSE_re);
-
 }
 
 
@@ -4316,16 +3972,12 @@ void dlsch_channel_aver_band(int **dl_ch_estimates_ext,
                              LTE_DL_FRAME_PARMS *frame_parms,
                              struct complex32 *chan_avg,
                              unsigned char symbol,
-                             unsigned short nb_rb)
-{
-
+                             unsigned short nb_rb) {
 #if defined(__x86_64__)||defined(__i386__)
-
   short rb;
   unsigned char aatx,aarx,nre=12,symbol_mod;
   __m128i *dl_ch128, avg128D;
   int32_t chan_est_avg[4];
-
   symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol;
 
   if (((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp-1)))&&(frame_parms->nb_antenna_ports_eNB!=1))
@@ -4335,97 +3987,89 @@ void dlsch_channel_aver_band(int **dl_ch_estimates_ext,
   else
     nre=12;
 
-  for (aatx=0; aatx<frame_parms->nb_antennas_tx; aatx++){
+  for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++) {
     for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
       dl_ch128=(__m128i *)&dl_ch_estimates_ext[aatx*frame_parms->nb_antennas_rx + aarx][symbol*frame_parms->N_RB_DL*12];
       avg128D = _mm_setzero_si128();
-     //  print_shorts("avg128D 1",&avg128D);
+      //  print_shorts("avg128D 1",&avg128D);
 
-      for (rb=0;rb<nb_rb;rb++) {
+      for (rb=0; rb<nb_rb; rb++) {
         /*  printf("symbol %d, ant %d, nre*nrb %d, rb %d \n", symbol, aatx*frame_parms->nb_antennas_rx + aarx, nb_rb*nre, rb);
           print_shorts("aver dl_ch128",&dl_ch128[0]);
           print_shorts("aver dl_ch128",&dl_ch128[1]);
           print_shorts("aver dl_ch128",&dl_ch128[2]);
         avg128D = _mm_add_epi16(avg128D, dl_ch128[0]);*/
         //print_shorts("avg128D 2",&avg128D);
-
         avg128D = _mm_add_epi16(avg128D, dl_ch128[1]);
-       //  print_shorts("avg128D 3",&avg128D);
+        //  print_shorts("avg128D 3",&avg128D);
 
         if (((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp-1)))&&(frame_parms->nb_antenna_ports_eNB!=1)) {
           dl_ch128+=2;
-        }else {
+        } else {
           avg128D = _mm_add_epi16(avg128D,dl_ch128[2]);
-         //  print_shorts("avg128D 4",&avg128D);
+          //  print_shorts("avg128D 4",&avg128D);
           dl_ch128+=3;
         }
       }
 
-      chan_avg[aatx*frame_parms->nb_antennas_rx + aarx].r =(((int16_t*)&avg128D)[0] +
-                                                              ((int16_t*)&avg128D)[2] +
-                                                              ((int16_t*)&avg128D)[4] +
-                                                              ((int16_t*)&avg128D)[6])/(nb_rb*nre);
-    //  printf("symb %d chan_avg re [%d] = %d\n", symbol, aatx*frame_parms->nb_antennas_rx + aarx, chan_avg[aatx*frame_parms->nb_antennas_rx + aarx].r);
-
-
-
-      chan_avg[aatx*frame_parms->nb_antennas_rx + aarx].i =(((int16_t*)&avg128D)[1] +
-                                                            ((int16_t*)&avg128D)[3] +
-                                                            ((int16_t*)&avg128D)[5] +
-                                                            ((int16_t*)&avg128D)[7])/(nb_rb*nre);
-    //  printf("symb %d chan_avg im [%d] = %d\n", symbol, aatx*frame_parms->nb_antennas_rx + aarx, chan_avg[aatx*frame_parms->nb_antennas_rx + aarx].i);
-
+      chan_avg[aatx*frame_parms->nb_antennas_rx + aarx].r =(((int16_t *)&avg128D)[0] +
+          ((int16_t *)&avg128D)[2] +
+          ((int16_t *)&avg128D)[4] +
+          ((int16_t *)&avg128D)[6])/(nb_rb*nre);
+      //  printf("symb %d chan_avg re [%d] = %d\n", symbol, aatx*frame_parms->nb_antennas_rx + aarx, chan_avg[aatx*frame_parms->nb_antennas_rx + aarx].r);
+      chan_avg[aatx*frame_parms->nb_antennas_rx + aarx].i =(((int16_t *)&avg128D)[1] +
+          ((int16_t *)&avg128D)[3] +
+          ((int16_t *)&avg128D)[5] +
+          ((int16_t *)&avg128D)[7])/(nb_rb*nre);
+      //  printf("symb %d chan_avg im [%d] = %d\n", symbol, aatx*frame_parms->nb_antennas_rx + aarx, chan_avg[aatx*frame_parms->nb_antennas_rx + aarx].i);
       //printf("symb %d chan_avg im [%d] = %d\n", symbol, aatx*frame_parms->nb_antennas_rx + aarx, chan_avg[aatx*frame_parms->nb_antennas_rx + aarx].i);
-
-
       chan_est_avg[aatx*frame_parms->nb_antennas_rx + aarx] = (((int32_t)chan_avg[aatx*frame_parms->nb_antennas_rx + aarx].i)<<16)|(((int32_t)chan_avg[aatx*frame_parms->nb_antennas_rx + aarx].r) & 0xffff);
-
       //printf("symb %d chan_est_avg [%d] = %d\n", symbol, aatx*frame_parms->nb_antennas_rx + aarx, chan_est_avg[aatx*frame_parms->nb_antennas_rx + aarx]);
-
       dl_ch128=(__m128i *)&dl_ch_estimates_ext[aatx*frame_parms->nb_antennas_rx + aarx][symbol*frame_parms->N_RB_DL*12];
 
-      for (rb=0;rb<nb_rb;rb++) {
+      for (rb=0; rb<nb_rb; rb++) {
         dl_ch128[0] = _mm_set1_epi32(chan_est_avg[aatx*frame_parms->nb_antennas_rx + aarx]);
         dl_ch128[1] = _mm_set1_epi32(chan_est_avg[aatx*frame_parms->nb_antennas_rx + aarx]);
+
         if (((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp-1)))&&(frame_parms->nb_antenna_ports_eNB!=1)) {
           dl_ch128+=2;
-        }else {
-        dl_ch128[2] = _mm_set1_epi32(chan_est_avg[aatx*frame_parms->nb_antennas_rx + aarx]);
+        } else {
+          dl_ch128[2] = _mm_set1_epi32(chan_est_avg[aatx*frame_parms->nb_antennas_rx + aarx]);
           dl_ch128+=3;
         }
-       }
-     }
-   }
-
-    _mm_empty();
-    _m_empty();
+      }
+    }
+  }
 
+  _mm_empty();
+  _m_empty();
 #elif defined(__arm__)
 #endif
-  }
+}
 
 void rxdataF_to_float(int32_t **rxdataF_ext,
                       float complex **rxdataF_f,
                       int n_rx,
                       int length,
-                      int start_point)
-{
+                      int start_point) {
   short re;
   int aarx;
   int16_t imag;
   int16_t real;
 
   for (aarx=0; aarx<n_rx; aarx++) {
-    for (re=0; re<length; re++){
+    for (re=0; re<length; re++) {
       imag = (int16_t) (rxdataF_ext[aarx][start_point + re] >> 16);
       real = (int16_t) (rxdataF_ext[aarx][start_point + re] & 0xffff);
       rxdataF_f[aarx][re] = (float)(real/(32768.0)) + I*(float)(imag/(32768.0));
 #ifdef DEBUG_MMSE
-        if (re==0){
-          printf("rxdataF_to_float: aarx = %d, real= %d, imag = %d\n", aarx, real, imag);
-          //printf("rxdataF_to_float: rxdataF_ext[%d][%d] = %d\n", aarx, start_point + re, rxdataF_ext[aarx][start_point + re]);
-          //printf("rxdataF_to_float: ant %d, re = %d, rxdataF_f real = %f, rxdataF_f imag = %f \n", aarx, re, creal(rxdataF_f[aarx][re]), cimag(rxdataF_f[aarx][re]));
-        }
+
+      if (re==0) {
+        printf("rxdataF_to_float: aarx = %d, real= %d, imag = %d\n", aarx, real, imag);
+        //printf("rxdataF_to_float: rxdataF_ext[%d][%d] = %d\n", aarx, start_point + re, rxdataF_ext[aarx][start_point + re]);
+        //printf("rxdataF_to_float: ant %d, re = %d, rxdataF_f real = %f, rxdataF_f imag = %f \n", aarx, re, creal(rxdataF_f[aarx][re]), cimag(rxdataF_f[aarx][re]));
+      }
+
 #endif
     }
   }
@@ -4438,66 +4082,68 @@ void chan_est_to_float(int32_t **dl_ch_estimates_ext,
                        int n_tx,
                        int n_rx,
                        int length,
-                       int start_point)
-{
+                       int start_point) {
   short re;
   int aatx,aarx;
   int16_t imag;
   int16_t real;
 
-  for (aatx=0; aatx<n_tx; aatx++){
+  for (aatx=0; aatx<n_tx; aatx++) {
     for (aarx=0; aarx<n_rx; aarx++) {
-      for (re=0; re<length; re++){
+      for (re=0; re<length; re++) {
         imag = (int16_t) (dl_ch_estimates_ext[aatx*n_rx + aarx][start_point + re] >> 16);
         real = (int16_t) (dl_ch_estimates_ext[aatx*n_rx + aarx][start_point+ re] & 0xffff);
         dl_ch_estimates_ext_f[aatx*n_rx + aarx][re] = (float)(real/(32768.0)) + I*(float)(imag/(32768.0));
 #ifdef DEBUG_MMSE
-        if (re==0){
+
+        if (re==0) {
           printf("ant %d, re = %d, real = %d, imag = %d \n", aatx*n_rx + aarx, re, real, imag);
           printf("ant %d, re = %d, real = %f, imag = %f \n", aatx*n_rx + aarx, re, creal(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re]), cimag(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re]));
         }
+
 #endif
-     }
+      }
     }
   }
 }
 
 void float_to_chan_est(int32_t **dl_ch_estimates_ext,
-                      float complex **dl_ch_estimates_ext_f,
-                      int n_tx,
-                      int n_rx,
-                      int length,
-                      int start_point)
-{
-
+                       float complex **dl_ch_estimates_ext_f,
+                       int n_tx,
+                       int n_rx,
+                       int length,
+                       int start_point) {
   short re;
   int aarx, aatx;
   int16_t imag;
   int16_t real;
 
-  for (aatx=0; aatx<n_tx; aatx++){
+  for (aatx=0; aatx<n_tx; aatx++) {
     for (aarx=0; aarx<n_rx; aarx++) {
-      for (re=0; re<length; re++){
+      for (re=0; re<length; re++) {
         if (cimag(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re])<-1)
-           imag = 0x8000;
-         else if (cimag(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re])>=1)
-           imag = 0x7FFF;
-         else
+          imag = 0x8000;
+        else if (cimag(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re])>=1)
+          imag = 0x7FFF;
+        else
           imag = cimag(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re])*32768;
-         if (creal(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re])<-1)
-           real = 0x8000;
-         else if (creal(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re])>=1)
-           real = 0x7FFF;
-         else
-           real = creal(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re])*32768;
-
-         dl_ch_estimates_ext[aatx*n_rx + aarx][start_point + re] = (((int32_t)imag)<<16)|((int32_t)real & 0xffff);
+
+        if (creal(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re])<-1)
+          real = 0x8000;
+        else if (creal(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re])>=1)
+          real = 0x7FFF;
+        else
+          real = creal(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re])*32768;
+
+        dl_ch_estimates_ext[aatx*n_rx + aarx][start_point + re] = (((int32_t)imag)<<16)|((int32_t)real & 0xffff);
 #ifdef DEBUG_MMSE
-        if (re==0){
+
+        if (re==0) {
           printf(" float_to_chan_est: chan est real = %f, chan est imag = %f\n",creal(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re]), cimag(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re]));
           printf("float_to_chan_est: real fixed = %d, imag fixed = %d\n", real, imag);
           printf("float_to_chan_est: ant %d, re = %d, dl_ch_estimates_ext = %d \n", aatx*n_rx + aarx, re,  dl_ch_estimates_ext[aatx*n_rx + aarx][start_point + re]);
         }
+
 #endif
       }
     }
@@ -4510,76 +4156,81 @@ void float_to_rxdataF(int32_t **rxdataF_ext,
                       int n_tx,
                       int n_rx,
                       int length,
-                      int start_point)
-{
-
+                      int start_point) {
   short re;
   int aarx;
   int16_t imag;
   int16_t real;
 
   for (aarx=0; aarx<n_rx; aarx++) {
-    for (re=0; re<length; re++){
+    for (re=0; re<length; re++) {
       if (cimag(rxdataF_f[aarx][re])<-1)
         imag = 0x8000;
       else if (cimag(rxdataF_f[aarx][re])>=1)
         imag = 0x7FFF;
       else
         imag = cimag(rxdataF_f[aarx][re])*32768;
+
       if (creal(rxdataF_f[aarx][re])<-1)
         real = 0x8000;
       else if (creal(rxdataF_f[aarx][re])>=1)
         real = 0x7FFF;
       else
         real = creal(rxdataF_f[aarx][re])*32768;
+
       rxdataF_ext[aarx][start_point + re] = (((int32_t)imag)<<16)|(((int32_t)real) & 0xffff);
 #ifdef DEBUG_MMSE
-        if (re==0){
-          printf(" float_to_rxdataF: real = %f, imag = %f\n",creal(rxdataF_f[aarx][re]), cimag(rxdataF_f[aarx][re]));
-          printf("float_to_rxdataF: real fixed = %d, imag fixed = %d\n", real, imag);
-          printf("float_to_rxdataF: ant %d, re = %d, rxdataF_ext = %d \n", aarx, re,  rxdataF_ext[aarx][start_point + re]);
-        }
-#endif
+
+      if (re==0) {
+        printf(" float_to_rxdataF: real = %f, imag = %f\n",creal(rxdataF_f[aarx][re]), cimag(rxdataF_f[aarx][re]));
+        printf("float_to_rxdataF: real fixed = %d, imag fixed = %d\n", real, imag);
+        printf("float_to_rxdataF: ant %d, re = %d, rxdataF_ext = %d \n", aarx, re,  rxdataF_ext[aarx][start_point + re]);
       }
+
+#endif
     }
+  }
 }
 
 
-void mult_mmse_rxdataF(float complex** Wmmse,
-                       float complex** rxdataF_ext_f,
+void mult_mmse_rxdataF(float complex **Wmmse,
+                       float complex **rxdataF_ext_f,
                        int n_tx,
                        int n_rx,
                        int length,
-                       int start_point)
-{
+                       int start_point) {
   short re;
   int aarx, aatx;
+  float complex *rxdata_re =  malloc(n_rx*sizeof(float complex));
+  float complex *rxdata_mmse_re =  malloc(n_rx*sizeof(float complex));
+  float complex *Wmmse_re =  malloc(n_tx*n_rx*sizeof(float complex));
 
-
-  float complex* rxdata_re =  malloc(n_rx*sizeof(float complex));
-  float complex* rxdata_mmse_re =  malloc(n_rx*sizeof(float complex));
-  float complex* Wmmse_re =  malloc(n_tx*n_rx*sizeof(float complex));
-
-  for (re=0;re<length; re++){
-    for (aarx=0; aarx<n_rx; aarx++){
+  for (re=0; re<length; re++) {
+    for (aarx=0; aarx<n_rx; aarx++) {
       rxdata_re[aarx] = rxdataF_ext_f[aarx][re];
 #ifdef DEBUG_MMSE
+
       if (re==0)
         printf("mult_mmse_rxdataF before: rxdata_re[%d] = (%f, %f)\n", aarx, creal(rxdata_re[aarx]), cimag(rxdata_re[aarx]));
+
 #endif
-     }
-    for (aatx=0; aatx<n_tx; aatx++){
-      for (aarx=0; aarx<n_rx; aarx++){
+    }
+
+    for (aatx=0; aatx<n_tx; aatx++) {
+      for (aarx=0; aarx<n_rx; aarx++) {
         Wmmse_re[aatx*n_rx + aarx] = Wmmse[aatx*n_rx + aarx][re];
       }
     }
+
     mutl_matrix_matrix_col_based(Wmmse_re, rxdata_re, n_rx, n_tx, n_rx, 1, rxdata_mmse_re);
 
-    for (aarx=0; aarx<n_rx; aarx++){
+    for (aarx=0; aarx<n_rx; aarx++) {
       rxdataF_ext_f[aarx][re] = rxdata_mmse_re[aarx];
 #ifdef DEBUG_MMSE
-       if (re==0)
+
+      if (re==0)
         printf("mult_mmse_rxdataF after: rxdataF_ext_f[%d] = (%f, %f)\n", aarx, creal(rxdataF_ext_f[aarx][re]), cimag(rxdataF_ext_f[aarx][re]));
+
 #endif
     }
   }
@@ -4589,45 +4240,50 @@ void mult_mmse_rxdataF(float complex** Wmmse,
   free(Wmmse_re);
 }
 
-void mult_mmse_chan_est(float complex** Wmmse,
-                        float complex** dl_ch_estimates_ext_f,
+void mult_mmse_chan_est(float complex **Wmmse,
+                        float complex **dl_ch_estimates_ext_f,
                         int n_tx,
                         int n_rx,
                         int length,
-                        int start_point)
-{
+                        int start_point) {
   short re;
   int aarx, aatx;
+  float complex *chan_est_re =  malloc(n_tx*n_rx*sizeof(float complex));
+  float complex *chan_est_mmse_re =  malloc(n_tx*n_rx*sizeof(float complex));
+  float complex *Wmmse_re =  malloc(n_tx*n_rx*sizeof(float complex));
 
-  float complex* chan_est_re =  malloc(n_tx*n_rx*sizeof(float complex));
-  float complex* chan_est_mmse_re =  malloc(n_tx*n_rx*sizeof(float complex));
-  float complex* Wmmse_re =  malloc(n_tx*n_rx*sizeof(float complex));
-
-  for (re=0;re<length; re++){
-    for (aatx=0; aatx<n_tx; aatx++){
-      for (aarx=0; aarx<n_rx; aarx++){
+  for (re=0; re<length; re++) {
+    for (aatx=0; aatx<n_tx; aatx++) {
+      for (aarx=0; aarx<n_rx; aarx++) {
         chan_est_re[aatx*n_rx + aarx] = dl_ch_estimates_ext_f[aatx*n_rx + aarx][re];
         Wmmse_re[aatx*n_rx + aarx] = Wmmse[aatx*n_rx + aarx][re];
 #ifdef DEBUG_MMSE
+
         if (re==0)
-        printf("mult_mmse_chan_est: chan_est_re[%d] = (%f, %f)\n", aatx*n_rx + aarx, creal(chan_est_re[aatx*n_rx + aarx]), cimag(chan_est_re[aatx*n_rx + aarx]));
+          printf("mult_mmse_chan_est: chan_est_re[%d] = (%f, %f)\n", aatx*n_rx + aarx, creal(chan_est_re[aatx*n_rx + aarx]), cimag(chan_est_re[aatx*n_rx + aarx]));
+
 #endif
       }
     }
-      mutl_matrix_matrix_col_based(Wmmse_re, chan_est_re, n_rx, n_tx, n_rx, n_tx, chan_est_mmse_re);
-      for (aatx=0; aatx<n_tx; aatx++){
-        for (aarx=0; aarx<n_rx; aarx++){
-          dl_ch_estimates_ext_f[aatx*n_rx + aarx][re] = chan_est_mmse_re[aatx*n_rx + aarx];
+
+    mutl_matrix_matrix_col_based(Wmmse_re, chan_est_re, n_rx, n_tx, n_rx, n_tx, chan_est_mmse_re);
+
+    for (aatx=0; aatx<n_tx; aatx++) {
+      for (aarx=0; aarx<n_rx; aarx++) {
+        dl_ch_estimates_ext_f[aatx*n_rx + aarx][re] = chan_est_mmse_re[aatx*n_rx + aarx];
 #ifdef DEBUG_MMSE
-          if (re==0)
+
+        if (re==0)
           printf("mult_mmse_chan_est: dl_ch_estimates_ext_f[%d][%d] = (%f, %f)\n", aatx*n_rx + aarx, re, creal(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re]), cimag(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re]));
+
 #endif
-        }
       }
-   }
-   free(Wmmse_re);
-   free(chan_est_re);
-   free(chan_est_mmse_re);
+    }
+  }
+
+  free(Wmmse_re);
+  free(chan_est_re);
+  free(chan_est_mmse_re);
 }
 
 
@@ -4643,19 +4299,15 @@ void dlsch_channel_level_TM34(int **dl_ch_estimates_ext,
                               uint8_t symbol,
                               unsigned short nb_rb,
                               unsigned int mmse_flag,
-                              MIMO_mode_t mimo_mode){
-
+                              MIMO_mode_t mimo_mode) {
 #if defined(__x86_64__)||defined(__i386__)
-
   short rb;
   unsigned char aarx,nre=12,symbol_mod;
   __m128i *dl_ch0_128,*dl_ch1_128, dl_ch0_128_tmp, dl_ch1_128_tmp, avg_0_128D, avg_1_128D;
-
   symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol;
-
   //clear average level
- // avg_0_128D = _mm_setzero_si128();
- // avg_1_128D = _mm_setzero_si128();
+  // avg_0_128D = _mm_setzero_si128();
+  // avg_1_128D = _mm_setzero_si128();
   avg_0[0] = 0;
   avg_0[1] = 0;
   avg_1[0] = 0;
@@ -4672,17 +4324,17 @@ void dlsch_channel_level_TM34(int **dl_ch_estimates_ext,
   for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
     dl_ch0_128 = (__m128i *)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12];
     dl_ch1_128 = (__m128i *)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12];
-
     avg_0_128D = _mm_setzero_si128();
     avg_1_128D = _mm_setzero_si128();
+
     for (rb=0; rb<nb_rb; rb++) {
-              // printf("rb %d : \n",rb);
-    //print_shorts("ch0\n",&dl_ch0_128[0]);
-    //print_shorts("ch1\n",&dl_ch1_128[0]);
+      // printf("rb %d : \n",rb);
+      //print_shorts("ch0\n",&dl_ch0_128[0]);
+      //print_shorts("ch1\n",&dl_ch1_128[0]);
       dl_ch0_128_tmp = _mm_load_si128(&dl_ch0_128[0]);
       dl_ch1_128_tmp = _mm_load_si128(&dl_ch1_128[0]);
 
-      if (mmse_flag == 0){
+      if (mmse_flag == 0) {
         if (mimo_mode==LARGE_CDD)
           prec2A_TM3_128(&dl_ch0_128_tmp,&dl_ch1_128_tmp);
         else if (mimo_mode==DUALSTREAM_UNIFORM_PRECODING1)
@@ -4695,13 +4347,11 @@ void dlsch_channel_level_TM34(int **dl_ch_estimates_ext,
 
       //      mmtmpD0 = _mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp);
       avg_0_128D = _mm_add_epi32(avg_0_128D,_mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp));
-
       avg_1_128D = _mm_add_epi32(avg_1_128D,_mm_madd_epi16(dl_ch1_128_tmp,dl_ch1_128_tmp));
-
       dl_ch0_128_tmp = _mm_load_si128(&dl_ch0_128[1]);
       dl_ch1_128_tmp = _mm_load_si128(&dl_ch1_128[1]);
 
-      if (mmse_flag == 0){
+      if (mmse_flag == 0) {
         if (mimo_mode==LARGE_CDD)
           prec2A_TM3_128(&dl_ch0_128_tmp,&dl_ch1_128_tmp);
         else if (mimo_mode==DUALSTREAM_UNIFORM_PRECODING1)
@@ -4714,18 +4364,16 @@ void dlsch_channel_level_TM34(int **dl_ch_estimates_ext,
 
       //      mmtmpD1 = _mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp);
       avg_0_128D = _mm_add_epi32(avg_0_128D,_mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp));
-
       avg_1_128D = _mm_add_epi32(avg_1_128D,_mm_madd_epi16(dl_ch1_128_tmp,dl_ch1_128_tmp));
 
       if (((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp-1)))&&(frame_parms->nb_antenna_ports_eNB!=1)) {
         dl_ch0_128+=2;
         dl_ch1_128+=2;
-      }
-      else {
+      } else {
         dl_ch0_128_tmp = _mm_load_si128(&dl_ch0_128[2]);
         dl_ch1_128_tmp = _mm_load_si128(&dl_ch1_128[2]);
 
-        if (mmse_flag == 0){
+        if (mmse_flag == 0) {
           if (mimo_mode==LARGE_CDD)
             prec2A_TM3_128(&dl_ch0_128_tmp,&dl_ch1_128_tmp);
           else if (mimo_mode==DUALSTREAM_UNIFORM_PRECODING1)
@@ -4735,45 +4383,39 @@ void dlsch_channel_level_TM34(int **dl_ch_estimates_ext,
           else if (mimo_mode==DUALSTREAM_PUSCH_PRECODING)
             prec2A_TM4_128(pmi_ext[rb],&dl_ch0_128_tmp,&dl_ch1_128_tmp);
         }
-        //      mmtmpD2 = _mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp);
 
+        //      mmtmpD2 = _mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp);
         avg_1_128D = _mm_add_epi32(avg_1_128D,_mm_madd_epi16(dl_ch1_128_tmp,dl_ch1_128_tmp));
         avg_0_128D = _mm_add_epi32(avg_0_128D,_mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp));
-
         dl_ch0_128+=3;
         dl_ch1_128+=3;
       }
     }
 
-
-    avg_0[aarx] = (((int*)&avg_0_128D)[0])/(nb_rb*nre) +
-      (((int*)&avg_0_128D)[1])/(nb_rb*nre) +
-      (((int*)&avg_0_128D)[2])/(nb_rb*nre) +
-      (((int*)&avg_0_128D)[3])/(nb_rb*nre);
+    avg_0[aarx] = (((int *)&avg_0_128D)[0])/(nb_rb*nre) +
+                  (((int *)&avg_0_128D)[1])/(nb_rb*nre) +
+                  (((int *)&avg_0_128D)[2])/(nb_rb*nre) +
+                  (((int *)&avg_0_128D)[3])/(nb_rb*nre);
     //  printf("From Chan_level aver stream 0 %d =%d\n", aarx, avg_0[aarx]);
-
-    avg_1[aarx] = (((int*)&avg_1_128D)[0])/(nb_rb*nre) +
-      (((int*)&avg_1_128D)[1])/(nb_rb*nre) +
-      (((int*)&avg_1_128D)[2])/(nb_rb*nre) +
-      (((int*)&avg_1_128D)[3])/(nb_rb*nre);
-  //    printf("From Chan_level aver stream 1 %d =%d\n", aarx, avg_1[aarx]);
+    avg_1[aarx] = (((int *)&avg_1_128D)[0])/(nb_rb*nre) +
+                  (((int *)&avg_1_128D)[1])/(nb_rb*nre) +
+                  (((int *)&avg_1_128D)[2])/(nb_rb*nre) +
+                  (((int *)&avg_1_128D)[3])/(nb_rb*nre);
+    //    printf("From Chan_level aver stream 1 %d =%d\n", aarx, avg_1[aarx]);
   }
-//avg_0[0] = max(avg_0[0],avg_0[1]);
-//avg_1[0] = max(avg_1[0],avg_1[1]);
-//avg_0[0]= max(avg_0[0], avg_1[0]);
 
+  //avg_0[0] = max(avg_0[0],avg_0[1]);
+  //avg_1[0] = max(avg_1[0],avg_1[1]);
+  //avg_0[0]= max(avg_0[0], avg_1[0]);
   avg_0[0] = avg_0[0] + avg_0[1];
- // printf("From Chan_level aver stream 0 final =%d\n", avg_0[0]);
+  // printf("From Chan_level aver stream 0 final =%d\n", avg_0[0]);
   avg_1[0] = avg_1[0] + avg_1[1];
- // printf("From Chan_level aver stream 1 final =%d\n", avg_1[0]);
- avg_0[0] = min (avg_0[0], avg_1[0]);
- avg_1[0] = avg_0[0];
-
+  // printf("From Chan_level aver stream 1 final =%d\n", avg_1[0]);
+  avg_0[0] = min (avg_0[0], avg_1[0]);
+  avg_1[0] = avg_0[0];
   _mm_empty();
   _m_empty();
-
 #elif defined(__arm__)
-
 #endif
 }
 
@@ -4783,17 +4425,12 @@ void dlsch_channel_level_TM56(int **dl_ch_estimates_ext,
                               unsigned char *pmi_ext,
                               int *avg,
                               uint8_t symbol,
-                              unsigned short nb_rb)
-{
-
+                              unsigned short nb_rb) {
 #if defined(__x86_64__)||defined(__i386__)
-
   short rb;
   unsigned char aarx,nre=12,symbol_mod;
   __m128i *dl_ch0_128,*dl_ch1_128, dl_ch0_128_tmp, dl_ch1_128_tmp,avg128D;
-
   symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol;
-
   //clear average level
   avg128D = _mm_setzero_si128();
   avg[0] = 0;
@@ -4812,17 +4449,13 @@ void dlsch_channel_level_TM56(int **dl_ch_estimates_ext,
     dl_ch1_128 = (__m128i *)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12];
 
     for (rb=0; rb<nb_rb; rb++) {
-
       dl_ch0_128_tmp = _mm_load_si128(&dl_ch0_128[0]);
       dl_ch1_128_tmp = _mm_load_si128(&dl_ch1_128[0]);
-
       prec2A_TM56_128(pmi_ext[rb],&dl_ch0_128_tmp,&dl_ch1_128_tmp);
       //      mmtmpD0 = _mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp);
       avg128D = _mm_add_epi32(avg128D,_mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp));
-
       dl_ch0_128_tmp = _mm_load_si128(&dl_ch0_128[1]);
       dl_ch1_128_tmp = _mm_load_si128(&dl_ch1_128[1]);
-
       prec2A_TM56_128(pmi_ext[rb],&dl_ch0_128_tmp,&dl_ch1_128_tmp);
       //      mmtmpD1 = _mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp);
       avg128D = _mm_add_epi32(avg128D,_mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp));
@@ -4830,52 +4463,41 @@ void dlsch_channel_level_TM56(int **dl_ch_estimates_ext,
       if (((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp-1)))&&(frame_parms->nb_antenna_ports_eNB!=1)) {
         dl_ch0_128+=2;
         dl_ch1_128+=2;
-      }
-      else {
+      } else {
         dl_ch0_128_tmp = _mm_load_si128(&dl_ch0_128[2]);
         dl_ch1_128_tmp = _mm_load_si128(&dl_ch1_128[2]);
-
         prec2A_TM56_128(pmi_ext[rb],&dl_ch0_128_tmp,&dl_ch1_128_tmp);
         //      mmtmpD2 = _mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp);
         avg128D = _mm_add_epi32(avg128D,_mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp));
-
         dl_ch0_128+=3;
         dl_ch1_128+=3;
       }
     }
 
-    avg[aarx] = (((int*)&avg128D)[0])/(nb_rb*nre) +
-      (((int*)&avg128D)[1])/(nb_rb*nre) +
-      (((int*)&avg128D)[2])/(nb_rb*nre) +
-      (((int*)&avg128D)[3])/(nb_rb*nre);
+    avg[aarx] = (((int *)&avg128D)[0])/(nb_rb*nre) +
+                (((int *)&avg128D)[1])/(nb_rb*nre) +
+                (((int *)&avg128D)[2])/(nb_rb*nre) +
+                (((int *)&avg128D)[3])/(nb_rb*nre);
   }
 
   // choose maximum of the 2 effective channels
   avg[0] = cmax(avg[0],avg[1]);
-
   _mm_empty();
   _m_empty();
-
 #elif defined(__arm__)
-
-
 #endif
 }
 
 //compute average channel_level for TM7
 void dlsch_channel_level_TM7(int **dl_bf_ch_estimates_ext,
-                         LTE_DL_FRAME_PARMS *frame_parms,
-                         int *avg,
-                         uint8_t symbol,
-                         unsigned short nb_rb)
-{
-
+                             LTE_DL_FRAME_PARMS *frame_parms,
+                             int *avg,
+                             uint8_t symbol,
+                             unsigned short nb_rb) {
 #if defined(__x86_64__)||defined(__i386__)
-
   short rb;
   unsigned char aatx,aarx,nre=12,symbol_mod;
   __m128i *dl_ch128,avg128D;
-
   symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol;
 
   for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++)
@@ -4883,7 +4505,6 @@ void dlsch_channel_level_TM7(int **dl_bf_ch_estimates_ext,
       //clear average level
       avg128D = _mm_setzero_si128();
       // 5 is always a symbol with no pilots for both normal and extended prefix
-
       dl_ch128=(__m128i *)&dl_bf_ch_estimates_ext[(aatx<<1)+aarx][symbol*frame_parms->N_RB_DL*12];
 
       for (rb=0; rb<nb_rb; rb++) {
@@ -4917,19 +4538,16 @@ void dlsch_channel_level_TM7(int **dl_bf_ch_estimates_ext,
       else
         nre=12;
 
-      avg[(aatx<<1)+aarx] = (((int*)&avg128D)[0] +
-                             ((int*)&avg128D)[1] +
-                             ((int*)&avg128D)[2] +
-                             ((int*)&avg128D)[3])/(nb_rb*nre);
-
+      avg[(aatx<<1)+aarx] = (((int *)&avg128D)[0] +
+                             ((int *)&avg128D)[1] +
+                             ((int *)&avg128D)[2] +
+                             ((int *)&avg128D)[3])/(nb_rb*nre);
       //            printf("Channel level : %d\n",avg[(aatx<<1)+aarx]);
     }
 
   _mm_empty();
   _m_empty();
-
 #elif defined(__arm__)
-
 #endif
 }
 //#define ONE_OVER_2_Q15 16384
@@ -4938,53 +4556,40 @@ void dlsch_alamouti(LTE_DL_FRAME_PARMS *frame_parms,
                     int **dl_ch_mag,
                     int **dl_ch_magb,
                     unsigned char symbol,
-                    unsigned short nb_rb)
-{
-
+                    unsigned short nb_rb) {
 #if defined(__x86_64__)||defined(__i386__)
-
   short *rxF0,*rxF1;
   __m128i *ch_mag0,*ch_mag1,*ch_mag0b,*ch_mag1b, *rxF0_128;
   unsigned char rb,re;
   int jj = (symbol*frame_parms->N_RB_DL*12);
   uint8_t symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol;
   uint8_t pilots = ((symbol_mod==0)||(symbol_mod==(4-frame_parms->Ncp))) ? 1 : 0;
-  rxF0_128 = (__m128i*) &rxdataF_comp[0][jj];
-
+  rxF0_128 = (__m128i *) &rxdataF_comp[0][jj];
   //amp = _mm_set1_epi16(ONE_OVER_2_Q15);
-
-
   //    printf("Doing alamouti!\n");
-  rxF0     = (short*)&rxdataF_comp[0][jj];  //tx antenna 0  h0*y
-  rxF1     = (short*)&rxdataF_comp[2][jj];  //tx antenna 1  h1*y
+  rxF0     = (short *)&rxdataF_comp[0][jj]; //tx antenna 0  h0*y
+  rxF1     = (short *)&rxdataF_comp[2][jj]; //tx antenna 1  h1*y
   ch_mag0 = (__m128i *)&dl_ch_mag[0][jj];
   ch_mag1 = (__m128i *)&dl_ch_mag[2][jj];
   ch_mag0b = (__m128i *)&dl_ch_magb[0][jj];
   ch_mag1b = (__m128i *)&dl_ch_magb[2][jj];
 
   for (rb=0; rb<nb_rb; rb++) {
-
     for (re=0; re<((pilots==0)?12:8); re+=2) {
-
       // Alamouti RX combining
-
       //      printf("Alamouti: symbol %d, rb %d, re %d: rxF0 (%d,%d,%d,%d), rxF1 (%d,%d,%d,%d)\n",symbol,rb,re,rxF0[0],rxF0[1],rxF0[2],rxF0[3],rxF1[0],rxF1[1],rxF1[2],rxF1[3]);
       rxF0[0] = rxF0[0] + rxF1[2];
       rxF0[1] = rxF0[1] - rxF1[3];
-
       rxF0[2] = rxF0[2] - rxF1[0];
       rxF0[3] = rxF0[3] + rxF1[1];
-
       //      printf("Alamouti: rxF0 after (%d,%d,%d,%d)\n",rxF0[0],rxF0[1],rxF0[2],rxF0[3]);
       rxF0+=4;
       rxF1+=4;
-
     }
 
     // compute levels for 16QAM or 64 QAM llr unit
     ch_mag0[0] = _mm_adds_epi16(ch_mag0[0],ch_mag1[0]);
     ch_mag0[1] = _mm_adds_epi16(ch_mag0[1],ch_mag1[1]);
-
     ch_mag0b[0] = _mm_adds_epi16(ch_mag0b[0],ch_mag1b[0]);
     ch_mag0b[1] = _mm_adds_epi16(ch_mag0b[1],ch_mag1b[1]);
 
@@ -5002,21 +4607,14 @@ void dlsch_alamouti(LTE_DL_FRAME_PARMS *frame_parms,
     //rxF0_128[0] = _mm_srai_epi16(rxF0_128[0],1);
     //rxF0_128[1] = _mm_srai_epi16(rxF0_128[1],1);
 
-
-
     if (pilots==0) {
       ch_mag0[2] = _mm_adds_epi16(ch_mag0[2],ch_mag1[2]);
       ch_mag0b[2] = _mm_adds_epi16(ch_mag0b[2],ch_mag1b[2]);
-
       //ch_mag0[2] = _mm_srai_epi16(ch_mag0[2],1);
       //ch_mag0b[2] = _mm_srai_epi16(ch_mag0b[2],1);
-
       //rxF0_128[2] = _mm_mulhi_epi16(rxF0_128[2],amp);
       //rxF0_128[2] = _mm_slli_epi16(rxF0_128[2],1);
-
       //rxF0_128[2] = _mm_srai_epi16(rxF0_128[2],1);
-
-
       ch_mag0+=3;
       ch_mag1+=3;
       ch_mag0b+=3;
@@ -5033,9 +4631,7 @@ void dlsch_alamouti(LTE_DL_FRAME_PARMS *frame_parms,
 
   _mm_empty();
   _m_empty();
-
 #elif defined(__arm__)
-
 #endif
 }
 
@@ -5055,18 +4651,11 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF,
                                         unsigned char subframe,
                                         uint32_t high_speed_flag,
                                         LTE_DL_FRAME_PARMS *frame_parms) {
-
-
-
   unsigned short rb,nb_rb=0;
   unsigned char rb_alloc_ind;
   unsigned char i,aarx,l,nsymb,skip_half=0,sss_symb,pss_symb=0;
   int *dl_ch0,*dl_ch0_ext,*rxF,*rxF_ext;
-
-
-
   unsigned char symbol_mod,pilots=0,j=0,poffset=0;
-
   symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol;
   pilots = ((symbol_mod==0)||(symbol_mod==(4-frame_parms->Ncp))) ? 1 : 0;
   l=symbol;
@@ -5084,21 +4673,17 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF,
     poffset=3;
 
   for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
-
     if (high_speed_flag == 1)
       dl_ch0     = &dl_ch_estimates[aarx][5+(symbol*(frame_parms->ofdm_symbol_size))];
     else
       dl_ch0     = &dl_ch_estimates[aarx][5];
 
     dl_ch0_ext = &dl_ch_estimates_ext[aarx][symbol*(frame_parms->N_RB_DL*12)];
-
     rxF_ext   = &rxdataF_ext[aarx][symbol*(frame_parms->N_RB_DL*12)];
     rxF       = &rxdataF[aarx][(frame_parms->first_carrier_offset + (symbol*(frame_parms->ofdm_symbol_size)))];
 
     if ((frame_parms->N_RB_DL&1) == 0)  // even number of RBs
-
-      for (rb=0;rb<frame_parms->N_RB_DL;rb++) {
-
+      for (rb=0; rb<frame_parms->N_RB_DL; rb++) {
         if (rb < 32)
           rb_alloc_ind = (rb_alloc[0]>>rb) & 1;
         else if (rb < 64)
@@ -5129,7 +4714,6 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF,
           rb_alloc_ind = 0;
         }
 
-
         if (frame_parms->frame_type == FDD) {
           //PSS
           if (((subframe==0)||(subframe==5)) && (rb>=((frame_parms->N_RB_DL>>1)-3)) && (rb<((frame_parms->N_RB_DL>>1)+3)) && (l==pss_symb) ) {
@@ -5173,25 +4757,21 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF,
                 rxF_ext[j]=rxF[i];
                 //            printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j]));
                 dl_ch0_ext[j++]=dl_ch0[i];
-
               }
             }
 
             dl_ch0_ext+=10;
             rxF_ext+=10;
           }
-
-
         }
 
         dl_ch0+=12;
         rxF+=12;
-
       }
     else {  // Odd number of RBs
       for (rb=0; rb<frame_parms->N_RB_DL>>1; rb++) {
 #ifdef DEBUG_DLSCH_DEMOD
-        printf("dlch_ext %d\n",dl_ch0_ext-&dl_ch_estimates_ext[aarx][0]);
+        printf("dlch_ext %u\n",dl_ch0_ext-&dl_ch_estimates_ext[aarx][0]);
 #endif
         skip_half=0;
 
@@ -5209,7 +4789,6 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF,
         if (rb_alloc_ind == 1)
           nb_rb++;
 
-
         // PBCH
         if ((subframe==0) && (rb>((frame_parms->N_RB_DL>>1)-3)) && (rb<((frame_parms->N_RB_DL>>1)+3)) && (l>=(nsymb>>1)) && (l<((nsymb>>1) + 4))) {
           rb_alloc_ind = 0;
@@ -5229,6 +4808,7 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF,
             (l==sss_symb) ) {
           rb_alloc_ind = 0;
         }
+
         //SSS
         if (((subframe==0)||(subframe==5)) &&
             (rb==((frame_parms->N_RB_DL>>1)-3)) &&
@@ -5241,7 +4821,6 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF,
 
         //PSS in subframe 0/5 if FDD
         if (frame_parms->frame_type == FDD) {  //FDD
-
           if (((subframe==0)||(subframe==5)) &&
               (rb>((frame_parms->N_RB_DL>>1)-3)) &&
               (rb<((frame_parms->N_RB_DL>>1)+3)) &&
@@ -5256,22 +4835,22 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF,
         }
 
         if ((frame_parms->frame_type == TDD) &&
-            (subframe==6)){  //TDD Subframe 6
+            (subframe==6)) { //TDD Subframe 6
           if ((rb>((frame_parms->N_RB_DL>>1)-3)) && (rb<((frame_parms->N_RB_DL>>1)+3)) && (l==pss_symb) ) {
             rb_alloc_ind = 0;
           }
+
           if ((rb==((frame_parms->N_RB_DL>>1)-3)) && (l==pss_symb))
             skip_half=1;
           else if ((rb==((frame_parms->N_RB_DL>>1)+3)) && (l==pss_symb))
             skip_half=2;
         }
 
-
         if (rb_alloc_ind==1) {
-
 #ifdef DEBUG_DLSCH_DEMOD
           printf("rb %d/symbol %d (skip_half %d)\n",rb,l,skip_half);
 #endif
+
           if (pilots==0) {
             //      printf("Extracting w/o pilots (symbol %d, rb %d, skip_half %d)\n",l,rb,skip_half);
             if (skip_half==1) {
@@ -5280,9 +4859,10 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF,
               for (i=0; i<6; i++) {
                 rxF_ext[i]=rxF[i];
 #ifdef DEBUG_DLSCH_DEMOD
-                printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
               }
+
               dl_ch0_ext+=6;
               rxF_ext+=6;
             } else if (skip_half==2) {
@@ -5291,9 +4871,10 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF,
               for (i=0; i<6; i++) {
                 rxF_ext[i]=rxF[(i+6)];
 #ifdef DEBUG_DLSCH_DEMOD
-                printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
               }
+
               dl_ch0_ext+=6;
               rxF_ext+=6;
             } else {
@@ -5302,9 +4883,10 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF,
               for (i=0; i<12; i++) {
                 rxF_ext[i]=rxF[i];
 #ifdef DEBUG_DLSCH_DEMOD
-                printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
               }
+
               dl_ch0_ext+=12;
               rxF_ext+=12;
             }
@@ -5317,11 +4899,12 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF,
                 if (i!=((frame_parms->nushift+poffset)%6)) {
                   rxF_ext[j]=rxF[i];
 #ifdef DEBUG_DLSCH_DEMOD
-                  printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j]));
+                  printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short *)&rxF_ext[j]));
 #endif
                   dl_ch0_ext[j++]=dl_ch0[i];
                 }
               }
+
               rxF_ext+=5;
               dl_ch0_ext+=5;
             } else if (skip_half==2) {
@@ -5329,7 +4912,7 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF,
                 if (i!=((frame_parms->nushift+poffset)%6)) {
                   rxF_ext[j]=rxF[(i+6)];
 #ifdef DEBUG_DLSCH_DEMOD
-                  printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j]));
+                  printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short *)&rxF_ext[j]));
 #endif
                   dl_ch0_ext[j++]=dl_ch0[i+6];
                 }
@@ -5343,10 +4926,9 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF,
                     (i!=((frame_parms->nushift+poffset+6)%12))) {
                   rxF_ext[j]=rxF[i];
 #ifdef DEBUG_DLSCH_DEMOD
-                  printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j]));
+                  printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short *)&rxF_ext[j]));
 #endif
                   dl_ch0_ext[j++]=dl_ch0[i];
-
                 }
               }
 
@@ -5355,11 +4937,11 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF,
             }
           }
         }
+
         dl_ch0+=12;
         rxF+=12;
       } // first half loop
 
-
       // Do middle RB (around DC)
       if (rb < 32)
         rb_alloc_ind = (rb_alloc[0]>>rb) & 1;
@@ -5372,7 +4954,6 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF,
       else
         rb_alloc_ind = 0;
 
-
       if (rb_alloc_ind == 1)
         nb_rb++;
 
@@ -5403,13 +4984,13 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF,
         rb_alloc_ind = 0;
       }
 
-
       //  printf("dlch_ext %d\n",dl_ch0_ext-&dl_ch_estimates_ext[aarx][0]);
       //      printf("DC rb %d (%p)\n",rb,rxF);
       if (rb_alloc_ind==1) {
 #ifdef DEBUG_DLSCH_DEMOD
         printf("rb %d/symbol %d (skip_half %d)\n",rb,l,skip_half);
 #endif
+
         if (pilots==0) {
           for (i=0; i<6; i++) {
             dl_ch0_ext[i]=dl_ch0[i];
@@ -5433,7 +5014,7 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF,
               dl_ch0_ext[j]=dl_ch0[i];
               rxF_ext[j++]=rxF[i];
 #ifdef DEBUG_DLSCH_DEMOD
-              printf("**extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j-1],*(1+(short*)&rxF_ext[j-1]));
+              printf("**extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j-1],*(1+(short *)&rxF_ext[j-1]));
 #endif
             }
           }
@@ -5445,7 +5026,7 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF,
               dl_ch0_ext[j]=dl_ch0[i];
               rxF_ext[j++]=rxF[(1+i-6)];
 #ifdef DEBUG_DLSCH_DEMOD
-              printf("**extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j-1],*(1+(short*)&rxF_ext[j-1]));
+              printf("**extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j-1],*(1+(short *)&rxF_ext[j-1]));
 #endif
             }
           }
@@ -5462,7 +5043,7 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF,
       rxF+=7;
       rb++;
 
-      for (;rb<frame_parms->N_RB_DL;rb++) {
+      for (; rb<frame_parms->N_RB_DL; rb++) {
         //      printf("dlch_ext %d\n",dl_ch0_ext-&dl_ch_estimates_ext[aarx][0]);
         //      printf("rb %d (%p)\n",rb,rxF);
         skip_half=0;
@@ -5485,6 +5066,7 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF,
         if ((subframe==0) && (rb>((frame_parms->N_RB_DL>>1)-3)) && (rb<((frame_parms->N_RB_DL>>1)+3)) && (l>=nsymb>>1) && (l<((nsymb>>1) + 4))) {
           rb_alloc_ind = 0;
         }
+
         //PBCH subframe 0, symbols nsymb>>1 ... nsymb>>1 + 3
         if ((subframe==0) && (rb==((frame_parms->N_RB_DL>>1)-3)) && (l>=(nsymb>>1)) && (l<((nsymb>>1) + 4)))
           skip_half=1;
@@ -5495,11 +5077,13 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF,
         if (((subframe==0)||(subframe==5)) && (rb>((frame_parms->N_RB_DL>>1)-3)) && (rb<((frame_parms->N_RB_DL>>1)+3)) && (l==sss_symb) ) {
           rb_alloc_ind = 0;
         }
+
         //SSS
         if (((subframe==0)||(subframe==5)) && (rb==((frame_parms->N_RB_DL>>1)-3)) && (l==sss_symb))
           skip_half=1;
         else if (((subframe==0)||(subframe==5)) && (rb==((frame_parms->N_RB_DL>>1)+3)) && (l==sss_symb))
           skip_half=2;
+
         if (frame_parms->frame_type == FDD) {
           //PSS
           if (((subframe==0)||(subframe==5)) && (rb>((frame_parms->N_RB_DL>>1)-3)) && (rb<((frame_parms->N_RB_DL>>1)+3)) && (l==pss_symb) ) {
@@ -5515,7 +5099,6 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF,
         }
 
         if ((frame_parms->frame_type == TDD) &&
-
             (subframe==6)) { //TDD Subframe 6
           if ((rb>((frame_parms->N_RB_DL>>1)-3)) && (rb<((frame_parms->N_RB_DL>>1)+3)) && (l==pss_symb) ) {
             rb_alloc_ind = 0;
@@ -5531,6 +5114,7 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF,
 #ifdef DEBUG_DLSCH_DEMOD
           printf("rb %d/symbol %d (skip_half %d)\n",rb,l,skip_half);
 #endif
+
           /*
             printf("rb %d\n",rb);
             for (i=0;i<12;i++)
@@ -5545,33 +5129,34 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF,
               for (i=0; i<6; i++) {
                 rxF_ext[i]=rxF[i];
 #ifdef DEBUG_DLSCH_DEMOD
-                printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
               }
+
               dl_ch0_ext+=6;
               rxF_ext+=6;
-
             } else if (skip_half==2) {
               memcpy(dl_ch0_ext,dl_ch0+6,6*sizeof(int));
 
               for (i=0; i<6; i++) {
                 rxF_ext[i]=rxF[(i+6)];
 #ifdef DEBUG_DLSCH_DEMOD
-                printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
               }
+
               dl_ch0_ext+=6;
               rxF_ext+=6;
-
             } else {
               memcpy(dl_ch0_ext,dl_ch0,12*sizeof(int));
 
               for (i=0; i<12; i++) {
                 rxF_ext[i]=rxF[i];
 #ifdef DEBUG_DLSCH_DEMOD
-                printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
               }
+
               dl_ch0_ext+=12;
               rxF_ext+=12;
             }
@@ -5584,7 +5169,7 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF,
                 if (i!=((frame_parms->nushift+poffset)%6)) {
                   rxF_ext[j]=rxF[i];
 #ifdef DEBUG_DLSCH_DEMOD
-                  printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j]));
+                  printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short *)&rxF_ext[j]));
 #endif
                   dl_ch0_ext[j++]=dl_ch0[i];
                 }
@@ -5597,7 +5182,7 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF,
                 if (i!=((frame_parms->nushift+poffset)%6)) {
                   rxF_ext[j]=rxF[(i+6)];
 #ifdef DEBUG_DLSCH_DEMOD
-                  printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j]));
+                  printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short *)&rxF_ext[j]));
 #endif
                   dl_ch0_ext[j++]=dl_ch0[i+6];
                 }
@@ -5611,11 +5196,12 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF,
                     (i!=((frame_parms->nushift+poffset+6)%12))) {
                   rxF_ext[j]=rxF[i];
 #ifdef DEBUG_DLSCH_DEMOD
-                  printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j]));
+                  printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short *)&rxF_ext[j]));
 #endif
                   dl_ch0_ext[j++]=dl_ch0[i];
                 }
               }
+
               dl_ch0_ext+=10;
               rxF_ext+=10;
             }
@@ -5628,7 +5214,6 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF,
     }
   }
 
-
   return(nb_rb/frame_parms->nb_antennas_rx);
 }
 
@@ -5644,7 +5229,6 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF,
                                       uint32_t high_speed_flag,
                                       LTE_DL_FRAME_PARMS *frame_parms,
                                       MIMO_mode_t mimo_mode) {
-
   int prb,nb_rb=0;
   int prb_off,prb_off2;
   int rb_alloc_ind,skip_half=0,sss_symb,pss_symb=0,nsymb,l;
@@ -5652,7 +5236,6 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF,
   int32_t *dl_ch0,*dl_ch0p,*dl_ch0_ext,*dl_ch1,*dl_ch1p,*dl_ch1_ext,*rxF,*rxF_ext;
   int symbol_mod,pilots=0,j=0;
   unsigned char *pmi_loc;
-
   symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol;
   //  printf("extract_rbs: symbol_mod %d\n",symbol_mod);
 
@@ -5671,7 +5254,6 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF,
   }
 
   for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
-
     if (high_speed_flag==1) {
       dl_ch0     = &dl_ch_estimates[aarx][5+(symbol*(frame_parms->ofdm_symbol_size))];
       dl_ch1     = &dl_ch_estimates[2+aarx][5+(symbol*(frame_parms->ofdm_symbol_size))];
@@ -5681,7 +5263,6 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF,
     }
 
     pmi_loc = pmi_ext;
-
     // pointers to extracted RX signals and channel estimates
     rxF_ext    = &rxdataF_ext[aarx][symbol*(frame_parms->N_RB_DL*12)];
     dl_ch0_ext = &dl_ch_estimates_ext[aarx][symbol*(frame_parms->N_RB_DL*12)];
@@ -5702,8 +5283,7 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF,
         rb_alloc_ind = 0;
 
       if (rb_alloc_ind == 1)
-          nb_rb++;
-
+        nb_rb++;
 
       if ((frame_parms->N_RB_DL&1) == 0) {  // even number of RBs
 
@@ -5727,8 +5307,6 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF,
           //    printf("symbol %d / rb %d: skipping SSS REs\n",symbol,prb);
         }
 
-
-
         //PSS in subframe 0/5 if FDD
         if (frame_parms->frame_type == FDD) {  //FDD
           if (((subframe==0)||(subframe==5)) &&
@@ -5750,35 +5328,29 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF,
         }
 
         if (rb_alloc_ind==1) {              // PRB is allocated
-
-
-
           prb_off      = 12*prb;
           prb_off2     = 1+(12*(prb-(frame_parms->N_RB_DL>>1)));
           dl_ch0p    = dl_ch0+(12*prb);
           dl_ch1p    = dl_ch1+(12*prb);
-          if (prb<(frame_parms->N_RB_DL>>1)){
+
+          if (prb<(frame_parms->N_RB_DL>>1)) {
             rxF      = &rxdataF[aarx][prb_off+
                                       frame_parms->first_carrier_offset +
                                       (symbol*(frame_parms->ofdm_symbol_size))];
-          }
-          else {
+          } else {
             rxF      = &rxdataF[aarx][prb_off2+
                                       (symbol*(frame_parms->ofdm_symbol_size))];
           }
 
-         /*
-         if (mimo_mode <= PUSCH_PRECODING1)
-          *pmi_loc = (pmi>>((prb>>2)<<1))&3;
-         else
-          *pmi_loc=(pmi>>prb)&1;*/
-
-         *pmi_loc = get_pmi(frame_parms->N_RB_DL,mimo_mode,pmi,prb);
+          /*
+          if (mimo_mode <= PUSCH_PRECODING1)
+           *pmi_loc = (pmi>>((prb>>2)<<1))&3;
+          else
+           *pmi_loc=(pmi>>prb)&1;*/
+          *pmi_loc = get_pmi(frame_parms->N_RB_DL,mimo_mode,pmi,prb);
           pmi_loc++;
 
-
           if (pilots == 0) {
-
             memcpy(dl_ch0_ext,dl_ch0p,12*sizeof(int));
             memcpy(dl_ch1_ext,dl_ch1p,12*sizeof(int));
             memcpy(rxF_ext,rxF,12*sizeof(int));
@@ -5787,6 +5359,7 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF,
             rxF_ext    +=12;
           } else { // pilots==1
             j=0;
+
             for (i=0; i<12; i++) {
               if ((i!=frame_parms->nushift) &&
                   (i!=frame_parms->nushift+3) &&
@@ -5798,16 +5371,15 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF,
                 dl_ch1_ext[j++]=dl_ch1p[i];
               }
             }
+
             dl_ch0_ext+=8;
             dl_ch1_ext+=8;
             rxF_ext+=8;
           } // pilots==1
-
         }
       } else {  // Odd number of RBs
 
-
-      // PBCH
+        // PBCH
         if ((subframe==0) &&
             (prb>((frame_parms->N_RB_DL>>1)-3)) &&
             (prb<((frame_parms->N_RB_DL>>1)+3)) &&
@@ -5827,8 +5399,6 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF,
           //    printf("symbol %d / rb %d: skipping SSS REs\n",symbol,prb);
         }
 
-
-
         //PSS in subframe 0/5 if FDD
         if (frame_parms->frame_type == FDD) {  //FDD
           if (((subframe==0)||(subframe==5)) &&
@@ -5883,7 +5453,6 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF,
                (((subframe==0)||(subframe==5)))) ||  //FDD Subframes 0,5
               ((frame_parms->frame_type == TDD) &&
                (((subframe==1) || (subframe==6))))) { //TDD Subframes 1,6
-
             if ((prb==((frame_parms->N_RB_DL>>1)-3)) &&
                 (l==pss_symb))
               skip_half=1;
@@ -5892,31 +5461,30 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF,
               skip_half=2;
           }
 
-
           prb_off      = 12*prb;
           prb_off2     = 7+(12*(prb-(frame_parms->N_RB_DL>>1)-1));
           dl_ch0p      = dl_ch0+(12*prb);
           dl_ch1p      = dl_ch1+(12*prb);
 
-          if (prb<=(frame_parms->N_RB_DL>>1)){
+          if (prb<=(frame_parms->N_RB_DL>>1)) {
             rxF      = &rxdataF[aarx][prb_off+
                                       frame_parms->first_carrier_offset +
                                       (symbol*(frame_parms->ofdm_symbol_size))];
-          }
-          else {
+          } else {
             rxF      = &rxdataF[aarx][prb_off2+
                                       (symbol*(frame_parms->ofdm_symbol_size))];
           }
+
 #ifdef DEBUG_DLSCH_DEMOD
           printf("symbol %d / rb %d: alloc %d skip_half %d (rxF %p, rxF_ext %p) prb_off (%d,%d)\n",symbol,prb,rb_alloc_ind,skip_half,rxF,rxF_ext,prb_off,prb_off2);
 #endif
-         /* if (mimo_mode <= PUSCH_PRECODING1)
-           *pmi_loc = (pmi>>((prb>>2)<<1))&3;
-          else
-           *pmi_loc=(pmi>>prb)&1;
-         // printf("symbol_mod %d (pilots %d) rb %d, sb %d, pmi %d (pmi_loc %p,rxF %p, ch00 %p, ch01 %p, rxF_ext %p dl_ch0_ext %p dl_ch1_ext %p)\n",symbol_mod,pilots,prb,prb>>2,*pmi_loc,pmi_loc,rxF,dl_ch0, dl_ch1, rxF_ext,dl_ch0_ext,dl_ch1_ext);
-*/
-         *pmi_loc = get_pmi(frame_parms->N_RB_DL,mimo_mode,pmi,prb);
+          /* if (mimo_mode <= PUSCH_PRECODING1)
+            *pmi_loc = (pmi>>((prb>>2)<<1))&3;
+           else
+            *pmi_loc=(pmi>>prb)&1;
+          // printf("symbol_mod %d (pilots %d) rb %d, sb %d, pmi %d (pmi_loc %p,rxF %p, ch00 %p, ch01 %p, rxF_ext %p dl_ch0_ext %p dl_ch1_ext %p)\n",symbol_mod,pilots,prb,prb>>2,*pmi_loc,pmi_loc,rxF,dl_ch0, dl_ch1, rxF_ext,dl_ch0_ext,dl_ch1_ext);
+          */
+          *pmi_loc = get_pmi(frame_parms->N_RB_DL,mimo_mode,pmi,prb);
           pmi_loc++;
 
           if (prb != (frame_parms->N_RB_DL>>1)) { // This PRB is not around DC
@@ -5926,8 +5494,10 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF,
                 memcpy(dl_ch1_ext,dl_ch1p,6*sizeof(int32_t));
                 memcpy(rxF_ext,rxF,6*sizeof(int32_t));
 #ifdef DEBUG_DLSCH_DEMOD
-                for (i=0;i<6;i++)
-                  printf("extract rb %d, re %d => (%d,%d)\n",prb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+
+                for (i=0; i<6; i++)
+                  printf("extract rb %d, re %d => (%d,%d)\n",prb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
+
 #endif
                 dl_ch0_ext+=6;
                 dl_ch1_ext+=6;
@@ -5937,8 +5507,10 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF,
                 memcpy(dl_ch1_ext,dl_ch1p+6,6*sizeof(int32_t));
                 memcpy(rxF_ext,rxF+6,6*sizeof(int32_t));
 #ifdef DEBUG_DLSCH_DEMOD
-                for (i=0;i<6;i++)
-                  printf("extract rb %d, re %d => (%d,%d)\n",prb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+
+                for (i=0; i<6; i++)
+                  printf("extract rb %d, re %d => (%d,%d)\n",prb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
+
 #endif
                 dl_ch0_ext+=6;
                 dl_ch1_ext+=6;
@@ -5948,8 +5520,10 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF,
                 memcpy(dl_ch1_ext,dl_ch1p,12*sizeof(int32_t));
                 memcpy(rxF_ext,rxF,12*sizeof(int32_t));
 #ifdef DEBUG_DLSCH_DEMOD
-                for (i=0;i<12;i++)
-                  printf("extract rb %d, re %d => (%d,%d)\n",prb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+
+                for (i=0; i<12; i++)
+                  printf("extract rb %d, re %d => (%d,%d)\n",prb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
+
 #endif
                 dl_ch0_ext+=12;
                 dl_ch1_ext+=12;
@@ -5964,12 +5538,13 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF,
                       (i!=((frame_parms->nushift+3)%6))) {
                     rxF_ext[j]=rxF[i];
 #ifdef DEBUG_DLSCH_DEMOD
-                    printf("(pilots,skip1)extract rb %d, re %d (%d)=> (%d,%d)\n",prb,i,j,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j]));
+                    printf("(pilots,skip1)extract rb %d, re %d (%d)=> (%d,%d)\n",prb,i,j,*(short *)&rxF_ext[j],*(1+(short *)&rxF_ext[j]));
 #endif
                     dl_ch0_ext[j]=dl_ch0p[i];
                     dl_ch1_ext[j++]=dl_ch1p[i];
                   }
                 }
+
                 dl_ch0_ext+=4;
                 dl_ch1_ext+=4;
                 rxF_ext+=4;
@@ -5979,16 +5554,16 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF,
                       (i!=((frame_parms->nushift+3)%6))) {
                     rxF_ext[j]=rxF[(i+6)];
 #ifdef DEBUG_DLSCH_DEMOD
-                    printf("(pilots,skip2)extract rb %d, re %d (%d) => (%d,%d)\n",prb,i,j,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j]));
+                    printf("(pilots,skip2)extract rb %d, re %d (%d) => (%d,%d)\n",prb,i,j,*(short *)&rxF_ext[j],*(1+(short *)&rxF_ext[j]));
 #endif
                     dl_ch0_ext[j]=dl_ch0p[i+6];
                     dl_ch1_ext[j++]=dl_ch1p[i+6];
                   }
                 }
+
                 dl_ch0_ext+=4;
                 dl_ch1_ext+=4;
                 rxF_ext+=4;
-
               } else { //skip_half==0
                 for (i=0; i<12; i++) {
                   if ((i!=frame_parms->nushift) &&
@@ -5997,43 +5572,45 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF,
                       (i!=((frame_parms->nushift+9)%12))) {
                     rxF_ext[j]=rxF[i];
 #ifdef DEBUG_DLSCH_DEMOD
-                    printf("(pilots)extract rb %d, re %d => (%d,%d)\n",prb,i,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j]));
+                    printf("(pilots)extract rb %d, re %d => (%d,%d)\n",prb,i,*(short *)&rxF_ext[j],*(1+(short *)&rxF_ext[j]));
 #endif
                     dl_ch0_ext[j]  =dl_ch0p[i];
                     dl_ch1_ext[j++]=dl_ch1p[i];
                   }
                 }
+
                 dl_ch0_ext+=8;
                 dl_ch1_ext+=8;
                 rxF_ext+=8;
               } //skip_half==0
             } //pilots==1
           } else {       // Do middle RB (around DC)
-
             if (pilots==0) {
               memcpy(dl_ch0_ext,dl_ch0p,6*sizeof(int32_t));
               memcpy(dl_ch1_ext,dl_ch1p,6*sizeof(int32_t));
               memcpy(rxF_ext,rxF,6*sizeof(int32_t));
 #ifdef DEBUG_DLSCH_DEMOD
+
               for (i=0; i<6; i++) {
-                printf("extract rb %d, re %d => (%d,%d)\n",prb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                printf("extract rb %d, re %d => (%d,%d)\n",prb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
               }
+
 #endif
               rxF_ext+=6;
               dl_ch0_ext+=6;
               dl_ch1_ext+=6;
               dl_ch0p+=6;
               dl_ch1p+=6;
-
               rxF       = &rxdataF[aarx][1+((symbol*(frame_parms->ofdm_symbol_size)))];
-
               memcpy(dl_ch0_ext,dl_ch0p,6*sizeof(int32_t));
               memcpy(dl_ch1_ext,dl_ch1p,6*sizeof(int32_t));
               memcpy(rxF_ext,rxF,6*sizeof(int32_t));
 #ifdef DEBUG_DLSCH_DEMOD
+
               for (i=0; i<6; i++) {
-                printf("extract rb %d, re %d => (%d,%d)\n",prb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                printf("extract rb %d, re %d => (%d,%d)\n",prb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
               }
+
 #endif
               rxF_ext+=6;
               dl_ch0_ext+=6;
@@ -6048,10 +5625,11 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF,
                   dl_ch1_ext[j]=dl_ch1p[i];
                   rxF_ext[j++]=rxF[i];
 #ifdef DEBUG_DLSCH_DEMOD
-                  printf("(pilots)extract rb %d, re %d (%d) => (%d,%d)\n",prb,i,j,*(short *)&rxF[i],*(1+(short*)&rxF[i]));
+                  printf("(pilots)extract rb %d, re %d (%d) => (%d,%d)\n",prb,i,j,*(short *)&rxF[i],*(1+(short *)&rxF[i]));
 #endif
                 }
               }
+
               rxF       = &rxdataF[aarx][1+symbol*(frame_parms->ofdm_symbol_size)];
 
               for (; i<12; i++) {
@@ -6061,7 +5639,7 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF,
                   dl_ch1_ext[j]=dl_ch1p[i];
                   rxF_ext[j++]=rxF[i-6];
 #ifdef DEBUG_DLSCH_DEMOD
-                  printf("(pilots)extract rb %d, re %d (%d) => (%d,%d)\n",prb,i,j,*(short *)&rxF[1+i-6],*(1+(short*)&rxF[1+i-6]));
+                  printf("(pilots)extract rb %d, re %d (%d) => (%d,%d)\n",prb,i,j,*(short *)&rxF[1+i-6],*(1+(short *)&rxF[1+i-6]));
 #endif
                 }
               }
@@ -6075,6 +5653,7 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF,
       } // if rballoc==1
     } // for prb
   } // for aarx
+
   return(nb_rb/frame_parms->nb_antennas_rx);
 }
 
@@ -6086,26 +5665,22 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF,
                                      unsigned char symbol,
                                      unsigned char subframe,
                                      uint32_t high_speed_flag,
-                                     LTE_DL_FRAME_PARMS *frame_parms)
-{
-
+                                     LTE_DL_FRAME_PARMS *frame_parms) {
   unsigned short rb,nb_rb=0;
   unsigned char rb_alloc_ind;
   unsigned char i,aarx,l,nsymb,skip_half=0,sss_symb,pss_symb=0;
   int *dl_ch0,*dl_ch0_ext,*rxF,*rxF_ext;
-
   unsigned char symbol_mod,pilots=0,uespec_pilots=0,j=0,poffset=0,uespec_poffset=0;
   int8_t uespec_nushift = frame_parms->Nid_cell%3;
-
   symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol;
   pilots = ((symbol_mod==0)||(symbol_mod==(4-frame_parms->Ncp))) ? 1 : 0;
   l=symbol;
   nsymb = (frame_parms->Ncp==NORMAL) ? 14:12;
 
-  if (frame_parms->Ncp==0){
+  if (frame_parms->Ncp==0) {
     if (symbol==3 || symbol==6 || symbol==9 || symbol==12)
       uespec_pilots = 1;
-  } else{
+  } else {
     if (symbol==4 || symbol==7 || symbol==10)
       uespec_pilots = 1;
   }
@@ -6125,20 +5700,17 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF,
     uespec_poffset=2;
 
   for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
-
     if (high_speed_flag == 1)
       dl_ch0     = &dl_bf_ch_estimates[aarx][symbol*(frame_parms->ofdm_symbol_size)];
     else
       dl_ch0     = &dl_bf_ch_estimates[aarx][0];
 
     dl_ch0_ext = &dl_bf_ch_estimates_ext[aarx][symbol*(frame_parms->N_RB_DL*12)];
-
     rxF_ext    = &rxdataF_ext[aarx][symbol*(frame_parms->N_RB_DL*12)];
     rxF        = &rxdataF[aarx][(frame_parms->first_carrier_offset + (symbol*(frame_parms->ofdm_symbol_size)))];
 
     if ((frame_parms->N_RB_DL&1) == 0)  // even number of RBs
       for (rb=0; rb<frame_parms->N_RB_DL; rb++) {
-
         if (rb < 32)
           rb_alloc_ind = (rb_alloc[0]>>rb) & 1;
         else if (rb < 64)
@@ -6150,7 +5722,7 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF,
         else
           rb_alloc_ind = 0;
 
-  if (rb_alloc_ind == 1)
+        if (rb_alloc_ind == 1)
           nb_rb++;
 
         // For second half of RBs skip DC carrier
@@ -6169,7 +5741,6 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF,
           rb_alloc_ind = 0;
         }
 
-
         if (frame_parms->frame_type == FDD) {
           //PSS
           if (((subframe==0)||(subframe==5)) && (rb>=((frame_parms->N_RB_DL>>1)-3)) && (rb<((frame_parms->N_RB_DL>>1)+3)) && (l==pss_symb) ) {
@@ -6185,7 +5756,6 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF,
         }
 
         if (rb_alloc_ind==1) {
-
           /*
               printf("rb %d\n",rb);
               for (i=0;i<12;i++)
@@ -6214,39 +5784,33 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF,
 
             dl_ch0_ext+=10;
             rxF_ext+=10;
-
           } else if (pilots==0 && uespec_pilots==1) {
             j=0;
 
-
-      for (i=0; i<12; i++){
-              if (frame_parms->Ncp==0){
-                if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12){
-      rxF_ext[j] = rxF[i];
+            for (i=0; i<12; i++) {
+              if (frame_parms->Ncp==0) {
+                if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12) {
+                  rxF_ext[j] = rxF[i];
                   dl_ch0_ext[j++]=dl_ch0[i];
                 }
-              } else{
-                if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12){
-      rxF_ext[j] = rxF[i];
+              } else {
+                if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12) {
+                  rxF_ext[j] = rxF[i];
                   dl_ch0_ext[j++]=dl_ch0[i];
                 }
               }
-
-      }
+            }
 
             dl_ch0_ext+=9-frame_parms->Ncp;
             rxF_ext+=9-frame_parms->Ncp;
-
           } else {
             LOG_E(PHY,"dlsch_extract_rbs_TM7(dl_demodulation.c):pilot or ue spec pilot detection error\n");
             exit(-1);
           }
-
         }
 
         dl_ch0+=12;
         rxF+=12;
-
       }
     else {  // Odd number of RBs
       for (rb=0; rb<frame_parms->N_RB_DL>>1; rb++) {
@@ -6319,7 +5883,6 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF,
             skip_half=2;
         }
 
-
         if (rb_alloc_ind==1) {
 #ifdef DEBUG_DLSCH_DEMOD
           printf("rb %d/symbol %d pilots %d, uespec_pilots %d, (skip_half %d)\n",rb,l,pilots,uespec_pilots,skip_half);
@@ -6327,14 +5890,13 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF,
 
           if (pilots==0 && uespec_pilots==0) {
             //printf("Extracting w/o pilots (symbol %d, rb %d, skip_half %d)\n",l,rb,skip_half);
-
             if (skip_half==1) {
               memcpy(dl_ch0_ext,dl_ch0,6*sizeof(int));
 
               for (i=0; i<6; i++) {
                 rxF_ext[i]=rxF[i];
 #ifdef DEBUG_DLSCH_DEMOD
-    printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
               }
 
@@ -6346,7 +5908,7 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF,
               for (i=0; i<6; i++) {
                 rxF_ext[i]=rxF[(i+6)];
 #ifdef DEBUG_DLSCH_DEMOD
-    printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
               }
 
@@ -6355,12 +5917,13 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF,
             } else {
               memcpy(dl_ch0_ext,dl_ch0,12*sizeof(int));
 
-              for (i=0; i<12; i++){
+              for (i=0; i<12; i++) {
                 rxF_ext[i]=rxF[i];
 #ifdef DEBUG_DLSCH_DEMOD
-                printf("extract rb %d, re %d => (%d,%d)\n",symbol,rb,i,*(short *)&rxF[i],*(1+(short*)&rxF[i]));
+                printf("extract symbol %d rb %d, re %d => (%d,%d)\n",symbol,rb,i,*(short *)&rxF[i],*(1+(short *)&rxF[i]));
 #endif
               }
+
               dl_ch0_ext+=12;
               rxF_ext+=12;
             }
@@ -6374,7 +5937,7 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF,
                   rxF_ext[j]=rxF[i];
                   dl_ch0_ext[j++]=dl_ch0[i];
 #ifdef DEBUG_DLSCH_DEMOD
-    printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                  printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
                 }
               }
@@ -6387,7 +5950,7 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF,
                   rxF_ext[j]=rxF[(i+6)];
                   dl_ch0_ext[j++]=dl_ch0[i+6];
 #ifdef DEBUG_DLSCH_DEMOD
-    printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                  printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
                 }
               }
@@ -6400,107 +5963,103 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF,
                     (i!=((frame_parms->nushift+poffset+6)%12))) {
                   rxF_ext[j]=rxF[i];
 #ifdef DEBUG_DLSCH_DEMOD
-                  printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j]));
+                  printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short *)&rxF_ext[j]));
 #endif
                   dl_ch0_ext[j++]=dl_ch0[i];
-
                 }
               }
 
               dl_ch0_ext+=10;
               rxF_ext+=10;
             }
-          } else if(pilots==0 && uespec_pilots==1){
+          } else if(pilots==0 && uespec_pilots==1) {
             //printf("Extracting with uespec pilots (symbol %d, rb %d, skip_half %d)\n",l,rb,skip_half);
             j=0;
 
             if (skip_half==1) {
-              if (frame_parms->Ncp==0){
+              if (frame_parms->Ncp==0) {
                 for (i=0; i<6; i++) {
-                  if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12){
+                  if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12) {
                     rxF_ext[j]=rxF[i];
                     dl_ch0_ext[j++]=dl_ch0[i];
 #ifdef DEBUG_DLSCH_DEMOD
-              printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                    printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
                   }
                 }
+
                 dl_ch0_ext+=6-(uespec_nushift+uespec_poffset<6)-(uespec_nushift+uespec_poffset+4<6)-((uespec_nushift+uespec_poffset+8)%12<6);
                 rxF_ext+=6-(uespec_nushift+uespec_poffset<6)-(uespec_nushift+uespec_poffset+4<6)-((uespec_nushift+uespec_poffset+8)%12<6);
-
-              } else{
+              } else {
                 for (i=0; i<6; i++) {
-                  if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12){
+                  if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12) {
                     rxF_ext[j]=rxF[i];
                     dl_ch0_ext[j++]=dl_ch0[i];
 #ifdef DEBUG_DLSCH_DEMOD
-        printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                    printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
                   }
                 }
+
                 dl_ch0_ext+=4;
                 rxF_ext+=4;
               }
-
             } else if (skip_half==2) {
-              if(frame_parms->Ncp==0){
+              if(frame_parms->Ncp==0) {
                 for (i=0; i<6; i++) {
-                  if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12){
+                  if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12) {
                     rxF_ext[j]=rxF[(i+6)];
                     dl_ch0_ext[j++]=dl_ch0[i+6];
 #ifdef DEBUG_DLSCH_DEMOD
-              printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                    printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
                   }
                 }
+
                 dl_ch0_ext+=6-(uespec_nushift+uespec_poffset>6)-(uespec_nushift+uespec_poffset+4>6)-((uespec_nushift+uespec_poffset+8)%12>6);
                 rxF_ext+=6-(uespec_nushift+uespec_poffset>6)-(uespec_nushift+uespec_poffset+4>6)-((uespec_nushift+uespec_poffset+8)%12>6);
-
               } else {
                 for (i=0; i<6; i++) {
-                  if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12){
+                  if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12) {
                     rxF_ext[j]=rxF[(i+6)];
                     dl_ch0_ext[j++]=dl_ch0[i+6];
 #ifdef DEBUG_DLSCH_DEMOD
-        printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                    printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
                   }
                 }
+
                 dl_ch0_ext+=4;
                 rxF_ext+=4;
               }
-
             } else {
-
-        for (i=0; i<12; i++){
-                if (frame_parms->Ncp==0){
-                  if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12){
-              rxF_ext[j] = rxF[i];
+              for (i=0; i<12; i++) {
+                if (frame_parms->Ncp==0) {
+                  if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12) {
+                    rxF_ext[j] = rxF[i];
                     dl_ch0_ext[j++] = dl_ch0[i];
 #ifdef DEBUG_DLSCH_DEMOD
-                    printf("extract rb %d, re %d, j %d => (%d,%d)\n",symbol,rb,i,j-1,*(short *)&dl_ch0[j],*(1+(short*)&dl_ch0[i]));
+                    printf("extract symbol %d, rb %d, re %d, j %d => (%d,%d)\n",
+                           symbol,rb,i,j-1,*(short *)&dl_ch0[j],*(1+(short *)&dl_ch0[i]));
 #endif
                   }
-                } else{
-                  if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12){
-              rxF_ext[j] = rxF[i];
+                } else {
+                  if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12) {
+                    rxF_ext[j] = rxF[i];
                     dl_ch0_ext[j++]=dl_ch0[i];
 #ifdef DEBUG_DLSCH_DEMOD
-        printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                    printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
                   }
                 }
-
-        }
+              }
 
               dl_ch0_ext+=9-frame_parms->Ncp;
               rxF_ext+=9-frame_parms->Ncp;
-      }
-
+            }
           } else {
             LOG_E(PHY,"dlsch_extract_rbs_TM7(dl_demodulation.c):pilot or ue spec pilot detection error\n");
             exit(-1);
-
           }
         }
 
@@ -6508,7 +6067,6 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF,
         rxF+=12;
       } // first half loop
 
-
       // Do middle RB (around DC)
       if (rb < 32)
         rb_alloc_ind = (rb_alloc[0]>>rb) & 1;
@@ -6557,7 +6115,7 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF,
             dl_ch0_ext[i]=dl_ch0[i];
             rxF_ext[i]=rxF[i];
 #ifdef DEBUG_DLSCH_DEMOD
-      printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+            printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
           }
 
@@ -6567,13 +6125,13 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF,
             dl_ch0_ext[i]=dl_ch0[i];
             rxF_ext[i]=rxF[(1+i-6)];
 #ifdef DEBUG_DLSCH_DEMOD
-      printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+            printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
           }
 
           dl_ch0_ext+=12;
           rxF_ext+=12;
-        } else if(pilots==1 && uespec_pilots==0){ // pilots==1
+        } else if(pilots==1 && uespec_pilots==0) { // pilots==1
           j=0;
 
           for (i=0; i<6; i++) {
@@ -6581,7 +6139,7 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF,
               dl_ch0_ext[j]=dl_ch0[i];
               rxF_ext[j++]=rxF[i];
 #ifdef DEBUG_DLSCH_DEMOD
-        printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+              printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
             }
           }
@@ -6593,7 +6151,7 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF,
               dl_ch0_ext[j]=dl_ch0[i];
               rxF_ext[j++]=rxF[(1+i-6)];
 #ifdef DEBUG_DLSCH_DEMOD
-        printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+              printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
             }
           }
@@ -6603,43 +6161,43 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF,
         } else if(pilots==0 && uespec_pilots==1) {
           j=0;
 
-    for (i=0; i<6; i++) {
-            if (frame_parms->Ncp==0){
-              if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12){
+          for (i=0; i<6; i++) {
+            if (frame_parms->Ncp==0) {
+              if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12) {
                 dl_ch0_ext[j]=dl_ch0[i];
-          rxF_ext[j++] = rxF[i];
+                rxF_ext[j++] = rxF[i];
 #ifdef DEBUG_DLSCH_DEMOD
-          printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
               }
             } else {
-              if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12){
+              if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12) {
                 dl_ch0_ext[j]=dl_ch0[i];
-          rxF_ext[j++] = rxF[i];
+                rxF_ext[j++] = rxF[i];
 #ifdef DEBUG_DLSCH_DEMOD
-              printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
               }
             }
-    }
+          }
 
           rxF       = &rxdataF[aarx][((symbol*(frame_parms->ofdm_symbol_size)))];
 
           for (; i<12; i++) {
-            if (frame_parms->Ncp==0){
-              if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12){
+            if (frame_parms->Ncp==0) {
+              if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12) {
                 dl_ch0_ext[j]=dl_ch0[i];
                 rxF_ext[j++]=rxF[(1+i-6)];
 #ifdef DEBUG_DLSCH_DEMOD
-          printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
               }
             } else {
-              if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12){
+              if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12) {
                 dl_ch0_ext[j]=dl_ch0[i];
-          rxF_ext[j++] = rxF[(1+i-6)];
+                rxF_ext[j++] = rxF[(1+i-6)];
 #ifdef DEBUG_DLSCH_DEMOD
-          printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
               }
             }
@@ -6647,9 +6205,7 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF,
 
           dl_ch0_ext+=9-frame_parms->Ncp;
           rxF_ext+=9-frame_parms->Ncp;
-
-  }// symbol_mod==0
-
+        }// symbol_mod==0
       } // rballoc==1
       else {
         rxF       = &rxdataF[aarx][((symbol*(frame_parms->ofdm_symbol_size)))];
@@ -6725,8 +6281,9 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF,
 
         if (rb_alloc_ind==1) {
 #ifdef DEBUG_DLSCH_DEMOD
-           printf("rb %d/symbol %d (skip_half %d)\n",rb,l,skip_half);
+          printf("rb %d/symbol %d (skip_half %d)\n",rb,l,skip_half);
 #endif
+
           /*
               printf("rb %d\n",rb);
             for (i=0;i<12;i++)
@@ -6741,26 +6298,24 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF,
               for (i=0; i<6; i++) {
                 rxF_ext[i]=rxF[i];
 #ifdef DEBUG_DLSCH_DEMOD
-          printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
               }
 
               dl_ch0_ext+=6;
               rxF_ext+=6;
-
             } else if (skip_half==2) {
               memcpy(dl_ch0_ext,dl_ch0+6,6*sizeof(int));
 
               for (i=0; i<6; i++) {
                 rxF_ext[i]=rxF[i+6];
 #ifdef DEBUG_DLSCH_DEMOD
-          printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
               }
 
               dl_ch0_ext+=6;
               rxF_ext+=6;
-
             } else {
               memcpy(dl_ch0_ext,dl_ch0,12*sizeof(int));
               //printf("symbol %d, extract rb %d, => (%d,%d)\n",symbol,rb,*(short *)&dl_ch0[j],*(1+(short*)&dl_ch0[i]));
@@ -6768,14 +6323,14 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF,
               for (i=0; i<12; i++) {
                 rxF_ext[i]=rxF[i];
 #ifdef DEBUG_DLSCH_DEMOD
-          printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
               }
 
               dl_ch0_ext+=12;
               rxF_ext+=12;
             }
-          } else if (pilots==1 && uespec_pilots==0){
+          } else if (pilots==1 && uespec_pilots==0) {
             //printf("Extracting with pilots (symbol %d, rb %d, skip_half %d)\n",l,rb,skip_half);
             j=0;
 
@@ -6785,7 +6340,7 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF,
                   rxF_ext[j]=rxF[i];
                   dl_ch0_ext[j++]=dl_ch0[i];
 #ifdef DEBUG_DLSCH_DEMOD
-            printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                  printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
                 }
               }
@@ -6798,7 +6353,7 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF,
                   rxF_ext[j]=rxF[(i+6)];
                   dl_ch0_ext[j++]=dl_ch0[i+6];
 #ifdef DEBUG_DLSCH_DEMOD
-            printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                  printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
                 }
               }
@@ -6811,7 +6366,7 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF,
                     (i!=((frame_parms->nushift+poffset+6)%12))) {
                   rxF_ext[j]=rxF[i];
 #ifdef DEBUG_DLSCH_DEMOD
-                  printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j]));
+                  printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short *)&rxF_ext[j]));
 #endif
                   dl_ch0_ext[j++]=dl_ch0[i];
                 }
@@ -6824,87 +6379,85 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF,
             j=0;
 
             if (skip_half==1) {
-              if (frame_parms->Ncp==0){
+              if (frame_parms->Ncp==0) {
                 for (i=0; i<6; i++) {
-                  if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12){
+                  if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12) {
                     rxF_ext[j]=rxF[i];
                     dl_ch0_ext[j++]=dl_ch0[i];
 #ifdef DEBUG_DLSCH_DEMOD
-              printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                    printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
                   }
                 }
+
                 dl_ch0_ext+=6-(uespec_nushift+uespec_poffset<6)-(uespec_nushift+uespec_poffset+4<6)-((uespec_nushift+uespec_poffset+8)%12<6);
                 rxF_ext+=6-(uespec_nushift+uespec_poffset<6)-(uespec_nushift+uespec_poffset+4<6)-((uespec_nushift+uespec_poffset+8)%12<6);
-
-              } else{
+              } else {
                 for (i=0; i<6; i++) {
-                  if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12){
+                  if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12) {
                     rxF_ext[j]=rxF[i];
                     dl_ch0_ext[j++]=dl_ch0[i];
 #ifdef DEBUG_DLSCH_DEMOD
-              printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                    printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
                   }
                 }
+
                 dl_ch0_ext+=4;
                 rxF_ext+=4;
               }
-
             } else if (skip_half==2) {
-              if(frame_parms->Ncp==0){
+              if(frame_parms->Ncp==0) {
                 for (i=0; i<6; i++) {
-                  if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12){
+                  if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12) {
                     rxF_ext[j]=rxF[i+6];
                     dl_ch0_ext[j++]=dl_ch0[i+6];
 #ifdef DEBUG_DLSCH_DEMOD
-              printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                    printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
                   }
                 }
+
                 dl_ch0_ext+=6-(uespec_nushift+uespec_poffset>6)-(uespec_nushift+uespec_poffset+4>6)-((uespec_nushift+uespec_poffset+8)%12>6);
                 rxF_ext+=6-(uespec_nushift+uespec_poffset>6)-(uespec_nushift+uespec_poffset+4>6)-((uespec_nushift+uespec_poffset+8)%12>6);
-
               } else {
                 for (i=0; i<6; i++) {
-                  if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12){
+                  if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12) {
                     rxF_ext[j]=rxF[(i+6)];
                     dl_ch0_ext[j++]=dl_ch0[i+6];
 #ifdef DEBUG_DLSCH_DEMOD
-              printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                    printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
                   }
                 }
+
                 dl_ch0_ext+=4;
                 rxF_ext+=4;
               }
-
             } else {
-        for (i=0; i<12; i++){
-                if (frame_parms->Ncp==0){
-                  if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12){
-              rxF_ext[j] = rxF[i];
+              for (i=0; i<12; i++) {
+                if (frame_parms->Ncp==0) {
+                  if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12) {
+                    rxF_ext[j] = rxF[i];
                     dl_ch0_ext[j++]=dl_ch0[i];
 #ifdef DEBUG_DLSCH_DEMOD
-              printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                    printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
                   }
-                } else{
-                  if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12){
-              rxF_ext[j] = rxF[i];
+                } else {
+                  if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12) {
+                    rxF_ext[j] = rxF[i];
                     dl_ch0_ext[j++]=dl_ch0[i];
 #ifdef DEBUG_DLSCH_DEMOD
-              printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i]));
+                    printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i]));
 #endif
                   }
                 }
-        }
+              }
 
               dl_ch0_ext+=9-frame_parms->Ncp;
               rxF_ext+=9-frame_parms->Ncp;
-
             }
-
           }// pilots=0
         }
 
@@ -6916,17 +6469,14 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF,
 
   _mm_empty();
   _m_empty();
-
   return(nb_rb/frame_parms->nb_antennas_rx);
 }
 
 //==============================================================================================
 
-void dump_dlsch2(PHY_VARS_UE *ue,uint8_t eNB_id,uint8_t subframe,unsigned int *coded_bits_per_codeword,int round,  unsigned char harq_pid)
-{
+void dump_dlsch2(PHY_VARS_UE *ue,uint8_t eNB_id,uint8_t subframe,unsigned int *coded_bits_per_codeword,int round,  unsigned char harq_pid) {
 #define NSYMB  ((ue->frame_parms.Ncp == 0) ? 14 : 12)
   char fname[32],vname[32];
-
   sprintf(fname,"dlsch%d_rxF_r%d_ext0.m",eNB_id,round);
   sprintf(vname,"dl%d_rxF_r%d_ext0",eNB_id,round);
   LOG_M(fname,vname,ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->rxdataF_ext[0],
@@ -6944,12 +6494,11 @@ void dump_dlsch2(PHY_VARS_UE *ue,uint8_t eNB_id,uint8_t subframe,unsigned int *c
   LOG_M(fname,vname,ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_ch_estimates_ext[0],
         12*(ue->frame_parms.N_RB_DL)*NSYMB,1,1);
 
-  if (ue->transmission_mode[eNB_id]==7){
+  if (ue->transmission_mode[eNB_id]==7) {
     sprintf(fname,"dlsch%d_bf_ch_r%d.m",eNB_id,round);
     sprintf(vname,"dl%d_bf_ch_r%d",eNB_id,round);
     LOG_M(fname,vname,ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_bf_ch_estimates[0],512*NSYMB,1,1);
     //LOG_M(fname,vname,phy_vars_ue->lte_ue_pdsch_vars[eNB_id]->dl_bf_ch_estimates[0],512,1,1);
-
     sprintf(fname,"dlsch%d_bf_ch_r%d_ext00.m",eNB_id,round);
     sprintf(vname,"dl%d_bf_ch_r%d_ext00",eNB_id,round);
     LOG_M(fname,vname,ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_bf_ch_estimates_ext[0],
@@ -6959,8 +6508,8 @@ void dump_dlsch2(PHY_VARS_UE *ue,uint8_t eNB_id,uint8_t subframe,unsigned int *c
   if (ue->frame_parms.nb_antennas_rx == 2) {
     sprintf(fname,"dlsch%d_ch_r%d_ext01.m",eNB_id,round);
     sprintf(vname,"dl%d_ch_r%d_ext01",eNB_id,round);
-	    LOG_M(fname,vname,ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_ch_estimates_ext[1],
-            12*(ue->frame_parms.N_RB_DL)*NSYMB,1,1);
+    LOG_M(fname,vname,ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_ch_estimates_ext[1],
+          12*(ue->frame_parms.N_RB_DL)*NSYMB,1,1);
   }
 
   if (ue->frame_parms.nb_antenna_ports_eNB == 2) {
@@ -6981,7 +6530,6 @@ void dump_dlsch2(PHY_VARS_UE *ue,uint8_t eNB_id,uint8_t subframe,unsigned int *c
   sprintf(vname,"dl%d_rxF_r%d_uespec0",eNB_id,round);
   LOG_M(fname,vname,ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->rxdataF_uespec_pilots[0],
         12*(ue->frame_parms.N_RB_DL)*NSYMB,1,1);
-
   /*
     LOG_M("dlsch%d_ch_ext01.m","dl01_ch0_ext",pdsch_vars[eNB_id]->dl_ch_estimates_ext[1],12*N_RB_DL*NSYMB,1,1);
     LOG_M("dlsch%d_ch_ext10.m","dl10_ch0_ext",pdsch_vars[eNB_id]->dl_ch_estimates_ext[2],12*N_RB_DL*NSYMB,1,1);
@@ -6989,20 +6537,17 @@ void dump_dlsch2(PHY_VARS_UE *ue,uint8_t eNB_id,uint8_t subframe,unsigned int *c
   */
   sprintf(fname,"dlsch%d_r%d_rho.m",eNB_id,round);
   sprintf(vname,"dl_rho_r%d_%d",eNB_id,round);
-
   LOG_M(fname,vname,ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_ch_rho_ext[harq_pid][round][0],
         12*(ue->frame_parms.N_RB_DL)*NSYMB,1,1);
-
   sprintf(fname,"dlsch%d_r%d_rho2.m",eNB_id,round);
   sprintf(vname,"dl_rho2_r%d_%d",eNB_id,round);
-
   LOG_M(fname,vname,ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_ch_rho2_ext[0],
         12*(ue->frame_parms.N_RB_DL)*NSYMB,1,1);
-
   sprintf(fname,"dlsch%d_rxF_r%d_comp0.m",eNB_id,round);
   sprintf(vname,"dl%d_rxF_r%d_comp0",eNB_id,round);
   LOG_M(fname,vname,ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->rxdataF_comp0[0],
         12*(ue->frame_parms.N_RB_DL)*NSYMB,1,1);
+
   if (ue->frame_parms.nb_antenna_ports_eNB == 2) {
     sprintf(fname,"dlsch%d_rxF_r%d_comp1.m",eNB_id,round);
     sprintf(vname,"dl%d_rxF_r%d_comp1",eNB_id,round);
@@ -7016,12 +6561,11 @@ void dump_dlsch2(PHY_VARS_UE *ue,uint8_t eNB_id,uint8_t subframe,unsigned int *c
   sprintf(fname,"dlsch%d_r%d_mag1.m",eNB_id,round);
   sprintf(vname,"dl%d_r%d_mag1",eNB_id,round);
   LOG_M(fname,vname,ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_ch_mag0[0],
-         12*(ue->frame_parms.N_RB_DL)*NSYMB,1,1);
+        12*(ue->frame_parms.N_RB_DL)*NSYMB,1,1);
   sprintf(fname,"dlsch%d_r%d_mag2.m",eNB_id,round);
   sprintf(vname,"dl%d_r%d_mag2",eNB_id,round);
   LOG_M(fname,vname,ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_ch_magb0[0],
         12*(ue->frame_parms.N_RB_DL)*NSYMB,1,1);
-
 }
 
 
diff --git a/openair1/PHY/LTE_UE_TRANSPORT/dlsch_llr_computation.c b/openair1/PHY/LTE_UE_TRANSPORT/dlsch_llr_computation.c
index ea3f100504e8b263b16e8e230e3bc7ba310f3910..4c74377ef6f4a323df9d96b46e993beadeac2908 100644
--- a/openair1/PHY/LTE_UE_TRANSPORT/dlsch_llr_computation.c
+++ b/openair1/PHY/LTE_UE_TRANSPORT/dlsch_llr_computation.c
@@ -673,14 +673,14 @@ int dlsch_qpsk_llr(LTE_DL_FRAME_PARMS *frame_parms,
   }
 
 
-  /*
-  LOG_I(PHY,"dlsch_qpsk_llr: [symb %d / FirstSym %d / Length %d]: @LLR Buff %x, @LLR Buff(symb) %x \n",
-             symbol,
-             first_symbol_flag,
-             len,
-             dlsch_llr,
-             llr32);
-  */
+  LOG_D(PHY,"[p %d : symb %d / FirstSym %d / Length %d]: @LLR Buff %p, @LLR Buff(symb) %p \n",
+	frame_parms->nb_antenna_ports_eNB,
+	symbol,
+	first_symbol_flag,
+	len,
+	dlsch_llr,
+	llr32);
+
 
   qpsk_llr((short *)rxF,
            (short *)llr32,
diff --git a/openair1/PHY/LTE_UE_TRANSPORT/linear_preprocessing_rec.h b/openair1/PHY/LTE_UE_TRANSPORT/linear_preprocessing_rec.h
old mode 100755
new mode 100644
diff --git a/openair1/PHY/LTE_UE_TRANSPORT/transport_proto_ue.h b/openair1/PHY/LTE_UE_TRANSPORT/transport_proto_ue.h
index 49b9e8b808b5fd0db93c0e0323d2ac68a4f4ab03..dc841075b4e72459e2068ac062d18397ec88cd6f 100644
--- a/openair1/PHY/LTE_UE_TRANSPORT/transport_proto_ue.h
+++ b/openair1/PHY/LTE_UE_TRANSPORT/transport_proto_ue.h
@@ -1361,6 +1361,10 @@ 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
+void init_mpdcch(PHY_VARS_eNB *eNB);
+#endif
+
 int32_t compareints (const void * a, const void * b);
 
 
@@ -1438,8 +1442,6 @@ uint8_t rx_pcfich(LTE_DL_FRAME_PARMS *frame_parms,
 void generate_phich_reg_mapping(LTE_DL_FRAME_PARMS *frame_parms);
 
 
-void init_transport_channels(uint8_t);
-
 void generate_RIV_tables(void);
 
 /*!
@@ -1608,7 +1610,6 @@ void generate_pucch3x(int32_t **txdataF,
                     uint8_t subframe,
                     uint16_t rnti);
 
-
 void init_ulsch_power_LUT(void);
 
 /*!
diff --git a/openair1/PHY/LTE_UE_TRANSPORT/ulsch_coding.c b/openair1/PHY/LTE_UE_TRANSPORT/ulsch_coding.c
index b62c5c55449cc351fc1540e42d6175e2a2517c18..cc1f762e7046b9836d0c898d6c459afd9f34cb89 100644
--- a/openair1/PHY/LTE_UE_TRANSPORT/ulsch_coding.c
+++ b/openair1/PHY/LTE_UE_TRANSPORT/ulsch_coding.c
@@ -80,7 +80,6 @@ void free_ue_ulsch(LTE_UE_ULSCH_t *ulsch)
       }
     }
     free16(ulsch,sizeof(LTE_UE_ULSCH_t));
-    ulsch = NULL;
   }
 
 }
diff --git a/openair1/PHY/MODULATION/compute_bf_weights.c b/openair1/PHY/MODULATION/compute_bf_weights.c
index 89d76058e6d2b1859124a14408704403fc9f778b..5c132062977ac574295022e232183738016013c9 100644
--- a/openair1/PHY/MODULATION/compute_bf_weights.c
+++ b/openair1/PHY/MODULATION/compute_bf_weights.c
@@ -22,6 +22,7 @@ int f_read(char *calibF_fname, int nb_ant, int nb_freq, int32_t **tdd_calib_coef
     }
     printf("%d\n",(int)tdd_calib_coeffs[0][0]);
     printf("%d\n",(int)tdd_calib_coeffs[1][599]);
+    fclose(calibF_fd);
   } else
    printf("%s not found, running with defaults\n",calibF_fname);
   /* TODO: what to return? is this code used at all? */
diff --git a/openair1/PHY/MODULATION/prach625Hz.h b/openair1/PHY/MODULATION/prach625Hz.h
deleted file mode 100644
index 38b63b3b053bb02d7e609137bcfcd0af78031d1c..0000000000000000000000000000000000000000
--- a/openair1/PHY/MODULATION/prach625Hz.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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
- */
-
-int16_t sig625_1_25MHz[2850*2];
-int16_t sig625_2_5MHz[5700*2];
-int16_t sig625_5MHz[11400*2];
-int16_t sig625_10MHz[22800*2];
-int16_t sig625_15MHz[34200*2];
-int16_t sig625_20MHz[45600*2];
diff --git a/openair1/PHY/MODULATION/slot_fep.c b/openair1/PHY/MODULATION/slot_fep.c
index b01979431dcf88212604aa71cf0d0470eb177d06..58cd46a73ffa6760b6c363f5ded012f7f590b160 100644
--- a/openair1/PHY/MODULATION/slot_fep.c
+++ b/openair1/PHY/MODULATION/slot_fep.c
@@ -33,9 +33,7 @@ int slot_fep(PHY_VARS_UE *ue,
              unsigned char Ns,
              int sample_offset,
              int no_prefix,
-	     int reset_freq_est)
-{
-
+             int reset_freq_est) {
   LTE_DL_FRAME_PARMS *frame_parms = &ue->frame_parms;
   LTE_UE_COMMON *common_vars   = &ue->common_vars;
   uint8_t eNB_id = 0;//ue_common_vars->eNb_id;
@@ -48,43 +46,41 @@ int slot_fep(PHY_VARS_UE *ue,
   int i;
   unsigned int frame_length_samples = frame_parms->samples_per_tti * 10;
   unsigned int rx_offset;
-
   /*LTE_UE_DLSCH_t **dlsch_ue = phy_vars_ue->dlsch_ue[eNB_id];
-  unsigned char harq_pid = dlsch_ue[0]->current_harq_pid; 
+  unsigned char harq_pid = dlsch_ue[0]->current_harq_pid;
   LTE_DL_UE_HARQ_t *dlsch0_harq = dlsch_ue[0]->harq_processes[harq_pid];
   int uespec_pilot[9][1200];*/
-
   void (*dft)(int16_t *,int16_t *, int);
   int tmp_dft_in[2048] __attribute__ ((aligned (32)));  // This is for misalignment issues for 6 and 15 PRBs
 
   switch (frame_parms->ofdm_symbol_size) {
-  case 128:
-    dft = dft128;
-    break;
+    case 128:
+      dft = dft128;
+      break;
 
-  case 256:
-    dft = dft256;
-    break;
+    case 256:
+      dft = dft256;
+      break;
 
-  case 512:
-    dft = dft512;
-    break;
+    case 512:
+      dft = dft512;
+      break;
 
-  case 1024:
-    dft = dft1024;
-    break;
+    case 1024:
+      dft = dft1024;
+      break;
 
-  case 1536:
-    dft = dft1536;
-    break;
+    case 1536:
+      dft = dft1536;
+      break;
 
-  case 2048:
-    dft = dft2048;
-    break;
+    case 2048:
+      dft = dft2048;
+      break;
 
-  default:
-    dft = dft512;
-    break;
+    default:
+      dft = dft512;
+      break;
   }
 
   if (no_prefix) {
@@ -97,7 +93,6 @@ int slot_fep(PHY_VARS_UE *ue,
 
   //  subframe_offset_F = frame_parms->ofdm_symbol_size * frame_parms->symbols_per_tti * (Ns>>1);
 
-
   if (l<0 || l>=7-frame_parms->Ncp) {
     printf("slot_fep: l must be between 0 and %d\n",7-frame_parms->Ncp);
     return(-1);
@@ -108,17 +103,13 @@ int slot_fep(PHY_VARS_UE *ue,
     return(-1);
   }
 
-
-
   for (aa=0; aa<frame_parms->nb_antennas_rx; aa++) {
     memset(&common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],0,frame_parms->ofdm_symbol_size*sizeof(int));
-
     rx_offset = sample_offset + slot_offset + nb_prefix_samples0 + subframe_offset - SOFFSET;
     // Align with 256 bit
     //    rx_offset = rx_offset&0xfffffff8;
 
     if (l==0) {
-
       if (rx_offset > (frame_length_samples - frame_parms->ofdm_symbol_size))
         memcpy((short *)&common_vars->rxdata[aa][frame_length_samples],
                (short *)&common_vars->rxdata[aa][0],
@@ -132,30 +123,29 @@ int slot_fep(PHY_VARS_UE *ue,
             (int16_t *)&common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
       } else { // use dft input from RX buffer directly
 #if UE_TIMING_TRACE
-          start_meas(&ue->rx_dft_stats);
+        start_meas(&ue->rx_dft_stats);
 #endif
-
         dft((int16_t *)&common_vars->rxdata[aa][(rx_offset) % frame_length_samples],
             (int16_t *)&common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
 #if UE_TIMING_TRACE
         stop_meas(&ue->rx_dft_stats);
 #endif
-
       }
     } else {
       rx_offset += (frame_parms->ofdm_symbol_size+nb_prefix_samples)*l;// +
       //                   (frame_parms->ofdm_symbol_size+nb_prefix_samples)*(l-1);
-
 #ifdef DEBUG_FEP
       //  if (ue->frame <100)
-      LOG_I(PHY,"slot_fep: frame %d: slot %d, symbol %d, nb_prefix_samples %d, nb_prefix_samples0 %d, slot_offset %d, subframe_offset %d, sample_offset %d,rx_offset %d, frame_length_samples %d\n", ue->proc.proc_rxtx[(Ns>>1)&1].frame_rx,Ns, symbol,
-          nb_prefix_samples,nb_prefix_samples0,slot_offset,subframe_offset,sample_offset,rx_offset,frame_length_samples);
+      LOG_I(PHY,"slot_fep: frame %d: slot %d, symbol %d, nb_prefix_samples %d, nb_prefix_samples0 %d, slot_offset %d, subframe_offset %d, sample_offset %d,rx_offset %d, frame_length_samples %d\n",
+            ue->proc.proc_rxtx[(Ns>>1)&1].frame_rx,Ns, symbol,
+            nb_prefix_samples,nb_prefix_samples0,slot_offset,subframe_offset,sample_offset,rx_offset,frame_length_samples);
 #endif
 
       if (rx_offset > (frame_length_samples - frame_parms->ofdm_symbol_size))
         memcpy((void *)&common_vars->rxdata[aa][frame_length_samples],
                (void *)&common_vars->rxdata[aa][0],
                frame_parms->ofdm_symbol_size*sizeof(int));
+
 #if UE_TIMING_TRACE
       start_meas(&ue->rx_dft_stats);
 #endif
@@ -167,27 +157,25 @@ int slot_fep(PHY_VARS_UE *ue,
         dft((int16_t *)tmp_dft_in,
             (int16_t *)&common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
       } else { // use dft input from RX buffer directly
-
         dft((int16_t *)&common_vars->rxdata[aa][(rx_offset) % frame_length_samples],
             (int16_t *)&common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
       }
+
 #if UE_TIMING_TRACE
       stop_meas(&ue->rx_dft_stats);
 #endif
-
-
     }
 
-    #ifdef DEBUG_FEP
-        //  if (ue->frame <100)
-        printf("slot_fep: frame %d: symbol %d rx_offset %d\n", ue->proc.proc_rxtx[(Ns>>1)&1].frame_rx, symbol,rx_offset);
-    #endif
+
+#ifdef DEBUG_FEP
+    //  if (ue->frame <100)
+    printf("slot_fep: frame %d: symbol %d rx_offset %u\n", ue->proc.proc_rxtx[(Ns>>1)&1].frame_rx, symbol,rx_offset);
+#endif
   }
 
   if (ue->perfect_ce == 0) {
     if ((l==0) || (l==(4-frame_parms->Ncp))) {
       for (aa=0; aa<frame_parms->nb_antenna_ports_eNB; aa++) {
-
 #ifdef DEBUG_FEP
         printf("Channel estimation eNB %d, aatx %d, slot %d, symbol %d\n",eNB_id,aa,Ns,l);
 #endif
@@ -212,7 +200,6 @@ int slot_fep(PHY_VARS_UE *ue,
         }
       }
 
-
       // do frequency offset estimation here!
       // use channel estimates from current symbol (=ch_t) and last symbol (ch_{t-1})
 #ifdef DEBUG_FEP
@@ -220,23 +207,19 @@ int slot_fep(PHY_VARS_UE *ue,
 #endif
 
       if (l==(4-frame_parms->Ncp)) {
-
 #if UE_TIMING_TRACE
-          start_meas(&ue->dlsch_freq_offset_estimation_stats);
+        start_meas(&ue->dlsch_freq_offset_estimation_stats);
 #endif
-
         lte_est_freq_offset(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].dl_ch_estimates[0],
                             frame_parms,
                             l,
                             &common_vars->freq_offset,
-			    reset_freq_est);
+                            reset_freq_est);
 #if UE_TIMING_TRACE
         stop_meas(&ue->dlsch_freq_offset_estimation_stats);
 #endif
-
       }
     }
-
   }
 
 #ifdef DEBUG_FEP
@@ -246,11 +229,10 @@ int slot_fep(PHY_VARS_UE *ue,
 }
 
 int front_end_fft(PHY_VARS_UE *ue,
-             unsigned char l,
-             unsigned char Ns,
-             int sample_offset,
-             int no_prefix)
-{
+                  unsigned char l,
+                  unsigned char Ns,
+                  int sample_offset,
+                  int no_prefix) {
   LTE_DL_FRAME_PARMS *frame_parms = &ue->frame_parms;
   LTE_UE_COMMON *common_vars   = &ue->common_vars;
   unsigned char aa;
@@ -262,43 +244,41 @@ int front_end_fft(PHY_VARS_UE *ue,
   unsigned int frame_length_samples = frame_parms->samples_per_tti * 10;
   unsigned int rx_offset;
   uint8_t  threadId;
-
   /*LTE_UE_DLSCH_t **dlsch_ue = phy_vars_ue->dlsch_ue[eNB_id];
   unsigned char harq_pid = dlsch_ue[0]->current_harq_pid;
   LTE_DL_UE_HARQ_t *dlsch0_harq = dlsch_ue[0]->harq_processes[harq_pid];
   int uespec_pilot[9][1200];*/
-
   void (*dft)(int16_t *,int16_t *, int);
   int tmp_dft_in[2048] __attribute__ ((aligned (32)));  // This is for misalignment issues for 6 and 15 PRBs
 
   switch (frame_parms->ofdm_symbol_size) {
-  case 128:
-    dft = dft128;
-    break;
+    case 128:
+      dft = dft128;
+      break;
 
-  case 256:
-    dft = dft256;
-    break;
+    case 256:
+      dft = dft256;
+      break;
 
-  case 512:
-    dft = dft512;
-    break;
+    case 512:
+      dft = dft512;
+      break;
 
-  case 1024:
-    dft = dft1024;
-    break;
+    case 1024:
+      dft = dft1024;
+      break;
 
-  case 1536:
-    dft = dft1536;
-    break;
+    case 1536:
+      dft = dft1536;
+      break;
 
-  case 2048:
-    dft = dft2048;
-    break;
+    case 2048:
+      dft = dft2048;
+      break;
 
-  default:
-    dft = dft512;
-    break;
+    default:
+      dft = dft512;
+      break;
   }
 
   if (no_prefix) {
@@ -311,7 +291,6 @@ int front_end_fft(PHY_VARS_UE *ue,
 
   //  subframe_offset_F = frame_parms->ofdm_symbol_size * frame_parms->symbols_per_tti * (Ns>>1);
 
-
   if (l<0 || l>=7-frame_parms->Ncp) {
     printf("slot_fep: l must be between 0 and %d\n",7-frame_parms->Ncp);
     return(-1);
@@ -322,19 +301,16 @@ int front_end_fft(PHY_VARS_UE *ue,
     return(-1);
   }
 
-
-
   threadId = ue->current_thread_id[Ns>>1];
+
   for (aa=0; aa<frame_parms->nb_antennas_rx; aa++) {
-      // change thread index
+    // change thread index
     memset(&common_vars->common_vars_rx_data_per_thread[threadId].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],0,frame_parms->ofdm_symbol_size*sizeof(int));
-
     rx_offset = sample_offset + slot_offset + nb_prefix_samples0 + subframe_offset - SOFFSET;
     // Align with 256 bit
     //    rx_offset = rx_offset&0xfffffff8;
 
     if (l==0) {
-
       if (rx_offset > (frame_length_samples - frame_parms->ofdm_symbol_size))
         memcpy((short *)&common_vars->rxdata[aa][frame_length_samples],
                (short *)&common_vars->rxdata[aa][0],
@@ -348,21 +324,19 @@ int front_end_fft(PHY_VARS_UE *ue,
             (int16_t *)&common_vars->common_vars_rx_data_per_thread[threadId].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
       } else { // use dft input from RX buffer directly
         start_meas(&ue->rx_dft_stats);
-
         dft((int16_t *)&common_vars->rxdata[aa][(rx_offset) % frame_length_samples],
             (int16_t *)&common_vars->common_vars_rx_data_per_thread[threadId].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
         stop_meas(&ue->rx_dft_stats);
-
       }
     } else {
       rx_offset += (frame_parms->ofdm_symbol_size+nb_prefix_samples)*l;// +
       //                   (frame_parms->ofdm_symbol_size+nb_prefix_samples)*(l-1);
-
 #ifdef DEBUG_FEP
       //  if (ue->frame <100)
-      LOG_I(PHY,"slot_fep: frame %d: slot %d, threadId %d, symbol %d, nb_prefix_samples %d, nb_prefix_samples0 %d, slot_offset %d, subframe_offset %d, sample_offset %d,rx_offset %d, frame_length_samples %d\n",
-              ue->proc.proc_rxtx[threadId].frame_rx,Ns, threadId,symbol,
-          nb_prefix_samples,nb_prefix_samples0,slot_offset,subframe_offset,sample_offset,rx_offset,frame_length_samples);
+      LOG_I(PHY,
+            "slot_fep: frame %d: slot %d, threadId %d, symbol %d, nb_prefix_samples %d, nb_prefix_samples0 %d, slot_offset %d, subframe_offset %d, sample_offset %d,rx_offset %d, frame_length_samples %d\n",
+            ue->proc.proc_rxtx[threadId].frame_rx,Ns, threadId,symbol,
+            nb_prefix_samples,nb_prefix_samples0,slot_offset,subframe_offset,sample_offset,rx_offset,frame_length_samples);
 #endif
 
       if (rx_offset > (frame_length_samples - frame_parms->ofdm_symbol_size))
@@ -379,29 +353,27 @@ int front_end_fft(PHY_VARS_UE *ue,
         dft((int16_t *)tmp_dft_in,
             (int16_t *)&common_vars->common_vars_rx_data_per_thread[threadId].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
       } else { // use dft input from RX buffer directly
-
         dft((int16_t *)&common_vars->rxdata[aa][(rx_offset) % frame_length_samples],
             (int16_t *)&common_vars->common_vars_rx_data_per_thread[threadId].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
       }
 
       stop_meas(&ue->rx_dft_stats);
-
-
     }
 
-    #ifdef DEBUG_FEP
-        //  if (ue->frame <100)
-        printf("slot_fep: frame %d: symbol %d rx_offset %d\n", ue->proc.proc_rxtx[threadId].frame_rx, symbol,rx_offset);
-    #endif
+#ifdef DEBUG_FEP
+    //  if (ue->frame <100)
+    printf("slot_fep: frame %d: symbol %d rx_offset %u\n", ue->proc.proc_rxtx[threadId].frame_rx, symbol,rx_offset);
+#endif
+
   }
+
   return(0);
 }
 
 int front_end_chanEst(PHY_VARS_UE *ue,
-             unsigned char l,
-             unsigned char Ns,
-             int reset_freq_est)
-{
+                      unsigned char l,
+                      unsigned char Ns,
+                      int reset_freq_est) {
   LTE_DL_FRAME_PARMS *frame_parms = &ue->frame_parms;
   LTE_UE_COMMON *common_vars   = &ue->common_vars;
   uint8_t eNB_id = 0;//ue_common_vars->eNb_id;
@@ -417,7 +389,6 @@ int front_end_chanEst(PHY_VARS_UE *ue,
   if (ue->perfect_ce == 0) {
     if ((l==0) || (l==(4-frame_parms->Ncp))) {
       for (aa=0; aa<frame_parms->nb_antenna_ports_eNB; aa++) {
-
 #ifdef DEBUG_FEP
         printf("Channel estimation eNB %d, aatx %d, slot %d, symbol %d\n",eNB_id,aa,Ns,l);
 #endif
@@ -438,7 +409,6 @@ int front_end_chanEst(PHY_VARS_UE *ue,
         }
       }
 
-
       // do frequency offset estimation here!
       // use channel estimates from current symbol (=ch_t) and last symbol (ch_{t-1})
 #ifdef DEBUG_FEP
@@ -451,12 +421,11 @@ int front_end_chanEst(PHY_VARS_UE *ue,
                             frame_parms,
                             l,
                             &common_vars->freq_offset,
-                reset_freq_est);
+                            reset_freq_est);
         stop_meas(&ue->dlsch_freq_offset_estimation_stats);
-
       }
     }
-
   }
+
   return(0);
 }
diff --git a/openair1/PHY/Makefile.inc b/openair1/PHY/Makefile.inc
deleted file mode 100644
index 90094b31f8605946ba6c18f31eb070b4ff99f484..0000000000000000000000000000000000000000
--- a/openair1/PHY/Makefile.inc
+++ /dev/null
@@ -1,91 +0,0 @@
-PHY_OBJS =  $(TOP_DIR)/PHY/LTE_TRANSPORT/pss.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/sss.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/pilots.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/pilots_ue_spec.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/pilots_mbsfn.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/dlsch_coding.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/dlsch_modulation.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/dlsch_demodulation.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/dlsch_llr_computation.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/dlsch_llr_computation_avx2.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/power_control.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/dlsch_decoding.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/dlsch_scrambling.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/dci_tools.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/uci_tools.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/lte_mcs.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/pbch.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/dci.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/phich.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/pcfich.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/pucch.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/prach.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/pmch.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/group_hopping.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/srs_modulation.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/drs_modulation.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/ulsch_modulation.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/ulsch_demodulation.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/ulsch_coding.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/ulsch_decoding.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/rar_tools.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/print_stats.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/initial_sync.o
-#PHY_OBJS += $(TOP_DIR)/PHY/LTE_TRANSPORT/lte_transport_init.o
-PHY_OBJS += $(TOP_DIR)/PHY/MODULATION/ofdm_mod.o
-PHY_OBJS += $(TOP_DIR)/PHY/MODULATION/slot_fep.o
-PHY_OBJS += $(TOP_DIR)/PHY/MODULATION/slot_fep_mbsfn.o
-PHY_OBJS += $(TOP_DIR)/PHY/MODULATION/slot_fep_ul.o
-PHY_OBJS += $(TOP_DIR)/PHY/MODULATION/ul_7_5_kHz.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_ESTIMATION/freq_equalization.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_ESTIMATION/lte_sync_time.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_ESTIMATION/lte_sync_timefreq.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_ESTIMATION/lte_adjust_sync.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_ESTIMATION/lte_dl_channel_estimation.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_ESTIMATION/lte_dl_bf_channel_estimation.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_ESTIMATION/lte_dl_mbsfn_channel_estimation.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_ESTIMATION/lte_ul_channel_estimation.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_ESTIMATION/lte_est_freq_offset.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_ESTIMATION/lte_ue_measurements.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_ESTIMATION/lte_eNB_measurements.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_ESTIMATION/adjust_gain.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_REFSIG/lte_dl_cell_spec.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_REFSIG/lte_dl_ue_spec.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_REFSIG/lte_gold.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_REFSIG/lte_gold_mbsfn.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_REFSIG/lte_dl_mbsfn.o
-PHY_OBJS += $(TOP_DIR)/PHY/LTE_REFSIG/lte_ul_ref.o
-PHY_OBJS += $(TOP_DIR)/PHY/CODING/lte_segmentation.o
-PHY_OBJS += $(TOP_DIR)/PHY/CODING/ccoding_byte.o
-PHY_OBJS += $(TOP_DIR)/PHY/CODING/ccoding_byte_lte.o
-#PHY_OBJS += $(TOP_DIR)/PHY/CODING/3gpplte.o
-PHY_OBJS += $(TOP_DIR)/PHY/CODING/3gpplte_sse.o
-PHY_OBJS += $(TOP_DIR)/PHY/CODING/crc_byte.o
-#PHY_OBJS += $(TOP_DIR)/PHY/CODING/3gpplte_turbo_decoder_sse.o
-PHY_OBJS += $(TOP_DIR)/PHY/CODING/3gpplte_turbo_decoder_sse_8bit.o
-PHY_OBJS += $(TOP_DIR)/PHY/CODING/3gpplte_turbo_decoder_sse_16bit.o
-PHY_OBJS += $(TOP_DIR)/PHY/CODING/lte_rate_matching.o
-PHY_OBJS += $(TOP_DIR)/PHY/CODING/rate_matching.o
-PHY_OBJS += $(TOP_DIR)/PHY/CODING/viterbi.o
-PHY_OBJS += $(TOP_DIR)/PHY/CODING/viterbi_lte.o
-PHY_OBJS += $(TOP_DIR)/PHY/INIT/lte_init.o
-PHY_OBJS += $(TOP_DIR)/PHY/INIT/lte_parms.o
-PHY_OBJS += $(TOP_DIR)/PHY/INIT/init_top.o
-PHY_OBJS += $(TOP_DIR)/PHY/TOOLS/file_output.o
-#PHY_OBJS += $(TOP_DIR)/PHY/TOOLS/fft.o
-PHY_OBJS += $(TOP_DIR)/PHY/TOOLS/lte_dfts.o
-PHY_OBJS += $(TOP_DIR)/PHY/TOOLS/log2_approx.o
-PHY_OBJS += $(TOP_DIR)/PHY/TOOLS/cmult_sv.o
-PHY_OBJS += $(TOP_DIR)/PHY/TOOLS/cmult_vv.o
-PHY_OBJS += $(TOP_DIR)/PHY/TOOLS/cadd_vv.o
-PHY_OBJS += $(TOP_DIR)/PHY/TOOLS/cdot_prod.o
-PHY_OBJS += $(TOP_DIR)/PHY/TOOLS/signal_energy.o
-PHY_OBJS += $(TOP_DIR)/PHY/TOOLS/dB_routines.o
-PHY_OBJS += $(TOP_DIR)/PHY/TOOLS/sqrt.o
-ifdef SMBV
-PHY_OBJS += $(TOP_DIR)/PHY/TOOLS/smbv.o
-endif
-PHY_OBJS += $(TOP_DIR)/PHY/TOOLS/time_meas.o
-PHY_OBJS += $(TOP_DIR)/PHY/TOOLS/lut.o
-#PHY_OBJS += $(TOP_DIR)/SIMULATION/TOOLS/rangen_double.o
-
diff --git a/openair1/PHY/TOOLS/lte_dfts.c b/openair1/PHY/TOOLS/lte_dfts.c
index 45373ab9e2ac57f768c59f2a80e20123062587fc..b8633b5126c43ce23d34b21e1bf9970b589ded47 100644
--- a/openair1/PHY/TOOLS/lte_dfts.c
+++ b/openair1/PHY/TOOLS/lte_dfts.c
@@ -9494,7 +9494,7 @@ int main(int argc, char**argv)
   LOG_M("x24576.m","x24576",x,24576,1,1);
 
   int dftsizes[33]={24,36,48,60,72,96,108,120,144,180,192,216,240,288,300,324,360,384,432,480,540,576,600,648,720,768,864,900,960,972,1080,1152,1200};
-  void (*dft[33])(int16_t *x,int16_t *y,uint8_t scale) = {dft24,dft36,dft48,dft60,dft72,dft96,dft108,dft120,dft144,dft180,dft192,dft216,dft240,dft288,dft300,dft324,dft360,dft384,dft432,dft480,dft540,dft576,dft600,dft648,dft720,dft768,dft864,dft900,dft960,dft972,dft1080,dft1152,dft1200};
+  void (*dft)(int16_t *x,int16_t *y,uint8_t scale)[33] = {dft24,dft36,dft48,dft60,dft72,dft96,dft108,dft120,dft144,dft180,dft192,dft216,dft240,dft288,dft300,dft324,dft360,dft384,dft432,dft480,dft540,dft576,dft600,dft648,dft720,dft768,dft864,dft900,dft960,dft972,dft1080,dft1152,dft1200};
   for (int n=0;n<33;n++) {
     // 4xN-point DFT
     memset((void*)x,0,dftsizes[n]*8*sizeof(int16_t));
diff --git a/openair1/PHY/TOOLS/lte_phy_scope.c b/openair1/PHY/TOOLS/lte_phy_scope.c
index 9f2ec54744941e783e0cb27cabeb19b93c95e4d5..000eb4861585adf34756dbbec7c8b32fc60e668c 100644
--- a/openair1/PHY/TOOLS/lte_phy_scope.c
+++ b/openair1/PHY/TOOLS/lte_phy_scope.c
@@ -178,7 +178,7 @@ void phy_scope_eNB(FD_lte_phy_scope_enb *form,
   float time[FRAME_LENGTH_COMPLEX_SAMPLES];
   float time2[2048];
   float freq[nsymb_ce*nb_antennas_rx*nb_antennas_tx];
-  int frame = phy_vars_enb->proc.proc_rxtx[0].frame_tx;
+  int frame = phy_vars_enb->proc.L1_proc.frame_tx;
   uint32_t total_dlsch_bitrate = phy_vars_enb->total_dlsch_bitrate;
   int coded_bits_per_codeword = 0;
   uint8_t harq_pid; // in TDD config 3 it is sf-2, i.e., can be 0,1,2
diff --git a/openair1/PHY/TOOLS/read_F.c b/openair1/PHY/TOOLS/read_F.c
index 32ade0dfdb698c69c1ccc0cf757c10e739787822..155b72c851e6ea0d710d507e0fbb45fcada963b5 100644
--- a/openair1/PHY/TOOLS/read_F.c
+++ b/openair1/PHY/TOOLS/read_F.c
@@ -19,6 +19,7 @@ int f_read(char *calibF_fname, int nb_antM, int nb_freq, int16_t (*calibF_mtx)[n
     }
     printf("%d\n",(int)calibF_mtx[0][0]);
     printf("%d\n",(int)calibF_mtx[1][599]);
+    fclose(calibF_fd);
   } else
    printf("%s not found, running with defaults\n",calibF_fname);
 }
diff --git a/openair1/PHY/TOOLS/smbv.c b/openair1/PHY/TOOLS/smbv.c
index e020ca0c5200573c391d2d0235a9d0bfb855b3cb..d3618725478cbec430fe0a986c704fd385773700 100644
--- a/openair1/PHY/TOOLS/smbv.c
+++ b/openair1/PHY/TOOLS/smbv.c
@@ -64,6 +64,7 @@ int smbv_init_config(const char* fname, uint16_t sequence_length)
 
   if (sequence_length>4) {
     msg("ERROR invalid sequence length: %d, maximum is 4\n", sequence_length);
+    fclose(f_ptr);
     return -1;
   } else
     slen = sequence_length;
@@ -448,13 +449,6 @@ int smbv_send_config (const char* fname, char* smbv_ip)
   int bytes_sent, status, sockfd;
   char buf[BUFFER_LENGTH];
 
-  if (fopen(fname,"r")!=NULL) {
-    msg("Configuration file: %s\n",fname);
-  } else {
-    msg("ERROR: can't open SMBV config file: %s\n",fname);
-    return -1;
-  }
-
   memset(buf,0,BUFFER_LENGTH);
 
   // first, load up address structs with getaddrinfo():
diff --git a/openair1/PHY/TOOLS/time_meas.c b/openair1/PHY/TOOLS/time_meas.c
index b37f146b0a8eb9b05f4c871f4e8562d0cc1e3afa..327efbaafae5f3386ad38d5760e91b37d12f281b 100644
--- a/openair1/PHY/TOOLS/time_meas.c
+++ b/openair1/PHY/TOOLS/time_meas.c
@@ -29,7 +29,6 @@ int opp_enabled = 0;
 
 
 double get_cpu_freq_GHz(void) {
-
   time_stats_t ts = {0};
   reset_meas(&ts);
   ts.trials++;
@@ -38,32 +37,40 @@ double get_cpu_freq_GHz(void) {
   ts.diff = (rdtsc_oai()-ts.in);
   cpu_freq_GHz = (double)ts.diff/1000000000;
   printf("CPU Freq is %f \n", cpu_freq_GHz);
-  return cpu_freq_GHz; 
+  return cpu_freq_GHz;
 }
+int cpumeas(int action) {
+  switch (action) {
+    case CPUMEAS_ENABLE:
+      opp_enabled = 1;
+      break;
+
+    case CPUMEAS_DISABLE:
+      opp_enabled = 0;
+      break;
+
+    case CPUMEAS_GETSTATE:
+    default:
+      break;
+  }
 
-void print_meas_now(time_stats_t *ts, const char* name, FILE* file_name){
-
+  return opp_enabled;
+}
+void print_meas_now(time_stats_t *ts, const char *name, FILE *file_name) {
   if (opp_enabled) {
-
     //static double cpu_freq_GHz = 3.2;
 
     //if (cpu_freq_GHz == 0.0)
-      //cpu_freq_GHz = get_cpu_freq_GHz(); // super slow
-
+    //cpu_freq_GHz = get_cpu_freq_GHz(); // super slow
     if (ts->trials>0) {
-
       //fprintf(file_name,"Name %25s: Processing %15.3f ms for SF %d, diff_now %15.3f \n", name,(ts->p_time/(cpu_freq_GHz*1000000.0)),subframe,ts->p_time);
       fprintf(file_name,"%15.3f us, diff_now %15.3f \n",(ts->p_time/(cpu_freq_GHz*1000.0)),(double)ts->p_time);
-      
     }
   }
 }
 
-void print_meas(time_stats_t *ts, const char* name, time_stats_t * total_exec_time, time_stats_t * sf_exec_time)
-{
-
+void print_meas(time_stats_t *ts, const char *name, time_stats_t *total_exec_time, time_stats_t *sf_exec_time) {
   if (opp_enabled) {
-
     static int first_time = 0;
     static double cpu_freq_GHz = 0.0;
 
@@ -81,7 +88,6 @@ void print_meas(time_stats_t *ts, const char* name, time_stats_t * total_exec_ti
 
     if (ts->trials>0) {
       //printf("%20s: total: %10.3f ms, average: %10.3f us (%10d trials)\n", name, ts->diff/cpu_freq_GHz/1000000.0, ts->diff/ts->trials/cpu_freq_GHz/1000.0, ts->trials);
-
       if ((total_exec_time == NULL) || (sf_exec_time== NULL)) {
         fprintf(stderr, "%25s:  %15.3f us; %15d;\n",
                 name,
@@ -98,12 +104,9 @@ void print_meas(time_stats_t *ts, const char* name, time_stats_t * total_exec_ti
       }
     }
   }
-
 }
 
-double get_time_meas_us(time_stats_t *ts)
-{
-
+double get_time_meas_us(time_stats_t *ts) {
   static double cpu_freq_GHz = 0.0;
 
   if (cpu_freq_GHz == 0.0)
diff --git a/openair1/PHY/TOOLS/time_meas.h b/openair1/PHY/TOOLS/time_meas.h
index eac057095a42d41ef89efc86a090715f9c09292a..797acef8e724259436248b3d6b85143c25fbc658 100644
--- a/openair1/PHY/TOOLS/time_meas.h
+++ b/openair1/PHY/TOOLS/time_meas.h
@@ -61,23 +61,21 @@ static inline void start_meas(time_stats_t *ts) __attribute__((always_inline));
 static inline void stop_meas(time_stats_t *ts) __attribute__((always_inline));
 
 
-void print_meas_now(time_stats_t *ts, const char* name, FILE* file_name);
-void print_meas(time_stats_t *ts, const char* name, time_stats_t * total_exec_time, time_stats_t * sf_exec_time);
+void print_meas_now(time_stats_t *ts, const char *name, FILE *file_name);
+void print_meas(time_stats_t *ts, const char *name, time_stats_t *total_exec_time, time_stats_t *sf_exec_time);
 double get_time_meas_us(time_stats_t *ts);
 double get_cpu_freq_GHz(void);
 
 #if defined(__i386__)
 static inline unsigned long long rdtsc_oai(void) __attribute__((always_inline));
-static inline unsigned long long rdtsc_oai(void)
-{
+static inline unsigned long long rdtsc_oai(void) {
   unsigned long long int x;
   __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
   return x;
 }
 #elif defined(__x86_64__)
 static inline unsigned long long rdtsc_oai(void) __attribute__((always_inline));
-static inline unsigned long long rdtsc_oai(void)
-{
+static inline unsigned long long rdtsc_oai(void) {
   unsigned long long a, d;
   __asm__ volatile ("rdtsc" : "=a" (a), "=d" (d));
   return (d<<32) | a;
@@ -85,61 +83,54 @@ static inline unsigned long long rdtsc_oai(void)
 
 #elif defined(__arm__)
 static inline uint32_t rdtsc_oai(void) __attribute__((always_inline));
-static inline uint32_t rdtsc_oai(void)
-{
+static inline uint32_t rdtsc_oai(void) {
   uint32_t r = 0;
   asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r"(r) );
   return r;
 }
 #endif
 
-static inline void start_meas(time_stats_t *ts)
-{
-
+#define CPUMEAS_DISABLE  0
+#define CPUMEAS_ENABLE   1
+#define CPUMEAS_GETSTATE 2
+int cpumeas(int action);
+static inline void start_meas(time_stats_t *ts) {
   if (opp_enabled) {
     if (ts->meas_flag==0) {
       ts->trials++;
       ts->in = rdtsc_oai();
       ts->meas_flag=1;
-    }
-    else {
+    } else {
       ts->in = rdtsc_oai();
     }
   }
 }
 
-static inline void stop_meas(time_stats_t *ts)
-{
-
+static inline void stop_meas(time_stats_t *ts) {
   if (opp_enabled) {
     long long out = rdtsc_oai();
-    
     ts->diff += (out-ts->in);
     /// process duration is the difference between two clock points
     ts->p_time = (out-ts->in);
     ts->diff_square += (out-ts->in)*(out-ts->in);
-    
+
     if ((out-ts->in) > ts->max)
       ts->max = out-ts->in;
 
-    ts->meas_flag=0;    
+    ts->meas_flag=0;
   }
 }
 
 static inline void reset_meas(time_stats_t *ts) {
-
   ts->trials=0;
   ts->diff=0;
   ts->p_time=0;
   ts->diff_square=0;
   ts->max=0;
   ts->meas_flag=0;
-  
 }
 
-static inline void copy_meas(time_stats_t *dst_ts,time_stats_t *src_ts)
-{
-
+static inline void copy_meas(time_stats_t *dst_ts,time_stats_t *src_ts) {
   if (opp_enabled) {
     dst_ts->trials=src_ts->trials;
     dst_ts->diff=src_ts->diff;
diff --git a/openair1/PHY/defs_L1_NB_IoT.h b/openair1/PHY/defs_L1_NB_IoT.h
index 8a7c853df55d10fbd148d94077683eabfd873a39..0a34d9f12bb9420b285b1adb387a6d3b73ac77c7 100644
--- a/openair1/PHY/defs_L1_NB_IoT.h
+++ b/openair1/PHY/defs_L1_NB_IoT.h
@@ -425,7 +425,7 @@ typedef struct eNB_proc_NB_IoT_t_s {
   int RU_mask;
   /// mask for RUs serving nbiot (PRACH)
   int RU_mask_prach;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   /// mask for RUs serving eNB (PRACH)
   int RU_mask_prach_br;
 #endif
diff --git a/openair1/PHY/defs_UE.h b/openair1/PHY/defs_UE.h
index 55f8c9639ab281316a25784b62f45811c69d9203..5beb6e3ba0e524cfa39d232110b66bfa48ce26da 100644
--- a/openair1/PHY/defs_UE.h
+++ b/openair1/PHY/defs_UE.h
@@ -204,6 +204,12 @@ typedef struct {
 	/// condition variable for timer_thread;
 	pthread_cond_t cond_ticking;
 	//time_stats_t timer_stats;
+
+	// below 3 members is used for waiting each UE threads(multiple UEs test) in L2 FAPI simulator.
+	// This used in UE_phy_stub_single_thread_rxn_txnp4
+	pthread_mutex_t mutex_single_thread;
+	pthread_cond_t  cond_single_thread;
+	int             num_single_thread[NUMBER_OF_UE_MAX];
 } SF_ticking;
 
 typedef struct {
@@ -847,6 +853,7 @@ typedef struct {
   time_stats_t pdsch_procedures_stat[RX_NB_TH];
   time_stats_t pdsch_procedures_per_slot_stat[RX_NB_TH][LTE_SLOTS_PER_SUBFRAME];
   time_stats_t dlsch_procedures_stat[RX_NB_TH];
+  time_stats_t crnti_procedures_stats;
 
   time_stats_t ofdm_demod_stats;
   time_stats_t dlsch_rx_pdcch_stats;
@@ -889,6 +896,7 @@ typedef struct {
 struct rx_tx_thread_data {
   PHY_VARS_UE    *UE;
   UE_rxtx_proc_t *proc;
+  uint16_t       ue_thread_id;
 };
 
 
diff --git a/openair1/PHY/defs_common.h b/openair1/PHY/defs_common.h
index 9a735b038fedd588a06afe665824d02f68d47da0..64ca5afbb63f0c3ef62fe87f4368281c837c5b64 100644
--- a/openair1/PHY/defs_common.h
+++ b/openair1/PHY/defs_common.h
@@ -58,6 +58,7 @@
 #include <math.h>
 #include "common_lib.h"
 #include "msc.h"
+#include <common/utils/LOG/log.h>
 
 
 //#include <complex.h>
@@ -159,7 +160,7 @@ typedef struct {
   PRACH_CONFIG_INFO prach_ConfigInfo;
 } PRACH_CONFIG_COMMON;
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 
 /// PRACH-eMTC-Config from 36.331 RRC spec
 typedef struct {
@@ -192,7 +193,7 @@ typedef struct {
   /// prach_Config_enabled=1 means enabled. \vr{[0..1]}
   uint8_t prach_Config_enabled;
   /// PRACH Configuration Information
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   PRACH_eMTC_CONFIG_INFO prach_ConfigInfo;
 #endif  
 } PRACH_eMTC_CONFIG_COMMON;
@@ -644,7 +645,7 @@ typedef struct {
   uint8_t nb_antenna_ports_eNB;
   /// PRACH_CONFIG
   PRACH_CONFIG_COMMON prach_config_common;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   /// PRACH_eMTC_CONFIG
   PRACH_eMTC_CONFIG_COMMON prach_emtc_config_common;
 #endif
@@ -807,6 +808,8 @@ typedef struct {
   uint8_t harq_pid;
   /// Narrowband index
   uint8_t narrowband;
+  /// number of mdpcch repetitions
+  uint16_t reps;
   /// number of PRB pairs for MPDCCH
   uint8_t number_of_prb_pairs;
   /// mpdcch resource assignment (combinatorial index r)
@@ -821,8 +824,6 @@ typedef struct {
   uint16_t dmrs_scrambling_init;
   /// Absolute subframe of the initial transmission (0-10239)
   uint16_t i0;
-  /// number of mdpcch repetitions
-  uint16_t reps;
   /// current absolute subframe number
   uint16_t absSF;
   /// DCI pdu
@@ -862,22 +863,60 @@ typedef enum {
   RESYNCH=4
 } UE_MODE_t;
 
-/// Threading Parameter
+#define FOREACH_PARALLEL(GEN)			\
+  GEN(PARALLEL_SINGLE_THREAD)			\
+  GEN(PARALLEL_RU_L1_SPLIT)			\
+  GEN(PARALLEL_RU_L1_TRX_SPLIT)
+
+#define GENERATE_ENUM(N) N,
+#define GENERATE_ENUMTXT(N) {(char*)#N, N},
+
 typedef enum {
-  PARALLEL_SINGLE_THREAD    =0,
-  PARALLEL_RU_L1_SPLIT      =1,
-  PARALLEL_RU_L1_TRX_SPLIT  =2
-}PARALLEL_CONF_t;
+  FOREACH_PARALLEL(GENERATE_ENUM)
+} PARALLEL_CONF_t;
 
+#define FOREACH_WORKER(GEN) GEN(WORKER_DISABLE) GEN(WORKER_ENABLE)
 typedef enum {
-  WORKER_DISABLE            =0,
-  WORKER_ENABLE             =1
+  FOREACH_WORKER(GENERATE_ENUM)
 }WORKER_CONF_t;
 
 typedef struct THREAD_STRUCT_s {
   PARALLEL_CONF_t  parallel_conf;
   WORKER_CONF_t    worker_conf;
 } THREAD_STRUCT;
+extern THREAD_STRUCT  thread_struct;
+
+static inline void set_parallel_conf(char *parallel_conf) {
+  mapping config[]= {
+    FOREACH_PARALLEL(GENERATE_ENUMTXT)
+    {NULL,-1}
+  };
+  thread_struct.parallel_conf = (PARALLEL_CONF_t)map_str_to_int(config, parallel_conf);
+  if (thread_struct.parallel_conf == -1 ) {
+    LOG_E(ENB_APP,"Impossible value: %s\n", parallel_conf);
+    thread_struct.parallel_conf = PARALLEL_SINGLE_THREAD;
+  }
+}
+
+static inline void set_worker_conf(char *worker_conf) {
+  mapping config[]={
+    FOREACH_WORKER(GENERATE_ENUMTXT)
+    {NULL, -1}
+  };
+  thread_struct.worker_conf =  (WORKER_CONF_t)map_str_to_int(config, worker_conf);
+  if (thread_struct.worker_conf == -1 ) {
+    LOG_E(ENB_APP,"Impossible value: %s\n", worker_conf);
+    thread_struct.worker_conf = WORKER_DISABLE ;
+  }
+}
+
+static inline PARALLEL_CONF_t get_thread_parallel_conf(void) {
+  return thread_struct.parallel_conf;
+}
+
+static inline WORKER_CONF_t get_thread_worker_conf(void) {
+  return thread_struct.worker_conf;
+}
 
 typedef enum {SF_DL, SF_UL, SF_S} lte_subframe_t;
 
diff --git a/openair1/PHY/defs_eNB.h b/openair1/PHY/defs_eNB.h
index f23485cad84e732ec2459da1ec7c005052b6b74e..4de830507504591dcf11cdad49d1ffde86272286 100644
--- a/openair1/PHY/defs_eNB.h
+++ b/openair1/PHY/defs_eNB.h
@@ -85,7 +85,7 @@ typedef struct RU_proc_t_s {
   int subframe_tx;
   /// subframe to act upon for reception of prach
   int subframe_prach;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   /// subframe to act upon for reception of prach BL/CE UEs
   int subframe_prach_br;
 #endif
@@ -97,7 +97,7 @@ typedef struct RU_proc_t_s {
   int frame_tx_unwrap;
   /// frame to act upon for reception of prach
   int frame_prach;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   /// frame to act upon for reception of prach
   int frame_prach_br;
 #endif
@@ -109,7 +109,7 @@ typedef struct RU_proc_t_s {
   int instance_cnt_FH1;
   /// \internal This variable is protected by \ref mutex_prach.
   int instance_cnt_prach;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   /// \internal This variable is protected by \ref mutex_prach.
   int instance_cnt_prach_br;
 #endif
@@ -131,7 +131,7 @@ typedef struct RU_proc_t_s {
   pthread_t pthread_FH1;
   /// pthread structure for RU prach processing thread
   pthread_t pthread_prach;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   /// pthread structure for RU prach processing thread BL/CE UEs
   pthread_t pthread_prach_br;
 #endif
@@ -154,7 +154,7 @@ typedef struct RU_proc_t_s {
   pthread_attr_t attr_FH1;
   /// pthread attributes for RU prach
   pthread_attr_t attr_prach;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   /// pthread attributes for RU prach BL/CE UEs
   pthread_attr_t attr_prach_br;
 #endif
@@ -173,7 +173,7 @@ typedef struct RU_proc_t_s {
   struct sched_param sched_param_FH1;
   /// scheduling parameters for RU prach thread
   struct sched_param sched_param_prach;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   /// scheduling parameters for RU prach thread BL/CE UEs
   struct sched_param sched_param_prach_br;
 #endif
@@ -186,7 +186,7 @@ typedef struct RU_proc_t_s {
   pthread_cond_t cond_FH1;
   /// condition variable for RU prach thread
   pthread_cond_t cond_prach;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   /// condition variable for RU prach thread BL/CE UEs
   pthread_cond_t cond_prach_br;
 #endif
@@ -207,7 +207,7 @@ typedef struct RU_proc_t_s {
   pthread_mutex_t mutex_FH1;
   /// mutex for RU prach
   pthread_mutex_t mutex_prach;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   /// mutex for RU prach BL/CE UEs
   pthread_mutex_t mutex_prach_br;
 #endif
@@ -257,9 +257,6 @@ typedef struct RU_proc_t_s {
   pthread_mutex_t mutex_pre_scd;
   int instance_pre_scd;
 #endif
-  /// pipeline ready state
-  int ru_rx_ready;
-  int ru_tx_ready;
   int emulate_rf_busy;
 } RU_proc_t;
 
@@ -359,7 +356,7 @@ typedef struct RU_t_s{
   int (*wakeup_rxtx)(struct PHY_VARS_eNB_s *eNB, struct RU_t_s *ru);
   /// function pointer to wakeup routine in lte-enb.
   void (*wakeup_prach_eNB)(struct PHY_VARS_eNB_s *eNB,struct RU_t_s *ru,int frame,int subframe);
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   /// function pointer to wakeup routine in lte-enb.
   void (*wakeup_prach_eNB_br)(struct PHY_VARS_eNB_s *eNB,struct RU_t_s *ru,int frame,int subframe);
 #endif
@@ -484,7 +481,7 @@ typedef struct RRU_config_s {
   int prach_FreqOffset[MAX_BANDS_PER_RRU];
   /// prach_ConfigIndex for IF4p5
   int prach_ConfigIndex[MAX_BANDS_PER_RRU];
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   int emtc_prach_CElevel_enable[MAX_BANDS_PER_RRU][4];
   /// emtc_prach_FreqOffset for IF4p5 per CE Level
   int emtc_prach_FreqOffset[MAX_BANDS_PER_RRU][4];
@@ -619,7 +616,7 @@ typedef struct {
   int32_t **prach_ifft[4];
 
   /// repetition number
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   /// indicator of first frame in a group of PRACH repetitions
   int first_frame[4];
   /// current repetition for each CE level
@@ -648,20 +645,25 @@ typedef struct {
   int frame_rx;
   /// \brief Instance count for RXn-TXnp4 processing thread.
   /// \internal This variable is protected by \ref mutex_rxtx.
-  int instance_cnt_rxtx;
+  int instance_cnt;
   /// pthread structure for RXn-TXnp4 processing thread
-  pthread_t pthread_rxtx;
+  pthread_t pthread;
   /// pthread attributes for RXn-TXnp4 processing thread
-  pthread_attr_t attr_rxtx;
+  pthread_attr_t attr;
   /// condition variable for tx processing thread
-  pthread_cond_t cond_rxtx;
+  pthread_cond_t cond;
   /// mutex for RXn-TXnp4 processing thread
-  pthread_mutex_t mutex_rxtx;
+  pthread_mutex_t mutex;
   /// scheduling parameters for RXn-TXnp4 thread
   struct sched_param sched_param_rxtx;
-  /// pipeline ready state
-  int pipe_ready;
-} eNB_rxtx_proc_t;
+
+  /// \internal This variable is protected by \ref mutex_RUs.
+  int instance_cnt_RUs;
+  /// condition variable for tx processing thread
+  pthread_cond_t cond_RUs;
+  /// mutex for RXn-TXnp4 processing thread
+  pthread_mutex_t mutex_RUs;
+} L1_rxtx_proc_t;
 
 typedef struct {
   struct PHY_VARS_eNB_s *eNB;
@@ -693,7 +695,7 @@ typedef struct {
 } te_params;
 
 /// Context data structure for eNB subframe processing
-typedef struct eNB_proc_t_s {
+typedef struct L1_proc_t_s {
   /// Component Carrier index
   uint8_t              CC_id;
   /// thread index
@@ -706,7 +708,7 @@ typedef struct eNB_proc_t_s {
   int subframe_rx;
   /// subframe to act upon for PRACH
   int subframe_prach;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   /// subframe to act upon for reception of prach BL/CE UEs
   int subframe_prach_br;
 #endif
@@ -716,7 +718,7 @@ typedef struct eNB_proc_t_s {
   int frame_tx;
   /// frame to act upon for PRACH
   int frame_prach;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   /// frame to act upon for PRACH BL/CE UEs
   int frame_prach_br;
 #endif
@@ -726,7 +728,7 @@ typedef struct eNB_proc_t_s {
   int instance_cnt_te;
   /// \internal This variable is protected by \ref mutex_prach.
   int instance_cnt_prach;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   /// \internal This variable is protected by \ref mutex_prach for BL/CE UEs.
   int instance_cnt_prach_br;
 #endif
@@ -748,7 +750,7 @@ typedef struct eNB_proc_t_s {
   pthread_attr_t attr_single;
   /// pthread attributes for prach processing thread
   pthread_attr_t attr_prach;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   /// pthread attributes for prach processing thread BL/CE UEs
   pthread_attr_t attr_prach_br;
 #endif
@@ -762,7 +764,7 @@ typedef struct eNB_proc_t_s {
   struct sched_param sched_param_single;
   /// scheduling parameters for prach thread
   struct sched_param sched_param_prach;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   /// scheduling parameters for prach thread
   struct sched_param sched_param_prach_br;
 #endif
@@ -774,7 +776,7 @@ typedef struct eNB_proc_t_s {
   pthread_t pthread_te;
   /// pthread structure for PRACH thread
   pthread_t pthread_prach;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   /// pthread structure for PRACH thread BL/CE UEs
   pthread_t pthread_prach_br;
 #endif
@@ -784,7 +786,7 @@ typedef struct eNB_proc_t_s {
   pthread_cond_t cond_te;
   /// condition variable for PRACH processing thread;
   pthread_cond_t cond_prach;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   /// condition variable for PRACH processing thread BL/CE UEs;
   pthread_cond_t cond_prach_br;
 #endif
@@ -796,7 +798,7 @@ typedef struct eNB_proc_t_s {
   pthread_mutex_t mutex_te;
   /// mutex for PRACH thread
   pthread_mutex_t mutex_prach;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   /// mutex for PRACH thread for BL/CE UEs
   pthread_mutex_t mutex_prach_br;
 #endif
@@ -804,15 +806,19 @@ typedef struct eNB_proc_t_s {
   pthread_mutex_t mutex_asynch_rxtx;
   /// mutex for RU access to eNB processing (PDSCH/PUSCH)
   pthread_mutex_t mutex_RU;
+  /// mutex for eNB processing to access RU TX (PDSCH/PUSCH)
+  pthread_mutex_t mutex_RU_tx;
   /// mutex for RU access to eNB processing (PRACH)
   pthread_mutex_t mutex_RU_PRACH;
   /// mutex for RU access to eNB processing (PRACH BR)
   pthread_mutex_t mutex_RU_PRACH_br;
   /// mask for RUs serving eNB (PDSCH/PUSCH)
   int RU_mask;
+  /// mask for RUs serving eNB (PDSCH/PUSCH)
+  int RU_mask_tx;
   /// mask for RUs serving eNB (PRACH)
   int RU_mask_prach;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   /// mask for RUs serving eNB (PRACH)
   int RU_mask_prach_br;
 #endif
@@ -821,12 +827,10 @@ typedef struct eNB_proc_t_s {
   /// parameters for turbo-encoding worker thread
   te_params tep[3];
   /// set of scheduling variables RXn-TXnp4 threads
-  eNB_rxtx_proc_t proc_rxtx[2];
+  L1_rxtx_proc_t L1_proc,L1_proc_tx;
   /// stats thread pthread descriptor
   pthread_t process_stats_thread;
-  /// for waking up tx procedure
-  RU_proc_t *ru_proc;
-} eNB_proc_t;
+} L1_proc_t;
 
 
 
@@ -894,7 +898,7 @@ typedef struct PHY_VARS_eNB_s {
   module_id_t          Mod_id;
   uint8_t              CC_id;
   uint8_t              configured;
-  eNB_proc_t           proc;
+  L1_proc_t            proc;
   int                  single_thread_flag;
   int                  abstraction_flag;
   int                  num_RU;
@@ -904,8 +908,6 @@ typedef struct PHY_VARS_eNB_s {
   /// Ethernet parameters for fronthaul interface
   eth_params_t         eth_params;
   int                  rx_total_gain_dB;
-  int                  (*td)(struct PHY_VARS_eNB_s *eNB,int UE_id,int harq_pid,int llr8_flag);
-  int                  (*te)(struct PHY_VARS_eNB_s *,uint8_t *,uint8_t,LTE_eNB_DLSCH_t *,int,uint8_t,time_stats_t *,time_stats_t *,time_stats_t *,time_stats_t *,time_stats_t *,time_stats_t *,time_stats_t *);
   int                  (*start_if)(struct RU_t_s *ru,struct PHY_VARS_eNB_s *eNB);
   uint8_t              local_flag;
   LTE_DL_FRAME_PARMS   frame_parms;
@@ -927,14 +929,14 @@ typedef struct PHY_VARS_eNB_s {
   nfapi_cqi_indication_raw_pdu_t cqi_raw_pdu_list[NFAPI_CQI_IND_MAX_PDU];
   /// NFAPI PRACH information
   nfapi_preamble_pdu_t preamble_list[MAX_NUM_RX_PRACH_PREAMBLES];
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   /// NFAPI PRACH information BL/CE UEs
   nfapi_preamble_pdu_t preamble_list_br[MAX_NUM_RX_PRACH_PREAMBLES];
 #endif
   Sched_Rsp_t          Sched_INFO;
   LTE_eNB_PDCCH        pdcch_vars[2];
   LTE_eNB_PHICH        phich_vars[2];
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   LTE_eNB_EPDCCH       epdcch_vars[2];
   LTE_eNB_MPDCCH       mpdcch_vars[2];
   LTE_eNB_PRACH        prach_vars_br;
@@ -966,7 +968,7 @@ typedef struct PHY_VARS_eNB_s {
   uint32_t         lte_gold_mbsfn_table[10][3][42];
 
   uint32_t X_u[64][839];
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   uint32_t X_u_br[4][64][839];
 #endif
   uint8_t pbch_configured;
@@ -1037,7 +1039,7 @@ typedef struct PHY_VARS_eNB_s {
   uint8_t cba_last_reception[4];
 
   // Pointers for active physicalConfigDedicated to be applied in current subframe
-  struct PhysicalConfigDedicated *physicalConfigDedicated[NUMBER_OF_UE_MAX];
+  struct LTE_PhysicalConfigDedicated *physicalConfigDedicated[NUMBER_OF_UE_MAX];
 
 
   uint32_t rb_mask_ul[4];
@@ -1074,12 +1076,13 @@ typedef struct PHY_VARS_eNB_s {
 
   int hw_timing_advance;
 
-  time_stats_t phy_proc;
   time_stats_t phy_proc_tx;
   time_stats_t phy_proc_rx;
   time_stats_t rx_prach;
 
   time_stats_t ofdm_mod_stats;
+  time_stats_t dlsch_common_and_dci;
+  time_stats_t dlsch_ue_specific;
   time_stats_t dlsch_encoding_stats;
   time_stats_t dlsch_modulation_stats;
   time_stats_t dlsch_scrambling_stats;
diff --git a/openair1/PHY/impl_defs_lte.h b/openair1/PHY/impl_defs_lte.h
index d649dce100482c0fc70012c6b4cc64f51e8e8487..df242aab8425bff5103e7772dcf8eceb5799129d 100644
--- a/openair1/PHY/impl_defs_lte.h
+++ b/openair1/PHY/impl_defs_lte.h
@@ -68,4 +68,5 @@ typedef struct {
   int32_t **tdd_calib_coeffs;
 } RU_COMMON;
 
+
 #endif
diff --git a/openair1/PHY/phy_vars_ue.h b/openair1/PHY/phy_vars_ue.h
index 0d29b03f63d0970103d1ed18d376ec5a712e9793..33f93fc78d7cbadef6540ca314278e51ab3f74f8 100644
--- a/openair1/PHY/phy_vars_ue.h
+++ b/openair1/PHY/phy_vars_ue.h
@@ -28,9 +28,9 @@
 
 #include "common/ran_context.h"
 
-char* namepointer_chMag ;
+char *namepointer_chMag ;
 char fmageren_name2[512];
-char* namepointer_log2;
+char *namepointer_log2;
 
 
 #include "PHY/LTE_REFSIG/primary_synch.h"
@@ -45,7 +45,7 @@ int16_t *primary_synch2_time;
 PHY_VARS_UE ***PHY_vars_UE_g;
 LTE_DL_FRAME_PARMS *lte_frame_parms_g;
 #else
-PHY_VARS_UE * PHY_vars_UE_g[MAX_UE][MAX_NUM_CCs]={NULL};
+PHY_VARS_UE *PHY_vars_UE_g[MAX_UE][MAX_NUM_CCs]= {NULL};
 
 #endif
 
@@ -62,10 +62,10 @@ char mode_string[4][20] = {"NOT SYNCHED","PRACH","RAR","PUSCH"};
 
 
 #ifndef OPENAIR2
-unsigned char NB_eNB_INST=0;
-unsigned char NB_UE_INST=0;
-unsigned char NB_RN_INST=0;
-unsigned char NB_INST=0;
+  unsigned char NB_eNB_INST=0;
+  unsigned char NB_UE_INST=0;
+  unsigned char NB_RN_INST=0;
+  unsigned char NB_INST=0;
 #endif
 
 unsigned int ULSCH_max_consecutive_errors = 20;
@@ -134,9 +134,9 @@ double beta2_dlsch[6][MCS_COUNT] = { {2.52163, 0.83231, 0.77472, 1.36536, 1.1682
 #ifdef OCP_FRAMEWORK
 #include <enums.h>
 #else
-char eNB_functions[6][20]={"eNodeB_3GPP","eNodeB_3GPP_BBU","NGFI_RAU_IF4p5","NGFI_RRU_IF5","NGFI_RRU_IF4p5",};
-char eNB_timing[2][20]={"synch_to_ext_device","synch_to_other"};
-char ru_if_types[MAX_RU_IF_TYPES][20]={"local RF","IF5 RRU","IF5 Mobipass","IF4p5 RRU","IF1pp RRU"};
+char eNB_functions[6][20]= {"eNodeB_3GPP","eNodeB_3GPP_BBU","NGFI_RAU_IF4p5","NGFI_RRU_IF5","NGFI_RRU_IF4p5",};
+char eNB_timing[2][20]= {"synch_to_ext_device","synch_to_other"};
+char ru_if_types[MAX_RU_IF_TYPES][20]= {"local RF","IF5 RRU","IF5 Mobipass","IF4p5 RRU","IF1pp RRU"};
 #endif
 
 /// lookup table for unscrambling in RX
diff --git a/openair1/README.TXT b/openair1/README.TXT
index 23c86e888e47f697adb8d1509630d5958e5be693..98ec8984c425a3683070f42b91f3166f70feacad 100644
--- a/openair1/README.TXT
+++ b/openair1/README.TXT
@@ -1,15 +1,20 @@
-This folder contains the software for the device driver of CBMIMO1 and the physical layer signal processing.
+This folder contains the software for layer 1 of the OpenAirInterface eNB and UE as well as the unitary simulators
 
 |-- PHY			   // contains all signal processing related to physical layer (used in real-time AND simulation)
 
-General remarks: every directory contains at least defs.h (for declaration of structure and functions), vars.h (for definitions of variables), and extern.h (variables are defined only once in cbmimo1_device.c (for real-time HW operation) or a top-level simulation (in SIMULATION/xxx), if variables are needed in another file, use extern.h)
+General remarks: every directory contains at least defs.h (for declaration of structure and functions), vars.h (for definitions of variables), and extern.h (variables are defined only once in xxx-softmodem.c (for real-time HW operation) or a top-level simulation (in SIMULATION/xxx), if variables are needed in another file, use extern.h)
 
 |   |-- CODING		   // turbo and convolutional (de-)coders, rate-matching, crc generation (implementation of 36-212)
 |   |   `-- TESTBENCH      // This contains unitary testbenches for the different channel coders/decoders
 |   |-- INIT		   // variables defined in vars.h are initialzed here (memory allocation)
 |   |-- LTE_ESTIMATION     // estimation for LTE
 |   |-- LTE_REFSIG 	   // reference signals for LTE (sync and pilot sequences) reference signals from 36-211 
+|   |-- NR_REFSIG 	   // reference signals for NR (sync and pilot sequences) reference signals from 38-211
 |   |-- LTE_TRANSPORT      // these are the top level routines for different transport and physical channels (for example DL-SCH, PSS) implements a subset of 36-211,36-212
+|   |-- LTE_UE_TRANSPORT      // these are the top level routines for different transport and physical channels (for example DL-SCH, PSS) implements a subset of 36-211,36-212
+|   |-- NR_TRANSPORT      // these are the top level routines for different transport and physical channels (for example DL-SCH, PSS) implements a subset of 38-211,38-212
+|   |-- NR_UE_TRANSPORT      // these are the top level routines for different transport and physical channels (for example DL-SCH, PSS) implements a subset of 38-211,38-212
+|   |-- NBIoT_TRANSPORT      // these are the top level routines for different transport and physical channels for NB-IoT
 |   |-- MODULATION	   // modulation and demodulation includes FFT/SC-FDMA front-end processing from 36-211
 |   |-- TOOLS		   // tools like (I)FFT, vector operations, matrix multiplication, etc.
 |   |   `-- FFTTEST        // unitary testbench for FFT routines
@@ -22,20 +27,25 @@ General remarks: every directory contains at least defs.h (for declaration of st
 |   |-- spec_defs_top.h
 |   |-- types.h
 |   `-- vars.h		  
-|-- SCHED		  // schedules the different PHY functions according to the nodes role 
+|-- SCHED		  // schedules the different LTE eNB functions
 |   |-- defs.h
 |   |-- extern.h
-|   |-- phy_procedures_emos.c    // non-LTE PHY procedures for EMOS
-|   |-- phy_procedures_emos.h
 |   |-- phy_procedures_lte_eNb.c // LTE PHY procedures for eNB (from 36-213) 
-|   |-- phy_procedures_lte_ue.c  // LTE PHY procedures for UE (from 36-213)
 |   |-- phy_procedures_lte_common.c  // LTE PHY procedures common for UE and eNB (from 36-213)
+|   |-- prach_procedures.c  //LTE PRACH  procedures (from 36-213)
+|   |-- ru_procedures.c  //RU  procedures
+|   |-- fapi_l1.c  //L1 side of the FAPI interface
 |   |-- phy_mac_stub.c  //MAC stub that generates channels when used in phy-test-mode
+|   |-- rt_compat.h
+|   `-- vars.h
+|-- SCHED_UE		  // schedules the different LTE UE functions
+|   |-- phy_procedures_lte_ue.c  // LTE PHY procedures for UE (from 36-213)
 |   |-- pucch_pc.c // power control for PUCCH
 |   |-- pusch_pc.c // power control for PUSCH
 |   |-- srs_pc.c // power control for SRS
-|   |-- rt_compat.h
-|   `-- vars.h
+|-- SCHED_NB_IOT		  // same as above for NB-IOT
+|-- SCHED_NR		  // same as above for NR gNB
+|-- SCHED_NR_UE		  // same as above for NR UE
 |-- SIMULATION		 // contains simulation routines to test PHY
 |   |-- LTE_PHY          // LTE simulation testbenches for unitary simulation of transport/physical channels
 |   |   |-- pbchsim.c       // PBCH simulation testbench
@@ -43,7 +53,7 @@ General remarks: every directory contains at least defs.h (for declaration of st
 |   |   |-- dlsim.c         // PDSCH simulation testbench
 |   |   |-- ulsim.c         // PUSCH simulation testbench
 |   |   |-- pucchsim.c      // PUCCH simulation testbench
-|   |-- RF
+|   |-- RF  		    // RF simulation tools
 |   |-- ETH_TRANSPORT
 |   `-- TOOLS
 
diff --git a/openair1/SCHED/Makefile.inc b/openair1/SCHED/Makefile.inc
deleted file mode 100644
index 559d3dca32b2db60e50caa0f8fc349edf9499e1e..0000000000000000000000000000000000000000
--- a/openair1/SCHED/Makefile.inc
+++ /dev/null
@@ -1,6 +0,0 @@
-SCHED_OBJS = $(TOP_DIR)/SCHED/phy_procedures_lte_common.o
-SCHED_OBJS += $(TOP_DIR)/SCHED/phy_procedures_lte_ue.o
-SCHED_OBJS += $(TOP_DIR)/SCHED/phy_procedures_lte_eNb.o
-SCHED_OBJS += $(TOP_DIR)/SCHED/pusch_pc.o
-SCHED_OBJS += $(TOP_DIR)/SCHED/pucch_pc.o
-SCHED_OBJS += $(TOP_DIR)/SCHED/srs_pc.o
diff --git a/openair1/SCHED/fapi_l1.c b/openair1/SCHED/fapi_l1.c
index ad72c3d9f5f6a2cf8a17933135b63a0399b62985..7d9a1c83205eab582afe06e110c4f70ad44dcff7 100644
--- a/openair1/SCHED/fapi_l1.c
+++ b/openair1/SCHED/fapi_l1.c
@@ -48,13 +48,15 @@ extern uint8_t nfapi_mode;
 
 void handle_nfapi_dci_dl_pdu(PHY_VARS_eNB *eNB,
                              int frame, int subframe,
-                             eNB_rxtx_proc_t *proc,
+                             L1_rxtx_proc_t *proc,
                              nfapi_dl_config_request_pdu_t *dl_config_pdu)
 {
   int idx                         = subframe&1;
   LTE_eNB_PDCCH *pdcch_vars       = &eNB->pdcch_vars[idx];
   nfapi_dl_config_dci_dl_pdu *pdu = &dl_config_pdu->dci_dl_pdu;
 
+  if (nfapi_mode==2) return;
+
   LOG_D(PHY,"Frame %d, Subframe %d: DCI processing - populating pdcch_vars->dci_alloc[%d] proc:subframe_tx:%d idx:%d pdcch_vars->num_dci:%d\n",frame,subframe, pdcch_vars->num_dci, proc->subframe_tx, idx, pdcch_vars->num_dci);
 
   // copy dci configuration into eNB structure
@@ -63,16 +65,18 @@ void handle_nfapi_dci_dl_pdu(PHY_VARS_eNB *eNB,
   LOG_D(PHY,"Frame %d, Subframe %d: DCI processing - populated pdcch_vars->dci_alloc[%d] proc:subframe_tx:%d idx:%d pdcch_vars->num_dci:%d\n",proc->frame_tx,proc->subframe_tx, pdcch_vars->num_dci, proc->subframe_tx, idx, pdcch_vars->num_dci);
 }
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 
 void handle_nfapi_mpdcch_pdu(PHY_VARS_eNB *eNB,
-                             eNB_rxtx_proc_t *proc,
+                             L1_rxtx_proc_t *proc,
                              nfapi_dl_config_request_pdu_t *dl_config_pdu)
 {
   int idx                         = proc->subframe_tx&1;
   LTE_eNB_MPDCCH *mpdcch_vars     = &eNB->mpdcch_vars[idx];
   nfapi_dl_config_mpdcch_pdu *pdu = &dl_config_pdu->mpdcch_pdu;
 
+  if (nfapi_mode==2) return;
+
   LOG_D(PHY,"Frame %d, Subframe %d: MDCI processing\n",proc->frame_tx,proc->subframe_tx);
 
   // copy dci configuration into eNB structure
@@ -81,23 +85,41 @@ void handle_nfapi_mpdcch_pdu(PHY_VARS_eNB *eNB,
 
 #endif
 
-void handle_nfapi_hi_dci0_dci_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t *proc,
+void handle_nfapi_hi_dci0_dci_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,L1_rxtx_proc_t *proc,
                                   nfapi_hi_dci0_request_pdu_t *hi_dci0_config_pdu)
 {
   int idx                         = subframe&1;
   LTE_eNB_PDCCH *pdcch_vars       = &eNB->pdcch_vars[idx];
 
+  if (nfapi_mode==2) return;
+
   //LOG_D(PHY,"%s() SFN/SF:%04d%d Before num_dci:%d\n", __FUNCTION__,frame,subframe,pdcch_vars->num_dci);
 
   // copy dci configuration in to eNB structure
   fill_dci0(eNB,frame,subframe,proc,&pdcch_vars->dci_alloc[pdcch_vars->num_dci], &hi_dci0_config_pdu->dci_pdu);
 }
 
-void handle_nfapi_hi_dci0_hi_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t *proc,
+
+
+void handle_nfapi_hi_dci0_mpdcch_dci_pdu(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc,
+					 nfapi_hi_dci0_request_pdu_t *hi_dci0_config_pdu)
+{
+  int idx                         = proc->subframe_tx&1;
+  LTE_eNB_MPDCCH *pdcch_vars      = &eNB->mpdcch_vars[idx];
+  if (nfapi_mode==2) return;
+
+  // copy dci configuration in to eNB structure
+  fill_mpdcch_dci0(eNB,proc,&pdcch_vars->mdci_alloc[pdcch_vars->num_dci], &hi_dci0_config_pdu->mpdcch_dci_pdu);
+}
+
+
+void handle_nfapi_hi_dci0_hi_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,L1_rxtx_proc_t *proc,
                                  nfapi_hi_dci0_request_pdu_t *hi_dci0_config_pdu)
 {
   LTE_eNB_PHICH *phich = &eNB->phich_vars[subframe&1];
 
+  if (nfapi_mode==2) return;
+
   // copy dci configuration in to eNB structure
   LOG_D(PHY,"Received HI PDU with value %d (rbstart %d,cshift %d)\n",
         hi_dci0_config_pdu->hi_pdu.hi_pdu_rel8.hi_value,
@@ -112,12 +134,14 @@ void handle_nfapi_hi_dci0_hi_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rx
   AssertFatal(phich->num_hi<32,"Maximum number of phich reached in subframe\n");
 }
 
-void handle_nfapi_bch_pdu(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
+void handle_nfapi_bch_pdu(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc,
                           nfapi_dl_config_request_pdu_t *dl_config_pdu,
                           uint8_t *sdu)
 {
   nfapi_dl_config_bch_pdu_rel8_t *rel8 = &dl_config_pdu->bch_pdu.bch_pdu_rel8;
 
+  if (nfapi_mode==2) return;
+
   AssertFatal(rel8->length == 3, "BCH PDU has length %d != 3\n",rel8->length);
 
   //LOG_D(PHY,"bch_pdu: %x,%x,%x\n",sdu[0],sdu[1],sdu[2]);
@@ -128,7 +152,7 @@ void handle_nfapi_bch_pdu(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
   // adjust transmit amplitude here based on NFAPI info
 }
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 extern uint32_t localRIV2alloc_LUT6[32];
 extern uint32_t localRIV2alloc_LUT25[512];
 extern uint32_t localRIV2alloc_LUT50_0[1600];
@@ -139,16 +163,16 @@ extern uint32_t localRIV2alloc_LUT100_2[6000];
 extern uint32_t localRIV2alloc_LUT100_3[6000];
 #endif
 
-void handle_nfapi_dlsch_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t *proc,
+void handle_nfapi_dlsch_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,L1_rxtx_proc_t *proc,
                             nfapi_dl_config_request_pdu_t *dl_config_pdu,
                             uint8_t codeword_index,
                             uint8_t *sdu)
 {
   nfapi_dl_config_dlsch_pdu_rel8_t *rel8 = &dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8;
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
   nfapi_dl_config_dlsch_pdu_rel10_t *rel10 = &dl_config_pdu->dlsch_pdu.dlsch_pdu_rel10;
 #endif
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   nfapi_dl_config_dlsch_pdu_rel13_t *rel13 = &dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13;
 #endif
   LTE_eNB_DLSCH_t *dlsch0=NULL,*dlsch1=NULL;
@@ -156,6 +180,8 @@ void handle_nfapi_dlsch_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_pr
   int UE_id;
   int harq_pid;
 
+  if (nfapi_mode==2) return;
+
   UE_id = find_dlsch(rel8->rnti,eNB,SEARCH_EXIST_OR_FREE);
   if( (UE_id<0) || (UE_id>=NUMBER_OF_UE_MAX) ){
     LOG_E(PHY,"illegal UE_id found!!! rnti %04x UE_id %d\n",rel8->rnti,UE_id);
@@ -167,25 +193,25 @@ void handle_nfapi_dlsch_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_pr
   dlsch0 = eNB->dlsch[UE_id][0];
   dlsch1 = eNB->dlsch[UE_id][1];
 
-#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
-  if ((rel13->pdsch_payload_type < 2) && (rel13->ue_type>0)) dlsch0->harq_ids[frame%2][subframe] = 0;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
+  if ((rel13->pdsch_payload_type < 2) && (rel13->ue_type>0)) dlsch0->harq_ids[proc->frame_tx%2][proc->subframe_tx] = 0;
 #endif
 
-  harq_pid        = dlsch0->harq_ids[frame%2][subframe];
+  harq_pid        = dlsch0->harq_ids[proc->frame_tx%2][proc->subframe_tx];
   AssertFatal((harq_pid>=0) && (harq_pid<8),"harq_pid %d not in 0...7 frame:%d subframe:%d subframe(TX):%d rnti:%x UE_id:%d dlsch0[harq_ids:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d]\n",
       harq_pid,
       frame,subframe,
       proc->subframe_tx,rel8->rnti,UE_id,
-      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],
-      dlsch0->harq_ids[frame%2][8],
-      dlsch0->harq_ids[frame%2][9]
+      dlsch0->harq_ids[proc->frame_tx%2][0],
+      dlsch0->harq_ids[proc->frame_tx%2][1],
+      dlsch0->harq_ids[proc->frame_tx%2][2],
+      dlsch0->harq_ids[proc->frame_tx%2][3],
+      dlsch0->harq_ids[proc->frame_tx%2][4],
+      dlsch0->harq_ids[proc->frame_tx%2][5],
+      dlsch0->harq_ids[proc->frame_tx%2][6],
+      dlsch0->harq_ids[proc->frame_tx%2][7],
+      dlsch0->harq_ids[proc->frame_tx%2][8],
+      dlsch0->harq_ids[proc->frame_tx%2][9]
       );
   dlsch0_harq     = dlsch0->harq_processes[harq_pid];
   dlsch1_harq     = dlsch1->harq_processes[harq_pid];
@@ -211,7 +237,7 @@ void handle_nfapi_dlsch_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_pr
     computeRhoB_eNB(rel8->pa,eNB->frame_parms.pdsch_config_common.p_b,eNB->frame_parms.nb_antenna_ports_eNB,dlsch1,dlsch1_harq->dl_power_off);
   }
 
-  dlsch0_harq->pdsch_start = eNB->pdcch_vars[subframe & 1].num_pdcch_symbols;
+  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
     if(sdu == NULL) {
@@ -236,7 +262,7 @@ void handle_nfapi_dlsch_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_pr
                                     rel8->rnti,UE_id,harq_pid);
   }
 
-#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
 #ifdef PHY_TX_THREAD
   dlsch0_harq->sib1_br_flag=0;
 #else
@@ -244,18 +270,36 @@ void handle_nfapi_dlsch_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_pr
 #endif
 
   if ((rel13->pdsch_payload_type <2) && (rel13->ue_type>0)) { // this is a BR/CE UE and SIB1-BR/SI-BR
+    UE_id = find_dlsch(rel8->rnti,eNB,SEARCH_EXIST_OR_FREE);
+    AssertFatal(UE_id!=-1,"no free or exiting dlsch_context\n");
+    AssertFatal(UE_id<NUMBER_OF_UE_MAX,"returned UE_id %d >= %d(NUMBER_OF_UE_MAX)\n",UE_id,NUMBER_OF_UE_MAX);
+
+    dlsch0 = eNB->dlsch[UE_id][0];
+    dlsch0->harq_mask = 1;
+    dlsch0_harq     = dlsch0->harq_processes[0];
+    dlsch0_harq->pdu                    = sdu;
+
+    if (proc->frame_tx < 200) LOG_D(PHY,"NFAPI: frame %d, subframe %d (TX %d.%d): Programming SI-BR (%d) => %d\n",frame,subframe,proc->frame_tx,proc->subframe_tx,rel13->pdsch_payload_type,UE_id);
+
     dlsch0->rnti             = 0xFFFF;
     dlsch0->Kmimo            = 1;
     dlsch0->Mdlharq          = 4;
     dlsch0->Nsoft            = 25344;
 
+    dlsch0->i0               = rel13->initial_transmission_sf_io;
+    dlsch0_harq->pdsch_start = rel10->pdsch_start;
+    dlsch0->harq_ids[proc->frame_tx%2][proc->subframe_rx] = 0;
+    dlsch0_harq->frame       = proc->frame_tx;
+    dlsch0_harq->subframe    = proc->subframe_tx;
+
+
 #ifdef PHY_TX_THREAD
     if (rel13->pdsch_payload_type == 0) dlsch0_harq->sib1_br_flag=1;
 #else
     if (rel13->pdsch_payload_type == 0) dlsch0->sib1_br_flag=1;
 #endif
 
-    // configure PDSCH
+     // configure PDSCH
     switch (eNB->frame_parms.N_RB_DL) {
     case 6:
       dlsch0_harq->rb_alloc[0]      = localRIV2alloc_LUT6[rel8->resource_block_coding];
@@ -299,15 +343,22 @@ void handle_nfapi_dlsch_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_pr
     dlsch0_harq->codeword           = 0;
     dlsch0_harq->pdsch_start        = rel10->pdsch_start;
   }
-#ifdef PHY_TX_THREAD
-  dlsch0_harq->i0          = rel13->initial_transmission_sf_io;
-#else
-  dlsch0->i0               = rel13->initial_transmission_sf_io;
+  else
 #endif
+  {
+    UE_id = find_dlsch(rel8->rnti,eNB,SEARCH_EXIST_OR_FREE);
+    AssertFatal(UE_id!=-1,"no free or exiting dlsch_context\n");
+    AssertFatal(UE_id<NUMBER_OF_UE_MAX,"returned UE_id %d >= %d(NUMBER_OF_UE_MAX)\n",UE_id,NUMBER_OF_UE_MAX);
 
+    dlsch0 = eNB->dlsch[UE_id][0];
+    dlsch1 = eNB->dlsch[UE_id][1];
+
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+    dlsch0->sib1_br_flag=0;
+    dlsch0->i0               = 0xFFFF;
 #endif
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   LOG_D(PHY,"dlsch->i0:%04x dlsch0_harq[pdsch_start:%d nb_rb:%d vrb_type:%d rvidx:%d Nl:%d mimo_mode:%d dl_power_off:%d round:%d status:%d TBS:%d Qm:%d codeword:%d rb_alloc:%d] rel8[length:%d]\n", 
 #ifdef PHY_TX_THREAD
       dlsch0_harq->i0,
@@ -323,9 +374,52 @@ void handle_nfapi_dlsch_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_pr
       rel8->length
       );
 #endif
+
+    dlsch0->active = 1;
+    harq_pid        = dlsch0->harq_ids[frame%2][proc->subframe_tx];
+    dlsch0->harq_mask |= (1<<harq_pid);
+
+    AssertFatal((harq_pid>=0) && (harq_pid<8),"subframe %d: harq_pid %d not in 0...7\n",proc->subframe_tx,harq_pid);
+    dlsch0_harq     = dlsch0->harq_processes[harq_pid];
+    dlsch1_harq     = dlsch1->harq_processes[harq_pid];
+    AssertFatal(dlsch0_harq!=NULL,"dlsch_harq is null\n");
+
+  // compute DL power control parameters
+
+
+    if (dlsch0->active){
+      computeRhoA_eNB(rel8->pa,dlsch0,dlsch0_harq->dl_power_off, eNB->frame_parms.nb_antenna_ports_eNB);
+      computeRhoB_eNB(rel8->pa,eNB->frame_parms.pdsch_config_common.p_b,eNB->frame_parms.nb_antenna_ports_eNB,dlsch0,dlsch0_harq->dl_power_off);
+    }
+    if (dlsch1->active){
+      computeRhoA_eNB(rel8->pa, dlsch1,dlsch1_harq->dl_power_off, eNB->frame_parms.nb_antenna_ports_eNB);
+      computeRhoB_eNB(rel8->pa,eNB->frame_parms.pdsch_config_common.p_b,eNB->frame_parms.nb_antenna_ports_eNB,dlsch1,dlsch1_harq->dl_power_off);
+    }
+
+#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;
+#endif
+    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,
+                  dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pdu_index);
+      if (rel8->rnti != 0xFFFF) LOG_D(PHY,"NFAPI: frame %d, subframe %d: programming dlsch for round 0, rnti %x, UE_id %d, harq_pid %d\n",
+                                    proc->frame_tx,proc->subframe_tx,rel8->rnti,UE_id,harq_pid);
+      if (codeword_index == 0) dlsch0_harq->pdu                    = sdu;
+      else                     dlsch1_harq->pdu                    = sdu;
+    }
+    else {
+      if (rel8->rnti != 0xFFFF) LOG_D(PHY,"NFAPI: frame %d, subframe %d: programming dlsch for round %d, rnti %x, UE_id %d, harq_pid %d\n",
+                                      proc->frame_tx,proc->subframe_tx,dlsch0_harq->round,
+                                    rel8->rnti,UE_id,harq_pid);
+    }
+
+  }
 }
 
-uint16_t to_beta_offset_harqack[16]={16,20,25,32,40,50,64,80,101,127,160,248,400,640,1008,8};
+int16_t to_beta_offset_harqack[16]={16,20,25,32,40,50,64,80,101,127,160,248,400,640,1008,8};
 
 void handle_ulsch_harq_pdu(
         PHY_VARS_eNB                           *eNB,
@@ -340,6 +434,8 @@ void handle_ulsch_harq_pdu(
   LTE_eNB_ULSCH_t *ulsch=eNB->ulsch[UE_id];
   LTE_UL_eNB_HARQ_t *ulsch_harq;
 
+  if (nfapi_mode==2) return;
+
   int harq_pid = rel8->harq_process_number;
   ulsch_harq = ulsch->harq_processes[harq_pid];
   ulsch_harq->frame                      = frame;
@@ -363,6 +459,8 @@ void handle_ulsch_cqi_ri_pdu(PHY_VARS_eNB *eNB,int UE_id,nfapi_ul_config_request
   int harq_pid = ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.harq_process_number;
   LTE_UL_eNB_HARQ_t *ulsch_harq = ulsch->harq_processes[harq_pid];
 
+  if (nfapi_mode==2) return;
+
   ulsch_harq->frame                       = frame;
   ulsch_harq->subframe                    = subframe;
   ulsch_harq->O_RI                        = rel9->aperiodic_cqi_pmi_ri_report.cc[0].ri_size;
@@ -384,6 +482,8 @@ void handle_ulsch_cqi_harq_ri_pdu(PHY_VARS_eNB *eNB,int UE_id,nfapi_ul_config_re
   LTE_UL_eNB_HARQ_t *ulsch_harq = ulsch->harq_processes[harq_pid];
   nfapi_ul_config_ulsch_harq_information *harq_information = &ul_config_pdu->ulsch_cqi_harq_ri_pdu.harq_information;
 
+  if (nfapi_mode==2) return;
+
   ulsch_harq->frame                       = frame;
   ulsch_harq->subframe                    = subframe;
   ulsch_harq->O_RI                        = rel9->aperiodic_cqi_pmi_ri_report.cc[0].ri_size;
@@ -399,6 +499,9 @@ void handle_ulsch_cqi_harq_ri_pdu(PHY_VARS_eNB *eNB,int UE_id,nfapi_ul_config_re
 
 void handle_uci_harq_information(PHY_VARS_eNB *eNB, LTE_eNB_UCI *uci,nfapi_ul_config_harq_information *harq_information)
 {
+
+  if (nfapi_mode==2) return;
+
   if (eNB->frame_parms.frame_type == FDD) {
     uci->num_pucch_resources = harq_information->harq_information_rel9_fdd.number_of_pucch_resources;
 
@@ -452,7 +555,7 @@ void handle_uci_harq_information(PHY_VARS_eNB *eNB, LTE_eNB_UCI *uci,nfapi_ul_co
       uci->n_pucch_3[0] = harq_information->harq_information_rel9_fdd.n_pucch_1_0;
       uci->n_pucch_3[1] = harq_information->harq_information_rel11.n_pucch_2_0;
     }
-    else AssertFatal(1==0,"unsupported HARQ mode %d\n",harq_information->harq_information_rel9_fdd.ack_nack_mode);
+    else AssertFatal(1==0,"unsupported FDD HARQ mode %d size %d\n",harq_information->harq_information_rel9_fdd.ack_nack_mode,harq_information->harq_information_rel9_fdd.harq_size);
   }
   else { // TDD
     uci->num_pucch_resources = harq_information->harq_information_rel10_tdd.number_of_pucch_resources;
@@ -497,6 +600,8 @@ void handle_uci_sr_pdu(PHY_VARS_eNB *eNB,int UE_id,nfapi_ul_config_request_pdu_t
 {
   LTE_eNB_UCI *uci = &eNB->uci_vars[UE_id];
 
+  if (nfapi_mode==2) return;
+
   uci->frame               = frame;
   uci->subframe            = subframe;
   uci->rnti                = ul_config_pdu->uci_sr_pdu.ue_information.ue_information_rel8.rnti;
@@ -507,7 +612,11 @@ void handle_uci_sr_pdu(PHY_VARS_eNB *eNB,int UE_id,nfapi_ul_config_request_pdu_t
   uci->n_pucch_1_0_sr[0]   = ul_config_pdu->uci_sr_pdu.sr_information.sr_information_rel8.pucch_index;
   uci->srs_active          = srs_active;
   uci->active              = 1;
-
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  uci->ue_type                     = ul_config_pdu->uci_sr_pdu.ue_information.ue_information_rel13.ue_type;
+  uci->empty_symbols               = ul_config_pdu->uci_sr_pdu.ue_information.ue_information_rel13.empty_symbols;
+  uci->total_repetitions = ul_config_pdu->uci_sr_pdu.ue_information.ue_information_rel13.total_number_of_repetitions;
+#endif
   LOG_D(PHY,"Programming UCI SR rnti %x, pucch1_0 %d for (%d,%d)\n",
         uci->rnti,uci->n_pucch_1_0_sr[0],frame,subframe);
 }
@@ -516,6 +625,8 @@ void handle_uci_sr_harq_pdu(PHY_VARS_eNB *eNB,int UE_id,nfapi_ul_config_request_
 {
   LTE_eNB_UCI *uci = &eNB->uci_vars[UE_id];
 
+  if (nfapi_mode==2) return;
+
   uci->frame               = frame;
   uci->subframe            = subframe;
   uci->rnti                = ul_config_pdu->uci_sr_harq_pdu.ue_information.ue_information_rel8.rnti;
@@ -525,7 +636,11 @@ void handle_uci_sr_harq_pdu(PHY_VARS_eNB *eNB,int UE_id,nfapi_ul_config_request_
   uci->n_pucch_1_0_sr[0]   = ul_config_pdu->uci_sr_harq_pdu.sr_information.sr_information_rel8.pucch_index;
   uci->srs_active          = srs_active;
   uci->active              = 1;
-
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  uci->ue_type                     = ul_config_pdu->uci_sr_harq_pdu.ue_information.ue_information_rel13.ue_type;
+  uci->empty_symbols               = ul_config_pdu->uci_sr_harq_pdu.ue_information.ue_information_rel13.empty_symbols;
+  uci->total_repetitions = ul_config_pdu->uci_sr_harq_pdu.ue_information.ue_information_rel13.total_number_of_repetitions;
+#endif
   handle_uci_harq_information(eNB,uci,&ul_config_pdu->uci_sr_harq_pdu.harq_information);
 }
 
@@ -533,6 +648,8 @@ void handle_uci_harq_pdu(PHY_VARS_eNB *eNB,int UE_id,nfapi_ul_config_request_pdu
 {
   LTE_eNB_UCI *uci = &eNB->uci_vars[UE_id];
 
+  if (nfapi_mode==2) return;
+
   LOG_D(PHY,"Frame %d, Subframe %d: Programming UCI_HARQ process (type %d)\n",frame,subframe,HARQ);
   uci->frame             = frame;
   uci->subframe          = subframe;
@@ -540,7 +657,11 @@ void handle_uci_harq_pdu(PHY_VARS_eNB *eNB,int UE_id,nfapi_ul_config_request_pdu
   uci->type              = HARQ;
   uci->srs_active        = srs_active;
   uci->num_antenna_ports = ul_config_pdu->uci_harq_pdu.harq_information.harq_information_rel11.num_ant_ports;
-
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  uci->ue_type                     = ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel13.ue_type;
+  uci->empty_symbols               = ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel13.empty_symbols;
+  uci->total_repetitions           = ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel13.total_number_of_repetitions;
+#endif
   handle_uci_harq_information(eNB,uci,&ul_config_pdu->uci_harq_pdu.harq_information);
 
   uci->active=1;
@@ -550,6 +671,8 @@ void handle_srs_pdu(PHY_VARS_eNB *eNB,nfapi_ul_config_request_pdu_t *ul_config_p
 {
   int i;
 
+  if (nfapi_mode==2) return;
+
   for (i=0;i<NUMBER_OF_UE_MAX;i++) {
 
     if (eNB->soundingrs_ul_config_dedicated[i].active==1) continue;
@@ -569,13 +692,15 @@ void handle_srs_pdu(PHY_VARS_eNB *eNB,nfapi_ul_config_request_pdu_t *ul_config_p
   AssertFatal(i<NUMBER_OF_UE_MAX,"No room for SRS processing\n");
 }
 
-void handle_nfapi_ul_pdu(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
+void handle_nfapi_ul_pdu(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc,
                          nfapi_ul_config_request_pdu_t *ul_config_pdu,
                          uint16_t frame,uint8_t subframe,uint8_t srs_present)
 {
   nfapi_ul_config_ulsch_pdu_rel8_t *rel8 = &ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8;
   int16_t UE_id;
 
+  if (nfapi_mode==2) return;
+
   // 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) {
@@ -616,6 +741,9 @@ void handle_nfapi_ul_pdu(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
     AssertFatal((UE_id = find_uci(ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.rnti,
                                   proc->frame_tx,proc->subframe_tx,eNB,SEARCH_EXIST_OR_FREE))>=0,
                 "No available UE UCI for rnti %x\n",ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.rnti);
+    LOG_D(PHY,"Applying UL UCI_HARQ config for UE %d, rnti %x for frame %d, subframe %d\n",
+          UE_id,ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.rnti,frame,subframe);
+
     handle_uci_harq_pdu(eNB,UE_id,ul_config_pdu,frame,subframe,srs_present);
   }
   else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_UCI_CQI_PDU_TYPE) {
@@ -647,7 +775,7 @@ void handle_nfapi_ul_pdu(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
 void schedule_response(Sched_Rsp_t *Sched_INFO)
 {
   PHY_VARS_eNB *eNB;
-  eNB_rxtx_proc_t *proc;
+  L1_rxtx_proc_t *proc;
   // copy data from L2 interface into L1 structures
   module_id_t               Mod_id       = Sched_INFO->module_id;
   uint8_t                   CC_id        = Sched_INFO->CC_id;
@@ -670,7 +798,7 @@ void schedule_response(Sched_Rsp_t *Sched_INFO)
 
   eNB         = RC.eNB[Mod_id][CC_id];
   fp          = &eNB->frame_parms;
-  proc        = &eNB->proc.proc_rxtx[0];
+  proc        = &eNB->proc.L1_proc;
 
   /* TODO: check that following line is correct - in the meantime it is disabled */
   //if ((fp->frame_type == TDD) && (subframe_select(fp,subframe)==SF_UL)) return;
@@ -697,6 +825,9 @@ void schedule_response(Sched_Rsp_t *Sched_INFO)
   eNB->pdcch_vars[subframe&1].num_pdcch_symbols = number_pdcch_ofdm_symbols;
   eNB->pdcch_vars[subframe&1].num_dci           = 0;
   eNB->phich_vars[subframe&1].num_hi            = 0;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  eNB->mpdcch_vars[subframe&1].num_dci           = 0;
+#endif
 
   LOG_D(PHY,"NFAPI: Sched_INFO:SFN/SF:%04d%d DL_req:SFN/SF:%04d%d:dl_pdu:%d tx_req:SFN/SF:%04d%d:pdus:%d\n",
        frame,subframe,
@@ -722,6 +853,7 @@ void schedule_response(Sched_Rsp_t *Sched_INFO)
   
     harq_pid = subframe2harq_pid(fp,ul_frame,ul_subframe);
 
+
     // clear DCI allocation maps for new subframe
 
     for (i=0; i<NUMBER_OF_UE_MAX; i++) {
@@ -823,7 +955,7 @@ void schedule_response(Sched_Rsp_t *Sched_INFO)
     case NFAPI_DL_CONFIG_EPDCCH_DL_PDU_TYPE:
       //      handle_nfapi_epdcch_pdu(eNB,dl_config_pdu);
       break;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
     case NFAPI_DL_CONFIG_MPDCCH_PDU_TYPE:
       handle_nfapi_mpdcch_pdu(eNB,proc,dl_config_pdu);
       eNB->mpdcch_vars[subframe&1].num_dci++;
@@ -852,16 +984,20 @@ void schedule_response(Sched_Rsp_t *Sched_INFO)
 
     switch (hi_dci0_req_pdu->pdu_type) {
 
-      case NFAPI_HI_DCI0_DCI_PDU_TYPE:
+    case NFAPI_HI_DCI0_DCI_PDU_TYPE:
 
-        handle_nfapi_hi_dci0_dci_pdu(eNB,NFAPI_SFNSF2SFN(HI_DCI0_req->sfn_sf),NFAPI_SFNSF2SF(HI_DCI0_req->sfn_sf),proc,hi_dci0_req_pdu);
+      handle_nfapi_hi_dci0_dci_pdu(eNB,NFAPI_SFNSF2SFN(HI_DCI0_req->sfn_sf),NFAPI_SFNSF2SF(HI_DCI0_req->sfn_sf),proc,hi_dci0_req_pdu);
+      eNB->pdcch_vars[NFAPI_SFNSF2SF(HI_DCI0_req->sfn_sf)&1].num_dci++;
+      break;
 
-        eNB->pdcch_vars[NFAPI_SFNSF2SF(HI_DCI0_req->sfn_sf)&1].num_dci++;
-        break;
+    case NFAPI_HI_DCI0_MPDCCH_DCI_PDU_TYPE:
+      handle_nfapi_hi_dci0_mpdcch_dci_pdu(eNB,proc,hi_dci0_req_pdu);
+      eNB->mpdcch_vars[subframe&1].num_dci++;
+      break;
 
-      case NFAPI_HI_DCI0_HI_PDU_TYPE:
-        handle_nfapi_hi_dci0_hi_pdu(eNB,NFAPI_SFNSF2SFN(HI_DCI0_req->sfn_sf),NFAPI_SFNSF2SF(HI_DCI0_req->sfn_sf),proc,hi_dci0_req_pdu);
-        break;
+    case NFAPI_HI_DCI0_HI_PDU_TYPE:
+      handle_nfapi_hi_dci0_hi_pdu(eNB,NFAPI_SFNSF2SFN(HI_DCI0_req->sfn_sf),NFAPI_SFNSF2SF(HI_DCI0_req->sfn_sf),proc,hi_dci0_req_pdu);
+      break;
     }
   }
 
diff --git a/openair1/SCHED/fapi_l1.h b/openair1/SCHED/fapi_l1.h
index efb028f46444b73cbed6df710faf6db75bcc4080..3bd469b685f6ea3fc04d973f9fc6463d4533a545 100644
--- a/openair1/SCHED/fapi_l1.h
+++ b/openair1/SCHED/fapi_l1.h
@@ -43,17 +43,17 @@ void fill_ulsch_cqi_indication(PHY_VARS_eNB *eNB,uint16_t frame,uint8_t subframe
 void fill_sr_indication(PHY_VARS_eNB *eNB,uint16_t rnti,int frame,int subframe,uint32_t stat);
 void fill_rx_indication(PHY_VARS_eNB *eNB,int UE_id,int frame,int subframe);
 void fill_crc_indication(PHY_VARS_eNB *eNB,int UE_id,int frame,int subframe,uint8_t crc_flag);
-void handle_nfapi_dci_dl_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t *proc,nfapi_dl_config_request_pdu_t *dl_config_pdu);
-void handle_nfapi_mpdcch_pdu(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,nfapi_dl_config_request_pdu_t *dl_config_pdu);
-void handle_nfapi_hi_dci0_dci_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t *proc,
+void handle_nfapi_dci_dl_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,L1_rxtx_proc_t *proc,nfapi_dl_config_request_pdu_t *dl_config_pdu);
+void handle_nfapi_mpdcch_pdu(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc,nfapi_dl_config_request_pdu_t *dl_config_pdu);
+void handle_nfapi_hi_dci0_dci_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,L1_rxtx_proc_t *proc,
 				  nfapi_hi_dci0_request_pdu_t *hi_dci0_config_pdu);
-void handle_nfapi_hi_dci0_hi_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t *proc,
+void handle_nfapi_hi_dci0_hi_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,L1_rxtx_proc_t *proc,
 				 nfapi_hi_dci0_request_pdu_t *hi_dci0_config_pdu);
-void handle_nfapi_dlsch_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t *proc,
+void handle_nfapi_dlsch_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,L1_rxtx_proc_t *proc,
 			    nfapi_dl_config_request_pdu_t *dl_config_pdu,
 			    uint8_t codeword_index,
 			    uint8_t *sdu);
-void handle_nfapi_ul_pdu(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
+void handle_nfapi_ul_pdu(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc,
 			 nfapi_ul_config_request_pdu_t *ul_config_pdu,
 			 uint16_t frame,uint8_t subframe,uint8_t srs_present);
 
diff --git a/openair1/SCHED/phy_mac_stub.c b/openair1/SCHED/phy_mac_stub.c
index 664791f7c459632d51541e413ef844384e6c8ab1..55149f8d2ea075623bb4788ec600f30c0a9a44bc 100644
--- a/openair1/SCHED/phy_mac_stub.c
+++ b/openair1/SCHED/phy_mac_stub.c
@@ -40,7 +40,7 @@
 uint8_t dci_ndi_toggle_even[8] = {0, 0, 0, 0, 0, 0, 0, 0};
 uint8_t dci_ndi_toggle_odd[8]  = {0, 0, 0, 0, 0, 0, 0, 0};
 
-void fill_dci(DCI_PDU *DCI_pdu,PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
+void fill_dci(DCI_PDU *DCI_pdu,PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc)
 {
 /* SYRTEM */
   uint8_t *dci_ndi_toggle_tmp = NULL;
diff --git a/openair1/SCHED/phy_procedures_lte_eNb.c b/openair1/SCHED/phy_procedures_lte_eNb.c
index a65bcd3b73a6ffa9bc184401731f221f0c882296..af844a8f1ff1f9f6d470ab87cc2d07ba30730a8c 100644
--- a/openair1/SCHED/phy_procedures_lte_eNb.c
+++ b/openair1/SCHED/phy_procedures_lte_eNb.c
@@ -46,7 +46,7 @@
 #include <time.h>
 
 #if defined(ENABLE_ITTI)
-#   include "intertask_interface.h"
+#include "intertask_interface.h"
 #endif
 
 extern uint8_t nfapi_mode;
@@ -63,7 +63,7 @@ int16_t get_hundred_times_delta_IF_eNB(PHY_VARS_eNB *eNB,uint16_t UE_id,uint8_t
   DevAssert( harq_pid < 8 );
 
   Nre = eNB->ulsch[UE_id]->harq_processes[harq_pid]->Nsymb_initial *
-        eNB->ulsch[UE_id]->harq_processes[harq_pid]->nb_rb*12;
+    eNB->ulsch[UE_id]->harq_processes[harq_pid]->nb_rb*12;
 
   sumKr = 0;
 
@@ -87,7 +87,7 @@ int16_t get_hundred_times_delta_IF_eNB(PHY_VARS_eNB *eNB,uint16_t UE_id,uint8_t
   //(eNB->ulsch[UE_id]->harq_processes[harq_pid]->control_only == 1) ? eNB->ulsch[UE_id]->beta_offset_cqi_times8:8;
 
   DevAssert( UE_id < NUMBER_OF_UE_MAX );
-//#warning "This condition happens sometimes. Need more investigation" // navid
+  //#warning "This condition happens sometimes. Need more investigation" // navid
   //DevAssert( MPR_x100/6 < 100 );
 
   if (1==1) { //eNB->ul_power_control_dedicated[UE_id].deltaMCS_Enabled == 1) {
@@ -133,33 +133,30 @@ lte_subframe_t get_subframe_direction(uint8_t Mod_id,uint8_t CC_id,uint8_t subfr
 
 }
 
-void pmch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc) {
+void pmch_procedures(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc) {
 
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
   MCH_PDU *mch_pduP=NULL;
   //  uint8_t sync_area=255;
 #endif
 
-  int subframe = proc->subframe_tx;
+  int             subframe = proc->subframe_tx;
 
-  AssertFatal(1==0,"pmch not tested for the moment, exiting\n");
+  AssertFatal (1 == 0, "pmch not tested for the moment, exiting\n");
 
   // This is DL-Cell spec pilots in Control region
-  generate_pilots_slot(eNB,
-		       eNB->common_vars.txdataF,
-		       AMP,
-		       subframe<<1,1);
+  generate_pilots_slot (eNB, eNB->common_vars.txdataF, AMP, subframe << 1, 1);
 
-  
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
   // if mcch is active, send regardless of the node type: eNB or RN
   // when mcch is active, MAC sched does not allow MCCH and MTCH multiplexing
   /*
-  mch_pduP = mac_xface->get_mch_sdu(eNB->Mod_id,
-				    eNB->CC_id,
-				    proc->frame_tx,
-				    subframe);
+    mch_pduP = mac_xface->get_mch_sdu(eNB->Mod_id,
+    eNB->CC_id,
+    proc->frame_tx,
+    subframe);
   */
   if ((mch_pduP->Pdu_size > 0) && (mch_pduP->sync_area == 0)) // TEST: only transmit mcch for sync area 0
     LOG_D(PHY,"[eNB%"PRIu8"] Frame %d subframe %d : Got MCH pdu for MBSFN (MCS %"PRIu8", TBS %d) \n",
@@ -173,13 +170,13 @@ void pmch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc) {
   }
     
   if (mch_pduP) {
-    fill_eNB_dlsch_MCH(eNB,mch_pduP->mcs,1,0);
+    fill_eNB_dlsch_MCH (eNB, mch_pduP->mcs, 1, 0);
     // Generate PMCH
-    generate_mch(eNB,proc,(uint8_t*)mch_pduP->payload);
+    generate_mch (eNB, proc, (uint8_t *) mch_pduP->payload);
   } else {
-    LOG_D(PHY,"[eNB/RN] Frame %d subframe %d: MCH not generated \n",proc->frame_tx,subframe);
+    LOG_D (PHY, "[eNB/RN] Frame %d subframe %d: MCH not generated \n", proc->frame_tx, subframe);
   }
-  
+
 #endif
 }
 
@@ -194,58 +191,39 @@ void common_signal_procedures (PHY_VARS_eNB *eNB,int frame, int subframe) {
   // generate Cell-Specific Reference Signals for both slots
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_RS_TX,1);
 
-   if(subframe_select(fp,subframe) == SF_S)
-       generate_pilots_slot(eNB,
-                    txdataF,
-                    AMP,
-                    subframe<<1,1);
-   else
-  generate_pilots_slot(eNB,
-		       txdataF,
-		       AMP,
-		       subframe<<1,0);
-
- // check that 2nd slot is for DL
-
-  // check that 2nd slot is for DL
-  if (subframe_select(fp,subframe) == SF_DL)
+  if(subframe_select(fp,subframe) == SF_S)
     generate_pilots_slot(eNB,
 			 txdataF,
 			 AMP,
-			 (subframe<<1)+1,0);
-  
-  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_RS_TX,0);
-      
+			 subframe<<1,1);
+  else
+    generate_pilots_slot(eNB,
+			 txdataF,
+			 AMP,
+			 subframe<<1,0);
+
+  // check that 2nd slot is for DL
+  if (subframe_select (fp, subframe) == SF_DL)
+    generate_pilots_slot (eNB, txdataF, AMP, (subframe << 1) + 1, 0);
+
+  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME (VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_RS_TX, 0);
+
 
   // First half of PSS/SSS (FDD, slot 0)
   if (subframe == 0) {
     if (fp->frame_type == FDD) {
-      generate_pss(txdataF,
-		   AMP,
-		   fp,
-		   (fp->Ncp==NORMAL) ? 6 : 5,
-		   0);
-      generate_sss(txdataF,
-		   AMP,
-		   fp,
-		   (fp->Ncp==NORMAL) ? 5 : 4,
-		   0);
-      
+      generate_pss (txdataF, AMP, fp, (fp->Ncp == NORMAL) ? 6 : 5, 0);
+      generate_sss (txdataF, AMP, fp, (fp->Ncp == NORMAL) ? 5 : 4, 0);
+
     }
-    
 
 
-      
+
     /// First half of SSS (TDD, slot 1)
-    
+
     if (fp->frame_type == TDD) {
-      generate_sss(txdataF,
-		   AMP,
-		   fp,
-		   (fp->Ncp==NORMAL) ? 6 : 5,
-		   1);
+      generate_sss (txdataF, AMP, fp, (fp->Ncp == NORMAL) ? 6 : 5, 1);
     }
-
     // generate PBCH (Physical Broadcast CHannel) info
 
     /// generate PBCH
@@ -254,57 +232,27 @@ void common_signal_procedures (PHY_VARS_eNB *eNB,int frame, int subframe) {
       if (eNB->pbch_configured!=1) return;
       eNB->pbch_configured=0;
     }
-    generate_pbch(&eNB->pbch,
-		  txdataF,
-		  AMP,
-		  fp,
-		  pbch_pdu,
-		  frame&3);
-  
-  }
-  else if ((subframe == 1) &&
-	   (fp->frame_type == TDD)){
-    generate_pss(txdataF,
-		 AMP,
-		 fp,
-		 2,
-		 2);
+    T(T_ENB_PHY_MIB, T_INT(eNB->Mod_id), T_INT(frame), T_INT(subframe),
+      T_BUFFER(pbch_pdu, 3));
+
+    generate_pbch (&eNB->pbch, txdataF, AMP, fp, pbch_pdu, frame & 3);
+
+  } else if ((subframe == 1) && (fp->frame_type == TDD)) {
+    generate_pss (txdataF, AMP, fp, 2, 2);
   }
-  
   // Second half of PSS/SSS (FDD, slot 10)
-  else if ((subframe == 5) && 
-	   (fp->frame_type == FDD)) {
-    generate_pss(txdataF,
-		 AMP,
-		 &eNB->frame_parms,
-		 (fp->Ncp==NORMAL) ? 6 : 5,
-		 10);
-    generate_sss(txdataF,
-		 AMP,
-		 &eNB->frame_parms,
-		 (fp->Ncp==NORMAL) ? 5 : 4,
-		 10);
+  else if ((subframe == 5) && (fp->frame_type == FDD)) {
+    generate_pss (txdataF, AMP, &eNB->frame_parms, (fp->Ncp == NORMAL) ? 6 : 5, 10);
+    generate_sss (txdataF, AMP, &eNB->frame_parms, (fp->Ncp == NORMAL) ? 5 : 4, 10);
 
   }
-
   //  Second-half of SSS (TDD, slot 11)
-  else if ((subframe == 5) &&
-	   (fp->frame_type == TDD)) {
-    generate_sss(txdataF,
-		 AMP,
-		 fp,
-		 (fp->Ncp==NORMAL) ? 6 : 5,
-		 11);
+  else if ((subframe == 5) && (fp->frame_type == TDD)) {
+    generate_sss (txdataF, AMP, fp, (fp->Ncp == NORMAL) ? 6 : 5, 11);
   }
-
   // Second half of PSS (TDD, slot 12)
-  else if ((subframe == 6) &&
-	   (fp->frame_type == TDD)) { 
-    generate_pss(txdataF,
-		 AMP,
-		 fp,
-		 2,
-		 12);
+  else if ((subframe == 6) && (fp->frame_type == TDD)) {
+    generate_pss (txdataF, AMP, fp, 2, 12);
   }
 
 }
@@ -312,7 +260,7 @@ void common_signal_procedures (PHY_VARS_eNB *eNB,int frame, int subframe) {
 
 
 void pdsch_procedures(PHY_VARS_eNB *eNB,
-		      eNB_rxtx_proc_t *proc,
+		      L1_rxtx_proc_t *proc,
 		      int harq_pid,
 		      LTE_eNB_DLSCH_t *dlsch, 
 		      LTE_eNB_DLSCH_t *dlsch1,
@@ -380,74 +328,75 @@ void pdsch_procedures(PHY_VARS_eNB *eNB,
     ue_stats->dlsch_trials[harq_pid][dlsch_harq->round]++;
 #ifdef DEBUG_PHY_PROC
 #ifdef DEBUG_DLSCH
-    LOG_D(PHY,"[eNB] This DLSCH is a retransmission\n");
+    LOG_D (PHY, "[eNB] This DLSCH is a retransmission\n");
 #endif
 #endif
   }
 
 
   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);
+	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
 
     if (dlsch_harq->pdu==NULL){
-        LOG_E(PHY,"dlsch_harq->pdu == NULL SFN/SF:%04d%d dlsch[rnti:%x] dlsch_harq[pdu:%p pdsch_start:%d Qm:%d Nl:%d round:%d nb_rb:%d rb_alloc[0]:%d]\n", frame,subframe,dlsch->rnti, dlsch_harq->pdu,dlsch_harq->pdsch_start,dlsch_harq->Qm,dlsch_harq->Nl,dlsch_harq->round,dlsch_harq->nb_rb,dlsch_harq->rb_alloc[0]);
+      LOG_E(PHY,"dlsch_harq->pdu == NULL SFN/SF:%04d%d dlsch[rnti:%x] dlsch_harq[pdu:%p pdsch_start:%d Qm:%d Nl:%d round:%d nb_rb:%d rb_alloc[0]:%d]\n", frame,subframe,dlsch->rnti, dlsch_harq->pdu,dlsch_harq->pdsch_start,dlsch_harq->Qm,dlsch_harq->Nl,dlsch_harq->round,dlsch_harq->nb_rb,dlsch_harq->rb_alloc[0]);
       return;
     }
 
     start_meas(&eNB->dlsch_encoding_stats);
 
-    eNB->te(eNB,
-	  dlsch_harq->pdu,
-	  dlsch_harq->pdsch_start,
-	  dlsch,
-	  frame,
-	  subframe,
-	  &eNB->dlsch_rate_matching_stats,
-	  &eNB->dlsch_turbo_encoding_stats,
-	  &eNB->dlsch_turbo_encoding_waiting_stats,
-      &eNB->dlsch_turbo_encoding_main_stats,
-      &eNB->dlsch_turbo_encoding_wakeup_stats0,
-      &eNB->dlsch_turbo_encoding_wakeup_stats1,
-	  &eNB->dlsch_interleaving_stats);
+    dlsch_encoding_all(eNB,
+		       dlsch_harq->pdu,
+		       dlsch_harq->pdsch_start,
+		       dlsch,
+		       frame,
+		       subframe,
+		       &eNB->dlsch_rate_matching_stats,
+		       &eNB->dlsch_turbo_encoding_stats,
+		       &eNB->dlsch_turbo_encoding_waiting_stats,
+		       &eNB->dlsch_turbo_encoding_main_stats,
+		       &eNB->dlsch_turbo_encoding_wakeup_stats0,
+		       &eNB->dlsch_turbo_encoding_wakeup_stats1,
+		       &eNB->dlsch_interleaving_stats);
+
     stop_meas(&eNB->dlsch_encoding_stats);
-  if(eNB->dlsch_encoding_stats.p_time>500*3000 && opp_enabled == 1)
-  {
-    print_meas_now(&eNB->dlsch_encoding_stats,"total coding",stderr);
-  }
-  // 36-211
+    if(eNB->dlsch_encoding_stats.p_time>500*3000 && opp_enabled == 1)
+      {
+	print_meas_now(&eNB->dlsch_encoding_stats,"total coding",stderr);
+      }
+    // 36-211
     start_meas(&eNB->dlsch_scrambling_stats);
     dlsch_scrambling(fp,
-        0,
-        dlsch,
-        harq_pid,
-        get_G(fp,
-          dlsch_harq->nb_rb,
-          dlsch_harq->rb_alloc,
-          dlsch_harq->Qm,
-          dlsch_harq->Nl,
-          dlsch_harq->pdsch_start,
-          frame,subframe,
-          0),
-        0,
-        frame,
-        subframe<<1);
+		     0,
+		     dlsch,
+		     harq_pid,
+		     get_G(fp,
+			   dlsch_harq->nb_rb,
+			   dlsch_harq->rb_alloc,
+			   dlsch_harq->Qm,
+			   dlsch_harq->Nl,
+			   dlsch_harq->pdsch_start,
+			   frame,subframe,
+			   0),
+		     0,
+		     frame,
+		     subframe<<1);
     stop_meas(&eNB->dlsch_scrambling_stats);
 
     start_meas(&eNB->dlsch_modulation_stats);
 
   
     dlsch_modulation(eNB,
-		   eNB->common_vars.txdataF,
-		   AMP,
-		   frame,
-		   subframe,
-		   dlsch_harq->pdsch_start,
-		   dlsch,
-		   dlsch1);
-  
-  stop_meas(&eNB->dlsch_modulation_stats);
+		     eNB->common_vars.txdataF,
+		     AMP,
+		     frame,
+		     subframe,
+		     dlsch_harq->pdsch_start,
+		     dlsch,
+		     dlsch1);
+
+    stop_meas(&eNB->dlsch_modulation_stats);
   }
 #ifdef PHY_TX_THREAD
   dlsch->active[subframe] = 0;
@@ -461,9 +410,8 @@ void pdsch_procedures(PHY_VARS_eNB *eNB,
 
 
 
-
 void phy_procedures_eNB_TX(PHY_VARS_eNB *eNB,
-			   eNB_rxtx_proc_t *proc,
+			   L1_rxtx_proc_t *proc,
 			   int do_meas)
 {
   int frame=proc->frame_tx;
@@ -473,6 +421,9 @@ void phy_procedures_eNB_TX(PHY_VARS_eNB *eNB,
   int16_t UE_id=0;
   uint8_t num_pdcch_symbols=0;
   uint8_t num_dci=0;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  uint8_t         num_mdci = 0;
+#endif
   uint8_t ul_subframe;
   uint32_t ul_frame;
   LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
@@ -480,19 +431,19 @@ void phy_procedures_eNB_TX(PHY_VARS_eNB *eNB,
 
 
 
-  if ((fp->frame_type == TDD) && (subframe_select(fp,subframe)==SF_UL)) return;
+  if ((fp->frame_type == TDD) && (subframe_select (fp, subframe) == SF_UL))
+    return;
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_TX+(eNB->CC_id),1);
   if (do_meas==1) start_meas(&eNB->phy_proc_tx);
+  if (do_meas==1) start_meas(&eNB->dlsch_common_and_dci);
 
   // clear the transmit data array for the current subframe
-  for (aa=0; aa<fp->nb_antenna_ports_eNB; aa++) {      
-    memset(&eNB->common_vars.txdataF[aa][subframe*fp->ofdm_symbol_size*(fp->symbols_per_tti)],
-	   0,fp->ofdm_symbol_size*(fp->symbols_per_tti)*sizeof(int32_t));
+  for (aa = 0; aa < fp->nb_antenna_ports_eNB; aa++) {
+    memset (&eNB->common_vars.txdataF[aa][subframe * fp->ofdm_symbol_size * (fp->symbols_per_tti)], 0, fp->ofdm_symbol_size * (fp->symbols_per_tti) * sizeof (int32_t));
   }
   
 
-
   if (nfapi_mode == 0 || nfapi_mode == 1) {
     if (is_pmch_subframe(frame,subframe,fp)) {
       pmch_procedures(eNB,proc);
@@ -505,24 +456,29 @@ void phy_procedures_eNB_TX(PHY_VARS_eNB *eNB,
 
 
   // clear existing ulsch dci allocations before applying info from MAC  (this is table
-  ul_subframe = pdcch_alloc2ul_subframe(fp,subframe);
-  ul_frame = pdcch_alloc2ul_frame(fp,frame,subframe);
+  ul_subframe = pdcch_alloc2ul_subframe (fp, subframe);
+  ul_frame = pdcch_alloc2ul_frame (fp, frame, subframe);
 
 
 
   // clear previous allocation information for all UEs
-  for (i=0; i<NUMBER_OF_UE_MAX; i++) {
+  for (i = 0; i < NUMBER_OF_UE_MAX; i++) {
     if (eNB->dlsch[i][0])
       eNB->dlsch[i][0]->subframe_tx[subframe] = 0;
   }
 
-  /* save old HARQ information needed for PHICH generation */
+
   /* TODO: check the following test - in the meantime it is put back as it was before */
   //if ((ul_subframe < 10)&&
   //    (subframe_select(fp,ul_subframe)==SF_UL)) { // This means that there is a potential UL subframe that will be scheduled here
   if (ul_subframe < 10) { // This means that there is a potential UL subframe that will be scheduled here
     for (i=0; i<NUMBER_OF_UE_MAX; i++) {
-      harq_pid = subframe2harq_pid(fp,ul_frame,ul_subframe);
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+      if (eNB->ulsch[i] && eNB->ulsch[i]->ue_type >0) harq_pid = 0;
+      else
+#endif
+	harq_pid = subframe2harq_pid(fp,ul_frame,ul_subframe);
+
       if (eNB->ulsch[i]) {
 	ulsch_harq = eNB->ulsch[i]->harq_processes[harq_pid];
 	
@@ -545,21 +501,19 @@ void phy_procedures_eNB_TX(PHY_VARS_eNB *eNB,
 	 * TODO: check if that works with TDD.
 	 */
 	ulsch_harq->previous_first_rb = ulsch_harq->first_rb;
-	ulsch_harq->previous_n_DMRS   = ulsch_harq->n_DMRS;
+	ulsch_harq->previous_n_DMRS = ulsch_harq->n_DMRS;
 	
       }
     }
   }
 
 
-
   num_pdcch_symbols = eNB->pdcch_vars[subframe&1].num_pdcch_symbols;
   num_dci           = eNB->pdcch_vars[subframe&1].num_dci;
   LOG_D(PHY,"num_pdcch_symbols %"PRIu8",number dci %"PRIu8"\n",num_pdcch_symbols, num_dci);
   VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_DCI_INFO,num_pdcch_symbols);
 
-
-  VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_DCI_INFO,(frame*10)+subframe);
+  VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME (VCD_SIGNAL_DUMPER_VARIABLES_DCI_INFO, (frame * 10) + subframe);
 
   if (num_dci > 0)
     LOG_D(PHY,"[eNB %"PRIu8"] Frame %d, subframe %d: Calling generate_dci_top (pdcch) (num_dci %"PRIu8") num_pdcch_symbols:%d\n",eNB->Mod_id,frame, subframe, num_dci, num_pdcch_symbols);
@@ -569,74 +523,84 @@ void phy_procedures_eNB_TX(PHY_VARS_eNB *eNB,
 
   if (nfapi_mode == 0 || nfapi_mode == 1) {
     generate_dci_top(num_pdcch_symbols,
-        num_dci,
-        &eNB->pdcch_vars[subframe&1].dci_alloc[0],
-        0,
-        AMP,
-        fp,
-        eNB->common_vars.txdataF,
-        subframe);
+		     num_dci,
+		     &eNB->pdcch_vars[subframe&1].dci_alloc[0],
+		     0,
+		     AMP,
+		     fp,
+		     eNB->common_vars.txdataF,
+		     subframe);
+
+#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);
+
+      generate_mdci_top (eNB, frame, subframe, AMP, eNB->common_vars.txdataF);
+
+    }
+#endif
   }
 
+  if (do_meas==1) stop_meas(&eNB->dlsch_common_and_dci);
+  if (do_meas==1) start_meas(&eNB->dlsch_ue_specific);
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_PDCCH_TX,0);
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_GENERATE_DLSCH,1);
   // Now scan UE specific DLSCH
   LTE_eNB_DLSCH_t *dlsch0,*dlsch1;
-  for (UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++)
-    {
-      dlsch0 = eNB->dlsch[(uint8_t)UE_id][0]; 
-      dlsch1 = eNB->dlsch[(uint8_t)UE_id][1]; 
+  for (UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++) {
+    dlsch0 = eNB->dlsch[(uint8_t)UE_id][0];
+    dlsch1 = eNB->dlsch[(uint8_t)UE_id][1];
 
-      if ((dlsch0)&&
-	  (dlsch0->rnti>0)&&
+    if ((dlsch0)&&(dlsch0->rnti>0)&&
 #ifdef PHY_TX_THREAD
-	  (dlsch0->active[subframe] == 1)) {
+	(dlsch0->active[subframe] == 1)
 #else
-	  (dlsch0->active == 1)) {
+	(dlsch0->active == 1)
 #endif
+	){
 
-	// get harq_pid
-	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
-        {
-          // generate pdsch
+      // get harq_pid
+      harq_pid = dlsch0->harq_ids[frame%2][subframe];
+      AssertFatal(harq_pid>=0,"harq_pid is negative\n");
 
-          pdsch_procedures(eNB,
-              proc,
-              harq_pid,
-              dlsch0,
-              dlsch1,
-              &eNB->UE_stats[(uint32_t)UE_id],
-              0);
-        }
+      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
+	{
+	  // generate pdsch
+
+	  pdsch_procedures(eNB,
+			   proc,
+			   harq_pid,
+			   dlsch0,
+			   dlsch1,
+			   &eNB->UE_stats[(uint32_t)UE_id],
+			   0);
+	}
 
 
-      }
+    }
 
 
-      else if ((dlsch0)&&
-	       (dlsch0->rnti>0)&&
+    else if ((dlsch0)&&(dlsch0->rnti>0)&&
 #ifdef PHY_TX_THREAD
-	       (dlsch0->active[subframe] == 0)) {
+	     (dlsch0->active[subframe] == 0)
 #else
-           (dlsch0->active == 0)) {
+	     (dlsch0->active == 0)
 #endif
-
-        // clear subframe TX flag since UE is not scheduled for PDSCH in this subframe (so that we don't look for PUCCH later)
-        dlsch0->subframe_tx[subframe]=0;
-      }
+	     ){
+      // clear subframe TX flag since UE is not scheduled for PDSCH in this subframe (so that we don't look for PUCCH later)
+      dlsch0->subframe_tx[subframe]=0;
     }
-  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_GENERATE_DLSCH,0);
 
+    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_GENERATE_DLSCH,0);
 
+  }
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_GENERATE_PHICH,1);
   generate_phich_top(eNB,
@@ -645,38 +609,34 @@ void phy_procedures_eNB_TX(PHY_VARS_eNB *eNB,
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_GENERATE_PHICH,0);
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_TX+(eNB->CC_id),0);
+  if (do_meas==1) stop_meas(&eNB->dlsch_ue_specific);
   if (do_meas==1) stop_meas(&eNB->phy_proc_tx);
   
 }
 
 
-void srs_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc) {
+void srs_procedures(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc) {
 
   LTE_DL_FRAME_PARMS *fp = &eNB->frame_parms;
-  const int subframe = proc->subframe_rx;
-  const int frame = proc->frame_rx;
-
-  int i;
-
-  if (is_srs_occasion_common(fp,frame,subframe)) { 
+  const int       subframe = proc->subframe_rx;
+  const int       frame = proc->frame_rx;
   
-  // Do SRS processing 
-  // check if there is SRS and we have to use shortened format
-  // TODO: check for exceptions in transmission of SRS together with ACK/NACK
-    for (i=0;i<NUMBER_OF_UE_MAX;i++) {
+  int             i;
 
-      if (eNB->soundingrs_ul_config_dedicated[i].active==1) {
+  if (is_srs_occasion_common (fp, frame, subframe)) {
 
+    // Do SRS processing
+    // check if there is SRS and we have to use shortened format
+    // TODO: check for exceptions in transmission of SRS together with ACK/NACK
+    for (i = 0; i < NUMBER_OF_UE_MAX; i++) {
       
-	if (lte_srs_channel_estimation(fp,
-				       &eNB->common_vars,
-				       &eNB->srs_vars[i],
-				       &eNB->soundingrs_ul_config_dedicated[i],
-				       subframe,
-				       0/*eNB_id*/)) {
-	  LOG_E(PHY,"problem processing SRS\n");
+      if (eNB->soundingrs_ul_config_dedicated[i].active == 1) {
+
+
+	if (lte_srs_channel_estimation (fp, &eNB->common_vars, &eNB->srs_vars[i], &eNB->soundingrs_ul_config_dedicated[i], subframe, 0 /*eNB_id */ )) {
+	  LOG_E (PHY, "problem processing SRS\n");
 	}
-	eNB->soundingrs_ul_config_dedicated[i].active=0;
+	eNB->soundingrs_ul_config_dedicated[i].active = 0;
       }
     }
   }
@@ -702,6 +662,7 @@ void fill_sr_indication(PHY_VARS_eNB *eNB,uint16_t rnti,int frame,int subframe,u
   int SNRtimes10 = dB_fixed_times10(stat) - 300;//(10*eNB->measurements.n0_power_dB[0]);
 
 
+
   pdu->ul_cqi_information.tl.tag = NFAPI_UL_CQI_INFORMATION_TAG;
 
   if      (SNRtimes10 < -640) pdu->ul_cqi_information.ul_cqi=0;
@@ -713,7 +674,7 @@ void fill_sr_indication(PHY_VARS_eNB *eNB,uint16_t rnti,int frame,int subframe,u
   pthread_mutex_unlock(&eNB->UL_INFO_mutex);
 }
 
-void uci_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
+void uci_procedures(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc)
 {
   LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
   uint8_t SR_payload = 0,pucch_b0b1[4][2]= {{0,0},{0,0},{0,0},{0,0}},harq_ack[4]={0,0,0,0};
@@ -726,46 +687,45 @@ void uci_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
 
   for (i=0;i<NUMBER_OF_UE_MAX;i++) {
 
+
     uci = &eNB->uci_vars[i];
-    if ((uci->active == 1) &&
-	(uci->frame == frame) &&
-	(uci->subframe == subframe)) {
+    if ((uci->active == 1) && (uci->frame == frame) && (uci->subframe == subframe)) {
 
-      LOG_D(PHY,"Frame %d, subframe %d: Running uci procedures (type %d) for %d \n",frame,subframe,uci->type,i);
-      uci->active=0;
+      LOG_D (PHY, "Frame %d, subframe %d: Running uci procedures (type %d) for %d \n", frame, subframe, uci->type, i);
+      uci->active = 0;
 
       // Null out PUCCH PRBs for noise measurement
-      switch(fp->N_RB_UL) {
+      switch (fp->N_RB_UL) {
       case 6:
-        eNB->rb_mask_ul[0] |= (0x1 | (1<<5)); //position 5
-        break;
+	eNB->rb_mask_ul[0] |= (0x1 | (1 << 5)); //position 5
+	break;
       case 15:
-        eNB->rb_mask_ul[0] |= (0x1 | (1<<14)); // position 14
-        break;
+	eNB->rb_mask_ul[0] |= (0x1 | (1 << 14));        // position 14
+	break;
       case 25:
-        eNB->rb_mask_ul[0] |= (0x1 | (1<<24)); // position 24
-        break;
+	eNB->rb_mask_ul[0] |= (0x1 | (1 << 24));        // position 24
+	break;
       case 50:
-        eNB->rb_mask_ul[0] |= 0x1;
-        eNB->rb_mask_ul[1] |= (1<<17); // position 49 (49-32)
-        break;
+	eNB->rb_mask_ul[0] |= 0x1;
+	eNB->rb_mask_ul[1] |= (1 << 17);        // position 49 (49-32)
+	break;
       case 75:
-        eNB->rb_mask_ul[0] |= 0x1;
-        eNB->rb_mask_ul[2] |= (1<<10); // position 74 (74-64)
-        break;
+	eNB->rb_mask_ul[0] |= 0x1;
+	eNB->rb_mask_ul[2] |= (1 << 10);        // position 74 (74-64)
+	break;
       case 100:
-        eNB->rb_mask_ul[0] |= 0x1;
-        eNB->rb_mask_ul[3] |= (1<<3); // position 99 (99-96)
-        break;
+	eNB->rb_mask_ul[0] |= 0x1;
+	eNB->rb_mask_ul[3] |= (1 << 3); // position 99 (99-96)
+	break;
       default:
-        LOG_E(PHY,"Unknown number for N_RB_UL %d\n",fp->N_RB_UL);
-        break;
+	LOG_E (PHY, "Unknown number for N_RB_UL %d\n", fp->N_RB_UL);
+	break;
       }
       SR_payload = 0;
       switch (uci->type) {
       case SR:
       case HARQ_SR:
-		
+
 	metric_SR = rx_pucch(eNB,
 			     uci->pucch_fmt,
 			     i,
@@ -782,7 +742,7 @@ void uci_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
 	      frame,
 	      subframe,
 	      SR_payload,
-              uci->type,
+	      uci->type,
 	      uci->n_pucch_1_0_sr[0]);
 	if (uci->type == SR) {
 	  if (SR_payload == 1) {
@@ -816,7 +776,7 @@ void uci_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
 	  /* 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;
@@ -851,42 +811,21 @@ void uci_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
 		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;
-	          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);
-	      }
-#else
-	  // 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);
-#endif
-	    
+	  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;
 	    metric[0] = rx_pucch(eNB,
 				 pucch_format1b,
 				 i,
@@ -897,18 +836,36 @@ void uci_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
 				 frame,
 				 subframe,
 				 PUCCH1a_THRES);
-	  } else { //using assigned pucch resources
+	  }
+#else
+	  // 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);
+#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
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+				  ,uci->ue_type
+#endif
+				  );
+	  } 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
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+				      ,uci->ue_type
+#endif
+				      );
 	    for (res=0;res<uci->num_pucch_resources;res++)
 	      metric[res] = rx_pucch(eNB,
 				     uci->pucch_fmt,
@@ -919,14 +876,15 @@ void uci_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
 				     pucch_b0b1[res],
 				     frame,
 				     subframe,
-				     PUCCH1a_THRES);
-	  	  
-	    
-
+				     PUCCH1a_THRES,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+				     ,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
@@ -998,7 +956,7 @@ void uci_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
 	      harq_ack[0] = 4; // DTX
 	      harq_ack[1] = 6; // NACK/DTX
 	      harq_ack[2] = 6; // NACK/DTX
-              max_metric = 0;
+	      max_metric = 0;
 	    } 
 	    else {
 	      
@@ -1023,8 +981,8 @@ void uci_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
 		}
 	      } // if (metric[0]==max_metric) {
 	      else if (metric[1]==max_metric) {
-	      
-	        if (pucch_b0b1[1][0] == 1 && pucch_b0b1[1][1] != 1){
+
+		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
@@ -1043,7 +1001,7 @@ void uci_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
 		}
 	      } // if (metric[1]==max_metric) {
 	      else {
-  	        if (pucch_b0b1[2][0] == 1 && pucch_b0b1[2][1] == 1){
+		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
@@ -1068,8 +1026,8 @@ void uci_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
 		  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
@@ -1081,7 +1039,7 @@ void uci_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
 	      harq_ack[1] = 6; // NACK/DTX
 	      harq_ack[2] = 6; // NACK/DTX
 	      harq_ack[3] = 6; // NACK/DTX
-              max_metric = 0;
+	      max_metric = 0;
 	    } else {
 
 	      max_metric = max(metric[0],max(metric[1],max(metric[2],metric[3])));
@@ -1218,36 +1176,31 @@ void uci_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
 	  }
 	  
 #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);
+	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);
+	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
+	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);
+	  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);
 	}
       }
     }
   }
 }
 
-void pusch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
+void pusch_procedures(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc)
 {
   uint32_t ret=0,i;
   uint32_t harq_pid;
@@ -1261,23 +1214,27 @@ void pusch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
   
   harq_pid = subframe2harq_pid(&eNB->frame_parms,frame,subframe);
 
-  for (i=0; i<NUMBER_OF_UE_MAX; i++) {
+
+  for (i = 0; i < NUMBER_OF_UE_MAX; i++) {
     ulsch = eNB->ulsch[i];
+    if (ulsch->ue_type > 0) harq_pid = 0;
+
     ulsch_harq = ulsch->harq_processes[harq_pid];
+
     if (ulsch->rnti>0) LOG_D(PHY,"eNB->ulsch[%d]->harq_processes[harq_pid:%d] SFN/SF:%04d%d: PUSCH procedures, UE %d/%x ulsch_harq[status:%d SFN/SF:%04d%d handled:%d]\n",
 			     i, harq_pid, frame,subframe,i,ulsch->rnti,
-                             ulsch_harq->status, ulsch_harq->frame, ulsch_harq->subframe, ulsch_harq->handled);
+			     ulsch_harq->status, ulsch_harq->frame, ulsch_harq->subframe, ulsch_harq->handled);
     
     if ((ulsch) &&
-        (ulsch->rnti>0) &&
-        (ulsch_harq->status == ACTIVE) &&
-	    (ulsch_harq->frame == frame) &&
-	    (ulsch_harq->subframe == subframe) &&
-        (ulsch_harq->handled == 0)) {
+	(ulsch->rnti>0) &&
+	(ulsch_harq->status == ACTIVE) &&
+	(ulsch_harq->frame == frame) &&
+	(ulsch_harq->subframe == subframe) &&
+	(ulsch_harq->handled == 0)) {
       
       // UE has ULSCH scheduling
       for (int rb=0;
-           rb<=ulsch_harq->nb_rb;
+	   rb<=ulsch_harq->nb_rb;
 	   rb++) {
 	int rb2 = rb+ulsch_harq->first_rb;
 	eNB->rb_mask_ul[rb2>>5] |= (1<<(rb2&31));
@@ -1325,40 +1282,40 @@ void pusch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
       stop_meas(&eNB->ulsch_decoding_stats);
       
       LOG_D(PHY,"[eNB %d][PUSCH %d] frame %d subframe %d RNTI %x RX power (%d,%d) N0 (%d,%d) dB ACK (%d,%d), decoding iter %d ulsch_harq->cqi_crc_status:%d ackBits:%d ulsch_decoding_stats[t:%lld max:%lld]\n",
-            eNB->Mod_id,harq_pid,
-            frame,subframe,
-            ulsch->rnti,
-            dB_fixed(eNB->pusch_vars[i]->ulsch_power[0]),
-            dB_fixed(eNB->pusch_vars[i]->ulsch_power[1]),
-            30,//eNB->measurements.n0_power_dB[0],
-            30,//eNB->measurements.n0_power_dB[1],
-            ulsch_harq->o_ACK[0],
-            ulsch_harq->o_ACK[1],
-            ret,
-            ulsch_harq->cqi_crc_status,
-            ulsch_harq->O_ACK,
-            eNB->ulsch_decoding_stats.p_time, eNB->ulsch_decoding_stats.max);
+	    eNB->Mod_id,harq_pid,
+	    frame,subframe,
+	    ulsch->rnti,
+	    dB_fixed(eNB->pusch_vars[i]->ulsch_power[0]),
+	    dB_fixed(eNB->pusch_vars[i]->ulsch_power[1]),
+	    30,//eNB->measurements.n0_power_dB[0],
+	    30,//eNB->measurements.n0_power_dB[1],
+	    ulsch_harq->o_ACK[0],
+	    ulsch_harq->o_ACK[1],
+	    ret,
+	    ulsch_harq->cqi_crc_status,
+	    ulsch_harq->O_ACK,
+	    eNB->ulsch_decoding_stats.p_time, eNB->ulsch_decoding_stats.max);
       
       //compute the expected ULSCH RX power (for the stats)
       ulsch_harq->delta_TF = get_hundred_times_delta_IF_eNB(eNB,i,harq_pid, 0); // 0 means bw_factor is not considered
       
       if (RC.mac != NULL) { /* ulsim dose not use RC.mac context. */
-        if (ulsch_harq->cqi_crc_status == 1) {
+	if (ulsch_harq->cqi_crc_status == 1) {
 #ifdef DEBUG_PHY_PROC
-	//if (((frame%10) == 0) || (frame < 50))
-	print_CQI(ulsch_harq->o,ulsch_harq->uci_format,0,fp->N_RB_DL);
+	  //if (((frame%10) == 0) || (frame < 50))
+	  print_CQI(ulsch_harq->o,ulsch_harq->uci_format,0,fp->N_RB_DL);
 #endif
-          fill_ulsch_cqi_indication(eNB,frame,subframe,ulsch_harq,ulsch->rnti);
-          RC.mac[eNB->Mod_id]->UE_list.UE_sched_ctrl[i].cqi_req_flag &= (~(1 << subframe));
-        } else {
-          if(RC.mac[eNB->Mod_id]->UE_list.UE_sched_ctrl[i].cqi_req_flag & (1 << subframe) ){
-            RC.mac[eNB->Mod_id]->UE_list.UE_sched_ctrl[i].cqi_req_flag &= (~(1 << subframe));
-            RC.mac[eNB->Mod_id]->UE_list.UE_sched_ctrl[i].cqi_req_timer=30;
-            LOG_D(PHY,"Frame %d,Subframe %d, We're supposed to get a cqi here. Set cqi_req_timer to 30.\n",frame,subframe);
-          }
-        }
+	  fill_ulsch_cqi_indication(eNB,frame,subframe,ulsch_harq,ulsch->rnti);
+	  RC.mac[eNB->Mod_id]->UE_list.UE_sched_ctrl[i].cqi_req_flag &= (~(1 << subframe));
+	} else {
+	  if(RC.mac[eNB->Mod_id]->UE_list.UE_sched_ctrl[i].cqi_req_flag & (1 << subframe) ){
+	    RC.mac[eNB->Mod_id]->UE_list.UE_sched_ctrl[i].cqi_req_flag &= (~(1 << subframe));
+	    RC.mac[eNB->Mod_id]->UE_list.UE_sched_ctrl[i].cqi_req_timer=30;
+	    LOG_D(PHY,"Frame %d,Subframe %d, We're supposed to get a cqi here. Set cqi_req_timer to 30.\n",frame,subframe);
+	  }
+	}
       }
-    
+
       if (ret == (1+MAX_TURBO_ITERATIONS)) {
 	T(T_ENB_PHY_ULSCH_UE_NACK, T_INT(eNB->Mod_id), T_INT(frame), T_INT(subframe), T_INT(ulsch->rnti),
 	  T_INT(harq_pid));
@@ -1374,14 +1331,14 @@ void pusch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
 	      ulsch_harq->o_ACK[0],
 	      ulsch_harq->o_ACK[1]);
 	
-        if (ulsch_harq->round >= 3)  {
+	if (ulsch_harq->round >= 3)  {
 	  ulsch_harq->status  = SCH_IDLE;
 	  ulsch_harq->handled = 0;
 	  ulsch->harq_mask   &= ~(1 << harq_pid);
 	  ulsch_harq->round   = 0;
 	}
 
-        MSC_LOG_RX_DISCARDED_MESSAGE(
+	MSC_LOG_RX_DISCARDED_MESSAGE(
 				     MSC_PHY_ENB,MSC_PHY_UE,
 				     NULL,0,
 				     "%05u:%02u ULSCH received rnti %x harq id %u round %d",
@@ -1389,44 +1346,40 @@ void pusch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
 				     ulsch->rnti,harq_pid,
 				     ulsch_harq->round-1
 				     );
-
 	
-        /* Mark the HARQ process to release it later if max transmission reached
-         * (see below).
-         * MAC does not send the max transmission count, we have to deal with it
-         * locally in PHY.
-         */
-        ulsch_harq->handled = 1;
-      }  // ulsch in error
+	/* Mark the HARQ process to release it later if max transmission reached
+	 * (see below).
+	 * MAC does not send the max transmission count, we have to deal with it
+	 * locally in PHY.
+	 */
+	ulsch_harq->handled = 1;
+      }                         // ulsch in error
       else {
 	fill_crc_indication(eNB,i,frame,subframe,0); // indicate ACK to MAC
 	fill_rx_indication(eNB,i,frame,subframe);  // indicate SDU to MAC
+	ulsch_harq->status = SCH_IDLE;
+	ulsch->harq_mask &= ~(1 << harq_pid);
 
-        ulsch_harq->status = SCH_IDLE;
-        ulsch->harq_mask   &= ~(1 << harq_pid);
+	T (T_ENB_PHY_ULSCH_UE_ACK, T_INT (eNB->Mod_id), T_INT (frame), T_INT (subframe), T_INT (ulsch->rnti), T_INT (harq_pid));
 
-        T(T_ENB_PHY_ULSCH_UE_ACK, T_INT(eNB->Mod_id), T_INT(frame), T_INT(subframe), T_INT(ulsch->rnti),
-          T_INT(harq_pid));
-
-
-          MSC_LOG_RX_MESSAGE(
-              MSC_PHY_ENB,MSC_PHY_UE,
-              NULL,0,
-              "%05u:%02u ULSCH received rnti %x harq id %u",
-              frame,subframe,
-              ulsch->rnti,harq_pid
-              );
+	MSC_LOG_RX_MESSAGE(
+			   MSC_PHY_ENB,MSC_PHY_UE,
+			   NULL,0,
+			   "%05u:%02u ULSCH received rnti %x harq id %u",
+			   frame,subframe,
+			   ulsch->rnti,harq_pid
+			   );
 
 
 #ifdef DEBUG_PHY_PROC
 #ifdef DEBUG_ULSCH
-          LOG_D(PHY,"[eNB] Frame %d, Subframe %d : ULSCH SDU (RX harq_pid %d) %d bytes:",frame,subframe,
-              harq_pid,ulsch_harq->TBS>>3);
+	LOG_D(PHY,"[eNB] Frame %d, Subframe %d : ULSCH SDU (RX harq_pid %d) %d bytes:",frame,subframe,
+	      harq_pid,ulsch_harq->TBS>>3);
 
-          for (j=0; j<ulsch_harq->TBS>>3; j++)
-            LOG_T(PHY,"%x.",ulsch->harq_processes[harq_pid]->b[j]);
+	for (j=0; j<ulsch_harq->TBS>>3; j++)
+	  LOG_T(PHY,"%x.",ulsch->harq_processes[harq_pid]->b[j]);
 
-          LOG_T(PHY,"\n");
+	LOG_T(PHY,"\n");
 #endif
 #endif
       }  // ulsch not in error
@@ -1434,41 +1387,40 @@ void pusch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
       if (ulsch_harq->O_ACK>0) fill_ulsch_harq_indication(eNB,ulsch_harq,ulsch->rnti,frame,subframe,ulsch->bundling);
       
       LOG_D(PHY,"[eNB %d] Frame %d subframe %d: received ULSCH harq_pid %d for UE %d, ret = %d, CQI CRC Status %d, ACK %d,%d, ulsch_errors %d/%d\n",
-            eNB->Mod_id,frame,subframe,
-            harq_pid,
-            i,
-            ret,
-            ulsch_harq->cqi_crc_status,
-            ulsch_harq->o_ACK[0],
-            ulsch_harq->o_ACK[1],
-            eNB->UE_stats[i].ulsch_errors[harq_pid],
-            eNB->UE_stats[i].ulsch_decoding_attempts[harq_pid][0]);
+	    eNB->Mod_id,frame,subframe,
+	    harq_pid,
+	    i,
+	    ret,
+	    ulsch_harq->cqi_crc_status,
+	    ulsch_harq->o_ACK[0],
+	    ulsch_harq->o_ACK[1],
+	    eNB->UE_stats[i].ulsch_errors[harq_pid],
+	    eNB->UE_stats[i].ulsch_decoding_attempts[harq_pid][0]);
     } //     if ((ulsch) &&
-      //         (ulsch->rnti>0) &&
-      //         (ulsch_harq->status == ACTIVE))
+    //         (ulsch->rnti>0) &&
+    //         (ulsch_harq->status == ACTIVE))
     else if ((ulsch) &&
-             (ulsch->rnti>0) &&
-             (ulsch_harq->status == ACTIVE) &&
-             (ulsch_harq->frame == frame) &&
-             (ulsch_harq->subframe == subframe) &&
-             (ulsch_harq->handled == 1)) {
-          // this harq process is stale, kill it, this 1024 frames later (10s), consider reducing that
-           ulsch_harq->status = SCH_IDLE;
+	     (ulsch->rnti>0) &&
+	     (ulsch_harq->status == ACTIVE) &&
+	     (ulsch_harq->frame == frame) &&
+	     (ulsch_harq->subframe == subframe) &&
+	     (ulsch_harq->handled == 1)) {
+      // this harq process is stale, kill it, this 1024 frames later (10s), consider reducing that
+      ulsch_harq->status = SCH_IDLE;
       ulsch_harq->handled = 0;
-      ulsch->harq_mask   &= ~(1 << harq_pid);
-      LOG_W(PHY,"Removing stale ULSCH config for UE %x harq_pid %d (harq_mask is now 0x%2.2x)\n",
-            ulsch->rnti, harq_pid, ulsch->harq_mask);
+      ulsch->harq_mask &= ~(1 << harq_pid);
+      LOG_W (PHY, "Removing stale ULSCH config for UE %x harq_pid %d (harq_mask is now 0x%2.2x)\n", ulsch->rnti, harq_pid, ulsch->harq_mask);
     }
   }   //   for (i=0; i<NUMBER_OF_UE_MAX; i++)
 }
 
-extern int oai_exit;
+extern int      oai_exit;
 
-extern void *td_thread(void*);
+extern void    *td_thread (void *);
 
 void init_td_thread(PHY_VARS_eNB *eNB) {
 
-  eNB_proc_t *proc = &eNB->proc;
+  L1_proc_t *proc = &eNB->proc;
 
   proc->tdp.eNB = eNB;
   proc->instance_cnt_td         = -1;
@@ -1482,7 +1434,8 @@ void init_td_thread(PHY_VARS_eNB *eNB) {
 }
 void kill_td_thread(PHY_VARS_eNB *eNB) {
 
-  eNB_proc_t *proc = &eNB->proc;
+  L1_proc_t *proc = &eNB->proc;
+
   proc->instance_cnt_td         = 0;
   pthread_cond_signal(&proc->cond_td);
   
@@ -1491,16 +1444,16 @@ void kill_td_thread(PHY_VARS_eNB *eNB) {
   pthread_cond_destroy( &proc->cond_td );
 }
 
-extern void *te_thread(void*);
+extern void    *te_thread (void *);
 
 void init_te_thread(PHY_VARS_eNB *eNB) {
 
-  eNB_proc_t *proc = &eNB->proc;
+  L1_proc_t *proc = &eNB->proc;
 
   for(int i=0; i<3 ;i++){
     proc->tep[i].eNB = eNB;
     proc->tep[i].instance_cnt_te         = -1;
-      
+
     pthread_mutex_init( &proc->tep[i].mutex_te, NULL);
     pthread_cond_init( &proc->tep[i].cond_te, NULL);
     pthread_attr_init( &proc->tep[i].attr_te);
@@ -1511,7 +1464,7 @@ void init_te_thread(PHY_VARS_eNB *eNB) {
 }
 void kill_te_thread(PHY_VARS_eNB *eNB) {
 
-  eNB_proc_t *proc = &eNB->proc;
+  L1_proc_t *proc = &eNB->proc;
 
   for(int i=0; i<3 ;i++){
     proc->tep[i].instance_cnt_te         = 0;
@@ -1522,16 +1475,22 @@ void kill_te_thread(PHY_VARS_eNB *eNB) {
   }
 }
 
-
-void fill_rx_indication(PHY_VARS_eNB *eNB,int UE_id,int frame,int subframe)
-{
+void fill_rx_indication(PHY_VARS_eNB *eNB,int UE_id,int frame,int subframe) {
   nfapi_rx_indication_pdu_t *pdu;
 
-  int timing_advance_update;
-  int sync_pos;
+  int             timing_advance_update;
+  int             sync_pos;
+
+  uint32_t        harq_pid;
 
-  uint32_t harq_pid = subframe2harq_pid(&eNB->frame_parms,
-					frame,subframe);
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  if (eNB->ulsch[UE_id]->ue_type > 0) harq_pid = 0;
+  else
+#endif
+    {
+      harq_pid = subframe2harq_pid (&eNB->frame_parms,
+				    frame, subframe);
+    }
 
   pthread_mutex_lock(&eNB->UL_INFO_mutex);
 
@@ -1551,32 +1510,51 @@ void fill_rx_indication(PHY_VARS_eNB *eNB,int UE_id,int frame,int subframe)
   sync_pos                               = lte_est_timing_advance_pusch(eNB,UE_id);
   timing_advance_update                  = sync_pos; // - eNB->frame_parms.nb_prefix_samples/4; //to check
 
+
   //  if (timing_advance_update > 10) { dump_ulsch(eNB,frame,subframe,UE_id); exit(-1);}
   //  if (timing_advance_update < -10) { dump_ulsch(eNB,frame,subframe,UE_id); exit(-1);}
   switch (eNB->frame_parms.N_RB_DL) {
-  case 6:   /* nothing to do */          break;
-  case 15:  timing_advance_update /= 2;  break;
-  case 25:  timing_advance_update /= 4;  break;
-  case 50:  timing_advance_update /= 8;  break;
-  case 75:  timing_advance_update /= 12; break;
-  case 100: timing_advance_update /= 16; break;
-  default: abort();
+  case 6:                      /* nothing to do */
+    break;
+  case 15:
+    timing_advance_update /= 2;
+    break;
+  case 25:
+    timing_advance_update /= 4;
+    break;
+  case 50:
+    timing_advance_update /= 8;
+    break;
+  case 75:
+    timing_advance_update /= 12;
+    break;
+  case 100:
+    timing_advance_update /= 16;
+    break;
+  default:
+    abort ();
   }
   // put timing advance command in 0..63 range
   timing_advance_update += 31;
-  if (timing_advance_update < 0)  timing_advance_update = 0;
-  if (timing_advance_update > 63) timing_advance_update = 63;
+  if (timing_advance_update < 0)
+    timing_advance_update = 0;
+  if (timing_advance_update > 63)
+    timing_advance_update = 63;
   pdu->rx_indication_rel8.timing_advance = timing_advance_update;
 
   // estimate UL_CQI for MAC (from antenna port 0 only)
   int SNRtimes10 = dB_fixed_times10(eNB->pusch_vars[UE_id]->ulsch_power[0]) - 300;//(10*eNB->measurements.n0_power_dB[0]);
 
-  if      (SNRtimes10 < -640) pdu->rx_indication_rel8.ul_cqi=0;
-  else if (SNRtimes10 >  635) pdu->rx_indication_rel8.ul_cqi=255;
-  else                        pdu->rx_indication_rel8.ul_cqi=(640+SNRtimes10)/5;
+
+  if (SNRtimes10 < -640)
+    pdu->rx_indication_rel8.ul_cqi = 0;
+  else if (SNRtimes10 > 635)
+    pdu->rx_indication_rel8.ul_cqi = 255;
+  else
+    pdu->rx_indication_rel8.ul_cqi = (640 + SNRtimes10) / 5;
 
   LOG_D(PHY,"[PUSCH %d] Frame %d Subframe %d Filling RX_indication with SNR %d (%d), timing_advance %d (update %d)\n",
-	harq_pid,frame,subframe,SNRtimes10,pdu->rx_indication_rel8.ul_cqi,pdu->rx_indication_rel8.timing_advance,
+		  harq_pid,frame,subframe,SNRtimes10,pdu->rx_indication_rel8.ul_cqi,pdu->rx_indication_rel8.timing_advance,
 	timing_advance_update);
 
   eNB->UL_INFO.rx_ind.rx_indication_body.number_of_pdus++;
@@ -1585,17 +1563,15 @@ void fill_rx_indication(PHY_VARS_eNB *eNB,int UE_id,int frame,int subframe)
 }
 
 /* release the harq if its round is >= 'after_rounds' */
-static void do_release_harq(PHY_VARS_eNB *eNB,int UE_id,int tb,uint16_t frame,uint8_t subframe,uint16_t mask, int after_rounds)
-{
+static void do_release_harq(PHY_VARS_eNB *eNB,int UE_id,int tb,uint16_t frame,uint8_t subframe,uint16_t mask, int after_rounds) {
 
   LTE_eNB_DLSCH_t *dlsch0=NULL,*dlsch1=NULL;
   LTE_DL_eNB_HARQ_t *dlsch0_harq=NULL,*dlsch1_harq=NULL;
   int harq_pid;
   int subframe_tx,frame_tx;
   int M,m;
-
-  AssertFatal(UE_id!=-1,"no existing dlsch context\n");
-  AssertFatal(UE_id<NUMBER_OF_UE_MAX,"returned UE_id %d >= %d(NUMBER_OF_UE_MAX)\n",UE_id,NUMBER_OF_UE_MAX);
+  AssertFatal (UE_id != -1, "no existing dlsch context\n");
+  AssertFatal (UE_id < NUMBER_OF_UE_MAX, "returned UE_id %d >= %d(NUMBER_OF_UE_MAX)\n", UE_id, NUMBER_OF_UE_MAX);
   dlsch0 = eNB->dlsch[UE_id][0];
   dlsch1 = eNB->dlsch[UE_id][1];
 
@@ -1612,27 +1588,27 @@ static void do_release_harq(PHY_VARS_eNB *eNB,int UE_id,int tb,uint16_t frame,ui
 #if T_TRACER
     if (after_rounds != -1) {
       T(T_ENB_PHY_DLSCH_UE_NACK, T_INT(0), T_INT(frame), T_INT(subframe),
-        T_INT(dlsch0->rnti), T_INT(harq_pid));
+	T_INT(dlsch0->rnti), T_INT(harq_pid));
     } else {
       T(T_ENB_PHY_DLSCH_UE_ACK, T_INT(0), T_INT(frame), T_INT(subframe),
-        T_INT(dlsch0->rnti), T_INT(harq_pid));
+	T_INT(dlsch0->rnti), T_INT(harq_pid));
     }
 #endif
 
     if (dlsch0_harq->round >= after_rounds) {
       dlsch0_harq->status = SCH_IDLE;
       /*if ((dlsch1_harq == NULL)||
-	  ((dlsch1_harq!=NULL)&&
-	   (dlsch1_harq->status == SCH_IDLE)))*/
+	((dlsch1_harq!=NULL)&&
+	(dlsch1_harq->status == SCH_IDLE)))*/
       dlsch0->harq_mask   &= ~(1<<harq_pid);
     }
     LOG_D(PHY,"Frame %d, subframe %d: Releasing harq %d for UE %x\n",frame,subframe,harq_pid,dlsch0->rnti);
 
   }
   else { // release all processes in the bundle that was acked, based on mask
-         // This is at most 4 for multiplexing and 9 for bundling/special bundling
+    // This is at most 4 for multiplexing and 9 for bundling/special bundling
     M=ul_ACK_subframe2_M(&eNB->frame_parms,
-                         subframe);
+			 subframe);
 
     for (m=0; m<M; m++) {
       subframe_tx = ul_ACK_subframe2_dl_subframe(&eNB->frame_parms,
@@ -1640,36 +1616,36 @@ static void do_release_harq(PHY_VARS_eNB *eNB,int UE_id,int tb,uint16_t frame,ui
 						 m);
       frame_tx = ul_ACK_subframe2_dl_frame(&eNB->frame_parms,frame,subframe,subframe_tx);
       if (((1<<m)&mask) > 0) {
-          harq_pid = dlsch0->harq_ids[frame_tx%2][subframe_tx];
+	harq_pid = dlsch0->harq_ids[frame_tx%2][subframe_tx];
 	if ((harq_pid>=0) && (harq_pid<dlsch0->Mdlharq)) {
 	  dlsch0_harq     = dlsch0->harq_processes[harq_pid];
 	  dlsch1_harq     = dlsch1->harq_processes[harq_pid];
 	  AssertFatal(dlsch0_harq!=NULL,"dlsch0_harq is null\n");
-      
+
 #if T_TRACER
-          if (after_rounds != -1) {
-            T(T_ENB_PHY_DLSCH_UE_NACK, T_INT(0), T_INT(frame), T_INT(subframe),
-              T_INT(dlsch0->rnti), T_INT(harq_pid));
-          } else {
-            T(T_ENB_PHY_DLSCH_UE_ACK, T_INT(0), T_INT(frame), T_INT(subframe),
-              T_INT(dlsch0->rnti), T_INT(harq_pid));
-          }
+	  if (after_rounds != -1) {
+	    T(T_ENB_PHY_DLSCH_UE_NACK, T_INT(0), T_INT(frame), T_INT(subframe),
+	      T_INT(dlsch0->rnti), T_INT(harq_pid));
+	  } else {
+	    T(T_ENB_PHY_DLSCH_UE_ACK, T_INT(0), T_INT(frame), T_INT(subframe),
+	      T_INT(dlsch0->rnti), T_INT(harq_pid));
+	  }
 #endif
-          if (dlsch0_harq->round >= after_rounds) {
+	  if (dlsch0_harq->round >= after_rounds) {
 	    dlsch0_harq->status = SCH_IDLE;
 	    if ((dlsch1_harq == NULL)||
-	        ((dlsch1_harq!=NULL)&&
-	         (dlsch1_harq->status == SCH_IDLE)))
+		((dlsch1_harq!=NULL)&&
+		 (dlsch1_harq->status == SCH_IDLE)))
 	      dlsch0->harq_mask   &= ~(1<<harq_pid);
-          }
+	  }
 	}
+
       }
     }
   }
 }
 
-static void release_harq(PHY_VARS_eNB *eNB,int UE_id,int tb,uint16_t frame,uint8_t subframe,uint16_t mask, int is_ack)
-{
+static void release_harq(PHY_VARS_eNB *eNB,int UE_id,int tb,uint16_t frame,uint8_t subframe,uint16_t mask, int is_ack) {
   /* Maximum number of DL transmissions = 4.
    * TODO: get the value from configuration.
    * If is_ack is true then we release immediately. The value -1 can be used for that.
@@ -1694,7 +1670,12 @@ int getM(PHY_VARS_eNB *eNB,int frame,int subframe) {
 					       subframe,
 					       m);
     frame_tx =  ul_ACK_subframe2_dl_frame(&eNB->frame_parms,frame,
-                                            subframe,subframe_tx);
+                                          subframe,subframe_tx);
+    if (dlsch0 == NULL || dlsch1 == NULL) {
+        LOG_E(PHY, "dlsch0 and/or dlsch1 NULL, getM frame %i, subframe %i\n",frame,subframe);
+	return Mtx;
+    }
+
     harq_pid = dlsch0->harq_ids[frame_tx%2][subframe_tx];
 
     if (harq_pid>=0 && harq_pid<10) {
@@ -1705,36 +1686,39 @@ int getM(PHY_VARS_eNB *eNB,int frame,int subframe) {
 	  (dlsch1_harq!=NULL && dlsch1_harq->status == ACTIVE)) Mtx ++;
     }
   }
-  return(Mtx);
+  return (Mtx);
 }
 
 
-void fill_ulsch_cqi_indication(PHY_VARS_eNB *eNB,uint16_t frame,uint8_t subframe,LTE_UL_eNB_HARQ_t *ulsch_harq,uint16_t rnti) {
+void fill_ulsch_cqi_indication (PHY_VARS_eNB * eNB, uint16_t frame, uint8_t subframe, LTE_UL_eNB_HARQ_t * ulsch_harq, uint16_t rnti) {
 
-  pthread_mutex_lock(&eNB->UL_INFO_mutex);
-  nfapi_cqi_indication_pdu_t *pdu         = &eNB->UL_INFO.cqi_ind.cqi_pdu_list[eNB->UL_INFO.cqi_ind.number_of_cqis];
+  pthread_mutex_lock (&eNB->UL_INFO_mutex);
+  nfapi_cqi_indication_pdu_t *pdu = &eNB->UL_INFO.cqi_ind.cqi_pdu_list[eNB->UL_INFO.cqi_ind.number_of_cqis];
   nfapi_cqi_indication_raw_pdu_t *raw_pdu = &eNB->UL_INFO.cqi_ind.cqi_raw_pdu_list[eNB->UL_INFO.cqi_ind.number_of_cqis];
 
   pdu->rx_ue_information.tl.tag          = NFAPI_RX_UE_INFORMATION_TAG;
   pdu->rx_ue_information.rnti = rnti;
-  if (ulsch_harq->cqi_crc_status != 1) pdu->cqi_indication_rel9.data_offset = 0;
-  else               pdu->cqi_indication_rel9.data_offset = 1; // fill in after all cqi_indications have been generated when non-zero
+  if (ulsch_harq->cqi_crc_status != 1)
+    pdu->cqi_indication_rel9.data_offset = 0;
+  else
+    pdu->cqi_indication_rel9.data_offset = 1;   // fill in after all cqi_indications have been generated when non-zero
 
   // by default set O to rank 1 value
+
   pdu->cqi_indication_rel9.tl.tag = NFAPI_CQI_INDICATION_REL9_TAG;
   pdu->cqi_indication_rel9.length = (ulsch_harq->Or1>>3) + ((ulsch_harq->Or1&7) > 0 ? 1 : 0);
   pdu->cqi_indication_rel9.ri[0]  = 0;
-
   // if we have RI bits, set them and if rank2 overwrite O
-  if (ulsch_harq->O_RI>0) {
+  if (ulsch_harq->O_RI > 0) {
     pdu->cqi_indication_rel9.ri[0] = ulsch_harq->o_RI[0];
-    if (ulsch_harq->o_RI[0] == 2)   pdu->cqi_indication_rel9.length = (ulsch_harq->Or2>>3) + ((ulsch_harq->Or2&7) > 0 ? 1 : 0);
+    if (ulsch_harq->o_RI[0] == 2)
+      pdu->cqi_indication_rel9.length = (ulsch_harq->Or2 >> 3) + ((ulsch_harq->Or2 & 7) > 0 ? 1 : 0);
     pdu->cqi_indication_rel9.timing_advance = 0;
   }
   
   pdu->cqi_indication_rel9.number_of_cc_reported = 1;
-  pdu->ul_cqi_information.channel = 1; // PUSCH
-  memcpy((void*)raw_pdu->pdu,ulsch_harq->o,pdu->cqi_indication_rel9.length);
+  pdu->ul_cqi_information.channel = 1;  // PUSCH
+  memcpy ((void *) raw_pdu->pdu, ulsch_harq->o, pdu->cqi_indication_rel9.length);
   eNB->UL_INFO.cqi_ind.number_of_cqis++;
   LOG_D(PHY,"eNB->UL_INFO.cqi_ind.number_of_cqis:%d\n", eNB->UL_INFO.cqi_ind.number_of_cqis);
 
@@ -1742,8 +1726,8 @@ void fill_ulsch_cqi_indication(PHY_VARS_eNB *eNB,uint16_t frame,uint8_t subframe
 
 }
 
-void fill_ulsch_harq_indication(PHY_VARS_eNB *eNB,LTE_UL_eNB_HARQ_t *ulsch_harq,uint16_t rnti, int frame,int subframe,int bundling)
-{
+void fill_ulsch_harq_indication (PHY_VARS_eNB * eNB, LTE_UL_eNB_HARQ_t * ulsch_harq, uint16_t rnti, int frame, int subframe, int bundling) {
+
   int UE_id = find_dlsch(rnti,eNB,SEARCH_EXIST);
   if( (UE_id<0) || (UE_id>=NUMBER_OF_UE_MAX) ){
     LOG_E(PHY,"illegal UE_id found!!! rnti %04x UE_id %d\n",rnti,UE_id);
@@ -1771,24 +1755,24 @@ void fill_ulsch_harq_indication(PHY_VARS_eNB *eNB,LTE_UL_eNB_HARQ_t *ulsch_harq,
     pdu->harq_indication_fdd_rel13.mode = 0;
     pdu->harq_indication_fdd_rel13.number_of_ack_nack = ulsch_harq->O_ACK;
 
-    for (i=0;i<ulsch_harq->O_ACK;i++) {
-      AssertFatal(ulsch_harq->o_ACK[i] == 0 || ulsch_harq->o_ACK[i] == 1, "harq_ack[%d] is %d, should be 1,2 or 4\n",i,ulsch_harq->o_ACK[i]);
+    for (i = 0; i < ulsch_harq->O_ACK; i++) {
+      AssertFatal (ulsch_harq->o_ACK[i] == 0 || ulsch_harq->o_ACK[i] == 1, "harq_ack[%d] is %d, should be 1,2 or 4\n", i, ulsch_harq->o_ACK[i]);
 
-      pdu->harq_indication_fdd_rel13.harq_tb_n[i] = 2-ulsch_harq->o_ACK[i];
+      pdu->harq_indication_fdd_rel13.harq_tb_n[i] = 2 - ulsch_harq->o_ACK[i];
       // release DLSCH if needed
+
       release_harq(eNB,UE_id,i,frame,subframe,0xffff, ulsch_harq->o_ACK[i] == 1);
+
     }
-  }
-  else { // TDD
-    M=ul_ACK_subframe2_M(&eNB->frame_parms,
-			 subframe);
+  } else {                      // TDD
+    M = ul_ACK_subframe2_M (&eNB->frame_parms, subframe);
 
     pdu->harq_indication_tdd_rel13.tl.tag = NFAPI_HARQ_INDICATION_TDD_REL13_TAG;
     pdu->harq_indication_tdd_rel13.mode = 1-bundling;
     pdu->harq_indication_tdd_rel13.number_of_ack_nack = ulsch_harq->O_ACK;
 
-    for (i=0;i<ulsch_harq->O_ACK;i++) {
-      AssertFatal(ulsch_harq->o_ACK[i] == 0 || ulsch_harq->o_ACK[i] == 1, "harq_ack[%d] is %d, should be 1,2 or 4\n",i,ulsch_harq->o_ACK[i]);
+    for (i = 0; i < ulsch_harq->O_ACK; i++) {
+      AssertFatal (ulsch_harq->o_ACK[i] == 0 || ulsch_harq->o_ACK[i] == 1, "harq_ack[%d] is %d, should be 1,2 or 4\n", i, ulsch_harq->o_ACK[i]);
 
       pdu->harq_indication_tdd_rel13.harq_data[0].bundling.value_0 = 2-ulsch_harq->o_ACK[i];
       // release DLSCH if needed
@@ -1804,22 +1788,17 @@ void fill_ulsch_harq_indication(PHY_VARS_eNB *eNB,LTE_UL_eNB_HARQ_t *ulsch_harq,
 	release_harq(eNB,UE_id,0,frame,subframe,1<<i, ulsch_harq->o_ACK[i] == 1);
 	release_harq(eNB,UE_id,1,frame,subframe,1<<i, ulsch_harq->o_ACK[i] == 1);
       }
-    }	
+    }
   }
 
   //LOG_E(PHY,"eNB->UL_INFO.harq_ind.harq_indication_body.number_of_harqs:%d\n", eNB->UL_INFO.harq_ind.harq_indication_body.number_of_harqs);
   eNB->UL_INFO.harq_ind.harq_indication_body.number_of_harqs++;
 
   pthread_mutex_unlock(&eNB->UL_INFO_mutex);
+
 }
 
-void fill_uci_harq_indication(PHY_VARS_eNB *eNB,
-			      LTE_eNB_UCI *uci,
-			      int frame,
-			      int subframe,
-			      uint8_t *harq_ack,
-			      uint8_t tdd_mapping_mode,
-			      uint16_t tdd_multiplexing_mask) {
+void fill_uci_harq_indication (PHY_VARS_eNB * eNB, LTE_eNB_UCI * uci, int frame, int subframe, uint8_t * harq_ack, uint8_t tdd_mapping_mode, uint16_t tdd_multiplexing_mask) {
 
   int UE_id=find_dlsch(uci->rnti,eNB,SEARCH_EXIST);
   //AssertFatal(UE_id>=0,"UE_id doesn't exist rnti:%x\n", uci->rnti);
@@ -1848,11 +1827,15 @@ void fill_uci_harq_indication(PHY_VARS_eNB *eNB,
   pdu->ul_cqi_information.tl.tag = NFAPI_UL_CQI_INFORMATION_TAG;
   int SNRtimes10 = dB_fixed_times10(uci->stat) - 300;//(10*eNB->measurements.n0_power_dB[0]);
 
-  if (SNRtimes10 < -100) LOG_D(PHY,"uci->stat %d \n",uci->stat);
+  if (SNRtimes10 < -100)
+    LOG_I (PHY, "uci->stat %d \n", uci->stat);
 
-  if      (SNRtimes10 < -640) pdu->ul_cqi_information.ul_cqi=0;
-  else if (SNRtimes10 >  635) pdu->ul_cqi_information.ul_cqi=255;
-  else                        pdu->ul_cqi_information.ul_cqi=(640+SNRtimes10)/5;
+  if (SNRtimes10 < -640)
+    pdu->ul_cqi_information.ul_cqi = 0;
+  else if (SNRtimes10 > 635)
+    pdu->ul_cqi_information.ul_cqi = 255;
+  else
+    pdu->ul_cqi_information.ul_cqi = (640 + SNRtimes10) / 5;
   pdu->ul_cqi_information.channel = 0;
 
   if (eNB->frame_parms.frame_type == FDD) {
@@ -1861,7 +1844,7 @@ void fill_uci_harq_indication(PHY_VARS_eNB *eNB,
       pdu->harq_indication_fdd_rel13.mode = 0;  
       pdu->harq_indication_fdd_rel13.number_of_ack_nack = 1;
       
-      AssertFatal(harq_ack[0] == 1 || harq_ack[0] == 2 || harq_ack[0] == 4, "harq_ack[0] is %d, should be 1,2 or 4\n",harq_ack[0]);
+      AssertFatal (harq_ack[0] == 1 || harq_ack[0] == 2 || harq_ack[0] == 4, "harq_ack[0] is %d, should be 1,2 or 4\n", harq_ack[0]);
       pdu->harq_indication_fdd_rel13.harq_tb_n[0] = harq_ack[0];
       // release DLSCH if needed
       release_harq(eNB,UE_id,0,frame,subframe,0xffff, harq_ack[0] == 1);
@@ -1870,10 +1853,10 @@ void fill_uci_harq_indication(PHY_VARS_eNB *eNB,
       pdu->harq_indication_fdd_rel13.tl.tag = NFAPI_HARQ_INDICATION_FDD_REL13_TAG;
       pdu->harq_indication_fdd_rel13.mode = 0;  
       pdu->harq_indication_fdd_rel13.number_of_ack_nack = 2;
-      AssertFatal(harq_ack[0] == 1 || harq_ack[0] == 2 || harq_ack[1] == 4, "harq_ack[0] is %d, should be 0,1 or 4\n",harq_ack[0]);
-      AssertFatal(harq_ack[1] == 1 || harq_ack[1] == 2 || harq_ack[1] == 4, "harq_ack[1] is %d, should be 0,1 or 4\n",harq_ack[1]);
+      AssertFatal (harq_ack[0] == 1 || harq_ack[0] == 2 || harq_ack[1] == 4, "harq_ack[0] is %d, should be 0,1 or 4\n", harq_ack[0]);
+      AssertFatal (harq_ack[1] == 1 || harq_ack[1] == 2 || harq_ack[1] == 4, "harq_ack[1] is %d, should be 0,1 or 4\n", harq_ack[1]);
       pdu->harq_indication_fdd_rel13.harq_tb_n[0] = harq_ack[0];
-      pdu->harq_indication_fdd_rel13.harq_tb_n[1] = harq_ack[1]; 
+      pdu->harq_indication_fdd_rel13.harq_tb_n[1] = harq_ack[1];
       // release DLSCH if needed
       release_harq(eNB,UE_id,0,frame,subframe,0xffff, harq_ack[0] == 1);
       release_harq(eNB,UE_id,1,frame,subframe,0xffff, harq_ack[1] == 1);
@@ -1881,18 +1864,15 @@ void fill_uci_harq_indication(PHY_VARS_eNB *eNB,
     else AssertFatal(1==0,"only format 1a/b for now, received %d\n",uci->pucch_fmt); 
   }
   else { // TDD
-
-    AssertFatal(tdd_mapping_mode==0 || tdd_mapping_mode==1 || tdd_mapping_mode==2,
-		"Illegal tdd_mapping_mode %d\n",tdd_mapping_mode);
-
+    AssertFatal (tdd_mapping_mode == 0 || tdd_mapping_mode == 1 || tdd_mapping_mode == 2, "Illegal tdd_mapping_mode %d\n", tdd_mapping_mode);
     pdu->harq_indication_tdd_rel13.tl.tag = NFAPI_HARQ_INDICATION_TDD_REL13_TAG;
     pdu->harq_indication_tdd_rel13.mode = tdd_mapping_mode;  
     LOG_D(PHY,"%s(eNB, uci_harq format %d, rnti:%04x, frame:%d, subframe:%d, tdd_mapping_mode:%d) harq_ack[0]:%d harq_ack[1]:%d\n", __FUNCTION__, uci->pucch_fmt,uci->rnti, frame, subframe, tdd_mapping_mode,harq_ack[0],harq_ack[1]);
     switch (tdd_mapping_mode) {
-    case 0: // bundling
+    case 0:                    // bundling
 
       if (uci->pucch_fmt == pucch_format1a) {
-        pdu->harq_indication_tdd_rel13.tl.tag = NFAPI_HARQ_INDICATION_TDD_REL13_TAG;
+	pdu->harq_indication_tdd_rel13.tl.tag = NFAPI_HARQ_INDICATION_TDD_REL13_TAG;
 	pdu->harq_indication_tdd_rel13.number_of_ack_nack = 1;	
 	LOG_D(PHY,"bundling, pucch1a, number of ack nack %d\n",pdu->harq_indication_tdd_rel13.number_of_ack_nack);
 	AssertFatal(harq_ack[0] == 1 || harq_ack[0] == 2 || harq_ack[0] == 4, "harq_ack[0] is %d, should be 1,2 or 4\n",harq_ack[0]);
@@ -1904,7 +1884,7 @@ void fill_uci_harq_indication(PHY_VARS_eNB *eNB,
 	pdu->harq_indication_tdd_rel13.number_of_ack_nack = 2;
 	AssertFatal(harq_ack[0] == 1 || harq_ack[0] == 2 || harq_ack[1] == 4, "harq_ack[0] is %d, should be 0,1 or 4\n",harq_ack[0]);
 	AssertFatal(harq_ack[1] == 1 || harq_ack[1] == 2 || harq_ack[1] == 4, "harq_ack[1] is %d, should be 0,1 or 4\n",harq_ack[1]);
-        pdu->harq_indication_tdd_rel13.tl.tag = NFAPI_HARQ_INDICATION_TDD_REL13_TAG;
+	pdu->harq_indication_tdd_rel13.tl.tag = NFAPI_HARQ_INDICATION_TDD_REL13_TAG;
 	pdu->harq_indication_tdd_rel13.harq_data[0].bundling.value_0 = harq_ack[0];
 	pdu->harq_indication_tdd_rel13.harq_data[1].bundling.value_0 = harq_ack[1]; 
 	// release all DLSCH if needed
@@ -1912,11 +1892,11 @@ void fill_uci_harq_indication(PHY_VARS_eNB *eNB,
 	release_harq(eNB,UE_id,1,frame,subframe,0xffff, harq_ack[1] == 1);
       }
       break;
-    case 1: // multiplexing
-      AssertFatal(uci->pucch_fmt == pucch_format1b,"uci->pucch_format %d is not format1b\n",uci->pucch_fmt);
+    case 1:                    // multiplexing
+      AssertFatal (uci->pucch_fmt == pucch_format1b, "uci->pucch_format %d is not format1b\n", uci->pucch_fmt);
       
       if (uci->num_pucch_resources == 1 && uci->pucch_fmt == pucch_format1a) {
-        pdu->harq_indication_tdd_rel13.tl.tag = NFAPI_HARQ_INDICATION_TDD_REL13_TAG;
+	pdu->harq_indication_tdd_rel13.tl.tag = NFAPI_HARQ_INDICATION_TDD_REL13_TAG;
 	pdu->harq_indication_tdd_rel13.number_of_ack_nack = 1;	
 	AssertFatal(harq_ack[0] == 1 || harq_ack[0] == 2 || harq_ack[0] == 4, "harq_ack[0] is %d, should be 1,2 or 4\n",harq_ack[0]);
 	pdu->harq_indication_tdd_rel13.harq_data[0].multiplex.value_0 = harq_ack[0];
@@ -1924,7 +1904,7 @@ void fill_uci_harq_indication(PHY_VARS_eNB *eNB,
 	release_harq(eNB,UE_id,0,frame,subframe,0xffff, harq_ack[0] == 1);
       }
       else if (uci->num_pucch_resources == 1 && uci->pucch_fmt == pucch_format1b) {
-        pdu->harq_indication_tdd_rel13.tl.tag = NFAPI_HARQ_INDICATION_TDD_REL13_TAG;
+	pdu->harq_indication_tdd_rel13.tl.tag = NFAPI_HARQ_INDICATION_TDD_REL13_TAG;
 	pdu->harq_indication_tdd_rel13.number_of_ack_nack = 2;
 	AssertFatal(harq_ack[0] == 1 || harq_ack[0] == 2 || harq_ack[1] == 4, "harq_ack[0] is %d, should be 0,1 or 4\n",harq_ack[0]);
 	AssertFatal(harq_ack[1] == 1 || harq_ack[1] == 2 || harq_ack[1] == 4, "harq_ack[1] is %d, should be 0,1 or 4\n",harq_ack[1]);
@@ -1935,7 +1915,7 @@ void fill_uci_harq_indication(PHY_VARS_eNB *eNB,
 	release_harq(eNB,UE_id,1,frame,subframe,0xffff, harq_ack[1] == 1);
       }
       else { // num_pucch_resources (M) > 1
-        pdu->harq_indication_tdd_rel13.tl.tag = NFAPI_HARQ_INDICATION_TDD_REL13_TAG;
+	pdu->harq_indication_tdd_rel13.tl.tag = NFAPI_HARQ_INDICATION_TDD_REL13_TAG;
 	pdu->harq_indication_tdd_rel13.number_of_ack_nack = uci->num_pucch_resources;
 
 	pdu->harq_indication_tdd_rel13.harq_data[0].multiplex.value_0 = harq_ack[0];
@@ -1957,54 +1937,52 @@ void fill_uci_harq_indication(PHY_VARS_eNB *eNB,
       switch (harq_ack[0]) {
       case 0:
       case 4:
-          pdu->harq_indication_tdd_rel13.harq_data[0].bundling.value_0 = 0;
-        /* TODO: release_harq here? this whole code looks suspicious */
+	pdu->harq_indication_tdd_rel13.harq_data[0].bundling.value_0 = 0;
+	/* TODO: release_harq here? this whole code looks suspicious */
 	break;
       case 1: // check if M=1,4,7
 	if (uci->num_pucch_resources == 1 || uci->num_pucch_resources == 4 ||
 	    tdd_config5_sf2scheds == 1 || tdd_config5_sf2scheds == 4 || tdd_config5_sf2scheds == 7) {
-	    pdu->harq_indication_tdd_rel13.harq_data[0].bundling.value_0 = 1;
+	  pdu->harq_indication_tdd_rel13.harq_data[0].bundling.value_0 = 1;
 	  release_harq(eNB,UE_id,0,frame,subframe,0xffff, 1);
 	  release_harq(eNB,UE_id,1,frame,subframe,0xffff, 1);
 	}else{
-          pdu->harq_indication_tdd_rel13.harq_data[0].bundling.value_0 = 0;
+	  pdu->harq_indication_tdd_rel13.harq_data[0].bundling.value_0 = 0;
 	}
 	break;
       case 2: // check if M=2,5,8
 	if (uci->num_pucch_resources == 2 || tdd_config5_sf2scheds == 2 || 
 	    tdd_config5_sf2scheds == 5 || tdd_config5_sf2scheds == 8) {
-	    pdu->harq_indication_tdd_rel13.harq_data[0].bundling.value_0 = 1;
+	  pdu->harq_indication_tdd_rel13.harq_data[0].bundling.value_0 = 1;
 	  release_harq(eNB,UE_id,0,frame,subframe,0xffff, 1);
 	  release_harq(eNB,UE_id,1,frame,subframe,0xffff, 1);
 	}else{
-          pdu->harq_indication_tdd_rel13.harq_data[0].bundling.value_0 = 0;
+	  pdu->harq_indication_tdd_rel13.harq_data[0].bundling.value_0 = 0;
 	}
 	break;
       case 3: // check if M=3,6,9
 	if (uci->num_pucch_resources == 3 || tdd_config5_sf2scheds == 3 || 
 	    tdd_config5_sf2scheds == 6 || tdd_config5_sf2scheds == 9) {
-	    pdu->harq_indication_tdd_rel13.harq_data[0].bundling.value_0 = 1;
+	  pdu->harq_indication_tdd_rel13.harq_data[0].bundling.value_0 = 1;
 	  release_harq(eNB,UE_id,0,frame,subframe,0xffff, 1);
 	  release_harq(eNB,UE_id,1,frame,subframe,0xffff, 1);
 	}else{
-          pdu->harq_indication_tdd_rel13.harq_data[0].bundling.value_0 = 0;
+	  pdu->harq_indication_tdd_rel13.harq_data[0].bundling.value_0 = 0;
 	}
 	break;
       }
       break;
 
     }
-  } //TDD
+  }                             //TDD
 
 
   eNB->UL_INFO.harq_ind.harq_indication_body.number_of_harqs++;
   LOG_D(PHY,"Incremented eNB->UL_INFO.harq_ind.harq_indication_body.number_of_harqs:%d\n", eNB->UL_INFO.harq_ind.harq_indication_body.number_of_harqs);
   pthread_mutex_unlock(&eNB->UL_INFO_mutex);  
-
 }
 
-
-void fill_crc_indication(PHY_VARS_eNB *eNB,int UE_id,int frame,int subframe,uint8_t crc_flag) {
+void fill_crc_indication (PHY_VARS_eNB * eNB, int UE_id, int frame, int subframe, uint8_t crc_flag) {
 
   pthread_mutex_lock(&eNB->UL_INFO_mutex);
   nfapi_crc_indication_pdu_t *pdu =   &eNB->UL_INFO.crc_ind.crc_indication_body.crc_pdu_list[eNB->UL_INFO.crc_ind.crc_indication_body.number_of_crcs];
@@ -2013,8 +1991,9 @@ void fill_crc_indication(PHY_VARS_eNB *eNB,int UE_id,int frame,int subframe,uint
   eNB->UL_INFO.crc_ind.header.message_id              = NFAPI_CRC_INDICATION;
   eNB->UL_INFO.crc_ind.crc_indication_body.tl.tag     = NFAPI_CRC_INDICATION_BODY_TAG;
 
-  pdu->instance_length                                = 0; // don't know what to do with this
+  pdu->instance_length = 0;     // don't know what to do with this
   //  pdu->rx_ue_information.handle                       = handle;
+
   pdu->rx_ue_information.tl.tag                       = NFAPI_RX_UE_INFORMATION_TAG;
   pdu->rx_ue_information.rnti                         = eNB->ulsch[UE_id]->rnti;
   pdu->crc_indication_rel8.tl.tag                     = NFAPI_CRC_INDICATION_REL8_TAG;
@@ -2027,17 +2006,16 @@ void fill_crc_indication(PHY_VARS_eNB *eNB,int UE_id,int frame,int subframe,uint
   pthread_mutex_unlock(&eNB->UL_INFO_mutex);
 }
 
-void phy_procedures_eNB_uespec_RX(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
+void phy_procedures_eNB_uespec_RX(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc)
 {
   //RX processing for ue-specific resources (i
-  LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
-  const int subframe = proc->subframe_rx;
-  const int frame    = proc->frame_rx;
+  LTE_DL_FRAME_PARMS *fp = &eNB->frame_parms;
+  const int       subframe = proc->subframe_rx;
+  const int       frame = proc->frame_rx;
 
   /* TODO: use correct rxdata */
-  T(T_ENB_PHY_INPUT_SIGNAL, T_INT(eNB->Mod_id), T_INT(frame), T_INT(subframe), T_INT(0),
-    T_BUFFER(&eNB->RU_list[0]->common.rxdata[0][subframe*eNB->frame_parms.samples_per_tti],
-             eNB->frame_parms.samples_per_tti * 4));
+  T (T_ENB_PHY_INPUT_SIGNAL, T_INT (eNB->Mod_id), T_INT (frame), T_INT (subframe), T_INT (0),
+     T_BUFFER (&eNB->RU_list[0]->common.rxdata[0][subframe * eNB->frame_parms.samples_per_tti], eNB->frame_parms.samples_per_tti * 4));
 
   if ((fp->frame_type == TDD) && (subframe_select(fp,subframe)!=SF_UL)) return;
 
@@ -2045,32 +2023,28 @@ void phy_procedures_eNB_uespec_RX(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_RX_UESPEC, 1 );
 
-  LOG_D(PHY,"[eNB %d] Frame %d: Doing phy_procedures_eNB_uespec_RX(%d)\n",eNB->Mod_id,frame, subframe);
+  LOG_D (PHY, "[eNB %d] Frame %d: Doing phy_procedures_eNB_uespec_RX(%d)\n", eNB->Mod_id, frame, subframe);
 
-  eNB->rb_mask_ul[0]=0;
-  eNB->rb_mask_ul[1]=0;
-  eNB->rb_mask_ul[2]=0;
-  eNB->rb_mask_ul[3]=0;
+  eNB->rb_mask_ul[0] = 0;
+  eNB->rb_mask_ul[1] = 0;
+  eNB->rb_mask_ul[2] = 0;
+  eNB->rb_mask_ul[3] = 0;
 
   // Fix me here, these should be locked
   eNB->UL_INFO.rx_ind.rx_indication_body.number_of_pdus  = 0;
   eNB->UL_INFO.crc_ind.crc_indication_body.number_of_crcs = 0;
-
   // Call SRS first since all others depend on presence of SRS or lack thereof
-  srs_procedures(eNB,proc);
+  srs_procedures (eNB, proc);
 
   eNB->first_run_I0_measurements = 0;
 
-  uci_procedures(eNB,proc);
+  uci_procedures (eNB, proc);
 
   if (nfapi_mode == 0 || nfapi_mode == 1) { // If PNF or monolithic
     pusch_procedures(eNB,proc);
   }
 
-  lte_eNB_I0_measurements(eNB,
-                          subframe,
-                          0,
-                          eNB->first_run_I0_measurements);
+  lte_eNB_I0_measurements (eNB, subframe, 0, eNB->first_run_I0_measurements);
 
   int min_I0=1000,max_I0=0;
   if ((frame==0) && (subframe==4)) { 
@@ -2079,9 +2053,9 @@ void phy_procedures_eNB_uespec_RX(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
  
       if (eNB->measurements.n0_subband_power_tot_dB[i]<min_I0) min_I0 = eNB->measurements.n0_subband_power_tot_dB[i];
       if (eNB->measurements.n0_subband_power_tot_dB[i]>max_I0) max_I0 = eNB->measurements.n0_subband_power_tot_dB[i];
+
     }
-    LOG_I(PHY,"max_I0 %d, min_I0 %d\n",max_I0,min_I0);
+    LOG_I (PHY, "max_I0 %d, min_I0 %d\n", max_I0, min_I0);
   }
-
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_RX_UESPEC, 0 );
 }
diff --git a/openair1/SCHED/prach_procedures.c b/openair1/SCHED/prach_procedures.c
index 8664dffc36c2a5c8b881f8afbbf578a3c056bb1e..13cf919264e744bcbc464662cc8173d8c5b8a4da 100644
--- a/openair1/SCHED/prach_procedures.c
+++ b/openair1/SCHED/prach_procedures.c
@@ -54,7 +54,7 @@ extern uint32_t nfapi_mode;
 extern int oai_nfapi_rach_ind(nfapi_rach_indication_t *rach_ind);
 
 void prach_procedures(PHY_VARS_eNB *eNB
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                       ,
 		      int br_flag
 #endif
@@ -63,7 +63,7 @@ void prach_procedures(PHY_VARS_eNB *eNB
   uint16_t i;
   int frame,subframe;
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   if (br_flag==1) {
     subframe = eNB->proc.subframe_prach_br;
     frame = eNB->proc.frame_prach_br;
@@ -93,7 +93,7 @@ void prach_procedures(PHY_VARS_eNB *eNB
     ru=eNB->RU_list[i];
     for (ru_aa=0,aa=0;ru_aa<ru->nb_rx;ru_aa++,aa++) {
       eNB->prach_vars.rxsigF[0][aa] = eNB->RU_list[i]->prach_rxsigF[ru_aa];
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
       int ce_level;
 
       if (br_flag==1)
@@ -109,7 +109,7 @@ void prach_procedures(PHY_VARS_eNB *eNB
 	   &max_preamble_delay[0],
 	   frame,
 	   0
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 	   ,br_flag
 #endif
 	   );
@@ -121,46 +121,47 @@ void prach_procedures(PHY_VARS_eNB *eNB
         max_preamble_delay[0],
 	eNB->prach_energy_counter);
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   if (br_flag==1) {
-
-    eNB->UL_INFO.rach_ind_br.rach_indication_body.preamble_list                              = eNB->preamble_list_br;
-    int ind=0;
-    int ce_level=0;
-    /* Save for later, it doesn't work 
-    int prach_mask = is_prach_subframe(&eNB->frame_parms,eNB->proc.frame_prach_br,eNB->proc.subframe_prach_br);   
-    for (int ind=0,ce_level=0;ce_level<4;ce_level++) {
-      
-      if ((eNB->frame_parms.prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[ce_level]==1)&&
-	  (prach_mask&(1<<(1+ce_level)) > 0) && // prach is active and CE level has finished its repetitions
-	  (eNB->prach_vars_br.repetition_number[ce_level]==
-	   eNB->frame_parms.prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[ce_level])) {
-    */ 
-    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 + 100)) {
-	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];//
-	eNB->preamble_list_br[ind].preamble_rel8.preamble              = max_preamble[ind];
-	// note: fid is implicitly 0 here, this is the rule for eMTC RA-RNTI from 36.321, Section 5.1.4
-	eNB->preamble_list_br[ind].preamble_rel8.rnti                  = 1+subframe+(eNB->prach_vars_br.first_frame[ce_level]%40);  
-	eNB->preamble_list_br[ind].instance_length                     = 0; //don't know exactly what this is
-	eNB->preamble_list_br[ind].preamble_rel13.rach_resource_type   = 1+ce_level;  // CE Level
-	LOG_D(PHY,"Filling NFAPI indication for RACH %d CELevel %d (mask %x) : TA %d, Preamble %d, rnti %x, rach_resource_type %d\n",
-	      ind,
-	      ce_level,
-	      is_prach_subframe(&eNB->frame_parms,eNB->proc.frame_prach_br,eNB->proc.subframe_prach_br),
-	      eNB->preamble_list_br[ind].preamble_rel8.timing_advance,
-	      eNB->preamble_list_br[ind].preamble_rel8.preamble,
-	      eNB->preamble_list_br[ind].preamble_rel8.rnti,
-	      eNB->preamble_list_br[ind].preamble_rel13.rach_resource_type);
+    int             prach_mask;
+
+    prach_mask = is_prach_subframe (&eNB->frame_parms, eNB->proc.frame_prach_br, eNB->proc.subframe_prach_br);
+
+    eNB->UL_INFO.rach_ind_br.rach_indication_body.preamble_list = eNB->preamble_list_br;
+    int             ind = 0;
+    int             ce_level = 0;
+    /* Save for later, it doesn't work
+       for (int ind=0,ce_level=0;ce_level<4;ce_level++) {
+
+       if ((eNB->frame_parms.prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[ce_level]==1)&&
+       (prach_mask&(1<<(1+ce_level)) > 0) && // prach is active and CE level has finished its repetitions
+       (eNB->prach_vars_br.repetition_number[ce_level]==
+       eNB->frame_parms.prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[ce_level])) {
+
+    */
+
+    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)) {
+        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];      //
+        eNB->preamble_list_br[ind].preamble_rel8.preamble = max_preamble[ind];
+        // note: fid is implicitly 0 here, this is the rule for eMTC RA-RNTI from 36.321, Section 5.1.4
+        eNB->preamble_list_br[ind].preamble_rel8.rnti = 1 + subframe + (60*(eNB->prach_vars_br.first_frame[ce_level] % 40));
+        eNB->preamble_list_br[ind].instance_length = 0; //don't know exactly what this is
+        eNB->preamble_list_br[ind].preamble_rel13.rach_resource_type = 1 + ce_level;    // CE Level
+        LOG_I (PHY, "Filling NFAPI indication for RACH %d CELevel %d (mask %x) : TA %d, Preamble %d, rnti %x, rach_resource_type %d\n",
+               ind,
+               ce_level,
+               prach_mask,
+               eNB->preamble_list_br[ind].preamble_rel8.timing_advance,
+               eNB->preamble_list_br[ind].preamble_rel8.preamble, eNB->preamble_list_br[ind].preamble_rel8.rnti, eNB->preamble_list_br[ind].preamble_rel13.rach_resource_type);
       }
+    }
       /*
 	ind++;
-      }
-      } */// ce_level
-    }
+	}
+	} */// ce_level
   }
   else
 #endif
@@ -222,4 +223,4 @@ void prach_procedures(PHY_VARS_eNB *eNB
     } // else br_flag
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_PRACH_RX,0);
-}
\ No newline at end of file
+}
diff --git a/openair1/SCHED/sched_common.h b/openair1/SCHED/sched_common.h
index e579110a78849e21cf37c361ba689753cb3ae633..e9af869b05518d68b71d05f4efef29ec90a9adeb 100644
--- a/openair1/SCHED/sched_common.h
+++ b/openair1/SCHED/sched_common.h
@@ -30,7 +30,7 @@
 
 #include "PHY/defs_eNB.h"
 #include "PHY/defs_UE.h"
-#include "TDD-Config.h"
+#include "LTE_TDD-Config.h"
 /*! \brief Function to compute subframe Number(DL and S) as a function of Frame type and TDD Configuration
   @param frame_parms Pointer to DL frame parameter descriptor
   @returns Subframe Number (DL,S)
@@ -180,7 +180,7 @@ uint8_t is_SR_TXOp(PHY_VARS_UE *phy_vars_ue,UE_rxtx_proc_t *proc,uint8_t eNB_id)
   @param UE_id ID of UE which may be issuing the SR
   @returns 1 if TXOp is active.
 */
-uint8_t is_SR_subframe(PHY_VARS_eNB *phy_vars_eNB,eNB_rxtx_proc_t *proc,uint8_t UE_id);
+uint8_t is_SR_subframe(PHY_VARS_eNB *phy_vars_eNB,L1_rxtx_proc_t *proc,uint8_t UE_id);
 
 /*! \brief Gives the UL subframe corresponding to a PDDCH order in subframe n
   @param frame_parms Pointer to DL frame parameters
@@ -247,7 +247,7 @@ TDD, this routine computes the procedure described in Section 10.1 of 36.213 (th
 @param n1_pucch3 Pointer to n1_pucch3
 */
 void get_n1_pucch_eNB(PHY_VARS_eNB *phy_vars_eNB,
-		      eNB_rxtx_proc_t *proc,
+		      L1_rxtx_proc_t *proc,
                       uint8_t UE_id,
                       int16_t *n1_pucch0,
                       int16_t *n1_pucch1,
@@ -266,7 +266,7 @@ void get_n1_pucch_eNB(PHY_VARS_eNB *phy_vars_eNB,
 */
 void process_HARQ_feedback(uint8_t UE_id,
                            PHY_VARS_eNB *phy_vars_eNB,
-			   eNB_rxtx_proc_t *proc,
+			   L1_rxtx_proc_t *proc,
                            uint8_t pusch_flag,
                            uint8_t *pucch_payload,
                            uint8_t pucch_sel,
@@ -346,7 +346,7 @@ void compute_srs_pos(lte_frame_type_t frameType,uint16_t isrs,uint16_t *psrsPeri
 
 int ul_ACK_subframe2_dl_frame(LTE_DL_FRAME_PARMS *frame_parms,int frame, unsigned char subframe,unsigned char subframe_tx);
 
-void get_retransmission_timing(TDD_Config_t *tdd_Config, frame_t *frameP,  sub_frame_t *subframeP);
+void get_retransmission_timing(LTE_TDD_Config_t *tdd_Config, frame_t *frameP,  sub_frame_t *subframeP);
 /*@}*/
 
 
diff --git a/openair1/SCHED/sched_eNB.h b/openair1/SCHED/sched_eNB.h
index cf6c5815f203bf1ac410bd292e2ca26ae0178d6c..dccfbf7c388ac204771e391eaa1044cffea9e4cd 100644
--- a/openair1/SCHED/sched_eNB.h
+++ b/openair1/SCHED/sched_eNB.h
@@ -92,13 +92,13 @@ enum openair_HARQ_TYPE {
   @param abstraction_flag Indicator of PHY abstraction
   @param do_meas Do inline timing measurement
 */
-void phy_procedures_eNB_TX(PHY_VARS_eNB *phy_vars_eNB,eNB_rxtx_proc_t *proc,int do_meas);
+void phy_procedures_eNB_TX(PHY_VARS_eNB *phy_vars_eNB,L1_rxtx_proc_t *proc,int do_meas);
 
 /*! \brief Scheduling for eNB RX UE-specific procedures in normal subframes.
   @param phy_vars_eNB Pointer to eNB variables on which to act
   @param proc Pointer to RXn-TXnp4 proc information
 */
-void phy_procedures_eNB_uespec_RX(PHY_VARS_eNB *phy_vars_eNB,eNB_rxtx_proc_t *proc);
+void phy_procedures_eNB_uespec_RX(PHY_VARS_eNB *phy_vars_eNB,L1_rxtx_proc_t *proc);
 
 /*! \brief Scheduling for eNB TX procedures in TDD S-subframes.
   @param phy_vars_eNB Pointer to eNB variables on which to act
@@ -110,7 +110,7 @@ void phy_procedures_eNB_uespec_RX(PHY_VARS_eNB *phy_vars_eNB,eNB_rxtx_proc_t *pr
   @param phy_vars_eNB Pointer to eNB variables on which to act
   @param abstraction_flag Indicator of PHY abstraction
 */
-void phy_procedures_eNB_common_RX(PHY_VARS_eNB *phy_vars_eNB,eNB_rxtx_proc_t *proc);
+void phy_procedures_eNB_common_RX(PHY_VARS_eNB *phy_vars_eNB,L1_rxtx_proc_t *proc);
 
 /*! \brief Scheduling for eNB TX procedures in TDD S-subframes.
   @param phy_vars_eNB Pointer to eNB variables on which to act
@@ -121,13 +121,13 @@ void phy_procedures_eNB_S_TX(PHY_VARS_eNB *phy_vars_eNB);
 /*! \brief Scheduling for eNB RX procedures in TDD S-subframes.
   @param phy_vars_eNB Pointer to eNB variables on which to act
 */
-void phy_procedures_eNB_S_RX(PHY_VARS_eNB *phy_vars_eNB,eNB_rxtx_proc_t *proc);
+void phy_procedures_eNB_S_RX(PHY_VARS_eNB *phy_vars_eNB,L1_rxtx_proc_t *proc);
 
 /*! \brief Scheduling for eNB PRACH RX procedures
   @param phy_vars_eNB Pointer to eNB variables on which to act
   @param br_flag indicator for eMTC PRACH
 */
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 void prach_procedures(PHY_VARS_eNB *eNB,
 		      int br_flag);
 #else
@@ -186,7 +186,7 @@ void ra_failed(uint8_t Mod_id,uint8_t CC_id,uint8_t eNB_index);
   @param UE_id ID of UE which may be issuing the SR
   @returns 1 if TXOp is active.
 */
-uint8_t is_SR_subframe(PHY_VARS_eNB *phy_vars_eNB,eNB_rxtx_proc_t *proc,uint8_t UE_id);
+uint8_t is_SR_subframe(PHY_VARS_eNB *phy_vars_eNB,L1_rxtx_proc_t *proc,uint8_t UE_id);
 
 int8_t find_ue_dlsch(uint16_t rnti, PHY_VARS_eNB *phy_vars_eNB);
 int8_t find_ue_ulsch(uint16_t rnti, PHY_VARS_eNB *phy_vars_eNB);
diff --git a/openair1/SCHED_UE/phy_procedures_lte_ue.c b/openair1/SCHED_UE/phy_procedures_lte_ue.c
index c6917b399612380076d8cc0f35595d59df42bd70..8ceda675e82ad91cd22d106e6ce9619551e7755b 100644
--- a/openair1/SCHED_UE/phy_procedures_lte_ue.c
+++ b/openair1/SCHED_UE/phy_procedures_lte_ue.c
@@ -45,7 +45,7 @@
 
 
 #ifndef PUCCH
-#define PUCCH
+  #define PUCCH
 #endif
 
 #include "LAYER2/MAC/mac.h"
@@ -55,7 +55,7 @@
 #include "UTIL/OPT/opt.h"
 
 #if defined(ENABLE_ITTI)
-# include "intertask_interface.h"
+  #include "intertask_interface.h"
 #endif
 
 #include "PHY/defs_UE.h"
@@ -78,41 +78,36 @@ void Msg1_transmitted(module_id_t module_idP,uint8_t CC_id,frame_t frameP, uint8
 void Msg3_transmitted(module_id_t module_idP,uint8_t CC_id,frame_t frameP, uint8_t eNB_id);
 
 #if defined(EXMIMO) || defined(OAI_USRP) || defined(OAI_BLADERF) || defined(OAI_LMSSDR)
-extern uint32_t downlink_frequency[MAX_NUM_CCs][4];
+  extern uint32_t downlink_frequency[MAX_NUM_CCs][4];
 #endif
 
 void get_dumpparam(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id, uint8_t nb_rb,
                    uint32_t *alloc_even, uint8_t subframe,uint32_t Qm, uint32_t Nl, uint32_t tm,
                    uint8_t *nsymb, uint32_t *coded_bits_per_codeword) {
-
   *nsymb = (ue->frame_parms.Ncp == 0) ? 14 : 12;
-
   *coded_bits_per_codeword = get_G(&ue->frame_parms,
-                                  nb_rb,
-                                  alloc_even,
-                                  Qm,
-                                  Nl,
-                                  ue->pdcch_vars[0%RX_NB_TH][eNB_id]->num_pdcch_symbols,
-                                  proc->frame_rx,
-                                  subframe,
-                                  tm);
+                                   nb_rb,
+                                   alloc_even,
+                                   Qm,
+                                   Nl,
+                                   ue->pdcch_vars[0%RX_NB_TH][eNB_id]->num_pdcch_symbols,
+                                   proc->frame_rx,
+                                   subframe,
+                                   tm);
 }
 
-void dump_dlsch(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uint8_t subframe,uint8_t harq_pid)
-{
-  if (LOG_DUMPFLAG(DEBUG_UE_PHYPROC)) { 
+void dump_dlsch(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uint8_t subframe,uint8_t harq_pid) {
+  if (LOG_DUMPFLAG(DEBUG_UE_PHYPROC)) {
     unsigned int coded_bits_per_codeword;
     uint8_t nsymb ;
-
-    get_dumpparam(ue, proc, eNB_id, 
-  		  ue->dlsch[ue->current_thread_id[subframe]][eNB_id][0]->harq_processes[harq_pid]->nb_rb ,
-  		  ue->dlsch[ue->current_thread_id[subframe]][eNB_id][0]->harq_processes[harq_pid]->rb_alloc_even,
-  		  subframe,
-  		  ue->dlsch[ue->current_thread_id[subframe]][eNB_id][0]->harq_processes[harq_pid]->Qm,
-  		  ue->dlsch[ue->current_thread_id[subframe]][eNB_id][0]->harq_processes[harq_pid]->Nl,  	      
-  		  ue->transmission_mode[eNB_id]<7?0:ue->transmission_mode[eNB_id],
-  		  &nsymb, &coded_bits_per_codeword);
-
+    get_dumpparam(ue, proc, eNB_id,
+                  ue->dlsch[ue->current_thread_id[subframe]][eNB_id][0]->harq_processes[harq_pid]->nb_rb,
+                  ue->dlsch[ue->current_thread_id[subframe]][eNB_id][0]->harq_processes[harq_pid]->rb_alloc_even,
+                  subframe,
+                  ue->dlsch[ue->current_thread_id[subframe]][eNB_id][0]->harq_processes[harq_pid]->Qm,
+                  ue->dlsch[ue->current_thread_id[subframe]][eNB_id][0]->harq_processes[harq_pid]->Nl,
+                  ue->transmission_mode[eNB_id]<7?0:ue->transmission_mode[eNB_id],
+                  &nsymb, &coded_bits_per_codeword);
     LOG_M("rxsigF0.m","rxsF0", ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].rxdataF[0],2*nsymb*ue->frame_parms.ofdm_symbol_size,2,1);
     LOG_M("rxsigF0_ext.m","rxsF0_ext", ue->pdsch_vars[ue->current_thread_id[subframe]][0]->rxdataF_ext[0],2*nsymb*ue->frame_parms.ofdm_symbol_size,1,1);
     LOG_M("dlsch00_ch0_ext.m","dl00_ch0_ext", ue->pdsch_vars[ue->current_thread_id[subframe]][0]->dl_ch_estimates_ext[0],300*nsymb,1,1);
@@ -124,36 +119,30 @@ void dump_dlsch(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uint8_t subf
     */
     LOG_M("dlsch_rxF_comp0.m","dlsch0_rxF_comp0", ue->pdsch_vars[ue->current_thread_id[subframe]][0]->rxdataF_comp0[0],300*12,1,1);
     LOG_M("dlsch_rxF_llr.m","dlsch_llr", ue->pdsch_vars[ue->current_thread_id[subframe]][0]->llr[0],coded_bits_per_codeword,1,0);
-
     LOG_M("dlsch_mag1.m","dlschmag1",ue->pdsch_vars[ue->current_thread_id[subframe]][0]->dl_ch_mag0,300*12,1,1);
     LOG_M("dlsch_mag2.m","dlschmag2",ue->pdsch_vars[ue->current_thread_id[subframe]][0]->dl_ch_magb0,300*12,1,1);
-    }
+  }
 }
 
-void dump_dlsch_SI(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uint8_t subframe)
-{
-  if (LOG_DUMPFLAG(DEBUG_UE_PHYPROC)){
+void dump_dlsch_SI(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uint8_t subframe) {
+  if (LOG_DUMPFLAG(DEBUG_UE_PHYPROC)) {
     unsigned int coded_bits_per_codeword;
     uint8_t nsymb;
-
     get_dumpparam(ue, proc, eNB_id,
-  		  ue->dlsch_SI[eNB_id]->harq_processes[0]->nb_rb,
-  		  ue->dlsch_SI[eNB_id]->harq_processes[0]->rb_alloc_even,
-  		  subframe,2,1,0,
-  		  &nsymb, &coded_bits_per_codeword);
-
+                  ue->dlsch_SI[eNB_id]->harq_processes[0]->nb_rb,
+                  ue->dlsch_SI[eNB_id]->harq_processes[0]->rb_alloc_even,
+                  subframe,2,1,0,
+                  &nsymb, &coded_bits_per_codeword);
     LOG_D(PHY,"[UE %d] Dumping dlsch_SI : ofdm_symbol_size %d, nsymb %d, nb_rb %d, mcs %d, nb_rb %d, num_pdcch_symbols %d,G %d\n",
-  	  ue->Mod_id,
-  	  ue->frame_parms.ofdm_symbol_size,
-  	  nsymb,
-  	  ue->dlsch_SI[eNB_id]->harq_processes[0]->nb_rb,
-  	  ue->dlsch_SI[eNB_id]->harq_processes[0]->mcs,
-  	  ue->dlsch_SI[eNB_id]->harq_processes[0]->nb_rb,
-  	  ue->pdcch_vars[0%RX_NB_TH][eNB_id]->num_pdcch_symbols,
-  	  coded_bits_per_codeword);
-
+          ue->Mod_id,
+          ue->frame_parms.ofdm_symbol_size,
+          nsymb,
+          ue->dlsch_SI[eNB_id]->harq_processes[0]->nb_rb,
+          ue->dlsch_SI[eNB_id]->harq_processes[0]->mcs,
+          ue->dlsch_SI[eNB_id]->harq_processes[0]->nb_rb,
+          ue->pdcch_vars[0%RX_NB_TH][eNB_id]->num_pdcch_symbols,
+          coded_bits_per_codeword);
     LOG_M("rxsig0.m","rxs0", &ue->common_vars.rxdata[0][subframe*ue->frame_parms.samples_per_tti],ue->frame_parms.samples_per_tti,1,1);
-
     LOG_M("rxsigF0.m","rxsF0", ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].rxdataF[0],nsymb*ue->frame_parms.ofdm_symbol_size,1,1);
     LOG_M("rxsigF0_ext.m","rxsF0_ext", ue->pdsch_vars_SI[0]->rxdataF_ext[0],2*nsymb*ue->frame_parms.ofdm_symbol_size,1,1);
     LOG_M("dlsch00_ch0_ext.m","dl00_ch0_ext", ue->pdsch_vars_SI[0]->dl_ch_estimates_ext[0],ue->frame_parms.N_RB_DL*12*nsymb,1,1);
@@ -165,7 +154,6 @@ void dump_dlsch_SI(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uint8_t s
     */
     LOG_M("dlsch_rxF_comp0.m","dlsch0_rxF_comp0", ue->pdsch_vars_SI[0]->rxdataF_comp0[0],ue->frame_parms.N_RB_DL*12*nsymb,1,1);
     LOG_M("dlsch_rxF_llr.m","dlsch_llr", ue->pdsch_vars_SI[0]->llr[0],coded_bits_per_codeword,1,0);
-
     LOG_M("dlsch_mag1.m","dlschmag1",ue->pdsch_vars_SI[0]->dl_ch_mag0,300*nsymb,1,1);
     LOG_M("dlsch_mag2.m","dlschmag2",ue->pdsch_vars_SI[0]->dl_ch_magb0,300*nsymb,1,1);
     sleep(1);
@@ -215,9 +203,7 @@ void dump_dlsch_SI(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uint8_t s
   }
 */
 
-unsigned int get_tx_amp(int power_dBm, int power_max_dBm, int N_RB_UL, int nb_rb)
-{
-
+unsigned int get_tx_amp(int power_dBm, int power_max_dBm, int N_RB_UL, int nb_rb) {
   int gain_dB;
   double gain_lin;
 
@@ -233,27 +219,22 @@ unsigned int get_tx_amp(int power_dBm, int power_max_dBm, int N_RB_UL, int nb_rb
 
 #endif
 
-void dump_dlsch_ra(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uint8_t subframe)
-{
-  if (LOG_DUMPFLAG(DEBUG_UE_PHYPROC)){
+void dump_dlsch_ra(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uint8_t subframe) {
+  if (LOG_DUMPFLAG(DEBUG_UE_PHYPROC)) {
     unsigned int coded_bits_per_codeword;
     uint8_t nsymb ;
-
-
     get_dumpparam(ue, proc, eNB_id,
-  		  ue->dlsch_SI[eNB_id]->harq_processes[0]->nb_rb,
-  		  ue->dlsch_SI[eNB_id]->harq_processes[0]->rb_alloc_even, 
-  		  subframe,2,1,0,
-  		  &nsymb, &coded_bits_per_codeword);
-
+                  ue->dlsch_SI[eNB_id]->harq_processes[0]->nb_rb,
+                  ue->dlsch_SI[eNB_id]->harq_processes[0]->rb_alloc_even,
+                  subframe,2,1,0,
+                  &nsymb, &coded_bits_per_codeword);
     LOG_D(PHY,"[UE %d] Dumping dlsch_ra : nb_rb %d, mcs %d, nb_rb %d, num_pdcch_symbols %d,G %d\n",
-  	  ue->Mod_id,
-  	  ue->dlsch_ra[eNB_id]->harq_processes[0]->nb_rb,
-  	  ue->dlsch_ra[eNB_id]->harq_processes[0]->mcs,
-  	  ue->dlsch_ra[eNB_id]->harq_processes[0]->nb_rb,
-  	  ue->pdcch_vars[0%RX_NB_TH][eNB_id]->num_pdcch_symbols,
-  	  coded_bits_per_codeword);
-
+          ue->Mod_id,
+          ue->dlsch_ra[eNB_id]->harq_processes[0]->nb_rb,
+          ue->dlsch_ra[eNB_id]->harq_processes[0]->mcs,
+          ue->dlsch_ra[eNB_id]->harq_processes[0]->nb_rb,
+          ue->pdcch_vars[0%RX_NB_TH][eNB_id]->num_pdcch_symbols,
+          coded_bits_per_codeword);
     LOG_M("rxsigF0.m","rxsF0", ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].rxdataF[0],2*12*ue->frame_parms.ofdm_symbol_size,2,1);
     LOG_M("rxsigF0_ext.m","rxsF0_ext", ue->pdsch_vars_ra[0]->rxdataF_ext[0],2*12*ue->frame_parms.ofdm_symbol_size,1,1);
     LOG_M("dlsch00_ch0_ext.m","dl00_ch0_ext", ue->pdsch_vars_ra[0]->dl_ch_estimates_ext[0],300*nsymb,1,1);
@@ -265,60 +246,53 @@ void dump_dlsch_ra(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uint8_t s
     */
     LOG_M("dlsch_rxF_comp0.m","dlsch0_rxF_comp0", ue->pdsch_vars_ra[0]->rxdataF_comp0[0],300*nsymb,1,1);
     LOG_M("dlsch_rxF_llr.m","dlsch_llr", ue->pdsch_vars_ra[0]->llr[0],coded_bits_per_codeword,1,0);
-
     LOG_M("dlsch_mag1.m","dlschmag1",ue->pdsch_vars_ra[0]->dl_ch_mag0,300*nsymb,1,1);
     LOG_M("dlsch_mag2.m","dlschmag2",ue->pdsch_vars_ra[0]->dl_ch_magb0,300*nsymb,1,1);
   }
 }
 
-void phy_reset_ue(module_id_t Mod_id,uint8_t CC_id,uint8_t eNB_index)
-{
-
+void phy_reset_ue(module_id_t Mod_id,uint8_t CC_id,uint8_t eNB_index) {
   // This flushes ALL DLSCH and ULSCH harq buffers of ALL connected eNBs...add the eNB_index later
   // for more flexibility
-
   uint8_t i,j,k,s;
   PHY_VARS_UE *ue = PHY_vars_UE_g[Mod_id][CC_id];
 
   //[NUMBER_OF_RX_THREAD=2][NUMBER_OF_CONNECTED_eNB_MAX][2];
   for(int l=0; l<RX_NB_TH; l++) {
-      for(i=0; i<NUMBER_OF_CONNECTED_eNB_MAX; i++) {
-          for(j=0; j<2; j++) {
-              //DL HARQ
-              if(ue->dlsch[l][i][j]) {
-                  for(k=0; k<NUMBER_OF_HARQ_PID_MAX && ue->dlsch[l][i][j]->harq_processes[k]; k++) {
-                      ue->dlsch[l][i][j]->harq_processes[k]->status = SCH_IDLE;
-                      for (s=0; s<10; s++) {
-                          // reset ACK/NACK bit to DTX for all subframes s = 0..9
-                          ue->dlsch[l][i][j]->harq_ack[s].ack = 2;
-                          ue->dlsch[l][i][j]->harq_ack[s].send_harq_status = 0;
-                          ue->dlsch[l][i][j]->harq_ack[s].vDAI_UL = 0xff;
-                          ue->dlsch[l][i][j]->harq_ack[s].vDAI_DL = 0xff;
-                      }
-                  }
-              }
-          }
-
-          //UL HARQ
-          if(ue->ulsch[i]) {
-              for(k=0; k<NUMBER_OF_HARQ_PID_MAX && ue->ulsch[i]->harq_processes[k]; k++) {
-                  ue->ulsch[i]->harq_processes[k]->status = SCH_IDLE;
-                  //Set NDIs for all UL HARQs to 0
-                  //  ue->ulsch[i]->harq_processes[k]->Ndi = 0;
-
-              }
+    for(i=0; i<NUMBER_OF_CONNECTED_eNB_MAX; i++) {
+      for(j=0; j<2; j++) {
+        //DL HARQ
+        if(ue->dlsch[l][i][j]) {
+          for(k=0; k<NUMBER_OF_HARQ_PID_MAX && ue->dlsch[l][i][j]->harq_processes[k]; k++) {
+            ue->dlsch[l][i][j]->harq_processes[k]->status = SCH_IDLE;
+
+            for (s=0; s<10; s++) {
+              // reset ACK/NACK bit to DTX for all subframes s = 0..9
+              ue->dlsch[l][i][j]->harq_ack[s].ack = 2;
+              ue->dlsch[l][i][j]->harq_ack[s].send_harq_status = 0;
+              ue->dlsch[l][i][j]->harq_ack[s].vDAI_UL = 0xff;
+              ue->dlsch[l][i][j]->harq_ack[s].vDAI_DL = 0xff;
+            }
           }
+        }
+      }
 
-          // flush Msg3 buffer
-          ue->ulsch_Msg3_active[i] = 0;
-
+      //UL HARQ
+      if(ue->ulsch[i]) {
+        for(k=0; k<NUMBER_OF_HARQ_PID_MAX && ue->ulsch[i]->harq_processes[k]; k++) {
+          ue->ulsch[i]->harq_processes[k]->status = SCH_IDLE;
+          //Set NDIs for all UL HARQs to 0
+          //  ue->ulsch[i]->harq_processes[k]->Ndi = 0;
+        }
       }
+
+      // flush Msg3 buffer
+      ue->ulsch_Msg3_active[i] = 0;
+    }
   }
 }
 
-void ra_failed(uint8_t Mod_id,uint8_t CC_id,uint8_t eNB_index)
-{
-
+void ra_failed(uint8_t Mod_id,uint8_t CC_id,uint8_t eNB_index) {
   // if contention resolution fails, go back to PRACH
   PHY_vars_UE_g[Mod_id][CC_id]->UE_mode[eNB_index] = PRACH;
   PHY_vars_UE_g[Mod_id][CC_id]->pdcch_vars[0][eNB_index]->crnti_is_temporary = 0;
@@ -328,13 +302,9 @@ void ra_failed(uint8_t Mod_id,uint8_t CC_id,uint8_t eNB_index)
   LOG_E(PHY,"[UE %d] Random-access procedure fails, going back to PRACH, setting SIStatus = 0, discard temporary C-RNTI and State RRC_IDLE\n",Mod_id);
 }
 
-void ra_succeeded(uint8_t Mod_id,uint8_t CC_id,uint8_t eNB_index)
-{
-
+void ra_succeeded(uint8_t Mod_id,uint8_t CC_id,uint8_t eNB_index) {
   int i;
-
   LOG_I(PHY,"[UE %d][RAPROC] Random-access procedure succeeded. Set C-RNTI = Temporary C-RNTI\n",Mod_id);
-
   PHY_vars_UE_g[Mod_id][CC_id]->pdcch_vars[0][eNB_index]->crnti_is_temporary = 0;
   PHY_vars_UE_g[Mod_id][CC_id]->pdcch_vars[1][eNB_index]->crnti_is_temporary = 0;
   PHY_vars_UE_g[Mod_id][CC_id]->ulsch_Msg3_active[eNB_index] = 0;
@@ -348,50 +318,31 @@ void ra_succeeded(uint8_t Mod_id,uint8_t CC_id,uint8_t eNB_index)
       PHY_vars_UE_g[Mod_id][CC_id]->ulsch[eNB_index]->harq_processes[i]->subframe_scheduling_flag=0;
     }
   }
-
-
 }
 
-UE_MODE_t get_ue_mode(uint8_t Mod_id,uint8_t CC_id,uint8_t eNB_index)
-{
-
+UE_MODE_t get_ue_mode(uint8_t Mod_id,uint8_t CC_id,uint8_t eNB_index) {
   return(PHY_vars_UE_g[Mod_id][CC_id]->UE_mode[eNB_index]);
-
 }
 void process_timing_advance_rar(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint16_t timing_advance) {
-
   ue->timing_advance = timing_advance*4;
 
-
   if (LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
-  /* TODO: fix this log, what is 'HW timing advance'? */
-  /*LOG_I(PHY,"[UE %d] AbsoluteSubFrame %d.%d, received (rar) timing_advance %d, HW timing advance %d\n",ue->Mod_id,proc->frame_rx, proc->subframe_rx, ue->timing_advance);*/
+    /* TODO: fix this log, what is 'HW timing advance'? */
+    /*LOG_I(PHY,"[UE %d] AbsoluteSubFrame %d.%d, received (rar) timing_advance %d, HW timing advance %d\n",ue->Mod_id,proc->frame_rx, proc->subframe_rx, ue->timing_advance);*/
     LOG_UI(PHY,"[UE %d] AbsoluteSubFrame %d.%d, received (rar) timing_advance %d\n",ue->Mod_id,proc->frame_rx, proc->subframe_rx, ue->timing_advance);
   }
-
 }
 
-void process_timing_advance(module_id_t Mod_id,uint8_t CC_id,int16_t timing_advance)
-{
-
+void process_timing_advance(module_id_t Mod_id,uint8_t CC_id,int16_t timing_advance) {
   //  uint32_t frame = PHY_vars_UE_g[Mod_id]->frame;
-
   // timing advance has Q1.5 format
   timing_advance = timing_advance - 31;
-
   PHY_vars_UE_g[Mod_id][CC_id]->timing_advance = PHY_vars_UE_g[Mod_id][CC_id]->timing_advance+timing_advance*4; //this is for 25RB only!!!
-
-
   LOG_D(PHY,"[UE %d] Got timing advance %d from MAC, new value %d\n",Mod_id, timing_advance, PHY_vars_UE_g[Mod_id][CC_id]->timing_advance);
-
-
 }
 
-uint8_t is_SR_TXOp(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id)
-{
-
+uint8_t is_SR_TXOp(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id) {
   int subframe=proc->subframe_tx;
-
   LOG_D(PHY,"[UE %d][SR %x] Frame %d subframe %d Checking for SR TXOp (sr_ConfigIndex %d)\n",
         ue->Mod_id,ue->pdcch_vars[ue->current_thread_id[proc->subframe_rx]][eNB_id]->crnti,proc->frame_tx,subframe,
         ue->scheduling_request_config[eNB_id].sr_ConfigIndex);
@@ -416,8 +367,7 @@ uint8_t is_SR_TXOp(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id)
   return(0);
 }
 
-uint8_t is_cqi_TXOp(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id)
-{
+uint8_t is_cqi_TXOp(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id) {
   int subframe = proc->subframe_tx;
   int frame    = proc->frame_tx;
   CQI_REPORTPERIODIC *cqirep = &ue->cqi_report_config[eNB_id].CQI_ReportPeriodic;
@@ -434,10 +384,7 @@ uint8_t is_cqi_TXOp(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id)
   else
     return(0);
 }
-uint8_t is_ri_TXOp(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id)
-{
-
-
+uint8_t is_ri_TXOp(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id) {
   int subframe = proc->subframe_tx;
   int frame    = proc->frame_tx;
   CQI_REPORTPERIODIC *cqirep = &ue->cqi_report_config[eNB_id].CQI_ReportPeriodic;
@@ -463,22 +410,17 @@ void compute_cqi_ri_resources(PHY_VARS_UE *ue,
                               uint16_t p_rnti,
                               uint16_t cba_rnti,
                               uint8_t cqi_status,
-                              uint8_t ri_status)
-{
-    //PHY_MEASUREMENTS *meas = &ue->measurements;
-    //uint8_t transmission_mode = ue->transmission_mode[eNB_id];
+                              uint8_t ri_status) {
+  //PHY_MEASUREMENTS *meas = &ue->measurements;
+  //uint8_t transmission_mode = ue->transmission_mode[eNB_id];
 
-
-    //LOG_I(PHY,"compute_cqi_ri_resources O_RI %d O %d uci format %d \n",ulsch->O_RI,ulsch->O,ulsch->uci_format);
-    if (cqi_status == 1 || ri_status == 1)
-    {
-        ulsch->O = 4;
-    }
+  //LOG_I(PHY,"compute_cqi_ri_resources O_RI %d O %d uci format %d \n",ulsch->O_RI,ulsch->O,ulsch->uci_format);
+  if (cqi_status == 1 || ri_status == 1) {
+    ulsch->O = 4;
+  }
 }
 
-void ue_compute_srs_occasion(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uint8_t isSubframeSRS)
-{
-
+void ue_compute_srs_occasion(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uint8_t isSubframeSRS) {
   LTE_DL_FRAME_PARMS *frame_parms = &ue->frame_parms;
   int frame_tx    = proc->frame_tx;
   int subframe_tx = proc->subframe_tx;
@@ -487,91 +429,81 @@ void ue_compute_srs_occasion(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id
   uint16_t srsOffset;
   uint8_t is_pucch2_subframe = 0;
   uint8_t is_sr_an_subframe  = 0;
-
   // check for SRS opportunity
   pSoundingrs_ul_config_dedicated->srsUeSubframe   = 0;
   pSoundingrs_ul_config_dedicated->srsCellSubframe = isSubframeSRS;
 
   if (isSubframeSRS) {
     LOG_D(PHY," SrsDedicatedSetup: %d \n",pSoundingrs_ul_config_dedicated->srsConfigDedicatedSetup);
-      if(pSoundingrs_ul_config_dedicated->srsConfigDedicatedSetup)
-      {
-          compute_srs_pos(frame_parms->frame_type, pSoundingrs_ul_config_dedicated->srs_ConfigIndex, &srsPeriodicity, &srsOffset);
-
-          LOG_D(PHY," srsPeriodicity: %d srsOffset: %d isSubframeSRS %d \n",srsPeriodicity,srsOffset,isSubframeSRS);
-
-          // transmit SRS if the four following constraints are respected:
-          // - UE is configured to transmit SRS
-          // - SRS are configured in current subframe
-          // - UE is configured to send SRS in this subframe
-
-          // 36.213 8.2
-          // 1- A UE shall not transmit SRS whenever SRS and PUCCH format 2/2a/2b transmissions happen to coincide in the same subframe
-          // 2- A UE shall not transmit SRS whenever SRS transmit
-          //    on and PUCCH transmission carrying ACK/NACK and/or
-          //    positive SR happen to coincide in the same subframe if the parameter
-          //    Simultaneous-AN-and-SRS is FALSE
-
-          // check PUCCH format 2/2a/2b transmissions
-          is_pucch2_subframe = is_cqi_TXOp(ue,proc,eNB_id) && (ue->cqi_report_config[eNB_id].CQI_ReportPeriodic.cqi_PMI_ConfigIndex>0);
-          is_pucch2_subframe = (is_ri_TXOp(ue,proc,eNB_id) && (ue->cqi_report_config[eNB_id].CQI_ReportPeriodic.ri_ConfigIndex>0)) || is_pucch2_subframe;
-
-          // check ACK/SR transmission
-          if(frame_parms->soundingrs_ul_config_common.ackNackSRS_SimultaneousTransmission == FALSE)
-          {
-              if(is_SR_TXOp(ue,proc,eNB_id))
-              {
-                  uint32_t SR_payload = 0;
-                  if (ue->mac_enabled==1)
-                  {
-                      int Mod_id = ue->Mod_id;
-                      int CC_id = ue->CC_id;
-                      SR_payload = ue_get_SR(Mod_id,
-					     CC_id,
-					     frame_tx,
-					     eNB_id,
-					     ue->pdcch_vars[ue->current_thread_id[proc->subframe_rx]][eNB_id]->crnti,
-					     subframe_tx); // subframe used for meas gap
-
-                      if (SR_payload > 0)
-                          is_sr_an_subframe = 1;
-                  }
-              }
-
-              uint8_t pucch_ack_payload[2];
-              if (get_ack(&ue->frame_parms,
-                      ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack,
-                      subframe_tx,proc->subframe_rx,pucch_ack_payload,0) > 0)
-              {
-                  is_sr_an_subframe = 1;
-              }
-          }
 
-          // check SRS UE opportunity
-          if( isSubframeSRS  &&
-                  (((10*frame_tx+subframe_tx) % srsPeriodicity) == srsOffset)
-          )
-          {
-              if ((is_pucch2_subframe == 0) && (is_sr_an_subframe == 0))
-              {
-                  pSoundingrs_ul_config_dedicated->srsUeSubframe = 1;
-                  ue->ulsch[eNB_id]->srs_active   = 1;
-                  ue->ulsch[eNB_id]->Nsymb_pusch  = 12-(frame_parms->Ncp<<1)- ue->ulsch[eNB_id]->srs_active;
-              }
-              else
-              {
-                  LOG_I(PHY,"DROP UE-SRS-TX for this subframe %d.%d: collision with PUCCH2 or SR/AN: PUCCH2-occasion: %d, SR-AN-occasion[simSRS-SR-AN %d]: %d  \n", frame_tx, subframe_tx, is_pucch2_subframe, frame_parms->soundingrs_ul_config_common.ackNackSRS_SimultaneousTransmission, is_sr_an_subframe);
-              }
+    if(pSoundingrs_ul_config_dedicated->srsConfigDedicatedSetup) {
+      compute_srs_pos(frame_parms->frame_type, pSoundingrs_ul_config_dedicated->srs_ConfigIndex, &srsPeriodicity, &srsOffset);
+      LOG_D(PHY," srsPeriodicity: %d srsOffset: %d isSubframeSRS %d \n",srsPeriodicity,srsOffset,isSubframeSRS);
+      // transmit SRS if the four following constraints are respected:
+      // - UE is configured to transmit SRS
+      // - SRS are configured in current subframe
+      // - UE is configured to send SRS in this subframe
+      // 36.213 8.2
+      // 1- A UE shall not transmit SRS whenever SRS and PUCCH format 2/2a/2b transmissions happen to coincide in the same subframe
+      // 2- A UE shall not transmit SRS whenever SRS transmit
+      //    on and PUCCH transmission carrying ACK/NACK and/or
+      //    positive SR happen to coincide in the same subframe if the parameter
+      //    Simultaneous-AN-and-SRS is FALSE
+      // check PUCCH format 2/2a/2b transmissions
+      is_pucch2_subframe = is_cqi_TXOp(ue,proc,eNB_id) && (ue->cqi_report_config[eNB_id].CQI_ReportPeriodic.cqi_PMI_ConfigIndex>0);
+      is_pucch2_subframe = (is_ri_TXOp(ue,proc,eNB_id) && (ue->cqi_report_config[eNB_id].CQI_ReportPeriodic.ri_ConfigIndex>0)) || is_pucch2_subframe;
+
+      // check ACK/SR transmission
+      if(frame_parms->soundingrs_ul_config_common.ackNackSRS_SimultaneousTransmission == FALSE) {
+        if(is_SR_TXOp(ue,proc,eNB_id)) {
+          uint32_t SR_payload = 0;
+
+          if (ue->mac_enabled==1) {
+            int Mod_id = ue->Mod_id;
+            int CC_id = ue->CC_id;
+            SR_payload = ue_get_SR(Mod_id,
+                                   CC_id,
+                                   frame_tx,
+                                   eNB_id,
+                                   ue->pdcch_vars[ue->current_thread_id[proc->subframe_rx]][eNB_id]->crnti,
+                                   subframe_tx); // subframe used for meas gap
+
+            if (SR_payload > 0)
+              is_sr_an_subframe = 1;
           }
+        }
+
+        uint8_t pucch_ack_payload[2];
+
+        if (get_ack(&ue->frame_parms,
+                    ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack,
+                    subframe_tx,proc->subframe_rx,pucch_ack_payload,0) > 0) {
+          is_sr_an_subframe = 1;
+        }
+      }
+
+      // check SRS UE opportunity
+      if( isSubframeSRS  &&
+          (((10*frame_tx+subframe_tx) % srsPeriodicity) == srsOffset)
+        ) {
+        if ((is_pucch2_subframe == 0) && (is_sr_an_subframe == 0)) {
+          pSoundingrs_ul_config_dedicated->srsUeSubframe = 1;
+          ue->ulsch[eNB_id]->srs_active   = 1;
+          ue->ulsch[eNB_id]->Nsymb_pusch  = 12-(frame_parms->Ncp<<1)- ue->ulsch[eNB_id]->srs_active;
+        } else {
+          LOG_I(PHY,"DROP UE-SRS-TX for this subframe %d.%d: collision with PUCCH2 or SR/AN: PUCCH2-occasion: %d, SR-AN-occasion[simSRS-SR-AN %d]: %d  \n", frame_tx, subframe_tx, is_pucch2_subframe,
+                frame_parms->soundingrs_ul_config_common.ackNackSRS_SimultaneousTransmission, is_sr_an_subframe);
+        }
       }
-      LOG_D(PHY," srsCellSubframe: %d, srsUeSubframe: %d, Nsymb-pusch: %d \n", pSoundingrs_ul_config_dedicated->srsCellSubframe, pSoundingrs_ul_config_dedicated->srsUeSubframe, ue->ulsch[eNB_id]->Nsymb_pusch);
+    }
+
+    LOG_D(PHY," srsCellSubframe: %d, srsUeSubframe: %d, Nsymb-pusch: %d \n", pSoundingrs_ul_config_dedicated->srsCellSubframe, pSoundingrs_ul_config_dedicated->srsUeSubframe,
+          ue->ulsch[eNB_id]->Nsymb_pusch);
   }
 }
 
 
-void get_cqipmiri_params(PHY_VARS_UE *ue,uint8_t eNB_id)
-{
-
+void get_cqipmiri_params(PHY_VARS_UE *ue,uint8_t eNB_id) {
   CQI_REPORTPERIODIC *cqirep = &ue->cqi_report_config[eNB_id].CQI_ReportPeriodic;
   int cqi_PMI_ConfigIndex = cqirep->cqi_PMI_ConfigIndex;
 
@@ -597,46 +529,41 @@ void get_cqipmiri_params(PHY_VARS_UE *ue,uint8_t eNB_id)
     } else if (cqi_PMI_ConfigIndex <= 316) { // 160 ms CQI_PMI period
       cqirep->Npd = 160;
       cqirep->N_OFFSET_CQI = cqi_PMI_ConfigIndex-157;
-    }
-    else if (cqi_PMI_ConfigIndex > 317) {
-
+    } else if (cqi_PMI_ConfigIndex > 317) {
       if (cqi_PMI_ConfigIndex <= 349) { // 32 ms CQI_PMI period
-  cqirep->Npd = 32;
-      cqirep->N_OFFSET_CQI = cqi_PMI_ConfigIndex-318;
-      }
-      else if (cqi_PMI_ConfigIndex <= 413) { // 64 ms CQI_PMI period
-  cqirep->Npd = 64;
-  cqirep->N_OFFSET_CQI = cqi_PMI_ConfigIndex-350;
-      }
-      else if (cqi_PMI_ConfigIndex <= 541) { // 128 ms CQI_PMI period
-  cqirep->Npd = 128;
-  cqirep->N_OFFSET_CQI = cqi_PMI_ConfigIndex-414;
+        cqirep->Npd = 32;
+        cqirep->N_OFFSET_CQI = cqi_PMI_ConfigIndex-318;
+      } else if (cqi_PMI_ConfigIndex <= 413) { // 64 ms CQI_PMI period
+        cqirep->Npd = 64;
+        cqirep->N_OFFSET_CQI = cqi_PMI_ConfigIndex-350;
+      } else if (cqi_PMI_ConfigIndex <= 541) { // 128 ms CQI_PMI period
+        cqirep->Npd = 128;
+        cqirep->N_OFFSET_CQI = cqi_PMI_ConfigIndex-414;
       }
     }
-  }
-  else { // TDD
-   if (cqi_PMI_ConfigIndex == 0) {        // all UL subframes
-     cqirep->Npd = 1;
-     cqirep->N_OFFSET_CQI = 0;
-   } else if (cqi_PMI_ConfigIndex <= 6) { // 5 ms CQI_PMI period
-     cqirep->Npd = 5;
-     cqirep->N_OFFSET_CQI = cqi_PMI_ConfigIndex-1;
-   } else if (cqi_PMI_ConfigIndex <=16) { // 10ms CQI_PMI period
-     cqirep->Npd = 10;
-     cqirep->N_OFFSET_CQI = cqi_PMI_ConfigIndex-6;
-   } else if (cqi_PMI_ConfigIndex <= 36) { // 20 ms CQI_PMI period
-     cqirep->Npd = 20;
-     cqirep->N_OFFSET_CQI = cqi_PMI_ConfigIndex-16;
-   } else if (cqi_PMI_ConfigIndex <= 76) { // 40 ms CQI_PMI period
-     cqirep->Npd = 40;
-     cqirep->N_OFFSET_CQI = cqi_PMI_ConfigIndex-36;
-   } else if (cqi_PMI_ConfigIndex <= 156) { // 80 ms CQI_PMI period
-     cqirep->Npd = 80;
-     cqirep->N_OFFSET_CQI = cqi_PMI_ConfigIndex-76;
-   } else if (cqi_PMI_ConfigIndex <= 316) { // 160 ms CQI_PMI period
-     cqirep->Npd = 160;
-     cqirep->N_OFFSET_CQI = cqi_PMI_ConfigIndex-156;
-   }
+  } else { // TDD
+    if (cqi_PMI_ConfigIndex == 0) {        // all UL subframes
+      cqirep->Npd = 1;
+      cqirep->N_OFFSET_CQI = 0;
+    } else if (cqi_PMI_ConfigIndex <= 6) { // 5 ms CQI_PMI period
+      cqirep->Npd = 5;
+      cqirep->N_OFFSET_CQI = cqi_PMI_ConfigIndex-1;
+    } else if (cqi_PMI_ConfigIndex <=16) { // 10ms CQI_PMI period
+      cqirep->Npd = 10;
+      cqirep->N_OFFSET_CQI = cqi_PMI_ConfigIndex-6;
+    } else if (cqi_PMI_ConfigIndex <= 36) { // 20 ms CQI_PMI period
+      cqirep->Npd = 20;
+      cqirep->N_OFFSET_CQI = cqi_PMI_ConfigIndex-16;
+    } else if (cqi_PMI_ConfigIndex <= 76) { // 40 ms CQI_PMI period
+      cqirep->Npd = 40;
+      cqirep->N_OFFSET_CQI = cqi_PMI_ConfigIndex-36;
+    } else if (cqi_PMI_ConfigIndex <= 156) { // 80 ms CQI_PMI period
+      cqirep->Npd = 80;
+      cqirep->N_OFFSET_CQI = cqi_PMI_ConfigIndex-76;
+    } else if (cqi_PMI_ConfigIndex <= 316) { // 160 ms CQI_PMI period
+      cqirep->Npd = 160;
+      cqirep->N_OFFSET_CQI = cqi_PMI_ConfigIndex-156;
+    }
   }
 }
 
@@ -646,76 +573,66 @@ PUCCH_FMT_t get_pucch_format(lte_frame_type_t frame_type,
                              uint8_t nb_cw,
                              uint8_t cqi_status,
                              uint8_t ri_status,
-                             uint8_t bundling_flag)
-{
-  if((cqi_status == 0) && (ri_status==0))
-  {
-      // PUCCH Format 1 1a 1b
-      // 1- SR only ==> PUCCH format 1
-      // 2- 1bit Ack/Nack with/without SR  ==> PUCCH format 1a
-      // 3- 2bits Ack/Nack with/without SR ==> PUCCH format 1b
-      if((nb_cw == 1)&&(bundling_flag==bundling))
-      {
-          return pucch_format1a;
-      }
-      if((nb_cw == 1)&&(bundling_flag==multiplexing))
-      {
-          return pucch_format1b;
-      }
-      if(nb_cw == 2)
-      {
-          return pucch_format1b;
-      }
-      if(SR_payload == 1)
-      {
+                             uint8_t bundling_flag) {
+  if((cqi_status == 0) && (ri_status==0)) {
+    // PUCCH Format 1 1a 1b
+    // 1- SR only ==> PUCCH format 1
+    // 2- 1bit Ack/Nack with/without SR  ==> PUCCH format 1a
+    // 3- 2bits Ack/Nack with/without SR ==> PUCCH format 1b
+    if((nb_cw == 1)&&(bundling_flag==bundling)) {
+      return pucch_format1a;
+    }
+
+    if((nb_cw == 1)&&(bundling_flag==multiplexing)) {
+      return pucch_format1b;
+    }
+
+    if(nb_cw == 2) {
+      return pucch_format1b;
+    }
+
+    if(SR_payload == 1) {
+      return pucch_format1;
+      /*
+      if (frame_type == FDD) {
           return pucch_format1;
-          /*
-          if (frame_type == FDD) {
-              return pucch_format1;
-          } else if (frame_type == TDD) {
-              return pucch_format1b;
-          } else {
-              AssertFatal(1==0,"Unknown frame_type");
-          }*/
-      }
-  }
-  else
-  {
-      // PUCCH Format 2 2a 2b
-      // 1- CQI only or RI only  ==> PUCCH format 2
-      // 2- CQI or RI + 1bit Ack/Nack for normal CP  ==> PUCCH format 2a
-      // 3- CQI or RI + 2bits Ack/Nack for normal CP ==> PUCCH format 2b
-      // 4- CQI or RI + Ack/Nack for extended CP ==> PUCCH format 2
-      if(nb_cw == 0)
-      {
-          return pucch_format2;
-      }
-      if(cyclic_prefix_type == NORMAL)
-      {
-          if(nb_cw == 1)
-          {
-              return pucch_format2a;
-          }
-          if(nb_cw == 2)
-          {
-              return pucch_format2b;
-          }
+      } else if (frame_type == TDD) {
+          return pucch_format1b;
+      } else {
+          AssertFatal(1==0,"Unknown frame_type");
+      }*/
+    }
+  } else {
+    // PUCCH Format 2 2a 2b
+    // 1- CQI only or RI only  ==> PUCCH format 2
+    // 2- CQI or RI + 1bit Ack/Nack for normal CP  ==> PUCCH format 2a
+    // 3- CQI or RI + 2bits Ack/Nack for normal CP ==> PUCCH format 2b
+    // 4- CQI or RI + Ack/Nack for extended CP ==> PUCCH format 2
+    if(nb_cw == 0) {
+      return pucch_format2;
+    }
+
+    if(cyclic_prefix_type == NORMAL) {
+      if(nb_cw == 1) {
+        return pucch_format2a;
       }
-      else
-      {
-          return pucch_format2;
+
+      if(nb_cw == 2) {
+        return pucch_format2b;
       }
+    } else {
+      return pucch_format2;
+    }
   }
+
   return pucch_format1a;
 }
 uint16_t get_n1_pucch(PHY_VARS_UE *ue,
-          UE_rxtx_proc_t *proc,
+                      UE_rxtx_proc_t *proc,
                       harq_status_t *harq_ack,
                       uint8_t eNB_id,
                       uint8_t *b,
-                      uint8_t SR)
-{
-
+                      uint8_t SR) {
   LTE_DL_FRAME_PARMS *frame_parms=&ue->frame_parms;
   uint8_t nCCE0,nCCE1,nCCE2,nCCE3,harq_ack1,harq_ack0,harq_ack3,harq_ack2;
   ANFBmode_t bundling_flag;
@@ -727,7 +644,6 @@ uint16_t get_n1_pucch(PHY_VARS_UE *ue,
   uint8_t ack_counter=0;
   // clear this, important for case where n1_pucch selection is not used
   int subframe=proc->subframe_tx;
-
   ue->pucch_sel[subframe] = 0;
 
   if (frame_parms->frame_type == FDD ) { // FDD
@@ -739,10 +655,9 @@ uint16_t get_n1_pucch(PHY_VARS_UE *ue,
     else
       return(ue->scheduling_request_config[eNB_id].sr_PUCCH_ResourceIndex);
   } else {
-
     bundling_flag = ue->pucch_config_dedicated[eNB_id].tdd_AckNackFeedbackMode;
-    if (LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
 
+    if (LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
       if (bundling_flag==bundling) {
         LOG_D(PHY,"[UE%d] Frame %d subframe %d : get_n1_pucch, bundling, SR %d/%d\n",ue->Mod_id,proc->frame_tx,subframe,SR,
               ue->scheduling_request_config[eNB_id].sr_PUCCH_ResourceIndex);
@@ -752,179 +667,175 @@ uint16_t get_n1_pucch(PHY_VARS_UE *ue,
       }
     }
 
-
     switch (frame_parms->tdd_config) {
-    case 1:  // DL:S:UL:UL:DL:DL:S:UL:UL:DL
-
-      harq_ack0 = 2; // DTX
-      M=1;
-
-      // This is the offset for a particular subframe (2,3,4) => (0,2,4)
-      if (subframe == 2) {  // ACK subframes 5,6
-        candidate_dl[0] = 6;
-        candidate_dl[1] = 5;
-        M=2;
-      } else if (subframe == 3) { // ACK subframe 9
-        candidate_dl[0] = 9;
-      } else if (subframe == 7) { // ACK subframes 0,1
-        candidate_dl[0] = 1;
-        candidate_dl[1] = 0;
-        M=2;
-      } else if (subframe == 8) { // ACK subframes 4
-        candidate_dl[0] = 4;
-      } else {
-        LOG_E(PHY,"[UE%d] : Frame %d phy_procedures_lte.c: get_n1pucch, illegal tx-subframe %d for tdd_config %d\n",
-              ue->Mod_id,proc->frame_tx,subframe,frame_parms->tdd_config);
-        return(0);
-      }
-
-      // checking which downlink candidate is the last downlink with valid DL-DCI
-      int k;
-      for (k=0;k<M;k++) {
-        if (harq_ack[candidate_dl[k]].send_harq_status>0) {
-          last_dl = candidate_dl[k];
-          break;
+      case 1:  // DL:S:UL:UL:DL:DL:S:UL:UL:DL
+        harq_ack0 = 2; // DTX
+        M=1;
+
+        // This is the offset for a particular subframe (2,3,4) => (0,2,4)
+        if (subframe == 2) {  // ACK subframes 5,6
+          candidate_dl[0] = 6;
+          candidate_dl[1] = 5;
+          M=2;
+        } else if (subframe == 3) { // ACK subframe 9
+          candidate_dl[0] = 9;
+        } else if (subframe == 7) { // ACK subframes 0,1
+          candidate_dl[0] = 1;
+          candidate_dl[1] = 0;
+          M=2;
+        } else if (subframe == 8) { // ACK subframes 4
+          candidate_dl[0] = 4;
+        } else {
+          LOG_E(PHY,"[UE%d] : Frame %d phy_procedures_lte.c: get_n1pucch, illegal tx-subframe %d for tdd_config %d\n",
+                ue->Mod_id,proc->frame_tx,subframe,frame_parms->tdd_config);
+          return(0);
         }
-      }
-      if (last_dl >= 10) {
-        LOG_E(PHY,"[UE%d] : Frame %d phy_procedures_lte.c: get_n1pucch, illegal rx-subframe %d (tx-subframe %d) for tdd_config %d\n",
-              ue->Mod_id,proc->frame_tx,last_dl,subframe,frame_parms->tdd_config);
-        return (0);
-      }
 
-      LOG_D(PHY,"SFN/SF %d/%d calculating n1_pucch0 from last_dl=%d\n",
-          proc->frame_tx%1024,
-          proc->subframe_tx,
-          last_dl);
+        // checking which downlink candidate is the last downlink with valid DL-DCI
+        int k;
 
-      // i=0
-      nCCE0 = ue->pdcch_vars[ue->current_thread_id[proc->subframe_rx]][eNB_id]->nCCE[last_dl];
-      n1_pucch0 = get_Np(frame_parms->N_RB_DL,nCCE0,0) + nCCE0+ frame_parms->pucch_config_common.n1PUCCH_AN;
+        for (k=0; k<M; k++) {
+          if (harq_ack[candidate_dl[k]].send_harq_status>0) {
+            last_dl = candidate_dl[k];
+            break;
+          }
+        }
 
-      harq_ack0 = b[0];
+        if (last_dl >= 10) {
+          LOG_E(PHY,"[UE%d] : Frame %d phy_procedures_lte.c: get_n1pucch, illegal rx-subframe %d (tx-subframe %d) for tdd_config %d\n",
+                ue->Mod_id,proc->frame_tx,last_dl,subframe,frame_parms->tdd_config);
+          return (0);
+        }
 
-      if (harq_ack0!=2) {  // DTX
-        if (frame_parms->frame_type == FDD ) {
-          if (SR == 0) {  // last paragraph pg 68 from 36.213 (v8.6), m=0
-            b[0]=(M==2) ? 1-harq_ack0 : harq_ack0;
-            b[1]=harq_ack0;   // in case we use pucch format 1b (subframes 2,7)
-          ue->pucch_sel[subframe] = 0;
-            return(n1_pucch0);
-          } else { // SR and only 0 or 1 ACKs (first 2 entries in Table 7.3-1 of 36.213)
-            b[0]=harq_ack0;
-          return(ue->scheduling_request_config[eNB_id].sr_PUCCH_ResourceIndex);
-          }
-        } else {
-          if (SR == 0) {
-            b[0] = harq_ack0;
-            b[1] = harq_ack0;
-            ue->pucch_sel[subframe] = 0;
-            return(n1_pucch0);
+        LOG_D(PHY,"SFN/SF %d/%d calculating n1_pucch0 from last_dl=%d\n",
+              proc->frame_tx%1024,
+              proc->subframe_tx,
+              last_dl);
+        // i=0
+        nCCE0 = ue->pdcch_vars[ue->current_thread_id[proc->subframe_rx]][eNB_id]->nCCE[last_dl];
+        n1_pucch0 = get_Np(frame_parms->N_RB_DL,nCCE0,0) + nCCE0+ frame_parms->pucch_config_common.n1PUCCH_AN;
+        harq_ack0 = b[0];
+
+        if (harq_ack0!=2) {  // DTX
+          if (frame_parms->frame_type == FDD ) {
+            if (SR == 0) {  // last paragraph pg 68 from 36.213 (v8.6), m=0
+              b[0]=(M==2) ? 1-harq_ack0 : harq_ack0;
+              b[1]=harq_ack0;   // in case we use pucch format 1b (subframes 2,7)
+              ue->pucch_sel[subframe] = 0;
+              return(n1_pucch0);
+            } else { // SR and only 0 or 1 ACKs (first 2 entries in Table 7.3-1 of 36.213)
+              b[0]=harq_ack0;
+              return(ue->scheduling_request_config[eNB_id].sr_PUCCH_ResourceIndex);
+            }
           } else {
-            b[0] = harq_ack0;
-            b[1] = harq_ack0;
-            return(ue->scheduling_request_config[eNB_id].sr_PUCCH_ResourceIndex);
+            if (SR == 0) {
+              b[0] = harq_ack0;
+              b[1] = harq_ack0;
+              ue->pucch_sel[subframe] = 0;
+              return(n1_pucch0);
+            } else {
+              b[0] = harq_ack0;
+              b[1] = harq_ack0;
+              return(ue->scheduling_request_config[eNB_id].sr_PUCCH_ResourceIndex);
+            }
           }
         }
-      }
-
-
-      break;
-
-    case 3:  // DL:S:UL:UL:UL:DL:DL:DL:DL:DL
-      // in this configuration we have M=2 from pg 68 of 36.213 (v8.6)
-      // Note: this doesn't allow using subframe 1 for PDSCH transmission!!! (i.e. SF 1 cannot be acked in SF 2)
-      // set ACK/NAKs to DTX
-      harq_ack1 = 2; // DTX
-      harq_ack0 = 2; // DTX
-      // This is the offset for a particular subframe (2,3,4) => (0,2,4)
-      last_dl = (subframe-2)<<1;
-      // i=0
-      nCCE0 = ue->pdcch_vars[ue->current_thread_id[proc->subframe_rx]][eNB_id]->nCCE[5+last_dl];
-      n1_pucch0 = get_Np(frame_parms->N_RB_DL,nCCE0,0) + nCCE0+ frame_parms->pucch_config_common.n1PUCCH_AN;
-      // i=1
-      nCCE1 = ue->pdcch_vars[ue->current_thread_id[proc->subframe_rx]][eNB_id]->nCCE[(6+last_dl)%10];
-      n1_pucch1 = get_Np(frame_parms->N_RB_DL,nCCE1,1) + nCCE1 + frame_parms->pucch_config_common.n1PUCCH_AN;
-
-      // set ACK/NAK to values if not DTX
-      if (ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack[(6+last_dl)%10].send_harq_status>0)  // n-6 // subframe 6 is to be ACK/NAKed
-        harq_ack1 = ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack[(6+last_dl)%10].ack;
-
-      if (ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack[5+last_dl].send_harq_status>0)  // n-6 // subframe 5 is to be ACK/NAKed
-        harq_ack0 = ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack[5+last_dl].ack;
-
-      LOG_D(PHY,"SFN/SF %d/%d calculating n1_pucch cce0=%d n1_pucch0=%d cce1=%d n1_pucch1=%d\n",
-                                      proc->frame_tx%1024,
-                                      proc->subframe_tx,
-                                      nCCE0,n1_pucch0,
-                                      nCCE1,n1_pucch1);
-
-      if (harq_ack1!=2) { // n-6 // subframe 6,8,0 and maybe 5,7,9 is to be ACK/NAKed
-
-        if ((bundling_flag==bundling)&&(SR == 0)) {  // This is for bundling without SR,
-          // n1_pucch index takes value of smallest element in set {0,1}
-          // i.e. 0 if harq_ack0 is not DTX, otherwise 1
-          b[0] = harq_ack1;
 
-          if (harq_ack0!=2)
-            b[0]=b[0]&harq_ack0;
+        break;
+
+      case 3:  // DL:S:UL:UL:UL:DL:DL:DL:DL:DL
+        // in this configuration we have M=2 from pg 68 of 36.213 (v8.6)
+        // Note: this doesn't allow using subframe 1 for PDSCH transmission!!! (i.e. SF 1 cannot be acked in SF 2)
+        // set ACK/NAKs to DTX
+        harq_ack1 = 2; // DTX
+        harq_ack0 = 2; // DTX
+        // This is the offset for a particular subframe (2,3,4) => (0,2,4)
+        last_dl = (subframe-2)<<1;
+        // i=0
+        nCCE0 = ue->pdcch_vars[ue->current_thread_id[proc->subframe_rx]][eNB_id]->nCCE[5+last_dl];
+        n1_pucch0 = get_Np(frame_parms->N_RB_DL,nCCE0,0) + nCCE0+ frame_parms->pucch_config_common.n1PUCCH_AN;
+        // i=1
+        nCCE1 = ue->pdcch_vars[ue->current_thread_id[proc->subframe_rx]][eNB_id]->nCCE[(6+last_dl)%10];
+        n1_pucch1 = get_Np(frame_parms->N_RB_DL,nCCE1,1) + nCCE1 + frame_parms->pucch_config_common.n1PUCCH_AN;
+
+        // set ACK/NAK to values if not DTX
+        if (ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack[(6+last_dl)%10].send_harq_status>0)  // n-6 // subframe 6 is to be ACK/NAKed
+          harq_ack1 = ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack[(6+last_dl)%10].ack;
+
+        if (ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack[5+last_dl].send_harq_status>0)  // n-6 // subframe 5 is to be ACK/NAKed
+          harq_ack0 = ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack[5+last_dl].ack;
+
+        LOG_D(PHY,"SFN/SF %d/%d calculating n1_pucch cce0=%d n1_pucch0=%d cce1=%d n1_pucch1=%d\n",
+              proc->frame_tx%1024,
+              proc->subframe_tx,
+              nCCE0,n1_pucch0,
+              nCCE1,n1_pucch1);
+
+        if (harq_ack1!=2) { // n-6 // subframe 6,8,0 and maybe 5,7,9 is to be ACK/NAKed
+          if ((bundling_flag==bundling)&&(SR == 0)) {  // This is for bundling without SR,
+            // n1_pucch index takes value of smallest element in set {0,1}
+            // i.e. 0 if harq_ack0 is not DTX, otherwise 1
+            b[0] = harq_ack1;
 
-          ue->pucch_sel[subframe] = 1;
-          return(n1_pucch1);
+            if (harq_ack0!=2)
+              b[0]=b[0]&harq_ack0;
 
-        } else if ((bundling_flag==multiplexing)&&(SR==0)) { // Table 10.1
-          if (harq_ack0 == 2)
-            harq_ack0 = 0;
+            ue->pucch_sel[subframe] = 1;
+            return(n1_pucch1);
+          } else if ((bundling_flag==multiplexing)&&(SR==0)) { // Table 10.1
+            if (harq_ack0 == 2)
+              harq_ack0 = 0;
 
-          b[1] = harq_ack0;
-          b[0] = (harq_ack0!=harq_ack1)?0:1;
+            b[1] = harq_ack0;
+            b[0] = (harq_ack0!=harq_ack1)?0:1;
+
+            if ((harq_ack0 == 1) && (harq_ack1 == 0)) {
+              ue->pucch_sel[subframe] = 0;
+              return(n1_pucch0);
+            } else {
+              ue->pucch_sel[subframe] = 1;
+              return(n1_pucch1);
+            }
+          } else if (SR==1) { // SR and 0,1,or 2 ACKS, (first 3 entries in Table 7.3-1 of 36.213)
+            // this should be number of ACKs (including
+            if (harq_ack0 == 2)
+              harq_ack0 = 0;
 
-          if ((harq_ack0 == 1) && (harq_ack1 == 0)) {
+            b[0]= harq_ack1 | harq_ack0;
+            b[1]= harq_ack1 ^ harq_ack0;
+            return(ue->scheduling_request_config[eNB_id].sr_PUCCH_ResourceIndex);
+          }
+        } else if (harq_ack0!=2) { // n-7  // subframe 5,7,9 only is to be ACK/NAKed
+          if ((bundling_flag==bundling)&&(SR == 0)) {  // last paragraph pg 68 from 36.213 (v8.6), m=0
+            b[0]=harq_ack0;
             ue->pucch_sel[subframe] = 0;
             return(n1_pucch0);
-          } else {
-            ue->pucch_sel[subframe] = 1;
-            return(n1_pucch1);
+          } else if ((bundling_flag==multiplexing)&&(SR==0)) { // Table 10.1 with i=1 set to DTX
+            b[0] = harq_ack0;
+            b[1] = 1-b[0];
+            ue->pucch_sel[subframe] = 0;
+            return(n1_pucch0);
+          } else if (SR==1) { // SR and only 0 or 1 ACKs (first 2 entries in Table 7.3-1 of 36.213)
+            b[0]=harq_ack0;
+            b[1]=b[0];
+            return(ue->scheduling_request_config[eNB_id].sr_PUCCH_ResourceIndex);
           }
-        } else if (SR==1) { // SR and 0,1,or 2 ACKS, (first 3 entries in Table 7.3-1 of 36.213)
-          // this should be number of ACKs (including
-          if (harq_ack0 == 2)
-            harq_ack0 = 0;
-
-          b[0]= harq_ack1 | harq_ack0;
-          b[1]= harq_ack1 ^ harq_ack0;
-          return(ue->scheduling_request_config[eNB_id].sr_PUCCH_ResourceIndex);
-        }
-      } else if (harq_ack0!=2) { // n-7  // subframe 5,7,9 only is to be ACK/NAKed
-        if ((bundling_flag==bundling)&&(SR == 0)) {  // last paragraph pg 68 from 36.213 (v8.6), m=0
-          b[0]=harq_ack0;
-          ue->pucch_sel[subframe] = 0;
-          return(n1_pucch0);
-        } else if ((bundling_flag==multiplexing)&&(SR==0)) { // Table 10.1 with i=1 set to DTX
-          b[0] = harq_ack0;
-          b[1] = 1-b[0];
-          ue->pucch_sel[subframe] = 0;
-          return(n1_pucch0);
-        } else if (SR==1) { // SR and only 0 or 1 ACKs (first 2 entries in Table 7.3-1 of 36.213)
-          b[0]=harq_ack0;
-          b[1]=b[0];
-          return(ue->scheduling_request_config[eNB_id].sr_PUCCH_ResourceIndex);
         }
-      }
 
-      break;
+        break;
+
+      case 4:  // DL:S:UL:UL:DL:DL:DL:DL:DL:DL
+        // in this configuration we have M=4 from pg 68 of 36.213 (v8.6)
+        // Note: this doesn't allow using subframe 1 for PDSCH transmission!!! (i.e. SF 1 cannot be acked in SF 2)
+        // set ACK/NAKs to DTX
+        harq_ack3 = 2; // DTX
+        harq_ack2 = 2; // DTX
+        harq_ack1 = 2; // DTX
+        harq_ack0 = 2; // DTX
 
-    case 4:  // DL:S:UL:UL:DL:DL:DL:DL:DL:DL
-          // in this configuration we have M=4 from pg 68 of 36.213 (v8.6)
-          // Note: this doesn't allow using subframe 1 for PDSCH transmission!!! (i.e. SF 1 cannot be acked in SF 2)
-          // set ACK/NAKs to DTX
-          harq_ack3 = 2; // DTX
-          harq_ack2 = 2; // DTX
-          harq_ack1 = 2; // DTX
-          harq_ack0 = 2; // DTX
-          // This is the offset for a particular subframe (2,3,4) => (0,2,4)
-          //last_dl = (subframe-2)<<1;
-          if (subframe == 2) {
+        // This is the offset for a particular subframe (2,3,4) => (0,2,4)
+        //last_dl = (subframe-2)<<1;
+        if (subframe == 2) {
           // i=0
           //nCCE0 = ue->pdcch_vars[ue->current_thread_id[proc->subframe_rx]][eNB_id]->nCCE[2+subframe];
           nCCE0 = ue->pdcch_vars[ue->current_thread_id[proc->subframe_rx]][eNB_id]->nCCE[(8+subframe)%10];
@@ -934,8 +845,8 @@ uint16_t get_n1_pucch(PHY_VARS_UE *ue,
           n1_pucch1 = get_Np(frame_parms->N_RB_DL,nCCE1,0) + get_Np(frame_parms->N_RB_DL,nCCE1,1) + nCCE1 + frame_parms->pucch_config_common.n1PUCCH_AN;
           // i=2
           nCCE2 = ue->pdcch_vars[ue->current_thread_id[proc->subframe_rx]][eNB_id]->nCCE[(8+subframe)%10];
-
           n1_pucch2 = 2*get_Np(frame_parms->N_RB_DL,nCCE2,1) + nCCE2+ frame_parms->pucch_config_common.n1PUCCH_AN;
+
           // i=3
           //nCCE3 = ue->pdcch_vars[ue->current_thread_id[proc->subframe_rx]][eNB_id]->nCCE[(9+subframe)%10];
           //n1_pucch3 = get_Np(frame_parms->N_RB_DL,nCCE3,1) + nCCE3 + frame_parms->pucch_config_common.n1PUCCH_AN;
@@ -951,15 +862,14 @@ uint16_t get_n1_pucch(PHY_VARS_UE *ue,
             harq_ack2 = ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack[3+subframe].ack;
 
           //if (ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack[(9+subframe)%10].send_harq_status>0)  // n-6 // subframe 5 is to be ACK/NAKed
-            //harq_ack3 = ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack[(9+subframe)%10].ack;
+          //harq_ack3 = ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack[(9+subframe)%10].ack;
           //LOG_I(PHY,"SFN/SF %d/%d calculating n1_pucch cce0=%d n1_pucch0=%d cce1=%d n1_pucch1=%d cce2=%d n1_pucch2=%d\n",
           //                      proc->frame_tx%1024,
           //                      proc->subframe_tx,
           //                      nCCE0,n1_pucch0,
           //                      nCCE1,n1_pucch1, nCCE2, n1_pucch2);
-          }else if (subframe == 3) {
+        } else if (subframe == 3) {
           // i=0
-
           nCCE0 = ue->pdcch_vars[ue->current_thread_id[proc->subframe_rx]][eNB_id]->nCCE[4+subframe];
           n1_pucch0 = 3*get_Np(frame_parms->N_RB_DL,nCCE0,0) + nCCE0+ frame_parms->pucch_config_common.n1PUCCH_AN;
           // i=1
@@ -974,236 +884,238 @@ uint16_t get_n1_pucch(PHY_VARS_UE *ue,
 
           // set ACK/NAK to values if not DTX
           if (ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack[4+subframe].send_harq_status>0)  // n-6 // subframe 6 is to be ACK/NAKed
-          harq_ack0 = ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack[4+subframe].ack;
+            harq_ack0 = ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack[4+subframe].ack;
 
           if (ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack[5+subframe].send_harq_status>0)  // n-6 // subframe 5 is to be ACK/NAKed
-          harq_ack1 = ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack[5+subframe].ack;
+            harq_ack1 = ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack[5+subframe].ack;
 
           if (ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack[(6+subframe)].send_harq_status>0)  // n-6 // subframe 6 is to be ACK/NAKed
-          harq_ack2 = ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack[(6+subframe)].ack;
+            harq_ack2 = ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack[(6+subframe)].ack;
 
           if (ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack[(3+subframe)].send_harq_status>0)  // n-6 // subframe 5 is to be ACK/NAKed
-          harq_ack3 = ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack[(3+subframe)].ack;
+            harq_ack3 = ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack[(3+subframe)].ack;
+        }
+
+        //LOG_I(PHY,"SFN/SF %d/%d calculating n1_pucch cce0=%d n1_pucch0=%d harq_ack0=%d cce1=%d n1_pucch1=%d harq_ack1=%d cce2=%d n1_pucch2=%d harq_ack2=%d cce3=%d n1_pucch3=%d harq_ack3=%d bundling_flag=%d\n",
+        //                                proc->frame_tx%1024,
+        //                                proc->subframe_tx,
+        //                                nCCE0,n1_pucch0,harq_ack0,
+        //                                nCCE1,n1_pucch1,harq_ack1, nCCE2, n1_pucch2, harq_ack2,
+        //                                nCCE3, n1_pucch3, harq_ack3, bundling_flag);
+
+        if ((bundling_flag==bundling)&&(SR == 0)) {  // This is for bundling without SR,
+          b[0] = 1;
+          ack_counter = 0;
+
+          if ((harq_ack3!=2) ) {
+            b[0] = b[0]&harq_ack3;
+            n1_pucch_inter = n1_pucch3;
+            ack_counter ++;
           }
 
-          //LOG_I(PHY,"SFN/SF %d/%d calculating n1_pucch cce0=%d n1_pucch0=%d harq_ack0=%d cce1=%d n1_pucch1=%d harq_ack1=%d cce2=%d n1_pucch2=%d harq_ack2=%d cce3=%d n1_pucch3=%d harq_ack3=%d bundling_flag=%d\n",
-          //                                proc->frame_tx%1024,
-          //                                proc->subframe_tx,
-          //                                nCCE0,n1_pucch0,harq_ack0,
-          //                                nCCE1,n1_pucch1,harq_ack1, nCCE2, n1_pucch2, harq_ack2,
-          //                                nCCE3, n1_pucch3, harq_ack3, bundling_flag);
+          if ((harq_ack0!=2) ) {
+            b[0] = b[0]&harq_ack0;
+            n1_pucch_inter = n1_pucch0;
+            ack_counter ++;
+          }
 
-          if ((bundling_flag==bundling)&&(SR == 0)) {  // This is for bundling without SR,
-             b[0] = 1;
-             ack_counter = 0;
-
-             if ((harq_ack3!=2) ) {
-                b[0] = b[0]&harq_ack3;
-                n1_pucch_inter = n1_pucch3;
-                ack_counter ++;
-             }
-             if ((harq_ack0!=2) ) {
-                b[0] = b[0]&harq_ack0;
-                n1_pucch_inter = n1_pucch0;
-                ack_counter ++;
-             }
-             if ((harq_ack1!=2) ) {
-                b[0] = b[0]&harq_ack1;
-                n1_pucch_inter = n1_pucch1;
-                ack_counter ++;
-             }
-             if ((harq_ack2!=2) ) {
-                b[0] = b[0]&harq_ack2;
-                n1_pucch_inter = n1_pucch2;
-                ack_counter ++;
-             }
-
-             if (ack_counter == 0)
-                 b[0] = 0;
-
-             /*if (subframe == 3) {
-                n1_pucch_inter = n1_pucch2;
-             } else if (subframe == 2) {
-                n1_pucch_inter = n1_pucch1;
-             }*/
-
-             //LOG_I(PHY,"SFN/SF %d/%d calculating n1_pucch n1_pucch_inter=%d  b[0]=%d b[1]=%d \n",
-             //                                           proc->frame_tx%1024,
-             //                                           proc->subframe_tx,n1_pucch_inter,
-             //                                           b[0],b[1]);
-
-              return(n1_pucch_inter);
-
-            } else if ((bundling_flag==multiplexing)&&(SR==0)) { // Table 10.1
-
-             if (subframe == 3) {
-                 LOG_I(PHY, "sbuframe=%d \n",subframe);
-              if ((harq_ack0 == 1) && (harq_ack1 == 1) && (harq_ack2 == 1) && (harq_ack3 == 1)) {
-                b[0] = 1;
-                b[1] = 1;
-                return(n1_pucch1);
-              } else if ((harq_ack0 == 1) && (harq_ack1 == 1) && (harq_ack2 == 1) && ((harq_ack3 == 2) || (harq_ack3 == 0))) {
-                b[0] = 1;
-                b[1] = 0;
-                return(n1_pucch1);
-              } else if (((harq_ack0 == 0) || (harq_ack0 == 2)) && ((harq_ack1 == 2) || (harq_ack1 == 0)) && (harq_ack2 == 0) && (harq_ack3 == 2)) {
-                b[0] = 1;
-                b[1] = 1;
-                return(n1_pucch2);
-              } else if ((harq_ack0 == 1) && (harq_ack1 == 1) && ((harq_ack2 == 2) || (harq_ack2 == 0)) && (harq_ack3 == 1)) {
-                b[0] = 1;
-                b[1] = 0;
-                return(n1_pucch1);
-              } else if ((harq_ack0 == 0) && (harq_ack1 == 2) && (harq_ack2 == 2) && (harq_ack3 == 2)) {
-                b[0] = 1;
-                b[1] = 0;
-                return(n1_pucch0);
-              } else if ((harq_ack0 == 1) && (harq_ack1 == 1) && ((harq_ack2 == 2) || (harq_ack2 == 0)) && ((harq_ack3 == 2) || (harq_ack3 == 0))) {
-                b[0] = 1;
-                b[1] = 0;
-                return(n1_pucch1);
-              } else if ((harq_ack0 == 1) && ((harq_ack1 == 2) || (harq_ack1 == 0)) && (harq_ack2 == 1) && (harq_ack3 == 1)) {
-                b[0] = 0;
-                b[1] = 1;
-                return(n1_pucch3);
-              } else if (((harq_ack0 == 0) || (harq_ack0 == 2)) && ((harq_ack1 == 2) || (harq_ack1 == 0)) && ((harq_ack2 == 2) || (harq_ack2 == 0)) && (harq_ack3 == 0)) {
-                b[0] = 1;
-                b[1] = 1;
-                return(n1_pucch3);
-              } else if ((harq_ack0 == 1) && ((harq_ack1 == 2) || (harq_ack1 == 0)) && (harq_ack2 == 1) && ((harq_ack3 == 2) || (harq_ack3 == 0))) {
-                b[0] = 0;
-                b[1] = 1;
-                return(n1_pucch2);
-              } else if ((harq_ack0 == 1) && ((harq_ack1 == 2) || (harq_ack1 == 0)) && ((harq_ack2 == 2) || (harq_ack2 == 0)) && (harq_ack3 == 1)) {
-                b[0] = 0;
-                b[1] = 1;
-                return(n1_pucch0);
-              } else if ((harq_ack0 == 1) && ((harq_ack1 == 2) || (harq_ack1 == 0)) && ((harq_ack2 == 2) || (harq_ack2 == 0)) && ((harq_ack3 == 2) || (harq_ack3 == 0))) {
-                b[0] = 0;
-                b[1] = 1;
-                return(n1_pucch0);
-              } else if (((harq_ack0 == 2) || (harq_ack0 == 0)) && (harq_ack1 == 1) && (harq_ack2 == 1) && (harq_ack3 == 1)) {
-                b[0] = 0;
-                b[1] = 1;
-                return(n1_pucch3);
-              } else if (((harq_ack0 == 2) || (harq_ack0 == 0)) && (harq_ack1 == 0) && (harq_ack2 == 2) && (harq_ack3 == 2)) {
-                b[0] = 0;
-                b[1] = 0;
-                return(n1_pucch1);
-              } else if (((harq_ack0 == 2) || (harq_ack0 == 0)) && (harq_ack1 == 1) && (harq_ack2 == 1) && ((harq_ack3 == 2) || (harq_ack3 == 0))) {
-                b[0] = 1;
-                b[1] = 0;
-                return(n1_pucch2);
-              } else if (((harq_ack0 == 2) || (harq_ack0 == 0)) && (harq_ack1 == 1) && ((harq_ack2 == 2) || (harq_ack2 == 0)) && (harq_ack3 == 1)) {
-                b[0] = 1;
-                b[1] = 0;
-                return(n1_pucch3);
-              } else if (((harq_ack0 == 2) || (harq_ack0 == 0)) && (harq_ack1 == 1) && ((harq_ack2 == 2) || (harq_ack2 == 0)) && ((harq_ack3 == 2) || (harq_ack3 == 0))) {
-                b[0] = 0;
-                b[1] = 1;
-                return(n1_pucch1);
-              } else if (((harq_ack0 == 2) || (harq_ack0 == 0)) && ((harq_ack1 == 2) || (harq_ack1 == 0)) && (harq_ack2 == 1) && (harq_ack3 == 1)) {
-                b[0] = 0;
-                b[1] = 1;
-                return(n1_pucch3);
-              } else if (((harq_ack0 == 2) || (harq_ack0 == 0)) && ((harq_ack1 == 2) || (harq_ack1 == 0)) && (harq_ack2 == 1) && ((harq_ack3 == 2) || (harq_ack3 == 0))) {
-                b[0] = 0;
-                b[1] = 0;
-                return(n1_pucch2);
-              } else if (((harq_ack0 == 2) || (harq_ack0 == 0)) && ((harq_ack1 == 2) || (harq_ack1 == 0)) && (harq_ack3 == 1) && ((harq_ack2 == 2) || (harq_ack2 == 0))) {
-                b[0] = 0;
-                b[1] = 0;
-                return(n1_pucch3);
-                }
-             } else if (subframe == 2) {
-                if ((harq_ack0 == 1) && (harq_ack1 == 1) && (harq_ack2 == 1)) {
-                 b[0] = 1;
-                 b[1] = 1;
-                 return(n1_pucch2);
-               } else if ((harq_ack0 == 1) && (harq_ack1 == 1) && ((harq_ack2 == 2) || (harq_ack2 == 0))) {
-                 b[0] = 1;
-                 b[1] = 1;
-                 return(n1_pucch1);
-               } else if ((harq_ack0 == 1) && ((harq_ack1 == 2) || (harq_ack1 == 0)) && (harq_ack2 == 1)) {
-                 b[0] = 1;
-                 b[1] = 1;
-                 return(n1_pucch0);
-               } else if ((harq_ack0 == 1) && ((harq_ack1 == 2) || (harq_ack1 == 0)) && ((harq_ack2 == 2) || (harq_ack2 == 0))) {
-                 b[0] = 0;
-                 b[1] = 1;
-                 return(n1_pucch0);
-               } else if (((harq_ack0 == 2) || (harq_ack0 == 0)) && (harq_ack1 == 1) && (harq_ack2 == 1)) {
-                 b[0] = 1;
-                 b[1] = 0;
-                 return(n1_pucch2);
-               } else if (((harq_ack0 == 2) || (harq_ack0 == 0)) && (harq_ack1 == 1) && ((harq_ack2 == 2) || (harq_ack2 == 0))) {
-                 b[1] = 0;
-                 b[0] = 0;
-                 return(n1_pucch1);
-               } else if (((harq_ack0 == 2) || (harq_ack0 == 0)) && ((harq_ack1 == 2) || (harq_ack1 == 0)) && (harq_ack2 == 1)) {
-                 b[0] = 0;
-                 b[1] = 0;
-                 return(n1_pucch2);
-               } else if ((harq_ack0 == 2) && (harq_ack1 == 2) && (harq_ack2 == 0)) {
-                 b[0] = 0;
-                 b[1] = 1;
-                 return(n1_pucch2);
-               } else if ((harq_ack0 == 2) && (harq_ack1 == 0) && ((harq_ack2 == 2) || (harq_ack2 == 0))) {
-                 b[0] = 1;
-                 b[1] = 0;
-                 return(n1_pucch1);
-               } else if ((harq_ack0 == 0) && ((harq_ack1 == 2) || (harq_ack1 == 0)) && ((harq_ack2 == 2) || (harq_ack2 == 0))) {
-                 b[0] = 1;
-                 b[1] = 0;
-                 return(n1_pucch0);
-               }
-
-             }
-            } else if (SR==1) { // SR and 0,1,or 2 ACKS, (first 3 entries in Table 7.3-1 of 36.213)
-              // this should be number of ACKs (including
-              ack_counter = 0;
-              if (harq_ack0==1)
-                 ack_counter ++;
-              if (harq_ack1==1)
-                 ack_counter ++;
-              if (harq_ack2==1)
-                 ack_counter ++;
-              if (harq_ack3==1)
-                 ack_counter ++;
-
-            switch (ack_counter) {
-               case 0:
-                 b[0] = 0;
-                 b[1] = 0;
-               break;
-
-               case 1:
-                 b[0] = 1;
-                 b[1] = 1;
-               break;
-
-               case 2:
-                 b[0] = 1;
-                 b[1] = 0;
-               break;
-
-               case 3:
-                 b[0] = 0;
-                 b[1] = 1;
-               break;
-
-               case 4:
-                 b[0] = 1;
-                 b[1] = 1;
-               break;
+          if ((harq_ack1!=2) ) {
+            b[0] = b[0]&harq_ack1;
+            n1_pucch_inter = n1_pucch1;
+            ack_counter ++;
+          }
+
+          if ((harq_ack2!=2) ) {
+            b[0] = b[0]&harq_ack2;
+            n1_pucch_inter = n1_pucch2;
+            ack_counter ++;
+          }
+
+          if (ack_counter == 0)
+            b[0] = 0;
+
+          /*if (subframe == 3) {
+             n1_pucch_inter = n1_pucch2;
+          } else if (subframe == 2) {
+             n1_pucch_inter = n1_pucch1;
+          }*/
+          //LOG_I(PHY,"SFN/SF %d/%d calculating n1_pucch n1_pucch_inter=%d  b[0]=%d b[1]=%d \n",
+          //                                           proc->frame_tx%1024,
+          //                                           proc->subframe_tx,n1_pucch_inter,
+          //                                           b[0],b[1]);
+          return(n1_pucch_inter);
+        } else if ((bundling_flag==multiplexing)&&(SR==0)) { // Table 10.1
+          if (subframe == 3) {
+            LOG_I(PHY, "sbuframe=%d \n",subframe);
+
+            if ((harq_ack0 == 1) && (harq_ack1 == 1) && (harq_ack2 == 1) && (harq_ack3 == 1)) {
+              b[0] = 1;
+              b[1] = 1;
+              return(n1_pucch1);
+            } else if ((harq_ack0 == 1) && (harq_ack1 == 1) && (harq_ack2 == 1) && ((harq_ack3 == 2) || (harq_ack3 == 0))) {
+              b[0] = 1;
+              b[1] = 0;
+              return(n1_pucch1);
+            } else if (((harq_ack0 == 0) || (harq_ack0 == 2)) && ((harq_ack1 == 2) || (harq_ack1 == 0)) && (harq_ack2 == 0) && (harq_ack3 == 2)) {
+              b[0] = 1;
+              b[1] = 1;
+              return(n1_pucch2);
+            } else if ((harq_ack0 == 1) && (harq_ack1 == 1) && ((harq_ack2 == 2) || (harq_ack2 == 0)) && (harq_ack3 == 1)) {
+              b[0] = 1;
+              b[1] = 0;
+              return(n1_pucch1);
+            } else if ((harq_ack0 == 0) && (harq_ack1 == 2) && (harq_ack2 == 2) && (harq_ack3 == 2)) {
+              b[0] = 1;
+              b[1] = 0;
+              return(n1_pucch0);
+            } else if ((harq_ack0 == 1) && (harq_ack1 == 1) && ((harq_ack2 == 2) || (harq_ack2 == 0)) && ((harq_ack3 == 2) || (harq_ack3 == 0))) {
+              b[0] = 1;
+              b[1] = 0;
+              return(n1_pucch1);
+            } else if ((harq_ack0 == 1) && ((harq_ack1 == 2) || (harq_ack1 == 0)) && (harq_ack2 == 1) && (harq_ack3 == 1)) {
+              b[0] = 0;
+              b[1] = 1;
+              return(n1_pucch3);
+            } else if (((harq_ack0 == 0) || (harq_ack0 == 2)) && ((harq_ack1 == 2) || (harq_ack1 == 0)) && ((harq_ack2 == 2) || (harq_ack2 == 0)) && (harq_ack3 == 0)) {
+              b[0] = 1;
+              b[1] = 1;
+              return(n1_pucch3);
+            } else if ((harq_ack0 == 1) && ((harq_ack1 == 2) || (harq_ack1 == 0)) && (harq_ack2 == 1) && ((harq_ack3 == 2) || (harq_ack3 == 0))) {
+              b[0] = 0;
+              b[1] = 1;
+              return(n1_pucch2);
+            } else if ((harq_ack0 == 1) && ((harq_ack1 == 2) || (harq_ack1 == 0)) && ((harq_ack2 == 2) || (harq_ack2 == 0)) && (harq_ack3 == 1)) {
+              b[0] = 0;
+              b[1] = 1;
+              return(n1_pucch0);
+            } else if ((harq_ack0 == 1) && ((harq_ack1 == 2) || (harq_ack1 == 0)) && ((harq_ack2 == 2) || (harq_ack2 == 0)) && ((harq_ack3 == 2) || (harq_ack3 == 0))) {
+              b[0] = 0;
+              b[1] = 1;
+              return(n1_pucch0);
+            } else if (((harq_ack0 == 2) || (harq_ack0 == 0)) && (harq_ack1 == 1) && (harq_ack2 == 1) && (harq_ack3 == 1)) {
+              b[0] = 0;
+              b[1] = 1;
+              return(n1_pucch3);
+            } else if (((harq_ack0 == 2) || (harq_ack0 == 0)) && (harq_ack1 == 0) && (harq_ack2 == 2) && (harq_ack3 == 2)) {
+              b[0] = 0;
+              b[1] = 0;
+              return(n1_pucch1);
+            } else if (((harq_ack0 == 2) || (harq_ack0 == 0)) && (harq_ack1 == 1) && (harq_ack2 == 1) && ((harq_ack3 == 2) || (harq_ack3 == 0))) {
+              b[0] = 1;
+              b[1] = 0;
+              return(n1_pucch2);
+            } else if (((harq_ack0 == 2) || (harq_ack0 == 0)) && (harq_ack1 == 1) && ((harq_ack2 == 2) || (harq_ack2 == 0)) && (harq_ack3 == 1)) {
+              b[0] = 1;
+              b[1] = 0;
+              return(n1_pucch3);
+            } else if (((harq_ack0 == 2) || (harq_ack0 == 0)) && (harq_ack1 == 1) && ((harq_ack2 == 2) || (harq_ack2 == 0)) && ((harq_ack3 == 2) || (harq_ack3 == 0))) {
+              b[0] = 0;
+              b[1] = 1;
+              return(n1_pucch1);
+            } else if (((harq_ack0 == 2) || (harq_ack0 == 0)) && ((harq_ack1 == 2) || (harq_ack1 == 0)) && (harq_ack2 == 1) && (harq_ack3 == 1)) {
+              b[0] = 0;
+              b[1] = 1;
+              return(n1_pucch3);
+            } else if (((harq_ack0 == 2) || (harq_ack0 == 0)) && ((harq_ack1 == 2) || (harq_ack1 == 0)) && (harq_ack2 == 1) && ((harq_ack3 == 2) || (harq_ack3 == 0))) {
+              b[0] = 0;
+              b[1] = 0;
+              return(n1_pucch2);
+            } else if (((harq_ack0 == 2) || (harq_ack0 == 0)) && ((harq_ack1 == 2) || (harq_ack1 == 0)) && (harq_ack3 == 1) && ((harq_ack2 == 2) || (harq_ack2 == 0))) {
+              b[0] = 0;
+              b[1] = 0;
+              return(n1_pucch3);
+            }
+          } else if (subframe == 2) {
+            if ((harq_ack0 == 1) && (harq_ack1 == 1) && (harq_ack2 == 1)) {
+              b[0] = 1;
+              b[1] = 1;
+              return(n1_pucch2);
+            } else if ((harq_ack0 == 1) && (harq_ack1 == 1) && ((harq_ack2 == 2) || (harq_ack2 == 0))) {
+              b[0] = 1;
+              b[1] = 1;
+              return(n1_pucch1);
+            } else if ((harq_ack0 == 1) && ((harq_ack1 == 2) || (harq_ack1 == 0)) && (harq_ack2 == 1)) {
+              b[0] = 1;
+              b[1] = 1;
+              return(n1_pucch0);
+            } else if ((harq_ack0 == 1) && ((harq_ack1 == 2) || (harq_ack1 == 0)) && ((harq_ack2 == 2) || (harq_ack2 == 0))) {
+              b[0] = 0;
+              b[1] = 1;
+              return(n1_pucch0);
+            } else if (((harq_ack0 == 2) || (harq_ack0 == 0)) && (harq_ack1 == 1) && (harq_ack2 == 1)) {
+              b[0] = 1;
+              b[1] = 0;
+              return(n1_pucch2);
+            } else if (((harq_ack0 == 2) || (harq_ack0 == 0)) && (harq_ack1 == 1) && ((harq_ack2 == 2) || (harq_ack2 == 0))) {
+              b[1] = 0;
+              b[0] = 0;
+              return(n1_pucch1);
+            } else if (((harq_ack0 == 2) || (harq_ack0 == 0)) && ((harq_ack1 == 2) || (harq_ack1 == 0)) && (harq_ack2 == 1)) {
+              b[0] = 0;
+              b[1] = 0;
+              return(n1_pucch2);
+            } else if ((harq_ack0 == 2) && (harq_ack1 == 2) && (harq_ack2 == 0)) {
+              b[0] = 0;
+              b[1] = 1;
+              return(n1_pucch2);
+            } else if ((harq_ack0 == 2) && (harq_ack1 == 0) && ((harq_ack2 == 2) || (harq_ack2 == 0))) {
+              b[0] = 1;
+              b[1] = 0;
+              return(n1_pucch1);
+            } else if ((harq_ack0 == 0) && ((harq_ack1 == 2) || (harq_ack1 == 0)) && ((harq_ack2 == 2) || (harq_ack2 == 0))) {
+              b[0] = 1;
+              b[1] = 0;
+              return(n1_pucch0);
             }
+          }
+        } else if (SR==1) { // SR and 0,1,or 2 ACKS, (first 3 entries in Table 7.3-1 of 36.213)
+          // this should be number of ACKs (including
+          ack_counter = 0;
 
-            ack_counter = 0;
-            return(ue->scheduling_request_config[eNB_id].sr_PUCCH_ResourceIndex);
+          if (harq_ack0==1)
+            ack_counter ++;
+
+          if (harq_ack1==1)
+            ack_counter ++;
+
+          if (harq_ack2==1)
+            ack_counter ++;
+
+          if (harq_ack3==1)
+            ack_counter ++;
+
+          switch (ack_counter) {
+            case 0:
+              b[0] = 0;
+              b[1] = 0;
+              break;
+
+            case 1:
+              b[0] = 1;
+              b[1] = 1;
+              break;
+
+            case 2:
+              b[0] = 1;
+              b[1] = 0;
+              break;
+
+            case 3:
+              b[0] = 0;
+              b[1] = 1;
+              break;
+
+            case 4:
+              b[0] = 1;
+              b[1] = 1;
+              break;
           }
 
-          break;
+          ack_counter = 0;
+          return(ue->scheduling_request_config[eNB_id].sr_PUCCH_ResourceIndex);
+        }
 
+        break;
     }  // switch tdd_config
   }
 
@@ -1213,10 +1125,8 @@ uint16_t get_n1_pucch(PHY_VARS_UE *ue,
 
 
 void ulsch_common_procedures(PHY_VARS_UE *ue, UE_rxtx_proc_t *proc, uint8_t empty_subframe) {
-
   int aa;
   LTE_DL_FRAME_PARMS *frame_parms=&ue->frame_parms;
-
   int nsymb;
   int subframe_tx = proc->subframe_tx;
   int ulsch_start;
@@ -1225,46 +1135,43 @@ void ulsch_common_procedures(PHY_VARS_UE *ue, UE_rxtx_proc_t *proc, uint8_t empt
   int k,l;
   int dummy_tx_buffer[frame_parms->samples_per_tti] __attribute__((aligned(16)));
 #endif
-
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_TX_ULSCH_COMMON,VCD_FUNCTION_IN);
+
   if ( LOG_DEBUGFLAG(UE_TIMING)) {
     start_meas(&ue->ofdm_mod_stats);
   }
-  nsymb = (frame_parms->Ncp == 0) ? 14 : 12;
 
+  nsymb = (frame_parms->Ncp == 0) ? 14 : 12;
 #if defined(EXMIMO) || defined(OAI_USRP) || defined(OAI_BLADERF) || defined(OAI_LMSSDR)//this is the EXPRESS MIMO case
   ulsch_start = (ue->rx_offset+subframe_tx*frame_parms->samples_per_tti-
-         ue->hw_timing_advance-
-         ue->timing_advance-
-         ue->N_TA_offset+5);
+                 ue->hw_timing_advance-
+                 ue->timing_advance-
+                 ue->N_TA_offset+5);
   //LOG_E(PHY,"ul-signal [subframe: %d, ulsch_start %d]\n",subframe_tx, ulsch_start);
 
   if(ulsch_start < 0)
-      ulsch_start = ulsch_start + (LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*frame_parms->samples_per_tti);
+    ulsch_start = ulsch_start + (LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*frame_parms->samples_per_tti);
 
   if (ulsch_start > (LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*frame_parms->samples_per_tti))
-      ulsch_start = ulsch_start % (LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*frame_parms->samples_per_tti);
+    ulsch_start = ulsch_start % (LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*frame_parms->samples_per_tti);
 
   //LOG_E(PHY,"ul-signal [subframe: %d, ulsch_start %d]\n",subframe_tx, ulsch_start);
 #else //this is the normal case
   ulsch_start = (frame_parms->samples_per_tti*subframe_tx)-ue->N_TA_offset; //-ue->timing_advance;
 #endif //else EXMIMO
 
-  if (empty_subframe)
-  {
+  if (empty_subframe) {
     overflow = ulsch_start - 9*frame_parms->samples_per_tti;
+
     for (aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
-      
-      if (overflow > 0)
-	{
-	  memset(&ue->common_vars.txdata[aa][ulsch_start],0,4*(frame_parms->samples_per_tti-overflow));
-	  memset(&ue->common_vars.txdata[aa][0],0,4*overflow);
-	}
-      else
-	{
-	  memset(&ue->common_vars.txdata[aa][ulsch_start],0,4*frame_parms->samples_per_tti);
-	}
+      if (overflow > 0) {
+        memset(&ue->common_vars.txdata[aa][ulsch_start],0,4*(frame_parms->samples_per_tti-overflow));
+        memset(&ue->common_vars.txdata[aa][0],0,4*overflow);
+      } else {
+        memset(&ue->common_vars.txdata[aa][ulsch_start],0,4*frame_parms->samples_per_tti);
+      }
     }
+
     return;
   }
 
@@ -1272,32 +1179,31 @@ void ulsch_common_procedures(PHY_VARS_UE *ue, UE_rxtx_proc_t *proc, uint8_t empt
     if (frame_parms->Ncp == 1)
       PHY_ofdm_mod(&ue->common_vars.txdataF[aa][subframe_tx*nsymb*frame_parms->ofdm_symbol_size],
 #if defined(EXMIMO) || defined(OAI_USRP) || defined(OAI_BLADERF) || defined(OAI_LMSSDR)
-       dummy_tx_buffer,
+                   dummy_tx_buffer,
 #else
-       &ue->common_vars.txdata[aa][ulsch_start],
+                   &ue->common_vars.txdata[aa][ulsch_start],
 #endif
-       frame_parms->ofdm_symbol_size,
-       nsymb,
-       frame_parms->nb_prefix_samples,
-       CYCLIC_PREFIX);
+                   frame_parms->ofdm_symbol_size,
+                   nsymb,
+                   frame_parms->nb_prefix_samples,
+                   CYCLIC_PREFIX);
     else {
       normal_prefix_mod(&ue->common_vars.txdataF[aa][subframe_tx*nsymb*frame_parms->ofdm_symbol_size],
 #if defined(EXMIMO) || defined(OAI_USRP) || defined(OAI_BLADERF) || defined(OAI_LMSSDR)
-			dummy_tx_buffer,
+                        dummy_tx_buffer,
 #else
-			&ue->common_vars.txdata[aa][ulsch_start],
+                        &ue->common_vars.txdata[aa][ulsch_start],
 #endif
-			nsymb>>1,
-			&ue->frame_parms);
-      
+                        nsymb>>1,
+                        &ue->frame_parms);
       normal_prefix_mod(&ue->common_vars.txdataF[aa][((subframe_tx*nsymb)+(nsymb>>1))*frame_parms->ofdm_symbol_size],
 #if defined(EXMIMO) || defined(OAI_USRP) || defined(OAI_BLADERF) || defined(OAI_LMSSDR)
-			dummy_tx_buffer+(frame_parms->samples_per_tti>>1),
+                        dummy_tx_buffer+(frame_parms->samples_per_tti>>1),
 #else
-			&ue->common_vars.txdata[aa][ulsch_start+(frame_parms->samples_per_tti>>1)],
+                        &ue->common_vars.txdata[aa][ulsch_start+(frame_parms->samples_per_tti>>1)],
 #endif
-			nsymb>>1,
-			&ue->frame_parms);
+                        nsymb>>1,
+                        &ue->frame_parms);
     }
 
 #if defined(EXMIMO) || defined(OAI_USRP) || defined(OAI_BLADERF) || defined(OAI_LMSSDR)
@@ -1307,31 +1213,31 @@ void ulsch_common_procedures(PHY_VARS_UE *ue, UE_rxtx_proc_t *proc, uint8_t empt
     apply_7_5_kHz(ue,&ue->common_vars.txdata[aa][ulsch_start],0);
     apply_7_5_kHz(ue,&ue->common_vars.txdata[aa][ulsch_start],1);
 #endif
-
-
 #if defined(EXMIMO) || defined(OAI_USRP) || defined(OAI_BLADERF) || defined(OAI_LMSSDR)
     overflow = ulsch_start - 9*frame_parms->samples_per_tti;
 
-
     for (k=ulsch_start,l=0; k<cmin(frame_parms->samples_per_tti*LTE_NUMBER_OF_SUBFRAMES_PER_FRAME,ulsch_start+frame_parms->samples_per_tti); k++,l++) {
-      ((short*)ue->common_vars.txdata[aa])[2*k] = ((short*)dummy_tx_buffer)[2*l];
-      ((short*)ue->common_vars.txdata[aa])[2*k+1] = ((short*)dummy_tx_buffer)[2*l+1];
+      ((short *)ue->common_vars.txdata[aa])[2*k] = ((short *)dummy_tx_buffer)[2*l];
+      ((short *)ue->common_vars.txdata[aa])[2*k+1] = ((short *)dummy_tx_buffer)[2*l+1];
     }
 
     for (k=0; k<overflow; k++,l++) {
-      ((short*)ue->common_vars.txdata[aa])[2*k] = ((short*)dummy_tx_buffer)[2*l];
-      ((short*)ue->common_vars.txdata[aa])[2*k+1] = ((short*)dummy_tx_buffer)[2*l+1];
+      ((short *)ue->common_vars.txdata[aa])[2*k] = ((short *)dummy_tx_buffer)[2*l];
+      ((short *)ue->common_vars.txdata[aa])[2*k+1] = ((short *)dummy_tx_buffer)[2*l+1];
     }
+
 #if defined(EXMIMO)
+
     // handle switch before 1st TX subframe, guarantee that the slot prior to transmission is switch on
     for (k=ulsch_start - (frame_parms->samples_per_tti>>1) ; k<ulsch_start ; k++) {
       if (k<0)
-	ue->common_vars.txdata[aa][k+frame_parms->samples_per_tti*LTE_NUMBER_OF_SUBFRAMES_PER_FRAME] &= 0xFFFEFFFE;
+        ue->common_vars.txdata[aa][k+frame_parms->samples_per_tti*LTE_NUMBER_OF_SUBFRAMES_PER_FRAME] &= 0xFFFEFFFE;
       else if (k>(frame_parms->samples_per_tti*LTE_NUMBER_OF_SUBFRAMES_PER_FRAME))
-	ue->common_vars.txdata[aa][k-frame_parms->samples_per_tti*LTE_NUMBER_OF_SUBFRAMES_PER_FRAME] &= 0xFFFEFFFE;
+        ue->common_vars.txdata[aa][k-frame_parms->samples_per_tti*LTE_NUMBER_OF_SUBFRAMES_PER_FRAME] &= 0xFFFEFFFE;
       else
-	ue->common_vars.txdata[aa][k] &= 0xFFFEFFFE;
+        ue->common_vars.txdata[aa][k] &= 0xFFFEFFFE;
     }
+
 #endif
 #endif
     /*
@@ -1343,7 +1249,6 @@ void ulsch_common_procedures(PHY_VARS_UE *ue, UE_rxtx_proc_t *proc, uint8_t empt
       LOG_M("txBuff.m","txSignal",&ue->common_vars.txdata[aa][ulsch_start],frame_parms->samples_per_tti,1,1);
     }
     */
-
   } //nb_antennas_tx
 
   if ( LOG_DEBUGFLAG(UE_TIMING)) {
@@ -1351,133 +1256,120 @@ void ulsch_common_procedures(PHY_VARS_UE *ue, UE_rxtx_proc_t *proc, uint8_t empt
   }
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_TX_ULSCH_COMMON,VCD_FUNCTION_OUT);
-
 }
 
 void ue_prach_procedures(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uint8_t abstraction_flag,runmode_t mode) {
-
   int frame_tx = proc->frame_tx;
   int subframe_tx = proc->subframe_tx;
   LOG_USEDINLOG_VAR(int, prach_power);
   PRACH_RESOURCES_t prach_resources_local;
-
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_TX_PRACH, VCD_FUNCTION_IN);
-
   ue->generate_prach=0;
 
-  if (ue->mac_enabled==0){
+  if (ue->mac_enabled==0) {
     ue->prach_resources[eNB_id] = &prach_resources_local;
     prach_resources_local.ra_RNTI = 0xbeef;
     prach_resources_local.ra_PreambleIndex = 0;
   }
 
-  if (ue->mac_enabled==1){
+  if (ue->mac_enabled==1) {
     // ask L2 for RACH transport
     if ((mode != rx_calib_ue) && (mode != rx_calib_ue_med) && (mode != rx_calib_ue_byp) && (mode != no_L2_connect) ) {
       //LOG_D(PHY,"Getting PRACH resources\n");
-
       ue->prach_resources[eNB_id] = ue_get_rach(ue->Mod_id,
-						ue->CC_id,
-						frame_tx,
-						eNB_id,
-						subframe_tx);
+                                    ue->CC_id,
+                                    frame_tx,
+                                    eNB_id,
+                                    subframe_tx);
       LOG_D(PHY,"Prach resources %p\n",ue->prach_resources[eNB_id]);
     }
   }
 
   if (ue->prach_resources[eNB_id]!=NULL) {
-
     ue->generate_prach=1;
     ue->prach_cnt=0;
 #ifdef SMBV
     ue->prach_resources[eNB_id]->ra_PreambleIndex = 19;
 #endif
     LOG_I(PHY,"mode %d\n",mode);
-    
+
     if ((ue->mac_enabled==1) && (mode != calib_prach_tx)) {
       ue->tx_power_dBm[subframe_tx] = ue->prach_resources[eNB_id]->ra_PREAMBLE_RECEIVED_TARGET_POWER+get_PL(ue->Mod_id,ue->CC_id,eNB_id);
-    }
-    else {
+    } else {
       ue->tx_power_dBm[subframe_tx] = ue->tx_power_max_dBm;
       ue->prach_resources[eNB_id]->ra_PreambleIndex = 19;
     }
-    
+
     LOG_D(PHY,"[UE  %d][RAPROC] Frame %d, Subframe %d : Generating PRACH, preamble %d,PL %d,  P0_PRACH %d, TARGET_RECEIVED_POWER %d dBm, PRACH TDD Resource index %d, RA-RNTI %d\n",
-	  ue->Mod_id,
-	  frame_tx,
-	  subframe_tx,
-	  ue->prach_resources[eNB_id]->ra_PreambleIndex,
-	  get_PL(ue->Mod_id,ue->CC_id,eNB_id),
-	  ue->tx_power_dBm[subframe_tx],
-	  ue->prach_resources[eNB_id]->ra_PREAMBLE_RECEIVED_TARGET_POWER,
-	  ue->prach_resources[eNB_id]->ra_TDD_map_index,
-	  ue->prach_resources[eNB_id]->ra_RNTI);
-    
+          ue->Mod_id,
+          frame_tx,
+          subframe_tx,
+          ue->prach_resources[eNB_id]->ra_PreambleIndex,
+          get_PL(ue->Mod_id,ue->CC_id,eNB_id),
+          ue->tx_power_dBm[subframe_tx],
+          ue->prach_resources[eNB_id]->ra_PREAMBLE_RECEIVED_TARGET_POWER,
+          ue->prach_resources[eNB_id]->ra_TDD_map_index,
+          ue->prach_resources[eNB_id]->ra_RNTI);
     ue->tx_total_RE[subframe_tx] = 96;
-    
 #if defined(EXMIMO) || defined(OAI_USRP) || defined(OAI_BLADERF) || defined(OAI_LMSSDR)
     ue->prach_vars[eNB_id]->amp = get_tx_amp(ue->tx_power_dBm[subframe_tx],
-					     ue->tx_power_max_dBm,
-					     ue->frame_parms.N_RB_UL,
-					     6);
-
+                                  ue->tx_power_max_dBm,
+                                  ue->frame_parms.N_RB_UL,
+                                  6);
 #else
     ue->prach_vars[eNB_id]->amp = AMP;
 #endif
 
     if ((mode == calib_prach_tx) && (((proc->frame_tx&0xfffe)%100)==0))
       LOG_D(PHY,"[UE  %d][RAPROC] Frame %d, Subframe %d : PRACH TX power %d dBm, amp %d\n",
-	    ue->Mod_id,
-	    proc->frame_rx,
-	    proc->subframe_tx,
-	    ue->tx_power_dBm[subframe_tx],
-	    ue->prach_vars[eNB_id]->amp);
-    
-    
+            ue->Mod_id,
+            proc->frame_rx,
+            proc->subframe_tx,
+            ue->tx_power_dBm[subframe_tx],
+            ue->prach_vars[eNB_id]->amp);
+
     //      start_meas(&ue->tx_prach);
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_GENERATE_PRACH, VCD_FUNCTION_IN);
     prach_power = generate_prach(ue,eNB_id,subframe_tx,frame_tx);
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_GENERATE_PRACH, VCD_FUNCTION_OUT);
     //      stop_meas(&ue->tx_prach);
-    LOG_D(PHY,"[UE  %d][RAPROC] PRACH PL %d dB, power %d dBm, digital power %d dB (amp %d)\n",
+    LOG_I(PHY,"[UE  %d][RAPROC] PRACH PL %d dB, power %d dBm (max %d dBm), digital power %d dB (amp %d)\n",
 	  ue->Mod_id,
 	  get_PL(ue->Mod_id,ue->CC_id,eNB_id),
 	  ue->tx_power_dBm[subframe_tx],
+          ue->tx_power_max_dBm,
 	  dB_fixed(prach_power),
 	  ue->prach_vars[eNB_id]->amp);
 
-    if (ue->mac_enabled==1){
+    if (ue->mac_enabled==1) {
       Msg1_transmitted(ue->Mod_id,
-		       ue->CC_id,
-		       frame_tx,
-		       eNB_id);
+                       ue->CC_id,
+                       frame_tx,
+                       eNB_id);
     }
-    
+
     LOG_I(PHY,"[UE  %d][RAPROC] Frame %d, subframe %d: Generating PRACH (eNB %d) preamble index %d for UL, TX power %d dBm (PL %d dB), l3msg \n",
-	  ue->Mod_id,frame_tx,subframe_tx,eNB_id,
-	  ue->prach_resources[eNB_id]->ra_PreambleIndex,
-	  ue->prach_resources[eNB_id]->ra_PREAMBLE_RECEIVED_TARGET_POWER+get_PL(ue->Mod_id,ue->CC_id,eNB_id),
-	  get_PL(ue->Mod_id,ue->CC_id,eNB_id));
-    
-    
-    
+          ue->Mod_id,frame_tx,subframe_tx,eNB_id,
+          ue->prach_resources[eNB_id]->ra_PreambleIndex,
+          ue->prach_resources[eNB_id]->ra_PREAMBLE_RECEIVED_TARGET_POWER+get_PL(ue->Mod_id,ue->CC_id,eNB_id),
+          get_PL(ue->Mod_id,ue->CC_id,eNB_id));
+
     // if we're calibrating the PRACH kill the pointer to its resources so that the RA protocol doesn't continue
     if (mode == calib_prach_tx)
       ue->prach_resources[eNB_id]=NULL;
 
     LOG_D(PHY,"[UE %d] frame %d subframe %d : generate_prach %d, prach_cnt %d\n",
-	  ue->Mod_id,frame_tx,subframe_tx,ue->generate_prach,ue->prach_cnt);
-
+          ue->Mod_id,frame_tx,subframe_tx,ue->generate_prach,ue->prach_cnt);
     ue->prach_cnt++;
 
     if (ue->prach_cnt==3)
       ue->generate_prach=0;
   }
+
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_TX_PRACH, VCD_FUNCTION_OUT);
 }
 
 void ue_ulsch_uespec_procedures(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uint8_t abstraction_flag) {
-
   int harq_pid;
   int frame_tx=proc->frame_tx;
   int subframe_tx=proc->subframe_tx;
@@ -1498,76 +1390,76 @@ void ue_ulsch_uespec_procedures(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB
   uint8_t cqi_status = 0;
   uint8_t ri_status  = 0;
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_TX_ULSCH_UESPEC,VCD_FUNCTION_IN);
-
   // get harq_pid from subframe relationship
   harq_pid = subframe2harq_pid(&ue->frame_parms,
-             frame_tx,
-             subframe_tx);
-
+                               frame_tx,
+                               subframe_tx);
   LOG_D(PHY,"Frame %d, Subframe %d : ue_uespec_procedures, harq_pid %d => subframe_scheduling %d\n",
-	frame_tx,subframe_tx,harq_pid,
-	ue->ulsch[eNB_id]->harq_processes[harq_pid]->subframe_scheduling_flag);
+        frame_tx,subframe_tx,harq_pid,
+        ue->ulsch[eNB_id]->harq_processes[harq_pid]->subframe_scheduling_flag);
 
   if (ue->mac_enabled == 1) {
     if ((ue->ulsch_Msg3_active[eNB_id] == 1)       &&
-	(ue->ulsch_Msg3_frame[eNB_id] == frame_tx) &&
-	(ue->ulsch_Msg3_subframe[eNB_id] == subframe_tx)) { // Initial Transmission of Msg3
-
+        (ue->ulsch_Msg3_frame[eNB_id] == frame_tx) &&
+        (ue->ulsch_Msg3_subframe[eNB_id] == subframe_tx)) { // Initial Transmission of Msg3
       ue->ulsch[eNB_id]->harq_processes[harq_pid]->subframe_scheduling_flag = 1;
 
       if (ue->ulsch[eNB_id]->harq_processes[harq_pid]->round==0)
-	generate_ue_ulsch_params_from_rar(ue,
-					  proc,
-					  eNB_id);
+        generate_ue_ulsch_params_from_rar(ue,
+                                          proc,
+                                          eNB_id);
 
       ue->ulsch[eNB_id]->power_offset = 14;
       LOG_D(PHY,"[UE  %d][RAPROC] Frame %d: Setting Msg3_flag in subframe %d, for harq_pid %d\n",
-      Mod_id,
-      frame_tx,
-      subframe_tx,
-      harq_pid);
+            Mod_id,
+            frame_tx,
+            subframe_tx,
+            harq_pid);
       Msg3_flag = 1;
     } else {
-
-      
       AssertFatal(harq_pid!=255,"[UE%d] Frame %d subframe %d ulsch_decoding.c: FATAL ERROR: illegal harq_pid, exiting\n",
-	      Mod_id,frame_tx, subframe_tx);
+                  Mod_id,frame_tx, subframe_tx);
       Msg3_flag=0;
     }
   }
 
   if (ue->ulsch[eNB_id]->harq_processes[harq_pid]->subframe_scheduling_flag == 1) {
-
     uint8_t isBad = 0;
+
     if (ue->frame_parms.N_RB_UL <= ue->ulsch[eNB_id]->harq_processes[harq_pid]->first_rb) {
       LOG_D(PHY,"Invalid PUSCH first_RB=%d for N_RB_UL=%d\n",
-          ue->ulsch[eNB_id]->harq_processes[harq_pid]->first_rb,
-          ue->frame_parms.N_RB_UL);
+            ue->ulsch[eNB_id]->harq_processes[harq_pid]->first_rb,
+            ue->frame_parms.N_RB_UL);
       isBad = 1;
     }
+
     if (ue->frame_parms.N_RB_UL < ue->ulsch[eNB_id]->harq_processes[harq_pid]->nb_rb) {
       LOG_D(PHY,"Invalid PUSCH num_RB=%d for N_RB_UL=%d\n",
-          ue->ulsch[eNB_id]->harq_processes[harq_pid]->nb_rb,
-          ue->frame_parms.N_RB_UL);
+            ue->ulsch[eNB_id]->harq_processes[harq_pid]->nb_rb,
+            ue->frame_parms.N_RB_UL);
       isBad = 1;
     }
+
     if (0 > ue->ulsch[eNB_id]->harq_processes[harq_pid]->first_rb) {
       LOG_D(PHY,"Invalid PUSCH first_RB=%d\n",
-          ue->ulsch[eNB_id]->harq_processes[harq_pid]->first_rb);
+            ue->ulsch[eNB_id]->harq_processes[harq_pid]->first_rb);
       isBad = 1;
     }
+
     if (0 >= ue->ulsch[eNB_id]->harq_processes[harq_pid]->nb_rb) {
       LOG_D(PHY,"Invalid PUSCH num_RB=%d\n",
-          ue->ulsch[eNB_id]->harq_processes[harq_pid]->nb_rb);
+            ue->ulsch[eNB_id]->harq_processes[harq_pid]->nb_rb);
       isBad = 1;
     }
+
     if (ue->frame_parms.N_RB_UL < (ue->ulsch[eNB_id]->harq_processes[harq_pid]->nb_rb + ue->ulsch[eNB_id]->harq_processes[harq_pid]->first_rb)) {
       LOG_D(PHY,"Invalid PUSCH num_RB=%d + first_RB=%d for N_RB_UL=%d\n",
-          ue->ulsch[eNB_id]->harq_processes[harq_pid]->nb_rb,
-          ue->ulsch[eNB_id]->harq_processes[harq_pid]->first_rb,
-          ue->frame_parms.N_RB_UL);
+            ue->ulsch[eNB_id]->harq_processes[harq_pid]->nb_rb,
+            ue->ulsch[eNB_id]->harq_processes[harq_pid]->first_rb,
+            ue->frame_parms.N_RB_UL);
       isBad = 1;
     }
+
     if ((0 > ue->ulsch[eNB_id]->harq_processes[harq_pid]->rvidx) ||
         (3 < ue->ulsch[eNB_id]->harq_processes[harq_pid]->rvidx)) {
       LOG_D(PHY,"Invalid PUSCH RV index=%d\n", ue->ulsch[eNB_id]->harq_processes[harq_pid]->rvidx);
@@ -1579,273 +1471,254 @@ void ue_ulsch_uespec_procedures(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB
       ue->ulsch[eNB_id]->harq_processes[harq_pid]->subframe_scheduling_flag = 0;
     }
   }
-  if (ue->ulsch[eNB_id]->harq_processes[harq_pid]->subframe_scheduling_flag == 1) {
 
+  if (ue->ulsch[eNB_id]->harq_processes[harq_pid]->subframe_scheduling_flag == 1) {
     ue->generate_ul_signal[eNB_id] = 1;
-
     // deactivate service request
     // ue->ulsch[eNB_id]->harq_processes[harq_pid]->subframe_scheduling_flag = 0;
-    LOG_D(PHY,"Generating PUSCH (Abssubframe: %d.%d): harq-Id: %d, round: %d, MaxReTrans: %d \n",frame_tx,subframe_tx,harq_pid,ue->ulsch[eNB_id]->harq_processes[harq_pid]->round,ue->ulsch[eNB_id]->Mlimit);
-    if (ue->ulsch[eNB_id]->harq_processes[harq_pid]->round >= (ue->ulsch[eNB_id]->Mlimit - 1))
-    {
+    LOG_D(PHY,"Generating PUSCH (Abssubframe: %d.%d): harq-Id: %d, round: %d, MaxReTrans: %d \n",frame_tx,subframe_tx,harq_pid,ue->ulsch[eNB_id]->harq_processes[harq_pid]->round,
+          ue->ulsch[eNB_id]->Mlimit);
+
+    if (ue->ulsch[eNB_id]->harq_processes[harq_pid]->round >= (ue->ulsch[eNB_id]->Mlimit - 1)) {
       //        LOG_D(PHY,"PUSCH MAX Retransmission achieved ==> send last pusch\n");
-        ue->ulsch[eNB_id]->harq_processes[harq_pid]->subframe_scheduling_flag = 0;
-        ue->ulsch[eNB_id]->harq_processes[harq_pid]->round  = 0;
+      ue->ulsch[eNB_id]->harq_processes[harq_pid]->subframe_scheduling_flag = 0;
+      ue->ulsch[eNB_id]->harq_processes[harq_pid]->round  = 0;
     }
 
     ack_status_cw0 = reset_ack(&ue->frame_parms,
-            ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack,
-            subframe_tx,
-            proc->subframe_rx,
-            ue->ulsch[eNB_id]->o_ACK,
-            &Nbundled,
-            0);
+                               ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack,
+                               subframe_tx,
+                               proc->subframe_rx,
+                               ue->ulsch[eNB_id]->o_ACK,
+                               &Nbundled,
+                               0);
     ack_status_cw1 = reset_ack(&ue->frame_parms,
-            ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][1]->harq_ack,
-            subframe_tx,
-            proc->subframe_rx,
-            ue->ulsch[eNB_id]->o_ACK,
-            &NbundledCw1,
-            1);
-
+                               ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][1]->harq_ack,
+                               subframe_tx,
+                               proc->subframe_rx,
+                               ue->ulsch[eNB_id]->o_ACK,
+                               &NbundledCw1,
+                               1);
     //Nbundled = ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack;
     //ue->ulsch[eNB_id]->bundling = Nbundled;
-
     first_rb = ue->ulsch[eNB_id]->harq_processes[harq_pid]->first_rb;
     nb_rb = ue->ulsch[eNB_id]->harq_processes[harq_pid]->nb_rb;
-
-
     // check Periodic CQI/RI reporting
     cqi_status = ((ue->cqi_report_config[eNB_id].CQI_ReportPeriodic.cqi_PMI_ConfigIndex>0)&&
-        (is_cqi_TXOp(ue,proc,eNB_id)==1));
-
+                  (is_cqi_TXOp(ue,proc,eNB_id)==1));
     ri_status = ((ue->cqi_report_config[eNB_id].CQI_ReportPeriodic.ri_ConfigIndex>0) &&
-             (is_ri_TXOp(ue,proc,eNB_id)==1));
-
+                 (is_ri_TXOp(ue,proc,eNB_id)==1));
     // compute CQI/RI resources
     compute_cqi_ri_resources(ue, ue->ulsch[eNB_id], eNB_id, ue->ulsch[eNB_id]->rnti, P_RNTI, CBA_RNTI, cqi_status, ri_status);
 
     if (ack_status_cw0 > 0) {
-
       // check if we received a PDSCH at subframe_tx - 4
       // ==> send ACK/NACK on PUSCH
-      if (ue->frame_parms.frame_type == FDD)
-      {
+      if (ue->frame_parms.frame_type == FDD) {
         ue->ulsch[eNB_id]->harq_processes[harq_pid]->O_ACK = ack_status_cw0 + ack_status_cw1;
       }
 
+      if ( LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
+        if(ue->ulsch[eNB_id]->o_ACK[0]) {
+          LOG_I(PHY,"PUSCH ACK\n");
+          T(T_UE_PHY_DLSCH_UE_ACK, T_INT(eNB_id), T_INT(frame_tx%1024), T_INT(subframe_tx), T_INT(ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->rnti),
+            T_INT(ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->current_harq_pid));
+        } else {
+          LOG_I(PHY,"PUSCH NACK\n");
+          T(T_UE_PHY_DLSCH_UE_NACK, T_INT(eNB_id), T_INT(frame_tx%1024), T_INT(subframe_tx), T_INT(ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->rnti),
+            T_INT(ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->current_harq_pid));
+        }
 
-    if ( LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
-      if(ue->ulsch[eNB_id]->o_ACK[0])
-      {
-  	  LOG_I(PHY,"PUSCH ACK\n");
-  	  T(T_UE_PHY_DLSCH_UE_ACK, T_INT(eNB_id), T_INT(frame_tx%1024), T_INT(subframe_tx), T_INT(ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->rnti),
-  			T_INT(ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->current_harq_pid));
-      }
-      else
-      {
-  	  LOG_I(PHY,"PUSCH NACK\n");
-  	  T(T_UE_PHY_DLSCH_UE_NACK, T_INT(eNB_id), T_INT(frame_tx%1024), T_INT(subframe_tx), T_INT(ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->rnti),
-  			T_INT(ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->current_harq_pid));
+        LOG_I(PHY,"[UE  %d][PDSCH %x] AbsSubFrame %d.%d Generating ACK (%d,%d) for %d bits on PUSCH\n",
+              Mod_id,
+              ue->ulsch[eNB_id]->rnti,
+              frame_tx%1024,subframe_tx,
+              ue->ulsch[eNB_id]->o_ACK[0],ue->ulsch[eNB_id]->o_ACK[1],
+              ue->ulsch[eNB_id]->harq_processes[harq_pid]->O_ACK);
       }
-  	LOG_I(PHY,"[UE  %d][PDSCH %x] AbsSubFrame %d.%d Generating ACK (%d,%d) for %d bits on PUSCH\n",
-  	  Mod_id,
-  	  ue->ulsch[eNB_id]->rnti,
-  	  frame_tx%1024,subframe_tx,
-  	  ue->ulsch[eNB_id]->o_ACK[0],ue->ulsch[eNB_id]->o_ACK[1],
-  	  ue->ulsch[eNB_id]->harq_processes[harq_pid]->O_ACK);
     }
-  }
 
-
-    if ( LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)){
-        LOG_D(PHY,
-              "[UE  %d][PUSCH %d] AbsSubframe %d.%d Generating PUSCH : first_rb %d, nb_rb %d, round %d, mcs %d, rv %d, "
-              "cyclic_shift %d (cyclic_shift_common %d,n_DMRS2 %d,n_PRS %d), ACK (%d,%d), O_ACK %d, ack_status_cw0 %d ack_status_cw1 %d bundling %d, Nbundled %d, CQI %d, RI %d\n",
-          Mod_id,harq_pid,frame_tx%1024,subframe_tx,
-          first_rb,nb_rb,
-          ue->ulsch[eNB_id]->harq_processes[harq_pid]->round,
-          ue->ulsch[eNB_id]->harq_processes[harq_pid]->mcs,
-          ue->ulsch[eNB_id]->harq_processes[harq_pid]->rvidx,
-          (ue->frame_parms.pusch_config_common.ul_ReferenceSignalsPUSCH.cyclicShift+
-           ue->ulsch[eNB_id]->harq_processes[harq_pid]->n_DMRS2+
-           ue->frame_parms.pusch_config_common.ul_ReferenceSignalsPUSCH.nPRS[subframe_tx<<1])%12,
-          ue->frame_parms.pusch_config_common.ul_ReferenceSignalsPUSCH.cyclicShift,
-          ue->ulsch[eNB_id]->harq_processes[harq_pid]->n_DMRS2,
-          ue->frame_parms.pusch_config_common.ul_ReferenceSignalsPUSCH.nPRS[subframe_tx<<1],
-          ue->ulsch[eNB_id]->o_ACK[0],ue->ulsch[eNB_id]->o_ACK[1],
-          ue->ulsch[eNB_id]->harq_processes[harq_pid]->O_ACK,
-          ack_status_cw0,
-          ack_status_cw1,
-          ue->ulsch[eNB_id]->bundling, Nbundled,
-          cqi_status,
-          ri_status);
+    if ( LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
+      LOG_D(PHY,
+            "[UE  %d][PUSCH %d] AbsSubframe %d.%d Generating PUSCH : first_rb %d, nb_rb %d, round %d, mcs %d, rv %d, "
+            "cyclic_shift %d (cyclic_shift_common %d,n_DMRS2 %d,n_PRS %d), ACK (%d,%d), O_ACK %d, ack_status_cw0 %d ack_status_cw1 %d bundling %d, Nbundled %d, CQI %d, RI %d\n",
+            Mod_id,harq_pid,frame_tx%1024,subframe_tx,
+            first_rb,nb_rb,
+            ue->ulsch[eNB_id]->harq_processes[harq_pid]->round,
+            ue->ulsch[eNB_id]->harq_processes[harq_pid]->mcs,
+            ue->ulsch[eNB_id]->harq_processes[harq_pid]->rvidx,
+            (ue->frame_parms.pusch_config_common.ul_ReferenceSignalsPUSCH.cyclicShift+
+             ue->ulsch[eNB_id]->harq_processes[harq_pid]->n_DMRS2+
+             ue->frame_parms.pusch_config_common.ul_ReferenceSignalsPUSCH.nPRS[subframe_tx<<1])%12,
+            ue->frame_parms.pusch_config_common.ul_ReferenceSignalsPUSCH.cyclicShift,
+            ue->ulsch[eNB_id]->harq_processes[harq_pid]->n_DMRS2,
+            ue->frame_parms.pusch_config_common.ul_ReferenceSignalsPUSCH.nPRS[subframe_tx<<1],
+            ue->ulsch[eNB_id]->o_ACK[0],ue->ulsch[eNB_id]->o_ACK[1],
+            ue->ulsch[eNB_id]->harq_processes[harq_pid]->O_ACK,
+            ack_status_cw0,
+            ack_status_cw1,
+            ue->ulsch[eNB_id]->bundling, Nbundled,
+            cqi_status,
+            ri_status);
     }
 
-
-
-
-
     if (Msg3_flag == 1) {
       LOG_I(PHY,"[UE  %d][RAPROC] Frame %d, Subframe %d Generating (RRCConnectionRequest) Msg3 (nb_rb %d, first_rb %d, round %d, rvidx %d) Msg3: %x.%x.%x|%x.%x.%x.%x.%x.%x\n",Mod_id,frame_tx,
-	    subframe_tx,
-	    ue->ulsch[eNB_id]->harq_processes[harq_pid]->nb_rb,
-	    ue->ulsch[eNB_id]->harq_processes[harq_pid]->first_rb,
-	    ue->ulsch[eNB_id]->harq_processes[harq_pid]->round,
-	    ue->ulsch[eNB_id]->harq_processes[harq_pid]->rvidx,
-	    ue->prach_resources[eNB_id]->Msg3[0],
-	    ue->prach_resources[eNB_id]->Msg3[1],
-	    ue->prach_resources[eNB_id]->Msg3[2],
-	    ue->prach_resources[eNB_id]->Msg3[3],
-	    ue->prach_resources[eNB_id]->Msg3[4],
-	    ue->prach_resources[eNB_id]->Msg3[5],
-	    ue->prach_resources[eNB_id]->Msg3[6],
-	    ue->prach_resources[eNB_id]->Msg3[7],
-	    ue->prach_resources[eNB_id]->Msg3[8]);
-    if ( LOG_DEBUGFLAG(UE_TIMING)) {
-      start_meas(&ue->ulsch_encoding_stats);
-    }
-      
+            subframe_tx,
+            ue->ulsch[eNB_id]->harq_processes[harq_pid]->nb_rb,
+            ue->ulsch[eNB_id]->harq_processes[harq_pid]->first_rb,
+            ue->ulsch[eNB_id]->harq_processes[harq_pid]->round,
+            ue->ulsch[eNB_id]->harq_processes[harq_pid]->rvidx,
+            ue->prach_resources[eNB_id]->Msg3[0],
+            ue->prach_resources[eNB_id]->Msg3[1],
+            ue->prach_resources[eNB_id]->Msg3[2],
+            ue->prach_resources[eNB_id]->Msg3[3],
+            ue->prach_resources[eNB_id]->Msg3[4],
+            ue->prach_resources[eNB_id]->Msg3[5],
+            ue->prach_resources[eNB_id]->Msg3[6],
+            ue->prach_resources[eNB_id]->Msg3[7],
+            ue->prach_resources[eNB_id]->Msg3[8]);
+
+      if ( LOG_DEBUGFLAG(UE_TIMING)) {
+        start_meas(&ue->ulsch_encoding_stats);
+      }
+
       AssertFatal(ulsch_encoding(ue->prach_resources[eNB_id]->Msg3,
-				 ue,
-				 harq_pid,
-				 eNB_id,
-				 proc->subframe_rx,
-				 ue->transmission_mode[eNB_id],0,0)==0,
-		  "ulsch_coding.c: FATAL ERROR: returning\n");
-      
-    if ( LOG_DEBUGFLAG(UE_TIMING)) {
-      stop_meas(&ue->phy_proc_tx);
-      LOG_UI(PHY,"------FULL TX PROC : %5.2f ------\n",ue->phy_proc_tx.p_time/(cpuf*1000.0));
-      stop_meas(&ue->ulsch_encoding_stats);
-    }
+                                 ue,
+                                 harq_pid,
+                                 eNB_id,
+                                 proc->subframe_rx,
+                                 ue->transmission_mode[eNB_id],0,0)==0,
+                  "ulsch_coding.c: FATAL ERROR: returning\n");
+
+      if ( LOG_DEBUGFLAG(UE_TIMING)) {
+        stop_meas(&ue->phy_proc_tx);
+        LOG_I(PHY,"------FULL TX PROC : %5.2f ------\n",ue->phy_proc_tx.p_time/(cpuf*1000.0));
+        stop_meas(&ue->ulsch_encoding_stats);
+      }
 
       if (ue->mac_enabled == 1) {
-
-	// signal MAC that Msg3 was sent
-	Msg3_transmitted(Mod_id,
-			 CC_id,
-			 frame_tx,
-			 eNB_id);
+        // signal MAC that Msg3 was sent
+        Msg3_transmitted(Mod_id,
+                         CC_id,
+                         frame_tx,
+                         eNB_id);
       }
+
       LOG_I(PHY,"Done Msg3 encoding\n");
     } // Msg3_flag==1
     else {// Msg3_flag==0
       input_buffer_length = ue->ulsch[eNB_id]->harq_processes[harq_pid]->TBS/8;
 
       if (ue->mac_enabled==1) {
+        //  LOG_D(PHY,"[UE  %d] ULSCH : Searching for MAC SDUs\n",Mod_id);
+        if (ue->ulsch[eNB_id]->harq_processes[harq_pid]->round==0) {
+          //if (ue->ulsch[eNB_id]->harq_processes[harq_pid]->calibration_flag == 0) {
+          access_mode=SCHEDULED_ACCESS;
+          ue_get_sdu(Mod_id,
+                     CC_id,
+                     frame_tx,
+                     subframe_tx,
+                     eNB_id,
+                     ulsch_input_buffer,
+                     input_buffer_length,
+                     &access_mode);
+        }
 
-	//  LOG_D(PHY,"[UE  %d] ULSCH : Searching for MAC SDUs\n",Mod_id);
-	if (ue->ulsch[eNB_id]->harq_processes[harq_pid]->round==0) {
-	  //if (ue->ulsch[eNB_id]->harq_processes[harq_pid]->calibration_flag == 0) {
-	  access_mode=SCHEDULED_ACCESS;
-
-	  ue_get_sdu(Mod_id,
-		     CC_id,
-		     frame_tx,
-		     subframe_tx,
-		     eNB_id,
-		     ulsch_input_buffer,
-		     input_buffer_length,
-		     &access_mode);
-	}
-	
-      
-
-	
-      if (LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
-	LOG_D(PHY,"[UE] Frame %d, subframe %d : ULSCH SDU (TX harq_pid %d)  (%d bytes) : \n",frame_tx,subframe_tx,harq_pid, ue->ulsch[eNB_id]->harq_processes[harq_pid]->TBS>>3);
-	
-	for (i=0; i<ue->ulsch[eNB_id]->harq_processes[harq_pid]->TBS>>3; i++)
-	  LOG_T(PHY,"%x.",ulsch_input_buffer[i]);
-	
-	LOG_T(PHY,"\n");
+        if (LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
+          LOG_D(PHY,"[UE] Frame %d, subframe %d : ULSCH SDU (TX harq_pid %d)  (%d bytes) : \n",frame_tx,subframe_tx,harq_pid, ue->ulsch[eNB_id]->harq_processes[harq_pid]->TBS>>3);
+
+          for (i=0; i<ue->ulsch[eNB_id]->harq_processes[harq_pid]->TBS>>3; i++)
+            LOG_T(PHY,"%x.",ulsch_input_buffer[i]);
+
+          LOG_T(PHY,"\n");
+        }
+      } else {
+        unsigned int taus(void);
+
+        for (i=0; i<input_buffer_length; i++)
+          ulsch_input_buffer[i]= (uint8_t)(taus()&0xff);
+      }
+
+      if ( LOG_DEBUGFLAG(UE_TIMING)) {
+        start_meas(&ue->ulsch_encoding_stats);
       }
-     } else {
-	unsigned int taus(void);
-	
-	for (i=0; i<input_buffer_length; i++)
-	  ulsch_input_buffer[i]= (uint8_t)(taus()&0xff);
-	
-     }
-      
-     if ( LOG_DEBUGFLAG(UE_TIMING)) {
-      start_meas(&ue->ulsch_encoding_stats);
-     }
+
       if (abstraction_flag==0) {
-	
-	if (ulsch_encoding(ulsch_input_buffer,
-			   ue,
-			   harq_pid,
-			   eNB_id,
-			   proc->subframe_rx,
-			   ue->transmission_mode[eNB_id],0,
-			   Nbundled)!=0) {
-	  LOG_E(PHY,"ulsch_coding.c: FATAL ERROR: returning\n");
-	  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_TX, VCD_FUNCTION_OUT);
+        if (ulsch_encoding(ulsch_input_buffer,
+                           ue,
+                           harq_pid,
+                           eNB_id,
+                           proc->subframe_rx,
+                           ue->transmission_mode[eNB_id],0,
+                           Nbundled)!=0) {
+          LOG_E(PHY,"ulsch_coding.c: FATAL ERROR: returning\n");
+          VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_TX, VCD_FUNCTION_OUT);
+
           if (LOG_DEBUGFLAG(UE_TIMING)) {
-	    stop_meas(&ue->phy_proc_tx);
+            stop_meas(&ue->phy_proc_tx);
           }
-	  return;
-	}
+
+          return;
+        }
       }
-      
+
       if(LOG_DEBUGFLAG(UE_TIMING)) {
         stop_meas(&ue->ulsch_encoding_stats);
       }
     }
-    
+
     if (abstraction_flag == 0) {
       if (ue->mac_enabled==1) {
-	pusch_power_cntl(ue,proc,eNB_id,1, abstraction_flag);
-	ue->tx_power_dBm[subframe_tx] = ue->ulsch[eNB_id]->Po_PUSCH;
-      }
-      else {
-	ue->tx_power_dBm[subframe_tx] = ue->tx_power_max_dBm;
+        pusch_power_cntl(ue,proc,eNB_id,1, abstraction_flag);
+        ue->tx_power_dBm[subframe_tx] = ue->ulsch[eNB_id]->Po_PUSCH;
+      } else {
+        ue->tx_power_dBm[subframe_tx] = ue->tx_power_max_dBm;
       }
+
       ue->tx_total_RE[subframe_tx] = nb_rb*12;
-      
 #if defined(EXMIMO) || defined(OAI_USRP) || defined(OAI_BLADERF) || defined(OAI_LMSSDR)
       tx_amp = get_tx_amp(ue->tx_power_dBm[subframe_tx],
-			  ue->tx_power_max_dBm,
-			  ue->frame_parms.N_RB_UL,
-			  nb_rb);
+                          ue->tx_power_max_dBm,
+                          ue->frame_parms.N_RB_UL,
+                          nb_rb);
 #else
-    tx_amp = AMP;
+      tx_amp = AMP;
 #endif
+      T(T_UE_PHY_PUSCH_TX_POWER, T_INT(eNB_id), T_INT(frame_tx%1024), T_INT(subframe_tx),T_INT(ue->tx_power_dBm[subframe_tx]),
+        T_INT(tx_amp),T_INT(ue->ulsch[eNB_id]->f_pusch),T_INT(get_PL(Mod_id,0,eNB_id)),T_INT(nb_rb));
+
+      if (LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
+        LOG_D(PHY,"[UE  %d][PUSCH %d] AbsSubFrame %d.%d, generating PUSCH, Po_PUSCH: %d dBm (max %d dBm), amp %d\n",
+              Mod_id,harq_pid,frame_tx%1024,subframe_tx,ue->tx_power_dBm[subframe_tx],ue->tx_power_max_dBm, tx_amp);
+      }
 
-    T(T_UE_PHY_PUSCH_TX_POWER, T_INT(eNB_id), T_INT(frame_tx%1024), T_INT(subframe_tx),T_INT(ue->tx_power_dBm[subframe_tx]),
-      T_INT(tx_amp),T_INT(ue->ulsch[eNB_id]->f_pusch),T_INT(get_PL(Mod_id,0,eNB_id)),T_INT(nb_rb));
+      if (LOG_DEBUGFLAG(UE_TIMING)) {
+        start_meas(&ue->ulsch_modulation_stats);
+      }
 
-    if (LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
-      LOG_D(PHY,"[UE  %d][PUSCH %d] AbsSubFrame %d.%d, generating PUSCH, Po_PUSCH: %d dBm (max %d dBm), amp %d\n",
-	    Mod_id,harq_pid,frame_tx%1024,subframe_tx,ue->tx_power_dBm[subframe_tx],ue->tx_power_max_dBm, tx_amp);
-    }
-    if (LOG_DEBUGFLAG(UE_TIMING)) {
-      start_meas(&ue->ulsch_modulation_stats);
-    }
-    ulsch_modulation(ue->common_vars.txdataF,
-		     tx_amp,
-		     frame_tx,
-		     subframe_tx,
-		     &ue->frame_parms,
-		     ue->ulsch[eNB_id]);
-    for (aa=0; aa<1/*frame_parms->nb_antennas_tx*/; aa++)
-      generate_drs_pusch(ue,
-			 proc,
-			 eNB_id,
-			 tx_amp,
-			 subframe_tx,
-			 first_rb,
-			 nb_rb,
-			 aa);
+      ulsch_modulation(ue->common_vars.txdataF,
+                       tx_amp,
+                       frame_tx,
+                       subframe_tx,
+                       &ue->frame_parms,
+                       ue->ulsch[eNB_id]);
+
+      for (aa=0; aa<1/*frame_parms->nb_antennas_tx*/; aa++)
+        generate_drs_pusch(ue,
+                           proc,
+                           eNB_id,
+                           tx_amp,
+                           subframe_tx,
+                           first_rb,
+                           nb_rb,
+                           aa);
 
-    if (LOG_DEBUGFLAG(UE_TIMING)) {
-      stop_meas(&ue->ulsch_modulation_stats);
+      if (LOG_DEBUGFLAG(UE_TIMING)) {
+        stop_meas(&ue->ulsch_modulation_stats);
+      }
     }
 
-    }
-    
     if (abstraction_flag==1) {
       // clear SR
       ue->sr[subframe_tx]=0;
@@ -1853,84 +1726,72 @@ void ue_ulsch_uespec_procedures(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB
   } // subframe_scheduling_flag==1
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_TX_ULSCH_UESPEC,VCD_FUNCTION_OUT);
-
 }
 
-void ue_srs_procedures(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uint8_t abstraction_flag)
-{
-
+void ue_srs_procedures(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uint8_t abstraction_flag) {
   //LTE_DL_FRAME_PARMS *frame_parms = &ue->frame_parms;
   //int8_t  frame_tx    = proc->frame_tx;
   int8_t  subframe_tx = proc->subframe_tx;
   int16_t tx_amp;
   int16_t Po_SRS;
   uint8_t nb_rb_srs;
-
   SOUNDINGRS_UL_CONFIG_DEDICATED *pSoundingrs_ul_config_dedicated=&ue->soundingrs_ul_config_dedicated[eNB_id];
   uint8_t isSrsTxOccasion = pSoundingrs_ul_config_dedicated->srsUeSubframe;
 
-  if(isSrsTxOccasion)
-  {
+  if(isSrsTxOccasion) {
     ue->generate_ul_signal[eNB_id] = 1;
-    if (ue->mac_enabled==1)
-    {
-      srs_power_cntl(ue,proc,eNB_id, (uint8_t*)(&nb_rb_srs), abstraction_flag);
+
+    if (ue->mac_enabled==1) {
+      srs_power_cntl(ue,proc,eNB_id, (uint8_t *)(&nb_rb_srs), abstraction_flag);
       Po_SRS = ue->ulsch[eNB_id]->Po_SRS;
-    }
-    else
-    {
+    } else {
       Po_SRS = ue->tx_power_max_dBm;
     }
 
 #if defined(EXMIMO) || defined(OAI_USRP) || defined(OAI_BLADERF) || defined(OAI_LMSSDR)
-    if (ue->mac_enabled==1)
-    {
-    tx_amp = get_tx_amp(Po_SRS,
-                        ue->tx_power_max_dBm,
-                        ue->frame_parms.N_RB_UL,
-                        nb_rb_srs);
-    }
-    else
-    {
-        tx_amp = AMP;
+
+    if (ue->mac_enabled==1) {
+      tx_amp = get_tx_amp(Po_SRS,
+                          ue->tx_power_max_dBm,
+                          ue->frame_parms.N_RB_UL,
+                          nb_rb_srs);
+    } else {
+      tx_amp = AMP;
     }
+
 #else
-      tx_amp = AMP;
+    tx_amp = AMP;
 #endif
     LOG_D(PHY,"SRS PROC; TX_MAX_POWER %d, Po_SRS %d, NB_RB_UL %d, NB_RB_SRS %d TX_AMPL %d\n",ue->tx_power_max_dBm,
-            Po_SRS,
-            ue->frame_parms.N_RB_UL,
-            nb_rb_srs,
-            tx_amp);
-
+          Po_SRS,
+          ue->frame_parms.N_RB_UL,
+          nb_rb_srs,
+          tx_amp);
     uint16_t nsymb = (ue->frame_parms.Ncp==0) ? 14:12;
     uint16_t symbol_offset = (int)ue->frame_parms.ofdm_symbol_size*((subframe_tx*nsymb)+(nsymb-1));
     generate_srs(&ue->frame_parms,
-     &ue->soundingrs_ul_config_dedicated[eNB_id],
-     &ue->common_vars.txdataF[eNB_id][symbol_offset],
-     tx_amp,
-     subframe_tx);
+                 &ue->soundingrs_ul_config_dedicated[eNB_id],
+                 &ue->common_vars.txdataF[eNB_id][symbol_offset],
+                 tx_amp,
+                 subframe_tx);
   }
 }
 
 int16_t get_pucch2_cqi(PHY_VARS_UE *ue,int eNB_id,int *len) {
-
   if ((ue->transmission_mode[eNB_id]<4)||
       (ue->transmission_mode[eNB_id]==7)) { // Mode 1-0 feedback
     // 4-bit CQI message
-          /*LOG_I(PHY,"compute CQI value, TM %d, length 4, Cqi Avg %d, value %d \n", ue->transmission_mode[eNB_id],
-                          ue->measurements.wideband_cqi_avg[eNB_id],
-                          sinr2cqi((double)ue->measurements.wideband_cqi_avg[eNB_id],
-                                    ue->transmission_mode[eNB_id]));*/
+    /*LOG_I(PHY,"compute CQI value, TM %d, length 4, Cqi Avg %d, value %d \n", ue->transmission_mode[eNB_id],
+                    ue->measurements.wideband_cqi_avg[eNB_id],
+                    sinr2cqi((double)ue->measurements.wideband_cqi_avg[eNB_id],
+                              ue->transmission_mode[eNB_id]));*/
     *len=4;
     return(sinr2cqi((double)ue->measurements.wideband_cqi_avg[eNB_id],
-        ue->transmission_mode[eNB_id]));
-  }
-  else { // Mode 1-1 feedback, later
-          //LOG_I(PHY,"compute CQI value, TM %d, length 0, Cqi Avg 0 \n", ue->transmission_mode[eNB_id]);
+                    ue->transmission_mode[eNB_id]));
+  } else { // Mode 1-1 feedback, later
+    //LOG_I(PHY,"compute CQI value, TM %d, length 0, Cqi Avg 0 \n", ue->transmission_mode[eNB_id]);
     *len=0;
     // 2-antenna ports RI=1, 6 bits (2 PMI, 4 CQI)
-
     // 2-antenna ports RI=2, 8 bits (1 PMI, 7 CQI/DIFF CQI)
     return(0);
   }
@@ -1938,7 +1799,6 @@ int16_t get_pucch2_cqi(PHY_VARS_UE *ue,int eNB_id,int *len) {
 
 
 int16_t get_pucch2_ri(PHY_VARS_UE *ue,int eNB_id) {
-
   return(1);
 }
 
@@ -1952,15 +1812,12 @@ void get_pucch_param(PHY_VARS_UE    *ue,
                      uint8_t        cqi_report,
                      uint16_t       *pucch_resource,
                      uint8_t        *pucch_payload,
-                     uint16_t       *plength)
-{
-
-    switch (format) {
-    case pucch_format1:
-    {
-        pucch_resource[0] = ue->scheduling_request_config[eNB_id].sr_PUCCH_ResourceIndex;
-        pucch_payload[0]  = 0; // payload is ignored in case of format1
-        pucch_payload[1]  = 0; // payload is ignored in case of format1
+                     uint16_t       *plength) {
+  switch (format) {
+    case pucch_format1: {
+      pucch_resource[0] = ue->scheduling_request_config[eNB_id].sr_PUCCH_ResourceIndex;
+      pucch_payload[0]  = 0; // payload is ignored in case of format1
+      pucch_payload[1]  = 0; // payload is ignored in case of format1
     }
     break;
 
@@ -1968,58 +1825,50 @@ void get_pucch_param(PHY_VARS_UE    *ue,
     case pucch_format1b:
     case pucch_format1b_csA2:
     case pucch_format1b_csA3:
-    case pucch_format1b_csA4:
-    {
-        pucch_resource[0] = get_n1_pucch(ue,
-                                         proc,
-                                         ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack,
-                                         eNB_id,
-                                         ack_payload,
-                                         SR);
-        pucch_payload[0]  = ack_payload[0];
-        pucch_payload[1]  = ack_payload[1];
-        //pucch_payload[1]  = 1;
+    case pucch_format1b_csA4: {
+      pucch_resource[0] = get_n1_pucch(ue,
+                                       proc,
+                                       ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack,
+                                       eNB_id,
+                                       ack_payload,
+                                       SR);
+      pucch_payload[0]  = ack_payload[0];
+      pucch_payload[1]  = ack_payload[1];
+      //pucch_payload[1]  = 1;
     }
     break;
 
-    case pucch_format2:
-    {
-        pucch_resource[0]    = ue->cqi_report_config[eNB_id].CQI_ReportPeriodic.cqi_PUCCH_ResourceIndex;
-        if(cqi_report)
-        {
-            pucch_payload[0] = get_pucch2_cqi(ue,eNB_id,(int*)plength);
-        }
-        else
-        {
-            *plength = 1;
-            pucch_payload[0] = get_pucch2_ri(ue,eNB_id);
-        }
+    case pucch_format2: {
+      pucch_resource[0]    = ue->cqi_report_config[eNB_id].CQI_ReportPeriodic.cqi_PUCCH_ResourceIndex;
+
+      if(cqi_report) {
+        pucch_payload[0] = get_pucch2_cqi(ue,eNB_id,(int *)plength);
+      } else {
+        *plength = 1;
+        pucch_payload[0] = get_pucch2_ri(ue,eNB_id);
+      }
     }
     break;
 
     case pucch_format2a:
     case pucch_format2b:
-        LOG_E(PHY,"NO Resource available for PUCCH 2a/2b \n");
-    break;
+      LOG_E(PHY,"NO Resource available for PUCCH 2a/2b \n");
+      break;
 
     case pucch_format3:
       fprintf(stderr, "PUCCH format 3 not handled\n");
       abort();
-    }
+  }
 }
 
 void ue_pucch_procedures(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uint8_t abstraction_flag) {
-
-
   uint8_t  pucch_ack_payload[2];
   uint16_t pucch_resource;
   ANFBmode_t bundling_flag;
   PUCCH_FMT_t format;
-
   uint8_t  SR_payload;
   uint8_t  pucch_payload[2];
   uint16_t len;
-
   LTE_DL_FRAME_PARMS *frame_parms = &ue->frame_parms;
   int frame_tx=proc->frame_tx;
   int subframe_tx=proc->subframe_tx;
@@ -2032,94 +1881,71 @@ void ue_pucch_procedures(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uin
   uint8_t nb_cw=0;
   uint8_t cqi_status=0;
   uint8_t ri_status=0;
-
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_TX_PUCCH,VCD_FUNCTION_IN);
-
   SOUNDINGRS_UL_CONFIG_DEDICATED *pSoundingrs_ul_config_dedicated=&ue->soundingrs_ul_config_dedicated[eNB_id];
-
   // 36.213 8.2
   /*if ackNackSRS_SimultaneousTransmission ==  TRUE and in the cell specific SRS subframes UE shall transmit
     ACK/NACK and SR using the shortened PUCCH format. This shortened PUCCH format shall be used in a cell
     specific SRS subframe even if the UE does not transmit SRS in that subframe
   */
-
   int harq_pid = subframe2harq_pid(&ue->frame_parms,
                                    frame_tx,
                                    subframe_tx);
 
-  if(ue->ulsch[eNB_id]->harq_processes[harq_pid]->subframe_scheduling_flag)
-  {
-      LOG_D(PHY,"PUSCH is programmed on this subframe [pid %d] AbsSuframe %d.%d ==> Skip PUCCH transmission \n",harq_pid,frame_tx,subframe_tx);
-      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_TX_PUCCH,VCD_FUNCTION_OUT);
-      return;
+  if(ue->ulsch[eNB_id]->harq_processes[harq_pid]->subframe_scheduling_flag) {
+    LOG_D(PHY,"PUSCH is programmed on this subframe [pid %d] AbsSuframe %d.%d ==> Skip PUCCH transmission \n",harq_pid,frame_tx,subframe_tx);
+    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_TX_PUCCH,VCD_FUNCTION_OUT);
+    return;
   }
 
   uint8_t isShortenPucch = (pSoundingrs_ul_config_dedicated->srsCellSubframe && frame_parms->soundingrs_ul_config_common.ackNackSRS_SimultaneousTransmission);
-
   bundling_flag = ue->pucch_config_dedicated[eNB_id].tdd_AckNackFeedbackMode;
 
-  if ((frame_parms->frame_type==FDD) ||
-      (bundling_flag==bundling)    ||
-      ((frame_parms->frame_type==TDD)&&(frame_parms->tdd_config==1)&&((subframe_tx!=2)||(subframe_tx!=7)))) {
-    format = pucch_format1a;
-    //    LOG_D(PHY,"[UE] PUCCH 1a\n");
-  } else {
-    format = pucch_format1b;
-    //    LOG_D(PHY,"[UE] PUCCH 1b\n");
-  }
-
   // Part - I
   // Collect feedback that should be transmitted at this subframe
   // - SR
   // - ACK/NACK
   // - CQI
   // - RI
-
   SR_payload = 0;
-  if (is_SR_TXOp(ue,proc,eNB_id)==1)
-  {
-      if (ue->mac_enabled==1) {
-	SR_payload = ue_get_SR(Mod_id,
-			       CC_id,
-			       frame_tx,
-			       eNB_id,
-			       ue->pdcch_vars[ue->current_thread_id[proc->subframe_rx]][eNB_id]->crnti,
-			       subframe_tx); // subframe used for meas gap
-      }
-      else {
-          SR_payload = 1;
-      }
+
+  if (is_SR_TXOp(ue,proc,eNB_id)==1) {
+    if (ue->mac_enabled==1) {
+      SR_payload = ue_get_SR(Mod_id,
+                             CC_id,
+                             frame_tx,
+                             eNB_id,
+                             ue->pdcch_vars[ue->current_thread_id[proc->subframe_rx]][eNB_id]->crnti,
+                             subframe_tx); // subframe used for meas gap
+    } else {
+      SR_payload = 1;
+    }
   }
 
   ack_status_cw0 = get_ack(&ue->frame_parms,
-                       ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack,
-                       subframe_tx,
-                       proc->subframe_rx,
-                       pucch_ack_payload,
-                       0);
-
+                           ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack,
+                           subframe_tx,
+                           proc->subframe_rx,
+                           pucch_ack_payload,
+                           0);
   ack_status_cw1 = get_ack(&ue->frame_parms,
-                       ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][1]->harq_ack,
-                       subframe_tx,
-                       proc->subframe_rx,
-                       pucch_ack_payload,
-                       1);
-
+                           ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][1]->harq_ack,
+                           subframe_tx,
+                           proc->subframe_rx,
+                           pucch_ack_payload,
+                           1);
   nb_cw = ( (ack_status_cw0 != 0) ? 1:0) + ( (ack_status_cw1 != 0) ? 1:0);
-
   cqi_status = ((ue->cqi_report_config[eNB_id].CQI_ReportPeriodic.cqi_PMI_ConfigIndex>0)&&
-      (is_cqi_TXOp(ue,proc,eNB_id)==1));
-
+                (is_cqi_TXOp(ue,proc,eNB_id)==1));
   ri_status = ((ue->cqi_report_config[eNB_id].CQI_ReportPeriodic.ri_ConfigIndex>0) &&
-           (is_ri_TXOp(ue,proc,eNB_id)==1));
+               (is_ri_TXOp(ue,proc,eNB_id)==1));
 
   // Part - II
   // if nothing to report ==> exit function
-  if( (nb_cw==0) && (SR_payload==0) && (cqi_status==0) && (ri_status==0) )
-  {
-      LOG_D(PHY,"PUCCH No feedback AbsSubframe %d.%d SR_payload %d nb_cw %d pucch_ack_payload[0] %d pucch_ack_payload[1] %d cqi_status %d Return \n",
-            frame_tx%1024, subframe_tx, SR_payload, nb_cw, pucch_ack_payload[0], pucch_ack_payload[1], cqi_status);
-      return;
+  if( (nb_cw==0) && (SR_payload==0) && (cqi_status==0) && (ri_status==0) ) {
+    LOG_D(PHY,"PUCCH No feedback AbsSubframe %d.%d SR_payload %d nb_cw %d pucch_ack_payload[0] %d pucch_ack_payload[1] %d cqi_status %d Return \n",
+          frame_tx%1024, subframe_tx, SR_payload, nb_cw, pucch_ack_payload[0], pucch_ack_payload[1], cqi_status);
+    return;
   }
 
   // Part - III
@@ -2142,184 +1968,169 @@ void ue_pucch_procedures(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uin
                   &pucch_resource,
                   (uint8_t *)&pucch_payload,
                   &len);
-
-
   LOG_D(PHY,"PUCCH feedback AbsSubframe %d.%d SR %d NbCW %d (%d %d) AckNack %d.%d CQI %d RI %d format %d pucch_resource %d pucch_payload %d %d \n",
-	frame_tx%1024, subframe_tx, SR_payload, nb_cw, ack_status_cw0, ack_status_cw1, pucch_ack_payload[0], pucch_ack_payload[1], cqi_status, ri_status, format, pucch_resource,pucch_payload[0],pucch_payload[1]);
-
+        frame_tx%1024, subframe_tx, SR_payload, nb_cw, ack_status_cw0, ack_status_cw1, pucch_ack_payload[0], pucch_ack_payload[1], cqi_status, ri_status, format, pucch_resource,pucch_payload[0],
+        pucch_payload[1]);
   // Part - IV
   // Generate PUCCH signal
   ue->generate_ul_signal[eNB_id] = 1;
 
   switch (format) {
-  case pucch_format1:
-  case pucch_format1a:
-  case pucch_format1b:
-  {
-    if (ue->mac_enabled == 1) {
-      Po_PUCCH = pucch_power_cntl(ue,proc,subframe_tx,eNB_id,format);
-    }
-    else {
-      Po_PUCCH = ue->tx_power_max_dBm;
-    }
-    ue->tx_power_dBm[subframe_tx] = Po_PUCCH;
-    ue->tx_total_RE[subframe_tx] = 12;
-    
+    case pucch_format1:
+    case pucch_format1a:
+    case pucch_format1b: {
+      if (ue->mac_enabled == 1) {
+        Po_PUCCH = pucch_power_cntl(ue,proc,subframe_tx,eNB_id,format);
+      } else {
+        Po_PUCCH = ue->tx_power_max_dBm;
+      }
+
+      ue->tx_power_dBm[subframe_tx] = Po_PUCCH;
+      ue->tx_total_RE[subframe_tx] = 12;
 #if defined(EXMIMO) || defined(OAI_USRP) || defined(OAI_BLADERF) || defined(OAI_LMSSDR)
-    tx_amp = get_tx_amp(Po_PUCCH,
-			ue->tx_power_max_dBm,
-			ue->frame_parms.N_RB_UL,
-			1);
+      tx_amp = get_tx_amp(Po_PUCCH,
+                          ue->tx_power_max_dBm,
+                          ue->frame_parms.N_RB_UL,
+                          1);
 #else
-    tx_amp = AMP;
+      tx_amp = AMP;
 #endif
+      T(T_UE_PHY_PUCCH_TX_POWER, T_INT(eNB_id), T_INT(frame_tx%1024), T_INT(subframe_tx),T_INT(ue->tx_power_dBm[subframe_tx]),
+        T_INT(tx_amp),T_INT(ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->g_pucch),T_INT(get_PL(ue->Mod_id,ue->CC_id,eNB_id)));
 
-    T(T_UE_PHY_PUCCH_TX_POWER, T_INT(eNB_id), T_INT(frame_tx%1024), T_INT(subframe_tx),T_INT(ue->tx_power_dBm[subframe_tx]),
-      T_INT(tx_amp),T_INT(ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->g_pucch),T_INT(get_PL(ue->Mod_id,ue->CC_id,eNB_id)));
-    
-      if(format == pucch_format1)
-	{
-          LOG_D(PHY,"[UE  %d][SR %x] AbsSubframe %d.%d Generating PUCCH 1 (SR for PUSCH), an_srs_simultanous %d, shorten_pucch %d, n1_pucch %d, Po_PUCCH %d\n",
-		Mod_id,
-		ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->rnti,
-		frame_tx%1024, subframe_tx,
-		frame_parms->soundingrs_ul_config_common.ackNackSRS_SimultaneousTransmission,
-		isShortenPucch,
-		ue->scheduling_request_config[eNB_id].sr_PUCCH_ResourceIndex,
-		Po_PUCCH);
-      }
-      else
-      {
-          if (SR_payload>0) {
-              LOG_D(PHY,"[UE  %d][SR %x] AbsSubFrame %d.%d Generating PUCCH %s payload %d,%d (with SR for PUSCH), an_srs_simultanous %d, shorten_pucch %d, n1_pucch %d, Po_PUCCH %d, amp %d\n",
-                      Mod_id,
-                      ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->rnti,
-                      frame_tx % 1024, subframe_tx,
-                      (format == pucch_format1a? "1a": (
-                              format == pucch_format1b? "1b" : "??")),
-                              pucch_ack_payload[0],pucch_ack_payload[1],
-                              frame_parms->soundingrs_ul_config_common.ackNackSRS_SimultaneousTransmission,
-                              isShortenPucch,
-                              pucch_resource,
-                              Po_PUCCH,
-                              tx_amp);
-          } else {
-              LOG_D(PHY,"[UE  %d][PDSCH %x] AbsSubFrame %d.%d rx_offset_diff: %d, Generating PUCCH %s, an_srs_simultanous %d, shorten_pucch %d, n1_pucch %d, b[0]=%d,b[1]=%d (SR_Payload %d), Po_PUCCH %d, amp %d\n",
-                      Mod_id,
-                      ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->rnti,
-                      frame_tx%1024, subframe_tx,ue->rx_offset_diff,
-                      (format == pucch_format1a? "1a": (
-                              format == pucch_format1b? "1b" : "??")),
-                              frame_parms->soundingrs_ul_config_common.ackNackSRS_SimultaneousTransmission,
-                              isShortenPucch,
-                              pucch_resource,pucch_payload[0],pucch_payload[1],SR_payload,
-                              Po_PUCCH,
-                              tx_amp);
-          }
+      if(format == pucch_format1) {
+        LOG_D(PHY,"[UE  %d][SR %x] AbsSubframe %d.%d Generating PUCCH 1 (SR for PUSCH), an_srs_simultanous %d, shorten_pucch %d, n1_pucch %d, Po_PUCCH %d\n",
+              Mod_id,
+              ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->rnti,
+              frame_tx%1024, subframe_tx,
+              frame_parms->soundingrs_ul_config_common.ackNackSRS_SimultaneousTransmission,
+              isShortenPucch,
+              ue->scheduling_request_config[eNB_id].sr_PUCCH_ResourceIndex,
+              Po_PUCCH);
+      } else {
+        if (SR_payload>0) {
+          LOG_D(PHY,"[UE  %d][SR %x] AbsSubFrame %d.%d Generating PUCCH %s payload %d,%d (with SR for PUSCH), an_srs_simultanous %d, shorten_pucch %d, n1_pucch %d, Po_PUCCH %d, amp %d\n",
+                Mod_id,
+                ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->rnti,
+                frame_tx % 1024, subframe_tx,
+                (format == pucch_format1a? "1a": (
+                   format == pucch_format1b? "1b" : "??")),
+                pucch_ack_payload[0],pucch_ack_payload[1],
+                frame_parms->soundingrs_ul_config_common.ackNackSRS_SimultaneousTransmission,
+                isShortenPucch,
+                pucch_resource,
+                Po_PUCCH,
+                tx_amp);
+        } else {
+          LOG_D(PHY,"[UE  %d][PDSCH %x] AbsSubFrame %d.%d rx_offset_diff: %d, Generating PUCCH %s, an_srs_simultanous %d, shorten_pucch %d, n1_pucch %d, b[0]=%d,b[1]=%d (SR_Payload %d), Po_PUCCH %d, amp %d\n",
+                Mod_id,
+                ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->rnti,
+                frame_tx%1024, subframe_tx,ue->rx_offset_diff,
+                (format == pucch_format1a? "1a": (
+                   format == pucch_format1b? "1b" : "??")),
+                frame_parms->soundingrs_ul_config_common.ackNackSRS_SimultaneousTransmission,
+                isShortenPucch,
+                pucch_resource,pucch_payload[0],pucch_payload[1],SR_payload,
+                Po_PUCCH,
+                tx_amp);
+        }
       }
 
-
       if (LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
-  	if(pucch_payload[0])
-  	{
-  	    T(T_UE_PHY_DLSCH_UE_ACK, T_INT(eNB_id), T_INT(frame_tx%1024), T_INT(subframe_tx), T_INT(ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->rnti),
-  		    T_INT(ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->current_harq_pid));
-  	}
-  	else
-  	{
-  	    T(T_UE_PHY_DLSCH_UE_NACK, T_INT(eNB_id), T_INT(frame_tx%1024), T_INT(subframe_tx), T_INT(ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->rnti),
-  		    T_INT(ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->current_harq_pid));
-  	}
+        if(pucch_payload[0]) {
+          T(T_UE_PHY_DLSCH_UE_ACK, T_INT(eNB_id), T_INT(frame_tx%1024), T_INT(subframe_tx), T_INT(ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->rnti),
+            T_INT(ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->current_harq_pid));
+        } else {
+          T(T_UE_PHY_DLSCH_UE_NACK, T_INT(eNB_id), T_INT(frame_tx%1024), T_INT(subframe_tx), T_INT(ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->rnti),
+            T_INT(ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->current_harq_pid));
+        }
       }
 
       generate_pucch1x(ue->common_vars.txdataF,
-		       &ue->frame_parms,
-		       ue->ncs_cell,
-		       format,
-		       &ue->pucch_config_dedicated[eNB_id],
-		       pucch_resource,
-		       isShortenPucch,  // shortened format
-		       pucch_payload,
-		       tx_amp,
-		       subframe_tx);
-      
-  }
-  break;
-
+                       &ue->frame_parms,
+                       ue->ncs_cell,
+                       format,
+                       &ue->pucch_config_dedicated[eNB_id],
+                       pucch_resource,
+                       isShortenPucch,  // shortened format
+                       pucch_payload,
+                       tx_amp,
+                       subframe_tx);
+    }
+    break;
 
-  case pucch_format2:
-  {
+    case pucch_format2: {
       if (ue->mac_enabled == 1) {
-          Po_PUCCH = pucch_power_cntl(ue,proc,subframe_tx,eNB_id,format);
-      }
-      else {
-          Po_PUCCH = ue->tx_power_max_dBm;
+        Po_PUCCH = pucch_power_cntl(ue,proc,subframe_tx,eNB_id,format);
+      } else {
+        Po_PUCCH = ue->tx_power_max_dBm;
       }
+
       ue->tx_power_dBm[subframe_tx] = Po_PUCCH;
       ue->tx_total_RE[subframe_tx] = 12;
-
 #if defined(EXMIMO) || defined(OAI_USRP) || defined(OAI_BLADERF) || defined(OAI_LMSSDR)
       tx_amp =  get_tx_amp(Po_PUCCH,
-              ue->tx_power_max_dBm,
-              ue->frame_parms.N_RB_UL,
-              1);
+                           ue->tx_power_max_dBm,
+                           ue->frame_parms.N_RB_UL,
+                           1);
 #else
       tx_amp = AMP;
 #endif
       T(T_UE_PHY_PUCCH_TX_POWER, T_INT(eNB_id), T_INT(frame_tx%1024), T_INT(subframe_tx),T_INT(ue->tx_power_dBm[subframe_tx]),
-              T_INT(tx_amp),T_INT(ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->g_pucch),T_INT(get_PL(ue->Mod_id,ue->CC_id,eNB_id)));
+        T_INT(tx_amp),T_INT(ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->g_pucch),T_INT(get_PL(ue->Mod_id,ue->CC_id,eNB_id)));
+
       if( LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
-  	LOG_D(PHY,"[UE  %d][RNTI %x] AbsSubFrame %d.%d Generating PUCCH 2 (RI or CQI), Po_PUCCH %d, isShortenPucch %d, amp %d\n",
-  		Mod_id,
-  		ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->rnti,
-  		frame_tx%1024, subframe_tx,
-  		Po_PUCCH,
-  		isShortenPucch,
-  		tx_amp);
+        LOG_D(PHY,"[UE  %d][RNTI %x] AbsSubFrame %d.%d Generating PUCCH 2 (RI or CQI), Po_PUCCH %d, isShortenPucch %d, amp %d\n",
+              Mod_id,
+              ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->rnti,
+              frame_tx%1024, subframe_tx,
+              Po_PUCCH,
+              isShortenPucch,
+              tx_amp);
       }
+
       generate_pucch2x(ue->common_vars.txdataF,
-              &ue->frame_parms,
-              ue->ncs_cell,
-              format,
-              &ue->pucch_config_dedicated[eNB_id],
-              pucch_resource,
-              pucch_payload,
-              len,          // A
-              0,            // B2 not needed
-              tx_amp,
-              subframe_tx,
-              ue->pdcch_vars[ue->current_thread_id[proc->subframe_rx]][eNB_id]->crnti);
-  }
-  break;
+                       &ue->frame_parms,
+                       ue->ncs_cell,
+                       format,
+                       &ue->pucch_config_dedicated[eNB_id],
+                       pucch_resource,
+                       pucch_payload,
+                       len,          // A
+                       0,            // B2 not needed
+                       tx_amp,
+                       subframe_tx,
+                       ue->pdcch_vars[ue->current_thread_id[proc->subframe_rx]][eNB_id]->crnti);
+    }
+    break;
 
-  case pucch_format2a:
+    case pucch_format2a:
       LOG_D(PHY,"[UE  %d][RNTI %x] AbsSubFrame %d.%d Generating PUCCH 2a (RI or CQI) Ack/Nack 1bit \n",
-              Mod_id,
-              ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->rnti,
-              frame_tx%1024, subframe_tx);
+            Mod_id,
+            ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->rnti,
+            frame_tx%1024, subframe_tx);
       break;
-  case pucch_format2b:
+
+    case pucch_format2b:
       LOG_D(PHY,"[UE  %d][RNTI %x] AbsSubFrame %d.%d Generating PUCCH 2b (RI or CQI) Ack/Nack 2bits\n",
-              Mod_id,
-              ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->rnti,
-              frame_tx%1024, subframe_tx);
+            Mod_id,
+            ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->rnti,
+            frame_tx%1024, subframe_tx);
       break;
-  default:
+
+    default:
       break;
   }
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_TX_PUCCH,VCD_FUNCTION_OUT);
-
 }
 
 void phy_procedures_UE_SL_TX(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc) {
-
   int subframe_tx = proc->subframe_tx;
   int frame_tx = proc->frame_tx;
   SLSS_t *slss;
   SLDCH_t *sldch;
   SLSCH_t *slsch;
-
   LOG_D(PHY,"****** start Sidelink TX-Chain for AbsSubframe %d.%d ******\n", frame_tx, subframe_tx);
 
   // check for SLBCH/SLSS
@@ -2330,78 +2141,61 @@ void phy_procedures_UE_SL_TX(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc) {
 
   // check for SLSCH
   if ((slsch = ue_get_slsch(ue->Mod_id,ue->CC_id,frame_tx,subframe_tx)) != NULL) generate_slsch(ue,slsch,frame_tx,subframe_tx);
-
 }
 
 void phy_procedures_UE_TX(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uint8_t abstraction_flag,runmode_t mode) {
-
-
   LTE_DL_FRAME_PARMS *frame_parms=&ue->frame_parms;
   //int32_t ulsch_start=0;
   int subframe_tx = proc->subframe_tx;
   int frame_tx = proc->frame_tx;
   unsigned int aa;
   uint8_t isSubframeSRS;
-
   uint8_t next1_thread_id = ue->current_thread_id[proc->subframe_rx]== (RX_NB_TH-1) ? 0:(ue->current_thread_id[proc->subframe_rx]+1);
   uint8_t next2_thread_id = next1_thread_id== (RX_NB_TH-1) ? 0:(next1_thread_id+1);
-
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_TX,VCD_FUNCTION_IN);
-
   LOG_D(PHY,"****** start TX-Chain for AbsSubframe %d.%d ******\n", frame_tx, subframe_tx);
-
   T(T_UE_PHY_UL_TICK, T_INT(ue->Mod_id), T_INT(frame_tx%1024), T_INT(subframe_tx));
-
-
   ue->generate_ul_signal[eNB_id] = 0;
+
   if ( LOG_DEBUGFLAG(UE_TIMING)) {
     start_meas(&ue->phy_proc_tx);
   }
 
   ue->tx_power_dBm[subframe_tx]=-127;
 
-      
   for (aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
     memset(&ue->common_vars.txdataF[aa][subframe_tx*frame_parms->ofdm_symbol_size*frame_parms->symbols_per_tti],
-	   0,
-	   frame_parms->ofdm_symbol_size*frame_parms->symbols_per_tti*sizeof(int32_t));
+           0,
+           frame_parms->ofdm_symbol_size*frame_parms->symbols_per_tti*sizeof(int32_t));
   }
-  
+
   if (subframe_select(&ue->frame_parms,proc->subframe_tx) == SF_UL ||
       ue->frame_parms.frame_type == FDD) {    
-    if (ue->UE_mode[eNB_id] != PRACH ) {
+    if (ue->UE_mode[eNB_id] > PRACH ) {
       // check cell srs subframe and ue srs subframe. This has an impact on pusch encoding
       isSubframeSRS = is_srs_occasion_common(&ue->frame_parms,proc->frame_tx,proc->subframe_tx);
-      
       ue_compute_srs_occasion(ue,proc,eNB_id,isSubframeSRS);
-      
       ue_ulsch_uespec_procedures(ue,proc,eNB_id,abstraction_flag);
-      
       LOG_D(PHY,"ULPOWERS After ulsch_uespec_procedures : ue->tx_power_dBm[%d]=%d, NPRB %d\n",
-	    subframe_tx,ue->tx_power_dBm[subframe_tx],ue->tx_total_RE[subframe_tx]);
+            subframe_tx,ue->tx_power_dBm[subframe_tx],ue->tx_total_RE[subframe_tx]);
     }
-    
+
     if (ue->UE_mode[eNB_id] == PUSCH) {
       // check if we need to use PUCCH 1a/1b
       ue_pucch_procedures(ue,proc,eNB_id,abstraction_flag);
       // check if we need to use SRS
       ue_srs_procedures(ue,proc,eNB_id,abstraction_flag);
     } // UE_mode==PUSCH
-
   }
-  	
 
   LOG_D(PHY,"doing ulsch_common_procedures (%d.%d): generate_ul_signal %d\n",frame_tx,subframe_tx,
-	ue->generate_ul_signal[eNB_id]);	
+        ue->generate_ul_signal[eNB_id]);
   ulsch_common_procedures(ue,proc, (ue->generate_ul_signal[eNB_id] == 0));
-        
-  if ((ue->UE_mode[eNB_id] == PRACH) && 
-      (ue->frame_parms.prach_config_common.prach_Config_enabled==1)) {
 
+  if ((ue->UE_mode[eNB_id] == PRACH) &&
+      (ue->frame_parms.prach_config_common.prach_Config_enabled==1)) {
     // check if we have PRACH opportunity
-
     if (is_prach_subframe(&ue->frame_parms,frame_tx,subframe_tx)) {
-
       ue_prach_procedures(ue,proc,eNB_id,abstraction_flag,mode);
     }
   } // mode is PRACH
@@ -2411,131 +2205,113 @@ void phy_procedures_UE_TX(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,ui
 
   // reset DL ACK/NACK status
   uint8_t N_bundled = 0;
-  if (ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0] != NULL)
-  {
+
+  if (ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0] != NULL) {
     reset_ack(&ue->frame_parms,
-               ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack,
-               subframe_tx,
-               proc->subframe_rx,
-               ue->ulsch[eNB_id]->o_ACK,
-               &N_bundled,
-               0);
+              ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->harq_ack,
+              subframe_tx,
+              proc->subframe_rx,
+              ue->ulsch[eNB_id]->o_ACK,
+              &N_bundled,
+              0);
     reset_ack(&ue->frame_parms,
-               ue->dlsch[next1_thread_id][eNB_id][0]->harq_ack,
-               subframe_tx,
-               proc->subframe_rx,
-               ue->ulsch[eNB_id]->o_ACK,
-               &N_bundled,
-               0);
+              ue->dlsch[next1_thread_id][eNB_id][0]->harq_ack,
+              subframe_tx,
+              proc->subframe_rx,
+              ue->ulsch[eNB_id]->o_ACK,
+              &N_bundled,
+              0);
     reset_ack(&ue->frame_parms,
-               ue->dlsch[next2_thread_id][eNB_id][0]->harq_ack,
-               subframe_tx,
-               proc->subframe_rx,
-               ue->ulsch[eNB_id]->o_ACK,
-               &N_bundled,
-               0);
+              ue->dlsch[next2_thread_id][eNB_id][0]->harq_ack,
+              subframe_tx,
+              proc->subframe_rx,
+              ue->ulsch[eNB_id]->o_ACK,
+              &N_bundled,
+              0);
   }
 
   if (ue->dlsch_SI[eNB_id] != NULL)
     reset_ack(&ue->frame_parms,
-             ue->dlsch_SI[eNB_id]->harq_ack,
-             subframe_tx,
-             proc->subframe_rx,
-             ue->ulsch[eNB_id]->o_ACK,
-             &N_bundled,
-             0);
-
+              ue->dlsch_SI[eNB_id]->harq_ack,
+              subframe_tx,
+              proc->subframe_rx,
+              ue->ulsch[eNB_id]->o_ACK,
+              &N_bundled,
+              0);
 
   LOG_D(PHY,"****** end TX-Chain for AbsSubframe %d.%d ******\n", frame_tx, subframe_tx);
-
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_TX, VCD_FUNCTION_OUT);
+
   if ( LOG_DEBUGFLAG(UE_TIMING)) {
     stop_meas(&ue->phy_proc_tx);
   }
 }
 
-void phy_procedures_UE_S_TX(PHY_VARS_UE *ue,uint8_t eNB_id,uint8_t abstraction_flag)
-{
+void phy_procedures_UE_S_TX(PHY_VARS_UE *ue,uint8_t eNB_id,uint8_t abstraction_flag) {
   int aa;//i,aa;
   LTE_DL_FRAME_PARMS *frame_parms=&ue->frame_parms;
 
-  
   for (aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
 #if defined(EXMIMO) //this is the EXPRESS MIMO case
     int i;
+
     // set the whole tx buffer to RX
     for (i=0; i<LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*frame_parms->samples_per_tti; i++)
       ue->common_vars.txdata[aa][i] = 0x00010001;
-    
+
 #else //this is the normal case
     //    memset(&ue->common_vars.txdata[aa][0],0,
-    //	   (LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*frame_parms->samples_per_tti)*sizeof(int32_t));
+    //     (LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*frame_parms->samples_per_tti)*sizeof(int32_t));
 #endif //else EXMIMO
-    
   }
-  
 }
 
 void ue_measurement_procedures(
-    uint16_t l,    // symbol index of each slot [0..6]
-    PHY_VARS_UE *ue,UE_rxtx_proc_t *proc, uint8_t eNB_id,
-    uint16_t slot, // slot index of each radio frame [0..19]
-    uint8_t abstraction_flag,runmode_t mode)
-{
-
+  uint16_t l,    // symbol index of each slot [0..6]
+  PHY_VARS_UE *ue,UE_rxtx_proc_t *proc, uint8_t eNB_id,
+  uint16_t slot, // slot index of each radio frame [0..19]
+  uint8_t abstraction_flag,runmode_t mode) {
   //LOG_I(PHY,"ue_measurement_procedures l %d Ncp %d\n",l,ue->frame_parms.Ncp);
-
   LTE_DL_FRAME_PARMS *frame_parms=&ue->frame_parms;
-
   int subframe_rx = proc->subframe_rx;
-
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_MEASUREMENT_PROCEDURES, VCD_FUNCTION_IN);
 
   if (l==0) {
     // UE measurements on symbol 0
-
     LOG_D(PHY,"Calling measurements subframe %d, rxdata %p\n",subframe_rx,ue->common_vars.rxdata);
-      LOG_D(PHY,"Calling measurements subframe %d, rxdata %p\n",subframe_rx,ue->common_vars.rxdata);
-
-      lte_ue_measurements(ue,
-			  (subframe_rx*frame_parms->samples_per_tti+ue->rx_offset)%(frame_parms->samples_per_tti*LTE_NUMBER_OF_SUBFRAMES_PER_FRAME),
-			  (subframe_rx == 1) ? 1 : 0,
-			  0,
-			  0,
-			  subframe_rx);
-      
-
-      if(slot == 0)
-	T(T_UE_PHY_MEAS, T_INT(eNB_id), T_INT(proc->frame_rx%1024), T_INT(proc->subframe_rx),
-	  T_INT((int)(10*log10(ue->measurements.rsrp[0])-ue->rx_total_gain_dB)),
-	  T_INT((int)ue->measurements.rx_rssi_dBm[0]),
-	  T_INT((int)(ue->measurements.rx_power_avg_dB[0] - ue->measurements.n0_power_avg_dB)),
-	  T_INT((int)ue->measurements.rx_power_avg_dB[0]),
-	  T_INT((int)ue->measurements.n0_power_avg_dB),
-	  T_INT((int)ue->measurements.wideband_cqi_avg[0]),
-	  T_INT((int)ue->common_vars.freq_offset));
+    LOG_D(PHY,"Calling measurements subframe %d, rxdata %p\n",subframe_rx,ue->common_vars.rxdata);
+    lte_ue_measurements(ue,
+                        (subframe_rx*frame_parms->samples_per_tti+ue->rx_offset)%(frame_parms->samples_per_tti*LTE_NUMBER_OF_SUBFRAMES_PER_FRAME),
+                        (subframe_rx == 1) ? 1 : 0,
+                        0,
+                        0,
+                        subframe_rx);
+
+    if(slot == 0)
+      T(T_UE_PHY_MEAS, T_INT(eNB_id), T_INT(proc->frame_rx%1024), T_INT(proc->subframe_rx),
+        T_INT((int)(10*log10(ue->measurements.rsrp[0])-ue->rx_total_gain_dB)),
+        T_INT((int)ue->measurements.rx_rssi_dBm[0]),
+        T_INT((int)(ue->measurements.rx_power_avg_dB[0] - ue->measurements.n0_power_avg_dB)),
+        T_INT((int)ue->measurements.rx_power_avg_dB[0]),
+        T_INT((int)ue->measurements.n0_power_avg_dB),
+        T_INT((int)ue->measurements.wideband_cqi_avg[0]),
+        T_INT((int)ue->common_vars.freq_offset));
   }
 
   if (( (slot%2) == 0) && (l==(6-ue->frame_parms.Ncp))) {
-
     // make sure we have signal from PSS/SSS for N0 measurement
-         // LOG_I(PHY," l==(6-ue->frame_parms.Ncp) ue_rrc_measurements\n");
-
+    // LOG_I(PHY," l==(6-ue->frame_parms.Ncp) ue_rrc_measurements\n");
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_RRC_MEASUREMENTS, VCD_FUNCTION_IN);
     ue_rrc_measurements(ue,
-      slot,
-      abstraction_flag);
+                        slot,
+                        abstraction_flag);
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_RRC_MEASUREMENTS, VCD_FUNCTION_OUT);
-
   }
 
   // accumulate and filter timing offset estimation every subframe (instead of every frame)
   if (( (slot%2) == 0) && (l==(4-frame_parms->Ncp))) {
-
     // AGC
-
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_GAIN_CONTROL, VCD_FUNCTION_IN);
-
 #ifndef OAI_USRP
 #ifndef OAI_BLADERF
 #ifndef OAI_LMSSDR
@@ -2543,20 +2319,16 @@ void ue_measurement_procedures(
 #endif
 #endif
 #endif
-
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_GAIN_CONTROL, VCD_FUNCTION_OUT);
-
     eNB_id = 0;
 
-    
     if (ue->no_timing_correction==0)
       lte_adjust_synch(&ue->frame_parms,
-		       ue,
-		       eNB_id,
-		       subframe_rx,
-		       0,
-		       16384);
- 
+                       ue,
+                       eNB_id,
+                       subframe_rx,
+                       0,
+                       16384);
   }
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_MEASUREMENT_PROCEDURES, VCD_FUNCTION_OUT);
@@ -2564,23 +2336,17 @@ void ue_measurement_procedures(
 
 
 
-void ue_pbch_procedures(uint8_t eNB_id,PHY_VARS_UE *ue,UE_rxtx_proc_t *proc, uint8_t abstraction_flag)
-{
-
+void ue_pbch_procedures(uint8_t eNB_id,PHY_VARS_UE *ue,UE_rxtx_proc_t *proc, uint8_t abstraction_flag) {
   //  int i;
   int pbch_tx_ant=0;
   uint8_t pbch_phase;
   uint16_t frame_tx;
   static uint8_t first_run = 1;
   uint8_t pbch_trials = 0;
-
   DevAssert(ue);
-
   int frame_rx = proc->frame_rx;
   int subframe_rx = proc->subframe_rx;
-
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_PBCH_PROCEDURES, VCD_FUNCTION_IN);
-
   pbch_phase=(frame_rx%4);
 
   if (pbch_phase>=4)
@@ -2589,15 +2355,14 @@ void ue_pbch_procedures(uint8_t eNB_id,PHY_VARS_UE *ue,UE_rxtx_proc_t *proc, uin
   for (pbch_trials=0; pbch_trials<4; pbch_trials++) {
     //for (pbch_phase=0;pbch_phase<4;pbch_phase++) {
     //LOG_I(PHY,"[UE  %d] Frame %d, Trying PBCH %d (NidCell %d, eNB_id %d)\n",ue->Mod_id,frame_rx,pbch_phase,ue->frame_parms.Nid_cell,eNB_id);
-
     pbch_tx_ant = rx_pbch(&ue->common_vars,
-			  ue->pbch_vars[eNB_id],
-			  &ue->frame_parms,
-			  eNB_id,
-			  ue->frame_parms.nb_antenna_ports_eNB==1?SISO:ALAMOUTI,
-			  ue->high_speed_flag,
-			  pbch_phase);
-    
+                          ue->pbch_vars[eNB_id],
+                          &ue->frame_parms,
+                          eNB_id,
+                          ue->frame_parms.nb_antenna_ports_eNB==1?SISO:ALAMOUTI,
+                          ue->high_speed_flag,
+                          pbch_phase);
+
     if ((pbch_tx_ant>0) && (pbch_tx_ant<=4)) {
       break;
     }
@@ -2608,19 +2373,16 @@ void ue_pbch_procedures(uint8_t eNB_id,PHY_VARS_UE *ue,UE_rxtx_proc_t *proc, uin
       pbch_phase=0;
   }
 
-
-
   if ((pbch_tx_ant>0) && (pbch_tx_ant<=4)) {
-
     if (opt_enabled) {
       static uint8_t dummy[3];
       dummy[0] = ue->pbch_vars[eNB_id]->decoded_output[2];
       dummy[1] = ue->pbch_vars[eNB_id]->decoded_output[1];
       dummy[2] = ue->pbch_vars[eNB_id]->decoded_output[0];
       trace_pdu( DIRECTION_DOWNLINK, dummy, WS_C_RNTI, ue->Mod_id, 0, 0,
-          frame_rx, subframe_rx, 0, 0);
+                 frame_rx, subframe_rx, 0, 0);
       LOG_D(OPT,"[UE %d][PBCH] Frame %d trace pdu for PBCH\n",
-          ue->Mod_id, subframe_rx);
+            ue->Mod_id, subframe_rx);
     }
 
     if (pbch_tx_ant>2) {
@@ -2629,95 +2391,77 @@ void ue_pbch_procedures(uint8_t eNB_id,PHY_VARS_UE *ue,UE_rxtx_proc_t *proc, uin
       return;
     }
 
-
     ue->pbch_vars[eNB_id]->pdu_errors_conseq = 0;
     frame_tx = (((int)(ue->pbch_vars[eNB_id]->decoded_output[2]&0x03))<<8);
     frame_tx += ((int)(ue->pbch_vars[eNB_id]->decoded_output[1]&0xfc));
     frame_tx += pbch_phase;
 
     if (ue->mac_enabled==1) {
-
       dl_phy_sync_success(ue->Mod_id,frame_rx,eNB_id,
-			  ue->UE_mode[eNB_id]==NOT_SYNCHED ? 1 : 0);
+                          ue->UE_mode[eNB_id]==NOT_SYNCHED ? 1 : 0);
     }
 
-    // if this is the first PBCH after initial synchronization, make L1 state = PRACH
-    if (ue->UE_mode[eNB_id]==NOT_SYNCHED) ue->UE_mode[eNB_id] = PRACH;
+    // if this is the first PBCH after initial synchronization and no timing correction is performed, make L1 state = PRACH
+    if (ue->UE_mode[eNB_id]==NOT_SYNCHED && ue->no_timing_correction == 1) ue->UE_mode[eNB_id] = PRACH;
 
     if (first_run) {
       first_run = 0;
-
       proc->frame_rx = (proc->frame_rx & 0xFFFFFC00) | (frame_tx & 0x000003FF);
       proc->frame_tx = proc->frame_rx;
 
-      for(int th_id=0; th_id<RX_NB_TH; th_id++)
-      {
+      for(int th_id=0; th_id<RX_NB_TH; th_id++) {
         ue->proc.proc_rxtx[th_id].frame_rx = proc->frame_rx;
         ue->proc.proc_rxtx[th_id].frame_tx = proc->frame_tx;
-
         printf("[UE %d] frame %d, subframe %d: Adjusting frame counter (PBCH ant_tx=%d, frame_tx=%d, phase %d, rx_offset %d) => new frame %d\n",
- 	    ue->Mod_id,
- 	    ue->proc.proc_rxtx[th_id].frame_rx,
- 	    subframe_rx,
- 	    pbch_tx_ant,
- 	    frame_tx,
- 	    pbch_phase,
- 	    ue->rx_offset,
- 	    proc->frame_rx);
+               ue->Mod_id,
+               ue->proc.proc_rxtx[th_id].frame_rx,
+               subframe_rx,
+               pbch_tx_ant,
+               frame_tx,
+               pbch_phase,
+               ue->rx_offset,
+               proc->frame_rx);
       }
 
-
       frame_rx = proc->frame_rx;
-
     } else if (((frame_tx & 0x03FF) != (proc->frame_rx & 0x03FF))) {
       //(pbch_tx_ant != ue->frame_parms.nb_antennas_tx)) {
       LOG_D(PHY,"[UE %d] frame %d, subframe %d: Re-adjusting frame counter (PBCH ant_tx=%d, frame_rx=%d, frame%%1024=%d, phase %d).\n",
-      ue->Mod_id,
-      proc->frame_rx,
-      subframe_rx,
-      pbch_tx_ant,
-      frame_tx,
-      frame_rx & 0x03FF,
-      pbch_phase);
-
-
+            ue->Mod_id,
+            proc->frame_rx,
+            subframe_rx,
+            pbch_tx_ant,
+            frame_tx,
+            frame_rx & 0x03FF,
+            pbch_phase);
       proc->frame_rx = (proc->frame_rx & 0xFFFFFC00) | (frame_tx & 0x000003FF);
       proc->frame_tx = proc->frame_rx;
       frame_rx = proc->frame_rx;
-      
-      for(int th_id=0; th_id<RX_NB_TH; th_id++)
-      {
+
+      for(int th_id=0; th_id<RX_NB_TH; th_id++) {
         ue->proc.proc_rxtx[th_id].frame_rx = (proc->frame_rx & 0xFFFFFC00) | (frame_tx & 0x000003FF);
         ue->proc.proc_rxtx[th_id].frame_tx = proc->frame_rx;
       }
-
     }
 
     if (LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
-
       LOG_UI(PHY,"[UE %d] frame %d, subframe %d, Received PBCH (MIB): nb_antenna_ports_eNB %d, tx_ant %d, frame_tx %d. N_RB_DL %d, phich_duration %d, phich_resource %d/6!\n",
-	    ue->Mod_id,
-	    frame_rx,
-	    subframe_rx,
-	    ue->frame_parms.nb_antenna_ports_eNB,
-	    pbch_tx_ant,
-	    frame_tx,
-	    ue->frame_parms.N_RB_DL,
-	    ue->frame_parms.phich_config_common.phich_duration,
-	    ue->frame_parms.phich_config_common.phich_resource);
+             ue->Mod_id,
+             frame_rx,
+             subframe_rx,
+             ue->frame_parms.nb_antenna_ports_eNB,
+             pbch_tx_ant,
+             frame_tx,
+             ue->frame_parms.N_RB_DL,
+             ue->frame_parms.phich_config_common.phich_duration,
+             ue->frame_parms.phich_config_common.phich_resource);
     }
-
-  } else { 
-
+  } else {
     if (LOG_DUMPFLAG(DEBUG_UE_PHYPROC)) {
       LOG_E(PHY,"[UE %d] frame %d, subframe %d, Error decoding PBCH!\n",
-      ue->Mod_id,frame_rx, subframe_rx);
-
+            ue->Mod_id,frame_rx, subframe_rx);
       LOG_I(PHY,"[UE %d] rx_offset %d\n",ue->Mod_id,ue->rx_offset);
-
-
       LOG_M("rxsig0.m","rxs0", ue->common_vars.rxdata[0],ue->frame_parms.samples_per_tti,1,1);
-
       LOG_M("PBCH_rxF0_ext.m","pbch0_ext",ue->pbch_vars[0]->rxdataF_ext[0],12*4*6,1,1);
       LOG_M("PBCH_rxF0_comp.m","pbch0_comp",ue->pbch_vars[0]->rxdataF_comp[0],12*4*6,1,1);
       LOG_M("PBCH_rxF_llr.m","pbch_llr",ue->pbch_vars[0]->llr,(ue->frame_parms.Ncp==0) ? 1920 : 1728,1,4);
@@ -2729,9 +2473,8 @@ void ue_pbch_procedures(uint8_t eNB_id,PHY_VARS_UE *ue,UE_rxtx_proc_t *proc, uin
 
     if (ue->mac_enabled == 1) rrc_out_of_sync_ind(ue->Mod_id,frame_rx,eNB_id);
     else AssertFatal(ue->pbch_vars[eNB_id]->pdu_errors_conseq<100,
-		     "More that 100 consecutive PBCH errors! Exiting!\n");
+                       "More that 100 consecutive PBCH errors! Exiting!\n");
   }
-  
 
   if (frame_rx % 100 == 0) {
     ue->pbch_vars[eNB_id]->pdu_fer = ue->pbch_vars[eNB_id]->pdu_errors - ue->pbch_vars[eNB_id]->pdu_errors_last;
@@ -2740,277 +2483,240 @@ void ue_pbch_procedures(uint8_t eNB_id,PHY_VARS_UE *ue,UE_rxtx_proc_t *proc, uin
 
   if (LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
     LOG_UI(PHY,"[UE %d] frame %d, slot %d, PBCH errors = %d, consecutive errors = %d!\n",
-    ue->Mod_id,frame_rx, subframe_rx,
-    ue->pbch_vars[eNB_id]->pdu_errors,
-    ue->pbch_vars[eNB_id]->pdu_errors_conseq);
+           ue->Mod_id,frame_rx, subframe_rx,
+           ue->pbch_vars[eNB_id]->pdu_errors,
+           ue->pbch_vars[eNB_id]->pdu_errors_conseq);
   }
+
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_PBCH_PROCEDURES, VCD_FUNCTION_OUT);
 }
 
 
 
-int ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t abstraction_flag)
-{
-
+int ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t abstraction_flag) {
   unsigned int dci_cnt=0, i;
-
   int frame_rx = proc->frame_rx;
   int subframe_rx = proc->subframe_rx;
   DCI_ALLOC_t dci_alloc_rx[8];
-
   uint8_t next1_thread_id = ue->current_thread_id[subframe_rx]== (RX_NB_TH-1) ? 0:(ue->current_thread_id[subframe_rx]+1);
   uint8_t next2_thread_id = next1_thread_id== (RX_NB_TH-1) ? 0:(next1_thread_id+1);
-
   LOG_D(PHY,"DCI Decoding procedure in %d.%d\n",frame_rx,subframe_rx);
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_PDCCH_PROCEDURES, VCD_FUNCTION_IN);
+
   if (LOG_DEBUGFLAG(UE_TIMING)) {
     start_meas(&ue->dlsch_rx_pdcch_stats);
   }
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RX_PDCCH, VCD_FUNCTION_IN);
   rx_pdcch(ue,
-	   proc->frame_rx,
-	   subframe_rx,
-	   eNB_id,
-	   ue->frame_parms.nb_antenna_ports_eNB==1?SISO:ALAMOUTI,
-	   ue->high_speed_flag);
-  
+           proc->frame_rx,
+           subframe_rx,
+           eNB_id,
+           ue->frame_parms.nb_antenna_ports_eNB==1?SISO:ALAMOUTI,
+           ue->high_speed_flag);
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RX_PDCCH, VCD_FUNCTION_OUT);
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_DCI_DECODING, VCD_FUNCTION_IN);
-  
-  
+
   /*printf("Decode SIB frame param aggregation + DCI %d %d, num_pdcch_symbols %d\n",
-	 ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->agregationLevel,
-	 ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->dciFormat,
-	 ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols);
+   ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->agregationLevel,
+   ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->dciFormat,
+   ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols);
   */
   //agregation level == FF means no configuration on
-  if(ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->agregationLevel == 0xFF || ue->decode_SIB)
-    {
-      // search all possible dcis
-      dci_cnt = dci_decoding_procedure(ue,
-				       dci_alloc_rx,
-				       (ue->UE_mode[eNB_id] < PUSCH)? 1 : 0,  // if we're in PUSCH don't listen to common search space,
-				       // later when we need paging or RA during connection, update this ...
-				       eNB_id,subframe_rx);
-    }
-  else
-    {
-      // search only preconfigured dcis
-      // search C RNTI dci
-      dci_cnt = dci_CRNTI_decoding_procedure(ue,
-					     dci_alloc_rx,
-					     ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->dciFormat,
-					     ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->agregationLevel,
-					     eNB_id,
-					     subframe_rx);
-    }
-  
+  if(ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->agregationLevel == 0xFF || ue->decode_SIB) {
+    // search all possible dcis
+    dci_cnt = dci_decoding_procedure(ue,
+                                     dci_alloc_rx,
+                                     (ue->UE_mode[eNB_id] < PUSCH)? 1 : 0,  // if we're in PUSCH don't listen to common search space,
+                                     // later when we need paging or RA during connection, update this ...
+                                     eNB_id,subframe_rx);
+  } else {
+    // search only preconfigured dcis
+    // search C RNTI dci
+    dci_cnt = dci_CRNTI_decoding_procedure(ue,
+                                           dci_alloc_rx,
+                                           ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->dciFormat,
+                                           ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->agregationLevel,
+                                           eNB_id,
+                                           subframe_rx);
+  }
+
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_DCI_DECODING, VCD_FUNCTION_OUT);
   //LOG_D(PHY,"[UE  %d][PUSCH] Frame %d subframe %d PHICH RX\n",ue->Mod_id,frame_rx,subframe_rx);
-  
+
   if (is_phich_subframe(&ue->frame_parms,subframe_rx)) {
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RX_PHICH, VCD_FUNCTION_IN);
     rx_phich(ue,proc,
-	     subframe_rx,eNB_id);
+             subframe_rx,eNB_id);
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RX_PHICH, VCD_FUNCTION_OUT);
   }
-  
+
   uint8_t *nCCE_current = &ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->nCCE[subframe_rx];
   uint8_t *nCCE_dest = &ue->pdcch_vars[next1_thread_id][eNB_id]->nCCE[subframe_rx];
   uint8_t *nCCE_dest1 = &ue->pdcch_vars[next2_thread_id][eNB_id]->nCCE[subframe_rx];
   memcpy(nCCE_dest, nCCE_current, sizeof(uint8_t));
   memcpy(nCCE_dest1, nCCE_current, sizeof(uint8_t));
-
   LOG_D(PHY,"current_thread %d next1_thread %d next2_thread %d \n", ue->current_thread_id[subframe_rx], next1_thread_id, next2_thread_id);
-
   LOG_D(PHY,"[UE  %d] AbsSubFrame %d.%d, Mode %s: DCI found %i --> rnti %x / crnti %x : format %d\n",
-       ue->Mod_id,frame_rx%1024,subframe_rx,mode_string[ue->UE_mode[eNB_id]],
-       dci_cnt,
-       dci_alloc_rx[0].rnti,
-       ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->crnti,
-       dci_alloc_rx[0].format );
-
+        ue->Mod_id,frame_rx%1024,subframe_rx,mode_string[ue->UE_mode[eNB_id]],
+        dci_cnt,
+        dci_alloc_rx[0].rnti,
+        ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->crnti,
+        dci_alloc_rx[0].format );
   ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->dci_received += dci_cnt;
 
   for (i=0; i<dci_cnt; i++) {
-
-
-
     if ((ue->UE_mode[eNB_id]>PRACH) &&
-	(dci_alloc_rx[i].rnti == ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->crnti) &&
-	(dci_alloc_rx[i].format != format0)) {
-      
+        (dci_alloc_rx[i].rnti == ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->crnti) &&
+        (dci_alloc_rx[i].format != format0)) {
       LOG_D(PHY,"[UE  %d][DCI][PDSCH %x] AbsSubframe %d.%d: format %d, num_pdcch_symbols %d, nCCE %d, total CCEs %d\n",
-	    ue->Mod_id,dci_alloc_rx[i].rnti,
-	    frame_rx%1024,subframe_rx,
-	    dci_alloc_rx[i].format,
-	    ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols,
-	    ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->nCCE[subframe_rx],
-	    get_nCCE(3,&ue->frame_parms,get_mi(&ue->frame_parms,0)));
-      
+            ue->Mod_id,dci_alloc_rx[i].rnti,
+            frame_rx%1024,subframe_rx,
+            dci_alloc_rx[i].format,
+            ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols,
+            ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->nCCE[subframe_rx],
+            get_nCCE(3,&ue->frame_parms,get_mi(&ue->frame_parms,0)));
+
       //dump_dci(&ue->frame_parms, &dci_alloc_rx[i]);
-      
+
       if ((ue->UE_mode[eNB_id] > PRACH) &&
-	  (generate_ue_dlsch_params_from_dci(frame_rx,
-					     subframe_rx,
-					     (void *)&dci_alloc_rx[i].dci_pdu,
-					     ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->crnti,
-					     dci_alloc_rx[i].format,
-					     ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id],
-					     ue->pdsch_vars[ue->current_thread_id[subframe_rx]][eNB_id],
-					     ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id],
-					     &ue->frame_parms,
-					     ue->pdsch_config_dedicated,
-					     SI_RNTI,
-					     0,
-					     P_RNTI,
-					     ue->transmission_mode[eNB_id]<7?0:ue->transmission_mode[eNB_id],
-					     ue->pdcch_vars[0%RX_NB_TH][eNB_id]->crnti_is_temporary? ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->crnti: 0)==0)) {
-	
-	// update TPC for PUCCH
-	if((dci_alloc_rx[i].format == format1)   ||
-	   (dci_alloc_rx[i].format == format1A) ||
-	   (dci_alloc_rx[i].format == format1B) ||
-	   (dci_alloc_rx[i].format == format2)  ||
-	   (dci_alloc_rx[i].format == format2A) ||
-	   (dci_alloc_rx[i].format == format2B))
-          {
-            //ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->g_pucch += ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->harq_processes[ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->current_harq_pid]->delta_PUCCH;
-            int32_t delta_pucch = ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->harq_processes[ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->current_harq_pid]->delta_PUCCH;
-            for(int th_id=0; th_id<RX_NB_TH; th_id++)
-	      {
-                ue->dlsch[th_id][eNB_id][0]->g_pucch += delta_pucch;
-	      }
-            LOG_D(PHY,"update TPC for PUCCH %d.%d / pid %d delta_PUCCH %d g_pucch %d %d \n",frame_rx, subframe_rx,ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->current_harq_pid,
-		  delta_pucch,
-		  ue->dlsch[0][eNB_id][0]->g_pucch,
-		  ue->dlsch[1][eNB_id][0]->g_pucch
-		  //ue->dlsch[2][eNB_id][0]->g_pucch
-		  );
+          (generate_ue_dlsch_params_from_dci(frame_rx,
+                                             subframe_rx,
+                                             (void *)&dci_alloc_rx[i].dci_pdu,
+                                             ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->crnti,
+                                             dci_alloc_rx[i].format,
+                                             ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id],
+                                             ue->pdsch_vars[ue->current_thread_id[subframe_rx]][eNB_id],
+                                             ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id],
+                                             &ue->frame_parms,
+                                             ue->pdsch_config_dedicated,
+                                             SI_RNTI,
+                                             0,
+                                             P_RNTI,
+                                             ue->transmission_mode[eNB_id]<7?0:ue->transmission_mode[eNB_id],
+                                             ue->pdcch_vars[0%RX_NB_TH][eNB_id]->crnti_is_temporary? ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->crnti: 0)==0)) {
+        // update TPC for PUCCH
+        if((dci_alloc_rx[i].format == format1)   ||
+            (dci_alloc_rx[i].format == format1A) ||
+            (dci_alloc_rx[i].format == format1B) ||
+            (dci_alloc_rx[i].format == format2)  ||
+            (dci_alloc_rx[i].format == format2A) ||
+            (dci_alloc_rx[i].format == format2B)) {
+          //ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->g_pucch += ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->harq_processes[ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->current_harq_pid]->delta_PUCCH;
+          int32_t delta_pucch = ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->harq_processes[ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->current_harq_pid]->delta_PUCCH;
+
+          for(int th_id=0; th_id<RX_NB_TH; th_id++) {
+            ue->dlsch[th_id][eNB_id][0]->g_pucch += delta_pucch;
           }
-	
-	ue->dlsch_received[eNB_id]++;
-	
-        if ( LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
-	  LOG_D(PHY,"[UE  %d] Generated UE DLSCH C_RNTI format %d\n",ue->Mod_id,dci_alloc_rx[i].format);
-	  dump_dci(&ue->frame_parms, &dci_alloc_rx[i]);
-	  LOG_D(PHY,"[UE %d] *********** dlsch->active in subframe %d=> %d\n",ue->Mod_id,subframe_rx,ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->active);
+
+          LOG_D(PHY,"update TPC for PUCCH %d.%d / pid %d delta_PUCCH %d g_pucch %d %d \n",frame_rx, subframe_rx,ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->current_harq_pid,
+                delta_pucch,
+                ue->dlsch[0][eNB_id][0]->g_pucch,
+                ue->dlsch[1][eNB_id][0]->g_pucch
+                //ue->dlsch[2][eNB_id][0]->g_pucch
+               );
         }
-	
-	// we received a CRNTI, so we're in PUSCH
-	if (ue->UE_mode[eNB_id] != PUSCH) {
-          if (LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
-	    LOG_D(PHY,"[UE  %d] Frame %d, subframe %d: Received DCI with CRNTI %x => Mode PUSCH\n",ue->Mod_id,frame_rx,subframe_rx,ue->pdcch_vars[subframe_rx&1][eNB_id]->crnti);
-         }
-	  
-	  //dump_dci(&ue->frame_parms, &dci_alloc_rx[i]);
-	  ue->UE_mode[eNB_id] = PUSCH;
-	}
-      } else {
-	  LOG_E(PHY,"[UE  %d] Frame %d, subframe %d: Problem in DCI!\n",ue->Mod_id,frame_rx,subframe_rx);
-	  dump_dci(&ue->frame_parms, &dci_alloc_rx[i]);
-	}
-    }
-      
-      else if ((dci_alloc_rx[i].rnti == SI_RNTI) &&
-	       ((dci_alloc_rx[i].format == format1A) || (dci_alloc_rx[i].format == format1C))) {
 
+        ue->dlsch_received[eNB_id]++;
 
-        if (LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
-	  LOG_D(PHY,"[UE  %d] subframe %d: Found rnti %x, format 1%s, dci_cnt %d\n",ue->Mod_id,subframe_rx,dci_alloc_rx[i].rnti,dci_alloc_rx[i].format==format1A?"A":"C",i);
+        if ( LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
+          LOG_D(PHY,"[UE  %d] Generated UE DLSCH C_RNTI format %d\n",ue->Mod_id,dci_alloc_rx[i].format);
+          dump_dci(&ue->frame_parms, &dci_alloc_rx[i]);
+          LOG_D(PHY,"[UE %d] *********** dlsch->active in subframe %d=> %d\n",ue->Mod_id,subframe_rx,ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->active);
         }
-	
-	if (generate_ue_dlsch_params_from_dci(frame_rx,
-					      subframe_rx,
-					      (void *)&dci_alloc_rx[i].dci_pdu,
-					      SI_RNTI,
-					      dci_alloc_rx[i].format,
-					      ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id],
-					      ue->pdsch_vars_SI[eNB_id],
-					      &ue->dlsch_SI[eNB_id],
-					      &ue->frame_parms,
-					      ue->pdsch_config_dedicated,
-					      SI_RNTI,
-					      0,
-					      P_RNTI,
-					      ue->transmission_mode[eNB_id]<7?0:ue->transmission_mode[eNB_id],
-					      0)==0) {
-	  
-	  ue->dlsch_SI_received[eNB_id]++;
-	  
-	  LOG_D(PHY,"[UE  %d] Frame %d, subframe %d : Generate UE DLSCH SI_RNTI format 1%s\n",ue->Mod_id,frame_rx,subframe_rx,dci_alloc_rx[i].format==format1A?"A":"C");
-	  //dump_dci(&ue->frame_parms, &dci_alloc_rx[i]);
-	
-	}
-      }
 
-    else if ((dci_alloc_rx[i].rnti == P_RNTI) &&
-       ((dci_alloc_rx[i].format == format1A) || (dci_alloc_rx[i].format == format1C))) {
+        // we received a CRNTI, so we're in PUSCH
+        if (ue->UE_mode[eNB_id] != PUSCH) {
+          if (LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
 
+          //dump_dci(&ue->frame_parms, &dci_alloc_rx[i]);
+          ue->UE_mode[eNB_id] = PUSCH;
+        }
+      } else {
+        LOG_E(PHY,"[UE  %d] Frame %d, subframe %d: Problem in DCI!\n",ue->Mod_id,frame_rx,subframe_rx);
+        dump_dci(&ue->frame_parms, &dci_alloc_rx[i]);
+      }
+    } else if ((dci_alloc_rx[i].rnti == SI_RNTI) &&
+               ((dci_alloc_rx[i].format == format1A) || (dci_alloc_rx[i].format == format1C))) {
       if (LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
         LOG_D(PHY,"[UE  %d] subframe %d: Found rnti %x, format 1%s, dci_cnt %d\n",ue->Mod_id,subframe_rx,dci_alloc_rx[i].rnti,dci_alloc_rx[i].format==format1A?"A":"C",i);
       }
 
-
       if (generate_ue_dlsch_params_from_dci(frame_rx,
-					    subframe_rx,
-					    (void *)&dci_alloc_rx[i].dci_pdu,
-					    P_RNTI,
-					    dci_alloc_rx[i].format,
-					    ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id],
-					    ue->pdsch_vars_p[eNB_id],
-					    &ue->dlsch_SI[eNB_id],
-					    &ue->frame_parms,
-					    ue->pdsch_config_dedicated,
-					    SI_RNTI,
-					    0,
-					    P_RNTI,
-					    ue->transmission_mode[eNB_id]<7?0:ue->transmission_mode[eNB_id],
+                                            subframe_rx,
+                                            (void *)&dci_alloc_rx[i].dci_pdu,
+                                            SI_RNTI,
+                                            dci_alloc_rx[i].format,
+                                            ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id],
+                                            ue->pdsch_vars_SI[eNB_id],
+                                            &ue->dlsch_SI[eNB_id],
+                                            &ue->frame_parms,
+                                            ue->pdsch_config_dedicated,
+                                            SI_RNTI,
+                                            0,
+                                            P_RNTI,
+                                            ue->transmission_mode[eNB_id]<7?0:ue->transmission_mode[eNB_id],
                                             0)==0) {
-
-	ue->dlsch_p_received[eNB_id]++;
-	LOG_D(PHY,"[UE  %d] Frame %d, subframe %d : Generate UE DLSCH P_RNTI format 1%s\n",ue->Mod_id,frame_rx,subframe_rx,dci_alloc_rx[i].format==format1A?"A":"C");
-	//dump_dci(&ue->frame_parms, &dci_alloc_rx[i]);
-	
+        ue->dlsch_SI_received[eNB_id]++;
+        LOG_D(PHY,"[UE  %d] Frame %d, subframe %d : Generate UE DLSCH SI_RNTI format 1%s\n",ue->Mod_id,frame_rx,subframe_rx,dci_alloc_rx[i].format==format1A?"A":"C");
+        //dump_dci(&ue->frame_parms, &dci_alloc_rx[i]);
+      }
+    } else if ((dci_alloc_rx[i].rnti == P_RNTI) &&
+               ((dci_alloc_rx[i].format == format1A) || (dci_alloc_rx[i].format == format1C))) {
+      if (LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
+        LOG_D(PHY,"[UE  %d] subframe %d: Found rnti %x, format 1%s, dci_cnt %d\n",ue->Mod_id,subframe_rx,dci_alloc_rx[i].rnti,dci_alloc_rx[i].format==format1A?"A":"C",i);
       }
-    }
-
-    else if ((ue->prach_resources[eNB_id]) &&
-       (dci_alloc_rx[i].rnti == ue->prach_resources[eNB_id]->ra_RNTI) &&
-       ((dci_alloc_rx[i].format == format1A) || (dci_alloc_rx[i].format == format1C))) {
 
+      if (generate_ue_dlsch_params_from_dci(frame_rx,
+                                            subframe_rx,
+                                            (void *)&dci_alloc_rx[i].dci_pdu,
+                                            P_RNTI,
+                                            dci_alloc_rx[i].format,
+                                            ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id],
+                                            ue->pdsch_vars_p[eNB_id],
+                                            &ue->dlsch_SI[eNB_id],
+                                            &ue->frame_parms,
+                                            ue->pdsch_config_dedicated,
+                                            SI_RNTI,
+                                            0,
+                                            P_RNTI,
+                                            ue->transmission_mode[eNB_id]<7?0:ue->transmission_mode[eNB_id],
+                                            0)==0) {
+        ue->dlsch_p_received[eNB_id]++;
+        LOG_D(PHY,"[UE  %d] Frame %d, subframe %d : Generate UE DLSCH P_RNTI format 1%s\n",ue->Mod_id,frame_rx,subframe_rx,dci_alloc_rx[i].format==format1A?"A":"C");
+        //dump_dci(&ue->frame_parms, &dci_alloc_rx[i]);
+      }
+    } else if ((ue->prach_resources[eNB_id]) &&
+               (dci_alloc_rx[i].rnti == ue->prach_resources[eNB_id]->ra_RNTI) &&
+               ((dci_alloc_rx[i].format == format1A) || (dci_alloc_rx[i].format == format1C))) {
       if (LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
         LOG_D(PHY,"[UE  %d][RAPROC] subframe %d: Found RA rnti %x, format 1%s, dci_cnt %d\n",ue->Mod_id,subframe_rx,dci_alloc_rx[i].rnti,dci_alloc_rx[i].format==format1A?"A":"C",i);
       }
 
-
       if (generate_ue_dlsch_params_from_dci(frame_rx,
-					    subframe_rx,
-					    (void *)&dci_alloc_rx[i].dci_pdu,
-					    ue->prach_resources[eNB_id]->ra_RNTI,
-					    dci_alloc_rx[i].format,
-					    ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id],
-					    ue->pdsch_vars_ra[eNB_id],
-					    &ue->dlsch_ra[eNB_id],
-					    &ue->frame_parms,
-					    ue->pdsch_config_dedicated,
-					    SI_RNTI,
-					    ue->prach_resources[eNB_id]->ra_RNTI,
-					    P_RNTI,
-					    ue->transmission_mode[eNB_id]<7?0:ue->transmission_mode[eNB_id],
+                                            subframe_rx,
+                                            (void *)&dci_alloc_rx[i].dci_pdu,
+                                            ue->prach_resources[eNB_id]->ra_RNTI,
+                                            dci_alloc_rx[i].format,
+                                            ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id],
+                                            ue->pdsch_vars_ra[eNB_id],
+                                            &ue->dlsch_ra[eNB_id],
+                                            &ue->frame_parms,
+                                            ue->pdsch_config_dedicated,
+                                            SI_RNTI,
+                                            ue->prach_resources[eNB_id]->ra_RNTI,
+                                            P_RNTI,
+                                            ue->transmission_mode[eNB_id]<7?0:ue->transmission_mode[eNB_id],
                                             0)==0) {
-	
-         ue->dlsch_ra_received[eNB_id]++;
+        ue->dlsch_ra_received[eNB_id]++;
 
-         if (LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
-           LOG_D(PHY,"[UE  %d] Generate UE DLSCH RA_RNTI format 1A, rb_alloc %x, dlsch_ra[eNB_id] %p\n",
-                  ue->Mod_id,ue->dlsch_ra[eNB_id]->harq_processes[0]->rb_alloc_even[0],ue->dlsch_ra[eNB_id]);
-         }
+        if (LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
+          LOG_D(PHY,"[UE  %d] Generate UE DLSCH RA_RNTI format 1A, rb_alloc %x, dlsch_ra[eNB_id] %p\n",
+                ue->Mod_id,ue->dlsch_ra[eNB_id]->harq_processes[0]->rb_alloc_even[0],ue->dlsch_ra[eNB_id]);
+        }
       }
     } else if( (dci_alloc_rx[i].rnti == ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->crnti) &&
-	       (dci_alloc_rx[i].format == format0)) {
-
+               (dci_alloc_rx[i].format == format0)) {
       if (LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
         LOG_D(PHY,"[UE  %d][PUSCH] Frame %d subframe %d: Found rnti %x, format 0, dci_cnt %d\n",
               ue->Mod_id,frame_rx,subframe_rx,dci_alloc_rx[i].rnti,i);
@@ -3018,48 +2724,46 @@ int ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint
 
       ue->ulsch_no_allocation_counter[eNB_id] = 0;
       //dump_dci(&ue->frame_parms,&dci_alloc_rx[i]);
-      
+
       if ((ue->UE_mode[eNB_id] > PRACH) &&
-	  (generate_ue_ulsch_params_from_dci((void *)&dci_alloc_rx[i].dci_pdu,
-					     ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->crnti,
-					     subframe_rx,
-					     format0,
-					     ue,
-					     proc,
-					     SI_RNTI,
-					     0,
-					     P_RNTI,
-					     CBA_RNTI,
-					     eNB_id,
-					     0)==0)) {
-         if (LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
-   
-             LOG_USEDINLOG_VAR(int8_t,harq_pid) = subframe2harq_pid(&ue->frame_parms,
-                                       pdcch_alloc2ul_frame(&ue->frame_parms,proc->frame_rx,proc->subframe_rx),
-                                       pdcch_alloc2ul_subframe(&ue->frame_parms,proc->subframe_rx));
-             T(T_UE_PHY_ULSCH_UE_DCI, T_INT(eNB_id), T_INT(proc->frame_rx%1024), T_INT(proc->subframe_rx),
-               T_INT(dci_alloc_rx[i].rnti), 
-               T_INT(harq_pid),
-               T_INT(ue->ulsch[eNB_id]->harq_processes[harq_pid]->mcs),
-               T_INT(ue->ulsch[eNB_id]->harq_processes[harq_pid]->round),
-               T_INT(ue->ulsch[eNB_id]->harq_processes[harq_pid]->first_rb),
-               T_INT(ue->ulsch[eNB_id]->harq_processes[harq_pid]->nb_rb),
-               T_INT(ue->ulsch[eNB_id]->harq_processes[harq_pid]->TBS));
-
-             LOG_D(PHY,"[UE  %d] Generate UE ULSCH C_RNTI format 0 (subframe %d)\n",ue->Mod_id,subframe_rx);
-         }
+          (generate_ue_ulsch_params_from_dci((void *)&dci_alloc_rx[i].dci_pdu,
+                                             ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->crnti,
+                                             subframe_rx,
+                                             format0,
+                                             ue,
+                                             proc,
+                                             SI_RNTI,
+                                             0,
+                                             P_RNTI,
+                                             CBA_RNTI,
+                                             eNB_id,
+                                             0)==0)) {
+        if (LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
+          LOG_USEDINLOG_VAR(int8_t,harq_pid) = subframe2harq_pid(&ue->frame_parms,
+                                               pdcch_alloc2ul_frame(&ue->frame_parms,proc->frame_rx,proc->subframe_rx),
+                                               pdcch_alloc2ul_subframe(&ue->frame_parms,proc->subframe_rx));
+          T(T_UE_PHY_ULSCH_UE_DCI, T_INT(eNB_id), T_INT(proc->frame_rx%1024), T_INT(proc->subframe_rx),
+            T_INT(dci_alloc_rx[i].rnti),
+            T_INT(harq_pid),
+            T_INT(ue->ulsch[eNB_id]->harq_processes[harq_pid]->mcs),
+            T_INT(ue->ulsch[eNB_id]->harq_processes[harq_pid]->round),
+            T_INT(ue->ulsch[eNB_id]->harq_processes[harq_pid]->first_rb),
+            T_INT(ue->ulsch[eNB_id]->harq_processes[harq_pid]->nb_rb),
+            T_INT(ue->ulsch[eNB_id]->harq_processes[harq_pid]->TBS));
+          LOG_D(PHY,"[UE  %d] Generate UE ULSCH C_RNTI format 0 (subframe %d)\n",ue->Mod_id,subframe_rx);
+        }
       }
     } else if( (dci_alloc_rx[i].rnti == ue->ulsch[eNB_id]->cba_rnti[0]) &&
-         (dci_alloc_rx[i].format == format0)) {
+               (dci_alloc_rx[i].format == format0)) {
       // UE could belong to more than one CBA group
       // ue->Mod_id%ue->ulsch[eNB_id]->num_active_cba_groups]
       if (LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
         LOG_D(PHY,"[UE  %d][PUSCH] Frame %d subframe %d: Found cba rnti %x, format 0, dci_cnt %d\n",
-                   ue->Mod_id,frame_rx,subframe_rx,dci_alloc_rx[i].rnti,i);
-      /*
-  if (((frame_rx%100) == 0) || (frame_rx < 20))
-  dump_dci(&ue->frame_parms, &dci_alloc_rx[i]);
-      */
+              ue->Mod_id,frame_rx,subframe_rx,dci_alloc_rx[i].rnti,i);
+        /*
+        if (((frame_rx%100) == 0) || (frame_rx < 20))
+        dump_dci(&ue->frame_parms, &dci_alloc_rx[i]);
+        */
       }
 
       ue->ulsch_no_allocation_counter[eNB_id] = 0;
@@ -3067,51 +2771,48 @@ int ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint
 
       if ((ue->UE_mode[eNB_id] > PRACH) &&
           (generate_ue_ulsch_params_from_dci((void *)&dci_alloc_rx[i].dci_pdu,
-               ue->ulsch[eNB_id]->cba_rnti[0],
-               subframe_rx,
-               format0,
-               ue,
-               proc,
-               SI_RNTI,
-               0,
-               P_RNTI,
-               CBA_RNTI,
-               eNB_id,
-               0)==0)) {
-
+                                             ue->ulsch[eNB_id]->cba_rnti[0],
+                                             subframe_rx,
+                                             format0,
+                                             ue,
+                                             proc,
+                                             SI_RNTI,
+                                             0,
+                                             P_RNTI,
+                                             CBA_RNTI,
+                                             eNB_id,
+                                             0)==0)) {
         if (LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
           LOG_D(PHY,"[UE  %d] Generate UE ULSCH CBA_RNTI format 0 (subframe %d)\n",ue->Mod_id,subframe_rx);
         }
+
         ue->ulsch[eNB_id]->num_cba_dci[(subframe_rx+4)%10]++;
       }
-    }
-
-    else {
+    } else {
       if (LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
         LOG_D(PHY,"[UE  %d] frame %d, subframe %d: received DCI %d with RNTI=%x (C-RNTI:%x, CBA_RNTI %x) and format %d!\n",ue->Mod_id,frame_rx,subframe_rx,i,dci_alloc_rx[i].rnti,
-	      ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->crnti,
-	      ue->ulsch[eNB_id]->cba_rnti[0],
-	    dci_alloc_rx[i].format);
-
-      //      dump_dci(&ue->frame_parms, &dci_alloc_rx[i]);
+              ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->crnti,
+              ue->ulsch[eNB_id]->cba_rnti[0],
+              dci_alloc_rx[i].format);
+        //      dump_dci(&ue->frame_parms, &dci_alloc_rx[i]);
       }
     }
-
   }
+
   if (LOG_DEBUGFLAG(UE_TIMING)) {
-      stop_meas(&ue->dlsch_rx_pdcch_stats);
+    stop_meas(&ue->dlsch_rx_pdcch_stats);
   }
+
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_PDCCH_PROCEDURES, VCD_FUNCTION_OUT);
   return(0);
 }
 
 
 void ue_pmch_procedures(PHY_VARS_UE *ue, UE_rxtx_proc_t *proc,int eNB_id,int abstraction_flag) {
-
   int subframe_rx = proc->subframe_rx;
   int frame_rx = proc->frame_rx;
   int pmch_mcs=-1;
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
   int CC_id = ue->CC_id;
 #endif
   uint8_t sync_area=255;
@@ -3121,19 +2822,16 @@ void ue_pmch_procedures(PHY_VARS_UE *ue, UE_rxtx_proc_t *proc,int eNB_id,int abs
 
   if (is_pmch_subframe(frame_rx,subframe_rx,&ue->frame_parms)) {
     // LOG_D(PHY,"ue calling pmch subframe ..\n ");
-
     LOG_D(PHY,"[UE %d] Frame %d, subframe %d: Querying for PMCH demodulation\n",
-    ue->Mod_id,frame_rx,subframe_rx);
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-
+          ue->Mod_id,frame_rx,subframe_rx);
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
     pmch_mcs = ue_query_mch(ue->Mod_id,
-			    CC_id,
-			    frame_rx,
-			    subframe_rx,
-			    eNB_id,
-			    &sync_area,
-			    &mcch_active);
-    
+                            CC_id,
+                            frame_rx,
+                            subframe_rx,
+                            eNB_id,
+                            &sync_area,
+                            &mcch_active);
 #else
     pmch_mcs=-1;
 #endif
@@ -3143,169 +2841,158 @@ void ue_pmch_procedures(PHY_VARS_UE *ue, UE_rxtx_proc_t *proc,int eNB_id,int abs
       fill_UE_dlsch_MCH(ue,pmch_mcs,1,0,0);
 
       for (l=2; l<12; l++) {
-	slot_fep_mbsfn(ue,
-		       l,
-		       subframe_rx,
-		       0,0);//ue->rx_offset,0);
+        slot_fep_mbsfn(ue,
+                       l,
+                       subframe_rx,
+                       0,0);//ue->rx_offset,0);
       }
-      
+
       for (l=2; l<12; l++) {
-	rx_pmch(ue,
-		0,
-		subframe_rx,
-		l);
+        rx_pmch(ue,
+                0,
+                subframe_rx,
+                l);
       }
-      
-      
-      ue->dlsch_MCH[0]->harq_processes[0]->Qm = get_Qm(pmch_mcs);
 
+      ue->dlsch_MCH[0]->harq_processes[0]->Qm = get_Qm(pmch_mcs);
       ue->dlsch_MCH[0]->harq_processes[0]->G = get_G(&ue->frame_parms,
-						     ue->dlsch_MCH[0]->harq_processes[0]->nb_rb,
-						     ue->dlsch_MCH[0]->harq_processes[0]->rb_alloc_even,
-						     ue->dlsch_MCH[0]->harq_processes[0]->Qm,
-						     1,
-						     2,
-						     frame_rx,
-						     subframe_rx,
-						     0);
-      
+          ue->dlsch_MCH[0]->harq_processes[0]->nb_rb,
+          ue->dlsch_MCH[0]->harq_processes[0]->rb_alloc_even,
+          ue->dlsch_MCH[0]->harq_processes[0]->Qm,
+          1,
+          2,
+          frame_rx,
+          subframe_rx,
+          0);
       dlsch_unscrambling(&ue->frame_parms,1,ue->dlsch_MCH[0],
-			 ue->dlsch_MCH[0]->harq_processes[0]->G,
-			 ue->pdsch_vars_MCH[0]->llr[0],0,subframe_rx<<1);
-
+                         ue->dlsch_MCH[0]->harq_processes[0]->G,
+                         ue->pdsch_vars_MCH[0]->llr[0],0,subframe_rx<<1);
       LOG_D(PHY,"start turbo decode for MCH %d.%d --> nb_rb %d \n", frame_rx, subframe_rx, ue->dlsch_MCH[0]->harq_processes[0]->nb_rb);
       LOG_D(PHY,"start turbo decode for MCH %d.%d --> rb_alloc_even %x \n", frame_rx, subframe_rx, (unsigned int)((intptr_t)ue->dlsch_MCH[0]->harq_processes[0]->rb_alloc_even));
       LOG_D(PHY,"start turbo decode for MCH %d.%d --> Qm %d \n", frame_rx, subframe_rx, ue->dlsch_MCH[0]->harq_processes[0]->Qm);
       LOG_D(PHY,"start turbo decode for MCH %d.%d --> Nl %d \n", frame_rx, subframe_rx, ue->dlsch_MCH[0]->harq_processes[0]->Nl);
       LOG_D(PHY,"start turbo decode for MCH %d.%d --> G  %d \n", frame_rx, subframe_rx, ue->dlsch_MCH[0]->harq_processes[0]->G);
       LOG_D(PHY,"start turbo decode for MCH %d.%d --> Kmimo  %d \n", frame_rx, subframe_rx, ue->dlsch_MCH[0]->Kmimo);
-
       ret = dlsch_decoding(ue,
-			   ue->pdsch_vars_MCH[0]->llr[0],
-			   &ue->frame_parms,
-			   ue->dlsch_MCH[0],
-			   ue->dlsch_MCH[0]->harq_processes[0],
-			   frame_rx,
-			   subframe_rx,
-			   0,
-			   0,1);
+                           ue->pdsch_vars_MCH[0]->llr[0],
+                           &ue->frame_parms,
+                           ue->dlsch_MCH[0],
+                           ue->dlsch_MCH[0]->harq_processes[0],
+                           frame_rx,
+                           subframe_rx,
+                           0,
+                           0,1);
+
       if (mcch_active == 1)
-	ue->dlsch_mcch_trials[sync_area][0]++;
+        ue->dlsch_mcch_trials[sync_area][0]++;
       else
-	ue->dlsch_mtch_trials[sync_area][0]++;
-      
+        ue->dlsch_mtch_trials[sync_area][0]++;
+
       if (ret == (1+ue->dlsch_MCH[0]->max_turbo_iterations)) {
-	if (mcch_active == 1)
-	  ue->dlsch_mcch_errors[sync_area][0]++;
-	else
-	  ue->dlsch_mtch_errors[sync_area][0]++;
-	
-	LOG_D(PHY,"[UE %d] Frame %d, subframe %d: PMCH in error (%d,%d), not passing to L2 (TBS %d, iter %d,G %d)\n",
-	      ue->Mod_id,
+        if (mcch_active == 1)
+          ue->dlsch_mcch_errors[sync_area][0]++;
+        else
+          ue->dlsch_mtch_errors[sync_area][0]++;
+
+        LOG_D(PHY,"[UE %d] Frame %d, subframe %d: PMCH in error (%d,%d), not passing to L2 (TBS %d, iter %d,G %d)\n",
+              ue->Mod_id,
               frame_rx,subframe_rx,
-	      ue->dlsch_mcch_errors[sync_area][0],
-	      ue->dlsch_mtch_errors[sync_area][0],
-	      ue->dlsch_MCH[0]->harq_processes[0]->TBS>>3,
-	      ue->dlsch_MCH[0]->max_turbo_iterations,
-	      ue->dlsch_MCH[0]->harq_processes[0]->G);
-	// dump_mch(ue,0,ue->dlsch_MCH[0]->harq_processes[0]->G,subframe_rx);
+              ue->dlsch_mcch_errors[sync_area][0],
+              ue->dlsch_mtch_errors[sync_area][0],
+              ue->dlsch_MCH[0]->harq_processes[0]->TBS>>3,
+              ue->dlsch_MCH[0]->max_turbo_iterations,
+              ue->dlsch_MCH[0]->harq_processes[0]->G);
+        // dump_mch(ue,0,ue->dlsch_MCH[0]->harq_processes[0]->G,subframe_rx);
 
         if (LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
-	
           for (int i=0; i<ue->dlsch_MCH[0]->harq_processes[0]->TBS>>3; i++) {
-	       LOG_T(PHY,"%02x.",ue->dlsch_MCH[0]->harq_processes[0]->c[0][i]);
-	  }
-	
-	  LOG_T(PHY,"\n");
+            LOG_T(PHY,"%02x.",ue->dlsch_MCH[0]->harq_processes[0]->c[0][i]);
+          }
+
+          LOG_T(PHY,"\n");
         }
-	
-	
-	//	if (subframe_rx==9)
-	//  mac_xface->macphy_exit("Why are we exiting here?");
+
+        //  if (subframe_rx==9)
+        //  mac_xface->macphy_exit("Why are we exiting here?");
       } else { // decoding successful
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-	
-	ue_send_mch_sdu(ue->Mod_id,
-			CC_id,
-			frame_rx,
-			ue->dlsch_MCH[0]->harq_processes[0]->b,
-			ue->dlsch_MCH[0]->harq_processes[0]->TBS>>3,
-			eNB_id,// not relevant in eMBMS context
-			sync_area);
-
-	if (mcch_active == 1)
-	  ue->dlsch_mcch_received[sync_area][0]++;
-	else
-	  ue->dlsch_mtch_received[sync_area][0]++;
-
-	if (ue->dlsch_mch_received_sf[subframe_rx%5][0] == 1 ) {
-	  ue->dlsch_mch_received_sf[subframe_rx%5][0]=0;
-	} else {
-	  ue->dlsch_mch_received[0]+=1;
-	  ue->dlsch_mch_received_sf[subframe_rx][0]=1;
-	}
-
-#endif // #if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+        ue_send_mch_sdu(ue->Mod_id,
+                        CC_id,
+                        frame_rx,
+                        ue->dlsch_MCH[0]->harq_processes[0]->b,
+                        ue->dlsch_MCH[0]->harq_processes[0]->TBS>>3,
+                        eNB_id,// not relevant in eMBMS context
+                        sync_area);
+
+        if (mcch_active == 1)
+          ue->dlsch_mcch_received[sync_area][0]++;
+        else
+          ue->dlsch_mtch_received[sync_area][0]++;
+
+        if (ue->dlsch_mch_received_sf[subframe_rx%5][0] == 1 ) {
+          ue->dlsch_mch_received_sf[subframe_rx%5][0]=0;
+        } else {
+          ue->dlsch_mch_received[0]+=1;
+          ue->dlsch_mch_received_sf[subframe_rx][0]=1;
+        }
+
+#endif // #if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
       } // decoding sucessful
     } // pmch_mcs>=0
   } // is_pmch_subframe=true
 }
 
-void copy_harq_proc_struct(LTE_DL_UE_HARQ_t *harq_processes_dest, LTE_DL_UE_HARQ_t *current_harq_processes)
-{
-      harq_processes_dest->B              = current_harq_processes->B              ;
-      harq_processes_dest->C              = current_harq_processes->C              ;
-      harq_processes_dest->Cminus         = current_harq_processes->Cminus         ;
-      harq_processes_dest->Cplus          = current_harq_processes->Cplus          ;
-      harq_processes_dest->DCINdi         = current_harq_processes->DCINdi         ;
-      harq_processes_dest->F              = current_harq_processes->F              ;
-      harq_processes_dest->G              = current_harq_processes->G              ;
-      harq_processes_dest->Kminus         = current_harq_processes->Kminus         ;
-      harq_processes_dest->Kplus          = current_harq_processes->Kplus          ;
-      harq_processes_dest->Nl             = current_harq_processes->Nl             ;
-      harq_processes_dest->Qm             = current_harq_processes->Qm             ;
-      harq_processes_dest->TBS            = current_harq_processes->TBS            ;
-      harq_processes_dest->b              = current_harq_processes->b              ;
-      harq_processes_dest->codeword       = current_harq_processes->codeword       ;
-      harq_processes_dest->delta_PUCCH    = current_harq_processes->delta_PUCCH    ;
-      harq_processes_dest->dl_power_off   = current_harq_processes->dl_power_off   ;
-      harq_processes_dest->first_tx       = current_harq_processes->first_tx       ;
-      harq_processes_dest->mcs            = current_harq_processes->mcs            ;
-      harq_processes_dest->mimo_mode      = current_harq_processes->mimo_mode      ;
-      harq_processes_dest->nb_rb          = current_harq_processes->nb_rb          ;
-      harq_processes_dest->pmi_alloc      = current_harq_processes->pmi_alloc      ;
-      harq_processes_dest->rb_alloc_even[0]  = current_harq_processes->rb_alloc_even[0] ;
-      harq_processes_dest->rb_alloc_even[1]  = current_harq_processes->rb_alloc_even[1] ;
-      harq_processes_dest->rb_alloc_even[2]  = current_harq_processes->rb_alloc_even[2] ;
-      harq_processes_dest->rb_alloc_even[3]  = current_harq_processes->rb_alloc_even[3] ;
-      harq_processes_dest->rb_alloc_odd[0]  = current_harq_processes->rb_alloc_odd[0]  ;
-      harq_processes_dest->rb_alloc_odd[1]  = current_harq_processes->rb_alloc_odd[1]  ;
-      harq_processes_dest->rb_alloc_odd[2]  = current_harq_processes->rb_alloc_odd[2]  ;
-      harq_processes_dest->rb_alloc_odd[3]  = current_harq_processes->rb_alloc_odd[3]  ;
-      harq_processes_dest->round          = current_harq_processes->round          ;
-      harq_processes_dest->rvidx          = current_harq_processes->rvidx          ;
-      harq_processes_dest->status         = current_harq_processes->status         ;
-      harq_processes_dest->vrb_type       = current_harq_processes->vrb_type       ;
+void copy_harq_proc_struct(LTE_DL_UE_HARQ_t *harq_processes_dest, LTE_DL_UE_HARQ_t *current_harq_processes) {
+  harq_processes_dest->B              = current_harq_processes->B              ;
+  harq_processes_dest->C              = current_harq_processes->C              ;
+  harq_processes_dest->Cminus         = current_harq_processes->Cminus         ;
+  harq_processes_dest->Cplus          = current_harq_processes->Cplus          ;
+  harq_processes_dest->DCINdi         = current_harq_processes->DCINdi         ;
+  harq_processes_dest->F              = current_harq_processes->F              ;
+  harq_processes_dest->G              = current_harq_processes->G              ;
+  harq_processes_dest->Kminus         = current_harq_processes->Kminus         ;
+  harq_processes_dest->Kplus          = current_harq_processes->Kplus          ;
+  harq_processes_dest->Nl             = current_harq_processes->Nl             ;
+  harq_processes_dest->Qm             = current_harq_processes->Qm             ;
+  harq_processes_dest->TBS            = current_harq_processes->TBS            ;
+  harq_processes_dest->b              = current_harq_processes->b              ;
+  harq_processes_dest->codeword       = current_harq_processes->codeword       ;
+  harq_processes_dest->delta_PUCCH    = current_harq_processes->delta_PUCCH    ;
+  harq_processes_dest->dl_power_off   = current_harq_processes->dl_power_off   ;
+  harq_processes_dest->first_tx       = current_harq_processes->first_tx       ;
+  harq_processes_dest->mcs            = current_harq_processes->mcs            ;
+  harq_processes_dest->mimo_mode      = current_harq_processes->mimo_mode      ;
+  harq_processes_dest->nb_rb          = current_harq_processes->nb_rb          ;
+  harq_processes_dest->pmi_alloc      = current_harq_processes->pmi_alloc      ;
+  harq_processes_dest->rb_alloc_even[0]  = current_harq_processes->rb_alloc_even[0] ;
+  harq_processes_dest->rb_alloc_even[1]  = current_harq_processes->rb_alloc_even[1] ;
+  harq_processes_dest->rb_alloc_even[2]  = current_harq_processes->rb_alloc_even[2] ;
+  harq_processes_dest->rb_alloc_even[3]  = current_harq_processes->rb_alloc_even[3] ;
+  harq_processes_dest->rb_alloc_odd[0]  = current_harq_processes->rb_alloc_odd[0]  ;
+  harq_processes_dest->rb_alloc_odd[1]  = current_harq_processes->rb_alloc_odd[1]  ;
+  harq_processes_dest->rb_alloc_odd[2]  = current_harq_processes->rb_alloc_odd[2]  ;
+  harq_processes_dest->rb_alloc_odd[3]  = current_harq_processes->rb_alloc_odd[3]  ;
+  harq_processes_dest->round          = current_harq_processes->round          ;
+  harq_processes_dest->rvidx          = current_harq_processes->rvidx          ;
+  harq_processes_dest->status         = current_harq_processes->status         ;
+  harq_processes_dest->vrb_type       = current_harq_processes->vrb_type       ;
 }
 
-void copy_ack_struct(harq_status_t *harq_ack_dest, harq_status_t *current_harq_ack)
-{
-    memcpy(harq_ack_dest, current_harq_ack, sizeof(harq_status_t));
+void copy_ack_struct(harq_status_t *harq_ack_dest, harq_status_t *current_harq_ack) {
+  memcpy(harq_ack_dest, current_harq_ack, sizeof(harq_status_t));
 }
 
 void ue_pdsch_procedures(PHY_VARS_UE *ue, UE_rxtx_proc_t *proc, int eNB_id, PDSCH_t pdsch, LTE_UE_DLSCH_t *dlsch0, LTE_UE_DLSCH_t *dlsch1, int s0, int s1, int abstraction_flag) {
-
   int subframe_rx = proc->subframe_rx;
   int m;
   int harq_pid;
   int i_mod,eNB_id_i,dual_stream_UE;
   int first_symbol_flag=0;
 
-  if (dlsch0->active == 0)
+  if (dlsch0 && dlsch0->active == 0)
     return;
 
-  for (m=s0;m<=s1;m++) {
-
+  for (m=s0; m<=s1; m++) {
     if (dlsch0 && (!dlsch1))  {
       harq_pid = dlsch0->current_harq_pid;
       LOG_D(PHY,"[UE %d] PDSCH active in subframe %d, harq_pid %d Symbol %d\n",ue->Mod_id,subframe_rx,harq_pid,m);
@@ -3317,15 +3004,11 @@ void ue_pdsch_procedures(PHY_VARS_UE *ue, UE_rxtx_proc_t *proc, int eNB_id, PDSC
         dual_stream_UE = 1;
         eNB_id_i = ue->n_connected_eNB;
         i_mod =  dlsch0->harq_processes[harq_pid]->Qm;
-
-      }
-      else if((pdsch==PDSCH) && (ue->transmission_mode[eNB_id]==3))
-      {
-          dual_stream_UE = rx_IC_dual_stream;
-          eNB_id_i       = eNB_id;
-          i_mod          = 0;
-      }
-      else {
+      } else if((pdsch==PDSCH) && (ue->transmission_mode[eNB_id]==3)) {
+        dual_stream_UE = rx_IC_dual_stream;
+        eNB_id_i       = eNB_id;
+        i_mod          = 0;
+      } else {
         dual_stream_UE = 0;
         eNB_id_i = eNB_id+1;
         i_mod = 0;
@@ -3343,48 +3026,50 @@ void ue_pdsch_procedures(PHY_VARS_UE *ue, UE_rxtx_proc_t *proc, int eNB_id, PDSC
       }
 
       if ((m==s0) && (m<4))
-          first_symbol_flag = 1;
+        first_symbol_flag = 1;
       else
-          first_symbol_flag = 0;
+        first_symbol_flag = 0;
 
       if (LOG_DEBUGFLAG(UE_TIMING)) {
         uint8_t slot = 0;
+
         if(m >= ue->frame_parms.symbols_per_tti>>1)
-        slot = 1;
+          slot = 1;
+
         start_meas(&ue->dlsch_llr_stats_parallelization[ue->current_thread_id[subframe_rx]][slot]);
       }
+
       // process DLSCH received in first slot
       rx_pdsch(ue,
-	       pdsch,
-	       eNB_id,
-	       eNB_id_i,
-	       proc->frame_rx,
-	       subframe_rx,  // subframe,
-	       m,
-	       first_symbol_flag,
-	       dual_stream_UE,
-	       i_mod,
-	       dlsch0->current_harq_pid);
+               pdsch,
+               eNB_id,
+               eNB_id_i,
+               proc->frame_rx,
+               subframe_rx,  // subframe,
+               m,
+               first_symbol_flag,
+               dual_stream_UE,
+               i_mod,
+               dlsch0->current_harq_pid);
+
       if (LOG_DEBUGFLAG(UE_TIMING)) {
-  	uint8_t slot = 0;
-  	if(m >= ue->frame_parms.symbols_per_tti>>1)
-  	  slot = 1;
-  	stop_meas(&ue->dlsch_llr_stats_parallelization[ue->current_thread_id[subframe_rx]][slot]);
-  	LOG_UI(PHY, "[AbsSFN %d.%d] LLR Computation Symbol %d %5.2f \n",proc->frame_rx,subframe_rx,m,ue->dlsch_llr_stats_parallelization[ue->current_thread_id[subframe_rx]][slot].p_time/(cpuf*1000.0));
-      }
+        uint8_t slot = 0;
 
+        if(m >= ue->frame_parms.symbols_per_tti>>1)
+          slot = 1;
 
+        stop_meas(&ue->dlsch_llr_stats_parallelization[ue->current_thread_id[subframe_rx]][slot]);
+        LOG_I(PHY, "[AbsSFN %d.%d] LLR Computation Symbol %d %5.2f \n",proc->frame_rx,subframe_rx,m,ue->dlsch_llr_stats_parallelization[ue->current_thread_id[subframe_rx]][slot].p_time/(cpuf*1000.0));
+      }
 
-      if(first_symbol_flag)
-      {
-          proc->first_symbol_available = 1;
+      if(first_symbol_flag) {
+        proc->first_symbol_available = 1;
       }
     } // CRNTI active
   }
 }
 
 void process_rar(PHY_VARS_UE *ue, UE_rxtx_proc_t *proc, int eNB_id, runmode_t mode, int abstraction_flag) {
-
   int frame_rx = proc->frame_rx;
   int subframe_rx = proc->subframe_rx;
   int timing_advance;
@@ -3393,99 +3078,85 @@ void process_rar(PHY_VARS_UE *ue, UE_rxtx_proc_t *proc, int eNB_id, runmode_t mo
   uint8_t *rar;
   uint8_t next1_thread_id = ue->current_thread_id[subframe_rx]== (RX_NB_TH-1) ? 0:(ue->current_thread_id[subframe_rx]+1);
   uint8_t next2_thread_id = next1_thread_id== (RX_NB_TH-1) ? 0:(next1_thread_id+1);
-
   LOG_D(PHY,"[UE  %d][RAPROC] Frame %d subframe %d Received RAR  mode %d\n",
-  ue->Mod_id,
-  frame_rx,
-  subframe_rx, ue->UE_mode[eNB_id]);
-
+        ue->Mod_id,
+        frame_rx,
+        subframe_rx, ue->UE_mode[eNB_id]);
 
   if (ue->mac_enabled == 1) {
     if ((ue->UE_mode[eNB_id] != PUSCH) &&
-  (ue->prach_resources[eNB_id]->Msg3!=NULL)) {
+        (ue->prach_resources[eNB_id]->Msg3!=NULL)) {
       LOG_D(PHY,"[UE  %d][RAPROC] Frame %d subframe %d Invoking MAC for RAR (current preamble %d)\n",
-	    ue->Mod_id,frame_rx,
-	    subframe_rx,
-	    ue->prach_resources[eNB_id]->ra_PreambleIndex);
-      
+            ue->Mod_id,frame_rx,
+            subframe_rx,
+            ue->prach_resources[eNB_id]->ra_PreambleIndex);
       timing_advance = ue_process_rar(ue->Mod_id,
-				      ue->CC_id,
-				      frame_rx,
-				      ue->prach_resources[eNB_id]->ra_RNTI,
-				      dlsch0->harq_processes[0]->b,
-				      &ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->crnti,
-				      ue->prach_resources[eNB_id]->ra_PreambleIndex,
-				      dlsch0->harq_processes[0]->b); // alter the 'b' buffer so it contains only the selected RAR header and RAR payload
-      
+                                      ue->CC_id,
+                                      frame_rx,
+                                      ue->prach_resources[eNB_id]->ra_RNTI,
+                                      dlsch0->harq_processes[0]->b,
+                                      &ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->crnti,
+                                      ue->prach_resources[eNB_id]->ra_PreambleIndex,
+                                      dlsch0->harq_processes[0]->b); // alter the 'b' buffer so it contains only the selected RAR header and RAR payload
       ue->pdcch_vars[next1_thread_id][eNB_id]->crnti = ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->crnti;
       ue->pdcch_vars[next2_thread_id][eNB_id]->crnti = ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->crnti;
 
-      
       if (timing_advance!=0xffff) {
-
-              LOG_D(PHY,"[UE  %d][RAPROC] Frame %d subframe %d Got rnti %x and timing advance %d from RAR\n",
+        LOG_D(PHY,"[UE  %d][RAPROC] Frame %d subframe %d Got rnti %x and timing advance %d from RAR\n",
               ue->Mod_id,
               frame_rx,
               subframe_rx,
               ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->crnti,
               timing_advance);
-
-	      // remember this c-rnti is still a tc-rnti
-	      
-	      ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->crnti_is_temporary = 1;
-	      
-	      //timing_advance = 0;
-	      process_timing_advance_rar(ue,proc,timing_advance);
-	      
-	      if (mode!=debug_prach) {
-		ue->ulsch_Msg3_active[eNB_id]=1;
-		get_Msg3_alloc(&ue->frame_parms,
-			       subframe_rx,
-			       frame_rx,
-			       &ue->ulsch_Msg3_frame[eNB_id],
-			       &ue->ulsch_Msg3_subframe[eNB_id]);
-		
-		LOG_D(PHY,"[UE  %d][RAPROC] Got Msg3_alloc Frame %d subframe %d: Msg3_frame %d, Msg3_subframe %d\n",
-		      ue->Mod_id,
-		      frame_rx,
-		      subframe_rx,
-		      ue->ulsch_Msg3_frame[eNB_id],
-		      ue->ulsch_Msg3_subframe[eNB_id]);
-		harq_pid = subframe2harq_pid(&ue->frame_parms,
-					     ue->ulsch_Msg3_frame[eNB_id],
-					     ue->ulsch_Msg3_subframe[eNB_id]);
-		ue->ulsch[eNB_id]->harq_processes[harq_pid]->round = 0;
-		
-		ue->UE_mode[eNB_id] = RA_RESPONSE;
-		//      ue->Msg3_timer[eNB_id] = 10;
-		ue->ulsch[eNB_id]->power_offset = 6;
-		ue->ulsch_no_allocation_counter[eNB_id] = 0;
-	      }
+        // remember this c-rnti is still a tc-rnti
+        ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->crnti_is_temporary = 1;
+        //timing_advance = 0;
+        process_timing_advance_rar(ue,proc,timing_advance);
+
+        if (mode!=debug_prach) {
+          ue->ulsch_Msg3_active[eNB_id]=1;
+          get_Msg3_alloc(&ue->frame_parms,
+                         subframe_rx,
+                         frame_rx,
+                         &ue->ulsch_Msg3_frame[eNB_id],
+                         &ue->ulsch_Msg3_subframe[eNB_id]);
+          LOG_D(PHY,"[UE  %d][RAPROC] Got Msg3_alloc Frame %d subframe %d: Msg3_frame %d, Msg3_subframe %d\n",
+                ue->Mod_id,
+                frame_rx,
+                subframe_rx,
+                ue->ulsch_Msg3_frame[eNB_id],
+                ue->ulsch_Msg3_subframe[eNB_id]);
+          harq_pid = subframe2harq_pid(&ue->frame_parms,
+                                       ue->ulsch_Msg3_frame[eNB_id],
+                                       ue->ulsch_Msg3_subframe[eNB_id]);
+          ue->ulsch[eNB_id]->harq_processes[harq_pid]->round = 0;
+          ue->UE_mode[eNB_id] = RA_RESPONSE;
+          //      ue->Msg3_timer[eNB_id] = 10;
+          ue->ulsch[eNB_id]->power_offset = 6;
+          ue->ulsch_no_allocation_counter[eNB_id] = 0;
+        }
       } else { // PRACH preamble doesn't match RAR
-	LOG_W(PHY,"[UE  %d][RAPROC] Received RAR preamble (%d) doesn't match !!!\n",
-	      ue->Mod_id,
-	      ue->prach_resources[eNB_id]->ra_PreambleIndex);
+        LOG_W(PHY,"[UE  %d][RAPROC] Received RAR preamble (%d) doesn't match !!!\n",
+              ue->Mod_id,
+              ue->prach_resources[eNB_id]->ra_PreambleIndex);
       }
     } // mode != PUSCH
-  }
-  else {
+  } else {
     rar = dlsch0->harq_processes[0]->b+1;
     timing_advance = ((((uint16_t)(rar[0]&0x7f))<<4) + (rar[1]>>4));
     process_timing_advance_rar(ue,proc,timing_advance);
   }
-  
 }
 
 void ue_dlsch_procedures(PHY_VARS_UE *ue,
-       UE_rxtx_proc_t *proc,
-       int eNB_id,
-       PDSCH_t pdsch,
-       LTE_UE_DLSCH_t *dlsch0,
-       LTE_UE_DLSCH_t *dlsch1,
-       int *dlsch_errors,
-       runmode_t mode,
-       int abstraction_flag) {
-
+                         UE_rxtx_proc_t *proc,
+                         int eNB_id,
+                         PDSCH_t pdsch,
+                         LTE_UE_DLSCH_t *dlsch0,
+                         LTE_UE_DLSCH_t *dlsch1,
+                         int *dlsch_errors,
+                         runmode_t mode,
+                         int abstraction_flag) {
   int harq_pid;
   int frame_rx = proc->frame_rx;
   int subframe_rx = proc->subframe_rx;
@@ -3496,7 +3167,7 @@ void ue_dlsch_procedures(PHY_VARS_UE *ue,
   uint8_t is_cw1_active = 0;
 
   if (dlsch0==NULL)
-      AssertFatal(0,"dlsch0 should be defined at this level \n");
+    AssertFatal(0,"dlsch0 should be defined at this level \n");
 
   harq_pid = dlsch0->current_harq_pid;
   is_cw0_active = dlsch0->harq_processes[harq_pid]->status;
@@ -3507,329 +3178,332 @@ void ue_dlsch_procedures(PHY_VARS_UE *ue,
   LOG_D(PHY,"AbsSubframe %d.%d Start Turbo Decoder for CW0 [harq_pid %d] ? %d \n", frame_rx%1024, subframe_rx, harq_pid, is_cw0_active);
   LOG_D(PHY,"AbsSubframe %d.%d Start Turbo Decoder for CW1 [harq_pid %d] ? %d \n", frame_rx%1024, subframe_rx, harq_pid, is_cw1_active);
 
-  if(is_cw0_active && is_cw1_active)
-  {
-      dlsch0->Kmimo = 2;
-      dlsch1->Kmimo = 2;
-  }
-  else
-  {
-      dlsch0->Kmimo = 1;
+  if(is_cw0_active && is_cw1_active) {
+    dlsch0->Kmimo = 2;
+    dlsch1->Kmimo = 2;
+  } else {
+    dlsch0->Kmimo = 1;
   }
+
   if (1) {
     switch (pdsch) {
-    case SI_PDSCH:
-      pdsch_vars = ue->pdsch_vars_SI[eNB_id];
-      break;
-    case RA_PDSCH:
-      pdsch_vars = ue->pdsch_vars_ra[eNB_id];
-      break;
-    case P_PDSCH:
-      pdsch_vars = ue->pdsch_vars_p[eNB_id];
-      break;
-    case PDSCH:
-      pdsch_vars = ue->pdsch_vars[ue->current_thread_id[subframe_rx]][eNB_id];
-      break;
-    case PMCH:
-    case PDSCH1:
-      LOG_E(PHY,"Illegal PDSCH %d for ue_pdsch_procedures\n",pdsch);
-      pdsch_vars = NULL;
-      return;
-      break;
-    default:
-      pdsch_vars = NULL;
-      return;
-      break;
+      case SI_PDSCH:
+        pdsch_vars = ue->pdsch_vars_SI[eNB_id];
+        break;
+
+      case RA_PDSCH:
+        pdsch_vars = ue->pdsch_vars_ra[eNB_id];
+        break;
+
+      case P_PDSCH:
+        pdsch_vars = ue->pdsch_vars_p[eNB_id];
+        break;
+
+      case PDSCH:
+        pdsch_vars = ue->pdsch_vars[ue->current_thread_id[subframe_rx]][eNB_id];
+        break;
+
+      case PMCH:
+      case PDSCH1:
+        LOG_E(PHY,"Illegal PDSCH %d for ue_pdsch_procedures\n",pdsch);
+        pdsch_vars = NULL;
+        return;
+        break;
 
+      default:
+        pdsch_vars = NULL;
+        return;
+        break;
     }
+
     if (frame_rx < *dlsch_errors)
       *dlsch_errors=0;
 
     if (pdsch==RA_PDSCH) {
-      
       if (ue->prach_resources[eNB_id]!=NULL)
-	dlsch0->rnti = ue->prach_resources[eNB_id]->ra_RNTI;
+        dlsch0->rnti = ue->prach_resources[eNB_id]->ra_RNTI;
       else {
-	LOG_E(PHY,"[UE %d] Frame %d, subframe %d: FATAL, prach_resources is NULL\n",ue->Mod_id,frame_rx,subframe_rx);
-	AssertFatal(1==0,"prach_resources is NULL");
+        LOG_E(PHY,"[UE %d] Frame %d, subframe %d: FATAL, prach_resources is NULL\n",ue->Mod_id,frame_rx,subframe_rx);
+        AssertFatal(1==0,"prach_resources is NULL");
       }
     }
-    
-      
-      // start turbo decode for CW 0
-      dlsch0->harq_processes[harq_pid]->G = get_G(&ue->frame_parms,
-						  dlsch0->harq_processes[harq_pid]->nb_rb,
-						  dlsch0->harq_processes[harq_pid]->rb_alloc_even,
-						  dlsch0->harq_processes[harq_pid]->Qm,
-						  dlsch0->harq_processes[harq_pid]->Nl,
-						  ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols,
-						  frame_rx,
-						  subframe_rx,
-						  ue->transmission_mode[eNB_id]<7?0:ue->transmission_mode[eNB_id]);
+
+    // start turbo decode for CW 0
+    dlsch0->harq_processes[harq_pid]->G = get_G(&ue->frame_parms,
+                                          dlsch0->harq_processes[harq_pid]->nb_rb,
+                                          dlsch0->harq_processes[harq_pid]->rb_alloc_even,
+                                          dlsch0->harq_processes[harq_pid]->Qm,
+                                          dlsch0->harq_processes[harq_pid]->Nl,
+                                          ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols,
+                                          frame_rx,
+                                          subframe_rx,
+                                          ue->transmission_mode[eNB_id]<7?0:ue->transmission_mode[eNB_id]);
+
+    if (LOG_DEBUGFLAG(UE_TIMING)) {
+      start_meas(&ue->dlsch_unscrambling_stats);
+    }
+
+    dlsch_unscrambling(&ue->frame_parms,
+                       0,
+                       dlsch0,
+                       dlsch0->harq_processes[harq_pid]->G,
+                       pdsch_vars->llr[0],
+                       0,
+                       subframe_rx<<1);
+
+    if (LOG_DEBUGFLAG(UE_TIMING)) {
+      stop_meas(&ue->dlsch_unscrambling_stats);
+    }
+
+    LOG_D(PHY," ------ start turbo decoder for AbsSubframe %d.%d / %d  ------  \n", frame_rx, subframe_rx, harq_pid);
+    LOG_D(PHY,"start turbo decode for CW 0 for AbsSubframe %d.%d / %d --> nb_rb %d \n", frame_rx, subframe_rx, harq_pid, dlsch0->harq_processes[harq_pid]->nb_rb);
+    LOG_D(PHY,"start turbo decode for CW 0 for AbsSubframe %d.%d / %d  --> rb_alloc_even %x \n", frame_rx, subframe_rx, harq_pid,
+          (unsigned int)((intptr_t)dlsch0->harq_processes[harq_pid]->rb_alloc_even));
+    LOG_D(PHY,"start turbo decode for CW 0 for AbsSubframe %d.%d / %d  --> Qm %d \n", frame_rx, subframe_rx, harq_pid, dlsch0->harq_processes[harq_pid]->Qm);
+    LOG_D(PHY,"start turbo decode for CW 0 for AbsSubframe %d.%d / %d  --> Nl %d \n", frame_rx, subframe_rx, harq_pid, dlsch0->harq_processes[harq_pid]->Nl);
+    LOG_D(PHY,"start turbo decode for CW 0 for AbsSubframe %d.%d / %d  --> G  %d \n", frame_rx, subframe_rx, harq_pid, dlsch0->harq_processes[harq_pid]->G);
+    LOG_D(PHY,"start turbo decode for CW 0 for AbsSubframe %d.%d / %d  --> Kmimo  %d \n", frame_rx, subframe_rx, harq_pid, dlsch0->Kmimo);
+    LOG_D(PHY,"start turbo decode for CW 0 for AbsSubframe %d.%d / %d  --> Pdcch Sym  %d \n", frame_rx, subframe_rx, harq_pid,
+          ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols);
+
+    if (LOG_DEBUGFLAG(UE_TIMING)) {
+      start_meas(&ue->dlsch_decoding_stats[ue->current_thread_id[subframe_rx]]);
+    }
+
+    ret = dlsch_decoding(ue,
+                         pdsch_vars->llr[0],
+                         &ue->frame_parms,
+                         dlsch0,
+                         dlsch0->harq_processes[harq_pid],
+                         frame_rx,
+                         subframe_rx,
+                         harq_pid,
+                         pdsch==PDSCH?1:0,
+                         dlsch0->harq_processes[harq_pid]->TBS>256?1:0);
+
+    if (LOG_DEBUGFLAG(UE_TIMING)) {
+      stop_meas(&ue->dlsch_decoding_stats[ue->current_thread_id[subframe_rx]]);
+      LOG_I(PHY, " --> Unscrambling for CW0 %5.3f\n",
+            (ue->dlsch_unscrambling_stats.p_time)/(cpuf*1000.0));
+      LOG_I(PHY, "AbsSubframe %d.%d --> Turbo Decoding for CW0 %5.3f\n",
+            frame_rx%1024, subframe_rx,(ue->dlsch_decoding_stats[ue->current_thread_id[subframe_rx]].p_time)/(cpuf*1000.0));
+    }
+
+    if(is_cw1_active) {
+      // start turbo decode for CW 1
+      dlsch1->harq_processes[harq_pid]->G = get_G(&ue->frame_parms,
+                                            dlsch1->harq_processes[harq_pid]->nb_rb,
+                                            dlsch1->harq_processes[harq_pid]->rb_alloc_even,
+                                            dlsch1->harq_processes[harq_pid]->Qm,
+                                            dlsch1->harq_processes[harq_pid]->Nl,
+                                            ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols,
+                                            frame_rx,
+                                            subframe_rx,
+                                            ue->transmission_mode[eNB_id]<7?0:ue->transmission_mode[eNB_id]);
+
       if (LOG_DEBUGFLAG(UE_TIMING)) {
         start_meas(&ue->dlsch_unscrambling_stats);
       }
+
       dlsch_unscrambling(&ue->frame_parms,
-			 0,
-			 dlsch0,
-			 dlsch0->harq_processes[harq_pid]->G,
-			 pdsch_vars->llr[0],
-			 0,
-			 subframe_rx<<1);
+                         0,
+                         dlsch1,
+                         dlsch1->harq_processes[harq_pid]->G,
+                         pdsch_vars->llr[1],
+                         1,
+                         subframe_rx<<1);
+
       if (LOG_DEBUGFLAG(UE_TIMING)) {
         stop_meas(&ue->dlsch_unscrambling_stats);
       }
-      
-      LOG_D(PHY," ------ start turbo decoder for AbsSubframe %d.%d / %d  ------  \n", frame_rx, subframe_rx, harq_pid);
-      LOG_D(PHY,"start turbo decode for CW 0 for AbsSubframe %d.%d / %d --> nb_rb %d \n", frame_rx, subframe_rx, harq_pid, dlsch0->harq_processes[harq_pid]->nb_rb);
-      LOG_D(PHY,"start turbo decode for CW 0 for AbsSubframe %d.%d / %d  --> rb_alloc_even %x \n", frame_rx, subframe_rx, harq_pid, (unsigned int)((intptr_t)dlsch0->harq_processes[harq_pid]->rb_alloc_even));
-      LOG_D(PHY,"start turbo decode for CW 0 for AbsSubframe %d.%d / %d  --> Qm %d \n", frame_rx, subframe_rx, harq_pid, dlsch0->harq_processes[harq_pid]->Qm);
-      LOG_D(PHY,"start turbo decode for CW 0 for AbsSubframe %d.%d / %d  --> Nl %d \n", frame_rx, subframe_rx, harq_pid, dlsch0->harq_processes[harq_pid]->Nl);
-      LOG_D(PHY,"start turbo decode for CW 0 for AbsSubframe %d.%d / %d  --> G  %d \n", frame_rx, subframe_rx, harq_pid, dlsch0->harq_processes[harq_pid]->G);
-      LOG_D(PHY,"start turbo decode for CW 0 for AbsSubframe %d.%d / %d  --> Kmimo  %d \n", frame_rx, subframe_rx, harq_pid, dlsch0->Kmimo);
-      LOG_D(PHY,"start turbo decode for CW 0 for AbsSubframe %d.%d / %d  --> Pdcch Sym  %d \n", frame_rx, subframe_rx, harq_pid, ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols);
-      
+
+      LOG_D(PHY,"start turbo decode for CW 1 for AbsSubframe %d.%d / %d --> nb_rb %d \n", frame_rx, subframe_rx, harq_pid, dlsch1->harq_processes[harq_pid]->nb_rb);
+      LOG_D(PHY,"start turbo decode for CW 1 for AbsSubframe %d.%d / %d  --> rb_alloc_even %x \n", frame_rx, subframe_rx, harq_pid, (uint16_t)((intptr_t)dlsch1->harq_processes[harq_pid]->rb_alloc_even));
+      LOG_D(PHY,"start turbo decode for CW 1 for AbsSubframe %d.%d / %d  --> Qm %d \n", frame_rx, subframe_rx, harq_pid, dlsch1->harq_processes[harq_pid]->Qm);
+      LOG_D(PHY,"start turbo decode for CW 1 for AbsSubframe %d.%d / %d  --> Nl %d \n", frame_rx, subframe_rx, harq_pid, dlsch1->harq_processes[harq_pid]->Nl);
+      LOG_D(PHY,"start turbo decode for CW 1 for AbsSubframe %d.%d / %d  --> G  %d \n", frame_rx, subframe_rx, harq_pid, dlsch1->harq_processes[harq_pid]->G);
+      LOG_D(PHY,"start turbo decode for CW 1 for AbsSubframe %d.%d / %d  --> Kmimo  %d \n", frame_rx, subframe_rx, harq_pid, dlsch1->Kmimo);
+      LOG_D(PHY,"start turbo decode for CW 1 for AbsSubframe %d.%d / %d  --> Pdcch Sym  %d \n", frame_rx, subframe_rx, harq_pid,
+            ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols);
+
       if (LOG_DEBUGFLAG(UE_TIMING)) {
         start_meas(&ue->dlsch_decoding_stats[ue->current_thread_id[subframe_rx]]);
       }
-      ret = dlsch_decoding(ue,
-			   pdsch_vars->llr[0],
-			   &ue->frame_parms,
-			   dlsch0,
-			   dlsch0->harq_processes[harq_pid],
-			   frame_rx,
-			   subframe_rx,
-			   harq_pid,
-			   pdsch==PDSCH?1:0,
-			   dlsch0->harq_processes[harq_pid]->TBS>256?1:0);
-      
+
+      ret1 = dlsch_decoding(ue,
+                            pdsch_vars->llr[1],
+                            &ue->frame_parms,
+                            dlsch1,
+                            dlsch1->harq_processes[harq_pid],
+                            frame_rx,
+                            subframe_rx,
+                            harq_pid,
+                            pdsch==PDSCH?1:0,
+                            dlsch1->harq_processes[harq_pid]->TBS>256?1:0);
+
       if (LOG_DEBUGFLAG(UE_TIMING)) {
         stop_meas(&ue->dlsch_decoding_stats[ue->current_thread_id[subframe_rx]]);
-        LOG_UI(PHY, " --> Unscrambling for CW0 %5.3f\n",
-	      (ue->dlsch_unscrambling_stats.p_time)/(cpuf*1000.0));
-        LOG_UI(PHY, "AbsSubframe %d.%d --> Turbo Decoding for CW0 %5.3f\n",
-	      frame_rx%1024, subframe_rx,(ue->dlsch_decoding_stats[ue->current_thread_id[subframe_rx]].p_time)/(cpuf*1000.0));
-      
+        LOG_I(PHY, " --> Unscrambling for CW1 %5.3f\n",
+              (ue->dlsch_unscrambling_stats.p_time)/(cpuf*1000.0));
+        LOG_I(PHY, "AbsSubframe %d.%d --> Turbo Decoding for CW1 %5.3f\n",
+              frame_rx%1024, subframe_rx,(ue->dlsch_decoding_stats[ue->current_thread_id[subframe_rx]].p_time)/(cpuf*1000.0));
       }
-      if(is_cw1_active)
-	{
-          // start turbo decode for CW 1
-          dlsch1->harq_processes[harq_pid]->G = get_G(&ue->frame_parms,
-						      dlsch1->harq_processes[harq_pid]->nb_rb,
-						      dlsch1->harq_processes[harq_pid]->rb_alloc_even,
-						      dlsch1->harq_processes[harq_pid]->Qm,
-						      dlsch1->harq_processes[harq_pid]->Nl,
-						      ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols,
-						      frame_rx,
-						      subframe_rx,
-						      ue->transmission_mode[eNB_id]<7?0:ue->transmission_mode[eNB_id]);
-          if (LOG_DEBUGFLAG(UE_TIMING)) {
-            start_meas(&ue->dlsch_unscrambling_stats);
-          }
-          dlsch_unscrambling(&ue->frame_parms,
-			     0,
-			     dlsch1,
-			     dlsch1->harq_processes[harq_pid]->G,
-			     pdsch_vars->llr[1],
-			     1,
-			     subframe_rx<<1);
-          if (LOG_DEBUGFLAG(UE_TIMING)) {
-            stop_meas(&ue->dlsch_unscrambling_stats);
-          }
-	  
-          LOG_D(PHY,"start turbo decode for CW 1 for AbsSubframe %d.%d / %d --> nb_rb %d \n", frame_rx, subframe_rx, harq_pid, dlsch1->harq_processes[harq_pid]->nb_rb);
-          LOG_D(PHY,"start turbo decode for CW 1 for AbsSubframe %d.%d / %d  --> rb_alloc_even %x \n", frame_rx, subframe_rx, harq_pid, (uint16_t)((intptr_t)dlsch1->harq_processes[harq_pid]->rb_alloc_even));
-          LOG_D(PHY,"start turbo decode for CW 1 for AbsSubframe %d.%d / %d  --> Qm %d \n", frame_rx, subframe_rx, harq_pid, dlsch1->harq_processes[harq_pid]->Qm);
-          LOG_D(PHY,"start turbo decode for CW 1 for AbsSubframe %d.%d / %d  --> Nl %d \n", frame_rx, subframe_rx, harq_pid, dlsch1->harq_processes[harq_pid]->Nl);
-          LOG_D(PHY,"start turbo decode for CW 1 for AbsSubframe %d.%d / %d  --> G  %d \n", frame_rx, subframe_rx, harq_pid, dlsch1->harq_processes[harq_pid]->G);
-          LOG_D(PHY,"start turbo decode for CW 1 for AbsSubframe %d.%d / %d  --> Kmimo  %d \n", frame_rx, subframe_rx, harq_pid, dlsch1->Kmimo);
-          LOG_D(PHY,"start turbo decode for CW 1 for AbsSubframe %d.%d / %d  --> Pdcch Sym  %d \n", frame_rx, subframe_rx, harq_pid, ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols);
-	  
-          if (LOG_DEBUGFLAG(UE_TIMING)) {
-            start_meas(&ue->dlsch_decoding_stats[ue->current_thread_id[subframe_rx]]);
-          }
-	  
-          ret1 = dlsch_decoding(ue,
-				pdsch_vars->llr[1],
-				&ue->frame_parms,
-				dlsch1,
-				dlsch1->harq_processes[harq_pid],
-				frame_rx,
-				subframe_rx,
-				harq_pid,
-				pdsch==PDSCH?1:0,
-				dlsch1->harq_processes[harq_pid]->TBS>256?1:0);
-	  
-          if (LOG_DEBUGFLAG(UE_TIMING)) {
-            stop_meas(&ue->dlsch_decoding_stats[ue->current_thread_id[subframe_rx]]);
-            LOG_UI(PHY, " --> Unscrambling for CW1 %5.3f\n",
-		  (ue->dlsch_unscrambling_stats.p_time)/(cpuf*1000.0));
-            LOG_UI(PHY, "AbsSubframe %d.%d --> Turbo Decoding for CW1 %5.3f\n",
-		  frame_rx%1024, subframe_rx,(ue->dlsch_decoding_stats[ue->current_thread_id[subframe_rx]].p_time)/(cpuf*1000.0));
-          }
 
-          LOG_D(PHY,"AbsSubframe %d.%d --> Turbo Decoding for CW1 %5.3f\n",
-		frame_rx%1024, subframe_rx,(ue->dlsch_decoding_stats[ue->current_thread_id[subframe_rx]].p_time)/(cpuf*1000.0));
-	}
-      
-      LOG_D(PHY," ------ end turbo decoder for AbsSubframe %d.%d ------  \n", frame_rx, subframe_rx);
-    
-    
+      LOG_D(PHY,"AbsSubframe %d.%d --> Turbo Decoding for CW1 %5.3f\n",
+            frame_rx%1024, subframe_rx,(ue->dlsch_decoding_stats[ue->current_thread_id[subframe_rx]].p_time)/(cpuf*1000.0));
+    }
+
+    LOG_D(PHY," ------ end turbo decoder for AbsSubframe %d.%d ------  \n", frame_rx, subframe_rx);
 
     // Check CRC for CW 0
     if (ret == (1+dlsch0->max_turbo_iterations)) {
       *dlsch_errors=*dlsch_errors+1;
 
-      if(dlsch0->rnti != 0xffff)
-      {
-
-	LOG_D(PHY,"[UE  %d][PDSCH %x/%d] AbsSubframe %d.%d : DLSCH CW0 in error (rv %d,round %d, mcs %d,TBS %d)\n",
-	      ue->Mod_id,dlsch0->rnti,
-	      harq_pid,frame_rx,subframe_rx,
-	      dlsch0->harq_processes[harq_pid]->rvidx,
-	      dlsch0->harq_processes[harq_pid]->round,
-	      dlsch0->harq_processes[harq_pid]->mcs,
-	      dlsch0->harq_processes[harq_pid]->TBS);
+      if(dlsch0->rnti != 0xffff) {
+        LOG_D(PHY,"[UE  %d][PDSCH %x/%d] AbsSubframe %d.%d : DLSCH CW0 in error (rv %d,round %d, mcs %d,TBS %d)\n",
+              ue->Mod_id,dlsch0->rnti,
+              harq_pid,frame_rx,subframe_rx,
+              dlsch0->harq_processes[harq_pid]->rvidx,
+              dlsch0->harq_processes[harq_pid]->round,
+              dlsch0->harq_processes[harq_pid]->mcs,
+              dlsch0->harq_processes[harq_pid]->TBS);
       }
-
-
     } else {
-        if(dlsch0->rnti != 0xffff)
-        {
-      LOG_D(PHY,"[UE  %d][PDSCH %x/%d] AbsSubframe %d.%d : Received DLSCH CW0 (rv %d,round %d, mcs %d,TBS %d)\n",
-            ue->Mod_id,dlsch0->rnti,
-            harq_pid,frame_rx,subframe_rx,
-            dlsch0->harq_processes[harq_pid]->rvidx,
-            dlsch0->harq_processes[harq_pid]->round,
-            dlsch0->harq_processes[harq_pid]->mcs,
-            dlsch0->harq_processes[harq_pid]->TBS);
-        }
+      if(dlsch0->rnti != 0xffff) {
+        LOG_D(PHY,"[UE  %d][PDSCH %x/%d] AbsSubframe %d.%d : Received DLSCH CW0 (rv %d,round %d, mcs %d,TBS %d)\n",
+              ue->Mod_id,dlsch0->rnti,
+              harq_pid,frame_rx,subframe_rx,
+              dlsch0->harq_processes[harq_pid]->rvidx,
+              dlsch0->harq_processes[harq_pid]->round,
+              dlsch0->harq_processes[harq_pid]->mcs,
+              dlsch0->harq_processes[harq_pid]->TBS);
+      }
 
-      if ( LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)){
+      if ( LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
         int j;
         LOG_D(PHY,"dlsch harq_pid %d (rx): \n",dlsch0->current_harq_pid);
 
         for (j=0; j<dlsch0->harq_processes[dlsch0->current_harq_pid]->TBS>>3; j++)
-            LOG_T(PHY,"%x.",dlsch0->harq_processes[dlsch0->current_harq_pid]->b[j]);
+          LOG_T(PHY,"%x.",dlsch0->harq_processes[dlsch0->current_harq_pid]->b[j]);
 
         LOG_T(PHY,"\n");
       }
 
-
       if (ue->mac_enabled == 1) {
-	
-	switch (pdsch) {
-	case PDSCH:
-	  ue_send_sdu(ue->Mod_id,
-		      CC_id,
-		      frame_rx,
-		      subframe_rx,
-		      dlsch0->harq_processes[dlsch0->current_harq_pid]->b,
-		      dlsch0->harq_processes[dlsch0->current_harq_pid]->TBS>>3,
-		      eNB_id);
-	  break;
-	case SI_PDSCH:
-	  ue_decode_si(ue->Mod_id,
-		       CC_id,
-		       frame_rx,
-		       eNB_id,
-		       ue->dlsch_SI[eNB_id]->harq_processes[0]->b,
-		       ue->dlsch_SI[eNB_id]->harq_processes[0]->TBS>>3);
-	  break;
-	case P_PDSCH:
-		ue_decode_p(ue->Mod_id,
-		      CC_id,
-		      frame_rx,
-		      eNB_id,
-		      ue->dlsch_SI[eNB_id]->harq_processes[0]->b,
-		      ue->dlsch_SI[eNB_id]->harq_processes[0]->TBS>>3);
-	  break;
-	case RA_PDSCH:
-	  process_rar(ue,proc,eNB_id,mode,abstraction_flag);
-	  break;
-	case PDSCH1:
-	  LOG_E(PHY,"Shouldn't have PDSCH1 yet, come back later\n");
-	  AssertFatal(1==0,"exiting");
-	  break;
-	case PMCH:
-	  LOG_E(PHY,"Shouldn't have PMCH here\n");
-	  AssertFatal(1==0,"exiting");
-	  break;
-	}
+        switch (pdsch) {
+          case PDSCH:
+            ue_send_sdu(ue->Mod_id,
+                        CC_id,
+                        frame_rx,
+                        subframe_rx,
+                        dlsch0->harq_processes[dlsch0->current_harq_pid]->b,
+                        dlsch0->harq_processes[dlsch0->current_harq_pid]->TBS>>3,
+                        eNB_id);
+            break;
+
+          case SI_PDSCH:
+            ue_decode_si(ue->Mod_id,
+                         CC_id,
+                         frame_rx,
+                         eNB_id,
+                         ue->dlsch_SI[eNB_id]->harq_processes[0]->b,
+                         ue->dlsch_SI[eNB_id]->harq_processes[0]->TBS>>3);
+            break;
+
+          case P_PDSCH:
+            ue_decode_p(ue->Mod_id,
+                        CC_id,
+                        frame_rx,
+                        eNB_id,
+                        ue->dlsch_SI[eNB_id]->harq_processes[0]->b,
+                        ue->dlsch_SI[eNB_id]->harq_processes[0]->TBS>>3);
+            break;
+
+          case RA_PDSCH:
+            process_rar(ue,proc,eNB_id,mode,abstraction_flag);
+            break;
+
+          case PDSCH1:
+            LOG_E(PHY,"Shouldn't have PDSCH1 yet, come back later\n");
+            AssertFatal(1==0,"exiting");
+            break;
+
+          case PMCH:
+            LOG_E(PHY,"Shouldn't have PMCH here\n");
+            AssertFatal(1==0,"exiting");
+            break;
+        }
       }
+
       ue->total_TBS[eNB_id] =  ue->total_TBS[eNB_id] +
-	dlsch0->harq_processes[dlsch0->current_harq_pid]->TBS;
+                               dlsch0->harq_processes[dlsch0->current_harq_pid]->TBS;
       ue->total_received_bits[eNB_id] = ue->total_TBS[eNB_id] +
-	dlsch0->harq_processes[dlsch0->current_harq_pid]->TBS;
+                                        dlsch0->harq_processes[dlsch0->current_harq_pid]->TBS;
     }
+
     // Check CRC for CW 1
-    if(is_cw1_active)
-      {
-        if (ret1 == (1+dlsch0->max_turbo_iterations)) {
-	  LOG_D(PHY,"[UE  %d][PDSCH %x/%d] Frame %d subframe %d DLSCH CW1 in error (rv %d,mcs %d,TBS %d)\n",
-		ue->Mod_id,dlsch0->rnti,
-		harq_pid,frame_rx,subframe_rx,
-		dlsch0->harq_processes[harq_pid]->rvidx,
-		dlsch0->harq_processes[harq_pid]->mcs,
-		dlsch0->harq_processes[harq_pid]->TBS);
-	  
-        } else {
-	  LOG_D(PHY,"[UE  %d][PDSCH %x/%d] Frame %d subframe %d: Received DLSCH CW1 (rv %d,mcs %d,TBS %d)\n",
-		ue->Mod_id,dlsch0->rnti,
-		harq_pid,frame_rx,subframe_rx,
-		dlsch0->harq_processes[harq_pid]->rvidx,
-		dlsch0->harq_processes[harq_pid]->mcs,
-		dlsch0->harq_processes[harq_pid]->TBS);
-	  
-	  
-	  if (ue->mac_enabled == 1) {
-	    switch (pdsch) {
-	    case PDSCH:
-	      if(is_cw1_active)
-		ue_send_sdu(ue->Mod_id,
-			    CC_id,
-			    frame_rx,
-			    subframe_rx,
-			    dlsch1->harq_processes[dlsch1->current_harq_pid]->b,
-			    dlsch1->harq_processes[dlsch1->current_harq_pid]->TBS>>3,
-			    eNB_id);
-	      break;
-	    case SI_PDSCH:
-	    case P_PDSCH:
-	    case RA_PDSCH:
-	    case PDSCH1:
-	    case PMCH:
-	      AssertFatal(0,"exiting");
-	      break;
-	    }
-	  }
+    if(is_cw1_active) {
+      if (ret1 == (1+dlsch0->max_turbo_iterations)) {
+        LOG_D(PHY,"[UE  %d][PDSCH %x/%d] Frame %d subframe %d DLSCH CW1 in error (rv %d,mcs %d,TBS %d)\n",
+              ue->Mod_id,dlsch0->rnti,
+              harq_pid,frame_rx,subframe_rx,
+              dlsch0->harq_processes[harq_pid]->rvidx,
+              dlsch0->harq_processes[harq_pid]->mcs,
+              dlsch0->harq_processes[harq_pid]->TBS);
+      } else {
+        LOG_D(PHY,"[UE  %d][PDSCH %x/%d] Frame %d subframe %d: Received DLSCH CW1 (rv %d,mcs %d,TBS %d)\n",
+              ue->Mod_id,dlsch0->rnti,
+              harq_pid,frame_rx,subframe_rx,
+              dlsch0->harq_processes[harq_pid]->rvidx,
+              dlsch0->harq_processes[harq_pid]->mcs,
+              dlsch0->harq_processes[harq_pid]->TBS);
+
+        if (ue->mac_enabled == 1) {
+          switch (pdsch) {
+            case PDSCH:
+              if(is_cw1_active)
+                ue_send_sdu(ue->Mod_id,
+                            CC_id,
+                            frame_rx,
+                            subframe_rx,
+                            dlsch1->harq_processes[dlsch1->current_harq_pid]->b,
+                            dlsch1->harq_processes[dlsch1->current_harq_pid]->TBS>>3,
+                            eNB_id);
+
+              break;
+
+            case SI_PDSCH:
+            case P_PDSCH:
+            case RA_PDSCH:
+            case PDSCH1:
+            case PMCH:
+              AssertFatal(0,"exiting");
+              break;
+          }
         }
       }
-    
+    }
+
     if (LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
       LOG_D(PHY,"[UE  %d][PDSCH %x/%d] Frame %d subframe %d: PDSCH/DLSCH decoding iter %d (mcs %d, rv %d, TBS %d)\n",
-  	    ue->Mod_id,
-  	    dlsch0->rnti,harq_pid,
-  	    frame_rx,subframe_rx,ret,
-  	    dlsch0->harq_processes[harq_pid]->mcs,
-  	    dlsch0->harq_processes[harq_pid]->rvidx,
-  	    dlsch0->harq_processes[harq_pid]->TBS);
-      
+            ue->Mod_id,
+            dlsch0->rnti,harq_pid,
+            frame_rx,subframe_rx,ret,
+            dlsch0->harq_processes[harq_pid]->mcs,
+            dlsch0->harq_processes[harq_pid]->rvidx,
+            dlsch0->harq_processes[harq_pid]->TBS);
+
       if (frame_rx%100==0) {
-  	LOG_D(PHY,"[UE  %d][PDSCH %x] Frame %d subframe %d dlsch_errors %d, dlsch_received %d, dlsch_fer %d, current_dlsch_cqi %d\n",
-  	      ue->Mod_id,dlsch0->rnti,
-  	      frame_rx,subframe_rx,
-  	      ue->dlsch_errors[eNB_id],
-  	      ue->dlsch_received[eNB_id],
-  	      ue->dlsch_fer[eNB_id],
-  	      ue->measurements.wideband_cqi_tot[eNB_id]);
+        LOG_D(PHY,"[UE  %d][PDSCH %x] Frame %d subframe %d dlsch_errors %d, dlsch_received %d, dlsch_fer %d, current_dlsch_cqi %d\n",
+              ue->Mod_id,dlsch0->rnti,
+              frame_rx,subframe_rx,
+              ue->dlsch_errors[eNB_id],
+              ue->dlsch_received[eNB_id],
+              ue->dlsch_fer[eNB_id],
+              ue->measurements.wideband_cqi_tot[eNB_id]);
       }
-    
     } /*LOG_DEBUGFLAG(DEBUG_UE_PHYPROC) */
-    
   }
-  
-  
 }
 
 /*!
@@ -3841,258 +3515,256 @@ void ue_dlsch_procedures(PHY_VARS_UE *ue,
 #ifdef UE_SLOT_PARALLELISATION
 #define FIFO_PRIORITY   40
 void *UE_thread_slot1_dl_processing(void *arg) {
+  static __thread int UE_dl_slot1_processing_retval;
+  struct rx_tx_thread_data *rtd = arg;
+  UE_rxtx_proc_t *proc = rtd->proc;
+  PHY_VARS_UE    *ue   = rtd->UE;
+  int frame_rx;
+  uint8_t subframe_rx;
+  uint8_t pilot0;
+  uint8_t pilot1;
+  uint8_t slot1;
+  uint8_t next_subframe_rx;
+  uint8_t next_subframe_slot0;
+  proc->instance_cnt_slot1_dl_processing=-1;
+  proc->subframe_rx=proc->sub_frame_start;
+  char threadname[256];
+  sprintf(threadname,"UE_thread_slot1_dl_processing_%d", proc->sub_frame_start);
+  cpu_set_t cpuset;
+  CPU_ZERO(&cpuset);
+
+  if ( (proc->sub_frame_start+1)%RX_NB_TH == 0 && threads.slot1_proc_one != -1 )
+    CPU_SET(threads.slot1_proc_one, &cpuset);
+
+  if ( (proc->sub_frame_start+1)%RX_NB_TH == 1 && threads.slot1_proc_two != -1 )
+    CPU_SET(threads.slot1_proc_two, &cpuset);
+
+  if ( (proc->sub_frame_start+1)%RX_NB_TH == 2 && threads.slot1_proc_three != -1 )
+    CPU_SET(threads.slot1_proc_three, &cpuset);
+
+  init_thread(900000,1000000, FIFO_PRIORITY-1, &cpuset,
+              threadname);
+
+  while (!oai_exit) {
+    if (pthread_mutex_lock(&proc->mutex_slot1_dl_processing) != 0) {
+      LOG_E( PHY, "[SCHED][UE] error locking mutex for UE slot1 dl processing\n" );
+      exit_fun("nothing to add");
+    }
 
-    static __thread int UE_dl_slot1_processing_retval;
-    struct rx_tx_thread_data *rtd = arg;
-    UE_rxtx_proc_t *proc = rtd->proc;
-    PHY_VARS_UE    *ue   = rtd->UE;
-
-    int frame_rx;
-    uint8_t subframe_rx;
-    uint8_t pilot0;
-    uint8_t pilot1;
-    uint8_t slot1;
-
-    uint8_t next_subframe_rx;
-    uint8_t next_subframe_slot0;
-
-    proc->instance_cnt_slot1_dl_processing=-1;
-    proc->subframe_rx=proc->sub_frame_start;
-
-    char threadname[256];
-    sprintf(threadname,"UE_thread_slot1_dl_processing_%d", proc->sub_frame_start);
-
-    cpu_set_t cpuset;
-    CPU_ZERO(&cpuset);
-    if ( (proc->sub_frame_start+1)%RX_NB_TH == 0 && threads.slot1_proc_one != -1 )
-        CPU_SET(threads.slot1_proc_one, &cpuset);
-    if ( (proc->sub_frame_start+1)%RX_NB_TH == 1 && threads.slot1_proc_two != -1 )
-        CPU_SET(threads.slot1_proc_two, &cpuset);
-    if ( (proc->sub_frame_start+1)%RX_NB_TH == 2 && threads.slot1_proc_three != -1 )
-        CPU_SET(threads.slot1_proc_three, &cpuset);
-
-    init_thread(900000,1000000 , FIFO_PRIORITY-1, &cpuset,
-                threadname);
-
-    while (!oai_exit) {
-        if (pthread_mutex_lock(&proc->mutex_slot1_dl_processing) != 0) {
-            LOG_E( PHY, "[SCHED][UE] error locking mutex for UE slot1 dl processing\n" );
-            exit_fun("nothing to add");
-        }
-        while (proc->instance_cnt_slot1_dl_processing < 0) {
-            // most of the time, the thread is waiting here
-            pthread_cond_wait( &proc->cond_slot1_dl_processing, &proc->mutex_slot1_dl_processing );
-        }
-        if (pthread_mutex_unlock(&proc->mutex_slot1_dl_processing) != 0) {
-            LOG_E( PHY, "[SCHED][UE] error unlocking mutex for UE slot1 dl processing \n" );
-            exit_fun("nothing to add");
-        }
+    while (proc->instance_cnt_slot1_dl_processing < 0) {
+      // most of the time, the thread is waiting here
+      pthread_cond_wait( &proc->cond_slot1_dl_processing, &proc->mutex_slot1_dl_processing );
+    }
 
-        /*for(int th_idx=0; th_idx< RX_NB_TH; th_idx++)
-        {
-        frame_rx    = ue->proc.proc_rxtx[0].frame_rx;
-        subframe_rx = ue->proc.proc_rxtx[0].subframe_rx;
-        printf("AbsSubframe %d.%d execute dl slot1 processing \n", frame_rx, subframe_rx);
-        }*/
-        frame_rx    = proc->frame_rx;
-        subframe_rx = proc->subframe_rx;
-        next_subframe_rx    = (1+subframe_rx)%10;
-        next_subframe_slot0 = next_subframe_rx<<1;
-
-        slot1  = (subframe_rx<<1) + 1;
-        pilot0 = 0;
-
-        //printf("AbsSubframe %d.%d execute dl slot1 processing \n", frame_rx, subframe_rx);
-
-        if (ue->frame_parms.Ncp == 0) {  // normal prefix
-            pilot1 = 4;
-        } else { // extended prefix
-            pilot1 = 3;
-        }
+    if (pthread_mutex_unlock(&proc->mutex_slot1_dl_processing) != 0) {
+      LOG_E( PHY, "[SCHED][UE] error unlocking mutex for UE slot1 dl processing \n" );
+      exit_fun("nothing to add");
+    }
 
-        /**** Slot1 FE Processing ****/
-        if (LOG_DEBUGFLAG(UE_TIMING)) {
-          start_meas(&ue->ue_front_end_per_slot_stat[ue->current_thread_id[subframe_rx]][1]);
-        }
-        // I- start dl slot1 processing
-        // do first symbol of next downlink subframe for channel estimation
-        /*
-        // 1- perform FFT for pilot ofdm symbols first (ofdmSym0 next subframe ofdmSym11)
-        if (subframe_select(&ue->frame_parms,next_subframe_rx) != SF_UL)
-        {
-            front_end_fft(ue,
-                    pilot0,
-                    next_subframe_slot0,
-                    0,
-                    0);
-        }
+    /*for(int th_idx=0; th_idx< RX_NB_TH; th_idx++)
+    {
+    frame_rx    = ue->proc.proc_rxtx[0].frame_rx;
+    subframe_rx = ue->proc.proc_rxtx[0].subframe_rx;
+    printf("AbsSubframe %d.%d execute dl slot1 processing \n", frame_rx, subframe_rx);
+    }*/
+    frame_rx    = proc->frame_rx;
+    subframe_rx = proc->subframe_rx;
+    next_subframe_rx    = (1+subframe_rx)%10;
+    next_subframe_slot0 = next_subframe_rx<<1;
+    slot1  = (subframe_rx<<1) + 1;
+    pilot0 = 0;
+
+    //printf("AbsSubframe %d.%d execute dl slot1 processing \n", frame_rx, subframe_rx);
+
+    if (ue->frame_parms.Ncp == 0) {  // normal prefix
+      pilot1 = 4;
+    } else { // extended prefix
+      pilot1 = 3;
+    }
 
+    /**** Slot1 FE Processing ****/
+    if (LOG_DEBUGFLAG(UE_TIMING)) {
+      start_meas(&ue->ue_front_end_per_slot_stat[ue->current_thread_id[subframe_rx]][1]);
+    }
+
+    // I- start dl slot1 processing
+    // do first symbol of next downlink subframe for channel estimation
+    /*
+    // 1- perform FFT for pilot ofdm symbols first (ofdmSym0 next subframe ofdmSym11)
+    if (subframe_select(&ue->frame_parms,next_subframe_rx) != SF_UL)
+    {
         front_end_fft(ue,
-                pilot1,
-                slot1,
+                pilot0,
+                next_subframe_slot0,
                 0,
                 0);
-         */
-        // 1- perform FFT
-        for (int l=1; l<ue->frame_parms.symbols_per_tti>>1; l++)
-        {
-            //if( (l != pilot0) && (l != pilot1))
-            {
-            if (LOG_DEBUGFLAG(UE_TIMING)) {
-                start_meas(&ue->ofdm_demod_stats);
-            }
-                VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP, VCD_FUNCTION_IN);
-                //printf("AbsSubframe %d.%d FFT slot %d, symbol %d\n", frame_rx,subframe_rx,slot1,l);
-                front_end_fft(ue,
-                        l,
-                        slot1,
-                        0,
-                        0);
-                VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP, VCD_FUNCTION_OUT);
-                if (LOG_DEBUGFLAG(UE_TIMING)) {
-                  stop_meas(&ue->ofdm_demod_stats);
-                }
-            }
-        } // for l=1..l2
+    }
+
+    front_end_fft(ue,
+            pilot1,
+            slot1,
+            0,
+            0);
+     */
+    // 1- perform FFT
+    for (int l=1; l<ue->frame_parms.symbols_per_tti>>1; l++) {
+      //if( (l != pilot0) && (l != pilot1))
+      {
+        if (LOG_DEBUGFLAG(UE_TIMING)) {
+          start_meas(&ue->ofdm_demod_stats);
+        }
+
+        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP, VCD_FUNCTION_IN);
+        //printf("AbsSubframe %d.%d FFT slot %d, symbol %d\n", frame_rx,subframe_rx,slot1,l);
+        front_end_fft(ue,
+                      l,
+                      slot1,
+                      0,
+                      0);
+        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP, VCD_FUNCTION_OUT);
 
-        if (subframe_select(&ue->frame_parms,next_subframe_rx) != SF_UL)
-        {
-            //printf("AbsSubframe %d.%d FFT slot %d, symbol %d\n", frame_rx,subframe_rx,next_subframe_slot0,pilot0);
-            front_end_fft(ue,
+        if (LOG_DEBUGFLAG(UE_TIMING)) {
+          stop_meas(&ue->ofdm_demod_stats);
+        }
+      }
+    } // for l=1..l2
+
+    if (subframe_select(&ue->frame_parms,next_subframe_rx) != SF_UL) {
+      //printf("AbsSubframe %d.%d FFT slot %d, symbol %d\n", frame_rx,subframe_rx,next_subframe_slot0,pilot0);
+      front_end_fft(ue,
                     pilot0,
                     next_subframe_slot0,
                     0,
                     0);
-        }
+    }
 
-        // 2- perform Channel Estimation for slot1
-        for (int l=1; l<ue->frame_parms.symbols_per_tti>>1; l++)
-        {
-            if(l == pilot1)
-            {
-                //wait until channel estimation for pilot0/slot1 is available
-                uint32_t wait = 0;
-                while(proc->chan_est_pilot0_slot1_available == 0)
-                {
-                    usleep(1);
-                    wait++;
-                }
-                //printf("[slot1 dl processing] ChanEst symbol %d slot %d wait%d\n",l,slot1,wait);
-            }
-            //printf("AbsSubframe %d.%d ChanEst slot %d, symbol %d\n", frame_rx,subframe_rx,slot1,l);
-            front_end_chanEst(ue,
-                    l,
-                    slot1,
-                    0);
-            ue_measurement_procedures(l-1,ue,proc,0,1+(subframe_rx<<1),0,ue->mode);
-        }
-        //printf("AbsSubframe %d.%d ChanEst slot %d, symbol %d\n", frame_rx,subframe_rx,next_subframe_slot0,pilot0);
-        front_end_chanEst(ue,
-                pilot0,
-                next_subframe_slot0,
-                0);
+    // 2- perform Channel Estimation for slot1
+    for (int l=1; l<ue->frame_parms.symbols_per_tti>>1; l++) {
+      if(l == pilot1) {
+        //wait until channel estimation for pilot0/slot1 is available
+        uint32_t wait = 0;
 
-        if ( (subframe_rx == 0) && (ue->decode_MIB == 1))
-        {
-            ue_pbch_procedures(0,ue,proc,0);
+        while(proc->chan_est_pilot0_slot1_available == 0) {
+          usleep(1);
+          wait++;
         }
 
-        proc->chan_est_slot1_available = 1;
-        //printf("Set available slot 1channelEst to 1 AbsSubframe %d.%d \n",frame_rx,subframe_rx);
-        //printf(" [slot1 dl processing] ==> FFT/CHanEst Done for AbsSubframe %d.%d \n", proc->frame_rx, proc->subframe_rx);
+        //printf("[slot1 dl processing] ChanEst symbol %d slot %d wait%d\n",l,slot1,wait);
+      }
 
-        //printf(" [slot1 dl processing] ==> Start LLR Comuptation slot1 for AbsSubframe %d.%d \n", proc->frame_rx, proc->subframe_rx);
+      //printf("AbsSubframe %d.%d ChanEst slot %d, symbol %d\n", frame_rx,subframe_rx,slot1,l);
+      front_end_chanEst(ue,
+                        l,
+                        slot1,
+                        0);
+      ue_measurement_procedures(l-1,ue,proc,0,1+(subframe_rx<<1),0,ue->mode);
+    }
+
+    //printf("AbsSubframe %d.%d ChanEst slot %d, symbol %d\n", frame_rx,subframe_rx,next_subframe_slot0,pilot0);
+    front_end_chanEst(ue,
+                      pilot0,
+                      next_subframe_slot0,
+                      0);
 
+    if ( (subframe_rx == 0) && (ue->decode_MIB == 1)) {
+      ue_pbch_procedures(0,ue,proc,0);
+    }
 
-        if ( LOG_DEBUGFLAG(UE_TIMING)) {
-          stop_meas(&ue->ue_front_end_per_slot_stat[ue->current_thread_id[subframe_rx]][1]);
-          LOG_UI(PHY, "[AbsSFN %d.%d] Slot1: FFT + Channel Estimate + Pdsch Proc Slot0 %5.2f \n",frame_rx,subframe_rx,ue->ue_front_end_per_slot_stat[ue->current_thread_id[subframe_rx]][1].p_time/(cpuf*1000.0));
-        }
+    proc->chan_est_slot1_available = 1;
+    //printf("Set available slot 1channelEst to 1 AbsSubframe %d.%d \n",frame_rx,subframe_rx);
+    //printf(" [slot1 dl processing] ==> FFT/CHanEst Done for AbsSubframe %d.%d \n", proc->frame_rx, proc->subframe_rx);
 
+    //printf(" [slot1 dl processing] ==> Start LLR Comuptation slot1 for AbsSubframe %d.%d \n", proc->frame_rx, proc->subframe_rx);
+
+    if ( LOG_DEBUGFLAG(UE_TIMING)) {
+      stop_meas(&ue->ue_front_end_per_slot_stat[ue->current_thread_id[subframe_rx]][1]);
+      LOG_I(PHY, "[AbsSFN %d.%d] Slot1: FFT + Channel Estimate + Pdsch Proc Slot0 %5.2f \n",frame_rx,subframe_rx,ue->ue_front_end_per_slot_stat[ue->current_thread_id[subframe_rx]][1].p_time/(cpuf*1000.0));
+    }
 
     //wait until pdcch is decoded
     uint32_t wait = 0;
-    while(proc->dci_slot0_available == 0)
-    {
-        usleep(1);
-        wait++;
+
+    while(proc->dci_slot0_available == 0) {
+      usleep(1);
+      wait++;
     }
-    //printf("[slot1 dl processing] AbsSubframe %d.%d LLR Computation Start wait DCI %d\n",frame_rx,subframe_rx,wait);
 
+    //printf("[slot1 dl processing] AbsSubframe %d.%d LLR Computation Start wait DCI %d\n",frame_rx,subframe_rx,wait);
 
     /**** Pdsch Procedure Slot1 ****/
     // start slot1 thread for Pdsch Procedure (slot1)
     // do procedures for C-RNTI
     //printf("AbsSubframe %d.%d Pdsch Procedure (slot1)\n",frame_rx,subframe_rx);
 
-
     if ( LOG_DEBUGFLAG(UE_TIMING)) {
       start_meas(&ue->pdsch_procedures_per_slot_stat[ue->current_thread_id[subframe_rx]][1]);
     }
+
     // start slave thread for Pdsch Procedure (slot1)
     // do procedures for C-RNTI
     uint8_t eNB_id = 0;
     uint8_t abstraction_flag = 0;
+
     if (ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->active == 1) {
-        //wait until first ofdm symbol is processed
-        //wait = 0;
-        //while(proc->first_symbol_available == 0)
-        //{
-        //    usleep(1);
-        //    wait++;
-        //}
-        //printf("[slot1 dl processing] AbsSubframe %d.%d LLR Computation Start wait First Ofdm Sym %d\n",frame_rx,subframe_rx,wait);
-
-        //VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC, VCD_FUNCTION_IN);
-        ue_pdsch_procedures(ue,
-                proc,
-                eNB_id,
-                PDSCH,
-                ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0],
-                NULL,
-                (ue->frame_parms.symbols_per_tti>>1),
-                ue->frame_parms.symbols_per_tti-1,
-                abstraction_flag);
-        LOG_D(PHY," ------ end PDSCH ChannelComp/LLR slot 0: AbsSubframe %d.%d ------  \n", frame_rx%1024, subframe_rx);
-        LOG_D(PHY," ------ --> PDSCH Turbo Decoder slot 0/1: AbsSubframe %d.%d ------  \n", frame_rx%1024, subframe_rx);
+      //wait until first ofdm symbol is processed
+      //wait = 0;
+      //while(proc->first_symbol_available == 0)
+      //{
+      //    usleep(1);
+      //    wait++;
+      //}
+      //printf("[slot1 dl processing] AbsSubframe %d.%d LLR Computation Start wait First Ofdm Sym %d\n",frame_rx,subframe_rx,wait);
+      //VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC, VCD_FUNCTION_IN);
+      ue_pdsch_procedures(ue,
+                          proc,
+                          eNB_id,
+                          PDSCH,
+                          ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0],
+                          NULL,
+                          (ue->frame_parms.symbols_per_tti>>1),
+                          ue->frame_parms.symbols_per_tti-1,
+                          abstraction_flag);
+      LOG_D(PHY," ------ end PDSCH ChannelComp/LLR slot 0: AbsSubframe %d.%d ------  \n", frame_rx%1024, subframe_rx);
+      LOG_D(PHY," ------ --> PDSCH Turbo Decoder slot 0/1: AbsSubframe %d.%d ------  \n", frame_rx%1024, subframe_rx);
     }
 
     // do procedures for SI-RNTI
     if ((ue->dlsch_SI[eNB_id]) && (ue->dlsch_SI[eNB_id]->active == 1)) {
-        ue_pdsch_procedures(ue,
-                proc,
-                eNB_id,
-                SI_PDSCH,
-                ue->dlsch_SI[eNB_id],
-                NULL,
-                (ue->frame_parms.symbols_per_tti>>1),
-                ue->frame_parms.symbols_per_tti-1,
-                abstraction_flag);
+      ue_pdsch_procedures(ue,
+                          proc,
+                          eNB_id,
+                          SI_PDSCH,
+                          ue->dlsch_SI[eNB_id],
+                          NULL,
+                          (ue->frame_parms.symbols_per_tti>>1),
+                          ue->frame_parms.symbols_per_tti-1,
+                          abstraction_flag);
     }
 
     // do procedures for P-RNTI
     if ((ue->dlsch_p[eNB_id]) && (ue->dlsch_p[eNB_id]->active == 1)) {
-        ue_pdsch_procedures(ue,
-                proc,
-                eNB_id,
-                P_PDSCH,
-                ue->dlsch_p[eNB_id],
-                NULL,
-                (ue->frame_parms.symbols_per_tti>>1),
-                ue->frame_parms.symbols_per_tti-1,
-                abstraction_flag);
+      ue_pdsch_procedures(ue,
+                          proc,
+                          eNB_id,
+                          P_PDSCH,
+                          ue->dlsch_p[eNB_id],
+                          NULL,
+                          (ue->frame_parms.symbols_per_tti>>1),
+                          ue->frame_parms.symbols_per_tti-1,
+                          abstraction_flag);
     }
+
     // do procedures for RA-RNTI
     if ((ue->dlsch_ra[eNB_id]) && (ue->dlsch_ra[eNB_id]->active == 1)) {
-        ue_pdsch_procedures(ue,
-                proc,
-                eNB_id,
-                RA_PDSCH,
-                ue->dlsch_ra[eNB_id],
-                NULL,
-                (ue->frame_parms.symbols_per_tti>>1),
-                ue->frame_parms.symbols_per_tti-1,
-                abstraction_flag);
+      ue_pdsch_procedures(ue,
+                          proc,
+                          eNB_id,
+                          RA_PDSCH,
+                          ue->dlsch_ra[eNB_id],
+                          NULL,
+                          (ue->frame_parms.symbols_per_tti>>1),
+                          ue->frame_parms.symbols_per_tti-1,
+                          abstraction_flag);
     }
 
     proc->llr_slot1_available=1;
@@ -4100,532 +3772,521 @@ void *UE_thread_slot1_dl_processing(void *arg) {
 
     if ( LOG_DEBUGFLAG(UE_TIMING)) {
       stop_meas(&ue->pdsch_procedures_per_slot_stat[ue->current_thread_id[subframe_rx]][1]);
-      LOG_UI(PHY, "[AbsSFN %d.%d] Slot1: LLR Computation %5.2f \n",frame_rx,subframe_rx,ue->pdsch_procedures_per_slot_stat[ue->current_thread_id[subframe_rx]][1].p_time/(cpuf*1000.0));
+      LOG_I(PHY, "[AbsSFN %d.%d] Slot1: LLR Computation %5.2f \n",frame_rx,subframe_rx,ue->pdsch_procedures_per_slot_stat[ue->current_thread_id[subframe_rx]][1].p_time/(cpuf*1000.0));
+    }
+
+    if (pthread_mutex_lock(&proc->mutex_slot1_dl_processing) != 0) {
+      LOG_E( PHY, "[SCHED][UE] error locking mutex for UE RXTX\n" );
+      exit_fun("noting to add");
     }
 
+    proc->instance_cnt_slot1_dl_processing--;
 
-        if (pthread_mutex_lock(&proc->mutex_slot1_dl_processing) != 0) {
-            LOG_E( PHY, "[SCHED][UE] error locking mutex for UE RXTX\n" );
-            exit_fun("noting to add");
-        }
-        proc->instance_cnt_slot1_dl_processing--;
-        if (pthread_mutex_unlock(&proc->mutex_slot1_dl_processing) != 0) {
-            LOG_E( PHY, "[SCHED][UE] error unlocking mutex for UE FEP Slo1\n" );
-            exit_fun("noting to add");
-        }
+    if (pthread_mutex_unlock(&proc->mutex_slot1_dl_processing) != 0) {
+      LOG_E( PHY, "[SCHED][UE] error unlocking mutex for UE FEP Slo1\n" );
+      exit_fun("noting to add");
     }
-    // thread finished
-        free(arg);
-        return &UE_dl_slot1_processing_retval;
+  }
+
+  // thread finished
+  free(arg);
+  return &UE_dl_slot1_processing_retval;
 }
 #endif
 
 #ifdef UE_SLOT_PARALLELISATION
 int phy_procedures_slot_parallelization_UE_RX(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,
-        uint8_t abstraction_flag,uint8_t do_pdcch_flag,runmode_t mode)  {
+    uint8_t abstraction_flag,uint8_t do_pdcch_flag,runmode_t mode)  {
+  int l,l2;
+  int pmch_flag=0;
+  int frame_rx = proc->frame_rx;
+  int subframe_rx = proc->subframe_rx;
+  uint8_t pilot0;
+  uint8_t pilot1;
+  uint8_t slot0;
+  uint8_t slot1;
+  uint8_t first_ofdm_sym;
+  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_RX, VCD_FUNCTION_IN);
+  T(T_UE_PHY_DL_TICK, T_INT(ue->Mod_id), T_INT(frame_rx%1024), T_INT(subframe_rx));
+  T(T_UE_PHY_INPUT_SIGNAL, T_INT(ue->Mod_id), T_INT(frame_rx%1024), T_INT(subframe_rx), T_INT(0),
+    T_BUFFER(&ue->common_vars.rxdata[0][subframe_rx*ue->frame_parms.samples_per_tti],
+             ue->frame_parms.samples_per_tti * 4));
 
-    int l,l2;
-    int pmch_flag=0;
-    int frame_rx = proc->frame_rx;
-    int subframe_rx = proc->subframe_rx;
-    uint8_t pilot0;
-    uint8_t pilot1;
-    uint8_t slot0;
-    uint8_t slot1;
-    uint8_t first_ofdm_sym;
+  // start timers
+  if (LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
+    LOG_D(PHY," ****** start RX-Chain for AbsSubframe %d.%d ******  \n", frame_rx%1024, subframe_rx);
+  }
 
-    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_RX, VCD_FUNCTION_IN);
+  if (LOG_DEBUGFLAG(UE_TIMING)) {
+    start_meas(&ue->phy_proc_rx[ue->current_thread_id[subframe_rx]]);
+    start_meas(&ue->ue_front_end_stat[ue->current_thread_id[subframe_rx]]);
+  }
 
+  pmch_flag = is_pmch_subframe(frame_rx,subframe_rx,&ue->frame_parms) ? 1 : 0;
 
-    T(T_UE_PHY_DL_TICK, T_INT(ue->Mod_id), T_INT(frame_rx%1024), T_INT(subframe_rx));
+  if (do_pdcch_flag) {
+    // deactivate reception until we scan pdcch
+    if (ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0])
+      ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->active = 0;
 
-    T(T_UE_PHY_INPUT_SIGNAL, T_INT(ue->Mod_id), T_INT(frame_rx%1024), T_INT(subframe_rx), T_INT(0),
-            T_BUFFER(&ue->common_vars.rxdata[0][subframe_rx*ue->frame_parms.samples_per_tti],
-                    ue->frame_parms.samples_per_tti * 4));
+    if (ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][1])
+      ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][1]->active = 0;
 
+    if (ue->dlsch_SI[eNB_id])
+      ue->dlsch_SI[eNB_id]->active = 0;
 
-    // start timers
-    if (LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
-      LOG_D(PHY," ****** start RX-Chain for AbsSubframe %d.%d ******  \n", frame_rx%1024, subframe_rx);
-    }
+    if (ue->dlsch_p[eNB_id])
+      ue->dlsch_p[eNB_id]->active = 0;
 
-    if (LOG_DEBUGFLAG(UE_TIMING)) {
-      start_meas(&ue->phy_proc_rx[ue->current_thread_id[subframe_rx]]);
-      start_meas(&ue->ue_front_end_stat[ue->current_thread_id[subframe_rx]]);
-    }
+    if (ue->dlsch_ra[eNB_id])
+      ue->dlsch_ra[eNB_id]->active = 0;
+  }
 
-    pmch_flag = is_pmch_subframe(frame_rx,subframe_rx,&ue->frame_parms) ? 1 : 0;
+  if ( LOG_DEBUG_FLAG(DEBUG_UE_PHYPROC)) {
+    LOG_D(PHY,"[UE %d] Frame %d subframe %d: Doing phy_procedures_UE_RX\n",
+          ue->Mod_id,frame_rx, subframe_rx);
+  }
 
-    if (do_pdcch_flag) {
-        // deactivate reception until we scan pdcch
-        if (ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0])
-            ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->active = 0;
-        if (ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][1])
-            ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][1]->active = 0;
-
-        if (ue->dlsch_SI[eNB_id])
-            ue->dlsch_SI[eNB_id]->active = 0;
-        if (ue->dlsch_p[eNB_id])
-            ue->dlsch_p[eNB_id]->active = 0;
-        if (ue->dlsch_ra[eNB_id])
-            ue->dlsch_ra[eNB_id]->active = 0;
-    }
+  if (subframe_select(&ue->frame_parms,subframe_rx) == SF_S) { // S-subframe, do first 5 symbols only
+    l2 = 4;
+  } else if (pmch_flag == 1) { // do first 2 symbols only
+    l2 = 1;
+  } else { // normal subframe, last symbol to be processed is the first of the second slot
+    l2 = (ue->frame_parms.symbols_per_tti/2)-1;
+  }
 
-    if ( LOG_DEBUG_FLAG(DEBUG_UE_PHYPROC)) {
-      LOG_D(PHY,"[UE %d] Frame %d subframe %d: Doing phy_procedures_UE_RX\n",
-                      ue->Mod_id,frame_rx, subframe_rx);
-    }
+  int prev_subframe_rx = (subframe_rx - 1)<0? 9: (subframe_rx - 1);
 
+  if (subframe_select(&ue->frame_parms,prev_subframe_rx) != SF_DL) {
+    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+    // RX processing of symbols l=0...l2
+    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+    first_ofdm_sym = 0;
+  } else {
+    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+    // RX processing of symbols l=1...l2 (l=0 is done in last scheduling epoch)
+    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+    first_ofdm_sym = 1;
+  }
 
+  slot0  = (subframe_rx<<1);
+  slot1  = (subframe_rx<<1) + 1;
+  pilot0 = 0;
 
+  if (ue->frame_parms.Ncp == 0) {  // normal prefix
+    pilot1 = 4;
+  } else { // extended prefix
+    pilot1 = 3;
+  }
 
-    if (subframe_select(&ue->frame_parms,subframe_rx) == SF_S) { // S-subframe, do first 5 symbols only
-        l2 = 4;
-    } else if (pmch_flag == 1) { // do first 2 symbols only
-        l2 = 1;
-    } else { // normal subframe, last symbol to be processed is the first of the second slot
-        l2 = (ue->frame_parms.symbols_per_tti/2)-1;
-    }
+  //LOG_I(PHY,"Set available channelEst to 0 AbsSubframe %d.%d \n",frame_rx,subframe_rx);
+  //LOG_I(PHY,"Set available llrs slot1 to 0 AbsSubframe %d.%d \n",frame_rx,subframe_rx);
+  //LOG_I(PHY,"Set available dci info slot0 to 0 AbsSubframe %d.%d \n",frame_rx,subframe_rx);
+  proc->chan_est_pilot0_slot1_available=0;
+  proc->llr_slot1_available=0;
+  proc->dci_slot0_available=0;
+  proc->first_symbol_available=0;
+  proc->chan_est_slot1_available=0;
+  //proc->channel_level=0;
+
+  if (pthread_mutex_lock(&proc->mutex_slot1_dl_processing) != 0) {
+    LOG_E( PHY, "[SCHED][UE %d][Slot0] error locking mutex for UE slot1 dl processing\n",ue->Mod_id );
+    exit_fun("nothing to add");
+  }
 
-    int prev_subframe_rx = (subframe_rx - 1)<0? 9: (subframe_rx - 1);
-    if (subframe_select(&ue->frame_parms,prev_subframe_rx) != SF_DL) {
-        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-        // RX processing of symbols l=0...l2
-        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-        first_ofdm_sym = 0;
-    } else {
-        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-        // RX processing of symbols l=1...l2 (l=0 is done in last scheduling epoch)
-        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-        first_ofdm_sym = 1;
-    }
-    slot0  = (subframe_rx<<1);
-    slot1  = (subframe_rx<<1) + 1;
-    pilot0 = 0;
-    if (ue->frame_parms.Ncp == 0) {  // normal prefix
-        pilot1 = 4;
-    } else { // extended prefix
-        pilot1 = 3;
-    }
+  proc->instance_cnt_slot1_dl_processing++;
 
-    //LOG_I(PHY,"Set available channelEst to 0 AbsSubframe %d.%d \n",frame_rx,subframe_rx);
-    //LOG_I(PHY,"Set available llrs slot1 to 0 AbsSubframe %d.%d \n",frame_rx,subframe_rx);
-    //LOG_I(PHY,"Set available dci info slot0 to 0 AbsSubframe %d.%d \n",frame_rx,subframe_rx);
-    proc->chan_est_pilot0_slot1_available=0;
-    proc->llr_slot1_available=0;
-    proc->dci_slot0_available=0;
-    proc->first_symbol_available=0;
-    proc->chan_est_slot1_available=0;
-    //proc->channel_level=0;
+  if (proc->instance_cnt_slot1_dl_processing == 0) {
+    LOG_D(PHY,"unblock slot1 dl processing thread blocked on instance_cnt_slot1_dl_processing : %d \n", proc->instance_cnt_slot1_dl_processing );
 
-    if (pthread_mutex_lock(&proc->mutex_slot1_dl_processing) != 0) {
-        LOG_E( PHY, "[SCHED][UE %d][Slot0] error locking mutex for UE slot1 dl processing\n",ue->Mod_id );
-        exit_fun("nothing to add");
+    if (pthread_cond_signal(&proc->cond_slot1_dl_processing) != 0) {
+      LOG_E( PHY, "[SCHED][UE %d][Slot0] ERROR pthread_cond_signal for UE slot1 processing thread\n", ue->Mod_id);
+      exit_fun("nothing to add");
     }
 
-    proc->instance_cnt_slot1_dl_processing++;
-    if (proc->instance_cnt_slot1_dl_processing == 0)
-    {
-    LOG_D(PHY,"unblock slot1 dl processing thread blocked on instance_cnt_slot1_dl_processing : %d \n", proc->instance_cnt_slot1_dl_processing );
-        if (pthread_cond_signal(&proc->cond_slot1_dl_processing) != 0) {
-            LOG_E( PHY, "[SCHED][UE %d][Slot0] ERROR pthread_cond_signal for UE slot1 processing thread\n", ue->Mod_id);
-            exit_fun("nothing to add");
-        }
-        if (pthread_mutex_unlock(&proc->mutex_slot1_dl_processing) != 0) {
-            LOG_E( PHY, "[SCHED][UE %d][Slot0] error unlocking mutex for UE slot1 dl processing \n",ue->Mod_id );
-            exit_fun("nothing to add");
-        }
-
-    } else
-    {
-        LOG_E( PHY, "[SCHED][UE %d] UE RX thread busy (IC %d)!!\n", ue->Mod_id, proc->instance_cnt_slot1_dl_processing);
-        if (proc->instance_cnt_slot1_dl_processing > 2)
-            exit_fun("instance_cnt_slot1_dl_processing > 2");
+    if (pthread_mutex_unlock(&proc->mutex_slot1_dl_processing) != 0) {
+      LOG_E( PHY, "[SCHED][UE %d][Slot0] error unlocking mutex for UE slot1 dl processing \n",ue->Mod_id );
+      exit_fun("nothing to add");
     }
-    //AssertFatal(pthread_cond_signal(&proc->cond_slot1_dl_processing) ==0 ,"");
-    AssertFatal(pthread_mutex_unlock(&proc->mutex_slot1_dl_processing) ==0,"");
+  } else {
+    LOG_E( PHY, "[SCHED][UE %d] UE RX thread busy (IC %d)!!\n", ue->Mod_id, proc->instance_cnt_slot1_dl_processing);
 
+    if (proc->instance_cnt_slot1_dl_processing > 2)
+      exit_fun("instance_cnt_slot1_dl_processing > 2");
+  }
 
-    /**** Slot0 FE Processing ****/
-    // I- start main thread for FFT/ChanEst symbol: 0/1 --> 7
-    if ( LOG_DEBUGFLAG(UE_TIMING)) {
-      start_meas(&ue->ue_front_end_per_slot_stat[ue->current_thread_id[subframe_rx]][0]);
-    }
-    // 1- perform FFT for pilot ofdm symbols first (ofdmSym7 ofdmSym4 or (ofdmSym6 ofdmSym3))
-    //printf("AbsSubframe %d.%d FFT slot %d, symbol %d\n", frame_rx,subframe_rx,slot1,pilot0);
-    front_end_fft(ue,
-            pilot0,
-            slot1,
-            0,
-            0);
-    //printf("AbsSubframe %d.%d FFT slot %d, symbol %d\n", frame_rx,subframe_rx,slot0,pilot1);
-    front_end_fft(ue,
-            pilot1,
-            slot0,
-            0,
-            0);
-    //printf("AbsSubframe %d.%d ChanEst slot %d, symbol %d\n", frame_rx,subframe_rx,slot0,pilot1);
-    front_end_chanEst(ue,
-            pilot1,
-            slot0,
-            0);
-    //printf("AbsSubframe %d.%d ChanEst slot %d, symbol %d\n", frame_rx,subframe_rx,slot1,pilot0);
-    front_end_chanEst(ue,
-            pilot0,
-            slot1,
-            0);
-    proc->chan_est_pilot0_slot1_available = 1;
-    //printf("Set available channelEst to 1 AbsSubframe %d.%d \n",frame_rx,subframe_rx);
+  //AssertFatal(pthread_cond_signal(&proc->cond_slot1_dl_processing) ==0 ,"");
+  AssertFatal(pthread_mutex_unlock(&proc->mutex_slot1_dl_processing) ==0,"");
 
-    // 2- perform FFT for other ofdm symbols other than pilots
-    for (l=first_ofdm_sym; l<=l2; l++)
-    {
-        if( (l != pilot0) && (l != pilot1))
-        {
-            //printf("AbsSubframe %d.%d FFT slot %d, symbol %d\n", frame_rx,subframe_rx,slot0,l);
-            if (LOG_DEBUGFLAG(UE_TIMING)) {
-              start_meas(&ue->ofdm_demod_stats);
-            }
-            VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP, VCD_FUNCTION_IN);
-            front_end_fft(ue,
-                    l,
+  /**** Slot0 FE Processing ****/
+  // I- start main thread for FFT/ChanEst symbol: 0/1 --> 7
+  if ( LOG_DEBUGFLAG(UE_TIMING)) {
+    start_meas(&ue->ue_front_end_per_slot_stat[ue->current_thread_id[subframe_rx]][0]);
+  }
+
+  // 1- perform FFT for pilot ofdm symbols first (ofdmSym7 ofdmSym4 or (ofdmSym6 ofdmSym3))
+  //printf("AbsSubframe %d.%d FFT slot %d, symbol %d\n", frame_rx,subframe_rx,slot1,pilot0);
+  front_end_fft(ue,
+                pilot0,
+                slot1,
+                0,
+                0);
+  //printf("AbsSubframe %d.%d FFT slot %d, symbol %d\n", frame_rx,subframe_rx,slot0,pilot1);
+  front_end_fft(ue,
+                pilot1,
+                slot0,
+                0,
+                0);
+  //printf("AbsSubframe %d.%d ChanEst slot %d, symbol %d\n", frame_rx,subframe_rx,slot0,pilot1);
+  front_end_chanEst(ue,
+                    pilot1,
                     slot0,
-                    0,
                     0);
-            VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP, VCD_FUNCTION_OUT);
-            if (LOG_DEBUGFLAG(UE_TIMING)) {
-              stop_meas(&ue->ofdm_demod_stats);
-            }
-        }
-    } // for l=1..l2
+  //printf("AbsSubframe %d.%d ChanEst slot %d, symbol %d\n", frame_rx,subframe_rx,slot1,pilot0);
+  front_end_chanEst(ue,
+                    pilot0,
+                    slot1,
+                    0);
+  proc->chan_est_pilot0_slot1_available = 1;
+  //printf("Set available channelEst to 1 AbsSubframe %d.%d \n",frame_rx,subframe_rx);
 
-    // 3- perform Channel Estimation for slot0
-    for (l=first_ofdm_sym; l<=l2; l++)
-    {
-        if( (l != pilot0) && (l != pilot1))
-        {
-            //printf("AbsSubframe %d.%d ChanEst slot %d, symbol %d\n", frame_rx,subframe_rx,slot0,l);
-            front_end_chanEst(ue,
+  // 2- perform FFT for other ofdm symbols other than pilots
+  for (l=first_ofdm_sym; l<=l2; l++) {
+    if( (l != pilot0) && (l != pilot1)) {
+      //printf("AbsSubframe %d.%d FFT slot %d, symbol %d\n", frame_rx,subframe_rx,slot0,l);
+      if (LOG_DEBUGFLAG(UE_TIMING)) {
+        start_meas(&ue->ofdm_demod_stats);
+      }
+
+      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP, VCD_FUNCTION_IN);
+      front_end_fft(ue,
                     l,
                     slot0,
+                    0,
                     0);
-        }
-        ue_measurement_procedures(l-1,ue,proc,eNB_id,(subframe_rx<<1),abstraction_flag,mode);
-    }
+      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP, VCD_FUNCTION_OUT);
 
-    if (do_pdcch_flag) {
-        if (LOG_DEBUGFLAG(UE_TIMING)) {
-          start_meas(&ue->pdcch_procedures_stat[ue->current_thread_id[subframe_rx]]);
-        }
-        if (ue_pdcch_procedures(eNB_id,ue,proc,abstraction_flag) == -1) {
-            LOG_E(PHY,"[UE  %d] Frame %d, subframe %d: Error in pdcch procedures\n",ue->Mod_id,frame_rx,subframe_rx);
-          if (LOG_DEBUGFLAG(UE_TIMING)) {
-            LOG_UI(PHY, "[AbsSFN %d.%d] Slot0: PDCCH %5.2f \n",frame_rx,subframe_rx,ue->pdcch_procedures_stat[ue->current_thread_id[subframe_rx]].p_time/(cpuf*1000.0));
-        }
+      if (LOG_DEBUGFLAG(UE_TIMING)) {
+        stop_meas(&ue->ofdm_demod_stats);
+      }
+    }
+  } // for l=1..l2
 
-            //proc->dci_slot0_available = 1;
-            return(-1);
-        }
-        //proc->dci_slot0_available=1;
-        if (LOG_DEBUGFLAG(UE_TIMING)) {
-          stop_meas(&ue->pdcch_procedures_stat[ue->current_thread_id[subframe_rx]]);
-          LOG_UI(PHY, "[AbsSFN %d.%d] Slot0: PDCCH %5.2f \n",frame_rx,subframe_rx,ue->pdcch_procedures_stat[ue->current_thread_id[subframe_rx]].p_time/(cpuf*1000.0));
-        }
+  // 3- perform Channel Estimation for slot0
+  for (l=first_ofdm_sym; l<=l2; l++) {
+    if( (l != pilot0) && (l != pilot1)) {
+      //printf("AbsSubframe %d.%d ChanEst slot %d, symbol %d\n", frame_rx,subframe_rx,slot0,l);
+      front_end_chanEst(ue,
+                        l,
+                        slot0,
+                        0);
     }
 
-    //printf("num_pdcch_symbols %d\n",ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols);
+    ue_measurement_procedures(l-1,ue,proc,eNB_id,(subframe_rx<<1),abstraction_flag,mode);
+  }
 
-    // first slot has been processed (FFTs + Channel Estimation, PCFICH/PHICH/PDCCH)
+  if (do_pdcch_flag) {
     if (LOG_DEBUGFLAG(UE_TIMING)) {
-      stop_meas(&ue->ue_front_end_per_slot_stat[ue->current_thread_id[subframe_rx]][0]);
-      LOG_UI(PHY, "[AbsSFN %d.%d] Slot0: FFT + Channel Estimate + PCFICH/PHICH/PDCCH %5.2f \n",frame_rx,subframe_rx,ue->ue_front_end_per_slot_stat[ue->current_thread_id[subframe_rx]][0].p_time/(cpuf*1000.0));
+      start_meas(&ue->pdcch_procedures_stat[ue->current_thread_id[subframe_rx]]);
     }
 
-    //wait until slot1 FE is done
-    uint32_t wait = 0;
-    while(proc->chan_est_slot1_available == 0)
-    {
-        usleep(1);
-        wait++;
+    if (ue_pdcch_procedures(eNB_id,ue,proc,abstraction_flag) == -1) {
+      LOG_E(PHY,"[UE  %d] Frame %d, subframe %d: Error in pdcch procedures\n",ue->Mod_id,frame_rx,subframe_rx);
+
+      if (LOG_DEBUGFLAG(UE_TIMING)) {
+        LOG_I(PHY, "[AbsSFN %d.%d] Slot0: PDCCH %5.2f \n",frame_rx,subframe_rx,ue->pdcch_procedures_stat[ue->current_thread_id[subframe_rx]].p_time/(cpuf*1000.0));
+      }
+
+      //proc->dci_slot0_available = 1;
+      return(-1);
     }
 
+    //proc->dci_slot0_available=1;
     if (LOG_DEBUGFLAG(UE_TIMING)) {
-      stop_meas(&ue->ue_front_end_stat[ue->current_thread_id[subframe_rx]]);
-      LOG_UI(PHY, "[AbsSFN %d.%d] FULL FE Processing %5.2f \n",frame_rx,subframe_rx,ue->ue_front_end_per_slot_stat[ue->current_thread_id[subframe_rx]][0].p_time/(cpuf*1000.0));
+      stop_meas(&ue->pdcch_procedures_stat[ue->current_thread_id[subframe_rx]]);
+      LOG_I(PHY, "[AbsSFN %d.%d] Slot0: PDCCH %5.2f \n",frame_rx,subframe_rx,ue->pdcch_procedures_stat[ue->current_thread_id[subframe_rx]].p_time/(cpuf*1000.0));
     }
-    /**** End Subframe FE Processing ****/
+  }
 
+  //printf("num_pdcch_symbols %d\n",ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols);
 
-    //Trigger LLR parallelized for Slot 1
-    //proc->dci_slot0_available=1;
-    //printf("Set available dci slot0 to 1 AbsSubframe %d.%d \n",frame_rx%1024,subframe_rx);
+  // first slot has been processed (FFTs + Channel Estimation, PCFICH/PHICH/PDCCH)
+  if (LOG_DEBUGFLAG(UE_TIMING)) {
+    stop_meas(&ue->ue_front_end_per_slot_stat[ue->current_thread_id[subframe_rx]][0]);
+    LOG_I(PHY, "[AbsSFN %d.%d] Slot0: FFT + Channel Estimate + PCFICH/PHICH/PDCCH %5.2f \n",frame_rx,subframe_rx,
+          ue->ue_front_end_per_slot_stat[ue->current_thread_id[subframe_rx]][0].p_time/(cpuf*1000.0));
+  }
 
-    /**** Pdsch Procedure Slot0 ****/
-    // start main thread for Pdsch Procedure (slot0)
-    // do procedures for C-RNTI
-    //printf("AbsSubframe %d.%d Pdsch Procedure (slot0)\n",frame_rx%1024,subframe_rx);
-    //printf("AbsSubframe %d.%d Pdsch Procedure PDSCH Active %d \n",frame_rx%1024,subframe_rx, ue->dlsch[ue->current_thread_id[subframe_rx]][0][0]->active);
+  //wait until slot1 FE is done
+  uint32_t wait = 0;
 
-    if (LOG_DEBUGFLAG(UE_TIMING)) {
-      start_meas(&ue->pdsch_procedures_stat[ue->current_thread_id[subframe_rx]]);
-    }
+  while(proc->chan_est_slot1_available == 0) {
+    usleep(1);
+    wait++;
+  }
 
-    if (LOG_DEBUGFLAG(UE_TIMING)) {
-      start_meas(&ue->pdsch_procedures_per_slot_stat[ue->current_thread_id[subframe_rx]][0]);
-    }
-    if (ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->active == 1) {
-        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC, VCD_FUNCTION_IN);
-        ue_pdsch_procedures(ue,
-                proc,
-                eNB_id,
-                PDSCH,
-                ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0],
-                NULL,
-                ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols,
-                (ue->frame_parms.symbols_per_tti>>1)-1,
-                abstraction_flag);
-
-        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC, VCD_FUNCTION_OUT);
-    }
+  if (LOG_DEBUGFLAG(UE_TIMING)) {
+    stop_meas(&ue->ue_front_end_stat[ue->current_thread_id[subframe_rx]]);
+    LOG_I(PHY, "[AbsSFN %d.%d] FULL FE Processing %5.2f \n",frame_rx,subframe_rx,ue->ue_front_end_per_slot_stat[ue->current_thread_id[subframe_rx]][0].p_time/(cpuf*1000.0));
+  }
 
-    // do procedures for SI-RNTI
-    if ((ue->dlsch_SI[eNB_id]) && (ue->dlsch_SI[eNB_id]->active == 1)) {
-        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC_SI, VCD_FUNCTION_IN);
-        ue_pdsch_procedures(ue,
-                proc,
-                eNB_id,
-                SI_PDSCH,
-                ue->dlsch_SI[eNB_id],
-                NULL,
-                ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols,
-                (ue->frame_parms.symbols_per_tti>>1)-1,
-                abstraction_flag);
-        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC_SI, VCD_FUNCTION_OUT);
-    }
+  /**** End Subframe FE Processing ****/
 
-    // do procedures for SI-RNTI
-    if ((ue->dlsch_p[eNB_id]) && (ue->dlsch_p[eNB_id]->active == 1)) {
-        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC_P, VCD_FUNCTION_IN);
-        ue_pdsch_procedures(ue,
-                proc,
-                eNB_id,
-                P_PDSCH,
-                ue->dlsch_p[eNB_id],
-                NULL,
-                ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols,
-                (ue->frame_parms.symbols_per_tti>>1)-1,
-                abstraction_flag);
-        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC_P, VCD_FUNCTION_OUT);
-    }
+  //Trigger LLR parallelized for Slot 1
+  //proc->dci_slot0_available=1;
+  //printf("Set available dci slot0 to 1 AbsSubframe %d.%d \n",frame_rx%1024,subframe_rx);
 
-    // do procedures for RA-RNTI
-    if ((ue->dlsch_ra[eNB_id]) && (ue->dlsch_ra[eNB_id]->active == 1)) {
-        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC_RA, VCD_FUNCTION_IN);
-        ue_pdsch_procedures(ue,
-                proc,
-                eNB_id,
-                RA_PDSCH,
-                ue->dlsch_ra[eNB_id],
-                NULL,
-                ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols,
-                (ue->frame_parms.symbols_per_tti>>1)-1,
-                abstraction_flag);
-        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC_RA, VCD_FUNCTION_OUT);
-    }
+  /**** Pdsch Procedure Slot0 ****/
+  // start main thread for Pdsch Procedure (slot0)
+  // do procedures for C-RNTI
+  //printf("AbsSubframe %d.%d Pdsch Procedure (slot0)\n",frame_rx%1024,subframe_rx);
+  //printf("AbsSubframe %d.%d Pdsch Procedure PDSCH Active %d \n",frame_rx%1024,subframe_rx, ue->dlsch[ue->current_thread_id[subframe_rx]][0][0]->active);
 
-    // LLR linear
-    proc->dci_slot0_available=1;
-    //printf("Set available dci slot0 to 1 AbsSubframe %d.%d \n",frame_rx%1024,subframe_rx);
+  if (LOG_DEBUGFLAG(UE_TIMING)) {
+    start_meas(&ue->pdsch_procedures_stat[ue->current_thread_id[subframe_rx]]);
+  }
 
+  if (LOG_DEBUGFLAG(UE_TIMING)) {
+    start_meas(&ue->pdsch_procedures_per_slot_stat[ue->current_thread_id[subframe_rx]][0]);
+  }
 
-    if (LOG_DEBUGFLAG(UE_TIMING)){
-      stop_meas(&ue->pdsch_procedures_per_slot_stat[ue->current_thread_id[subframe_rx]][0]);
-      LOG_UI(PHY, "[AbsSFN %d.%d] Slot0: LLR Computation %5.2f \n",frame_rx,subframe_rx,ue->pdsch_procedures_per_slot_stat[ue->current_thread_id[subframe_rx]][0].p_time/(cpuf*1000.0));
-    }
+  if (ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->active == 1) {
+    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC, VCD_FUNCTION_IN);
+    ue_pdsch_procedures(ue,
+                        proc,
+                        eNB_id,
+                        PDSCH,
+                        ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0],
+                        NULL,
+                        ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols,
+                        (ue->frame_parms.symbols_per_tti>>1)-1,
+                        abstraction_flag);
+    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC, VCD_FUNCTION_OUT);
+  }
 
+  // do procedures for SI-RNTI
+  if ((ue->dlsch_SI[eNB_id]) && (ue->dlsch_SI[eNB_id]->active == 1)) {
+    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC_SI, VCD_FUNCTION_IN);
+    ue_pdsch_procedures(ue,
+                        proc,
+                        eNB_id,
+                        SI_PDSCH,
+                        ue->dlsch_SI[eNB_id],
+                        NULL,
+                        ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols,
+                        (ue->frame_parms.symbols_per_tti>>1)-1,
+                        abstraction_flag);
+    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC_SI, VCD_FUNCTION_OUT);
+  }
 
-    //wait until LLR Slot1 is done
-    wait = 0;
-    while(proc->llr_slot1_available == 0)
-    {
-        usleep(1);
-        wait++;
-    }
+  // do procedures for SI-RNTI
+  if ((ue->dlsch_p[eNB_id]) && (ue->dlsch_p[eNB_id]->active == 1)) {
+    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC_P, VCD_FUNCTION_IN);
+    ue_pdsch_procedures(ue,
+                        proc,
+                        eNB_id,
+                        P_PDSCH,
+                        ue->dlsch_p[eNB_id],
+                        NULL,
+                        ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols,
+                        (ue->frame_parms.symbols_per_tti>>1)-1,
+                        abstraction_flag);
+    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC_P, VCD_FUNCTION_OUT);
+  }
 
+  // do procedures for RA-RNTI
+  if ((ue->dlsch_ra[eNB_id]) && (ue->dlsch_ra[eNB_id]->active == 1)) {
+    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC_RA, VCD_FUNCTION_IN);
+    ue_pdsch_procedures(ue,
+                        proc,
+                        eNB_id,
+                        RA_PDSCH,
+                        ue->dlsch_ra[eNB_id],
+                        NULL,
+                        ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols,
+                        (ue->frame_parms.symbols_per_tti>>1)-1,
+                        abstraction_flag);
+    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC_RA, VCD_FUNCTION_OUT);
+  }
 
+  // LLR linear
+  proc->dci_slot0_available=1;
+  //printf("Set available dci slot0 to 1 AbsSubframe %d.%d \n",frame_rx%1024,subframe_rx);
 
-    if (LOG_DEBUGFLAG(UE_TIMING)){
-      stop_meas(&ue->pdsch_procedures_stat[ue->current_thread_id[subframe_rx]]);
-      LOG_UI(PHY, "[AbsSFN %d.%d] Full LLR Computation %5.2f \n",frame_rx,subframe_rx,ue->pdsch_procedures_stat[ue->current_thread_id[subframe_rx]].p_time/(cpuf*1000.0));
-    }
+  if (LOG_DEBUGFLAG(UE_TIMING)) {
+    stop_meas(&ue->pdsch_procedures_per_slot_stat[ue->current_thread_id[subframe_rx]][0]);
+    LOG_I(PHY, "[AbsSFN %d.%d] Slot0: LLR Computation %5.2f \n",frame_rx,subframe_rx,ue->pdsch_procedures_per_slot_stat[ue->current_thread_id[subframe_rx]][0].p_time/(cpuf*1000.0));
+  }
 
+  //wait until LLR Slot1 is done
+  wait = 0;
 
-    //=====================================================================//
-    if (LOG_DEBUGFLAG(UE_TIMING)){
-      start_meas(&ue->dlsch_procedures_stat[ue->current_thread_id[subframe_rx]]);
-    }
+  while(proc->llr_slot1_available == 0) {
+    usleep(1);
+    wait++;
+  }
 
-    LOG_D(PHY,"==> Start Turbo Decoder active dlsch %d SI %d RA %d \n",ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->active,
-    		ue->dlsch_SI[eNB_id]->active,
-			//ue->dlsch_p[eNB_id]->active,
-			ue->dlsch_ra[eNB_id]->active);
-    // Start Turbo decoder
-    if (ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->active == 1) {
-        //VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC, VCD_FUNCTION_IN);
-        ue_dlsch_procedures(ue,
-                proc,
-                eNB_id,
-                PDSCH,
-                ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0],
-                ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][1],
-                &ue->dlsch_errors[eNB_id],
-                mode,
-                abstraction_flag);
-        //VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC, VCD_FUNCTION_OUT);
-    }
+  if (LOG_DEBUGFLAG(UE_TIMING)) {
+    stop_meas(&ue->pdsch_procedures_stat[ue->current_thread_id[subframe_rx]]);
+    LOG_I(PHY, "[AbsSFN %d.%d] Full LLR Computation %5.2f \n",frame_rx,subframe_rx,ue->pdsch_procedures_stat[ue->current_thread_id[subframe_rx]].p_time/(cpuf*1000.0));
+  }
 
-    // do procedures for SI-RNTI
-    if ((ue->dlsch_SI[eNB_id]) && (ue->dlsch_SI[eNB_id]->active == 1)) {
-        ue_dlsch_procedures(ue,
-                proc,
-                eNB_id,
-                SI_PDSCH,
-                ue->dlsch_SI[eNB_id],
-                NULL,
-                &ue->dlsch_SI_errors[eNB_id],
-                mode,
-                abstraction_flag);
-        ue->dlsch_SI[eNB_id]->active = 0;
-    }
+  //=====================================================================//
+  if (LOG_DEBUGFLAG(UE_TIMING)) {
+    start_meas(&ue->dlsch_procedures_stat[ue->current_thread_id[subframe_rx]]);
+  }
 
-    // do procedures for P-RNTI
-    if ((ue->dlsch_p[eNB_id]) && (ue->dlsch_p[eNB_id]->active == 1)) {
-        ue_dlsch_procedures(ue,
-                proc,
-                eNB_id,
-                P_PDSCH,
-                ue->dlsch_p[eNB_id],
-                NULL,
-                &ue->dlsch_p_errors[eNB_id],
-                mode,
-                abstraction_flag);
-        ue->dlsch_p[eNB_id]->active = 0;
-    }
-    // do procedures for RA-RNTI
-    if ((ue->dlsch_ra[eNB_id]) && (ue->dlsch_ra[eNB_id]->active == 1)) {
-        ue_dlsch_procedures(ue,
-                proc,
-                eNB_id,
-                RA_PDSCH,
-                ue->dlsch_ra[eNB_id],
-                NULL,
-                &ue->dlsch_ra_errors[eNB_id],
-                mode,
-                abstraction_flag);
-        ue->dlsch_ra[eNB_id]->active = 0;
-    }
+  LOG_D(PHY,"==> Start Turbo Decoder active dlsch %d SI %d RA %d \n",ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->active,
+        ue->dlsch_SI[eNB_id]->active,
+        //ue->dlsch_p[eNB_id]->active,
+        ue->dlsch_ra[eNB_id]->active);
 
-    if (LOG_DEBUGFLAG(UE_TIMING)
-      stop_meas(&ue->dlsch_procedures_stat[ue->current_thread_id[subframe_rx]]);
-      LOG_UI(PHY, "[AbsSFN %d.%d] Channel Decoder: %5.2f \n",frame_rx,subframe_rx,ue->dlsch_procedures_stat[ue->current_thread_id[subframe_rx]].p_time/(cpuf*1000.0));
-    }
+  // Start Turbo decoder
+  if (ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->active == 1) {
+    //VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC, VCD_FUNCTION_IN);
+    ue_dlsch_procedures(ue,
+                        proc,
+                        eNB_id,
+                        PDSCH,
+                        ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0],
+                        ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][1],
+                        &ue->dlsch_errors[eNB_id],
+                        mode,
+                        abstraction_flag);
+    //VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC, VCD_FUNCTION_OUT);
+  }
 
-        // duplicate harq structure
-        uint8_t          current_harq_pid        = ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->current_harq_pid;
-        LTE_DL_UE_HARQ_t *current_harq_processes = ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->harq_processes[current_harq_pid];
-        harq_status_t    *current_harq_ack       = &ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->harq_ack[subframe_rx];
+  // do procedures for SI-RNTI
+  if ((ue->dlsch_SI[eNB_id]) && (ue->dlsch_SI[eNB_id]->active == 1)) {
+    ue_dlsch_procedures(ue,
+                        proc,
+                        eNB_id,
+                        SI_PDSCH,
+                        ue->dlsch_SI[eNB_id],
+                        NULL,
+                        &ue->dlsch_SI_errors[eNB_id],
+                        mode,
+                        abstraction_flag);
+    ue->dlsch_SI[eNB_id]->active = 0;
+  }
 
-        // For Debug parallelisation
-        //if (current_harq_ack->ack == 0) {
-            //printf("[slot0 dl processing][End of Channel Decoding] AbsSubframe %d.%d Decode Fail for HarqId%d Round%d\n",frame_rx,subframe_rx,current_harq_pid,current_harq_processes->round);
-        //}
-        for(uint8_t rx_th_idx=1; rx_th_idx<RX_NB_TH; rx_th_idx++)
-        {
-            LTE_DL_UE_HARQ_t *harq_processes_dest  = ue->dlsch[ue->current_thread_id[(subframe_rx+rx_th_idx)%10]][eNB_id][0]->harq_processes[current_harq_pid];
-            harq_status_t    *harq_ack_dest        = &ue->dlsch[ue->current_thread_id[(subframe_rx+rx_th_idx)%10]][eNB_id][0]->harq_ack[subframe_rx];
+  // do procedures for P-RNTI
+  if ((ue->dlsch_p[eNB_id]) && (ue->dlsch_p[eNB_id]->active == 1)) {
+    ue_dlsch_procedures(ue,
+                        proc,
+                        eNB_id,
+                        P_PDSCH,
+                        ue->dlsch_p[eNB_id],
+                        NULL,
+                        &ue->dlsch_p_errors[eNB_id],
+                        mode,
+                        abstraction_flag);
+    ue->dlsch_p[eNB_id]->active = 0;
+  }
 
-            copy_harq_proc_struct(harq_processes_dest, current_harq_processes);
-            copy_ack_struct(harq_ack_dest, current_harq_ack);
+  // do procedures for RA-RNTI
+  if ((ue->dlsch_ra[eNB_id]) && (ue->dlsch_ra[eNB_id]->active == 1)) {
+    ue_dlsch_procedures(ue,
+                        proc,
+                        eNB_id,
+                        RA_PDSCH,
+                        ue->dlsch_ra[eNB_id],
+                        NULL,
+                        &ue->dlsch_ra_errors[eNB_id],
+                        mode,
+                        abstraction_flag);
+    ue->dlsch_ra[eNB_id]->active = 0;
+  }
 
-        }
-    /*
-    LTE_DL_UE_HARQ_t *harq_processes_dest    = ue->dlsch[(subframe_rx+1)%RX_NB_TH][eNB_id][0]->harq_processes[current_harq_pid];
-    LTE_DL_UE_HARQ_t *harq_processes_dest1    = ue->dlsch[(subframe_rx+2)%RX_NB_TH][eNB_id][0]->harq_processes[current_harq_pid];
+  if (LOG_DEBUGFLAG(UE_TIMING)) {
+      stop_meas(&ue->dlsch_procedures_stat[ue->current_thread_id[subframe_rx]]);
+      LOG_I(PHY, "[AbsSFN %d.%d] Channel Decoder: %5.2f \n",frame_rx,subframe_rx,ue->dlsch_procedures_stat[ue->current_thread_id[subframe_rx]].p_time/(cpuf*1000.0));
+}
 
-    harq_status_t *current_harq_ack = &ue->dlsch[subframe_rx%RX_NB_TH][eNB_id][0]->harq_ack[subframe_rx];
-    harq_status_t *harq_ack_dest    = &ue->dlsch[(subframe_rx+1)%RX_NB_TH][eNB_id][0]->harq_ack[subframe_rx];
-    harq_status_t *harq_ack_dest1    = &ue->dlsch[(subframe_rx+2)%RX_NB_TH][eNB_id][0]->harq_ack[subframe_rx];
+// duplicate harq structure
+uint8_t          current_harq_pid        = ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->current_harq_pid;
+LTE_DL_UE_HARQ_t *current_harq_processes = ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->harq_processes[current_harq_pid];
+harq_status_t    *current_harq_ack       = &ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->harq_ack[subframe_rx];
+
+// For Debug parallelisation
+//if (current_harq_ack->ack == 0) {
+//printf("[slot0 dl processing][End of Channel Decoding] AbsSubframe %d.%d Decode Fail for HarqId%d Round%d\n",frame_rx,subframe_rx,current_harq_pid,current_harq_processes->round);
+//}
+for(uint8_t rx_th_idx=1; rx_th_idx<RX_NB_TH; rx_th_idx++) {
+  LTE_DL_UE_HARQ_t *harq_processes_dest  = ue->dlsch[ue->current_thread_id[(subframe_rx+rx_th_idx)%10]][eNB_id][0]->harq_processes[current_harq_pid];
+  harq_status_t    *harq_ack_dest        = &ue->dlsch[ue->current_thread_id[(subframe_rx+rx_th_idx)%10]][eNB_id][0]->harq_ack[subframe_rx];
+  copy_harq_proc_struct(harq_processes_dest, current_harq_processes);
+  copy_ack_struct(harq_ack_dest, current_harq_ack);
+}
 
-    copy_harq_proc_struct(harq_processes_dest, current_harq_processes);
-    copy_ack_struct(harq_ack_dest, current_harq_ack);
+/*
+LTE_DL_UE_HARQ_t *harq_processes_dest    = ue->dlsch[(subframe_rx+1)%RX_NB_TH][eNB_id][0]->harq_processes[current_harq_pid];
+LTE_DL_UE_HARQ_t *harq_processes_dest1    = ue->dlsch[(subframe_rx+2)%RX_NB_TH][eNB_id][0]->harq_processes[current_harq_pid];
 
-    copy_harq_proc_struct(harq_processes_dest1, current_harq_processes);
-    copy_ack_struct(harq_ack_dest1, current_harq_ack);
-    */
-    if (subframe_rx==9) {
-        if (frame_rx % 10 == 0) {
-            if ((ue->dlsch_received[eNB_id] - ue->dlsch_received_last[eNB_id]) != 0)
-                ue->dlsch_fer[eNB_id] = (100*(ue->dlsch_errors[eNB_id] - ue->dlsch_errors_last[eNB_id]))/(ue->dlsch_received[eNB_id] - ue->dlsch_received_last[eNB_id]);
+harq_status_t *current_harq_ack = &ue->dlsch[subframe_rx%RX_NB_TH][eNB_id][0]->harq_ack[subframe_rx];
+harq_status_t *harq_ack_dest    = &ue->dlsch[(subframe_rx+1)%RX_NB_TH][eNB_id][0]->harq_ack[subframe_rx];
+harq_status_t *harq_ack_dest1    = &ue->dlsch[(subframe_rx+2)%RX_NB_TH][eNB_id][0]->harq_ack[subframe_rx];
 
-            ue->dlsch_errors_last[eNB_id] = ue->dlsch_errors[eNB_id];
-            ue->dlsch_received_last[eNB_id] = ue->dlsch_received[eNB_id];
-        }
+copy_harq_proc_struct(harq_processes_dest, current_harq_processes);
+copy_ack_struct(harq_ack_dest, current_harq_ack);
 
+copy_harq_proc_struct(harq_processes_dest1, current_harq_processes);
+copy_ack_struct(harq_ack_dest1, current_harq_ack);
+*/
+if (subframe_rx==9) {
+  if (frame_rx % 10 == 0) {
+    if ((ue->dlsch_received[eNB_id] - ue->dlsch_received_last[eNB_id]) != 0)
+      ue->dlsch_fer[eNB_id] = (100*(ue->dlsch_errors[eNB_id] - ue->dlsch_errors_last[eNB_id]))/(ue->dlsch_received[eNB_id] - ue->dlsch_received_last[eNB_id]);
 
-        ue->bitrate[eNB_id] = (ue->total_TBS[eNB_id] - ue->total_TBS_last[eNB_id])*100;
-        ue->total_TBS_last[eNB_id] = ue->total_TBS[eNB_id];
-        LOG_D(PHY,"[UE %d] Calculating bitrate Frame %d: total_TBS = %d, total_TBS_last = %d, bitrate %f kbits\n",
-                ue->Mod_id,frame_rx,ue->total_TBS[eNB_id],
-                ue->total_TBS_last[eNB_id],(float) ue->bitrate[eNB_id]/1000.0);
+    ue->dlsch_errors_last[eNB_id] = ue->dlsch_errors[eNB_id];
+    ue->dlsch_received_last[eNB_id] = ue->dlsch_received[eNB_id];
+  }
 
+  ue->bitrate[eNB_id] = (ue->total_TBS[eNB_id] - ue->total_TBS_last[eNB_id])*100;
+  ue->total_TBS_last[eNB_id] = ue->total_TBS[eNB_id];
+  LOG_D(PHY,"[UE %d] Calculating bitrate Frame %d: total_TBS = %d, total_TBS_last = %d, bitrate %f kbits\n",
+        ue->Mod_id,frame_rx,ue->total_TBS[eNB_id],
+        ue->total_TBS_last[eNB_id],(float) ue->bitrate[eNB_id]/1000.0);
 #if UE_AUTOTEST_TRACE
-        if ((frame_rx % 100 == 0)) {
-            LOG_I(PHY,"[UE  %d] AUTOTEST Metric : UE_DLSCH_BITRATE = %5.2f kbps (frame = %d) \n", ue->Mod_id, (float) ue->bitrate[eNB_id]/1000.0, frame_rx);
-        }
-#endif
 
-    }
+  if ((frame_rx % 100 == 0)) {
+    LOG_I(PHY,"[UE  %d] AUTOTEST Metric : UE_DLSCH_BITRATE = %5.2f kbps (frame = %d) \n", ue->Mod_id, (float) ue->bitrate[eNB_id]/1000.0, frame_rx);
+  }
+
+#endif
+}
 
-    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_RX, VCD_FUNCTION_OUT);
+VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_RX, VCD_FUNCTION_OUT);
 
-    if (LOG_DEBUGFLAG(UE_TIMING)){
-    stop_meas(&ue->phy_proc_rx[ue->current_thread_id[subframe_rx]]);
-    LOG_UI(PHY, "------FULL RX PROC [AbsSFN %d.%d]: %5.2f ------\n",frame_rx,subframe_rx,ue->phy_proc_rx[ue->current_thread_id[subframe_rx]].p_time/(cpuf*1000.0));
-    }
+if (LOG_DEBUGFLAG(UE_TIMING)) {
+  stop_meas(&ue->phy_proc_rx[ue->current_thread_id[subframe_rx]]);
+  LOG_I(PHY, "------FULL RX PROC [AbsSFN %d.%d]: %5.2f ------\n",frame_rx,subframe_rx,ue->phy_proc_rx[ue->current_thread_id[subframe_rx]].p_time/(cpuf*1000.0));
+}
 
-    LOG_D(PHY," ****** end RX-Chain  for AbsSubframe %d.%d ******  \n", frame_rx%1024, subframe_rx);
-    return (0);
+LOG_D(PHY," ****** end RX-Chain  for AbsSubframe %d.%d ******  \n", frame_rx%1024, subframe_rx);
+return (0);
 }
 #endif /*UE_SLOT_PARALLELISATION */
 
 
 void phy_procedures_UE_SL_RX(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc) {
-
-
 }
 
 int phy_procedures_UE_RX(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,
-			 uint8_t abstraction_flag,uint8_t do_pdcch_flag,runmode_t mode) {
-
+                         uint8_t abstraction_flag,uint8_t do_pdcch_flag,runmode_t mode) {
   int l,l2;
   int pilot1;
   int pmch_flag=0;
   int frame_rx = proc->frame_rx;
   int subframe_rx = proc->subframe_rx;
-
   uint8_t next1_thread_id = ue->current_thread_id[subframe_rx]== (RX_NB_TH-1) ? 0:(ue->current_thread_id[subframe_rx]+1);
   uint8_t next2_thread_id = next1_thread_id== (RX_NB_TH-1) ? 0:(next1_thread_id+1);
-
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_RX, VCD_FUNCTION_IN);
-
-
   T(T_UE_PHY_DL_TICK, T_INT(ue->Mod_id), T_INT(frame_rx%1024), T_INT(subframe_rx));
-
   T(T_UE_PHY_INPUT_SIGNAL, T_INT(ue->Mod_id), T_INT(frame_rx%1024), T_INT(subframe_rx), T_INT(0),
     T_BUFFER(&ue->common_vars.rxdata[0][subframe_rx*ue->frame_parms.samples_per_tti],
              ue->frame_parms.samples_per_tti * 4));
 
-
   // start timers
   if ( LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
     LOG_I(PHY," ****** start RX-Chain for AbsSubframe %d.%d ******  \n", frame_rx%1024, subframe_rx);
@@ -4633,29 +4294,32 @@ int phy_procedures_UE_RX(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,
 
   if(LOG_DEBUGFLAG(UE_TIMING)) {
     start_meas(&ue->phy_proc_rx[ue->current_thread_id[subframe_rx]]);
-    start_meas(&ue->generic_stat);
+    start_meas(&ue->ue_front_end_stat[ue->current_thread_id[subframe_rx]]);
   }
 
   pmch_flag = is_pmch_subframe(frame_rx,subframe_rx,&ue->frame_parms) ? 1 : 0;
 
   if (do_pdcch_flag) {
-  // deactivate reception until we scan pdcch
-  if (ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0])
-    ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->active = 0;
-  if (ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][1])
-    ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][1]->active = 0;
+    // deactivate reception until we scan pdcch
+    if (ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0])
+      ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->active = 0;
 
-  if (ue->dlsch_SI[eNB_id])
-    ue->dlsch_SI[eNB_id]->active = 0;
-  if (ue->dlsch_p[eNB_id])
-    ue->dlsch_p[eNB_id]->active = 0;
-  if (ue->dlsch_ra[eNB_id])
-    ue->dlsch_ra[eNB_id]->active = 0;
+    if (ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][1])
+      ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][1]->active = 0;
+
+    if (ue->dlsch_SI[eNB_id])
+      ue->dlsch_SI[eNB_id]->active = 0;
+
+    if (ue->dlsch_p[eNB_id])
+      ue->dlsch_p[eNB_id]->active = 0;
+
+    if (ue->dlsch_ra[eNB_id])
+      ue->dlsch_ra[eNB_id]->active = 0;
   }
 
   if (LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
-      LOG_D(PHY,"[UE %d] Frame %d subframe %d: Doing phy_procedures_UE_RX\n",
-      ue->Mod_id,frame_rx, subframe_rx);
+    LOG_D(PHY,"[UE %d] Frame %d subframe %d: Doing phy_procedures_UE_RX\n",
+          ue->Mod_id,frame_rx, subframe_rx);
   }
 
   if (ue->frame_parms.Ncp == 0) {  // normal prefix
@@ -4664,7 +4328,6 @@ int phy_procedures_UE_RX(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,
     pilot1 = 3;
   }
 
-
   if (subframe_select(&ue->frame_parms,subframe_rx) == SF_S) { // S-subframe, do first 5 symbols only
     l2 = 4;
   } else if (pmch_flag == 1) { // do first 2 symbols only
@@ -4674,6 +4337,7 @@ int phy_procedures_UE_RX(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,
   }
 
   int prev_subframe_rx = (subframe_rx - 1)<0? 9: (subframe_rx - 1);
+
   if (subframe_select(&ue->frame_parms,prev_subframe_rx) != SF_DL) {
     //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     // RX processing of symbols l=0...l2
@@ -4688,115 +4352,122 @@ int phy_procedures_UE_RX(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,
 
   LOG_D(PHY," ------ slot 0 Processing: AbsSubframe %d.%d ------  \n", frame_rx%1024, subframe_rx);
   LOG_D(PHY," ------  --> FFT/ChannelEst/PDCCH slot 0: AbsSubframe %d.%d ------  \n", frame_rx%1024, subframe_rx);
+
   for (; l<=l2; l++) {
     if (abstraction_flag == 0) {
-        if (LOG_DEBUGFLAG(UE_TIMING)) {
-          start_meas(&ue->ofdm_demod_stats);
-        }
+      if (LOG_DEBUGFLAG(UE_TIMING)) {
+        start_meas(&ue->ofdm_demod_stats);
+      }
+
       VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP, VCD_FUNCTION_IN);
       slot_fep(ue,
-         l,
-         (subframe_rx<<1),
-         0,
-         0,
-         0);
+               l,
+               (subframe_rx<<1),
+               0,
+               0,
+               0);
       VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP, VCD_FUNCTION_OUT);
+
       if (LOG_DEBUGFLAG(UE_TIMING)) {
         stop_meas(&ue->ofdm_demod_stats);
-        }
+      }
     }
 
     ue_measurement_procedures(l-1,ue,proc,eNB_id,(subframe_rx<<1),abstraction_flag,mode);
 
     if (do_pdcch_flag) {
       if ((l==pilot1) ||
-	  ((pmch_flag==1)&&(l==l2)))  {
-	LOG_D(PHY,"[UE  %d] Frame %d: Calling pdcch procedures (eNB %d)\n",ue->Mod_id,frame_rx,eNB_id);
-
-	//start_meas(&ue->rx_pdcch_stats[ue->current_thread_id[subframe_rx]]);
-	if (ue_pdcch_procedures(eNB_id,ue,proc,abstraction_flag) == -1) {
-	  LOG_E(PHY,"[UE  %d] Frame %d, subframe %d: Error in pdcch procedures\n",ue->Mod_id,frame_rx,subframe_rx);
-	  return(-1);
-	}
-	//stop_meas(&ue->rx_pdcch_stats[ue->current_thread_id[subframe_rx]]);
-    //printf("subframe %d n_pdcch_sym %d pdcch procedures  %5.3f \n",
-    //        subframe_rx, ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols,
-    //     (ue->rx_pdcch_stats[ue->current_thread_id[subframe_rx]].p_time)/(cpuf*1000.0));
-	LOG_D(PHY,"num_pdcch_symbols %d\n",ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols);
+          ((pmch_flag==1)&&(l==l2)))  {
+        LOG_D(PHY,"[UE  %d] Frame %d: Calling pdcch procedures (eNB %d)\n",ue->Mod_id,frame_rx,eNB_id);
+
+        //start_meas(&ue->rx_pdcch_stats[ue->current_thread_id[subframe_rx]]);
+        if (ue_pdcch_procedures(eNB_id,ue,proc,abstraction_flag) == -1) {
+          LOG_E(PHY,"[UE  %d] Frame %d, subframe %d: Error in pdcch procedures\n",ue->Mod_id,frame_rx,subframe_rx);
+          return(-1);
+        }
+
+        //stop_meas(&ue->rx_pdcch_stats[ue->current_thread_id[subframe_rx]]);
+        //printf("subframe %d n_pdcch_sym %d pdcch procedures  %5.3f \n",
+        //        subframe_rx, ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols,
+        //     (ue->rx_pdcch_stats[ue->current_thread_id[subframe_rx]].p_time)/(cpuf*1000.0));
+        LOG_D(PHY,"num_pdcch_symbols %d\n",ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols);
       }
     }
-
   } // for l=1..l2
-  ue_measurement_procedures(l-1,ue,proc,eNB_id,(subframe_rx<<1),abstraction_flag,mode);
 
+  ue_measurement_procedures(l-1,ue,proc,eNB_id,(subframe_rx<<1),abstraction_flag,mode);
   LOG_D(PHY," ------  end FFT/ChannelEst/PDCCH slot 0: AbsSubframe %d.%d ------  \n", frame_rx%1024, subframe_rx);
 
   // If this is PMCH, call procedures, do channel estimation for first symbol of next DL subframe and return
   if (pmch_flag == 1) {
     ue_pmch_procedures(ue,proc,eNB_id,abstraction_flag);
-
     int next_subframe_rx = (1+subframe_rx)%10;
-    if (subframe_select(&ue->frame_parms,next_subframe_rx) != SF_UL)
-    {
+
+    if (subframe_select(&ue->frame_parms,next_subframe_rx) != SF_UL) {
       slot_fep(ue,
-         0,
-         (next_subframe_rx<<1),
-         0,
-         0,
-         0);
+               0,
+               (next_subframe_rx<<1),
+               0,
+               0,
+               0);
     }
 
     return 0;
   }
 
   slot_fep(ue,
-     0,
-     1+(subframe_rx<<1),
-     0,
-     0,
-     0);
+           0,
+           1+(subframe_rx<<1),
+           0,
+           0,
+           0);
 
   // first slot has been processed (FFTs + Channel Estimation, PCFICH/PHICH/PDCCH)
   if (LOG_DEBUGFLAG(UE_TIMING)) {
-    stop_meas(&ue->generic_stat);
-    LOG_UI(PHY, "[SFN %d] Slot0: FFT + Channel Estimate + PCFICH/PHICH/PDCCH %5.2f \n",subframe_rx,ue->generic_stat.p_time/(cpuf*1000.0));
+    stop_meas(&ue->ue_front_end_stat[ue->current_thread_id[subframe_rx]]);
+    LOG_I(PHY, "[SFN %d] Slot0: FFT + Channel Estimate + PCFICH/PHICH/PDCCH %5.2f \n",subframe_rx,ue->ue_front_end_stat[ue->current_thread_id[subframe_rx]].p_time/(cpuf*1000.0));
   }
 
-
   LOG_D(PHY," ------ --> PDSCH ChannelComp/LLR slot 0: AbsSubframe %d.%d ------  \n", frame_rx%1024, subframe_rx);
+
   if (LOG_DEBUGFLAG(UE_TIMING)) {
     start_meas(&ue->generic_stat);
+    start_meas(&ue->crnti_procedures_stats);
   }
+
   // do procedures for C-RNTI
   if (ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->active == 1) {
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC, VCD_FUNCTION_IN);
     ue_pdsch_procedures(ue,
-			proc,
-			eNB_id,
-			PDSCH,
-			ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0],
-			NULL,
-			ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols,
-			ue->frame_parms.symbols_per_tti>>1,
-			abstraction_flag);
-
+                        proc,
+                        eNB_id,
+                        PDSCH,
+                        ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0],
+                        NULL,
+                        ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols,
+                        ue->frame_parms.symbols_per_tti>>1,
+                        abstraction_flag);
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC, VCD_FUNCTION_OUT);
   }
 
+  if (LOG_DEBUGFLAG(UE_TIMING)) {
+    stop_meas(&ue->crnti_procedures_stats);
+  }
+
   LOG_D(PHY," ------ end PDSCH ChannelComp/LLR slot 0: AbsSubframe %d.%d ------  \n", frame_rx%1024, subframe_rx);
+
   // do procedures for SI-RNTI
   if ((ue->dlsch_SI[eNB_id]) && (ue->dlsch_SI[eNB_id]->active == 1)) {
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC_SI, VCD_FUNCTION_IN);
     ue_pdsch_procedures(ue,
-
-			proc,
-			eNB_id,
-			SI_PDSCH,
-			ue->dlsch_SI[eNB_id],
-			NULL,
-			ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols,
-			ue->frame_parms.symbols_per_tti>>1,
-			abstraction_flag);
+                        proc,
+                        eNB_id,
+                        SI_PDSCH,
+                        ue->dlsch_SI[eNB_id],
+                        NULL,
+                        ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols,
+                        ue->frame_parms.symbols_per_tti>>1,
+                        abstraction_flag);
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC_SI, VCD_FUNCTION_OUT);
   }
 
@@ -4804,14 +4475,14 @@ int phy_procedures_UE_RX(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,
   if ((ue->dlsch_p[eNB_id]) && (ue->dlsch_p[eNB_id]->active == 1)) {
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC_P, VCD_FUNCTION_IN);
     ue_pdsch_procedures(ue,
-			proc,
-			eNB_id,
-			P_PDSCH,
-			ue->dlsch_p[eNB_id],
-			NULL,
-			ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols,
-			ue->frame_parms.symbols_per_tti>>1,
-			abstraction_flag);
+                        proc,
+                        eNB_id,
+                        P_PDSCH,
+                        ue->dlsch_p[eNB_id],
+                        NULL,
+                        ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols,
+                        ue->frame_parms.symbols_per_tti>>1,
+                        abstraction_flag);
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC_P, VCD_FUNCTION_OUT);
   }
 
@@ -4819,14 +4490,14 @@ int phy_procedures_UE_RX(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,
   if ((ue->dlsch_ra[eNB_id]) && (ue->dlsch_ra[eNB_id]->active == 1)) {
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC_RA, VCD_FUNCTION_IN);
     ue_pdsch_procedures(ue,
-			proc,
-			eNB_id,
-			RA_PDSCH,
-			ue->dlsch_ra[eNB_id],
-			NULL,
-			ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols,
-			ue->frame_parms.symbols_per_tti>>1,
-			abstraction_flag);
+                        proc,
+                        eNB_id,
+                        RA_PDSCH,
+                        ue->dlsch_ra[eNB_id],
+                        NULL,
+                        ue->pdcch_vars[ue->current_thread_id[subframe_rx]][eNB_id]->num_pdcch_symbols,
+                        ue->frame_parms.symbols_per_tti>>1,
+                        abstraction_flag);
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC_RA, VCD_FUNCTION_OUT);
   }
 
@@ -4839,235 +4510,230 @@ int phy_procedures_UE_RX(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,
         if (LOG_DEBUGFLAG(UE_TIMING)) {
           start_meas(&ue->ofdm_demod_stats);
         }
-	VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP, VCD_FUNCTION_IN);
-	slot_fep(ue,
-		 l,
-		 1+(subframe_rx<<1),
-		 0,
-		 0,
-		 0);
-	VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP, VCD_FUNCTION_OUT);
+
+        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP, VCD_FUNCTION_IN);
+        slot_fep(ue,
+                 l,
+                 1+(subframe_rx<<1),
+                 0,
+                 0,
+                 0);
+        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP, VCD_FUNCTION_OUT);
+
         if (LOG_DEBUGFLAG(UE_TIMING)) {
           stop_meas(&ue->ofdm_demod_stats);
         }
       }
 
       ue_measurement_procedures(l-1,ue,proc,eNB_id,1+(subframe_rx<<1),abstraction_flag,mode);
-
     } // for l=1..l2
-    ue_measurement_procedures(l-1,ue,proc,eNB_id,1+(subframe_rx<<1),abstraction_flag,mode);
 
+    ue_measurement_procedures(l-1,ue,proc,eNB_id,1+(subframe_rx<<1),abstraction_flag,mode);
     // do first symbol of next downlink subframe for channel estimation
     int next_subframe_rx = (1+subframe_rx)%10;
-    if (subframe_select(&ue->frame_parms,next_subframe_rx) != SF_UL)
-    {
+
+    if (subframe_select(&ue->frame_parms,next_subframe_rx) != SF_UL) {
       slot_fep(ue,
-         0,
-         (next_subframe_rx<<1),
-         0,
-         0,
-         0);
+               0,
+               (next_subframe_rx<<1),
+               0,
+               0,
+               0);
     }
   } // not an S-subframe
+
   if(LOG_DEBUGFLAG(UE_TIMING)) {
     stop_meas(&ue->generic_stat);
-    LOG_UI(PHY, "[SFN %d] Slot1: FFT + Channel Estimate + Pdsch Proc Slot0 %5.2f \n",subframe_rx,ue->generic_stat.p_time/(cpuf*1000.0));
+    LOG_I(PHY, "[SFN %d] Slot1: FFT + Channel Estimate + Pdsch Proc Slot0 %5.2f \n",subframe_rx,ue->generic_stat.p_time/(cpuf*1000.0));
   }
 
   LOG_D(PHY," ------  end FFT/ChannelEst/PDCCH slot 1: AbsSubframe %d.%d ------  \n", frame_rx%1024, subframe_rx);
 
-  if ( (subframe_rx == 0) && (ue->decode_MIB == 1))
-  {
+  if ( (subframe_rx == 0) && (ue->decode_MIB == 1)) {
     ue_pbch_procedures(eNB_id,ue,proc,abstraction_flag);
   }
 
-
-
   // do procedures for C-RNTI
   LOG_D(PHY," ------ --> PDSCH ChannelComp/LLR slot 0: AbsSubframe %d.%d ------  \n", frame_rx%1024, subframe_rx);
+
   if (ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->active == 1) {
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC, VCD_FUNCTION_IN);
-    if (LOG_DEBUGFLAG(UE_TIMING)) { 
+
+    if (LOG_DEBUGFLAG(UE_TIMING)) {
       start_meas(&ue->pdsch_procedures_stat[ue->current_thread_id[subframe_rx]]);
     }
+
     ue_pdsch_procedures(ue,
-			proc,
-			eNB_id,
-			PDSCH,
-			ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0],
-			NULL,
-			1+(ue->frame_parms.symbols_per_tti>>1),
-			ue->frame_parms.symbols_per_tti-1,
-			abstraction_flag);
+                        proc,
+                        eNB_id,
+                        PDSCH,
+                        ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0],
+                        NULL,
+                        1+(ue->frame_parms.symbols_per_tti>>1),
+                        ue->frame_parms.symbols_per_tti-1,
+                        abstraction_flag);
     LOG_D(PHY," ------ end PDSCH ChannelComp/LLR slot 0: AbsSubframe %d.%d ------  \n", frame_rx%1024, subframe_rx);
     LOG_D(PHY," ------ --> PDSCH Turbo Decoder slot 0/1: AbsSubframe %d.%d ------  \n", frame_rx%1024, subframe_rx);
-    if (LOG_DEBUGFLAG(UE_TIMING)) { 
+
+    if (LOG_DEBUGFLAG(UE_TIMING)) {
       stop_meas(&ue->pdsch_procedures_stat[ue->current_thread_id[subframe_rx]]);
       start_meas(&ue->dlsch_procedures_stat[ue->current_thread_id[subframe_rx]]);
     }
+
     ue_dlsch_procedures(ue,
-			proc,
-			eNB_id,
-			PDSCH,
-			ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0],
-			ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][1],
-			&ue->dlsch_errors[eNB_id],
-			mode,
-			abstraction_flag);
-    if (LOG_DEBUGFLAG(UE_TIMING)) { 
+                        proc,
+                        eNB_id,
+                        PDSCH,
+                        ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0],
+                        ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][1],
+                        &ue->dlsch_errors[eNB_id],
+                        mode,
+                        abstraction_flag);
+
+    if (LOG_DEBUGFLAG(UE_TIMING)) {
       stop_meas(&ue->dlsch_procedures_stat[ue->current_thread_id[subframe_rx]]);
-      LOG_UI(PHY, "[SFN %d] Slot1:       Pdsch Proc %5.2f\n",subframe_rx,ue->pdsch_procedures_stat[ue->current_thread_id[subframe_rx]].p_time/(cpuf*1000.0));
-      LOG_UI(PHY, "[SFN %d] Slot0 Slot1: Dlsch Proc %5.2f\n",subframe_rx,ue->dlsch_procedures_stat[ue->current_thread_id[subframe_rx]].p_time/(cpuf*1000.0));
+      LOG_I(PHY, "[SFN %d] Slot1:       Pdsch Proc %5.2f\n",subframe_rx,ue->pdsch_procedures_stat[ue->current_thread_id[subframe_rx]].p_time/(cpuf*1000.0));
+      LOG_I(PHY, "[SFN %d] Slot0 Slot1: Dlsch Proc %5.2f\n",subframe_rx,ue->dlsch_procedures_stat[ue->current_thread_id[subframe_rx]].p_time/(cpuf*1000.0));
     }
 
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC, VCD_FUNCTION_OUT);
-
   }
+
   if (LOG_DEBUGFLAG(UE_TIMING)) {
     start_meas(&ue->generic_stat);
   }
 
   if (LOG_DUMPFLAG(DEBUG_UE_PHYPROC)) {
-    if(subframe_rx==5 &&  ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->harq_processes[ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->current_harq_pid]->nb_rb > 20){
-  	 //LOG_M("decoder_llr.m","decllr",dlsch_llr,G,1,0);
-  	 //LOG_M("llr.m","llr",  &ue->pdsch_vars[eNB_id]->llr[0][0],(14*nb_rb*12*dlsch1_harq->Qm) - 4*(nb_rb*4*dlsch1_harq->Qm),1,0);
-
-  	 LOG_M("rxdataF0_current.m"    , "rxdataF0", &ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[subframe_rx]].rxdataF[0][0],14*ue->frame_parms.ofdm_symbol_size,1,1);
-  	 //LOG_M("rxdataF0_previous.m"    , "rxdataF0_prev_sss", &ue->common_vars.common_vars_rx_data_per_thread[next_thread_id].rxdataF[0][0],14*ue->frame_parms.ofdm_symbol_size,1,1);
-
-  	 //LOG_M("rxdataF0_previous.m"    , "rxdataF0_prev", &ue->common_vars.common_vars_rx_data_per_thread[next_thread_id].rxdataF[0][0],14*ue->frame_parms.ofdm_symbol_size,1,1);
-
-  	 LOG_M("dl_ch_estimates.m", "dl_ch_estimates_sfn5", &ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[subframe_rx]].dl_ch_estimates[0][0][0],14*ue->frame_parms.ofdm_symbol_size,1,1);
-  	 LOG_M("dl_ch_estimates_ext.m", "dl_ch_estimatesExt_sfn5", &ue->pdsch_vars[ue->current_thread_id[subframe_rx]][0]->dl_ch_estimates_ext[0][0],14*ue->frame_parms.N_RB_DL*12,1,1);
-  	 LOG_M("rxdataF_comp00.m","rxdataF_comp00",	    &ue->pdsch_vars[ue->current_thread_id[subframe_rx]][0]->rxdataF_comp0[0][0],14*ue->frame_parms.N_RB_DL*12,1,1);
-  	 //LOG_M("magDLFirst.m", "magDLFirst", &phy_vars_ue->pdsch_vars[ue->current_thread_id[subframe_rx]][0]->dl_ch_mag0[0][0],14*frame_parms->N_RB_DL*12,1,1);
-  	 //LOG_M("magDLSecond.m", "magDLSecond", &phy_vars_ue->pdsch_vars[ue->current_thread_id[subframe_rx]][0]->dl_ch_magb0[0][0],14*frame_parms->N_RB_DL*12,1,1);
-
-  	 AssertFatal (0,"");
+    if(subframe_rx==5 &&  ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->harq_processes[ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->current_harq_pid]->nb_rb > 20) {
+      //LOG_M("decoder_llr.m","decllr",dlsch_llr,G,1,0);
+      //LOG_M("llr.m","llr",  &ue->pdsch_vars[eNB_id]->llr[0][0],(14*nb_rb*12*dlsch1_harq->Qm) - 4*(nb_rb*4*dlsch1_harq->Qm),1,0);
+      LOG_M("rxdataF0_current.m", "rxdataF0", &ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[subframe_rx]].rxdataF[0][0],14*ue->frame_parms.ofdm_symbol_size,1,1);
+      //LOG_M("rxdataF0_previous.m"    , "rxdataF0_prev_sss", &ue->common_vars.common_vars_rx_data_per_thread[next_thread_id].rxdataF[0][0],14*ue->frame_parms.ofdm_symbol_size,1,1);
+      //LOG_M("rxdataF0_previous.m"    , "rxdataF0_prev", &ue->common_vars.common_vars_rx_data_per_thread[next_thread_id].rxdataF[0][0],14*ue->frame_parms.ofdm_symbol_size,1,1);
+      LOG_M("dl_ch_estimates.m", "dl_ch_estimates_sfn5", &ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[subframe_rx]].dl_ch_estimates[0][0][0],14*ue->frame_parms.ofdm_symbol_size,1,
+            1);
+      LOG_M("dl_ch_estimates_ext.m", "dl_ch_estimatesExt_sfn5", &ue->pdsch_vars[ue->current_thread_id[subframe_rx]][0]->dl_ch_estimates_ext[0][0],14*ue->frame_parms.N_RB_DL*12,1,1);
+      LOG_M("rxdataF_comp00.m","rxdataF_comp00",     &ue->pdsch_vars[ue->current_thread_id[subframe_rx]][0]->rxdataF_comp0[0][0],14*ue->frame_parms.N_RB_DL*12,1,1);
+      //LOG_M("magDLFirst.m", "magDLFirst", &phy_vars_ue->pdsch_vars[ue->current_thread_id[subframe_rx]][0]->dl_ch_mag0[0][0],14*frame_parms->N_RB_DL*12,1,1);
+      //LOG_M("magDLSecond.m", "magDLSecond", &phy_vars_ue->pdsch_vars[ue->current_thread_id[subframe_rx]][0]->dl_ch_magb0[0][0],14*frame_parms->N_RB_DL*12,1,1);
+      AssertFatal (0,"");
     }
   }
 
   // do procedures for SI-RNTI
   if ((ue->dlsch_SI[eNB_id]) && (ue->dlsch_SI[eNB_id]->active == 1)) {
     ue_pdsch_procedures(ue,
-      proc,
-      eNB_id,
-      SI_PDSCH,
-      ue->dlsch_SI[eNB_id],
-      NULL,
-      1+(ue->frame_parms.symbols_per_tti>>1),
-      ue->frame_parms.symbols_per_tti-1,
-      abstraction_flag);
-
+                        proc,
+                        eNB_id,
+                        SI_PDSCH,
+                        ue->dlsch_SI[eNB_id],
+                        NULL,
+                        1+(ue->frame_parms.symbols_per_tti>>1),
+                        ue->frame_parms.symbols_per_tti-1,
+                        abstraction_flag);
     ue_dlsch_procedures(ue,
-      proc,
-      eNB_id,
-      SI_PDSCH,
-      ue->dlsch_SI[eNB_id],
-      NULL,
-      &ue->dlsch_SI_errors[eNB_id],
-      mode,
-      abstraction_flag);
+                        proc,
+                        eNB_id,
+                        SI_PDSCH,
+                        ue->dlsch_SI[eNB_id],
+                        NULL,
+                        &ue->dlsch_SI_errors[eNB_id],
+                        mode,
+                        abstraction_flag);
     ue->dlsch_SI[eNB_id]->active = 0;
   }
 
   // do procedures for P-RNTI
   if ((ue->dlsch_p[eNB_id]) && (ue->dlsch_p[eNB_id]->active == 1)) {
     ue_pdsch_procedures(ue,
-      proc,
-      eNB_id,
-      P_PDSCH,
-      ue->dlsch_p[eNB_id],
-      NULL,
-      1+(ue->frame_parms.symbols_per_tti>>1),
-      ue->frame_parms.symbols_per_tti-1,
-      abstraction_flag);
-
+                        proc,
+                        eNB_id,
+                        P_PDSCH,
+                        ue->dlsch_p[eNB_id],
+                        NULL,
+                        1+(ue->frame_parms.symbols_per_tti>>1),
+                        ue->frame_parms.symbols_per_tti-1,
+                        abstraction_flag);
     ue_dlsch_procedures(ue,
-      proc,
-      eNB_id,
-      P_PDSCH,
-      ue->dlsch_p[eNB_id],
-      NULL,
-      &ue->dlsch_p_errors[eNB_id],
-      mode,
-      abstraction_flag);
+                        proc,
+                        eNB_id,
+                        P_PDSCH,
+                        ue->dlsch_p[eNB_id],
+                        NULL,
+                        &ue->dlsch_p_errors[eNB_id],
+                        mode,
+                        abstraction_flag);
     ue->dlsch_p[eNB_id]->active = 0;
   }
+
   // do procedures for RA-RNTI
   if ((ue->dlsch_ra[eNB_id]) && (ue->dlsch_ra[eNB_id]->active == 1)) {
     ue_pdsch_procedures(ue,
-      proc,
-      eNB_id,
-      RA_PDSCH,
-      ue->dlsch_ra[eNB_id],
-      NULL,
-      1+(ue->frame_parms.symbols_per_tti>>1),
-      ue->frame_parms.symbols_per_tti-1,
-      abstraction_flag);
+                        proc,
+                        eNB_id,
+                        RA_PDSCH,
+                        ue->dlsch_ra[eNB_id],
+                        NULL,
+                        1+(ue->frame_parms.symbols_per_tti>>1),
+                        ue->frame_parms.symbols_per_tti-1,
+                        abstraction_flag);
     ue_dlsch_procedures(ue,
-      proc,
-      eNB_id,
-      RA_PDSCH,
-      ue->dlsch_ra[eNB_id],
-      NULL,
-      &ue->dlsch_ra_errors[eNB_id],
-      mode,
-      abstraction_flag);
+                        proc,
+                        eNB_id,
+                        RA_PDSCH,
+                        ue->dlsch_ra[eNB_id],
+                        NULL,
+                        &ue->dlsch_ra_errors[eNB_id],
+                        mode,
+                        abstraction_flag);
     ue->dlsch_ra[eNB_id]->active = 0;
   }
 
   // duplicate harq structure
-
   uint8_t          current_harq_pid        = ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->current_harq_pid;
   LTE_DL_UE_HARQ_t *current_harq_processes = ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->harq_processes[current_harq_pid];
   LTE_DL_UE_HARQ_t *harq_processes_dest    = ue->dlsch[next1_thread_id][eNB_id][0]->harq_processes[current_harq_pid];
   LTE_DL_UE_HARQ_t *harq_processes_dest1    = ue->dlsch[next2_thread_id][eNB_id][0]->harq_processes[current_harq_pid];
-
   harq_status_t *current_harq_ack = &ue->dlsch[ue->current_thread_id[subframe_rx]][eNB_id][0]->harq_ack[subframe_rx];
   harq_status_t *harq_ack_dest    = &ue->dlsch[next1_thread_id][eNB_id][0]->harq_ack[subframe_rx];
   harq_status_t *harq_ack_dest1    = &ue->dlsch[next2_thread_id][eNB_id][0]->harq_ack[subframe_rx];
-
   copy_harq_proc_struct(harq_processes_dest, current_harq_processes);
   copy_ack_struct(harq_ack_dest, current_harq_ack);
-
   copy_harq_proc_struct(harq_processes_dest1, current_harq_processes);
   copy_ack_struct(harq_ack_dest1, current_harq_ack);
 
   if (subframe_rx==9) {
     if (frame_rx % 10 == 0) {
       if ((ue->dlsch_received[eNB_id] - ue->dlsch_received_last[eNB_id]) != 0)
-  ue->dlsch_fer[eNB_id] = (100*(ue->dlsch_errors[eNB_id] - ue->dlsch_errors_last[eNB_id]))/(ue->dlsch_received[eNB_id] - ue->dlsch_received_last[eNB_id]);
+        ue->dlsch_fer[eNB_id] = (100*(ue->dlsch_errors[eNB_id] - ue->dlsch_errors_last[eNB_id]))/(ue->dlsch_received[eNB_id] - ue->dlsch_received_last[eNB_id]);
 
       ue->dlsch_errors_last[eNB_id] = ue->dlsch_errors[eNB_id];
       ue->dlsch_received_last[eNB_id] = ue->dlsch_received[eNB_id];
     }
 
-
     ue->bitrate[eNB_id] = (ue->total_TBS[eNB_id] - ue->total_TBS_last[eNB_id])*100;
     ue->total_TBS_last[eNB_id] = ue->total_TBS[eNB_id];
     LOG_D(PHY,"[UE %d] Calculating bitrate Frame %d: total_TBS = %d, total_TBS_last = %d, bitrate %f kbits\n",
-    ue->Mod_id,frame_rx,ue->total_TBS[eNB_id],
-    ue->total_TBS_last[eNB_id],(float) ue->bitrate[eNB_id]/1000.0);
+          ue->Mod_id,frame_rx,ue->total_TBS[eNB_id],
+          ue->total_TBS_last[eNB_id],(float) ue->bitrate[eNB_id]/1000.0);
 
     if ( LOG_DEBUGFLAG(DEBUG_UE_PHYPROC)) {
       if ((frame_rx % 100 == 0)) {
         LOG_UI(PHY,"[UE  %d] AUTOTEST Metric : UE_DLSCH_BITRATE = %5.2f kbps (frame = %d) \n", ue->Mod_id, (float) ue->bitrate[eNB_id]/1000.0, frame_rx);
       }
     }
-
   }
 
   if ( LOG_DEBUGFLAG(UE_TIMING)) {
     stop_meas(&ue->generic_stat);
-    LOG_UI(PHY,"after tubo until end of Rx %5.2f \n",ue->generic_stat.p_time/(cpuf*1000.0));
+    LOG_I(PHY,"after tubo until end of Rx %5.2f \n",ue->generic_stat.p_time/(cpuf*1000.0));
   }
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_RX, VCD_FUNCTION_OUT);
 
   if ( LOG_DEBUGFLAG(UE_TIMING) ) {
     stop_meas(&ue->phy_proc_rx[ue->current_thread_id[subframe_rx]]);
-    LOG_UI(PHY, "------FULL RX PROC [SFN %d]: %5.2f ------\n",subframe_rx,ue->phy_proc_rx[ue->current_thread_id[subframe_rx]].p_time/(cpuf*1000.0));
+    LOG_I(PHY, "------FULL RX PROC [SFN %d]: %5.2f ------\n",subframe_rx,ue->phy_proc_rx[ue->current_thread_id[subframe_rx]].p_time/(cpuf*1000.0));
   }
 
   LOG_D(PHY," ****** end RX-Chain  for AbsSubframe %d.%d ******  \n", frame_rx%1024, subframe_rx);
@@ -5076,19 +4742,15 @@ int phy_procedures_UE_RX(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,
 
 
 
-void phy_procedures_UE_lte(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uint8_t abstraction_flag,uint8_t do_pdcch_flag,runmode_t mode)
-{
+void phy_procedures_UE_lte(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uint8_t abstraction_flag,uint8_t do_pdcch_flag,runmode_t mode) {
 #if defined(ENABLE_ITTI)
   MessageDef   *msg_p;
   int           result;
 #endif
-
   int           frame_rx = proc->frame_rx;
   int           frame_tx = proc->frame_tx;
   int           subframe_rx = proc->subframe_rx;
   int           subframe_tx = proc->subframe_tx;
-
-
   UE_L2_STATE_t ret;
   int slot;
 
@@ -5096,8 +4758,8 @@ void phy_procedures_UE_lte(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,u
     ue->UE_mode[eNB_id]=PUSCH;
   }
 
-
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_LTE,1);
+
   if ( LOG_DEBUGFLAG(UE_TIMING)) {
     start_meas(&ue->phy_proc[ue->current_thread_id[subframe_rx]]);
   }
@@ -5110,15 +4772,14 @@ void phy_procedures_UE_lte(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,u
 
     if (msg_p != NULL) {
       switch (ITTI_MSG_ID(msg_p)) {
-      case PHY_FIND_CELL_REQ:
-  LOG_I(PHY, "[UE %d] Received %s\n", ITTI_MSG_INSTANCE (msg_p) - NB_eNB_INST, ITTI_MSG_NAME (msg_p));
-
-  /* TODO process the message */
-  break;
+        case PHY_FIND_CELL_REQ:
+          LOG_E(PHY, "[UE %d] Received PLMN doesn't match SIM data, but not developped further processing %s\n", ITTI_MSG_INSTANCE (msg_p) - NB_eNB_INST, ITTI_MSG_NAME (msg_p));
+          /* TODO process the message */
+          break;
 
-      default:
-  LOG_E(PHY, "[UE %d] Received unexpected message %s\n", ITTI_MSG_INSTANCE (msg_p) - NB_eNB_INST, ITTI_MSG_NAME (msg_p));
-  break;
+        default:
+          LOG_E(PHY, "[UE %d] Received unexpected message %s\n", ITTI_MSG_INSTANCE (msg_p) - NB_eNB_INST, ITTI_MSG_NAME (msg_p));
+          break;
       }
 
       result = itti_free (ITTI_MSG_ORIGIN_ID(msg_p), msg_p);
@@ -5128,62 +4789,61 @@ void phy_procedures_UE_lte(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,u
 
 #endif
 
-  for (slot=0;slot<2;slot++) {
-
+  for (slot=0; slot<2; slot++) {
     if ((subframe_select(&ue->frame_parms,subframe_tx)==SF_UL)||
-  (ue->frame_parms.frame_type == FDD)) {
+        (ue->frame_parms.frame_type == FDD)) {
       phy_procedures_UE_TX(ue,proc,eNB_id,abstraction_flag,mode);
     }
 
     if ((subframe_select(&ue->frame_parms,subframe_rx)==SF_DL) ||
-	(ue->frame_parms.frame_type == FDD)) {
+        (ue->frame_parms.frame_type == FDD)) {
       phy_procedures_UE_RX(ue,proc,eNB_id,abstraction_flag,do_pdcch_flag,mode);
     }
 
     if ((subframe_select(&ue->frame_parms,subframe_tx)==SF_S) &&
-	(slot==1)) {
+        (slot==1)) {
       phy_procedures_UE_S_TX(ue,eNB_id,abstraction_flag);
     }
 
     if ((subframe_select(&ue->frame_parms,subframe_rx)==SF_S) &&
-	(slot==0)) {
-	phy_procedures_UE_RX(ue,proc,eNB_id,abstraction_flag,do_pdcch_flag,mode);
+        (slot==0)) {
+      phy_procedures_UE_RX(ue,proc,eNB_id,abstraction_flag,do_pdcch_flag,mode);
     }
 
     if (ue->mac_enabled==1) {
       if (slot==0) {
-
-          //LOG_I(PHY,"[UE %d] Frame %d, subframe %d, star ue_scheduler\n", ue->Mod_id,frame_rx,subframe_tx);
+        //LOG_I(PHY,"[UE %d] Frame %d, subframe %d, star ue_scheduler\n", ue->Mod_id,frame_rx,subframe_tx);
         ret = ue_scheduler(ue->Mod_id,
-			   frame_rx,
-			   subframe_rx,
-			   frame_tx,
-			   subframe_tx,
-			   subframe_select(&ue->frame_parms,subframe_tx),
-			   eNB_id,
-			   0/*FIXME CC_id*/);
-	
-	if (ret == CONNECTION_LOST) {
-	  LOG_E(PHY,"[UE %d] Frame %d, subframe %d RRC Connection lost, returning to PRACH\n",ue->Mod_id,
-		frame_rx,subframe_tx);
-	  ue->UE_mode[eNB_id] = PRACH;
-	  //      mac_xface->macphy_exit("Connection lost");
-	} else if (ret == PHY_RESYNCH) {
-	  LOG_E(PHY,"[UE %d] Frame %d, subframe %d RRC Connection lost, trying to resynch\n",
-		ue->Mod_id,
-		frame_rx,subframe_tx);
-	  ue->UE_mode[eNB_id] = RESYNCH;
-	  //     mac_xface->macphy_exit("Connection lost");
-	} else if (ret == PHY_HO_PRACH) {
-	  LOG_I(PHY,"[UE %d] Frame %d, subframe %d, return to PRACH and perform a contention-free access\n",
-		ue->Mod_id,frame_rx,subframe_tx);
-	  ue->UE_mode[eNB_id] = PRACH;
-	}
+                           frame_rx,
+                           subframe_rx,
+                           frame_tx,
+                           subframe_tx,
+                           subframe_select(&ue->frame_parms,subframe_tx),
+                           eNB_id,
+                           0/*FIXME CC_id*/);
+
+        if (ret == CONNECTION_LOST) {
+          LOG_E(PHY,"[UE %d] Frame %d, subframe %d RRC Connection lost, returning to PRACH\n",ue->Mod_id,
+                frame_rx,subframe_tx);
+          ue->UE_mode[eNB_id] = PRACH;
+          //      mac_xface->macphy_exit("Connection lost");
+        } else if (ret == PHY_RESYNCH) {
+          LOG_E(PHY,"[UE %d] Frame %d, subframe %d RRC Connection lost, trying to resynch\n",
+                ue->Mod_id,
+                frame_rx,subframe_tx);
+          ue->UE_mode[eNB_id] = RESYNCH;
+          //     mac_xface->macphy_exit("Connection lost");
+        } else if (ret == PHY_HO_PRACH) {
+          LOG_I(PHY,"[UE %d] Frame %d, subframe %d, return to PRACH and perform a contention-free access\n",
+                ue->Mod_id,frame_rx,subframe_tx);
+          ue->UE_mode[eNB_id] = PRACH;
+        }
       }
     }
-    
+
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_LTE,0);
-    if (LOG_DEBUGFLAG(UE_TIMING)) { 
+
+    if (LOG_DEBUGFLAG(UE_TIMING)) {
       stop_meas(&ue->phy_proc[ue->current_thread_id[subframe_rx]]);
     }
   } // slot
diff --git a/openair1/SIMULATION/LTE_PHY/Abstraction/Training/IEEEtran.cls b/openair1/SIMULATION/LTE_PHY/Abstraction/Training/IEEEtran.cls
old mode 100755
new mode 100644
diff --git a/openair1/SIMULATION/LTE_PHY/Abstraction/Training/bare_adv.tex b/openair1/SIMULATION/LTE_PHY/Abstraction/Training/bare_adv.tex
old mode 100755
new mode 100644
diff --git a/openair1/SIMULATION/LTE_PHY/Abstraction/Training/bare_jrnl.tex b/openair1/SIMULATION/LTE_PHY/Abstraction/Training/bare_jrnl.tex
old mode 100755
new mode 100644
diff --git a/openair1/SIMULATION/LTE_PHY/Abstraction/Training/bare_jrnl_compsoc.tex b/openair1/SIMULATION/LTE_PHY/Abstraction/Training/bare_jrnl_compsoc.tex
old mode 100755
new mode 100644
diff --git a/openair1/SIMULATION/LTE_PHY/common_sim.h b/openair1/SIMULATION/LTE_PHY/common_sim.h
new file mode 100644
index 0000000000000000000000000000000000000000..ff8406b0c1a4cab7f759a7aa1573f20752b050ad
--- /dev/null
+++ b/openair1/SIMULATION/LTE_PHY/common_sim.h
@@ -0,0 +1,172 @@
+
+static int cmpdouble(const void *p1, const void *p2) {
+  return *(double *)p1 > *(double *)p2;
+}
+
+double median(varArray_t *input) {
+  return *(double *)((uint8_t *)(input+1)+(input->size/2)*input->atomSize);
+}
+
+double q1(varArray_t *input) {
+  return *(double *)((uint8_t *)(input+1)+(input->size/4)*input->atomSize);
+}
+
+double q3(varArray_t *input) {
+  return *(double *)((uint8_t *)(input+1)+(3*input->size/4)*input->atomSize);
+}
+
+void dumpVarArray(varArray_t *input) {
+  double *ptr=dataArray(input);
+  printf("dumping size=%ld\n", input->size);
+
+  for (int i=0; i < input->size; i++)
+    printf("%.1f:", *ptr++);
+
+  printf("\n");
+}
+void sumUpStats(time_stats_t * res, time_stats_t * src, int lastActive) {
+  reset_meas(res);
+	for (int i=0; i<RX_NB_TH; i++) {
+	  res->diff+=src[i].diff;
+	  res->diff_square+=src[i].diff_square;
+	  res->trials+=src[i].trials;
+	  if (src[i].max > res->max)
+	    res->max=src[i].max;
+	}
+	res->p_time=src[lastActive].p_time;
+}
+void sumUpStatsSlot(time_stats_t *res, time_stats_t src[RX_NB_TH][2], int lastActive) {
+  reset_meas(res);
+	for (int i=0; i<RX_NB_TH; i++) {
+	  res->diff+=src[i][0].diff+src[i][1].diff;
+	  res->diff_square+=src[i][0].diff_square+src[i][1].diff_square;
+	  res->trials+=src[i][0].trials+src[i][1].trials;
+	  if (src[i][0].max > res->max)
+	    res->max=src[i][0].max;
+	  if (src[i][1].max > res->max)
+	    res->max=src[i][1].max;}
+	int last=src[lastActive][0].in < src[lastActive][1].in? 1 : 0 ;
+	res->p_time=src[lastActive][last].p_time;
+}
+
+double squareRoot(time_stats_t *ptr) {
+  double timeBase=1/(1000*cpu_freq_GHz);
+  return sqrt((double)ptr->diff_square*pow(timeBase,2)/ptr->trials -
+              pow((double)ptr->diff/ptr->trials*timeBase,2));
+}
+
+void printDistribution(time_stats_t *ptr, varArray_t *sortedList, char *txt) {
+  double timeBase=1/(1000*cpu_freq_GHz);
+  printf("%-43s %6.2f us (%d trials)\n",
+         txt,
+         (double)ptr->diff/ptr->trials*timeBase,
+         ptr->trials);
+  printf(" Statistics std=%.2f, median=%.2f, q1=%.2f, q3=%.2f µs (on %ld trials)\n",
+         squareRoot(ptr), median(sortedList),q1(sortedList),q3(sortedList), sortedList->size);
+}
+
+void printStatIndent(time_stats_t *ptr, char *txt) {
+  printf("|__ %-38s %6.2f us (%3d trials)\n",
+         txt,
+         ptr->trials?inMicroS(ptr->diff/ptr->trials):0,
+         ptr->trials);
+}
+
+void printStatIndent2(time_stats_t *ptr, char *txt) {
+  double timeBase=1/(1000*cpu_freq_GHz);
+  printf("    |__ %-34s %6.2f us (%3d trials)\n",
+         txt,
+         ptr->trials?((double)ptr->diff)/ptr->trials*timeBase:0,
+	 ptr->trials);
+}
+
+void printStatIndent3(time_stats_t *ptr, char *txt) {
+  double timeBase=1/(1000*cpu_freq_GHz);
+  printf("        |__ %-30s %6.2f us (%3d trials)\n",
+         txt,
+         ptr->trials?((double)ptr->diff)/ptr->trials*timeBase:0,
+	 ptr->trials);
+}
+
+
+void logDistribution(FILE* fd, time_stats_t *ptr, varArray_t *sortedList, int dropped) {
+  fprintf(fd,"%f;%f;%f;%f;%f;%f;%d;",
+	  squareRoot(ptr),
+	  (double)ptr->max, *(double*)dataArray(sortedList),
+	  median(sortedList),q1(sortedList),q3(sortedList),
+	  dropped);
+}
+
+struct option * parse_oai_options(paramdef_t *options) {
+  int l;
+
+  for(l=0; options[l].optname[0]!=0; l++) {};
+
+  struct option *long_options=calloc(sizeof(struct option),l);
+
+  for(int i=0; options[i].optname[0]!=0; i++) {
+    long_options[i].name=options[i].optname;
+    long_options[i].has_arg=options[i].paramflags==PARAMFLAG_BOOL?no_argument:required_argument;
+
+    if ( options[i].voidptr)
+      switch (options[i].type) {
+      case TYPE_INT:
+	*options[i].iptr=options[i].defintval;
+	break;
+
+      case TYPE_DOUBLE:
+	*options[i].dblptr=options[i].defdblval;
+	break;
+
+      case TYPE_UINT8:
+	*options[i].u8ptr=options[i].defintval;
+	break;
+
+      case TYPE_UINT16:
+	*options[i].u16ptr=options[i].defintval;
+	break;
+
+      default:
+	printf("not parsed type for default value %s\n", options[i].optname );
+	exit(1);
+      }
+
+    continue;
+  };
+  return long_options;
+}
+
+void display_options_values(paramdef_t *options, int verbose) {
+  for(paramdef_t * ptr=options; ptr->optname[0]!=0; ptr++) {
+    char varText[256]="need specific display";
+
+    if (ptr->voidptr != NULL) {
+      if ( (ptr->paramflags & PARAMFLAG_BOOL) )
+        strcpy(varText, *(bool *)ptr->iptr ? "True": "False" );
+      else  switch (ptr->type) {
+          case TYPE_INT:
+            sprintf(varText,"%d",*ptr->iptr);
+            break;
+
+          case TYPE_DOUBLE:
+            sprintf(varText,"%.2f",*ptr->dblptr);
+            break;
+
+	case TYPE_UINT8:
+	  sprintf(varText,"%d",(int)*ptr->u8ptr);
+	  break;
+
+	case TYPE_UINT16:
+	  sprintf(varText,"%d",(int)*ptr->u16ptr);
+	  break;
+
+	default:
+	  printf("not decoded type\n");
+	  exit(1);
+        }
+    }
+
+    printf("--%-20s set to %s\n",ptr->optname, varText);
+    if (verbose) printf("%s\n",ptr->helpstr);
+  }
+}
diff --git a/openair1/SIMULATION/LTE_PHY/dlsim.c b/openair1/SIMULATION/LTE_PHY/dlsim.c
index 14a49b0355d84aa62fdddc8ccb51cc4e96ed51ad..74613f8fb128df6177af2e0259ad45015cd0c519 100644
--- a/openair1/SIMULATION/LTE_PHY/dlsim.c
+++ b/openair1/SIMULATION/LTE_PHY/dlsim.c
@@ -72,6 +72,9 @@ void feptx_ofdm(RU_t *ru);
 void feptx_prec(RU_t *ru);
 
 double cpuf;
+#define inMicroS(a) (((double)(a))/(cpu_freq_GHz*1000.0))
+//#define MCS_COUNT 23//added for PHY abstraction
+#include <openair1/SIMULATION/LTE_PHY/common_sim.h>
 
 int otg_enabled=0;
 /*the following parameters are used to control the processing times calculations*/
@@ -82,41 +85,15 @@ double t_rx_min = 1000000000; /*!< \brief initial min process time for rx */
 int n_tx_dropped = 0; /*!< \brief initial max process time for tx */
 int n_rx_dropped = 0; /*!< \brief initial max process time for rx */
 
-char *parallel_config = NULL;
-char *worker_config = NULL;
-static THREAD_STRUCT thread_struct;
-void set_parallel_conf(char *parallel_conf)
-{
-  if(strcmp(parallel_conf,"PARALLEL_SINGLE_THREAD")==0)           thread_struct.parallel_conf = PARALLEL_SINGLE_THREAD;
-  else if(strcmp(parallel_conf,"PARALLEL_RU_L1_SPLIT")==0)        thread_struct.parallel_conf = PARALLEL_RU_L1_SPLIT;
-  else if(strcmp(parallel_conf,"PARALLEL_RU_L1_TRX_SPLIT")==0)    thread_struct.parallel_conf = PARALLEL_RU_L1_TRX_SPLIT;
-  printf("[CONFIG] parallel conf is set to %d\n",thread_struct.parallel_conf);
-}
-void set_worker_conf(char *worker_conf)
-{
-  if(strcmp(worker_conf,"WORKER_DISABLE")==0)                     thread_struct.worker_conf = WORKER_DISABLE;
-  else if(strcmp(worker_conf,"WORKER_ENABLE")==0)                 thread_struct.worker_conf = WORKER_ENABLE;
-  printf("[CONFIG] worker conf is set to %d\n",thread_struct.worker_conf);
-}
-PARALLEL_CONF_t get_thread_parallel_conf(void)
-{
-  return thread_struct.parallel_conf;
-}
-WORKER_CONF_t get_thread_worker_conf(void)
-{
-  return thread_struct.worker_conf;
-}
+THREAD_STRUCT thread_struct;
 
 int emulate_rf = 0;
 
-void handler(int sig)
-{
+void handler(int sig) {
   void *array[10];
   size_t size;
-
   // get void*'s for all entries on the stack
   size = backtrace(array, 10);
-
   // print out all the frames to stderr
   fprintf(stderr, "Error: signal %d:\n", sig);
   backtrace_symbols_fd(array, size, 2);
@@ -134,17 +111,13 @@ uint64_t DLSCH_alloc_pdu_1[2];
 #define CCCH_RB_ALLOC computeRIV(eNB->frame_parms.N_RB_UL,0,2)
 //#define DLSCH_RB_ALLOC 0x1fbf // igore DC component,RB13
 //#define DLSCH_RB_ALLOC 0x0001
-void do_OFDM_mod_l(int32_t **txdataF, int32_t **txdata, uint16_t next_slot, LTE_DL_FRAME_PARMS *frame_parms)
-{
-
+void do_OFDM_mod_l(int32_t **txdataF, int32_t **txdata, uint16_t next_slot, LTE_DL_FRAME_PARMS *frame_parms) {
   int aa, slot_offset, slot_offset_F;
-
   slot_offset_F = (next_slot)*(frame_parms->ofdm_symbol_size)*((frame_parms->Ncp==1) ? 6 : 7);
   slot_offset = (next_slot)*(frame_parms->samples_per_tti>>1);
 
   for (aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
     //    printf("Thread %d starting ... aa %d (%llu)\n",omp_get_thread_num(),aa,rdtsc());
-
     if (frame_parms->Ncp == 1)
       PHY_ofdm_mod(&txdataF[aa][slot_offset_F],        // input
                    &txdata[aa][slot_offset],         // output
@@ -158,15 +131,11 @@ void do_OFDM_mod_l(int32_t **txdataF, int32_t **txdata, uint16_t next_slot, LTE_
                         7,
                         frame_parms);
     }
-
-
   }
-
 }
 
 void DL_channel(RU_t *ru,PHY_VARS_UE *UE,uint subframe,int awgn_flag,double SNR, int tx_lev,int hold_channel,int abstx, int num_rounds, int trials, int round, channel_desc_t *eNB2UE[4],
-		double *s_re[2],double *s_im[2],double *r_re[2],double *r_im[2],FILE *csv_fd) {
-
+                double *s_re[2],double *s_im[2],double *r_re[2],double *r_im[2],FILE *csv_fd) {
   int i,u;
   int aa,aarx,aatx;
   double channelx,channely;
@@ -177,19 +146,18 @@ void DL_channel(RU_t *ru,PHY_VARS_UE *UE,uint subframe,int awgn_flag,double SNR,
   for (i=0; i<2*UE->frame_parms.samples_per_tti; i++) {
     for (aa=0; aa<ru->frame_parms.nb_antennas_tx; aa++) {
       if (awgn_flag == 0) {
-	s_re[aa][i] = ((double)(((short *)ru->common.txdata[aa]))[(2*subframe*UE->frame_parms.samples_per_tti) + (i<<1)]);
-	s_im[aa][i] = ((double)(((short *)ru->common.txdata[aa]))[(2*subframe*UE->frame_parms.samples_per_tti) +(i<<1)+1]);
+        s_re[aa][i] = ((double)(((short *)ru->common.txdata[aa]))[(2*subframe*UE->frame_parms.samples_per_tti) + (i<<1)]);
+        s_im[aa][i] = ((double)(((short *)ru->common.txdata[aa]))[(2*subframe*UE->frame_parms.samples_per_tti) +(i<<1)+1]);
       } else {
-	for (aarx=0; aarx<UE->frame_parms.nb_antennas_rx; aarx++) {
-	  if (aa==0) {
-	    r_re[aarx][i] = ((double)(((short *)ru->common.txdata[aa]))[(2*subframe*UE->frame_parms.samples_per_tti) +(i<<1)]);
-	    r_im[aarx][i] = ((double)(((short *)ru->common.txdata[aa]))[(2*subframe*UE->frame_parms.samples_per_tti) +(i<<1)+1]);
-	  } else {
-	    r_re[aarx][i] += ((double)(((short *)ru->common.txdata[aa]))[(2*subframe*UE->frame_parms.samples_per_tti) +(i<<1)]);
-	    r_im[aarx][i] += ((double)(((short *)ru->common.txdata[aa]))[(2*subframe*UE->frame_parms.samples_per_tti) +(i<<1)+1]);
-	  }
-
-	}
+        for (aarx=0; aarx<UE->frame_parms.nb_antennas_rx; aarx++) {
+          if (aa==0) {
+            r_re[aarx][i] = ((double)(((short *)ru->common.txdata[aa]))[(2*subframe*UE->frame_parms.samples_per_tti) +(i<<1)]);
+            r_im[aarx][i] = ((double)(((short *)ru->common.txdata[aa]))[(2*subframe*UE->frame_parms.samples_per_tti) +(i<<1)+1]);
+          } else {
+            r_re[aarx][i] += ((double)(((short *)ru->common.txdata[aa]))[(2*subframe*UE->frame_parms.samples_per_tti) +(i<<1)]);
+            r_im[aarx][i] += ((double)(((short *)ru->common.txdata[aa]))[(2*subframe*UE->frame_parms.samples_per_tti) +(i<<1)+1]);
+          }
+        }
       }
     }
   }
@@ -197,27 +165,26 @@ void DL_channel(RU_t *ru,PHY_VARS_UE *UE,uint subframe,int awgn_flag,double SNR,
   // Multipath channel
   if (awgn_flag == 0) {
     multipath_channel(eNB2UE[round],s_re,s_im,r_re,r_im,
-		      2*UE->frame_parms.samples_per_tti,hold_channel);
+                      2*UE->frame_parms.samples_per_tti,hold_channel);
 
     //      printf("amc: ****************** eNB2UE[%d]->n_rx = %d,dd %d\n",round,eNB2UE[round]->nb_rx,eNB2UE[round]->channel_offset);
     if(abstx==1 && num_rounds>1)
       if(round==0 && hold_channel==0) {
-	random_channel(eNB2UE[1],0);
-	random_channel(eNB2UE[2],0);
-	random_channel(eNB2UE[3],0);
+        random_channel(eNB2UE[1],0);
+        random_channel(eNB2UE[2],0);
+        random_channel(eNB2UE[3],0);
       }
 
     if (UE->perfect_ce==1) {
       // fill in perfect channel estimates
       freq_channel(eNB2UE[round],UE->frame_parms.N_RB_DL,12*UE->frame_parms.N_RB_DL + 1);
       /*
-	LOG_M("channel.m","ch",eNB2UE[round]->ch[0],eNB2UE[round]->channel_length,1,8);
-	LOG_M("channelF.m","chF",eNB2UE[round]->chF[0],12*UE->frame_parms.N_RB_DL + 1,1,8);
+      LOG_M("channel.m","ch",eNB2UE[round]->ch[0],eNB2UE[round]->channel_length,1,8);
+      LOG_M("channelF.m","chF",eNB2UE[round]->chF[0],12*UE->frame_parms.N_RB_DL + 1,1,8);
       */
     }
   }
 
-
   if(abstx) {
     if (trials==0 && round==0) {
       // calculate freq domain representation to compute SINR
@@ -226,51 +193,51 @@ void DL_channel(RU_t *ru,PHY_VARS_UE *UE,uint subframe,int awgn_flag,double SNR,
       fprintf(csv_fd,"%f,",SNR);
 
       for (u=0; u<2*ru->frame_parms.N_RB_DL; u++) {
-	for (aarx=0; aarx<eNB2UE[0]->nb_rx; aarx++) {
-	  for (aatx=0; aatx<eNB2UE[0]->nb_tx; aatx++) {
-	    channelx = eNB2UE[0]->chF[aarx+(aatx*eNB2UE[0]->nb_rx)][u].x;
-	    channely = eNB2UE[0]->chF[aarx+(aatx*eNB2UE[0]->nb_rx)][u].y;
-	    fprintf(csv_fd,"%e+i*(%e),",channelx,channely);
-	  }
-	}
+        for (aarx=0; aarx<eNB2UE[0]->nb_rx; aarx++) {
+          for (aatx=0; aatx<eNB2UE[0]->nb_tx; aatx++) {
+            channelx = eNB2UE[0]->chF[aarx+(aatx*eNB2UE[0]->nb_rx)][u].x;
+            channely = eNB2UE[0]->chF[aarx+(aatx*eNB2UE[0]->nb_rx)][u].y;
+            fprintf(csv_fd,"%e+i*(%e),",channelx,channely);
+          }
+        }
       }
 
       if(num_rounds>1) {
-	freq_channel(eNB2UE[1], ru->frame_parms.N_RB_DL,2*ru->frame_parms.N_RB_DL + 1);
-
-	for (u=0; u<2*ru->frame_parms.N_RB_DL; u++) {
-	  for (aarx=0; aarx<eNB2UE[1]->nb_rx; aarx++) {
-	    for (aatx=0; aatx<eNB2UE[1]->nb_tx; aatx++) {
-	      channelx = eNB2UE[1]->chF[aarx+(aatx*eNB2UE[1]->nb_rx)][u].x;
-	      channely = eNB2UE[1]->chF[aarx+(aatx*eNB2UE[1]->nb_rx)][u].y;
-	      fprintf(csv_fd,"%e+i*(%e),",channelx,channely);
-	    }
-	  }
-	}
+        freq_channel(eNB2UE[1], ru->frame_parms.N_RB_DL,2*ru->frame_parms.N_RB_DL + 1);
+
+        for (u=0; u<2*ru->frame_parms.N_RB_DL; u++) {
+          for (aarx=0; aarx<eNB2UE[1]->nb_rx; aarx++) {
+            for (aatx=0; aatx<eNB2UE[1]->nb_tx; aatx++) {
+              channelx = eNB2UE[1]->chF[aarx+(aatx*eNB2UE[1]->nb_rx)][u].x;
+              channely = eNB2UE[1]->chF[aarx+(aatx*eNB2UE[1]->nb_rx)][u].y;
+              fprintf(csv_fd,"%e+i*(%e),",channelx,channely);
+            }
+          }
+        }
 
-	freq_channel(eNB2UE[2], ru->frame_parms.N_RB_DL,2*ru->frame_parms.N_RB_DL + 1);
+        freq_channel(eNB2UE[2], ru->frame_parms.N_RB_DL,2*ru->frame_parms.N_RB_DL + 1);
 
-	for (u=0; u<2*ru->frame_parms.N_RB_DL; u++) {
-	  for (aarx=0; aarx<eNB2UE[2]->nb_rx; aarx++) {
-	    for (aatx=0; aatx<eNB2UE[2]->nb_tx; aatx++) {
-	      channelx = eNB2UE[2]->chF[aarx+(aatx*eNB2UE[2]->nb_rx)][u].x;
-	      channely = eNB2UE[2]->chF[aarx+(aatx*eNB2UE[2]->nb_rx)][u].y;
-	      fprintf(csv_fd,"%e+i*(%e),",channelx,channely);
-	    }
-	  }
-	}
+        for (u=0; u<2*ru->frame_parms.N_RB_DL; u++) {
+          for (aarx=0; aarx<eNB2UE[2]->nb_rx; aarx++) {
+            for (aatx=0; aatx<eNB2UE[2]->nb_tx; aatx++) {
+              channelx = eNB2UE[2]->chF[aarx+(aatx*eNB2UE[2]->nb_rx)][u].x;
+              channely = eNB2UE[2]->chF[aarx+(aatx*eNB2UE[2]->nb_rx)][u].y;
+              fprintf(csv_fd,"%e+i*(%e),",channelx,channely);
+            }
+          }
+        }
 
-	freq_channel(eNB2UE[3], ru->frame_parms.N_RB_DL,2*ru->frame_parms.N_RB_DL + 1);
+        freq_channel(eNB2UE[3], ru->frame_parms.N_RB_DL,2*ru->frame_parms.N_RB_DL + 1);
 
-	for (u=0; u<2*ru->frame_parms.N_RB_DL; u++) {
-	  for (aarx=0; aarx<eNB2UE[3]->nb_rx; aarx++) {
-	    for (aatx=0; aatx<eNB2UE[3]->nb_tx; aatx++) {
-	      channelx = eNB2UE[3]->chF[aarx+(aatx*eNB2UE[3]->nb_rx)][u].x;
-	      channely = eNB2UE[3]->chF[aarx+(aatx*eNB2UE[3]->nb_rx)][u].y;
-	      fprintf(csv_fd,"%e+i*(%e),",channelx,channely);
-	    }
-	  }
-	}
+        for (u=0; u<2*ru->frame_parms.N_RB_DL; u++) {
+          for (aarx=0; aarx<eNB2UE[3]->nb_rx; aarx++) {
+            for (aatx=0; aatx<eNB2UE[3]->nb_tx; aatx++) {
+              channelx = eNB2UE[3]->chF[aarx+(aatx*eNB2UE[3]->nb_rx)][u].x;
+              channely = eNB2UE[3]->chF[aarx+(aatx*eNB2UE[3]->nb_rx)][u].y;
+              fprintf(csv_fd,"%e+i*(%e),",channelx,channely);
+            }
+          }
+        }
       }
     }
   }
@@ -284,25 +251,23 @@ void DL_channel(RU_t *ru,PHY_VARS_UE *UE,uint subframe,int awgn_flag,double SNR,
   for (i=0; i<2*UE->frame_parms.samples_per_tti; i++) {
     for (aa=0; aa<UE->frame_parms.nb_antennas_rx; aa++) {
       //printf("s_re[0][%d]=> %f , r_re[0][%d]=> %f\n",i,s_re[aa][i],i,r_re[aa][i]);
-      ((short*) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti)+2*i] =
-	(short) (r_re[aa][i] + sqrt(sigma2/2)*gaussdouble(0.0,1.0));
-      ((short*) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti)+2*i+1] =
-	(short) (r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0));
+      ((short *) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti)+2*i] =
+        (short) (r_re[aa][i] + sqrt(sigma2/2)*gaussdouble(0.0,1.0));
+      ((short *) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti)+2*i+1] =
+        (short) (r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0));
     }
   }
 }
 
 uint16_t
 fill_tx_req(nfapi_tx_request_body_t *tx_req_body,
-	    uint16_t                absSF,
-	    uint16_t                pdu_length,
-	    uint16_t                pdu_index,
-	    uint8_t                 *pdu)
-{
+            uint16_t                absSF,
+            uint16_t                pdu_length,
+            uint16_t                pdu_index,
+            uint8_t                 *pdu) {
   nfapi_tx_request_pdu_t *TX_req = &tx_req_body->tx_pdu_list[tx_req_body->number_of_pdus];
   LOG_D(MAC, "Filling TX_req %d for pdu length %d\n",
-	tx_req_body->number_of_pdus, pdu_length);
-
+        tx_req_body->number_of_pdus, pdu_length);
   TX_req->pdu_length                 = pdu_length;
   TX_req->pdu_index                  = pdu_index;
   TX_req->num_segments               = 1;
@@ -310,40 +275,37 @@ fill_tx_req(nfapi_tx_request_body_t *tx_req_body,
   TX_req->segments[0].segment_data   = pdu;
   tx_req_body->tl.tag                = NFAPI_TX_REQUEST_BODY_TAG;
   tx_req_body->number_of_pdus++;
-
   return (((absSF / 10) << 4) + (absSF % 10));
 }
 
 void
-fill_dlsch_config(nfapi_dl_config_request_body_t * dl_req,
-		  uint16_t length,
-		  uint16_t pdu_index,
-		  uint16_t rnti,
-		  uint8_t resource_allocation_type,
-		  uint8_t virtual_resource_block_assignment_flag,
-		  uint16_t resource_block_coding,
-		  uint8_t modulation,
-		  uint8_t redundancy_version,
-		  uint8_t transport_blocks,
-		  uint8_t transport_block_to_codeword_swap_flag,
-		  uint8_t transmission_scheme,
-		  uint8_t number_of_layers,
-		  uint8_t number_of_subbands,
-		  //                             uint8_t codebook_index,
-		  uint8_t ue_category_capacity,
-		  uint8_t pa,
-		  uint8_t delta_power_offset_index,
-		  uint8_t ngap,
-		  uint8_t nprb,
-		  uint8_t transmission_mode,
-		  uint8_t num_bf_prb_per_subband,
-		  uint8_t num_bf_vector)
-{
+fill_dlsch_config(nfapi_dl_config_request_body_t *dl_req,
+                  uint16_t length,
+                  uint16_t pdu_index,
+                  uint16_t rnti,
+                  uint8_t resource_allocation_type,
+                  uint8_t virtual_resource_block_assignment_flag,
+                  uint16_t resource_block_coding,
+                  uint8_t modulation,
+                  uint8_t redundancy_version,
+                  uint8_t transport_blocks,
+                  uint8_t transport_block_to_codeword_swap_flag,
+                  uint8_t transmission_scheme,
+                  uint8_t number_of_layers,
+                  uint8_t number_of_subbands,
+                  //                             uint8_t codebook_index,
+                  uint8_t ue_category_capacity,
+                  uint8_t pa,
+                  uint8_t delta_power_offset_index,
+                  uint8_t ngap,
+                  uint8_t nprb,
+                  uint8_t transmission_mode,
+                  uint8_t num_bf_prb_per_subband,
+                  uint8_t num_bf_vector) {
   nfapi_dl_config_request_pdu_t *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));
-
+         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.tl.tag                                 = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL8_TAG;
@@ -369,225 +331,198 @@ fill_dlsch_config(nfapi_dl_config_request_body_t * dl_req,
   dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transmission_mode                      = transmission_mode;
   dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.num_bf_prb_per_subband                 = num_bf_prb_per_subband;
   dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.num_bf_vector                          = num_bf_vector;
+  dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.initial_transmission_sf_io            = 0xFFFF;
   dl_req->number_pdu++;
 }
 
 void fill_DCI(PHY_VARS_eNB *eNB,
-	      int frame,
-	      int subframe,
-	      Sched_Rsp_t *sched_resp,
-	      uint8_t input_buffer[NUMBER_OF_UE_MAX][20000],
-	      int n_rnti,
-	      int n_users,
-	      int transmission_mode,
-	      int retrans,
-	      int common_flag,
-	      int NB_RB,
-	      int DLSCH_RB_ALLOC,
-	      int TPC,
-	      int mcs1,
-	      int mcs2,
-	      int ndi,
-	      int rv,
-	      int pa,
-	      int *num_common_dci,
-	      int *num_ue_spec_dci,
-	      int *num_dci) {
-
+              int frame,
+              int subframe,
+              Sched_Rsp_t *sched_resp,
+              uint8_t input_buffer[NUMBER_OF_UE_MAX][20000],
+              int n_rnti,
+              int n_users,
+              int transmission_mode,
+              int retrans,
+              int common_flag,
+              int NB_RB,
+              int DLSCH_RB_ALLOC,
+              int TPC,
+              int mcs1,
+              int mcs2,
+              int ndi,
+              int rv,
+              int pa,
+              int *num_common_dci,
+              int *num_ue_spec_dci,
+              int *num_dci) {
   int k;
-
   nfapi_dl_config_request_body_t *dl_req=&sched_resp->DL_req->dl_config_request_body;
   nfapi_dl_config_request_pdu_t  *dl_config_pdu;
   nfapi_tx_request_body_t        *TX_req=&sched_resp->TX_req->tx_request_body;
-
+  int NB_RB4TBS = common_flag == 0 ? NB_RB : (2+TPC);
   dl_req->number_dci=0;
   dl_req->number_pdu=0;
   TX_req->number_of_pdus=0;
 
   for(k=0; k<n_users; k++) {
     switch(transmission_mode) {
-    case 1:
-
-    case 2:
-
-    case 7:
-      if (common_flag == 0) {
-
-	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 = 4;
-	dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL8_TAG;
-	dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti = n_rnti+k;
-	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 = 0;
-	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 = ndi;
-	dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1 = mcs1;
-	dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_1 = rv;
-	dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.resource_block_coding = DLSCH_RB_ALLOC;
-	//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_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.downlink_assignment_index = 0;
-	dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.cce_idx = 0;
-
-	dl_req->number_dci++;
-	dl_req->number_pdu++;
-	dl_req->tl.tag = NFAPI_DL_CONFIG_REQUEST_BODY_TAG;
-
-
-	fill_dlsch_config(dl_req,
-			  get_TBS_DL(mcs1,NB_RB),
-			  (retrans > 0) ? -1 : 0, /* retransmission, no pdu_index */
-			  n_rnti,
-			  0,	// type 0 allocation from 7.1.6 in 36.213
-			  0,	// virtual_resource_block_assignment_flag, unused here
-			  DLSCH_RB_ALLOC,	// resource_block_coding,
-			  get_Qm(mcs1),
-			  rv,	// redundancy version
-			  1,	// transport blocks
-			  0,	// transport block to codeword swap flag
-			  transmission_mode == 1 ? 0 : 1,	// transmission_scheme
-			  1,	// number of layers
-			  1,	// number of subbands
-				//                      uint8_t codebook_index,
-			  4,	// UE category capacity
-			  pa,    // pa
-			  0,	// delta_power_offset for TM5
-			  0,	// ngap
-			  0,	// nprb
-			  transmission_mode,
-			  0,	//number of PRBs treated as one subband, not used here
-			  0	// number of beamforming vectors, not used here
-			  );
-	fill_tx_req(TX_req,
-		    (frame * 10) + subframe,
-		    get_TBS_DL(mcs1,NB_RB),
-		    0,
-		    input_buffer[k]);
-      }
-      else {
-
-      }
-
-      break;
-
-    case 3:
-      if (common_flag == 0) {
-
-	if (eNB->frame_parms.nb_antennas_tx == 2) {
-
-	  if (eNB->frame_parms.frame_type == TDD) {
-
-	  }
-	  else {
-
-	  }
-	}
-      }
-      break;
-
-    case 4:
-      if (common_flag == 0) {
-
-	if (eNB->frame_parms.nb_antennas_tx == 2) {
-
-	  if (eNB->frame_parms.frame_type == TDD) {
-
-
-	  }
-
-	  else {
-
-	  }
-	} else if (eNB->frame_parms.nb_antennas_tx == 4) {
+      case 1:
+      case 2:
+      case 7:
+        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 = (common_flag == 0) ? NFAPI_DL_DCI_FORMAT_1 : NFAPI_DL_DCI_FORMAT_1A;
+        dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level = 4;
+        dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL8_TAG;
+        dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti = (common_flag == 0) ? n_rnti+k : SI_RNTI;
+        dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type = (common_flag ==0 ) ? 1: 2;  // 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 = 0;
+        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 = (common_flag == 0) ? ndi : 0;
+        dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1 = mcs1;
+        dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_1 = rv;
+        dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.resource_block_coding = (common_flag == 0) ? DLSCH_RB_ALLOC : computeRIV(eNB->frame_parms.N_RB_DL,0,NB_RB);
+        //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_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.downlink_assignment_index = 0;
+        dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.cce_idx = 0;
+        dl_req->number_dci++;
+        dl_req->number_pdu++;
+        dl_req->tl.tag = NFAPI_DL_CONFIG_REQUEST_BODY_TAG;
+        AssertFatal(TPC>=0 && TPC<2, "TPC should be 0 or 1\n");
+        fill_dlsch_config(dl_req,
+                          get_TBS_DL(mcs1,NB_RB4TBS),
+                          (retrans > 0) ? -1 : 0, /* retransmission, no pdu_index */
+                          (common_flag == 0) ? n_rnti : SI_RNTI,
+                          0,  // type 0 allocation from 7.1.6 in 36.213
+                          0,  // virtual_resource_block_assignment_flag, unused here
+                          DLSCH_RB_ALLOC, // resource_block_coding,
+                          get_Qm(mcs1),
+                          rv, // redundancy version
+                          1,  // transport blocks
+                          0,  // transport block to codeword swap flag
+                          transmission_mode == 1 ? 0 : 1, // transmission_scheme
+                          1,  // number of layers
+                          1,  // number of subbands
+                          //                      uint8_t codebook_index,
+                          4,  // UE category capacity
+                          pa,    // pa
+                          0,  // delta_power_offset for TM5
+                          0,  // ngap
+                          0,  // nprb
+                          transmission_mode,
+                          0,  //number of PRBs treated as one subband, not used here
+                          0 // number of beamforming vectors, not used here
+                         );
+        fill_tx_req(TX_req,
+                    (frame * 10) + subframe,
+                    get_TBS_DL(mcs1,NB_RB4TBS),
+                    0,
+                    input_buffer[k]);
+        break;
 
-	}
+      case 3:
+        if (common_flag == 0) {
+          if (eNB->frame_parms.nb_antennas_tx == 2) {
+            if (eNB->frame_parms.frame_type == TDD) {
+            } else {
+            }
+          }
+        }
 
-      }
-      else {
+        break;
 
+      case 4:
+        if (common_flag == 0) {
+          if (eNB->frame_parms.nb_antennas_tx == 2) {
+            if (eNB->frame_parms.frame_type == TDD) {
+            } else {
+            }
+          } else if (eNB->frame_parms.nb_antennas_tx == 4) {
+          }
+        } else {
         }
 
         break;
 
       case 5:
       case 6:
-
         break;
 
-    default:
-      printf("Unsupported Transmission Mode %d!!!\n",transmission_mode);
-      exit(-1);
-      break;
+      default:
+        printf("Unsupported Transmission Mode %d!!!\n",transmission_mode);
+        exit(-1);
+        break;
     }
   }
+
   *num_dci         = dl_req->number_dci;
   *num_ue_spec_dci = dl_req->number_dci;
   *num_common_dci  = 0;
 }
 
 int n_users = 1;
-sub_frame_t subframe=7;
+int subframe=7;
 int num_common_dci=0,num_ue_spec_dci=0,num_dci=0,num_pdcch_symbols=1;
 uint16_t n_rnti=0x1234;
-  int nfapi_mode=0;
-
-int main(int argc, char **argv)
-{
-
-  int c;
+int nfapi_mode=0;
+int abstx=0;
+int Nid_cell=0;
+int N_RB_DL=25;
+int tdd_config=3;
+int dci_flag=0;
+int threequarter_fs=0;
+double snr_step=1,input_snr_step=1, snr_int=30;
+double forgetting_factor=0.0; //in [0,1] 0 means a new channel every time, 1 means keep the same channel
+int test_perf=0;
+int n_frames;
+int n_ch_rlz = 1;
+int rx_sample_offset = 0;
+int xforms=0;
+int dump_table=0;
+int loglvl=OAILOG_WARNING;
+int mcs1=0,mcs2=0,mcs_i=0,dual_stream_UE = 0,awgn_flag=0;
+int two_thread_flag=0;
+int num_rounds = 4;//,fix_rounds=0;
+int perfect_ce = 0;
+int extended_prefix_flag=0;
+int verbose=0, help=0;
+double SNR,snr0=-2.0,snr1,rate = 0;
+int print_perf=0;
+
+int main(int argc, char **argv) {
   int k,i,j,aa;
   int re;
-  int loglvl=OAILOG_DEBUG;
-
   int s,Kr,Kr_bytes;
-
-  double SNR,snr0=-2.0,snr1,rate = 0;
-  double snr_step=1,input_snr_step=1, snr_int=30;
-
   LTE_DL_FRAME_PARMS *frame_parms;
   double s_re0[30720*2],s_im0[30720*2],r_re0[30720*2],r_im0[30720*2];
   double s_re1[30720*2],s_im1[30720*2],r_re1[30720*2],r_im1[30720*2];
-  double *s_re[2]={s_re0,s_re1};
-  double *s_im[2]={s_im0,s_im1};
-  double *r_re[2]={r_re0,r_re1};
-  double *r_im[2]={r_im0,r_im1};
-  double forgetting_factor=0.0; //in [0,1] 0 means a new channel every time, 1 means keep the same channel
-
-
-  uint8_t extended_prefix_flag=0,transmission_mode=1,n_tx_port=1,n_tx_phy=1,n_rx=2;
-  uint16_t Nid_cell=0;
-
+  double *s_re[2]= {s_re0,s_re1};
+  double *s_im[2]= {s_im0,s_im1};
+  double *r_re[2]= {r_re0,r_re1};
+  double *r_im[2]= {r_im0,r_im1};
+  uint8_t transmission_mode=1,n_tx_port=1,n_tx_phy=1,n_rx=2;
   int eNB_id = 0;
-  unsigned char mcs1=0,mcs2=0,mcs_i=0,dual_stream_UE = 0,awgn_flag=0,round;
+  unsigned char round;
   unsigned char i_mod = 2;
-  unsigned short NB_RB;
-  uint16_t tdd_config=3;
-
-
+  int NB_RB;
   SCM_t channel_model=Rayleigh1;
   //  unsigned char *input_data,*decoded_output;
-
   DCI_ALLOC_t da;
   DCI_ALLOC_t *dci_alloc = &da;
-
   unsigned int coded_bits_per_codeword=0,nsymb; //,tbs=0;
-
   unsigned int tx_lev=0,tx_lev_dB=0,trials;
   unsigned int errs[4],errs2[4],round_trials[4],dci_errors[4];//,num_layers;
   memset(errs,0,4*sizeof(unsigned int));
   memset(errs2,0,4*sizeof(unsigned int));
   memset(round_trials,0,4*sizeof(unsigned int));
   memset(dci_errors,0,4*sizeof(unsigned int));
-
   //int re_allocated;
   char fname[32],vname[32];
   FILE *bler_fd;
@@ -596,87 +531,56 @@ int main(int argc, char **argv)
   char time_meas_fname[256];
   //  FILE *tikz_fd;
   //  char tikz_fname[256];
-
   FILE *input_trch_fd=NULL;
   unsigned char input_trch_file=0;
   FILE *input_fd=NULL;
   unsigned char input_file=0;
-
-  int n_frames;
-  int n_ch_rlz = 1;
   channel_desc_t *eNB2UE[4];
   //uint8_t num_pdcch_symbols_2=0;
-  uint8_t rx_sample_offset = 0;
   //char stats_buffer[4096];
   //int len;
-  uint8_t num_rounds = 4;//,fix_rounds=0;
-
   //int u;
   int n=0;
-  int abstx=0;
   //int iii;
-
   int ch_realization;
   //int pmi_feedback=0;
   int hold_channel=0;
-
   // void *data;
   // int ii;
   //  int bler;
   double blerr[4];
   short *uncoded_ber_bit=NULL;
-  uint8_t N_RB_DL=25,osf=1;
+  int osf=1;
   frame_t frame_type = FDD;
-  int xforms=0;
   FD_lte_phy_scope_ue *form_ue = NULL;
   char title[255];
-
   int numCCE=0;
   //int dci_length_bytes=0,dci_length=0;
   //double channel_bandwidth = 5.0, sampling_rate=7.68;
   int common_flag=0,TPC=0;
-
   double cpu_freq_GHz;
   //  time_stats_t ts;//,sts,usts;
   int avg_iter,iter_trials;
   int rballocset=0;
-  int print_perf=0;
-  int test_perf=0;
   int test_passed=0;
-  int dump_table=0;
-
   double effective_rate=0.0;
   char channel_model_input[10]="I";
-
   int TB0_active = 1;
-  uint32_t perfect_ce = 0;
-
   //  LTE_DL_UE_HARQ_t *dlsch0_ue_harq;
   //  LTE_DL_eNB_HARQ_t *dlsch0_eNB_harq;
   uint8_t Kmimo;
   uint8_t ue_category=4;
   uint32_t Nsoft;
   int sf;
-
-
-
   int CCE_table[800];
-
-  int threequarter_fs=0;
-
-
   opp_enabled=1; // to enable the time meas
-
   FILE *csv_fd=NULL;
-  char csv_fname[32];
-  int dci_flag=0;
-  int two_thread_flag=0;
+  char csv_fname[FILENAME_MAX];
   int DLSCH_RB_ALLOC = 0;
-
   int dci_received;
   PHY_VARS_eNB *eNB;
   RU_t *ru;
-  PHY_VARS_UE *UE;
+  PHY_VARS_UE *UE=NULL;
   nfapi_dl_config_request_t DL_req;
   nfapi_ul_config_request_t UL_req;
   nfapi_hi_dci0_request_t HI_DCI0_req;
@@ -685,425 +589,354 @@ int main(int argc, char **argv)
   nfapi_tx_request_t TX_req;
   Sched_Rsp_t sched_resp;
   int pa=dB0;
-
 #if defined(__arm__)
   FILE    *proc_fd = NULL;
   char buf[64];
-
+  memset(buf,0,sizeof(buf));
   proc_fd = fopen("/sys/devices/system/cpu/cpu4/cpufreq/cpuinfo_cur_freq", "r");
+
   if(!proc_fd)
-     printf("cannot open /sys/devices/system/cpu/cpu4/cpufreq/cpuinfo_cur_freq");
+    printf("cannot open /sys/devices/system/cpu/cpu4/cpufreq/cpuinfo_cur_freq");
   else {
-     while(fgets(buf, 63, proc_fd))
-        printf("%s", buf);
+    while(fgets(buf, 63, proc_fd))
+      printf("%s", buf);
   }
+
   fclose(proc_fd);
   cpu_freq_GHz = ((double)atof(buf))/1e6;
 #else
   cpu_freq_GHz = get_cpu_freq_GHz();
 #endif
   printf("Detected cpu_freq %f GHz\n",cpu_freq_GHz);
-  memset((void*)&sched_resp,0,sizeof(sched_resp));
+  memset((void *)&sched_resp,0,sizeof(sched_resp));
   sched_resp.DL_req = &DL_req;
   sched_resp.UL_req = &UL_req;
   sched_resp.HI_DCI0_req = &HI_DCI0_req;
   sched_resp.TX_req = &TX_req;
-  memset((void*)&DL_req,0,sizeof(DL_req));
-  memset((void*)&UL_req,0,sizeof(UL_req));
-  memset((void*)&HI_DCI0_req,0,sizeof(HI_DCI0_req));
-  memset((void*)&TX_req,0,sizeof(TX_req));
-
+  memset((void *)&DL_req,0,sizeof(DL_req));
+  memset((void *)&UL_req,0,sizeof(UL_req));
+  memset((void *)&HI_DCI0_req,0,sizeof(HI_DCI0_req));
+  memset((void *)&TX_req,0,sizeof(TX_req));
   DL_req.dl_config_request_body.dl_config_pdu_list = dl_config_pdu_list;
   TX_req.tx_request_body.tx_pdu_list = tx_pdu_list;
-
+  set_parallel_conf("PARALLEL_SINGLE_THREAD");
   cpuf = cpu_freq_GHz;
-
   //signal(SIGSEGV, handler);
   //signal(SIGABRT, handler);
-
   // default parameters
   n_frames = 1000;
   snr0 = 0;
   //  num_layers = 1;
   perfect_ce = 0;
+  static paramdef_t options[] = {
+    { "awgn", "Use AWGN channel and not multipath", PARAMFLAG_BOOL, strptr:NULL, defintval:0, TYPE_INT, 0, NULL, NULL },
+    { "Abstx", "Turns on calibration mode for abstraction.", PARAMFLAG_BOOL, iptr:&abstx,  defintval:0, TYPE_INT, 0 },
+    { "bTDD", "Set the tdd configuration mode",0, iptr:&tdd_config,  defintval:3, TYPE_INT, 0 },
+    { "BnbRBs", "The LTE bandwith in RBs (100 is 20MHz)",0, iptr:&N_RB_DL,  defintval:25, TYPE_INT, 0 },
+    { "cPdcch", "Number of PDCCH symbols",0, iptr:&num_pdcch_symbols,  defintval:1, TYPE_INT, 0 },
+    { "CnidCell", "The cell id ",0, iptr:&Nid_cell,  defintval:0, TYPE_INT, 0 },
+    { "dciFlag", "Transmit the DCI and compute its error statistics", PARAMFLAG_BOOL, iptr:&dci_flag,  defintval:0, TYPE_INT, 0 },
+    { "Dtdd", "Enable tdd", PARAMFLAG_BOOL,  strptr:NULL, defintval:0, TYPE_INT, 0, NULL, NULL },
+    { "eRounds", "Number of rounds",0, iptr:NULL,  defintval:25, TYPE_INT, 0 },
+    { "EsubSampling","three quarters sub-sampling",PARAMFLAG_BOOL, iptr:&threequarter_fs, defintval:0, TYPE_INT, 0 },
+    { "f_snr_step", "step size of SNR, default value is 1.",0, dblptr:&input_snr_step,  defdblval:1, TYPE_DOUBLE, 0 },
+    { "Forgetting", "forgetting factor (0 new channel every trial, 1 channel constant)",0, dblptr:&forgetting_factor,  defdblval:0.0, TYPE_DOUBLE, 0 },
+    { "input_file", "input IQ data file",0, iptr:NULL,  defintval:0, TYPE_INT, 0 },
+    { "Input_file_trch", " Input filename for TrCH data (binary)",0, iptr:NULL,  defintval:0, TYPE_INT, 0 },
+    { "WtwoThreads", "two_thread_flag", PARAMFLAG_BOOL, iptr:&two_thread_flag,  defintval:0, TYPE_INT, 0 },
+    { "lMuMimo", "offset_mumimo_llr_drange_fix",0, u8ptr:&offset_mumimo_llr_drange_fix,  defintval:0, TYPE_UINT8, 0 },
+    { "mcs1", "The MCS for TB 1", 0, iptr:&mcs1,  defintval:0, TYPE_INT, 0 },
+    { "Mcs2", "The MCS for TB 2", 0, iptr:&mcs2,  defintval:0, TYPE_INT, 0 },
+    { "Operf", "Set the percenatge of effective rate to testbench the modem performance (typically 30 and 70, range 1-100)",0, iptr:&test_perf,  defintval:0, TYPE_INT, 0 },
+    { "tmcs_i", "MCS of interfering UE",0, iptr:NULL,  defintval:0, TYPE_INT, 0 },
+    { "nb_frame", "number of frame in a test",0, iptr:&n_frames,  defintval:1, TYPE_INT, 0 },
+    { "offsetRxSample", "Sample offset for receiver", 0, iptr:&rx_sample_offset,  defintval:0, TYPE_INT, 0 },
+    { "rballocset", "ressource block allocation (see  section 7.1.6.3 in 36.213)",0, iptr:NULL,  defintval:0, TYPE_INT, 0 },
+    { "snr", "Starting SNR, runs from SNR to SNR+%.1fdB in steps of %.1fdB. If n_frames is 1 then just SNR is simulated and MATLAB/OCTAVE output is generated", dblptr:&snr0,  defdblval:-2.0, TYPE_DOUBLE, 0 },
+    { "wsnrInterrupt", "snr int ?", 0, dblptr:&snr_int,  defdblval:30, TYPE_DOUBLE, 0 },
+    { "N_ch_rlzN0", "Determines the number of Channel Realizations in Abstraction mode. Default value is 1",0, iptr:&n_ch_rlz,  defintval:1, TYPE_INT, 0 },
+    { "prefix_extended","Enable extended prefix", PARAMFLAG_BOOL, iptr:&extended_prefix_flag,  defintval:0, TYPE_INT, 0 },
+    { "RNumRound", "Number of HARQ rounds (fixed)",0, iptr:&num_rounds,  defintval:4, TYPE_INT, 0 },
+    { "Subframe", "subframe ",0, iptr:&subframe,  defintval:7, TYPE_INT, 0 },
+    { "Trnti", "rnti",0, u16ptr:&n_rnti,  defuintval:0x1234, TYPE_UINT16, 0 },
+    { "vi_mod", "i_mod",0, iptr:NULL,  defintval:0, TYPE_INT, 0 },
+    { "Qparallel", "Enable parallel execution",0, strptr:NULL,  defstrval:NULL, TYPE_STRING,  0 },
+    { "Performance", "Display CPU perfomance of each L1 piece", PARAMFLAG_BOOL,  iptr:&print_perf,  defintval:0, TYPE_INT, 0 },
+    { "q_tx_port", "Number of TX antennas ports used in eNB",0, iptr:NULL,  defintval:0, TYPE_INT, 0 },
+    { "uEdual", "Enables the Interference Aware Receiver for TM5 (default is normal receiver)",0, iptr:NULL,  defintval:0, TYPE_INT, 0 },
+    { "xTransmission","Transmission mode (1,2,6,7 for the moment)",0, iptr:NULL,  defintval:25, TYPE_INT, 0 },
+    { "yn_tx_phy","Number of TX antennas used in eNB",0, iptr:NULL,  defintval:25, TYPE_INT, 0 },
+    { "XForms", "Display the soft scope", PARAMFLAG_BOOL, iptr:&xforms,  defintval:0, TYPE_INT, 0 },
+    { "Yperfect_ce","Perfect CE", PARAMFLAG_BOOL, iptr:&perfect_ce,  defintval:0, TYPE_INT, 0 },
+    { "Zdump", "dump table",PARAMFLAG_BOOL,  iptr:&dump_table, defintval:0, TYPE_INT, 0 },
+    { "Loglvl", "log level",0, iptr:&loglvl,  defintval:OAILOG_DEBUG, TYPE_INT, 0 },
+    { "zn_rx", "Number of RX antennas used in UE",0, iptr:NULL,  defintval:2, TYPE_INT, 0 },
+    { "gchannel", "[A:M] Use 3GPP 25.814 SCM-A/B/C/D('A','B','C','D') or 36-101 EPA('E'), EVA ('F'),ETU('G') models (ignores delay spread and Ricean factor), Rayghleigh8 ('H'), Rayleigh1('I'), Rayleigh1_corr('J'), Rayleigh1_anticorr ('K'),  Rice8('L'), Rice1('M')",0, strptr:NULL,  defstrval:NULL, TYPE_STRING, 0 },
+    { "verbose", "display debug text", PARAMFLAG_BOOL,  iptr:&verbose, defintval:0, TYPE_INT, 0 },
+    { "help", "display help and exit", PARAMFLAG_BOOL,  iptr:&help, defintval:0, TYPE_INT, 0 },
+    { "", "",0,  iptr:NULL, defintval:0, TYPE_INT, 0 },
+  };
+  struct option *long_options = parse_oai_options(options);
+  int option_index;
+  int res;
+
+  while ((res=getopt_long_only(argc, argv, "", long_options, &option_index)) == 0) {
+    if (options[option_index].voidptr != NULL ) {
+      if (long_options[option_index].has_arg==no_argument)
+        *(bool *)options[option_index].iptr=1;
+      else switch (options[option_index].type) {
+          case TYPE_INT:
+            *(int *)options[option_index].iptr=atoi(optarg);
+            break;
+
+          case TYPE_DOUBLE:
+            *(double *)options[option_index].dblptr=atof(optarg);
+            break;
+
+          case TYPE_UINT8:
+            *(uint8_t *)options[option_index].dblptr=atoi(optarg);
+            break;
+
+          case TYPE_UINT16:
+            *(uint16_t *)options[option_index].dblptr=atoi(optarg);
+            break;
+
+          default:
+            printf("not decoded type.\n");
+            exit(1);
+        }
 
-  while ((c = getopt (argc, argv, "ahdpZDe:Em:n:o:s:f:t:c:g:r:F:x:q:y:z:AM:N:I:i:O:R:S:C:T:b:u:v:w:B:Pl:WXYL:")) != -1) {
-    switch (c) {
-    case 'a':
-      awgn_flag = 1;
-      channel_model = AWGN;
-      break;
-
-    case 'A':
-      abstx = 1;
-      break;
-
-    case 'b':
-      tdd_config=atoi(optarg);
-      break;
-
-    case 'B':
-      N_RB_DL=atoi(optarg);
-      break;
-
-    case 'c':
-      num_pdcch_symbols=atoi(optarg);
-      break;
-
-    case 'C':
-      Nid_cell = atoi(optarg);
-      break;
-
-    case 'd':
-      dci_flag = 1;
-      break;
-
-    case 'D':
-      frame_type=TDD;
-      break;
-
-    case 'e':
-      num_rounds=1;
-      common_flag = 1;
-      TPC = atoi(optarg);
-      break;
-
-    case 'E':
-      threequarter_fs=1;
-      break;
-
-    case 'f':
-      input_snr_step= atof(optarg);
-      break;
-
-    case 'F':
-      forgetting_factor = atof(optarg);
-      break;
-
-    case 'i':
-      input_fd = fopen(optarg,"r");
-      input_file=1;
-      dci_flag = 1;
-      break;
-
-    case 'I':
-      input_trch_fd = fopen(optarg,"r");
-      input_trch_file=1;
-      break;
-
-    case 'W':
-      two_thread_flag = 1;
-      break;
-    case 'l':
-      offset_mumimo_llr_drange_fix=atoi(optarg);
-      break;
-
-    case 'm':
-      mcs1 = atoi(optarg);
-      break;
-
-    case 'M':
-      mcs2 = atoi(optarg);
-      break;
-
-    case 'O':
-      test_perf=atoi(optarg);
-      //print_perf =1;
-      break;
-
-    case 't':
-      mcs_i = atoi(optarg);
-      i_mod = get_Qm(mcs_i);
-      break;
-
-    case 'n':
-      n_frames = atoi(optarg);
-      break;
-
-
-    case 'o':
-      rx_sample_offset = atoi(optarg);
-      break;
-
-    case 'r':
-      DLSCH_RB_ALLOC = atoi(optarg);
-      rballocset = 1;
-      break;
-
-    case 's':
-      snr0 = atof(optarg);
-      break;
-
-    case 'w':
-      snr_int = atof(optarg);
-      break;
-
-
-    case 'N':
-      n_ch_rlz= atof(optarg);
-      break;
-
-    case 'p':
-      extended_prefix_flag=1;
-      break;
-
-    case 'g':
-      memcpy(channel_model_input,optarg,10);
-
-      switch((char)*optarg) {
-      case 'A':
-        channel_model=SCM_A;
-        break;
-
-      case 'B':
-        channel_model=SCM_B;
-        break;
+      continue;
+    }
 
-      case 'C':
-        channel_model=SCM_C;
+    switch (long_options[option_index].name[0]) {
+      case 'a':
+        awgn_flag = 1;
+        channel_model = AWGN;
         break;
 
       case 'D':
-        channel_model=SCM_D;
-        break;
-
-      case 'E':
-        channel_model=EPA;
-        break;
-
-      case 'F':
-        channel_model=EVA;
+        frame_type=TDD;
         break;
 
-      case 'G':
-        channel_model=ETU;
+      case 'e':
+        num_rounds=1;
+        common_flag = 1;
+        TPC = atoi(optarg);
         break;
 
-      case 'H':
-        channel_model=Rayleigh8;
+      case 'i':
+        input_fd = fopen(optarg,"r");
+        input_file=1;
+        dci_flag = 1;
         break;
 
       case 'I':
-        channel_model=Rayleigh1;
+        input_trch_fd = fopen(optarg,"r");
+        input_trch_file=1;
         break;
 
-      case 'J':
-        channel_model=Rayleigh1_corr;
+      case 't':
+        mcs_i = atoi(optarg);
+        i_mod = get_Qm(mcs_i);
         break;
 
-      case 'K':
-        channel_model=Rayleigh1_anticorr;
+      case 'r':
+        DLSCH_RB_ALLOC = atoi(optarg);
+        rballocset = 1;
         break;
 
-      case 'L':
-        channel_model=Rice8;
-        break;
+      case 'g':
+        strncpy(channel_model_input,optarg,9);
+        struct tmp {
+          char opt;
+          int m;
+          int M;
+        }
+        tmp[]= {
+          {'A',SCM_A,2},
+          {'B',SCM_B,3},
+          {'C',SCM_C,4},
+          {'D',SCM_D,5},
+          {'E',EPA,6},
+          {'F',EVA,6},
+          {'G',ETU,8},
+          {'H',Rayleigh8,9},
+          {'I',Rayleigh1,10},
+          {'J',Rayleigh1_corr,11},
+          {'K',Rayleigh1_anticorr,12},
+          {'L',Rice8,13},
+          {'M',Rice1,14},
+          {'N',AWGN,1},
+          {0,0,0}
+        };
+        struct tmp *ptr;
+
+        for (ptr=tmp; ptr->opt!=0; ptr++)
+          if ( ptr->opt == optarg[0] ) {
+            channel_model=ptr->m;
+            break;
+          }
 
-      case 'M':
-        channel_model=Rice1;
+        AssertFatal(ptr->opt != 0, "Unsupported channel model: %s !\n", optarg );
         break;
 
-      case 'N':
-        channel_model=AWGN;
-        break;
-      default:
-        printf("Unsupported channel model!\n");
-        exit(-1);
-      }
-
-      break;
-    case 'R':
-      num_rounds=atoi(optarg);
-      break;
-
-    case 'S':
-      subframe=atoi(optarg);
-      break;
-
-    case 'T':
-      n_rnti=atoi(optarg);
-      break;
-
-    case 'u':
-      dual_stream_UE=1;
-      UE->use_ia_receiver = 1;
-
-      if ((n_tx_port!=2) || (transmission_mode!=5)) {
-        printf("IA receiver only supported for TM5!");
-        exit(-1);
-      }
-
-      break;
-
-    case 'v':
-      i_mod = atoi(optarg);
+      case 'u':
+        dual_stream_UE=1;
+	if (UE != NULL)
+           UE->use_ia_receiver = 1;
+        else {
+          printf("UE  is NULL\n");
+          exit(-1);
+	}
+        if ((n_tx_port!=2) || (transmission_mode!=5)) {
+          printf("IA receiver only supported for TM5!");
+          exit(-1);
+        }
 
-      if (i_mod!=2 && i_mod!=4 && i_mod!=6) {
-        printf("Wrong i_mod %d, should be 2,4 or 6\n",i_mod);
-        exit(-1);
-      }
+        break;
 
-      break;
+      case 'v':
+        i_mod = atoi(optarg);
 
-    case 'P':
-      print_perf=1;
-      break;
+        if (i_mod!=2 && i_mod!=4 && i_mod!=6) {
+          printf("Wrong i_mod %d, should be 2,4 or 6\n",i_mod);
+          exit(-1);
+        }
 
-    case 'q':
-      n_tx_port=atoi(optarg);
+        break;
 
-      if ((n_tx_port==0) || ((n_tx_port>2))) {
-        printf("Unsupported number of cell specific antennas ports %d\n",n_tx_port);
-        exit(-1);
-      }
+      case 'q':
+        n_tx_port=atoi(optarg);
 
-      break;
+        if ((n_tx_port==0) || ((n_tx_port>2))) {
+          printf("Unsupported number of cell specific antennas ports %d\n",n_tx_port);
+          exit(-1);
+        }
 
+        break;
 
-    case 'x':
-      transmission_mode=atoi(optarg);
+      case 'x':
+        transmission_mode=atoi(optarg);
+
+        if ((transmission_mode!=1) &&
+            (transmission_mode!=2) &&
+            (transmission_mode!=3) &&
+            (transmission_mode!=4) &&
+            (transmission_mode!=5) &&
+            (transmission_mode!=6) &&
+            (transmission_mode!=7)) {
+          printf("Unsupported transmission mode %d\n",transmission_mode);
+          exit(-1);
+        }
 
-      if ((transmission_mode!=1) &&
-          (transmission_mode!=2) &&
-          (transmission_mode!=3) &&
-          (transmission_mode!=4) &&
-          (transmission_mode!=5) &&
-          (transmission_mode!=6) &&
-          (transmission_mode!=7)) {
-        printf("Unsupported transmission mode %d\n",transmission_mode);
-        exit(-1);
-      }
+        if (transmission_mode>1 && transmission_mode<7) {
+          n_tx_port = 2;
+        }
 
-      if (transmission_mode>1 && transmission_mode<7) {
-        n_tx_port = 2;
-      }
+        break;
 
-      break;
+      case 'y':
+        n_tx_phy=atoi(optarg);
 
-    case 'y':
-      n_tx_phy=atoi(optarg);
+        if (n_tx_phy < n_tx_port) {
+          printf("n_tx_phy mush not be smaller than n_tx_port");
+          exit(-1);
+        }
 
-      if (n_tx_phy < n_tx_port) {
-        printf("n_tx_phy mush not be smaller than n_tx_port");
-        exit(-1);
-      }
+        if ((transmission_mode>1 && transmission_mode<7) && n_tx_port<2) {
+          printf("n_tx_port must be >1 for transmission_mode %d\n",transmission_mode);
+          exit(-1);
+        }
 
-      if ((transmission_mode>1 && transmission_mode<7) && n_tx_port<2) {
-        printf("n_tx_port must be >1 for transmission_mode %d\n",transmission_mode);
-        exit(-1);
-      }
+        if (transmission_mode==7 && (n_tx_phy!=1 && n_tx_phy!=2 && n_tx_phy!=4 && n_tx_phy!=8 && n_tx_phy!=16 && n_tx_phy!=64 && n_tx_phy!=128)) {
+          printf("Physical number of antennas not supported for TM7.\n");
+          exit(-1);
+        }
 
-      if (transmission_mode==7 && (n_tx_phy!=1 && n_tx_phy!=2 && n_tx_phy!=4 && n_tx_phy!=8 && n_tx_phy!=16 && n_tx_phy!=64 && n_tx_phy!=128)) {
-        printf("Physical number of antennas not supported for TM7.\n");
-        exit(-1);
-      }
+        break;
 
-      break;
-      break;
+      case 'z':
+        n_rx=atoi(optarg);
 
-    case 'X':
-      xforms=1;
-      break;
+        if ((n_rx==0) || (n_rx>2)) {
+          printf("Unsupported number of rx antennas %d\n",n_rx);
+          exit(-1);
+        }
 
-    case 'Y':
-      perfect_ce=1;
-      break;
+        break;
 
-    case 'z':
-      n_rx=atoi(optarg);
+      case 'Q':
+        set_parallel_conf(optarg);
+        break;
 
-      if ((n_rx==0) || (n_rx>2)) {
-        printf("Unsupported number of rx antennas %d\n",n_rx);
-        exit(-1);
-      }
+      default:
+        printf("Wrong option: %s\n",long_options[option_index].name);
+        exit(1);
+        break;
+    }
+  }
 
-      break;
+  if ( res != -1 ) {
+    printf("A wrong option has been found\n");
+    exit(1);
+  }
 
-    case 'Z':
-      dump_table=1;
-      break;
+  if (help || verbose )
+    display_options_values(options, true);
 
-    case 'L':
-      loglvl = atoi(optarg);
-      break;
+  if (help)
+    exit(0);
 
-    case 'h':
-    default:
-      printf("%s -h(elp) -a(wgn on) -d(ci decoding on) -p(extended prefix on) -m mcs1 -M mcs2 -n n_frames -s snr0 -x transmission mode (1,2,5,6,7) -y TXant -z RXant -I trch_file\n",argv[0]);
-      printf("-h This message\n");
-      printf("-a Use AWGN channel and not multipath\n");
-      printf("-c Number of PDCCH symbols\n");
-      printf("-m MCS1 for TB 1\n");
-      printf("-M MCS2 for TB 2\n");
-      printf("-d Transmit the DCI and compute its error statistics\n");
-      printf("-p Use extended prefix mode\n");
-      printf("-n Number of frames to simulate\n");
-      printf("-o Sample offset for receiver\n");
-      printf("-s Starting SNR, runs from SNR to SNR+%.1fdB in steps of %.1fdB. If n_frames is 1 then just SNR is simulated and MATLAB/OCTAVE output is generated\n", snr_int, snr_step);
-      printf("-f step size of SNR, default value is 1.\n");
-      printf("-C cell id\n");
-      printf("-S subframe\n");
-      printf("-D use TDD mode\n");
-      printf("-b TDD config\n");
-      printf("-B bandwidth configuration (in number of ressource blocks): 6, 25, 50, 100\n");
-      printf("-r ressource block allocation (see  section 7.1.6.3 in 36.213\n");
-      printf("-g [A:M] Use 3GPP 25.814 SCM-A/B/C/D('A','B','C','D') or 36-101 EPA('E'), EVA ('F'),ETU('G') models (ignores delay spread and Ricean factor), Rayghleigh8 ('H'), Rayleigh1('I'), Rayleigh1_corr('J'), Rayleigh1_anticorr ('K'), Rice8('L'), Rice1('M')\n");
-      printf("-F forgetting factor (0 new channel every trial, 1 channel constant\n");
-      printf("-x Transmission mode (1,2,6,7 for the moment)\n");
-      printf("-q Number of TX antennas ports used in eNB\n");
-      printf("-y Number of TX antennas used in eNB\n");
-      printf("-z Number of RX antennas used in UE\n");
-      printf("-t MCS of interfering UE\n");
-      printf("-R Number of HARQ rounds (fixed)\n");
-      printf("-A Turns on calibration mode for abstraction.\n");
-      printf("-N Determines the number of Channel Realizations in Abstraction mode. Default value is 1. \n");
-      printf("-O Set the percenatge of effective rate to testbench the modem performance (typically 30 and 70, range 1-100) \n");
-      printf("-I Input filename for TrCH data (binary)\n");
-      printf("-u Enables the Interference Aware Receiver for TM5 (default is normal receiver)\n");
-      exit(1);
-      break;
-    }
-  }
-  set_parallel_conf("PARALLEL_RU_L1_TRX_SPLIT");
-  set_worker_conf("WORKER_ENABLE");
+  if (thread_struct.parallel_conf != PARALLEL_SINGLE_THREAD)
+    set_worker_conf("WORKER_ENABLE");
 
   if (transmission_mode>1) pa=dBm3;
-  printf("dlsim: tmode %d, pa %d\n",transmission_mode,pa);
 
-  AssertFatal(load_configmodule(argc,argv) != NULL,
-	      "cannot load configuration module, exiting\n");
+  printf("dlsim: tmode %d, pa %d\n",transmission_mode,pa);
+  AssertFatal(load_configmodule(argc,argv, CONFIG_ENABLECMDLINEONLY) != NULL,
+              "cannot load configuration module, exiting\n");
   logInit();
+  set_glog_onlinelog(true);
   // enable these lines if you need debug info
   set_glog(loglvl);
+  SET_LOG_DEBUG(UE_TIMING);
   // moreover you need to init itti with the following line
   // however itti will catch all signals, so ctrl-c won't work anymore
   // alternatively you can disable ITTI completely in CMakeLists.txt
   //itti_init(TASK_MAX, THREAD_MAX, MESSAGES_ID_MAX, tasks_info, messages_info, messages_definition_xml, NULL);
 
-
   if (common_flag == 0) {
     switch (N_RB_DL) {
-    case 6:
-      if (rballocset==0) DLSCH_RB_ALLOC = 0x3f;
-      num_pdcch_symbols = 3;
-      break;
+      case 6:
+        if (rballocset==0) DLSCH_RB_ALLOC = 0x3f;
 
-    case 25:
-      if (rballocset==0) DLSCH_RB_ALLOC = 0x1fff;
-      break;
+        num_pdcch_symbols = 3;
+        break;
 
-    case 50:
-      if (rballocset==0) DLSCH_RB_ALLOC = 0x1ffff;
-      break;
+      case 25:
+        if (rballocset==0) DLSCH_RB_ALLOC = 0x1fff;
 
-    case 100:
-      if (rballocset==0) DLSCH_RB_ALLOC = 0x1ffffff;
-      break;
+        break;
+
+      case 50:
+        if (rballocset==0) DLSCH_RB_ALLOC = 0x1ffff;
+
+        break;
+
+      case 100:
+        if (rballocset==0) DLSCH_RB_ALLOC = 0x1ffffff;
+
+        break;
     }
 
-    NB_RB=conv_nprb(0,DLSCH_RB_ALLOC,N_RB_DL);
-  } else
-    NB_RB = 4;
+    NB_RB = conv_nprb(0,DLSCH_RB_ALLOC,N_RB_DL);
+  } else {
+    if (rballocset==0) NB_RB = 8;
+    else               NB_RB = DLSCH_RB_ALLOC;
+
+    AssertFatal(NB_RB <= N_RB_DL,"illegal NB_RB %d\n",NB_RB);
+  }
 
   if (xforms==1) {
     fl_initialize (&argc, argv, NULL, 0, 0);
@@ -1112,10 +945,15 @@ int main(int argc, char **argv)
     fl_show_form (form_ue->lte_phy_scope_ue, FL_PLACE_HOTSPOT, FL_FULLBORDER, title);
 
     if (!dual_stream_UE==0) {
-      UE->use_ia_receiver = 1;
-      fl_set_button(form_ue->button_0,1);
-      fl_set_object_label(form_ue->button_0, "IA Receiver ON");
-      fl_set_object_color(form_ue->button_0, FL_GREEN, FL_GREEN);
+      if (UE) {
+        UE->use_ia_receiver = 1;
+        fl_set_button(form_ue->button_0,1);
+        fl_set_object_label(form_ue->button_0, "IA Receiver ON");
+        fl_set_object_color(form_ue->button_0, FL_GREEN, FL_GREEN);
+      } else {
+          printf("UE  is NULL\n");
+          exit(-1);
+      }
     }
   }
 
@@ -1123,47 +961,45 @@ int main(int argc, char **argv)
     n_users = 2;
     printf("dual_stream_UE=%d\n", dual_stream_UE);
   }
+
   RC.nb_L1_inst = 1;
   RC.nb_RU = 1;
-
   lte_param_init(&eNB,&UE,&ru,
-		 n_tx_port,
-		 n_tx_phy,
-		 1,
+                 n_tx_port,
+                 n_tx_phy,
+                 1,
                  n_rx,
-		 transmission_mode,
-		 extended_prefix_flag,
-		 frame_type,
-		 Nid_cell,
-		 tdd_config,
-		 N_RB_DL,
-		 pa,
-		 threequarter_fs,
-		 osf,
-		 perfect_ce);
-  RC.eNB = (PHY_VARS_eNB ***)malloc(sizeof(PHY_VARS_eNB **));
+                 transmission_mode,
+                 extended_prefix_flag,
+                 frame_type,
+                 Nid_cell,
+                 tdd_config,
+                 N_RB_DL,
+                 pa,
+                 threequarter_fs,
+                 osf,
+                 perfect_ce);
+  RC.eNB = (PHY_VARS_eNB ** *)malloc(sizeof(PHY_VARS_eNB **));
   RC.eNB[0] = (PHY_VARS_eNB **)malloc(sizeof(PHY_VARS_eNB *));
   RC.ru = (RU_t **)malloc(sizeof(RC.ru));
   RC.eNB[0][0] = eNB;
   RC.ru[0] = ru;
   printf("lte_param_init done\n");
+
   if ((transmission_mode==1) || (transmission_mode==7)) {
     for (aa=0; aa<ru->nb_tx; aa++)
-     for (re=0; re<ru->frame_parms.ofdm_symbol_size; re++)
-       ru->beam_weights[0][0][aa][re] = 0x00007fff/eNB->frame_parms.nb_antennas_tx;
+      for (re=0; re<ru->frame_parms.ofdm_symbol_size; re++)
+        ru->beam_weights[0][0][aa][re] = 0x00007fff/eNB->frame_parms.nb_antennas_tx;
   }
 
   if (transmission_mode<7)
-     ru->do_precoding=0;
+    ru->do_precoding=0;
   else
-     ru->do_precoding=1;
+    ru->do_precoding=1;
 
   eNB->mac_enabled=1;
-  if (two_thread_flag == 0) {
-    eNB->te = dlsch_encoding;
-  }
-  else {
-    eNB->te = dlsch_encoding_2threads;
+
+  if(get_thread_worker_conf() == WORKER_ENABLE) {
     extern void init_td_thread(PHY_VARS_eNB *);
     extern void init_te_thread(PHY_VARS_eNB *);
     init_td_thread(eNB);
@@ -1171,27 +1007,21 @@ int main(int argc, char **argv)
   }
 
   // callback functions required for phy_procedures_tx
-
   //  eNB_id_i = UE->n_connected_eNB;
-
   printf("Setting mcs1 = %d\n",mcs1);
   printf("Setting mcs2 = %d\n",mcs2);
   printf("NPRB = %d\n",NB_RB);
   printf("n_frames = %d\n",n_frames);
   printf("Transmission mode %d with %dx%d antenna configuration, Extended Prefix %d\n",transmission_mode,n_tx_phy,n_rx,extended_prefix_flag);
-
   snr1 = snr0+snr_int;
   printf("SNR0 %f, SNR1 %f\n",snr0,snr1);
-
   uint8_t input_buffer[NUMBER_OF_UE_MAX][20000];
 
-  for (i=0;i<n_users;i++)
-    for (j=0;j<20000;j++) input_buffer[i][j] = (uint8_t)((taus())&255);
+  for (i=0; i<n_users; i++)
+    for (j=0; j<20000; j++) input_buffer[i][j] = (uint8_t)((taus())&255);
 
   frame_parms = &eNB->frame_parms;
-
   nsymb = (eNB->frame_parms.Ncp == 0) ? 14 : 12;
-
   printf("Channel Model= (%s,%d)\n",channel_model_input, channel_model);
   printf("SCM-A=%d, SCM-B=%d, SCM-C=%d, SCM-D=%d, EPA=%d, EVA=%d, ETU=%d, Rayleigh8=%d, Rayleigh1=%d, Rayleigh1_corr=%d, Rayleigh1_anticorr=%d, Rice1=%d, Rice8=%d\n",
          SCM_A, SCM_B, SCM_C, SCM_D, EPA, EVA, ETU, Rayleigh8, Rayleigh1, Rayleigh1_corr, Rayleigh1_anticorr, Rice1, Rice8);
@@ -1202,10 +1032,12 @@ int main(int argc, char **argv)
     sprintf(bler_fname,"bler_tx%d_chan%d_nrx%d_mcs%d.csv",transmission_mode,channel_model,n_rx,mcs1);
 
   bler_fd = fopen(bler_fname,"w");
+
   if (bler_fd==NULL) {
     fprintf(stderr,"Cannot create file %s!\n",bler_fname);
     exit(-1);
   }
+
   fprintf(bler_fd,"SNR; MCS; TBS; rate; err0; trials0; err1; trials1; err2; trials2; err3; trials3; dci_err\n");
 
   if (test_perf != 0) {
@@ -1219,6 +1051,7 @@ int main(int argc, char **argv)
             N_RB_DL,mcs1,n_tx_phy,n_rx,num_pdcch_symbols,channel_model_input,transmission_mode);
     //mkdir(dirname,0777);
     time_meas_fd = fopen(time_meas_fname,"w");
+
     if (time_meas_fd==NULL) {
       fprintf(stderr,"Cannot create file %s!\n",time_meas_fname);
       exit(-1);
@@ -1229,11 +1062,13 @@ int main(int argc, char **argv)
     // CSV file
     sprintf(csv_fname,"dataout_tx%d_u2%d_mcs%d_chan%d_nsimus%d_R%d.m",transmission_mode,dual_stream_UE,mcs1,channel_model,n_frames,num_rounds);
     csv_fd = fopen(csv_fname,"w");
-    fprintf(csv_fd,"data_all%d=[",mcs1);
+
     if (csv_fd==NULL) {
       fprintf(stderr,"Cannot create file %s!\n",csv_fname);
       exit(-1);
     }
+
+    fprintf(csv_fd,"data_all%d=[",mcs1);
   }
 
   /*
@@ -1332,38 +1167,35 @@ int main(int argc, char **argv)
       break;
     }
   */
-
-
   UE->pdcch_vars[UE->current_thread_id[subframe]][0]->crnti = n_rnti;
   UE->n_connected_eNB = 1;
-
   printf("Allocating %dx%d eNB->UE channel descriptor\n",eNB->frame_parms.nb_antennas_tx,UE->frame_parms.nb_antennas_rx);
   eNB2UE[0] = new_channel_desc_scm(eNB->frame_parms.nb_antennas_tx,
                                    UE->frame_parms.nb_antennas_rx,
                                    channel_model,
                                    N_RB2sampling_rate(eNB->frame_parms.N_RB_DL),
-				   N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL),
+                                   N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL),
                                    forgetting_factor,
                                    rx_sample_offset,
                                    0);
-
   reset_meas(&eNB2UE[0]->random_channel);
   reset_meas(&eNB2UE[0]->interp_time);
+
   if(num_rounds>1) {
     for(n=1; n<4; n++) {
       eNB2UE[n] = new_channel_desc_scm(eNB->frame_parms.nb_antennas_tx,
                                        UE->frame_parms.nb_antennas_rx,
                                        channel_model,
-				       N_RB2sampling_rate(eNB->frame_parms.N_RB_DL),
-				       N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL),
-				       forgetting_factor,
+                                       N_RB2sampling_rate(eNB->frame_parms.N_RB_DL),
+                                       N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL),
+                                       forgetting_factor,
                                        rx_sample_offset,
                                        0);
       reset_meas(&eNB2UE[n]->random_channel);
       reset_meas(&eNB2UE[n]->interp_time);
     }
   }
-  
+
   if (eNB2UE[0]==NULL) {
     printf("Problem generating channel model. Exiting.\n");
     exit(-1);
@@ -1375,20 +1207,23 @@ int main(int argc, char **argv)
     Kmimo=1;
 
   switch (ue_category) {
-  case 1:
-    Nsoft = 250368;
-    break;
-  case 2:
-  case 3:
-    Nsoft = 1237248;
-    break;
-  case 4:
-    Nsoft = 1827072;
-    break;
-  default:
-    printf("Unsupported UE category %d\n",ue_category);
-    exit(-1);
-    break;
+    case 1:
+      Nsoft = 250368;
+      break;
+
+    case 2:
+    case 3:
+      Nsoft = 1237248;
+      break;
+
+    case 4:
+      Nsoft = 1827072;
+      break;
+
+    default:
+      printf("Unsupported UE category %d\n",ue_category);
+      exit(-1);
+      break;
   }
 
   for (k=0; k<NUMBER_OF_UE_MAX; k++) {
@@ -1423,15 +1258,13 @@ int main(int argc, char **argv)
     }
   }
 
-    UE->dlsch_SI[0]  = new_ue_dlsch(1,1,Nsoft,MAX_TURBO_ITERATIONS,N_RB_DL,0);
-    UE->dlsch_ra[0]  = new_ue_dlsch(1,1,Nsoft,MAX_TURBO_ITERATIONS,N_RB_DL,0);
-    UE->ulsch[0] = new_ue_ulsch(N_RB_DL,0);
-
+  UE->dlsch_SI[0]  = new_ue_dlsch(1,1,Nsoft,MAX_TURBO_ITERATIONS,N_RB_DL,0);
+  UE->dlsch_ra[0]  = new_ue_dlsch(1,1,Nsoft,MAX_TURBO_ITERATIONS,N_RB_DL,0);
+  UE->ulsch[0] = new_ue_ulsch(N_RB_DL,0);
   // structure for SIC at UE
   UE->dlsch_eNB[0] = new_eNB_dlsch(Kmimo,8,Nsoft,N_RB_DL,0,&eNB->frame_parms);
 
   if (DLSCH_alloc_pdu2_1E[0].tpmi == 5) {
-
     eNB->UE_stats[0].DL_pmi_single = (unsigned short)(taus()&0xffff);
 
     if (n_users>1)
@@ -1443,41 +1276,36 @@ int main(int argc, char **argv)
       eNB->UE_stats[1].DL_pmi_single = 0;
   }
 
-  eNB_rxtx_proc_t *proc_eNB = &eNB->proc.proc_rxtx[0];//UE->current_thread_id[subframe]];
+  L1_rxtx_proc_t *proc_eNB = &eNB->proc.L1_proc;
 
   if (input_fd==NULL) {
-
     DL_req.dl_config_request_body.number_pdcch_ofdm_symbols = num_pdcch_symbols;
     DL_req.sfn_sf = (proc_eNB->frame_tx<<4)+subframe;
     TX_req.sfn_sf = (proc_eNB->frame_tx<<4)+subframe;
     // UE specific DCI
     fill_DCI(eNB,
-	     proc_eNB->frame_tx,subframe,
-	     &sched_resp,
-	     input_buffer,
-	     n_rnti,
-	     n_users,
-	     transmission_mode,
-	     0,
-	     common_flag,
-	     NB_RB,
-	     DLSCH_RB_ALLOC,
-	     TPC,
-	     mcs1,
-	     mcs2,
-	     1,
-	     0,
-	     pa,
-	     &num_common_dci,
-	     &num_ue_spec_dci,
-	     &num_dci);
-
+             proc_eNB->frame_tx,subframe,
+             &sched_resp,
+             input_buffer,
+             n_rnti,
+             n_users,
+             transmission_mode,
+             0,
+             common_flag,
+             NB_RB,
+             DLSCH_RB_ALLOC,
+             TPC,
+             mcs1,
+             mcs2,
+             1,
+             0,
+             pa,
+             &num_common_dci,
+             &num_ue_spec_dci,
+             &num_dci);
     numCCE = get_nCCE(num_pdcch_symbols,&eNB->frame_parms,get_mi(&eNB->frame_parms,subframe));
 
     if (n_frames==1) printf("num_pdcch_symbols %d, numCCE %d, num_dci %d/%d/%d\n",num_pdcch_symbols,numCCE, num_dci,num_ue_spec_dci,num_common_dci);
-
-
-
   }
 
   snr_step = input_snr_step;
@@ -1503,13 +1331,11 @@ int main(int argc, char **argv)
       round_trials[1] = 0;
       round_trials[2] = 0;
       round_trials[3] = 0;
-
       dci_errors[0]=0;
       dci_errors[1]=0;
       dci_errors[2]=0;
       dci_errors[3]=0;
       //      avg_ber = 0;
-
       round=0;
       avg_iter = 0;
       iter_trials=0;
@@ -1522,9 +1348,21 @@ int main(int argc, char **argv)
       reset_meas(&eNB->dlsch_interleaving_stats);
       reset_meas(&eNB->dlsch_rate_matching_stats);
       reset_meas(&eNB->dlsch_turbo_encoding_stats);
+      reset_meas(&eNB->dlsch_common_and_dci);
+      reset_meas(&eNB->dlsch_ue_specific);
+
+      for (int i=0; i<RX_NB_TH; i++) {
+        reset_meas(&UE->phy_proc_rx[i]); // total UE rx
+        reset_meas(&UE->ue_front_end_stat[i]);
+        reset_meas(&UE->pdsch_procedures_stat[i]);
+        reset_meas(&UE->dlsch_procedures_stat[i]);
+        reset_meas(&UE->dlsch_decoding_stats[i]);
+        reset_meas(&UE->dlsch_llr_stats_parallelization[i][0]);
+        reset_meas(&UE->dlsch_llr_stats_parallelization[i][1]);
+      }
 
-      reset_meas(&UE->phy_proc_rx[UE->current_thread_id[subframe]]); // total UE rx
       reset_meas(&UE->ofdm_demod_stats);
+      reset_meas(&UE->crnti_procedures_stats);
       reset_meas(&UE->dlsch_channel_estimation_stats);
       reset_meas(&UE->dlsch_freq_offset_estimation_stats);
       reset_meas(&UE->rx_dft_stats);
@@ -1541,38 +1379,33 @@ int main(int argc, char **argv)
       reset_meas(&UE->dlsch_tc_intl1_stats);
       reset_meas(&UE->dlsch_tc_intl2_stats);
       // initialization
-      struct list time_vector_tx;
-      initialize(&time_vector_tx);
-      struct list time_vector_tx_ifft;
-      initialize(&time_vector_tx_ifft);
-      struct list time_vector_tx_mod;
-      initialize(&time_vector_tx_mod);
-      struct list time_vector_tx_enc;
-      initialize(&time_vector_tx_enc);
-
-      struct list time_vector_rx;
-      initialize(&time_vector_rx);
-      struct list time_vector_rx_fft;
-      initialize(&time_vector_rx_fft);
-      struct list time_vector_rx_demod;
-      initialize(&time_vector_rx_demod);
-      struct list time_vector_rx_dec;
-      initialize(&time_vector_rx_dec);
-
-
+      // initialization
+      varArray_t *table_tx=initVarArray(1000,sizeof(double));
+      varArray_t *table_tx_ifft=initVarArray(1000,sizeof(double));
+      varArray_t *table_tx_mod=initVarArray(1000,sizeof(double));
+      varArray_t *table_tx_enc=initVarArray(1000,sizeof(double));
+      varArray_t *table_rx=initVarArray(1000,sizeof(double));
+      time_stats_t phy_proc_rx_tot;
+      time_stats_t pdsch_procedures_tot;
+      time_stats_t dlsch_procedures_tot;
+      time_stats_t dlsch_decoding_tot;
+      time_stats_t dlsch_llr_tot;
+      time_stats_t ue_front_end_tot;
+      varArray_t *table_rx_fft=initVarArray(1000,sizeof(double));
+      varArray_t *table_rx_demod=initVarArray(1000,sizeof(double));
+      varArray_t *table_rx_dec=initVarArray(1000,sizeof(double));
 
       for (trials = 0; trials<n_frames; trials++) {
-	//printf("Trial %d\n",trials);
+        //printf("Trial %d\n",trials);
         fflush(stdout);
         round=0;
-
         //if (trials%100==0)
         eNB2UE[0]->first_run = 1;
-	UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->harq_ack[subframe].ack = 0;
-	UE->dlsch[UE->current_thread_id[subframe]][eNB_id][1]->harq_ack[subframe].ack = 0;
+        UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->harq_ack[subframe].ack = 0;
+        UE->dlsch[UE->current_thread_id[subframe]][eNB_id][1]->harq_ack[subframe].ack = 0;
 
         while ((round < num_rounds) && (UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->harq_ack[subframe].ack == 0)) {
-	  //	  printf("Trial %d, round %d\n",trials,round);
+          //    printf("Trial %d, round %d\n",trials,round);
           round_trials[round]++;
 
           //if(transmission_mode>=5)
@@ -1588,7 +1421,7 @@ int main(int argc, char **argv)
           } else
             hold_channel = 0;//(round==0) ? 0 : 1;
 
-	  //PMI_FEEDBACK:
+          //PMI_FEEDBACK:
 
           //  printf("Trial %d : Round %d, pmi_feedback %d \n",trials,round,pmi_feedback);
           for (aa=0; aa<eNB->frame_parms.nb_antennas_tx; aa++) {
@@ -1596,91 +1429,73 @@ int main(int argc, char **argv)
           }
 
           if (input_fd==NULL) {
-
-
             // Simulate HARQ procedures!!!
-	    memset(CCE_table,0,800*sizeof(int));
-            if (common_flag == 0) {
+            memset(CCE_table,0,800*sizeof(int));
 
-	      num_dci=0;
-	      num_common_dci=0;
-	      num_ue_spec_dci=0;
+            if (/*common_flag == 0*/ 1) {
+              num_dci=0;
+              num_common_dci=0;
+              num_ue_spec_dci=0;
 
               if (round == 0) {   // First round
                 TB0_active = 1;
-
                 eNB->dlsch[0][0]->harq_processes[0]->rvidx = round&3;
-		DL_req.sfn_sf = (proc_eNB->frame_tx<<4)+subframe;
-		TX_req.sfn_sf = (proc_eNB->frame_tx<<4)+subframe;
-		fill_DCI(eNB,proc_eNB->frame_tx,subframe,&sched_resp,input_buffer,n_rnti,n_users,transmission_mode,0,common_flag,NB_RB,DLSCH_RB_ALLOC,TPC,
-			 mcs1,mcs2,!(trials&1),round&3,pa,&num_common_dci,&num_ue_spec_dci,&num_dci);
-	      }
-	      else {
-		DL_req.sfn_sf = (proc_eNB->frame_tx<<4)+subframe;
-		TX_req.sfn_sf = (proc_eNB->frame_tx<<4)+subframe;
-		fill_DCI(eNB,proc_eNB->frame_tx,subframe,&sched_resp,input_buffer,n_rnti,n_users,transmission_mode,1,common_flag,NB_RB,DLSCH_RB_ALLOC,TPC,
-			 (TB0_active==1)?mcs1:0,mcs2,!(trials&1),(TB0_active==1)?round&3:0,pa,&num_common_dci,&num_ue_spec_dci,&num_dci);
-	      }
-	    }
-
-	    proc_eNB->subframe_tx = subframe;
-	    sched_resp.subframe=subframe;
-	    sched_resp.frame=proc_eNB->frame_tx;
-
-	    eNB->abstraction_flag=0;
-	    schedule_response(&sched_resp);
-	    phy_procedures_eNB_TX(eNB,proc_eNB,1);
-
-	    if (uncoded_ber_bit == NULL) {
-	      // this is for user 0 only
-	      printf("nb_rb %d, rb_alloc %x, mcs %d\n",
-		     eNB->dlsch[0][0]->harq_processes[0]->nb_rb,
-		     eNB->dlsch[0][0]->harq_processes[0]->rb_alloc[0],
-		     eNB->dlsch[0][0]->harq_processes[0]->mcs);
-
-	      coded_bits_per_codeword = get_G(&eNB->frame_parms,
-					      eNB->dlsch[0][0]->harq_processes[0]->nb_rb,
-					      eNB->dlsch[0][0]->harq_processes[0]->rb_alloc,
-					      get_Qm(eNB->dlsch[0][0]->harq_processes[0]->mcs),
-					      eNB->dlsch[0][0]->harq_processes[0]->Nl,
-					      num_pdcch_symbols,
-					      0,
-					      subframe,
-					      transmission_mode>=7?transmission_mode:0);
-
-	      uncoded_ber_bit = (short*) malloc(sizeof(short)*coded_bits_per_codeword);
-	      printf("uncoded_ber_bit=%p\n",uncoded_ber_bit);
-	    }
-
-	    start_meas(&eNB->ofdm_mod_stats);
-
-	    ru->proc.subframe_tx=subframe;
-	    memcpy((void*)&ru->frame_parms,(void*)&eNB->frame_parms,sizeof(LTE_DL_FRAME_PARMS));
-	    feptx_prec(ru);
-	    feptx_ofdm(ru);
-
-	    stop_meas(&eNB->ofdm_mod_stats);
-
-
-
-	    // generate next subframe for channel estimation
-
-	    DL_req.dl_config_request_body.number_dci=0;
-	    DL_req.dl_config_request_body.number_pdu=0;
-	    TX_req.tx_request_body.number_of_pdus=0;
-	    proc_eNB->subframe_tx = subframe+1;
-	    sched_resp.subframe=subframe+1;
-	    schedule_response(&sched_resp);
-	    phy_procedures_eNB_TX(eNB,proc_eNB,0);
-
-
-	    ru->proc.subframe_tx=(subframe+1)%10;
-	    feptx_prec(ru);
-	    feptx_ofdm(ru);
-
+                DL_req.sfn_sf = (proc_eNB->frame_tx<<4)+subframe;
+                TX_req.sfn_sf = (proc_eNB->frame_tx<<4)+subframe;
+                fill_DCI(eNB,proc_eNB->frame_tx,subframe,&sched_resp,input_buffer,n_rnti,n_users,transmission_mode,0,common_flag,NB_RB,DLSCH_RB_ALLOC,TPC,
+                         mcs1,mcs2,!(trials&1),round&3,pa,&num_common_dci,&num_ue_spec_dci,&num_dci);
+              } else {
+                DL_req.sfn_sf = (proc_eNB->frame_tx<<4)+subframe;
+                TX_req.sfn_sf = (proc_eNB->frame_tx<<4)+subframe;
+                fill_DCI(eNB,proc_eNB->frame_tx,subframe,&sched_resp,input_buffer,n_rnti,n_users,transmission_mode,1,common_flag,NB_RB,DLSCH_RB_ALLOC,TPC,
+                         (TB0_active==1)?mcs1:0,mcs2,!(trials&1),(TB0_active==1)?round&3:0,pa,&num_common_dci,&num_ue_spec_dci,&num_dci);
+              }
+            }
 
-	    proc_eNB->frame_tx++;
+            proc_eNB->subframe_tx = subframe;
+            sched_resp.subframe=subframe;
+            sched_resp.frame=proc_eNB->frame_tx;
+            eNB->abstraction_flag=0;
+            schedule_response(&sched_resp);
+            phy_procedures_eNB_TX(eNB,proc_eNB,1);
+
+            if (uncoded_ber_bit == NULL) {
+              // this is for user 0 only
+              printf("nb_rb %d, rb_alloc %x, mcs %d\n",
+                     eNB->dlsch[0][0]->harq_processes[0]->nb_rb,
+                     eNB->dlsch[0][0]->harq_processes[0]->rb_alloc[0],
+                     eNB->dlsch[0][0]->harq_processes[0]->mcs);
+              coded_bits_per_codeword = get_G(&eNB->frame_parms,
+                                              eNB->dlsch[0][0]->harq_processes[0]->nb_rb,
+                                              eNB->dlsch[0][0]->harq_processes[0]->rb_alloc,
+                                              get_Qm(eNB->dlsch[0][0]->harq_processes[0]->mcs),
+                                              eNB->dlsch[0][0]->harq_processes[0]->Nl,
+                                              num_pdcch_symbols,
+                                              0,
+                                              subframe,
+                                              transmission_mode>=7?transmission_mode:0);
+              uncoded_ber_bit = (short *) malloc(sizeof(short)*coded_bits_per_codeword);
+              printf("uncoded_ber_bit=%p\n",uncoded_ber_bit);
+            }
 
+            start_meas(&eNB->ofdm_mod_stats);
+            ru->proc.subframe_tx=subframe;
+            memcpy((void *)&ru->frame_parms,(void *)&eNB->frame_parms,sizeof(LTE_DL_FRAME_PARMS));
+            feptx_prec(ru);
+            feptx_ofdm(ru);
+            stop_meas(&eNB->ofdm_mod_stats);
+            // generate next subframe for channel estimation
+            DL_req.dl_config_request_body.number_dci=0;
+            DL_req.dl_config_request_body.number_pdu=0;
+            TX_req.tx_request_body.number_of_pdus=0;
+            proc_eNB->subframe_tx = subframe+1;
+            sched_resp.subframe=subframe+1;
+            schedule_response(&sched_resp);
+            phy_procedures_eNB_TX(eNB,proc_eNB,0);
+            ru->proc.subframe_tx=(subframe+1)%10;
+            feptx_prec(ru);
+            feptx_ofdm(ru);
+            proc_eNB->frame_tx++;
             tx_lev = 0;
 
             for (aa=0; aa<eNB->frame_parms.nb_antennas_tx; aa++) {
@@ -1691,179 +1506,153 @@ int main(int argc, char **argv)
 
             tx_lev_dB = (unsigned int) dB_fixed(tx_lev);
 
-
-
             if (n_frames==1) {
-              printf("tx_lev = %d (%d dB)\n",tx_lev,tx_lev_dB);
-
+              printf("tx_lev = %u (%u dB)\n",tx_lev,tx_lev_dB);
               LOG_M("txsig0.m","txs0", &ru->common.txdata[0][subframe* eNB->frame_parms.samples_per_tti], eNB->frame_parms.samples_per_tti,1,1);
 
               if (transmission_mode<7) {
-	        LOG_M("txsigF0.m","txsF0x", &ru->common.txdataF_BF[0][subframe*nsymb*eNB->frame_parms.ofdm_symbol_size],nsymb*eNB->frame_parms.ofdm_symbol_size,1,1);
+                LOG_M("txsigF0.m","txsF0x", &ru->common.txdataF_BF[0][subframe*nsymb*eNB->frame_parms.ofdm_symbol_size],nsymb*eNB->frame_parms.ofdm_symbol_size,1,1);
               } else if (transmission_mode == 7) {
                 LOG_M("txsigF0.m","txsF0", &ru->common.txdataF_BF[5][subframe*nsymb*eNB->frame_parms.ofdm_symbol_size],nsymb*eNB->frame_parms.ofdm_symbol_size,1,1);
                 LOG_M("txsigF0_BF.m","txsF0_BF", &ru->common.txdataF_BF[0][0],eNB->frame_parms.ofdm_symbol_size,1,1);
               }
             }
-	  }
-
-	  DL_channel(ru,UE,subframe,awgn_flag,SNR,tx_lev,hold_channel,abstx,num_rounds,trials,round,eNB2UE,s_re,s_im,r_re,r_im,csv_fd);
-
-
-	  UE_rxtx_proc_t *proc = &UE->proc.proc_rxtx[UE->current_thread_id[subframe]];
-	  proc->subframe_rx = subframe;
-	  UE->UE_mode[0] = PUSCH;
-
-	  // first symbol has to be done separately in one-shot mode
-	  slot_fep(UE,
-		   0,
-		   (proc->subframe_rx<<1),
-		   UE->rx_offset,
-		   0,
-		   0);
-
-	  if (n_frames==1) printf("Running phy_procedures_UE_RX\n");
-
-	  if (dci_flag==0) {
-	    memcpy(dci_alloc,eNB->pdcch_vars[subframe&1].dci_alloc,num_dci*sizeof(DCI_ALLOC_t));
-	    UE->pdcch_vars[UE->current_thread_id[proc->subframe_rx]][eNB_id]->num_pdcch_symbols = num_pdcch_symbols;
-	    if (n_frames==1)
-	      printf("bypassing PDCCH/DCI detection\n");
-	    if  (generate_ue_dlsch_params_from_dci(proc->frame_rx,
-						   proc->subframe_rx,
-						   (void *)&dci_alloc[0].dci_pdu,
-						   n_rnti,
-						   dci_alloc[0].format,
-						   UE->pdcch_vars[UE->current_thread_id[proc->subframe_rx]][eNB_id],
-						   UE->pdsch_vars[UE->current_thread_id[proc->subframe_rx]][eNB_id],
-						   UE->dlsch[UE->current_thread_id[proc->subframe_rx]][0],
-						   &UE->frame_parms,
-						   UE->pdsch_config_dedicated,
-						   SI_RNTI,
-						   0,
-						   P_RNTI,
-						   UE->transmission_mode[eNB_id]<7?0:UE->transmission_mode[eNB_id],
-						   0)==0) {
-
-		dump_dci(&UE->frame_parms, &dci_alloc[0]);
-
-		//UE->dlsch[UE->current_thread_id[proc->subframe_rx]][eNB_id][0]->active = 1;
-		//UE->dlsch[UE->current_thread_id[proc->subframe_rx]][eNB_id][1]->active = 1;
-
-		UE->pdcch_vars[UE->current_thread_id[proc->subframe_rx]][eNB_id]->num_pdcch_symbols = num_pdcch_symbols;
-
-		UE->dlsch_received[eNB_id]++;
-	    } else {
-	      LOG_E(PHY,"Problem in DCI!\n");
-	    }
-	  }
-
-	  dci_received = UE->pdcch_vars[UE->current_thread_id[proc->subframe_rx]][eNB_id]->dci_received;
-
-	  phy_procedures_UE_RX(UE,proc,0,0,dci_flag,normal_txrx);
-
-	  dci_received = dci_received - UE->pdcch_vars[UE->current_thread_id[proc->subframe_rx]][eNB_id]->dci_received;
-
-	  if (dci_flag && (dci_received == 0)) {
-	    printf("DCI not received\n");
-	    dci_errors[round]++;
-
-	    LOG_M("pdcchF0_ext.m","pdcchF_ext", UE->pdcch_vars[0][eNB_id]->rxdataF_ext[0],2*3*UE->frame_parms.ofdm_symbol_size,1,1);
-	    LOG_M("pdcch00_ch0_ext.m","pdcch00_ch0_ext",UE->pdcch_vars[0][eNB_id]->dl_ch_estimates_ext[0],300*3,1,1);
-
-	    LOG_M("pdcch_rxF_comp0.m","pdcch0_rxF_comp0",UE->pdcch_vars[0][eNB_id]->rxdataF_comp[0],4*300,1,1);
-	    LOG_M("pdcch_rxF_llr.m","pdcch_llr",UE->pdcch_vars[0][eNB_id]->llr,2400,1,4);
-
-	    LOG_M("rxsig0.m","rxs0", &UE->common_vars.rxdata[0][0],10*UE->frame_parms.samples_per_tti,1,1);
-	    LOG_M("rxsigF0.m","rxsF0", &UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].rxdataF[0][0],UE->frame_parms.ofdm_symbol_size*nsymb,1,1);
-
-
-	    exit(-1);
-
-	  }
-
-	  int bit_errors=0;
-	  if ((test_perf ==0 ) && (n_frames==1)) {
-
-	    dlsch_unscrambling(&eNB->frame_parms,
-			       0,
-			       UE->dlsch[UE->current_thread_id[subframe]][0][0],
-			       coded_bits_per_codeword,
-			       UE->pdsch_vars[UE->current_thread_id[subframe]][0]->llr[0],
-			       0,
-			       subframe<<1);
-	    for (i=0;i<coded_bits_per_codeword;i++)
-	      if ((eNB->dlsch[0][0]->harq_processes[0]->e[i]==1 && UE->pdsch_vars[UE->current_thread_id[subframe]][0]->llr[0][i] > 0)||
-		  (eNB->dlsch[0][0]->harq_processes[0]->e[i]==0 && UE->pdsch_vars[UE->current_thread_id[subframe]][0]->llr[0][i] < 0)) {
-		uncoded_ber_bit[bit_errors++] = 1;
-		printf("error in pos %d : %d => %d\n",i,
-		       eNB->dlsch[0][0]->harq_processes[0]->e[i],
-		       UE->pdsch_vars[UE->current_thread_id[subframe]][0]->llr[0][i]);
-	      }
-	      else {
-		/*
-		printf("no error in pos %d : %d => %d\n",i,
-		       eNB->dlsch[0][0]->harq_processes[0]->e[i],
-		       UE->pdsch_vars[UE->current_thread_id[subframe]][0]->llr[0][i]);
-		*/
-	      }
-
-	    LOG_M("dlsch_ber_bit.m","ber_bit",uncoded_ber_bit,coded_bits_per_codeword,1,0);
-	    LOG_M("ch0.m","ch0",eNB2UE[0]->ch[0],eNB2UE[0]->channel_length,1,8);
-
-	    if (eNB->frame_parms.nb_antennas_tx>1)
-	      LOG_M("ch1.m","ch1",eNB2UE[0]->ch[eNB->frame_parms.nb_antennas_rx],eNB2UE[0]->channel_length,1,8);
-
-	    //common vars
-	    LOG_M("rxsig0.m","rxs0", &UE->common_vars.rxdata[0][0],10*UE->frame_parms.samples_per_tti,1,1);
-
-	    LOG_M("rxsigF0.m","rxsF0", &UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].rxdataF[0][0],UE->frame_parms.ofdm_symbol_size*nsymb,1,1);
-
-	    if (UE->frame_parms.nb_antennas_rx>1) {
-	      LOG_M("rxsig1.m","rxs1", UE->common_vars.rxdata[1],UE->frame_parms.samples_per_tti,1,1);
-	      LOG_M("rxsigF1.m","rxsF1", UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].rxdataF[1],UE->frame_parms.ofdm_symbol_size*nsymb,1,1);
-	    }
-
-	    LOG_M("dlsch00_r0.m","dl00_r0",
-			 &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][0][0]),
-			 UE->frame_parms.ofdm_symbol_size*nsymb,1,1);
-
-	    if (UE->frame_parms.nb_antennas_rx>1)
-	      LOG_M("dlsch01_r0.m","dl01_r0",
-			   &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][1][0]),
-			   UE->frame_parms.ofdm_symbol_size*nsymb,1,1);
+          }
 
-	    if (eNB->frame_parms.nb_antennas_tx>1)
-	      LOG_M("dlsch10_r0.m","dl10_r0",
-			   &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][2][0]),
-			   UE->frame_parms.ofdm_symbol_size*nsymb,1,1);
+          DL_channel(ru,UE,subframe,awgn_flag,SNR,tx_lev,hold_channel,abstx,num_rounds,trials,round,eNB2UE,s_re,s_im,r_re,r_im,csv_fd);
+          UE_rxtx_proc_t *proc = &UE->proc.proc_rxtx[UE->current_thread_id[subframe]];
+          proc->subframe_rx = subframe;
+          UE->UE_mode[0] = PUSCH;
+          // first symbol has to be done separately in one-shot mode
+          slot_fep(UE,
+                   0,
+                   (proc->subframe_rx<<1),
+                   UE->rx_offset,
+                   0,
+                   0);
 
-	    if ((UE->frame_parms.nb_antennas_rx>1) && (eNB->frame_parms.nb_antennas_tx>1))
-	      LOG_M("dlsch11_r0.m","dl11_r0",
-			   &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][3][0]),
-			   UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1);
+          if (n_frames==1) printf("Running phy_procedures_UE_RX\n");
 
-	    //pdsch_vars
-	    printf("coded_bits_per_codeword %d\n",coded_bits_per_codeword);
+          if (dci_flag==0) {
+            memcpy(dci_alloc,eNB->pdcch_vars[subframe&1].dci_alloc,num_dci*sizeof(DCI_ALLOC_t));
+            UE->pdcch_vars[UE->current_thread_id[proc->subframe_rx]][eNB_id]->num_pdcch_symbols = num_pdcch_symbols;
 
-	    dump_dlsch2(UE,eNB_id,subframe,&coded_bits_per_codeword,round, UE->dlsch[UE->current_thread_id[subframe]][0][0]->current_harq_pid);
+            if (n_frames==1)
+              printf("bypassing PDCCH/DCI detection\n");
+
+            if  (generate_ue_dlsch_params_from_dci(proc->frame_rx,
+                                                   proc->subframe_rx,
+                                                   (void *)&dci_alloc[0].dci_pdu,
+                                                   common_flag == 0 ? n_rnti : SI_RNTI,
+                                                   dci_alloc[0].format,
+                                                   UE->pdcch_vars[UE->current_thread_id[proc->subframe_rx]][eNB_id],
+                                                   UE->pdsch_vars[UE->current_thread_id[proc->subframe_rx]][eNB_id],
+                                                   UE->dlsch[UE->current_thread_id[proc->subframe_rx]][0],
+                                                   &UE->frame_parms,
+                                                   UE->pdsch_config_dedicated,
+                                                   SI_RNTI,
+                                                   0,
+                                                   P_RNTI,
+                                                   UE->transmission_mode[eNB_id]<7?0:UE->transmission_mode[eNB_id],
+                                                   0)==0) {
+              dump_dci(&UE->frame_parms, &dci_alloc[0]);
+              //UE->dlsch[UE->current_thread_id[proc->subframe_rx]][eNB_id][0]->active = 1;
+              //UE->dlsch[UE->current_thread_id[proc->subframe_rx]][eNB_id][1]->active = 1;
+              UE->pdcch_vars[UE->current_thread_id[proc->subframe_rx]][eNB_id]->num_pdcch_symbols = num_pdcch_symbols;
+              UE->dlsch_received[eNB_id]++;
+            } else {
+              LOG_E(PHY,"Problem in DCI!\n");
+            }
+          }
 
-	    LOG_M("dlsch_e.m","e",eNB->dlsch[0][0]->harq_processes[0]->e,coded_bits_per_codeword,1,4);
+          dci_received = UE->pdcch_vars[UE->current_thread_id[proc->subframe_rx]][eNB_id]->dci_received;
+          phy_procedures_UE_RX(UE,proc,0,0,dci_flag,normal_txrx);
+          dci_received = dci_received - UE->pdcch_vars[UE->current_thread_id[proc->subframe_rx]][eNB_id]->dci_received;
+
+          if (dci_flag && (dci_received == 0)) {
+            printf("DCI not received\n");
+            dci_errors[round]++;
+            LOG_M("pdcchF0_ext.m","pdcchF_ext", UE->pdcch_vars[0][eNB_id]->rxdataF_ext[0],2*3*UE->frame_parms.ofdm_symbol_size,1,1);
+            LOG_M("pdcch00_ch0_ext.m","pdcch00_ch0_ext",UE->pdcch_vars[0][eNB_id]->dl_ch_estimates_ext[0],300*3,1,1);
+            LOG_M("pdcch_rxF_comp0.m","pdcch0_rxF_comp0",UE->pdcch_vars[0][eNB_id]->rxdataF_comp[0],4*300,1,1);
+            LOG_M("pdcch_rxF_llr.m","pdcch_llr",UE->pdcch_vars[0][eNB_id]->llr,2400,1,4);
+            LOG_M("rxsig0.m","rxs0", &UE->common_vars.rxdata[0][0],10*UE->frame_parms.samples_per_tti,1,1);
+            LOG_M("rxsigF0.m","rxsF0", &UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].rxdataF[0][0],UE->frame_parms.ofdm_symbol_size*nsymb,1,1);
+            exit(-1);
+          }
 
-	    //pdcch_vars
-	    LOG_M("pdcchF0_ext.m","pdcchF_ext", UE->pdcch_vars[0][eNB_id]->rxdataF_ext[0],2*3*UE->frame_parms.ofdm_symbol_size,1,1);
-	    LOG_M("pdcch00_ch0_ext.m","pdcch00_ch0_ext",UE->pdcch_vars[0][eNB_id]->dl_ch_estimates_ext[0],300*3,1,1);
+          int bit_errors=0;
+
+          if ((test_perf ==0 ) && (n_frames==1)) {
+            dlsch_unscrambling(&eNB->frame_parms,
+                               0,
+                               UE->dlsch[UE->current_thread_id[subframe]][0][0],
+                               coded_bits_per_codeword,
+                               UE->pdsch_vars[UE->current_thread_id[subframe]][0]->llr[0],
+                               0,
+                               subframe<<1);
+
+            for (i=0; i<coded_bits_per_codeword; i++)
+              if ((eNB->dlsch[0][0]->harq_processes[0]->e[i]==1 && UE->pdsch_vars[UE->current_thread_id[subframe]][0]->llr[0][i] > 0)||
+                  (eNB->dlsch[0][0]->harq_processes[0]->e[i]==0 && UE->pdsch_vars[UE->current_thread_id[subframe]][0]->llr[0][i] < 0)) {
+                uncoded_ber_bit[bit_errors++] = 1;
+                printf("error in pos %d : %d => %d\n",i,
+                       eNB->dlsch[0][0]->harq_processes[0]->e[i],
+                       UE->pdsch_vars[UE->current_thread_id[subframe]][0]->llr[0][i]);
+              } else {
+                /*
+                printf("no error in pos %d : %d => %d\n",i,
+                       eNB->dlsch[0][0]->harq_processes[0]->e[i],
+                       UE->pdsch_vars[UE->current_thread_id[subframe]][0]->llr[0][i]);
+                */
+              }
 
-	    LOG_M("pdcch_rxF_comp0.m","pdcch0_rxF_comp0",UE->pdcch_vars[0][eNB_id]->rxdataF_comp[0],4*300,1,1);
-	    LOG_M("pdcch_rxF_llr.m","pdcch_llr",UE->pdcch_vars[0][eNB_id]->llr,2400,1,4);
+            LOG_M("dlsch_ber_bit.m","ber_bit",uncoded_ber_bit,coded_bits_per_codeword,1,0);
+            LOG_M("ch0.m","ch0",eNB2UE[0]->ch[0],eNB2UE[0]->channel_length,1,8);
 
-	  }
+            if (eNB->frame_parms.nb_antennas_tx>1)
+              LOG_M("ch1.m","ch1",eNB2UE[0]->ch[eNB->frame_parms.nb_antennas_rx],eNB2UE[0]->channel_length,1,8);
 
+            //common vars
+            LOG_M("rxsig0.m","rxs0", &UE->common_vars.rxdata[0][0],10*UE->frame_parms.samples_per_tti,1,1);
+            LOG_M("rxsigF0.m","rxsF0", &UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].rxdataF[0][0],UE->frame_parms.ofdm_symbol_size*nsymb,1,1);
 
+            if (UE->frame_parms.nb_antennas_rx>1) {
+              LOG_M("rxsig1.m","rxs1", UE->common_vars.rxdata[1],UE->frame_parms.samples_per_tti,1,1);
+              LOG_M("rxsigF1.m","rxsF1", UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].rxdataF[1],UE->frame_parms.ofdm_symbol_size*nsymb,1,1);
+            }
 
+            LOG_M("dlsch00_r0.m","dl00_r0",
+                  &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][0][0]),
+                  UE->frame_parms.ofdm_symbol_size*nsymb,1,1);
+
+            if (UE->frame_parms.nb_antennas_rx>1)
+              LOG_M("dlsch01_r0.m","dl01_r0",
+                    &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][1][0]),
+                    UE->frame_parms.ofdm_symbol_size*nsymb,1,1);
+
+            if (eNB->frame_parms.nb_antennas_tx>1)
+              LOG_M("dlsch10_r0.m","dl10_r0",
+                    &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][2][0]),
+                    UE->frame_parms.ofdm_symbol_size*nsymb,1,1);
+
+            if ((UE->frame_parms.nb_antennas_rx>1) && (eNB->frame_parms.nb_antennas_tx>1))
+              LOG_M("dlsch11_r0.m","dl11_r0",
+                    &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][3][0]),
+                    UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1);
+
+            //pdsch_vars
+            printf("coded_bits_per_codeword %u\n",coded_bits_per_codeword);
+            dump_dlsch2(UE,eNB_id,subframe,&coded_bits_per_codeword,round, UE->dlsch[UE->current_thread_id[subframe]][0][0]->current_harq_pid);
+            LOG_M("dlsch_e.m","e",eNB->dlsch[0][0]->harq_processes[0]->e,coded_bits_per_codeword,1,4);
+            //pdcch_vars
+            LOG_M("pdcchF0_ext.m","pdcchF_ext", UE->pdcch_vars[0][eNB_id]->rxdataF_ext[0],2*3*UE->frame_parms.ofdm_symbol_size,1,1);
+            LOG_M("pdcch00_ch0_ext.m","pdcch00_ch0_ext",UE->pdcch_vars[0][eNB_id]->dl_ch_estimates_ext[0],300*3,1,1);
+            LOG_M("pdcch_rxF_comp0.m","pdcch0_rxF_comp0",UE->pdcch_vars[0][eNB_id]->rxdataF_comp[0],4*300,1,1);
+            LOG_M("pdcch_rxF_llr.m","pdcch_llr",UE->pdcch_vars[0][eNB_id]->llr,2400,1,4);
+          }
 
           if (UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->harq_ack[subframe].ack == 1) {
-
             avg_iter += UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->last_iteration_cnt;
             iter_trials++;
 
@@ -1872,18 +1661,13 @@ int main(int argc, char **argv)
 
             UE->total_TBS[eNB_id] =  UE->total_TBS[eNB_id] + UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->harq_processes[UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->current_harq_pid]->TBS;
             TB0_active = 0;
-
-
-	  } // DLSCH received ok
-	  else {
+          } // DLSCH received ok
+          else {
             errs[round]++;
-
             avg_iter += UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->last_iteration_cnt-1;
             iter_trials++;
 
             if (n_frames==1) {
-
-
               //if ((n_frames==1) || (SNR>=30)) {
               printf("DLSCH errors found (round %d), uncoded ber %f\n",round,(double)bit_errors/coded_bits_per_codeword);
 
@@ -1894,11 +1678,11 @@ int main(int argc, char **argv)
                   Kr = UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->Kplus;
 
                 Kr_bytes = Kr>>3;
-
                 printf("Decoded_output (Segment %d):\n",s);
 
                 for (i=0; i<Kr_bytes; i++)
-                  printf("%d : %x (%x)\n",i,UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->c[s][i],UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->c[s][i]^eNB->dlsch[0][0]->harq_processes[0]->c[s][i]);
+                  printf("%d : %x (%x)\n",i,UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->c[s][i],
+                         UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->c[s][i]^eNB->dlsch[0][0]->harq_processes[0]->c[s][i]);
               }
 
               sprintf(fname,"rxsig0_r%d.m",round);
@@ -1906,7 +1690,6 @@ int main(int argc, char **argv)
               LOG_M(fname,vname, &UE->common_vars.rxdata[0][0],10*UE->frame_parms.samples_per_tti,1,1);
               sprintf(fname,"rxsigF0_r%d.m",round);
               sprintf(vname,"rxs0F_r%d",round);
-
               LOG_M(fname,vname, &UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].rxdataF[0][0],UE->frame_parms.ofdm_symbol_size*nsymb,1,1);
 
               if (UE->frame_parms.nb_antennas_rx>1) {
@@ -1921,67 +1704,63 @@ int main(int argc, char **argv)
               sprintf(fname,"dlsch00_r%d.m",round);
               sprintf(vname,"dl00_r%d",round);
               LOG_M(fname,vname,
-                           &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][0][0]),
-                           UE->frame_parms.ofdm_symbol_size*nsymb,1,1);
+                    &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][0][0]),
+                    UE->frame_parms.ofdm_symbol_size*nsymb,1,1);
 
               if (UE->frame_parms.nb_antennas_rx>1) {
                 sprintf(fname,"dlsch01_r%d.m",round);
                 sprintf(vname,"dl01_r%d",round);
                 LOG_M(fname,vname,
-                             &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][1][0]),
-                             UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1);
+                      &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][1][0]),
+                      UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1);
               }
 
               if (eNB->frame_parms.nb_antennas_tx>1) {
                 sprintf(fname,"dlsch10_r%d.m",round);
                 sprintf(vname,"dl10_r%d",round);
                 LOG_M(fname,vname,
-                             &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][2][0]),
-                             UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1);
+                      &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][2][0]),
+                      UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1);
               }
 
               if ((UE->frame_parms.nb_antennas_rx>1) && (eNB->frame_parms.nb_antennas_tx>1)) {
                 sprintf(fname,"dlsch11_r%d.m",round);
                 sprintf(vname,"dl11_r%d",round);
                 LOG_M(fname,vname,
-                             &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][3][0]),
-                             UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1);
+                      &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][3][0]),
+                      UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1);
               }
 
               //pdsch_vars
               dump_dlsch2(UE,eNB_id,subframe,&coded_bits_per_codeword,round, UE->dlsch[UE->current_thread_id[subframe]][0][0]->current_harq_pid);
-
-
               //LOG_M("dlsch_e.m","e",eNB->dlsch[0][0]->harq_processes[0]->e,coded_bits_per_codeword,1,4);
               //LOG_M("dlsch_ber_bit.m","ber_bit",uncoded_ber_bit,coded_bits_per_codeword,1,0);
               //LOG_M("dlsch_w.m","w",eNB->dlsch[0][0]->harq_processes[0]->w[0],3*(tbs+64),1,4);
               //LOG_M("dlsch_w.m","w",UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->w[0],3*(tbs+64),1,0);
-	      //pdcch_vars
-	      LOG_M("pdcchF0_ext.m","pdcchF_ext", UE->pdcch_vars[0][eNB_id]->rxdataF_ext[0],2*3*UE->frame_parms.ofdm_symbol_size,1,1);
-	      LOG_M("pdcch00_ch0_ext.m","pdcch00_ch0_ext",UE->pdcch_vars[0][eNB_id]->dl_ch_estimates_ext[0],300*3,1,1);
-
-	      LOG_M("pdcch_rxF_comp0.m","pdcch0_rxF_comp0",UE->pdcch_vars[0][eNB_id]->rxdataF_comp[0],4*300,1,1);
-	      LOG_M("pdcch_rxF_llr.m","pdcch_llr",UE->pdcch_vars[0][eNB_id]->llr,2400,1,4);
+              //pdcch_vars
+              LOG_M("pdcchF0_ext.m","pdcchF_ext", UE->pdcch_vars[0][eNB_id]->rxdataF_ext[0],2*3*UE->frame_parms.ofdm_symbol_size,1,1);
+              LOG_M("pdcch00_ch0_ext.m","pdcch00_ch0_ext",UE->pdcch_vars[0][eNB_id]->dl_ch_estimates_ext[0],300*3,1,1);
+              LOG_M("pdcch_rxF_comp0.m","pdcch0_rxF_comp0",UE->pdcch_vars[0][eNB_id]->rxdataF_comp[0],4*300,1,1);
+              LOG_M("pdcch_rxF_llr.m","pdcch_llr",UE->pdcch_vars[0][eNB_id]->llr,2400,1,4);
 
               if (round == 3) exit(-1);
             }
 
             //      printf("round %d errors %d/%d\n",round,errs[round],trials);
-
             round++;
             //      UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->round++;
           }
 
-	  if (xforms==1) {
-	    phy_scope_UE(form_ue,
-			 UE,
-			 eNB_id,
-			 0,// UE_id
-			 subframe);
-	  }
+          if (xforms==1) {
+            phy_scope_UE(form_ue,
+                         UE,
+                         eNB_id,
+                         0,// UE_id
+                         subframe);
+          }
 
-	  UE->proc.proc_rxtx[UE->current_thread_id[subframe]].frame_rx++;
-	}  //round
+          UE->proc.proc_rxtx[UE->current_thread_id[subframe]].frame_rx++;
+        }  //round
 
         //      printf("\n");
 
@@ -1998,133 +1777,58 @@ int main(int argc, char **argv)
           UE->total_TBS_last[eNB_id] = UE->total_TBS[eNB_id];
         }
 
-
-
-
         /* calculate the total processing time for each packet,
          * get the max, min, and number of packets that exceed t>2000us
          */
-        double t_tx = (double)eNB->phy_proc_tx.p_time/cpu_freq_GHz/1000.0;
-        double t_tx_ifft = (double)eNB->ofdm_mod_stats.p_time/cpu_freq_GHz/1000.0;
-        double t_tx_mod = (double)eNB->dlsch_modulation_stats.p_time/cpu_freq_GHz/1000.0;
-        double t_tx_enc = (double)eNB->dlsch_encoding_stats.p_time/cpu_freq_GHz/1000.0;
-
-
-        double t_rx = (double)UE->phy_proc_rx[UE->current_thread_id[subframe]].p_time/cpu_freq_GHz/1000.0;
-        double t_rx_fft = (double)UE->ofdm_demod_stats.p_time/cpu_freq_GHz/1000.0;
-        double t_rx_demod = (double)UE->dlsch_rx_pdcch_stats.p_time/cpu_freq_GHz/1000.0;
-        double t_rx_dec = (double)UE->dlsch_decoding_stats[UE->current_thread_id[subframe]].p_time/cpu_freq_GHz/1000.0;
-
-        if (t_tx > t_tx_max)
-          t_tx_max = t_tx;
-
-        if (t_tx < t_tx_min)
-          t_tx_min = t_tx;
-
-        if (t_rx > t_rx_max)
-          t_rx_max = t_rx;
-
-        if (t_rx < t_rx_min)
-          t_rx_min = t_rx;
-
-        if (t_tx > 2000)
+        double t_tx = inMicroS(eNB->phy_proc_tx.p_time);
+        double t_tx_ifft = inMicroS(eNB->ofdm_mod_stats.p_time);
+        double t_rx = inMicroS(UE->phy_proc_rx[UE->current_thread_id[subframe]].p_time);
+        sumUpStats(&phy_proc_rx_tot, UE->phy_proc_rx, UE->current_thread_id[subframe]);
+        sumUpStats(&ue_front_end_tot, UE->ue_front_end_stat, UE->current_thread_id[subframe]);
+        sumUpStats(&pdsch_procedures_tot, UE->pdsch_procedures_stat, UE->current_thread_id[subframe]);
+        sumUpStats(&dlsch_procedures_tot, UE->dlsch_procedures_stat, UE->current_thread_id[subframe]);
+        sumUpStats(&dlsch_decoding_tot, UE->dlsch_decoding_stats, UE->current_thread_id[subframe]);
+        sumUpStatsSlot(&dlsch_llr_tot, UE->dlsch_llr_stats_parallelization, UE->current_thread_id[subframe]);
+        double t_rx_fft = inMicroS(UE->ofdm_demod_stats.p_time);
+        double t_rx_demod = inMicroS(UE->dlsch_rx_pdcch_stats.p_time);
+        double t_rx_dec = inMicroS(UE->dlsch_decoding_stats[UE->current_thread_id[subframe]].p_time);
+
+        if (t_tx > 2000 )// 2ms is too much time for a subframe
           n_tx_dropped++;
 
-        if (t_rx > 2000)
+        if (t_rx > 2000 )
           n_rx_dropped++;
 
-        push_front(&time_vector_tx, t_tx);
-        push_front(&time_vector_tx_ifft, t_tx_ifft);
-        push_front(&time_vector_tx_mod, t_tx_mod);
-        push_front(&time_vector_tx_enc, t_tx_enc);
-
-        push_front(&time_vector_rx, t_rx);
-        push_front(&time_vector_rx_fft, t_rx_fft);
-        push_front(&time_vector_rx_demod, t_rx_demod);
-        push_front(&time_vector_rx_dec, t_rx_dec);
-
-
+        appendVarArray(table_tx, &t_tx);
+        appendVarArray(table_tx_ifft, &t_tx_ifft);
+        appendVarArray(table_rx, &t_rx );
+        appendVarArray(table_rx_fft, &t_rx_fft );
+        appendVarArray(table_rx_demod, &t_rx_demod );
+        appendVarArray(table_rx_dec, &t_rx_dec );
       }   //trials
 
       // round_trials[0]: number of code word : goodput the protocol
-      double table_tx[time_vector_tx.size];
-      totable(table_tx, &time_vector_tx);
-      double table_tx_ifft[time_vector_tx_ifft.size];
-      totable(table_tx_ifft, &time_vector_tx_ifft);
-      double table_tx_mod[time_vector_tx_mod.size];
-      totable(table_tx_mod, &time_vector_tx_mod);
-      double table_tx_enc[time_vector_tx_enc.size];
-      totable(table_tx_enc, &time_vector_tx_enc);
-
-      double table_rx[time_vector_rx.size];
-      totable(table_rx, &time_vector_rx);
-      double table_rx_fft[time_vector_rx_fft.size];
-      totable(table_rx_fft, &time_vector_rx_fft);
-      double table_rx_demod[time_vector_rx_demod.size];
-      totable(table_rx_demod, &time_vector_rx_demod);
-      double table_rx_dec[time_vector_rx_dec.size];
-      totable(table_rx_dec, &time_vector_rx_dec);
-
-
       // sort table
-      qsort (table_tx, time_vector_tx.size, sizeof(double), &compare);
-      qsort (table_rx, time_vector_rx.size, sizeof(double), &compare);
+      qsort (dataArray(table_tx), table_tx->size, table_tx->atomSize, &cmpdouble);
+      qsort (dataArray(table_tx_ifft), table_tx_ifft->size, table_tx_ifft->atomSize, &cmpdouble);
+      qsort (dataArray(table_tx_mod), table_tx_mod->size, table_tx_mod->atomSize, &cmpdouble);
+      qsort (dataArray(table_tx_enc), table_tx_enc->size, table_tx_enc->atomSize, &cmpdouble);
+      qsort (dataArray(table_rx), table_rx->size, table_rx->atomSize, &cmpdouble);
+      qsort (dataArray(table_rx_fft), table_rx_fft->size, table_rx_fft->atomSize, &cmpdouble);
+      qsort (dataArray(table_rx_demod), table_rx_demod->size, table_rx_demod->atomSize, &cmpdouble);
+      qsort (dataArray(table_rx_dec), table_rx_dec->size, table_rx_dec->atomSize, &cmpdouble);
 
       if (dump_table == 1 ) {
         set_component_filelog(SIM);  // file located in /tmp/usim.txt
-        LOG_UDUMPMSG(SIM,table_tx,time_vector_tx.size,LOG_DUMP_DOUBLE,"The transmitter raw data: \n");
-        LOG_UDUMPMSG(SIM,table_rx,time_vector_rx.size,LOG_DUMP_DOUBLE,"Thereceiver raw data: \n");
+        LOG_UDUMPMSG(SIM,table_tx,table_tx->size,LOG_DUMP_DOUBLE,"The transmitter raw data: \n");
+        LOG_UDUMPMSG(SIM,table_rx,table_rx->size,LOG_DUMP_DOUBLE,"Thereceiver raw data: \n");
       }
 
-      double tx_median = table_tx[time_vector_tx.size/2];
-      double tx_q1 = table_tx[time_vector_tx.size/4];
-      double tx_q3 = table_tx[3*time_vector_tx.size/4];
-
-      double tx_ifft_median = table_tx_ifft[time_vector_tx_ifft.size/2];
-      double tx_ifft_q1 = table_tx_ifft[time_vector_tx_ifft.size/4];
-      double tx_ifft_q3 = table_tx_ifft[3*time_vector_tx_ifft.size/4];
-
-      double tx_mod_median = table_tx_mod[time_vector_tx_mod.size/2];
-      double tx_mod_q1 = table_tx_mod[time_vector_tx_mod.size/4];
-      double tx_mod_q3 = table_tx_mod[3*time_vector_tx_mod.size/4];
-
-      double tx_enc_median = table_tx_enc[time_vector_tx_enc.size/2];
-      double tx_enc_q1 = table_tx_enc[time_vector_tx_enc.size/4];
-      double tx_enc_q3 = table_tx_enc[3*time_vector_tx_enc.size/4];
-
-      double rx_median = table_rx[time_vector_rx.size/2];
-      double rx_q1 = table_rx[time_vector_rx.size/4];
-      double rx_q3 = table_rx[3*time_vector_rx.size/4];
-
-      double rx_fft_median = table_rx_fft[time_vector_rx_fft.size/2];
-      double rx_fft_q1 = table_rx_fft[time_vector_rx_fft.size/4];
-      double rx_fft_q3 = table_rx_fft[3*time_vector_rx_fft.size/4];
-
-      double rx_demod_median = table_rx_demod[time_vector_rx_demod.size/2];
-      double rx_demod_q1 = table_rx_demod[time_vector_rx_demod.size/4];
-      double rx_demod_q3 = table_rx_demod[3*time_vector_rx_demod.size/4];
-
-      double rx_dec_median = table_rx_dec[time_vector_rx_dec.size/2];
-      double rx_dec_q1 = table_rx_dec[time_vector_rx_dec.size/4];
-      double rx_dec_q3 = table_rx_dec[3*time_vector_rx_dec.size/4];
-
-      double std_phy_proc_tx=0;
-      double std_phy_proc_tx_ifft=0;
-      double std_phy_proc_tx_mod=0;
-      double std_phy_proc_tx_enc=0;
-
-      double std_phy_proc_rx=0;
-      double std_phy_proc_rx_fft=0;
-      double std_phy_proc_rx_demod=0;
-      double std_phy_proc_rx_dec=0;
-
       effective_rate = 1.0-((double)(errs[0]+errs[1]+errs[2]+errs[3])/((double)round_trials[0] + round_trials[1] + round_trials[2] + round_trials[3]));
-
       printf("\n**********************SNR = %f dB (tx_lev %f)**************************\n",
              SNR,
              (double)tx_lev_dB+10*log10(UE->frame_parms.ofdm_symbol_size/(NB_RB*12)));
-
-      printf("Errors (%d(%d)/%d %d/%d %d/%d %d/%d), Pe = (%e,%e,%e,%e), dci_errors %d/%d, Pe = %e => effective rate %f, normalized delay %f (%f)\n",
+      printf("Errors (%u(%u)/%u %u/%u %u/%u %u/%u), Pe = (%e,%e,%e,%e), dci_errors %u/%u, Pe = %e => effective rate %f, normalized delay %f (%f)\n",
              errs[0],
              errs2[0],
              round_trials[0],
@@ -2148,113 +1852,52 @@ int main(int argc, char **argv)
              (1.0*(round_trials[0]-errs[0])+2.0*(round_trials[1]-errs[1])+3.0*(round_trials[2]-errs[2])+4.0*(round_trials[3]-errs[3]))/((double)round_trials[0])/
              (double)eNB->dlsch[0][0]->harq_processes[0]->TBS,
              (1.0*(round_trials[0]-errs[0])+2.0*(round_trials[1]-errs[1])+3.0*(round_trials[2]-errs[2])+4.0*(round_trials[3]-errs[3]))/((double)round_trials[0]));
+      double timeBase=1/(1000*cpu_freq_GHz);
 
       if (print_perf==1) {
-        printf("eNB TX function statistics (per 1ms subframe)\n\n");
-        std_phy_proc_tx = sqrt((double)eNB->phy_proc_tx.diff_square/pow(cpu_freq_GHz,2)/pow(1000,
-                               2)/eNB->phy_proc_tx.trials - pow((double)eNB->phy_proc_tx.diff/eNB->phy_proc_tx.trials/cpu_freq_GHz/1000,2));
-        std_phy_proc_tx_ifft = sqrt((double)eNB->ofdm_mod_stats.diff_square/pow(cpu_freq_GHz,2)/pow(1000,
-                                    2)/eNB->ofdm_mod_stats.trials - pow((double)eNB->ofdm_mod_stats.diff/eNB->ofdm_mod_stats.trials/cpu_freq_GHz/1000,2));
-        printf("OFDM_mod time                     :%f us (%d trials)\n",(double)eNB->ofdm_mod_stats.diff/eNB->ofdm_mod_stats.trials/cpu_freq_GHz/1000.0,eNB->ofdm_mod_stats.trials);
-        printf("|__ Statistcs                           std: %fus median %fus q1 %fus q3 %fus \n",std_phy_proc_tx_ifft, tx_ifft_median, tx_ifft_q1, tx_ifft_q3);
-        printf("Total PHY proc tx                 :%f us (%d trials)\n",(double)eNB->phy_proc_tx.diff/eNB->phy_proc_tx.trials/cpu_freq_GHz/1000.0,eNB->phy_proc_tx.trials);
-        printf("|__ Statistcs                           std: %fus max: %fus min: %fus median %fus q1 %fus q3 %fus n_dropped: %d packet \n",std_phy_proc_tx, t_tx_max, t_tx_min, tx_median, tx_q1, tx_q3,
-               n_tx_dropped);
-
-        std_phy_proc_tx_mod = sqrt((double)eNB->dlsch_modulation_stats.diff_square/pow(cpu_freq_GHz,2)/pow(1000,
-                                   2)/eNB->dlsch_modulation_stats.trials - pow((double)eNB->dlsch_modulation_stats.diff/eNB->dlsch_modulation_stats.trials/cpu_freq_GHz/1000,2));
-        printf("DLSCH modulation time             :%f us (%d trials)\n",(double)eNB->dlsch_modulation_stats.diff/eNB->dlsch_modulation_stats.trials/cpu_freq_GHz/1000.0,
-               eNB->dlsch_modulation_stats.trials);
-        printf("|__ Statistcs                           std: %fus median %fus q1 %fus q3 %fus \n",std_phy_proc_tx_mod, tx_mod_median, tx_mod_q1, tx_mod_q3);
-        printf("DLSCH scrambling time             :%f us (%d trials)\n",(double)eNB->dlsch_scrambling_stats.diff/eNB->dlsch_scrambling_stats.trials/cpu_freq_GHz/1000.0,
-               eNB->dlsch_scrambling_stats.trials);
-        std_phy_proc_tx_enc = sqrt((double)eNB->dlsch_encoding_stats.diff_square/pow(cpu_freq_GHz,2)/pow(1000,
-                                   2)/eNB->dlsch_encoding_stats.trials - pow((double)eNB->dlsch_encoding_stats.diff/eNB->dlsch_encoding_stats.trials/cpu_freq_GHz/1000,2));
-        printf("DLSCH encoding time               :%f us (%d trials)\n",(double)eNB->dlsch_encoding_stats.diff/eNB->dlsch_encoding_stats.trials/cpu_freq_GHz/1000.0,
-               eNB->dlsch_modulation_stats.trials);
-        printf("|__ Statistcs                           std: %fus median %fus q1 %fus q3 %fus \n",std_phy_proc_tx_enc, tx_enc_median, tx_enc_q1, tx_enc_q3);
-        printf("|__ DLSCH turbo encoding time         :%f us (%d trials)\n",
-               ((double)eNB->dlsch_turbo_encoding_stats.trials/eNB->dlsch_encoding_stats.trials)*(double)
-               eNB->dlsch_turbo_encoding_stats.diff/eNB->dlsch_turbo_encoding_stats.trials/cpu_freq_GHz/1000.0,eNB->dlsch_turbo_encoding_stats.trials);
-        printf("|__ DLSCH rate-matching time          :%f us (%d trials)\n",
-               ((double)eNB->dlsch_rate_matching_stats.trials/eNB->dlsch_encoding_stats.trials)*(double)
-               eNB->dlsch_rate_matching_stats.diff/eNB->dlsch_rate_matching_stats.trials/cpu_freq_GHz/1000.0,eNB->dlsch_rate_matching_stats.trials);
-        printf("|__ DLSCH sub-block interleaving time :%f us (%d trials)\n",
-               ((double)eNB->dlsch_interleaving_stats.trials/eNB->dlsch_encoding_stats.trials)*(double)
-               eNB->dlsch_interleaving_stats.diff/eNB->dlsch_interleaving_stats.trials/cpu_freq_GHz/1000.0,eNB->dlsch_interleaving_stats.trials);
-
-        printf("\n\nUE RX function statistics (per 1ms subframe)\n\n");
-        std_phy_proc_rx = sqrt((double)UE->phy_proc_rx[UE->current_thread_id[subframe]].diff_square/pow(cpu_freq_GHz,2)/pow(1000,
-                               2)/UE->phy_proc_rx[UE->current_thread_id[subframe]].trials - pow((double)UE->phy_proc_rx[UE->current_thread_id[subframe]].diff/UE->phy_proc_rx[UE->current_thread_id[subframe]].trials/cpu_freq_GHz/1000,2));
-        printf("Total PHY proc rx                                   :%f us (%d trials)\n",(double)UE->phy_proc_rx[UE->current_thread_id[subframe]].diff/UE->phy_proc_rx[UE->current_thread_id[subframe]].trials/cpu_freq_GHz/1000.0,
-               UE->phy_proc_rx[UE->current_thread_id[subframe]].trials*2/3);
-        printf("|__Statistcs                                            std: %fus max: %fus min: %fus median %fus q1 %fus q3 %fus n_dropped: %d packet \n", std_phy_proc_rx, t_rx_max, t_rx_min, rx_median,
-               rx_q1, rx_q3, n_rx_dropped);
-        std_phy_proc_rx_fft = sqrt((double)UE->ofdm_demod_stats.diff_square/pow(cpu_freq_GHz,2)/pow(1000,
-                                   2)/UE->ofdm_demod_stats.trials - pow((double)UE->ofdm_demod_stats.diff/UE->ofdm_demod_stats.trials/cpu_freq_GHz/1000,2));
-        printf("DLSCH OFDM demodulation and channel_estimation time :%f us (%d trials)\n",(nsymb)*(double)UE->ofdm_demod_stats.diff/UE->ofdm_demod_stats.trials/cpu_freq_GHz/1000.0,
-               UE->ofdm_demod_stats.trials*2/3);
-        printf("|__ Statistcs                           std: %fus median %fus q1 %fus q3 %fus \n",std_phy_proc_rx_fft, rx_fft_median, rx_fft_q1, rx_fft_q3);
-        printf("|__ DLSCH rx dft                                        :%f us (%d trials)\n",
-               (nsymb*UE->frame_parms.nb_antennas_rx)*(double)UE->rx_dft_stats.diff/UE->rx_dft_stats.trials/cpu_freq_GHz/1000.0,UE->rx_dft_stats.trials*2/3);
-        printf("|__ DLSCH channel estimation time                       :%f us (%d trials)\n",
-               (4.0)*(double)UE->dlsch_channel_estimation_stats.diff/UE->dlsch_channel_estimation_stats.trials/cpu_freq_GHz/1000.0,UE->dlsch_channel_estimation_stats.trials*2/3);
-        printf("|__ DLSCH frequency offset estimation time              :%f us (%d trials)\n",
-               (4.0)*(double)UE->dlsch_freq_offset_estimation_stats.diff/UE->dlsch_freq_offset_estimation_stats.trials/cpu_freq_GHz/1000.0,
-               UE->dlsch_freq_offset_estimation_stats.trials*2/3);
-        printf("DLSCH rx pdcch                                       :%f us (%d trials)\n",(double)UE->dlsch_rx_pdcch_stats.diff/UE->dlsch_rx_pdcch_stats.trials/cpu_freq_GHz/1000.0,
-               UE->dlsch_rx_pdcch_stats.trials);
-        std_phy_proc_rx_demod = sqrt((double)UE->dlsch_llr_stats.diff_square/pow(cpu_freq_GHz,2)/pow(1000,
-                                     2)/UE->dlsch_llr_stats.trials - pow((double)UE->dlsch_llr_stats.diff/UE->dlsch_llr_stats.trials/cpu_freq_GHz/1000,2));
-        printf("DLSCH Channel Compensation and LLR generation time  :%f us (%d trials)\n",(14-num_pdcch_symbols)*(double)UE->dlsch_llr_stats.diff/UE->dlsch_llr_stats.trials/cpu_freq_GHz/1000.0,
-               UE->dlsch_llr_stats.trials/3);
-        printf("|__ Statistcs                           std: %fus median %fus q1 %fus q3 %fus \n",std_phy_proc_rx_demod, rx_demod_median, rx_demod_q1, rx_demod_q3);
-        printf("DLSCH unscrambling time                             :%f us (%d trials)\n",(double)UE->dlsch_unscrambling_stats.diff/UE->dlsch_unscrambling_stats.trials/cpu_freq_GHz/1000.0,
-               UE->dlsch_unscrambling_stats.trials);
-        std_phy_proc_rx_dec = sqrt((double)UE->dlsch_decoding_stats[UE->current_thread_id[subframe]].diff_square/pow(cpu_freq_GHz,2)/pow(1000,
-                                   2)/UE->dlsch_decoding_stats[UE->current_thread_id[subframe]].trials - pow((double)UE->dlsch_decoding_stats[UE->current_thread_id[subframe]].diff/UE->dlsch_decoding_stats[UE->current_thread_id[subframe]].trials/cpu_freq_GHz/1000,2));
-        printf("DLSCH Decoding time (%02.2f Mbit/s, avg iter %1.2f)    :%f us (%d trials, max %f)\n",
-               eNB->dlsch[0][0]->harq_processes[0]->TBS/1000.0,(double)avg_iter/iter_trials,
-               (double)UE->dlsch_decoding_stats[UE->current_thread_id[subframe]].diff/UE->dlsch_decoding_stats[UE->current_thread_id[subframe]].trials/cpu_freq_GHz/1000.0,UE->dlsch_decoding_stats[UE->current_thread_id[subframe]].trials,
-               (double)UE->dlsch_decoding_stats[UE->current_thread_id[subframe]].max/cpu_freq_GHz/1000.0);
-        printf("|__ Statistcs                           std: %fus median %fus q1 %fus q3 %fus \n",std_phy_proc_rx_dec, rx_dec_median, rx_dec_q1, rx_dec_q3);
-        printf("|__ DLSCH Rate Unmatching                               :%f us (%d trials)\n",
-               (double)UE->dlsch_rate_unmatching_stats.diff/UE->dlsch_rate_unmatching_stats.trials/cpu_freq_GHz/1000.0,UE->dlsch_rate_unmatching_stats.trials);
-        printf("|__ DLSCH Turbo Decoding(%d bits)                       :%f us (%d trials)\n",
-               UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->Cminus ? UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->Kminus : UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->Kplus,
-               (double)UE->dlsch_turbo_decoding_stats.diff/UE->dlsch_turbo_decoding_stats.trials/cpu_freq_GHz/1000.0,UE->dlsch_turbo_decoding_stats.trials);
-        printf("    |__ init                                            %f us (cycles/iter %f, %d trials)\n",
-               (double)UE->dlsch_tc_init_stats.diff/UE->dlsch_tc_init_stats.trials/cpu_freq_GHz/1000.0,
-               (double)UE->dlsch_tc_init_stats.diff/UE->dlsch_tc_init_stats.trials/((double)avg_iter/iter_trials),
-               UE->dlsch_tc_init_stats.trials);
-        printf("    |__ alpha                                           %f us (cycles/iter %f, %d trials)\n",
-               (double)UE->dlsch_tc_alpha_stats.diff/UE->dlsch_tc_alpha_stats.trials/cpu_freq_GHz/1000.0,
-               (double)UE->dlsch_tc_alpha_stats.diff/UE->dlsch_tc_alpha_stats.trials*2,
-               UE->dlsch_tc_alpha_stats.trials);
-        printf("    |__ beta                                            %f us (cycles/iter %f,%d trials)\n",
-               (double)UE->dlsch_tc_beta_stats.diff/UE->dlsch_tc_beta_stats.trials/cpu_freq_GHz/1000.0,
-               (double)UE->dlsch_tc_beta_stats.diff/UE->dlsch_tc_beta_stats.trials*2,
-               UE->dlsch_tc_beta_stats.trials);
-        printf("    |__ gamma                                           %f us (cycles/iter %f,%d trials)\n",
-               (double)UE->dlsch_tc_gamma_stats.diff/UE->dlsch_tc_gamma_stats.trials/cpu_freq_GHz/1000.0,
-               (double)UE->dlsch_tc_gamma_stats.diff/UE->dlsch_tc_gamma_stats.trials*2,
-               UE->dlsch_tc_gamma_stats.trials);
-        printf("    |__ ext                                             %f us (cycles/iter %f,%d trials)\n",
-               (double)UE->dlsch_tc_ext_stats.diff/UE->dlsch_tc_ext_stats.trials/cpu_freq_GHz/1000.0,
-               (double)UE->dlsch_tc_ext_stats.diff/UE->dlsch_tc_ext_stats.trials*2,
-               UE->dlsch_tc_ext_stats.trials);
-        printf("    |__ intl1                                           %f us (cycles/iter %f,%d trials)\n",
-               (double)UE->dlsch_tc_intl1_stats.diff/UE->dlsch_tc_intl1_stats.trials/cpu_freq_GHz/1000.0,
-               (double)UE->dlsch_tc_intl1_stats.diff/UE->dlsch_tc_intl1_stats.trials,
-               UE->dlsch_tc_intl1_stats.trials);
-        printf("    |__ intl2+HD+CRC                                    %f us (cycles/iter %f,%d trials)\n",
-               (double)UE->dlsch_tc_intl2_stats.diff/UE->dlsch_tc_intl2_stats.trials/cpu_freq_GHz/1000.0,
-               (double)UE->dlsch_tc_intl2_stats.diff/UE->dlsch_tc_intl2_stats.trials,
-               UE->dlsch_tc_intl2_stats.trials);
+        printf("\neNB TX function statistics (per 1ms subframe)\n");
+        printDistribution(&eNB->phy_proc_tx,table_tx,"PHY proc tx");
+        printStatIndent(&eNB->dlsch_common_and_dci,"DL common channels and dci time");
+        printStatIndent(&eNB->dlsch_ue_specific,"DL per ue part time");
+        printStatIndent2(&eNB->dlsch_encoding_stats,"DLSCH encoding time");
+        printStatIndent3(&eNB->dlsch_rate_matching_stats,"DLSCH rate matching time");
+        printStatIndent3(&eNB->dlsch_turbo_encoding_stats,"DLSCH turbo encoding time");
+        printStatIndent3(&eNB->dlsch_interleaving_stats,"DLSCH interleaving time");
+        printStatIndent2(&eNB->dlsch_scrambling_stats,  "DLSCH scrambling time");
+        printStatIndent2(&eNB->dlsch_modulation_stats, "DLSCH modulation time");
+        printDistribution(&eNB->ofdm_mod_stats,table_tx_ifft,"OFDM_mod (idft) time");
+        printf("\nUE RX function statistics (per 1ms subframe)\n");
+        printDistribution(&phy_proc_rx_tot, table_rx,"Total PHY proc rx");
+        printStatIndent(&ue_front_end_tot,"Front end processing");
+        printStatIndent(&dlsch_llr_tot,"rx_pdsch processing");
+        printStatIndent2(&pdsch_procedures_tot,"pdsch processing");
+        printStatIndent2(&dlsch_procedures_tot,"dlsch processing");
+        printStatIndent2(&UE->crnti_procedures_stats,"C-RNTI processing");
+        printStatIndent(&UE->ofdm_demod_stats,"ofdm demodulation");
+        printStatIndent(&UE->dlsch_channel_estimation_stats,"DLSCH channel estimation time");
+        printStatIndent(&UE->dlsch_freq_offset_estimation_stats,"DLSCH frequency offset estimation time");
+        printStatIndent(&dlsch_decoding_tot, "DLSCH Decoding time ");
+        printStatIndent(&UE->dlsch_unscrambling_stats,"DLSCH unscrambling time");
+        printStatIndent(&UE->dlsch_rate_unmatching_stats,"DLSCH Rate Unmatching");
+        printf("|__ DLSCH Turbo Decoding(%d bits), avg iterations: %.1f       %.2f us (%d cycles, %d trials)\n",
+               UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->Cminus ?
+               UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->Kminus :
+               UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->Kplus,
+               UE->dlsch_tc_intl1_stats.trials/(double)UE->dlsch_tc_init_stats.trials,
+               (double)UE->dlsch_turbo_decoding_stats.diff/UE->dlsch_turbo_decoding_stats.trials*timeBase,
+               (int)((double)UE->dlsch_turbo_decoding_stats.diff/UE->dlsch_turbo_decoding_stats.trials),
+               UE->dlsch_turbo_decoding_stats.trials);
+        printStatIndent2(&UE->dlsch_tc_init_stats,"init");
+        printStatIndent2(&UE->dlsch_tc_alpha_stats,"alpha");
+        printStatIndent2(&UE->dlsch_tc_beta_stats,"beta");
+        printStatIndent2(&UE->dlsch_tc_gamma_stats,"gamma");
+        printStatIndent2(&UE->dlsch_tc_ext_stats,"ext");
+        printStatIndent2(&UE->dlsch_tc_intl1_stats,"turbo internal interleaver");
+        printStatIndent2(&UE->dlsch_tc_intl2_stats,"intl2+HardDecode+CRC");
       }
 
       if ((transmission_mode != 3) && (transmission_mode != 4)) {
-        fprintf(bler_fd,"%f;%d;%d;%f;%d;%d;%d;%d;%d;%d;%d;%d;%d\n",
+        fprintf(bler_fd,"%f;%d;%d;%f;%u;%u;%u;%u;%u;%u;%u;%u;%u\n",
                 SNR,
                 mcs1,
                 eNB->dlsch[0][0]->harq_processes[0]->TBS,
@@ -2269,7 +1912,7 @@ int main(int argc, char **argv)
                 round_trials[3],
                 dci_errors[0]);
       } else {
-        fprintf(bler_fd,"%f;%d;%d;%d;%d;%f;%d;%d;%d;%d;%d;%d;%d;%d;%d\n",
+        fprintf(bler_fd,"%f;%d;%d;%d;%d;%f;%u;%u;%u;%u;%u;%u;%u;%u;%u\n",
                 SNR,
                 mcs1,mcs2,
                 eNB->dlsch[0][0]->harq_processes[0]->TBS,
@@ -2286,7 +1929,6 @@ int main(int argc, char **argv)
                 dci_errors[0]);
       }
 
-
       if(abstx) { //ABSTRACTION
         blerr[0] = (double)errs[0]/(round_trials[0]);
 
@@ -2303,7 +1945,7 @@ int main(int argc, char **argv)
       if ( (test_perf != 0) && (100 * effective_rate > test_perf )) {
         //fprintf(time_meas_fd,"SNR; MCS; TBS; rate; err0; trials0; err1; trials1; err2; trials2; err3; trials3; dci_err\n");
         if ((transmission_mode != 3) && (transmission_mode != 4)) {
-          fprintf(time_meas_fd,"%f;%d;%d;%f;%d;%d;%d;%d;%d;%d;%d;%d;%d;",
+          fprintf(time_meas_fd,"%f;%d;%d;%f;%u;%u;%u;%u;%u;%u;%u;%u;%u;",
                   SNR,
                   mcs1,
                   eNB->dlsch[0][0]->harq_processes[0]->TBS,
@@ -2317,9 +1959,8 @@ int main(int argc, char **argv)
                   errs[3],
                   round_trials[3],
                   dci_errors[0]);
-
           //fprintf(time_meas_fd,"SNR; MCS; TBS; rate; DL_DECOD_ITER; err0; trials0; err1; trials1; err2; trials2; err3; trials3; PE; dci_err;PE;ND;\n");
-          fprintf(time_meas_fd,"%f;%d;%d;%f; %2.1f%%;%f;%f;%d;%d;%d;%d;%d;%d;%d;%d;%e;%e;%e;%e;%d;%d;%e;%f;%f;",
+          fprintf(time_meas_fd,"%f;%d;%d;%f; %2.1f%%;%f;%f;%u;%u;%u;%u;%u;%u;%u;%u;%e;%e;%e;%e;%u;%u;%e;%f;%f;",
                   SNR,
                   mcs1,
                   eNB->dlsch[0][0]->harq_processes[0]->TBS,
@@ -2346,7 +1987,7 @@ int main(int argc, char **argv)
                   (double)eNB->dlsch[0][0]->harq_processes[0]->TBS,
                   (1.0*(round_trials[0]-errs[0])+2.0*(round_trials[1]-errs[1])+3.0*(round_trials[2]-errs[2])+4.0*(round_trials[3]-errs[3]))/((double)round_trials[0]));
         } else {
-          fprintf(time_meas_fd,"%f;%d;%d;%d;%d;%f;%d;%d;%d;%d;%d;%d;%d;%d;%d;",
+          fprintf(time_meas_fd,"%f;%d;%d;%d;%d;%f;%u;%u;%u;%u;%u;%u;%u;%u;%u;",
                   SNR,
                   mcs1,mcs2,
                   eNB->dlsch[0][0]->harq_processes[0]->TBS,
@@ -2361,9 +2002,8 @@ int main(int argc, char **argv)
                   errs[3],
                   round_trials[3],
                   dci_errors[0]);
-
           //fprintf(time_meas_fd,"SNR; MCS; TBS; rate; DL_DECOD_ITER; err0; trials0; err1; trials1; err2; trials2; err3; trials3; PE; dci_err;PE;ND;\n");
-          fprintf(time_meas_fd,"%f;%d;%d;%d;%d;%f;%2.1f;%f;%f;%d;%d;%d;%d;%d;%d;%d;%d;%e;%e;%e;%e;%d;%d;%e;%f;%f;",
+          fprintf(time_meas_fd,"%f;%d;%d;%d;%d;%f;%2.1f;%f;%f;%u;%u;%u;%u;%u;%u;%u;%u;%e;%e;%e;%e;%u;%u;%e;%f;%f;",
                   SNR,
                   mcs1,mcs2,
                   eNB->dlsch[0][0]->harq_processes[0]->TBS,
@@ -2399,7 +2039,7 @@ int main(int argc, char **argv)
                 eNB->dlsch_modulation_stats.trials,
                 eNB->dlsch_scrambling_stats.trials,
                 eNB->dlsch_encoding_stats.trials,
-                UE->phy_proc_rx[UE->current_thread_id[subframe]].trials,
+                phy_proc_rx_tot.trials,
                 UE->ofdm_demod_stats.trials,
                 UE->dlsch_rx_pdcch_stats.trials,
                 UE->dlsch_llr_stats.trials,
@@ -2412,7 +2052,7 @@ int main(int argc, char **argv)
                 get_time_meas_us(&eNB->dlsch_modulation_stats),
                 get_time_meas_us(&eNB->dlsch_scrambling_stats),
                 get_time_meas_us(&eNB->dlsch_encoding_stats),
-                get_time_meas_us(&UE->phy_proc_rx[UE->current_thread_id[subframe]]),
+                get_time_meas_us(&phy_proc_rx_tot),
                 nsymb*get_time_meas_us(&UE->ofdm_demod_stats),
                 get_time_meas_us(&UE->dlsch_rx_pdcch_stats),
                 3*get_time_meas_us(&UE->dlsch_llr_stats),
@@ -2420,61 +2060,48 @@ int main(int argc, char **argv)
                 get_time_meas_us(&UE->dlsch_decoding_stats[UE->current_thread_id[subframe]])
                );
         //fprintf(time_meas_fd,"eNB_PROC_TX_STD;eNB_PROC_TX_MAX;eNB_PROC_TX_MIN;eNB_PROC_TX_MED;eNB_PROC_TX_Q1;eNB_PROC_TX_Q3;eNB_PROC_TX_DROPPED;\n");
-        fprintf(time_meas_fd,"%f;%f;%f;%f;%f;%f;%d;", std_phy_proc_tx, t_tx_max, t_tx_min, tx_median, tx_q1, tx_q3, n_tx_dropped);
-
+        fprintf(time_meas_fd,"%f;%f;%f;%f;%f;%f;%d;",squareRoot(&UE->phy_proc_tx), t_tx_max, t_tx_min, median(table_tx), q1(table_tx), q3(table_tx), n_tx_dropped);
         //fprintf(time_meas_fd,"IFFT;\n");
-        fprintf(time_meas_fd,"%f;%f;%f;%f;", std_phy_proc_tx_ifft, tx_ifft_median, tx_ifft_q1, tx_ifft_q3);
-
+        fprintf(time_meas_fd,"%f;%f;%f;%f;",
+                squareRoot(&eNB->ofdm_mod_stats),
+                median(table_tx_ifft),q1(table_tx_ifft),q3(table_tx_ifft));
         //fprintf(time_meas_fd,"MOD;\n");
-        fprintf(time_meas_fd,"%f;%f;%f;%f;", std_phy_proc_tx_mod, tx_mod_median, tx_mod_q1, tx_mod_q3);
-
+        fprintf(time_meas_fd,"%f;%f;%f;%f;",
+                squareRoot(&eNB->dlsch_modulation_stats),
+                median(table_tx_mod), q1(table_tx_mod), q3(table_tx_mod));
         //fprintf(time_meas_fd,"ENC;\n");
-        fprintf(time_meas_fd,"%f;%f;%f;%f;", std_phy_proc_tx_enc, tx_enc_median, tx_enc_q1, tx_enc_q3);
-
-
-        //fprintf(time_meas_fd,"UE_PROC_RX_STD;UE_PROC_RX_MAX;UE_PROC_RX_MIN;UE_PROC_RX_MED;UE_PROC_RX_Q1;UE_PROC_RX_Q3;UE_PROC_RX_DROPPED;\n");
-        fprintf(time_meas_fd,"%f;%f;%f;%f;%f;%f;%d;", std_phy_proc_rx, t_rx_max, t_rx_min, rx_median, rx_q1, rx_q3, n_rx_dropped);
-
+        fprintf(time_meas_fd,"%f;%f;%f;%f;",
+                squareRoot(&eNB->dlsch_encoding_stats),
+                median(table_tx_enc),q1(table_tx_enc),q3(table_tx_enc));
+        //fprintf(time_meas_fd,"eNB_PROC_RX_STD;eNB_PROC_RX_MAX;eNB_PROC_RX_MIN;eNB_PROC_RX_MED;eNB_PROC_RX_Q1;eNB_PROC_RX_Q3;eNB_PROC_RX_DROPPED;\n");
+        fprintf(time_meas_fd,"%f;%f;%f;%f;%f;%f;%d;",
+                squareRoot(&phy_proc_rx_tot), t_rx_max, t_rx_min,
+                median(table_rx), q1(table_rx), q3(table_rx), n_rx_dropped);
         //fprintf(time_meas_fd,"FFT;\n");
-        fprintf(time_meas_fd,"%f;%f;%f;%f;", std_phy_proc_rx_fft, rx_fft_median, rx_fft_q1, rx_fft_q3);
-
+        fprintf(time_meas_fd,"%f;%f;%f;%f;",
+                squareRoot(&UE->ofdm_demod_stats),
+                median(table_rx_fft), q1(table_rx_fft), q3(table_rx_fft));
         //fprintf(time_meas_fd,"DEMOD;\n");
-        fprintf(time_meas_fd,"%f;%f;%f;%f;", std_phy_proc_rx_demod,rx_demod_median, rx_demod_q1, rx_demod_q3);
-
+        fprintf(time_meas_fd,"%f;%f;%f;%f;",
+                squareRoot(&UE->dlsch_demodulation_stats),
+                median(table_rx_demod), q1(table_rx_demod), q3(table_rx_demod));
         //fprintf(time_meas_fd,"DEC;\n");
-        fprintf(time_meas_fd,"%f;%f;%f;%f\n", std_phy_proc_rx_dec, rx_dec_median, rx_dec_q1, rx_dec_q3);
-
-
-        /*
-        fprintf(time_meas_fd,"%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;",
-        eNB->phy_proc_tx.trials,
-        eNB->ofdm_mod_stats.trials,
-        eNB->dlsch_modulation_stats.trials,
-        eNB->dlsch_scrambling_stats.trials,
-        eNB->dlsch_encoding_stats.trials,
-        UE->phy_proc_rx[UE->current_thread_id[subframe]].trials,
-        UE->ofdm_demod_stats.trials,
-        UE->dlsch_rx_pdcch_stats.trials,
-        UE->dlsch_llr_stats.trials,
-        UE->dlsch_unscrambling_stats.trials,
-        UE->dlsch_decoding_stats[UE->current_thread_id[subframe]].trials);
-        */
+        fprintf(time_meas_fd,"%f;%f;%f;%f\n",
+                squareRoot(&UE->dlsch_decoding_stats[subframe]),
+                median(table_rx_dec), q1(table_rx_dec), q3(table_rx_dec));
         printf("[passed] effective rate : %f  (%2.1f%%,%f)): log and break \n",rate*effective_rate, 100*effective_rate, rate );
-	test_passed = 1;
+        test_passed = 1;
         break;
       } else if (test_perf !=0 ) {
         printf("[continue] effective rate : %f  (%2.1f%%,%f)): increase snr \n",rate*effective_rate, 100*effective_rate, rate);
-	test_passed = 0;
+        test_passed = 0;
       }
 
       if (((double)errs[0]/(round_trials[0]))<(10.0/n_frames))
         break;
     }// SNR
-
-
   } //ch_realization
 
-
   fclose(bler_fd);
 
   if (test_perf !=0)
@@ -2498,7 +2125,6 @@ int main(int argc, char **argv)
     free(uncoded_ber_bit);
 
   uncoded_ber_bit = NULL;
-
   printf("Freeing dlsch structures\n");
 
   for (i=0; i<2; i++) {
diff --git a/openair1/SIMULATION/LTE_PHY/dlsim_tm7.c b/openair1/SIMULATION/LTE_PHY/dlsim_tm7.c
index 570c13c0b64f0abec0a817b1cfc1223583fffb61..5973f80b55a59f662490e960cb5f295e3ae2267b 100644
--- a/openair1/SIMULATION/LTE_PHY/dlsim_tm7.c
+++ b/openair1/SIMULATION/LTE_PHY/dlsim_tm7.c
@@ -68,14 +68,11 @@ double t_rx_min = 1000000000; /*!< \brief initial min process time for rx */
 int n_tx_dropped = 0; /*!< \brief initial max process time for tx */
 int n_rx_dropped = 0; /*!< \brief initial max process time for rx */
 
-void handler(int sig)
-{
+void handler(int sig) {
   void *array[10];
   size_t size;
-
   // get void*'s for all entries on the stack
   size = backtrace(array, 10);
-
   // print out all the frames to stderr
   fprintf(stderr, "Error: signal %d:\n", sig);
   backtrace_symbols_fd(array, size, 2);
@@ -94,28 +91,21 @@ uint64_t DLSCH_alloc_pdu_1[2];
 //#define DLSCH_RB_ALLOC 0x1fbf // igore DC component,RB13
 //#define DLSCH_RB_ALLOC 0x0001
 
-int main(int argc, char **argv)
-{
-
+int main(int argc, char **argv) {
   int c;
   int k,i,j,aa,aarx,aatx;
   int re;
-
   int s,Kr,Kr_bytes;
-
   double sigma2, sigma2_dB=10,SNR,snr0=-2.0,snr1,rate;
   double snr_step=1,input_snr_step=1, snr_int=30;
-
   LTE_DL_FRAME_PARMS *frame_parms;
   double **s_re,**s_im,**r_re,**r_im;
   double forgetting_factor=0.0; //in [0,1] 0 means a new channel every time, 1 means keep the same channel
   double iqim=0.0;
-
   uint8_t extended_prefix_flag=0,transmission_mode=1,n_tx_port=1,n_tx_phy=1,n_rx=1;
   uint16_t Nid_cell=0;
   int32_t **cell_spec_bf_weights;
   int32_t *ue_spec_bf_weights;
-
   int eNB_id = 0, eNB_id_i = 1;
   unsigned char mcs1=0,mcs2=0,mcs_i=0,dual_stream_UE = 0,awgn_flag=0,round,dci_flag=0;
   unsigned char i_mod = 2;
@@ -124,15 +114,12 @@ int main(int argc, char **argv)
   uint16_t tdd_config=3;
   uint16_t n_rnti=0x1234;
   int n_users = 1;
-
   SCM_t channel_model=Rayleigh1;
   //  unsigned char *input_data,*decoded_output;
-
   unsigned char *input_buffer0[2],*input_buffer1[2];
   unsigned short input_buffer_length0,input_buffer_length1;
   unsigned int ret;
   unsigned int coded_bits_per_codeword=0,nsymb,dci_cnt,tbs=0;
-
   unsigned int tx_lev=0,tx_lev_dB=0,trials,errs[4]= {0,0,0,0},errs2[4]= {0,0,0,0},round_trials[4]= {0,0,0,0},dci_errors=0,dlsch_active=0;//,num_layers;
   int re_allocated;
   char fname[32],vname[32];
@@ -142,23 +129,17 @@ int main(int argc, char **argv)
   char time_meas_fname[256];
   //  FILE *tikz_fd;
   //  char tikz_fname[256];
-
   FILE *input_trch_fd=NULL;
   unsigned char input_trch_file=0;
   FILE *input_fd=NULL;
   unsigned char input_file=0;
   //  char input_val_str[50],input_val_str2[50];
-
   char input_trch_val[16];
   double channelx,channely;
-
   unsigned char pbch_pdu[6];
-
   DCI_ALLOC_t dci_alloc[8],dci_alloc_rx[8];
   int num_common_dci=0,num_ue_spec_dci=0,num_dci=0;
-
   //  FILE *rx_frame_file;
-
   int n_frames;
   int n_ch_rlz = 1;
   channel_desc_t *eNB2UE[4];
@@ -178,7 +159,6 @@ int main(int argc, char **argv)
   int ch_realization;
   int pmi_feedback=0;
   int hold_channel=0;
-
   // void *data;
   // int ii;
   //  int bler;
@@ -194,7 +174,6 @@ int main(int argc, char **argv)
   int dci_length_bytes=0,dci_length=0;
   //double channel_bandwidth = 5.0, sampling_rate=7.68;
   int common_flag=0,TPC=0;
-
   double cpu_freq_GHz;
   //  time_stats_t ts;//,sts,usts;
   int avg_iter,iter_trials;
@@ -203,50 +182,40 @@ int main(int argc, char **argv)
   int test_perf=0;
   int dump_table=0;
   int llr8_flag=0;
-
   double effective_rate=0.0;
   char channel_model_input[10]="I";
-
   int TB0_active = 1;
   uint32_t perfect_ce = 0;
-
   //  LTE_DL_UE_HARQ_t *dlsch0_ue_harq;
   //  LTE_DL_eNB_HARQ_t *dlsch0_eNB_harq;
   uint8_t Kmimo;
   uint8_t ue_category=4;
   uint32_t Nsoft;
-
-
-
   int CCE_table[800];
-
   int threequarter_fs=0;
-
   opp_enabled=1; // to enable the time meas
-
 #if defined(__arm__)
   FILE    *proc_fd = NULL;
   char buf[64];
-
   proc_fd = fopen("/sys/devices/system/cpu/cpu4/cpufreq/cpuinfo_cur_freq", "r");
-  if(!proc_fd)
-     printf("cannot open /sys/devices/system/cpu/cpu4/cpufreq/cpuinfo_cur_freq");
-  else {
-     while(fgets(buf, 63, proc_fd))
-        printf("%s", buf);
+
+  if(!proc_fd) {
+    printf("cannot open /sys/devices/system/cpu/cpu4/cpufreq/cpuinfo_cur_freq");
+    exit(-1);
+  } else {
+    while(fgets(buf, 63, proc_fd))
+      printf("%s", buf);
   }
+
   fclose(proc_fd);
   cpu_freq_GHz = ((double)atof(buf))/1e6;
 #else
   cpu_freq_GHz = get_cpu_freq_GHz();
 #endif
   printf("Detected cpu_freq %f GHz\n",cpu_freq_GHz);
-
   //signal(SIGSEGV, handler);
   //signal(SIGABRT, handler);
-
   logInit();
-
   // default parameters
   n_frames = 1000;
   snr0 = 0;
@@ -255,362 +224,363 @@ int main(int argc, char **argv)
 
   while ((c = getopt (argc, argv, "ahdpZDe:Em:n:o:s:f:t:c:g:r:F:x:p:y:z:AM:N:I:i:O:R:S:C:T:b:u:v:w:B:PLl:XY")) != -1) {
     switch (c) {
-    case 'a':
-      awgn_flag = 1;
-      channel_model = AWGN;
-      break;
-
-    case 'A':
-      abstx = 1;
-      break;
-
-    case 'b':
-      tdd_config=atoi(optarg);
-      break;
-
-    case 'B':
-      N_RB_DL=atoi(optarg);
-      break;
-
-    case 'c':
-      num_pdcch_symbols=atoi(optarg);
-      break;
-
-    case 'C':
-      Nid_cell = atoi(optarg);
-      break;
-
-    case 'd':
-      dci_flag = 1;
-      break;
-
-    case 'D':
-      frame_type=TDD;
-      break;
-
-    case 'e':
-      num_rounds=1;
-      common_flag = 1;
-      TPC = atoi(optarg);
-      break;
-      
-    case 'E':
-      threequarter_fs=1;
-      break;
-
-    case 'f':
-      input_snr_step= atof(optarg);
-      break;
-
-    case 'F':
-      forgetting_factor = atof(optarg);
-      break;
-
-    case 'i':
-      input_fd = fopen(optarg,"r");
-      input_file=1;
-      dci_flag = 1;
-      break;
-
-    case 'I':
-      input_trch_fd = fopen(optarg,"r");
-      input_trch_file=1;
-      break;
-
-    case 'L':
-      llr8_flag=1;
-      break;
-
-    case 'l':
-      offset_mumimo_llr_drange_fix=atoi(optarg);
-      break;
-
-    case 'm':
-      mcs1 = atoi(optarg);
-      break;
+      case 'a':
+        awgn_flag = 1;
+        channel_model = AWGN;
+        break;
 
-    case 'M':
-      mcs2 = atoi(optarg);
-      break;
+      case 'A':
+        abstx = 1;
+        break;
 
-    case 'O':
-      test_perf=atoi(optarg);
-      //print_perf =1;
-      break;
+      case 'b':
+        tdd_config=atoi(optarg);
+        break;
 
-    case 't':
-      mcs_i = atoi(optarg);
-      i_mod = get_Qm(mcs_i);
-      break;
+      case 'B':
+        N_RB_DL=atoi(optarg);
+        break;
 
-    case 'n':
-      n_frames = atoi(optarg);
-      break;
+      case 'c':
+        num_pdcch_symbols=atoi(optarg);
+        break;
 
-    case 'o':
-      rx_sample_offset = atoi(optarg);
-      break;
+      case 'C':
+        Nid_cell = atoi(optarg);
+        break;
 
-    case 'r':
-      DLSCH_RB_ALLOC = atoi(optarg);
-      rballocset = 1;
-      break;
+      case 'd':
+        dci_flag = 1;
+        break;
 
-    case 's':
-      snr0 = atof(optarg);
-      break;
+      case 'D':
+        frame_type=TDD;
+        break;
 
-    case 'w':
-      snr_int = atof(optarg);
-      break;
+      case 'e':
+        num_rounds=1;
+        common_flag = 1;
+        TPC = atoi(optarg);
+        break;
 
-    case 'N':
-      n_ch_rlz= atof(optarg);
-      break;
+      case 'E':
+        threequarter_fs=1;
+        break;
 
-    case 'p':
-      extended_prefix_flag=1;
-      break;
+      case 'f':
+        input_snr_step= atof(optarg);
+        break;
 
-    case 'g':
-      memcpy(channel_model_input,optarg,10);
+      case 'F':
+        forgetting_factor = atof(optarg);
+        break;
 
-      switch((char)*optarg) {
-      case 'A':
-        channel_model=SCM_A;
+      case 'i':
+        input_fd = fopen(optarg,"r");
+        input_file=1;
+        dci_flag = 1;
         break;
 
-      case 'B':
-        channel_model=SCM_B;
+      case 'I':
+        input_trch_fd = fopen(optarg,"r");
+        input_trch_file=1;
         break;
 
-      case 'C':
-        channel_model=SCM_C;
+      case 'L':
+        llr8_flag=1;
         break;
 
-      case 'D':
-        channel_model=SCM_D;
+      case 'l':
+        offset_mumimo_llr_drange_fix=atoi(optarg);
         break;
 
-      case 'E':
-        channel_model=EPA;
+      case 'm':
+        mcs1 = atoi(optarg);
         break;
 
-      case 'F':
-        channel_model=EVA;
+      case 'M':
+        mcs2 = atoi(optarg);
         break;
 
-      case 'G':
-        channel_model=ETU;
+      case 'O':
+        test_perf=atoi(optarg);
+        //print_perf =1;
         break;
 
-      case 'H':
-        channel_model=Rayleigh8;
+      case 't':
+        mcs_i = atoi(optarg);
+        i_mod = get_Qm(mcs_i);
         break;
 
-      case 'I':
-        channel_model=Rayleigh1;
+      case 'n':
+        n_frames = atoi(optarg);
         break;
 
-      case 'J':
-        channel_model=Rayleigh1_corr;
+      case 'o':
+        rx_sample_offset = atoi(optarg);
         break;
 
-      case 'K':
-        channel_model=Rayleigh1_anticorr;
+      case 'r':
+        DLSCH_RB_ALLOC = atoi(optarg);
+        rballocset = 1;
         break;
 
-      case 'L':
-        channel_model=Rice8;
+      case 's':
+        snr0 = atof(optarg);
         break;
 
-      case 'M':
-        channel_model=Rice1;
+      case 'w':
+        snr_int = atof(optarg);
         break;
 
       case 'N':
-        channel_model=AWGN;
+        n_ch_rlz= atof(optarg);
         break;
-      default:
-        msg("Unsupported channel model!\n");
-        exit(-1);
-      }
 
-      break;
+      case 'p':
+        extended_prefix_flag=1;
+        break;
 
-    case 'R':
-      num_rounds=atoi(optarg);
-      break;
+      case 'g':
+        memcpy(channel_model_input,optarg,10);
 
-    case 'S':
-      subframe=atoi(optarg);
-      break;
+        switch((char)*optarg) {
+          case 'A':
+            channel_model=SCM_A;
+            break;
 
-    case 'T':
-      n_rnti=atoi(optarg);
-      break;
+          case 'B':
+            channel_model=SCM_B;
+            break;
 
-    case 'u':
-      dual_stream_UE=1;
-      UE->use_ia_receiver = 1;
+          case 'C':
+            channel_model=SCM_C;
+            break;
 
-      if ((n_tx_port!=2) || (transmission_mode!=5)) {
-        msg("IA receiver only supported for TM5!");
-        exit(-1);
-      }
+          case 'D':
+            channel_model=SCM_D;
+            break;
 
-      break;
+          case 'E':
+            channel_model=EPA;
+            break;
 
-    case 'v':
-      i_mod = atoi(optarg);
+          case 'F':
+            channel_model=EVA;
+            break;
 
-      if (i_mod!=2 && i_mod!=4 && i_mod!=6) {
-        msg("Wrong i_mod %d, should be 2,4 or 6\n",i_mod);
-        exit(-1);
-      }
+          case 'G':
+            channel_model=ETU;
+            break;
 
-      break;
+          case 'H':
+            channel_model=Rayleigh8;
+            break;
 
-    case 'P':
-      print_perf=1;
-      break;
+          case 'I':
+            channel_model=Rayleigh1;
+            break;
 
-    case 'q':
-      n_tx_port=atoi(optarg);
+          case 'J':
+            channel_model=Rayleigh1_corr;
+            break;
 
-      if ((n_tx_port==0) || ((n_tx_port>2))) {
-        msg("Unsupported number of cell specific antennas ports %d\n",n_tx_port);
-        exit(-1);
-      }
+          case 'K':
+            channel_model=Rayleigh1_anticorr;
+            break;
 
-      break;
+          case 'L':
+            channel_model=Rice8;
+            break;
 
+          case 'M':
+            channel_model=Rice1;
+            break;
 
-    case 'x':
-      transmission_mode=atoi(optarg);
+          case 'N':
+            channel_model=AWGN;
+            break;
 
-      if ((transmission_mode!=1) &&
-          (transmission_mode!=2) &&
-          (transmission_mode!=3) &&
-          (transmission_mode!=4) &&
-          (transmission_mode!=5) &&
-          (transmission_mode!=6) &&
-          (transmission_mode!=7)) {
-        msg("Unsupported transmission mode %d\n",transmission_mode);
-        exit(-1);
-      }
+          default:
+            msg("Unsupported channel model!\n");
+            exit(-1);
+        }
 
-      if (transmission_mode>1 && transmission_mode<7) {
-        n_tx_port = 2;
-      }
+        break;
 
-      break;
+      case 'R':
+        num_rounds=atoi(optarg);
+        break;
+
+      case 'S':
+        subframe=atoi(optarg);
+        break;
 
-    case 'y':
-      n_tx_phy=atoi(optarg);
-      
-      if (transmission_mode>1&&transmission_mode<7) {
-        if(n_tx_phy==1) {
-          msg("n_tx_phy must be >1 for transmission_mode %d\n",transmission_mode);
+      case 'T':
+        n_rnti=atoi(optarg);
+        break;
+
+      case 'u':
+        dual_stream_UE=1;
+        UE->use_ia_receiver = 1;
+
+        if ((n_tx_port!=2) || (transmission_mode!=5)) {
+          msg("IA receiver only supported for TM5!");
           exit(-1);
-        } 
-      }
+        }
 
-      if (transmission_mode==7 && (n_tx_phy!=1 && n_tx_phy!=2 && n_tx_phy!=4 && n_tx_phy!=8 && n_tx_phy!=16 && n_tx_phy!=64 && n_tx_phy!=128)) {
-        msg("Physical number of antennas not supported for TM7.\n");
-        exit(-1);
-      }
+        break;
 
-      break;
+      case 'v':
+        i_mod = atoi(optarg);
 
-    case 'X':
-      xforms=1;
-      break;
+        if (i_mod!=2 && i_mod!=4 && i_mod!=6) {
+          msg("Wrong i_mod %d, should be 2,4 or 6\n",i_mod);
+          exit(-1);
+        }
 
-    case 'Y':
-      perfect_ce=1;
-      break;
+        break;
 
-    case 'z':
-      n_rx=atoi(optarg);
+      case 'P':
+        print_perf=1;
+        break;
 
-      if ((n_rx==0) || (n_rx>2)) {
-        msg("Unsupported number of rx antennas %d\n",n_rx);
-        exit(-1);
-      }
+      case 'q':
+        n_tx_port=atoi(optarg);
 
-      break;
+        if ((n_tx_port==0) || ((n_tx_port>2))) {
+          msg("Unsupported number of cell specific antennas ports %d\n",n_tx_port);
+          exit(-1);
+        }
 
-    case 'Z':
-      dump_table=1;
-      break;
+        break;
 
+      case 'x':
+        transmission_mode=atoi(optarg);
+
+        if ((transmission_mode!=1) &&
+            (transmission_mode!=2) &&
+            (transmission_mode!=3) &&
+            (transmission_mode!=4) &&
+            (transmission_mode!=5) &&
+            (transmission_mode!=6) &&
+            (transmission_mode!=7)) {
+          msg("Unsupported transmission mode %d\n",transmission_mode);
+          exit(-1);
+        }
 
+        if (transmission_mode>1 && transmission_mode<7) {
+          n_tx_port = 2;
+        }
 
-    case 'h':
-    default:
-      printf("%s -h(elp) -a(wgn on) -d(ci decoding on) -p(extended prefix on) -m mcs1 -M mcs2 -n n_frames -s snr0 -x transmission mode (1,2,5,6,7) -y TXant -z RXant -I trch_file\n",argv[0]);
-      printf("-h This message\n");
-      printf("-a Use AWGN channel and not multipath\n");
-      printf("-c Number of PDCCH symbols\n");
-      printf("-m MCS1 for TB 1\n");
-      printf("-M MCS2 for TB 2\n");
-      printf("-d Transmit the DCI and compute its error statistics and the overall throughput\n");
-      printf("-p Use extended prefix mode\n");
-      printf("-n Number of frames to simulate\n");
-      printf("-o Sample offset for receiver\n");
-      printf("-s Starting SNR, runs from SNR to SNR+%.1fdB in steps of %.1fdB. If n_frames is 1 then just SNR is simulated and MATLAB/OCTAVE output is generated\n", snr_int, snr_step);
-      printf("-f step size of SNR, default value is 1.\n");
-      printf("-r ressource block allocation (see  section 7.1.6.3 in 36.213\n");
-      printf("-g [A:M] Use 3GPP 25.814 SCM-A/B/C/D('A','B','C','D') or 36-101 EPA('E'), EVA ('F'),ETU('G') models (ignores delay spread and Ricean factor), Rayghleigh8 ('H'), Rayleigh1('I'), Rayleigh1_corr('J'), Rayleigh1_anticorr ('K'), Rice8('L'), Rice1('M')\n");
-      printf("-F forgetting factor (0 new channel every trial, 1 channel constant\n");
-      printf("-x Transmission mode (1,2,6,7 for the moment)\n");
-      printf("-q Number of TX antennas ports used in eNB\n");
-      printf("-y Number of physical TX antennas used in eNB\n");
-      printf("-z Number of RX antennas used in UE\n");
-      printf("-t MCS of interfering UE\n");
-      printf("-R Number of HARQ rounds (fixed)\n");
-      printf("-A Turns on calibration mode for abstraction.\n");
-      printf("-N Determines the number of Channel Realizations in Abstraction mode. Default value is 1. \n");
-      printf("-O Set the percenatge of effective rate to testbench the modem performance (typically 30 and 70, range 1-100) \n");
-      printf("-I Input filename for TrCH data (binary)\n");
-      printf("-u Enables the Interference Aware Receiver for TM5 (default is normal receiver)\n");
-      exit(1);
-      break;
+        break;
+
+      case 'y':
+        n_tx_phy=atoi(optarg);
+
+        if (transmission_mode>1&&transmission_mode<7) {
+          if(n_tx_phy==1) {
+            msg("n_tx_phy must be >1 for transmission_mode %d\n",transmission_mode);
+            exit(-1);
+          }
+        }
+
+        if (transmission_mode==7 && (n_tx_phy!=1 && n_tx_phy!=2 && n_tx_phy!=4 && n_tx_phy!=8 && n_tx_phy!=16 && n_tx_phy!=64 && n_tx_phy!=128)) {
+          msg("Physical number of antennas not supported for TM7.\n");
+          exit(-1);
+        }
+
+        break;
+
+      case 'X':
+        xforms=1;
+        break;
+
+      case 'Y':
+        perfect_ce=1;
+        break;
+
+      case 'z':
+        n_rx=atoi(optarg);
+
+        if ((n_rx==0) || (n_rx>2)) {
+          msg("Unsupported number of rx antennas %d\n",n_rx);
+          exit(-1);
+        }
+
+        break;
+
+      case 'Z':
+        dump_table=1;
+        break;
+
+      case 'h':
+      default:
+        printf("%s -h(elp) -a(wgn on) -d(ci decoding on) -p(extended prefix on) -m mcs1 -M mcs2 -n n_frames -s snr0 -x transmission mode (1,2,5,6,7) -y TXant -z RXant -I trch_file\n",argv[0]);
+        printf("-h This message\n");
+        printf("-a Use AWGN channel and not multipath\n");
+        printf("-c Number of PDCCH symbols\n");
+        printf("-m MCS1 for TB 1\n");
+        printf("-M MCS2 for TB 2\n");
+        printf("-d Transmit the DCI and compute its error statistics and the overall throughput\n");
+        printf("-p Use extended prefix mode\n");
+        printf("-n Number of frames to simulate\n");
+        printf("-o Sample offset for receiver\n");
+        printf("-s Starting SNR, runs from SNR to SNR+%.1fdB in steps of %.1fdB. If n_frames is 1 then just SNR is simulated and MATLAB/OCTAVE output is generated\n", snr_int, snr_step);
+        printf("-f step size of SNR, default value is 1.\n");
+        printf("-r ressource block allocation (see  section 7.1.6.3 in 36.213\n");
+        printf("-g [A:M] Use 3GPP 25.814 SCM-A/B/C/D('A','B','C','D') or 36-101 EPA('E'), EVA ('F'),ETU('G') models (ignores delay spread and Ricean factor), Rayghleigh8 ('H'), Rayleigh1('I'), Rayleigh1_corr('J'), Rayleigh1_anticorr ('K'), Rice8('L'), Rice1('M')\n");
+        printf("-F forgetting factor (0 new channel every trial, 1 channel constant\n");
+        printf("-x Transmission mode (1,2,6,7 for the moment)\n");
+        printf("-q Number of TX antennas ports used in eNB\n");
+        printf("-y Number of physical TX antennas used in eNB\n");
+        printf("-z Number of RX antennas used in UE\n");
+        printf("-t MCS of interfering UE\n");
+        printf("-R Number of HARQ rounds (fixed)\n");
+        printf("-A Turns on calibration mode for abstraction.\n");
+        printf("-N Determines the number of Channel Realizations in Abstraction mode. Default value is 1. \n");
+        printf("-O Set the percenatge of effective rate to testbench the modem performance (typically 30 and 70, range 1-100) \n");
+        printf("-I Input filename for TrCH data (binary)\n");
+        printf("-u Enables the Interference Aware Receiver for TM5 (default is normal receiver)\n");
+        exit(1);
+        break;
     }
   }
 
   if (common_flag == 0) {
     switch (N_RB_DL) {
-    case 6:
-      if (rballocset==0) DLSCH_RB_ALLOC = 0x3f;
-      num_pdcch_symbols = 3;
-      break;
+      case 6:
+        if (rballocset==0) DLSCH_RB_ALLOC = 0x3f;
 
-    case 25:
-      if (rballocset==0) DLSCH_RB_ALLOC = 0x1fff;
-      break;
+        num_pdcch_symbols = 3;
+        break;
 
-    case 50:
-      if (rballocset==0) DLSCH_RB_ALLOC = 0x1ffff;
-      break;
+      case 25:
+        if (rballocset==0) DLSCH_RB_ALLOC = 0x1fff;
 
-    case 100:
-      if (rballocset==0) DLSCH_RB_ALLOC = 0x1ffffff;
-      break;
+        break;
+
+      case 50:
+        if (rballocset==0) DLSCH_RB_ALLOC = 0x1ffff;
+
+        break;
+
+      case 100:
+        if (rballocset==0) DLSCH_RB_ALLOC = 0x1ffffff;
+
+        break;
     }
 
     NB_RB=conv_nprb(0,DLSCH_RB_ALLOC,N_RB_DL);
   } else
     NB_RB = 4;
 
-
   if (xforms==1) {
     fl_initialize (&argc, argv, NULL, 0, 0);
     form_ue = create_lte_phy_scope_ue();
     sprintf (title, "LTE PHY SCOPE eNB");
     fl_show_form (form_ue->lte_phy_scope_ue, FL_PLACE_HOTSPOT, FL_FULLBORDER, title);
-    
+
     if (!dual_stream_UE==0) {
       UE->use_ia_receiver = 1;
       fl_set_button(form_ue->button_0,1);
@@ -625,9 +595,7 @@ int main(int argc, char **argv)
   }
 
   lte_param_init(n_tx_port,n_tx_phy,n_rx,transmission_mode,extended_prefix_flag,frame_type,Nid_cell,tdd_config,N_RB_DL,threequarter_fs,osf,perfect_ce);
-
   frame_parms = &eNB->frame_parms;
-
   /*
   cell_spec_bf_weights = eNB->common_vars.beam_weights[0][0];
   for(aa=0;aa<n_tx_phy;aa++) {
@@ -641,35 +609,27 @@ int main(int argc, char **argv)
       else if (n_tx_phy==64)
         cell_spec_bf_weights[aa][re] = 0x00007fff>>4;
     }
-  } 
+  }
 
   if (transmission_mode==7){
     lte_gold_ue_spec_port5(eNB->lte_gold_uespec_port5_table[0],Nid_cell,n_rnti);
     lte_gold_ue_spec_port5(UE->lte_gold_uespec_port5_table,Nid_cell,n_rnti);
   }*/
-
-    
   eNB_id_i = UE->n_connected_eNB;
-
   printf("Setting mcs1 = %d\n",mcs1);
   printf("Setting mcs2 = %d\n",mcs2);
   printf("NPRB = %d\n",NB_RB);
   printf("n_frames = %d\n",n_frames);
   printf("Transmission mode %d with %dx%d antenna configuration, Extended Prefix %d\n",transmission_mode,n_tx_phy,n_rx,extended_prefix_flag);
-
   snr1 = snr0+snr_int;
   printf("SNR0 %f, SNR1 %f\n",snr0,snr1);
-
-
-  s_re = malloc(n_tx_phy*sizeof(double*));
-  s_im = malloc(n_tx_phy*sizeof(double*));
-  r_re = malloc(2*sizeof(double*));
-  r_im = malloc(2*sizeof(double*));
+  s_re = malloc(n_tx_phy*sizeof(double *));
+  s_im = malloc(n_tx_phy*sizeof(double *));
+  r_re = malloc(2*sizeof(double *));
+  r_im = malloc(2*sizeof(double *));
   //  r_re0 = malloc(2*sizeof(double*));
   //  r_im0 = malloc(2*sizeof(double*));
-
   nsymb = (eNB->frame_parms.Ncp == 0) ? 14 : 12;
-
   printf("Channel Model= (%s,%d)\n",channel_model_input, channel_model);
   printf("SCM-A=%d, SCM-B=%d, SCM-C=%d, SCM-D=%d, EPA=%d, EVA=%d, ETU=%d, Rayleigh8=%d, Rayleigh1=%d, Rayleigh1_corr=%d, Rayleigh1_anticorr=%d, Rice1=%d, Rice8=%d\n",
          SCM_A, SCM_B, SCM_C, SCM_D, EPA, EVA, ETU, Rayleigh8, Rayleigh1, Rayleigh1_corr, Rayleigh1_anticorr, Rice1, Rice8);
@@ -680,10 +640,12 @@ int main(int argc, char **argv)
     sprintf(bler_fname,"bler_tm%d_chan%d_perfce%d_ntx%d_nrx%d_mcs%d.csv",transmission_mode,channel_model,perfect_ce,n_tx_phy,n_rx,mcs1);
 
   bler_fd = fopen(bler_fname,"w");
+
   if (bler_fd==NULL) {
     fprintf(stderr,"Cannot create file %s!\n",bler_fname);
     exit(-1);
   }
+
   fprintf(bler_fd,"SNR; MCS; TBS; rate; err0; trials0; err1; trials1; err2; trials2; err3; trials3; dci_err\n");
 
   if (test_perf != 0) {
@@ -697,6 +659,7 @@ int main(int argc, char **argv)
             N_RB_DL,mcs1,n_tx_phy,n_rx,num_pdcch_symbols,channel_model_input,transmission_mode);
     //mkdir(dirname,0777);
     time_meas_fd = fopen(time_meas_fname,"w");
+
     if (time_meas_fd==NULL) {
       fprintf(stderr,"Cannot create file %s!\n",time_meas_fname);
       exit(-1);
@@ -707,11 +670,11 @@ int main(int argc, char **argv)
     // CSV file
     sprintf(csv_fname,"dataout_tx%d_u2%d_mcs%d_chan%d_nsimus%d_R%d.m",transmission_mode,dual_stream_UE,mcs1,channel_model,n_frames,num_rounds);
     csv_fd = fopen(csv_fname,"w");
-    fprintf(csv_fd,"data_all%d=[",mcs1);
     if (csv_fd==NULL) {
       fprintf(stderr,"Cannot create file %s!\n",csv_fname);
       exit(-1);
     }
+    fprintf(csv_fd,"data_all%d=[",mcs1);
   }
 
   /*
@@ -811,7 +774,7 @@ int main(int argc, char **argv)
     }
   */
 
-  for (i=0; i<n_tx_phy; i++){
+  for (i=0; i<n_tx_phy; i++) {
     s_re[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
     s_im[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
   }
@@ -825,9 +788,7 @@ int main(int argc, char **argv)
     //    bzero(r_im0[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
   }
 
-
   UE->pdcch_vars[0]->crnti = n_rnti;
-
   // Fill in UL_alloc
   UL_alloc_pdu.type    = 0;
   UL_alloc_pdu.hopping = 0;
@@ -836,14 +797,12 @@ int main(int argc, char **argv)
   UL_alloc_pdu.ndi     = 1;
   UL_alloc_pdu.TPC     = 0;
   UL_alloc_pdu.cqi_req = 1;
-
   CCCH_alloc_pdu.type               = 0;
   CCCH_alloc_pdu.vrb_type           = 0;
   CCCH_alloc_pdu.rballoc            = CCCH_RB_ALLOC;
   CCCH_alloc_pdu.ndi      = 1;
   CCCH_alloc_pdu.mcs      = 1;
   CCCH_alloc_pdu.harq_pid = 0;
-
   DLSCH_alloc_pdu2_1E[0].rah              = 0;
   DLSCH_alloc_pdu2_1E[0].rballoc          = DLSCH_RB_ALLOC;
   DLSCH_alloc_pdu2_1E[0].TPC              = 0;
@@ -856,7 +815,6 @@ int main(int argc, char **argv)
   // Forget second codeword
   DLSCH_alloc_pdu2_1E[0].tpmi             = (transmission_mode>=5 ? 5 : 0);  // precoding
   DLSCH_alloc_pdu2_1E[0].dl_power_off     = (transmission_mode==5 ? 0 : 1);
-
   DLSCH_alloc_pdu2_1E[1].rah              = 0;
   DLSCH_alloc_pdu2_1E[1].rballoc          = DLSCH_RB_ALLOC;
   DLSCH_alloc_pdu2_1E[1].TPC              = 0;
@@ -869,12 +827,11 @@ int main(int argc, char **argv)
   // Forget second codeword
   DLSCH_alloc_pdu2_1E[1].tpmi             = (transmission_mode>=5 ? 5 : 0) ;  // precoding
   DLSCH_alloc_pdu2_1E[1].dl_power_off     = (transmission_mode==5 ? 0 : 1);
-
   eNB2UE[0] = new_channel_desc_scm(eNB->frame_parms.nb_antennas_tx,
                                    UE->frame_parms.nb_antennas_rx,
                                    channel_model,
                                    N_RB2sampling_rate(eNB->frame_parms.N_RB_DL),
-				   N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL),
+                                   N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL),
                                    forgetting_factor,
                                    rx_sample_offset,
                                    0);
@@ -884,9 +841,9 @@ int main(int argc, char **argv)
       eNB2UE[n] = new_channel_desc_scm(eNB->frame_parms.nb_antennas_tx,
                                        UE->frame_parms.nb_antennas_rx,
                                        channel_model,
-				       N_RB2sampling_rate(eNB->frame_parms.N_RB_DL),
-				       N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL),
-				       forgetting_factor,
+                                       N_RB2sampling_rate(eNB->frame_parms.N_RB_DL),
+                                       N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL),
+                                       forgetting_factor,
                                        rx_sample_offset,
                                        0);
   }
@@ -902,20 +859,23 @@ int main(int argc, char **argv)
     Kmimo=1;
 
   switch (ue_category) {
-  case 1:
-    Nsoft = 250368;
-    break;
-  case 2:
-  case 3:
-    Nsoft = 1237248;
-    break;
-  case 4:
-    Nsoft = 1827072;
-    break;
-  default:
-    printf("Unsupported UE category %d\n",ue_category);
-    exit(-1);
-    break;
+    case 1:
+      Nsoft = 250368;
+      break;
+
+    case 2:
+    case 3:
+      Nsoft = 1237248;
+      break;
+
+    case 4:
+      Nsoft = 1827072;
+      break;
+
+    default:
+      printf("Unsupported UE category %d\n",ue_category);
+      exit(-1);
+      break;
   }
 
   for (k=0; k<n_users; k++) {
@@ -927,12 +887,12 @@ int main(int argc, char **argv)
         printf("Can't get eNB dlsch structures\n");
         exit(-1);
       } else {
-         // this initilisation may should be moved to another place
-        for (j=0; j<4; j++) {                                                            
-          for (aa=0; aa<n_tx_phy; aa++) {                                          
+        // this initilisation may should be moved to another place
+        for (j=0; j<4; j++) {
+          for (aa=0; aa<n_tx_phy; aa++) {
             ue_spec_bf_weights = eNB->dlsch[k][i]->ue_spec_bf_weights[j][aa];
 
-            for (re=0;re<OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES;re++) {
+            for (re=0; re<OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES; re++) {
               if (n_tx_phy==1 || n_tx_phy==2)
                 ue_spec_bf_weights[re] = 0x00007fff;
               else if (n_tx_phy==4 || n_tx_phy==8)
@@ -942,10 +902,8 @@ int main(int argc, char **argv)
               else if (n_tx_phy==64)
                 ue_spec_bf_weights[re] = 0x00007fff>>4;
             }
-
           }
-        } 
-
+        }
       }
 
       eNB->dlsch[k][i]->rnti = n_rnti+k;
@@ -967,7 +925,6 @@ int main(int argc, char **argv)
   UE->dlsch_eNB[0] = new_eNB_dlsch(Kmimo,8,Nsoft,N_RB_DL,0,&eNB->frame_parms);
 
   if (DLSCH_alloc_pdu2_1E[0].tpmi == 5) {
-
     eNB->UE_stats[0].DL_pmi_single = (unsigned short)(taus()&0xffff);
 
     if (n_users>1)
@@ -984,8 +941,6 @@ int main(int argc, char **argv)
   //read_calibration_matrix(calib_fname, nb_ant, nb_freq, eNB->common_vars.tdd_calib_coeffs[0]);
 
   if (input_fd==NULL) {
-
-
     /*
     // common DCI
     memcpy(&dci_alloc[num_dci].dci_pdu[0],&CCCH_alloc_pdu,sizeof(DCI1A_5MHz_TDD_1_6_t));
@@ -999,955 +954,917 @@ int main(int argc, char **argv)
     // UE specific DCI
     for(k=0; k<n_users; k++) {
       switch(transmission_mode) {
-      case 1:
-      case 2:
-      case 7:
-        if (common_flag == 0) {
-
-          if (eNB->frame_parms.frame_type == TDD) {
-
-            switch (eNB->frame_parms.N_RB_DL) {
-            case 6:
-              dci_length = sizeof_DCI1_1_5MHz_TDD_t;
-              dci_length_bytes = sizeof(DCI1_1_5MHz_TDD_t);
-              ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
-              ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
-              ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
-              ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
-              ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 1;
-              ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
-              break;
-
-            case 25:
-              dci_length = sizeof_DCI1_5MHz_TDD_t;
-              dci_length_bytes = sizeof(DCI1_5MHz_TDD_t);
-              ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
-              ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
-              ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
-              ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
-              ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 1;
-              ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
-              break;
-
-            case 50:
-              dci_length = sizeof_DCI1_10MHz_TDD_t;
-              dci_length_bytes = sizeof(DCI1_10MHz_TDD_t);
-              ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
-              ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
-              ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
-              ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
-              ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 1;
-              ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
-              break;
-
-            case 100:
-              ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
-              ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
-              ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
-              ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
-              ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 1;
-              ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
-              dci_length = sizeof_DCI1_20MHz_TDD_t;
-              dci_length_bytes = sizeof(DCI1_20MHz_TDD_t);
-              break;
-            }
-          } else {
-            switch (eNB->frame_parms.N_RB_DL) {
-            case 6:
-              dci_length = sizeof_DCI1_1_5MHz_FDD_t;
-              dci_length_bytes = sizeof(DCI1_1_5MHz_FDD_t);
-              ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
-              ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
-              ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
-              ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 1;
-              ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
-              break;
-
-            case 25:
-              dci_length = sizeof_DCI1_5MHz_FDD_t;
-              dci_length_bytes = sizeof(DCI1_5MHz_FDD_t);
-              ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
-              ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
-              ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
-              ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 1;
-              ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
-              break;
-
-            case 50:
-              dci_length = sizeof_DCI1_10MHz_FDD_t;
-              dci_length_bytes = sizeof(DCI1_10MHz_FDD_t);
-              ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
-              ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
-              ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
-              ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 1;
-              ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
-              break;
-
-            case 100:
-              dci_length = sizeof_DCI1_20MHz_FDD_t;
-              dci_length_bytes = sizeof(DCI1_20MHz_FDD_t);
-              ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
-              ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
-              ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
-              ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 1;
-              ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
-              break;
+        case 1:
+        case 2:
+        case 7:
+          if (common_flag == 0) {
+            if (eNB->frame_parms.frame_type == TDD) {
+              switch (eNB->frame_parms.N_RB_DL) {
+                case 6:
+                  dci_length = sizeof_DCI1_1_5MHz_TDD_t;
+                  dci_length_bytes = sizeof(DCI1_1_5MHz_TDD_t);
+                  ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
+                  ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
+                  ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
+                  ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
+                  ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 1;
+                  ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
+                  break;
+
+                case 25:
+                  dci_length = sizeof_DCI1_5MHz_TDD_t;
+                  dci_length_bytes = sizeof(DCI1_5MHz_TDD_t);
+                  ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
+                  ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
+                  ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
+                  ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
+                  ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 1;
+                  ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
+                  break;
+
+                case 50:
+                  dci_length = sizeof_DCI1_10MHz_TDD_t;
+                  dci_length_bytes = sizeof(DCI1_10MHz_TDD_t);
+                  ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
+                  ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
+                  ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
+                  ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
+                  ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 1;
+                  ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
+                  break;
+
+                case 100:
+                  ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
+                  ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
+                  ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
+                  ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
+                  ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 1;
+                  ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
+                  dci_length = sizeof_DCI1_20MHz_TDD_t;
+                  dci_length_bytes = sizeof(DCI1_20MHz_TDD_t);
+                  break;
+              }
+            } else {
+              switch (eNB->frame_parms.N_RB_DL) {
+                case 6:
+                  dci_length = sizeof_DCI1_1_5MHz_FDD_t;
+                  dci_length_bytes = sizeof(DCI1_1_5MHz_FDD_t);
+                  ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
+                  ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
+                  ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
+                  ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 1;
+                  ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
+                  break;
+
+                case 25:
+                  dci_length = sizeof_DCI1_5MHz_FDD_t;
+                  dci_length_bytes = sizeof(DCI1_5MHz_FDD_t);
+                  ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
+                  ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
+                  ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
+                  ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 1;
+                  ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
+                  break;
+
+                case 50:
+                  dci_length = sizeof_DCI1_10MHz_FDD_t;
+                  dci_length_bytes = sizeof(DCI1_10MHz_FDD_t);
+                  ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
+                  ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
+                  ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
+                  ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 1;
+                  ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
+                  break;
+
+                case 100:
+                  dci_length = sizeof_DCI1_20MHz_FDD_t;
+                  dci_length_bytes = sizeof(DCI1_20MHz_FDD_t);
+                  ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
+                  ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
+                  ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
+                  ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 1;
+                  ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
+                  break;
+              }
             }
-          }
-
-          memcpy(&dci_alloc[num_dci].dci_pdu[0],&DLSCH_alloc_pdu_1[k],dci_length_bytes);
-          dci_alloc[num_dci].dci_length   = dci_length;
-          dci_alloc[num_dci].L            = 1;
-          dci_alloc[num_dci].rnti         = n_rnti+k;
-          dci_alloc[num_dci].format       = format1;
-          dci_alloc[num_dci].search_space = DCI_UE_SPACE;
-          dump_dci(&eNB->frame_parms,&dci_alloc[num_dci]);
 
-          printf("Generating dlsch params for user %d\n",k);
-          generate_eNB_dlsch_params_from_dci(0,
-					     subframe,
-                                             &DLSCH_alloc_pdu_1[0],
-                                             n_rnti+k,
-                                             format1,
-                                             eNB->dlsch[0],
-                                             &eNB->frame_parms,
-                                             eNB->pdsch_config_dedicated,
-                                             SI_RNTI,
-                                             0,
-                                             P_RNTI,
-                                             eNB->UE_stats[0].DL_pmi_single,
-                                             transmission_mode<7?0:transmission_mode);
-
-          /*if (transmission_mode == 7)
-	    eNB->dlsch[0][0]->harq_processes[0]->mimo_mode = TM7; //Xiwen: to check about harq_pid*/
-
-          num_dci++;
-          num_ue_spec_dci++;
-        } else {
-          if (eNB->frame_parms.frame_type == TDD) {
-
-            switch (eNB->frame_parms.N_RB_DL) {
-            case 6:
-              dci_length = sizeof_DCI1A_1_5MHz_TDD_1_6_t;
-              dci_length_bytes = sizeof(DCI1A_1_5MHz_TDD_1_6_t);
-              ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
-              ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 0;
-              ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
-              ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
-              ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
-              ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
-              ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
-              break;
-
-            case 25:
-              dci_length = sizeof_DCI1A_5MHz_TDD_1_6_t;
-              dci_length_bytes = sizeof(DCI1A_5MHz_TDD_1_6_t);
-              ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
-              ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 0;
-              ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
-              ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
-              ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
-              ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
-              ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv              = 1;
-              break;
-
-            case 50:
-              dci_length = sizeof_DCI1A_10MHz_TDD_1_6_t;
-              dci_length_bytes = sizeof(DCI1A_10MHz_TDD_1_6_t);
-              ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
-              ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
-              ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
-              ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
-              ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
-              ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
-              ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
-              break;
-
-            case 100:
-              ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
-              ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
-              ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
-              ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
-              ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
-              ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
-              ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
-              dci_length = sizeof_DCI1A_20MHz_TDD_1_6_t;
-              dci_length_bytes = sizeof(DCI1A_20MHz_TDD_1_6_t);
-              break;
-            }
+            memcpy(&dci_alloc[num_dci].dci_pdu[0],&DLSCH_alloc_pdu_1[k],dci_length_bytes);
+            dci_alloc[num_dci].dci_length   = dci_length;
+            dci_alloc[num_dci].L            = 1;
+            dci_alloc[num_dci].rnti         = n_rnti+k;
+            dci_alloc[num_dci].format       = format1;
+            dci_alloc[num_dci].search_space = DCI_UE_SPACE;
+            dump_dci(&eNB->frame_parms,&dci_alloc[num_dci]);
+            printf("Generating dlsch params for user %d\n",k);
+            generate_eNB_dlsch_params_from_dci(0,
+                                               subframe,
+                                               &DLSCH_alloc_pdu_1[0],
+                                               n_rnti+k,
+                                               format1,
+                                               eNB->dlsch[0],
+                                               &eNB->frame_parms,
+                                               eNB->pdsch_config_dedicated,
+                                               SI_RNTI,
+                                               0,
+                                               P_RNTI,
+                                               eNB->UE_stats[0].DL_pmi_single,
+                                               transmission_mode<7?0:transmission_mode);
+            /*if (transmission_mode == 7)
+            eNB->dlsch[0][0]->harq_processes[0]->mimo_mode = TM7; //Xiwen: to check about harq_pid*/
+            num_dci++;
+            num_ue_spec_dci++;
           } else {
-            switch (eNB->frame_parms.N_RB_DL) {
-            case 6:
-              dci_length = sizeof_DCI1A_1_5MHz_FDD_t;
-              dci_length_bytes = sizeof(DCI1A_1_5MHz_FDD_t);
-              ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
-              ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
-              ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
-              ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
-              ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
-              ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
-              break;
-
-            case 25:
-              dci_length = sizeof_DCI1A_5MHz_FDD_t;
-              dci_length_bytes = sizeof(DCI1A_5MHz_FDD_t);
-              ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
-              ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
-              ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
-              ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
-              ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
-              ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
-              break;
-
-            case 50:
-              dci_length = sizeof_DCI1A_10MHz_FDD_t;
-              dci_length_bytes = sizeof(DCI1A_10MHz_FDD_t);
-              ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
-              ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
-              ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
-              ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
-              ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
-              ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
-              break;
-
-            case 100:
-              dci_length = sizeof_DCI1A_20MHz_FDD_t;
-              dci_length_bytes = sizeof(DCI1A_20MHz_FDD_t);
-              ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
-              ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
-              ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
-              ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
-              ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
-              ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
-              break;
+            if (eNB->frame_parms.frame_type == TDD) {
+              switch (eNB->frame_parms.N_RB_DL) {
+                case 6:
+                  dci_length = sizeof_DCI1A_1_5MHz_TDD_1_6_t;
+                  dci_length_bytes = sizeof(DCI1A_1_5MHz_TDD_1_6_t);
+                  ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
+                  ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 0;
+                  ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
+                  ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
+                  ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
+                  ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
+                  ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
+                  break;
+
+                case 25:
+                  dci_length = sizeof_DCI1A_5MHz_TDD_1_6_t;
+                  dci_length_bytes = sizeof(DCI1A_5MHz_TDD_1_6_t);
+                  ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
+                  ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 0;
+                  ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
+                  ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
+                  ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
+                  ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
+                  ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv              = 1;
+                  break;
+
+                case 50:
+                  dci_length = sizeof_DCI1A_10MHz_TDD_1_6_t;
+                  dci_length_bytes = sizeof(DCI1A_10MHz_TDD_1_6_t);
+                  ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
+                  ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
+                  ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
+                  ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
+                  ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
+                  ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
+                  ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
+                  break;
+
+                case 100:
+                  ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
+                  ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
+                  ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
+                  ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
+                  ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
+                  ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
+                  ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
+                  dci_length = sizeof_DCI1A_20MHz_TDD_1_6_t;
+                  dci_length_bytes = sizeof(DCI1A_20MHz_TDD_1_6_t);
+                  break;
+              }
+            } else {
+              switch (eNB->frame_parms.N_RB_DL) {
+                case 6:
+                  dci_length = sizeof_DCI1A_1_5MHz_FDD_t;
+                  dci_length_bytes = sizeof(DCI1A_1_5MHz_FDD_t);
+                  ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
+                  ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
+                  ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
+                  ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
+                  ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
+                  ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
+                  break;
+
+                case 25:
+                  dci_length = sizeof_DCI1A_5MHz_FDD_t;
+                  dci_length_bytes = sizeof(DCI1A_5MHz_FDD_t);
+                  ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
+                  ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
+                  ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
+                  ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
+                  ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
+                  ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
+                  break;
+
+                case 50:
+                  dci_length = sizeof_DCI1A_10MHz_FDD_t;
+                  dci_length_bytes = sizeof(DCI1A_10MHz_FDD_t);
+                  ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
+                  ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
+                  ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
+                  ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
+                  ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
+                  ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
+                  break;
+
+                case 100:
+                  dci_length = sizeof_DCI1A_20MHz_FDD_t;
+                  dci_length_bytes = sizeof(DCI1A_20MHz_FDD_t);
+                  ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
+                  ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
+                  ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
+                  ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
+                  ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
+                  ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
+                  break;
+              }
             }
+
+            memcpy(&dci_alloc[num_dci].dci_pdu[0],&DLSCH_alloc_pdu_1[k],dci_length_bytes);
+            dci_alloc[num_dci].dci_length   = dci_length;
+            dci_alloc[num_dci].L            = 1;
+            dci_alloc[num_dci].rnti         = SI_RNTI;
+            dci_alloc[num_dci].format       = format1A;
+            dci_alloc[num_dci].firstCCE     = 0;
+            dci_alloc[num_dci].search_space = DCI_COMMON_SPACE;
+            dump_dci(&eNB->frame_parms,&dci_alloc[num_dci]);
+            printf("Generating dlsch params for user %d\n",k);
+            generate_eNB_dlsch_params_from_dci(0,
+                                               subframe,
+                                               &DLSCH_alloc_pdu_1[0],
+                                               SI_RNTI,
+                                               format1A,
+                                               eNB->dlsch[0],
+                                               &eNB->frame_parms,
+                                               eNB->pdsch_config_dedicated,
+                                               SI_RNTI,
+                                               0,
+                                               P_RNTI,
+                                               eNB->UE_stats[0].DL_pmi_single,
+                                               0);
+            num_common_dci++;
+            num_dci++;
           }
 
-          memcpy(&dci_alloc[num_dci].dci_pdu[0],&DLSCH_alloc_pdu_1[k],dci_length_bytes);
-          dci_alloc[num_dci].dci_length   = dci_length;
-          dci_alloc[num_dci].L            = 1;
-          dci_alloc[num_dci].rnti         = SI_RNTI;
-          dci_alloc[num_dci].format       = format1A;
-          dci_alloc[num_dci].firstCCE     = 0;
-          dci_alloc[num_dci].search_space = DCI_COMMON_SPACE;
-          dump_dci(&eNB->frame_parms,&dci_alloc[num_dci]);
+          break;
 
-          printf("Generating dlsch params for user %d\n",k);
-          generate_eNB_dlsch_params_from_dci(0,
-					     subframe,
-                                             &DLSCH_alloc_pdu_1[0],
-                                             SI_RNTI,
-                                             format1A,
-                                             eNB->dlsch[0],
-                                             &eNB->frame_parms,
-                                             eNB->pdsch_config_dedicated,
-                                             SI_RNTI,
-                                             0,
-                                             P_RNTI,
-                                             eNB->UE_stats[0].DL_pmi_single,
-                                             0);
+        case 3:
+          if (common_flag == 0) {
+            if (eNB->frame_parms.nb_antennas_tx == 2) {
+              if (eNB->frame_parms.frame_type == TDD) {
+                switch (eNB->frame_parms.N_RB_DL) {
+                  case 6:
+                    dci_length = sizeof_DCI2A_1_5MHz_2A_TDD_t;
+                    dci_length_bytes = sizeof(DCI2A_1_5MHz_2A_TDD_t);
+                    ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
+                    ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
+                    ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
+                    ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                    ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
+                    ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
+                    ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
+                    ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
+                    ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
+                    ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
+                    break;
 
-          num_common_dci++;
-          num_dci++;
+                  case 25:
+                    dci_length = sizeof_DCI2A_5MHz_2A_TDD_t;
+                    dci_length_bytes = sizeof(DCI2A_5MHz_2A_TDD_t);
+                    ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
+                    ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
+                    ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
+                    ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
+                    ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                    ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
+                    ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
+                    ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
+                    ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
+                    ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
+                    ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
+                    break;
 
-        }
-       
-        break;
+                  case 50:
+                    dci_length = sizeof_DCI2A_10MHz_2A_TDD_t;
+                    dci_length_bytes = sizeof(DCI2A_10MHz_2A_TDD_t);
+                    ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
+                    ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
+                    ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
+                    ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
+                    ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                    ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
+                    ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
+                    ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
+                    ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
+                    ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
+                    ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
+                    break;
 
-      case 3:
-        if (common_flag == 0) {
+                  case 100:
+                    ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
+                    ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
+                    ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
+                    ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
+                    ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                    ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
+                    ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
+                    ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
+                    ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
+                    ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
+                    ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
+                    dci_length = sizeof_DCI2A_20MHz_2A_TDD_t;
+                    dci_length_bytes = sizeof(DCI2A_20MHz_2A_TDD_t);
+                    break;
+                }
+              } else {
+                switch (eNB->frame_parms.N_RB_DL) {
+                  case 6:
+                    dci_length = sizeof_DCI2A_1_5MHz_2A_FDD_t;
+                    dci_length_bytes = sizeof(DCI2A_1_5MHz_2A_FDD_t);
+                    ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
+                    ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
+                    ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                    ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
+                    ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
+                    ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
+                    ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
+                    ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
+                    ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
+                    break;
 
-          if (eNB->frame_parms.nb_antennas_tx == 2) {
+                  case 25:
+                    dci_length = sizeof_DCI2A_5MHz_2A_FDD_t;
+                    dci_length_bytes = sizeof(DCI2A_5MHz_2A_FDD_t);
+                    ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
+                    ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
+                    ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
+                    ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                    ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
+                    ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
+                    ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
+                    ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
+                    ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
+                    ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
+                    break;
 
-            if (eNB->frame_parms.frame_type == TDD) {
+                  case 50:
+                    dci_length = sizeof_DCI2A_10MHz_2A_FDD_t;
+                    dci_length_bytes = sizeof(DCI2A_10MHz_2A_FDD_t);
+                    ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
+                    ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
+                    ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
+                    ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                    ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
+                    ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
+                    ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
+                    ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
+                    ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
+                    ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
+                    break;
 
-              switch (eNB->frame_parms.N_RB_DL) {
-              case 6:
-                dci_length = sizeof_DCI2A_1_5MHz_2A_TDD_t;
-                dci_length_bytes = sizeof(DCI2A_1_5MHz_2A_TDD_t);
-                ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
-                ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
-                ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
-                ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-                ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
-                ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
-                ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
-                ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
-                ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
-                ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
-                break;
-
-              case 25:
-                dci_length = sizeof_DCI2A_5MHz_2A_TDD_t;
-                dci_length_bytes = sizeof(DCI2A_5MHz_2A_TDD_t);
-                ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
-                ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
-                ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
-                ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
-                ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-                ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
-                ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
-                ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
-                ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
-                ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
-                ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
-                break;
-
-              case 50:
-                dci_length = sizeof_DCI2A_10MHz_2A_TDD_t;
-                dci_length_bytes = sizeof(DCI2A_10MHz_2A_TDD_t);
-                ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
-                ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
-                ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
-                ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
-                ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-                ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
-                ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
-                ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
-                ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
-                ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
-                ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
-                break;
-
-              case 100:
-                ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
-                ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
-                ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
-                ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
-                ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-                ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
-                ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
-                ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
-                ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
-                ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
-                ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
-                dci_length = sizeof_DCI2A_20MHz_2A_TDD_t;
-                dci_length_bytes = sizeof(DCI2A_20MHz_2A_TDD_t);
-                break;
+                  case 100:
+                    dci_length = sizeof_DCI2A_20MHz_2A_FDD_t;
+                    dci_length_bytes = sizeof(DCI2A_20MHz_2A_FDD_t);
+                    ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
+                    ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
+                    ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
+                    ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                    ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
+                    ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
+                    ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
+                    ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
+                    ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
+                    ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
+                    break;
+                }
               }
+            } else if (eNB->frame_parms.nb_antennas_tx == 4) {
             }
 
-            else {
+            memcpy(&dci_alloc[num_dci].dci_pdu[0],&DLSCH_alloc_pdu_1[k],dci_length_bytes);
+            dci_alloc[num_dci].dci_length   = dci_length;
+            dci_alloc[num_dci].L            = 1;
+            dci_alloc[num_dci].rnti         = n_rnti+k;
+            dci_alloc[num_dci].format       = format2A;
+            dci_alloc[num_dci].search_space = DCI_UE_SPACE;
+            dump_dci(&eNB->frame_parms,&dci_alloc[num_dci]);
+            printf("Generating dlsch params for user %d / format 2A (%d)\n",k,format2A);
+            generate_eNB_dlsch_params_from_dci(0,
+                                               subframe,
+                                               &DLSCH_alloc_pdu_1[0],
+                                               n_rnti+k,
+                                               format2A,
+                                               eNB->dlsch[0],
+                                               &eNB->frame_parms,
+                                               eNB->pdsch_config_dedicated,
+                                               SI_RNTI,
+                                               0,
+                                               P_RNTI,
+                                               eNB->UE_stats[0].DL_pmi_single,
+                                               0);
+            num_dci++;
+            num_ue_spec_dci++;
+          } else {
+            if (eNB->frame_parms.frame_type == TDD) {
+              switch (eNB->frame_parms.N_RB_DL) {
+                case 6:
+                  dci_length = sizeof_DCI1A_1_5MHz_TDD_1_6_t;
+                  dci_length_bytes = sizeof(DCI1A_1_5MHz_TDD_1_6_t);
+                  ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
+                  ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 0;
+                  ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
+                  ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
+                  ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
+                  ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
+                  ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
+                  break;
+
+                case 25:
+                  dci_length = sizeof_DCI1A_5MHz_TDD_1_6_t;
+                  dci_length_bytes = sizeof(DCI1A_5MHz_TDD_1_6_t);
+                  ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
+                  ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 0;
+                  ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
+                  ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
+                  ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
+                  ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
+                  ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv              = 1;
+                  break;
+
+                case 50:
+                  dci_length = sizeof_DCI1A_10MHz_TDD_1_6_t;
+                  dci_length_bytes = sizeof(DCI1A_10MHz_TDD_1_6_t);
+                  ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
+                  ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
+                  ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
+                  ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
+                  ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
+                  ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
+                  ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
+                  break;
+
+                case 100:
+                  ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
+                  ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
+                  ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
+                  ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
+                  ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
+                  ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
+                  ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
+                  dci_length = sizeof_DCI1A_20MHz_TDD_1_6_t;
+                  dci_length_bytes = sizeof(DCI1A_20MHz_TDD_1_6_t);
+                  break;
+              }
+            } else {
               switch (eNB->frame_parms.N_RB_DL) {
-              case 6:
-                dci_length = sizeof_DCI2A_1_5MHz_2A_FDD_t;
-                dci_length_bytes = sizeof(DCI2A_1_5MHz_2A_FDD_t);
-                ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
-                ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
-                ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-                ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
-                ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
-                ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
-                ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
-                ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
-                ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
-                break;
-
-              case 25:
-                dci_length = sizeof_DCI2A_5MHz_2A_FDD_t;
-                dci_length_bytes = sizeof(DCI2A_5MHz_2A_FDD_t);
-                ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
-                ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
-                ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
-                ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-                ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
-                ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
-                ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
-                ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
-                ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
-                ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
-                break;
-
-              case 50:
-                dci_length = sizeof_DCI2A_10MHz_2A_FDD_t;
-                dci_length_bytes = sizeof(DCI2A_10MHz_2A_FDD_t);
-                ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
-                ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
-                ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
-                ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-                ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
-                ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
-                ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
-                ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
-                ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
-                ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
-                break;
-
-              case 100:
-                dci_length = sizeof_DCI2A_20MHz_2A_FDD_t;
-                dci_length_bytes = sizeof(DCI2A_20MHz_2A_FDD_t);
-                ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
-                ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
-                ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
-                ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-                ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
-                ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
-                ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
-                ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
-                ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
-                ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
-                break;
+                case 6:
+                  dci_length = sizeof_DCI1A_1_5MHz_FDD_t;
+                  dci_length_bytes = sizeof(DCI1A_1_5MHz_FDD_t);
+                  ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
+                  ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
+                  ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
+                  ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
+                  ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
+                  ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
+                  break;
+
+                case 25:
+                  dci_length = sizeof_DCI1A_5MHz_FDD_t;
+                  dci_length_bytes = sizeof(DCI1A_5MHz_FDD_t);
+                  ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
+                  ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
+                  ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
+                  ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
+                  ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
+                  ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
+                  break;
+
+                case 50:
+                  dci_length = sizeof_DCI1A_10MHz_FDD_t;
+                  dci_length_bytes = sizeof(DCI1A_10MHz_FDD_t);
+                  ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
+                  ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
+                  ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
+                  ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
+                  ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
+                  ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
+                  break;
+
+                case 100:
+                  dci_length = sizeof_DCI1A_20MHz_FDD_t;
+                  dci_length_bytes = sizeof(DCI1A_20MHz_FDD_t);
+                  ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
+                  ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
+                  ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
+                  ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
+                  ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
+                  ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
+                  break;
               }
             }
-          } else if (eNB->frame_parms.nb_antennas_tx == 4) {
 
+            memcpy(&dci_alloc[num_dci].dci_pdu[0],&DLSCH_alloc_pdu_1[k],dci_length_bytes);
+            dci_alloc[num_dci].dci_length   = dci_length;
+            dci_alloc[num_dci].L            = 1;
+            dci_alloc[num_dci].rnti         = SI_RNTI;
+            dci_alloc[num_dci].format       = format1A;
+            dci_alloc[num_dci].firstCCE     = 0;
+            dci_alloc[num_dci].search_space = DCI_COMMON_SPACE;
+            dump_dci(&eNB->frame_parms,&dci_alloc[num_dci]);
+            printf("Generating dlsch params for user %d\n",k);
+            generate_eNB_dlsch_params_from_dci(0,
+                                               subframe,
+                                               &DLSCH_alloc_pdu_1[0],
+                                               SI_RNTI,
+                                               format1A,
+                                               eNB->dlsch[0],
+                                               &eNB->frame_parms,
+                                               eNB->pdsch_config_dedicated,
+                                               SI_RNTI,
+                                               0,
+                                               P_RNTI,
+                                               eNB->UE_stats[0].DL_pmi_single,
+                                               0);
+            num_common_dci++;
+            num_dci++;
           }
 
-          memcpy(&dci_alloc[num_dci].dci_pdu[0],&DLSCH_alloc_pdu_1[k],dci_length_bytes);
-          dci_alloc[num_dci].dci_length   = dci_length;
-          dci_alloc[num_dci].L            = 1;
-          dci_alloc[num_dci].rnti         = n_rnti+k;
-          dci_alloc[num_dci].format       = format2A;
-          dci_alloc[num_dci].search_space = DCI_UE_SPACE;
-          dump_dci(&eNB->frame_parms,&dci_alloc[num_dci]);
-
-          printf("Generating dlsch params for user %d / format 2A (%d)\n",k,format2A);
-          generate_eNB_dlsch_params_from_dci(0,
-					     subframe,
-                                             &DLSCH_alloc_pdu_1[0],
-                                             n_rnti+k,
-                                             format2A,
-                                             eNB->dlsch[0],
-                                             &eNB->frame_parms,
-                                             eNB->pdsch_config_dedicated,
-                                             SI_RNTI,
-                                             0,
-                                             P_RNTI,
-                                             eNB->UE_stats[0].DL_pmi_single,
-                                             0);
-
-          num_dci++;
-          num_ue_spec_dci++;
-        } else {
-          if (eNB->frame_parms.frame_type == TDD) {
-
-            switch (eNB->frame_parms.N_RB_DL) {
-            case 6:
-              dci_length = sizeof_DCI1A_1_5MHz_TDD_1_6_t;
-              dci_length_bytes = sizeof(DCI1A_1_5MHz_TDD_1_6_t);
-              ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
-              ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 0;
-              ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
-              ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
-              ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
-              ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
-              ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
-              break;
-
-            case 25:
-              dci_length = sizeof_DCI1A_5MHz_TDD_1_6_t;
-              dci_length_bytes = sizeof(DCI1A_5MHz_TDD_1_6_t);
-              ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
-              ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 0;
-              ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
-              ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
-              ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
-              ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
-              ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv              = 1;
-              break;
-
-            case 50:
-              dci_length = sizeof_DCI1A_10MHz_TDD_1_6_t;
-              dci_length_bytes = sizeof(DCI1A_10MHz_TDD_1_6_t);
-              ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
-              ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
-              ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
-              ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
-              ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
-              ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
-              ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
-              break;
-
-            case 100:
-              ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
-              ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
-              ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
-              ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
-              ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
-              ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
-              ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
-              dci_length = sizeof_DCI1A_20MHz_TDD_1_6_t;
-              dci_length_bytes = sizeof(DCI1A_20MHz_TDD_1_6_t);
-              break;
-            }
-          } else {
-            switch (eNB->frame_parms.N_RB_DL) {
-            case 6:
-              dci_length = sizeof_DCI1A_1_5MHz_FDD_t;
-              dci_length_bytes = sizeof(DCI1A_1_5MHz_FDD_t);
-              ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
-              ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
-              ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
-              ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
-              ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
-              ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
-              break;
-
-            case 25:
-              dci_length = sizeof_DCI1A_5MHz_FDD_t;
-              dci_length_bytes = sizeof(DCI1A_5MHz_FDD_t);
-              ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
-              ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
-              ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
-              ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
-              ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
-              ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
-              break;
-
-            case 50:
-              dci_length = sizeof_DCI1A_10MHz_FDD_t;
-              dci_length_bytes = sizeof(DCI1A_10MHz_FDD_t);
-              ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
-              ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
-              ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
-              ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
-              ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
-              ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
-              break;
-
-            case 100:
-              dci_length = sizeof_DCI1A_20MHz_FDD_t;
-              dci_length_bytes = sizeof(DCI1A_20MHz_FDD_t);
-              ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
-              ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
-              ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
-              ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
-              ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
-              ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
-              break;
-            }
-          }
+          printf("Generated DCI format 2A (Transmission Mode 3)\n");
+          break;
 
-          memcpy(&dci_alloc[num_dci].dci_pdu[0],&DLSCH_alloc_pdu_1[k],dci_length_bytes);
-          dci_alloc[num_dci].dci_length   = dci_length;
-          dci_alloc[num_dci].L            = 1;
-          dci_alloc[num_dci].rnti         = SI_RNTI;
-          dci_alloc[num_dci].format       = format1A;
-          dci_alloc[num_dci].firstCCE     = 0;
-          dci_alloc[num_dci].search_space = DCI_COMMON_SPACE;
-          dump_dci(&eNB->frame_parms,&dci_alloc[num_dci]);
+        case 4:
+          if (common_flag == 0) {
+            if (eNB->frame_parms.nb_antennas_tx == 2) {
+              if (eNB->frame_parms.frame_type == TDD) {
+                switch (eNB->frame_parms.N_RB_DL) {
+                  case 6:
+                    dci_length = sizeof_DCI2_1_5MHz_2A_TDD_t;
+                    dci_length_bytes = sizeof(DCI2_1_5MHz_2A_TDD_t);
+                    ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
+                    ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
+                    ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
+                    ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                    ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
+                    ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
+                    ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
+                    ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
+                    ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
+                    ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
+                    break;
 
-          printf("Generating dlsch params for user %d\n",k);
-          generate_eNB_dlsch_params_from_dci(0,
-					     subframe,
-                                             &DLSCH_alloc_pdu_1[0],
-                                             SI_RNTI,
-                                             format1A,
-                                             eNB->dlsch[0],
-                                             &eNB->frame_parms,
-                                             eNB->pdsch_config_dedicated,
-                                             SI_RNTI,
-                                             0,
-                                             P_RNTI,
-                                             eNB->UE_stats[0].DL_pmi_single,
-                                             0);
+                  case 25:
+                    dci_length = sizeof_DCI2_5MHz_2A_TDD_t;
+                    dci_length_bytes = sizeof(DCI2_5MHz_2A_TDD_t);
+                    ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
+                    ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
+                    ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
+                    ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
+                    ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                    ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
+                    ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
+                    ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
+                    ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
+                    ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
+                    ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
+                    break;
 
-          num_common_dci++;
-          num_dci++;
+                  case 50:
+                    dci_length = sizeof_DCI2_10MHz_2A_TDD_t;
+                    dci_length_bytes = sizeof(DCI2_10MHz_2A_TDD_t);
+                    ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
+                    ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
+                    ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
+                    ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
+                    ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                    ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
+                    ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
+                    ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
+                    ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
+                    ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
+                    ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
+                    break;
 
-        }
+                  case 100:
+                    ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
+                    ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
+                    ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
+                    ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
+                    ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                    ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
+                    ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
+                    ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
+                    ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
+                    ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
+                    ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
+                    dci_length = sizeof_DCI2_20MHz_2A_TDD_t;
+                    dci_length_bytes = sizeof(DCI2_20MHz_2A_TDD_t);
+                    break;
+                }
+              } else {
+                switch (eNB->frame_parms.N_RB_DL) {
+                  case 6:
+                    dci_length = sizeof_DCI2_1_5MHz_2A_FDD_t;
+                    dci_length_bytes = sizeof(DCI2_1_5MHz_2A_FDD_t);
+                    ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
+                    ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
+                    ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                    ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
+                    ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
+                    ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
+                    ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
+                    ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
+                    ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
+                    break;
 
-        printf("Generated DCI format 2A (Transmission Mode 3)\n");
-        break;
+                  case 25:
+                    dci_length = sizeof_DCI2_5MHz_2A_FDD_t;
+                    dci_length_bytes = sizeof(DCI2_5MHz_2A_FDD_t);
+                    ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
+                    ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
+                    ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
+                    ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                    ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
+                    ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
+                    ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
+                    ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
+                    ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
+                    ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
+                    break;
 
-      case 4:
-        if (common_flag == 0) {
+                  case 50:
+                    dci_length = sizeof_DCI2_10MHz_2A_FDD_t;
+                    dci_length_bytes = sizeof(DCI2_10MHz_2A_FDD_t);
+                    ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
+                    ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
+                    ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
+                    ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                    ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
+                    ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
+                    ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
+                    ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
+                    ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
+                    ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
+                    break;
 
-          if (eNB->frame_parms.nb_antennas_tx == 2) {
+                  case 100:
+                    dci_length = sizeof_DCI2_20MHz_2A_FDD_t;
+                    dci_length_bytes = sizeof(DCI2_20MHz_2A_FDD_t);
+                    ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
+                    ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
+                    ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
+                    ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                    ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
+                    ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
+                    ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
+                    ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
+                    ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
+                    ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
+                    break;
+                }
+              }
+            } else if (eNB->frame_parms.nb_antennas_tx == 4) {
+            }
 
+            memcpy(&dci_alloc[num_dci].dci_pdu[0],&DLSCH_alloc_pdu_1[k],dci_length_bytes);
+            dci_alloc[num_dci].dci_length   = dci_length;
+            dci_alloc[num_dci].L            = 1;
+            dci_alloc[num_dci].rnti         = n_rnti+k;
+            dci_alloc[num_dci].format       = format2;
+            dci_alloc[num_dci].search_space = DCI_UE_SPACE;
+            dump_dci(&eNB->frame_parms,&dci_alloc[num_dci]);
+            printf("Generating dlsch params for user %d\n",k);
+            generate_eNB_dlsch_params_from_dci(0,
+                                               subframe,
+                                               &DLSCH_alloc_pdu_1[0],
+                                               n_rnti+k,
+                                               format2,
+                                               eNB->dlsch[0],
+                                               &eNB->frame_parms,
+                                               eNB->pdsch_config_dedicated,
+                                               SI_RNTI,
+                                               0,
+                                               P_RNTI,
+                                               eNB->UE_stats[0].DL_pmi_single,
+                                               0);
+            num_dci++;
+            num_ue_spec_dci++;
+          } else {
             if (eNB->frame_parms.frame_type == TDD) {
-
               switch (eNB->frame_parms.N_RB_DL) {
-              case 6:
-                dci_length = sizeof_DCI2_1_5MHz_2A_TDD_t;
-                dci_length_bytes = sizeof(DCI2_1_5MHz_2A_TDD_t);
-                ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
-                ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
-                ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
-                ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-                ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
-                ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
-                ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
-                ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
-                ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
-                ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
-                break;
-
-              case 25:
-                dci_length = sizeof_DCI2_5MHz_2A_TDD_t;
-                dci_length_bytes = sizeof(DCI2_5MHz_2A_TDD_t);
-                ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
-                ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
-                ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
-                ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
-                ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-                ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
-                ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
-                ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
-                ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
-                ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
-                ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
-                break;
-
-              case 50:
-                dci_length = sizeof_DCI2_10MHz_2A_TDD_t;
-                dci_length_bytes = sizeof(DCI2_10MHz_2A_TDD_t);
-                ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
-                ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
-                ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
-                ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
-                ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-                ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
-                ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
-                ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
-                ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
-                ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
-                ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
-                break;
-
-              case 100:
-                ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
-                ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
-                ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
-                ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
-                ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-                ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
-                ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
-                ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
-                ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
-                ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
-                ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
-                dci_length = sizeof_DCI2_20MHz_2A_TDD_t;
-                dci_length_bytes = sizeof(DCI2_20MHz_2A_TDD_t);
-                break;
+                case 6:
+                  dci_length = sizeof_DCI1A_1_5MHz_TDD_1_6_t;
+                  dci_length_bytes = sizeof(DCI1A_1_5MHz_TDD_1_6_t);
+                  ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
+                  ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 0;
+                  ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
+                  ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
+                  ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
+                  ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
+                  ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
+                  break;
+
+                case 25:
+                  dci_length = sizeof_DCI1A_5MHz_TDD_1_6_t;
+                  dci_length_bytes = sizeof(DCI1A_5MHz_TDD_1_6_t);
+                  ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
+                  ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 0;
+                  ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
+                  ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
+                  ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
+                  ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
+                  ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv              = 1;
+                  break;
+
+                case 50:
+                  dci_length = sizeof_DCI1A_10MHz_TDD_1_6_t;
+                  dci_length_bytes = sizeof(DCI1A_10MHz_TDD_1_6_t);
+                  ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
+                  ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
+                  ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
+                  ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
+                  ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
+                  ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
+                  ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
+                  break;
+
+                case 100:
+                  ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
+                  ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
+                  ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
+                  ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
+                  ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
+                  ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
+                  ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
+                  dci_length = sizeof_DCI1A_20MHz_TDD_1_6_t;
+                  dci_length_bytes = sizeof(DCI1A_20MHz_TDD_1_6_t);
+                  break;
               }
-            }
-
-            else {
+            } else {
               switch (eNB->frame_parms.N_RB_DL) {
-              case 6:
-                dci_length = sizeof_DCI2_1_5MHz_2A_FDD_t;
-                dci_length_bytes = sizeof(DCI2_1_5MHz_2A_FDD_t);
-                ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
-                ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
-                ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-                ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
-                ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
-                ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
-                ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
-                ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
-                ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
-                break;
-
-              case 25:
-                dci_length = sizeof_DCI2_5MHz_2A_FDD_t;
-                dci_length_bytes = sizeof(DCI2_5MHz_2A_FDD_t);
-                ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
-                ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
-                ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
-                ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-                ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
-                ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
-                ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
-                ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
-                ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
-                ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
-                break;
-
-              case 50:
-                dci_length = sizeof_DCI2_10MHz_2A_FDD_t;
-                dci_length_bytes = sizeof(DCI2_10MHz_2A_FDD_t);
-                ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
-                ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
-                ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
-                ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-                ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
-                ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
-                ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
-                ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
-                ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
-                ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
-                break;
-
-              case 100:
-                dci_length = sizeof_DCI2_20MHz_2A_FDD_t;
-                dci_length_bytes = sizeof(DCI2_20MHz_2A_FDD_t);
-                ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah              = 0;
-                ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = DLSCH_RB_ALLOC;
-                ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = 0;
-                ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-                ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1             = mcs1;
-                ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1             = 1;
-                ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1              = 0;
-                ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2             = mcs2;
-                ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2             = 1;
-                ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2              = 0;
-                break;
+                case 6:
+                  dci_length = sizeof_DCI1A_1_5MHz_FDD_t;
+                  dci_length_bytes = sizeof(DCI1A_1_5MHz_FDD_t);
+                  ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
+                  ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
+                  ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
+                  ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
+                  ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
+                  ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
+                  break;
+
+                case 25:
+                  dci_length = sizeof_DCI1A_5MHz_FDD_t;
+                  dci_length_bytes = sizeof(DCI1A_5MHz_FDD_t);
+                  ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
+                  ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
+                  ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
+                  ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
+                  ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
+                  ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
+                  break;
+
+                case 50:
+                  dci_length = sizeof_DCI1A_10MHz_FDD_t;
+                  dci_length_bytes = sizeof(DCI1A_10MHz_FDD_t);
+                  ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
+                  ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
+                  ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
+                  ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
+                  ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
+                  ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
+                  break;
+
+                case 100:
+                  dci_length = sizeof_DCI1A_20MHz_FDD_t;
+                  dci_length_bytes = sizeof(DCI1A_20MHz_FDD_t);
+                  ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
+                  ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
+                  ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
+                  ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
+                  ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
+                  ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
+                  ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
+                  ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
+                  break;
               }
             }
-          } else if (eNB->frame_parms.nb_antennas_tx == 4) {
 
+            memcpy(&dci_alloc[num_dci].dci_pdu[0],&DLSCH_alloc_pdu_1[k],dci_length_bytes);
+            dci_alloc[num_dci].dci_length   = dci_length;
+            dci_alloc[num_dci].L            = 1;
+            dci_alloc[num_dci].rnti         = SI_RNTI;
+            dci_alloc[num_dci].format       = format1A;
+            dci_alloc[num_dci].firstCCE     = 0;
+            dci_alloc[num_dci].search_space = DCI_COMMON_SPACE;
+            dump_dci(&eNB->frame_parms,&dci_alloc[num_dci]);
+            printf("Generating dlsch params for user %d\n",k);
+            generate_eNB_dlsch_params_from_dci(0,
+                                               subframe,
+                                               &DLSCH_alloc_pdu_1[0],
+                                               SI_RNTI,
+                                               format1A,
+                                               eNB->dlsch[0],
+                                               &eNB->frame_parms,
+                                               eNB->pdsch_config_dedicated,
+                                               SI_RNTI,
+                                               0,
+                                               P_RNTI,
+                                               eNB->UE_stats[0].DL_pmi_single,
+                                               0);
+            num_common_dci++;
+            num_dci++;
           }
 
-          memcpy(&dci_alloc[num_dci].dci_pdu[0],&DLSCH_alloc_pdu_1[k],dci_length_bytes);
-          dci_alloc[num_dci].dci_length   = dci_length;
+          break;
+
+        case 5:
+        case 6:
+          memcpy(&dci_alloc[num_dci].dci_pdu[0],&DLSCH_alloc_pdu2_1E[k],sizeof(DCI1E_5MHz_2A_M10PRB_TDD_t));
+          dci_alloc[num_dci].dci_length   = sizeof_DCI1E_5MHz_2A_M10PRB_TDD_t;
           dci_alloc[num_dci].L            = 1;
           dci_alloc[num_dci].rnti         = n_rnti+k;
-          dci_alloc[num_dci].format       = format2;
+          dci_alloc[num_dci].format       = format1E_2A_M10PRB;
+          dci_alloc[num_dci].firstCCE     = 4*k;
           dci_alloc[num_dci].search_space = DCI_UE_SPACE;
-          dump_dci(&eNB->frame_parms,&dci_alloc[num_dci]);
-
           printf("Generating dlsch params for user %d\n",k);
           generate_eNB_dlsch_params_from_dci(0,
-					     subframe,
-                                             &DLSCH_alloc_pdu_1[0],
+                                             subframe,
+                                             &DLSCH_alloc_pdu2_1E[k],
                                              n_rnti+k,
-                                             format2,
-                                             eNB->dlsch[0],
+                                             format1E_2A_M10PRB,
+                                             eNB->dlsch[k],
                                              &eNB->frame_parms,
                                              eNB->pdsch_config_dedicated,
                                              SI_RNTI,
                                              0,
                                              P_RNTI,
-                                             eNB->UE_stats[0].DL_pmi_single,
+                                             eNB->UE_stats[k].DL_pmi_single,
                                              0);
-
-          num_dci++;
-          num_ue_spec_dci++;
-        } else {
-          if (eNB->frame_parms.frame_type == TDD) {
-
-            switch (eNB->frame_parms.N_RB_DL) {
-            case 6:
-              dci_length = sizeof_DCI1A_1_5MHz_TDD_1_6_t;
-              dci_length_bytes = sizeof(DCI1A_1_5MHz_TDD_1_6_t);
-              ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
-              ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 0;
-              ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
-              ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
-              ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
-              ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
-              ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
-              break;
-
-            case 25:
-              dci_length = sizeof_DCI1A_5MHz_TDD_1_6_t;
-              dci_length_bytes = sizeof(DCI1A_5MHz_TDD_1_6_t);
-              ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
-              ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 0;
-              ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
-              ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
-              ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
-              ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
-              ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv              = 1;
-              break;
-
-            case 50:
-              dci_length = sizeof_DCI1A_10MHz_TDD_1_6_t;
-              dci_length_bytes = sizeof(DCI1A_10MHz_TDD_1_6_t);
-              ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
-              ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
-              ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
-              ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
-              ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
-              ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
-              ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
-              break;
-
-            case 100:
-              ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
-              ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
-              ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
-              ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
-              ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai              = 0;
-              ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
-              ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
-              dci_length = sizeof_DCI1A_20MHz_TDD_1_6_t;
-              dci_length_bytes = sizeof(DCI1A_20MHz_TDD_1_6_t);
-              break;
-            }
-          } else {
-            switch (eNB->frame_parms.N_RB_DL) {
-            case 6:
-              dci_length = sizeof_DCI1A_1_5MHz_FDD_t;
-              dci_length_bytes = sizeof(DCI1A_1_5MHz_FDD_t);
-              ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
-              ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
-              ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
-              ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
-              ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
-              ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
-              break;
-
-            case 25:
-              dci_length = sizeof_DCI1A_5MHz_FDD_t;
-              dci_length_bytes = sizeof(DCI1A_5MHz_FDD_t);
-              ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
-              ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
-              ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
-              ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
-              ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
-              ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
-              break;
-
-            case 50:
-              dci_length = sizeof_DCI1A_10MHz_FDD_t;
-              dci_length_bytes = sizeof(DCI1A_10MHz_FDD_t);
-              ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
-              ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
-              ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
-              ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
-              ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
-              ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
-              break;
-
-            case 100:
-              dci_length = sizeof_DCI1A_20MHz_FDD_t;
-              dci_length_bytes = sizeof(DCI1A_20MHz_FDD_t);
-              ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type             = 1;
-              ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type         = 1;
-              ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc          = computeRIV(eNB->frame_parms.N_RB_DL,0,9);
-              ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC              = TPC;
-              ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid         = 0;
-              ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs             = mcs1;
-              ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi             = 0;
-              ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv              = 0;
-              break;
-            }
-          }
-
-          memcpy(&dci_alloc[num_dci].dci_pdu[0],&DLSCH_alloc_pdu_1[k],dci_length_bytes);
-          dci_alloc[num_dci].dci_length   = dci_length;
-          dci_alloc[num_dci].L            = 1;
-          dci_alloc[num_dci].rnti         = SI_RNTI;
-          dci_alloc[num_dci].format       = format1A;
-          dci_alloc[num_dci].firstCCE     = 0;
-          dci_alloc[num_dci].search_space = DCI_COMMON_SPACE;
           dump_dci(&eNB->frame_parms,&dci_alloc[num_dci]);
-
-          printf("Generating dlsch params for user %d\n",k);
-          generate_eNB_dlsch_params_from_dci(0,
-					     subframe,
-                                             &DLSCH_alloc_pdu_1[0],
-                                             SI_RNTI,
-                                             format1A,
-                                             eNB->dlsch[0],
-                                             &eNB->frame_parms,
-                                             eNB->pdsch_config_dedicated,
-                                             SI_RNTI,
-                                             0,
-                                             P_RNTI,
-                                             eNB->UE_stats[0].DL_pmi_single,
-                                             0);
-
-          num_common_dci++;
+          num_ue_spec_dci++;
           num_dci++;
+          break;
 
-        }
-
-        break;
-
-      case 5:
-      case 6:
-        memcpy(&dci_alloc[num_dci].dci_pdu[0],&DLSCH_alloc_pdu2_1E[k],sizeof(DCI1E_5MHz_2A_M10PRB_TDD_t));
-        dci_alloc[num_dci].dci_length   = sizeof_DCI1E_5MHz_2A_M10PRB_TDD_t;
-        dci_alloc[num_dci].L            = 1;
-        dci_alloc[num_dci].rnti         = n_rnti+k;
-        dci_alloc[num_dci].format       = format1E_2A_M10PRB;
-        dci_alloc[num_dci].firstCCE     = 4*k;
-        dci_alloc[num_dci].search_space = DCI_UE_SPACE;
-        printf("Generating dlsch params for user %d\n",k);
-        generate_eNB_dlsch_params_from_dci(0,
-					   subframe,
-                                           &DLSCH_alloc_pdu2_1E[k],
-                                           n_rnti+k,
-                                           format1E_2A_M10PRB,
-                                           eNB->dlsch[k],
-                                           &eNB->frame_parms,
-                                           eNB->pdsch_config_dedicated,
-                                           SI_RNTI,
-                                           0,
-                                           P_RNTI,
-                                           eNB->UE_stats[k].DL_pmi_single,
-                                           0);
-
-        dump_dci(&eNB->frame_parms,&dci_alloc[num_dci]);
-        num_ue_spec_dci++;
-        num_dci++;
-
-        break;
-
-      default:
-        printf("Unsupported Transmission Mode!!!");
-        exit(-1);
-        break;
+        default:
+          printf("Unsupported Transmission Mode!!!");
+          exit(-1);
+          break;
       }
 
-
-
-
       /*
       memcpy(&dci_alloc[1].dci_pdu[0],&UL_alloc_pdu,sizeof(DCI0_5MHz_TDD0_t));
       dci_alloc[1].dci_length = sizeof_DCI0_5MHz_TDD_0_t;
@@ -1966,13 +1883,12 @@ int main(int argc, char **argv)
     memset(CCE_table,0,800*sizeof(int));
 
     for (i=num_common_dci; i<num_dci; i++) {
-
       dci_alloc[i].firstCCE = get_nCCE_offset_l1(CCE_table,
-						 1<<dci_alloc[i].L,
-						 numCCE,
-						 (dci_alloc[i].rnti==SI_RNTI)? 1 : 0,
-						 dci_alloc[i].rnti,
-						 subframe);
+                              1<<dci_alloc[i].L,
+                              numCCE,
+                              (dci_alloc[i].rnti==SI_RNTI)? 1 : 0,
+                              dci_alloc[i].rnti,
+                              subframe);
 
       if (n_frames==1)
         printf("dci %d: rnti %x, format %d : nCCE %d/%d\n",i,dci_alloc[i].rnti, dci_alloc[i].format,
@@ -1980,7 +1896,6 @@ int main(int argc, char **argv)
     }
 
     for (k=0; k<n_users; k++) {
-
       input_buffer_length0 = eNB->dlsch[k][0]->harq_processes[0]->TBS/8;
       input_buffer0[k] = (unsigned char *)malloc(input_buffer_length0+4);
       memset(input_buffer0[k],0,input_buffer_length0+4);
@@ -1997,13 +1912,11 @@ int main(int argc, char **argv)
         for (i=0; i<input_buffer_length1; i++) {
           input_buffer1[k][i]= (unsigned char)(taus()&0xff);
         }
-      }
-
-      else {
+      } else {
         i=0;
 
         while ((!feof(input_trch_fd)) && (i<input_buffer_length0<<3)) {
-          ret=fscanf(input_trch_fd,"%s",input_trch_val);
+          ret=fscanf(input_trch_fd,"%15s",input_trch_val);
 
           if (input_trch_val[0] == '1')
             input_buffer0[k][i>>3]+=(1<<(7-(i&7)));
@@ -2030,12 +1943,10 @@ int main(int argc, char **argv)
                                   eNB->dlsch[0][0]->harq_processes[0]->Nl,
                                   num_pdcch_symbols,
                                   0,
- 				  subframe,
-				  (transmission_mode<7?0:transmission_mode));
-
-  uncoded_ber_bit = (short*) malloc(sizeof(short)*coded_bits_per_codeword);
+                                  subframe,
+                                  (transmission_mode<7?0:transmission_mode));
+  uncoded_ber_bit = (short *) malloc(sizeof(short)*coded_bits_per_codeword);
   printf("uncoded_ber_bit=%p\n",uncoded_ber_bit);
-
   snr_step = input_snr_step;
   UE->high_speed_flag = 0; //1
   UE->ch_est_alpha=0;
@@ -2059,10 +1970,8 @@ int main(int argc, char **argv)
       round_trials[1] = 0;
       round_trials[2] = 0;
       round_trials[3] = 0;
-
       dci_errors=0;
       //      avg_ber = 0;
-
       round=0;
       avg_iter = 0;
       iter_trials=0;
@@ -2075,7 +1984,6 @@ int main(int argc, char **argv)
       reset_meas(&eNB->dlsch_interleaving_stats);
       reset_meas(&eNB->dlsch_rate_matching_stats);
       reset_meas(&eNB->dlsch_turbo_encoding_stats);
-
       reset_meas(&UE->phy_proc_rx[UE->current_thread_id[subframe]]); // total UE rx
       reset_meas(&UE->ofdm_demod_stats);
       reset_meas(&UE->dlsch_channel_estimation_stats);
@@ -2101,7 +2009,6 @@ int main(int argc, char **argv)
       initialize(&time_vector_tx_mod);
       struct list time_vector_tx_enc;
       initialize(&time_vector_tx_enc);
-
       struct list time_vector_rx;
       initialize(&time_vector_rx);
       struct list time_vector_rx_fft;
@@ -2115,14 +2022,12 @@ int main(int argc, char **argv)
         //  printf("Trial %d\n",trials);
         fflush(stdout);
         round=0;
-
         //if (trials%100==0)
         eNB2UE[0]->first_run = 1;
-
         ret = UE->dlsch[UE->current_thread_id[subframe]][0][0]->max_turbo_iterations+1;
 
         while ((round < num_rounds) && (ret > UE->dlsch[UE->current_thread_id[subframe]][0][0]->max_turbo_iterations)) {
-              //printf("Trial %d, round %d\n",trials,round);
+          //printf("Trial %d, round %d\n",trials,round);
           round_trials[round]++;
 
           if(transmission_mode>=5&&transmission_mode<7)
@@ -2140,31 +2045,30 @@ int main(int argc, char **argv)
 
 PMI_FEEDBACK:
 
-	  //make sure dlsim is called with perfect channel estimation option (for freq_channel)
-	  //fill drs_ch_estimates with data from eNB2UE->chF
-	  for(aa=0; aa<frame_parms->nb_antenna_ports_eNB; aa++) {
-	    for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
-	      for (i=0; i<frame_parms->N_RB_DL*12; i++) {
-		for (l=0; l<frame_parms->symbols_per_tti; l++) {
-		  ((int16_t *) eNB->pusch_vars[0]->drs_ch_estimates[0][(aa<<1)+aarx])[2*i+(l*frame_parms->ofdm_symbol_size)*2]=(int16_t)(eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x*AMP);
-                          //printf("x=%d,AMP=%d\n",eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x,AMP);
-		  ((int16_t *) eNB->pusch_vars[0]->drs_ch_estimates[0][(aa<<1)+aarx])[2*i+1+(l*frame_parms->ofdm_symbol_size)*2]=(int16_t)(eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].y*AMP);
-		}
-	      }
-	    }
-	  }
-
-	  estimate_DLCSI_from_ULCSI(eNB->dlsch[0][0]->calib_dl_ch_estimates,
-					 &eNB->pusch_vars[0]->drs_ch_estimates[0][0/*position of second DMRS*/],
-					 eNB->common_vars.tdd_calib_coeffs[0],
-					 frame_parms->nb_antennas_tx,
-					 frame_parms->N_RB_DL*12);
-	  
-	  compute_BF_weights(eNB->dlsch[0][0]->ue_spec_bf_weights[0],
-			     eNB->dlsch[0][0]->calib_dl_ch_estimates,
-			     MRT,
-			     frame_parms->nb_antennas_tx,
-			     frame_parms->N_RB_DL*12);
+          //make sure dlsim is called with perfect channel estimation option (for freq_channel)
+          //fill drs_ch_estimates with data from eNB2UE->chF
+          for(aa=0; aa<frame_parms->nb_antenna_ports_eNB; aa++) {
+            for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
+              for (i=0; i<frame_parms->N_RB_DL*12; i++) {
+                for (l=0; l<frame_parms->symbols_per_tti; l++) {
+                  ((int16_t *) eNB->pusch_vars[0]->drs_ch_estimates[0][(aa<<1)+aarx])[2*i+(l*frame_parms->ofdm_symbol_size)*2]=(int16_t)(eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x*AMP);
+                  //printf("x=%d,AMP=%d\n",eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x,AMP);
+                  ((int16_t *) eNB->pusch_vars[0]->drs_ch_estimates[0][(aa<<1)+aarx])[2*i+1+(l*frame_parms->ofdm_symbol_size)*2]=(int16_t)(eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].y*AMP);
+                }
+              }
+            }
+          }
+
+          estimate_DLCSI_from_ULCSI(eNB->dlsch[0][0]->calib_dl_ch_estimates,
+                                    &eNB->pusch_vars[0]->drs_ch_estimates[0][0/*position of second DMRS*/],
+                                    eNB->common_vars.tdd_calib_coeffs[0],
+                                    frame_parms->nb_antennas_tx,
+                                    frame_parms->N_RB_DL*12);
+          compute_BF_weights(eNB->dlsch[0][0]->ue_spec_bf_weights[0],
+                             eNB->dlsch[0][0]->calib_dl_ch_estimates,
+                             MRT,
+                             frame_parms->nb_antennas_tx,
+                             frame_parms->N_RB_DL*12);
 
           //printf("Trial %d : Round %d, pmi_feedback %d \n",trials,round,pmi_feedback);
           for (aa=0; aa<NB_ANTENNA_PORTS_ENB; aa++) {
@@ -2172,397 +2076,390 @@ PMI_FEEDBACK:
           }
 
           if (input_fd==NULL) {
-
             start_meas(&eNB->phy_proc_tx);
 
             // Simulate HARQ procedures!!!
             if (common_flag == 0) {
-
               if (round == 0) {   // First round
                 TB0_active = 1;
-
                 eNB->dlsch[0][0]->harq_processes[0]->rvidx = round&3;
 
                 if (eNB->frame_parms.frame_type == TDD) {
-
                   switch (transmission_mode) {
-                  case 1:
-                  case 2:
-                  case 7:
-                    switch (eNB->frame_parms.N_RB_DL) {
-                    case 6:
-                      ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
-                      ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = 0;
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_1_5MHz_TDD_t));
-                      break;
-
-                    case 25:
-                      ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
-                      ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = 0;
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_5MHz_TDD_t));
-                      break;
-
-                    case 50:
-                      ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
-                      ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = 0;
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_10MHz_TDD_t));
-                      break;
-
-                    case 100:
-                      ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
-                      ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = 0;
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_20MHz_TDD_t));
-                      break;
-                    }
-
-                    break;
+                    case 1:
+                    case 2:
+                    case 7:
+                      switch (eNB->frame_parms.N_RB_DL) {
+                        case 6:
+                          ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
+                          ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = 0;
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_1_5MHz_TDD_t));
+                          break;
+
+                        case 25:
+                          ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
+                          ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = 0;
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_5MHz_TDD_t));
+                          break;
+
+                        case 50:
+                          ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
+                          ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = 0;
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_10MHz_TDD_t));
+                          break;
+
+                        case 100:
+                          ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
+                          ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = 0;
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_20MHz_TDD_t));
+                          break;
+                      }
 
-                  case 3:
-                    switch (eNB->frame_parms.N_RB_DL) {
-                    case 6:
-                      ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
-                      ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 0;
-                      ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
-                      ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = 0;
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_1_5MHz_2A_TDD_t));
                       break;
 
-                    case 25:
-                      ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
-                      ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 0;
-                      ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
-                      ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = 0;
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_5MHz_2A_TDD_t));
-                      break;
+                    case 3:
+                      switch (eNB->frame_parms.N_RB_DL) {
+                        case 6:
+                          ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
+                          ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 0;
+                          ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
+                          ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = 0;
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_1_5MHz_2A_TDD_t));
+                          break;
+
+                        case 25:
+                          ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
+                          ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 0;
+                          ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
+                          ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = 0;
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_5MHz_2A_TDD_t));
+                          break;
+
+                        case 50:
+                          ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
+                          ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 0;
+                          ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
+                          ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = 0;
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_10MHz_2A_TDD_t));
+                          break;
+
+                        case 100:
+                          ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
+                          ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 0;
+                          ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
+                          ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = 0;
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_20MHz_2A_TDD_t));
+                          break;
+                      }
 
-                    case 50:
-                      ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
-                      ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 0;
-                      ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
-                      ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = 0;
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_10MHz_2A_TDD_t));
                       break;
 
-                    case 100:
-                      ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
-                      ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 0;
-                      ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
-                      ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = 0;
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_20MHz_2A_TDD_t));
+                    case 5:
+                      DLSCH_alloc_pdu2_1E[0].ndi             = trials&1;
+                      DLSCH_alloc_pdu2_1E[0].rv              = 0;
+                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu2_1E[0],sizeof(DCI1E_5MHz_2A_M10PRB_TDD_t));
                       break;
-                    }
-
-                    break;
-
-                  case 5:
-                    DLSCH_alloc_pdu2_1E[0].ndi             = trials&1;
-                    DLSCH_alloc_pdu2_1E[0].rv              = 0;
-                    memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu2_1E[0],sizeof(DCI1E_5MHz_2A_M10PRB_TDD_t));
-                    break;
-
                   }
                 } else { // FDD
                   switch (transmission_mode) {
-                  case 1:
-                  case 2:
-                  case 7:
-                    switch (eNB->frame_parms.N_RB_DL) {
-                    case 6:
-                      ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
-                      ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = 0;
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_1_5MHz_FDD_t));
-                      break;
-
-                    case 25:
-                      ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
-                      ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = 0;
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_5MHz_FDD_t));
-                      break;
-
-                    case 50:
-                      ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
-                      ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = 0;
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_10MHz_FDD_t));
-                      break;
-
-                    case 100:
-                      ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
-                      ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = 0;
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_20MHz_FDD_t));
-                      break;
-                    }
+                    case 1:
+                    case 2:
+                    case 7:
+                      switch (eNB->frame_parms.N_RB_DL) {
+                        case 6:
+                          ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
+                          ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = 0;
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_1_5MHz_FDD_t));
+                          break;
+
+                        case 25:
+                          ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
+                          ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = 0;
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_5MHz_FDD_t));
+                          break;
+
+                        case 50:
+                          ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
+                          ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = 0;
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_10MHz_FDD_t));
+                          break;
+
+                        case 100:
+                          ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
+                          ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = 0;
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_20MHz_FDD_t));
+                          break;
+                      }
 
-                    break;
-                  case 3:
-                    switch (eNB->frame_parms.N_RB_DL) {
-                    case 6:
-                      ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
-                      ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 0;
-                      ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
-                      ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = 0;
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_1_5MHz_2A_FDD_t));
                       break;
 
-                    case 25:
-                      ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
-                      ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 0;
-                      ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
-                      ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = 0;
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_5MHz_2A_FDD_t));
-                      break;
+                    case 3:
+                      switch (eNB->frame_parms.N_RB_DL) {
+                        case 6:
+                          ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
+                          ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 0;
+                          ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
+                          ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = 0;
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_1_5MHz_2A_FDD_t));
+                          break;
+
+                        case 25:
+                          ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
+                          ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 0;
+                          ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
+                          ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = 0;
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_5MHz_2A_FDD_t));
+                          break;
+
+                        case 50:
+                          ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
+                          ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 0;
+                          ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
+                          ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = 0;
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_10MHz_2A_FDD_t));
+                          break;
+
+                        case 100:
+                          ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
+                          ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 0;
+                          ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
+                          ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = 0;
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_20MHz_2A_FDD_t));
+                          break;
+                      }
 
-                    case 50:
-                      ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
-                      ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 0;
-                      ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
-                      ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = 0;
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_10MHz_2A_FDD_t));
                       break;
 
-                    case 100:
-                      ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
-                      ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 0;
-                      ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
-                      ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = 0;
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_20MHz_2A_FDD_t));
+                    case 5:
+                      DLSCH_alloc_pdu2_1E[0].ndi             = trials&1;
+                      DLSCH_alloc_pdu2_1E[0].rv              = 0;
+                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu2_1E[0],sizeof(DCI1E_5MHz_2A_M10PRB_TDD_t));
                       break;
-                    }
-
-                    break;
-
-                  case 5:
-                    DLSCH_alloc_pdu2_1E[0].ndi             = trials&1;
-                    DLSCH_alloc_pdu2_1E[0].rv              = 0;
-                    memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu2_1E[0],sizeof(DCI1E_5MHz_2A_M10PRB_TDD_t));
-                    break;
                   }
-
                 }
               } else {
                 eNB->dlsch[0][0]->harq_processes[0]->rvidx = round&3;
 
                 if (eNB->frame_parms.frame_type == TDD) {
-
-
                   switch (transmission_mode) {
-                  case 1:
-                  case 2:
-                  case 7:
-                    switch (eNB->frame_parms.N_RB_DL) {
-                    case 6:
-                      ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
-                      ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = round&3;;
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_1_5MHz_TDD_t));
-                      break;
-
-                    case 25:
-                      ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
-                      ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = round&3;
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_5MHz_TDD_t));
-                      break;
-
-                    case 50:
-                      ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
-                      ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = round&3;
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_10MHz_TDD_t));
-                      break;
-
-                    case 100:
-                      ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
-                      ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = round&3;
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_20MHz_TDD_t));
-                      break;
-                    }
-
-                    break;
-
-                  case 3:
-                    switch (eNB->frame_parms.N_RB_DL) {
-                    case 6:
-                      if (TB0_active==1) {
-                        ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
-                        ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = round&3;
-                        ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
-                        ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
-                      } else { // deactivate TB0
-                        ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1             = 0;
-                        ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 1;
-                        ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
-                        ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
+                    case 1:
+                    case 2:
+                    case 7:
+                      switch (eNB->frame_parms.N_RB_DL) {
+                        case 6:
+                          ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
+                          ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = round&3;;
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_1_5MHz_TDD_t));
+                          break;
+
+                        case 25:
+                          ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
+                          ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = round&3;
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_5MHz_TDD_t));
+                          break;
+
+                        case 50:
+                          ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
+                          ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = round&3;
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_10MHz_TDD_t));
+                          break;
+
+                        case 100:
+                          ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
+                          ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = round&3;
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_20MHz_TDD_t));
+                          break;
                       }
 
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_1_5MHz_2A_TDD_t));
                       break;
 
-                    case 25:
-                      if (TB0_active==1) {
-                        ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
-                        ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = round&3;
-                        ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
-                        ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
-                      } else { // deactivate TB0
-                        ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1             = 0;
-                        ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 1;
-                        ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
-                        ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
-                      }
+                    case 3:
+                      switch (eNB->frame_parms.N_RB_DL) {
+                        case 6:
+                          if (TB0_active==1) {
+                            ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
+                            ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = round&3;
+                            ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
+                            ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
+                          } else { // deactivate TB0
+                            ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1             = 0;
+                            ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 1;
+                            ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
+                            ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
+                          }
 
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_5MHz_2A_TDD_t));
-                      break;
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_1_5MHz_2A_TDD_t));
+                          break;
+
+                        case 25:
+                          if (TB0_active==1) {
+                            ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
+                            ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = round&3;
+                            ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
+                            ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
+                          } else { // deactivate TB0
+                            ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1             = 0;
+                            ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 1;
+                            ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
+                            ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
+                          }
 
-                    case 50:
-                      if (TB0_active==1) {
-                        ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
-                        ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = round&3;
-                        ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
-                        ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
-                      } else { // deactivate TB0
-                        ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1             = 0;
-                        ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 1;
-                        ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
-                        ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
-                      }
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_5MHz_2A_TDD_t));
+                          break;
+
+                        case 50:
+                          if (TB0_active==1) {
+                            ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
+                            ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = round&3;
+                            ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
+                            ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
+                          } else { // deactivate TB0
+                            ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1             = 0;
+                            ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 1;
+                            ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
+                            ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
+                          }
 
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_10MHz_2A_TDD_t));
-                      break;
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_10MHz_2A_TDD_t));
+                          break;
+
+                        case 100:
+                          if (TB0_active==1) {
+                            ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
+                            ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = round&3;
+                            ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
+                            ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
+                          } else { // deactivate TB0
+                            ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1             = 0;
+                            ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 1;
+                            ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
+                            ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
+                          }
 
-                    case 100:
-                      if (TB0_active==1) {
-                        ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
-                        ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = round&3;
-                        ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
-                        ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
-                      } else { // deactivate TB0
-                        ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1             = 0;
-                        ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 1;
-                        ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
-                        ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_20MHz_2A_TDD_t));
+                          break;
                       }
 
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_20MHz_2A_TDD_t));
                       break;
-                    }
 
-                    break;
-
-                  case 5:
-                    DLSCH_alloc_pdu2_1E[0].ndi             = trials&1;
-                    DLSCH_alloc_pdu2_1E[0].rv              = round&3;
-                    memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu2_1E[0],sizeof(DCI1E_5MHz_2A_M10PRB_TDD_t));
-                    break;
+                    case 5:
+                      DLSCH_alloc_pdu2_1E[0].ndi             = trials&1;
+                      DLSCH_alloc_pdu2_1E[0].rv              = round&3;
+                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu2_1E[0],sizeof(DCI1E_5MHz_2A_M10PRB_TDD_t));
+                      break;
                   }
                 } else {
                   switch (transmission_mode) {
-                  case 1:
-                  case 2:
-                  case 7:
-                    switch (eNB->frame_parms.N_RB_DL) {
-                    case 6:
-                      ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
-                      ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = round&3;;
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_1_5MHz_FDD_t));
-                      break;
-
-                    case 25:
-                      ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
-                      ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = round&3;
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_5MHz_FDD_t));
-                      break;
-
-                    case 50:
-                      ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
-                      ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = round&3;
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_10MHz_FDD_t));
-                      break;
-
-                    case 100:
-                      ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
-                      ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = round&3;
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_20MHz_FDD_t));
-                      break;
-                    }
-
-                    break;
-
-                  case 3:
-                    switch (eNB->frame_parms.N_RB_DL) {
-                    case 6:
-                      if (TB0_active==1) {
-                        ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
-                        ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = round&3;
-                        ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
-                        ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
-                      } else { // deactivate TB0
-                        ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1             = 0;
-                        ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 1;
-                        ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
-                        ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
+                    case 1:
+                    case 2:
+                    case 7:
+                      switch (eNB->frame_parms.N_RB_DL) {
+                        case 6:
+                          ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
+                          ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = round&3;;
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_1_5MHz_FDD_t));
+                          break;
+
+                        case 25:
+                          ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
+                          ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = round&3;
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_5MHz_FDD_t));
+                          break;
+
+                        case 50:
+                          ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
+                          ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = round&3;
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_10MHz_FDD_t));
+                          break;
+
+                        case 100:
+                          ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi             = trials&1;
+                          ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv              = round&3;
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_20MHz_FDD_t));
+                          break;
                       }
 
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_1_5MHz_2A_FDD_t));
                       break;
 
-                    case 25:
-                      if (TB0_active==1) {
-                        ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
-                        ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = round&3;
-                        ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
-                        ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
-                      } else { // deactivate TB0
-                        ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1             = 0;
-                        ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 1;
-                        ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
-                        ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
-                      }
+                    case 3:
+                      switch (eNB->frame_parms.N_RB_DL) {
+                        case 6:
+                          if (TB0_active==1) {
+                            ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
+                            ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = round&3;
+                            ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
+                            ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
+                          } else { // deactivate TB0
+                            ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1             = 0;
+                            ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 1;
+                            ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
+                            ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
+                          }
 
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_5MHz_2A_FDD_t));
-                      break;
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_1_5MHz_2A_FDD_t));
+                          break;
+
+                        case 25:
+                          if (TB0_active==1) {
+                            ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
+                            ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = round&3;
+                            ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
+                            ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
+                          } else { // deactivate TB0
+                            ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1             = 0;
+                            ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 1;
+                            ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
+                            ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
+                          }
 
-                    case 50:
-                      if (TB0_active==1) {
-                        ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
-                        ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = round&3;
-                        ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
-                        ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
-                      } else { // deactivate TB0
-                        ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1             = 0;
-                        ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 1;
-                        ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
-                        ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
-                      }
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_5MHz_2A_FDD_t));
+                          break;
+
+                        case 50:
+                          if (TB0_active==1) {
+                            ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
+                            ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = round&3;
+                            ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
+                            ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
+                          } else { // deactivate TB0
+                            ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1             = 0;
+                            ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 1;
+                            ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
+                            ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
+                          }
 
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_10MHz_2A_FDD_t));
-                      break;
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_10MHz_2A_FDD_t));
+                          break;
+
+                        case 100:
+                          if (TB0_active==1) {
+                            ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
+                            ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = round&3;
+                            ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
+                            ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
+                          } else { // deactivate TB0
+                            ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1             = 0;
+                            ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 1;
+                            ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
+                            ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
+                          }
 
-                    case 100:
-                      if (TB0_active==1) {
-                        ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1             = trials&1;
-                        ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = round&3;
-                        ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
-                        ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
-                      } else { // deactivate TB0
-                        ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1             = 0;
-                        ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1              = 1;
-                        ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2             = trials&1;
-                        ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2              = round&3;
+                          memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_20MHz_2A_FDD_t));
+                          break;
                       }
 
-                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_20MHz_2A_FDD_t));
                       break;
-                    }
-
-                    break;
 
-                  case 5:
-                    DLSCH_alloc_pdu2_1E[0].ndi             = trials&1;
-                    DLSCH_alloc_pdu2_1E[0].rv              = round&3;
-                    memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu2_1E[0],sizeof(DCI1E_5MHz_2A_M10PRB_TDD_t));
-                    break;
+                    case 5:
+                      DLSCH_alloc_pdu2_1E[0].ndi             = trials&1;
+                      DLSCH_alloc_pdu2_1E[0].rv              = round&3;
+                      memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu2_1E[0],sizeof(DCI1E_5MHz_2A_M10PRB_TDD_t));
+                      break;
                   }
                 }
               }
             }
-	    
+
             num_pdcch_symbols_2 = generate_dci_top(num_ue_spec_dci + num_common_dci,
                                                    dci_alloc,
                                                    0,
@@ -2570,7 +2467,7 @@ PMI_FEEDBACK:
                                                    &eNB->frame_parms,
                                                    eNB->common_vars.txdataF[eNB_id],
                                                    subframe);
-	    
+
             if (num_pdcch_symbols_2 > num_pdcch_symbols) {
               msg("Error: given num_pdcch_symbols not big enough (%d > %d)\n",num_pdcch_symbols_2,num_pdcch_symbols);
               exit(-1);
@@ -2585,9 +2482,8 @@ PMI_FEEDBACK:
                                                 eNB->dlsch[k][cw]->harq_processes[0]->Nl,
                                                 num_pdcch_symbols,
                                                 0,
-						subframe,
-						(transmission_mode<7?0:transmission_mode));
-
+                                                subframe,
+                                                (transmission_mode<7?0:transmission_mode));
 #ifdef TBS_FIX   // This is for MESH operation!!!
                 tbs = (double)3*TBStable[get_I_TBS(eNB->dlsch[k][cw]->harq_processes[0]->mcs)][eNB->dlsch[k][cw]->nb_rb-1]/4;
 #else
@@ -2596,7 +2492,7 @@ PMI_FEEDBACK:
                 rate = (double)tbs/(double)coded_bits_per_codeword;
 
                 if ((SNR==snr0) && (trials==0) && (round==0))
-                  printf("User %d, cw %d: Rate = %f (%f bits/dim) (G %d, TBS %d, mod %d, pdcch_sym %d, ndi %d)\n",
+                  printf("User %d, cw %d: Rate = %f (%f bits/dim) (G %u, TBS %u, mod %d, pdcch_sym %d, ndi %d)\n",
                          k,cw,rate,rate*get_Qm(eNB->dlsch[k][0]->harq_processes[0]->mcs),
                          coded_bits_per_codeword,
                          tbs,
@@ -2621,11 +2517,10 @@ PMI_FEEDBACK:
                   */
                 }
 
-
                 start_meas(&eNB->dlsch_encoding_stats);
 
                 if (dlsch_encoding(eNB,
-				   ((cw==0) ? input_buffer0[k] : input_buffer1[k]),
+                                   ((cw==0) ? input_buffer0[k] : input_buffer1[k]),
                                    num_pdcch_symbols,
                                    eNB->dlsch[k][cw],
                                    0,subframe,
@@ -2649,7 +2544,6 @@ PMI_FEEDBACK:
                 }
                 */
                 stop_meas(&eNB->dlsch_encoding_stats);
-
                 eNB->dlsch[k][cw]->rnti = (common_flag==0) ? n_rnti+k : SI_RNTI;
                 start_meas(&eNB->dlsch_scrambling_stats);
                 dlsch_scrambling(&eNB->frame_parms,
@@ -2674,19 +2568,18 @@ PMI_FEEDBACK:
                   }
                 }
               }
-              
+
               start_meas(&eNB->dlsch_modulation_stats);
               re_allocated = dlsch_modulation(eNB,
-					      eNB->common_vars.txdataF[eNB_id],
+                                              eNB->common_vars.txdataF[eNB_id],
                                               AMP,
                                               frame,
                                               subframe,
                                               num_pdcch_symbols,
                                               eNB->dlsch[k][0],
-                                              eNB->dlsch[k][1]);	      
+                                              eNB->dlsch[k][1]);
               /* avoid gcc warnings */
               (void)re_allocated;
-
               stop_meas(&eNB->dlsch_modulation_stats);
               /*
               if (trials==0 && round==0)
@@ -2694,174 +2587,172 @@ PMI_FEEDBACK:
               */
             } //n_users
 
-
             generate_pilots(eNB,
                             eNB->common_vars.txdataF[eNB_id],
                             AMP,
                             LTE_NUMBER_OF_SUBFRAMES_PER_FRAME);
-/*
-	    //PSS/SSS
-            if (eNB->frame_parms.frame_type == FDD) {
-              generate_pss(eNB->common_vars.txdataF[0],
-                           AMP,
-                           &eNB->frame_parms,
-                           (eNB->frame_parms.Ncp==NORMAL) ? 6 : 5,
-                           0);
-              generate_sss(eNB->common_vars.txdataF[0],
-                           AMP,
-                           &eNB->frame_parms,
-                           (eNB->frame_parms.Ncp==NORMAL) ? 5 : 4,
-                           0);
-              generate_pss(eNB->common_vars.txdataF[0],
-                           AMP,
-                           &eNB->frame_parms,
-                           (eNB->frame_parms.Ncp==NORMAL) ? 6 : 5,
-                           10);
-              generate_sss(eNB->common_vars.txdataF[0],
-                           AMP,
-                           &eNB->frame_parms,
-                           (eNB->frame_parms.Ncp==NORMAL) ? 5 : 4,
-                           10);
-	    }
-            else if (eNB->frame_parms.frame_type == TDD) {
-              generate_sss(eNB->common_vars.txdataF[0],
-                           AMP,
-                           &eNB->frame_parms,
-                           (eNB->frame_parms.Ncp==NORMAL) ? 6 : 5,
-                           1);
-              generate_pss(eNB->common_vars.txdataF[0],
-                           AMP,
-                           &eNB->frame_parms,
-                           2,
-                           2);
-              generate_sss(eNB->common_vars.txdataF[0],
-                           AMP,
-                           &eNB->frame_parms,
-                           (eNB->frame_parms.Ncp==NORMAL) ? 6 : 5,
-                           11);
-              generate_pss(eNB->common_vars.txdataF[0],
-                           AMP,
-                           &eNB->frame_parms,
-                           2,
-                           12);
-            }
+            /*
+                  //PSS/SSS
+                        if (eNB->frame_parms.frame_type == FDD) {
+                          generate_pss(eNB->common_vars.txdataF[0],
+                                       AMP,
+                                       &eNB->frame_parms,
+                                       (eNB->frame_parms.Ncp==NORMAL) ? 6 : 5,
+                                       0);
+                          generate_sss(eNB->common_vars.txdataF[0],
+                                       AMP,
+                                       &eNB->frame_parms,
+                                       (eNB->frame_parms.Ncp==NORMAL) ? 5 : 4,
+                                       0);
+                          generate_pss(eNB->common_vars.txdataF[0],
+                                       AMP,
+                                       &eNB->frame_parms,
+                                       (eNB->frame_parms.Ncp==NORMAL) ? 6 : 5,
+                                       10);
+                          generate_sss(eNB->common_vars.txdataF[0],
+                                       AMP,
+                                       &eNB->frame_parms,
+                                       (eNB->frame_parms.Ncp==NORMAL) ? 5 : 4,
+                                       10);
+                  }
+                        else if (eNB->frame_parms.frame_type == TDD) {
+                          generate_sss(eNB->common_vars.txdataF[0],
+                                       AMP,
+                                       &eNB->frame_parms,
+                                       (eNB->frame_parms.Ncp==NORMAL) ? 6 : 5,
+                                       1);
+                          generate_pss(eNB->common_vars.txdataF[0],
+                                       AMP,
+                                       &eNB->frame_parms,
+                                       2,
+                                       2);
+                          generate_sss(eNB->common_vars.txdataF[0],
+                                       AMP,
+                                       &eNB->frame_parms,
+                                       (eNB->frame_parms.Ncp==NORMAL) ? 6 : 5,
+                                       11);
+                          generate_pss(eNB->common_vars.txdataF[0],
+                                       AMP,
+                                       &eNB->frame_parms,
+                                       2,
+                                       12);
+                        }
 
-              //PBCH
-              pbch_pdu[2] = 0;
+                          //PBCH
+                          pbch_pdu[2] = 0;
 
-              // FIXME setting pbch_pdu[2] to zero makes the switch statement easier: remove all the or-operators
-              switch (eNB->frame_parms.N_RB_DL) {
-              case 6:
-                pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (0<<5);
-                break;
-
-              case 15:
-                pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (1<<5);
-                break;
-
-              case 25:
-                pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (2<<5);
-                break;
-
-              case 50:
-                pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (3<<5);
-                break;
-
-              case 75:
-                pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (4<<5);
-                break;
-
-              case 100:
-                pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (5<<5);
-                break;
-
-              default:
-                // FIXME if we get here, this should be flagged as an error, right?
-                pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (2<<5);
-                break;
-              }
+                          // FIXME setting pbch_pdu[2] to zero makes the switch statement easier: remove all the or-operators
+                          switch (eNB->frame_parms.N_RB_DL) {
+                          case 6:
+                            pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (0<<5);
+                            break;
 
-              pbch_pdu[2] = (pbch_pdu[2]&0xef) |
-                            ((eNB->frame_parms.phich_config_common.phich_duration << 4)&0x10);
+                          case 15:
+                            pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (1<<5);
+                            break;
 
-              switch (eNB->frame_parms.phich_config_common.phich_resource) {
-              case oneSixth:
-                pbch_pdu[2] = (pbch_pdu[2]&0xf3) | (0<<2);
-                break;
+                          case 25:
+                            pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (2<<5);
+                            break;
 
-              case half:
-                pbch_pdu[2] = (pbch_pdu[2]&0xf3) | (1<<2);
-                break;
+                          case 50:
+                            pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (3<<5);
+                            break;
 
-              case one:
-                pbch_pdu[2] = (pbch_pdu[2]&0xf3) | (2<<2);
-                break;
+                          case 75:
+                            pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (4<<5);
+                            break;
 
-              case two:
-                pbch_pdu[2] = (pbch_pdu[2]&0xf3) | (3<<2);
-                break;
+                          case 100:
+                            pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (5<<5);
+                            break;
 
-              default:
-                // unreachable
-                break;
-              
+                          default:
+                            // FIXME if we get here, this should be flagged as an error, right?
+                            pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (2<<5);
+                            break;
+                          }
 
-              pbch_pdu[2] = (pbch_pdu[2]&0xfc) | ((0>>8)&0x3);
-              pbch_pdu[1] = 0&0xfc;
-              pbch_pdu[0] = 0;
-            }
+                          pbch_pdu[2] = (pbch_pdu[2]&0xef) |
+                                        ((eNB->frame_parms.phich_config_common.phich_duration << 4)&0x10);
+
+                          switch (eNB->frame_parms.phich_config_common.phich_resource) {
+                          case oneSixth:
+                            pbch_pdu[2] = (pbch_pdu[2]&0xf3) | (0<<2);
+                            break;
+
+                          case half:
+                            pbch_pdu[2] = (pbch_pdu[2]&0xf3) | (1<<2);
+                            break;
+
+                          case one:
+                            pbch_pdu[2] = (pbch_pdu[2]&0xf3) | (2<<2);
+                            break;
+
+                          case two:
+                            pbch_pdu[2] = (pbch_pdu[2]&0xf3) | (3<<2);
+                            break;
+
+                          default:
+                            // unreachable
+                            break;
 
-            generate_pbch(&eNB->lte_eNB_pbch,
-                          eNB->common_vars.txdataF[0],
-                          AMP,
-                          &eNB->frame_parms,
-                          pbch_pdu,
-                          0&3);
-*/
 
+                          pbch_pdu[2] = (pbch_pdu[2]&0xfc) | ((0>>8)&0x3);
+                          pbch_pdu[1] = 0&0xfc;
+                          pbch_pdu[0] = 0;
+                        }
+
+                        generate_pbch(&eNB->lte_eNB_pbch,
+                                      eNB->common_vars.txdataF[0],
+                                      AMP,
+                                      &eNB->frame_parms,
+                                      pbch_pdu,
+                                      0&3);
+            */
             start_meas(&eNB->ofdm_mod_stats);
-/*
-	    for(i=0;i<20;i++){
-	      
-              do_OFDM_mod_l(eNB->common_vars.txdataF[eNB_id],
-                            eNB->common_vars.txdata[eNB_id],
-                            i,
-                            &eNB->frame_parms);
- 	      } 
+            /*
+                  for(i=0;i<20;i++){
 
-*/
-            do_OFDM_mod_symbol(&eNB->common_vars,
-                          eNB_id,
-                          (subframe*2),
-                          &eNB->frame_parms);
+                          do_OFDM_mod_l(eNB->common_vars.txdataF[eNB_id],
+                                        eNB->common_vars.txdata[eNB_id],
+                                        i,
+                                        &eNB->frame_parms);
+                    }
 
+            */
             do_OFDM_mod_symbol(&eNB->common_vars,
-                          eNB_id,
-                          (subframe*2)+1,
-                          &eNB->frame_parms);
-
+                               eNB_id,
+                               (subframe*2),
+                               &eNB->frame_parms);
+            do_OFDM_mod_symbol(&eNB->common_vars,
+                               eNB_id,
+                               (subframe*2)+1,
+                               &eNB->frame_parms);
             stop_meas(&eNB->ofdm_mod_stats);
             stop_meas(&eNB->phy_proc_tx);
 
-           /* do_OFDM_mod_l(&eNB->common_vars,
-                          eNB_id,
-                          (subframe*2)+2,
-                          &eNB->frame_parms); */
+            /* do_OFDM_mod_l(&eNB->common_vars,
+                           eNB_id,
+                           (subframe*2)+2,
+                           &eNB->frame_parms); */
 
             if (n_frames==1) {
               if (transmission_mode<7)
                 LOG_M("txsigF0.m","txsF0", &eNB->common_vars.txdataF[eNB_id][0][subframe*nsymb*eNB->frame_parms.ofdm_symbol_size],
-                             nsymb*eNB->frame_parms.ofdm_symbol_size,1,1);
+                      nsymb*eNB->frame_parms.ofdm_symbol_size,1,1);
               else if (transmission_mode==7)
                 LOG_M("txsigF0.m","txsF0", &eNB->common_vars.txdataF[eNB_id][5][subframe*nsymb*eNB->frame_parms.ofdm_symbol_size],
-                             nsymb*eNB->frame_parms.ofdm_symbol_size,1,1);
+                      nsymb*eNB->frame_parms.ofdm_symbol_size,1,1);
+
               LOG_M("txsigF0_BF.m","txsF0_BF", &eNB->common_vars.txdataF_BF[eNB_id][0][0],
-                           eNB->frame_parms.ofdm_symbol_size,1,1);
+                    eNB->frame_parms.ofdm_symbol_size,1,1);
 
               if (eNB->frame_parms.nb_antennas_tx>1)// to be updated
                 LOG_M("txsigF1.m","txsF1", &eNB->common_vars.txdataF[eNB_id][1][subframe*nsymb*eNB->frame_parms.ofdm_symbol_size],
-                             nsymb*eNB->frame_parms.ofdm_symbol_size,1,1);
+                      nsymb*eNB->frame_parms.ofdm_symbol_size,1,1);
             }
+
             tx_lev = 0;
 
             for (aa=0; aa<eNB->frame_parms.nb_antennas_tx; aa++) {
@@ -2873,7 +2764,7 @@ PMI_FEEDBACK:
             tx_lev_dB = (unsigned int) dB_fixed(tx_lev);
 
             if (n_frames==1) {
-              printf("tx_lev = %d (%d dB)\n",tx_lev,tx_lev_dB);
+              printf("tx_lev = %u (%u dB)\n",tx_lev,tx_lev_dB);
               LOG_M("txsig0.m","txs0", &eNB->common_vars.txdata[eNB_id][0][subframe*eNB->frame_parms.samples_per_tti],eNB->frame_parms.samples_per_tti,1,1);
               // LOG_M("txsig0.m","txs0",&eNB->common_vars.txdata[eNB_id][0][0*eNB->frame_parms.samples_per_tti],eNB->frame_parms.samples_per_tti*10,1,1);
             }
@@ -2920,7 +2811,6 @@ PMI_FEEDBACK:
                     r_re[aarx][i] += (double)(((short *)eNB->common_vars.txdata[eNB_id][aa]))[(2*subframe*UE->frame_parms.samples_per_tti) +(i<<1)];
                     r_im[aarx][i] += (double)(((short *)eNB->common_vars.txdata[eNB_id][aa]))[(2*subframe*UE->frame_parms.samples_per_tti) +(i<<1)+1];
                   }
-
                 }
               }
             }
@@ -2938,16 +2828,16 @@ PMI_FEEDBACK:
                 random_channel(eNB2UE[2],0);
                 random_channel(eNB2UE[3],0);
               }
-	    
-	    if (UE->perfect_ce==1) {
-                  // fill in perfect channel estimates
-                  freq_channel(eNB2UE[round],UE->frame_parms.N_RB_DL,12*UE->frame_parms.N_RB_DL + 1);
-		  /*
-		  LOG_M("channel.m","ch",eNB2UE[round]->ch[0],eNB2UE[round]->channel_length,1,8);
-                  LOG_M("channelF.m","chF",eNB2UE[round]->chF[0],12*UE->frame_parms.N_RB_DL + 1,1,8);
-		  */
-	    }
-	  }
+
+            if (UE->perfect_ce==1) {
+              // fill in perfect channel estimates
+              freq_channel(eNB2UE[round],UE->frame_parms.N_RB_DL,12*UE->frame_parms.N_RB_DL + 1);
+              /*
+              LOG_M("channel.m","ch",eNB2UE[round]->ch[0],eNB2UE[round]->channel_length,1,8);
+                          LOG_M("channelF.m","chF",eNB2UE[round]->chF[0],12*UE->frame_parms.N_RB_DL + 1,1,8);
+              */
+            }
+          }
 
           if(abstx) {
             if (trials==0 && round==0) {
@@ -3017,17 +2907,16 @@ PMI_FEEDBACK:
           for (i=0; i<2*frame_parms->samples_per_tti; i++) {
             for (aa=0; aa<eNB->frame_parms.nb_antennas_rx; aa++) {
               // printf("s_re[0][%d]=> %f , r_re[0][%d]=> %f\n",i,s_re[aa][i],i,r_re[aa][i]);
-              ((short*) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti)+2*i] =
+              ((short *) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti)+2*i] =
                 (short) (r_re[aa][i] + sqrt(sigma2/2)*gaussdouble(0.0,1.0));
-              ((short*) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti)+2*i+1] =
+              ((short *) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti)+2*i+1] =
                 (short) (r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0));
               //((short*) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti)+2*i] = (short) r_re[aa][i];
-              //((short*) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti)+2*i+1] = (short) r_im[aa][i]; 
+              //((short*) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti)+2*i+1] = (short) r_im[aa][i];
               //printf("rxdata[%d][%d]=> %d, %d\n",aa,subframe*UE->frame_parms.samples_per_tti+i,r_re[aa][i],r_im[aa][i]);
             }
           }
 
-
           //    lte_sync_time_init(eNB->frame_parms,common_vars);
           //    lte_sync_time(common_vars->rxdata, eNB->frame_parms);
           //    lte_sync_time_free();
@@ -3064,12 +2953,11 @@ PMI_FEEDBACK:
             pilot2 = 6;
             pilot3 = 9;
           }
-          
 
           start_meas(&UE->phy_proc_rx[UE->current_thread_id[subframe]]);
 
           // Inner receiver scheduling for 3 slots
-        
+
           for (Ns=(2*subframe); Ns<((2*subframe)+3); Ns++) {
             for (l=0; l<pilot2; l++) {
               if (n_frames==1)
@@ -3087,14 +2975,13 @@ PMI_FEEDBACK:
               no_prefix  if 1 prefix is removed by HW
 
               */
-
               start_meas(&UE->ofdm_demod_stats);
               slot_fep(UE,
                        l,
                        Ns%20,
                        0,
                        0,
-		       0);
+                       0);
               stop_meas(&UE->ofdm_demod_stats);
 
               if (UE->perfect_ce==1) {
@@ -3103,26 +2990,27 @@ PMI_FEEDBACK:
                     for(aa=0; aa<frame_parms->nb_antenna_ports_eNB; aa++) {
                       for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
                         for (i=0; i<frame_parms->N_RB_DL*12; i++) {
-                          ((int16_t *) UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[k][(aa<<1)+aarx])[2*i+((l+(Ns%2)*pilot2)*frame_parms->ofdm_symbol_size+LTE_CE_FILTER_LENGTH)*2]=(int16_t)(
-                                eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x*AMP);
+                          ((int16_t *) UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[k][(aa<<1)+aarx])[2*i+((l+(Ns%2)*pilot2)*frame_parms->ofdm_symbol_size
+                              +LTE_CE_FILTER_LENGTH)*2]=(int16_t)(
+                                                          eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x*AMP);
                           //printf("x=%d,AMP=%d\n",eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x,AMP);
-                          ((int16_t *) UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[k][(aa<<1)+aarx])[2*i+1+((l+(Ns%2)*pilot2)*frame_parms->ofdm_symbol_size+LTE_CE_FILTER_LENGTH)*2]=(int16_t)(
-                                eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].y*AMP);
+                          ((int16_t *) UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[k][(aa<<1)+aarx])[2*i+1+((l+(Ns%2)*pilot2)*frame_parms->ofdm_symbol_size
+                              +LTE_CE_FILTER_LENGTH)*2]=(int16_t)(
+                                                          eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].y*AMP);
 
-                          if (transmission_mode == 7){
-			    //this should include the BF weights! Will not work for a random channel
+                          if (transmission_mode == 7) {
+                            //this should include the BF weights! Will not work for a random channel
                             if (UE->high_speed_flag==0) {
                               ((int16_t *)UE->pdsch_vars[UE->current_thread_id[subframe]][0]->dl_bf_ch_estimates[(aa<<1)+aarx])[2*i]=(int16_t)(
-                                  eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x*AMP);
+                                    eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x*AMP);
                               ((int16_t *)UE->pdsch_vars[UE->current_thread_id[subframe]][0]->dl_bf_ch_estimates[(aa<<1)+aarx])[2*i+1]=(int16_t)(
-                                  eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].y*AMP);
+                                    eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].y*AMP);
                               //printf("**,x=%d,AMP=%d\n",eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x,AMP);
                             } else  {
                               ((int16_t *)UE->pdsch_vars[UE->current_thread_id[subframe]][0]->dl_bf_ch_estimates[(aa<<1)+aarx])[2*i+((l+(Ns%2)*pilot2)*frame_parms->ofdm_symbol_size)*2]=(int16_t)(
-                                  eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x*AMP);
+                                    eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x*AMP);
                               ((int16_t *)UE->pdsch_vars[UE->current_thread_id[subframe]][0]->dl_bf_ch_estimates[(aa<<1)+aarx])[2*i+1+((l+(Ns%2)*pilot2)*frame_parms->ofdm_symbol_size)*2]=(int16_t)(
-                                  eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].y*AMP);
-                                
+                                    eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].y*AMP);
                             }
                           }
                         }
@@ -3133,10 +3021,13 @@ PMI_FEEDBACK:
                   for(aa=0; aa<frame_parms->nb_antenna_ports_eNB; aa++) {
                     for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
                       for (i=0; i<frame_parms->N_RB_DL*12; i++) {
-                          ((int16_t *) UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[0][(aa<<1)+aarx])[2*i+((l+(Ns%2)*pilot2)*frame_parms->ofdm_symbol_size+LTE_CE_FILTER_LENGTH)*2]=(short)(AMP);
-                          ((int16_t *) UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[0][(aa<<1)+aarx])[2*i+1+((l+(Ns%2)*pilot2)*frame_parms->ofdm_symbol_size+LTE_CE_FILTER_LENGTH)*2]=0/2;
+                        ((int16_t *) UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[0][(aa<<1)+aarx])[2*i+((l+(Ns%2)*pilot2)*frame_parms->ofdm_symbol_size
+                            +LTE_CE_FILTER_LENGTH)*2]=(short)(AMP);
+                        ((int16_t *) UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[0][(aa<<1)+aarx])[2*i+1+((l+(Ns%2)*pilot2)*frame_parms->ofdm_symbol_size
+                            +LTE_CE_FILTER_LENGTH)*2]=0/2;
+
                         if (transmission_mode == 7) {
-                          if (UE->high_speed_flag==0){
+                          if (UE->high_speed_flag==0) {
                             ((int16_t *) UE->pdsch_vars[UE->current_thread_id[subframe]][0]->dl_bf_ch_estimates[(aa<<1)+aarx])[2*i]=(short)(AMP);
                             ((int16_t *) UE->pdsch_vars[UE->current_thread_id[subframe]][0]->dl_bf_ch_estimates[(aa<<1)+aarx])[2*i+1]=0/2;
                           } else {
@@ -3150,7 +3041,6 @@ PMI_FEEDBACK:
                 }
               }
 
-
               if ((Ns==((2*subframe))) && (l==0)) {
                 lte_ue_measurements(UE,
                                     subframe*UE->frame_parms.samples_per_tti,
@@ -3186,12 +3076,9 @@ PMI_FEEDBACK:
                     goto PMI_FEEDBACK;
                   }
                 }
-
               }
 
-
               if ((Ns==(2*subframe)) && (l==pilot1)) {// process symbols 0,1,2
-
                 if (dci_flag == 1) {
                   UE->UE_mode[0] = PUSCH;
                   start_meas(&UE->dlsch_rx_pdcch_stats);
@@ -3207,7 +3094,6 @@ PMI_FEEDBACK:
                   stop_meas(&UE->dlsch_rx_pdcch_stats);
                   // overwrite number of pdcch symbols
                   UE->pdcch_vars[0]->num_pdcch_symbols = num_pdcch_symbols;
-
                   dci_cnt = dci_decoding_procedure(UE,
                                                    dci_alloc_rx,1,
                                                    eNB_id,
@@ -3224,7 +3110,7 @@ PMI_FEEDBACK:
                       //round_trials[0]++;
 
                       if (n_frames==1)
-                        printf("DCI error trial %d errs[0] %d\n",trials,errs[0]);
+                        printf("DCI error trial %u errs[0] %u\n",trials,errs[0]);
                     }
 
                     //    for (i=1;i<=round;i++)
@@ -3238,7 +3124,7 @@ PMI_FEEDBACK:
 
                     if ((dci_alloc_rx[i].rnti == n_rnti) &&
                         (generate_ue_dlsch_params_from_dci(0,
-							   subframe,
+                                                           subframe,
                                                            dci_alloc_rx[i].dci_pdu,
                                                            dci_alloc_rx[i].rnti,
                                                            dci_alloc_rx[i].format,
@@ -3259,18 +3145,16 @@ PMI_FEEDBACK:
                                                       UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[UE->dlsch[UE->current_thread_id[subframe]][0][0]->current_harq_pid]->Nl,
                                                       UE->pdcch_vars[0]->num_pdcch_symbols,
                                                       0,
-						      subframe,
-						      (transmission_mode<7?0:transmission_mode));
-          	    /*if (transmission_mode==7 && common_flag==0)
-       	    	      UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->mimo_mode = TM7; */
-
+                                                      subframe,
+                                                      (transmission_mode<7?0:transmission_mode));
+                      /*if (transmission_mode==7 && common_flag==0)
+                          UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->mimo_mode = TM7; */
                       /*
                       rate = (double)dlsch_tbs25[get_I_TBS(UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[UE->dlsch[UE->current_thread_id[subframe]][0][0]->current_harq_pid]->mcs)][UE->dlsch[UE->current_thread_id[subframe]][0][0]->nb_rb-1]/(coded_bits_per_codeword);
                       rate*=get_Qm(UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[UE->dlsch[UE->current_thread_id[subframe]][0][0]->current_harq_pid]->mcs);
                       */
-                      printf("num_pdcch_symbols %d, G %d, TBS %d\n",UE->pdcch_vars[0]->num_pdcch_symbols,coded_bits_per_codeword,
+                      printf("num_pdcch_symbols %d, G %u, TBS %d\n",UE->pdcch_vars[0]->num_pdcch_symbols,coded_bits_per_codeword,
                              UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[UE->dlsch[UE->current_thread_id[subframe]][0][0]->current_harq_pid]->TBS);
-
                       dlsch_active = 1;
                     } else {
                       dlsch_active = 0;
@@ -3282,7 +3166,7 @@ PMI_FEEDBACK:
                         round=5;
 
                         if (n_frames==1)
-                          printf("DCI misdetection trial %d\n",trials);
+                          printf("DCI misdetection trial %u\n",trials);
 
                       }
 
@@ -3293,86 +3177,84 @@ PMI_FEEDBACK:
                   }
                 }  // if dci_flag==1
                 else { //dci_flag == 0
-
                   UE->pdcch_vars[0]->crnti = n_rnti;
                   UE->pdcch_vars[0]->num_pdcch_symbols = num_pdcch_symbols;
 
                   if (round == 0) UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->first_tx=1;
 
                   switch (transmission_mode) {
-                  case 1:
-                  case 2:
-                  case 7:
-                    generate_ue_dlsch_params_from_dci(0,
-						      subframe,
-                                                      &DLSCH_alloc_pdu_1[0],
-                                                      (common_flag==0)? C_RNTI : SI_RNTI,
-                                                      (common_flag==0)? format1 : format1A,
-                                                      UE->pdcch_vars[UE->current_thread_id[subframe]][eNB_id],
-                                                      UE->pdsch_vars[UE->current_thread_id[subframe]][eNB_id],
-                                                      UE->dlsch[UE->current_thread_id[subframe]][0],
-                                                      &UE->frame_parms,
-                                                      UE->pdsch_config_dedicated,
-                                                      SI_RNTI,
-                                                      0,
-                                                      P_RNTI,
-                                                      transmission_mode<7?0:transmission_mode);
-          	    /*if(transmission_mode==7 && common_flag==0)
-       	    	      UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->mimo_mode = TM7;*/
-                    break;
-
-                  case 3:
-                    //        printf("Rate: TM3 (before) round %d (%d) first_tx %d\n",round,UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->round,UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->first_tx);
-                    generate_ue_dlsch_params_from_dci(0,
-						      subframe,
-                                                      &DLSCH_alloc_pdu_1[0],
-                                                      (common_flag==0)? C_RNTI : SI_RNTI,
-                                                      (common_flag==0)? format2A : format1A,
-                                                      UE->dlsch[UE->current_thread_id[subframe]][0],
-                                                      &UE->frame_parms,
-                                                      UE->pdsch_config_dedicated,
-                                                      SI_RNTI,
-                                                      0,
-                                                      P_RNTI,
-                                                      0);
-                    //        printf("Rate: TM3 (after) round %d (%d) first_tx %d\n",round,UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->round,UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->first_tx);
-                    break;
+                    case 1:
+                    case 2:
+                    case 7:
+                      generate_ue_dlsch_params_from_dci(0,
+                                                        subframe,
+                                                        &DLSCH_alloc_pdu_1[0],
+                                                        (common_flag==0)? C_RNTI : SI_RNTI,
+                                                        (common_flag==0)? format1 : format1A,
+                                                        UE->pdcch_vars[UE->current_thread_id[subframe]][eNB_id],
+                                                        UE->pdsch_vars[UE->current_thread_id[subframe]][eNB_id],
+                                                        UE->dlsch[UE->current_thread_id[subframe]][0],
+                                                        &UE->frame_parms,
+                                                        UE->pdsch_config_dedicated,
+                                                        SI_RNTI,
+                                                        0,
+                                                        P_RNTI,
+                                                        transmission_mode<7?0:transmission_mode);
+                      /*if(transmission_mode==7 && common_flag==0)
+                          UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->mimo_mode = TM7;*/
+                      break;
 
-                  case 4:
-                    generate_ue_dlsch_params_from_dci(0,
-						      subframe,
-                                                      &DLSCH_alloc_pdu_1[0],
-                                                      (common_flag==0)? C_RNTI : SI_RNTI,
-                                                      (common_flag==0)? format2 : format1A,
-                                                      UE->pdcch_vars[UE->current_thread_id[subframe]][eNB_id],
-                                                      UE->pdsch_vars[UE->current_thread_id[subframe]][eNB_id],
-                                                      UE->dlsch[UE->current_thread_id[subframe]][0],
-                                                      &UE->frame_parms,
-                                                      UE->pdsch_config_dedicated,
-                                                      SI_RNTI,
-                                                      0,
-                                                      P_RNTI,
-                                                      0);
-                    break;
+                    case 3:
+                      //        printf("Rate: TM3 (before) round %d (%d) first_tx %d\n",round,UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->round,UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->first_tx);
+                      generate_ue_dlsch_params_from_dci(0,
+                                                        subframe,
+                                                        &DLSCH_alloc_pdu_1[0],
+                                                        (common_flag==0)? C_RNTI : SI_RNTI,
+                                                        (common_flag==0)? format2A : format1A,
+                                                        UE->dlsch[UE->current_thread_id[subframe]][0],
+                                                        &UE->frame_parms,
+                                                        UE->pdsch_config_dedicated,
+                                                        SI_RNTI,
+                                                        0,
+                                                        P_RNTI,
+                                                        0);
+                      //        printf("Rate: TM3 (after) round %d (%d) first_tx %d\n",round,UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->round,UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->first_tx);
+                      break;
 
-                  case 5:
-                  case 6:
-                    generate_ue_dlsch_params_from_dci(0,
-						      subframe,
-                                                      &DLSCH_alloc_pdu2_1E[0],
-                                                      C_RNTI,
-                                                      format1E_2A_M10PRB,
-                                                      ue->pdcch_vars[UE->current_thread_id[subframe]][eNB_id],
-                                                      ue->pdsch_vars[UE->current_thread_id[subframe]][eNB_id],
-                                                      UE->dlsch[UE->current_thread_id[subframe]][0],
-                                                      &UE->frame_parms,
-                                                      UE->pdsch_config_dedicated,
-                                                      SI_RNTI,
-                                                      0,
-                                                      P_RNTI,
-                                                      0);
-                    break;
+                    case 4:
+                      generate_ue_dlsch_params_from_dci(0,
+                                                        subframe,
+                                                        &DLSCH_alloc_pdu_1[0],
+                                                        (common_flag==0)? C_RNTI : SI_RNTI,
+                                                        (common_flag==0)? format2 : format1A,
+                                                        UE->pdcch_vars[UE->current_thread_id[subframe]][eNB_id],
+                                                        UE->pdsch_vars[UE->current_thread_id[subframe]][eNB_id],
+                                                        UE->dlsch[UE->current_thread_id[subframe]][0],
+                                                        &UE->frame_parms,
+                                                        UE->pdsch_config_dedicated,
+                                                        SI_RNTI,
+                                                        0,
+                                                        P_RNTI,
+                                                        0);
+                      break;
 
+                    case 5:
+                    case 6:
+                      generate_ue_dlsch_params_from_dci(0,
+                                                        subframe,
+                                                        &DLSCH_alloc_pdu2_1E[0],
+                                                        C_RNTI,
+                                                        format1E_2A_M10PRB,
+                                                        ue->pdcch_vars[UE->current_thread_id[subframe]][eNB_id],
+                                                        ue->pdsch_vars[UE->current_thread_id[subframe]][eNB_id],
+                                                        UE->dlsch[UE->current_thread_id[subframe]][0],
+                                                        &UE->frame_parms,
+                                                        UE->pdsch_config_dedicated,
+                                                        SI_RNTI,
+                                                        0,
+                                                        P_RNTI,
+                                                        0);
+                      break;
                   }
 
                   dlsch_active = 1;
@@ -3380,21 +3262,19 @@ PMI_FEEDBACK:
               }
 
               if (dlsch_active == 1) {
-                
-		if (transmission_mode==7) {
-		  if (UE->frame_parms.Ncp==0) {
-		    if ((Ns==(2*subframe)   && ((l==3) || (l==6))) ||
-			(Ns==(1+2*subframe) && ((l==2) || (l==5)))) {
-		      if (perfect_ce==0)
-			lte_dl_bf_channel_estimation(UE,eNB_id,0,Ns,5,l+7*(Ns%2==1)); 
-		    }
-		  } else {
-		    msg("Beamforming channel estimation not supported yet for TM7 extented CP.\n");
-		  }
-		}
+                if (transmission_mode==7) {
+                  if (UE->frame_parms.Ncp==0) {
+                    if ((Ns==(2*subframe)   && ((l==3) || (l==6))) ||
+                        (Ns==(1+2*subframe) && ((l==2) || (l==5)))) {
+                      if (perfect_ce==0)
+                        lte_dl_bf_channel_estimation(UE,eNB_id,0,Ns,5,l+7*(Ns%2==1));
+                    }
+                  } else {
+                    msg("Beamforming channel estimation not supported yet for TM7 extented CP.\n");
+                  }
+                }
 
                 if ((Ns==(1+(2*subframe))) && (l==0)) {// process PDSCH symbols 1,2,3,4,5,(6 Normal Prefix)
-
                   if ((transmission_mode == 5) &&
                       (UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->harq_processes[UE->dlsch[UE->current_thread_id[subframe]][0][0]->current_harq_pid]->dl_power_off==0) &&
                       (UE->use_ia_receiver ==1)) {
@@ -3403,7 +3283,6 @@ PMI_FEEDBACK:
                     dual_stream_UE = 0;
                   }
 
-
                   start_meas(&UE->dlsch_llr_stats);
 
                   for (m=UE->pdcch_vars[0]->num_pdcch_symbols;
@@ -3480,7 +3359,6 @@ PMI_FEEDBACK:
                   stop_meas(&UE->dlsch_llr_stats);
                 }
 
-
                 if (test_perf ==0 ) {
                   if ((n_frames==1) && (Ns==(2+(2*subframe))) && (l==0))  {
                     LOG_M("ch0.m","ch0",eNB2UE[0]->ch[0],eNB2UE[0]->channel_length,1,8);
@@ -3500,36 +3378,33 @@ PMI_FEEDBACK:
                     }
 
                     LOG_M("dlsch00_r0.m","dl00_r0",
-                                 &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][0][0]),
-                                 UE->frame_parms.ofdm_symbol_size*nsymb,1,1);
+                          &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][0][0]),
+                          UE->frame_parms.ofdm_symbol_size*nsymb,1,1);
 
                     if (UE->frame_parms.nb_antennas_rx>1)
                       LOG_M("dlsch01_r0.m","dl01_r0",
-                                   &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][1][0]),
-                                   UE->frame_parms.ofdm_symbol_size*nsymb,1,1);
+                            &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][1][0]),
+                            UE->frame_parms.ofdm_symbol_size*nsymb,1,1);
 
                     if (eNB->frame_parms.nb_antennas_tx>1)
                       LOG_M("dlsch10_r0.m","dl10_r0",
-                                   &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][2][0]),
-                                   UE->frame_parms.ofdm_symbol_size*nsymb,1,1);
+                            &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][2][0]),
+                            UE->frame_parms.ofdm_symbol_size*nsymb,1,1);
 
                     if ((UE->frame_parms.nb_antennas_rx>1) && (eNB->frame_parms.nb_antennas_tx>1))
                       LOG_M("dlsch11_r0.m","dl11_r0",
-                                   &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][3][0]),
-                                   UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1);
+                            &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][3][0]),
+                            UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1);
 
                     //pdsch_vars
                     dump_dlsch2(UE,eNB_id,subframe,&coded_bits_per_codeword,round);
                     //dump_dlsch2(UE,eNB_id_i,coded_bits_per_codeword);
                     LOG_M("dlsch_e.m","e",eNB->dlsch[0][0]->harq_processes[0]->e,coded_bits_per_codeword,1,4);
-
                     //pdcch_vars
                     LOG_M("pdcchF0_ext.m","pdcchF_ext", UE->pdcch_vars[eNB_id]->rxdataF_ext[0],2*3*UE->frame_parms.ofdm_symbol_size,1,1);
                     LOG_M("pdcch00_ch0_ext.m","pdcch00_ch0_ext",UE->pdcch_vars[eNB_id]->dl_ch_estimates_ext[0],300*3,1,1);
-
                     LOG_M("pdcch_rxF_comp0.m","pdcch0_rxF_comp0",UE->pdcch_vars[eNB_id]->rxdataF_comp[0],4*300,1,1);
                     LOG_M("pdcch_rxF_llr.m","pdcch_llr",UE->pdcch_vars[eNB_id]->llr,2400,1,4);
-
                   }
                 }
               }
@@ -3557,21 +3432,17 @@ PMI_FEEDBACK:
                                             eNB->dlsch[0][cw]->harq_processes[0]->Nl,
                                             num_pdcch_symbols,
                                             0,
-					    subframe,
-					    (transmission_mode<7?0:transmission_mode));
-
+                                            subframe,
+                                            (transmission_mode<7?0:transmission_mode));
             UE->dlsch[UE->current_thread_id[subframe]][0][cw]->harq_processes[UE->dlsch[UE->current_thread_id[subframe]][0][cw]->current_harq_pid]->G = coded_bits_per_codeword;
-
-
-	                
             // calculate uncoded BLER
             uncoded_ber=0;
-            for (i=0;i<coded_bits_per_codeword;i++)
+
+            for (i=0; i<coded_bits_per_codeword; i++)
               if (eNB->dlsch[0][0]->harq_processes[0]->e[i] != (UE->pdsch_vars[UE->current_thread_id[subframe]][0]->llr[0][i]<0)) {
                 uncoded_ber_bit[i] = 1;
                 uncoded_ber++;
-              }
-              else
+              } else
                 uncoded_ber_bit[i] = 0;
 
             uncoded_ber/=coded_bits_per_codeword;
@@ -3579,7 +3450,6 @@ PMI_FEEDBACK:
 
             if (n_frames==1)
               LOG_M("uncoded_ber_bit.m","uncoded_ber_bit",uncoded_ber_bit,coded_bits_per_codeword,1,0);
-            
 
             start_meas(&UE->dlsch_unscrambling_stats);
             dlsch_unscrambling(&UE->frame_parms,
@@ -3590,7 +3460,6 @@ PMI_FEEDBACK:
                                0,
                                subframe<<1);
             stop_meas(&UE->dlsch_unscrambling_stats);
-
             start_meas(&UE->dlsch_decoding_stats);
             ret = dlsch_decoding(UE,
                                  UE->pdsch_vars[UE->current_thread_id[subframe]][eNB_id]->llr[cw],
@@ -3610,12 +3479,9 @@ PMI_FEEDBACK:
             }
           }
 
-
           stop_meas(&UE->phy_proc_rx[UE->current_thread_id[subframe]]);
 
-
           if (ret <= UE->dlsch[UE->current_thread_id[subframe]][0][0]->max_turbo_iterations) {
-
             avg_iter += ret;
             iter_trials++;
 
@@ -3625,7 +3491,8 @@ PMI_FEEDBACK:
             UE->total_TBS[eNB_id] =  UE->total_TBS[eNB_id] + UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->harq_processes[UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->current_harq_pid]->TBS;
             TB0_active = 0;
 
-            if (UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->harq_processes[UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->current_harq_pid]->mimo_mode == LARGE_CDD) {   //try to decode second stream using SIC
+            if (UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->harq_processes[UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->current_harq_pid]->mimo_mode ==
+                LARGE_CDD) {   //try to decode second stream using SIC
               /*
               for (round = 0 ; round < UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->harq_processes[UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->current_harq_pid]->round ; round++) {
               // re-encoding of first stream
@@ -3667,12 +3534,11 @@ PMI_FEEDBACK:
             }
           } else {
             errs[round]++;
-
             avg_iter += ret-1;
             iter_trials++;
 
             if (n_frames==1) {
-              //if ((n_frames==1) || (SNR>=30)) 
+              //if ((n_frames==1) || (SNR>=30))
               printf("DLSCH errors found (round %d), uncoded ber %f\n",round,uncoded_ber);
 
               for (s=0; s<UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->C; s++) {
@@ -3682,11 +3548,11 @@ PMI_FEEDBACK:
                   Kr = UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->Kplus;
 
                 Kr_bytes = Kr>>3;
-
                 printf("Decoded_output (Segment %d):\n",s);
 
                 for (i=0; i<Kr_bytes; i++)
-                  printf("%d : %x (%x)\n",i,UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->c[s][i],UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->c[s][i]^eNB->dlsch[0][0]->harq_processes[0]->c[s][i]);
+                  printf("%d : %x (%x)\n",i,UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->c[s][i],
+                         UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->c[s][i]^eNB->dlsch[0][0]->harq_processes[0]->c[s][i]);
               }
 
               sprintf(fname,"rxsig0_r%d.m",round);
@@ -3695,7 +3561,7 @@ PMI_FEEDBACK:
               sprintf(fname,"rxsigF0_r%d.m",round);
               sprintf(vname,"rxs0F_r%d",round);
               LOG_M(fname,vname, &UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].rxdataF[0][0],2*UE->frame_parms.ofdm_symbol_size*nsymb,2,1);
-	     
+
               if (UE->frame_parms.nb_antennas_rx>1) {
                 sprintf(fname,"rxsig1_r%d.m",round);
                 sprintf(vname,"rxs1_r%d.m",round);
@@ -3708,31 +3574,31 @@ PMI_FEEDBACK:
               sprintf(fname,"dlsch00_r%d.m",round);
               sprintf(vname,"dl00_r%d",round);
               LOG_M(fname,vname,
-                           &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][0][0]),
-                           UE->frame_parms.ofdm_symbol_size*nsymb,1,1);
+                    &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][0][0]),
+                    UE->frame_parms.ofdm_symbol_size*nsymb,1,1);
 
               if (UE->frame_parms.nb_antennas_rx>1) {
                 sprintf(fname,"dlsch01_r%d.m",round);
                 sprintf(vname,"dl01_r%d",round);
                 LOG_M(fname,vname,
-                             &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][1][0]),
-                             UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1);
+                      &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][1][0]),
+                      UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1);
               }
 
               if (eNB->frame_parms.nb_antennas_tx>1) {
                 sprintf(fname,"dlsch10_r%d.m",round);
                 sprintf(vname,"dl10_r%d",round);
                 LOG_M(fname,vname,
-                             &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][2][0]),
-                             UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1);
+                      &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][2][0]),
+                      UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1);
               }
 
               if ((UE->frame_parms.nb_antennas_rx>1) && (eNB->frame_parms.nb_antennas_tx>1)) {
                 sprintf(fname,"dlsch11_r%d.m",round);
                 sprintf(vname,"dl11_r%d",round);
                 LOG_M(fname,vname,
-                             &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][3][0]),
-                             UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1);
+                      &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][3][0]),
+                      UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1);
               }
 
               //pdsch_vars
@@ -3748,19 +3614,17 @@ PMI_FEEDBACK:
             }
 
             //      printf("round %d errors %d/%d\n",round,errs[round],trials);
-
             round++;
             //      UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->round++;
           }
 
-	  if (xforms==1) {
-	    phy_scope_UE(form_ue,
-			 UE,
-			 eNB_id,
-			 0,// UE_id
-			 subframe);
-	  }
-
+          if (xforms==1) {
+            phy_scope_UE(form_ue,
+                         UE,
+                         eNB_id,
+                         0,// UE_id
+                         subframe);
+          }
         }  //round
 
         //      printf("\n");
@@ -3778,9 +3642,7 @@ PMI_FEEDBACK:
           UE->total_TBS_last[eNB_id] = UE->total_TBS[eNB_id];
         }
 
-
         UE->proc.proc_rxtx[UE->current_thread_id[subframe]].frame_rx++;
-
         /* calculate the total processing time for each packet,
          * get the max, min, and number of packets that exceed t>2000us
          */
@@ -3788,8 +3650,6 @@ PMI_FEEDBACK:
         double t_tx_ifft = (double)eNB->ofdm_mod_stats.p_time/cpu_freq_GHz/1000.0;
         double t_tx_mod = (double)eNB->dlsch_modulation_stats.p_time/cpu_freq_GHz/1000.0;
         double t_tx_enc = (double)eNB->dlsch_encoding_stats.p_time/cpu_freq_GHz/1000.0;
-
-
         double t_rx = (double)UE->phy_proc_rx[UE->current_thread_id[subframe]].p_time/cpu_freq_GHz/1000.0;
         double t_rx_fft = (double)UE->ofdm_demod_stats.p_time/cpu_freq_GHz/1000.0;
         double t_rx_demod = (double)UE->dlsch_rx_pdcch_stats.p_time/cpu_freq_GHz/1000.0;
@@ -3817,13 +3677,10 @@ PMI_FEEDBACK:
         push_front(&time_vector_tx_ifft, t_tx_ifft);
         push_front(&time_vector_tx_mod, t_tx_mod);
         push_front(&time_vector_tx_enc, t_tx_enc);
-
         push_front(&time_vector_rx, t_rx);
         push_front(&time_vector_rx_fft, t_rx_fft);
         push_front(&time_vector_rx_demod, t_rx_demod);
         push_front(&time_vector_rx_dec, t_rx_dec);
-
-
       }   //trials
 
       // round_trials[0]: number of code word : goodput the protocol
@@ -3835,7 +3692,6 @@ PMI_FEEDBACK:
       totable(table_tx_mod, &time_vector_tx_mod);
       double table_tx_enc[time_vector_tx_enc.size];
       totable(table_tx_enc, &time_vector_tx_enc);
-
       double table_rx[time_vector_rx.size];
       totable(table_rx, &time_vector_rx);
       double table_rx_fft[time_vector_rx_fft.size];
@@ -3844,8 +3700,6 @@ PMI_FEEDBACK:
       totable(table_rx_demod, &time_vector_rx_demod);
       double table_rx_dec[time_vector_rx_dec.size];
       totable(table_rx_dec, &time_vector_rx_dec);
-
-
       // sort table
       qsort (table_tx, time_vector_tx.size, sizeof(double), &compare);
       qsort (table_rx, time_vector_rx.size, sizeof(double), &compare);
@@ -3859,53 +3713,41 @@ PMI_FEEDBACK:
       double tx_median = table_tx[time_vector_tx.size/2];
       double tx_q1 = table_tx[time_vector_tx.size/4];
       double tx_q3 = table_tx[3*time_vector_tx.size/4];
-
       double tx_ifft_median = table_tx_ifft[time_vector_tx_ifft.size/2];
       double tx_ifft_q1 = table_tx_ifft[time_vector_tx_ifft.size/4];
       double tx_ifft_q3 = table_tx_ifft[3*time_vector_tx_ifft.size/4];
-
       double tx_mod_median = table_tx_mod[time_vector_tx_mod.size/2];
       double tx_mod_q1 = table_tx_mod[time_vector_tx_mod.size/4];
       double tx_mod_q3 = table_tx_mod[3*time_vector_tx_mod.size/4];
-
       double tx_enc_median = table_tx_enc[time_vector_tx_enc.size/2];
       double tx_enc_q1 = table_tx_enc[time_vector_tx_enc.size/4];
       double tx_enc_q3 = table_tx_enc[3*time_vector_tx_enc.size/4];
-
       double rx_median = table_rx[time_vector_rx.size/2];
       double rx_q1 = table_rx[time_vector_rx.size/4];
       double rx_q3 = table_rx[3*time_vector_rx.size/4];
-
       double rx_fft_median = table_rx_fft[time_vector_rx_fft.size/2];
       double rx_fft_q1 = table_rx_fft[time_vector_rx_fft.size/4];
       double rx_fft_q3 = table_rx_fft[3*time_vector_rx_fft.size/4];
-
       double rx_demod_median = table_rx_demod[time_vector_rx_demod.size/2];
       double rx_demod_q1 = table_rx_demod[time_vector_rx_demod.size/4];
       double rx_demod_q3 = table_rx_demod[3*time_vector_rx_demod.size/4];
-
       double rx_dec_median = table_rx_dec[time_vector_rx_dec.size/2];
       double rx_dec_q1 = table_rx_dec[time_vector_rx_dec.size/4];
       double rx_dec_q3 = table_rx_dec[3*time_vector_rx_dec.size/4];
-
       double std_phy_proc_tx=0;
       double std_phy_proc_tx_ifft=0;
       double std_phy_proc_tx_mod=0;
       double std_phy_proc_tx_enc=0;
-
       double std_phy_proc_rx=0;
       double std_phy_proc_rx_fft=0;
       double std_phy_proc_rx_demod=0;
       double std_phy_proc_rx_dec=0;
-
       effective_rate = ((double)(round_trials[0]-dci_errors)/((double)round_trials[0] + round_trials[1] + round_trials[2] + round_trials[3]));
-
       printf("\n**********************SNR = %f dB (tx_lev %f, sigma2_dB %f)**************************\n",
              SNR,
              (double)tx_lev_dB+10*log10(UE->frame_parms.ofdm_symbol_size/(NB_RB*12)),
              sigma2_dB);
-
-      printf("Errors (%d(%d)/%d %d/%d %d/%d %d/%d), Pe = (%e,%e,%e,%e), dci_errors %d/%d, Pe = %e => effective rate %f  (%2.1f%%,%f, %f), normalized delay %f (%f)\n",
+      printf("Errors (%u(%u)/%u %u/%u %u/%u %u/%u), Pe = (%e,%e,%e,%e), dci_errors %u/%u, Pe = %e => effective rate %f  (%2.1f%%,%f, %f), normalized delay %f (%f)\n",
              errs[0],
              errs2[0],
              round_trials[0],
@@ -3962,11 +3804,12 @@ PMI_FEEDBACK:
         printf("|__ DLSCH sub-block interleaving time :%f us (%d trials)\n",
                ((double)eNB->dlsch_interleaving_stats.trials/eNB->dlsch_encoding_stats.trials)*(double)
                eNB->dlsch_interleaving_stats.diff/eNB->dlsch_interleaving_stats.trials/cpu_freq_GHz/1000.0,eNB->dlsch_interleaving_stats.trials);
-
         printf("\n\nUE RX function statistics (per 1ms subframe)\n\n");
         std_phy_proc_rx = sqrt((double)UE->phy_proc_rx[UE->current_thread_id[subframe]].diff_square/pow(cpu_freq_GHz,2)/pow(1000,
-                               2)/UE->phy_proc_rx[UE->current_thread_id[subframe]].trials - pow((double)UE->phy_proc_rx[UE->current_thread_id[subframe]].diff/UE->phy_proc_rx[UE->current_thread_id[subframe]].trials/cpu_freq_GHz/1000,2));
-        printf("Total PHY proc rx                                   :%f us (%d trials)\n",(double)UE->phy_proc_rx[UE->current_thread_id[subframe]].diff/UE->phy_proc_rx[UE->current_thread_id[subframe]].trials/cpu_freq_GHz/1000.0,
+                               2)/UE->phy_proc_rx[UE->current_thread_id[subframe]].trials - pow((double)
+                                   UE->phy_proc_rx[UE->current_thread_id[subframe]].diff/UE->phy_proc_rx[UE->current_thread_id[subframe]].trials/cpu_freq_GHz/1000,2));
+        printf("Total PHY proc rx                                   :%f us (%d trials)\n",
+               (double)UE->phy_proc_rx[UE->current_thread_id[subframe]].diff/UE->phy_proc_rx[UE->current_thread_id[subframe]].trials/cpu_freq_GHz/1000.0,
                UE->phy_proc_rx[UE->current_thread_id[subframe]].trials*2/3);
         printf("|__Statistcs                                            std: %fus max: %fus min: %fus median %fus q1 %fus q3 %fus n_dropped: %d packet \n", std_phy_proc_rx, t_rx_max, t_rx_min, rx_median,
                rx_q1, rx_q3, n_rx_dropped);
@@ -4001,7 +3844,8 @@ PMI_FEEDBACK:
         printf("|__ DLSCH Rate Unmatching                               :%f us (%d trials)\n",
                (double)UE->dlsch_rate_unmatching_stats.diff/UE->dlsch_rate_unmatching_stats.trials/cpu_freq_GHz/1000.0,UE->dlsch_rate_unmatching_stats.trials);
         printf("|__ DLSCH Turbo Decoding(%d bits)                       :%f us (%d trials)\n",
-               UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->Cminus ? UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->Kminus : UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->Kplus,
+               UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->Cminus ? UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->Kminus :
+               UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->Kplus,
                (double)UE->dlsch_turbo_decoding_stats.diff/UE->dlsch_turbo_decoding_stats.trials/cpu_freq_GHz/1000.0,UE->dlsch_turbo_decoding_stats.trials);
         printf("    |__ init                                            %f us (cycles/iter %f, %d trials)\n",
                (double)UE->dlsch_tc_init_stats.diff/UE->dlsch_tc_init_stats.trials/cpu_freq_GHz/1000.0,
@@ -4034,7 +3878,7 @@ PMI_FEEDBACK:
       }
 
       if ((transmission_mode != 3) && (transmission_mode != 4)) {
-        fprintf(bler_fd,"%f;%d;%d;%f;%d;%d;%d;%d;%d;%d;%d;%d;%d\n",
+        fprintf(bler_fd,"%f;%d;%d;%f;%u;%u;%u;%u;%u;%u;%u;%u;%u\n",
                 SNR,
                 mcs1,
                 eNB->dlsch[0][0]->harq_processes[0]->TBS,
@@ -4049,7 +3893,7 @@ PMI_FEEDBACK:
                 round_trials[3],
                 dci_errors);
       } else {
-        fprintf(bler_fd,"%f;%d;%d;%d;%d;%f;%d;%d;%d;%d;%d;%d;%d;%d;%d\n",
+        fprintf(bler_fd,"%f;%d;%d;%d;%d;%f;%u;%u;%u;%u;%u;%u;%u;%u;%u\n",
                 SNR,
                 mcs1,mcs2,
                 eNB->dlsch[0][0]->harq_processes[0]->TBS,
@@ -4066,7 +3910,6 @@ PMI_FEEDBACK:
                 dci_errors);
       }
 
-
       if(abstx) { //ABSTRACTION
         blerr[0] = (double)errs[0]/(round_trials[0]);
 
@@ -4083,7 +3926,7 @@ PMI_FEEDBACK:
       if ( (test_perf != 0) && (100 * effective_rate > test_perf )) {
         //fprintf(time_meas_fd,"SNR; MCS; TBS; rate; err0; trials0; err1; trials1; err2; trials2; err3; trials3; dci_err\n");
         if ((transmission_mode != 3) && (transmission_mode != 4)) {
-          fprintf(time_meas_fd,"%f;%d;%d;%f;%d;%d;%d;%d;%d;%d;%d;%d;%d;",
+          fprintf(time_meas_fd,"%f;%d;%d;%f;%u;%u;%u;%u;%u;%u;%u;%u;%u;",
                   SNR,
                   mcs1,
                   eNB->dlsch[0][0]->harq_processes[0]->TBS,
@@ -4097,9 +3940,8 @@ PMI_FEEDBACK:
                   errs[3],
                   round_trials[3],
                   dci_errors);
-
           //fprintf(time_meas_fd,"SNR; MCS; TBS; rate; DL_DECOD_ITER; err0; trials0; err1; trials1; err2; trials2; err3; trials3; PE; dci_err;PE;ND;\n");
-          fprintf(time_meas_fd,"%f;%d;%d;%f; %2.1f%%;%f;%f;%d;%d;%d;%d;%d;%d;%d;%d;%e;%e;%e;%e;%d;%d;%e;%f;%f;",
+          fprintf(time_meas_fd,"%f;%d;%d;%f; %2.1f%%;%f;%f;%u;%u;%u;%u;%u;%u;%u;%u;%e;%e;%e;%e;%u;%u;%e;%f;%f;",
                   SNR,
                   mcs1,
                   eNB->dlsch[0][0]->harq_processes[0]->TBS,
@@ -4126,7 +3968,7 @@ PMI_FEEDBACK:
                   (double)eNB->dlsch[0][0]->harq_processes[0]->TBS,
                   (1.0*(round_trials[0]-errs[0])+2.0*(round_trials[1]-errs[1])+3.0*(round_trials[2]-errs[2])+4.0*(round_trials[3]-errs[3]))/((double)round_trials[0]));
         } else {
-          fprintf(time_meas_fd,"%f;%d;%d;%d;%d;%f;%d;%d;%d;%d;%d;%d;%d;%d;%d;",
+          fprintf(time_meas_fd,"%f;%d;%d;%d;%d;%f;%u;%u;%u;%u;%u;%u;%u;%u;%u;",
                   SNR,
                   mcs1,mcs2,
                   eNB->dlsch[0][0]->harq_processes[0]->TBS,
@@ -4141,9 +3983,8 @@ PMI_FEEDBACK:
                   errs[3],
                   round_trials[3],
                   dci_errors);
-
           //fprintf(time_meas_fd,"SNR; MCS; TBS; rate; DL_DECOD_ITER; err0; trials0; err1; trials1; err2; trials2; err3; trials3; PE; dci_err;PE;ND;\n");
-          fprintf(time_meas_fd,"%f;%d;%d;%d;%d;%f;%2.1f;%f;%f;%d;%d;%d;%d;%d;%d;%d;%d;%e;%e;%e;%e;%d;%d;%e;%f;%f;",
+          fprintf(time_meas_fd,"%f;%d;%d;%d;%d;%f;%2.1f;%f;%f;%u;%u;%u;%u;%u;%u;%u;%u;%e;%e;%e;%e;%u;%u;%e;%f;%f;",
                   SNR,
                   mcs1,mcs2,
                   eNB->dlsch[0][0]->harq_processes[0]->TBS,
@@ -4201,30 +4042,20 @@ PMI_FEEDBACK:
                );
         //fprintf(time_meas_fd,"eNB_PROC_TX_STD;eNB_PROC_TX_MAX;eNB_PROC_TX_MIN;eNB_PROC_TX_MED;eNB_PROC_TX_Q1;eNB_PROC_TX_Q3;eNB_PROC_TX_DROPPED;\n");
         fprintf(time_meas_fd,"%f;%f;%f;%f;%f;%f;%d;", std_phy_proc_tx, t_tx_max, t_tx_min, tx_median, tx_q1, tx_q3, n_tx_dropped);
-
         //fprintf(time_meas_fd,"IFFT;\n");
         fprintf(time_meas_fd,"%f;%f;%f;%f;", std_phy_proc_tx_ifft, tx_ifft_median, tx_ifft_q1, tx_ifft_q3);
-
         //fprintf(time_meas_fd,"MOD;\n");
         fprintf(time_meas_fd,"%f;%f;%f;%f;", std_phy_proc_tx_mod, tx_mod_median, tx_mod_q1, tx_mod_q3);
-
         //fprintf(time_meas_fd,"ENC;\n");
         fprintf(time_meas_fd,"%f;%f;%f;%f;", std_phy_proc_tx_enc, tx_enc_median, tx_enc_q1, tx_enc_q3);
-
-
         //fprintf(time_meas_fd,"UE_PROC_RX_STD;UE_PROC_RX_MAX;UE_PROC_RX_MIN;UE_PROC_RX_MED;UE_PROC_RX_Q1;UE_PROC_RX_Q3;UE_PROC_RX_DROPPED;\n");
         fprintf(time_meas_fd,"%f;%f;%f;%f;%f;%f;%d;", std_phy_proc_rx, t_rx_max, t_rx_min, rx_median, rx_q1, rx_q3, n_rx_dropped);
-
         //fprintf(time_meas_fd,"FFT;\n");
         fprintf(time_meas_fd,"%f;%f;%f;%f;", std_phy_proc_rx_fft, rx_fft_median, rx_fft_q1, rx_fft_q3);
-
         //fprintf(time_meas_fd,"DEMOD;\n");
         fprintf(time_meas_fd,"%f;%f;%f;%f;", std_phy_proc_rx_demod,rx_demod_median, rx_demod_q1, rx_demod_q3);
-
         //fprintf(time_meas_fd,"DEC;\n");
         fprintf(time_meas_fd,"%f;%f;%f;%f\n", std_phy_proc_rx_dec, rx_dec_median, rx_dec_q1, rx_dec_q3);
-
-
         /*
         fprintf(time_meas_fd,"%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;",
         eNB->phy_proc_tx.trials,
@@ -4248,11 +4079,8 @@ PMI_FEEDBACK:
       if (((double)errs[0]/(round_trials[0]))<(10.0/n_frames))
         break;
     }// SNR
-
-
   } //ch_realization
 
-
   fclose(bler_fd);
 
   if (test_perf !=0)
@@ -4293,10 +4121,9 @@ PMI_FEEDBACK:
     free_ue_dlsch(UE->dlsch[UE->current_thread_id[subframe]][0][i]);
   }
 
-
   printf("Freeing channel I/O\n");
 
-  for (i=0; i<n_tx_phy; i++){
+  for (i=0; i<n_tx_phy; i++) {
     free(s_re[i]);
     free(s_im[i]);
   }
@@ -4306,16 +4133,12 @@ PMI_FEEDBACK:
     free(r_im[i]);
   }
 
-
   free(s_re);
   free(s_im);
   free(r_re);
   free(r_im);
-
   //  lte_sync_time_free();
-
   //  printf("[MUMIMO] mcs %d, mcsi %d, offset %d, bler %f\n",mcs,mcs_i,offset_mumimo_llr_drange_fix,((double)errs[0])/((double)round_trials[0]));
-
   return(0);
 }
 
diff --git a/openair1/SIMULATION/LTE_PHY/launch_sim.sh b/openair1/SIMULATION/LTE_PHY/launch_sim.sh
old mode 100644
new mode 100755
diff --git a/openair1/SIMULATION/LTE_PHY/mat2wv.m b/openair1/SIMULATION/LTE_PHY/mat2wv.m
old mode 100755
new mode 100644
diff --git a/openair1/SIMULATION/LTE_PHY/mbmssim.c b/openair1/SIMULATION/LTE_PHY/mbmssim.c
index 9910c97af838db34ec814a0019c3b9e036f622c6..65415e7c68b97633eff7557dfe51ffba935f70f5 100644
--- a/openair1/SIMULATION/LTE_PHY/mbmssim.c
+++ b/openair1/SIMULATION/LTE_PHY/mbmssim.c
@@ -36,7 +36,7 @@
 #include "LAYER2/MAC/vars.h"
 
 #ifdef XFORMS
-#include "PHY/TOOLS/lte_phy_scope.h"
+  #include "PHY/TOOLS/lte_phy_scope.h"
 #endif //XFORMS
 
 
@@ -52,11 +52,8 @@ double cpuf;
 DCI1E_5MHz_2A_M10PRB_TDD_t  DLSCH_alloc_pdu2_1E[2];
 #define UL_RB_ALLOC 0x1ff;
 #define CCCH_RB_ALLOC computeRIV(eNB->frame_parms.N_RB_UL,0,2)
-int main(int argc, char **argv)
-{
-
+int main(int argc, char **argv) {
   char c;
-
   int i,l,l2,aa,aarx,k;
   double sigma2, sigma2_dB=0,SNR,snr0=-2.0,snr1=0.0;
   uint8_t snr1set=0;
@@ -64,48 +61,34 @@ int main(int argc, char **argv)
   int **txdata;
   double s_re0[2*30720],s_im0[2*30720],s_re1[2*30720],s_im1[2*30720];
   double r_re0[2*30720],r_im0[2*30720],r_re1[2*30720],r_im1[2*30720];
-  double *s_re[2]={s_re0,s_re1},*s_im[2]={s_im0,s_im1},*r_re[2]={r_re0,r_re1},*r_im[2]={r_im0,r_im1};
+  double *s_re[2]= {s_re0,s_re1},*s_im[2]= {s_im0,s_im1},*r_re[2]= {r_re0,r_re1},*r_im[2]= {r_im0,r_im1};
   double iqim = 0.0;
   int subframe=1;
   char fname[40];//, vname[40];
   uint8_t transmission_mode = 1,n_tx=1,n_rx=2;
   uint16_t Nid_cell=0;
-
   FILE *fd;
-
   int eNB_id = 0;
   unsigned char mcs=0,awgn_flag=0,round;
-
   int n_frames=1;
   channel_desc_t *eNB2UE;
   uint32_t nsymb,tx_lev,tx_lev_dB;
   uint8_t extended_prefix_flag=1;
   LTE_DL_FRAME_PARMS *frame_parms;
   int hold_channel=0;
-
-
   uint16_t NB_RB=25;
-
   int tdd_config=3;
-
   SCM_t channel_model=MBSFN;
-
-
   unsigned char *input_buffer;
   unsigned short input_buffer_length;
   unsigned int ret;
-
   unsigned int trials,errs[4]= {0,0,0,0}; //,round_trials[4]={0,0,0,0};
-
   uint8_t N_RB_DL=25,osf=1;
   uint32_t perfect_ce = 0;
-
   lte_frame_type_t frame_type = FDD;
-
   uint32_t Nsoft = 1827072;
-
   /*
-#ifdef XFORMS
+  #ifdef XFORMS
   FD_lte_phy_scope_ue *form_ue;
   char title[255];
 
@@ -113,114 +96,110 @@ int main(int argc, char **argv)
   form_ue = create_lte_phy_scope_ue();
   sprintf (title, "LTE DL SCOPE UE");
   fl_show_form (form_ue->lte_phy_scope_ue, FL_PLACE_HOTSPOT, FL_FULLBORDER, title);
-#endif
+  #endif
   */
-
   cpuf = get_cpu_freq_GHz();
-
   logInit();
   number_of_cards = 1;
 
   while ((c = getopt (argc, argv, "ahA:Cp:n:s:S:t:x:y:z:N:F:R:O:dm:i:Y")) != -1) {
     switch (c) {
-    case 'a':
-      awgn_flag=1;
-      break;
-
-    case 'd':
-      frame_type = 0;
-      break;
-
-    case 'n':
-      n_frames = atoi(optarg);
-      break;
-
-    case 'm':
-      mcs=atoi(optarg);
-      break;
-
-    case 's':
-      snr0 = atof(optarg);
-      msg("Setting SNR0 to %f\n",snr0);
-      break;
-
-    case 'i':
-      input_snr_step = atof(optarg);
-      break;
-
-    case 'S':
-      snr1 = atof(optarg);
-      snr1set=1;
-      msg("Setting SNR1 to %f\n",snr1);
-      break;
-
-    case 'p': // subframe no;
-      subframe=atoi(optarg);
-      break;
-
-    case 'z':
-      n_rx=atoi(optarg);
-
-      if ((n_rx==0) || (n_rx>2)) {
-        msg("Unsupported number of rx antennas %d\n",n_rx);
-        exit(-1);
-      }
-
-      break;
-
-    case 'N':
-      Nid_cell = atoi(optarg);
-      break;
-
-    case 'R':
-      N_RB_DL = atoi(optarg);
+      case 'a':
+        awgn_flag=1;
+        break;
+
+      case 'd':
+        frame_type = 0;
+        break;
+
+      case 'n':
+        n_frames = atoi(optarg);
+        break;
+
+      case 'm':
+        mcs=atoi(optarg);
+        break;
+
+      case 's':
+        snr0 = atof(optarg);
+        msg("Setting SNR0 to %f\n",snr0);
+        break;
+
+      case 'i':
+        input_snr_step = atof(optarg);
+        break;
+
+      case 'S':
+        snr1 = atof(optarg);
+        snr1set=1;
+        msg("Setting SNR1 to %f\n",snr1);
+        break;
+
+      case 'p': // subframe no;
+        subframe=atoi(optarg);
+        break;
+
+      case 'z':
+        n_rx=atoi(optarg);
+
+        if ((n_rx==0) || (n_rx>2)) {
+          msg("Unsupported number of rx antennas %d\n",n_rx);
+          exit(-1);
+        }
 
-      if ((N_RB_DL!=6) && (N_RB_DL!=25) && (N_RB_DL!=50) && (N_RB_DL!=100))  {
-        printf("Unsupported Bandwidth %d\n",N_RB_DL);
-        exit(-1);
-      }
+        break;
 
-      break;
+      case 'N':
+        Nid_cell = atoi(optarg);
+        break;
 
-    case 'O':
-      osf = atoi(optarg);
-      break;
+      case 'R':
+        N_RB_DL = atoi(optarg);
 
-    case 'Y':
-      perfect_ce = 1;
-      break;
+        if ((N_RB_DL!=6) && (N_RB_DL!=25) && (N_RB_DL!=50) && (N_RB_DL!=100))  {
+          printf("Unsupported Bandwidth %d\n",N_RB_DL);
+          exit(-1);
+        }
 
-    default:
-    case 'h':
-      printf("%s -h(elp) -p(subframe) -N cell_id -g channel_model -n n_frames -t Delayspread -s snr0 -S snr1 -i snr increment -z RXant \n",argv[0]);
-      printf("-h This message\n");
-      printf("-a Use AWGN Channel\n");
-      printf("-p Use extended prefix mode\n");
-      printf("-d Use TDD\n");
-      printf("-n Number of frames to simulate\n");
-      printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB.  If n_frames is 1 then just SNR is simulated\n");
-      printf("-S Ending SNR, runs from SNR0 to SNR1\n");
-      printf("-t Delay spread for multipath channel\n");
-      printf("-g [A,B,C,D,E,F,G] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) models (ignores delay spread and Ricean factor)\n");
-      printf("-x Transmission mode (1,2,6 for the moment)\n");
-      printf("-y Number of TX antennas used in eNB\n");
-      printf("-z Number of RX antennas used in UE\n");
-      printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n");
-      printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n");
-      printf("-N Nid_cell\n");
-      printf("-R N_RB_DL\n");
-      printf("-O oversampling factor (1,2,4,8,16)\n");
-      printf("-A Interpolation_filname Run with Abstraction to generate Scatter plot using interpolation polynomial in file\n");
-      printf("-C Generate Calibration information for Abstraction (effective SNR adjustment to remove Pe bias w.r.t. AWGN)\n");
-      printf("-f Output filename (.txt format) for Pe/SNR results\n");
-      printf("-F Input filename (.txt format) for RX conformance testing\n");
-      exit (-1);
-      break;
+        break;
+
+      case 'O':
+        osf = atoi(optarg);
+        break;
+
+      case 'Y':
+        perfect_ce = 1;
+        break;
+
+      default:
+      case 'h':
+        printf("%s -h(elp) -p(subframe) -N cell_id -g channel_model -n n_frames -t Delayspread -s snr0 -S snr1 -i snr increment -z RXant \n",argv[0]);
+        printf("-h This message\n");
+        printf("-a Use AWGN Channel\n");
+        printf("-p Use extended prefix mode\n");
+        printf("-d Use TDD\n");
+        printf("-n Number of frames to simulate\n");
+        printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB.  If n_frames is 1 then just SNR is simulated\n");
+        printf("-S Ending SNR, runs from SNR0 to SNR1\n");
+        printf("-t Delay spread for multipath channel\n");
+        printf("-g [A,B,C,D,E,F,G] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) models (ignores delay spread and Ricean factor)\n");
+        printf("-x Transmission mode (1,2,6 for the moment)\n");
+        printf("-y Number of TX antennas used in eNB\n");
+        printf("-z Number of RX antennas used in UE\n");
+        printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n");
+        printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n");
+        printf("-N Nid_cell\n");
+        printf("-R N_RB_DL\n");
+        printf("-O oversampling factor (1,2,4,8,16)\n");
+        printf("-A Interpolation_filname Run with Abstraction to generate Scatter plot using interpolation polynomial in file\n");
+        printf("-C Generate Calibration information for Abstraction (effective SNR adjustment to remove Pe bias w.r.t. AWGN)\n");
+        printf("-f Output filename (.txt format) for Pe/SNR results\n");
+        printf("-F Input filename (.txt format) for RX conformance testing\n");
+        exit (-1);
+        break;
     }
   }
 
-
-
   if (awgn_flag == 1)
     channel_model = AWGN;
 
@@ -229,7 +208,6 @@ int main(int argc, char **argv)
   if ((subframe == 0) || (subframe == 5) ||    // TDD and FDD SFn 0,5;
       ((frame_type == FDD) && ((subframe == 4) || (subframe == 9))) || // FDD SFn 4,9;
       ((frame_type == TDD ) && ((subframe<3) || (subframe==6))))    {  // TDD SFn 1,2,6;
-
     printf("Illegal subframe %d for eMBMS transmission (frame_type %d)\n",subframe,frame_type);
     exit(-1);
   }
@@ -239,16 +217,16 @@ int main(int argc, char **argv)
 
   lte_param_init(n_tx,
                  n_tx,
-		 n_rx,
-		 transmission_mode,
-		 extended_prefix_flag,
-		 frame_type,
-		 Nid_cell,
-		 tdd_config,
-		 N_RB_DL,
-		 0,
-		 osf,
-		 perfect_ce);
+                 n_rx,
+                 transmission_mode,
+                 extended_prefix_flag,
+                 frame_type,
+                 Nid_cell,
+                 tdd_config,
+                 N_RB_DL,
+                 0,
+                 osf,
+                 perfect_ce);
 
   if (snr1set==0) {
     if (n_frames==1)
@@ -258,7 +236,6 @@ int main(int argc, char **argv)
   }
 
   printf("SNR0 %f, SNR1 %f\n",snr0,snr1);
-
   frame_parms = &eNB->frame_parms;
 
   if (awgn_flag == 0)
@@ -270,7 +247,6 @@ int main(int argc, char **argv)
     printf("Cannot open %s, check permissions\n",fname);
     exit(-1);
   }
-	
 
   if (awgn_flag==0)
     fprintf(fd,"SNR_%d_%d=[];errs_mch_%d_%d=[];mch_trials_%d_%d=[];\n",
@@ -284,23 +260,18 @@ int main(int argc, char **argv)
             mcs,N_RB_DL);
 
   fflush(fd);
-
   txdata = eNB->common_vars.txdata[0];
-
   nsymb = 12;
-
   printf("FFT Size %d, Extended Prefix %d, Samples per subframe %d, Symbols per subframe %d, AWGN %d\n",NUMBER_OF_OFDM_CARRIERS,
          frame_parms->Ncp,frame_parms->samples_per_tti,nsymb,awgn_flag);
-
   eNB2UE = new_channel_desc_scm(eNB->frame_parms.nb_antennas_tx,
                                 UE->frame_parms.nb_antennas_rx,
                                 channel_model,
-				N_RB2sampling_rate(eNB->frame_parms.N_RB_DL),
-				N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL),
+                                N_RB2sampling_rate(eNB->frame_parms.N_RB_DL),
+                                N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL),
                                 0,
                                 0,
                                 0);
-
   // Create transport channel structures for 2 transport blocks (MIMO)
   eNB->dlsch_MCH = new_eNB_dlsch(1,8,Nsoft,N_RB_DL,0,&eNB->frame_parms);
 
@@ -310,7 +281,6 @@ int main(int argc, char **argv)
   }
 
   UE->dlsch_MCH[0]  = new_ue_dlsch(1,8,Nsoft,MAX_TURBO_ITERATIONS_MBSFN,N_RB_DL,0);
-
   eNB->frame_parms.num_MBSFN_config = 1;
   eNB->frame_parms.MBSFN_config[0].radioframeAllocationPeriod = 0;
   eNB->frame_parms.MBSFN_config[0].radioframeAllocationOffset = 0;
@@ -321,7 +291,6 @@ int main(int argc, char **argv)
   UE->frame_parms.MBSFN_config[0].radioframeAllocationOffset = 0;
   UE->frame_parms.MBSFN_config[0].fourFrames_flag = 0;
   UE->frame_parms.MBSFN_config[0].mbsfn_SubframeConfig=0xff; // activate all possible subframes
-
   fill_eNB_dlsch_MCH(eNB,mcs,1,0);
   fill_UE_dlsch_MCH(UE,mcs,1,0,0);
 
@@ -333,7 +302,6 @@ int main(int argc, char **argv)
     exit(-1);
   }
 
-
   input_buffer_length = eNB->dlsch_MCH->harq_processes[0]->TBS/8;
   input_buffer = (unsigned char *)malloc(input_buffer_length+4);
   memset(input_buffer,0,input_buffer_length+4);
@@ -342,14 +310,12 @@ int main(int argc, char **argv)
     input_buffer[i]= (unsigned char)(taus()&0xff);
   }
 
-
   snr_step = input_snr_step;
 
   for (SNR=snr0; SNR<snr1; SNR+=snr_step) {
     UE->proc.proc_rxtx[0].frame_tx=0;
     eNB->proc.proc_rxtx[0].frame_tx=0;
     eNB->proc.proc_rxtx[0].subframe_tx=subframe;
-
     errs[0]=0;
     errs[1]=0;
     errs[2]=0;
@@ -365,14 +331,11 @@ int main(int argc, char **argv)
       //        printf("Trial %d\n",trials);
       fflush(stdout);
       round=0;
-
       //if (trials%100==0)
       //eNB2UE[0]->first_run = 1;
       eNB2UE->first_run = 1;
       memset(&eNB->common_vars.txdataF[0][0][0],0,FRAME_LENGTH_COMPLEX_SAMPLES_NO_PREFIX*sizeof(int32_t));
       generate_mch(eNB,&eNB->proc.proc_rxtx[0],input_buffer);
-
-
       PHY_ofdm_mod(eNB->common_vars.txdataF[0][0],        // input,
                    txdata[0],         // output
                    frame_parms->ofdm_symbol_size,
@@ -382,7 +345,7 @@ int main(int argc, char **argv)
 
       if (n_frames==1) {
         LOG_M("txsigF0.m","txsF0", &eNB->common_vars.txdataF[0][0][subframe*nsymb*eNB->frame_parms.ofdm_symbol_size],
-                     nsymb*eNB->frame_parms.ofdm_symbol_size,1,1);
+              nsymb*eNB->frame_parms.ofdm_symbol_size,1,1);
         //if (eNB->frame_parms.nb_antennas_tx>1)
         //LOG_M("txsigF1.m","txsF1", &eNB->lte_eNB_common_vars.txdataF[eNB_id][1][subframe*nsymb*eNB->frame_parms.ofdm_symbol_size],nsymb*eNB->frame_parms.ofdm_symbol_size,1,1);
       }
@@ -400,11 +363,9 @@ int main(int argc, char **argv)
       if (n_frames==1) {
         printf("tx_lev = %d (%d dB)\n",tx_lev,tx_lev_dB);
         //    LOG_M("txsig0.m","txs0", &eNB->common_vars.txdata[0][0][subframe* eNB->frame_parms.samples_per_tti],
-
         //     eNB->frame_parms.samples_per_tti,1,1);
       }
 
-
       for (i=0; i<2*frame_parms->samples_per_tti; i++) {
         for (aa=0; aa<eNB->frame_parms.nb_antennas_tx; aa++) {
           s_re[aa][i] = ((double)(((short *)eNB->common_vars.txdata[0][aa]))[(2*subframe*UE->frame_parms.samples_per_tti) + (i<<1)]);
@@ -415,7 +376,6 @@ int main(int argc, char **argv)
       //Multipath channel
       multipath_channel(eNB2UE,s_re,s_im,r_re,r_im,
                         2*frame_parms->samples_per_tti,hold_channel);
-
       //AWGN
       sigma2_dB = 10*log10((double)tx_lev) +10*log10((double)eNB->frame_parms.ofdm_symbol_size/(NB_RB*12)) - SNR;
       sigma2 = pow(10,sigma2_dB/10);
@@ -426,67 +386,70 @@ int main(int argc, char **argv)
       for (i=0; i<2*frame_parms->samples_per_tti; i++) {
         for (aa=0; aa<eNB->frame_parms.nb_antennas_rx; aa++) {
           //printf("s_re[0][%d]=> %f , r_re[0][%d]=> %f\n",i,s_re[aa][i],i,r_re[aa][i]);
-          ((short*) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti)+2*i] =
+          ((short *) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti)+2*i] =
             (short) (r_re[aa][i] + sqrt(sigma2/2)*gaussdouble(0.0,1.0));
-          ((short*) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti)+2*i+1] =
+          ((short *) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti)+2*i+1] =
             (short) (r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0));
         }
       }
 
       for (l=2; l<12; l++) {
-
         slot_fep_mbsfn(UE,
                        l,
                        subframe%10,
                        0,
                        0);
-	if (UE->perfect_ce==1) {
-	  // fill in perfect channel estimates
-	  freq_channel(eNB2UE,UE->frame_parms.N_RB_DL,12*UE->frame_parms.N_RB_DL + 1);
-	  for(k=0; k<NUMBER_OF_eNB_MAX; k++) {
-	    for(aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
-	      for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
-		for (i=0; i<frame_parms->N_RB_DL*12; i++) {
-		  ((int16_t *) UE->common_vars.common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[k][(aa<<1)+aarx])[2*i+(l*frame_parms->ofdm_symbol_size+LTE_CE_FILTER_LENGTH)*2]=(int16_t)(eNB2UE->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x*AMP);
-		  ((int16_t *) UE->common_vars.common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[k][(aa<<1)+aarx])[2*i+1+(l*frame_parms->ofdm_symbol_size+LTE_CE_FILTER_LENGTH)*2]=(int16_t)(eNB2UE->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].y*AMP);
-		}
-	      }
-	    }
-	  }
-	}
-
-	if (l==6)
-          for (l2=2;l2<7;l2++)
-	    rx_pmch(UE,
-		    0,
-		    subframe%10,
-		    l2);
-	if (l==6)
-          for (l2=2;l2<7;l2++)
-	    rx_pmch(UE,
-		    0,
-		    subframe%10,
-		    l2);
-	if (l==11)
-          for (l2=7;l2<12;l2++)
-	    rx_pmch(UE,
-		    0,
-		    subframe%10,
-		    l2);
+
+        if (UE->perfect_ce==1) {
+          // fill in perfect channel estimates
+          freq_channel(eNB2UE,UE->frame_parms.N_RB_DL,12*UE->frame_parms.N_RB_DL + 1);
+
+          for(k=0; k<NUMBER_OF_eNB_MAX; k++) {
+            for(aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
+              for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
+                for (i=0; i<frame_parms->N_RB_DL*12; i++) {
+                  ((int16_t *) UE->common_vars.common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[k][(aa<<1)+aarx])[2*i+(l*frame_parms->ofdm_symbol_size+LTE_CE_FILTER_LENGTH)*2]=(int16_t)(eNB2UE->chF[aarx+
+                      (aa*frame_parms->nb_antennas_rx)][i].x*AMP);
+                  ((int16_t *) UE->common_vars.common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[k][(aa<<1)+aarx])[2*i+1+(l*frame_parms->ofdm_symbol_size+LTE_CE_FILTER_LENGTH)*2]=(int16_t)(eNB2UE->chF[aarx+
+                      (aa*frame_parms->nb_antennas_rx)][i].y*AMP);
+                }
+              }
+            }
+          }
+        }
+
+        if (l==6)
+          for (l2=2; l2<7; l2++)
+            rx_pmch(UE,
+                    0,
+                    subframe%10,
+                    l2);
+
+        if (l==6)
+          for (l2=2; l2<7; l2++)
+            rx_pmch(UE,
+                    0,
+                    subframe%10,
+                    l2);
+
+        if (l==11)
+          for (l2=7; l2<12; l2++)
+            rx_pmch(UE,
+                    0,
+                    subframe%10,
+                    l2);
       }
 
       UE->dlsch_MCH[0]->harq_processes[0]->G = get_G(&UE->frame_parms,
-						     UE->dlsch_MCH[0]->harq_processes[0]->nb_rb,
-						     UE->dlsch_MCH[0]->harq_processes[0]->rb_alloc_even,
-						     get_Qm(UE->dlsch_MCH[0]->harq_processes[0]->mcs),
-						     1,2,
-						     UE->proc.proc_rxtx[0].frame_tx,subframe,0);
+          UE->dlsch_MCH[0]->harq_processes[0]->nb_rb,
+          UE->dlsch_MCH[0]->harq_processes[0]->rb_alloc_even,
+          get_Qm(UE->dlsch_MCH[0]->harq_processes[0]->mcs),
+          1,2,
+          UE->proc.proc_rxtx[0].frame_tx,subframe,0);
       UE->dlsch_MCH[0]->harq_processes[0]->Qm = get_Qm(UE->dlsch_MCH[0]->harq_processes[0]->mcs);
-
       dlsch_unscrambling(&UE->frame_parms,1,UE->dlsch_MCH[0],
                          UE->dlsch_MCH[0]->harq_processes[0]->G,
                          UE->pdsch_vars_MCH[0]->llr[0],0,subframe<<1);
-
       ret = dlsch_decoding(UE,
                            UE->pdsch_vars_MCH[0]->llr[0],
                            &UE->frame_parms,
@@ -497,7 +460,7 @@ int main(int argc, char **argv)
                            0,0,0);
 
       if (n_frames==1)
-        printf("MCH decoding returns %d\n",ret);
+        printf("MCH decoding returns %u\n",ret);
 
       if (ret == (1+UE->dlsch_MCH[0]->max_turbo_iterations))
         errs[0]++;
@@ -506,15 +469,15 @@ int main(int argc, char **argv)
       eNB->proc.proc_rxtx[0].frame_tx++;
     }
 
-    printf("errors %d/%d (Pe %e)\n",errs[round],trials,(double)errs[round]/trials);
+    printf("errors %u/%u (Pe %e)\n",errs[round],trials,(double)errs[round]/trials);
 
     if (awgn_flag==0)
-      fprintf(fd,"SNR_%d_%d = [SNR_%d_%d %f]; errs_mch_%d_%d =[errs_mch_%d_%d  %d]; mch_trials_%d_%d =[mch_trials_%d_%d  %d];\n",
+      fprintf(fd,"SNR_%d_%d = [SNR_%d_%d %f]; errs_mch_%d_%d =[errs_mch_%d_%d  %u]; mch_trials_%d_%d =[mch_trials_%d_%d  %u];\n",
               mcs,N_RB_DL,mcs,N_RB_DL,SNR,
               mcs,N_RB_DL,mcs,N_RB_DL,errs[0],
               mcs,N_RB_DL,mcs,N_RB_DL,trials);
     else
-      fprintf(fd,"SNR_awgn_%d = [SNR_awgn_%d %f]; errs_mch_awgn_%d =[errs_mch_awgn_%d  %d]; mch_trials_awgn_%d =[mch_trials_awgn_%d %d];\n",
+      fprintf(fd,"SNR_awgn_%d = [SNR_awgn_%d %f]; errs_mch_awgn_%d =[errs_mch_awgn_%d  %u]; mch_trials_awgn_%d =[mch_trials_awgn_%d %u];\n",
               N_RB_DL,N_RB_DL,SNR,
               N_RB_DL,N_RB_DL,errs[0],
               N_RB_DL,N_RB_DL,trials);
@@ -525,7 +488,6 @@ int main(int argc, char **argv)
       break;
   }
 
-
   if (n_frames==1) {
     printf("Dumping PMCH files ( G %d)\n",UE->dlsch_MCH[0]->harq_processes[0]->G);
     dump_mch(UE,0,
@@ -536,9 +498,7 @@ int main(int argc, char **argv)
   printf("Freeing dlsch structures\n");
   free_eNB_dlsch(eNB->dlsch_MCH);
   free_ue_dlsch(UE->dlsch_MCH[0]);
-
   fclose(fd);
-
   return(0);
 }
 
diff --git a/openair1/SIMULATION/LTE_PHY/pbchsim.c b/openair1/SIMULATION/LTE_PHY/pbchsim.c
index f44ed7b3a21665ec1bd40ba2b3e7fa11d30fbfef..00ad03c52dc8f0ffb038fe2b98328087bd6787e2 100644
--- a/openair1/SIMULATION/LTE_PHY/pbchsim.c
+++ b/openair1/SIMULATION/LTE_PHY/pbchsim.c
@@ -37,7 +37,7 @@
 #include "LAYER2/MAC/vars.h"
 
 #ifdef XFORMS
-#include "PHY/TOOLS/lte_phy_scope.h"
+  #include "PHY/TOOLS/lte_phy_scope.h"
 #endif
 
 #include "OCG_vars.h"
@@ -58,11 +58,8 @@ int32_t dummy2[2048*14];
 int32_t dummy3[2048*14];
 
 
-int main(int argc, char **argv)
-{
-
+int main(int argc, char **argv) {
   char c;
-
   int i,l,aa;
   double sigma2, sigma2_dB=0,SNR,snr0=-2.0,snr1;
   uint8_t snr1set=0;
@@ -81,127 +78,119 @@ int main(int argc, char **argv)
   int trial, n_trials, ntrials=1, n_errors,n_errors2,n_alamouti;
   uint8_t transmission_mode = 1,n_tx=1,n_rx=1;
   uint16_t Nid_cell=0;
-
   int n_frames=1;
   channel_desc_t *eNB2UE,*eNB2UE1 = NULL,*eNB2UE2 = NULL;
   uint32_t nsymb,tx_lev,tx_lev1 = 0,tx_lev2 = 0;
   uint8_t extended_prefix_flag=0;
   int8_t interf1=-21,interf2=-21;
   LTE_DL_FRAME_PARMS *frame_parms;
-
   FILE *input_fd=NULL,*pbch_file_fd=NULL;
   char input_val_str[50],input_val_str2[50];
   //  double input_val1,input_val2;
   //  uint16_t amask=0;
   uint8_t frame_mod4,num_pdcch_symbols = 0;
   uint16_t NB_RB=25;
-
   SCM_t channel_model=AWGN;//Rayleigh1_anticorr;
-
   //DCI_ALLOC_t dci_alloc[8];
   uint8_t abstraction_flag=0;//,calibration_flag=0;
   double pbch_sinr;
   int pbch_tx_ant;
   uint8_t N_RB_DL=25,osf=1;
-
   unsigned char frame_type = 0;
   unsigned char pbch_phase = 0;
-
 #ifdef XFORMS
   FD_lte_phy_scope_ue *form_ue;
   char title[255];
 #endif
-
   cpuf = get_cpu_freq_GHz();
-
   logInit();
   number_of_cards = 1;
 
   while ((c = getopt (argc, argv, "f:hA:pf:g:i:j:n:s:S:t:x:y:z:N:F:GR:O:dP:")) != -1) {
     switch (c) {
-    case 'f':
-      write_output_file=1;
-      output_fd = fopen(optarg,"w");
+      case 'f':
+        write_output_file=1;
+        output_fd = fopen(optarg,"w");
 
-      if (output_fd==NULL) {
-        printf("Error opening %s\n",optarg);
-        exit(-1);
-      }
-
-      break;
-
-    case 'd':
-      frame_type = 1;
-      break;
+        if (output_fd==NULL) {
+          printf("Error opening %s\n",optarg);
+          exit(-1);
+        }
 
-    case 'g':
-      switch((char)*optarg) {
-      case 'A':
-        channel_model=SCM_A;
         break;
 
-      case 'B':
-        channel_model=SCM_B;
+      case 'd':
+        frame_type = 1;
         break;
 
-      case 'C':
-        channel_model=SCM_C;
-        break;
+      case 'g':
+        switch((char)*optarg) {
+          case 'A':
+            channel_model=SCM_A;
+            break;
 
-      case 'D':
-        channel_model=SCM_D;
-        break;
+          case 'B':
+            channel_model=SCM_B;
+            break;
 
-      case 'E':
-        channel_model=EPA;
-        break;
+          case 'C':
+            channel_model=SCM_C;
+            break;
 
-      case 'F':
-        channel_model=EVA;
-        break;
+          case 'D':
+            channel_model=SCM_D;
+            break;
 
-      case 'G':
-        channel_model=ETU;
-        break;
+          case 'E':
+            channel_model=EPA;
+            break;
 
-      default:
-        msg("Unsupported channel model!\n");
-        exit(-1);
-      }
+          case 'F':
+            channel_model=EVA;
+            break;
 
-      break;
+          case 'G':
+            channel_model=ETU;
+            break;
 
-    case 'i':
-      interf1=atoi(optarg);
-      break;
+          default:
+            msg("Unsupported channel model!\n");
+            exit(-1);
+        }
 
-    case 'j':
-      interf2=atoi(optarg);
-      break;
+        break;
 
-    case 'n':
-      n_frames = atoi(optarg);
-      break;
+      case 'i':
+        interf1=atoi(optarg);
+        break;
 
-    case 's':
-      snr0 = atof(optarg);
-      msg("Setting SNR0 to %f\n",snr0);
-      break;
+      case 'j':
+        interf2=atoi(optarg);
+        break;
 
-    case 'S':
-      snr1 = atof(optarg);
-      snr1set=1;
-      msg("Setting SNR1 to %f\n",snr1);
-      break;
+      case 'n':
+        n_frames = atoi(optarg);
+        break;
+
+      case 's':
+        snr0 = atof(optarg);
+        msg("Setting SNR0 to %f\n",snr0);
+        break;
+
+      case 'S':
+        snr1 = atof(optarg);
+        snr1set=1;
+        msg("Setting SNR1 to %f\n",snr1);
+        break;
 
       /*
       case 't':
       Td= atof(optarg);
       break;
       */
-    case 'p':
-      extended_prefix_flag=1;
-      break;
+      case 'p':
+        extended_prefix_flag=1;
+        break;
 
       /*
       case 'r':
@@ -212,111 +201,111 @@ int main(int argc, char **argv)
       }
       break;
       */
-    case 'x':
-      transmission_mode=atoi(optarg);
-
-      if ((transmission_mode!=1) &&
-          (transmission_mode!=2) &&
-          (transmission_mode!=6)) {
-        msg("Unsupported transmission mode %d\n",transmission_mode);
-        exit(-1);
-      }
+      case 'x':
+        transmission_mode=atoi(optarg);
+
+        if ((transmission_mode!=1) &&
+            (transmission_mode!=2) &&
+            (transmission_mode!=6)) {
+          msg("Unsupported transmission mode %d\n",transmission_mode);
+          exit(-1);
+        }
 
-      break;
+        break;
 
-    case 'y':
-      n_tx=atoi(optarg);
+      case 'y':
+        n_tx=atoi(optarg);
 
-      if ((n_tx==0) || (n_tx>2)) {
-        msg("Unsupported number of tx antennas %d\n",n_tx);
-        exit(-1);
-      }
+        if ((n_tx==0) || (n_tx>2)) {
+          msg("Unsupported number of tx antennas %d\n",n_tx);
+          exit(-1);
+        }
 
-      break;
+        break;
 
-    case 'z':
-      n_rx=atoi(optarg);
+      case 'z':
+        n_rx=atoi(optarg);
 
-      if ((n_rx==0) || (n_rx>2)) {
-        msg("Unsupported number of rx antennas %d\n",n_rx);
-        exit(-1);
-      }
-
-      break;
+        if ((n_rx==0) || (n_rx>2)) {
+          msg("Unsupported number of rx antennas %d\n",n_rx);
+          exit(-1);
+        }
 
-    case 'A':
-      abstraction_flag=1;
-      ntrials=10000;
-      msg("Running Abstraction test\n");
-      pbch_file_fd=fopen(optarg,"r");
+        break;
 
-      if (pbch_file_fd==NULL) {
-        printf("Problem with filename %s\n",optarg);
-        exit(-1);
-      }
+      case 'A':
+        abstraction_flag=1;
+        ntrials=10000;
+        msg("Running Abstraction test\n");
+        pbch_file_fd=fopen(optarg,"r");
+
+        if (pbch_file_fd==NULL) {
+          printf("Problem with filename %s\n",optarg);
+          exit(-1);
+        }
 
-      break;
+        break;
 
       //  case 'C':
       //    calibration_flag=1;
       //    msg("Running Abstraction calibration for Bias removal\n");
       //    break;
-    case 'N':
-      Nid_cell = atoi(optarg);
-      break;
+      case 'N':
+        Nid_cell = atoi(optarg);
+        break;
 
-    case 'R':
-      N_RB_DL = atoi(optarg);
-      break;
+      case 'R':
+        N_RB_DL = atoi(optarg);
+        break;
 
-    case 'O':
-      osf = atoi(optarg);
-      break;
+      case 'O':
+        osf = atoi(optarg);
+        break;
 
-    case 'F':
-      input_fd = fopen(optarg,"r");
+      case 'F':
+        input_fd = fopen(optarg,"r");
 
-      if (input_fd==NULL) {
-        printf("Problem with filename %s\n",optarg);
-        exit(-1);
-      }
+        if (input_fd==NULL) {
+          printf("Problem with filename %s\n",optarg);
+          exit(-1);
+        }
 
-      break;
+        break;
 
-    case 'P':
-      pbch_phase = atoi(optarg);
+      case 'P':
+        pbch_phase = atoi(optarg);
 
-      if (pbch_phase>3)
-        printf("Illegal PBCH phase (0-3) got %d\n",pbch_phase);
+        if (pbch_phase>3)
+          printf("Illegal PBCH phase (0-3) got %d\n",pbch_phase);
 
-      break;
+        break;
 
-    default:
-    case 'h':
-      printf("%s -h(elp) -p(extended_prefix) -N cell_id -f output_filename -F input_filename -g channel_model -n n_frames -t Delayspread -s snr0 -S snr1 -x transmission_mode -y TXant -z RXant -i Intefrence0 -j Interference1 -A interpolation_file -C(alibration offset dB) -N CellId\n",
-             argv[0]);
-      printf("-h This message\n");
-      printf("-p Use extended prefix mode\n");
-      printf("-d Use TDD\n");
-      printf("-n Number of frames to simulate\n");
-      printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB.  If n_frames is 1 then just SNR is simulated\n");
-      printf("-S Ending SNR, runs from SNR0 to SNR1\n");
-      printf("-t Delay spread for multipath channel\n");
-      printf("-g [A,B,C,D,E,F,G] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) models (ignores delay spread and Ricean factor)\n");
-      printf("-x Transmission mode (1,2,6 for the moment)\n");
-      printf("-y Number of TX antennas used in eNB\n");
-      printf("-z Number of RX antennas used in UE\n");
-      printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n");
-      printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n");
-      printf("-N Nid_cell\n");
-      printf("-R N_RB_DL\n");
-      printf("-O oversampling factor (1,2,4,8,16)\n");
-      printf("-A Interpolation_filname Run with Abstraction to generate Scatter plot using interpolation polynomial in file\n");
-      //    printf("-C Generate Calibration information for Abstraction (effective SNR adjustment to remove Pe bias w.r.t. AWGN)\n");
-      printf("-f Output filename (.txt format) for Pe/SNR results\n");
-      printf("-F Input filename (.txt format) for RX conformance testing\n");
-      exit (-1);
-      break;
+      default:
+      case 'h':
+        printf("%s -h(elp) -p(extended_prefix) -N cell_id -f output_filename -F input_filename -g channel_model -n n_frames -t Delayspread -s snr0 -S snr1 -x transmission_mode -y TXant -z RXant -i Intefrence0 -j Interference1 -A interpolation_file -C(alibration offset dB) -N CellId\n",
+               argv[0]);
+        printf("-h This message\n");
+        printf("-p Use extended prefix mode\n");
+        printf("-d Use TDD\n");
+        printf("-n Number of frames to simulate\n");
+        printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB.  If n_frames is 1 then just SNR is simulated\n");
+        printf("-S Ending SNR, runs from SNR0 to SNR1\n");
+        printf("-t Delay spread for multipath channel\n");
+        printf("-g [A,B,C,D,E,F,G] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) models (ignores delay spread and Ricean factor)\n");
+        printf("-x Transmission mode (1,2,6 for the moment)\n");
+        printf("-y Number of TX antennas used in eNB\n");
+        printf("-z Number of RX antennas used in UE\n");
+        printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n");
+        printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n");
+        printf("-N Nid_cell\n");
+        printf("-R N_RB_DL\n");
+        printf("-O oversampling factor (1,2,4,8,16)\n");
+        printf("-A Interpolation_filname Run with Abstraction to generate Scatter plot using interpolation polynomial in file\n");
+        //    printf("-C Generate Calibration information for Abstraction (effective SNR adjustment to remove Pe bias w.r.t. AWGN)\n");
+        printf("-f Output filename (.txt format) for Pe/SNR results\n");
+        printf("-F Input filename (.txt format) for RX conformance testing\n");
+        exit (-1);
+        break;
     }
   }
 
@@ -324,7 +313,6 @@ int main(int argc, char **argv)
     n_tx=2;
 
   lte_param_init(n_tx, n_tx,n_rx,transmission_mode,extended_prefix_flag,frame_type,Nid_cell,3,N_RB_DL,0,osf,0);
-
   eNB1 = malloc(sizeof(PHY_VARS_eNB));
   eNB2 = malloc(sizeof(PHY_VARS_eNB));
   UE->measurements.n_adj_cells=2;
@@ -334,19 +322,16 @@ int main(int argc, char **argv)
   for (i=0; i<3; i++)
     lte_gold(&eNB->frame_parms,UE->lte_gold_table[i],Nid_cell+i);
 
-  memcpy((void*)&eNB1->frame_parms,(void*)&eNB->frame_parms,sizeof(LTE_DL_FRAME_PARMS));
+  memcpy((void *)&eNB1->frame_parms,(void *)&eNB->frame_parms,sizeof(LTE_DL_FRAME_PARMS));
   eNB1->frame_parms.Nid_cell=Nid_cell+1;
   eNB1->frame_parms.nushift=(Nid_cell+1)%6;
   eNB1->Mod_id=1;
-
-  memcpy((void*)&eNB2->frame_parms,(void*)&eNB->frame_parms,sizeof(LTE_DL_FRAME_PARMS));
+  memcpy((void *)&eNB2->frame_parms,(void *)&eNB->frame_parms,sizeof(LTE_DL_FRAME_PARMS));
   eNB2->frame_parms.Nid_cell=Nid_cell+2;
   eNB2->frame_parms.nushift=(Nid_cell+2)%6;
   eNB2->Mod_id=2;
-
   phy_init_lte_eNB(eNB1,0,0);
   phy_init_lte_eNB(eNB2,0,0);
-
 #ifdef XFORMS
   fl_initialize (&argc, argv, NULL, 0, 0);
   form_ue = create_lte_phy_scope_ue();
@@ -362,38 +347,27 @@ int main(int argc, char **argv)
   }
 
   printf("SNR0 %f, SNR1 %f\n",snr0,snr1);
-
   frame_parms = &eNB->frame_parms;
-
-
-
   txdata = eNB->common_vars.txdata[0];
   txdata1 = eNB1->common_vars.txdata[0];
   txdata2 = eNB2->common_vars.txdata[0];
-
-
-  s_re = malloc(2*sizeof(double*));
-  s_im = malloc(2*sizeof(double*));
-  s_re1 = malloc(2*sizeof(double*));
-  s_im1 = malloc(2*sizeof(double*));
-  s_re2 = malloc(2*sizeof(double*));
-  s_im2 = malloc(2*sizeof(double*));
-  r_re = malloc(2*sizeof(double*));
-  r_im = malloc(2*sizeof(double*));
-  r_re1 = malloc(2*sizeof(double*));
-  r_im1 = malloc(2*sizeof(double*));
-  r_re2 = malloc(2*sizeof(double*));
-  r_im2 = malloc(2*sizeof(double*));
-
+  s_re = malloc(2*sizeof(double *));
+  s_im = malloc(2*sizeof(double *));
+  s_re1 = malloc(2*sizeof(double *));
+  s_im1 = malloc(2*sizeof(double *));
+  s_re2 = malloc(2*sizeof(double *));
+  s_im2 = malloc(2*sizeof(double *));
+  r_re = malloc(2*sizeof(double *));
+  r_im = malloc(2*sizeof(double *));
+  r_re1 = malloc(2*sizeof(double *));
+  r_im1 = malloc(2*sizeof(double *));
+  r_re2 = malloc(2*sizeof(double *));
+  r_im2 = malloc(2*sizeof(double *));
   nsymb = (frame_parms->Ncp == 0) ? 14 : 12;
-
   printf("FFT Size %d, Extended Prefix %d, Samples per subframe %d, Symbols per subframe %d, interf (%d,%d)\n",NUMBER_OF_OFDM_CARRIERS,
          frame_parms->Ncp,frame_parms->samples_per_tti,nsymb,interf1,interf2);
-
   printf("eNB1->common_vars.txdataF[0][0] = %p\n",
          eNB1->common_vars.txdataF[0][0]);
-
-
   DLSCH_alloc_pdu2.rah              = 0;
   DLSCH_alloc_pdu2.rballoc          = DLSCH_RB_ALLOC;
   DLSCH_alloc_pdu2.TPC              = 0;
@@ -405,12 +379,11 @@ int main(int argc, char **argv)
   DLSCH_alloc_pdu2.rv1              = 0;
   // Forget second codeword
   DLSCH_alloc_pdu2.tpmi             = (transmission_mode==6 ? 5 : 0) ;  // precoding
-
   eNB2UE = new_channel_desc_scm(eNB->frame_parms.nb_antennas_tx,
                                 UE->frame_parms.nb_antennas_rx,
                                 channel_model,
- 				N_RB2sampling_rate(eNB->frame_parms.N_RB_DL),
-				N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL),
+                                N_RB2sampling_rate(eNB->frame_parms.N_RB_DL),
+                                N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL),
                                 0,
                                 0,
                                 0);
@@ -419,8 +392,8 @@ int main(int argc, char **argv)
     eNB2UE1 = new_channel_desc_scm(eNB->frame_parms.nb_antennas_tx,
                                    UE->frame_parms.nb_antennas_rx,
                                    channel_model,
-				   N_RB2sampling_rate(eNB->frame_parms.N_RB_DL),
-				   N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL),
+                                   N_RB2sampling_rate(eNB->frame_parms.N_RB_DL),
+                                   N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL),
                                    0,
                                    4,
                                    0);
@@ -429,20 +402,18 @@ int main(int argc, char **argv)
     eNB2UE2 = new_channel_desc_scm(eNB->frame_parms.nb_antennas_tx,
                                    UE->frame_parms.nb_antennas_rx,
                                    channel_model,
-				   N_RB2sampling_rate(eNB->frame_parms.N_RB_DL),
-				   N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL),
+                                   N_RB2sampling_rate(eNB->frame_parms.N_RB_DL),
+                                   N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL),
                                    0,
                                    8,
                                    0);
 
-
   if (eNB2UE==NULL) {
     msg("Problem generating channel model. Exiting.\n");
     exit(-1);
   }
 
   for (i=0; i<2; i++) {
-
     s_re[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
     bzero(s_re[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
     s_im[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
@@ -455,7 +426,6 @@ int main(int argc, char **argv)
     bzero(s_re2[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
     s_im2[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
     bzero(s_im2[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
-
     r_re[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
     bzero(r_re[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
     r_im[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
@@ -487,7 +457,6 @@ int main(int argc, char **argv)
   }
 
   if (input_fd==NULL) {
-
     //    for (i=0;i<6;i++)
     //      pbch_pdu[i] = i;
     pbch_pdu[0]=100;
@@ -515,7 +484,6 @@ int main(int argc, char **argv)
                    &eNB->frame_parms,
                    (eNB->frame_parms.Ncp==0) ? 5 : 4,
                    10);
-
     } else {
       generate_sss(eNB->common_vars.txdataF[0],
                    AMP,
@@ -537,8 +505,6 @@ int main(int argc, char **argv)
                    &eNB->frame_parms,
                    2,
                    12);
-
-
     }
 
     /*
@@ -552,16 +518,12 @@ int main(int argc, char **argv)
     dci_alloc[1].L          = 3;
     dci_alloc[1].rnti       = 0x1234;
     */
-
     printf("Generating PBCH for mode1_flag = %d\n", eNB->frame_parms.mode1_flag);
-
-
     generate_pilots(eNB,
                     eNB->common_vars.txdataF[0],
                     AMP,
                     LTE_NUMBER_OF_SUBFRAMES_PER_FRAME);
 
-
     /*
     num_pdcch_symbols = generate_dci_top(1,
            dci_alloc,
@@ -572,7 +534,6 @@ int main(int argc, char **argv)
            0);
     */
 
-
     if (num_pdcch_symbols<3) {
       printf("Less than 3 pdcch symbols\n");
       //  exit(-1);
@@ -584,7 +545,7 @@ int main(int argc, char **argv)
       dummybuf[2] = dummy2;
       dummybuf[3] = dummy3;
       generate_pbch(&eNB->pbch,
-                    (int32_t**)dummybuf,
+                    (int32_t **)dummybuf,
                     AMP,
                     &eNB->frame_parms,
                     pbch_pdu,
@@ -618,15 +579,12 @@ int main(int argc, char **argv)
                       eNB1->common_vars.txdataF[0],
                       AMP,
                       LTE_NUMBER_OF_SUBFRAMES_PER_FRAME);
-
-
       generate_pbch(&eNB1->pbch,
                     eNB1->common_vars.txdataF[0],
                     AMP,
                     &eNB1->frame_parms,
                     pbch_pdu,
                     0);
-
     }
 
     if (interf2>-20) {
@@ -638,27 +596,19 @@ int main(int argc, char **argv)
        0);
 
       */
-
-
-
       generate_pilots(eNB2,
                       eNB2->common_vars.txdataF[0],
                       AMP,
                       LTE_NUMBER_OF_SUBFRAMES_PER_FRAME);
-
-
       generate_pbch(&eNB2->pbch,
                     eNB2->common_vars.txdataF[0],
                     AMP,
                     &eNB2->frame_parms,
                     pbch_pdu,
                     0);
-
     }
 
-
     //  LOG_M("pilotsF.m","rsF",txdataF[0],frame_parms->ofdm_symbol_size,1,1);
-
     LOG_M("txsigF0.m","txsF0", eNB->common_vars.txdataF[0][0],FRAME_LENGTH_COMPLEX_SAMPLES_NO_PREFIX,1,1);
 
     if (eNB->frame_parms.nb_antennas_tx>1)
@@ -668,9 +618,6 @@ int main(int argc, char **argv)
     tx_lev1 = 0;
     tx_lev2 = 0;
 
-
-
-
     for (aa=0; aa<eNB->frame_parms.nb_antennas_tx; aa++) {
       if (frame_parms->Ncp == 1)
         PHY_ofdm_mod(eNB->common_vars.txdataF[0][aa],        // input,
@@ -743,7 +690,6 @@ int main(int argc, char **argv)
     }
 
     //    tx_lev_dB = (unsigned int) dB_fixed(tx_lev);
-
     LOG_M("txsig0.m","txs0", txdata[0],FRAME_LENGTH_COMPLEX_SAMPLES,1,1);
 
     if (frame_parms->nb_antennas_tx>1)
@@ -762,17 +708,17 @@ int main(int argc, char **argv)
     i=0;
 
     while (!feof(input_fd)) {
-      if (fscanf(input_fd,"%s %s",input_val_str,input_val_str2) != 2) { //&input_val1,&input_val2);
+      if (fscanf(input_fd,"%49s %49s",input_val_str,input_val_str2) != 2) { //&input_val1,&input_val2);
         printf("%s:%d:%s: error with fscanf, exiting\n", __FILE__, __LINE__, __FUNCTION__);
         exit(1);
       }
 
       if ((i%4)==0) {
-        ((short*)txdata[0])[i/2] = (short)((1<<15)*strtod(input_val_str,NULL));
-        ((short*)txdata[0])[(i/2)+1] = (short)((1<<15)*strtod(input_val_str2,NULL));
+        ((short *)txdata[0])[i/2] = (short)((1<<15)*strtod(input_val_str,NULL));
+        ((short *)txdata[0])[(i/2)+1] = (short)((1<<15)*strtod(input_val_str2,NULL));
 
         if ((i/4)<100)
-          printf("sample %d => %e + j%e (%d +j%d)\n",i/4,strtod(input_val_str,NULL),strtod(input_val_str2,NULL),((short*)txdata[0])[i/4],((short*)txdata[0])[(i/4)+1]);//1,input_val2,);
+          printf("sample %d => %e + j%e (%d +j%d)\n",i/4,strtod(input_val_str,NULL),strtod(input_val_str2,NULL),((short *)txdata[0])[i/4],((short *)txdata[0])[(i/4)+1]); //1,input_val2,);
       }
 
       i++;
@@ -789,7 +735,6 @@ int main(int argc, char **argv)
     //    tx_lev_dB = (unsigned int) dB_fixed(tx_lev);
   }
 
-
   // multipath channel
 
   for (i=0; i<2*nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES; i++) {
@@ -809,10 +754,7 @@ int main(int argc, char **argv)
     }
   }
 
-
   for (SNR=snr0; SNR<snr1; SNR+=.2) {
-
-
     n_errors = 0;
     n_errors2 = 0;
     n_alamouti = 0;
@@ -824,8 +766,6 @@ int main(int argc, char **argv)
         printf("*********************** trial %d ***************************\n",trial);
 
       while (pbch_sinr>-2.0) {
-
-
         multipath_channel(eNB2UE,s_re,s_im,r_re,r_im,
                           2*nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES,0);
 
@@ -882,8 +822,8 @@ int main(int argc, char **argv)
               r_im[aa][i] += (pow(10.0,.05*interf1)*r_im1[aa][i] + pow(10.0,.05*interf2)*r_im2[aa][i]);
             }
 
-            ((short*) UE->common_vars.rxdata[aa])[2*i] = (short) (.167*(r_re[aa][i] +sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
-            ((short*) UE->common_vars.rxdata[aa])[2*i+1] = (short) (.167*(r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
+            ((short *) UE->common_vars.rxdata[aa])[2*i] = (short) (.167*(r_re[aa][i] +sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
+            ((short *) UE->common_vars.rxdata[aa])[2*i+1] = (short) (.167*(r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
           }
         }
 
@@ -892,7 +832,6 @@ int main(int argc, char **argv)
                  10*log10(signal_energy(&UE->common_vars.rxdata[0][frame_parms->samples_per_tti/2],4*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES)));
         }
 
-
         /*
         // optional: read rx_frame from file
         if ((rx_frame_file = fopen("rx_frame.dat","r")) == NULL)
@@ -911,19 +850,15 @@ int main(int argc, char **argv)
         fclose(rx_frame_file);
         */
 
-
         for (l=0; l<eNB->frame_parms.symbols_per_tti; l++) {
-
           //    subframe_offset = (l/eNB->frame_parms.symbols_per_tti)*eNB->frame_parms.samples_per_tti;
           //      printf("subframe_offset = %d\n",subframe_offset);
-
           slot_fep(UE,
                    l%(eNB->frame_parms.symbols_per_tti/2),
                    l/(eNB->frame_parms.symbols_per_tti/2),
                    0,
                    0,
-		   0);
-
+                   0);
 
           if (l==0) {
             lte_ue_measurements(UE,
@@ -961,16 +896,14 @@ int main(int argc, char **argv)
             //sprintf(fname,"dl_ch00_%d.m",l);
             //sprintf(vname,"dl_ch00_%d",l);
             //LOG_M(fname,vname,&(common_vars->dl_ch_estimates[0][frame_parms->ofdm_symbol_size*(l%6)]),frame_parms->ofdm_symbol_size,1,1);
-
             lte_est_freq_offset(UE->common_vars.common_vars_rx_data_per_thread[/*subframe*/0&0x1].dl_ch_estimates[0],
                                 &UE->frame_parms,
                                 l,
                                 &freq_offset,
-				1);
+                                1);
           }
 
           if (l==((eNB->frame_parms.Ncp==0)?10:9)) {
-
             for (frame_mod4=0; frame_mod4<4; frame_mod4++) {
               pbch_tx_ant = rx_pbch(&UE->common_vars,
                                     UE->pbch_vars[0],
@@ -1003,7 +936,6 @@ int main(int argc, char **argv)
               }
             }
 
-
             if ((pbch_tx_ant>0) && (pbch_tx_ant<4)) {
               if (n_frames==1)
                 msg("pbch decoded sucessfully mode1_flag %d, frame_mod4 %d, tx_ant %d!\n",
@@ -1023,7 +955,6 @@ int main(int argc, char **argv)
                      UE,
                      0,0,1);
 #endif
-
       } //noise trials
 
       if (abstraction_flag==1) {
@@ -1049,7 +980,6 @@ int main(int argc, char **argv)
   } // NSR
 
   if (n_frames==1) {
-
     LOG_M("H00.m","h00",&(UE->common_vars.common_vars_rx_data_per_thread[/*subframe*/0&0x1].dl_ch_estimates[0][0][0]),((frame_parms->Ncp==0)?7:6)*(eNB->frame_parms.ofdm_symbol_size),1,1);
 
     if (n_tx==2)
@@ -1062,7 +992,6 @@ int main(int argc, char **argv)
     LOG_M("PBCH_rxF_llr.m","pbch_llr",UE->pbch_vars[0]->llr,(frame_parms->Ncp==0) ? 1920 : 1728,1,4);
   }
 
-
   for (i=0; i<2; i++) {
     free(s_re[i]);
     free(s_im[i]);
@@ -1074,15 +1003,15 @@ int main(int argc, char **argv)
   free(s_im);
   free(r_re);
   free(r_im);
-
-
   lte_sync_time_free();
 
   if (write_output_file)
     fclose(output_fd);
 
-  return(n_errors);
+  if (input_fd != NULL)
+    fclose(input_fd);
 
+  return(n_errors);
 }
 
 
diff --git a/openair1/SIMULATION/LTE_PHY/pbsPhyProcSim.sh b/openair1/SIMULATION/LTE_PHY/pbsPhyProcSim.sh
old mode 100644
new mode 100755
diff --git a/openair1/SIMULATION/LTE_PHY/pdcchsim.c b/openair1/SIMULATION/LTE_PHY/pdcchsim.c
index ac442ae5e97f6c21a56308ca37a0a0e4503cb03e..004eb24243bff7b6ab4272568e2281737f4e3364 100644
--- a/openair1/SIMULATION/LTE_PHY/pdcchsim.c
+++ b/openair1/SIMULATION/LTE_PHY/pdcchsim.c
@@ -34,7 +34,7 @@
 #include "OCG_vars.h"
 
 #ifdef XFORMS
-#include "PHY/TOOLS/lte_phy_scope.h"
+  #include "PHY/TOOLS/lte_phy_scope.h"
 #endif
 
 #include "unitary_defs.h"
@@ -51,303 +51,284 @@ double cpuf;
 
 DCI_PDU DCI_pdu;
 
-DCI_PDU *get_dci(LTE_DL_FRAME_PARMS *lte_frame_parms,uint8_t log2L, uint8_t log2Lcommon, DCI_format_t format_selector[MAX_NUM_DCI], uint8_t num_dci, uint32_t rnti)
-{
+DCI_PDU *get_dci(LTE_DL_FRAME_PARMS *lte_frame_parms,uint8_t log2L, uint8_t log2Lcommon, DCI_format_t format_selector[MAX_NUM_DCI], uint8_t num_dci, uint32_t rnti) {
   uint32_t BCCH_alloc_pdu[2];
   uint32_t DLSCH_alloc_pdu[2];
   uint32_t UL_alloc_pdu[2];
-
   int ind;
   int dci_length_bytes=0,dci_length=0;
   int BCCH_pdu_size_bits=0, BCCH_pdu_size_bytes=0;
   int UL_pdu_size_bits=0, UL_pdu_size_bytes=0;
   int mcs = 3;
-
   DCI_pdu.Num_dci = 0;
 
   if (lte_frame_parms->frame_type == TDD) {
     switch (lte_frame_parms->N_RB_DL) {
-    case 6:
-      dci_length = sizeof_DCI1_1_5MHz_TDD_t;
-      dci_length_bytes = sizeof(DCI1_1_5MHz_TDD_t);
-      ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rah               = 0;
-      ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rballoc           = DLSCH_RB_ALLOC;
-      ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->mcs               = mcs;
-      ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->harq_pid          = 0;
-      ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->ndi               = 1;
-      ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rv                = 0;
-      ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->TPC               = 0;
-      ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->dai               = 0;
-
-      ((DCI1A_1_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->type           = 1;
-      ((DCI1A_1_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->vrb_type       = 0;
-      ((DCI1A_1_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->rballoc     = computeRIV(lte_frame_parms->N_RB_DL, 0, 4);
-      ((DCI1A_1_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->ndi            = 1;
-      ((DCI1A_1_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->rv             = 0;
-      ((DCI1A_1_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->mcs            = 2;
-      ((DCI1A_1_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->harq_pid       = 0;
-      ((DCI1A_1_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->TPC            = 1;
-      BCCH_pdu_size_bits  = sizeof_DCI1A_1_5MHz_TDD_1_6_t;
-      BCCH_pdu_size_bytes = sizeof(DCI1A_1_5MHz_TDD_1_6_t);
-
-      ((DCI0_1_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->type              = 0;
-      ((DCI0_1_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->hopping           = 0;
-      ((DCI0_1_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->rballoc        = DLSCH_RB_ALLOC;
-      ((DCI0_1_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->mcs               = mcs;
-      ((DCI0_1_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->ndi               = 1;
-      ((DCI0_1_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->TPC               = 2;
-      ((DCI0_1_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->cshift            = 3;
-      ((DCI0_1_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->dai               = 1;
-      ((DCI0_1_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->cqi_req           = 1;
-      UL_pdu_size_bits  = sizeof_DCI0_1_5MHz_TDD_1_6_t;
-      UL_pdu_size_bytes = sizeof(DCI0_1_5MHz_TDD_1_6_t);
-      break;
+      case 6:
+        dci_length = sizeof_DCI1_1_5MHz_TDD_t;
+        dci_length_bytes = sizeof(DCI1_1_5MHz_TDD_t);
+        ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rah               = 0;
+        ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rballoc           = DLSCH_RB_ALLOC;
+        ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->mcs               = mcs;
+        ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->harq_pid          = 0;
+        ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->ndi               = 1;
+        ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rv                = 0;
+        ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->TPC               = 0;
+        ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->dai               = 0;
+        ((DCI1A_1_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->type           = 1;
+        ((DCI1A_1_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->vrb_type       = 0;
+        ((DCI1A_1_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->rballoc     = computeRIV(lte_frame_parms->N_RB_DL, 0, 4);
+        ((DCI1A_1_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->ndi            = 1;
+        ((DCI1A_1_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->rv             = 0;
+        ((DCI1A_1_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->mcs            = 2;
+        ((DCI1A_1_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->harq_pid       = 0;
+        ((DCI1A_1_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->TPC            = 1;
+        BCCH_pdu_size_bits  = sizeof_DCI1A_1_5MHz_TDD_1_6_t;
+        BCCH_pdu_size_bytes = sizeof(DCI1A_1_5MHz_TDD_1_6_t);
+        ((DCI0_1_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->type              = 0;
+        ((DCI0_1_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->hopping           = 0;
+        ((DCI0_1_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->rballoc        = DLSCH_RB_ALLOC;
+        ((DCI0_1_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->mcs               = mcs;
+        ((DCI0_1_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->ndi               = 1;
+        ((DCI0_1_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->TPC               = 2;
+        ((DCI0_1_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->cshift            = 3;
+        ((DCI0_1_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->dai               = 1;
+        ((DCI0_1_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->cqi_req           = 1;
+        UL_pdu_size_bits  = sizeof_DCI0_1_5MHz_TDD_1_6_t;
+        UL_pdu_size_bytes = sizeof(DCI0_1_5MHz_TDD_1_6_t);
+        break;
 
-    case 25:
-      dci_length = sizeof_DCI1_5MHz_TDD_t;
-      dci_length_bytes = sizeof(DCI1_5MHz_TDD_t);
-      ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rah                 = 0;
-      ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rballoc          = DLSCH_RB_ALLOC;
-      ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->mcs                 = mcs;
-      ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->harq_pid            = 0;
-      ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->ndi                 = 1;
-      ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rv                  = 0;
-      ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->TPC                 = 0;
-      ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->dai                 = 0;
-
-      ((DCI1A_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->type            = 1;
-      ((DCI1A_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->vrb_type        = 0;
-      ((DCI1A_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->rballoc      = computeRIV(lte_frame_parms->N_RB_DL, 18, 4);
-      ((DCI1A_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->ndi             = 1;
-      ((DCI1A_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->rv              = 0;
-      ((DCI1A_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->mcs             = 2;
-      ((DCI1A_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->harq_pid        = 0;
-      ((DCI1A_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->TPC             = 1;
-      BCCH_pdu_size_bits  = sizeof_DCI1A_5MHz_TDD_1_6_t;
-      BCCH_pdu_size_bytes = sizeof(DCI1A_5MHz_TDD_1_6_t);
-
-      ((DCI0_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->type              = 0;
-      ((DCI0_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->hopping           = 0;
-      ((DCI0_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->rballoc        = DLSCH_RB_ALLOC;
-      ((DCI0_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->mcs               = mcs;
-      ((DCI0_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->ndi               = 1;
-      ((DCI0_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->TPC               = 2;
-      ((DCI0_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->cshift            = 3;
-      ((DCI0_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->dai               = 1;
-      ((DCI0_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->cqi_req           = 1;
-      UL_pdu_size_bits  = sizeof_DCI0_5MHz_TDD_1_6_t;
-      UL_pdu_size_bytes = sizeof(DCI0_5MHz_TDD_1_6_t);
-      break;
+      case 25:
+        dci_length = sizeof_DCI1_5MHz_TDD_t;
+        dci_length_bytes = sizeof(DCI1_5MHz_TDD_t);
+        ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rah                 = 0;
+        ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rballoc          = DLSCH_RB_ALLOC;
+        ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->mcs                 = mcs;
+        ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->harq_pid            = 0;
+        ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->ndi                 = 1;
+        ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rv                  = 0;
+        ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->TPC                 = 0;
+        ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->dai                 = 0;
+        ((DCI1A_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->type            = 1;
+        ((DCI1A_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->vrb_type        = 0;
+        ((DCI1A_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->rballoc      = computeRIV(lte_frame_parms->N_RB_DL, 18, 4);
+        ((DCI1A_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->ndi             = 1;
+        ((DCI1A_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->rv              = 0;
+        ((DCI1A_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->mcs             = 2;
+        ((DCI1A_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->harq_pid        = 0;
+        ((DCI1A_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->TPC             = 1;
+        BCCH_pdu_size_bits  = sizeof_DCI1A_5MHz_TDD_1_6_t;
+        BCCH_pdu_size_bytes = sizeof(DCI1A_5MHz_TDD_1_6_t);
+        ((DCI0_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->type              = 0;
+        ((DCI0_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->hopping           = 0;
+        ((DCI0_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->rballoc        = DLSCH_RB_ALLOC;
+        ((DCI0_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->mcs               = mcs;
+        ((DCI0_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->ndi               = 1;
+        ((DCI0_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->TPC               = 2;
+        ((DCI0_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->cshift            = 3;
+        ((DCI0_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->dai               = 1;
+        ((DCI0_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->cqi_req           = 1;
+        UL_pdu_size_bits  = sizeof_DCI0_5MHz_TDD_1_6_t;
+        UL_pdu_size_bytes = sizeof(DCI0_5MHz_TDD_1_6_t);
+        break;
 
-    case 50:
-      dci_length = sizeof_DCI1_10MHz_TDD_t;
-      dci_length_bytes = sizeof(DCI1_10MHz_TDD_t);
-      ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rah              = 0;
-      ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rballoc       = DLSCH_RB_ALLOC;
-      ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->mcs              = mcs;
-      ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->harq_pid         = 0;
-      ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->ndi              = 1;
-      ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rv               = 0;
-      ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->TPC              = 0;
-      ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->dai              = 0;
-
-      ((DCI1A_10MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->type          = 1;
-      ((DCI1A_10MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->vrb_type      = 0;
-      ((DCI1A_10MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->rballoc    = computeRIV(lte_frame_parms->N_RB_DL, 30, 4);
-      ((DCI1A_10MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->ndi           = 1;
-      ((DCI1A_10MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->rv            = 0;
-      ((DCI1A_10MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->mcs           = 2;
-      ((DCI1A_10MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->harq_pid      = 0;
-      ((DCI1A_10MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->TPC           = 1;
-      BCCH_pdu_size_bits  = sizeof_DCI1A_10MHz_TDD_1_6_t;
-      BCCH_pdu_size_bytes = sizeof(DCI1A_10MHz_TDD_1_6_t);
-
-      ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->type              = 0;
-      ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->hopping           = 0;
-      ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->rballoc        = DLSCH_RB_ALLOC;
-      ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->mcs               = mcs;
-      ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->ndi               = 1;
-      ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->TPC               = 2;
-      ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->cshift            = 3;
-      ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->dai               = 1;
-      ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->cqi_req           = 1;
-      UL_pdu_size_bits  = sizeof_DCI0_10MHz_TDD_1_6_t;
-      UL_pdu_size_bytes = sizeof(DCI0_10MHz_TDD_1_6_t);
-      break;
+      case 50:
+        dci_length = sizeof_DCI1_10MHz_TDD_t;
+        dci_length_bytes = sizeof(DCI1_10MHz_TDD_t);
+        ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rah              = 0;
+        ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rballoc       = DLSCH_RB_ALLOC;
+        ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->mcs              = mcs;
+        ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->harq_pid         = 0;
+        ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->ndi              = 1;
+        ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rv               = 0;
+        ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->TPC              = 0;
+        ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->dai              = 0;
+        ((DCI1A_10MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->type          = 1;
+        ((DCI1A_10MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->vrb_type      = 0;
+        ((DCI1A_10MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->rballoc    = computeRIV(lte_frame_parms->N_RB_DL, 30, 4);
+        ((DCI1A_10MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->ndi           = 1;
+        ((DCI1A_10MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->rv            = 0;
+        ((DCI1A_10MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->mcs           = 2;
+        ((DCI1A_10MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->harq_pid      = 0;
+        ((DCI1A_10MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->TPC           = 1;
+        BCCH_pdu_size_bits  = sizeof_DCI1A_10MHz_TDD_1_6_t;
+        BCCH_pdu_size_bytes = sizeof(DCI1A_10MHz_TDD_1_6_t);
+        ((DCI0_10MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->type              = 0;
+        ((DCI0_10MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->hopping           = 0;
+        ((DCI0_10MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->rballoc        = DLSCH_RB_ALLOC;
+        ((DCI0_10MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->mcs               = mcs;
+        ((DCI0_10MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->ndi               = 1;
+        ((DCI0_10MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->TPC               = 2;
+        ((DCI0_10MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->cshift            = 3;
+        ((DCI0_10MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->dai               = 1;
+        ((DCI0_10MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->cqi_req           = 1;
+        UL_pdu_size_bits  = sizeof_DCI0_10MHz_TDD_1_6_t;
+        UL_pdu_size_bytes = sizeof(DCI0_10MHz_TDD_1_6_t);
+        break;
 
-    case 100:
-      dci_length = sizeof_DCI1_20MHz_TDD_t;
-      dci_length_bytes = sizeof(DCI1_20MHz_TDD_t);
-      ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rah                = 0;
-      ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rballoc         = DLSCH_RB_ALLOC;
-      ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->mcs                = mcs;
-      ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->harq_pid           = 0;
-      ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->ndi                = 1;
-      ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rv                 = 0;
-      ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->TPC                = 0;
-      ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->dai                = 0;
-
-      ((DCI1A_20MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->type            = 1;
-      ((DCI1A_20MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->vrb_type        = 0;
-      ((DCI1A_20MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->rballoc      = computeRIV(lte_frame_parms->N_RB_DL, 70, 4);
-      ((DCI1A_20MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->ndi             = 1;
-      ((DCI1A_20MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->rv              = 0;
-      ((DCI1A_20MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->mcs             = 2;
-      ((DCI1A_20MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->harq_pid        = 0;
-      ((DCI1A_20MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->TPC             = 1;
-      BCCH_pdu_size_bits  = sizeof_DCI1A_20MHz_TDD_1_6_t;
-      BCCH_pdu_size_bytes = sizeof(DCI1A_20MHz_TDD_1_6_t);
-
-      ((DCI0_20MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->type              = 0;
-      ((DCI0_20MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->hopping           = 0;
-      ((DCI0_20MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->rballoc        = DLSCH_RB_ALLOC;
-      ((DCI0_20MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->mcs               = mcs;
-      ((DCI0_20MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->ndi               = 1;
-      ((DCI0_20MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->TPC               = 2;
-      ((DCI0_20MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->cshift            = 3;
-      ((DCI0_20MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->dai               = 1;
-      ((DCI0_20MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->cqi_req           = 1;
-      UL_pdu_size_bits  = sizeof_DCI0_20MHz_TDD_1_6_t;
-      UL_pdu_size_bytes = sizeof(DCI0_20MHz_TDD_1_6_t);
-      break;
+      case 100:
+        dci_length = sizeof_DCI1_20MHz_TDD_t;
+        dci_length_bytes = sizeof(DCI1_20MHz_TDD_t);
+        ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rah                = 0;
+        ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rballoc         = DLSCH_RB_ALLOC;
+        ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->mcs                = mcs;
+        ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->harq_pid           = 0;
+        ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->ndi                = 1;
+        ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rv                 = 0;
+        ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->TPC                = 0;
+        ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->dai                = 0;
+        ((DCI1A_20MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->type            = 1;
+        ((DCI1A_20MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->vrb_type        = 0;
+        ((DCI1A_20MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->rballoc      = computeRIV(lte_frame_parms->N_RB_DL, 70, 4);
+        ((DCI1A_20MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->ndi             = 1;
+        ((DCI1A_20MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->rv              = 0;
+        ((DCI1A_20MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->mcs             = 2;
+        ((DCI1A_20MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->harq_pid        = 0;
+        ((DCI1A_20MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->TPC             = 1;
+        BCCH_pdu_size_bits  = sizeof_DCI1A_20MHz_TDD_1_6_t;
+        BCCH_pdu_size_bytes = sizeof(DCI1A_20MHz_TDD_1_6_t);
+        ((DCI0_20MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->type              = 0;
+        ((DCI0_20MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->hopping           = 0;
+        ((DCI0_20MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->rballoc        = DLSCH_RB_ALLOC;
+        ((DCI0_20MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->mcs               = mcs;
+        ((DCI0_20MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->ndi               = 1;
+        ((DCI0_20MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->TPC               = 2;
+        ((DCI0_20MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->cshift            = 3;
+        ((DCI0_20MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->dai               = 1;
+        ((DCI0_20MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->cqi_req           = 1;
+        UL_pdu_size_bits  = sizeof_DCI0_20MHz_TDD_1_6_t;
+        UL_pdu_size_bytes = sizeof(DCI0_20MHz_TDD_1_6_t);
+        break;
     }
   } else { //FDD
     switch (lte_frame_parms->N_RB_DL) {
-    case 6:
-      dci_length = sizeof_DCI1_1_5MHz_FDD_t;
-      dci_length_bytes = sizeof(DCI1_1_5MHz_FDD_t);
-      ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rah           = 0;
-      ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rballoc    = DLSCH_RB_ALLOC;
-      ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->mcs           = mcs;
-      ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->harq_pid      = 0;
-      ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->ndi           = 1;
-      ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rv            = 0;
-      ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->TPC           = 0;
-
-      ((DCI1A_1_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->type           = 1;
-      ((DCI1A_1_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->vrb_type       = 0;
-      ((DCI1A_1_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->rballoc     = computeRIV(lte_frame_parms->N_RB_DL, 0, 4);
-      ((DCI1A_1_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->ndi            = 1;
-      ((DCI1A_1_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->rv             = 0;
-      ((DCI1A_1_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->mcs            = 2;
-      ((DCI1A_1_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->harq_pid       = 0;
-      ((DCI1A_1_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->TPC            = 1;
-      BCCH_pdu_size_bits  = sizeof_DCI1A_1_5MHz_FDD_t;
-      BCCH_pdu_size_bytes = sizeof(DCI1A_1_5MHz_FDD_t);
-
-      ((DCI0_1_5MHz_FDD_t*)&UL_alloc_pdu[0])->type              = 0;
-      ((DCI0_1_5MHz_FDD_t*)&UL_alloc_pdu[0])->hopping           = 0;
-      ((DCI0_1_5MHz_FDD_t*)&UL_alloc_pdu[0])->rballoc        = DLSCH_RB_ALLOC;
-      ((DCI0_1_5MHz_FDD_t*)&UL_alloc_pdu[0])->mcs               = mcs;
-      ((DCI0_1_5MHz_FDD_t*)&UL_alloc_pdu[0])->ndi               = 1;
-      ((DCI0_1_5MHz_FDD_t*)&UL_alloc_pdu[0])->TPC               = 2;
-      ((DCI0_1_5MHz_FDD_t*)&UL_alloc_pdu[0])->cshift            = 3;
-      ((DCI0_1_5MHz_FDD_t*)&UL_alloc_pdu[0])->cqi_req           = 1;
-      UL_pdu_size_bits  = sizeof_DCI0_1_5MHz_FDD_t;
-      UL_pdu_size_bytes = sizeof(DCI0_1_5MHz_FDD_t);
-      break;
+      case 6:
+        dci_length = sizeof_DCI1_1_5MHz_FDD_t;
+        dci_length_bytes = sizeof(DCI1_1_5MHz_FDD_t);
+        ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rah           = 0;
+        ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rballoc    = DLSCH_RB_ALLOC;
+        ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->mcs           = mcs;
+        ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->harq_pid      = 0;
+        ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->ndi           = 1;
+        ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rv            = 0;
+        ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->TPC           = 0;
+        ((DCI1A_1_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->type           = 1;
+        ((DCI1A_1_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->vrb_type       = 0;
+        ((DCI1A_1_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->rballoc     = computeRIV(lte_frame_parms->N_RB_DL, 0, 4);
+        ((DCI1A_1_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->ndi            = 1;
+        ((DCI1A_1_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->rv             = 0;
+        ((DCI1A_1_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->mcs            = 2;
+        ((DCI1A_1_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->harq_pid       = 0;
+        ((DCI1A_1_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->TPC            = 1;
+        BCCH_pdu_size_bits  = sizeof_DCI1A_1_5MHz_FDD_t;
+        BCCH_pdu_size_bytes = sizeof(DCI1A_1_5MHz_FDD_t);
+        ((DCI0_1_5MHz_FDD_t *)&UL_alloc_pdu[0])->type              = 0;
+        ((DCI0_1_5MHz_FDD_t *)&UL_alloc_pdu[0])->hopping           = 0;
+        ((DCI0_1_5MHz_FDD_t *)&UL_alloc_pdu[0])->rballoc        = DLSCH_RB_ALLOC;
+        ((DCI0_1_5MHz_FDD_t *)&UL_alloc_pdu[0])->mcs               = mcs;
+        ((DCI0_1_5MHz_FDD_t *)&UL_alloc_pdu[0])->ndi               = 1;
+        ((DCI0_1_5MHz_FDD_t *)&UL_alloc_pdu[0])->TPC               = 2;
+        ((DCI0_1_5MHz_FDD_t *)&UL_alloc_pdu[0])->cshift            = 3;
+        ((DCI0_1_5MHz_FDD_t *)&UL_alloc_pdu[0])->cqi_req           = 1;
+        UL_pdu_size_bits  = sizeof_DCI0_1_5MHz_FDD_t;
+        UL_pdu_size_bytes = sizeof(DCI0_1_5MHz_FDD_t);
+        break;
 
-    case 25:
-      dci_length = sizeof_DCI1_5MHz_FDD_t;
-      dci_length_bytes = sizeof(DCI1_5MHz_FDD_t);
-      ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rah           = 0;
-      ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rballoc    = DLSCH_RB_ALLOC;
-      ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->mcs           = mcs;
-      ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->harq_pid      = 0;
-      ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->ndi           = 1;
-      ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rv            = 0;
-      ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->TPC           = 0;
-
-      ((DCI1A_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->type           = 1;
-      ((DCI1A_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->vrb_type       = 0;
-      ((DCI1A_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->rballoc     = computeRIV(lte_frame_parms->N_RB_DL, 18, 4);
-      ((DCI1A_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->ndi            = 1;
-      ((DCI1A_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->rv             = 0;
-      ((DCI1A_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->mcs            = 2;
-      ((DCI1A_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->harq_pid       = 0;
-      ((DCI1A_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->TPC            = 1;
-      BCCH_pdu_size_bits  = sizeof_DCI1A_5MHz_FDD_t;
-      BCCH_pdu_size_bytes = sizeof(DCI1A_5MHz_FDD_t);
-
-      ((DCI0_5MHz_FDD_t*)&UL_alloc_pdu[0])->type              = 0;
-      ((DCI0_5MHz_FDD_t*)&UL_alloc_pdu[0])->hopping           = 0;
-      ((DCI0_5MHz_FDD_t*)&UL_alloc_pdu[0])->rballoc        = DLSCH_RB_ALLOC;
-      ((DCI0_5MHz_FDD_t*)&UL_alloc_pdu[0])->mcs               = mcs;
-      ((DCI0_5MHz_FDD_t*)&UL_alloc_pdu[0])->ndi               = 1;
-      ((DCI0_5MHz_FDD_t*)&UL_alloc_pdu[0])->TPC               = 2;
-      ((DCI0_5MHz_FDD_t*)&UL_alloc_pdu[0])->cshift            = 3;
-      ((DCI0_5MHz_FDD_t*)&UL_alloc_pdu[0])->cqi_req           = 1;
-      UL_pdu_size_bits  = sizeof_DCI0_5MHz_FDD_t;
-      UL_pdu_size_bytes = sizeof(DCI0_5MHz_FDD_t);
-      break;
+      case 25:
+        dci_length = sizeof_DCI1_5MHz_FDD_t;
+        dci_length_bytes = sizeof(DCI1_5MHz_FDD_t);
+        ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rah           = 0;
+        ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rballoc    = DLSCH_RB_ALLOC;
+        ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->mcs           = mcs;
+        ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->harq_pid      = 0;
+        ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->ndi           = 1;
+        ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rv            = 0;
+        ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->TPC           = 0;
+        ((DCI1A_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->type           = 1;
+        ((DCI1A_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->vrb_type       = 0;
+        ((DCI1A_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->rballoc     = computeRIV(lte_frame_parms->N_RB_DL, 18, 4);
+        ((DCI1A_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->ndi            = 1;
+        ((DCI1A_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->rv             = 0;
+        ((DCI1A_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->mcs            = 2;
+        ((DCI1A_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->harq_pid       = 0;
+        ((DCI1A_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->TPC            = 1;
+        BCCH_pdu_size_bits  = sizeof_DCI1A_5MHz_FDD_t;
+        BCCH_pdu_size_bytes = sizeof(DCI1A_5MHz_FDD_t);
+        ((DCI0_5MHz_FDD_t *)&UL_alloc_pdu[0])->type              = 0;
+        ((DCI0_5MHz_FDD_t *)&UL_alloc_pdu[0])->hopping           = 0;
+        ((DCI0_5MHz_FDD_t *)&UL_alloc_pdu[0])->rballoc        = DLSCH_RB_ALLOC;
+        ((DCI0_5MHz_FDD_t *)&UL_alloc_pdu[0])->mcs               = mcs;
+        ((DCI0_5MHz_FDD_t *)&UL_alloc_pdu[0])->ndi               = 1;
+        ((DCI0_5MHz_FDD_t *)&UL_alloc_pdu[0])->TPC               = 2;
+        ((DCI0_5MHz_FDD_t *)&UL_alloc_pdu[0])->cshift            = 3;
+        ((DCI0_5MHz_FDD_t *)&UL_alloc_pdu[0])->cqi_req           = 1;
+        UL_pdu_size_bits  = sizeof_DCI0_5MHz_FDD_t;
+        UL_pdu_size_bytes = sizeof(DCI0_5MHz_FDD_t);
+        break;
 
-    case 50:
-      dci_length = sizeof_DCI1_10MHz_FDD_t;
-      dci_length_bytes = sizeof(DCI1_10MHz_FDD_t);
-      ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rah           = 0;
-      ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rballoc    = DLSCH_RB_ALLOC;
-      ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->mcs           = mcs;
-      ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->harq_pid      = 0;
-      ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->ndi           = 1;
-      ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rv            = 0;
-      ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->TPC           = 0;
-
-      ((DCI1A_10MHz_FDD_t*)&BCCH_alloc_pdu[0])->type           = 1;
-      ((DCI1A_10MHz_FDD_t*)&BCCH_alloc_pdu[0])->vrb_type       = 0;
-      ((DCI1A_10MHz_FDD_t*)&BCCH_alloc_pdu[0])->rballoc     = computeRIV(lte_frame_parms->N_RB_DL, 30, 4);
-      ((DCI1A_10MHz_FDD_t*)&BCCH_alloc_pdu[0])->ndi            = 1;
-      ((DCI1A_10MHz_FDD_t*)&BCCH_alloc_pdu[0])->rv             = 0;
-      ((DCI1A_10MHz_FDD_t*)&BCCH_alloc_pdu[0])->mcs            = 2;
-      ((DCI1A_10MHz_FDD_t*)&BCCH_alloc_pdu[0])->harq_pid       = 0;
-      ((DCI1A_10MHz_FDD_t*)&BCCH_alloc_pdu[0])->TPC            = 1;
-      BCCH_pdu_size_bits  = sizeof_DCI1A_10MHz_FDD_t;
-      BCCH_pdu_size_bytes = sizeof(DCI1A_10MHz_FDD_t);
-
-      ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu[0])->type              = 0;
-      ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu[0])->hopping           = 0;
-      ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu[0])->rballoc        = DLSCH_RB_ALLOC;
-      ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu[0])->mcs               = mcs;
-      ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu[0])->ndi               = 1;
-      ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu[0])->TPC               = 2;
-      ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu[0])->cshift            = 3;
-      ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu[0])->cqi_req           = 1;
-      UL_pdu_size_bits  = sizeof_DCI0_10MHz_FDD_t;
-      UL_pdu_size_bytes = sizeof(DCI0_10MHz_FDD_t);
-      break;
+      case 50:
+        dci_length = sizeof_DCI1_10MHz_FDD_t;
+        dci_length_bytes = sizeof(DCI1_10MHz_FDD_t);
+        ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rah           = 0;
+        ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rballoc    = DLSCH_RB_ALLOC;
+        ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->mcs           = mcs;
+        ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->harq_pid      = 0;
+        ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->ndi           = 1;
+        ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rv            = 0;
+        ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->TPC           = 0;
+        ((DCI1A_10MHz_FDD_t *)&BCCH_alloc_pdu[0])->type           = 1;
+        ((DCI1A_10MHz_FDD_t *)&BCCH_alloc_pdu[0])->vrb_type       = 0;
+        ((DCI1A_10MHz_FDD_t *)&BCCH_alloc_pdu[0])->rballoc     = computeRIV(lte_frame_parms->N_RB_DL, 30, 4);
+        ((DCI1A_10MHz_FDD_t *)&BCCH_alloc_pdu[0])->ndi            = 1;
+        ((DCI1A_10MHz_FDD_t *)&BCCH_alloc_pdu[0])->rv             = 0;
+        ((DCI1A_10MHz_FDD_t *)&BCCH_alloc_pdu[0])->mcs            = 2;
+        ((DCI1A_10MHz_FDD_t *)&BCCH_alloc_pdu[0])->harq_pid       = 0;
+        ((DCI1A_10MHz_FDD_t *)&BCCH_alloc_pdu[0])->TPC            = 1;
+        BCCH_pdu_size_bits  = sizeof_DCI1A_10MHz_FDD_t;
+        BCCH_pdu_size_bytes = sizeof(DCI1A_10MHz_FDD_t);
+        ((DCI0_10MHz_FDD_t *)&UL_alloc_pdu[0])->type              = 0;
+        ((DCI0_10MHz_FDD_t *)&UL_alloc_pdu[0])->hopping           = 0;
+        ((DCI0_10MHz_FDD_t *)&UL_alloc_pdu[0])->rballoc        = DLSCH_RB_ALLOC;
+        ((DCI0_10MHz_FDD_t *)&UL_alloc_pdu[0])->mcs               = mcs;
+        ((DCI0_10MHz_FDD_t *)&UL_alloc_pdu[0])->ndi               = 1;
+        ((DCI0_10MHz_FDD_t *)&UL_alloc_pdu[0])->TPC               = 2;
+        ((DCI0_10MHz_FDD_t *)&UL_alloc_pdu[0])->cshift            = 3;
+        ((DCI0_10MHz_FDD_t *)&UL_alloc_pdu[0])->cqi_req           = 1;
+        UL_pdu_size_bits  = sizeof_DCI0_10MHz_FDD_t;
+        UL_pdu_size_bytes = sizeof(DCI0_10MHz_FDD_t);
+        break;
 
-    case 100:
-      dci_length = sizeof_DCI1_20MHz_FDD_t;
-      dci_length_bytes = sizeof(DCI1_20MHz_FDD_t);
-      ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rah           = 0;
-      ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rballoc    = DLSCH_RB_ALLOC;
-      ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->mcs           = mcs;
-      ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->harq_pid      = 0;
-      ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->ndi           = 1;
-      ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rv            = 0;
-      ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->TPC           = 0;
-
-      ((DCI1A_20MHz_FDD_t*)&BCCH_alloc_pdu[0])->type           = 1;
-      ((DCI1A_20MHz_FDD_t*)&BCCH_alloc_pdu[0])->vrb_type       = 0;
-      ((DCI1A_20MHz_FDD_t*)&BCCH_alloc_pdu[0])->rballoc     = computeRIV(lte_frame_parms->N_RB_DL, 70, 4);
-      ((DCI1A_20MHz_FDD_t*)&BCCH_alloc_pdu[0])->ndi            = 1;
-      ((DCI1A_20MHz_FDD_t*)&BCCH_alloc_pdu[0])->rv             = 0;
-      ((DCI1A_20MHz_FDD_t*)&BCCH_alloc_pdu[0])->mcs            = 2;
-      ((DCI1A_20MHz_FDD_t*)&BCCH_alloc_pdu[0])->harq_pid       = 0;
-      ((DCI1A_20MHz_FDD_t*)&BCCH_alloc_pdu[0])->TPC            = 1;
-      BCCH_pdu_size_bits  = sizeof_DCI1A_20MHz_FDD_t;
-      BCCH_pdu_size_bytes = sizeof(DCI1A_20MHz_FDD_t);
-
-      ((DCI0_20MHz_FDD_t*)&UL_alloc_pdu[0])->type              = 0;
-      ((DCI0_20MHz_FDD_t*)&UL_alloc_pdu[0])->hopping           = 0;
-      ((DCI0_20MHz_FDD_t*)&UL_alloc_pdu[0])->rballoc        = DLSCH_RB_ALLOC;
-      ((DCI0_20MHz_FDD_t*)&UL_alloc_pdu[0])->mcs               = mcs;
-      ((DCI0_20MHz_FDD_t*)&UL_alloc_pdu[0])->ndi               = 1;
-      ((DCI0_20MHz_FDD_t*)&UL_alloc_pdu[0])->TPC               = 2;
-      ((DCI0_20MHz_FDD_t*)&UL_alloc_pdu[0])->cshift            = 3;
-      ((DCI0_20MHz_FDD_t*)&UL_alloc_pdu[0])->cqi_req           = 1;
-      UL_pdu_size_bits  = sizeof_DCI0_20MHz_FDD_t;
-      UL_pdu_size_bytes = sizeof(DCI0_20MHz_FDD_t);
-      break;
+      case 100:
+        dci_length = sizeof_DCI1_20MHz_FDD_t;
+        dci_length_bytes = sizeof(DCI1_20MHz_FDD_t);
+        ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rah           = 0;
+        ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rballoc    = DLSCH_RB_ALLOC;
+        ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->mcs           = mcs;
+        ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->harq_pid      = 0;
+        ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->ndi           = 1;
+        ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rv            = 0;
+        ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->TPC           = 0;
+        ((DCI1A_20MHz_FDD_t *)&BCCH_alloc_pdu[0])->type           = 1;
+        ((DCI1A_20MHz_FDD_t *)&BCCH_alloc_pdu[0])->vrb_type       = 0;
+        ((DCI1A_20MHz_FDD_t *)&BCCH_alloc_pdu[0])->rballoc     = computeRIV(lte_frame_parms->N_RB_DL, 70, 4);
+        ((DCI1A_20MHz_FDD_t *)&BCCH_alloc_pdu[0])->ndi            = 1;
+        ((DCI1A_20MHz_FDD_t *)&BCCH_alloc_pdu[0])->rv             = 0;
+        ((DCI1A_20MHz_FDD_t *)&BCCH_alloc_pdu[0])->mcs            = 2;
+        ((DCI1A_20MHz_FDD_t *)&BCCH_alloc_pdu[0])->harq_pid       = 0;
+        ((DCI1A_20MHz_FDD_t *)&BCCH_alloc_pdu[0])->TPC            = 1;
+        BCCH_pdu_size_bits  = sizeof_DCI1A_20MHz_FDD_t;
+        BCCH_pdu_size_bytes = sizeof(DCI1A_20MHz_FDD_t);
+        ((DCI0_20MHz_FDD_t *)&UL_alloc_pdu[0])->type              = 0;
+        ((DCI0_20MHz_FDD_t *)&UL_alloc_pdu[0])->hopping           = 0;
+        ((DCI0_20MHz_FDD_t *)&UL_alloc_pdu[0])->rballoc        = DLSCH_RB_ALLOC;
+        ((DCI0_20MHz_FDD_t *)&UL_alloc_pdu[0])->mcs               = mcs;
+        ((DCI0_20MHz_FDD_t *)&UL_alloc_pdu[0])->ndi               = 1;
+        ((DCI0_20MHz_FDD_t *)&UL_alloc_pdu[0])->TPC               = 2;
+        ((DCI0_20MHz_FDD_t *)&UL_alloc_pdu[0])->cshift            = 3;
+        ((DCI0_20MHz_FDD_t *)&UL_alloc_pdu[0])->cqi_req           = 1;
+        UL_pdu_size_bits  = sizeof_DCI0_20MHz_FDD_t;
+        UL_pdu_size_bytes = sizeof(DCI0_20MHz_FDD_t);
+        break;
     }
   }
 
@@ -360,11 +341,10 @@ DCI_PDU *get_dci(LTE_DL_FRAME_PARMS *lte_frame_parms,uint8_t log2L, uint8_t log2
       DCI_pdu.dci_alloc[ind].format       = format1A;
       DCI_pdu.dci_alloc[ind].ra_flag      = 0;
       DCI_pdu.dci_alloc[ind].search_space = DCI_COMMON_SPACE;
-      memcpy((void*)&DCI_pdu.dci_alloc[ind].dci_pdu[0], &BCCH_alloc_pdu[0], BCCH_pdu_size_bytes);
+      memcpy((void *)&DCI_pdu.dci_alloc[ind].dci_pdu[0], &BCCH_alloc_pdu[0], BCCH_pdu_size_bytes);
       DCI_pdu.Num_dci++;
       printf("Added common dci (%d) for rnti %x\n",ind,SI_RNTI);
     }
-    
 
     if (format_selector[ind]==format1) {
       DCI_pdu.dci_alloc[ind].dci_length   = dci_length;
@@ -373,10 +353,10 @@ DCI_PDU *get_dci(LTE_DL_FRAME_PARMS *lte_frame_parms,uint8_t log2L, uint8_t log2
       DCI_pdu.dci_alloc[ind].format       = format1;
       DCI_pdu.dci_alloc[ind].ra_flag      = 0;
       DCI_pdu.dci_alloc[ind].search_space = DCI_UE_SPACE;
-      memcpy((void*)&DCI_pdu.dci_alloc[ind].dci_pdu[0], &DLSCH_alloc_pdu[0], dci_length_bytes);
+      memcpy((void *)&DCI_pdu.dci_alloc[ind].dci_pdu[0], &DLSCH_alloc_pdu[0], dci_length_bytes);
       DCI_pdu.Num_dci++;
     }
-    
+
     if (format_selector[ind]==format0) {
       DCI_pdu.dci_alloc[ind].dci_length   = UL_pdu_size_bits;
       DCI_pdu.dci_alloc[ind].L            = log2L;
@@ -384,24 +364,20 @@ DCI_PDU *get_dci(LTE_DL_FRAME_PARMS *lte_frame_parms,uint8_t log2L, uint8_t log2
       DCI_pdu.dci_alloc[ind].format       = format0;
       DCI_pdu.dci_alloc[ind].ra_flag      = 0;
       DCI_pdu.dci_alloc[ind].search_space = DCI_UE_SPACE;
-      memcpy((void*)&DCI_pdu.dci_alloc[ind].dci_pdu[0], &UL_alloc_pdu[0], UL_pdu_size_bytes);
+      memcpy((void *)&DCI_pdu.dci_alloc[ind].dci_pdu[0], &UL_alloc_pdu[0], UL_pdu_size_bytes);
       DCI_pdu.Num_dci++;
     }
   }
-  
+
   return(&DCI_pdu);
 }
 
 extern int QPSK[4],QPSK2[4];
 
-int main(int argc, char **argv)
-{
-
+int main(int argc, char **argv) {
   char c;
-
   int i,l,aa;
   double sigma2, sigma2_dB=0,SNR,snr0=-2.0,snr1;
-
   int **txdata;
   double s_re[2][30720*2],s_im[2][30720*2],r_re[2][30720*2],r_im[2][30720*2];
   double iqim=0.0;
@@ -413,7 +389,6 @@ int main(int argc, char **argv)
 #endif
   int trial, n_errors_common=0,n_errors_ul=0,n_errors_dl=0,n_errors_cfi=0,n_errors_hi=0;
   unsigned char eNb_id = 0;
-
   uint8_t awgn_flag=0;
   int n_frames=1;
   channel_desc_t *eNB2UE;
@@ -427,25 +402,18 @@ int main(int argc, char **argv)
   DCI_format_t format_selector[MAX_NUM_DCI];
   uint8_t num_dci=0;
   uint8_t numCCE,common_active=0,ul_active=0,dl_active=0;
-
   uint32_t n_trials_common=0,n_trials_ul=0,n_trials_dl=0,false_detection_cnt=0;
   uint8_t common_rx,ul_rx,dl_rx;
   uint8_t tdd_config=3;
-
   FILE *input_fd=NULL;
   char input_val_str[50],input_val_str2[50];
   uint16_t n_rnti=0x1234;
   uint8_t osf=1,N_RB_DL=25;
-
   SCM_t channel_model=Rayleigh1_anticorr;
-
   DCI_ALLOC_t dci_alloc_rx[8];
-
   int ret;
-
   uint8_t harq_pid;
   uint8_t phich_ACK;
-
   uint8_t num_phich_interf = 0;
   lte_frame_type_t frame_type=TDD;
   //  int re_offset;
@@ -454,75 +422,71 @@ int main(int argc, char **argv)
   int k;
   uint32_t perfect_ce = 0;
   int CCE_table[800];
-
   number_of_cards = 1;
-
   cpuf = get_cpu_freq_GHz();
-
   logInit();
 
-
   while ((c = getopt (argc, argv, "hapFg:R:c:n:s:x:y:z:L:M:N:I:f:i:S:P:Y")) != -1) {
     switch (c) {
-    case 'a':
-      printf("Running AWGN simulation\n");
-      awgn_flag = 1;
-      break;
-
-    case 'R':
-      N_RB_DL = atoi(optarg);
-      break;
+      case 'a':
+        printf("Running AWGN simulation\n");
+        awgn_flag = 1;
+        break;
 
-    case 'F':
-      frame_type = FDD;
-      break;
+      case 'R':
+        N_RB_DL = atoi(optarg);
+        break;
 
-    case 'c':
-      tdd_config=atoi(optarg);
+      case 'F':
+        frame_type = FDD;
+        break;
 
-      if (tdd_config>6) {
-        printf("Illegal tdd_config %d (should be 0-6)\n",tdd_config);
-        exit(-1);
-      }
+      case 'c':
+        tdd_config=atoi(optarg);
 
-      break;
+        if (tdd_config>6) {
+          printf("Illegal tdd_config %d (should be 0-6)\n",tdd_config);
+          exit(-1);
+        }
 
-    case 'g':
-      switch((char)*optarg) {
-      case 'A':
-        channel_model=SCM_A;
         break;
 
-      case 'B':
-        channel_model=SCM_B;
-        break;
+      case 'g':
+        switch((char)*optarg) {
+          case 'A':
+            channel_model=SCM_A;
+            break;
 
-      case 'C':
-        channel_model=SCM_C;
-        break;
+          case 'B':
+            channel_model=SCM_B;
+            break;
 
-      case 'D':
-        channel_model=SCM_D;
-        break;
+          case 'C':
+            channel_model=SCM_C;
+            break;
 
-      case 'E':
-        channel_model=EPA;
-        break;
+          case 'D':
+            channel_model=SCM_D;
+            break;
 
-      case 'F':
-        channel_model=EVA;
-        break;
+          case 'E':
+            channel_model=EPA;
+            break;
 
-      case 'G':
-        channel_model=ETU;
-        break;
+          case 'F':
+            channel_model=EVA;
+            break;
 
-      default:
-        printf("Unsupported channel model!\n");
-        exit(-1);
-      }
+          case 'G':
+            channel_model=ETU;
+            break;
 
-      break;
+          default:
+            printf("Unsupported channel model!\n");
+            exit(-1);
+        }
+
+        break;
 
       /*
           case 'i':
@@ -532,164 +496,169 @@ int main(int argc, char **argv)
       interf2=atoi(optarg);
       break;
       */
-    case 'n':
-      n_frames = atoi(optarg);
-      break;
+      case 'n':
+        n_frames = atoi(optarg);
+        break;
 
-    case 's':
-      snr0 = atoi(optarg);
-      break;
+      case 's':
+        snr0 = atoi(optarg);
+        break;
 
-    case 'p':
-      extended_prefix_flag=1;
-      break;
+      case 'p':
+        extended_prefix_flag=1;
+        break;
 
-    case 'x':
-      transmission_mode=atoi(optarg);
+      case 'x':
+        transmission_mode=atoi(optarg);
 
-      if ((transmission_mode!=1) &&
-          (transmission_mode!=2) &&
-          (transmission_mode!=6)) {
-        printf("Unsupported transmission mode %d\n",transmission_mode);
-        exit(-1);
-      }
+        if ((transmission_mode!=1) &&
+            (transmission_mode!=2) &&
+            (transmission_mode!=6)) {
+          printf("Unsupported transmission mode %d\n",transmission_mode);
+          exit(-1);
+        }
 
-      break;
+        break;
 
-    case 'y':
-      n_tx=atoi(optarg);
+      case 'y':
+        n_tx=atoi(optarg);
 
-      if ((n_tx==0) || (n_tx>2)) {
-        printf("Unsupported number of tx antennas %d\n",n_tx);
-        exit(-1);
-      }
+        if ((n_tx==0) || (n_tx>2)) {
+          printf("Unsupported number of tx antennas %d\n",n_tx);
+          exit(-1);
+        }
 
-      break;
+        break;
 
-    case 'z':
-      n_rx=atoi(optarg);
+      case 'z':
+        n_rx=atoi(optarg);
 
-      if ((n_rx==0) || (n_rx>2)) {
-        printf("Unsupported number of rx antennas %d\n",n_rx);
-        exit(-1);
-      }
+        if ((n_rx==0) || (n_rx>2)) {
+          printf("Unsupported number of rx antennas %d\n",n_rx);
+          exit(-1);
+        }
 
-      break;
+        break;
 
-    case 'S':
-      subframe=atoi(optarg);
-      break;
+      case 'S':
+        subframe=atoi(optarg);
+        break;
 
-    case 'L':
-      log2L=atoi(optarg);
+      case 'L':
+        log2L=atoi(optarg);
 
-      if ((log2L!=0)&&
-          (log2L!=1)&&
-          (log2L!=2)&&
-          (log2L!=3)) {
-        printf("Unsupported DCI aggregation level %d (should be 0,1,2,3)\n",log2L);
-        exit(-1);
-      }
+        if ((log2L!=0)&&
+            (log2L!=1)&&
+            (log2L!=2)&&
+            (log2L!=3)) {
+          printf("Unsupported DCI aggregation level %d (should be 0,1,2,3)\n",log2L);
+          exit(-1);
+        }
 
-      break;
+        break;
 
-    case 'M':
-      log2Lcommon=atoi(optarg);
+      case 'M':
+        log2Lcommon=atoi(optarg);
 
-      if ((log2Lcommon!=2)&&
-          (log2Lcommon!=3)) {
-        printf("Unsupported Common DCI aggregation level %d (should be 2 or 3)\n",log2Lcommon);
-        exit(-1);
-      }
+        if ((log2Lcommon!=2)&&
+            (log2Lcommon!=3)) {
+          printf("Unsupported Common DCI aggregation level %d (should be 2 or 3)\n",log2Lcommon);
+          exit(-1);
+        }
 
-      break;
+        break;
 
-    case 'N':
-      format_selector[num_dci] = (DCI_format_t) atoi(optarg);
-      if ((format_selector[num_dci]<format0) || (format_selector[num_dci] > format1A)) {
-	printf("only formats 0, 1, and 1A supported for the moment\n");
-	exit(-1);
-      }
-      if (format_selector[num_dci]==format0) ul_active=1;
-      if (format_selector[num_dci]==format1A) common_active=1;
-      if (format_selector[num_dci]==format1) dl_active=1;
-      num_dci++;
-      break;
+      case 'N':
+        format_selector[num_dci] = (DCI_format_t) atoi(optarg);
 
-    case 'O':
-      osf = atoi(optarg);
-      break;
+        if ((format_selector[num_dci]<format0) || (format_selector[num_dci] > format1A)) {
+          printf("only formats 0, 1, and 1A supported for the moment\n");
+          exit(-1);
+        }
 
-    case 'I':
-      Nid_cell = atoi(optarg);
-      break;
+        if (format_selector[num_dci]==format0) ul_active=1;
 
-    case 'f':
-      input_fd = fopen(optarg,"r");
+        if (format_selector[num_dci]==format1A) common_active=1;
 
-      if (input_fd==NULL) {
-        printf("Problem with filename %s\n",optarg);
-        exit(-1);
-      }
+        if (format_selector[num_dci]==format1) dl_active=1;
 
-      break;
+        num_dci++;
+        break;
 
-    case 'i':
-      n_rnti=atoi(optarg);
-      break;
+      case 'O':
+        osf = atoi(optarg);
+        break;
 
-    case 'P':
-      num_phich_interf=atoi(optarg);
-      break;
+      case 'I':
+        Nid_cell = atoi(optarg);
+        break;
 
-    case 'Y':
-      perfect_ce = 1;
-      break;
+      case 'f':
+        input_fd = fopen(optarg,"r");
 
-    case 'h':
-      printf("%s -h(elp) -a(wgn on) -c tdd_config -n n_frames -r RiceanFactor -s snr0 -t Delayspread -x transmission mode (1,2,6) -y TXant -z RXant -L AggregLevelUEspec -M AggregLevelCommonDCI -N DCIFormat\n\n",
-             argv[0]);
-      printf("-h This message\n");
-      printf("-a Use AWGN channel and not multipath\n");
-      printf("-c TDD config\n");
-      printf("-S Subframe number (0..9)\n");
-      printf("-R N_RB_DL\n");
-      printf("-F use FDD frame\n");
-      printf("-p Use extended prefix mode\n");
-      printf("-n Number of frames to simulate\n");
-      printf("-r Ricean factor (dB, 0 means Rayleigh, 100 is almost AWGN\n");
-      printf("-s Starting SNR, runs from SNR to SNR + 5 dB.  If n_frames is 1 then just SNR is simulated\n");
-      printf("-t Delay spread for multipath channel\n");
-      printf("-x Transmission mode (1,2,6 for the moment)\n");
-      printf("-y Number of TX antennas used in eNB\n");
-      printf("-z Number of RX antennas used in UE\n");
-      printf("-P Number of interfering PHICH\n");
-      printf("-L log2 of Aggregation level for UE Specific DCI (0,1,2,3)\n");
-      printf("-M log2 Aggregation level for Common DCI (4,8)\n");
-      printf("-N Format for UE Spec DCI (0 - format0,\n");
-      printf("                           1 - format1,\n");
-      printf("                           2 - format1A,\n");
-      printf("                           3 - format1B_2A,\n");
-      printf("                           4 - format1B_4A,\n");
-      printf("                           5 - format1C,\n");
-      printf("                           6 - format1D_2A,\n");
-      printf("                           7 - format1D_4A,\n");
-      printf("                           8 - format2A_2A_L10PRB,\n");
-      printf("                           9 - format2A_2A_M10PRB,\n");
-      printf("                          10 - format2A_4A_L10PRB,\n");
-      printf("                          11 - format2A_4A_M10PRB,\n");
-      printf("                          12 - format2_2A_L10PRB,\n");
-      printf("                          13 - format2_2A_M10PRB,\n");
-      printf("                          14 - format2_4A_L10PRB,\n");
-      printf("                          15 - format2_4A_M10PRB\n");
-      printf("                          16 - format2_2D_M10PRB\n");
-      printf("                          17 - format2_2D_L10PRB\n");
-      printf("   can be called multiple times to add more than one DCI\n");
-      printf("-O Oversampling factor\n");
-      printf("-I Cell Id\n");
-      printf("-F Input sample stream\n");
-      exit(1);
-      break;
+        if (input_fd==NULL) {
+          printf("Problem with filename %s\n",optarg);
+          exit(-1);
+        }
+
+        break;
+
+      case 'i':
+        n_rnti=atoi(optarg);
+        break;
+
+      case 'P':
+        num_phich_interf=atoi(optarg);
+        break;
+
+      case 'Y':
+        perfect_ce = 1;
+        break;
+
+      case 'h':
+        printf("%s -h(elp) -a(wgn on) -c tdd_config -n n_frames -r RiceanFactor -s snr0 -t Delayspread -x transmission mode (1,2,6) -y TXant -z RXant -L AggregLevelUEspec -M AggregLevelCommonDCI -N DCIFormat\n\n",
+               argv[0]);
+        printf("-h This message\n");
+        printf("-a Use AWGN channel and not multipath\n");
+        printf("-c TDD config\n");
+        printf("-S Subframe number (0..9)\n");
+        printf("-R N_RB_DL\n");
+        printf("-F use FDD frame\n");
+        printf("-p Use extended prefix mode\n");
+        printf("-n Number of frames to simulate\n");
+        printf("-r Ricean factor (dB, 0 means Rayleigh, 100 is almost AWGN\n");
+        printf("-s Starting SNR, runs from SNR to SNR + 5 dB.  If n_frames is 1 then just SNR is simulated\n");
+        printf("-t Delay spread for multipath channel\n");
+        printf("-x Transmission mode (1,2,6 for the moment)\n");
+        printf("-y Number of TX antennas used in eNB\n");
+        printf("-z Number of RX antennas used in UE\n");
+        printf("-P Number of interfering PHICH\n");
+        printf("-L log2 of Aggregation level for UE Specific DCI (0,1,2,3)\n");
+        printf("-M log2 Aggregation level for Common DCI (4,8)\n");
+        printf("-N Format for UE Spec DCI (0 - format0,\n");
+        printf("                           1 - format1,\n");
+        printf("                           2 - format1A,\n");
+        printf("                           3 - format1B_2A,\n");
+        printf("                           4 - format1B_4A,\n");
+        printf("                           5 - format1C,\n");
+        printf("                           6 - format1D_2A,\n");
+        printf("                           7 - format1D_4A,\n");
+        printf("                           8 - format2A_2A_L10PRB,\n");
+        printf("                           9 - format2A_2A_M10PRB,\n");
+        printf("                          10 - format2A_4A_L10PRB,\n");
+        printf("                          11 - format2A_4A_M10PRB,\n");
+        printf("                          12 - format2_2A_L10PRB,\n");
+        printf("                          13 - format2_2A_M10PRB,\n");
+        printf("                          14 - format2_4A_L10PRB,\n");
+        printf("                          15 - format2_4A_M10PRB\n");
+        printf("                          16 - format2_2D_M10PRB\n");
+        printf("                          17 - format2_2D_L10PRB\n");
+        printf("   can be called multiple times to add more than one DCI\n");
+        printf("-O Oversampling factor\n");
+        printf("-I Cell Id\n");
+        printf("-F Input sample stream\n");
+        exit(1);
+        break;
     }
   }
 
@@ -701,22 +670,19 @@ int main(int argc, char **argv)
                  n_rx,
                  transmission_mode,
                  extended_prefix_flag,
-		 frame_type,
+                 frame_type,
                  Nid_cell,
                  tdd_config,
                  N_RB_DL,
-		 0,
+                 0,
                  osf,
                  perfect_ce);
-
 #ifdef XFORMS
   fl_initialize (&argc, argv, NULL, 0, 0);
   form_ue = create_lte_phy_scope_ue();
   sprintf (title, "LTE PHY SCOPE UE");
   fl_show_form (form_ue->lte_phy_scope_ue, FL_PLACE_HOTSPOT, FL_FULLBORDER, title);
 #endif
-
-
   mac_xface->computeRIV = computeRIV;
   mac_xface->frame_parms = &eNB->frame_parms;
   //  init_transport_channels(transmission_mode);
@@ -727,35 +693,25 @@ int main(int argc, char **argv)
     snr1 = snr0+8.0;
 
   printf("SNR0 %f, SNR1 %f\n",snr0,snr1);
-
   frame_parms = &eNB->frame_parms;
   printf("Getting %d dcis\n",num_dci);
-
   get_dci(frame_parms, log2L, log2Lcommon, format_selector, num_dci, n_rnti);
-
   txdata = eNB->common_vars.txdata[eNb_id];
-
   nsymb = (eNB->frame_parms.Ncp == 0) ? 14 : 12;
-
   printf("Subframe %d, FFT Size %d, Extended Prefix %d, Samples per subframe %d, Symbols per subframe %d\n",
          subframe,NUMBER_OF_OFDM_CARRIERS,
          eNB->frame_parms.Ncp,eNB->frame_parms.samples_per_tti,nsymb);
-
   eNB2UE = new_channel_desc_scm(eNB->frame_parms.nb_antennas_tx,
                                 UE->frame_parms.nb_antennas_rx,
                                 channel_model,
-				N_RB2sampling_rate(eNB->frame_parms.N_RB_DL),
-				N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL),
+                                N_RB2sampling_rate(eNB->frame_parms.N_RB_DL),
+                                N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL),
                                 0,
                                 0,
                                 0);
-
-  eNB_rxtx_proc_t *proc_rxtx = &eNB->proc.proc_rxtx[subframe&1];
-
+  L1_rxtx_proc_t *proc_rxtx = (subframe == 0)? &eNB->proc.L1_proc: &eNB->proc.L1_proc_tx;
   eNB->ulsch[0] = new_eNB_ulsch(MAX_TURBO_ITERATIONS,N_RB_DL,0);
   UE->ulsch[0]   = new_ue_ulsch(N_RB_DL,0);
-
-
   proc_rxtx->frame_tx    = 0;
   proc_rxtx->subframe_tx = subframe;
 
@@ -765,7 +721,7 @@ int main(int argc, char **argv)
     i=0;
 
     while (!feof(input_fd)) {
-      ret=fscanf(input_fd,"%s %s",input_val_str,input_val_str2);//&input_val1,&input_val2);
+      ret=fscanf(input_fd,"%49s %49s",input_val_str,input_val_str2);//&input_val1,&input_val2);
 
       if (ret != 2) {
         printf("%s:%d:%s: fscanf error, exiting\n", __FILE__, __LINE__, __FUNCTION__);
@@ -773,11 +729,11 @@ int main(int argc, char **argv)
       }
 
       if ((i%4)==0) {
-        ((short*)txdata[0])[i/2] = (short)((1<<15)*strtod(input_val_str,NULL));
-        ((short*)txdata[0])[(i/2)+1] = (short)((1<<15)*strtod(input_val_str2,NULL));
+        ((short *)txdata[0])[i/2] = (short)((1<<15)*strtod(input_val_str,NULL));
+        ((short *)txdata[0])[(i/2)+1] = (short)((1<<15)*strtod(input_val_str2,NULL));
 
         if ((i/4)<100)
-          printf("sample %d => %e + j%e (%d +j%d)\n",i/4,strtod(input_val_str,NULL),strtod(input_val_str2,NULL),((short*)txdata[0])[i/4],((short*)txdata[0])[(i/4)+1]);//1,input_val2,);
+          printf("sample %d => %e + j%e (%d +j%d)\n",i/4,strtod(input_val_str,NULL),strtod(input_val_str2,NULL),((short *)txdata[0])[i/4],((short *)txdata[0])[(i/4)+1]); //1,input_val2,);
       }
 
       i++;
@@ -794,7 +750,6 @@ int main(int argc, char **argv)
     tx_lev_dB = (unsigned int) dB_fixed(tx_lev);
   }
 
-
   UE->UE_mode[0] = PUSCH;
 
   //  nCCE_max = get_nCCE(3,&eNB->frame_parms,get_mi(&eNB->frame_parms,0));
@@ -802,8 +757,6 @@ int main(int argc, char **argv)
 
   //printf("num_phich interferers %d\n",num_phich_interf);
   for (SNR=snr0; SNR<snr1; SNR+=0.2) {
-
-
     n_errors_common = 0;
     n_errors_ul     = 0;
     n_errors_dl     = 0;
@@ -814,14 +767,11 @@ int main(int argc, char **argv)
     n_trials_dl=0;
 
     for (trial=0; trial<n_frames; trial++) {
-      
       //    printf("DCI (SF %d): txdataF %p (0 %p)\n",subframe,&eNB->common_vars.txdataF[eNb_id][aa][512*14*subframe],&eNB->common_vars.txdataF[eNb_id][aa][0]);
       for (aa=0; aa<eNB->frame_parms.nb_antennas_tx; aa++) {
         memset(&eNB->common_vars.txdataF[eNb_id][aa][0],0,FRAME_LENGTH_COMPLEX_SAMPLES_NO_PREFIX*sizeof(int32_t));
-
       }
 
-
       generate_pilots_slot(eNB,
                            eNB->common_vars.txdataF[eNb_id],
                            AMP,    //1024,
@@ -833,24 +783,26 @@ int main(int argc, char **argv)
                            (subframe*2)+1,
                            0);
 
-
       if (input_fd == NULL) {
         numCCE=0;
         n_trials_common++;
         common_active = 1;
-	if (eNB->frame_parms.N_RB_DL >= 50) { 
-	  if (ul_active==1) { 
-	    n_trials_ul++;
-	  }
-	}
-        if (eNB->frame_parms.N_RB_DL >= 25) { 
-	  if (dl_active==1) { 
-	    n_trials_dl++;
-	  }
-	}
+
+        if (eNB->frame_parms.N_RB_DL >= 50) {
+          if (ul_active==1) {
+            n_trials_ul++;
+          }
+        }
+
+        if (eNB->frame_parms.N_RB_DL >= 25) {
+          if (dl_active==1) {
+            n_trials_dl++;
+          }
+        }
+
         num_pdcch_symbols = get_num_pdcch_symbols(DCI_pdu.Num_dci,
                             DCI_pdu.dci_alloc, frame_parms, subframe);
-	numCCE = get_nCCE(num_pdcch_symbols,&eNB->frame_parms,get_mi(&eNB->frame_parms,subframe));
+        numCCE = get_nCCE(num_pdcch_symbols,&eNB->frame_parms,get_mi(&eNB->frame_parms,subframe));
 
         if (n_frames==1) {
           printf("num_dci %d, num_pddch_symbols %d, nCCE %d\n",
@@ -859,35 +811,35 @@ int main(int argc, char **argv)
         }
 
         // apply RNTI-based nCCE allocation
-	memset(CCE_table,0,800*sizeof(int));
+        memset(CCE_table,0,800*sizeof(int));
 
         for (i = 0; i < DCI_pdu.Num_dci; i++) {
           // SI RNTI
           if (DCI_pdu.dci_alloc[i].rnti == SI_RNTI) {
             DCI_pdu.dci_alloc[i].firstCCE = get_nCCE_offset_l1(CCE_table,
-							       1<<DCI_pdu.dci_alloc[i].L,
-							       numCCE,
-							       1,
-							       SI_RNTI,
-							       subframe);
+                                            1<<DCI_pdu.dci_alloc[i].L,
+                                            numCCE,
+                                            1,
+                                            SI_RNTI,
+                                            subframe);
           }
           // RA RNTI
           else if (DCI_pdu.dci_alloc[i].ra_flag == 1) {
             DCI_pdu.dci_alloc[i].firstCCE = get_nCCE_offset_l1(CCE_table,
-							       1<<DCI_pdu.dci_alloc[i].L,
-							       numCCE,
-							       1,
-							       DCI_pdu.dci_alloc[i].rnti,
-							       subframe);
+                                            1<<DCI_pdu.dci_alloc[i].L,
+                                            numCCE,
+                                            1,
+                                            DCI_pdu.dci_alloc[i].rnti,
+                                            subframe);
           }
           // C RNTI
           else {
             DCI_pdu.dci_alloc[i].firstCCE = get_nCCE_offset_l1(CCE_table,
-							       1<<DCI_pdu.dci_alloc[i].L,
-							       numCCE,
-							       0,
-							       DCI_pdu.dci_alloc[i].rnti,
-							       subframe);
+                                            1<<DCI_pdu.dci_alloc[i].L,
+                                            numCCE,
+                                            0,
+                                            DCI_pdu.dci_alloc[i].rnti,
+                                            subframe);
           }
 
           if (n_frames==1)
@@ -914,19 +866,16 @@ int main(int argc, char **argv)
             printf("generating PHICH\n");
 
           harq_pid = phich_subframe_to_harq_pid(&eNB->frame_parms, proc_rxtx->frame_tx, subframe);
-
           phich_ACK = taus()&1;
           eNB->ulsch[0]->harq_processes[harq_pid]->phich_active = 1;
           eNB->ulsch[0]->harq_processes[harq_pid]->first_rb     = 0;
           eNB->ulsch[0]->harq_processes[harq_pid]->n_DMRS       = 0;
           eNB->ulsch[0]->harq_processes[harq_pid]->phich_ACK    = phich_ACK;
           eNB->ulsch[0]->harq_processes[harq_pid]->dci_alloc    = 1;
-
           UE->ulsch[0]->harq_processes[harq_pid]->first_rb       = 0;
           UE->ulsch[0]->harq_processes[harq_pid]->n_DMRS         = 0;
-
           generate_phich_top(eNB,proc_rxtx,AMP,0);
-          
+
           // generate 3 interfering PHICH
           if (num_phich_interf>0) {
             eNB->ulsch[0]->harq_processes[harq_pid]->first_rb = 4;
@@ -938,15 +887,14 @@ int main(int argc, char **argv)
             eNB->ulsch[0]->harq_processes[harq_pid]->n_DMRS = 1;
             generate_phich_top(eNB,proc_rxtx,1024,0);
           }
+
           if (num_phich_interf>2) {
             eNB->ulsch[0]->harq_processes[harq_pid]->first_rb = 12;
             eNB->ulsch[0]->harq_processes[harq_pid]->n_DMRS = 1;
             generate_phich_top(eNB,proc_rxtx,1024,0);
-
           }
 
           eNB->ulsch[0]->harq_processes[harq_pid]->first_rb = 0;
-          
         }
 
         //  LOG_M("pilotsF.m","rsF",txdataF[0],lte_eNB->frame_parms.ofdm_symbol_size,1,1);
@@ -960,7 +908,6 @@ int main(int argc, char **argv)
 
         tx_lev = 0;
 
-
         for (aa=0; aa<eNB->frame_parms.nb_antenna_ports_eNB; aa++) {
           if (eNB->frame_parms.Ncp == 1)
             PHY_ofdm_mod(&eNB->common_vars.txdataF[eNb_id][aa][subframe*nsymb*eNB->frame_parms.ofdm_symbol_size],        // input,
@@ -1002,15 +949,12 @@ int main(int argc, char **argv)
         }
       }
 
-
-
       if (awgn_flag == 0) {
         multipath_channel(eNB2UE,s_re,s_im,r_re,r_im,
                           2*nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES,0);
       }
 
       //LOG_M("channel0.m","chan0",ch[0],channel_length,1,8);
-
       // scale by path_loss = NOW - P_noise
       //sigma2       = pow(10,sigma2_dB/10);
       //N0W          = -95.87;
@@ -1025,9 +969,8 @@ int main(int argc, char **argv)
       //  printf("Sigma2 %f (sigma2_dB %f)\n",sigma2,sigma2_dB);
       for (i=0; i<2*nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES; i++) {
         for (aa=0; aa<UE->frame_parms.nb_antennas_rx; aa++) {
-
-          ((short*) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti) + 2*i] = (short) (.667*(r_re[aa][i] + sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
-          ((short*) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti) + 2*i+1] = (short) (.667*(r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(
+          ((short *) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti) + 2*i] = (short) (.667*(r_re[aa][i] + sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
+          ((short *) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti) + 2*i+1] = (short) (.667*(r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(
                 0.0,1.0)));
           /*
           ((short*)UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti) + 2*i] =
@@ -1040,16 +983,14 @@ int main(int argc, char **argv)
 
       // UE receiver
       for (l=0; l<eNB->frame_parms.symbols_per_tti; l++) {
-
         //  subframe_offset = (l/eNB->frame_parms.symbols_per_tti)*eNB->frame_parms.samples_per_tti;
         //      printf("subframe_offset = %d\n",subframe_offset);
-
         slot_fep(UE,
                  l%(eNB->frame_parms.symbols_per_tti/2),
                  (2*subframe)+(l/(eNB->frame_parms.symbols_per_tti/2)),
                  0,
                  0,
-		 0);
+                 0);
 
         if (UE->perfect_ce == 1) {
           if (awgn_flag==0) {
@@ -1083,12 +1024,9 @@ int main(int argc, char **argv)
         }
 
         if (l==((eNB->frame_parms.Ncp==0)?4:3)) {
-
           //      LOG_M("H00.m","h00",&(UE->common_vars.dl_ch_estimates[0][0][0]),((frame_parms->Ncp==0)?7:6)*(eNB->frame_parms.ofdm_symbol_size),1,1);
-
           // do PDCCH procedures here
           UE->pdcch_vars[0][0]->crnti = n_rnti;
-
           //    printf("Doing RX : num_pdcch_symbols at TX %d\n",num_pdcch_symbols);
           rx_pdcch(UE,
                    trial,
@@ -1102,7 +1040,7 @@ int main(int argc, char **argv)
             UE->ulsch[0]->harq_processes[phich_subframe_to_harq_pid(&UE->frame_parms,0,subframe)]->status = ACTIVE;
             //UE->ulsch[0]->harq_processes[phich_subframe_to_harq_pid(&UE->frame_parms,0,subframe)]->Ndi = 1;
             rx_phich(UE,
-		     &UE->proc.proc_rxtx[subframe&1],
+                     &UE->proc.proc_rxtx[subframe&1],
                      subframe,
                      0);
           }
@@ -1112,7 +1050,6 @@ int main(int argc, char **argv)
           dci_cnt = dci_decoding_procedure(UE,
                                            dci_alloc_rx,1,
                                            0,subframe);
-
           common_rx=0;
           ul_rx=0;
           dl_rx=0;
@@ -1179,7 +1116,6 @@ int main(int argc, char **argv)
           if (n_errors_cfi > 10)
             break;
         }
-
       } // symbol loop
 
       if (n_errors_cfi > 100)
@@ -1193,17 +1129,17 @@ int main(int argc, char **argv)
                    UE,
                    eNb_id,0,subframe);
 #endif
-
     } //trials
-    
+
     if (common_active) printf("SNR %f : n_errors_common = %d/%d (%e)\n", SNR,n_errors_common,n_trials_common,(double)n_errors_common/n_trials_common);
+
     if (ul_active==1) printf("SNR %f : n_errors_ul = %d/%d (%e)\n", SNR,n_errors_ul,n_trials_ul,(double)n_errors_ul/n_trials_ul);
+
     if (dl_active==1) printf("SNR %f : n_errors_dl = %d/%d (%e)\n", SNR,n_errors_dl,n_trials_dl,(double)n_errors_dl/n_trials_dl);
+
     printf("SNR %f : n_errors_cfi = %d/%d (%e)\n", SNR,n_errors_cfi,trial,(double)n_errors_cfi/trial);
     printf("SNR %f : n_errors_hi = %d/%d (%e)\n", SNR,n_errors_hi,trial,(double)n_errors_hi/trial);
-    
   } // SNR
- 
 
   if (n_frames==1) {
     LOG_M("txsig0.m","txs0", txdata[0],FRAME_LENGTH_COMPLEX_SAMPLES,1,1);
@@ -1231,9 +1167,11 @@ int main(int argc, char **argv)
 
   lte_sync_time_free();
 
-  return(n_errors_ul);
+  if ( input_fd != NULL)
+    fclose(input_fd);
 
-  }
+  return(n_errors_ul);
+}
 
 
 
diff --git a/openair1/SIMULATION/LTE_PHY/prachsim.c b/openair1/SIMULATION/LTE_PHY/prachsim.c
index 7475017d85becb53cb083ee93165c49795302d17..0771917bfba865ac0daacad3e7f0d75303ff4a69 100644
--- a/openair1/SIMULATION/LTE_PHY/prachsim.c
+++ b/openair1/SIMULATION/LTE_PHY/prachsim.c
@@ -48,11 +48,8 @@ extern uint16_t prach_root_sequence_map0_3[838];
 
 void dump_prach_config(LTE_DL_FRAME_PARMS *frame_parms,uint8_t subframe);
 
-int main(int argc, char **argv)
-{
-
+int main(int argc, char **argv) {
   char c;
-
   int i,aa,aarx;
   double sigma2, sigma2_dB=0,SNR,snr0=-2.0,snr1=0.0,ue_speed0=0.0,ue_speed1=0.0;
   uint8_t snr1set=0;
@@ -64,7 +61,6 @@ int main(int argc, char **argv)
   int trial; //, ntrials=1;
   uint8_t transmission_mode = 1,n_tx=1,n_rx=1;
   uint16_t Nid_cell=0;
-
   uint8_t awgn_flag=0;
   uint8_t hs_flag=0;
   int n_frames=1;
@@ -73,9 +69,7 @@ int main(int argc, char **argv)
   uint8_t extended_prefix_flag=0;
   //  int8_t interf1=-19,interf2=-19;
   LTE_DL_FRAME_PARMS *frame_parms;
-
   SCM_t channel_model=Rayleigh1;
-
   //  uint8_t abstraction_flag=0,calibration_flag=0;
   //  double prach_sinr;
   uint8_t osf=1,N_RB_DL=25;
@@ -91,211 +85,212 @@ int main(int argc, char **argv)
   double ue_speed = 0;
   int NCS_config = 1,rootSequenceIndex=0;
   int threequarter_fs = 0;
-
   cpuf = get_cpu_freq_GHz();
-
   logInit();
-
   number_of_cards = 1;
 
-
-
   while ((c = getopt (argc, argv, "hHaA:Cr:p:g:n:s:S:t:x:y:v:V:z:N:F:d:Z:L:R:E")) != -1) {
     switch (c) {
-    case 'a':
-      printf("Running AWGN simulation\n");
-      awgn_flag = 1;
-      /* ntrials not used later, no need to set */
-      //ntrials=1;
-      break;
-
-    case 'd':
-      delay = atoi(optarg);
-      break;
-
-    case 'g':
-      switch((char)*optarg) {
-      case 'A':
-        channel_model=SCM_A;
+      case 'a':
+        printf("Running AWGN simulation\n");
+        awgn_flag = 1;
+        /* ntrials not used later, no need to set */
+        //ntrials=1;
         break;
 
-      case 'B':
-        channel_model=SCM_B;
+      case 'd':
+        delay = atoi(optarg);
         break;
 
-      case 'C':
-        channel_model=SCM_C;
-        break;
+      case 'g':
+        switch((char)*optarg) {
+          case 'A':
+            channel_model=SCM_A;
+            break;
 
-      case 'D':
-        channel_model=SCM_D;
-        break;
+          case 'B':
+            channel_model=SCM_B;
+            break;
 
-      case 'E':
-        channel_model=EPA;
-        break;
+          case 'C':
+            channel_model=SCM_C;
+            break;
 
-      case 'F':
-        channel_model=EVA;
-        break;
+          case 'D':
+            channel_model=SCM_D;
+            break;
 
-      case 'G':
-        channel_model=ETU;
-        break;
+          case 'E':
+            channel_model=EPA;
+            break;
 
-      case 'H':
-        channel_model=Rayleigh8;
+          case 'F':
+            channel_model=EVA;
+            break;
 
-      case 'I':
-        channel_model=Rayleigh1;
+          case 'G':
+            channel_model=ETU;
+            break;
 
-      case 'J':
-        channel_model=Rayleigh1_corr;
+          case 'H':
+            channel_model=Rayleigh8;
+            break;
 
-      case 'K':
-        channel_model=Rayleigh1_anticorr;
+          case 'I':
+            channel_model=Rayleigh1;
+            break;
 
-      case 'L':
-        channel_model=Rice8;
+          case 'J':
+            channel_model=Rayleigh1_corr;
+            break;
 
-      case 'M':
-        channel_model=Rice1;
+          case 'K':
+            channel_model=Rayleigh1_anticorr;
+            break;
+
+          case 'L':
+            channel_model=Rice8;
+            break;
+
+          case 'M':
+            channel_model=Rice1;
+            break;
+
+          case 'N':
+            channel_model=Rayleigh1_800;
+            break;
+
+          default:
+            msg("Unsupported channel model!\n");
+            exit(-1);
+        }
 
-      case 'N':
-        channel_model=Rayleigh1_800;
         break;
 
-      default:
-        msg("Unsupported channel model!\n");
-        exit(-1);
-      }
+      case 'E':
+        threequarter_fs=1;
+        break;
 
-      break;
+      case 'n':
+        n_frames = atoi(optarg);
+        break;
 
-    case 'E':
-      threequarter_fs=1;
-      break;
+      case 's':
+        snr0 = atof(optarg);
+        msg("Setting SNR0 to %f\n",snr0);
+        break;
 
-    case 'n':
-      n_frames = atoi(optarg);
-      break;
+      case 'S':
+        snr1 = atof(optarg);
+        snr1set=1;
+        msg("Setting SNR1 to %f\n",snr1);
+        break;
 
-    case 's':
-      snr0 = atof(optarg);
-      msg("Setting SNR0 to %f\n",snr0);
-      break;
+      case 'p':
+        preamble_tx=atoi(optarg);
+        break;
 
-    case 'S':
-      snr1 = atof(optarg);
-      snr1set=1;
-      msg("Setting SNR1 to %f\n",snr1);
-      break;
+      case 'v':
+        ue_speed0 = atoi(optarg);
+        break;
 
-    case 'p':
-      preamble_tx=atoi(optarg);
-      break;
+      case 'V':
+        ue_speed1 = atoi(optarg);
+        ue_speed1set = 1;
+        break;
 
-    case 'v':
-      ue_speed0 = atoi(optarg);
-      break;
+      case 'Z':
+        NCS_config = atoi(optarg);
 
-    case 'V':
-      ue_speed1 = atoi(optarg);
-      ue_speed1set = 1;
-      break;
+        if ((NCS_config > 15) || (NCS_config < 0))
+          printf("Illegal NCS_config %d, (should be 0-15)\n",NCS_config);
 
-    case 'Z':
-      NCS_config = atoi(optarg);
+        break;
 
-      if ((NCS_config > 15) || (NCS_config < 0))
-        printf("Illegal NCS_config %d, (should be 0-15)\n",NCS_config);
+      case 'H':
+        printf("High-Speed Flag enabled\n");
+        hs_flag = 1;
+        break;
 
-      break;
+      case 'L':
+        rootSequenceIndex = atoi(optarg);
 
-    case 'H':
-      printf("High-Speed Flag enabled\n");
-      hs_flag = 1;
-      break;
+        if ((rootSequenceIndex < 0) || (rootSequenceIndex > 837))
+          printf("Illegal rootSequenceNumber %d, (should be 0-837)\n",rootSequenceIndex);
 
-    case 'L':
-      rootSequenceIndex = atoi(optarg);
+        break;
 
-      if ((rootSequenceIndex < 0) || (rootSequenceIndex > 837))
-        printf("Illegal rootSequenceNumber %d, (should be 0-837)\n",rootSequenceIndex);
+      case 'x':
+        transmission_mode=atoi(optarg);
 
-      break;
+        if ((transmission_mode!=1) &&
+            (transmission_mode!=2) &&
+            (transmission_mode!=6)) {
+          msg("Unsupported transmission mode %d\n",transmission_mode);
+          exit(-1);
+        }
 
-    case 'x':
-      transmission_mode=atoi(optarg);
+        break;
 
-      if ((transmission_mode!=1) &&
-          (transmission_mode!=2) &&
-          (transmission_mode!=6)) {
-        msg("Unsupported transmission mode %d\n",transmission_mode);
-        exit(-1);
-      }
+      case 'y':
+        n_tx=atoi(optarg);
 
-      break;
+        if ((n_tx==0) || (n_tx>2)) {
+          msg("Unsupported number of tx antennas %d\n",n_tx);
+          exit(-1);
+        }
 
-    case 'y':
-      n_tx=atoi(optarg);
+        break;
 
-      if ((n_tx==0) || (n_tx>2)) {
-        msg("Unsupported number of tx antennas %d\n",n_tx);
-        exit(-1);
-      }
+      case 'z':
+        n_rx=atoi(optarg);
 
-      break;
+        if ((n_rx==0) || (n_rx>2)) {
+          msg("Unsupported number of rx antennas %d\n",n_rx);
+          exit(-1);
+        }
 
-    case 'z':
-      n_rx=atoi(optarg);
+        break;
 
-      if ((n_rx==0) || (n_rx>2)) {
-        msg("Unsupported number of rx antennas %d\n",n_rx);
-        exit(-1);
-      }
+      case 'N':
+        Nid_cell = atoi(optarg);
+        break;
+
+      case 'R':
+        N_RB_DL = atoi(optarg);
+        break;
 
-      break;
-
-    case 'N':
-      Nid_cell = atoi(optarg);
-      break;
-
-    case 'R':
-      N_RB_DL = atoi(optarg);
-      break;
-
-    case 'O':
-      osf = atoi(optarg);
-      break;
-
-    case 'F':
-      break;
-
-    default:
-    case 'h':
-      printf("%s -h(elp) -a(wgn on) -p(extended_prefix) -N cell_id -f output_filename -F input_filename -g channel_model -n n_frames -s snr0 -S snr1 -x transmission_mode -y TXant -z RXant -i Intefrence0 -j Interference1 -A interpolation_file -C(alibration offset dB) -N CellId\n",
-             argv[0]);
-      printf("-h This message\n");
-      printf("-a Use AWGN channel and not multipath\n");
-      printf("-n Number of frames to simulate\n");
-      printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB.  If n_frames is 1 then just SNR is simulated\n");
-      printf("-S Ending SNR, runs from SNR0 to SNR1\n");
-      printf("-g [A,B,C,D,E,F,G,I,N] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) or Rayleigh1 (I) or Rayleigh1_800 (N) models (ignores delay spread and Ricean factor)\n");
-      printf("-z Number of RX antennas used in eNB\n");
-      printf("-N Nid_cell\n");
-      printf("-O oversampling factor (1,2,4,8,16)\n");
-      //    printf("-f PRACH format (0=1,1=2,2=3,3=4)\n");
-      printf("-d Channel delay \n");
-      printf("-v Starting UE velocity in km/h, runs from 'v' to 'v+50km/h'. If n_frames is 1 just 'v' is simulated \n");
-      printf("-V Ending UE velocity in km/h, runs from 'v' to 'V'");
-      printf("-L rootSequenceIndex (0-837)\n");
-      printf("-Z NCS_config (ZeroCorrelationZone) (0-15)\n");
-      printf("-H Run with High-Speed Flag enabled \n");
-      printf("-R Number of PRB (6,15,25,50,75,100)\n");
-      printf("-F Input filename (.txt format) for RX conformance testing\n");
-      exit (-1);
-      break;
+      case 'O':
+        osf = atoi(optarg);
+        break;
+
+      case 'F':
+        break;
+
+      default:
+      case 'h':
+        printf("%s -h(elp) -a(wgn on) -p(extended_prefix) -N cell_id -f output_filename -F input_filename -g channel_model -n n_frames -s snr0 -S snr1 -x transmission_mode -y TXant -z RXant -i Intefrence0 -j Interference1 -A interpolation_file -C(alibration offset dB) -N CellId\n",
+               argv[0]);
+        printf("-h This message\n");
+        printf("-a Use AWGN channel and not multipath\n");
+        printf("-n Number of frames to simulate\n");
+        printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB.  If n_frames is 1 then just SNR is simulated\n");
+        printf("-S Ending SNR, runs from SNR0 to SNR1\n");
+        printf("-g [A,B,C,D,E,F,G,I,N] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) or Rayleigh1 (I) or Rayleigh1_800 (N) models (ignores delay spread and Ricean factor)\n");
+        printf("-z Number of RX antennas used in eNB\n");
+        printf("-N Nid_cell\n");
+        printf("-O oversampling factor (1,2,4,8,16)\n");
+        //    printf("-f PRACH format (0=1,1=2,2=3,3=4)\n");
+        printf("-d Channel delay \n");
+        printf("-v Starting UE velocity in km/h, runs from 'v' to 'v+50km/h'. If n_frames is 1 just 'v' is simulated \n");
+        printf("-V Ending UE velocity in km/h, runs from 'v' to 'V'");
+        printf("-L rootSequenceIndex (0-837)\n");
+        printf("-Z NCS_config (ZeroCorrelationZone) (0-15)\n");
+        printf("-H Run with High-Speed Flag enabled \n");
+        printf("-R Number of PRB (6,15,25,50,75,100)\n");
+        printf("-F Input filename (.txt format) for RX conformance testing\n");
+        exit (-1);
+        break;
     }
   }
 
@@ -304,17 +299,16 @@ int main(int argc, char **argv)
 
   lte_param_init(n_tx,
                  n_tx,
-		 n_rx,
-		 transmission_mode,
-		 extended_prefix_flag,
-		 FDD,
-		 Nid_cell,
-		 3,
-		 N_RB_DL,
-		 threequarter_fs,
-		 osf,
-		 0);
-
+                 n_rx,
+                 transmission_mode,
+                 extended_prefix_flag,
+                 FDD,
+                 Nid_cell,
+                 3,
+                 N_RB_DL,
+                 threequarter_fs,
+                 osf,
+                 0);
 
   if (snr1set==0) {
     if (n_frames==1)
@@ -331,30 +325,22 @@ int main(int argc, char **argv)
   }
 
   printf("SNR0 %f, SNR1 %f\n",snr0,snr1);
-
   frame_parms = &eNB->frame_parms;
-
-
   txdata = UE->common_vars.txdata;
   printf("txdata %p\n",&txdata[0][subframe*frame_parms->samples_per_tti]);
-
-  s_re = malloc(2*sizeof(double*));
-  s_im = malloc(2*sizeof(double*));
-  r_re = malloc(2*sizeof(double*));
-  r_im = malloc(2*sizeof(double*));
+  s_re = malloc(2*sizeof(double *));
+  s_im = malloc(2*sizeof(double *));
+  r_re = malloc(2*sizeof(double *));
+  r_im = malloc(2*sizeof(double *));
   nsymb = (frame_parms->Ncp == 0) ? 14 : 12;
-
   printf("FFT Size %d, Extended Prefix %d, Samples per subframe %d, Symbols per subframe %d\n",NUMBER_OF_OFDM_CARRIERS,
          frame_parms->Ncp,frame_parms->samples_per_tti,nsymb);
-
-
-
   msg("[SIM] Using SCM/101\n");
   UE2eNB = new_channel_desc_scm(UE->frame_parms.nb_antennas_tx,
                                 eNB->frame_parms.nb_antennas_rx,
                                 channel_model,
-				N_RB2sampling_rate(eNB->frame_parms.N_RB_UL),
-				N_RB2channel_bandwidth(eNB->frame_parms.N_RB_UL),
+                                N_RB2sampling_rate(eNB->frame_parms.N_RB_UL),
+                                N_RB2channel_bandwidth(eNB->frame_parms.N_RB_UL),
                                 0.0,
                                 delay,
                                 0);
@@ -365,12 +351,10 @@ int main(int argc, char **argv)
   }
 
   for (i=0; i<2; i++) {
-
     s_re[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
     bzero(s_re[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
     s_im[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
     bzero(s_im[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
-
     r_re[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
     bzero(r_re[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
     r_im[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
@@ -382,30 +366,22 @@ int main(int argc, char **argv)
   UE->frame_parms.prach_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig=NCS_config;
   UE->frame_parms.prach_config_common.prach_ConfigInfo.highSpeedFlag=hs_flag;
   UE->frame_parms.prach_config_common.prach_ConfigInfo.prach_FreqOffset=0;
-
-
   eNB->frame_parms.prach_config_common.rootSequenceIndex=rootSequenceIndex;
   eNB->frame_parms.prach_config_common.prach_ConfigInfo.prach_ConfigIndex=0;
   eNB->frame_parms.prach_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig=NCS_config;
   eNB->frame_parms.prach_config_common.prach_ConfigInfo.highSpeedFlag=hs_flag;
   eNB->frame_parms.prach_config_common.prach_ConfigInfo.prach_FreqOffset=0;
-
   eNB->node_function       = eNodeB_3GPP;
   eNB->proc.subframe_rx    = subframe;
   eNB->proc.subframe_prach = subframe;
-
   /* N_ZC not used later, so prach_fmt is also useless, don't set */
   //prach_fmt = get_prach_fmt(eNB->frame_parms.prach_config_common.prach_ConfigInfo.prach_ConfigIndex,
   //                          eNB->frame_parms.frame_type);
   /* N_ZC not used later, no need to set */
   //N_ZC = (prach_fmt <4)?839:139;
-
   compute_prach_seq(&eNB->frame_parms.prach_config_common,eNB->frame_parms.frame_type,eNB->X_u);
-
   compute_prach_seq(&UE->frame_parms.prach_config_common,UE->frame_parms.frame_type,UE->X_u);
-
   UE->prach_vars[0]->amp = AMP;
-
   UE->prach_resources[0] = &prach_resources;
 
   if (preamble_tx == 99)
@@ -416,18 +392,14 @@ int main(int argc, char **argv)
 
   UE->prach_resources[0]->ra_PreambleIndex = preamble_tx;
   UE->prach_resources[0]->ra_TDD_map_index = 0;
-
   tx_lev = generate_prach(UE,
                           0, //eNB_id,
                           subframe,
                           0); //Nf
-
   /* tx_lev_dB not used later, no need to set */
   //tx_lev_dB = (unsigned int) dB_fixed(tx_lev);
-
   LOG_M("txsig0_new.m","txs0", &txdata[0][subframe*frame_parms->samples_per_tti],frame_parms->samples_per_tti,1,1);
   //LOG_M("txsig1.m","txs1", txdata[1],FRAME_LENGTH_COMPLEX_SAMPLES,1,1);
-
   // multipath channel
   dump_prach_config(&eNB->frame_parms,subframe);
 
@@ -450,8 +422,6 @@ int main(int argc, char **argv)
     }
   }
 
-
-
   for (SNR=snr0; SNR<snr1; SNR+=.2) {
     for (ue_speed=ue_speed0; ue_speed<ue_speed1; ue_speed+=10) {
       delay_avg = 0.0;
@@ -461,7 +431,6 @@ int main(int argc, char **argv)
       prach_errors=0;
 
       for (trial=0; trial<n_frames; trial++) {
-
         sigma2_dB = 10*log10((double)tx_lev) - SNR;
 
         if (n_frames==1)
@@ -471,7 +440,6 @@ int main(int argc, char **argv)
         sigma2 = pow(10,sigma2_dB/10);
         //  printf("Sigma2 %f (sigma2_dB %f)\n",sigma2,sigma2_dB);
 
-
         if (awgn_flag == 0) {
           multipath_tv_channel(UE2eNB,s_re,s_im,r_re,r_im,
                                2*frame_parms->samples_per_tti,0);
@@ -485,9 +453,8 @@ int main(int argc, char **argv)
 
         for (i=0; i<frame_parms->samples_per_tti; i++) {
           for (aa=0; aa<eNB->frame_parms.nb_antennas_rx; aa++) {
-
-            ((short*) &eNB->common_vars.rxdata[0][aa][subframe*frame_parms->samples_per_tti])[2*i] = (short) (.167*(r_re[aa][i] +sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
-            ((short*) &eNB->common_vars.rxdata[0][aa][subframe*frame_parms->samples_per_tti])[2*i+1] = (short) (.167*(r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
+            ((short *) &eNB->common_vars.rxdata[0][aa][subframe*frame_parms->samples_per_tti])[2*i] = (short) (.167*(r_re[aa][i] +sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
+            ((short *) &eNB->common_vars.rxdata[0][aa][subframe*frame_parms->samples_per_tti])[2*i+1] = (short) (.167*(r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
           }
         }
 
@@ -496,7 +463,6 @@ int main(int argc, char **argv)
                  preamble_delay_list,
                  0,   //Nf
                  0);    //tdd_mapindex
-
         preamble_energy_max = preamble_energy_list[0];
         preamble_max = 0;
 
@@ -524,8 +490,8 @@ int main(int argc, char **argv)
           LOG_M("prach0.m","prach0", &txdata[0][subframe*frame_parms->samples_per_tti],frame_parms->samples_per_tti,1,1);
           LOG_M("prachF0.m","prachF0", &eNB->prach_vars.prachF[0],24576,1,1);
           LOG_M("rxsig0.m","rxs0",
-                       &eNB->common_vars.rxdata[0][0][subframe*frame_parms->samples_per_tti],
-                       frame_parms->samples_per_tti,1,1);
+                &eNB->common_vars.rxdata[0][0][subframe*frame_parms->samples_per_tti],
+                frame_parms->samples_per_tti,1,1);
           LOG_M("rxsigF0.m","rxsF0", eNB->prach_vars.rxsigF[0],6144,1,1);
           LOG_M("prach_preamble.m","prachp",&eNB->X_u[0],839,1,1);
         }
@@ -539,7 +505,6 @@ int main(int argc, char **argv)
     //  printf("(%f,%f)\n",SNR,(double)prach_errors/(double)n_frames);
   } //SNR loop
 
-
   for (i=0; i<2; i++) {
     free(s_re[i]);
     free(s_im[i]);
@@ -551,11 +516,8 @@ int main(int argc, char **argv)
   free(s_im);
   free(r_re);
   free(r_im);
-
   lte_sync_time_free();
-
   return(0);
-
 }
 
 
diff --git a/openair1/SIMULATION/LTE_PHY/pucchsim.c b/openair1/SIMULATION/LTE_PHY/pucchsim.c
index ad236a6f7568bb9a7d6aeb4a81195bf48a60039e..a58f844945706b37c30457494964734f55540502 100644
--- a/openair1/SIMULATION/LTE_PHY/pucchsim.c
+++ b/openair1/SIMULATION/LTE_PHY/pucchsim.c
@@ -45,37 +45,29 @@ PHY_VARS_UE *UE;
 
 double cpuf;
 
-int main(int argc, char **argv)
-{
-
+int main(int argc, char **argv) {
   char c;
-
   int i,l,aa;
   double sigma2, sigma2_dB=0,SNR,snr0=-2.0,snr1=0.0;
   uint8_t snr1set=0;
   //mod_sym_t **txdataF;
   int **txdata;
   double s_re0[30720],s_re1[30720],s_im0[30720],s_im1[30720],r_re0[30720],r_im0[30720],r_re1[30720],r_im1[30720];
-  double *s_re[2]={s_re0,s_re1};
-  double *s_im[2]={s_im0,s_im1};
-  double *r_re[2]={r_re0,r_re1};
-  double *r_im[2]={r_im0,r_im1};
+  double *s_re[2]= {s_re0,s_re1};
+  double *s_im[2]= {s_im0,s_im1};
+  double *r_re[2]= {r_re0,r_re1};
+  double *r_im[2]= {r_im0,r_im1};
   double ricean_factor=0.0000005,iqim=0.0;
-
   int trial, n_trials, ntrials=1, n_errors;
   uint8_t transmission_mode = 1,n_tx=1,n_rx=1;
   unsigned char eNB_id = 0;
   uint16_t Nid_cell=0;
-
   int n_frames=1;
   channel_desc_t *UE2eNB;
   uint32_t nsymb,tx_lev;
   uint8_t extended_prefix_flag=0;
-
   LTE_DL_FRAME_PARMS *frame_parms;
-
   SCM_t channel_model=Rayleigh1_corr;
-
   //  double pucch_sinr;
   uint8_t osf=1,N_RB_DL=25;
   uint32_t pucch_tx=0,pucch1_missed=0,pucch1_false=0,pucch3_false=0,sig;
@@ -90,202 +82,203 @@ int main(int argc, char **argv)
   double stat_no_sig,stat_sig;
   uint8_t N0=40;
   uint8_t pucch1_thres=10;
-
   uint16_t n1_pucch = 0;
   uint16_t n2_pucch = 0;
   uint16_t n3_pucch = 20;
-  
   uint16_t n_rnti=0x1234;
-
   number_of_cards = 1;
-
   cpuf = get_cpu_freq_GHz();
 
   while ((c = getopt (argc, argv, "har:pf:g:n:s:S:x:y:z:N:F:T:R:")) != -1) {
     switch (c) {
-    case 'a':
-      printf("Running AWGN simulation\n");
-      channel_model = AWGN;
-      ntrials=1;
-      break;
-
-    case 'f':
-      if (atoi(optarg)==0)
-        pucch_format = pucch_format1;
-      else if (atoi(optarg)==1)
-        pucch_format = pucch_format1a;
-      else if (atoi(optarg)==2)
-        pucch_format = pucch_format1b;
-      else if (atoi(optarg)==6) // 3,4,5 is reserved for format2,2a,2b
-        pucch_format = pucch_format3;
-      else {
-        printf("Unsupported pucch_format %d\n",atoi(optarg));
-        exit(-1);
-      }
+      case 'a':
+        printf("Running AWGN simulation\n");
+        channel_model = AWGN;
+        ntrials=1;
+        break;
 
-      break;
+      case 'f':
+        if (atoi(optarg)==0)
+          pucch_format = pucch_format1;
+        else if (atoi(optarg)==1)
+          pucch_format = pucch_format1a;
+        else if (atoi(optarg)==2)
+          pucch_format = pucch_format1b;
+        else if (atoi(optarg)==6) // 3,4,5 is reserved for format2,2a,2b
+          pucch_format = pucch_format3;
+        else {
+          printf("Unsupported pucch_format %d\n",atoi(optarg));
+          exit(-1);
+        }
 
-    case 'g':
-      switch((char)*optarg) {
-      case 'A':
-        channel_model=SCM_A;
         break;
 
-      case 'B':
-        channel_model=SCM_B;
-        break;
+      case 'g':
+        switch((char)*optarg) {
+          case 'A':
+            channel_model=SCM_A;
+            break;
 
-      case 'C':
-        channel_model=SCM_C;
-        break;
+          case 'B':
+            channel_model=SCM_B;
+            break;
 
-      case 'D':
-        channel_model=SCM_D;
-        break;
+          case 'C':
+            channel_model=SCM_C;
+            break;
 
-      case 'E':
-        channel_model=EPA;
-        break;
+          case 'D':
+            channel_model=SCM_D;
+            break;
 
-      case 'F':
-        channel_model=EVA;
-        break;
+          case 'E':
+            channel_model=EPA;
+            break;
 
-      case 'G':
-        channel_model=ETU;
-        break;
+          case 'F':
+            channel_model=EVA;
+            break;
+
+          case 'G':
+            channel_model=ETU;
+            break;
+
+          case 'H':
+            channel_model=Rayleigh8;
+            break;
 
-      case 'H':
-        channel_model=Rayleigh8;
+          case 'I':
+            channel_model=Rayleigh1;
+            break;
 
-      case 'I':
-        channel_model=Rayleigh1;
+          case 'J':
+            channel_model=Rayleigh1_corr;
+            break;
 
-      case 'J':
-        channel_model=Rayleigh1_corr;
+          case 'K':
+            channel_model=Rayleigh1_anticorr;
+            break;
 
-      case 'K':
-        channel_model=Rayleigh1_anticorr;
+          case 'L':
+            channel_model=Rice8;
+            break;
 
-      case 'L':
-        channel_model=Rice8;
+          case 'M':
+            channel_model=Rice1;
+            break;
+
+          default:
+            printf("Unsupported channel model!\n");
+            exit(-1);
+        }
 
-      case 'M':
-        channel_model=Rice1;
         break;
 
-      default:
-        printf("Unsupported channel model!\n");
-        exit(-1);
-      }
+      case 'n':
+        n_frames = atoi(optarg);
+        break;
 
-      break;
+      case 's':
+        snr0 = atof(optarg);
+        printf("Setting SNR0 to %f\n",snr0);
+        break;
 
-    case 'n':
-      n_frames = atoi(optarg);
-      break;
+      case 'S':
+        snr1 = atof(optarg);
+        snr1set=1;
+        printf("Setting SNR1 to %f\n",snr1);
+        break;
 
-    case 's':
-      snr0 = atof(optarg);
-      printf("Setting SNR0 to %f\n",snr0);
-      break;
+      case 'p':
+        extended_prefix_flag=1;
+        break;
 
-    case 'S':
-      snr1 = atof(optarg);
-      snr1set=1;
-      printf("Setting SNR1 to %f\n",snr1);
-      break;
+      case 'r':
+        ricean_factor = pow(10,-.1*atof(optarg));
 
-    case 'p':
-      extended_prefix_flag=1;
-      break;
+        if (ricean_factor>1) {
+          printf("Ricean factor must be between 0 and 1\n");
+          exit(-1);
+        }
 
-    case 'r':
-      ricean_factor = pow(10,-.1*atof(optarg));
+        break;
 
-      if (ricean_factor>1) {
-        printf("Ricean factor must be between 0 and 1\n");
-        exit(-1);
-      }
+      case 'x':
+        transmission_mode=atoi(optarg);
 
-      break;
+        if ((transmission_mode!=1) &&
+            (transmission_mode!=2) &&
+            (transmission_mode!=6)) {
+          printf("Unsupported transmission mode %d\n",transmission_mode);
+          exit(-1);
+        }
 
-    case 'x':
-      transmission_mode=atoi(optarg);
+        break;
 
-      if ((transmission_mode!=1) &&
-          (transmission_mode!=2) &&
-          (transmission_mode!=6)) {
-        printf("Unsupported transmission mode %d\n",transmission_mode);
-        exit(-1);
-      }
+      case 'y':
+        n_tx=atoi(optarg);
 
-      break;
+        if ((n_tx==0) || (n_tx>2)) {
+          printf("Unsupported number of tx antennas %d\n",n_tx);
+          exit(-1);
+        }
 
-    case 'y':
-      n_tx=atoi(optarg);
+        break;
 
-      if ((n_tx==0) || (n_tx>2)) {
-        printf("Unsupported number of tx antennas %d\n",n_tx);
-        exit(-1);
-      }
+      case 'z':
+        n_rx=atoi(optarg);
 
-      break;
+        if ((n_rx==0) || (n_rx>2)) {
+          printf("Unsupported number of rx antennas %d\n",n_rx);
+          exit(-1);
+        }
 
-    case 'z':
-      n_rx=atoi(optarg);
+        break;
 
-      if ((n_rx==0) || (n_rx>2)) {
-        printf("Unsupported number of rx antennas %d\n",n_rx);
-        exit(-1);
-      }
+      case 'N':
+        N0 = atoi(optarg);
+        break;
+
+      case 'T':
+        pucch1_thres = atoi(optarg);
+        break;
+
+      case 'R':
+        N_RB_DL = atoi(optarg);
+        break;
 
-      break;
-
-    case 'N':
-      N0 = atoi(optarg);
-      break;
-
-    case 'T':
-      pucch1_thres = atoi(optarg);
-      break;
-
-    case 'R':
-      N_RB_DL = atoi(optarg);
-      break;
-
-    case 'O':
-      osf = atoi(optarg);
-      break;
-
-    case 'F':
-      break;
-
-    default:
-    case 'h':
-      printf("%s -h(elp) -a(wgn on) -p(extended_prefix) -N cell_id -f output_filename -F input_filename -g channel_model -n n_frames -t Delayspread -r Ricean_FactordB -s snr0 -S snr1 -x transmission_mode -y TXant -z RXant -N CellId\n",
-             argv[0]);
-      printf("-h This message\n");
-      printf("-a Use AWGN channel and not multipath\n");
-      printf("-p Use extended prefix mode\n");
-      printf("-n Number of frames to simulate\n");
-      printf("-r Ricean factor (dB, 0 means Rayleigh, 100 is almost AWGN\n");
-      printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB.  If n_frames is 1 then just SNR is simulated\n");
-      printf("-S Ending SNR, runs from SNR0 to SNR1\n");
-      printf("-t Delay spread for multipath channel\n");
-      printf("-g [A,B,C,D,E,F,G] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) models (ignores delay spread and Ricean factor)\n");
-      printf("-x Transmission mode (1,2,6 for the moment)\n");
-      printf("-y Number of TX antennas used in eNB\n");
-      printf("-z Number of RX antennas used in UE\n");
-      printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n");
-      printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n");
-      printf("-N Noise variance in dB\n");
-      printf("-R N_RB_DL\n");
-      printf("-O oversampling factor (1,2,4,8,16)\n");
-      printf("-f PUCCH format (0=1,1=1a,2=1b,6=3), formats 2/2a/2b not supported\n");
-      printf("-F Input filename (.txt format) for RX conformance testing\n");
-      exit (-1);
-      break;
+      case 'O':
+        osf = atoi(optarg);
+        break;
+
+      case 'F':
+        break;
+
+      default:
+      case 'h':
+        printf("%s -h(elp) -a(wgn on) -p(extended_prefix) -N cell_id -f output_filename -F input_filename -g channel_model -n n_frames -t Delayspread -r Ricean_FactordB -s snr0 -S snr1 -x transmission_mode -y TXant -z RXant -N CellId\n",
+               argv[0]);
+        printf("-h This message\n");
+        printf("-a Use AWGN channel and not multipath\n");
+        printf("-p Use extended prefix mode\n");
+        printf("-n Number of frames to simulate\n");
+        printf("-r Ricean factor (dB, 0 means Rayleigh, 100 is almost AWGN\n");
+        printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB.  If n_frames is 1 then just SNR is simulated\n");
+        printf("-S Ending SNR, runs from SNR0 to SNR1\n");
+        printf("-t Delay spread for multipath channel\n");
+        printf("-g [A,B,C,D,E,F,G] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) models (ignores delay spread and Ricean factor)\n");
+        printf("-x Transmission mode (1,2,6 for the moment)\n");
+        printf("-y Number of TX antennas used in eNB\n");
+        printf("-z Number of RX antennas used in UE\n");
+        printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n");
+        printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n");
+        printf("-N Noise variance in dB\n");
+        printf("-R N_RB_DL\n");
+        printf("-O oversampling factor (1,2,4,8,16)\n");
+        printf("-f PUCCH format (0=1,1=1a,2=1b,6=3), formats 2/2a/2b not supported\n");
+        printf("-F Input filename (.txt format) for RX conformance testing\n");
+        exit (-1);
+        break;
     }
   }
 
@@ -299,17 +292,16 @@ int main(int argc, char **argv)
 
   lte_param_init(n_tx,
                  n_tx,
-		 n_rx,
-		 transmission_mode,
-		 extended_prefix_flag,
-		 FDD,
-		 Nid_cell,
-		 3,
-		 N_RB_DL,
-		 0,
-		 osf,
-		 0);
-
+                 n_rx,
+                 transmission_mode,
+                 extended_prefix_flag,
+                 FDD,
+                 Nid_cell,
+                 3,
+                 N_RB_DL,
+                 0,
+                 osf,
+                 0);
 
   if (snr1set==0) {
     if (n_frames==1)
@@ -319,42 +311,30 @@ int main(int argc, char **argv)
   }
 
   printf("SNR0 %f, SNR1 %f\n",snr0,snr1);
-
   frame_parms = &eNB->frame_parms;
-
-
   txdata = eNB->common_vars.txdata[eNB_id];
-
   nsymb = (frame_parms->Ncp == 0) ? 14 : 12;
-
   printf("FFT Size %d, Extended Prefix %d, Samples per subframe %d, Symbols per subframe %d\n",NUMBER_OF_OFDM_CARRIERS,
          frame_parms->Ncp,frame_parms->samples_per_tti,nsymb);
-
-
-
   printf("[SIM] Using SCM/101\n");
   UE2eNB = new_channel_desc_scm(eNB->frame_parms.nb_antennas_tx,
                                 UE->frame_parms.nb_antennas_rx,
                                 channel_model,
- 				N_RB2sampling_rate(eNB->frame_parms.N_RB_UL),
-				N_RB2channel_bandwidth(eNB->frame_parms.N_RB_UL),
+                                N_RB2sampling_rate(eNB->frame_parms.N_RB_UL),
+                                N_RB2channel_bandwidth(eNB->frame_parms.N_RB_UL),
                                 0.0,
                                 0,
                                 0);
 
-
   if (UE2eNB==NULL) {
     printf("Problem generating channel model. Exiting.\n");
     exit(-1);
   }
 
   init_ncs_cell(&eNB->frame_parms,eNB->ncs_cell);
-
   init_ncs_cell(&UE->frame_parms,UE->ncs_cell);
-
   init_ul_hopping(&eNB->frame_parms);
   init_ul_hopping(&UE->frame_parms);
-
   eNB->frame_parms.pucch_config_common.deltaPUCCH_Shift = 2;
   eNB->frame_parms.pucch_config_common.nRB_CQI          = 4;
   eNB->frame_parms.pucch_config_common.nCS_AN           = 6;
@@ -362,40 +342,38 @@ int main(int argc, char **argv)
   UE->frame_parms.pucch_config_common.nRB_CQI          = 4;
   UE->frame_parms.pucch_config_common.nCS_AN           = 6;
 
-
-  if( (pucch_format == pucch_format1) || (pucch_format == pucch_format1a) || (pucch_format == pucch_format1b) ){
+  if( (pucch_format == pucch_format1) || (pucch_format == pucch_format1a) || (pucch_format == pucch_format1b) ) {
     pucch_payload = 0;
     generate_pucch1x(UE->common_vars.txdataF,
-  		   frame_parms,
-  		   UE->ncs_cell,
-  		   pucch_format,
-  		   &pucch_config_dedicated,
-  		   n1_pucch,
-  		   0, //shortened_format,
-  		   &pucch_payload,
-  		   AMP, //amp,
-  		   subframe); //subframe
-  }else if( pucch_format == pucch_format3){
-    for(i=0;i<pucch3_payload_size;i++)
+                     frame_parms,
+                     UE->ncs_cell,
+                     pucch_format,
+                     &pucch_config_dedicated,
+                     n1_pucch,
+                     0, //shortened_format,
+                     &pucch_payload,
+                     AMP, //amp,
+                     subframe); //subframe
+  } else if( pucch_format == pucch_format3) {
+    for(i=0; i<pucch3_payload_size; i++)
       pucch3_payload[i]=(uint8_t)(taus()&0x1);
+
     generate_pucch3x(UE->common_vars.txdataF,
-  		   frame_parms,
-  		   UE->ncs_cell,
-  		   pucch_format,
-  		   &pucch_config_dedicated,
-  		   n3_pucch,
-  		   0, //shortened_format,
-  		   pucch3_payload,
-  		   AMP, //amp,
-  		   subframe, //subframe
-         n_rnti);  //rnti
+                     frame_parms,
+                     UE->ncs_cell,
+                     pucch_format,
+                     &pucch_config_dedicated,
+                     n3_pucch,
+                     0, //shortened_format,
+                     pucch3_payload,
+                     AMP, //amp,
+                     subframe, //subframe
+                     n_rnti);  //rnti
   }
-  LOG_M("txsigF0.m","txsF0", &UE->common_vars.txdataF[0][2*subframe*nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES_NO_PREFIX],OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES_NO_PREFIX*nsymb,1,1);
 
+  LOG_M("txsigF0.m","txsF0", &UE->common_vars.txdataF[0][2*subframe*nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES_NO_PREFIX],OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES_NO_PREFIX*nsymb,1,1);
   tx_lev = 0;
 
-
-
   for (aa=0; aa<eNB->frame_parms.nb_antennas_tx; aa++) {
     if (frame_parms->Ncp == 1)
       PHY_ofdm_mod(&UE->common_vars.txdataF[aa][2*subframe*nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES_NO_PREFIX],        // input,
@@ -413,16 +391,12 @@ int main(int argc, char **argv)
       //apply_7_5_kHz(UE,UE->common_vars.txdata[aa],1+(subframe<<1));
       apply_7_5_kHz(UE,&txdata[aa][eNB->frame_parms.samples_per_tti*subframe],0);
       apply_7_5_kHz(UE,&txdata[aa][eNB->frame_parms.samples_per_tti*subframe],1);
-
-
     }
 
     tx_lev += signal_energy(&txdata[aa][subframe*eNB->frame_parms.samples_per_tti],
                             OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES);
   }
 
-
-
   LOG_M("txsig0.m","txs0", txdata[0], FRAME_LENGTH_COMPLEX_SAMPLES,1,1);
   //LOG_M("txsig1.m","txs1", txdata[1],FRAME_LENGTH_COMPLEX_SAMPLES,1,1);
 
@@ -435,28 +409,19 @@ int main(int argc, char **argv)
     }
   }
 
-
-
   for (SNR=snr0; SNR<snr1; SNR+=.2) {
-
     printf("n_frames %d SNR %f\n",n_frames,SNR);
-
     n_errors = 0;
     pucch_tx = 0;
     pucch1_missed=0;
     pucch1_false=0;
     pucch3_false=0;
-
     stat_no_sig = 0;
     stat_sig = 0;
 
     for (trial=0; trial<n_frames; trial++) {
-
-
-
       multipath_channel(UE2eNB,s_re,s_im,r_re,r_im,
                         eNB->frame_parms.samples_per_tti,0);
-
       sigma2_dB = N0;//10*log10((double)tx_lev) - SNR;
       tx_gain = sqrt(pow(10.0,.1*(N0+SNR))/(double)tx_lev);
 
@@ -478,11 +443,11 @@ int main(int argc, char **argv)
         sig=1;
       } else {
         if (trial<(n_frames>>1)) {
-	  //printf("no sig =>");
+          //printf("no sig =>");
           sig= 0;
         } else {
           sig=1;
-	  //printf("sig =>");
+          //printf("sig =>");
           pucch_tx++;
         }
       }
@@ -493,14 +458,11 @@ int main(int argc, char **argv)
         // fill measurement symbol (19) with noise
         for (i=0; i<OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES; i++) {
           for (aa=0; aa<eNB->frame_parms.nb_antennas_rx; aa++) {
-
-            ((short*) &eNB->common_vars.rxdata[0][aa][(frame_parms->samples_per_tti<<1) -frame_parms->ofdm_symbol_size])[2*i] = (short) ((sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
-            ((short*) &eNB->common_vars.rxdata[0][aa][(frame_parms->samples_per_tti<<1) -frame_parms->ofdm_symbol_size])[2*i+1] = (short) ((sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
+            ((short *) &eNB->common_vars.rxdata[0][aa][(frame_parms->samples_per_tti<<1) -frame_parms->ofdm_symbol_size])[2*i] = (short) ((sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
+            ((short *) &eNB->common_vars.rxdata[0][aa][(frame_parms->samples_per_tti<<1) -frame_parms->ofdm_symbol_size])[2*i+1] = (short) ((sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
           }
         }
 
-
-
         for (i=0; i<2*nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES; i++) {
           for (aa=0; aa<eNB->frame_parms.nb_antennas_rx; aa++) {
             if (n_trials==0) {
@@ -508,14 +470,12 @@ int main(int argc, char **argv)
               //    r_im[aa][i] += (pow(10.0,.05*interf1)*r_im1[aa][i] + pow(10.0,.05*interf2)*r_im2[aa][i]);
             }
 
-
             if (sig==1) {
-              ((short*) &eNB->common_vars.rxdata[0][aa][subframe*frame_parms->samples_per_tti])[2*i] = (short) (((tx_gain*r_re[aa][i]) +sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
-              ((short*) &eNB->common_vars.rxdata[0][aa][subframe*frame_parms->samples_per_tti])[2*i+1] = (short) (((tx_gain*r_im[aa][i]) + (iqim*r_re[aa][i]*tx_gain) + sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
+              ((short *) &eNB->common_vars.rxdata[0][aa][subframe*frame_parms->samples_per_tti])[2*i] = (short) (((tx_gain*r_re[aa][i]) +sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
+              ((short *) &eNB->common_vars.rxdata[0][aa][subframe*frame_parms->samples_per_tti])[2*i+1] = (short) (((tx_gain*r_im[aa][i]) + (iqim*r_re[aa][i]*tx_gain) + sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
             } else {
-              ((short*) &eNB->common_vars.rxdata[0][aa][subframe*frame_parms->samples_per_tti])[2*i] = (short) ((sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
-              ((short*) &eNB->common_vars.rxdata[0][aa][subframe*frame_parms->samples_per_tti])[2*i+1] = (short) ((sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
-
+              ((short *) &eNB->common_vars.rxdata[0][aa][subframe*frame_parms->samples_per_tti])[2*i] = (short) ((sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
+              ((short *) &eNB->common_vars.rxdata[0][aa][subframe*frame_parms->samples_per_tti])[2*i+1] = (short) ((sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
             }
           }
         }
@@ -524,7 +484,6 @@ int main(int argc, char **argv)
         remove_7_5_kHz(eNB,1+(subframe<<1));
 
         for (l=0; l<eNB->frame_parms.symbols_per_tti/2; l++) {
-
           slot_fep_ul(&eNB->frame_parms,
                       &eNB->common_vars,
                       l,
@@ -539,16 +498,13 @@ int main(int argc, char **argv)
                       0,
                       0
                      );
-
-
         }
 
-
         //      if (sig == 1)
         //    printf("*");
         lte_eNB_I0_measurements(eNB,
                                 subframe,
-				0,
+                                0,
                                 1);
         eNB->measurements[0].n0_power_tot_dB = N0;//(int8_t)(sigma2_dB-10*log10(eNB->frame_parms.ofdm_symbol_size/(12*NB_RB)));
         stat = rx_pucch(eNB,
@@ -580,9 +536,9 @@ int main(int argc, char **argv)
           }*/
         } else if( (pucch_format==pucch_format1a) || (pucch_format==pucch_format1b) ) {
           pucch1_false = (pucch_payload_rx != pucch_payload) ? (pucch1_false+1) : pucch1_false;
-        } else if (pucch_format==pucch_format3){
-          for(i=0;i<pucch3_payload_size;i++){
-            if(pucch3_payload[i]!=pucch3_payload_rx[i]){
+        } else if (pucch_format==pucch_format3) {
+          for(i=0; i<pucch3_payload_size; i++) {
+            if(pucch3_payload[i]!=pucch3_payload_rx[i]) {
               pucch3_false = (pucch3_false+1);
               break;
             }
@@ -611,11 +567,8 @@ int main(int argc, char **argv)
     LOG_M("rxsigF0.m","rxsF0", &eNB->common_vars.rxdataF[0][0][0],512*nsymb*2,2,1);
   }
 
-
   lte_sync_time_free();
-
   return(n_errors);
-
 }
 
 
diff --git a/openair1/SIMULATION/LTE_PHY/scansim.c b/openair1/SIMULATION/LTE_PHY/scansim.c
index cb419f57c248a5f7011a126639d831b118104a0b..5ceeee7f2f5d5d16575183e05cb2d5185186ed1e 100644
--- a/openair1/SIMULATION/LTE_PHY/scansim.c
+++ b/openair1/SIMULATION/LTE_PHY/scansim.c
@@ -38,7 +38,7 @@
 #include "LAYER2/MAC/vars.h"
 
 #ifdef XFORMS
-#include "PHY/TOOLS/lte_phy_scope.h"
+  #include "PHY/TOOLS/lte_phy_scope.h"
 #endif
 
 #include "OCG_vars.h"
@@ -58,11 +58,8 @@ mod_sym_t dummy2[2048*14];
 mod_sym_t dummy3[2048*14];
 
 
-int main(int argc, char **argv)
-{
-
+int main(int argc, char **argv) {
   char c;
-
   int i,l,aa;
   double sigma2, sigma2_dB=0,SNR,snr0=-2.0,snr1;
   uint8_t snr1set=0;
@@ -82,226 +79,192 @@ int main(int argc, char **argv)
   int trial, n_trials, ntrials=1, n_errors,n_errors2,n_alamouti;
   uint8_t transmission_mode = 1,n_tx=1,n_rx=1;
   uint16_t Nid_cell=0;
-
   int n_frames=1;
   channel_desc_t *eNB2UE,*eNB2UE1,*eNB2UE2;
   uint32_t nsymb,tx_lev,tx_lev1,tx_lev2;
   uint8_t extended_prefix_flag=0;
   LTE_DL_FRAME_PARMS *frame_parms;
-
   FILE *input_fd=NULL,*pbch_file_fd=NULL;
   char input_val_str[50],input_val_str2[50];
   //  double input_val1,input_val2;
   //  uint16_t amask=0;
   uint8_t frame_mod4,num_pdcch_symbols;
   uint16_t NB_RB=25;
-
   SCM_t channel_model=AWGN;//Rayleigh1_anticorr;
-
   DCI_ALLOC_t dci_alloc[8];
   uint8_t abstraction_flag=0;//,calibration_flag=0;
   int pbch_tx_ant;
   uint8_t N_RB_DL=100,osf=1;
-
   unsigned char frame_type = FDD;
   unsigned char pbch_phase = 0;
-
 #ifdef XFORMS
   FD_lte_phy_scope_ue *form_ue;
   char title[255];
 #endif
-
   logInit();
   number_of_cards = 1;
   openair_daq_vars.rx_rf_mode = 1;
 
-  /*
-    rxdataF    = (int **)malloc16(2*sizeof(int*));
-    rxdataF[0] = (int *)malloc16(FRAME_LENGTH_BYTES);
-    rxdataF[1] = (int *)malloc16(FRAME_LENGTH_BYTES);
-
-    rxdata    = (int **)malloc16(2*sizeof(int*));
-    rxdata[0] = (int *)malloc16(FRAME_LENGTH_BYTES);
-    rxdata[1] = (int *)malloc16(FRAME_LENGTH_BYTES);
-  */
   while ((c = getopt (argc, argv, "f:hpf:g:n:s:S:t:x:y:z:N:F:GdP:")) != -1) {
     switch (c) {
-    case 'f':
-      write_output_file=1;
-      output_fd = fopen(optarg,"w");
-
-      if (output_fd==NULL) {
-        printf("Error opening %s\n",optarg);
-        exit(-1);
-      }
+      case 'f':
+        write_output_file=1;
+        output_fd = fopen(optarg,"w");
 
-      break;
-
-    case 'd':
-      frame_type = TDD;
-      break;
+        if (output_fd==NULL) {
+          printf("Error opening %s\n",optarg);
+          exit(-1);
+        }
 
-    case 'g':
-      switch((char)*optarg) {
-      case 'A':
-        channel_model=SCM_A;
         break;
 
-      case 'B':
-        channel_model=SCM_B;
+      case 'd':
+        frame_type = TDD;
         break;
 
-      case 'C':
-        channel_model=SCM_C;
-        break;
+      case 'g':
+        switch((char)*optarg) {
+          case 'A':
+            channel_model=SCM_A;
+            break;
 
-      case 'D':
-        channel_model=SCM_D;
-        break;
+          case 'B':
+            channel_model=SCM_B;
+            break;
 
-      case 'E':
-        channel_model=EPA;
-        break;
+          case 'C':
+            channel_model=SCM_C;
+            break;
+
+          case 'D':
+            channel_model=SCM_D;
+            break;
+
+          case 'E':
+            channel_model=EPA;
+            break;
+
+          case 'F':
+            channel_model=EVA;
+            break;
+
+          case 'G':
+            channel_model=ETU;
+            break;
+
+          default:
+            msg("Unsupported channel model!\n");
+            exit(-1);
+        }
 
-      case 'F':
-        channel_model=EVA;
         break;
 
-      case 'G':
-        channel_model=ETU;
+      case 'n':
+        n_frames = atoi(optarg);
         break;
 
-      default:
-        msg("Unsupported channel model!\n");
-        exit(-1);
-      }
+      case 's':
+        snr0 = atof(optarg);
+        msg("Setting SNR0 to %f\n",snr0);
+        break;
 
-      break;
+      case 'S':
+        snr1 = atof(optarg);
+        snr1set=1;
+        msg("Setting SNR1 to %f\n",snr1);
+        break;
 
-    case 'n':
-      n_frames = atoi(optarg);
-      break;
+      case 'p':
+        extended_prefix_flag=1;
+        break;
 
-    case 's':
-      snr0 = atof(optarg);
-      msg("Setting SNR0 to %f\n",snr0);
-      break;
+      case 'x':
+        transmission_mode=atoi(optarg);
 
-    case 'S':
-      snr1 = atof(optarg);
-      snr1set=1;
-      msg("Setting SNR1 to %f\n",snr1);
-      break;
+        if ((transmission_mode!=1) &&
+            (transmission_mode!=2) &&
+            (transmission_mode!=6)) {
+          msg("Unsupported transmission mode %d\n",transmission_mode);
+          exit(-1);
+        }
 
-      /*
-        case 't':
-        Td= atof(optarg);
         break;
-      */
-    case 'p':
-      extended_prefix_flag=1;
-      break;
 
-      /*
-        case 'r':
-        ricean_factor = pow(10,-.1*atof(optarg));
-        if (ricean_factor>1) {
-        printf("Ricean factor must be between 0 and 1\n");
-        exit(-1);
+      case 'y':
+        n_tx=atoi(optarg);
+
+        if ((n_tx==0) || (n_tx>2)) {
+          msg("Unsupported number of tx antennas %d\n",n_tx);
+          exit(-1);
         }
-        break;
-      */
-    case 'x':
-      transmission_mode=atoi(optarg);
-
-      if ((transmission_mode!=1) &&
-          (transmission_mode!=2) &&
-          (transmission_mode!=6)) {
-        msg("Unsupported transmission mode %d\n",transmission_mode);
-        exit(-1);
-      }
 
-      break;
+        break;
 
-    case 'y':
-      n_tx=atoi(optarg);
+      case 'z':
+        n_rx=atoi(optarg);
 
-      if ((n_tx==0) || (n_tx>2)) {
-        msg("Unsupported number of tx antennas %d\n",n_tx);
-        exit(-1);
-      }
+        if ((n_rx==0) || (n_rx>2)) {
+          msg("Unsupported number of rx antennas %d\n",n_rx);
+          exit(-1);
+        }
 
-      break;
+        break;
 
-    case 'z':
-      n_rx=atoi(optarg);
+      case 'A':
+        abstraction_flag=1;
+        ntrials=10000;
+        msg("Running Abstraction test\n");
+        pbch_file_fd=fopen(optarg,"r");
+
+        if (pbch_file_fd==NULL) {
+          printf("Problem with filename %s\n",optarg);
+          exit(-1);
+        }
 
-      if ((n_rx==0) || (n_rx>2)) {
-        msg("Unsupported number of rx antennas %d\n",n_rx);
-        exit(-1);
-      }
+        break;
 
-      break;
+      case 'N':
+        Nid_cell = atoi(optarg);
+        break;
 
-    case 'A':
-      abstraction_flag=1;
-      ntrials=10000;
-      msg("Running Abstraction test\n");
-      pbch_file_fd=fopen(optarg,"r");
+      case 'F':
+        input_fd = fopen(optarg,"r");
 
-      if (pbch_file_fd==NULL) {
-        printf("Problem with filename %s\n",optarg);
-        exit(-1);
-      }
+        if (input_fd==NULL) {
+          printf("Problem with filename %s\n",optarg);
+          exit(-1);
+        }
 
-      break;
+        break;
 
-      //  case 'C':
-      //    calibration_flag=1;
-      //    msg("Running Abstraction calibration for Bias removal\n");
-      //    break;
-    case 'N':
-      Nid_cell = atoi(optarg);
-      break;
+      case 'P':
+        pbch_phase = atoi(optarg);
 
-    case 'F':
-      input_fd = fopen(optarg,"r");
+        if (pbch_phase>3)
+          printf("Illegal PBCH phase (0-3) got %d\n",pbch_phase);
 
-      if (input_fd==NULL) {
-        printf("Problem with filename %s\n",optarg);
-        exit(-1);
-      }
+        break;
 
-      break;
-
-    case 'P':
-      pbch_phase = atoi(optarg);
-
-      if (pbch_phase>3)
-        printf("Illegal PBCH phase (0-3) got %d\n",pbch_phase);
-
-      break;
-
-    default:
-    case 'h':
-      printf("%s -h(elp) -p(extended_prefix) -N cell_id -f output_filename -F input_filename -g channel_model -n n_frames -t Delayspread -s snr0 -S snr1 -x transmission_mode -y TXant -z RXant -N CellId\n",
-             argv[0]);
-      printf("-h This message\n");
-      printf("-p Use extended prefix mode\n");
-      printf("-d Use TDD\n");
-      printf("-n Number of frames to simulate\n");
-      printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB.  If n_frames is 1 then just SNR is simulated\n");
-      printf("-S Ending SNR, runs from SNR0 to SNR1\n");
-      printf("-t Delay spread for multipath channel\n");
-      printf("-g [A,B,C,D,E,F,G] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) models (ignores delay spread and Ricean factor)\n");
-      printf("-x Transmission mode (1,2,6 for the moment)\n");
-      printf("-y Number of TX antennas used in eNB\n");
-      printf("-z Number of RX antennas used in UE\n");
-      printf("-N Nid_cell\n");
-      printf("-f Output filename (.txt format) for Pe/SNR results\n");
-      printf("-F Input filename (.txt format) for RX conformance testing\n");
-      exit (-1);
-      break;
+      default:
+      case 'h':
+        printf("%s -h(elp) -p(extended_prefix) -N cell_id -f output_filename -F input_filename -g channel_model -n n_frames -t Delayspread -s snr0 -S snr1 -x transmission_mode -y TXant -z RXant -N CellId\n",
+               argv[0]);
+        printf("-h This message\n");
+        printf("-p Use extended prefix mode\n");
+        printf("-d Use TDD\n");
+        printf("-n Number of frames to simulate\n");
+        printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB.  If n_frames is 1 then just SNR is simulated\n");
+        printf("-S Ending SNR, runs from SNR0 to SNR1\n");
+        printf("-t Delay spread for multipath channel\n");
+        printf("-g [A,B,C,D,E,F,G] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) models (ignores delay spread and Ricean factor)\n");
+        printf("-x Transmission mode (1,2,6 for the moment)\n");
+        printf("-y Number of TX antennas used in eNB\n");
+        printf("-z Number of RX antennas used in UE\n");
+        printf("-N Nid_cell\n");
+        printf("-f Output filename (.txt format) for Pe/SNR results\n");
+        printf("-F Input filename (.txt format) for RX conformance testing\n");
+        exit (-1);
+        break;
     }
   }
 
@@ -309,16 +272,15 @@ int main(int argc, char **argv)
     n_tx=2;
 
   lte_param_init(n_tx,
-		 n_rx,
-		 transmission_mode,
-		 extended_prefix_flag,
-		 frame_type,
-		 Nid_cell,
-		 3,
-		 N_RB_DL,
-		 osf,
-		 0);
-
+                 n_rx,
+                 transmission_mode,
+                 extended_prefix_flag,
+                 frame_type,
+                 Nid_cell,
+                 3,
+                 N_RB_DL,
+                 osf,
+                 0);
 #ifdef XFORMS
   fl_initialize (&argc, argv, NULL, 0, 0);
   form_ue = create_lte_phy_scope_ue();
@@ -334,38 +296,27 @@ int main(int argc, char **argv)
   }
 
   printf("SNR0 %f, SNR1 %f\n",snr0,snr1);
-
   frame_parms = &PHY_vars_eNB->lte_frame_parms;
-
-
-
   txdata = PHY_vars_eNB->lte_eNB_common_vars.txdata[0];
   txdata1 = PHY_vars_eNB1->lte_eNB_common_vars.txdata[0];
   txdata2 = PHY_vars_eNB2->lte_eNB_common_vars.txdata[0];
-
-
-  s_re = malloc(2*sizeof(double*));
-  s_im = malloc(2*sizeof(double*));
-  s_re1 = malloc(2*sizeof(double*));
-  s_im1 = malloc(2*sizeof(double*));
-  s_re2 = malloc(2*sizeof(double*));
-  s_im2 = malloc(2*sizeof(double*));
-  r_re = malloc(2*sizeof(double*));
-  r_im = malloc(2*sizeof(double*));
-  r_re1 = malloc(2*sizeof(double*));
-  r_im1 = malloc(2*sizeof(double*));
-  r_re2 = malloc(2*sizeof(double*));
-  r_im2 = malloc(2*sizeof(double*));
-
+  s_re = malloc(2*sizeof(double *));
+  s_im = malloc(2*sizeof(double *));
+  s_re1 = malloc(2*sizeof(double *));
+  s_im1 = malloc(2*sizeof(double *));
+  s_re2 = malloc(2*sizeof(double *));
+  s_im2 = malloc(2*sizeof(double *));
+  r_re = malloc(2*sizeof(double *));
+  r_im = malloc(2*sizeof(double *));
+  r_re1 = malloc(2*sizeof(double *));
+  r_im1 = malloc(2*sizeof(double *));
+  r_re2 = malloc(2*sizeof(double *));
+  r_im2 = malloc(2*sizeof(double *));
   nsymb = (frame_parms->Ncp == 0) ? 14 : 12;
-
   printf("FFT Size %d, Extended Prefix %d, Samples per subframe %d, Symbols per subframe %d\n",NUMBER_OF_OFDM_CARRIERS,
          frame_parms->Ncp,frame_parms->samples_per_tti,nsymb);
-
   printf("PHY_vars_eNB1->lte_eNB_common_vars.txdataF[0][0] = %p\n",
          PHY_vars_eNB1->lte_eNB_common_vars.txdataF[0][0]);
-
-
   DLSCH_alloc_pdu2.rah              = 0;
   DLSCH_alloc_pdu2.rballoc          = DLSCH_RB_ALLOC;
   DLSCH_alloc_pdu2.TPC              = 0;
@@ -377,16 +328,14 @@ int main(int argc, char **argv)
   DLSCH_alloc_pdu2.rv1              = 0;
   // Forget second codeword
   DLSCH_alloc_pdu2.tpmi             = (transmission_mode==6 ? 5 : 0) ;  // precoding
-
   eNB2UE = new_channel_desc_scm(PHY_vars_eNB->lte_frame_parms.nb_antennas_tx,
-				PHY_vars_UE->lte_frame_parms.nb_antennas_rx,
-				channel_model,
-				N_RB2sampling_rate(PHY_vars_eNB->lte_frame_parms.N_RB_DL),
-				N_RB2channel_bandwidth(PHY_vars_eNB->lte_frame_parms.N_RB_DL),
-				0,
-				0,
-				0);
-
+                                PHY_vars_UE->lte_frame_parms.nb_antennas_rx,
+                                channel_model,
+                                N_RB2sampling_rate(PHY_vars_eNB->lte_frame_parms.N_RB_DL),
+                                N_RB2channel_bandwidth(PHY_vars_eNB->lte_frame_parms.N_RB_DL),
+                                0,
+                                0,
+                                0);
 
   if (eNB2UE==NULL) {
     msg("Problem generating channel model. Exiting.\n");
@@ -394,7 +343,6 @@ int main(int argc, char **argv)
   }
 
   for (i=0; i<2; i++) {
-
     s_re[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
     bzero(s_re[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
     s_im[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
@@ -407,7 +355,6 @@ int main(int argc, char **argv)
     bzero(s_re2[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
     s_im2[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
     bzero(s_im2[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
-
     r_re[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
     bzero(r_re[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
     r_im[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
@@ -450,9 +397,7 @@ int main(int argc, char **argv)
                  (PHY_vars_eNB->lte_frame_parms.Ncp==0) ? 5 : 4,
                  10);
     */
-
   } else {
-
     generate_sss(PHY_vars_eNB->lte_eNB_common_vars.txdataF[0],
                  AMP,
                  &PHY_vars_eNB->lte_frame_parms,
@@ -473,11 +418,8 @@ int main(int argc, char **argv)
                  &PHY_vars_eNB->lte_frame_parms,
                  2,
                  12);
-
-
   }
 
-
   /*
   generate_pilots(PHY_vars_eNB,
       PHY_vars_eNB->lte_eNB_common_vars.txdataF[0],
@@ -494,7 +436,6 @@ int main(int argc, char **argv)
      PHY_vars_eNB->lte_eNB_common_vars.txdataF[0],
      0);
   */
-
   /*
   if (num_pdcch_symbols<3) {
     printf("Less than 3 pdcch symbols\n");
@@ -530,9 +471,6 @@ int main(int argc, char **argv)
   tx_lev1 = 0;
   tx_lev2 = 0;
 
-
-
-
   for (aa=0; aa<PHY_vars_eNB->lte_frame_parms.nb_antennas_tx; aa++) {
     if (frame_parms->Ncp == 1)
       PHY_ofdm_mod(PHY_vars_eNB->lte_eNB_common_vars.txdataF[0][aa],        // input,
@@ -552,7 +490,6 @@ int main(int argc, char **argv)
                             OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES);
   }
 
-
   LOG_M("txsig0.m","txs0", txdata[0],FRAME_LENGTH_COMPLEX_SAMPLES,1,1);
 
   if (frame_parms->nb_antennas_tx>1)
@@ -567,19 +504,14 @@ int main(int argc, char **argv)
     }
   }
 
-
   for (SNR=snr0; SNR<snr1; SNR+=.2) {
-
-
     n_errors = 0;
     n_errors2 = 0;
     n_alamouti = 0;
 
     for (trial=0; trial<n_frames; trial++) {
-
       multipath_channel(eNB2UE,s_re,s_im,r_re,r_im,
                         2*nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES,0);
-
       sigma2_dB = 10*log10((double)tx_lev) +10*log10((double)PHY_vars_eNB->lte_frame_parms.ofdm_symbol_size/(double)(12*NB_RB)) - SNR;
 
       if (n_frames==1)
@@ -603,8 +535,8 @@ int main(int argc, char **argv)
         //printf("n_trial %d\n",n_trials);
         for (i=0; i<2*nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES; i++) {
           for (aa=0; aa<PHY_vars_eNB->lte_frame_parms.nb_antennas_rx; aa++) {
-            ((short*) PHY_vars_UE->lte_ue_common_vars.rxdata[aa])[2*i] = (short) ((r_re[aa][i] +sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
-            ((short*) PHY_vars_UE->lte_ue_common_vars.rxdata[aa])[2*i+1] = (short) ((r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
+            ((short *) PHY_vars_UE->lte_ue_common_vars.rxdata[aa])[2*i] = (short) ((r_re[aa][i] +sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
+            ((short *) PHY_vars_UE->lte_ue_common_vars.rxdata[aa])[2*i+1] = (short) ((r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
           }
         }
 
@@ -614,8 +546,6 @@ int main(int argc, char **argv)
           printf("rx_level data symbol %f\n",
                  10*log10(signal_energy(&PHY_vars_UE->lte_ue_common_vars.rxdata[0][frame_parms->samples_per_tti/2],4*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES)));
         }
-
-
       } //noise trials
     } // trials
 
@@ -629,30 +559,65 @@ int main(int argc, char **argv)
   } // NSR
 
   if (n_frames==1) {
-
   }
 
-
   for (i=0; i<2; i++) {
     free(s_re[i]);
     free(s_im[i]);
+
+    if (s_im1)
+      free(s_im1[i]);
+
+    if (s_im2)
+      free(s_im2[i]);
+
     free(r_re[i]);
+
+    if (r_re1)
+      free(r_re1[i]);
+
+    if (r_re2)
+      free(r_re2[i]);
+
     free(r_im[i]);
+
+    if (s_re1)
+      free(s_re1[i]);
+
+    if (s_re2)
+      free(s_re2[i]);
+
+    if (r_im1)
+      free(r_im1[i]);
+
+    if (r_im2)
+      free(r_im2[i]);
   }
 
   free(s_re);
+  free(s_re1);
+  free(s_re2);
   free(s_im);
+  free(s_im1);
+  free(s_im2);
   free(r_re);
+  free(r_re1);
+  free(r_re2);
   free(r_im);
-
-
+  free(r_im1);
+  free(r_im2);
   lte_sync_time_free();
 
   if (write_output_file)
     fclose(output_fd);
 
-  return(n_errors);
+  if (input_fd)
+    fclose(input_fd);
+
+  if (pbch_file_fd)
+    fclose(pbch_file_fd);
 
+  return(n_errors);
 }
 
 
diff --git a/openair1/SIMULATION/LTE_PHY/syncsim.c b/openair1/SIMULATION/LTE_PHY/syncsim.c
index 59116bc5e176ebf4565fd1bde7f2ff27148ba56b..2c0385efbfdcaa3c6de6ceceaef45e36d8b3728e 100644
--- a/openair1/SIMULATION/LTE_PHY/syncsim.c
+++ b/openair1/SIMULATION/LTE_PHY/syncsim.c
@@ -37,7 +37,7 @@
 #include "PHY/vars.h"
 #include "MAC_INTERFACE/vars.h"
 #ifdef IFFT_FPGA
-#include "PHY/LTE_REFSIG/mod_table.h"
+  #include "PHY/LTE_REFSIG/mod_table.h"
 #endif
 #include "SCHED/defs.h"
 #include "SCHED/vars.h"
@@ -47,8 +47,8 @@
 #include "LAYER2/MAC/vars.h"
 
 #ifdef XFORMS
-#include <forms.h>
-#include "../../USERSPACE_TOOLS/SCOPE/lte_scope.h"
+  #include <forms.h>
+  #include "../../USERSPACE_TOOLS/SCOPE/lte_scope.h"
 #endif //XFORMS
 
 
@@ -77,11 +77,8 @@ void do_forms2(FD_lte_scope *form,
                int16_t *dlsch_llr,
                int16_t *pbch_comp,
                int8_t *pbch_llr,
-               int coded_bits_per_codeword)
-{
-
+               int coded_bits_per_codeword) {
   int i,j,k,s;
-
   float Re,Im;
   float mag_sig[NB_ANTENNAS_RX*4*NUMBER_OF_OFDM_CARRIERS*NUMBER_OF_OFDM_SYMBOLS_PER_SLOT],
         sig_time[NB_ANTENNAS_RX*4*NUMBER_OF_OFDM_CARRIERS*NUMBER_OF_OFDM_SYMBOLS_PER_SLOT],
@@ -91,15 +88,11 @@ void do_forms2(FD_lte_scope *form,
         *llr,*llr_time;
   int ind;
   float avg, cum_avg;
-
-  extern int* sync_corr_ue0;
-
+  extern int *sync_corr_ue0;
   //  uint16_t nsymb = (frame_parms->Ncp == 0) ? 14 : 12;
-
   llr = malloc(max(coded_bits_per_codeword,1920)*sizeof(float));
   llr_time = malloc(max(coded_bits_per_codeword,1920)*sizeof(float));
 
-
   // Channel frequency response
   if (channel_f[0] != NULL) {
     cum_avg = 0;
@@ -122,7 +115,6 @@ void do_forms2(FD_lte_scope *form,
     }
 
     avg = cum_avg/NUMBER_OF_USEFUL_CARRIERS;
-
     //fl_set_xyplot_ybounds(form->channel_f,30,70);
     fl_set_xyplot_data(form->channel_f,sig_time,mag_sig,ind,"","","");
   }
@@ -196,7 +188,6 @@ void do_forms2(FD_lte_scope *form,
     //fl_set_xyplot_ybounds(form->scatter_plot,-100,100);
   }
 
-
   // PDCCH I/Q
   j=0;
 
@@ -210,7 +201,6 @@ void do_forms2(FD_lte_scope *form,
   //fl_set_xyplot_xbounds(form->scatter_plot,-100,100);
   //fl_set_xyplot_ybounds(form->scatter_plot,-100,100);
 
-
   // DLSCH LLR
   if (dlsch_llr != NULL) {
     for(i=0; i<coded_bits_per_codeword; i++) {
@@ -246,35 +236,25 @@ void do_forms2(FD_lte_scope *form,
     //fl_set_xyplot_ybounds(form->scatter_plot,-2000,2000);
   }
 
-
   free(llr);
   free(llr_time);
-
 }
 #endif
 
-void lte_param_init(unsigned char N_tx, unsigned char N_rx,unsigned char transmission_mode,unsigned char extended_prefix_flag,uint8_t frame_type,uint16_t Nid_cell,uint8_t N_RB_DL,uint8_t osf)
-{
-
+void lte_param_init(unsigned char N_tx, unsigned char N_rx,unsigned char transmission_mode,unsigned char extended_prefix_flag,uint8_t frame_type,uint16_t Nid_cell,uint8_t N_RB_DL,uint8_t osf) {
   LTE_DL_FRAME_PARMS *lte_frame_parms;
   int i;
-
   printf("Start lte_param_init, frame_type %d, extended_prefix %d\n",frame_type,extended_prefix_flag);
   PHY_vars_eNB = malloc(sizeof(PHY_VARS_eNB));
   PHY_vars_eNB1 = malloc(sizeof(PHY_VARS_eNB));
   PHY_vars_eNB2 = malloc(sizeof(PHY_VARS_eNB));
-
   PHY_vars_UE[0] = malloc(sizeof(PHY_VARS_UE));
   PHY_vars_UE[1] = malloc(sizeof(PHY_VARS_UE));
   //PHY_config = malloc(sizeof(PHY_CONFIG));
   mac_xface = malloc(sizeof(MAC_xface));
-
   randominit(0);
   set_taus_seed(0);
-
-
   lte_frame_parms = &(PHY_vars_eNB->lte_frame_parms);
-
   lte_frame_parms->N_RB_DL            = N_RB_DL;   //50 for 10MHz and 25 for 5 MHz
   lte_frame_parms->N_RB_UL            = N_RB_DL;
   lte_frame_parms->Ncp                = extended_prefix_flag;
@@ -292,63 +272,42 @@ void lte_param_init(unsigned char N_tx, unsigned char N_rx,unsigned char transmi
   lte_frame_parms->frame_type = frame_type;
   lte_frame_parms->node_id = 2;
   init_frame_parms(lte_frame_parms,osf);
-
-
-
-
   phy_init_top(lte_frame_parms); //allocation
-
   lte_frame_parms->twiddle_fft      = twiddle_fft;
   lte_frame_parms->twiddle_ifft     = twiddle_ifft;
   lte_frame_parms->rev              = rev;
-
   phy_init_lte_top(lte_frame_parms);
-
-  memcpy((void*)&PHY_vars_UE[0]->lte_frame_parms,(void*)&PHY_vars_eNB->lte_frame_parms,sizeof(LTE_DL_FRAME_PARMS));
-  memcpy((void*)&PHY_vars_UE[1]->lte_frame_parms,(void*)&PHY_vars_eNB->lte_frame_parms,sizeof(LTE_DL_FRAME_PARMS));
-
+  memcpy((void *)&PHY_vars_UE[0]->lte_frame_parms,(void *)&PHY_vars_eNB->lte_frame_parms,sizeof(LTE_DL_FRAME_PARMS));
+  memcpy((void *)&PHY_vars_UE[1]->lte_frame_parms,(void *)&PHY_vars_eNB->lte_frame_parms,sizeof(LTE_DL_FRAME_PARMS));
   phy_init_lte_ue(PHY_vars_UE[0],1,0);
 
   for (i=0; i<3; i++)
     lte_gold(lte_frame_parms,PHY_vars_UE[0]->lte_gold_table[i],i);
 
   PHY_vars_UE[0]->Mod_id = 0;
-
   phy_init_lte_ue(PHY_vars_UE[1],1,0);
 
   for (i=0; i<3; i++)
     lte_gold(lte_frame_parms,PHY_vars_UE[1]->lte_gold_table[i],i);
 
   PHY_vars_UE[1]->Mod_id = 1;
-
   phy_init_lte_eNB(PHY_vars_eNB,0,0,0);
-
-  memcpy((void*)&PHY_vars_eNB1->lte_frame_parms,(void*)&PHY_vars_eNB->lte_frame_parms,sizeof(LTE_DL_FRAME_PARMS));
+  memcpy((void *)&PHY_vars_eNB1->lte_frame_parms,(void *)&PHY_vars_eNB->lte_frame_parms,sizeof(LTE_DL_FRAME_PARMS));
   PHY_vars_eNB1->lte_frame_parms.nushift=1;
   PHY_vars_eNB1->lte_frame_parms.Nid_cell=2;
-
-  memcpy((void*)&PHY_vars_eNB2->lte_frame_parms,(void*)&PHY_vars_eNB->lte_frame_parms,sizeof(LTE_DL_FRAME_PARMS));
+  memcpy((void *)&PHY_vars_eNB2->lte_frame_parms,(void *)&PHY_vars_eNB->lte_frame_parms,sizeof(LTE_DL_FRAME_PARMS));
   PHY_vars_eNB2->lte_frame_parms.nushift=2;
   PHY_vars_eNB2->lte_frame_parms.Nid_cell=3;
-
   phy_init_lte_eNB(PHY_vars_eNB1,0,0,0);
-
   phy_init_lte_eNB(PHY_vars_eNB2,0,0,0);
-
   phy_init_lte_top(lte_frame_parms);
-
   printf("Done lte_param_init\n");
-
-
 }
 
 
 
-int main(int argc, char **argv)
-{
-
+int main(int argc, char **argv) {
   char c;
-
   int i,iout,l,aa,aarx;
   double sigma2, sigma2_dB=0,SNR,snr0=10.0,snr1=11.0;
   uint8_t snr1set=0;
@@ -373,26 +332,19 @@ int main(int argc, char **argv)
   uint8_t extended_prefix_flag=0,frame_type=1;
   int8_t interf1=-21,interf2=-21;
   LTE_DL_FRAME_PARMS *frame_parms;
-
   FILE *input_fd=NULL,*pbch_file_fd=NULL;
   char input_val_str[50],input_val_str2[50];
   uint8_t num_pdcch_symbols=1;
   uint16_t NB_RB=25;
-
   SCM_t channel_model=Rayleigh8;
-
   uint8_t abstraction_flag=0;
   double pbch_sinr;
   uint8_t N_RB_DL=25,osf=1;
-
   int openair_fd=(int)0;
   int tcxo=74,fc=0;
   unsigned char temp[4];
-
   int oai_hw_input=0;
   int oai_hw_output=0;
-
-
   DCI_ALLOC_t dci_alloc[8],dci_alloc_rx[8];
   uint16_t n_rnti=1234,dci_cnt;
   unsigned int coded_bits_per_codeword;
@@ -406,21 +358,16 @@ int main(int argc, char **argv)
   uint32_t rxgain[4]= {30,30,30,30};
   uint32_t do_forms=0;
   int ret;
-
 #ifdef XFORMS
   FD_lte_scope *form_dl=NULL;
   FD_lte_scope *form_dl1=NULL;
   char title[255];
 #endif
-
   int UE_idx,N_carriers=1,subframe=2;
   int dual_stream_flag=0;
   unsigned char i_mod = 2;
-
   int rx_offset_mod;
-
   logInit();
-
   number_of_cards = 1;
   openair_daq_vars.rx_rf_mode = 1;
 
@@ -435,141 +382,141 @@ int main(int argc, char **argv)
   */
   while ((c = getopt (argc, argv, "aehc:f:g:i:j:n:r:s:t:x:y:z:A:F:N:O:R:S:ZYDT:C:G:dB:U:u")) != -1) {
     switch (c) {
-    case 'a':
-      printf("Running AWGN simulation\n");
-      awgn_flag = 1;
-      break;
-
-    case 'f':
-      output_fd = fopen(optarg,"w");
-      write_output_file=1;
-      break;
-
-    case 'g':
-      switch((char)*optarg) {
-      case 'A':
-        channel_model=SCM_A;
+      case 'a':
+        printf("Running AWGN simulation\n");
+        awgn_flag = 1;
         break;
 
-      case 'B':
-        channel_model=SCM_B;
+      case 'f':
+        output_fd = fopen(optarg,"w");
+        write_output_file=1;
         break;
 
-      case 'C':
-        channel_model=SCM_C;
-        break;
+      case 'g':
+        switch((char)*optarg) {
+          case 'A':
+            channel_model=SCM_A;
+            break;
 
-      case 'D':
-        channel_model=SCM_D;
-        break;
+          case 'B':
+            channel_model=SCM_B;
+            break;
 
-      case 'E':
-        channel_model=EPA;
-        break;
+          case 'C':
+            channel_model=SCM_C;
+            break;
 
-      case 'F':
-        channel_model=EVA;
-        break;
+          case 'D':
+            channel_model=SCM_D;
+            break;
 
-      case 'G':
-        channel_model=ETU;
-        break;
+          case 'E':
+            channel_model=EPA;
+            break;
 
-      default:
-        msg("Unsupported channel model!\n");
-        exit(-1);
-      }
+          case 'F':
+            channel_model=EVA;
+            break;
 
-      break;
+          case 'G':
+            channel_model=ETU;
+            break;
 
-    case 'C':
-      sscanf(optarg,"%d,%d,%d,%d",&carrier_freq[0],&carrier_freq[1],&carrier_freq[2],&carrier_freq[3]);
-      printf("Configuring for frequencies %d,%d,%d,%d\n",carrier_freq[0],carrier_freq[1],carrier_freq[2],carrier_freq[3]);
-      //carrier_freq = atoi(optarg);
-      break;
+          default:
+            msg("Unsupported channel model!\n");
+            exit(-1);
+        }
 
-    case 'G':
-      sscanf(optarg,"%d,%d,%d,%d",&rxgain[0],&rxgain[1],&rxgain[2],&rxgain[3]);
-      printf("Configuring for gains %d,%d,%d,%d\n",rxgain[0],rxgain[1],rxgain[2],rxgain[3]);
-      //rxgain = atoi(optarg);
-      break;
+        break;
 
-    case 'i':
-      interf1=atoi(optarg);
-      break;
+      case 'C':
+        sscanf(optarg,"%d,%d,%d,%d",&carrier_freq[0],&carrier_freq[1],&carrier_freq[2],&carrier_freq[3]);
+        printf("Configuring for frequencies %d,%d,%d,%d\n",carrier_freq[0],carrier_freq[1],carrier_freq[2],carrier_freq[3]);
+        //carrier_freq = atoi(optarg);
+        break;
 
-    case 'c':
-      deltaF=atof(optarg);
-      break;
+      case 'G':
+        sscanf(optarg,"%d,%d,%d,%d",&rxgain[0],&rxgain[1],&rxgain[2],&rxgain[3]);
+        printf("Configuring for gains %d,%d,%d,%d\n",rxgain[0],rxgain[1],rxgain[2],rxgain[3]);
+        //rxgain = atoi(optarg);
+        break;
 
-    case 'j':
-      interf2=atoi(optarg);
-      break;
+      case 'i':
+        interf1=atoi(optarg);
+        break;
 
-    case 'n':
-      n_frames = atoi(optarg);
-      break;
+      case 'c':
+        deltaF=atof(optarg);
+        break;
 
-    case 's':
-      snr0 = atof(optarg);
-      msg("Setting SNR0 to %f\n",snr0);
-      break;
+      case 'j':
+        interf2=atoi(optarg);
+        break;
 
-    case 'S':
-      snr1 = atof(optarg);
-      snr1set=1;
-      msg("Setting SNR1 to %f\n",snr1);
-      break;
+      case 'n':
+        n_frames = atoi(optarg);
+        break;
+
+      case 's':
+        snr0 = atof(optarg);
+        msg("Setting SNR0 to %f\n",snr0);
+        break;
+
+      case 'S':
+        snr1 = atof(optarg);
+        snr1set=1;
+        msg("Setting SNR1 to %f\n",snr1);
+        break;
 
       /*
       case 't':
       Td= atof(optarg);
       break;
       */
-    case 'e':
-      extended_prefix_flag=1;
-      break;
+      case 'e':
+        extended_prefix_flag=1;
+        break;
 
-    case 'd':
-      do_forms=1;
-      break;
+      case 'd':
+        do_forms=1;
+        break;
 
-    case 'r':
-      n_rnti=atoi(optarg);
-      break;
+      case 'r':
+        n_rnti=atoi(optarg);
+        break;
 
-    case 'x':
-      transmission_mode=atoi(optarg);
+      case 'x':
+        transmission_mode=atoi(optarg);
 
-      if ((transmission_mode!=1) &&
-          (transmission_mode!=2) &&
-          (transmission_mode!=5) &&
-          (transmission_mode!=6)) {
-        msg("Unsupported transmission mode %d\n",transmission_mode);
-        exit(-1);
-      }
+        if ((transmission_mode!=1) &&
+            (transmission_mode!=2) &&
+            (transmission_mode!=5) &&
+            (transmission_mode!=6)) {
+          msg("Unsupported transmission mode %d\n",transmission_mode);
+          exit(-1);
+        }
 
-      break;
+        break;
 
-    case 'y':
-      n_tx=atoi(optarg);
+      case 'y':
+        n_tx=atoi(optarg);
 
-      if ((n_tx==0) || (n_tx>2)) {
-        msg("Unsupported number of tx antennas %d\n",n_tx);
-        exit(-1);
-      }
+        if ((n_tx==0) || (n_tx>2)) {
+          msg("Unsupported number of tx antennas %d\n",n_tx);
+          exit(-1);
+        }
 
-      break;
+        break;
 
-    case 'z':
-      n_rx=atoi(optarg);
+      case 'z':
+        n_rx=atoi(optarg);
 
-      if ((n_rx==0) || (n_rx>2)) {
-        msg("Unsupported number of rx antennas %d\n",n_rx);
-        exit(-1);
-      }
+        if ((n_rx==0) || (n_rx>2)) {
+          msg("Unsupported number of rx antennas %d\n",n_rx);
+          exit(-1);
+        }
 
-      break;
+        break;
 
       /*
       case 'A':
@@ -583,96 +530,96 @@ int main(int argc, char **argv)
       }
       break;
       */
-    case 'D':
-      frame_type=0;
-      msg("Running in FDD\n");
-      break;
+      case 'D':
+        frame_type=0;
+        msg("Running in FDD\n");
+        break;
 
-    case 'N':
-      Nid_cell = atoi(optarg);
-      break;
+      case 'N':
+        Nid_cell = atoi(optarg);
+        break;
 
-    case 'R':
-      N_RB_DL = atoi(optarg);
-      break;
+      case 'R':
+        N_RB_DL = atoi(optarg);
+        break;
 
-    case 'O':
-      osf = atoi(optarg);
-      break;
+      case 'O':
+        osf = atoi(optarg);
+        break;
 
-    case 'Z':
-      oai_hw_input = 1;
-      break;
+      case 'Z':
+        oai_hw_input = 1;
+        break;
 
-    case 'Y':
-      oai_hw_output = 1;
-      break;
+      case 'Y':
+        oai_hw_output = 1;
+        break;
 
-    case 'F':
-      input_fd = fopen(optarg,"r");
+      case 'F':
+        input_fd = fopen(optarg,"r");
 
-      if (input_fd==NULL) {
-        printf("Problem with filename %s\n",optarg);
-        exit(-1);
-      }
+        if (input_fd==NULL) {
+          printf("Problem with filename %s\n",optarg);
+          exit(-1);
+        }
 
-      break;
+        break;
 
-    case 'T':
-      tcxo = atoi(optarg);
-      break;
+      case 'T':
+        tcxo = atoi(optarg);
+        break;
 
-    case 'B':
-      N_carriers = atoi(optarg);
+      case 'B':
+        N_carriers = atoi(optarg);
 
-      if ((N_carriers!=1) && (N_carriers!=2)) {
-        printf("N_carriers must be 1 or 2!\n");
-        exit(-1);
-      }
+        if ((N_carriers!=1) && (N_carriers!=2)) {
+          printf("N_carriers must be 1 or 2!\n");
+          exit(-1);
+        }
 
-      break;
+        break;
 
-    case 'U':
-      subframe = atoi(optarg);
-      break;
+      case 'U':
+        subframe = atoi(optarg);
+        break;
 
-    case 'u':
-      dual_stream_flag=1;
-      break;
+      case 'u':
+        dual_stream_flag=1;
+        break;
 
-    default:
-    case 'h':
-      printf("-h This message\n");
-      printf("-a Use AWGN channel and not multipath\n");
-      printf("-e Use extended prefix mode\n");
-      printf("-d Display signal output on XFORMS scope\n");
-      printf("-D Use FDD frame\n");
-      printf("-n Number of frames to simulate\n");
-      printf("-r RNTI for DCI detection in SF 0/5\n");
-      printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB.  If n_frames is 1 then just SNR is simulated\n");
-      printf("-S Ending SNR, runs from SNR0 to SNR1\n");
-      printf("-t Delay spread for multipath channel\n");
-      printf("-g [A,B,C,D,E,F,G] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) models (ignores delay spread and Ricean factor)\n");
-      printf("-c Frequency offset\n");
-      printf("-x Transmission mode (1,2,6 for the moment)\n");
-      printf("-y Number of TX antennas used in eNB\n");
-      printf("-z Number of RX antennas used in UE\n");
-      printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n");
-      printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n");
-      printf("-N Nid_cell\n");
-      printf("-R N_RB_DL\n");
-      printf("-O oversampling factor (1,2,4,8,16)\n");
-      //printf("-A Interpolation_filname Run with Abstraction to generate Scatter plot using interpolation polynomial in file\n");
-      printf("-f Output filename (.txt format) for Pe/SNR results\n");
-      printf("-F Input filename (.txt format) for RX conformance testing\n");
-      printf("-Y just generate tx frame and send it to hardware\n");
-      printf("-Z grab frame from hardware and do rx processing\n");
-      printf("-T set TCXO parameter on CBMIMO1 hardware\n");
-      printf("-C set frequency for ExpressMIMO hardware. Can take up to four parameters in format f1,f2,f3,f4\n");
-      printf("-G set RX gain for ExpressMIMO hardware. Can take up to four parameters in format g1,g2,g3,g4\n");
-      printf("-d enables the graphical display");
-      exit (-1);
-      break;
+      default:
+      case 'h':
+        printf("-h This message\n");
+        printf("-a Use AWGN channel and not multipath\n");
+        printf("-e Use extended prefix mode\n");
+        printf("-d Display signal output on XFORMS scope\n");
+        printf("-D Use FDD frame\n");
+        printf("-n Number of frames to simulate\n");
+        printf("-r RNTI for DCI detection in SF 0/5\n");
+        printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB.  If n_frames is 1 then just SNR is simulated\n");
+        printf("-S Ending SNR, runs from SNR0 to SNR1\n");
+        printf("-t Delay spread for multipath channel\n");
+        printf("-g [A,B,C,D,E,F,G] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) models (ignores delay spread and Ricean factor)\n");
+        printf("-c Frequency offset\n");
+        printf("-x Transmission mode (1,2,6 for the moment)\n");
+        printf("-y Number of TX antennas used in eNB\n");
+        printf("-z Number of RX antennas used in UE\n");
+        printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n");
+        printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n");
+        printf("-N Nid_cell\n");
+        printf("-R N_RB_DL\n");
+        printf("-O oversampling factor (1,2,4,8,16)\n");
+        //printf("-A Interpolation_filname Run with Abstraction to generate Scatter plot using interpolation polynomial in file\n");
+        printf("-f Output filename (.txt format) for Pe/SNR results\n");
+        printf("-F Input filename (.txt format) for RX conformance testing\n");
+        printf("-Y just generate tx frame and send it to hardware\n");
+        printf("-Z grab frame from hardware and do rx processing\n");
+        printf("-T set TCXO parameter on CBMIMO1 hardware\n");
+        printf("-C set frequency for ExpressMIMO hardware. Can take up to four parameters in format f1,f2,f3,f4\n");
+        printf("-G set RX gain for ExpressMIMO hardware. Can take up to four parameters in format g1,g2,g3,g4\n");
+        printf("-d enables the graphical display");
+        exit (-1);
+        break;
     }
   }
 
@@ -707,7 +654,6 @@ int main(int argc, char **argv)
   }
 
   printf("SNR0 %f, SNR1 %f\n",snr0,snr1);
-
   frame_parms = &PHY_vars_eNB->lte_frame_parms;
   frame_parms->dual_tx      = 0;
   frame_parms->freq_idx     = 0;
@@ -738,22 +684,18 @@ int main(int argc, char **argv)
   if ((oai_hw_input==1) ||
       (oai_hw_output==1)) {
     msg("setting TCXO to %d\n",tcxo);
-
     ioctl(openair_fd,openair_SET_TCXO_DAC,(void *)&tcxo);
   }
 
 #ifdef IFFT_FPGA
-  txdata    = (int **)malloc16(2*sizeof(int*));
+  txdata    = (int **)malloc16(2*sizeof(int *));
   txdata[0] = (int *)malloc16(FRAME_LENGTH_BYTES);
   txdata[1] = (int *)malloc16(FRAME_LENGTH_BYTES);
-
   bzero(txdata[0],FRAME_LENGTH_BYTES);
   bzero(txdata[1],FRAME_LENGTH_BYTES);
-
-  txdataF2    = (int **)malloc16(2*sizeof(int*));
+  txdataF2    = (int **)malloc16(2*sizeof(int *));
   txdataF2[0] = (int *)malloc16(FRAME_LENGTH_BYTES_NO_PREFIX);
   txdataF2[1] = (int *)malloc16(FRAME_LENGTH_BYTES_NO_PREFIX);
-
   bzero(txdataF2[0],FRAME_LENGTH_BYTES_NO_PREFIX);
   bzero(txdataF2[1],FRAME_LENGTH_BYTES_NO_PREFIX);
 #else
@@ -761,26 +703,21 @@ int main(int argc, char **argv)
   txdata1 = PHY_vars_eNB1->lte_eNB_common_vars.txdata[eNb_id];
   txdata2 = PHY_vars_eNB2->lte_eNB_common_vars.txdata[eNb_id];
 #endif
-
-  s_re = malloc(2*sizeof(double*));
-  s_im = malloc(2*sizeof(double*));
-  s_re1 = malloc(2*sizeof(double*));
-  s_im1 = malloc(2*sizeof(double*));
-  s_re2 = malloc(2*sizeof(double*));
-  s_im2 = malloc(2*sizeof(double*));
-  r_re = malloc(2*sizeof(double*));
-  r_im = malloc(2*sizeof(double*));
-  r_re1 = malloc(2*sizeof(double*));
-  r_im1 = malloc(2*sizeof(double*));
-  r_re2 = malloc(2*sizeof(double*));
-  r_im2 = malloc(2*sizeof(double*));
-
+  s_re = malloc(2*sizeof(double *));
+  s_im = malloc(2*sizeof(double *));
+  s_re1 = malloc(2*sizeof(double *));
+  s_im1 = malloc(2*sizeof(double *));
+  s_re2 = malloc(2*sizeof(double *));
+  s_im2 = malloc(2*sizeof(double *));
+  r_re = malloc(2*sizeof(double *));
+  r_im = malloc(2*sizeof(double *));
+  r_re1 = malloc(2*sizeof(double *));
+  r_im1 = malloc(2*sizeof(double *));
+  r_re2 = malloc(2*sizeof(double *));
+  r_im2 = malloc(2*sizeof(double *));
   nsymb = (frame_parms->Ncp == 0) ? 14 : 12;
-
   printf("FFT Size %d, Extended Prefix %d, Samples per subframe %d, Symbols per subframe %d\n",NUMBER_OF_OFDM_CARRIERS,
          frame_parms->Ncp,frame_parms->samples_per_tti,nsymb);
-
-
   eNB2UE = new_channel_desc_scm(PHY_vars_eNB->lte_frame_parms.nb_antennas_tx,
                                 PHY_vars_UE[0]->lte_frame_parms.nb_antennas_rx,
                                 channel_model,
@@ -807,14 +744,12 @@ int main(int argc, char **argv)
                                    0,
                                    0);
 
-
   if (eNB2UE==NULL) {
     msg("Problem generating channel model. Exiting.\n");
     exit(-1);
   }
 
   for (i=0; i<2; i++) {
-
     s_re[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
     bzero(s_re[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
     s_im[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
@@ -827,7 +762,6 @@ int main(int argc, char **argv)
     bzero(s_re2[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
     s_im2[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
     bzero(s_im2[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
-
     r_re[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
     bzero(r_re[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
     r_im[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
@@ -867,69 +801,67 @@ int main(int argc, char **argv)
   //    load_pbch_desc(pbch_file_fd);
   //  }
 
-
   if ((input_fd==NULL)&&(oai_hw_input==0)) {
-
     //    for (i=0;i<6;i++)
     //      pbch_pdu[i] = i;
     //pbch_pdu[0]=100;
     //pbch_pdu[1]=1;
     //pbch_pdu[2]=0;
-    ((uint8_t*) pbch_pdu)[0] = 0;
+    ((uint8_t *) pbch_pdu)[0] = 0;
 
     switch (PHY_vars_eNB->lte_frame_parms.N_RB_DL) {
-    case 6:
-      ((uint8_t*) pbch_pdu)[0] = (((uint8_t*) pbch_pdu)[0]&0x1f) | (0<<5);
-      break;
+      case 6:
+        ((uint8_t *) pbch_pdu)[0] = (((uint8_t *) pbch_pdu)[0]&0x1f) | (0<<5);
+        break;
 
-    case 15:
-      ((uint8_t*) pbch_pdu)[0] = (((uint8_t*) pbch_pdu)[0]&0x1f) | (1<<5);
-      break;
+      case 15:
+        ((uint8_t *) pbch_pdu)[0] = (((uint8_t *) pbch_pdu)[0]&0x1f) | (1<<5);
+        break;
 
-    case 25:
-      ((uint8_t*) pbch_pdu)[0] = (((uint8_t*) pbch_pdu)[0]&0x1f) | (2<<5);
-      break;
+      case 25:
+        ((uint8_t *) pbch_pdu)[0] = (((uint8_t *) pbch_pdu)[0]&0x1f) | (2<<5);
+        break;
 
-    case 50:
-      ((uint8_t*) pbch_pdu)[0] = (((uint8_t*) pbch_pdu)[0]&0x1f) | (3<<5);
-      break;
+      case 50:
+        ((uint8_t *) pbch_pdu)[0] = (((uint8_t *) pbch_pdu)[0]&0x1f) | (3<<5);
+        break;
 
-    case 100:
-      ((uint8_t*) pbch_pdu)[0] = (((uint8_t*) pbch_pdu)[0]&0x1f) | (4<<5);
-      break;
+      case 100:
+        ((uint8_t *) pbch_pdu)[0] = (((uint8_t *) pbch_pdu)[0]&0x1f) | (4<<5);
+        break;
 
-    default:
-      ((uint8_t*) pbch_pdu)[0] = (((uint8_t*) pbch_pdu)[0]&0x1f) | (2<<5);
-      break;
+      default:
+        ((uint8_t *) pbch_pdu)[0] = (((uint8_t *) pbch_pdu)[0]&0x1f) | (2<<5);
+        break;
     }
 
-    ((uint8_t*) pbch_pdu)[0] = (((uint8_t*) pbch_pdu)[0]&0xef) |
-                               ((PHY_vars_eNB->lte_frame_parms.phich_config_common.phich_duration << 4)&0x10);
+    ((uint8_t *) pbch_pdu)[0] = (((uint8_t *) pbch_pdu)[0]&0xef) |
+                                ((PHY_vars_eNB->lte_frame_parms.phich_config_common.phich_duration << 4)&0x10);
 
     switch (PHY_vars_eNB->lte_frame_parms.phich_config_common.phich_resource) {
-    case oneSixth:
-      ((uint8_t*) pbch_pdu)[0] = (((uint8_t*) pbch_pdu)[0]&0xf3) | (0<<3);
-      break;
+      case oneSixth:
+        ((uint8_t *) pbch_pdu)[0] = (((uint8_t *) pbch_pdu)[0]&0xf3) | (0<<3);
+        break;
 
-    case half:
-      ((uint8_t*) pbch_pdu)[0] = (((uint8_t*) pbch_pdu)[0]&0xf3) | (1<<3);
-      break;
+      case half:
+        ((uint8_t *) pbch_pdu)[0] = (((uint8_t *) pbch_pdu)[0]&0xf3) | (1<<3);
+        break;
 
-    case one:
-      ((uint8_t*) pbch_pdu)[0] = (((uint8_t*) pbch_pdu)[0]&0xf3) | (2<<3);
-      break;
+      case one:
+        ((uint8_t *) pbch_pdu)[0] = (((uint8_t *) pbch_pdu)[0]&0xf3) | (2<<3);
+        break;
 
-    case two:
-      ((uint8_t*) pbch_pdu)[0] = (((uint8_t*) pbch_pdu)[0]&0xf3) | (3<<3);
-      break;
+      case two:
+        ((uint8_t *) pbch_pdu)[0] = (((uint8_t *) pbch_pdu)[0]&0xf3) | (3<<3);
+        break;
 
-    default:
-      break;
+      default:
+        break;
     }
 
-    ((uint8_t*) pbch_pdu)[0] = (((uint8_t*) pbch_pdu)[0]&0xfc) | ((PHY_vars_eNB->frame>>8)&0x3);
-    ((uint8_t*) pbch_pdu)[1] = PHY_vars_eNB->frame&0xfc;
-    ((uint8_t*) pbch_pdu)[2] = 0;
+    ((uint8_t *) pbch_pdu)[0] = (((uint8_t *) pbch_pdu)[0]&0xfc) | ((PHY_vars_eNB->frame>>8)&0x3);
+    ((uint8_t *) pbch_pdu)[1] = PHY_vars_eNB->frame&0xfc;
+    ((uint8_t *) pbch_pdu)[2] = 0;
 
     if (PHY_vars_eNB->lte_frame_parms.frame_type == 1) {
       generate_pss(PHY_vars_eNB->lte_eNB_common_vars.txdataF[0],
@@ -975,21 +907,11 @@ int main(int argc, char **argv)
                    10);
     }
 
-
-
     printf("Generating PBCH for mode1_flag = %d, frame_type %d\n", PHY_vars_eNB->lte_frame_parms.mode1_flag,PHY_vars_eNB->lte_frame_parms.frame_type);
-
-
     generate_pilots(PHY_vars_eNB,
                     PHY_vars_eNB->lte_eNB_common_vars.txdataF[0],
                     AMP,
                     LTE_NUMBER_OF_SUBFRAMES_PER_FRAME);
-
-
-
-
-
-
     generate_pbch(&PHY_vars_eNB->lte_eNB_pbch,
                   PHY_vars_eNB->lte_eNB_common_vars.txdataF[0],
                   AMP,
@@ -1010,24 +932,16 @@ int main(int argc, char **argv)
                    &PHY_vars_eNB1->lte_frame_parms,
                    (PHY_vars_eNB1->lte_frame_parms.Ncp==0)?6:5,
                    0);
-
-
-
-
-
       generate_pilots(PHY_vars_eNB1,
                       PHY_vars_eNB1->lte_eNB_common_vars.txdataF[0],
                       AMP,
                       LTE_NUMBER_OF_SUBFRAMES_PER_FRAME);
-
-
       generate_pbch(&PHY_vars_eNB1->lte_eNB_pbch,
                     PHY_vars_eNB1->lte_eNB_common_vars.txdataF[0],
                     AMP,
                     &PHY_vars_eNB1->lte_frame_parms,
                     pbch_pdu,
                     0);
-
     }
 
     if (interf2>-20) {
@@ -1036,36 +950,28 @@ int main(int argc, char **argv)
                    &PHY_vars_eNB2->lte_frame_parms,
                    (PHY_vars_eNB2->lte_frame_parms.Ncp==0)?6:5,
                    0);
-
-
-
-
-
       generate_pilots(PHY_vars_eNB2,
                       PHY_vars_eNB2->lte_eNB_common_vars.txdataF[0],
                       AMP,
                       LTE_NUMBER_OF_SUBFRAMES_PER_FRAME);
-
-
       generate_pbch(&PHY_vars_eNB2->lte_eNB_pbch,
                     PHY_vars_eNB2->lte_eNB_common_vars.txdataF[0],
                     AMP,
                     &PHY_vars_eNB2->lte_frame_parms,
                     pbch_pdu,
                     0);
-
     }
 
     // Generate two PDCCH
 
     if (frame_type == 0) {
-      ((DCI1_5MHz_FDD_t*)&DLSCH_alloc_pdu)->rah             = 0;
-      ((DCI1_5MHz_FDD_t*)&DLSCH_alloc_pdu)->rballoc         = DLSCH_RB_ALLOC;
-      ((DCI1_5MHz_FDD_t*)&DLSCH_alloc_pdu)->TPC             = 0;
-      ((DCI1_5MHz_FDD_t*)&DLSCH_alloc_pdu)->harq_pid        = 0;
-      ((DCI1_5MHz_FDD_t*)&DLSCH_alloc_pdu)->mcs             = 0;
-      ((DCI1_5MHz_FDD_t*)&DLSCH_alloc_pdu)->ndi             = 1;
-      ((DCI1_5MHz_FDD_t*)&DLSCH_alloc_pdu)->rv              = 0;
+      ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu)->rah             = 0;
+      ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu)->rballoc         = DLSCH_RB_ALLOC;
+      ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu)->TPC             = 0;
+      ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu)->harq_pid        = 0;
+      ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu)->mcs             = 0;
+      ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu)->ndi             = 1;
+      ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu)->rv              = 0;
       dci_alloc[0].dci_length   = sizeof_DCI1_5MHz_FDD_t;
       memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu,sizeof(DCI1_5MHz_FDD_t));
       dci_alloc[0].L            = 2;
@@ -1073,16 +979,16 @@ int main(int argc, char **argv)
       dci_alloc[0].format       = format1;
       dci_alloc[0].search_space = DCI_UE_SPACE;
     } else {
-      ((DCI1E_5MHz_2A_M10PRB_TDD_t*)&DLSCH_alloc_pdu)->rah             = 0;
-      ((DCI1E_5MHz_2A_M10PRB_TDD_t*)&DLSCH_alloc_pdu)->rballoc         = DLSCH_RB_ALLOC;
-      ((DCI1E_5MHz_2A_M10PRB_TDD_t*)&DLSCH_alloc_pdu)->TPC             = 0;
-      ((DCI1E_5MHz_2A_M10PRB_TDD_t*)&DLSCH_alloc_pdu)->dai             = 0;
-      ((DCI1E_5MHz_2A_M10PRB_TDD_t*)&DLSCH_alloc_pdu)->harq_pid        = 0;
-      ((DCI1E_5MHz_2A_M10PRB_TDD_t*)&DLSCH_alloc_pdu)->mcs             = 0;
-      ((DCI1E_5MHz_2A_M10PRB_TDD_t*)&DLSCH_alloc_pdu)->ndi             = 1;
-      ((DCI1E_5MHz_2A_M10PRB_TDD_t*)&DLSCH_alloc_pdu)->rv              = 0;
-      ((DCI1E_5MHz_2A_M10PRB_TDD_t*)&DLSCH_alloc_pdu)->tpmi            = (transmission_mode>=5 ? 5 : 0);  // precoding
-      ((DCI1E_5MHz_2A_M10PRB_TDD_t*)&DLSCH_alloc_pdu)->dl_power_off    = (transmission_mode==5 ? 0 : 1);
+      ((DCI1E_5MHz_2A_M10PRB_TDD_t *)&DLSCH_alloc_pdu)->rah             = 0;
+      ((DCI1E_5MHz_2A_M10PRB_TDD_t *)&DLSCH_alloc_pdu)->rballoc         = DLSCH_RB_ALLOC;
+      ((DCI1E_5MHz_2A_M10PRB_TDD_t *)&DLSCH_alloc_pdu)->TPC             = 0;
+      ((DCI1E_5MHz_2A_M10PRB_TDD_t *)&DLSCH_alloc_pdu)->dai             = 0;
+      ((DCI1E_5MHz_2A_M10PRB_TDD_t *)&DLSCH_alloc_pdu)->harq_pid        = 0;
+      ((DCI1E_5MHz_2A_M10PRB_TDD_t *)&DLSCH_alloc_pdu)->mcs             = 0;
+      ((DCI1E_5MHz_2A_M10PRB_TDD_t *)&DLSCH_alloc_pdu)->ndi             = 1;
+      ((DCI1E_5MHz_2A_M10PRB_TDD_t *)&DLSCH_alloc_pdu)->rv              = 0;
+      ((DCI1E_5MHz_2A_M10PRB_TDD_t *)&DLSCH_alloc_pdu)->tpmi            = (transmission_mode>=5 ? 5 : 0); // precoding
+      ((DCI1E_5MHz_2A_M10PRB_TDD_t *)&DLSCH_alloc_pdu)->dl_power_off    = (transmission_mode==5 ? 0 : 1);
       dci_alloc[0].dci_length   = sizeof_DCI1E_5MHz_2A_M10PRB_TDD_t;
       memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu,sizeof(DCI1E_5MHz_2A_M10PRB_TDD_t));
       dci_alloc[0].L            = 2;
@@ -1107,7 +1013,6 @@ int main(int argc, char **argv)
            PHY_vars_eNB->lte_eNB_common_vars.txdataF[eNb_id],
            5);
     */
-
     //  LOG_M("pilotsF.m","rsF",txdataF[0],lte_frame_parms->ofdm_symbol_size,1,1);
 #ifdef IFFT_FPGA
     LOG_M("txsigF0.m","txsF0", PHY_vars_eNB->lte_eNB_common_vars.txdataF[eNb_id][0],300*120,1,4);
@@ -1116,8 +1021,7 @@ int main(int argc, char **argv)
       LOG_M("txsigF1.m","txsF1", PHY_vars_eNB->lte_eNB_common_vars.txdataF[eNb_id][1],300*120,1,4);
 
     for (i=0; i<10; i++)
-      debug_msg("%08x\n",((unsigned int*)&PHY_vars_eNB->lte_eNB_common_vars.txdataF[0][0][1*(PHY_vars_eNB->lte_frame_parms.N_RB_DL*12)*(PHY_vars_eNB->lte_frame_parms.symbols_per_tti>>1)])[i]);
-
+      debug_msg("%08x\n",((unsigned int *)&PHY_vars_eNB->lte_eNB_common_vars.txdataF[0][0][1*(PHY_vars_eNB->lte_frame_parms.N_RB_DL*12)*(PHY_vars_eNB->lte_frame_parms.symbols_per_tti>>1)])[i]);
 
     // do talbe lookup and write results to txdataF2
     for (aa=0; aa<PHY_vars_eNB->lte_frame_parms.nb_antennas_tx; aa++) {
@@ -1125,9 +1029,9 @@ int main(int argc, char **argv)
 
       for (i=0; i<FRAME_LENGTH_COMPLEX_SAMPLES_NO_PREFIX; i++)
         if ((i%512>=1) && (i%512<=150))
-          txdataF2[aa][i] = ((int*)mod_table)[PHY_vars_eNB->lte_eNB_common_vars.txdataF[eNb_id][aa][l++]];
+          txdataF2[aa][i] = ((int *)mod_table)[PHY_vars_eNB->lte_eNB_common_vars.txdataF[eNb_id][aa][l++]];
         else if (i%512>=362)
-          txdataF2[aa][i] = ((int*)mod_table)[PHY_vars_eNB->lte_eNB_common_vars.txdataF[eNb_id][aa][l++]];
+          txdataF2[aa][i] = ((int *)mod_table)[PHY_vars_eNB->lte_eNB_common_vars.txdataF[eNb_id][aa][l++]];
         else
           txdataF2[aa][i] = 0;
 
@@ -1139,11 +1043,9 @@ int main(int argc, char **argv)
     if (PHY_vars_eNB->lte_frame_parms.nb_antennas_tx>1)
       LOG_M("txsigF21.m","txsF21", txdataF2[1],FRAME_LENGTH_COMPLEX_SAMPLES_NO_PREFIX,1,1);
 
-
     tx_lev=0;
 
     for (aa=0; aa<PHY_vars_eNB->lte_frame_parms.nb_antennas_tx; aa++) {
-
       if (frame_parms->Ncp == 1)
         PHY_ofdm_mod(txdataF2[aa],        // input
                      txdata[aa],         // output
@@ -1169,9 +1071,6 @@ int main(int argc, char **argv)
 
     tx_lev = 0;
 
-
-
-
     for (aa=0; aa<PHY_vars_eNB->lte_frame_parms.nb_antennas_tx; aa++) {
       if (frame_parms->Ncp == 1)
         PHY_ofdm_mod(PHY_vars_eNB->lte_eNB_common_vars.txdataF[eNb_id][aa],        // input,
@@ -1234,9 +1133,6 @@ int main(int argc, char **argv)
     }
 
 #endif
-
-
-
     LOG_M("txsig0.m","txs0", txdata[0],FRAME_LENGTH_COMPLEX_SAMPLES,1,1);
 
     if (frame_parms->nb_antennas_tx>1)
@@ -1245,7 +1141,7 @@ int main(int argc, char **argv)
     i=0;
 
     while (!feof(input_fd)) {
-      ret=fscanf(input_fd,"%s %s",input_val_str,input_val_str2);//&input_val1,&input_val2);
+      ret=fscanf(input_fd,"%49s %49s",input_val_str,input_val_str2);//&input_val1,&input_val2);
       /*
       if ((i%4)==0) {
       ((short*)txdata[0])[i/2] = (short)((1<<15)*strtod(input_val_str,NULL));
@@ -1254,9 +1150,8 @@ int main(int argc, char **argv)
       printf("sample %d => %e + j%e (%d +j%d)\n",i/4,strtod(input_val_str,NULL),strtod(input_val_str2,NULL),((short*)txdata[0])[i/4],((short*)txdata[0])[(i/4)+1]);//1,input_val2,);
       }
       */
-      ((short*)txdata[0])[i<<1] = 16*(short)(strtod(input_val_str,NULL));
-      ((short*)txdata[0])[(i<<1)+1] = 16*(short)(strtod(input_val_str2,NULL));
-
+      ((short *)txdata[0])[i<<1] = 16*(short)(strtod(input_val_str,NULL));
+      ((short *)txdata[0])[(i<<1)+1] = 16*(short)(strtod(input_val_str2,NULL));
       i++;
 
       if (i==(FRAME_LENGTH_COMPLEX_SAMPLES))
@@ -1270,8 +1165,6 @@ int main(int argc, char **argv)
                            OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES);
   } else { // get from OAI HW
     // set check if we have to set up a signal generator here
-
-
     printf("Doing Acquisition from OAI HW\n");
     snr0=snr1-.1;
   }
@@ -1283,13 +1176,10 @@ int main(int argc, char **argv)
     sn = sin(2*M_PI*foff*i);
 
     for (aa=0; aa<PHY_vars_eNB->lte_frame_parms.nb_antennas_tx; aa++) {
-
-      tmp_re =  (double)((short*)txdata[aa])[(i<<1)]*cs - (double)((short*)txdata[aa])[1+(i<<1)]*sn;
-
-      tmp_im =  (double)((short*)txdata[aa])[1+(i<<1)]*cs + (double)((short*)txdata[aa])[(i<<1)]*sn;
+      tmp_re =  (double)((short *)txdata[aa])[(i<<1)]*cs - (double)((short *)txdata[aa])[1+(i<<1)]*sn;
+      tmp_im =  (double)((short *)txdata[aa])[1+(i<<1)]*cs + (double)((short *)txdata[aa])[(i<<1)]*sn;
 
       if (awgn_flag == 0) {
-
         s_re[aa][i] = tmp_re;
         s_im[aa][i] = tmp_im;
 
@@ -1302,7 +1192,6 @@ int main(int argc, char **argv)
           s_re2[aa][i] = ((double)(((short *)txdata2[aa]))[(i<<1)]);
           s_im2[aa][i] = ((double)(((short *)txdata2[aa]))[(i<<1)+1]);
         }
-
       } else {
         for (aarx=0; aarx<PHY_vars_UE[0]->lte_frame_parms.nb_antennas_rx; aarx++) {
           if (aa==0) {
@@ -1330,19 +1219,14 @@ int main(int argc, char **argv)
   }
 
   if (oai_hw_output==0) {
-
     for (SNR=snr0; SNR<snr1; SNR+=.2) {
-
       n_errors = 0;
       n_errors2 = 0;
       n_alamouti = 0;
 
       for (trial=0; trial<n_frames; trial++) {
-
         if (oai_hw_input == 0) {
-
           if (awgn_flag == 0) {
-
             multipath_channel(eNB2UE,s_re,s_im,r_re,r_im,
                               FRAME_LENGTH_COMPLEX_SAMPLES,0);//LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES,0);
 
@@ -1353,7 +1237,6 @@ int main(int argc, char **argv)
             if (interf2>-20)
               multipath_channel(eNB2UE2,s_re2,s_im2,r_re2,r_im2,
                                 LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES,0);
-
           } // awgn_flag
 
           sigma2_dB = 10*log10((double)tx_lev) +10*log10(PHY_vars_eNB->lte_frame_parms.ofdm_symbol_size/(12*NB_RB)) - SNR;
@@ -1363,7 +1246,6 @@ int main(int argc, char **argv)
 
           //AWGN
           sigma2 = pow(10,sigma2_dB/10);
-
           /*
               if (n_frames==1) {
               printf("rx_level data symbol %f, tx_lev %f\n",
@@ -1371,16 +1253,14 @@ int main(int argc, char **argv)
               10*log10(tx_lev));
               }
           */
-
           iout = 0;//taus()%(FRAME_LENGTH_COMPLEX_SAMPLES>>2);
 
           for (i=0; i<FRAME_LENGTH_COMPLEX_SAMPLES; i++) { //nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES; i++) {
             for (aa=0; aa<PHY_vars_eNB->lte_frame_parms.nb_antennas_rx; aa++) {
               r_re[aa][i] += (pow(10.0,.05*interf1)*r_re1[aa][i] + pow(10.0,.05*interf2)*r_re2[aa][i]);
               r_im[aa][i] += (pow(10.0,.05*interf1)*r_im1[aa][i] + pow(10.0,.05*interf2)*r_im2[aa][i]);
-
-              ((short*) PHY_vars_UE[0]->lte_ue_common_vars.rxdata[aa])[2*i] = (short) (.167*(r_re[aa][i] +sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
-              ((short*) PHY_vars_UE[0]->lte_ue_common_vars.rxdata[aa])[(2*i)+1] = (short) (.167*(r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
+              ((short *) PHY_vars_UE[0]->lte_ue_common_vars.rxdata[aa])[2*i] = (short) (.167*(r_re[aa][i] +sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
+              ((short *) PHY_vars_UE[0]->lte_ue_common_vars.rxdata[aa])[(2*i)+1] = (short) (.167*(r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
             }
 
             iout++;
@@ -1440,11 +1320,9 @@ int main(int argc, char **argv)
                        0);
             }
 
-
             PHY_vars_UE[UE_idx]->lte_ue_pdcch_vars[0]->crnti = n_rnti;
             PHY_vars_UE[UE_idx]->transmission_mode[0] = transmission_mode;
             PHY_vars_UE[UE_idx]->UE_mode[0] = PUSCH;
-
             printf("Fine Frequency offset %d\n",PHY_vars_UE[UE_idx]->lte_ue_common_vars.freq_offset);
             printf("Doing PDCCH RX : num_pdcch_symbols at TX %d\n",num_pdcch_symbols);
             rx_pdcch(&PHY_vars_UE[UE_idx]->lte_ue_common_vars,
@@ -1456,7 +1334,6 @@ int main(int argc, char **argv)
                      (PHY_vars_UE[UE_idx]->lte_frame_parms.mode1_flag == 1) ? SISO : ALAMOUTI,
                      PHY_vars_UE[UE_idx]->is_secondary_ue);
             printf("Got PCFICH for %d pdcch symbols\n",PHY_vars_UE[UE_idx]->lte_ue_pdcch_vars[0]->num_pdcch_symbols);
-
             dci_cnt = dci_decoding_procedure(PHY_vars_UE[UE_idx],
                                              dci_alloc_rx,
                                              0,
@@ -1475,9 +1352,7 @@ int main(int argc, char **argv)
                                                 SI_RNTI,
                                                 0,
                                                 P_RNTI);
-
               i_mod = get_Qm(PHY_vars_UE[UE_idx]->dlsch_ue[0][0]->harq_processes[0]->mcs);
-
               /*
               // overwrite some values until source is sure
               PHY_vars_UE[UE_idx]->dlsch_ue[0][0]->nb_rb = 25;
@@ -1485,7 +1360,6 @@ int main(int argc, char **argv)
               PHY_vars_UE[UE_idx]->dlsch_ue[0][0]->harq_processes[0]->Ndi = 1;
               PHY_vars_UE[UE_idx]->dlsch_ue[0][0]->harq_processes[0]->mcs = 0;
               */
-
               dump_dci(&PHY_vars_UE[UE_idx]->lte_frame_parms, &dci_alloc_rx[0]);
 
               for (l=PHY_vars_UE[UE_idx]->lte_ue_pdcch_vars[0]->num_pdcch_symbols;
@@ -1590,20 +1464,16 @@ int main(int argc, char **argv)
                          i_mod);
               }
 
-
-
               coded_bits_per_codeword = get_G(&PHY_vars_UE[UE_idx]->lte_frame_parms,
                                               PHY_vars_UE[UE_idx]->dlsch_ue[0][0]->nb_rb,
                                               PHY_vars_UE[UE_idx]->dlsch_ue[0][0]->rb_alloc,
                                               get_Qm(PHY_vars_UE[UE_idx]->dlsch_ue[0][0]->harq_processes[PHY_vars_UE[UE_idx]->dlsch_ue[0][0]->current_harq_pid]->mcs),
                                               PHY_vars_UE[UE_idx]->lte_ue_pdcch_vars[0]->num_pdcch_symbols,
                                               subframe);
-
-              printf("G %d, TBS %d, pdcch_sym %d\n",
+              printf("G %u, TBS %d, pdcch_sym %d\n",
                      coded_bits_per_codeword,
                      dlsch_tbs25[get_I_TBS(PHY_vars_UE[UE_idx]->dlsch_ue[0][0]->harq_processes[0]->mcs)][PHY_vars_UE[UE_idx]->dlsch_ue[0][0]->nb_rb-1],
                      num_pdcch_symbols);
-
               dlsch_unscrambling(&PHY_vars_UE[UE_idx]->lte_frame_parms,
                                  PHY_vars_UE[UE_idx]->lte_ue_pdcch_vars[0]->num_pdcch_symbols,
                                  PHY_vars_UE[UE_idx]->dlsch_ue[0][0],
@@ -1611,7 +1481,6 @@ int main(int argc, char **argv)
                                  PHY_vars_UE[UE_idx]->lte_ue_pdsch_vars[0]->llr[0],
                                  0,
                                  subframe<<1);
-
               ret = dlsch_decoding(PHY_vars_UE[UE_idx],
                                    PHY_vars_UE[UE_idx]->lte_ue_pdsch_vars[0]->llr[0],
                                    &PHY_vars_UE[UE_idx]->lte_frame_parms,
@@ -1635,53 +1504,52 @@ int main(int argc, char **argv)
             n_errors++;
         }
 
-
 #ifdef XFORMS
 
         if (do_forms==1) {
           do_forms2(form_dl,
                     frame_parms,
                     PHY_vars_UE[0]->lte_ue_pdcch_vars[0]->num_pdcch_symbols,
-                    (int16_t**)PHY_vars_UE[0]->lte_ue_common_vars.dl_ch_estimates_time,
-                    (int16_t**)PHY_vars_UE[0]->lte_ue_common_vars.common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[0],
-                    (int16_t**)PHY_vars_UE[0]->lte_ue_common_vars.rxdata,
-                    (int16_t**)PHY_vars_UE[0]->lte_ue_common_vars.common_vars_rx_data_per_thread[subframe&0x1].rxdataF,
-                    (int16_t*)PHY_vars_UE[0]->lte_ue_pdcch_vars[0]->rxdataF_comp[0],
-                    (int16_t*)PHY_vars_UE[0]->lte_ue_pdsch_vars[0]->rxdataF_comp[0],
-                    (int16_t*)PHY_vars_UE[0]->lte_ue_pdsch_vars[1]->rxdataF_comp[0],
-                    (int16_t*)PHY_vars_UE[0]->lte_ue_pdsch_vars[0]->llr[0],
-                    (int16_t*)PHY_vars_UE[0]->lte_ue_pbch_vars[0]->rxdataF_comp[0],
-                    (int8_t*)PHY_vars_UE[0]->lte_ue_pbch_vars[0]->llr,
+                    (int16_t **)PHY_vars_UE[0]->lte_ue_common_vars.dl_ch_estimates_time,
+                    (int16_t **)PHY_vars_UE[0]->lte_ue_common_vars.common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[0],
+                    (int16_t **)PHY_vars_UE[0]->lte_ue_common_vars.rxdata,
+                    (int16_t **)PHY_vars_UE[0]->lte_ue_common_vars.common_vars_rx_data_per_thread[subframe&0x1].rxdataF,
+                    (int16_t *)PHY_vars_UE[0]->lte_ue_pdcch_vars[0]->rxdataF_comp[0],
+                    (int16_t *)PHY_vars_UE[0]->lte_ue_pdsch_vars[0]->rxdataF_comp[0],
+                    (int16_t *)PHY_vars_UE[0]->lte_ue_pdsch_vars[1]->rxdataF_comp[0],
+                    (int16_t *)PHY_vars_UE[0]->lte_ue_pdsch_vars[0]->llr[0],
+                    (int16_t *)PHY_vars_UE[0]->lte_ue_pbch_vars[0]->rxdataF_comp[0],
+                    (int8_t *)PHY_vars_UE[0]->lte_ue_pbch_vars[0]->llr,
                     coded_bits_per_codeword);
 
           if (N_carriers==2)
             do_forms2(form_dl1,
                       frame_parms,
                       PHY_vars_UE[1]->lte_ue_pdcch_vars[0]->num_pdcch_symbols,
-                      (int16_t**)PHY_vars_UE[1]->lte_ue_common_vars.dl_ch_estimates_time,
-                      (int16_t**)PHY_vars_UE[1]->lte_ue_common_vars.common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[0],
-                      (int16_t**)PHY_vars_UE[1]->lte_ue_common_vars.rxdata,
-                      (int16_t**)PHY_vars_UE[1]->lte_ue_common_vars.common_vars_rx_data_per_thread[subframe&0x1].rxdataF,
-                      (int16_t*)PHY_vars_UE[1]->lte_ue_pdcch_vars[0]->rxdataF_comp[0],
-                      (int16_t*)PHY_vars_UE[1]->lte_ue_pdsch_vars[0]->rxdataF_comp[0],
-                      (int16_t*)PHY_vars_UE[1]->lte_ue_pdsch_vars[3]->rxdataF_comp[0],
-                      (int16_t*)PHY_vars_UE[1]->lte_ue_pdsch_vars[0]->llr[0],
-                      (int16_t*)PHY_vars_UE[1]->lte_ue_pbch_vars[0]->rxdataF_comp[0],
-                      (int8_t*)PHY_vars_UE[1]->lte_ue_pbch_vars[0]->llr,
+                      (int16_t **)PHY_vars_UE[1]->lte_ue_common_vars.dl_ch_estimates_time,
+                      (int16_t **)PHY_vars_UE[1]->lte_ue_common_vars.common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[0],
+                      (int16_t **)PHY_vars_UE[1]->lte_ue_common_vars.rxdata,
+                      (int16_t **)PHY_vars_UE[1]->lte_ue_common_vars.common_vars_rx_data_per_thread[subframe&0x1].rxdataF,
+                      (int16_t *)PHY_vars_UE[1]->lte_ue_pdcch_vars[0]->rxdataF_comp[0],
+                      (int16_t *)PHY_vars_UE[1]->lte_ue_pdsch_vars[0]->rxdataF_comp[0],
+                      (int16_t *)PHY_vars_UE[1]->lte_ue_pdsch_vars[3]->rxdataF_comp[0],
+                      (int16_t *)PHY_vars_UE[1]->lte_ue_pdsch_vars[0]->llr[0],
+                      (int16_t *)PHY_vars_UE[1]->lte_ue_pbch_vars[0]->rxdataF_comp[0],
+                      (int8_t *)PHY_vars_UE[1]->lte_ue_pbch_vars[0]->llr,
                       1920);
         }
 
 #endif
-
       } // trials
     } // SNR
 
     if (n_frames==1) {
-
-      LOG_M("H00.m","h00",&(PHY_vars_UE[0]->lte_ue_common_vars.common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[0][0][0]),((frame_parms->Ncp==0)?7:6)*(PHY_vars_eNB->lte_frame_parms.ofdm_symbol_size),1,1);
+      LOG_M("H00.m","h00",&(PHY_vars_UE[0]->lte_ue_common_vars.common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[0][0][0]),
+            ((frame_parms->Ncp==0)?7:6)*(PHY_vars_eNB->lte_frame_parms.ofdm_symbol_size),1,1);
 
       if (n_tx==2)
-        LOG_M("H10.m","h10",&(PHY_vars_UE[0]->lte_ue_common_vars.common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[0][2][0]),((frame_parms->Ncp==0)?7:6)*(PHY_vars_eNB->lte_frame_parms.ofdm_symbol_size),1,1);
+        LOG_M("H10.m","h10",&(PHY_vars_UE[0]->lte_ue_common_vars.common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[0][2][0]),
+              ((frame_parms->Ncp==0)?7:6)*(PHY_vars_eNB->lte_frame_parms.ofdm_symbol_size),1,1);
 
       LOG_M("rxsig0.m","rxs0", PHY_vars_UE[0]->lte_ue_common_vars.rxdata[0],FRAME_LENGTH_COMPLEX_SAMPLES,1,1);
       LOG_M("rxsigF0.m","rxsF0", PHY_vars_UE[0]->lte_ue_common_vars.rxdataF[0],NUMBER_OF_OFDM_CARRIERS*LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*nsymb,2,1);
@@ -1691,16 +1559,13 @@ int main(int argc, char **argv)
       LOG_M("pdcch_rxF_ext0.m","pdcch_rxF_ext0",PHY_vars_UE[0]->lte_ue_pdcch_vars[eNb_id]->rxdataF_ext[0],3*300,1,1);
       LOG_M("pdcch_rxF_comp0.m","pdcch0_rxF_comp0",PHY_vars_UE[0]->lte_ue_pdcch_vars[eNb_id]->rxdataF_comp[0],4*300,1,1);
       LOG_M("pdcch_rxF_llr.m","pdcch_llr",PHY_vars_UE[0]->lte_ue_pdcch_vars[eNb_id]->llr,2400,1,4);
-
       coded_bits_per_codeword = get_G(&PHY_vars_UE[0]->lte_frame_parms,
                                       PHY_vars_UE[0]->dlsch_ue[0][0]->nb_rb,
                                       PHY_vars_UE[0]->dlsch_ue[0][0]->rb_alloc,
                                       get_Qm(PHY_vars_UE[0]->dlsch_ue[0][0]->harq_processes[0]->mcs),
                                       PHY_vars_UE[0]->lte_ue_pdcch_vars[0]->num_pdcch_symbols,
                                       0);
-
       dump_dlsch2(PHY_vars_UE[0],0,0,&coded_bits_per_codeword);
-
     }
   } else {
     printf("Sending frame to OAI HW\n");
@@ -1720,8 +1585,6 @@ int main(int argc, char **argv)
   }
 
 #endif
-
-
 #ifdef IFFT_FPGA
   free(txdataF2[0]);
   free(txdataF2[1]);
@@ -1750,20 +1613,20 @@ int main(int argc, char **argv)
   free(r_re);
   printf("Freeing r_im\n");
   free(r_im);
-
-
   lte_sync_time_free();
 
   if (write_output_file)
     fclose(output_fd);
 
+  if (input_fd)
+    fclose(input_fd);
+
   if ((oai_hw_input==1)||
       (oai_hw_output==1)) {
     close(openair_fd);
   }
 
   return(n_errors);
-
 }
 
 
diff --git a/openair1/SIMULATION/LTE_PHY/ulsim.c b/openair1/SIMULATION/LTE_PHY/ulsim.c
index 92b18205699816584c4cc222595ae889291e8536..e38d6ad3cd0f3d699008299fc17c6222737e1375 100644
--- a/openair1/SIMULATION/LTE_PHY/ulsim.c
+++ b/openair1/SIMULATION/LTE_PHY/ulsim.c
@@ -1,23 +1,23 @@
 /*
-   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
-*/
+ * 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
+ */
 
 /*! \file ulsim.c
   \brief Top-level UL simulator
@@ -60,32 +60,7 @@
 double cpuf;
 #define inMicroS(a) (((double)(a))/(cpu_freq_GHz*1000.0))
 //#define MCS_COUNT 23//added for PHY abstraction
-static int cmpdouble(const void *p1, const void *p2) {
-  return *(double *)p1 > *(double *)p2;
-}
-
-double median(varArray_t *input) {
-  return *(double *)((uint8_t *)(input+1)+(input->size/2)*input->atomSize);
-}
-
-double q1(varArray_t *input) {
-  return *(double *)((uint8_t *)(input+1)+(input->size/4)*input->atomSize);
-}
-
-double q3(varArray_t *input) {
-  return *(double *)((uint8_t *)(input+1)+(3*input->size/4)*input->atomSize);
-}
-
-void dumpVarArray(varArray_t *input) {
-  double *ptr=dataArray(input);
-  printf("dumping size=%ld\n", input->size);
-
-  for (int i=0; i < input->size; i++)
-    printf("%.1f:", *ptr++);
-
-  printf("\n");
-}
-
+#include <openair1/SIMULATION/LTE_PHY/common_sim.h>
 channel_desc_t *eNB2UE[NUMBER_OF_eNB_MAX][NUMBER_OF_UE_MAX];
 channel_desc_t *UE2eNB[NUMBER_OF_UE_MAX][NUMBER_OF_eNB_MAX];
 //Added for PHY abstractionopenair1/PHY/TOOLS/lte_phy_scope.h
@@ -110,8 +85,8 @@ int nfapi_mode = 0;
 
 extern void fep_full(RU_t *ru);
 extern void ru_fep_full_2thread(RU_t *ru);
-extern void eNB_fep_full(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc);
-extern void eNB_fep_full_2thread(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc);
+extern void eNB_fep_full(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc);
+extern void eNB_fep_full_2thread(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc);
 
 nfapi_dl_config_request_t DL_req;
 nfapi_ul_config_request_t UL_req;
@@ -121,30 +96,7 @@ nfapi_tx_request_pdu_t tx_pdu_list[MAX_NUM_TX_REQUEST_PDU];
 nfapi_tx_request_t TX_req;
 Sched_Rsp_t sched_resp;
 
-char *parallel_config = NULL;
-char *worker_config = NULL;
-static THREAD_STRUCT thread_struct;
-void set_parallel_conf(char *parallel_conf)
-{
-  if(strcmp(parallel_conf,"PARALLEL_SINGLE_THREAD")==0)           thread_struct.parallel_conf = PARALLEL_SINGLE_THREAD;
-  else if(strcmp(parallel_conf,"PARALLEL_RU_L1_SPLIT")==0)        thread_struct.parallel_conf = PARALLEL_RU_L1_SPLIT;
-  else if(strcmp(parallel_conf,"PARALLEL_RU_L1_TRX_SPLIT")==0)    thread_struct.parallel_conf = PARALLEL_RU_L1_TRX_SPLIT;
-  printf("[CONFIG] parallel conf is set to %d\n",thread_struct.parallel_conf);
-}
-void set_worker_conf(char *worker_conf)
-{
-  if(strcmp(worker_conf,"WORKER_DISABLE")==0)                     thread_struct.worker_conf = WORKER_DISABLE;
-  else if(strcmp(worker_conf,"WORKER_ENABLE")==0)                 thread_struct.worker_conf = WORKER_ENABLE;
-  printf("[CONFIG] worker conf is set to %d\n",thread_struct.worker_conf);
-}
-PARALLEL_CONF_t get_thread_parallel_conf(void)
-{
-  return thread_struct.parallel_conf;
-}
-WORKER_CONF_t get_thread_worker_conf(void)
-{
-  return thread_struct.worker_conf;
-}
+THREAD_STRUCT thread_struct;
 
 void
 fill_nfapi_ulsch_config_request(nfapi_ul_config_request_pdu_t *ul_config_pdu,
@@ -348,48 +300,8 @@ void fill_ulsch_dci(PHY_VARS_eNB *eNB,
   ul_req->tl.tag = NFAPI_UL_CONFIG_REQUEST_BODY_TAG;
 }
 
-void printStatIndent(time_stats_t *ptr, char *txt) {
-  printf("|__ %-50s %.2f us (%d trials)\n",
-         txt,
-         inMicroS(ptr->diff/ptr->trials),
-         ptr->trials);
-}
-
-void printStatIndent2(time_stats_t *ptr, char *txt, int turbo_iter) {
-  double timeBase=1/(1000*cpu_freq_GHz);
-  printf("    |__ %-45s %.2f us (cycles/block %7g, %5d trials)\n",
-         txt,
-         ((double)ptr->diff)/ptr->trials*timeBase,
-         round(((double)ptr->diff)/turbo_iter),
-         ptr->trials);
-}
-
-double squareRoot(time_stats_t *ptr) {
-  double timeBase=1/(1000*cpu_freq_GHz);
-  return sqrt((double)ptr->diff_square*pow(timeBase,2)/ptr->trials -
-              pow((double)ptr->diff/ptr->trials*timeBase,2));
-}
-
-void printDistribution(time_stats_t *ptr, varArray_t *sortedList, char *txt) {
-  double timeBase=1/(1000*cpu_freq_GHz);
-  printf("%-50s             :%.2f us (%d trials)\n",
-         txt,
-         (double)ptr->diff/ptr->trials*timeBase,
-         ptr->trials);
-  printf("|__ Statistics std=%.2f, median=%.2f, q1=%.2f, q3=%.2f µs (on %ld trials)\n",
-         squareRoot(ptr), median(sortedList),q1(sortedList),q3(sortedList), sortedList->size);
-}
-
-void logDistribution(FILE* fd, time_stats_t *ptr, varArray_t *sortedList, int dropped) {
-  fprintf(fd,"%f;%f;%f;%f;%f;%f;%d;",
-	  squareRoot(ptr),
-	  (double)ptr->max, *(double*)dataArray(sortedList),
-	  median(sortedList),q1(sortedList),q3(sortedList),
-	  dropped);
-}
-
 enum eTypes { eBool, eInt, eFloat, eText };
-static int verbose,disable_bundling=0,cqi_flag=0, extended_prefix_flag=0, test_perf=0, subframe=3, transmission_m=1,n_rx=1;
+static int verbose,help,disable_bundling=0,cqi_flag=0, extended_prefix_flag=0, test_perf=0, subframe=3, transmission_m=1,n_rx=1;
 
 int main(int argc, char **argv) {
   int i,j,aa,u;
@@ -437,19 +349,6 @@ int main(int argc, char **argv) {
   char input_val_str[50],input_val_str2[50];
   //  FILE *rx_frame_file;
   FILE *csv_fdUL=NULL;
-  /*
-    FILE *fperen=NULL;
-    char fperen_name[512];
-
-    FILE *fmageren=NULL;
-    char fmageren_name[512];
-
-    FILE *flogeren=NULL;
-    char flogeren_name[512];
-  */
-  /* FILE *ftxlev;
-     char ftxlev_name[512];
-  */
   char csv_fname[512];
   static int n_frames=5000;
   static int n_ch_rlz = 1;
@@ -475,7 +374,6 @@ int main(int argc, char **argv) {
   double effective_rate=0.0;
   char channel_model_input[10]= {0};
   static int max_turbo_iterations=4;
-  static int parallel_flag=0;
   int nb_rb_set = 0;
   int sf;
   static int threequarter_fs=0;
@@ -493,25 +391,26 @@ int main(int argc, char **argv) {
   TX_req.tx_request_body.tx_pdu_list = tx_pdu_list;
   cpu_freq_GHz = (double)get_cpu_freq_GHz();
   cpuf = cpu_freq_GHz;
+  set_parallel_conf("PARALLEL_SINGLE_THREAD");
   printf("Detected cpu_freq %f GHz\n",cpu_freq_GHz);
-  AssertFatal(load_configmodule(argc,argv) != NULL,
+  AssertFatal(load_configmodule(argc,argv,CONFIG_ENABLECMDLINEONLY) != NULL,
               "cannot load configuration module, exiting\n");
   logInit();
   // enable these lines if you need debug info
   // however itti will catch all signals, so ctrl-c won't work anymore
   // alternatively you can disable ITTI completely in CMakeLists.txt
-  //itti_init(TASK_MAX, THREAD_MAX, MESSAGES_ID_MAX, tasks_info, messages_info, messages_definition_xml, NULL);
-  //set_comp_log(PHY,LOG_DEBUG,LOG_MED,1);
-  //set_glog(LOG_DEBUG,LOG_MED);
+  //  itti_init(TASK_MAX, THREAD_MAX, MESSAGES_ID_MAX, tasks_info, messages_info, messages_definition_xml, NULL);
+  //  set_comp_log(PHY,LOG_DEBUG,LOG_HIGH,1);
+  //  set_glog(LOG_DEBUG,LOG_HIGH);
   //hapZEbm:n:Y:X:x:s:w:e:q:d:D:O:c:r:i:f:y:c:oA:C:R:g:N:l:S:T:QB:PI:LF
   static paramdef_t options[] = {
-    { "awgn", "Additive white gaussian noise", PARAMFLAG_BOOL, strptr:NULL, defintval:0, TYPE_INT, 0, NULL, NULL },
+    { "awgn", "Use AWGN channel and not multipath", PARAMFLAG_BOOL, strptr:NULL, defintval:0, TYPE_INT, 0, NULL, NULL },
     { "BnbRBs", "The LTE bandwith in RBs (100 is 20MHz)",0, iptr:&N_RB_DL,  defintval:25, TYPE_INT, 0 },
     { "mcs", "The MCS to use", 0, iptr:&mcs,  defintval:10, TYPE_INT, 0 },
     { "nb_frame", "number of frame in a test",0, iptr:&n_frames,  defintval:1, TYPE_INT, 0 },
     { "snr", "starting snr", 0, dblptr:&snr0,  defdblval:-2.9, TYPE_DOUBLE, 0 },
     { "wsnrInterrupt", "snr int ?", 0, dblptr:&snr_int,  defdblval:30, TYPE_DOUBLE, 0 },
-    { "e_snr_step", "step increasint snr",0, dblptr:&input_snr_step,  defdblval:0.2, TYPE_DOUBLE, 0 },
+    { "e_snr_step", "step increasing snr",0, dblptr:&input_snr_step,  defdblval:0.2, TYPE_DOUBLE, 0 },
     { "rb_dynamic", "number of rb in dynamic allocation",0, iptr:NULL,  defintval:0, TYPE_INT, 0 },
     { "first_rb", "first rb used in dynamic allocation",0, iptr:&first_rb,  defintval:0, TYPE_INT, 0 },
     { "osrs", "enable srs generation",PARAMFLAG_BOOL, iptr:&srs_flag,  defintval:0, TYPE_INT, 0 },
@@ -520,7 +419,7 @@ int main(int argc, char **argv) {
     { "Doppler", "Maximum doppler shift",0, dblptr:&maxDoppler,  defdblval:0.0, TYPE_DOUBLE, 0 },
     { "Zdump", "dump table",PARAMFLAG_BOOL,  iptr:&dump_table, defintval:0, TYPE_INT, 0 },
     { "Forms", "Display the soft scope", PARAMFLAG_BOOL, iptr:&xforms,  defintval:0, TYPE_INT, 0 },
-    { "Lparallel", "Enable parallel execution", PARAMFLAG_BOOL, iptr:&parallel_flag,  defintval:0, TYPE_INT, 0 },
+    { "Lparallel", "Enable parallel execution",0, strptr:NULL,  defstrval:NULL, TYPE_STRING,  0 },
     { "Iterations", "Number of iterations of turbo decoder", 0, iptr:&max_turbo_iterations,  defintval:4, TYPE_INT, 0 },
     { "Performance", "Display CPU perfomance of each L1 piece", PARAMFLAG_BOOL,  iptr:NULL,  defintval:0, TYPE_INT, 0 },
     { "Q_cqi", "Enable CQI", PARAMFLAG_BOOL, iptr:&cqi_flag,  defintval:0, TYPE_INT, 0 },
@@ -538,40 +437,13 @@ int main(int argc, char **argv) {
     { "bundling_disable", "bundling disable",PARAMFLAG_BOOL,  iptr:&disable_bundling, defintval:0, TYPE_INT, 0 },
     { "Y",  "n_ch_rlz",0, iptr:&n_ch_rlz,  defintval:1, TYPE_INT, 0 },
     { "X",  "abstx", PARAMFLAG_BOOL,  iptr:&abstx, defintval:0, TYPE_INT, 0 },
-    { "Operf", "test perf mode ?",0, iptr:&test_perf,  defintval:0, TYPE_INT, 0 },
+    { "Operf", "Set the percentage of effective rate to testbench the modem performance (typically 30 and 70, range 1-100)",0, iptr:&test_perf,  defintval:0, TYPE_INT, 0 },
     { "verbose", "display debug text", PARAMFLAG_BOOL,  iptr:&verbose, defintval:0, TYPE_INT, 0 },
+    { "help", "display help and exit", PARAMFLAG_BOOL,  iptr:&help, defintval:0, TYPE_INT, 0 },
     { "", "",0,  iptr:NULL, defintval:0, TYPE_INT, 0 },
   };
-  int l;
-
-  for(l=0; options[l].optname[0]!=0; l++) {};
-
-  struct option *long_options=calloc(sizeof(struct option),l);
-
-  for(int i=0; options[i].optname[0]!=0; i++) {
-    long_options[i].name=options[i].optname;
-    long_options[i].has_arg=options[i].paramflags==PARAMFLAG_BOOL?no_argument:required_argument;
-
-    if ( options[i].voidptr)
-      switch (options[i].type) {
-        case TYPE_INT:
-          *options[i].iptr=options[i].defintval;
-          break;
-
-        case TYPE_DOUBLE:
-          *options[i].dblptr=options[i].defdblval;
-          break;
-
-        default:
-          printf("not parsed type for default value %s\n", options[i].optname );
-          exit(1);
-      }
-
-    continue;
-  };
-
+  struct option *long_options = parse_oai_options(options);
   int option_index;
-
   int res;
 
   while ((res=getopt_long_only(argc, argv, "", long_options, &option_index)) == 0) {
@@ -587,6 +459,14 @@ int main(int argc, char **argv) {
             *(double *)options[option_index].dblptr=atof(optarg);
             break;
 
+          case TYPE_UINT8:
+            *(uint8_t *)options[option_index].dblptr=atoi(optarg);
+            break;
+
+          case TYPE_UINT16:
+            *(uint16_t *)options[option_index].dblptr=atoi(optarg);
+            break;
+
           default:
             printf("not decoded type.\n");
             exit(1);
@@ -682,8 +562,12 @@ int main(int argc, char **argv) {
         opp_enabled=1;
         break;
 
+      case 'L':
+        set_parallel_conf(optarg);
+        break;
+
       default:
-        printf("Wrong option\n");
+        printf("Wrong option: %s\n",long_options[option_index].name);
         exit(1);
         break;
     }
@@ -694,36 +578,15 @@ int main(int argc, char **argv) {
     exit(1);
   }
 
-  paramdef_t *ptr=options ;
+  if (help || verbose )
+    display_options_values(options, true);
 
-  for( ptr=options; ptr->optname[0]!=0; ptr++) {
-    char varText[256]="need specific display";
-
-    if (ptr->voidptr != NULL) {
-      if ( (ptr->paramflags & PARAMFLAG_BOOL) )
-        strcpy(varText, *(bool *)ptr->iptr ? "True": "False" );
-      else  switch (ptr->type) {
-          case TYPE_INT:
-            sprintf(varText,"%d",*ptr->iptr);
-            break;
+  if (help)
+    exit(0);
 
-          case TYPE_DOUBLE:
-            sprintf(varText,"%.2f",*ptr->dblptr);
-            break;
+  if (thread_struct.parallel_conf != PARALLEL_SINGLE_THREAD)
+    set_worker_conf("WORKER_ENABLE");
 
-          default:
-            printf("not decoded type\n");
-            exit(1);
-        }
-    }
-
-    printf("Option: %20s set to %s\n",ptr->optname, varText);
-
-    if (verbose)
-      printf("%s\n",ptr->helpstr);
-  }
-  set_parallel_conf("PARALLEL_RU_L1_TRX_SPLIT");
-  set_worker_conf("WORKER_ENABLE");
   RC.nb_L1_inst = 1;
   RC.nb_RU = 1;
   lte_param_init(&eNB,&UE,&ru,
@@ -741,7 +604,7 @@ int main(int argc, char **argv) {
                  threequarter_fs,
                  osf,
                  0);
-  RC.eNB = (PHY_VARS_eNB ***)malloc(sizeof(PHY_VARS_eNB **));
+  RC.eNB = (PHY_VARS_eNB ** *)malloc(sizeof(PHY_VARS_eNB **));
   RC.eNB[0] = (PHY_VARS_eNB **)malloc(sizeof(PHY_VARS_eNB *));
   RC.ru = (RU_t **)malloc(sizeof(RC.ru));
   RC.eNB[0][0] = eNB;
@@ -759,7 +622,7 @@ int main(int argc, char **argv) {
   eNB->UL_INFO.cqi_ind.cqi_raw_pdu_list = eNB->cqi_raw_pdu_list;
   printf("lte_param_init done\n");
   // for a call to phy_reset_ue later we need PHY_vars_UE_g allocated and pointing to UE
-  PHY_vars_UE_g = (PHY_VARS_UE ***)malloc(sizeof(PHY_VARS_UE **));
+  PHY_vars_UE_g = (PHY_VARS_UE ** *)malloc(sizeof(PHY_VARS_UE **));
   PHY_vars_UE_g[0] = (PHY_VARS_UE **) malloc(sizeof(PHY_VARS_UE *));
   PHY_vars_UE_g[0][0] = UE;
 
@@ -871,7 +734,7 @@ int main(int argc, char **argv) {
   UE->ulsch[0]   = new_ue_ulsch(N_RB_DL,0);
   printf("ULSCH %p\n",UE->ulsch[0]);
 
-  if (parallel_flag == 1) {
+  if(get_thread_worker_conf() == WORKER_ENABLE) {
     extern void init_fep_thread(PHY_VARS_eNB *, pthread_attr_t *);
     extern void init_td_thread(PHY_VARS_eNB *);
     init_fep_thread(eNB,NULL);
@@ -922,7 +785,7 @@ int main(int argc, char **argv) {
   UE->frame_parms.pusch_config_common.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH = 0;
   eNB->frame_parms.pusch_config_common.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH = 0;
   UE->mac_enabled=0;
-  eNB_rxtx_proc_t *proc_rxtx   = &eNB->proc.proc_rxtx[subframe&1];
+  L1_rxtx_proc_t *proc_rxtx         = &eNB->proc.L1_proc;
   UE_rxtx_proc_t *proc_rxtx_ue = &UE->proc.proc_rxtx[subframe&1];
   proc_rxtx->frame_rx=1;
   proc_rxtx->subframe_rx=subframe;
@@ -944,7 +807,7 @@ int main(int argc, char **argv) {
   if (cqi_flag == 1) coded_bits_per_codeword-=UE->ulsch[0]->O;
 
   rate = (double)dlsch_tbs25[get_I_TBS(mcs)][nb_rb-1]/(coded_bits_per_codeword);
-  printf("Rate = %f (mod %d), coded bits %d\n",rate,get_Qm_ul(mcs),coded_bits_per_codeword);
+  printf("Rate = %f (mod %d), coded bits %u\n",rate,get_Qm_ul(mcs),coded_bits_per_codeword);
 
   for (ch_realization=0; ch_realization<n_ch_rlz; ch_realization++) {
     /*
@@ -1006,7 +869,7 @@ int main(int argc, char **argv) {
         i=0;
 
         while (!feof(input_fdUL)) {
-          ret=fscanf(input_fdUL,"%s %s",input_val_str,input_val_str2);//&input_val1,&input_val2);
+          ret=fscanf(input_fdUL,"%49s %49s",input_val_str,input_val_str2);//&input_val1,&input_val2);
 
           if (ret != 2) printf("ERROR: error reading file\n");
 
@@ -1093,7 +956,7 @@ int main(int argc, char **argv) {
           eNB->ulsch[0]->harq_processes[harq_pid]->round=round;
           UE->ulsch[0]->harq_processes[harq_pid]->round=round;
 
-          if (n_frames==1) printf("filling ulsch: Trial %d : Round %d (subframe %d, frame %d)\n",trials,round,proc_rxtx_ue->subframe_tx,proc_rxtx_ue->frame_tx);
+          if (n_frames==1) printf("filling ulsch: Trial %u : Round %d (subframe %d, frame %d)\n",trials,round,proc_rxtx_ue->subframe_tx,proc_rxtx_ue->frame_tx);
 
           round_trials[round]++;
           UL_req.sfn_sf = (1<<4)+subframe;
@@ -1184,10 +1047,10 @@ int main(int argc, char **argv) {
           sigma2_dB = N0;//-10*log10(UE->frame_parms.ofdm_symbol_size/(UE->frame_parms.N_RB_DL*12));//10*log10((double)tx_lev)  +10*log10(UE->frame_parms.ofdm_symbol_size/(UE->frame_parms.N_RB_DL*12)) - SNR;
           sigma2 = pow(10,sigma2_dB/10);
           // compute tx_gain to achieve target SNR (per resource element!)
-          tx_gain = sqrt(pow(10.0,.1*(N0+SNR))/(double)tx_lev);//*(nb_rb*12/(double)UE->frame_parms.ofdm_symbol_size)/(double)tx_lev);
+          tx_gain = sqrt(pow(10.0,.1*(N0+SNR))/(double)tx_lev);// *(nb_rb*12/(double)UE->frame_parms.ofdm_symbol_size)/(double)tx_lev);
 
           if (n_frames==1)
-            printf("tx_lev = %d (%d.%d dB,%f), gain %f\n",tx_lev,tx_lev_dB/10,tx_lev_dB,10*log10((double)tx_lev),10*log10(tx_gain));
+            printf("tx_lev = %u (%u.%u dB,%f), gain %f\n",tx_lev,tx_lev_dB/10,tx_lev_dB,10*log10((double)tx_lev),10*log10(tx_gain));
 
           // fill measurement symbol (19) with noise
           for (i=0; i<OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES; i++) {
@@ -1222,7 +1085,7 @@ int main(int argc, char **argv) {
                 // calculate freq domain representation to compute SINR
                 freq_channel(UE2eNB, N_RB_DL,12*N_RB_DL + 1);
                 // snr=pow(10.0,.1*SNR);
-                fprintf(csv_fdUL,"%f,%d,%d,%f,%f,%f,",SNR,tx_lev,tx_lev_dB,sigma2_dB,tx_gain,SNR2);
+                fprintf(csv_fdUL,"%f,%u,%u,%f,%f,%f,",SNR,tx_lev,tx_lev_dB,sigma2_dB,tx_gain,SNR2);
 
                 //fprintf(csv_fdUL,"%f,",SNR);
                 for (u=0; u<12*nb_rb; u++) {
@@ -1278,12 +1141,11 @@ int main(int argc, char **argv) {
             if (eNB->frame_parms.nb_antennas_rx>1) LOG_M("rxsig1UL.m","rxs1", &ru->common.rxdata[1][eNB->frame_parms.samples_per_tti*subframe],eNB->frame_parms.samples_per_tti,1,1);
           }
 
-	  start_meas(&eNB->phy_proc_rx);
-          ru->feprx = (parallel_flag == 1) ? ru_fep_full_2thread        : fep_full;
-          eNB->td  = (parallel_flag == 1) ? ulsch_decoding_data_2thread : ulsch_decoding_data;
+          start_meas(&eNB->phy_proc_rx);
+          ru->feprx = (get_thread_worker_conf() == WORKER_ENABLE) ? ru_fep_full_2thread        : fep_full;
           ru->feprx(ru);
           phy_procedures_eNB_uespec_RX(eNB,proc_rxtx);
-	  stop_meas(&eNB->phy_proc_rx);
+          stop_meas(&eNB->phy_proc_rx);
 
           if (cqi_flag > 0) {
             cqi_error = 0;
@@ -1350,10 +1212,11 @@ int main(int argc, char **argv) {
 
               dump_ulsch(eNB,eNB->proc.frame_rx,subframe,0,round);
 
-              if (round == 4) exit(-1);
+              round=5;
+
             }
 
-            if (n_frames==1) printf("round %d errors %d/%d\n",round,errs[round],trials);
+            if (n_frames==1) printf("round %d errors %u/%u\n",round,errs[round],trials);
 
             round++;
 
@@ -1411,7 +1274,7 @@ int main(int argc, char **argv) {
         LOG_UDUMPMSG(SIM,dataArray(table_rx),table_rx->size,LOG_DUMP_DOUBLE,"The receiver raw data: \n");
       }
 
-      printf("\n**********rb: %d ***mcs : %d  *********SNR = %f dB (%f): TX %d dB (gain %f dB), N0W %f dB, I0 %d dB, delta_IF %d [ (%d,%d) dB / (%d,%d) dB ]**************************\n",
+      printf("\n**********rb: %d ***mcs : %d  *********SNR = %f dB (%f): TX %u dB (gain %f dB), N0W %f dB, I0 %d dB, delta_IF %d [ (%d,%d) dB / (%d,%d) dB ]**************************\n",
              nb_rb,mcs,SNR,SNR2,
              tx_lev_dB,
              20*log10(tx_gain),
@@ -1423,7 +1286,7 @@ int main(int argc, char **argv) {
              eNB->measurements.n0_power_dB[0],
              eNB->measurements.n0_power_dB[1]);
       effective_rate = ((double)(round_trials[0])/((double)round_trials[0] + round_trials[1] + round_trials[2] + round_trials[3]));
-      printf("Errors (%d/%d %d/%d %d/%d %d/%d), Pe = (%e,%e,%e,%e) => effective rate %f (%3.1f%%,%f,%f), normalized delay %f (%f)\n",
+      printf("Errors (%u/%u %u/%u %u/%u %u/%u), Pe = (%e,%e,%e,%e) => effective rate %f (%3.1f%%,%f,%f), normalized delay %f (%f)\n",
              errs[0],
              round_trials[0],
              errs[1],
@@ -1445,16 +1308,16 @@ int main(int argc, char **argv) {
              (1.0*(round_trials[0]-errs[0])+2.0*(round_trials[1]-errs[1])+3.0*(round_trials[2]-errs[2])+4.0*(round_trials[3]-errs[3]))/((double)round_trials[0]));
 
       if (cqi_flag >0) {
-        printf("CQI errors %d/%d,false positives %d/%d, CQI false negatives %d/%d\n",
+        printf("CQI errors %d/%u,false positives %d/%u, CQI false negatives %d/%u\n",
                cqi_errors,round_trials[0]+round_trials[1]+round_trials[2]+round_trials[3],
                cqi_crc_falsepositives,round_trials[0]+round_trials[1]+round_trials[2]+round_trials[3],
                cqi_crc_falsenegatives,round_trials[0]+round_trials[1]+round_trials[2]+round_trials[3]);
       }
 
       if (eNB->ulsch[0]->harq_processes[harq_pid]->o_ACK[0] > 0)
-        printf("ACK/NAK errors %d/%d\n",ack_errors,round_trials[0]+round_trials[1]+round_trials[2]+round_trials[3]);
+        printf("ACK/NAK errors %d/%u\n",ack_errors,round_trials[0]+round_trials[1]+round_trials[2]+round_trials[3]);
 
-      fprintf(bler_fd,"%f;%d;%d;%d;%f;%d;%d;%d;%d;%d;%d;%d;%d\n",
+      fprintf(bler_fd,"%f;%d;%d;%d;%f;%u;%u;%u;%u;%u;%u;%u;%u\n",
               SNR,
               mcs,
               nb_rb,
@@ -1481,20 +1344,18 @@ int main(int argc, char **argv) {
         printStatIndent(&UE->ulsch_rate_matching_stats,"ULSCH rate-matching time");
         printStatIndent(&UE->ulsch_interleaving_stats,"ULSCH sub-block interleaving");
         printStatIndent(&UE->ulsch_multiplexing_stats,"ULSCH multiplexing time");
-        printDistribution(&eNB->phy_proc_rx,table_rx,"\nTotal PHY proc rx subframe");
-        printDistribution(&ru->ofdm_demod_stats,table_rx_fft,"OFDM_demod time");
-        printDistribution(&eNB->ulsch_demodulation_stats,table_rx_demod,"ULSCH demodulation time");
-        printf("ULSCH Decoding time (%.2f Mbit/s, avg iter %.2f)      :%.2f us (%d trials, max %.2f)\n",
-               UE->ulsch[0]->harq_processes[harq_pid]->TBS/1000.0,(double)iter_trials,
-               (double)eNB->ulsch_decoding_stats.diff/eNB->ulsch_decoding_stats.trials*timeBase,
-               eNB->ulsch_decoding_stats.trials,
+        printf("\n");
+        printDistribution(&eNB->phy_proc_rx,table_rx,"Total PHY proc rx subframe");
+        printDistribution(&ru->ofdm_demod_stats,table_rx_fft,"|__ OFDM_demod time");
+        printDistribution(&eNB->ulsch_demodulation_stats,table_rx_demod,"|__ ULSCH demodulation time");
+        printDistribution(&eNB->ulsch_decoding_stats,table_rx_dec,"|__ ULSCH Decoding time");
+        printf("     (%.2f Mbit/s, avg iter %.2f, max %.2f)\n",
+               UE->ulsch[0]->harq_processes[harq_pid]->TBS/1000.0,
+               (double)iter_trials,
                (double)eNB->ulsch_decoding_stats.max*timeBase);
-        printf("|__ Statistics                           std: %.2fus median %.2fus q1 %.2fus q3 %.2fus \n",
-               squareRoot(&eNB->ulsch_decoding_stats),
-               median(table_rx_dec), q1(table_rx_dec), q3(table_rx_dec));
-        printStatIndent(&eNB->ulsch_deinterleaving_stats,"sub-block interleaving" );
-        printStatIndent(&eNB->ulsch_demultiplexing_stats,"sub-block demultiplexing" );
-        printStatIndent(&eNB->ulsch_rate_unmatching_stats,"sub-block rate-matching" );
+        printStatIndent2(&eNB->ulsch_deinterleaving_stats,"sub-block interleaving" );
+        printStatIndent2(&eNB->ulsch_demultiplexing_stats,"sub-block demultiplexing" );
+        printStatIndent2(&eNB->ulsch_rate_unmatching_stats,"sub-block rate-matching" );
         printf("|__ turbo_decoder(%d bits), avg iterations: %.1f       %.2f us (%d cycles, %d trials)\n",
                eNB->ulsch[0]->harq_processes[harq_pid]->Cminus ?
                eNB->ulsch[0]->harq_processes[harq_pid]->Kminus :
@@ -1503,13 +1364,13 @@ int main(int argc, char **argv) {
                (double)eNB->ulsch_turbo_decoding_stats.diff/eNB->ulsch_turbo_decoding_stats.trials*timeBase,
                (int)((double)eNB->ulsch_turbo_decoding_stats.diff/eNB->ulsch_turbo_decoding_stats.trials),
                eNB->ulsch_turbo_decoding_stats.trials);
-        printStatIndent2(&eNB->ulsch_tc_init_stats,"init", eNB->ulsch_tc_init_stats.trials);
-        printStatIndent2(&eNB->ulsch_tc_alpha_stats,"alpha", eNB->ulsch_tc_init_stats.trials);
-        printStatIndent2(&eNB->ulsch_tc_beta_stats,"beta", eNB->ulsch_tc_init_stats.trials);
-        printStatIndent2(&eNB->ulsch_tc_gamma_stats,"gamma", eNB->ulsch_tc_init_stats.trials);
-        printStatIndent2(&eNB->ulsch_tc_ext_stats,"ext", eNB->ulsch_tc_init_stats.trials);
-        printStatIndent2(&eNB->ulsch_tc_intl1_stats,"turbo internal interleaver", eNB->ulsch_tc_init_stats.trials);
-        printStatIndent2(&eNB->ulsch_tc_intl2_stats,"intl2+HardDecode+CRC", eNB->ulsch_tc_init_stats.trials);
+        printStatIndent3(&eNB->ulsch_tc_init_stats,"init");
+        printStatIndent3(&eNB->ulsch_tc_alpha_stats,"alpha");
+        printStatIndent3(&eNB->ulsch_tc_beta_stats,"beta");
+        printStatIndent3(&eNB->ulsch_tc_gamma_stats,"gamma");
+        printStatIndent3(&eNB->ulsch_tc_ext_stats,"ext");
+        printStatIndent3(&eNB->ulsch_tc_intl1_stats,"turbo internal interleaver");
+        printStatIndent3(&eNB->ulsch_tc_intl2_stats,"intl2+HardDecode+CRC");
       }
 
       if(abstx) { //ABSTRACTION
@@ -1529,7 +1390,7 @@ int main(int argc, char **argv) {
 
       if ( (test_perf != 0) && (100 * effective_rate > test_perf )) {
         //fprintf(time_meas_fd,"SNR; MCS; TBS; rate; err0; trials0; err1; trials1; err2; trials2; err3; trials3\n");
-        fprintf(time_meas_fd,"%f;%d;%d;%f;%d;%d;%d;%d;%d;%d;%d;%d;",
+        fprintf(time_meas_fd,"%f;%d;%d;%f;%u;%u;%u;%u;%u;%u;%u;%u;",
                 SNR,
                 mcs,
                 eNB->ulsch[0]->harq_processes[harq_pid]->TBS,
@@ -1543,7 +1404,7 @@ int main(int argc, char **argv) {
                 errs[3],
                 round_trials[3]);
         //fprintf(time_meas_fd,"SNR; MCS; TBS; rate; err0; trials0; err1; trials1; err2; trials2; err3; trials3;ND;\n");
-        fprintf(time_meas_fd,"%f;%d;%d;%f;%2.1f;%f;%d;%d;%d;%d;%d;%d;%d;%d;%e;%e;%e;%e;%f;%f;",
+        fprintf(time_meas_fd,"%f;%d;%d;%f;%2.1f;%f;%u;%u;%u;%u;%u;%u;%u;%u;%e;%e;%e;%e;%f;%f;",
                 SNR,
                 mcs,
                 eNB->ulsch[0]->harq_processes[harq_pid]->TBS,
@@ -1588,34 +1449,34 @@ int main(int argc, char **argv) {
                );
         //fprintf(time_meas_fd,"UE_PROC_TX_STD;UE_PROC_TX_MAX;UE_PROC_TX_MIN;UE_PROC_TX_MED;UE_PROC_TX_Q1;UE_PROC_TX_Q3;UE_PROC_TX_DROPPED;\n");
         fprintf(time_meas_fd,"%f;%f;%f;%f;%f;%f;%d;",
-		squareRoot(&UE->phy_proc_tx), t_tx_max, t_tx_min, median(table_tx), q1(table_tx), q3(table_tx), n_tx_dropped);
+                squareRoot(&UE->phy_proc_tx), t_tx_max, t_tx_min, median(table_tx), q1(table_tx), q3(table_tx), n_tx_dropped);
         //fprintf(time_meas_fd,"IFFT;\n");
         fprintf(time_meas_fd,"%f;%f;%f;%f;",
-		squareRoot(&UE->ofdm_mod_stats),
+                squareRoot(&UE->ofdm_mod_stats),
                 median(table_tx_ifft),q1(table_tx_ifft),q3(table_tx_ifft));
         //fprintf(time_meas_fd,"MOD;\n");
         fprintf(time_meas_fd,"%f;%f;%f;%f;",
-		squareRoot(&UE->ulsch_modulation_stats),
+                squareRoot(&UE->ulsch_modulation_stats),
                 median(table_tx_mod), q1(table_tx_mod), q3(table_tx_mod));
         //fprintf(time_meas_fd,"ENC;\n");
         fprintf(time_meas_fd,"%f;%f;%f;%f;",
-		squareRoot(&UE->ulsch_encoding_stats),
+                squareRoot(&UE->ulsch_encoding_stats),
                 median(table_tx_enc),q1(table_tx_enc),q3(table_tx_enc));
         //fprintf(time_meas_fd,"eNB_PROC_RX_STD;eNB_PROC_RX_MAX;eNB_PROC_RX_MIN;eNB_PROC_RX_MED;eNB_PROC_RX_Q1;eNB_PROC_RX_Q3;eNB_PROC_RX_DROPPED;\n");
         fprintf(time_meas_fd,"%f;%f;%f;%f;%f;%f;%d;",
-		squareRoot(&eNB->phy_proc_rx), t_rx_max, t_rx_min,
+                squareRoot(&eNB->phy_proc_rx), t_rx_max, t_rx_min,
                 median(table_rx), q1(table_rx), q3(table_rx), n_rx_dropped);
         //fprintf(time_meas_fd,"FFT;\n");
         fprintf(time_meas_fd,"%f;%f;%f;%f;",
-		squareRoot(&ru->ofdm_demod_stats),
+                squareRoot(&ru->ofdm_demod_stats),
                 median(table_rx_fft), q1(table_rx_fft), q3(table_rx_fft));
         //fprintf(time_meas_fd,"DEMOD;\n");
         fprintf(time_meas_fd,"%f;%f;%f;%f;",
-		squareRoot(&eNB->ulsch_demodulation_stats),
+                squareRoot(&eNB->ulsch_demodulation_stats),
                 median(table_rx_demod), q1(table_rx_demod), q3(table_rx_demod));
         //fprintf(time_meas_fd,"DEC;\n");
         fprintf(time_meas_fd,"%f;%f;%f;%f\n",
-		squareRoot(&eNB->ulsch_decoding_stats),
+                squareRoot(&eNB->ulsch_decoding_stats),
                 median(table_rx_dec), q1(table_rx_dec), q3(table_rx_dec));
         printf("[passed] effective rate : %f  (%2.1f%%,%f)): log and break \n",rate*effective_rate, 100*effective_rate, rate );
         break;
diff --git a/openair1/SIMULATION/TOOLS/abstraction.c b/openair1/SIMULATION/TOOLS/abstraction.c
index 6b846bb2d5db9e584d54cfd027792506d6363ae8..7ac19804176115087bb1db54b803543bd20a7bf9 100644
--- a/openair1/SIMULATION/TOOLS/abstraction.c
+++ b/openair1/SIMULATION/TOOLS/abstraction.c
@@ -32,17 +32,14 @@
 
 // NEW code with lookup table for sin/cos based on delay profile (TO BE TESTED)
 
-double **cos_lut=NULL,**sin_lut=NULL;
+double **cos_lut=NULL,* *sin_lut=NULL;
 
 
 //#if 1
 
 
 
-int init_freq_channel(channel_desc_t *desc,uint16_t nb_rb,int16_t n_samples)
-{
-
-
+int init_freq_channel(channel_desc_t *desc,uint16_t nb_rb,int16_t n_samples) {
   double delta_f,freq;  // 90 kHz spacing
   double delay;
   int16_t f;
@@ -50,21 +47,18 @@ int init_freq_channel(channel_desc_t *desc,uint16_t nb_rb,int16_t n_samples)
 
   if ((n_samples&1)==0) {
     fprintf(stderr, "freq_channel_init: n_samples has to be odd\n");
-    return(-1); 
+    return(-1);
   }
 
-  cos_lut = (double **)malloc(n_samples*sizeof(double*));
-  sin_lut = (double **)malloc(n_samples*sizeof(double*));
-
+  cos_lut = (double **)malloc(n_samples*sizeof(double *));
+  sin_lut = (double **)malloc(n_samples*sizeof(double *));
   delta_f = nb_rb*180000/(n_samples-1);
 
   for (f=-(n_samples>>1); f<=(n_samples>>1); f++) {
     freq=delta_f*(double)f*1e-6;// due to the fact that delays is in mus
-
     cos_lut[f+(n_samples>>1)] = (double *)malloc((int)desc->nb_taps*sizeof(double));
     sin_lut[f+(n_samples>>1)] = (double *)malloc((int)desc->nb_taps*sizeof(double));
 
-
     for (l=0; l<(int)desc->nb_taps; l++) {
       if (desc->nb_taps==1)
         delay = desc->delays[l];
@@ -74,17 +68,13 @@ int init_freq_channel(channel_desc_t *desc,uint16_t nb_rb,int16_t n_samples)
       cos_lut[f+(n_samples>>1)][l] = cos(2*M_PI*freq*delay);
       sin_lut[f+(n_samples>>1)][l] = sin(2*M_PI*freq*delay);
       //printf("values cos:%d, sin:%d\n", cos_lut[f][l], sin_lut[f][l]);
-
     }
   }
 
   return(0);
 }
 
-int freq_channel(channel_desc_t *desc,uint16_t nb_rb,int16_t n_samples)
-{
-
-
+int freq_channel(channel_desc_t *desc,uint16_t nb_rb,int16_t n_samples) {
   int16_t f,f2,d;
   uint8_t aarx,aatx,l;
   double *clut,*slut;
@@ -95,7 +85,7 @@ int freq_channel(channel_desc_t *desc,uint16_t nb_rb,int16_t n_samples)
   // n_samples has to be a odd number because we assume the spectrum is symmetric around the DC and includes the DC
   if ((n_samples&1)==0) {
     fprintf(stderr, "freq_channel: n_samples has to be odd\n");
-    return(-1); 
+    return(-1);
   }
 
   // printf("no of taps:%d,",(int)desc->nb_taps);
@@ -104,6 +94,7 @@ int freq_channel(channel_desc_t *desc,uint16_t nb_rb,int16_t n_samples)
     // we are initializing the lut for the largets possible n_samples=12*nb_rb+1
     // if called with n_samples<12*nb_rb+1, we decimate the lut
     n_samples_max=12*nb_rb+1;
+
     if (init_freq_channel(desc,nb_rb,n_samples_max)==0)
       freq_channel_init=1;
     else
@@ -111,9 +102,7 @@ int freq_channel(channel_desc_t *desc,uint16_t nb_rb,int16_t n_samples)
   }
 
   d=(n_samples_max-1)/(n_samples-1);
-
   //printf("no_samples=%d, n_samples_max=%d, d=%d\n",n_samples,n_samples_max,d);
-
   start_meas(&desc->interp_freq);
 
   for (f=-n_samples_max/2,f2=-n_samples/2; f<n_samples_max/2; f+=d,f2++) {
@@ -126,7 +115,6 @@ int freq_channel(channel_desc_t *desc,uint16_t nb_rb,int16_t n_samples)
         desc->chF[aarx+(aatx*desc->nb_rx)][n_samples/2+f2].y=0.0;
 
         for (l=0; l<(int)desc->nb_taps; l++) {
-
           desc->chF[aarx+(aatx*desc->nb_rx)][n_samples/2+f2].x+=(desc->a[l][aarx+(aatx*desc->nb_rx)].x*clut[l]+
               desc->a[l][aarx+(aatx*desc->nb_rx)].y*slut[l]);
           desc->chF[aarx+(aatx*desc->nb_rx)][n_samples/2+f2].y+=(-desc->a[l][aarx+(aatx*desc->nb_rx)].x*slut[l]+
@@ -137,7 +125,6 @@ int freq_channel(channel_desc_t *desc,uint16_t nb_rb,int16_t n_samples)
   }
 
   stop_meas(&desc->interp_freq);
-
   return(0);
 }
 
@@ -146,16 +133,13 @@ double compute_pbch_sinr(channel_desc_t *desc,
                          channel_desc_t *desc_i2,
                          double snr_dB,double snr_i1_dB,
                          double snr_i2_dB,
-                         uint16_t nb_rb)
-{
-
+                         uint16_t nb_rb) {
   double avg_sinr,snr=pow(10.0,.1*snr_dB),snr_i1=pow(10.0,.1*snr_i1_dB),snr_i2=pow(10.0,.1*snr_i2_dB);
   uint16_t f;
   uint8_t aarx,aatx;
   double S;
   struct complex S_i1;
   struct complex S_i2;
-
   avg_sinr=0.0;
 
   //  printf("nb_rb %d\n",nb_rb);
@@ -202,18 +186,14 @@ double compute_sinr(channel_desc_t *desc,
                     channel_desc_t *desc_i2,
                     double snr_dB,double snr_i1_dB,
                     double snr_i2_dB,
-                    uint16_t nb_rb)
-{
-
+                    uint16_t nb_rb) {
   double avg_sinr,snr=pow(10.0,.1*snr_dB),snr_i1=pow(10.0,.1*snr_i1_dB),snr_i2=pow(10.0,.1*snr_i2_dB);
   uint16_t f;
   uint8_t aarx,aatx;
   double S;
   struct complex S_i1;
   struct complex S_i2;
-
   DevAssert( nb_rb > 0 );
-
   avg_sinr=0.0;
 
   //  printf("nb_rb %d\n",nb_rb);
@@ -256,12 +236,9 @@ double compute_sinr(channel_desc_t *desc,
 int pbch_polynomial_degree=6;
 double pbch_awgn_polynomial[7]= {-7.2926e-05, -2.8749e-03, -4.5064e-02, -3.5301e-01, -1.4655e+00, -3.6282e+00, -6.6907e+00};
 
-void load_pbch_desc(FILE *pbch_file_fd)
-{
-
+void load_pbch_desc(FILE *pbch_file_fd) {
   int i, ret;
   char dummy[25];
-
   ret = fscanf(pbch_file_fd,"%d",&pbch_polynomial_degree);
 
   if (ret < 0) {
@@ -277,7 +254,7 @@ void load_pbch_desc(FILE *pbch_file_fd)
   printf("PBCH polynomial : ");
 
   for (i=0; i<=pbch_polynomial_degree; i++) {
-    ret = fscanf(pbch_file_fd,"%s",dummy);
+    ret = fscanf(pbch_file_fd,"%24s",dummy);
 
     if (ret < 0) {
       printf("fscanf failed: %s\n", strerror(errno));
@@ -291,9 +268,7 @@ void load_pbch_desc(FILE *pbch_file_fd)
   printf("\n");
 }
 
-double pbch_bler(double sinr)
-{
-
+double pbch_bler(double sinr) {
   int i;
   double log10_bler=pbch_awgn_polynomial[pbch_polynomial_degree];
   double sinrpow=sinr;
@@ -317,6 +292,5 @@ double pbch_bler(double sinr)
 
   //printf ("sinr %f bler %f\n",sinr,bler);
   return(bler);
-
 }
 
diff --git a/openair1/SIMULATION/TOOLS/ch_desc_proto.c b/openair1/SIMULATION/TOOLS/ch_desc_proto.c
index 8b07a596a925774c1c6cdc4a9296bcec2e8673be..b1e71fcfb4a0c99bd2066e9d58dedf342860de9d 100644
--- a/openair1/SIMULATION/TOOLS/ch_desc_proto.c
+++ b/openair1/SIMULATION/TOOLS/ch_desc_proto.c
@@ -31,17 +31,14 @@
 enum sector {SEC1, SEC2, SEC3};
 scenario_desc_t scenario;
 
-void get_chan_desc(node_desc_t* node_tx, node_desc_t* node_rx, channel_desc_t *ch_desc, scenario_desc_t* scenario)
-{
+void get_chan_desc(node_desc_t *node_tx, node_desc_t *node_rx, channel_desc_t *ch_desc, scenario_desc_t *scenario) {
   double dist;
   dist = sqrt(pow((node_tx->x - node_rx->x), 2) + pow((node_tx->y - node_rx->y), 2));
-
   /* conversion of distance into KM 3gpp (36-942)*/
   ch_desc->path_loss_dB = (128.1 + 37.6 * log10(dist/1000));
 }
 
-int main()
-{
+int main() {
   int enb_count = 16;
   int ue_count = 50;
   double sect_angle[3]= {0,2*PI/3,4*PI/3};
@@ -75,19 +72,16 @@ int main()
                       "bler_9.csv", "bler_10.csv", "bler_11.csv", "bler_12.csv", "bler_13.csv", "bler_14.csv", "bler_15.csv", "bler_16.csv",
                       "bler_17.csv", "bler_18.csv", "bler_19.csv", "bler_20.csv", "bler_21.csv", "bler_22.csv"
                      };
-
   double beta[MCS_COUNT] = {0, 0, 0, 0, 0.9459960937499999, 1.2912109374999994, 1.0133789062499998, 1.000390625,
                             1.02392578125, 1.8595703124999998, 2.424389648437498, 2.3946533203124982, 2.5790039062499988,
                             2.4084960937499984, 2.782617187499999, 2.7868652343749996, 3.92099609375, 4.0392578125,
                             4.56109619140625, 5.03338623046875, 5.810888671875, 6.449108886718749
                            };
-
   double enb_position[][2] = {{1100,1100},{1100,2100},{1100,3100},{1100,4100},
     {2100,1100},{2100,2100},{2100,3100},{2100,4100},
     {3100,1100},{3100,2100},{3100,3100},{3100,4100},
     {4100,1100},{4100,2100},{4100,3100},{4100,4100}
   };
-
   double ue_position[][2] = {{3340,4740},{1500,620},{1780,4220},{1300,3540},{780,3100},
     {1140,540},{1340,3660},{860,1220},{2700,2140},{3860,3060},
     {3740,1060},{1700,3060},{2180,1620},{4420,1060},{1300,3340},
@@ -99,15 +93,12 @@ int main()
     {3420,2820},{1580,3940},{660,2100},{2740,1180},{2500,2500},
     {3580,3580},{3740,3140},{3020,3020},{4340,4140},{980,4300}
   };
-
   randominit(0);
-
   /////////////////////////////////////////////////////////////////////////////////////////////////
   int tabl_len=0;
   double local_table[MCS_COUNT][9][9];
 
   for (mcs = 5; mcs <= MCS_COUNT; mcs++) {
-
     fp = fopen(file_name[mcs - 1],"r");
 
     if (fp == NULL) {
@@ -117,7 +108,6 @@ int main()
       tabl_len=0;
 
       while (!feof(fp)) {
-
         sinr_bler = strtok(buffer, ";");
         local_table[mcs-1][0][tabl_len] = atof(sinr_bler);
         sinr_bler = strtok(NULL,";");
@@ -133,12 +123,8 @@ int main()
 
     for (tabl_len=0; tabl_len<9; tabl_len++)
       printf("%lf  %lf \n ",local_table[mcs-1][0][tabl_len],local_table[mcs-1][1][tabl_len]);
-
-
   }
 
-
-
   ////////////////////////////////////////////////////////////////////////////////////////////////////
 
   for (enb_index = 0; enb_index < enb_count; enb_index++)
@@ -172,7 +158,6 @@ int main()
       ul_channel[ue_index][enb_index] = new_channel_desc_scm(1, 1, SCM_C, 7.68, 0, 0, 0);
       dl_channel[ue_index][enb_index] = new_channel_desc_scm(1, 1, SCM_C, 7.68, 0, 0, 0);
       //printf("ue %d enb %d\n", ue_index, enb_index);
-
       /* Calculating the angle in the range -pi to pi from the slope */
       //(ue_data[ue_index])->alpha_rad[enb_index] = (double)(atan2((ue_data[ue_index]->x - enb_data[enb_index]->x), (ue_data[ue_index]->y - enb_data[enb_index]->y)));
       ue_data[ue_index]->alpha_rad[enb_index] = atan2((ue_data[ue_index]->x - enb_data[enb_index]->x), (ue_data[ue_index]->y - enb_data[enb_index]->y));
@@ -190,8 +175,7 @@ int main()
 
       /* gain = -min(Am , 12 * (theta/theta_3dB)^2) */
       gain_max = (gain_sec[SEC1] > gain_sec[SEC2]) ? ((gain_sec[SEC1] > gain_sec[SEC3]) ? gain_sec[SEC1]:gain_sec[SEC3]) :
-                   ((gain_sec[SEC2] > gain_sec[SEC3]) ? gain_sec[SEC2]:gain_sec[SEC3]);
-
+                 ((gain_sec[SEC2] > gain_sec[SEC3]) ? gain_sec[SEC2]:gain_sec[SEC3]);
       get_chan_desc(enb_data[enb_index], ue_data[ue_index], ul_channel[ue_index][enb_index], &scenario);
       get_chan_desc(enb_data[enb_index], ue_data[ue_index], dl_channel[ue_index][enb_index], &scenario);
 
@@ -204,7 +188,6 @@ int main()
 
       //return_value = random_channel(ul_channel[ue_index][enb_index]);
       return_value = random_channel(dl_channel[ue_index][enb_index]);
-
       /* Thermal noise is calculated using 10log10(K*T*B) K = Boltzmann´s constant T = room temperature B = bandwidth */
       /* Taken as constant for the time being since the BW is not changing */
       thermal_noise = -105; //value in dBm
@@ -222,7 +205,6 @@ int main()
                                    - (thermal_noise + ue_data[ue_index]->rx_noise_level)
                                    + 10 * log10 (pow(dl_channel[ue_index][enb_index]->chF[0][count].r, 2)
                                                  + pow(dl_channel[ue_index][enb_index]->chF[0][count].i, 2));
-
           //printf("Dl_link SNR for res. block %d is %lf\n", count, sinr[enb_index][count]);
         }
       }
@@ -252,7 +234,6 @@ int main()
       //printf("mcs value  %d \n",mcs);
       //printf("beta value  %lf \n",-beta[mcs-1]);
       //printf("snr_eff value  %lf \n",log(sinr_eff[ue_index][mcs-1]));
-
       sinr_eff[ue_index][mcs-1] =  -beta[mcs-1] *log((sinr_eff[ue_index][mcs-1])/(2*nb_rb));//
       //printf("snr_eff value  %lf \n",sinr_eff[ue_index][mcs-1]);
       sinr_eff[ue_index][mcs-1] = 10 * log10(sinr_eff[ue_index][mcs-1]);
@@ -264,9 +245,7 @@ int main()
       }
 
       sinr_eff[ue_index][mcs-1] /= 10;
-
       //printf("Effective snr   %lf  \n",sinr_eff[ue_index][mcs-1]);
-
       bler[ue_index][mcs-1] = 0;
 
       /*line_num = 0;
@@ -295,37 +274,31 @@ int main()
         }
         fclose(fp);*/
       for (tabl_len=0; tabl_len<9; tabl_len++) {
-
         if(tabl_len==0)
           if (sinr_eff[ue_index][mcs-1] < local_table[mcs-1][0][tabl_len]) {
             bler[ue_index][mcs-1] = 1;
             break;
           }
 
-
         if (sinr_eff[ue_index][mcs-1] == local_table[mcs-1][0][tabl_len]) {
           bler[ue_index][mcs-1] = local_table[mcs-1][1][tabl_len];
         }
-
       }
 
       //printf("\n###Dl_link UE %d attached to eNB %d \n MCS %d effective SNR %lf BLER %lf", ue_index, att_enb_index, mcs,sinr_eff[ue_index][mcs-1],bler[ue_index][mcs-1]);
     }
 
     //printf("\n\n");
-
     printf("\n     Ue_ix enb_ix  mcs5    mcs6    mcs7    mcs8    mcs9   mcs10   mcs11   mcs12   mcs13\
    mcs14   mcs15   mcs16   mcs17   mcs18   mcs19   mcs20   mcs21   mcs22\n");
-
     printf("SINR %4d   %4d  %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f\
-   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f\n",
+   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f\n",
            ue_index, att_enb_index, sinr_eff[ue_index][4], sinr_eff[ue_index][5], sinr_eff[ue_index][6], sinr_eff[ue_index][7],
            sinr_eff[ue_index][8], sinr_eff[ue_index][9], sinr_eff[ue_index][10], sinr_eff[ue_index][11], sinr_eff[ue_index][12],
            sinr_eff[ue_index][13], sinr_eff[ue_index][14], sinr_eff[ue_index][15], sinr_eff[ue_index][16], sinr_eff[ue_index][17],
            sinr_eff[ue_index][18], sinr_eff[ue_index][19], sinr_eff[ue_index][20], sinr_eff[ue_index][21], sinr_eff[ue_index][22]);
-
     printf("BLER %4d   %4d  %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f\
-   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f\n",
+   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f   %+4.2f  %+4.2f\n",
            ue_index, att_enb_index, bler[ue_index][4], bler[ue_index][5], bler[ue_index][6], bler[ue_index][7],
            bler[ue_index][8], bler[ue_index][9], bler[ue_index][10], bler[ue_index][11], bler[ue_index][12],
            bler[ue_index][13], bler[ue_index][14], bler[ue_index][15], bler[ue_index][16], bler[ue_index][17],
diff --git a/openair1/SIMULATION/TOOLS/gauss.c b/openair1/SIMULATION/TOOLS/gauss.c
index f69748270b0cc8a4baf23e54ae8fc0259159913e..cc4b1fb793e1115bc2c8de5bc7abb5b603f7369d 100644
--- a/openair1/SIMULATION/TOOLS/gauss.c
+++ b/openair1/SIMULATION/TOOLS/gauss.c
@@ -27,20 +27,15 @@
 
 unsigned int *generate_gauss_LUT(unsigned char Nbits,
                                  unsigned char L
-                                )
-{
-
+                                ) {
   unsigned int *LUT_ptr,i;
-
   LUT_ptr = (unsigned int *)malloc((1<<(Nbits-1))*sizeof(int));
   assert(LUT_ptr);
 
-
   for (i=0; i<(1<<(Nbits-1)); i++) {
     LUT_ptr[i] = (unsigned int)((double)((unsigned int)(1<<31))*erf(i*L/(double)(1<<(Nbits-1))));
-
 #ifdef LUTDEBUG
-    printf("pos %d : LUT_ptr[%d]=%x (%f)\n",i,i,LUT_ptr[i],(double)(erf(i*L/(double)(1<<(Nbits-1)))));
+    printf("pos %u : LUT_ptr[%u]=%x (%f)\n",i,i,LUT_ptr[i],(double)(erf(i*L/(double)(1<<(Nbits-1)))));
 #endif //LUTDEBUG
   }
 
@@ -51,40 +46,29 @@ unsigned int *generate_gauss_LUT(unsigned char Nbits,
 
 int gauss(unsigned int *gauss_LUT,
           unsigned char Nbits
-         )
-{
-
+         ) {
   unsigned int search_pos,step_size,u,tmp,tmpm1,tmpp1,s;
-
   // Get a 32-bit uniform random-variable
   u = taus();
-
 #ifdef DEBUG
   printf("u = %u\n",u);
 #endif //DEBUG
-
   // if it is larger than 2^31 (here negative), save the sign and rescale down to 31-bits.
-
   s = u & 0x80000000;
   u &= 0x7fffffff;
-
-
 #ifdef DEBUG
-  printf("u = %x,s=%d\n",u,s);
+  printf("u = %x,s=%u\n",u,s);
 #endif //DEBUG
-
   search_pos = (1<<(Nbits-2));   // starting position of the binary search
   step_size  = search_pos;
 
   do {
-
     step_size >>= 1;
-
     tmp = gauss_LUT[search_pos];
     tmpm1 = gauss_LUT[search_pos-1];
     tmpp1 = gauss_LUT[search_pos+1];
 #ifdef DEBUG
-    printf("search_pos %d, step_size %d: t %x tm %x,tp %x\n",search_pos,step_size,tmp,tmpm1,tmpp1);
+    printf("search_pos %u, step_size %u: t %x tm %x,tp %x\n",search_pos,step_size,tmp,tmpm1,tmpp1);
 #endif //DEBUG
 
     if (u <= tmp)
@@ -96,12 +80,10 @@ int gauss(unsigned int *gauss_LUT,
       return s==0 ? search_pos : - search_pos;
     else
       search_pos += step_size;
-
   } while (step_size > 0);
 
   // If it gets here we're beyond the positive edge  so return max
   return s==0 ? (1<<(Nbits-1))-1 : 1-((1<<(Nbits-1)));
-
 }
 
 
@@ -109,9 +91,7 @@ int gauss(unsigned int *gauss_LUT,
 
 #define Nhistbits 8
 
-void main(int argc,char **argv)
-{
-
+void main(int argc,char **argv) {
   unsigned int *gauss_LUT_ptr,i;
   unsigned int hist[(1<<Nhistbits)];
   int gvar,maxg=0,ming=9999999,maxnum=0,L,Ntrials,Nbits;
@@ -125,7 +105,6 @@ void main(int argc,char **argv)
   Nbits   = atoi(argv[1]);
   L       = atoi(argv[2]);
   Ntrials = atoi(argv[3]);
-
   set_taus_seed();
   // Generate Gaussian LUT 12-bit quantization over 5 standard deviations
   gauss_LUT_ptr = generate_gauss_LUT(Nbits,L);
@@ -134,7 +113,6 @@ void main(int argc,char **argv)
     hist[i] = 0;
 
   for (i=0; i<Ntrials; i++) {
-
     gvar = gauss(gauss_LUT_ptr,Nbits);
 
     if (gvar == ((1<<(Nbits-1))-1))
@@ -151,10 +129,8 @@ void main(int argc,char **argv)
 
   printf("Tail probability = %e(%x)\n",2*erfc((double)L*gauss_LUT_ptr[(1<<(Nbits-1))-1]/(unsigned int)(1<<31)),gauss_LUT_ptr[(1<<(Nbits-1))-1]);
   printf("max %d, min %d, mean %f, stddev %f, Pr(maxnum)=%e(%d)\n",maxg,ming,meang,sqrt(varg),(double)maxnum/Ntrials,maxnum);
-
   //  for (i=0;i<(1<<Nhistbits);i++)
   //    printf("%d : %u\n",i,hist[i]);
-
   free(gauss_LUT_ptr);
 }
 
diff --git a/openair1/SIMULATION/TOOLS/multipath_tv_channel.c b/openair1/SIMULATION/TOOLS/multipath_tv_channel.c
index daa3462b1c85c1f4cf6ec22fcb29cea1e740c6e3..f4835570bf386eef8435720825d8e620c3b49c37 100644
--- a/openair1/SIMULATION/TOOLS/multipath_tv_channel.c
+++ b/openair1/SIMULATION/TOOLS/multipath_tv_channel.c
@@ -37,24 +37,18 @@ void multipath_tv_channel(channel_desc_t *desc,
                           double **rx_sig_re,
                           double **rx_sig_im,
                           uint16_t length,
-                          uint8_t keep_channel)
-{
-
-  double complex **tx,**rx,***H_t,*rx_temp;//, *tv_H_t;
+                          uint8_t keep_channel) {
+  double complex **tx,**rx,* **H_t,*rx_temp; //, *tv_H_t;
   double path_loss = pow(10,desc->path_loss_dB/20);
   int i,j,k,dd;
-
   dd = abs(desc->channel_offset);
-
 #ifdef DEBUG_CH
-  printf("[TV CHANNEL] keep = %d : path_loss = %g (%f), nb_rx %d, nb_tx %d, dd %d, len %d max_doppler %d\n",keep_channel,path_loss,desc->path_loss_dB,desc->nb_rx,desc->nb_tx,dd,desc->channel_length,
+  printf("[TV CHANNEL] keep = %d : path_loss = %g (%f), nb_rx %d, nb_tx %d, dd %d, len %d max_doppler %g\n",keep_channel,path_loss,desc->path_loss_dB,desc->nb_rx,desc->nb_tx,dd,desc->channel_length,
          desc->max_Doppler);
 #endif
-
   tx = (double complex **)malloc(desc->nb_tx*sizeof(double complex));
   rx = (double complex **)malloc(desc->nb_rx*sizeof(double complex));
-
-  H_t= (double complex ***) malloc(desc->nb_tx*desc->nb_rx*sizeof(double complex **));
+  H_t= (double complex ** *) malloc(desc->nb_tx*desc->nb_rx*sizeof(double complex **));
   //  tv_H_t = (double complex *) malloc(length*sizeof(double complex));
   rx_temp= (double complex *) calloc(length,sizeof(double complex));
 
@@ -128,17 +122,13 @@ void multipath_tv_channel(channel_desc_t *desc,
   }
 
   free(H_t);
-
   free(rx_temp);
 }
 
 //TODO: make phi_rad a parameter of this function
-void tv_channel(channel_desc_t *desc,double complex ***H,uint16_t length)
-{
-
+void tv_channel(channel_desc_t *desc,double complex ***H,uint16_t length) {
   int i,j,p,l,k;
   double *alpha,*phi_rad,pi=acos(-1),*w_Hz;
-
   alpha = (double *)calloc(desc->nb_paths,sizeof(double));
   phi_rad = (double *)calloc(desc->nb_paths,sizeof(double));
   w_Hz = (double *)calloc(desc->nb_paths,sizeof(double));
@@ -203,21 +193,17 @@ void tv_channel(channel_desc_t *desc,double complex ***H,uint16_t length)
 }
 
 // time varying convolution
-void tv_conv(double complex **h, double complex *x, double complex *y, uint16_t nb_samples, uint8_t nb_taps, int dd)
-{
-
+void tv_conv(double complex **h, double complex *x, double complex *y, uint16_t nb_samples, uint8_t nb_taps, int dd) {
   int i,j;
 
   for(i=0; i<((int)nb_samples-dd); i++) {
     for(j=0; j<nb_taps; j++) {
       if(i>j)
         y[i+dd] += creal(h[i][j])*creal(x[i-j])-cimag(h[i][j])*cimag(x[i-j]) + I*(creal(h[i][j])*cimag(x[i-j])+cimag(h[i][j])*creal(x[i-j]));
-
     }
   }
 }
 
-double frand_a_b(double a, double b)
-{
+double frand_a_b(double a, double b) {
   return (rand()/(double)RAND_MAX)*(b-a)+a;
 }
diff --git a/openair1/SIMULATION/TOOLS/scm.m b/openair1/SIMULATION/TOOLS/scm.m
old mode 100755
new mode 100644
diff --git a/openair2/COMMON/gtpv1_u_messages_types.h b/openair2/COMMON/gtpv1_u_messages_types.h
index 0118a78f6d9f43652414f7c298351c14018d1d96..c398b55e3ef2fc40d2bb21946c0d9fb68ff2751b 100644
--- a/openair2/COMMON/gtpv1_u_messages_types.h
+++ b/openair2/COMMON/gtpv1_u_messages_types.h
@@ -22,10 +22,10 @@
 #ifndef GTPV1_U_MESSAGES_TYPES_H_
 #define GTPV1_U_MESSAGES_TYPES_H_
 
-#include "asn_constant.h"
+#include "LTE_asn_constant.h"
 
 
-#define GTPV1U_MAX_BEARERS_PER_UE max_val_DRB_Identity
+#define GTPV1U_MAX_BEARERS_PER_UE max_val_LTE_DRB_Identity
 
 #define GTPV1U_ENB_UPDATE_TUNNEL_REQ(mSGpTR)  (mSGpTR)->ittiMsg.Gtpv1uUpdateTunnelReq
 #define GTPV1U_ENB_UPDATE_TUNNEL_RESP(mSGpTR) (mSGpTR)->ittiMsg.Gtpv1uUpdateTunnelResp
diff --git a/openair2/COMMON/intertask_interface_conf.h b/openair2/COMMON/intertask_interface_conf.h
deleted file mode 100644
index 9c108f87e08395753404665293f67ca282751f3f..0000000000000000000000000000000000000000
--- a/openair2/COMMON/intertask_interface_conf.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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
- */
-
-/*
- * intertask_interface_conf.h
- *
- *  Created on: Oct 21, 2013
- *      Author: winckel
- */
-
-#ifndef INTERTASK_INTERFACE_CONF_H_
-#define INTERTASK_INTERFACE_CONF_H_
-
-/*******************************************************************************
- * Intertask Interface Constants
- ******************************************************************************/
-
-#define ITTI_PORT                (10006)
-
-/* This is the queue size for signal dumper */
-#define ITTI_QUEUE_MAX_ELEMENTS  (10 * 1000)
-#define ITTI_DUMP_MAX_CON        (5)    /* Max connections in parallel */
-
-#endif /* INTERTASK_INTERFACE_CONF_H_ */
diff --git a/openair2/COMMON/mac_rrc_primitives.h b/openair2/COMMON/mac_rrc_primitives.h
index f175f9ddf8b8e11199caae3d466610a88fe31a70..ab05f394a1c9d04d2490ba5a9527f448dd834034 100644
--- a/openair2/COMMON/mac_rrc_primitives.h
+++ b/openair2/COMMON/mac_rrc_primitives.h
@@ -30,13 +30,13 @@
 #include "COMMON/platform_types.h"
 #include "COMMON/platform_constants.h"
 
-#include "RadioResourceConfigCommonSIB.h"
-#include "RadioResourceConfigDedicated.h"
-#include "MeasGapConfig.h"
-#include "TDD-Config.h"
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-#include "MBSFN-AreaInfoList-r9.h"
-#include "MBSFN-SubframeConfigList.h"
+#include "LTE_RadioResourceConfigCommonSIB.h"
+#include "LTE_RadioResourceConfigDedicated.h"
+#include "LTE_MeasGapConfig.h"
+#include "LTE_TDD-Config.h"
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+#include "LTE_MBSFN-AreaInfoList-r9.h"
+#include "LTE_MBSFN-SubframeConfigList.h"
 #endif
 //#include "rrm_config_structs.h"
 //#include "platform_types.h"
@@ -347,25 +347,25 @@ typedef struct {
   void (*pdcp_data_req)(module_id_t, rb_id_t, sdu_size_t, char*);
   signed int (*rrc_rlc_config_req)(unsigned int, unsigned int, unsigned int, unsigned int, rlc_info_t );
   int (*rrc_mac_config_req)(uint8_t Mod_id,uint8_t eNB_flag,uint8_t UE_id,uint8_t eNB_index,
-                            RadioResourceConfigCommonSIB_t *radioResourceConfigCommon,
-                            struct PhysicalConfigDedicated *physicalConfigDedicated,
-                            MAC_MainConfig_t *mac_MainConfig,
+                            LTE_RadioResourceConfigCommonSIB_t *radioResourceConfigCommon,
+                            struct LTE_PhysicalConfigDedicated *physicalConfigDedicated,
+                            LTE_MAC_MainConfig_t *mac_MainConfig,
                             long logicalChannelIdentity,
-                            LogicalChannelConfig_t *logicalChannelConfig,
-                            MeasGapConfig_t *measGapConfig,
-                            TDD_Config_t *tdd_Config,
+                            LTE_LogicalChannelConfig_t *logicalChannelConfig,
+                            LTE_MeasGapConfig_t *measGapConfig,
+                            LTE_TDD_Config_t *tdd_Config,
                             uint8_t *SIwindowsize,
                             uint16_t *SIperiod
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
                             ,
                             MBMS_flag_t MBMS_Flag,
-                            struct MBSFN_SubframeConfigList *mbsfn_SubframeConfigList,
-                            MBSFN_AreaInfoList_r9_t *mbsfn_AreaInfoList,
-                            struct PMCH_InfoList_r9 *pmch_InfoList
+                            struct LTE_MBSFN_SubframeConfigList *mbsfn_SubframeConfigList,
+                            LTE_MBSFN_AreaInfoList_r9_t *mbsfn_AreaInfoList,
+                            struct LTE_PMCH_InfoList_r9 *pmch_InfoList
 #endif
                            );
   unsigned int (*mac_rlc_data_req)(module_id_t, unsigned int, const unsigned int,char*
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                                   ,uint32_t
                                   ,uint32_t
 #endif
@@ -373,7 +373,7 @@ typedef struct {
   void (*mac_rlc_data_ind)(module_id_t, logical_chan_id_t, char*, tb_size_t, num_tb_t, crc_t* );
   mac_rlc_status_resp_t (*mac_rlc_status_ind)     (module_id_t enb_mod_idP, module_id_t ue_mod_idP, frame_t frameP, sub_frame_t subframeP, eNB_flag_t eNB_flagP, MBMS_flag_t MBMS_flagP,
       logical_chan_id_t channel_idP, tb_size_t tb_sizeP
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
       ,uint32_t sourceL2Id
       ,uint32_t destinationL2Id
 #endif
diff --git a/openair2/COMMON/messages_types.h b/openair2/COMMON/messages_types.h
deleted file mode 100644
index f5ca697f50d8158a3f2214ba37e392ab74b09803..0000000000000000000000000000000000000000
--- a/openair2/COMMON/messages_types.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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
- */
-
-/*
- * messages_types.h
- *
- *  Created on: Oct 14, 2013
- *      Author: winckel
- */
-
-#ifndef MESSAGES_TYPES_H_
-#define MESSAGES_TYPES_H_
-
-#include "intertask_messages_types.h"
-#include "timer_messages_types.h"
-
-#include "phy_messages_types.h"
-#include "mac_messages_types.h"
-#include "rlc_messages_types.h"
-#include "pdcp_messages_types.h"
-#include "rrc_messages_types.h"
-#include "nas_messages_types.h"
-#if ENABLE_RAL
-#include "ral_messages_types.h"
-#endif 
-#include "s1ap_messages_types.h"
-#include "f1ap_messages_types.h"
-#include "x2ap_messages_types.h"
-#include "sctp_messages_types.h"
-#include "udp_messages_types.h"
-#include "gtpv1_u_messages_types.h"
-
-#endif /* MESSAGES_TYPES_H_ */
diff --git a/openair2/COMMON/platform_constants.h b/openair2/COMMON/platform_constants.h
index 9aa912a01eda2a49dcf08d21285a56f996d41d80..2b28b760a813fcfcf0a98e6ebff5d20779d7cddd 100644
--- a/openair2/COMMON/platform_constants.h
+++ b/openair2/COMMON/platform_constants.h
@@ -28,11 +28,7 @@
 
  ***************************************************************************/
 
-#ifdef CMAKER
-#include "asn_constant.h"
-#else
-#include "RRC/LTE/MESSAGES/asn1_constants.h"
-#endif
+#include "LTE_asn_constant.h"
 
 #ifndef __PLATFORM_CONSTANTS_H__
 #    define __PLATFORM_CONSTANTS_H__
@@ -68,6 +64,16 @@
 #    define MAX_MODULES                NB_MODULES_MAX
 
 #ifndef UE_EXPANSION
+// TODO:L2 FAPI simulator.
+// UESIM_EXPANSION is used to be same value of MAX_MOBILES_PER_ENB
+// in eNB and UE.
+// now , if we use --mu option in UE, compiling error will occur.
+// This problem will be fixed in the future.
+# ifdef UESIM_EXPANSION
+#    define MAX_MOBILES_PER_ENB         256
+#    define MAX_MOBILES_PER_ENB_NB_IoT  256
+#    define MAX_eNB                      2
+# else
 # ifdef LARGE_SCALE
 #    define MAX_MOBILES_PER_ENB         128
 #    define MAX_MOBILES_PER_ENB_NB_IoT  128
@@ -77,6 +83,7 @@
 #    define MAX_MOBILES_PER_ENB_NB_IoT  16
 #    define MAX_eNB                      2
 # endif
+#endif
 #else
 #    define MAX_MOBILES_PER_ENB 256
 #    define MAX_MOBILES_PER_ENB_NB_IoT 256
@@ -87,19 +94,19 @@
 #define MAX_MANAGED_ENB_PER_MOBILE  2
 
 ///NB-IOT
-#define NB_RB_MAX_NB_IOT  (maxDRB_NB_r13 + 3) //MP: NB_IoT --> 2(DRB)+3(SRBs - 2 is not used) = 5
+#define NB_RB_MAX_NB_IOT  (LTE_maxDRB_NB_r13 + 3) //MP: NB_IoT --> 2(DRB)+3(SRBs - 2 is not used) = 5
 
 
 #define DEFAULT_RAB_ID 1
 
-#define NB_RB_MAX      (maxDRB + 3) /* was 11, now 14, maxDRB comes from asn1_constants.h, + 3 because of 3 SRB, one invisible id 0, then id 1 and 2 */
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-#define NB_RB_MBMS_MAX (maxSessionPerPMCH*maxServiceCount)
+#define NB_RB_MAX      (LTE_maxDRB + 3) /* was 11, now 14, maxDRB comes from asn1_constants.h, + 3 because of 3 SRB, one invisible id 0, then id 1 and 2 */
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#define NB_RB_MBMS_MAX (LTE_maxSessionPerPMCH*LTE_maxServiceCount)
 #else
 // Do not allocate unused memory
 #define NB_RB_MBMS_MAX 1
 #endif
-#define NB_RAB_MAX     maxDRB       /* was 8, now 11 */
+#define NB_RAB_MAX     LTE_maxDRB       /* was 8, now 11 */
 #define RAB_SHIFT1     9
 #define RAB_SHIFT2     3
 #define RAB_OFFSET     0x0007
diff --git a/openair2/COMMON/platform_types.h b/openair2/COMMON/platform_types.h
index 843f6458164472eb52776c7b416682f46d069e4c..ee8d6abcc9cb2e4b97ec53e0346e28ec59c44598 100644
--- a/openair2/COMMON/platform_types.h
+++ b/openair2/COMMON/platform_types.h
@@ -31,7 +31,7 @@
 #    define __PLATFORM_TYPES_H__
 
 #if !defined(NAS_NETLINK)
-#include <stdint.h>
+  #include <stdint.h>
 #endif
 
 //-----------------------------------------------------------------------------
@@ -42,19 +42,19 @@
  * let's protect potential redefinition
  */
 #ifndef _BOOLEAN_T_DEFINED_
-#define _BOOLEAN_T_DEFINED_
+  #define _BOOLEAN_T_DEFINED_
 
-typedef signed char        boolean_t;
+  typedef signed char        boolean_t;
 
-#if !defined(TRUE)
-#define TRUE               (boolean_t)0x01
-#endif
+  #if !defined(TRUE)
+    #define TRUE               (boolean_t)0x01
+  #endif
 
-#if !defined(FALSE)
-#define FALSE              (boolean_t)0x00
-#endif
+  #if !defined(FALSE)
+    #define FALSE              (boolean_t)0x00
+  #endif
 
-#define BOOL_NOT(b) (b^TRUE)
+  #define BOOL_NOT(b) (b^TRUE)
 
 #endif /* _BOOLEAN_T_DEFINED_ */
 
@@ -65,7 +65,7 @@ typedef int32_t               sdu_size_t;
 typedef uint32_t              frame_t;
 typedef int32_t               sframe_t;
 typedef uint32_t              sub_frame_t;
-typedef uint16_t               module_id_t;
+typedef uint16_t              module_id_t;
 typedef uint8_t               slice_id_t;
 typedef uint8_t               eNB_index_t;
 typedef uint16_t              ue_id_t;
@@ -102,19 +102,19 @@ typedef enum rb_type_e {
 } rb_type_t;
 
 typedef enum {
-    CR_ROUND = 0,
-    CR_SRB12 = 1,
-    CR_HOL   = 2,
-    CR_LC    = 3,
-    CR_CQI   = 4,
-    CR_LCP   = 5,
-    CR_NUM   = 6
+  CR_ROUND = 0,
+  CR_SRB12 = 1,
+  CR_HOL   = 2,
+  CR_LC    = 3,
+  CR_CQI   = 4,
+  CR_LCP   = 5,
+  CR_NUM   = 6
 } sorting_criterion_t;
 
 typedef enum {
-    POL_FAIR   = 0,
-    POL_GREEDY = 1,
-    POL_NUM    = 2
+  POL_FAIR   = 0,
+  POL_GREEDY = 1,
+  POL_NUM    = 2
 } accounting_policy_t;
 //-----------------------------------------------------------------------------
 // PHY TYPES
@@ -188,19 +188,19 @@ typedef uint32_t           m_tmsi_t;
 
 //Random UE identity length = 40 bits
 #if ! defined(NOT_A_RANDOM_UE_IDENTITY)
-#define NOT_A_RANDOM_UE_IDENTITY (uint64_t)0xFFFFFFFF
+  #define NOT_A_RANDOM_UE_IDENTITY (uint64_t)0xFFFFFFFF
 #endif
 #if ! defined(NOT_A_RNTI)
-#define NOT_A_RNTI (rnti_t)0
+  #define NOT_A_RNTI (rnti_t)0
 #endif
 #if ! defined(M_RNTI)
-#define M_RNTI     (rnti_t)0xFFFD
+  #define M_RNTI     (rnti_t)0xFFFD
 #endif
 #if ! defined(P_RNTI)
-#define P_RNTI     (rnti_t)0xFFFE
+  #define P_RNTI     (rnti_t)0xFFFE
 #endif
 #if ! defined(SI_RNTI)
-#define SI_RNTI    (rnti_t)0xFFFF
+  #define SI_RNTI    (rnti_t)0xFFFF
 #endif
 typedef enum config_action_e {
   CONFIG_ACTION_NULL              = 0,
@@ -225,7 +225,7 @@ typedef uint8_t            ebi_t;  // eps bearer id
 //-----------------------------------------------------------------------------
 // may be ITTI not enabled, but type instance is useful also for OTG,
 #if !defined(instance_t)
-typedef uint16_t instance_t;
+  typedef uint16_t instance_t;
 #endif
 typedef struct protocol_ctxt_s {
   module_id_t module_id;     /*!< \brief  Virtualized module identifier      */
@@ -236,6 +236,9 @@ 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)
@@ -247,51 +250,51 @@ typedef struct protocol_ctxt_s {
 
 
 #define MODULE_ID_TO_INSTANCE(mODULE_iD, iNSTANCE, eNB_fLAG) \
-    if(eNB_fLAG == ENB_FLAG_YES) \
-        iNSTANCE = ENB_MODULE_ID_TO_INSTANCE(mODULE_iD); \
-    else \
-        iNSTANCE = UE_MODULE_ID_TO_INSTANCE(mODULE_iD)
+  if(eNB_fLAG == ENB_FLAG_YES) \
+    iNSTANCE = ENB_MODULE_ID_TO_INSTANCE(mODULE_iD); \
+  else \
+    iNSTANCE = UE_MODULE_ID_TO_INSTANCE(mODULE_iD)
 
 #define INSTANCE_TO_MODULE_ID(iNSTANCE, mODULE_iD, eNB_fLAG) \
-    if(eNB_fLAG == ENB_FLAG_YES) \
-        mODULE_iD = ENB_INSTANCE_TO_MODULE_ID(iNSTANCE); \
-    else \
-        mODULE_iD = UE_INSTANCE_TO_MODULE_ID(iNSTANCE)
+  if(eNB_fLAG == ENB_FLAG_YES) \
+    mODULE_iD = ENB_INSTANCE_TO_MODULE_ID(iNSTANCE); \
+  else \
+    mODULE_iD = UE_INSTANCE_TO_MODULE_ID(iNSTANCE)
 
 #define PROTOCOL_CTXT_COMPUTE_MODULE_ID(CtXt_h) \
-    INSTANCE_TO_MODULE_ID( (CtXt_h)->instance , (CtXt_h)->module_id , (CtXt_h)->enb_flag )
+  INSTANCE_TO_MODULE_ID( (CtXt_h)->instance , (CtXt_h)->module_id , (CtXt_h)->enb_flag )
 
 
 #define PROTOCOL_CTXT_COMPUTE_INSTANCE(CtXt_h) \
-    MODULE_ID_TO_INSTANCE( (CtXt_h)->module_id , (CtXt_h)->instance , (CtXt_h)->enb_flag )
+  MODULE_ID_TO_INSTANCE( (CtXt_h)->module_id , (CtXt_h)->instance , (CtXt_h)->enb_flag )
 
 
 #define PROTOCOL_CTXT_SET_BY_MODULE_ID(Ctxt_Pp, mODULE_iD, eNB_fLAG, rNTI, fRAME, sUBfRAME, eNB_iNDEX) \
-    (Ctxt_Pp)->module_id = mODULE_iD; \
-    (Ctxt_Pp)->enb_flag  = eNB_fLAG; \
-    (Ctxt_Pp)->rnti      = rNTI; \
-    (Ctxt_Pp)->frame     = fRAME; \
-    (Ctxt_Pp)->subframe  = sUBfRAME; \
-    (Ctxt_Pp)->eNB_index  = eNB_iNDEX; \
-    PROTOCOL_CTXT_COMPUTE_INSTANCE(Ctxt_Pp)
+  (Ctxt_Pp)->module_id = mODULE_iD; \
+  (Ctxt_Pp)->enb_flag  = eNB_fLAG; \
+  (Ctxt_Pp)->rnti      = rNTI; \
+  (Ctxt_Pp)->frame     = fRAME; \
+  (Ctxt_Pp)->subframe  = sUBfRAME; \
+  (Ctxt_Pp)->eNB_index  = eNB_iNDEX; \
+  PROTOCOL_CTXT_COMPUTE_INSTANCE(Ctxt_Pp)
 
 #define PROTOCOL_CTXT_SET_BY_INSTANCE(Ctxt_Pp, iNSTANCE, eNB_fLAG, rNTI, fRAME, sUBfRAME) \
-    (Ctxt_Pp)->instance  = iNSTANCE; \
-    (Ctxt_Pp)->enb_flag  = eNB_fLAG; \
-    (Ctxt_Pp)->rnti      = rNTI; \
-    (Ctxt_Pp)->frame     = fRAME; \
-    (Ctxt_Pp)->subframe  = sUBfRAME; \
-    PROTOCOL_CTXT_COMPUTE_MODULE_ID(Ctxt_Pp)
+  (Ctxt_Pp)->instance  = iNSTANCE; \
+  (Ctxt_Pp)->enb_flag  = eNB_fLAG; \
+  (Ctxt_Pp)->rnti      = rNTI; \
+  (Ctxt_Pp)->frame     = fRAME; \
+  (Ctxt_Pp)->subframe  = sUBfRAME; \
+  PROTOCOL_CTXT_COMPUTE_MODULE_ID(Ctxt_Pp)
 
 #define PROTOCOL_CTXT_FMT "[FRAME %05u][%s][MOD %02u][RNTI %" PRIx16 "]"
 #define PROTOCOL_CTXT_ARGS(CTXT_Pp) \
-    (CTXT_Pp)->frame, \
-    ((CTXT_Pp)->enb_flag == ENB_FLAG_YES) ? "eNB":" UE", \
-    (CTXT_Pp)->module_id, \
-    (CTXT_Pp)->rnti
+  (CTXT_Pp)->frame, \
+  ((CTXT_Pp)->enb_flag == ENB_FLAG_YES) ? "eNB":" UE", \
+  (CTXT_Pp)->module_id, \
+  (CTXT_Pp)->rnti
 
 #define CHECK_CTXT_ARGS(CTXT_Pp)
 
 #define exit_fun(msg) exit_function(__FILE__,__FUNCTION__,__LINE__,msg)
-void exit_function(const char* file, const char* function, const int line, const char* s);
+void exit_function(const char *file, const char *function, const int line, const char *s);
 #endif
diff --git a/openair2/COMMON/rrc_messages_types.h b/openair2/COMMON/rrc_messages_types.h
index 0be7c7fe8198a6355d1c096f695ed70c7c97d425..2e6d7a9d0b9aef2e1101d911d8bffb2ef8f2e83b 100644
--- a/openair2/COMMON/rrc_messages_types.h
+++ b/openair2/COMMON/rrc_messages_types.h
@@ -33,34 +33,30 @@
 #include "rrc_types.h"
 #include "s1ap_messages_types.h"
 #include "f1ap_messages_types.h"
-#ifdef CMAKER
-#include "SystemInformationBlockType2.h"
-#else
-#include "RRC/LTE/MESSAGES/SystemInformationBlockType2.h"
-#endif
-#include "SL-OffsetIndicator-r12.h"
-#include "SubframeBitmapSL-r12.h"
-#include "SL-CP-Len-r12.h"
-#include "SL-PeriodComm-r12.h"
-#include "SL-DiscResourcePool-r12.h"
+#include "LTE_SystemInformationBlockType2.h"
+#include "LTE_SL-OffsetIndicator-r12.h"
+#include "LTE_SubframeBitmapSL-r12.h"
+#include "LTE_SL-CP-Len-r12.h"
+#include "LTE_SL-PeriodComm-r12.h"
+#include "LTE_SL-DiscResourcePool-r12.h"
 
 
 //-------------------------------------------------------------------------------------------//
 // Messages for RRC logging
 #if defined(DISABLE_ITTI_XER_PRINT)
-#include "BCCH-DL-SCH-Message.h"
-#include "DL-CCCH-Message.h"
-#include "DL-DCCH-Message.h"
-#include "UE-EUTRA-Capability.h"
-#include "UL-CCCH-Message.h"
-#include "UL-DCCH-Message.h"
+  #include "LTE_BCCH-DL-SCH-Message.h"
+  #include "LTE_DL-CCCH-Message.h"
+  #include "LTE_DL-DCCH-Message.h"
+  #include "LTE_UE-EUTRA-Capability.h"
+  #include "LTE_UL-CCCH-Message.h"
+  #include "LTE_UL-DCCH-Message.h"
 
-typedef BCCH_DL_SCH_Message_t   RrcDlBcchMessage;
-typedef DL_CCCH_Message_t       RrcDlCcchMessage;
-typedef DL_DCCH_Message_t       RrcDlDcchMessage;
-typedef UE_EUTRA_Capability_t   RrcUeEutraCapability;
-typedef UL_CCCH_Message_t       RrcUlCcchMessage;
-typedef UL_DCCH_Message_t       RrcUlDcchMessage;
+  typedef BCCH_DL_SCH_Message_t   RrcDlBcchMessage;
+  typedef DL_CCCH_Message_t       RrcDlCcchMessage;
+  typedef DL_DCCH_Message_t       RrcDlDcchMessage;
+  typedef UE_EUTRA_Capability_t   RrcUeEutraCapability;
+  typedef UL_CCCH_Message_t       RrcUlCcchMessage;
+  typedef UL_DCCH_Message_t       RrcUlDcchMessage;
 #endif
 
 //-------------------------------------------------------------------------------------------//
@@ -92,18 +88,89 @@ typedef struct RrcStateInd_s {
   Rrc_Sub_State_t sub_state;
 } RrcStateInd;
 
+typedef struct RadioResourceConfig_s {
+  long                    prach_root;
+  long                    prach_config_index;
+  BOOLEAN_t               prach_high_speed;
+  long                    prach_zero_correlation;
+  long                    prach_freq_offset;
+  long                    pucch_delta_shift;
+  long                    pucch_nRB_CQI;
+  long                    pucch_nCS_AN;
+  long                    pucch_n1_AN;
+  long                    pdsch_referenceSignalPower;
+  long                    pdsch_p_b;
+  long                    pusch_n_SB;
+  long                    pusch_hoppingMode;
+  long                    pusch_hoppingOffset;
+  BOOLEAN_t               pusch_enable64QAM;
+  BOOLEAN_t               pusch_groupHoppingEnabled;
+  long                    pusch_groupAssignment;
+  BOOLEAN_t               pusch_sequenceHoppingEnabled;
+  long                    pusch_nDMRS1;
+  long                    phich_duration;
+  long                    phich_resource;
+  BOOLEAN_t               srs_enable;
+  long                    srs_BandwidthConfig;
+  long                    srs_SubframeConfig;
+  BOOLEAN_t               srs_ackNackST;
+  BOOLEAN_t               srs_MaxUpPts;
+  long                    pusch_p0_Nominal;
+  long                    pusch_alpha;
+  long                    pucch_p0_Nominal;
+  long                    msg3_delta_Preamble;
+  long                    ul_CyclicPrefixLength;
+  e_LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format1                    pucch_deltaF_Format1;
+  e_LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format1b                   pucch_deltaF_Format1b;
+  e_LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format2                    pucch_deltaF_Format2;
+  e_LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format2a                   pucch_deltaF_Format2a;
+  e_LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format2b                   pucch_deltaF_Format2b;
+  long                    rach_numberOfRA_Preambles;
+  BOOLEAN_t               rach_preamblesGroupAConfig;
+  long                    rach_sizeOfRA_PreamblesGroupA;
+  long                    rach_messageSizeGroupA;
+  e_LTE_RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messagePowerOffsetGroupB                    rach_messagePowerOffsetGroupB;
+  long                    rach_powerRampingStep;
+  long                    rach_preambleInitialReceivedTargetPower;
+  long                    rach_preambleTransMax;
+  long                    rach_raResponseWindowSize;
+  long                    rach_macContentionResolutionTimer;
+  long                    rach_maxHARQ_Msg3Tx;
+  long                    bcch_modificationPeriodCoeff;
+  long                    pcch_defaultPagingCycle;
+  long                    pcch_nB;
+  long                    ue_TimersAndConstants_t300;
+  long                    ue_TimersAndConstants_t301;
+  long                    ue_TimersAndConstants_t310;
+  long                    ue_TimersAndConstants_t311;
+  long                    ue_TimersAndConstants_n310;
+  long                    ue_TimersAndConstants_n311;
+  long                    ue_TransmissionMode;
+  long                    ue_multiple_max;
+#ifdef Rel14
+  //SIB2 BR Options
+  long*			  preambleTransMax_CE_r13;
+  BOOLEAN_t		  prach_ConfigCommon_v1310;
+  BOOLEAN_t*	          mpdcch_startSF_CSS_RA_r13;
+  long			  mpdcch_startSF_CSS_RA_r13_val;
+  long*			  prach_HoppingOffset_r13;
+#endif
+} RadioResourceConfig;
+
 // eNB: ENB_APP -> RRC messages
 typedef struct RrcConfigurationReq_s {
-  uint32_t            cell_identity;
+  uint32_t                cell_identity;
+
+  uint16_t                tac;
 
-  uint16_t            tac;
 
   uint16_t            mcc[PLMN_LIST_MAX_SIZE];
   uint16_t            mnc[PLMN_LIST_MAX_SIZE];
   uint8_t             mnc_digit_length[PLMN_LIST_MAX_SIZE];
   uint8_t             num_plmn;
 
-  
+  uint32_t            rrc_inactivity_timer_thres; // for testing, maybe change later
+
   paging_drx_t            default_drx;
   int16_t                 nb_cc;
   lte_frame_type_t        frame_type[MAX_NUM_CCs];
@@ -117,109 +184,130 @@ typedef struct RrcConfigurationReq_s {
   int16_t                 Nid_cell[MAX_NUM_CCs];// for testing, change later
   int16_t                 N_RB_DL[MAX_NUM_CCs];// for testing, change later
   int                     nb_antenna_ports[MAX_NUM_CCs];
-  long                    prach_root[MAX_NUM_CCs];
-  long                    prach_config_index[MAX_NUM_CCs];
-  BOOLEAN_t               prach_high_speed[MAX_NUM_CCs];
-  long                    prach_zero_correlation[MAX_NUM_CCs];
-  long                    prach_freq_offset[MAX_NUM_CCs];
-  long                    pucch_delta_shift[MAX_NUM_CCs];
-  long                    pucch_nRB_CQI[MAX_NUM_CCs];
-  long                    pucch_nCS_AN[MAX_NUM_CCs];
-//#if (RRC_VERSION < MAKE_VERSION(10, 0, 0))
-  long                    pucch_n1_AN[MAX_NUM_CCs];
-//#endif
-  long                    pdsch_referenceSignalPower[MAX_NUM_CCs];
-  long                    pdsch_p_b[MAX_NUM_CCs];
-  long                    pusch_n_SB[MAX_NUM_CCs];
-  long                    pusch_hoppingMode[MAX_NUM_CCs];
-  long                    pusch_hoppingOffset[MAX_NUM_CCs];
-  BOOLEAN_t               pusch_enable64QAM[MAX_NUM_CCs];
-  BOOLEAN_t               pusch_groupHoppingEnabled[MAX_NUM_CCs];
-  long                    pusch_groupAssignment[MAX_NUM_CCs];
-  BOOLEAN_t               pusch_sequenceHoppingEnabled[MAX_NUM_CCs];
-  long                    pusch_nDMRS1[MAX_NUM_CCs];
-  long                    phich_duration[MAX_NUM_CCs];
-  long                    phich_resource[MAX_NUM_CCs];
-  BOOLEAN_t               srs_enable[MAX_NUM_CCs];
-  long                    srs_BandwidthConfig[MAX_NUM_CCs];
-  long                    srs_SubframeConfig[MAX_NUM_CCs];
-  BOOLEAN_t               srs_ackNackST[MAX_NUM_CCs];
-  BOOLEAN_t               srs_MaxUpPts[MAX_NUM_CCs];
-  long                    pusch_p0_Nominal[MAX_NUM_CCs];
-  long                    pusch_alpha[MAX_NUM_CCs];
-  long                    pucch_p0_Nominal[MAX_NUM_CCs];
-  long                    msg3_delta_Preamble[MAX_NUM_CCs];
-  long                    ul_CyclicPrefixLength[MAX_NUM_CCs];
-  e_DeltaFList_PUCCH__deltaF_PUCCH_Format1                    pucch_deltaF_Format1[MAX_NUM_CCs];
-  e_DeltaFList_PUCCH__deltaF_PUCCH_Format1b                   pucch_deltaF_Format1b[MAX_NUM_CCs];
-  e_DeltaFList_PUCCH__deltaF_PUCCH_Format2                    pucch_deltaF_Format2[MAX_NUM_CCs];
-  e_DeltaFList_PUCCH__deltaF_PUCCH_Format2a                   pucch_deltaF_Format2a[MAX_NUM_CCs];
-  e_DeltaFList_PUCCH__deltaF_PUCCH_Format2b                   pucch_deltaF_Format2b[MAX_NUM_CCs];
-  long                    rach_numberOfRA_Preambles[MAX_NUM_CCs];
-  BOOLEAN_t               rach_preamblesGroupAConfig[MAX_NUM_CCs];
-  long                    rach_sizeOfRA_PreamblesGroupA[MAX_NUM_CCs];
-  long                    rach_messageSizeGroupA[MAX_NUM_CCs];
-  e_RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messagePowerOffsetGroupB                    rach_messagePowerOffsetGroupB[MAX_NUM_CCs];
-  long                    rach_powerRampingStep[MAX_NUM_CCs];
-  long                    rach_preambleInitialReceivedTargetPower[MAX_NUM_CCs];
-  long                    rach_preambleTransMax[MAX_NUM_CCs];
-  long                    rach_raResponseWindowSize[MAX_NUM_CCs];
-  long                    rach_macContentionResolutionTimer[MAX_NUM_CCs];
-  long                    rach_maxHARQ_Msg3Tx[MAX_NUM_CCs];
-  long                    bcch_modificationPeriodCoeff[MAX_NUM_CCs];
-  long                    pcch_defaultPagingCycle[MAX_NUM_CCs];
-  long                    pcch_nB[MAX_NUM_CCs];
-  long                    ue_TimersAndConstants_t300[MAX_NUM_CCs];
-  long                    ue_TimersAndConstants_t301[MAX_NUM_CCs];
-  long                    ue_TimersAndConstants_t310[MAX_NUM_CCs];
-  long                    ue_TimersAndConstants_t311[MAX_NUM_CCs];
-  long                    ue_TimersAndConstants_n310[MAX_NUM_CCs];
-  long                    ue_TimersAndConstants_n311[MAX_NUM_CCs];
-  long                    ue_TransmissionMode[MAX_NUM_CCs];
-  long                    ue_multiple_max[MAX_NUM_CCs];
+  int                     eMBMS_configured;
+  int                     eMTC_configured;
+  int                     SL_configured;
+
+  RadioResourceConfig     radioresourceconfig[MAX_NUM_CCs];
+  RadioResourceConfig     radioresourceconfig_BR[MAX_NUM_CCs];
 
-  //TTN - for D2D
+#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
+  //MIB
+  long	 		  schedulingInfoSIB1_BR_r13[MAX_NUM_CCs];
+  //SIB1 BR options
+  uint16_t*		  hyperSFN_r13                           [MAX_NUM_CCs];
+  long*			  eDRX_Allowed_r13                       [MAX_NUM_CCs];
+  BOOLEAN_t		  cellSelectionInfoCE_r13                [MAX_NUM_CCs];
+  long			  q_RxLevMinCE_r13                       [MAX_NUM_CCs];
+  long*			  q_QualMinRSRQ_CE_r13                   [MAX_NUM_CCs];
+  BOOLEAN_t		  bandwidthReducedAccessRelatedInfo_r13  [MAX_NUM_CCs];
+  long            si_Narrowband_r13         [MAX_NUM_CCs][32];
+  long            si_TBS_r13                [MAX_NUM_CCs][32];
+  int             scheduling_info_br_size   [MAX_NUM_CCs];
+  long			  si_WindowLength_BR_r13                       [MAX_NUM_CCs];
+  long			  si_RepetitionPattern_r13                     [MAX_NUM_CCs];
+  BOOLEAN_t		 * fdd_DownlinkOrTddSubframeBitmapBR_r13       [MAX_NUM_CCs];
+  uint64_t		  fdd_DownlinkOrTddSubframeBitmapBR_val_r13    [MAX_NUM_CCs];
+  uint16_t		  *fdd_UplinkSubframeBitmapBR_r13              [MAX_NUM_CCs];
+  long			  startSymbolBR_r13                            [MAX_NUM_CCs];
+  long			  si_HoppingConfigCommon_r13                   [MAX_NUM_CCs];
+  long*			  si_ValidityTime_r13                          [MAX_NUM_CCs];
+  long            systemInfoValueTagSi_r13      [MAX_NUM_CCs][10];
+  int             system_info_value_tag_SI_size [MAX_NUM_CCs];
+  BOOLEAN_t		  freqHoppingParametersDL_r13                   [MAX_NUM_CCs];
+  long*			  mpdcch_pdsch_HoppingNB_r13                    [MAX_NUM_CCs];
+  BOOLEAN_t		  interval_DLHoppingConfigCommonModeA_r13       [MAX_NUM_CCs];
+  long			  interval_DLHoppingConfigCommonModeA_r13_val   [MAX_NUM_CCs];
+  BOOLEAN_t		  interval_DLHoppingConfigCommonModeB_r13       [MAX_NUM_CCs];
+  long			  interval_DLHoppingConfigCommonModeB_r13_val   [MAX_NUM_CCs];
+  long*			  mpdcch_pdsch_HoppingOffset_r13                [MAX_NUM_CCs];
+  long firstPreamble_r13                 [MAX_NUM_CCs][4];
+  long lastPreamble_r13                  [MAX_NUM_CCs][4];
+  long ra_ResponseWindowSize_r13         [MAX_NUM_CCs][4];
+  long mac_ContentionResolutionTimer_r13 [MAX_NUM_CCs][4];
+  long rar_HoppingConfig_r13             [MAX_NUM_CCs][4];
+  int  rach_CE_LevelInfoList_r13_size    [MAX_NUM_CCs];
+//  long pcch_defaultPagingCycle_br;
+  long rsrp_range           [MAX_NUM_CCs][3];
+  int rsrp_range_list_size  [MAX_NUM_CCs];
+  long prach_config_index                        [MAX_NUM_CCs][4];
+  long prach_freq_offset                         [MAX_NUM_CCs][4];
+  long *prach_StartingSubframe_r13               [MAX_NUM_CCs][4];
+  long *maxNumPreambleAttemptCE_r13              [MAX_NUM_CCs][4];
+  long numRepetitionPerPreambleAttempt_r13       [MAX_NUM_CCs][4];
+  long mpdcch_NumRepetition_RA_r13               [MAX_NUM_CCs][4];
+  long prach_HoppingConfig_r13                   [MAX_NUM_CCs][4];
+  int  prach_parameters_list_size                [MAX_NUM_CCs];
+  long max_available_narrow_band                 [MAX_NUM_CCs][4][2];
+  int  max_available_narrow_band_size            [MAX_NUM_CCs][4];
+  long pucch_info_value       [MAX_NUM_CCs][4];
+  int  pucch_info_value_size  [MAX_NUM_CCs];
+  bool  pcch_config_v1310               [MAX_NUM_CCs];
+  long  paging_narrowbands_r13          [MAX_NUM_CCs];
+  long  mpdcch_numrepetition_paging_r13 [MAX_NUM_CCs];
+  long  *nb_v1310                        [MAX_NUM_CCs];
+  long  *pucch_NumRepetitionCE_Msg4_Level0_r13  [MAX_NUM_CCs];
+  long  *pucch_NumRepetitionCE_Msg4_Level1_r13  [MAX_NUM_CCs];
+  long  *pucch_NumRepetitionCE_Msg4_Level2_r13  [MAX_NUM_CCs];
+  long  *pucch_NumRepetitionCE_Msg4_Level3_r13  [MAX_NUM_CCs];
+  bool  sib2_freq_hoppingParameters_r13_exists             [MAX_NUM_CCs];
+  long  *sib2_mpdcch_pdsch_hoppingNB_r13                   [MAX_NUM_CCs];
+  long  *sib2_interval_DLHoppingConfigCommonModeA_r13      [MAX_NUM_CCs];
+  long  sib2_interval_DLHoppingConfigCommonModeA_r13_val  [MAX_NUM_CCs];
+  long  *sib2_interval_DLHoppingConfigCommonModeB_r13      [MAX_NUM_CCs];
+  long  sib2_interval_DLHoppingConfigCommonModeB_r13_val  [MAX_NUM_CCs];
+  long  *sib2_interval_ULHoppingConfigCommonModeA_r13      [MAX_NUM_CCs];
+  long  sib2_interval_ULHoppingConfigCommonModeA_r13_val  [MAX_NUM_CCs];
+  long  *sib2_interval_ULHoppingConfigCommonModeB_r13      [MAX_NUM_CCs];
+  long  sib2_interval_ULHoppingConfigCommonModeB_r13_val  [MAX_NUM_CCs];
+  long  *sib2_mpdcch_pdsch_hoppingOffset_r13               [MAX_NUM_CCs];
+  long  *pdsch_maxNumRepetitionCEmodeA_r13                 [MAX_NUM_CCs];
+  long  *pdsch_maxNumRepetitionCEmodeB_r13                 [MAX_NUM_CCs];
+  long  *pusch_maxNumRepetitionCEmodeA_r13                 [MAX_NUM_CCs];
+  long  *pusch_maxNumRepetitionCEmodeB_r13                 [MAX_NUM_CCs];
+  long  *pusch_HoppingOffset_v1310                         [MAX_NUM_CCs];
+#endif
   //SIB18
-  e_SL_CP_Len_r12                rxPool_sc_CP_Len[MAX_NUM_CCs];
-  e_SL_PeriodComm_r12            rxPool_sc_Period[MAX_NUM_CCs];
-  e_SL_CP_Len_r12                rxPool_data_CP_Len[MAX_NUM_CCs];
+  e_LTE_SL_CP_Len_r12            rxPool_sc_CP_Len[MAX_NUM_CCs];
+  e_LTE_SL_PeriodComm_r12        rxPool_sc_Period[MAX_NUM_CCs];
+  e_LTE_SL_CP_Len_r12            rxPool_data_CP_Len[MAX_NUM_CCs];
   long                           rxPool_ResourceConfig_prb_Num[MAX_NUM_CCs];
   long                           rxPool_ResourceConfig_prb_Start[MAX_NUM_CCs];
   long                           rxPool_ResourceConfig_prb_End[MAX_NUM_CCs];
-  SL_OffsetIndicator_r12_PR      rxPool_ResourceConfig_offsetIndicator_present[MAX_NUM_CCs];
+  LTE_SL_OffsetIndicator_r12_PR  rxPool_ResourceConfig_offsetIndicator_present[MAX_NUM_CCs];
   long                           rxPool_ResourceConfig_offsetIndicator_choice[MAX_NUM_CCs];
-  SubframeBitmapSL_r12_PR        rxPool_ResourceConfig_subframeBitmap_present[MAX_NUM_CCs];
-  char*                          rxPool_ResourceConfig_subframeBitmap_choice_bs_buf[MAX_NUM_CCs];
+  LTE_SubframeBitmapSL_r12_PR    rxPool_ResourceConfig_subframeBitmap_present[MAX_NUM_CCs];
+  char                          *rxPool_ResourceConfig_subframeBitmap_choice_bs_buf[MAX_NUM_CCs];
   long                           rxPool_ResourceConfig_subframeBitmap_choice_bs_size[MAX_NUM_CCs];
   long                           rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[MAX_NUM_CCs];
 
   //SIB19
   //for discRxPool
-  SL_CP_Len_r12_t                discRxPool_cp_Len[MAX_NUM_CCs];
-  e_SL_DiscResourcePool_r12__discPeriod_r12                   discRxPool_discPeriod[MAX_NUM_CCs];
+  LTE_SL_CP_Len_r12_t            discRxPool_cp_Len[MAX_NUM_CCs];
+  e_LTE_SL_DiscResourcePool_r12__discPeriod_r12               discRxPool_discPeriod[MAX_NUM_CCs];
   long                           discRxPool_numRetx[MAX_NUM_CCs];
   long                           discRxPool_numRepetition[MAX_NUM_CCs];
   long                           discRxPool_ResourceConfig_prb_Num[MAX_NUM_CCs];
   long                           discRxPool_ResourceConfig_prb_Start[MAX_NUM_CCs];
   long                           discRxPool_ResourceConfig_prb_End[MAX_NUM_CCs];
-  SL_OffsetIndicator_r12_PR      discRxPool_ResourceConfig_offsetIndicator_present[MAX_NUM_CCs];
+  LTE_SL_OffsetIndicator_r12_PR  discRxPool_ResourceConfig_offsetIndicator_present[MAX_NUM_CCs];
   long                           discRxPool_ResourceConfig_offsetIndicator_choice[MAX_NUM_CCs];
-  SubframeBitmapSL_r12_PR        discRxPool_ResourceConfig_subframeBitmap_present[MAX_NUM_CCs];
-  char*                          discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf[MAX_NUM_CCs];
+  LTE_SubframeBitmapSL_r12_PR    discRxPool_ResourceConfig_subframeBitmap_present[MAX_NUM_CCs];
+  char                          *discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf[MAX_NUM_CCs];
   long                           discRxPool_ResourceConfig_subframeBitmap_choice_bs_size[MAX_NUM_CCs];
   long                           discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[MAX_NUM_CCs];
   //for discRxPoolPS
-  SL_CP_Len_r12_t                discRxPoolPS_cp_Len[MAX_NUM_CCs];
-  e_SL_DiscResourcePool_r12__discPeriod_r12                   discRxPoolPS_discPeriod[MAX_NUM_CCs];
+  LTE_SL_CP_Len_r12_t            discRxPoolPS_cp_Len[MAX_NUM_CCs];
+  e_LTE_SL_DiscResourcePool_r12__discPeriod_r12                   discRxPoolPS_discPeriod[MAX_NUM_CCs];
   long                           discRxPoolPS_numRetx[MAX_NUM_CCs];
   long                           discRxPoolPS_numRepetition[MAX_NUM_CCs];
   long                           discRxPoolPS_ResourceConfig_prb_Num[MAX_NUM_CCs];
   long                           discRxPoolPS_ResourceConfig_prb_Start[MAX_NUM_CCs];
   long                           discRxPoolPS_ResourceConfig_prb_End[MAX_NUM_CCs];
-  SL_OffsetIndicator_r12_PR      discRxPoolPS_ResourceConfig_offsetIndicator_present[MAX_NUM_CCs];
+  LTE_SL_OffsetIndicator_r12_PR  discRxPoolPS_ResourceConfig_offsetIndicator_present[MAX_NUM_CCs];
   long                           discRxPoolPS_ResourceConfig_offsetIndicator_choice[MAX_NUM_CCs];
-  SubframeBitmapSL_r12_PR        discRxPoolPS_ResourceConfig_subframeBitmap_present[MAX_NUM_CCs];
-  char*                          discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_buf[MAX_NUM_CCs];
+  LTE_SubframeBitmapSL_r12_PR    discRxPoolPS_ResourceConfig_subframeBitmap_present[MAX_NUM_CCs];
+  char                          *discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_buf[MAX_NUM_CCs];
   long                           discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_size[MAX_NUM_CCs];
   long                           discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_bits_unused[MAX_NUM_CCs];
 } RrcConfigurationReq;
@@ -228,72 +316,70 @@ typedef struct RrcConfigurationReq_s {
 
 typedef struct NbIoTRrcConfigurationReq_s {
   uint32_t            cell_identity;
-
   uint16_t            tac;
-
-  uint16_t	      mcc;
-  uint16_t	      mnc;
-  uint8_t	      mnc_digit_length;
-  lte_frame_type_t	  frame_type;
+  uint16_t        mcc;
+  uint16_t        mnc;
+  uint8_t       mnc_digit_length;
+  lte_frame_type_t    frame_type;
   uint8_t                 tdd_config;
   uint8_t                 tdd_config_s;
   lte_prefix_type_t       prefix_type;
-  lte_prefix_type_t	  prefix_type_UL;
+  lte_prefix_type_t   prefix_type_UL;
   int16_t                 eutra_band;
   uint32_t                downlink_frequency;
   int32_t                 uplink_frequency_offset;
   int16_t                 Nid_cell;// for testing, change later
   int16_t                 N_RB_DL;// for testing, change later
   //RACH
-  long					  rach_raResponseWindowSize_NB;
-  long					  rach_macContentionResolutionTimer_NB;
-  long					  rach_powerRampingStep_NB;
-  long					  rach_preambleInitialReceivedTargetPower_NB;
-  long					  rach_preambleTransMax_CE_NB;
+  long            rach_raResponseWindowSize_NB;
+  long            rach_macContentionResolutionTimer_NB;
+  long            rach_powerRampingStep_NB;
+  long            rach_preambleInitialReceivedTargetPower_NB;
+  long            rach_preambleTransMax_CE_NB;
   //BCCH
-  long					  bcch_modificationPeriodCoeff_NB;
+  long            bcch_modificationPeriodCoeff_NB;
   //PCCH
-  long					  pcch_defaultPagingCycle_NB;
-  long					  pcch_nB_NB;
-  long					  pcch_npdcch_NumRepetitionPaging_NB;
+  long            pcch_defaultPagingCycle_NB;
+  long            pcch_nB_NB;
+  long            pcch_npdcch_NumRepetitionPaging_NB;
   //NPRACH
-  long					  nprach_CP_Length;
-  long					  nprach_rsrp_range;
-  long					  nprach_Periodicity[MAX_NUM_NBIOT_CELEVELS];
-  long					  nprach_StartTime[MAX_NUM_NBIOT_CELEVELS];
-  long					  nprach_SubcarrierOffset[MAX_NUM_NBIOT_CELEVELS];
-  long					  nprach_NumSubcarriers[MAX_NUM_NBIOT_CELEVELS];
-  long					  numRepetitionsPerPreambleAttempt_NB[MAX_NUM_NBIOT_CELEVELS];
-  long					  nprach_SubcarrierMSG3_RangeStart;
-  long					  maxNumPreambleAttemptCE_NB;
-  long					  npdcch_NumRepetitions_RA[MAX_NUM_NBIOT_CELEVELS];
-  long					  npdcch_StartSF_CSS_RA[MAX_NUM_NBIOT_CELEVELS];
-  long					  npdcch_Offset_RA[MAX_NUM_NBIOT_CELEVELS];
+  long            nprach_CP_Length;
+  long            nprach_rsrp_range;
+  long            nprach_Periodicity[MAX_NUM_NBIOT_CELEVELS];
+  long            nprach_StartTime[MAX_NUM_NBIOT_CELEVELS];
+  long            nprach_SubcarrierOffset[MAX_NUM_NBIOT_CELEVELS];
+  long            nprach_NumSubcarriers[MAX_NUM_NBIOT_CELEVELS];
+  long            numRepetitionsPerPreambleAttempt_NB[MAX_NUM_NBIOT_CELEVELS];
+  long            nprach_SubcarrierMSG3_RangeStart;
+  long            maxNumPreambleAttemptCE_NB;
+  long            npdcch_NumRepetitions_RA[MAX_NUM_NBIOT_CELEVELS];
+  long            npdcch_StartSF_CSS_RA[MAX_NUM_NBIOT_CELEVELS];
+  long            npdcch_Offset_RA[MAX_NUM_NBIOT_CELEVELS];
   //NPDSCH
-  long					  npdsch_nrs_Power;
+  long            npdsch_nrs_Power;
   //NPUSCH
-  long					  npusch_ack_nack_numRepetitions_NB;
-  long					  npusch_srs_SubframeConfig_NB;
-  long					  npusch_threeTone_CyclicShift_r13;
-  long					  npusch_sixTone_CyclicShift_r13;
-  BOOLEAN_t				  npusch_groupHoppingEnabled;
-  long					  npusch_groupAssignmentNPUSCH_r13;
+  long            npusch_ack_nack_numRepetitions_NB;
+  long            npusch_srs_SubframeConfig_NB;
+  long            npusch_threeTone_CyclicShift_r13;
+  long            npusch_sixTone_CyclicShift_r13;
+  BOOLEAN_t         npusch_groupHoppingEnabled;
+  long            npusch_groupAssignmentNPUSCH_r13;
 
   //DL_GapConfig
-  long					  dl_GapThreshold_NB;
-  long	 				  dl_GapPeriodicity_NB;
-  long	 				  dl_GapDurationCoeff_NB;
+  long            dl_GapThreshold_NB;
+  long            dl_GapPeriodicity_NB;
+  long            dl_GapDurationCoeff_NB;
   //Uplink power control Common
-  long					  npusch_p0_NominalNPUSCH;
-  long					  npusch_alpha;
-  long					  deltaPreambleMsg3;
+  long            npusch_p0_NominalNPUSCH;
+  long            npusch_alpha;
+  long            deltaPreambleMsg3;
   //UE timers and constants
-  long					  ue_TimersAndConstants_t300_NB;
-  long					  ue_TimersAndConstants_t301_NB;
-  long					  ue_TimersAndConstants_t310_NB;
-  long					  ue_TimersAndConstants_t311_NB;
-  long					  ue_TimersAndConstants_n310_NB;
-  long					  ue_TimersAndConstants_n311_NB;
+  long            ue_TimersAndConstants_t300_NB;
+  long            ue_TimersAndConstants_t301_NB;
+  long            ue_TimersAndConstants_t310_NB;
+  long            ue_TimersAndConstants_t311_NB;
+  long            ue_TimersAndConstants_n310_NB;
+  long            ue_TimersAndConstants_n311_NB;
 } NbIoTRrcConfigurationReq;
 
 
diff --git a/openair2/COMMON/s1ap_messages_def.h b/openair2/COMMON/s1ap_messages_def.h
index f98782f19ec238bb32de3fd0ce770372fa032f37..57201721ced6b4019577343a897bae1bdb3db2cd 100644
--- a/openair2/COMMON/s1ap_messages_def.h
+++ b/openair2/COMMON/s1ap_messages_def.h
@@ -39,6 +39,8 @@ MESSAGE_DEF(S1AP_PAGING_LOG    , MESSAGE_PRIORITY_MED, IttiMsgText
 MESSAGE_DEF(S1AP_E_RAB_RELEASE_REQUEST_LOG   , MESSAGE_PRIORITY_MED, IttiMsgText                      , s1ap_e_rab_release_request_log)
 MESSAGE_DEF(S1AP_E_RAB_RELEASE_RESPONSE_LOG  , MESSAGE_PRIORITY_MED, IttiMsgText                      , s1ap_e_rab_release_response_log)
 MESSAGE_DEF(S1AP_ERROR_INDICATION_LOG        , MESSAGE_PRIORITY_MED, IttiMsgText                      , s1ap_error_indication_log)
+MESSAGE_DEF(S1AP_PATH_SWITCH_REQ_LOG         , MESSAGE_PRIORITY_MED, IttiMsgText                      , s1ap_path_switch_req_log)
+MESSAGE_DEF(S1AP_PATH_SWITCH_REQ_ACK_LOG     , MESSAGE_PRIORITY_MED, IttiMsgText                      , s1ap_path_switch_req_ack_log)
 
 /* eNB application layer -> S1AP messages */
 MESSAGE_DEF(S1AP_REGISTER_ENB_REQ          , MESSAGE_PRIORITY_MED, s1ap_register_enb_req_t          , s1ap_register_enb_req)
@@ -62,6 +64,8 @@ MESSAGE_DEF(S1AP_E_RAB_SETUP_RESP          , MESSAGE_PRIORITY_MED, s1ap_e_rab_se
 MESSAGE_DEF(S1AP_E_RAB_SETUP_REQUEST_FAIL  , MESSAGE_PRIORITY_MED, s1ap_e_rab_setup_req_fail_t      , s1ap_e_rab_setup_request_fail)
 MESSAGE_DEF(S1AP_E_RAB_MODIFY_RESP          , MESSAGE_PRIORITY_MED, s1ap_e_rab_modify_resp_t          , s1ap_e_rab_modify_resp)
 MESSAGE_DEF(S1AP_E_RAB_RELEASE_RESPONSE    , MESSAGE_PRIORITY_MED, s1ap_e_rab_release_resp_t        , s1ap_e_rab_release_resp)
+MESSAGE_DEF(S1AP_PATH_SWITCH_REQ           , MESSAGE_PRIORITY_MED, s1ap_path_switch_req_t           , s1ap_path_switch_req)
+MESSAGE_DEF(S1AP_PATH_SWITCH_REQ_ACK       , MESSAGE_PRIORITY_MED, s1ap_path_switch_req_ack_t       , s1ap_path_switch_req_ack)
 
 /* S1AP -> RRC messages */
 MESSAGE_DEF(S1AP_DOWNLINK_NAS              , MESSAGE_PRIORITY_MED, s1ap_downlink_nas_t              , s1ap_downlink_nas )
diff --git a/openair2/COMMON/s1ap_messages_types.h b/openair2/COMMON/s1ap_messages_types.h
index f56a340cb24d7df4c9db45b4c6f6b156568c2817..2ea8237184fa96462c3fffe17f7877b3f2200db5 100644
--- a/openair2/COMMON/s1ap_messages_types.h
+++ b/openair2/COMMON/s1ap_messages_types.h
@@ -42,6 +42,8 @@
 #define S1AP_E_RAB_SETUP_RESP(mSGpTR)           (mSGpTR)->ittiMsg.s1ap_e_rab_setup_resp
 #define S1AP_E_RAB_SETUP_FAIL(mSGpTR)           (mSGpTR)->ittiMsg.s1ap_e_rab_setup_req_fail
 #define S1AP_E_RAB_MODIFY_RESP(mSGpTR)           (mSGpTR)->ittiMsg.s1ap_e_rab_modify_resp
+#define S1AP_PATH_SWITCH_REQ(mSGpTR)            (mSGpTR)->ittiMsg.s1ap_path_switch_req
+#define S1AP_PATH_SWITCH_REQ_ACK(mSGpTR)        (mSGpTR)->ittiMsg.s1ap_path_switch_req_ack
 
 #define S1AP_DOWNLINK_NAS(mSGpTR)               (mSGpTR)->ittiMsg.s1ap_downlink_nas
 #define S1AP_INITIAL_CONTEXT_SETUP_REQ(mSGpTR)  (mSGpTR)->ittiMsg.s1ap_initial_context_setup_req
@@ -269,6 +271,17 @@ typedef struct e_rab_setup_s {
   uint32_t gtp_teid;
 } e_rab_setup_t;
 
+typedef struct e_rab_tobeswitched_s {
+  /* Unique e_rab_id for the UE. */
+  uint8_t e_rab_id;
+
+  /* The transport layer address for the IP packets */
+  transport_layer_addr_t sgw_addr;
+
+  /* S-GW Tunnel endpoint identifier */
+  uint32_t gtp_teid;
+} e_rab_tobeswitched_t;
+
 typedef struct e_rab_modify_s {
   /* Unique e_rab_id for the UE. */
   uint8_t e_rab_id;
@@ -480,6 +493,8 @@ typedef struct s1ap_initial_context_setup_req_s {
   /* eNB ue s1ap id as initialized by S1AP layer */
   unsigned eNB_ue_s1ap_id:24;
 
+  uint32_t mme_ue_s1ap_id;
+
   /* UE aggregate maximum bitrate */
   ambr_t ue_ambr;
 
@@ -533,7 +548,7 @@ typedef struct s1ap_e_rab_setup_req_s {
   uint16_t ue_initial_id;
 
   /* MME UE id  */
-  uint16_t mme_ue_s1ap_id;
+  uint32_t mme_ue_s1ap_id;
 
   /* eNB ue s1ap id as initialized by S1AP layer */
   unsigned eNB_ue_s1ap_id:24;
@@ -560,6 +575,58 @@ typedef struct s1ap_e_rab_setup_resp_s {
   e_rab_failed_t e_rabs_failed[S1AP_MAX_E_RAB];
 } s1ap_e_rab_setup_resp_t;
 
+typedef struct s1ap_path_switch_req_s {
+
+  unsigned  eNB_ue_s1ap_id:24;
+
+  /* Number of e_rab setup-ed in the list */
+  uint8_t       nb_of_e_rabs;
+
+  /* list of e_rab setup-ed by RRC layers */
+  e_rab_setup_t e_rabs_tobeswitched[S1AP_MAX_E_RAB];
+
+  /* MME UE id  */
+  uint32_t mme_ue_s1ap_id;
+
+  s1ap_gummei_t ue_gummei;
+
+  uint16_t ue_initial_id;
+
+   /* Security algorithms */
+  security_capabilities_t security_capabilities;
+
+} s1ap_path_switch_req_t;
+
+typedef struct s1ap_path_switch_req_ack_s {
+
+  /* UE id for initial connection to S1AP */
+  uint16_t ue_initial_id;
+
+  unsigned  eNB_ue_s1ap_id:24;
+
+  /* MME UE id  */
+  uint32_t mme_ue_s1ap_id;
+
+  /* UE aggregate maximum bitrate */
+  ambr_t ue_ambr;
+
+  /* Number of e_rab setup-ed in the list */
+  uint8_t       nb_e_rabs_tobeswitched;
+
+  /* list of e_rab to be switched by RRC layers */
+  e_rab_tobeswitched_t e_rabs_tobeswitched[S1AP_MAX_E_RAB];
+
+  /* Number of e_rabs to be released by RRC */
+  uint8_t        nb_e_rabs_tobereleased;
+
+  /* list of e_rabs to be released */
+  e_rab_failed_t e_rabs_tobereleased[S1AP_MAX_E_RAB];
+
+  /* Security key */
+  int     next_hop_chain_count;
+  uint8_t next_security_key[SECURITY_KEY_LENGTH];
+
+} s1ap_path_switch_req_ack_t;
 
 // S1AP --> RRC messages
 typedef struct s1ap_ue_release_command_s {
@@ -582,7 +649,7 @@ typedef struct s1ap_e_rab_modify_req_s {
   uint16_t ue_initial_id;
 
   /* MME UE id  */
-  uint16_t mme_ue_s1ap_id;
+  uint32_t mme_ue_s1ap_id;
 
   /* eNB ue s1ap id as initialized by S1AP layer */
   unsigned eNB_ue_s1ap_id:24;
@@ -615,7 +682,7 @@ typedef struct e_rab_release_s {
 
 typedef struct s1ap_e_rab_release_command_s {
   /* MME UE id  */
-  uint16_t mme_ue_s1ap_id;
+  uint32_t mme_ue_s1ap_id;
 
   /* eNB ue s1ap id as initialized by S1AP layer */
   unsigned eNB_ue_s1ap_id:24;
@@ -633,7 +700,7 @@ typedef struct s1ap_e_rab_release_command_s {
 
 typedef struct s1ap_e_rab_release_resp_s {
   /* MME UE id  */
-  uint16_t mme_ue_s1ap_id;
+  uint32_t mme_ue_s1ap_id;
 
   /* eNB ue s1ap id as initialized by S1AP layer */
   unsigned eNB_ue_s1ap_id:24;
diff --git a/openair2/COMMON/tasks_def.h b/openair2/COMMON/tasks_def.h
index ad38c9b03172ce092eeef8eade023fedfe0b39df..2ccb7b1c29059395641813059ba1c39100f85641 100644
--- a/openair2/COMMON/tasks_def.h
+++ b/openair2/COMMON/tasks_def.h
@@ -25,18 +25,11 @@ TASK_DEF(TASK_TIMER,    TASK_PRIORITY_MAX,          10)
 // Other possible tasks in the process
 
 // Common tasks:
-/// Layer 2 and Layer 1 task supporting all the synchronous processing
-TASK_DEF(TASK_L2L1,     TASK_PRIORITY_MAX_LEAST,    200)
 
 ///   Bearers Manager task
 TASK_DEF(TASK_BM,       TASK_PRIORITY_MED,          200)
 
 // eNodeB tasks and sub-tasks:
-//// Layer 2 and Layer 1 sub-tasks
-SUB_TASK_DEF(TASK_L2L1,     TASK_PHY_ENB,               200)
-SUB_TASK_DEF(TASK_L2L1,     TASK_MAC_ENB,               200)
-SUB_TASK_DEF(TASK_L2L1,     TASK_RLC_ENB,               200)
-SUB_TASK_DEF(TASK_L2L1,     TASK_PDCP_ENB,              200)
 
 ///   Radio Resource Control task
 TASK_DEF(TASK_RRC_ENB,  TASK_PRIORITY_MED,          200)
@@ -65,11 +58,6 @@ TASK_DEF(TASK_ENB_APP,  TASK_PRIORITY_MED,          200)
 TASK_DEF(TASK_FLEXRAN_AGENT,  TASK_PRIORITY_MED,          200)
 TASK_DEF(TASK_PROTO_AGENT,  TASK_PRIORITY_MED,          200)
 // UE tasks and sub-tasks:
-//// Layer 2 and Layer 1 sub-tasks
-SUB_TASK_DEF(TASK_L2L1,     TASK_PHY_UE,                200)
-SUB_TASK_DEF(TASK_L2L1,     TASK_MAC_UE,                200)
-SUB_TASK_DEF(TASK_L2L1,     TASK_RLC_UE,                200)
-SUB_TASK_DEF(TASK_L2L1,     TASK_PDCP_UE,               200)
 
 ///   Radio Resource Control task
 TASK_DEF(TASK_RRC_UE,   TASK_PRIORITY_MED,          200)
diff --git a/openair2/COMMON/x2ap_messages_types.h b/openair2/COMMON/x2ap_messages_types.h
index c74a826ff84685c88ea9a36b6226ccbf58eee166..7cdd0ff0ff37a605e59604a0186e951ae6d47463 100644
--- a/openair2/COMMON/x2ap_messages_types.h
+++ b/openair2/COMMON/x2ap_messages_types.h
@@ -22,7 +22,8 @@
 #ifndef X2AP_MESSAGES_TYPES_H_
 #define X2AP_MESSAGES_TYPES_H_
 
-#include "PhysCellId.h"
+#include "s1ap_messages_types.h"
+#include "LTE_PhysCellId.h"
 
 //-------------------------------------------------------------------------------------------//
 // Defines to access message fields.
@@ -122,7 +123,7 @@ typedef struct x2ap_lastvisitedcell_info_s {
   uint16_t mcc;
   uint16_t mnc;
   uint8_t  mnc_len;
-  PhysCellId_t target_physCellId;
+  LTE_PhysCellId_t target_physCellId;
   cell_type_t cell_type;
   uint64_t time_UE_StayedInCell;
 }x2ap_lastvisitedcell_info_t;
@@ -132,9 +133,9 @@ typedef struct x2ap_handover_req_s {
   int source_rnti;                       /* TODO: to be fixed/remove */
   int source_x2id;                       /* TODO: to be fixed/remove */
 
-  unsigned  old_eNB_ue_s1ap_id:24;
+  int old_eNB_ue_x2ap_id;
 
-  PhysCellId_t target_physCellId;
+  LTE_PhysCellId_t target_physCellId;
 
   x2ap_gummei_t ue_gummei;
 
@@ -158,10 +159,14 @@ typedef struct x2ap_handover_req_s {
  /* list of e_rab setup-ed by RRC layers */
   e_rab_setup_t e_rabs_tobesetup[S1AP_MAX_E_RAB];
 
-  /* ue_context_pP->ue_context.e_rab[i].param.sgw_addr; */
+  /* list of e_rab to be setup by RRC layers */
+  e_rab_t  e_rab_param[S1AP_MAX_E_RAB];
 
   x2ap_lastvisitedcell_info_t lastvisitedcell_info;
 
+  uint8_t rrc_buffer[1024 /* arbitrary, big enough */];
+  int rrc_buffer_size;
+
   /* TODO: this parameter has to be removed */
   int target_mod_id;
 } x2ap_handover_req_t;
@@ -171,6 +176,15 @@ typedef struct x2ap_handover_req_ack_s {
   int source_x2id;                       /* TODO: to be fixed/remove */
   /* TODO: this parameter has to be removed */
   int target_mod_id;
+
+  uint8_t nb_e_rabs_tobesetup;
+
+ /* list of e_rab setup-ed by RRC layers */
+  e_rab_setup_t e_rabs_tobesetup[S1AP_MAX_E_RAB];
+
+  /* list of e_rab to be setup by RRC layers */
+  e_rab_t  e_rab_param[S1AP_MAX_E_RAB];
+
   uint8_t rrc_buffer[1024 /* arbitrary, big enough */];
   int rrc_buffer_size;
 
diff --git a/openair2/DOCS/DOXYGEN/Doxyfile b/openair2/DOCS/DOXYGEN/Doxyfile
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/DLC_arch.png b/openair2/DOCS/DOXYGEN/images/DLC_arch.png
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/Diapositive6.JPG b/openair2/DOCS/DOXYGEN/images/Diapositive6.JPG
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/Framing.png b/openair2/DOCS/DOXYGEN/images/Framing.png
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/Framing.vsd b/openair2/DOCS/DOXYGEN/images/Framing.vsd
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/MAC Services.vsd b/openair2/DOCS/DOXYGEN/images/MAC Services.vsd
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/MAC_Measurements.png b/openair2/DOCS/DOXYGEN/images/MAC_Measurements.png
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/MAC_Measurements.vsd b/openair2/DOCS/DOXYGEN/images/MAC_Measurements.vsd
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/MAC_Services.eps b/openair2/DOCS/DOXYGEN/images/MAC_Services.eps
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/MAC_Services.vsd b/openair2/DOCS/DOXYGEN/images/MAC_Services.vsd
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/MAC_Services2.eps b/openair2/DOCS/DOXYGEN/images/MAC_Services2.eps
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/MAC_Services2.png b/openair2/DOCS/DOXYGEN/images/MAC_Services2.png
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/MAC_Services2.vsd b/openair2/DOCS/DOXYGEN/images/MAC_Services2.vsd
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/MAC_arch.eps b/openair2/DOCS/DOXYGEN/images/MAC_arch.eps
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/MAC_architecture.JPG b/openair2/DOCS/DOXYGEN/images/MAC_architecture.JPG
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/OFDM Transmitter.png b/openair2/DOCS/DOXYGEN/images/OFDM Transmitter.png
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/OFDM Transmitter.vsd b/openair2/DOCS/DOXYGEN/images/OFDM Transmitter.vsd
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/PHY_arch.eps b/openair2/DOCS/DOXYGEN/images/PHY_arch.eps
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/PHY_arch.png b/openair2/DOCS/DOXYGEN/images/PHY_arch.png
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/PHY_arch.vsd b/openair2/DOCS/DOXYGEN/images/PHY_arch.vsd
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/QAM modulation.png b/openair2/DOCS/DOXYGEN/images/QAM modulation.png
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/QAM modulation.vsd b/openair2/DOCS/DOXYGEN/images/QAM modulation.vsd
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/QAMmodulation.png b/openair2/DOCS/DOXYGEN/images/QAMmodulation.png
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/Transmission.pdf b/openair2/DOCS/DOXYGEN/images/Transmission.pdf
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/cellular_topology.doc b/openair2/DOCS/DOXYGEN/images/cellular_topology.doc
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/cellular_topology.pdf b/openair2/DOCS/DOXYGEN/images/cellular_topology.pdf
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/cellular_topology_small.png b/openair2/DOCS/DOXYGEN/images/cellular_topology_small.png
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/channel server.png b/openair2/DOCS/DOXYGEN/images/channel server.png
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/channel server.vsd b/openair2/DOCS/DOXYGEN/images/channel server.vsd
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/convolutional.png b/openair2/DOCS/DOXYGEN/images/convolutional.png
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/convolutional.vsd b/openair2/DOCS/DOXYGEN/images/convolutional.vsd
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/irs_dcf.jpg b/openair2/DOCS/DOXYGEN/images/irs_dcf.jpg
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/irs_pcf.jpg b/openair2/DOCS/DOXYGEN/images/irs_pcf.jpg
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/layer2_stack.jpg b/openair2/DOCS/DOXYGEN/images/layer2_stack.jpg
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/layer2_stack.pdf b/openair2/DOCS/DOXYGEN/images/layer2_stack.pdf
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/layer2_stack.png b/openair2/DOCS/DOXYGEN/images/layer2_stack.png
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/mac_channels.png b/openair2/DOCS/DOXYGEN/images/mac_channels.png
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/mac_w3g4f_mac_channels.pdf b/openair2/DOCS/DOXYGEN/images/mac_w3g4f_mac_channels.pdf
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/mac_w3g4f_mac_channels.png b/openair2/DOCS/DOXYGEN/images/mac_w3g4f_mac_channels.png
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/mac_w3g4f_mac_channels.vsd b/openair2/DOCS/DOXYGEN/images/mac_w3g4f_mac_channels.vsd
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/mac_wbs.jpg b/openair2/DOCS/DOXYGEN/images/mac_wbs.jpg
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/macphynet.eps b/openair2/DOCS/DOXYGEN/images/macphynet.eps
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/macphynet.png b/openair2/DOCS/DOXYGEN/images/macphynet.png
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/mesh_frame.pdf b/openair2/DOCS/DOXYGEN/images/mesh_frame.pdf
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/mesh_topology.pdf b/openair2/DOCS/DOXYGEN/images/mesh_topology.pdf
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/mesh_topology_small.png b/openair2/DOCS/DOXYGEN/images/mesh_topology_small.png
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/scrambler.png b/openair2/DOCS/DOXYGEN/images/scrambler.png
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/scrambler.vsd b/openair2/DOCS/DOXYGEN/images/scrambler.vsd
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/w3g4f_framing.png b/openair2/DOCS/DOXYGEN/images/w3g4f_framing.png
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/w3g4f_framing.vsd b/openair2/DOCS/DOXYGEN/images/w3g4f_framing.vsd
old mode 100755
new mode 100644
diff --git a/openair2/DOCS/DOXYGEN/images/widens_mac_channels.vsd b/openair2/DOCS/DOXYGEN/images/widens_mac_channels.vsd
old mode 100755
new mode 100644
diff --git a/openair2/ENB_APP/CONTROL_MODULES/MAC/flexran_agent_mac.c b/openair2/ENB_APP/CONTROL_MODULES/MAC/flexran_agent_mac.c
index e10e78baf68a4e33f12c60b9bfeee1c87935537d..7110f681d78efa51f03c25a809c467100c59a515 100644
--- a/openair2/ENB_APP/CONTROL_MODULES/MAC/flexran_agent_mac.c
+++ b/openair2/ENB_APP/CONTROL_MODULES/MAC/flexran_agent_mac.c
@@ -772,10 +772,6 @@ int flexran_agent_mac_destroy_stats_reply(Protocol__FlexStatsReply *reply) {
   }
 
   return 0;
-
- error:
-  //LOG_E(MAC, "%s: an error occured\n", __FUNCTION__);
-  return -1;
 }
 
 int flexran_agent_mac_sr_info(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg) {
diff --git a/openair2/ENB_APP/CONTROL_MODULES/RRC/flexran_agent_rrc.c b/openair2/ENB_APP/CONTROL_MODULES/RRC/flexran_agent_rrc.c
index 4717bcbc1e8ecbed0e844d2cde621312f9398d73..a785c681635f2db9d0c6cb83b8a80a5f531dd5ae 100644
--- a/openair2/ENB_APP/CONTROL_MODULES/RRC/flexran_agent_rrc.c
+++ b/openair2/ENB_APP/CONTROL_MODULES/RRC/flexran_agent_rrc.c
@@ -128,7 +128,7 @@ int flexran_agent_destroy_ue_state_change(Protocol__FlexranMessage *msg) {
 }
 
 /* this is called by RRC as a part of rrc xface  . The controller previously requested  this*/ 
-void flexran_trigger_rrc_measurements (mid_t mod_id, MeasResults_t*  measResults) {
+void flexran_trigger_rrc_measurements (mid_t mod_id, LTE_MeasResults_t*  measResults) {
 
   // int                   priority = 0; // Warning Preventing
   // void                  *data;
diff --git a/openair2/ENB_APP/CONTROL_MODULES/RRC/flexran_agent_rrc.h b/openair2/ENB_APP/CONTROL_MODULES/RRC/flexran_agent_rrc.h
index 6007da2cf46201d6b40f476202c1dbe1a7ba6aab..4b9cec861427871ec0c4973f03062564c78e081a 100644
--- a/openair2/ENB_APP/CONTROL_MODULES/RRC/flexran_agent_rrc.h
+++ b/openair2/ENB_APP/CONTROL_MODULES/RRC/flexran_agent_rrc.h
@@ -54,7 +54,7 @@ int flexran_agent_destroy_ue_state_change(Protocol__FlexranMessage *msg);
 // void flexran_agent_send_update_rrc_stats(mid_t mod_id);
 
 /* this is called by RRC as a part of rrc xface  . The controller previously requested  this*/ 
-void flexran_trigger_rrc_measurements (mid_t mod_id, MeasResults_t *);
+void flexran_trigger_rrc_measurements (mid_t mod_id, LTE_MeasResults_t *);
 
 /* Statistics reply protocol message constructor and destructor */
 int flexran_agent_rrc_stats_reply(mid_t mod_id, const report_config_t *report_config, Protocol__FlexUeStatsReport **ue_report, Protocol__FlexCellStatsReport **cell_report);
diff --git a/openair2/ENB_APP/CONTROL_MODULES/RRC/flexran_agent_rrc_defs.h b/openair2/ENB_APP/CONTROL_MODULES/RRC/flexran_agent_rrc_defs.h
index 8c336abef1a54e3acf3e2f571251d697a595a373..5f6432732f486e1842068fa5b33e76e8a548f26c 100644
--- a/openair2/ENB_APP/CONTROL_MODULES/RRC/flexran_agent_rrc_defs.h
+++ b/openair2/ENB_APP/CONTROL_MODULES/RRC/flexran_agent_rrc_defs.h
@@ -34,7 +34,7 @@
 #include "flexran_agent_defs.h"
 #include "flexran.pb-c.h"
 #include "header.pb-c.h"
-#include "MeasResults.h"
+#include "LTE_MeasResults.h"
 
 #define RINGBUFFER_SIZE 100
 
@@ -62,7 +62,7 @@ typedef struct {
   void (*flexran_agent_notify_ue_state_change)(mid_t mod_id, uint32_t rnti,
                  uint8_t state_change);
 
-  void (*flexran_trigger_rrc_measurements)(mid_t mod_id, MeasResults_t*  measResults);
+  void (*flexran_trigger_rrc_measurements)(mid_t mod_id, LTE_MeasResults_t*  measResults);
   
 } AGENT_RRC_xface;
 
diff --git a/openair2/ENB_APP/Makefile.inc b/openair2/ENB_APP/Makefile.inc
deleted file mode 100644
index e018d676105f151594d2f6abfb230593a4b7680d..0000000000000000000000000000000000000000
--- a/openair2/ENB_APP/Makefile.inc
+++ /dev/null
@@ -1,7 +0,0 @@
-ENB_APP_DIR = $(OPENAIR2_TOP)/ENB_APP
-
-ENB_APP_OBJS =  $(ENB_APP_DIR)/enb_app.o \
-                $(ENB_APP_DIR)/enb_config.o 
-ENB_APP_incl = \
-    -I$(ENB_APP_DIR) -I$(OPENAIR2_TOP)
-    
diff --git a/openair2/ENB_APP/NB_IoT_config.c b/openair2/ENB_APP/NB_IoT_config.c
index 08c3d30fa366cc0012c9550ea202d9b396567112..272fa48b3e09079df1b4ca8a8533eff3f52dd9d1 100644
--- a/openair2/ENB_APP/NB_IoT_config.c
+++ b/openair2/ENB_APP/NB_IoT_config.c
@@ -34,11 +34,11 @@
 #include "log_extern.h"
 #include "assertions.h"
 #if defined(ENABLE_ITTI)
-# include "intertask_interface.h"
-# if defined(ENABLE_USE_MME)
-#   include "s1ap_eNB.h"
-#   include "sctp_eNB_task.h"
-# endif
+  #include "intertask_interface.h"
+  #if defined(ENABLE_USE_MME)
+    #include "s1ap_eNB.h"
+    #include "sctp_eNB_task.h"
+  #endif
 #endif
 #include "SystemInformationBlockType2.h"
 
@@ -56,11 +56,10 @@
 void RCconfig_NbIoTL1(void) {
   paramdef_t NbIoT_L1_Params[] = L1PARAMS_DESC;
   paramlist_def_t NbIoT_L1_ParamList = {NBIOT_L1LIST_CONFIG_STRING,NULL,0};
+  /* No component carrier for NbIoT, ignore number of CC */
+  //  NbIoT_L1_Params[L1_CC_IDX ].paramflags = PARAMFLAG_DONOTREAD;
+  config_getlist( &NbIoT_L1_ParamList,NbIoT_L1_Params,sizeof(NbIoT_L1_Params)/sizeof(paramdef_t), NULL);
 
-/* No component carrier for NbIoT, ignore number of CC */
-//  NbIoT_L1_Params[L1_CC_IDX ].paramflags = PARAMFLAG_DONOTREAD;
-
-  config_getlist( &NbIoT_L1_ParamList,NbIoT_L1_Params,sizeof(NbIoT_L1_Params)/sizeof(paramdef_t), NULL);    
   if (NbIoT_L1_ParamList.numelt > 0) {
     if (RC.L1_NB_IoT == NULL) {
       RC.L1_NB_IoT                         = (PHY_VARS_eNB_NB_IoT **)malloc(RC.nb_nb_iot_L1_inst*sizeof(PHY_VARS_eNB_NB_IoT *));
@@ -68,219 +67,190 @@ void RCconfig_NbIoTL1(void) {
       memset(RC.L1_NB_IoT,0,RC.nb_nb_iot_L1_inst*sizeof(PHY_VARS_eNB_NB_IoT *));
     }
 
-
-  for(int j = 0; j <NbIoT_L1_ParamList.numelt ; j++) {
+    for(int j = 0; j <NbIoT_L1_ParamList.numelt ; j++) {
       if (RC.L1_NB_IoT[j] == NULL) {
-	RC.L1_NB_IoT[j]                       = (PHY_VARS_eNB_NB_IoT *)malloc(sizeof(PHY_VARS_eNB_NB_IoT));
-	LOG_I(PHY,"RC.L1_NB_IoT[%d] = %p\n",j,RC.L1_NB_IoT[j]);
-	memset(RC.L1_NB_IoT[j],0,sizeof(PHY_VARS_eNB_NB_IoT));
+        RC.L1_NB_IoT[j]                       = (PHY_VARS_eNB_NB_IoT *)malloc(sizeof(PHY_VARS_eNB_NB_IoT));
+        LOG_I(PHY,"RC.L1_NB_IoT[%d] = %p\n",j,RC.L1_NB_IoT[j]);
+        memset(RC.L1_NB_IoT[j],0,sizeof(PHY_VARS_eNB_NB_IoT));
       }
-      if (strcmp(*(NbIoT_L1_ParamList.paramarray[j][L1_TRANSPORT_N_PREFERENCE_IDX].strptr), "local_mac") == 0) {
 
+      if (strcmp(*(NbIoT_L1_ParamList.paramarray[j][L1_TRANSPORT_N_PREFERENCE_IDX].strptr), "local_mac") == 0) {
+      } else if (strcmp(*(NbIoT_L1_ParamList.paramarray[j][L1_TRANSPORT_N_PREFERENCE_IDX].strptr), "nfapi") == 0) {
+        RC.L1_NB_IoT[j]->eth_params_n.local_if_name        = strdup(*(NbIoT_L1_ParamList.paramarray[j][L1_LOCAL_N_IF_NAME_IDX].strptr));
+        RC.L1_NB_IoT[j]->eth_params_n.my_addr         = strdup(*(NbIoT_L1_ParamList.paramarray[j][L1_LOCAL_N_ADDRESS_IDX].strptr));
+        RC.L1_NB_IoT[j]->eth_params_n.remote_addr       = strdup(*(NbIoT_L1_ParamList.paramarray[j][L1_REMOTE_N_ADDRESS_IDX].strptr));
+        RC.L1_NB_IoT[j]->eth_params_n.my_portc          = *(NbIoT_L1_ParamList.paramarray[j][L1_LOCAL_N_PORTC_IDX].iptr);
+        RC.L1_NB_IoT[j]->eth_params_n.remote_portc        = *(NbIoT_L1_ParamList.paramarray[j][L1_REMOTE_N_PORTC_IDX].iptr);
+        RC.L1_NB_IoT[j]->eth_params_n.my_portd          = *(NbIoT_L1_ParamList.paramarray[j][L1_LOCAL_N_PORTD_IDX].iptr);
+        RC.L1_NB_IoT[j]->eth_params_n.remote_portd        = *(NbIoT_L1_ParamList.paramarray[j][L1_REMOTE_N_PORTD_IDX].iptr);
+        RC.L1_NB_IoT[j]->eth_params_n.transp_preference       = ETH_UDP_MODE;
+      } else { // other midhaul
       }
-      else if (strcmp(*(NbIoT_L1_ParamList.paramarray[j][L1_TRANSPORT_N_PREFERENCE_IDX].strptr), "nfapi") == 0) {
-	RC.L1_NB_IoT[j]->eth_params_n.local_if_name	       = strdup(*(NbIoT_L1_ParamList.paramarray[j][L1_LOCAL_N_IF_NAME_IDX].strptr));
-	RC.L1_NB_IoT[j]->eth_params_n.my_addr		      = strdup(*(NbIoT_L1_ParamList.paramarray[j][L1_LOCAL_N_ADDRESS_IDX].strptr));
-	RC.L1_NB_IoT[j]->eth_params_n.remote_addr	      = strdup(*(NbIoT_L1_ParamList.paramarray[j][L1_REMOTE_N_ADDRESS_IDX].strptr));
-	RC.L1_NB_IoT[j]->eth_params_n.my_portc  	      = *(NbIoT_L1_ParamList.paramarray[j][L1_LOCAL_N_PORTC_IDX].iptr);
-	RC.L1_NB_IoT[j]->eth_params_n.remote_portc	      = *(NbIoT_L1_ParamList.paramarray[j][L1_REMOTE_N_PORTC_IDX].iptr);
-	RC.L1_NB_IoT[j]->eth_params_n.my_portd  	      = *(NbIoT_L1_ParamList.paramarray[j][L1_LOCAL_N_PORTD_IDX].iptr);
-	RC.L1_NB_IoT[j]->eth_params_n.remote_portd	      = *(NbIoT_L1_ParamList.paramarray[j][L1_REMOTE_N_PORTD_IDX].iptr);
-	RC.L1_NB_IoT[j]->eth_params_n.transp_preference       = ETH_UDP_MODE;
-      }
-      
-      else { // other midhaul
-      }	
     }// j=0..num_inst
+
     printf("Initializing northbound interface for NB-IoT L1\n");
     l1_north_init_NB_IoT();
   } else {
-    LOG_I(PHY,"No " NBIOT_L1LIST_CONFIG_STRING " configuration found");    
+    LOG_I(PHY,"No " NBIOT_L1LIST_CONFIG_STRING " configuration found");
   }
 }
 
 void RCconfig_NbIoTmacrlc(void) {
- 
-
-
   paramdef_t NbIoT_MacRLC_Params[] = MACRLCPARAMS_DESC;
   paramlist_def_t NbIoT_MacRLC_ParamList = {NBIOT_MACRLCLIST_CONFIG_STRING,NULL,0};
-
-
-/* No component carrier for NbIoT, ignore number of CC */
-//  NbIoT_MacRLC_Params[MACRLC_CC_IDX ].paramflags = PARAMFLAG_DONOTREAD;
-
-  config_getlist( &NbIoT_MacRLC_ParamList,NbIoT_MacRLC_Params,sizeof(NbIoT_MacRLC_Params)/sizeof(paramdef_t), NULL);    
-  
+  /* No component carrier for NbIoT, ignore number of CC */
+  //  NbIoT_MacRLC_Params[MACRLC_CC_IDX ].paramflags = PARAMFLAG_DONOTREAD;
+  config_getlist( &NbIoT_MacRLC_ParamList,NbIoT_MacRLC_Params,sizeof(NbIoT_MacRLC_Params)/sizeof(paramdef_t), NULL);
 
   if ( NbIoT_MacRLC_ParamList.numelt > 0) {
     mac_top_init_eNB_NB_IoT();
-    for (int j=0;j<RC.nb_nb_iot_macrlc_inst;j++) {
 
+    for (int j=0; j<RC.nb_nb_iot_macrlc_inst; j++) {
       if (strcmp(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_TRANSPORT_N_PREFERENCE_IDX].strptr), "local_RRC") == 0) {
-	// check number of instances is same as RRC/PDCP
-	
+        // check number of instances is same as RRC/PDCP
       } else if (strcmp(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_TRANSPORT_N_PREFERENCE_IDX].strptr), "cudu") == 0) {
-	RC.nb_iot_mac[j]->eth_params_n.local_if_name            = strdup(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_N_IF_NAME_IDX].strptr));
-	RC.nb_iot_mac[j]->eth_params_n.my_addr                  = strdup(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_N_ADDRESS_IDX].strptr));
-	RC.nb_iot_mac[j]->eth_params_n.remote_addr              = strdup(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_REMOTE_N_ADDRESS_IDX].strptr));
-	RC.nb_iot_mac[j]->eth_params_n.my_portc                 = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_N_PORTC_IDX].iptr);
-	RC.nb_iot_mac[j]->eth_params_n.remote_portc             = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_REMOTE_N_PORTC_IDX].iptr);
-	RC.nb_iot_mac[j]->eth_params_n.my_portd                 = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_N_PORTD_IDX].iptr);
-	RC.nb_iot_mac[j]->eth_params_n.remote_portd             = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_REMOTE_N_PORTD_IDX].iptr);;
-	RC.nb_iot_mac[j]->eth_params_n.transp_preference        = ETH_UDP_MODE;
+        RC.nb_iot_mac[j]->eth_params_n.local_if_name            = strdup(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_N_IF_NAME_IDX].strptr));
+        RC.nb_iot_mac[j]->eth_params_n.my_addr                  = strdup(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_N_ADDRESS_IDX].strptr));
+        RC.nb_iot_mac[j]->eth_params_n.remote_addr              = strdup(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_REMOTE_N_ADDRESS_IDX].strptr));
+        RC.nb_iot_mac[j]->eth_params_n.my_portc                 = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_N_PORTC_IDX].iptr);
+        RC.nb_iot_mac[j]->eth_params_n.remote_portc             = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_REMOTE_N_PORTC_IDX].iptr);
+        RC.nb_iot_mac[j]->eth_params_n.my_portd                 = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_N_PORTD_IDX].iptr);
+        RC.nb_iot_mac[j]->eth_params_n.remote_portd             = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_REMOTE_N_PORTD_IDX].iptr);;
+        RC.nb_iot_mac[j]->eth_params_n.transp_preference        = ETH_UDP_MODE;
       } else { // other midhaul
-	AssertFatal(1==0,"MACRLC %d: %s unknown northbound midhaul\n",j, *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_TRANSPORT_N_PREFERENCE_IDX].strptr));
-      }	
+        AssertFatal(1==0,"MACRLC %d: %s unknown northbound midhaul\n",j, *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_TRANSPORT_N_PREFERENCE_IDX].strptr));
+      }
 
       if (strcmp(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_TRANSPORT_S_PREFERENCE_IDX].strptr), "local_L1") == 0) {
-
-	
       } else if (strcmp(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_TRANSPORT_S_PREFERENCE_IDX].strptr), "nfapi") == 0) {
-	RC.nb_iot_mac[j]->eth_params_s.local_if_name		= strdup(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_S_IF_NAME_IDX].strptr));
-	RC.nb_iot_mac[j]->eth_params_s.my_addr  		= strdup(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_S_ADDRESS_IDX].strptr));
-	RC.nb_iot_mac[j]->eth_params_s.remote_addr		= strdup(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_REMOTE_S_ADDRESS_IDX].strptr));
-	RC.nb_iot_mac[j]->eth_params_s.my_portc 		= *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_S_PORTC_IDX].iptr);
-	RC.nb_iot_mac[j]->eth_params_s.remote_portc             = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_REMOTE_S_PORTC_IDX].iptr);
-	RC.nb_iot_mac[j]->eth_params_s.my_portd                 = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_S_PORTD_IDX].iptr);
-	RC.nb_iot_mac[j]->eth_params_s.remote_portd             = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_REMOTE_S_PORTD_IDX].iptr);
-	RC.nb_iot_mac[j]->eth_params_s.transp_preference        = ETH_UDP_MODE;
+        RC.nb_iot_mac[j]->eth_params_s.local_if_name    = strdup(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_S_IF_NAME_IDX].strptr));
+        RC.nb_iot_mac[j]->eth_params_s.my_addr      = strdup(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_S_ADDRESS_IDX].strptr));
+        RC.nb_iot_mac[j]->eth_params_s.remote_addr    = strdup(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_REMOTE_S_ADDRESS_IDX].strptr));
+        RC.nb_iot_mac[j]->eth_params_s.my_portc     = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_S_PORTC_IDX].iptr);
+        RC.nb_iot_mac[j]->eth_params_s.remote_portc             = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_REMOTE_S_PORTC_IDX].iptr);
+        RC.nb_iot_mac[j]->eth_params_s.my_portd                 = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_S_PORTD_IDX].iptr);
+        RC.nb_iot_mac[j]->eth_params_s.remote_portd             = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_REMOTE_S_PORTD_IDX].iptr);
+        RC.nb_iot_mac[j]->eth_params_s.transp_preference        = ETH_UDP_MODE;
       } else { // other midhaul
-	AssertFatal(1==0,"MACRLC %d: %s unknown southbound midhaul\n",j,*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_TRANSPORT_S_PREFERENCE_IDX].strptr));
-      }	
+        AssertFatal(1==0,"MACRLC %d: %s unknown southbound midhaul\n",j,*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_TRANSPORT_S_PREFERENCE_IDX].strptr));
+      }
     }// j=0..num_inst */
   } else {// MacRLC_ParamList.numelt > 0
-	  AssertFatal (0,
-		       "No " NBIOT_MACRLCLIST_CONFIG_STRING " configuration found");     
+    AssertFatal (0,
+                 "No " NBIOT_MACRLCLIST_CONFIG_STRING " configuration found");
   }
 }
 
 
 
-	       
-int RCconfig_NbIoTRRC(MessageDef *msg_p, int nbiotrrc_id,eNB_RRC_INST_NB_IoT *nbiotrrc) {
-
 
+int RCconfig_NbIoTRRC(MessageDef *msg_p, int nbiotrrc_id,eNB_RRC_INST_NB_IoT *nbiotrrc) {
   char instprefix[MAX_OPTNAME_SIZE*3 + 32];
-  
- 
-  checkedparam_t NBIoTCheckParams[] = NBIOT_RRCPARAMS_CHECK_DESC;
+  checkedparam_t NBIoTCheckParams[]  = NBIOT_RRCPARAMS_CHECK_DESC_0_14;
+  checkedparam_t NBIoTCheckParamsB[] = NBIOT_RRCPARAMS_CHECK_DESC_15_end;
   paramdef_t     NBIoTParams[]      = NBIOTRRCPARAMS_DESC;
-
   paramdef_t     NBIoTPrachParams[]      = NBIOTRRC_NPRACH_PARAMS_DESC;
   checkedparam_t NBIoTPrachCheckParams[] = NBIOT_RRCLIST_NPRACHPARAMSCHECK_DESC;
-
   paramdef_t     NBIoTRRCRefParams[]      = NBIOTRRCPARAMS_RRCREF_DESC;
-
   paramdef_t     NBIoTLteCCParams[] = NBIOT_LTECCPARAMS_DESC;
   checkedparam_t NBIoTLteCCCheckParams[] = NBIOT_LTECCPARAMS_CHECK_DESC;
-/* map parameter checking array instances to parameter definition array instances */
+
+  /* map parameter checking array instances to parameter definition array instances */
   for (int i=0; (i<sizeof(NBIoTParams)/sizeof(paramdef_t)) && (i<sizeof(NBIoTCheckParams)/sizeof(checkedparam_t)); i++ ) {
-     NBIoTParams[i].chkPptr = &(NBIoTCheckParams[i]); 
-  } 
+    NBIoTParams[i].chkPptr = &(NBIoTCheckParams[i]);
+  }
+
+  for (int i=0; (i<sizeof(NBIoTParams)/sizeof(paramdef_t)) && (i<sizeof(NBIoTCheckParamsB)/sizeof(checkedparam_t)); i++ ) {
+    NBIoTParams[i+15].chkPptr = &(NBIoTCheckParamsB[i]);
+  }
+
   for (int i=0; (i<sizeof(NBIoTPrachParams)/sizeof(paramdef_t)) && (i<sizeof(NBIoTPrachCheckParams)/sizeof(checkedparam_t)); i++ ) {
-     NBIoTPrachParams[i].chkPptr = &(NBIoTPrachCheckParams[i]);
+    NBIoTPrachParams[i].chkPptr = &(NBIoTPrachCheckParams[i]);
   }
 
-/* brut force itti message fields assignment, to be redesigned with itti replacement */
+  /* brut force itti message fields assignment, to be redesigned with itti replacement */
   NBIoTParams[NBIOT_RACH_RARESPONSEWINDOWSIZE_NB_IDX].uptr               = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).rach_raResponseWindowSize_NB);
   NBIoTParams[NBIOT_RACH_MACCONTENTIONRESOLUTIONTIMER_NB_IDX].uptr       = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).rach_macContentionResolutionTimer_NB);
-  NBIoTParams[NBIOT_RACH_POWERRAMPINGSTEP_NB_IDX].uptr                   = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).rach_powerRampingStep_NB);		     		   
+  NBIoTParams[NBIOT_RACH_POWERRAMPINGSTEP_NB_IDX].uptr                   = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).rach_powerRampingStep_NB);
   NBIoTParams[NBIOT_RACH_PREAMBLEINITIALRECEIVEDTARGETPOWER_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).rach_preambleInitialReceivedTargetPower_NB);
-  NBIoTParams[NBIOT_RACH_PREAMBLETRANSMAX_CE_NB_IDX].uptr                = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).rach_preambleTransMax_CE_NB);				    
-  NBIoTParams[NBIOT_BCCH_MODIFICATIONPERIODCOEFF_NB_IDX].uptr            = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).bcch_modificationPeriodCoeff_NB);	 
-  NBIoTParams[NBIOT_PCCH_DEFAULTPAGINGCYCLE_NB_IDX].uptr                 = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).pcch_defaultPagingCycle_NB);	 
-  NBIoTParams[NBIOT_NPRACH_CP_LENGTH_IDX].uptr                           = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).nprach_CP_Length);  		 
-  NBIoTParams[NBIOT_NPRACH_RSRP_RANGE_IDX].uptr                          = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).nprach_rsrp_range); 		       
-
-  
-  
+  NBIoTParams[NBIOT_RACH_PREAMBLETRANSMAX_CE_NB_IDX].uptr                = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).rach_preambleTransMax_CE_NB);
+  NBIoTParams[NBIOT_BCCH_MODIFICATIONPERIODCOEFF_NB_IDX].uptr            = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).bcch_modificationPeriodCoeff_NB);
+  NBIoTParams[NBIOT_PCCH_DEFAULTPAGINGCYCLE_NB_IDX].uptr                 = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).pcch_defaultPagingCycle_NB);
+  NBIoTParams[NBIOT_NPRACH_CP_LENGTH_IDX].uptr                           = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).nprach_CP_Length);
+  NBIoTParams[NBIOT_NPRACH_RSRP_RANGE_IDX].uptr                          = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).nprach_rsrp_range);
   NBIoTParams[NBIOT_MAXNUMPREAMBLEATTEMPTCE_NB_IDX].uptr                 = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).maxNumPreambleAttemptCE_NB);
-
-  NBIoTParams[NBIOT_NPDSCH_NRS_POWER_IDX].uptr  			 = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).npdsch_nrs_Power);       
-  NBIoTParams[NBIOT_NPUSCH_ACK_NACK_NUMREPETITIONS_NB_IDX].uptr 	 = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p). npusch_ack_nack_numRepetitions_NB);
-  NBIoTParams[NBIOT_NPUSCH_SRS_SUBFRAMECONFIG_NB_IDX].uptr		 = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p). npusch_srs_SubframeConfig_NB);
-  NBIoTParams[NBIOT_NPUSCH_THREETONE_CYCLICSHIFT_R13_IDX].uptr 	         = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).npusch_threeTone_CyclicShift_r13);
+  NBIoTParams[NBIOT_NPDSCH_NRS_POWER_IDX].uptr         = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).npdsch_nrs_Power);
+  NBIoTParams[NBIOT_NPUSCH_ACK_NACK_NUMREPETITIONS_NB_IDX].uptr    = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p). npusch_ack_nack_numRepetitions_NB);
+  NBIoTParams[NBIOT_NPUSCH_SRS_SUBFRAMECONFIG_NB_IDX].uptr     = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p). npusch_srs_SubframeConfig_NB);
+  NBIoTParams[NBIOT_NPUSCH_THREETONE_CYCLICSHIFT_R13_IDX].uptr           = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).npusch_threeTone_CyclicShift_r13);
   NBIoTParams[NBIOT_NPUSCH_SIXTONE_CYCLICSHIFT_R13_IDX].uptr             = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).npusch_sixTone_CyclicShift_r13);
-  
   NBIoTParams[NBIOT_NPUSCH_GROUPASSIGNMENTNPUSCH_R13_IDX].uptr           = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).npusch_groupAssignmentNPUSCH_r13);
-  NBIoTParams[NBIOT_DL_GAPTHRESHOLD_NB_IDX].uptr                         = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).dl_GapThreshold_NB);	 
-  NBIoTParams[NBIOT_DL_GAPPERIODICITY_NB_IDX].uptr                       = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).dl_GapPeriodicity_NB);	 
-  
-  NBIoTParams[NBIOT_NPUSCH_P0_NOMINALNPUSCH_IDX].uptr                    = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).npusch_p0_NominalNPUSCH);	  
-  		  
-  NBIoTParams[NBIOT_DELTAPREAMBLEMSG3_IDX].uptr                          = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).deltaPreambleMsg3); 	  
-  NBIoTParams[NBIOT_UE_TIMERSANDCONSTANTS_T300_NB_IDX].uptr              = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).ue_TimersAndConstants_t300_NB);						 
+  NBIoTParams[NBIOT_DL_GAPTHRESHOLD_NB_IDX].uptr                         = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).dl_GapThreshold_NB);
+  NBIoTParams[NBIOT_DL_GAPPERIODICITY_NB_IDX].uptr                       = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).dl_GapPeriodicity_NB);
+  NBIoTParams[NBIOT_NPUSCH_P0_NOMINALNPUSCH_IDX].uptr                    = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).npusch_p0_NominalNPUSCH);
+  NBIoTParams[NBIOT_DELTAPREAMBLEMSG3_IDX].uptr                          = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).deltaPreambleMsg3);
+  NBIoTParams[NBIOT_UE_TIMERSANDCONSTANTS_T300_NB_IDX].uptr              = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).ue_TimersAndConstants_t300_NB);
   NBIoTParams[NBIOT_UE_TIMERSANDCONSTANTS_T301_NB_IDX].uptr              = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).ue_TimersAndConstants_t301_NB);
-  NBIoTParams[NBIOT_UE_TIMERSANDCONSTANTS_T310_NB_IDX].uptr              = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).ue_TimersAndConstants_t310_NB);						
-  NBIoTParams[NBIOT_UE_TIMERSANDCONSTANTS_T311_NB_IDX].uptr              = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).ue_TimersAndConstants_t311_NB);						
-  NBIoTParams[NBIOT_UE_TIMERSANDCONSTANTS_N310_NB_IDX].uptr              = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).ue_TimersAndConstants_n310_NB);						
+  NBIoTParams[NBIOT_UE_TIMERSANDCONSTANTS_T310_NB_IDX].uptr              = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).ue_TimersAndConstants_t310_NB);
+  NBIoTParams[NBIOT_UE_TIMERSANDCONSTANTS_T311_NB_IDX].uptr              = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).ue_TimersAndConstants_t311_NB);
+  NBIoTParams[NBIOT_UE_TIMERSANDCONSTANTS_N310_NB_IDX].uptr              = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).ue_TimersAndConstants_n310_NB);
   NBIoTParams[NBIOT_UE_TIMERSANDCONSTANTS_N311_NB_IDX].uptr              = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).ue_TimersAndConstants_n311_NB);
-
   sprintf(instprefix, NBIOT_RRCLIST_CONFIG_STRING ".[%i]",nbiotrrc_id);
-  config_get( NBIoTParams,sizeof(NBIoTParams)/sizeof(paramdef_t),instprefix); 
-
+  config_get( NBIoTParams,sizeof(NBIoTParams)/sizeof(paramdef_t),instprefix);
   NBIOTRRC_CONFIGURATION_REQ (msg_p).nprach_SubcarrierMSG3_RangeStart    = config_get_processedint( &(NBIoTParams[NBIOT_NPRACH_SUBCARRIERMSG3_RANGESTART_IDX]) );
-  NBIOTRRC_CONFIGURATION_REQ (msg_p).npusch_groupHoppingEnabled          = config_get_processedint( &(NBIoTParams[NBIOT_NPUSCH_GROUPHOPPINGENABLED_IDX]      ) ); 
-  NBIOTRRC_CONFIGURATION_REQ (msg_p).dl_GapDurationCoeff_NB              = config_get_processedint( &(NBIoTParams[NBIOT_DL_GAPDURATIONCOEFF_NB_IDX]          ) ); 	 
+  NBIOTRRC_CONFIGURATION_REQ (msg_p).npusch_groupHoppingEnabled          = config_get_processedint( &(NBIoTParams[NBIOT_NPUSCH_GROUPHOPPINGENABLED_IDX]      ) );
+  NBIOTRRC_CONFIGURATION_REQ (msg_p).dl_GapDurationCoeff_NB              = config_get_processedint( &(NBIoTParams[NBIOT_DL_GAPDURATIONCOEFF_NB_IDX]          ) );
   NBIOTRRC_CONFIGURATION_REQ (msg_p).npusch_alpha                        = config_get_processedint( &(NBIoTParams[NBIOT_NPUSCH_ALPHA_IDX]                    ) );
+
   for (int i=0; i<MAX_NUM_NBIOT_CELEVELS; i++) {
-       char *tmpptr=NULL;
-       NBIoTPrachParams[NBIOT_NPRACH_PERIODICITY_IDX ].uptr	            = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).nprach_Periodicity[i]);		
-       NBIoTPrachParams[NBIOT_NPRACH_STARTTIME_IDX].uptr  	            = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).nprach_StartTime[i]);			
-       NBIoTPrachParams[NBIOT_NPRACH_SUBCARRIEROFFSET_IDX].uptr	            = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).nprach_SubcarrierOffset[i]);		
-       NBIoTPrachParams[NBIOT_NPRACH_NUMSUBCARRIERS_IDX].uptr	            = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).nprach_NumSubcarriers[i]);		
-       NBIoTPrachParams[NBIOT_NUMREPETITIONSPERPREAMBLEATTEMPT_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).numRepetitionsPerPreambleAttempt_NB[i]);
-       NBIoTParams[NBIOT_NPDCCH_NUMREPETITIONS_RA_IDX].uptr                 = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).npdcch_NumRepetitions_RA[i]);
-       NBIoTParams[NBIOT_NPDCCH_STARTSF_CSS_RA_IDX].uptr	            = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).npdcch_StartSF_CSS_RA[i]);
-       NBIoTParams[NBIOT_NPDCCH_OFFSET_RA_IDX].strptr			    = &tmpptr;
-       sprintf(instprefix, "%s.[%i].%s.[%i]",NBIOT_RRCLIST_CONFIG_STRING, nbiotrrc_id,NBIOT_RRCLIST_NPRACHPARAMS_CONFIG_STRING,i);
-       config_get( NBIoTPrachParams,sizeof(NBIoTPrachParams)/sizeof(paramdef_t),instprefix); 
-       NBIOTRRC_CONFIGURATION_REQ (msg_p).npdcch_Offset_RA[i] = config_get_processedint( &(NBIoTPrachParams[NBIOT_NPDCCH_OFFSET_RA_IDX]) ); 
+    char *tmpptr=NULL;
+    NBIoTPrachParams[NBIOT_NPRACH_PERIODICITY_IDX ].uptr             = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).nprach_Periodicity[i]);
+    NBIoTPrachParams[NBIOT_NPRACH_STARTTIME_IDX].uptr                = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).nprach_StartTime[i]);
+    NBIoTPrachParams[NBIOT_NPRACH_SUBCARRIEROFFSET_IDX].uptr             = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).nprach_SubcarrierOffset[i]);
+    NBIoTPrachParams[NBIOT_NPRACH_NUMSUBCARRIERS_IDX].uptr             = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).nprach_NumSubcarriers[i]);
+    NBIoTPrachParams[NBIOT_NUMREPETITIONSPERPREAMBLEATTEMPT_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).numRepetitionsPerPreambleAttempt_NB[i]);
+    NBIoTParams[NBIOT_NPDCCH_NUMREPETITIONS_RA_IDX].uptr                 = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).npdcch_NumRepetitions_RA[i]);
+    NBIoTParams[NBIOT_NPDCCH_STARTSF_CSS_RA_IDX].uptr              = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).npdcch_StartSF_CSS_RA[i]);
+    NBIoTParams[NBIOT_NPDCCH_OFFSET_RA_IDX].strptr         = &tmpptr;
+    sprintf(instprefix, "%s.[%i].%s.[%i]",NBIOT_RRCLIST_CONFIG_STRING, nbiotrrc_id,NBIOT_RRCLIST_NPRACHPARAMS_CONFIG_STRING,i);
+    config_get( NBIoTPrachParams,sizeof(NBIoTPrachParams)/sizeof(paramdef_t),instprefix);
+    NBIOTRRC_CONFIGURATION_REQ (msg_p).npdcch_Offset_RA[i] = config_get_processedint( &(NBIoTPrachParams[NBIOT_NPDCCH_OFFSET_RA_IDX]) );
   }
-/* get the LTE RRC and CC this NB-IoT RRC instance is attached to */
-  sprintf(instprefix, NBIOT_RRCLIST_CONFIG_STRING ".[%i]." NBIOT_LTERRCREF_CONFIG_STRING, nbiotrrc_id );
-  config_get( NBIoTRRCRefParams,sizeof(NBIoTRRCRefParams)/sizeof(paramdef_t),instprefix); 
 
-/* read SIB1 parameters in the LTE RRC and CC sections */
+  /* get the LTE RRC and CC this NB-IoT RRC instance is attached to */
+  sprintf(instprefix, NBIOT_RRCLIST_CONFIG_STRING ".[%i]." NBIOT_LTERRCREF_CONFIG_STRING, nbiotrrc_id );
+  config_get( NBIoTRRCRefParams,sizeof(NBIoTRRCRefParams)/sizeof(paramdef_t),instprefix);
+  /* read SIB1 parameters in the LTE RRC and CC sections */
   sprintf(instprefix, ENB_CONFIG_STRING_ENB_LIST ".[%i]."  ENB_CONFIG_STRING_COMPONENT_CARRIERS ".[%i]",
-          *(NBIoTRRCRefParams[NBIOT_RRCINST_IDX].uptr), *(NBIoTRRCRefParams[NBIOT_CCINST_IDX].uptr)); 
-
-  NBIoTLteCCParams[LTECCPARAMS_TDD_CONFIG_IDX  ].uptr	         = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).tdd_config);
-  NBIoTLteCCParams[LTECCPARAMS_TDD_CONFIG_S_IDX].uptr	         = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).tdd_config_s);
-  NBIoTLteCCParams[LTECCPARAMS_EUTRA_BAND_IDX ].uptr	         = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).eutra_band);             
-  NBIoTLteCCParams[LTECCPARAMS_DOWNLINK_FREQUENCY_IDX].uptr      = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).downlink_frequency);      
+          *(NBIoTRRCRefParams[NBIOT_RRCINST_IDX].uptr), *(NBIoTRRCRefParams[NBIOT_CCINST_IDX].uptr));
+  NBIoTLteCCParams[LTECCPARAMS_TDD_CONFIG_IDX  ].uptr          = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).tdd_config);
+  NBIoTLteCCParams[LTECCPARAMS_TDD_CONFIG_S_IDX].uptr          = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).tdd_config_s);
+  NBIoTLteCCParams[LTECCPARAMS_EUTRA_BAND_IDX ].uptr           = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).eutra_band);
+  NBIoTLteCCParams[LTECCPARAMS_DOWNLINK_FREQUENCY_IDX].uptr      = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).downlink_frequency);
   NBIoTLteCCParams[LTECCPARAMS_UPLINK_FREQUENCY_OFFSET_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).uplink_frequency_offset);
-  NBIoTLteCCParams[LTECCPARAMS_NID_CELL_IDX].uptr	         = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).Nid_cell);                 
-  NBIoTLteCCParams[LTECCPARAMS_N_RB_DL_IDX].uptr	         = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).N_RB_DL);                   
+  NBIoTLteCCParams[LTECCPARAMS_NID_CELL_IDX].uptr          = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).Nid_cell);
+  NBIoTLteCCParams[LTECCPARAMS_N_RB_DL_IDX].uptr           = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).N_RB_DL);
 
   for (int i=0; (i<sizeof(NBIoTLteCCParams)/sizeof(paramdef_t)) && (i<sizeof(NBIoTLteCCCheckParams)/sizeof(checkedparam_t)); i++ ) {
-     NBIoTLteCCParams[i].chkPptr = &(NBIoTLteCCCheckParams[i]);
+    NBIoTLteCCParams[i].chkPptr = &(NBIoTLteCCCheckParams[i]);
   }
-  config_get( NBIoTLteCCParams,sizeof(NBIoTLteCCParams)/sizeof(paramdef_t),instprefix); 
-  NBIOTRRC_CONFIGURATION_REQ (msg_p).frame_type = config_get_processedint( &(NBIoTLteCCParams[LTECCPARAMS_FRAME_TYPE_IDX]) ); 
+
+  config_get( NBIoTLteCCParams,sizeof(NBIoTLteCCParams)/sizeof(paramdef_t),instprefix);
+  NBIOTRRC_CONFIGURATION_REQ (msg_p).frame_type = config_get_processedint( &(NBIoTLteCCParams[LTECCPARAMS_FRAME_TYPE_IDX]) );
   NBIOTRRC_CONFIGURATION_REQ (msg_p).prefix_type = config_get_processedint( &(NBIoTLteCCParams[LTECCPARAMS_PREFIX_TYPE_IDX]) );
   NBIOTRRC_CONFIGURATION_REQ (msg_p).prefix_type = config_get_processedint( &(NBIoTLteCCParams[LTECCPARAMS_PREFIX_TYPE_UL_IDX]) );
-return 0;
+  return 0;
 }
 
 void RCConfig_NbIoT(RAN_CONTEXT_t *RC) {
-
   paramlist_def_t NbIoT_MACRLCParamList = {NBIOT_MACRLCLIST_CONFIG_STRING,NULL,0};
   paramlist_def_t NbIoT_L1ParamList = {NBIOT_L1LIST_CONFIG_STRING,NULL,0};
   paramlist_def_t NbIoT_ParamList = {NBIOT_RRCLIST_CONFIG_STRING,NULL,0};
-    
-  
   config_getlist( &NbIoT_ParamList,NULL,0,NULL);
   RC->nb_nb_iot_rrc_inst = NbIoT_ParamList.numelt;
-
-
-    
- 
-    config_getlist( &NbIoT_MACRLCParamList,NULL,0, NULL);
-    RC->nb_nb_iot_macrlc_inst  = NbIoT_MACRLCParamList.numelt;
-    // Get num L1 instances
-    config_getlist( &NbIoT_L1ParamList,NULL,0, NULL);
-    RC->nb_nb_iot_L1_inst = NbIoT_L1ParamList.numelt;
-
+  config_getlist( &NbIoT_MACRLCParamList,NULL,0, NULL);
+  RC->nb_nb_iot_macrlc_inst  = NbIoT_MACRLCParamList.numelt;
+  // Get num L1 instances
+  config_getlist( &NbIoT_L1ParamList,NULL,0, NULL);
+  RC->nb_nb_iot_L1_inst = NbIoT_L1ParamList.numelt;
 }
diff --git a/openair2/ENB_APP/RRC_config_tools.c b/openair2/ENB_APP/RRC_config_tools.c
index c7c75c13d4314c2969ce8d11e6fe5da28fe0cd8e..e778439d3d2420c887bd6605891bb62c06ff78aa 100644
--- a/openair2/ENB_APP/RRC_config_tools.c
+++ b/openair2/ENB_APP/RRC_config_tools.c
@@ -40,11 +40,11 @@
 #   include "sctp_eNB_task.h"
 # endif
 #endif
-#include "SystemInformationBlockType2.h"
+#include "LTE_SystemInformationBlockType2.h"
 #include "common/config/config_userapi.h"
 #include "RRC_config_tools.h"
-#include "DL-GapConfig-NB-r13.h"
-#include "NPRACH-Parameters-NB-r13.h"
+#include "LTE_DL-GapConfig-NB-r13.h"
+#include "LTE_NPRACH-Parameters-NB-r13.h"
 
 static const eutra_band_t eutra_bands[] = {
   { 1, 1920    * MHz, 1980    * MHz, 2110    * MHz, 2170    * MHz, FDD},
diff --git a/openair2/ENB_APP/RRC_paramsvalues.h b/openair2/ENB_APP/RRC_paramsvalues.h
index 06fee0e172515ed105adb6dc54fa5d808af07491..ea559ff74b8bf9d4bc11447c615d94d07dce1e37 100644
--- a/openair2/ENB_APP/RRC_paramsvalues.h
+++ b/openair2/ENB_APP/RRC_paramsvalues.h
@@ -35,6 +35,8 @@
 #define ENB_CONFIG_STRING_ENB_LIST                      "eNBs"
 /* component carriers configuration section name */		
 #define ENB_CONFIG_STRING_COMPONENT_CARRIERS                            "component_carriers"		 
+#define ENB_CONFIG_STRING_COMPONENT_BR_PARAMETERS                       "br_parameters"
+
 
 #define ENB_CONFIG_STRING_FRAME_TYPE                                    "frame_type"
 #define ENB_CONFIG_STRING_PBCH_REPETITION                               "pbch_repetition"
@@ -68,27 +70,27 @@
 #define NRBDL_OKVALUES                                          {6,15,25,50,75,100}
 
 #define UETIMER_T300_OKVALUES                                   {100,200,300,400,600,1000,1500,2000}
-#define UETT300(A)                                              UE_TimersAndConstants__t300_ ## A
+#define UETT300(A)                                              LTE_UE_TimersAndConstants__t300_ ## A
 #define UETIMER_T300_MODVALUES                                  { UETT300(ms100), UETT300(ms200),UETT300(ms300),UETT300(ms400),UETT300(ms600),UETT300(ms1000),UETT300(ms1500),UETT300(ms2000)}           		
 
 #define UETIMER_T301_OKVALUES                                   {100,200,300,400,600,1000,1500,2000}
-#define UETT301(A)                                              UE_TimersAndConstants__t301_ ## A
+#define UETT301(A)                                              LTE_UE_TimersAndConstants__t301_ ## A
 #define UETIMER_T301_MODVALUES                                  { UETT301(ms100), UETT301(ms200),UETT301(ms300),UETT301(ms400),UETT301(ms600),UETT301(ms1000),UETT301(ms1500),UETT301(ms2000)}
 
 #define UETIMER_T310_OKVALUES                                   {0,50,100,200,500,1000,2000}
-#define UETT310(A)                                              UE_TimersAndConstants__t310_ ## A
+#define UETT310(A)                                              LTE_UE_TimersAndConstants__t310_ ## A
 #define UETIMER_T310_MODVALUES                                  { UETT310(ms0), UETT310(ms50),UETT310(ms100),UETT310(ms200),UETT310(ms500),UETT310(ms1000),UETT310(ms2000)}
 
 #define UETIMER_T311_OKVALUES                                   {1000,3110,5000,10000,15000,20000,31100}
-#define UETT311(A)                                              UE_TimersAndConstants__t311_ ## A
+#define UETT311(A)                                              LTE_UE_TimersAndConstants__t311_ ## A
 #define UETIMER_T311_MODVALUES                                  { UETT311(ms1000), UETT311(ms3000),UETT311(ms5000),UETT311(ms10000),UETT311(ms15000),UETT311(ms20000),UETT311(ms30000)}
 
 #define UETIMER_N310_OKVALUES                                   {1,2,3,4,6,8,10,20}
-#define UETN310(A)                                              UE_TimersAndConstants__n310_ ## A
+#define UETN310(A)                                              LTE_UE_TimersAndConstants__n310_ ## A
 #define UETIMER_N310_MODVALUES                                  { UETN310(n1), UETN310(n2),UETN310(n3),UETN310(n4),UETN310(n6),UETN310(n8),UETN310(n10),UETN310(n20)}
 
 #define UETIMER_N311_OKVALUES                                   {1,2,3,4,5,6,8,10}
-#define UETN311(A)                                              UE_TimersAndConstants__n311_ ## A
+#define UETN311(A)                                              LTE_UE_TimersAndConstants__n311_ ## A
 #define UETIMER_N311_MODVALUES                                  { UETN311(n1), UETN311(n2),UETN311(n3),UETN311(n4),UETN311(n5),UETN311(n6),UETN311(n8),UETN311(n10)}
 
 #endif
diff --git a/openair2/ENB_APP/enb_app.c b/openair2/ENB_APP/enb_app.c
index 22c0d3418c960dfb617987eaef781784f41b6f4e..3ef96d63b19968b977548467cddd1b77591dcc98 100644
--- a/openair2/ENB_APP/enb_app.c
+++ b/openair2/ENB_APP/enb_app.c
@@ -44,14 +44,15 @@
 #   include "s1ap_eNB.h"
 #   include "sctp_eNB_task.h"
 #   include "gtpv1u_eNB_task.h"
-# else
-#    define EPC_MODE_ENABLED 0
-# endif
-
-#if defined(FLEXRAN_AGENT_SB_IF)
 #   include "flexran_agent.h"
-#endif
-
+/* temporary warning removale while implementing noS1 */
+/* as config option                                   */
+#   else
+#     ifdef EPC_MODE_ENABLED
+#       undef  EPC_MODE_ENABLED
+#     endif
+#     define EPC_MODE_ENABLED 0
+#   endif
 #   include "x2ap_eNB.h"
 #   include "x2ap_messages_types.h"
 #   define X2AP_ENB_REGISTER_RETRY_DELAY   10
@@ -147,7 +148,6 @@ void *eNB_app_task(void *args_p)
   uint32_t                        x2_register_enb_pending;
   uint32_t                        x2_registered_enb;
   long                            x2_enb_register_retry_timer_id;
-  uint32_t                        enb_id;
   MessageDef                     *msg_p           = NULL;
   instance_t                      instance;
   int                             result;
diff --git a/openair2/ENB_APP/enb_config.c b/openair2/ENB_APP/enb_config.c
index f39bf330bf082c281f56225dada84f4022da2fe4..df1c065ba8ea93196873aae277d73a0a2bc4e0dd 100644
--- a/openair2/ENB_APP/enb_config.c
+++ b/openair2/ENB_APP/enb_config.c
@@ -36,17 +36,17 @@
 #include "UTIL/OTG/otg.h"
 #include "UTIL/OTG/otg_externs.h"
 #if defined(ENABLE_ITTI)
-#include "intertask_interface.h"
-#if defined(ENABLE_USE_MME)
-#include "s1ap_eNB.h"
-#include "sctp_eNB_task.h"
-#else
-#define EPC_MODE_ENABLED 0
-#endif
+  #include "intertask_interface.h"
+  #if defined(ENABLE_USE_MME)
+    #include "s1ap_eNB.h"
+    #include "sctp_eNB_task.h"
+  #else
+    #define EPC_MODE_ENABLED 0
+  #endif
 #endif
 #include "common/ran_context.h"
 #include "sctp_default_values.h"
-#include "SystemInformationBlockType2.h"
+#include "LTE_SystemInformationBlockType2.h"
 #include "LAYER2/MAC/mac_extern.h"
 #include "LAYER2/MAC/mac_proto.h"
 #include "PHY/phy_extern.h"
@@ -61,8 +61,7 @@
 #include "RRC_config_tools.h"
 #include "enb_paramdef.h"
 
-#include "SystemInformationBlockType1.h"
-#include "SIB-Type.h"
+#define RRC_INACTIVITY_THRESH 0
 
 extern uint16_t sf_ahead;
 extern void set_parallel_conf(char *parallel_conf);
@@ -71,9 +70,10 @@ extern PARALLEL_CONF_t get_thread_parallel_conf(void);
 extern WORKER_CONF_t   get_thread_worker_conf(void);
 extern uint32_t to_earfcn_DL(int eutra_bandP, uint32_t dl_CarrierFreq, uint32_t bw);
 extern uint32_t to_earfcn_UL(int eutra_bandP, uint32_t ul_CarrierFreq, uint32_t bw);
+extern char *parallel_config;
+extern char *worker_config;
 
-void RCconfig_flexran()
-{
+void RCconfig_flexran() {
   /* get number of eNBs */
   paramdef_t ENBSParams[] = ENBSPARAMS_DESC;
   config_get(ENBSParams, sizeof(ENBSParams)/sizeof(paramdef_t), NULL);
@@ -175,7 +175,7 @@ void RCconfig_L1(void) {
       }
     }// j=0..num_inst
 
-    printf("Initializing northbound interface for L1\n");
+    LOG_I(ENB_APP,"Initializing northbound interface for L1\n");
     l1_north_init_eNB();
   } else {
     LOG_I(PHY,"No " CONFIG_STRING_L1_LIST " configuration found");
@@ -216,8 +216,6 @@ void RCconfig_macrlc(int macrlc_has_f1[MAX_MAC_INST]) {
     mac_top_init_eNB();   
     RC.nb_mac_CC = (int*)malloc(RC.nb_macrlc_inst*sizeof(int));
 
-    printf("Configuring %d MACRLC entities\n",RC.nb_macrlc_inst);
-
     for (j = 0; j < RC.nb_macrlc_inst; j++) {
       RC.mac[j]->puSch10xSnr = *(MacRLC_ParamList.paramarray[j][MACRLC_PUSCH10xSNR_IDX ].iptr);
       RC.mac[j]->puCch10xSnr = *(MacRLC_ParamList.paramarray[j][MACRLC_PUCCH10xSNR_IDX ].iptr);
@@ -254,16 +252,16 @@ void RCconfig_macrlc(int macrlc_has_f1[MAX_MAC_INST]) {
         RC.mac[j]->eth_params_s.remote_portd             = *(MacRLC_ParamList.paramarray[j][MACRLC_REMOTE_S_PORTD_IDX].iptr);
         RC.mac[j]->eth_params_s.transp_preference        = ETH_UDP_MODE;
         sf_ahead = 2; // Cannot cope with 4 subframes betweem RX and TX - set it to 2
-        printf("**************** vnf_port:%d\n", RC.mac[j]->eth_params_s.my_portc);
+        LOG_I(ENB_APP,"**************** vnf_port:%d\n", RC.mac[j]->eth_params_s.my_portc);
         configure_nfapi_vnf(RC.mac[j]->eth_params_s.my_addr, RC.mac[j]->eth_params_s.my_portc);
-        printf("**************** RETURNED FROM configure_nfapi_vnf() vnf_port:%d\n", RC.mac[j]->eth_params_s.my_portc);
+        LOG_I(ENB_APP,"**************** RETURNED FROM configure_nfapi_vnf() vnf_port:%d\n", RC.mac[j]->eth_params_s.my_portc);
       } else { // other midhaul
         AssertFatal(1==0,"MACRLC %d: %s unknown southbound midhaul\n",j,*(MacRLC_ParamList.paramarray[j][MACRLC_TRANSPORT_S_PREFERENCE_IDX].strptr));
       }
 
       if (strcmp(*(MacRLC_ParamList.paramarray[j][MACRLC_SCHED_MODE_IDX].strptr), "default") == 0) {
         global_scheduler_mode=SCHED_MODE_DEFAULT;
-        printf("sched mode = default %d [%s]\n",global_scheduler_mode,*(MacRLC_ParamList.paramarray[j][MACRLC_SCHED_MODE_IDX].strptr));
+        LOG_I(ENB_APP,"sched mode = default %d [%s]\n",global_scheduler_mode,*(MacRLC_ParamList.paramarray[j][MACRLC_SCHED_MODE_IDX].strptr));
       } else if (strcmp(*(MacRLC_ParamList.paramarray[j][MACRLC_SCHED_MODE_IDX].strptr), "fairRR") == 0) {
         global_scheduler_mode=SCHED_MODE_FAIR_RR;
         printf("sched mode = fairRR %d [%s]\n",global_scheduler_mode,*(MacRLC_ParamList.paramarray[j][MACRLC_SCHED_MODE_IDX].strptr));
@@ -281,149 +279,47 @@ void RCconfig_macrlc(int macrlc_has_f1[MAX_MAC_INST]) {
 int RCconfig_RRC(uint32_t i, eNB_RRC_INST *rrc, int macrlc_has_f1) {
   int               num_enbs                      = 0;
   int               j,k                           = 0;
-  int32_t     enb_id                        = 0;
+  int32_t           enb_id                        = 0;
   int               nb_cc                         = 0;
-  char       *frame_type                    = NULL;
-  int32_t     tdd_config                    = 0;
-  int32_t     tdd_config_s                  = 0;
-  char       *prefix_type                   = NULL;
-  char       *pbch_repetition               = NULL;
-  int32_t     eutra_band                    = 0;
-  long long int     downlink_frequency            = 0;
-  int32_t     uplink_frequency_offset       = 0;
-  int32_t     Nid_cell                      = 0;
-  int32_t     Nid_cell_mbsfn                = 0;
-  int32_t     N_RB_DL                       = 0;
-  int32_t     nb_antenna_ports              = 0;
-  int32_t     prach_root                    = 0;
-  int32_t     prach_config_index            = 0;
-  char            *prach_high_speed         = NULL;
-  int32_t     prach_zero_correlation        = 0;
-  int32_t     prach_freq_offset             = 0;
-  int32_t     pucch_delta_shift             = 0;
-  int32_t     pucch_nRB_CQI                 = 0;
-  int32_t     pucch_nCS_AN                  = 0;
-  //#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-  int32_t     pucch_n1_AN                   = 0;
-  //#endif
-  int32_t     pdsch_referenceSignalPower    = 0;
-  int32_t     pdsch_p_b                     = 0;
-  int32_t     pusch_n_SB                    = 0;
-  char       *pusch_hoppingMode             = NULL;
-  int32_t     pusch_hoppingOffset           = 0;
-  char          *pusch_enable64QAM          = NULL;
-  char          *pusch_groupHoppingEnabled  = NULL;
-  int32_t     pusch_groupAssignment         = 0;
-  char          *pusch_sequenceHoppingEnabled = NULL;
-  int32_t     pusch_nDMRS1                  = 0;
-  char       *phich_duration                = NULL;
-  char       *phich_resource                = NULL;
-  char       *srs_enable                    = NULL;
-  int32_t     srs_BandwidthConfig           = 0;
-  int32_t     srs_SubframeConfig            = 0;
-  char       *srs_ackNackST                 = NULL;
-  char       *srs_MaxUpPts                  = NULL;
-  int32_t     pusch_p0_Nominal              = 0;
-  char       *pusch_alpha                   = NULL;
-  int32_t     pucch_p0_Nominal              = 0;
-  int32_t     msg3_delta_Preamble           = 0;
-  //int32_t     ul_CyclicPrefixLength         = 0;
-  char       *pucch_deltaF_Format1          = NULL;
-  //const char*       pucch_deltaF_Format1a         = NULL;
-  char       *pucch_deltaF_Format1b         = NULL;
-  char       *pucch_deltaF_Format2          = NULL;
-  char       *pucch_deltaF_Format2a         = NULL;
-  char       *pucch_deltaF_Format2b         = NULL;
-  int32_t     rach_numberOfRA_Preambles     = 0;
-  char       *rach_preamblesGroupAConfig    = NULL;
-  int32_t     rach_sizeOfRA_PreamblesGroupA = 0;
-  int32_t     rach_messageSizeGroupA        = 0;
-  char       *rach_messagePowerOffsetGroupB = NULL;
-  int32_t     rach_powerRampingStep         = 0;
-  int32_t     rach_preambleInitialReceivedTargetPower    = 0;
-  int32_t     rach_preambleTransMax         = 0;
-  int32_t     rach_raResponseWindowSize     = 10;
-  int32_t     rach_macContentionResolutionTimer = 0;
-  int32_t     rach_maxHARQ_Msg3Tx           = 0;
-  int32_t     pcch_defaultPagingCycle       = 0;
-  char       *pcch_nB                       = NULL;
-  int32_t     bcch_modificationPeriodCoeff  = 0;
-  int32_t     ue_TimersAndConstants_t300    = 0;
-  int32_t     ue_TimersAndConstants_t301    = 0;
-  int32_t     ue_TimersAndConstants_t310    = 0;
-  int32_t     ue_TimersAndConstants_t311    = 0;
-  int32_t     ue_TimersAndConstants_n310    = 0;
-  int32_t     ue_TimersAndConstants_n311    = 0;
-  int32_t     ue_TransmissionMode           = 0;
-  int32_t     ue_multiple_max               = 0;
-  //TTN - for D2D
-  //SIB18
-  const char       *rxPool_sc_CP_Len                                        = NULL;
-  const char       *rxPool_sc_Period                                        = NULL;
-  const char       *rxPool_data_CP_Len                                      = NULL;
-  libconfig_int     rxPool_ResourceConfig_prb_Num                           = 0;
-  libconfig_int     rxPool_ResourceConfig_prb_Start                         = 0;
-  libconfig_int     rxPool_ResourceConfig_prb_End                           = 0;
-  const char       *rxPool_ResourceConfig_offsetIndicator_present           = NULL;
-  libconfig_int     rxPool_ResourceConfig_offsetIndicator_choice            = 0;
-  const char       *rxPool_ResourceConfig_subframeBitmap_present            = NULL;
-  char             *rxPool_ResourceConfig_subframeBitmap_choice_bs_buf      = NULL;
-  libconfig_int     rxPool_ResourceConfig_subframeBitmap_choice_bs_size     = 0;
-  libconfig_int     rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused     = 0;
-  //SIB19
-  //For discRxPool
-  const char       *discRxPool_cp_Len                                              = NULL;
-  const char       *discRxPool_discPeriod                                          = NULL;
-  libconfig_int     discRxPool_numRetx                                             = 0;
-  libconfig_int     discRxPool_numRepetition                                       = 0;
-  libconfig_int     discRxPool_ResourceConfig_prb_Num                              = 0;
-  libconfig_int     discRxPool_ResourceConfig_prb_Start                            = 0;
-  libconfig_int     discRxPool_ResourceConfig_prb_End                              = 0;
-  const char       *discRxPool_ResourceConfig_offsetIndicator_present              = NULL;
-  libconfig_int     discRxPool_ResourceConfig_offsetIndicator_choice               = 0;
-  const char       *discRxPool_ResourceConfig_subframeBitmap_present               = NULL;
-  char             *discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf         = NULL;
-  libconfig_int     discRxPool_ResourceConfig_subframeBitmap_choice_bs_size        = 0;
-  libconfig_int     discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused = 0;
-  //For discRxPoolPS
-  const char       *discRxPoolPS_cp_Len                                              = NULL;
-  const char       *discRxPoolPS_discPeriod                                          = NULL;
-  libconfig_int     discRxPoolPS_numRetx                                             = 0;
-  libconfig_int     discRxPoolPS_numRepetition                                       = 0;
-  libconfig_int     discRxPoolPS_ResourceConfig_prb_Num                              = 0;
-  libconfig_int     discRxPoolPS_ResourceConfig_prb_Start                            = 0;
-  libconfig_int     discRxPoolPS_ResourceConfig_prb_End                              = 0;
-  const char       *discRxPoolPS_ResourceConfig_offsetIndicator_present              = NULL;
-  libconfig_int     discRxPoolPS_ResourceConfig_offsetIndicator_choice               = 0;
-  const char       *discRxPoolPS_ResourceConfig_subframeBitmap_present               = NULL;
-  char             *discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_buf         = NULL;
-  libconfig_int     discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_size        = 0;
-  libconfig_int     discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_bits_unused = 0;
-  int32_t     srb1_timer_poll_retransmit    = 0;
-  int32_t     srb1_timer_reordering         = 0;
-  int32_t     srb1_timer_status_prohibit    = 0;
-  int32_t     srb1_poll_pdu                 = 0;
-  int32_t     srb1_poll_byte                = 0;
-  int32_t     srb1_max_retx_threshold       = 0;
-  int32_t     my_int;
-
   MessageDef *msg_p = itti_alloc_new_message(TASK_RRC_ENB, RRC_CONFIGURATION_REQ);
-  
-  // for no gcc warnings
-  (void)my_int;
+
+  ccparams_lte_t ccparams_lte;
+  ccparams_sidelink_t SLconfig;
+  ccparams_eMTC_t eMTCconfig;
+
+  memset((void*)&ccparams_lte,0,sizeof(ccparams_lte_t));
+  memset((void*)&SLconfig,0,sizeof(ccparams_sidelink_t));
+  memset((void*)&eMTCconfig,0,sizeof(ccparams_eMTC_t));
+
+
   paramdef_t ENBSParams[] = ENBSPARAMS_DESC;
   paramdef_t ENBParams[]  = ENBPARAMS_DESC;
   paramlist_def_t ENBParamList = {ENB_CONFIG_STRING_ENB_LIST,NULL,0};
   checkedparam_t config_check_CCparams[] = CCPARAMS_CHECK;
-  paramdef_t CCsParams[] = CCPARAMS_DESC;
+  paramdef_t CCsParams[] = CCPARAMS_DESC(ccparams_lte);
   paramlist_def_t CCsParamList = {ENB_CONFIG_STRING_COMPONENT_CARRIERS,NULL,0};
-  paramdef_t SRB1Params[] = SRB1PARAMS_DESC;
+
+  paramdef_t eMTCParams[]              = EMTCPARAMS_DESC((&eMTCconfig));
+  checkedparam_t config_check_eMTCparams[] = EMTCPARAMS_CHECK;
+
+  srb1_params_t srb1_params;
+  memset((void*)&srb1_params,0,sizeof(srb1_params_t));
+  paramdef_t SRB1Params[] = SRB1PARAMS_DESC(srb1_params);
+
+
+  paramdef_t SLParams[]              = CCPARAMS_SIDELINK_DESC(SLconfig);
+
 
   /* map parameter checking array instances to parameter definition array instances */
   for (int I=0; I< ( sizeof(CCsParams)/ sizeof(paramdef_t)  ) ; I++) {
     CCsParams[I].chkPptr = &(config_check_CCparams[I]);
   }
 
+
+  for (int I = 0; I < (sizeof(CCsParams) / sizeof(paramdef_t)); I++) {
+    eMTCParams[I].chkPptr = &(config_check_eMTCparams[I]);
+  }
+
   /* get global parameters, defined outside any section in the config file */
   config_get( ENBSParams,sizeof(ENBSParams)/sizeof(paramdef_t),NULL);
   num_enbs = ENBSParams[ENB_ACTIVE_ENBS_IDX].numelt;
@@ -447,7 +343,6 @@ int RCconfig_RRC(uint32_t i, eNB_RRC_INST *rrc, int macrlc_has_f1) {
       enb_id = *(ENBParamList.paramarray[i][ENB_ENB_ID_IDX].uptr);
     }
 
-      
       LOG_I(RRC,"Instance %d: Southbound Transport %s\n",i,*(ENBParamList.paramarray[i][ENB_TRANSPORT_S_PREFERENCE_IDX].strptr));
 	    
       if (strcmp(*(ENBParamList.paramarray[i][ENB_TRANSPORT_S_PREFERENCE_IDX].strptr), "f1") == 0) {
@@ -465,19 +360,12 @@ int RCconfig_RRC(uint32_t i, eNB_RRC_INST *rrc, int macrlc_has_f1) {
 	LOG_I(ENB_APP,"F1AP: gNB_CU_name[%d] %s\n",k,rrc->node_name);
 
 	rrc->eth_params_s.local_if_name            = strdup(*(ENBParamList.paramarray[i][ENB_LOCAL_S_IF_NAME_IDX].strptr));
-	LOG_I(RRC,"Configuring CU-DU interfaces for MACRLC on %s\n",rrc->eth_params_s.local_if_name);
 	rrc->eth_params_s.my_addr                  = strdup(*(ENBParamList.paramarray[i][ENB_LOCAL_S_ADDRESS_IDX].strptr));
-	LOG_I(RRC,"local address: %s\n",rrc->eth_params_s.my_addr);
 	rrc->eth_params_s.remote_addr              = strdup(*(ENBParamList.paramarray[i][ENB_REMOTE_S_ADDRESS_IDX].strptr));
-	LOG_I(RRC,"remote address: %s\n",rrc->eth_params_s.remote_addr);
 	rrc->eth_params_s.my_portc                 = *(ENBParamList.paramarray[i][ENB_LOCAL_S_PORTC_IDX].uptr);
-	LOG_I(RRC,"local port (F1AP) %d\n",rrc->eth_params_s.my_portc);
 	rrc->eth_params_s.remote_portc             = *(ENBParamList.paramarray[i][ENB_REMOTE_S_PORTC_IDX].uptr);
-	LOG_I(RRC,"remote port (F1AP) %d\n",rrc->eth_params_s.remote_portc);
 	rrc->eth_params_s.my_portd                 = *(ENBParamList.paramarray[i][ENB_LOCAL_S_PORTD_IDX].uptr);
-	LOG_I(RRC,"local port (F1U) %d\n",rrc->eth_params_s.my_portd);
 	rrc->eth_params_s.remote_portd             = *(ENBParamList.paramarray[i][ENB_REMOTE_S_PORTD_IDX].uptr);
-	LOG_I(RRC,"remote port (F1U) %d\n",rrc->eth_params_s.remote_portd);
 	rrc->eth_params_s.transp_preference        = ETH_UDP_MODE;
 	rrc->node_type                             = ngran_eNB_CU;
 	rrc->sctp_in_streams                       = (uint16_t)*(SCTPParams[ENB_SCTP_INSTREAMS_IDX].uptr);
@@ -503,7 +391,7 @@ int RCconfig_RRC(uint32_t i, eNB_RRC_INST *rrc, int macrlc_has_f1) {
     // search if in active list
 
     for (k=0; k <num_enbs ; k++) {
-      if (strcmp(ENBSParams[ENB_ACTIVE_ENBS_IDX].strlistptr[k], *(ENBParamList.paramarray[i][ENB_ENB_NAME_IDX].strptr) )== 0) {
+      if (strcmp(ENBSParams[ENB_ACTIVE_ENBS_IDX].strlistptr[k], *(ENBParamList.paramarray[i][ENB_ENB_NAME_IDX].strptr)) == 0) {
         char enbpath[MAX_OPTNAME_SIZE + 8];
         sprintf(enbpath,"%s.[%i]",ENB_CONFIG_STRING_ENB_LIST,k);
         paramdef_t PLMNParams[] = PLMNPARAMS_DESC;
@@ -514,8 +402,9 @@ int RCconfig_RRC(uint32_t i, eNB_RRC_INST *rrc, int macrlc_has_f1) {
         for (int I = 0; I < sizeof(PLMNParams) / sizeof(paramdef_t); ++I)
           PLMNParams[I].chkPptr = &(config_check_PLMNParams[I]);
 
+        RRC_CONFIGURATION_REQ (msg_p).rrc_inactivity_timer_thres = RRC_INACTIVITY_THRESH; // set to 0 to deactivate
         RRC_CONFIGURATION_REQ (msg_p).cell_identity = enb_id;
-        RRC_CONFIGURATION_REQ(msg_p).tac = *ENBParamList.paramarray[i][ENB_TRACKING_AREA_CODE_IDX].uptr;
+        RRC_CONFIGURATION_REQ (msg_p).tac = *ENBParamList.paramarray[i][ENB_TRACKING_AREA_CODE_IDX].uptr;
         AssertFatal(!ENBParamList.paramarray[i][ENB_MOBILE_COUNTRY_CODE_IDX_OLD].strptr
                     && !ENBParamList.paramarray[i][ENB_MOBILE_NETWORK_CODE_IDX_OLD].strptr,
                     "It seems that you use an old configuration file. Please change the existing\n"
@@ -547,1445 +436,1254 @@ int RCconfig_RRC(uint32_t i, eNB_RRC_INST *rrc, int macrlc_has_f1) {
         config_getlist( &CCsParamList,NULL,0,enbpath);
         LOG_I(RRC,"num component carriers %d \n",CCsParamList.numelt);
 
-	  if ( CCsParamList.numelt> 0) {
-	    char ccspath[MAX_OPTNAME_SIZE*2 + 16];
-	    
-	    for (j = 0; j < CCsParamList.numelt ;j++) { 
+        if ( CCsParamList.numelt> 0) {
+          char ccspath[MAX_OPTNAME_SIZE*2 + 16];
+
+          for (j = 0; j < CCsParamList.numelt ; j++) {
+            sprintf(ccspath,"%s.%s.[%i]",enbpath,ENB_CONFIG_STRING_COMPONENT_CARRIERS,j);
+            LOG_I(RRC, "enb_config::RCconfig_RRC() parameter number: %d, total number of parameters: %zd, ccspath: %s \n \n", j, sizeof(CCsParams)/sizeof(paramdef_t), ccspath);
+            config_get( CCsParams,sizeof(CCsParams)/sizeof(paramdef_t),ccspath);
+            //printf("Component carrier %d\n",component_carrier);
+            nb_cc++;
+
+            if ( (rrc->node_type != ngran_eNB_CU) || (rrc->node_type != ngran_ng_eNB_CU) || (rrc->node_type != ngran_gNB_CU) ) {
+              RRC_CONFIGURATION_REQ (msg_p).tdd_config[j] = ccparams_lte.tdd_config;
+              AssertFatal (ccparams_lte.tdd_config <= LTE_TDD_Config__subframeAssignment_sa6,
+                           "Failed to parse eNB configuration file %s, enb %d illegal tdd_config %d (should be 0-%d)!",
+                           RC.config_file_name, i, ccparams_lte.tdd_config, LTE_TDD_Config__subframeAssignment_sa6);
+              RRC_CONFIGURATION_REQ (msg_p).tdd_config_s[j] = ccparams_lte.tdd_config_s;
+              AssertFatal (ccparams_lte.tdd_config_s <= LTE_TDD_Config__specialSubframePatterns_ssp8,
+                           "Failed to parse eNB configuration file %s, enb %d illegal tdd_config_s %d (should be 0-%d)!",
+                           RC.config_file_name, i, ccparams_lte.tdd_config_s, LTE_TDD_Config__specialSubframePatterns_ssp8);
+              if (!ccparams_lte.prefix_type)
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d define %s: NORMAL,EXTENDED!\n",
+                             RC.config_file_name, i, ENB_CONFIG_STRING_PREFIX_TYPE);
+              else if (strcmp(ccparams_lte.prefix_type, "NORMAL") == 0) {
+                RRC_CONFIGURATION_REQ (msg_p).prefix_type[j] = NORMAL;
+              } else  if (strcmp(ccparams_lte.prefix_type, "EXTENDED") == 0) {
+                RRC_CONFIGURATION_REQ (msg_p).prefix_type[j] = EXTENDED;
+              } else {
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for prefix_type choice: NORMAL or EXTENDED !\n",
+                             RC.config_file_name, i, ccparams_lte.prefix_type);
+              }
 
-	      sprintf(ccspath,"%s.%s.[%i]",enbpath,ENB_CONFIG_STRING_COMPONENT_CARRIERS,j);
-	      LOG_I(RRC, "enb_config::RCconfig_RRC() parameter number: %d, total number of parameters: %zd, ccspath: %s \n \n", j, sizeof(CCsParams)/sizeof(paramdef_t), ccspath);
-	      config_get( CCsParams,sizeof(CCsParams)/sizeof(paramdef_t),ccspath);	      
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+
+              if (!ccparams_lte.pbch_repetition)
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d define %s: TRUE,FALSE!\n",
+                             RC.config_file_name, i, ENB_CONFIG_STRING_PBCH_REPETITION);
+              else if (strcmp(ccparams_lte.pbch_repetition, "TRUE") == 0) {
+                RRC_CONFIGURATION_REQ (msg_p).pbch_repetition[j] = 1;
+              } else  if (strcmp(ccparams_lte.pbch_repetition, "FALSE") == 0) {
+                RRC_CONFIGURATION_REQ (msg_p).pbch_repetition[j] = 0;
+              } else {
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pbch_repetition choice: TRUE or FALSE !\n",
+                             RC.config_file_name, i, ccparams_lte.pbch_repetition);
+              }
 
+#endif
+              RRC_CONFIGURATION_REQ (msg_p).eutra_band[j] = ccparams_lte.eutra_band;
+              RRC_CONFIGURATION_REQ (msg_p).downlink_frequency[j] = (uint32_t) ccparams_lte.downlink_frequency;
+              RRC_CONFIGURATION_REQ (msg_p).uplink_frequency_offset[j] = (unsigned int) ccparams_lte.uplink_frequency_offset;
 
-	      //printf("Component carrier %d\n",component_carrier);	     
 
-		    
+              RRC_CONFIGURATION_REQ (msg_p).Nid_cell[j]= ccparams_lte.Nid_cell;
 
-	      nb_cc++;
+              if (ccparams_lte.Nid_cell>503) {
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for Nid_cell choice: 0...503 !\n",
+                             RC.config_file_name, i, ccparams_lte.Nid_cell);
+              }
 
-	      if ( (rrc->node_type != ngran_eNB_CU) || (rrc->node_type != ngran_ng_eNB_CU) || (rrc->node_type != ngran_gNB_CU) ) {
-		// Cell params, MIB/SIB1 in DU
-		RRC_CONFIGURATION_REQ (msg_p).tdd_config[j] = tdd_config;
-	      
-		AssertFatal (tdd_config <= TDD_Config__subframeAssignment_sa6,
-			     "Failed to parse eNB configuration file %s, enb %d illegal tdd_config %d (should be 0-%d)!",
-			     RC.config_file_name, i, tdd_config, TDD_Config__subframeAssignment_sa6);
-	      
-		RRC_CONFIGURATION_REQ (msg_p).tdd_config_s[j] = tdd_config_s;
-		AssertFatal (tdd_config_s <= TDD_Config__specialSubframePatterns_ssp8,
-			     "Failed to parse eNB configuration file %s, enb %d illegal tdd_config_s %d (should be 0-%d)!",
-			     RC.config_file_name, i, tdd_config_s, TDD_Config__specialSubframePatterns_ssp8);
-		
-		if (!prefix_type)
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d define %s: NORMAL,EXTENDED!\n",
-			       RC.config_file_name, i, ENB_CONFIG_STRING_PREFIX_TYPE);
-		else if (strcmp(prefix_type, "NORMAL") == 0) {
-		  RRC_CONFIGURATION_REQ (msg_p).prefix_type[j] = NORMAL;
-		} else  if (strcmp(prefix_type, "EXTENDED") == 0) {
-		  RRC_CONFIGURATION_REQ (msg_p).prefix_type[j] = EXTENDED;
-		} else {
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for prefix_type choice: NORMAL or EXTENDED !\n",
-			       RC.config_file_name, i, prefix_type);
-		}
+              RRC_CONFIGURATION_REQ (msg_p).N_RB_DL[j]= ccparams_lte.N_RB_DL;
+
+              if ((ccparams_lte.N_RB_DL!=6) &&
+                  (ccparams_lte.N_RB_DL!=15) &&
+                  (ccparams_lte.N_RB_DL!=25) &&
+                  (ccparams_lte.N_RB_DL!=50) &&
+                  (ccparams_lte.N_RB_DL!=75) &&
+                  (ccparams_lte.N_RB_DL!=100)) {
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for N_RB_DL choice: 6,15,25,50,75,100 !\n",
+                             RC.config_file_name, i, ccparams_lte.N_RB_DL);
+              }
 
-		RRC_CONFIGURATION_REQ (msg_p).eutra_band[j] = eutra_band;
-		RRC_CONFIGURATION_REQ (msg_p).downlink_frequency[j] = (uint32_t) downlink_frequency;
-		RRC_CONFIGURATION_REQ (msg_p).uplink_frequency_offset[j] = (unsigned int) uplink_frequency_offset;
+              if (strcmp(ccparams_lte.frame_type, "FDD") == 0) {
+                RRC_CONFIGURATION_REQ (msg_p).frame_type[j] = FDD;
+              } else  if (strcmp(ccparams_lte.frame_type, "TDD") == 0) {
+                RRC_CONFIGURATION_REQ (msg_p).frame_type[j] = TDD;
+              } else {
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for frame_type choice: FDD or TDD !\n",
+                             RC.config_file_name, i, ccparams_lte.frame_type);
+              }
 
-		if (config_check_band_frequencies(j,
-						  RRC_CONFIGURATION_REQ (msg_p).eutra_band[j],
-						  RRC_CONFIGURATION_REQ (msg_p).downlink_frequency[j],
-						  RRC_CONFIGURATION_REQ (msg_p).uplink_frequency_offset[j],
-						  RRC_CONFIGURATION_REQ (msg_p).frame_type[j])) {
-		  AssertFatal(0, "error calling enb_check_band_frequencies\n");
-		}
-	      
+              if (config_check_band_frequencies(j,
+                                                RRC_CONFIGURATION_REQ (msg_p).eutra_band[j],
+                                                RRC_CONFIGURATION_REQ (msg_p).downlink_frequency[j],
+                                                RRC_CONFIGURATION_REQ (msg_p).uplink_frequency_offset[j],
+                                                RRC_CONFIGURATION_REQ (msg_p).frame_type[j])) {
+                AssertFatal(0, "error calling enb_check_band_frequencies\n");
+              }
+
+
+              if ((ccparams_lte.nb_antenna_ports <1) || (ccparams_lte.nb_antenna_ports > 2))
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for nb_antenna_ports choice: 1..2 !\n",
+                             RC.config_file_name, i, ccparams_lte.nb_antenna_ports);
+
+              RRC_CONFIGURATION_REQ (msg_p).nb_antenna_ports[j] = ccparams_lte.nb_antenna_ports;
+            }
+
+            if (rrc->node_type != ngran_eNB_DU) {//this is CU or eNB, SIB2-20 in CU
+              // Radio Resource Configuration (SIB2)
+
+              RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].prach_root =  ccparams_lte.prach_root;
+
+              if ((ccparams_lte.prach_root <0) || (ccparams_lte.prach_root > 1023))
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for prach_root choice: 0..1023 !\n",
+                             RC.config_file_name, i, ccparams_lte.prach_root);
+
+              RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].prach_config_index = ccparams_lte.prach_config_index;
+
+              if ((ccparams_lte.prach_config_index <0) || (ccparams_lte.prach_config_index > 63))
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for prach_config_index choice: 0..1023 !\n",
+                             RC.config_file_name, i, ccparams_lte.prach_config_index);
+
+              if (!ccparams_lte.prach_high_speed)
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d define %s: ENABLE,DISABLE!\n",
+                             RC.config_file_name, i, ENB_CONFIG_STRING_PRACH_HIGH_SPEED);
+              else if (strcmp(ccparams_lte.prach_high_speed, "ENABLE") == 0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].prach_high_speed = TRUE;
+              } else if (strcmp(ccparams_lte.prach_high_speed, "DISABLE") == 0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].prach_high_speed = FALSE;
+              } else
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for prach_config choice: ENABLE,DISABLE !\n",
+                             RC.config_file_name, i, ccparams_lte.prach_high_speed);
+
+              RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].prach_zero_correlation = ccparams_lte.prach_zero_correlation;
+
+              if ((ccparams_lte.prach_zero_correlation <0) ||
+                  (ccparams_lte.prach_zero_correlation > 15))
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for prach_zero_correlation choice: 0..15!\n",
+                             RC.config_file_name, i, ccparams_lte.prach_zero_correlation);
+
+              RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].prach_freq_offset = ccparams_lte.prach_freq_offset;
+
+              if ((ccparams_lte.prach_freq_offset <0) ||
+                  (ccparams_lte.prach_freq_offset > 94))
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for prach_freq_offset choice: 0..94!\n",
+                             RC.config_file_name, i, ccparams_lte.prach_freq_offset);
+
+              RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pucch_delta_shift = ccparams_lte.pucch_delta_shift-1;
+
+              if ((ccparams_lte.pucch_delta_shift <1) ||
+                  (ccparams_lte.pucch_delta_shift > 3))
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pucch_delta_shift choice: 1..3!\n",
+                             RC.config_file_name, i, ccparams_lte.pucch_delta_shift);
+
+              RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pucch_nRB_CQI = ccparams_lte.pucch_nRB_CQI;
+
+              if ((ccparams_lte.pucch_nRB_CQI <0) ||
+                  (ccparams_lte.pucch_nRB_CQI > 98))
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pucch_nRB_CQI choice: 0..98!\n",
+                             RC.config_file_name, i, ccparams_lte.pucch_nRB_CQI);
+
+              RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pucch_nCS_AN = ccparams_lte.pucch_nCS_AN;
+
+              if ((ccparams_lte.pucch_nCS_AN <0) ||
+                  (ccparams_lte.pucch_nCS_AN > 7))
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pucch_nCS_AN choice: 0..7!\n",
+                             RC.config_file_name, i, ccparams_lte.pucch_nCS_AN);
+
+
+              //#if (LTE_RRC_VERSION < MAKE_VERSION(10, 0, 0))
+              RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pucch_n1_AN = ccparams_lte.pucch_n1_AN;
+
+              if ((ccparams_lte.pucch_n1_AN <0) ||
+                  (ccparams_lte.pucch_n1_AN > 2047))
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pucch_n1_AN choice: 0..2047!\n",
+                             RC.config_file_name, i, ccparams_lte.pucch_n1_AN);
+
+              //#endif
+              RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pdsch_referenceSignalPower = ccparams_lte.pdsch_referenceSignalPower;
+
+              if ((ccparams_lte.pdsch_referenceSignalPower <-60) ||
+                  (ccparams_lte.pdsch_referenceSignalPower > 50))
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pdsch_referenceSignalPower choice:-60..50!\n",
+                             RC.config_file_name, i, ccparams_lte.pdsch_referenceSignalPower);
+
+              RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pdsch_p_b = ccparams_lte.pdsch_p_b;
+
+              if ((ccparams_lte.pdsch_p_b <0) ||
+                  (ccparams_lte.pdsch_p_b > 3))
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pdsch_p_b choice: 0..3!\n",
+                             RC.config_file_name, i, ccparams_lte.pdsch_p_b);
+
+              RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pusch_n_SB = ccparams_lte.pusch_n_SB;
+
+              if ((ccparams_lte.pusch_n_SB <1) ||
+                  (ccparams_lte.pusch_n_SB > 4))
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pusch_n_SB choice: 1..4!\n",
+                             RC.config_file_name, i, ccparams_lte.pusch_n_SB);
+
+              if (!ccparams_lte.pusch_hoppingMode)
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d define %s: interSubframe,intraAndInterSubframe!\n",
+                             RC.config_file_name, i, ENB_CONFIG_STRING_PUSCH_HOPPINGMODE);
+
+              else if (strcmp(ccparams_lte.pusch_hoppingMode,"interSubFrame")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pusch_hoppingMode = LTE_PUSCH_ConfigCommon__pusch_ConfigBasic__hoppingMode_interSubFrame;
+              }
+              else if (strcmp(ccparams_lte.pusch_hoppingMode,"intraAndInterSubFrame")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pusch_hoppingMode = LTE_PUSCH_ConfigCommon__pusch_ConfigBasic__hoppingMode_intraAndInterSubFrame;
+              } else
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pusch_hoppingMode choice: interSubframe,intraAndInterSubframe!\n",
+                             RC.config_file_name, i, ccparams_lte.pusch_hoppingMode);
+
+              RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pusch_hoppingOffset = ccparams_lte.pusch_hoppingOffset;
+
+              if ((ccparams_lte.pusch_hoppingOffset<0) ||
+                  (ccparams_lte.pusch_hoppingOffset>98))
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pusch_hoppingOffset choice: 0..98!\n",
+                             RC.config_file_name, i, ccparams_lte.pusch_hoppingMode);
+
+              if (!ccparams_lte.pusch_enable64QAM)
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d define %s: ENABLE,DISABLE!\n",
+                             RC.config_file_name, i, ENB_CONFIG_STRING_PUSCH_ENABLE64QAM);
+              else if (strcmp(ccparams_lte.pusch_enable64QAM, "ENABLE") == 0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pusch_enable64QAM = TRUE;
+              }
+              else if (strcmp(ccparams_lte.pusch_enable64QAM, "DISABLE") == 0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pusch_enable64QAM = FALSE;
+              }
+              else
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pusch_enable64QAM choice: ENABLE,DISABLE!\n",
+                             RC.config_file_name, i, ccparams_lte.pusch_enable64QAM);
+
+              if (!ccparams_lte.pusch_groupHoppingEnabled)
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d define %s: ENABLE,DISABLE!\n",
+                             RC.config_file_name, i, ENB_CONFIG_STRING_PUSCH_GROUP_HOPPING_EN);
+              else if (strcmp(ccparams_lte.pusch_groupHoppingEnabled, "ENABLE") == 0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pusch_groupHoppingEnabled = TRUE;
+              }
+              else if (strcmp(ccparams_lte.pusch_groupHoppingEnabled, "DISABLE") == 0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pusch_groupHoppingEnabled= FALSE;
+              }
+              else
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pusch_groupHoppingEnabled choice: ENABLE,DISABLE!\n",
+                             RC.config_file_name, i, ccparams_lte.pusch_groupHoppingEnabled);
+
+              RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pusch_groupAssignment = ccparams_lte.pusch_groupAssignment;
+
+              if ((ccparams_lte.pusch_groupAssignment<0)||
+                  (ccparams_lte.pusch_groupAssignment>29))
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pusch_groupAssignment choice: 0..29!\n",
+                             RC.config_file_name, i, ccparams_lte.pusch_groupAssignment);
+
+              if (!ccparams_lte.pusch_sequenceHoppingEnabled)
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d define %s: ENABLE,DISABLE!\n",
+                             RC.config_file_name, i, ENB_CONFIG_STRING_PUSCH_SEQUENCE_HOPPING_EN);
+              else if (strcmp(ccparams_lte.pusch_sequenceHoppingEnabled, "ENABLE") == 0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pusch_sequenceHoppingEnabled = TRUE;
+              }
+              else if (strcmp(ccparams_lte.pusch_sequenceHoppingEnabled, "DISABLE") == 0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pusch_sequenceHoppingEnabled = FALSE;
+              } else
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pusch_sequenceHoppingEnabled choice: ENABLE,DISABLE!\n",
+                             RC.config_file_name, i, ccparams_lte.pusch_sequenceHoppingEnabled);
+
+              RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pusch_nDMRS1= ccparams_lte.pusch_nDMRS1;  //cyclic_shift in RRC!
+
+              if ((ccparams_lte.pusch_nDMRS1 <0) ||
+                  (ccparams_lte.pusch_nDMRS1>7))
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pusch_nDMRS1 choice: 0..7!\n",
+                             RC.config_file_name, i, ccparams_lte.pusch_nDMRS1);
+
+
+              if (strcmp(ccparams_lte.phich_duration,"NORMAL")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].phich_duration= LTE_PHICH_Config__phich_Duration_normal;
+              } else if (strcmp(ccparams_lte.phich_duration,"EXTENDED")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].phich_duration= LTE_PHICH_Config__phich_Duration_extended;
+              } else
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for phich_duration choice: NORMAL,EXTENDED!\n",
+                             RC.config_file_name, i, ccparams_lte.phich_duration);
+
+              if (strcmp(ccparams_lte.phich_resource,"ONESIXTH")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].phich_resource= LTE_PHICH_Config__phich_Resource_oneSixth ;
+              }
+              else if (strcmp(ccparams_lte.phich_resource,"HALF")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].phich_resource= LTE_PHICH_Config__phich_Resource_half;
+              }
+              else if (strcmp(ccparams_lte.phich_resource,"ONE")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].phich_resource= LTE_PHICH_Config__phich_Resource_one;
+              }
+              else if (strcmp(ccparams_lte.phich_resource,"TWO")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].phich_resource= LTE_PHICH_Config__phich_Resource_two;
+              }
+              else
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for phich_resource choice: ONESIXTH,HALF,ONE,TWO!\n",
+                             RC.config_file_name, i, ccparams_lte.phich_resource);
+
+              printf("phich.resource %ld (%s), phich.duration %ld (%s)\n",
+                     RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].phich_resource,ccparams_lte.phich_resource,
+                     RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].phich_duration,ccparams_lte.phich_duration);
+
+              if (strcmp(ccparams_lte.srs_enable, "ENABLE") == 0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].srs_enable= TRUE;
+              }
+              else if (strcmp(ccparams_lte.srs_enable, "DISABLE") == 0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].srs_enable= FALSE;
+              }
+              else
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for srs_BandwidthConfig choice: ENABLE,DISABLE !\n",
+                             RC.config_file_name, i, ccparams_lte.srs_enable);
+
+              if (RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].srs_enable== TRUE) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].srs_BandwidthConfig= ccparams_lte.srs_BandwidthConfig;
+
+                if ((ccparams_lte.srs_BandwidthConfig < 0) ||
+                    (ccparams_lte.srs_BandwidthConfig >7))
+                  AssertFatal (0, "Failed to parse eNB configuration file %s, enb %d unknown value %d for srs_BandwidthConfig choice: 0...7\n",
+                               RC.config_file_name, i, ccparams_lte.srs_BandwidthConfig);
+
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].srs_SubframeConfig= ccparams_lte.srs_SubframeConfig;
+
+                if ((ccparams_lte.srs_SubframeConfig<0) ||
+                    (ccparams_lte.srs_SubframeConfig>15))
+                  AssertFatal (0,
+                               "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for srs_SubframeConfig choice: 0..15 !\n",
+                               RC.config_file_name, i, ccparams_lte.srs_SubframeConfig);
+
+                if (strcmp(ccparams_lte.srs_ackNackST, "ENABLE") == 0) {
+                  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].srs_ackNackST= TRUE;
+                }
+                else if (strcmp(ccparams_lte.srs_ackNackST, "DISABLE") == 0) {
+                  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].srs_ackNackST= FALSE;
+                } else
+                  AssertFatal (0,
+                               "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for srs_BandwidthConfig choice: ENABLE,DISABLE !\n",
+                               RC.config_file_name, i, ccparams_lte.srs_ackNackST);
+
+                if (strcmp(ccparams_lte.srs_MaxUpPts, "ENABLE") == 0) {
+                  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].srs_MaxUpPts= TRUE;
+                }
+                else if (strcmp(ccparams_lte.srs_MaxUpPts, "DISABLE") == 0) {
+                  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].srs_MaxUpPts= FALSE;
+                }
+                else
+                  AssertFatal (0,
+                               "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for srs_MaxUpPts choice: ENABLE,DISABLE !\n",
+                               RC.config_file_name, i, ccparams_lte.srs_MaxUpPts);
+              }
+
+              RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pusch_p0_Nominal= ccparams_lte.pusch_p0_Nominal;
+
+              if ((ccparams_lte.pusch_p0_Nominal<-126) ||
+                  (ccparams_lte.pusch_p0_Nominal>24))
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pusch_p0_Nominal choice: -126..24 !\n",
+                             RC.config_file_name, i, ccparams_lte.pusch_p0_Nominal);
+
+#if (LTE_RRC_VERSION <= MAKE_VERSION(12, 0, 0))
+
+              if (strcmp(ccparams_lte.pusch_alpha,"AL0")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pusch_alpha= LTE_UplinkPowerControlCommon__alpha_al0;
+              }
+              else if (strcmp(ccparams_lte.pusch_alpha,"AL04")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pusch_alpha= LTE_UplinkPowerControlCommon__alpha_al04;
+              }
+              else if (strcmp(ccparams_lte.pusch_alpha,"AL05")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pusch_alpha= LTE_UplinkPowerControlCommon__alpha_al05;
+              }
+              else if (strcmp(ccparams_lte.pusch_alpha,"AL06")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pusch_alpha= LTE_UplinkPowerControlCommon__alpha_al06;
+              }
+              else if (strcmp(ccparams_lte.pusch_alpha,"AL07")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pusch_alpha= LTE_UplinkPowerControlCommon__alpha_al07;
+              }
+              else if (strcmp(ccparams_lte.pusch_alpha,"AL08")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pusch_alpha= LTE_UplinkPowerControlCommon__alpha_al08;
+              }
+              else if (strcmp(ccparams_lte.pusch_alpha,"AL09")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pusch_alpha= LTE_UplinkPowerControlCommon__alpha_al09;
+              }
+              else if (strcmp(ccparams_lte.pusch_alpha,"AL1")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pusch_alpha= LTE_UplinkPowerControlCommon__alpha_al1;
+              }
 
-		RRC_CONFIGURATION_REQ (msg_p).Nid_cell[j]= Nid_cell;
-	      
-		if (Nid_cell>503) {
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for Nid_cell choice: 0...503 !\n",
-			       RC.config_file_name, i, Nid_cell);
-		}
-		
-		RRC_CONFIGURATION_REQ (msg_p).N_RB_DL[j]= N_RB_DL;
-		
-		if ((N_RB_DL!=6) && (N_RB_DL!=15) && (N_RB_DL!=25) && (N_RB_DL!=50) && (N_RB_DL!=75) && (N_RB_DL!=100)) {
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for N_RB_DL choice: 6,15,25,50,75,100 !\n",
-			       RC.config_file_name, i, N_RB_DL);
-		}
-		
-		if (strcmp(frame_type, "FDD") == 0) {
-		  RRC_CONFIGURATION_REQ (msg_p).frame_type[j] = FDD;
-		} else  if (strcmp(frame_type, "TDD") == 0) {
-		  RRC_CONFIGURATION_REQ (msg_p).frame_type[j] = TDD;
-		} else {
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for frame_type choice: FDD or TDD !\n",
-			       RC.config_file_name, i, frame_type);
-		}
-		
-	      
-	      
-	      
-	      
-		if ((nb_antenna_ports <1) || (nb_antenna_ports > 2))
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for nb_antenna_ports choice: 1..2 !\n",
-			       RC.config_file_name, i, nb_antenna_ports);
-		
-		RRC_CONFIGURATION_REQ (msg_p).nb_antenna_ports[j] = nb_antenna_ports;
-		
-	      }
-	      if (rrc->node_type != ngran_eNB_DU) {//this is CU or eNB, SIB2-20 in CU
-	      
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-		if (!pbch_repetition)
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d define %s: TRUE,FALSE!\n",
-			       RC.config_file_name, i, ENB_CONFIG_STRING_PBCH_REPETITION);
-		else if (strcmp(pbch_repetition, "TRUE") == 0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pbch_repetition[j] = 1;
-		} else  if (strcmp(pbch_repetition, "FALSE") == 0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pbch_repetition[j] = 0;
-		} else {
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pbch_repetition choice: TRUE or FALSE !\n",
-			       RC.config_file_name, i, pbch_repetition);
-		}
 #endif
-		
-		
-	       	      		
-		RRC_CONFIGURATION_REQ (msg_p).prach_root[j] =  prach_root;
-	      	
-		if ((prach_root <0) || (prach_root > 1023))
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for prach_root choice: 0..1023 !\n",
-			       RC.config_file_name, i, prach_root);
-		
-		RRC_CONFIGURATION_REQ (msg_p).prach_config_index[j] = prach_config_index;
-		
-		if ((prach_config_index <0) || (prach_config_index > 63))
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for prach_config_index choice: 0..1023 !\n",
-			       RC.config_file_name, i, prach_config_index);
-	      		
-		if (!prach_high_speed)
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d define %s: ENABLE,DISABLE!\n",
-			       RC.config_file_name, i, ENB_CONFIG_STRING_PRACH_HIGH_SPEED);
-		else if (strcmp(prach_high_speed, "ENABLE") == 0) {
-		  RRC_CONFIGURATION_REQ (msg_p).prach_high_speed[j] = TRUE;
-		} else if (strcmp(prach_high_speed, "DISABLE") == 0) {
-		  RRC_CONFIGURATION_REQ (msg_p).prach_high_speed[j] = FALSE;
-		} else
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for prach_config choice: ENABLE,DISABLE !\n",
-			       RC.config_file_name, i, prach_high_speed);
-	      	
-		RRC_CONFIGURATION_REQ (msg_p).prach_zero_correlation[j] =prach_zero_correlation;
-		
-		if ((prach_zero_correlation <0) || (prach_zero_correlation > 15))
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for prach_zero_correlation choice: 0..15!\n",
-			       RC.config_file_name, i, prach_zero_correlation);
-		
-		RRC_CONFIGURATION_REQ (msg_p).prach_freq_offset[j] = prach_freq_offset;
-		if ((prach_freq_offset <0) || (prach_freq_offset > 94))
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for prach_freq_offset choice: 0..94!\n",
-			       RC.config_file_name, i, prach_freq_offset);
-		
-		RRC_CONFIGURATION_REQ (msg_p).pucch_delta_shift[j] = pucch_delta_shift-1;
-		
-		if ((pucch_delta_shift <1) || (pucch_delta_shift > 3))
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pucch_delta_shift choice: 1..3!\n",
-			       RC.config_file_name, i, pucch_delta_shift);
-		
-		RRC_CONFIGURATION_REQ (msg_p).pucch_nRB_CQI[j] = pucch_nRB_CQI;
-		
-		if ((pucch_nRB_CQI <0) || (pucch_nRB_CQI > 98))
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pucch_nRB_CQI choice: 0..98!\n",
-			       RC.config_file_name, i, pucch_nRB_CQI);
-		
-		RRC_CONFIGURATION_REQ (msg_p).pucch_nCS_AN[j] = pucch_nCS_AN;
-		
-		if ((pucch_nCS_AN <0) || (pucch_nCS_AN > 7))
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pucch_nCS_AN choice: 0..7!\n",
-			       RC.config_file_name, i, pucch_nCS_AN);
-		
-		//#if (RRC_VERSION < MAKE_VERSION(10, 0, 0))
-		RRC_CONFIGURATION_REQ (msg_p).pucch_n1_AN[j] = pucch_n1_AN;
-		
-		if ((pucch_n1_AN <0) || (pucch_n1_AN > 2047))
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pucch_n1_AN choice: 0..2047!\n",
-			       RC.config_file_name, i, pucch_n1_AN);
-		
-		//#endif
-		RRC_CONFIGURATION_REQ (msg_p).pdsch_referenceSignalPower[j] = pdsch_referenceSignalPower;
-		
-		if ((pdsch_referenceSignalPower <-60) || (pdsch_referenceSignalPower > 50))
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pdsch_referenceSignalPower choice:-60..50!\n",
-			       RC.config_file_name, i, pdsch_referenceSignalPower);
-		
-		RRC_CONFIGURATION_REQ (msg_p).pdsch_p_b[j] = pdsch_p_b;
-		
-		if ((pdsch_p_b <0) || (pdsch_p_b > 3))
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pdsch_p_b choice: 0..3!\n",
-			       RC.config_file_name, i, pdsch_p_b);
-		
-		RRC_CONFIGURATION_REQ (msg_p).pusch_n_SB[j] = pusch_n_SB;
-		
-		if ((pusch_n_SB <1) || (pusch_n_SB > 4))
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pusch_n_SB choice: 1..4!\n",
-			       RC.config_file_name, i, pusch_n_SB);
-		
-		if (!pusch_hoppingMode)
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d define %s: interSubframe,intraAndInterSubframe!\n",
-			       RC.config_file_name, i, ENB_CONFIG_STRING_PUSCH_HOPPINGMODE);
-		else if (strcmp(pusch_hoppingMode,"interSubFrame")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pusch_hoppingMode[j] = PUSCH_ConfigCommon__pusch_ConfigBasic__hoppingMode_interSubFrame;
-		}  else if (strcmp(pusch_hoppingMode,"intraAndInterSubFrame")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pusch_hoppingMode[j] = PUSCH_ConfigCommon__pusch_ConfigBasic__hoppingMode_intraAndInterSubFrame;
-		} else
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pusch_hoppingMode choice: interSubframe,intraAndInterSubframe!\n",
-			       RC.config_file_name, i, pusch_hoppingMode);
-		
-		RRC_CONFIGURATION_REQ (msg_p).pusch_hoppingOffset[j] = pusch_hoppingOffset;
-		
-		if ((pusch_hoppingOffset<0) || (pusch_hoppingOffset>98))
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pusch_hoppingOffset choice: 0..98!\n",
-			       RC.config_file_name, i, pusch_hoppingMode);
-		
-		if (!pusch_enable64QAM)
-		  AssertFatal (0, 
-			       "Failed to parse eNB configuration file %s, enb %d define %s: ENABLE,DISABLE!\n",
-			       RC.config_file_name, i, ENB_CONFIG_STRING_PUSCH_ENABLE64QAM);
-		else if (strcmp(pusch_enable64QAM, "ENABLE") == 0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pusch_enable64QAM[j] = TRUE;
-		}  else if (strcmp(pusch_enable64QAM, "DISABLE") == 0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pusch_enable64QAM[j] = FALSE;
-		} else
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pusch_enable64QAM choice: ENABLE,DISABLE!\n",
-			       RC.config_file_name, i, pusch_enable64QAM);
-		
-		if (!pusch_groupHoppingEnabled)
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d define %s: ENABLE,DISABLE!\n",
-			       RC.config_file_name, i, ENB_CONFIG_STRING_PUSCH_GROUP_HOPPING_EN);
-		else if (strcmp(pusch_groupHoppingEnabled, "ENABLE") == 0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pusch_groupHoppingEnabled[j] = TRUE;
-		}  else if (strcmp(pusch_groupHoppingEnabled, "DISABLE") == 0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pusch_groupHoppingEnabled[j] = FALSE;
-		} else
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pusch_groupHoppingEnabled choice: ENABLE,DISABLE!\n",
-			       RC.config_file_name, i, pusch_groupHoppingEnabled);
-		
-		
-		RRC_CONFIGURATION_REQ (msg_p).pusch_groupAssignment[j] = pusch_groupAssignment;
-		
-		if ((pusch_groupAssignment<0)||(pusch_groupAssignment>29))
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pusch_groupAssignment choice: 0..29!\n",
-			       RC.config_file_name, i, pusch_groupAssignment);
-		
-		if (!pusch_sequenceHoppingEnabled)
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d define %s: ENABLE,DISABLE!\n",
-			       RC.config_file_name, i, ENB_CONFIG_STRING_PUSCH_SEQUENCE_HOPPING_EN);
-		else if (strcmp(pusch_sequenceHoppingEnabled, "ENABLE") == 0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pusch_sequenceHoppingEnabled[j] = TRUE;
-		}  else if (strcmp(pusch_sequenceHoppingEnabled, "DISABLE") == 0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pusch_sequenceHoppingEnabled[j] = FALSE;
-		} else
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pusch_sequenceHoppingEnabled choice: ENABLE,DISABLE!\n",
-			       RC.config_file_name, i, pusch_sequenceHoppingEnabled);
-		
-		RRC_CONFIGURATION_REQ (msg_p).pusch_nDMRS1[j] = pusch_nDMRS1;  //cyclic_shift in RRC!
-		
-		if ((pusch_nDMRS1 <0) || (pusch_nDMRS1>7))
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pusch_nDMRS1 choice: 0..7!\n",
-			       RC.config_file_name, i, pusch_nDMRS1);
-		
-		if (strcmp(phich_duration,"NORMAL")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).phich_duration[j] = PHICH_Config__phich_Duration_normal;
-		} else if (strcmp(phich_duration,"EXTENDED")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).phich_duration[j] = PHICH_Config__phich_Duration_extended;
-		} else
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for phich_duration choice: NORMAL,EXTENDED!\n",
-			       RC.config_file_name, i, phich_duration);
-		
-		if (strcmp(phich_resource,"ONESIXTH")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).phich_resource[j] = PHICH_Config__phich_Resource_oneSixth ;
-		} else if (strcmp(phich_resource,"HALF")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).phich_resource[j] = PHICH_Config__phich_Resource_half;
-		} else if (strcmp(phich_resource,"ONE")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).phich_resource[j] = PHICH_Config__phich_Resource_one;
-		} else if (strcmp(phich_resource,"TWO")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).phich_resource[j] = PHICH_Config__phich_Resource_two;
-		} else
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for phich_resource choice: ONESIXTH,HALF,ONE,TWO!\n",
-			       RC.config_file_name, i, phich_resource);
-
-		printf("phich.resource %ld (%s), phich.duration %ld (%s)\n",
-		       RRC_CONFIGURATION_REQ (msg_p).phich_resource[j],phich_resource,
-		       RRC_CONFIGURATION_REQ (msg_p).phich_duration[j],phich_duration);
-
-		if (strcmp(srs_enable, "ENABLE") == 0) {
-		  RRC_CONFIGURATION_REQ (msg_p).srs_enable[j] = TRUE;
-		} else if (strcmp(srs_enable, "DISABLE") == 0) {
-		  RRC_CONFIGURATION_REQ (msg_p).srs_enable[j] = FALSE;
-		} else
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for srs_BandwidthConfig choice: ENABLE,DISABLE !\n",
-			       RC.config_file_name, i, srs_enable);
-
-		if (RRC_CONFIGURATION_REQ (msg_p).srs_enable[j] == TRUE) {
-
-		  RRC_CONFIGURATION_REQ (msg_p).srs_BandwidthConfig[j] = srs_BandwidthConfig;
-
-		  if ((srs_BandwidthConfig < 0) || (srs_BandwidthConfig >7))
-		    AssertFatal (0, "Failed to parse eNB configuration file %s, enb %d unknown value %d for srs_BandwidthConfig choice: 0...7\n",
-				 RC.config_file_name, i, srs_BandwidthConfig);
-
-		  RRC_CONFIGURATION_REQ (msg_p).srs_SubframeConfig[j] = srs_SubframeConfig;
-
-		  if ((srs_SubframeConfig<0) || (srs_SubframeConfig>15))
-		    AssertFatal (0,
-				 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for srs_SubframeConfig choice: 0..15 !\n",
-				 RC.config_file_name, i, srs_SubframeConfig);
-
-		  if (strcmp(srs_ackNackST, "ENABLE") == 0) {
-		    RRC_CONFIGURATION_REQ (msg_p).srs_ackNackST[j] = TRUE;
-		  } else if (strcmp(srs_ackNackST, "DISABLE") == 0) {
-		    RRC_CONFIGURATION_REQ (msg_p).srs_ackNackST[j] = FALSE;
-		  } else
-		    AssertFatal (0,
-				 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for srs_BandwidthConfig choice: ENABLE,DISABLE !\n",
-				 RC.config_file_name, i, srs_ackNackST);
-
-		  if (strcmp(srs_MaxUpPts, "ENABLE") == 0) {
-		    RRC_CONFIGURATION_REQ (msg_p).srs_MaxUpPts[j] = TRUE;
-		  } else if (strcmp(srs_MaxUpPts, "DISABLE") == 0) {
-		    RRC_CONFIGURATION_REQ (msg_p).srs_MaxUpPts[j] = FALSE;
-		  } else
-		    AssertFatal (0,
-				 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for srs_MaxUpPts choice: ENABLE,DISABLE !\n",
-				 RC.config_file_name, i, srs_MaxUpPts);
-		}
-		
-		RRC_CONFIGURATION_REQ (msg_p).pusch_p0_Nominal[j] = pusch_p0_Nominal;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(12, 0, 0))
+
+              if (strcmp(ccparams_lte.pusch_alpha,"AL0")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pusch_alpha= LTE_Alpha_r12_al0;
+              }
+              else if (strcmp(ccparams_lte.pusch_alpha,"AL04")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pusch_alpha= LTE_Alpha_r12_al04;
+              }
+              else if (strcmp(ccparams_lte.pusch_alpha,"AL05")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pusch_alpha= LTE_Alpha_r12_al05;
+              }
+              else if (strcmp(ccparams_lte.pusch_alpha,"AL06")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pusch_alpha= LTE_Alpha_r12_al06;
+              }
+              else if (strcmp(ccparams_lte.pusch_alpha,"AL07")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pusch_alpha= LTE_Alpha_r12_al07;
+              }
+              else if (strcmp(ccparams_lte.pusch_alpha,"AL08")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pusch_alpha= LTE_Alpha_r12_al08;
+              }
+              else if (strcmp(ccparams_lte.pusch_alpha,"AL09")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pusch_alpha= LTE_Alpha_r12_al09;
+              }
+              else if (strcmp(ccparams_lte.pusch_alpha,"AL1")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pusch_alpha= LTE_Alpha_r12_al1;
+              }
 
-		if ((pusch_p0_Nominal<-126) || (pusch_p0_Nominal>24))
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pusch_p0_Nominal choice: -126..24 !\n",
-			       RC.config_file_name, i, pusch_p0_Nominal);
-
-#if (RRC_VERSION <= MAKE_VERSION(12, 0, 0))
-		if (strcmp(pusch_alpha,"AL0")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pusch_alpha[j] = UplinkPowerControlCommon__alpha_al0;
-		} else if (strcmp(pusch_alpha,"AL04")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pusch_alpha[j] = UplinkPowerControlCommon__alpha_al04;
-		} else if (strcmp(pusch_alpha,"AL05")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pusch_alpha[j] = UplinkPowerControlCommon__alpha_al05;
-		} else if (strcmp(pusch_alpha,"AL06")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pusch_alpha[j] = UplinkPowerControlCommon__alpha_al06;
-		} else if (strcmp(pusch_alpha,"AL07")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pusch_alpha[j] = UplinkPowerControlCommon__alpha_al07;
-		} else if (strcmp(pusch_alpha,"AL08")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pusch_alpha[j] = UplinkPowerControlCommon__alpha_al08;
-		} else if (strcmp(pusch_alpha,"AL09")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pusch_alpha[j] = UplinkPowerControlCommon__alpha_al09;
-		} else if (strcmp(pusch_alpha,"AL1")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pusch_alpha[j] = UplinkPowerControlCommon__alpha_al1;
-		} 
 #endif
+              else
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pucch_Alpha choice: AL0,AL04,AL05,AL06,AL07,AL08,AL09,AL1!\n",
+                             RC.config_file_name, i, ccparams_lte.pusch_alpha);
 
-#if (RRC_VERSION >= MAKE_VERSION(12, 0, 0))
-
-            if (strcmp(pusch_alpha,"AL0")==0) {
-              RRC_CONFIGURATION_REQ (msg_p).pusch_alpha[j] = Alpha_r12_al0;
-            } else if (strcmp(pusch_alpha,"AL04")==0) {
-              RRC_CONFIGURATION_REQ (msg_p).pusch_alpha[j] = Alpha_r12_al04;
-            } else if (strcmp(pusch_alpha,"AL05")==0) {
-              RRC_CONFIGURATION_REQ (msg_p).pusch_alpha[j] = Alpha_r12_al05;
-            } else if (strcmp(pusch_alpha,"AL06")==0) {
-              RRC_CONFIGURATION_REQ (msg_p).pusch_alpha[j] = Alpha_r12_al06;
-            } else if (strcmp(pusch_alpha,"AL07")==0) {
-              RRC_CONFIGURATION_REQ (msg_p).pusch_alpha[j] = Alpha_r12_al07;
-            } else if (strcmp(pusch_alpha,"AL08")==0) {
-              RRC_CONFIGURATION_REQ (msg_p).pusch_alpha[j] = Alpha_r12_al08;
-            } else if (strcmp(pusch_alpha,"AL09")==0) {
-              RRC_CONFIGURATION_REQ (msg_p).pusch_alpha[j] = Alpha_r12_al09;
-            } else if (strcmp(pusch_alpha,"AL1")==0) {
-              RRC_CONFIGURATION_REQ (msg_p).pusch_alpha[j] = Alpha_r12_al1;
-            }
+              RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pucch_p0_Nominal= ccparams_lte.pucch_p0_Nominal;
+
+              if ((ccparams_lte.pucch_p0_Nominal<-127) ||
+                  (ccparams_lte.pucch_p0_Nominal>-96))
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pucch_p0_Nominal choice: -127..-96 !\n",
+                             RC.config_file_name, i, ccparams_lte.pucch_p0_Nominal);
+
+              RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].msg3_delta_Preamble= ccparams_lte.msg3_delta_Preamble;
+
+              if ((ccparams_lte.msg3_delta_Preamble<-1) ||
+                  (ccparams_lte.msg3_delta_Preamble>6))
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for msg3_delta_Preamble choice: -1..6 !\n",
+                             RC.config_file_name, i, ccparams_lte.msg3_delta_Preamble);
+
+              if (strcmp(ccparams_lte.pucch_deltaF_Format1,"deltaF_2")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pucch_deltaF_Format1= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format1_deltaF_2;
+              }
+              else if (strcmp(ccparams_lte.pucch_deltaF_Format1,"deltaF0")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pucch_deltaF_Format1= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format1_deltaF0;
+              }
+              else if (strcmp(ccparams_lte.pucch_deltaF_Format1,"deltaF2")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pucch_deltaF_Format1= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format1_deltaF2;
+              }
+              else
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pucch_deltaF_Format1 choice: deltaF_2,dltaF0,deltaF2!\n",
+                             RC.config_file_name, i, ccparams_lte.pucch_deltaF_Format1);
+
+              if (strcmp(ccparams_lte.pucch_deltaF_Format1b,"deltaF1")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pucch_deltaF_Format1b= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format1b_deltaF1;
+              }
+              else if (strcmp(ccparams_lte.pucch_deltaF_Format1b,"deltaF3")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pucch_deltaF_Format1b= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format1b_deltaF3;
+              }
+              else if (strcmp(ccparams_lte.pucch_deltaF_Format1b,"deltaF5")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pucch_deltaF_Format1b= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format1b_deltaF5;
+              }
+              else
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pucch_deltaF_Format1b choice: deltaF1,dltaF3,deltaF5!\n",
+                             RC.config_file_name, i, ccparams_lte.pucch_deltaF_Format1b);
+
+              if (strcmp(ccparams_lte.pucch_deltaF_Format2,"deltaF_2")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pucch_deltaF_Format2= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format2_deltaF_2;
+              }
+              else if (strcmp(ccparams_lte.pucch_deltaF_Format2,"deltaF0")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pucch_deltaF_Format2= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format2_deltaF0;
+              }
+              else if (strcmp(ccparams_lte.pucch_deltaF_Format2,"deltaF1")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pucch_deltaF_Format2= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format2_deltaF1;
+              }
+              else if (strcmp(ccparams_lte.pucch_deltaF_Format2,"deltaF2")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pucch_deltaF_Format2= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format2_deltaF2;
+              } else
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pucch_deltaF_Format2 choice: deltaF_2,dltaF0,deltaF1,deltaF2!\n",
+                             RC.config_file_name, i, ccparams_lte.pucch_deltaF_Format2);
+
+              if (strcmp(ccparams_lte.pucch_deltaF_Format2a,"deltaF_2")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pucch_deltaF_Format2a= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format2a_deltaF_2;
+              }
+              else if (strcmp(ccparams_lte.pucch_deltaF_Format2a,"deltaF0")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pucch_deltaF_Format2a= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format2a_deltaF0;
+              }
+              else if (strcmp(ccparams_lte.pucch_deltaF_Format2a,"deltaF2")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pucch_deltaF_Format2a= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format2a_deltaF2;
+              }
+              else
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pucch_deltaF_Format2a choice: deltaF_2,dltaF0,deltaF2!\n",
+                             RC.config_file_name, i, ccparams_lte.pucch_deltaF_Format2a);
+
+              if (strcmp(ccparams_lte.pucch_deltaF_Format2b,"deltaF_2")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pucch_deltaF_Format2b= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format2b_deltaF_2;
+              }
+              else if (strcmp(ccparams_lte.pucch_deltaF_Format2b,"deltaF0")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pucch_deltaF_Format2b= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format2b_deltaF0;
+              }
+              else if (strcmp(ccparams_lte.pucch_deltaF_Format2b,"deltaF2")==0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pucch_deltaF_Format2b= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format2b_deltaF2;
+              }
+              else
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pucch_deltaF_Format2b choice: deltaF_2,dltaF0,deltaF2!\n",
+                             RC.config_file_name, i, ccparams_lte.pucch_deltaF_Format2b);
+
+              RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_numberOfRA_Preambles= (ccparams_lte.rach_numberOfRA_Preambles/4)-1;
+
+              if ((ccparams_lte.rach_numberOfRA_Preambles <4) ||
+                  (ccparams_lte.rach_numberOfRA_Preambles>64) ||
+                  ((ccparams_lte.rach_numberOfRA_Preambles&3)!=0))
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for rach_numberOfRA_Preambles choice: 4,8,12,...,64!\n",
+                             RC.config_file_name, i, ccparams_lte.rach_numberOfRA_Preambles);
+
+              if (strcmp(ccparams_lte.rach_preamblesGroupAConfig, "ENABLE") == 0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_preamblesGroupAConfig= TRUE;
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_sizeOfRA_PreamblesGroupA= (ccparams_lte.rach_sizeOfRA_PreamblesGroupA/4)-1;
+
+                if ((ccparams_lte.rach_numberOfRA_Preambles <4) ||
+                    (ccparams_lte.rach_numberOfRA_Preambles>60) ||
+                    ((ccparams_lte.rach_numberOfRA_Preambles&3)!=0))
+                  AssertFatal (0,
+                               "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for rach_sizeOfRA_PreamblesGroupA choice: 4,8,12,...,60!\n",
+                               RC.config_file_name, i, ccparams_lte.rach_sizeOfRA_PreamblesGroupA);
+
+                switch (ccparams_lte.rach_messageSizeGroupA) {
+                case 56:
+                  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_messageSizeGroupA= LTE_RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messageSizeGroupA_b56;
+                  break;
+
+                case 144:
+                  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_messageSizeGroupA= LTE_RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messageSizeGroupA_b144;
+                  break;
+
+                case 208:
+                  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_messageSizeGroupA= LTE_RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messageSizeGroupA_b208;
+                  break;
+
+                case 256:
+                  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_messageSizeGroupA= LTE_RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messageSizeGroupA_b256;
+                  break;
+
+                default:
+                  AssertFatal (0,
+                               "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for rach_messageSizeGroupA choice: 56,144,208,256!\n",
+                               RC.config_file_name, i, ccparams_lte.rach_messageSizeGroupA);
+                  break;
+                }
+
+                if (strcmp(ccparams_lte.rach_messagePowerOffsetGroupB,"minusinfinity")==0) {
+                  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_messagePowerOffsetGroupB= LTE_RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messagePowerOffsetGroupB_minusinfinity;
+                }
+                else if (strcmp(ccparams_lte.rach_messagePowerOffsetGroupB,"dB0")==0) {
+                  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_messagePowerOffsetGroupB= LTE_RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messagePowerOffsetGroupB_dB0;
+                }
+                else if (strcmp(ccparams_lte.rach_messagePowerOffsetGroupB,"dB5")==0) {
+                  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_messagePowerOffsetGroupB= LTE_RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messagePowerOffsetGroupB_dB5;
+                }
+                else if (strcmp(ccparams_lte.rach_messagePowerOffsetGroupB,"dB8")==0) {
+                  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_messagePowerOffsetGroupB= LTE_RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messagePowerOffsetGroupB_dB8;
+                }
+                else if (strcmp(ccparams_lte.rach_messagePowerOffsetGroupB,"dB10")==0) {
+                  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_messagePowerOffsetGroupB= LTE_RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messagePowerOffsetGroupB_dB10;
+                }
+                else if (strcmp(ccparams_lte.rach_messagePowerOffsetGroupB,"dB12")==0) {
+                  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_messagePowerOffsetGroupB= LTE_RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messagePowerOffsetGroupB_dB12;
+                }
+                else if (strcmp(ccparams_lte.rach_messagePowerOffsetGroupB,"dB15")==0) {
+                  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_messagePowerOffsetGroupB= LTE_RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messagePowerOffsetGroupB_dB15;
+                }
+                else if (strcmp(ccparams_lte.rach_messagePowerOffsetGroupB,"dB18")==0) {
+                  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_messagePowerOffsetGroupB= LTE_RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messagePowerOffsetGroupB_dB18;
+                }
+                else
+                  AssertFatal (0,
+                               "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for rach_messagePowerOffsetGroupB choice: minusinfinity,dB0,dB5,dB8,dB10,dB12,dB15,dB18!\n",
+                               RC.config_file_name, i, ccparams_lte.rach_messagePowerOffsetGroupB);
+              } else if (strcmp(ccparams_lte.rach_preamblesGroupAConfig, "DISABLE") == 0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_preamblesGroupAConfig= FALSE;
+              } else
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for rach_preamblesGroupAConfig choice: ENABLE,DISABLE !\n",
+                             RC.config_file_name, i, ccparams_lte.rach_preamblesGroupAConfig);
+
+              RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_preambleInitialReceivedTargetPower= (ccparams_lte.rach_preambleInitialReceivedTargetPower+120)/2;
+
+              if ((ccparams_lte.rach_preambleInitialReceivedTargetPower<-120) ||
+                  (ccparams_lte.rach_preambleInitialReceivedTargetPower>-90) ||
+                  ((ccparams_lte.rach_preambleInitialReceivedTargetPower&1)!=0))
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for rach_preambleInitialReceivedTargetPower choice: -120,-118,...,-90 !\n",
+                             RC.config_file_name, i, ccparams_lte.rach_preambleInitialReceivedTargetPower);
+
+              RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_powerRampingStep= ccparams_lte.rach_powerRampingStep/2;
+
+              if ((ccparams_lte.rach_powerRampingStep<0) ||
+                  (ccparams_lte.rach_powerRampingStep>6) ||
+                  ((ccparams_lte.rach_powerRampingStep&1)!=0))
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for rach_powerRampingStep choice: 0,2,4,6 !\n",
+                             RC.config_file_name, i, ccparams_lte.rach_powerRampingStep);
+
+              switch (ccparams_lte.rach_preambleTransMax) {
+#if (LTE_RRC_VERSION < MAKE_VERSION(14, 0, 0))
+
+              case 3:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_preambleTransMax= LTE_RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n3;
+                break;
+
+              case 4:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_preambleTransMax= LTE_RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n4;
+                break;
+
+              case 5:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_preambleTransMax= LTE_RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n5;
+                break;
+
+              case 6:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_preambleTransMax= LTE_RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n6;
+                break;
+
+              case 7:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_preambleTransMax= LTE_RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n7;
+                break;
+
+              case 8:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_preambleTransMax= LTE_RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n8;
+                break;
+
+              case 10:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_preambleTransMax= LTE_RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n10;
+                break;
+
+              case 20:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_preambleTransMax= LTE_RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n20;
+                break;
+
+              case 50:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_preambleTransMax= LTE_RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n50;
+                break;
+
+              case 100:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_preambleTransMax= LTE_RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n100;
+                break;
+
+              case 200:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_preambleTransMax= LTE_RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n200;
+                break;
+#else
+
+              case 3:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_preambleTransMax= LTE_PreambleTransMax_n3;
+                break;
+
+              case 4:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_preambleTransMax= LTE_PreambleTransMax_n4;
+                break;
+
+              case 5:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_preambleTransMax= LTE_PreambleTransMax_n5;
+                break;
+
+              case 6:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_preambleTransMax= LTE_PreambleTransMax_n6;
+                break;
+
+              case 7:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_preambleTransMax= LTE_PreambleTransMax_n7;
+                break;
+
+              case 8:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_preambleTransMax= LTE_PreambleTransMax_n8;
+                break;
+
+              case 10:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_preambleTransMax= LTE_PreambleTransMax_n10;
+                break;
+
+              case 20:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_preambleTransMax= LTE_PreambleTransMax_n20;
+                break;
+
+              case 50:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_preambleTransMax= LTE_PreambleTransMax_n50;
+                break;
+
+              case 100:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_preambleTransMax= LTE_PreambleTransMax_n100;
+                break;
+
+              case 200:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_preambleTransMax= LTE_PreambleTransMax_n200;
+                break;
 
 #endif
-		else
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pucch_Alpha choice: AL0,AL04,AL05,AL06,AL07,AL08,AL09,AL1!\n",
-			       RC.config_file_name, i, pusch_alpha);
 
-		RRC_CONFIGURATION_REQ (msg_p).pucch_p0_Nominal[j] = pucch_p0_Nominal;
+              default:
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for rach_preambleTransMax choice: 3,4,5,6,7,8,10,20,50,100,200!\n",
+                             RC.config_file_name, i, ccparams_lte.rach_preambleTransMax);
+                break;
+              }
+
+              RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_raResponseWindowSize=  (ccparams_lte.rach_raResponseWindowSize==10)?7:ccparams_lte.rach_raResponseWindowSize-2;
+
+              if ((ccparams_lte.rach_raResponseWindowSize<0)||
+                  (ccparams_lte.rach_raResponseWindowSize==9)||
+                  (ccparams_lte.rach_raResponseWindowSize>10))
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for rach_raResponseWindowSize choice: 2,3,4,5,6,7,8,10!\n",
+                             RC.config_file_name, i, ccparams_lte.rach_preambleTransMax);
+
+              RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_macContentionResolutionTimer= (ccparams_lte.rach_macContentionResolutionTimer/8)-1;
+
+              if ((ccparams_lte.rach_macContentionResolutionTimer<8) ||
+                  (ccparams_lte.rach_macContentionResolutionTimer>64) ||
+                  ((ccparams_lte.rach_macContentionResolutionTimer&7)!=0))
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for rach_macContentionResolutionTimer choice: 8,16,...,56,64!\n",
+                             RC.config_file_name, i, ccparams_lte.rach_preambleTransMax);
+
+              RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].rach_maxHARQ_Msg3Tx= ccparams_lte.rach_maxHARQ_Msg3Tx;
+
+              if ((ccparams_lte.rach_maxHARQ_Msg3Tx<0) ||
+                  (ccparams_lte.rach_maxHARQ_Msg3Tx>8))
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for rach_maxHARQ_Msg3Tx choice: 1..8!\n",
+                             RC.config_file_name, i, ccparams_lte.rach_preambleTransMax);
+
+              switch (ccparams_lte.pcch_defaultPagingCycle) {
+              case 32:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pcch_defaultPagingCycle= LTE_PCCH_Config__defaultPagingCycle_rf32;
+                break;
+
+              case 64:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pcch_defaultPagingCycle= LTE_PCCH_Config__defaultPagingCycle_rf64;
+                break;
+
+              case 128:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pcch_defaultPagingCycle= LTE_PCCH_Config__defaultPagingCycle_rf128;
+                break;
+
+              case 256:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pcch_defaultPagingCycle= LTE_PCCH_Config__defaultPagingCycle_rf256;
+                break;
+
+              default:
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pcch_defaultPagingCycle choice: 32,64,128,256!\n",
+                             RC.config_file_name, i, ccparams_lte.pcch_defaultPagingCycle);
+                break;
+              }
+
+              if (strcmp(ccparams_lte.pcch_nB, "fourT") == 0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pcch_nB= LTE_PCCH_Config__nB_fourT;
+              }
+              else if (strcmp(ccparams_lte.pcch_nB, "twoT") == 0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pcch_nB= LTE_PCCH_Config__nB_twoT;
+              }
+              else if (strcmp(ccparams_lte.pcch_nB, "oneT") == 0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pcch_nB= LTE_PCCH_Config__nB_oneT;
+              }
+              else if (strcmp(ccparams_lte.pcch_nB, "halfT") == 0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pcch_nB= LTE_PCCH_Config__nB_halfT;
+              }
+              else if (strcmp(ccparams_lte.pcch_nB, "quarterT") == 0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pcch_nB= LTE_PCCH_Config__nB_quarterT;
+              }
+              else if (strcmp(ccparams_lte.pcch_nB, "oneEighthT") == 0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pcch_nB= LTE_PCCH_Config__nB_oneEighthT;
+              }
+              else if (strcmp(ccparams_lte.pcch_nB, "oneSixteenthT") == 0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pcch_nB= LTE_PCCH_Config__nB_oneSixteenthT;
+              }
+              else if (strcmp(ccparams_lte.pcch_nB, "oneThirtySecondT") == 0) {
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].pcch_nB= LTE_PCCH_Config__nB_oneThirtySecondT;
+              }
+              else
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pcch_nB choice: fourT,twoT,oneT,halfT,quarterT,oneighthT,oneSixteenthT,oneThirtySecondT !\n",
+                             RC.config_file_name, i, ccparams_lte.pcch_nB);
+
+              switch (ccparams_lte.bcch_modificationPeriodCoeff) {
+              case 2:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].bcch_modificationPeriodCoeff= LTE_BCCH_Config__modificationPeriodCoeff_n2;
+                break;
+
+              case 4:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].bcch_modificationPeriodCoeff= LTE_BCCH_Config__modificationPeriodCoeff_n4;
+                break;
+
+              case 8:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].bcch_modificationPeriodCoeff= LTE_BCCH_Config__modificationPeriodCoeff_n8;
+                break;
+
+              case 16:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].bcch_modificationPeriodCoeff= LTE_BCCH_Config__modificationPeriodCoeff_n16;
+                break;
+
+              default:
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for bcch_modificationPeriodCoeff choice: 2,4,8,16",
+                             RC.config_file_name, i, ccparams_lte.bcch_modificationPeriodCoeff);
+                break;
+              }
+
+              RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].ue_TimersAndConstants_t300= ccparams_lte.ue_TimersAndConstants_t300;
+              RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].ue_TimersAndConstants_t301= ccparams_lte.ue_TimersAndConstants_t301;
+              RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].ue_TimersAndConstants_t310= ccparams_lte.ue_TimersAndConstants_t310;
+              RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].ue_TimersAndConstants_t311= ccparams_lte.ue_TimersAndConstants_t311;
+              RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].ue_TimersAndConstants_n310= ccparams_lte.ue_TimersAndConstants_n310;
+              RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].ue_TimersAndConstants_n311= ccparams_lte.ue_TimersAndConstants_n311;
+
+              switch (ccparams_lte.ue_TransmissionMode) {
+              case 1:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].ue_TransmissionMode= LTE_AntennaInfoDedicated__transmissionMode_tm1;
+                break;
+
+              case 2:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].ue_TransmissionMode= LTE_AntennaInfoDedicated__transmissionMode_tm2;
+                break;
+
+              case 3:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].ue_TransmissionMode= LTE_AntennaInfoDedicated__transmissionMode_tm3;
+                break;
+
+              case 4:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].ue_TransmissionMode= LTE_AntennaInfoDedicated__transmissionMode_tm4;
+                break;
+
+              case 5:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].ue_TransmissionMode= LTE_AntennaInfoDedicated__transmissionMode_tm5;
+                break;
+
+              case 6:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].ue_TransmissionMode= LTE_AntennaInfoDedicated__transmissionMode_tm6;
+                break;
+
+              case 7:
+                RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].ue_TransmissionMode= LTE_AntennaInfoDedicated__transmissionMode_tm7;
+                break;
+
+              default:
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for ue_TransmissionMode choice: 1,2,3,4,5,6,7",
+                             RC.config_file_name, i, ccparams_lte.ue_TransmissionMode);
+                break;
+              }
+
+              RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[j].ue_multiple_max= ccparams_lte.ue_multiple_max;
+
+              switch (ccparams_lte.N_RB_DL) {
+              case 25:
+                if ((ccparams_lte.ue_multiple_max < 1) ||
+                    (ccparams_lte.ue_multiple_max > 4))
+                  AssertFatal (0,
+                               "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for ue_multiple_max choice: 1..4!\n",
+                               RC.config_file_name, i, ccparams_lte.ue_multiple_max);
+
+                break;
+
+              case 50:
+                if ((ccparams_lte.ue_multiple_max < 1) ||
+                    (ccparams_lte.ue_multiple_max > 8))
+                  AssertFatal (0,
+                               "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for ue_multiple_max choice: 1..8!\n",
+                               RC.config_file_name, i, ccparams_lte.ue_multiple_max);
+
+                break;
+
+              case 100:
+                if ((ccparams_lte.ue_multiple_max < 1) ||
+                    (ccparams_lte.ue_multiple_max > 16))
+                  AssertFatal (0,
+                               "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for ue_multiple_max choice: 1..16!\n",
+                               RC.config_file_name, i, ccparams_lte.ue_multiple_max);
+
+                break;
+
+              default:
+                AssertFatal (0,
+                             "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for N_RB_DL choice: 25,50,100 !\n",
+                             RC.config_file_name, i, ccparams_lte.N_RB_DL);
+                break;
+              }
+
+              // eMBMS configuration
+              RRC_CONFIGURATION_REQ(msg_p).eMBMS_configured = 0;
+              printf("No eMBMS configuration, skipping it\n");
+
+              // eMTC configuration
+              char brparamspath[MAX_OPTNAME_SIZE*2 + 16];
+              sprintf(brparamspath,"%s.%s", ccspath, ENB_CONFIG_STRING_EMTC_PARAMETERS);
+              config_get(eMTCParams, sizeof(eMTCParams)/sizeof(paramdef_t), brparamspath);
+              RRC_CONFIGURATION_REQ(msg_p).eMTC_configured = eMTCconfig.eMTC_configured&1;
+
+              if (eMTCconfig.eMTC_configured > 0) fill_eMTC_configuration(msg_p,&eMTCconfig, i,j,RC.config_file_name,brparamspath);
+              else   	                        printf("No eMTC configuration, skipping it\n");
+
+
+              // Sidelink configuration
+              char SLparamspath[MAX_OPTNAME_SIZE*2 + 16];
+              sprintf(SLparamspath,"%s.%s", ccspath, ENB_CONFIG_STRING_SL_PARAMETERS);
+              config_get( SLParams, sizeof(SLParams)/sizeof(paramdef_t), SLparamspath);
+
+              // Sidelink Resource pool information
+              RRC_CONFIGURATION_REQ (msg_p).SL_configured=SLconfig.sidelink_configured&1;
+              if (SLconfig.sidelink_configured==1) fill_SL_configuration(msg_p,&SLconfig,i,j,RC.config_file_name);
+              else                                 printf("No SL configuration skipping it\n");
+            } // node_type!=ngran_eNB_DU
+          }
+
+          if ( (rrc->node_type == ngran_eNB_CU) || (rrc->node_type == ngran_ng_eNB_CU) || (rrc->node_type == ngran_gNB_CU) ) {
+            char srb1path[MAX_OPTNAME_SIZE*2 + 8];
+            sprintf(srb1path,"%s.%s",enbpath,ENB_CONFIG_STRING_SRB1);
+            config_get( SRB1Params,sizeof(SRB1Params)/sizeof(paramdef_t), srb1path);
+
+
+            switch (srb1_params.srb1_max_retx_threshold) {
+            case 1:
+              rrc->srb1_max_retx_threshold = LTE_UL_AM_RLC__maxRetxThreshold_t1;
+              break;
+
+            case 2:
+              rrc->srb1_max_retx_threshold = LTE_UL_AM_RLC__maxRetxThreshold_t2;
+              break;
+
+            case 3:
+              rrc->srb1_max_retx_threshold = LTE_UL_AM_RLC__maxRetxThreshold_t3;
+              break;
+
+            case 4:
+              rrc->srb1_max_retx_threshold = LTE_UL_AM_RLC__maxRetxThreshold_t4;
+              break;
+
+            case 6:
+              rrc->srb1_max_retx_threshold = LTE_UL_AM_RLC__maxRetxThreshold_t6;
+              break;
+
+            case 8:
+              rrc->srb1_max_retx_threshold = LTE_UL_AM_RLC__maxRetxThreshold_t8;
+              break;
+
+            case 16:
+              rrc->srb1_max_retx_threshold = LTE_UL_AM_RLC__maxRetxThreshold_t16;
+              break;
+
+            case 32:
+              rrc->srb1_max_retx_threshold = LTE_UL_AM_RLC__maxRetxThreshold_t32;
+              break;
 
-		if ((pucch_p0_Nominal<-127) || (pucch_p0_Nominal>-96))
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pucch_p0_Nominal choice: -127..-96 !\n",
-			       RC.config_file_name, i, pucch_p0_Nominal);
+            default:
+              AssertFatal (0,
+                           "Bad config value when parsing eNB configuration file %s, enb %d  srb1_max_retx_threshold %u!\n",
+                           RC.config_file_name, i, srb1_params.srb1_max_retx_threshold);
+            }
 
-		RRC_CONFIGURATION_REQ (msg_p).msg3_delta_Preamble[j] = msg3_delta_Preamble;
+            switch (srb1_params.srb1_poll_pdu) {
+            case 4:
+              rrc->srb1_poll_pdu = LTE_PollPDU_p4;
+              break;
 
-		if ((msg3_delta_Preamble<-1) || (msg3_delta_Preamble>6))
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for msg3_delta_Preamble choice: -1..6 !\n",
-			       RC.config_file_name, i, msg3_delta_Preamble);
-	      
-
-		if (strcmp(pucch_deltaF_Format1,"deltaF_2")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pucch_deltaF_Format1[j] = DeltaFList_PUCCH__deltaF_PUCCH_Format1_deltaF_2;
-		} else if (strcmp(pucch_deltaF_Format1,"deltaF0")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pucch_deltaF_Format1[j] = DeltaFList_PUCCH__deltaF_PUCCH_Format1_deltaF0;
-		} else if (strcmp(pucch_deltaF_Format1,"deltaF2")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pucch_deltaF_Format1[j] = DeltaFList_PUCCH__deltaF_PUCCH_Format1_deltaF2;
-		} else
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pucch_deltaF_Format1 choice: deltaF_2,dltaF0,deltaF2!\n",
-			       RC.config_file_name, i, pucch_deltaF_Format1);
-
-		if (strcmp(pucch_deltaF_Format1b,"deltaF1")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pucch_deltaF_Format1b[j] = DeltaFList_PUCCH__deltaF_PUCCH_Format1b_deltaF1;
-		} else if (strcmp(pucch_deltaF_Format1b,"deltaF3")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pucch_deltaF_Format1b[j] = DeltaFList_PUCCH__deltaF_PUCCH_Format1b_deltaF3;
-		} else if (strcmp(pucch_deltaF_Format1b,"deltaF5")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pucch_deltaF_Format1b[j] = DeltaFList_PUCCH__deltaF_PUCCH_Format1b_deltaF5;
-		} else
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pucch_deltaF_Format1b choice: deltaF1,dltaF3,deltaF5!\n",
-			       RC.config_file_name, i, pucch_deltaF_Format1b);
-
-
-		if (strcmp(pucch_deltaF_Format2,"deltaF_2")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pucch_deltaF_Format2[j] = DeltaFList_PUCCH__deltaF_PUCCH_Format2_deltaF_2;
-		} else if (strcmp(pucch_deltaF_Format2,"deltaF0")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pucch_deltaF_Format2[j] = DeltaFList_PUCCH__deltaF_PUCCH_Format2_deltaF0;
-		} else if (strcmp(pucch_deltaF_Format2,"deltaF1")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pucch_deltaF_Format2[j] = DeltaFList_PUCCH__deltaF_PUCCH_Format2_deltaF1;
-		} else if (strcmp(pucch_deltaF_Format2,"deltaF2")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pucch_deltaF_Format2[j] = DeltaFList_PUCCH__deltaF_PUCCH_Format2_deltaF2;
-		} else
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pucch_deltaF_Format2 choice: deltaF_2,dltaF0,deltaF1,deltaF2!\n",
-			       RC.config_file_name, i, pucch_deltaF_Format2);
-
-		if (strcmp(pucch_deltaF_Format2a,"deltaF_2")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pucch_deltaF_Format2a[j] = DeltaFList_PUCCH__deltaF_PUCCH_Format2a_deltaF_2;
-		} else if (strcmp(pucch_deltaF_Format2a,"deltaF0")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pucch_deltaF_Format2a[j] = DeltaFList_PUCCH__deltaF_PUCCH_Format2a_deltaF0;
-		} else if (strcmp(pucch_deltaF_Format2a,"deltaF2")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pucch_deltaF_Format2a[j] = DeltaFList_PUCCH__deltaF_PUCCH_Format2a_deltaF2;
-		} else
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pucch_deltaF_Format2a choice: deltaF_2,dltaF0,deltaF2!\n",
-			       RC.config_file_name, i, pucch_deltaF_Format2a);
-
-		if (strcmp(pucch_deltaF_Format2b,"deltaF_2")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pucch_deltaF_Format2b[j] = DeltaFList_PUCCH__deltaF_PUCCH_Format2b_deltaF_2;
-		} else if (strcmp(pucch_deltaF_Format2b,"deltaF0")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pucch_deltaF_Format2b[j] = DeltaFList_PUCCH__deltaF_PUCCH_Format2b_deltaF0;
-		} else if (strcmp(pucch_deltaF_Format2b,"deltaF2")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pucch_deltaF_Format2b[j] = DeltaFList_PUCCH__deltaF_PUCCH_Format2b_deltaF2;
-		} else
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pucch_deltaF_Format2b choice: deltaF_2,dltaF0,deltaF2!\n",
-			       RC.config_file_name, i, pucch_deltaF_Format2b);
+            case 8:
+              rrc->srb1_poll_pdu = LTE_PollPDU_p8;
+              break;
 
+            case 16:
+              rrc->srb1_poll_pdu = LTE_PollPDU_p16;
+              break;
 
-	      
+            case 32:
+              rrc->srb1_poll_pdu = LTE_PollPDU_p32;
+              break;
 
-		RRC_CONFIGURATION_REQ (msg_p).rach_numberOfRA_Preambles[j] = (rach_numberOfRA_Preambles/4)-1;
+            case 64:
+              rrc->srb1_poll_pdu = LTE_PollPDU_p64;
+              break;
 
-		if ((rach_numberOfRA_Preambles <4) || (rach_numberOfRA_Preambles>64) || ((rach_numberOfRA_Preambles&3)!=0))
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for rach_numberOfRA_Preambles choice: 4,8,12,...,64!\n",
-			       RC.config_file_name, i, rach_numberOfRA_Preambles);
-
-		if (strcmp(rach_preamblesGroupAConfig, "ENABLE") == 0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rach_preamblesGroupAConfig[j] = TRUE;
-
-
-		  RRC_CONFIGURATION_REQ (msg_p).rach_sizeOfRA_PreamblesGroupA[j] = (rach_sizeOfRA_PreamblesGroupA/4)-1;
-
-		  if ((rach_numberOfRA_Preambles <4) || (rach_numberOfRA_Preambles>60) || ((rach_numberOfRA_Preambles&3)!=0))
-		    AssertFatal (0,
-				 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for rach_sizeOfRA_PreamblesGroupA choice: 4,8,12,...,60!\n",
-				 RC.config_file_name, i, rach_sizeOfRA_PreamblesGroupA);
-
-
-		  switch (rach_messageSizeGroupA) {
-		  case 56:
-		    RRC_CONFIGURATION_REQ (msg_p).rach_messageSizeGroupA[j] = RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messageSizeGroupA_b56;
-		    break;
-
-		  case 144:
-		    RRC_CONFIGURATION_REQ (msg_p).rach_messageSizeGroupA[j] = RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messageSizeGroupA_b144;
-		    break;
-
-		  case 208:
-		    RRC_CONFIGURATION_REQ (msg_p).rach_messageSizeGroupA[j] = RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messageSizeGroupA_b208;
-		    break;
-
-		  case 256:
-		    RRC_CONFIGURATION_REQ (msg_p).rach_messageSizeGroupA[j] = RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messageSizeGroupA_b256;
-		    break;
-
-		  default:
-		    AssertFatal (0,
-				 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for rach_messageSizeGroupA choice: 56,144,208,256!\n",
-				 RC.config_file_name, i, rach_messageSizeGroupA);
-		    break;
-		  }
-
-		  if (strcmp(rach_messagePowerOffsetGroupB,"minusinfinity")==0) {
-		    RRC_CONFIGURATION_REQ (msg_p).rach_messagePowerOffsetGroupB[j] = RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messagePowerOffsetGroupB_minusinfinity;
-		  } else if (strcmp(rach_messagePowerOffsetGroupB,"dB0")==0) {
-		    RRC_CONFIGURATION_REQ (msg_p).rach_messagePowerOffsetGroupB[j] = RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messagePowerOffsetGroupB_dB0;
-		  } else if (strcmp(rach_messagePowerOffsetGroupB,"dB5")==0) {
-		    RRC_CONFIGURATION_REQ (msg_p).rach_messagePowerOffsetGroupB[j] = RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messagePowerOffsetGroupB_dB5;
-		  } else if (strcmp(rach_messagePowerOffsetGroupB,"dB8")==0) {
-		    RRC_CONFIGURATION_REQ (msg_p).rach_messagePowerOffsetGroupB[j] = RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messagePowerOffsetGroupB_dB8;
-		  } else if (strcmp(rach_messagePowerOffsetGroupB,"dB10")==0) {
-                    RRC_CONFIGURATION_REQ (msg_p).rach_messagePowerOffsetGroupB[j] = RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messagePowerOffsetGroupB_dB10;
-                  } else if (strcmp(rach_messagePowerOffsetGroupB,"dB12")==0) {
-                    RRC_CONFIGURATION_REQ (msg_p).rach_messagePowerOffsetGroupB[j] = RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messagePowerOffsetGroupB_dB12;
-                  } else if (strcmp(rach_messagePowerOffsetGroupB,"dB15")==0) {
-                    RRC_CONFIGURATION_REQ (msg_p).rach_messagePowerOffsetGroupB[j] = RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messagePowerOffsetGroupB_dB15;
-                  } else if (strcmp(rach_messagePowerOffsetGroupB,"dB18")==0) {
-                    RRC_CONFIGURATION_REQ (msg_p).rach_messagePowerOffsetGroupB[j] = RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messagePowerOffsetGroupB_dB18;
-                  } else
-                    AssertFatal (0,
-                                 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for rach_messagePowerOffsetGroupB choice: minusinfinity,dB0,dB5,dB8,dB10,dB12,dB15,dB18!\n",
-                                 RC.config_file_name, i, rach_messagePowerOffsetGroupB);
-
-                } else if (strcmp(rach_preamblesGroupAConfig, "DISABLE") == 0) {
-                  RRC_CONFIGURATION_REQ (msg_p).rach_preamblesGroupAConfig[j] = FALSE;
-                } else
-                  AssertFatal (0,
-                               "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for rach_preamblesGroupAConfig choice: ENABLE,DISABLE !\n",
-                               RC.config_file_name, i, rach_preamblesGroupAConfig);
+            case 128:
+              rrc->srb1_poll_pdu = LTE_PollPDU_p128;
+              break;
 
-            RRC_CONFIGURATION_REQ (msg_p).rach_preambleInitialReceivedTargetPower[j] = (rach_preambleInitialReceivedTargetPower+120)/2;
+            case 256:
+              rrc->srb1_poll_pdu = LTE_PollPDU_p256;
+              break;
 
-            if ((rach_preambleInitialReceivedTargetPower<-120) || (rach_preambleInitialReceivedTargetPower>-90) || ((rach_preambleInitialReceivedTargetPower&1)!=0))
-              AssertFatal (0,
-                           "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for rach_preambleInitialReceivedTargetPower choice: -120,-118,...,-90 !\n",
-                           RC.config_file_name, i, rach_preambleInitialReceivedTargetPower);
+            default:
+              if (srb1_params.srb1_poll_pdu >= 10000)
+                rrc->srb1_poll_pdu = LTE_PollPDU_pInfinity;
+              else
+                AssertFatal (0,
+                             "Bad config value when parsing eNB configuration file %s, enb %d  srb1_poll_pdu %u!\n",
+                             RC.config_file_name, i, srb1_params.srb1_poll_pdu);
+            }
 
-            RRC_CONFIGURATION_REQ (msg_p).rach_powerRampingStep[j] = rach_powerRampingStep/2;
+            rrc->srb1_poll_byte             = srb1_params.srb1_poll_byte;
 
-            if ((rach_powerRampingStep<0) || (rach_powerRampingStep>6) || ((rach_powerRampingStep&1)!=0))
-              AssertFatal (0,
-                           "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for rach_powerRampingStep choice: 0,2,4,6 !\n",
-                           RC.config_file_name, i, rach_powerRampingStep);
+            switch (srb1_params.srb1_poll_byte) {
+            case 25:
+              rrc->srb1_poll_byte = LTE_PollByte_kB25;
+              break;
 
-            switch (rach_preambleTransMax) {
-#if (RRC_VERSION < MAKE_VERSION(14, 0, 0))
+            case 50:
+              rrc->srb1_poll_byte = LTE_PollByte_kB50;
+              break;
 
-              case 3:
-                RRC_CONFIGURATION_REQ (msg_p).rach_preambleTransMax[j] =  RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n3;
-                break;
+            case 75:
+              rrc->srb1_poll_byte = LTE_PollByte_kB75;
+              break;
 
-              case 4:
-                RRC_CONFIGURATION_REQ (msg_p).rach_preambleTransMax[j] =  RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n4;
-                break;
+            case 100:
+              rrc->srb1_poll_byte = LTE_PollByte_kB100;
+              break;
 
-              case 5:
-                RRC_CONFIGURATION_REQ (msg_p).rach_preambleTransMax[j] =  RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n5;
-                break;
+            case 125:
+              rrc->srb1_poll_byte = LTE_PollByte_kB125;
+              break;
 
-              case 6:
-                RRC_CONFIGURATION_REQ (msg_p).rach_preambleTransMax[j] =  RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n6;
-                break;
+            case 250:
+              rrc->srb1_poll_byte = LTE_PollByte_kB250;
+              break;
 
-              case 7:
-                RRC_CONFIGURATION_REQ (msg_p).rach_preambleTransMax[j] =  RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n7;
-                break;
+            case 375:
+              rrc->srb1_poll_byte = LTE_PollByte_kB375;
+              break;
 
-              case 8:
-                RRC_CONFIGURATION_REQ (msg_p).rach_preambleTransMax[j] =  RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n8;
-                break;
+            case 500:
+              rrc->srb1_poll_byte = LTE_PollByte_kB500;
+              break;
 
-              case 10:
-                RRC_CONFIGURATION_REQ (msg_p).rach_preambleTransMax[j] =  RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n10;
-                break;
+            case 750:
+              rrc->srb1_poll_byte = LTE_PollByte_kB750;
+              break;
 
-              case 20:
-                RRC_CONFIGURATION_REQ (msg_p).rach_preambleTransMax[j] =  RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n20;
-                break;
+            case 1000:
+              rrc->srb1_poll_byte = LTE_PollByte_kB1000;
+              break;
 
-              case 50:
-                RRC_CONFIGURATION_REQ (msg_p).rach_preambleTransMax[j] =  RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n50;
-                break;
+            case 1250:
+              rrc->srb1_poll_byte = LTE_PollByte_kB1250;
+              break;
 
-              case 100:
-                RRC_CONFIGURATION_REQ (msg_p).rach_preambleTransMax[j] =  RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n100;
-                break;
+            case 1500:
+              rrc->srb1_poll_byte = LTE_PollByte_kB1500;
+              break;
 
-              case 200:
-                RRC_CONFIGURATION_REQ (msg_p).rach_preambleTransMax[j] =  RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n200;
-                break;
-#else
+            case 2000:
+              rrc->srb1_poll_byte = LTE_PollByte_kB2000;
+              break;
 
-              case 3:
-                RRC_CONFIGURATION_REQ (msg_p).rach_preambleTransMax[j] =  PreambleTransMax_n3;
-                break;
+            case 3000:
+              rrc->srb1_poll_byte = LTE_PollByte_kB3000;
+              break;
 
-              case 4:
-                RRC_CONFIGURATION_REQ (msg_p).rach_preambleTransMax[j] =  PreambleTransMax_n4;
-                break;
+            default:
+              if (srb1_params.srb1_poll_byte >= 10000)
+                rrc->srb1_poll_byte = LTE_PollByte_kBinfinity;
+              else
+                AssertFatal (0,
+                             "Bad config value when parsing eNB configuration file %s, enb %d  srb1_poll_byte %u!\n",
+                             RC.config_file_name, i, srb1_params.srb1_poll_byte);
+            }
 
-              case 5:
-                RRC_CONFIGURATION_REQ (msg_p).rach_preambleTransMax[j] =  PreambleTransMax_n5;
-                break;
+            if (srb1_params.srb1_timer_poll_retransmit <= 250) {
+              rrc->srb1_timer_poll_retransmit = (srb1_params.srb1_timer_poll_retransmit - 5)/5;
+            } else if (srb1_params.srb1_timer_poll_retransmit <= 500) {
+              rrc->srb1_timer_poll_retransmit = (srb1_params.srb1_timer_poll_retransmit - 300)/50 + 50;
+            } else {
+              AssertFatal (0,
+                           "Bad config value when parsing eNB configuration file %s, enb %d  srb1_timer_poll_retransmit %u!\n",
+                           RC.config_file_name, i, srb1_params.srb1_timer_poll_retransmit);
+            }
 
-              case 6:
-                RRC_CONFIGURATION_REQ (msg_p).rach_preambleTransMax[j] =  PreambleTransMax_n6;
-                break;
+            if (srb1_params.srb1_timer_status_prohibit <= 250) {
+              rrc->srb1_timer_status_prohibit = srb1_params.srb1_timer_status_prohibit/5;
+            } else if ((srb1_params.srb1_timer_poll_retransmit >= 300) && (srb1_params.srb1_timer_poll_retransmit <= 500)) {
+              rrc->srb1_timer_status_prohibit = (srb1_params.srb1_timer_status_prohibit - 300)/50 + 51;
+            } else {
+              AssertFatal (0,
+                           "Bad config value when parsing eNB configuration file %s, enb %d  srb1_timer_status_prohibit %u!\n",
+                           RC.config_file_name, i, srb1_params.srb1_timer_status_prohibit);
+            }
 
-              case 7:
-                RRC_CONFIGURATION_REQ (msg_p).rach_preambleTransMax[j] =  PreambleTransMax_n7;
-                break;
+            switch (srb1_params.srb1_timer_reordering) {
+            case 0:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms0;
+              break;
 
-              case 8:
-                RRC_CONFIGURATION_REQ (msg_p).rach_preambleTransMax[j] =  PreambleTransMax_n8;
-                break;
+            case 5:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms5;
+              break;
 
-              case 10:
-                RRC_CONFIGURATION_REQ (msg_p).rach_preambleTransMax[j] =  PreambleTransMax_n10;
-                break;
+            case 10:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms10;
+              break;
 
-              case 20:
-                RRC_CONFIGURATION_REQ (msg_p).rach_preambleTransMax[j] =  PreambleTransMax_n20;
-                break;
+            case 15:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms15;
+              break;
 
-              case 50:
-                RRC_CONFIGURATION_REQ (msg_p).rach_preambleTransMax[j] =  PreambleTransMax_n50;
-                break;
+            case 20:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms20;
+              break;
 
-              case 100:
-                RRC_CONFIGURATION_REQ (msg_p).rach_preambleTransMax[j] =  PreambleTransMax_n100;
-                break;
+            case 25:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms25;
+              break;
 
-              case 200:
-                RRC_CONFIGURATION_REQ (msg_p).rach_preambleTransMax[j] =  PreambleTransMax_n200;
-                break;
-#endif
+            case 30:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms30;
+              break;
 
-		default:
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for rach_preambleTransMax choice: 3,4,5,6,7,8,10,20,50,100,200!\n",
-			       RC.config_file_name, i, rach_preambleTransMax);
-		  break;
-		}
+            case 35:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms35;
+              break;
 
-		RRC_CONFIGURATION_REQ (msg_p).rach_raResponseWindowSize[j] =  (rach_raResponseWindowSize==10)?7:rach_raResponseWindowSize-2;
+            case 40:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms40;
+              break;
 
-		if ((rach_raResponseWindowSize<0)||(rach_raResponseWindowSize==9)||(rach_raResponseWindowSize>10))
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for rach_raResponseWindowSize choice: 2,3,4,5,6,7,8,10!\n",
-			       RC.config_file_name, i, rach_preambleTransMax);
+            case 45:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms45;
+              break;
 
+            case 50:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms50;
+              break;
 
-		RRC_CONFIGURATION_REQ (msg_p).rach_macContentionResolutionTimer[j] = (rach_macContentionResolutionTimer/8)-1;
+            case 55:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms55;
+              break;
 
-		if ((rach_macContentionResolutionTimer<8) || (rach_macContentionResolutionTimer>64) || ((rach_macContentionResolutionTimer&7)!=0))
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for rach_macContentionResolutionTimer choice: 8,16,...,56,64!\n",
-			       RC.config_file_name, i, rach_preambleTransMax);
+            case 60:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms60;
+              break;
 
-		RRC_CONFIGURATION_REQ (msg_p).rach_maxHARQ_Msg3Tx[j] = rach_maxHARQ_Msg3Tx;
+            case 65:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms65;
+              break;
 
-		if ((rach_maxHARQ_Msg3Tx<0) || (rach_maxHARQ_Msg3Tx>8))
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for rach_maxHARQ_Msg3Tx choice: 1..8!\n",
-			       RC.config_file_name, i, rach_preambleTransMax);
+            case 70:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms70;
+              break;
 
+            case 75:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms75;
+              break;
 
-		switch (pcch_defaultPagingCycle) {
-		case 32:
-		  RRC_CONFIGURATION_REQ (msg_p).pcch_defaultPagingCycle[j] = PCCH_Config__defaultPagingCycle_rf32;
-		  break;
+            case 80:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms80;
+              break;
 
-		case 64:
-		  RRC_CONFIGURATION_REQ (msg_p).pcch_defaultPagingCycle[j] = PCCH_Config__defaultPagingCycle_rf64;
-		  break;
+            case 85:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms85;
+              break;
 
-		case 128:
-		  RRC_CONFIGURATION_REQ (msg_p).pcch_defaultPagingCycle[j] = PCCH_Config__defaultPagingCycle_rf128;
-		  break;
+            case 90:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms90;
+              break;
 
-		case 256:
-		  RRC_CONFIGURATION_REQ (msg_p).pcch_defaultPagingCycle[j] = PCCH_Config__defaultPagingCycle_rf256;
-		  break;
+            case 95:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms95;
+              break;
 
-		default:
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pcch_defaultPagingCycle choice: 32,64,128,256!\n",
-			       RC.config_file_name, i, pcch_defaultPagingCycle);
-		  break;
-		}
+            case 100:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms100;
+              break;
 
-		if (strcmp(pcch_nB, "fourT") == 0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pcch_nB[j] = PCCH_Config__nB_fourT;
-		} else if (strcmp(pcch_nB, "twoT") == 0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pcch_nB[j] = PCCH_Config__nB_twoT;
-		} else if (strcmp(pcch_nB, "oneT") == 0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pcch_nB[j] = PCCH_Config__nB_oneT;
-		} else if (strcmp(pcch_nB, "halfT") == 0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pcch_nB[j] = PCCH_Config__nB_halfT;
-		} else if (strcmp(pcch_nB, "quarterT") == 0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pcch_nB[j] = PCCH_Config__nB_quarterT;
-		} else if (strcmp(pcch_nB, "oneEighthT") == 0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pcch_nB[j] = PCCH_Config__nB_oneEighthT;
-		} else if (strcmp(pcch_nB, "oneSixteenthT") == 0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pcch_nB[j] = PCCH_Config__nB_oneSixteenthT;
-		} else if (strcmp(pcch_nB, "oneThirtySecondT") == 0) {
-		  RRC_CONFIGURATION_REQ (msg_p).pcch_nB[j] = PCCH_Config__nB_oneThirtySecondT;
-		} else
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pcch_nB choice: fourT,twoT,oneT,halfT,quarterT,oneighthT,oneSixteenthT,oneThirtySecondT !\n",
-			       RC.config_file_name, i, pcch_defaultPagingCycle);
+            case 110:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms110;
+              break;
 
+            case 120:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms120;
+              break;
 
+            case 130:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms130;
+              break;
 
-		switch (bcch_modificationPeriodCoeff) {
-		case 2:
-		  RRC_CONFIGURATION_REQ (msg_p).bcch_modificationPeriodCoeff[j] = BCCH_Config__modificationPeriodCoeff_n2;
-		  break;
+            case 140:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms140;
+              break;
 
-		case 4:
-		  RRC_CONFIGURATION_REQ (msg_p).bcch_modificationPeriodCoeff[j] = BCCH_Config__modificationPeriodCoeff_n4;
-		  break;
+            case 150:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms150;
+              break;
 
-		case 8:
-		  RRC_CONFIGURATION_REQ (msg_p).bcch_modificationPeriodCoeff[j] = BCCH_Config__modificationPeriodCoeff_n8;
-		  break;
+            case 160:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms160;
+              break;
 
-		case 16:
-		  RRC_CONFIGURATION_REQ (msg_p).bcch_modificationPeriodCoeff[j] = BCCH_Config__modificationPeriodCoeff_n16;
-		  break;
+            case 170:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms170;
+              break;
 
-		default:
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for bcch_modificationPeriodCoeff choice: 2,4,8,16",
-			       RC.config_file_name, i, bcch_modificationPeriodCoeff);
+            case 180:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms180;
+              break;
 
-		  break;
-		}
+            case 190:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms190;
+              break;
 
-                
-                RRC_CONFIGURATION_REQ (msg_p).ue_TimersAndConstants_t300[j] = ue_TimersAndConstants_t300;
-                RRC_CONFIGURATION_REQ (msg_p).ue_TimersAndConstants_t301[j] = ue_TimersAndConstants_t301;
-                RRC_CONFIGURATION_REQ (msg_p).ue_TimersAndConstants_t310[j] = ue_TimersAndConstants_t310;
-                RRC_CONFIGURATION_REQ (msg_p).ue_TimersAndConstants_t311[j] = ue_TimersAndConstants_t311;
-                RRC_CONFIGURATION_REQ (msg_p).ue_TimersAndConstants_n310[j] = ue_TimersAndConstants_n310;
-                RRC_CONFIGURATION_REQ (msg_p).ue_TimersAndConstants_n311[j] = ue_TimersAndConstants_n311;
-
-		switch (ue_TransmissionMode) {
-		case 1:
-		  RRC_CONFIGURATION_REQ (msg_p).ue_TransmissionMode[j] = AntennaInfoDedicated__transmissionMode_tm1;
-		  break;
-		case 2:
-		  RRC_CONFIGURATION_REQ (msg_p).ue_TransmissionMode[j] = AntennaInfoDedicated__transmissionMode_tm2;
-		  break;
-		case 3:
-		  RRC_CONFIGURATION_REQ (msg_p).ue_TransmissionMode[j] = AntennaInfoDedicated__transmissionMode_tm3;
-		  break;
-		case 4:
-		  RRC_CONFIGURATION_REQ (msg_p).ue_TransmissionMode[j] = AntennaInfoDedicated__transmissionMode_tm4;
-		  break;
-		case 5:
-		  RRC_CONFIGURATION_REQ (msg_p).ue_TransmissionMode[j] = AntennaInfoDedicated__transmissionMode_tm5;
-		  break;
-		case 6:
-		  RRC_CONFIGURATION_REQ (msg_p).ue_TransmissionMode[j] = AntennaInfoDedicated__transmissionMode_tm6;
-		  break;
-		case 7:
-		  RRC_CONFIGURATION_REQ (msg_p).ue_TransmissionMode[j] = AntennaInfoDedicated__transmissionMode_tm7;
-		  break;
-		default:
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for ue_TransmissionMode choice: 1,2,3,4,5,6,7",
-			       RC.config_file_name, i, ue_TransmissionMode);
-		  break;
-		}
+            case 200:
+              rrc->srb1_timer_reordering = LTE_T_Reordering_ms200;
+              break;
 
-		RRC_CONFIGURATION_REQ (msg_p).ue_multiple_max[j] = ue_multiple_max;
-
-		switch (N_RB_DL) {
-		case 25:
-		  if ((ue_multiple_max < 1) || (ue_multiple_max > 4))
-		    AssertFatal (0,
-				 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for ue_multiple_max choice: 1..4!\n",
-				 RC.config_file_name, i, ue_multiple_max);
-		  break;
-		case 50:
-		  if ((ue_multiple_max < 1) || (ue_multiple_max > 8))
-		    AssertFatal (0,
-				 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for ue_multiple_max choice: 1..8!\n",
-				 RC.config_file_name, i, ue_multiple_max);
-		  break;
-		case 100:
-		  if ((ue_multiple_max < 1) || (ue_multiple_max > 16))
-		    AssertFatal (0,
-				 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for ue_multiple_max choice: 1..16!\n",
-				 RC.config_file_name, i, ue_multiple_max);
-		  break;
-		default:
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for N_RB_DL choice: 25,50,100 !\n",
-			       RC.config_file_name, i, N_RB_DL);
-		  break;
-		}
-	      		
-		//TTN - for D2D
-		//SIB18
-		if (strcmp(rxPool_sc_CP_Len,"normal")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_CP_Len[j] = SL_CP_Len_r12_normal;
-		} else if (strcmp(rxPool_sc_CP_Len,"extended")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_CP_Len[j] = SL_CP_Len_r12_extended;
-		} else
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for rxPool_sc_CP_Len choice: normal,extended!\n",
-			       RC.config_file_name, i, rxPool_sc_CP_Len);
-		
-		if (strcmp(rxPool_sc_Period,"sf40")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[j] = SL_PeriodComm_r12_sf40;
-		} else if (strcmp(rxPool_sc_Period,"sf60")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[j] = SL_PeriodComm_r12_sf60;
-		} else if (strcmp(rxPool_sc_Period,"sf70")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[j] = SL_PeriodComm_r12_sf70;
-		} else if (strcmp(rxPool_sc_Period,"sf80")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[j] = SL_PeriodComm_r12_sf80;
-		} else if (strcmp(rxPool_sc_Period,"sf120")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[j] = SL_PeriodComm_r12_sf120;
-		} else if (strcmp(rxPool_sc_Period,"sf140")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[j] = SL_PeriodComm_r12_sf140;
-		} else if (strcmp(rxPool_sc_Period,"sf160")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[j] = SL_PeriodComm_r12_sf160;
-		} else if (strcmp(rxPool_sc_Period,"sf240")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[j] = SL_PeriodComm_r12_sf240;
-		} else if (strcmp(rxPool_sc_Period,"sf280")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[j] = SL_PeriodComm_r12_sf280;
-		} else if (strcmp(rxPool_sc_Period,"sf320")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[j] = SL_PeriodComm_r12_sf320;
-		} else if (strcmp(rxPool_sc_Period,"spare6")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[j] = SL_PeriodComm_r12_spare6;
-		} else if (strcmp(rxPool_sc_Period,"spare5")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[j] = SL_PeriodComm_r12_spare5;
-		} else if (strcmp(rxPool_sc_Period,"spare4")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[j] = SL_PeriodComm_r12_spare4;
-		} else if (strcmp(rxPool_sc_Period,"spare3")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[j] = SL_PeriodComm_r12_spare3;
-		} else if (strcmp(rxPool_sc_Period,"spare2")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[j] = SL_PeriodComm_r12_spare2;
-		} else if (strcmp(rxPool_sc_Period,"spare")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[j] = SL_PeriodComm_r12_spare;
-		} else
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for rxPool_sc_Period choice: sf40,sf60,sf70,sf80,sf120,sf140,sf160,sf240,sf280,sf320,spare6,spare5,spare4,spare3,spare2,spare!\n",
-			       RC.config_file_name, i, rxPool_sc_Period);
-		
-		if (strcmp(rxPool_data_CP_Len,"normal")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_data_CP_Len[j] = SL_CP_Len_r12_normal;
-		} else if (strcmp(rxPool_data_CP_Len,"extended")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_data_CP_Len[j] = SL_CP_Len_r12_extended;
-		} else
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for rxPool_data_CP_Len choice: normal,extended!\n",
-			       RC.config_file_name, i, rxPool_data_CP_Len);
-		
-		RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_prb_Num[j] = rxPool_ResourceConfig_prb_Num;
-		RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_prb_Start[j] = rxPool_ResourceConfig_prb_Start;
-		RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_prb_End[j] = rxPool_ResourceConfig_prb_End;
-		
-		if (strcmp(rxPool_ResourceConfig_offsetIndicator_present,"prNothing")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_offsetIndicator_present[j] = SL_OffsetIndicator_r12_PR_NOTHING;
-		} else if (strcmp(rxPool_ResourceConfig_offsetIndicator_present,"prSmall")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_offsetIndicator_present[j] = SL_OffsetIndicator_r12_PR_small_r12;
-		} else if (strcmp(rxPool_ResourceConfig_offsetIndicator_present,"prLarge")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_offsetIndicator_present[j] = SL_OffsetIndicator_r12_PR_large_r12;
-		} else
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for rxPool_ResourceConfig_offsetIndicator_present choice: prNothing,prSmal,prLarge!\n",
-			       RC.config_file_name, i, rxPool_ResourceConfig_offsetIndicator_present);
-		
-		RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_offsetIndicator_choice[j] = rxPool_ResourceConfig_offsetIndicator_choice;
-		
-		if (strcmp(rxPool_ResourceConfig_subframeBitmap_present,"prNothing")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_subframeBitmap_present[j] = SubframeBitmapSL_r12_PR_NOTHING;
-		} else if (strcmp(rxPool_ResourceConfig_subframeBitmap_present,"prBs4")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_subframeBitmap_present[j] = SubframeBitmapSL_r12_PR_bs4_r12;
-		} else if (strcmp(rxPool_ResourceConfig_subframeBitmap_present,"prBs8")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_subframeBitmap_present[j] = SubframeBitmapSL_r12_PR_bs8_r12;
-		} else if (strcmp(rxPool_ResourceConfig_subframeBitmap_present,"prBs12")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_subframeBitmap_present[j] = SubframeBitmapSL_r12_PR_bs12_r12;
-		} else if (strcmp(rxPool_ResourceConfig_subframeBitmap_present,"prBs16")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_subframeBitmap_present[j] = SubframeBitmapSL_r12_PR_bs16_r12;
-		} else if (strcmp(rxPool_ResourceConfig_subframeBitmap_present,"prBs30")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_subframeBitmap_present[j] = SubframeBitmapSL_r12_PR_bs30_r12;
-		} else if (strcmp(rxPool_ResourceConfig_subframeBitmap_present,"prBs40")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_subframeBitmap_present[j] = SubframeBitmapSL_r12_PR_bs40_r12;
-		} else if (strcmp(rxPool_ResourceConfig_subframeBitmap_present,"prBs42")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_subframeBitmap_present[j] = SubframeBitmapSL_r12_PR_bs42_r12;
-		} else
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for rxPool_ResourceConfig_subframeBitmap_present choice: prNothing,prBs4,prBs8,prBs12,prBs16,prBs30,prBs40,prBs42!\n",
-			       RC.config_file_name, i, rxPool_ResourceConfig_subframeBitmap_present);
-		
-		RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_subframeBitmap_choice_bs_buf[j] = rxPool_ResourceConfig_subframeBitmap_choice_bs_buf;
-		RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_subframeBitmap_choice_bs_size[j] = rxPool_ResourceConfig_subframeBitmap_choice_bs_size;
-		RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[j] = rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused;
-		
-		//SIB19 - for discRxPool
-		if (strcmp(discRxPool_cp_Len,"normal")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPool_cp_Len[j] = SL_CP_Len_r12_normal;
-		} else if (strcmp(discRxPool_cp_Len,"extended")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPool_cp_Len[j] = SL_CP_Len_r12_extended;
-		} else
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for discRxPool_cp_Len choice: normal,extended!\n",
-			       RC.config_file_name, i, discRxPool_cp_Len);
-		
-		
-		if (strcmp(discRxPool_discPeriod,"rf32")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPool_discPeriod[j] = SL_DiscResourcePool_r12__discPeriod_r12_rf32;
-		} else if (strcmp(discRxPool_discPeriod,"rf64")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPool_discPeriod[j] = SL_DiscResourcePool_r12__discPeriod_r12_rf64;
-		} else if (strcmp(discRxPool_discPeriod,"rf128")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPool_discPeriod[j] = SL_DiscResourcePool_r12__discPeriod_r12_rf128;
-		} else if (strcmp(discRxPool_discPeriod,"rf256")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPool_discPeriod[j] = SL_DiscResourcePool_r12__discPeriod_r12_rf256;
-		} else if (strcmp(discRxPool_discPeriod,"rf512")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPool_discPeriod[j] = SL_DiscResourcePool_r12__discPeriod_r12_rf512;
-		} else if (strcmp(discRxPool_discPeriod,"rf1024")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPool_discPeriod[j] = SL_DiscResourcePool_r12__discPeriod_r12_rf1024;
-		} else if (strcmp(discRxPool_discPeriod,"rf16")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPool_discPeriod[j] = SL_DiscResourcePool_r12__discPeriod_r12_rf16_v1310;
-		} else if (strcmp(discRxPool_discPeriod,"spare")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPool_discPeriod[j] = SL_DiscResourcePool_r12__discPeriod_r12_spare;
-		} else
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for discRxPool_discPeriod choice: rf32,rf64,rf128,rf512,rf1024,rf16,spare!\n",
-			       RC.config_file_name, i, discRxPool_discPeriod);
-		
-	      		
-		
-		RRC_CONFIGURATION_REQ (msg_p).discRxPool_numRetx[j] = discRxPool_numRetx;
-		RRC_CONFIGURATION_REQ (msg_p).discRxPool_numRepetition[j] = discRxPool_numRepetition;
-		
-		
-		RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_prb_Num[j] = discRxPool_ResourceConfig_prb_Num;
-		RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_prb_Start[j] = discRxPool_ResourceConfig_prb_Start;
-		RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_prb_End[j] = discRxPool_ResourceConfig_prb_End;
-		
-		if (strcmp(discRxPool_ResourceConfig_offsetIndicator_present,"prNothing")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_offsetIndicator_present[j] = SL_OffsetIndicator_r12_PR_NOTHING;
-		} else if (strcmp(discRxPool_ResourceConfig_offsetIndicator_present,"prSmall")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_offsetIndicator_present[j] = SL_OffsetIndicator_r12_PR_small_r12;
-		} else if (strcmp(discRxPool_ResourceConfig_offsetIndicator_present,"prLarge")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_offsetIndicator_present[j] = SL_OffsetIndicator_r12_PR_large_r12;
-		} else
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for discRxPool_ResourceConfig_offsetIndicator_present choice: prNothing,prSmal,prLarge!\n",
-			       RC.config_file_name, i, discRxPool_ResourceConfig_offsetIndicator_present);
-		
-		RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_offsetIndicator_choice[j] = discRxPool_ResourceConfig_offsetIndicator_choice;
-		
-		if (strcmp(discRxPool_ResourceConfig_subframeBitmap_present,"prNothing")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_subframeBitmap_present[j] = SubframeBitmapSL_r12_PR_NOTHING;
-		} else if (strcmp(discRxPool_ResourceConfig_subframeBitmap_present,"prBs4")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_subframeBitmap_present[j] = SubframeBitmapSL_r12_PR_bs4_r12;
-		} else if (strcmp(discRxPool_ResourceConfig_subframeBitmap_present,"prBs8")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_subframeBitmap_present[j] = SubframeBitmapSL_r12_PR_bs8_r12;
-		} else if (strcmp(discRxPool_ResourceConfig_subframeBitmap_present,"prBs12")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_subframeBitmap_present[j] = SubframeBitmapSL_r12_PR_bs12_r12;
-		} else if (strcmp(discRxPool_ResourceConfig_subframeBitmap_present,"prBs16")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_subframeBitmap_present[j] = SubframeBitmapSL_r12_PR_bs16_r12;
-		} else if (strcmp(discRxPool_ResourceConfig_subframeBitmap_present,"prBs30")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_subframeBitmap_present[j] = SubframeBitmapSL_r12_PR_bs30_r12;
-		} else if (strcmp(discRxPool_ResourceConfig_subframeBitmap_present,"prBs40")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_subframeBitmap_present[j] = SubframeBitmapSL_r12_PR_bs40_r12;
-		} else if (strcmp(discRxPool_ResourceConfig_subframeBitmap_present,"prBs42")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_subframeBitmap_present[j] = SubframeBitmapSL_r12_PR_bs42_r12;
-		} else
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for discRxPool_ResourceConfig_subframeBitmap_present choice: prNothing,prBs4,prBs8,prBs12,prBs16,prBs30,prBs40,prBs42!\n",
-			       RC.config_file_name, i, discRxPool_ResourceConfig_subframeBitmap_present);
-		
-		RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf[j] = discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf;
-		RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_subframeBitmap_choice_bs_size[j] = discRxPool_ResourceConfig_subframeBitmap_choice_bs_size;
-		RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[j] = discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused;
-		
-		//SIB19 - For discRxPoolPS
-		if (strcmp(discRxPoolPS_cp_Len,"normal")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_cp_Len[j] = SL_CP_Len_r12_normal;
-		} else if (strcmp(discRxPoolPS_cp_Len,"extended")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_cp_Len[j] = SL_CP_Len_r12_extended;
-		} else
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for discRxPoolPS_cp_Len choice: normal,extended!\n",
-			       RC.config_file_name, i, discRxPoolPS_cp_Len);
-		
-		
-		if (strcmp(discRxPoolPS_discPeriod,"rf32")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_discPeriod[j] = SL_DiscResourcePool_r12__discPeriod_r12_rf32;
-		} else if (strcmp(discRxPoolPS_discPeriod,"rf64")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_discPeriod[j] = SL_DiscResourcePool_r12__discPeriod_r12_rf64;
-		} else if (strcmp(discRxPoolPS_discPeriod,"rf128")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_discPeriod[j] = SL_DiscResourcePool_r12__discPeriod_r12_rf128;
-		} else if (strcmp(discRxPoolPS_discPeriod,"rf256")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_discPeriod[j] = SL_DiscResourcePool_r12__discPeriod_r12_rf256;
-		} else if (strcmp(discRxPoolPS_discPeriod,"rf512")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_discPeriod[j] = SL_DiscResourcePool_r12__discPeriod_r12_rf512;
-		} else if (strcmp(discRxPoolPS_discPeriod,"rf1024")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_discPeriod[j] = SL_DiscResourcePool_r12__discPeriod_r12_rf1024;
-		} else if (strcmp(discRxPoolPS_discPeriod,"rf16")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_discPeriod[j] = SL_DiscResourcePool_r12__discPeriod_r12_rf16_v1310;
-		} else if (strcmp(discRxPoolPS_discPeriod,"spare")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_discPeriod[j] = SL_DiscResourcePool_r12__discPeriod_r12_spare;
-		} else
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for discRxPoolPS_discPeriod choice: rf32,rf64,rf128,rf512,rf1024,rf16,spare!\n",
-			       RC.config_file_name, i, discRxPoolPS_discPeriod);
-		
-		
-		
-		RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_numRetx[j] = discRxPoolPS_numRetx;
-		RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_numRepetition[j] = discRxPoolPS_numRepetition;
-		
-		
-		RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_prb_Num[j] = discRxPoolPS_ResourceConfig_prb_Num;
-		RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_prb_Start[j] = discRxPoolPS_ResourceConfig_prb_Start;
-		RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_prb_End[j] = discRxPoolPS_ResourceConfig_prb_End;
-		
-		if (strcmp(discRxPoolPS_ResourceConfig_offsetIndicator_present,"prNothing")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_offsetIndicator_present[j] = SL_OffsetIndicator_r12_PR_NOTHING;
-		} else if (strcmp(discRxPoolPS_ResourceConfig_offsetIndicator_present,"prSmall")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_offsetIndicator_present[j] = SL_OffsetIndicator_r12_PR_small_r12;
-		} else if (strcmp(discRxPoolPS_ResourceConfig_offsetIndicator_present,"prLarge")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_offsetIndicator_present[j] = SL_OffsetIndicator_r12_PR_large_r12;
-		} else
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for discRxPoolPS_ResourceConfig_offsetIndicator_present choice: prNothing,prSmal,prLarge!\n",
-			       RC.config_file_name, i, discRxPoolPS_ResourceConfig_offsetIndicator_present);
-		
-		RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_offsetIndicator_choice[j] = discRxPoolPS_ResourceConfig_offsetIndicator_choice;
-		
-		if (strcmp(discRxPoolPS_ResourceConfig_subframeBitmap_present,"prNothing")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_subframeBitmap_present[j] = SubframeBitmapSL_r12_PR_NOTHING;
-		} else if (strcmp(discRxPoolPS_ResourceConfig_subframeBitmap_present,"prBs4")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_subframeBitmap_present[j] = SubframeBitmapSL_r12_PR_bs4_r12;
-		} else if (strcmp(discRxPoolPS_ResourceConfig_subframeBitmap_present,"prBs8")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_subframeBitmap_present[j] = SubframeBitmapSL_r12_PR_bs8_r12;
-		} else if (strcmp(discRxPoolPS_ResourceConfig_subframeBitmap_present,"prBs12")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_subframeBitmap_present[j] = SubframeBitmapSL_r12_PR_bs12_r12;
-		} else if (strcmp(discRxPoolPS_ResourceConfig_subframeBitmap_present,"prBs16")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_subframeBitmap_present[j] = SubframeBitmapSL_r12_PR_bs16_r12;
-		} else if (strcmp(discRxPoolPS_ResourceConfig_subframeBitmap_present,"prBs30")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_subframeBitmap_present[j] = SubframeBitmapSL_r12_PR_bs30_r12;
-		} else if (strcmp(discRxPoolPS_ResourceConfig_subframeBitmap_present,"prBs40")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_subframeBitmap_present[j] = SubframeBitmapSL_r12_PR_bs40_r12;
-		} else if (strcmp(discRxPoolPS_ResourceConfig_subframeBitmap_present,"prBs42")==0) {
-		  RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_subframeBitmap_present[j] = SubframeBitmapSL_r12_PR_bs42_r12;
-		} else
-		  AssertFatal (0,
-			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for discRxPoolPS_ResourceConfig_subframeBitmap_present choice: prNothing,prBs4,prBs8,prBs12,prBs16,prBs30,prBs40,prBs42!\n",
-			       RC.config_file_name, i, discRxPoolPS_ResourceConfig_subframeBitmap_present);
-		
-		RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_buf[j] = discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_buf;
-		RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_size[j] = discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_size;
-		RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_bits_unused[j] = discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_bits_unused;
-		
-		
-	      } // node_type!=ngran_eNB_DU
-	    }
-	    if ( (rrc->node_type == ngran_eNB_CU) || (rrc->node_type == ngran_ng_eNB_CU) || (rrc->node_type == ngran_gNB_CU) ) {
-	      char srb1path[MAX_OPTNAME_SIZE*2 + 8];
-	      sprintf(srb1path,"%s.%s",enbpath,ENB_CONFIG_STRING_SRB1);
-	      int npar = config_get( SRB1Params,sizeof(SRB1Params)/sizeof(paramdef_t), srb1path);
-	      if (npar == sizeof(SRB1Params)/sizeof(paramdef_t)) {
-		switch (srb1_max_retx_threshold) {
-		case 1:
-		  rrc->srb1_max_retx_threshold = UL_AM_RLC__maxRetxThreshold_t1;
-		  break;
-		  
-		case 2:
-		  rrc->srb1_max_retx_threshold = UL_AM_RLC__maxRetxThreshold_t2;
-		  break;
-		  
-		case 3:
-		  rrc->srb1_max_retx_threshold = UL_AM_RLC__maxRetxThreshold_t3;
-		  break;
-		  
-		case 4:
-		  rrc->srb1_max_retx_threshold = UL_AM_RLC__maxRetxThreshold_t4;
-		  break;
-		  
-		case 6:
-		  rrc->srb1_max_retx_threshold = UL_AM_RLC__maxRetxThreshold_t6;
-		  break;
-		  
-		case 8:
-		  rrc->srb1_max_retx_threshold = UL_AM_RLC__maxRetxThreshold_t8;
-		  break;
-		  
-		case 16:
-		  rrc->srb1_max_retx_threshold = UL_AM_RLC__maxRetxThreshold_t16;
-		  break;
-		  
-		case 32:
-		  rrc->srb1_max_retx_threshold = UL_AM_RLC__maxRetxThreshold_t32;
-		  break;
-		  
-		default:
-		  AssertFatal (0,
-			       "Bad config value when parsing eNB configuration file %s, enb %d  srb1_max_retx_threshold %u!\n",
-			       RC.config_file_name, i, srb1_max_retx_threshold);
-		}
-		
-		
-		switch (srb1_poll_pdu) {
-		case 4:
-		  rrc->srb1_poll_pdu = PollPDU_p4;
-		  break;
-		  
-		case 8:
-		  rrc->srb1_poll_pdu = PollPDU_p8;
-		  break;
-		  
-		case 16:
-		  rrc->srb1_poll_pdu = PollPDU_p16;
-		  break;
-		  
-		case 32:
-		  rrc->srb1_poll_pdu = PollPDU_p32;
-		  break;
-		  
-		case 64:
-		  rrc->srb1_poll_pdu = PollPDU_p64;
-		  break;
-		  
-		case 128:
-		  rrc->srb1_poll_pdu = PollPDU_p128;
-		  break;
-		  
-		case 256:
-		  rrc->srb1_poll_pdu = PollPDU_p256;
-		  break;
-		  
-		default:
-		  if (srb1_poll_pdu >= 10000)
-		    rrc->srb1_poll_pdu = PollPDU_pInfinity;
-		  else
-		    AssertFatal (0,
-				 "Bad config value when parsing eNB configuration file %s, enb %d  srb1_poll_pdu %u!\n",
-				 RC.config_file_name, i, srb1_poll_pdu);
-		}
-		
-		rrc->srb1_poll_byte             = srb1_poll_byte;
-		
-		switch (srb1_poll_byte) {
-		case 25:
-		  rrc->srb1_poll_byte = PollByte_kB25;
-		  break;
-		  
-		case 50:
-		  rrc->srb1_poll_byte = PollByte_kB50;
-		  break;
-		  
-		case 75:
-		  rrc->srb1_poll_byte = PollByte_kB75;
-		  break;
-		  
-		case 100:
-		  rrc->srb1_poll_byte = PollByte_kB100;
-		  break;
-		  
-		case 125:
-		  rrc->srb1_poll_byte = PollByte_kB125;
-		  break;
-		  
-		case 250:
-		  rrc->srb1_poll_byte = PollByte_kB250;
-		  break;
-		  
-		case 375:
-		  rrc->srb1_poll_byte = PollByte_kB375;
-		  break;
-		  
-		case 500:
-		  rrc->srb1_poll_byte = PollByte_kB500;
-		  break;
-		  
-		case 750:
-		  rrc->srb1_poll_byte = PollByte_kB750;
-		  break;
-
-		case 1000:
-		  rrc->srb1_poll_byte = PollByte_kB1000;
-		  break;
-		  
-		case 1250:
-		  rrc->srb1_poll_byte = PollByte_kB1250;
-		  break;
-		  
-		case 1500:
-		  rrc->srb1_poll_byte = PollByte_kB1500;
-		  break;
-		  
-		case 2000:
-		  rrc->srb1_poll_byte = PollByte_kB2000;
-		  break;
-		  
-		case 3000:
-		  rrc->srb1_poll_byte = PollByte_kB3000;
-		  break;
-		  
-		default:
-		  if (srb1_poll_byte >= 10000)
-		    rrc->srb1_poll_byte = PollByte_kBinfinity;
-		  else
-		    AssertFatal (0,
-				 "Bad config value when parsing eNB configuration file %s, enb %d  srb1_poll_byte %u!\n",
-				 RC.config_file_name, i, srb1_poll_byte);
-		}
-		
-		if (srb1_timer_poll_retransmit <= 250) {
-		  rrc->srb1_timer_poll_retransmit = (srb1_timer_poll_retransmit - 5)/5;
-		} else if (srb1_timer_poll_retransmit <= 500) {
-		  rrc->srb1_timer_poll_retransmit = (srb1_timer_poll_retransmit - 300)/50 + 50;
-		} else {
-		  AssertFatal (0,
-			       "Bad config value when parsing eNB configuration file %s, enb %d  srb1_timer_poll_retransmit %u!\n",
-			       RC.config_file_name, i, srb1_timer_poll_retransmit);
-		}
-		
-		if (srb1_timer_status_prohibit <= 250) {
-		  rrc->srb1_timer_status_prohibit = srb1_timer_status_prohibit/5;
-		} else if ((srb1_timer_poll_retransmit >= 300) && (srb1_timer_poll_retransmit <= 500)) {
-		  rrc->srb1_timer_status_prohibit = (srb1_timer_status_prohibit - 300)/50 + 51;
-		} else {
-		  AssertFatal (0,
-			       "Bad config value when parsing eNB configuration file %s, enb %d  srb1_timer_status_prohibit %u!\n",
-			       RC.config_file_name, i, srb1_timer_status_prohibit);
-		}
-		
-		switch (srb1_timer_reordering) {
-		case 0:
-		  rrc->srb1_timer_reordering = T_Reordering_ms0;
-		  break;
-		  
-		case 5:
-		  rrc->srb1_timer_reordering = T_Reordering_ms5;
-		  break;
-		  
-		case 10:
-		  rrc->srb1_timer_reordering = T_Reordering_ms10;
-		  break;
-		  
-		case 15:
-		  rrc->srb1_timer_reordering = T_Reordering_ms15;
-		  break;
-		  
-		case 20:
-		  rrc->srb1_timer_reordering = T_Reordering_ms20;
-		  break;
-		  
-		case 25:
-		  rrc->srb1_timer_reordering = T_Reordering_ms25;
-		  break;
-		  
-		case 30:
-		  rrc->srb1_timer_reordering = T_Reordering_ms30;
-		  break;
-		  
-		case 35:
-		  rrc->srb1_timer_reordering = T_Reordering_ms35;
-		  break;
-		  
-		case 40:
-		  rrc->srb1_timer_reordering = T_Reordering_ms40;
-		  break;
-		  
-		case 45:
-		  rrc->srb1_timer_reordering = T_Reordering_ms45;
-		  break;
-		  
-		case 50:
-		  rrc->srb1_timer_reordering = T_Reordering_ms50;
-		  break;
-		  
-		case 55:
-		  rrc->srb1_timer_reordering = T_Reordering_ms55;
-		  break;
-		  
-		case 60:
-		  rrc->srb1_timer_reordering = T_Reordering_ms60;
-		  break;
-		  
-		case 65:
-		  rrc->srb1_timer_reordering = T_Reordering_ms65;
-		  break;
-		  
-		case 70:
-		  rrc->srb1_timer_reordering = T_Reordering_ms70;
-		  break;
-		  
-		case 75:
-		  rrc->srb1_timer_reordering = T_Reordering_ms75;
-		  break;
-		  
-		case 80:
-		  rrc->srb1_timer_reordering = T_Reordering_ms80;
-		  break;
-		  
-		case 85:
-		  rrc->srb1_timer_reordering = T_Reordering_ms85;
-		  break;
-		  
-		case 90:
-		  rrc->srb1_timer_reordering = T_Reordering_ms90;
-		  break;
-		  
-		case 95:
-		  rrc->srb1_timer_reordering = T_Reordering_ms95;
-		  break;
-		  
-		case 100:
-		  rrc->srb1_timer_reordering = T_Reordering_ms100;
-		  break;
-		  
-		case 110:
-		  rrc->srb1_timer_reordering = T_Reordering_ms110;
-		  break;
-		  
-		case 120:
-		  rrc->srb1_timer_reordering = T_Reordering_ms120;
-		  break;
-		  
-		case 130:
-		  rrc->srb1_timer_reordering = T_Reordering_ms130;
-		  break;
-		  
-		case 140:
-		  rrc->srb1_timer_reordering = T_Reordering_ms140;
-		  break;
-		  
-		case 150:
-		  rrc->srb1_timer_reordering = T_Reordering_ms150;
-		  break;
-		  
-		case 160:
-		  rrc->srb1_timer_reordering = T_Reordering_ms160;
-		  break;
-		  
-		case 170:
-		  rrc->srb1_timer_reordering = T_Reordering_ms170;
-		  break;
-		  
-		case 180:
-		  rrc->srb1_timer_reordering = T_Reordering_ms180;
-		  break;
-		  
-		case 190:
-		  rrc->srb1_timer_reordering = T_Reordering_ms190;
-		  break;
-		  
-		case 200:
-		  rrc->srb1_timer_reordering = T_Reordering_ms200;
-		  break;
-		  
-		default:
-		  AssertFatal (0,
-			       "Bad config value when parsing eNB configuration file %s, enb %d  srb1_timer_reordering %u!\n",
-			       RC.config_file_name, i, srb1_timer_reordering);
-		}
-		
-	      } else {
-		rrc->srb1_timer_poll_retransmit = T_PollRetransmit_ms80;
-		rrc->srb1_timer_reordering      = T_Reordering_ms35;
-		rrc->srb1_timer_status_prohibit = T_StatusProhibit_ms0;
-		rrc->srb1_poll_pdu              = PollPDU_p4;
-		rrc->srb1_poll_byte             = PollByte_kBinfinity;
-		rrc->srb1_max_retx_threshold    = UL_AM_RLC__maxRetxThreshold_t8;
-	      }
-	      
-	      /*
-	      // Network Controller 
-	      subsetting = config_setting_get_member (setting_enb, ENB_CONFIG_STRING_NETWORK_CONTROLLER_CONFIG);
-	      
-	      if (subsetting != NULL) {
-	      if (  (
-	      config_setting_lookup_string( subsetting, ENB_CONFIG_STRING_FLEXRAN_AGENT_INTERFACE_NAME,
-	      (const char **)&flexran_agent_interface_name)
-	      && config_setting_lookup_string( subsetting, ENB_CONFIG_STRING_FLEXRAN_AGENT_IPV4_ADDRESS,
-	      (const char **)&flexran_agent_ipv4_address)
-	      && config_setting_lookup_int(subsetting, ENB_CONFIG_STRING_FLEXRAN_AGENT_PORT,
-	      &flexran_agent_port)
-	      && config_setting_lookup_string( subsetting, ENB_CONFIG_STRING_FLEXRAN_AGENT_CACHE,
-	      (const char **)&flexran_agent_cache)
-	      )
-	      ) {
-	      enb_properties_loc.properties[enb_properties_loc_index]->flexran_agent_interface_name = strdup(flexran_agent_interface_name);
-	      cidr = flexran_agent_ipv4_address;
-	      address = strtok(cidr, "/");
-	      //enb_properties_loc.properties[enb_properties_loc_index]->flexran_agent_ipv4_address = strdup(address);
-	      if (address) {
-	      IPV4_STR_ADDR_TO_INT_NWBO (address, enb_properties_loc.properties[enb_properties_loc_index]->flexran_agent_ipv4_address, "BAD IP ADDRESS FORMAT FOR eNB Agent !\n" );
-	      }
-	      
-	      enb_properties_loc.properties[enb_properties_loc_index]->flexran_agent_port = flexran_agent_port;
-	      enb_properties_loc.properties[enb_properties_loc_index]->flexran_agent_cache = strdup(flexran_agent_cache);
-	      }
-	      }
-	      */
-	      break;
-	    }
-	  }
-	}
+            default:
+              AssertFatal (0,
+                           "Bad config value when parsing eNB configuration file %s, enb %d  srb1_timer_reordering %u!\n",
+                           RC.config_file_name, i, srb1_params.srb1_timer_reordering);
+            }
+          }
+        }
       }
-
+    }
 #if defined (ENABLE_ITTI)
-      memcpy(&RC.rrc[i]->configuration, &RRC_CONFIGURATION_REQ(msg_p),
-             sizeof(RRC_CONFIGURATION_REQ(msg_p)));
+    memcpy(&RC.rrc[i]->configuration, &RRC_CONFIGURATION_REQ(msg_p),
+           sizeof(RRC_CONFIGURATION_REQ(msg_p)));
 #endif
-
   }
   LOG_I(RRC,"Node type %d \n ", rrc->node_type);
 
-return 0;
+  return 0;
 }
 
 int RCconfig_DU_F1(MessageDef *msg_p, uint32_t i) {
@@ -2151,9 +1849,7 @@ int RCconfig_DU_F1(MessageDef *msg_p, uint32_t i) {
       } // if
     } // for
   } // if
-
   return 0;
-
 }
 
 int RCconfig_gtpu(void ) {
@@ -2190,41 +1886,50 @@ int RCconfig_gtpu(void ) {
   return 0;
 }
 
+//-----------------------------------------------------------------------------
+/*
+* Configure the s1ap_register_enb_req in itti message for future
+* communications between eNB(s) and MME.
+*/
+int RCconfig_S1(
+  MessageDef *msg_p,
+  uint32_t i)
+//-----------------------------------------------------------------------------
+{
+  int enb_id = 0;
+  int32_t my_int = 0;
+  const char *active_enb[MAX_ENB];
+  char *address = NULL;
+  char *cidr    = NULL;
+
+  ccparams_lte_t ccparams_lte;
+
+  memset((void*)&ccparams_lte,0,sizeof(ccparams_lte_t));
+
 
-int RCconfig_S1(MessageDef *msg_p, uint32_t i) {
-  int               j,k                           = 0;
-  int enb_id;
-  int32_t     my_int;
-  const char       *active_enb[MAX_ENB];
-  char             *address                       = NULL;
-  char             *cidr                          = NULL;
   // for no gcc warnings
   (void)my_int;
-  memset((char *)active_enb,     0, MAX_ENB * sizeof(char *));
+  memset((char *)active_enb, 0, MAX_ENB * sizeof(char *));
   paramdef_t ENBSParams[] = ENBSPARAMS_DESC;
-  paramdef_t ENBParams[]  = ENBPARAMS_DESC;
-  paramlist_def_t ENBParamList = {ENB_CONFIG_STRING_ENB_LIST,NULL,0};
+  paramdef_t ENBParams[] = ENBPARAMS_DESC;
+  paramlist_def_t ENBParamList = {ENB_CONFIG_STRING_ENB_LIST, NULL, 0};
   /* get global parameters, defined outside any section in the config file */
-  config_get( ENBSParams,sizeof(ENBSParams)/sizeof(paramdef_t),NULL);
-  AssertFatal (i<ENBSParams[ENB_ACTIVE_ENBS_IDX].numelt,
+  config_get(ENBSParams, sizeof(ENBSParams)/sizeof(paramdef_t), NULL);
+  AssertFatal (i < ENBSParams[ENB_ACTIVE_ENBS_IDX].numelt,
                "Failed to parse config file %s, %uth attribute %s \n",
                RC.config_file_name, i, ENB_CONFIG_STRING_ACTIVE_ENBS);
 
-    AssertFatal (i<ENBSParams[ENB_ACTIVE_ENBS_IDX].numelt,
-		 "Failed to parse config file %s, %uth attribute %s \n",
-		 RC.config_file_name, i, ENB_CONFIG_STRING_ACTIVE_ENBS);
-    
-  if (ENBSParams[ENB_ACTIVE_ENBS_IDX].numelt>0) {
+  if (ENBSParams[ENB_ACTIVE_ENBS_IDX].numelt > 0) {
     // Output a list of all eNBs.
-    config_getlist( &ENBParamList,ENBParams,sizeof(ENBParams)/sizeof(paramdef_t),NULL);
+    config_getlist(&ENBParamList, ENBParams, sizeof(ENBParams)/sizeof(paramdef_t), NULL);
 
     if (ENBParamList.numelt > 0) {
-      for (k = 0; k < ENBParamList.numelt; k++) {
+      for (int k = 0; k < ENBParamList.numelt; k++) {
         if (ENBParamList.paramarray[k][ENB_ENB_ID_IDX].uptr == NULL) {
           // Calculate a default eNB ID
           if (EPC_MODE_ENABLED) {
-            uint32_t hash;
-            hash = s1ap_generate_eNB_id ();
+            uint32_t hash = 0;
+            hash = s1ap_generate_eNB_id();
             enb_id = k + (hash & 0xFFFF8);
           } else {
             enb_id = k;
@@ -2234,22 +1939,31 @@ int RCconfig_S1(MessageDef *msg_p, uint32_t i) {
         }
 
         // search if in active list
-        for (j=0; j < ENBSParams[ENB_ACTIVE_ENBS_IDX].numelt; j++) {
+        for (int j = 0; j < ENBSParams[ENB_ACTIVE_ENBS_IDX].numelt; j++) {
           if (strcmp(ENBSParams[ENB_ACTIVE_ENBS_IDX].strlistptr[j], *(ENBParamList.paramarray[k][ENB_ENB_NAME_IDX].strptr)) == 0) {
             paramdef_t PLMNParams[] = PLMNPARAMS_DESC;
             paramlist_def_t PLMNParamList = {ENB_CONFIG_STRING_PLMN_LIST, NULL, 0};
+            paramdef_t CCsParams[] = CCPARAMS_DESC(ccparams_lte);
+            /* map parameter checking array instances to parameter definition array instances */
+            checkedparam_t config_check_CCparams[] = CCPARAMS_CHECK;
+
+            for (int I = 0; I < (sizeof(CCsParams) / sizeof(paramdef_t)); I++) {
+              CCsParams[I].chkPptr = &(config_check_CCparams[I]);
+            }
+
             /* map parameter checking array instances to parameter definition array instances */
             checkedparam_t config_check_PLMNParams [] = PLMNPARAMS_CHECK;
 
-            for (int I = 0; I < sizeof(PLMNParams) / sizeof(paramdef_t); ++I)
+            for (int I = 0; I < sizeof(PLMNParams) / sizeof(paramdef_t); ++I) {
               PLMNParams[I].chkPptr = &(config_check_PLMNParams[I]);
+            }
 
-            paramdef_t S1Params[]  = S1PARAMS_DESC;
-            paramlist_def_t S1ParamList = {ENB_CONFIG_STRING_MME_IP_ADDRESS,NULL,0};
-            paramdef_t SCTPParams[]  = SCTPPARAMS_DESC;
-            paramdef_t NETParams[]  =  NETPARAMS_DESC;
+            paramdef_t S1Params[] = S1PARAMS_DESC;
+            paramlist_def_t S1ParamList = {ENB_CONFIG_STRING_MME_IP_ADDRESS, NULL, 0};
+            paramdef_t SCTPParams[] = SCTPPARAMS_DESC;
+            paramdef_t NETParams[] =  NETPARAMS_DESC;
             char aprefix[MAX_OPTNAME_SIZE*2 + 8];
-            sprintf(aprefix,"%s.[%i]",ENB_CONFIG_STRING_ENB_LIST,k);
+            sprintf(aprefix, "%s.[%i]", ENB_CONFIG_STRING_ENB_LIST, k);
             S1AP_REGISTER_ENB_REQ (msg_p).eNB_id = enb_id;
 
             if (strcmp(*(ENBParamList.paramarray[k][ENB_CELL_TYPE_IDX].strptr), "CELL_MACRO_ENB") == 0) {
@@ -2257,13 +1971,15 @@ int RCconfig_S1(MessageDef *msg_p, uint32_t i) {
             } else  if (strcmp(*(ENBParamList.paramarray[k][ENB_CELL_TYPE_IDX].strptr), "CELL_HOME_ENB") == 0) {
               S1AP_REGISTER_ENB_REQ (msg_p).cell_type = CELL_HOME_ENB;
             } else {
-              AssertFatal (0,
-                           "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for cell_type choice: CELL_MACRO_ENB or CELL_HOME_ENB !\n",
-                           RC.config_file_name, i, *(ENBParamList.paramarray[k][ENB_CELL_TYPE_IDX].strptr));
+              AssertFatal(0,
+                          "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for cell_type choice: CELL_MACRO_ENB or CELL_HOME_ENB !\n",
+                          RC.config_file_name,
+                          i,
+                          *(ENBParamList.paramarray[k][ENB_CELL_TYPE_IDX].strptr));
             }
 
-            S1AP_REGISTER_ENB_REQ (msg_p).eNB_name         = strdup(*(ENBParamList.paramarray[k][ENB_ENB_NAME_IDX].strptr));
-            S1AP_REGISTER_ENB_REQ(msg_p).tac               = *ENBParamList.paramarray[k][ENB_TRACKING_AREA_CODE_IDX].uptr;
+            S1AP_REGISTER_ENB_REQ (msg_p).eNB_name = strdup(*(ENBParamList.paramarray[k][ENB_ENB_NAME_IDX].strptr));
+            S1AP_REGISTER_ENB_REQ(msg_p).tac = *ENBParamList.paramarray[k][ENB_TRACKING_AREA_CODE_IDX].uptr;
             AssertFatal(!ENBParamList.paramarray[k][ENB_MOBILE_COUNTRY_CODE_IDX_OLD].strptr
                         && !ENBParamList.paramarray[k][ENB_MOBILE_NETWORK_CODE_IDX_OLD].strptr,
                         "It seems that you use an old configuration file. Please change the existing\n"
@@ -2275,9 +1991,10 @@ int RCconfig_S1(MessageDef *msg_p, uint32_t i) {
                         "    plmn_list = ( { mcc = 208; mnc = 93; mnc_length = 2; } )\n");
             config_getlist(&PLMNParamList, PLMNParams, sizeof(PLMNParams)/sizeof(paramdef_t), aprefix);
 
-            if (PLMNParamList.numelt < 1 || PLMNParamList.numelt > 6)
+            if (PLMNParamList.numelt < 1 || PLMNParamList.numelt > 6) {
               AssertFatal(0, "The number of PLMN IDs must be in [1,6], but is %d\n",
                           PLMNParamList.numelt);
+            }
 
             S1AP_REGISTER_ENB_REQ(msg_p).num_plmn = PLMNParamList.numelt;
 
@@ -2291,8 +2008,48 @@ int RCconfig_S1(MessageDef *msg_p, uint32_t i) {
                           S1AP_REGISTER_ENB_REQ(msg_p).mnc[l]);
             }
 
-            S1AP_REGISTER_ENB_REQ(msg_p).default_drx = 0;
-            config_getlist( &S1ParamList,S1Params,sizeof(S1Params)/sizeof(paramdef_t),aprefix);
+            /* Default DRX param */
+            /*
+            * Here we get the config of the first CC, since the s1ap_register_enb_req_t doesn't support multiple CC.
+            * There is a unique value of defaultPagingCycle per eNB (same for multiple cells).
+            * Hence, it should be stated somewhere that the value should be the same for every CC, or put the value outside the CC
+            * in the conf file.
+            */
+            sprintf(aprefix, "%s.[%i].%s.[%i]", ENB_CONFIG_STRING_ENB_LIST, k, ENB_CONFIG_STRING_COMPONENT_CARRIERS, 0);
+            config_get(CCsParams, sizeof(CCsParams)/sizeof(paramdef_t), aprefix);
+
+            switch (ccparams_lte.pcch_defaultPagingCycle) {
+              case 32: {
+                S1AP_REGISTER_ENB_REQ(msg_p).default_drx = 0;
+                break;
+              }
+
+              case 64: {
+                S1AP_REGISTER_ENB_REQ(msg_p).default_drx = 1;
+                break;
+              }
+
+              case 128: {
+                S1AP_REGISTER_ENB_REQ(msg_p).default_drx = 2;
+                break;
+              }
+
+              case 256: {
+                S1AP_REGISTER_ENB_REQ(msg_p).default_drx = 3;
+                break;
+              }
+
+              default: {
+                LOG_E(S1AP, "Default I-DRX value in conf file is invalid (%i). Should be 32, 64, 128 or 256. \
+                             Default DRX set to 32 in MME configuration\n",
+                      ccparams_lte.pcch_defaultPagingCycle);
+                S1AP_REGISTER_ENB_REQ(msg_p).default_drx = 0;
+              }
+            }
+
+            /* MME connection params */
+            sprintf(aprefix, "%s.[%i]", ENB_CONFIG_STRING_ENB_LIST, k);
+            config_getlist(&S1ParamList, S1Params, sizeof(S1Params)/sizeof(paramdef_t), aprefix);
             S1AP_REGISTER_ENB_REQ (msg_p).nb_mme = 0;
 
             for (int l = 0; l < S1ParamList.numelt; l++) {
@@ -2302,17 +2059,20 @@ int RCconfig_S1(MessageDef *msg_p, uint32_t i) {
 
               if (strcmp(*(S1ParamList.paramarray[l][ENB_MME_IP_ADDRESS_PREFERENCE_IDX].strptr), "ipv4") == 0) {
                 S1AP_REGISTER_ENB_REQ (msg_p).mme_ip_address[l].ipv4 = 1;
+                S1AP_REGISTER_ENB_REQ (msg_p).mme_ip_address[l].ipv6 = 0;
               } else if (strcmp(*(S1ParamList.paramarray[l][ENB_MME_IP_ADDRESS_PREFERENCE_IDX].strptr), "ipv6") == 0) {
+                S1AP_REGISTER_ENB_REQ (msg_p).mme_ip_address[l].ipv4 = 0;
                 S1AP_REGISTER_ENB_REQ (msg_p).mme_ip_address[l].ipv6 = 1;
               } else if (strcmp(*(S1ParamList.paramarray[l][ENB_MME_IP_ADDRESS_PREFERENCE_IDX].strptr), "no") == 0) {
                 S1AP_REGISTER_ENB_REQ (msg_p).mme_ip_address[l].ipv4 = 1;
                 S1AP_REGISTER_ENB_REQ (msg_p).mme_ip_address[l].ipv6 = 1;
               }
 
-              if (S1ParamList.paramarray[l][ENB_MME_BROADCAST_PLMN_INDEX].iptr)
+              if (S1ParamList.paramarray[l][ENB_MME_BROADCAST_PLMN_INDEX].iptr) {
                 S1AP_REGISTER_ENB_REQ(msg_p).broadcast_plmn_num[l] = S1ParamList.paramarray[l][ENB_MME_BROADCAST_PLMN_INDEX].numelt;
-              else
+              } else {
                 S1AP_REGISTER_ENB_REQ(msg_p).broadcast_plmn_num[l] = 0;
+              }
 
               AssertFatal(S1AP_REGISTER_ENB_REQ(msg_p).broadcast_plmn_num[l] <= S1AP_REGISTER_ENB_REQ(msg_p).num_plmn,
                           "List of broadcast PLMN to be sent to MME can not be longer than actual "
@@ -2334,8 +2094,9 @@ int RCconfig_S1(MessageDef *msg_p, uint32_t i) {
               if (S1AP_REGISTER_ENB_REQ(msg_p).broadcast_plmn_num[l] == 0) {
                 S1AP_REGISTER_ENB_REQ(msg_p).broadcast_plmn_num[l] = S1AP_REGISTER_ENB_REQ(msg_p).num_plmn;
 
-                for (int el = 0; el < S1AP_REGISTER_ENB_REQ(msg_p).num_plmn; ++el)
+                for (int el = 0; el < S1AP_REGISTER_ENB_REQ(msg_p).num_plmn; ++el) {
                   S1AP_REGISTER_ENB_REQ(msg_p).broadcast_plmn_index[l][el] = el;
+                }
               }
             }
 
@@ -2353,7 +2114,6 @@ int RCconfig_S1(MessageDef *msg_p, uint32_t i) {
             sprintf(aprefix,"%s.[%i].%s",ENB_CONFIG_STRING_ENB_LIST,k,ENB_CONFIG_STRING_NETWORK_INTERFACES_CONFIG);
             // NETWORK_INTERFACES
             config_get( NETParams,sizeof(NETParams)/sizeof(paramdef_t),aprefix);
-            //    S1AP_REGISTER_ENB_REQ (msg_p).enb_interface_name_for_S1U = strdup(enb_interface_name_for_S1U);
             cidr = *(NETParams[ENB_IPV4_ADDRESS_FOR_S1_MME_IDX].strptr);
             address = strtok(cidr, "/");
             S1AP_REGISTER_ENB_REQ (msg_p).enb_ip_address.ipv6 = 0;
@@ -2374,80 +2134,20 @@ int RCconfig_X2(MessageDef *msg_p, uint32_t i) {
   int   enb_id;
   char *address = NULL;
   char *cidr    = NULL;
+
+  ccparams_lte_t ccparams_lte;
+
+  memset((void*)&ccparams_lte,0,sizeof(ccparams_lte_t));
+
+
   paramdef_t ENBSParams[] = ENBSPARAMS_DESC;
   paramdef_t ENBParams[]  = ENBPARAMS_DESC;
   paramlist_def_t ENBParamList = {ENB_CONFIG_STRING_ENB_LIST,NULL,0};
   /* get global parameters, defined outside any section in the config file */
   config_get( ENBSParams,sizeof(ENBSParams)/sizeof(paramdef_t),NULL);
-  /* define CC params */
-  int32_t Nid_cell = 0;
-  char *frame_type, *prefix_type, *pbch_repetition, *prach_high_speed,
-       *pusch_hoppingMode, *pusch_enable64QAM, *pusch_groupHoppingEnabled,
-       *pusch_sequenceHoppingEnabled, *phich_duration, *phich_resource,
-       *srs_enable, *srs_ackNackST, *srs_MaxUpPts, *pusch_alpha,
-       *pucch_deltaF_Format1, *pucch_deltaF_Format1b, *pucch_deltaF_Format2,
-       *pucch_deltaF_Format2a, *pucch_deltaF_Format2b,
-       *rach_preamblesGroupAConfig, *rach_messagePowerOffsetGroupB, *pcch_nB;
-  long long int     downlink_frequency;
-  int32_t tdd_config, tdd_config_s, eutra_band, uplink_frequency_offset,
-          Nid_cell_mbsfn, N_RB_DL, nb_antenna_ports, prach_root, prach_config_index,
-          prach_zero_correlation, prach_freq_offset, pucch_delta_shift,
-          pucch_nRB_CQI, pucch_nCS_AN, pucch_n1_AN, pdsch_referenceSignalPower,
-          pdsch_p_b, pusch_n_SB, pusch_hoppingOffset, pusch_groupAssignment,
-          pusch_nDMRS1, srs_BandwidthConfig, srs_SubframeConfig, pusch_p0_Nominal,
-          pucch_p0_Nominal, msg3_delta_Preamble, rach_numberOfRA_Preambles,
-          rach_sizeOfRA_PreamblesGroupA, rach_messageSizeGroupA,
-          rach_powerRampingStep, rach_preambleInitialReceivedTargetPower,
-          rach_preambleTransMax, rach_raResponseWindowSize,
-          rach_macContentionResolutionTimer, rach_maxHARQ_Msg3Tx,
-          pcch_defaultPagingCycle, bcch_modificationPeriodCoeff,
-          ue_TimersAndConstants_t300, ue_TimersAndConstants_t301,
-          ue_TimersAndConstants_t310, ue_TimersAndConstants_t311,
-          ue_TimersAndConstants_n310, ue_TimersAndConstants_n311,
-          ue_TransmissionMode, ue_multiple_max;
-  const char       *rxPool_sc_CP_Len;
-  const char       *rxPool_sc_Period;
-  const char       *rxPool_data_CP_Len;
-  libconfig_int     rxPool_ResourceConfig_prb_Num;
-  libconfig_int     rxPool_ResourceConfig_prb_Start;
-  libconfig_int     rxPool_ResourceConfig_prb_End;
-  const char       *rxPool_ResourceConfig_offsetIndicator_present;
-  libconfig_int     rxPool_ResourceConfig_offsetIndicator_choice;
-  const char       *rxPool_ResourceConfig_subframeBitmap_present;
-  char             *rxPool_ResourceConfig_subframeBitmap_choice_bs_buf;
-  libconfig_int     rxPool_ResourceConfig_subframeBitmap_choice_bs_size;
-  libconfig_int     rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused;
-  //SIB19
-  //for discRxPool
-  const char       *discRxPool_cp_Len;
-  const char       *discRxPool_discPeriod;
-  libconfig_int     discRxPool_numRetx;
-  libconfig_int     discRxPool_numRepetition;
-  libconfig_int     discRxPool_ResourceConfig_prb_Num;
-  libconfig_int     discRxPool_ResourceConfig_prb_Start;
-  libconfig_int     discRxPool_ResourceConfig_prb_End;
-  const char       *discRxPool_ResourceConfig_offsetIndicator_present;
-  libconfig_int     discRxPool_ResourceConfig_offsetIndicator_choice;
-  const char       *discRxPool_ResourceConfig_subframeBitmap_present;
-  char             *discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf;
-  libconfig_int     discRxPool_ResourceConfig_subframeBitmap_choice_bs_size;
-  libconfig_int     discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused;
-  //for discRxPoolPS
-  const char       *discRxPoolPS_cp_Len;
-  const char       *discRxPoolPS_discPeriod;
-  libconfig_int     discRxPoolPS_numRetx;
-  libconfig_int     discRxPoolPS_numRepetition;
-  libconfig_int     discRxPoolPS_ResourceConfig_prb_Num;
-  libconfig_int     discRxPoolPS_ResourceConfig_prb_Start;
-  libconfig_int     discRxPoolPS_ResourceConfig_prb_End;
-  const char       *discRxPoolPS_ResourceConfig_offsetIndicator_present;
-  libconfig_int     discRxPoolPS_ResourceConfig_offsetIndicator_choice;
-  const char       *discRxPoolPS_ResourceConfig_subframeBitmap_present;
-  char             *discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_buf;
-  libconfig_int     discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_size;
-  libconfig_int     discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_bits_unused;
+
   checkedparam_t config_check_CCparams[] = CCPARAMS_CHECK;
-  paramdef_t CCsParams[] = CCPARAMS_DESC;
+  paramdef_t CCsParams[] = CCPARAMS_DESC(ccparams_lte);
   paramlist_def_t CCsParamList = {ENB_CONFIG_STRING_COMPONENT_CARRIERS, NULL, 0};
 
   /* map parameter checking array instances to parameter definition array instances */
@@ -2456,23 +2156,23 @@ int RCconfig_X2(MessageDef *msg_p, uint32_t i) {
   }
 
   /*#if defined(ENABLE_ITTI) && defined(ENABLE_USE_MME)
-      if (strcasecmp( *(ENBSParams[ENB_ASN1_VERBOSITY_IDX].strptr), ENB_CONFIG_STRING_ASN1_VERBOSITY_NONE) == 0) {
-        asn_debug      = 0;
-        asn1_xer_print = 0;
-      } else if (strcasecmp( *(ENBSParams[ENB_ASN1_VERBOSITY_IDX].strptr), ENB_CONFIG_STRING_ASN1_VERBOSITY_INFO) == 0) {
-        asn_debug      = 1;
-        asn1_xer_print = 1;
-      } else if (strcasecmp(*(ENBSParams[ENB_ASN1_VERBOSITY_IDX].strptr) , ENB_CONFIG_STRING_ASN1_VERBOSITY_ANNOYING) == 0) {
-        asn_debug      = 1;
-        asn1_xer_print = 2;
-      } else {
-        asn_debug      = 0;
-        asn1_xer_print = 0;
-      }
-  #endif */
+    if (strcasecmp( *(ENBSParams[ENB_ASN1_VERBOSITY_IDX].strptr), ENB_CONFIG_STRING_ASN1_VERBOSITY_NONE) == 0) {
+    asn_debug      = 0;
+    asn1_xer_print = 0;
+    } else if (strcasecmp( *(ENBSParams[ENB_ASN1_VERBOSITY_IDX].strptr), ENB_CONFIG_STRING_ASN1_VERBOSITY_INFO) == 0) {
+    asn_debug      = 1;
+    asn1_xer_print = 1;
+    } else if (strcasecmp(*(ENBSParams[ENB_ASN1_VERBOSITY_IDX].strptr) , ENB_CONFIG_STRING_ASN1_VERBOSITY_ANNOYING) == 0) {
+    asn_debug      = 1;
+    asn1_xer_print = 2;
+    } else {
+    asn_debug      = 0;
+    asn1_xer_print = 0;
+    }
+    #endif */
   AssertFatal(i < ENBSParams[ENB_ACTIVE_ENBS_IDX].numelt,
-              "Failed to parse config file %s, %uth attribute %s \n",
-              RC.config_file_name, i, ENB_CONFIG_STRING_ACTIVE_ENBS);
+    "Failed to parse config file %s, %uth attribute %s \n",
+    RC.config_file_name, i, ENB_CONFIG_STRING_ACTIVE_ENBS);
 
   if (ENBSParams[ENB_ACTIVE_ENBS_IDX].numelt > 0) {
     // Output a list of all eNBs.
@@ -2480,163 +2180,162 @@ int RCconfig_X2(MessageDef *msg_p, uint32_t i) {
 
     if (ENBParamList.numelt > 0) {
       for (k = 0; k < ENBParamList.numelt; k++) {
-        if (ENBParamList.paramarray[k][ENB_ENB_ID_IDX].uptr == NULL) {
-          // Calculate a default eNB ID
+	if (ENBParamList.paramarray[k][ENB_ENB_ID_IDX].uptr == NULL) {
+	  // Calculate a default eNB ID
 # if defined(ENABLE_USE_MME)
-          uint32_t hash;
-          hash = s1ap_generate_eNB_id ();
-          enb_id = k + (hash & 0xFFFF8);
+	  uint32_t hash;
+	  hash = s1ap_generate_eNB_id ();
+	  enb_id = k + (hash & 0xFFFF8);
 # else
-          enb_id = k;
+	  enb_id = k;
 # endif
-        } else {
-          enb_id = *(ENBParamList.paramarray[k][ENB_ENB_ID_IDX].uptr);
-        }
-
-        // search if in active list
-        for (j = 0; j < ENBSParams[ENB_ACTIVE_ENBS_IDX].numelt; j++) {
-          if (strcmp(ENBSParams[ENB_ACTIVE_ENBS_IDX].strlistptr[j], *(ENBParamList.paramarray[k][ENB_ENB_NAME_IDX].strptr)) == 0) {
-            paramdef_t PLMNParams[] = PLMNPARAMS_DESC;
-            paramlist_def_t PLMNParamList = {ENB_CONFIG_STRING_PLMN_LIST, NULL, 0};
-            /* map parameter checking array instances to parameter definition array instances */
-            checkedparam_t config_check_PLMNParams [] = PLMNPARAMS_CHECK;
-
-            for (int I = 0; I < sizeof(PLMNParams) / sizeof(paramdef_t); ++I)
-              PLMNParams[I].chkPptr = &(config_check_PLMNParams[I]);
-
-            paramdef_t X2Params[]  = X2PARAMS_DESC;
-            paramlist_def_t X2ParamList = {ENB_CONFIG_STRING_TARGET_ENB_X2_IP_ADDRESS,NULL,0};
-            paramdef_t SCTPParams[]  = SCTPPARAMS_DESC;
-            paramdef_t NETParams[]  =  NETPARAMS_DESC;
-            /* TODO: fix the size - if set lower we have a crash (MAX_OPTNAME_SIZE was 64 when this code was written) */
-            /* this is most probably a problem with the config module */
-            char aprefix[MAX_OPTNAME_SIZE*80 + 8];
-            sprintf(aprefix,"%s.[%i]",ENB_CONFIG_STRING_ENB_LIST,k);
-            /* Some default/random parameters */
-            X2AP_REGISTER_ENB_REQ (msg_p).eNB_id = enb_id;
-
-            if (strcmp(*(ENBParamList.paramarray[k][ENB_CELL_TYPE_IDX].strptr), "CELL_MACRO_ENB") == 0) {
-              X2AP_REGISTER_ENB_REQ (msg_p).cell_type = CELL_MACRO_ENB;
-            } else  if (strcmp(*(ENBParamList.paramarray[k][ENB_CELL_TYPE_IDX].strptr), "CELL_HOME_ENB") == 0) {
-              X2AP_REGISTER_ENB_REQ (msg_p).cell_type = CELL_HOME_ENB;
-            } else {
-              AssertFatal (0,
-                           "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for cell_type choice: CELL_MACRO_ENB or CELL_HOME_ENB !\n",
-                           RC.config_file_name, i, *(ENBParamList.paramarray[k][ENB_CELL_TYPE_IDX].strptr));
-            }
-
-            X2AP_REGISTER_ENB_REQ (msg_p).eNB_name         = strdup(*(ENBParamList.paramarray[k][ENB_ENB_NAME_IDX].strptr));
-            X2AP_REGISTER_ENB_REQ (msg_p).tac              = *ENBParamList.paramarray[k][ENB_TRACKING_AREA_CODE_IDX].uptr;
-            config_getlist(&PLMNParamList, PLMNParams, sizeof(PLMNParams)/sizeof(paramdef_t), aprefix);
-
-            if (PLMNParamList.numelt < 1 || PLMNParamList.numelt > 6)
-              AssertFatal(0, "The number of PLMN IDs must be in [1,6], but is %d\n",
-                          PLMNParamList.numelt);
-
-            if (PLMNParamList.numelt > 1)
-              LOG_W(X2AP, "X2AP currently handles only one PLMN, ignoring the others!\n");
-
-            X2AP_REGISTER_ENB_REQ (msg_p).mcc = *PLMNParamList.paramarray[0][ENB_MOBILE_COUNTRY_CODE_IDX].uptr;
-            X2AP_REGISTER_ENB_REQ (msg_p).mnc = *PLMNParamList.paramarray[0][ENB_MOBILE_NETWORK_CODE_IDX].uptr;
-            X2AP_REGISTER_ENB_REQ (msg_p).mnc_digit_length = *PLMNParamList.paramarray[0][ENB_MNC_DIGIT_LENGTH].u8ptr;
-            AssertFatal(X2AP_REGISTER_ENB_REQ(msg_p).mnc_digit_length == 3
-                        || X2AP_REGISTER_ENB_REQ(msg_p).mnc < 100,
-                        "MNC %d cannot be encoded in two digits as requested (change mnc_digit_length to 3)\n",
-                        X2AP_REGISTER_ENB_REQ(msg_p).mnc);
-
-            /* CC params */
-            config_getlist(&CCsParamList, NULL, 0, aprefix);
-
-            X2AP_REGISTER_ENB_REQ (msg_p).num_cc = CCsParamList.numelt;
-
-            if (CCsParamList.numelt > 0) {
-              //char ccspath[MAX_OPTNAME_SIZE*2 + 16];
-              for (J = 0; J < CCsParamList.numelt ; J++) {
-                sprintf(aprefix, "%s.[%i].%s.[%i]", ENB_CONFIG_STRING_ENB_LIST, k, ENB_CONFIG_STRING_COMPONENT_CARRIERS, J);
-                config_get(CCsParams, sizeof(CCsParams)/sizeof(paramdef_t), aprefix);
-                X2AP_REGISTER_ENB_REQ (msg_p).eutra_band[J] = eutra_band;
-                X2AP_REGISTER_ENB_REQ (msg_p).downlink_frequency[J] = (uint32_t) downlink_frequency;
-                X2AP_REGISTER_ENB_REQ (msg_p).uplink_frequency_offset[J] = (unsigned int) uplink_frequency_offset;
-                X2AP_REGISTER_ENB_REQ (msg_p).Nid_cell[J]= Nid_cell;
-
-                if (Nid_cell>503) {
-                  AssertFatal (0,
-                               "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for Nid_cell choice: 0...503 !\n",
-                               RC.config_file_name, k, Nid_cell);
-                }
+	} else {
+	  enb_id = *(ENBParamList.paramarray[k][ENB_ENB_ID_IDX].uptr);
+	}
 
-                X2AP_REGISTER_ENB_REQ (msg_p).N_RB_DL[J]= N_RB_DL;
+	// search if in active list
+	for (j = 0; j < ENBSParams[ENB_ACTIVE_ENBS_IDX].numelt; j++) {
+	  if (strcmp(ENBSParams[ENB_ACTIVE_ENBS_IDX].strlistptr[j], *(ENBParamList.paramarray[k][ENB_ENB_NAME_IDX].strptr)) == 0) {
+	    paramdef_t PLMNParams[] = PLMNPARAMS_DESC;
+	    paramlist_def_t PLMNParamList = {ENB_CONFIG_STRING_PLMN_LIST, NULL, 0};
+	    /* map parameter checking array instances to parameter definition array instances */
+	    checkedparam_t config_check_PLMNParams [] = PLMNPARAMS_CHECK;
+
+	    for (int I = 0; I < sizeof(PLMNParams) / sizeof(paramdef_t); ++I)
+	      PLMNParams[I].chkPptr = &(config_check_PLMNParams[I]);
+
+	    paramdef_t X2Params[]  = X2PARAMS_DESC;
+	    paramlist_def_t X2ParamList = {ENB_CONFIG_STRING_TARGET_ENB_X2_IP_ADDRESS,NULL,0};
+	    paramdef_t SCTPParams[]  = SCTPPARAMS_DESC;
+	    paramdef_t NETParams[]  =  NETPARAMS_DESC;
+	    /* TODO: fix the size - if set lower we have a crash (MAX_OPTNAME_SIZE was 64 when this code was written) */
+	    /* this is most probably a problem with the config module */
+	    char aprefix[MAX_OPTNAME_SIZE*80 + 8];
+	    sprintf(aprefix,"%s.[%i]",ENB_CONFIG_STRING_ENB_LIST,k);
+	    /* Some default/random parameters */
+	    X2AP_REGISTER_ENB_REQ (msg_p).eNB_id = enb_id;
+
+	    if (strcmp(*(ENBParamList.paramarray[k][ENB_CELL_TYPE_IDX].strptr), "CELL_MACRO_ENB") == 0) {
+	      X2AP_REGISTER_ENB_REQ (msg_p).cell_type = CELL_MACRO_ENB;
+	    } else  if (strcmp(*(ENBParamList.paramarray[k][ENB_CELL_TYPE_IDX].strptr), "CELL_HOME_ENB") == 0) {
+	      X2AP_REGISTER_ENB_REQ (msg_p).cell_type = CELL_HOME_ENB;
+	    } else {
+	      AssertFatal (0,
+			   "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for cell_type choice: CELL_MACRO_ENB or CELL_HOME_ENB !\n",
+			   RC.config_file_name, i, *(ENBParamList.paramarray[k][ENB_CELL_TYPE_IDX].strptr));
+	    }
 
-                if ((N_RB_DL!=6) && (N_RB_DL!=15) && (N_RB_DL!=25) && (N_RB_DL!=50) && (N_RB_DL!=75) && (N_RB_DL!=100)) {
-                  AssertFatal (0,
-                               "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for N_RB_DL choice: 6,15,25,50,75,100 !\n",
-                               RC.config_file_name, k, N_RB_DL);
-                }
+	    X2AP_REGISTER_ENB_REQ (msg_p).eNB_name         = strdup(*(ENBParamList.paramarray[k][ENB_ENB_NAME_IDX].strptr));
+	    X2AP_REGISTER_ENB_REQ (msg_p).tac              = *ENBParamList.paramarray[k][ENB_TRACKING_AREA_CODE_IDX].uptr;
+	    config_getlist(&PLMNParamList, PLMNParams, sizeof(PLMNParams)/sizeof(paramdef_t), aprefix);
+
+	    if (PLMNParamList.numelt < 1 || PLMNParamList.numelt > 6)
+	      AssertFatal(0, "The number of PLMN IDs must be in [1,6], but is %d\n",
+			  PLMNParamList.numelt);
+
+
+	    if (PLMNParamList.numelt > 1)
+	      LOG_W(X2AP, "X2AP currently handles only one PLMN, ignoring the others!\n");
+
+	    X2AP_REGISTER_ENB_REQ (msg_p).mcc = *PLMNParamList.paramarray[0][ENB_MOBILE_COUNTRY_CODE_IDX].uptr;
+	    X2AP_REGISTER_ENB_REQ (msg_p).mnc = *PLMNParamList.paramarray[0][ENB_MOBILE_NETWORK_CODE_IDX].uptr;
+	    X2AP_REGISTER_ENB_REQ (msg_p).mnc_digit_length = *PLMNParamList.paramarray[0][ENB_MNC_DIGIT_LENGTH].u8ptr;
+	    AssertFatal(X2AP_REGISTER_ENB_REQ(msg_p).mnc_digit_length == 3
+			|| X2AP_REGISTER_ENB_REQ(msg_p).mnc < 100,
+			"MNC %d cannot be encoded in two digits as requested (change mnc_digit_length to 3)\n",
+			X2AP_REGISTER_ENB_REQ(msg_p).mnc);
+	    /* CC params */
+	    config_getlist(&CCsParamList, NULL, 0, aprefix);
+	    X2AP_REGISTER_ENB_REQ (msg_p).num_cc = CCsParamList.numelt;
+
+	    if (CCsParamList.numelt > 0) {
+	      //char ccspath[MAX_OPTNAME_SIZE*2 + 16];
+	      for (J = 0; J < CCsParamList.numelt ; J++) {
+		sprintf(aprefix, "%s.[%i].%s.[%i]", ENB_CONFIG_STRING_ENB_LIST, k, ENB_CONFIG_STRING_COMPONENT_CARRIERS, J);
+		config_get(CCsParams, sizeof(CCsParams)/sizeof(paramdef_t), aprefix);
+		X2AP_REGISTER_ENB_REQ (msg_p).eutra_band[J] = ccparams_lte.eutra_band;
+		X2AP_REGISTER_ENB_REQ (msg_p).downlink_frequency[J] = (uint32_t) ccparams_lte.downlink_frequency;
+		X2AP_REGISTER_ENB_REQ (msg_p).uplink_frequency_offset[J] = (unsigned int) ccparams_lte.uplink_frequency_offset;
+		X2AP_REGISTER_ENB_REQ (msg_p).Nid_cell[J]= ccparams_lte.Nid_cell;
+
+		if (ccparams_lte.Nid_cell>503) {
+		  AssertFatal (0,
+			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for Nid_cell choice: 0...503 !\n",
+			       RC.config_file_name, k, ccparams_lte.Nid_cell);
+		}
 
-                if (strcmp(frame_type, "FDD") == 0) {
-                  X2AP_REGISTER_ENB_REQ (msg_p).frame_type[J] = FDD;
-                } else  if (strcmp(frame_type, "TDD") == 0) {
-                  X2AP_REGISTER_ENB_REQ (msg_p).frame_type[J] = TDD;
-                } else {
-                  AssertFatal (0,
-                               "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for frame_type choice: FDD or TDD !\n",
-                               RC.config_file_name, k, frame_type);
-                }
+		X2AP_REGISTER_ENB_REQ (msg_p).N_RB_DL[J]= ccparams_lte.N_RB_DL;
 
-                X2AP_REGISTER_ENB_REQ (msg_p).fdd_earfcn_DL[J] = to_earfcn_DL(eutra_band, downlink_frequency, N_RB_DL);
-                X2AP_REGISTER_ENB_REQ (msg_p).fdd_earfcn_UL[J] = to_earfcn_UL(eutra_band, downlink_frequency + uplink_frequency_offset, N_RB_DL);
-              }
-            }
+		if ((ccparams_lte.N_RB_DL!=6) && (ccparams_lte.N_RB_DL!=15) && (ccparams_lte.N_RB_DL!=25) && (ccparams_lte.N_RB_DL!=50) && (ccparams_lte.N_RB_DL!=75) && (ccparams_lte.N_RB_DL!=100)) {
+		  AssertFatal (0,
+			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for N_RB_DL choice: 6,15,25,50,75,100 !\n",
+			       RC.config_file_name, k, ccparams_lte.N_RB_DL);
+		}
 
-            sprintf(aprefix,"%s.[%i]",ENB_CONFIG_STRING_ENB_LIST,k);
-            config_getlist( &X2ParamList,X2Params,sizeof(X2Params)/sizeof(paramdef_t),aprefix);
-            AssertFatal(X2ParamList.numelt <= X2AP_MAX_NB_ENB_IP_ADDRESS,
-                        "value of X2ParamList.numelt %d must be lower than X2AP_MAX_NB_ENB_IP_ADDRESS %d value: reconsider to increase X2AP_MAX_NB_ENB_IP_ADDRESS\n",
-                        X2ParamList.numelt,X2AP_MAX_NB_ENB_IP_ADDRESS);
+		if (strcmp(ccparams_lte.frame_type, "FDD") == 0) {
+		  X2AP_REGISTER_ENB_REQ (msg_p).frame_type[J] = FDD;
+		} else  if (strcmp(ccparams_lte.frame_type, "TDD") == 0) {
+		  X2AP_REGISTER_ENB_REQ (msg_p).frame_type[J] = TDD;
+		} else {
+		  AssertFatal (0,
+			       "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for frame_type choice: FDD or TDD !\n",
+			       RC.config_file_name, k, ccparams_lte.frame_type);
+		}
 
-            X2AP_REGISTER_ENB_REQ (msg_p).nb_x2 = 0;
+		X2AP_REGISTER_ENB_REQ (msg_p).fdd_earfcn_DL[J] = to_earfcn_DL(ccparams_lte.eutra_band, ccparams_lte.downlink_frequency, ccparams_lte.N_RB_DL);
+		X2AP_REGISTER_ENB_REQ (msg_p).fdd_earfcn_UL[J] = to_earfcn_UL(ccparams_lte.eutra_band, ccparams_lte.downlink_frequency + ccparams_lte.uplink_frequency_offset, ccparams_lte.N_RB_DL);
+	      }
+	    }
 
-            for (l = 0; l < X2ParamList.numelt; l++) {
-              X2AP_REGISTER_ENB_REQ (msg_p).nb_x2 += 1;
-              strcpy(X2AP_REGISTER_ENB_REQ (msg_p).target_enb_x2_ip_address[l].ipv4_address,*(X2ParamList.paramarray[l][ENB_X2_IPV4_ADDRESS_IDX].strptr));
-              strcpy(X2AP_REGISTER_ENB_REQ (msg_p).target_enb_x2_ip_address[l].ipv6_address,*(X2ParamList.paramarray[l][ENB_X2_IPV6_ADDRESS_IDX].strptr));
+	    sprintf(aprefix,"%s.[%i]",ENB_CONFIG_STRING_ENB_LIST,k);
+	    config_getlist( &X2ParamList,X2Params,sizeof(X2Params)/sizeof(paramdef_t),aprefix);
+	    AssertFatal(X2ParamList.numelt <= X2AP_MAX_NB_ENB_IP_ADDRESS,
+			"value of X2ParamList.numelt %d must be lower than X2AP_MAX_NB_ENB_IP_ADDRESS %d value: reconsider to increase X2AP_MAX_NB_ENB_IP_ADDRESS\n",
+			X2ParamList.numelt,X2AP_MAX_NB_ENB_IP_ADDRESS);
+	    X2AP_REGISTER_ENB_REQ (msg_p).nb_x2 = 0;
+
+	    for (l = 0; l < X2ParamList.numelt; l++) {
+	      X2AP_REGISTER_ENB_REQ (msg_p).nb_x2 += 1;
+	      strcpy(X2AP_REGISTER_ENB_REQ (msg_p).target_enb_x2_ip_address[l].ipv4_address,*(X2ParamList.paramarray[l][ENB_X2_IPV4_ADDRESS_IDX].strptr));
+	      strcpy(X2AP_REGISTER_ENB_REQ (msg_p).target_enb_x2_ip_address[l].ipv6_address,*(X2ParamList.paramarray[l][ENB_X2_IPV6_ADDRESS_IDX].strptr));
+
+	      if (strcmp(*(X2ParamList.paramarray[l][ENB_X2_IP_ADDRESS_PREFERENCE_IDX].strptr), "ipv4") == 0) {
+		X2AP_REGISTER_ENB_REQ (msg_p).target_enb_x2_ip_address[l].ipv4 = 1;
+	      } else if (strcmp(*(X2ParamList.paramarray[l][ENB_X2_IP_ADDRESS_PREFERENCE_IDX].strptr), "ipv6") == 0) {
+		X2AP_REGISTER_ENB_REQ (msg_p).target_enb_x2_ip_address[l].ipv6 = 1;
+	      } else if (strcmp(*(X2ParamList.paramarray[l][ENB_X2_IP_ADDRESS_PREFERENCE_IDX].strptr), "no") == 0) {
+		X2AP_REGISTER_ENB_REQ (msg_p).target_enb_x2_ip_address[l].ipv4 = 1;
+		X2AP_REGISTER_ENB_REQ (msg_p).target_enb_x2_ip_address[l].ipv6 = 1;
+	      }
+	    }
 
-              if (strcmp(*(X2ParamList.paramarray[l][ENB_X2_IP_ADDRESS_PREFERENCE_IDX].strptr), "ipv4") == 0) {
-                X2AP_REGISTER_ENB_REQ (msg_p).target_enb_x2_ip_address[l].ipv4 = 1;
-              } else if (strcmp(*(X2ParamList.paramarray[l][ENB_X2_IP_ADDRESS_PREFERENCE_IDX].strptr), "ipv6") == 0) {
-                X2AP_REGISTER_ENB_REQ (msg_p).target_enb_x2_ip_address[l].ipv6 = 1;
-              } else if (strcmp(*(X2ParamList.paramarray[l][ENB_X2_IP_ADDRESS_PREFERENCE_IDX].strptr), "no") == 0) {
-                X2AP_REGISTER_ENB_REQ (msg_p).target_enb_x2_ip_address[l].ipv4 = 1;
-                X2AP_REGISTER_ENB_REQ (msg_p).target_enb_x2_ip_address[l].ipv6 = 1;
-              }
-            }
 
-            // 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;
+	    // 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;
 # if defined(ENABLE_USE_MME)
-            sprintf(aprefix,"%s.[%i].%s",ENB_CONFIG_STRING_ENB_LIST,k,ENB_CONFIG_STRING_SCTP_CONFIG);
-            config_get( SCTPParams,sizeof(SCTPParams)/sizeof(paramdef_t),aprefix);
-            X2AP_REGISTER_ENB_REQ (msg_p).sctp_in_streams = (uint16_t)*(SCTPParams[ENB_SCTP_INSTREAMS_IDX].uptr);
-            X2AP_REGISTER_ENB_REQ (msg_p).sctp_out_streams = (uint16_t)*(SCTPParams[ENB_SCTP_OUTSTREAMS_IDX].uptr);
+	    sprintf(aprefix,"%s.[%i].%s",ENB_CONFIG_STRING_ENB_LIST,k,ENB_CONFIG_STRING_SCTP_CONFIG);
+	    config_get( SCTPParams,sizeof(SCTPParams)/sizeof(paramdef_t),aprefix);
+	    X2AP_REGISTER_ENB_REQ (msg_p).sctp_in_streams = (uint16_t)*(SCTPParams[ENB_SCTP_INSTREAMS_IDX].uptr);
+	    X2AP_REGISTER_ENB_REQ (msg_p).sctp_out_streams = (uint16_t)*(SCTPParams[ENB_SCTP_OUTSTREAMS_IDX].uptr);
 #endif
-            sprintf(aprefix,"%s.[%i].%s",ENB_CONFIG_STRING_ENB_LIST,k,ENB_CONFIG_STRING_NETWORK_INTERFACES_CONFIG);
-            // NETWORK_INTERFACES
-            config_get( NETParams,sizeof(NETParams)/sizeof(paramdef_t),aprefix);
-            X2AP_REGISTER_ENB_REQ (msg_p).enb_port_for_X2C = (uint32_t)*(NETParams[ENB_PORT_FOR_X2C_IDX].uptr);
-
-            if ((NETParams[ENB_IPV4_ADDR_FOR_X2C_IDX].strptr == NULL) || (X2AP_REGISTER_ENB_REQ (msg_p).enb_port_for_X2C == 0)) {
-              LOG_E(RRC,"Add eNB IPv4 address and/or port for X2C in the CONF file!\n");
-              exit(1);
-            }
+	    sprintf(aprefix,"%s.[%i].%s",ENB_CONFIG_STRING_ENB_LIST,k,ENB_CONFIG_STRING_NETWORK_INTERFACES_CONFIG);
+	    // NETWORK_INTERFACES
+	    config_get( NETParams,sizeof(NETParams)/sizeof(paramdef_t),aprefix);
+	    X2AP_REGISTER_ENB_REQ (msg_p).enb_port_for_X2C = (uint32_t)*(NETParams[ENB_PORT_FOR_X2C_IDX].uptr);
+
+	    if ((NETParams[ENB_IPV4_ADDR_FOR_X2C_IDX].strptr == NULL) || (X2AP_REGISTER_ENB_REQ (msg_p).enb_port_for_X2C == 0)) {
+	      LOG_E(RRC,"Add eNB IPv4 address and/or port for X2C in the CONF file!\n");
+	      exit(1);
+	    }
 
-            cidr = *(NETParams[ENB_IPV4_ADDR_FOR_X2C_IDX].strptr);
-            address = strtok(cidr, "/");
-            X2AP_REGISTER_ENB_REQ (msg_p).enb_x2_ip_address.ipv6 = 0;
-            X2AP_REGISTER_ENB_REQ (msg_p).enb_x2_ip_address.ipv4 = 1;
-            strcpy(X2AP_REGISTER_ENB_REQ (msg_p).enb_x2_ip_address.ipv4_address, address);
-          }
-        }
+	    cidr = *(NETParams[ENB_IPV4_ADDR_FOR_X2C_IDX].strptr);
+	    address = strtok(cidr, "/");
+	    X2AP_REGISTER_ENB_REQ (msg_p).enb_x2_ip_address.ipv6 = 0;
+	    X2AP_REGISTER_ENB_REQ (msg_p).enb_x2_ip_address.ipv4 = 1;
+	    strcpy(X2AP_REGISTER_ENB_REQ (msg_p).enb_x2_ip_address.ipv4_address, address);
+	  }
+	}
       }
     }
   }
@@ -2647,29 +2346,33 @@ int RCconfig_X2(MessageDef *msg_p, uint32_t i) {
 int RCconfig_parallel(void) {
   char *parallel_conf = NULL;
   char *worker_conf   = NULL;
-  extern char *parallel_config;
-  extern char *worker_config;
+
+
   paramdef_t ThreadParams[]  = THREAD_CONF_DESC;
   paramlist_def_t THREADParamList = {THREAD_CONFIG_STRING_THREAD_STRUCT,NULL,0};
   config_getlist( &THREADParamList,NULL,0,NULL);
 
-  if(THREADParamList.numelt>0) {
-    config_getlist( &THREADParamList,ThreadParams,sizeof(ThreadParams)/sizeof(paramdef_t),NULL);
-    parallel_conf = strdup(*(THREADParamList.paramarray[0][THREAD_PARALLEL_IDX].strptr));
-  } else {
-    parallel_conf = strdup("PARALLEL_RU_L1_TRX_SPLIT");
+  if(parallel_config == NULL){
+    if(THREADParamList.numelt>0) {
+      config_getlist( &THREADParamList,ThreadParams,sizeof(ThreadParams)/sizeof(paramdef_t),NULL);
+      parallel_conf = strdup(*(THREADParamList.paramarray[0][THREAD_PARALLEL_IDX].strptr));
+    } else {
+      parallel_conf = strdup("PARALLEL_RU_L1_TRX_SPLIT");
+    }
+    set_parallel_conf(parallel_conf);
   }
 
-  if(THREADParamList.numelt>0) {
-    config_getlist( &THREADParamList,ThreadParams,sizeof(ThreadParams)/sizeof(paramdef_t),NULL);
-    worker_conf   = strdup(*(THREADParamList.paramarray[0][THREAD_WORKER_IDX].strptr));
-  } else {
-    worker_conf   = strdup("WORKER_ENABLE");
+  if(worker_config == NULL){
+    if(THREADParamList.numelt>0) {
+      config_getlist( &THREADParamList,ThreadParams,sizeof(ThreadParams)/sizeof(paramdef_t),NULL);
+      worker_conf   = strdup(*(THREADParamList.paramarray[0][THREAD_WORKER_IDX].strptr));
+    } else {
+      worker_conf   = strdup("WORKER_ENABLE");
+    }
+    set_worker_conf(worker_conf);
   }
 
-  if(parallel_config == NULL) set_parallel_conf(parallel_conf);
 
-  if(worker_config == NULL)   set_worker_conf(worker_conf);
 
   return 0;
 }
@@ -2694,7 +2397,6 @@ void RCConfig(void) {
 
   if (RC.nb_inst > 0) {
     RC.nb_CC = (int *)malloc((1+RC.nb_inst)*sizeof(int));
-
     for (int i=0; i<RC.nb_inst; i++) {
       sprintf(aprefix,"%s.[%i]",ENB_CONFIG_STRING_ENB_LIST,i);
       config_getlist( &CCsParamList,NULL,0, aprefix);
@@ -2725,7 +2427,7 @@ int check_plmn_identity(rrc_eNB_carrier_data_t *carrier,uint16_t mcc,uint16_t mn
   AssertFatal(mnc_digit_length ==2 || mnc_digit_length == 3,
 	      "impossible mnc_digit_length %d\n",mnc_digit_length);
 
-  PLMN_IdentityInfo_t *plmn_Identity_info = carrier->sib1->cellAccessRelatedInfo.plmn_IdentityList.list.array[0];
+  LTE_PLMN_IdentityInfo_t *plmn_Identity_info = carrier->sib1->cellAccessRelatedInfo.plmn_IdentityList.list.array[0];
 
   // check if mcc is different and return failure if so
   if (mcc != 
@@ -2756,7 +2458,7 @@ void extract_and_decode_SI(int inst,int si_ind,uint8_t *si_container,int si_cont
 
   eNB_RRC_INST *rrc = RC.rrc[inst];
   rrc_eNB_carrier_data_t *carrier = &rrc->carrier[0];
-  BCCH_DL_SCH_Message_t *bcch_message ;
+  LTE_BCCH_DL_SCH_Message_t *bcch_message ;
 
   AssertFatal(si_ind==0,"Can only handle a single SI block for now\n");
 
@@ -2764,7 +2466,7 @@ void extract_and_decode_SI(int inst,int si_ind,uint8_t *si_container,int si_cont
   // point to first SI block
   bcch_message = &carrier->systemInformation;
   asn_dec_rval_t dec_rval = uper_decode_complete( NULL,
-						  &asn_DEF_BCCH_DL_SCH_Message,
+						  &asn_DEF_LTE_BCCH_DL_SCH_Message,
 						  (void **)&bcch_message,
 						  (const void *)si_container,
 						  si_container_length);
@@ -2774,91 +2476,91 @@ void extract_and_decode_SI(int inst,int si_ind,uint8_t *si_container,int si_cont
 		inst,
 		dec_rval.consumed );
   }
-  if (bcch_message->message.present == BCCH_DL_SCH_MessageType_PR_c1) {
+  if (bcch_message->message.present == LTE_BCCH_DL_SCH_MessageType_PR_c1) {
     switch (bcch_message->message.choice.c1.present) {
-    case BCCH_DL_SCH_MessageType__c1_PR_systemInformationBlockType1:
+    case LTE_BCCH_DL_SCH_MessageType__c1_PR_systemInformationBlockType1:
       AssertFatal(1==0,"Should have received SIB1 from CU\n");
       break;
-    case BCCH_DL_SCH_MessageType__c1_PR_systemInformation:
+    case LTE_BCCH_DL_SCH_MessageType__c1_PR_systemInformation:
       {
-	SystemInformation_t *si = &bcch_message->message.choice.c1.choice.systemInformation;
+	LTE_SystemInformation_t *si = &bcch_message->message.choice.c1.choice.systemInformation;
 
 
 	for (int i=0; i<si->criticalExtensions.choice.systemInformation_r8.sib_TypeAndInfo.list.count; i++) {
 	  LOG_I(ENB_APP,"Extracting SI %d/%d\n",i,si->criticalExtensions.choice.systemInformation_r8.sib_TypeAndInfo.list.count);
-	  struct SystemInformation_r8_IEs__sib_TypeAndInfo__Member *typeandinfo;
+	  struct LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member *typeandinfo;
 	  typeandinfo = si->criticalExtensions.choice.systemInformation_r8.sib_TypeAndInfo.list.array[i];
 	  
 	  switch(typeandinfo->present) {
-	  case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib2:
+	  case LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib2:
 	    carrier->sib2 = &typeandinfo->choice.sib2;
 	    carrier->SIB23 = (uint8_t*)malloc(64);
 	    memcpy((void*)carrier->SIB23,(void*)si_container,si_container_length);
 	    carrier->sizeof_SIB23 = si_container_length;
 	    LOG_I( ENB_APP, "[RRC %"PRIu8"] Found SIB2 in CU F1AP_SETUP_RESP message\n", inst);
 	    break;
-	  case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib3:
+	  case LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib3:
 	    carrier->sib3 = &typeandinfo->choice.sib3;
 	    LOG_I( ENB_APP, "[RRC %"PRIu8"] Found SIB3 in CU F1AP_SETUP_RESP message\n", inst);
 	    break;
-	  case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib4:
+	  case LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib4:
 	    //carrier->sib4 = &typeandinfo->choice.sib4;
 	    LOG_I( ENB_APP, "[RRC %"PRIu8"] Found SIB4 in CU F1AP_SETUP_RESP message\n", inst);
 	    break;
-	  case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib5:
+	  case LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib5:
 	    //carrier->sib5 = &typeandinfo->choice.sib5;
 	    LOG_I( ENB_APP, "[RRC %"PRIu8"] Found SIB5 in CU F1AP_SETUP_RESP message\n", inst);
 	    break;
-	  case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib6:
+	  case LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib6:
 	    //carrier->sib6 = &typeandinfo->choice.sib6;
 	    LOG_I( ENB_APP, "[RRC %"PRIu8"] Found SIB6 in CU F1AP_SETUP_RESP message\n", inst);
 	    break;
-	  case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib7:
+	  case LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib7:
 	    //carrier->sib7 = &typeandinfo->choice.sib7;
 	    LOG_I( ENB_APP, "[RRC %"PRIu8"] Found SIB7 in CU F1AP_SETUP_RESP message\n", inst);
 	    break;
-	  case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib8:
+	  case LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib8:
 	    //carrier->sib8 = &typeandinfo->choice.sib8;
 	    LOG_I( ENB_APP, "[RRC %"PRIu8"] Found SIB8 in CU F1AP_SETUP_RESP message\n", inst);
 	    break;
-	  case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib9:
+	  case LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib9:
 	    //carrier->sib9 = &typeandinfo->choice.sib9;
 	    LOG_I( ENB_APP, "[RRC %"PRIu8"] Found SIB9 in CU F1AP_SETUP_RESP message\n", inst);
 	    break;
-	  case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib10:
+	  case LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib10:
 	    //carrier->sib10 = &typeandinfo->choice.sib10;
 	    LOG_I( ENB_APP, "[RRC %"PRIu8"] Found SIB10 in CU F1AP_SETUP_RESP message\n", inst);
 	    break;
-	  case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib11:
+	  case LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib11:
 	    //carrier->sib11 = &typeandinfo->choice.sib11;
 	    LOG_I( ENB_APP, "[RRC %"PRIu8"] Found SIB11 in CU F1AP_SETUP_RESP message\n", inst);
 	    break;
 	    
-#if (RRC_VERSION >= MAKE_VERSION(9, 2, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 2, 0))
 	    
-	  case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib12_v920:
+	  case LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib12_v920:
 	    //carrier->sib12 = &typeandinfo->choice.sib12;
 	    LOG_I( ENB_APP, "[RRC %"PRIu8"] Found SIB12 in CU F1AP_SETUP_RESP message\n", inst);
 	    break;
 	    
-	  case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib13_v920:
+	  case LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib13_v920:
 	    carrier->sib13 = &typeandinfo->choice.sib13_v920;
 	    LOG_I( ENB_APP, "[RRC %"PRIu8"] Found SIB13 in CU F1AP_SETUP_RESP message\n", inst);
 	    break;
 #endif
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 	    //SIB18
-	  case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib18_v1250:
+	  case LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib18_v1250:
 	    carrier->sib18 = &typeandinfo->choice.sib18_v1250;
 	    LOG_I( ENB_APP, "[RRC %"PRIu8"] Found SIB18 in CU F1AP_SETUP_RESP message\n", inst);
 	    break;
 	    //SIB19
-	  case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib19_v1250:
+	  case LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib19_v1250:
 	    carrier->sib19 = &typeandinfo->choice.sib19_v1250;
 	    LOG_I( ENB_APP, "[RRC %"PRIu8"] Found SIB19 in CU F1AP_SETUP_RESP message\n", inst);
 	    break;
 	    //SIB21
-	  case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib21_v1430:
+	  case LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib21_v1430:
 	    carrier->sib21 = &typeandinfo->choice.sib21_v1430;
 	    LOG_I( ENB_APP, "[RRC %"PRIu8"] Found SIB21 in CU F1AP_SETUP_RESP message\n", inst);
 	    break;
@@ -2870,7 +2572,7 @@ void extract_and_decode_SI(int inst,int si_ind,uint8_t *si_container,int si_cont
 	}
 	break;
       }
-      case BCCH_DL_SCH_MessageType__c1_PR_NOTHING:
+      case LTE_BCCH_DL_SCH_MessageType__c1_PR_NOTHING:
         AssertFatal(0, "Should have received SIB1 from CU\n");
         break;
     }
@@ -2894,40 +2596,38 @@ void configure_du_mac(int inst) {
 			 carrier->Ncp,
 			 carrier->sib1->freqBandIndicator,
 			 carrier->dl_CarrierFreq,
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 			 carrier->pbch_repetition,
 #endif
 			 0, // rnti
-			 (BCCH_BCH_Message_t *)
-			 &carrier->mib,
-			 (RadioResourceConfigCommonSIB_t *) &carrier->sib2->radioResourceConfigCommon,
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-			 (RadioResourceConfigCommonSIB_t *) 
-			 NULL,
+			 (LTE_BCCH_BCH_Message_t *) &carrier->mib,
+			 (LTE_RadioResourceConfigCommonSIB_t *) &carrier->sib2->radioResourceConfigCommon,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+			 (LTE_RadioResourceConfigCommonSIB_t *) &carrier->sib2_BR->radioResourceConfigCommon,
 #endif
-			 (struct PhysicalConfigDedicated *)NULL,
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-			 (SCellToAddMod_r10_t *)NULL,
+			 (struct LTE_PhysicalConfigDedicated *)NULL,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+			 (LTE_SCellToAddMod_r10_t *)NULL,
 			 //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
 #endif
-			 (MeasObjectToAddMod_t **) NULL,
-			 (MAC_MainConfig_t *) NULL, 0,
-			 (struct LogicalChannelConfig *)NULL,
-			 (MeasGapConfig_t *) NULL,
-			 NULL,
+			 (LTE_MeasObjectToAddMod_t **) NULL,
+			 (LTE_MAC_MainConfig_t *) NULL, 0,
+			 (struct LTE_LogicalChannelConfig *)NULL,
+			 (LTE_MeasGapConfig_t *) NULL,
+                         carrier->sib1->tdd_Config,
 			 NULL,
 			 &carrier->sib1->schedulingInfoList,
 			 carrier->ul_CarrierFreq,
 			 carrier->sib2->freqInfo.ul_Bandwidth,
 			 &carrier->sib2->freqInfo.additionalSpectrumEmission,
-			 (MBSFN_SubframeConfigList_t*) carrier->sib2->mbsfn_SubframeConfigList
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+			 (LTE_MBSFN_SubframeConfigList_t*) carrier->sib2->mbsfn_SubframeConfigList
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
 			 ,
 			 carrier->MBMS_flag,
-			 (MBSFN_AreaInfoList_r9_t*) & carrier->sib13->mbsfn_AreaInfoList_r9,
-			 (PMCH_InfoList_r9_t *) NULL
+			 (LTE_MBSFN_AreaInfoList_r9_t*) & carrier->sib13->mbsfn_AreaInfoList_r9,
+			 (LTE_PMCH_InfoList_r9_t *) NULL
 #endif
-#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
 			 , 
 			 NULL
 #endif
diff --git a/openair2/ENB_APP/enb_config.h b/openair2/ENB_APP/enb_config.h
index 2fc4fa49580702b529e7a1467703b64f0b89c003..d1aece8b4c47c8f615e25e400306eec090e12987 100644
--- a/openair2/ENB_APP/enb_config.h
+++ b/openair2/ENB_APP/enb_config.h
@@ -41,14 +41,11 @@
 #include "PHY/defs_eNB.h"
 #include "s1ap_messages_types.h"
 #include "f1ap_messages_types.h"
-#ifdef CMAKER
-#include "SystemInformationBlockType2.h"
+#include "LTE_SystemInformationBlockType2.h"
 #include "rrc_messages_types.h"
-#else
-#include "RRC/LTE/MESSAGES/SystemInformationBlockType2.h"
-#endif
 #include "RRC/LTE/rrc_defs.h"
 #include <intertask_interface.h>
+#include "enb_paramdef.h"
 
 #define IPV4_STR_ADDR_TO_INT_NWBO(AdDr_StR,NwBo,MeSsAgE ) do {\
             struct in_addr inp;\
@@ -121,5 +118,8 @@ int RCconfig_S1(MessageDef *msg_p, uint32_t i);
 void read_config_and_init(void);
 int RCconfig_X2(MessageDef *msg_p, uint32_t i);
 
+void fill_SL_configuration(MessageDef *msg_p,  ccparams_sidelink_t *SLconfig,int cell_idx,int cc_idx,char *config_fname);
+void fill_eMTC_configuration(MessageDef *msg_p,  ccparams_eMTC_t *eMTCconfig, int cell_idx,int cc_idx,char *config_fname,char *brparamspath);
+
 #endif /* ENB_CONFIG_H_ */
 /** @} */
diff --git a/openair2/ENB_APP/enb_config_SL.c b/openair2/ENB_APP/enb_config_SL.c
new file mode 100644
index 0000000000000000000000000000000000000000..aecede2db8da25fe465e53f5129a4aec16c2e615
--- /dev/null
+++ b/openair2/ENB_APP/enb_config_SL.c
@@ -0,0 +1,293 @@
+/*
+ * 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
+ */
+
+/*
+  enb_config_SL.c
+  -------------------
+  AUTHOR  : T.T.Nguyen / R. Knopp
+  COMPANY : EURECOM
+  EMAIL   : raymond.knopp@eurecom.fr
+*/
+
+#include <string.h>
+#include <inttypes.h>
+
+#include "common/utils/LOG/log.h"
+#include "assertions.h"
+#include "enb_config.h"
+#include "intertask_interface.h"
+#include "LTE_SystemInformationBlockType2.h"
+#include "common/config/config_userapi.h"
+#include "RRC_config_tools.h"
+#include "enb_paramdef.h"
+#include "enb_paramdef_sidelink.h"
+
+void fill_SL_configuration(MessageDef *msg_p,  ccparams_sidelink_t *SLconfig,int cell_idx,int cc_idx,char *config_fname) {
+
+  printf("Configuring SL\n");
+  //SIB18
+  if (strcmp(SLconfig->rxPool_sc_CP_Len,"normal")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_CP_Len[cc_idx] = LTE_SL_CP_Len_r12_normal;
+  } else if (strcmp(SLconfig->rxPool_sc_CP_Len,"extended")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_CP_Len[cc_idx] = LTE_SL_CP_Len_r12_extended;
+  } else
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for rxPool_sc_CP_Len choice: normal,extended!\n",
+		 config_fname, cell_idx, SLconfig->rxPool_sc_CP_Len);
+
+  if (strcmp(SLconfig->rxPool_sc_Period,"sf40")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[cc_idx] = LTE_SL_PeriodComm_r12_sf40;
+  } else if (strcmp(SLconfig->rxPool_sc_Period,"sf60")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[cc_idx] = LTE_SL_PeriodComm_r12_sf60;
+  } else if (strcmp(SLconfig->rxPool_sc_Period,"sf70")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[cc_idx] = LTE_SL_PeriodComm_r12_sf70;
+  } else if (strcmp(SLconfig->rxPool_sc_Period,"sf80")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[cc_idx] = LTE_SL_PeriodComm_r12_sf80;
+  } else if (strcmp(SLconfig->rxPool_sc_Period,"sf120")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[cc_idx] = LTE_SL_PeriodComm_r12_sf120;
+  } else if (strcmp(SLconfig->rxPool_sc_Period,"sf140")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[cc_idx] = LTE_SL_PeriodComm_r12_sf140;
+  } else if (strcmp(SLconfig->rxPool_sc_Period,"sf160")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[cc_idx] = LTE_SL_PeriodComm_r12_sf160;
+  } else if (strcmp(SLconfig->rxPool_sc_Period,"sf240")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[cc_idx] = LTE_SL_PeriodComm_r12_sf240;
+  } else if (strcmp(SLconfig->rxPool_sc_Period,"sf280")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[cc_idx] = LTE_SL_PeriodComm_r12_sf280;
+  } else if (strcmp(SLconfig->rxPool_sc_Period,"sf320")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[cc_idx] = LTE_SL_PeriodComm_r12_sf320;
+  } else if (strcmp(SLconfig->rxPool_sc_Period,"spare6")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[cc_idx] = LTE_SL_PeriodComm_r12_spare6;
+  } else if (strcmp(SLconfig->rxPool_sc_Period,"spare5")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[cc_idx] = LTE_SL_PeriodComm_r12_spare5;
+  } else if (strcmp(SLconfig->rxPool_sc_Period,"spare4")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[cc_idx] = LTE_SL_PeriodComm_r12_spare4;
+  } else if (strcmp(SLconfig->rxPool_sc_Period,"spare3")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[cc_idx] = LTE_SL_PeriodComm_r12_spare3;
+  } else if (strcmp(SLconfig->rxPool_sc_Period,"spare2")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[cc_idx] = LTE_SL_PeriodComm_r12_spare2;
+  } else if (strcmp(SLconfig->rxPool_sc_Period,"spare")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_sc_Period[cc_idx] = LTE_SL_PeriodComm_r12_spare;
+  } else
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for rxPool_sc_Period choice: sf40,sf60,sf70,sf80,sf120,sf140,sf160,sf240,sf280,sf320,spare6,spare5,spare4,spare3,spare2,spare!\n",
+		 config_fname, cell_idx, SLconfig->rxPool_sc_Period);
+
+  if (strcmp(SLconfig->rxPool_data_CP_Len,"normal")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_data_CP_Len[cc_idx] = LTE_SL_CP_Len_r12_normal;
+  } else if (strcmp(SLconfig->rxPool_data_CP_Len,"extended")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_data_CP_Len[cc_idx] = LTE_SL_CP_Len_r12_extended;
+  } else
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for rxPool_data_CP_Len choice: normal,extended!\n",
+		 config_fname, cell_idx, SLconfig->rxPool_data_CP_Len);
+
+  RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_prb_Num[cc_idx] = SLconfig->rxPool_ResourceConfig_prb_Num;
+  RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_prb_Start[cc_idx] = SLconfig->rxPool_ResourceConfig_prb_Start;
+  RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_prb_End[cc_idx] = SLconfig->rxPool_ResourceConfig_prb_End;
+
+  if (strcmp(SLconfig->rxPool_ResourceConfig_offsetIndicator_present,"prNothing")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_offsetIndicator_present[cc_idx] = LTE_SL_OffsetIndicator_r12_PR_NOTHING;
+  } else if (strcmp(SLconfig->rxPool_ResourceConfig_offsetIndicator_present,"prSmall")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_offsetIndicator_present[cc_idx] = LTE_SL_OffsetIndicator_r12_PR_small_r12;
+  } else if (strcmp(SLconfig->rxPool_ResourceConfig_offsetIndicator_present,"prLarge")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_offsetIndicator_present[cc_idx] = LTE_SL_OffsetIndicator_r12_PR_large_r12;
+  } else
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for rxPool_ResourceConfig_offsetIndicator_present choice: prNothing,prSmal,prLarge!\n",
+		 config_fname, cell_idx, SLconfig->rxPool_ResourceConfig_offsetIndicator_present);
+
+  RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_offsetIndicator_choice[cc_idx] = SLconfig->rxPool_ResourceConfig_offsetIndicator_choice;
+
+  if (strcmp(SLconfig->rxPool_ResourceConfig_subframeBitmap_present,"prNothing")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_subframeBitmap_present[cc_idx] = LTE_SubframeBitmapSL_r12_PR_NOTHING;
+  } else if (strcmp(SLconfig->rxPool_ResourceConfig_subframeBitmap_present,"prBs4")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_subframeBitmap_present[cc_idx] = LTE_SubframeBitmapSL_r12_PR_bs4_r12;
+  } else if (strcmp(SLconfig->rxPool_ResourceConfig_subframeBitmap_present,"prBs8")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_subframeBitmap_present[cc_idx] = LTE_SubframeBitmapSL_r12_PR_bs8_r12;
+  } else if (strcmp(SLconfig->rxPool_ResourceConfig_subframeBitmap_present,"prBs12")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_subframeBitmap_present[cc_idx] = LTE_SubframeBitmapSL_r12_PR_bs12_r12;
+  } else if (strcmp(SLconfig->rxPool_ResourceConfig_subframeBitmap_present,"prBs16")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_subframeBitmap_present[cc_idx] = LTE_SubframeBitmapSL_r12_PR_bs16_r12;
+  } else if (strcmp(SLconfig->rxPool_ResourceConfig_subframeBitmap_present,"prBs30")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_subframeBitmap_present[cc_idx] = LTE_SubframeBitmapSL_r12_PR_bs30_r12;
+  } else if (strcmp(SLconfig->rxPool_ResourceConfig_subframeBitmap_present,"prBs40")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_subframeBitmap_present[cc_idx] = LTE_SubframeBitmapSL_r12_PR_bs40_r12;
+  } else if (strcmp(SLconfig->rxPool_ResourceConfig_subframeBitmap_present,"prBs42")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_subframeBitmap_present[cc_idx] = LTE_SubframeBitmapSL_r12_PR_bs42_r12;
+  } else
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for rxPool_ResourceConfig_subframeBitmap_present choice: prNothing,prBs4,prBs8,prBs12,prBs16,prBs30,prBs40,prBs42!\n",
+		 config_fname, cell_idx, SLconfig->rxPool_ResourceConfig_subframeBitmap_present);
+
+  RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_subframeBitmap_choice_bs_buf[cc_idx] = SLconfig->rxPool_ResourceConfig_subframeBitmap_choice_bs_buf;
+  RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_subframeBitmap_choice_bs_size[cc_idx] = SLconfig->rxPool_ResourceConfig_subframeBitmap_choice_bs_size;
+  RRC_CONFIGURATION_REQ (msg_p).rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[cc_idx] = SLconfig->rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused;
+
+  //SIB19 - for discRxPool
+  if (strcmp(SLconfig->discRxPool_cp_Len,"normal")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPool_cp_Len[cc_idx] = LTE_SL_CP_Len_r12_normal;
+  } else if (strcmp(SLconfig->discRxPool_cp_Len,"extended")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPool_cp_Len[cc_idx] = LTE_SL_CP_Len_r12_extended;
+  } else
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for discRxPool_cp_Len choice: normal,extended!\n",
+		 config_fname, cell_idx, SLconfig->discRxPool_cp_Len);
+
+  if (strcmp(SLconfig->discRxPool_discPeriod,"rf32")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPool_discPeriod[cc_idx] = LTE_SL_DiscResourcePool_r12__discPeriod_r12_rf32;
+  } else if (strcmp(SLconfig->discRxPool_discPeriod,"rf64")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPool_discPeriod[cc_idx] = LTE_SL_DiscResourcePool_r12__discPeriod_r12_rf64;
+  } else if (strcmp(SLconfig->discRxPool_discPeriod,"rf128")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPool_discPeriod[cc_idx] = LTE_SL_DiscResourcePool_r12__discPeriod_r12_rf128;
+  } else if (strcmp(SLconfig->discRxPool_discPeriod,"rf256")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPool_discPeriod[cc_idx] = LTE_SL_DiscResourcePool_r12__discPeriod_r12_rf256;
+  } else if (strcmp(SLconfig->discRxPool_discPeriod,"rf512")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPool_discPeriod[cc_idx] = LTE_SL_DiscResourcePool_r12__discPeriod_r12_rf512;
+  } else if (strcmp(SLconfig->discRxPool_discPeriod,"rf1024")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPool_discPeriod[cc_idx] = LTE_SL_DiscResourcePool_r12__discPeriod_r12_rf1024;
+  } else if (strcmp(SLconfig->discRxPool_discPeriod,"rf16")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPool_discPeriod[cc_idx] = LTE_SL_DiscResourcePool_r12__discPeriod_r12_rf16_v1310;
+  } else if (strcmp(SLconfig->discRxPool_discPeriod,"spare")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPool_discPeriod[cc_idx] = LTE_SL_DiscResourcePool_r12__discPeriod_r12_spare;
+  } else
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for discRxPool_discPeriod choice: rf32,rf64,rf128,rf512,rf1024,rf16,spare!\n",
+		 config_fname, cell_idx, SLconfig->discRxPool_discPeriod);
+
+  RRC_CONFIGURATION_REQ (msg_p).discRxPool_numRetx[cc_idx] = SLconfig->discRxPool_numRetx;
+  RRC_CONFIGURATION_REQ (msg_p).discRxPool_numRepetition[cc_idx] = SLconfig->discRxPool_numRepetition;
+  RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_prb_Num[cc_idx] = SLconfig->discRxPool_ResourceConfig_prb_Num;
+  RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_prb_Start[cc_idx] = SLconfig->discRxPool_ResourceConfig_prb_Start;
+  RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_prb_End[cc_idx] = SLconfig->discRxPool_ResourceConfig_prb_End;
+
+  if (strcmp(SLconfig->discRxPool_ResourceConfig_offsetIndicator_present,"prNothing")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_offsetIndicator_present[cc_idx] = LTE_SL_OffsetIndicator_r12_PR_NOTHING;
+  } else if (strcmp(SLconfig->discRxPool_ResourceConfig_offsetIndicator_present,"prSmall")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_offsetIndicator_present[cc_idx] = LTE_SL_OffsetIndicator_r12_PR_small_r12;
+  } else if (strcmp(SLconfig->discRxPool_ResourceConfig_offsetIndicator_present,"prLarge")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_offsetIndicator_present[cc_idx] = LTE_SL_OffsetIndicator_r12_PR_large_r12;
+  } else
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for discRxPool_ResourceConfig_offsetIndicator_present choice: prNothing,prSmal,prLarge!\n",
+		 config_fname, cell_idx, SLconfig->discRxPool_ResourceConfig_offsetIndicator_present);
+
+  RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_offsetIndicator_choice[cc_idx] = SLconfig->discRxPool_ResourceConfig_offsetIndicator_choice;
+
+  if (strcmp(SLconfig->discRxPool_ResourceConfig_subframeBitmap_present,"prNothing")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_subframeBitmap_present[cc_idx] = LTE_SubframeBitmapSL_r12_PR_NOTHING;
+  } else if (strcmp(SLconfig->discRxPool_ResourceConfig_subframeBitmap_present,"prBs4")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_subframeBitmap_present[cc_idx] = LTE_SubframeBitmapSL_r12_PR_bs4_r12;
+  } else if (strcmp(SLconfig->discRxPool_ResourceConfig_subframeBitmap_present,"prBs8")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_subframeBitmap_present[cc_idx] = LTE_SubframeBitmapSL_r12_PR_bs8_r12;
+  } else if (strcmp(SLconfig->discRxPool_ResourceConfig_subframeBitmap_present,"prBs12")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_subframeBitmap_present[cc_idx] = LTE_SubframeBitmapSL_r12_PR_bs12_r12;
+  } else if (strcmp(SLconfig->discRxPool_ResourceConfig_subframeBitmap_present,"prBs16")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_subframeBitmap_present[cc_idx] = LTE_SubframeBitmapSL_r12_PR_bs16_r12;
+  } else if (strcmp(SLconfig->discRxPool_ResourceConfig_subframeBitmap_present,"prBs30")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_subframeBitmap_present[cc_idx] = LTE_SubframeBitmapSL_r12_PR_bs30_r12;
+  } else if (strcmp(SLconfig->discRxPool_ResourceConfig_subframeBitmap_present,"prBs40")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_subframeBitmap_present[cc_idx] = LTE_SubframeBitmapSL_r12_PR_bs40_r12;
+  } else if (strcmp(SLconfig->discRxPool_ResourceConfig_subframeBitmap_present,"prBs42")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_subframeBitmap_present[cc_idx] = LTE_SubframeBitmapSL_r12_PR_bs42_r12;
+  } else
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for discRxPool_ResourceConfig_subframeBitmap_present choice: prNothing,prBs4,prBs8,prBs12,prBs16,prBs30,prBs40,prBs42!\n",
+		 config_fname, cell_idx, SLconfig->discRxPool_ResourceConfig_subframeBitmap_present);
+
+  RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf[cc_idx] = SLconfig->discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf;
+  RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_subframeBitmap_choice_bs_size[cc_idx] = SLconfig->discRxPool_ResourceConfig_subframeBitmap_choice_bs_size;
+  RRC_CONFIGURATION_REQ (msg_p).discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[cc_idx] = SLconfig->discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused;
+
+  //SIB19 - For discRxPoolPS
+  if (strcmp(SLconfig->discRxPoolPS_cp_Len,"normal")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_cp_Len[cc_idx] = LTE_SL_CP_Len_r12_normal;
+  } else if (strcmp(SLconfig->discRxPoolPS_cp_Len,"extended")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_cp_Len[cc_idx] = LTE_SL_CP_Len_r12_extended;
+  } else
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for discRxPoolPS_cp_Len choice: normal,extended!\n",
+		 config_fname, cell_idx, SLconfig->discRxPoolPS_cp_Len);
+
+  if (strcmp(SLconfig->discRxPoolPS_discPeriod,"rf32")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_discPeriod[cc_idx] = LTE_SL_DiscResourcePool_r12__discPeriod_r12_rf32;
+  } else if (strcmp(SLconfig->discRxPoolPS_discPeriod,"rf64")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_discPeriod[cc_idx] = LTE_SL_DiscResourcePool_r12__discPeriod_r12_rf64;
+  } else if (strcmp(SLconfig->discRxPoolPS_discPeriod,"rf128")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_discPeriod[cc_idx] = LTE_SL_DiscResourcePool_r12__discPeriod_r12_rf128;
+  } else if (strcmp(SLconfig->discRxPoolPS_discPeriod,"rf256")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_discPeriod[cc_idx] = LTE_SL_DiscResourcePool_r12__discPeriod_r12_rf256;
+  } else if (strcmp(SLconfig->discRxPoolPS_discPeriod,"rf512")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_discPeriod[cc_idx] = LTE_SL_DiscResourcePool_r12__discPeriod_r12_rf512;
+  } else if (strcmp(SLconfig->discRxPoolPS_discPeriod,"rf1024")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_discPeriod[cc_idx] = LTE_SL_DiscResourcePool_r12__discPeriod_r12_rf1024;
+  } else if (strcmp(SLconfig->discRxPoolPS_discPeriod,"rf16")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_discPeriod[cc_idx] = LTE_SL_DiscResourcePool_r12__discPeriod_r12_rf16_v1310;
+  } else if (strcmp(SLconfig->discRxPoolPS_discPeriod,"spare")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_discPeriod[cc_idx] = LTE_SL_DiscResourcePool_r12__discPeriod_r12_spare;
+  } else
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for discRxPoolPS_discPeriod choice: rf32,rf64,rf128,rf512,rf1024,rf16,spare!\n",
+		 config_fname, cell_idx, SLconfig->discRxPoolPS_discPeriod);
+
+  RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_numRetx[cc_idx] = SLconfig->discRxPoolPS_numRetx;
+  RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_numRepetition[cc_idx] = SLconfig->discRxPoolPS_numRepetition;
+  RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_prb_Num[cc_idx] = SLconfig->discRxPoolPS_ResourceConfig_prb_Num;
+  RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_prb_Start[cc_idx] = SLconfig->discRxPoolPS_ResourceConfig_prb_Start;
+  RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_prb_End[cc_idx] = SLconfig->discRxPoolPS_ResourceConfig_prb_End;
+
+  if (strcmp(SLconfig->discRxPoolPS_ResourceConfig_offsetIndicator_present,"prNothing")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_offsetIndicator_present[cc_idx] = LTE_SL_OffsetIndicator_r12_PR_NOTHING;
+  } else if (strcmp(SLconfig->discRxPoolPS_ResourceConfig_offsetIndicator_present,"prSmall")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_offsetIndicator_present[cc_idx] = LTE_SL_OffsetIndicator_r12_PR_small_r12;
+  } else if (strcmp(SLconfig->discRxPoolPS_ResourceConfig_offsetIndicator_present,"prLarge")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_offsetIndicator_present[cc_idx] = LTE_SL_OffsetIndicator_r12_PR_large_r12;
+  } else
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for discRxPoolPS_ResourceConfig_offsetIndicator_present choice: prNothing,prSmal,prLarge!\n",
+		 config_fname, cell_idx, SLconfig->discRxPoolPS_ResourceConfig_offsetIndicator_present);
+
+  RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_offsetIndicator_choice[cc_idx] = SLconfig->discRxPoolPS_ResourceConfig_offsetIndicator_choice;
+
+  if (strcmp(SLconfig->discRxPoolPS_ResourceConfig_subframeBitmap_present,"prNothing")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_subframeBitmap_present[cc_idx] = LTE_SubframeBitmapSL_r12_PR_NOTHING;
+  } else if (strcmp(SLconfig->discRxPoolPS_ResourceConfig_subframeBitmap_present,"prBs4")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_subframeBitmap_present[cc_idx] = LTE_SubframeBitmapSL_r12_PR_bs4_r12;
+  } else if (strcmp(SLconfig->discRxPoolPS_ResourceConfig_subframeBitmap_present,"prBs8")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_subframeBitmap_present[cc_idx] = LTE_SubframeBitmapSL_r12_PR_bs8_r12;
+  } else if (strcmp(SLconfig->discRxPoolPS_ResourceConfig_subframeBitmap_present,"prBs12")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_subframeBitmap_present[cc_idx] = LTE_SubframeBitmapSL_r12_PR_bs12_r12;
+  } else if (strcmp(SLconfig->discRxPoolPS_ResourceConfig_subframeBitmap_present,"prBs16")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_subframeBitmap_present[cc_idx] = LTE_SubframeBitmapSL_r12_PR_bs16_r12;
+  } else if (strcmp(SLconfig->discRxPoolPS_ResourceConfig_subframeBitmap_present,"prBs30")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_subframeBitmap_present[cc_idx] = LTE_SubframeBitmapSL_r12_PR_bs30_r12;
+  } else if (strcmp(SLconfig->discRxPoolPS_ResourceConfig_subframeBitmap_present,"prBs40")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_subframeBitmap_present[cc_idx] = LTE_SubframeBitmapSL_r12_PR_bs40_r12;
+  } else if (strcmp(SLconfig->discRxPoolPS_ResourceConfig_subframeBitmap_present,"prBs42")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_subframeBitmap_present[cc_idx] = LTE_SubframeBitmapSL_r12_PR_bs42_r12;
+  } else
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for discRxPoolPS_ResourceConfig_subframeBitmap_present choice: prNothing,prBs4,prBs8,prBs12,prBs16,prBs30,prBs40,prBs42!\n",
+		 config_fname, cell_idx, SLconfig->discRxPoolPS_ResourceConfig_subframeBitmap_present);
+
+  RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_buf[cc_idx] = SLconfig->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_buf;
+  RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_size[cc_idx] = SLconfig->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_size;
+  RRC_CONFIGURATION_REQ (msg_p).discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_bits_unused[cc_idx] = SLconfig->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_bits_unused;
+} // sidelink_configured==1
diff --git a/openair2/ENB_APP/enb_config_eMTC.c b/openair2/ENB_APP/enb_config_eMTC.c
new file mode 100644
index 0000000000000000000000000000000000000000..5a8362300e094f99e9be3c344ac64b5d913ac863
--- /dev/null
+++ b/openair2/ENB_APP/enb_config_eMTC.c
@@ -0,0 +1,1210 @@
+/*
+ * 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
+ */
+
+/*
+  enb_config_SL.c
+  -------------------
+  AUTHOR  : R. Knopp
+  COMPANY : EURECOM
+  EMAIL   : raymond.knopp@eurecom.fr
+*/
+
+#include <string.h>
+#include <inttypes.h>
+
+#include "common/utils/LOG/log.h"
+#include "assertions.h"
+#include "enb_config.h"
+#include "intertask_interface.h"
+#include "LTE_SystemInformationBlockType2.h"
+#include "common/config/config_userapi.h"
+#include "RRC_config_tools.h"
+#include "enb_paramdef.h"
+
+void fill_eMTC_configuration(MessageDef *msg_p,  ccparams_eMTC_t *eMTCconfig, int cell_idx,int cc_idx,char *config_fname,char *brparamspath) {
+
+  paramdef_t schedulingInfoBrParams[] = SI_INFO_BR_DESC(eMTCconfig);
+  paramlist_def_t schedulingInfoBrParamList = {ENB_CONFIG_STRING_SCHEDULING_INFO_BR, NULL, 0};
+  paramdef_t rachcelevelParams[]     = RACH_CE_LEVELINFOLIST_R13_DESC(eMTCconfig);
+  paramlist_def_t rachcelevellist    = {ENB_CONFIG_STRING_RACH_CE_LEVELINFOLIST_R13, NULL, 0};
+  paramdef_t rsrprangeParams[]       = RSRP_RANGE_LIST_DESC(eMTCconfig);
+  paramlist_def_t rsrprangelist      = {ENB_CONFIG_STRING_RSRP_RANGE_LIST, NULL, 0};
+  paramdef_t prachParams[]           = PRACH_PARAMS_CE_R13_DESC(eMTCconfig);
+  paramlist_def_t prachParamslist    = {ENB_CONFIG_STRING_PRACH_PARAMETERS_CE_R13, NULL, 0};
+  paramdef_t n1PUCCH_ANR13Params[]   = N1PUCCH_AN_INFOLIST_R13_DESC(eMTCconfig);
+  paramlist_def_t n1PUCCHInfoList    = {ENB_CONFIG_STRING_N1PUCCH_AN_INFOLIST_R13, NULL, 0};
+  paramdef_t pcchv1310Params[]       = PCCH_CONFIG_V1310_DESC(eMTCconfig);
+  paramdef_t sib2freqhoppingParams[] = SIB2_FREQ_HOPPING_R13_DESC(eMTCconfig);
+
+
+
+  printf("Found parameters for eMTC from %s : %s\n",config_fname,brparamspath);
+  RRC_CONFIGURATION_REQ(msg_p).schedulingInfoSIB1_BR_r13[cc_idx] = eMTCconfig->schedulingInfoSIB1_BR_r13;
+
+
+  if (!strcmp(eMTCconfig->cellSelectionInfoCE_r13, "ENABLE")) {
+    RRC_CONFIGURATION_REQ(msg_p).cellSelectionInfoCE_r13[cc_idx] = TRUE;
+    RRC_CONFIGURATION_REQ(msg_p).q_RxLevMinCE_r13[cc_idx]= eMTCconfig->q_RxLevMinCE_r13;
+    //                            RRC_CONFIGURATION_REQ(msg_p).q_QualMinRSRQ_CE_r13[cc_idx]= calloc(1, sizeof(long));
+    //                            *RRC_CONFIGURATION_REQ(msg_p).q_QualMinRSRQ_CE_r13[cc_idx]= q_QualMinRSRQ_CE_r13;
+  } else {
+    RRC_CONFIGURATION_REQ(msg_p).cellSelectionInfoCE_r13[cc_idx] = FALSE;
+  }
+
+
+
+  if (!strcmp(eMTCconfig->bandwidthReducedAccessRelatedInfo_r13, "ENABLE")) {
+    RRC_CONFIGURATION_REQ(msg_p).bandwidthReducedAccessRelatedInfo_r13[cc_idx] = TRUE;
+
+
+
+    if (!strcmp(eMTCconfig->si_WindowLength_BR_r13, "ms20")) {
+      RRC_CONFIGURATION_REQ(msg_p).si_WindowLength_BR_r13[cc_idx] = 0;
+    } else if (!strcmp(eMTCconfig->si_WindowLength_BR_r13, "ms40")) {
+      RRC_CONFIGURATION_REQ(msg_p).si_WindowLength_BR_r13[cc_idx] = 1;
+    } else if (!strcmp(eMTCconfig->si_WindowLength_BR_r13, "ms60")) {
+      RRC_CONFIGURATION_REQ(msg_p).si_WindowLength_BR_r13[cc_idx] = 2;
+    } else if (!strcmp(eMTCconfig->si_WindowLength_BR_r13, "ms80")) {
+      RRC_CONFIGURATION_REQ(msg_p).si_WindowLength_BR_r13[cc_idx] = 3;
+    } else if (!strcmp(eMTCconfig->si_WindowLength_BR_r13, "ms120")) {
+      RRC_CONFIGURATION_REQ(msg_p).si_WindowLength_BR_r13[cc_idx] = 4;
+    } else if (!strcmp(eMTCconfig->si_WindowLength_BR_r13, "ms160")) {
+      RRC_CONFIGURATION_REQ(msg_p).si_WindowLength_BR_r13[cc_idx] = 5;
+    } else if (!strcmp(eMTCconfig->si_WindowLength_BR_r13, "ms200")) {
+      RRC_CONFIGURATION_REQ(msg_p).si_WindowLength_BR_r13[cc_idx] = 6;
+    } else if (!strcmp(eMTCconfig->si_WindowLength_BR_r13, "spare")) {
+      RRC_CONFIGURATION_REQ(msg_p).si_WindowLength_BR_r13[cc_idx] = 7;
+    }
+
+
+    if (!strcmp(eMTCconfig->si_RepetitionPattern_r13, "everyRF")) {
+      RRC_CONFIGURATION_REQ(msg_p).si_RepetitionPattern_r13[cc_idx] = 0;
+    } else if (!strcmp(eMTCconfig->si_RepetitionPattern_r13, "every2ndRF")) {
+      RRC_CONFIGURATION_REQ(msg_p).si_RepetitionPattern_r13[cc_idx] = 1;
+    } else if (!strcmp(eMTCconfig->si_RepetitionPattern_r13, "every4thRF")) {
+      RRC_CONFIGURATION_REQ(msg_p).si_RepetitionPattern_r13[cc_idx] = 2;
+    } else if (!strcmp(eMTCconfig->si_RepetitionPattern_r13, "every8thRF")) {
+      RRC_CONFIGURATION_REQ(msg_p).si_RepetitionPattern_r13[cc_idx] = 3;
+    }
+
+  } else {
+    RRC_CONFIGURATION_REQ(msg_p).bandwidthReducedAccessRelatedInfo_r13[cc_idx] = FALSE;
+  }
+
+  char schedulingInfoBrPath[MAX_OPTNAME_SIZE * 2];
+  config_getlist(&schedulingInfoBrParamList, NULL, 0, brparamspath);
+  RRC_CONFIGURATION_REQ (msg_p).scheduling_info_br_size[cc_idx] = schedulingInfoBrParamList.numelt;
+  int siInfoindex;
+  for (siInfoindex = 0; siInfoindex < schedulingInfoBrParamList.numelt; siInfoindex++) {
+    sprintf(schedulingInfoBrPath, "%s.%s.[%i]", brparamspath, ENB_CONFIG_STRING_EMTC_PARAMETERS, siInfoindex);
+    config_get(schedulingInfoBrParams, sizeof(schedulingInfoBrParams) / sizeof(paramdef_t), schedulingInfoBrPath);
+    RRC_CONFIGURATION_REQ (msg_p).si_Narrowband_r13[cc_idx][siInfoindex] = eMTCconfig->si_Narrowband_r13;
+    RRC_CONFIGURATION_REQ (msg_p).si_TBS_r13[cc_idx][siInfoindex] = eMTCconfig->si_TBS_r13;
+  }
+
+
+
+  //                        RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig[cc_idx].system_info_value_tag_SI_size[cc_idx] = 0;
+
+
+  RRC_CONFIGURATION_REQ(msg_p).fdd_DownlinkOrTddSubframeBitmapBR_r13[cc_idx] = CALLOC(1, sizeof(BOOLEAN_t));
+  if (!strcmp(eMTCconfig->fdd_DownlinkOrTddSubframeBitmapBR_r13, "subframePattern40-r13")) {
+    *RRC_CONFIGURATION_REQ(msg_p).fdd_DownlinkOrTddSubframeBitmapBR_r13[cc_idx] = FALSE;
+    RRC_CONFIGURATION_REQ(msg_p).fdd_DownlinkOrTddSubframeBitmapBR_val_r13[cc_idx] = eMTCconfig->fdd_DownlinkOrTddSubframeBitmapBR_val_r13;
+  } else {
+    *RRC_CONFIGURATION_REQ(msg_p).fdd_DownlinkOrTddSubframeBitmapBR_r13[cc_idx] = TRUE;
+    RRC_CONFIGURATION_REQ(msg_p).fdd_DownlinkOrTddSubframeBitmapBR_val_r13[cc_idx] = eMTCconfig->fdd_DownlinkOrTddSubframeBitmapBR_val_r13;
+  }
+
+  RRC_CONFIGURATION_REQ(msg_p).startSymbolBR_r13[cc_idx] = eMTCconfig->startSymbolBR_r13;
+
+
+  if (!strcmp(eMTCconfig->si_HoppingConfigCommon_r13, "off")) {
+    RRC_CONFIGURATION_REQ(msg_p).si_HoppingConfigCommon_r13[cc_idx] = 1;
+  } else if (!strcmp(eMTCconfig->si_HoppingConfigCommon_r13, "on")) {
+    RRC_CONFIGURATION_REQ(msg_p).si_HoppingConfigCommon_r13[cc_idx] = 0;
+  }
+
+
+  RRC_CONFIGURATION_REQ(msg_p).si_ValidityTime_r13[cc_idx] = calloc(1, sizeof(long));
+  if (!strcmp(eMTCconfig->si_ValidityTime_r13, "true")) {
+    *RRC_CONFIGURATION_REQ(msg_p).si_ValidityTime_r13[cc_idx] = 0;
+  } else {
+    AssertFatal(0,
+		"Failed to parse eNB configuration file %s, enb %d  si_ValidityTime_r13 unknown value!\n",
+		config_fname, cell_idx);
+  }
+
+
+  if (!strcmp(eMTCconfig->freqHoppingParametersDL_r13, "ENABLE"))
+    {
+      RRC_CONFIGURATION_REQ(msg_p).freqHoppingParametersDL_r13[cc_idx] = TRUE;
+
+      if (!strcmp(eMTCconfig->interval_DLHoppingConfigCommonModeA_r13, "interval-TDD-r13"))
+	RRC_CONFIGURATION_REQ(msg_p).interval_DLHoppingConfigCommonModeA_r13[cc_idx] = FALSE;
+      else
+	RRC_CONFIGURATION_REQ(msg_p).interval_DLHoppingConfigCommonModeA_r13[cc_idx] = TRUE;
+      RRC_CONFIGURATION_REQ(msg_p).interval_DLHoppingConfigCommonModeA_r13_val[cc_idx] = eMTCconfig->interval_DLHoppingConfigCommonModeA_r13_val;
+
+      if (!strcmp(eMTCconfig->interval_DLHoppingConfigCommonModeB_r13, "interval-TDD-r13"))
+	RRC_CONFIGURATION_REQ(msg_p).interval_DLHoppingConfigCommonModeB_r13[cc_idx] = FALSE;
+      else
+	RRC_CONFIGURATION_REQ(msg_p).interval_DLHoppingConfigCommonModeB_r13[cc_idx] = TRUE;
+      RRC_CONFIGURATION_REQ(msg_p).interval_DLHoppingConfigCommonModeB_r13_val[cc_idx] = eMTCconfig->interval_DLHoppingConfigCommonModeB_r13_val;
+
+      RRC_CONFIGURATION_REQ(msg_p).mpdcch_pdsch_HoppingNB_r13[cc_idx] = calloc(1, sizeof(long));
+      if (!strcmp(eMTCconfig->mpdcch_pdsch_HoppingNB_r13, "nb2")) {
+	*RRC_CONFIGURATION_REQ(msg_p).mpdcch_pdsch_HoppingNB_r13[cc_idx] = 0;
+      } else if (!strcmp(eMTCconfig->mpdcch_pdsch_HoppingNB_r13, "nb4")) {
+	*RRC_CONFIGURATION_REQ(msg_p).mpdcch_pdsch_HoppingNB_r13[cc_idx] = 1;
+      } else {
+	AssertFatal(0,
+		    "Failed to parse eNB configuration file %s, enb %d  mpdcch_pdsch_HoppingNB_r13 unknown value!\n",
+		    config_fname, cell_idx);
+      }
+
+
+      RRC_CONFIGURATION_REQ(msg_p).mpdcch_pdsch_HoppingOffset_r13[cc_idx] = calloc(1, sizeof(long));
+      *RRC_CONFIGURATION_REQ(msg_p).mpdcch_pdsch_HoppingOffset_r13[cc_idx] = eMTCconfig->mpdcch_pdsch_HoppingOffset_r13;
+
+    }
+  else
+    {
+      RRC_CONFIGURATION_REQ(msg_p).freqHoppingParametersDL_r13[cc_idx] = FALSE;
+    }
+
+  /** ------------------------------SIB2/3 BR------------------------------------------ */
+
+
+  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].prach_root =  eMTCconfig->ccparams.prach_root;
+
+  if ((eMTCconfig->ccparams.prach_root <0) || (eMTCconfig->ccparams.prach_root > 1023))
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for prach_root choice: 0..1023 !\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.prach_root);
+
+  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].prach_config_index = eMTCconfig->ccparams.prach_config_index;
+
+  if ((eMTCconfig->ccparams.prach_config_index <0) || (eMTCconfig->ccparams.prach_config_index > 63))
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for prach_config_index choice: 0..1023 !\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.prach_config_index);
+
+  if (!eMTCconfig->ccparams.prach_high_speed)
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d define %s: ENABLE,DISABLE!\n",
+		 config_fname, cell_idx,ENB_CONFIG_STRING_PRACH_HIGH_SPEED);
+  else if (strcmp(eMTCconfig->ccparams.prach_high_speed, "ENABLE") == 0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].prach_high_speed = TRUE;
+  } else if (strcmp(eMTCconfig->ccparams.prach_high_speed, "DISABLE") == 0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].prach_high_speed = FALSE;
+  } else
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for prach_config choice: ENABLE,DISABLE !\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.prach_high_speed);
+
+  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].prach_zero_correlation = eMTCconfig->ccparams.prach_zero_correlation;
+
+  if ((eMTCconfig->ccparams.prach_zero_correlation <0) || (eMTCconfig->ccparams.prach_zero_correlation > 15))
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for prach_zero_correlation choice: 0..15!\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.prach_zero_correlation);
+
+  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].prach_freq_offset = eMTCconfig->ccparams.prach_freq_offset;
+
+  if ((eMTCconfig->ccparams.prach_freq_offset <0) || (eMTCconfig->ccparams.prach_freq_offset > 94))
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for prach_freq_offset choice: 0..94!\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.prach_freq_offset);
+
+  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pucch_delta_shift = eMTCconfig->ccparams.pucch_delta_shift-1;
+
+  if ((eMTCconfig->ccparams.pucch_delta_shift <1) || (eMTCconfig->ccparams.pucch_delta_shift > 3))
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pucch_delta_shift choice: 1..3!\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.pucch_delta_shift);
+
+  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pucch_nRB_CQI = eMTCconfig->ccparams.pucch_nRB_CQI;
+
+  if ((eMTCconfig->ccparams.pucch_nRB_CQI <0) || (eMTCconfig->ccparams.pucch_nRB_CQI > 98))
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pucch_nRB_CQI choice: 0..98!\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.pucch_nRB_CQI);
+
+  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pucch_nCS_AN = eMTCconfig->ccparams.pucch_nCS_AN;
+
+  if ((eMTCconfig->ccparams.pucch_nCS_AN <0) || (eMTCconfig->ccparams.pucch_nCS_AN > 7))
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pucch_nCS_AN choice: 0..7!\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.pucch_nCS_AN);
+
+  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pucch_n1_AN = eMTCconfig->ccparams.pucch_n1_AN;
+
+  if ((eMTCconfig->ccparams.pucch_n1_AN <0) || (eMTCconfig->ccparams.pucch_n1_AN > 2047))
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pucch_n1_AN choice: 0..2047!\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.pucch_n1_AN);
+
+  //#endif
+  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pdsch_referenceSignalPower = eMTCconfig->ccparams.pdsch_referenceSignalPower;
+
+  if ((eMTCconfig->ccparams.pdsch_referenceSignalPower <-60) || (eMTCconfig->ccparams.pdsch_referenceSignalPower > 50))
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pdsch_referenceSignalPower choice:-60..50!\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.pdsch_referenceSignalPower);
+
+  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pdsch_p_b = eMTCconfig->ccparams.pdsch_p_b;
+
+  if ((eMTCconfig->ccparams.pdsch_p_b <0) || (eMTCconfig->ccparams.pdsch_p_b > 3))
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pdsch_p_b choice: 0..3!\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.pdsch_p_b);
+
+  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pusch_n_SB = eMTCconfig->ccparams.pusch_n_SB;
+
+  if ((eMTCconfig->ccparams.pusch_n_SB <1) || (eMTCconfig->ccparams.pusch_n_SB > 4))
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pusch_n_SB choice: 1..4!\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.pusch_n_SB);
+
+  if (!eMTCconfig->ccparams.pusch_hoppingMode)
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d define %s: interSubframe,intraAndInterSubframe!\n",
+		 config_fname, cell_idx,ENB_CONFIG_STRING_PUSCH_HOPPINGMODE);
+  else if (strcmp(eMTCconfig->ccparams.pusch_hoppingMode,"interSubFrame")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pusch_hoppingMode = LTE_PUSCH_ConfigCommon__pusch_ConfigBasic__hoppingMode_interSubFrame;
+  }  else if (strcmp(eMTCconfig->ccparams.pusch_hoppingMode,"intraAndInterSubFrame")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pusch_hoppingMode = LTE_PUSCH_ConfigCommon__pusch_ConfigBasic__hoppingMode_intraAndInterSubFrame;
+  } else
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pusch_hoppingMode choice: interSubframe,intraAndInterSubframe!\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.pusch_hoppingMode);
+
+  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pusch_hoppingOffset = eMTCconfig->ccparams.pusch_hoppingOffset;
+
+  if ((eMTCconfig->ccparams.pusch_hoppingOffset<0) || (eMTCconfig->ccparams.pusch_hoppingOffset>98))
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pusch_hoppingOffset choice: 0..98!\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.pusch_hoppingMode);
+
+  if (!eMTCconfig->ccparams.pusch_enable64QAM)
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d define %s: ENABLE,DISABLE!\n",
+		 config_fname, cell_idx,ENB_CONFIG_STRING_PUSCH_ENABLE64QAM);
+  else if (strcmp(eMTCconfig->ccparams.pusch_enable64QAM, "ENABLE") == 0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pusch_enable64QAM = TRUE;
+  }  else if (strcmp(eMTCconfig->ccparams.pusch_enable64QAM, "DISABLE") == 0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pusch_enable64QAM = FALSE;
+  } else
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pusch_enable64QAM choice: ENABLE,DISABLE!\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.pusch_enable64QAM);
+
+  if (!eMTCconfig->ccparams.pusch_groupHoppingEnabled)
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d define %s: ENABLE,DISABLE!\n",
+		 config_fname, cell_idx,ENB_CONFIG_STRING_PUSCH_GROUP_HOPPING_EN);
+  else if (strcmp(eMTCconfig->ccparams.pusch_groupHoppingEnabled, "ENABLE") == 0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pusch_groupHoppingEnabled = TRUE;
+  }  else if (strcmp(eMTCconfig->ccparams.pusch_groupHoppingEnabled, "DISABLE") == 0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pusch_groupHoppingEnabled= FALSE;
+  } else
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pusch_groupHoppingEnabled choice: ENABLE,DISABLE!\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.pusch_groupHoppingEnabled);
+
+  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pusch_groupAssignment = eMTCconfig->ccparams.pusch_groupAssignment;
+
+  if ((eMTCconfig->ccparams.pusch_groupAssignment<0)||(eMTCconfig->ccparams.pusch_groupAssignment>29))
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pusch_groupAssignment choice: 0..29!\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.pusch_groupAssignment);
+
+  if (!eMTCconfig->ccparams.pusch_sequenceHoppingEnabled)
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d define %s: ENABLE,DISABLE!\n",
+		 config_fname, cell_idx,ENB_CONFIG_STRING_PUSCH_SEQUENCE_HOPPING_EN);
+  else if (strcmp(eMTCconfig->ccparams.pusch_sequenceHoppingEnabled, "ENABLE") == 0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pusch_sequenceHoppingEnabled = TRUE;
+  }  else if (strcmp(eMTCconfig->ccparams.pusch_sequenceHoppingEnabled, "DISABLE") == 0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pusch_sequenceHoppingEnabled = FALSE;
+  } else
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pusch_sequenceHoppingEnabled choice: ENABLE,DISABLE!\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.pusch_sequenceHoppingEnabled);
+
+  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pusch_nDMRS1= eMTCconfig->ccparams.pusch_nDMRS1;  //cyclic_shift in RRC!
+
+  if ((eMTCconfig->ccparams.pusch_nDMRS1 <0) || (eMTCconfig->ccparams.pusch_nDMRS1>7))
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pusch_nDMRS1 choice: 0..7!\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.pusch_nDMRS1);
+
+  if (strcmp(eMTCconfig->ccparams.phich_duration,"NORMAL")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].phich_duration= LTE_PHICH_Config__phich_Duration_normal;
+  } else if (strcmp(eMTCconfig->ccparams.phich_duration,"EXTENDED")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].phich_duration= LTE_PHICH_Config__phich_Duration_extended;
+  } else
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for phich_duration choice: NORMAL,EXTENDED!\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.phich_duration);
+
+  if (strcmp(eMTCconfig->ccparams.phich_resource,"ONESIXTH")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].phich_resource= LTE_PHICH_Config__phich_Resource_oneSixth ;
+  } else if (strcmp(eMTCconfig->ccparams.phich_resource,"HALF")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].phich_resource= LTE_PHICH_Config__phich_Resource_half;
+  } else if (strcmp(eMTCconfig->ccparams.phich_resource,"ONE")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].phich_resource= LTE_PHICH_Config__phich_Resource_one;
+  } else if (strcmp(eMTCconfig->ccparams.phich_resource,"TWO")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].phich_resource= LTE_PHICH_Config__phich_Resource_two;
+  } else
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for phich_resource choice: ONESIXTH,HALF,ONE,TWO!\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.phich_resource);
+
+  printf("phich.resource eMTC %ld (%s), phich.duration eMTC %ld (%s)\n",
+	 RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].phich_resource,eMTCconfig->ccparams.phich_resource,
+	 RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].phich_duration,eMTCconfig->ccparams.phich_duration);
+
+  if (strcmp(eMTCconfig->ccparams.srs_enable, "ENABLE") == 0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].srs_enable= TRUE;
+  } else if (strcmp(eMTCconfig->ccparams.srs_enable, "DISABLE") == 0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].srs_enable= FALSE;
+  } else
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for srs_BandwidthConfig choice: ENABLE,DISABLE !\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.srs_enable);
+
+  if (RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].srs_enable== TRUE) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].srs_BandwidthConfig= eMTCconfig->ccparams.srs_BandwidthConfig;
+
+    if ((eMTCconfig->ccparams.srs_BandwidthConfig < 0) || (eMTCconfig->ccparams.srs_BandwidthConfig >7))
+      AssertFatal (0, "Failed to parse eNB configuration file %s, enb %d unknown value %d for srs_BandwidthConfig choice: 0...7\n",
+		   config_fname, cell_idx,eMTCconfig->ccparams.srs_BandwidthConfig);
+
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].srs_SubframeConfig= eMTCconfig->ccparams.srs_SubframeConfig;
+
+    if ((eMTCconfig->ccparams.srs_SubframeConfig<0) || (eMTCconfig->ccparams.srs_SubframeConfig>15))
+      AssertFatal (0,
+		   "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for srs_SubframeConfig choice: 0..15 !\n",
+		   config_fname, cell_idx,eMTCconfig->ccparams.srs_SubframeConfig);
+
+    if (strcmp(eMTCconfig->ccparams.srs_ackNackST, "ENABLE") == 0) {
+      RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].srs_ackNackST= TRUE;
+    } else if (strcmp(eMTCconfig->ccparams.srs_ackNackST, "DISABLE") == 0) {
+      RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].srs_ackNackST= FALSE;
+    } else
+      AssertFatal (0,
+		   "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for srs_BandwidthConfig choice: ENABLE,DISABLE !\n",
+		   config_fname, cell_idx,eMTCconfig->ccparams.srs_ackNackST);
+
+    if (strcmp(eMTCconfig->ccparams.srs_MaxUpPts, "ENABLE") == 0) {
+      RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].srs_MaxUpPts= TRUE;
+    } else if (strcmp(eMTCconfig->ccparams.srs_MaxUpPts, "DISABLE") == 0) {
+      RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].srs_MaxUpPts= FALSE;
+    } else
+      AssertFatal (0,
+		   "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for srs_MaxUpPts choice: ENABLE,DISABLE !\n",
+		   config_fname, cell_idx,eMTCconfig->ccparams.srs_MaxUpPts);
+  }
+
+  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pusch_p0_Nominal= eMTCconfig->ccparams.pusch_p0_Nominal;
+
+  if ((eMTCconfig->ccparams.pusch_p0_Nominal<-126) || (eMTCconfig->ccparams.pusch_p0_Nominal>24))
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pusch_p0_Nominal choice: -126..24 !\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.pusch_p0_Nominal);
+
+  if (strcmp(eMTCconfig->ccparams.pusch_alpha,"AL0")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pusch_alpha= LTE_Alpha_r12_al0;
+  } else if (strcmp(eMTCconfig->ccparams.pusch_alpha,"AL04")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pusch_alpha= LTE_Alpha_r12_al04;
+  } else if (strcmp(eMTCconfig->ccparams.pusch_alpha,"AL05")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pusch_alpha= LTE_Alpha_r12_al05;
+  } else if (strcmp(eMTCconfig->ccparams.pusch_alpha,"AL06")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pusch_alpha= LTE_Alpha_r12_al06;
+  } else if (strcmp(eMTCconfig->ccparams.pusch_alpha,"AL07")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pusch_alpha= LTE_Alpha_r12_al07;
+  } else if (strcmp(eMTCconfig->ccparams.pusch_alpha,"AL08")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pusch_alpha= LTE_Alpha_r12_al08;
+  } else if (strcmp(eMTCconfig->ccparams.pusch_alpha,"AL09")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pusch_alpha= LTE_Alpha_r12_al09;
+  } else if (strcmp(eMTCconfig->ccparams.pusch_alpha,"AL1")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pusch_alpha= LTE_Alpha_r12_al1;
+  }
+
+  else
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pucch_Alpha choice: AL0,AL04,AL05,AL06,AL07,AL08,AL09,AL1!\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.pusch_alpha);
+
+  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pucch_p0_Nominal= eMTCconfig->ccparams.pucch_p0_Nominal;
+
+  if ((eMTCconfig->ccparams.pucch_p0_Nominal<-127) || (eMTCconfig->ccparams.pucch_p0_Nominal>-96))
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pucch_p0_Nominal choice: -127..-96 !\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.pucch_p0_Nominal);
+
+  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].msg3_delta_Preamble= eMTCconfig->ccparams.msg3_delta_Preamble;
+
+  if ((eMTCconfig->ccparams.msg3_delta_Preamble<-1) || (eMTCconfig->ccparams.msg3_delta_Preamble>6))
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for msg3_delta_Preamble choice: -1..6 !\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.msg3_delta_Preamble);
+
+  if (strcmp(eMTCconfig->ccparams.pucch_deltaF_Format1,"deltaF_2")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pucch_deltaF_Format1= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format1_deltaF_2;
+  } else if (strcmp(eMTCconfig->ccparams.pucch_deltaF_Format1,"deltaF0")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pucch_deltaF_Format1= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format1_deltaF0;
+  } else if (strcmp(eMTCconfig->ccparams.pucch_deltaF_Format1,"deltaF2")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pucch_deltaF_Format1= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format1_deltaF2;
+  } else
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pucch_deltaF_Format1 choice: deltaF_2,dltaF0,deltaF2!\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.pucch_deltaF_Format1);
+
+  if (strcmp(eMTCconfig->ccparams.pucch_deltaF_Format1b,"deltaF1")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pucch_deltaF_Format1b= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format1b_deltaF1;
+  } else if (strcmp(eMTCconfig->ccparams.pucch_deltaF_Format1b,"deltaF3")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pucch_deltaF_Format1b= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format1b_deltaF3;
+  } else if (strcmp(eMTCconfig->ccparams.pucch_deltaF_Format1b,"deltaF5")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pucch_deltaF_Format1b= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format1b_deltaF5;
+  } else
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pucch_deltaF_Format1b choice: deltaF1,dltaF3,deltaF5!\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.pucch_deltaF_Format1b);
+
+  if (strcmp(eMTCconfig->ccparams.pucch_deltaF_Format2,"deltaF_2")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pucch_deltaF_Format2= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format2_deltaF_2;
+  } else if (strcmp(eMTCconfig->ccparams.pucch_deltaF_Format2,"deltaF0")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pucch_deltaF_Format2= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format2_deltaF0;
+  } else if (strcmp(eMTCconfig->ccparams.pucch_deltaF_Format2,"deltaF1")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pucch_deltaF_Format2= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format2_deltaF1;
+  } else if (strcmp(eMTCconfig->ccparams.pucch_deltaF_Format2,"deltaF2")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pucch_deltaF_Format2= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format2_deltaF2;
+  } else
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pucch_deltaF_Format2 choice: deltaF_2,dltaF0,deltaF1,deltaF2!\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.pucch_deltaF_Format2);
+
+  if (strcmp(eMTCconfig->ccparams.pucch_deltaF_Format2a,"deltaF_2")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pucch_deltaF_Format2a= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format2a_deltaF_2;
+  } else if (strcmp(eMTCconfig->ccparams.pucch_deltaF_Format2a,"deltaF0")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pucch_deltaF_Format2a= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format2a_deltaF0;
+  } else if (strcmp(eMTCconfig->ccparams.pucch_deltaF_Format2a,"deltaF2")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pucch_deltaF_Format2a= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format2a_deltaF2;
+  } else
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pucch_deltaF_Format2a choice: deltaF_2,dltaF0,deltaF2!\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.pucch_deltaF_Format2a);
+
+  if (strcmp(eMTCconfig->ccparams.pucch_deltaF_Format2b,"deltaF_2")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pucch_deltaF_Format2b= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format2b_deltaF_2;
+  } else if (strcmp(eMTCconfig->ccparams.pucch_deltaF_Format2b,"deltaF0")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pucch_deltaF_Format2b= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format2b_deltaF0;
+  } else if (strcmp(eMTCconfig->ccparams.pucch_deltaF_Format2b,"deltaF2")==0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pucch_deltaF_Format2b= LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format2b_deltaF2;
+  } else
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pucch_deltaF_Format2b choice: deltaF_2,dltaF0,deltaF2!\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.pucch_deltaF_Format2b);
+
+  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_numberOfRA_Preambles= (eMTCconfig->ccparams.rach_numberOfRA_Preambles/4)-1;
+
+  if ((eMTCconfig->ccparams.rach_numberOfRA_Preambles <4) || (eMTCconfig->ccparams.rach_numberOfRA_Preambles >64) || ((eMTCconfig->ccparams.rach_numberOfRA_Preambles&3)!=0))
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for rach_numberOfRA_Preambles choice: 4,8,12,...,64!\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.rach_numberOfRA_Preambles);
+
+  if (strcmp(eMTCconfig->ccparams.rach_preamblesGroupAConfig, "ENABLE") == 0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_preamblesGroupAConfig= TRUE;
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_sizeOfRA_PreamblesGroupA= (eMTCconfig->ccparams.rach_sizeOfRA_PreamblesGroupA/4)-1;
+
+    if ((eMTCconfig->ccparams.rach_numberOfRA_Preambles <4) || (eMTCconfig->ccparams.rach_numberOfRA_Preambles>60) || ((eMTCconfig->ccparams.rach_numberOfRA_Preambles&3)!=0))
+      AssertFatal (0,
+		   "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for rach_sizeOfRA_PreamblesGroupA choice: 4,8,12,...,60!\n",
+		   config_fname, cell_idx,eMTCconfig->ccparams.rach_sizeOfRA_PreamblesGroupA);
+
+    switch (eMTCconfig->ccparams.rach_messageSizeGroupA) {
+    case 56:
+      RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_messageSizeGroupA= LTE_RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messageSizeGroupA_b56;
+      break;
+
+    case 144:
+      RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_messageSizeGroupA= LTE_RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messageSizeGroupA_b144;
+      break;
+
+    case 208:
+      RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_messageSizeGroupA= LTE_RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messageSizeGroupA_b208;
+      break;
+
+    case 256:
+      RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_messageSizeGroupA= LTE_RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messageSizeGroupA_b256;
+      break;
+
+    default:
+      AssertFatal (0,
+		   "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for rach_messageSizeGroupA choice: 56,144,208,256!\n",
+		   config_fname, cell_idx,eMTCconfig->ccparams.rach_messageSizeGroupA);
+      break;
+    }
+
+    if (strcmp(eMTCconfig->ccparams.rach_messagePowerOffsetGroupB,"minusinfinity")==0) {
+      RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_messagePowerOffsetGroupB= LTE_RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messagePowerOffsetGroupB_minusinfinity;
+    } else if (strcmp(eMTCconfig->ccparams.rach_messagePowerOffsetGroupB,"dB0")==0) {
+      RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_messagePowerOffsetGroupB= LTE_RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messagePowerOffsetGroupB_dB0;
+    } else if (strcmp(eMTCconfig->ccparams.rach_messagePowerOffsetGroupB,"dB5")==0) {
+      RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_messagePowerOffsetGroupB= LTE_RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messagePowerOffsetGroupB_dB5;
+    } else if (strcmp(eMTCconfig->ccparams.rach_messagePowerOffsetGroupB,"dB8")==0) {
+      RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_messagePowerOffsetGroupB= LTE_RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messagePowerOffsetGroupB_dB8;
+    } else if (strcmp(eMTCconfig->ccparams.rach_messagePowerOffsetGroupB,"dB10")==0) {
+      RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_messagePowerOffsetGroupB= LTE_RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messagePowerOffsetGroupB_dB10;
+    } else if (strcmp(eMTCconfig->ccparams.rach_messagePowerOffsetGroupB,"dB12")==0) {
+      RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_messagePowerOffsetGroupB= LTE_RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messagePowerOffsetGroupB_dB12;
+    } else if (strcmp(eMTCconfig->ccparams.rach_messagePowerOffsetGroupB,"dB15")==0) {
+      RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_messagePowerOffsetGroupB= LTE_RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messagePowerOffsetGroupB_dB15;
+    } else if (strcmp(eMTCconfig->ccparams.rach_messagePowerOffsetGroupB,"dB18")==0) {
+      RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_messagePowerOffsetGroupB= LTE_RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messagePowerOffsetGroupB_dB18;
+    } else
+      AssertFatal (0,
+		   "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for rach_messagePowerOffsetGroupB choice: minusinfinity,dB0,dB5,dB8,dB10,dB12,dB15,dB18!\n",
+		   config_fname, cell_idx,eMTCconfig->ccparams.rach_messagePowerOffsetGroupB);
+  } else if (strcmp(eMTCconfig->ccparams.rach_preamblesGroupAConfig, "DISABLE") == 0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_preamblesGroupAConfig= FALSE;
+  } else
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for rach_preamblesGroupAConfig choice: ENABLE,DISABLE !\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.rach_preamblesGroupAConfig);
+
+  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_preambleInitialReceivedTargetPower= (eMTCconfig->ccparams.rach_preambleInitialReceivedTargetPower+120)/2;
+
+  if ((eMTCconfig->ccparams.rach_preambleInitialReceivedTargetPower<-120) || (eMTCconfig->ccparams.rach_preambleInitialReceivedTargetPower>-90) || ((eMTCconfig->ccparams.rach_preambleInitialReceivedTargetPower&1)!=0))
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for rach_preambleInitialReceivedTargetPower choice: -120,-118,...,-90 !\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.rach_preambleInitialReceivedTargetPower);
+
+  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_powerRampingStep= eMTCconfig->ccparams.rach_powerRampingStep/2;
+
+  if ((eMTCconfig->ccparams.rach_powerRampingStep<0) || (eMTCconfig->ccparams.rach_powerRampingStep>6) || ((eMTCconfig->ccparams.rach_powerRampingStep&1)!=0))
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for rach_powerRampingStep choice: 0,2,4,6 !\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.rach_powerRampingStep);
+
+  switch (eMTCconfig->ccparams.rach_preambleTransMax) {
+  case 3:
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_preambleTransMax=  LTE_PreambleTransMax_n3;
+    break;
+
+  case 4:
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_preambleTransMax=  LTE_PreambleTransMax_n4;
+    break;
+
+  case 5:
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_preambleTransMax=  LTE_PreambleTransMax_n5;
+    break;
+
+  case 6:
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_preambleTransMax=  LTE_PreambleTransMax_n6;
+    break;
+
+  case 7:
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_preambleTransMax=  LTE_PreambleTransMax_n7;
+    break;
+
+  case 8:
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_preambleTransMax=  LTE_PreambleTransMax_n8;
+    break;
+
+  case 10:
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_preambleTransMax=  LTE_PreambleTransMax_n10;
+    break;
+
+  case 20:
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_preambleTransMax=  LTE_PreambleTransMax_n20;
+    break;
+
+  case 50:
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_preambleTransMax=  LTE_PreambleTransMax_n50;
+    break;
+
+  case 100:
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_preambleTransMax=  LTE_PreambleTransMax_n100;
+    break;
+
+  case 200:
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_preambleTransMax=  LTE_PreambleTransMax_n200;
+    break;
+
+  default:
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for rach_preambleTransMax choice: 3,4,5,6,7,8,10,20,50,100,200!\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.rach_preambleTransMax);
+    break;
+  }
+
+  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_raResponseWindowSize=  (eMTCconfig->ccparams.rach_raResponseWindowSize==10)?7:eMTCconfig->ccparams.rach_raResponseWindowSize-2;
+
+  if ((eMTCconfig->ccparams.rach_raResponseWindowSize<0)||(eMTCconfig->ccparams.rach_raResponseWindowSize==9)||(eMTCconfig->ccparams.rach_raResponseWindowSize>10))
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for rach_raResponseWindowSize choice: 2,3,4,5,6,7,8,10!\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.rach_raResponseWindowSize);
+
+  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_macContentionResolutionTimer= (eMTCconfig->ccparams.rach_macContentionResolutionTimer/8)-1;
+
+  if ((eMTCconfig->ccparams.rach_macContentionResolutionTimer<8) || (eMTCconfig->ccparams.rach_macContentionResolutionTimer>64) || ((eMTCconfig->ccparams.rach_macContentionResolutionTimer&7)!=0))
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for rach_macContentionResolutionTimer choice: 8,16,...,56,64!\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.rach_macContentionResolutionTimer);
+
+  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].rach_maxHARQ_Msg3Tx= eMTCconfig->ccparams.rach_maxHARQ_Msg3Tx;
+
+  if ((eMTCconfig->ccparams.rach_maxHARQ_Msg3Tx<0) || (eMTCconfig->ccparams.rach_maxHARQ_Msg3Tx>8))
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for rach_maxHARQ_Msg3Tx choice: 1..8!\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.rach_maxHARQ_Msg3Tx);
+
+  switch (eMTCconfig->ccparams.pcch_defaultPagingCycle) {
+  case 32:
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pcch_defaultPagingCycle= LTE_PCCH_Config__defaultPagingCycle_rf32;
+    break;
+
+  case 64:
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pcch_defaultPagingCycle= LTE_PCCH_Config__defaultPagingCycle_rf64;
+    break;
+
+  case 128:
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pcch_defaultPagingCycle= LTE_PCCH_Config__defaultPagingCycle_rf128;
+    break;
+
+  case 256:
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pcch_defaultPagingCycle= LTE_PCCH_Config__defaultPagingCycle_rf256;
+    break;
+
+  default:
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for pcch_defaultPagingCycle choice: 32,64,128,256!\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.pcch_defaultPagingCycle);
+    break;
+  }
+
+  if (strcmp(eMTCconfig->ccparams.pcch_nB, "fourT") == 0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pcch_nB= LTE_PCCH_Config__nB_fourT;
+  } else if (strcmp(eMTCconfig->ccparams.pcch_nB, "twoT") == 0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pcch_nB= LTE_PCCH_Config__nB_twoT;
+  } else if (strcmp(eMTCconfig->ccparams.pcch_nB, "oneT") == 0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pcch_nB= LTE_PCCH_Config__nB_oneT;
+  } else if (strcmp(eMTCconfig->ccparams.pcch_nB, "halfT") == 0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pcch_nB= LTE_PCCH_Config__nB_halfT;
+  } else if (strcmp(eMTCconfig->ccparams.pcch_nB, "quarterT") == 0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pcch_nB= LTE_PCCH_Config__nB_quarterT;
+  } else if (strcmp(eMTCconfig->ccparams.pcch_nB, "oneEighthT") == 0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pcch_nB= LTE_PCCH_Config__nB_oneEighthT;
+  } else if (strcmp(eMTCconfig->ccparams.pcch_nB, "oneSixteenthT") == 0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pcch_nB= LTE_PCCH_Config__nB_oneSixteenthT;
+  } else if (strcmp(eMTCconfig->ccparams.pcch_nB, "oneThirtySecondT") == 0) {
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].pcch_nB= LTE_PCCH_Config__nB_oneThirtySecondT;
+  } else
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pcch_nB choice: fourT,twoT,oneT,halfT,quarterT,oneighthT,oneSixteenthT,oneThirtySecondT !\n",
+		 config_fname, cell_idx,eMTCconfig->ccparams.pcch_nB);
+
+  switch (eMTCconfig->ccparams.bcch_modificationPeriodCoeff) {
+  case 2:
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].bcch_modificationPeriodCoeff= LTE_BCCH_Config__modificationPeriodCoeff_n2;
+    break;
+
+  case 4:
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].bcch_modificationPeriodCoeff= LTE_BCCH_Config__modificationPeriodCoeff_n4;
+    break;
+
+  case 8:
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].bcch_modificationPeriodCoeff= LTE_BCCH_Config__modificationPeriodCoeff_n8;
+    break;
+
+  case 16:
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].bcch_modificationPeriodCoeff= LTE_BCCH_Config__modificationPeriodCoeff_n16;
+    break;
+
+  default:
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for bcch_modificationPeriodCoeff choice: 2,4,8,16",
+		 config_fname, cell_idx,eMTCconfig->ccparams.bcch_modificationPeriodCoeff);
+    break;
+  }
+
+  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].ue_TimersAndConstants_t300= eMTCconfig->ccparams.ue_TimersAndConstants_t300;
+  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].ue_TimersAndConstants_t301= eMTCconfig->ccparams.ue_TimersAndConstants_t301;
+  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].ue_TimersAndConstants_t310= eMTCconfig->ccparams.ue_TimersAndConstants_t310;
+  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].ue_TimersAndConstants_t311= eMTCconfig->ccparams.ue_TimersAndConstants_t311;
+  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].ue_TimersAndConstants_n310= eMTCconfig->ccparams.ue_TimersAndConstants_n310;
+  RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].ue_TimersAndConstants_n311= eMTCconfig->ccparams.ue_TimersAndConstants_n311;
+
+  switch (eMTCconfig->ccparams.ue_TransmissionMode) {
+  case 1:
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].ue_TransmissionMode= LTE_AntennaInfoDedicated__transmissionMode_tm1;
+    break;
+
+  case 2:
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].ue_TransmissionMode= LTE_AntennaInfoDedicated__transmissionMode_tm2;
+    break;
+
+  case 3:
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].ue_TransmissionMode= LTE_AntennaInfoDedicated__transmissionMode_tm3;
+    break;
+
+  case 4:
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].ue_TransmissionMode= LTE_AntennaInfoDedicated__transmissionMode_tm4;
+    break;
+
+  case 5:
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].ue_TransmissionMode= LTE_AntennaInfoDedicated__transmissionMode_tm5;
+    break;
+
+  case 6:
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].ue_TransmissionMode= LTE_AntennaInfoDedicated__transmissionMode_tm6;
+    break;
+
+  case 7:
+    RRC_CONFIGURATION_REQ (msg_p).radioresourceconfig_BR[cc_idx].ue_TransmissionMode= LTE_AntennaInfoDedicated__transmissionMode_tm7;
+    break;
+
+  default:
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, enb %d unknown value \"%d\" for ue_TransmissionMode choice: 1,2,3,4,5,6,7",
+		 config_fname, cell_idx, eMTCconfig->ccparams.ue_TransmissionMode);
+    break;
+  }
+
+
+  if (!strcmp(eMTCconfig->prach_ConfigCommon_v1310, "ENABLE")) {
+    RRC_CONFIGURATION_REQ(msg_p).radioresourceconfig_BR[cc_idx].prach_ConfigCommon_v1310 = TRUE;
+
+    RRC_CONFIGURATION_REQ(msg_p).radioresourceconfig_BR[cc_idx].mpdcch_startSF_CSS_RA_r13 = calloc(1, sizeof(BOOLEAN_t));
+
+    if (!strcmp(eMTCconfig->mpdcch_startSF_CSS_RA_r13, "tdd-r13")) {
+      *RRC_CONFIGURATION_REQ(msg_p).radioresourceconfig_BR[cc_idx].mpdcch_startSF_CSS_RA_r13 = FALSE;
+    } else {
+      *RRC_CONFIGURATION_REQ(msg_p).radioresourceconfig_BR[cc_idx].mpdcch_startSF_CSS_RA_r13 = TRUE;
+    }
+
+    if (!strcmp(eMTCconfig->mpdcch_startSF_CSS_RA_r13_val, "v1")) {
+      RRC_CONFIGURATION_REQ(msg_p).radioresourceconfig_BR[cc_idx].mpdcch_startSF_CSS_RA_r13_val = 0;
+    } else if (!strcmp(eMTCconfig->mpdcch_startSF_CSS_RA_r13_val, "v1dot5")) {
+      RRC_CONFIGURATION_REQ(msg_p).radioresourceconfig_BR[cc_idx].mpdcch_startSF_CSS_RA_r13_val = 1;
+    } else if (!strcmp(eMTCconfig->mpdcch_startSF_CSS_RA_r13_val, "v2")) {
+      RRC_CONFIGURATION_REQ(msg_p).radioresourceconfig_BR[cc_idx].mpdcch_startSF_CSS_RA_r13_val = 2;
+    } else if (!strcmp(eMTCconfig->mpdcch_startSF_CSS_RA_r13_val, "v2dot5")) {
+      RRC_CONFIGURATION_REQ(msg_p).radioresourceconfig_BR[cc_idx].mpdcch_startSF_CSS_RA_r13_val = 3;
+    } else if (!strcmp(eMTCconfig->mpdcch_startSF_CSS_RA_r13_val, "v4")) {
+      RRC_CONFIGURATION_REQ(msg_p).radioresourceconfig_BR[cc_idx].mpdcch_startSF_CSS_RA_r13_val = 4;
+    } else if (!strcmp(eMTCconfig->mpdcch_startSF_CSS_RA_r13_val, "v5")) {
+      RRC_CONFIGURATION_REQ(msg_p).radioresourceconfig_BR[cc_idx].mpdcch_startSF_CSS_RA_r13_val = 5;
+    } else if (!strcmp(eMTCconfig->mpdcch_startSF_CSS_RA_r13_val, "v8")) {
+      RRC_CONFIGURATION_REQ(msg_p).radioresourceconfig_BR[cc_idx].mpdcch_startSF_CSS_RA_r13_val = 6;
+    } else if (!strcmp(eMTCconfig->mpdcch_startSF_CSS_RA_r13_val, "10")) {
+      RRC_CONFIGURATION_REQ(msg_p).radioresourceconfig_BR[cc_idx].mpdcch_startSF_CSS_RA_r13_val = 7;
+    } else {
+      AssertFatal(0,
+		  "Failed to parse eNB configuration file %s, enb %d mpdcch_startSF_CSS_RA_r13_val! Unknown Value !!\n",
+		  config_fname, cell_idx);
+    }
+
+    RRC_CONFIGURATION_REQ(msg_p).radioresourceconfig_BR[cc_idx].prach_HoppingOffset_r13 = calloc(1, sizeof(long));
+    *RRC_CONFIGURATION_REQ(msg_p).radioresourceconfig_BR[cc_idx].prach_HoppingOffset_r13 = eMTCconfig->prach_HoppingOffset_r13;
+  } else {
+    RRC_CONFIGURATION_REQ(msg_p).radioresourceconfig_BR[cc_idx].prach_ConfigCommon_v1310 = FALSE;
+  }
+
+
+  RRC_CONFIGURATION_REQ(msg_p).pdsch_maxNumRepetitionCEmodeA_r13[cc_idx] = CALLOC(1, sizeof(long));
+  if (!strcmp(eMTCconfig->pdsch_maxNumRepetitionCEmodeA_r13, "r16")) {
+    *RRC_CONFIGURATION_REQ(msg_p).pdsch_maxNumRepetitionCEmodeA_r13[cc_idx] = 0;
+  } else if (!strcmp(eMTCconfig->pdsch_maxNumRepetitionCEmodeA_r13, "r32")) {
+    *RRC_CONFIGURATION_REQ(msg_p).pdsch_maxNumRepetitionCEmodeA_r13[cc_idx] = 1;
+  } else {
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, pdsch_maxNumRepetitionCEmodeA_r13 unknown value!\n",
+		 config_fname);
+  }
+
+
+  RRC_CONFIGURATION_REQ(msg_p).pusch_maxNumRepetitionCEmodeA_r13[cc_idx] = CALLOC(1, sizeof(long));
+  if (!strcmp(eMTCconfig->pusch_maxNumRepetitionCEmodeA_r13, "r8")) {
+    *RRC_CONFIGURATION_REQ(msg_p).pusch_maxNumRepetitionCEmodeA_r13[cc_idx] =  0;
+  } else if (!strcmp(eMTCconfig->pusch_maxNumRepetitionCEmodeA_r13, "r16")) {
+    *RRC_CONFIGURATION_REQ(msg_p).pusch_maxNumRepetitionCEmodeA_r13[cc_idx] =  1;
+  } else if (!strcmp(eMTCconfig->pusch_maxNumRepetitionCEmodeA_r13, "r32")) {
+    *RRC_CONFIGURATION_REQ(msg_p).pusch_maxNumRepetitionCEmodeA_r13[cc_idx] =  2;
+  } else {
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, pusch_maxNumRepetitionCEmodeA_r13 unknown value!\n",
+		 config_fname);
+  }
+
+  char rachCELevelInfoListPath[MAX_OPTNAME_SIZE * 2];
+  config_getlist(&rachcelevellist, NULL, 0, brparamspath);
+  RRC_CONFIGURATION_REQ (msg_p).rach_CE_LevelInfoList_r13_size[cc_idx] = rachcelevellist.numelt;
+  int rachCEInfoIndex;
+  for (rachCEInfoIndex = 0; rachCEInfoIndex < rachcelevellist.numelt; rachCEInfoIndex++) {
+    sprintf(rachCELevelInfoListPath, "%s.%s.[%i]", brparamspath, ENB_CONFIG_STRING_RACH_CE_LEVELINFOLIST_R13, rachCEInfoIndex);
+    config_get(rachcelevelParams, sizeof(rachcelevelParams) / sizeof(paramdef_t), rachCELevelInfoListPath);
+
+    RRC_CONFIGURATION_REQ (msg_p).firstPreamble_r13[cc_idx][rachCEInfoIndex] = eMTCconfig->firstPreamble_r13;
+    RRC_CONFIGURATION_REQ (msg_p).lastPreamble_r13[cc_idx][rachCEInfoIndex]  = eMTCconfig->lastPreamble_r13;
+
+    switch (eMTCconfig->ra_ResponseWindowSize_r13) {
+    case 20:
+      RRC_CONFIGURATION_REQ (msg_p).ra_ResponseWindowSize_r13[cc_idx][rachCEInfoIndex] = LTE_RACH_CE_LevelInfo_r13__ra_ResponseWindowSize_r13_sf20;
+      break;
+    case 50:
+      RRC_CONFIGURATION_REQ (msg_p).ra_ResponseWindowSize_r13[cc_idx][rachCEInfoIndex] = LTE_RACH_CE_LevelInfo_r13__ra_ResponseWindowSize_r13_sf50;
+      break;
+    case 80:
+      RRC_CONFIGURATION_REQ (msg_p).ra_ResponseWindowSize_r13[cc_idx][rachCEInfoIndex] = LTE_RACH_CE_LevelInfo_r13__ra_ResponseWindowSize_r13_sf80;
+      break;
+    case 120:
+      RRC_CONFIGURATION_REQ (msg_p).ra_ResponseWindowSize_r13[cc_idx][rachCEInfoIndex] = LTE_RACH_CE_LevelInfo_r13__ra_ResponseWindowSize_r13_sf120;
+      break;
+    case 180:
+      RRC_CONFIGURATION_REQ (msg_p).ra_ResponseWindowSize_r13[cc_idx][rachCEInfoIndex] = LTE_RACH_CE_LevelInfo_r13__ra_ResponseWindowSize_r13_sf180;
+      break;
+    case 240:
+      RRC_CONFIGURATION_REQ (msg_p).ra_ResponseWindowSize_r13[cc_idx][rachCEInfoIndex] = LTE_RACH_CE_LevelInfo_r13__ra_ResponseWindowSize_r13_sf240;
+      break;
+    case 320:
+      RRC_CONFIGURATION_REQ (msg_p).ra_ResponseWindowSize_r13[cc_idx][rachCEInfoIndex] = LTE_RACH_CE_LevelInfo_r13__ra_ResponseWindowSize_r13_sf320;
+      break;
+    case 400:
+      RRC_CONFIGURATION_REQ (msg_p).ra_ResponseWindowSize_r13[cc_idx][rachCEInfoIndex] = LTE_RACH_CE_LevelInfo_r13__ra_ResponseWindowSize_r13_sf400;
+      break;
+    default:
+      AssertFatal(1==0,
+		"Illegal ra_ResponseWindowSize_r13 %d\n",eMTCconfig->ra_ResponseWindowSize_r13);
+    }
+
+
+    switch(eMTCconfig->mac_ContentionResolutionTimer_r13) {
+    case 80:
+      RRC_CONFIGURATION_REQ (msg_p).mac_ContentionResolutionTimer_r13[cc_idx][rachCEInfoIndex] = LTE_RACH_CE_LevelInfo_r13__mac_ContentionResolutionTimer_r13_sf80;
+      break;
+    case 100:
+      RRC_CONFIGURATION_REQ (msg_p).mac_ContentionResolutionTimer_r13[cc_idx][rachCEInfoIndex] = LTE_RACH_CE_LevelInfo_r13__mac_ContentionResolutionTimer_r13_sf100;
+      break;
+    case 120:
+      RRC_CONFIGURATION_REQ (msg_p).mac_ContentionResolutionTimer_r13[cc_idx][rachCEInfoIndex] = LTE_RACH_CE_LevelInfo_r13__mac_ContentionResolutionTimer_r13_sf120;
+      break;
+    case 160:
+      RRC_CONFIGURATION_REQ (msg_p).mac_ContentionResolutionTimer_r13[cc_idx][rachCEInfoIndex] = LTE_RACH_CE_LevelInfo_r13__mac_ContentionResolutionTimer_r13_sf160;
+      break;
+    case 200:
+      RRC_CONFIGURATION_REQ (msg_p).mac_ContentionResolutionTimer_r13[cc_idx][rachCEInfoIndex] = LTE_RACH_CE_LevelInfo_r13__mac_ContentionResolutionTimer_r13_sf200;
+      break;
+    case 240:
+      RRC_CONFIGURATION_REQ (msg_p).mac_ContentionResolutionTimer_r13[cc_idx][rachCEInfoIndex] = LTE_RACH_CE_LevelInfo_r13__mac_ContentionResolutionTimer_r13_sf240;
+      break;
+    case 480:
+      RRC_CONFIGURATION_REQ (msg_p).mac_ContentionResolutionTimer_r13[cc_idx][rachCEInfoIndex] = LTE_RACH_CE_LevelInfo_r13__mac_ContentionResolutionTimer_r13_sf480;
+      break;
+    case 960:
+      RRC_CONFIGURATION_REQ (msg_p).mac_ContentionResolutionTimer_r13[cc_idx][rachCEInfoIndex] = LTE_RACH_CE_LevelInfo_r13__mac_ContentionResolutionTimer_r13_sf960;
+      break;
+    default:
+      AssertFatal(1==0,"Illegal mac_ContentionResolutionTimer_r13 %d\n",
+		  eMTCconfig->mac_ContentionResolutionTimer_r13);
+      break;
+    }
+    RRC_CONFIGURATION_REQ (msg_p).rar_HoppingConfig_r13[cc_idx][rachCEInfoIndex] = eMTCconfig->rar_HoppingConfig_r13;
+    AssertFatal(eMTCconfig->rar_HoppingConfig_r13 == 0 || eMTCconfig->rar_HoppingConfig_r13 == 1,
+		"illegal rar_HoppingConfig_r13 %d\n",eMTCconfig->rar_HoppingConfig_r13);
+  } // end for loop (rach ce level info)
+
+  char rsrpRangeListPath[MAX_OPTNAME_SIZE * 2];
+  config_getlist(&rsrprangelist, NULL, 0, brparamspath);
+  RRC_CONFIGURATION_REQ (msg_p).rsrp_range_list_size[cc_idx] = rsrprangelist.numelt;
+
+
+  int rsrprangeindex;
+  for (rsrprangeindex = 0; rsrprangeindex < rsrprangelist.numelt; rsrprangeindex++) {
+    sprintf(rsrpRangeListPath, "%s.%s.[%i]", brparamspath, ENB_CONFIG_STRING_RSRP_RANGE_LIST, rsrprangeindex);
+    config_get(rsrprangeParams, sizeof(rsrprangeParams) / sizeof(paramdef_t), rsrpRangeListPath);
+    RRC_CONFIGURATION_REQ (msg_p).rsrp_range[cc_idx][rsrprangeindex] = eMTCconfig->rsrp_range_br;
+
+  }
+
+
+  char prachparameterscePath[MAX_OPTNAME_SIZE * 2];
+  config_getlist(&prachParamslist, NULL, 0, brparamspath);
+  RRC_CONFIGURATION_REQ (msg_p).prach_parameters_list_size[cc_idx] = prachParamslist.numelt;
+
+  int prachparamsindex;
+  for (prachparamsindex = 0; prachparamsindex < prachParamslist.numelt; prachparamsindex++) {
+    sprintf(prachparameterscePath, "%s.%s.[%i]", brparamspath, ENB_CONFIG_STRING_PRACH_PARAMETERS_CE_R13, prachparamsindex);
+    config_get(prachParams, sizeof(prachParams) / sizeof(paramdef_t), prachparameterscePath);
+
+    RRC_CONFIGURATION_REQ (msg_p).prach_config_index[cc_idx][prachparamsindex]                  = eMTCconfig->prach_config_index_br;
+    RRC_CONFIGURATION_REQ (msg_p).prach_freq_offset[cc_idx][prachparamsindex]                   = eMTCconfig->prach_freq_offset_br;
+
+    RRC_CONFIGURATION_REQ (msg_p).prach_StartingSubframe_r13[cc_idx][prachparamsindex] = calloc(1, sizeof(long));
+    switch(eMTCconfig->prach_StartingSubframe_r13) {
+    case 2:
+      *RRC_CONFIGURATION_REQ (msg_p).prach_StartingSubframe_r13[cc_idx][prachparamsindex] = LTE_PRACH_ParametersCE_r13__prach_StartingSubframe_r13_sf2;
+      break;
+    case 4:
+      *RRC_CONFIGURATION_REQ (msg_p).prach_StartingSubframe_r13[cc_idx][prachparamsindex] = LTE_PRACH_ParametersCE_r13__prach_StartingSubframe_r13_sf4;
+      break;
+    case 8:
+      *RRC_CONFIGURATION_REQ (msg_p).prach_StartingSubframe_r13[cc_idx][prachparamsindex] = LTE_PRACH_ParametersCE_r13__prach_StartingSubframe_r13_sf8;
+      break;
+    case 16:
+      *RRC_CONFIGURATION_REQ (msg_p).prach_StartingSubframe_r13[cc_idx][prachparamsindex] = LTE_PRACH_ParametersCE_r13__prach_StartingSubframe_r13_sf16;
+      break;
+    case 32:
+      *RRC_CONFIGURATION_REQ (msg_p).prach_StartingSubframe_r13[cc_idx][prachparamsindex] = LTE_PRACH_ParametersCE_r13__prach_StartingSubframe_r13_sf32;
+      break;
+    case 64:
+      *RRC_CONFIGURATION_REQ (msg_p).prach_StartingSubframe_r13[cc_idx][prachparamsindex] = LTE_PRACH_ParametersCE_r13__prach_StartingSubframe_r13_sf64;
+      break;
+    case 128:
+      *RRC_CONFIGURATION_REQ (msg_p).prach_StartingSubframe_r13[cc_idx][prachparamsindex] = LTE_PRACH_ParametersCE_r13__prach_StartingSubframe_r13_sf128;
+      break;
+    case 256:
+      *RRC_CONFIGURATION_REQ (msg_p).prach_StartingSubframe_r13[cc_idx][prachparamsindex] = LTE_PRACH_ParametersCE_r13__prach_StartingSubframe_r13_sf256;
+      break;
+    default:
+      AssertFatal(1==0,"prach_StartingSubframe_r13 %d is illegal\n",
+		  eMTCconfig->prach_StartingSubframe_r13);
+      break;
+    }
+
+    RRC_CONFIGURATION_REQ (msg_p).maxNumPreambleAttemptCE_r13[cc_idx][prachparamsindex] = calloc(1, sizeof(long));
+    if (eMTCconfig->maxNumPreambleAttemptCE_r13==10)  *RRC_CONFIGURATION_REQ (msg_p).maxNumPreambleAttemptCE_r13[cc_idx][prachparamsindex] = 6;
+    else                                              *RRC_CONFIGURATION_REQ (msg_p).maxNumPreambleAttemptCE_r13[cc_idx][prachparamsindex] = eMTCconfig->maxNumPreambleAttemptCE_r13-3;
+    AssertFatal(eMTCconfig->maxNumPreambleAttemptCE_r13 > 2 && eMTCconfig->maxNumPreambleAttemptCE_r13 <11,
+		"prachparamsindex %d: Illegal maxNumPreambleAttemptCE_r13 %d\n",
+		prachparamsindex,eMTCconfig->maxNumPreambleAttemptCE_r13);
+
+
+    switch(eMTCconfig->numRepetitionPerPreambleAttempt_r13) {
+    case 1:
+      RRC_CONFIGURATION_REQ (msg_p).numRepetitionPerPreambleAttempt_r13[cc_idx][prachparamsindex] = LTE_PRACH_ParametersCE_r13__numRepetitionPerPreambleAttempt_r13_n1;
+      break;
+    case 2:
+      RRC_CONFIGURATION_REQ (msg_p).numRepetitionPerPreambleAttempt_r13[cc_idx][prachparamsindex] = LTE_PRACH_ParametersCE_r13__numRepetitionPerPreambleAttempt_r13_n2;
+      break;
+    case 4:
+      RRC_CONFIGURATION_REQ (msg_p).numRepetitionPerPreambleAttempt_r13[cc_idx][prachparamsindex] = LTE_PRACH_ParametersCE_r13__numRepetitionPerPreambleAttempt_r13_n4;
+      break;
+    case 8:
+      RRC_CONFIGURATION_REQ (msg_p).numRepetitionPerPreambleAttempt_r13[cc_idx][prachparamsindex] = LTE_PRACH_ParametersCE_r13__numRepetitionPerPreambleAttempt_r13_n8;
+      break;
+    case 16:
+      RRC_CONFIGURATION_REQ (msg_p).numRepetitionPerPreambleAttempt_r13[cc_idx][prachparamsindex] = LTE_PRACH_ParametersCE_r13__numRepetitionPerPreambleAttempt_r13_n16;
+      break;
+    case 32:
+      RRC_CONFIGURATION_REQ (msg_p).numRepetitionPerPreambleAttempt_r13[cc_idx][prachparamsindex] = LTE_PRACH_ParametersCE_r13__numRepetitionPerPreambleAttempt_r13_n32;
+      break;
+    case 64:
+      RRC_CONFIGURATION_REQ (msg_p).numRepetitionPerPreambleAttempt_r13[cc_idx][prachparamsindex] = LTE_PRACH_ParametersCE_r13__numRepetitionPerPreambleAttempt_r13_n64;
+      break;
+    case 128:
+      RRC_CONFIGURATION_REQ (msg_p).numRepetitionPerPreambleAttempt_r13[cc_idx][prachparamsindex] = LTE_PRACH_ParametersCE_r13__numRepetitionPerPreambleAttempt_r13_n128;
+      break;
+    default:
+      AssertFatal(1==0,
+		  "illegal numReptitionPerPreambleAttempt %d\n",
+		  eMTCconfig->numRepetitionPerPreambleAttempt_r13);
+      break;
+    }
+    switch (eMTCconfig->mpdcch_NumRepetition_RA_r13) {
+    case 1:
+      RRC_CONFIGURATION_REQ (msg_p).mpdcch_NumRepetition_RA_r13[cc_idx][prachparamsindex] = LTE_PRACH_ParametersCE_r13__mpdcch_NumRepetition_RA_r13_r1;
+	break;
+    case 2:
+      RRC_CONFIGURATION_REQ (msg_p).mpdcch_NumRepetition_RA_r13[cc_idx][prachparamsindex] = LTE_PRACH_ParametersCE_r13__mpdcch_NumRepetition_RA_r13_r2;
+	break;
+    case 4:
+      RRC_CONFIGURATION_REQ (msg_p).mpdcch_NumRepetition_RA_r13[cc_idx][prachparamsindex] = LTE_PRACH_ParametersCE_r13__mpdcch_NumRepetition_RA_r13_r4;
+	break;
+    case 8:
+      RRC_CONFIGURATION_REQ (msg_p).mpdcch_NumRepetition_RA_r13[cc_idx][prachparamsindex] = LTE_PRACH_ParametersCE_r13__mpdcch_NumRepetition_RA_r13_r8;
+	break;
+    case 16:
+      RRC_CONFIGURATION_REQ (msg_p).mpdcch_NumRepetition_RA_r13[cc_idx][prachparamsindex] = LTE_PRACH_ParametersCE_r13__mpdcch_NumRepetition_RA_r13_r16;
+	break;
+    case 32:
+      RRC_CONFIGURATION_REQ (msg_p).mpdcch_NumRepetition_RA_r13[cc_idx][prachparamsindex] = LTE_PRACH_ParametersCE_r13__mpdcch_NumRepetition_RA_r13_r32;
+	break;
+    case 64:
+      RRC_CONFIGURATION_REQ (msg_p).mpdcch_NumRepetition_RA_r13[cc_idx][prachparamsindex] = LTE_PRACH_ParametersCE_r13__mpdcch_NumRepetition_RA_r13_r64;
+	break;
+    case 128:
+      RRC_CONFIGURATION_REQ (msg_p).mpdcch_NumRepetition_RA_r13[cc_idx][prachparamsindex] = LTE_PRACH_ParametersCE_r13__mpdcch_NumRepetition_RA_r13_r128;
+	break;
+    case 256:
+      RRC_CONFIGURATION_REQ (msg_p).mpdcch_NumRepetition_RA_r13[cc_idx][prachparamsindex] = LTE_PRACH_ParametersCE_r13__mpdcch_NumRepetition_RA_r13_r256;
+	break;
+    default:
+      AssertFatal (1==0,
+		 "illegal mpdcch_NumRepeition_RA_r13 %d\n",
+		   eMTCconfig->mpdcch_NumRepetition_RA_r13);
+      break;
+    }
+
+    RRC_CONFIGURATION_REQ (msg_p).prach_HoppingConfig_r13[cc_idx][prachparamsindex] = eMTCconfig->prach_HoppingConfig_r13;
+
+    AssertFatal (eMTCconfig->prach_HoppingConfig_r13 >=0 && eMTCconfig->prach_HoppingConfig_r13 < 2,
+		 "Illegal prach_HoppingConfig_r13 %d\n",eMTCconfig->prach_HoppingConfig_r13);
+
+
+    int maxavailablenarrowband_count = prachParams[7].numelt;
+
+    RRC_CONFIGURATION_REQ (msg_p).max_available_narrow_band_size[cc_idx][prachparamsindex] = maxavailablenarrowband_count;
+    int narrow_band_index;
+    for (narrow_band_index = 0; narrow_band_index < maxavailablenarrowband_count; narrow_band_index++) {
+      RRC_CONFIGURATION_REQ (msg_p).max_available_narrow_band[cc_idx][prachparamsindex][narrow_band_index] = prachParams[7].iptr[narrow_band_index];
+    }
+  }
+
+  char n1PUCCHInfoParamsPath[MAX_OPTNAME_SIZE * 2];
+  config_getlist(&n1PUCCHInfoList, NULL, 0, brparamspath);
+  RRC_CONFIGURATION_REQ (msg_p).pucch_info_value_size[cc_idx] = n1PUCCHInfoList.numelt;
+
+  int n1PUCCHinfolistindex;
+  for (n1PUCCHinfolistindex = 0; n1PUCCHinfolistindex < n1PUCCHInfoList.numelt; n1PUCCHinfolistindex++) {
+    sprintf(n1PUCCHInfoParamsPath, "%s.%s.[%i]", brparamspath, ENB_CONFIG_STRING_N1PUCCH_AN_INFOLIST_R13, n1PUCCHinfolistindex);
+    config_get(n1PUCCH_ANR13Params, sizeof(n1PUCCH_ANR13Params) / sizeof(paramdef_t), n1PUCCHInfoParamsPath);
+    RRC_CONFIGURATION_REQ (msg_p).pucch_info_value[cc_idx][n1PUCCHinfolistindex] = eMTCconfig->pucch_info_value;
+  }
+
+  char PCCHConfigv1310Path[MAX_OPTNAME_SIZE*2 + 16];
+  sprintf(PCCHConfigv1310Path, "%s.%s", brparamspath, ENB_CONFIG_STRING_PCCH_CONFIG_V1310);
+  config_get(pcchv1310Params, sizeof(pcchv1310Params)/sizeof(paramdef_t), PCCHConfigv1310Path);
+
+
+
+  /** PCCH CONFIG V1310 */
+
+  RRC_CONFIGURATION_REQ(msg_p).pcch_config_v1310[cc_idx] = TRUE;
+  RRC_CONFIGURATION_REQ(msg_p).paging_narrowbands_r13[cc_idx] = eMTCconfig->paging_narrowbands_r13;
+  RRC_CONFIGURATION_REQ(msg_p).mpdcch_numrepetition_paging_r13[cc_idx] = eMTCconfig->mpdcch_numrepetition_paging_r13;
+  AssertFatal (eMTCconfig->mpdcch_numrepetition_paging_r13 == 1 ||
+	       eMTCconfig->mpdcch_numrepetition_paging_r13 == 2 ||
+	       eMTCconfig->mpdcch_numrepetition_paging_r13 == 4 ||
+	       eMTCconfig->mpdcch_numrepetition_paging_r13 == 8 ||
+	       eMTCconfig->mpdcch_numrepetition_paging_r13 == 16 ||
+	       eMTCconfig->mpdcch_numrepetition_paging_r13 == 32 ||
+	       eMTCconfig->mpdcch_numrepetition_paging_r13 == 64 ||
+	       eMTCconfig->mpdcch_numrepetition_paging_r13 == 128 ||
+	       eMTCconfig->mpdcch_numrepetition_paging_r13 == 256,
+	       "illegal mpdcch_numrepetition_paging_r13 %d\n",
+	       eMTCconfig->mpdcch_numrepetition_paging_r13);
+
+
+  //                        RRC_CONFIGURATION_REQ(msg_p).nb_v1310[cc_idx] = CALLOC(1, sizeof(long));
+  //                        if (!strcmp(nb_v1310, "one64thT")) {
+  //                            *RRC_CONFIGURATION_REQ(msg_p).nb_v1310[cc_idx] = 0;
+  //                        } else if (!strcmp(nb_v1310, "one128thT")) {
+  //                            *RRC_CONFIGURATION_REQ(msg_p).nb_v1310[cc_idx] = 1;
+  //                        } else if (!strcmp(nb_v1310, "one256thT")) {
+  //                            *RRC_CONFIGURATION_REQ(msg_p).nb_v1310[cc_idx] = 2;
+  //                        } else {
+  //                            AssertFatal(0,
+  //                                        "Failed to parse eNB configuration file %s, nb_v1310, unknown value !\n",
+  //                                        config_fname);
+  //                        }
+
+
+
+  RRC_CONFIGURATION_REQ (msg_p).pucch_NumRepetitionCE_Msg4_Level0_r13[cc_idx] = CALLOC(1, sizeof(long));
+  // ++cnt; // check this ,, the conter is up above
+  if (!strcmp(eMTCconfig->pucch_NumRepetitionCE_Msg4_Level0_r13, "n1")) {
+    *RRC_CONFIGURATION_REQ (msg_p).pucch_NumRepetitionCE_Msg4_Level0_r13[cc_idx] = 0;
+  } else if (!strcmp(eMTCconfig->pucch_NumRepetitionCE_Msg4_Level0_r13, "n2")) {
+    *RRC_CONFIGURATION_REQ (msg_p).pucch_NumRepetitionCE_Msg4_Level0_r13[cc_idx] = 1;
+  } else if (!strcmp(eMTCconfig->pucch_NumRepetitionCE_Msg4_Level0_r13, "n4")) {
+    *RRC_CONFIGURATION_REQ (msg_p).pucch_NumRepetitionCE_Msg4_Level0_r13[cc_idx] = 2;
+  } else if (!strcmp(eMTCconfig->pucch_NumRepetitionCE_Msg4_Level0_r13, "n8")) {
+    *RRC_CONFIGURATION_REQ (msg_p).pucch_NumRepetitionCE_Msg4_Level0_r13[cc_idx] = 3;
+  } else {
+    AssertFatal (0,
+		 "Failed to parse eNB configuration file %s, pucch_NumRepetitionCE_Msg4_Level0_r13 unknown value!\n",
+		 config_fname);
+  }
+
+
+
+  /** SIB2 FREQ HOPPING PARAMETERS R13 */
+  RRC_CONFIGURATION_REQ(msg_p).sib2_freq_hoppingParameters_r13_exists[cc_idx] = TRUE;
+
+  char sib2FreqHoppingParametersR13Path[MAX_OPTNAME_SIZE*2 + 16];
+  sprintf(sib2FreqHoppingParametersR13Path, "%s.%s", brparamspath, ENB_CONFIG_STRING_SIB2_FREQ_HOPPINGPARAMETERS_R13);
+  config_get(sib2freqhoppingParams, sizeof(sib2freqhoppingParams)/sizeof(paramdef_t), sib2FreqHoppingParametersR13Path);
+
+
+  RRC_CONFIGURATION_REQ(msg_p).sib2_interval_ULHoppingConfigCommonModeA_r13[cc_idx] = CALLOC(1, sizeof(long));
+  if (!strcmp(eMTCconfig->sib2_interval_ULHoppingConfigCommonModeA_r13, "FDD")) {
+    *RRC_CONFIGURATION_REQ(msg_p).sib2_interval_ULHoppingConfigCommonModeA_r13[cc_idx] = 0;
+
+    switch(eMTCconfig->sib2_interval_ULHoppingConfigCommonModeA_r13_val) {
+    case 1:
+      RRC_CONFIGURATION_REQ(msg_p).sib2_interval_ULHoppingConfigCommonModeA_r13_val[cc_idx] = 0;
+      break;
+    case 2:
+      RRC_CONFIGURATION_REQ(msg_p).sib2_interval_ULHoppingConfigCommonModeA_r13_val[cc_idx] = 1;
+      break;
+    case 4:
+      RRC_CONFIGURATION_REQ(msg_p).sib2_interval_ULHoppingConfigCommonModeA_r13_val[cc_idx] = 2;
+      break;
+    case 8:
+      RRC_CONFIGURATION_REQ(msg_p).sib2_interval_ULHoppingConfigCommonModeA_r13_val[cc_idx] = 3;
+      break;
+    default:
+      AssertFatal(1==0,
+		  "illegal sib2_interval_ULHoppingConfigCommonModeA_r13_val %d\n",
+		  eMTCconfig->sib2_interval_ULHoppingConfigCommonModeA_r13_val);
+    }
+  } else if (!strcmp(eMTCconfig->sib2_interval_ULHoppingConfigCommonModeA_r13, "TDD")) {
+    *RRC_CONFIGURATION_REQ(msg_p).sib2_interval_ULHoppingConfigCommonModeA_r13[cc_idx] = 1;
+    switch(eMTCconfig->sib2_interval_ULHoppingConfigCommonModeA_r13_val) {
+    case 1:
+      RRC_CONFIGURATION_REQ(msg_p).sib2_interval_ULHoppingConfigCommonModeA_r13_val[cc_idx] = 0;
+      break;
+    case 5:
+      RRC_CONFIGURATION_REQ(msg_p).sib2_interval_ULHoppingConfigCommonModeA_r13_val[cc_idx] = 1;
+      break;
+    case 10:
+      RRC_CONFIGURATION_REQ(msg_p).sib2_interval_ULHoppingConfigCommonModeA_r13_val[cc_idx] = 2;
+      break;
+    case 20:
+      RRC_CONFIGURATION_REQ(msg_p).sib2_interval_ULHoppingConfigCommonModeA_r13_val[cc_idx] = 3;
+      break;
+    default:
+      AssertFatal(1==0,
+		  "illegal sib2_interval_ULHoppingConfigCommonModeA_r13_val %d\n",
+		  eMTCconfig->sib2_interval_ULHoppingConfigCommonModeA_r13_val);
+      break;
+    }
+  } else {
+    AssertFatal (1==0,
+		 "Failed to parse eNB configuration file %s, sib2_interval_ULHoppingConfigCommonModeA_r13 unknown value !!\n",
+		 config_fname);
+  }
+}
diff --git a/openair2/ENB_APP/enb_paramdef.h b/openair2/ENB_APP/enb_paramdef.h
old mode 100755
new mode 100644
index cc1e528bbc43e00016e4bf7f86eae9b11f91aa53..98a5e4206ea68f19d61c8b7af863ddebab4cf12a
--- a/openair2/ENB_APP/enb_paramdef.h
+++ b/openair2/ENB_APP/enb_paramdef.h
@@ -19,7 +19,7 @@
  *      contact@openairinterface.org
  */
 
-/*! \file openair2/ENB_APP/enb_paramdef.f
+/*! \file openair2/ENB_APP/enb_paramdef.h
  * \brief definition of configuration parameters for all eNodeB modules 
  * \author Francois TABURET
  * \date 2017
@@ -30,6 +30,8 @@
  * \warning
  */
 
+#ifndef ENB_PARAMDEF_H_
+#define ENB_PARAMDEF_H_
 #include "common/config/config_paramdesc.h"
 #include "RRC_paramsvalues.h"
 
@@ -298,12 +300,27 @@ typedef enum {
 #define ENB_CONFIG_STRING_PUCCH_DELTA_SHIFT                             "pucch_delta_shift"
 #define ENB_CONFIG_STRING_PUCCH_NRB_CQI                                 "pucch_nRB_CQI"
 #define ENB_CONFIG_STRING_PUCCH_NCS_AN                                  "pucch_nCS_AN"
-//#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+//#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 #define ENB_CONFIG_STRING_PUCCH_N1_AN                                   "pucch_n1_AN"
 //#endif
+
+#define ENB_CONFIG_STRING_PCCH_CONFIG_V1310                      "pcch_config_v1310"
+#define ENB_CONFIG_STRING_PAGING_NARROWBANDS_R13                 "paging_narrowbands_r13"
+#define ENB_CONFIG_STRING_MPDCCH_NUMREPETITION_PAGING_R13        "mpdcch_numrepetition_paging_r13"
+#define ENB_CONFIG_STRING_NB_V1310                               "nb_v1310"
+
+
+#define ENB_CONFIG_STRING_PUCCH_NUM_REPETITION_CE_MSG4_LEVEL0    "pucch_NumRepetitionCE_Msg4_Level0_r13"
+#define ENB_CONFIG_STRING_PUCCH_NUM_REPETITION_CE_MSG4_LEVEL1    "pucch_NumRepetitionCE_Msg4_Level1_r13"
+#define ENB_CONFIG_STRING_PUCCH_NUM_REPETITION_CE_MSG4_LEVEL2    "pucch_NumRepetitionCE_Msg4_Level2_r13"
+#define ENB_CONFIG_STRING_PUCCH_NUM_REPETITION_CE_MSG4_LEVEL3    "pucch_NumRepetitionCE_Msg4_Level3_r13"
+
+#define ENB_CONFIG_STRING_FREQ_HOPPING_PARAMETERS_R13                      "sib2_freq_hoppingParameters_r13"
+
+
 #define ENB_CONFIG_STRING_PDSCH_RS_EPRE                                 "pdsch_referenceSignalPower"
 #define ENB_CONFIG_STRING_PDSCH_PB                                      "pdsch_p_b"
-#define ENB_CONFIG_STRING_PUSCH_N_SB                                     "pusch_n_SB"
+#define ENB_CONFIG_STRING_PUSCH_N_SB                                    "pusch_n_SB"
 #define ENB_CONFIG_STRING_PUSCH_HOPPINGMODE                             "pusch_hoppingMode"
 #define ENB_CONFIG_STRING_PUSCH_HOPPINGOFFSET                           "pusch_hoppingOffset"
 #define ENB_CONFIG_STRING_PUSCH_ENABLE64QAM                             "pusch_enable64QAM"
@@ -327,6 +344,7 @@ typedef enum {
 #define ENB_CONFIG_STRING_PUCCH_DELTAF_FORMAT2                          "pucch_deltaF_Format2"
 #define ENB_CONFIG_STRING_PUCCH_DELTAF_FORMAT2A                         "pucch_deltaF_Format2a"
 #define ENB_CONFIG_STRING_PUCCH_DELTAF_FORMAT2B                         "pucch_deltaF_Format2b"
+
 #define ENB_CONFIG_STRING_RACH_NUM_RA_PREAMBLES                         "rach_numberOfRA_Preambles"
 #define ENB_CONFIG_STRING_RACH_PREAMBLESGROUPACONFIG                    "rach_preamblesGroupAConfig"
 #define ENB_CONFIG_STRING_RACH_SIZEOFRA_PREAMBLESGROUPA                 "rach_sizeOfRA_PreamblesGroupA"
@@ -350,6 +368,14 @@ typedef enum {
 #define ENB_CONFIG_STRING_UE_TRANSMISSION_MODE                          "ue_TransmissionMode"
 #define ENB_CONFIG_STRING_UE_MULTIPLE_MAX                               "ue_multiple_max"
 
+#define ENB_CONFIG_STRING_PDSCH_MAX_NUM_REPETITION_CE_MODE_A_R13        "pdsch_maxNumRepetitionCEmodeA_r13"
+#define ENB_CONFIG_STRING_PDSCH_MAX_NUM_REPETITION_CE_MODE_B_R13        "pdsch_maxNumRepetitionCEmodeB_r13"
+
+#define ENB_CONFIG_STRING_PUSCH_MAX_NUM_REPETITION_CE_MODE_A_R13        "pusch_maxNumRepetitionCEmodeA_r13"
+#define ENB_CONFIG_STRING_PUSCH_MAX_NUM_REPETITION_CE_MODE_B_R13        "pusch_maxNumRepetitionCEmodeB_r13"
+#define ENB_CONFIG_STRING_PUSCH_HOPPING_OFFSET_V1310                    "pusch_HoppingOffset_v1310"
+
+
 //TTN - for D2D
 //SIB18
 #define ENB_CONFIG_STRING_RXPOOL_SC_CP_LEN                              "rxPool_sc_CP_Len"
@@ -394,12 +420,93 @@ typedef enum {
 #define ENB_CONFIG_STRING_DISCRXPOOLPS_RC_SFBITMAP_CHOICE_BS_SIZE             "DISCRXPOOLPS_ResourceConfig_subframeBitmap_choice_bs_size"
 #define ENB_CONFIG_STRING_DISCRXPOOLPS_RC_SFBITMAP_CHOICE_BS_ASN_BITS_UNUSED  "DISCRXPOOLPS_ResourceConfig_subframeBitmap_choice_bs_bits_unused"
 
+
 /*-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
 /*                                     component carriers configuration parameters                                                                                                     */
 /*   optname                                                   helpstr   paramflags    XXXptr                                        defXXXval                    type         numelt  */
 /*-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
 /* init for checkedparam_t structure */
 
+typedef struct ccparams_lte_s {
+  char             *frame_type;
+  int32_t           tdd_config;
+  int32_t           tdd_config_s;
+  char             *prefix_type;
+  char             *pbch_repetition;
+  int32_t           eutra_band;
+  long long int     downlink_frequency;
+  int32_t           uplink_frequency_offset;
+  int32_t           Nid_cell;
+  int32_t           Nid_cell_mbsfn;
+  int32_t           N_RB_DL;
+  int32_t           nb_antenna_ports;
+  int32_t           prach_root;
+  int32_t           prach_config_index;
+  char             *prach_high_speed;
+  int32_t           prach_zero_correlation;
+  int32_t           prach_freq_offset;
+  int32_t           pucch_delta_shift;
+  int32_t           pucch_nRB_CQI;
+  int32_t           pucch_nCS_AN;
+  int32_t           pucch_n1_AN;
+  int32_t           pdsch_referenceSignalPower;
+  int32_t           pdsch_p_b;
+  int32_t           pusch_n_SB;
+  char             *pusch_hoppingMode;
+  int32_t           pusch_hoppingOffset;
+  char             *pusch_enable64QAM;
+  char             *pusch_groupHoppingEnabled;
+  int32_t           pusch_groupAssignment;
+  char             *pusch_sequenceHoppingEnabled;
+  int32_t           pusch_nDMRS1;
+  char             *phich_duration;
+  char             *phich_resource;
+  char             *srs_enable;
+  int32_t           srs_BandwidthConfig;
+  int32_t           srs_SubframeConfig;
+  char             *srs_ackNackST;
+  char             *srs_MaxUpPts;
+  int32_t           pusch_p0_Nominal;
+  char             *pusch_alpha;
+  int32_t           pucch_p0_Nominal;
+  int32_t           msg3_delta_Preamble;
+  int32_t           ul_CyclicPrefixLength;
+  char             *pucch_deltaF_Format1;
+  char             *pucch_deltaF_Format1a;
+  char             *pucch_deltaF_Format1b;
+  char             *pucch_deltaF_Format2;
+  char             *pucch_deltaF_Format2a;
+  char             *pucch_deltaF_Format2b;
+  int32_t           rach_numberOfRA_Preambles;
+  char             *rach_preamblesGroupAConfig;
+  int32_t           rach_sizeOfRA_PreamblesGroupA;
+  int32_t           rach_messageSizeGroupA;
+  char             *rach_messagePowerOffsetGroupB;
+  int32_t           rach_powerRampingStep;
+  int32_t           rach_preambleInitialReceivedTargetPower;
+  int32_t           rach_preambleTransMax;
+  int32_t           rach_raResponseWindowSize;
+  int32_t           rach_macContentionResolutionTimer;
+  int32_t           rach_maxHARQ_Msg3Tx;
+  int32_t           pcch_defaultPagingCycle;
+  char             *pcch_nB;
+  int32_t           bcch_modificationPeriodCoeff;
+  int32_t           ue_TimersAndConstants_t300;
+  int32_t           ue_TimersAndConstants_t301;
+  int32_t           ue_TimersAndConstants_t310;
+  int32_t           ue_TimersAndConstants_t311;
+  int32_t           ue_TimersAndConstants_n310;
+  int32_t           ue_TimersAndConstants_n311;
+  int32_t           ue_TransmissionMode;
+  int32_t           ue_multiple_max;
+  int32_t           srb1_timer_poll_retransmit;
+  int32_t           srb1_timer_reordering;
+  int32_t           srb1_timer_status_prohibit;
+  int32_t           srb1_poll_pdu;
+  int32_t           srb1_poll_byte;
+  int32_t           srb1_max_retx_threshold;
+} ccparams_lte_t;
+
 #define CCPARAMS_CHECK                 {                                     \
              { .s5= {NULL }} ,						     \
              { .s5= {NULL }} ,						     \
@@ -507,123 +614,87 @@ typedef enum {
                           { .s5= {NULL }} ,						     \
                           { .s5= {NULL }} ,						     \
                           { .s5= {NULL }} ,						     \
-                          { .s5= {NULL }} ,						     \
+			  { .s5= {NULL }}				\
 }
 /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
 /*                                     component carriers configuration parameters                                                                                                                   */
 /*   optname                                                   helpstr   paramflags    XXXptr                                        defXXXval                    type         numelt  checked_param */
 /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
 
-#define CCPARAMS_DESC { \
-{ENB_CONFIG_STRING_FRAME_TYPE,                                   NULL,   0,           strptr:&frame_type,                             defstrval:"FDD",           TYPE_STRING,     0},  \
-{ENB_CONFIG_STRING_TDD_CONFIG,                                   NULL,   0,           iptr:&tdd_config,                               defintval:3,               TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_TDD_CONFIG_S,                                 NULL,   0,           iptr:&tdd_config_s,                             defintval:0,               TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_PREFIX_TYPE,                                  NULL,   0,           strptr:&prefix_type,                            defstrval:"NORMAL",        TYPE_STRING,     0},  \
-{ENB_CONFIG_STRING_PBCH_REPETITION,                              NULL,   0,           strptr:&pbch_repetition,                        defstrval:"FALSE",         TYPE_STRING,     0},  \
-{ENB_CONFIG_STRING_EUTRA_BAND,                                   NULL,   0,           iptr:&eutra_band,                               defintval:7,               TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_DOWNLINK_FREQUENCY,                           NULL,   0,           i64ptr:(int64_t *)&downlink_frequency,          defint64val:2680000000,    TYPE_UINT64,     0},  \
-{ENB_CONFIG_STRING_UPLINK_FREQUENCY_OFFSET,                      NULL,   0,           iptr:&uplink_frequency_offset,                  defintval:-120000000,      TYPE_INT,        0},  \
-{ENB_CONFIG_STRING_NID_CELL,                                     NULL,   0,           iptr:&Nid_cell,                                 defintval:0,               TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_N_RB_DL,                                      NULL,   0,           iptr:&N_RB_DL,                                  defintval:25,              TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_CELL_MBSFN,                                   NULL,   0,           iptr:&Nid_cell_mbsfn,                           defintval:0,               TYPE_INT,        0},  \
-{ENB_CONFIG_STRING_NB_ANT_PORTS,                                 NULL,   0,           iptr:&nb_antenna_ports,                         defintval:1,               TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_PRACH_ROOT,                                   NULL,   0,           iptr:&prach_root,                               defintval:0,               TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_PRACH_CONFIG_INDEX,                           NULL,   0,           iptr:&prach_config_index,                       defintval:0,               TYPE_INT,        0},  \
-{ENB_CONFIG_STRING_PRACH_HIGH_SPEED,                             NULL,   0,           strptr:&prach_high_speed,                       defstrval:"DISABLE",       TYPE_STRING,     0},  \
-{ENB_CONFIG_STRING_PRACH_ZERO_CORRELATION,                       NULL,   0,           iptr:&prach_zero_correlation,                   defintval:1,               TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_PRACH_FREQ_OFFSET,                            NULL,   0,           iptr:&prach_freq_offset,                        defintval:2,               TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_PUCCH_DELTA_SHIFT,                            NULL,   0,           iptr:&pucch_delta_shift,                        defintval:1,               TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_PUCCH_NRB_CQI,                                NULL,   0,           iptr:&pucch_nRB_CQI,                            defintval:1,               TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_PUCCH_NCS_AN,                                 NULL,   0,           iptr:&pucch_nCS_AN,                             defintval:0,               TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_PUCCH_N1_AN,                                  NULL,   0,           iptr:&pucch_n1_AN,                              defintval:0,               TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_PDSCH_RS_EPRE,                                NULL,   0,           iptr:&pdsch_referenceSignalPower,               defintval:-29,             TYPE_INT,        0},  \
-{ENB_CONFIG_STRING_PDSCH_PB,                                     NULL,   0,           iptr:&pdsch_p_b,                                defintval:0,               TYPE_INT,        0},  \
-{ENB_CONFIG_STRING_PUSCH_N_SB,                                   NULL,   0,           iptr:&pusch_n_SB,                               defintval:1,               TYPE_INT,        0},  \
-{ENB_CONFIG_STRING_PUSCH_HOPPINGMODE,                            NULL,   0,           strptr:&pusch_hoppingMode,                      defstrval:"interSubFrame", TYPE_STRING,     0},  \
-{ENB_CONFIG_STRING_PUSCH_HOPPINGOFFSET,                          NULL,   0,           iptr:&pusch_hoppingOffset,                      defintval:0,               TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_PUSCH_ENABLE64QAM,                            NULL,   0,           strptr:&pusch_enable64QAM,                      defstrval:"DISABLE",       TYPE_STRING,     0},  \
-{ENB_CONFIG_STRING_PUSCH_GROUP_HOPPING_EN,                       NULL,   0,           strptr:&pusch_groupHoppingEnabled,              defstrval:"ENABLE",        TYPE_STRING,     0},  \
-{ENB_CONFIG_STRING_PUSCH_GROUP_ASSIGNMENT,                       NULL,   0,           iptr:&pusch_groupAssignment,                    defintval:0,               TYPE_INT,        0},  \
-{ENB_CONFIG_STRING_PUSCH_SEQUENCE_HOPPING_EN,                    NULL,   0,           strptr:&pusch_sequenceHoppingEnabled,           defstrval:"DISABLE",       TYPE_STRING,     0},  \
-{ENB_CONFIG_STRING_PUSCH_NDMRS1,                                 NULL,   0,           iptr:&pusch_nDMRS1,                             defintval:0,               TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_PHICH_DURATION,                               NULL,   0,           strptr:&phich_duration,                         defstrval:"NORMAL",        TYPE_STRING,     0},  \
-{ENB_CONFIG_STRING_PHICH_RESOURCE,                               NULL,   0,           strptr:&phich_resource,                         defstrval:"ONESIXTH",      TYPE_STRING,     0},  \
-{ENB_CONFIG_STRING_SRS_ENABLE,                                   NULL,   0,           strptr:&srs_enable,                             defstrval:"DISABLE",       TYPE_STRING,     0},  \
-{ENB_CONFIG_STRING_SRS_BANDWIDTH_CONFIG,                         NULL,   0,           iptr:&srs_BandwidthConfig,                      defintval:0,               TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_SRS_SUBFRAME_CONFIG,                          NULL,   0,           iptr:&srs_SubframeConfig,                       defintval:0,               TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_SRS_ACKNACKST_CONFIG,                         NULL,   0,           strptr:&srs_ackNackST,                          defstrval:"DISABLE",       TYPE_STRING,     0},  \
-{ENB_CONFIG_STRING_SRS_MAXUPPTS,                                 NULL,   0,           strptr:&srs_MaxUpPts,                           defstrval:"DISABLE",       TYPE_STRING,     0},  \
-{ENB_CONFIG_STRING_PUSCH_PO_NOMINAL,                             NULL,   0,           iptr:&pusch_p0_Nominal,                         defintval:-90,             TYPE_INT,        0},  \
-{ENB_CONFIG_STRING_PUSCH_ALPHA,                                  NULL,   0,           strptr:&pusch_alpha,                            defstrval:"AL1",           TYPE_STRING,     0},  \
-{ENB_CONFIG_STRING_PUCCH_PO_NOMINAL,                             NULL,   0,           iptr:&pucch_p0_Nominal,                         defintval:-96,             TYPE_INT,        0},  \
-{ENB_CONFIG_STRING_MSG3_DELTA_PREAMBLE,                          NULL,   0,           iptr:&msg3_delta_Preamble,                      defintval:6,               TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_PUCCH_DELTAF_FORMAT1,                         NULL,   0,           strptr:&pucch_deltaF_Format1,                   defstrval:"DELTAF2",       TYPE_STRING,     0},  \
-{ENB_CONFIG_STRING_PUCCH_DELTAF_FORMAT1b,                        NULL,   0,           strptr:&pucch_deltaF_Format1b,                  defstrval:"deltaF3",       TYPE_STRING,     0},  \
-{ENB_CONFIG_STRING_PUCCH_DELTAF_FORMAT2,                         NULL,   0,           strptr:&pucch_deltaF_Format2,                   defstrval:"deltaF0",       TYPE_STRING,     0},  \
-{ENB_CONFIG_STRING_PUCCH_DELTAF_FORMAT2A,                        NULL,   0,           strptr:&pucch_deltaF_Format2a,                  defstrval:"deltaF0",       TYPE_STRING,     0},  \
-{ENB_CONFIG_STRING_PUCCH_DELTAF_FORMAT2B,                        NULL,   0,           strptr:&pucch_deltaF_Format2b,                  defstrval:"deltaF0",       TYPE_STRING,     0},  \
-{ENB_CONFIG_STRING_RACH_NUM_RA_PREAMBLES,                        NULL,   0,           iptr:&rach_numberOfRA_Preambles,                defintval:4,               TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_RACH_PREAMBLESGROUPACONFIG,                   NULL,   0,           strptr:&rach_preamblesGroupAConfig,             defstrval:"DISABLE",       TYPE_STRING,     0},  \
-{ENB_CONFIG_STRING_RACH_SIZEOFRA_PREAMBLESGROUPA,                NULL,   0,           iptr:&rach_sizeOfRA_PreamblesGroupA,            defintval:0,               TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_RACH_MESSAGESIZEGROUPA,                       NULL,   0,           iptr:&rach_messageSizeGroupA,                   defintval:56,              TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_RACH_MESSAGEPOWEROFFSETGROUPB,                NULL,   0,           strptr:&rach_messagePowerOffsetGroupB,          defstrval:"minusinfinity", TYPE_STRING,     0},  \
-{ENB_CONFIG_STRING_RACH_POWERRAMPINGSTEP,                        NULL,   0,           iptr:&rach_powerRampingStep,                    defintval:4,               TYPE_INT,        0},  \
-{ENB_CONFIG_STRING_RACH_PREAMBLEINITIALRECEIVEDTARGETPOWER,      NULL,   0,           iptr:&rach_preambleInitialReceivedTargetPower,  defintval:-100,            TYPE_INT,        0},  \
-{ENB_CONFIG_STRING_RACH_PREAMBLETRANSMAX,                        NULL,   0,           iptr:&rach_preambleTransMax,                    defintval:10,              TYPE_INT,        0},  \
-{ENB_CONFIG_STRING_RACH_RARESPONSEWINDOWSIZE,                    NULL,   0,           iptr:&rach_raResponseWindowSize,                defintval:10,              TYPE_INT,        0},  \
-{ENB_CONFIG_STRING_RACH_MACCONTENTIONRESOLUTIONTIMER,            NULL,   0,           iptr:&rach_macContentionResolutionTimer,        defintval:48,              TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_RACH_MAXHARQMSG3TX,                           NULL,   0,           iptr:&rach_maxHARQ_Msg3Tx,                      defintval:4,               TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_PCCH_DEFAULT_PAGING_CYCLE,                    NULL,   0,           iptr:&pcch_defaultPagingCycle,                  defintval:128,             TYPE_INT,        0},  \
-{ENB_CONFIG_STRING_PCCH_NB,                                      NULL,   0,           strptr:&pcch_nB,                                defstrval:"oneT",          TYPE_STRING,     0},  \
-{ENB_CONFIG_STRING_BCCH_MODIFICATIONPERIODCOEFF,                 NULL,   0,           iptr:&bcch_modificationPeriodCoeff,             defintval:2,               TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_UETIMERS_T300,                                NULL,   0,           iptr:&ue_TimersAndConstants_t300,               defintval:1000,            TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_UETIMERS_T301,                                NULL,   0,           iptr:&ue_TimersAndConstants_t301,               defintval:1000,            TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_UETIMERS_T310,                                NULL,   0,           iptr:&ue_TimersAndConstants_t310,               defintval:1000,            TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_UETIMERS_T311,                                NULL,   0,           iptr:&ue_TimersAndConstants_t311,               defintval:10000,           TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_UETIMERS_N310,                                NULL,   0,           iptr:&ue_TimersAndConstants_n310,               defintval:20,              TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_UETIMERS_N311,                                NULL,   0,           iptr:&ue_TimersAndConstants_n311,               defintval:1,               TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_UE_TRANSMISSION_MODE,                         NULL,   0,           iptr:&ue_TransmissionMode,                      defintval:1,               TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_UE_MULTIPLE_MAX,                              NULL,   0,           iptr:&ue_multiple_max,                          defintval:4,               TYPE_UINT,       0},  \
-{ENB_CONFIG_STRING_RXPOOL_SC_CP_LEN,                             NULL,   0,   strptr:(char **)&rxPool_sc_CP_Len,          defstrval:"normal",  TYPE_STRING,  0}, \
-{ENB_CONFIG_STRING_RXPOOL_SC_PRIOD,                              NULL,   0,   strptr:(char **)&rxPool_sc_Period,          defstrval:"sf40",  TYPE_STRING,  0}, \
-{ENB_CONFIG_STRING_RXPOOL_DATA_CP_LEN,                           NULL,   0,   strptr:(char **)&rxPool_data_CP_Len,          defstrval:"normal",  TYPE_STRING,  0}, \
-{ENB_CONFIG_STRING_RXPOOL_RC_PRB_NUM,                            NULL,   0,   iptr:(int32_t *)&rxPool_ResourceConfig_prb_Num,         defintval:1,       TYPE_UINT,    0}, \
-{ENB_CONFIG_STRING_RXPOOL_RC_PRB_START,                          NULL,   0,   iptr:(int32_t *)&rxPool_ResourceConfig_prb_Start,         defintval:1,       TYPE_UINT,    0}, \
-{ENB_CONFIG_STRING_RXPOOL_RC_PRB_END,                            NULL,   0,   iptr:(int32_t *)&rxPool_ResourceConfig_prb_End,         defintval:1,       TYPE_UINT,    0}, \
-{ENB_CONFIG_STRING_RXPOOL_RC_OFFSETIND_PRESENT,                  NULL,   0,   strptr:(char **)&rxPool_ResourceConfig_offsetIndicator_present,            defstrval:"prNothing",  TYPE_STRING,  0}, \
-{ENB_CONFIG_STRING_RXPOOL_RC_OFFSETIND_CHOICE,                   NULL,   0,   iptr:(int32_t *)&rxPool_ResourceConfig_offsetIndicator_choice,         defintval:1,       TYPE_UINT,    0}, \
-{ENB_CONFIG_STRING_RXPOOL_RC_SFBITMAP_PRESENT,                   NULL,   0,   strptr:(char **)&rxPool_ResourceConfig_subframeBitmap_present,            defstrval:"prNothing",  TYPE_STRING,  0}, \
-{ENB_CONFIG_STRING_RXPOOL_RC_SFBITMAP_CHOICE_BS_BUF,             NULL,   0,   strptr:(char **)&rxPool_ResourceConfig_subframeBitmap_choice_bs_buf,            defstrval:"001001",  TYPE_STRING,  0}, \
-{ENB_CONFIG_STRING_RXPOOL_RC_SFBITMAP_CHOICE_BS_SIZE,            NULL,   0,   iptr:(int32_t *)&rxPool_ResourceConfig_subframeBitmap_choice_bs_size,         defintval:1,       TYPE_UINT,    0}, \
-{ENB_CONFIG_STRING_RXPOOL_RC_SFBITMAP_CHOICE_BS_ASN_BITS_UNUSED, NULL,   0,   iptr:(int32_t *)&rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused,         defintval:1,       TYPE_UINT,    0}, \
-{ENB_CONFIG_STRING_DISCRXPOOL_CP_LEN,                            NULL,   0,   strptr:(char **)&discRxPool_cp_Len,          defstrval:"normal",  TYPE_STRING,  0}, \
-{ENB_CONFIG_STRING_DISCRXPOOL_DISCPERIOD,                        NULL,   0,   strptr:(char **)&discRxPool_discPeriod,          defstrval:"rf32",  TYPE_STRING,  0}, \
-{ENB_CONFIG_STRING_DISCRXPOOL_NUMRETX,                           NULL,   0,   iptr:(int32_t *)&discRxPool_numRetx,         defintval:1,       TYPE_UINT,    0}, \
-{ENB_CONFIG_STRING_DISCRXPOOL_NUMREPETITION,                     NULL,   0,   iptr:(int32_t *)&discRxPool_numRepetition,         defintval:1,       TYPE_UINT,    0}, \
-{ENB_CONFIG_STRING_DISCRXPOOL_RC_PRB_NUM,                        NULL,   0,   iptr:(int32_t *)&discRxPool_ResourceConfig_prb_Num,         defintval:1,       TYPE_UINT,    0}, \
-{ENB_CONFIG_STRING_DISCRXPOOL_RC_PRB_START,                      NULL,   0,   iptr:(int32_t *)&discRxPool_ResourceConfig_prb_Start,         defintval:1,       TYPE_UINT,    0}, \
-{ENB_CONFIG_STRING_DISCRXPOOL_RC_PRB_END,                        NULL,   0,   iptr:(int32_t *)&discRxPool_ResourceConfig_prb_End,         defintval:1,       TYPE_UINT,    0}, \
-{ENB_CONFIG_STRING_DISCRXPOOL_RC_OFFSETIND_PRESENT,              NULL,   0,   strptr:(char **)&discRxPool_ResourceConfig_offsetIndicator_present,            defstrval:"prNothing",  TYPE_STRING,  0}, \
-{ENB_CONFIG_STRING_DISCRXPOOL_RC_OFFSETIND_CHOICE,               NULL,   0,   iptr:(int32_t *)&discRxPool_ResourceConfig_offsetIndicator_choice,         defintval:1,       TYPE_UINT,    0}, \
-{ENB_CONFIG_STRING_DISCRXPOOL_RC_SFBITMAP_PRESENT,               NULL,   0,   strptr:(char **)&discRxPool_ResourceConfig_subframeBitmap_present,            defstrval:"prNothing",  TYPE_STRING,  0}, \
-{ENB_CONFIG_STRING_DISCRXPOOL_RC_SFBITMAP_CHOICE_BS_BUF,         NULL,   0,   strptr:(char **)&discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf,            defstrval:"001001",  TYPE_STRING,  0}, \
-{ENB_CONFIG_STRING_DISCRXPOOL_RC_SFBITMAP_CHOICE_BS_SIZE,        NULL,   0,   iptr:(int32_t *)&discRxPool_ResourceConfig_subframeBitmap_choice_bs_size,         defintval:1,       TYPE_UINT,    0}, \
-{ENB_CONFIG_STRING_DISCRXPOOL_RC_SFBITMAP_CHOICE_BS_ASN_BITS_UNUSED,NULL,   0,   iptr:(int32_t *)&discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused,         defintval:1,       TYPE_UINT,    0}, \
-{ENB_CONFIG_STRING_DISCRXPOOLPS_CP_LEN,                            NULL,   0,   strptr:(char **)&discRxPoolPS_cp_Len,          defstrval:"normal",  TYPE_STRING,  0}, \
-{ENB_CONFIG_STRING_DISCRXPOOLPS_DISCPERIOD,                        NULL,   0,   strptr:(char **)&discRxPoolPS_discPeriod,          defstrval:"rf32",  TYPE_STRING,  0}, \
-{ENB_CONFIG_STRING_DISCRXPOOLPS_NUMRETX,                           NULL,   0,   iptr:(int32_t *)&discRxPoolPS_numRetx,         defintval:1,       TYPE_UINT,    0}, \
-{ENB_CONFIG_STRING_DISCRXPOOLPS_NUMREPETITION,                     NULL,   0,   iptr:(int32_t *)&discRxPoolPS_numRepetition,         defintval:1,       TYPE_UINT,    0}, \
-{ENB_CONFIG_STRING_DISCRXPOOLPS_RC_PRB_NUM,                        NULL,   0,   iptr:(int32_t *)&discRxPoolPS_ResourceConfig_prb_Num,         defintval:1,       TYPE_UINT,    0}, \
-{ENB_CONFIG_STRING_DISCRXPOOLPS_RC_PRB_START,                      NULL,   0,   iptr:(int32_t *)&discRxPoolPS_ResourceConfig_prb_Start,         defintval:1,       TYPE_UINT,    0}, \
-{ENB_CONFIG_STRING_DISCRXPOOLPS_RC_PRB_END,                        NULL,   0,   iptr:(int32_t *)&discRxPoolPS_ResourceConfig_prb_End,         defintval:1,       TYPE_UINT,    0}, \
-{ENB_CONFIG_STRING_DISCRXPOOLPS_RC_OFFSETIND_PRESENT,              NULL,   0,   strptr:(char **)&discRxPoolPS_ResourceConfig_offsetIndicator_present,            defstrval:"prNothing",  TYPE_STRING,  0}, \
-{ENB_CONFIG_STRING_DISCRXPOOLPS_RC_OFFSETIND_CHOICE,               NULL,   0,   iptr:(int32_t *)&discRxPoolPS_ResourceConfig_offsetIndicator_choice,         defintval:1,       TYPE_UINT,    0}, \
-{ENB_CONFIG_STRING_DISCRXPOOLPS_RC_SFBITMAP_PRESENT,               NULL,   0,   strptr:(char **)&discRxPoolPS_ResourceConfig_subframeBitmap_present,            defstrval:"prNothing",  TYPE_STRING,  0}, \
-{ENB_CONFIG_STRING_DISCRXPOOLPS_RC_SFBITMAP_CHOICE_BS_BUF,         NULL,   0,   strptr:(char **)&discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_buf,            defstrval:"001001",  TYPE_STRING,  0}, \
-{ENB_CONFIG_STRING_DISCRXPOOLPS_RC_SFBITMAP_CHOICE_BS_SIZE,        NULL,   0,   iptr:(int32_t *)&discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_size,         defintval:1,       TYPE_UINT,    0}, \
-{ENB_CONFIG_STRING_DISCRXPOOLPS_RC_SFBITMAP_CHOICE_BS_ASN_BITS_UNUSED,NULL,   0,   iptr:(int32_t *)&discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_bits_unused,         defintval:1,       TYPE_UINT,    0} \
+#define CCPARAMS_DESC(ccparams) {					\
+{ENB_CONFIG_STRING_FRAME_TYPE,                                   NULL,   0,           strptr:&ccparams.frame_type,                             defstrval:"FDD",           TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_TDD_CONFIG,                                   NULL,   0,           iptr:&ccparams.tdd_config,                               defintval:3,               TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_TDD_CONFIG_S,                                 NULL,   0,           iptr:&ccparams.tdd_config_s,                             defintval:0,               TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_PREFIX_TYPE,                                  NULL,   0,           strptr:&ccparams.prefix_type,                            defstrval:"NORMAL",        TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_PBCH_REPETITION,                              NULL,   0,           strptr:&ccparams.pbch_repetition,                        defstrval:"FALSE",         TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_EUTRA_BAND,                                   NULL,   0,           iptr:&ccparams.eutra_band,                               defintval:7,               TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_DOWNLINK_FREQUENCY,                           NULL,   0,           i64ptr:(int64_t *)&ccparams.downlink_frequency,          defint64val:2680000000,    TYPE_UINT64,     0},  \
+{ENB_CONFIG_STRING_UPLINK_FREQUENCY_OFFSET,                      NULL,   0,           iptr:&ccparams.uplink_frequency_offset,                  defintval:-120000000,      TYPE_INT,        0},  \
+{ENB_CONFIG_STRING_NID_CELL,                                     NULL,   0,           iptr:&ccparams.Nid_cell,                                 defintval:0,               TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_N_RB_DL,                                      NULL,   0,           iptr:&ccparams.N_RB_DL,                                  defintval:25,              TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_CELL_MBSFN,                                   NULL,   0,           iptr:&ccparams.Nid_cell_mbsfn,                           defintval:0,               TYPE_INT,        0},  \
+{ENB_CONFIG_STRING_NB_ANT_PORTS,                                 NULL,   0,           iptr:&ccparams.nb_antenna_ports,                         defintval:1,               TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_PRACH_ROOT,                                   NULL,   0,           iptr:&ccparams.prach_root,                               defintval:0,               TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_PRACH_CONFIG_INDEX,                           NULL,   0,           iptr:&ccparams.prach_config_index,                       defintval:0,               TYPE_INT,        0},  \
+{ENB_CONFIG_STRING_PRACH_HIGH_SPEED,                             NULL,   0,           strptr:&ccparams.prach_high_speed,                       defstrval:"DISABLE",       TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_PRACH_ZERO_CORRELATION,                       NULL,   0,           iptr:&ccparams.prach_zero_correlation,                   defintval:1,               TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_PRACH_FREQ_OFFSET,                            NULL,   0,           iptr:&ccparams.prach_freq_offset,                        defintval:2,               TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_PUCCH_DELTA_SHIFT,                            NULL,   0,           iptr:&ccparams.pucch_delta_shift,                        defintval:1,               TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_PUCCH_NRB_CQI,                                NULL,   0,           iptr:&ccparams.pucch_nRB_CQI,                            defintval:1,               TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_PUCCH_NCS_AN,                                 NULL,   0,           iptr:&ccparams.pucch_nCS_AN,                             defintval:0,               TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_PUCCH_N1_AN,                                  NULL,   0,           iptr:&ccparams.pucch_n1_AN,                              defintval:0,               TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_PDSCH_RS_EPRE,                                NULL,   0,           iptr:&ccparams.pdsch_referenceSignalPower,               defintval:-29,             TYPE_INT,        0},  \
+{ENB_CONFIG_STRING_PDSCH_PB,                                     NULL,   0,           iptr:&ccparams.pdsch_p_b,                                defintval:0,               TYPE_INT,        0},  \
+{ENB_CONFIG_STRING_PUSCH_N_SB,                                   NULL,   0,           iptr:&ccparams.pusch_n_SB,                               defintval:1,               TYPE_INT,        0},  \
+{ENB_CONFIG_STRING_PUSCH_HOPPINGMODE,                            NULL,   0,           strptr:&ccparams.pusch_hoppingMode,                      defstrval:"interSubFrame", TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_PUSCH_HOPPINGOFFSET,                          NULL,   0,           iptr:&ccparams.pusch_hoppingOffset,                      defintval:0,               TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_PUSCH_ENABLE64QAM,                            NULL,   0,           strptr:&ccparams.pusch_enable64QAM,                      defstrval:"DISABLE",       TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_PUSCH_GROUP_HOPPING_EN,                       NULL,   0,           strptr:&ccparams.pusch_groupHoppingEnabled,              defstrval:"ENABLE",        TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_PUSCH_GROUP_ASSIGNMENT,                       NULL,   0,           iptr:&ccparams.pusch_groupAssignment,                    defintval:0,               TYPE_INT,        0},  \
+{ENB_CONFIG_STRING_PUSCH_SEQUENCE_HOPPING_EN,                    NULL,   0,           strptr:&ccparams.pusch_sequenceHoppingEnabled,           defstrval:"DISABLE",       TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_PUSCH_NDMRS1,                                 NULL,   0,           iptr:&ccparams.pusch_nDMRS1,                             defintval:0,               TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_PHICH_DURATION,                               NULL,   0,           strptr:&ccparams.phich_duration,                         defstrval:"NORMAL",        TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_PHICH_RESOURCE,                               NULL,   0,           strptr:&ccparams.phich_resource,                         defstrval:"ONESIXTH",      TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_SRS_ENABLE,                                   NULL,   0,           strptr:&ccparams.srs_enable,                             defstrval:"DISABLE",       TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_SRS_BANDWIDTH_CONFIG,                         NULL,   0,           iptr:&ccparams.srs_BandwidthConfig,                      defintval:0,               TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_SRS_SUBFRAME_CONFIG,                          NULL,   0,           iptr:&ccparams.srs_SubframeConfig,                       defintval:0,               TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_SRS_ACKNACKST_CONFIG,                         NULL,   0,           strptr:&ccparams.srs_ackNackST,                          defstrval:"DISABLE",       TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_SRS_MAXUPPTS,                                 NULL,   0,           strptr:&ccparams.srs_MaxUpPts,                           defstrval:"DISABLE",       TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_PUSCH_PO_NOMINAL,                             NULL,   0,           iptr:&ccparams.pusch_p0_Nominal,                         defintval:-90,             TYPE_INT,        0},  \
+{ENB_CONFIG_STRING_PUSCH_ALPHA,                                  NULL,   0,           strptr:&ccparams.pusch_alpha,                            defstrval:"AL1",           TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_PUCCH_PO_NOMINAL,                             NULL,   0,           iptr:&ccparams.pucch_p0_Nominal,                         defintval:-96,             TYPE_INT,        0},  \
+{ENB_CONFIG_STRING_MSG3_DELTA_PREAMBLE,                          NULL,   0,           iptr:&ccparams.msg3_delta_Preamble,                      defintval:6,               TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_PUCCH_DELTAF_FORMAT1,                         NULL,   0,           strptr:&ccparams.pucch_deltaF_Format1,                   defstrval:"DELTAF2",       TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_PUCCH_DELTAF_FORMAT1b,                        NULL,   0,           strptr:&ccparams.pucch_deltaF_Format1b,                  defstrval:"deltaF3",       TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_PUCCH_DELTAF_FORMAT2,                         NULL,   0,           strptr:&ccparams.pucch_deltaF_Format2,                   defstrval:"deltaF0",       TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_PUCCH_DELTAF_FORMAT2A,                        NULL,   0,           strptr:&ccparams.pucch_deltaF_Format2a,                  defstrval:"deltaF0",       TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_PUCCH_DELTAF_FORMAT2B,                        NULL,   0,           strptr:&ccparams.pucch_deltaF_Format2b,                  defstrval:"deltaF0",       TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_RACH_NUM_RA_PREAMBLES,                        NULL,   0,           iptr:&ccparams.rach_numberOfRA_Preambles,                defintval:4,               TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_RACH_PREAMBLESGROUPACONFIG,                   NULL,   0,           strptr:&ccparams.rach_preamblesGroupAConfig,             defstrval:"DISABLE",       TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_RACH_SIZEOFRA_PREAMBLESGROUPA,                NULL,   0,           iptr:&ccparams.rach_sizeOfRA_PreamblesGroupA,            defintval:0,               TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_RACH_MESSAGESIZEGROUPA,                       NULL,   0,           iptr:&ccparams.rach_messageSizeGroupA,                   defintval:56,              TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_RACH_MESSAGEPOWEROFFSETGROUPB,                NULL,   0,           strptr:&ccparams.rach_messagePowerOffsetGroupB,          defstrval:"minusinfinity", TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_RACH_POWERRAMPINGSTEP,                        NULL,   0,           iptr:&ccparams.rach_powerRampingStep,                    defintval:4,               TYPE_INT,        0},  \
+{ENB_CONFIG_STRING_RACH_PREAMBLEINITIALRECEIVEDTARGETPOWER,      NULL,   0,           iptr:&ccparams.rach_preambleInitialReceivedTargetPower,  defintval:-100,            TYPE_INT,        0},  \
+{ENB_CONFIG_STRING_RACH_PREAMBLETRANSMAX,                        NULL,   0,           iptr:&ccparams.rach_preambleTransMax,                    defintval:10,              TYPE_INT,        0},  \
+{ENB_CONFIG_STRING_RACH_RARESPONSEWINDOWSIZE,                    NULL,   0,           iptr:&ccparams.rach_raResponseWindowSize,                defintval:10,              TYPE_INT,        0},  \
+{ENB_CONFIG_STRING_RACH_MACCONTENTIONRESOLUTIONTIMER,            NULL,   0,           iptr:&ccparams.rach_macContentionResolutionTimer,        defintval:48,              TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_RACH_MAXHARQMSG3TX,                           NULL,   0,           iptr:&ccparams.rach_maxHARQ_Msg3Tx,                      defintval:4,               TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_PCCH_DEFAULT_PAGING_CYCLE,                    NULL,   0,           iptr:&ccparams.pcch_defaultPagingCycle,                  defintval:128,             TYPE_INT,        0},  \
+{ENB_CONFIG_STRING_PCCH_NB,                                      NULL,   0,           strptr:&ccparams.pcch_nB,                                defstrval:"oneT",          TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_BCCH_MODIFICATIONPERIODCOEFF,                 NULL,   0,           iptr:&ccparams.bcch_modificationPeriodCoeff,             defintval:2,               TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_UETIMERS_T300,                                NULL,   0,           iptr:&ccparams.ue_TimersAndConstants_t300,               defintval:1000,            TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_UETIMERS_T301,                                NULL,   0,           iptr:&ccparams.ue_TimersAndConstants_t301,               defintval:1000,            TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_UETIMERS_T310,                                NULL,   0,           iptr:&ccparams.ue_TimersAndConstants_t310,               defintval:1000,            TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_UETIMERS_T311,                                NULL,   0,           iptr:&ccparams.ue_TimersAndConstants_t311,               defintval:10000,           TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_UETIMERS_N310,                                NULL,   0,           iptr:&ccparams.ue_TimersAndConstants_n310,               defintval:20,              TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_UETIMERS_N311,                                NULL,   0,           iptr:&ccparams.ue_TimersAndConstants_n311,               defintval:1,               TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_UE_TRANSMISSION_MODE,                         NULL,   0,           iptr:&ccparams.ue_TransmissionMode,                      defintval:1,               TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_UE_MULTIPLE_MAX,                              NULL,   0,           iptr:&ccparams.ue_multiple_max,                          defintval:4,               TYPE_UINT,       0}  \
 }
 
+
+
 #define ENB_CONFIG_FRAME_TYPE_IDX                            0  			     
 #define ENB_CONFIG_TDD_CONFIG_IDX                            1  			     
 #define ENB_CONFIG_TDD_CONFIG_S_IDX			     2
@@ -693,7 +764,6 @@ typedef enum {
 #define ENB_CONFIG_UETIMERS_N311_IDX			     66
 #define ENB_CONFIG_UE_TRANSMISSION_MODE_IDX		     67
 
-/*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
 /*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
 /* SRB1 configuration parameters section name */
 #define ENB_CONFIG_STRING_SRB1                                          "srb1_parameters"
@@ -710,21 +780,27 @@ typedef enum {
 /*                                            SRB1 configuration parameters                                                                                  */
 /*   optname                                          helpstr   paramflags    XXXptr                             defXXXval         type           numelt     */
 /*-----------------------------------------------------------------------------------------------------------------------------------------------------------*/
-#define SRB1PARAMS_DESC {                                                                                                \
-{ENB_CONFIG_STRING_SRB1_TIMER_POLL_RETRANSMIT,         NULL,   0,            iptr:&srb1_timer_poll_retransmit,   defintval:80,     TYPE_UINT,      0},       \
-{ENB_CONFIG_STRING_SRB1_TIMER_REORDERING,              NULL,   0,            iptr:&srb1_timer_reordering,        defintval:35,     TYPE_UINT,      0},       \
-{ENB_CONFIG_STRING_SRB1_TIMER_STATUS_PROHIBIT,         NULL,   0,            iptr:&srb1_timer_status_prohibit,   defintval:0,      TYPE_UINT,      0},       \
-{ENB_CONFIG_STRING_SRB1_POLL_PDU,                      NULL,   0,            iptr:&srb1_poll_pdu,                defintval:4,      TYPE_UINT,      0},       \
-{ENB_CONFIG_STRING_SRB1_POLL_BYTE,                     NULL,   0,            iptr:&srb1_poll_byte,               defintval:99999,  TYPE_UINT,      0},       \
-{ENB_CONFIG_STRING_SRB1_MAX_RETX_THRESHOLD,            NULL,   0,            iptr:&srb1_max_retx_threshold,      defintval:4,      TYPE_UINT,      0}        \
+typedef struct srb1_params_s {
+  int32_t     srb1_timer_poll_retransmit;
+  int32_t     srb1_timer_reordering;
+  int32_t     srb1_timer_status_prohibit;
+  int32_t     srb1_poll_pdu;
+  int32_t     srb1_poll_byte;
+  int32_t     srb1_max_retx_threshold;
+} srb1_params_t;
+
+#define SRB1PARAMS_DESC(srb1_params) {					\
+{ENB_CONFIG_STRING_SRB1_TIMER_POLL_RETRANSMIT,         NULL,   0,            iptr:&srb1_params.srb1_timer_poll_retransmit,   defintval:80,     TYPE_UINT,      0},       \
+{ENB_CONFIG_STRING_SRB1_TIMER_REORDERING,              NULL,   0,            iptr:&srb1_params.srb1_timer_reordering,        defintval:35,     TYPE_UINT,      0},       \
+{ENB_CONFIG_STRING_SRB1_TIMER_STATUS_PROHIBIT,         NULL,   0,            iptr:&srb1_params.srb1_timer_status_prohibit,   defintval:0,      TYPE_UINT,      0},       \
+{ENB_CONFIG_STRING_SRB1_POLL_PDU,                      NULL,   0,            iptr:&srb1_params.srb1_poll_pdu,                defintval:4,      TYPE_UINT,      0},       \
+{ENB_CONFIG_STRING_SRB1_POLL_BYTE,                     NULL,   0,            iptr:&srb1_params.srb1_poll_byte,               defintval:99999,  TYPE_UINT,      0},       \
+{ENB_CONFIG_STRING_SRB1_MAX_RETX_THRESHOLD,            NULL,   0,            iptr:&srb1_params.srb1_max_retx_threshold,      defintval:4,      TYPE_UINT,      0}        \
 }
-/*-----------------------------------------------------------------------------------------------------------------------------------------------------------*/
 
 /* MME configuration parameters section name */
 #define ENB_CONFIG_STRING_MME_IP_ADDRESS                "mme_ip_address"
 
-/* SRB1 configuration parameters names   */
-
 
 #define ENB_CONFIG_STRING_MME_IPV4_ADDRESS              "ipv4"
 #define ENB_CONFIG_STRING_MME_IPV6_ADDRESS              "ipv6"
@@ -1008,3 +1084,7 @@ typedef enum {
 #define CONFIG_HLP_WORKER                          "coding and FEP worker thread WORKER_DISABLE or WORKER_ENABLE\n"
 #define CONFIG_HLP_PARALLEL                        "PARALLEL_SINGLE_THREAD, PARALLEL_RU_L1_SPLIT, or PARALLEL_RU_L1_TRX_SPLIT(RU_L1_TRX_SPLIT by defult)\n"
 /*-------------------------------------------------------------------------------------------------------------------------------------------------------------*/
+
+#include "enb_paramdef_emtc.h"
+#include "enb_paramdef_sidelink.h"
+#endif
diff --git a/openair2/ENB_APP/enb_paramdef_emtc.h b/openair2/ENB_APP/enb_paramdef_emtc.h
new file mode 100644
index 0000000000000000000000000000000000000000..058e4275667cc8ba77beef81e68a3c40e4d89da7
--- /dev/null
+++ b/openair2/ENB_APP/enb_paramdef_emtc.h
@@ -0,0 +1,398 @@
+/*
+ * 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
+ */
+
+/*! \file openair2/ENB_APP/enb_paramdef_emtc.h
+ * \brief definition of configuration parameters for emtc eNodeB modules
+ * \author Raymond KNOPP
+ * \date 2018
+ * \version 0.1
+ * \company EURECOM France
+ * \email: raymond.knopp@eurecom.fr
+ * \note
+ * \warning
+ */
+
+#include "common/config/config_paramdesc.h"
+#include "RRC_paramsvalues.h"
+
+#define ENB_CONFIG_STRING_EMTC_PARAMETERS                                  "emtc_parameters"
+#define ENB_CONFIG_STRING_SCHEDULING_INFO_BR                               "scheduling_info_br"
+#define ENB_CONFIG_STRING_RSRP_RANGE_LIST                                  "rsrp_range_list"
+#define ENB_CONFIG_STRING_PRACH_CONFIG_COMMON_V1310                        "prach_ConfigCommon_v1310"
+#define ENB_CONFIG_STRING_MPDCCH_START_SF_CSS_RA_R13                       "mpdcch_startSF_CSS_RA_r13"
+#define ENB_CONFIG_STRING_MPDCCH_START_SF_CSS_RA_R13_VAL                   "mpdcch_startSF_CSS_RA_r13_val"
+#define ENB_CONFIG_STRING_PRACH_HOPPING_OFFSET_R13                         "prach_HoppingOffset_r13"
+#define ENB_CONFIG_STRING_SCHEDULING_INFO_SIB1_BR_R13                      "schedulingInfoSIB1_BR_r13"
+#define ENB_CONFIG_STRING_CELL_SELECTION_INFO_CE_R13                       "cellSelectionInfoCE_r13"
+#define ENB_CONFIG_STRING_Q_RX_LEV_MIN_CE_R13                              "q_RxLevMinCE_r13"
+#define ENB_CONFIG_STRING_BANDWIDTH_REDUCED_ACCESS_RELATED_INFO_R13        "bandwidthReducedAccessRelatedInfo_r13"
+#define ENB_CONFIG_STRING_SI_WINDOW_LENGTH_BR_R13                          "si_WindowLength_BR_r13"
+#define ENB_CONFIG_STRING_SI_REPETITION_PATTERN_R13                        "si_RepetitionPattern_r13"
+#define ENB_CONFIG_STRING_FDD_DOWNLINK_OR_TDD_SUBFRAME_BITMAP_BR_R13       "fdd_DownlinkOrTddSubframeBitmapBR_r13"
+#define ENB_CONFIG_STRING_FDD_DOWNLINK_OR_TDD_SUBFRAME_BITMAP_BR_VAL_R13   "fdd_DownlinkOrTddSubframeBitmapBR_val_r13"
+#define ENB_CONFIG_STRING_START_SYMBOL_BR_R13                              "startSymbolBR_r13"
+#define ENB_CONFIG_STRING_SI_HOPPING_CONFIG_COMMON_R13                     "si_HoppingConfigCommon_r13"
+#define ENB_CONFIG_STRING_SI_VALIDITY_TIME_R13                             "si_ValidityTime_r13"
+#define ENB_CONFIG_STRING_FREQ_HOPPING_PARAMETERS_DL_R13                   "freqHoppingParametersDL_r13"
+#define ENB_CONFIG_STRING_MPDCCH_PDSCH_HOPPING_NB_R13                      "mpdcch_pdsch_HoppingNB_r13"
+#define ENB_CONFIG_STRING_INTERVAL_DL_HOPPING_CONFIG_COMMON_MODE_A_R13     "interval_DLHoppingConfigCommonModeA_r13"
+#define ENB_CONFIG_STRING_INTERVAL_DL_HOPPING_CONFIG_COMMON_MODE_A_R13_VAL "interval_DLHoppingConfigCommonModeA_r13_val"
+#define ENB_CONFIG_STRING_INTERVAL_DL_HOPPING_CONFIG_COMMON_MODE_B_R13     "interval_DLHoppingConfigCommonModeB_r13"
+#define ENB_CONFIG_STRING_INTERVAL_DL_HOPPING_CONFIG_COMMON_MODE_B_R13_VAL "interval_DLHoppingConfigCommonModeB_r13_val"
+#define ENB_CONFIG_STRING_MPDCCH_PDSCH_HOPPING_OFFSET_R13                  "mpdcch_pdsch_HoppingOffset_r13"
+#define ENB_CONFIG_STRING_PREAMBLE_TRANSMAX_CE_R13                         "preamble_TransMax_ce_r13"
+#define ENB_CONFIG_STRING_PREAMBLE_TRANSMAX_CE_R13_VAL                     "preamble_TransMax_ce_r13_val"
+#define ENB_CONFIG_STRING_PDSCH_MAX_NUM_REPETITION_CE_MODE_A_R13           "pdsch_maxNumRepetitionCEmodeA_r13"
+#define ENB_CONFIG_STRING_PUSCH_MAX_NUM_REPETITION_CE_MODE_A_R13           "pusch_maxNumRepetitionCEmodeA_r13"
+#define ENB_CONFIG_STRING_SYSTEM_INFO_VALUE_TAG_LIST                       "system_info_value_tag_SI"
+#define ENB_CONFIG_STRING_FIRST_PREAMBLE_R13                               "firstPreamble_r13"
+#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_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"
+#define ENB_CONFIG_STRING_PRACH_STARTING_SUBFRAME_R13                      "prach_StartingSubframe_r13"
+#define ENB_CONFIG_STRING_MAX_NUM_PER_PREAMBLE_ATTEMPT_CE_R13              "maxNumPreambleAttemptCE_r13"
+#define ENB_CONFIG_STRING_NUM_REPETITION_PER_PREAMBLE_ATTEMPT_R13          "numRepetitionPerPreambleAttempt_r13"
+#define ENB_CONFIG_STRING_MPDCCH_NUM_REPETITION_RA_R13                     "mpdcch_NumRepetition_RA_r13"
+#define ENB_CONFIG_STRING_PRACH_HOPPING_CONFIG_R13                         "prach_HoppingConfig_r13"
+#define ENB_CONFIG_SRING_MAX_AVAILABLE_NARROW_BAND                         "max_available_narrow_band"
+#define ENB_CONFIG_STRING_PRACH_PARAMETERS_CE_R13                          "prach_parameters_ce_r13"
+#define ENB_CONFIG_STRING_PUCCH_INFO_VALUE                                 "pucch_info_value"
+#define ENB_CONFIG_STRING_N1PUCCH_AN_INFOLIST_R13                          "n1PUCCH_AN_InfoList_r13"
+#define ENB_CONFIG_STRING_PCCH_CONFIG_V1310                                "pcch_config_v1310"
+#define ENB_CONFIG_STRING_SIB2_FREQ_HOPPINGPARAMETERS_R13                  "sib2_freq_hoppingParameters_r13"
+
+typedef struct ccparams_eMTC_s {
+  /// indicator that eMTC is configured for this cell
+  int32_t        eMTC_configured;
+  /// the SIB2 parameters for eMTC SIB2
+  ccparams_lte_t ccparams;
+  int            si_Narrowband_r13;
+  int            si_TBS_r13;
+  int            systemInfoValueTagSi_r13;
+  int            firstPreamble_r13;
+  int            lastPreamble_r13;
+  int            ra_ResponseWindowSize_r13;
+  int            mac_ContentionResolutionTimer_r13;
+  int            rar_HoppingConfig_r13;
+  int            rsrp_range_br;
+  int            prach_config_index_br;
+  int            prach_freq_offset_br;
+  int            prach_StartingSubframe_r13;
+  int            maxNumPreambleAttemptCE_r13;
+  int            numRepetitionPerPreambleAttempt_r13;
+  int            mpdcch_NumRepetition_RA_r13;
+  int            prach_HoppingConfig_r13;
+  int           *maxavailablenarrowband;
+  int            pucch_info_value;
+  int            paging_narrowbands_r13;
+  int            mpdcch_numrepetition_paging_r13;
+  int            nb_v1310;
+  char          *pucch_NumRepetitionCE_Msg4_Level0_r13;
+  char          *pucch_NumRepetitionCE_Msg4_Level1_r13;
+  char          *pucch_NumRepetitionCE_Msg4_Level2_r13;
+  char          *pucch_NumRepetitionCE_Msg4_Level3_r13;
+  int            sib2_mpdcch_pdsch_hoppingNB_r13;
+  char          *sib2_interval_DLHoppingConfigCommonModeA_r13;
+  int            sib2_interval_DLHoppingConfigCommonModeA_r13_val;
+  char          *sib2_interval_DLHoppingConfigCommonModeB_r13;
+  int            sib2_interval_DLHoppingConfigCommonModeB_r13_val;
+  char          *sib2_interval_ULHoppingConfigCommonModeA_r13;
+  int            sib2_interval_ULHoppingConfigCommonModeA_r13_val;
+  char          *sib2_interval_ULHoppingConfigCommonModeB_r13;
+  int            sib2_interval_ULHoppingConfigCommonModeB_r13_val;
+  int            sib2_mpdcch_pdsch_hoppingOffset_r13;
+  int            pusch_HoppingOffset_v1310;
+  int            hyperSFN_r13;
+  int            eDRX_Allowed_r13;
+  int            q_RxLevMinCE_r13;
+  int            q_QualMinRSRQ_CE_r13;
+  char          *si_WindowLength_BR_r13;
+  char          *si_RepetitionPattern_r13;
+  int            startSymbolBR_r13;
+  char          *si_HoppingConfigCommon_r13;
+  char          *si_ValidityTime_r13;
+  char          *mpdcch_pdsch_HoppingNB_r13;
+  int            interval_DLHoppingConfigCommonModeA_r13_val;
+  int            interval_DLHoppingConfigCommonModeB_r13_val;
+  int            mpdcch_pdsch_HoppingOffset_r13;
+  char          *preambleTransMax_CE_r13;
+  int            prach_HoppingOffset_r13;
+  int            schedulingInfoSIB1_BR_r13;
+  int64_t        fdd_DownlinkOrTddSubframeBitmapBR_val_r13;
+  char          *cellSelectionInfoCE_r13;
+  char          *bandwidthReducedAccessRelatedInfo_r13;
+  char          *fdd_DownlinkOrTddSubframeBitmapBR_r13;
+  char          *fdd_UplinkSubframeBitmapBR_r13;
+  char          *freqHoppingParametersDL_r13;
+  char          *interval_DLHoppingConfigCommonModeA_r13;
+  char          *interval_DLHoppingConfigCommonModeB_r13;
+  char          *prach_ConfigCommon_v1310;
+  char          *mpdcch_startSF_CSS_RA_r13;
+  char          *mpdcch_startSF_CSS_RA_r13_val;
+  char          *pdsch_maxNumRepetitionCEmodeA_r13;
+  char          *pdsch_maxNumRepetitionCEmodeB_r13;
+  char          *pusch_maxNumRepetitionCEmodeA_r13;
+  char          *pusch_maxNumRepetitionCEmodeB_r13;
+} ccparams_eMTC_t;
+
+
+#define EMTCPARAMS_DESC(eMTCconfig) {					\
+  {"eMTC_configured",                                              NULL,   0,           iptr:&eMTCconfig->eMTC_configured,                             defintval:0,                       TYPE_UINT,         0}, \
+{ENB_CONFIG_STRING_PRACH_ROOT,                                           NULL,   0,           iptr:&eMTCconfig->ccparams.prach_root,                                  defintval:0,                       TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_PRACH_CONFIG_INDEX,                                   NULL,   0,           iptr:&eMTCconfig->ccparams.prach_config_index,                          defintval:0,                       TYPE_INT,        0},  \
+{ENB_CONFIG_STRING_PRACH_HIGH_SPEED,                                     NULL,   0,           strptr:&eMTCconfig->ccparams.prach_high_speed,                          defstrval:"DISABLE",               TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_PRACH_ZERO_CORRELATION,                               NULL,   0,           iptr:&eMTCconfig->ccparams.prach_zero_correlation,                      defintval:1,                       TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_PRACH_FREQ_OFFSET,                                    NULL,   0,           iptr:&eMTCconfig->ccparams.prach_freq_offset,                           defintval:2,                       TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_PUCCH_DELTA_SHIFT,                                    NULL,   0,           iptr:&eMTCconfig->ccparams.pucch_delta_shift,                           defintval:1,                       TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_PUCCH_NRB_CQI,                                        NULL,   0,           iptr:&eMTCconfig->ccparams.pucch_nRB_CQI,                               defintval:1,                       TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_PUCCH_NCS_AN,                                         NULL,   0,           iptr:&eMTCconfig->ccparams.pucch_nCS_AN,                                defintval:0,                       TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_PUCCH_N1_AN,                                          NULL,   0,           iptr:&eMTCconfig->ccparams.pucch_n1_AN,                                 defintval:32,                      TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_PDSCH_RS_EPRE,                                        NULL,   0,           iptr:&eMTCconfig->ccparams.pdsch_referenceSignalPower,                  defintval:-29,                     TYPE_INT,        0},  \
+{ENB_CONFIG_STRING_PDSCH_PB,                                             NULL,   0,           iptr:&eMTCconfig->ccparams.pdsch_p_b,                                   defintval:0,                       TYPE_INT,        0},  \
+{ENB_CONFIG_STRING_PUSCH_N_SB,                                           NULL,   0,           iptr:&eMTCconfig->ccparams.pusch_n_SB,                                  defintval:1,                       TYPE_INT,        0},  \
+{ENB_CONFIG_STRING_PUSCH_HOPPINGMODE,                                    NULL,   0,           strptr:&eMTCconfig->ccparams.pusch_hoppingMode,                         defstrval:"interSubFrame",         TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_PUSCH_HOPPINGOFFSET,                                  NULL,   0,           iptr:&eMTCconfig->ccparams.pusch_hoppingOffset,                         defintval:0,                       TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_PUSCH_ENABLE64QAM,                                    NULL,   0,           strptr:&eMTCconfig->ccparams.pusch_enable64QAM,                         defstrval:"DISABLE",               TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_PUSCH_GROUP_HOPPING_EN,                               NULL,   0,           strptr:&eMTCconfig->ccparams.pusch_groupHoppingEnabled,                 defstrval:"ENABLE",                TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_PUSCH_GROUP_ASSIGNMENT,                               NULL,   0,           iptr:&eMTCconfig->ccparams.pusch_groupAssignment,                       defintval:0,                       TYPE_INT,        0},  \
+{ENB_CONFIG_STRING_PUSCH_SEQUENCE_HOPPING_EN,                            NULL,   0,           strptr:&eMTCconfig->ccparams.pusch_sequenceHoppingEnabled,              defstrval:"DISABLE",               TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_PUSCH_NDMRS1,                                         NULL,   0,           iptr:&eMTCconfig->ccparams.pusch_nDMRS1,                                defintval:0,                       TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_PHICH_DURATION,                                       NULL,   0,           strptr:&eMTCconfig->ccparams.phich_duration,                            defstrval:"NORMAL",                TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_PHICH_RESOURCE,                                       NULL,   0,           strptr:&eMTCconfig->ccparams.phich_resource,                            defstrval:"ONESIXTH",              TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_SRS_ENABLE,                                           NULL,   0,           strptr:&eMTCconfig->ccparams.srs_enable,                                defstrval:"DISABLE",               TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_SRS_BANDWIDTH_CONFIG,                                 NULL,   0,           iptr:&eMTCconfig->ccparams.srs_BandwidthConfig,                         defintval:0,                       TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_SRS_SUBFRAME_CONFIG,                                  NULL,   0,           iptr:&eMTCconfig->ccparams.srs_SubframeConfig,                          defintval:0,                       TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_SRS_ACKNACKST_CONFIG,                                 NULL,   0,           strptr:&eMTCconfig->ccparams.srs_ackNackST,                             defstrval:"DISABLE",               TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_SRS_MAXUPPTS,                                         NULL,   0,           strptr:&eMTCconfig->ccparams.srs_MaxUpPts,                              defstrval:"DISABLE",               TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_PUSCH_PO_NOMINAL,                                     NULL,   0,           iptr:&eMTCconfig->ccparams.pusch_p0_Nominal,                            defintval:-90,                     TYPE_INT,        0},  \
+{ENB_CONFIG_STRING_PUSCH_ALPHA,                                          NULL,   0,           strptr:&eMTCconfig->ccparams.pusch_alpha,                               defstrval:"AL1",                   TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_PUCCH_PO_NOMINAL,                                     NULL,   0,           iptr:&eMTCconfig->ccparams.pucch_p0_Nominal,                            defintval:-96,                     TYPE_INT,        0},  \
+{ENB_CONFIG_STRING_MSG3_DELTA_PREAMBLE,                                  NULL,   0,           iptr:&eMTCconfig->ccparams.msg3_delta_Preamble,                         defintval:6,                       TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_PUCCH_DELTAF_FORMAT1,                                 NULL,   0,           strptr:&eMTCconfig->ccparams.pucch_deltaF_Format1,                      defstrval:"DELTAF2",               TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_PUCCH_DELTAF_FORMAT1b,                                NULL,   0,           strptr:&eMTCconfig->ccparams.pucch_deltaF_Format1b,                     defstrval:"deltaF3",               TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_PUCCH_DELTAF_FORMAT2,                                 NULL,   0,           strptr:&eMTCconfig->ccparams.pucch_deltaF_Format2,                      defstrval:"deltaF0",               TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_PUCCH_DELTAF_FORMAT2A,                                NULL,   0,           strptr:&eMTCconfig->ccparams.pucch_deltaF_Format2a,                     defstrval:"deltaF0",               TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_PUCCH_DELTAF_FORMAT2B,                                NULL,   0,           strptr:&eMTCconfig->ccparams.pucch_deltaF_Format2b,                     defstrval:"deltaF0",               TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_RACH_NUM_RA_PREAMBLES,                                NULL,   0,           iptr:&eMTCconfig->ccparams.rach_numberOfRA_Preambles,                   defintval:4,                       TYPE_UINT,     0},  \
+{ENB_CONFIG_STRING_RACH_PREAMBLESGROUPACONFIG,                           NULL,   0,           strptr:&eMTCconfig->ccparams.rach_preamblesGroupAConfig,                defstrval:"DISABLE",               TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_RACH_SIZEOFRA_PREAMBLESGROUPA,                        NULL,   0,           iptr:&eMTCconfig->ccparams.rach_sizeOfRA_PreamblesGroupA,               defintval:0,                       TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_RACH_MESSAGESIZEGROUPA,                               NULL,   0,           iptr:&eMTCconfig->ccparams.rach_messageSizeGroupA,                      defintval:56,                      TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_RACH_MESSAGEPOWEROFFSETGROUPB,                        NULL,   0,           strptr:&eMTCconfig->ccparams.rach_messagePowerOffsetGroupB,             defstrval:"minusinfinity",         TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_RACH_POWERRAMPINGSTEP,                                NULL,   0,           iptr:&eMTCconfig->ccparams.rach_powerRampingStep,                       defintval:4,                       TYPE_INT,        0},  \
+{ENB_CONFIG_STRING_RACH_PREAMBLEINITIALRECEIVEDTARGETPOWER,              NULL,   0,           iptr:&eMTCconfig->ccparams.rach_preambleInitialReceivedTargetPower,     defintval:-100,                    TYPE_INT,        0},  \
+{ENB_CONFIG_STRING_RACH_PREAMBLETRANSMAX,                                NULL,   0,           iptr:&eMTCconfig->ccparams.rach_preambleTransMax,                       defintval:10,                      TYPE_INT,        0},  \
+{ENB_CONFIG_STRING_RACH_RARESPONSEWINDOWSIZE,                            NULL,   0,           iptr:&eMTCconfig->ccparams.rach_raResponseWindowSize,                   defintval:10,                      TYPE_INT,        0},  \
+{ENB_CONFIG_STRING_RACH_MACCONTENTIONRESOLUTIONTIMER,                    NULL,   0,           iptr:&eMTCconfig->ccparams.rach_macContentionResolutionTimer,           defintval:48,                      TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_RACH_MAXHARQMSG3TX,                                   NULL,   0,           iptr:&eMTCconfig->ccparams.rach_maxHARQ_Msg3Tx,                         defintval:4,                       TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_PCCH_DEFAULT_PAGING_CYCLE,                            NULL,   0,           iptr:&eMTCconfig->ccparams.pcch_defaultPagingCycle,                     defintval:128,                 TYPE_INT,     0},  \
+{ENB_CONFIG_STRING_PCCH_NB,                                              NULL,   0,           strptr:&eMTCconfig->ccparams.pcch_nB,                                   defstrval:"oneT",                  TYPE_STRING,     0},  \
+{ENB_CONFIG_STRING_BCCH_MODIFICATIONPERIODCOEFF,                         NULL,   0,           iptr:&eMTCconfig->ccparams.bcch_modificationPeriodCoeff,                defintval:2,                       TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_RACH_PREAMBLESGROUPACONFIG,                           NULL,   0,           strptr:&eMTCconfig->ccparams.rach_preamblesGroupAConfig,                defstrval:"",                      TYPE_STRING,     0}, \
+{ENB_CONFIG_STRING_UETIMERS_T300,                                NULL,   0,           iptr:&eMTCconfig->ccparams.ue_TimersAndConstants_t300,               defintval:1000,            TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_UETIMERS_T301,                                NULL,   0,           iptr:&eMTCconfig->ccparams.ue_TimersAndConstants_t301,               defintval:1000,            TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_UETIMERS_T310,                                NULL,   0,           iptr:&eMTCconfig->ccparams.ue_TimersAndConstants_t310,               defintval:1000,            TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_UETIMERS_T311,                                NULL,   0,           iptr:&eMTCconfig->ccparams.ue_TimersAndConstants_t311,               defintval:10000,           TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_UETIMERS_N310,                                NULL,   0,           iptr:&eMTCconfig->ccparams.ue_TimersAndConstants_n310,               defintval:20,              TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_UETIMERS_N311,                                NULL,   0,           iptr:&eMTCconfig->ccparams.ue_TimersAndConstants_n311,               defintval:1,               TYPE_UINT,       0},  \
+{ENB_CONFIG_STRING_UE_TRANSMISSION_MODE,                         NULL,   0,           iptr:&eMTCconfig->ccparams.ue_TransmissionMode,                      defintval:1,               TYPE_UINT,       0},  \
+  {ENB_CONFIG_STRING_SCHEDULING_INFO_SIB1_BR_R13,                  NULL,   0,           iptr:&eMTCconfig->schedulingInfoSIB1_BR_r13,                   defintval:4,                       TYPE_UINT,         0}, \
+  {ENB_CONFIG_STRING_PRACH_CONFIG_COMMON_V1310,                    NULL,   0,           strptr:&eMTCconfig->prach_ConfigCommon_v1310,               defstrval:"ENABLE",        TYPE_STRING,     0}, \
+  {ENB_CONFIG_STRING_MPDCCH_START_SF_CSS_RA_R13,                   NULL,   0,           strptr:&eMTCconfig->mpdcch_startSF_CSS_RA_r13,              defstrval:"fdd-r13",       TYPE_STRING,     0}, \
+  {ENB_CONFIG_STRING_MPDCCH_START_SF_CSS_RA_R13_VAL,               NULL,   0,           strptr:&eMTCconfig->mpdcch_startSF_CSS_RA_r13_val,          defstrval:"v1",            TYPE_STRING,     0}, \
+  {ENB_CONFIG_STRING_PRACH_HOPPING_OFFSET_R13,                     NULL,   0,           iptr:&eMTCconfig->prach_HoppingOffset_r13,                  defintval:0,               TYPE_INT,        0}, \
+  {ENB_CONFIG_STRING_PDSCH_MAX_NUM_REPETITION_CE_MODE_A_R13,       NULL,   0,           strptr:&eMTCconfig->pdsch_maxNumRepetitionCEmodeA_r13,      defstrval:"r16",           TYPE_STRING,     0}, \
+  {ENB_CONFIG_STRING_PUSCH_MAX_NUM_REPETITION_CE_MODE_A_R13,       NULL,   0,           strptr:&eMTCconfig->pusch_maxNumRepetitionCEmodeA_r13,      defstrval:"r8",            TYPE_STRING,     0},	\
+{ENB_CONFIG_STRING_CELL_SELECTION_INFO_CE_R13,                           NULL,   0,           strptr:&eMTCconfig->cellSelectionInfoCE_r13,                   defstrval:"ENABLE",                TYPE_STRING,       0}, \
+{ENB_CONFIG_STRING_Q_RX_LEV_MIN_CE_R13,                                  NULL,   0,           iptr:&eMTCconfig->q_RxLevMinCE_r13,                            defintval:-70,                     TYPE_INT,          0}, \
+{ENB_CONFIG_STRING_BANDWIDTH_REDUCED_ACCESS_RELATED_INFO_R13,            NULL,   0,           strptr:&eMTCconfig->bandwidthReducedAccessRelatedInfo_r13,     defstrval:"ENABLE",                TYPE_STRING,       0}, \
+{ENB_CONFIG_STRING_SI_WINDOW_LENGTH_BR_R13,                              NULL,   0,           strptr:&eMTCconfig->si_WindowLength_BR_r13,                    defstrval:"ms20",                  TYPE_STRING,       0}, \
+{ENB_CONFIG_STRING_SI_REPETITION_PATTERN_R13,                            NULL,   0,           strptr:&eMTCconfig->si_RepetitionPattern_r13,                  defstrval:"everyRF",               TYPE_STRING,       0},			\
+{ENB_CONFIG_STRING_FDD_DOWNLINK_OR_TDD_SUBFRAME_BITMAP_BR_R13,           NULL,   0,           strptr:&eMTCconfig->fdd_DownlinkOrTddSubframeBitmapBR_r13,     defstrval:"subframePattern40-r13", TYPE_STRING,       0}, \
+{ENB_CONFIG_STRING_FDD_DOWNLINK_OR_TDD_SUBFRAME_BITMAP_BR_VAL_R13,       NULL,   0,           i64ptr:&eMTCconfig->fdd_DownlinkOrTddSubframeBitmapBR_val_r13, defint64val:0xFFFFFFFFFF,          TYPE_UINT64,       0}, \
+{ENB_CONFIG_STRING_START_SYMBOL_BR_R13,                                  NULL,   0,           iptr:&eMTCconfig->startSymbolBR_r13,                           defintval:3,                       TYPE_UINT,         0}, \
+{ENB_CONFIG_STRING_SI_HOPPING_CONFIG_COMMON_R13,                         NULL,   0,           strptr:&eMTCconfig->si_HoppingConfigCommon_r13 ,               defstrval:"off",                   TYPE_STRING,       0}, \
+{ENB_CONFIG_STRING_SI_VALIDITY_TIME_R13,                                 NULL,   0,           strptr:&eMTCconfig->si_ValidityTime_r13,                       defstrval:"true",                  TYPE_STRING,       0}, \
+{ENB_CONFIG_STRING_FREQ_HOPPING_PARAMETERS_DL_R13,                       NULL,   0,           strptr:&eMTCconfig->freqHoppingParametersDL_r13,               defstrval:"DISABLE",               TYPE_STRING,       0}, \
+{ENB_CONFIG_STRING_MPDCCH_PDSCH_HOPPING_NB_R13,                          NULL,   0,           strptr:&eMTCconfig->mpdcch_pdsch_HoppingNB_r13,                defstrval:"nb2",                   TYPE_STRING,       0}, \
+{ENB_CONFIG_STRING_INTERVAL_DL_HOPPING_CONFIG_COMMON_MODE_A_R13,         NULL,   0,           strptr:&eMTCconfig->interval_DLHoppingConfigCommonModeA_r13,   defstrval:"interval-FDD-r13",      TYPE_STRING,       0}, \
+{ENB_CONFIG_STRING_INTERVAL_DL_HOPPING_CONFIG_COMMON_MODE_A_R13_VAL,     NULL,   0,           iptr:&eMTCconfig->interval_DLHoppingConfigCommonModeA_r13_val, defintval:0,                       TYPE_UINT,         0}, \
+{ENB_CONFIG_STRING_INTERVAL_DL_HOPPING_CONFIG_COMMON_MODE_B_R13,         NULL,   0,           strptr:&eMTCconfig->interval_DLHoppingConfigCommonModeB_r13,   defstrval:"interval-FDD-r13",      TYPE_STRING,       0}, \
+{ENB_CONFIG_STRING_INTERVAL_DL_HOPPING_CONFIG_COMMON_MODE_B_R13_VAL,     NULL,   0,           iptr:&eMTCconfig->interval_DLHoppingConfigCommonModeB_r13_val, defintval:0,                       TYPE_UINT,         0}, \
+{ENB_CONFIG_STRING_MPDCCH_PDSCH_HOPPING_OFFSET_R13,                      NULL,   0,           iptr:&eMTCconfig->mpdcch_pdsch_HoppingOffset_r13,              defintval:1,                       TYPE_UINT,         0}, \
+{ENB_CONFIG_STRING_PREAMBLE_TRANSMAX_CE_R13,                             NULL,   0,           strptr:&eMTCconfig->preambleTransMax_CE_r13,                   defstrval:"n10",                   TYPE_STRING,       0},  \
+{ENB_CONFIG_STRING_PUCCH_NUM_REPETITION_CE_MSG4_LEVEL0,                  NULL,   0,           strptr:&eMTCconfig->pucch_NumRepetitionCE_Msg4_Level0_r13,     defstrval:"n1",                    TYPE_STRING,     0}, \
+{ENB_CONFIG_STRING_PUCCH_NUM_REPETITION_CE_MSG4_LEVEL1,                  NULL,   0,           strptr:&eMTCconfig->pucch_NumRepetitionCE_Msg4_Level1_r13,     defstrval:"",                      TYPE_STRING,     0}, \
+{ENB_CONFIG_STRING_PUCCH_NUM_REPETITION_CE_MSG4_LEVEL2,                  NULL,   0,           strptr:&eMTCconfig->pucch_NumRepetitionCE_Msg4_Level2_r13,     defstrval:"",                      TYPE_STRING,     0}, \
+  {ENB_CONFIG_STRING_PUCCH_NUM_REPETITION_CE_MSG4_LEVEL3,                  NULL,   0,           strptr:&eMTCconfig->pucch_NumRepetitionCE_Msg4_Level3_r13,     defstrval:"",                      TYPE_STRING,     0} \
+ }
+
+#define EMTCPARAMS_CHECK                 {                                     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+             { .s1a= { config_check_modify_integer, UETIMER_T300_OKVALUES, UETIMER_T300_MODVALUES,8}} ,						     \
+             { .s1a= { config_check_modify_integer, UETIMER_T301_OKVALUES, UETIMER_T301_MODVALUES,8}} ,						     \
+             { .s1a= { config_check_modify_integer, UETIMER_T310_OKVALUES, UETIMER_T310_MODVALUES,7}} ,						     \
+             { .s1a= { config_check_modify_integer, UETIMER_T311_OKVALUES, UETIMER_T311_MODVALUES,7}} ,						     \
+             { .s1a= { config_check_modify_integer, UETIMER_N310_OKVALUES, UETIMER_N310_MODVALUES,8}} , 					      \
+             { .s1a= { config_check_modify_integer, UETIMER_N311_OKVALUES, UETIMER_N311_MODVALUES,8}} , 					      \
+             { .s5= {NULL }} ,						     \
+             { .s5= {NULL }} ,						     \
+                          { .s5= {NULL }} ,						     \
+                          { .s5= {NULL }} ,						     \
+                          { .s5= {NULL }} ,						     \
+                          { .s5= {NULL }} ,						     \
+                          { .s5= {NULL }} ,						     \
+                          { .s5= {NULL }} ,						     \
+                          { .s5= {NULL }} ,						     \
+                          { .s5= {NULL }} ,						     \
+                          { .s5= {NULL }} ,						     \
+                          { .s5= {NULL }} ,						     \
+                          { .s5= {NULL }} ,						     \
+                          { .s5= {NULL }} ,						     \
+                          { .s5= {NULL }} ,						     \
+                          { .s5= {NULL }} ,						     \
+                          { .s5= {NULL }} ,						     \
+                          { .s5= {NULL }} ,						     \
+                          { .s5= {NULL }} ,						     \
+                          { .s5= {NULL }} ,						     \
+                          { .s5= {NULL }} ,						     \
+                          { .s5= {NULL }} ,						     \
+                          { .s5= {NULL }} ,						     \
+                          { .s5= {NULL }} ,						     \
+                          { .s5= {NULL }} ,						     \
+                          { .s5= {NULL }} ,						     \
+                          { .s5= {NULL }} ,						     \
+                          { .s5= {NULL }} ,						     \
+                          { .s5= {NULL }} ,						     \
+                          { .s5= {NULL }} ,						     \
+}
+
+#define SYSTEM_INFO_VALUE_TAG_SI_DESC(eMTCconfig) {			\
+{"systemInfoValueTagSi_r13", NULL,   0,           iptr:&eMTCconfig->systemInfoValueTagSi_r13,                              defintval:0,              TYPE_UINT,       0} \
+  }
+
+
+#define SI_INFO_BR_DESC(eMTCconfig) {					\
+{"si_Narrowband_r13", NULL,   0,           iptr:&eMTCconfig->si_Narrowband_r13,             defintval:5,             TYPE_UINT,       0}, \
+{"si_TBS_r13",        NULL,   0,           iptr:&eMTCconfig->si_TBS_r13,                    defintval:5,             TYPE_UINT,       0} \
+}
+
+#define RSRP_RANGE_LIST_DESC(eMTCconfig) {				\
+{"rsrp_range_br", NULL,   0,           iptr:&eMTCconfig->rsrp_range_br,                     defintval:0,     TYPE_UINT,       0} \
+  }
+
+
+#define RACH_CE_LEVELINFOLIST_R13_DESC(eMTCconfig) {			\
+{ENB_CONFIG_STRING_FIRST_PREAMBLE_R13,                     NULL,   0,           iptr:&eMTCconfig->firstPreamble_r13,                 defintval:60,            TYPE_UINT,       0}, \
+{ENB_CONFIG_STRING_LAST_PREAMBLE_R13,                      NULL,   0,           iptr:&eMTCconfig->lastPreamble_r13,                  defintval:63,            TYPE_UINT,       0}, \
+{ENB_CONFIG_STRING_RA_RESPONSE_WINDOW_SIZE_R13,            NULL,   0,           iptr:&eMTCconfig->ra_ResponseWindowSize_r13,         defintval:20,        TYPE_UINT,     0}, \
+{ENB_CONFIG_STRING_MAC_CONTENTION_RESOLUTION_TIMER_R13,    NULL,   0,           iptr:&eMTCconfig->mac_ContentionResolutionTimer_r13, defintval:80,        TYPE_UINT,     0}, \
+{ENB_CONFIG_STRING_RAR_HOPPING_CONFIG_R13,                 NULL,   0,           iptr:&eMTCconfig->rar_HoppingConfig_r13,             defintval:0,         TYPE_UINT,     0}\
+}
+
+#define PRACH_PARAMS_CE_R13_DESC(eMTCconfig) {				\
+{ENB_CONFIG_STRING_PRACH_CONFIG_INDEX_BR,                   NULL,   0,           iptr:&eMTCconfig->prach_config_index_br,                 defintval:3,             TYPE_UINT,       0}, \
+{ENB_CONFIG_STRING_PRACH_FREQ_OFFSET_BR,                    NULL,   0,           iptr:&eMTCconfig->prach_freq_offset_br,                  defintval:1,             TYPE_UINT,       0}, \
+{ENB_CONFIG_STRING_PRACH_STARTING_SUBFRAME_R13,             NULL,   0,           iptr:&eMTCconfig->prach_StartingSubframe_r13,            defintval:0,             TYPE_UINT,       0}, \
+{ENB_CONFIG_STRING_MAX_NUM_PER_PREAMBLE_ATTEMPT_CE_R13,     NULL,   0,           iptr:&eMTCconfig->maxNumPreambleAttemptCE_r13,         defintval:10,         TYPE_UINT,     0}, \
+{ENB_CONFIG_STRING_NUM_REPETITION_PER_PREAMBLE_ATTEMPT_R13, NULL,   0,           iptr:&eMTCconfig->numRepetitionPerPreambleAttempt_r13, defintval:1,          TYPE_UINT,     0}, \
+{ENB_CONFIG_STRING_MPDCCH_NUM_REPETITION_RA_R13,            NULL,   0,           iptr:&eMTCconfig->mpdcch_NumRepetition_RA_r13,         defintval:1,          TYPE_UINT,     0}, \
+{ENB_CONFIG_STRING_PRACH_HOPPING_CONFIG_R13,                NULL,   0,           iptr:&eMTCconfig->prach_HoppingConfig_r13,             defintval:0,         TYPE_UINT,     0}, \
+{ENB_CONFIG_SRING_MAX_AVAILABLE_NARROW_BAND,                NULL,   0,           uptr:NULL,                                  defintarrayval:NULL,     TYPE_INTARRAY,   0} \
+}
+
+#define N1PUCCH_AN_INFOLIST_R13_DESC(eMTCconfig) {			\
+{ENB_CONFIG_STRING_PUCCH_INFO_VALUE,                     NULL,   0,           iptr:&eMTCconfig->pucch_info_value,                    defintval:0,             TYPE_UINT,       0} \
+}
+
+
+#define PCCH_CONFIG_V1310_DESC(eMTCconfig) {				\
+{ENB_CONFIG_STRING_PAGING_NARROWBANDS_R13,          NULL,   0,           iptr:&eMTCconfig->paging_narrowbands_r13,                   defintval:1,             TYPE_UINT,       0}, \
+{ENB_CONFIG_STRING_MPDCCH_NUMREPETITION_PAGING_R13, NULL,   0,           iptr:&eMTCconfig->mpdcch_numrepetition_paging_r13,          defintval:1,          TYPE_UINT,     0}, \
+{ENB_CONFIG_STRING_NB_V1310,                        NULL,   0,           iptr:&eMTCconfig->nb_v1310,                                 defintval:256,   TYPE_UINT,     0} \
+}
+
+
+#define SIB2_FREQ_HOPPING_R13_DESC(eMTCconfig) {			\
+{ENB_CONFIG_STRING_MPDCCH_PDSCH_HOPPING_NB_R13,                      NULL,   0,           iptr:&eMTCconfig->sib2_mpdcch_pdsch_hoppingNB_r13,                  defintval:0,            TYPE_UINT,       0}, \
+{"sib2_interval_DLHoppingConfigCommonModeA_r13",                     NULL,   0,           strptr:&eMTCconfig->sib2_interval_DLHoppingConfigCommonModeA_r13,       defstrval:"FDD",            TYPE_STRING,       0}, \
+{"sib2_interval_DLHoppingConfigCommonModeA_r13_val",                 NULL,   0,           iptr:&eMTCconfig->sib2_interval_DLHoppingConfigCommonModeA_r13_val,   defintval:0,            TYPE_UINT,       0}, \
+{"sib2_interval_DLHoppingConfigCommonModeB_r13",                     NULL,   0,           strptr:&eMTCconfig->sib2_interval_DLHoppingConfigCommonModeB_r13,       defstrval:"FDD",            TYPE_STRING,       0}, \
+{"sib2_interval_DLHoppingConfigCommonModeB_r13_val",                 NULL,   0,           iptr:&eMTCconfig->sib2_interval_DLHoppingConfigCommonModeB_r13_val,   defintval:0,            TYPE_UINT,       0}, \
+{"sib2_interval_ULHoppingConfigCommonModeA_r13",     NULL,   0,           strptr:&eMTCconfig->sib2_interval_ULHoppingConfigCommonModeA_r13,     defstrval:"FDD",         TYPE_STRING,       0}, \
+{"sib2_interval_ULHoppingConfigCommonModeA_r13_val", NULL,   0,           iptr:&eMTCconfig->sib2_interval_ULHoppingConfigCommonModeA_r13_val, defintval:4,        TYPE_UINT,       0}, \
+{"sib2_interval_ULHoppingConfigCommonModeB_r13",                     NULL,   0,           strptr:&eMTCconfig->sib2_interval_ULHoppingConfigCommonModeB_r13,       defstrval:"FDD",            TYPE_STRING,       0}, \
+{"sib2_interval_ULHoppingConfigCommonModeB_r13_val",                 NULL,   0,           iptr:&eMTCconfig->sib2_interval_ULHoppingConfigCommonModeB_r13_val,   defintval:0,            TYPE_UINT,       0}, \
+{"sib2_mpdcch_pdsch_hoppingOffset_r13",                              NULL,   0,           iptr:&eMTCconfig->sib2_mpdcch_pdsch_hoppingOffset_r13,                defintval:1,             TYPE_UINT,         0} \
+}
diff --git a/openair2/ENB_APP/enb_paramdef_sidelink.h b/openair2/ENB_APP/enb_paramdef_sidelink.h
new file mode 100644
index 0000000000000000000000000000000000000000..dd3aa5f0fbb75d32131bec58d0c8fd187ffc9c63
--- /dev/null
+++ b/openair2/ENB_APP/enb_paramdef_sidelink.h
@@ -0,0 +1,182 @@
+/*
+ * 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
+ */
+
+/*! \file openair2/ENB_APP/enb_paramdef_sidelink.h
+ * \brief definition of configuration parameters for sidelink eNodeB modules
+ * \author Raymond KNOPP
+ * \date 2018
+ * \version 0.1
+ * \company EURECOM France
+ * \email: raymond.knopp@eurecom.fr
+ * \note
+ * \warning
+ */
+
+#ifndef ENB_PARAMDEF_SIDELINK_H_
+#define ENB_PARAMDEF_SIDELINK_H_
+#include "common/config/config_paramdesc.h"
+#include "RRC_paramsvalues.h"
+#include <libconfig.h>
+
+#define ENB_CONFIG_STRING_SL_PARAMETERS                                 "SLparameters"
+//SIB18
+#define ENB_CONFIG_STRING_RXPOOL_SC_CP_LEN                              "rxPool_sc_CP_Len"
+#define ENB_CONFIG_STRING_RXPOOL_SC_PRIOD                               "rxPool_sc_Period"
+#define ENB_CONFIG_STRING_RXPOOL_DATA_CP_LEN                            "rxPool_data_CP_Len"
+#define ENB_CONFIG_STRING_RXPOOL_RC_PRB_NUM                             "rxPool_ResourceConfig_prb_Num"
+#define ENB_CONFIG_STRING_RXPOOL_RC_PRB_START                           "rxPool_ResourceConfig_prb_Start"
+#define ENB_CONFIG_STRING_RXPOOL_RC_PRB_END                             "rxPool_ResourceConfig_prb_End"
+#define ENB_CONFIG_STRING_RXPOOL_RC_OFFSETIND_PRESENT                   "rxPool_ResourceConfig_offsetIndicator_present"
+#define ENB_CONFIG_STRING_RXPOOL_RC_OFFSETIND_CHOICE                    "rxPool_ResourceConfig_offsetIndicator_choice"
+#define ENB_CONFIG_STRING_RXPOOL_RC_SFBITMAP_PRESENT                    "rxPool_ResourceConfig_subframeBitmap_present"
+#define ENB_CONFIG_STRING_RXPOOL_RC_SFBITMAP_CHOICE_BS_BUF              "rxPool_ResourceConfig_subframeBitmap_choice_bs_buf"
+#define ENB_CONFIG_STRING_RXPOOL_RC_SFBITMAP_CHOICE_BS_SIZE             "rxPool_ResourceConfig_subframeBitmap_choice_bs_size"
+#define ENB_CONFIG_STRING_RXPOOL_RC_SFBITMAP_CHOICE_BS_ASN_BITS_UNUSED  "rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused"
+//SIB19 for DiscRxPool
+#define ENB_CONFIG_STRING_DISCRXPOOL_CP_LEN                                 "discRxPool_cp_Len"
+#define ENB_CONFIG_STRING_DISCRXPOOL_DISCPERIOD                             "discRxPool_discPeriod"
+#define ENB_CONFIG_STRING_DISCRXPOOL_NUMRETX                                "discRxPool_numRetx"
+#define ENB_CONFIG_STRING_DISCRXPOOL_NUMREPETITION                          "discRxPool_numRepetition"
+#define ENB_CONFIG_STRING_DISCRXPOOL_RC_PRB_NUM                             "discRxPool_ResourceConfig_prb_Num"
+#define ENB_CONFIG_STRING_DISCRXPOOL_RC_PRB_START                           "discRxPool_ResourceConfig_prb_Start"
+#define ENB_CONFIG_STRING_DISCRXPOOL_RC_PRB_END                             "discRxPool_ResourceConfig_prb_End"
+#define ENB_CONFIG_STRING_DISCRXPOOL_RC_OFFSETIND_PRESENT                   "discRxPool_ResourceConfig_offsetIndicator_present"
+#define ENB_CONFIG_STRING_DISCRXPOOL_RC_OFFSETIND_CHOICE                    "discRxPool_ResourceConfig_offsetIndicator_choice"
+#define ENB_CONFIG_STRING_DISCRXPOOL_RC_SFBITMAP_PRESENT                    "discRxPool_ResourceConfig_subframeBitmap_present"
+#define ENB_CONFIG_STRING_DISCRXPOOL_RC_SFBITMAP_CHOICE_BS_BUF              "discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf"
+#define ENB_CONFIG_STRING_DISCRXPOOL_RC_SFBITMAP_CHOICE_BS_SIZE             "discRxPool_ResourceConfig_subframeBitmap_choice_bs_size"
+#define ENB_CONFIG_STRING_DISCRXPOOL_RC_SFBITMAP_CHOICE_BS_ASN_BITS_UNUSED  "discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused"
+
+//SIB19 for DiscRxPoolPS
+#define ENB_CONFIG_STRING_DISCRXPOOLPS_CP_LEN                                 "DISCRXPOOLPS_cp_Len"
+#define ENB_CONFIG_STRING_DISCRXPOOLPS_DISCPERIOD                             "DISCRXPOOLPS_discPeriod"
+#define ENB_CONFIG_STRING_DISCRXPOOLPS_NUMRETX                                "DISCRXPOOLPS_numRetx"
+#define ENB_CONFIG_STRING_DISCRXPOOLPS_NUMREPETITION                          "DISCRXPOOLPS_numRepetition"
+#define ENB_CONFIG_STRING_DISCRXPOOLPS_RC_PRB_NUM                             "DISCRXPOOLPS_ResourceConfig_prb_Num"
+#define ENB_CONFIG_STRING_DISCRXPOOLPS_RC_PRB_START                           "DISCRXPOOLPS_ResourceConfig_prb_Start"
+#define ENB_CONFIG_STRING_DISCRXPOOLPS_RC_PRB_END                             "DISCRXPOOLPS_ResourceConfig_prb_End"
+#define ENB_CONFIG_STRING_DISCRXPOOLPS_RC_OFFSETIND_PRESENT                   "DISCRXPOOLPS_ResourceConfig_offsetIndicator_present"
+#define ENB_CONFIG_STRING_DISCRXPOOLPS_RC_OFFSETIND_CHOICE                    "DISCRXPOOLPS_ResourceConfig_offsetIndicator_choice"
+#define ENB_CONFIG_STRING_DISCRXPOOLPS_RC_SFBITMAP_PRESENT                    "DISCRXPOOLPS_ResourceConfig_subframeBitmap_present"
+#define ENB_CONFIG_STRING_DISCRXPOOLPS_RC_SFBITMAP_CHOICE_BS_BUF              "DISCRXPOOLPS_ResourceConfig_subframeBitmap_choice_bs_buf"
+#define ENB_CONFIG_STRING_DISCRXPOOLPS_RC_SFBITMAP_CHOICE_BS_SIZE             "DISCRXPOOLPS_ResourceConfig_subframeBitmap_choice_bs_size"
+#define ENB_CONFIG_STRING_DISCRXPOOLPS_RC_SFBITMAP_CHOICE_BS_ASN_BITS_UNUSED  "DISCRXPOOLPS_ResourceConfig_subframeBitmap_choice_bs_bits_unused"
+
+
+/*-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
+/*                                     component carriers configuration parameters                                                                                                     */
+/*   optname                                                   helpstr   paramflags    XXXptr                                        defXXXval                    type         numelt  */
+/*-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
+/* init for checkedparam_t structure */
+
+typedef struct ccparams_sidelink_s {
+  int               sidelink_configured;
+  //SIB18
+  char             *rxPool_sc_CP_Len;
+  char             *rxPool_sc_Period;
+  char             *rxPool_data_CP_Len;
+  libconfig_int     rxPool_ResourceConfig_prb_Num;
+  libconfig_int     rxPool_ResourceConfig_prb_Start;
+  libconfig_int     rxPool_ResourceConfig_prb_End;
+  char             *rxPool_ResourceConfig_offsetIndicator_present;
+  libconfig_int     rxPool_ResourceConfig_offsetIndicator_choice;
+  char             *rxPool_ResourceConfig_subframeBitmap_present;
+  char             *rxPool_ResourceConfig_subframeBitmap_choice_bs_buf;
+  libconfig_int     rxPool_ResourceConfig_subframeBitmap_choice_bs_size;
+  libconfig_int     rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused;
+  //SIB19
+  //For discRxPool
+  char             *discRxPool_cp_Len;
+  char             *discRxPool_discPeriod;
+  libconfig_int     discRxPool_numRetx;
+  libconfig_int     discRxPool_numRepetition;
+  libconfig_int     discRxPool_ResourceConfig_prb_Num;
+  libconfig_int     discRxPool_ResourceConfig_prb_Start;
+  libconfig_int     discRxPool_ResourceConfig_prb_End;
+  char             *discRxPool_ResourceConfig_offsetIndicator_present;
+  libconfig_int     discRxPool_ResourceConfig_offsetIndicator_choice;
+  char             *discRxPool_ResourceConfig_subframeBitmap_present;
+  char             *discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf;
+  libconfig_int     discRxPool_ResourceConfig_subframeBitmap_choice_bs_size;
+  libconfig_int     discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused;
+  //For discRxPoolPS
+  char             *discRxPoolPS_cp_Len;
+  const char       *discRxPoolPS_discPeriod;
+  libconfig_int     discRxPoolPS_numRetx;
+  libconfig_int     discRxPoolPS_numRepetition;
+  libconfig_int     discRxPoolPS_ResourceConfig_prb_Num;
+  libconfig_int     discRxPoolPS_ResourceConfig_prb_Start;
+  libconfig_int     discRxPoolPS_ResourceConfig_prb_End;
+  const char       *discRxPoolPS_ResourceConfig_offsetIndicator_present;
+  libconfig_int     discRxPoolPS_ResourceConfig_offsetIndicator_choice;
+  const char       *discRxPoolPS_ResourceConfig_subframeBitmap_present;
+  char             *discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_buf;
+  libconfig_int     discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_size;
+  libconfig_int     discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_bits_unused;
+} ccparams_sidelink_t;
+
+/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
+/*                                     component carriers configuration parameters                                                                                                                   */
+/*   optname                                                   helpstr   paramflags    XXXptr                                        defXXXval                    type         numelt  checked_param */
+/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
+
+#define CCPARAMS_SIDELINK_DESC(SLparams) {				\
+{"sidelink_configured",                                          NULL,   0,   iptr:(int*)&SLparams.sidelink_configured,   defintval:0,  TYPE_UINT,  0}, \
+{ENB_CONFIG_STRING_RXPOOL_SC_CP_LEN,                             NULL,   0,   strptr:(char **)&SLparams.rxPool_sc_CP_Len,          defstrval:"normal",  TYPE_STRING,  0}, \
+{ENB_CONFIG_STRING_RXPOOL_SC_PRIOD,                              NULL,   0,   strptr:(char **)&SLparams.rxPool_sc_Period,          defstrval:"sf40",  TYPE_STRING,  0}, \
+{ENB_CONFIG_STRING_RXPOOL_DATA_CP_LEN,                           NULL,   0,   strptr:(char **)&SLparams.rxPool_data_CP_Len,          defstrval:"normal",  TYPE_STRING,  0}, \
+{ENB_CONFIG_STRING_RXPOOL_RC_PRB_NUM,                            NULL,   0,   iptr:(int32_t *)&SLparams.rxPool_ResourceConfig_prb_Num,         defintval:1,       TYPE_UINT,    0}, \
+{ENB_CONFIG_STRING_RXPOOL_RC_PRB_START,                          NULL,   0,   iptr:(int32_t *)&SLparams.rxPool_ResourceConfig_prb_Start,         defintval:1,       TYPE_UINT,    0}, \
+{ENB_CONFIG_STRING_RXPOOL_RC_PRB_END,                            NULL,   0,   iptr:(int32_t *)&SLparams.rxPool_ResourceConfig_prb_End,         defintval:1,       TYPE_UINT,    0}, \
+{ENB_CONFIG_STRING_RXPOOL_RC_OFFSETIND_PRESENT,                  NULL,   0,   strptr:(char **)&SLparams.rxPool_ResourceConfig_offsetIndicator_present,            defstrval:"prNothing",  TYPE_STRING,  0}, \
+{ENB_CONFIG_STRING_RXPOOL_RC_OFFSETIND_CHOICE,                   NULL,   0,   iptr:(int32_t *)&SLparams.rxPool_ResourceConfig_offsetIndicator_choice,         defintval:1,       TYPE_UINT,    0}, \
+{ENB_CONFIG_STRING_RXPOOL_RC_SFBITMAP_PRESENT,                   NULL,   0,   strptr:(char **)&SLparams.rxPool_ResourceConfig_subframeBitmap_present,            defstrval:"prNothing",  TYPE_STRING,  0}, \
+{ENB_CONFIG_STRING_RXPOOL_RC_SFBITMAP_CHOICE_BS_BUF,             NULL,   0,   strptr:(char **)&SLparams.rxPool_ResourceConfig_subframeBitmap_choice_bs_buf,            defstrval:"001001",  TYPE_STRING,  0}, \
+{ENB_CONFIG_STRING_RXPOOL_RC_SFBITMAP_CHOICE_BS_SIZE,            NULL,   0,   iptr:(int32_t *)&SLparams.rxPool_ResourceConfig_subframeBitmap_choice_bs_size,         defintval:1,       TYPE_UINT,    0}, \
+{ENB_CONFIG_STRING_RXPOOL_RC_SFBITMAP_CHOICE_BS_ASN_BITS_UNUSED, NULL,   0,   iptr:(int32_t *)&SLparams.rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused,         defintval:1,       TYPE_UINT,    0}, \
+{ENB_CONFIG_STRING_DISCRXPOOL_CP_LEN,                            NULL,   0,   strptr:(char **)&SLparams.discRxPool_cp_Len,          defstrval:"normal",  TYPE_STRING,  0}, \
+{ENB_CONFIG_STRING_DISCRXPOOL_DISCPERIOD,                        NULL,   0,   strptr:(char **)&SLparams.discRxPool_discPeriod,          defstrval:"rf32",  TYPE_STRING,  0}, \
+{ENB_CONFIG_STRING_DISCRXPOOL_NUMRETX,                           NULL,   0,   iptr:(int32_t *)&SLparams.discRxPool_numRetx,         defintval:1,       TYPE_UINT,    0}, \
+{ENB_CONFIG_STRING_DISCRXPOOL_NUMREPETITION,                     NULL,   0,   iptr:(int32_t *)&SLparams.discRxPool_numRepetition,         defintval:1,       TYPE_UINT,    0}, \
+{ENB_CONFIG_STRING_DISCRXPOOL_RC_PRB_NUM,                        NULL,   0,   iptr:(int32_t *)&SLparams.discRxPool_ResourceConfig_prb_Num,         defintval:1,       TYPE_UINT,    0}, \
+{ENB_CONFIG_STRING_DISCRXPOOL_RC_PRB_START,                      NULL,   0,   iptr:(int32_t *)&SLparams.discRxPool_ResourceConfig_prb_Start,         defintval:1,       TYPE_UINT,    0}, \
+{ENB_CONFIG_STRING_DISCRXPOOL_RC_PRB_END,                        NULL,   0,   iptr:(int32_t *)&SLparams.discRxPool_ResourceConfig_prb_End,         defintval:1,       TYPE_UINT,    0}, \
+{ENB_CONFIG_STRING_DISCRXPOOL_RC_OFFSETIND_PRESENT,              NULL,   0,   strptr:(char **)&SLparams.discRxPool_ResourceConfig_offsetIndicator_present,            defstrval:"prNothing",  TYPE_STRING,  0}, \
+{ENB_CONFIG_STRING_DISCRXPOOL_RC_OFFSETIND_CHOICE,               NULL,   0,   iptr:(int32_t *)&SLparams.discRxPool_ResourceConfig_offsetIndicator_choice,         defintval:1,       TYPE_UINT,    0}, \
+{ENB_CONFIG_STRING_DISCRXPOOL_RC_SFBITMAP_PRESENT,               NULL,   0,   strptr:(char **)&SLparams.discRxPool_ResourceConfig_subframeBitmap_present,            defstrval:"prNothing",  TYPE_STRING,  0}, \
+{ENB_CONFIG_STRING_DISCRXPOOL_RC_SFBITMAP_CHOICE_BS_BUF,         NULL,   0,   strptr:(char **)&SLparams.discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf,            defstrval:"001001",  TYPE_STRING,  0}, \
+{ENB_CONFIG_STRING_DISCRXPOOL_RC_SFBITMAP_CHOICE_BS_SIZE,        NULL,   0,   iptr:(int32_t *)&SLparams.discRxPool_ResourceConfig_subframeBitmap_choice_bs_size,         defintval:1,       TYPE_UINT,    0}, \
+{ENB_CONFIG_STRING_DISCRXPOOL_RC_SFBITMAP_CHOICE_BS_ASN_BITS_UNUSED,NULL,   0,   iptr:(int32_t *)&SLparams.discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused,         defintval:1,       TYPE_UINT,    0}, \
+{ENB_CONFIG_STRING_DISCRXPOOLPS_CP_LEN,                            NULL,   0,   strptr:(char **)&SLparams.discRxPoolPS_cp_Len,          defstrval:"normal",  TYPE_STRING,  0}, \
+{ENB_CONFIG_STRING_DISCRXPOOLPS_DISCPERIOD,                        NULL,   0,   strptr:(char **)&SLparams.discRxPoolPS_discPeriod,          defstrval:"rf32",  TYPE_STRING,  0}, \
+{ENB_CONFIG_STRING_DISCRXPOOLPS_NUMRETX,                           NULL,   0,   iptr:(int32_t *)&SLparams.discRxPoolPS_numRetx,         defintval:1,       TYPE_UINT,    0}, \
+{ENB_CONFIG_STRING_DISCRXPOOLPS_NUMREPETITION,                     NULL,   0,   iptr:(int32_t *)&SLparams.discRxPoolPS_numRepetition,         defintval:1,       TYPE_UINT,    0}, \
+{ENB_CONFIG_STRING_DISCRXPOOLPS_RC_PRB_NUM,                        NULL,   0,   iptr:(int32_t *)&SLparams.discRxPoolPS_ResourceConfig_prb_Num,         defintval:1,       TYPE_UINT,    0}, \
+{ENB_CONFIG_STRING_DISCRXPOOLPS_RC_PRB_START,                      NULL,   0,   iptr:(int32_t *)&SLparams.discRxPoolPS_ResourceConfig_prb_Start,         defintval:1,       TYPE_UINT,    0}, \
+{ENB_CONFIG_STRING_DISCRXPOOLPS_RC_PRB_END,                        NULL,   0,   iptr:(int32_t *)&SLparams.discRxPoolPS_ResourceConfig_prb_End,         defintval:1,       TYPE_UINT,    0}, \
+{ENB_CONFIG_STRING_DISCRXPOOLPS_RC_OFFSETIND_PRESENT,              NULL,   0,   strptr:(char **)&SLparams.discRxPoolPS_ResourceConfig_offsetIndicator_present,            defstrval:"prNothing",  TYPE_STRING,  0}, \
+{ENB_CONFIG_STRING_DISCRXPOOLPS_RC_OFFSETIND_CHOICE,               NULL,   0,   iptr:(int32_t *)&SLparams.discRxPoolPS_ResourceConfig_offsetIndicator_choice,         defintval:1,       TYPE_UINT,    0}, \
+{ENB_CONFIG_STRING_DISCRXPOOLPS_RC_SFBITMAP_PRESENT,               NULL,   0,   strptr:(char **)&SLparams.discRxPoolPS_ResourceConfig_subframeBitmap_present,            defstrval:"prNothing",  TYPE_STRING,  0}, \
+{ENB_CONFIG_STRING_DISCRXPOOLPS_RC_SFBITMAP_CHOICE_BS_BUF,         NULL,   0,   strptr:(char **)&SLparams.discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_buf,            defstrval:"001001",  TYPE_STRING,  0}, \
+{ENB_CONFIG_STRING_DISCRXPOOLPS_RC_SFBITMAP_CHOICE_BS_SIZE,        NULL,   0,   iptr:(int32_t *)&SLparams.discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_size,         defintval:1,       TYPE_UINT,    0}, \
+{ENB_CONFIG_STRING_DISCRXPOOLPS_RC_SFBITMAP_CHOICE_BS_ASN_BITS_UNUSED,NULL,   0,   iptr:(int32_t *)&SLparams.discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_bits_unused,         defintval:1,       TYPE_UINT,    0} \
+}
+#endif
diff --git a/openair2/ENB_APP/flexran_agent_common.c b/openair2/ENB_APP/flexran_agent_common.c
index 106fe15a85dc67d54a6fb9c824c844f8af11bc88..e2780073f672f481904d23debd334de56bc346f1 100644
--- a/openair2/ENB_APP/flexran_agent_common.c
+++ b/openair2/ENB_APP/flexran_agent_common.c
@@ -17,10 +17,10 @@
  *-------------------------------------------------------------------------------
  * For more information about the OpenAirInterface (OAI) Software Alliance:
  *      contact@openairinterface.org
- */ 
+ */
 
 /*! \file flexran_agent_common.c
- * \brief common primitives for all agents 
+ * \brief common primitives for all agents
  * \author Xenofon Foukas, Mohamed Kassem and Navid Nikaein, shahab SHARIAT BAGHERI
  * \date 2017
  * \version 0.1
@@ -52,18 +52,19 @@
  */
 
 int flexran_agent_serialize_message(Protocol__FlexranMessage *msg, void **buf, int *size) {
-
   *size = protocol__flexran_message__get_packed_size(msg);
-  
-  *buf = malloc(*size);
+
   if (buf == NULL)
     goto error;
-  
+
+  *buf = malloc(*size);
+
+  if (*buf == NULL)
+    goto error;
+
   protocol__flexran_message__pack(msg, *buf);
-  
   return 0;
-  
- error:
+error:
   LOG_E(FLEXRAN_AGENT, "an error occured\n"); // change the com
   return -1;
 }
@@ -74,12 +75,12 @@ int flexran_agent_serialize_message(Protocol__FlexranMessage *msg, void **buf, i
    Should be chekced durint Tx/Rx */
 int flexran_agent_deserialize_message(void *data, int size, Protocol__FlexranMessage **msg) {
   *msg = protocol__flexran_message__unpack(NULL, size, data);
+
   if (*msg == NULL)
     goto error;
 
   return 0;
-  
- error:
+error:
   //LOG_E(MAC, "%s: an error occured\n", __FUNCTION__);
   return -1;
 }
@@ -87,37 +88,36 @@ int flexran_agent_deserialize_message(void *data, int size, Protocol__FlexranMes
 
 
 int flexran_create_header(xid_t xid, Protocol__FlexType type,  Protocol__FlexHeader **header) {
-  
   *header = malloc(sizeof(Protocol__FlexHeader));
+
   if(*header == NULL)
     goto error;
-  
+
   protocol__flex_header__init(*header);
   (*header)->version = FLEXRAN_VERSION;
-  (*header)->has_version = 1; 
+  (*header)->has_version = 1;
   // check if the type is set
   (*header)->type = type;
   (*header)->has_type = 1;
   (*header)->xid = xid;
   (*header)->has_xid = 1;
   return 0;
-
- error:
+error:
   LOG_E(FLEXRAN_AGENT, "%s: an error occured\n", __FUNCTION__);
   return -1;
 }
 
 
 int flexran_agent_hello(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg) {
- 
   Protocol__FlexHeader *header = NULL;
   /*TODO: Need to set random xid or xid from received hello message*/
   xid_t xid = 1;
-
   Protocol__FlexHello *hello_msg;
   hello_msg = malloc(sizeof(Protocol__FlexHello));
+
   if(hello_msg == NULL)
     goto error;
+
   protocol__flex_hello__init(hello_msg);
 
   if (flexran_create_header(xid, PROTOCOL__FLEX_TYPE__FLPT_HELLO, &header) != 0)
@@ -129,77 +129,84 @@ int flexran_agent_hello(mid_t mod_id, const void *params, Protocol__FlexranMessa
   hello_msg->n_capabilities = flexran_get_capabilities(mod_id, &hello_msg->capabilities);
 
   *msg = malloc(sizeof(Protocol__FlexranMessage));
+
   if(*msg == NULL)
     goto error;
-  
+
   protocol__flexran_message__init(*msg);
   (*msg)->msg_case = PROTOCOL__FLEXRAN_MESSAGE__MSG_HELLO_MSG;
   (*msg)->msg_dir = PROTOCOL__FLEXRAN_DIRECTION__SUCCESSFUL_OUTCOME;
   (*msg)->has_msg_dir = 1;
   (*msg)->hello_msg = hello_msg;
   return 0;
-  
- error:
+error:
+
   if(header != NULL)
     free(header);
+
   if(hello_msg != NULL)
     free(hello_msg);
+
   if(*msg != NULL)
     free(*msg);
+
   LOG_E(FLEXRAN_AGENT, "%s: an error occured\n", __FUNCTION__);
   return -1;
 }
 
 
 int flexran_agent_destroy_hello(Protocol__FlexranMessage *msg) {
-  
   if(msg->msg_case != PROTOCOL__FLEXRAN_MESSAGE__MSG_HELLO_MSG)
     goto error;
-  
+
   free(msg->hello_msg->header);
   free(msg->hello_msg->capabilities);
   free(msg->hello_msg);
   free(msg);
   return 0;
-
- error:
+error:
   LOG_E(FLEXRAN_AGENT, "%s: an error occured\n", __FUNCTION__);
   return -1;
 }
 
 
-int flexran_agent_echo_request(mid_t mod_id, const void* params, Protocol__FlexranMessage **msg) {
+int flexran_agent_echo_request(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg) {
   Protocol__FlexHeader *header = NULL;
   /*TODO: Need to set a random xid*/
   xid_t xid = 1;
-
   Protocol__FlexEchoRequest *echo_request_msg = NULL;
   echo_request_msg = malloc(sizeof(Protocol__FlexEchoRequest));
+
   if(echo_request_msg == NULL)
     goto error;
+
   protocol__flex_echo_request__init(echo_request_msg);
 
   if (flexran_create_header(xid, PROTOCOL__FLEX_TYPE__FLPT_ECHO_REQUEST, &header) != 0)
     goto error;
 
   echo_request_msg->header = header;
-
   *msg = malloc(sizeof(Protocol__FlexranMessage));
+
   if(*msg == NULL)
     goto error;
+
   protocol__flexran_message__init(*msg);
   (*msg)->msg_case = PROTOCOL__FLEXRAN_MESSAGE__MSG_ECHO_REQUEST_MSG;
   (*msg)->msg_dir = PROTOCOL__FLEXRAN_DIRECTION__INITIATING_MESSAGE;
   (*msg)->echo_request_msg = echo_request_msg;
   return 0;
+error:
 
- error:
   if(header != NULL)
     free(header);
+
   if(echo_request_msg != NULL)
     free(echo_request_msg);
+
   if(*msg != NULL)
     free(*msg);
+
   //LOG_E(MAC, "%s: an error occured\n", __FUNCTION__);
   return -1;
 }
@@ -208,13 +215,12 @@ int flexran_agent_echo_request(mid_t mod_id, const void* params, Protocol__Flexr
 int flexran_agent_destroy_echo_request(Protocol__FlexranMessage *msg) {
   if(msg->msg_case != PROTOCOL__FLEXRAN_MESSAGE__MSG_ECHO_REQUEST_MSG)
     goto error;
-  
+
   free(msg->echo_request_msg->header);
   free(msg->echo_request_msg);
   free(msg);
   return 0;
-  
- error:
+error:
   LOG_E(FLEXRAN_AGENT, "%s: an error occured\n", __FUNCTION__);
   return -1;
 }
@@ -222,41 +228,45 @@ int flexran_agent_destroy_echo_request(Protocol__FlexranMessage *msg) {
 
 
 int flexran_agent_echo_reply(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg) {
-  
   xid_t xid;
   Protocol__FlexHeader *header = NULL;
   Protocol__FlexranMessage *input = (Protocol__FlexranMessage *)params;
   Protocol__FlexEchoRequest *echo_req = input->echo_request_msg;
   xid = (echo_req->header)->xid;
-
   Protocol__FlexEchoReply *echo_reply_msg = NULL;
   echo_reply_msg = malloc(sizeof(Protocol__FlexEchoReply));
+
   if(echo_reply_msg == NULL)
     goto error;
+
   protocol__flex_echo_reply__init(echo_reply_msg);
 
   if (flexran_create_header(xid, PROTOCOL__FLEX_TYPE__FLPT_ECHO_REPLY, &header) != 0)
     goto error;
 
   echo_reply_msg->header = header;
-
   *msg = malloc(sizeof(Protocol__FlexranMessage));
+
   if(*msg == NULL)
     goto error;
+
   protocol__flexran_message__init(*msg);
   (*msg)->msg_case = PROTOCOL__FLEXRAN_MESSAGE__MSG_ECHO_REPLY_MSG;
   (*msg)->msg_dir = PROTOCOL__FLEXRAN_DIRECTION__SUCCESSFUL_OUTCOME;
   (*msg)->has_msg_dir = 1;
   (*msg)->echo_reply_msg = echo_reply_msg;
   return 0;
+error:
 
- error:
   if(header != NULL)
     free(header);
+
   if(echo_reply_msg != NULL)
     free(echo_reply_msg);
+
   if(*msg != NULL)
     free(*msg);
+
   LOG_E(FLEXRAN_AGENT, "%s: an error occured\n", __FUNCTION__);
   return -1;
 }
@@ -265,13 +275,12 @@ int flexran_agent_echo_reply(mid_t mod_id, const void *params, Protocol__Flexran
 int flexran_agent_destroy_echo_reply(Protocol__FlexranMessage *msg) {
   if(msg->msg_case != PROTOCOL__FLEXRAN_MESSAGE__MSG_ECHO_REPLY_MSG)
     goto error;
-  
+
   free(msg->echo_reply_msg->header);
   free(msg->echo_reply_msg);
   free(msg);
   return 0;
-  
- error:
+error:
   LOG_E(FLEXRAN_AGENT, "%s: an error occured\n", __FUNCTION__);
   return -1;
 }
@@ -280,48 +289,56 @@ int flexran_agent_destroy_echo_reply(Protocol__FlexranMessage *msg) {
 int flexran_agent_destroy_enb_config_reply(Protocol__FlexranMessage *msg) {
   if(msg->msg_case != PROTOCOL__FLEXRAN_MESSAGE__MSG_ENB_CONFIG_REPLY_MSG)
     goto error;
+
   free(msg->enb_config_reply_msg->header);
   Protocol__FlexEnbConfigReply *reply = msg->enb_config_reply_msg;
-  
-  for (int i = 0; i < reply->n_cell_config;i++) {
+
+  for (int i = 0; i < reply->n_cell_config; i++) {
     if (reply->cell_config[i]->mbsfn_subframe_config_rfoffset)
       free(reply->cell_config[i]->mbsfn_subframe_config_rfoffset);
     if (reply->cell_config[i]->mbsfn_subframe_config_rfperiod)
       free(reply->cell_config[i]->mbsfn_subframe_config_rfperiod);
-    if (reply->cell_config[i]->mbsfn_subframe_config_sfalloc)
+    if (reply->cell_config[i]->mbsfn_subframe_config_sfalloc);
       free(reply->cell_config[i]->mbsfn_subframe_config_sfalloc);
-    if (reply->cell_config[i]->si_config != NULL) {
-      for (int j = 0; j < reply->cell_config[i]->si_config->n_si_message;j++){
-	free(reply->cell_config[i]->si_config->si_message[j]);
+
+    if (reply->cell_config[i]->si_config) {
+      for(int j = 0; j < reply->cell_config[i]->si_config->n_si_message; j++) {
+        free(reply->cell_config[i]->si_config->si_message[j]);
       }
       free(reply->cell_config[i]->si_config->si_message);
       free(reply->cell_config[i]->si_config);
     }
-    if (reply->cell_config[i]->slice_config != NULL) {
+
+    if (reply->cell_config[i]->slice_config) {
       for (int j = 0; j < reply->cell_config[i]->slice_config->n_dl; ++j) {
         if (reply->cell_config[i]->slice_config->dl[j]->n_sorting > 0)
           free(reply->cell_config[i]->slice_config->dl[j]->sorting);
+
         free(reply->cell_config[i]->slice_config->dl[j]->scheduler_name);
         free(reply->cell_config[i]->slice_config->dl[j]);
       }
+
       free(reply->cell_config[i]->slice_config->dl);
       for (int j = 0; j < reply->cell_config[i]->slice_config->n_ul; ++j) {
         if (reply->cell_config[i]->slice_config->ul[j]->n_sorting > 0)
           free(reply->cell_config[i]->slice_config->ul[j]->sorting);
+
         free(reply->cell_config[i]->slice_config->ul[j]->scheduler_name);
         free(reply->cell_config[i]->slice_config->ul[j]);
       }
+
       free(reply->cell_config[i]->slice_config->ul);
       free(reply->cell_config[i]->slice_config);
     }
+
     free(reply->cell_config[i]);
   }
+
   free(reply->cell_config);
   free(reply);
   free(msg);
-  
   return 0;
- error:
+error:
   //LOG_E(FLEXRAN_AGENT, "%s: an error occured\n", __FUNCTION__);
   return -1;
 }
@@ -329,20 +346,21 @@ int flexran_agent_destroy_enb_config_reply(Protocol__FlexranMessage *msg) {
 int flexran_agent_destroy_ue_config_reply(Protocol__FlexranMessage *msg) {
   if(msg->msg_case != PROTOCOL__FLEXRAN_MESSAGE__MSG_UE_CONFIG_REPLY_MSG)
     goto error;
+
   free(msg->ue_config_reply_msg->header);
   int i;
   Protocol__FlexUeConfigReply *reply = msg->ue_config_reply_msg;
-  
-  for(i = 0; i < reply->n_ue_config;i++){
+
+  for(i = 0; i < reply->n_ue_config; i++) {
     free(reply->ue_config[i]->capabilities);
     free(reply->ue_config[i]);
   }
+
   free(reply->ue_config);
   free(reply);
   free(msg);
-
   return 0;
- error:
+error:
   //LOG_E(FLEXRAN_AGENT, "%s: an error occured\n", __FUNCTION__);
   return -1;
 }
@@ -353,18 +371,21 @@ int flexran_agent_destroy_lc_config_reply(Protocol__FlexranMessage *msg) {
 
   int i, j;
   free(msg->lc_config_reply_msg->header);
+
   for (i = 0; i < msg->lc_config_reply_msg->n_lc_ue_config; i++) {
     for (j = 0; j < msg->lc_config_reply_msg->lc_ue_config[i]->n_lc_config; j++) {
       free(msg->lc_config_reply_msg->lc_ue_config[i]->lc_config[j]);
     }
+
     free(msg->lc_config_reply_msg->lc_ue_config[i]->lc_config);
     free(msg->lc_config_reply_msg->lc_ue_config[i]);
   }
+
   free(msg->lc_config_reply_msg->lc_ue_config);
   free(msg->lc_config_reply_msg);
   free(msg);
   return 0;
- error:
+error:
   //LOG_E(FLEXRAN_AGENT, "%s: an error occured\n", __FUNCTION__);
   return -1;
 }
@@ -373,12 +394,12 @@ int flexran_agent_destroy_lc_config_reply(Protocol__FlexranMessage *msg) {
 int flexran_agent_destroy_enb_config_request(Protocol__FlexranMessage *msg) {
   if(msg->msg_case != PROTOCOL__FLEXRAN_MESSAGE__MSG_ENB_CONFIG_REQUEST_MSG)
     goto error;
+
   free(msg->enb_config_request_msg->header);
   free(msg->enb_config_request_msg);
   free(msg);
   return 0;
-  
- error:
+error:
   //LOG_E(FLEXRAN_AGENT, "%s: an error occured\n", __FUNCTION__);
   return -1;
 }
@@ -395,24 +416,22 @@ int flexran_agent_destroy_lc_config_request(Protocol__FlexranMessage *msg) {
 
 // call this function to start a nanosecond-resolution timer
 struct timespec timer_start(void) {
-    struct timespec start_time;
-    clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start_time);
-    return start_time;
+  struct timespec start_time;
+  clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start_time);
+  return start_time;
 }
 
 // call this function to end a timer, returning nanoseconds elapsed as a long
-long timer_end(struct timespec start_time){
-    struct timespec end_time;
-    clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end_time);
-    long diffInNanos = end_time.tv_nsec - start_time.tv_nsec;
-    return diffInNanos;
+long timer_end(struct timespec start_time) {
+  struct timespec end_time;
+  clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end_time);
+  long diffInNanos = end_time.tv_nsec - start_time.tv_nsec;
+  return diffInNanos;
 }
 
 int flexran_agent_control_delegation(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg) {
-
   Protocol__FlexranMessage *input = (Protocol__FlexranMessage *)params;
   Protocol__FlexControlDelegation *control_delegation_msg = input->control_delegation_msg;
-
   //  struct timespec vartime = timer_start();
   //Write the payload lib into a file in the cache and load the lib
   char lib_name[120];
@@ -420,14 +439,13 @@ int flexran_agent_control_delegation(mid_t mod_id, const void *params, Protocol_
   snprintf(lib_name, sizeof(lib_name), "/%s.so", control_delegation_msg->name);
   strcpy(target, RC.flexran[mod_id]->cache_name);
   strcat(target, lib_name);
-  
   FILE *f;
   f = fopen(target, "wb");
+
   if (f) {
     fwrite(control_delegation_msg->payload.data, control_delegation_msg->payload.len, 1, f);
     fclose(f);
-  }
-  else {
+  } else {
     LOG_W(FLEXRAN_AGENT, "[%d] can not write control delegation data to %s\n",
           mod_id, target);
   }
@@ -435,7 +453,6 @@ int flexran_agent_control_delegation(mid_t mod_id, const void *params, Protocol_
   //  long time_elapsed_nanos = timer_end(vartime);
   *msg = NULL;
   return 0;
-
 }
 
 int flexran_agent_destroy_control_delegation(Protocol__FlexranMessage *msg) {
@@ -446,9 +463,7 @@ int flexran_agent_destroy_control_delegation(Protocol__FlexranMessage *msg) {
 int flexran_agent_reconfiguration(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg) {
   Protocol__FlexranMessage *input = (Protocol__FlexranMessage *)params;
   Protocol__FlexAgentReconfiguration *agent_reconfiguration_msg = input->agent_reconfiguration_msg;
-
   apply_reconfiguration_policy(mod_id, agent_reconfiguration_msg->policy, strlen(agent_reconfiguration_msg->policy));
-
   *msg = NULL;
   return 0;
 }
@@ -460,17 +475,17 @@ int flexran_agent_destroy_agent_reconfiguration(Protocol__FlexranMessage *msg) {
 
 
 int flexran_agent_lc_config_reply(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg) {
-
   xid_t xid;
   Protocol__FlexHeader *header = NULL;
   Protocol__FlexranMessage *input = (Protocol__FlexranMessage *)params;
   Protocol__FlexLcConfigRequest *lc_config_request_msg = input->lc_config_request_msg;
   xid = (lc_config_request_msg->header)->xid;
-
   Protocol__FlexLcConfigReply *lc_config_reply_msg;
   lc_config_reply_msg = malloc(sizeof(Protocol__FlexLcConfigReply));
+
   if(lc_config_reply_msg == NULL)
     goto error;
+
   protocol__flex_lc_config_reply__init(lc_config_reply_msg);
 
   if(flexran_create_header(xid, PROTOCOL__FLEX_TYPE__FLPT_GET_LC_CONFIG_REPLY, &header) != 0)
@@ -489,9 +504,11 @@ int flexran_agent_lc_config_reply(mid_t mod_id, const void *params, Protocol__Fl
   Protocol__FlexLcUeConfig **lc_ue_config = NULL;
   if (lc_config_reply_msg->n_lc_ue_config > 0) {
     lc_ue_config = malloc(sizeof(Protocol__FlexLcUeConfig *) * lc_config_reply_msg->n_lc_ue_config);
+
     if (lc_ue_config == NULL) {
       goto error;
     }
+
     // Fill the config for each UE
     for (int i = 0; i < lc_config_reply_msg->n_lc_ue_config; i++) {
       lc_ue_config[i] = malloc(sizeof(Protocol__FlexLcUeConfig));
@@ -501,27 +518,33 @@ int flexran_agent_lc_config_reply(mid_t mod_id, const void *params, Protocol__Fl
       const int UE_id = flexran_get_mac_ue_id(mod_id, i);
       flexran_agent_fill_mac_lc_ue_config(mod_id, UE_id, lc_ue_config[i]);
     } // end for UE
+
     lc_config_reply_msg->lc_ue_config = lc_ue_config;
   } // lc_config_reply_msg->n_lc_ue_config > 0
+
   *msg = malloc(sizeof(Protocol__FlexranMessage));
+
   if (*msg == NULL)
     goto error;
+
   protocol__flexran_message__init(*msg);
   (*msg)->msg_case = PROTOCOL__FLEXRAN_MESSAGE__MSG_LC_CONFIG_REPLY_MSG;
   (*msg)->msg_dir = PROTOCOL__FLEXRAN_DIRECTION__SUCCESSFUL_OUTCOME;
   (*msg)->lc_config_reply_msg = lc_config_reply_msg;
-
   return 0;
+error:
 
- error:
   // TODO: Need to make proper error handling
   if (header != NULL)
     free(header);
+
   if (lc_config_reply_msg != NULL)
     free(lc_config_reply_msg);
+
   if(*msg != NULL)
     free(*msg);
-  LOG_E(FLEXRAN_AGENT, "%s: an error occured\n", __FUNCTION__);
+
+  //LOG_E(FLEXRAN_AGENT, "%s: an error occured\n", __FUNCTION__);
   return -1;
 }
 
@@ -544,17 +567,17 @@ int sort_ue_config(const void *a, const void *b)
 }
 
 int flexran_agent_ue_config_reply(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg) {
-
   xid_t xid;
   Protocol__FlexHeader *header = NULL;
   Protocol__FlexranMessage *input = (Protocol__FlexranMessage *)params;
   Protocol__FlexUeConfigRequest *ue_config_request_msg = input->ue_config_request_msg;
   xid = (ue_config_request_msg->header)->xid;
-
   Protocol__FlexUeConfigReply *ue_config_reply_msg;
   ue_config_reply_msg = malloc(sizeof(Protocol__FlexUeConfigReply));
+
   if(ue_config_reply_msg == NULL)
     goto error;
+
   protocol__flex_ue_config_reply__init(ue_config_reply_msg);
 
   if(flexran_create_header(xid, PROTOCOL__FLEX_TYPE__FLPT_GET_UE_CONFIG_REPLY, &header) != 0)
@@ -576,8 +599,10 @@ int flexran_agent_ue_config_reply(mid_t mod_id, const void *params, Protocol__Fl
   }
 
   Protocol__FlexUeConfig **ue_config;
+
   if (ue_config_reply_msg->n_ue_config > 0) {
     ue_config = malloc(sizeof(Protocol__FlexUeConfig *) * ue_config_reply_msg->n_ue_config);
+
     if (ue_config == NULL) {
       goto error;
     }
@@ -595,27 +620,32 @@ int flexran_agent_ue_config_reply(mid_t mod_id, const void *params, Protocol__Fl
         flexran_agent_fill_mac_ue_config(mod_id, UE_id, ue_config[i]);
       }
     }
-    qsort(ue_config, ue_config_reply_msg->n_ue_config, sizeof(ue_config[0]), sort_ue_config);
     ue_config_reply_msg->ue_config = ue_config;
   }
+
   *msg = malloc(sizeof(Protocol__FlexranMessage));
+
   if (*msg == NULL)
     goto error;
+
   protocol__flexran_message__init(*msg);
   (*msg)->msg_case = PROTOCOL__FLEXRAN_MESSAGE__MSG_UE_CONFIG_REPLY_MSG;
   (*msg)->msg_dir = PROTOCOL__FLEXRAN_DIRECTION__SUCCESSFUL_OUTCOME;
   (*msg)->ue_config_reply_msg = ue_config_reply_msg;
   return 0;
+error:
 
- error:
   // TODO: Need to make proper error handling
   if (header != NULL)
     free(header);
+
   if (ue_config_reply_msg != NULL)
     free(ue_config_reply_msg);
+
   if(*msg != NULL)
     free(*msg);
-  LOG_E(FLEXRAN_AGENT, "%s: an error occured\n", __FUNCTION__);
+
+  //LOG_E(FLEXRAN_AGENT, "%s: an error occured\n", __FUNCTION__);
   return -1;
 }
 
@@ -626,68 +656,71 @@ int flexran_agent_ue_config_reply(mid_t mod_id, const void *params, Protocol__Fl
  * ************************************
  */
 
-int flexran_agent_enb_config_request(mid_t mod_id, const void* params, Protocol__FlexranMessage **msg) {
-
-	Protocol__FlexHeader *header = NULL;
-	xid_t xid = 1;
-
-	Protocol__FlexEnbConfigRequest *enb_config_request_msg;
-	enb_config_request_msg = malloc(sizeof(Protocol__FlexEnbConfigRequest));
-	if(enb_config_request_msg == NULL)
-	  goto error;
-	protocol__flex_enb_config_request__init(enb_config_request_msg);
-	
-	if(flexran_create_header(xid,PROTOCOL__FLEX_TYPE__FLPT_GET_ENB_CONFIG_REQUEST, &header) != 0)
-	  goto error;
-
-	enb_config_request_msg->header = header;
-
-	*msg = malloc(sizeof(Protocol__FlexranMessage));
-	if(*msg == NULL)
-	  goto error;
-
-	protocol__flexran_message__init(*msg);
-	(*msg)->msg_case = PROTOCOL__FLEXRAN_MESSAGE__MSG_ENB_CONFIG_REQUEST_MSG;
-	(*msg)->msg_dir = PROTOCOL__FLEXRAN_DIRECTION__INITIATING_MESSAGE;
-	(*msg)->enb_config_request_msg = enb_config_request_msg;
-	return 0;
-
-	error:
-	  // TODO: Need to make proper error handling
-	  if (header != NULL)
-	    free(header);
-	  if (enb_config_request_msg != NULL)
-	    free(enb_config_request_msg);
-	  if(*msg != NULL)
-	    free(*msg);
-	  //LOG_E(MAC, "%s: an error occured\n", __FUNCTION__);
-	  return -1;
+int flexran_agent_enb_config_request(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg) {
+  Protocol__FlexHeader *header = NULL;
+  xid_t xid = 1;
+  Protocol__FlexEnbConfigRequest *enb_config_request_msg;
+  enb_config_request_msg = malloc(sizeof(Protocol__FlexEnbConfigRequest));
+
+  if(enb_config_request_msg == NULL)
+    goto error;
+
+  protocol__flex_enb_config_request__init(enb_config_request_msg);
+
+  if(flexran_create_header(xid,PROTOCOL__FLEX_TYPE__FLPT_GET_ENB_CONFIG_REQUEST, &header) != 0)
+    goto error;
+
+  enb_config_request_msg->header = header;
+  *msg = malloc(sizeof(Protocol__FlexranMessage));
+
+  if(*msg == NULL)
+    goto error;
+
+  protocol__flexran_message__init(*msg);
+  (*msg)->msg_case = PROTOCOL__FLEXRAN_MESSAGE__MSG_ENB_CONFIG_REQUEST_MSG;
+  (*msg)->msg_dir = PROTOCOL__FLEXRAN_DIRECTION__INITIATING_MESSAGE;
+  (*msg)->enb_config_request_msg = enb_config_request_msg;
+  return 0;
+error:
+
+  // TODO: Need to make proper error handling
+  if (header != NULL)
+    free(header);
+
+  if (enb_config_request_msg != NULL)
+    free(enb_config_request_msg);
+
+  if(*msg != NULL)
+    free(*msg);
+
+  //LOG_E(MAC, "%s: an error occured\n", __FUNCTION__);
+  return -1;
 }
 
 int flexran_agent_enb_config_reply(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg) {
-
   xid_t xid;
   Protocol__FlexHeader *header = NULL;
   Protocol__FlexranMessage *input = (Protocol__FlexranMessage *)params;
   Protocol__FlexEnbConfigRequest *enb_config_req_msg = input->enb_config_request_msg;
   xid = (enb_config_req_msg->header)->xid;
-  
   Protocol__FlexEnbConfigReply *enb_config_reply_msg;
   enb_config_reply_msg = malloc(sizeof(Protocol__FlexEnbConfigReply));
+
   if(enb_config_reply_msg == NULL)
     goto error;
+
   protocol__flex_enb_config_reply__init(enb_config_reply_msg);
 
   if(flexran_create_header(xid, PROTOCOL__FLEX_TYPE__FLPT_GET_ENB_CONFIG_REPLY, &header) != 0)
     goto error;
-  
-  enb_config_reply_msg->header = header;
 
+  enb_config_reply_msg->header = header;
   enb_config_reply_msg->n_cell_config = MAX_NUM_CCs;
-  
   Protocol__FlexCellConfig **cell_conf;
-  if(enb_config_reply_msg->n_cell_config > 0){
+
+  if(enb_config_reply_msg->n_cell_config > 0) {
     cell_conf = malloc(sizeof(Protocol__FlexCellConfig *) * enb_config_reply_msg->n_cell_config);
+
     if(cell_conf == NULL)
       goto error;
     for(int i = 0; i < enb_config_reply_msg->n_cell_config; i++){
@@ -704,67 +737,59 @@ int flexran_agent_enb_config_reply(mid_t mod_id, const void *params, Protocol__F
       cell_conf[i]->carrier_index = i;
       cell_conf[i]->has_carrier_index = 1;
     }
+
     enb_config_reply_msg->cell_config=cell_conf;
   }
+
   *msg = malloc(sizeof(Protocol__FlexranMessage));
+
   if(*msg == NULL)
     goto error;
+
   protocol__flexran_message__init(*msg);
   (*msg)->msg_case = PROTOCOL__FLEXRAN_MESSAGE__MSG_ENB_CONFIG_REPLY_MSG;
   (*msg)->msg_dir = PROTOCOL__FLEXRAN_DIRECTION__SUCCESSFUL_OUTCOME;
   (*msg)->enb_config_reply_msg = enb_config_reply_msg;
-  
   return 0;
-  
- error:
+error:
+
   // TODO: Need to make proper error handling
   if (header != NULL)
     free(header);
+
   if (enb_config_reply_msg != NULL)
     free(enb_config_reply_msg);
+
   if(*msg != NULL)
     free(*msg);
+
   //LOG_E(FLEXRAN_AGENT, "%s: an error occured\n", __FUNCTION__);
   return -1;
 }
 
 
 int flexran_agent_rrc_measurement(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg) {
-
   protocol_ctxt_t  ctxt;
-
   Protocol__FlexranMessage *input = (Protocol__FlexranMessage *)params;
   Protocol__FlexRrcTriggering *triggering = input->rrc_triggering;
-
   agent_reconf_rrc *reconf_param = malloc(sizeof(agent_reconf_rrc));
-  
-
   reconf_param->trigger_policy = triggering->rrc_trigger;
-
   struct rrc_eNB_ue_context_s   *ue_context_p = NULL;
-
-  RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(RC.rrc[mod_id]->rrc_ue_head)){
-
-
-  PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, mod_id, ENB_FLAG_YES, ue_context_p->ue_context.rnti, flexran_get_current_frame(mod_id), flexran_get_current_subframe (mod_id), mod_id);
-  
-  flexran_rrc_eNB_generate_defaultRRCConnectionReconfiguration(&ctxt, ue_context_p, 0, reconf_param);  
-
+  RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(RC.rrc[mod_id]->rrc_ue_head)) {
+    PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, mod_id, ENB_FLAG_YES, ue_context_p->ue_context.rnti, flexran_get_current_frame(mod_id), flexran_get_current_subframe (mod_id), mod_id);
+    flexran_rrc_eNB_generate_defaultRRCConnectionReconfiguration(&ctxt, ue_context_p, 0, reconf_param);
   }
-  
-  
   *msg = NULL;
   return 0;
 }
 
 
-int flexran_agent_destroy_rrc_measurement(Protocol__FlexranMessage *msg){
+int flexran_agent_destroy_rrc_measurement(Protocol__FlexranMessage *msg) {
   // TODO
   return 0;
 }
 
-int flexran_agent_handle_enb_config_reply(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg)
-{
+int flexran_agent_handle_enb_config_reply(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg) {
   Protocol__FlexranMessage *input = (Protocol__FlexranMessage *)params;
   Protocol__FlexEnbConfigReply *enb_config = input->enb_config_reply_msg;
 
@@ -787,8 +812,7 @@ int flexran_agent_handle_enb_config_reply(mid_t mod_id, const void *params, Prot
   return 0;
 }
 
-int flexran_agent_handle_ue_config_reply(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg)
-{
+int flexran_agent_handle_ue_config_reply(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg) {
   int i;
   Protocol__FlexranMessage *input = (Protocol__FlexranMessage *)params;
   Protocol__FlexUeConfigReply *ue_config_reply = input->ue_config_reply_msg;
diff --git a/openair2/ENB_APP/flexran_agent_ran_api.c b/openair2/ENB_APP/flexran_agent_ran_api.c
index fbf43cc25ac8fea50bb59f04f06f473a88fdae38..4596defc5258ccb2f41eb72e1fa1e278e545b836 100644
--- a/openair2/ENB_APP/flexran_agent_ran_api.c
+++ b/openair2/ENB_APP/flexran_agent_ran_api.c
@@ -190,7 +190,7 @@ rlc_buffer_occupancy_t flexran_get_tx_queue_size(mid_t mod_id, mid_t ue_id, logi
   frame_t frame = flexran_get_current_frame(mod_id);
   sub_frame_t subframe = flexran_get_current_subframe(mod_id);
   mac_rlc_status_resp_t rlc_status = mac_rlc_status_ind(mod_id,rnti, mod_id, frame, subframe, ENB_FLAG_YES,MBMS_FLAG_NO, channel_id, 0
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                                                     ,0, 0
 #endif
                                                     );
@@ -204,7 +204,7 @@ rlc_buffer_occupancy_t flexran_get_num_pdus_buffer(mid_t mod_id, mid_t ue_id, lo
   frame_t frame = flexran_get_current_frame(mod_id);
   sub_frame_t subframe = flexran_get_current_subframe(mod_id);
   mac_rlc_status_resp_t rlc_status = mac_rlc_status_ind(mod_id,rnti, mod_id, frame, subframe, ENB_FLAG_YES,MBMS_FLAG_NO, channel_id, 0
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                                                     ,0, 0
 #endif
                                                     );
@@ -218,7 +218,7 @@ frame_t flexran_get_hol_delay(mid_t mod_id, mid_t ue_id, logical_chan_id_t chann
   frame_t frame = flexran_get_current_frame(mod_id);
   sub_frame_t subframe = flexran_get_current_subframe(mod_id);
   mac_rlc_status_resp_t rlc_status = mac_rlc_status_ind(mod_id, rnti, mod_id, frame, subframe, ENB_FLAG_YES, MBMS_FLAG_NO, channel_id, 0
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                                                     ,0, 0
 #endif
                                                     );
@@ -410,14 +410,16 @@ void flexran_update_TA(mid_t mod_id, mid_t ue_id, uint8_t cc_id)
     ue_sched_ctl->ta_timer--;
     ue_sched_ctl->ta_update		      = 0;	// don't trigger a timing advance command      
   }
-*/
 #warning "Implement flexran_update_TA() in RAN API"
+*/
 }
 
 /* TODO needs to be revised, looks suspicious: why do we need UE stats? */
 int flexran_get_MAC_CE_bitmap_TA(mid_t mod_id, mid_t ue_id, uint8_t cc_id)
 {
+/*
 #warning "Implement flexran_get_MAC_CE_bitmap_TA() in RAN API"
+*/
   if (!phy_is_present(mod_id, cc_id)) return 0;
 
   /* UE_stats can not be null, they are an array in RC
@@ -511,7 +513,9 @@ int flexran_get_harq(mid_t       mod_id,
   /*   *status = 0; */
   /* } */
   /*return *round;*/
+/*
 #warning "Implement flexran_get_harq() in RAN API"
+*/
   return 0;
 }
 
@@ -731,13 +735,13 @@ uint8_t flexran_get_special_subframe_assignment(mid_t mod_id, uint8_t cc_id)
 long flexran_get_ra_ResponseWindowSize(mid_t mod_id, uint8_t cc_id)
 {
   if (!rrc_is_present(mod_id)) return 0;
-  return RC.rrc[mod_id]->configuration.rach_raResponseWindowSize[cc_id];
+  return RC.rrc[mod_id]->configuration.radioresourceconfig[cc_id].rach_raResponseWindowSize;
 }
 
 long flexran_get_mac_ContentionResolutionTimer(mid_t mod_id, uint8_t cc_id)
 {
   if (!rrc_is_present(mod_id)) return 0;
-  return RC.rrc[mod_id]->configuration.rach_macContentionResolutionTimer[cc_id];
+  return RC.rrc[mod_id]->configuration.radioresourceconfig[cc_id].rach_macContentionResolutionTimer;
 }
 
 Protocol__FlexDuplexMode flexran_get_duplex_mode(mid_t mod_id, uint8_t cc_id)
@@ -808,7 +812,7 @@ int flexran_get_rrc_rnti_list(mid_t mod_id, rnti_t *list, int max_list)
   return n;
 }
 
-TimeAlignmentTimer_t flexran_get_time_alignment_timer(mid_t mod_id, rnti_t rnti)
+LTE_TimeAlignmentTimer_t  flexran_get_time_alignment_timer(mid_t mod_id, rnti_t rnti)
 {
   if (!rrc_is_present(mod_id)) return -1;
   struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti);
@@ -823,11 +827,11 @@ Protocol__FlexMeasGapConfigPattern flexran_get_meas_gap_config(mid_t mod_id, rnt
   struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti);
   if (!ue_context_p) return -1;
   if (!ue_context_p->ue_context.measGapConfig) return -1;
-  if (ue_context_p->ue_context.measGapConfig->present != MeasGapConfig_PR_setup) return -1;
+  if (ue_context_p->ue_context.measGapConfig->present != LTE_MeasGapConfig_PR_setup) return -1;
   switch (ue_context_p->ue_context.measGapConfig->choice.setup.gapOffset.present) {
-  case MeasGapConfig__setup__gapOffset_PR_gp0:
+  case LTE_MeasGapConfig__setup__gapOffset_PR_gp0:
     return PROTOCOL__FLEX_MEAS_GAP_CONFIG_PATTERN__FLMGCP_GP1;
-  case MeasGapConfig__setup__gapOffset_PR_gp1:
+  case LTE_MeasGapConfig__setup__gapOffset_PR_gp1:
     return PROTOCOL__FLEX_MEAS_GAP_CONFIG_PATTERN__FLMGCP_GP2;
   default:
     return PROTOCOL__FLEX_MEAS_GAP_CONFIG_PATTERN__FLMGCP_OFF;
@@ -841,11 +845,11 @@ long flexran_get_meas_gap_config_offset(mid_t mod_id, rnti_t rnti)
   struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti);
   if (!ue_context_p) return -1;
   if (!ue_context_p->ue_context.measGapConfig) return -1;
-  if (ue_context_p->ue_context.measGapConfig->present != MeasGapConfig_PR_setup) return -1;
+  if (ue_context_p->ue_context.measGapConfig->present != LTE_MeasGapConfig_PR_setup) return -1;
   switch (ue_context_p->ue_context.measGapConfig->choice.setup.gapOffset.present) {
-  case MeasGapConfig__setup__gapOffset_PR_gp0:
+  case LTE_MeasGapConfig__setup__gapOffset_PR_gp0:
     return ue_context_p->ue_context.measGapConfig->choice.setup.gapOffset.choice.gp0;
-  case MeasGapConfig__setup__gapOffset_PR_gp1:
+  case LTE_MeasGapConfig__setup__gapOffset_PR_gp1:
     return ue_context_p->ue_context.measGapConfig->choice.setup.gapOffset.choice.gp1;
   default:
     return -1;
@@ -878,7 +882,7 @@ int flexran_get_half_duplex(mid_t mod_id, rnti_t rnti)
   struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti);
   if (!ue_context_p) return -1;
   if (!ue_context_p->ue_context.UE_Capability) return -1;
-  SupportedBandListEUTRA_t *bands = &ue_context_p->ue_context.UE_Capability->rf_Parameters.supportedBandListEUTRA;
+  LTE_SupportedBandListEUTRA_t *bands = &ue_context_p->ue_context.UE_Capability->rf_Parameters.supportedBandListEUTRA;
   for (int i = 0; i < bands->list.count; i++) {
     if (bands->list.array[i]->halfDuplex > 0) return 1;
   }
@@ -1026,21 +1030,21 @@ Protocol__FlexAperiodicCqiReportMode flexran_get_aperiodic_cqi_rep_mode(mid_t mo
   if (!ue_context_p->ue_context.physicalConfigDedicated) return -1;
   if (!ue_context_p->ue_context.physicalConfigDedicated->cqi_ReportConfig) return -1;
   switch (*ue_context_p->ue_context.physicalConfigDedicated->cqi_ReportConfig->cqi_ReportModeAperiodic) {
-  case CQI_ReportModeAperiodic_rm12:
+  case LTE_CQI_ReportModeAperiodic_rm12:
     return PROTOCOL__FLEX_APERIODIC_CQI_REPORT_MODE__FLACRM_RM12;
-  case CQI_ReportModeAperiodic_rm20:
+  case LTE_CQI_ReportModeAperiodic_rm20:
     return PROTOCOL__FLEX_APERIODIC_CQI_REPORT_MODE__FLACRM_RM20;
-  case CQI_ReportModeAperiodic_rm22:
+  case LTE_CQI_ReportModeAperiodic_rm22:
     return PROTOCOL__FLEX_APERIODIC_CQI_REPORT_MODE__FLACRM_RM22;
-  case CQI_ReportModeAperiodic_rm30:
+  case LTE_CQI_ReportModeAperiodic_rm30:
     return PROTOCOL__FLEX_APERIODIC_CQI_REPORT_MODE__FLACRM_RM30;
-  case CQI_ReportModeAperiodic_rm31:
+  case LTE_CQI_ReportModeAperiodic_rm31:
     return PROTOCOL__FLEX_APERIODIC_CQI_REPORT_MODE__FLACRM_RM31;
-  case CQI_ReportModeAperiodic_rm32_v1250:
+  case LTE_CQI_ReportModeAperiodic_rm32_v1250:
     return PROTOCOL__FLEX_APERIODIC_CQI_REPORT_MODE__FLACRM_RM32_v1250;
-  case CQI_ReportModeAperiodic_rm10_v1310:
+  case LTE_CQI_ReportModeAperiodic_rm10_v1310:
     return PROTOCOL__FLEX_APERIODIC_CQI_REPORT_MODE__FLACRM_RM10_v1310;
-  case CQI_ReportModeAperiodic_rm11_v1310:
+  case LTE_CQI_ReportModeAperiodic_rm11_v1310:
     return PROTOCOL__FLEX_APERIODIC_CQI_REPORT_MODE__FLACRM_RM11_v1310;
   default:
     return PROTOCOL__FLEX_APERIODIC_CQI_REPORT_MODE__FLACRM_NONE;
@@ -1087,9 +1091,9 @@ int flexran_get_ue_transmission_antenna(mid_t mod_id, rnti_t rnti)
   if (!ue_context_p->ue_context.physicalConfigDedicated) return -1;
   if (!ue_context_p->ue_context.physicalConfigDedicated->antennaInfo) return -1;
   switch (ue_context_p->ue_context.physicalConfigDedicated->antennaInfo->choice.explicitValue.ue_TransmitAntennaSelection.choice.setup) {
-  case AntennaInfoDedicated__ue_TransmitAntennaSelection__setup_closedLoop:
+  case LTE_AntennaInfoDedicated__ue_TransmitAntennaSelection__setup_closedLoop:
     return 2;
-  case AntennaInfoDedicated__ue_TransmitAntennaSelection__setup_openLoop:
+  case LTE_AntennaInfoDedicated__ue_TransmitAntennaSelection__setup_openLoop:
     return 1;
   default:
     return 0;
@@ -1173,7 +1177,7 @@ int8_t flexran_agent_get_operating_pdsch_refpower(mid_t mod_id, uint8_t cc_id)
 long flexran_agent_get_operating_pusch_p0(mid_t mod_id, uint8_t cc_id)
 {
   if (!rrc_is_present(mod_id)) return 0;
-  return RC.rrc[mod_id]->configuration.pusch_p0_Nominal[cc_id];
+  return RC.rrc[mod_id]->configuration.radioresourceconfig[cc_id].pusch_p0_Nominal;
 }
 
 void flexran_agent_set_operating_dl_freq(mid_t mod_id, uint8_t cc_id, uint32_t dl_freq_mhz)
@@ -1427,7 +1431,7 @@ uint32_t flexran_get_pdcp_rx_oo(mid_t mod_id, uint16_t uid, lcid_t lcid)
 
 /******************** RRC *****************************/
 
-MeasId_t flexran_get_rrc_pcell_measid(mid_t mod_id, rnti_t rnti)
+LTE_MeasId_t  flexran_get_rrc_pcell_measid(mid_t mod_id, rnti_t rnti)
 {
   if (!rrc_is_present(mod_id)) return -1;
   struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti);
@@ -1462,7 +1466,7 @@ int flexran_get_rrc_num_ncell(mid_t mod_id, rnti_t rnti)
   if (!ue_context_p) return 0;
   if (!ue_context_p->ue_context.measResults) return 0;
   if (!ue_context_p->ue_context.measResults->measResultNeighCells) return 0;
-  if (ue_context_p->ue_context.measResults->measResultNeighCells->present != MeasResults__measResultNeighCells_PR_measResultListEUTRA) return 0;
+  if (ue_context_p->ue_context.measResults->measResultNeighCells->present != LTE_MeasResults__measResultNeighCells_PR_measResultListEUTRA) return 0;
   return ue_context_p->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.count;
 }
 
@@ -1473,7 +1477,7 @@ long flexran_get_rrc_neigh_phy_cell_id(mid_t mod_id, rnti_t rnti, long cell_id)
   if (!ue_context_p) return -1;
   if (!ue_context_p->ue_context.measResults) return -1;
   if (!ue_context_p->ue_context.measResults->measResultNeighCells) return -1;
-  if (ue_context_p->ue_context.measResults->measResultNeighCells->present != MeasResults__measResultNeighCells_PR_measResultListEUTRA) return -1;
+  if (ue_context_p->ue_context.measResults->measResultNeighCells->present != LTE_MeasResults__measResultNeighCells_PR_measResultListEUTRA) return -1;
   if (!ue_context_p->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[cell_id]) return -1;
   return ue_context_p->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[cell_id]->physCellId;
 }
@@ -1485,7 +1489,7 @@ float flexran_get_rrc_neigh_rsrp(mid_t mod_id, rnti_t rnti, long cell_id)
   if (!ue_context_p) return -1;
   if (!ue_context_p->ue_context.measResults) return -1;
   if (!ue_context_p->ue_context.measResults->measResultNeighCells) return -1;
-  if (ue_context_p->ue_context.measResults->measResultNeighCells->present != MeasResults__measResultNeighCells_PR_measResultListEUTRA) return -1;
+  if (ue_context_p->ue_context.measResults->measResultNeighCells->present != LTE_MeasResults__measResultNeighCells_PR_measResultListEUTRA) return -1;
   if (!ue_context_p->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[cell_id]) return -1;
   if (!ue_context_p->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[cell_id]->measResult.rsrpResult) return 0;
   return RSRP_meas_mapping[*(ue_context_p->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[cell_id]->measResult.rsrpResult)];
@@ -1498,7 +1502,7 @@ float flexran_get_rrc_neigh_rsrq(mid_t mod_id, rnti_t rnti, long cell_id)
   if (!ue_context_p) return -1;
   if (!ue_context_p->ue_context.measResults) return -1;
   if (!ue_context_p->ue_context.measResults->measResultNeighCells) return -1;
-  if (ue_context_p->ue_context.measResults->measResultNeighCells->present != MeasResults__measResultNeighCells_PR_measResultListEUTRA) return -1;
+  if (ue_context_p->ue_context.measResults->measResultNeighCells->present != LTE_MeasResults__measResultNeighCells_PR_measResultListEUTRA) return -1;
   if (!ue_context_p->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[cell_id]->measResult.rsrqResult) return 0;
   return RSRQ_meas_mapping[*(ue_context_p->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[cell_id]->measResult.rsrqResult)];
 }
diff --git a/openair2/ENB_APP/flexran_agent_ran_api.h b/openair2/ENB_APP/flexran_agent_ran_api.h
index 8419435179e9df598c9d94c5db53bb1484f96db8..a60cdeb994cb0f7c0f25af76b01d8b5d8a30178e 100644
--- a/openair2/ENB_APP/flexran_agent_ran_api.h
+++ b/openair2/ENB_APP/flexran_agent_ran_api.h
@@ -324,7 +324,7 @@ int flexran_get_rrc_rnti_list(mid_t mod_id, rnti_t *list, int max_list);
 /* Get timer in subframes. Controls the synchronization
    status of the UE, not the actual timing 
    advance procedure. See TS 36.321 */
-TimeAlignmentTimer_t flexran_get_time_alignment_timer(mid_t mod_id, rnti_t rnti);
+LTE_TimeAlignmentTimer_t flexran_get_time_alignment_timer(mid_t mod_id, rnti_t rnti);
 
 /* Get measurement gap configuration. See TS 36.133 */
 Protocol__FlexMeasGapConfigPattern flexran_get_meas_gap_config(mid_t mod_id, rnti_t rnti);
@@ -499,7 +499,7 @@ uint32_t flexran_get_pdcp_rx_oo(mid_t mod_id, uint16_t uid, lcid_t lcid);
 
 /*********************RRC**********************/
 /*Get primary cell measuremeant id flexRAN*/
-MeasId_t flexran_get_rrc_pcell_measid(mid_t mod_id, rnti_t rnti);
+LTE_MeasId_t flexran_get_rrc_pcell_measid(mid_t mod_id, rnti_t rnti);
 
 /*Get primary cell RSRP measurement flexRAN*/  
 float flexran_get_rrc_pcell_rsrp(mid_t mod_id, rnti_t rnti);
diff --git a/openair2/ENB_APP/flexran_agent_timer.c b/openair2/ENB_APP/flexran_agent_timer.c
index dda302735388ce56f5ce57d9e39de10a5cd712b8..143c2df889294377819bbeba08b28de2be5b8c63 100644
--- a/openair2/ENB_APP/flexran_agent_timer.c
+++ b/openair2/ENB_APP/flexran_agent_timer.c
@@ -17,10 +17,10 @@
  *-------------------------------------------------------------------------------
  * For more information about the OpenAirInterface (OAI) Software Alliance:
  *      contact@openairinterface.org
- */ 
+ */
 
 /*! \file flexran_agent_timer.c
- * \brief FlexRAN Timer  
+ * \brief FlexRAN Timer
  * \author shahab SHARIAT BAGHERI
  * \date 2017
  * \version 0.1
@@ -35,23 +35,23 @@
 //struct flexran_agent_map agent_map;
 flexran_agent_timer_instance_t timer_instance;
 int agent_timer_init = 0;
-err_code_t flexran_agent_init_timer(void){
-  
+err_code_t flexran_agent_init_timer(void) {
   LOG_I(FLEXRAN_AGENT, "init RB tree\n");
+
   if (!agent_timer_init) {
     RB_INIT(&timer_instance.flexran_agent_head);
     agent_timer_init = 1;
   }
- 
- return PROTOCOL__FLEXRAN_ERR__NO_ERR;
+
+  return PROTOCOL__FLEXRAN_ERR__NO_ERR;
 }
 
 RB_GENERATE(flexran_agent_map, flexran_agent_timer_element_s, entry, flexran_agent_compare_timer);
 
 /* The timer_id might not be the best choice for the comparison */
-int flexran_agent_compare_timer(struct flexran_agent_timer_element_s *a, struct flexran_agent_timer_element_s *b){
-
+int flexran_agent_compare_timer(struct flexran_agent_timer_element_s *a, struct flexran_agent_timer_element_s *b) {
   if (a->timer_id < b->timer_id) return -1;
+
   if (a->timer_id > b->timer_id) return 1;
 
   // equal timers
@@ -59,52 +59,53 @@ int flexran_agent_compare_timer(struct flexran_agent_timer_element_s *a, struct
 }
 
 err_code_t flexran_agent_create_timer(uint32_t interval_sec,
-				      uint32_t interval_usec,
-				      agent_id_t     agent_id,
-				      instance_t     instance,
-				      uint32_t timer_type,
-				      xid_t xid,
-				      flexran_agent_timer_callback_t cb,
-				      void*    timer_args,
-				      long *timer_id){
-  
+                                      uint32_t interval_usec,
+                                      agent_id_t     agent_id,
+                                      instance_t     instance,
+                                      uint32_t timer_type,
+                                      xid_t xid,
+                                      flexran_agent_timer_callback_t cb,
+                                      void    *timer_args,
+                                      long *timer_id) {
   struct flexran_agent_timer_element_s *e = calloc(1, sizeof(*e));
   DevAssert(e != NULL);
-  
-//uint32_t timer_id;
+  //uint32_t timer_id;
   int ret=-1;
-  
-  if ((interval_sec == 0) && (interval_usec == 0 ))
+
+  if ((interval_sec == 0) && (interval_usec == 0 )) {
+    free(e);
     return TIMER_NULL;
-  
-  if (timer_type >= FLEXRAN_AGENT_TIMER_TYPE_MAX)
+  }
+
+  if (timer_type >= FLEXRAN_AGENT_TIMER_TYPE_MAX) {
+    free(e);
     return TIMER_TYPE_INVALIDE;
-  
-  if (timer_type  ==   FLEXRAN_AGENT_TIMER_TYPE_ONESHOT){ 
-    ret = timer_setup(interval_sec, 
-		      interval_usec, 
-		      TASK_FLEXRAN_AGENT, 
-		      instance, 
-		      TIMER_ONE_SHOT,
-		      timer_args,
-		      timer_id);
-    
-    e->type = TIMER_ONE_SHOT;
   }
-  else if (timer_type  ==   FLEXRAN_AGENT_TIMER_TYPE_PERIODIC ){
-    ret = timer_setup(interval_sec, 
-		      interval_usec, 
-		      TASK_FLEXRAN_AGENT, 
-		      instance, 
-		      TIMER_PERIODIC,
-		      timer_args,
-		      timer_id);
-    
+
+  if (timer_type  ==   FLEXRAN_AGENT_TIMER_TYPE_ONESHOT) {
+    ret = timer_setup(interval_sec,
+                      interval_usec,
+                      TASK_FLEXRAN_AGENT,
+                      instance,
+                      TIMER_ONE_SHOT,
+                      timer_args,
+                      timer_id);
+
+    e->type = TIMER_ONE_SHOT;
+  } else if (timer_type  ==   FLEXRAN_AGENT_TIMER_TYPE_PERIODIC ) {
+    ret = timer_setup(interval_sec,
+                      interval_usec,
+                      TASK_FLEXRAN_AGENT,
+                      instance,
+                      TIMER_PERIODIC,
+                      timer_args,
+                      timer_id);
     e->type = TIMER_PERIODIC;
   }
-  
+
   if (ret < 0 ) {
-    return TIMER_SETUP_FAILED; 
+    free(e);
+    return TIMER_SETUP_FAILED;
   }
 
   e->agent_id = agent_id;
@@ -112,19 +113,16 @@ err_code_t flexran_agent_create_timer(uint32_t interval_sec,
   e->state = FLEXRAN_AGENT_TIMER_STATE_ACTIVE;
   e->timer_id = *timer_id;
   e->xid = xid;
-  e->timer_args = timer_args; 
+  e->timer_args = timer_args;
   e->cb = cb;
   /*element should be a real pointer*/
-  RB_INSERT(flexran_agent_map, &timer_instance.flexran_agent_head, e); 
-  
+  RB_INSERT(flexran_agent_map, &timer_instance.flexran_agent_head, e);
   LOG_I(FLEXRAN_AGENT,"Created a new timer with id 0x%lx for agent %d, instance %d \n",
-	e->timer_id, e->agent_id, e->instance);
-  
-  return 0; 
+        e->timer_id, e->agent_id, e->instance);
+  return 0;
 }
 
-err_code_t flexran_agent_destroy_timer(long timer_id){
-  
+err_code_t flexran_agent_destroy_timer(long timer_id) {
   struct flexran_agent_timer_element_s *e = get_timer_entry(timer_id);
 
   if (e != NULL ) {
@@ -132,13 +130,12 @@ err_code_t flexran_agent_destroy_timer(long timer_id){
     flexran_agent_destroy_flexran_message(e->timer_args->msg);
     free(e);
   }
-  
-  if (timer_remove(timer_id) < 0 ) 
+
+  if (timer_remove(timer_id) < 0 )
     goto error;
-  
-  return 0;
 
- error:
+  return 0;
+error:
   LOG_E(FLEXRAN_AGENT, "timer can't be removed\n");
   return TIMER_REMOVED_FAILED ;
 }
@@ -152,66 +149,59 @@ err_code_t flexran_agent_destroy_timer_by_task_id(xid_t xid) {
       RB_REMOVE(flexran_agent_map, &timer_instance.flexran_agent_head, e);
       flexran_agent_destroy_flexran_message(e->timer_args->msg);
       free(e);
-      if (timer_remove(timer_id) < 0 ) { 
-	goto error;
+
+      if (timer_remove(timer_id) < 0 ) {
+        goto error;
       }
     }
   }
   return 0;
-
- error:
+error:
   LOG_E(FLEXRAN_AGENT, "timer can't be removed\n");
   return TIMER_REMOVED_FAILED ;
 }
 
-err_code_t flexran_agent_destroy_timers(void){
-  
+err_code_t flexran_agent_destroy_timers(void) {
   struct flexran_agent_timer_element_s *e = NULL;
-  
   RB_FOREACH(e, flexran_agent_map, &timer_instance.flexran_agent_head) {
     RB_REMOVE(flexran_agent_map, &timer_instance.flexran_agent_head, e);
     timer_remove(e->timer_id);
     flexran_agent_destroy_flexran_message(e->timer_args->msg);
     free(e);
-  }  
-
+  }
   return 0;
-
 }
 
 void flexran_agent_sleep_until(struct timespec *ts, int delay) {
   ts->tv_nsec += delay;
-  if(ts->tv_nsec >= 1000*1000*1000){
+
+  if(ts->tv_nsec >= 1000*1000*1000) {
     ts->tv_nsec -= 1000*1000*1000;
     ts->tv_sec++;
   }
+
   clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, ts,  NULL);
 }
 
 
-err_code_t flexran_agent_stop_timer(long timer_id){
-  
+err_code_t flexran_agent_stop_timer(long timer_id) {
   struct flexran_agent_timer_element_s *e=NULL;
   struct flexran_agent_timer_element_s search;
   memset(&search, 0, sizeof(struct flexran_agent_timer_element_s));
   search.timer_id = timer_id;
-
   e = RB_FIND(flexran_agent_map, &timer_instance.flexran_agent_head, &search);
 
   if (e != NULL ) {
     e->state =  FLEXRAN_AGENT_TIMER_STATE_STOPPED;
   }
-  
+
   timer_remove(timer_id);
-  
   return 0;
 }
 
-struct flexran_agent_timer_element_s * get_timer_entry(long timer_id) {
-  
+struct flexran_agent_timer_element_s *get_timer_entry(long timer_id) {
   struct flexran_agent_timer_element_s search;
   memset(&search, 0, sizeof(struct flexran_agent_timer_element_s));
   search.timer_id = timer_id;
-
-  return  RB_FIND(flexran_agent_map, &timer_instance.flexran_agent_head, &search); 
+  return  RB_FIND(flexran_agent_map, &timer_instance.flexran_agent_head, &search);
 }
diff --git a/openair2/F1AP/f1ap_du_rrc_message_transfer.c b/openair2/F1AP/f1ap_du_rrc_message_transfer.c
index 5ccfebbbd0d7776ce13be367f75cc93b754d6daa..05cc602451d27e38af80ecb01f7a1754229b08d6 100644
--- a/openair2/F1AP/f1ap_du_rrc_message_transfer.c
+++ b/openair2/F1AP/f1ap_du_rrc_message_transfer.c
@@ -38,9 +38,9 @@
 #include "f1ap_du_rrc_message_transfer.h"
 
 
-#include "DL-CCCH-Message.h"
-#include "DL-DCCH-Message.h"
-#include "UL-DCCH-Message.h"
+#include "LTE_DL-CCCH-Message.h"
+#include "LTE_DL-DCCH-Message.h"
+#include "LTE_UL-DCCH-Message.h"
 
 // for SRB1_logicalChannelConfig_defaultValue
 #include "rrc_extern.h"
@@ -77,8 +77,8 @@ int DU_handle_DL_RRC_MESSAGE_TRANSFER(instance_t       instance,
   uint64_t        srb_id;
   int             executeDuplication;
   sdu_size_t      rrc_dl_sdu_len;
-  uint64_t        subscriberProfileIDforRFP;
-  uint64_t        rAT_FrequencySelectionPriority;
+  //uint64_t        subscriberProfileIDforRFP;
+  //uint64_t        rAT_FrequencySelectionPriority;
 
   DevAssert(pdu != NULL);
 
@@ -159,10 +159,10 @@ int DU_handle_DL_RRC_MESSAGE_TRANSFER(instance_t       instance,
 
     switch(ie->value.choice.RAT_FrequencyPriorityInformation.present) {
       case F1AP_RAT_FrequencyPriorityInformation_PR_subscriberProfileIDforRFP:
-        subscriberProfileIDforRFP = ie->value.choice.RAT_FrequencyPriorityInformation.choice.subscriberProfileIDforRFP;
+        //subscriberProfileIDforRFP = ie->value.choice.RAT_FrequencyPriorityInformation.choice.subscriberProfileIDforRFP;
         break;
       case F1AP_RAT_FrequencyPriorityInformation_PR_rAT_FrequencySelectionPriority:
-        rAT_FrequencySelectionPriority = ie->value.choice.RAT_FrequencyPriorityInformation.choice.rAT_FrequencySelectionPriority;
+        //rAT_FrequencySelectionPriority = ie->value.choice.RAT_FrequencyPriorityInformation.choice.rAT_FrequencySelectionPriority;
         break;
       default:
         LOG_W(DU_F1AP, "unhandled IE RAT_FrequencyPriorityInformation.present\n");
@@ -184,35 +184,36 @@ int DU_handle_DL_RRC_MESSAGE_TRANSFER(instance_t       instance,
                                                 ctxt.rnti);
 
   if (srb_id == 0) {
-    DL_CCCH_Message_t* dl_ccch_msg=NULL;
+    LTE_DL_CCCH_Message_t* dl_ccch_msg=NULL;
     asn_dec_rval_t dec_rval;
     dec_rval = uper_decode(NULL,
-         &asn_DEF_DL_CCCH_Message,
+         &asn_DEF_LTE_DL_CCCH_Message,
          (void**)&dl_ccch_msg,
          ie->value.choice.RRCContainer.buf,
          rrc_dl_sdu_len,0,0);
+    AssertFatal(dec_rval.code == RC_OK, "could not decode F1AP message\n");
     switch (dl_ccch_msg->message.choice.c1.present) {
 
-      case DL_CCCH_MessageType__c1_PR_NOTHING:
+      case LTE_DL_CCCH_MessageType__c1_PR_NOTHING:
         LOG_I(DU_F1AP, "Received PR_NOTHING on DL-CCCH-Message\n");
         break;
 
-      case DL_CCCH_MessageType__c1_PR_rrcConnectionReestablishment:
+      case LTE_DL_CCCH_MessageType__c1_PR_rrcConnectionReestablishment:
         LOG_I(DU_F1AP,
         "Logical Channel DL-CCCH (SRB0), Received RRCConnectionReestablishment\n");
         break;
 
-      case DL_CCCH_MessageType__c1_PR_rrcConnectionReestablishmentReject:
+      case LTE_DL_CCCH_MessageType__c1_PR_rrcConnectionReestablishmentReject:
         LOG_I(DU_F1AP,
         "Logical Channel DL-CCCH (SRB0), Received RRCConnectionReestablishmentReject\n");
         break;
 
-      case DL_CCCH_MessageType__c1_PR_rrcConnectionReject:
+      case LTE_DL_CCCH_MessageType__c1_PR_rrcConnectionReject:
         LOG_I(DU_F1AP,
         "Logical Channel DL-CCCH (SRB0), Received RRCConnectionReject \n");
         break;
 
-      case DL_CCCH_MessageType__c1_PR_rrcConnectionSetup:
+      case LTE_DL_CCCH_MessageType__c1_PR_rrcConnectionSetup:
       {
         LOG_I(DU_F1AP,
           "Logical Channel DL-CCCH (SRB0), Received RRCConnectionSetup DU_ID %lx/RNTI %x\n",
@@ -220,14 +221,14 @@ int DU_handle_DL_RRC_MESSAGE_TRANSFER(instance_t       instance,
           f1ap_get_rnti_by_du_id(&f1ap_du_inst[instance], du_ue_f1ap_id));
           // Get configuration
 
-        RRCConnectionSetup_t* rrcConnectionSetup = &dl_ccch_msg->message.choice.c1.choice.rrcConnectionSetup;
+        LTE_RRCConnectionSetup_t* rrcConnectionSetup = &dl_ccch_msg->message.choice.c1.choice.rrcConnectionSetup;
         AssertFatal(rrcConnectionSetup!=NULL,"rrcConnectionSetup is null\n");
-        RadioResourceConfigDedicated_t* radioResourceConfigDedicated = &rrcConnectionSetup->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r8.radioResourceConfigDedicated;
+        LTE_RadioResourceConfigDedicated_t* radioResourceConfigDedicated = &rrcConnectionSetup->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r8.radioResourceConfigDedicated;
 
         // get SRB logical channel information
-        SRB_ToAddModList_t *SRB_configList;
-        SRB_ToAddMod_t *SRB1_config;
-        LogicalChannelConfig_t *SRB1_logicalChannelConfig;  //,*SRB2_logicalChannelConfig;
+        LTE_SRB_ToAddModList_t *SRB_configList;
+        LTE_SRB_ToAddMod_t *SRB1_config;
+        LTE_LogicalChannelConfig_t *SRB1_logicalChannelConfig;  //,*SRB2_logicalChannelConfig;
         SRB_configList                 = radioResourceConfigDedicated->srb_ToAddModList;
 
         AssertFatal(SRB_configList!=NULL,"SRB_configList is null\n");
@@ -237,7 +238,7 @@ int DU_handle_DL_RRC_MESSAGE_TRANSFER(instance_t       instance,
 
             if (SRB1_config->logicalChannelConfig) {
               if (SRB1_config->logicalChannelConfig->present ==
-                SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
+                LTE_SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
                 SRB1_logicalChannelConfig = &SRB1_config->logicalChannelConfig->choice.explicitValue;
               } else {
                 SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
@@ -249,10 +250,10 @@ int DU_handle_DL_RRC_MESSAGE_TRANSFER(instance_t       instance,
         } // for
         rrc_rlc_config_asn1_req(&ctxt,
           SRB_configList,
-          (DRB_ToAddModList_t*) NULL,
-          (DRB_ToReleaseList_t*) NULL
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-          , (PMCH_InfoList_r9_t *) NULL,
+          (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
           );
@@ -276,35 +277,35 @@ int DU_handle_DL_RRC_MESSAGE_TRANSFER(instance_t       instance,
           ctxt.module_id,
           0, //primaryCC_id,
           0,0,0,0,0,
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
           0,
 #endif
           ctxt.rnti,
-          (BCCH_BCH_Message_t *) NULL,
-          (RadioResourceConfigCommonSIB_t *) NULL,
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-          (RadioResourceConfigCommonSIB_t *) NULL,
+          (LTE_BCCH_BCH_Message_t *) NULL,
+          (LTE_RadioResourceConfigCommonSIB_t *) NULL,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+          (LTE_RadioResourceConfigCommonSIB_t *) NULL,
 #endif
           radioResourceConfigDedicated->physicalConfigDedicated,
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-          (SCellToAddMod_r10_t *)NULL,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+          (LTE_SCellToAddMod_r10_t *)NULL,
           //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
 #endif
-          (MeasObjectToAddMod_t **) NULL,
+          (LTE_MeasObjectToAddMod_t **) NULL,
           radioResourceConfigDedicated->mac_MainConfig,
           1,
           SRB1_logicalChannelConfig,
           NULL, // measGapConfig,
-          (TDD_Config_t *) NULL,
+          (LTE_TDD_Config_t *) NULL,
           NULL,
-          (SchedulingInfoList_t *) NULL,
-          0, NULL, NULL, (MBSFN_SubframeConfigList_t *) NULL
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-          , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_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 (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
           ,
-          (SystemInformationBlockType1_v1310_IEs_t *)NULL
+          (LTE_SystemInformationBlockType1_v1310_IEs_t *)NULL
 #endif
           );
           break;
@@ -318,10 +319,10 @@ int DU_handle_DL_RRC_MESSAGE_TRANSFER(instance_t       instance,
     return(0);
   } else if (srb_id == 1) { 
 
-    DL_DCCH_Message_t* dl_dcch_msg=NULL;
+    LTE_DL_DCCH_Message_t* dl_dcch_msg=NULL;
     asn_dec_rval_t dec_rval;
     dec_rval = uper_decode(NULL,
-         &asn_DEF_DL_DCCH_Message,
+         &asn_DEF_LTE_DL_DCCH_Message,
          (void**)&dl_dcch_msg,
          &ie->value.choice.RRCContainer.buf[1], // buf[0] includes the pdcp header
          rrc_dl_sdu_len,0,0);
@@ -332,38 +333,38 @@ int DU_handle_DL_RRC_MESSAGE_TRANSFER(instance_t       instance,
       LOG_D(DU_F1AP, "Received message: present %d and c1 present %d\n", 
         dl_dcch_msg->message.present, dl_dcch_msg->message.choice.c1.present);
 
-    if (dl_dcch_msg->message.present == DL_DCCH_MessageType_PR_c1) {
+    if (dl_dcch_msg->message.present == LTE_DL_DCCH_MessageType_PR_c1) {
      
       switch (dl_dcch_msg->message.choice.c1.present) {
 	
-      case DL_DCCH_MessageType__c1_PR_NOTHING:
+      case LTE_DL_DCCH_MessageType__c1_PR_NOTHING:
         LOG_I(DU_F1AP, "Received PR_NOTHING on DL-DCCH-Message\n");
         return 0;
-      case DL_DCCH_MessageType__c1_PR_dlInformationTransfer:
+      case LTE_DL_DCCH_MessageType__c1_PR_dlInformationTransfer:
         LOG_I(DU_F1AP,"Received NAS DL Information Transfer\n");
         break;	
-      case DL_DCCH_MessageType__c1_PR_csfbParametersResponseCDMA2000:
+      case LTE_DL_DCCH_MessageType__c1_PR_csfbParametersResponseCDMA2000:
         LOG_I(DU_F1AP,"Received NAS sfbParametersResponseCDMA2000\n");
         break;  
-      case DL_DCCH_MessageType__c1_PR_handoverFromEUTRAPreparationRequest:
+      case LTE_DL_DCCH_MessageType__c1_PR_handoverFromEUTRAPreparationRequest:
         LOG_I(DU_F1AP,"Received NAS andoverFromEUTRAPreparationRequest\n");
         break;  
-      case DL_DCCH_MessageType__c1_PR_mobilityFromEUTRACommand:
+      case LTE_DL_DCCH_MessageType__c1_PR_mobilityFromEUTRACommand:
         LOG_I(DU_F1AP,"Received NAS mobilityFromEUTRACommand\n");
         break;
-      case DL_DCCH_MessageType__c1_PR_rrcConnectionReconfiguration:
+      case LTE_DL_DCCH_MessageType__c1_PR_rrcConnectionReconfiguration:
 	     // handle RRCConnectionReconfiguration
         LOG_I(DU_F1AP,
 	       "Logical Channel DL-DCCH (SRB1), Received RRCConnectionReconfiguration DU_ID %lx/RNTI %x\n",
 	       du_ue_f1ap_id,
 	       f1ap_get_rnti_by_du_id(&f1ap_du_inst[instance], du_ue_f1ap_id));
 	
-        RRCConnectionReconfiguration_t* rrcConnectionReconfiguration = &dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration;
+        LTE_RRCConnectionReconfiguration_t* rrcConnectionReconfiguration = &dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration;
 
-        if (rrcConnectionReconfiguration->criticalExtensions.present == RRCConnectionReconfiguration__criticalExtensions_PR_c1) {
+        if (rrcConnectionReconfiguration->criticalExtensions.present == LTE_RRCConnectionReconfiguration__criticalExtensions_PR_c1) {
 	        if (rrcConnectionReconfiguration->criticalExtensions.choice.c1.present ==
-	         RRCConnectionReconfiguration__criticalExtensions__c1_PR_rrcConnectionReconfiguration_r8) {
-	          RRCConnectionReconfiguration_r8_IEs_t* rrcConnectionReconfiguration_r8 =
+	         LTE_RRCConnectionReconfiguration__criticalExtensions__c1_PR_rrcConnectionReconfiguration_r8) {
+	          LTE_RRCConnectionReconfiguration_r8_IEs_t* rrcConnectionReconfiguration_r8 =
 	          &rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8;
 	    
             if (rrcConnectionReconfiguration_r8->mobilityControlInfo) {
@@ -379,19 +380,19 @@ int DU_handle_DL_RRC_MESSAGE_TRANSFER(instance_t       instance,
       	      uint8_t DRB2LCHAN[8];
               long drb_id;
               int i;
-      	      DRB_ToAddModList_t*                 DRB_configList = rrcConnectionReconfiguration_r8->radioResourceConfigDedicated->drb_ToAddModList;
-              SRB_ToAddModList_t*                 SRB_configList = rrcConnectionReconfiguration_r8->radioResourceConfigDedicated->srb_ToAddModList;
-              DRB_ToReleaseList_t*                DRB_ReleaseList = rrcConnectionReconfiguration_r8->radioResourceConfigDedicated->drb_ToReleaseList;
-              MAC_MainConfig_t                    *mac_MainConfig = rrcConnectionReconfiguration_r8->radioResourceConfigDedicated->mac_MainConfig;
-              MeasGapConfig_t                    *measGapConfig = NULL;
-              struct PhysicalConfigDedicated**    physicalConfigDedicated = rrcConnectionReconfiguration_r8->radioResourceConfigDedicated->physicalConfigDedicated;
+              LTE_DRB_ToAddModList_t  *DRB_configList  = rrcConnectionReconfiguration_r8->radioResourceConfigDedicated->drb_ToAddModList;
+              LTE_SRB_ToAddModList_t  *SRB_configList  = rrcConnectionReconfiguration_r8->radioResourceConfigDedicated->srb_ToAddModList;
+              LTE_DRB_ToReleaseList_t *DRB_ReleaseList = rrcConnectionReconfiguration_r8->radioResourceConfigDedicated->drb_ToReleaseList;
+              LTE_MAC_MainConfig_t    *mac_MainConfig  = rrcConnectionReconfiguration_r8->radioResourceConfigDedicated->mac_MainConfig;
+              LTE_MeasGapConfig_t     *measGapConfig   = NULL;
+              struct LTE_PhysicalConfigDedicated**    physicalConfigDedicated = rrcConnectionReconfiguration_r8->radioResourceConfigDedicated->physicalConfigDedicated;
               rrc_rlc_config_asn1_req(
                 &ctxt,
                 SRB_configList, // NULL,  //LG-RK 14/05/2014 SRB_configList,
                 DRB_configList,
                 DRB_ReleaseList
-      #if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-                , (PMCH_InfoList_r9_t *) NULL
+      #if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+                , (LTE_PMCH_InfoList_r9_t *) NULL
                 , 0, 0
       #endif
                 );
@@ -433,35 +434,35 @@ int DU_handle_DL_RRC_MESSAGE_TRANSFER(instance_t       instance,
                     rrc_mac_config_req_eNB(
                       ctxt.module_id,
                       0,0,0,0,0,0,
-        #if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+        #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                    0,
         #endif
                    ue_context_p->ue_context.rnti,
-                   (BCCH_BCH_Message_t *) NULL,
-                   (RadioResourceConfigCommonSIB_t *) NULL,
-        #if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-                   (RadioResourceConfigCommonSIB_t *) NULL,
+                   (LTE_BCCH_BCH_Message_t *) NULL,
+                   (LTE_RadioResourceConfigCommonSIB_t *) NULL,
+        #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                   (LTE_RadioResourceConfigCommonSIB_t *) NULL,
         #endif
                    physicalConfigDedicated,
-        #if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-                   (SCellToAddMod_r10_t *)NULL,
+        #if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                   (LTE_SCellToAddMod_r10_t *)NULL,
                    //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
         #endif
-                   (MeasObjectToAddMod_t **) NULL,
+                   (LTE_MeasObjectToAddMod_t **) NULL,
                    mac_MainConfig,
                    DRB2LCHAN[i],
                    DRB_configList->list.array[i]->logicalChannelConfig,
                    measGapConfig,
-                   (TDD_Config_t *) NULL,
+                   (LTE_TDD_Config_t *) NULL,
                    NULL,
-                   (SchedulingInfoList_t *) NULL,
-                   0, NULL, NULL, (MBSFN_SubframeConfigList_t *) NULL
-        #if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-                   , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_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 (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
+        #if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
                    ,
-                   (SystemInformationBlockType1_v1310_IEs_t *)NULL
+                   (LTE_SystemInformationBlockType1_v1310_IEs_t *)NULL
         #endif
                    );
                   }
@@ -475,32 +476,32 @@ int DU_handle_DL_RRC_MESSAGE_TRANSFER(instance_t       instance,
          }
        }
 	    break;
-  	  case DL_DCCH_MessageType__c1_PR_rrcConnectionRelease:
+      case LTE_DL_DCCH_MessageType__c1_PR_rrcConnectionRelease:
   	    // handle RRCConnectionRelease
             LOG_I(DU_F1AP,"Received RRCConnectionRelease\n");
   	    break;
-  	  case DL_DCCH_MessageType__c1_PR_securityModeCommand:
+      case LTE_DL_DCCH_MessageType__c1_PR_securityModeCommand:
          LOG_I(DU_F1AP,"Received securityModeCommand\n");
           break; 
-  	  case DL_DCCH_MessageType__c1_PR_ueCapabilityEnquiry:
+      case LTE_DL_DCCH_MessageType__c1_PR_ueCapabilityEnquiry:
         LOG_I(DU_F1AP,"Received ueCapabilityEnquiry\n");
           break;
-  	  case DL_DCCH_MessageType__c1_PR_counterCheck:
-  #if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-  	  case DL_DCCH_MessageType__c1_PR_loggedMeasurementConfiguration_r10:
-  	  case DL_DCCH_MessageType__c1_PR_rnReconfiguration_r10:
+      case LTE_DL_DCCH_MessageType__c1_PR_counterCheck:
+  #if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+      case LTE_DL_DCCH_MessageType__c1_PR_loggedMeasurementConfiguration_r10:
+      case LTE_DL_DCCH_MessageType__c1_PR_rnReconfiguration_r10:
   #endif
-  	  case DL_DCCH_MessageType__c1_PR_spare1:
-  	  case DL_DCCH_MessageType__c1_PR_spare2:
-  	  case DL_DCCH_MessageType__c1_PR_spare3:
-  #if (RRC_VERSION < MAKE_VERSION(14, 0, 0))
-  	  case DL_DCCH_MessageType__c1_PR_spare4:
+      case LTE_DL_DCCH_MessageType__c1_PR_spare1:
+      case LTE_DL_DCCH_MessageType__c1_PR_spare2:
+      case LTE_DL_DCCH_MessageType__c1_PR_spare3:
+  #if (LTE_RRC_VERSION < MAKE_VERSION(14, 0, 0))
+      case LTE_DL_DCCH_MessageType__c1_PR_spare4:
   #endif
   	    break;
-      case DL_DCCH_MessageType__c1_PR_ueInformationRequest_r9:
+      case LTE_DL_DCCH_MessageType__c1_PR_ueInformationRequest_r9:
         LOG_I(DU_F1AP, "Received ueInformationRequest_r9\n");
         break;
-      case DL_DCCH_MessageType__c1_PR_rrcConnectionResume_r13:
+      case LTE_DL_DCCH_MessageType__c1_PR_rrcConnectionResume_r13:
         LOG_I(DU_F1AP, "Received rrcConnectionResume_r13\n");
 	   } 
 	 }	
@@ -542,7 +543,7 @@ int DU_handle_DL_RRC_MESSAGE_TRANSFER(instance_t       instance,
                                 );
       switch (rlc_status) {
         case RLC_OP_STATUS_OK:
-          LOG_I(DU_F1AP, "Data sending request over RLC succeeded!\n");
+          //LOG_I(DU_F1AP, "Data sending request over RLC succeeded!\n");
           ret=TRUE;
           break;
 
@@ -591,8 +592,8 @@ int DU_send_UL_RRC_MESSAGE_TRANSFER(const protocol_ctxt_t* const ctxt_pP,
   uint32_t  len;
 
 
- LOG_I(DU_F1AP,"[DU %d] Received UL_RRC_MESSAGE_TRANSFER : size %d UE RNTI %x in SRB %d\n", 
-        ctxt_pP->module_id, sdu_sizeP, rnti, rb_idP);
+  LOG_I(DU_F1AP,"[DU %d] %s: size %d UE RNTI %x in SRB %d\n",
+        ctxt_pP->module_id, __func__, sdu_sizeP, rnti, rb_idP);
 
   /* Create */
   /* 0. Message Type */
@@ -651,10 +652,10 @@ int DU_send_UL_RRC_MESSAGE_TRANSFER(const protocol_ctxt_t* const ctxt_pP,
                                                 rnti);
 
    
-    UL_DCCH_Message_t* ul_dcch_msg=NULL;
+    LTE_UL_DCCH_Message_t* ul_dcch_msg=NULL;
     asn_dec_rval_t dec_rval;
     dec_rval = uper_decode(NULL,
-         &asn_DEF_UL_DCCH_Message,
+         &asn_DEF_LTE_UL_DCCH_Message,
          (void**)&ul_dcch_msg,
          &ie->value.choice.RRCContainer.buf[1], // buf[0] includes the pdcp header
          sdu_sizeP,0,0);
@@ -665,25 +666,25 @@ int DU_send_UL_RRC_MESSAGE_TRANSFER(const protocol_ctxt_t* const ctxt_pP,
       LOG_I(DU_F1AP, "Received message: present %d and c1 present %d\n", 
         ul_dcch_msg->message.present, ul_dcch_msg->message.choice.c1.present);
 
-    if (ul_dcch_msg->message.present == UL_DCCH_MessageType_PR_c1) {
+    if (ul_dcch_msg->message.present == LTE_UL_DCCH_MessageType_PR_c1) {
 
       switch (ul_dcch_msg->message.choice.c1.present) {
-      case UL_DCCH_MessageType__c1_PR_NOTHING:   /* No components present */
+      case LTE_UL_DCCH_MessageType__c1_PR_NOTHING:   /* No components present */
         break;
 
-      case UL_DCCH_MessageType__c1_PR_csfbParametersRequestCDMA2000:
+      case LTE_UL_DCCH_MessageType__c1_PR_csfbParametersRequestCDMA2000:
         break;
 
-      case UL_DCCH_MessageType__c1_PR_measurementReport:
+      case LTE_UL_DCCH_MessageType__c1_PR_measurementReport:
         break;
 
-      case UL_DCCH_MessageType__c1_PR_rrcConnectionReconfigurationComplete:
+      case LTE_UL_DCCH_MessageType__c1_PR_rrcConnectionReconfigurationComplete:
         break;
 
-      case UL_DCCH_MessageType__c1_PR_rrcConnectionReestablishmentComplete:
+      case LTE_UL_DCCH_MessageType__c1_PR_rrcConnectionReestablishmentComplete:
         break;
 
-      case UL_DCCH_MessageType__c1_PR_rrcConnectionSetupComplete:
+      case LTE_UL_DCCH_MessageType__c1_PR_rrcConnectionSetupComplete:
         LOG_I(DU_F1AP,"[MSG] RRC UL rrcConnectionSetupComplete \n");
        if(!ue_context_p){
           LOG_E(DU_F1AP, "Did not find the UE context associated with UE RNTOI %x, ue_context_p is NULL\n", ctxt_pP->rnti);
@@ -693,43 +694,43 @@ int DU_send_UL_RRC_MESSAGE_TRANSFER(const protocol_ctxt_t* const ctxt_pP,
         }
 
         break;
-      case UL_DCCH_MessageType__c1_PR_securityModeComplete:
+      case LTE_UL_DCCH_MessageType__c1_PR_securityModeComplete:
          LOG_I(DU_F1AP,"[MSG] RRC securityModeComplete \n");
         break;
 
-      case UL_DCCH_MessageType__c1_PR_securityModeFailure:
+      case LTE_UL_DCCH_MessageType__c1_PR_securityModeFailure:
         break;
 
-      case UL_DCCH_MessageType__c1_PR_ueCapabilityInformation:
+      case LTE_UL_DCCH_MessageType__c1_PR_ueCapabilityInformation:
            LOG_I(DU_F1AP,"[MSG] RRC ueCapabilityInformation \n");
         break;
 
-      case UL_DCCH_MessageType__c1_PR_ulHandoverPreparationTransfer:
+      case LTE_UL_DCCH_MessageType__c1_PR_ulHandoverPreparationTransfer:
         break;
 
-      case UL_DCCH_MessageType__c1_PR_ulInformationTransfer:
+      case LTE_UL_DCCH_MessageType__c1_PR_ulInformationTransfer:
         LOG_I(DU_F1AP,"[MSG] RRC UL Information Transfer \n");
         break;
 
-      case UL_DCCH_MessageType__c1_PR_counterCheckResponse:
+      case LTE_UL_DCCH_MessageType__c1_PR_counterCheckResponse:
         break;
 
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
 
-      case UL_DCCH_MessageType__c1_PR_ueInformationResponse_r9:
+      case LTE_UL_DCCH_MessageType__c1_PR_ueInformationResponse_r9:
         break;
-      case UL_DCCH_MessageType__c1_PR_proximityIndication_r9:
+      case LTE_UL_DCCH_MessageType__c1_PR_proximityIndication_r9:
        break;
 #endif
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-      case UL_DCCH_MessageType__c1_PR_rnReconfigurationComplete_r10:
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+      case LTE_UL_DCCH_MessageType__c1_PR_rnReconfigurationComplete_r10:
         break;
 
-      case UL_DCCH_MessageType__c1_PR_mbmsCountingResponse_r10:
+      case LTE_UL_DCCH_MessageType__c1_PR_mbmsCountingResponse_r10:
        break;
 
-      case UL_DCCH_MessageType__c1_PR_interFreqRSTDMeasurementIndication_r10:
+      case LTE_UL_DCCH_MessageType__c1_PR_interFreqRSTDMeasurementIndication_r10:
        break;
 #endif
 
@@ -741,7 +742,6 @@ int DU_send_UL_RRC_MESSAGE_TRANSFER(const protocol_ctxt_t* const ctxt_pP,
     LOG_E(DU_F1AP, "Failed to encode F1 setup request\n");
     return -1;
   }
-  LOG_W(DU_F1AP, "DU_send_UL_RRC_MESSAGE_TRANSFER on SRB %d for UE %x \n", rb_idP, rnti);
 
   du_f1ap_itti_send_sctp_data_req(instance, f1ap_du_data->assoc_id, buffer, len, f1ap_du_data->default_sctp_stream_id);
   return 0;
diff --git a/openair2/LAYER2/MAC/config.c b/openair2/LAYER2/MAC/config.c
index 7fdb5f5943fc3804ca1010df60bfcb7f4467210b..fbe810f5361b6efd71fbb7a2061d1ce504cba302 100644
--- a/openair2/LAYER2/MAC/config.c
+++ b/openair2/LAYER2/MAC/config.c
@@ -32,16 +32,16 @@
 
 #include "COMMON/platform_types.h"
 #include "COMMON/platform_constants.h"
-#include "SystemInformationBlockType2.h"
+#include "LTE_SystemInformationBlockType2.h"
 //#include "RadioResourceConfigCommonSIB.h"
-#include "RadioResourceConfigDedicated.h"
-#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
-#include "PRACH-ConfigSIB-v1310.h"
+#include "LTE_RadioResourceConfigDedicated.h"
+#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
+#include "LTE_PRACH-ConfigSIB-v1310.h"
 #endif
-#include "MeasGapConfig.h"
-#include "MeasObjectToAddModList.h"
-#include "TDD-Config.h"
-#include "MAC-MainConfig.h"
+#include "LTE_MeasGapConfig.h"
+#include "LTE_MeasObjectToAddModList.h"
+#include "LTE_TDD-Config.h"
+#include "LTE_MAC-MainConfig.h"
 #include "mac.h"
 #include "mac_proto.h"
 #include "mac_extern.h"
@@ -49,11 +49,11 @@
 #include "common/utils/LOG/vcd_signal_dumper.h"
 
 #include "common/ran_context.h"
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-#include "MBSFN-AreaInfoList-r9.h"
-#include "MBSFN-AreaInfo-r9.h"
-#include "MBSFN-SubframeConfigList.h"
-#include "PMCH-InfoList-r9.h"
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+#include "LTE_MBSFN-AreaInfoList-r9.h"
+#include "LTE_MBSFN-AreaInfo-r9.h"
+#include "LTE_MBSFN-SubframeConfigList.h"
+#include "LTE_PMCH-InfoList-r9.h"
 #endif
 
 extern RAN_CONTEXT_t RC;
@@ -134,42 +134,37 @@ static const eutra_bandentry_t eutra_bandtable[] = {
   {68, 6980, 7280, 7530, 7830, 67536}
 };
 
-uint32_t to_earfcn(int eutra_bandP, uint32_t dl_CarrierFreq, uint32_t bw)
-{
 
+#define BANDTABLE_SIZE (sizeof(eutra_bandtable)/sizeof(eutra_bandentry_t))
+
+uint32_t to_earfcn(int eutra_bandP, uint32_t dl_CarrierFreq, uint32_t bw) {
   uint32_t dl_CarrierFreq_by_100k = dl_CarrierFreq / 100000;
   int bw_by_100 = bw / 100;
-
   int i;
-
   AssertFatal(eutra_bandP < 69, "eutra_band %d > 68\n", eutra_bandP);
-  for (i = 0; i < 69 && eutra_bandtable[i].band != eutra_bandP; i++);
+
+  for (i = 0; i < BANDTABLE_SIZE && eutra_bandtable[i].band != eutra_bandP; i++);
 
   AssertFatal(dl_CarrierFreq_by_100k >= eutra_bandtable[i].dl_min,
-	      "Band %d, bw %u : DL carrier frequency %u Hz < %u\n",
-	      eutra_bandP, bw, dl_CarrierFreq,
-	      eutra_bandtable[i].dl_min);
+              "Band %d, bw %u : DL carrier frequency %u Hz < %u\n",
+              eutra_bandP, bw, dl_CarrierFreq,
+              eutra_bandtable[i].dl_min);
   AssertFatal(dl_CarrierFreq_by_100k <=
-	      (eutra_bandtable[i].dl_max - bw_by_100),
-	      "Band %d, bw %u: DL carrier frequency %u Hz > %d\n",
-	      eutra_bandP, bw, dl_CarrierFreq,
-	      eutra_bandtable[i].dl_max - bw_by_100);
-
-
+              (eutra_bandtable[i].dl_max - bw_by_100),
+              "Band %d, bw %u: DL carrier frequency %u Hz > %d\n",
+              eutra_bandP, bw, dl_CarrierFreq,
+              eutra_bandtable[i].dl_max - bw_by_100);
   return (dl_CarrierFreq_by_100k - eutra_bandtable[i].dl_min +
-	  (eutra_bandtable[i].N_OFFs_DL / 10));
+          (eutra_bandtable[i].N_OFFs_DL / 10));
 }
 
-uint32_t to_earfcn_DL(int eutra_bandP, long long int dl_CarrierFreq, uint32_t bw)
-{
-
+uint32_t to_earfcn_DL(int eutra_bandP, long long int dl_CarrierFreq, uint32_t bw) {
   uint32_t dl_CarrierFreq_by_100k = dl_CarrierFreq / 100000;
   int bw_by_100 = bw / 100;
-
   int i;
-
   AssertFatal(eutra_bandP < 69, "eutra_band %d > 68\n", eutra_bandP);
-  for (i = 0; i < 69 && eutra_bandtable[i].band != eutra_bandP; i++);
+
+  for (i = 0; i < BANDTABLE_SIZE && eutra_bandtable[i].band != eutra_bandP; i++);
 
   AssertFatal(dl_CarrierFreq_by_100k >= eutra_bandtable[i].dl_min,
               "Band %d, bw %u : DL carrier frequency %lld Hz < %u\n",
@@ -180,22 +175,17 @@ uint32_t to_earfcn_DL(int eutra_bandP, long long int dl_CarrierFreq, uint32_t bw
               "Band %d, bw %u : DL carrier frequency %lld Hz > %d\n",
               eutra_bandP, bw, dl_CarrierFreq,
               eutra_bandtable[i].dl_max - bw_by_100);
-
-
   return (dl_CarrierFreq_by_100k - eutra_bandtable[i].dl_min +
           (eutra_bandtable[i].N_OFFs_DL / 10));
 }
 
-uint32_t to_earfcn_UL(int eutra_bandP, long long int ul_CarrierFreq, uint32_t bw)
-{
-
+uint32_t to_earfcn_UL(int eutra_bandP, long long int ul_CarrierFreq, uint32_t bw) {
   uint32_t ul_CarrierFreq_by_100k = ul_CarrierFreq / 100000;
   int bw_by_100 = bw / 100;
-
   int i;
-
   AssertFatal(eutra_bandP < 69, "eutra_band %d > 68\n", eutra_bandP);
-  for (i = 0; i < 69 && eutra_bandtable[i].band != eutra_bandP; i++);
+
+  for (i = 0; i < BANDTABLE_SIZE && eutra_bandtable[i].band != eutra_bandP; i++);
 
   AssertFatal(ul_CarrierFreq_by_100k >= eutra_bandtable[i].ul_min,
               "Band %d, bw %u : UL carrier frequency %lld Hz < %u\n",
@@ -206,30 +196,26 @@ uint32_t to_earfcn_UL(int eutra_bandP, long long int ul_CarrierFreq, uint32_t bw
               "Band %d, bw %u : UL carrier frequency %lld Hz > %d\n",
               eutra_bandP, bw, ul_CarrierFreq,
               eutra_bandtable[i].ul_max - bw_by_100);
-
-
   return (ul_CarrierFreq_by_100k - eutra_bandtable[i].ul_min +
           ((eutra_bandtable[i].N_OFFs_DL + 180000) / 10));
 }
 
-uint32_t from_earfcn(int eutra_bandP, uint32_t dl_earfcn)
-{
-
+uint32_t from_earfcn(int eutra_bandP, uint32_t dl_earfcn) {
   int i;
-
   AssertFatal(eutra_bandP < 69, "eutra_band %d > 68\n", eutra_bandP);
-  for (i = 0; i < 69 && eutra_bandtable[i].band != eutra_bandP; i++);
+
+  for (i = 0; i < BANDTABLE_SIZE && eutra_bandtable[i].band != eutra_bandP; i++);
 
   return (eutra_bandtable[i].dl_min +
-	  (dl_earfcn - (eutra_bandtable[i].N_OFFs_DL / 10))) * 100000;
+          (dl_earfcn - (eutra_bandtable[i].N_OFFs_DL / 10))) * 100000;
 }
 
 
-int32_t get_uldl_offset(int eutra_bandP)
-{
+int32_t get_uldl_offset(int eutra_bandP) {
   int i;
 
-  for (i = 0; i < 69 && eutra_bandtable[i].band != eutra_bandP; i++);
+  for (i = 0; i < BANDTABLE_SIZE && eutra_bandtable[i].band != eutra_bandP; i++);
+
   return (eutra_bandtable[i].dl_min - eutra_bandtable[i].ul_min);
 }
 
@@ -239,13 +225,13 @@ void config_mib(int                 Mod_idP,
 		int                 CC_idP,
 		int                 eutra_bandP,  
 		int                 dl_BandwidthP,
-		PHICH_Config_t      *phich_configP,
+		LTE_PHICH_Config_t  *phich_configP,
 		int                 Nid_cellP,
 		int                 NcpP,
 		int                 p_eNBP,
 		uint32_t            dl_CarrierFreqP,
 		uint32_t            ul_CarrierFreqP
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                 ,
 		uint32_t            pbch_repetitionP
 #endif
@@ -317,14 +303,14 @@ void config_mib(int                 Mod_idP,
   cfg->sch_config.physical_cell_id.tl.tag = NFAPI_SCH_CONFIG_PHYSICAL_CELL_ID_TAG;
   cfg->num_tlv++;
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   cfg->emtc_config.pbch_repetitions_enable_r13.value                 = pbch_repetitionP;
   cfg->emtc_config.pbch_repetitions_enable_r13.tl.tag = NFAPI_EMTC_CONFIG_PBCH_REPETITIONS_ENABLE_R13_TAG;
   cfg->num_tlv++;
 #endif  
   LOG_I(MAC,
 	"%s() NFAPI_CONFIG_REQUEST(num_tlv:%u) DL_BW:%u UL_BW:%u Ncp %d,p_eNB %d,earfcn %d,band %d,phich_resource %u phich_duration %u phich_power_offset %u PSS %d SSS %d PCI %d"
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 	
 	" PBCH repetition %d"
 #endif  
@@ -342,13 +328,13 @@ void config_mib(int                 Mod_idP,
 	,cfg->sch_config.primary_synchronization_signal_epre_eprers.value
 	,cfg->sch_config.secondary_synchronization_signal_epre_eprers.value
 	,cfg->sch_config.physical_cell_id.value
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 	,cfg->emtc_config.pbch_repetitions_enable_r13.value
 #endif  
       );
 }
 
-void config_sib1(int Mod_idP, int CC_idP, TDD_Config_t * tdd_ConfigP)
+void config_sib1(int Mod_idP, int CC_idP, LTE_TDD_Config_t * tdd_ConfigP)
 {
 
 
@@ -380,14 +366,14 @@ int power_off_dB[6] = { 78, 118, 140, 170, 188, 200 };
 void
 config_sib2(int Mod_idP,
 	    int CC_idP,
-	    RadioResourceConfigCommonSIB_t * radioResourceConfigCommonP,
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-	    RadioResourceConfigCommonSIB_t * radioResourceConfigCommon_BRP,
+	    LTE_RadioResourceConfigCommonSIB_t * radioResourceConfigCommonP,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+	    LTE_RadioResourceConfigCommonSIB_t * radioResourceConfigCommon_BRP,
 #endif
-            ARFCN_ValueEUTRA_t *ul_CArrierFreqP,
+            LTE_ARFCN_ValueEUTRA_t *ul_CArrierFreqP,
             long *ul_BandwidthP,
-            AdditionalSpectrumEmission_t *additionalSpectrumEmissionP,
-            struct MBSFN_SubframeConfigList  *mbsfn_SubframeConfigListP) {
+            LTE_AdditionalSpectrumEmission_t *additionalSpectrumEmissionP,
+            struct LTE_MBSFN_SubframeConfigList  *mbsfn_SubframeConfigListP) {
 
   nfapi_config_request_t *cfg = &RC.mac[Mod_idP]->config[CC_idP];
 
@@ -474,7 +460,7 @@ config_sib2(int Mod_idP,
 
 
   // how to enable/disable SRS?
-  if (radioResourceConfigCommonP->soundingRS_UL_ConfigCommon.present==SoundingRS_UL_ConfigCommon_PR_setup) {
+  if (radioResourceConfigCommonP->soundingRS_UL_ConfigCommon.present== LTE_SoundingRS_UL_ConfigCommon_PR_setup) {
     cfg->srs_config.bandwidth_configuration.value                       = radioResourceConfigCommonP->soundingRS_UL_ConfigCommon.choice.setup.srs_BandwidthConfig;
     cfg->srs_config.bandwidth_configuration.tl.tag = NFAPI_SRS_CONFIG_BANDWIDTH_CONFIGURATION_TAG;
     cfg->num_tlv++;
@@ -497,7 +483,7 @@ config_sib2(int Mod_idP,
     cfg->num_tlv++;
   }
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   if (RC.mac[Mod_idP]->common_channels[CC_idP].mib->message.schedulingInfoSIB1_BR_r13 > 0) {
     AssertFatal(radioResourceConfigCommon_BRP != NULL, "radioResource rou is missing\n");
     AssertFatal(radioResourceConfigCommon_BRP->ext4 != NULL, "ext4 is missing\n");
@@ -513,11 +499,11 @@ config_sib2(int Mod_idP,
     cfg->emtc_config.prach_catm_high_speed_flag.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CATM_HIGH_SPEED_FLAG;
     cfg->num_tlv++;
 
-    struct PRACH_ConfigSIB_v1310 *ext4_prach = radioResourceConfigCommon_BRP->ext4->prach_ConfigCommon_v1310;
+    struct LTE_PRACH_ConfigSIB_v1310 *ext4_prach = radioResourceConfigCommon_BRP->ext4->prach_ConfigCommon_v1310;
 
-    PRACH_ParametersListCE_r13_t *prach_ParametersListCE_r13 = &ext4_prach->prach_ParametersListCE_r13;
+    LTE_PRACH_ParametersListCE_r13_t *prach_ParametersListCE_r13 = &ext4_prach->prach_ParametersListCE_r13;
 
-    PRACH_ParametersCE_r13_t *p;
+    LTE_PRACH_ParametersCE_r13_t *p;
     cfg->emtc_config.prach_ce_level_0_enable.value = 0;
     cfg->emtc_config.prach_ce_level_0_enable.tl.tag=NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_0_ENABLE_TAG;
     cfg->num_tlv++;
@@ -534,6 +520,7 @@ config_sib2(int Mod_idP,
     cfg->emtc_config.prach_ce_level_3_enable.tl.tag=NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_3_ENABLE_TAG;
     cfg->num_tlv++;
 
+
     switch (prach_ParametersListCE_r13->list.count) {
     case 4:
       p = prach_ParametersListCE_r13->list.array[3];
@@ -549,16 +536,17 @@ config_sib2(int Mod_idP,
       cfg->emtc_config.prach_ce_level_3_frequency_offset.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_3_FREQUENCY_OFFSET_TAG;
       cfg->num_tlv++;
 
-      cfg->emtc_config.prach_ce_level_3_number_of_repetitions_per_attempt.value = p->numRepetitionPerPreambleAttempt_r13;
+      cfg->emtc_config.prach_ce_level_3_number_of_repetitions_per_attempt.value = 1<<p->numRepetitionPerPreambleAttempt_r13;
       cfg->emtc_config.prach_ce_level_3_number_of_repetitions_per_attempt.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_3_NUMBER_OF_REPETITIONS_PER_ATTEMPT_TAG;
       cfg->num_tlv++;
 
       if (p->prach_StartingSubframe_r13) {
-	cfg->emtc_config.prach_ce_level_3_starting_subframe_periodicity.value   = *p->prach_StartingSubframe_r13;
+	cfg->emtc_config.prach_ce_level_3_starting_subframe_periodicity.value   = 2<<*p->prach_StartingSubframe_r13;
         cfg->emtc_config.prach_ce_level_3_starting_subframe_periodicity.tl.tag  = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_3_STARTING_SUBFRAME_PERIODICITY_TAG;
         cfg->num_tlv++;
       }
 
+
       cfg->emtc_config.prach_ce_level_3_hopping_enable.value                    = p->prach_HoppingConfig_r13;
       cfg->emtc_config.prach_ce_level_3_hopping_enable.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_3_HOPPING_ENABLE_TAG;
       cfg->num_tlv++;
@@ -581,12 +569,12 @@ config_sib2(int Mod_idP,
       cfg->emtc_config.prach_ce_level_2_frequency_offset.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_2_FREQUENCY_OFFSET_TAG;
       cfg->num_tlv++;
 
-      cfg->emtc_config.prach_ce_level_2_number_of_repetitions_per_attempt.value = p->numRepetitionPerPreambleAttempt_r13;
+      cfg->emtc_config.prach_ce_level_2_number_of_repetitions_per_attempt.value = 1<<p->numRepetitionPerPreambleAttempt_r13;
       cfg->emtc_config.prach_ce_level_2_number_of_repetitions_per_attempt.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_2_NUMBER_OF_REPETITIONS_PER_ATTEMPT_TAG;
       cfg->num_tlv++;
 
       if (p->prach_StartingSubframe_r13) {
-	cfg->emtc_config.prach_ce_level_2_starting_subframe_periodicity.value   = *p->prach_StartingSubframe_r13;
+	cfg->emtc_config.prach_ce_level_2_starting_subframe_periodicity.value   = 2<<*p->prach_StartingSubframe_r13;
         cfg->emtc_config.prach_ce_level_2_starting_subframe_periodicity.tl.tag  = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_2_STARTING_SUBFRAME_PERIODICITY_TAG;
         cfg->num_tlv++;
       }
@@ -613,12 +601,12 @@ config_sib2(int Mod_idP,
       cfg->emtc_config.prach_ce_level_1_frequency_offset.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_1_FREQUENCY_OFFSET_TAG;
       cfg->num_tlv++;
 
-      cfg->emtc_config.prach_ce_level_1_number_of_repetitions_per_attempt.value = p->numRepetitionPerPreambleAttempt_r13;
+      cfg->emtc_config.prach_ce_level_1_number_of_repetitions_per_attempt.value = 1<<p->numRepetitionPerPreambleAttempt_r13;
       cfg->emtc_config.prach_ce_level_1_number_of_repetitions_per_attempt.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_1_NUMBER_OF_REPETITIONS_PER_ATTEMPT_TAG;
       cfg->num_tlv++;
 
       if (p->prach_StartingSubframe_r13) {
-	cfg->emtc_config.prach_ce_level_1_starting_subframe_periodicity.value   = *p->prach_StartingSubframe_r13;
+	cfg->emtc_config.prach_ce_level_1_starting_subframe_periodicity.value   = 2<<*p->prach_StartingSubframe_r13;
         cfg->emtc_config.prach_ce_level_1_starting_subframe_periodicity.tl.tag  = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_1_STARTING_SUBFRAME_PERIODICITY_TAG;
         cfg->num_tlv++;
       }
@@ -645,12 +633,12 @@ config_sib2(int Mod_idP,
       cfg->emtc_config.prach_ce_level_0_frequency_offset.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_0_FREQUENCY_OFFSET_TAG;
       cfg->num_tlv++;
 
-      cfg->emtc_config.prach_ce_level_0_number_of_repetitions_per_attempt.value = p->numRepetitionPerPreambleAttempt_r13;
+      cfg->emtc_config.prach_ce_level_0_number_of_repetitions_per_attempt.value = 1<<p->numRepetitionPerPreambleAttempt_r13;
       cfg->emtc_config.prach_ce_level_0_number_of_repetitions_per_attempt.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_0_NUMBER_OF_REPETITIONS_PER_ATTEMPT_TAG;
       cfg->num_tlv++;
 
       if (p->prach_StartingSubframe_r13) {
-	cfg->emtc_config.prach_ce_level_0_starting_subframe_periodicity.value   = *p->prach_StartingSubframe_r13;
+	cfg->emtc_config.prach_ce_level_0_starting_subframe_periodicity.value   = 2<<*p->prach_StartingSubframe_r13;
         cfg->emtc_config.prach_ce_level_0_starting_subframe_periodicity.tl.tag  = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_0_STARTING_SUBFRAME_PERIODICITY_TAG;
         cfg->num_tlv++;
       }
@@ -664,18 +652,21 @@ config_sib2(int Mod_idP,
       cfg->num_tlv++;
     }
 
-    struct FreqHoppingParameters_r13 *ext4_freqHoppingParameters = radioResourceConfigCommonP->ext4->freqHoppingParameters_r13;
+
+    AssertFatal(cfg->emtc_config.prach_ce_level_0_enable.value>0,"CE_level0 is not enabled\n");
+
+    struct LTE_FreqHoppingParameters_r13 *ext4_freqHoppingParameters = radioResourceConfigCommonP->ext4->freqHoppingParameters_r13;
     if ((ext4_freqHoppingParameters) &&
         (ext4_freqHoppingParameters->interval_ULHoppingConfigCommonModeA_r13)){
       switch(ext4_freqHoppingParameters->interval_ULHoppingConfigCommonModeA_r13->present) {
-      case      FreqHoppingParameters_r13__interval_ULHoppingConfigCommonModeA_r13_PR_NOTHING:  /* No components present */
+      case LTE_FreqHoppingParameters_r13__interval_ULHoppingConfigCommonModeA_r13_PR_NOTHING:  /* No components present */
         break;
-      case FreqHoppingParameters_r13__interval_ULHoppingConfigCommonModeA_r13_PR_interval_FDD_r13:
+      case LTE_FreqHoppingParameters_r13__interval_ULHoppingConfigCommonModeA_r13_PR_interval_FDD_r13:
         cfg->emtc_config.pucch_interval_ulhoppingconfigcommonmodea.value = ext4_freqHoppingParameters->interval_ULHoppingConfigCommonModeA_r13->choice.interval_FDD_r13;
         cfg->emtc_config.pucch_interval_ulhoppingconfigcommonmodea.tl.tag = NFAPI_EMTC_CONFIG_PUCCH_INTERVAL_ULHOPPINGCONFIGCOMMONMODEA_TAG;
         cfg->num_tlv++;
         break;
-      case FreqHoppingParameters_r13__interval_ULHoppingConfigCommonModeA_r13_PR_interval_TDD_r13:
+      case LTE_FreqHoppingParameters_r13__interval_ULHoppingConfigCommonModeA_r13_PR_interval_TDD_r13:
         cfg->emtc_config.pucch_interval_ulhoppingconfigcommonmodea.value = ext4_freqHoppingParameters->interval_ULHoppingConfigCommonModeA_r13->choice.interval_TDD_r13;
         cfg->emtc_config.pucch_interval_ulhoppingconfigcommonmodea.tl.tag = NFAPI_EMTC_CONFIG_PUCCH_INTERVAL_ULHOPPINGCONFIGCOMMONMODEA_TAG;
         cfg->num_tlv++;
@@ -685,14 +676,14 @@ config_sib2(int Mod_idP,
     if ((ext4_freqHoppingParameters) &&
         (ext4_freqHoppingParameters->interval_ULHoppingConfigCommonModeB_r13)){
       switch(ext4_freqHoppingParameters->interval_ULHoppingConfigCommonModeB_r13->present) {
-      case      FreqHoppingParameters_r13__interval_ULHoppingConfigCommonModeB_r13_PR_NOTHING:  /* No components present */
+      case LTE_FreqHoppingParameters_r13__interval_ULHoppingConfigCommonModeB_r13_PR_NOTHING:  /* No components present */
         break;
-      case FreqHoppingParameters_r13__interval_ULHoppingConfigCommonModeB_r13_PR_interval_FDD_r13:
+      case LTE_FreqHoppingParameters_r13__interval_ULHoppingConfigCommonModeB_r13_PR_interval_FDD_r13:
         cfg->emtc_config.pucch_interval_ulhoppingconfigcommonmodeb.value = ext4_freqHoppingParameters->interval_ULHoppingConfigCommonModeB_r13->choice.interval_FDD_r13;
         cfg->emtc_config.pucch_interval_ulhoppingconfigcommonmodeb.tl.tag = NFAPI_EMTC_CONFIG_PUCCH_INTERVAL_ULHOPPINGCONFIGCOMMONMODEB_TAG;
         cfg->num_tlv++;
         break;
-      case FreqHoppingParameters_r13__interval_ULHoppingConfigCommonModeB_r13_PR_interval_TDD_r13:
+      case LTE_FreqHoppingParameters_r13__interval_ULHoppingConfigCommonModeB_r13_PR_interval_TDD_r13:
         cfg->emtc_config.pucch_interval_ulhoppingconfigcommonmodeb.value = ext4_freqHoppingParameters->interval_ULHoppingConfigCommonModeB_r13->choice.interval_TDD_r13;
         cfg->emtc_config.pucch_interval_ulhoppingconfigcommonmodeb.tl.tag = NFAPI_EMTC_CONFIG_PUCCH_INTERVAL_ULHOPPINGCONFIGCOMMONMODEB_TAG;
         cfg->num_tlv++;
@@ -708,7 +699,7 @@ void
 config_dedicated(int Mod_idP,
 		 int CC_idP,
 		 uint16_t rnti,
-		 struct PhysicalConfigDedicated *physicalConfigDedicated)
+		 struct LTE_PhysicalConfigDedicated *physicalConfigDedicated)
 {
 
 }
@@ -716,61 +707,60 @@ config_dedicated(int Mod_idP,
 void
 config_dedicated_scell(int Mod_idP,
 		       uint16_t rnti,
-		       SCellToAddMod_r10_t * sCellToAddMod_r10)
+		       LTE_SCellToAddMod_r10_t * sCellToAddMod_r10)
 {
 
 }
 
 
-int
-rrc_mac_config_req_eNB(module_id_t Mod_idP,
-		       int CC_idP,
-		       int physCellId,
-		       int p_eNB,
-		       int Ncp, int eutra_band, uint32_t dl_CarrierFreq,
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-		       int pbch_repetition,
+int rrc_mac_config_req_eNB(module_id_t Mod_idP,
+			   int CC_idP,
+			   int physCellId,
+			   int p_eNB,
+			   int Ncp, int eutra_band, uint32_t dl_CarrierFreq,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+			   int pbch_repetition,
 #endif
-		       rnti_t rntiP,
-		       BCCH_BCH_Message_t * mib,
-		       RadioResourceConfigCommonSIB_t *
-		       radioResourceConfigCommon,
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-		       RadioResourceConfigCommonSIB_t *
-		       radioResourceConfigCommon_BR,
+			   rnti_t rntiP,
+			   LTE_BCCH_BCH_Message_t * mib,
+			   LTE_RadioResourceConfigCommonSIB_t *
+			   radioResourceConfigCommon,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+			   LTE_RadioResourceConfigCommonSIB_t *
+			   radioResourceConfigCommon_BR,
 #endif
-		       struct PhysicalConfigDedicated
-		       *physicalConfigDedicated,
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-		       SCellToAddMod_r10_t * sCellToAddMod_r10,
-		       //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
+			   struct LTE_PhysicalConfigDedicated
+			   *physicalConfigDedicated,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+			   LTE_SCellToAddMod_r10_t * sCellToAddMod_r10,
+			   //struct LTE_PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
 #endif
-		       MeasObjectToAddMod_t ** measObj,
-		       MAC_MainConfig_t * mac_MainConfig,
-		       long logicalChannelIdentity,
-		       LogicalChannelConfig_t * logicalChannelConfig,
-		       MeasGapConfig_t * measGapConfig,
-		       TDD_Config_t * tdd_Config,
-		       MobilityControlInfo_t * mobilityControlInfo,
-		       SchedulingInfoList_t * schedulingInfoList,
-		       uint32_t ul_CarrierFreq,
-		       long *ul_Bandwidth,
-		       AdditionalSpectrumEmission_t *
-		       additionalSpectrumEmission,
-		       struct MBSFN_SubframeConfigList
-		       *mbsfn_SubframeConfigList
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-		       , uint8_t MBMS_Flag,
-		       MBSFN_AreaInfoList_r9_t * mbsfn_AreaInfoList,
-		       PMCH_InfoList_r9_t * pmch_InfoList
+			   LTE_MeasObjectToAddMod_t ** measObj,
+			   LTE_MAC_MainConfig_t * mac_MainConfig,
+			   long logicalChannelIdentity,
+			   LTE_LogicalChannelConfig_t * logicalChannelConfig,
+			   LTE_MeasGapConfig_t * measGapConfig,
+			   LTE_TDD_Config_t * tdd_Config,
+			   LTE_MobilityControlInfo_t * mobilityControlInfo,
+			   LTE_SchedulingInfoList_t * schedulingInfoList,
+			   uint32_t ul_CarrierFreq,
+			   long *ul_Bandwidth,
+			   LTE_AdditionalSpectrumEmission_t *
+			   additionalSpectrumEmission,
+			   struct LTE_MBSFN_SubframeConfigList
+			   *mbsfn_SubframeConfigList
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+			   , uint8_t MBMS_Flag,
+			   LTE_MBSFN_AreaInfoList_r9_t * mbsfn_AreaInfoList,
+			   LTE_PMCH_InfoList_r9_t * pmch_InfoList
 #endif
-#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
-		       ,
-		       SystemInformationBlockType1_v1310_IEs_t *
-		       sib1_v13ext
+#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
+			   ,
+			   LTE_SystemInformationBlockType1_v1310_IEs_t *
+			   sib1_v13ext
 #endif
-                       ) {
-			   
+			   ) {
+
   int i;
 
   int UE_id = -1;
@@ -815,7 +805,7 @@ rrc_mac_config_req_eNB(module_id_t Mod_idP,
 	       p_eNB,
 	       dl_CarrierFreq,
 	       ul_CarrierFreq
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 	       , pbch_repetition
 #endif
 	       );
@@ -827,7 +817,7 @@ rrc_mac_config_req_eNB(module_id_t Mod_idP,
       RC.mac[Mod_idP]->common_channels[CC_idP].schedulingInfoList = schedulingInfoList;    
       config_sib1(Mod_idP,CC_idP,tdd_Config);
     }
-#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
     if (sib1_v13ext != NULL) {
       RC.mac[Mod_idP]->common_channels[CC_idP].sib1_v13ext = sib1_v13ext;
     }
@@ -835,127 +825,100 @@ rrc_mac_config_req_eNB(module_id_t Mod_idP,
     AssertFatal(radioResourceConfigCommon != NULL, "radioResourceConfigCommon is null\n");
     LOG_I(MAC, "[CONFIG]SIB2/3 Contents (partial)\n");
     LOG_I(MAC, "[CONFIG]pusch_config_common.n_SB = %ld\n",
-	  radioResourceConfigCommon->
-	  pusch_ConfigCommon.pusch_ConfigBasic.n_SB);
+	        radioResourceConfigCommon->pusch_ConfigCommon.pusch_ConfigBasic.n_SB);
     LOG_I(MAC, "[CONFIG]pusch_config_common.hoppingMode = %ld\n",
-	  radioResourceConfigCommon->
-	  pusch_ConfigCommon.pusch_ConfigBasic.hoppingMode);
-    LOG_I(MAC,
-	  "[CONFIG]pusch_config_common.pusch_HoppingOffset = %ld\n",
-	  radioResourceConfigCommon->
-	  pusch_ConfigCommon.pusch_ConfigBasic.pusch_HoppingOffset);
+	        radioResourceConfigCommon->pusch_ConfigCommon.pusch_ConfigBasic.hoppingMode);
+    LOG_I(MAC, "[CONFIG]pusch_config_common.pusch_HoppingOffset = %ld\n",
+          radioResourceConfigCommon->pusch_ConfigCommon.pusch_ConfigBasic.pusch_HoppingOffset);
     LOG_I(MAC, "[CONFIG]pusch_config_common.enable64QAM = %d\n",
-	  radioResourceConfigCommon->
-	  pusch_ConfigCommon.pusch_ConfigBasic.enable64QAM);
-    LOG_I(MAC,
-	  "[CONFIG]pusch_config_common.groupHoppingEnabled = %d\n",
-	  radioResourceConfigCommon->
-	  pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.
-	  groupHoppingEnabled);
-    LOG_I(MAC,
-	  "[CONFIG]pusch_config_common.groupAssignmentPUSCH = %ld\n",
-	  radioResourceConfigCommon->
-	  pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.
-	  groupAssignmentPUSCH);
-    LOG_I(MAC,
-	  "[CONFIG]pusch_config_common.sequenceHoppingEnabled = %d\n",
-	  radioResourceConfigCommon->
-	  pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.
-	  sequenceHoppingEnabled);
+          radioResourceConfigCommon->pusch_ConfigCommon.pusch_ConfigBasic.enable64QAM);
+    LOG_I(MAC, "[CONFIG]pusch_config_common.groupHoppingEnabled = %d\n",
+	        radioResourceConfigCommon->pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.groupHoppingEnabled);
+    LOG_I(MAC, "[CONFIG]pusch_config_common.groupAssignmentPUSCH = %ld\n",
+          radioResourceConfigCommon->pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH);
+    LOG_I(MAC, "[CONFIG]pusch_config_common.sequenceHoppingEnabled = %d\n",
+	        radioResourceConfigCommon->pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled);
     LOG_I(MAC, "[CONFIG]pusch_config_common.cyclicShift  = %ld\n",
-	  radioResourceConfigCommon->
-	  pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.cyclicShift);
+          radioResourceConfigCommon->pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.cyclicShift);
     
-    AssertFatal(radioResourceConfigCommon->
-		rach_ConfigCommon.maxHARQ_Msg3Tx > 0,
-		"radioResourceconfigCommon %d == 0\n",
-		(int) radioResourceConfigCommon->
-		rach_ConfigCommon.maxHARQ_Msg3Tx);
+    AssertFatal(radioResourceConfigCommon->rach_ConfigCommon.maxHARQ_Msg3Tx > 0,
+                "radioResourceconfigCommon %d == 0\n",
+		            (int) radioResourceConfigCommon->rach_ConfigCommon.maxHARQ_Msg3Tx);
     
-    RC.mac[Mod_idP]->common_channels[CC_idP].
-      radioResourceConfigCommon = radioResourceConfigCommon;
-    if (ul_CarrierFreq > 0)
-      RC.mac[Mod_idP]->common_channels[CC_idP].ul_CarrierFreq =
-	ul_CarrierFreq;
-    if (ul_Bandwidth)
-      RC.mac[Mod_idP]->common_channels[CC_idP].ul_Bandwidth =
-	*ul_Bandwidth;
-    else
-      RC.mac[Mod_idP]->common_channels[CC_idP].ul_Bandwidth =
-	RC.mac[Mod_idP]->common_channels[CC_idP].mib->message.
-	dl_Bandwidth;
+    RC.mac[Mod_idP]->common_channels[CC_idP].radioResourceConfigCommon = radioResourceConfigCommon;
+    RC.mac[Mod_idP]->common_channels[CC_idP].radioResourceConfigCommon_BR = radioResourceConfigCommon_BR;
+    if (ul_CarrierFreq > 0) RC.mac[Mod_idP]->common_channels[CC_idP].ul_CarrierFreq = ul_CarrierFreq;
+    if (ul_Bandwidth) RC.mac[Mod_idP]->common_channels[CC_idP].ul_Bandwidth = *ul_Bandwidth;
+    else RC.mac[Mod_idP]->common_channels[CC_idP].ul_Bandwidth = RC.mac[Mod_idP]->common_channels[CC_idP].mib->message.dl_Bandwidth;
     
     config_sib2(Mod_idP, CC_idP, radioResourceConfigCommon,
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-		radioResourceConfigCommon_BR,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                radioResourceConfigCommon_BR,
 #endif
-		NULL, ul_Bandwidth, additionalSpectrumEmission,
-		mbsfn_SubframeConfigList);
+                NULL, ul_Bandwidth, additionalSpectrumEmission,
+                mbsfn_SubframeConfigList);
     
   } // mib != NULL
 
+  if (mobilityControlInfo !=NULL){
+     if ((UE_id = add_new_ue(Mod_idP, CC_idP,
+                             rntiP, -1
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                             ,
+                             -1
+#endif
+                             )) == -1)
+     {
+       LOG_E(MAC, "%s:%d: fatal\n", __FILE__, __LINE__);
+       abort();
+     }
+  }
+
   // SRB2_lchan_config->choice.explicitValue.ul_SpecificParameters->logicalChannelGroup
   if (logicalChannelConfig != NULL) {	// check for eMTC specific things
     UE_id = find_UE_id(Mod_idP, rntiP);
 
-    if (UE_id == -1) {
-      LOG_E(MAC, "%s:%d:%s: ERROR, UE_id == -1\n", __FILE__,
-	    __LINE__, __FUNCTION__);
-    } else {
-		if (logicalChannelConfig) {
-        UE_list->
-          UE_template[CC_idP][UE_id].lcgidmap
-          [logicalChannelIdentity] =
-          *logicalChannelConfig->
-			ul_SpecificParameters->logicalChannelGroup;
-		UE_list->
-          UE_template[CC_idP][UE_id].lcgidpriority
-          [logicalChannelIdentity]=
-			logicalChannelConfig->ul_SpecificParameters->priority;
-
-		} else
-			UE_list->
-				UE_template[CC_idP][UE_id].lcgidmap
-				[logicalChannelIdentity] = 0;
+    if (UE_id<0) {
+      LOG_E(MAC,"Configuration received for unknown UE (%x), shouldn't happen\n",rntiP);
+      return(-1);
     }
+    if (logicalChannelConfig) {
+        UE_list->UE_template[CC_idP][UE_id].lcgidmap[logicalChannelIdentity]      = *logicalChannelConfig->ul_SpecificParameters->logicalChannelGroup;
+	UE_list->UE_template[CC_idP][UE_id].lcgidpriority[logicalChannelIdentity] =  logicalChannelConfig->ul_SpecificParameters->priority;
+    } else UE_list->UE_template[CC_idP][UE_id].lcgidmap[logicalChannelIdentity]   =  0;
   }
 
-
   if (physicalConfigDedicated != NULL) {
     UE_id = find_UE_id(Mod_idP, rntiP);
-
-    if (UE_id == -1)
-      LOG_E(MAC, "%s:%d:%s: ERROR, UE_id == -1\n", __FILE__, __LINE__, __FUNCTION__);
-    else
-      UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated = physicalConfigDedicated;
+    if (UE_id<0) {
+      LOG_E(MAC,"Configuration received for unknown UE (%x), shouldn't happen\n",rntiP);
+      return(-1);
+    }
+    UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated = physicalConfigDedicated;
+    LOG_I(MAC,"Added physicalConfigDedicated %p for %d.%d\n",physicalConfigDedicated,CC_idP,UE_id);
   }
 
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 
   if (sCellToAddMod_r10 != NULL) {
-    UE_id = find_UE_id(Mod_idP, rntiP);
-    if (UE_id == -1)
-      LOG_E(MAC, "%s:%d:%s: ERROR, UE_id == -1\n", __FILE__,
-	    __LINE__, __FUNCTION__);
-    else
-      config_dedicated_scell(Mod_idP, rntiP, sCellToAddMod_r10);
+    if (UE_id<0) {
+      LOG_E(MAC,"Configuration received for unknown UE (%x), shouldn't happen\n",rntiP);
+      return(-1);
+    }
+    AssertFatal(UE_id>=0,"Configuration received for unknown UE (%x), shouldn't happen\n",rntiP);
+    config_dedicated_scell(Mod_idP, rntiP, sCellToAddMod_r10);
   }
 #endif
 
-
-
-
   if (mbsfn_SubframeConfigList != NULL) {
     LOG_I(MAC,
 	  "[eNB %d][CONFIG] Received %d subframe allocation pattern for MBSFN\n",
 	  Mod_idP, mbsfn_SubframeConfigList->list.count);
-    RC.mac[Mod_idP]->common_channels[0].num_sf_allocation_pattern =
-      mbsfn_SubframeConfigList->list.count;
+    RC.mac[Mod_idP]->common_channels[0].num_sf_allocation_pattern = mbsfn_SubframeConfigList->list.count;
 
     for (i = 0; i < mbsfn_SubframeConfigList->list.count; i++) {
-      RC.mac[Mod_idP]->common_channels[0].mbsfn_SubframeConfig[i] =
-	mbsfn_SubframeConfigList->list.array[i];
+      RC.mac[Mod_idP]->common_channels[0].mbsfn_SubframeConfig[i] = mbsfn_SubframeConfigList->list.array[i];
       LOG_I(MAC,
 	    "[eNB %d][CONFIG] MBSFN_SubframeConfig[%d] pattern is  %x\n",
 	    Mod_idP, i,
@@ -964,11 +927,11 @@ rrc_mac_config_req_eNB(module_id_t Mod_idP,
 	    subframeAllocation.choice.oneFrame.buf[0]);
     }
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
     RC.mac[Mod_idP]->common_channels[0].MBMS_flag = MBMS_Flag;
 #endif
   }
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 
   if (mbsfn_AreaInfoList != NULL) {
     // One eNB could be part of multiple mbsfn syc area, this could change over time so reset each time
diff --git a/openair2/LAYER2/MAC/config_ue.c b/openair2/LAYER2/MAC/config_ue.c
index c38c32a4de7706544112b277d8e0ffbd45d5ce61..19dc16c13ffb52d6dafd9207ba8ea841484fb207 100644
--- a/openair2/LAYER2/MAC/config_ue.c
+++ b/openair2/LAYER2/MAC/config_ue.c
@@ -33,16 +33,16 @@
 #include "COMMON/platform_types.h"
 #include "COMMON/platform_constants.h"
 #include "SCHED_UE/sched_UE.h"
-#include "SystemInformationBlockType2.h"
+#include "LTE_SystemInformationBlockType2.h"
 //#include "RadioResourceConfigCommonSIB.h"
-#include "RadioResourceConfigDedicated.h"
-#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
-#include "PRACH-ConfigSIB-v1310.h"
+#include "LTE_RadioResourceConfigDedicated.h"
+#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
+#include "LTE_PRACH-ConfigSIB-v1310.h"
 #endif
-#include "MeasGapConfig.h"
-#include "MeasObjectToAddModList.h"
-#include "TDD-Config.h"
-#include "MAC-MainConfig.h"
+#include "LTE_MeasGapConfig.h"
+#include "LTE_MeasObjectToAddModList.h"
+#include "LTE_TDD-Config.h"
+#include "LTE_MAC-MainConfig.h"
 #include "mac.h"
 #include "mac_proto.h"
 #include "mac_extern.h"
@@ -51,11 +51,11 @@
 #include "PHY/INIT/phy_init.h"
 
 #include "common/ran_context.h"
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-#include "MBSFN-AreaInfoList-r9.h"
-#include "MBSFN-AreaInfo-r9.h"
-#include "MBSFN-SubframeConfigList.h"
-#include "PMCH-InfoList-r9.h"
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+#include "LTE_MBSFN-AreaInfoList-r9.h"
+#include "LTE_MBSFN-AreaInfo-r9.h"
+#include "LTE_MBSFN-SubframeConfigList.h"
+#include "LTE_PMCH-InfoList-r9.h"
 #endif
 
 extern void mac_init_cell_params(int Mod_idP,int CC_idP);
@@ -107,38 +107,38 @@ int
 rrc_mac_config_req_ue(module_id_t Mod_idP,
 		      int CC_idP,
 		      uint8_t eNB_index,
-		      RadioResourceConfigCommonSIB_t *
+		      LTE_RadioResourceConfigCommonSIB_t *
 		      radioResourceConfigCommon,
-		      struct PhysicalConfigDedicated
+		      struct LTE_PhysicalConfigDedicated
 		      *physicalConfigDedicated,
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-		      SCellToAddMod_r10_t * sCellToAddMod_r10,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+		      LTE_SCellToAddMod_r10_t * sCellToAddMod_r10,
 		      //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
 #endif
-		      MeasObjectToAddMod_t ** measObj,
-		      MAC_MainConfig_t * mac_MainConfig,
+		      LTE_MeasObjectToAddMod_t ** measObj,
+		      LTE_MAC_MainConfig_t * mac_MainConfig,
 		      long logicalChannelIdentity,
-		      LogicalChannelConfig_t * logicalChannelConfig,
-		      MeasGapConfig_t * measGapConfig,
-		      TDD_Config_t * tdd_Config,
-		      MobilityControlInfo_t * mobilityControlInfo,
+		      LTE_LogicalChannelConfig_t * logicalChannelConfig,
+		      LTE_MeasGapConfig_t * measGapConfig,
+		      LTE_TDD_Config_t * tdd_Config,
+		      LTE_MobilityControlInfo_t * mobilityControlInfo,
 		      uint8_t * SIwindowsize,
 		      uint16_t * SIperiod,
-		      ARFCN_ValueEUTRA_t * ul_CarrierFreq,
+		      LTE_ARFCN_ValueEUTRA_t * ul_CarrierFreq,
 		      long *ul_Bandwidth,
-		      AdditionalSpectrumEmission_t *
+		      LTE_AdditionalSpectrumEmission_t *
 		      additionalSpectrumEmission,
-		      struct MBSFN_SubframeConfigList
+		      struct LTE_MBSFN_SubframeConfigList
 		      *mbsfn_SubframeConfigList
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
 		      , uint8_t MBMS_Flag,
-		      MBSFN_AreaInfoList_r9_t * mbsfn_AreaInfoList,
-		      PMCH_InfoList_r9_t * pmch_InfoList
+		      LTE_MBSFN_AreaInfoList_r9_t * mbsfn_AreaInfoList,
+		      LTE_PMCH_InfoList_r9_t * pmch_InfoList
 #endif
 #ifdef CBA
 		      , uint8_t num_active_cba_groups, uint16_t cba_rnti
 #endif
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   ,config_action_t  config_action
   ,const uint32_t * const sourceL2Id
   ,const uint32_t * const destinationL2Id
@@ -219,11 +219,11 @@ rrc_mac_config_req_ue(module_id_t Mod_idP,
 	  mac_MainConfig->ul_SCH_Config->periodicBSR_Timer;
       } else {
 	UE_mac_inst[Mod_idP].scheduling_info.periodicBSR_Timer =
-#if (RRC_VERSION < MAKE_VERSION(12, 0, 0))
+#if (LTE_RRC_VERSION < MAKE_VERSION(12, 0, 0))
 	  (uint16_t)
-	  MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_infinity
+	  LTE_MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_infinity
 #else
-	  (uint16_t) PeriodicBSR_Timer_r12_infinity;
+	  (uint16_t) LTE_PeriodicBSR_Timer_r12_infinity;
 #endif
 	;
       }
@@ -234,7 +234,7 @@ rrc_mac_config_req_ue(module_id_t Mod_idP,
       } else {
 	UE_mac_inst[Mod_idP].scheduling_info.maxHARQ_Tx =
 	  (uint16_t)
-	  MAC_MainConfig__ul_SCH_Config__maxHARQ_Tx_n5;
+	  LTE_MAC_MainConfig__ul_SCH_Config__maxHARQ_Tx_n5;
       }
       if(nfapi_mode!=3)
         phy_config_harq_ue(Mod_idP, 0, eNB_index,
@@ -246,17 +246,17 @@ rrc_mac_config_req_ue(module_id_t Mod_idP,
 	  (uint16_t) mac_MainConfig->ul_SCH_Config->
 	  retxBSR_Timer;
       } else {
-#if (RRC_VERSION < MAKE_VERSION(12, 0, 0))
+#if (LTE_RRC_VERSION < MAKE_VERSION(12, 0, 0))
 	UE_mac_inst[Mod_idP].scheduling_info.retxBSR_Timer =
 	  (uint16_t)
-	  MAC_MainConfig__ul_SCH_Config__retxBSR_Timer_sf2560;
+	  LTE_MAC_MainConfig__ul_SCH_Config__retxBSR_Timer_sf2560;
 #else
 	UE_mac_inst[Mod_idP].scheduling_info.retxBSR_Timer =
-	  (uint16_t) RetxBSR_Timer_r12_sf2560;
+	  (uint16_t) LTE_RetxBSR_Timer_r12_sf2560;
 #endif
       }
     }
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 
     if (mac_MainConfig->ext1
 	&& mac_MainConfig->ext1->sr_ProhibitTimer_r9) {
@@ -326,13 +326,13 @@ rrc_mac_config_req_ue(module_id_t Mod_idP,
     } else {
       UE_mac_inst[Mod_idP].PHR_reconfigured = 0;
       UE_mac_inst[Mod_idP].PHR_state =
-	MAC_MainConfig__phr_Config_PR_setup;
+	LTE_MAC_MainConfig__phr_Config_PR_setup;
       UE_mac_inst[Mod_idP].scheduling_info.periodicPHR_Timer =
-	MAC_MainConfig__phr_Config__setup__periodicPHR_Timer_sf20;
+	LTE_MAC_MainConfig__phr_Config__setup__periodicPHR_Timer_sf20;
       UE_mac_inst[Mod_idP].scheduling_info.prohibitPHR_Timer =
-	MAC_MainConfig__phr_Config__setup__prohibitPHR_Timer_sf20;
+	LTE_MAC_MainConfig__phr_Config__setup__prohibitPHR_Timer_sf20;
       UE_mac_inst[Mod_idP].scheduling_info.PathlossChange =
-	MAC_MainConfig__phr_Config__setup__dl_PathlossChange_dB1;
+	LTE_MAC_MainConfig__phr_Config__setup__dl_PathlossChange_dB1;
     }
 
     UE_mac_inst[Mod_idP].scheduling_info.periodicPHR_SF =
@@ -362,7 +362,7 @@ rrc_mac_config_req_ue(module_id_t Mod_idP,
 			      physicalConfigDedicated);
     UE_mac_inst[Mod_idP].physicalConfigDedicated = physicalConfigDedicated;	// for SR proc
   }
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 
   if (sCellToAddMod_r10 != NULL) {
 
@@ -374,7 +374,9 @@ rrc_mac_config_req_ue(module_id_t Mod_idP,
 #endif
 
   if (measObj != NULL) {
-    if (measObj[0] != NULL) {
+    if (measObj[0] != NULL &&
+        measObj[0]->measObject.present == LTE_MeasObjectToAddMod__measObject_PR_measObjectEUTRA &&
+        measObj[0]->measObject.choice.measObjectEUTRA.cellsToAddModList != NULL) {
       UE_mac_inst[Mod_idP].n_adj_cells =
 	measObj[0]->measObject.choice.
 	measObjectEUTRA.cellsToAddModList->list.count;
@@ -410,14 +412,14 @@ rrc_mac_config_req_ue(module_id_t Mod_idP,
 	     rach_ConfigCommon,
 	     (void *) mobilityControlInfo->
 	     radioResourceConfigCommon.rach_ConfigCommon,
-	     sizeof(RACH_ConfigCommon_t));
+	     sizeof(LTE_RACH_ConfigCommon_t));
     }
 
     memcpy((void *) &UE_mac_inst[Mod_idP].
 	   radioResourceConfigCommon->prach_Config.prach_ConfigInfo,
 	   (void *) mobilityControlInfo->
 	   radioResourceConfigCommon.prach_Config.prach_ConfigInfo,
-	   sizeof(PRACH_ConfigInfo_t));
+	   sizeof(LTE_PRACH_ConfigInfo_t));
     UE_mac_inst[Mod_idP].radioResourceConfigCommon->
       prach_Config.rootSequenceIndex =
       mobilityControlInfo->radioResourceConfigCommon.
@@ -430,19 +432,19 @@ rrc_mac_config_req_ue(module_id_t Mod_idP,
 	     pdsch_ConfigCommon,
 	     (void *) mobilityControlInfo->
 	     radioResourceConfigCommon.pdsch_ConfigCommon,
-	     sizeof(PDSCH_ConfigCommon_t));
+	     sizeof(LTE_PDSCH_ConfigCommon_t));
     }
     // not a pointer: mobilityControlInfo->radioResourceConfigCommon.pusch_ConfigCommon
     memcpy((void *) &UE_mac_inst[Mod_idP].
 	   radioResourceConfigCommon->pusch_ConfigCommon,
 	   (void *) &mobilityControlInfo->
 	   radioResourceConfigCommon.pusch_ConfigCommon,
-	   sizeof(PUSCH_ConfigCommon_t));
+	   sizeof(LTE_PUSCH_ConfigCommon_t));
 
     if (mobilityControlInfo->radioResourceConfigCommon.phich_Config) {
       /* memcpy((void *)&UE_mac_inst[Mod_idP].radioResourceConfigCommon->phich_Config,
 	 (void *)mobilityControlInfo->radioResourceConfigCommon.phich_Config,
-	 sizeof(PHICH_Config_t)); */
+	 sizeof(LTE_PHICH_Config_t)); */
     }
 
     if (mobilityControlInfo->radioResourceConfigCommon.
@@ -452,7 +454,7 @@ rrc_mac_config_req_ue(module_id_t Mod_idP,
 	     pucch_ConfigCommon,
 	     (void *) mobilityControlInfo->
 	     radioResourceConfigCommon.pucch_ConfigCommon,
-	     sizeof(PUCCH_ConfigCommon_t));
+	     sizeof(LTE_PUCCH_ConfigCommon_t));
     }
 
     if (mobilityControlInfo->
@@ -462,7 +464,7 @@ rrc_mac_config_req_ue(module_id_t Mod_idP,
 	     soundingRS_UL_ConfigCommon,
 	     (void *) mobilityControlInfo->
 	     radioResourceConfigCommon.soundingRS_UL_ConfigCommon,
-	     sizeof(SoundingRS_UL_ConfigCommon_t));
+	     sizeof(LTE_SoundingRS_UL_ConfigCommon_t));
     }
 
     if (mobilityControlInfo->
@@ -472,7 +474,7 @@ rrc_mac_config_req_ue(module_id_t Mod_idP,
 	     uplinkPowerControlCommon,
 	     (void *) mobilityControlInfo->
 	     radioResourceConfigCommon.uplinkPowerControlCommon,
-	     sizeof(UplinkPowerControlCommon_t));
+	     sizeof(LTE_UplinkPowerControlCommon_t));
     }
     //configure antennaInfoCommon somewhere here..
     if (mobilityControlInfo->radioResourceConfigCommon.p_Max) {
@@ -491,7 +493,7 @@ rrc_mac_config_req_ue(module_id_t Mod_idP,
 	     ul_CyclicPrefixLength,
 	     (void *) mobilityControlInfo->
 	     radioResourceConfigCommon.ul_CyclicPrefixLength,
-	     sizeof(UL_CyclicPrefixLength_t));
+	     sizeof(LTE_UL_CyclicPrefixLength_t));
     }
     // store the previous rnti in case of failure, and set thenew rnti
     UE_mac_inst[Mod_idP].crnti_before_ho = UE_mac_inst[Mod_idP].crnti;
@@ -532,7 +534,7 @@ rrc_mac_config_req_ue(module_id_t Mod_idP,
       //    UE_mac_inst[Mod_idP].mbsfn_SubframeConfig[i]->subframeAllocation.choice.oneFrame.buf[0]);
     }
   }
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 
   if (mbsfn_AreaInfoList != NULL) {
     LOG_I(MAC, "[UE %d][CONFIG] Received %d MBSFN Area Info\n",
@@ -590,7 +592,7 @@ rrc_mac_config_req_ue(module_id_t Mod_idP,
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME
     (VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_MAC_CONFIG, VCD_FUNCTION_OUT);
   //for D2D
-  #if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+  #if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
     switch (config_action) {
     case CONFIG_ACTION_ADD:
        if (sourceL2Id){
diff --git a/openair2/LAYER2/MAC/defs.h b/openair2/LAYER2/MAC/defs.h
new file mode 100644
index 0000000000000000000000000000000000000000..8ff4a20662859d97006cf472a004c61c001a2b11
--- /dev/null
+++ b/openair2/LAYER2/MAC/defs.h
@@ -0,0 +1,1342 @@
+/*
+ * 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
+ */
+
+/*! \file LAYER2/MAC/defs.h
+* \brief MAC data structures, constant, and function prototype
+* \author Navid Nikaein and Raymond Knopp
+* \date 2011
+* \version 0.5
+* \email navid.nikaein@eurecom.fr
+
+*/
+/** @defgroup _oai2  openair2 Reference Implementation
+ * @ingroup _ref_implementation_
+ * @{
+ */
+
+/*@}*/
+
+#ifndef __LAYER2_MAC_DEFS_H__
+#define __LAYER2_MAC_DEFS_H__
+
+
+
+#ifdef USER_MODE
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#endif
+
+//#include "COMMON/openair_defs.h"
+
+
+
+#include "PHY/defs.h"
+#include "PHY/LTE_TRANSPORT/defs.h"
+#include "COMMON/platform_constants.h"
+#include "BCCH-BCH-Message.h"
+#include "RadioResourceConfigCommon.h"
+#include "RadioResourceConfigDedicated.h"
+#include "MeasGapConfig.h"
+#include "SchedulingInfoList.h"
+#include "TDD-Config.h"
+#include "RACH-ConfigCommon.h"
+#include "MeasObjectToAddModList.h"
+#include "MobilityControlInfo.h"
+#if defined(Rel10) || defined(Rel14)
+#include "MBSFN-AreaInfoList-r9.h"
+#include "MBSFN-SubframeConfigList.h"
+#include "PMCH-InfoList-r9.h"
+#include "SCellToAddMod-r10.h"
+#endif
+#ifdef Rel14
+#include "SystemInformationBlockType1-v1310-IEs.h"
+#endif
+
+#include "nfapi_interface.h"
+#include "PHY_INTERFACE/IF_Module.h"
+
+/** @defgroup _mac  MAC
+ * @ingroup _oai2
+ * @{
+ */
+
+#define BCCH_PAYLOAD_SIZE_MAX 128
+#define CCCH_PAYLOAD_SIZE_MAX 128
+#define PCCH_PAYLOAD_SIZE_MAX 128
+#define RAR_PAYLOAD_SIZE_MAX 128
+
+#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)
+
+// Mask for identifying subframe for MBMS
+#define MBSFN_TDD_SF3 0x80// for TDD
+#define MBSFN_TDD_SF4 0x40
+#define MBSFN_TDD_SF7 0x20
+#define MBSFN_TDD_SF8 0x10
+#define MBSFN_TDD_SF9 0x08
+#define MBSFN_FDD_SF1 0x80// for FDD
+#define MBSFN_FDD_SF2 0x40
+#define MBSFN_FDD_SF3 0x20
+#define MBSFN_FDD_SF6 0x10
+#define MBSFN_FDD_SF7 0x08
+#define MBSFN_FDD_SF8 0x04
+
+#define MAX_MBSFN_AREA 8
+#define MAX_PMCH_perMBSFN 15
+/*!\brief MAX MCCH payload size  */
+#define MCCH_PAYLOAD_SIZE_MAX 128
+//#define MCH_PAYLOAD_SIZE_MAX 16384// this value is using in case mcs and TBS index are high
+#endif
+
+#ifdef USER_MODE
+#define printk printf
+#endif //USER_MODE
+
+/*!\brief Maximum number of logical channl group IDs */
+#define MAX_NUM_LCGID 4
+/*!\brief logical channl group ID 0 */
+#define LCGID0 0
+/*!\brief logical channl group ID 1 */
+#define LCGID1 1
+/*!\brief logical channl group ID 2 */
+#define LCGID2 2
+/*!\brief logical channl group ID 3 */
+#define LCGID3 3
+/*!\brief Maximum number of logical chanels */
+#define MAX_NUM_LCID 11
+/*!\brief Maximum number od control elemenets */
+#define MAX_NUM_CE 5
+/*!\brief Maximum number of random access process */
+#define NB_RA_PROC_MAX 4
+/*!\brief size of buffer status report table */
+#define BSR_TABLE_SIZE 64
+/*!\brief The power headroom reporting range is from -23 ...+40 dB and beyond, with step 1 */
+#define PHR_MAPPING_OFFSET 23  // if ( x>= -23 ) val = floor (x + 23)
+/*!\brief maximum number of resource block groups */
+#define N_RBG_MAX 25 // for 20MHz channel BW
+/*!\brief minimum value for channel quality indicator */
+#define MIN_CQI_VALUE  0
+/*!\brief maximum value for channel quality indicator */
+#define MAX_CQI_VALUE  15
+/*!\briefmaximum number of supported bandwidth (1.4, 5, 10, 20 MHz) */
+#define MAX_SUPPORTED_BW  4
+/*!\brief CQI values range from 1 to 15 (4 bits) */
+#define CQI_VALUE_RANGE 16
+
+/*!\brief value for indicating BSR Timer is not running */
+#define MAC_UE_BSR_TIMER_NOT_RUNNING   (0xFFFF)
+
+#define LCID_EMPTY 0
+#define LCID_NOT_EMPTY 1
+
+/*!\brief minimum RLC PDU size to be transmitted = min RLC Status PDU or RLC UM PDU SN 5 bits */
+#define MIN_RLC_PDU_SIZE    (2)
+
+/*!\brief minimum MAC data needed for transmitting 1 min RLC PDU size + 1 byte MAC subHeader */
+#define MIN_MAC_HDR_RLC_SIZE    (1 + MIN_RLC_PDU_SIZE)
+
+/*!\brief maximum number of slices / groups */
+#define MAX_NUM_SLICES 4
+
+/*
+ * eNB part
+ */
+
+
+/*
+ * UE/ENB common part
+ */
+/*!\brief MAC header of Random Access Response for Random access preamble identifier (RAPID) */
+typedef struct {
+  uint8_t RAPID:6;
+  uint8_t T:1;
+  uint8_t E:1;
+} __attribute__((__packed__))RA_HEADER_RAPID;
+
+/*!\brief  MAC header of Random Access Response for backoff indicator (BI)*/
+typedef struct {
+  uint8_t BI:4;
+  uint8_t R:2;
+  uint8_t T:1;
+  uint8_t E:1;
+} __attribute__((__packed__))RA_HEADER_BI;
+/*
+typedef struct {
+  uint64_t padding:16;
+  uint64_t t_crnti:16;
+  uint64_t hopping_flag:1;
+  uint64_t rb_alloc:10;
+  uint64_t mcs:4;
+  uint64_t TPC:3;
+  uint64_t UL_delay:1;
+  uint64_t cqi_req:1;
+  uint64_t Timing_Advance_Command:11;  // first/2nd octet LSB
+  uint64_t R:1;                        // octet MSB
+  } __attribute__((__packed__))RAR_PDU;
+
+typedef struct {
+  uint64_t padding:16;
+  uint64_t R:1;                        // octet MSB
+  uint64_t Timing_Advance_Command:11;  // first/2nd octet LSB
+  uint64_t cqi_req:1;
+  uint64_t UL_delay:1;
+  uint64_t TPC:3;
+  uint64_t mcs:4;
+  uint64_t rb_alloc:10;
+  uint64_t hopping_flag:1;
+  uint64_t t_crnti:16;
+  } __attribute__((__packed__))RAR_PDU;
+
+#define sizeof_RAR_PDU 6
+*/
+/*!\brief  MAC subheader short with 7bit Length field */
+typedef struct {
+  uint8_t LCID:5;  // octet 1 LSB
+  uint8_t E:1;
+  uint8_t R:2;     // octet 1 MSB
+  uint8_t L:7;     // octet 2 LSB
+  uint8_t F:1;     // octet 2 MSB
+} __attribute__((__packed__))SCH_SUBHEADER_SHORT;
+/*!\brief  MAC subheader long  with 15bit Length field */
+typedef struct {
+  uint8_t LCID:5;   // octet 1 LSB
+  uint8_t E:1;
+  uint8_t R:2;      // octet 1 MSB
+  uint8_t L_MSB:7;
+  uint8_t F:1;      // octet 2 MSB
+  uint8_t L_LSB:8;
+  uint8_t padding;
+} __attribute__((__packed__))SCH_SUBHEADER_LONG;
+/*!\brief MAC subheader short without length field */
+typedef struct {
+  uint8_t LCID:5;
+  uint8_t E:1;
+  uint8_t R:2;
+} __attribute__((__packed__))SCH_SUBHEADER_FIXED;
+
+/*!\brief  mac control element: short buffer status report for a specific logical channel group ID*/
+typedef struct {
+  uint8_t Buffer_size:6;  // octet 1 LSB
+  uint8_t LCGID:2;        // octet 1 MSB
+} __attribute__((__packed__))BSR_SHORT;
+
+typedef BSR_SHORT BSR_TRUNCATED;
+/*!\brief  mac control element: long buffer status report for all logical channel group ID*/
+typedef struct {
+  uint8_t Buffer_size3:6;
+  uint8_t Buffer_size2:6;
+  uint8_t Buffer_size1:6;
+  uint8_t Buffer_size0:6;
+} __attribute__((__packed__))BSR_LONG;
+
+#define BSR_LONG_SIZE  (sizeof(BSR_LONG))
+/*!\brief  mac control element: timing advance  */
+typedef struct {
+  uint8_t TA:6;
+  uint8_t R:2;
+} __attribute__((__packed__))TIMING_ADVANCE_CMD;
+/*!\brief  mac control element: power headroom report  */
+typedef struct {
+  uint8_t PH:6;
+  uint8_t R:2;
+} __attribute__((__packed__))POWER_HEADROOM_CMD;
+
+/*! \brief MIB payload */
+typedef struct {
+  uint8_t payload[3] ;
+} __attribute__((__packed__))MIB_PDU;
+/*! \brief CCCH payload */
+typedef struct {
+  uint8_t payload[CCCH_PAYLOAD_SIZE_MAX] ;
+} __attribute__((__packed__))CCCH_PDU;
+/*! \brief BCCH payload */
+typedef struct {
+  uint8_t payload[BCCH_PAYLOAD_SIZE_MAX] ;
+} __attribute__((__packed__))BCCH_PDU;
+/*! \brief RAR payload */
+typedef struct {
+  uint8_t payload[RAR_PAYLOAD_SIZE_MAX];
+} __attribute__ ((__packed__)) RAR_PDU;
+/*! \brief BCCH payload */
+typedef struct {
+  uint8_t payload[PCCH_PAYLOAD_SIZE_MAX] ;
+} __attribute__((__packed__))PCCH_PDU;
+
+#if defined(Rel10) || defined(Rel14)
+/*! \brief MCCH payload */
+typedef struct {
+  uint8_t payload[MCCH_PAYLOAD_SIZE_MAX] ;
+} __attribute__((__packed__))MCCH_PDU;
+/*!< \brief MAC control element for activation and deactivation of component carriers */
+typedef struct {
+  uint8_t C7:1;/*!< \brief Component carrier 7 */
+  uint8_t C6:1;/*!< \brief Component carrier 6 */
+  uint8_t C5:1;/*!< \brief Component carrier 5 */
+  uint8_t C4:1;/*!< \brief Component carrier 4 */
+  uint8_t C3:1;/*!< \brief Component carrier 3 */
+  uint8_t C2:1;/*!< \brief Component carrier 2 */
+  uint8_t C1:1;/*!< \brief Component carrier 1 */
+  uint8_t R:1;/*!< \brief Reserved  */
+} __attribute__((__packed__))CC_ELEMENT;
+/*! \brief MAC control element: MCH Scheduling Information */
+typedef struct {
+  uint8_t stop_sf_MSB:3; // octet 1 LSB
+  uint8_t lcid:5;        // octet 2 MSB
+  uint8_t stop_sf_LSB:8;
+} __attribute__((__packed__))MSI_ELEMENT;
+#endif
+/*! \brief Values of CCCH LCID for DLSCH */
+#define CCCH_LCHANID 0
+/*!\brief Values of BCCH logical channel (fake)*/
+#define BCCH 3  // SI
+/*!\brief Values of PCCH logical channel (fake)*/
+#define PCCH 4  // Paging
+/*!\brief Values of PCCH logical channel (fake) */
+#define MIBCH 5  // MIB
+/*!\brief Values of BCCH SIB1_BR logical channel (fake) */
+#define BCCH_SIB1_BR 6  // SIB1_BR
+/*!\brief Values of BCCH SIB_BR logical channel (fake) */
+#define BCCH_SI_BR 7  // SI-BR
+/*!\brief Value of CCCH / SRB0 logical channel */
+#define CCCH 0  // srb0
+/*!\brief DCCH / SRB1 logical channel */
+#define DCCH 1  // srb1
+/*!\brief DCCH1 / SRB2  logical channel */
+#define DCCH1 2 // srb2
+/*!\brief DTCH DRB1  logical channel */
+#define DTCH 3 // LCID
+/*!\brief MCCH logical channel */
+#define MCCH 4
+/*!\brief MTCH logical channel */
+#define MTCH 1
+// DLSCH LCHAN ID
+/*!\brief LCID of UE contention resolution identity for DLSCH*/
+#define UE_CONT_RES 28
+/*!\brief LCID of timing advance for DLSCH */
+#define TIMING_ADV_CMD 29
+/*!\brief LCID of discontinous reception mode for DLSCH */
+#define DRX_CMD 30
+/*!\brief LCID of padding LCID for DLSCH */
+#define SHORT_PADDING 31
+
+#if defined(Rel10) || defined(Rel14)
+// MCH LCHAN IDs (table6.2.1-4 TS36.321)
+/*!\brief LCID of MCCH for DL */
+#define MCCH_LCHANID 0
+/*!\brief LCID of MCH scheduling info for DL */
+#define MCH_SCHDL_INFO 3
+/*!\brief LCID of Carrier component activation/deactivation */
+#define CC_ACT_DEACT 27
+#endif
+
+// ULSCH LCHAN IDs
+/*!\brief LCID of extended power headroom for ULSCH */
+#define EXTENDED_POWER_HEADROOM 25
+/*!\brief LCID of power headroom for ULSCH */
+#define POWER_HEADROOM 26
+/*!\brief LCID of CRNTI for ULSCH */
+#define CRNTI 27
+/*!\brief LCID of truncated BSR for ULSCH */
+#define TRUNCATED_BSR 28
+/*!\brief LCID of short BSR for ULSCH */
+#define SHORT_BSR 29
+/*!\brief LCID of long BSR for ULSCH */
+#define LONG_BSR 30
+/*!\bitmaps for BSR Triggers */
+#define	BSR_TRIGGER_NONE		(0)			/* No BSR Trigger */
+#define	BSR_TRIGGER_REGULAR		(1)			/* For Regular and ReTxBSR Expiry Triggers */
+#define	BSR_TRIGGER_PERIODIC	(2)			/* For BSR Periodic Timer Expiry Trigger */
+#define	BSR_TRIGGER_PADDING		(4)			/* For Padding BSR Trigger */
+
+
+/*! \brief Downlink SCH PDU Structure */
+typedef struct {
+  uint8_t payload[8][SCH_PAYLOAD_SIZE_MAX];
+  uint16_t Pdu_size[8];
+} __attribute__ ((__packed__)) DLSCH_PDU;
+
+
+/*! \brief MCH PDU Structure */
+typedef struct {
+  int8_t payload[SCH_PAYLOAD_SIZE_MAX];
+  uint16_t Pdu_size;
+  uint8_t mcs;
+  uint8_t sync_area;
+  uint8_t msi_active;
+  uint8_t mcch_active;
+  uint8_t mtch_active;
+} __attribute__ ((__packed__)) MCH_PDU;
+
+/*! \brief Uplink SCH PDU Structure */
+typedef struct {
+  int8_t payload[SCH_PAYLOAD_SIZE_MAX];         /*!< \brief SACH payload */
+  uint16_t Pdu_size;
+} __attribute__ ((__packed__)) ULSCH_PDU;
+
+#include "PHY/impl_defs_top.h"
+
+/*!\brief  UE ULSCH scheduling states*/
+typedef enum {
+  S_UL_NONE =0,
+  S_UL_WAITING,
+  S_UL_SCHEDULED,
+  S_UL_BUFFERED,
+  S_UL_NUM_STATUS
+} UE_ULSCH_STATUS;
+
+/*!\brief  UE DLSCH scheduling states*/
+typedef enum {
+  S_DL_NONE =0,
+  S_DL_WAITING,
+  S_DL_SCHEDULED,
+  S_DL_BUFFERED,
+  S_DL_NUM_STATUS
+} UE_DLSCH_STATUS;
+
+/*!\brief  scheduling policy for the contention-based access */
+typedef enum {
+  CBA_ES=0, /// equal share of RB among groups w
+  CBA_ES_S,  /// equal share of RB among groups with small allocation
+  CBA_PF, /// proportional fair (kind of)
+  CBA_PF_S,  /// proportional fair (kind of) with small RB allocation
+  CBA_RS /// random allocation
+} CBA_POLICY;
+
+
+/*! \brief temporary struct for ULSCH sched */
+typedef struct {
+  rnti_t rnti;
+  uint16_t subframe;
+  uint16_t serving_num;
+  UE_ULSCH_STATUS status;
+} eNB_ULSCH_INFO;
+/*! \brief temp struct for DLSCH sched */
+typedef struct {
+  rnti_t rnti;
+  uint16_t weight;
+  uint16_t subframe;
+  uint16_t serving_num;
+  UE_DLSCH_STATUS status;
+} eNB_DLSCH_INFO;
+/*! \brief eNB overall statistics */
+typedef struct {
+  /// num BCCH PDU per CC
+  uint32_t total_num_bcch_pdu;
+  /// BCCH buffer size
+  uint32_t bcch_buffer;
+  /// total BCCH buffer size
+  uint32_t total_bcch_buffer;
+  /// BCCH MCS
+  uint32_t bcch_mcs;
+
+  /// num CCCH PDU per CC
+  uint32_t total_num_ccch_pdu;
+  /// BCCH buffer size
+  uint32_t ccch_buffer;
+  /// total BCCH buffer size
+  uint32_t total_ccch_buffer;
+  /// BCCH MCS
+  uint32_t ccch_mcs;
+
+/// num active users
+  uint16_t num_dlactive_UEs;
+  ///  available number of PRBs for a give SF
+  uint16_t available_prbs;
+  /// total number of PRB available for the user plane
+  uint32_t total_available_prbs;
+  /// aggregation
+  /// total avilable nccc : num control channel element
+  uint16_t available_ncces;
+  // only for a new transmission, should be extended for retransmission
+  // current dlsch  bit rate for all transport channels
+  uint32_t dlsch_bitrate;
+  //
+  uint32_t dlsch_bytes_tx;
+  //
+  uint32_t dlsch_pdus_tx;
+  //
+  uint32_t total_dlsch_bitrate;
+  //
+  uint32_t total_dlsch_bytes_tx;
+  //
+  uint32_t total_dlsch_pdus_tx;
+
+  // here for RX
+  //
+  uint32_t ulsch_bitrate;
+  //
+  uint32_t ulsch_bytes_rx;
+  //
+  uint64_t ulsch_pdus_rx;
+
+  uint32_t total_ulsch_bitrate;
+  //
+  uint32_t total_ulsch_bytes_rx;
+  //
+  uint32_t total_ulsch_pdus_rx;
+
+
+  /// MAC agent-related stats
+  /// total number of scheduling decisions
+  int sched_decisions;
+  /// missed deadlines
+  int missed_deadlines;
+
+} eNB_STATS;
+/*! \brief eNB statistics for the connected UEs*/
+typedef struct {
+
+  /// CRNTI of UE
+  rnti_t crnti; ///user id (rnti) of connected UEs
+  // rrc status
+  uint8_t rrc_status;
+  /// harq pid
+  uint8_t harq_pid;
+  /// harq rounf
+  uint8_t harq_round;
+  /// total available number of PRBs for a new transmission
+  uint16_t rbs_used;
+  /// total available number of PRBs for a retransmission
+  uint16_t rbs_used_retx;
+  /// total nccc used for a new transmission: num control channel element
+  uint16_t ncce_used;
+  /// total avilable nccc for a retransmission: num control channel element
+  uint16_t ncce_used_retx;
+
+  // mcs1 before the rate adaptaion
+  uint8_t dlsch_mcs1;
+  /// Target mcs2 after rate-adaptation
+  uint8_t dlsch_mcs2;
+  //  current TBS with mcs2
+  uint32_t TBS;
+  //  total TBS with mcs2
+  //  uint32_t total_TBS;
+  //  total rb used for a new transmission
+  uint32_t total_rbs_used;
+  //  total rb used for retransmission
+  uint32_t total_rbs_used_retx;
+
+   /// TX
+  /// Num pkt
+  uint32_t num_pdu_tx[NB_RB_MAX];
+  /// num bytes
+  uint32_t num_bytes_tx[NB_RB_MAX];
+  /// num retransmission / harq
+  uint32_t num_retransmission;
+  /// instantaneous tx throughput for each TTI
+  //  uint32_t tti_throughput[NB_RB_MAX];
+
+  /// overall
+  //
+  uint32_t  dlsch_bitrate;
+  //total
+  uint32_t  total_dlsch_bitrate;
+  /// headers+ CE +  padding bytes for a MAC PDU
+  uint64_t overhead_bytes;
+  /// headers+ CE +  padding bytes for a MAC PDU
+  uint64_t total_overhead_bytes;
+  /// headers+ CE +  padding bytes for a MAC PDU
+  uint64_t avg_overhead_bytes;
+  // MAC multiplexed payload
+  uint64_t total_sdu_bytes;
+  // total MAC pdu bytes
+  uint64_t total_pdu_bytes;
+
+  // total num pdu
+  uint32_t total_num_pdus;
+  //
+  //  uint32_t avg_pdu_size;
+
+  /// RX
+
+  /// PUCCH1a/b power (dBm)
+  int32_t Po_PUCCH_dBm;
+  /// Indicator that Po_PUCCH has been updated by PHY
+  int32_t Po_PUCCH_update;
+  /// Uplink measured RSSI
+  int32_t UL_rssi;
+  /// preassigned mcs after rate adaptation
+  uint8_t ulsch_mcs1;
+  /// adjusted mcs
+  uint8_t ulsch_mcs2;
+
+  /// estimated average pdu inter-departure time
+  uint32_t avg_pdu_idt;
+  /// estimated average pdu size
+  uint32_t avg_pdu_ps;
+  ///
+  uint32_t aggregated_pdu_size;
+  uint32_t aggregated_pdu_arrival;
+
+  ///  uplink transport block size
+  uint32_t ulsch_TBS;
+
+  ///  total rb used for a new uplink transmission
+  uint32_t num_retransmission_rx;
+  ///  total rb used for a new uplink transmission
+  uint32_t rbs_used_rx;
+   ///  total rb used for a new uplink retransmission
+  uint32_t rbs_used_retx_rx;
+  ///  total rb used for a new uplink transmission
+  uint32_t total_rbs_used_rx;
+  /// normalized rx power
+  int32_t      normalized_rx_power;
+   /// target rx power
+  int32_t    target_rx_power;
+
+  /// num rx pdu
+  uint32_t num_pdu_rx[NB_RB_MAX];
+  /// num bytes rx
+  uint32_t num_bytes_rx[NB_RB_MAX];
+  /// instantaneous rx throughput for each TTI
+  //  uint32_t tti_goodput[NB_RB_MAX];
+  /// errors
+  uint32_t num_errors_rx;
+
+  uint64_t overhead_bytes_rx;
+  /// headers+ CE +  padding bytes for a MAC PDU
+  uint64_t total_overhead_bytes_rx;
+  /// headers+ CE +  padding bytes for a MAC PDU
+  uint64_t avg_overhead_bytes_rx;
+ //
+  uint32_t  ulsch_bitrate;
+  //total
+  uint32_t  total_ulsch_bitrate;
+  /// overall
+  ///  MAC pdu bytes
+  uint64_t pdu_bytes_rx;
+  /// total MAC pdu bytes
+  uint64_t total_pdu_bytes_rx;
+  /// total num pdu
+  uint32_t total_num_pdus_rx;
+  /// num of error pdus
+  uint32_t total_num_errors_rx;
+
+} eNB_UE_STATS;
+/*! \brief eNB template for UE context information  */
+typedef struct {
+  /// C-RNTI of UE
+  rnti_t rnti;
+  /// NDI from last scheduling
+  uint8_t oldNDI[8];
+  /// mcs1 from last scheduling
+  uint8_t oldmcs1[8];
+  /// mcs2 from last scheduling
+  uint8_t oldmcs2[8];
+  /// NDI from last UL scheduling
+  uint8_t oldNDI_UL[8];
+  /// mcs from last UL scheduling
+  uint8_t mcs_UL[8];
+  /// TBS from last UL scheduling
+  uint8_t TBS_UL[8];
+  /// CQI_req from last scheduling
+  uint8_t oldCQI_UL[8];
+  /// TPC from last scheduling
+  uint8_t oldTPC_UL[8];
+  /// Flag to indicate UL has been scheduled at least once
+  boolean_t ul_active;
+  /// Flag to indicate UE has been configured (ACK from RRCConnectionSetup received)
+  boolean_t configured;
+
+  /// MCS from last scheduling
+  uint8_t mcs[8];
+
+  /// TPC from last scheduling
+  uint8_t oldTPC[8];
+
+  // PHY interface info
+
+  /// Number of Allocated RBs for DL after scheduling (prior to frequency allocation)
+  uint16_t nb_rb[8]; // num_max_harq
+
+  /// Number of Allocated RBs for UL after scheduling
+  uint16_t nb_rb_ul[8]; // num_max_harq
+
+  /// Number of Allocated RBs for UL after scheduling
+  uint16_t first_rb_ul[8]; // num_max_harq
+
+  /// Cyclic shift for DMRS after scheduling
+  uint16_t cshift[8]; // num_max_harq
+
+  /// Number of Allocated RBs by the ulsch preprocessor
+  uint8_t pre_allocated_nb_rb_ul;
+
+  /// index of Allocated RBs by the ulsch preprocessor
+  int8_t pre_allocated_rb_table_index_ul;
+
+  /// total allocated RBs
+  int8_t total_allocated_rbs;
+
+  /// pre-assigned MCS by the ulsch preprocessor
+  uint8_t pre_assigned_mcs_ul;
+
+  /// assigned MCS by the ulsch scheduler
+  uint8_t assigned_mcs_ul;
+
+  /// DL DAI
+  uint8_t DAI;
+
+  /// UL DAI
+  uint8_t DAI_ul[10];
+
+  /// UL Scheduling Request Received
+  uint8_t ul_SR;
+
+  ///Resource Block indication for each sub-band in MU-MIMO
+  uint8_t rballoc_subband[8][50];
+
+  // Logical channel info for link with RLC
+
+  /// Last received UE BSR info for each logical channel group id
+  uint8_t bsr_info[MAX_NUM_LCGID];
+
+  /// LCGID mapping
+  long lcgidmap[11];
+
+  /// phr information
+  int8_t phr_info;
+
+  /// phr information
+  int8_t phr_info_configured;
+
+  ///dl buffer info
+  uint32_t dl_buffer_info[MAX_NUM_LCID];
+  /// total downlink buffer info
+  uint32_t dl_buffer_total;
+  /// total downlink pdus
+  uint32_t dl_pdus_total;
+  /// downlink pdus for each LCID
+  uint32_t dl_pdus_in_buffer[MAX_NUM_LCID];
+  /// creation time of the downlink buffer head for each LCID
+  uint32_t dl_buffer_head_sdu_creation_time[MAX_NUM_LCID];
+  /// maximum creation time of the downlink buffer head across all LCID
+  uint32_t  dl_buffer_head_sdu_creation_time_max;
+  /// a flag indicating that the downlink head SDU is segmented
+  uint8_t    dl_buffer_head_sdu_is_segmented[MAX_NUM_LCID];
+  /// size of remaining size to send for the downlink head SDU
+  uint32_t dl_buffer_head_sdu_remaining_size_to_send[MAX_NUM_LCID];
+
+  /// total uplink buffer size
+  uint32_t ul_total_buffer;
+  /// uplink buffer creation time for each LCID
+  uint32_t ul_buffer_creation_time[MAX_NUM_LCGID];
+  /// maximum uplink buffer creation time across all the LCIDs
+  uint32_t ul_buffer_creation_time_max;
+  /// uplink buffer size per LCID
+  uint32_t ul_buffer_info[MAX_NUM_LCGID];
+
+  /// UE tx power
+  int32_t ue_tx_power;
+
+  /// stores the frame where the last TPC was transmitted
+  uint32_t pusch_tpc_tx_frame;
+  uint32_t pusch_tpc_tx_subframe;
+  uint32_t pucch_tpc_tx_frame;
+  uint32_t pucch_tpc_tx_subframe;
+
+#ifdef LOCALIZATION
+  eNB_UE_estimated_distances distance;
+#endif
+
+#ifdef Rel14
+  uint8_t rach_resource_type;
+
+ uint16_t mpdcch_repetition_cnt;
+  struct PhysicalConfigDedicated  *physicalConfigDedicated;
+  frame_t Msg2_frame;
+  sub_frame_t Msg2_subframe;
+#endif
+} UE_TEMPLATE;
+
+/*! \brief scheduling control information set through an API (not used)*/
+typedef struct {
+  ///UL transmission bandwidth in RBs
+  uint8_t ul_bandwidth[MAX_NUM_LCID];
+  ///DL transmission bandwidth in RBs
+  uint8_t dl_bandwidth[MAX_NUM_LCID];
+
+  //To do GBR bearer
+  uint8_t min_ul_bandwidth[MAX_NUM_LCID];
+
+  uint8_t min_dl_bandwidth[MAX_NUM_LCID];
+
+  ///aggregated bit rate of non-gbr bearer per UE
+  uint64_t  ue_AggregatedMaximumBitrateDL;
+  ///aggregated bit rate of non-gbr bearer per UE
+  uint64_t  ue_AggregatedMaximumBitrateUL;
+  ///CQI scheduling interval in subframes.
+  uint16_t cqiSchedInterval;
+  ///Contention resolution timer used during random access
+  uint8_t mac_ContentionResolutionTimer;
+
+  uint16_t max_allowed_rbs[MAX_NUM_LCID];
+
+  uint8_t max_mcs[MAX_NUM_LCID];
+
+  uint16_t priority[MAX_NUM_LCID];
+
+  // resource scheduling information
+
+  /// Current DL harq round per harq_pid on each CC
+  uint8_t       round[MAX_NUM_CCs][10];
+  /// Current Active TBs per harq_pid on each CC
+  uint8_t       tbcnt[MAX_NUM_CCs][10];
+  /// Current UL harq round per harq_pid on each CC
+  uint8_t       round_UL[MAX_NUM_CCs][8];
+  uint8_t       dl_pow_off[MAX_NUM_CCs];
+  uint16_t      pre_nb_available_rbs[MAX_NUM_CCs];
+  unsigned char rballoc_sub_UE[MAX_NUM_CCs][N_RBG_MAX];
+  uint16_t      ta_timer;
+  int16_t       ta_update;
+  uint16_t      ul_consecutive_errors;
+  int32_t       context_active_timer;
+  int32_t       cqi_req_timer;
+  int32_t       ul_inactivity_timer;
+  int32_t       ul_failure_timer;
+  int32_t       ul_scheduled;
+  int32_t       ra_pdcch_order_sent;
+  int32_t       ul_out_of_sync;
+  int32_t       phr_received;
+  uint8_t       periodic_ri_received[NFAPI_CC_MAX];
+  uint8_t       aperiodic_ri_received[NFAPI_CC_MAX];
+  uint32_t      pucch_tpc_accumulated[NFAPI_CC_MAX];
+  uint8_t       pucch1_cqi_update[NFAPI_CC_MAX];
+  uint8_t       pucch1_snr[NFAPI_CC_MAX];
+  uint8_t       pucch2_cqi_update[NFAPI_CC_MAX];
+  uint8_t       pucch2_snr[NFAPI_CC_MAX];
+  uint8_t       pucch3_cqi_update[NFAPI_CC_MAX];
+  uint8_t       pucch3_snr[NFAPI_CC_MAX];
+  uint8_t       pusch_snr[NFAPI_CC_MAX];
+  uint16_t      feedback_cnt[NFAPI_CC_MAX];
+  uint16_t      timing_advance;
+  uint16_t      timing_advance_r9;
+  uint8_t       periodic_wideband_cqi[NFAPI_CC_MAX];
+  uint8_t       periodic_wideband_spatial_diffcqi[NFAPI_CC_MAX];
+  uint8_t       periodic_wideband_pmi[NFAPI_CC_MAX];
+  uint8_t       periodic_subband_cqi[NFAPI_CC_MAX][16];
+  uint8_t       periodic_subband_spatial_diffcqi[NFAPI_CC_MAX][16];
+  uint8_t       aperiodic_subband_cqi0[NFAPI_CC_MAX][25];
+  uint8_t       aperiodic_subband_pmi[NFAPI_CC_MAX][25];
+  uint8_t       aperiodic_subband_diffcqi0[NFAPI_CC_MAX][25];
+  uint8_t       aperiodic_subband_cqi1[NFAPI_CC_MAX][25];
+  uint8_t       aperiodic_subband_diffcqi1[NFAPI_CC_MAX][25];
+  uint8_t       aperiodic_wideband_cqi0[NFAPI_CC_MAX];
+  uint8_t       aperiodic_wideband_pmi[NFAPI_CC_MAX];
+  uint8_t       aperiodic_wideband_cqi1[NFAPI_CC_MAX];
+  uint8_t       aperiodic_wideband_pmi1[NFAPI_CC_MAX];
+  uint8_t       dl_cqi[NFAPI_CC_MAX];
+} UE_sched_ctrl;
+/*! \brief eNB template for the Random access information */
+typedef struct {
+  /// Flag to indicate this process is active
+  boolean_t RA_active;
+  /// Size of DCI for RA-Response (bytes)
+  uint8_t RA_dci_size_bytes1;
+  /// Size of DCI for RA-Response (bits)
+  uint8_t RA_dci_size_bits1;
+  /// Actual DCI to transmit for RA-Response
+  uint8_t RA_alloc_pdu1[(MAX_DCI_SIZE_BITS>>3)+1];
+  /// DCI format for RA-Response (should be 1A)
+  uint8_t RA_dci_fmt1;
+  /// Size of DCI for Msg4/ContRes (bytes)
+  uint8_t RA_dci_size_bytes2;
+  /// Size of DCI for Msg4/ContRes (bits)
+  uint8_t RA_dci_size_bits2;
+  /// Actual DCI to transmit for Msg4/ContRes
+  uint8_t RA_alloc_pdu2[(MAX_DCI_SIZE_BITS>>3)+1];
+  /// DCI format for Msg4/ContRes (should be 1A)
+  uint8_t RA_dci_fmt2;
+  /// Flag to indicate the eNB should generate RAR.  This is triggered by detection of PRACH
+  uint8_t generate_rar;
+  /// Subframe where preamble was received
+  uint8_t preamble_subframe;
+  /// Subframe where Msg2 is to be sent
+  uint8_t Msg2_subframe;
+  /// Frame where Msg2 is to be sent
+  frame_t Msg2_frame;
+  /// Subframe where Msg3 is to be sent
+  sub_frame_t Msg3_subframe;
+  /// Frame where Msg3 is to be sent
+  frame_t Msg3_frame;
+  /// Subframe where Msg4 is to be sent
+  sub_frame_t Msg4_subframe;
+  /// Frame where Msg4 is to be sent
+  frame_t Msg4_frame;
+  /// Flag to indicate the eNB should generate Msg4 upon reception of SDU from RRC.  This is triggered by first ULSCH reception at eNB for new user.
+  uint8_t generate_Msg4;
+  /// Flag to indicate that eNB is waiting for ACK that UE has received Msg3.
+  uint8_t wait_ack_Msg4;
+  /// harq_pid used for Msg4 transmission
+  uint8_t harq_pid;
+  /// UE RNTI allocated during RAR
+  rnti_t rnti;
+  /// RA RNTI allocated from received PRACH
+  uint16_t RA_rnti;
+  /// Received preamble_index
+  uint8_t preamble_index;
+  /// Received UE Contention Resolution Identifier
+  uint8_t cont_res_id[6];
+  /// Timing offset indicated by PHY
+  int16_t timing_offset;
+  /// Timeout for RRC connection
+  int16_t RRC_timer;
+  /// Msg3 first RB
+  uint8_t msg3_first_rb;
+  /// Msg3 number of RB
+  uint8_t msg3_nb_rb;
+  /// Msg3 MCS
+  uint8_t msg3_mcs;
+  /// Msg3 TPC command
+  uint8_t msg3_TPC;
+  /// Msg3 ULdelay command
+  uint8_t msg3_ULdelay;
+  /// Msg3 cqireq command
+  uint8_t msg3_cqireq;
+  /// Round of Msg3 HARQ
+  uint8_t msg3_round;
+  /// TBS used for Msg4
+  int msg4_TBsize;
+  /// MCS used for Msg4
+  int msg4_mcs;
+  /// size off piggybacked RRC SDU
+  uint8_t msg4_rrc_sdu_length;
+  uint32_t msg4_delay;
+
+#ifdef Rel14
+  uint8_t rach_resource_type;
+  uint8_t msg2_mpdcch_repetition_cnt;
+  uint8_t msg2_mpdcch_done;
+  uint8_t msg4_mpdcch_repetition_cnt;
+  uint8_t msg4_mpdcch_done;
+  uint8_t msg2_narrowband;
+  uint32_t msg34_narrowband;
+#endif
+} RA_TEMPLATE;
+
+
+/*! \brief subband bitmap confguration (for ALU icic algo purpose), in test phase */
+typedef struct {
+  uint8_t sbmap[NUMBER_OF_SUBBANDS_MAX]; //13 = number of SB MAX for 100 PRB
+  uint8_t periodicity;
+  uint8_t first_subframe;
+  uint8_t sb_size;
+  uint8_t nb_active_sb;
+} SBMAP_CONF;
+/*! \brief UE list used by eNB to order UEs/CC for scheduling*/
+typedef struct {
+  /// Dedicated information for UEs
+  struct PhysicalConfigDedicated  *physicalConfigDedicated[MAX_NUM_CCs][NUMBER_OF_UE_MAX];
+  /// DLSCH pdu
+  DLSCH_PDU DLSCH_pdu[MAX_NUM_CCs][2][NUMBER_OF_UE_MAX];
+  /// DCI template and MAC connection parameters for UEs
+  UE_TEMPLATE UE_template[MAX_NUM_CCs][NUMBER_OF_UE_MAX];
+  /// DCI template and MAC connection for RA processes
+  int pCC_id[NUMBER_OF_UE_MAX];
+  /// sorted downlink component carrier for the scheduler
+  int ordered_CCids[MAX_NUM_CCs][NUMBER_OF_UE_MAX];
+  /// number of downlink active component carrier
+  int numactiveCCs[NUMBER_OF_UE_MAX];
+  /// sorted uplink component carrier for the scheduler
+  int ordered_ULCCids[MAX_NUM_CCs][NUMBER_OF_UE_MAX];
+  /// number of uplink active component carrier
+  int numactiveULCCs[NUMBER_OF_UE_MAX];
+  /// number of downlink active component carrier
+  uint8_t dl_CC_bitmap[NUMBER_OF_UE_MAX];
+  /// eNB to UE statistics
+  eNB_UE_STATS eNB_UE_stats[MAX_NUM_CCs][NUMBER_OF_UE_MAX];
+  /// scheduling control info
+  UE_sched_ctrl UE_sched_ctrl[NUMBER_OF_UE_MAX];
+  int next[NUMBER_OF_UE_MAX];
+  int head;
+  int next_ul[NUMBER_OF_UE_MAX];
+  int head_ul;
+  int avail;
+  int num_UEs;
+  boolean_t active[NUMBER_OF_UE_MAX];
+} UE_list_t;
+
+/*! \brief eNB common channels */
+typedef struct {
+  int                              physCellId;
+  int                              p_eNB;
+  int                              Ncp;
+  int                              eutra_band;
+  uint32_t                         dl_CarrierFreq;
+  BCCH_BCH_Message_t               *mib;
+  RadioResourceConfigCommonSIB_t   *radioResourceConfigCommon;
+#ifdef Rel14
+  RadioResourceConfigCommonSIB_t   *radioResourceConfigCommon_BR;
+#endif
+  TDD_Config_t                     *tdd_Config;
+  SchedulingInfoList_t             *schedulingInfoList;
+  ARFCN_ValueEUTRA_t               ul_CarrierFreq;
+  long                             ul_Bandwidth;
+  /// Outgoing MIB PDU for PHY
+  MIB_PDU MIB_pdu;
+  /// Outgoing BCCH pdu for PHY
+  BCCH_PDU BCCH_pdu;
+  /// Outgoing BCCH DCI allocation
+  uint32_t BCCH_alloc_pdu;
+  /// Outgoing CCCH pdu for PHY
+  CCCH_PDU CCCH_pdu;
+  /// Outgoing RAR pdu for PHY
+  RAR_PDU RAR_pdu;
+  /// Template for RA computations
+  RA_TEMPLATE RA_template[NB_RA_PROC_MAX];
+  /// VRB map for common channels
+  uint8_t vrb_map[100];
+  /// VRB map for common channels and retransmissions by PHICH
+  uint8_t vrb_map_UL[100];
+  /// MBSFN SubframeConfig
+  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)
+  /// MBMS Flag
+  uint8_t MBMS_flag;
+  /// Outgoing MCCH pdu for PHY
+  MCCH_PDU MCCH_pdu;
+  /// MCCH active flag
+  uint8_t msi_active;
+  /// MCCH active flag
+  uint8_t mcch_active;
+  /// MTCH active flag
+  uint8_t mtch_active;
+  /// number of active MBSFN area
+  uint8_t num_active_mbsfn_area;
+  /// MBSFN Area Info
+  struct  MBSFN_AreaInfo_r9 *mbsfn_AreaInfo[MAX_MBSFN_AREA];
+  /// PMCH Config
+  struct PMCH_Config_r9 *pmch_Config[MAX_PMCH_perMBSFN];
+  /// MBMS session info list
+  struct MBMS_SessionInfoList_r9 *mbms_SessionList[MAX_PMCH_perMBSFN];
+  /// Outgoing MCH pdu for PHY
+  MCH_PDU MCH_pdu;
+#endif
+#ifdef Rel14
+  /// Rel13 parameters from SIB1
+  SystemInformationBlockType1_v1310_IEs_t *sib1_v13ext;
+  /// Counter for SIB1-BR scheduling
+  int SIB1_BR_cnt;
+  /// Outgoing BCCH-BR pdu for PHY
+  BCCH_PDU BCCH_BR_pdu[20];
+#endif
+} COMMON_channels_t;
+/*! \brief top level eNB MAC structure */
+typedef struct eNB_MAC_INST_s {
+  /// Ethernet parameters for northbound midhaul interface
+  eth_params_t         eth_params_n;
+  /// Ethernet parameters for fronthaul interface
+  eth_params_t         eth_params_s;
+  ///
+  module_id_t Mod_id;
+  /// frame counter
+  frame_t frame;
+  /// subframe counter
+  sub_frame_t subframe;
+  /// Pointer to IF module instance for PHY
+  IF_Module_t *if_inst;
+  /// Common cell resources
+  COMMON_channels_t common_channels[MAX_NUM_CCs];
+  /// current PDU index (BCH,MCH,DLSCH)
+  uint16_t pdu_index[MAX_NUM_CCs];
+
+  /// NFAPI Config Request Structure
+  nfapi_config_request_t config[MAX_NUM_CCs];
+  /// Preallocated DL pdu list
+  nfapi_dl_config_request_pdu_t dl_config_pdu_list[MAX_NUM_CCs][MAX_NUM_DL_PDU];
+  /// NFAPI DL Config Request Structure
+  nfapi_dl_config_request_t DL_req[MAX_NUM_CCs];
+  /// Preallocated UL pdu list
+  nfapi_ul_config_request_pdu_t ul_config_pdu_list[MAX_NUM_CCs][MAX_NUM_UL_PDU];
+  /// Preallocated UL pdu list for ULSCH (n+k delay)
+  nfapi_ul_config_request_pdu_t ul_config_pdu_list_tmp[MAX_NUM_CCs][10][MAX_NUM_UL_PDU];
+  /// NFAPI UL Config Request Structure, send to L1 4 subframes before processing takes place
+  nfapi_ul_config_request_t UL_req[MAX_NUM_CCs];
+  /// NFAPI "Temporary" UL Config Request Structure, holds future UL_config requests
+  nfapi_ul_config_request_t UL_req_tmp[MAX_NUM_CCs][10];
+  /// Preallocated HI_DCI0 pdu list
+  nfapi_hi_dci0_request_pdu_t hi_dci0_pdu_list[MAX_NUM_CCs][MAX_NUM_HI_DCI0_PDU];
+  /// NFAPI HI/DCI0 Config Request Structure
+  nfapi_hi_dci0_request_t HI_DCI0_req[MAX_NUM_CCs];
+  /// Prealocated TX pdu list
+  nfapi_tx_request_pdu_t tx_request_pdu[MAX_NUM_CCs][MAX_NUM_TX_REQUEST_PDU];
+  /// NFAPI DL PDU structure
+  nfapi_tx_request_t TX_req[MAX_NUM_CCs];
+  /// UL handle
+  uint32_t ul_handle;
+  UE_list_t UE_list;
+
+  ///subband bitmap configuration
+  SBMAP_CONF sbmap_conf;
+  /// CCE table used to build DCI scheduling information
+  int CCE_table[MAX_NUM_CCs][800];
+  ///  active flag for Other lcid
+  uint8_t lcid_active[NB_RB_MAX];
+  /// eNB stats
+  eNB_STATS eNB_stats[MAX_NUM_CCs];
+  // MAC function execution peformance profiler
+  /// processing time of eNB scheduler
+  time_stats_t eNB_scheduler;
+  /// processing time of eNB scheduler for SI
+  time_stats_t schedule_si;
+  /// processing time of eNB scheduler for Random access
+  time_stats_t schedule_ra;
+  /// processing time of eNB ULSCH scheduler
+  time_stats_t schedule_ulsch;
+  /// processing time of eNB DCI generation
+  time_stats_t fill_DLSCH_dci;
+  /// processing time of eNB MAC preprocessor
+  time_stats_t schedule_dlsch_preprocessor;
+  /// processing time of eNB DLSCH scheduler
+  time_stats_t schedule_dlsch; // include rlc_data_req + MAC header + preprocessor
+  /// processing time of eNB MCH scheduler
+  time_stats_t schedule_mch;
+  /// processing time of eNB ULSCH reception
+  time_stats_t rx_ulsch_sdu; // include rlc_data_ind
+} eNB_MAC_INST;
+
+/*
+ * UE part
+ */
+
+typedef enum {
+  TYPE0,
+  TYPE1,
+  TYPE1A,
+  TYPE2,
+  TYPE2A,
+  TYPEUESPEC
+} MPDCCH_TYPES_t;
+
+/*!\brief UE layer 2 status */
+typedef enum {
+  CONNECTION_OK=0,
+  CONNECTION_LOST,
+  PHY_RESYNCH,
+  PHY_HO_PRACH
+} UE_L2_STATE_t;
+
+/*!\brief UE scheduling info */
+typedef struct {
+  /// buffer status for each lcgid
+  uint8_t  BSR[MAX_NUM_LCGID]; // should be more for mesh topology
+  /// keep the number of bytes in rlc buffer for each lcgid
+  int32_t  BSR_bytes[MAX_NUM_LCGID];
+  /// after multiplexing buffer remain for each lcid
+  int32_t  LCID_buffer_remain[MAX_NUM_LCID];
+  /// sum of all lcid buffer size
+  uint16_t  All_lcid_buffer_size_lastTTI;
+  /// buffer status for each lcid
+  uint8_t  LCID_status[MAX_NUM_LCID];
+  /// SR pending as defined in 36.321
+  uint8_t  SR_pending;
+  /// SR_COUNTER as defined in 36.321
+  uint16_t SR_COUNTER;
+  /// logical channel group ide for each LCID
+  uint8_t  LCGID[MAX_NUM_LCID];
+  /// retxBSR-Timer, default value is sf2560
+  uint16_t retxBSR_Timer;
+  /// retxBSR_SF, number of subframe before triggering a regular BSR
+  uint16_t retxBSR_SF;
+  /// periodicBSR-Timer, default to infinity
+  uint16_t periodicBSR_Timer;
+  /// periodicBSR_SF, number of subframe before triggering a periodic BSR
+  uint16_t periodicBSR_SF;
+  /// default value is 0: not configured
+  uint16_t sr_ProhibitTimer;
+  /// sr ProhibitTime running
+  uint8_t sr_ProhibitTimer_Running;
+  ///  default value to n5
+  uint16_t maxHARQ_Tx;
+  /// default value is false
+  uint16_t ttiBundling;
+  /// default value is release
+  struct DRX_Config *drx_config;
+  /// default value is release
+  struct MAC_MainConfig__phr_Config *phr_config;
+  ///timer before triggering a periodic PHR
+  uint16_t periodicPHR_Timer;
+  ///timer before triggering a prohibit PHR
+  uint16_t prohibitPHR_Timer;
+  ///DL Pathloss change value
+  uint16_t PathlossChange;
+  ///number of subframe before triggering a periodic PHR
+  int16_t periodicPHR_SF;
+  ///number of subframe before triggering a prohibit PHR
+  int16_t prohibitPHR_SF;
+  ///DL Pathloss Change in db
+  uint16_t PathlossChange_db;
+
+  /// default value is false
+  uint16_t extendedBSR_Sizes_r10;
+  /// default value is false
+  uint16_t extendedPHR_r10;
+
+  //Bj bucket usage per  lcid
+  int16_t Bj[MAX_NUM_LCID];
+  // Bucket size per lcid
+  int16_t bucket_size[MAX_NUM_LCID];
+} UE_SCHEDULING_INFO;
+/*!\brief Top level UE MAC structure */
+typedef struct {
+  uint16_t Node_id;
+  /// RX frame counter
+  frame_t     rxFrame;
+  /// RX subframe counter
+  sub_frame_t rxSubframe;
+  /// TX frame counter
+  frame_t     txFrame;
+  /// TX subframe counter
+  sub_frame_t txSubframe;
+  /// C-RNTI of UE
+  uint16_t crnti;
+  /// C-RNTI of UE before HO
+  rnti_t crnti_before_ho; ///user id (rnti) of connected UEs
+  /// uplink active flag
+  uint8_t ul_active;
+  /// pointer to RRC PHY configuration
+  RadioResourceConfigCommonSIB_t *radioResourceConfigCommon;
+  /// pointer to RACH_ConfigDedicated (NULL when not active, i.e. upon HO completion or T304 expiry)
+  struct RACH_ConfigDedicated *rach_ConfigDedicated;
+  /// pointer to RRC PHY configuration
+  struct PhysicalConfigDedicated *physicalConfigDedicated;
+#if defined(Rel10) || defined(Rel14)
+  /// pointer to RRC PHY configuration SCEll
+  struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10;
+#endif
+  /// pointer to TDD Configuration (NULL for FDD)
+  TDD_Config_t *tdd_Config;
+  /// Number of adjacent cells to measure
+  uint8_t  n_adj_cells;
+  /// Array of adjacent physical cell ids
+  uint32_t adj_cell_id[6];
+  /// Pointer to RRC MAC configuration
+  MAC_MainConfig_t *macConfig;
+  /// Pointer to RRC Measurement gap configuration
+  MeasGapConfig_t  *measGapConfig;
+  /// Pointers to LogicalChannelConfig indexed by LogicalChannelIdentity. Note NULL means LCHAN is inactive.
+  LogicalChannelConfig_t *logicalChannelConfig[MAX_NUM_LCID];
+  /// Scheduling Information
+  UE_SCHEDULING_INFO scheduling_info;
+  /// Outgoing CCCH pdu for PHY
+  CCCH_PDU CCCH_pdu;
+  /// Outgoing RAR pdu for PHY
+  RAR_PDU RAR_pdu;
+  /// Incoming DLSCH pdu for PHY
+  DLSCH_PDU DLSCH_pdu[NUMBER_OF_UE_MAX][2];
+  /// number of attempt for rach
+  uint8_t RA_attempt_number;
+  /// Random-access procedure flag
+  uint8_t RA_active;
+  /// Random-access window counter
+  int8_t RA_window_cnt;
+  /// Random-access Msg3 size in bytes
+  uint8_t RA_Msg3_size;
+  /// Random-access prachMaskIndex
+  uint8_t RA_prachMaskIndex;
+  /// Flag indicating Preamble set (A,B) used for first Msg3 transmission
+  uint8_t RA_usedGroupA;
+  /// Random-access Resources
+  PRACH_RESOURCES_t RA_prach_resources;
+  /// Random-access PREAMBLE_TRANSMISSION_COUNTER
+  uint8_t RA_PREAMBLE_TRANSMISSION_COUNTER;
+  /// Random-access backoff counter
+  int16_t RA_backoff_cnt;
+  /// Random-access variable for window calculation (frame of last change in window counter)
+  uint32_t RA_tx_frame;
+  /// Random-access variable for window calculation (subframe of last change in window counter)
+  uint8_t RA_tx_subframe;
+  /// Random-access Group B maximum path-loss
+  /// Random-access variable for backoff (frame of last change in backoff counter)
+  uint32_t RA_backoff_frame;
+  /// Random-access variable for backoff (subframe of last change in backoff counter)
+  uint8_t RA_backoff_subframe;
+  /// Random-access Group B maximum path-loss
+  uint16_t RA_maxPL;
+  /// Random-access Contention Resolution Timer active flag
+  uint8_t RA_contention_resolution_timer_active;
+  /// Random-access Contention Resolution Timer count value
+  uint8_t RA_contention_resolution_cnt;
+  /// power headroom reporitng reconfigured
+  uint8_t PHR_reconfigured;
+  /// power headroom state as configured by the higher layers
+  uint8_t PHR_state;
+  /// power backoff due to power management (as allowed by P-MPRc) for this cell
+  uint8_t PHR_reporting_active;
+  /// power backoff due to power management (as allowed by P-MPRc) for this cell
+  uint8_t power_backoff_db[NUMBER_OF_eNB_MAX];
+  /// BSR report falg management
+  uint8_t BSR_reporting_active;
+  /// retxBSR-Timer expires flag
+  uint8_t retxBSRTimer_expires_flag;
+  /// periodBSR-Timer expires flag
+  uint8_t periodBSRTimer_expires_flag;
+
+  /// MBSFN_Subframe Configuration
+  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)
+  /// number of active MBSFN area
+  uint8_t num_active_mbsfn_area;
+  /// MBSFN Area Info
+  struct  MBSFN_AreaInfo_r9 *mbsfn_AreaInfo[MAX_MBSFN_AREA];
+  /// PMCH Config
+  struct PMCH_Config_r9 *pmch_Config[MAX_PMCH_perMBSFN];
+  /// MCCH status
+  uint8_t mcch_status;
+  /// MSI status
+  uint8_t msi_status;// could be an array if there are >1 MCH in one MBSFN area
+#endif
+  //#ifdef CBA
+  /// CBA RNTI for each group
+  uint16_t cba_rnti[NUM_MAX_CBA_GROUP];
+  /// last SFN for CBA channel access
+  uint8_t cba_last_access[NUM_MAX_CBA_GROUP];
+  //#endif
+  /// total UE scheduler processing time
+  time_stats_t ue_scheduler; // total
+  /// UE ULSCH tx  processing time inlcuding RLC interface (rlc_data_req) and mac header generation
+  time_stats_t tx_ulsch_sdu;
+  /// UE DLSCH rx  processing time inlcuding RLC interface (mac_rrc_data_ind or mac_rlc_status_ind+mac_rlc_data_ind) and mac header parser
+  time_stats_t rx_dlsch_sdu ;
+  /// UE query for MCH subframe processing time
+  time_stats_t ue_query_mch;
+  /// UE MCH rx processing time
+  time_stats_t rx_mch_sdu;
+  /// UE BCCH rx processing time including RLC interface (mac_rrc_data_ind)
+  time_stats_t rx_si;
+  /// UE PCCH rx processing time including RLC interface (mac_rrc_data_ind)
+  time_stats_t rx_p;
+} UE_MAC_INST;
+/*! \brief ID of the neighboring cells used for HO*/
+typedef struct {
+  uint16_t cell_ids[6];
+  uint8_t n_adj_cells;
+} neigh_cell_id_t;
+
+#include "proto.h"
+/*@}*/
+#endif /*__LAYER2_MAC_DEFS_H__ */
diff --git a/openair2/LAYER2/MAC/eNB_scheduler.c b/openair2/LAYER2/MAC/eNB_scheduler.c
index 8989d43f1bae0afc3e4edefc9960e6155a46a4b8..f0366235aec9e672fcd944cf7b64467a43369941 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler.c
@@ -30,7 +30,7 @@
  */
 
 #include "assertions.h"
-
+#include "targets/RT/USER/lte-softmodem.h"
 #include "LAYER2/MAC/mac.h"
 #include "LAYER2/MAC/mac_extern.h"
 
@@ -64,7 +64,7 @@
 #define DEBUG_eNB_SCHEDULER 1
 
 extern RAN_CONTEXT_t RC;
-extern int phy_test;
+
 
 uint16_t pdcch_order_table[6] = { 31, 31, 511, 2047, 2047, 8191 };
 
@@ -79,8 +79,8 @@ schedule_SRS(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP)
   nfapi_ul_config_request_body_t *ul_req;
   int CC_id, UE_id;
   COMMON_channels_t *cc = RC.mac[module_idP]->common_channels;
-  SoundingRS_UL_ConfigCommon_t *soundingRS_UL_ConfigCommon;
-  struct SoundingRS_UL_ConfigDedicated *soundingRS_UL_ConfigDedicated;
+  LTE_SoundingRS_UL_ConfigCommon_t *soundingRS_UL_ConfigCommon;
+  struct LTE_SoundingRS_UL_ConfigDedicated *soundingRS_UL_ConfigDedicated;
   uint8_t TSFC;
   uint16_t deltaTSFC;		// bitmap
   uint8_t srs_SubframeConfig;
@@ -119,7 +119,7 @@ schedule_SRS(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP)
 		      UE_id);
 	  
 	  if ((soundingRS_UL_ConfigDedicated = UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated->soundingRS_UL_ConfigDedicated) != NULL) {
-	    if (soundingRS_UL_ConfigDedicated->present == SoundingRS_UL_ConfigDedicated_PR_setup) {
+	    if (soundingRS_UL_ConfigDedicated->present == LTE_SoundingRS_UL_ConfigDedicated_PR_setup) {
 	      get_srs_pos(&cc[CC_id],
 			  soundingRS_UL_ConfigDedicated->choice.
 			  setup.srs_ConfigIndex,
@@ -162,7 +162,7 @@ schedule_CSI(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP)
   COMMON_channels_t              *cc;
   nfapi_ul_config_request_body_t *ul_req;
   int                            CC_id, UE_id;
-  struct CQI_ReportPeriodic      *cqi_ReportPeriodic;
+  struct LTE_CQI_ReportPeriodic  *cqi_ReportPeriodic;
   uint16_t                       Npd, N_OFFSET_CQI;
   int                            H;
 
@@ -185,7 +185,7 @@ schedule_CSI(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP)
 
       if (UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated->cqi_ReportConfig) {
 	if ((cqi_ReportPeriodic = UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated->cqi_ReportConfig->cqi_ReportPeriodic) != NULL
-	    && (cqi_ReportPeriodic->present != CQI_ReportPeriodic_PR_release)) {
+	    && (cqi_ReportPeriodic->present != LTE_CQI_ReportPeriodic_PR_release)) {
 	  //Rel8 Periodic CQI/PMI/RI reporting
 
 	  get_csi_params(cc, cqi_ReportPeriodic, &Npd,
@@ -209,7 +209,7 @@ schedule_CSI(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP)
 	    ul_req->number_of_pdus++;
 	    ul_req->tl.tag                                                                   = NFAPI_UL_CONFIG_REQUEST_BODY_TAG;
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 	    // PUT rel10-13 UCI options here
 #endif
 	  } else
@@ -245,7 +245,7 @@ schedule_SR(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP)
   nfapi_ul_config_request_body_t *ul_req_body;
   int                            CC_id;
   int                            UE_id;
-  SchedulingRequestConfig_t      *SRconfig;
+  LTE_SchedulingRequestConfig_t  *SRconfig;
   int                            skip_ue;
   int                            is_harq;
   nfapi_ul_config_sr_information sr;
@@ -269,7 +269,7 @@ schedule_SR(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP)
 		  UE_id);
 
       if ((SRconfig = UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated->schedulingRequestConfig) != NULL) {
-	if (SRconfig->present == SchedulingRequestConfig_PR_setup) {
+	if (SRconfig->present == LTE_SchedulingRequestConfig_PR_setup) {
 	  if (SRconfig->choice.setup.sr_ConfigIndex <= 4) {	// 5 ms SR period
 	    if ((subframeP % 5) != SRconfig->choice.setup.sr_ConfigIndex) continue;
 	  } else if (SRconfig->choice.setup.sr_ConfigIndex <= 14) {	// 10 ms SR period
@@ -312,7 +312,7 @@ schedule_SR(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP)
       LOG_D(MAC,"Frame %d, Subframe %d : Scheduling SR for UE %d/%x is_harq:%d\n",frameP,subframeP,UE_id,UE_list->UE_template[CC_id][UE_id].rnti, is_harq);
 
       // check Rel10 or Rel8 SR
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
       if ((UE_list-> UE_template[CC_id][UE_id].physicalConfigDedicated->ext2)
 	  && (UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated->ext2->schedulingRequestConfig_v1020)
 	  && (UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated->ext2->schedulingRequestConfig_v1020)) {
@@ -447,6 +447,7 @@ clear_nfapi_information(eNB_MAC_INST * eNB, int CC_idP,
     DL_req[CC_idP].dl_config_request_body.number_pdu                          = 0;
     DL_req[CC_idP].dl_config_request_body.number_pdsch_rnti                   = 0;
     DL_req[CC_idP].dl_config_request_body.transmission_power_pcfich           = 6000;
+    DL_req[CC_idP].sfn_sf                                                     = subframeP + (frameP<<4);
 
     HI_DCI0_req->hi_dci0_request_body.sfnsf                                   = subframeP + (frameP<<4);
     HI_DCI0_req->hi_dci0_request_body.number_of_dci                           = 0;
@@ -521,7 +522,7 @@ eNB_dlsch_ulsch_scheduler(module_id_t module_idP, frame_t frameP,
     memset(cc[CC_id].vrb_map_UL, 0, 100);
 
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
     cc[CC_id].mcch_active        = 0;
 #endif
 
@@ -632,7 +633,7 @@ eNB_dlsch_ulsch_scheduler(module_id_t module_idP, frame_t frameP,
   rrc_rx_tx(&ctxt, CC_id);
 #endif
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 
   for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
     if (cc[CC_id].MBMS_flag > 0) {
@@ -661,10 +662,9 @@ eNB_dlsch_ulsch_scheduler(module_id_t module_idP, frame_t frameP,
   }
 
   // This schedules MIB
-
   if ((subframeP == 0) && (frameP & 3) == 0)
       schedule_mib(module_idP, frameP, subframeP);
-  if (phy_test == 0){
+  if (get_softmodem_params()->phy_test == 0){
     // This schedules SI for legacy LTE and eMTC starting in subframeP
     schedule_SI(module_idP, frameP, subframeP);
     // This schedules Paging in subframeP
@@ -685,6 +685,10 @@ 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 (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+    // This schedules DLSCH in subframeP
+    schedule_ue_spec_br(module_idP,frameP,subframeP);
+#endif
     // This schedules DLSCH in subframeP
     if (schedule_ue_spec_p != NULL) {
        schedule_ue_spec_p(module_idP, frameP, subframeP, mbsfn_status);
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_RA.c b/openair2/LAYER2/MAC/eNB_scheduler_RA.c
index efb41267ccf878daf951161eb8979fc675163b54..7b704f2264183268744d601efff506fd27bda9cb 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_RA.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_RA.c
@@ -112,7 +112,7 @@ add_msg3(module_id_t module_idP, int CC_id, RA_t * ra, frame_t frameP,
     nfapi_hi_dci0_request_body_t   *hi_dci0_req_body;
     nfapi_hi_dci0_request_pdu_t    *hi_dci0_pdu;
     uint8_t sf_ahead_dl;
-    uint8_t rvseq[4] = { 0, 2, 3, 1 };
+    uint8_t rvseq[4] = {0, 2, 3, 1};
 
 
     ul_req = &mac->UL_req_tmp[CC_id][ra->Msg3_subframe];
@@ -120,54 +120,41 @@ add_msg3(module_id_t module_idP, int CC_id, RA_t * ra, frame_t frameP,
     AssertFatal(ra->state != IDLE, "RA is not active for RA %X\n",
 		ra->rnti);
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-    if (ra->rach_resource_type > 0) {
-	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_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];
-
-	memset((void *) ul_config_pdu, 0,
-	       sizeof(nfapi_ul_config_request_pdu_t));
-	ul_config_pdu->pdu_type                                                = NFAPI_UL_CONFIG_ULSCH_PDU_TYPE;
-	ul_config_pdu->pdu_size                                                = (uint8_t) (2 + sizeof(nfapi_ul_config_ulsch_pdu));
-	ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.handle                         = mac->ul_handle++;
-        ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.tl.tag                         = NFAPI_UL_CONFIG_REQUEST_ULSCH_PDU_REL8_TAG;
-	ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.rnti                           = ra->rnti;
-	ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.resource_block_start           = narrowband_to_first_rb(cc,
-													ra->msg34_narrowband) + ra->msg3_first_rb;
-	ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.number_of_resource_blocks      = ra->msg3_nb_rb;
-	ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.modulation_type                = 2;
-	ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.cyclic_shift_2_for_drms        = 0;
-	ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.frequency_hopping_enabled_flag = 0;
-	ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.frequency_hopping_bits         = 0;
-	ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.new_data_indication            = 0;
-	ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.redundancy_version             = rvseq[ra->msg3_round];
-	ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.harq_process_number            = ((10 * ra->Msg3_frame) + ra->Msg3_subframe) & 7;
-	ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.ul_tx_mode                     = 0;
-	ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.current_tx_nb                  = 0;
-	ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.n_srs                          = 1;
-	ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.size                           = get_TBS_UL(ra->msg3_mcs, ra->msg3_nb_rb);
-	// Re13 fields
-        ul_config_pdu->ulsch_pdu.ulsch_pdu_rel13.tl.tag                        = NFAPI_UL_CONFIG_REQUEST_ULSCH_PDU_REL13_TAG;
-	ul_config_pdu->ulsch_pdu.ulsch_pdu_rel13.ue_type                       = ra->rach_resource_type > 2 ? 2 : 1;
-	ul_config_pdu->ulsch_pdu.ulsch_pdu_rel13.total_number_of_repetitions   = 1;
-	ul_config_pdu->ulsch_pdu.ulsch_pdu_rel13.repetition_number             = 1;
-	ul_config_pdu->ulsch_pdu.ulsch_pdu_rel13.initial_transmission_sf_io    = (ra->Msg3_frame * 10) + ra->Msg3_subframe;
-	ul_req_body->number_of_pdus++;
-        ul_req_body->tl.tag                                                    = NFAPI_UL_CONFIG_REQUEST_BODY_TAG;
-        ul_req->sfn_sf                                                         = ra->Msg3_frame<<4|ra->Msg3_subframe;
-        ul_req->header.message_id                                              = NFAPI_UL_CONFIG_REQUEST;
-    }				//  if (ra->rach_resource_type>0) {  
-    else
+#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",
+           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",
+           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];
+
+    memset ((void *) ul_config_pdu, 0, sizeof (nfapi_ul_config_request_pdu_t));
+    ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_ULSCH_PDU_TYPE;
+    ul_config_pdu->pdu_size = (uint8_t) (2 + sizeof (nfapi_ul_config_ulsch_pdu));
+    ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.handle = mac->ul_handle++;
+    ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.rnti = ra->rnti;
+    ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.resource_block_start = narrowband_to_first_rb (cc, ra->msg34_narrowband) + ra->msg3_first_rb;
+    ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.number_of_resource_blocks = ra->msg3_nb_rb;
+    ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.modulation_type = 2;
+    ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.cyclic_shift_2_for_drms = 0;
+    ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.frequency_hopping_enabled_flag = 0;
+    ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.frequency_hopping_bits = 0;
+    ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.new_data_indication = 0;
+    ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.redundancy_version = rvseq[ra->msg3_round];
+    ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.harq_process_number = 0;
+    ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.ul_tx_mode = 0;
+    ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.current_tx_nb = 0;
+    ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.n_srs = 1;
+    ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.size = get_TBS_UL (ra->msg3_mcs, ra->msg3_nb_rb);
+    // Re13 fields
+    ul_config_pdu->ulsch_pdu.ulsch_pdu_rel13.ue_type = ra->rach_resource_type > 2 ? 2 : 1;
+    ul_config_pdu->ulsch_pdu.ulsch_pdu_rel13.total_number_of_repetitions = 1;
+    ul_config_pdu->ulsch_pdu.ulsch_pdu_rel13.repetition_number = 1;
+    ul_config_pdu->ulsch_pdu.ulsch_pdu_rel13.initial_transmission_sf_io = (ra->Msg3_frame * 10) + ra->Msg3_subframe;
+    ul_req_body->number_of_pdus++;
+  }                             //  if (ra->rach_resource_type>0) {
+  else
 #endif
     {
 	LOG_D(MAC,
@@ -257,247 +244,224 @@ 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;
+  eNB_MAC_INST *mac = RC.mac[module_idP];
+  COMMON_channels_t *cc = mac->common_channels;
 
-    vrb_map = cc[CC_idP].vrb_map;
-    dl_req = &mac->DL_req[CC_idP].dl_config_request_body;
-    dl_config_pdu = &dl_req->dl_config_pdu_list[dl_req->number_pdu];
-    N_RB_DL = to_prb(cc[CC_idP].mib->message.dl_Bandwidth);
+  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;
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-    int rmax = 0;
-    int rep = 0;
-    int reps = 0;
-    int num_nb = 0;
-
-    first_rb = 0;
-    struct PRACH_ConfigSIB_v1310 *ext4_prach;
-    PRACH_ParametersListCE_r13_t *prach_ParametersListCE_r13;
-    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;
-
-    LOG_D(MAC,"absSF:%d absSF_Msg2:%d ra->rach_resource_type:%d\n",absSF,absSF_Msg2,ra->rach_resource_type);
-
-    if (absSF < absSF_Msg2)
-	return;			// we're not ready yet, need to be to start ==  
-
-    if (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;
-	}
-    }
+  vrb_map = cc[CC_idP].vrb_map;
+  dl_req_body = &mac->DL_req[CC_idP].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);
+
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 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;
+  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 ==
+
+  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;
 
-    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
-
-	// rmax from SIB2 information
-	AssertFatal(rmax < 9, "rmax>8!\n");
-	rmax = 1 << p[ra->rach_resource_type-1]->mpdcch_NumRepetition_RA_r13;
-	// choose r1 by default for RAR (Table 9.1.5-5)
-	rep = 0;
-	// 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 
-	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];
-	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)) {
-	    // MPDCCH configuration for RAR
-	    LOG_D(MAC,
-		  "[eNB %d][RAPROC] Frame %d, Subframe %d : In generate_Msg2, Programming MPDCCH %d repetitions\n",
-		  module_idP, frameP, subframeP, 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.tl.tag                                        = NFAPI_DL_CONFIG_REQUEST_MPDCCH_PDU_REL13_TAG;
-	    dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.dci_format                                    = (ra->rach_resource_type > 1) ? 11 : 10;
-	    dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mpdcch_narrow_band                            = ra->msg2_narrowband;
-	    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_id].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                             = 16;	// OK for CEModeA r1-3 (9.1.5-1b) or CEModeB r1-4
-	    dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.rnti_type                                     = 2;	// RA-RNTI
-	    dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.rnti                                          = ra->RA_rnti;
-	    dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.ce_mode                                       = (ra->rach_resource_type < 3) ? 1 : 2;
-	    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);	// 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                            = 0;
-	    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                = 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;
-	    ra->msg2_mpdcch_repetition_cnt++;
-	    dl_req->number_pdu++;
-            dl_req->tl.tag = NFAPI_DL_CONFIG_REQUEST_BODY_TAG;
-	    ra->Msg2_subframe = (ra->Msg2_subframe + 9) % 10;
-
-            mac->DL_req[CC_idP].sfn_sf = sfnsf_add_subframe(ra->Msg2_frame, ra->Msg2_subframe, 4);	// nFAPI is runnning at TX SFN/SF - ie 4 ahead
-            mac->DL_req[CC_idP].header.message_id = NFAPI_DL_CONFIG_REQUEST;
-	}			//repetition_count==0 && SF condition met
-	if (ra->msg2_mpdcch_repetition_cnt > 0) {	// we're in a stream of repetitions
-	    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);
-
-	    if (ra->msg2_mpdcch_repetition_cnt == reps) {	// this is the last mpdcch repetition
-		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
-		} else {
-		    AssertFatal(1 == 0, "TDD case not done yet\n");
-		}
-	    }			// mpdcch_repetition_count == reps
-	    ra->msg2_mpdcch_repetition_cnt++;
+    }
+  }
 
-	    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);
-		ra->state = WAITMSG3;
-                LOG_D(MAC,"[eNB %d][RAPROC] Frame %d, Subframe %d: state:WAITMSG3\n", module_idP, frameP, subframeP);
+  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
+
+    // rmax from SIB2 information
+    AssertFatal (rmax < 9, "rmax>8!\n");
+    rmax = 1 << p[ra->rach_resource_type - 1]->mpdcch_NumRepetition_RA_r13;
+    // choose r1 by default for RAR (Table 9.1.5-5)
+    rep = 0;
+    // 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
+    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);
+
+    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);
+
+
+      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;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mpdcch_narrow_band = ra->msg2_narrowband;
+      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
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.rnti_type = 2; // RA-RNTI
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.rnti = ra->RA_rnti;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.ce_mode = (ra->rach_resource_type < 3) ? 1 : 2;
+      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.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;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.new_data_indicator = 0;
+      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 = rep;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.tpc = 1;       // N1A_PRB=3 (36.212) => 56 bits
+      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;
+      ra->msg2_mpdcch_repetition_cnt++;
+      dl_req_body->number_pdu++;
+      ra->Msg2_subframe = (ra->Msg2_subframe + 9) % 10;
+
+    }                           //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 (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);
+        } else {
+          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);
+        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);
+
+        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.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_idP].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_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
+        dl_config_pdu->dlsch_pdu.dlsch_pdu_rel10.pdsch_start = cc[CC_idP].sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13->startSymbolBR_r13;
+        // 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.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
+        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);
+        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
+        TX_req->pdu_index = mac->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;
+        mac->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_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.tl.tag                                 = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL8_TAG;
-		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.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                    = ; 
-
-		// Rel10 fields
-                dl_config_pdu->dlsch_pdu.dlsch_pdu_rel10.tl.tag                                = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL10_TAG;
-		dl_config_pdu->dlsch_pdu.dlsch_pdu_rel10.pdsch_start                           = cc[CC_idP].sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13->startSymbolBR_r13;
-		// Rel13 fields
-                dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.tl.tag                                = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL13_TAG;
-		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.initial_transmission_sf_io            = (10 * frameP) + subframeP;
-		dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.drms_table_flag                       = 0;
-		dl_req->number_pdu++;
-
-                mac->DL_req[CC_idP].sfn_sf = (frameP<<4)+subframeP;
-                mac->DL_req[CC_idP].header.message_id = NFAPI_DL_CONFIG_REQUEST;
-
-                LOG_D(MAC,"DL_CONFIG SFN/SF:%d/%d MESSAGE2\n", frameP, subframeP);
-
-		// 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);
-		fill_rar_br(mac, CC_idP, ra, frameP, subframeP,
-			    cc[CC_idP].RAR_pdu.payload,
-			    ra->rach_resource_type - 1);
-		// DL request
-                mac->TX_req[CC_idP].tx_request_body.tl.tag = NFAPI_TX_REQUEST_BODY_TAG;
-                mac->TX_req[CC_idP].header.message_id = NFAPI_TX_REQUEST;
-		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 
-		TX_req->pdu_index = mac->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;
-		mac->TX_req[CC_idP].tx_request_body.number_of_pdus++;
-		if(RC.mac[module_idP]->scheduler_mode == SCHED_MODE_FAIR_RR){
-    		  set_dl_ue_select_msg2(CC_idP, 4, -1, ra->rnti);
-		}
-	    }
-	}
+  } else
 
-    } else
 #endif
     {
 
@@ -538,10 +502,10 @@ generate_Msg2(module_id_t module_idP, int CC_idP, frame_t frameP,
 		LOG_D(MAC,
 		      "Frame %d: Subframe %d : Adding common DCI for RA_RNTI %x\n",
 		      frameP, subframeP, ra->RA_rnti);
-		dl_req->number_dci++;
-		dl_req->number_pdu++;
+		dl_req_body->number_dci++;
+		dl_req_body->number_pdu++;
 
-		dl_config_pdu = &dl_req->dl_config_pdu_list[dl_req->number_pdu];
+		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));
@@ -568,7 +532,7 @@ generate_Msg2(module_id_t module_idP, int CC_idP, frame_t frameP,
 		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_req->number_pdu++;
+		dl_req_body->number_pdu++;
                 mac->DL_req[CC_idP].sfn_sf = frameP<<4 | subframeP;
 
 		// Program UL processing for Msg3
@@ -584,6 +548,11 @@ generate_Msg2(module_id_t module_idP, int CC_idP, frame_t frameP,
 		ra->state = WAITMSG3;
                 LOG_D(MAC,"[eNB %d][RAPROC] Frame %d, Subframe %d: state:WAITMSG3\n", module_idP, frameP, subframeP);
 
+                T(T_ENB_MAC_UE_DL_RAR_PDU_WITH_DATA, T_INT(module_idP),
+                  T_INT(CC_idP), T_INT(ra->RA_rnti), T_INT(frameP),
+                  T_INT(subframeP), T_INT(0 /*harq_pid always 0? */ ),
+                  T_BUFFER(cc[CC_idP].RAR_pdu.payload, 7));
+
 		// DL request
 		mac->TX_req[CC_idP].sfn_sf = (frameP << 4) + subframeP;
 		TX_req =
@@ -607,7 +576,6 @@ 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;
@@ -615,7 +583,6 @@ generate_Msg4(module_id_t module_idP, int CC_idP, frame_t frameP,
   uint16_t msg4_padding;
   uint16_t msg4_post_padding;
   uint16_t msg4_header;
-
   uint8_t                         *vrb_map;
   int                             first_rb;
   int                             N_RB_DL;
@@ -626,72 +593,70 @@ generate_Msg4(module_id_t module_idP, int CC_idP, frame_t frameP,
   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;
-  nfapi_ul_config_request_t      *ul_req;
   uint8_t                         lcid;
   uint8_t                         offset;
 
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-    int rmax = 0;
-    int rep = 0;
-    int reps = 0;
-
-
-    first_rb = 0;
-    struct PRACH_ConfigSIB_v1310 *ext4_prach;
-    struct PUCCH_ConfigCommon_v1310 *ext4_pucch;
-    PRACH_ParametersListCE_r13_t *prach_ParametersListCE_r13;
-    struct N1PUCCH_AN_InfoList_r13 *pucch_N1PUCCH_AN_InfoList_r13;
-    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].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;
-	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
-	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_Level2_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_Level2_r13 != NULL,
-			"pucch_NumRepetitionCE_Msg4_Level0 shouldn't be NULL\n");
-	    pucchreps[0] =(int) (1 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level0_r13);
-	default:
-	    AssertFatal(1 == 0,
-			"Illegal count for prach_ParametersListCE_r13 %d\n",
-			prach_ParametersListCE_r13->list.count);
-	}
+
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 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;
+  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) {
+
+    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;
+    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
+    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);
+
     }
+  }
+
 #endif
 
+
     vrb_map = cc[CC_idP].vrb_map;
 
     dl_req        = &mac->DL_req[CC_idP];
@@ -700,7 +665,11 @@ generate_Msg4(module_id_t module_idP, int CC_idP, frame_t frameP,
     N_RB_DL = to_prb(cc[CC_idP].mib->message.dl_Bandwidth);
 
     UE_id = find_UE_id(module_idP, ra->rnti);
-    AssertFatal(UE_id >= 0, "Can't find UE for t-crnti\n");
+    if (UE_id < 0) {
+      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;
+    }
 
     // set HARQ process round to 0 for this UE
 
@@ -722,291 +691,241 @@ generate_Msg4(module_id_t module_idP, int CC_idP, frame_t frameP,
 	  module_idP, CC_idP, frameP, subframeP, UE_id, rrc_sdu_length);*/
 
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-    if (ra->rach_resource_type > 0) {
-
-	// Generate DCI + repetitions first
-	// This uses an MPDCCH Type 2 allocation according to Section 9.1.5 36-213, Type2 common allocation according to Table 7.1-8 (36-213)
-	// Parameters:
-	//    p=2+4 PRB set (number of PRB pairs 6)
-	//    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
-	rmax = p[ra->rach_resource_type - 1]->mpdcch_NumRepetition_RA_r13;
-	AssertFatal(rmax >= 4,
-		    "choose rmax>=4 for enough repeititions, or reduce rep to 1 or 2\n");
-
-	// choose r3 by default for Msg4 (this is ok from table 9.1.5-3 for rmax = >=4, if we choose rmax <4 it has to be less
-	rep = 2;
-	// get actual repetition count from Table 9.1.5-3
-	reps = (rmax <= 8) ? (1 << rep) : (rmax >> (3 - rep));
-	// get first narrowband
-	first_rb =
-	    narrowband_to_first_rb(&cc[CC_idP], ra->msg34_narrowband);
-
-	if ((ra->msg4_mpdcch_repetition_cnt == 0) &&
-	    (mpdcch_sf_condition
-	     (mac, CC_idP, frameP, subframeP, rmax, TYPE2, -1) > 0)) {
-	    // MPDCCH configuration for RAR
-
-	    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.tl.tag = NFAPI_DL_CONFIG_REQUEST_MPDCCH_PDU_REL13_TAG;
-	    dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.dci_format = (ra->rach_resource_type > 1) ? 11 : 10;
-	    dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mpdcch_narrow_band = ra->msg34_narrowband;
-	    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;
-	    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 = 16;	// OK for CEModeA r1-3 (9.1.5-1b) or CEModeB r1-4
-	    dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.rnti_type = 0;	// t-C-RNTI
-	    dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.rnti = ra->RA_rnti;
-	    dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.ce_mode = (ra->rach_resource_type < 3) ? 1 : 2;
-	    dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.drms_scrambling_init = cc[CC_idP].physCellId;	/// Check this is still N_id_cell for type2 common
-	    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);	// check if not getRIV(N_RB_DL,first_rb,6);
-	    dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mcs = 4;	// adjust according to size of Msg4, 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 = 0;
-	    dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.harq_process = ra->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; => 208 bits
-	    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;
-	    ra->msg4_mpdcch_repetition_cnt++;
-	    dl_req_body->number_pdu++;
-            dl_req_body->tl.tag = NFAPI_DL_CONFIG_REQUEST_BODY_TAG;
-
-            dl_req->sfn_sf = (ra->Msg4_frame<<4)+ra->Msg4_subframe;
-            dl_req->header.message_id = NFAPI_DL_CONFIG_REQUEST;
-
-	}			//repetition_count==0 && SF condition met
-	else if (ra->msg4_mpdcch_repetition_cnt > 0) {	// we're in a stream of repetitions
-	    ra->msg4_mpdcch_repetition_cnt++;
-	    if (ra->msg4_mpdcch_repetition_cnt == reps) {	// this is the last mpdcch repetition
-		if (cc[CC_idP].tdd_Config == NULL) {	// FDD case
-		    // wait 2 subframes for PDSCH transmission
-		    if (subframeP > 7)
-			ra->Msg4_frame = (frameP + 1) & 1023;
-		    else
-			ra->Msg4_frame = frameP;
-		    ra->Msg4_subframe = (subframeP + 2) % 10;
-		} else {
-		    AssertFatal(1 == 0, "TDD case not done yet\n");
-		}
-	    }			// mpdcch_repetition_count == reps
-	    if ((ra->Msg4_frame == frameP) && (ra->Msg4_subframe == subframeP)) {
-
-		// Program PDSCH
-
-	        // Get RRCConnectionSetup for Piggyback
-	        /*rrc_sdu_length = mac_rrc_data_req(module_idP, CC_idP, frameP, CCCH, 1,	// 1 transport block
-	    				      &cc[CC_idP].CCCH_pdu.payload[0], ENB_FLAG_YES, module_idP, 0);	// not used in this case*/
-	      
-	      rrc_sdu_length = mac_rrc_data_req(module_idP, CC_idP, frameP, CCCH, 
-						UE_RNTI(module_idP,UE_id),1,	// 1 transport block
-						&cc[CC_idP].CCCH_pdu.payload[0], 0);	// not used in this case
-	      
-	      LOG_D(MAC,
-		    "[eNB %d][RAPROC] CC_id %d Frame %d, subframeP %d: UE_id %d, rrc_sdu_length %d\n",
-		    module_idP, CC_idP, frameP, subframeP, UE_id, rrc_sdu_length);
-	      
-	      AssertFatal(rrc_sdu_length > 0,
-			  "[MAC][eNB Scheduler] CCCH not allocated\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);
-
-		AssertFatal(1 == 0,
-			    "Msg4 generation not finished for BL/CE UE\n");
-		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.tl.tag = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL8_TAG;
-		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->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(N_RB_DL, 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->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_rel10.tl.tag = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL10_TAG;
-		dl_config_pdu->dlsch_pdu.dlsch_pdu_rel10.pdsch_start = cc[CC_idP].sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13->startSymbolBR_r13;
-
-                dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL13_TAG;
-		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.initial_transmission_sf_io = (10 * frameP) + subframeP;
-		dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.drms_table_flag = 0;
-		dl_req_body->number_pdu++;
-                dl_req_body->tl.tag = NFAPI_DL_CONFIG_REQUEST_BODY_TAG;
-
-                mac->DL_req[CC_idP].sfn_sf = (frameP<<4)+subframeP;
-                mac->DL_req[CC_idP].header.message_id = NFAPI_DL_CONFIG_REQUEST;
-	
-		ra->state = WAITMSG4ACK;
-                LOG_D(MAC,"[eNB %d][RAPROC] Frame %d, Subframe %d: state:WAITMSG4ACK\n", module_idP, frameP, subframeP);
-
-		lcid = 0;
-
-		UE_list->UE_sched_ctrl[UE_id].round[CC_idP][ra->harq_pid] = 0;
-		msg4_header = 1 + 6 + 1;	// CR header, CR CE, SDU header
-
-		if ((ra->msg4_TBsize - rrc_sdu_length - msg4_header) <= 2) {
-		    msg4_padding = ra->msg4_TBsize - rrc_sdu_length - msg4_header;
-		    msg4_post_padding = 0;
-		} else {
-		    msg4_padding = 0;
-		    msg4_post_padding = ra->msg4_TBsize - rrc_sdu_length - msg4_header - 1;
-		}
-
-		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, 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]
-		offset = generate_dlsch_header((unsigned char *) mac->UE_list.DLSCH_pdu[CC_idP][0][(unsigned char) UE_id].payload[0], 1,	//num_sdus
-					       (unsigned short *) &rrc_sdu_length,	//
-					       &lcid,	// sdu_lcid
-					       255,	// no drx
-					       31,	// no timing advance
-					       ra->cont_res_id,	// contention res id
-					       msg4_padding,	// no padding
-					       msg4_post_padding);
-
-		memcpy((void *) &mac->UE_list.
-		       DLSCH_pdu[CC_idP][0][(unsigned char)UE_id].payload[0][(unsigned char)offset],
-		       &cc[CC_idP].CCCH_pdu.payload[0], rrc_sdu_length);
-
-		// DL request
-		mac->TX_req[CC_idP].sfn_sf = (frameP << 4) + subframeP;
-                mac->TX_req[CC_idP].tx_request_body.tl.tag  = NFAPI_TX_REQUEST_BODY_TAG;
-                mac->TX_req[CC_idP].header.message_id 	    = NFAPI_TX_REQUEST;
-
-		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 = rrc_sdu_length;
-		TX_req->pdu_index = mac->pdu_index[CC_idP]++;
-		TX_req->num_segments = 1;
-		TX_req->segments[0].segment_length = rrc_sdu_length;
-		TX_req->segments[0].segment_data = mac->UE_list.DLSCH_pdu[CC_idP][0][(unsigned char) UE_id].payload[0];
-		mac->TX_req[CC_idP].tx_request_body.number_of_pdus++;
-
-		// Program ACK/NAK for Msg4 PDSCH
-		int absSF = (ra->Msg3_frame * 10) + ra->Msg3_subframe;
-		// see Section 10.2 from 36.213
-		int ackNAK_absSF = absSF + reps + 4;
-		AssertFatal(reps > 2,
-			    "Have to handle programming of ACK when PDSCH repetitions is > 2\n");
-		ul_req = &mac->UL_req_tmp[CC_idP][ackNAK_absSF % 10];
-		ul_req_body = &ul_req->ul_config_request_body;
-		ul_config_pdu = &ul_req_body->ul_config_pdu_list[ul_req_body->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.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL8_TAG;
-		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 = ra->rnti;
-                ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL13_TAG;
-		ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel13.ue_type = (ra->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[ra->rach_resource_type - 1];
-		ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel13.repetition_number = 0;
-
-                ul_req_body->tl.tag                                                                         = NFAPI_UL_CONFIG_REQUEST_BODY_TAG;
-                ul_req->sfn_sf  									    = sfnsf_add_subframe(ra->Msg3_frame, ra->Msg3_subframe, 4);
-                ul_req->header.message_id  								    = NFAPI_UL_CONFIG_REQUEST;
-                LOG_D(MAC,"UL_req_tmp[CC_idP:%d][ackNAK_absSF mod 10:%d] ra->Msg3_frame:%d ra->Msg3_subframe:%d + 4 sfn_sf:%d\n", CC_idP, ackNAK_absSF%10, ra->Msg3_frame, ra->Msg3_subframe, NFAPI_SFNSF2DEC(ul_req->sfn_sf));
-
-		// Note need to keep sending this across reptitions!!!! Not really for PUCCH, to ask small-cell forum, we'll see for the other messages, maybe parameters change across repetitions and FAPI has to provide for that
-		if (cc[CC_idP].tdd_Config == NULL) {	// FDD case
-                  ul_config_pdu->uci_harq_pdu.harq_information.harq_information_rel8_fdd.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL8_FDD_TAG;
-		    ul_config_pdu->uci_harq_pdu.harq_information.harq_information_rel8_fdd.n_pucch_1_0 = n1pucchan[ra->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_rel8_fdd.harq_size = 1;	// 1-bit ACK/NAK
-		} else {
-		    AssertFatal(1 == 0,
-				"PUCCH configuration for ACK/NAK not handled yet for TDD BL/CE case\n");
-		}
-		ul_req_body->number_of_pdus++;
-		T(T_ENB_MAC_UE_DL_PDU_WITH_DATA, T_INT(module_idP),
-		  T_INT(CC_idP), T_INT(ra->rnti), T_INT(frameP),
-		  T_INT(subframeP), T_INT(0 /*harq_pid always 0? */ ),
-		  T_BUFFER(&mac->UE_list.DLSCH_pdu[CC_idP][0][UE_id].
-			   payload[0], ra->msg4_TBsize));
-
-		if (opt_enabled == 1) {
-		    trace_pdu(DIRECTION_DOWNLINK,
-			      (uint8_t *) mac->
-			      UE_list.DLSCH_pdu[CC_idP][0][(unsigned char)UE_id].payload[0],
-			      rrc_sdu_length, UE_id, WS_C_RNTI,
-			      UE_RNTI(module_idP, UE_id), mac->frame,
-			      mac->subframe, 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_idP, frameP, UE_RNTI(module_idP,UE_id),
-			  rrc_sdu_length);
-		}
-		if(RC.mac[module_idP]->scheduler_mode == SCHED_MODE_FAIR_RR){
-        	  set_dl_ue_select_msg4(CC_idP, 4, UE_id, ra->rnti);
-		}
-	    }			// Msg4 frame/subframe
-	}			// msg4_mpdcch_repetition_count
-    }				// rach_resource_type > 0 
-    else
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  if (ra->rach_resource_type > 0) {
+
+    ra->harq_pid = 0;
+    // Generate DCI + repetitions first
+    // This uses an MPDCCH Type 2 allocation according to Section 9.1.5 36-213, Type2 common allocation according to Table 7.1-8 (36-213)
+    // Parameters:
+    //    p=2+4 PRB set (number of PRB pairs 6)
+    //    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
+    rmax = 1<<p[ra->rach_resource_type - 1]->mpdcch_NumRepetition_RA_r13;
+
+
+    // choose r3 by default for Msg4 (this is ok from table 9.1.5-3 for rmax = >=4, if we choose rmax <4 it has to be less
+    rep = 0;
+    // get actual repetition count from Table 9.1.5-3
+    reps = (rmax <= 8) ? (1 << rep) : (rmax >> (3 - rep));
+    // get first narrowband
+    first_rb = narrowband_to_first_rb (&cc[CC_idP], ra->msg34_narrowband);
+
+    if ((ra->msg4_mpdcch_repetition_cnt == 0) && (mpdcch_sf_condition (mac, CC_idP, frameP, subframeP, rmax, TYPE2, -1) > 0)) {
+      // Get RRCConnectionSetup for Piggyback
+      ra->msg4_rrc_sdu_length = mac_rrc_data_req (module_idP, CC_idP, frameP, CCCH, ra->rnti, 1,       // 1 transport block
+							   &cc[CC_idP].CCCH_pdu.payload[0], 0);     // not used in this case
+
+      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);
+
+      // MPDCCH configuration for Msg4
+      ra->msg4_mpdcch_done=0;
+      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;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mpdcch_narrow_band = ra->msg2_narrowband;
+      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
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.rnti_type = 0; // t-CRNTI
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.rnti = ra->rnti;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.ce_mode = (ra->rach_resource_type < 3) ? 1 : 2;
+      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.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 = 0;    // 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 = 0;
+      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 = rep;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.tpc = 3;       // N1A_PRB=3 (36.212) => 56 bits
+      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;
+
+      ra->msg4_mpdcch_repetition_cnt++;
+      dl_req_body->number_pdu++;
+      ra->msg4_TBsize = get_TBS_DL(dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mcs,
+					    6);
+    }                           //repetition_count==0 && SF condition met
+
+    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",
+	    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;
+	if (cc[CC_idP].tdd_Config == NULL) {    // FDD case
+          // wait 2 subframes for PDSCH transmission
+          if (subframeP > 7)
+            ra->Msg4_frame = (frameP + 1) & 1023;
+          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",
+		module_idP, CC_idP, frameP, subframeP, ra->Msg4_frame,ra->Msg4_subframe);
+        } else {
+          AssertFatal (1 == 0, "TDD case not done yet\n");
+        }
+      }
+      else if (ra->msg4_mpdcch_done==0)
+	ra->msg4_mpdcch_repetition_cnt++;
+    }
+// mpdcch_repetition_count == reps
+    else if ((ra->Msg4_frame == frameP) && (ra->Msg4_subframe == subframeP)) {
+
+      // 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",
+	     module_idP, CC_idP, frameP, subframeP, ra->rach_resource_type - 1, ra->rnti);
+
+
+      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->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 (N_RB_DL, 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_idP].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_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                    = ;
+
+      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel10.pdsch_start = cc[CC_idP].sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13->startSymbolBR_r13;
+
+      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.initial_transmission_sf_io = (10 * frameP) + subframeP;
+      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.drms_table_flag = 0;
+      dl_req_body->number_pdu++;
+
+
+      ra->state = WAITMSG4ACK;
+
+      lcid = 0;
+
+      UE_list->UE_sched_ctrl[UE_id].round[CC_idP][ra->harq_pid] = 0;
+      msg4_header = 1 + 6 + 1;        // CR header, CR CE, SDU header
+      AssertFatal((ra->msg4_TBsize - ra->msg4_rrc_sdu_length - msg4_header)>=0,
+		  "msg4_TBS %d is too small, change mcs to increase by %d bytes\n",ra->msg4_TBsize,ra->msg4_rrc_sdu_length+msg4_header-ra->msg4_TBsize);
+      if ((ra->msg4_TBsize - ra->msg4_rrc_sdu_length - msg4_header) <= 2) {
+	msg4_padding = ra->msg4_TBsize - ra->msg4_rrc_sdu_length - msg4_header;
+	msg4_post_padding = 0;
+      } else {
+	msg4_padding = 0;
+	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",
+	     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]
+      offset = generate_dlsch_header ((unsigned char *) mac->UE_list.DLSCH_pdu[CC_idP][0][(unsigned char) UE_id].payload[0], 1,       //num_sdus
+				      (unsigned short *) &ra->msg4_rrc_sdu_length,     //
+				      &lcid,  // sdu_lcid
+				      255,    // no drx
+				      31,     // no timing advance
+				      ra->cont_res_id,       // contention res id
+				      msg4_padding,   // no padding
+				      msg4_post_padding);
+
+      memcpy ((void *) &mac->UE_list.DLSCH_pdu[CC_idP][0][(unsigned char) UE_id].payload[0][(unsigned char) offset], &cc[CC_idP].CCCH_pdu.payload[0], ra->msg4_rrc_sdu_length);
+
+      // DL request
+      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 = ra->msg4_TBsize;
+      TX_req->pdu_index = mac->pdu_index[CC_idP]++;
+      TX_req->num_segments = 1;
+      TX_req->segments[0].segment_length = ra->msg4_TBsize;
+      TX_req->segments[0].segment_data = mac->UE_list.DLSCH_pdu[CC_idP][0][(unsigned char) UE_id].payload[0];
+      mac->TX_req[CC_idP].tx_request_body.number_of_pdus++;
+
+      // Program ACK/NAK for Msg4 PDSCH
+      int             absSF = (frameP * 10) + subframeP;
+      // see Section 10.2 from 36.213
+      int             ackNAK_absSF = absSF + reps + 3;
+      AssertFatal (reps == 1, "Have to handle programming of ACK when PDSCH repetitions is > 1\n");
+      ul_req_body = &mac->UL_req_tmp[CC_idP][ackNAK_absSF % 10].ul_config_request_body;
+      ul_config_pdu = &ul_req_body->ul_config_pdu_list[ul_req_body->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 = ra->rnti;
+      ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel13.ue_type = (ra->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[ra->rach_resource_type - 1];
+      ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel13.repetition_number = 0;
+      // Note need to keep sending this across reptitions!!!! Not really for PUCCH, to ask small-cell forum, we'll see for the other messages, maybe parameters change across repetitions and FAPI has to provide for that
+      if (cc[CC_idP].tdd_Config == NULL) {    // FDD case
+	ul_config_pdu->uci_harq_pdu.harq_information.harq_information_rel9_fdd.n_pucch_1_0 = n1pucchan[ra->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");
+      }
+      ul_req_body->number_of_pdus++;
+      T (T_ENB_MAC_UE_DL_PDU_WITH_DATA, T_INT (module_idP), T_INT (CC_idP), T_INT (ra->rnti), T_INT (frameP), T_INT (subframeP),
+	 T_INT (0 /*harq_pid always 0? */ ), T_BUFFER (&mac->UE_list.DLSCH_pdu[CC_idP][0][UE_id].payload[0], ra->msg4_TBsize));
+
+      if (opt_enabled == 1) {
+	trace_pdu (1, (uint8_t *) mac->UE_list.DLSCH_pdu[CC_idP][0][(unsigned char) UE_id].payload[0], ra->msg4_rrc_sdu_length, UE_id, 3, UE_RNTI (module_idP, UE_id), mac->frame, mac->subframe, 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_idP, frameP, UE_RNTI (module_idP, UE_id), ra->msg4_rrc_sdu_length);
+      }
+    }                           // Msg4 frame/subframe
+  }                             // rach_resource_type > 0
+  else
 #endif
     {
     // This is normal LTE case
@@ -1252,7 +1171,7 @@ check_Msg4_retransmission(module_id_t module_idP, int CC_idP,
 
     int round;
     /*
-       #if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+       #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
        COMMON_channels_t               *cc  = mac->common_channels;
 
        int rmax            = 0;
@@ -1305,7 +1224,7 @@ check_Msg4_retransmission(module_id_t module_idP, int CC_idP,
 
     if (round != 8) {
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 	if (ra->rach_resource_type > 0) {
 	    AssertFatal(1 == 0,
 			"Msg4 Retransmissions not handled yet for BL/CE UEs\n");
@@ -1424,15 +1343,14 @@ schedule_RA(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP)
     RA_t *ra;
     uint8_t i;
 
-    start_meas(&mac->schedule_ra);
 
+    start_meas(&mac->schedule_ra);
 
     for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
 	// skip UL component carriers if TDD
 	if (is_UL_sf(&cc[CC_id], subframeP) == 1)
 	    continue;
 
-
 	for (i = 0; i < NB_RA_PROC_MAX; i++) {
 
 	    ra = (RA_t *) & cc[CC_id].ra[i];
@@ -1441,7 +1359,7 @@ schedule_RA(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP)
 
 	    if (ra->state == MSG2)
 		generate_Msg2(module_idP, CC_id, frameP, subframeP, ra);
-	    else if (ra->state == MSG4 && ra->Msg4_frame == frameP && ra->Msg4_subframe == subframeP )
+		else if (ra->state == MSG4 && ra->Msg4_frame == frameP && ra->Msg4_subframe == subframeP )
 		generate_Msg4(module_idP, CC_id, frameP, subframeP, ra);
 	    else if (ra->state == WAITMSG4ACK)
 		check_Msg4_retransmission(module_idP, CC_id, frameP,
@@ -1451,6 +1369,7 @@ schedule_RA(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP)
     }				// CC_id
 
     stop_meas(&mac->schedule_ra);
+
 }
 
 
@@ -1462,7 +1381,7 @@ initiate_ra_proc(module_id_t module_idP,
 		 sub_frame_t subframeP,
 		 uint16_t preamble_index,
 		 int16_t timing_offset, uint16_t ra_rnti
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 		 , uint8_t rach_resource_type
 #endif
     )
@@ -1472,26 +1391,28 @@ initiate_ra_proc(module_id_t module_idP,
 
     COMMON_channels_t *cc = &RC.mac[module_idP]->common_channels[CC_id];
     RA_t *ra = &cc->ra[0];
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 
-    struct PRACH_ConfigSIB_v1310 *ext4_prach = NULL;
-    PRACH_ParametersListCE_r13_t *prach_ParametersListCE_r13 = NULL;
+    struct LTE_PRACH_ConfigSIB_v1310 *ext4_prach = NULL;
+    LTE_PRACH_ParametersListCE_r13_t *prach_ParametersListCE_r13 = NULL;
   
-    static uint8_t failure_cnt = 0;
 
-    if (cc->radioResourceConfigCommon_BR
-	&& cc->radioResourceConfigCommon_BR->ext4) {
-	ext4_prach = cc->radioResourceConfigCommon_BR->ext4->prach_ConfigCommon_v1310;
-	prach_ParametersListCE_r13 = &ext4_prach->prach_ParametersListCE_r13;
+
+    if (cc->mib->message.schedulingInfoSIB1_BR_r13>0) {
+      AssertFatal(cc->radioResourceConfigCommon_BR != NULL,"radioResourceConfigCommon_BR is null\n");
+      AssertFatal(cc->radioResourceConfigCommon_BR->ext4 != NULL, "radioResourceConfigCommon_BR->ext4 is null\n");
+      ext4_prach = cc->radioResourceConfigCommon_BR->ext4->prach_ConfigCommon_v1310;
+      AssertFatal(ext4_prach!=NULL,"ext4_prach is null\n");
+      prach_ParametersListCE_r13 = &ext4_prach->prach_ParametersListCE_r13;
     }
 
-#endif /* #if (RRC_VERSION >= MAKE_VERSION(14, 0, 0)) */
+#endif /* #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) */
 
     LOG_D(MAC,
 	  "[eNB %d][RAPROC] CC_id %d Frame %d, Subframe %d  Initiating RA procedure for preamble index %d\n",
 	  module_idP, CC_id, frameP, subframeP, preamble_index);
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
     LOG_D(MAC,
 	  "[eNB %d][RAPROC] CC_id %d Frame %d, Subframe %d  PRACH resource type %d\n",
 	  module_idP, CC_id, frameP, subframeP, rach_resource_type);
@@ -1501,7 +1422,9 @@ initiate_ra_proc(module_id_t module_idP,
     uint16_t msg2_subframe = subframeP;
     int offset;
 
-#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
+    static uint8_t failure_cnt = 0 ;
+
+#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
 
     if (prach_ParametersListCE_r13 &&
 	prach_ParametersListCE_r13->list.count < rach_resource_type) {
@@ -1512,7 +1435,7 @@ initiate_ra_proc(module_id_t module_idP,
 	return;
     }
 
-#endif /* #if (RRC_VERSION >= MAKE_VERSION(14, 0, 0)) */
+#endif /* #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) */
 
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_INITIATE_RA_PROC, 1);
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_INITIATE_RA_PROC, 0);
@@ -1526,13 +1449,14 @@ initiate_ra_proc(module_id_t module_idP,
 	    ra[i].Msg4_delay_cnt=0;
 	    ra[i].timing_offset = timing_offset;
 	    ra[i].preamble_subframe = subframeP;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 	    ra[i].rach_resource_type = rach_resource_type;
 	    ra[i].msg2_mpdcch_repetition_cnt = 0;
 	    ra[i].msg4_mpdcch_repetition_cnt = 0;
 #endif
 
 
+
             //TODO Fill in other TDD config. What about nfapi_mode?
             if(cc->tdd_Config!=NULL){
               switch(cc->tdd_Config->subframeAssignment){
@@ -1630,14 +1554,14 @@ cancel_ra_proc(module_id_t module_idP, int CC_id, frame_t frameP,
 	  module_idP, CC_id, frameP, rnti);
 
     for (i = 0; i < NB_RA_PROC_MAX; i++) {
-	if (rnti == ra[i].rnti) {
-	  ra[i].state = IDLE;
-	  ra[i].timing_offset = 0;
-	  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);
-	}
+      if (rnti == ra[i].rnti) {
+        ra[i].state = IDLE;
+        ra[i].timing_offset = 0;
+        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);
+      }
     }
 }
 
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_bch.c b/openair2/LAYER2/MAC/eNB_scheduler_bch.c
index b88a58ec7c99a24d2128f62d03134c6b15a539fb..c1f2e85c6a2a0f7a1dbbf9a2a6a96b7b9e4dc9ba 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_bch.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_bch.c
@@ -59,7 +59,7 @@ extern RAN_CONTEXT_t RC;
 // NEED TO ADD schedule_SI_BR for SIB1_BR and SIB23_BR
 // CCE_allocation_infeasible to be done for EPDCCH/MPDCCH
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 
 #define size_Sj25 2
 int Sj25[size_Sj25] = { 0, 3 };
@@ -301,8 +301,8 @@ schedule_SIB1_BR(module_id_t module_idP,
     }
 }
 
-int si_WindowLength_BR_r13tab[SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13__si_WindowLength_BR_r13_spare] = { 20, 40, 60, 80, 120, 160, 200 };
-int si_TBS_r13tab[SchedulingInfo_BR_r13__si_TBS_r13_b936 + 1] = { 152, 208, 256, 328, 408, 504, 600, 712, 808, 936 };
+int si_WindowLength_BR_r13tab[LTE_SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13__si_WindowLength_BR_r13_spare] = { 20, 40, 60, 80, 120, 160, 200 };
+int si_TBS_r13tab[LTE_SchedulingInfo_BR_r13__si_TBS_r13_b936 + 1] = { 152, 208, 256, 328, 408, 504, 600, 712, 808, 936 };
 
 //------------------------------------------------------------------------------
 void
@@ -310,195 +310,190 @@ schedule_SI_BR(module_id_t module_idP, frame_t frameP,
 	       sub_frame_t subframeP)
 //------------------------------------------------------------------------------
 {
-    int8_t bcch_sdu_length;
-    int CC_id;
-    eNB_MAC_INST *eNB = RC.mac[module_idP];
-    COMMON_channels_t *cc;
-    uint8_t *vrb_map;
-    int first_rb = -1;
-    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;
-    int i;
-    int rvidx;
-    int absSF = (frameP * 10) + subframeP;
-    uint16_t sfn_sf = frameP << 4 | subframeP;
-
-
-    for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
-
-	cc = &eNB->common_channels[CC_id];
-	vrb_map = (void *) &cc->vrb_map;
-	N_RB_DL = to_prb(cc->mib->message.dl_Bandwidth);
-	dl_req = &eNB->DL_req[CC_id].dl_config_request_body;
-
-	// Time-domain scheduling
-	if (cc->mib->message.schedulingInfoSIB1_BR_r13 == 0)
-	    continue;
-	else {
-	    AssertFatal(cc->sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13 != NULL,
-			"sib_v13ext->bandwidthReducedAccessRelatedInfo_r13 is null\n");
-
-	    SchedulingInfoList_BR_r13_t *schedulingInfoList_BR_r13 = cc->sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13->schedulingInfoList_BR_r13;
-	    AssertFatal(schedulingInfoList_BR_r13 != NULL,
-			"sib_v13ext->schedulingInfoList_BR_r13 is null\n");
-
-	    SchedulingInfoList_t *schedulingInfoList = cc->schedulingInfoList;
-	    AssertFatal(schedulingInfoList_BR_r13->list.count == schedulingInfoList->list.count,
-			"schedulingInfolist_BR.r13->list.count %d != schedulingInfoList.list.count %d\n",
-			schedulingInfoList_BR_r13->list.count,
-			schedulingInfoList->list.count);
-
-	    AssertFatal(cc->sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13->si_WindowLength_BR_r13<=SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13__si_WindowLength_BR_r13_ms200,
-			"si_WindowLength_BR_r13 %d > %d\n",
-			(int) cc->sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13->si_WindowLength_BR_r13,
-			SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13__si_WindowLength_BR_r13_ms200);
-
-	    // check that SI frequency-hopping is disabled
-	    AssertFatal(cc->sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13->si_HoppingConfigCommon_r13 == SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13__si_HoppingConfigCommon_r13_off,
-			"Deactivate SI_HoppingConfigCommon_r13 in configuration file, not supported for now\n");
-	    long si_WindowLength_BR_r13 = si_WindowLength_BR_r13tab[cc->sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13->si_WindowLength_BR_r13];
-
-	    long si_RepetitionPattern_r13 = cc->sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13->si_RepetitionPattern_r13;
-	    AssertFatal(si_RepetitionPattern_r13<=SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13__si_RepetitionPattern_r13_every8thRF,
-			"si_RepetitionPattern_r13 %d > %d\n",
-			(int) si_RepetitionPattern_r13,
-			SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13__si_RepetitionPattern_r13_every8thRF);
-	    // cycle through SIB list
-
-	    for (i = 0; i < schedulingInfoList_BR_r13->list.count; i++) {
-		long si_Periodicity = schedulingInfoList->list.array[i]->si_Periodicity;
-		long si_Narrowband_r13 = schedulingInfoList_BR_r13->list.array[i]->si_Narrowband_r13;
-		long si_TBS_r13 = si_TBS_r13tab[schedulingInfoList_BR_r13->list.array[i]->si_TBS_r13];
-
-		// check if the SI is to be scheduled now
-		int period_in_sf = 80 << si_Periodicity;	// 2^i * 80 subframes, note: si_Periodicity is 2^i * 80ms
-		int sf_mod_period = absSF % period_in_sf;
-		int k = sf_mod_period & 3;
-		// Note: definition of k and rvidx from 36.321 section 5.3.1
-		rvidx = (((3 * k) >> 1) + (k & 1)) & 3;
-
-		if ((sf_mod_period < si_WindowLength_BR_r13)
-		    && ((frameP & (((1 << si_RepetitionPattern_r13) - 1))) == 0)) {	// this SIB is to be scheduled
-
-		  bcch_sdu_length = mac_rrc_data_req(module_idP, CC_id, frameP, BCCH_SI_BR + i, 0xFFFF, 1, &cc->BCCH_BR_pdu[i + 1].payload[0], 0);	// not used in this case
-
-		    AssertFatal(bcch_sdu_length > 0,
-				"RRC returned 0 bytes for SI-BR %d\n", i);
-
-		    if (bcch_sdu_length > 0) {
-			AssertFatal(bcch_sdu_length <= (si_TBS_r13 >> 3),
-				    "RRC provided bcch with length %d > %d (si_TBS_r13 %d)\n",
-				    bcch_sdu_length,
-				    (int) (si_TBS_r13 >> 3),
-				    (int) schedulingInfoList_BR_r13->list.array[i]->si_TBS_r13);
-
-			// allocate all 6 PRBs in narrowband for SIB1_BR
-
-			// check that SIB1 didn't take this narrowband
-			if (vrb_map[first_rb] > 0) continue;
-
-			first_rb = narrowband_to_first_rb(cc,si_Narrowband_r13 - 1);
-			vrb_map[first_rb] = 1;
-			vrb_map[first_rb + 1] = 1;
-			vrb_map[first_rb + 2] = 1;
-			vrb_map[first_rb + 4] = 1;
-			vrb_map[first_rb + 5] = 1;
-
-			if ((frameP & 1023) < 200)
-			    LOG_D(MAC,
-				  "[eNB %d] Frame %d Subframe %d: SI_BR->DLSCH CC_id %d, Narrowband %d rvidx %d (sf_mod_period %d : si_WindowLength_BR_r13 %d : si_RepetitionPattern_r13 %d) bcch_sdu_length %d\n",
-				  module_idP, frameP, subframeP, CC_id,
-				  (int) si_Narrowband_r13 - 1, rvidx,
-				  sf_mod_period,
-				  (int) si_WindowLength_BR_r13,
-				  (int) si_RepetitionPattern_r13,
-				  bcch_sdu_length);
-
-
-
-
-			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.tl.tag = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL8_TAG;
-			dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.length = si_TBS_r13 >> 3;
-			dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pdu_index = eNB->pdu_index[CC_id];
-			dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.rnti = 0xFFFF;
-			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(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 = rvidx;
-			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;
-			// Rel10 fields (for PDSCH starting symbol)
-                        dl_config_pdu->dlsch_pdu.dlsch_pdu_rel10.tl.tag = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL10_TAG;
-			dl_config_pdu->dlsch_pdu.dlsch_pdu_rel10.pdsch_start = cc[CC_id].sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13->startSymbolBR_r13;
-			// Rel13 fields
-                        dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL13_TAG;
-			dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.ue_type = 1;	// CEModeA UE
-			dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.pdsch_payload_type = 1;	// SI-BR
-			dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.initial_transmission_sf_io = absSF - sf_mod_period;
-
-			//  dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.bf_vector                    = ; 
-			dl_req->number_pdu++;
-                        dl_req->tl.tag = NFAPI_DL_CONFIG_REQUEST_BODY_TAG;
-
-			// Program TX Request
-			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 = bcch_sdu_length;
-			TX_req->pdu_index = eNB->pdu_index[CC_id]++;
-			TX_req->num_segments = 1;
-			TX_req->segments[0].segment_length = bcch_sdu_length;
-			TX_req->segments[0].segment_data = cc->BCCH_BR_pdu[i + 1].payload;
-			eNB->TX_req[CC_id].tx_request_body.number_of_pdus++;
-                        eNB->TX_req[CC_id].sfn_sf = sfn_sf;
-                        eNB->TX_req[CC_id].tx_request_body.tl.tag = NFAPI_TX_REQUEST_BODY_TAG;
-                        eNB->TX_req[CC_id].header.message_id = NFAPI_TX_REQUEST;
-
-			if (opt_enabled == 1) {
-			    trace_pdu(DIRECTION_DOWNLINK,
-				      &cc->BCCH_BR_pdu[i + 1].payload[0],
-				      bcch_sdu_length,
-				      0xffff,
-				      WS_SI_RNTI,
-				      0xffff, eNB->frame, eNB->subframe, 0,
-				      0);
-			    LOG_D(OPT,
-				  "[eNB %d][BCH] Frame %d trace pdu for CC_id %d rnti %x with size %d\n",
-				  module_idP, frameP, CC_id, 0xffff,
-				  bcch_sdu_length);
-			}
-			if (cc->tdd_Config != NULL) {	//TDD
-			    LOG_D(MAC,
-				  "[eNB] Frame %d : Scheduling BCCH-BR %d->DLSCH (TDD) for CC_id %d SI-BR %d bytes\n",
-				  frameP, i, CC_id, bcch_sdu_length);
-			} else {
-			    LOG_D(MAC,
-				  "[eNB] Frame %d : Scheduling BCCH-BR %d->DLSCH (FDD) for CC_id %d SI-BR %d bytes\n",
-				  frameP, i, CC_id, bcch_sdu_length);
-			}
-		    }
-		}		// scheduling in current frame/subframe
+  int8_t                                  bcch_sdu_length;
+  int                                     CC_id;
+  eNB_MAC_INST                            *eNB = RC.mac[module_idP];
+  COMMON_channels_t                       *cc;
+  uint8_t                                 *vrb_map;
+  int                                     first_rb = -1;
+  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;
+  int                                     i;
+  int                                     rvidx;
+  int                                     absSF = (frameP*10)+subframeP;
+
+
+  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
+
+    cc              = &eNB->common_channels[CC_id];
+    vrb_map         = (void*)&cc->vrb_map;
+    N_RB_DL         = to_prb(cc->mib->message.dl_Bandwidth);
+    dl_req          = &eNB->DL_req[CC_id].dl_config_request_body;
+
+    // Time-domain scheduling
+    if (cc->mib->message.schedulingInfoSIB1_BR_r13==0) continue;
+    else  {
+
+
+      AssertFatal(cc->sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13!=NULL,
+		  "sib_v13ext->bandwidthReducedAccessRelatedInfo_r13 is null\n");
+
+      LTE_SchedulingInfoList_BR_r13_t *schedulingInfoList_BR_r13 = cc->sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13->schedulingInfoList_BR_r13;
+      AssertFatal(schedulingInfoList_BR_r13!=NULL,
+		  "sib_v13ext->schedulingInfoList_BR_r13 is null\n");
+
+      LTE_SchedulingInfoList_t *schedulingInfoList = cc->schedulingInfoList;
+      AssertFatal(schedulingInfoList_BR_r13->list.count==schedulingInfoList->list.count,
+		  "schedulingInfolist_BR.r13->list.count %d != schedulingInfoList.list.count %d\n",
+		  schedulingInfoList_BR_r13->list.count,schedulingInfoList->list.count);
+
+      AssertFatal(cc->sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13->si_WindowLength_BR_r13<=LTE_SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13__si_WindowLength_BR_r13_ms200,
+		  "si_WindowLength_BR_r13 %d > %d\n",
+		  (int)cc->sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13->si_WindowLength_BR_r13,
+		  LTE_SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13__si_WindowLength_BR_r13_ms200);
+
+      // check that SI frequency-hopping is disabled
+      AssertFatal(cc->sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13->si_HoppingConfigCommon_r13==LTE_SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13__si_HoppingConfigCommon_r13_off,
+		  "Deactivate SI_HoppingConfigCommon_r13 in configuration file, not supported for now\n");
+      long si_WindowLength_BR_r13   = si_WindowLength_BR_r13tab[cc->sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13->si_WindowLength_BR_r13];
+
+      long si_RepetitionPattern_r13 = cc->sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13->si_RepetitionPattern_r13;
+      AssertFatal(si_RepetitionPattern_r13<=LTE_SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13__si_RepetitionPattern_r13_every8thRF,
+		  "si_RepetitionPattern_r13 %d > %d\n",
+		  (int)si_RepetitionPattern_r13,
+		  LTE_SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13__si_RepetitionPattern_r13_every8thRF);
+      // cycle through SIB list
+
+      for (i=0;i<schedulingInfoList_BR_r13->list.count;i++) {
+        long si_Periodicity = schedulingInfoList->list.array[i]->si_Periodicity;
+        long si_Narrowband_r13 = schedulingInfoList_BR_r13->list.array[i]->si_Narrowband_r13;
+        long si_TBS_r13 = si_TBS_r13tab[schedulingInfoList_BR_r13->list.array[i]->si_TBS_r13];
+
+        // check if the SI is to be scheduled now
+        int period_in_sf = 80 << si_Periodicity;	// 2^i * 80 subframes, note: si_Periodicity is 2^i * 80ms
+        int sf_mod_period = absSF % period_in_sf;
+        int k = sf_mod_period & 3;
+        // Note: definition of k and rvidx from 36.321 section 5.3.1
+        rvidx = (((3 * k) >> 1) + (k & 1)) & 3;
+
+        if ((sf_mod_period < si_WindowLength_BR_r13)
+            && ((frameP & (((1 << si_RepetitionPattern_r13) - 1))) == 0)) {	// this SIB is to be scheduled
+
+          bcch_sdu_length = mac_rrc_data_req(module_idP, CC_id, frameP, BCCH_SI_BR + i, 0xFFFF, 1, &cc->BCCH_BR_pdu[i + 1].payload[0], 0);	// not used in this case
+
+
+          AssertFatal(bcch_sdu_length > 0,
+          "RRC returned 0 bytes for SI-BR %d\n", i);
+
+          if (bcch_sdu_length > 0) {
+            AssertFatal(bcch_sdu_length <= (si_TBS_r13 >> 3),
+                        "RRC provided bcch with length %d > %d (si_TBS_r13 %d)\n",
+                        bcch_sdu_length,
+                        (int) (si_TBS_r13 >> 3),
+                        (int) schedulingInfoList_BR_r13->list.array[i]->si_TBS_r13);
+
+            // allocate all 6 PRBs in narrowband for SIB1_BR
+
+            // check that SIB1 didn't take this narrowband
+            if (vrb_map[first_rb] > 0) continue;
+
+            first_rb = narrowband_to_first_rb(cc,si_Narrowband_r13 - 1);
+            vrb_map[first_rb] = 1;
+            vrb_map[first_rb + 1] = 1;
+            vrb_map[first_rb + 2] = 1;
+            vrb_map[first_rb + 4] = 1;
+            vrb_map[first_rb + 5] = 1;
+
+            if ((frameP&1023) < 200)
+              LOG_D(MAC,"[eNB %d] Frame %d Subframe %d: SI_BR->DLSCH CC_id %d, Narrowband %d rvidx %d (sf_mod_period %d : si_WindowLength_BR_r13 %d : si_RepetitionPattern_r13 %d) bcch_sdu_length %d\n",
+                   module_idP,frameP,subframeP,CC_id,(int)si_Narrowband_r13-1,rvidx,
+                   sf_mod_period,(int)si_WindowLength_BR_r13,(int)si_RepetitionPattern_r13,
+                   bcch_sdu_length);
+
+
+            //// Rel10 fields (for PDSCH starting symbol)
+            //dl_config_pdu->dlsch_pdu.dlsch_pdu_rel10.pdsch_start = cc[CC_id].sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13->startSymbolBR_r13;
+            //// Rel13 fields
+            //                  dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL13_TAG;
+            //dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.ue_type = 1;	// CEModeA UE
+            //dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.pdsch_payload_type = 1;	// SI-BR
+            //dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.initial_transmission_sf_io = absSF - sf_mod_period;
+
+            ////  dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.bf_vector                    = ;
+            //dl_req->number_pdu++;
+            //                  dl_req->tl.tag = NFAPI_DL_CONFIG_REQUEST_BODY_TAG;
+
+            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.length                                 = si_TBS_r13>>3;
+            dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pdu_index                              = eNB->pdu_index[CC_id];
+            dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.rnti                                   = 0xFFFF;
+            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(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                     = rvidx;
+            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;
+            // Rel10 fields (for PDSCH starting symbol)
+            dl_config_pdu->dlsch_pdu.dlsch_pdu_rel10.pdsch_start                           = cc[CC_id].sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13->startSymbolBR_r13;
+            // Rel13 fields
+            dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.ue_type                               = 1; // CEModeA UE
+            dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.pdsch_payload_type                    = 1; // SI-BR
+            dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.initial_transmission_sf_io            = absSF - sf_mod_period;
+
+            //	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.bf_vector                    = ;
+            dl_req->number_pdu++;
+
+            // Program TX Request
+            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                                                    = bcch_sdu_length;
+            TX_req->pdu_index                                                     = eNB->pdu_index[CC_id]++;
+            TX_req->num_segments                                                  = 1;
+            TX_req->segments[0].segment_length                                    = bcch_sdu_length;
+            TX_req->segments[0].segment_data                                      = cc->BCCH_BR_pdu[i+1].payload;
+            eNB->TX_req[CC_id].tx_request_body.number_of_pdus++;
+
+            if (opt_enabled == 1) {
+                trace_pdu(DIRECTION_DOWNLINK,
+                    &cc->BCCH_BR_pdu[i + 1].payload[0],
+                    bcch_sdu_length,
+                    0xffff,
+                    WS_SI_RNTI,
+                    0xffff, eNB->frame, eNB->subframe, 0,
+                    0);
+                LOG_D(OPT, "[eNB %d][BCH] Frame %d trace pdu for CC_id %d rnti %x with size %d\n",
+                      module_idP, frameP, CC_id, 0xffff, bcch_sdu_length);
+            }
+            if (cc->tdd_Config != NULL) {	//TDD
+                LOG_D(MAC, "[eNB] Frame %d : Scheduling BCCH-BR %d->DLSCH (TDD) for CC_id %d SI-BR %d bytes\n",
+                      frameP, i, CC_id, bcch_sdu_length);
+            } else {
+                LOG_D(MAC, "[eNB] Frame %d : Scheduling BCCH-BR %d->DLSCH (FDD) for CC_id %d SI-BR %d bytes\n",
+                      frameP, i, CC_id, bcch_sdu_length);
+            }
+          }
+        }		// scheduling in current frame/subframe
 	    }			//for SI List
-	}			// eMTC is activated
-    }				// CC_id
-    return;
+    }			// eMTC is activated
+  }				// CC_id
+  return;
 }
 #endif
 
@@ -533,7 +528,7 @@ schedule_mib(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP)
 	    LOG_D(MAC, "Frame %d, subframe %d: Adding BCH PDU in position %d (length %d)\n", frameP, subframeP, dl_req->number_pdu, mib_sdu_length);
 
 	    if ((frameP & 1023) < 40)
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 		LOG_D(MAC,
 		      "[eNB %d] Frame %d : MIB->BCH  CC_id %d, Received %d bytes (cc->mib->message.schedulingInfoSIB1_BR_r13 %d)\n",
 		      module_idP, frameP, CC_id, mib_sdu_length,
@@ -758,6 +753,9 @@ schedule_SI(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP)
 			  module_idP, CC_id, frameP, subframeP);
 		}
 
+                T(T_ENB_MAC_UE_DL_PDU_WITH_DATA, T_INT(module_idP), T_INT(CC_id), T_INT(0xffff),
+                  T_INT(frameP), T_INT(subframeP), T_INT(0), T_BUFFER(cc->BCCH_pdu.payload, bcch_sdu_length));
+
 		if (opt_enabled == 1) {
 		    trace_pdu(DIRECTION_DOWNLINK,
 			      &cc->BCCH_pdu.payload[0],
@@ -789,7 +787,7 @@ schedule_SI(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP)
 	    }
 	}
     }
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
     schedule_SIB1_BR(module_idP, frameP, subframeP);
     schedule_SI_BR(module_idP, frameP, subframeP);
 #endif
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c b/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c
index 0ef94249ab2d0f781c9959daa60c878d3e9000f8..7d37e753ec89b0c58c76b78c10cffc7383280d4e 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c
@@ -47,12 +47,12 @@
 //#include "LAYER2/MAC/pre_processor.c"
 #include "pdcp.h"
 
-#include "SIMULATION/TOOLS/sim.h"	// for taus
+#include "SIMULATION/TOOLS/sim.h" // for taus
 
 #include "assertions.h"
 
 #if defined(ENABLE_ITTI)
-#include "intertask_interface.h"
+  #include "intertask_interface.h"
 #endif
 
 #include <dlfcn.h>
@@ -74,15 +74,12 @@ add_ue_dlsch_info(module_id_t module_idP,
 //------------------------------------------------------------------------------
 {
   //LOG_D(MAC, "%s(module_idP:%d, CC_id:%d, UE_id:%d, subframeP:%d, status:%d) serving_num:%d rnti:%x\n", __FUNCTION__, module_idP, CC_id, UE_id, subframeP, status, eNB_dlsch_info[module_idP][CC_id][UE_id].serving_num, UE_RNTI(module_idP,UE_id));
-
   eNB_dlsch_info[module_idP][CC_id][UE_id].rnti =
-          UE_RNTI(module_idP, UE_id);
+    UE_RNTI(module_idP, UE_id);
   //  eNB_dlsch_info[module_idP][CC_id][ue_mod_idP].weight           = weight;
   eNB_dlsch_info[module_idP][CC_id][UE_id].subframe = subframeP;
   eNB_dlsch_info[module_idP][CC_id][UE_id].status = status;
-
   eNB_dlsch_info[module_idP][CC_id][UE_id].serving_num++;
-
 }
 
 //------------------------------------------------------------------------------
@@ -91,7 +88,6 @@ schedule_next_dlue(module_id_t module_idP, int CC_id,
                    sub_frame_t subframeP)
 //------------------------------------------------------------------------------
 {
-
   int next_ue;
   UE_list_t *UE_list = &RC.mac[module_idP]->UE_list;
 
@@ -111,7 +107,6 @@ schedule_next_dlue(module_id_t module_idP, int CC_id,
   }
 
   return (-1);        //next_ue;
-
 }
 
 //------------------------------------------------------------------------------
@@ -127,11 +122,9 @@ generate_dlsch_header(unsigned char *mac_header,
                       unsigned short post_padding)
 //------------------------------------------------------------------------------
 {
-
   SCH_SUBHEADER_FIXED *mac_header_ptr = (SCH_SUBHEADER_FIXED *) mac_header;
   uint8_t first_element = 0, last_size = 0, i;
   uint8_t mac_header_control_elements[16], *ce_ptr;
-
   ce_ptr = &mac_header_control_elements[0];
 
   // compute header components
@@ -194,10 +187,10 @@ generate_dlsch_header(unsigned char *mac_header,
     if (first_element > 0) {
       mac_header_ptr->E = 1;
       /*
-	printf("[eNB][MAC] last subheader : %x (R%d,E%d,LCID%d)\n",*(unsigned char*)mac_header_ptr,
-	((SCH_SUBHEADER_FIXED *)mac_header_ptr)->R,
-	((SCH_SUBHEADER_FIXED *)mac_header_ptr)->E,
-	((SCH_SUBHEADER_FIXED *)mac_header_ptr)->LCID);
+      printf("[eNB][MAC] last subheader : %x (R%d,E%d,LCID%d)\n",*(unsigned char*)mac_header_ptr,
+      ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->R,
+      ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->E,
+      ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->LCID);
       */
       mac_header_ptr++;
     } else {
@@ -208,16 +201,15 @@ generate_dlsch_header(unsigned char *mac_header,
     mac_header_ptr->E = 0;
     mac_header_ptr->LCID = UE_CONT_RES;
     last_size = 1;
-
     LOG_T(MAC,
           "[eNB ][RAPROC] Generate contention resolution msg: %x.%x.%x.%x.%x.%x\n",
           ue_cont_res_id[0], ue_cont_res_id[1], ue_cont_res_id[2],
           ue_cont_res_id[3], ue_cont_res_id[4], ue_cont_res_id[5]);
-
     memcpy(ce_ptr, ue_cont_res_id, 6);
     ce_ptr += 6;
     // msg("(cont_res) : offset %d\n",ce_ptr-mac_header_control_elements);
   }
+
   //msg("last_size %d,mac_header_ptr %p\n",last_size,mac_header_ptr);
 
   for (i = 0; i < num_sdus; i++) {
@@ -227,9 +219,9 @@ generate_dlsch_header(unsigned char *mac_header,
     if (first_element > 0) {
       mac_header_ptr->E = 1;
       /*msg("last subheader : %x (R%d,E%d,LCID%d)\n",*(unsigned char*)mac_header_ptr,
-	((SCH_SUBHEADER_FIXED *)mac_header_ptr)->R,
-	((SCH_SUBHEADER_FIXED *)mac_header_ptr)->E,
-	((SCH_SUBHEADER_FIXED *)mac_header_ptr)->LCID);
+      ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->R,
+      ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->E,
+      ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->LCID);
       */
       mac_header_ptr += last_size;
       //msg("last_size %d,mac_header_ptr %p\n",last_size,mac_header_ptr);
@@ -255,10 +247,10 @@ generate_dlsch_header(unsigned char *mac_header,
       last_size = 3;
 #ifdef DEBUG_HEADER_PARSING
       LOG_D(MAC,
-        "[eNB] generate long sdu, size %x (MSB %x, LSB %x)\n",
-        sdu_lengths[i],
-        ((SCH_SUBHEADER_LONG *) mac_header_ptr)->L_MSB,
-        ((SCH_SUBHEADER_LONG *) mac_header_ptr)->L_LSB);
+            "[eNB] generate long sdu, size %x (MSB %x, LSB %x)\n",
+            sdu_lengths[i],
+            ((SCH_SUBHEADER_LONG *) mac_header_ptr)->L_MSB,
+            ((SCH_SUBHEADER_LONG *) mac_header_ptr)->L_LSB);
 #endif
     }
   }
@@ -300,10 +292,10 @@ generate_dlsch_header(unsigned char *mac_header,
     memcpy((void *) mac_header_ptr, mac_header_control_elements,
            ce_ptr - mac_header_control_elements);
     mac_header_ptr +=
-            (unsigned char) (ce_ptr - mac_header_control_elements);
+      (unsigned char) (ce_ptr - mac_header_control_elements);
   }
-  //msg("After CEs %d\n",(uint8_t*)mac_header_ptr - mac_header);
 
+  //msg("After CEs %d\n",(uint8_t*)mac_header_ptr - mac_header);
   return ((unsigned char *) mac_header_ptr - mac_header);
 }
 
@@ -313,11 +305,11 @@ set_ul_DAI(int module_idP, int UE_idP, int CC_idP, int frameP,
            int subframeP)
 //------------------------------------------------------------------------------
 {
-
   eNB_MAC_INST *eNB = RC.mac[module_idP];
   UE_list_t *UE_list = &eNB->UE_list;
   unsigned char DAI;
   COMMON_channels_t *cc = &eNB->common_channels[CC_idP];
+
   if (cc->tdd_Config != NULL) {    //TDD
     DAI = (UE_list->UE_template[CC_idP][UE_idP].DAI - 1) & 3;
     LOG_D(MAC,
@@ -332,24 +324,25 @@ set_ul_DAI(int module_idP, int UE_idP, int CC_idP, int frameP,
 
       case 1:
         switch (subframeP) {
-        case 0:
-        case 1:
-          UE_list->UE_template[CC_idP][UE_idP].DAI_ul[7] = DAI;
-        break;
+          case 0:
+          case 1:
+            UE_list->UE_template[CC_idP][UE_idP].DAI_ul[7] = DAI;
+            break;
 
-        case 4:
-          UE_list->UE_template[CC_idP][UE_idP].DAI_ul[8] = DAI;
-          break;
+          case 4:
+            UE_list->UE_template[CC_idP][UE_idP].DAI_ul[8] = DAI;
+            break;
 
-        case 5:
-        case 6:
-          UE_list->UE_template[CC_idP][UE_idP].DAI_ul[2] = DAI;
-          break;
+          case 5:
+          case 6:
+            UE_list->UE_template[CC_idP][UE_idP].DAI_ul[2] = DAI;
+            break;
 
-        case 9:
-          UE_list->UE_template[CC_idP][UE_idP].DAI_ul[3] = DAI;
-          break;
+          case 9:
+            UE_list->UE_template[CC_idP][UE_idP].DAI_ul[3] = DAI;
+            break;
         }
+
         break;
 
       case 2:
@@ -410,7 +403,6 @@ set_ul_DAI(int module_idP, int UE_idP, int CC_idP, int frameP,
 //------------------------------------------------------------------------------
 void
 schedule_dlsch(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP, int *mbsfn_flag) {
-
   int i = 0;
   slice_info_t *sli = &RC.mac[module_idP]->slice_info;
   memset(sli->rballoc_sub, 0, sizeof(sli->rballoc_sub));
@@ -419,10 +411,1103 @@ schedule_dlsch(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP, in
     // Run each enabled slice-specific schedulers one by one
     sli->dl[i].sched_cb(module_idP, i, frameP, subframeP, mbsfn_flag/*, dl_info*/);
   }
-
 }
 
 // changes to pre-processor for eMTC
+//------------------------------------------------------------------------------
+
+void  getRepetition(UE_TEMPLATE * pue_template,unsigned int *maxRep , unsigned int *narrowBandindex){
+    LTE_EPDCCH_SetConfig_r11_t *epdcch_setconfig_r11;
+
+    AssertFatal(pue_template->physicalConfigDedicated !=NULL, "no RRC physical configuration for this UE ") ;
+    AssertFatal(pue_template->physicalConfigDedicated->ext4 !=NULL, "no RRC physical configuration for this UE ") ;
+
+    AssertFatal(pue_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11->list.count > 0 ,"epdcch config list is empty") ;
+
+    epdcch_setconfig_r11 = pue_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11->list.array[0] ;
+
+    AssertFatal(epdcch_setconfig_r11->ext2 !=NULL && epdcch_setconfig_r11->ext2->mpdcch_config_r13 !=NULL," mpdcch config not found")  ;
+
+*maxRep = epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_NumRepetition_r13  ;
+
+    *narrowBandindex = epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13  ;
+
+
+
+
+}
+
+
+
+/*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
@@ -445,7 +1530,6 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
   int harq_pid = 0;
   eNB_UE_STATS *eNB_UE_stats = NULL;
   int 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;
@@ -465,63 +1549,79 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
   int ta_update;
   int header_length_last;
   int header_length_total;
-
+  rrc_eNB_ue_context_t *ue_contextP = NULL;
   start_meas(&eNB->schedule_dlsch);
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_SCHEDULE_DLSCH, VCD_FUNCTION_IN);
 
   // for TDD: check that we have to act here, otherwise return
   if (cc[0].tdd_Config) {
     tdd_sfa = cc[0].tdd_Config->subframeAssignment;
+
     switch (subframeP) {
       case 0:
         // always continue
         break;
+
       case 1:
         return;
         break;
+
       case 2:
         return;
         break;
+
       case 3:
         if ((tdd_sfa != 2) && (tdd_sfa != 5))
           return;
+
         break;
+
       case 4:
         if ((tdd_sfa != 1) && (tdd_sfa != 2) && (tdd_sfa != 4)
             && (tdd_sfa != 5))
           return;
+
         break;
+
       case 5:
         break;
+
       case 6:
       case 7:
         if ((tdd_sfa != 3) && (tdd_sfa != 4) && (tdd_sfa != 5))
           return;
+
         break;
+
       case 8:
         if ((tdd_sfa != 2) && (tdd_sfa != 3) && (tdd_sfa != 4)
             && (tdd_sfa != 5))
           return;
+
         break;
+
       case 9:
         if (tdd_sfa == 0)
           return;
+
         break;
     }
   }
+
   //weight = get_ue_weight(module_idP,UE_id);
   aggregation = 2;
+
   for (CC_id = 0; CC_id < RC.nb_mac_CC[module_idP]; 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];
@@ -533,7 +1633,6 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
   // 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,
                                 slice_idxP,
@@ -542,15 +1641,14 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
                                 mbsfn_flag,
                                 eNB->slice_info.rballoc_sub);
   stop_meas(&eNB->schedule_dlsch_preprocessor);
-
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_DLSCH_PREPROCESSOR, VCD_FUNCTION_OUT);
 
   //RC.mac[module_idP]->slice_info.slice_counter--;
   // Do the multiplexing and actual allocation only when all slices have been pre-processed.
   //if (RC.mac[module_idP]->slice_info.slice_counter > 0) {
-    //stop_meas(&eNB->schedule_dlsch);
-    //VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_SCHEDULE_DLSCH, VCD_FUNCTION_OUT);
-    //return;
+  //stop_meas(&eNB->schedule_dlsch);
+  //VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_SCHEDULE_DLSCH, VCD_FUNCTION_OUT);
+  //return;
   //}
 
   if (RC.mac[module_idP]->slice_info.interslice_share_active) {
@@ -562,7 +1660,6 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
 
   for (CC_id = 0; CC_id < RC.nb_mac_CC[module_idP]; CC_id++) {
     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)
@@ -580,6 +1677,8 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
         continue_flag = 1;
       }
 
+      if (UE_list->UE_template[CC_id][UE_id].rach_resource_type > 0) continue_flag=1;
+
       if (eNB_UE_stats == NULL) {
         LOG_D(MAC, "[eNB] Cannot find eNB_UE_stats\n");
         continue_flag = 1;
@@ -602,13 +1701,15 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
                                           ue_sched_ctl->dl_cqi[CC_id],
                                           format1);
             break;
+
           case 3:
             aggregation = get_aggregation(get_bw_index(module_idP, CC_id),
                                           ue_sched_ctl->dl_cqi[CC_id],
                                           format2A);
             break;
+
           default:
-            LOG_W(MAC, "Unsupported transmission mode %d\n", get_tmode(module_idP, CC_id, UE_id));
+            AssertFatal(1==0,"Unsupported transmission mode %d\n", get_tmode(module_idP, CC_id, UE_id));
             aggregation = 2;
         }
       }
@@ -620,12 +1721,12 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
       }
 
       /* if (continue_flag != 1 */
-      if ((ue_sched_ctl->pre_nb_available_rbs[CC_id] == 0) ||	// no RBs allocated
-	  ccecond) {
-	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 ((ue_sched_ctl->pre_nb_available_rbs[CC_id] == 0) || // no RBs allocated
+          ccecond) {
+        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 TDD
@@ -645,10 +1746,8 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
       }
 
       nb_available_rb = ue_sched_ctl->pre_nb_available_rbs[CC_id];
-      harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frameP ,subframeP);
-
+      harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frameP,subframeP);
       round = ue_sched_ctl->round[CC_id][harq_pid];
-
       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);
       UE_list->eNB_UE_stats[CC_id][UE_id].harq_pid = harq_pid;
@@ -692,21 +1791,20 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
 
       /* process retransmission  */
       if (round != 8) {
-
         // get freq_allocation
         nb_rb = UE_list->UE_template[CC_id][UE_id].nb_rb[harq_pid];
         TBS = get_TBS_DL(UE_list->UE_template[CC_id][UE_id].oldmcs1[harq_pid], nb_rb);
 
-	if (nb_rb <= nb_available_rb) {
-	  if (cc[CC_id].tdd_Config != NULL) {
-	    UE_list->UE_template[CC_id][UE_id].DAI++;
-	    update_ul_dci(module_idP, CC_id, rnti,
-			  UE_list->UE_template[CC_id][UE_id].DAI, subframeP);
-	    LOG_D(MAC,
-		  "DAI update: CC_id %d subframeP %d: UE %d, DAI %d\n",
-		  CC_id, subframeP, UE_id,
-		  UE_list->UE_template[CC_id][UE_id].DAI);
-	  }
+        if (nb_rb <= nb_available_rb) {
+          if (cc[CC_id].tdd_Config != NULL) {
+            UE_list->UE_template[CC_id][UE_id].DAI++;
+            update_ul_dci(module_idP, CC_id, rnti,
+                          UE_list->UE_template[CC_id][UE_id].DAI, subframeP);
+            LOG_D(MAC,
+                  "DAI update: CC_id %d subframeP %d: UE %d, DAI %d\n",
+                  CC_id, subframeP, UE_id,
+                  UE_list->UE_template[CC_id][UE_id].DAI);
+          }
 
           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
@@ -720,6 +1818,7 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
               if (ue_sched_ctl->rballoc_sub_UE[CC_id][j] == 1) {
                 if (UE_list->UE_template[CC_id][UE_id].rballoc_subband[harq_pid][j])
                   printf("WARN: rballoc_subband not free for retrans?\n");
+
                 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))) {
@@ -749,7 +1848,6 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
             case 7:
             default:
               LOG_D(MAC, "retransmission DL_REQ: rnti:%x\n", rnti);
-
               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;
@@ -757,13 +1855,12 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
               dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL8_TAG;
               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),
-                                      ue_sched_ctl->dl_cqi[CC_id],
-                                      format1);
+                get_aggregation(get_bw_index(module_idP, CC_id),
+                                ue_sched_ctl->dl_cqi[CC_id],
+                                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 = 1; // Don't adjust power when retransmitting
               dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_1 = UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
@@ -773,7 +1870,7 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
               // TDD
               if (cc[CC_id].tdd_Config != NULL) {
                 dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.downlink_assignment_index =
-                        (UE_list->UE_template[CC_id][UE_id].DAI - 1) & 3;
+                  (UE_list->UE_template[CC_id][UE_id].DAI - 1) & 3;
                 LOG_D(MAC,
                       "[eNB %d] Retransmission CC_id %d : harq_pid %d, round %d, dai %d, mcs %d\n",
                       module_idP, CC_id, harq_pid, round,
@@ -784,17 +1881,15 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
                       "[eNB %d] Retransmission CC_id %d : harq_pid %d, round %d, mcs %d\n",
                       module_idP, CC_id, harq_pid, round,
                       UE_list->UE_template[CC_id][UE_id].oldmcs1[harq_pid]);
+              }
 
-	    }
-	    if (!CCE_allocation_infeasible(module_idP, CC_id, 1, subframeP,
-					   dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level, rnti)) {
-	      dl_req->number_dci++;
-	      dl_req->number_pdu++;
-	      dl_req->tl.tag = NFAPI_DL_CONFIG_REQUEST_BODY_TAG;
-
-	      eNB->DL_req[CC_id].sfn_sf = frameP<<4 | subframeP;
-	      eNB->DL_req[CC_id].header.message_id = NFAPI_DL_CONFIG_REQUEST;
-
+              if (!CCE_allocation_infeasible(module_idP, CC_id, 1, subframeP,
+                                             dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level, rnti)) {
+                dl_req->number_dci++;
+                dl_req->number_pdu++;
+                dl_req->tl.tag = NFAPI_DL_CONFIG_REQUEST_BODY_TAG;
+                eNB->DL_req[CC_id].sfn_sf = frameP<<4 | subframeP;
+                eNB->DL_req[CC_id].header.message_id = NFAPI_DL_CONFIG_REQUEST;
                 fill_nfapi_dlsch_config(eNB, dl_req, TBS, -1,
                                         /* retransmission, no pdu_index */
                                         rnti, 0, // type 0 allocation from 7.1.6 in 36.213
@@ -807,7 +1902,7 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
                                         cc[CC_id].p_eNB == 1 ? 0 : 1,    // transmission_scheme
                                         1,    // number of layers
                                         1,    // number of subbands
-                        //                      uint8_t codebook_index,
+                                        //                      uint8_t codebook_index,
                                         4,    // UE category capacity
                                         UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated->pdsch_ConfigDedicated->p_a,
                                         0,    // delta_power_offset for TM5
@@ -816,12 +1911,10 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
                                         cc[CC_id].p_eNB == 1 ? 1 : 2,    // transmission mode
                                         0,    //number of PRBs treated as one subband, not used here
                                         0    // number of beamforming vectors, not used here
-                );
-
+                                       );
                 LOG_D(MAC,
                       "Filled NFAPI configuration for DCI/DLSCH %d, retransmission round %d\n",
                       eNB->pdu_index[CC_id], round);
-
                 program_dlsch_acknak(module_idP, CC_id, UE_id, frameP, subframeP,
                                      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.cce_idx);
                 // No TX request for retransmission (check if null request for FAPI)
@@ -833,32 +1926,32 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
           }
 
           add_ue_dlsch_info(module_idP, CC_id, UE_id, subframeP, S_DL_SCHEDULED);
+          //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;
+        } 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 = get_TBS_DL(eNB_UE_stats->dlsch_mcs1, nb_available_rb);
 
-	  //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;
-	} 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 = get_TBS_DL(eNB_UE_stats->dlsch_mcs1, nb_available_rb);
-
-	// add the length for  all the control elements (timing adv, drx, etc) : header + payload
+        // 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 (ta_update != 31)
             ue_sched_ctl->ta_timer = 20;
+
           /* reset ta_update */
           ue_sched_ctl->ta_update = 31;
         } else {
@@ -867,44 +1960,43 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
 
         ta_len = (ta_update != 31) ? 2 : 0;
 
-	// RLC data on DCCH
-	if (TBS - ta_len - header_length_total - sdu_length_total - 3 > 0) {
-	  rlc_status = mac_rlc_status_ind(module_idP, rnti, module_idP, frameP, subframeP, ENB_FLAG_YES, MBMS_FLAG_NO, DCCH,
+        // RLC data on DCCH
+        if (TBS - ta_len - header_length_total - sdu_length_total - 3 > 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_length_total - sdu_length_total - 3
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-                                                    ,0, 0
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                                          ,0, 0
 #endif
-                          );
-
+                                         );
           sdu_lengths[0] = 0;
 
-	  if (rlc_status.bytes_in_buffer > 0) {
-	    LOG_D(MAC, "[eNB %d] SFN/SF %d.%d, DL-DCCH->DLSCH CC_id %d, Requesting %d bytes from RLC (RRC message)\n",
-		  module_idP, frameP, subframeP, CC_id,
-		  TBS - ta_len - header_length_total - sdu_length_total - 3);
-
-	    sdu_lengths[0] = mac_rlc_data_req(module_idP, rnti, module_idP, frameP, ENB_FLAG_YES, MBMS_FLAG_NO, DCCH,
+          if (rlc_status.bytes_in_buffer > 0) {
+            LOG_D(MAC, "[eNB %d] SFN/SF %d.%d, DL-DCCH->DLSCH CC_id %d, Requesting %d bytes from RLC (RRC message)\n",
+                  module_idP, frameP, subframeP, CC_id,
+                  TBS - ta_len - header_length_total - sdu_length_total - 3);
+            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]
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-                          ,0, 0
+                                              (char *)&dlsch_buffer[0]
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                                              ,0, 0
 #endif
-                          );
-
+                                             );
             pthread_mutex_lock(&rrc_release_freelist);
-            if((rrc_release_info.num_UEs > 0) && (rlc_am_mui.rrc_mui_num > 0)){
+
+            if((rrc_release_info.num_UEs > 0) && (rlc_am_mui.rrc_mui_num > 0)) {
               uint16_t release_total = 0;
-              for(uint16_t release_num = 0;release_num < NUMBER_OF_UE_MAX;release_num++){
-                if(rrc_release_info.RRC_release_ctrl[release_num].flag > 0){
+
+              for(uint16_t release_num = 0; release_num < NUMBER_OF_UE_MAX; release_num++) {
+                if(rrc_release_info.RRC_release_ctrl[release_num].flag > 0) {
                   release_total++;
-                }else{
+                } else {
                   continue;
                 }
 
-                if(rrc_release_info.RRC_release_ctrl[release_num].flag == 1){
-                  if(rrc_release_info.RRC_release_ctrl[release_num].rnti == rnti){
-                    for(uint16_t mui_num = 0;mui_num < rlc_am_mui.rrc_mui_num;mui_num++){
-                      if(rrc_release_info.RRC_release_ctrl[release_num].rrc_eNB_mui == rlc_am_mui.rrc_mui[mui_num]){
+                if(rrc_release_info.RRC_release_ctrl[release_num].flag == 1) {
+                  if(rrc_release_info.RRC_release_ctrl[release_num].rnti == rnti) {
+                    for(uint16_t mui_num = 0; mui_num < rlc_am_mui.rrc_mui_num; mui_num++) {
+                      if(rrc_release_info.RRC_release_ctrl[release_num].rrc_eNB_mui == rlc_am_mui.rrc_mui[mui_num]) {
                         rrc_release_info.RRC_release_ctrl[release_num].flag = 3;
                         LOG_D(MAC,"DLSCH Release send:index %d rnti %x mui %d mui_num %d flag 1->3\n",release_num,rnti,rlc_am_mui.rrc_mui[mui_num],mui_num);
                         break;
@@ -912,10 +2004,11 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
                     }
                   }
                 }
-                if(rrc_release_info.RRC_release_ctrl[release_num].flag == 2){
-                  if(rrc_release_info.RRC_release_ctrl[release_num].rnti == rnti){
-                    for(uint16_t mui_num = 0;mui_num < rlc_am_mui.rrc_mui_num;mui_num++){
-                      if(rrc_release_info.RRC_release_ctrl[release_num].rrc_eNB_mui == rlc_am_mui.rrc_mui[mui_num]){
+
+                if(rrc_release_info.RRC_release_ctrl[release_num].flag == 2) {
+                  if(rrc_release_info.RRC_release_ctrl[release_num].rnti == rnti) {
+                    for(uint16_t mui_num = 0; mui_num < rlc_am_mui.rrc_mui_num; mui_num++) {
+                      if(rrc_release_info.RRC_release_ctrl[release_num].rrc_eNB_mui == rlc_am_mui.rrc_mui[mui_num]) {
                         rrc_release_info.RRC_release_ctrl[release_num].flag = 4;
                         LOG_D(MAC,"DLSCH Release send:index %d rnti %x mui %d mui_num %d flag 2->4\n",release_num,rnti,rlc_am_mui.rrc_mui[mui_num],mui_num);
                         break;
@@ -923,17 +2016,19 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
                     }
                   }
                 }
+
                 if(release_total >= rrc_release_info.num_UEs)
                   break;
               }
             }
-            pthread_mutex_unlock(&rrc_release_freelist);
 
+            pthread_mutex_unlock(&rrc_release_freelist);
             RA_t *ra = &eNB->common_channels[CC_id].ra[0];
+
             for (uint8_t ra_ii = 0; ra_ii < NB_RA_PROC_MAX; ra_ii++) {
-              if((ra[ra_ii].rnti == rnti) && (ra[ra_ii].state == MSGCRNTI)){
-                for(uint16_t mui_num = 0;mui_num < rlc_am_mui.rrc_mui_num;mui_num++){
-                  if(ra[ra_ii].crnti_rrc_mui == rlc_am_mui.rrc_mui[mui_num]){
+              if((ra[ra_ii].rnti == rnti) && (ra[ra_ii].state == MSGCRNTI)) {
+                for(uint16_t mui_num = 0; mui_num < rlc_am_mui.rrc_mui_num; mui_num++) {
+                  if(ra[ra_ii].crnti_rrc_mui == rlc_am_mui.rrc_mui[mui_num]) {
                     ra[ra_ii].crnti_harq_pid = harq_pid;
                     ra[ra_ii].state = MSGCRNTI_ACK;
                     break;
@@ -946,26 +2041,21 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
               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;
+            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].lcid_sdu[0] = DCCH;
             UE_list->eNB_UE_stats[CC_id][UE_id].sdu_length_tx[DCCH] = sdu_lengths[0];
-	    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];
-
+            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];
             header_length_last = 1 + 1 + (sdu_lengths[0] >= 128);
             header_length_total += header_length_last;
-
-	    num_sdus = 1;
-
+            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]);
+                  "[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]);
@@ -973,55 +2063,48 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
 
             LOG_T(MAC, "\n");
 #endif
-	  }
-	}
+          }
+        }
 
-	// RLC data on DCCH1
-	if (TBS - ta_len - header_length_total - sdu_length_total - 3 > 0) {
-	  rlc_status = mac_rlc_status_ind(module_idP, rnti, module_idP, frameP, subframeP, ENB_FLAG_YES, MBMS_FLAG_NO, DCCH + 1,
+        // RLC data on DCCH1
+        if (TBS - ta_len - header_length_total - sdu_length_total - 3 > 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_length_total - sdu_length_total - 3
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-                                                    ,0, 0
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                                          ,0, 0
 #endif
                                          );
-
-	  // DCCH SDU
-	  sdu_lengths[num_sdus] = 0;
-
-	  if (rlc_status.bytes_in_buffer > 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 - ta_len - header_length_total - sdu_length_total - 3);
-
-	    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]
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-                          ,0, 0
+          // DCCH SDU
+          sdu_lengths[num_sdus] = 0;
+
+          if (rlc_status.bytes_in_buffer > 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 - ta_len - header_length_total - sdu_length_total - 3);
+            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]
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                                     ,0, 0
 #endif
-	    );
-
+                                                     );
             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];
+            sdu_lcids[num_sdus] = DCCH1;
+            sdu_length_total += sdu_lengths[num_sdus];
             UE_list->eNB_UE_stats[CC_id][UE_id].lcid_sdu[num_sdus] = DCCH1;
             UE_list->eNB_UE_stats[CC_id][UE_id].sdu_length_tx[DCCH1] = sdu_lengths[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];
-
+            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];
             header_length_last = 1 + 1 + (sdu_lengths[num_sdus] >= 128);
             header_length_total += header_length_last;
-
-	    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]);
+                  "[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]);
@@ -1029,79 +2112,92 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
 
             LOG_T(MAC, "\n");
 #endif
+          }
+        }
 
-	  }
-	}
-
-	// TODO: lcid has to be sorted before the actual allocation (similar struct as ue_list).
-	for (lcid = NB_RB_MAX - 1; lcid >= DTCH; lcid--) {
-	  // TODO: check if the lcid is active
-
-	  LOG_D(MAC, "[eNB %d], Frame %d, DTCH%d->DLSCH, Checking RLC status (tbs %d, len %d)\n",
-		module_idP, frameP, lcid, TBS,
+        // TODO: lcid has to be sorted before the actual allocation (similar struct as ue_list).
+        for (lcid = NB_RB_MAX - 1; lcid >= DTCH; lcid--) {
+          // TODO: check if the lcid is active
+          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_length_total - sdu_length_total - 3);
 
-	  if (TBS - ta_len - header_length_total - sdu_length_total - 3 > 0) {
-	    rlc_status = mac_rlc_status_ind(module_idP,
-					    rnti,
-					    module_idP,
-					    frameP,
-					    subframeP,
-					    ENB_FLAG_YES,
-					    MBMS_FLAG_NO,
-					    lcid,
-					    TBS - ta_len - header_length_total - sdu_length_total - 3
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-                                                    ,0, 0
+          if (TBS - ta_len - header_length_total - sdu_length_total - 3 > 0) {
+            rlc_status = mac_rlc_status_ind(module_idP,
+                                            rnti,
+                                            module_idP,
+                                            frameP,
+                                            subframeP,
+                                            ENB_FLAG_YES,
+                                            MBMS_FLAG_NO,
+                                            lcid,
+                                            TBS - ta_len - header_length_total - sdu_length_total - 3
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                                            , 0, 0
 #endif
                                            );
 
-
-
-	    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,
+            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 - ta_len - header_length_total - sdu_length_total - 3,
-		    lcid,
-		    header_length_total);
-
-	      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]
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-                          ,0, 0
+                    lcid,
+                    header_length_total);
+              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]
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                                      , 0, 0
 #endif
-	      );
-
-	      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]++;
+                                                      );
+              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]++;
               UE_list->eNB_UE_stats[CC_id][UE_id].lcid_sdu[num_sdus] = lcid;
               UE_list->eNB_UE_stats[CC_id][UE_id].sdu_length_tx[lcid] = sdu_lengths[num_sdus];
-	      UE_list->eNB_UE_stats[CC_id][UE_id].num_bytes_tx[lcid] += sdu_lengths[num_sdus];
-
+              UE_list->eNB_UE_stats[CC_id][UE_id].num_bytes_tx[lcid] += sdu_lengths[num_sdus];
               header_length_last = 1 + 1 + (sdu_lengths[num_sdus] >= 128);
               header_length_total += header_length_last;
-
-	      num_sdus++;
-
-	      UE_list->UE_sched_ctrl[UE_id].uplane_inactivity_timer = 0;
-	    }
-	  } else {
-            // no TBS left
-	    break;
-	  }
-	}
+              num_sdus++;
+              UE_list->UE_sched_ctrl[UE_id].uplane_inactivity_timer = 0;
+              // 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);
+              }
+            } // end if (rlc_status.bytes_in_buffer > 0)
+          } else {  // no TBS left
+            break;  // break for (lcid = NB_RB_MAX - 1; lcid >= DTCH; lcid--)
+          }
+        }
 
         /* last header does not have length field */
         if (header_length_total) {
@@ -1109,13 +2205,11 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
           header_length_total++;
         }
 
-	// there is at least one SDU or TA command
-	// if (num_sdus > 0 ){
-	if (ta_len + sdu_length_total + header_length_total > 0) {
-
-	  // Now compute number of required RBs for total sdu length
-	  // Assume RAH format 2
-
+        // there is at least one SDU or TA command
+        // if (num_sdus > 0 ){
+        if (ta_len + sdu_length_total + header_length_total > 0) {
+          // Now compute number of required RBs for total sdu length
+          // Assume RAH format 2
           mcs = eNB_UE_stats->dlsch_mcs1;
 
           if (mcs == 0) {
@@ -1123,17 +2217,18 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
           } else {
             nb_rb = min_rb_unit[CC_id];
           }
+
           TBS = get_TBS_DL(mcs, nb_rb);
 
-	  while (TBS < sdu_length_total + header_length_total + ta_len) {
-	    nb_rb += min_rb_unit[CC_id];	//
+          while (TBS < sdu_length_total + header_length_total + 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;
-	    }
+            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);
           }
@@ -1161,41 +2256,40 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
             }
           }
 
-	  // decrease mcs until TBS falls below required length
-	  while ((TBS > sdu_length_total + header_length_total + ta_len) && (mcs > 0)) {
-	    mcs--;
-	    TBS = get_TBS_DL(mcs, nb_rb);
-	  }
+          // decrease mcs until TBS falls below required length
+          while ((TBS > sdu_length_total + header_length_total + 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_length_total + 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);
-	  }
+          // if we have decreased too much or we don't have enough RBs, increase MCS
+          while ((TBS < sdu_length_total + header_length_total + 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);
+                "[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_length_total - sdu_length_total - ta_len <= 2) {
-	    padding = TBS - header_length_total - sdu_length_total - ta_len;
-	    post_padding = 0;
-	  } else {
-	    padding = 0;
-	    post_padding = 1;
-	  }
+          if (TBS - header_length_total - sdu_length_total - ta_len <= 2) {
+            padding = TBS - header_length_total - sdu_length_total - ta_len;
+            post_padding = 0;
+          } else {
+            padding = 0;
+            post_padding = 1;
+          }
 
           offset = generate_dlsch_header((unsigned char *) UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0],
                                          num_sdus,    //num_sdus
@@ -1205,17 +2299,18 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
                                          NULL,    // contention res id
                                          padding, post_padding);
 
-	  //#ifdef DEBUG_eNB_SCHEDULER
-	  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_length %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, nb_rb,
-		  header_length_total);
-	  }
-	  //#endif
+          //#ifdef DEBUG_eNB_SCHEDULER
+          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_length %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, nb_rb,
+                  header_length_total);
+          }
+
+          //#endif
 #ifdef DEBUG_eNB_SCHEDULER
           LOG_T(MAC, "[eNB %d] First 16 bytes of DLSCH : \n");
 
@@ -1225,98 +2320,91 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
 
           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 0
-	  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] = 0;
-	  }
-
-	  if (opt_enabled == 1) {
-	    trace_pdu(DIRECTION_DOWNLINK,
-		      (uint8_t *) UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0],
-		      TBS, module_idP, WS_C_RNTI,
-		      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);
-	  }
+          // fill remainder of DLSCH with 0
+          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] = 0;
+          }
 
-	  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 (opt_enabled == 1) {
+            trace_pdu(DIRECTION_DOWNLINK,
+                      (uint8_t *) UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0],
+                      TBS, module_idP, WS_C_RNTI,
+                      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].rbs_used = nb_rb;
           UE_list->eNB_UE_stats[CC_id][UE_id].num_mac_sdu_tx = num_sdus;
-	  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 = 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].total_rbs_used += 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 = 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;
 
-	  if (cc[CC_id].tdd_Config != NULL) {	// TDD
-	    UE_list->UE_template[CC_id][UE_id].DAI++;
-	    update_ul_dci(module_idP, CC_id, rnti,
-			  UE_list->UE_template[CC_id][UE_id].DAI,
+          if (cc[CC_id].tdd_Config != NULL) { // TDD
+            UE_list->UE_template[CC_id][UE_id].DAI++;
+            update_ul_dci(module_idP, CC_id, rnti,
+                          UE_list->UE_template[CC_id][UE_id].DAI,
                           subframeP);
-	  }
-
-	  // do PUCCH power control
-	  // this is the normalized RX power
-	  eNB_UE_stats = &UE_list->eNB_UE_stats[CC_id][UE_id];
-
-	  /* unit is not dBm, it's special from nfapi */
-	  // converting to dBm: ToDo: Noise power hard coded to 30
-	  normalized_rx_power = (5*ue_sched_ctl->pucch1_snr[CC_id]-640)/10+30;
-	  target_rx_power= eNB->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);
+          // do PUCCH power control
+          // this is the normalized RX power
+          eNB_UE_stats = &UE_list->eNB_UE_stats[CC_id][UE_id];
+          /* unit is not dBm, it's special from nfapi */
+          // converting to dBm: ToDo: Noise power hard coded to 30
+          normalized_rx_power = (5*ue_sched_ctl->pucch1_snr[CC_id]-640)/10+30;
+          target_rx_power= eNB->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
+              }
 
-	    }	// Po_PUCCH has been updated
-	    else {
-	      tpc = 1;	//0
-	    }	// time to do TPC update
-	  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 {
+              tpc = 1;  //0
+            } // time to do TPC update
+          else {
+            tpc = 1;  //0
+          }
 
           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));
@@ -1324,16 +2412,15 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
           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), ue_sched_ctl->dl_cqi[CC_id], format1);
+            get_aggregation(get_bw_index(module_idP, CC_id), ue_sched_ctl->dl_cqi[CC_id], format1);
           dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL8_TAG;
           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];
+            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
@@ -1342,7 +2429,7 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
 
           if (cc[CC_id].tdd_Config != NULL) {    //TDD
             dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.downlink_assignment_index =
-                    (UE_list->UE_template[CC_id][UE_id].DAI - 1) & 3;
+              (UE_list->UE_template[CC_id][UE_id].DAI - 1) & 3;
             LOG_D(MAC,
                   "[eNB %d] Initial transmission CC_id %d : harq_pid %d, dai %d, mcs %d\n",
                   module_idP, CC_id, harq_pid,
@@ -1352,115 +2439,102 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP,
             LOG_D(MAC,
                   "[eNB %d] Initial transmission CC_id %d : harq_pid %d, mcs %d\n",
                   module_idP, CC_id, harq_pid, mcs);
+          }
 
-	  }
-
-	  LOG_D(MAC, "Checking feasibility pdu %d (new sdu)\n",
-		dl_req->number_pdu);
-
-	  if (!CCE_allocation_infeasible(module_idP, CC_id, 1, subframeP,
-					 dl_config_pdu->dci_dl_pdu.
-					 dci_dl_pdu_rel8.aggregation_level, rnti)) {
-	    ue_sched_ctl->round[CC_id][harq_pid] = 0;
-	    dl_req->number_dci++;
-	    dl_req->number_pdu++;
-	    dl_req->tl.tag = NFAPI_DL_CONFIG_REQUEST_BODY_TAG;
+          LOG_D(MAC, "Checking feasibility pdu %d (new sdu)\n",
+                dl_req->number_pdu);
 
+          if (!CCE_allocation_infeasible(module_idP, CC_id, 1, subframeP,
+                                         dl_config_pdu->dci_dl_pdu.
+                                         dci_dl_pdu_rel8.aggregation_level, rnti)) {
+            ue_sched_ctl->round[CC_id][harq_pid] = 0;
+            dl_req->number_dci++;
+            dl_req->number_pdu++;
+            dl_req->tl.tag = NFAPI_DL_CONFIG_REQUEST_BODY_TAG;
             eNB->DL_req[CC_id].sfn_sf = frameP << 4 | subframeP;
             eNB->DL_req[CC_id].header.message_id = NFAPI_DL_CONFIG_REQUEST;
-
             // 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, 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;
-	    AssertFatal(UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated != NULL,
-			"physicalConfigDedicated is NULL\n");
-	    AssertFatal(UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated->pdsch_ConfigDedicated != NULL,
-			"physicalConfigDedicated->pdsch_ConfigDedicated is NULL\n");
-
-	    fill_nfapi_dlsch_config(eNB, dl_req, TBS, eNB->pdu_index[CC_id], rnti, 0,	// type 0 allocation from 7.1.6 in 36.213
-				    0,	// virtual_resource_block_assignment_flag, unused here
-				    0,	// resource_block_coding, to be filled in later
-				    getQm(mcs), 0,	// redundancy version
-				    1,	// transport blocks
-				    0,	// transport block to codeword swap flag
-				    cc[CC_id].p_eNB == 1 ? 0 : 1,	// transmission_scheme
-				    1,	// number of layers
-				    1,	// number of subbands
-				    //                       uint8_t codebook_index,
-				    4,	// UE category capacity
-				    UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated->pdsch_ConfigDedicated->p_a, 0,	// delta_power_offset for TM5
-				    0,	// ngap
-				    0,	// nprb
-				    cc[CC_id].p_eNB == 1 ? 1 : 2,	// transmission mode
-				    0,	//number of PRBs treated as one subband, not used here
-				    0	// number of beamforming vectors, not used here
-				    );
-	    eNB->TX_req[CC_id].sfn_sf = fill_nfapi_tx_req(&eNB->TX_req[CC_id].tx_request_body,
-							  (frameP * 10) + subframeP,
-							  TBS, eNB->pdu_index[CC_id],
-							  eNB->UE_list.DLSCH_pdu[CC_id][0][UE_id].payload[0]);
-
-	    LOG_D(MAC,
-		  "Filled NFAPI configuration for DCI/DLSCH/TXREQ %d, new SDU\n",
-		  eNB->pdu_index[CC_id]);
-
-	    eNB->pdu_index[CC_id]++;
-	    program_dlsch_acknak(module_idP, CC_id, UE_id,
-				 frameP, subframeP,
-				 dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.cce_idx);
-	  } else {
-	    LOG_W(MAC,
-		  "Frame %d, Subframe %d: Dropping DLSCH allocation for UE %d/%x, infeasible CCE allocations\n",
-		  frameP, subframeP, UE_id, rnti);
-	  }
-	} else {	// There is no data from RLC or MAC header, so don't schedule
-
-	}
+            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;
+            AssertFatal(UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated != NULL,
+                        "physicalConfigDedicated is NULL\n");
+            AssertFatal(UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated->pdsch_ConfigDedicated != NULL,
+                        "physicalConfigDedicated->pdsch_ConfigDedicated is NULL\n");
+            fill_nfapi_dlsch_config(eNB, dl_req, TBS, eNB->pdu_index[CC_id], rnti, 0, // type 0 allocation from 7.1.6 in 36.213
+                                    0,  // virtual_resource_block_assignment_flag, unused here
+                                    0,  // resource_block_coding, to be filled in later
+                                    getQm(mcs), 0,  // redundancy version
+                                    1,  // transport blocks
+                                    0,  // transport block to codeword swap flag
+                                    cc[CC_id].p_eNB == 1 ? 0 : 1, // transmission_scheme
+                                    1,  // number of layers
+                                    1,  // number of subbands
+                                    //                       uint8_t codebook_index,
+                                    4,  // UE category capacity
+                                    UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated->pdsch_ConfigDedicated->p_a, 0,  // delta_power_offset for TM5
+                                    0,  // ngap
+                                    0,  // nprb
+                                    cc[CC_id].p_eNB == 1 ? 1 : 2, // transmission mode
+                                    0,  //number of PRBs treated as one subband, not used here
+                                    0 // number of beamforming vectors, not used here
+                                   );
+            eNB->TX_req[CC_id].sfn_sf = fill_nfapi_tx_req(&eNB->TX_req[CC_id].tx_request_body,
+                                        (frameP * 10) + subframeP,
+                                        TBS, eNB->pdu_index[CC_id],
+                                        eNB->UE_list.DLSCH_pdu[CC_id][0][UE_id].payload[0]);
+            LOG_D(MAC,
+                  "Filled NFAPI configuration for DCI/DLSCH/TXREQ %d, new SDU\n",
+                  eNB->pdu_index[CC_id]);
+            eNB->pdu_index[CC_id]++;
+            program_dlsch_acknak(module_idP, CC_id, UE_id,
+                                 frameP, subframeP,
+                                 dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.cce_idx);
+          } else {
+            LOG_W(MAC,
+                  "Frame %d, Subframe %d: Dropping DLSCH allocation for UE %d/%x, infeasible CCE allocations\n",
+                  frameP, subframeP, UE_id, rnti);
+          }
+        } 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
+    }     // 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 dlsch_scheduler_interslice_multiplexing(module_id_t Mod_id,
-                                             int frameP,
-                                             sub_frame_t subframeP,
-                                             uint8_t rballoc_sub[NFAPI_CC_MAX][N_RBG_MAX])
+    int frameP,
+    sub_frame_t subframeP,
+    uint8_t rballoc_sub[NFAPI_CC_MAX][N_RBG_MAX])
 //------------------------------------------------------------------------------
 {
   // FIXME: I'm prototyping the algorithm, so there may be arrays and variables that carry redundant information here and in pre_processor_results struct.
-
   int UE_id, CC_id, rbg, i;
   int N_RB_DL, min_rb_unit, tm;
   int owned, used;
-
   UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list;
   slice_info_t *sli = &RC.mac[Mod_id]->slice_info;
   UE_sched_ctrl *ue_sched_ctl;
   COMMON_channels_t *cc;
   int N_RBG[NFAPI_CC_MAX];
-
   int slice_sorted_list[MAX_NUM_SLICES];
   int slice_idx;
   int8_t free_rbgs_map[NFAPI_CC_MAX][N_RBG_MAX];
   int has_traffic[NFAPI_CC_MAX][MAX_NUM_SLICES];
   uint8_t allocation_mask[NFAPI_CC_MAX][N_RBG_MAX];
-
   uint16_t (*nb_rbs_remaining)[MAX_MOBILES_PER_ENB];
   uint16_t (*nb_rbs_required)[MAX_MOBILES_PER_ENB];
   uint8_t  (*MIMO_mode_indicator)[N_RBG_MAX];
@@ -1473,9 +2547,11 @@ void dlsch_scheduler_interslice_multiplexing(module_id_t Mod_id,
   for (CC_id = 0; CC_id < RC.nb_mac_CC[Mod_id]; ++CC_id) {
     cc = &RC.mac[Mod_id]->common_channels[CC_id];
     N_RBG[CC_id] = to_rbg(cc->mib->message.dl_Bandwidth);
+
     for (rbg = 0; rbg < N_RBG[CC_id]; ++rbg) {
       for (i = 0; i < sli->n_dl; ++i) {
         owned = sli->pre_processor_results[i].slice_allocation_mask[CC_id][rbg];
+
         if (owned) {
           used = rballoc_sub[CC_id][rbg];
           free_rbgs_map[CC_id][rbg] = used ? -1 : i;
@@ -1490,6 +2566,7 @@ void dlsch_scheduler_interslice_multiplexing(module_id_t Mod_id,
   for (CC_id = 0; CC_id < RC.nb_mac_CC[Mod_id]; ++CC_id) {
     for (i = 0; i < sli->n_dl; ++i) {
       has_traffic[CC_id][i] = 0;
+
       for (UE_id = 0; UE_id < MAX_MOBILES_PER_ENB; ++UE_id) {
         if (sli->pre_processor_results[i].nb_rbs_remaining[CC_id][UE_id] > 0) {
           has_traffic[CC_id][i] = 1;
@@ -1504,7 +2581,6 @@ void dlsch_scheduler_interslice_multiplexing(module_id_t Mod_id,
   // MULTIPLEXING
   // This part is an adaptation of dlsch_scheduler_pre_processor_allocate() code
   for (CC_id = 0; CC_id < RC.nb_mac_CC[Mod_id]; ++CC_id) {
-
     N_RB_DL = to_prb(RC.mac[Mod_id]->common_channels[CC_id].mib->message.dl_Bandwidth);
     min_rb_unit = get_min_rb_unit(Mod_id, CC_id);
 
@@ -1520,11 +2596,13 @@ void dlsch_scheduler_interslice_multiplexing(module_id_t Mod_id,
           allocation_mask[CC_id][rbg] = 0;
           continue;
         }
+
         if (sli->dl[free_rbgs_map[CC_id][rbg]].isol == 1) {
           // RBG belongs to an isolated slice
           allocation_mask[CC_id][rbg] = 0;
           continue;
         }
+
         // RBG is free
         allocation_mask[CC_id][rbg] = 1;
       }
@@ -1533,7 +2611,6 @@ void dlsch_scheduler_interslice_multiplexing(module_id_t Mod_id,
       // (UE list gets sorted every time pre_processor is called so it is probably dirty at this point)
       // FIXME: There is only one UE_list for all slices, so it must be sorted again each time we use it
       sort_UEs(Mod_id, slice_idx, frameP, subframeP);
-
       nb_rbs_remaining = sli->pre_processor_results[slice_idx].nb_rbs_remaining;
       nb_rbs_required = sli->pre_processor_results[slice_idx].nb_rbs_required;
       MIMO_mode_indicator = sli->pre_processor_results[slice_idx].MIMO_mode_indicator;
@@ -1544,13 +2621,17 @@ void dlsch_scheduler_interslice_multiplexing(module_id_t Mod_id,
         tm = get_tmode(Mod_id, CC_id, UE_id);
 
         for (rbg = 0; rbg < N_RBG[CC_id]; ++rbg) {
-
           // FIXME: I think that some of these checks are redundant
           if (allocation_mask[CC_id][rbg] == 0) continue;
+
           if (rballoc_sub[CC_id][rbg] != 0) continue;
+
           if (ue_sched_ctl->rballoc_sub_UE[CC_id][rbg] != 0) continue;
+
           if (nb_rbs_remaining[CC_id][UE_id] <= 0) continue;
+
           if (ue_sched_ctl->pre_nb_available_rbs[CC_id] >= nb_rbs_required[CC_id][UE_id]) continue;
+
           if (ue_sched_ctl->dl_pow_off[CC_id] == 0) continue;
 
           if ((rbg == N_RBG[CC_id] - 1) && ((N_RB_DL == 25) || (N_RB_DL == 50))) {
@@ -1560,9 +2641,11 @@ void dlsch_scheduler_interslice_multiplexing(module_id_t Mod_id,
               free_rbgs_map[CC_id][rbg] = -1;
               ue_sched_ctl->rballoc_sub_UE[CC_id][rbg] = 1;
               MIMO_mode_indicator[CC_id][rbg] = 1;
+
               if (tm == 5) {
                 ue_sched_ctl->dl_pow_off[CC_id] = 1;
               }
+
               nb_rbs_remaining[CC_id][UE_id] = nb_rbs_remaining[CC_id][UE_id] - min_rb_unit + 1;
               ue_sched_ctl->pre_nb_available_rbs[CC_id] = ue_sched_ctl->pre_nb_available_rbs[CC_id] + min_rb_unit - 1;
             }
@@ -1573,9 +2656,11 @@ void dlsch_scheduler_interslice_multiplexing(module_id_t Mod_id,
               free_rbgs_map[CC_id][rbg] = -1;
               ue_sched_ctl->rballoc_sub_UE[CC_id][rbg] = 1;
               MIMO_mode_indicator[CC_id][rbg] = 1;
+
               if (tm == 5) {
                 ue_sched_ctl->dl_pow_off[CC_id] = 1;
               }
+
               nb_rbs_remaining[CC_id][UE_id] = nb_rbs_remaining[CC_id][UE_id] - min_rb_unit;
               ue_sched_ctl->pre_nb_available_rbs[CC_id] = ue_sched_ctl->pre_nb_available_rbs[CC_id] + min_rb_unit;
             }
@@ -1597,14 +2682,12 @@ void dlsch_scheduler_qos_multiplexing(module_id_t Mod_id, int frameP, sub_frame_
 
   for (CC_id = 0; CC_id < RC.nb_mac_CC[Mod_id]; ++CC_id) {
     for (i = 0; i < sli->n_dl; ++i) {
-
       // Sort UE again
       // FIXME: There is only one UE_list for all slices, so it must be sorted again each time we use it
       sort_UEs(Mod_id, (uint8_t)i, frameP, subframeP);
 
       for (UE_id = UE_list->head; UE_id >= 0; UE_id = UE_list->next[UE_id]) {
         //ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
-
         // TODO: Do something here
         // ue_sched_ctl->pre_nb_available_rbs[CC_id];
       }
@@ -1613,13 +2696,612 @@ void dlsch_scheduler_qos_multiplexing(module_id_t Mod_id, int frameP, sub_frame_
 }
 
 
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+//------------------------------------------------------------------------------
+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;
+  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;
+
+  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;
+
+  dl_req = &mac->DL_req[CC_id].dl_config_request_body;
+  dl_config_pdu = &dl_req->dl_config_pdu_list[dl_req->number_pdu];
+
+  if ((frameP&1) == 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
+    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 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]) {
+
+    int harq_pid = 0;
+
+    rnti = UE_RNTI(module_idP,UE_id);
+    if (rnti==NOT_A_RNTI)  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;
+
+    round = 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->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");
+
+
+    // simple scheduler for 1 repetition, 1 HARQ
+    if (subframeP == 5) { // MPDCCH
+
+      if (round == 8) {
+        rlc_status.bytes_in_buffer = 0;
+        // 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
+
+        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 (ta_update != 31)
+            ue_sched_ctl->ta_timer = 20;
+          /* reset ta_update */
+          ue_sched_ctl->ta_update = 31;
+        } else {
+          ta_update = 31;
+        }
+
+        ta_len = (ta_update != 31) ? 2 : 0;
+
+        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 (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]);
+            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;
+          } 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)
+					  ,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
+						      );
+
+            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++;
+	  }
+        }
+
+	// 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);
+          }
+
+          // 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);
+          }
+
+	  //#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);
+
+
+          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
+                                         ta_update, // timing advance
+                                         NULL,                                  // contention res id
+                                         padding,
+                                         post_padding);
+
+
+          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);
+	  }
+
+
+
+          // 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),
+                      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));
+
+	  // 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 {
+	      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;
+      }
+    }
+    else if ((subframeP == 7)&&(round<8)) {  // DLSCH
+
+	  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);
+
+	  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++;
+
+      // 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");
+      }
+      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));
+
+      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 );
+      }
+
+    }
+  }
+
+}
+#endif
+
 //------------------------------------------------------------------------------
 void
 fill_DLSCH_dci(module_id_t module_idP,
                frame_t frameP, sub_frame_t subframeP, int *mbsfn_flagP)
 //------------------------------------------------------------------------------
 {
-
   // loop over all allocated UEs and compute frequency allocations for PDSCH
   int UE_id = -1;
   uint8_t /* first_rb, */ nb_rb = 3;
@@ -1627,7 +3309,6 @@ fill_DLSCH_dci(module_id_t module_idP,
   //unsigned char *vrb_map;
   uint8_t rballoc_sub[25];
   //uint8_t number_of_subbands=13;
-
   //unsigned char round;
   unsigned char harq_pid;
   int i;
@@ -1637,7 +3318,6 @@ fill_DLSCH_dci(module_id_t module_idP,
   int N_RBG;
   int N_RB_DL;
   COMMON_channels_t *cc;
-
   start_meas(&eNB->fill_DLSCH_dci);
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME
   (VCD_SIGNAL_DUMPER_FUNCTIONS_FILL_DLSCH_DCI, VCD_FUNCTION_IN);
@@ -1659,11 +3339,10 @@ fill_DLSCH_dci(module_id_t module_idP,
             eNB_dlsch_info[module_idP][CC_id][UE_id].status);
 
       if (eNB_dlsch_info[module_idP][CC_id][UE_id].status == S_DL_SCHEDULED) {
-
         // clear scheduling flag
         eNB_dlsch_info[module_idP][CC_id][UE_id].status = S_DL_WAITING;
         rnti = UE_RNTI(module_idP, UE_id);
-        harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frameP ,subframeP);
+        harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frameP,subframeP);
         nb_rb = UE_list->UE_template[CC_id][UE_id].nb_rb[harq_pid];
 
         /// Synchronizing rballoc with rballoc_sub
@@ -1678,22 +3357,22 @@ fill_DLSCH_dci(module_id_t module_idP,
              i < DL_req[CC_id].dl_config_request_body.number_pdu;
              i++) {
           dl_config_pdu = &DL_req[CC_id].dl_config_request_body.dl_config_pdu_list[i];
+
           if ((dl_config_pdu->pdu_type == NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE)
               && (dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti == rnti)
               && (dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.dci_format != 1)) {
             dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.resource_block_coding = allocate_prbs_sub(nb_rb, N_RB_DL, N_RBG,
-                                                                                                rballoc_sub);
+                rballoc_sub);
             dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.resource_allocation_type = 0;
           } else if ((dl_config_pdu->pdu_type == NFAPI_DL_CONFIG_DLSCH_PDU_TYPE)
                      && (dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.rnti == rnti)
                      && (dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_allocation_type == 0)) {
             dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_block_coding = allocate_prbs_sub(nb_rb, N_RB_DL, N_RBG,
-                                                                                              rballoc_sub);
+                rballoc_sub);
           }
         }
       }
     }
-
   }
 
   stop_meas(&eNB->fill_DLSCH_dci);
@@ -1706,20 +3385,17 @@ unsigned char *get_dlsch_sdu(module_id_t module_idP,
                              uint8_t TBindex)
 //------------------------------------------------------------------------------
 {
-
   int UE_id;
   eNB_MAC_INST *eNB = RC.mac[module_idP];
 
   if (rntiP == SI_RNTI) {
     LOG_D(MAC, "[eNB %d] CC_id %d Frame %d Get DLSCH sdu for BCCH \n",
           module_idP, CC_id, frameP);
-
     return ((unsigned char *) &eNB->common_channels[CC_id].BCCH_pdu.payload[0]);
   }
 
   if (rntiP == P_RNTI) {
     LOG_D(MAC, "[eNB %d] CC_id %d Frame %d Get PCH sdu for PCCH \n", module_idP, CC_id, frameP);
-
     return ((unsigned char *) &eNB->common_channels[CC_id].PCCH_pdu.payload[0]);
   }
 
@@ -1736,34 +3412,29 @@ unsigned char *get_dlsch_sdu(module_id_t module_idP,
           module_idP, frameP, CC_id, rntiP);
     return NULL;
   }
-
 }
 
 
 //------------------------------------------------------------------------------
 void
 update_ul_dci(module_id_t module_idP,
-	      uint8_t CC_idP, rnti_t rntiP, uint8_t daiP, sub_frame_t subframe)
+              uint8_t CC_idP, rnti_t rntiP, uint8_t daiP, sub_frame_t subframe)
 //------------------------------------------------------------------------------
 {
-
   nfapi_hi_dci0_request_t *HI_DCI0_req =
     &RC.mac[module_idP]->HI_DCI0_req[CC_idP][subframe];
   nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu =
-          &HI_DCI0_req->hi_dci0_request_body.hi_dci0_pdu_list[0];
+    &HI_DCI0_req->hi_dci0_request_body.hi_dci0_pdu_list[0];
   COMMON_channels_t *cc = &RC.mac[module_idP]->common_channels[CC_idP];
   int i;
 
-
-  if (cc->tdd_Config != NULL) {	// TDD
+  if (cc->tdd_Config != NULL) { // TDD
     for (i = 0;
-	 i <HI_DCI0_req->hi_dci0_request_body.number_of_dci + HI_DCI0_req->hi_dci0_request_body.number_of_hi;
-	 i++) {
-
+         i <HI_DCI0_req->hi_dci0_request_body.number_of_dci + HI_DCI0_req->hi_dci0_request_body.number_of_hi;
+         i++) {
       if ((hi_dci0_pdu[i].pdu_type == NFAPI_HI_DCI0_DCI_PDU_TYPE) &&
           (hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.rnti == rntiP))
         hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.dl_assignment_index = (daiP - 1) & 3;
-
     }
   }
 }
@@ -1869,7 +3540,6 @@ void schedule_PCH(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP)
   uint8_t                        Lcrbs = 0;
   uint16_t                       rb_bit    = 168;    /* RB bit number value is unsure */
 #endif
-
   start_meas(&eNB->schedule_pch);
 
   for (CC_id = 0; CC_id < RC.nb_mac_CC[module_idP]; CC_id++) {
@@ -1877,10 +3547,12 @@ void schedule_PCH(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP)
     vrb_map         = (void *) &cc->vrb_map;
     n_rb_dl         = to_prb(cc->mib->message.dl_Bandwidth);
     dl_req          = &eNB->DL_req[CC_id].dl_config_request_body;
+
     for (uint16_t i = 0; i < MAX_MOBILES_PER_ENB; i++) {
       if (UE_PF_PO[CC_id][i].enable_flag != TRUE) {
         continue;
       }
+
       if (frameP % UE_PF_PO[CC_id][i].T == UE_PF_PO[CC_id][i].PF_min && subframeP == UE_PF_PO[CC_id][i].PO) {
         pcch_sdu_length = mac_rrc_data_req(module_idP,
                                            CC_id,
@@ -1888,140 +3560,166 @@ void schedule_PCH(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP)
                                            PCCH,0xFFFE,1,
                                            &cc->PCCH_pdu.payload[0],
                                            i); // used for ue index
+
         if (pcch_sdu_length == 0) {
           LOG_D(MAC, "[eNB %d] Frame %d subframe %d: PCCH not active(size = 0 byte)\n", module_idP, frameP, subframeP);
           continue;
         }
+
         LOG_D(MAC, "[eNB %d] Frame %d subframe %d: PCCH->PCH CC_id %d UE_id %d, Received %d bytes \n", module_idP,
               frameP, subframeP, CC_id, i, pcch_sdu_length);
 #ifdef FORMAT1C
-	//NO SIB
-	if ((subframeP == 0 || subframeP == 1 || subframeP == 2 || subframeP == 4 || subframeP == 6 || subframeP == 9) ||
-	    (subframeP == 5 && ((frameP % 2) != 0 && (frameP % 8) != 1))) {
-	  switch (n_rb_dl) {
-	  case 25:
-	    n_gap = GAP_MAP[3][0];  /* expect: 12 */
-	    n_vrb_dl = 2*((n_gap < (n_rb_dl - n_gap)) ? n_gap : (n_rb_dl - n_gap));  /* expect: 24 */
-	    first_rb = 10;
-	    break;
-	  case 50:
-	    n_gap = GAP_MAP[6][gap_index];  /* expect: 27 or 9 */
-	    if (gap_index > 0) {
-	      n_vrb_dl = (n_rb_dl / (2*n_gap)) * (2*n_gap);  /* 36 */
-	    } else {
-	      n_vrb_dl = 2*((n_gap < (n_rb_dl - n_gap)) ? n_gap : (n_rb_dl - n_gap));  /* expect: 46 */
-	    }
-	    first_rb = 24;
-	    break;
-	  case 100:
-	    n_gap = GAP_MAP[8][gap_index];  /* expect: 48 or 16 */
-	    if (gap_index > 0) {
-	      n_vrb_dl = (n_rb_dl / (2*n_gap)) * (2*n_gap);  /* expect: 96 */
-	    } else {
-	      n_vrb_dl = 2*((n_gap < (n_rb_dl - n_gap)) ? n_gap : (n_rb_dl - n_gap));  /* expect: 96 */
-	    }
-	    first_rb = 48;
-	    break;
-	  }
-	} else if (subframeP == 5 && ((frameP % 2) == 0 || (frameP % 8) == 1)) {  // SIB + paging
-	  switch (n_rb_dl) {
-	  case 25:
-	    n_gap = GAP_MAP[3][0];  /* expect: 12 */
-	    n_vrb_dl = 2*((n_gap < (n_rb_dl - n_gap)) ? n_gap : (n_rb_dl - n_gap));  /* expect: 24 */
-	    first_rb = 14;
-	    break;
-	  case 50:
-	    n_gap = GAP_MAP[6][gap_index];  /* expect: 27 or 9 */
-	    if (gap_index > 0) {
-	      n_vrb_dl = (n_rb_dl / (2*n_gap)) * (2*n_gap);  /* 36 */
-	    } else {
-	      n_vrb_dl = 2*((n_gap < (n_rb_dl - n_gap)) ? n_gap : (n_rb_dl - n_gap));  /* expect: 46 */
-	    }
-	    first_rb = 28;
-	    break;
-	  case 100:
-	    n_gap = GAP_MAP[8][gap_index];  /* expect: 48 or 16 */
-	    if (gap_index > 0) {
-	      n_vrb_dl = (n_rb_dl / (2*n_gap)) * (2*n_gap);  /* expect: 96 */
-	    } else {
-	      n_vrb_dl = 2*((n_gap < (n_rb_dl - n_gap)) ? n_gap : (n_rb_dl - n_gap));  /* expect: 96 */
-	    }
-	    first_rb = 52;
-	    break;
-	  }
-	}
-	/* Get MCS for length of PCH */
-	if (pcch_sdu_length <= TBStable1C[0]) {
-	  mcs=0;
-	} else if (pcch_sdu_length <= TBStable1C[1]) {
-	  mcs=1;
-	} else if (pcch_sdu_length <= TBStable1C[2]) {
-	  mcs=2;
-	} else if (pcch_sdu_length <= TBStable1C[3]) {
-	  mcs=3;
-	} else if (pcch_sdu_length <= TBStable1C[4]) {
-	  mcs=4;
-	} else if (pcch_sdu_length <= TBStable1C[5]) {
-	  mcs=5;
-	} else if (pcch_sdu_length <= TBStable1C[6]) {
-	  mcs=6;
-	} else if (pcch_sdu_length <= TBStable1C[7]) {
-	  mcs=7;
-	} else if (pcch_sdu_length <= TBStable1C[8]) {
-	  mcs=8;
-	} else if (pcch_sdu_length <= TBStable1C[9]) {
-	  mcs=9;
-	} else {
-	  /* unexpected: pcch sdb size is over max value*/
-	  LOG_E(MAC,"[eNB %d] Frame %d : PCCH->PCH CC_id %d, Received %d bytes is over max length(256) \n",
-		module_idP, frameP,CC_id, pcch_sdu_length);
-	  return;
-	}
-	rb_num = TBStable1C[mcs] / rb_bit + ( (TBStable1C[mcs] % rb_bit == 0)? 0: 1) + 1;
-	/* calculate N_RB_STEP and Lcrbs */
-	if (n_rb_dl < 50) {
-	  n_rb_step = 2;
-	  Lcrbs = rb_num / 2 + ((rb_num % 2 == 0) ? 0:2);
-	} else {
-	  n_rb_step = 4;
-	  Lcrbs = rb_num / 4 + ((rb_num % 4 == 0) ? 0:4);
-	}
-	for(i = 0;i < Lcrbs ;i++){
-	  vrb_map[first_rb+i] = 1;
-	}
+
+        //NO SIB
+        if ((subframeP == 0 || subframeP == 1 || subframeP == 2 || subframeP == 4 || subframeP == 6 || subframeP == 9) ||
+            (subframeP == 5 && ((frameP % 2) != 0 && (frameP % 8) != 1))) {
+          switch (n_rb_dl) {
+            case 25:
+              n_gap = GAP_MAP[3][0];  /* expect: 12 */
+              n_vrb_dl = 2*((n_gap < (n_rb_dl - n_gap)) ? n_gap : (n_rb_dl - n_gap));  /* expect: 24 */
+              first_rb = 10;
+              break;
+
+            case 50:
+              n_gap = GAP_MAP[6][gap_index];  /* expect: 27 or 9 */
+
+              if (gap_index > 0) {
+                n_vrb_dl = (n_rb_dl / (2*n_gap)) * (2*n_gap);  /* 36 */
+              } else {
+                n_vrb_dl = 2*((n_gap < (n_rb_dl - n_gap)) ? n_gap : (n_rb_dl - n_gap));  /* expect: 46 */
+              }
+
+              first_rb = 24;
+              break;
+
+            case 100:
+              n_gap = GAP_MAP[8][gap_index];  /* expect: 48 or 16 */
+
+              if (gap_index > 0) {
+                n_vrb_dl = (n_rb_dl / (2*n_gap)) * (2*n_gap);  /* expect: 96 */
+              } else {
+                n_vrb_dl = 2*((n_gap < (n_rb_dl - n_gap)) ? n_gap : (n_rb_dl - n_gap));  /* expect: 96 */
+              }
+
+              first_rb = 48;
+              break;
+          }
+        } else if (subframeP == 5 && ((frameP % 2) == 0 || (frameP % 8) == 1)) {  // SIB + paging
+          switch (n_rb_dl) {
+            case 25:
+              n_gap = GAP_MAP[3][0];  /* expect: 12 */
+              n_vrb_dl = 2*((n_gap < (n_rb_dl - n_gap)) ? n_gap : (n_rb_dl - n_gap));  /* expect: 24 */
+              first_rb = 14;
+              break;
+
+            case 50:
+              n_gap = GAP_MAP[6][gap_index];  /* expect: 27 or 9 */
+
+              if (gap_index > 0) {
+                n_vrb_dl = (n_rb_dl / (2*n_gap)) * (2*n_gap);  /* 36 */
+              } else {
+                n_vrb_dl = 2*((n_gap < (n_rb_dl - n_gap)) ? n_gap : (n_rb_dl - n_gap));  /* expect: 46 */
+              }
+
+              first_rb = 28;
+              break;
+
+            case 100:
+              n_gap = GAP_MAP[8][gap_index];  /* expect: 48 or 16 */
+
+              if (gap_index > 0) {
+                n_vrb_dl = (n_rb_dl / (2*n_gap)) * (2*n_gap);  /* expect: 96 */
+              } else {
+                n_vrb_dl = 2*((n_gap < (n_rb_dl - n_gap)) ? n_gap : (n_rb_dl - n_gap));  /* expect: 96 */
+              }
+
+              first_rb = 52;
+              break;
+          }
+        }
+
+        /* Get MCS for length of PCH */
+        if (pcch_sdu_length <= TBStable1C[0]) {
+          mcs=0;
+        } else if (pcch_sdu_length <= TBStable1C[1]) {
+          mcs=1;
+        } else if (pcch_sdu_length <= TBStable1C[2]) {
+          mcs=2;
+        } else if (pcch_sdu_length <= TBStable1C[3]) {
+          mcs=3;
+        } else if (pcch_sdu_length <= TBStable1C[4]) {
+          mcs=4;
+        } else if (pcch_sdu_length <= TBStable1C[5]) {
+          mcs=5;
+        } else if (pcch_sdu_length <= TBStable1C[6]) {
+          mcs=6;
+        } else if (pcch_sdu_length <= TBStable1C[7]) {
+          mcs=7;
+        } else if (pcch_sdu_length <= TBStable1C[8]) {
+          mcs=8;
+        } else if (pcch_sdu_length <= TBStable1C[9]) {
+          mcs=9;
+        } else {
+          /* unexpected: pcch sdb size is over max value*/
+          LOG_E(MAC,"[eNB %d] Frame %d : PCCH->PCH CC_id %d, Received %d bytes is over max length(256) \n",
+                module_idP, frameP,CC_id, pcch_sdu_length);
+          return;
+        }
+
+        rb_num = TBStable1C[mcs] / rb_bit + ( (TBStable1C[mcs] % rb_bit == 0)? 0: 1) + 1;
+
+        /* calculate N_RB_STEP and Lcrbs */
+        if (n_rb_dl < 50) {
+          n_rb_step = 2;
+          Lcrbs = rb_num / 2 + ((rb_num % 2 == 0) ? 0:2);
+        } else {
+          n_rb_step = 4;
+          Lcrbs = rb_num / 4 + ((rb_num % 4 == 0) ? 0:4);
+        }
+
+        for(i = 0; i < Lcrbs ; i++) {
+          vrb_map[first_rb+i] = 1;
+        }
+
 #else
-	//NO SIB
-	if ((subframeP == 0 || subframeP == 1 || subframeP == 2 || subframeP == 4 || subframeP == 6 || subframeP == 9) ||
-	    (subframeP == 5 && ((frameP % 2) != 0 && (frameP % 8) != 1))) {
-	  switch (n_rb_dl) {
-	  case 25:
-	    first_rb = 10;
-	    break;
-	  case 50:
-	    first_rb = 24;
-	    break;
-	  case 100:
-	    first_rb = 48;
-	    break;
-	  }
-	} else if (subframeP == 5 && ((frameP % 2) == 0 || (frameP % 8) == 1)) {  // SIB + paging
-	  switch (n_rb_dl) {
-	  case 25:
-	    first_rb = 14;
-	    break;
-	  case 50:
-	    first_rb = 28;
-	    break;
-	  case 100:
-	    first_rb = 52;
-	    break;
-	  }
-	}
+
+        //NO SIB
+        if ((subframeP == 0 || subframeP == 1 || subframeP == 2 || subframeP == 4 || subframeP == 6 || subframeP == 9) ||
+            (subframeP == 5 && ((frameP % 2) != 0 && (frameP % 8) != 1))) {
+          switch (n_rb_dl) {
+            case 25:
+              first_rb = 10;
+              break;
+
+            case 50:
+              first_rb = 24;
+              break;
+
+            case 100:
+              first_rb = 48;
+              break;
+          }
+        } else if (subframeP == 5 && ((frameP % 2) == 0 || (frameP % 8) == 1)) {  // SIB + paging
+          switch (n_rb_dl) {
+            case 25:
+              first_rb = 14;
+              break;
+
+            case 50:
+              first_rb = 28;
+              break;
+
+            case 100:
+              first_rb = 52;
+              break;
+          }
+        }
 
         vrb_map[first_rb] = 1;
         vrb_map[first_rb + 1] = 1;
         vrb_map[first_rb + 2] = 1;
         vrb_map[first_rb + 3] = 1;
+
         /* Get MCS for length of PCH */
         if (pcch_sdu_length <= get_TBS_DL(0, 3)) {
           mcs = 0;
@@ -2044,6 +3742,7 @@ void schedule_PCH(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP)
         } else if (pcch_sdu_length <= get_TBS_DL(9, 3)) {
           mcs = 9;
         }
+
 #endif
         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));
@@ -2068,20 +3767,19 @@ void schedule_PCH(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP)
         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.mcs_1                       = mcs;
 
-	if (!CCE_allocation_infeasible(module_idP, CC_id, 0, subframeP, dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level, P_RNTI)) {
-	  LOG_D(MAC,"Frame %d: Subframe %d : Adding common DCI for P_RNTI\n", frameP,subframeP);
-	  dl_req->number_dci++;
-	  dl_req->number_pdu++;
+        if (!CCE_allocation_infeasible(module_idP, CC_id, 0, subframeP, dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level, P_RNTI)) {
+          LOG_D(MAC,"Frame %d: Subframe %d : Adding common DCI for P_RNTI\n", frameP,subframeP);
+          dl_req->number_dci++;
+          dl_req->number_pdu++;
           dl_req->tl.tag = NFAPI_DL_CONFIG_REQUEST_BODY_TAG;
           eNB->DL_req[CC_id].sfn_sf = frameP<<4 | subframeP;
           eNB->DL_req[CC_id].header.message_id = NFAPI_DL_CONFIG_REQUEST;
-
-	  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                                   = 0xFFFE;
+          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                                   = 0xFFFE;
 #ifdef FORMAT1C
           dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_allocation_type               = 3;   // format 1C
           dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_block_coding                  = getRIV(n_vrb_dl/n_rb_step, first_rb/n_rb_step, Lcrbs/n_rb_step);
@@ -2090,86 +3788,83 @@ void schedule_PCH(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP)
           dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_block_coding = getRIV(n_rb_dl, first_rb, 4);
           dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.virtual_resource_block_assignment_flag = 0;   // localized
 #endif
-	  dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.modulation                             = 2; //QPSK
-	  dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.redundancy_version                     = 1;
-	  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                    = ;
-
-	// Rel10 fields
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel10.pdsch_start                           = 3;
+          dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.modulation                             = 2; //QPSK
+          dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.redundancy_version                     = 1;
+          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                    = ;
+          // Rel10 fields
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+          dl_config_pdu->dlsch_pdu.dlsch_pdu_rel10.pdsch_start                           = 3;
 #endif
-	// Rel13 fields
-#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
-	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.ue_type                               = 0; // regular UE
-	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.pdsch_payload_type                    = 2; // not BR
-	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.initial_transmission_sf_io            = 0xFFFF;
+          // Rel13 fields
+#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
+          dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.ue_type                               = 0; // regular UE
+          dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.pdsch_payload_type                    = 2; // not BR
+          dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.initial_transmission_sf_io            = 0xFFFF;
 #endif
-
-	  dl_req->number_pdu++;
-
-	  eNB->TX_req[CC_id].sfn_sf                                                     = (frameP<<4)+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                                                             = pcch_sdu_length;
-	  TX_req->pdu_index                                                              = eNB->pdu_index[CC_id]++;
-	  TX_req->num_segments                                                           = 1;
-	  TX_req->segments[0].segment_length                                             = pcch_sdu_length;
-	  TX_req->segments[0].segment_data                                               = cc[CC_id].PCCH_pdu.payload;
+          dl_req->number_pdu++;
+          eNB->TX_req[CC_id].sfn_sf                                                     = (frameP<<4)+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                                                             = pcch_sdu_length;
+          TX_req->pdu_index                                                              = eNB->pdu_index[CC_id]++;
+          TX_req->num_segments                                                           = 1;
+          TX_req->segments[0].segment_length                                             = pcch_sdu_length;
+          TX_req->segments[0].segment_data                                               = cc[CC_id].PCCH_pdu.payload;
           eNB->TX_req[CC_id].tx_request_body.tl.tag = NFAPI_TX_REQUEST_BODY_TAG;
-	  eNB->TX_req[CC_id].tx_request_body.number_of_pdus++;
-	} else {
-	  LOG_E(MAC,"[eNB %d] CCid %d Frame %d, subframe %d : Cannot add DCI 1A/1C for Paging\n",module_idP, CC_id, frameP, subframeP);
-	  continue;
-	}
+          eNB->TX_req[CC_id].tx_request_body.number_of_pdus++;
+        } else {
+          LOG_E(MAC,"[eNB %d] CCid %d Frame %d, subframe %d : Cannot add DCI 1A/1C for Paging\n",module_idP, CC_id, frameP, subframeP);
+          continue;
+        }
 
-	if (opt_enabled == 1) {
-	  trace_pdu(DIRECTION_DOWNLINK,
-		    &eNB->common_channels[CC_id].PCCH_pdu.payload[0],
-		    pcch_sdu_length,
-		    0xffff,
-		    PCCH,
-		    P_RNTI,
-		    eNB->frame,
-		    eNB->subframe,
-		    0,
-		    0);
-	  LOG_D(OPT,"[eNB %d][PCH] Frame %d trace pdu for CC_id %d rnti %x with size %d\n",
-		module_idP, frameP, CC_id, 0xffff, pcch_sdu_length);
-	}
-	eNB->eNB_stats[CC_id].total_num_pcch_pdu+=1;
-	eNB->eNB_stats[CC_id].pcch_buffer=pcch_sdu_length;
-	eNB->eNB_stats[CC_id].total_pcch_buffer+=pcch_sdu_length;
-	eNB->eNB_stats[CC_id].pcch_mcs=mcs;
-	//paging first_rb log
-	LOG_D(MAC,"[eNB %d] Frame %d subframe %d PCH: paging_ue_index %d pcch_sdu_length %d mcs %d first_rb %d\n",
-	      module_idP, frameP, subframeP, UE_PF_PO[CC_id][i].ue_index_value, pcch_sdu_length, mcs, first_rb);
-
-	pthread_mutex_lock(&ue_pf_po_mutex);
-	memset(&UE_PF_PO[CC_id][i], 0, sizeof(UE_PF_PO_t));
-	pthread_mutex_unlock(&ue_pf_po_mutex);
+        if (opt_enabled == 1) {
+          trace_pdu(DIRECTION_DOWNLINK,
+                    &eNB->common_channels[CC_id].PCCH_pdu.payload[0],
+                    pcch_sdu_length,
+                    0xffff,
+                    PCCH,
+                    P_RNTI,
+                    eNB->frame,
+                    eNB->subframe,
+                    0,
+                    0);
+          LOG_D(OPT,"[eNB %d][PCH] Frame %d trace pdu for CC_id %d rnti %x with size %d\n",
+                module_idP, frameP, CC_id, 0xffff, pcch_sdu_length);
+        }
+
+        eNB->eNB_stats[CC_id].total_num_pcch_pdu+=1;
+        eNB->eNB_stats[CC_id].pcch_buffer=pcch_sdu_length;
+        eNB->eNB_stats[CC_id].total_pcch_buffer+=pcch_sdu_length;
+        eNB->eNB_stats[CC_id].pcch_mcs=mcs;
+        //paging first_rb log
+        LOG_D(MAC,"[eNB %d] Frame %d subframe %d PCH: paging_ue_index %d pcch_sdu_length %d mcs %d first_rb %d\n",
+              module_idP, frameP, subframeP, UE_PF_PO[CC_id][i].ue_index_value, pcch_sdu_length, mcs, first_rb);
+        pthread_mutex_lock(&ue_pf_po_mutex);
+        memset(&UE_PF_PO[CC_id][i], 0, sizeof(UE_PF_PO_t));
+        pthread_mutex_unlock(&ue_pf_po_mutex);
       }
     }
   }
+
   /* this might be misleading when pcch is inactive */
   stop_meas(&eNB->schedule_pch);
   return;
 }
 
-static int slice_priority_compare(const void *_a, const void *_b, void *_c)
-{
+static int slice_priority_compare(const void *_a, const void *_b, void *_c) {
   const int slice_id1 = *(const int *) _a;
   const int slice_id2 = *(const int *) _b;
   const module_id_t Mod_id = *(int *)  _c;
@@ -2178,12 +3873,13 @@ static int slice_priority_compare(const void *_a, const void *_b, void *_c)
   if (sli->dl[slice_id1].prio > sli->dl[slice_id2].prio) {
     return -1;
   }
+
   return 1;
 }
 
-void slice_priority_sort(module_id_t Mod_id, int slice_list[MAX_NUM_SLICES])
-{
+void slice_priority_sort(module_id_t Mod_id, int slice_list[MAX_NUM_SLICES]) {
   int i;
+
   for (i = 0; i < RC.mac[Mod_id]->slice_info.n_dl; ++i) {
     slice_list[i] = i;
   }
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_fairRR.c b/openair2/LAYER2/MAC/eNB_scheduler_fairRR.c
index 20ac1531b6511bb0d2556ba79eb233950dead707..ccc71b102ac8273ceda8996050e982f758febb92 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_fairRR.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_fairRR.c
@@ -51,8 +51,8 @@
 
 extern uint8_t nfapi_mode;
 #ifdef PHY_TX_THREAD
-extern volatile int16_t phy_tx_txdataF_end;
-extern int oai_exit;
+  extern volatile int16_t phy_tx_txdataF_end;
+  extern int oai_exit;
 #endif
 extern uint16_t sfnsf_add_subframe(uint16_t frameP, uint16_t subframeP, int offset);
 extern void add_subframe(uint16_t *frameP, uint16_t *subframeP, int offset);
@@ -63,11 +63,11 @@ int last_dlsch_ue_id[MAX_NUM_CCs] = {-1};
 int last_ulsch_ue_id[MAX_NUM_CCs] = {-1};
 
 #if defined(PRE_SCD_THREAD)
-uint16_t pre_nb_rbs_required[2][MAX_NUM_CCs][NUMBER_OF_UE_MAX];
-uint8_t dlsch_ue_select_tbl_in_use;
-uint8_t new_dlsch_ue_select_tbl_in_use;
-boolean_t pre_scd_activeUE[NUMBER_OF_UE_MAX];
-eNB_UE_STATS pre_scd_eNB_UE_stats[MAX_NUM_CCs][NUMBER_OF_UE_MAX];
+  uint16_t pre_nb_rbs_required[2][MAX_NUM_CCs][NUMBER_OF_UE_MAX];
+  uint8_t dlsch_ue_select_tbl_in_use;
+  uint8_t new_dlsch_ue_select_tbl_in_use;
+  boolean_t pre_scd_activeUE[NUMBER_OF_UE_MAX];
+  eNB_UE_STATS pre_scd_eNB_UE_stats[MAX_NUM_CCs][NUMBER_OF_UE_MAX];
 #endif
 
 #define DEBUG_eNB_SCHEDULER 1
@@ -89,92 +89,92 @@ void set_dl_ue_select_msg4(int CC_idP, uint16_t nb_rb, int UE_id, rnti_t rnti) {
   dlsch_ue_select[CC_idP].ue_num++;
 }
 #if defined(PRE_SCD_THREAD)
-inline uint16_t search_rbs_required(uint16_t mcs, uint16_t TBS,uint16_t NB_RB, uint16_t step_size){
+inline uint16_t search_rbs_required(uint16_t mcs, uint16_t TBS,uint16_t NB_RB, uint16_t step_size) {
   uint16_t nb_rb,i_TBS,tmp_TBS;
   i_TBS=get_I_TBS(mcs);
-  for(nb_rb=step_size;nb_rb<NB_RB;nb_rb+=step_size){
+
+  for(nb_rb=step_size; nb_rb<NB_RB; nb_rb+=step_size) {
     tmp_TBS = TBStable[i_TBS][nb_rb-1]>>3;
+
     if(TBS<tmp_TBS)return(nb_rb);
   }
+
   return NB_RB;
 }
 void pre_scd_nb_rbs_required(    module_id_t     module_idP,
                                  frame_t         frameP,
                                  sub_frame_t     subframeP,
                                  int             min_rb_unit[MAX_NUM_CCs],
-                                 uint16_t        nb_rbs_required[MAX_NUM_CCs][NUMBER_OF_UE_MAX])
-{
-    int                          CC_id=0,UE_id, lc_id, N_RB_DL;
-    UE_TEMPLATE                  UE_template;
-    eNB_UE_STATS                 *eNB_UE_stats;
-    rnti_t                       rnti;
-    mac_rlc_status_resp_t        rlc_status;
-    uint16_t                     step_size=2;
-    
-    N_RB_DL = to_prb(RC.mac[module_idP]->common_channels[CC_id].mib->message.dl_Bandwidth);
-    if(N_RB_DL==50) step_size=3;
-    if(N_RB_DL==100) step_size=4;
-    memset(nb_rbs_required, 0, sizeof(uint16_t)*MAX_NUM_CCs*NUMBER_OF_UE_MAX);
-    UE_list_t *UE_list = &RC.mac[module_idP]->UE_list;
-
-    for (UE_id = 0; UE_id <NUMBER_OF_UE_MAX; UE_id++) {
-        if (pre_scd_activeUE[UE_id] != TRUE)
-            continue;
-
-        // store dlsch buffer
+                                 uint16_t        nb_rbs_required[MAX_NUM_CCs][NUMBER_OF_UE_MAX]) {
+  int                          CC_id=0,UE_id, lc_id, N_RB_DL;
+  UE_TEMPLATE                  UE_template;
+  eNB_UE_STATS                 *eNB_UE_stats;
+  rnti_t                       rnti;
+  mac_rlc_status_resp_t        rlc_status;
+  uint16_t                     step_size=2;
+  N_RB_DL = to_prb(RC.mac[module_idP]->common_channels[CC_id].mib->message.dl_Bandwidth);
 
-        // clear logical channel interface variables
-        UE_template.dl_buffer_total = 0;
+  if(N_RB_DL==50) step_size=3;
 
-        rnti = UE_RNTI(module_idP, UE_id);
+  if(N_RB_DL==100) step_size=4;
 
-        for (lc_id = DCCH; lc_id <= DTCH; lc_id++) {
-            rlc_status =
-                    mac_rlc_status_ind(module_idP, rnti, module_idP, frameP, subframeP,
-                            ENB_FLAG_YES, MBMS_FLAG_NO, lc_id, 0
-#ifdef Rel14
-                            ,0, 0
-#endif
-                    );
-            UE_template.dl_buffer_total += rlc_status.bytes_in_buffer; //storing the total dlsch buffer
-        }
-         // end of store dlsch buffer
+  memset(nb_rbs_required, 0, sizeof(uint16_t)*MAX_NUM_CCs*NUMBER_OF_UE_MAX);
+  UE_list_t *UE_list = &RC.mac[module_idP]->UE_list;
 
-        // assgin rbs required
-        // Calculate the number of RBs required by each UE on the basis of logical channel's buffer
-        //update CQI information across component carriers
-        eNB_UE_stats = &pre_scd_eNB_UE_stats[CC_id][UE_id];
+  for (UE_id = 0; UE_id <NUMBER_OF_UE_MAX; UE_id++) {
+    if (pre_scd_activeUE[UE_id] != TRUE)
+      continue;
 
-        eNB_UE_stats->dlsch_mcs1 = cqi_to_mcs[UE_list->UE_sched_ctrl[UE_id].dl_cqi[CC_id]];
+    // store dlsch buffer
+    // clear logical channel interface variables
+    UE_template.dl_buffer_total = 0;
+    rnti = UE_RNTI(module_idP, UE_id);
+
+    for (lc_id = DCCH; lc_id <= DTCH; lc_id++) {
+      rlc_status =
+        mac_rlc_status_ind(module_idP, rnti, module_idP, frameP, subframeP,
+                           ENB_FLAG_YES, MBMS_FLAG_NO, lc_id, 0
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                           ,0, 0
+#endif
+                          );
+      UE_template.dl_buffer_total += rlc_status.bytes_in_buffer; //storing the total dlsch buffer
+    }
 
+    // end of store dlsch buffer
+    // assgin rbs required
+    // Calculate the number of RBs required by each UE on the basis of logical channel's buffer
+    //update CQI information across component carriers
+    eNB_UE_stats = &pre_scd_eNB_UE_stats[CC_id][UE_id];
+    eNB_UE_stats->dlsch_mcs1 = cqi_to_mcs[UE_list->UE_sched_ctrl[UE_id].dl_cqi[CC_id]];
 
-        if (UE_template.dl_buffer_total > 0) {
-          nb_rbs_required[CC_id][UE_id] = search_rbs_required(eNB_UE_stats->dlsch_mcs1, UE_template.dl_buffer_total, N_RB_DL, step_size);
-        }
+    if (UE_template.dl_buffer_total > 0) {
+      nb_rbs_required[CC_id][UE_id] = search_rbs_required(eNB_UE_stats->dlsch_mcs1, UE_template.dl_buffer_total, N_RB_DL, step_size);
     }
+  }
 }
 #endif
 
-int cc_id_end(uint8_t *cc_id_flag )
-{
+int cc_id_end(uint8_t *cc_id_flag ) {
   int end_flag = 1;
-  for (int CC_id=0;CC_id<MAX_NUM_CCs;CC_id++) {
+
+  for (int CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
     if (cc_id_flag[CC_id]==0) {
       end_flag = 0;
       break;
     }
   }
+
   return end_flag;
 }
 
 void dlsch_scheduler_pre_ue_select_fairRR(
-    module_id_t     module_idP,
-    frame_t         frameP,
-    sub_frame_t     subframeP,
-    int*            mbsfn_flag,
-    uint16_t        nb_rbs_required[MAX_NUM_CCs][NUMBER_OF_UE_MAX],
-    DLSCH_UE_SELECT dlsch_ue_select[MAX_NUM_CCs])
-{
+  module_id_t     module_idP,
+  frame_t         frameP,
+  sub_frame_t     subframeP,
+  int            *mbsfn_flag,
+  uint16_t        nb_rbs_required[MAX_NUM_CCs][NUMBER_OF_UE_MAX],
+  DLSCH_UE_SELECT dlsch_ue_select[MAX_NUM_CCs]) {
   eNB_MAC_INST                   *eNB      = RC.mac[module_idP];
   COMMON_channels_t              *cc       = eNB->common_channels;
   UE_list_t                      *UE_list  = &eNB->UE_list;
@@ -195,8 +195,7 @@ void dlsch_scheduler_pre_ue_select_fairRR(
 
   // Initialization
   for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
-    dlsch_ue_max_num[CC_id] = (uint16_t)RC.rrc[module_idP]->configuration.ue_multiple_max[CC_id];
-
+    dlsch_ue_max_num[CC_id] = (uint16_t)RC.rrc[module_idP]->configuration.radioresourceconfig[CC_id].ue_multiple_max;
     // save origin DL PDU number
     DL_req          = &eNB->DL_req[CC_id].dl_config_request_body;
     saved_dlsch_dci[CC_id] = DL_req->number_pdu;
@@ -209,60 +208,66 @@ void dlsch_scheduler_pre_ue_select_fairRR(
     }
 
     DL_req          = &eNB->DL_req[CC_id].dl_config_request_body;
+
     for (UE_id = 0; UE_id < NUMBER_OF_UE_MAX; UE_id++) {
       if (UE_list->active[UE_id] == FALSE) {
         continue;
       }
 
       rnti = UE_RNTI(module_idP, UE_id);
+
       if (rnti == NOT_A_RNTI) {
         continue;
       }
 
-      if(mac_eNB_get_rrc_status(module_idP,rnti) < RRC_CONNECTED){
+      if(mac_eNB_get_rrc_status(module_idP,rnti) < RRC_CONNECTED) {
         continue;
       }
 
       ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
-      harq_pid = frame_subframe2_dl_harq_pid(cc[CC_id].tdd_Config,frameP ,subframeP);
-
+      harq_pid = frame_subframe2_dl_harq_pid(cc[CC_id].tdd_Config,frameP,subframeP);
       round = ue_sched_ctl->round[CC_id][harq_pid];
+
       if (round != 8) {  // retransmission
-        if(UE_list->UE_template[CC_id][UE_id].nb_rb[harq_pid] == 0){
+        if(UE_list->UE_template[CC_id][UE_id].nb_rb[harq_pid] == 0) {
           continue;
         }
+
         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),
-                  ue_sched_ctl->dl_cqi[CC_id],
-                  format1);
+                                          ue_sched_ctl->dl_cqi[CC_id],
+                                          format1);
             break;
+
           case 3:
             aggregation = get_aggregation(get_bw_index(module_idP,CC_id),
-                  ue_sched_ctl->dl_cqi[CC_id],
-                  format2A);
+                                          ue_sched_ctl->dl_cqi[CC_id],
+                                          format2A);
             break;
+
           default:
             LOG_W(MAC,"Unsupported transmission mode %d\n", get_tmode(module_idP,CC_id,UE_id));
             aggregation = 2;
             break;
         }
+
         format_flag = 1;
+
         if (!CCE_allocation_infeasible(module_idP,
-                                      CC_id,
-                                      format_flag,
-                                      subframeP,
-                                      aggregation,
-                                      rnti)) {
+                                       CC_id,
+                                       format_flag,
+                                       subframeP,
+                                       aggregation,
+                                       rnti)) {
           dl_config_pdu = &DL_req->dl_config_pdu_list[DL_req->number_pdu];
           dl_config_pdu->pdu_type                                     = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE;
           dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti              = rnti;
           dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type         = (format_flag == 0)?2:1;
           dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level = aggregation;
           DL_req->number_pdu++;
-
           nb_rbs_required[CC_id][UE_id] = UE_list->UE_template[CC_id][UE_id].nb_rb[harq_pid];
           // Insert DLSCH(retransmission) UE into selected UE list
           dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].UE_id = UE_id;
@@ -270,6 +275,7 @@ void dlsch_scheduler_pre_ue_select_fairRR(
           dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].rnti = rnti;
           dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].nb_rb = nb_rbs_required[CC_id][UE_id];
           dlsch_ue_select[CC_id].ue_num++;
+
           if (dlsch_ue_select[CC_id].ue_num == dlsch_ue_max_num[CC_id]) {
             end_flag[CC_id] = 1;
             break;
@@ -277,10 +283,10 @@ void dlsch_scheduler_pre_ue_select_fairRR(
         } else {
           if (cc[CC_id].tdd_Config != NULL) { //TDD
             set_ue_dai (subframeP,
-                         UE_id,
-                         CC_id,
-            cc[CC_id].tdd_Config->subframeAssignment,
-                         UE_list);
+                        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);
           }
@@ -296,227 +302,249 @@ void dlsch_scheduler_pre_ue_select_fairRR(
       }
     }
   }
-  if(cc_id_end(end_flag) == 1){
+
+  if(cc_id_end(end_flag) == 1) {
     for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
       DL_req          = &eNB->DL_req[CC_id].dl_config_request_body;
       DL_req->number_pdu = saved_dlsch_dci[CC_id];
     }
+
     return;
   }
 
   // Insert DLSCH(first transmission) UE into selected UE list (UE_id > last_dlsch_ue_id[CC_id])
   for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
-      if (mbsfn_flag[CC_id]>0) {
+    if (mbsfn_flag[CC_id]>0) {
+      continue;
+    }
+
+    DL_req          = &eNB->DL_req[CC_id].dl_config_request_body;
+
+    for (UE_id = (last_dlsch_ue_id[CC_id]+1); UE_id <NUMBER_OF_UE_MAX; UE_id++) {
+      if(end_flag[CC_id] == 1) {
+        break;
+      }
+
+      if (UE_list->active[UE_id] == FALSE) {
         continue;
       }
 
-      DL_req          = &eNB->DL_req[CC_id].dl_config_request_body;
-      for (UE_id = (last_dlsch_ue_id[CC_id]+1); UE_id <NUMBER_OF_UE_MAX; UE_id++) {
-        if(end_flag[CC_id] == 1){
+      rnti = UE_RNTI(module_idP,UE_id);
+
+      if (rnti == NOT_A_RNTI)
+        continue;
+
+      if(mac_eNB_get_rrc_status(module_idP,rnti) < RRC_CONNECTED) {
+        continue;
+      }
+
+      ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
+
+      for(i = 0; i<dlsch_ue_select[CC_id].ue_num; i++) {
+        if(dlsch_ue_select[CC_id].list[i].UE_id == UE_id) {
           break;
         }
+      }
 
-        if (UE_list->active[UE_id] == FALSE) {
-          continue;
-        }
+      if(i < dlsch_ue_select[CC_id].ue_num)
+        continue;
 
-        rnti = UE_RNTI(module_idP,UE_id);
-        if (rnti == NOT_A_RNTI)
-          continue;
+      harq_pid = frame_subframe2_dl_harq_pid(cc[CC_id].tdd_Config,frameP,subframeP);
+      round = ue_sched_ctl->round[CC_id][harq_pid];
 
-        if(mac_eNB_get_rrc_status(module_idP,rnti) < RRC_CONNECTED){
+      if (round == 8) {
+        if (nb_rbs_required[CC_id][UE_id] == 0) {
           continue;
         }
 
-        ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
-	for(i = 0;i<dlsch_ue_select[CC_id].ue_num;i++){
-          if(dlsch_ue_select[CC_id].list[i].UE_id == UE_id){
-	    break;
-          }
+        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),
+                                          ue_sched_ctl->dl_cqi[CC_id],
+                                          format1);
+            break;
+
+          case 3:
+            aggregation = get_aggregation(get_bw_index(module_idP,CC_id),
+                                          ue_sched_ctl->dl_cqi[CC_id],
+                                          format2A);
+            break;
+
+          default:
+            LOG_W(MAC,"Unsupported transmission mode %d\n", get_tmode(module_idP,CC_id,UE_id));
+            aggregation = 2;
+            break;
         }
-        if(i < dlsch_ue_select[CC_id].ue_num)
-          continue;
 
-        harq_pid = frame_subframe2_dl_harq_pid(cc[CC_id].tdd_Config,frameP ,subframeP);
+        format_flag = 1;
 
-        round = ue_sched_ctl->round[CC_id][harq_pid];
-        if (round == 8) {
-            if (nb_rbs_required[CC_id][UE_id] == 0) {
-              continue;
-            }
-            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),
-                      ue_sched_ctl->dl_cqi[CC_id],
-                      format1);
-                break;
-              case 3:
-                aggregation = get_aggregation(get_bw_index(module_idP,CC_id),
-                      ue_sched_ctl->dl_cqi[CC_id],
-                      format2A);
-                break;
-              default:
-                LOG_W(MAC,"Unsupported transmission mode %d\n", get_tmode(module_idP,CC_id,UE_id));
-                aggregation = 2;
-                break;
-            }
-            format_flag = 1;
-            if (!CCE_allocation_infeasible(module_idP,
-                                           CC_id,
-                                           format_flag,
-                                           subframeP,
-                                           aggregation,
-                                           rnti)) {
-              dl_config_pdu = &DL_req->dl_config_pdu_list[DL_req->number_pdu];
-              dl_config_pdu->pdu_type                                     = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE;
-              dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti              = rnti;
-              dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type         = (format_flag == 0)?2:1;
-              dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level = aggregation;
-              DL_req->number_pdu++;
-
-              // Insert DLSCH(first transmission) UE into selected selected UE list
-              dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].ue_priority = SCH_DL_FIRST;
-              dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].nb_rb = nb_rbs_required[CC_id][UE_id];
-              dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].UE_id = UE_id;
-              dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].rnti = rnti;
-              dlsch_ue_select[CC_id].ue_num++;
+        if (!CCE_allocation_infeasible(module_idP,
+                                       CC_id,
+                                       format_flag,
+                                       subframeP,
+                                       aggregation,
+                                       rnti)) {
+          dl_config_pdu = &DL_req->dl_config_pdu_list[DL_req->number_pdu];
+          dl_config_pdu->pdu_type                                     = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE;
+          dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti              = rnti;
+          dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type         = (format_flag == 0)?2:1;
+          dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level = aggregation;
+          DL_req->number_pdu++;
+          // Insert DLSCH(first transmission) UE into selected selected UE list
+          dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].ue_priority = SCH_DL_FIRST;
+          dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].nb_rb = nb_rbs_required[CC_id][UE_id];
+          dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].UE_id = UE_id;
+          dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].rnti = rnti;
+          dlsch_ue_select[CC_id].ue_num++;
 
           if (dlsch_ue_select[CC_id].ue_num == dlsch_ue_max_num[CC_id]) {
-                  end_flag[CC_id] = 1;
-                  break;
-              }
-          }else {
-            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);
-            }
-           add_ue_dlsch_info(module_idP,
+            end_flag[CC_id] = 1;
+            break;
+          }
+        } else {
+          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);
+          }
+
+          add_ue_dlsch_info(module_idP,
                             CC_id,
                             UE_id,
                             subframeP,
                             S_DL_NONE);
-            end_flag[CC_id] = 1;
-            break;
-          }
+          end_flag[CC_id] = 1;
+          break;
+        }
       }
     }
   }
-  if(cc_id_end(end_flag) == 1){
+
+  if(cc_id_end(end_flag) == 1) {
     for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
       DL_req          = &eNB->DL_req[CC_id].dl_config_request_body;
       DL_req->number_pdu = saved_dlsch_dci[CC_id];
     }
+
     return;
   }
 
   // Insert DLSCH(first transmission) UE into selected UE list (UE_id <= last_dlsch_ue_id[CC_id])
   for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
-      if (mbsfn_flag[CC_id]>0) {
+    if (mbsfn_flag[CC_id]>0) {
+      continue;
+    }
+
+    DL_req          = &eNB->DL_req[CC_id].dl_config_request_body;
+
+    for (UE_id = 0; UE_id <= last_dlsch_ue_id[CC_id]; UE_id++) {
+      if(end_flag[CC_id] == 1) {
+        break;
+      }
+
+      if (UE_list->active[UE_id] == FALSE) {
         continue;
       }
 
-      DL_req          = &eNB->DL_req[CC_id].dl_config_request_body;
-      for (UE_id = 0; UE_id <= last_dlsch_ue_id[CC_id]; UE_id++) {
-        if(end_flag[CC_id] == 1){
+      rnti = UE_RNTI(module_idP,UE_id);
+
+      if (rnti == NOT_A_RNTI)
+        continue;
+
+      if(mac_eNB_get_rrc_status(module_idP,rnti) < RRC_CONNECTED) {
+        continue;
+      }
+
+      ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
+
+      for(i = 0; i<dlsch_ue_select[CC_id].ue_num; i++) {
+        if(dlsch_ue_select[CC_id].list[i].UE_id == UE_id) {
           break;
         }
+      }
 
-        if (UE_list->active[UE_id] == FALSE) {
-          continue;
-        }
+      if(i < dlsch_ue_select[CC_id].ue_num)
+        continue;
 
-        rnti = UE_RNTI(module_idP,UE_id);
-        if (rnti == NOT_A_RNTI)
-          continue;
+      harq_pid = frame_subframe2_dl_harq_pid(cc[CC_id].tdd_Config,frameP,subframeP);
+      round = ue_sched_ctl->round[CC_id][harq_pid];
 
-        if(mac_eNB_get_rrc_status(module_idP,rnti) < RRC_CONNECTED){
+      if (round == 8) {
+        if (nb_rbs_required[CC_id][UE_id] == 0) {
           continue;
         }
 
-        ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
-        for(i = 0;i<dlsch_ue_select[CC_id].ue_num;i++){
-          if(dlsch_ue_select[CC_id].list[i].UE_id == UE_id){
-           break;
-          }
+        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),
+                                          ue_sched_ctl->dl_cqi[CC_id],
+                                          format1);
+            break;
+
+          case 3:
+            aggregation = get_aggregation(get_bw_index(module_idP,CC_id),
+                                          ue_sched_ctl->dl_cqi[CC_id],
+                                          format2A);
+            break;
+
+          default:
+            LOG_W(MAC,"Unsupported transmission mode %d\n", get_tmode(module_idP,CC_id,UE_id));
+            aggregation = 2;
+            break;
         }
-        if(i < dlsch_ue_select[CC_id].ue_num)
-          continue;
 
-        harq_pid = frame_subframe2_dl_harq_pid(cc[CC_id].tdd_Config,frameP ,subframeP);
+        format_flag = 1;
+
+        if (!CCE_allocation_infeasible(module_idP,
+                                       CC_id,
+                                       format_flag,
+                                       subframeP,
+                                       aggregation,
+                                       rnti)) {
+          dl_config_pdu = &DL_req->dl_config_pdu_list[DL_req->number_pdu];
+          dl_config_pdu->pdu_type                                     = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE;
+          dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti              = rnti;
+          dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type         = (format_flag == 0)?2:1;
+          dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level = aggregation;
+          DL_req->number_pdu++;
+          // Insert DLSCH(first transmission) UE into selected selected UE list
+          dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].ue_priority = SCH_DL_FIRST;
+          dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].nb_rb = nb_rbs_required[CC_id][UE_id];
+          dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].UE_id = UE_id;
+          dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].rnti = rnti;
+          dlsch_ue_select[CC_id].ue_num++;
+
+          if (dlsch_ue_select[CC_id].ue_num == dlsch_ue_max_num[CC_id]) {
+            end_flag[CC_id] = 1;
+            break;
+          }
+        } else {
+          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);
+          }
 
-        round = ue_sched_ctl->round[CC_id][harq_pid];
-        if (round == 8) {
-            if (nb_rbs_required[CC_id][UE_id] == 0) {
-                continue;
-             }
-            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),
-                      ue_sched_ctl->dl_cqi[CC_id],
-                      format1);
-                break;
-              case 3:
-                aggregation = get_aggregation(get_bw_index(module_idP,CC_id),
-                      ue_sched_ctl->dl_cqi[CC_id],
-                      format2A);
-                break;
-              default:
-                LOG_W(MAC,"Unsupported transmission mode %d\n", get_tmode(module_idP,CC_id,UE_id));
-                aggregation = 2;
-                break;
-            }
-            format_flag = 1;
-            if (!CCE_allocation_infeasible(module_idP,
-                                           CC_id,
-                                           format_flag,
-                                           subframeP,
-                                           aggregation,
-                                           rnti)) {
-              dl_config_pdu = &DL_req->dl_config_pdu_list[DL_req->number_pdu];
-              dl_config_pdu->pdu_type                                     = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE;
-              dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti              = rnti;
-              dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type         = (format_flag == 0)?2:1;
-              dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level = aggregation;
-              DL_req->number_pdu++;
-
-              // Insert DLSCH(first transmission) UE into selected selected UE list
-              dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].ue_priority = SCH_DL_FIRST;
-              dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].nb_rb = nb_rbs_required[CC_id][UE_id];
-              dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].UE_id = UE_id;
-              dlsch_ue_select[CC_id].list[dlsch_ue_select[CC_id].ue_num].rnti = rnti;
-              dlsch_ue_select[CC_id].ue_num++;
-
-              if (dlsch_ue_select[CC_id].ue_num == dlsch_ue_max_num[CC_id]) {
-                end_flag[CC_id] = 1;
-                break;
-              }
-            } else {
-              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);
-              }
           add_ue_dlsch_info(module_idP,
                             CC_id,
                             UE_id,
                             subframeP,
                             S_DL_NONE);
-              end_flag[CC_id] = 1;
-              break;
-            }
+          end_flag[CC_id] = 1;
+          break;
+        }
       }
     }
   }
@@ -525,6 +553,7 @@ void dlsch_scheduler_pre_ue_select_fairRR(
     DL_req          = &eNB->DL_req[CC_id].dl_config_request_body;
     DL_req->number_pdu = saved_dlsch_dci[CC_id];
   }
+
   return;
 }
 
@@ -532,88 +561,75 @@ void dlsch_scheduler_pre_ue_select_fairRR(
 
 // This function assigns pre-available RBS to each UE in specified sub-bands before scheduling is done
 void dlsch_scheduler_pre_processor_fairRR (module_id_t   Mod_id,
-                                    frame_t       frameP,
-                                    sub_frame_t   subframeP,
-                                    int           N_RBG[MAX_NUM_CCs],
-                                    int           *mbsfn_flag)
-{
-
+    frame_t       frameP,
+    sub_frame_t   subframeP,
+    int           N_RBG[MAX_NUM_CCs],
+    int           *mbsfn_flag) {
   unsigned char rballoc_sub[MAX_NUM_CCs][N_RBG_MAX],harq_pid=0,Round=0;
   uint16_t                temp_total_rbs_count;
   unsigned char           temp_total_ue_count;
   unsigned char MIMO_mode_indicator[MAX_NUM_CCs][N_RBG_MAX];
   uint8_t slice_allocation[MAX_NUM_CCs][N_RBG_MAX];
-  int                     UE_id, i; 
+  int                     UE_id, i;
   uint16_t                j,c;
   uint16_t                nb_rbs_required[MAX_NUM_CCs][NUMBER_OF_UE_MAX];
   uint16_t                nb_rbs_required_remaining[MAX_NUM_CCs][NUMBER_OF_UE_MAX];
-//  uint16_t                nb_rbs_required_remaining_1[MAX_NUM_CCs][NUMBER_OF_UE_MAX];
+  //  uint16_t                nb_rbs_required_remaining_1[MAX_NUM_CCs][NUMBER_OF_UE_MAX];
   uint16_t                average_rbs_per_user[MAX_NUM_CCs] = {0};
   rnti_t             rnti;
   int                min_rb_unit[MAX_NUM_CCs];
-//  uint16_t r1=0;
+  //  uint16_t r1=0;
   uint8_t CC_id;
   UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list;
-
   UE_sched_ctrl *ue_sched_ctl;
   //  int rrc_status           = RRC_IDLE;
   COMMON_channels_t *cc;
-
 #ifdef TM5
-    int harq_pid1 = 0;
-    int round1 = 0, round2 = 0;
-    int UE_id2;
-    uint16_t i1, i2, i3;
-    rnti_t rnti1, rnti2;
-    LTE_eNB_UE_stats *eNB_UE_stats1 = NULL;
-    LTE_eNB_UE_stats *eNB_UE_stats2 = NULL;
-    UE_sched_ctrl *ue_sched_ctl1, *ue_sched_ctl2;
+  int harq_pid1 = 0;
+  int round1 = 0, round2 = 0;
+  int UE_id2;
+  uint16_t i1, i2, i3;
+  rnti_t rnti1, rnti2;
+  LTE_eNB_UE_stats *eNB_UE_stats1 = NULL;
+  LTE_eNB_UE_stats *eNB_UE_stats2 = NULL;
+  UE_sched_ctrl *ue_sched_ctl1, *ue_sched_ctl2;
 #endif
+  memset(rballoc_sub[0],0,(MAX_NUM_CCs)*(N_RBG_MAX)*sizeof(unsigned char));
   memset(min_rb_unit,0,sizeof(min_rb_unit));
-  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
-
-	if (mbsfn_flag[CC_id] > 0)	// If this CC is allocated for MBSFN skip it here
-	    continue;
-
-
-
-	min_rb_unit[CC_id] = get_min_rb_unit(Mod_id, CC_id);
-
-	for (i = 0; i < NUMBER_OF_UE_MAX; i++) {
-	    if (UE_list->active[i] != TRUE)
-		continue;
-
-	    UE_id = i;
-	    // Initialize scheduling information for all active UEs
 
+  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
+    if (mbsfn_flag[CC_id] > 0)  // If this CC is allocated for MBSFN skip it here
+      continue;
 
+    min_rb_unit[CC_id] = get_min_rb_unit(Mod_id, CC_id);
 
-	    dlsch_scheduler_pre_processor_reset(Mod_id,
-                                                0,
-						frameP,
-						subframeP,
-                                                min_rb_unit,
-						(uint16_t (*)[NUMBER_OF_UE_MAX])nb_rbs_required,
-						rballoc_sub,
-						MIMO_mode_indicator,
-                                                mbsfn_flag);
+    for (i = 0; i < NUMBER_OF_UE_MAX; i++) {
+      if (UE_list->active[i] != TRUE)
+        continue;
 
-	}
+      UE_id = i;
+      // Initialize scheduling information for all active UEs
+      dlsch_scheduler_pre_processor_reset(Mod_id,
+                                          0,
+                                          frameP,
+                                          subframeP,
+                                          min_rb_unit,
+                                          (uint16_t (*)[NUMBER_OF_UE_MAX])nb_rbs_required,
+                                          rballoc_sub,
+                                          MIMO_mode_indicator,
+                                          mbsfn_flag);
     }
+  }
 
 #if (!defined(PRE_SCD_THREAD))
-    // Store the DLSCH buffer for each logical channel
-    store_dlsch_buffer(Mod_id,0, frameP, subframeP);
-
-
-
-    // Calculate the number of RBs required by each UE on the basis of logical channel's buffer
-    assign_rbs_required(Mod_id, 0, frameP, subframeP, nb_rbs_required,
-			min_rb_unit);
+  // Store the DLSCH buffer for each logical channel
+  store_dlsch_buffer(Mod_id,0, frameP, subframeP);
+  // Calculate the number of RBs required by each UE on the basis of logical channel's buffer
+  assign_rbs_required(Mod_id, 0, frameP, subframeP, nb_rbs_required,
+                      min_rb_unit);
 #else
-    memcpy(nb_rbs_required, pre_nb_rbs_required[dlsch_ue_select_tbl_in_use] , sizeof(uint16_t)*MAX_NUM_CCs*NUMBER_OF_UE_MAX);
+  memcpy(nb_rbs_required, pre_nb_rbs_required[dlsch_ue_select_tbl_in_use], sizeof(uint16_t)*MAX_NUM_CCs*NUMBER_OF_UE_MAX);
 #endif
-
   dlsch_scheduler_pre_ue_select_fairRR(Mod_id,frameP,subframeP, mbsfn_flag,nb_rbs_required,dlsch_ue_select);
 
   for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
@@ -624,19 +640,21 @@ void dlsch_scheduler_pre_processor_fairRR (module_id_t   Mod_id,
     temp_total_ue_count = dlsch_ue_select[CC_id].ue_num;
 
     for (i = 0; i < dlsch_ue_select[CC_id].ue_num; i++) {
-      if(dlsch_ue_select[CC_id].list[i].ue_priority == SCH_DL_MSG2){
-          temp_total_ue_count--;
-          continue;
+      if(dlsch_ue_select[CC_id].list[i].ue_priority == SCH_DL_MSG2) {
+        temp_total_ue_count--;
+        continue;
       }
-      if(dlsch_ue_select[CC_id].list[i].ue_priority == SCH_DL_MSG4){
-          temp_total_ue_count--;
-          continue;
+
+      if(dlsch_ue_select[CC_id].list[i].ue_priority == SCH_DL_MSG4) {
+        temp_total_ue_count--;
+        continue;
       }
+
       UE_id = dlsch_ue_select[CC_id].list[i].UE_id;
       nb_rbs_required[CC_id][UE_id] = dlsch_ue_select[CC_id].list[i].nb_rb;
-
       average_rbs_per_user[CC_id] = (uint16_t)round((double)temp_total_rbs_count/(double)temp_total_ue_count);
-      if( average_rbs_per_user[CC_id] < min_rb_unit[CC_id] ){
+
+      if( average_rbs_per_user[CC_id] < min_rb_unit[CC_id] ) {
         temp_total_ue_count--;
         dlsch_ue_select[CC_id].ue_num--;
         i--;
@@ -644,9 +662,8 @@ void dlsch_scheduler_pre_processor_fairRR (module_id_t   Mod_id,
       }
 
       rnti = dlsch_ue_select[CC_id].list[i].rnti;
-
       ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
-      harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frameP ,subframeP);
+      harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frameP,subframeP);
       Round    = ue_sched_ctl->round[CC_id][harq_pid];
 
       //if (mac_eNB_get_rrc_status(Mod_id, rnti) < RRC_RECONFIGURED || round > 0) {
@@ -685,9 +702,11 @@ void dlsch_scheduler_pre_processor_fairRR (module_id_t   Mod_id,
         dlsch_ue_select[CC_id].ue_num = i+1;
         break;
       }
-      LOG_D(MAC,"DLSCH UE Select: frame %d subframe %d pre_nb_available_rbs %d(i %d UE_id %d nb_rbs_required %d nb_rbs_required_remaining %d average_rbs_per_user %d (temp_total rbs_count %d ue_num %d) available_prbs %d)\n",
-          frameP,subframeP,ue_sched_ctl->pre_nb_available_rbs[CC_id],i,UE_id,nb_rbs_required[CC_id][UE_id],nb_rbs_required_remaining[CC_id][UE_id],
-          average_rbs_per_user[CC_id],temp_total_rbs_count,temp_total_ue_count,RC.mac[Mod_id]->eNB_stats[CC_id].available_prbs);
+
+      LOG_D(MAC,
+            "DLSCH UE Select: frame %d subframe %d pre_nb_available_rbs %d(i %d UE_id %d nb_rbs_required %d nb_rbs_required_remaining %d average_rbs_per_user %d (temp_total rbs_count %d ue_num %d) available_prbs %d)\n",
+            frameP,subframeP,ue_sched_ctl->pre_nb_available_rbs[CC_id],i,UE_id,nb_rbs_required[CC_id][UE_id],nb_rbs_required_remaining[CC_id][UE_id],
+            average_rbs_per_user[CC_id],temp_total_rbs_count,temp_total_ue_count,RC.mac[Mod_id]->eNB_stats[CC_id].available_prbs);
 #ifdef TM5
       // TODO: data channel TM5: to be re-visited
 #endif
@@ -696,231 +715,241 @@ void dlsch_scheduler_pre_processor_fairRR (module_id_t   Mod_id,
 
 #ifdef TM5
 
-    // This has to be revisited!!!!
-    for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
-	i1 = 0;
-	i2 = 0;
-	i3 = 0;
-
-	for (j = 0; j < N_RBG[CC_id]; j++) {
-	    if (MIMO_mode_indicator[CC_id][j] == 2) {
-		i1 = i1 + 1;
-	    } else if (MIMO_mode_indicator[CC_id][j] == 1) {
-		i2 = i2 + 1;
-	    } else if (MIMO_mode_indicator[CC_id][j] == 0) {
-		i3 = i3 + 1;
-	    }
-	}
-
-	if ((i1 < N_RBG[CC_id]) && (i2 > 0) && (i3 == 0)) {
-	    PHY_vars_eNB_g[Mod_id][CC_id]->check_for_SUMIMO_transmissions =
-		PHY_vars_eNB_g[Mod_id][CC_id]->
-		check_for_SUMIMO_transmissions + 1;
-	}
-
-	if (i3 == N_RBG[CC_id] && i1 == 0 && i2 == 0) {
-	    PHY_vars_eNB_g[Mod_id][CC_id]->FULL_MUMIMO_transmissions =
-		PHY_vars_eNB_g[Mod_id][CC_id]->FULL_MUMIMO_transmissions +
-		1;
-	}
-
-        if((i1 < N_RBG[CC_id]) && (i3 > 0)) {
-		PHY_vars_eNB_g[Mod_id][CC_id]->
-		check_for_MUMIMO_transmissions + 1;
-	}
-
-	PHY_vars_eNB_g[Mod_id][CC_id]->check_for_total_transmissions =
-	    PHY_vars_eNB_g[Mod_id][CC_id]->check_for_total_transmissions +
-	    1;
-
+  // This has to be revisited!!!!
+  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
+    i1 = 0;
+    i2 = 0;
+    i3 = 0;
+
+    for (j = 0; j < N_RBG[CC_id]; j++) {
+      if (MIMO_mode_indicator[CC_id][j] == 2) {
+        i1 = i1 + 1;
+      } else if (MIMO_mode_indicator[CC_id][j] == 1) {
+        i2 = i2 + 1;
+      } else if (MIMO_mode_indicator[CC_id][j] == 0) {
+        i3 = i3 + 1;
+      }
     }
 
-#endif
-
-  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
-      for (i = 0; i < dlsch_ue_select[CC_id].ue_num; i++) {
-        if(dlsch_ue_select[CC_id].list[i].ue_priority == SCH_DL_MSG2){
-            continue;
-        }
-        if(dlsch_ue_select[CC_id].list[i].ue_priority == SCH_DL_MSG4){
-            continue;
-        }
-        UE_id = dlsch_ue_select[CC_id].list[i].UE_id;
-        ue_sched_ctl = &RC.mac[Mod_id]->UE_list.UE_sched_ctrl[UE_id];
-	    //PHY_vars_eNB_g[Mod_id]->mu_mimo_mode[UE_id].dl_pow_off = dl_pow_off[UE_id];
-
-	    if (ue_sched_ctl->pre_nb_available_rbs[CC_id] > 0) {
-		LOG_D(MAC,
-		      "******************DL Scheduling Information for UE%d ************************\n",
-		      UE_id);
-		LOG_D(MAC, "dl power offset UE%d = %d \n", UE_id,
-		      ue_sched_ctl->dl_pow_off[CC_id]);
-		LOG_D(MAC,
-		      "***********RB Alloc for every subband for UE%d ***********\n",
-		      UE_id);
-
-		for (j = 0; j < N_RBG[CC_id]; j++) {
-		    //PHY_vars_eNB_g[Mod_id]->mu_mimo_mode[UE_id].rballoc_sub[i] = rballoc_sub_UE[CC_id][UE_id][i];
-		    LOG_D(MAC, "RB Alloc for UE%d and Subband%d = %d\n",
-			  UE_id, j,
-			  ue_sched_ctl->rballoc_sub_UE[CC_id][j]);
-		}
-
-		//PHY_vars_eNB_g[Mod_id]->mu_mimo_mode[UE_id].pre_nb_available_rbs = pre_nb_available_rbs[CC_id][UE_id];
-		LOG_D(MAC, "Total RBs allocated for UE%d = %d\n", UE_id,
-		      ue_sched_ctl->pre_nb_available_rbs[CC_id]);
-	    }
-	}
+    if ((i1 < N_RBG[CC_id]) && (i2 > 0) && (i3 == 0)) {
+      PHY_vars_eNB_g[Mod_id][CC_id]->check_for_SUMIMO_transmissions =
+        PHY_vars_eNB_g[Mod_id][CC_id]->
+        check_for_SUMIMO_transmissions + 1;
     }
-}
 
+    if (i3 == N_RBG[CC_id] && i1 == 0 && i2 == 0) {
+      PHY_vars_eNB_g[Mod_id][CC_id]->FULL_MUMIMO_transmissions =
+        PHY_vars_eNB_g[Mod_id][CC_id]->FULL_MUMIMO_transmissions +
+        1;
+    }
 
-//------------------------------------------------------------------------------
-void
-schedule_ue_spec_fairRR(module_id_t module_idP,
-		 frame_t frameP, sub_frame_t subframeP, int *mbsfn_flag)
-//------------------------------------------------------------------------------
-{
+    if((i1 < N_RBG[CC_id]) && (i3 > 0)) {
+      PHY_vars_eNB_g[Mod_id][CC_id]->
+      check_for_MUMIMO_transmissions + 1;
+    }
 
+    PHY_vars_eNB_g[Mod_id][CC_id]->check_for_total_transmissions =
+      PHY_vars_eNB_g[Mod_id][CC_id]->check_for_total_transmissions +
+      1;
+  }
 
-    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;
-    int tdd_sfa;
-    int ta_update;
-#ifdef DEBUG_eNB_SCHEDULER
-    int k;
 #endif
 
-    start_meas(&eNB->schedule_dlsch);
-    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME
-	(VCD_SIGNAL_DUMPER_FUNCTIONS_SCHEDULE_DLSCH, VCD_FUNCTION_IN);
-
-
-    // for TDD: check that we have to act here, otherwise return
-    if (cc[0].tdd_Config) {
-	tdd_sfa = cc[0].tdd_Config->subframeAssignment;
-	switch (subframeP) {
-	case 0:
-	    // always continue
-	    break;
-	case 1:
-	    return;
-	    break;
-	case 2:
-	    return;
-	    break;
-	case 3:
-	    if ((tdd_sfa != 2) && (tdd_sfa != 5))
-		return;
-	    break;
-	case 4:
-	    if ((tdd_sfa != 1) && (tdd_sfa != 2) && (tdd_sfa != 4)
-		&& (tdd_sfa != 5))
-		return;
-	    break;
-	case 5:
-	    break;
-	case 6:
-	case 7:
-	    if ((tdd_sfa != 3)&& (tdd_sfa != 4) && (tdd_sfa != 5))
-		return;
-	    break;
-	case 8:
-	    if ((tdd_sfa != 2) && (tdd_sfa != 3) && (tdd_sfa != 4)
-		&& (tdd_sfa != 5))
-		return;
-	    break;
-	case 9:
-	    if (tdd_sfa == 0)
-		return;
-	    break;
-
-	  }
+  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
+    for (i = 0; i < dlsch_ue_select[CC_id].ue_num; i++) {
+      if(dlsch_ue_select[CC_id].list[i].ue_priority == SCH_DL_MSG2) {
+        continue;
+      }
+
+      if(dlsch_ue_select[CC_id].list[i].ue_priority == SCH_DL_MSG4) {
+        continue;
+      }
+
+      UE_id = dlsch_ue_select[CC_id].list[i].UE_id;
+      ue_sched_ctl = &RC.mac[Mod_id]->UE_list.UE_sched_ctrl[UE_id];
+      //PHY_vars_eNB_g[Mod_id]->mu_mimo_mode[UE_id].dl_pow_off = dl_pow_off[UE_id];
+
+      if (ue_sched_ctl->pre_nb_available_rbs[CC_id] > 0) {
+        LOG_D(MAC,
+              "******************DL Scheduling Information for UE%d ************************\n",
+              UE_id);
+        LOG_D(MAC, "dl power offset UE%d = %d \n", UE_id,
+              ue_sched_ctl->dl_pow_off[CC_id]);
+        LOG_D(MAC,
+              "***********RB Alloc for every subband for UE%d ***********\n",
+              UE_id);
+
+        for (j = 0; j < N_RBG[CC_id]; j++) {
+          //PHY_vars_eNB_g[Mod_id]->mu_mimo_mode[UE_id].rballoc_sub[i] = rballoc_sub_UE[CC_id][UE_id][i];
+          LOG_D(MAC, "RB Alloc for UE%d and Subband%d = %d\n",
+                UE_id, j,
+                ue_sched_ctl->rballoc_sub_UE[CC_id][j]);
+        }
+
+        //PHY_vars_eNB_g[Mod_id]->mu_mimo_mode[UE_id].pre_nb_available_rbs = pre_nb_available_rbs[CC_id][UE_id];
+        LOG_D(MAC, "Total RBs allocated for UE%d = %d\n", UE_id,
+              ue_sched_ctl->pre_nb_available_rbs[CC_id]);
+      }
     }
+  }
+}
 
-    //weight = get_ue_weight(module_idP,UE_id);
-//    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;
+
+//------------------------------------------------------------------------------
+void
+schedule_ue_spec_fairRR(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;
+  int tdd_sfa;
+  int ta_update;
+#ifdef DEBUG_eNB_SCHEDULER
+  int k;
+#endif
+
+  start_meas(&eNB->schedule_dlsch);
+  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME
+  (VCD_SIGNAL_DUMPER_FUNCTIONS_SCHEDULE_DLSCH, VCD_FUNCTION_IN);
+
+  // for TDD: check that we have to act here, otherwise return
+  if (cc[0].tdd_Config) {
+    tdd_sfa = cc[0].tdd_Config->subframeAssignment;
+
+    switch (subframeP) {
+      case 0:
+        // always continue
+        break;
+
+      case 1:
+        return;
+        break;
+
+      case 2:
+        return;
+        break;
+
+      case 3:
+        if ((tdd_sfa != 2) && (tdd_sfa != 5))
+          return;
+
+        break;
+
+      case 4:
+        if ((tdd_sfa != 1) && (tdd_sfa != 2) && (tdd_sfa != 4)
+            && (tdd_sfa != 5))
+          return;
+
+        break;
+
+      case 5:
+        break;
+
+      case 6:
+      case 7:
+        if ((tdd_sfa != 3)&& (tdd_sfa != 4) && (tdd_sfa != 5))
+          return;
+
+        break;
+
+      case 8:
+        if ((tdd_sfa != 2) && (tdd_sfa != 3) && (tdd_sfa != 4)
+            && (tdd_sfa != 5))
+          return;
+
+        break;
+
+      case 9:
+        if (tdd_sfa == 0)
+          return;
+
+        break;
     }
+  }
 
-  /// CALLING Pre_Processor for downlink scheduling (Returns estimation of RBs required by each UE and the allocation on sub-band)
+  //weight = get_ue_weight(module_idP,UE_id);
+  //    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_fairRR(module_idP,
-                                frameP,
-                                subframeP,
-                                N_RBG,
-                                mbsfn_flag);
+                                       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++) {
     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;
 
     for (i = 0; i < dlsch_ue_select[CC_id].ue_num; i++) {
-      if(dlsch_ue_select[CC_id].list[i].ue_priority == SCH_DL_MSG2){
+      if(dlsch_ue_select[CC_id].list[i].ue_priority == SCH_DL_MSG2) {
         continue;
       }
-      if(dlsch_ue_select[CC_id].list[i].ue_priority == SCH_DL_MSG4){
+
+      if(dlsch_ue_select[CC_id].list[i].ue_priority == SCH_DL_MSG4) {
         continue;
       }
+
       UE_id = dlsch_ue_select[CC_id].list[i].UE_id;
       rnti = UE_RNTI(module_idP,UE_id);
+
       if (rnti==NOT_A_RNTI) {
         LOG_E(MAC,"Cannot find rnti for UE_id %d (num_UEs %d)\n",UE_id,UE_list->num_UEs);
         continue;
@@ -928,387 +957,377 @@ schedule_ue_spec_fairRR(module_id_t module_idP,
 
       eNB_UE_stats = &UE_list->eNB_UE_stats[CC_id][UE_id];
       ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
-/*
-      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),
-                                      ue_sched_ctl->dl_cqi[CC_id],
-                                      format1);
-        break;
-      case 3:
-        aggregation = get_aggregation(get_bw_index(module_idP,CC_id),
-                                      ue_sched_ctl->dl_cqi[CC_id],
-                                      format2A);
-        break;
-      default:
-        LOG_W(MAC,"Unsupported transmission mode %d\n", get_tmode(module_idP,CC_id,UE_id));
-        aggregation = 2;
-        break;
-      }
-*/
+
+      /*
+            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),
+                                            ue_sched_ctl->dl_cqi[CC_id],
+                                            format1);
+              break;
+            case 3:
+              aggregation = get_aggregation(get_bw_index(module_idP,CC_id),
+                                            ue_sched_ctl->dl_cqi[CC_id],
+                                            format2A);
+              break;
+            default:
+              LOG_W(MAC,"Unsupported transmission mode %d\n", get_tmode(module_idP,CC_id,UE_id));
+              aggregation = 2;
+              break;
+            }
+      */
       if (cc[CC_id].tdd_Config != NULL) { //TDD
         set_ue_dai (subframeP,
                     UE_id,
                     CC_id,
-  		    cc[CC_id].tdd_Config->subframeAssignment,
+                    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);
       }
 
-	    nb_available_rb = ue_sched_ctl->pre_nb_available_rbs[CC_id];
+      nb_available_rb = ue_sched_ctl->pre_nb_available_rbs[CC_id];
+      harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frameP,subframeP);
+      round = ue_sched_ctl->round[CC_id][harq_pid];
+      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);
+      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;
+
+      if (UE_list->eNB_UE_stats[CC_id][UE_id].rrc_status <
+          RRC_CONNECTED)
+        continue;
 
-	    harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frameP ,subframeP);
+      sdu_length_total = 0;
+      num_sdus = 0;
 
-	    round = ue_sched_ctl->round[CC_id][harq_pid];
+      /*
+         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);
+       */
+      if (nfapi_mode) {
+        eNB_UE_stats->dlsch_mcs1 = 10;//cqi_to_mcs[ue_sched_ctl->dl_cqi[CC_id]];
+      } else {
+        eNB_UE_stats->dlsch_mcs1 = cqi_to_mcs[ue_sched_ctl->dl_cqi[CC_id]];
+      }
+
+      //eNB_UE_stats->dlsch_mcs1 = cmin(eNB_UE_stats->dlsch_mcs1, openair_daq_vars.target_ue_dl_mcs);
+
+      // store stats
+      //UE_list->eNB_UE_stats[CC_id][UE_id].dl_cqi= eNB_UE_stats->dl_cqi;
 
-	    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);
-	    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;
+      // initializing the rb allocation indicator for each UE
+      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, ue_sched_ctl->dl_cqi[CC_id],
+            eNB_UE_stats->dlsch_mcs1,
+            UE_list->eNB_UE_stats[CC_id][UE_id].rrc_status);
 
-	    if (UE_list->eNB_UE_stats[CC_id][UE_id].rrc_status <
-		RRC_CONNECTED)
-		continue;
+      /* process retransmission  */
 
-	    sdu_length_total = 0;
-	    num_sdus = 0;
+      if (round != 8) {
+        // get freq_allocation
+        nb_rb = UE_list->UE_template[CC_id][UE_id].nb_rb[harq_pid];
+        TBS =
+          get_TBS_DL(UE_list->
+                     UE_template[CC_id][UE_id].oldmcs1[harq_pid],
+                     nb_rb);
 
-	    /*
-	       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);
-	     */
-            if (nfapi_mode) {
-              eNB_UE_stats->dlsch_mcs1 = 10;//cqi_to_mcs[ue_sched_ctl->dl_cqi[CC_id]];
+        if (nb_rb <= nb_available_rb) {
+          if (cc[CC_id].tdd_Config != NULL) {
+            UE_list->UE_template[CC_id][UE_id].DAI++;
+            update_ul_dci(module_idP, CC_id, rnti,
+                          UE_list->UE_template[CC_id][UE_id].
+                          DAI,subframeP);
+            LOG_D(MAC,
+                  "DAI update: CC_id %d subframeP %d: UE %d, DAI %d\n",
+                  CC_id, subframeP, UE_id,
+                  UE_list->UE_template[CC_id][UE_id].DAI);
+          }
+
+          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 {
-              eNB_UE_stats->dlsch_mcs1 = cqi_to_mcs[ue_sched_ctl->dl_cqi[CC_id]];
+          } 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) {
+                if (UE_list->
+                    UE_template[CC_id]
+                    [UE_id].rballoc_subband[harq_pid][j])
+                  printf
+                  ("WARN: rballoc_subband not free for retrans?\n");
+
+                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;
             }
-	    eNB_UE_stats->dlsch_mcs1 = eNB_UE_stats->dlsch_mcs1;	//cmin(eNB_UE_stats->dlsch_mcs1, openair_daq_vars.target_ue_dl_mcs);
-
-
-	    // 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
-	    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, ue_sched_ctl->dl_cqi[CC_id],
-		  eNB_UE_stats->dlsch_mcs1,
-		  UE_list->eNB_UE_stats[CC_id][UE_id].rrc_status);
-
-
-
-	    /* process retransmission  */
-
-	    if (round != 8) {
-
-		// get freq_allocation
-		nb_rb = UE_list->UE_template[CC_id][UE_id].nb_rb[harq_pid];
-		TBS =
-		    get_TBS_DL(UE_list->
-			       UE_template[CC_id][UE_id].oldmcs1[harq_pid],
-			       nb_rb);
-
-		if (nb_rb <= nb_available_rb) {
-		    if (cc[CC_id].tdd_Config != NULL) {
-			UE_list->UE_template[CC_id][UE_id].DAI++;
-			update_ul_dci(module_idP, CC_id, rnti,
-				      UE_list->UE_template[CC_id][UE_id].
-				      DAI,subframeP);
-			LOG_D(MAC,
-			      "DAI update: CC_id %d subframeP %d: UE %d, DAI %d\n",
-			      CC_id, subframeP, UE_id,
-			      UE_list->UE_template[CC_id][UE_id].DAI);
-		    }
-
-		    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) {
-				if (UE_list->
-				    UE_template[CC_id]
-				    [UE_id].rballoc_subband[harq_pid][j])
-				    printf
-					("WARN: rballoc_subband not free for retrans?\n");
-				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:
-                      LOG_D(MAC,"retransmission DL_REQ: rnti:%x\n",rnti);
-
-			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.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL8_TAG;
-			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),
-					    ue_sched_ctl->dl_cqi[CC_id],
-					    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 = 1;	// dont adjust power when retransmitting
-			dl_config_pdu->dci_dl_pdu.
-			    dci_dl_pdu_rel8.new_data_indicator_1 =
-			    UE_list->UE_template[CC_id][UE_id].
-			    oldNDI[harq_pid];
-			dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1 =
-			    UE_list->UE_template[CC_id][UE_id].
-			    oldmcs1[harq_pid];
-			dl_config_pdu->dci_dl_pdu.
-			    dci_dl_pdu_rel8.redundancy_version_1 =
-			    round & 3;
-
-			if (cc[CC_id].tdd_Config != NULL) {	//TDD
-			    dl_config_pdu->dci_dl_pdu.
-				dci_dl_pdu_rel8.downlink_assignment_index =
-				(UE_list->UE_template[CC_id][UE_id].DAI -
-				 1) & 3;
-			    LOG_D(MAC,
-				  "[eNB %d] Retransmission CC_id %d : harq_pid %d, round %d, dai %d, mcs %d\n",
-				  module_idP, CC_id, harq_pid, round,
-				  (UE_list->UE_template[CC_id][UE_id].DAI -
-				   1),
-				  UE_list->
-				  UE_template[CC_id][UE_id].oldmcs1
-				  [harq_pid]);
-			} else {
-			    LOG_D(MAC,
-				  "[eNB %d] Retransmission CC_id %d : harq_pid %d, round %d, mcs %d\n",
-				  module_idP, CC_id, harq_pid, round,
-				  UE_list->
-				  UE_template[CC_id][UE_id].oldmcs1
-				  [harq_pid]);
-
-			}
-			if (!CCE_allocation_infeasible
-			    (module_idP, CC_id, 1, subframeP,
-			     dl_config_pdu->dci_dl_pdu.
-			     dci_dl_pdu_rel8.aggregation_level, rnti)) {
-			    dl_req->number_dci++;
-			    dl_req->number_pdu++;
-                            dl_req->tl.tag = NFAPI_DL_CONFIG_REQUEST_BODY_TAG;
-
-                            eNB->DL_req[CC_id].sfn_sf = frameP<<4 | subframeP;
-                            eNB->DL_req[CC_id].header.message_id = NFAPI_DL_CONFIG_REQUEST;
-
-			    fill_nfapi_dlsch_config(eNB, dl_req, TBS, -1
-						    /* retransmission, no pdu_index */
-						    , rnti, 0,	// type 0 allocation from 7.1.6 in 36.213
-						    0,	// virtual_resource_block_assignment_flag, unused here
-						    0,	// resource_block_coding, to be filled in later
-						    getQm(UE_list->UE_template[CC_id][UE_id].oldmcs1[harq_pid]), round & 3,	// redundancy version
-						    1,	// transport blocks
-						    0,	// transport block to codeword swap flag
-						    cc[CC_id].p_eNB == 1 ? 0 : 1,	// transmission_scheme
-						    1,	// number of layers
-						    1,	// number of subbands
-						    //                      uint8_t codebook_index,
-						    4,	// UE category capacity
-						    UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated->pdsch_ConfigDedicated->p_a, 0,	// delta_power_offset for TM5
-						    0,	// ngap
-						    0,	// nprb
-						    cc[CC_id].p_eNB == 1 ? 1 : 2,	// transmission mode
-						    0,	//number of PRBs treated as one subband, not used here
-						    0	// number of beamforming vectors, not used here
-				);
-
-			    LOG_D(MAC,
-				  "Filled NFAPI configuration for DCI/DLSCH %d, retransmission round %d\n",
-				  eNB->pdu_index[CC_id], round);
-
-			    program_dlsch_acknak(module_idP, CC_id, UE_id,
-						 frameP, subframeP,
-						 dl_config_pdu->
-						 dci_dl_pdu.dci_dl_pdu_rel8.
-						 cce_idx);
-			    // No TX request for retransmission (check if null request for FAPI)
-			} else {
-			    LOG_W(MAC,
-				  "Frame %d, Subframe %d: Dropping DLSCH allocation for UE %d\%x, infeasible CCE allocation\n",
-				  frameP, subframeP, UE_id, rnti);
-			}
-		    }
-
-
-		    add_ue_dlsch_info(module_idP,
-				      CC_id, UE_id, subframeP,
-				      S_DL_SCHEDULED);
-
-		    //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;
-		} 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 =
-		    get_TBS_DL(eNB_UE_stats->dlsch_mcs1, nb_available_rb);
-		// 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 (ta_update != 31)
-			ue_sched_ctl->ta_timer = 20;
-		    /* reset ta_update */
-		    ue_sched_ctl->ta_update = 31;
-		} else {
-		    ta_update = 31;
-		}
-
-		ta_len = (ta_update != 31) ? 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)
-#ifdef Rel14
-                                                    ,0, 0
+          }
+
+          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:
+              LOG_D(MAC,"retransmission DL_REQ: rnti:%x\n",rnti);
+              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.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL8_TAG;
+              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),
+                                ue_sched_ctl->dl_cqi[CC_id],
+                                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 = 1;  // dont adjust power when retransmitting
+              dl_config_pdu->dci_dl_pdu.
+              dci_dl_pdu_rel8.new_data_indicator_1 =
+                UE_list->UE_template[CC_id][UE_id].
+                oldNDI[harq_pid];
+              dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1 =
+                UE_list->UE_template[CC_id][UE_id].
+                oldmcs1[harq_pid];
+              dl_config_pdu->dci_dl_pdu.
+              dci_dl_pdu_rel8.redundancy_version_1 =
+                round & 3;
+
+              if (cc[CC_id].tdd_Config != NULL) { //TDD
+                dl_config_pdu->dci_dl_pdu.
+                dci_dl_pdu_rel8.downlink_assignment_index =
+                  (UE_list->UE_template[CC_id][UE_id].DAI -
+                   1) & 3;
+                LOG_D(MAC,
+                      "[eNB %d] Retransmission CC_id %d : harq_pid %d, round %d, dai %d, mcs %d\n",
+                      module_idP, CC_id, harq_pid, round,
+                      (UE_list->UE_template[CC_id][UE_id].DAI -
+                       1),
+                      UE_list->
+                      UE_template[CC_id][UE_id].oldmcs1
+                      [harq_pid]);
+              } else {
+                LOG_D(MAC,
+                      "[eNB %d] Retransmission CC_id %d : harq_pid %d, round %d, mcs %d\n",
+                      module_idP, CC_id, harq_pid, round,
+                      UE_list->
+                      UE_template[CC_id][UE_id].oldmcs1
+                      [harq_pid]);
+              }
+
+              if (!CCE_allocation_infeasible
+                  (module_idP, CC_id, 1, subframeP,
+                   dl_config_pdu->dci_dl_pdu.
+                   dci_dl_pdu_rel8.aggregation_level, rnti)) {
+                dl_req->number_dci++;
+                dl_req->number_pdu++;
+                dl_req->tl.tag = NFAPI_DL_CONFIG_REQUEST_BODY_TAG;
+                eNB->DL_req[CC_id].sfn_sf = frameP<<4 | subframeP;
+                eNB->DL_req[CC_id].header.message_id = NFAPI_DL_CONFIG_REQUEST;
+                fill_nfapi_dlsch_config(eNB, dl_req, TBS, -1
+                                        /* retransmission, no pdu_index */
+                                        , rnti, 0,  // type 0 allocation from 7.1.6 in 36.213
+                                        0,  // virtual_resource_block_assignment_flag, unused here
+                                        0,  // resource_block_coding, to be filled in later
+                                        getQm(UE_list->UE_template[CC_id][UE_id].oldmcs1[harq_pid]), round & 3, // redundancy version
+                                        1,  // transport blocks
+                                        0,  // transport block to codeword swap flag
+                                        cc[CC_id].p_eNB == 1 ? 0 : 1, // transmission_scheme
+                                        1,  // number of layers
+                                        1,  // number of subbands
+                                        //                      uint8_t codebook_index,
+                                        4,  // UE category capacity
+                                        UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated->pdsch_ConfigDedicated->p_a, 0,  // delta_power_offset for TM5
+                                        0,  // ngap
+                                        0,  // nprb
+                                        cc[CC_id].p_eNB == 1 ? 1 : 2, // transmission mode
+                                        0,  //number of PRBs treated as one subband, not used here
+                                        0 // number of beamforming vectors, not used here
+                                       );
+                LOG_D(MAC,
+                      "Filled NFAPI configuration for DCI/DLSCH %d, retransmission round %d\n",
+                      eNB->pdu_index[CC_id], round);
+                program_dlsch_acknak(module_idP, CC_id, UE_id,
+                                     frameP, subframeP,
+                                     dl_config_pdu->
+                                     dci_dl_pdu.dci_dl_pdu_rel8.
+                                     cce_idx);
+                // No TX request for retransmission (check if null request for FAPI)
+              } else {
+                LOG_W(MAC,
+                      "Frame %d, Subframe %d: Dropping DLSCH allocation for UE %d\%x, infeasible CCE allocation\n",
+                      frameP, subframeP, UE_id, rnti);
+              }
+          }
+
+          add_ue_dlsch_info(module_idP,
+                            CC_id, UE_id, subframeP,
+                            S_DL_SCHEDULED);
+          //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;
+        } 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 =
+          get_TBS_DL(eNB_UE_stats->dlsch_mcs1, nb_available_rb);
+        // 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 (ta_update != 31)
+            ue_sched_ctl->ta_timer = 20;
+
+          /* reset ta_update */
+          ue_sched_ctl->ta_update = 31;
+        } else {
+          ta_update = 31;
+        }
+
+        ta_len = (ta_update != 31) ? 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)
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                                          ,0, 0
 #endif
-                                                   );	// 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] SFN/SF %d.%d, DL-DCCH->DLSCH CC_id %d, Requesting %d bytes from RLC (RRC message)\n",
-			      module_idP, frameP, subframeP, 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]
-#ifdef Rel14
-                                                          ,0, 0
+                                         ); // 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] SFN/SF %d.%d, DL-DCCH->DLSCH CC_id %d, Requesting %d bytes from RLC (RRC message)\n",
+                  module_idP, frameP, subframeP, 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]
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                                              ,0, 0
 #endif
-                                                         );
+                                             );
             pthread_mutex_lock(&rrc_release_freelist);
-            if((rrc_release_info.num_UEs > 0) && (rlc_am_mui.rrc_mui_num > 0)){
+
+            if((rrc_release_info.num_UEs > 0) && (rlc_am_mui.rrc_mui_num > 0)) {
               uint16_t release_total = 0;
-              for(uint16_t release_num = 0;release_num < NUMBER_OF_UE_MAX;release_num++){
-                if(rrc_release_info.RRC_release_ctrl[release_num].flag > 0){
+
+              for(uint16_t release_num = 0; release_num < NUMBER_OF_UE_MAX; release_num++) {
+                if(rrc_release_info.RRC_release_ctrl[release_num].flag > 0) {
                   release_total++;
-                }else{
+                } else {
                   continue;
                 }
 
-                if(rrc_release_info.RRC_release_ctrl[release_num].flag == 1){
-                  if(rrc_release_info.RRC_release_ctrl[release_num].rnti == rnti){
-                    for(uint16_t mui_num = 0;mui_num < rlc_am_mui.rrc_mui_num;mui_num++){
-                      if(rrc_release_info.RRC_release_ctrl[release_num].rrc_eNB_mui == rlc_am_mui.rrc_mui[mui_num]){
+                if(rrc_release_info.RRC_release_ctrl[release_num].flag == 1) {
+                  if(rrc_release_info.RRC_release_ctrl[release_num].rnti == rnti) {
+                    for(uint16_t mui_num = 0; mui_num < rlc_am_mui.rrc_mui_num; mui_num++) {
+                      if(rrc_release_info.RRC_release_ctrl[release_num].rrc_eNB_mui == rlc_am_mui.rrc_mui[mui_num]) {
                         rrc_release_info.RRC_release_ctrl[release_num].flag = 3;
                         LOG_D(MAC,"DLSCH Release send:index %d rnti %x mui %d mui_num %d flag 1->3\n",release_num,rnti,rlc_am_mui.rrc_mui[mui_num],mui_num);
                         break;
-                       }
-                     }
+                      }
+                    }
                   }
                 }
-                if(rrc_release_info.RRC_release_ctrl[release_num].flag == 2){
-                  if(rrc_release_info.RRC_release_ctrl[release_num].rnti == rnti){
-                    for(uint16_t mui_num = 0;mui_num < rlc_am_mui.rrc_mui_num;mui_num++){
-                      if(rrc_release_info.RRC_release_ctrl[release_num].rrc_eNB_mui == rlc_am_mui.rrc_mui[mui_num]){
-                          rrc_release_info.RRC_release_ctrl[release_num].flag = 4;
-                          LOG_D(MAC,"DLSCH Release send:index %d rnti %x mui %d mui_num %d flag 2->4\n",release_num,rnti,rlc_am_mui.rrc_mui[mui_num],mui_num);
-                          break;
+
+                if(rrc_release_info.RRC_release_ctrl[release_num].flag == 2) {
+                  if(rrc_release_info.RRC_release_ctrl[release_num].rnti == rnti) {
+                    for(uint16_t mui_num = 0; mui_num < rlc_am_mui.rrc_mui_num; mui_num++) {
+                      if(rrc_release_info.RRC_release_ctrl[release_num].rrc_eNB_mui == rlc_am_mui.rrc_mui[mui_num]) {
+                        rrc_release_info.RRC_release_ctrl[release_num].flag = 4;
+                        LOG_D(MAC,"DLSCH Release send:index %d rnti %x mui %d mui_num %d flag 2->4\n",release_num,rnti,rlc_am_mui.rrc_mui[mui_num],mui_num);
+                        break;
                       }
                     }
                   }
                 }
+
                 if(release_total >= rrc_release_info.num_UEs)
                   break;
               }
             }
-            pthread_mutex_unlock(&rrc_release_freelist);
 
+            pthread_mutex_unlock(&rrc_release_freelist);
             RA_t *ra = &eNB->common_channels[CC_id].ra[0];
+
             for (uint8_t ra_ii = 0; ra_ii < NB_RA_PROC_MAX; ra_ii++) {
-              if((ra[ra_ii].rnti == rnti) && (ra[ra_ii].state == MSGCRNTI)){
-                for(uint16_t mui_num = 0;mui_num < rlc_am_mui.rrc_mui_num;mui_num++){
-                  if(ra[ra_ii].crnti_rrc_mui == rlc_am_mui.rrc_mui[mui_num]){
+              if((ra[ra_ii].rnti == rnti) && (ra[ra_ii].state == MSGCRNTI)) {
+                for(uint16_t mui_num = 0; mui_num < rlc_am_mui.rrc_mui_num; mui_num++) {
+                  if(ra[ra_ii].crnti_rrc_mui == rlc_am_mui.rrc_mui[mui_num]) {
                     ra[ra_ii].crnti_harq_pid = harq_pid;
                     ra[ra_ii].state = MSGCRNTI_ACK;
                     break;
@@ -1316,337 +1335,339 @@ schedule_ue_spec_fairRR(module_id_t module_idP,
                 }
               }
             }
-			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 frame %d subframe %d UE_id %d/%x Got %d bytes bytes_in_buffer %d from release_num %d\n",
-                             module_idP, CC_id, frameP, subframeP, UE_id, rnti, sdu_lengths[0],rlc_status.bytes_in_buffer,rrc_release_info.num_UEs);
- 
-			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;
+
+            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 frame %d subframe %d UE_id %d/%x Got %d bytes bytes_in_buffer %d from release_num %d\n",
+                  module_idP, CC_id, frameP, subframeP, UE_id, rnti, sdu_lengths[0],rlc_status.bytes_in_buffer,rrc_release_info.num_UEs);
+            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]);
+            LOG_T(MAC,
+                  "[eNB %d][DCCH] CC_id %d Got %d bytes :",
+                  module_idP, CC_id, sdu_lengths[0]);
 
-			for (k = 0; k < sdu_lengths[0]; k++) {
-			    LOG_T(MAC, "%x ", dlsch_buffer[k]);
-			}
+            for (k = 0; k < sdu_lengths[0]; k++) {
+              LOG_T(MAC, "%x ", dlsch_buffer[k]);
+            }
 
-			LOG_T(MAC, "\n");
+            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)
-#ifdef Rel14
-                                                    ,0, 0
+          } 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)
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                                          ,0, 0
 #endif
-                                                   );	// 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_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]
-#ifdef Rel14
-                                                                  ,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_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]
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                                     ,0, 0
 #endif
-                                                                 );
-
-			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++;
+                                                     );
+            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]);
+            LOG_T(MAC,
+                  "[eNB %d][DCCH1] CC_id %d Got %d bytes :",
+                  module_idP, CC_id, sdu_lengths[num_sdus]);
 
-			for (k = 0; k < sdu_lengths[num_sdus]; k++) {
-			    LOG_T(MAC, "%x ", dlsch_buffer[k]);
-			}
+            for (k = 0; k < sdu_lengths[num_sdus]; k++) {
+              LOG_T(MAC, "%x ", dlsch_buffer[k]);
+            }
 
-			LOG_T(MAC, "\n");
+            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
 
-		    }
-		}
-		// 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).
-	    /* TODO limited lcid for performance */
+        // lcid has to be sorted before the actual allocation (similar struct as ue_list).
+        /* TODO limited lcid for performance */
         for (lcid = DTCH; 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
+          // 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
 #ifdef Rel14
-                                                        ,0, 0
+                                            , 0, 0
 #endif
-                                                       );
-
-
-			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]
+                                           );
+
+            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]
 #ifdef Rel14
-                                                                     ,0, 0
+                                      , 0, 0
 #endif
-                                                                    );
-			    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++;
-                            UE_list->UE_sched_ctrl[UE_id].uplane_inactivity_timer = 0;
-			}	// 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;
-            nb_rb = min_rb_unit[CC_id];
-		    TBS = 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;
-			}
-		    }
-
-		    // 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);
+                                                      );
+              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++;
+              UE_list->UE_sched_ctrl[UE_id].uplane_inactivity_timer = 0;
+            } else { // no data for this LCID
+              header_len_dtch -= 3;
+            }
+          } else {  // no TBS left
+            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;
+          nb_rb = min_rb_unit[CC_id];
+          TBS = 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;
+            }
+          }
+
+          // 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);
+          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
-		    }
+          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
+          }
 
 #ifdef PHY_TX_THREAD
-  struct timespec time_req, time_rem;
-  time_req.tv_sec = 0;
-  time_req.tv_nsec = 10000;
-		    while((!oai_exit)&&(phy_tx_txdataF_end == 0)){
-		      nanosleep(&time_req,&time_rem);
-		        continue;
-		    }
+          struct timespec time_req, time_rem;
+          time_req.tv_sec = 0;
+          time_req.tv_nsec = 10000;
+
+          while((!oai_exit)&&(phy_tx_txdataF_end == 0)) {
+            nanosleep(&time_req,&time_rem);
+            continue;
+          }
+
 #endif
+          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);
+
+          //#ifdef DEBUG_eNB_SCHEDULER
+          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, nb_rb,
+                  header_len_dcch, header_len_dtch);
+          }
 
-		    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);
-
-		    //#ifdef DEBUG_eNB_SCHEDULER
-		    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, nb_rb,
-			      header_len_dcch, header_len_dtch);
-		    }
-		    //#endif
+          //#endif
 #ifdef DEBUG_eNB_SCHEDULER
-		    LOG_T(MAC, "[eNB %d] First 16 bytes of DLSCH : \n",module_idP );
+          LOG_T(MAC, "[eNB %d] First 16 bytes of DLSCH : \n",module_idP );
 
-		    for (k = 0; k < 16; k++) {
-			LOG_T(MAC, "%x.", dlsch_buffer[k]);
-		    }
+          for (k = 0; k < 16; k++) {
+            LOG_T(MAC, "%x.", dlsch_buffer[k]);
+          }
 
-		    LOG_T(MAC, "\n");
+          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]);
@@ -1666,9 +1687,7 @@ schedule_ue_spec_fairRR(module_id_t module_idP,
 
           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;
-
+          UE_list->UE_template[CC_id][UE_id].nb_rb[harq_pid] = nb_rb;
           add_ue_dlsch_info(module_idP,
                             CC_id,
                             UE_id,
@@ -1677,13 +1696,11 @@ schedule_ue_spec_fairRR(module_id_t module_idP,
           // 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=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;
@@ -1694,168 +1711,152 @@ schedule_ue_spec_fairRR(module_id_t module_idP,
             update_ul_dci(module_idP,CC_id,rnti,UE_list->UE_template[CC_id][UE_id].DAI,subframeP);
           }
 
-	  // do PUCCH power control
+          // do PUCCH power control
           // this is the normalized RX power
-	  eNB_UE_stats =  &UE_list->eNB_UE_stats[CC_id][UE_id];
-
+          eNB_UE_stats =  &UE_list->eNB_UE_stats[CC_id][UE_id];
           /* Unit is not dBm, it's special from nfapi */
-      normalized_rx_power = (5*ue_sched_ctl->pucch1_snr[CC_id]-640)/10+30;//(+eNB->measurements.n0_power_dB[0])
-	  target_rx_power= eNB->puCch10xSnr/10 + 30;//(+eNB->measurements.n0_power_dB[0])
-	    
+          normalized_rx_power = (5*ue_sched_ctl->pucch1_snr[CC_id]-640)/10+30;//(+eNB->measurements.n0_power_dB[0])
+          target_rx_power= eNB->puCch10xSnr/10 + 30;//(+eNB->measurements.n0_power_dB[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_list->UE_template[CC_id][UE_id].pucch_tpc_tx_frame*10+UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_subframe;
+          // 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
-		tpc_accumulated--;
-	      } else if (normalized_rx_power<(target_rx_power-4)) {
-		tpc = 2; //+1
-		tpc_accumulated++;
-	      } else {
-		tpc = 1; //0
-	      }
-	      	      
-	      LOG_D(MAC,"[eNB %d] DLSCH 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,
-		    tpc_accumulated,normalized_rx_power,target_rx_power);
-
-	    } // Po_PUCCH has been updated 
-	    else {
-	      tpc = 1; //0
-	    } // time to do TPC update 
-	  else {
-	    tpc = 1; //0
-	  }
-
-	  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),ue_sched_ctl->dl_cqi[CC_id],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;
-	  if (cc[CC_id].tdd_Config != NULL) { //TDD
-	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.downlink_assignment_index = (UE_list->UE_template[CC_id][UE_id].DAI-1)&3;
-	    LOG_D(MAC,"[eNB %d] Initial transmission CC_id %d : harq_pid %d, dai %d, mcs %d\n",
-		  module_idP,CC_id,harq_pid,
-		  (UE_list->UE_template[CC_id][UE_id].DAI-1),
-		  mcs);
-	  } else {
-	    LOG_D(MAC,"[eNB %d] Initial transmission CC_id %d : harq_pid %d, mcs %d\n",
-		  module_idP,CC_id,harq_pid,mcs);
-	    
-	  }
-	  LOG_D(MAC,"Checking feasibility pdu %d (new sdu)\n",dl_req->number_pdu);
-	  if (!CCE_allocation_infeasible(module_idP,CC_id,1,subframeP,dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level,rnti)) {
-
-
-	    ue_sched_ctl->round[CC_id][harq_pid] = 0;
-	    dl_req->number_dci++;
-	    dl_req->number_pdu++;
-	    dl_req->tl.tag = NFAPI_DL_CONFIG_REQUEST_BODY_TAG;
-	    
-	    eNB->DL_req[CC_id].sfn_sf = frameP<<4 | subframeP;
-	    eNB->DL_req[CC_id].header.message_id = NFAPI_DL_CONFIG_REQUEST;
-	    // 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,
-		  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;
-	    AssertFatal(UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated!=NULL,"physicalConfigDedicated is NULL\n");
-	    AssertFatal(UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated->pdsch_ConfigDedicated!=NULL,"physicalConfigDedicated->pdsch_ConfigDedicated is NULL\n");
-	    
-	    fill_nfapi_dlsch_config(eNB,dl_req,
-				    TBS,
-				    eNB->pdu_index[CC_id],
-				    rnti,
-				    0, // type 0 allocation from 7.1.6 in 36.213
-				    0, // virtual_resource_block_assignment_flag, unused here
-				    0, // resource_block_coding, to be filled in later
-				    getQm(mcs),
-				    0, // redundancy version
-				    1, // transport blocks
-				    0, // transport block to codeword swap flag
-				    cc[CC_id].p_eNB == 1 ? 0 : 1, // transmission_scheme
-				    1, // number of layers
-				    1, // number of subbands
-				    //			     uint8_t codebook_index,
-				    4, // UE category capacity
-				    UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated->pdsch_ConfigDedicated->p_a, 
-				    0, // delta_power_offset for TM5
-				    0, // ngap
-				    0, // nprb
-				    cc[CC_id].p_eNB == 1 ? 1 : 2, // transmission mode
-				    0, //number of PRBs treated as one subband, not used here
-				    0 // number of beamforming vectors, not used here
-				    );  
-	    eNB->TX_req[CC_id].sfn_sf = fill_nfapi_tx_req(&eNB->TX_req[CC_id].tx_request_body,
-							  (frameP*10)+subframeP,
-							  TBS,
-							  eNB->pdu_index[CC_id],
-							  eNB->UE_list.DLSCH_pdu[CC_id][0][(unsigned char)UE_id].payload[0]);
-	    
-	    LOG_D(MAC,"Filled NFAPI configuration for DCI/DLSCH/TXREQ %d, new SDU\n",eNB->pdu_index[CC_id]);
-
-	    eNB->pdu_index[CC_id]++;
-	    program_dlsch_acknak(module_idP,CC_id,UE_id,frameP,subframeP,dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.cce_idx);
-        last_dlsch_ue_id[CC_id] = UE_id;
-	  }
-	  else {
-	    LOG_W(MAC,"Frame %d, Subframe %d: Dropping DLSCH allocation for UE %d/%x, infeasible CCE allocations\n",
-		  frameP,subframeP,UE_id,rnti);
-	  }
-        } else {  // There is no data from RLC or MAC header, so don't schedule
+              ((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
+                tpc_accumulated--;
+              } else if (normalized_rx_power<(target_rx_power-4)) {
+                tpc = 2; //+1
+                tpc_accumulated++;
+              } else {
+                tpc = 1; //0
+              }
+
+              LOG_D(MAC,"[eNB %d] DLSCH 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,
+                    tpc_accumulated,normalized_rx_power,target_rx_power);
+            } // Po_PUCCH has been updated
+            else {
+              tpc = 1; //0
+            } // time to do TPC update
+          else {
+            tpc = 1; //0
+          }
 
+          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),ue_sched_ctl->dl_cqi[CC_id],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;
+
+          if (cc[CC_id].tdd_Config != NULL) { //TDD
+            dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.downlink_assignment_index = (UE_list->UE_template[CC_id][UE_id].DAI-1)&3;
+            LOG_D(MAC,"[eNB %d] Initial transmission CC_id %d : harq_pid %d, dai %d, mcs %d\n",
+                  module_idP,CC_id,harq_pid,
+                  (UE_list->UE_template[CC_id][UE_id].DAI-1),
+                  mcs);
+          } else {
+            LOG_D(MAC,"[eNB %d] Initial transmission CC_id %d : harq_pid %d, mcs %d\n",
+                  module_idP,CC_id,harq_pid,mcs);
+          }
+
+          LOG_D(MAC,"Checking feasibility pdu %d (new sdu)\n",dl_req->number_pdu);
+
+          if (!CCE_allocation_infeasible(module_idP,CC_id,1,subframeP,dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level,rnti)) {
+            ue_sched_ctl->round[CC_id][harq_pid] = 0;
+            dl_req->number_dci++;
+            dl_req->number_pdu++;
+            dl_req->tl.tag = NFAPI_DL_CONFIG_REQUEST_BODY_TAG;
+            eNB->DL_req[CC_id].sfn_sf = frameP<<4 | subframeP;
+            eNB->DL_req[CC_id].header.message_id = NFAPI_DL_CONFIG_REQUEST;
+            // 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,
+                  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;
+            AssertFatal(UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated!=NULL,"physicalConfigDedicated is NULL\n");
+            AssertFatal(UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated->pdsch_ConfigDedicated!=NULL,"physicalConfigDedicated->pdsch_ConfigDedicated is NULL\n");
+            fill_nfapi_dlsch_config(eNB,dl_req,
+                                    TBS,
+                                    eNB->pdu_index[CC_id],
+                                    rnti,
+                                    0, // type 0 allocation from 7.1.6 in 36.213
+                                    0, // virtual_resource_block_assignment_flag, unused here
+                                    0, // resource_block_coding, to be filled in later
+                                    getQm(mcs),
+                                    0, // redundancy version
+                                    1, // transport blocks
+                                    0, // transport block to codeword swap flag
+                                    cc[CC_id].p_eNB == 1 ? 0 : 1, // transmission_scheme
+                                    1, // number of layers
+                                    1, // number of subbands
+                                    //           uint8_t codebook_index,
+                                    4, // UE category capacity
+                                    UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated->pdsch_ConfigDedicated->p_a,
+                                    0, // delta_power_offset for TM5
+                                    0, // ngap
+                                    0, // nprb
+                                    cc[CC_id].p_eNB == 1 ? 1 : 2, // transmission mode
+                                    0, //number of PRBs treated as one subband, not used here
+                                    0 // number of beamforming vectors, not used here
+                                   );
+            eNB->TX_req[CC_id].sfn_sf = fill_nfapi_tx_req(&eNB->TX_req[CC_id].tx_request_body,
+                                        (frameP*10)+subframeP,
+                                        TBS,
+                                        eNB->pdu_index[CC_id],
+                                        eNB->UE_list.DLSCH_pdu[CC_id][0][(unsigned char)UE_id].payload[0]);
+            LOG_D(MAC,"Filled NFAPI configuration for DCI/DLSCH/TXREQ %d, new SDU\n",eNB->pdu_index[CC_id]);
+            eNB->pdu_index[CC_id]++;
+            program_dlsch_acknak(module_idP,CC_id,UE_id,frameP,subframeP,dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.cce_idx);
+            last_dlsch_ue_id[CC_id] = UE_id;
+          } else {
+            LOG_W(MAC,"Frame %d, Subframe %d: Dropping DLSCH allocation for UE %d/%x, infeasible CCE allocations\n",
+                  frameP,subframeP,UE_id,rnti);
+          }
+        } else {  // There is no data from RLC or MAC header, so don't schedule
         }
       }
 
-      if (cc[CC_id].tdd_Config != NULL){ // TDD
+      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_fairRR(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
 fill_DLSCH_dci_fairRR(
-	       module_id_t module_idP,
-	       frame_t frameP,
-	       sub_frame_t subframeP,
-	       int* mbsfn_flagP)
+  module_id_t module_idP,
+  frame_t frameP,
+  sub_frame_t subframeP,
+  int *mbsfn_flagP)
 //------------------------------------------------------------------------------
 {
-
   // loop over all allocated UEs and compute frequency allocations for PDSCH
   int   UE_id = -1;
   uint8_t            /* first_rb, */ nb_rb=3;
@@ -1863,7 +1864,6 @@ fill_DLSCH_dci_fairRR(
   //unsigned char *vrb_map;
   uint8_t            rballoc_sub[25];
   //uint8_t number_of_subbands=13;
-
   //unsigned char round;
   unsigned char     harq_pid;
   int               i;
@@ -1889,65 +1889,63 @@ fill_DLSCH_dci_fairRR(
 
     // UE specific DCIs
     for (j = 0; j < dlsch_ue_select[CC_id].ue_num; j++) {
-      if(dlsch_ue_select[CC_id].list[j].ue_priority == SCH_DL_MSG2){
+      if(dlsch_ue_select[CC_id].list[j].ue_priority == SCH_DL_MSG2) {
         continue;
       }
-      if(dlsch_ue_select[CC_id].list[j].ue_priority == SCH_DL_MSG4){
+
+      if(dlsch_ue_select[CC_id].list[j].ue_priority == SCH_DL_MSG4) {
         continue;
       }
+
       UE_id = dlsch_ue_select[CC_id].list[j].UE_id;
       LOG_T(MAC,"CC_id %d, UE_id: %d => status %d\n",CC_id,UE_id,eNB_dlsch_info[module_idP][CC_id][UE_id].status);
 
       if (eNB_dlsch_info[module_idP][CC_id][UE_id].status == S_DL_SCHEDULED) {
-
         // clear scheduling flag
         eNB_dlsch_info[module_idP][CC_id][UE_id].status = S_DL_WAITING;
         rnti = UE_RNTI(module_idP,UE_id);
-        harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frameP ,subframeP);
+        harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frameP,subframeP);
         nb_rb = UE_list->UE_template[CC_id][UE_id].nb_rb[harq_pid];
 
-
-	
         /// Synchronizing rballoc with rballoc_sub
         for(i=0; i<N_RBG; i++) {
           rballoc_sub[i] = UE_list->UE_template[CC_id][UE_id].rballoc_subband[harq_pid][i];
         }
 
-	nfapi_dl_config_request_t      *DL_req         = &RC.mac[module_idP]->DL_req[0];
-	nfapi_dl_config_request_pdu_t* dl_config_pdu;
-
-	for (i=0;i<DL_req[CC_id].dl_config_request_body.number_pdu;i++) {
-	  dl_config_pdu                    = &DL_req[CC_id].dl_config_request_body.dl_config_pdu_list[i];
-	  if ((dl_config_pdu->pdu_type == NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE)&&
-	      (dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti == rnti) &&
-          (dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.dci_format != 1)) {
-	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.resource_block_coding    = allocate_prbs_sub(nb_rb,N_RB_DL,N_RBG,rballoc_sub);
-	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.resource_allocation_type = 0;
-	  }
-	  else if ((dl_config_pdu->pdu_type == NFAPI_DL_CONFIG_DLSCH_PDU_TYPE)&&
-		       (dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.rnti == rnti) &&
-               (dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_allocation_type==0)) {
-	    dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_block_coding    = allocate_prbs_sub(nb_rb,N_RB_DL,N_RBG,rballoc_sub);
-	  }
-         }
-	}
+        nfapi_dl_config_request_t      *DL_req         = &RC.mac[module_idP]->DL_req[0];
+        nfapi_dl_config_request_pdu_t *dl_config_pdu;
+
+        for (i=0; i<DL_req[CC_id].dl_config_request_body.number_pdu; i++) {
+          dl_config_pdu                    = &DL_req[CC_id].dl_config_request_body.dl_config_pdu_list[i];
+
+          if ((dl_config_pdu->pdu_type == NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE)&&
+              (dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti == rnti) &&
+              (dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.dci_format != 1)) {
+            dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.resource_block_coding    = allocate_prbs_sub(nb_rb,N_RB_DL,N_RBG,rballoc_sub);
+            dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.resource_allocation_type = 0;
+          } else if ((dl_config_pdu->pdu_type == NFAPI_DL_CONFIG_DLSCH_PDU_TYPE)&&
+                     (dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.rnti == rnti) &&
+                     (dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_allocation_type==0)) {
+            dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_block_coding    = allocate_prbs_sub(nb_rb,N_RB_DL,N_RBG,rballoc_sub);
+          }
+        }
       }
     }
+  }
 
-    stop_meas(&eNB->fill_DLSCH_dci);
-    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME
-	(VCD_SIGNAL_DUMPER_FUNCTIONS_FILL_DLSCH_DCI, VCD_FUNCTION_OUT);
+  stop_meas(&eNB->fill_DLSCH_dci);
+  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME
+  (VCD_SIGNAL_DUMPER_FUNCTIONS_FILL_DLSCH_DCI, VCD_FUNCTION_OUT);
 }
 
 
 
 void ulsch_scheduler_pre_ue_select_fairRR(
-    module_id_t       module_idP,
-    frame_t           frameP,
-    sub_frame_t       subframeP,
-    sub_frame_t       sched_subframeP,
-    ULSCH_UE_SELECT   ulsch_ue_select[MAX_NUM_CCs])
-{
+  module_id_t       module_idP,
+  frame_t           frameP,
+  sub_frame_t       subframeP,
+  sub_frame_t       sched_subframeP,
+  ULSCH_UE_SELECT   ulsch_ue_select[MAX_NUM_CCs]) {
   eNB_MAC_INST *eNB=RC.mac[module_idP];
   COMMON_channels_t *cc;
   int CC_id,UE_id;
@@ -1958,7 +1956,7 @@ void ulsch_scheduler_pre_ue_select_fairRR(
   uint8_t first_ue_id[MAX_NUM_CCs][20];
   uint8_t ul_inactivity_num[MAX_NUM_CCs];
   uint8_t ul_inactivity_id[MAX_NUM_CCs][20];
-//  LTE_DL_FRAME_PARMS *frame_parms;
+  //  LTE_DL_FRAME_PARMS *frame_parms;
   uint8_t ulsch_ue_max_num[MAX_NUM_CCs];
   uint16_t saved_ulsch_dci[MAX_NUM_CCs];
   rnti_t rnti;
@@ -1966,127 +1964,134 @@ void ulsch_scheduler_pre_ue_select_fairRR(
   uint8_t cc_id_flag[MAX_NUM_CCs];
   uint8_t harq_pid = 0,round = 0;
   UE_list_t *UE_list= &eNB->UE_list;
-
-
   uint8_t                        aggregation = 2;
   int                            format_flag;
   nfapi_hi_dci0_request_body_t   *HI_DCI0_req;
   nfapi_hi_dci0_request_pdu_t    *hi_dci0_pdu;
 
-
   for ( CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++ ) {
-      //save ulsch dci number
-      saved_ulsch_dci[CC_id] = eNB->HI_DCI0_req[CC_id][subframeP].hi_dci0_request_body.number_of_dci;
-      // maximum multiplicity number
-      ulsch_ue_max_num[CC_id] =RC.rrc[module_idP]->configuration.ue_multiple_max[CC_id];
-
-      cc_id_flag[CC_id] = 0;
-      ue_first_num[CC_id] = 0;
-      ul_inactivity_num[CC_id] = 0;
-
+    //save ulsch dci number
+    saved_ulsch_dci[CC_id] = eNB->HI_DCI0_req[CC_id][subframeP].hi_dci0_request_body.number_of_dci;
+    // maximum multiplicity number
+    ulsch_ue_max_num[CC_id] =RC.rrc[module_idP]->configuration.radioresourceconfig[CC_id].ue_multiple_max;
+    cc_id_flag[CC_id] = 0;
+    ue_first_num[CC_id] = 0;
+    ul_inactivity_num[CC_id] = 0;
   }
+
   // UE round >0
   for ( UE_id = 0; UE_id < NUMBER_OF_UE_MAX; UE_id++ ) {
-      if (UE_list->active[UE_id] == FALSE)
-          continue;
+    if (UE_list->active[UE_id] == FALSE)
+      continue;
 
-      rnti = UE_RNTI(module_idP,UE_id);
-      if (rnti ==NOT_A_RNTI)
+    rnti = UE_RNTI(module_idP,UE_id);
+
+    if (rnti ==NOT_A_RNTI)
+      continue;
+
+    CC_id = UE_PCCID(module_idP,UE_id);
+
+    if (UE_list->UE_template[CC_id][UE_id].configured == FALSE)
+      continue;
+
+    if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync == 1)
+      continue;
+
+    // UL DCI
+    HI_DCI0_req   = &eNB->HI_DCI0_req[CC_id][subframeP].hi_dci0_request_body;
+
+    if ( (ulsch_ue_select[CC_id].ue_num >= ulsch_ue_max_num[CC_id]) || (cc_id_flag[CC_id] == 1) ) {
+      cc_id_flag[CC_id] = 1;
+      HI_DCI0_req->number_of_dci = saved_ulsch_dci[CC_id];
+      ret = cc_id_end(cc_id_flag);
+
+      if ( ret == 0 ) {
         continue;
+      }
 
-      CC_id = UE_PCCID(module_idP,UE_id);
-      if (UE_list->UE_template[CC_id][UE_id].configured == FALSE)
+      if ( ret == 1 ) {
+        return;
+      }
+    }
+
+    cc = &eNB->common_channels[CC_id];
+    //harq_pid
+    harq_pid = subframe2harqpid(cc,(frameP+(sched_subframeP<subframeP ? 1 : 0)),sched_subframeP);
+    //round
+    round = UE_list->UE_sched_ctrl[UE_id].round_UL[CC_id][harq_pid];
+
+    if ( round > 0 ) {
+      hi_dci0_pdu   = &HI_DCI0_req->hi_dci0_pdu_list[HI_DCI0_req->number_of_dci+HI_DCI0_req->number_of_hi];
+      format_flag = 2;
+
+      if (CCE_allocation_infeasible(module_idP,CC_id,format_flag,subframeP,aggregation,rnti) == 1) {
+        cc_id_flag[CC_id] = 1;
+        continue;
+      } else {
+        hi_dci0_pdu->pdu_type                               = NFAPI_HI_DCI0_DCI_PDU_TYPE;
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.rnti              = rnti;
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.aggregation_level = aggregation;
+        HI_DCI0_req->number_of_dci++;
+        ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].ue_priority = SCH_UL_RETRANS;
+        ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].start_rb = eNB->UE_list.UE_template[CC_id][UE_id].first_rb_ul[harq_pid];
+        ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].nb_rb = eNB->UE_list.UE_template[CC_id][UE_id].nb_rb_ul[harq_pid];
+        ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].UE_id = UE_id;
+        ulsch_ue_select[CC_id].ue_num++;
         continue;
+      }
+    }
+
+    //
+    int bytes_to_schedule = UE_list->UE_template[CC_id][UE_id].estimated_ul_buffer - UE_list->UE_template[CC_id][UE_id].scheduled_ul_bytes;
 
-      if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync == 1)
+    if (bytes_to_schedule < 0) bytes_to_schedule = 0;
+
+    if ( UE_id > last_ulsch_ue_id[CC_id] && ((ulsch_ue_select[CC_id].ue_num+ue_first_num[CC_id]) < ulsch_ue_max_num[CC_id]) ) {
+      if ( bytes_to_schedule > 0 ) {
+        first_ue_id[CC_id][ue_first_num[CC_id]]= UE_id;
+        first_ue_total[CC_id][ue_first_num[CC_id]] = bytes_to_schedule;
+        ue_first_num[CC_id]++;
         continue;
+      }
 
-      // UL DCI
-      HI_DCI0_req   = &eNB->HI_DCI0_req[CC_id][subframeP].hi_dci0_request_body;
-      if ( (ulsch_ue_select[CC_id].ue_num >= ulsch_ue_max_num[CC_id]) || (cc_id_flag[CC_id] == 1) ) {
-        cc_id_flag[CC_id] = 1;
-        HI_DCI0_req->number_of_dci = saved_ulsch_dci[CC_id];
-        ret = cc_id_end(cc_id_flag);
-        if ( ret == 0 ) {
-            continue;
-        }
-        if ( ret == 1 ) {
-            return;
-        }
+      if ( UE_list->UE_template[CC_id][UE_id].ul_SR > 0 ) {
+        first_ue_id[CC_id][ue_first_num[CC_id]]= UE_id;
+        first_ue_total[CC_id] [ue_first_num[CC_id]] = 0;
+        ue_first_num[CC_id]++;
+        continue;
       }
 
-      cc = &eNB->common_channels[CC_id];
-      //harq_pid
-      harq_pid = subframe2harqpid(cc,(frameP+(sched_subframeP<subframeP ? 1 : 0)),sched_subframeP);
-      //round
-      round = UE_list->UE_sched_ctrl[UE_id].round_UL[CC_id][harq_pid];
+      UE_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
 
-      if ( round > 0 ) {
-          hi_dci0_pdu   = &HI_DCI0_req->hi_dci0_pdu_list[HI_DCI0_req->number_of_dci+HI_DCI0_req->number_of_hi];
-          format_flag = 2;
-          if (CCE_allocation_infeasible(module_idP,CC_id,format_flag,subframeP,aggregation,rnti) == 1) {
-              cc_id_flag[CC_id] = 1;
-              continue;
-          } else {
-              hi_dci0_pdu->pdu_type                               = NFAPI_HI_DCI0_DCI_PDU_TYPE;
-              hi_dci0_pdu->dci_pdu.dci_pdu_rel8.rnti              = rnti;
-              hi_dci0_pdu->dci_pdu.dci_pdu_rel8.aggregation_level = aggregation;
-              HI_DCI0_req->number_of_dci++;
-
-              ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].ue_priority = SCH_UL_RETRANS;
-              ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].start_rb = eNB->UE_list.UE_template[CC_id][UE_id].first_rb_ul[harq_pid];
-              ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].nb_rb = eNB->UE_list.UE_template[CC_id][UE_id].nb_rb_ul[harq_pid];
-              ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].UE_id = UE_id;
-              ulsch_ue_select[CC_id].ue_num++;
-              continue;
-          }
+      if ( ((UE_sched_ctl->ul_inactivity_timer>20)&&(UE_sched_ctl->ul_scheduled==0))  ||
+           ((UE_sched_ctl->ul_inactivity_timer>10)&&(UE_sched_ctl->ul_scheduled==0)&&(mac_eNB_get_rrc_status(module_idP,UE_RNTI(module_idP,UE_id)) < RRC_CONNECTED))) {
+        first_ue_id[CC_id][ue_first_num[CC_id]]= UE_id;
+        first_ue_total[CC_id] [ue_first_num[CC_id]] = 0;
+        ue_first_num[CC_id]++;
+        continue;
       }
-      //
-      int bytes_to_schedule = UE_list->UE_template[CC_id][UE_id].estimated_ul_buffer - UE_list->UE_template[CC_id][UE_id].scheduled_ul_bytes;
-      if (bytes_to_schedule < 0) bytes_to_schedule = 0;
 
-      if ( UE_id > last_ulsch_ue_id[CC_id] && ((ulsch_ue_select[CC_id].ue_num+ue_first_num[CC_id]) < ulsch_ue_max_num[CC_id]) ) {
-        if ( bytes_to_schedule > 0 ) {
-          first_ue_id[CC_id][ue_first_num[CC_id]]= UE_id;
-          first_ue_total[CC_id][ue_first_num[CC_id]] = bytes_to_schedule;
-          ue_first_num[CC_id]++;
-          continue;
-        }
-        if ( UE_list->UE_template[CC_id][UE_id].ul_SR > 0 ) {
-          first_ue_id[CC_id][ue_first_num[CC_id]]= UE_id;
-          first_ue_total[CC_id] [ue_first_num[CC_id]] = 0;
-          ue_first_num[CC_id]++;
-          continue;
-        }
-        UE_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
-        if ( ((UE_sched_ctl->ul_inactivity_timer>20)&&(UE_sched_ctl->ul_scheduled==0))  ||
+      /*if ( (ulsch_ue_select[CC_id].ue_num+ul_inactivity_num[CC_id] ) < ulsch_ue_max_num[CC_id] ) {
+          UE_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
+          uint8_t ul_period = 0;
+          if (cc->tdd_Config) {
+            ul_period = 50;
+          } else {
+            ul_period = 20;
+          }
+          if ( ((UE_sched_ctl->ul_inactivity_timer>ul_period)&&(UE_sched_ctl->ul_scheduled==0))  ||
             ((UE_sched_ctl->ul_inactivity_timer>10)&&(UE_sched_ctl->ul_scheduled==0)&&(mac_eNB_get_rrc_status(module_idP,UE_RNTI(module_idP,UE_id)) < RRC_CONNECTED))) {
-          first_ue_id[CC_id][ue_first_num[CC_id]]= UE_id;
-          first_ue_total[CC_id] [ue_first_num[CC_id]] = 0;
-          ue_first_num[CC_id]++;
+          ul_inactivity_id[CC_id][ul_inactivity_num[CC_id]]= UE_id;
+          ul_inactivity_num[CC_id] ++;
           continue;
         }
-        /*if ( (ulsch_ue_select[CC_id].ue_num+ul_inactivity_num[CC_id] ) < ulsch_ue_max_num[CC_id] ) {
-            UE_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
-            uint8_t ul_period = 0;
-            if (cc->tdd_Config) {
-              ul_period = 50;
-            } else {
-              ul_period = 20;
-            }
-            if ( ((UE_sched_ctl->ul_inactivity_timer>ul_period)&&(UE_sched_ctl->ul_scheduled==0))  ||
-              ((UE_sched_ctl->ul_inactivity_timer>10)&&(UE_sched_ctl->ul_scheduled==0)&&(mac_eNB_get_rrc_status(module_idP,UE_RNTI(module_idP,UE_id)) < RRC_CONNECTED))) {
-            ul_inactivity_id[CC_id][ul_inactivity_num[CC_id]]= UE_id;
-            ul_inactivity_num[CC_id] ++;
-            continue;
-          }
-        }*/
-      }
-
+      }*/
+    }
   }
 
   for ( CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++ ) {
     HI_DCI0_req   = &eNB->HI_DCI0_req[CC_id][subframeP].hi_dci0_request_body;
+
     for ( int temp = 0; temp < ue_first_num[CC_id]; temp++ ) {
       if ( (ulsch_ue_select[CC_id].ue_num >= ulsch_ue_max_num[CC_id]) || (cc_id_flag[CC_id] == 1) ) {
         cc_id_flag[CC_id] = 1;
@@ -2097,113 +2102,121 @@ void ulsch_scheduler_pre_ue_select_fairRR(
       hi_dci0_pdu   = &HI_DCI0_req->hi_dci0_pdu_list[HI_DCI0_req->number_of_dci+HI_DCI0_req->number_of_hi];
       format_flag = 2;
       rnti = UE_RNTI(module_idP,first_ue_id[CC_id][temp]);
+
       if (CCE_allocation_infeasible(module_idP,CC_id,format_flag,subframeP,aggregation,rnti) == 1) {
-    	  cc_id_flag[CC_id] = 1;
-          break;
+        cc_id_flag[CC_id] = 1;
+        break;
       } else {
-          hi_dci0_pdu->pdu_type                               = NFAPI_HI_DCI0_DCI_PDU_TYPE;
-          hi_dci0_pdu->dci_pdu.dci_pdu_rel8.rnti              = rnti;
-          hi_dci0_pdu->dci_pdu.dci_pdu_rel8.aggregation_level = aggregation;
-          HI_DCI0_req->number_of_dci++;
-
-          ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].ue_priority = SCH_UL_FIRST;
-          ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].ul_total_buffer = first_ue_total[CC_id][temp];
-          ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].UE_id = first_ue_id[CC_id][temp];
-          ulsch_ue_select[CC_id].ue_num++;
+        hi_dci0_pdu->pdu_type                               = NFAPI_HI_DCI0_DCI_PDU_TYPE;
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.rnti              = rnti;
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.aggregation_level = aggregation;
+        HI_DCI0_req->number_of_dci++;
+        ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].ue_priority = SCH_UL_FIRST;
+        ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].ul_total_buffer = first_ue_total[CC_id][temp];
+        ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].UE_id = first_ue_id[CC_id][temp];
+        ulsch_ue_select[CC_id].ue_num++;
       }
     }
   }
 
   for ( UE_id = 0; UE_id < NUMBER_OF_UE_MAX; UE_id++ ) {
     if (UE_list->active[UE_id] == FALSE)
-        continue;
+      continue;
 
     rnti = UE_RNTI(module_idP,UE_id);
+
     if (rnti ==NOT_A_RNTI)
-        continue;
+      continue;
 
     CC_id = UE_PCCID(module_idP,UE_id);
 
     if (UE_id > last_ulsch_ue_id[CC_id])
-        continue;
+      continue;
 
     if (UE_list->UE_template[CC_id][UE_id].configured == FALSE)
-        continue;
+      continue;
 
     if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync == 1)
-        continue;
+      continue;
 
     if ( (ulsch_ue_select[CC_id].ue_num >= ulsch_ue_max_num[CC_id]) || (cc_id_flag[CC_id] == 1) ) {
-        cc_id_flag[CC_id] = 1;
-        HI_DCI0_req->number_of_dci = saved_ulsch_dci[CC_id];
-        ret = cc_id_end(cc_id_flag);
-        if ( ret == 0 ) {
-            continue;
-        }
-        if ( ret == 1 ) {
-            return;
-        }
+      cc_id_flag[CC_id] = 1;
+      HI_DCI0_req->number_of_dci = saved_ulsch_dci[CC_id];
+      ret = cc_id_end(cc_id_flag);
+
+      if ( ret == 0 ) {
+        continue;
+      }
+
+      if ( ret == 1 ) {
+        return;
+      }
     }
 
-    for(i = 0;i<ulsch_ue_select[CC_id].ue_num;i++){
-      if(ulsch_ue_select[CC_id].list[i].UE_id == UE_id){
-       break;
+    for(i = 0; i<ulsch_ue_select[CC_id].ue_num; i++) {
+      if(ulsch_ue_select[CC_id].list[i].UE_id == UE_id) {
+        break;
       }
     }
+
     if(i < ulsch_ue_select[CC_id].ue_num)
       continue;
 
     HI_DCI0_req   = &eNB->HI_DCI0_req[CC_id][subframeP].hi_dci0_request_body;
     //SR BSR
-        UE_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
-
+    UE_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
     int bytes_to_schedule = UE_list->UE_template[CC_id][UE_id].estimated_ul_buffer - UE_list->UE_template[CC_id][UE_id].scheduled_ul_bytes;
+
     if (bytes_to_schedule < 0) bytes_to_schedule = 0;
 
     if ( (bytes_to_schedule > 0) || (UE_list->UE_template[CC_id][UE_id].ul_SR > 0) ||
-          ((UE_sched_ctl->ul_inactivity_timer>20)&&(UE_sched_ctl->ul_scheduled==0))  ||
-          ((UE_sched_ctl->ul_inactivity_timer>10)&&(UE_sched_ctl->ul_scheduled==0)&&(mac_eNB_get_rrc_status(module_idP,UE_RNTI(module_idP,UE_id)) < RRC_CONNECTED)) ){
-        hi_dci0_pdu   = &HI_DCI0_req->hi_dci0_pdu_list[HI_DCI0_req->number_of_dci+HI_DCI0_req->number_of_hi];
-        format_flag = 2;
-        if (CCE_allocation_infeasible(module_idP,CC_id,format_flag,subframeP,aggregation,rnti) == 1) {
-            cc_id_flag[CC_id] = 1;
-            continue;
-        } else {
-              hi_dci0_pdu->pdu_type                               = NFAPI_HI_DCI0_DCI_PDU_TYPE;
-              hi_dci0_pdu->dci_pdu.dci_pdu_rel8.rnti              = rnti;
-              hi_dci0_pdu->dci_pdu.dci_pdu_rel8.aggregation_level = aggregation;
-              HI_DCI0_req->number_of_dci++;
-
-              ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].ue_priority = SCH_UL_FIRST;
-              if(bytes_to_schedule > 0)
-                  ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].ul_total_buffer = bytes_to_schedule;
-              else if(UE_list->UE_template[CC_id][UE_id].ul_SR > 0)
-                  ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].ul_total_buffer = 0;
-              ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].UE_id = UE_id;
-              ulsch_ue_select[CC_id].ue_num++;
-              continue;
-          }
+         ((UE_sched_ctl->ul_inactivity_timer>20)&&(UE_sched_ctl->ul_scheduled==0))  ||
+         ((UE_sched_ctl->ul_inactivity_timer>10)&&(UE_sched_ctl->ul_scheduled==0)&&(mac_eNB_get_rrc_status(module_idP,UE_RNTI(module_idP,UE_id)) < RRC_CONNECTED)) ) {
+      hi_dci0_pdu   = &HI_DCI0_req->hi_dci0_pdu_list[HI_DCI0_req->number_of_dci+HI_DCI0_req->number_of_hi];
+      format_flag = 2;
+
+      if (CCE_allocation_infeasible(module_idP,CC_id,format_flag,subframeP,aggregation,rnti) == 1) {
+        cc_id_flag[CC_id] = 1;
+        continue;
+      } else {
+        hi_dci0_pdu->pdu_type                               = NFAPI_HI_DCI0_DCI_PDU_TYPE;
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.rnti              = rnti;
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.aggregation_level = aggregation;
+        HI_DCI0_req->number_of_dci++;
+        ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].ue_priority = SCH_UL_FIRST;
+
+        if(bytes_to_schedule > 0)
+          ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].ul_total_buffer = bytes_to_schedule;
+        else if(UE_list->UE_template[CC_id][UE_id].ul_SR > 0)
+          ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].ul_total_buffer = 0;
+
+        ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].UE_id = UE_id;
+        ulsch_ue_select[CC_id].ue_num++;
+        continue;
+      }
     }
+
     //inactivity UE
-/*    if ( (ulsch_ue_select[CC_id].ue_num+ul_inactivity_num[CC_id]) < ulsch_ue_max_num[CC_id] ) {
-        UE_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
-        uint8_t ul_period = 0;
-        if (cc->tdd_Config) {
-          ul_period = 50;
-        } else {
-          ul_period = 20;
-        }
-        if ( ((UE_sched_ctl->ul_inactivity_timer>ul_period)&&(UE_sched_ctl->ul_scheduled==0))  ||
-            ((UE_sched_ctl->ul_inactivity_timer>10)&&(UE_sched_ctl->ul_scheduled==0)&&(mac_eNB_get_rrc_status(module_idP,UE_RNTI(module_idP,UE_id)) < RRC_CONNECTED))) {
-          ul_inactivity_id[CC_id][ul_inactivity_num[CC_id]]= UE_id;
-          ul_inactivity_num[CC_id]++;
-          continue;
-        }
-    }*/
+    /*    if ( (ulsch_ue_select[CC_id].ue_num+ul_inactivity_num[CC_id]) < ulsch_ue_max_num[CC_id] ) {
+            UE_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
+            uint8_t ul_period = 0;
+            if (cc->tdd_Config) {
+              ul_period = 50;
+            } else {
+              ul_period = 20;
+            }
+            if ( ((UE_sched_ctl->ul_inactivity_timer>ul_period)&&(UE_sched_ctl->ul_scheduled==0))  ||
+                ((UE_sched_ctl->ul_inactivity_timer>10)&&(UE_sched_ctl->ul_scheduled==0)&&(mac_eNB_get_rrc_status(module_idP,UE_RNTI(module_idP,UE_id)) < RRC_CONNECTED))) {
+              ul_inactivity_id[CC_id][ul_inactivity_num[CC_id]]= UE_id;
+              ul_inactivity_num[CC_id]++;
+              continue;
+            }
+        }*/
   }
 
   for ( CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++ ) {
     HI_DCI0_req   = &eNB->HI_DCI0_req[CC_id][subframeP].hi_dci0_request_body;
+
     for ( int temp = 0; temp < ul_inactivity_num[CC_id]; temp++ ) {
       if ( (ulsch_ue_select[CC_id].ue_num >= ulsch_ue_max_num[CC_id]) || (cc_id_flag[CC_id] == 1) ) {
         HI_DCI0_req   = &eNB->HI_DCI0_req[CC_id][subframeP].hi_dci0_request_body;
@@ -2214,43 +2227,45 @@ void ulsch_scheduler_pre_ue_select_fairRR(
       hi_dci0_pdu   = &HI_DCI0_req->hi_dci0_pdu_list[HI_DCI0_req->number_of_dci+HI_DCI0_req->number_of_hi];
       format_flag = 2;
       rnti = UE_RNTI(module_idP,ul_inactivity_id[CC_id][temp]);
+
       if (CCE_allocation_infeasible(module_idP,CC_id,format_flag,subframeP,aggregation,rnti) == 1) {
-          cc_id_flag[CC_id] = 1;
-          continue;
+        cc_id_flag[CC_id] = 1;
+        continue;
       } else {
-          hi_dci0_pdu->pdu_type                               = NFAPI_HI_DCI0_DCI_PDU_TYPE;
-          hi_dci0_pdu->dci_pdu.dci_pdu_rel8.rnti              = rnti;
-          hi_dci0_pdu->dci_pdu.dci_pdu_rel8.aggregation_level = aggregation;
-          HI_DCI0_req->number_of_dci++;
-
-          ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].ue_priority = SCH_UL_INACTIVE;
-          ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].ul_total_buffer = 0;
-          ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].UE_id = ul_inactivity_id[CC_id][temp];
-          ulsch_ue_select[CC_id].ue_num++;
+        hi_dci0_pdu->pdu_type                               = NFAPI_HI_DCI0_DCI_PDU_TYPE;
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.rnti              = rnti;
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.aggregation_level = aggregation;
+        HI_DCI0_req->number_of_dci++;
+        ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].ue_priority = SCH_UL_INACTIVE;
+        ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].ul_total_buffer = 0;
+        ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].UE_id = ul_inactivity_id[CC_id][temp];
+        ulsch_ue_select[CC_id].ue_num++;
       }
     }
+
     HI_DCI0_req->number_of_dci = saved_ulsch_dci[CC_id];
   }
+
   return;
 }
 
-uint8_t find_rb_table_index(uint8_t average_rbs)
-{
+uint8_t find_rb_table_index(uint8_t average_rbs) {
   int i;
+
   for ( i = 0; i < 34; i++ ) {
     if ( rb_table[i] > average_rbs ) {
       return (i-1);
     }
   }
+
   return i;
 }
 
 void ulsch_scheduler_pre_processor_fairRR(module_id_t module_idP,
-                                   frame_t frameP,
-                                   sub_frame_t subframeP,
-                                   sub_frame_t sched_subframeP,
-                                   ULSCH_UE_SELECT ulsch_ue_select[MAX_NUM_CCs])
-{
+    frame_t frameP,
+    sub_frame_t subframeP,
+    sub_frame_t sched_subframeP,
+    ULSCH_UE_SELECT ulsch_ue_select[MAX_NUM_CCs]) {
   int                CC_id,ulsch_ue_num;
   eNB_MAC_INST       *eNB = RC.mac[module_idP];
   UE_list_t          *UE_list= &eNB->UE_list;
@@ -2275,26 +2290,27 @@ void ulsch_scheduler_pre_processor_fairRR(module_id_t module_idP,
   for ( CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++ ) {
     cc = &RC.mac[module_idP]->common_channels[CC_id];
     frame_parms = &(RC.eNB[module_idP][CC_id]->frame_parms);
+
     if (cc->tdd_Config) { //TDD
       if (frame_parms->N_RB_UL == 25) {
-          num_pucch_rb = 1;
+        num_pucch_rb = 1;
       } else if (frame_parms->N_RB_UL == 50) {
-          num_pucch_rb = 2;
+        num_pucch_rb = 2;
       } else {
-          num_pucch_rb = 3;
+        num_pucch_rb = 3;
       }
     } else {//FDD
       if (frame_parms->N_RB_UL == 25) {
-          num_pucch_rb = 1;
+        num_pucch_rb = 1;
       } else {
-          num_pucch_rb = 2;
+        num_pucch_rb = 2;
       }
     }
 
     first_rb[CC_id] = num_pucch_rb;
     ue_num_temp       = ulsch_ue_select[CC_id].ue_num;
-    for ( ulsch_ue_num = 0; ulsch_ue_num < ulsch_ue_select[CC_id].ue_num; ulsch_ue_num++ ) {
 
+    for ( ulsch_ue_num = 0; ulsch_ue_num < ulsch_ue_select[CC_id].ue_num; ulsch_ue_num++ ) {
       UE_id = ulsch_ue_select[CC_id].list[ulsch_ue_num].UE_id;
 
       if (ulsch_ue_select[CC_id].list[ulsch_ue_num].ue_priority == SCH_UL_MSG3) {
@@ -2309,52 +2325,59 @@ void ulsch_scheduler_pre_processor_fairRR(module_id_t module_idP,
         continue;
       }
 
-
       if (first_rb[CC_id] >= frame_parms->N_RB_UL-num_pucch_rb ) {
-         LOG_W(MAC,"[eNB %d] frame %d subframe %d, UE %d/%x CC %d: dropping, not enough RBs\n",
-               module_idP,frameP,subframeP,UE_id,UE_RNTI(CC_id,UE_id),CC_id);
-         break;
+        LOG_W(MAC,"[eNB %d] frame %d subframe %d, UE %d/%x CC %d: dropping, not enough RBs\n",
+              module_idP,frameP,subframeP,UE_id,UE_RNTI(CC_id,UE_id),CC_id);
+        break;
       }
-      total_rbs = frame_parms->N_RB_UL-num_pucch_rb-first_rb[CC_id];
 
+      total_rbs = frame_parms->N_RB_UL-num_pucch_rb-first_rb[CC_id];
       average_rbs = (int)round((double)total_rbs/(double)ue_num_temp);
+
       if ( average_rbs < 3 ) {
         ue_num_temp--;
         ulsch_ue_num--;
         ulsch_ue_select[CC_id].ue_num--;
         continue;
       }
+
       if ( ulsch_ue_select[CC_id].list[ulsch_ue_num].ue_priority == SCH_UL_RETRANS ) {
         if ( ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb <= average_rbs ) {
-            // assigne RBS(nb_rb)
-            ulsch_ue_select[CC_id].list[ulsch_ue_num].start_rb = first_rb[CC_id];
-            first_rb[CC_id] = first_rb[CC_id] + ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb;
+          // assigne RBS(nb_rb)
+          ulsch_ue_select[CC_id].list[ulsch_ue_num].start_rb = first_rb[CC_id];
+          first_rb[CC_id] = first_rb[CC_id] + ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb;
         }
+
         if ( ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb > average_rbs ) {
           if ( ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb <= total_rbs ) {
-              // assigne RBS(average_rbs)
-              ulsch_ue_select[CC_id].list[ulsch_ue_num].start_rb = first_rb[CC_id];
-              first_rb[CC_id] = first_rb[CC_id] + ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb;
+            // assigne RBS(average_rbs)
+            ulsch_ue_select[CC_id].list[ulsch_ue_num].start_rb = first_rb[CC_id];
+            first_rb[CC_id] = first_rb[CC_id] + ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb;
           } else {
-              // assigne RBS(remain rbs)
-              ulsch_ue_select[CC_id].list[ulsch_ue_num].start_rb = first_rb[CC_id];
-              rb_table_index = 2;
-              while(rb_table[rb_table_index] <= total_rbs){
-                rb_table_index++;
-              }
-              ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb = rb_table[rb_table_index-1];
-              first_rb[CC_id] = first_rb[CC_id] + rb_table[rb_table_index-1];
+            // assigne RBS(remain rbs)
+            ulsch_ue_select[CC_id].list[ulsch_ue_num].start_rb = first_rb[CC_id];
+            rb_table_index = 2;
+
+            while(rb_table[rb_table_index] <= total_rbs) {
+              rb_table_index++;
+            }
+
+            ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb = rb_table[rb_table_index-1];
+            first_rb[CC_id] = first_rb[CC_id] + rb_table[rb_table_index-1];
           }
         }
-      }else{
+      } else {
         UE_template = &UE_list->UE_template[CC_id][UE_id];
+
         if ( UE_list->UE_sched_ctrl[UE_id].phr_received == 1 ) {
           mcs = 20;
         } else {
           mcs = 10;
         }
+
         if ( ulsch_ue_select[CC_id].list[ulsch_ue_num].ue_priority  == SCH_UL_FIRST ) {
           int bytes_to_schedule = UE_template->estimated_ul_buffer - UE_template->scheduled_ul_bytes;
+
           if (bytes_to_schedule < 0) bytes_to_schedule = 0;
 
           if ( ulsch_ue_select[CC_id].list[ulsch_ue_num].ul_total_buffer > 0 ) {
@@ -2369,7 +2392,7 @@ void ulsch_scheduler_pre_processor_fairRR(module_id_t module_idP,
             }
 
             while ( (tbs < bytes_to_schedule) && (rb_table[rb_table_index]<(frame_parms->N_RB_UL-num_pucch_rb-first_rb[CC_id])) &&
-                   ((UE_template->phr_info - tx_power) > 0) && (rb_table_index < 32 )) {
+                    ((UE_template->phr_info - tx_power) > 0) && (rb_table_index < 32 )) {
               rb_table_index++;
               tbs = get_TBS_UL(mcs,rb_table[rb_table_index])<<3;
               tx_power= estimate_ue_tx_power(tbs,rb_table[rb_table_index],0,frame_parms->Ncp,0);
@@ -2378,6 +2401,7 @@ void ulsch_scheduler_pre_processor_fairRR(module_id_t module_idP,
             if ( rb_table[rb_table_index]<3 ) {
               rb_table_index=2;
             }
+
             if ( rb_table[rb_table_index] <= average_rbs ) {
               // assigne RBS( nb_rb)
               first_rb[CC_id] = first_rb[CC_id] + rb_table[rb_table_index];
@@ -2385,27 +2409,30 @@ void ulsch_scheduler_pre_processor_fairRR(module_id_t module_idP,
               UE_list->UE_template[CC_id][UE_id].pre_allocated_rb_table_index_ul = rb_table_index;
               UE_list->UE_template[CC_id][UE_id].pre_assigned_mcs_ul = mcs;
             }
+
             if ( rb_table[rb_table_index] > average_rbs ) {
               // assigne RBS(average_rbs)
               rb_table_index = find_rb_table_index(average_rbs);
-              if (rb_table_index>=34){
-                  LOG_W(MAC,"[eNB %d] frame %d subframe %d, UE %d/%x CC %d: average RBs %d > 100\n",
-                         module_idP,frameP,subframeP,UE_id,UE_RNTI(CC_id,UE_id),CC_id,average_rbs);
-                  break;
+
+              if (rb_table_index>=34) {
+                LOG_W(MAC,"[eNB %d] frame %d subframe %d, UE %d/%x CC %d: average RBs %d > 100\n",
+                      module_idP,frameP,subframeP,UE_id,UE_RNTI(CC_id,UE_id),CC_id,average_rbs);
+                break;
               }
+
               first_rb[CC_id] = first_rb[CC_id] + rb_table[rb_table_index];
               UE_list->UE_template[CC_id][UE_id].pre_allocated_nb_rb_ul[0] = rb_table[rb_table_index];
               UE_list->UE_template[CC_id][UE_id].pre_allocated_rb_table_index_ul = rb_table_index;
               UE_list->UE_template[CC_id][UE_id].pre_assigned_mcs_ul = mcs;
             }
-          }else {
+          } else {
             // assigne RBS( 3 RBs)
             first_rb[CC_id] = first_rb[CC_id] + 3;
             UE_list->UE_template[CC_id][UE_id].pre_allocated_nb_rb_ul[0] = 3;
             UE_list->UE_template[CC_id][UE_id].pre_allocated_rb_table_index_ul = 2;
             UE_list->UE_template[CC_id][UE_id].pre_assigned_mcs_ul = 10;
           }
-        }else if ( ulsch_ue_select[CC_id].list[ulsch_ue_num].ue_priority  == SCH_UL_INACTIVE ) {
+        } else if ( ulsch_ue_select[CC_id].list[ulsch_ue_num].ue_priority  == SCH_UL_INACTIVE ) {
           // assigne RBS( 3 RBs)
           first_rb[CC_id] = first_rb[CC_id] + 3;
           UE_list->UE_template[CC_id][UE_id].pre_allocated_nb_rb_ul[0] = 3;
@@ -2413,6 +2440,7 @@ void ulsch_scheduler_pre_processor_fairRR(module_id_t module_idP,
           UE_list->UE_template[CC_id][UE_id].pre_assigned_mcs_ul = 10;
         }
       }
+
       ue_num_temp--;
     }
   }
@@ -2421,105 +2449,126 @@ void ulsch_scheduler_pre_processor_fairRR(module_id_t module_idP,
 
 void
 schedule_ulsch_fairRR(module_id_t module_idP, frame_t frameP,
-	       sub_frame_t subframeP)
-{
+                      sub_frame_t subframeP) {
   uint16_t i;
   int CC_id;
   eNB_MAC_INST *mac = RC.mac[module_idP];
   COMMON_channels_t *cc;
   int sched_frame=frameP;
-
   start_meas(&mac->schedule_ulsch);
-
   int sched_subframe = (subframeP+4)%10;
-
   cc = &mac->common_channels[0];
   int tdd_sfa;
+
   // for TDD: check subframes where we have to act and return if nothing should be done now
   if (cc->tdd_Config) {
     tdd_sfa = cc->tdd_Config->subframeAssignment;
+
     switch (subframeP) {
-    case 0:
-      if ((tdd_sfa == 0)||
-          (tdd_sfa == 3)) sched_subframe = 4;
-      else if (tdd_sfa==6) sched_subframe = 7;
-      else return;
-      break;
-    case 1:
-      if ((tdd_sfa==0)||
-          (tdd_sfa==1)) sched_subframe = 7;
-      else if (tdd_sfa==6) sched_subframe = 8;
-      else return;
-      break;
-    case 2: // Don't schedule UL in subframe 2 for TDD
-      return;
-    case 3:
-      if (tdd_sfa==2) sched_subframe = 7;
-      else return;
-      break;
-    case 4:
-      if (tdd_sfa==1) sched_subframe = 8;
-      else return;
-      break;
-    case 5:
-      if (tdd_sfa==0)      sched_subframe = 9;
-      else if (tdd_sfa==6) sched_subframe = 2;
-      else return;
-      break;
-    case 6:
-      if (tdd_sfa==0 || tdd_sfa==1)      sched_subframe = 2;
-      else if (tdd_sfa==6) sched_subframe = 3;
-      else return;
-      break;
-    case 7:
-      return;
-    case 8:
-      if ((tdd_sfa>=2) && (tdd_sfa<=5)) sched_subframe=2;
-      else return;
-      break;
-    case 9:
-      if ((tdd_sfa==1) || (tdd_sfa==3) || (tdd_sfa==4)) sched_subframe=3;
-      else if (tdd_sfa==6) sched_subframe=4;
-      else return;
-      break;
+      case 0:
+        if ((tdd_sfa == 0)||
+            (tdd_sfa == 3)) sched_subframe = 4;
+        else if (tdd_sfa==6) sched_subframe = 7;
+        else return;
+
+        break;
+
+      case 1:
+        if ((tdd_sfa==0)||
+            (tdd_sfa==1)) sched_subframe = 7;
+        else if (tdd_sfa==6) sched_subframe = 8;
+        else return;
+
+        break;
+
+      case 2: // Don't schedule UL in subframe 2 for TDD
+        return;
+
+      case 3:
+        if (tdd_sfa==2) sched_subframe = 7;
+        else return;
+
+        break;
+
+      case 4:
+        if (tdd_sfa==1) sched_subframe = 8;
+        else return;
+
+        break;
+
+      case 5:
+        if (tdd_sfa==0)      sched_subframe = 9;
+        else if (tdd_sfa==6) sched_subframe = 2;
+        else return;
+
+        break;
+
+      case 6:
+        if (tdd_sfa==0 || tdd_sfa==1)      sched_subframe = 2;
+        else if (tdd_sfa==6) sched_subframe = 3;
+        else return;
+
+        break;
+
+      case 7:
+        return;
+
+      case 8:
+        if ((tdd_sfa>=2) && (tdd_sfa<=5)) sched_subframe=2;
+        else return;
+
+        break;
+
+      case 9:
+        if ((tdd_sfa==1) || (tdd_sfa==3) || (tdd_sfa==4)) sched_subframe=3;
+        else if (tdd_sfa==6) sched_subframe=4;
+        else return;
+
+        break;
     }
   }
+
   if (sched_subframe < subframeP) sched_frame++;
+
   ULSCH_UE_SELECT ulsch_ue_select[MAX_NUM_CCs];
   memset(ulsch_ue_select, 0, sizeof(ulsch_ue_select));
-
   LTE_DL_FRAME_PARMS *frame_parms ;
 
   for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
     cc = &mac->common_channels[CC_id];
     frame_parms= &RC.eNB[module_idP][CC_id]->frame_parms;
+
     // output of scheduling, the UE numbers in RBs, where it is in the code???
     // check if RA (Msg3) is active in this subframeP, if so skip the PRBs used for Msg3
     // Msg3 is using 1 PRB so we need to increase first_rb accordingly
     // not sure about the break (can there be more than 1 active RA procedure?)
     for (i=0; i<NB_RA_PROC_MAX; i++) {
-      if ((cc->ra[i].state == WAITMSG3) &&(cc->ra[i].Msg3_subframe == sched_subframe)) {  
+      if ((cc->ra[i].state == WAITMSG3) &&(cc->ra[i].Msg3_subframe == sched_subframe)) {
         ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].ue_priority = SCH_UL_MSG3;
+
         if (cc->tdd_Config == NULL) {
-            if(frame_parms->N_RB_UL == 25){
-              ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].start_rb = 1;
-            }else{
-              ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].start_rb = 2;
-            }
+          if(frame_parms->N_RB_UL == 25) {
+            ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].start_rb = 1;
+          } else {
+            ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].start_rb = 2;
+          }
         } else {
-            switch(frame_parms->N_RB_UL){
+          switch(frame_parms->N_RB_UL) {
             case 25:
             default:
               ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].start_rb = 1;
               break;
+
             case 50:
               ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].start_rb = 2;
               break;
+
             case 100:
               ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].start_rb = 3;
               break;
-            }
+          }
         }
+
         ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].nb_rb = 1;
         ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].UE_id = -1;
         ulsch_ue_select[CC_id].ue_num++;
@@ -2531,11 +2580,11 @@ schedule_ulsch_fairRR(module_id_t module_idP, frame_t frameP,
     if (is_prach_subframe(frame_parms,sched_frame,sched_subframe)==1) {
       ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].ue_priority = SCH_UL_PRACH;
       ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].start_rb = get_prach_prb_offset(
-    		                                                                 frame_parms,
-    		                                                                 frame_parms->prach_config_common.prach_ConfigInfo.prach_ConfigIndex,
-    		                                                                 frame_parms->prach_config_common.prach_ConfigInfo.prach_FreqOffset,
-    		                                                                 0,//tdd_mapindex
-    		                                                                 frameP); //Nf
+            frame_parms,
+            frame_parms->prach_config_common.prach_ConfigInfo.prach_ConfigIndex,
+            frame_parms->prach_config_common.prach_ConfigInfo.prach_FreqOffset,
+            0,//tdd_mapindex
+            frameP); //Nf --> shouldn't it be sched_frame ???
       ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].nb_rb = 6;
       ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].UE_id = -1;
       ulsch_ue_select[CC_id].ue_num++;
@@ -2547,11 +2596,10 @@ schedule_ulsch_fairRR(module_id_t module_idP, frame_t frameP,
 }
 
 void schedule_ulsch_rnti_fairRR(module_id_t   module_idP,
-                         frame_t       frameP,
-                         sub_frame_t   subframeP,
-                         unsigned char sched_subframeP,
-                         ULSCH_UE_SELECT  ulsch_ue_select[MAX_NUM_CCs])
-{
+                                frame_t       frameP,
+                                sub_frame_t   subframeP,
+                                unsigned char sched_subframeP,
+                                ULSCH_UE_SELECT  ulsch_ue_select[MAX_NUM_CCs]) {
   int16_t           UE_id;
   uint8_t           aggregation    = 2;
   uint16_t          first_rb[MAX_NUM_CCs];
@@ -2560,7 +2608,7 @@ void schedule_ulsch_rnti_fairRR(module_id_t   module_idP,
   uint8_t           round          = 0;
   uint8_t           harq_pid       = 0;
   uint8_t           status         = 0;
-    uint8_t           rb_table_index = -1;
+  uint8_t           rb_table_index = -1;
   uint32_t          cqi_req,cshift,ndi,tpc;
   int32_t           normalized_rx_power;
   int32_t           target_rx_power=-90;
@@ -2576,99 +2624,102 @@ void schedule_ulsch_rnti_fairRR(module_id_t   module_idP,
   int               rvidx_tab[4] = {0,2,3,1};
   uint16_t          ul_req_index;
   uint8_t           dlsch_flag;
+
   if (sched_subframeP < subframeP) sched_frame++;
 
   nfapi_hi_dci0_request_body_t   *hi_dci0_req;
   nfapi_hi_dci0_request_pdu_t    *hi_dci0_pdu;
-
   nfapi_ul_config_request_body_t *ul_req_tmp;
   nfapi_ul_config_ulsch_harq_information *ulsch_harq_information;
   LOG_D(MAC,"entering ulsch preprocesor\n");
   ulsch_scheduler_pre_processor_fairRR(module_idP,
-                                frameP,
-                                subframeP,
-                                sched_subframeP,
-                                ulsch_ue_select);
-
+                                       frameP,
+                                       subframeP,
+                                       sched_subframeP,
+                                       ulsch_ue_select);
   LOG_D(MAC,"exiting ulsch preprocesor\n");
 
-
-
   // loop over all active UEs
   for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
-      hi_dci0_req = &eNB->HI_DCI0_req[CC_id][subframeP].hi_dci0_request_body;
-      eNB->HI_DCI0_req[CC_id][subframeP].sfn_sf = (frameP<<4)+subframeP;
-      ul_req_tmp = &eNB->UL_req_tmp[CC_id][sched_subframeP].ul_config_request_body;
-      nfapi_ul_config_request_t *ul_req  = &eNB->UL_req_tmp[CC_id][sched_subframeP];
-
+    hi_dci0_req = &eNB->HI_DCI0_req[CC_id][subframeP].hi_dci0_request_body;
+    eNB->HI_DCI0_req[CC_id][subframeP].sfn_sf = (frameP<<4)+subframeP;
+    ul_req_tmp = &eNB->UL_req_tmp[CC_id][sched_subframeP].ul_config_request_body;
+    nfapi_ul_config_request_t *ul_req  = &eNB->UL_req_tmp[CC_id][sched_subframeP];
     ULSCH_first_end = 0;
     cc  = &eNB->common_channels[CC_id];
     // This is the actual CC_id in the list
     N_RB_UL      = to_prb(cc->mib->message.dl_Bandwidth);
+
     //leave out first RB for PUCCH
     if (cc->tdd_Config == NULL) {
-        if(N_RB_UL == 25){
-          first_rb[CC_id] = 1;
-        }else{
-          first_rb[CC_id] = 2;
-        }
-    }else {
-        switch(N_RB_UL){
+      if(N_RB_UL == 25) {
+        first_rb[CC_id] = 1;
+      } else {
+        first_rb[CC_id] = 2;
+      }
+    } else {
+      switch(N_RB_UL) {
         case 25:
         default:
-            first_rb[CC_id] = 1;
+          first_rb[CC_id] = 1;
           break;
+
         case 50:
-            first_rb[CC_id] = 2;
+          first_rb[CC_id] = 2;
           break;
+
         case 100:
-            first_rb[CC_id] = 3;
+          first_rb[CC_id] = 3;
           break;
-        }
+      }
     }
+
     for ( ulsch_ue_num = 0; ulsch_ue_num < ulsch_ue_select[CC_id].ue_num; ulsch_ue_num++ ) {
       UE_id = ulsch_ue_select[CC_id].list[ulsch_ue_num].UE_id;
+
       /* be sure that there are some free RBs */
-      if (cc->tdd_Config == NULL){
-          if(N_RB_UL == 25){
-            if (first_rb[CC_id] >= N_RB_UL-1) {
-              LOG_W(MAC,"[eNB %d] frame %d subframe %d, UE %d/%x CC %d: dropping, not enough RBs\n",
-                     module_idP,frameP,subframeP,UE_id,rnti,CC_id);
-              break;
-            }
-          }else{
-              if (first_rb[CC_id] >= N_RB_UL-2) {
-                LOG_W(MAC,"[eNB %d] frame %d subframe %d, UE %d/%x CC %d: dropping, not enough RBs\n",
-                       module_idP,frameP,subframeP,UE_id,rnti,CC_id);
-                break;
-              }
+      if (cc->tdd_Config == NULL) {
+        if(N_RB_UL == 25) {
+          if (first_rb[CC_id] >= N_RB_UL-1) {
+            LOG_W(MAC,"[eNB %d] frame %d subframe %d, UE %d/%x CC %d: dropping, not enough RBs\n",
+                  module_idP,frameP,subframeP,UE_id,rnti,CC_id);
+            break;
+          }
+        } else {
+          if (first_rb[CC_id] >= N_RB_UL-2) {
+            LOG_W(MAC,"[eNB %d] frame %d subframe %d, UE %d/%x CC %d: dropping, not enough RBs\n",
+                  module_idP,frameP,subframeP,UE_id,rnti,CC_id);
+            break;
           }
+        }
       } else {
-          if(N_RB_UL == 25){
-            if (first_rb[CC_id] >= N_RB_UL-1) {
-              LOG_W(MAC,"[eNB %d] frame %d subframe %d, UE %d/%x CC %d N_RB_UL %d first_rb %d: dropping, not enough RBs\n",
-                       module_idP,frameP,subframeP,UE_id,rnti,CC_id, N_RB_UL, first_rb[CC_id]);
-              break;
-            }
-          }else if(N_RB_UL == 50){
-              if (first_rb[CC_id] >= N_RB_UL-2) {
-                LOG_W(MAC,"[eNB %d] frame %d subframe %d, UE %d/%x CC %d N_RB_UL %d first_rb %d: dropping, not enough RBs\n",
-                         module_idP,frameP,subframeP,UE_id,rnti,CC_id, N_RB_UL, first_rb[CC_id]);
-                break;
-              }
-          }else if(N_RB_UL == 100){
-              if (first_rb[CC_id] >= N_RB_UL-3) {
-                LOG_W(MAC,"[eNB %d] frame %d subframe %d, UE %d/%x CC %d N_RB_UL %d first_rb %d: dropping, not enough RBs\n",
-                       module_idP,frameP,subframeP,UE_id,rnti,CC_id, N_RB_UL, first_rb[CC_id]);
-                break;
-              }
+        if(N_RB_UL == 25) {
+          if (first_rb[CC_id] >= N_RB_UL-1) {
+            LOG_W(MAC,"[eNB %d] frame %d subframe %d, UE %d/%x CC %d N_RB_UL %d first_rb %d: dropping, not enough RBs\n",
+                  module_idP,frameP,subframeP,UE_id,rnti,CC_id, N_RB_UL, first_rb[CC_id]);
+            break;
           }
+        } else if(N_RB_UL == 50) {
+          if (first_rb[CC_id] >= N_RB_UL-2) {
+            LOG_W(MAC,"[eNB %d] frame %d subframe %d, UE %d/%x CC %d N_RB_UL %d first_rb %d: dropping, not enough RBs\n",
+                  module_idP,frameP,subframeP,UE_id,rnti,CC_id, N_RB_UL, first_rb[CC_id]);
+            break;
+          }
+        } else if(N_RB_UL == 100) {
+          if (first_rb[CC_id] >= N_RB_UL-3) {
+            LOG_W(MAC,"[eNB %d] frame %d subframe %d, UE %d/%x CC %d N_RB_UL %d first_rb %d: dropping, not enough RBs\n",
+                  module_idP,frameP,subframeP,UE_id,rnti,CC_id, N_RB_UL, first_rb[CC_id]);
+            break;
+          }
+        }
       }
+
       //MSG3
       if (ulsch_ue_select[CC_id].list[ulsch_ue_num].ue_priority == SCH_UL_MSG3) {
         first_rb[CC_id] ++;
         continue;
       }
+
       //PRACH
       if (ulsch_ue_select[CC_id].list[ulsch_ue_num].ue_priority == SCH_UL_PRACH) {
         first_rb[CC_id] = ulsch_ue_select[CC_id].list[ulsch_ue_num].start_rb+ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb;
@@ -2681,376 +2732,389 @@ void schedule_ulsch_rnti_fairRR(module_id_t   module_idP,
       rnti = UE_RNTI(CC_id,UE_id);
       LOG_D(MAC,"[eNB %d] frame %d subframe %d,Checking PUSCH %d for UE %d/%x CC %d : aggregation level %d, N_RB_UL %d\n",
             module_idP,frameP,subframeP,harq_pid,UE_id,rnti,CC_id, aggregation,N_RB_UL);
-
       int bytes_to_schedule = UE_template->estimated_ul_buffer - UE_template->scheduled_ul_bytes;
+
       if (bytes_to_schedule < 0) bytes_to_schedule = 0;
 
       RC.eNB[module_idP][CC_id]->pusch_stats_BO[UE_id][(frameP*10)+subframeP] = bytes_to_schedule;
       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]);
-
       status = mac_eNB_get_rrc_status(module_idP,rnti);
+
       if (status < RRC_CONNECTED)
         cqi_req = 0;
       else if (UE_sched_ctrl->cqi_req_timer>30) {
-    	  cqi_req = 1;
-		   // To be safe , do not ask CQI in special SFs:36.213/7.2.3 CQI definition
-			if (cc->tdd_Config) {
-			  switch (cc->tdd_Config->subframeAssignment) {
-				  case 1:
-					if( subframeP == 1 || subframeP == 6 ) cqi_req=0;
-					break;
-				  case 3:
-					if( subframeP == 1 ) cqi_req=0;
-					break;
-				  default:
-					LOG_E(MAC," TDD config not supported\n");
-					break;
-			  }
-			}
-			if(cqi_req == 1){
-				UE_sched_ctrl->cqi_req_timer=0;
-				UE_sched_ctrl->cqi_req_flag |= 1 << sched_subframeP;
-			}
-      }
-      else
+        cqi_req = 1;
+
+        // To be safe , do not ask CQI in special SFs:36.213/7.2.3 CQI definition
+        if (cc->tdd_Config) {
+          switch (cc->tdd_Config->subframeAssignment) {
+            case 1:
+              if( subframeP == 1 || subframeP == 6 ) cqi_req=0;
+
+              break;
+
+            case 3:
+              if( subframeP == 1 ) cqi_req=0;
+
+              break;
+
+            default:
+              LOG_E(MAC," TDD config not supported\n");
+              break;
+          }
+        }
+
+        if(cqi_req == 1) {
+          UE_sched_ctrl->cqi_req_timer=0;
+          UE_sched_ctrl->cqi_req_flag |= 1 << sched_subframeP;
+        }
+      } else
         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 = (5*UE_sched_ctrl->pusch_snr[CC_id]-640)/10+30; //(+eNB->measurements.n0_power_dB[0])
       target_rx_power= eNB->puSch10xSnr/10 + 30; //(+eNB->measurements.n0_power_dB[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
-            tpc_accumulated--;
-          } else if (normalized_rx_power<(target_rx_power-4)) {
-            tpc = 2; //+1
-            tpc_accumulated++;
-          } else {
-            tpc = 1; //0
-          }
+          ((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
+          tpc_accumulated--;
+        } else if (normalized_rx_power<(target_rx_power-4)) {
+          tpc = 2; //+1
+          tpc_accumulated++;
         } else {
           tpc = 1; //0
         }
-        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",
+      } else {
+        tpc = 1; //0
+      }
+
+      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,
               tpc_accumulated,normalized_rx_power,target_rx_power);
+      }
+
+      // new transmission
+      if ((ulsch_ue_select[CC_id].list[ulsch_ue_num].ue_priority == SCH_UL_FIRST) ||
+          (ulsch_ue_select[CC_id].list[ulsch_ue_num].ue_priority == SCH_UL_INACTIVE)) {
+        LOG_D(MAC,"[eNB %d][PUSCH %d] Frame %d subframe %d Scheduling UE %d/%x (SR %d,UL_inactivity timer %d,UL_failure timer %d,cqi_req_timer %d)\n",
+              module_idP,harq_pid,frameP,subframeP,UE_id,rnti,UE_template->ul_SR,
+              UE_sched_ctrl->ul_inactivity_timer,
+              UE_sched_ctrl->ul_failure_timer,
+              UE_sched_ctrl->cqi_req_timer);
+        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=UE_template->pre_assigned_mcs_ul;
+        UE_template->mcs_UL[harq_pid] = UE_template->pre_assigned_mcs_ul;//cmin (UE_template->pre_assigned_mcs_ul, openair_daq_vars.target_ue_ul_mcs); // adjust, based on user-defined MCS
+
+        if (UE_template->pre_allocated_rb_table_index_ul >=0) {
+          rb_table_index=UE_template->pre_allocated_rb_table_index_ul;
+        } else {
+          UE_template->mcs_UL[harq_pid]=10;//cmin (10, openair_daq_vars.target_ue_ul_mcs);
+          rb_table_index=5; // for PHR
         }
-          // new transmission
-          if ((ulsch_ue_select[CC_id].list[ulsch_ue_num].ue_priority == SCH_UL_FIRST) ||
-              (ulsch_ue_select[CC_id].list[ulsch_ue_num].ue_priority == SCH_UL_INACTIVE)) {
-              LOG_D(MAC,"[eNB %d][PUSCH %d] Frame %d subframe %d Scheduling UE %d/%x (SR %d,UL_inactivity timer %d,UL_failure timer %d,cqi_req_timer %d)\n",
-                    module_idP,harq_pid,frameP,subframeP,UE_id,rnti,UE_template->ul_SR,
-                    UE_sched_ctrl->ul_inactivity_timer,
-                    UE_sched_ctrl->ul_failure_timer,
-                    UE_sched_ctrl->cqi_req_timer);
-
-            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=UE_template->pre_assigned_mcs_ul;
-            UE_template->mcs_UL[harq_pid] = UE_template->pre_assigned_mcs_ul;//cmin (UE_template->pre_assigned_mcs_ul, openair_daq_vars.target_ue_ul_mcs); // adjust, based on user-defined MCS
-            if (UE_template->pre_allocated_rb_table_index_ul >=0) {
-              rb_table_index=UE_template->pre_allocated_rb_table_index_ul;
-            } else {
-              UE_template->mcs_UL[harq_pid]=10;//cmin (10, openair_daq_vars.target_ue_ul_mcs);
-              rb_table_index=5; // for PHR
-            }
-            UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs2=UE_template->mcs_UL[harq_pid];
-
-            UE_template->TBS_UL[harq_pid] = get_TBS_UL(UE_template->mcs_UL[harq_pid],rb_table[rb_table_index]);
-            UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used_rx+=rb_table[rb_table_index];
-            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(first_rb[CC_id]), T_INT(rb_table[rb_table_index]),
-              T_INT(UE_template->TBS_UL[harq_pid]), T_INT(ndi));
-
-            if (mac_eNB_get_rrc_status(module_idP,rnti) < RRC_CONNECTED)
-              LOG_D(MAC,"[eNB %d][PUSCH %d/%x] CC_id %d Frame %d subframeP %d Scheduled UE %d (mcs %d, first rb %d, nb_rb %d, rb_table_index %d, TBS %d, harq_pid %d)\n",
-                    module_idP,harq_pid,rnti,CC_id,frameP,subframeP,UE_id,UE_template->mcs_UL[harq_pid],
-                    first_rb[CC_id],rb_table[rb_table_index],
-                    rb_table_index,UE_template->TBS_UL[harq_pid],harq_pid);
-
-            // bad indices : 20 (40 PRB), 21 (45 PRB), 22 (48 PRB)
-            //store for possible retransmission
-            UE_template->nb_rb_ul[harq_pid]    = rb_table[rb_table_index];
-            UE_template->first_rb_ul[harq_pid] = first_rb[CC_id];
-
-            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
-            /*LOG_D(MAC,"[eNB %d] CC_id %d UE %d/%x : adjusting ul_total_buffer, old %d, TBS %d\n", module_idP,CC_id,UE_id,rnti,UE_template->ul_total_buffer,UE_template->TBS_UL[harq_pid]);
-            if (UE_template->ul_total_buffer > UE_template->TBS_UL[harq_pid])
-              UE_template->ul_total_buffer -= UE_template->TBS_UL[harq_pid];
-            else
-              UE_template->ul_total_buffer = 0;
-            LOG_D(MAC,"ul_total_buffer, new %d\n", UE_template->ul_total_buffer);*/
-            // 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;
-
-            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_DCI_PDU_TYPE;
-            hi_dci0_pdu->pdu_size                                               = 2+sizeof(nfapi_hi_dci0_dci_pdu);
-            hi_dci0_pdu->dci_pdu.dci_pdu_rel8.dci_format                        = NFAPI_UL_DCI_FORMAT_0;
-            hi_dci0_pdu->dci_pdu.dci_pdu_rel8.aggregation_level                 = aggregation;
-            hi_dci0_pdu->dci_pdu.dci_pdu_rel8.rnti                              = rnti;
-            hi_dci0_pdu->dci_pdu.dci_pdu_rel8.transmission_power                = 6000;
-            hi_dci0_pdu->dci_pdu.dci_pdu_rel8.resource_block_start              = first_rb[CC_id];
-            hi_dci0_pdu->dci_pdu.dci_pdu_rel8.number_of_resource_block          = rb_table[rb_table_index];
-            hi_dci0_pdu->dci_pdu.dci_pdu_rel8.mcs_1                             = UE_template->mcs_UL[harq_pid];
-            hi_dci0_pdu->dci_pdu.dci_pdu_rel8.cyclic_shift_2_for_drms           = cshift;
-            hi_dci0_pdu->dci_pdu.dci_pdu_rel8.frequency_hopping_enabled_flag    = 0;
-            hi_dci0_pdu->dci_pdu.dci_pdu_rel8.new_data_indication_1             = ndi;
-            hi_dci0_pdu->dci_pdu.dci_pdu_rel8.tpc                               = tpc;
-            hi_dci0_pdu->dci_pdu.dci_pdu_rel8.cqi_csi_request                   = cqi_req;
-            hi_dci0_pdu->dci_pdu.dci_pdu_rel8.dl_assignment_index               = UE_template->DAI_ul[sched_subframeP];
-            hi_dci0_pdu->dci_pdu.dci_pdu_rel8.harq_pid                          = harq_pid;
-
-            hi_dci0_req->number_of_dci++;
-            hi_dci0_req->sfnsf = sfnsf_add_subframe(sched_frame, sched_subframeP, 0); //(frameP, subframeP, 4)
-            hi_dci0_req->tl.tag = NFAPI_HI_DCI0_REQUEST_BODY_TAG;
-            nfapi_hi_dci0_request_t        *nfapi_hi_dci0_req = &eNB->HI_DCI0_req[CC_id][subframeP];
-            nfapi_hi_dci0_req->sfn_sf = frameP<<4|subframeP; // sfnsf_add_subframe(sched_frame, sched_subframeP, 0); // sunday!
-            nfapi_hi_dci0_req->header.message_id = NFAPI_HI_DCI0_REQUEST;
-
-            LOG_D(MAC,"[PUSCH %d] Frame %d, Subframe %d: Adding UL CONFIG.Request for UE %d/%x, ulsch_frame %d, ulsch_subframe %d\n",
-                  harq_pid,frameP,subframeP,UE_id,rnti,sched_frame,sched_subframeP);
-
-            ul_req_index = 0;
-            dlsch_flag = 0;
-            for(ul_req_index = 0;ul_req_index < ul_req_tmp->number_of_pdus;ul_req_index++){
-                if((ul_req_tmp->ul_config_pdu_list[ul_req_index].pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE) &&
-                   (ul_req_tmp->ul_config_pdu_list[ul_req_index].uci_harq_pdu.ue_information.ue_information_rel8.rnti == rnti)){
-                   dlsch_flag = 1;
-                   LOG_D(MAC,"Frame %d, Subframe %d:rnti %x ul_req_index %d Switched UCI HARQ to ULSCH HARQ(first)\n",frameP,subframeP,rnti,ul_req_index);
-                   break;
-                }
-            }
-            // Add UL_config PDUs
-            fill_nfapi_ulsch_config_request_rel8(&ul_req_tmp->ul_config_pdu_list[ul_req_index],
-                                                 cqi_req,
-                                                 cc,
-                                                 UE_template->physicalConfigDedicated,
-                                                 get_tmode(module_idP,CC_id,UE_id),
-                                                 eNB->ul_handle,
-                                                 rnti,
-                                                 first_rb[CC_id], // resource_block_start
-                                                 rb_table[rb_table_index], // 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
-                                                 ndi, // new_data_indication
-                                                 0, // redundancy_version
-                                                 harq_pid, // harq_process_number
-                                                 0, // ul_tx_mode
-                                                 0, // current_tx_nb
-                                                 0, // n_srs
-                                                 get_TBS_UL(UE_template->mcs_UL[harq_pid],
-                                                            rb_table[rb_table_index])
-                                                 );
-#ifdef Rel14
-            if (UE_template->rach_resource_type>0) { // This is a BL/CE UE allocation
-              fill_nfapi_ulsch_config_request_emtc(&ul_req_tmp->ul_config_pdu_list[ul_req_index],
-                                                   UE_template->rach_resource_type>2 ? 2 : 1,
-                                                   1, //total_number_of_repetitions
-                                                   1, //repetition_number
-                                                   (frameP*10)+subframeP);
-            }
-#endif
-            if(dlsch_flag == 1){
-                if(cqi_req == 1){
-                    ul_req_tmp->ul_config_pdu_list[ul_req_index].pdu_type = NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE;
-                    ulsch_harq_information = &ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.harq_information;
-                    ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag=NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG;
-                    ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = 0;    // last symbol not punctured
-                    ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks = rb_table[rb_table_index];
-
-                }else{
-                    ul_req_tmp->ul_config_pdu_list[ul_req_index].pdu_type = NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE;
-                    ulsch_harq_information = &ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.harq_information;
-                    ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG;
-                    ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = 0;  // last symbol not punctured
-                    ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks = rb_table[rb_table_index];
-                }
-                fill_nfapi_ulsch_harq_information(module_idP, CC_id,rnti, ulsch_harq_information,subframeP);
-            }else{
-                ul_req_tmp->number_of_pdus++;
-            }
-            eNB->ul_handle++;
-            ul_req->header.message_id = NFAPI_UL_CONFIG_REQUEST;
-            ul_req_tmp->tl.tag = NFAPI_UL_CONFIG_REQUEST_BODY_TAG;
-            uint16_t ul_sched_frame = sched_frame;
-            uint16_t ul_sched_subframeP = sched_subframeP;
-            add_subframe(&ul_sched_frame, &ul_sched_subframeP, 2);
-            ul_req->sfn_sf = ul_sched_frame<<4|ul_sched_subframeP;
-
-            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);
-
-            // increment first rb for next UE allocation
-            first_rb[CC_id]+=rb_table[rb_table_index];
-            if(ulsch_ue_select[CC_id].list[ulsch_ue_num].ue_priority == SCH_UL_FIRST) {
-              UE_template->scheduled_ul_bytes += get_TBS_UL(UE_template->mcs_UL[harq_pid],rb_table[rb_table_index]);
-              UE_template->ul_SR = 0;
-            }
-            if((ulsch_ue_select[CC_id].list[ulsch_ue_num].ue_priority == SCH_UL_INACTIVE) && (ULSCH_first_end == 0)) {
-                ULSCH_first_end = 1;
-                last_ulsch_ue_id[CC_id] = ulsch_ue_select[CC_id].list[ulsch_ue_num-1].UE_id;
-            }
-            if((ulsch_ue_num == ulsch_ue_select[CC_id].ue_num-1) && (ULSCH_first_end == 0)) {
-                ULSCH_first_end = 1;
-                last_ulsch_ue_id[CC_id] = ulsch_ue_select[CC_id].list[ulsch_ue_num].UE_id;
-            }
+
+        UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs2=UE_template->mcs_UL[harq_pid];
+        UE_template->TBS_UL[harq_pid] = get_TBS_UL(UE_template->mcs_UL[harq_pid],rb_table[rb_table_index]);
+        UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used_rx+=rb_table[rb_table_index];
+        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(first_rb[CC_id]), T_INT(rb_table[rb_table_index]),
+          T_INT(UE_template->TBS_UL[harq_pid]), T_INT(ndi));
+
+        if (mac_eNB_get_rrc_status(module_idP,rnti) < RRC_CONNECTED)
+          LOG_D(MAC,"[eNB %d][PUSCH %d/%x] CC_id %d Frame %d subframeP %d Scheduled UE %d (mcs %d, first rb %d, nb_rb %d, rb_table_index %d, TBS %d, harq_pid %d)\n",
+                module_idP,harq_pid,rnti,CC_id,frameP,subframeP,UE_id,UE_template->mcs_UL[harq_pid],
+                first_rb[CC_id],rb_table[rb_table_index],
+                rb_table_index,UE_template->TBS_UL[harq_pid],harq_pid);
+
+        // bad indices : 20 (40 PRB), 21 (45 PRB), 22 (48 PRB)
+        //store for possible retransmission
+        UE_template->nb_rb_ul[harq_pid]    = rb_table[rb_table_index];
+        UE_template->first_rb_ul[harq_pid] = first_rb[CC_id];
+        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
+        /*LOG_D(MAC,"[eNB %d] CC_id %d UE %d/%x : adjusting ul_total_buffer, old %d, TBS %d\n", module_idP,CC_id,UE_id,rnti,UE_template->ul_total_buffer,UE_template->TBS_UL[harq_pid]);
+        if (UE_template->ul_total_buffer > UE_template->TBS_UL[harq_pid])
+          UE_template->ul_total_buffer -= UE_template->TBS_UL[harq_pid];
+        else
+          UE_template->ul_total_buffer = 0;
+        LOG_D(MAC,"ul_total_buffer, new %d\n", UE_template->ul_total_buffer);*/
+        // 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;
+        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_DCI_PDU_TYPE;
+        hi_dci0_pdu->pdu_size                                               = 2+sizeof(nfapi_hi_dci0_dci_pdu);
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.dci_format                        = NFAPI_UL_DCI_FORMAT_0;
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.aggregation_level                 = aggregation;
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.rnti                              = rnti;
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.transmission_power                = 6000;
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.resource_block_start              = first_rb[CC_id];
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.number_of_resource_block          = rb_table[rb_table_index];
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.mcs_1                             = UE_template->mcs_UL[harq_pid];
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.cyclic_shift_2_for_drms           = cshift;
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.frequency_hopping_enabled_flag    = 0;
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.new_data_indication_1             = ndi;
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.tpc                               = tpc;
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.cqi_csi_request                   = cqi_req;
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.dl_assignment_index               = UE_template->DAI_ul[sched_subframeP];
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.harq_pid                          = harq_pid;
+        hi_dci0_req->number_of_dci++;
+        hi_dci0_req->sfnsf = sfnsf_add_subframe(sched_frame, sched_subframeP, 0); //(frameP, subframeP, 4)
+        hi_dci0_req->tl.tag = NFAPI_HI_DCI0_REQUEST_BODY_TAG;
+        nfapi_hi_dci0_request_t        *nfapi_hi_dci0_req = &eNB->HI_DCI0_req[CC_id][subframeP];
+        nfapi_hi_dci0_req->sfn_sf = frameP<<4|subframeP; // sfnsf_add_subframe(sched_frame, sched_subframeP, 0); // sunday!
+        nfapi_hi_dci0_req->header.message_id = NFAPI_HI_DCI0_REQUEST;
+        LOG_D(MAC,"[PUSCH %d] Frame %d, Subframe %d: Adding UL CONFIG.Request for UE %d/%x, ulsch_frame %d, ulsch_subframe %d\n",
+              harq_pid,frameP,subframeP,UE_id,rnti,sched_frame,sched_subframeP);
+        ul_req_index = 0;
+        dlsch_flag = 0;
+
+        for(ul_req_index = 0; ul_req_index < ul_req_tmp->number_of_pdus; ul_req_index++) {
+          if((ul_req_tmp->ul_config_pdu_list[ul_req_index].pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE) &&
+              (ul_req_tmp->ul_config_pdu_list[ul_req_index].uci_harq_pdu.ue_information.ue_information_rel8.rnti == rnti)) {
+            dlsch_flag = 1;
+            LOG_D(MAC,"Frame %d, Subframe %d:rnti %x ul_req_index %d Switched UCI HARQ to ULSCH HARQ(first)\n",frameP,subframeP,rnti,ul_req_index);
+            break;
           }
-          else if (ulsch_ue_select[CC_id].list[ulsch_ue_num].ue_priority == SCH_UL_RETRANS) { // 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(first_rb[CC_id]), T_INT(rb_table[rb_table_index]),
-              T_INT(round));
-
-            round = UE_sched_ctrl->round_UL[CC_id][harq_pid];
-            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;
-            uint8_t mcs_rv = 0;
-            if(rvidx_tab[round&3]==1){
-               mcs_rv = 29;
-            }else if(rvidx_tab[round&3]==2){
-               mcs_rv = 30;
-            }else if(rvidx_tab[round&3]==3){
-               mcs_rv = 31;
-            }
-            UE_template->TBS_UL[harq_pid] = get_TBS_UL(UE_template->mcs_UL[harq_pid],ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb);
-            UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_TBS=UE_template->TBS_UL[harq_pid];
-
-
-            if (mac_eNB_get_rrc_status(module_idP,rnti) < RRC_CONNECTED)
-              LOG_D(MAC,"[eNB %d][PUSCH %d/%x] CC_id %d Frame %d subframeP %d Scheduled UE %d (mcs %d, first rb %d, nb_rb %d, rb_table_index %d, TBS %d, harq_pid %d)\n",
-                    module_idP,harq_pid,rnti,CC_id,frameP,subframeP,UE_id,mcs_rv,first_rb[CC_id],rb_table[rb_table_index],rb_table_index,UE_template->TBS_UL[harq_pid],harq_pid);
-
-            // bad indices : 20 (40 PRB), 21 (45 PRB), 22 (48 PRB)
-            //store for possible retransmission
-            UE_template->nb_rb_ul[harq_pid]    = ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb;
-            UE_template->first_rb_ul[harq_pid] = ulsch_ue_select[CC_id].list[ulsch_ue_num].start_rb;
-
-            UE_sched_ctrl->ul_scheduled |= (1<<harq_pid);
-            // 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)
-
-            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_DCI_PDU_TYPE;
-            hi_dci0_pdu->pdu_size                                               = 2+sizeof(nfapi_hi_dci0_dci_pdu);
-            hi_dci0_pdu->dci_pdu.dci_pdu_rel8.dci_format                        = NFAPI_UL_DCI_FORMAT_0;
-            hi_dci0_pdu->dci_pdu.dci_pdu_rel8.aggregation_level                 = aggregation;
-            hi_dci0_pdu->dci_pdu.dci_pdu_rel8.rnti                              = rnti;
-            hi_dci0_pdu->dci_pdu.dci_pdu_rel8.transmission_power                = 6000;
-            hi_dci0_pdu->dci_pdu.dci_pdu_rel8.resource_block_start              = ulsch_ue_select[CC_id].list[ulsch_ue_num].start_rb;
-            hi_dci0_pdu->dci_pdu.dci_pdu_rel8.number_of_resource_block          = ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb;
-            hi_dci0_pdu->dci_pdu.dci_pdu_rel8.mcs_1                             = mcs_rv;
-            hi_dci0_pdu->dci_pdu.dci_pdu_rel8.cyclic_shift_2_for_drms           = cshift;
-            hi_dci0_pdu->dci_pdu.dci_pdu_rel8.frequency_hopping_enabled_flag    = 0;
-            hi_dci0_pdu->dci_pdu.dci_pdu_rel8.new_data_indication_1             = UE_template->oldNDI_UL[harq_pid];
-            hi_dci0_pdu->dci_pdu.dci_pdu_rel8.tpc                               = tpc;
-            hi_dci0_pdu->dci_pdu.dci_pdu_rel8.cqi_csi_request                   = cqi_req;
-            hi_dci0_pdu->dci_pdu.dci_pdu_rel8.dl_assignment_index               = UE_template->DAI_ul[sched_subframeP];
-            hi_dci0_pdu->dci_pdu.dci_pdu_rel8.harq_pid                          = harq_pid;
-
-            hi_dci0_req->number_of_dci++;
-            // Add UL_config PDUs
-            LOG_D(MAC,"[PUSCH %d] Frame %d, Subframe %d: Adding UL CONFIG.Request for UE %d/%x, ulsch_frame %d, ulsch_subframe %d\n",
-                  harq_pid,frameP,subframeP,UE_id,rnti,sched_frame,sched_subframeP);
-            ul_req_index = 0;
-            dlsch_flag = 0;
-            for(ul_req_index = 0;ul_req_index < ul_req_tmp->number_of_pdus;ul_req_index++){
-                if((ul_req_tmp->ul_config_pdu_list[ul_req_index].pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE) &&
-                   (ul_req_tmp->ul_config_pdu_list[ul_req_index].uci_harq_pdu.ue_information.ue_information_rel8.rnti == rnti)){
-                   dlsch_flag = 1;
-                   LOG_D(MAC,"Frame %d, Subframe %d:rnti %x ul_req_index %d Switched UCI HARQ to ULSCH HARQ(phich)\n",frameP,subframeP,rnti,ul_req_index);
-                   break;
-                }
-            }
-            fill_nfapi_ulsch_config_request_rel8(&ul_req_tmp->ul_config_pdu_list[ul_req_index],
-                                                 cqi_req,
-                                                 cc,
-                                                 UE_template->physicalConfigDedicated,
-                                                 get_tmode(module_idP,CC_id,UE_id),
-                                                 eNB->ul_handle,
-                                                 rnti,
-                                                 ulsch_ue_select[CC_id].list[ulsch_ue_num].start_rb, // resource_block_start
-                                                 ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb, // 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]
-                                                 );
-#ifdef Rel14
-            if (UE_template->rach_resource_type>0) { // This is a BL/CE UE allocation
-              fill_nfapi_ulsch_config_request_emtc(&ul_req_tmp->ul_config_pdu_list[ul_req_index],
-                                                   UE_template->rach_resource_type>2 ? 2 : 1,
-                                                   1, //total_number_of_repetitions
-                                                   1, //repetition_number
-                                                   (frameP*10)+subframeP);
-            }
+        }
+
+        // Add UL_config PDUs
+        fill_nfapi_ulsch_config_request_rel8(&ul_req_tmp->ul_config_pdu_list[ul_req_index],
+                                             cqi_req,
+                                             cc,
+                                             UE_template->physicalConfigDedicated,
+                                             get_tmode(module_idP,CC_id,UE_id),
+                                             eNB->ul_handle,
+                                             rnti,
+                                             first_rb[CC_id], // resource_block_start
+                                             rb_table[rb_table_index], // 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
+                                             ndi, // new_data_indication
+                                             0, // redundancy_version
+                                             harq_pid, // harq_process_number
+                                             0, // ul_tx_mode
+                                             0, // current_tx_nb
+                                             0, // n_srs
+                                             get_TBS_UL(UE_template->mcs_UL[harq_pid],
+                                                 rb_table[rb_table_index])
+                                            );
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+
+        if (UE_template->rach_resource_type>0) { // This is a BL/CE UE allocation
+          fill_nfapi_ulsch_config_request_emtc(&ul_req_tmp->ul_config_pdu_list[ul_req_index],
+                                               UE_template->rach_resource_type>2 ? 2 : 1,
+                                               1, //total_number_of_repetitions
+                                               1, //repetition_number
+                                               (frameP*10)+subframeP);
+        }
+
 #endif
-              if(dlsch_flag == 1){
-                  if(cqi_req == 1){
-                      ul_req_tmp->ul_config_pdu_list[ul_req_index].pdu_type = NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE;
-                      ulsch_harq_information = &ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.harq_information;
-                      ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag=NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG;
-                      ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = 0;    // last symbol not punctured
-                      ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks = ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb;
-
-                  }else{
-                      ul_req_tmp->ul_config_pdu_list[ul_req_index].pdu_type = NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE;
-                      ulsch_harq_information = &ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.harq_information;
-                      ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG;
-                      ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = 0;  // last symbol not punctured
-                      ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks = ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb;
-                  }
-                  fill_nfapi_ulsch_harq_information(module_idP, CC_id,rnti, ulsch_harq_information,subframeP);
-              }else{
-                ul_req_tmp->number_of_pdus++;
-              }
-              eNB->ul_handle++;
-            ul_req->header.message_id = NFAPI_UL_CONFIG_REQUEST;
-            ul_req_tmp->tl.tag = NFAPI_UL_CONFIG_REQUEST_BODY_TAG;
-            ul_req->sfn_sf = sched_frame<<4|sched_subframeP;
 
-              LOG_D(MAC,"[eNB %d] CC_id %d Frame %d, subframeP %d: Generated ULSCH DCI for next UE_id %d, format 0(round >0)\n", module_idP,CC_id,frameP,subframeP,UE_id);
+        if(dlsch_flag == 1) {
+          if(cqi_req == 1) {
+            ul_req_tmp->ul_config_pdu_list[ul_req_index].pdu_type = NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE;
+            ulsch_harq_information = &ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.harq_information;
+            ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag=
+              NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG;
+            ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = 0;    // last symbol not punctured
+            ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks = rb_table[rb_table_index];
+          } else {
+            ul_req_tmp->ul_config_pdu_list[ul_req_index].pdu_type = NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE;
+            ulsch_harq_information = &ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.harq_information;
+            ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag =
+              NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG;
+            ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = 0;  // last symbol not punctured
+            ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks = rb_table[rb_table_index];
+          }
+
+          fill_nfapi_ulsch_harq_information(module_idP, CC_id,rnti, ulsch_harq_information,subframeP);
+        } else {
+          ul_req_tmp->number_of_pdus++;
+        }
+
+        eNB->ul_handle++;
+        ul_req->header.message_id = NFAPI_UL_CONFIG_REQUEST;
+        ul_req_tmp->tl.tag = NFAPI_UL_CONFIG_REQUEST_BODY_TAG;
+        uint16_t ul_sched_frame = sched_frame;
+        uint16_t ul_sched_subframeP = sched_subframeP;
+        add_subframe(&ul_sched_frame, &ul_sched_subframeP, 2);
+        ul_req->sfn_sf = ul_sched_frame<<4|ul_sched_subframeP;
+        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);
+        // increment first rb for next UE allocation
+        first_rb[CC_id]+=rb_table[rb_table_index];
+
+        if(ulsch_ue_select[CC_id].list[ulsch_ue_num].ue_priority == SCH_UL_FIRST) {
+          UE_template->scheduled_ul_bytes += get_TBS_UL(UE_template->mcs_UL[harq_pid],rb_table[rb_table_index]);
+          UE_template->ul_SR = 0;
+        }
+
+        if((ulsch_ue_select[CC_id].list[ulsch_ue_num].ue_priority == SCH_UL_INACTIVE) && (ULSCH_first_end == 0)) {
+          ULSCH_first_end = 1;
+          last_ulsch_ue_id[CC_id] = ulsch_ue_select[CC_id].list[ulsch_ue_num-1].UE_id;
+        }
+
+        if((ulsch_ue_num == ulsch_ue_select[CC_id].ue_num-1) && (ULSCH_first_end == 0)) {
+          ULSCH_first_end = 1;
+          last_ulsch_ue_id[CC_id] = ulsch_ue_select[CC_id].list[ulsch_ue_num].UE_id;
+        }
+      } else if (ulsch_ue_select[CC_id].list[ulsch_ue_num].ue_priority == SCH_UL_RETRANS) { // 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(first_rb[CC_id]), T_INT(rb_table[rb_table_index]),
+          T_INT(round));
+        round = UE_sched_ctrl->round_UL[CC_id][harq_pid];
+        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;
+        uint8_t mcs_rv = 0;
+
+        if(rvidx_tab[round&3]==1) {
+          mcs_rv = 29;
+        } else if(rvidx_tab[round&3]==2) {
+          mcs_rv = 30;
+        } else if(rvidx_tab[round&3]==3) {
+          mcs_rv = 31;
+        }
+
+        UE_template->TBS_UL[harq_pid] = get_TBS_UL(UE_template->mcs_UL[harq_pid],ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb);
+        UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_TBS=UE_template->TBS_UL[harq_pid];
+
+        if (mac_eNB_get_rrc_status(module_idP,rnti) < RRC_CONNECTED)
+          LOG_D(MAC,"[eNB %d][PUSCH %d/%x] CC_id %d Frame %d subframeP %d Scheduled UE %d (mcs %d, first rb %d, nb_rb %d, rb_table_index %d, TBS %d, harq_pid %d)\n",
+                module_idP,harq_pid,rnti,CC_id,frameP,subframeP,UE_id,mcs_rv,first_rb[CC_id],rb_table[rb_table_index],rb_table_index,UE_template->TBS_UL[harq_pid],harq_pid);
+
+        // bad indices : 20 (40 PRB), 21 (45 PRB), 22 (48 PRB)
+        //store for possible retransmission
+        UE_template->nb_rb_ul[harq_pid]    = ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb;
+        UE_template->first_rb_ul[harq_pid] = ulsch_ue_select[CC_id].list[ulsch_ue_num].start_rb;
+        UE_sched_ctrl->ul_scheduled |= (1<<harq_pid);
+        // 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)
+        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_DCI_PDU_TYPE;
+        hi_dci0_pdu->pdu_size                                               = 2+sizeof(nfapi_hi_dci0_dci_pdu);
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.dci_format                        = NFAPI_UL_DCI_FORMAT_0;
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.aggregation_level                 = aggregation;
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.rnti                              = rnti;
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.transmission_power                = 6000;
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.resource_block_start              = ulsch_ue_select[CC_id].list[ulsch_ue_num].start_rb;
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.number_of_resource_block          = ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb;
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.mcs_1                             = mcs_rv;
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.cyclic_shift_2_for_drms           = cshift;
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.frequency_hopping_enabled_flag    = 0;
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.new_data_indication_1             = UE_template->oldNDI_UL[harq_pid];
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.tpc                               = tpc;
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.cqi_csi_request                   = cqi_req;
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.dl_assignment_index               = UE_template->DAI_ul[sched_subframeP];
+        hi_dci0_pdu->dci_pdu.dci_pdu_rel8.harq_pid                          = harq_pid;
+        hi_dci0_req->number_of_dci++;
+        // Add UL_config PDUs
+        LOG_D(MAC,"[PUSCH %d] Frame %d, Subframe %d: Adding UL CONFIG.Request for UE %d/%x, ulsch_frame %d, ulsch_subframe %d\n",
+              harq_pid,frameP,subframeP,UE_id,rnti,sched_frame,sched_subframeP);
+        ul_req_index = 0;
+        dlsch_flag = 0;
+
+        for(ul_req_index = 0; ul_req_index < ul_req_tmp->number_of_pdus; ul_req_index++) {
+          if((ul_req_tmp->ul_config_pdu_list[ul_req_index].pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE) &&
+              (ul_req_tmp->ul_config_pdu_list[ul_req_index].uci_harq_pdu.ue_information.ue_information_rel8.rnti == rnti)) {
+            dlsch_flag = 1;
+            LOG_D(MAC,"Frame %d, Subframe %d:rnti %x ul_req_index %d Switched UCI HARQ to ULSCH HARQ(phich)\n",frameP,subframeP,rnti,ul_req_index);
+            break;
+          }
+        }
+
+        fill_nfapi_ulsch_config_request_rel8(&ul_req_tmp->ul_config_pdu_list[ul_req_index],
+                                             cqi_req,
+                                             cc,
+                                             UE_template->physicalConfigDedicated,
+                                             get_tmode(module_idP,CC_id,UE_id),
+                                             eNB->ul_handle,
+                                             rnti,
+                                             ulsch_ue_select[CC_id].list[ulsch_ue_num].start_rb, // resource_block_start
+                                             ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb, // 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]
+                                            );
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+
+        if (UE_template->rach_resource_type>0) { // This is a BL/CE UE allocation
+          fill_nfapi_ulsch_config_request_emtc(&ul_req_tmp->ul_config_pdu_list[ul_req_index],
+                                               UE_template->rach_resource_type>2 ? 2 : 1,
+                                               1, //total_number_of_repetitions
+                                               1, //repetition_number
+                                               (frameP*10)+subframeP);
+        }
 
-              // increment first rb for next UE allocation
-              first_rb[CC_id]+=ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb;
+#endif
+
+        if(dlsch_flag == 1) {
+          if(cqi_req == 1) {
+            ul_req_tmp->ul_config_pdu_list[ul_req_index].pdu_type = NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE;
+            ulsch_harq_information = &ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.harq_information;
+            ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag=
+              NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG;
+            ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = 0;    // last symbol not punctured
+            ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks =
+              ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb;
+          } else {
+            ul_req_tmp->ul_config_pdu_list[ul_req_index].pdu_type = NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE;
+            ulsch_harq_information = &ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.harq_information;
+            ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag =
+              NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG;
+            ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = 0;  // last symbol not punctured
+            ul_req_tmp->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks =
+              ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb;
           }
+
+          fill_nfapi_ulsch_harq_information(module_idP, CC_id,rnti, ulsch_harq_information,subframeP);
+        } else {
+          ul_req_tmp->number_of_pdus++;
+        }
+
+        eNB->ul_handle++;
+        ul_req->header.message_id = NFAPI_UL_CONFIG_REQUEST;
+        ul_req_tmp->tl.tag = NFAPI_UL_CONFIG_REQUEST_BODY_TAG;
+        ul_req->sfn_sf = sched_frame<<4|sched_subframeP;
+        LOG_D(MAC,"[eNB %d] CC_id %d Frame %d, subframeP %d: Generated ULSCH DCI for next UE_id %d, format 0(round >0)\n", module_idP,CC_id,frameP,subframeP,UE_id);
+        // increment first rb for next UE allocation
+        first_rb[CC_id]+=ulsch_ue_select[CC_id].list[ulsch_ue_num].nb_rb;
+      }
     } // loop over UE_id
   } // loop of CC_id
 }
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_mch.c b/openair2/LAYER2/MAC/eNB_scheduler_mch.c
index da2b19dee61cfb18c35a94326a45daac0271f6d7..faf36026d62e8346a0adac000a01125bb4f2b5e3 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_mch.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_mch.c
@@ -59,7 +59,7 @@
 
 extern RAN_CONTEXT_t RC;
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 int8_t
 get_mbsfn_sf_alloction(module_id_t module_idP, uint8_t CC_id,
 		       uint8_t mbsfn_sync_area)
@@ -151,7 +151,7 @@ schedule_MBMS(module_id_t module_idP, uint8_t CC_id, frame_t frameP,
 
 	// 1st: Check the MBSFN subframes from SIB2 info (SF allocation pattern i, max 8 non-overlapping patterns exist)
 	if (frameP % mbsfn_period == cc->mbsfn_SubframeConfig[j]->radioframeAllocationOffset) {	// MBSFN frameP
-	    if (cc->mbsfn_SubframeConfig[j]->subframeAllocation.present == MBSFN_SubframeConfig__subframeAllocation_PR_oneFrame) {	// one-frameP format
+	    if (cc->mbsfn_SubframeConfig[j]->subframeAllocation.present == LTE_MBSFN_SubframeConfig__subframeAllocation_PR_oneFrame) {	// one-frameP format
 
 		//  Find the first subframeP in this MCH to transmit MSI
 		if (frameP % mch_scheduling_period ==
@@ -585,7 +585,7 @@ schedule_MBMS(module_id_t module_idP, uint8_t CC_id, frame_t frameP,
 
     TBS =
 	get_TBS_DL(cc->MCH_pdu.mcs, to_prb(cc->mib->message.dl_Bandwidth));
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
     // do not let mcch and mtch multiplexing when relaying is active
     // for sync area 1, so not transmit data
     //if ((i == 0) && ((RC.mac[module_idP]->MBMS_flag != multicast_relay) || (RC.mac[module_idP]->mcch_active==0))) {
@@ -633,7 +633,7 @@ schedule_MBMS(module_id_t module_idP, uint8_t CC_id, frame_t frameP,
 			       MTCH,
 			       TBS - header_len_mcch - header_len_msi -
 			       sdu_length_total - header_len_mtch
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                                     ,0, 0
 #endif
                                     );
@@ -652,7 +652,7 @@ schedule_MBMS(module_id_t module_idP, uint8_t CC_id, frame_t frameP,
 	    sdu_lengths[num_sdus] = mac_rlc_data_req(module_idP, 0, module_idP, frameP, ENB_FLAG_YES, MBMS_FLAG_YES, MTCH, 0,	//not used
 						     (char *)
 						     &mch_buffer[sdu_length_total]
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                                 ,0,
                                  0
 #endif
@@ -676,7 +676,7 @@ schedule_MBMS(module_id_t module_idP, uint8_t CC_id, frame_t frameP,
 	    header_len_mtch = 0;
 	}
     }
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
     //  }
 #endif
 
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_phytest.c b/openair2/LAYER2/MAC/eNB_scheduler_phytest.c
index 81c418c12352ea83d87cbe1aedbf0941df37641b..2f566c0d7a0d48d1397c23b4fe4892cba59879dc 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_phytest.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_phytest.c
@@ -169,7 +169,7 @@ schedule_ue_spec_phy_test(
 			      1, // number of subbands
 			      //			     uint8_t codebook_index,
 			      4, // UE category capacity
-			      PDSCH_ConfigDedicated__p_a_dB0, 
+			      LTE_PDSCH_ConfigDedicated__p_a_dB0,
 			      0, // delta_power_offset for TM5
 			      0, // ngap
 			      0, // nprb
@@ -347,7 +347,7 @@ void schedule_ulsch_phy_test(module_id_t module_idP,frame_t frameP,sub_frame_t s
 						 0, // n_srs
 						 get_TBS_UL(mcs,nb_rb)
 						 );
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 	  if (UE_template->rach_resource_type>0) { // This is a BL/CE UE allocation
 	    fill_nfapi_ulsch_config_request_emtc(&ul_req->ul_config_pdu_list[ul_req_index],
 						   UE_template->rach_resource_type>2 ? 2 : 1,
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c
index 817cfd20339724e63ec8a311a30f0d370d1384ba..8bc86df30ced83be9eeca58d3b1292206295b736 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c
@@ -48,7 +48,7 @@
 #include "pdcp.h"
 
 #if defined(ENABLE_ITTI)
-#include "intertask_interface.h"
+  #include "intertask_interface.h"
 #endif
 
 #include "T.h"
@@ -61,20 +61,22 @@ extern uint16_t frame_cnt;
 #include "SCHED/sched_common.h"
 
 extern RAN_CONTEXT_t RC;
+extern uint8_t nfapi_mode;
 
-int choose(int n, int k)
-{
+int choose(int n, int k) {
   int res = 1;
   int res2 = 1;
   int i;
 
   if (k > n)
     return (0);
+
   if (n == k)
     return (1);
 
   for (i = n; i > k; i--)
     res *= i;
+
   for (i = 2; i <= (n - k); i++)
     res2 *= i;
 
@@ -82,21 +84,20 @@ int choose(int n, int k)
 }
 
 // Patented algorithm from Yang et al, US Patent 2009, "Channel Quality Indexing and Reverse Indexing"
-void reverse_index(int N, int M, int r, int *v)
-{
+void reverse_index(int N, int M, int r, int *v) {
   int BaseValue = 0;
   int IncreaseValue, ThresholdValue;
   int sumV;
   int i;
-
   r = choose(N, M) - 1 - r;
   memset((void *) v, 0, M * sizeof(int));
-
   sumV = 0;
   i = M;
+
   while (i > 0 && r > 0) {
     IncreaseValue = choose(N - M + 1 - sumV - v[i - 1] + i - 2, i - 1);
     ThresholdValue = BaseValue + IncreaseValue;
+
     if (r >= ThresholdValue) {
       v[i - 1]++;
       BaseValue = ThresholdValue;
@@ -109,37 +110,30 @@ void reverse_index(int N, int M, int r, int *v)
   }
 }
 
-int to_prb(int dl_Bandwidth)
-{
+int to_prb(int dl_Bandwidth) {
   int prbmap[6] = { 6, 15, 25, 50, 75, 100 };
-
   AssertFatal(dl_Bandwidth < 6, "dl_Bandwidth is 0..5\n");
   return (prbmap[dl_Bandwidth]);
 }
 
-int to_rbg(int dl_Bandwidth)
-{
+int to_rbg(int dl_Bandwidth) {
   int rbgmap[6] = { 6, 8, 13, 17, 19, 25 };
-
   AssertFatal(dl_Bandwidth < 6, "dl_Bandwidth is 0..5\n");
   return (rbgmap[dl_Bandwidth]);
 }
 
-int get_phich_resource_times6(COMMON_channels_t * cc)
-{
+int get_phich_resource_times6(COMMON_channels_t *cc) {
   int phichmap[4] = { 1, 3, 6, 12 };
   AssertFatal(cc != NULL, "cc is null\n");
   AssertFatal(cc->mib != NULL, "cc->mib is null\n");
   AssertFatal((cc->mib->message.phich_Config.phich_Resource >= 0) &&
-	      (cc->mib->message.phich_Config.phich_Resource < 4),
-	      "phich_Resource %d not in 0..3\n",
-	      (int) cc->mib->message.phich_Config.phich_Resource);
-
+              (cc->mib->message.phich_Config.phich_Resource < 4),
+              "phich_Resource %d not in 0..3\n",
+              (int) cc->mib->message.phich_Config.phich_Resource);
   return (phichmap[cc->mib->message.phich_Config.phich_Resource]);
 }
 
-uint16_t mac_computeRIV(uint16_t N_RB_DL, uint16_t RBstart, uint16_t Lcrbs)
-{
+uint16_t mac_computeRIV(uint16_t N_RB_DL, uint16_t RBstart, uint16_t Lcrbs) {
   uint16_t RIV;
 
   if (Lcrbs <= (1 + (N_RB_DL >> 1))) RIV = (N_RB_DL * (Lcrbs - 1)) + RBstart;
@@ -148,8 +142,7 @@ uint16_t mac_computeRIV(uint16_t N_RB_DL, uint16_t RBstart, uint16_t Lcrbs)
   return (RIV);
 }
 
-uint8_t getQm(uint8_t mcs)
-{
+uint8_t getQm(uint8_t mcs) {
   if (mcs < 10)      return (2);
   else if (mcs < 17) return (4);
   else               return (6);
@@ -157,14 +150,12 @@ uint8_t getQm(uint8_t mcs)
 
 void
 get_Msg3alloc(COMMON_channels_t *cc,
-	      sub_frame_t       current_subframe,
-	      frame_t           current_frame, 
-	      frame_t           *frame,
-	      sub_frame_t       *subframe)
-{
+              sub_frame_t       current_subframe,
+              frame_t           current_frame,
+              frame_t           *frame,
+              sub_frame_t       *subframe) {
   // Fill in other TDD Configuration!!!!
-
-  if (cc->tdd_Config == NULL) {	// FDD
+  if (cc->tdd_Config == NULL) { // FDD
     *subframe = current_subframe + 6;
 
     if (*subframe > 9) {
@@ -173,94 +164,90 @@ get_Msg3alloc(COMMON_channels_t *cc,
     } else {
       *frame = current_frame;
     }
-  } else {			// TDD
+  } else {      // TDD
     if (cc->tdd_Config->subframeAssignment == 1) {
       switch (current_subframe) {
-	  
-      case 0:
-	*subframe = 7;
-	*frame = current_frame;
-	break;
+        case 0:
+          *subframe = 7;
+          *frame = current_frame;
+          break;
 
-      case 4:
-	*subframe = 2;
-	*frame = (current_frame + 1) & 1023;
-	break;
+        case 4:
+          *subframe = 2;
+          *frame = (current_frame + 1) & 1023;
+          break;
 
-      case 5:
-	*subframe = 2;
-	*frame = (current_frame + 1) & 1023;
-	break;
-
-      case 9:
-	*subframe = 7;
-	*frame = (current_frame + 1) & 1023;
-	break;
+        case 5:
+          *subframe = 2;
+          *frame = (current_frame + 1) & 1023;
+          break;
+
+        case 9:
+          *subframe = 7;
+          *frame = (current_frame + 1) & 1023;
+          break;
       }
     } else if (cc->tdd_Config->subframeAssignment == 3) {
       switch (current_subframe) {
+        case 0:
+        case 5:
+        case 6:
+          *subframe = 2;
+          *frame = (current_frame + 1) & 1023;
+          break;
 
-      case 0:
-      case 5:
-      case 6:
-	*subframe = 2;
-	*frame = (current_frame + 1) & 1023;
-	break;
+        case 7:
+          *subframe = 3;
+          *frame = (current_frame + 1) & 1023;
+          break;
 
-      case 7:
-	*subframe = 3;
-	*frame = (current_frame + 1) & 1023;
-	break;
+        case 8:
+          *subframe = 4;
+          *frame = (current_frame + 1) & 1023;
+          break;
 
-      case 8:
-	*subframe = 4;
-	*frame = (current_frame + 1) & 1023;
-	break;
-
-      case 9:
-	*subframe = 2;
-	*frame = (current_frame + 2) & 1023;
-	break;
+        case 9:
+          *subframe = 2;
+          *frame = (current_frame + 2) & 1023;
+          break;
       }
     } else if (cc->tdd_Config->subframeAssignment == 4) {
       switch (current_subframe) {
+        case 0:
+        case 4:
+        case 5:
+        case 6:
+          *subframe = 2;
+          *frame = (current_frame + 1) & 1023;
+          break;
 
-      case 0:
-      case 4:
-      case 5:
-      case 6:
-	*subframe = 2;
-	*frame = (current_frame + 1) & 1023;
-	break;
-
-      case 7:
-	*subframe = 3;
-	*frame = (current_frame + 1) & 1023;
-	break;
+        case 7:
+          *subframe = 3;
+          *frame = (current_frame + 1) & 1023;
+          break;
 
-      case 8:
-      case 9:
-	*subframe = 2;
-	*frame = (current_frame + 2) & 1023;
-	break;
+        case 8:
+        case 9:
+          *subframe = 2;
+          *frame = (current_frame + 2) & 1023;
+          break;
       }
     } else if (cc->tdd_Config->subframeAssignment == 5) {
       switch (current_subframe) {
+        case 0:
+        case 4:
+        case 5:
+        case 6:
+          *subframe = 2;
+          *frame = (current_frame + 1) & 1023;
+          break;
 
-      case 0:
-      case 4:
-      case 5:
-      case 6:
-	*subframe = 2;
-	*frame = (current_frame + 1) & 1023;
-	break;
-
-      case 7:
-      case 8:
-      case 9:
-	*subframe = 2;
-	*frame = (current_frame + 2) & 1023;
-	break;
+        case 7:
+        case 8:
+        case 9:
+          *subframe = 2;
+          *frame = (current_frame + 2) & 1023;
+          break;
       }
     }
   }
@@ -269,12 +256,11 @@ get_Msg3alloc(COMMON_channels_t *cc,
 
 
 void
-get_Msg3allocret(COMMON_channels_t * cc,
-		 sub_frame_t current_subframe,
-		 frame_t current_frame,
-		 frame_t * frame, sub_frame_t * subframe)
-{
-  if (cc->tdd_Config == NULL) {	//FDD
+get_Msg3allocret(COMMON_channels_t *cc,
+                 sub_frame_t current_subframe,
+                 frame_t current_frame,
+                 frame_t *frame, sub_frame_t *subframe) {
+  if (cc->tdd_Config == NULL) { //FDD
     /* always retransmit in n+8 */
     *subframe = current_subframe + 8;
 
@@ -308,149 +294,153 @@ get_Msg3allocret(COMMON_channels_t * cc,
 }
 
 uint8_t
-subframe2harqpid(COMMON_channels_t * cc, frame_t frame,
-		 sub_frame_t subframe)
+subframe2harqpid(COMMON_channels_t *cc,
+                 frame_t frame,
+                 sub_frame_t subframe)
 {
   uint8_t ret = 255;
-
   AssertFatal(cc != NULL, "cc is null\n");
 
-  if (cc->tdd_Config == NULL) {	// FDD
+  if (cc->tdd_Config == NULL) { // FDD
     ret = (((frame << 1) + subframe) & 7);
   } else {
     switch (cc->tdd_Config->subframeAssignment) {
-    case 1:
-      if ((subframe == 2) ||
-	  (subframe == 3) || (subframe == 7) || (subframe == 8))
-	switch (subframe) {
-	case 2:
-	case 3:
-	  ret = (subframe - 2);
-	  break;
-	case 7:
-	case 8:
-	  ret = (subframe - 5);
-	  break;
-	default:
-	  AssertFatal(1 == 0,
-		      "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",
-		      subframe,
-		      (int) cc->tdd_Config->subframeAssignment);
-	  break;
-	}
+      case 1:
+        switch (subframe) {
+          case 2:
+          case 3:
+            ret = (subframe - 2);
+            break;
 
-      break;
+          case 7:
+          case 8:
+            ret = (subframe - 5);
+            break;
 
-    case 2:
-      AssertFatal((subframe == 2) || (subframe == 7),
-		  "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",
-		  subframe,
-		  (int) cc->tdd_Config->subframeAssignment);
+          default:
+            AssertFatal(1 == 0, "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",
+                        subframe, (int) cc->tdd_Config->subframeAssignment);
+            break;
+        }
+        break;
 
-      ret = (subframe / 7);
-      break;
+      case 2:
+        AssertFatal((subframe == 2) || (subframe == 7),
+                    "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",
+                    subframe, (int) cc->tdd_Config->subframeAssignment);
+        ret = (subframe / 7);
+        break;
 
-    case 3:
-      AssertFatal((subframe > 1) && (subframe < 5),
-		  "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",
-		  subframe,
-		  (int) cc->tdd_Config->subframeAssignment);
-      ret = (subframe - 2);
-      break;
+      case 3:
+        AssertFatal((subframe > 1) && (subframe < 5),
+                    "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",
+                    subframe, (int) cc->tdd_Config->subframeAssignment);
+        ret = (subframe - 2);
+        break;
 
-    case 4:
-      AssertFatal((subframe > 1) && (subframe < 4),
-		  "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",
-		  subframe,
-		  (int) cc->tdd_Config->subframeAssignment);
-      ret = (subframe - 2);
-      break;
+      case 4:
+        AssertFatal((subframe > 1) && (subframe < 4),
+                    "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",
+                    subframe, (int) cc->tdd_Config->subframeAssignment);
+        ret = (subframe - 2);
+        break;
 
-    case 5:
-      AssertFatal(subframe == 2,
-		  "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",
-		  subframe,
-		  (int) cc->tdd_Config->subframeAssignment);
-      ret = (subframe - 2);
-      break;
+      case 5:
+        AssertFatal(subframe == 2,
+                    "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",
+                    subframe, (int) cc->tdd_Config->subframeAssignment);
+        ret = (subframe - 2);
+        break;
 
-    default:
-      AssertFatal(1 == 0,
-		  "subframe2_harq_pid, Unsupported TDD mode %d\n",
-		  (int) cc->tdd_Config->subframeAssignment);
+      default:
+        AssertFatal(1 == 0,
+                    "subframe2_harq_pid, Unsupported TDD mode %d\n",
+                    (int) cc->tdd_Config->subframeAssignment);
+        break;
     }
   }
   return ret;
 }
 
 uint8_t
-get_Msg3harqpid(COMMON_channels_t * cc,
-		frame_t frame, sub_frame_t current_subframe)
-{
+get_Msg3harqpid(COMMON_channels_t *cc,
+                frame_t frame, sub_frame_t current_subframe) {
   uint8_t ul_subframe = 0;
   uint32_t ul_frame = 0;
 
-  if (cc->tdd_Config == NULL) {	// FDD
+  if (cc->tdd_Config == NULL) { // FDD
     ul_subframe =
       (current_subframe >
        3) ? (current_subframe - 4) : (current_subframe + 6);
     ul_frame = (current_subframe > 3) ? ((frame + 1) & 1023) : frame;
   } else {
     switch (cc->tdd_Config->subframeAssignment) {
-    case 1:
-      switch (current_subframe) {
-      case 9:
-      case 0:
-	ul_subframe = 7;
-	break;
-      case 5:
-      case 7:
-	ul_subframe = 2;
-	break;
-      }
-      break;
-    case 3:
-      switch (current_subframe) {
-      case 0:
-      case 5:
-      case 6:
-	ul_subframe = 2;
-	break;
-      case 7:
-	ul_subframe = 3;
-	break;
-      case 8:
-	ul_subframe = 4;
-	break;
-      case 9:
-	ul_subframe = 2;
-	break;
-      }
-      break;
-    case 4:
-      switch (current_subframe) {
-      case 0:
+      case 1:
+        switch (current_subframe) {
+          case 9:
+          case 0:
+            ul_subframe = 7;
+            break;
+
+          case 5:
+          case 7:
+            ul_subframe = 2;
+            break;
+        }
+
+        break;
+
+      case 3:
+        switch (current_subframe) {
+          case 0:
+          case 5:
+          case 6:
+            ul_subframe = 2;
+            break;
+
+          case 7:
+            ul_subframe = 3;
+            break;
+
+          case 8:
+            ul_subframe = 4;
+            break;
+
+          case 9:
+            ul_subframe = 2;
+            break;
+        }
+
+        break;
+
+      case 4:
+        switch (current_subframe) {
+          case 0:
+          case 5:
+          case 6:
+          case 8:
+          case 9:
+            ul_subframe = 2;
+            break;
+
+          case 7:
+            ul_subframe = 3;
+            break;
+        }
+
+        break;
+
       case 5:
-      case 6:
-      case 8:
-      case 9:
-	ul_subframe = 2;
-	break;
-      case 7:
-	ul_subframe = 3;
-	break;
-      }
-      break;
-    case 5:
-      ul_subframe = 2;
-      break;
-    default:
-      LOG_E(PHY,
-	    "get_Msg3_harq_pid: Unsupported TDD configuration %d\n",
-	    (int) cc->tdd_Config->subframeAssignment);
-      AssertFatal(1 == 0,
-		  "get_Msg3_harq_pid: Unsupported TDD configuration");
-      break;
+        ul_subframe = 2;
+        break;
+
+      default:
+        LOG_E(PHY,
+              "get_Msg3_harq_pid: Unsupported TDD configuration %d\n",
+              (int) cc->tdd_Config->subframeAssignment);
+        AssertFatal(1 == 0,
+                    "get_Msg3_harq_pid: Unsupported TDD configuration");
+        break;
     }
   }
 
@@ -458,37 +448,35 @@ get_Msg3harqpid(COMMON_channels_t * cc,
 }
 
 uint32_t
-pdcchalloc2ulframe(COMMON_channels_t * ccP, uint32_t frame, uint8_t n)
-{
+pdcchalloc2ulframe(COMMON_channels_t *ccP, uint32_t frame, uint8_t n) {
   uint32_t ul_frame;
 
-  if ((ccP->tdd_Config) && (ccP->tdd_Config->subframeAssignment == 1) && ((n == 1) || (n == 6)))	// tdd_config 0,1 SF 1,5
+  if ((ccP->tdd_Config) && (ccP->tdd_Config->subframeAssignment == 1) && ((n == 1) || (n == 6)))  // tdd_config 0,1 SF 1,5
     ul_frame = (frame + (n == 1 ? 0 : 1));
   else if ((ccP->tdd_Config) &&
-	   (ccP->tdd_Config->subframeAssignment == 6) &&
-	   ((n == 0) || (n == 1) || (n == 5) || (n == 6)))
+           (ccP->tdd_Config->subframeAssignment == 6) &&
+           ((n == 0) || (n == 1) || (n == 5) || (n == 6)))
     ul_frame = (frame + (n >= 5 ? 1 : 0));
-  else if ((ccP->tdd_Config) && (ccP->tdd_Config->subframeAssignment == 6) && (n == 9))	// tdd_config 6 SF 9
+  else if ((ccP->tdd_Config) && (ccP->tdd_Config->subframeAssignment == 6) && (n == 9)) // tdd_config 6 SF 9
     ul_frame = (frame + 1);
   else
     ul_frame = (frame + (n >= 6 ? 1 : 0));
 
   LOG_D(PHY, "frame %d subframe %d: PUSCH frame = %d\n", frame, n,
-	ul_frame);
+        ul_frame);
   return ul_frame;
 }
 
-uint8_t pdcchalloc2ulsubframe(COMMON_channels_t * ccP, uint8_t n)
-{
+uint8_t pdcchalloc2ulsubframe(COMMON_channels_t *ccP, uint8_t n) {
   uint8_t ul_subframe;
 
-  if ((ccP->tdd_Config) && (ccP->tdd_Config->subframeAssignment == 1) && ((n == 1) || (n == 6)))	// tdd_config 0,1 SF 1,5
+  if ((ccP->tdd_Config) && (ccP->tdd_Config->subframeAssignment == 1) && ((n == 1) || (n == 6)))  // tdd_config 0,1 SF 1,5
     ul_subframe = ((n + 6) % 10);
   else if ((ccP->tdd_Config) &&
-	   (ccP->tdd_Config->subframeAssignment == 6) &&
-	   ((n == 0) || (n == 1) || (n == 5) || (n == 6)))
+           (ccP->tdd_Config->subframeAssignment == 6) &&
+           ((n == 0) || (n == 1) || (n == 5) || (n == 6)))
     ul_subframe = ((n + 7) % 10);
-  else if ((ccP->tdd_Config) && (ccP->tdd_Config->subframeAssignment == 6) && (n == 9))	// tdd_config 6 SF 9
+  else if ((ccP->tdd_Config) && (ccP->tdd_Config->subframeAssignment == 6) && (n == 9)) // tdd_config 6 SF 9
     ul_subframe = ((n + 5) % 10);
   else
     ul_subframe = ((n + 4) % 10);
@@ -497,116 +485,131 @@ uint8_t pdcchalloc2ulsubframe(COMMON_channels_t * ccP, uint8_t n)
   return ul_subframe;
 }
 
-int is_UL_sf(COMMON_channels_t * ccP, sub_frame_t subframeP)
-{
+int is_UL_sf(COMMON_channels_t *ccP, sub_frame_t subframeP) {
   // if FDD return dummy value
   if (ccP->tdd_Config == NULL)
     return (0);
 
   switch (ccP->tdd_Config->subframeAssignment) {
-  case 1:
-    switch (subframeP) {
-    case 0:
-    case 4:
-    case 5:
-    case 9:
-      return (0);
+    case 1:
+      switch (subframeP) {
+        case 0:
+        case 4:
+        case 5:
+        case 9:
+          return (0);
+          break;
+
+        case 2:
+        case 3:
+        case 7:
+        case 8:
+          return (1);
+          break;
+
+        default:
+          return (0);
+          break;
+      }
+
       break;
-    case 2:
+
     case 3:
-    case 7:
-    case 8:
-      return (1);
+      if ((subframeP <= 1) || (subframeP >= 5))
+        return (0);
+      else if ((subframeP > 1) && (subframeP < 5))
+        return (1);
+      else
+        AssertFatal(1 == 0, "Unknown subframe number\n");
+
       break;
+
+    case 4:
+      if ((subframeP <= 1) || (subframeP >= 4))
+        return (0);
+      else if ((subframeP > 1) && (subframeP < 4))
+        return (1);
+      else
+        AssertFatal(1 == 0, "Unknown subframe number\n");
+
+      break;
+
+    case 5:
+      if ((subframeP <= 1) || (subframeP >= 3))
+        return (0);
+      else if ((subframeP > 1) && (subframeP < 3))
+        return (1);
+      else
+        AssertFatal(1 == 0, "Unknown subframe number\n");
+
+      break;
+
     default:
-      return (0);
+      AssertFatal(1 == 0,
+                  "subframe %d Unsupported TDD configuration %d\n",
+                  subframeP, (int) ccP->tdd_Config->subframeAssignment);
       break;
-    }
-    break;
-  case 3:
-    if ((subframeP <= 1) || (subframeP >= 5))
-      return (0);
-    else if ((subframeP > 1) && (subframeP < 5))
-      return (1);
-    else
-      AssertFatal(1 == 0, "Unknown subframe number\n");
-    break;
-  case 4:
-    if ((subframeP <= 1) || (subframeP >= 4))
-      return (0);
-    else if ((subframeP > 1) && (subframeP < 4))
-      return (1);
-    else
-      AssertFatal(1 == 0, "Unknown subframe number\n");
-    break;
-  case 5:
-    if ((subframeP <= 1) || (subframeP >= 3))
-      return (0);
-    else if ((subframeP > 1) && (subframeP < 3))
-      return (1);
-    else
-      AssertFatal(1 == 0, "Unknown subframe number\n");
-    break;
-  default:
-    AssertFatal(1 == 0,
-		"subframe %d Unsupported TDD configuration %d\n",
-		subframeP, (int) ccP->tdd_Config->subframeAssignment);
-    break;
   }
 }
 
-int is_S_sf(COMMON_channels_t * ccP, sub_frame_t subframeP)
-{
-    // if FDD return dummy value
-    if (ccP->tdd_Config == NULL)
+int is_S_sf(COMMON_channels_t *ccP, sub_frame_t subframeP) {
+  // if FDD return dummy value
+  if (ccP->tdd_Config == NULL)
     return (0);
 
-    switch (subframeP) {
+  switch (subframeP) {
     case 1:
-        return (1);
-        break;
+      return (1);
+      break;
 
     case 6:
-        if(ccP->tdd_Config->subframeAssignment == 0 || ccP->tdd_Config->subframeAssignment == 1
-                || ccP->tdd_Config->subframeAssignment == 2 || ccP->tdd_Config->subframeAssignment == 6)
+      if(ccP->tdd_Config->subframeAssignment == 0 || ccP->tdd_Config->subframeAssignment == 1
+          || ccP->tdd_Config->subframeAssignment == 2 || ccP->tdd_Config->subframeAssignment == 6)
         return (1);
-        break;
+
+      break;
 
     default:
-        return (0);
-        break;
-    }
-    return 0;
+      return (0);
+      break;
+  }
+
+  return 0;
 }
 
-uint8_t ul_subframe2_k_phich(COMMON_channels_t * cc, sub_frame_t ul_subframe){
+uint8_t ul_subframe2_k_phich(COMMON_channels_t *cc, sub_frame_t ul_subframe) {
+  if(cc->tdd_Config) { //TODO fill other tdd config
+    switch(cc->tdd_Config->subframeAssignment) {
+      case 0:
+        break;
 
-    if(cc->tdd_Config){//TODO fill other tdd config
-        switch(cc->tdd_Config->subframeAssignment){
-        case 0:
-            break;
-        case 1:
-            if(ul_subframe == 2 || ul_subframe == 7)
-                return 4;
-            else if(ul_subframe == 3 || ul_subframe == 8)
-                return 6;
-            else return 255;
-            break;
-        case 2:
-            break;
-        case 3:
-            break;
-        case 4:
-            break;
-        case 5:
-            break;
-        }
+      case 1:
+        if(ul_subframe == 2 || ul_subframe == 7)
+          return 4;
+        else if(ul_subframe == 3 || ul_subframe == 8)
+          return 6;
+        else return 255;
+
+        break;
+
+      case 2:
+        break;
+
+      case 3:
+        break;
+
+      case 4:
+        break;
+
+      case 5:
+        break;
     }
-    return 4; //idk  sf_ahead?
+  }
+
+  return 4; //idk  sf_ahead?
 }
 
-uint16_t get_pucch1_absSF(COMMON_channels_t * cc, uint16_t dlsch_absSF)
-{
+uint16_t get_pucch1_absSF(COMMON_channels_t *cc, uint16_t dlsch_absSF) {
   uint16_t sf, f, nextf;
 
   if (cc->tdd_Config == NULL) { //FDD n+4
@@ -617,242 +620,267 @@ uint16_t get_pucch1_absSF(COMMON_channels_t * cc, uint16_t dlsch_absSF)
     nextf = (f + 1) & 1023;
 
     switch (cc->tdd_Config->subframeAssignment) {
-    case 0:
-      if ((sf == 0) || (sf == 5))
-        return ((10 * f) + sf + 4)% 10240;  // ACK/NAK in SF 4,9 same frame
-      else if (sf == 6)
-        return ((10 * nextf) + 2)% 10240;  // ACK/NAK in SF 2 next frame
-      else if (sf == 1)
-        return ((10 * f) + 7)% 10240;  // ACK/NAK in SF 7 same frame
-      else
-        AssertFatal(1 == 0,
-                   "Impossible dlsch subframe %d for TDD configuration 0\n",
-                   sf);
+      case 0:
+        if ((sf == 0) || (sf == 5))
+          return ((10 * f) + sf + 4)% 10240;  // ACK/NAK in SF 4,9 same frame
+        else if (sf == 6)
+          return ((10 * nextf) + 2)% 10240;  // ACK/NAK in SF 2 next frame
+        else if (sf == 1)
+          return ((10 * f) + 7)% 10240;  // ACK/NAK in SF 7 same frame
+        else
+          AssertFatal(1 == 0,
+                      "Impossible dlsch subframe %d for TDD configuration 0\n",
+                      sf);
 
-      break;
-    case 1:
-      if ((sf == 5) || (sf == 6))
-        return ((10 * nextf) + 2)% 10240;        // ACK/NAK in SF 2 next frame
-      else if (sf == 9)
-        return ((10 * nextf) + 3)% 10240;        // ACK/NAK in SF 3 next frame
-      else if ((sf == 0) || (sf == 1))
-        return ((10 * f) + 7)% 10240;        // ACK/NAK in SF 7 same frame
-      else if (sf == 4)
-        return ((10 * f) + 8)% 10240;  // ACK/NAK in SF 8 same frame
-      else
-        AssertFatal(1 == 0,
-                    "Impossible dlsch subframe %d for TDD configuration 1\n",
-                    sf);
-      break;
-    case 2:
-      if ((sf == 4) || (sf == 5) || (sf == 6) || (sf == 8))
-        return ((10 * nextf) + 2)% 10240;        // ACK/NAK in SF 2 next frame
-      else if (sf == 9)
-        return ((10 * nextf) + 7)% 10240;        // ACK/NAK in SF 7 next frame
-      else if ((sf == 0) || (sf == 1) || (sf == 3))
-        return ((10 * f) + 7)% 10240;        // ACK/NAK in SF 7 same frame
-      else
-        AssertFatal(1 == 0,
-                    "Impossible dlsch subframe %d for TDD configuration 2\n",
-                    sf);
-      break;
-    case 3:
-      if ((sf == 5) || (sf == 6) || (sf == 7) || (sf == 8)
-          || (sf == 9))
-        return ((10 * nextf) + ((sf-1) >> 1))% 10240;   // ACK/NAK in 2,3,4 resp. next frame
-      else if (sf == 1)
-        return ((10 * nextf) + 2)% 10240;         // ACK/NAK in 2 next frame
-      else if (sf == 0)
-        return ((10 * f) + 4)% 10240;        // ACK/NAK in 4 same frame
-      else
-        AssertFatal(1 == 0,
-                    "Impossible dlsch subframe %d for TDD configuration 3\n",
-                    sf);
-      break;
-    case 4:
-      if ((sf == 6) || (sf == 7) || (sf == 8) || (sf == 9))
-        return (((10 * nextf) + 3) % 10240);        // ACK/NAK in SF 3 next frame
-      else if ((sf == 0) || (sf == 1) || (sf == 4) || (sf == 5))
-        return (((10 * nextf) + 2) % 10240);        // ACK/NAK in SF 2 next frame
-      else
-        AssertFatal(1 == 0,
-                    "Impossible dlsch subframe %d for TDD configuration 4\n",
-                    sf);
-      break;
-    case 5:
-      if ((sf == 0) || (sf == 1) || (sf == 3) || (sf == 4)
-          || (sf == 5) || (sf == 6) || (sf == 7) || (sf == 8))
-        return (((10 * nextf) + 2) % 10240);        // ACK/NAK in SF 3 next frame
-      else if (sf == 9)
-        return (((10 * (1 + nextf)) + 2) % 10240);        // ACK/NAK in SF 2 next frame
-      else
-        AssertFatal(1 == 0,
-                    "Impossible dlsch subframe %d for TDD configuration 5\n",
-                    sf);
-      break;
-    case 6:
-      if ((sf == 5) || (sf == 6))
-        return ((10 * f) + sf + 7)% 10240;  // ACK/NAK in SF 2,3 next frame
-      else if (sf == 9)
-        return ((10 * nextf) + 4)% 10240;  // ACK/NAK in SF 4 next frame
-      else if ((sf == 1) || (sf == 0))
-        return ((10 * f) + sf + 7)% 10240;  // ACK/NAK in SF 7 same frame
-      else
-        AssertFatal(1 == 0,
-                "Impossible dlsch subframe %d for TDD configuration 6\n",
-                sf);
-      break;
-    default:
-      AssertFatal(1 == 0, "Illegal TDD subframe Assigment %d\n",
-                  (int) cc->tdd_Config->subframeAssignment);
-      break;
+        break;
+
+      case 1:
+        if ((sf == 5) || (sf == 6))
+          return ((10 * nextf) + 2)% 10240;        // ACK/NAK in SF 2 next frame
+        else if (sf == 9)
+          return ((10 * nextf) + 3)% 10240;        // ACK/NAK in SF 3 next frame
+        else if ((sf == 0) || (sf == 1))
+          return ((10 * f) + 7)% 10240;        // ACK/NAK in SF 7 same frame
+        else if (sf == 4)
+          return ((10 * f) + 8)% 10240;  // ACK/NAK in SF 8 same frame
+        else
+          AssertFatal(1 == 0,
+                      "Impossible dlsch subframe %d for TDD configuration 1\n",
+                      sf);
+
+        break;
+
+      case 2:
+        if ((sf == 4) || (sf == 5) || (sf == 6) || (sf == 8))
+          return ((10 * nextf) + 2)% 10240;        // ACK/NAK in SF 2 next frame
+        else if (sf == 9)
+          return ((10 * nextf) + 7)% 10240;        // ACK/NAK in SF 7 next frame
+        else if ((sf == 0) || (sf == 1) || (sf == 3))
+          return ((10 * f) + 7)% 10240;        // ACK/NAK in SF 7 same frame
+        else
+          AssertFatal(1 == 0,
+                      "Impossible dlsch subframe %d for TDD configuration 2\n",
+                      sf);
+
+        break;
+
+      case 3:
+        if ((sf == 5) || (sf == 6) || (sf == 7) || (sf == 8)
+            || (sf == 9))
+          return ((10 * nextf) + ((sf-1) >> 1))% 10240;   // ACK/NAK in 2,3,4 resp. next frame
+        else if (sf == 1)
+          return ((10 * nextf) + 2)% 10240;         // ACK/NAK in 2 next frame
+        else if (sf == 0)
+          return ((10 * f) + 4)% 10240;        // ACK/NAK in 4 same frame
+        else
+          AssertFatal(1 == 0,
+                      "Impossible dlsch subframe %d for TDD configuration 3\n",
+                      sf);
+
+        break;
+
+      case 4:
+        if ((sf == 6) || (sf == 7) || (sf == 8) || (sf == 9))
+          return (((10 * nextf) + 3) % 10240);        // ACK/NAK in SF 3 next frame
+        else if ((sf == 0) || (sf == 1) || (sf == 4) || (sf == 5))
+          return (((10 * nextf) + 2) % 10240);        // ACK/NAK in SF 2 next frame
+        else
+          AssertFatal(1 == 0,
+                      "Impossible dlsch subframe %d for TDD configuration 4\n",
+                      sf);
+
+        break;
+
+      case 5:
+        if ((sf == 0) || (sf == 1) || (sf == 3) || (sf == 4)
+            || (sf == 5) || (sf == 6) || (sf == 7) || (sf == 8))
+          return (((10 * nextf) + 2) % 10240);        // ACK/NAK in SF 3 next frame
+        else if (sf == 9)
+          return (((10 * (1 + nextf)) + 2) % 10240);        // ACK/NAK in SF 2 next frame
+        else
+          AssertFatal(1 == 0,
+                      "Impossible dlsch subframe %d for TDD configuration 5\n",
+                      sf);
+
+        break;
+
+      case 6:
+        if ((sf == 5) || (sf == 6))
+          return ((10 * f) + sf + 7)% 10240;  // ACK/NAK in SF 2,3 next frame
+        else if (sf == 9)
+          return ((10 * nextf) + 4)% 10240;  // ACK/NAK in SF 4 next frame
+        else if ((sf == 1) || (sf == 0))
+          return ((10 * f) + sf + 7)% 10240;  // ACK/NAK in SF 7 same frame
+        else
+          AssertFatal(1 == 0,
+                      "Impossible dlsch subframe %d for TDD configuration 6\n",
+                      sf);
+
+        break;
+
+      default:
+        AssertFatal(1 == 0, "Illegal TDD subframe Assigment %d\n",
+                    (int) cc->tdd_Config->subframeAssignment);
+        break;
     }
   }
+
   AssertFatal(1 == 0, "Shouldn't get here\n");
 }
 
 void
-get_srs_pos(COMMON_channels_t * cc, uint16_t isrs,
-	    uint16_t * psrsPeriodicity, uint16_t * psrsOffset)
-{
-  if (cc->tdd_Config) {	// TDD
+get_srs_pos(COMMON_channels_t *cc, uint16_t isrs,
+            uint16_t *psrsPeriodicity, uint16_t *psrsOffset) {
+  if (cc->tdd_Config) { // TDD
     AssertFatal(isrs >= 10, "2 ms SRS periodicity not supported");
 
     if ((isrs > 9) && (isrs < 15)) {
       *psrsPeriodicity = 5;
       *psrsOffset = isrs - 10;
     }
+
     if ((isrs > 14) && (isrs < 25)) {
       *psrsPeriodicity = 10;
       *psrsOffset = isrs - 15;
     }
+
     if ((isrs > 24) && (isrs < 45)) {
       *psrsPeriodicity = 20;
       *psrsOffset = isrs - 25;
     }
+
     if ((isrs > 44) && (isrs < 85)) {
       *psrsPeriodicity = 40;
       *psrsOffset = isrs - 45;
     }
+
     if ((isrs > 84) && (isrs < 165)) {
       *psrsPeriodicity = 80;
       *psrsOffset = isrs - 85;
     }
+
     if ((isrs > 164) && (isrs < 325)) {
       *psrsPeriodicity = 160;
       *psrsOffset = isrs - 165;
     }
+
     if ((isrs > 324) && (isrs < 645)) {
       *psrsPeriodicity = 320;
       *psrsOffset = isrs - 325;
     }
 
     AssertFatal(isrs <= 644, "Isrs out of range %d>644\n", isrs);
-  }				// TDD
-  else {			// FDD
+  }       // TDD
+  else {      // FDD
     if (isrs < 2) {
       *psrsPeriodicity = 2;
       *psrsOffset = isrs;
     }
+
     if ((isrs > 1) && (isrs < 7)) {
       *psrsPeriodicity = 5;
       *psrsOffset = isrs - 2;
     }
+
     if ((isrs > 6) && (isrs < 17)) {
       *psrsPeriodicity = 10;
       *psrsOffset = isrs - 7;
     }
+
     if ((isrs > 16) && (isrs < 37)) {
       *psrsPeriodicity = 20;
       *psrsOffset = isrs - 17;
     }
+
     if ((isrs > 36) && (isrs < 77)) {
       *psrsPeriodicity = 40;
       *psrsOffset = isrs - 37;
     }
+
     if ((isrs > 76) && (isrs < 157)) {
       *psrsPeriodicity = 80;
       *psrsOffset = isrs - 77;
     }
+
     if ((isrs > 156) && (isrs < 317)) {
       *psrsPeriodicity = 160;
       *psrsOffset = isrs - 157;
     }
+
     if ((isrs > 316) && (isrs < 637)) {
       *psrsPeriodicity = 320;
       *psrsOffset = isrs - 317;
     }
+
     AssertFatal(isrs <= 636, "Isrs out of range %d>636\n", isrs);
   }
 }
 
 void
-get_csi_params(COMMON_channels_t * cc,
-	       struct CQI_ReportPeriodic *cqi_ReportPeriodic,
-	       uint16_t * Npd, uint16_t * N_OFFSET_CQI, int *H)
-{
+get_csi_params(COMMON_channels_t *cc,
+               struct LTE_CQI_ReportPeriodic *cqi_ReportPeriodic,
+               uint16_t *Npd, uint16_t *N_OFFSET_CQI, int *H) {
+  AssertFatal(cqi_ReportPeriodic != NULL,
+              "cqi_ReportPeriodic is null!\n");
+
   uint16_t cqi_PMI_ConfigIndex =
     cqi_ReportPeriodic->choice.setup.cqi_pmi_ConfigIndex;
   uint8_t Jtab[6] = { 0, 2, 2, 3, 4, 4 };
 
-  AssertFatal(cqi_ReportPeriodic != NULL,
-	      "cqi_ReportPeriodic is null!\n");
-
-  if (cc->tdd_Config == NULL) {	//FDD
-    if (cqi_PMI_ConfigIndex <= 1) {	// 2 ms CQI_PMI period
+  if (cc->tdd_Config == NULL) { //FDD
+    if (cqi_PMI_ConfigIndex <= 1) { // 2 ms CQI_PMI period
       *Npd = 2;
       *N_OFFSET_CQI = cqi_PMI_ConfigIndex;
-    } else if (cqi_PMI_ConfigIndex <= 6) {	// 5 ms CQI_PMI period
+    } else if (cqi_PMI_ConfigIndex <= 6) {  // 5 ms CQI_PMI period
       *Npd = 5;
       *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 2;
-    } else if (cqi_PMI_ConfigIndex <= 16) {	// 10ms CQI_PMI period
+    } else if (cqi_PMI_ConfigIndex <= 16) { // 10ms CQI_PMI period
       *Npd = 10;
       *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 7;
-    } else if (cqi_PMI_ConfigIndex <= 36) {	// 20 ms CQI_PMI period
+    } else if (cqi_PMI_ConfigIndex <= 36) { // 20 ms CQI_PMI period
       *Npd = 20;
       *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 17;
-    } else if (cqi_PMI_ConfigIndex <= 76) {	// 40 ms CQI_PMI period
+    } else if (cqi_PMI_ConfigIndex <= 76) { // 40 ms CQI_PMI period
       *Npd = 40;
       *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 37;
-    } else if (cqi_PMI_ConfigIndex <= 156) {	// 80 ms CQI_PMI period
+    } else if (cqi_PMI_ConfigIndex <= 156) {  // 80 ms CQI_PMI period
       *Npd = 80;
       *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 77;
-    } else if (cqi_PMI_ConfigIndex <= 316) {	// 160 ms CQI_PMI period
+    } else if (cqi_PMI_ConfigIndex <= 316) {  // 160 ms CQI_PMI period
       *Npd = 160;
       *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 157;
     } else if (cqi_PMI_ConfigIndex > 317) {
-
-      if (cqi_PMI_ConfigIndex <= 349) {	// 32 ms CQI_PMI period
-	*Npd = 32;
-	*N_OFFSET_CQI = cqi_PMI_ConfigIndex - 318;
-      } else if (cqi_PMI_ConfigIndex <= 413) {	// 64 ms CQI_PMI period
-	*Npd = 64;
-	*N_OFFSET_CQI = cqi_PMI_ConfigIndex - 350;
-      } else if (cqi_PMI_ConfigIndex <= 541) {	// 128 ms CQI_PMI period
-	*Npd = 128;
-	*N_OFFSET_CQI = cqi_PMI_ConfigIndex - 414;
+      if (cqi_PMI_ConfigIndex <= 349) { // 32 ms CQI_PMI period
+        *Npd = 32;
+        *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 318;
+      } else if (cqi_PMI_ConfigIndex <= 413) {  // 64 ms CQI_PMI period
+        *Npd = 64;
+        *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 350;
+      } else if (cqi_PMI_ConfigIndex <= 541) {  // 128 ms CQI_PMI period
+        *Npd = 128;
+        *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 414;
       }
     }
-  } else {			// TDD
-    if (cqi_PMI_ConfigIndex == 0) {	// all UL subframes
+  } else {      // TDD
+    if (cqi_PMI_ConfigIndex == 0) { // all UL subframes
       *Npd = 1;
       *N_OFFSET_CQI = 0;
-    } else if (cqi_PMI_ConfigIndex <= 6) {	// 5 ms CQI_PMI period
+    } else if (cqi_PMI_ConfigIndex <= 6) {  // 5 ms CQI_PMI period
       *Npd = 5;
       *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 1;
-    } else if (cqi_PMI_ConfigIndex <= 16) {	// 10ms CQI_PMI period
+    } else if (cqi_PMI_ConfigIndex <= 16) { // 10ms CQI_PMI period
       *Npd = 10;
       *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 6;
-    } else if (cqi_PMI_ConfigIndex <= 36) {	// 20 ms CQI_PMI period
+    } else if (cqi_PMI_ConfigIndex <= 36) { // 20 ms CQI_PMI period
       *Npd = 20;
       *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 16;
-    } else if (cqi_PMI_ConfigIndex <= 76) {	// 40 ms CQI_PMI period
+    } else if (cqi_PMI_ConfigIndex <= 76) { // 40 ms CQI_PMI period
       *Npd = 40;
       *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 36;
-    } else if (cqi_PMI_ConfigIndex <= 156) {	// 80 ms CQI_PMI period
+    } else if (cqi_PMI_ConfigIndex <= 156) {  // 80 ms CQI_PMI period
       *Npd = 80;
       *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 76;
-    } else if (cqi_PMI_ConfigIndex <= 316) {	// 160 ms CQI_PMI period
+    } else if (cqi_PMI_ConfigIndex <= 316) {  // 160 ms CQI_PMI period
       *Npd = 160;
       *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 156;
     }
@@ -861,178 +889,194 @@ get_csi_params(COMMON_channels_t * cc,
   // get H
   if (cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.
       present ==
-      CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_subbandCQI)
+      LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_subbandCQI)
     *H = 1 +
-      (Jtab[cc->mib->message.dl_Bandwidth] *
-       cqi_ReportPeriodic->choice.setup.
-       cqi_FormatIndicatorPeriodic.choice.subbandCQI.k);
+         (Jtab[cc->mib->message.dl_Bandwidth] *
+          cqi_ReportPeriodic->choice.setup.
+          cqi_FormatIndicatorPeriodic.choice.subbandCQI.k);
   else
     *H = 1;
 }
 
 uint8_t
-get_dl_cqi_pmi_size_pusch(COMMON_channels_t * cc, uint8_t tmode,
-			  uint8_t ri,
-			  CQI_ReportModeAperiodic_t *
-			  cqi_ReportModeAperiodic)
-{
+get_dl_cqi_pmi_size_pusch(COMMON_channels_t *cc, uint8_t tmode,
+                          uint8_t ri,
+                          LTE_CQI_ReportModeAperiodic_t *
+                          cqi_ReportModeAperiodic) {
   int Ntab[6] = { 0, 4, 7, 9, 10, 13 };
   int N = Ntab[cc->mib->message.dl_Bandwidth];
   int Ltab_uesel[6] = { 0, 6, 9, 13, 15, 18 };
   int L = Ltab_uesel[cc->mib->message.dl_Bandwidth];
-
   AssertFatal(cqi_ReportModeAperiodic != NULL,
-	      "cqi_ReportPeriodic is null!\n");
+              "cqi_ReportPeriodic is null!\n");
 
   switch (*cqi_ReportModeAperiodic) {
-  case CQI_ReportModeAperiodic_rm12:
-    AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9
-		|| tmode == 10,
-		"Illegal TM (%d) for CQI_ReportModeAperiodic_rm12\n",
-		tmode);
-    AssertFatal(cc->p_eNB <= 4,
-		"only up to 4 antenna ports supported here\n");
-    if (ri == 1 && cc->p_eNB == 2)
+    case LTE_CQI_ReportModeAperiodic_rm12:
+      AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9
+                  || tmode == 10,
+                  "Illegal TM (%d) for CQI_ReportModeAperiodic_rm12\n",
+                  tmode);
+      AssertFatal(cc->p_eNB <= 4,
+                  "only up to 4 antenna ports supported here\n");
+
+      if (ri == 1 && cc->p_eNB == 2)
+        return (4 + (N << 1));
+      else if (ri == 2 && cc->p_eNB == 2)
+        return (8 + N);
+      else if (ri == 1 && cc->p_eNB == 4)
+        return (4 + (N << 2));
+      else if (ri > 1 && cc->p_eNB == 4)
+        return (8 + (N << 2));
+
+      break;
+
+    case LTE_CQI_ReportModeAperiodic_rm20:
+      // Table 5.2.2.6.3-1 (36.212)
+      AssertFatal(tmode == 1 || tmode == 2 || tmode == 3 || tmode == 7
+                  || tmode == 9
+                  || tmode == 10,
+                  "Illegal TM (%d) for CQI_ReportModeAperiodic_rm20\n",
+                  tmode);
+      AssertFatal(tmode != 9
+                  && tmode != 10,
+                  "TM9/10 will be handled later for CQI_ReportModeAperiodic_rm20\n");
+      return (4 + 2 + L);
+      break;
+
+    case LTE_CQI_ReportModeAperiodic_rm22:
+      // Table 5.2.2.6.3-2 (36.212)
+      AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9
+                  || tmode == 10,
+                  "Illegal TM (%d) for CQI_ReportModeAperiodic_rm22\n",
+                  tmode);
+      AssertFatal(tmode != 9
+                  && tmode != 10,
+                  "TM9/10 will be handled later for CQI_ReportModeAperiodic_rm22\n");
+
+      if (ri == 1 && cc->p_eNB == 2)
+        return (4 + 2 + 0 + 0 + L + 4);
+
+      if (ri == 2 && cc->p_eNB == 2)
+        return (4 + 2 + 4 + 2 + L + 2);
+
+      if (ri == 1 && cc->p_eNB == 4)
+        return (4 + 2 + 0 + 0 + L + 8);
+
+      if (ri >= 2 && cc->p_eNB == 4)
+        return (4 + 2 + 4 + 2 + L + 8);
+
+      break;
+
+    case LTE_CQI_ReportModeAperiodic_rm30:
+      // Table 5.2.2.6.2-1 (36.212)
+      AssertFatal(tmode == 1 || tmode == 2 || tmode == 3 || tmode == 7
+                  || tmode == 8 || tmode == 9
+                  || tmode == 10,
+                  "Illegal TM (%d) for CQI_ReportModeAperiodic_rm30\n",
+                  tmode);
+      AssertFatal(tmode != 8 && tmode != 9
+                  && tmode != 10,
+                  "TM8/9/10 will be handled later for CQI_ReportModeAperiodic_rm30\n");
       return (4 + (N << 1));
-    else if (ri == 2 && cc->p_eNB == 2)
-      return (8 + N);
-    else if (ri == 1 && cc->p_eNB == 4)
-      return (4 + (N << 2));
-    else if (ri > 1 && cc->p_eNB == 4)
-      return (8 + (N << 2));
-    break;
-  case CQI_ReportModeAperiodic_rm20:
-    // Table 5.2.2.6.3-1 (36.212)
-    AssertFatal(tmode == 1 || tmode == 2 || tmode == 3 || tmode == 7
-		|| tmode == 9
-		|| tmode == 10,
-		"Illegal TM (%d) for CQI_ReportModeAperiodic_rm20\n",
-		tmode);
-    AssertFatal(tmode != 9
-		&& tmode != 10,
-		"TM9/10 will be handled later for CQI_ReportModeAperiodic_rm20\n");
-    return (4 + 2 + L);
-    break;
-  case CQI_ReportModeAperiodic_rm22:
-    // Table 5.2.2.6.3-2 (36.212)
-    AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9
-		|| tmode == 10,
-		"Illegal TM (%d) for CQI_ReportModeAperiodic_rm22\n",
-		tmode);
-    AssertFatal(tmode != 9
-		&& tmode != 10,
-		"TM9/10 will be handled later for CQI_ReportModeAperiodic_rm22\n");
-    if (ri == 1 && cc->p_eNB == 2)
-      return (4 + 2 + 0 + 0 + L + 4);
-    if (ri == 2 && cc->p_eNB == 2)
-      return (4 + 2 + 4 + 2 + L + 2);
-    if (ri == 1 && cc->p_eNB == 4)
-      return (4 + 2 + 0 + 0 + L + 8);
-    if (ri >= 2 && cc->p_eNB == 4)
-      return (4 + 2 + 4 + 2 + L + 8);
-    break;
-  case CQI_ReportModeAperiodic_rm30:
-    // Table 5.2.2.6.2-1 (36.212)
-    AssertFatal(tmode == 1 || tmode == 2 || tmode == 3 || tmode == 7
-		|| tmode == 8 || tmode == 9
-		|| tmode == 10,
-		"Illegal TM (%d) for CQI_ReportModeAperiodic_rm30\n",
-		tmode);
-    AssertFatal(tmode != 8 && tmode != 9
-		&& tmode != 10,
-		"TM8/9/10 will be handled later for CQI_ReportModeAperiodic_rm30\n");
-    return (4 + (N << 1));
-    break;
-  case CQI_ReportModeAperiodic_rm31:
-    // Table 5.2.2.6.2-2 (36.212)
-    AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9
-		|| tmode == 10,
-		"Illegal TM (%d) for CQI_ReportModeAperiodic_rm31\n",
-		tmode);
-    AssertFatal(tmode != 8 && tmode != 9
-		&& tmode != 10,
-		"TM8/9/10 will be handled later for CQI_ReportModeAperiodic_rm31\n");
-    if (ri == 1 && cc->p_eNB == 2)
-      return (4 + (N << 1) + 0 + 0 + 2);
-    else if (ri == 2 && cc->p_eNB == 2)
-      return (4 + (N << 1) + 4 + (N << 1) + 1);
-    else if (ri == 1 && cc->p_eNB == 4)
-      return (4 + (N << 1) + 0 + 0 + 4);
-    else if (ri >= 2 && cc->p_eNB == 4)
-      return (4 + (N << 1) + 4 + (N << 1) + 4);
-    break;
-#if (RRC_VERSION >= MAKE_VERSION(12, 5, 0))
-  case CQI_ReportModeAperiodic_rm32_v1250:
-    AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9
-		|| tmode == 10,
-		"Illegal TM (%d) for CQI_ReportModeAperiodic_rm32\n",
-		tmode);
-    AssertFatal(1 == 0,
-		"CQI_ReportModeAperiodic_rm32_v1250 not supported yet\n");
-    break;
-  case CQI_ReportModeAperiodic_rm10_v1310:
-    // Table 5.2.2.6.1-1F/G (36.212)
-    if (ri == 1)
-      return (4);		// F
-    else
-      return (7);		// G
-    break;
-  case CQI_ReportModeAperiodic_rm11_v1310:
-    // Table 5.2.2.6.1-1H (36.212)
-    AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9
-		|| tmode == 10,
-		"Illegal TM (%d) for CQI_ReportModeAperiodic_rm11\n",
-		tmode);
-    AssertFatal(cc->p_eNB <= 4,
-		"only up to 4 antenna ports supported here\n");
-    if (ri == 1 && cc->p_eNB == 2)
-      return (4 + 0 + 2);
-    else if (ri == 2 && cc->p_eNB == 2)
-      return (4 + 4 + 1);
-    else if (ri == 1 && cc->p_eNB == 4)
-      return (4 + 0 + 4);
-    else if (ri > 1 && cc->p_eNB == 4)
-      return (4 + 4 + 4);
-
-    break;
-#endif /* #if (RRC_VERSION >= MAKE_VERSION(12, 5, 0)) */
+      break;
+
+    case LTE_CQI_ReportModeAperiodic_rm31:
+      // Table 5.2.2.6.2-2 (36.212)
+      AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9
+                  || tmode == 10,
+                  "Illegal TM (%d) for CQI_ReportModeAperiodic_rm31\n",
+                  tmode);
+      AssertFatal(tmode != 8 && tmode != 9
+                  && tmode != 10,
+                  "TM8/9/10 will be handled later for CQI_ReportModeAperiodic_rm31\n");
+
+      if (ri == 1 && cc->p_eNB == 2)
+        return (4 + (N << 1) + 0 + 0 + 2);
+      else if (ri == 2 && cc->p_eNB == 2)
+        return (4 + (N << 1) + 4 + (N << 1) + 1);
+      else if (ri == 1 && cc->p_eNB == 4)
+        return (4 + (N << 1) + 0 + 0 + 4);
+      else if (ri >= 2 && cc->p_eNB == 4)
+        return (4 + (N << 1) + 4 + (N << 1) + 4);
+
+      break;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(12, 5, 0))
+
+    case LTE_CQI_ReportModeAperiodic_rm32_v1250:
+      AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9
+                  || tmode == 10,
+                  "Illegal TM (%d) for CQI_ReportModeAperiodic_rm32\n",
+                  tmode);
+      AssertFatal(1 == 0,
+                  "CQI_ReportModeAperiodic_rm32_v1250 not supported yet\n");
+      break;
+
+    case LTE_CQI_ReportModeAperiodic_rm10_v1310:
+
+      // Table 5.2.2.6.1-1F/G (36.212)
+      if (ri == 1)
+        return (4);   // F
+      else
+        return (7);   // G
+
+      break;
+
+    case LTE_CQI_ReportModeAperiodic_rm11_v1310:
+      // Table 5.2.2.6.1-1H (36.212)
+      AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9
+                  || tmode == 10,
+                  "Illegal TM (%d) for CQI_ReportModeAperiodic_rm11\n",
+                  tmode);
+      AssertFatal(cc->p_eNB <= 4,
+                  "only up to 4 antenna ports supported here\n");
+
+      if (ri == 1 && cc->p_eNB == 2)
+        return (4 + 0 + 2);
+      else if (ri == 2 && cc->p_eNB == 2)
+        return (4 + 4 + 1);
+      else if (ri == 1 && cc->p_eNB == 4)
+        return (4 + 0 + 4);
+      else if (ri > 1 && cc->p_eNB == 4)
+        return (4 + 4 + 4);
+
+      break;
+#endif /* #if (LTE_RRC_VERSION >= MAKE_VERSION(12, 5, 0)) */
   }
+
   AssertFatal(1 == 0, "Shouldn't get here\n");
   return (0);
 }
 
 uint8_t
-get_rel8_dl_cqi_pmi_size(UE_sched_ctrl * sched_ctl, int CC_idP,
-			 COMMON_channels_t * cc, uint8_t tmode,
-			 struct CQI_ReportPeriodic * cqi_ReportPeriodic)
-{
+get_rel8_dl_cqi_pmi_size(UE_sched_ctrl *sched_ctl, int CC_idP,
+                         COMMON_channels_t *cc, uint8_t tmode,
+                         struct LTE_CQI_ReportPeriodic *cqi_ReportPeriodic) {
   int no_pmi = 0;
   //    Ltab[6] = {0,log2(15/4/2),log2(25/4/2),log2(50/6/3),log2(75/8/4),log2(100/8/4)};
-
   uint8_t Ltab[6] = { 0, 1, 2, 2, 2, 2 };
   uint8_t ri = sched_ctl->periodic_ri_received[CC_idP];
-
   AssertFatal(cqi_ReportPeriodic != NULL,
-	      "cqi_ReportPeriodic is null!\n");
-  AssertFatal(cqi_ReportPeriodic->present != CQI_ReportPeriodic_PR_NOTHING,
-	      "cqi_ReportPeriodic->present == CQI_ReportPeriodic_PR_NOTHING!\n");
+              "cqi_ReportPeriodic is null!\n");
+  AssertFatal(cqi_ReportPeriodic->present != LTE_CQI_ReportPeriodic_PR_NOTHING,
+              "cqi_ReportPeriodic->present == CQI_ReportPeriodic_PR_NOTHING!\n");
   AssertFatal(cqi_ReportPeriodic->choice.
-	      setup.cqi_FormatIndicatorPeriodic.present != CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_NOTHING,
-	      "cqi_ReportPeriodic->cqi_FormatIndicatorPeriodic.choice.setup.present == CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_NOTHING!\n");
+              setup.cqi_FormatIndicatorPeriodic.present != LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_NOTHING,
+              "cqi_ReportPeriodic->cqi_FormatIndicatorPeriodic.choice.setup.present == CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_NOTHING!\n");
 
   switch (tmode) {
-  case 1:
-  case 2:
-  case 5:
-  case 6:
-  case 7:
-    no_pmi = 1;
-    break;
-  default:
-    no_pmi = 0;
+    case 1:
+    case 2:
+    case 5:
+    case 6:
+    case 7:
+      no_pmi = 1;
+      break;
+
+    default:
+      no_pmi = 0;
   }
 
-  if ((cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present == CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_widebandCQI)
+  if ((cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present == LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_widebandCQI)
       || (sched_ctl->feedback_cnt[CC_idP] == 0)) {
     // send wideband report every opportunity if wideband reporting mode is selected, else every H opportunities
     if (no_pmi == 1)                        return (4);
@@ -1042,35 +1086,34 @@ get_rel8_dl_cqi_pmi_size(UE_sched_ctrl * sched_ctl, int CC_idP,
     else if ((cc->p_eNB == 4) && (ri == 2)) return (11);
     else
       AssertFatal(1 == 0,
-		  "illegal combination p %d, ri %d, no_pmi %d\n",
-		  cc->p_eNB, ri, no_pmi);
-  } else if (cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present == CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_subbandCQI) {
+                  "illegal combination p %d, ri %d, no_pmi %d\n",
+                  cc->p_eNB, ri, no_pmi);
+  } else if (cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present == LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_subbandCQI) {
     if ((no_pmi == 1) || ri == 1) return (4 + Ltab[cc->mib->message.dl_Bandwidth]);
     else                          return (7 + Ltab[cc->mib->message.dl_Bandwidth]);
   }
 
   AssertFatal(1 == 0,
-	      "Shouldn't get here : cqi_ReportPeriodic->present %d\n",
-	      cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present);
+              "Shouldn't get here : cqi_ReportPeriodic->present %d\n",
+              cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present);
 }
 
 
 
 void
 fill_nfapi_dl_dci_1A(nfapi_dl_config_request_pdu_t *dl_config_pdu,
-		     uint8_t                       aggregation_level,
-		     uint16_t                      rnti,
-		     uint8_t                       rnti_type,
-		     uint8_t                       harq_process,
-		     uint8_t                       tpc,
-		     uint16_t                      resource_block_coding,
-		     uint8_t                       mcs, 
-		     uint8_t                       ndi, 
-		     uint8_t                       rv,
-		     uint8_t                       vrb_flag)
-{
+                     uint8_t                       aggregation_level,
+                     uint16_t                      rnti,
+                     uint8_t                       rnti_type,
+                     uint8_t                       harq_process,
+                     uint8_t                       tpc,
+                     uint16_t                      resource_block_coding,
+                     uint8_t                       mcs,
+                     uint8_t                       ndi,
+                     uint8_t                       rv,
+                     uint8_t                       vrb_flag) {
   memset((void *) dl_config_pdu, 0,
-	 sizeof(nfapi_dl_config_request_pdu_t));
+         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.tl.tag                                 = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL8_TAG;
@@ -1078,7 +1121,7 @@ fill_nfapi_dl_dci_1A(nfapi_dl_config_request_pdu_t *dl_config_pdu,
   dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level                      = aggregation_level;
   dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti                                   = rnti;
   dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type                              = rnti_type;
-  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.transmission_power                     = 6000;  // equal to RS power
   dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.harq_process                           = harq_process;
   dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tpc                                    = tpc;
   dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.resource_block_coding                  = resource_block_coding;
@@ -1090,9 +1133,8 @@ fill_nfapi_dl_dci_1A(nfapi_dl_config_request_pdu_t *dl_config_pdu,
 
 void
 program_dlsch_acknak(module_id_t module_idP, int CC_idP, int UE_idP,
-		     frame_t frameP, sub_frame_t subframeP,
-		     uint8_t cce_idx)
-{
+                     frame_t frameP, sub_frame_t subframeP,
+                     uint8_t cce_idx) {
   eNB_MAC_INST                           *eNB                         = RC.mac[module_idP];
   COMMON_channels_t                      *cc                          = eNB->common_channels;
   UE_list_t                              *UE_list                     = &eNB->UE_list;
@@ -1102,16 +1144,15 @@ program_dlsch_acknak(module_id_t module_idP, int CC_idP, int UE_idP,
   int                                    use_simultaneous_pucch_pusch = 0;
   nfapi_ul_config_ulsch_harq_information *ulsch_harq_information      = NULL;
   nfapi_ul_config_harq_information       *harq_information            = NULL;
-
-#if (RRC_VERSION >= MAKE_VERSION(10, 2, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 2, 0))
 
   if ((UE_list->UE_template[CC_idP][UE_idP].physicalConfigDedicated->ext2)
       && (UE_list->UE_template[CC_idP][UE_idP].physicalConfigDedicated->ext2->pucch_ConfigDedicated_v1020)
       && (UE_list->UE_template[CC_idP][UE_idP].physicalConfigDedicated->ext2->pucch_ConfigDedicated_v1020->simultaneousPUCCH_PUSCH_r10)
-      && (*UE_list->UE_template[CC_idP][UE_idP].physicalConfigDedicated->ext2->pucch_ConfigDedicated_v1020->simultaneousPUCCH_PUSCH_r10 == PUCCH_ConfigDedicated_v1020__simultaneousPUCCH_PUSCH_r10_true))
+      && (*UE_list->UE_template[CC_idP][UE_idP].physicalConfigDedicated->ext2->pucch_ConfigDedicated_v1020->simultaneousPUCCH_PUSCH_r10 == LTE_PUCCH_ConfigDedicated_v1020__simultaneousPUCCH_PUSCH_r10_true))
     use_simultaneous_pucch_pusch = 1;
-#endif
 
+#endif
   // pucch1 and pusch feedback is similar, namely in n+k subframes from now
   // This is used in the following "if/else" condition to check if there isn't or is already an UL grant in n+k
   int16_t ul_absSF = get_pucch1_absSF(&cc[CC_idP], subframeP + (10 * frameP));
@@ -1119,219 +1160,230 @@ program_dlsch_acknak(module_id_t module_idP, int CC_idP, int UE_idP,
   if ((ul_config_pdu = has_ul_grant(module_idP, CC_idP,ul_absSF, rnti)) == NULL) {
     // no UL grant so
     // Program ACK/NAK alone Format 1a/b or 3
-
     ul_req        = &RC.mac[module_idP]->UL_req_tmp[CC_idP][ul_absSF %10].ul_config_request_body;
     ul_config_pdu = &ul_req->ul_config_pdu_list[ul_req->number_of_pdus];
     // Do PUCCH
     fill_nfapi_uci_acknak(module_idP,
-			  CC_idP,
-			  rnti, (frameP * 10) + subframeP, cce_idx);
+                          CC_idP,
+                          rnti, (frameP * 10) + subframeP, cce_idx);
   } else {
     /* there is already an existing UL grant so update it if needed
      * on top of some other UL resource (PUSCH,combined SR/CQI/HARQ on PUCCH, etc)
      */
     switch (ul_config_pdu->pdu_type) {
-      
       /* [ulsch] to [ulsch + harq] or [ulsch + harq on pucch] */
-      
-    case NFAPI_UL_CONFIG_ULSCH_PDU_TYPE:
-      if (use_simultaneous_pucch_pusch == 1) {
-	// Convert it to an NFAPI_UL_CONFIG_ULSCH_UCI_HARQ_PDU_TYPE
-	harq_information        = &ul_config_pdu->ulsch_uci_harq_pdu.harq_information;
-	ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_ULSCH_UCI_HARQ_PDU_TYPE;
-	LOG_D(MAC,
-	      "Frame %d, Subframe %d: Switched UCI HARQ to ULSCH UCI HARQ\n",
-	      frameP, subframeP);
-      } else {
-	// Convert it to an NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE
-	ulsch_harq_information                                                                                                               = &ul_config_pdu->ulsch_harq_pdu.harq_information;
-	ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE;
-	ul_config_pdu->ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag                            = NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG;
-	ul_config_pdu->ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial                     = 0;	// last symbol not punctured
-	ul_config_pdu->ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks = ul_config_pdu->ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.number_of_resource_blocks;	// we don't change the number of resource blocks across retransmissions yet
-	LOG_D(MAC,
-	      "Frame %d, Subframe %d: Switched UCI HARQ to ULSCH HARQ\n",
-	      frameP, subframeP);
-      }
-      break;
-    case NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE:
-      AssertFatal(use_simultaneous_pucch_pusch == 0,
-		  "Cannot be NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE, simultaneous_pucch_pusch is active");
-      break;
-    case NFAPI_UL_CONFIG_ULSCH_UCI_HARQ_PDU_TYPE:
-      AssertFatal(use_simultaneous_pucch_pusch == 1,
-		  "Cannot be NFAPI_UL_CONFIG_ULSCH_UCI_PDU_TYPE, simultaneous_pucch_pusch is inactive\n");
-      break;
+      case NFAPI_UL_CONFIG_ULSCH_PDU_TYPE:
+        if (use_simultaneous_pucch_pusch == 1) {
+          // Convert it to an NFAPI_UL_CONFIG_ULSCH_UCI_HARQ_PDU_TYPE
+          harq_information        = &ul_config_pdu->ulsch_uci_harq_pdu.harq_information;
+          ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_ULSCH_UCI_HARQ_PDU_TYPE;
+          LOG_D(MAC,
+                "Frame %d, Subframe %d: Switched UCI HARQ to ULSCH UCI HARQ\n",
+                frameP, subframeP);
+        } else {
+          // Convert it to an NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE
+          ulsch_harq_information                                                                                                               = &ul_config_pdu->ulsch_harq_pdu.harq_information;
+          ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE;
+          ul_config_pdu->ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag                            = NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG;
+          ul_config_pdu->ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial                     = 0; // last symbol not punctured
+          ul_config_pdu->ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks =
+            ul_config_pdu->ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.number_of_resource_blocks;  // we don't change the number of resource blocks across retransmissions yet
+          LOG_D(MAC,
+                "Frame %d, Subframe %d: Switched UCI HARQ to ULSCH HARQ\n",
+                frameP, subframeP);
+        }
+
+        break;
+
+      case NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE:
+        AssertFatal(use_simultaneous_pucch_pusch == 0,
+                    "Cannot be NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE, simultaneous_pucch_pusch is active");
+        break;
+
+      case NFAPI_UL_CONFIG_ULSCH_UCI_HARQ_PDU_TYPE:
+        AssertFatal(use_simultaneous_pucch_pusch == 1,
+                    "Cannot be NFAPI_UL_CONFIG_ULSCH_UCI_PDU_TYPE, simultaneous_pucch_pusch is inactive\n");
+        break;
 
       /* [ulsch + cqi] to [ulsch + cqi + harq] */
 
-    case NFAPI_UL_CONFIG_ULSCH_CQI_RI_PDU_TYPE:
-      // Convert it to an NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE
-      ulsch_harq_information  = &ul_config_pdu->ulsch_cqi_harq_ri_pdu.harq_information;
-      ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE;
-      /* TODO: check this - when converting from nfapi_ul_config_ulsch_cqi_ri_pdu to
-       * nfapi_ul_config_ulsch_cqi_harq_ri_pdu, shouldn't we copy initial_transmission_parameters
-       * from the one to the other?
-       * Those two types are not compatible. 'initial_transmission_parameters' is not at the
-       * place in both.
-       */
-      ul_config_pdu->ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag                            = NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG;
-      ul_config_pdu->ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial                     = 0;	// last symbol not punctured
-      ul_config_pdu->ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks = ul_config_pdu->ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.number_of_resource_blocks;	// we don't change the number of resource blocks across retransmissions yet
-      break;
-    case NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE:
-      AssertFatal(use_simultaneous_pucch_pusch == 0,
-		  "Cannot be NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE, simultaneous_pucch_pusch is active\n");
-      break;
+      case NFAPI_UL_CONFIG_ULSCH_CQI_RI_PDU_TYPE:
+        // Convert it to an NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE
+        ulsch_harq_information  = &ul_config_pdu->ulsch_cqi_harq_ri_pdu.harq_information;
+        ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE;
+        /* TODO: check this - when converting from nfapi_ul_config_ulsch_cqi_ri_pdu to
+         * nfapi_ul_config_ulsch_cqi_harq_ri_pdu, shouldn't we copy initial_transmission_parameters
+         * from the one to the other?
+         * Those two types are not compatible. 'initial_transmission_parameters' is not at the
+         * place in both.
+         */
+        ul_config_pdu->ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag                            =
+          NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG;
+        ul_config_pdu->ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial                     = 0;  // last symbol not punctured
+        ul_config_pdu->ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks =
+          ul_config_pdu->ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.number_of_resource_blocks; // we don't change the number of resource blocks across retransmissions yet
+        break;
+
+      case NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE:
+        AssertFatal(use_simultaneous_pucch_pusch == 0,
+                    "Cannot be NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE, simultaneous_pucch_pusch is active\n");
+        break;
 
       /* [ulsch + cqi on pucch] to [ulsch + cqi on pucch + harq on pucch] */
 
-    case NFAPI_UL_CONFIG_ULSCH_UCI_CSI_PDU_TYPE:
-      // convert it to an NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE
-      harq_information        = &ul_config_pdu->ulsch_csi_uci_harq_pdu.harq_information;
-      ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE;
-      break;
-    case NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE:
-      AssertFatal(use_simultaneous_pucch_pusch == 1,
-		  "Cannot be NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE, simultaneous_pucch_pusch is inactive\n");
-      break;
+      case NFAPI_UL_CONFIG_ULSCH_UCI_CSI_PDU_TYPE:
+        // convert it to an NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE
+        harq_information        = &ul_config_pdu->ulsch_csi_uci_harq_pdu.harq_information;
+        ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE;
+        break;
+
+      case NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE:
+        AssertFatal(use_simultaneous_pucch_pusch == 1,
+                    "Cannot be NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE, simultaneous_pucch_pusch is inactive\n");
+        break;
 
       /* [sr] to [sr + harq] */
 
-    case NFAPI_UL_CONFIG_UCI_SR_PDU_TYPE:
-      // convert to NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE
-      ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE;
-      harq_information        = &ul_config_pdu->uci_sr_harq_pdu.harq_information;
-      break;
-    case NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE:
-      /* nothing to do */
-      break;
+      case NFAPI_UL_CONFIG_UCI_SR_PDU_TYPE:
+        // convert to NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE
+        ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE;
+        harq_information        = &ul_config_pdu->uci_sr_harq_pdu.harq_information;
+        break;
+
+      case NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE:
+        /* nothing to do */
+        break;
+
       /* [cqi] to [cqi + harq] */
-    case NFAPI_UL_CONFIG_UCI_CQI_PDU_TYPE:
-      // convert to NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE
-      ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE;
-      harq_information = &ul_config_pdu->uci_cqi_harq_pdu.harq_information;
-      break;
-    case NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE:
-      /* nothing to do */
-      break;
+      case NFAPI_UL_CONFIG_UCI_CQI_PDU_TYPE:
+        // convert to NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE
+        ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE;
+        harq_information = &ul_config_pdu->uci_cqi_harq_pdu.harq_information;
+        break;
+
+      case NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE:
+        /* nothing to do */
+        break;
+
       /* [cqi + sr] to [cqr + sr + harq] */
-    case NFAPI_UL_CONFIG_UCI_CQI_SR_PDU_TYPE:
-      // convert to NFAPI_UL_CONFIG_UCI_CQI_SR_HARQ_PDU_TYPE
-      ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_UCI_CQI_SR_HARQ_PDU_TYPE;
-      harq_information = &ul_config_pdu->uci_cqi_sr_harq_pdu.harq_information;
-      break;
-    case NFAPI_UL_CONFIG_UCI_CQI_SR_HARQ_PDU_TYPE:
-      /* nothing to do */
-      break;
+      case NFAPI_UL_CONFIG_UCI_CQI_SR_PDU_TYPE:
+        // convert to NFAPI_UL_CONFIG_UCI_CQI_SR_HARQ_PDU_TYPE
+        ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_UCI_CQI_SR_HARQ_PDU_TYPE;
+        harq_information = &ul_config_pdu->uci_cqi_sr_harq_pdu.harq_information;
+        break;
+
+      case NFAPI_UL_CONFIG_UCI_CQI_SR_HARQ_PDU_TYPE:
+        /* nothing to do */
+        break;
     }
   }
 
   if (ulsch_harq_information) fill_nfapi_ulsch_harq_information(module_idP, CC_idP, rnti, ulsch_harq_information, subframeP);
 
   if (harq_information) fill_nfapi_harq_information(module_idP, CC_idP,
-						    rnti,
-						    (frameP * 10) + subframeP,
-						    harq_information, cce_idx);
+        rnti,
+        (frameP * 10) + subframeP,
+        harq_information, cce_idx);
 }
 
-uint8_t get_V_UL_DAI(module_id_t module_idP, int CC_idP, uint16_t rntiP,sub_frame_t subframeP)
-{
+uint8_t get_V_UL_DAI(module_id_t module_idP, int CC_idP, uint16_t rntiP,sub_frame_t subframeP) {
   nfapi_hi_dci0_request_body_t *HI_DCI0_req = &RC.mac[module_idP]->HI_DCI0_req[CC_idP][subframeP].hi_dci0_request_body;
   nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu  = &HI_DCI0_req->hi_dci0_pdu_list[0];
 
   for (int i = 0; i < HI_DCI0_req->number_of_dci; i++) {
     if ((hi_dci0_pdu[i].pdu_type == NFAPI_HI_DCI0_DCI_PDU_TYPE) &&
-	(hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.rnti == rntiP))
+        (hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.rnti == rntiP))
       return (hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.dl_assignment_index);
   }
-  return (4);			// this is rule from Section 7.3 in 36.213
+
+  return (4);     // this is rule from Section 7.3 in 36.213
 }
 
 void
 fill_nfapi_ulsch_harq_information(module_id_t                            module_idP,
-				  int                                    CC_idP,
-				  uint16_t                               rntiP,
-				  nfapi_ul_config_ulsch_harq_information *harq_information,
-				  sub_frame_t                            subframeP)
+                                  int                                    CC_idP,
+                                  uint16_t                               rntiP,
+                                  nfapi_ul_config_ulsch_harq_information *harq_information,
+                                  sub_frame_t                            subframeP)
 {
   eNB_MAC_INST *eNB     = RC.mac[module_idP];
   COMMON_channels_t *cc = &eNB->common_channels[CC_idP];
   UE_list_t *UE_list    = &eNB->UE_list;
-
   int UE_id = find_UE_id(module_idP, rntiP);
-
-  PUSCH_ConfigDedicated_t *puschConfigDedicated;
+  LTE_PUSCH_ConfigDedicated_t *puschConfigDedicated;
   //  PUSCH_ConfigDedicated_v1020_t        *puschConfigDedicated_v1020;
   //  PUSCH_ConfigDedicated_v1130_t        *puschConfigDedicated_v1130;
   //  PUSCH_ConfigDedicated_v1250_t        *puschConfigDedicated_v1250;
-
   AssertFatal(UE_id >= 0, "UE_id cannot be found, impossible\n");
   AssertFatal(UE_list != NULL, "UE_list is null\n");
   AssertFatal(UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated != NULL,
-	      "physicalConfigDedicated for rnti %x is null\n", rntiP);
-  AssertFatal((puschConfigDedicated = (PUSCH_ConfigDedicated_t *)
-	       UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pusch_ConfigDedicated) != NULL,
-	      "physicalConfigDedicated->puschConfigDedicated for rnti %x is null\n",
-	      rntiP);
-#if (RRC_VERSION >= MAKE_VERSION(10, 2, 0))
+              "physicalConfigDedicated for rnti %x is null\n", rntiP);
+  AssertFatal((puschConfigDedicated = (LTE_PUSCH_ConfigDedicated_t *)
+                                      UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pusch_ConfigDedicated) != NULL,
+              "physicalConfigDedicated->puschConfigDedicated for rnti %x is null\n",
+              rntiP);
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 2, 0))
   /*  if (UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->ext2) puschConfigDedicated_v1020 =  UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->ext2->pusch_ConfigDedicated_v1020;
       #endif
-      #if (RRC_VERSION >= MAKE_VERSION(11, 3, 0))
+      #if (LTE_RRC_VERSION >= MAKE_VERSION(11, 3, 0))
       if (UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->ext4) puschConfigDedicated_v1130 =  UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->ext4->pusch_ConfigDedicated_v1130;
       #endif
-      #if (RRC_VERSION >= MAKE_VERSION(12, 5, 0))
+      #if (LTE_RRC_VERSION >= MAKE_VERSION(12, 5, 0))
       if (UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->ext5) puschConfigDedicated_v1250 =  UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->ext5->pusch_ConfigDedicated_v1250;
       #endif
   */
 #endif
   harq_information->harq_information_rel10.delta_offset_harq = puschConfigDedicated->betaOffset_ACK_Index;
+  harq_information->harq_information_rel10.tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_HARQ_INFORMATION_REL10_TAG;
   AssertFatal(UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated != NULL,
-	      "pucch_ConfigDedicated is null!\n");
+              "pucch_ConfigDedicated is null!\n");
+
   if ((UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated->tdd_AckNackFeedbackMode != NULL)
-      && (*UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated->tdd_AckNackFeedbackMode == PUCCH_ConfigDedicated__tdd_AckNackFeedbackMode_multiplexing))
-    harq_information->harq_information_rel10.ack_nack_mode = 1;	// multiplexing
+      && (*UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated->tdd_AckNackFeedbackMode == LTE_PUCCH_ConfigDedicated__tdd_AckNackFeedbackMode_multiplexing))
+    harq_information->harq_information_rel10.ack_nack_mode = 1; // multiplexing
   else
-    harq_information->harq_information_rel10.ack_nack_mode = 0;	// bundling
+    harq_information->harq_information_rel10.ack_nack_mode = 0; // bundling
 
   switch (get_tmode(module_idP, CC_idP, UE_id)) {
-  case 1:
-  case 2:
-  case 5:
-  case 6:
-  case 7:
-    if (cc->tdd_Config == NULL)	// FDD
-      harq_information->harq_information_rel10.harq_size = 1;
-    else {
-      if (harq_information->harq_information_rel10.ack_nack_mode == 1)
-	harq_information->harq_information_rel10.harq_size = get_V_UL_DAI(module_idP, CC_idP, rntiP, subframeP);
-      else
+    case 1:
+    case 2:
+    case 5:
+    case 6:
+    case 7:
+      if (cc->tdd_Config == NULL) // FDD
         harq_information->harq_information_rel10.harq_size = 1;
-    }
-    break;
-  default:			// for any other TM we need 2 bits harq
-    if (cc->tdd_Config == NULL) {
-      harq_information->harq_information_rel10.harq_size = 2;
-    } else {
-      if (harq_information->harq_information_rel10.ack_nack_mode == 1)
-	harq_information->harq_information_rel10.harq_size = get_V_UL_DAI(module_idP, CC_idP, rntiP, subframeP);
-      else
-	harq_information->harq_information_rel10.harq_size = 2;
-    }
-    break;
-  }				// get Tmode
+      else {
+        if (harq_information->harq_information_rel10.ack_nack_mode == 1)
+          harq_information->harq_information_rel10.harq_size = get_V_UL_DAI(module_idP, CC_idP, rntiP, subframeP);
+        else
+          harq_information->harq_information_rel10.harq_size = 1;
+      }
+      break;
+
+    default:      // for any other TM we need 2 bits harq
+      if (cc->tdd_Config == NULL) {
+        harq_information->harq_information_rel10.harq_size = 2;
+      } else {
+        if (harq_information->harq_information_rel10.ack_nack_mode == 1)
+          harq_information->harq_information_rel10.harq_size = get_V_UL_DAI(module_idP, CC_idP, rntiP, subframeP);
+        else
+          harq_information->harq_information_rel10.harq_size = 2;
+      }
+      break;
+  }       // get Tmode
+  return;
 }
 
 uint8_t Np[6][4]= {{0,1,3,5},
-                   {0,3,8,13},
-		   {0,5,13,22},
-		   {0,11,27,44},
-		   {0,16,41,66},
-		   {0,22,55,88}};
+  {0,3,8,13},
+  {0,5,13,22},
+  {0,11,27,44},
+  {0,16,41,66},
+  {0,22,55,88}
+};
 
 // This is part of the PUCCH allocation procedure (see Section 10.1 36.213)
-uint16_t getNp(int dl_Bandwidth,uint8_t nCCE,uint8_t plus1)
-{
+uint16_t getNp(int dl_Bandwidth,uint8_t nCCE,uint8_t plus1) {
   AssertFatal(dl_Bandwidth<6,"dl_Bandwidth %d>5\n",dl_Bandwidth);
 
   if (nCCE>=Np[dl_Bandwidth][2])
@@ -1344,152 +1396,146 @@ uint16_t getNp(int dl_Bandwidth,uint8_t nCCE,uint8_t plus1)
 
 void
 fill_nfapi_harq_information(module_id_t                      module_idP,
-			    int                              CC_idP,
-			    uint16_t                         rntiP,
-			    uint16_t                         absSFP,
-			    nfapi_ul_config_harq_information *harq_information, 
-			    uint8_t                          cce_idxP)
-{
+                            int                              CC_idP,
+                            uint16_t                         rntiP,
+                            uint16_t                         absSFP,
+                            nfapi_ul_config_harq_information *harq_information,
+                            uint8_t                          cce_idxP) {
   eNB_MAC_INST *eNB     = RC.mac[module_idP];
   COMMON_channels_t *cc = &eNB->common_channels[CC_idP];
   UE_list_t *UE_list    = &eNB->UE_list;
-
   int UE_id = find_UE_id(module_idP, rntiP);
-
   AssertFatal(UE_id >= 0, "UE_id cannot be found, impossible\n");
   AssertFatal(UE_list != NULL, "UE_list is null\n");
-
   harq_information->harq_information_rel11.tl.tag        = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL11_TAG;
   harq_information->harq_information_rel11.num_ant_ports = 1;
 
   switch (get_tmode(module_idP, CC_idP, UE_id)) {
-  case 1:
-  case 2:
-  case 5:
-  case 6:
-  case 7:
-    if (cc->tdd_Config != NULL) {
-//      AssertFatal(UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated != NULL,
-//		  "pucch_ConfigDedicated is null for TDD!\n");
-      if (UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated != NULL
-          && UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated != NULL
-          && (UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated->tdd_AckNackFeedbackMode != NULL)
-	  && (*UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated->tdd_AckNackFeedbackMode == PUCCH_ConfigDedicated__tdd_AckNackFeedbackMode_multiplexing))
-      {
-        harq_information->harq_information_rel10_tdd.harq_size             = 2;        // 2-bit ACK/NAK
-        harq_information->harq_information_rel10_tdd.ack_nack_mode         = 1;        // multiplexing
+    case 1:
+    case 2:
+    case 5:
+    case 6:
+    case 7:
+      if (cc->tdd_Config != NULL) {
+        //      AssertFatal(UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated != NULL,
+        //      "pucch_ConfigDedicated is null for TDD!\n");
+        if (UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated != NULL
+            && UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated != NULL
+            && (UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated->tdd_AckNackFeedbackMode != NULL)
+            && (*UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated->tdd_AckNackFeedbackMode == LTE_PUCCH_ConfigDedicated__tdd_AckNackFeedbackMode_multiplexing)) {
+          harq_information->harq_information_rel10_tdd.harq_size             = 2;        // 2-bit ACK/NAK
+          harq_information->harq_information_rel10_tdd.ack_nack_mode         = 1;        // multiplexing
+        } else {
+          harq_information->harq_information_rel10_tdd.harq_size             = 1;        // 1-bit ACK/NAK
+          harq_information->harq_information_rel10_tdd.ack_nack_mode         = 0;        // bundling
+        }
+
+        harq_information->harq_information_rel10_tdd.tl.tag                    = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL10_TDD_TAG;
+        harq_information->harq_information_rel10_tdd.n_pucch_1_0               = getNp(cc->mib->message.dl_Bandwidth,cce_idxP,0) +
+            cc->radioResourceConfigCommon->pucch_ConfigCommon.n1PUCCH_AN + cce_idxP;
+        harq_information->harq_information_rel10_tdd.number_of_pucch_resources = 1;
       } else {
-        harq_information->harq_information_rel10_tdd.harq_size             = 1;        // 1-bit ACK/NAK
-        harq_information->harq_information_rel10_tdd.ack_nack_mode         = 0;        // bundling
+        harq_information->harq_information_rel9_fdd.tl.tag                     = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL9_FDD_TAG;
+        harq_information->harq_information_rel9_fdd.number_of_pucch_resources  = 1;
+        harq_information->harq_information_rel9_fdd.harq_size                  = 1; // 1-bit ACK/NAK
+        harq_information->harq_information_rel9_fdd.n_pucch_1_0                = cc->radioResourceConfigCommon->pucch_ConfigCommon.n1PUCCH_AN + cce_idxP;
       }
-      harq_information->harq_information_rel10_tdd.tl.tag                    = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL10_TDD_TAG;
-      harq_information->harq_information_rel10_tdd.n_pucch_1_0               = getNp(cc->mib->message.dl_Bandwidth,cce_idxP,0) +
-                                                                               cc->radioResourceConfigCommon->pucch_ConfigCommon.n1PUCCH_AN + cce_idxP;
-      harq_information->harq_information_rel10_tdd.number_of_pucch_resources = 1;
-    } else {
-      harq_information->harq_information_rel9_fdd.tl.tag                     = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL9_FDD_TAG;
-      harq_information->harq_information_rel9_fdd.number_of_pucch_resources  = 1;
-      harq_information->harq_information_rel9_fdd.harq_size                  = 1;	// 1-bit ACK/NAK
-      harq_information->harq_information_rel9_fdd.n_pucch_1_0                = cc->radioResourceConfigCommon->pucch_ConfigCommon.n1PUCCH_AN + cce_idxP;
-    }
-    break;
-  default:			// for any other TM we need 2 bits harq
-    if (cc->tdd_Config != NULL) {
-      AssertFatal(UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated != NULL,
-		  "pucch_ConfigDedicated is null for TDD!\n");
-      if ((UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated->tdd_AckNackFeedbackMode != NULL)
-	  && (*UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated->tdd_AckNackFeedbackMode == PUCCH_ConfigDedicated__tdd_AckNackFeedbackMode_multiplexing)) {
-	harq_information->harq_information_rel10_tdd.ack_nack_mode            = 1;	// multiplexing
+
+      break;
+
+    default:      // for any other TM we need 2 bits harq
+      if (cc->tdd_Config != NULL) {
+        AssertFatal(UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated != NULL,
+                    "pucch_ConfigDedicated is null for TDD!\n");
+
+        if ((UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated->tdd_AckNackFeedbackMode != NULL)
+            && (*UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated->tdd_AckNackFeedbackMode == LTE_PUCCH_ConfigDedicated__tdd_AckNackFeedbackMode_multiplexing)) {
+          harq_information->harq_information_rel10_tdd.ack_nack_mode            = 1;  // multiplexing
+        } else {
+          harq_information->harq_information_rel10_tdd.ack_nack_mode            = 0;  // bundling
+        }
+
+        harq_information->harq_information_rel10_tdd.tl.tag                     = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL10_TDD_TAG;
+        harq_information->harq_information_rel10_tdd.harq_size                  = 2;
+        harq_information->harq_information_rel10_tdd.n_pucch_1_0                = cc->radioResourceConfigCommon->pucch_ConfigCommon.n1PUCCH_AN + cce_idxP;
+        harq_information->harq_information_rel10_tdd.number_of_pucch_resources  = 1;
       } else {
-	harq_information->harq_information_rel10_tdd.ack_nack_mode            = 0;	// bundling
+        harq_information->harq_information_rel9_fdd.tl.tag                      = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL9_FDD_TAG;
+        harq_information->harq_information_rel9_fdd.number_of_pucch_resources   = 1;
+        harq_information->harq_information_rel9_fdd.ack_nack_mode               = 0;  // 1a/b
+        harq_information->harq_information_rel9_fdd.harq_size                   = 2;
+        harq_information->harq_information_rel9_fdd.n_pucch_1_0                 = cc->radioResourceConfigCommon->pucch_ConfigCommon.n1PUCCH_AN + cce_idxP;
       }
-      harq_information->harq_information_rel10_tdd.tl.tag                     = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL10_TDD_TAG;
-      harq_information->harq_information_rel10_tdd.harq_size                  = 2;
-      harq_information->harq_information_rel10_tdd.n_pucch_1_0                =	cc->radioResourceConfigCommon->pucch_ConfigCommon.n1PUCCH_AN + cce_idxP;
-      harq_information->harq_information_rel10_tdd.number_of_pucch_resources  = 1;
-    } else {
-      harq_information->harq_information_rel9_fdd.tl.tag                      = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL9_FDD_TAG;
-      harq_information->harq_information_rel9_fdd.number_of_pucch_resources   = 1;
-      harq_information->harq_information_rel9_fdd.ack_nack_mode               = 0;	// 1a/b
-      harq_information->harq_information_rel9_fdd.harq_size                   = 2;
-      harq_information->harq_information_rel9_fdd.n_pucch_1_0                 =	cc->radioResourceConfigCommon->pucch_ConfigCommon.n1PUCCH_AN + cce_idxP;
-    }
-    break;
-  }				// get Tmode
+
+      break;
+  }       // get Tmode
 }
 
 uint16_t
 fill_nfapi_uci_acknak(module_id_t module_idP,
-		      int         CC_idP,
-		      uint16_t    rntiP, 
-		      uint16_t    absSFP, 
-		      uint8_t     cce_idxP)
-{
+                      int         CC_idP,
+                      uint16_t    rntiP,
+                      uint16_t    absSFP,
+                      uint8_t     cce_idxP) {
   eNB_MAC_INST                   *eNB           = RC.mac[module_idP];
   COMMON_channels_t              *cc            = &eNB->common_channels[CC_idP];
   int                            ackNAK_absSF   = get_pucch1_absSF(cc, absSFP);
   nfapi_ul_config_request_t      *ul_req        = &eNB->UL_req_tmp[CC_idP][ackNAK_absSF % 10];
   nfapi_ul_config_request_body_t *ul_req_body   = &ul_req->ul_config_request_body;
   nfapi_ul_config_request_pdu_t  *ul_config_pdu = &ul_req_body->ul_config_pdu_list[ul_req_body->number_of_pdus];
-
   memset((void *) ul_config_pdu, 0, sizeof(nfapi_ul_config_request_pdu_t));
   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.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL8_TAG;
-  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.handle = 0;  // don't know how to use this
   ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.rnti   = rntiP;
-
   fill_nfapi_harq_information(module_idP, CC_idP,
-			      rntiP,
-			      absSFP,
-			      &ul_config_pdu->uci_harq_pdu.harq_information, cce_idxP);
+                              rntiP,
+                              absSFP,
+                              &ul_config_pdu->uci_harq_pdu.harq_information, cce_idxP);
   LOG_D(MAC,
-	"Filled in UCI HARQ request for rnti %x SF %d.%d acknakSF %d.%d, cce_idxP %d-> n1_pucch %d\n",
-	rntiP, absSFP / 10, absSFP % 10, ackNAK_absSF / 10,
-	ackNAK_absSF % 10, cce_idxP,
-	ul_config_pdu->uci_harq_pdu.
-	harq_information.harq_information_rel9_fdd.n_pucch_1_0);
-
+        "Filled in UCI HARQ request for rnti %x SF %d.%d acknakSF %d.%d, cce_idxP %d-> n1_pucch %d\n",
+        rntiP, absSFP / 10, absSFP % 10, ackNAK_absSF / 10,
+        ackNAK_absSF % 10, cce_idxP,
+        ul_config_pdu->uci_harq_pdu.
+        harq_information.harq_information_rel9_fdd.n_pucch_1_0);
   ul_req_body->number_of_pdus++;
   ul_req_body->tl.tag       = NFAPI_UL_CONFIG_REQUEST_BODY_TAG;
   ul_req->header.message_id = NFAPI_UL_CONFIG_REQUEST;
   ul_req->sfn_sf            = (ackNAK_absSF/10) << 4 | ackNAK_absSF%10;
-
   return (((ackNAK_absSF / 10) << 4) + (ackNAK_absSF % 10));
 }
 
 void
-fill_nfapi_dlsch_config(eNB_MAC_INST * eNB,
-			nfapi_dl_config_request_body_t * dl_req,
-			uint16_t length,
-			int16_t pdu_index,
-			uint16_t rnti,
-			uint8_t resource_allocation_type,
-			uint8_t
-			virtual_resource_block_assignment_flag,
-			uint16_t resource_block_coding,
-			uint8_t modulation,
-			uint8_t redundancy_version,
-			uint8_t transport_blocks,
-			uint8_t transport_block_to_codeword_swap_flag,
-			uint8_t transmission_scheme,
-			uint8_t number_of_layers,
-			uint8_t number_of_subbands,
-			//                             uint8_t codebook_index,
-			uint8_t ue_category_capacity,
-			uint8_t pa,
-			uint8_t delta_power_offset_index,
-			uint8_t ngap,
-			uint8_t nprb,
-			uint8_t transmission_mode,
-			uint8_t num_bf_prb_per_subband,
-			uint8_t num_bf_vector)
-{
+fill_nfapi_dlsch_config(eNB_MAC_INST *eNB,
+                        nfapi_dl_config_request_body_t *dl_req,
+                        uint16_t length,
+                        int16_t pdu_index,
+                        uint16_t rnti,
+                        uint8_t resource_allocation_type,
+                        uint8_t
+                        virtual_resource_block_assignment_flag,
+                        uint16_t resource_block_coding,
+                        uint8_t modulation,
+                        uint8_t redundancy_version,
+                        uint8_t transport_blocks,
+                        uint8_t transport_block_to_codeword_swap_flag,
+                        uint8_t transmission_scheme,
+                        uint8_t number_of_layers,
+                        uint8_t number_of_subbands,
+                        //                             uint8_t codebook_index,
+                        uint8_t ue_category_capacity,
+                        uint8_t pa,
+                        uint8_t delta_power_offset_index,
+                        uint8_t ngap,
+                        uint8_t nprb,
+                        uint8_t transmission_mode,
+                        uint8_t num_bf_prb_per_subband,
+                        uint8_t num_bf_vector) {
   nfapi_dl_config_request_pdu_t *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));
-
+         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.tl.tag                                 = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL8_TAG;
@@ -1520,15 +1566,13 @@ fill_nfapi_dlsch_config(eNB_MAC_INST * eNB,
 
 uint16_t
 fill_nfapi_tx_req(nfapi_tx_request_body_t *tx_req_body,
-		  uint16_t                absSF, 
-		  uint16_t                pdu_length,
-		  int16_t                 pdu_index, 
-		  uint8_t                 *pdu)
-{
+                  uint16_t                absSF,
+                  uint16_t                pdu_length,
+                  int16_t                 pdu_index,
+                  uint8_t                 *pdu) {
   nfapi_tx_request_pdu_t *TX_req = &tx_req_body->tx_pdu_list[tx_req_body->number_of_pdus];
   LOG_D(MAC, "Filling TX_req %d for pdu length %d\n",
-	tx_req_body->number_of_pdus, pdu_length);
-
+        tx_req_body->number_of_pdus, pdu_length);
   TX_req->pdu_length                 = pdu_length;
   TX_req->pdu_index                  = pdu_index;
   TX_req->num_segments               = 1;
@@ -1536,34 +1580,34 @@ fill_nfapi_tx_req(nfapi_tx_request_body_t *tx_req_body,
   TX_req->segments[0].segment_data   = pdu;
   tx_req_body->tl.tag                = NFAPI_TX_REQUEST_BODY_TAG;
   tx_req_body->number_of_pdus++;
-
   return (((absSF / 10) << 4) + (absSF % 10));
 }
 
 void
-fill_nfapi_ulsch_config_request_rel8(nfapi_ul_config_request_pdu_t *ul_config_pdu, 
-				     uint8_t                        cqi_req,
-				     COMMON_channels_t              *cc,
-				     struct PhysicalConfigDedicated *physicalConfigDedicated,
-				     uint8_t                        tmode, 
-				     uint32_t                       handle,
-				     uint16_t                       rnti,
-				     uint8_t                        resource_block_start,
-				     uint8_t                        number_of_resource_blocks,
-				     uint8_t                        mcs,
-				     uint8_t                        cyclic_shift_2_for_drms,
-				     uint8_t                        frequency_hopping_enabled_flag,
-				     uint8_t                        frequency_hopping_bits,
-				     uint8_t                        new_data_indication,
-				     uint8_t                        redundancy_version,
-				     uint8_t                        harq_process_number,
-				     uint8_t                        ul_tx_mode,
-				     uint8_t                        current_tx_nb,
-				     uint8_t                        n_srs, 
-				     uint16_t                       size)
+fill_nfapi_ulsch_config_request_rel8(nfapi_ul_config_request_pdu_t *ul_config_pdu,
+                                     uint8_t                        cqi_req,
+                                     COMMON_channels_t              *cc,
+                                     struct LTE_PhysicalConfigDedicated *physicalConfigDedicated,
+                                     uint8_t                        tmode,
+                                     uint32_t                       handle,
+                                     uint16_t                       rnti,
+                                     uint8_t                        resource_block_start,
+                                     uint8_t                        number_of_resource_blocks,
+                                     uint8_t                        mcs,
+                                     uint8_t                        cyclic_shift_2_for_drms,
+                                     uint8_t                        frequency_hopping_enabled_flag,
+                                     uint8_t                        frequency_hopping_bits,
+                                     uint8_t                        new_data_indication,
+                                     uint8_t                        redundancy_version,
+                                     uint8_t                        harq_process_number,
+                                     uint8_t                        ul_tx_mode,
+                                     uint8_t                        current_tx_nb,
+                                     uint8_t                        n_srs,
+                                     uint16_t                       size)
 {
-  memset((void *) ul_config_pdu, 0, sizeof(nfapi_ul_config_request_pdu_t));
+  uint8_t ri_size = 0;
 
+  memset((void *) ul_config_pdu, 0, sizeof(nfapi_ul_config_request_pdu_t));
   ul_config_pdu->pdu_type                                                    = NFAPI_UL_CONFIG_ULSCH_PDU_TYPE;
   ul_config_pdu->pdu_size                                                    = (uint8_t) (2 + sizeof(nfapi_ul_config_ulsch_pdu));
   ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.tl.tag                             = NFAPI_UL_CONFIG_REQUEST_ULSCH_PDU_REL8_TAG;
@@ -1571,10 +1615,12 @@ fill_nfapi_ulsch_config_request_rel8(nfapi_ul_config_request_pdu_t *ul_config_pd
   ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.rnti                               = rnti;
   ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.resource_block_start               = resource_block_start;
   ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.number_of_resource_blocks          = number_of_resource_blocks;
+
   if (mcs < 11)      ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.modulation_type = 2;
   else if (mcs < 21) ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.modulation_type = 4;
   else if(mcs < 29)  ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.modulation_type = 6;
   else               ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.modulation_type = 0;
+
   ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.cyclic_shift_2_for_drms            = cyclic_shift_2_for_drms;
   ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.frequency_hopping_enabled_flag     = frequency_hopping_enabled_flag;
   ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.frequency_hopping_bits             = frequency_hopping_bits;
@@ -1595,37 +1641,37 @@ fill_nfapi_ulsch_config_request_rel8(nfapi_ul_config_request_pdu_t *ul_config_pd
     ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.number_of_cc = 1;
     LOG_D(MAC, "report_type %d\n",ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.report_type);
 
-    if (cc->p_eNB <= 2
-	&& (tmode == 3 || tmode == 4 || tmode == 8 || tmode == 9 || tmode == 10))
-      ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].ri_size = 1;
-    else if (cc->p_eNB <= 2) ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].ri_size = 0;
-    else if (cc->p_eNB == 4) ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].ri_size = 2;
+    if (cc->p_eNB <= 2 && (tmode == 3 || tmode == 4 || tmode == 8 || tmode == 9 || tmode == 10)) ri_size = 1;
+    else if (cc->p_eNB <= 2) ri_size = 0;
+    else if (cc->p_eNB == 4) ri_size = 2;
+    ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].ri_size = ri_size;
 
     AssertFatal(physicalConfigDedicated->cqi_ReportConfig != NULL,"physicalConfigDedicated->cqi_ReportConfig is null!\n");
     AssertFatal(physicalConfigDedicated->cqi_ReportConfig->cqi_ReportModeAperiodic != NULL,"physicalConfigDedicated->cqi_ReportModeAperiodic is null!\n");
     AssertFatal(physicalConfigDedicated->pusch_ConfigDedicated != NULL,"physicalConfigDedicated->puschConfigDedicated is null!\n");
 
-    for (int ri = 0; 
-	 ri <  (1 << ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].ri_size); 
-	 ri++)
-      ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].dl_cqi_pmi_size[ri] =	get_dl_cqi_pmi_size_pusch(cc,tmode,1 + ri,physicalConfigDedicated->cqi_ReportConfig->cqi_ReportModeAperiodic);
+    for (int ri = 0; ri < (1 << ri_size); ri++) {
+      ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].dl_cqi_pmi_size[ri] =
+        get_dl_cqi_pmi_size_pusch(cc,tmode,1 + ri, physicalConfigDedicated->cqi_ReportConfig->cqi_ReportModeAperiodic);
+    }
 
-    ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.delta_offset_cqi                                       = physicalConfigDedicated->pusch_ConfigDedicated->betaOffset_CQI_Index;
-    ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.delta_offset_ri                                        = physicalConfigDedicated->pusch_ConfigDedicated->betaOffset_RI_Index;
+    ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.delta_offset_cqi =
+      physicalConfigDedicated->pusch_ConfigDedicated->betaOffset_CQI_Index;
+    ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.delta_offset_ri =
+      physicalConfigDedicated->pusch_ConfigDedicated->betaOffset_RI_Index;
   }
 }
 
-#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
 void
 fill_nfapi_ulsch_config_request_emtc(nfapi_ul_config_request_pdu_t *
-				     ul_config_pdu, uint8_t ue_type,
-				     uint16_t
-				     total_number_of_repetitions,
-				     uint16_t repetition_number,
-				     uint16_t initial_transmission_sf_io)
+                                     ul_config_pdu, uint8_t ue_type,
+                                     uint16_t
+                                     total_number_of_repetitions,
+                                     uint16_t repetition_number,
+                                     uint16_t initial_transmission_sf_io)
 {
   // Re13 fields
-
   ul_config_pdu->ulsch_pdu.ulsch_pdu_rel13.tl.tag                      = NFAPI_UL_CONFIG_REQUEST_ULSCH_PDU_REL13_TAG;
   ul_config_pdu->ulsch_pdu.ulsch_pdu_rel13.ue_type                     = ue_type;
   ul_config_pdu->ulsch_pdu.ulsch_pdu_rel13.total_number_of_repetitions = total_number_of_repetitions;
@@ -1633,18 +1679,14 @@ fill_nfapi_ulsch_config_request_emtc(nfapi_ul_config_request_pdu_t *
   ul_config_pdu->ulsch_pdu.ulsch_pdu_rel13.initial_transmission_sf_io  = initial_transmission_sf_io;
 }
 
-int get_numnarrowbands(long dl_Bandwidth)
-{
+int get_numnarrowbands(long dl_Bandwidth) {
   int nb_tab[6] = { 1, 2, 4, 8, 12, 16 };
-
   AssertFatal(dl_Bandwidth < 7 || dl_Bandwidth >= 0, "dl_Bandwidth not in [0..6]\n");
   return (nb_tab[dl_Bandwidth]);
 }
 
-int get_numnarrowbandbits(long dl_Bandwidth)
-{
+int get_numnarrowbandbits(long dl_Bandwidth) {
   int nbbits_tab[6] = { 0, 1, 2, 3, 4, 4 };
-
   AssertFatal(dl_Bandwidth < 7 || dl_Bandwidth >= 0, "dl_Bandwidth not in [0..6]\n");
   return (nbbits_tab[dl_Bandwidth]);
 }
@@ -1654,99 +1696,114 @@ int startSF_fdd_RA_times2[8] = { 2, 3, 4, 5, 8, 10, 16, 20 };
 int startSF_tdd_RA[7] = { 1, 2, 4, 5, 8, 10, 20 };
 
 int
-mpdcch_sf_condition(eNB_MAC_INST * eNB, int CC_id, frame_t frameP,
-		    sub_frame_t subframeP, int rmax,
-		    MPDCCH_TYPES_t mpdcch_type, int UE_id)
-{
-  struct PRACH_ConfigSIB_v1310 *ext4_prach =
-    eNB->common_channels[CC_id].radioResourceConfigCommon_BR->
-    ext4->prach_ConfigCommon_v1310;
-
+mpdcch_sf_condition(eNB_MAC_INST *eNB, int CC_id, frame_t frameP,
+                    sub_frame_t subframeP, int rmax,
+                    MPDCCH_TYPES_t mpdcch_type, int UE_id) {
+  struct LTE_PRACH_ConfigSIB_v1310 *ext4_prach =
+      eNB->common_channels[CC_id].radioResourceConfigCommon_BR->
+      ext4->prach_ConfigCommon_v1310;
   int T;
-  EPDCCH_SetConfig_r11_t *epdcch_setconfig_r11;
+  LTE_EPDCCH_SetConfig_r11_t *epdcch_setconfig_r11;
 
   switch (mpdcch_type) {
-  case TYPE0:
-    AssertFatal(1 == 0, "MPDCCH Type 0 not handled yet\n");
-    break;
-  case TYPE1:
-    AssertFatal(1 == 0, "MPDCCH Type 1 not handled yet\n");
-    break;
-  case TYPE1A:
-    AssertFatal(1 == 0, "MPDCCH Type 1A not handled yet\n");
-    break;
-  case TYPE2:		// RAR
-    AssertFatal(ext4_prach->mpdcch_startSF_CSS_RA_r13 != NULL,
-		"mpdcch_startSF_CSS_RA_r13 is null\n");
-    AssertFatal(rmax > 0, "rmax is 0!\b");
-    if (eNB->common_channels[CC_id].tdd_Config == NULL)	//FDD
-      T = rmax *startSF_fdd_RA_times2[ext4_prach->
-				      mpdcch_startSF_CSS_RA_r13->
-				      choice.fdd_r13] >> 1;
-    else			//TDD
-      T = rmax *startSF_tdd_RA[ext4_prach->
-			       mpdcch_startSF_CSS_RA_r13->choice.tdd_r13];
-    break;
-  case TYPE2A:
-    AssertFatal(1 == 0, "MPDCCH Type 2A not handled yet\n");
-    break;
-  case TYPEUESPEC:
-    epdcch_setconfig_r11 =
-      eNB->UE_list.UE_template[CC_id][UE_id].physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11->list.array[0];
-
-    AssertFatal(epdcch_setconfig_r11 != NULL,
-		" epdcch_setconfig_r11 is null for UE specific \n");
-    AssertFatal(epdcch_setconfig_r11->ext2 != NULL,
-		" ext2 doesn't exist in epdcch config ' \n");
-
-    if (eNB->common_channels[CC_id].tdd_Config == NULL)	//FDD
-      T = rmax *startSF_fdd_RA_times2[epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_StartSF_UESS_r13.choice.fdd_r13] >> 1;
-    else			//TDD
-      T = rmax *startSF_tdd_RA[epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_StartSF_UESS_r13.choice.tdd_r13];
-    break;
-  default:
-    return (0);
+    case TYPE0:
+      AssertFatal(1 == 0, "MPDCCH Type 0 not handled yet\n");
+      break;
+
+    case TYPE1:
+      AssertFatal(1 == 0, "MPDCCH Type 1 not handled yet\n");
+      break;
+
+    case TYPE1A:
+      AssertFatal(1 == 0, "MPDCCH Type 1A not handled yet\n");
+      break;
+
+    case TYPE2:   // RAR
+      AssertFatal(ext4_prach->mpdcch_startSF_CSS_RA_r13 != NULL,
+                  "mpdcch_startSF_CSS_RA_r13 is null\n");
+      AssertFatal(rmax > 0, "rmax is 0!\b");
+
+      if (eNB->common_channels[CC_id].tdd_Config == NULL) //FDD
+        T = rmax *startSF_fdd_RA_times2[ext4_prach->
+                                        mpdcch_startSF_CSS_RA_r13->
+                                        choice.fdd_r13] >> 1;
+      else      //TDD
+        T = rmax *startSF_tdd_RA[ext4_prach->
+                                 mpdcch_startSF_CSS_RA_r13->choice.tdd_r13];
+
+      break;
+
+    case TYPE2A:
+      AssertFatal(1 == 0, "MPDCCH Type 2A not handled yet\n");
+      break;
+
+    case TYPEUESPEC:
+      epdcch_setconfig_r11 =
+        eNB->UE_list.UE_template[CC_id][UE_id].physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11->list.array[0];
+      AssertFatal(epdcch_setconfig_r11 != NULL,
+                  " epdcch_setconfig_r11 is null for UE specific \n");
+      AssertFatal(epdcch_setconfig_r11->ext2 != NULL,
+                  " ext2 doesn't exist in epdcch config ' \n");
+
+      if (eNB->common_channels[CC_id].tdd_Config == NULL) //FDD
+        T = rmax *startSF_fdd_RA_times2[epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_StartSF_UESS_r13.choice.fdd_r13] >> 1;
+      else      //TDD
+        T = rmax *startSF_tdd_RA[epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_StartSF_UESS_r13.choice.tdd_r13];
+
+      break;
+
+    default:
+      return (0);
   }
 
   AssertFatal(T > 0, "T is 0!\n");
+
   if (((10 * frameP) + subframeP) % T == 0) return (1);
   else return (0);
 }
 
-int narrowband_to_first_rb(COMMON_channels_t * cc, int nb_index)
-{
+int narrowband_to_first_rb(COMMON_channels_t *cc, int nb_index) {
   switch (cc->mib->message.dl_Bandwidth) {
-  case 0:			// 6 PRBs, N_NB=1, i_0=0
-    return (0);
-    break;
-  case 3:			// 50 PRBs, N_NB=8, i_0=1
-    return ((int) (1 + (6 * nb_index)));
-    break;
-  case 5:			// 100 PRBs, N_NB=16, i_0=2
-    return ((int) (2 + (6 * nb_index)));
-    break;
-  case 1:			// 15 PRBs  N_NB=2, i_0=1
-    if (nb_index > 0)
-      return (1);
-    else
+    case 0:     // 6 PRBs, N_NB=1, i_0=0
       return (0);
-    break;
-  case 2:			// 25 PRBs, N_NB=4, i_0=0
-    if (nb_index > 1)
-      return (1 + (6 * nb_index));
-    else
-      return ((6 * nb_index));
-    break;
-  case 4:			// 75 PRBs, N_NB=12, i_0=1
-    if (nb_index > 5)
-      return (2 + (6 * nb_index));
-    else
-      return (1 + (6 * nb_index));
-    break;
-  default:
-    AssertFatal(1 == 0, "Impossible dl_Bandwidth %d\n",
-		(int) cc->mib->message.dl_Bandwidth);
-    break;
+      break;
+
+    case 3:     // 50 PRBs, N_NB=8, i_0=1
+      return ((int) (1 + (6 * nb_index)));
+      break;
+
+    case 5:     // 100 PRBs, N_NB=16, i_0=2
+      return ((int) (2 + (6 * nb_index)));
+      break;
+
+    case 1:     // 15 PRBs  N_NB=2, i_0=1
+      if (nb_index > 0)
+        return (1);
+      else
+        return (0);
+
+      break;
+
+    case 2:     // 25 PRBs, N_NB=4, i_0=0
+      if (nb_index > 1)
+        return (1 + (6 * nb_index));
+      else
+        return ((6 * nb_index));
+
+      break;
+
+    case 4:     // 75 PRBs, N_NB=12, i_0=1
+      if (nb_index > 5)
+        return (2 + (6 * nb_index));
+      else
+        return (1 + (6 * nb_index));
+
+      break;
+
+    default:
+      AssertFatal(1 == 0, "Impossible dl_Bandwidth %d\n",
+                  (int) cc->mib->message.dl_Bandwidth);
+      break;
   }
 }
 #endif
@@ -1760,15 +1817,15 @@ void init_ue_sched_info(void)
   for (i = 0; i < NUMBER_OF_eNB_MAX; i++) {
     for (k = 0; k < MAX_NUM_CCs; k++) {
       for (j = 0; j < MAX_MOBILES_PER_ENB; j++) {
-	// init DL
-	eNB_dlsch_info[i][k][j].weight = 0;
-	eNB_dlsch_info[i][k][j].subframe = 0;
-	eNB_dlsch_info[i][k][j].serving_num = 0;
-	eNB_dlsch_info[i][k][j].status = S_DL_NONE;
-	// init UL
-	eNB_ulsch_info[i][k][j].subframe = 0;
-	eNB_ulsch_info[i][k][j].serving_num = 0;
-	eNB_ulsch_info[i][k][j].status = S_UL_NONE;
+        // init DL
+        eNB_dlsch_info[i][k][j].weight = 0;
+        eNB_dlsch_info[i][k][j].subframe = 0;
+        eNB_dlsch_info[i][k][j].serving_num = 0;
+        eNB_dlsch_info[i][k][j].status = S_DL_NONE;
+        // init UL
+        eNB_ulsch_info[i][k][j].subframe = 0;
+        eNB_ulsch_info[i][k][j].serving_num = 0;
+        eNB_ulsch_info[i][k][j].status = S_UL_NONE;
       }
     }
   }
@@ -1793,8 +1850,9 @@ int find_UE_id(module_id_t mod_idP, rnti_t rntiP)
   for (UE_id = 0; UE_id < MAX_MOBILES_PER_ENB; UE_id++) {
     if (UE_list->active[UE_id] != TRUE)
       continue;
+
     if (UE_list->UE_template[UE_PCCID(mod_idP, UE_id)][UE_id].rnti ==
-	rntiP) {
+        rntiP) {
       return (UE_id);
     }
   }
@@ -1808,23 +1866,23 @@ int find_RA_id(module_id_t mod_idP, int CC_idP, rnti_t rntiP)
 {
   int RA_id;
   AssertFatal(RC.mac[mod_idP], "RC.mac[%d] is null\n", mod_idP);
-
   RA_t *ra = (RA_t *) & RC.mac[mod_idP]->common_channels[CC_idP].ra[0];
 
   for (RA_id = 0; RA_id < NB_RA_PROC_MAX; RA_id++) {
     LOG_D(MAC,
-	  "Checking RA_id %d for %x : state %d\n",
-	  RA_id, rntiP, ra[RA_id].state);
+          "Checking RA_id %d for %x : state %d\n",
+          RA_id, rntiP, ra[RA_id].state);
 
     if (ra[RA_id].state != IDLE &&
-	ra[RA_id].rnti == rntiP)
+        ra[RA_id].rnti == rntiP)
       return (RA_id);
   }
+
   return (-1);
 }
 
 //------------------------------------------------------------------------------
-int UE_num_active_CC(UE_list_t * listP, int ue_idP)
+int UE_num_active_CC(UE_list_t *listP, int ue_idP)
 //------------------------------------------------------------------------------
 {
   return (listP->numactiveCCs[ue_idP]);
@@ -1862,43 +1920,43 @@ boolean_t is_UE_active(module_id_t mod_idP, int ue_idP)
 }
 
 unsigned char
-get_aggregation(uint8_t bw_index, uint8_t cqi, uint8_t dci_fmt)
-{
+get_aggregation(uint8_t bw_index, uint8_t cqi, uint8_t dci_fmt) {
   unsigned char aggregation = 3;
 
   switch (dci_fmt) {
-  case format0:
-    aggregation = cqi2fmt0_agg[bw_index][cqi];
-    break;
-  case format1:
-  case format1A:
-  case format1B:
-  case format1D:
-    aggregation = cqi2fmt1x_agg[bw_index][cqi];
-    break;
-  case format2:
-  case format2A:
-  case format2B:
-  case format2C:
-  case format2D:
-    aggregation = cqi2fmt2x_agg[bw_index][cqi];
-    break;
-  case format1C:
-  case format1E_2A_M10PRB:
-  case format3:
-  case format3A:
-  case format4:
-  default:
-    LOG_W(MAC, "unsupported DCI format %d\n", dci_fmt);
+    case format0:
+      aggregation = cqi2fmt0_agg[bw_index][cqi];
+      break;
+
+    case format1:
+    case format1A:
+    case format1B:
+    case format1D:
+      aggregation = cqi2fmt1x_agg[bw_index][cqi];
+      break;
+
+    case format2:
+    case format2A:
+    case format2B:
+    case format2C:
+    case format2D:
+      aggregation = cqi2fmt2x_agg[bw_index][cqi];
+      break;
+
+    case format1C:
+    case format1E_2A_M10PRB:
+    case format3:
+    case format3A:
+    case format4:
+    default:
+      LOG_W(MAC, "unsupported DCI format %d\n", dci_fmt);
   }
 
   LOG_D(MAC, "Aggregation level %d (cqi %d, bw_index %d, format %d)\n", 1 << aggregation, cqi, bw_index, dci_fmt);
-
   return 1 << aggregation;
 }
 
-void dump_ue_list(UE_list_t * listP, int ul_flag)
-{
+void dump_ue_list(UE_list_t *listP, int ul_flag) {
   int j;
 
   if (ul_flag == 0) {
@@ -1913,27 +1971,25 @@ void dump_ue_list(UE_list_t * listP, int ul_flag)
 }
 
 int add_new_ue(module_id_t mod_idP, int cc_idP, rnti_t rntiP, int harq_pidP
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-	       , uint8_t rach_resource_type
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  , uint8_t rach_resource_type
 #endif
-	       )
-{
+              ) {
   int UE_id;
   int i, j;
-
   UE_list_t *UE_list = &RC.mac[mod_idP]->UE_list;
-
   LOG_D(MAC,
-	"[eNB %d, CC_id %d] Adding UE with rnti %x (next avail %d, num_UEs %d)\n",
-	mod_idP, cc_idP, rntiP, UE_list->avail, UE_list->num_UEs);
+        "[eNB %d, CC_id %d] Adding UE with rnti %x (next avail %d, num_UEs %d)\n",
+        mod_idP, cc_idP, rntiP, UE_list->avail, UE_list->num_UEs);
   dump_ue_list(UE_list, 0);
 
   for (i = 0; i < MAX_MOBILES_PER_ENB; i++) {
     if (UE_list->active[i] == TRUE)
       continue;
+
     UE_id = i;
     memset(&UE_list->UE_template[cc_idP][UE_id], 0,
-	   sizeof(UE_TEMPLATE));
+           sizeof(UE_TEMPLATE));
     UE_list->UE_template[cc_idP][UE_id].rnti = rntiP;
     UE_list->UE_template[cc_idP][UE_id].configured = FALSE;
     UE_list->numactiveCCs[UE_id] = 1;
@@ -1945,28 +2001,24 @@ int add_new_ue(module_id_t mod_idP, int cc_idP, rnti_t rntiP, int harq_pidP
     UE_list->active[UE_id] = TRUE;
 #if defined(USRP_REC_PLAY) // not specific to record/playback ?
     UE_list->UE_template[cc_idP][UE_id].pre_assigned_mcs_ul = 0;
-#endif    
-
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#endif
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
     UE_list->UE_template[cc_idP][UE_id].rach_resource_type =
       rach_resource_type;
 #endif
-
     memset((void *) &UE_list->UE_sched_ctrl[UE_id], 0,
-	   sizeof(UE_sched_ctrl));
+           sizeof(UE_sched_ctrl));
     memset((void *) &UE_list->eNB_UE_stats[cc_idP][UE_id], 0,
-	   sizeof(eNB_UE_STATS));
+           sizeof(eNB_UE_STATS));
     UE_list->UE_sched_ctrl[UE_id].ue_reestablishment_reject_timer = 0;
-
     /* default slice in case there was something different */
     UE_list->assoc_dl_slice_idx[UE_id] = 0;
     UE_list->assoc_ul_slice_idx[UE_id] = 0;
-
     UE_list->UE_sched_ctrl[UE_id].ta_update = 31;
 
     for (j = 0; j < 8; j++) {
-      UE_list->UE_template[cc_idP][UE_id].oldNDI[j] = (j == 0) ? 1 : 0;	// 1 because first transmission is with format1A (Msg4) for harq_pid 0
-      UE_list->UE_template[cc_idP][UE_id].oldNDI_UL[j] = (j == harq_pidP) ? 0 : 1;	// 1st transmission is with Msg3;
+      UE_list->UE_template[cc_idP][UE_id].oldNDI[j] = (j == 0) ? 1 : 0; // 1 because first transmission is with format1A (Msg4) for harq_pid 0
+      UE_list->UE_template[cc_idP][UE_id].oldNDI_UL[j] = (j == harq_pidP) ? 0 : 1;  // 1st transmission is with Msg3;
       UE_list->UE_sched_ctrl[UE_id].round[cc_idP][j] = 8;
       UE_list->UE_sched_ctrl[UE_id].round_UL[cc_idP][j] = 0;
     }
@@ -1974,14 +2026,14 @@ int add_new_ue(module_id_t mod_idP, int cc_idP, rnti_t rntiP, int harq_pidP
     eNB_ulsch_info[mod_idP][cc_idP][UE_id].status = S_UL_WAITING;
     eNB_dlsch_info[mod_idP][cc_idP][UE_id].status = S_DL_WAITING;
     LOG_D(MAC, "[eNB %d] Add UE_id %d on Primary CC_id %d: rnti %x\n",
-	  mod_idP, UE_id, cc_idP, rntiP);
+          mod_idP, UE_id, cc_idP, rntiP);
     dump_ue_list(UE_list, 0);
     return (UE_id);
   }
 
   printf("MAC: cannot add new UE for rnti %x\n", rntiP);
   LOG_E(MAC,
-	"error in add_new_ue(), could not find space in UE_list, Dumping UE list\n");
+        "error in add_new_ue(), could not find space in UE_list, Dumping UE list\n");
   dump_ue_list(UE_list, 0);
   return (-1);
 }
@@ -1990,105 +2042,102 @@ int add_new_ue(module_id_t mod_idP, int cc_idP, rnti_t rntiP, int harq_pidP
 int rrc_mac_remove_ue(module_id_t mod_idP, rnti_t rntiP)
 //------------------------------------------------------------------------------
 {
-
   int j;
   UE_list_t *UE_list = &RC.mac[mod_idP]->UE_list;
   int UE_id = find_UE_id(mod_idP,rntiP);
   int pCC_id;
-  
+
   if (UE_id == -1) {
     LOG_W(MAC,"rrc_mac_remove_ue: UE %x not found\n", rntiP);
     return 0;
   }
-  
+
   pCC_id = UE_PCCID(mod_idP,UE_id);
-  
   LOG_I(MAC,"Removing UE %d from Primary CC_id %d (rnti %x)\n",UE_id,pCC_id, rntiP);
   dump_ue_list(UE_list,0);
-  
   UE_list->active[UE_id] = FALSE;
   UE_list->num_UEs--;
-  
+
   if (UE_list->head == UE_id) UE_list->head=UE_list->next[UE_id];
   else UE_list->next[prev(UE_list,UE_id,0)]=UE_list->next[UE_id];
+
   if (UE_list->head_ul == UE_id) UE_list->head_ul=UE_list->next_ul[UE_id];
   else UE_list->next_ul[prev(UE_list,UE_id,0)]=UE_list->next_ul[UE_id];
-  
+
   // clear all remaining pending transmissions
   /*  UE_list->UE_template[pCC_id][UE_id].bsr_info[LCGID0]  = 0;
       UE_list->UE_template[pCC_id][UE_id].bsr_info[LCGID1]  = 0;
       UE_list->UE_template[pCC_id][UE_id].bsr_info[LCGID2]  = 0;
       UE_list->UE_template[pCC_id][UE_id].bsr_info[LCGID3]  = 0;
-      
+
       UE_list->UE_template[pCC_id][UE_id].ul_SR             = 0;
       UE_list->UE_template[pCC_id][UE_id].rnti              = NOT_A_RNTI;
       UE_list->UE_template[pCC_id][UE_id].ul_active         = FALSE;
   */
   memset (&UE_list->UE_template[pCC_id][UE_id],0,sizeof(UE_TEMPLATE));
-  
   UE_list->eNB_UE_stats[pCC_id][UE_id].total_rbs_used = 0;
   UE_list->eNB_UE_stats[pCC_id][UE_id].total_rbs_used_retx = 0;
+
   for ( j = 0; j < NB_RB_MAX; j++ ) {
     UE_list->eNB_UE_stats[pCC_id][UE_id].num_pdu_tx[j] = 0;
     UE_list->eNB_UE_stats[pCC_id][UE_id].num_bytes_tx[j] = 0;
   }
+
   UE_list->eNB_UE_stats[pCC_id][UE_id].num_retransmission = 0;
   UE_list->eNB_UE_stats[pCC_id][UE_id].total_sdu_bytes = 0;
   UE_list->eNB_UE_stats[pCC_id][UE_id].total_pdu_bytes = 0;
   UE_list->eNB_UE_stats[pCC_id][UE_id].total_num_pdus = 0;
   UE_list->eNB_UE_stats[pCC_id][UE_id].total_rbs_used_rx = 0;
+
   for ( j = 0; j < NB_RB_MAX; j++ ) {
     UE_list->eNB_UE_stats[pCC_id][UE_id].num_pdu_rx[j] = 0;
     UE_list->eNB_UE_stats[pCC_id][UE_id].num_bytes_rx[j] = 0;
   }
+
   UE_list->eNB_UE_stats[pCC_id][UE_id].num_errors_rx = 0;
   UE_list->eNB_UE_stats[pCC_id][UE_id].total_pdu_bytes_rx = 0;
   UE_list->eNB_UE_stats[pCC_id][UE_id].total_num_pdus_rx = 0;
   UE_list->eNB_UE_stats[pCC_id][UE_id].total_num_errors_rx = 0;
-  
   eNB_ulsch_info[mod_idP][pCC_id][UE_id].rnti                        = NOT_A_RNTI;
   eNB_ulsch_info[mod_idP][pCC_id][UE_id].status                      = S_UL_NONE;
   eNB_dlsch_info[mod_idP][pCC_id][UE_id].rnti                        = NOT_A_RNTI;
   eNB_dlsch_info[mod_idP][pCC_id][UE_id].status                      = S_DL_NONE;
-  
   eNB_ulsch_info[mod_idP][pCC_id][UE_id].serving_num = 0;
   eNB_dlsch_info[mod_idP][pCC_id][UE_id].serving_num = 0;
-  
+
   // check if this has an RA process active
   if(find_RA_id(mod_idP, pCC_id, rntiP) != -1) {
     cancel_ra_proc(mod_idP, pCC_id, 0, rntiP);
   }
 
-  rrc_mac_signal_ue_release(mod_idP, rntiP);
-
-  return 0;
-}
-
-void rrc_mac_signal_ue_release(module_id_t mod_idP, rnti_t rntiP)
-{
   pthread_mutex_lock(&rrc_release_freelist);
-  if (rrc_release_info.num_UEs > 0) {
+  if(rrc_release_info.num_UEs > 0) {
     uint16_t release_total = 0;
-    for (uint16_t release_num = 0; release_num < NUMBER_OF_UE_MAX; release_num++) {
-      if (rrc_release_info.RRC_release_ctrl[release_num].flag > 0)
+
+    for(uint16_t release_num = 0; release_num < NUMBER_OF_UE_MAX; release_num++) {
+      if(rrc_release_info.RRC_release_ctrl[release_num].flag > 0) {
         release_total++;
-      else
+      } else {
         continue;
-      if (rrc_release_info.RRC_release_ctrl[release_num].rnti == rntiP) {
+      }
+
+      if(rrc_release_info.RRC_release_ctrl[release_num].rnti == rntiP) {
         rrc_release_info.RRC_release_ctrl[release_num].flag = 0;
         rrc_release_info.num_UEs--;
         release_total--;
       }
-      if(release_total >= rrc_release_info.num_UEs){
+
+      if(release_total >= rrc_release_info.num_UEs) {
         break;
       }
     }
   }
+
   pthread_mutex_unlock(&rrc_release_freelist);
+  return 0;
 }
 
-int prev(UE_list_t * listP, int nodeP, int ul_flag)
-{
+int prev(UE_list_t *listP, int nodeP, int ul_flag) {
   int j;
 
   if (ul_flag == 0) {
@@ -2098,7 +2147,7 @@ int prev(UE_list_t * listP, int nodeP, int ul_flag)
 
     for (j = listP->head; j >= 0; j = listP->next[j]) {
       if (listP->next[j] == nodeP) {
-	return (j);
+        return (j);
       }
     }
   } else {
@@ -2108,29 +2157,24 @@ int prev(UE_list_t * listP, int nodeP, int ul_flag)
 
     for (j = listP->head_ul; j >= 0; j = listP->next_ul[j]) {
       if (listP->next_ul[j] == nodeP) {
-	return (j);
+        return (j);
       }
     }
   }
 
   LOG_E(MAC,
-	"error in prev(), could not find previous to %d in UE_list %s, should never happen, Dumping UE list\n",
-	nodeP, (ul_flag == 0) ? "DL" : "UL");
+        "error in prev(), could not find previous to %d in UE_list %s, should never happen, Dumping UE list\n",
+        nodeP, (ul_flag == 0) ? "DL" : "UL");
   dump_ue_list(listP, ul_flag);
-
   return (-1);
 }
 
-void swap_UEs(UE_list_t * listP, int nodeiP, int nodejP, int ul_flag)
-{
+void swap_UEs(UE_list_t *listP, int nodeiP, int nodejP, int ul_flag) {
   int prev_i, prev_j, next_i, next_j;
-
   LOG_T(MAC, "Swapping UE %d,%d\n", nodeiP, nodejP);
   dump_ue_list(listP, ul_flag);
-
   prev_i = prev(listP, nodeiP, ul_flag);
   prev_j = prev(listP, nodejP, ul_flag);
-
   AssertFatal((prev_i >= 0) && (prev_j >= 0), "swap_UEs: problem");
 
   if (ul_flag == 0) {
@@ -2142,91 +2186,86 @@ void swap_UEs(UE_list_t * listP, int nodeiP, int nodejP, int ul_flag)
   }
 
   LOG_T(MAC, "[%s] next_i %d, next_i, next_j %d, head %d \n",
-	(ul_flag == 0) ? "DL" : "UL", next_i, next_j, listP->head);
+        (ul_flag == 0) ? "DL" : "UL", next_i, next_j, listP->head);
 
   if (ul_flag == 0) {
-
-    if (next_i == nodejP) {	// case ... p(i) i j n(j) ... => ... p(j) j i n(i) ...
+    if (next_i == nodejP) { // case ... p(i) i j n(j) ... => ... p(j) j i n(i) ...
       LOG_T(MAC,
-	    "Case ... p(i) i j n(j) ... => ... p(j) j i n(i) ...\n");
-
+            "Case ... p(i) i j n(j) ... => ... p(j) j i n(i) ...\n");
       listP->next[nodeiP] = next_j;
       listP->next[nodejP] = nodeiP;
 
-      if (nodeiP == listP->head) {	// case i j n(j)
-	listP->head = nodejP;
+      if (nodeiP == listP->head) {  // case i j n(j)
+        listP->head = nodejP;
       } else {
-	listP->next[prev_i] = nodejP;
+        listP->next[prev_i] = nodejP;
       }
-    } else if (next_j == nodeiP) {	// case ... p(j) j i n(i) ... => ... p(i) i j n(j) ...
+    } else if (next_j == nodeiP) {  // case ... p(j) j i n(i) ... => ... p(i) i j n(j) ...
       LOG_T(MAC,
-	    "Case ... p(j) j i n(i) ... => ... p(i) i j n(j) ...\n");
+            "Case ... p(j) j i n(i) ... => ... p(i) i j n(j) ...\n");
       listP->next[nodejP] = next_i;
       listP->next[nodeiP] = nodejP;
 
-      if (nodejP == listP->head) {	// case j i n(i)
-	listP->head = nodeiP;
+      if (nodejP == listP->head) {  // case j i n(i)
+        listP->head = nodeiP;
       } else {
-	listP->next[prev_j] = nodeiP;
+        listP->next[prev_j] = nodeiP;
       }
-    } else {		// case ...  p(i) i n(i) ... p(j) j n(j) ...
+    } else {    // case ...  p(i) i n(i) ... p(j) j n(j) ...
       listP->next[nodejP] = next_i;
       listP->next[nodeiP] = next_j;
 
       if (nodeiP == listP->head) {
-	LOG_T(MAC, "changing head to %d\n", nodejP);
-	listP->head = nodejP;
-	listP->next[prev_j] = nodeiP;
+        LOG_T(MAC, "changing head to %d\n", nodejP);
+        listP->head = nodejP;
+        listP->next[prev_j] = nodeiP;
       } else if (nodejP == listP->head) {
-	LOG_D(MAC, "changing head to %d\n", nodeiP);
-	listP->head = nodeiP;
-	listP->next[prev_i] = nodejP;
+        LOG_D(MAC, "changing head to %d\n", nodeiP);
+        listP->head = nodeiP;
+        listP->next[prev_i] = nodejP;
       } else {
-	listP->next[prev_i] = nodejP;
-	listP->next[prev_j] = nodeiP;
+        listP->next[prev_i] = nodejP;
+        listP->next[prev_j] = nodeiP;
       }
     }
-  } else {			// ul_flag
-
-    if (next_i == nodejP) {	// case ... p(i) i j n(j) ... => ... p(j) j i n(i) ...
+  } else {      // ul_flag
+    if (next_i == nodejP) { // case ... p(i) i j n(j) ... => ... p(j) j i n(i) ...
       LOG_T(MAC,
-	    "[UL] Case ... p(i) i j n(j) ... => ... p(j) j i n(i) ...\n");
-
+            "[UL] Case ... p(i) i j n(j) ... => ... p(j) j i n(i) ...\n");
       listP->next_ul[nodeiP] = next_j;
       listP->next_ul[nodejP] = nodeiP;
 
-      if (nodeiP == listP->head_ul) {	// case i j n(j)
-	listP->head_ul = nodejP;
+      if (nodeiP == listP->head_ul) { // case i j n(j)
+        listP->head_ul = nodejP;
       } else {
-	listP->next_ul[prev_i] = nodejP;
+        listP->next_ul[prev_i] = nodejP;
       }
-    } else if (next_j == nodeiP) {	// case ... p(j) j i n(i) ... => ... p(i) i j n(j) ...
+    } else if (next_j == nodeiP) {  // case ... p(j) j i n(i) ... => ... p(i) i j n(j) ...
       LOG_T(MAC,
-	    "[UL]Case ... p(j) j i n(i) ... => ... p(i) i j n(j) ...\n");
+            "[UL]Case ... p(j) j i n(i) ... => ... p(i) i j n(j) ...\n");
       listP->next_ul[nodejP] = next_i;
       listP->next_ul[nodeiP] = nodejP;
 
-      if (nodejP == listP->head_ul) {	// case j i n(i)
-	listP->head_ul = nodeiP;
+      if (nodejP == listP->head_ul) { // case j i n(i)
+        listP->head_ul = nodeiP;
       } else {
-	listP->next_ul[prev_j] = nodeiP;
+        listP->next_ul[prev_j] = nodeiP;
       }
-    } else {		// case ...  p(i) i n(i) ... p(j) j n(j) ...
-
+    } else {    // case ...  p(i) i n(i) ... p(j) j n(j) ...
       listP->next_ul[nodejP] = next_i;
       listP->next_ul[nodeiP] = next_j;
 
       if (nodeiP == listP->head_ul) {
-	LOG_T(MAC, "[UL]changing head to %d\n", nodejP);
-	listP->head_ul = nodejP;
-	listP->next_ul[prev_j] = nodeiP;
+        LOG_T(MAC, "[UL]changing head to %d\n", nodejP);
+        listP->head_ul = nodejP;
+        listP->next_ul[prev_j] = nodeiP;
       } else if (nodejP == listP->head_ul) {
-	LOG_T(MAC, "[UL]changing head to %d\n", nodeiP);
-	listP->head_ul = nodeiP;
-	listP->next_ul[prev_i] = nodejP;
+        LOG_T(MAC, "[UL]changing head to %d\n", nodeiP);
+        listP->head_ul = nodeiP;
+        listP->next_ul[prev_i] = nodejP;
       } else {
-	listP->next_ul[prev_i] = nodejP;
-	listP->next_ul[prev_j] = nodeiP;
+        listP->next_ul[prev_i] = nodejP;
+        listP->next_ul[prev_j] = nodeiP;
       }
     }
   }
@@ -2237,158 +2276,152 @@ void swap_UEs(UE_list_t * listP, int nodeiP, int nodejP, int ul_flag)
 
 // This has to be updated to include BSR information
 uint8_t
-UE_is_to_be_scheduled(module_id_t module_idP, int CC_id, uint8_t UE_id)
+UE_is_to_be_scheduled(module_id_t module_idP,
+                      int CC_id,
+                      uint8_t UE_id)
 {
-  UE_TEMPLATE *UE_template =
-    &RC.mac[module_idP]->UE_list.UE_template[CC_id][UE_id];
-  UE_sched_ctrl *UE_sched_ctl =
-    &RC.mac[module_idP]->UE_list.UE_sched_ctrl[UE_id];
+  UE_TEMPLATE *UE_template = &RC.mac[module_idP]->UE_list.UE_template[CC_id][UE_id];
+  UE_sched_ctrl *UE_sched_ctl = &RC.mac[module_idP]->UE_list.UE_sched_ctrl[UE_id];
 
   // do not schedule UE if UL is not working
-  if (UE_sched_ctl->ul_failure_timer > 0)
-    return (0);
-  if (UE_sched_ctl->ul_out_of_sync > 0)
-    return (0);
+  if (UE_sched_ctl->ul_failure_timer > 0 || UE_sched_ctl->ul_out_of_sync > 0)
+    return 0;
 
   LOG_D(MAC, "[eNB %d][PUSCH] Checking UL requirements UE %d/%x\n",
-	module_idP, UE_id, UE_RNTI(module_idP, UE_id));
+        module_idP, UE_id, UE_RNTI(module_idP, UE_id));
 
   if ((UE_template->scheduled_ul_bytes < UE_template->estimated_ul_buffer) ||
-      (UE_template->ul_SR > 0) ||	// uplink scheduling request
-      ((UE_sched_ctl->ul_inactivity_timer > 20) && (UE_sched_ctl->ul_scheduled == 0)) ||	// every 2 frames when RRC_CONNECTED
-      ((UE_sched_ctl->ul_inactivity_timer > 10) && (UE_sched_ctl->ul_scheduled == 0) && (mac_eNB_get_rrc_status(module_idP, UE_RNTI(module_idP, UE_id)) < RRC_CONNECTED)))	// every Frame when not RRC_CONNECTED
-    {
-      LOG_D(MAC,
-	    "[eNB %d][PUSCH] UE %d/%x should be scheduled (BSR0 estimated size %d, SR %d)\n",
-	    module_idP, UE_id, UE_RNTI(module_idP, UE_id),
-	    UE_template->ul_buffer_info[LCGID0], UE_template->ul_SR);
-      return (1);
-    } else {
-    return (0);
+      (UE_template->ul_SR > 0) || // uplink scheduling request
+      ((UE_sched_ctl->ul_inactivity_timer > 20) && (UE_sched_ctl->ul_scheduled == 0)) ||  // every 2 frames when RRC_CONNECTED
+      ((UE_sched_ctl->ul_inactivity_timer > 10) && (UE_sched_ctl->ul_scheduled == 0) &&
+       (mac_eNB_get_rrc_status(module_idP, UE_RNTI(module_idP, UE_id)) < RRC_CONNECTED))) { // every Frame when not RRC_CONNECTED
+    LOG_D(MAC,
+          "[eNB %d][PUSCH] UE %d/%x should be scheduled (BSR0 estimated size %d, SR %d)\n",
+          module_idP, UE_id, UE_RNTI(module_idP, UE_id),
+          UE_template->ul_buffer_info[LCGID0], UE_template->ul_SR);
+    return 1;
   }
+  return 0;
 }
 
-uint8_t get_tmode(module_id_t module_idP, int CC_idP, int UE_idP)
+uint8_t
+get_tmode(module_id_t module_idP,
+          int CC_idP,
+          int UE_idP)
 {
   eNB_MAC_INST *eNB = RC.mac[module_idP];
   COMMON_channels_t *cc = &eNB->common_channels[CC_idP];
 
-  struct PhysicalConfigDedicated *physicalConfigDedicated =
-    eNB->UE_list.physicalConfigDedicated[CC_idP][UE_idP];
+  struct LTE_PhysicalConfigDedicated *physicalConfigDedicated = eNB->UE_list.UE_template[CC_idP][UE_idP].physicalConfigDedicated;
 
-  if (physicalConfigDedicated == NULL) {	// RRCConnectionSetup not received by UE yet
-    AssertFatal(cc->p_eNB <= 2, "p_eNB is %d, should be <2\n",
-		cc->p_eNB);
+  if (physicalConfigDedicated == NULL) {  // RRCConnectionSetup not received by UE yet
+    AssertFatal(cc->p_eNB <= 2, "p_eNB is %d, should be <2\n", cc->p_eNB);
+    return (cc->p_eNB);
+  }
+
+  AssertFatal(physicalConfigDedicated->antennaInfo != NULL,
+              "antennaInfo (mod_id %d) is null for CCId %d, UEid %d, physicalConfigDedicated %p\n",
+              module_idP, CC_idP, UE_idP,physicalConfigDedicated);
+
+  AssertFatal(physicalConfigDedicated->antennaInfo->present != LTE_PhysicalConfigDedicated__antennaInfo_PR_NOTHING,
+              "antennaInfo (mod_id %d, CC_id %d) is set to NOTHING\n", module_idP, CC_idP);
+
+  if (physicalConfigDedicated->antennaInfo->present == LTE_PhysicalConfigDedicated__antennaInfo_PR_explicitValue) {
+    return (1 + physicalConfigDedicated->antennaInfo->choice.explicitValue.transmissionMode);
+  }
+
+  if (physicalConfigDedicated->antennaInfo->present == LTE_PhysicalConfigDedicated__antennaInfo_PR_defaultValue) {
+    AssertFatal(cc->p_eNB <= 2, "p_eNB is %d, should be <2\n", cc->p_eNB);
     return (cc->p_eNB);
-  } else {
-    AssertFatal(physicalConfigDedicated->antennaInfo != NULL,
-		"antennaInfo is null for CCId %d, UEid %d\n", CC_idP,
-		UE_idP);
-
-    AssertFatal(physicalConfigDedicated->antennaInfo->present !=
-		PhysicalConfigDedicated__antennaInfo_PR_NOTHING,
-		"antennaInfo (mod_id %d, CC_id %d) is set to NOTHING\n",
-		module_idP, CC_idP);
-
-    if (physicalConfigDedicated->antennaInfo->present ==
-	PhysicalConfigDedicated__antennaInfo_PR_explicitValue) {
-      return (physicalConfigDedicated->antennaInfo->
-	      choice.explicitValue.transmissionMode);
-    } else if (physicalConfigDedicated->antennaInfo->present ==
-	       PhysicalConfigDedicated__antennaInfo_PR_defaultValue) {
-      AssertFatal(cc->p_eNB <= 2, "p_eNB is %d, should be <2\n",
-		  cc->p_eNB);
-      return (cc->p_eNB);
-    } else
-      AssertFatal(1 == 0, "Shouldn't be here\n");
   }
+
+  AssertFatal(1 == 0, "Shouldn't be here\n");
+  return 0;
 }
 
 int8_t
 get_ULharq(module_id_t module_idP, int CC_idP, uint16_t frameP,
-	   uint8_t subframeP)
-{
+           uint8_t subframeP) {
   uint8_t ret = -1;
   eNB_MAC_INST *eNB = RC.mac[module_idP];
   COMMON_channels_t *cc = &eNB->common_channels[CC_idP];
 
-  if (cc->tdd_Config == NULL) {	// FDD
+  if (cc->tdd_Config == NULL) { // FDD
     ret = (((frameP << 1) + subframeP) & 7);
   } else {
     switch (cc->tdd_Config->subframeAssignment) {
-    case 1:
-      if ((subframeP == 2) ||
-	  (subframeP == 3) || (subframeP == 7) || (subframeP == 8))
-	switch (subframeP) {
-	case 2:
-	case 3:
-	  ret = (subframeP - 2);
-	  break;
-
-	case 7:
-	case 8:
-	  ret = (subframeP - 5);
-	  break;
-
-	default:
-	  AssertFatal(1 == 0,
-		      "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",
-		      subframeP,
-		      (int) cc->tdd_Config->subframeAssignment);
-	  break;
-	}
+      case 1:
+        if ((subframeP == 2) ||
+            (subframeP == 3) || (subframeP == 7) || (subframeP == 8))
+          switch (subframeP) {
+            case 2:
+            case 3:
+              ret = (subframeP - 2);
+              break;
 
-      break;
+            case 7:
+            case 8:
+              ret = (subframeP - 5);
+              break;
 
-    case 2:
-      AssertFatal((subframeP == 2) || (subframeP == 7),
-		  "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",
-		  subframeP,
-		  (int) cc->tdd_Config->subframeAssignment);
-      ret = (subframeP / 7);
-      break;
+            default:
+              AssertFatal(1 == 0,
+                          "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",
+                          subframeP,
+                          (int) cc->tdd_Config->subframeAssignment);
+              break;
+          }
 
-    case 3:
-      AssertFatal((subframeP > 1) && (subframeP < 5),
-		  "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",
-		  subframeP,
-		  (int) cc->tdd_Config->subframeAssignment);
-      ret = (subframeP - 2);
-      break;
+        break;
 
-    case 4:
-      AssertFatal((subframeP > 1) && (subframeP < 4),
-		  "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",
-		  subframeP,
-		  (int) cc->tdd_Config->subframeAssignment);
-      ret = (subframeP - 2);
-      break;
+      case 2:
+        AssertFatal((subframeP == 2) || (subframeP == 7),
+                    "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",
+                    subframeP,
+                    (int) cc->tdd_Config->subframeAssignment);
+        ret = (subframeP / 7);
+        break;
 
-    case 5:
-      AssertFatal(subframeP == 2,
-		  "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",
-		  subframeP,
-		  (int) cc->tdd_Config->subframeAssignment);
-      ret = (subframeP - 2);
-      break;
+      case 3:
+        AssertFatal((subframeP > 1) && (subframeP < 5),
+                    "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",
+                    subframeP,
+                    (int) cc->tdd_Config->subframeAssignment);
+        ret = (subframeP - 2);
+        break;
 
-    default:
-      AssertFatal(1 == 0,
-		  "subframe2_harq_pid, Unsupported TDD mode %d\n",
-		  (int) cc->tdd_Config->subframeAssignment);
-      break;
+      case 4:
+        AssertFatal((subframeP > 1) && (subframeP < 4),
+                    "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",
+                    subframeP,
+                    (int) cc->tdd_Config->subframeAssignment);
+        ret = (subframeP - 2);
+        break;
+
+      case 5:
+        AssertFatal(subframeP == 2,
+                    "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",
+                    subframeP,
+                    (int) cc->tdd_Config->subframeAssignment);
+        ret = (subframeP - 2);
+        break;
+
+      default:
+        AssertFatal(1 == 0,
+                    "subframe2_harq_pid, Unsupported TDD mode %d\n",
+                    (int) cc->tdd_Config->subframeAssignment);
+        break;
     }
   }
 
   AssertFatal(ret != -1,
-	      "invalid harq_pid(%d) at SFN/SF = %d/%d\n", (int8_t) ret,
-	      frameP, subframeP);
+              "invalid harq_pid(%d) at SFN/SF = %d/%d\n", (int8_t) ret,
+              frameP, subframeP);
   return ret;
 }
 
 
-uint16_t getRIV(uint16_t N_RB_DL, uint16_t RBstart, uint16_t Lcrbs)
-{
+uint16_t getRIV(uint16_t N_RB_DL, uint16_t RBstart, uint16_t Lcrbs) {
   uint16_t RIV;
 
   if (Lcrbs <= (1 + (N_RB_DL >> 1)))
@@ -2401,8 +2434,7 @@ uint16_t getRIV(uint16_t N_RB_DL, uint16_t RBstart, uint16_t Lcrbs)
 
 uint32_t
 allocate_prbs(int UE_id, unsigned char nb_rb, int N_RB_DL,
-	      uint32_t * rballoc)
-{
+              uint32_t *rballoc) {
   int i;
   uint32_t rballoc_dci = 0;
   unsigned char nb_rb_alloc = 0;
@@ -2429,82 +2461,77 @@ allocate_prbs(int UE_id, unsigned char nb_rb, int N_RB_DL,
   return (rballoc_dci);
 }
 
-int get_bw_index(module_id_t module_id, uint8_t CC_id)
-{
+int get_bw_index(module_id_t module_id, uint8_t CC_id) {
   int bw_index = 0;
-
   int N_RB_DL = to_prb(RC.mac[module_id]->common_channels[CC_id].mib->message.dl_Bandwidth);
 
   switch (N_RB_DL) {
-  case 6:			// 1.4 MHz
-    bw_index = 0;
-    break;
+    case 6:     // 1.4 MHz
+      bw_index = 0;
+      break;
 
-  case 25:			// 5HMz
-    bw_index = 1;
-    break;
+    case 25:      // 5HMz
+      bw_index = 1;
+      break;
 
-  case 50:			// 10HMz
-    bw_index = 2;
-    break;
+    case 50:      // 10HMz
+      bw_index = 2;
+      break;
 
-  case 100:			// 20HMz
-    bw_index = 3;
-    break;
+    case 100:     // 20HMz
+      bw_index = 3;
+      break;
 
-  default:
-    bw_index = 1;
-    LOG_W(MAC,
-	  "[eNB %d] N_RB_DL %d unknown for CC_id %d, setting bw_index to 1\n",
-	  module_id, N_RB_DL, CC_id);
-    break;
+    default:
+      bw_index = 1;
+      LOG_W(MAC,
+            "[eNB %d] N_RB_DL %d unknown for CC_id %d, setting bw_index to 1\n",
+            module_id, N_RB_DL, CC_id);
+      break;
   }
 
   return bw_index;
 }
 
-int get_min_rb_unit(module_id_t module_id, uint8_t CC_id)
-{
+int get_min_rb_unit(module_id_t module_id, uint8_t CC_id) {
   int min_rb_unit = 0;
   int N_RB_DL = to_prb(RC.mac[module_id]->common_channels[CC_id].mib->message.dl_Bandwidth);
 
   switch (N_RB_DL) {
-  case 6:			// 1.4 MHz
-    min_rb_unit = 1;
-    break;
+    case 6:     // 1.4 MHz
+      min_rb_unit = 1;
+      break;
 
-  case 25:			// 5HMz
-    min_rb_unit = 2;
-    break;
+    case 25:      // 5HMz
+      min_rb_unit = 2;
+      break;
 
-  case 50:			// 10HMz
-    min_rb_unit = 3;
-    break;
+    case 50:      // 10HMz
+      min_rb_unit = 3;
+      break;
 
-  case 100:			// 20HMz
-    min_rb_unit = 4;
-    break;
+    case 100:     // 20HMz
+      min_rb_unit = 4;
+      break;
 
-  default:
-    min_rb_unit = 2;
-    LOG_W(MAC,
-	  "[eNB %d] N_DL_RB %d unknown for CC_id %d, setting min_rb_unit to 2\n",
-	  module_id, N_RB_DL, CC_id);
-    break;
+    default:
+      min_rb_unit = 2;
+      LOG_W(MAC,
+            "[eNB %d] N_DL_RB %d unknown for CC_id %d, setting min_rb_unit to 2\n",
+            module_id, N_RB_DL, CC_id);
+      break;
   }
 
   return min_rb_unit;
 }
 
 uint32_t
-allocate_prbs_sub(int nb_rb, int N_RB_DL, int N_RBG, uint8_t * rballoc)
-{
-  int check = 0;		//check1=0,check2=0;
+allocate_prbs_sub(int nb_rb, int N_RB_DL, int N_RBG, uint8_t *rballoc) {
+  int check = 0;    //check1=0,check2=0;
   uint32_t rballoc_dci = 0;
   //uint8_t number_of_subbands=13;
-
   LOG_T(MAC, "*****Check1RBALLOC****: %d%d%d%d (nb_rb %d,N_RBG %d)\n",
-	rballoc[3], rballoc[2], rballoc[1], rballoc[0], nb_rb, N_RBG);
+        rballoc[3], rballoc[2], rballoc[1], rballoc[0], nb_rb, N_RBG);
 
   while ((nb_rb > 0) && (check < N_RBG)) {
     //printf("rballoc[%d] %d\n",check,rballoc[check]);
@@ -2512,33 +2539,34 @@ allocate_prbs_sub(int nb_rb, int N_RB_DL, int N_RBG, uint8_t * rballoc)
       rballoc_dci |= (1 << ((N_RBG - 1) - check));
 
       switch (N_RB_DL) {
-      case 6:
-	nb_rb--;
-	break;
+        case 6:
+          nb_rb--;
+          break;
 
-      case 25:
-	if ((check == N_RBG - 1)) {
-	  nb_rb--;
-	} else {
-	  nb_rb -= 2;
-	}
+        case 25:
+          if ((check == N_RBG - 1)) {
+            nb_rb--;
+          } else {
+            nb_rb -= 2;
+          }
 
-	break;
+          break;
 
-      case 50:
-	if ((check == N_RBG - 1)) {
-	  nb_rb -= 2;
-	} else {
-	  nb_rb -= 3;
-	}
+        case 50:
+          if ((check == N_RBG - 1)) {
+            nb_rb -= 2;
+          } else {
+            nb_rb -= 3;
+          }
 
-	break;
+          break;
 
-      case 100:
-	nb_rb -= 4;
-	break;
+        case 100:
+          nb_rb -= 4;
+          break;
       }
     }
+
     //      printf("rb_alloc %x\n",rballoc_dci);
     check = check + 1;
     //    check1 = check1+2;
@@ -2550,67 +2578,71 @@ allocate_prbs_sub(int nb_rb, int N_RB_DL, int N_RBG, uint8_t * rballoc)
   return (rballoc_dci);
 }
 
-int get_subbandsize(uint8_t dl_Bandwidth)
-{
+int get_subbandsize(uint8_t dl_Bandwidth) {
   uint8_t ss[6] = { 6, 4, 4, 6, 8, 8 };
-
   AssertFatal(dl_Bandwidth < 6, "dl_Bandwidth %d is out of bounds\n",
-	      dl_Bandwidth);
-
+              dl_Bandwidth);
   return (ss[dl_Bandwidth]);
 }
 
-int get_nb_subband(int N_RB_DL)
-{
+int get_nb_subband(int N_RB_DL) {
   int nb_sb = 0;
 
   switch (N_RB_DL) {
-  case 6:
-    nb_sb = 0;
-    break;
+    case 6:
+      nb_sb = 0;
+      break;
 
-  case 15:
-    nb_sb = 4;		// sb_size =4
+    case 15:
+      nb_sb = 4;    // sb_size =4
+      break;
 
-  case 25:
-    nb_sb = 7;		// sb_size =4, 1 sb with 1PRB, 6 with 2 RBG, each has 2 PRBs
-    break;
+    case 25:
+      nb_sb = 7;    // sb_size =4, 1 sb with 1PRB, 6 with 2 RBG, each has 2 PRBs
+      break;
 
-  case 50:			// sb_size =6
-    nb_sb = 9;
-    break;
+    case 50:      // sb_size =6
+      nb_sb = 9;
+      break;
 
-  case 75:			// sb_size =8
-    nb_sb = 10;
-    break;
+    case 75:      // sb_size =8
+      nb_sb = 10;
+      break;
 
-  case 100:			// sb_size =8 , 1 sb with 1 RBG + 12 sb with 2RBG, each RBG has 4 PRBs
-    nb_sb = 13;
-    break;
+    case 100:     // sb_size =8 , 1 sb with 1 RBG + 12 sb with 2RBG, each RBG has 4 PRBs
+      nb_sb = 13;
+      break;
 
-  default:
-    nb_sb = 0;
-    break;
+    default:
+      nb_sb = 0;
+      break;
   }
 
   return nb_sb;
 }
-
-void init_CCE_table(int module_idP, int CC_idP)
+/*
+void
+init_CCE_table(int module_idP,
+               int CC_idP)
 {
   memset(RC.mac[module_idP]->CCE_table[CC_idP], 0, 800 * sizeof(int));
 }
-
+*/
+void
+init_CCE_table(int *CCE_table)
+{
+  memset(CCE_table, 0, 800 * sizeof(int));
+}
 
 int
 get_nCCE_offset(int *CCE_table,
-		const unsigned char L,
-		const int nCCE,
-		const int common_dci,
-		const unsigned short rnti, const unsigned char subframe)
-{
+                const unsigned char L,
+                const int nCCE,
+                const int common_dci,
+                const unsigned short rnti, const unsigned char subframe) {
   int search_space_free, m, nb_candidates = 0, l, i;
   unsigned int Yk;
+
   /*
     printf("CCE Allocation: ");
     for (i=0;i<nCCE;i++)
@@ -2625,30 +2657,27 @@ get_nCCE_offset(int *CCE_table,
     //    printf("Common DCI nb_candidates %d, L %d\n",nb_candidates,L);
 
     for (m = nb_candidates - 1; m >= 0; m--) {
-
       search_space_free = 1;
-      for (l = 0; l < L; l++) {
 
-	//        printf("CCE_table[%d] %d\n",(m*L)+l,CCE_table[(m*L)+l]);
-	if (CCE_table[(m * L) + l] == 1) {
-	  search_space_free = 0;
-	  break;
-	}
+      for (l = 0; l < L; l++) {
+        //        printf("CCE_table[%d] %d\n",(m*L)+l,CCE_table[(m*L)+l]);
+        if (CCE_table[(m * L) + l] == 1) {
+          search_space_free = 0;
+          break;
+        }
       }
 
       if (search_space_free == 1) {
+        //        printf("returning %d\n",m*L);
+        for (l = 0; l < L; l++)
+          CCE_table[(m * L) + l] = 1;
 
-	//        printf("returning %d\n",m*L);
-
-	for (l = 0; l < L; l++)
-	  CCE_table[(m * L) + l] = 1;
-	return (m * L);
+        return (m * L);
       }
     }
 
     return (-1);
-
-  } else {			// Find first available in ue specific search space
+  } else {      // Find first available in ue specific search space
     // according to procedure in Section 9.1.1 of 36.213 (v. 8.6)
     // compute Yk
     Yk = (unsigned int) rnti;
@@ -2659,40 +2688,41 @@ get_nCCE_offset(int *CCE_table,
     Yk = Yk % (nCCE / L);
 
     switch (L) {
-    case 1:
-    case 2:
-      nb_candidates = 6;
-      break;
+      case 1:
+      case 2:
+        nb_candidates = 6;
+        break;
 
-    case 4:
-    case 8:
-      nb_candidates = 2;
-      break;
+      case 4:
+      case 8:
+        nb_candidates = 2;
+        break;
 
-    default:
-      DevParam(L, nCCE, rnti);
-      break;
+      default:
+        DevParam(L, nCCE, rnti);
+        break;
     }
 
     LOG_D(MAC, "rnti %x, Yk = %d, nCCE %d (nCCE/L %d),nb_cand %d\n",
-	  rnti, Yk, nCCE, nCCE / L, nb_candidates);
+          rnti, Yk, nCCE, nCCE / L, nb_candidates);
 
     for (m = 0; m < nb_candidates; m++) {
       search_space_free = 1;
 
       for (l = 0; l < L; l++) {
-	int cce = (((Yk + m) % (nCCE / L)) * L) + l;
-	if (cce >= nCCE || CCE_table[cce] == 1) {
-	  search_space_free = 0;
-	  break;
-	}
+        int cce = (((Yk + m) % (nCCE / L)) * L) + l;
+
+        if (cce >= nCCE || CCE_table[cce] == 1) {
+          search_space_free = 0;
+          break;
+        }
       }
 
       if (search_space_free == 1) {
-	for (l = 0; l < L; l++)
-	  CCE_table[(((Yk + m) % (nCCE / L)) * L) + l] = 1;
+        for (l = 0; l < L; l++)
+          CCE_table[(((Yk + m) % (nCCE / L)) * L) + l] = 1;
 
-	return (((Yk + m) % (nCCE / L)) * L);
+        return (((Yk + m) % (nCCE / L)) * L);
       }
     }
 
@@ -2702,14 +2732,14 @@ get_nCCE_offset(int *CCE_table,
 
 void
 dump_CCE_table(int *CCE_table, const int nCCE,
-	       const unsigned short rnti, const int subframe, int L)
-{
+               const unsigned short rnti, const int subframe, int L) {
   int nb_candidates = 0, i;
   unsigned int Yk;
-
   printf("CCE 0: ");
+
   for (i = 0; i < nCCE; i++) {
     printf("%1d.", CCE_table[i]);
+
     if ((i & 7) == 7)
       printf("\n CCE %d: ", i);
   }
@@ -2719,39 +2749,35 @@ dump_CCE_table(int *CCE_table, const int nCCE,
   for (i = 0; i <= subframe; i++)
     Yk = (Yk * 39827) % 65537;
 
-  Yk = Yk % (nCCE / L);
+  Yk = Yk % (nCCE / L);
+
+  switch (L) {
+    case 1:
+    case 2:
+      nb_candidates = 6;
+      break;
+
+    case 4:
+    case 8:
+      nb_candidates = 2;
+      break;
 
-  switch (L) {
-  case 1:
-  case 2:
-    nb_candidates = 6;
-    break;
-
-  case 4:
-  case 8:
-    nb_candidates = 2;
-    break;
-
-  default:
-    DevParam(L, nCCE, rnti);
-    break;
+    default:
+      DevParam(L, nCCE, rnti);
+      break;
   }
 
-  printf("rnti %x, Yk*L = %d, nCCE %d (nCCE/L %d),nb_cand*L %d\n", rnti,
-	 Yk * L, nCCE, nCCE / L, nb_candidates * L);
+  printf("rnti %x, Yk*L = %u, nCCE %d (nCCE/L %d),nb_cand*L %d\n", rnti,
+         Yk * L, nCCE, nCCE / L, nb_candidates * L);
 }
 
 uint16_t
-getnquad(COMMON_channels_t * cc, uint8_t num_pdcch_symbols, uint8_t mi)
-{
+getnquad(COMMON_channels_t *cc, uint8_t num_pdcch_symbols, uint8_t mi) {
   uint16_t Nreg = 0;
-
   AssertFatal(cc != NULL, "cc is null\n");
   AssertFatal(cc->mib != NULL, "cc->mib is null\n");
-
   int N_RB_DL = to_prb(cc->mib->message.dl_Bandwidth);
   int phich_resource = get_phich_resource_times6(cc);
-
   uint8_t Ngroup_PHICH = (phich_resource * N_RB_DL) / 48;
 
   if (((phich_resource * N_RB_DL) % 48) > 0)
@@ -2765,515 +2791,505 @@ getnquad(COMMON_channels_t * cc, uint8_t num_pdcch_symbols, uint8_t mi)
 
   if ((num_pdcch_symbols > 0) && (num_pdcch_symbols < 4))
     switch (N_RB_DL) {
-    case 6:
-      Nreg = 12 + (num_pdcch_symbols - 1) * 18;
-      break;
+      case 6:
+        Nreg = 12 + (num_pdcch_symbols - 1) * 18;
+        break;
 
-    case 25:
-      Nreg = 50 + (num_pdcch_symbols - 1) * 75;
-      break;
+      case 25:
+        Nreg = 50 + (num_pdcch_symbols - 1) * 75;
+        break;
 
-    case 50:
-      Nreg = 100 + (num_pdcch_symbols - 1) * 150;
-      break;
+      case 50:
+        Nreg = 100 + (num_pdcch_symbols - 1) * 150;
+        break;
 
-    case 100:
-      Nreg = 200 + (num_pdcch_symbols - 1) * 300;
-      break;
+      case 100:
+        Nreg = 200 + (num_pdcch_symbols - 1) * 300;
+        break;
 
-    default:
-      return (0);
+      default:
+        return (0);
     }
+
   //   printf("Nreg %d (%d)\n",Nreg,Nreg - 4 - (3*Ngroup_PHICH));
   return (Nreg - 4 - (3 * Ngroup_PHICH));
 }
 
 uint16_t
-getnCCE(COMMON_channels_t * cc, uint8_t num_pdcch_symbols, uint8_t mi)
-{
+getnCCE(COMMON_channels_t *cc, uint8_t num_pdcch_symbols, uint8_t mi) {
   AssertFatal(cc != NULL, "cc is null\n");
   return (getnquad(cc, num_pdcch_symbols, mi) / 9);
 }
 
-uint8_t getmi(COMMON_channels_t * cc, int subframe)
-{
+uint8_t getmi(COMMON_channels_t *cc, int subframe) {
   AssertFatal(cc != NULL, "cc is null\n");
 
   // for FDD
-  if (cc->tdd_Config == NULL)	// FDD
+  if (cc->tdd_Config == NULL) // FDD
     return 1;
 
   // for TDD
   switch (cc->tdd_Config->subframeAssignment) {
-  case 0:
-    if ((subframe == 0) || (subframe == 5))
-      return (2);
-    else
-      return (1);
+    case 0:
+      if ((subframe == 0) || (subframe == 5))
+        return (2);
+      else
+        return (1);
 
-    break;
+      break;
 
-  case 1:
-    if ((subframe == 0) || (subframe == 5))
-      return (0);
-    else
-      return (1);
+    case 1:
+      if ((subframe == 0) || (subframe == 5))
+        return (0);
+      else
+        return (1);
 
-    break;
+      break;
 
-  case 2:
-    if ((subframe == 3) || (subframe == 8))
-      return (1);
-    else
-      return (0);
+    case 2:
+      if ((subframe == 3) || (subframe == 8))
+        return (1);
+      else
+        return (0);
 
-    break;
+      break;
 
-  case 3:
-    if ((subframe == 0) || (subframe == 8) || (subframe == 9))
-      return (1);
-    else
-      return (0);
+    case 3:
+      if ((subframe == 0) || (subframe == 8) || (subframe == 9))
+        return (1);
+      else
+        return (0);
 
-    break;
+      break;
 
-  case 4:
-    if ((subframe == 8) || (subframe == 9))
-      return (1);
-    else
-      return (0);
+    case 4:
+      if ((subframe == 8) || (subframe == 9))
+        return (1);
+      else
+        return (0);
 
-    break;
+      break;
 
-  case 5:
-    if (subframe == 8)
-      return (1);
-    else
-      return (0);
+    case 5:
+      if (subframe == 8)
+        return (1);
+      else
+        return (0);
 
-    break;
+      break;
 
-  case 6:
-    return (1);
-    break;
+    case 6:
+      return (1);
+      break;
 
-  default:
-    return (0);
+    default:
+      return (0);
   }
 }
 
 uint16_t
-get_nCCE_max(COMMON_channels_t * cc, int num_pdcch_symbols, int subframe)
-{
+get_nCCE_max(COMMON_channels_t *cc, int num_pdcch_symbols, int subframe) {
   AssertFatal(cc != NULL, "cc is null\n");
   return (getnCCE(cc, num_pdcch_symbols, getmi(cc, subframe)));
 }
 
 // Allocate the CCEs
 int
-allocate_CCEs(int module_idP, int CC_idP, frame_t frameP, sub_frame_t subframeP, int test_onlyP)
+allocate_CCEs(int module_idP,
+              int CC_idP,
+              frame_t frameP,
+              sub_frame_t subframeP,
+              int test_onlyP)
 {
-  int *CCE_table = RC.mac[module_idP]->CCE_table[CC_idP];
-  nfapi_dl_config_request_body_t *DL_req =
-    &RC.mac[module_idP]->DL_req[CC_idP].dl_config_request_body;
-  nfapi_hi_dci0_request_body_t *HI_DCI0_req =
-    &RC.mac[module_idP]->HI_DCI0_req[CC_idP][subframeP].hi_dci0_request_body;
-  nfapi_dl_config_request_pdu_t *dl_config_pdu =
-    &DL_req->dl_config_pdu_list[0];
-  nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu =
-    &HI_DCI0_req->hi_dci0_pdu_list[0];
-  int nCCE_max =
-    get_nCCE_max(&RC.mac[module_idP]->common_channels[CC_idP], 1,
-		 subframeP);
+  eNB_MAC_INST *eNB = RC.mac[module_idP];
+  int *CCE_table = eNB->CCE_table[CC_idP];
+  nfapi_dl_config_request_body_t *DL_req = &eNB->DL_req[CC_idP].dl_config_request_body;
+  nfapi_hi_dci0_request_body_t *HI_DCI0_req = &eNB->HI_DCI0_req[CC_idP][subframeP].hi_dci0_request_body;
+  nfapi_dl_config_request_pdu_t *dl_config_pdu = &DL_req->dl_config_pdu_list[0];
+  nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu = &HI_DCI0_req->hi_dci0_pdu_list[0];
+  COMMON_channels_t *cc = &eNB->common_channels[CC_idP];
+  int nCCE_max = get_nCCE_max(cc, 1, subframeP);
   int fCCE;
   int i, j, idci;
   int nCCE = 0;
   int max_symbol;
-
-  eNB_MAC_INST *eNB = RC.mac[module_idP];
-  COMMON_channels_t *cc = &eNB->common_channels[CC_idP];
   int ackNAK_absSF = get_pucch1_absSF(cc, (frameP*10+subframeP));
+  nfapi_dl_config_request_pdu_t *dl_config_pduLoop;
+  nfapi_hi_dci0_request_pdu_t *hi_dci0_pduLoop;
+
   if (cc->tdd_Config!=NULL && is_S_sf(cc,subframeP) > 0)
     max_symbol = 2;
   else
     max_symbol = 3;
 
   nfapi_ul_config_request_body_t *ul_req = &eNB->UL_req_tmp[CC_idP][ackNAK_absSF % 10].ul_config_request_body;
-
-  LOG_D(MAC,
-	"Allocate CCEs subframe %d, test %d : (DL PDU %d, DL DCI %d, UL %d)\n",
-	subframeP, test_onlyP, DL_req->number_pdu, DL_req->number_dci,
-	HI_DCI0_req->number_of_dci);
+  LOG_D(MAC, "Allocate CCEs subframe %d, test %d : (DL PDU %d, DL DCI %d, UL %d)\n",
+        subframeP,
+        test_onlyP,
+        DL_req->number_pdu,
+        DL_req->number_dci,
+        HI_DCI0_req->number_of_dci);
   DL_req->number_pdcch_ofdm_symbols = 1;
 
- try_again:
-  init_CCE_table(module_idP, CC_idP);
+try_again:
+
+  init_CCE_table(CCE_table);
   nCCE = 0;
 
   for (i = 0, idci = 0; i < DL_req->number_pdu; i++) {
+    dl_config_pduLoop = &dl_config_pdu[i];
     // allocate DL common DCIs first
-    if ((dl_config_pdu[i].pdu_type == NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE)
-	&& (dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti_type ==
-	    2)) {
-      LOG_D(MAC,
-	    "Trying to allocate COMMON DCI %d/%d (%d,%d) : rnti %x, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n",
-	    idci, DL_req->number_dci + HI_DCI0_req->number_of_dci,
-	    DL_req->number_dci, HI_DCI0_req->number_of_dci,
-	    dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti,
-	    dl_config_pdu[i].dci_dl_pdu.
-	    dci_dl_pdu_rel8.aggregation_level, nCCE, nCCE_max,
-	    DL_req->number_pdcch_ofdm_symbols);
-
-      if (nCCE +
-	  (dl_config_pdu[i].dci_dl_pdu.
-	   dci_dl_pdu_rel8.aggregation_level) > nCCE_max) {
-	if (DL_req->number_pdcch_ofdm_symbols == max_symbol)
-	  goto failed;
-	LOG_D(MAC,
-	      "Can't fit DCI allocations with %d PDCCH symbols, increasing by 1\n",
-	      DL_req->number_pdcch_ofdm_symbols);
-	DL_req->number_pdcch_ofdm_symbols++;
-	nCCE_max =
-	  get_nCCE_max(&RC.mac[module_idP]->
-		       common_channels[CC_idP],
-		       DL_req->number_pdcch_ofdm_symbols,
-		       subframeP);
-	goto try_again;
+    if (dl_config_pduLoop->pdu_type == NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE &&
+        dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type == 2) {
+      LOG_D(MAC, "Trying to allocate COMMON DCI %d/%d (%d,%d) : rnti %x, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n",
+            idci,
+            DL_req->number_dci + HI_DCI0_req->number_of_dci,
+            DL_req->number_dci,
+            HI_DCI0_req->number_of_dci,
+            dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.rnti,
+            dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level,
+            nCCE,
+            nCCE_max,
+            DL_req->number_pdcch_ofdm_symbols);
+
+      if (nCCE + (dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level) > nCCE_max) {
+        if (DL_req->number_pdcch_ofdm_symbols == max_symbol)
+          return -1;
+
+        LOG_D(MAC, "Can't fit DCI allocations with %d PDCCH symbols, increasing by 1\n",
+              DL_req->number_pdcch_ofdm_symbols);
+        DL_req->number_pdcch_ofdm_symbols++;
+        nCCE_max = get_nCCE_max(cc, DL_req->number_pdcch_ofdm_symbols, subframeP);
+        goto try_again;
       }
+
       // number of CCEs left can potentially hold this allocation
       fCCE = get_nCCE_offset(CCE_table,
-			     dl_config_pdu[i].
-			     dci_dl_pdu.dci_dl_pdu_rel8.
-			     aggregation_level, nCCE_max, 1,
-			     dl_config_pdu[i].
-			     dci_dl_pdu.dci_dl_pdu_rel8.rnti,
-			     subframeP);
+                             dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level,
+                             nCCE_max,
+                             1,
+                             dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.rnti,
+                             subframeP);
+
       if (fCCE == -1) {
-	if (DL_req->number_pdcch_ofdm_symbols == max_symbol) {
-	  LOG_D(MAC,
-		"subframe %d: Dropping Allocation for RNTI %x\n",
-		subframeP,
-		dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.
-		rnti);
-	  for (j = 0; j <= i; j++) {
-	    if (dl_config_pdu[j].pdu_type ==
-		NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE)
-	      LOG_D(MAC,
-		    "DCI %d/%d (%d,%d) : rnti %x dci format %d, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n",
-		    j,
-		    DL_req->number_dci +
-		    HI_DCI0_req->number_of_dci,
-		    DL_req->number_dci,
-		    HI_DCI0_req->number_of_dci,
-		    dl_config_pdu[j].
-		    dci_dl_pdu.dci_dl_pdu_rel8.rnti,
-		    dl_config_pdu[j].
-		    dci_dl_pdu.dci_dl_pdu_rel8.dci_format,
-		    dl_config_pdu[j].
-		    dci_dl_pdu.dci_dl_pdu_rel8.
-		    aggregation_level, nCCE, nCCE_max,
-		    DL_req->number_pdcch_ofdm_symbols);
-	  }
-	  //dump_CCE_table(CCE_table,nCCE_max,subframeP,dci_alloc->rnti,1<<dci_alloc->L);
-	  goto failed;
-	}
-	LOG_D(MAC,
-	      "Can't fit DCI allocations with %d PDCCH symbols (rnti condition), increasing by 1\n",
-	      DL_req->number_pdcch_ofdm_symbols);
-
-	DL_req->number_pdcch_ofdm_symbols++;
-	nCCE_max =  get_nCCE_max(&RC.mac[module_idP]->
-				 common_channels[CC_idP],
-				 DL_req->number_pdcch_ofdm_symbols,
-				 subframeP);
-	goto try_again;
-      }			// fCCE==-1
+        if (DL_req->number_pdcch_ofdm_symbols == max_symbol) {
+          LOG_D(MAC, "subframe %d: Dropping Allocation for RNTI %x\n",
+                subframeP,
+                dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.rnti);
+
+          for (j = 0; j <= i; j++) {
+            dl_config_pduLoop = &dl_config_pdu[j];
+            if (dl_config_pduLoop->pdu_type == NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE)
+              LOG_D(MAC, "DCI %d/%d (%d,%d) : rnti %x dci format %d, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n",
+                    j,
+                    DL_req->number_dci + HI_DCI0_req->number_of_dci,
+                    DL_req->number_dci,
+                    HI_DCI0_req->number_of_dci,
+                    dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.rnti,
+                    dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.dci_format,
+                    dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level,
+                    nCCE, nCCE_max, DL_req->number_pdcch_ofdm_symbols);
+          }
+          //dump_CCE_table(CCE_table,nCCE_max,subframeP,dci_alloc->rnti,1<<dci_alloc->L);
+          return -1;
+        }
+
+        LOG_D(MAC, "Can't fit DCI allocations with %d PDCCH symbols (rnti condition), increasing by 1\n",
+              DL_req->number_pdcch_ofdm_symbols);
+        DL_req->number_pdcch_ofdm_symbols++;
+        nCCE_max = get_nCCE_max(cc, DL_req->number_pdcch_ofdm_symbols, subframeP);
+        goto try_again;
+      }     // fCCE==-1
 
       // the allocation is feasible, rnti rule passes
-      nCCE += dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level;
+      nCCE += dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level;
       LOG_D(MAC, "Allocating at nCCE %d\n", fCCE);
+
       if ((test_onlyP%2) == 0) {
-	dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.cce_idx = fCCE;
-	LOG_D(MAC,
-	      "Allocate COMMON DCI CCEs subframe %d, test %d => L %d fCCE %d\n",
-	      subframeP, test_onlyP,
-	      dl_config_pdu[i].dci_dl_pdu.
-	      dci_dl_pdu_rel8.aggregation_level, fCCE);
+        dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.cce_idx = fCCE;
+        LOG_D(MAC, "Allocate COMMON DCI CCEs subframe %d, test %d => L %d fCCE %d\n",
+              subframeP,
+              test_onlyP,
+              dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level,
+              fCCE);
       }
+
       idci++;
     }
-  }				// for i = 0 ... num_DL_DCIs
+  }       // for i = 0 ... num_DL_DCIs
 
   // no try to allocate UL DCIs
-  for (i = 0; i < HI_DCI0_req->number_of_dci + HI_DCI0_req->number_of_hi;
-       i++) {
-
+  for (i = 0; i < HI_DCI0_req->number_of_dci + HI_DCI0_req->number_of_hi; i++) {
+    hi_dci0_pduLoop = &hi_dci0_pdu[i];
     // allocate UL DCIs
     if (hi_dci0_pdu[i].pdu_type == NFAPI_HI_DCI0_DCI_PDU_TYPE) {
-
-      LOG_D(MAC,
-	    "Trying to allocate format 0 DCI %d/%d (%d,%d) : rnti %x, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n",
-	    idci, DL_req->number_dci + HI_DCI0_req->number_of_dci,
-	    DL_req->number_dci, HI_DCI0_req->number_of_dci,
-	    hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.rnti,
-	    hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.aggregation_level,
-	    nCCE, nCCE_max, DL_req->number_pdcch_ofdm_symbols);
-
-      if (nCCE + (hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.aggregation_level) > nCCE_max) {
-	if (DL_req->number_pdcch_ofdm_symbols == max_symbol)
-	  goto failed;
-	LOG_D(MAC,
-	      "Can't fit DCI allocations with %d PDCCH symbols, increasing by 1\n",
-	      DL_req->number_pdcch_ofdm_symbols);
-
-	DL_req->number_pdcch_ofdm_symbols++;
-	nCCE_max =
-	  get_nCCE_max(&RC.mac[module_idP]->common_channels[CC_idP],
-		       DL_req->number_pdcch_ofdm_symbols,
-		       subframeP);
-	goto try_again;
+      LOG_D(MAC, "Trying to allocate format 0 DCI %d/%d (%d,%d) : rnti %x, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n",
+            idci,
+            DL_req->number_dci + HI_DCI0_req->number_of_dci,
+            DL_req->number_dci,
+            HI_DCI0_req->number_of_dci,
+            hi_dci0_pduLoop->dci_pdu.dci_pdu_rel8.rnti,
+            hi_dci0_pduLoop->dci_pdu.dci_pdu_rel8.aggregation_level,
+            nCCE, nCCE_max,
+            DL_req->number_pdcch_ofdm_symbols);
+
+      if (nCCE + hi_dci0_pduLoop->dci_pdu.dci_pdu_rel8.aggregation_level > nCCE_max) {
+        if (DL_req->number_pdcch_ofdm_symbols == max_symbol)
+          return -1;
+
+        LOG_D(MAC, "Can't fit DCI allocations with %d PDCCH symbols, increasing by 1\n",
+              DL_req->number_pdcch_ofdm_symbols);
+        DL_req->number_pdcch_ofdm_symbols++;
+        nCCE_max = get_nCCE_max(cc, DL_req->number_pdcch_ofdm_symbols, subframeP);
+        goto try_again;
       }
+
       // number of CCEs left can potentially hold this allocation
       fCCE = get_nCCE_offset(CCE_table,
-			     hi_dci0_pdu[i].dci_pdu.
-			     dci_pdu_rel8.aggregation_level,
-			     nCCE_max, 0,
-			     hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.
-			     rnti, subframeP);
+                             hi_dci0_pduLoop->dci_pdu.dci_pdu_rel8.aggregation_level,
+                             nCCE_max,
+                             0,
+                             hi_dci0_pduLoop->dci_pdu.dci_pdu_rel8.rnti,
+                             subframeP);
+
       if (fCCE == -1) {
-	if (DL_req->number_pdcch_ofdm_symbols == max_symbol) {
-	  LOG_D(MAC,
-		"subframe %d: Dropping Allocation for RNTI %x\n",
-		subframeP,
-		hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.rnti);
-	  for (j = 0; j <= i; j++) {
-	    if (hi_dci0_pdu[j].pdu_type ==
-		NFAPI_HI_DCI0_DCI_PDU_TYPE)
-	      LOG_D(MAC,
-		    "DCI %d/%d (%d,%d) : rnti %x dci format %d, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n",
-		    j,
-		    DL_req->number_dci + HI_DCI0_req->number_of_dci,
-		    DL_req->number_dci,
-		    HI_DCI0_req->number_of_dci,
-		    hi_dci0_pdu[j].dci_pdu.dci_pdu_rel8.rnti,
-		    hi_dci0_pdu[j].dci_pdu.dci_pdu_rel8.
-		    dci_format,
-		    hi_dci0_pdu[j].dci_pdu.
-		    dci_pdu_rel8.aggregation_level, nCCE,
-		    nCCE_max,
-		    DL_req->number_pdcch_ofdm_symbols);
-	  }
-	  //dump_CCE_table(CCE_table,nCCE_max,subframeP,dci_alloc->rnti,1<<dci_alloc->L);
-	  goto failed;
-	}
-	LOG_D(MAC,
-	      "Can't fit DCI allocations with %d PDCCH symbols (rnti condition), increasing by 1\n",
-	      DL_req->number_pdcch_ofdm_symbols);
-
-	DL_req->number_pdcch_ofdm_symbols++;
-	nCCE_max =
-	  get_nCCE_max(&RC.mac[module_idP]->common_channels[CC_idP],
-		       DL_req->number_pdcch_ofdm_symbols,
-		       subframeP);
-	goto try_again;
-      }			// fCCE==-1
+        if (DL_req->number_pdcch_ofdm_symbols == max_symbol) {
+          LOG_D(MAC, "subframe %d: Dropping Allocation for RNTI %x\n",
+                subframeP,
+                hi_dci0_pduLoop->dci_pdu.dci_pdu_rel8.rnti);
+
+          for (j = 0; j <= i; j++) {
+            hi_dci0_pduLoop = &hi_dci0_pdu[j];
+            if (hi_dci0_pdu[j].pdu_type == NFAPI_HI_DCI0_DCI_PDU_TYPE)
+              LOG_D(MAC, "DCI %d/%d (%d,%d) : rnti %x dci format %d, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n",
+                    j,
+                    DL_req->number_dci + HI_DCI0_req->number_of_dci,
+                    DL_req->number_dci,
+                    HI_DCI0_req->number_of_dci,
+                    hi_dci0_pduLoop->dci_pdu.dci_pdu_rel8.rnti,
+                    hi_dci0_pduLoop->dci_pdu.dci_pdu_rel8.dci_format,
+                    hi_dci0_pduLoop->dci_pdu.dci_pdu_rel8.aggregation_level,
+                    nCCE, nCCE_max, DL_req->number_pdcch_ofdm_symbols);
+          }
+          //dump_CCE_table(CCE_table,nCCE_max,subframeP,dci_alloc->rnti,1<<dci_alloc->L);
+          return -1;
+        }
+
+        LOG_D(MAC, "Can't fit DCI allocations with %d PDCCH symbols (rnti condition), increasing by 1\n",
+              DL_req->number_pdcch_ofdm_symbols);
+        DL_req->number_pdcch_ofdm_symbols++;
+        nCCE_max = get_nCCE_max(cc, DL_req->number_pdcch_ofdm_symbols, subframeP);
+        goto try_again;
+      }     // fCCE==-1
 
       // the allocation is feasible, rnti rule passes
-      nCCE += hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.aggregation_level;
-      LOG_D(MAC, "Allocating at nCCE %d\n", fCCE);
+      nCCE += hi_dci0_pduLoop->dci_pdu.dci_pdu_rel8.aggregation_level;
+      LOG_D(MAC, "Allocating at nCCE %d\n",
+            fCCE);
+
       if ((test_onlyP%2) == 0) {
-	hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.cce_index = fCCE;
-	LOG_D(MAC, "Allocate CCEs subframe %d, test %d\n",
-	      subframeP, test_onlyP);
+        hi_dci0_pduLoop->dci_pdu.dci_pdu_rel8.cce_index = fCCE;
+        LOG_D(MAC, "Allocate CCEs subframe %d, test %d\n",
+              subframeP,
+              test_onlyP);
       }
+
       idci++;
     }
-  }				// for i = 0 ... num_UL_DCIs
+  }       // for i = 0 ... num_UL_DCIs
 
   for (i = 0; i < DL_req->number_pdu; i++) {
+    dl_config_pduLoop = &dl_config_pdu[i];
     // allocate DL UE specific DCIs
     if ((dl_config_pdu[i].pdu_type == NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE)
-	&& (dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti_type ==
-	    1)) {
-      LOG_D(MAC,
-	    "Trying to allocate DL UE-SPECIFIC DCI %d/%d (%d,%d) : rnti %x, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n",
-	    idci, DL_req->number_dci + HI_DCI0_req->number_of_dci,
-	    DL_req->number_dci, HI_DCI0_req->number_of_dci,
-	    dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti,
-	    dl_config_pdu[i].dci_dl_pdu.
-	    dci_dl_pdu_rel8.aggregation_level, nCCE, nCCE_max,
-	    DL_req->number_pdcch_ofdm_symbols);
-
-      if (nCCE + (dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level) > nCCE_max) {
-	if (DL_req->number_pdcch_ofdm_symbols == max_symbol)
-	  goto failed;
-	LOG_D(MAC,
-	      "Can't fit DCI allocations with %d PDCCH symbols, increasing by 1\n",
-	      DL_req->number_pdcch_ofdm_symbols);
-
-	DL_req->number_pdcch_ofdm_symbols++;
-	nCCE_max = get_nCCE_max(&RC.mac[module_idP]->common_channels[CC_idP],
-		       DL_req->number_pdcch_ofdm_symbols,
-		       subframeP);
-	goto try_again;
+        && (dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type == 1)) {
+      LOG_D(MAC, "Trying to allocate DL UE-SPECIFIC DCI %d/%d (%d,%d) : rnti %x, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n",
+            idci,
+            DL_req->number_dci + HI_DCI0_req->number_of_dci,
+            DL_req->number_dci, HI_DCI0_req->number_of_dci,
+            dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.rnti,
+            dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level,
+            nCCE,
+            nCCE_max,
+            DL_req->number_pdcch_ofdm_symbols);
+
+      if (nCCE + (dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level) > nCCE_max) {
+        if (DL_req->number_pdcch_ofdm_symbols == max_symbol)
+          return -1;
+
+        LOG_D(MAC, "Can't fit DCI allocations with %d PDCCH symbols, increasing by 1\n",
+              DL_req->number_pdcch_ofdm_symbols);
+        DL_req->number_pdcch_ofdm_symbols++;
+        nCCE_max = get_nCCE_max(cc, DL_req->number_pdcch_ofdm_symbols, subframeP);
+        goto try_again;
       }
+
       // number of CCEs left can potentially hold this allocation
       fCCE = get_nCCE_offset(CCE_table,
-			     dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level, nCCE_max, 0,
-			     dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti,
-			     subframeP);
+                             dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level,
+                             nCCE_max,
+                             0,
+                             dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.rnti,
+                             subframeP);
+
       if (fCCE == -1) {
-	if (DL_req->number_pdcch_ofdm_symbols == max_symbol) {
-	  LOG_I(MAC,
-		"subframe %d: Dropping Allocation for RNTI %x\n",
-		subframeP,
-		dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.
-		rnti);
-	  for (j = 0; j <= i; j++) {
-	    if (dl_config_pdu[j].pdu_type == NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE)
-	      LOG_D(MAC,
-		    "DCI %d/%d (%d,%d) : rnti %x dci format %d, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n",
-		    j,
-		    DL_req->number_dci + HI_DCI0_req->number_of_dci,
-		    DL_req->number_dci,
-		    HI_DCI0_req->number_of_dci,
-		    dl_config_pdu[j].dci_dl_pdu.dci_dl_pdu_rel8.rnti,
-		    dl_config_pdu[j].dci_dl_pdu.dci_dl_pdu_rel8.dci_format,
-		    dl_config_pdu[j].dci_dl_pdu.dci_dl_pdu_rel8.
-		    aggregation_level, 
-		    nCCE, 
-		    nCCE_max,
-		    DL_req->number_pdcch_ofdm_symbols);
-	  }
-	  //dump_CCE_table(CCE_table,nCCE_max,subframeP,dci_alloc->rnti,1<<dci_alloc->L);
-	  goto failed;
-	}
-	LOG_D(MAC,
-	      "Can't fit DCI allocations with %d PDCCH symbols (rnti condition), increasing by 1\n",
-	      DL_req->number_pdcch_ofdm_symbols);
-
-	DL_req->number_pdcch_ofdm_symbols++;
-	nCCE_max =
-	  get_nCCE_max(&RC.mac[module_idP]->common_channels[CC_idP],
-		       DL_req->number_pdcch_ofdm_symbols,
-		       subframeP);
-	goto try_again;
-      }			// fCCE==-1
+        if (DL_req->number_pdcch_ofdm_symbols == max_symbol) {
+          LOG_I(MAC, "subframe %d: Dropping Allocation for RNTI %x\n",
+                subframeP,
+                dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.rnti);
+
+          for (j = 0; j <= i; j++) {
+            dl_config_pduLoop = &dl_config_pdu[j];
+            if (dl_config_pduLoop->pdu_type == NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE)
+              LOG_D(MAC, "DCI %d/%d (%d,%d) : rnti %x dci format %d, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n",
+                    j,
+                    DL_req->number_dci + HI_DCI0_req->number_of_dci,
+                    DL_req->number_dci,
+                    HI_DCI0_req->number_of_dci,
+                    dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.rnti,
+                    dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.dci_format,
+                    dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level,
+                    nCCE,
+                    nCCE_max,
+                    DL_req->number_pdcch_ofdm_symbols);
+          }
+          //dump_CCE_table(CCE_table,nCCE_max,subframeP,dci_alloc->rnti,1<<dci_alloc->L);
+          return -1;
+        }
+
+        LOG_D(MAC, "Can't fit DCI allocations with %d PDCCH symbols (rnti condition), increasing by 1\n",
+              DL_req->number_pdcch_ofdm_symbols);
+        DL_req->number_pdcch_ofdm_symbols++;
+        nCCE_max = get_nCCE_max(cc, DL_req->number_pdcch_ofdm_symbols, subframeP);
+        goto try_again;
+      }     // fCCE==-1
 
       // the allocation is feasible, rnti rule passes
-      nCCE += dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level;
-      LOG_D(MAC, "Allocating at nCCE %d\n", fCCE);
+      nCCE += dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level;
+      LOG_D(MAC, "Allocating at nCCE %d\n",
+            fCCE);
+
       if ((test_onlyP%2) == 0) {
-	dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.cce_idx = fCCE;
-	LOG_D(MAC, "Allocate CCEs subframe %d, test %d\n",
-	      subframeP, test_onlyP);
+        dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.cce_idx = fCCE;
+        LOG_D(MAC, "Allocate CCEs subframe %d, test %d\n",
+              subframeP,
+              test_onlyP);
       }
+
       if ((test_onlyP/2) == 1) {
-       for(int ack_int = 0;ack_int < ul_req->number_of_pdus; ack_int++){
-        if(((ul_req->ul_config_pdu_list[ack_int].pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE) ||
-          (ul_req->ul_config_pdu_list[ack_int].pdu_type == NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE)) &&
-          (ul_req->ul_config_pdu_list[ack_int].uci_harq_pdu.ue_information.ue_information_rel8.rnti == dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti)){
-          if (cc->tdd_Config==NULL)
-           ul_req->ul_config_pdu_list[ack_int].uci_harq_pdu.harq_information.harq_information_rel9_fdd.n_pucch_1_0 =
-            cc->radioResourceConfigCommon->pucch_ConfigCommon.n1PUCCH_AN + fCCE;
-          else
-           ul_req->ul_config_pdu_list[ack_int].uci_harq_pdu.harq_information.harq_information_rel10_tdd.n_pucch_1_0 =
-            cc->radioResourceConfigCommon->pucch_ConfigCommon.n1PUCCH_AN + fCCE + getNp(cc->mib->message.dl_Bandwidth,fCCE,0) ;
+        for(int ack_int = 0; ack_int < ul_req->number_of_pdus; ack_int++) {
+          if(((ul_req->ul_config_pdu_list[ack_int].pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE) ||
+              (ul_req->ul_config_pdu_list[ack_int].pdu_type == NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE)) &&
+              (ul_req->ul_config_pdu_list[ack_int].uci_harq_pdu.ue_information.ue_information_rel8.rnti == dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti)) {
+            if (cc->tdd_Config==NULL)
+              ul_req->ul_config_pdu_list[ack_int].uci_harq_pdu.harq_information.harq_information_rel9_fdd.n_pucch_1_0 =
+                cc->radioResourceConfigCommon->pucch_ConfigCommon.n1PUCCH_AN + fCCE;
+            else
+              ul_req->ul_config_pdu_list[ack_int].uci_harq_pdu.harq_information.harq_information_rel10_tdd.n_pucch_1_0 =
+                cc->radioResourceConfigCommon->pucch_ConfigCommon.n1PUCCH_AN + fCCE + getNp(cc->mib->message.dl_Bandwidth,fCCE,0) ;
+          }
         }
-       }
       }
+
       idci++;
     }
-  }				// for i = 0 ... num_DL_DCIs
-
+  }       // for i = 0 ... num_DL_DCIs
   return 0;
-
- failed:
-  return -1;
 }
 
 nfapi_ul_config_request_pdu_t *has_ul_grant(module_id_t module_idP,
-					    int CC_idP, uint16_t absSFP,
-					    uint16_t rnti)
-{
+    int CC_idP, uint16_t absSFP,
+    uint16_t rnti) {
   nfapi_ul_config_request_body_t *ul_req;
   nfapi_ul_config_request_pdu_t *ul_config_pdu;
-
   ul_req = &RC.mac[module_idP]->UL_req_tmp[CC_idP][absSFP % 10].ul_config_request_body;
   ul_config_pdu = &ul_req->ul_config_pdu_list[0];
   LOG_D(MAC,
-	"Checking for rnti %x UL grant in subframeP %d (num pdu %d)\n",
-	rnti, absSFP % 10, ul_req->number_of_pdus);
+        "Checking for rnti %x UL grant in subframeP %d (num pdu %d)\n",
+        rnti, absSFP % 10, ul_req->number_of_pdus);
 
   for (int i = 0; i < ul_req->number_of_pdus; i++) {
     LOG_D(MAC, "PDU %d : type %d,rnti %x\n", i,ul_config_pdu[i].pdu_type, rnti);
+
     if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_ULSCH_PDU_TYPE)
-	&& (ul_config_pdu[i].ulsch_pdu.ulsch_pdu_rel8.rnti == rnti))
+        && (ul_config_pdu[i].ulsch_pdu.ulsch_pdu_rel8.rnti == rnti))
       return (&ul_config_pdu[i]);
+
     if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_ULSCH_CQI_RI_PDU_TYPE)
-	&& (ul_config_pdu[i].ulsch_cqi_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti))
+        && (ul_config_pdu[i].ulsch_cqi_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti))
       return (&ul_config_pdu[i]);
+
     if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE)
-	&& (ul_config_pdu[i].ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti))
+        && (ul_config_pdu[i].ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti))
       return (&ul_config_pdu[i]);
+
     if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE)
-	&& (ul_config_pdu[i].ulsch_cqi_harq_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti))
+        && (ul_config_pdu[i].ulsch_cqi_harq_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti))
       return (&ul_config_pdu[i]);
 
     if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_UCI_CQI_PDU_TYPE)
-	&& (ul_config_pdu[i].uci_cqi_pdu.ue_information.ue_information_rel8.rnti == rnti))
+        && (ul_config_pdu[i].uci_cqi_pdu.ue_information.ue_information_rel8.rnti == rnti))
       return (&ul_config_pdu[i]);
+
     if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_UCI_SR_PDU_TYPE)
-	&& (ul_config_pdu[i].uci_sr_pdu.ue_information.ue_information_rel8.rnti == rnti))
+        && (ul_config_pdu[i].uci_sr_pdu.ue_information.ue_information_rel8.rnti == rnti))
       return (&ul_config_pdu[i]);
+
     if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE)
-	&& (ul_config_pdu[i].uci_harq_pdu.ue_information.ue_information_rel8.rnti == rnti))
+        && (ul_config_pdu[i].uci_harq_pdu.ue_information.ue_information_rel8.rnti == rnti))
       return (&ul_config_pdu[i]);
+
     if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE)
-	&& (ul_config_pdu[i].uci_sr_harq_pdu.ue_information.ue_information_rel8.rnti == rnti))
+        && (ul_config_pdu[i].uci_sr_harq_pdu.ue_information.ue_information_rel8.rnti == rnti))
       return (&ul_config_pdu[i]);
+
     if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE)
-	&& (ul_config_pdu[i].uci_cqi_harq_pdu.ue_information.ue_information_rel8.rnti == rnti))
+        && (ul_config_pdu[i].uci_cqi_harq_pdu.ue_information.ue_information_rel8.rnti == rnti))
       return (&ul_config_pdu[i]);
+
     if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_UCI_CQI_SR_PDU_TYPE)
-	&& (ul_config_pdu[i].uci_cqi_sr_pdu.ue_information.ue_information_rel8.rnti == rnti))
+        && (ul_config_pdu[i].uci_cqi_sr_pdu.ue_information.ue_information_rel8.rnti == rnti))
       return (&ul_config_pdu[i]);
+
     if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_UCI_CQI_SR_HARQ_PDU_TYPE)
-	&& (ul_config_pdu[i].uci_cqi_sr_harq_pdu.ue_information.ue_information_rel8.rnti == rnti))
+        && (ul_config_pdu[i].uci_cqi_sr_harq_pdu.ue_information.ue_information_rel8.rnti == rnti))
       return (&ul_config_pdu[i]);
 
     if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_ULSCH_UCI_CSI_PDU_TYPE)
-	&& (ul_config_pdu[i].ulsch_uci_csi_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti))
+        && (ul_config_pdu[i].ulsch_uci_csi_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti))
       return (&ul_config_pdu[i]);
+
     if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_ULSCH_UCI_HARQ_PDU_TYPE)
-	&& (ul_config_pdu[i].ulsch_uci_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti))
+        && (ul_config_pdu[i].ulsch_uci_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti))
       return (&ul_config_pdu[i]);
+
     if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE)
-	&& (ul_config_pdu[i].ulsch_csi_uci_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti))
+        && (ul_config_pdu[i].ulsch_csi_uci_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti))
       return (&ul_config_pdu[i]);
   }
 
-  return (NULL);		// no ul grant at all for this UE
+  return (NULL);    // no ul grant at all for this UE
 }
 
+//-----------------------------------------------------------------------------
 boolean_t
 CCE_allocation_infeasible(int module_idP,
-			  int CC_idP,
-			  int format_flag,
-			  int subframe, int aggregation, int rnti)
+                          int CC_idP,
+                          int format_flag,
+                          int subframe,
+                          int aggregation,
+                          int rnti)
+//-----------------------------------------------------------------------------
 {
   nfapi_dl_config_request_body_t *DL_req       = &RC.mac[module_idP]->DL_req[CC_idP].dl_config_request_body;
   nfapi_dl_config_request_pdu_t *dl_config_pdu = &DL_req->dl_config_pdu_list[DL_req->number_pdu];
   nfapi_hi_dci0_request_body_t *HI_DCI0_req    = &RC.mac[module_idP]->HI_DCI0_req[CC_idP][subframe].hi_dci0_request_body;
   nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu     = &HI_DCI0_req->hi_dci0_pdu_list[HI_DCI0_req->number_of_dci + HI_DCI0_req->number_of_hi];
-  int ret;
-  boolean_t res = FALSE;
+  boolean_t res = TRUE;
 
-  if (format_flag != 2) {	// DL DCI
+  if (format_flag != 2) { // DL DCI
     if (DL_req->number_pdu == MAX_NUM_DL_PDU) {
-      LOG_W(MAC,
-	    "Subframe %d: FAPI DL structure is full, skip scheduling UE %d\n",
-	    subframe, rnti);
+      LOG_W(MAC, "Subframe %d: FAPI DL structure is full, skip scheduling UE %d\n", subframe, rnti);
     } else {
       dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tl.tag            = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL8_TAG;
       dl_config_pdu->pdu_type                                     = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE;
@@ -3281,229 +3297,219 @@ CCE_allocation_infeasible(int module_idP,
       dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type         = (format_flag == 0) ? 2 : 1;
       dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level = aggregation;
       DL_req->number_pdu++;
-      LOG_D(MAC,
-	    "Subframe %d: Checking CCE feasibility format %d : (%x,%d) (%x,%d,%d)\n",
-	    subframe, format_flag, rnti, aggregation,
-	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti,
-	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.
-	    aggregation_level,
-	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type);
-      ret = allocate_CCEs(module_idP, CC_idP, 0, subframe, 0);
-      if (ret == -1) res = TRUE;
+      LOG_D(MAC, "Subframe %d: Checking CCE feasibility format %d : (%x,%d) \n",
+            subframe, format_flag, rnti, aggregation);
+
+      if (allocate_CCEs(module_idP, CC_idP, 0, subframe, 0) != -1)
+        res = FALSE;
       DL_req->number_pdu--;
     }
-  } else {			// ue-specific UL DCI
+  } else { // ue-specific UL DCI
     if (HI_DCI0_req->number_of_dci + HI_DCI0_req->number_of_hi == MAX_NUM_HI_DCI0_PDU) {
-      LOG_W(MAC,
-	    "Subframe %d: FAPI UL structure is full, skip scheduling UE %d\n",
-	    subframe, rnti);
+      LOG_W(MAC, "Subframe %d: FAPI UL structure is full, skip scheduling UE %d\n", subframe, rnti);
     } else {
       hi_dci0_pdu->pdu_type                               = NFAPI_HI_DCI0_DCI_PDU_TYPE;
       hi_dci0_pdu->dci_pdu.dci_pdu_rel8.tl.tag            = NFAPI_HI_DCI0_REQUEST_DCI_PDU_REL8_TAG;
       hi_dci0_pdu->dci_pdu.dci_pdu_rel8.rnti              = rnti;
       hi_dci0_pdu->dci_pdu.dci_pdu_rel8.aggregation_level = aggregation;
       HI_DCI0_req->number_of_dci++;
-      ret = allocate_CCEs(module_idP, CC_idP, 0, subframe, 0);
-      if (ret == -1) res = TRUE;
+
+      if (allocate_CCEs(module_idP, CC_idP, 0, subframe, 0) != -1)
+        res = FALSE;
       HI_DCI0_req->number_of_dci--;
     }
   }
 
   return res;
 }
-void get_retransmission_timing(TDD_Config_t *tdd_Config, frame_t *frameP,
-    sub_frame_t *subframeP)
-{
 
-    if (tdd_Config == NULL)
-    {
-        if (*subframeP > 1)
-            *frameP = (*frameP + 1) % 1024;
-        *subframeP = (*subframeP + 8) % 10;
-    }
-    else
-    {
-        switch (tdd_Config->subframeAssignment)//TODO fill in other TDD configs
-        {
-        default: printf("%s:%d: TODO\n", __FILE__, __LINE__); abort();
-        case 1:
-            if (*subframeP == 0 || *subframeP == 5)
-            {
-                *subframeP  += 19;
-                *frameP = (*frameP + *subframeP/10) % 1024;
-                *subframeP %= 10;
-            }
-            else if (*subframeP == 4 || *subframeP == 9)
-            {
-                *subframeP  += 16;
-                *frameP = (*frameP + *subframeP/10) % 1024;
-                *subframeP %= 10;
-            }
-            else
-            {
-                AssertFatal(2 == 1,
-                        "Illegal dl subframe %d for tdd config %ld\n", *subframeP,
-                        tdd_Config->subframeAssignment);
-            }
-            break;
+void get_retransmission_timing(LTE_TDD_Config_t *tdd_Config, frame_t *frameP,
+                               sub_frame_t *subframeP) {
+  if (tdd_Config == NULL) {
+    if (*subframeP > 1)
+      *frameP = (*frameP + 1) % 1024;
+
+    *subframeP = (*subframeP + 8) % 10;
+  } else {
+    switch (tdd_Config->subframeAssignment) { //TODO fill in other TDD configs
+      default:
+        printf("%s:%d: TODO\n", __FILE__, __LINE__);
+        abort();
+
+      case 1:
+        if (*subframeP == 0 || *subframeP == 5) {
+          *subframeP  += 19;
+          *frameP = (*frameP + *subframeP/10) % 1024;
+          *subframeP %= 10;
+        } else if (*subframeP == 4 || *subframeP == 9) {
+          *subframeP  += 16;
+          *frameP = (*frameP + *subframeP/10) % 1024;
+          *subframeP %= 10;
+        } else {
+          AssertFatal(2 == 1,
+                      "Illegal dl subframe %d for tdd config %ld\n", *subframeP,
+                      tdd_Config->subframeAssignment);
         }
+
+        break;
     }
+  }
 }
 
-uint8_t get_dl_subframe_count(int tdd_config_sfa, sub_frame_t subframeP){
+uint8_t get_dl_subframe_count(int tdd_config_sfa, sub_frame_t subframeP) {
+  uint8_t tdd1[10] = {1,-1,-1,-1,2,3,-1,-1,-1,4}; // special subframes 1,6 are excluded
 
-    uint8_t tdd1[10] = {1,-1,-1,-1,2,3,-1,-1,-1,4}; // special subframes 1,6 are excluded
-
-    switch(tdd_config_sfa){// TODO fill in other tdd configs
+  switch(tdd_config_sfa) { // TODO fill in other tdd configs
     case 1 :
-        return tdd1[subframeP];
-        break;
-    }
-    return -1;
+      return tdd1[subframeP];
+      break;
+  }
+
+  return -1;
 }
 
-uint8_t frame_subframe2_dl_harq_pid(TDD_Config_t *tdd_Config, int abs_frameP, sub_frame_t subframeP){
-    int harq_pid;
-    if(tdd_Config){
-
-        switch(tdd_Config->subframeAssignment){ //TODO fill in other tdd config
-        case 1:
-            harq_pid = (((frame_cnt*1024 + abs_frameP) * 4) - 1 + get_dl_subframe_count(tdd_Config->subframeAssignment,subframeP))%7;//4 dl subframe in a frame
-            if(harq_pid < 0)
-              harq_pid += 7;
-            LOG_D(MAC,"[frame_subframe2_dl_harq_pid] (%d,%d) calculate harq_pid ((( %d * 1024 + %d) *4) - 1 + %d) = %d \n",
-                    (abs_frameP+1024)%1024,subframeP,frame_cnt,abs_frameP,
-                    get_dl_subframe_count(tdd_Config->subframeAssignment,subframeP),harq_pid);
-            return harq_pid;
-            break;
-        }
-    }else{
-        return ((abs_frameP*10)+subframeP)&7;
+uint8_t frame_subframe2_dl_harq_pid(LTE_TDD_Config_t *tdd_Config, int abs_frameP, sub_frame_t subframeP) {
+  int harq_pid;
+
+  if(tdd_Config) {
+    switch(tdd_Config->subframeAssignment) { //TODO fill in other tdd config
+      case 1:
+        harq_pid = (((frame_cnt*1024 + abs_frameP) * 4) - 1 + get_dl_subframe_count(tdd_Config->subframeAssignment,subframeP))%7;//4 dl subframe in a frame
+
+        if(harq_pid < 0)
+          harq_pid += 7;
+
+        LOG_D(MAC,"[frame_subframe2_dl_harq_pid] (%d,%d) calculate harq_pid ((( %d * 1024 + %d) *4) - 1 + %d) = %d \n",
+              (abs_frameP+1024)%1024,subframeP,frame_cnt,abs_frameP,
+              get_dl_subframe_count(tdd_Config->subframeAssignment,subframeP),harq_pid);
+        return harq_pid;
+        break;
     }
-    return -1;
-}
+  } else {
+    return ((abs_frameP*10)+subframeP)&7;
+  }
 
-unsigned char ul_ACK_subframe2M(TDD_Config_t *tdd_Config,unsigned char subframe)
-{
+  return -1;
+}
 
+unsigned char ul_ACK_subframe2M(LTE_TDD_Config_t *tdd_Config,unsigned char subframe) {
   if (tdd_Config == NULL) {
     return(1);
   } else {
     switch (tdd_Config->subframeAssignment) {
-    case 1:
+      case 1:
         return 1; // don't ACK special subframe for now
-      if (subframe == 2) {  // ACK subframes 5 and 6
-        return(2);
-      } else if (subframe == 3) { // ACK subframe 9
-        return(1);  // To be updated
-      } else if (subframe == 7) { // ACK subframes 0 and 1
-        return(2);  // To be updated
-      } else if (subframe == 8) { // ACK subframe 4
-        return(1);  // To be updated
-      } else {
-	AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n",
-		    subframe,tdd_Config->subframeAssignment);
 
-      }
+        if (subframe == 2) {  // ACK subframes 5 and 6
+          return(2);
+        } else if (subframe == 3) { // ACK subframe 9
+          return(1);  // To be updated
+        } else if (subframe == 7) { // ACK subframes 0 and 1
+          return(2);  // To be updated
+        } else if (subframe == 8) { // ACK subframe 4
+          return(1);  // To be updated
+        } else {
+          AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n",
+                      subframe,tdd_Config->subframeAssignment);
+        }
 
-      break;
-    case 3:
-      if (subframe == 2) {  // ACK subframes 5 and 6
-        return(2); // should be 3
-      } else if (subframe == 3) { // ACK subframes 7 and 8
-        return(2);  // To be updated
-      } else if (subframe == 4) { // ACK subframes 9 and 0
-        return(2);
-      } else {
-	AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n",
-		    subframe,tdd_Config->subframeAssignment);
-      }
+        break;
 
-      break;
+      case 3:
+        if (subframe == 2) {  // ACK subframes 5 and 6
+          return(2); // should be 3
+        } else if (subframe == 3) { // ACK subframes 7 and 8
+          return(2);  // To be updated
+        } else if (subframe == 4) { // ACK subframes 9 and 0
+          return(2);
+        } else {
+          AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n",
+                      subframe,tdd_Config->subframeAssignment);
+        }
 
-    case 4:
-          if (subframe == 2) {  // ACK subframes 0,4 and 5
-            return(3); // should be 4
-          } else if (subframe == 3) { // ACK subframes 6,7,8 and 9
-            return(4);
-          } else {
-	    AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n",
-			subframe,tdd_Config->subframeAssignment);
-          }
+        break;
 
-          break;
+      case 4:
+        if (subframe == 2) {  // ACK subframes 0,4 and 5
+          return(3); // should be 4
+        } else if (subframe == 3) { // ACK subframes 6,7,8 and 9
+          return(4);
+        } else {
+          AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n",
+                      subframe,tdd_Config->subframeAssignment);
+        }
 
-    case 5:
-              if (subframe == 2) {  // ACK subframes 0,3,4,5,6,7,8 and 9
-                return(8); // should be 3
-              } else {
-		AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n",
-			    subframe,tdd_Config->subframeAssignment);
-              }
+        break;
 
-              break;
+      case 5:
+        if (subframe == 2) {  // ACK subframes 0,3,4,5,6,7,8 and 9
+          return(8); // should be 3
+        } else {
+          AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n",
+                      subframe,tdd_Config->subframeAssignment);
+        }
+
+        break;
     }
   }
 
   return(0);
 }
 
-unsigned char ul_ACK_subframe2dl_subframe(TDD_Config_t *tdd_Config,unsigned char subframe,unsigned char ACK_index)
-{
-
+unsigned char ul_ACK_subframe2dl_subframe(LTE_TDD_Config_t *tdd_Config,unsigned char subframe,unsigned char ACK_index) {
   if (tdd_Config == NULL) {
     return((subframe<4) ? subframe+6 : subframe-4);
   } else {
     switch (tdd_Config->subframeAssignment) {
-    case 3:
-      if (subframe == 2) {  // ACK subframes 5 and 6
-        if (ACK_index==2)
-          return(1);
-
-        return(5+ACK_index);
-      } else if (subframe == 3) { // ACK subframes 7 and 8
-        return(7+ACK_index);  // To be updated
-      } else if (subframe == 4) { // ACK subframes 9 and 0
-        return((9+ACK_index)%10);
-      } else {
-        AssertFatal(1==0,"illegal subframe %d for tdd_config->subframeAssignment %ld\n",
-              subframe,tdd_Config->subframeAssignment);
-      }
+      case 3:
+        if (subframe == 2) {  // ACK subframes 5 and 6
+          if (ACK_index==2)
+            return(1);
+
+          return(5+ACK_index);
+        } else if (subframe == 3) { // ACK subframes 7 and 8
+          return(7+ACK_index);  // To be updated
+        } else if (subframe == 4) { // ACK subframes 9 and 0
+          return((9+ACK_index)%10);
+        } else {
+          AssertFatal(1==0,"illegal subframe %d for tdd_config->subframeAssignment %ld\n",
+                      subframe,tdd_Config->subframeAssignment);
+        }
 
-      break;
+        break;
 
-    case 4:
-          if (subframe == 2) {  // ACK subframes 0, 4 and 5
-            //if (ACK_index==2)
-            //  return(1); TBC
-            if (ACK_index==2)
+      case 4:
+        if (subframe == 2) {  // ACK subframes 0, 4 and 5
+          //if (ACK_index==2)
+          //  return(1); TBC
+          if (ACK_index==2)
             return(0);
 
-            return(4+ACK_index);
-          } else if (subframe == 3) { // ACK subframes 6, 7 8 and 9
-            return(6+ACK_index);  // To be updated
-          } else {
-            AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n",
-                  subframe,tdd_Config->subframeAssignment);
-          }
+          return(4+ACK_index);
+        } else if (subframe == 3) { // ACK subframes 6, 7 8 and 9
+          return(6+ACK_index);  // To be updated
+        } else {
+          AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n",
+                      subframe,tdd_Config->subframeAssignment);
+        }
 
-          break;
+        break;
 
-    case 1:
-      if (subframe == 2) {  // ACK subframes 5 and 6
-        return(5+ACK_index);
-      } else if (subframe == 3) { // ACK subframe 9
-        return(9);  // To be updated
-      } else if (subframe == 7) { // ACK subframes 0 and 1
-        return(ACK_index);  // To be updated
-      } else if (subframe == 8) { // ACK subframe 4
-        return(4);  // To be updated
-      } else {
-        AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n",
-              subframe,tdd_Config->subframeAssignment);
-      }
+      case 1:
+        if (subframe == 2) {  // ACK subframes 5 and 6
+          return(5+ACK_index);
+        } else if (subframe == 3) { // ACK subframe 9
+          return(9);  // To be updated
+        } else if (subframe == 7) { // ACK subframes 0 and 1
+          return(ACK_index);  // To be updated
+        } else if (subframe == 8) { // ACK subframe 4
+          return(4);  // To be updated
+        } else {
+          AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n",
+                      subframe,tdd_Config->subframeAssignment);
+        }
 
-      break;
+        break;
     }
   }
 
@@ -3512,9 +3518,8 @@ unsigned char ul_ACK_subframe2dl_subframe(TDD_Config_t *tdd_Config,unsigned char
 
 void
 extract_harq(module_id_t mod_idP, int CC_idP, int UE_id,
-	     frame_t frameP, sub_frame_t subframeP,
-	     void *harq_indication, int format)
-{
+             frame_t frameP, sub_frame_t subframeP,
+             void *harq_indication, int format) {
   UE_list_t *UE_list = &RC.mac[mod_idP]->UE_list;
   UE_sched_ctrl *sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
   rnti_t rnti = UE_RNTI(mod_idP, UE_id);
@@ -3531,510 +3536,574 @@ extract_harq(module_id_t mod_idP, int CC_idP, int UE_id,
   sub_frame_t subframe_tx;
   int frame_tx;
   uint8_t harq_pid;
-  
-#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
+
   if (UE_list->UE_template[pCCid][UE_id].physicalConfigDedicated != NULL &&
       UE_list->UE_template[pCCid][UE_id].physicalConfigDedicated->pucch_ConfigDedicated != NULL &&
       (UE_list->UE_template[pCCid][UE_id].physicalConfigDedicated->ext7)
       && (UE_list->UE_template[pCCid][UE_id].physicalConfigDedicated->ext7->pucch_ConfigDedicated_r13)
       && (((UE_list->UE_template[pCCid][UE_id].physicalConfigDedicated->ext7->pucch_ConfigDedicated_r13->spatialBundlingPUCCH_r13) && (format == 0))
-	  || ((UE_list->UE_template[pCCid][UE_id].physicalConfigDedicated->ext7->pucch_ConfigDedicated_r13->spatialBundlingPUSCH_r13)
-	      && (format == 1))))
+          || ((UE_list->UE_template[pCCid][UE_id].physicalConfigDedicated->ext7->pucch_ConfigDedicated_r13->spatialBundlingPUSCH_r13)
+              && (format == 1))))
     spatial_bundling = 1;
+
 #endif
+
   for (i = 0; i < numCC; i++)
     tmode[i] = get_tmode(mod_idP, i, UE_id);
-  
+
   if (cc->tdd_Config) {
     harq_indication_tdd = (nfapi_harq_indication_tdd_rel13_t *) harq_indication;
     //    pdu = &harq_indication_tdd->harq_tb_n[0];
-    
     num_ack_nak = harq_indication_tdd->number_of_ack_nack;
-    
+
     switch (harq_indication_tdd->mode) {
-    case 0:		// Format 1a/b bundling
-      AssertFatal(numCC == 1, "numCC %d > 1, should not be using Format1a/b\n", numCC);
-      int M = ul_ACK_subframe2M(cc->tdd_Config,subframeP);
-      for(m=0;m<M;m++){
-	subframe_tx = ul_ACK_subframe2dl_subframe(cc->tdd_Config,subframeP,m);
-	if(frameP==1023&&subframeP>5)
-	  frame_tx=-1;
-	else
-	  frame_tx = subframeP < 4 ? frameP -1 : frameP;
-	harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frame_tx,subframe_tx);
-        RA_t *ra = &RC.mac[mod_idP]->common_channels[CC_idP].ra[0];
-
-       if(num_ack_nak==1){
-         if(harq_indication_tdd->harq_data[0].bundling.value_0==1){ //ack
-           sched_ctl->round[CC_idP][harq_pid] = 8; // release HARQ process
-           sched_ctl->tbcnt[CC_idP][harq_pid] = 0;
-           LOG_D(MAC,"frame %d subframe %d Acking (%d,%d) harq_pid %d round %d\n",frameP,subframeP,frame_tx,subframe_tx,harq_pid,sched_ctl->round[CC_idP][harq_pid]);
-         }else{ //nack
-	   if( sched_ctl->round[CC_idP][harq_pid]<8) sched_ctl->round[CC_idP][harq_pid]++;
-           if (sched_ctl->round[CC_idP][harq_pid] == 4) {
-             sched_ctl->round[CC_idP][harq_pid] = 8;     // release HARQ process
-             sched_ctl->tbcnt[CC_idP][harq_pid] = 0;
-           }
-           LOG_D(MAC,"frame %d subframe %d Nacking (%d,%d) harq_pid %d round %d\n",frameP,subframeP,frame_tx,subframe_tx,harq_pid,sched_ctl->round[CC_idP][harq_pid]);
-      if(sched_ctl->round[CC_idP][harq_pid] == 8){
-       for (uint8_t ra_i = 0; ra_i < NB_RA_PROC_MAX; ra_i++) {
-        if((ra[ra_i].rnti == rnti) && (ra[ra_i].state == WAITMSG4ACK)){
-         //Msg NACK num to MAC ,remove UE
-         // add UE info to freeList
-         LOG_I(RRC, "put UE %x into freeList\n", rnti);
-         put_UE_in_freelist(mod_idP, rnti, 1);
-        }
-       }
-      }
-         }
-        }
-        for (uint8_t ra_i = 0; ra_i < NB_RA_PROC_MAX; ra_i++) {
-        if ((ra[ra_i].rnti == rnti) && (ra[ra_i].state == MSGCRNTI_ACK) && (ra[ra_i].crnti_harq_pid == harq_pid)) {
-         LOG_D(MAC,"CRNTI Reconfiguration: ACK %d rnti %x round %d frame %d subframe %d \n",harq_indication_tdd->harq_data[0].bundling.value_0,rnti,sched_ctl->round[CC_idP][harq_pid],frameP,subframeP);
-         if(num_ack_nak == 1 && harq_indication_tdd->harq_data[0].bundling.value_0 == 1) {
-          cancel_ra_proc(mod_idP, CC_idP, frameP, ra[ra_i].rnti);
-         }else{
-          if(sched_ctl->round[CC_idP][harq_pid] == 7){
-           cancel_ra_proc(mod_idP, CC_idP, frameP, ra[ra_i].rnti);
+      case 0:   // Format 1a/b bundling
+        AssertFatal(numCC == 1, "numCC %d > 1, should not be using Format1a/b\n", numCC);
+        int M = ul_ACK_subframe2M(cc->tdd_Config,subframeP);
+
+        for(m=0; m<M; m++) {
+          subframe_tx = ul_ACK_subframe2dl_subframe(cc->tdd_Config,subframeP,m);
+
+          if(frameP==1023&&subframeP>5)
+            frame_tx=-1;
+          else
+            frame_tx = subframeP < 4 ? frameP -1 : frameP;
+
+          harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frame_tx,subframe_tx);
+          RA_t *ra = &RC.mac[mod_idP]->common_channels[CC_idP].ra[0];
+
+          if(num_ack_nak==1) {
+            if(harq_indication_tdd->harq_data[0].bundling.value_0==1) { //ack
+              sched_ctl->round[CC_idP][harq_pid] = 8; // release HARQ process
+              sched_ctl->tbcnt[CC_idP][harq_pid] = 0;
+              LOG_D(MAC,"frame %d subframe %d Acking (%d,%d) harq_pid %d round %d\n",frameP,subframeP,frame_tx,subframe_tx,harq_pid,sched_ctl->round[CC_idP][harq_pid]);
+            } else { //nack
+              if( sched_ctl->round[CC_idP][harq_pid]<8) sched_ctl->round[CC_idP][harq_pid]++;
+
+              if (sched_ctl->round[CC_idP][harq_pid] == 4) {
+                sched_ctl->round[CC_idP][harq_pid] = 8;     // release HARQ process
+                sched_ctl->tbcnt[CC_idP][harq_pid] = 0;
+              }
+
+              LOG_D(MAC,"frame %d subframe %d Nacking (%d,%d) harq_pid %d round %d\n",frameP,subframeP,frame_tx,subframe_tx,harq_pid,sched_ctl->round[CC_idP][harq_pid]);
+
+              if(sched_ctl->round[CC_idP][harq_pid] == 8) {
+                for (uint8_t ra_i = 0; ra_i < NB_RA_PROC_MAX; ra_i++) {
+                  if((ra[ra_i].rnti == rnti) && (ra[ra_i].state == WAITMSG4ACK)) {
+                    //Msg NACK num to MAC ,remove UE
+                    // add UE info to freeList
+                    LOG_I(RRC, "put UE %x into freeList\n", rnti);
+                    put_UE_in_freelist(mod_idP, rnti, 1);
+                  }
+                }
+              }
+            }
+          }
+
+          for (uint8_t ra_i = 0; ra_i < NB_RA_PROC_MAX; ra_i++) {
+            if ((ra[ra_i].rnti == rnti) && (ra[ra_i].state == MSGCRNTI_ACK) && (ra[ra_i].crnti_harq_pid == harq_pid)) {
+              LOG_D(MAC,"CRNTI Reconfiguration: ACK %d rnti %x round %d frame %d subframe %d \n",harq_indication_tdd->harq_data[0].bundling.value_0,rnti,sched_ctl->round[CC_idP][harq_pid],frameP,subframeP);
+
+              if(num_ack_nak == 1 && harq_indication_tdd->harq_data[0].bundling.value_0 == 1) {
+                cancel_ra_proc(mod_idP, CC_idP, frameP, ra[ra_i].rnti);
+              } else {
+                if(sched_ctl->round[CC_idP][harq_pid] == 7) {
+                  cancel_ra_proc(mod_idP, CC_idP, frameP, ra[ra_i].rnti);
+                }
+              }
+
+              break;
+            }
           }
-         }
-         break;
         }
-       }
-      }
-      break;
-    case 1:		// Channel Selection
-      break;
-    case 2:		// Format 3
-      break;
-    case 3:		// Format 4
-      break;
-    case 4:		// Format 5
-      break;
+
+        break;
+
+      case 1:   // Channel Selection
+        break;
+
+      case 2:   // Format 3
+        break;
+
+      case 3:   // Format 4
+        break;
+
+      case 4:   // Format 5
+        break;
     }
   } else {
     harq_indication_fdd = (nfapi_harq_indication_fdd_rel13_t *) harq_indication;
     num_ack_nak         = harq_indication_fdd->number_of_ack_nack;
     pdu                 = &harq_indication_fdd->harq_tb_n[0];
-
     harq_pid = ((10 * frameP) + subframeP + 10236) & 7;
-
     LOG_D(MAC,"frame %d subframe %d harq_pid %d mode %d tmode[0] %d num_ack_nak %d round %d\n",frameP,subframeP,harq_pid,harq_indication_fdd->mode,tmode[0],num_ack_nak,sched_ctl->round[CC_idP][harq_pid]);
 
-    switch (harq_indication_fdd->mode) {
-    case 0:		// Format 1a/b (10.1.2.1)
-      AssertFatal(numCC == 1,
-		  "numCC %d > 1, should not be using Format1a/b\n",
-		  numCC);
-      if (tmode[0] == 1 || tmode[0] == 2 || tmode[0] == 5 || tmode[0] == 6 || tmode[0] == 7) {	// NOTE: have to handle the case of TM9-10 with 1 antenna port
-	// single ACK/NAK bit
-	AssertFatal(num_ack_nak == 1,
-		    "num_ack_nak %d > 1 for 1 CC and single-layer transmission frame:%d subframe:%d\n",
-		    num_ack_nak,frameP,subframeP);
-	AssertFatal(sched_ctl->round[CC_idP][harq_pid] < 8,
-		    "Got ACK/NAK for inactive harq_pid %d for UE %d/%x\n",
-		    harq_pid, UE_id, rnti);
-	AssertFatal(pdu[0] == 1 || pdu[0] == 2
-		    || pdu[0] == 4,
-		    "Received ACK/NAK %d which is not 1 or 2 for harq_pid %d from UE %d/%x\n",
-		    pdu[0], harq_pid, UE_id, rnti);
-	LOG_D(MAC, "Received %d for harq_pid %d\n", pdu[0],
-	      harq_pid);
-
-    RA_t *ra = &RC.mac[mod_idP]->common_channels[CC_idP].ra[0];
-    for (uint8_t ra_i = 0; ra_i < NB_RA_PROC_MAX; ra_i++) {
-     if ((ra[ra_i].rnti == rnti) && (ra[ra_i].state == MSGCRNTI_ACK) &&
-       (ra[ra_i].crnti_harq_pid == harq_pid)) {
-      LOG_D(MAC,"CRNTI Reconfiguration: ACK %d rnti %x round %d frame %d subframe %d \n",pdu[0],rnti,sched_ctl->round[CC_idP][harq_pid],frameP,subframeP);
-      if(pdu[0] == 1){
-       cancel_ra_proc(mod_idP, CC_idP, frameP, ra[ra_i].rnti);
-      }else{
-       if(sched_ctl->round[CC_idP][harq_pid] == 7){
-        cancel_ra_proc(mod_idP, CC_idP, frameP, ra[ra_i].rnti);
-       }
-      }
-      break;
-     }
-    }
+    // use 1 HARQ proces of BL/CE UE for now
+    if (UE_list->UE_template[pCCid][UE_id].rach_resource_type > 0) harq_pid = 0;
 
-	if (pdu[0] == 1) {	// ACK
-	  sched_ctl->round[CC_idP][harq_pid] = 8;	// release HARQ process
-	  sched_ctl->tbcnt[CC_idP][harq_pid] = 0;
-	} else if (pdu[0] == 2 || pdu[0] == 4) {	// NAK (treat DTX as NAK)
-	  sched_ctl->round[CC_idP][harq_pid]++;	// increment round
-          if (sched_ctl->round[CC_idP][harq_pid] == 4) {
-	    sched_ctl->round[CC_idP][harq_pid] = 8;	// release HARQ process
-	    sched_ctl->tbcnt[CC_idP][harq_pid] = 0;
+    switch (harq_indication_fdd->mode) {
+      case 0:	// Format 1a/b (10.1.2.1)
+        AssertFatal(numCC == 1, "numCC %d > 1, should not be using Format1a/b\n", numCC);
+        if (tmode[0] == 1 || tmode[0] == 2 || tmode[0] == 5 || tmode[0] == 6 || tmode[0] == 7) {	// NOTE: have to handle the case of TM9-10 with 1 antenna port
+          // single ACK/NAK bit
+          AssertFatal(num_ack_nak == 1, "num_ack_nak %d > 1 for 1 CC and single-layer transmission frame:%d subframe:%d\n", num_ack_nak,frameP,subframeP);
+
+          // In case of nFAPI, sometimes timing of eNB and UE become different.
+          // So if nfapi_mode == 2(VNF) , this function don't check assertion to avoid process exit.
+          if (nfapi_mode != 2) {
+            AssertFatal(sched_ctl->round[CC_idP][harq_pid] < 8, "Got ACK/NAK for inactive harq_pid %d for UE %d/%x\n",
+                  harq_pid,
+                  UE_id,
+                  rnti);
+          } else {
+            if (sched_ctl->round[CC_idP][harq_pid] == 8) {
+              LOG_E(MAC,"Got ACK/NAK for inactive harq_pid %d for UE %d/%x\n", harq_pid, UE_id, rnti);
+              return;
+            }
           }
-          if (sched_ctl->round[CC_idP][harq_pid] == 8){
-           for (uint8_t ra_i = 0; ra_i < NB_RA_PROC_MAX; ra_i++) {
-            if((ra[ra_i].rnti == rnti) && (ra[ra_i].state == WAITMSG4ACK)){
-             //Msg NACK num to MAC ,remove UE
-             // add UE info to freeList
-             LOG_I(RRC, "put UE %x into freeList\n", rnti);
-             put_UE_in_freelist(mod_idP, rnti, 1);
+
+          AssertFatal(pdu[0] == 1 || pdu[0] == 2 || pdu[0] == 4, "Received ACK/NAK %d which is not 1 or 2 for harq_pid %d from UE %d/%x\n",
+                pdu[0],
+                harq_pid,
+                UE_id,
+                rnti);
+
+          LOG_D(MAC, "Received %d for harq_pid %d\n", pdu[0], harq_pid);
+
+          RA_t *ra = &RC.mac[mod_idP]->common_channels[CC_idP].ra[0];
+
+          for (uint8_t ra_i = 0; ra_i < NB_RA_PROC_MAX; ra_i++) {
+            if ((ra[ra_i].rnti == rnti) && (ra[ra_i].state == MSGCRNTI_ACK) &&  (ra[ra_i].crnti_harq_pid == harq_pid)) {
+              LOG_D(MAC,"CRNTI Reconfiguration: ACK %d rnti %x round %d frame %d subframe %d \n",
+                    pdu[0],
+                    rnti,
+                    sched_ctl->round[CC_idP][harq_pid],
+                    frameP,subframeP);
+
+              if (pdu[0] == 1) {
+                cancel_ra_proc(mod_idP, CC_idP, frameP, ra[ra_i].rnti);
+              } else {
+                if(sched_ctl->round[CC_idP][harq_pid] == 7) {
+                  cancel_ra_proc(mod_idP, CC_idP, frameP, ra[ra_i].rnti);
+                }
+              }
+
+              break;
             }
-           }
           }
-        }
-      } else {
-	// one or two ACK/NAK bits
-	AssertFatal(num_ack_nak <= 2,
-		    "num_ack_nak %d > 2 for 1 CC and TM3/4/8/9/10\n",
-		    num_ack_nak);
-	if ((num_ack_nak == 2)
-	    && (sched_ctl->round[CC_idP][harq_pid] < 8)
-	    && (sched_ctl->tbcnt[CC_idP][harq_pid] == 1)
-	    && (pdu[0] == 1) && (pdu[1] == 1)) {
-	  sched_ctl->round[CC_idP][harq_pid] = 8;
-	  sched_ctl->tbcnt[CC_idP][harq_pid] = 0;
-	}
-	if ((num_ack_nak == 2)
-	    && (sched_ctl->round[CC_idP][harq_pid] < 8)
-	    && (sched_ctl->tbcnt[CC_idP][harq_pid] == 1)
-	    && (pdu[0] == 2) && (pdu[1] == 2)) {
-	  sched_ctl->round[CC_idP][harq_pid]++;
-          if (sched_ctl->round[CC_idP][harq_pid] == 4) {
-            sched_ctl->round[CC_idP][harq_pid] = 8;     // release HARQ process
+
+          if (pdu[0] == 1) {  // ACK
+            sched_ctl->round[CC_idP][harq_pid] = 8; // release HARQ process
             sched_ctl->tbcnt[CC_idP][harq_pid] = 0;
+          } else if (pdu[0] == 2 || pdu[0] == 4) {  // NAK (treat DTX as NAK)
+            sched_ctl->round[CC_idP][harq_pid]++; // increment round
+
+            if (sched_ctl->round[CC_idP][harq_pid] == 4) {
+              sched_ctl->round[CC_idP][harq_pid] = 8; // release HARQ process
+              sched_ctl->tbcnt[CC_idP][harq_pid] = 0;
+            }
+
+            if (sched_ctl->round[CC_idP][harq_pid] == 8) {
+              for (uint8_t ra_i = 0; ra_i < NB_RA_PROC_MAX; ra_i++) {
+                if((ra[ra_i].rnti == rnti) && (ra[ra_i].state == WAITMSG4ACK)) {
+                  //Msg NACK num to MAC ,remove UE
+                  // add UE info to freeList
+                  LOG_I(RRC, "put UE %x into freeList\n", rnti);
+                  put_UE_in_freelist(mod_idP, rnti, 1);
+                }
+              }
+            }
           }
-        }
-	else if (((num_ack_nak == 2)
-		  && (sched_ctl->round[CC_idP][harq_pid] < 8)
-		  && (sched_ctl->tbcnt[0][harq_pid] == 2)
-		  && (pdu[0] == 1) && (pdu[1] == 2))
-		 || ((num_ack_nak == 2)
-		     && (sched_ctl->round[CC_idP][harq_pid] < 8)
-		     && (sched_ctl->tbcnt[CC_idP][harq_pid] == 2)
-		     && (pdu[0] == 2) && (pdu[1] == 1))) {
-	  sched_ctl->round[CC_idP][harq_pid]++;
-	  sched_ctl->tbcnt[CC_idP][harq_pid] = 1;
-          if (sched_ctl->round[CC_idP][harq_pid] == 4) {
-            sched_ctl->round[CC_idP][harq_pid] = 8;     // release HARQ process
-            sched_ctl->tbcnt[CC_idP][harq_pid] = 0;  /* TODO: do we have to set it to 0? */
-          }
-	} else if ((num_ack_nak == 2)
-		   && (sched_ctl->round[CC_idP][harq_pid] < 8)
-		   && (sched_ctl->tbcnt[CC_idP][harq_pid] == 2)
-		   && (pdu[0] == 2) && (pdu[1] == 2)) {
-	  sched_ctl->round[CC_idP][harq_pid]++;
-          if (sched_ctl->round[CC_idP][harq_pid] == 4) {
-            sched_ctl->round[CC_idP][harq_pid] = 8;     // release HARQ process
+        } else {
+          // one or two ACK/NAK bits
+          AssertFatal(num_ack_nak <= 2,
+                      "num_ack_nak %d > 2 for 1 CC and TM3/4/8/9/10\n",
+                      num_ack_nak);
+
+          if ((num_ack_nak == 2)
+              && (sched_ctl->round[CC_idP][harq_pid] < 8)
+              && (sched_ctl->tbcnt[CC_idP][harq_pid] == 1)
+              && (pdu[0] == 1) && (pdu[1] == 1)) {
+            sched_ctl->round[CC_idP][harq_pid] = 8;
             sched_ctl->tbcnt[CC_idP][harq_pid] = 0;
           }
+
+          if ((num_ack_nak == 2)
+              && (sched_ctl->round[CC_idP][harq_pid] < 8)
+              && (sched_ctl->tbcnt[CC_idP][harq_pid] == 1)
+              && (pdu[0] == 2) && (pdu[1] == 2)) {
+            sched_ctl->round[CC_idP][harq_pid]++;
+
+            if (sched_ctl->round[CC_idP][harq_pid] == 4) {
+              sched_ctl->round[CC_idP][harq_pid] = 8;     // release HARQ process
+              sched_ctl->tbcnt[CC_idP][harq_pid] = 0;
+            }
+          } else if (((num_ack_nak == 2)
+                      && (sched_ctl->round[CC_idP][harq_pid] < 8)
+                      && (sched_ctl->tbcnt[0][harq_pid] == 2)
+                      && (pdu[0] == 1) && (pdu[1] == 2))
+                     || ((num_ack_nak == 2)
+                         && (sched_ctl->round[CC_idP][harq_pid] < 8)
+                         && (sched_ctl->tbcnt[CC_idP][harq_pid] == 2)
+                         && (pdu[0] == 2) && (pdu[1] == 1))) {
+            sched_ctl->round[CC_idP][harq_pid]++;
+            sched_ctl->tbcnt[CC_idP][harq_pid] = 1;
+
+            if (sched_ctl->round[CC_idP][harq_pid] == 4) {
+              sched_ctl->round[CC_idP][harq_pid] = 8;     // release HARQ process
+              sched_ctl->tbcnt[CC_idP][harq_pid] = 0;  /* TODO: do we have to set it to 0? */
+            }
+          } else if ((num_ack_nak == 2)
+                     && (sched_ctl->round[CC_idP][harq_pid] < 8)
+                     && (sched_ctl->tbcnt[CC_idP][harq_pid] == 2)
+                     && (pdu[0] == 2) && (pdu[1] == 2)) {
+            sched_ctl->round[CC_idP][harq_pid]++;
+
+            if (sched_ctl->round[CC_idP][harq_pid] == 4) {
+              sched_ctl->round[CC_idP][harq_pid] = 8;     // release HARQ process
+              sched_ctl->tbcnt[CC_idP][harq_pid] = 0;
+            }
+          } else
+            AssertFatal(1 == 0,
+                        "Illegal ACK/NAK/round combination (%d,%d,%d,%d,%d) for harq_pid %d, UE %d/%x\n",
+                        num_ack_nak,
+                        sched_ctl->round[CC_idP][harq_pid],
+                        sched_ctl->round[CC_idP][harq_pid], pdu[0],
+                        pdu[1], harq_pid, UE_id, rnti);
         }
-	else
-	  AssertFatal(1 == 0,
-		      "Illegal ACK/NAK/round combination (%d,%d,%d,%d,%d) for harq_pid %d, UE %d/%x\n",
-		      num_ack_nak,
-		      sched_ctl->round[CC_idP][harq_pid],
-		      sched_ctl->round[CC_idP][harq_pid], pdu[0],
-		      pdu[1], harq_pid, UE_id, rnti);
-      }
-      break;
-    case 1:		// FDD Channel Selection (10.1.2.2.1), must be received for 2 serving cells
-      AssertFatal(numCC == 2,
-		  "Should not receive harq indication with channel selection with %d active CCs\n",
-		  numCC);
-
-      if ((num_ack_nak == 2)
-	  && (sched_ctl->round[pCCid][harq_pid] < 8)
-	  && (sched_ctl->round[1 - pCCid][harq_pid] < 8)
-	  && (sched_ctl->tbcnt[pCCid][harq_pid] == 1)
-	  && (sched_ctl->tbcnt[1 - pCCid][harq_pid] == 1)) {
-	AssertFatal(pdu[0] <= 3, "pdu[0] %d is not ACK/NAK/DTX\n",
-		    pdu[0]);
-	AssertFatal(pdu[1] <= 3, "pdu[1] %d is not ACK/NAK/DTX\n",
-		    pdu[1]);
-	if (pdu[0] == 1)
-	  sched_ctl->round[pCCid][harq_pid] = 8;
-	else {
-	  sched_ctl->round[pCCid][harq_pid]++;
-          if (sched_ctl->round[pCCid][harq_pid] == 4)
-	    sched_ctl->round[pCCid][harq_pid] = 8;
-        }
-	if (pdu[1] == 1)
-	  sched_ctl->round[1 - pCCid][harq_pid] = 8;
-	else {
-	  sched_ctl->round[1 - pCCid][harq_pid]++;
-	  if (sched_ctl->round[1 - pCCid][harq_pid] == 4)
-	    sched_ctl->round[1 - pCCid][harq_pid] = 8;
-        }
-      }			// A=2
-      else if ((num_ack_nak == 3)
-	       && (sched_ctl->round[pCCid][harq_pid] < 8)
-	       && (sched_ctl->tbcnt[pCCid][harq_pid] == 2)
-	       && (sched_ctl->round[1 - pCCid][harq_pid] < 8)
-	       && (sched_ctl->tbcnt[1 - pCCid][harq_pid] == 1)) {
-	AssertFatal(pdu[0] <= 3, "pdu[0] %d is not ACK/NAK/DTX\n",
-		    pdu[0]);
-	AssertFatal(pdu[1] <= 3, "pdu[1] %d is not ACK/NAK/DTX\n",
-		    pdu[1]);
-	AssertFatal(pdu[2] <= 3, "pdu[2] %d is not ACK/NAK/DTX\n",
-		    pdu[2]);
-	AssertFatal(sched_ctl->tbcnt[pCCid][harq_pid] == 2,
-		    "sched_ctl->tbcnt[%d][%d] != 2 for UE %d/%x\n",
-		    pCCid, harq_pid, UE_id, rnti);
-	AssertFatal(sched_ctl->tbcnt[1 - pCCid][harq_pid] == 1,
-		    "sched_ctl->tbcnt[%d][%d] != 1 for UE %d/%x\n",
-		    1 - pCCid, harq_pid, UE_id, rnti);
-	if ((pdu[0] == 1) && (pdu[1] == 1)) {	// both ACK
-	  sched_ctl->round[pCCid][harq_pid] = 8;
-	  sched_ctl->tbcnt[pCCid][harq_pid] = 0;
-	} else if (((pdu[0] == 2) && (pdu[1] == 1)) ||
-		   ((pdu[0] == 1) && (pdu[1] == 2))) {
-	  sched_ctl->round[pCCid][harq_pid]++;
-	  sched_ctl->tbcnt[pCCid][harq_pid] = 1;
-	  if (sched_ctl->round[pCCid][harq_pid] == 4) {
-	    sched_ctl->round[pCCid][harq_pid] = 8;
-	    sched_ctl->tbcnt[pCCid][harq_pid] = 0; /* TODO: do we have to set it to 0? */
+
+        break;
+
+      case 1:   // FDD Channel Selection (10.1.2.2.1), must be received for 2 serving cells
+        AssertFatal(numCC == 2,
+                    "Should not receive harq indication with channel selection with %d active CCs\n",
+                    numCC);
+
+        if ((num_ack_nak == 2)
+            && (sched_ctl->round[pCCid][harq_pid] < 8)
+            && (sched_ctl->round[1 - pCCid][harq_pid] < 8)
+            && (sched_ctl->tbcnt[pCCid][harq_pid] == 1)
+            && (sched_ctl->tbcnt[1 - pCCid][harq_pid] == 1)) {
+          AssertFatal(pdu[0] <= 3, "pdu[0] %d is not ACK/NAK/DTX\n",
+                      pdu[0]);
+          AssertFatal(pdu[1] <= 3, "pdu[1] %d is not ACK/NAK/DTX\n",
+                      pdu[1]);
+
+          if (pdu[0] == 1)
+            sched_ctl->round[pCCid][harq_pid] = 8;
+          else {
+            sched_ctl->round[pCCid][harq_pid]++;
+
+            if (sched_ctl->round[pCCid][harq_pid] == 4)
+              sched_ctl->round[pCCid][harq_pid] = 8;
           }
-	} else {
-	  sched_ctl->round[pCCid][harq_pid]++;
-	  if (sched_ctl->round[pCCid][harq_pid] == 4) {
-	    sched_ctl->round[pCCid][harq_pid] = 8;
-	    sched_ctl->tbcnt[pCCid][harq_pid] = 0;
+
+          if (pdu[1] == 1)
+            sched_ctl->round[1 - pCCid][harq_pid] = 8;
+          else {
+            sched_ctl->round[1 - pCCid][harq_pid]++;
+
+            if (sched_ctl->round[1 - pCCid][harq_pid] == 4)
+              sched_ctl->round[1 - pCCid][harq_pid] = 8;
           }
-        }
+        }     // A=2
+        else if ((num_ack_nak == 3)
+                 && (sched_ctl->round[pCCid][harq_pid] < 8)
+                 && (sched_ctl->tbcnt[pCCid][harq_pid] == 2)
+                 && (sched_ctl->round[1 - pCCid][harq_pid] < 8)
+                 && (sched_ctl->tbcnt[1 - pCCid][harq_pid] == 1)) {
+          AssertFatal(pdu[0] <= 3, "pdu[0] %d is not ACK/NAK/DTX\n",
+                      pdu[0]);
+          AssertFatal(pdu[1] <= 3, "pdu[1] %d is not ACK/NAK/DTX\n",
+                      pdu[1]);
+          AssertFatal(pdu[2] <= 3, "pdu[2] %d is not ACK/NAK/DTX\n",
+                      pdu[2]);
+          AssertFatal(sched_ctl->tbcnt[pCCid][harq_pid] == 2,
+                      "sched_ctl->tbcnt[%d][%d] != 2 for UE %d/%x\n",
+                      pCCid, harq_pid, UE_id, rnti);
+          AssertFatal(sched_ctl->tbcnt[1 - pCCid][harq_pid] == 1,
+                      "sched_ctl->tbcnt[%d][%d] != 1 for UE %d/%x\n",
+                      1 - pCCid, harq_pid, UE_id, rnti);
+
+          if ((pdu[0] == 1) && (pdu[1] == 1)) { // both ACK
+            sched_ctl->round[pCCid][harq_pid] = 8;
+            sched_ctl->tbcnt[pCCid][harq_pid] = 0;
+          } else if (((pdu[0] == 2) && (pdu[1] == 1)) ||
+                     ((pdu[0] == 1) && (pdu[1] == 2))) {
+            sched_ctl->round[pCCid][harq_pid]++;
+            sched_ctl->tbcnt[pCCid][harq_pid] = 1;
+
+            if (sched_ctl->round[pCCid][harq_pid] == 4) {
+              sched_ctl->round[pCCid][harq_pid] = 8;
+              sched_ctl->tbcnt[pCCid][harq_pid] = 0; /* TODO: do we have to set it to 0? */
+            }
+          } else {
+            sched_ctl->round[pCCid][harq_pid]++;
 
-	if (pdu[2] == 1)
-	  sched_ctl->round[1 - pCCid][harq_pid] = 8;
-	else {
-	  sched_ctl->round[1 - pCCid][harq_pid]++;
-	  if (sched_ctl->round[1 - pCCid][harq_pid] == 4) {
-	    sched_ctl->round[1 - pCCid][harq_pid] = 8;
+            if (sched_ctl->round[pCCid][harq_pid] == 4) {
+              sched_ctl->round[pCCid][harq_pid] = 8;
+              sched_ctl->tbcnt[pCCid][harq_pid] = 0;
+            }
           }
-        }
-      }			// A=3 primary cell has 2 TBs
-      else if ((num_ack_nak == 3)
-	       && (sched_ctl->round[1 - pCCid][harq_pid] < 8)
-	       && (sched_ctl->round[pCCid][harq_pid] < 8)
-	       && (sched_ctl->tbcnt[1 - pCCid][harq_pid] == 2)
-	       && (sched_ctl->tbcnt[pCCid][harq_pid] == 1)) {
-	AssertFatal(pdu[0] <= 3, "pdu[0] %d is not ACK/NAK/DTX\n",
-		    pdu[0]);
-	AssertFatal(pdu[1] <= 3, "pdu[1] %d is not ACK/NAK/DTX\n",
-		    pdu[1]);
-	AssertFatal(pdu[2] <= 3, "pdu[2] %d is not ACK/NAK/DTX\n",
-		    pdu[2]);
-	AssertFatal(sched_ctl->tbcnt[1 - pCCid][harq_pid] == 2,
-		    "sched_ctl->tbcnt[%d][%d] != 2 for UE %d/%x\n",
-		    1 - pCCid, harq_pid, UE_id, rnti);
-	AssertFatal(sched_ctl->tbcnt[pCCid][harq_pid] == 1,
-		    "sched_ctl->tbcnt[%d][%d] != 1 for UE %d/%x\n",
-		    pCCid, harq_pid, UE_id, rnti);
-	if ((pdu[0] == 1) && (pdu[1] == 1)) {	// both ACK
-	  sched_ctl->round[1 - pCCid][harq_pid] = 8;
-	  sched_ctl->tbcnt[1 - pCCid][harq_pid] = 0;
-	} else if (((pdu[0] >= 2) && (pdu[1] == 1))
-		   || ((pdu[0] == 1) && (pdu[1] >= 2))) {	// one ACK
-	  sched_ctl->round[1 - pCCid][harq_pid]++;
-	  sched_ctl->tbcnt[1 - pCCid][harq_pid] = 1;
-	  if (sched_ctl->round[1 - pCCid][harq_pid] == 4) {
-	    sched_ctl->round[1 - pCCid][harq_pid] = 8;
-	    sched_ctl->tbcnt[1 - pCCid][harq_pid] = 0;
+
+          if (pdu[2] == 1)
+            sched_ctl->round[1 - pCCid][harq_pid] = 8;
+          else {
+            sched_ctl->round[1 - pCCid][harq_pid]++;
+
+            if (sched_ctl->round[1 - pCCid][harq_pid] == 4) {
+              sched_ctl->round[1 - pCCid][harq_pid] = 8;
+            }
           }
-	} else {		// both NAK/DTX
-	  sched_ctl->round[1 - pCCid][harq_pid]++;
-	  if (sched_ctl->round[1 - pCCid][harq_pid] == 4) {
-	    sched_ctl->round[1 - pCCid][harq_pid] = 8;
-	    sched_ctl->tbcnt[1 - pCCid][harq_pid] = 0;
+        }     // A=3 primary cell has 2 TBs
+        else if ((num_ack_nak == 3)
+                 && (sched_ctl->round[1 - pCCid][harq_pid] < 8)
+                 && (sched_ctl->round[pCCid][harq_pid] < 8)
+                 && (sched_ctl->tbcnt[1 - pCCid][harq_pid] == 2)
+                 && (sched_ctl->tbcnt[pCCid][harq_pid] == 1)) {
+          AssertFatal(pdu[0] <= 3, "pdu[0] %d is not ACK/NAK/DTX\n",
+                      pdu[0]);
+          AssertFatal(pdu[1] <= 3, "pdu[1] %d is not ACK/NAK/DTX\n",
+                      pdu[1]);
+          AssertFatal(pdu[2] <= 3, "pdu[2] %d is not ACK/NAK/DTX\n",
+                      pdu[2]);
+          AssertFatal(sched_ctl->tbcnt[1 - pCCid][harq_pid] == 2,
+                      "sched_ctl->tbcnt[%d][%d] != 2 for UE %d/%x\n",
+                      1 - pCCid, harq_pid, UE_id, rnti);
+          AssertFatal(sched_ctl->tbcnt[pCCid][harq_pid] == 1,
+                      "sched_ctl->tbcnt[%d][%d] != 1 for UE %d/%x\n",
+                      pCCid, harq_pid, UE_id, rnti);
+
+          if ((pdu[0] == 1) && (pdu[1] == 1)) { // both ACK
+            sched_ctl->round[1 - pCCid][harq_pid] = 8;
+            sched_ctl->tbcnt[1 - pCCid][harq_pid] = 0;
+          } else if (((pdu[0] >= 2) && (pdu[1] == 1))
+                     || ((pdu[0] == 1) && (pdu[1] >= 2))) { // one ACK
+            sched_ctl->round[1 - pCCid][harq_pid]++;
+            sched_ctl->tbcnt[1 - pCCid][harq_pid] = 1;
+
+            if (sched_ctl->round[1 - pCCid][harq_pid] == 4) {
+              sched_ctl->round[1 - pCCid][harq_pid] = 8;
+              sched_ctl->tbcnt[1 - pCCid][harq_pid] = 0;
+            }
+          } else {    // both NAK/DTX
+            sched_ctl->round[1 - pCCid][harq_pid]++;
+
+            if (sched_ctl->round[1 - pCCid][harq_pid] == 4) {
+              sched_ctl->round[1 - pCCid][harq_pid] = 8;
+              sched_ctl->tbcnt[1 - pCCid][harq_pid] = 0;
+            }
           }
-        }
 
-	if (pdu[2] == 1)
-	  sched_ctl->round[pCCid][harq_pid] = 8;
-	else {
-	  sched_ctl->round[pCCid][harq_pid]++;
-	  if (sched_ctl->round[pCCid][harq_pid] == 4) {
-	    sched_ctl->round[pCCid][harq_pid] = 8;
+          if (pdu[2] == 1)
+            sched_ctl->round[pCCid][harq_pid] = 8;
+          else {
+            sched_ctl->round[pCCid][harq_pid]++;
+
+            if (sched_ctl->round[pCCid][harq_pid] == 4) {
+              sched_ctl->round[pCCid][harq_pid] = 8;
+            }
           }
-        }
-      }			// A=3 secondary cell has 2 TBs
+        }     // A=3 secondary cell has 2 TBs
+
 #if MAX_NUM_CCs>1
-      else if ((num_ack_nak == 4)
-	       && (sched_ctl->round[0][harq_pid] < 8)
-	       && (sched_ctl->round[1][harq_pid] < 8)
-	       && (sched_ctl->tbcnt[1 - pCCid][harq_pid] == 2)
-	       && (sched_ctl->tbcnt[pCCid][harq_pid] == 2)) {
-	AssertFatal(pdu[0] <= 3, "pdu[0] %d is not ACK/NAK/DTX\n",
-		    pdu[0]);
-	AssertFatal(pdu[1] <= 3, "pdu[1] %d is not ACK/NAK/DTX\n",
-		    pdu[1]);
-	AssertFatal(pdu[2] <= 3, "pdu[2] %d is not ACK/NAK/DTX\n",
-		    pdu[2]);
-	AssertFatal(pdu[3] <= 3, "pdu[3] %d is not ACK/NAK/DTX\n",
-		    pdu[3]);
-	AssertFatal(sched_ctl->tbcnt[0][harq_pid] == 2,
-		    "sched_ctl->tbcnt[0][%d] != 2 for UE %d/%x\n",
-		    harq_pid, UE_id, rnti);
-	AssertFatal(sched_ctl->tbcnt[1][harq_pid] == 2,
-		    "sched_ctl->tbcnt[1][%d] != 2 for UE %d/%x\n",
-		    harq_pid, UE_id, rnti);
-	if ((pdu[0] == 1) && (pdu[1] == 1)) {	// both ACK
-	  sched_ctl->round[0][harq_pid] = 8;
-	  sched_ctl->tbcnt[0][harq_pid] = 0;
-	} else if (((pdu[0] >= 2) && (pdu[1] == 1))
-		   || ((pdu[0] == 1) && (pdu[1] >= 2))) {	// one ACK
-	  sched_ctl->round[0][harq_pid]++;
-	  sched_ctl->tbcnt[0][harq_pid] = 1;
-	  if (sched_ctl->round[0][harq_pid] == 4) {
-	    sched_ctl->round[0][harq_pid] = 8;
-	    sched_ctl->tbcnt[0][harq_pid] = 0;
-          }
-	} else {		// both NAK/DTX
-	  sched_ctl->round[0][harq_pid]++;
-	  if (sched_ctl->round[0][harq_pid] == 4) {
-	    sched_ctl->round[0][harq_pid] = 8;
-	    sched_ctl->tbcnt[0][harq_pid] = 0;
+        else if ((num_ack_nak == 4)
+                 && (sched_ctl->round[0][harq_pid] < 8)
+                 && (sched_ctl->round[1][harq_pid] < 8)
+                 && (sched_ctl->tbcnt[1 - pCCid][harq_pid] == 2)
+                 && (sched_ctl->tbcnt[pCCid][harq_pid] == 2)) {
+          AssertFatal(pdu[0] <= 3, "pdu[0] %d is not ACK/NAK/DTX\n",
+                      pdu[0]);
+          AssertFatal(pdu[1] <= 3, "pdu[1] %d is not ACK/NAK/DTX\n",
+                      pdu[1]);
+          AssertFatal(pdu[2] <= 3, "pdu[2] %d is not ACK/NAK/DTX\n",
+                      pdu[2]);
+          AssertFatal(pdu[3] <= 3, "pdu[3] %d is not ACK/NAK/DTX\n",
+                      pdu[3]);
+          AssertFatal(sched_ctl->tbcnt[0][harq_pid] == 2,
+                      "sched_ctl->tbcnt[0][%d] != 2 for UE %d/%x\n",
+                      harq_pid, UE_id, rnti);
+          AssertFatal(sched_ctl->tbcnt[1][harq_pid] == 2,
+                      "sched_ctl->tbcnt[1][%d] != 2 for UE %d/%x\n",
+                      harq_pid, UE_id, rnti);
+
+          if ((pdu[0] == 1) && (pdu[1] == 1)) { // both ACK
+            sched_ctl->round[0][harq_pid] = 8;
+            sched_ctl->tbcnt[0][harq_pid] = 0;
+          } else if (((pdu[0] >= 2) && (pdu[1] == 1))
+                     || ((pdu[0] == 1) && (pdu[1] >= 2))) { // one ACK
+            sched_ctl->round[0][harq_pid]++;
+            sched_ctl->tbcnt[0][harq_pid] = 1;
+
+            if (sched_ctl->round[0][harq_pid] == 4) {
+              sched_ctl->round[0][harq_pid] = 8;
+              sched_ctl->tbcnt[0][harq_pid] = 0;
+            }
+          } else {    // both NAK/DTX
+            sched_ctl->round[0][harq_pid]++;
+
+            if (sched_ctl->round[0][harq_pid] == 4) {
+              sched_ctl->round[0][harq_pid] = 8;
+              sched_ctl->tbcnt[0][harq_pid] = 0;
+            }
           }
-        }
 
-	if ((pdu[2] == 1) && (pdu[3] == 1)) {	// both ACK
-	  sched_ctl->round[1][harq_pid] = 8;
-	  sched_ctl->tbcnt[1][harq_pid] = 0;
-	} else if (((pdu[2] >= 2) && (pdu[3] == 1))
-		   || ((pdu[2] == 1) && (pdu[3] >= 2))) {	// one ACK
-	  sched_ctl->round[1][harq_pid]++;
-	  sched_ctl->tbcnt[1][harq_pid] = 1;
-	  if (sched_ctl->round[1][harq_pid] == 4) {
-	    sched_ctl->round[1][harq_pid] = 8;
-	    sched_ctl->tbcnt[1][harq_pid] = 0;
+          if ((pdu[2] == 1) && (pdu[3] == 1)) { // both ACK
+            sched_ctl->round[1][harq_pid] = 8;
+            sched_ctl->tbcnt[1][harq_pid] = 0;
+          } else if (((pdu[2] >= 2) && (pdu[3] == 1))
+                     || ((pdu[2] == 1) && (pdu[3] >= 2))) { // one ACK
+            sched_ctl->round[1][harq_pid]++;
+            sched_ctl->tbcnt[1][harq_pid] = 1;
+
+            if (sched_ctl->round[1][harq_pid] == 4) {
+              sched_ctl->round[1][harq_pid] = 8;
+              sched_ctl->tbcnt[1][harq_pid] = 0;
+            }
+          } else {    // both NAK/DTX
+            sched_ctl->round[1][harq_pid]++;
+
+            if (sched_ctl->round[1][harq_pid] == 4) {
+              sched_ctl->round[1][harq_pid] = 8;
+              sched_ctl->tbcnt[1][harq_pid] = 0;
+            }
           }
-	} else {		// both NAK/DTX
-	  sched_ctl->round[1][harq_pid]++;
-	  if (sched_ctl->round[1][harq_pid] == 4) {
-	    sched_ctl->round[1][harq_pid] = 8;
-	    sched_ctl->tbcnt[1][harq_pid] = 0;
+        }     // A=4 both serving cells have 2 TBs
+
+#endif
+        break;
+
+      case 2:   // Format 3
+        AssertFatal(numCC > 2,
+                    "Should not receive harq indication with FDD format 3 with %d < 3 active CCs\n",
+                    numCC);
+
+        for (i = 0, j = 0; i < numCC; i++) {
+          if ((sched_ctl->round[i][harq_pid] < 8)) {
+            if (tmode[i] == 1 || tmode[i] == 2 || tmode[0] == 5
+                || tmode[0] == 6 || tmode[0] == 7) {
+              if (pdu[j] == 1) {
+                sched_ctl->round[i][harq_pid] = 8;
+                sched_ctl->tbcnt[i][harq_pid] = 0;
+              } else if (pdu[j] == 2) {
+                sched_ctl->round[i][harq_pid]++;
+
+                if (sched_ctl->round[i][harq_pid] == 4) {
+                  sched_ctl->round[i][harq_pid] = 8;
+                  sched_ctl->tbcnt[i][harq_pid] = 0;
+                }
+              } else
+                AssertFatal(1 == 0,
+                            "Illegal harq_ack value for CC %d harq_pid %d (%d) UE %d/%x\n",
+                            i, harq_pid, pdu[j], UE_id, rnti);
+
+              j++;
+            } else if (spatial_bundling == 0) {
+              if ((sched_ctl->tbcnt[i][harq_pid] == 2)
+                  && (pdu[j] == 1) && (pdu[j + 1] == 1)) {
+                sched_ctl->round[i][harq_pid] = 8;
+                sched_ctl->tbcnt[i][harq_pid] = 0;
+              } else if ((sched_ctl->tbcnt[i][harq_pid] == 2)
+                         && (pdu[j] == 1) && (pdu[j + 1] == 2)) {
+                sched_ctl->round[i][harq_pid]++;
+                sched_ctl->tbcnt[i][harq_pid] = 1;
+
+                if (sched_ctl->round[i][harq_pid] == 4) {
+                  sched_ctl->round[i][harq_pid] = 8;
+                  sched_ctl->tbcnt[i][harq_pid] = 0;
+                }
+              } else if ((sched_ctl->tbcnt[i][harq_pid] == 2)
+                         && (pdu[j] == 2) && (pdu[j + 1] == 1)) {
+                sched_ctl->round[i][harq_pid]++;
+                sched_ctl->tbcnt[i][harq_pid] = 1;
+
+                if (sched_ctl->round[i][harq_pid] == 4) {
+                  sched_ctl->round[i][harq_pid] = 8;
+                  sched_ctl->tbcnt[i][harq_pid] = 0;
+                }
+              } else if ((sched_ctl->tbcnt[i][harq_pid] == 2)
+                         && (pdu[j] == 2) && (pdu[j + 1] == 2)) {
+                sched_ctl->round[i][harq_pid]++;
+
+                if (sched_ctl->round[i][harq_pid] == 4) {
+                  sched_ctl->round[i][harq_pid] = 8;
+                  sched_ctl->tbcnt[i][harq_pid] = 0;
+                }
+              } else
+                AssertFatal(1 == 0,
+                            "Illegal combination for CC %d harq_pid %d (%d,%d,%d) UE %d/%x\n",
+                            i, harq_pid,
+                            sched_ctl->tbcnt[i][harq_pid],
+                            pdu[j], pdu[j + 1], UE_id, rnti);
+
+              j += 2;
+            } else if (spatial_bundling == 1) {
+              if (pdu[j] == 1) {
+                sched_ctl->round[i][harq_pid] = 8;
+                sched_ctl->tbcnt[i][harq_pid] = 0;
+              } else if (pdu[j] == 2) {
+                sched_ctl->round[i][harq_pid]++;
+
+                if (sched_ctl->round[i][harq_pid] == 4) {
+                  sched_ctl->round[i][harq_pid] = 8;
+                  sched_ctl->tbcnt[i][harq_pid] = 0;
+                }
+              } else
+                AssertFatal(1 == 0,
+                            "Illegal hack_nak value %d for CC %d harq_pid %d UE %d/%x\n",
+                            pdu[j], i, harq_pid, UE_id, rnti);
+
+              j++;
+            } else
+              AssertFatal(1 == 0,
+                          "Illegal value for spatial_bundling %d\n",
+                          spatial_bundling);
           }
         }
-      }			// A=4 both serving cells have 2 TBs
-#endif
-      break;
-    case 2:		// Format 3
-      AssertFatal(numCC > 2,
-		  "Should not receive harq indication with FDD format 3 with %d < 3 active CCs\n",
-		  numCC);
-      for (i = 0, j = 0; i < numCC; i++) {
-	if ((sched_ctl->round[i][harq_pid] < 8)) {
-	  if (tmode[i] == 1 || tmode[i] == 2 || tmode[0] == 5
-	      || tmode[0] == 6 || tmode[0] == 7) {
-	    if (pdu[j] == 1) {
-	      sched_ctl->round[i][harq_pid] = 8;
-	      sched_ctl->tbcnt[i][harq_pid] = 0;
-	    } else if (pdu[j] == 2) {
-	      sched_ctl->round[i][harq_pid]++;
-	      if (sched_ctl->round[i][harq_pid] == 4) {
-	        sched_ctl->round[i][harq_pid] = 8;
-	        sched_ctl->tbcnt[i][harq_pid] = 0;
-              }
-            }
-	    else
-	      AssertFatal(1 == 0,
-			  "Illegal harq_ack value for CC %d harq_pid %d (%d) UE %d/%x\n",
-			  i, harq_pid, pdu[j], UE_id, rnti);
-	    j++;
-	  } else if (spatial_bundling == 0) {
-	    if ((sched_ctl->tbcnt[i][harq_pid] == 2)
-		&& (pdu[j] == 1) && (pdu[j + 1] == 1)) {
-	      sched_ctl->round[i][harq_pid] = 8;
-	      sched_ctl->tbcnt[i][harq_pid] = 0;
-	    } else if ((sched_ctl->tbcnt[i][harq_pid] == 2)
-		       && (pdu[j] == 1) && (pdu[j + 1] == 2)) {
-	      sched_ctl->round[i][harq_pid]++;
-	      sched_ctl->tbcnt[i][harq_pid] = 1;
-	      if (sched_ctl->round[i][harq_pid] == 4) {
-	        sched_ctl->round[i][harq_pid] = 8;
-	        sched_ctl->tbcnt[i][harq_pid] = 0;
-              }
-	    } else if ((sched_ctl->tbcnt[i][harq_pid] == 2)
-		       && (pdu[j] == 2) && (pdu[j + 1] == 1)) {
-	      sched_ctl->round[i][harq_pid]++;
-	      sched_ctl->tbcnt[i][harq_pid] = 1;
-	      if (sched_ctl->round[i][harq_pid] == 4) {
-	        sched_ctl->round[i][harq_pid] = 8;
-	        sched_ctl->tbcnt[i][harq_pid] = 0;
-              }
-	    } else if ((sched_ctl->tbcnt[i][harq_pid] == 2)
-		       && (pdu[j] == 2) && (pdu[j + 1] == 2)) {
-	      sched_ctl->round[i][harq_pid]++;
-	      if (sched_ctl->round[i][harq_pid] == 4) {
-	        sched_ctl->round[i][harq_pid] = 8;
-	        sched_ctl->tbcnt[i][harq_pid] = 0;
-              }
-	    } else
-	      AssertFatal(1 == 0,
-			  "Illegal combination for CC %d harq_pid %d (%d,%d,%d) UE %d/%x\n",
-			  i, harq_pid,
-			  sched_ctl->tbcnt[i][harq_pid],
-			  pdu[j], pdu[j + 1], UE_id, rnti);
-	    j += 2;
-	  } else if (spatial_bundling == 1) {
-	    if (pdu[j] == 1) {
-	      sched_ctl->round[i][harq_pid] = 8;
-	      sched_ctl->tbcnt[i][harq_pid] = 0;
-	    } else if (pdu[j] == 2) {
-	      sched_ctl->round[i][harq_pid]++;
-	      if (sched_ctl->round[i][harq_pid] == 4) {
-	        sched_ctl->round[i][harq_pid] = 8;
-	        sched_ctl->tbcnt[i][harq_pid] = 0;
-              }
-	    } else
-	      AssertFatal(1 == 0,
-			  "Illegal hack_nak value %d for CC %d harq_pid %d UE %d/%x\n",
-			  pdu[j], i, harq_pid, UE_id, rnti);
-	    j++;
-	  } else
-	    AssertFatal(1 == 0,
-			"Illegal value for spatial_bundling %d\n",
-			spatial_bundling);
-	}
-      }
-      break;
-    case 3:		// Format 4
-      AssertFatal(1 == 0,
-		  "Should not receive harq indication with Format 4\n");
-      break;
-    case 4:		// Format 5
-      AssertFatal(1 == 0,
-		  "Should not receive harq indication with Format 5\n");
-      break;
+
+        break;
+
+      case 3:   // Format 4
+        AssertFatal(1 == 0,
+                    "Should not receive harq indication with Format 4\n");
+        break;
+
+      case 4:   // Format 5
+        AssertFatal(1 == 0,
+                    "Should not receive harq indication with Format 5\n");
+        break;
     }
   }
 }
 
 void
 extract_pucch_csi(module_id_t mod_idP, int CC_idP, int UE_id,
-		  frame_t frameP, sub_frame_t subframeP,
-		  uint8_t * pdu, uint8_t length)
-{
+                  frame_t frameP, sub_frame_t subframeP,
+                  uint8_t *pdu, uint8_t length) {
   UE_list_t *UE_list = &RC.mac[mod_idP]->UE_list;
   UE_sched_ctrl *sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
   COMMON_channels_t *cc = &RC.mac[mod_idP]->common_channels[CC_idP];
-  struct CQI_ReportPeriodic *cqi_ReportPeriodic;
+  struct LTE_CQI_ReportPeriodic *cqi_ReportPeriodic;
   int no_pmi;
   uint8_t Ltab[6] = { 0, 2, 4, 4, 4, 4 };
   uint8_t Jtab[6] = { 0, 2, 2, 3, 4, 4 };
   int feedback_cnt;
-
   AssertFatal(UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated != NULL,
-	      "physicalConfigDedicated is null for UE %d\n", UE_id);
+              "physicalConfigDedicated is null for UE %d\n", UE_id);
   AssertFatal(UE_list->
-	      UE_template[CC_idP][UE_id].physicalConfigDedicated->cqi_ReportConfig != NULL,
-	      "cqi_ReportConfig is null for UE %d\n", UE_id);
+              UE_template[CC_idP][UE_id].physicalConfigDedicated->cqi_ReportConfig != NULL,
+              "cqi_ReportConfig is null for UE %d\n", UE_id);
   AssertFatal((cqi_ReportPeriodic = UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->cqi_ReportConfig->cqi_ReportPeriodic) != NULL,
-	      "cqi_ReportPeriodic is null for UE %d\n", UE_id);
-
+              "cqi_ReportPeriodic is null for UE %d\n", UE_id);
   // determine feedback mode
-  AssertFatal(cqi_ReportPeriodic->present != CQI_ReportPeriodic_PR_NOTHING,
-	      "cqi_ReportPeriodic->present == CQI_ReportPeriodic_PR_NOTHING!\n");
-  AssertFatal(cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present != CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_NOTHING,
-	      "cqi_ReportPeriodic->cqi_FormatIndicatorPeriodic.choice.setup.present == CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_NOTHING!\n");
-
+  AssertFatal(cqi_ReportPeriodic->present != LTE_CQI_ReportPeriodic_PR_NOTHING,
+              "cqi_ReportPeriodic->present == LTE_CQI_ReportPeriodic_PR_NOTHING!\n");
+  AssertFatal(cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present != LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_NOTHING,
+              "cqi_ReportPeriodic->cqi_FormatIndicatorPeriodic.choice.setup.present == LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_NOTHING!\n");
   uint16_t Npd, N_OFFSET_CQI;
   int H, K, bandwidth_part, L, Lmask;
   int ri = sched_ctl->periodic_ri_received[CC_idP];
-
   get_csi_params(cc, cqi_ReportPeriodic, &Npd, &N_OFFSET_CQI, &H);
   K = (H - 1) / Jtab[cc->mib->message.dl_Bandwidth];
   L = Ltab[cc->mib->message.dl_Bandwidth];
@@ -4047,30 +4116,31 @@ extract_pucch_csi(module_id_t mod_idP, int CC_idP, int UE_id,
     bandwidth_part = 0;
 
   switch (get_tmode(mod_idP, CC_idP, UE_id)) {
-  case 1:
-  case 2:
-  case 3:
-  case 7:
-    no_pmi = 1;
-    break;
-  case 4:
-  case 5:
-  case 6:
-    no_pmi = 0;
-    break;
-  default:
-    // note: need to check TM8-10 without PMI/RI or with 1 antenna port (see Section 5.2.3.3.1 from 36.213)
-    no_pmi = 0;
+    case 1:
+    case 2:
+    case 3:
+    case 7:
+      no_pmi = 1;
+      break;
+
+    case 4:
+    case 5:
+    case 6:
+      no_pmi = 0;
+      break;
+
+    default:
+      // note: need to check TM8-10 without PMI/RI or with 1 antenna port (see Section 5.2.3.3.1 from 36.213)
+      no_pmi = 0;
   }
 
-  if ((cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present == CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_widebandCQI)
+  if ((cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present == LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_widebandCQI)
       || (feedback_cnt == 0)) {
     // Note: This implements only Tables: 5.3.3.1-1,5.3.3.1-1A and 5.3.3.1-2 from 36.213 (1,2,4 antenna ports Wideband CQI/PMI)
-
-    if (no_pmi == 1) {	// get spatial_diffcqi if needed
+    if (no_pmi == 1) {  // get spatial_diffcqi if needed
       sched_ctl->periodic_wideband_cqi[CC_idP] = pdu[0] & 0xF;
       sched_ctl->periodic_wideband_spatial_diffcqi[CC_idP] =
-	(pdu[0] >> 4) & 7;
+        (pdu[0] >> 4) & 7;
     } else if ((cc->p_eNB == 2) && (ri == 1)) {
       // p=2 Rank 1 wideband CQI/PMI 6 bits
       sched_ctl->periodic_wideband_cqi[CC_idP] = pdu[0] & 0xF;
@@ -4079,43 +4149,41 @@ extract_pucch_csi(module_id_t mod_idP, int CC_idP, int UE_id,
       // p=2 Rank 2 wideband CQI/PMI 8 bits
       sched_ctl->periodic_wideband_cqi[CC_idP] = pdu[0] & 0xF;
       sched_ctl->periodic_wideband_spatial_diffcqi[CC_idP] =
-	(pdu[0] >> 4) & 7;
+        (pdu[0] >> 4) & 7;
       sched_ctl->periodic_wideband_pmi[CC_idP] = (pdu[0] >> 7) & 1;
     } else if ((cc->p_eNB == 4) && (ri == 1)) {
       // p=4 Rank 1 wideband CQI/PMI 8 bits
       sched_ctl->periodic_wideband_cqi[CC_idP] = pdu[0] & 0xF;
       sched_ctl->periodic_wideband_pmi[CC_idP] =
-	(pdu[0] >> 4) & 0x0F;
+        (pdu[0] >> 4) & 0x0F;
     } else if ((cc->p_eNB == 4) && (ri > 1)) {
       // p=4 Rank 2 wideband CQI/PMI 11 bits
       sched_ctl->periodic_wideband_cqi[CC_idP] = pdu[0] & 0xF;
       sched_ctl->periodic_wideband_spatial_diffcqi[CC_idP] =
-	(pdu[0] >> 4) & 7;
+        (pdu[0] >> 4) & 7;
       sched_ctl->periodic_wideband_pmi[CC_idP] = (pdu[0] >> 7) & 0xF;
     } else
       AssertFatal(1 == 0,
-		  "illegal combination p %d, ri %d, no_pmi %d\n",
-		  cc->p_eNB, ri, no_pmi);
-  } else if (cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present == CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_subbandCQI)
-    {
-      // This is Table 5.2.3.3.2-2 for 36.213
-      if (ri == 1) {
-	//4+Ltab[cc->mib->message.dl_Bandwidth] bits
-	sched_ctl->periodic_subband_cqi[CC_idP][(bandwidth_part * L) +((pdu[0] >> 4) & Lmask)] = pdu[0] & 0xF;
-      } else if (ri > 1) {
-	//7+Ltab[cc->mib->message.dl_Bandwidth] bits;
-	sched_ctl->periodic_subband_spatial_diffcqi[CC_idP][(bandwidth_part * L) + ((pdu[0] >> 7) & Lmask)] = (pdu[0] >> 4) & 7;
-	sched_ctl->periodic_subband_cqi[CC_idP][(bandwidth_part * L) + ((pdu[0] >> 7) & Lmask)] =
-	  pdu[0] & 0xF;
-      }
+                  "illegal combination p %d, ri %d, no_pmi %d\n",
+                  cc->p_eNB, ri, no_pmi);
+  } else if (cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present == LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_subbandCQI) {
+    // This is Table 5.2.3.3.2-2 for 36.213
+    if (ri == 1) {
+      //4+Ltab[cc->mib->message.dl_Bandwidth] bits
+      sched_ctl->periodic_subband_cqi[CC_idP][(bandwidth_part * L) +((pdu[0] >> 4) & Lmask)] = pdu[0] & 0xF;
+    } else if (ri > 1) {
+      //7+Ltab[cc->mib->message.dl_Bandwidth] bits;
+      sched_ctl->periodic_subband_spatial_diffcqi[CC_idP][(bandwidth_part * L) + ((pdu[0] >> 7) & Lmask)] = (pdu[0] >> 4) & 7;
+      sched_ctl->periodic_subband_cqi[CC_idP][(bandwidth_part * L) + ((pdu[0] >> 7) & Lmask)] =
+        pdu[0] & 0xF;
     }
+  }
 }
 
 void
 extract_pusch_csi(module_id_t mod_idP, int CC_idP, int UE_id,
-		  frame_t frameP, sub_frame_t subframeP,
-		  uint8_t * pdu, uint8_t length)
-{
+                  frame_t frameP, sub_frame_t subframeP,
+                  uint8_t *pdu, uint8_t length) {
   UE_list_t *UE_list = &RC.mac[mod_idP]->UE_list;
   COMMON_channels_t *cc = &RC.mac[mod_idP]->common_channels[CC_idP];
   UE_sched_ctrl *sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
@@ -4127,15 +4195,13 @@ extract_pusch_csi(module_id_t mod_idP, int CC_idP, int UE_id,
   int i;
   uint64_t p = *(uint64_t *) pdu;
   int curbyte, curbit;
-  CQI_ReportModeAperiodic_t *cqi_ReportModeAperiodic;
-
+  LTE_CQI_ReportModeAperiodic_t *cqi_ReportModeAperiodic;
   AssertFatal(UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated != NULL,
-	      "physicalConfigDedicated is null for UE %d\n", UE_id);
+              "physicalConfigDedicated is null for UE %d\n", UE_id);
   AssertFatal(UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->cqi_ReportConfig != NULL,
-	      "cqi_ReportConfig is null for UE %d\n", UE_id);
+              "cqi_ReportConfig is null for UE %d\n", UE_id);
   AssertFatal((cqi_ReportModeAperiodic = UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->cqi_ReportConfig->cqi_ReportModeAperiodic) != NULL,
-	      "cqi_ReportModeAperiodic is null for UE %d\n", UE_id);
-
+              "cqi_ReportModeAperiodic is null for UE %d\n", UE_id);
   int N = Ntab[cc->mib->message.dl_Bandwidth];
   int tmode = get_tmode(mod_idP, CC_idP, UE_id);
   int ri = sched_ctl->aperiodic_ri_received[CC_idP];
@@ -4144,277 +4210,309 @@ extract_pusch_csi(module_id_t mod_idP, int CC_idP, int UE_id,
   int m;
 
   switch (*cqi_ReportModeAperiodic) {
-  case CQI_ReportModeAperiodic_rm12:
-    AssertFatal(0 == 1, "to be fixed, don't use p but pdu directly\n");
-    // wideband multiple PMI (TM4/6), Table 5.2.2.6.1-1 (for TM4/6)
-    AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9 || tmode == 10,
-		"Illegal transmission mode %d for CQI_ReportModeAperiodic_rm12\n",
-		tmode);
-    if (tmode <= 6) {	//Table 5.2.2.6.1-1 36.213
-      if ((ri == 1) && (cc->p_eNB == 2)) {
-	sched_ctl->aperiodic_wideband_cqi0[CC_idP]    = (uint8_t) (p & 0x0F);
-	p >>= 4;
-	for (i = 0; i < N; i++) {
-	  sched_ctl->aperiodic_subband_pmi[CC_idP][i] = (uint8_t) (p & 0x03);
-	  p >>= 2;
-	}
-      }
-      if ((ri == 2) && (cc->p_eNB == 2)) {
-	sched_ctl->aperiodic_wideband_cqi0[CC_idP]    = (uint8_t) (p & 0x0F);
-	p >>= 4;
-	sched_ctl->aperiodic_wideband_cqi1[CC_idP]    = (uint8_t) (p & 0x0F);
-	p >>= 4;
-	for (i = 0; i < N; i++) {
-	  sched_ctl->aperiodic_subband_pmi[CC_idP][i] = (uint8_t) (p & 0x01);
-	  p >>= 1;
-	}
-      }
-      if ((ri == 1) && (cc->p_eNB == 4)) {
-	sched_ctl->aperiodic_wideband_cqi0[CC_idP]    = (uint8_t) (p & 0x0F);
-	p >>= 4;
-	for (i = 0; i < N; i++) {
-	  sched_ctl->aperiodic_subband_pmi[CC_idP][i] = (uint8_t) (p & 0x03);
-	  p >>= 4;
-	}
-      }
-      if ((ri == 2) && (cc->p_eNB == 4)) {
-	sched_ctl->aperiodic_wideband_cqi0[CC_idP]    = (uint8_t) (p & 0x0F);
-	p >>= 4;
-	sched_ctl->aperiodic_wideband_cqi1[CC_idP]    = (uint8_t) (p & 0x0F);
-	p >>= 4;
-	for (i = 0; i < N; i++) {
-	  sched_ctl->aperiodic_subband_pmi[CC_idP][i] = (uint8_t) (p & 0x01);
-	  p >>= 4;
-	}
+    case LTE_CQI_ReportModeAperiodic_rm12:
+      AssertFatal(0 == 1, "to be fixed, don't use p but pdu directly\n");
+      // wideband multiple PMI (TM4/6), Table 5.2.2.6.1-1 (for TM4/6)
+      AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9 || tmode == 10,
+                  "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm12\n",
+                  tmode);
+
+      if (tmode <= 6) { //Table 5.2.2.6.1-1 36.213
+        if ((ri == 1) && (cc->p_eNB == 2)) {
+          sched_ctl->aperiodic_wideband_cqi0[CC_idP]    = (uint8_t) (p & 0x0F);
+          p >>= 4;
+
+          for (i = 0; i < N; i++) {
+            sched_ctl->aperiodic_subband_pmi[CC_idP][i] = (uint8_t) (p & 0x03);
+            p >>= 2;
+          }
+        }
+
+        if ((ri == 2) && (cc->p_eNB == 2)) {
+          sched_ctl->aperiodic_wideband_cqi0[CC_idP]    = (uint8_t) (p & 0x0F);
+          p >>= 4;
+          sched_ctl->aperiodic_wideband_cqi1[CC_idP]    = (uint8_t) (p & 0x0F);
+          p >>= 4;
+
+          for (i = 0; i < N; i++) {
+            sched_ctl->aperiodic_subband_pmi[CC_idP][i] = (uint8_t) (p & 0x01);
+            p >>= 1;
+          }
+        }
+
+        if ((ri == 1) && (cc->p_eNB == 4)) {
+          sched_ctl->aperiodic_wideband_cqi0[CC_idP]    = (uint8_t) (p & 0x0F);
+          p >>= 4;
+
+          for (i = 0; i < N; i++) {
+            sched_ctl->aperiodic_subband_pmi[CC_idP][i] = (uint8_t) (p & 0x03);
+            p >>= 4;
+          }
+        }
+
+        if ((ri == 2) && (cc->p_eNB == 4)) {
+          sched_ctl->aperiodic_wideband_cqi0[CC_idP]    = (uint8_t) (p & 0x0F);
+          p >>= 4;
+          sched_ctl->aperiodic_wideband_cqi1[CC_idP]    = (uint8_t) (p & 0x0F);
+          p >>= 4;
+
+          for (i = 0; i < N; i++) {
+            sched_ctl->aperiodic_subband_pmi[CC_idP][i] = (uint8_t) (p & 0x01);
+            p >>= 4;
+          }
+        }
+      }     // if (tmode <= 6) { //Table 5.2.2.6.1-1 36.213
+      else {
+        AssertFatal(1 == 0, "support for TM 8-10 to be done\n");
       }
-    }			// if (tmode <= 6) { //Table 5.2.2.6.1-1 36.213
-    else {
-      AssertFatal(1 == 0, "support for TM 8-10 to be done\n");
-    }
 
-    break;
-  case CQI_ReportModeAperiodic_rm20:
-    AssertFatal(0 == 1, "to be fixed, don't use p but pdu directly\n");
-    // UE-selected subband CQI no PMI (TM1/2/3/7) , Table 5.2.2.6.3-1 from 36.213
-    AssertFatal(tmode == 1 || tmode == 2 || tmode == 3
-		|| tmode == 7,
-		"Illegal transmission mode %d for CQI_ReportModeAperiodic_rm20\n",
-		tmode);
-
-    sched_ctl->aperiodic_wideband_cqi0[CC_idP] = (uint8_t) (p & 0x0F);
-    p >>= 4;
-    diffcqi0 = (uint8_t) (p & 0x03);
-    p >>= 2;
-    r = (uint8_t) (p & ((1 >> Ltab_uesel[bw]) - 1));
-    reverse_index(Ntab_uesel[bw], Mtab_uesel[bw], r, v);
-    for (m = 0; m < Mtab_uesel[bw]; m++)
-      sched_ctl->aperiodic_subband_diffcqi0[CC_idP][v[m]] = diffcqi0;
-    break;
-  case CQI_ReportModeAperiodic_rm22:
-    AssertFatal(0 == 1, "to be fixed, don't use p but pdu directly\n");
-    // UE-selected subband CQI multiple PMI (TM4/6) Table 5.2.2.6.3-2 from 36.213
-
-    AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9
-		|| tmode == 10,
-		"Illegal transmission mode %d for CQI_ReportModeAperiodic_rm22\n",
-		tmode);
-
-    sched_ctl->aperiodic_wideband_cqi0[CC_idP] = (uint8_t) (p & 0x0F);
-    p >>= 4;
-    diffcqi0 = (uint8_t) (p & 0x03);
-    p >>= 2;
-
-    if (ri > 1) {
-      sched_ctl->aperiodic_wideband_cqi1[CC_idP] =
-	(uint8_t) (p & 0x0F);
+      break;
+
+    case LTE_CQI_ReportModeAperiodic_rm20:
+      AssertFatal(0 == 1, "to be fixed, don't use p but pdu directly\n");
+      // UE-selected subband CQI no PMI (TM1/2/3/7) , Table 5.2.2.6.3-1 from 36.213
+      AssertFatal(tmode == 1 || tmode == 2 || tmode == 3
+                  || tmode == 7,
+                  "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm20\n",
+                  tmode);
+      sched_ctl->aperiodic_wideband_cqi0[CC_idP] = (uint8_t) (p & 0x0F);
       p >>= 4;
-      diffcqi1 = (uint8_t) (p & 0x03);
-      p >>= 2;
-    }
-    r = (uint8_t) (p & ((1 >> Ltab_uesel[bw]) - 1));
-    p >>= Ltab_uesel[bw];
-    reverse_index(Ntab_uesel[bw], Mtab_uesel[bw], r, v);
-    if ((ri == 1) && (cc->p_eNB == 2)) {
-      pmi_uesel = p & 0x3;
+      diffcqi0 = (uint8_t) (p & 0x03);
       p >>= 2;
-      sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x3;
-    } else if ((ri == 2) && (cc->p_eNB == 2)) {
-      pmi_uesel = p & 0x1;
-      p >>= 1;
-      sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x1;
-    } else if (cc->p_eNB == 4) {
-      pmi_uesel = p & 0x0F;
+      r = (uint8_t) (p & ((1 >> Ltab_uesel[bw]) - 1));
+      reverse_index(Ntab_uesel[bw], Mtab_uesel[bw], r, v);
+
+      for (m = 0; m < Mtab_uesel[bw]; m++)
+        sched_ctl->aperiodic_subband_diffcqi0[CC_idP][v[m]] = diffcqi0;
+
+      break;
+
+    case LTE_CQI_ReportModeAperiodic_rm22:
+      AssertFatal(0 == 1, "to be fixed, don't use p but pdu directly\n");
+      // UE-selected subband CQI multiple PMI (TM4/6) Table 5.2.2.6.3-2 from 36.213
+      AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9
+                  || tmode == 10,
+                  "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm22\n",
+                  tmode);
+      sched_ctl->aperiodic_wideband_cqi0[CC_idP] = (uint8_t) (p & 0x0F);
       p >>= 4;
-      sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x0F;
-    }
-    for (m = 0; m < Mtab_uesel[bw]; m++) {
-      sched_ctl->aperiodic_subband_diffcqi0[CC_idP][v[m]] = diffcqi0;
-      if (ri > 1)
-	sched_ctl->aperiodic_subband_diffcqi1[CC_idP][v[m]] =
-	  diffcqi1;
-      sched_ctl->aperiodic_subband_pmi[CC_idP][v[m]] = pmi_uesel;
-    }
-    break;
-  case CQI_ReportModeAperiodic_rm30:
-    //subband CQI no PMI (TM1/2/3/7)
-    AssertFatal(tmode == 1 || tmode == 2 || tmode == 3
-		|| tmode == 7,
-		"Illegal transmission mode %d for CQI_ReportModeAperiodic_rm30\n",
-		tmode);
-    sched_ctl->aperiodic_wideband_cqi0[CC_idP] = pdu[0] >> 4;
-    curbyte = 0;
-    curbit = 3;
-    for (i = 0; i < N; i++) {
-      sched_ctl->aperiodic_subband_diffcqi0[CC_idP][i] =
-	(pdu[curbyte] >> (curbit - 1)) & 0x03;
-      curbit -= 2;
-      if (curbit < 0) {
-	curbit = 7;
-	curbyte++;
+      diffcqi0 = (uint8_t) (p & 0x03);
+      p >>= 2;
+
+      if (ri > 1) {
+        sched_ctl->aperiodic_wideband_cqi1[CC_idP] =
+          (uint8_t) (p & 0x0F);
+        p >>= 4;
+        diffcqi1 = (uint8_t) (p & 0x03);
+        p >>= 2;
       }
-    }
-    sched_ctl->dl_cqi[CC_idP] =
-      sched_ctl->aperiodic_wideband_cqi0[CC_idP];
-    break;
-  case CQI_ReportModeAperiodic_rm31:
-    AssertFatal(0 == 1, "to be fixed, don't use p but pdu directly\n");
-    //subband CQI single PMI (TM4/5/6)
-    AssertFatal(tmode == 4 || tmode == 5 || tmode == 6 || tmode == 8
-		|| tmode == 9
-		|| tmode == 10,
-		"Illegal transmission mode %d for CQI_ReportModeAperiodic_rm31\n",
-		tmode);
-
-    if ((ri == 1) && (cc->p_eNB == 2)) {
-      sched_ctl->aperiodic_wideband_cqi0[CC_idP] =
-	(uint8_t) (p & 0x0F);
-      p >>= 4;
-      for (i = 0; i < N; i++) {
-	sched_ctl->aperiodic_subband_diffcqi0[CC_idP][i] =
-	  (uint8_t) (p & 0x03);
-	p >>= 2;
+
+      r = (uint8_t) (p & ((1 >> Ltab_uesel[bw]) - 1));
+      p >>= Ltab_uesel[bw];
+      reverse_index(Ntab_uesel[bw], Mtab_uesel[bw], r, v);
+
+      if ((ri == 1) && (cc->p_eNB == 2)) {
+        pmi_uesel = p & 0x3;
+        p >>= 2;
+        sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x3;
+      } else if ((ri == 2) && (cc->p_eNB == 2)) {
+        pmi_uesel = p & 0x1;
+        p >>= 1;
+        sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x1;
+      } else if (cc->p_eNB == 4) {
+        pmi_uesel = p & 0x0F;
+        p >>= 4;
+        sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x0F;
       }
-      sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x03;
-    }
-    if ((ri == 2) && (cc->p_eNB == 2)) {
-      sched_ctl->aperiodic_wideband_cqi0[CC_idP] =
-	(uint8_t) (p & 0x0F);
-      p >>= 4;
-      for (i = 0; i < N; i++) {
-	sched_ctl->aperiodic_subband_pmi[CC_idP][i] =
-	  (uint8_t) (p & 0x01);
-	p >>= 1;
+
+      for (m = 0; m < Mtab_uesel[bw]; m++) {
+        sched_ctl->aperiodic_subband_diffcqi0[CC_idP][v[m]] = diffcqi0;
+
+        if (ri > 1)
+          sched_ctl->aperiodic_subband_diffcqi1[CC_idP][v[m]] =
+            diffcqi1;
+
+        sched_ctl->aperiodic_subband_pmi[CC_idP][v[m]] = pmi_uesel;
       }
-      sched_ctl->aperiodic_wideband_cqi1[CC_idP] =
-	(uint8_t) (p & 0x0F);
-      p >>= 4;
+
+      break;
+
+    case LTE_CQI_ReportModeAperiodic_rm30:
+      //subband CQI no PMI (TM1/2/3/7)
+      AssertFatal(tmode == 1 || tmode == 2 || tmode == 3
+                  || tmode == 7,
+                  "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm30\n",
+                  tmode);
+      sched_ctl->aperiodic_wideband_cqi0[CC_idP] = pdu[0] >> 4;
+      curbyte = 0;
+      curbit = 3;
+
       for (i = 0; i < N; i++) {
-	sched_ctl->aperiodic_subband_pmi[CC_idP][i] =
-	  (uint8_t) (p & 0x01);
-	p >>= 1;
+        sched_ctl->aperiodic_subband_diffcqi0[CC_idP][i] =
+          (pdu[curbyte] >> (curbit - 1)) & 0x03;
+        curbit -= 2;
+
+        if (curbit < 0) {
+          curbit = 7;
+          curbyte++;
+        }
       }
-      sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x01;
-    }
-    if ((ri == 1) && (cc->p_eNB == 4)) {
-      sched_ctl->aperiodic_wideband_cqi0[CC_idP] =
-	(uint8_t) (p & 0x0F);
-      p >>= 4;
-      for (i = 0; i < N; i++) {
-	sched_ctl->aperiodic_subband_diffcqi0[CC_idP][i] =
-	  (uint8_t) (p & 0x03);
-	p >>= 2;
+
+      sched_ctl->dl_cqi[CC_idP] =
+        sched_ctl->aperiodic_wideband_cqi0[CC_idP];
+      break;
+
+    case LTE_CQI_ReportModeAperiodic_rm31:
+      AssertFatal(0 == 1, "to be fixed, don't use p but pdu directly\n");
+      //subband CQI single PMI (TM4/5/6)
+      AssertFatal(tmode == 4 || tmode == 5 || tmode == 6 || tmode == 8
+                  || tmode == 9
+                  || tmode == 10,
+                  "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm31\n",
+                  tmode);
+
+      if ((ri == 1) && (cc->p_eNB == 2)) {
+        sched_ctl->aperiodic_wideband_cqi0[CC_idP] =
+          (uint8_t) (p & 0x0F);
+        p >>= 4;
+
+        for (i = 0; i < N; i++) {
+          sched_ctl->aperiodic_subband_diffcqi0[CC_idP][i] =
+            (uint8_t) (p & 0x03);
+          p >>= 2;
+        }
+
+        sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x03;
       }
-      sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x0F;
-    }
-    if ((ri > 1) && (cc->p_eNB == 4)) {	// Note : 64 bits for 20 MHz
-      sched_ctl->aperiodic_wideband_cqi0[CC_idP] =
-	(uint8_t) (p & 0x0F);
-      p >>= 4;
-      for (i = 0; i < N; i++) {
-	sched_ctl->aperiodic_subband_pmi[CC_idP][i] =
-	  (uint8_t) (p & 0x01);
-	p >>= 1;
+
+      if ((ri == 2) && (cc->p_eNB == 2)) {
+        sched_ctl->aperiodic_wideband_cqi0[CC_idP] =
+          (uint8_t) (p & 0x0F);
+        p >>= 4;
+
+        for (i = 0; i < N; i++) {
+          sched_ctl->aperiodic_subband_pmi[CC_idP][i] =
+            (uint8_t) (p & 0x01);
+          p >>= 1;
+        }
+
+        sched_ctl->aperiodic_wideband_cqi1[CC_idP] =
+          (uint8_t) (p & 0x0F);
+        p >>= 4;
+
+        for (i = 0; i < N; i++) {
+          sched_ctl->aperiodic_subband_pmi[CC_idP][i] =
+            (uint8_t) (p & 0x01);
+          p >>= 1;
+        }
+
+        sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x01;
       }
-      sched_ctl->aperiodic_wideband_cqi1[CC_idP] =
-	(uint8_t) (p & 0x0F);
-      p >>= 4;
-      for (i = 0; i < N; i++) {
-	sched_ctl->aperiodic_subband_pmi[CC_idP][i] =
-	  (uint8_t) (p & 0x01);
-	p >>= 2;
+
+      if ((ri == 1) && (cc->p_eNB == 4)) {
+        sched_ctl->aperiodic_wideband_cqi0[CC_idP] =
+          (uint8_t) (p & 0x0F);
+        p >>= 4;
+
+        for (i = 0; i < N; i++) {
+          sched_ctl->aperiodic_subband_diffcqi0[CC_idP][i] =
+            (uint8_t) (p & 0x03);
+          p >>= 2;
+        }
+
+        sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x0F;
       }
-      sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x0F;
-    }
 
-    break;
-#if (RRC_VERSION >= MAKE_VERSION(12, 5, 0))
-  case CQI_ReportModeAperiodic_rm32_v1250:
-    AssertFatal(tmode == 4 || tmode == 5 || tmode == 6 || tmode == 8
-		|| tmode == 9
-		|| tmode == 10,
-		"Illegal transmission mode %d for CQI_ReportModeAperiodic_rm32\n",
-		tmode);
-    AssertFatal(1 == 0, "CQI_ReportModeAperiodic_rm32 to be done\n");
-    break;
+      if ((ri > 1) && (cc->p_eNB == 4)) { // Note : 64 bits for 20 MHz
+        sched_ctl->aperiodic_wideband_cqi0[CC_idP] =
+          (uint8_t) (p & 0x0F);
+        p >>= 4;
+
+        for (i = 0; i < N; i++) {
+          sched_ctl->aperiodic_subband_pmi[CC_idP][i] =
+            (uint8_t) (p & 0x01);
+          p >>= 1;
+        }
+
+        sched_ctl->aperiodic_wideband_cqi1[CC_idP] =
+          (uint8_t) (p & 0x0F);
+        p >>= 4;
+
+        for (i = 0; i < N; i++) {
+          sched_ctl->aperiodic_subband_pmi[CC_idP][i] =
+            (uint8_t) (p & 0x01);
+          p >>= 2;
+        }
+
+        sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x0F;
+      }
+
+      break;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(12, 5, 0))
+
+    case LTE_CQI_ReportModeAperiodic_rm32_v1250:
+      AssertFatal(tmode == 4 || tmode == 5 || tmode == 6 || tmode == 8
+                  || tmode == 9
+                  || tmode == 10,
+                  "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm32\n",
+                  tmode);
+      AssertFatal(1 == 0, "CQI_ReportModeAperiodic_rm32 to be done\n");
+      break;
 #endif
-#if (RRC_VERSION >= MAKE_VERSION(13, 1, 0))
-  case CQI_ReportModeAperiodic_rm10_v1310:
-    AssertFatal(tmode == 1 || tmode == 2 || tmode == 3
-		|| tmode == 7,
-		"Illegal transmission mode %d for CQI_ReportModeAperiodic_rm10\n",
-		tmode);
-    AssertFatal(1 == 0, "CQI_ReportModeAperiodic_rm10 to be done\n");
-    break;
-  case CQI_ReportModeAperiodic_rm11_v1310:
-    AssertFatal(tmode == 4 || tmode == 5 || tmode == 6 || tmode == 8
-		|| tmode == 9
-		|| tmode == 10,
-		"Illegal transmission mode %d for CQI_ReportModeAperiodic_rm11\n",
-		tmode);
-    AssertFatal(1 == 0, "CQI_ReportModeAperiodic_rm11 to be done\n");
-    break;
-#endif /* #if (RRC_VERSION >= MAKE_VERSION(13, 1, 0)) */
+#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 1, 0))
+
+    case LTE_CQI_ReportModeAperiodic_rm10_v1310:
+      AssertFatal(tmode == 1 || tmode == 2 || tmode == 3
+                  || tmode == 7,
+                  "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm10\n",
+                  tmode);
+      AssertFatal(1 == 0, "CQI_ReportModeAperiodic_rm10 to be done\n");
+      break;
+
+    case LTE_CQI_ReportModeAperiodic_rm11_v1310:
+      AssertFatal(tmode == 4 || tmode == 5 || tmode == 6 || tmode == 8
+                  || tmode == 9
+                  || tmode == 10,
+                  "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm11\n",
+                  tmode);
+      AssertFatal(1 == 0, "CQI_ReportModeAperiodic_rm11 to be done\n");
+      break;
+#endif /* #if (LTE_RRC_VERSION >= MAKE_VERSION(13, 1, 0)) */
   }
 }
 
 void
 cqi_indication(module_id_t mod_idP, int CC_idP, frame_t frameP,
-	       sub_frame_t subframeP, rnti_t rntiP,
-	       nfapi_cqi_indication_rel9_t * rel9, uint8_t * pdu,
-	       nfapi_ul_cqi_information_t * ul_cqi_information)
-{
+               sub_frame_t subframeP, rnti_t rntiP,
+               nfapi_cqi_indication_rel9_t *rel9, uint8_t *pdu,
+               nfapi_ul_cqi_information_t *ul_cqi_information) {
   int UE_id = find_UE_id(mod_idP, rntiP);
   UE_list_t *UE_list = &RC.mac[mod_idP]->UE_list;
+
   if (UE_id == -1) {
     LOG_W(MAC, "cqi_indication: UE %x not found\n", rntiP);
     return;
   }
+
   UE_sched_ctrl *sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
 
   if (UE_id >= 0) {
-
     LOG_D(MAC,"%s() UE_id:%d channel:%d cqi:%d\n", __FUNCTION__, UE_id, ul_cqi_information->channel, ul_cqi_information->ul_cqi);
 
-    if (ul_cqi_information->channel == 0) {	// PUCCH
-
+    if (ul_cqi_information->channel == 0) { // PUCCH
       // extract pucch csi information before changing RI information
       extract_pucch_csi(mod_idP, CC_idP, UE_id, frameP, subframeP,
-			pdu, rel9->length);
-
+                        pdu, rel9->length);
       memcpy((void *) sched_ctl->periodic_ri_received,
-	     (void *) rel9->ri, rel9->number_of_cc_reported);
-
+             (void *) rel9->ri, rel9->number_of_cc_reported);
       // SNR for PUCCH2
       sched_ctl->pucch2_snr[CC_idP] = ul_cqi_information->ul_cqi;
-    } else {		//PUSCH
+    } else {    //PUSCH
       memcpy((void *) sched_ctl->aperiodic_ri_received,
-	     (void *) rel9->ri, rel9->number_of_cc_reported);
-
+             (void *) rel9->ri, rel9->number_of_cc_reported);
       extract_pusch_csi(mod_idP, CC_idP, UE_id, frameP, subframeP,
-			pdu, rel9->length);
-
+                        pdu, rel9->length);
       LOG_D(MAC,"Frame %d Subframe %d update CQI:%d\n",frameP,subframeP,sched_ctl->dl_cqi[CC_idP]);
-
       sched_ctl->cqi_req_flag &= (~(1 << subframeP));
       sched_ctl->cqi_received = 1;
     }
@@ -4427,108 +4525,112 @@ cqi_indication(module_id_t mod_idP, int CC_idP, frame_t frameP,
 
 void
 SR_indication(module_id_t mod_idP, int cc_idP, frame_t frameP,
-	      sub_frame_t subframeP, rnti_t rntiP, uint8_t ul_cqi)
-{
+              sub_frame_t subframeP, rnti_t rntiP, uint8_t ul_cqi) {
   T(T_ENB_MAC_SCHEDULING_REQUEST, T_INT(mod_idP), T_INT(cc_idP),
     T_INT(frameP), T_INT(subframeP), T_INT(rntiP));
-
   int UE_id = find_UE_id(mod_idP, rntiP);
   UE_list_t *UE_list = &RC.mac[mod_idP]->UE_list;
 
   if (UE_id != -1) {
     if (mac_eNB_get_rrc_status(mod_idP, UE_RNTI(mod_idP, UE_id)) <
-	RRC_CONNECTED)
+        RRC_CONNECTED)
       LOG_D(MAC,
-	    "[eNB %d][SR %x] Frame %d subframeP %d Signaling SR for UE %d on CC_id %d\n",
-	    mod_idP, rntiP, frameP, subframeP, UE_id, cc_idP);
+            "[eNB %d][SR %x] Frame %d subframeP %d Signaling SR for UE %d on CC_id %d\n",
+            mod_idP, rntiP, frameP, subframeP, UE_id, cc_idP);
 
     UE_list->UE_template[cc_idP][UE_id].ul_SR = 1;
     UE_list->UE_template[cc_idP][UE_id].ul_active = TRUE;
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME
-      (VCD_SIGNAL_DUMPER_FUNCTIONS_SR_INDICATION, 1);
+    (VCD_SIGNAL_DUMPER_FUNCTIONS_SR_INDICATION, 1);
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME
-      (VCD_SIGNAL_DUMPER_FUNCTIONS_SR_INDICATION, 0);
+    (VCD_SIGNAL_DUMPER_FUNCTIONS_SR_INDICATION, 0);
   } else {
     //     AssertFatal(0, "find_UE_id(%u,rnti %d) not found", enb_mod_idP, rntiP);
     //    AssertError(0, 0, "Frame %d: find_UE_id(%u,rnti %d) not found\n", frameP, enb_mod_idP, rntiP);
     LOG_D(MAC,
-	  "[eNB %d][SR %x] Frame %d subframeP %d Signaling SR for UE %d (unknown UEid) on CC_id %d\n",
-	  mod_idP, rntiP, frameP, subframeP, UE_id, cc_idP);
+          "[eNB %d][SR %x] Frame %d subframeP %d Signaling SR for UE %d (unknown UEid) on CC_id %d\n",
+          mod_idP, rntiP, frameP, subframeP, UE_id, cc_idP);
   }
 }
 
 void
 UL_failure_indication(module_id_t mod_idP, int cc_idP, frame_t frameP,
-		      rnti_t rntiP, sub_frame_t subframeP)
-{
+                      rnti_t rntiP, sub_frame_t subframeP) {
   int UE_id = find_UE_id(mod_idP, rntiP);
   UE_list_t *UE_list = &RC.mac[mod_idP]->UE_list;
 
   if (UE_id != -1) {
     LOG_D(MAC,
-	  "[eNB %d][UE %d/%x] Frame %d subframeP %d Signaling UL Failure for UE %d on CC_id %d (timer %d)\n",
-	  mod_idP, UE_id, rntiP, frameP, subframeP, UE_id, cc_idP,
-	  UE_list->UE_sched_ctrl[UE_id].ul_failure_timer);
+          "[eNB %d][UE %d/%x] Frame %d subframeP %d Signaling UL Failure for UE %d on CC_id %d (timer %d)\n",
+          mod_idP, UE_id, rntiP, frameP, subframeP, UE_id, cc_idP,
+          UE_list->UE_sched_ctrl[UE_id].ul_failure_timer);
+
     if (UE_list->UE_sched_ctrl[UE_id].ul_failure_timer == 0)
       UE_list->UE_sched_ctrl[UE_id].ul_failure_timer = 1;
   } else {
     //     AssertFatal(0, "find_UE_id(%u,rnti %d) not found", enb_mod_idP, rntiP);
     //    AssertError(0, 0, "Frame %d: find_UE_id(%u,rnti %d) not found\n", frameP, enb_mod_idP, rntiP);
     LOG_W(MAC,
-	  "[eNB %d][SR %x] Frame %d subframeP %d Signaling UL Failure for UE %d (unknown UEid) on CC_id %d\n",
-	  mod_idP, rntiP, frameP, subframeP, UE_id, cc_idP);
+          "[eNB %d][SR %x] Frame %d subframeP %d Signaling UL Failure for UE %d (unknown UEid) on CC_id %d\n",
+          mod_idP, rntiP, frameP, subframeP, UE_id, cc_idP);
   }
 }
 
 static int nack_or_dtx_reported(
-    COMMON_channels_t *cc,
-    nfapi_harq_indication_pdu_t *harq_pdu)
-{
+  COMMON_channels_t *cc,
+  nfapi_harq_indication_pdu_t *harq_pdu) {
   int i;
 
   if (cc->tdd_Config) {
     nfapi_harq_indication_tdd_rel13_t *hi = &harq_pdu->harq_indication_tdd_rel13;
+
     for (i = 0; i < hi->number_of_ack_nack; hi++)
       if (hi->harq_data[0].bundling.value_0 != 1) //only bundling is used for tdd for now
         return 1;
+
     return 0;
   } else {
     nfapi_harq_indication_fdd_rel13_t *hi = &harq_pdu->harq_indication_fdd_rel13;
+
     for (i = 0; i < hi->number_of_ack_nack; hi++)
       if (hi->harq_tb_n[i] != 1)
         return 1;
+
     return 0;
   }
 }
 
 void
 harq_indication(module_id_t mod_idP, int CC_idP, frame_t frameP,
-		sub_frame_t subframeP,
-		nfapi_harq_indication_pdu_t * harq_pdu)
-{
+                sub_frame_t subframeP,
+                nfapi_harq_indication_pdu_t *harq_pdu) {
   rnti_t rnti = harq_pdu->rx_ue_information.rnti;
   uint8_t ul_cqi = harq_pdu->ul_cqi_information.ul_cqi;
   uint8_t channel = harq_pdu->ul_cqi_information.channel;
   int UE_id = find_UE_id(mod_idP, rnti);
+
   if (UE_id == -1) {
     LOG_W(MAC, "harq_indication: UE %x not found\n", rnti);
     return;
   }
+
   UE_list_t *UE_list = &RC.mac[mod_idP]->UE_list;
   UE_sched_ctrl *sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
   COMMON_channels_t *cc = &RC.mac[mod_idP]->common_channels[CC_idP];
   // extract HARQ Information
   LOG_D(MAC,
-	"Frame %d, subframe %d: Received harq indication (%d) from UE %d/%x, ul_cqi %d\n",
-	frameP, subframeP, channel, UE_id, rnti, ul_cqi);
+        "Frame %d, subframe %d: Received harq indication (%d) from UE %d/%x, ul_cqi %d\n",
+        frameP, subframeP, channel, UE_id, rnti, ul_cqi);
+
   if (cc->tdd_Config)
     extract_harq(mod_idP, CC_idP, UE_id, frameP, subframeP,
-		 (void *) &harq_pdu->harq_indication_tdd_rel13,
-		 channel);
+                 (void *) &harq_pdu->harq_indication_tdd_rel13,
+                 channel);
   else
     extract_harq(mod_idP, CC_idP, UE_id, frameP, subframeP,
-		 (void *) &harq_pdu->harq_indication_fdd_rel13,
-		 channel);
+                 (void *) &harq_pdu->harq_indication_fdd_rel13,
+                 channel);
+
   /* don't care about cqi reporting if NACK/DTX is there */
   if (channel == 0 && !nack_or_dtx_reported(cc, harq_pdu)) {
     sched_ctl->pucch1_snr[CC_idP] = ul_cqi;
@@ -4538,31 +4640,31 @@ harq_indication(module_id_t mod_idP, int CC_idP, frame_t frameP,
 
 // Flexran Slicing functions
 
-uint16_t nb_rbs_allowed_slice(float rb_percentage, int total_rbs)
-{
-    return (uint16_t) floor(rb_percentage * total_rbs);
+uint16_t nb_rbs_allowed_slice(float rb_percentage, int total_rbs) {
+  return (uint16_t) floor(rb_percentage * total_rbs);
 }
 
-int ue_dl_slice_membership(module_id_t mod_id, int UE_id, int slice_idx)
-{
+int ue_dl_slice_membership(module_id_t mod_id, int UE_id, int slice_idx) {
   if ((slice_idx < 0)
       || (slice_idx >= RC.mac[mod_id]->slice_info.n_dl)) {
     LOG_W(MAC, "out of range slice index %d (slice ID %d)\n",
           slice_idx, RC.mac[mod_id]->slice_info.dl[slice_idx].id);
     return 0;
   }
+
   return RC.mac[mod_id]->UE_list.active[UE_id] == TRUE
          && RC.mac[mod_id]->UE_list.assoc_dl_slice_idx[UE_id] == slice_idx;
 }
 
-int ue_ul_slice_membership(module_id_t mod_id, int UE_id, int slice_idx)
+int ue_ul_slice_membership(module_id_t mod_id,
+                           int UE_id,
+                           int slice_idx)
 {
-  if ((slice_idx < 0)
-      || (slice_idx >= RC.mac[mod_id]->slice_info.n_ul)) {
+  if ((slice_idx < 0) || (slice_idx >= RC.mac[mod_id]->slice_info.n_ul)) {
     LOG_W(MAC, "out of range slice index %d (slice ID %d)\n",
           slice_idx, RC.mac[mod_id]->slice_info.dl[slice_idx].id);
     return 0;
   }
-  return RC.mac[mod_id]->UE_list.active[UE_id] == TRUE
-         && RC.mac[mod_id]->UE_list.assoc_ul_slice_idx[UE_id] == slice_idx;
+
+  return RC.mac[mod_id]->UE_list.active[UE_id] == TRUE && RC.mac[mod_id]->UE_list.assoc_ul_slice_idx[UE_id] == slice_idx;
 }
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
index e3a8dbe178ade83a477e7c65999d9c1170716418..05260f76ed140d6195048804297569107b8673cb 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
@@ -31,8 +31,6 @@
 
 /* indented with: indent -kr eNB_scheduler_RA.c */
 
-
-
 #include "LAYER2/MAC/mac.h"
 #include "LAYER2/MAC/mac_proto.h"
 #include "LAYER2/MAC/mac_extern.h"
@@ -47,11 +45,10 @@
 #include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"
 
 #include "assertions.h"
-//#include "LAYER2/MAC/pre_processor.c"
 #include "pdcp.h"
 
 #if defined(ENABLE_ITTI)
-#include "intertask_interface.h"
+  #include "intertask_interface.h"
 #endif
 
 #include "ENB_APP/flexran_agent_defs.h"
@@ -76,66 +73,92 @@ extern int oai_nfapi_ul_config_req(nfapi_ul_config_request_t *ul_config_req);
 extern uint8_t nfapi_mode;
 
 // This table holds the allowable PRB sizes for ULSCH transmissions
-uint8_t rb_table[34] =
-  { 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24, 25, 27, 30, 32,
-    36, 40, 45, 48, 50, 54, 60, 64, 72, 75, 80, 81, 90, 96, 100
-  };
-
-extern mui_t    rrc_eNB_mui;
-
+uint8_t rb_table[34] = {
+  1, 2, 3, 4, 5,      // 0-4
+  6, 8, 9, 10, 12,    // 5-9
+  15, 16, 18, 20, 24, // 10-14
+  25, 27, 30, 32, 36, // 15-19
+  40, 45, 48, 50, 54, // 20-24
+  60, 64, 72, 75, 80, // 25-29
+  81, 90, 96, 100     // 30-33
+};
+
+extern mui_t rrc_eNB_mui;
+
+//-----------------------------------------------------------------------------
+/*
+* When data are received on PHY and transmitted to MAC
+*/
 void
 rx_sdu(const module_id_t enb_mod_idP,
        const int CC_idP,
        const frame_t frameP,
        const sub_frame_t subframeP,
        const rnti_t rntiP,
-       uint8_t * sduP,
+       uint8_t *sduP,
        const uint16_t sdu_lenP,
-       const uint16_t timing_advance, const uint8_t ul_cqi)
+       const uint16_t timing_advance,
+       const uint8_t ul_cqi)
+//-----------------------------------------------------------------------------
 {
-  int current_rnti = rntiP;
-  unsigned char rx_ces[MAX_NUM_CE], num_ce, num_sdu, i, *payload_ptr;
+  int current_rnti = 0;
+  int UE_id = -1;
+  int RA_id = 0;
+  int old_rnti = -1;
+  int old_UE_id = -1;
+  int crnti_rx = 0;
+  int harq_pid = 0;
+  int first_rb = 0;
+  unsigned char num_ce = 0;
+  unsigned char num_sdu = 0;
+  unsigned char *payload_ptr = NULL;
+  unsigned char rx_ces[MAX_NUM_CE];
   unsigned char rx_lcids[NB_RB_MAX];
   unsigned short rx_lengths[NB_RB_MAX];
-  int UE_id = find_UE_id(enb_mod_idP, current_rnti);
-  int RA_id;
-  int ii, j;
-  eNB_MAC_INST *mac = RC.mac[enb_mod_idP];
-  int harq_pid =
-    subframe2harqpid(&mac->common_channels[CC_idP], frameP, subframeP);
+  uint8_t lcgid = 0;
   int lcgid_updated[4] = {0, 0, 0, 0};
-
-  UE_list_t *UE_list = &mac->UE_list;
-  int crnti_rx = 0;
-  RA_t *ra =
-    (RA_t *) & RC.mac[enb_mod_idP]->common_channels[CC_idP].ra[0];
-  int first_rb = 0;
+  eNB_MAC_INST *mac = NULL;
+  UE_list_t *UE_list = NULL;
+  rrc_eNB_ue_context_t *ue_contextP = NULL;
+
+  /* Init */
+  current_rnti = rntiP;
+  UE_id = find_UE_id(enb_mod_idP, current_rnti);
+  mac = RC.mac[enb_mod_idP];
+  harq_pid = subframe2harqpid(&mac->common_channels[CC_idP], frameP, subframeP);
+  UE_list = &mac->UE_list;
+  memset(rx_ces, 0, MAX_NUM_CE * sizeof(unsigned char));
+  memset(rx_lcids, 0, NB_RB_MAX * sizeof(unsigned char));
+  memset(rx_lengths, 0, NB_RB_MAX * sizeof(unsigned short));
 
   start_meas(&mac->rx_ulsch_sdu);
 
-  if ((UE_id > MAX_MOBILES_PER_ENB) || (UE_id == -1))
-    for (ii = 0; ii < NB_RB_MAX; ii++) {
-      rx_lengths[ii] = 0;
-    }
+  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RX_SDU, 1);
 
-  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME
-    (VCD_SIGNAL_DUMPER_FUNCTIONS_RX_SDU, 1);
   if (opt_enabled == 1) {
-    trace_pdu(DIRECTION_UPLINK, sduP, sdu_lenP, 0, WS_C_RNTI, current_rnti, frameP, subframeP,
-	      0, 0);
-    LOG_D(OPT, "[eNB %d][ULSCH] Frame %d  rnti %x  with size %d\n",
-	  enb_mod_idP, frameP, current_rnti, sdu_lenP);
+    trace_pdu(DIRECTION_UPLINK, sduP, sdu_lenP, 0, WS_C_RNTI, current_rnti, frameP, subframeP, 0, 0);
+
+    LOG_D(OPT, "[eNB %d][ULSCH] Frame %d rnti %x with size %d\n",
+      enb_mod_idP,
+      frameP,
+      current_rnti,
+      sdu_lenP);
   }
 
   if (UE_id != -1) {
-    LOG_D(MAC,
-	  "[eNB %d][PUSCH %d] CC_id %d %d.%d Received ULSCH sdu round %d from PHY (rnti %x, UE_id %d) ul_cqi %d\n",
-	  enb_mod_idP, harq_pid, CC_idP,frameP,subframeP,
-	  UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid],
-	  current_rnti, UE_id, ul_cqi);
-
-    AssertFatal(UE_list->UE_sched_ctrl[UE_id].
-		round_UL[CC_idP][harq_pid] < 8, "round >= 8\n");
+    LOG_D(MAC, "[eNB %d][PUSCH %d] CC_id %d %d.%d Received ULSCH sdu round %d from PHY (rnti %x, UE_id %d) ul_cqi %d\n",
+          enb_mod_idP,
+          harq_pid,
+          CC_idP,
+          frameP,
+          subframeP,
+          UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid],
+          current_rnti,
+          UE_id,
+          ul_cqi);
+
+    AssertFatal(UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid] < 8, "round >= 8\n");
+
     if (sduP != NULL) {
       UE_list->UE_sched_ctrl[UE_id].ul_inactivity_timer = 0;
       UE_list->UE_sched_ctrl[UE_id].ul_failure_timer = 0;
@@ -145,63 +168,81 @@ rx_sdu(const module_id_t enb_mod_idP,
        * lte_est_timing_advance_pusch, maybe it's not necessary?
        * maybe it's even not correct at all?
        */
-      UE_list->UE_sched_ctrl[UE_id].ta_update =	(UE_list->UE_sched_ctrl[UE_id].ta_update * 3 + timing_advance) / 4;
+      UE_list->UE_sched_ctrl[UE_id].ta_update = (UE_list->UE_sched_ctrl[UE_id].ta_update * 3 + timing_advance) / 4;
       UE_list->UE_sched_ctrl[UE_id].pusch_snr[CC_idP] = ul_cqi;
       UE_list->UE_sched_ctrl[UE_id].ul_consecutive_errors = 0;
+
       first_rb = UE_list->UE_template[CC_idP][UE_id].first_rb_ul[harq_pid];
 
       if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync > 0) {
-	UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync = 0;
-	mac_eNB_rrc_ul_in_sync(enb_mod_idP, CC_idP, frameP,
-			       subframeP, UE_RNTI(enb_mod_idP,
-						  UE_id));
+        UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync = 0;
+        mac_eNB_rrc_ul_in_sync(enb_mod_idP, CC_idP, frameP, subframeP, current_rnti);
       }
 
-      /* update scheduled bytes */
+      /* Update bytes to schedule */
       UE_list->UE_template[CC_idP][UE_id].scheduled_ul_bytes -= UE_list->UE_template[CC_idP][UE_id].TBS_UL[harq_pid];
-      if (UE_list->UE_template[CC_idP][UE_id].scheduled_ul_bytes < 0)
+
+      if (UE_list->UE_template[CC_idP][UE_id].scheduled_ul_bytes < 0) {
         UE_list->UE_template[CC_idP][UE_id].scheduled_ul_bytes = 0;
-    } else {		// we've got an error
-      LOG_D(MAC,
-	    "[eNB %d][PUSCH %d] CC_id %d %d.%d ULSCH in error in round %d, ul_cqi %d\n",
-	    enb_mod_idP, harq_pid, CC_idP,frameP,subframeP,
-	    UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid],
-	    ul_cqi);
-
-      if(ul_cqi>200){ // too high energy pattern
+      }
+
+    } else {  // sduP == NULL => error
+      LOG_W(MAC, "[eNB %d][PUSCH %d] CC_id %d %d.%d ULSCH in error in round %d, ul_cqi %d, UE_id %d, RNTI %x\n",
+        enb_mod_idP,
+        harq_pid,
+        CC_idP,
+        frameP,
+        subframeP,
+        UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid],
+        ul_cqi,
+        UE_id,
+        current_rnti);
+
+      if (ul_cqi > 200) { // too high energy pattern
         UE_list->UE_sched_ctrl[UE_id].pusch_snr[CC_idP] = ul_cqi;
+        LOG_W(MAC, "[MAC] Too high energy pattern\n");
       }
 
-      //      AssertFatal(1==0,"ulsch in error\n");
       if (UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid] == 3) {
-	UE_list->UE_sched_ctrl[UE_id].ul_scheduled &= (~(1 << harq_pid));
-	UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid] = 0;
-	if (UE_list->UE_sched_ctrl[UE_id].ul_consecutive_errors++ == 10)
-	  UE_list->UE_sched_ctrl[UE_id].ul_failure_timer = 1;
+        UE_list->UE_sched_ctrl[UE_id].ul_scheduled &= (~(1 << harq_pid));
+        UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid] = 0;
 
-        /* update scheduled bytes */
+        if (UE_list->UE_sched_ctrl[UE_id].ul_consecutive_errors++ == 10) {
+          UE_list->UE_sched_ctrl[UE_id].ul_failure_timer = 1;
+        }
+
+        /* Update scheduled bytes */
         UE_list->UE_template[CC_idP][UE_id].scheduled_ul_bytes -= UE_list->UE_template[CC_idP][UE_id].TBS_UL[harq_pid];
-        if (UE_list->UE_template[CC_idP][UE_id].scheduled_ul_bytes < 0)
+
+        if (UE_list->UE_template[CC_idP][UE_id].scheduled_ul_bytes < 0) {
           UE_list->UE_template[CC_idP][UE_id].scheduled_ul_bytes = 0;
+        }
 
-        if (find_RA_id(enb_mod_idP, CC_idP, current_rnti) != -1)
+        if (find_RA_id(enb_mod_idP, CC_idP, current_rnti) != -1) {
           cancel_ra_proc(enb_mod_idP, CC_idP, frameP, current_rnti);
-      } else
-	UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid]++;
+        }
+
+      } else {
+        UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid]++;
+      }
 
       first_rb = UE_list->UE_template[CC_idP][UE_id].first_rb_ul[harq_pid];
 
-      // Program NACK for PHICH
-      LOG_D(MAC,
-	"Programming PHICH NACK for rnti %x harq_pid %d (first_rb %d)\n",
-	current_rnti, harq_pid, first_rb);
-      nfapi_hi_dci0_request_t *hi_dci0_req;
-      uint8_t sf_ahead_dl = ul_subframe2_k_phich(&mac->common_channels[CC_idP] , subframeP);
-      hi_dci0_req = &mac->HI_DCI0_req[CC_idP][(subframeP+sf_ahead_dl)%10];
+      /* Program NACK for PHICH */
+      LOG_D(MAC, "Programming PHICH NACK for rnti %x harq_pid %d (first_rb %d)\n",
+        current_rnti,
+        harq_pid,
+        first_rb);
+
+      nfapi_hi_dci0_request_t *hi_dci0_req = NULL;
+      uint8_t sf_ahead_dl = ul_subframe2_k_phich(&mac->common_channels[CC_idP], subframeP);
+      hi_dci0_req = &mac->HI_DCI0_req[CC_idP][(subframeP + sf_ahead_dl) % 10];
+
       nfapi_hi_dci0_request_body_t *hi_dci0_req_body = &hi_dci0_req->hi_dci0_request_body;
-      nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu =
-        &hi_dci0_req_body->hi_dci0_pdu_list[hi_dci0_req_body->number_of_dci + hi_dci0_req_body->number_of_hi];
+      nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu = &hi_dci0_req_body->hi_dci0_pdu_list[hi_dci0_req_body->number_of_dci + hi_dci0_req_body->number_of_hi];
+
       memset((void *) hi_dci0_pdu, 0, sizeof(nfapi_hi_dci0_request_pdu_t));
+
       hi_dci0_pdu->pdu_type = NFAPI_HI_DCI0_HI_PDU_TYPE;
       hi_dci0_pdu->pdu_size = 2 + sizeof(nfapi_hi_dci0_hi_pdu);
       hi_dci0_pdu->hi_pdu.hi_pdu_rel8.tl.tag = NFAPI_HI_DCI0_REQUEST_HI_PDU_REL8_TAG;
@@ -213,549 +254,666 @@ rx_sdu(const module_id_t enb_mod_idP,
       hi_dci0_req_body->tl.tag = NFAPI_HI_DCI0_REQUEST_BODY_TAG;
       hi_dci0_req->sfn_sf = sfnsf_add_subframe(frameP,subframeP, sf_ahead_dl);
       hi_dci0_req->header.message_id = NFAPI_HI_DCI0_REQUEST;
-
       return;
+    }
+  // if UE_id == -1
+  } else if ((RA_id = find_RA_id(enb_mod_idP, CC_idP, current_rnti)) != -1) { // Check if this is an RA process for the rnti
 
+    RA_t *ra = (RA_t *) &(mac->common_channels[CC_idP].ra[RA_id]);
+
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+    if (ra->rach_resource_type > 0) {
+      harq_pid = 0;
     }
-  } else if ((RA_id = find_RA_id(enb_mod_idP, CC_idP, current_rnti)) != -1) {	// Check if this is an RA process for the rnti
-    AssertFatal(mac->common_channels[CC_idP].
-		radioResourceConfigCommon->rach_ConfigCommon.
-		maxHARQ_Msg3Tx > 1,
-		"maxHARQ %d should be greater than 1\n",
-		(int) mac->common_channels[CC_idP].
-		radioResourceConfigCommon->rach_ConfigCommon.
-		maxHARQ_Msg3Tx);
-
-    LOG_D(MAC,
-	  "[eNB %d][PUSCH %d] CC_id %d [RAPROC Msg3] Received ULSCH sdu round %d from PHY (rnti %x, RA_id %d) ul_cqi %d\n",
-	  enb_mod_idP, harq_pid, CC_idP, ra[RA_id].msg3_round,
-	  current_rnti, RA_id, ul_cqi);
+#endif
+
+    AssertFatal(mac->common_channels[CC_idP].radioResourceConfigCommon->rach_ConfigCommon.maxHARQ_Msg3Tx > 1,
+                "maxHARQ %d should be greater than 1\n",
+                (int) mac->common_channels[CC_idP].radioResourceConfigCommon->rach_ConfigCommon.maxHARQ_Msg3Tx);
+
+    LOG_D(MAC, "[eNB %d][PUSCH %d] CC_id %d [RAPROC Msg3] Received ULSCH sdu round %d from PHY (rnti %x, RA_id %d) ul_cqi %d\n",
+      enb_mod_idP,
+      harq_pid,
+      CC_idP,
+      ra->msg3_round,
+      current_rnti,
+      RA_id,
+      ul_cqi);
 
     first_rb = ra->msg3_first_rb;
 
-    if (sduP == NULL) {	// we've got an error on Msg3
-      LOG_D(MAC,
-	    "[eNB %d] CC_id %d, RA %d ULSCH in error in round %d/%d\n",
-	    enb_mod_idP, CC_idP, RA_id,
-	    ra[RA_id].msg3_round,
-	    (int) mac->common_channels[CC_idP].
-	    radioResourceConfigCommon->rach_ConfigCommon.
-	    maxHARQ_Msg3Tx);
-      if (ra[RA_id].msg3_round >= mac->common_channels[CC_idP].radioResourceConfigCommon->rach_ConfigCommon.maxHARQ_Msg3Tx - 1) {
-	cancel_ra_proc(enb_mod_idP, CC_idP, frameP, current_rnti);
-      }
+    if (sduP == NULL) { // we've got an error on Msg3
+      LOG_D(MAC, "[eNB %d] CC_id %d, RA %d ULSCH in error in round %d/%d\n",
+        enb_mod_idP,
+        CC_idP,
+        RA_id,
+        ra->msg3_round,
+        (int) mac->common_channels[CC_idP].radioResourceConfigCommon->rach_ConfigCommon.maxHARQ_Msg3Tx);
+
+      if (ra->msg3_round >= mac->common_channels[CC_idP].radioResourceConfigCommon->rach_ConfigCommon.maxHARQ_Msg3Tx - 1) {
+        cancel_ra_proc(enb_mod_idP, CC_idP, frameP, current_rnti);
+      } else {
+        // first_rb = UE_list->UE_template[CC_idP][UE_id].first_rb_ul[harq_pid]; // UE_id = -1 !!!!
+        ra->msg3_round++;
 
-      else {
-	first_rb = UE_list->UE_template[CC_idP][UE_id].first_rb_ul[harq_pid];
-	ra[RA_id].msg3_round++;
-	// prepare handling of retransmission
+        /* Prepare handling of retransmission */
         get_Msg3allocret(&mac->common_channels[CC_idP],
-                 ra[RA_id].Msg3_subframe, ra[RA_id].Msg3_frame,
-                 &ra[RA_id].Msg3_frame, &ra[RA_id].Msg3_subframe);
-	add_msg3(enb_mod_idP, CC_idP, &ra[RA_id], frameP, subframeP);
+                         ra->Msg3_subframe,
+                         ra->Msg3_frame,
+                         &ra->Msg3_frame,
+                         &ra->Msg3_subframe);
+        // prepare handling of retransmission
+
+        add_msg3(enb_mod_idP, CC_idP, ra, frameP, subframeP);
       }
 
       /* TODO: program NACK for PHICH? */
-
       return;
     }
   } else {
-    LOG_W(MAC,
-	  "Cannot find UE or RA corresponding to ULSCH rnti %x, dropping it\n",
-	  current_rnti);
+    LOG_W(MAC, "Cannot find UE or RA corresponding to ULSCH rnti %x, dropping it\n", current_rnti);
+
     return;
   }
+
   payload_ptr = parse_ulsch_header(sduP, &num_ce, &num_sdu, rx_ces, rx_lcids, rx_lengths, sdu_lenP);
 
-  if(payload_ptr == NULL){
-   LOG_E(MAC,"[eNB %d][PUSCH %d] CC_id %d ulsch header unknown lcid(rnti %x, UE_id %d)\n",
-         enb_mod_idP, harq_pid, CC_idP,current_rnti, UE_id);
-   return;
+  if (payload_ptr == NULL) {
+    LOG_E(MAC,"[eNB %d][PUSCH %d] CC_id %d ulsch header unknown lcid(rnti %x, UE_id %d)\n",
+      enb_mod_idP,
+      harq_pid,
+      CC_idP,
+      current_rnti,
+      UE_id);
+
+    return;
   }
 
-  T(T_ENB_MAC_UE_UL_PDU, T_INT(enb_mod_idP), T_INT(CC_idP),
-    T_INT(current_rnti), T_INT(frameP), T_INT(subframeP),
-    T_INT(harq_pid), T_INT(sdu_lenP), T_INT(num_ce), T_INT(num_sdu));
-  T(T_ENB_MAC_UE_UL_PDU_WITH_DATA, T_INT(enb_mod_idP), T_INT(CC_idP),
-    T_INT(current_rnti), T_INT(frameP), T_INT(subframeP),
-    T_INT(harq_pid), T_INT(sdu_lenP), T_INT(num_ce), T_INT(num_sdu),
+  T(T_ENB_MAC_UE_UL_PDU,
+    T_INT(enb_mod_idP),
+    T_INT(CC_idP),
+    T_INT(current_rnti),
+    T_INT(frameP),
+    T_INT(subframeP),
+    T_INT(harq_pid),
+    T_INT(sdu_lenP),
+    T_INT(num_ce),
+    T_INT(num_sdu));
+
+  T(T_ENB_MAC_UE_UL_PDU_WITH_DATA,
+    T_INT(enb_mod_idP),
+    T_INT(CC_idP),
+    T_INT(current_rnti),
+    T_INT(frameP),
+    T_INT(subframeP),
+    T_INT(harq_pid),
+    T_INT(sdu_lenP),
+    T_INT(num_ce),
+    T_INT(num_sdu),
     T_BUFFER(sduP, sdu_lenP));
 
   mac->eNB_stats[CC_idP].ulsch_bytes_rx = sdu_lenP;
   mac->eNB_stats[CC_idP].total_ulsch_bytes_rx += sdu_lenP;
   mac->eNB_stats[CC_idP].total_ulsch_pdus_rx += 1;
+  if (UE_id != -1) {
+    UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid] = 0;
+  }
 
-  UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid] = 0;
+  /* Control element */
+  for (int i = 0; i < num_ce; i++) {
+    T(T_ENB_MAC_UE_UL_CE,
+      T_INT(enb_mod_idP),
+      T_INT(CC_idP),
+      T_INT(current_rnti),
+      T_INT(frameP),
+      T_INT(subframeP),
+      T_INT(rx_ces[i]));
 
-  // control element
-  for (i = 0; i < num_ce; i++) {
+    switch (rx_ces[i]) {  // implement and process PHR + CRNTI + BSR
+      case POWER_HEADROOM:
+        if (UE_id != -1) {
+          UE_list->UE_template[CC_idP][UE_id].phr_info = (payload_ptr[0] & 0x3f) - PHR_MAPPING_OFFSET + (int8_t)(hundred_times_log10_NPRB[UE_list->UE_template[CC_idP][UE_id].nb_rb_ul[harq_pid] - 1] / 100);
 
-    T(T_ENB_MAC_UE_UL_CE, T_INT(enb_mod_idP), T_INT(CC_idP),
-      T_INT(current_rnti), T_INT(frameP), T_INT(subframeP),
-      T_INT(rx_ces[i]));
+          if (UE_list->UE_template[CC_idP][UE_id].phr_info > 40) {
+            UE_list->UE_template[CC_idP][UE_id].phr_info = 40;
+          }
 
-    switch (rx_ces[i]) {	// implement and process BSR + CRNTI +
-    case POWER_HEADROOM:
-      if (UE_id != -1) {
-	UE_list->UE_template[CC_idP][UE_id].phr_info =
-	  (payload_ptr[0] & 0x3f) - PHR_MAPPING_OFFSET;
-	LOG_D(MAC,
-	      "[eNB %d] CC_id %d MAC CE_LCID %d : Received PHR PH = %d (db)\n",
-	      enb_mod_idP, CC_idP, rx_ces[i],
-	      UE_list->UE_template[CC_idP][UE_id].phr_info);
-	UE_list->UE_template[CC_idP][UE_id].phr_info_configured =
-	  1;
-	UE_list->UE_sched_ctrl[UE_id].phr_received = 1;
-      }
-      payload_ptr += sizeof(POWER_HEADROOM_CMD);
-      break;
-
-    case CRNTI:
-      {
-	int old_rnti =
-	  (((uint16_t) payload_ptr[0]) << 8) + payload_ptr[1];
-	int old_UE_id = find_UE_id(enb_mod_idP, old_rnti);
-	LOG_D(MAC,
-	      "[eNB %d] Frame %d, Subframe %d CC_id %d MAC CE_LCID %d (ce %d/%d): CRNTI %x (UE_id %d) in Msg3\n",
-	      enb_mod_idP, frameP, subframeP, CC_idP, rx_ces[i], i,
-	      num_ce, old_rnti, old_UE_id);
-	/* receiving CRNTI means that the current rnti has to go away */
-	//cancel_ra_proc(enb_mod_idP, CC_idP, frameP,
-	//	       current_rnti);
-	if (old_UE_id != -1) {
-	  /* TODO: if the UE did random access (followed by a MAC uplink with
-	   * CRNTI) because none of its scheduling request was granted, then
-	   * according to 36.321 5.4.4 the UE's MAC will notify RRC to release
-	   * PUCCH/SRS. According to 36.331 5.3.13 the UE will then apply
-	   * default configuration for CQI reporting and scheduling requests,
-	   * which basically means that the CQI requests won't work anymore and
-	   * that the UE won't do any scheduling request anymore as long as the
-	   * eNB doesn't reconfigure the UE.
-	   * We have to take care of this. As the code is, nothing is done and
-	   * the UE state in the eNB is wrong.
-	   */
-          for (ii = 0; ii < NB_RA_PROC_MAX; ii++) {
-            ra = &mac->common_channels[CC_idP].ra[ii];
-            if ((ra->rnti == current_rnti) && (ra->state != IDLE)) {
-              mac_rrc_data_ind(
-                   enb_mod_idP,
-                   CC_idP,
-                   frameP, subframeP, old_UE_id,
-                   old_rnti,
-                   DCCH,
-                   (uint8_t *) payload_ptr,
-                   rx_lengths[i],
-                   0
-              );
-              // prepare transmission of Msg4(RRCConnectionReconfiguration)
-              ra->state = MSGCRNTI;
-              LOG_D(MAC,
-                    "[eNB %d] Frame %d, Subframe %d CC_id %d : (rnti %x UE_id %d) RRCConnectionReconfiguration(Msg4)\n",
-                    enb_mod_idP, frameP, subframeP, CC_idP, old_rnti, old_UE_id);
+          LOG_D(MAC, "[eNB %d] CC_id %d MAC CE_LCID %d : Received PHR PH = %d (db)\n",
+            enb_mod_idP,
+            CC_idP,
+            rx_ces[i],
+            UE_list->UE_template[CC_idP][UE_id].phr_info);
+
+          UE_list->UE_template[CC_idP][UE_id].phr_info_configured = 1;
+          UE_list->UE_sched_ctrl[UE_id].phr_received = 1;
+        }
+
+        payload_ptr += sizeof(POWER_HEADROOM_CMD);
+
+        break;
+
+      case CRNTI:
+        old_rnti = (((uint16_t) payload_ptr[0]) << 8) + payload_ptr[1];
+        old_UE_id = find_UE_id(enb_mod_idP, old_rnti);
+
+        LOG_D(MAC, "[eNB %d] Frame %d, Subframe %d CC_id %d MAC CE_LCID %d (ce %d/%d): CRNTI %x (UE_id %d) in Msg3\n",
+          enb_mod_idP,
+          frameP,
+          subframeP,
+          CC_idP,
+          rx_ces[i],
+          i,
+          num_ce,
+          old_rnti,
+          old_UE_id);
+
+        /* Receiving CRNTI means that the current rnti has to go away */
+        if (old_UE_id != -1) {
+          if (mac_eNB_get_rrc_status(enb_mod_idP,old_rnti) ==  RRC_HO_EXECUTION) {
+            LOG_I(MAC,
+                  "[eNB %d] Frame %d, Subframe %d CC_id %d : (rnti %x UE_id %d) Handover case\n",
+                  enb_mod_idP, frameP, subframeP, CC_idP, old_rnti, old_UE_id);
+            UE_id = old_UE_id;
+            current_rnti = old_rnti;
+            //clear timer
+            UE_list->UE_sched_ctrl[UE_id].uplane_inactivity_timer = 0;
+            UE_list->UE_sched_ctrl[UE_id].ul_inactivity_timer = 0;
+            UE_list->UE_sched_ctrl[UE_id].ul_failure_timer = 0;
+
+            if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync > 0) {
+              UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync = 0;
+              mac_eNB_rrc_ul_in_sync(enb_mod_idP, CC_idP, frameP,
+                                     subframeP, old_rnti);
+            }
 
+            UE_list->UE_template[CC_idP][UE_id].ul_SR = 1;
+            UE_list->UE_sched_ctrl[UE_id].crnti_reconfigurationcomplete_flag = 1;
+            UE_list->UE_template[UE_PCCID(enb_mod_idP, UE_id)][UE_id].configured = 1;
+            cancel_ra_proc(enb_mod_idP, CC_idP, frameP,current_rnti);
+          } else {
+            /* TODO: if the UE did random access (followed by a MAC uplink with
+             * CRNTI) because none of its scheduling request was granted, then
+             * according to 36.321 5.4.4 the UE's MAC will notify RRC to release
+             * PUCCH/SRS. According to 36.331 5.3.13 the UE will then apply
+             * default configuration for CQI reporting and scheduling requests,
+             * which basically means that the CQI requests won't work anymore and
+             * that the UE won't do any scheduling request anymore as long as the
+             * eNB doesn't reconfigure the UE.
+             * We have to take care of this. As the code is, nothing is done and
+             * the UE state in the eNB is wrong.
+             */
+            RA_id = find_RA_id(enb_mod_idP, CC_idP, current_rnti);
+
+            if (RA_id != -1) {
+              RA_t *ra = &(mac->common_channels[CC_idP].ra[RA_id]);
+              mac_rrc_data_ind(enb_mod_idP,
+                               CC_idP,
+                               frameP, subframeP,
+                               UE_id,
+                               old_rnti,
+                               DCCH,
+                               (uint8_t *) payload_ptr,
+                               rx_lengths[i],
+                               0
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                               ,ra->rach_resource_type > 0
+#endif
+                              );
+              /* Prepare transmission of Msg4(RRCConnectionReconfiguration) */
+              ra->state = MSGCRNTI;
+              LOG_I(MAC, "[eNB %d] Frame %d, Subframe %d CC_id %d : (rnti %x UE_id %d) RRCConnectionReconfiguration(Msg4)\n",
+                    enb_mod_idP,
+                    frameP,
+                    subframeP,
+                    CC_idP,
+                    old_rnti,
+                    old_UE_id);
               UE_id = old_UE_id;
               current_rnti = old_rnti;
               ra->rnti = old_rnti;
               ra->crnti_rrc_mui = rrc_eNB_mui-1;
               ra->crnti_harq_pid = -1;
-              //clear timer
+              /* Clear timer */
+              UE_list->UE_sched_ctrl[UE_id].uplane_inactivity_timer = 0;
               UE_list->UE_sched_ctrl[UE_id].uplane_inactivity_timer = 0;
               UE_list->UE_sched_ctrl[UE_id].ul_inactivity_timer = 0;
               UE_list->UE_sched_ctrl[UE_id].ul_failure_timer = 0;
+
               if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync > 0) {
                 UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync = 0;
-                mac_eNB_rrc_ul_in_sync(enb_mod_idP, CC_idP, frameP,
-                                       subframeP, old_rnti);
+                mac_eNB_rrc_ul_in_sync(enb_mod_idP, CC_idP, frameP, subframeP, old_rnti);
               }
+
               UE_list->UE_template[CC_idP][UE_id].ul_SR = 1;
               UE_list->UE_sched_ctrl[UE_id].crnti_reconfigurationcomplete_flag = 1;
-              break;
+              // break;
             }
           }
         } else {
-          cancel_ra_proc(enb_mod_idP, CC_idP, frameP,current_rnti);
+          cancel_ra_proc(enb_mod_idP, CC_idP, frameP, current_rnti);
+          LOG_W(MAC, "[MAC] Can't find old UE_id\n");
         }
-	crnti_rx = 1;
-	payload_ptr += 2;
-	break;
-      }
 
-    case TRUNCATED_BSR:
-    case SHORT_BSR:
-      {
-	uint8_t lcgid;
-	lcgid = (payload_ptr[0] >> 6);
-
-	LOG_D(MAC,
-	      "[eNB %d] CC_id %d MAC CE_LCID %d : Received short BSR LCGID = %u bsr = %d\n",
-	      enb_mod_idP, CC_idP, rx_ces[i], lcgid,
-	      payload_ptr[0] & 0x3f);
-
-	if (crnti_rx == 1)
-	  LOG_D(MAC,
-		"[eNB %d] CC_id %d MAC CE_LCID %d : Received short BSR LCGID = %u bsr = %d\n",
-		enb_mod_idP, CC_idP, rx_ces[i], lcgid,
-		payload_ptr[0] & 0x3f);
-	if (UE_id != -1) {
-          int bsr = payload_ptr[0] & 0x3f;
+        crnti_rx = 1;
+        payload_ptr += 2; // sizeof(CRNTI)
+
+        break;
+
+      case TRUNCATED_BSR:
 
+      case SHORT_BSR:
+        lcgid = (payload_ptr[0] >> 6);
+
+        LOG_D(MAC, "[eNB %d] CC_id %d MAC CE_LCID %d : Received short BSR LCGID = %u bsr = %d\n",
+          enb_mod_idP,
+          CC_idP,
+          rx_ces[i],
+          lcgid,
+          payload_ptr[0] & 0x3f);
+
+        if (UE_id != -1) {
+          int bsr = 0;
+
+          bsr = payload_ptr[0] & 0x3f;
           lcgid_updated[lcgid] = 1;
 
-          // update buffer info
+          /* Update buffer info */
           UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[lcgid] = BSR_TABLE[bsr];
-
           UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer =
-              UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID0] +
-              UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID1] +
-              UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID2] +
-              UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID3];
-          //UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer += UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer / 4;
-
-	  RC.eNB[enb_mod_idP][CC_idP]->pusch_stats_bsr[UE_id][(frameP * 10) + subframeP] = (payload_ptr[0] & 0x3f);
-	  if (UE_id == UE_list->head)
-	    VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_BSR,
-						    RC.eNB[enb_mod_idP][CC_idP]->pusch_stats_bsr
-						    [UE_id][(frameP * 10) + subframeP]);
-	  if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[lcgid] == 0) {
-	    UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[lcgid] = frameP;
-	  }
-	  if (mac_eNB_get_rrc_status(enb_mod_idP,UE_RNTI(enb_mod_idP, UE_id)) < RRC_CONNECTED)
-	    LOG_D(MAC,
-		  "[eNB %d] CC_id %d MAC CE_LCID %d : estimated_ul_buffer = %d (lcg increment %d)\n",
-		  enb_mod_idP, CC_idP, rx_ces[i],
-		  UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer,
-		  UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[lcgid]);
-	} else {
-
-	}
-	payload_ptr += 1;	//sizeof(SHORT_BSR); // fixme
-      }
-      break;
-
-    case LONG_BSR:
-      if (UE_id != -1) {
-        int bsr0 = (payload_ptr[0] & 0xFC) >> 2;
-        int bsr1 = ((payload_ptr[0] & 0x03) << 4) | ((payload_ptr[1] & 0xF0) >> 4);
-        int bsr2 = ((payload_ptr[1] & 0x0F) << 2) | ((payload_ptr[2] & 0xC0) >> 6);
-        int bsr3 = payload_ptr[2] & 0x3F;
-
-        lcgid_updated[LCGID0] = 1;
-        lcgid_updated[LCGID1] = 1;
-        lcgid_updated[LCGID2] = 1;
-        lcgid_updated[LCGID3] = 1;
-
-        // update buffer info
-        UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID0] = BSR_TABLE[bsr0];
-        UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID1] = BSR_TABLE[bsr1];
-        UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID2] = BSR_TABLE[bsr2];
-        UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID3] = BSR_TABLE[bsr3];
-
-        UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer =
             UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID0] +
             UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID1] +
             UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID2] +
             UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID3];
-        //UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer += UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer / 4;
 
-        LOG_D(MAC,
-              "[eNB %d] CC_id %d MAC CE_LCID %d: Received long BSR. Size is LCGID0 = %u LCGID1 = "
-              "%u LCGID2 = %u LCGID3 = %u\n", enb_mod_idP, CC_idP,
+          RC.eNB[enb_mod_idP][CC_idP]->pusch_stats_bsr[UE_id][(frameP * 10) + subframeP] = (payload_ptr[0] & 0x3f);
+
+          if (UE_id == UE_list->head) {
+            VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_BSR, (payload_ptr[0] & 0x3f));
+          }
+
+          if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[lcgid] == 0) {
+            UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[lcgid] = frameP;
+          }
+
+          if (mac_eNB_get_rrc_status(enb_mod_idP,UE_RNTI(enb_mod_idP, UE_id)) < RRC_CONNECTED) {
+            LOG_D(MAC, "[eNB %d] CC_id %d MAC CE_LCID %d : estimated_ul_buffer = %d (lcg increment %d)\n",
+              enb_mod_idP,
+              CC_idP,
               rx_ces[i],
-              UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID0],
-              UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID1],
-              UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID2],
-              UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID3]);
-        if (crnti_rx == 1)
-          LOG_D(MAC,
-                "[eNB %d] CC_id %d MAC CE_LCID %d: Received long BSR. Size is LCGID0 = %u LCGID1 = "
-                "%u LCGID2 = %u LCGID3 = %u\n", enb_mod_idP,
-                CC_idP, rx_ces[i],
-                UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID0],
-                UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID1],
-                UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID2],
-                UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID3]);
-
-	if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID0] == 0) {
-	  UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID0] = 0;
-	} else if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID0] == 0) {
-	  UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID0] = frameP;
-	}
-
-	if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID1] == 0) {
-	  UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID1] = 0;
-	} else if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID1] == 0) {
-	  UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID1] = frameP;
-	}
-
-	if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID2] == 0) {
-	  UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID2] = 0;
-	} else if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID2] == 0) {
-	  UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID2] = frameP;
-	}
-
-	if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID3] == 0) {
-	  UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID3] = 0;
-	} else if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID3] == 0) {
-	  UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID3] = frameP;
-
-	}
-      }
+              UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer,
+              UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[lcgid]);
+          }
 
-      payload_ptr += 3;	////sizeof(LONG_BSR);
-      break;
+        } else {
+          /* Need error message */
+        }
 
-    default:
-      LOG_E(MAC,
-	    "[eNB %d] CC_id %d Received unknown MAC header (0x%02x)\n",
-	    enb_mod_idP, CC_idP, rx_ces[i]);
-      break;
-    }
-  }
+        payload_ptr += 1;  // sizeof(SHORT_BSR)
 
-  for (i = 0; i < num_sdu; i++) {
-    LOG_D(MAC, "SDU Number %d MAC Subheader SDU_LCID %d, length %d\n",
-	  i, rx_lcids[i], rx_lengths[i]);
+        break;
+
+      case LONG_BSR:
+        if (UE_id != -1) {
+          int bsr0 = (payload_ptr[0] & 0xFC) >> 2;
+          int bsr1 = ((payload_ptr[0] & 0x03) << 4) | ((payload_ptr[1] & 0xF0) >> 4);
+          int bsr2 = ((payload_ptr[1] & 0x0F) << 2) | ((payload_ptr[2] & 0xC0) >> 6);
+          int bsr3 = payload_ptr[2] & 0x3F;
+
+          lcgid_updated[LCGID0] = 1;
+          lcgid_updated[LCGID1] = 1;
+          lcgid_updated[LCGID2] = 1;
+          lcgid_updated[LCGID3] = 1;
+
+          /* Update buffer info */
+          UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID0] = BSR_TABLE[bsr0];
+          UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID1] = BSR_TABLE[bsr1];
+          UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID2] = BSR_TABLE[bsr2];
+          UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID3] = BSR_TABLE[bsr3];
 
-    T(T_ENB_MAC_UE_UL_SDU, T_INT(enb_mod_idP), T_INT(CC_idP),
-      T_INT(current_rnti), T_INT(frameP), T_INT(subframeP),
-      T_INT(rx_lcids[i]), T_INT(rx_lengths[i]));
-    T(T_ENB_MAC_UE_UL_SDU_WITH_DATA, T_INT(enb_mod_idP), T_INT(CC_idP),
-      T_INT(current_rnti), T_INT(frameP), T_INT(subframeP),
-      T_INT(rx_lcids[i]), T_INT(rx_lengths[i]), T_BUFFER(payload_ptr,
-							 rx_lengths
-							 [i]));
+          UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer =
+            UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID0] +
+            UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID1] +
+            UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID2] +
+            UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID3];
+
+          LOG_D(MAC, "[eNB %d] CC_id %d MAC CE_LCID %d: Received long BSR. Size is LCGID0 = %u LCGID1 = %u LCGID2 = %u LCGID3 = %u\n",
+            enb_mod_idP,
+            CC_idP,
+            rx_ces[i],
+            UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID0],
+            UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID1],
+            UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID2],
+            UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID3]);
+
+          if (crnti_rx == 1) {
+            LOG_D(MAC, "[eNB %d] CC_id %d MAC CE_LCID %d: Received CRNTI.\n",
+              enb_mod_idP,
+              CC_idP,
+              rx_ces[i]);
+          }
+
+          for(int lcgid = 0; lcgid <= LCGID3; lcgid++) {
+            if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[lcgid] == 0) {
+              UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[lcgid] = 0;
+            } else if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[lcgid] == 0) {
+              UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[lcgid] = frameP;
+            }
+          }
+        }
+
+        payload_ptr += 3; // sizeof(LONG_BSR)
+        break;
+
+      default:
+        LOG_E(MAC, "[eNB %d] CC_id %d Received unknown MAC header (0x%02x)\n",
+          enb_mod_idP,
+          CC_idP,
+          rx_ces[i]);
+
+        break;
+
+    } // end switch on control element
+  } // end for loop on control element
+
+  for (int i = 0; i < num_sdu; i++) {
+    LOG_D(MAC, "SDU Number %d MAC Subheader SDU_LCID %d, length %d\n",
+      i,
+      rx_lcids[i],
+      rx_lengths[i]);
+
+    T(T_ENB_MAC_UE_UL_SDU,
+      T_INT(enb_mod_idP),
+      T_INT(CC_idP),
+      T_INT(current_rnti),
+      T_INT(frameP),
+      T_INT(subframeP),
+      T_INT(rx_lcids[i]),
+      T_INT(rx_lengths[i]));
+
+    T(T_ENB_MAC_UE_UL_SDU_WITH_DATA,
+      T_INT(enb_mod_idP),
+      T_INT(CC_idP),
+      T_INT(current_rnti),
+      T_INT(frameP),
+      T_INT(subframeP),
+      T_INT(rx_lcids[i]),
+      T_INT(rx_lengths[i]),
+      T_BUFFER(payload_ptr, rx_lengths[i]));
 
     switch (rx_lcids[i]) {
-    case CCCH:
-      if (rx_lengths[i] > CCCH_PAYLOAD_SIZE_MAX) {
-	LOG_E(MAC,
-	      "[eNB %d/%d] frame %d received CCCH of size %d (too big, maximum allowed is %d, sdu_len %d), dropping packet\n",
-	      enb_mod_idP, CC_idP, frameP, rx_lengths[i],
-	      CCCH_PAYLOAD_SIZE_MAX, sdu_lenP);
-	break;
-      }
-      LOG_D(MAC,
-	    "[eNB %d][RAPROC] CC_id %d Frame %d, Received CCCH:  %x.%x.%x.%x.%x.%x, Terminating RA procedure for UE rnti %x\n",
-	    enb_mod_idP, CC_idP, frameP, payload_ptr[0],
-	    payload_ptr[1], payload_ptr[2], payload_ptr[3],
-	    payload_ptr[4], payload_ptr[5], current_rnti);
-      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_TERMINATE_RA_PROC, 1);
-      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_TERMINATE_RA_PROC, 0);
-      for (ii = 0; ii < NB_RA_PROC_MAX; ii++) {
-	RA_t *ra = &mac->common_channels[CC_idP].ra[ii];
-
-	LOG_D(MAC,
-	      "[mac %d][RAPROC] CC_id %d Checking proc %d : rnti (%x, %x), state %d\n",
-	      enb_mod_idP, CC_idP, ii, ra->rnti,
-	      current_rnti, ra->state);
-
-	if ((ra->rnti == current_rnti) && (ra->state != IDLE)) {
-
-	  //payload_ptr = parse_ulsch_header(msg3,&num_ce,&num_sdu,rx_ces,rx_lcids,rx_lengths,msg3_len);
-
-	  if (UE_id < 0) {
-	    memcpy(&ra->cont_res_id[0], payload_ptr, 6);
-	    LOG_D(MAC,
-		  "[eNB %d][RAPROC] CC_id %d Frame %d CCCH: Received Msg3: length %d, offset %ld\n",
-		  enb_mod_idP, CC_idP, frameP, rx_lengths[i],
-		  payload_ptr - sduP);
-
-	    if ((UE_id = add_new_ue(enb_mod_idP, CC_idP,
-				    mac->common_channels[CC_idP].
-				    ra[ii].rnti, harq_pid
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-				    ,
-				    mac->common_channels[CC_idP].
-				    ra[ii].rach_resource_type
+      case CCCH:
+        if (rx_lengths[i] > CCCH_PAYLOAD_SIZE_MAX) {
+          LOG_E(MAC, "[eNB %d/%d] frame %d received CCCH of size %d (too big, maximum allowed is %d, sdu_len %d), dropping packet\n",
+            enb_mod_idP,
+            CC_idP,
+            frameP,
+            rx_lengths[i],
+            CCCH_PAYLOAD_SIZE_MAX,
+            sdu_lenP);
+
+          break;
+        }
+
+        LOG_D(MAC, "[eNB %d][RAPROC] CC_id %d Frame %d, Received CCCH:  %x.%x.%x.%x.%x.%x, Terminating RA procedure for UE rnti %x\n",
+          enb_mod_idP,
+          CC_idP,
+          frameP,
+          payload_ptr[0], payload_ptr[1], payload_ptr[2], payload_ptr[3], payload_ptr[4], payload_ptr[5],
+          current_rnti);
+
+        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_TERMINATE_RA_PROC, 1);
+        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_TERMINATE_RA_PROC, 0);
+
+        RA_id = find_RA_id(enb_mod_idP, CC_idP, current_rnti);
+
+        if (RA_id != -1) {
+          RA_t *ra = &(mac->common_channels[CC_idP].ra[RA_id]);
+
+          LOG_D(MAC, "[mac %d][RAPROC] CC_id %d Checking proc %d : rnti (%x, %x), state %d\n",
+            enb_mod_idP,
+            CC_idP,
+            RA_id,
+            ra->rnti,
+            current_rnti,
+            ra->state);
+
+          if (UE_id < 0) {
+            memcpy(&(ra->cont_res_id[0]), payload_ptr, 6);
+
+            LOG_D(MAC, "[eNB %d][RAPROC] CC_id %d Frame %d CCCH: Received Msg3: length %d, offset %ld\n",
+              enb_mod_idP,
+              CC_idP,
+              frameP,
+              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 (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                                    , mac->common_channels[CC_idP].ra->rach_resource_type
 #endif
-				    )) == -1) {
+                                    )) == -1) {
               LOG_E(MAC,"[MAC][eNB] Max user count reached\n");
-              cancel_ra_proc(enb_mod_idP, CC_idP, frameP,current_rnti);
-              break;
-	      // kill RA procedure
-	    } else
-	      LOG_D(MAC,
-		    "[eNB %d][RAPROC] CC_id %d Frame %d Added user with rnti %x => UE %d\n",
-		    enb_mod_idP, CC_idP, frameP, ra->rnti,
-		    UE_id);
-	  } else {
-	    LOG_D(MAC,
-		  "[eNB %d][RAPROC] CC_id %d Frame %d CCCH: Received Msg3 from already registered UE %d: length %d, offset %ld\n",
-		  enb_mod_idP, CC_idP, frameP, UE_id,
-		  rx_lengths[i], payload_ptr - sduP);
-	    // kill RA procedure
-	  }
-    
-	  mac_rrc_data_ind(
-			   enb_mod_idP,
-			   CC_idP,
-			   frameP, subframeP, UE_id,
-			   current_rnti,
-			   CCCH,
-			   (uint8_t *) payload_ptr,
-			   rx_lengths[i],
-			   0
-			   );
-
-
-	  if (num_ce > 0) {	// handle msg3 which is not RRCConnectionRequest
-	    //  process_ra_message(msg3,num_ce,rx_lcids,rx_ces);
-	  }
-	  // prepare transmission of Msg4
-	  ra->state = MSG4;
-
-
-
-          if(mac->common_channels[CC_idP].tdd_Config!=NULL){
-            switch(mac->common_channels[CC_idP].tdd_Config->subframeAssignment){
-            case 1:
-              ra->Msg4_frame = frameP + ((subframeP > 2) ? 1 : 0);
-              ra->Msg4_subframe = (subframeP + 7) % 10;
+
+              cancel_ra_proc(enb_mod_idP, CC_idP, frameP, current_rnti); // send Connection Reject ???
+
               break;
-            default: printf("%s:%d: TODO\n", __FILE__, __LINE__); abort();
-             // TODO need to be complete for other tdd configs.
+              // kill RA proc
+            } else {
+              LOG_D(MAC, "[eNB %d][RAPROC] CC_id %d Frame %d Added user with rnti %x => UE %d\n",
+                    enb_mod_idP,
+                    CC_idP,
+                    frameP,
+                    ra->rnti,
+                    UE_id);
+            }
+          } else {
+            LOG_D(MAC, "[eNB %d][RAPROC] CC_id %d Frame %d CCCH: Received Msg3 from already registered UE %d: length %d, offset %ld\n",
+                  enb_mod_idP,
+                  CC_idP,
+                  frameP,
+                  UE_id,
+                  rx_lengths[i],
+                  payload_ptr - sduP);
+            // kill RA proc
+          }
+
+          mac_rrc_data_ind(enb_mod_idP,
+                            CC_idP,
+                            frameP, subframeP,
+                            UE_id,
+                            current_rnti,
+                            CCCH,
+                            (uint8_t *) payload_ptr,
+                            rx_lengths[i],
+                            0
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                            ,ra->rach_resource_type > 0
+#endif
+                            );
+
+          if (num_ce > 0) { // handle msg3 which is not RRCConnectionRequest
+            //  process_ra_message(msg3,num_ce,rx_lcids,rx_ces);
+          }
+
+          // prepare transmission of Msg4
+          ra->state = MSG4;
+
+          if(mac->common_channels[CC_idP].tdd_Config != NULL) {
+            switch(mac->common_channels[CC_idP].tdd_Config->subframeAssignment) {
+              case 1:
+                ra->Msg4_frame = frameP + ((subframeP > 2) ? 1 : 0);
+                ra->Msg4_subframe = (subframeP + 7) % 10;
+                break;
+
+              default:
+                printf("%s:%d: TODO\n", __FILE__, __LINE__);
+                abort();
+                // TODO need to be complete for other tdd configs.
             }
-          }else{
-            // Program Msg4 PDCCH+DLSCH/MPDCCH transmission 4 subframes from now, // Check if this is ok for BL/CE, or if the rule is different
+          } else {
+            /* Program Msg4 PDCCH+DLSCH/MPDCCH transmission 4 subframes from now,
+              * Check if this is ok for BL/CE, or if the rule is different
+              */
             ra->Msg4_frame = frameP + ((subframeP > 5) ? 1 : 0);
             ra->Msg4_subframe = (subframeP + 4) % 10;
           }
 
           UE_list->UE_sched_ctrl[UE_id].crnti_reconfigurationcomplete_flag = 0;
-	}		// if process is active
-      }			// loop on RA processes
+        } // if RA process is active
 
-      break;
+        break;
 
-    case DCCH:
-    case DCCH1:
-      //      if(eNB_mac_inst[module_idP][CC_idP].Dcch_lchan[UE_id].Active==1){
+      case DCCH:
 
+      case DCCH1:
 
 #if defined(ENABLE_MAC_PAYLOAD_DEBUG)
-      LOG_T(MAC, "offset: %d\n",
-	    (unsigned char) ((unsigned char *) payload_ptr - sduP));
-      for (j = 0; j < 32; j++) {
-	LOG_T(MAC, "%x ", payload_ptr[j]);
-      }
-      LOG_T(MAC, "\n");
-#endif
-
-      if (UE_id != -1) {
-        if (lcgid_updated[UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]]] == 0) {
-	  // adjust buffer occupancy of the correponding logical channel group
-	  if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]]] >= rx_lengths[i])
-	    UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]]] -= rx_lengths[i];
-	  else
-	    UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]]] = 0;
+        LOG_T(MAC, "offset: %d\n", (unsigned char) ((unsigned char *) payload_ptr - sduP));
 
-          UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer =
-          UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[0] +
-          UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[1] +
-          UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[2] +
-          UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[3];
-          //UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer += UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer / 4;
+        for (int j = 0; j < 32; j++) {
+          LOG_T(MAC, "%x ", payload_ptr[j]);
         }
 
-	LOG_D(MAC,
-	      "[eNB %d] CC_id %d Frame %d : ULSCH -> UL-DCCH, received %d bytes form UE %d on LCID %d \n",
-	      enb_mod_idP, CC_idP, frameP, rx_lengths[i], UE_id,
-	      rx_lcids[i]);
+        LOG_T(MAC, "\n");
+#endif
 
-	mac_rlc_data_ind(enb_mod_idP, current_rnti, enb_mod_idP, frameP, ENB_FLAG_YES, MBMS_FLAG_NO, rx_lcids[i], (char *) payload_ptr, rx_lengths[i], 1, NULL);	//(unsigned int*)crc_status);
-	UE_list->eNB_UE_stats[CC_idP][UE_id].num_pdu_rx[rx_lcids[i]] += 1;
-	UE_list->eNB_UE_stats[CC_idP][UE_id].num_bytes_rx[rx_lcids[i]] += rx_lengths[i];
+        if (UE_id != -1) {
+          if (lcgid_updated[UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]]] == 0) {
+            /* Adjust buffer occupancy of the correponding logical channel group */
+            if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]]] >= rx_lengths[i])
+              UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]]] -= rx_lengths[i];
+            else
+              UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]]] = 0;
 
+            UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer =
+              UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[0] +
+              UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[1] +
+              UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[2] +
+              UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[3];
+            //UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer += UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer / 4;
+          }
 
-      }
+          LOG_D(MAC,
+                "[eNB %d] CC_id %d Frame %d : ULSCH -> UL-DCCH, received %d bytes form UE %d on LCID %d \n",
+                enb_mod_idP, CC_idP, frameP, rx_lengths[i], UE_id,
+                rx_lcids[i]);
+          mac_rlc_data_ind(enb_mod_idP, current_rnti, enb_mod_idP, frameP, ENB_FLAG_YES, MBMS_FLAG_NO, rx_lcids[i], (char *) payload_ptr, rx_lengths[i], 1, NULL);  //(unsigned int*)crc_status);
+          UE_list->eNB_UE_stats[CC_idP][UE_id].num_pdu_rx[rx_lcids[i]] += 1;
+          UE_list->eNB_UE_stats[CC_idP][UE_id].num_bytes_rx[rx_lcids[i]] += rx_lengths[i];
+        }
 
-      /* UE_id != -1 */
-      // }
-      break;
+        break;
 
       // all the DRBS
-    case DTCH:
-    default:
-
+      case DTCH:
+      default:
 #if defined(ENABLE_MAC_PAYLOAD_DEBUG)
-      LOG_T(MAC, "offset: %d\n",
-	    (unsigned char) ((unsigned char *) payload_ptr - sduP));
-      for (j = 0; j < 32; j++) {
-	LOG_T(MAC, "%x ", payload_ptr[j]);
-      }
-      LOG_T(MAC, "\n");
+        LOG_T(MAC, "offset: %d\n",
+              (unsigned char) ((unsigned char *) payload_ptr - sduP));
+
+        for (int j = 0; j < 32; j++) {
+          LOG_T(MAC, "%x ", payload_ptr[j]);
+        }
+
+        LOG_T(MAC, "\n");
 #endif
-      if (rx_lcids[i] < NB_RB_MAX) {
-	LOG_D(MAC,
-	      "[eNB %d] CC_id %d Frame %d : ULSCH -> UL-DTCH, received %d bytes from UE %d for lcid %d\n",
-	      enb_mod_idP, CC_idP, frameP, rx_lengths[i], UE_id,
-	      rx_lcids[i]);
-
-	if (UE_id != -1) {
-	  // adjust buffer occupancy of the correponding logical channel group
-	  LOG_D(MAC,
-		"[eNB %d] CC_id %d Frame %d : ULSCH -> UL-DTCH, received %d bytes from UE %d for lcid %d, removing from LCGID %ld, %d\n",
-		enb_mod_idP, CC_idP, frameP, rx_lengths[i],
-		UE_id, rx_lcids[i],
-		UE_list->UE_template[CC_idP][UE_id].
-		lcgidmap[rx_lcids[i]],
-		UE_list->UE_template[CC_idP][UE_id].
-		ul_buffer_info[UE_list->UE_template[CC_idP]
-			       [UE_id].lcgidmap[rx_lcids[i]]]);
 
-          if (lcgid_updated[UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]]] == 0) {
-	    if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]]] >= rx_lengths[i])
-	      UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]]] -= rx_lengths[i];
-	    else
-	      UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]]] = 0;
+        if (rx_lcids[i] < NB_RB_MAX) {
+          LOG_D(MAC, "[eNB %d] CC_id %d Frame %d : ULSCH -> UL-DTCH, received %d bytes from UE %d for lcid %d\n",
+                enb_mod_idP,
+                CC_idP,
+                frameP,
+                rx_lengths[i],
+                UE_id,
+                rx_lcids[i]);
+
+          if (UE_id != -1) {
+            /* Adjust buffer occupancy of the correponding logical channel group */
+            LOG_D(MAC, "[eNB %d] CC_id %d Frame %d : ULSCH -> UL-DTCH, received %d bytes from UE %d for lcid %d, removing from LCGID %ld, %d\n",
+                  enb_mod_idP,
+                  CC_idP,
+                  frameP,
+                  rx_lengths[i],
+                  UE_id,
+                  rx_lcids[i],
+                  UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]],
+                  UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]]]);
+
+            if (lcgid_updated[UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]]] == 0) {
+              if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]]] >= rx_lengths[i]) {
+                UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]]] -= rx_lengths[i];
+              } else {
+                UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]]] = 0;
+              }
 
-            UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer =
-               UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[0] +
-               UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[1] +
-               UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[2] +
-               UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[3];
-            //UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer += UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer / 4;
-          }
+              UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer =
+                UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[0] +
+                UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[1] +
+                UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[2] +
+                UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[3];
+            }
 
-	  if ((rx_lengths[i] < SCH_PAYLOAD_SIZE_MAX) && (rx_lengths[i] > 0)) {	// MAX SIZE OF transport block
-	    mac_rlc_data_ind(enb_mod_idP, current_rnti, enb_mod_idP, frameP, ENB_FLAG_YES, MBMS_FLAG_NO, rx_lcids[i], (char *) payload_ptr, rx_lengths[i], 1, NULL);	//(unsigned int*)crc_status);
-
-	    UE_list->eNB_UE_stats[CC_idP][UE_id].num_pdu_rx[rx_lcids[i]] += 1;
-	    UE_list->eNB_UE_stats[CC_idP][UE_id].num_bytes_rx[rx_lcids[i]] += rx_lengths[i];
-	    //clear uplane_inactivity_timer
-	    UE_list->UE_sched_ctrl[UE_id].uplane_inactivity_timer = 0;
-	  } else {	/* rx_length[i] */
-	    UE_list->eNB_UE_stats[CC_idP][UE_id].num_errors_rx += 1;
-	    LOG_E(MAC,
-		  "[eNB %d] CC_id %d Frame %d : Max size of transport block reached LCID %d from UE %d ",
-		  enb_mod_idP, CC_idP, frameP, rx_lcids[i],
-		  UE_id);
-	  }
-	} else {	/*(UE_id != -1 */
-	  LOG_E(MAC,
-		"[eNB %d] CC_id %d Frame %d : received unsupported or unknown LCID %d from UE %d ",
-		enb_mod_idP, CC_idP, frameP, rx_lcids[i], UE_id);
-	}
-      }
+            if ((rx_lengths[i] < SCH_PAYLOAD_SIZE_MAX) && (rx_lengths[i] > 0)) {  // MAX SIZE OF transport block
+              mac_rlc_data_ind(enb_mod_idP, current_rnti, enb_mod_idP, frameP, ENB_FLAG_YES, MBMS_FLAG_NO, rx_lcids[i], (char *) payload_ptr, rx_lengths[i], 1, NULL);
+              UE_list->eNB_UE_stats[CC_idP][UE_id].num_pdu_rx[rx_lcids[i]] += 1;
+              UE_list->eNB_UE_stats[CC_idP][UE_id].num_bytes_rx[rx_lcids[i]] += rx_lengths[i];
 
-      break;
+              /* Clear uplane_inactivity_timer */
+              UE_list->UE_sched_ctrl[UE_id].uplane_inactivity_timer = 0;
+
+              /* Reset RRC inactivity timer after uplane activity */
+              ue_contextP = rrc_eNB_get_ue_context(RC.rrc[enb_mod_idP], current_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",
+                      enb_mod_idP,
+                      CC_idP,
+                      current_rnti);
+              }
+
+            } else {  /* rx_length[i] Max size */
+              UE_list->eNB_UE_stats[CC_idP][UE_id].num_errors_rx += 1;
+
+              LOG_E(MAC, "[eNB %d] CC_id %d Frame %d : Max size of transport block reached LCID %d from UE %d ",
+                    enb_mod_idP,
+                    CC_idP,
+                    frameP,
+                    rx_lcids[i],
+                    UE_id);
+            }
+          } else {  // end if (UE_id != -1)
+            LOG_E(MAC,"[eNB %d] CC_id %d Frame %d : received unsupported or unknown LCID %d from UE %d ",
+                  enb_mod_idP,
+                  CC_idP,
+                  frameP,
+                  rx_lcids[i],
+                  UE_id);
+          }
+        }
+        break;
     }
 
     payload_ptr += rx_lengths[i];
   }
 
-  // Program ACK for PHICH
-  LOG_D(MAC,
-	"Programming PHICH ACK for rnti %x harq_pid %d (first_rb %d)\n",
-	current_rnti, harq_pid, first_rb);
+  /* Program ACK for PHICH */
+  LOG_D(MAC, "Programming PHICH ACK for rnti %x harq_pid %d (first_rb %d)\n",
+    current_rnti,
+    harq_pid,
+    first_rb);
+
   nfapi_hi_dci0_request_t *hi_dci0_req;
-  uint8_t sf_ahead_dl = ul_subframe2_k_phich(&mac->common_channels[CC_idP] , subframeP);
-  hi_dci0_req = &mac->HI_DCI0_req[CC_idP][(subframeP+sf_ahead_dl)%10];
 
+  uint8_t sf_ahead_dl = ul_subframe2_k_phich(&mac->common_channels[CC_idP], subframeP);
+
+  hi_dci0_req = &mac->HI_DCI0_req[CC_idP][(subframeP+sf_ahead_dl)%10];
   nfapi_hi_dci0_request_body_t *hi_dci0_req_body = &hi_dci0_req->hi_dci0_request_body;
-  nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu =
-    &hi_dci0_req_body->hi_dci0_pdu_list[hi_dci0_req_body->number_of_dci + hi_dci0_req_body->number_of_hi];
+  nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu = &hi_dci0_req_body->hi_dci0_pdu_list[hi_dci0_req_body->number_of_dci +
+                                              hi_dci0_req_body->number_of_hi];
+
   memset((void *) hi_dci0_pdu, 0, sizeof(nfapi_hi_dci0_request_pdu_t));
+
   hi_dci0_pdu->pdu_type = NFAPI_HI_DCI0_HI_PDU_TYPE;
   hi_dci0_pdu->pdu_size = 2 + sizeof(nfapi_hi_dci0_hi_pdu);
   hi_dci0_pdu->hi_pdu.hi_pdu_rel8.tl.tag = NFAPI_HI_DCI0_REQUEST_HI_PDU_REL8_TAG;
@@ -772,13 +930,7 @@ rx_sdu(const module_id_t enb_mod_idP,
   if ((num_sdu == 0) && (num_ce == 0)) {
     if (UE_id != -1)
       UE_list->eNB_UE_stats[CC_idP][UE_id].total_num_errors_rx += 1;
-    /*
-      if (msg3_flagP != NULL) {
-      if( *msg3_flagP == 1 ) {
-      LOG_I(MAC,"[eNB %d] CC_id %d frame %d : false msg3 detection: signal phy to canceling RA and remove the UE\n", enb_mod_idP, CC_idP, frameP);
-      *msg3_flagP=0;
-      }
-      } */
+
   } else {
     if (UE_id != -1) {
       UE_list->eNB_UE_stats[CC_idP][UE_id].pdu_bytes_rx        = sdu_lenP;
@@ -791,7 +943,13 @@ rx_sdu(const module_id_t enb_mod_idP,
   stop_meas(&mac->rx_ulsch_sdu);
 }
 
-uint32_t bytes_to_bsr_index(int32_t nbytes)
+//-----------------------------------------------------------------------------
+/*
+ * Return the BSR table index corresponding to the number of bytes in input
+ */
+uint32_t
+bytes_to_bsr_index(int32_t nbytes)
+//-----------------------------------------------------------------------------
 {
   uint32_t i = 0;
 
@@ -806,32 +964,50 @@ uint32_t bytes_to_bsr_index(int32_t nbytes)
   return (i - 1);
 }
 
+//-----------------------------------------------------------------------------
+/*
+ * Add ue info in eNB_ulsch_info[module_idP][CC_id][UE_id] struct
+ */
 void
-add_ue_ulsch_info(module_id_t module_idP, int CC_id, int UE_id,
-		  sub_frame_t subframeP, UE_ULSCH_STATUS status)
+add_ue_ulsch_info(module_id_t module_idP,
+  int CC_id,
+  int UE_id,
+  sub_frame_t subframeP,
+  UE_ULSCH_STATUS status)
+//-----------------------------------------------------------------------------
 {
   eNB_ulsch_info[module_idP][CC_id][UE_id].rnti     = UE_RNTI(module_idP, UE_id);
   eNB_ulsch_info[module_idP][CC_id][UE_id].subframe = subframeP;
   eNB_ulsch_info[module_idP][CC_id][UE_id].status   = status;
-
   eNB_ulsch_info[module_idP][CC_id][UE_id].serving_num++;
 }
 
-unsigned char *parse_ulsch_header(unsigned char *mac_header,
-				  unsigned char *num_ce,
-				  unsigned char *num_sdu,
-				  unsigned char *rx_ces,
-				  unsigned char *rx_lcids,
-				  unsigned short *rx_lengths,
-				  unsigned short tb_length)
+//-----------------------------------------------------------------------------
+/*
+ * Parse MAC header from ULSCH
+ */
+unsigned char *
+parse_ulsch_header(unsigned char *mac_header,
+  unsigned char *num_ce,
+  unsigned char *num_sdu,
+  unsigned char *rx_ces,
+  unsigned char *rx_lcids,
+  unsigned short *rx_lengths,
+  unsigned short tb_length)
+//-----------------------------------------------------------------------------
 {
-  unsigned char not_done = 1, num_ces = 0, num_sdus =
-    0, lcid, num_sdu_cnt;
-  unsigned char *mac_header_ptr = mac_header;
+  unsigned char not_done = 1;
+  unsigned char num_ces = 0;
+  unsigned char num_sdus = 0;
+  unsigned char lcid = 0;
+  unsigned char num_sdu_cnt = 0;
+  unsigned char *mac_header_ptr = NULL;
   unsigned short length, ce_len = 0;
 
-  while (not_done == 1) {
+  /* Init */
+  mac_header_ptr = mac_header;
 
+  while (not_done == 1) {
     if (((SCH_SUBHEADER_FIXED *) mac_header_ptr)->E == 0) {
       not_done = 0;
     }
@@ -839,751 +1015,1323 @@ unsigned char *parse_ulsch_header(unsigned char *mac_header,
     lcid = ((SCH_SUBHEADER_FIXED *) mac_header_ptr)->LCID;
 
     if (lcid < EXTENDED_POWER_HEADROOM) {
-      if (not_done == 0) {	// last MAC SDU, length is implicit
-	mac_header_ptr++;
-	length = tb_length - (mac_header_ptr - mac_header) - ce_len;
-
-	for (num_sdu_cnt = 0; num_sdu_cnt < num_sdus;
-	     num_sdu_cnt++) {
-	  length -= rx_lengths[num_sdu_cnt];
-	}
+      if (not_done == 0) {  // last MAC SDU, length is implicit
+        mac_header_ptr++;
+        length = tb_length - (mac_header_ptr - mac_header) - ce_len;
+
+        for (num_sdu_cnt = 0; num_sdu_cnt < num_sdus; num_sdu_cnt++) {
+          length -= rx_lengths[num_sdu_cnt];
+        }
       } else {
-	if (((SCH_SUBHEADER_SHORT *) mac_header_ptr)->F == 0) {
-	  length = ((SCH_SUBHEADER_SHORT *) mac_header_ptr)->L;
-	  mac_header_ptr += 2;	//sizeof(SCH_SUBHEADER_SHORT);
-	} else {	// F = 1
-	  length =
-	    ((((SCH_SUBHEADER_LONG *) mac_header_ptr)->L_MSB &
-	      0x7f) << 8) | (((SCH_SUBHEADER_LONG *)
-			      mac_header_ptr)->L_LSB & 0xff);
-	  mac_header_ptr += 3;	//sizeof(SCH_SUBHEADER_LONG);
-	}
+        if (((SCH_SUBHEADER_SHORT *) mac_header_ptr)->F == 0) {
+          length = ((SCH_SUBHEADER_SHORT *) mac_header_ptr)->L;
+          mac_header_ptr += 2;  //sizeof(SCH_SUBHEADER_SHORT);
+        } else {  // F = 1
+          length = ((((SCH_SUBHEADER_LONG *) mac_header_ptr)->L_MSB & 0x7f) << 8) |
+           (((SCH_SUBHEADER_LONG *) mac_header_ptr)->L_LSB & 0xff);
+          mac_header_ptr += 3;  //sizeof(SCH_SUBHEADER_LONG);
+        }
       }
 
-      LOG_D(MAC,
-	    "[eNB] sdu %d lcid %d tb_length %d length %d (offset now %ld)\n",
-	    num_sdus, lcid, tb_length, length,
-	    mac_header_ptr - mac_header);
+      LOG_D(MAC, "[eNB] sdu %d lcid %d tb_length %d length %d (offset now %ld)\n",
+        num_sdus,
+        lcid,
+        tb_length,
+        length,
+        mac_header_ptr - mac_header);
+
       rx_lcids[num_sdus] = lcid;
       rx_lengths[num_sdus] = length;
       num_sdus++;
-    } else {		// This is a control element subheader POWER_HEADROOM, BSR and CRNTI
+
+    } else {  // This is a control element subheader POWER_HEADROOM, BSR and CRNTI
       if (lcid == SHORT_PADDING) {
-	mac_header_ptr++;
+        mac_header_ptr++;
       } else {
-	rx_ces[num_ces] = lcid;
-	num_ces++;
-	mac_header_ptr++;
-
-	if (lcid == LONG_BSR) {
-	  ce_len += 3;
-	} else if (lcid == CRNTI) {
-	  ce_len += 2;
-	} else if ((lcid == POWER_HEADROOM)
-		   || (lcid == TRUNCATED_BSR)
-		   || (lcid == SHORT_BSR)) {
-	  ce_len++;
-	} else {
-	  LOG_E(MAC, "unknown CE %d \n", lcid);
-	  //AssertFatal(1 == 0, "unknown CE");
+        rx_ces[num_ces] = lcid;
+        num_ces++;
+        mac_header_ptr++;
+
+        if (lcid == LONG_BSR) {
+          ce_len += 3;
+        } else if (lcid == CRNTI) {
+          ce_len += 2;
+        } else if ((lcid == POWER_HEADROOM) || (lcid == TRUNCATED_BSR) || (lcid == SHORT_BSR)) {
+          ce_len++;
+        } else {
+          LOG_E(MAC, "unknown CE %d \n", lcid);
           return NULL;
-	}
+        }
       }
     }
   }
 
   *num_ce = num_ces;
   *num_sdu = num_sdus;
-
   return (mac_header_ptr);
 }
 
+//-----------------------------------------------------------------------------
 /* This function is called by PHY layer when it schedules some
  * uplink for a random access message 3.
  * The MAC scheduler has to skip the RBs used by this message 3
  * (done below in schedule_ulsch).
+ * This function seems to be unused, the Msg3_subframe is set somewhere else...
+ * In NFAPI??
  */
 void
 set_msg3_subframe(module_id_t mod_id,
-		  int CC_id,
-		  int frame,
-		  int subframe, int rnti, int Msg3_frame,
-		  int Msg3_subframe)
+  int CC_id,
+  int frame, // Not used, remove?
+  int subframe, // Not used, remove?
+  int rnti,
+  int Msg3_frame, // Not used, remove?
+  int Msg3_subframe)
+//-----------------------------------------------------------------------------
 {
-  eNB_MAC_INST *mac = RC.mac[mod_id];
-  int i;
-  for (i = 0; i < NB_RA_PROC_MAX; i++) {
-    if (mac->common_channels[CC_id].ra[i].state != IDLE &&
-	mac->common_channels[CC_id].ra[i].rnti == rnti) {
-      mac->common_channels[CC_id].ra[i].Msg3_subframe =
-	Msg3_subframe;
-      break;
-    }
+  int RA_id = 0;
+
+  /* Init */
+  RA_id = find_RA_id(mod_id, CC_id, rnti); // state == WAITMSG3 instead of state != IDLE (?)
+
+  if (RA_id != -1) {
+    RC.mac[mod_id]->common_channels[CC_id].ra[RA_id].Msg3_subframe = Msg3_subframe;
+  } else {
+    LOG_E(MAC, "[MAC] Unknown RAPROC associated to RNTI %x\n", rnti);
   }
+
+  return;
 }
 
+//-----------------------------------------------------------------------------
+/*
+ * Main function called for uplink scheduling (DCI0).
+ */
 void
-schedule_ulsch(module_id_t module_idP, frame_t frameP,
-	       sub_frame_t subframeP)
+schedule_ulsch(module_id_t module_idP,
+  frame_t frameP,
+  sub_frame_t subframeP)
+//-----------------------------------------------------------------------------
 {
-  uint16_t first_rb[NFAPI_CC_MAX], i;
-  int CC_id;
-  eNB_MAC_INST *mac = RC.mac[module_idP];
-  slice_info_t *sli = &RC.mac[module_idP]->slice_info;
-  COMMON_channels_t *cc;
-
-  start_meas(&mac->schedule_ulsch);
-
-  int sched_frame=frameP;
-  int sched_subframe = (subframeP + 4) % 10;
-
-  cc = &mac->common_channels[0];
-  int tdd_sfa;
-  // for TDD: check subframes where we have to act and return if nothing should be done now
-  if (cc->tdd_Config) {
-    tdd_sfa = cc->tdd_Config->subframeAssignment;
+  uint16_t first_rb[NFAPI_CC_MAX];
+  eNB_MAC_INST *mac = NULL;
+  slice_info_t *sli = NULL;
+  COMMON_channels_t *cc = NULL;
+
+  /* Init */
+  mac = RC.mac[module_idP];
+  sli = &(mac->slice_info);
+  memset(first_rb, 0, NFAPI_CC_MAX * sizeof(uint16_t));
+
+  start_meas(&(mac->schedule_ulsch));
+
+  /* Second setup step */
+  int sched_subframe = 0;
+  int sched_frame = 0;
+
+  /* Second init step */
+  sched_subframe = (subframeP + 4) % 10;
+  sched_frame = frameP;
+  cc = mac->common_channels;
+
+  /* For TDD: check subframes where we have to act and return if nothing should be done now */
+  if (cc->tdd_Config) {  // Done only for CC_id = 0, assume tdd_Config for all CC_id
+    int tdd_sfa = cc->tdd_Config->subframeAssignment;
+
     switch (subframeP) {
-    case 0:
-      if ((tdd_sfa == 0) || (tdd_sfa == 3))
-	sched_subframe = 4;
-      else if (tdd_sfa == 6)
-	sched_subframe = 7;
-      else
-	return;
-      break;
-    case 1:
-      if ((tdd_sfa == 0) || (tdd_sfa == 1))
-	sched_subframe = 7;
-      else if (tdd_sfa == 6)
-	sched_subframe = 8;
-      else
+      case 0:
+        if ((tdd_sfa == 0) || (tdd_sfa == 3))
+          sched_subframe = 4;
+        else if (tdd_sfa == 6)
+          sched_subframe = 7;
+        else
+          return;
+
+        break;
+
+      case 1:
+        if ((tdd_sfa == 0) || (tdd_sfa == 1))
+          sched_subframe = 7;
+        else if (tdd_sfa == 6)
+          sched_subframe = 8;
+        else
+          return;
+
+        break;
+
+      case 2:  // Don't schedule UL in subframe 2 for TDD
         return;
-      break;
-    default:
-      return;
 
-    case 2:		// Don't schedule UL in subframe 2 for TDD
-      return;
-    case 3:
-      if (tdd_sfa == 2)
-	sched_subframe = 7;
-      else
-	return;
-      break;
-    case 4:
-      if (tdd_sfa == 1)
-	sched_subframe = 8;
-      else
-	return;
-      break;
-    case 5:
-      if (tdd_sfa == 0)
-	sched_subframe = 9;
-      else if (tdd_sfa == 6)
-	sched_subframe = 2;
-      else
-	return;
-      break;
-    case 6:
-      if (tdd_sfa == 0 || tdd_sfa == 1)
-	sched_subframe = 2;
-      else if (tdd_sfa == 6)
-	sched_subframe = 3;
-      else
-	return;
-      break;
-    case 7:
-      return;
-    case 8:
-      if ((tdd_sfa >= 2) && (tdd_sfa <= 5))
-        sched_subframe = 2;
-      else
+      case 3:
+        if (tdd_sfa == 2)
+          sched_subframe = 7;
+        else
+          return;
+
+        break;
+
+      case 4:
+        if (tdd_sfa == 1)
+          sched_subframe = 8;
+        else
+          return;
+
+        break;
+
+      case 5:
+        if (tdd_sfa == 0)
+          sched_subframe = 9;
+        else if (tdd_sfa == 6)
+          sched_subframe = 2;
+        else
+          return;
+
+        break;
+
+      case 6:
+        if (tdd_sfa == 0 || tdd_sfa == 1)
+          sched_subframe = 2;
+        else if (tdd_sfa == 6)
+          sched_subframe = 3;
+        else
+          return;
+
+        break;
+
+      case 7:
         return;
-      break;
-    case 9:
-      if ((tdd_sfa == 1) || (tdd_sfa == 3) || (tdd_sfa == 4))
-        sched_subframe = 3;
-      else if (tdd_sfa == 6)
-        sched_subframe = 4;
-      else
+
+      case 8:
+        if ((tdd_sfa >= 2) && (tdd_sfa <= 5))
+          sched_subframe = 2;
+        else
+          return;
+
+        break;
+
+      case 9:
+        if ((tdd_sfa == 1) || (tdd_sfa == 3) || (tdd_sfa == 4))
+          sched_subframe = 3;
+        else if (tdd_sfa == 6)
+          sched_subframe = 4;
+        else
+          return;
+
+        break;
+
+      default:
         return;
-      break;
     }
   }
 
-  if (sched_subframe < subframeP) sched_frame++;
+  if (sched_subframe < subframeP) {
+    sched_frame++;
+  }
 
-  for (CC_id = 0; CC_id < RC.nb_mac_CC[module_idP]; CC_id++) {
-    //leave out first RB for PUCCH
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  int emtc_active[5];
+  memset(emtc_active, 0, 5 * sizeof(int));
+  schedule_ulsch_rnti_emtc(module_idP, frameP, subframeP, sched_subframe, emtc_active);
+#endif
+
+  /* Note: RC.nb_mac_CC[module_idP] should be lower than or equal to NFAPI_CC_MAX */
+  for (int CC_id = 0; CC_id < RC.nb_mac_CC[module_idP]; CC_id++, cc++) {
+    first_rb[CC_id] = 1;  // leave out first RB for PUCCH
+
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+    first_rb[CC_id] = (emtc_active[CC_id] == 1) ? 7 : 1;
+#else
     first_rb[CC_id] = 1;
+#endif
+
+    RA_t *ra_ptr = cc->ra;
+
+    /* From Louis-Adrien to François:
+     * The comment bloc below is to configure with a command line.
+     * I took it from the equivalent part in the fairRR scheduler (around line 2578 in eNB_scheduler_fairRR.c).
+     * As said in the meeting, it seems to work only for small TBS.
+     * The cause of false RA still present with this fix is to investigate.
+     *
+     * Note: in the get_prach_prb_offset() function below, the last argument is frameP in eNB_scheduler_fairRR.c
+     * I think it should be sched_frame instead. This parameter has only impacts in case TDD and preamble format 4.
+     * To confirm.
+     */
+    /*
+    int start_rb = 0;
+    int nb_rb = 6;
+    LTE_DL_FRAME_PARMS *frame_parms = &(RC.eNB[module_idP][CC_id]->frame_parms);
+
+    if (is_prach_subframe(frame_parms, sched_frame, sched_subframe) == 1) {
+      start_rb = get_prach_prb_offset(frame_parms,
+                                      frame_parms->prach_config_common.prach_ConfigInfo.prach_ConfigIndex,
+                                      frame_parms->prach_config_common.prach_ConfigInfo.prach_FreqOffset,
+                                      0, // tdd_mapindex
+                                      sched_frame); // Nf
+
+      first_rb[CC_id] = start_rb + nb_rb;
+    }
+    */
 
-    // UE data info;
-    // check which UE has data to transmit
-    // function to decide the scheduling
-    // e.g. scheduling_rslt = Greedy(granted_UEs, nb_RB)
-
-    // default function for default scheduling
-    //
-
-    // output of scheduling, the UE numbers in RBs, where it is in the code???
-    // check if RA (Msg3) is active in this subframeP, if so skip the PRBs used for Msg3
-    // Msg3 is using 1 PRB so we need to increase first_rb accordingly
-    // not sure about the break (can there be more than 1 active RA procedure?)
-
-    for (i = 0; i < NB_RA_PROC_MAX; i++) {
-      if ((cc->ra[i].state == WAITMSG3) &&
-	  (cc->ra[i].Msg3_subframe == sched_subframe)) {
-	first_rb[CC_id]++;
-	//    cc->ray[i].Msg3_subframe = -1;
-	break;
+    /*
+     * Check if RA (Msg3) is active in this subframeP, if so skip the PRB used for Msg3
+     * Msg3 is using 1 PRB so we need to increase first_rb accordingly
+     * Not sure about the break (can there be more than 1 active RA procedure per CC_id and per subframe?)
+     */
+    for (int ra_index = 0; ra_index < NB_RA_PROC_MAX; ra_index++, ra_ptr++) {
+      if ((ra_ptr->state == WAITMSG3) && (ra_ptr->Msg3_subframe == sched_subframe)) {
+        if (first_rb[CC_id] < ra_ptr->msg3_first_rb + ra_ptr->msg3_nb_rb) {
+          first_rb[CC_id] = ra_ptr->msg3_first_rb + ra_ptr->msg3_nb_rb;
+        }
+        /* Louis-Adrien: I couldn't find an interdiction of multiple Msg3 scheduling
+         * on the same time resources. Also the performance improvement of breaking is low,
+         * since we will loop until the end, most of the time.
+         * I'm letting the break as a reminder, in case of misunderstanding the spec.
+         */
+        // break;
       }
     }
   }
 
-  for (i = 0; i < sli->n_ul; i++) {
-    // Run each enabled slice-specific schedulers one by one
+  /* Run each enabled slice-specific schedulers one by one */
+  for (int i = 0; i < sli->n_ul; i++) {
+    /* By default the scheduler is schedule_ulsch_rnti (see below) */
     sli->ul[i].sched_cb(module_idP, i, frameP, subframeP, sched_subframe, first_rb);
   }
 
   stop_meas(&mac->schedule_ulsch);
 }
 
+//-----------------------------------------------------------------------------
+/*
+ * Default scheduler for ULSCH (DCI0)
+ */
 void
 schedule_ulsch_rnti(module_id_t module_idP,
-        int slice_idx,
-		    frame_t frameP,
-		    sub_frame_t subframeP,
-		    unsigned char sched_subframeP, uint16_t * first_rb)
+  int slice_idx,
+  frame_t frameP,
+  sub_frame_t subframeP,
+  unsigned char sched_subframeP,
+  uint16_t *first_rb)
+//-----------------------------------------------------------------------------
 {
-  int UE_id;
-  uint8_t aggregation = 2;
   rnti_t rnti = -1;
-  uint8_t round = 0;
+  uint8_t aggregation = 2;
+  uint8_t round_index = 0;
   uint8_t harq_pid = 0;
   uint8_t status = 0;
   uint8_t rb_table_index = -1;
-  uint32_t cqi_req, cshift, ndi, tpc;
-  int32_t normalized_rx_power, target_rx_power;
+  uint8_t dlsch_flag = 0;
+  uint16_t ul_req_index = 0;
+  uint32_t cqi_req = 0;
+  uint32_t cshift = 0;
+  uint32_t ndi = 0;
+  uint32_t tpc = 0;
+  int32_t normalized_rx_power = 0;
+  int32_t target_rx_power = 0;
+  int32_t framex10psubframe = 0;
   static int32_t tpc_accumulated = 0;
-  int n;
+  int sched_frame = 0;
   int CC_id = 0;
-  int drop_ue = 0;
-  int N_RB_UL;
-  eNB_MAC_INST *mac = RC.mac[module_idP];
-  COMMON_channels_t *cc = mac->common_channels;
-  UE_list_t *UE_list = &mac->UE_list;
-  slice_info_t *sli = &RC.mac[module_idP]->slice_info;
-  UE_TEMPLATE *UE_template;
-  UE_sched_ctrl *UE_sched_ctrl;
-  int sched_frame = frameP;
-  int rvidx_tab[4] = { 0, 2, 3, 1 };
-  uint16_t          ul_req_index;
-  uint8_t           dlsch_flag;
+  eNB_MAC_INST *mac = NULL;
+  COMMON_channels_t *cc = NULL;
+  UE_list_t *UE_list = NULL;
+  slice_info_t *sli = NULL;
+  UE_TEMPLATE *UE_template_ptr = NULL;
+  UE_sched_ctrl *UE_sched_ctrl_ptr = NULL;
+  int rvidx_tab[4] = {0, 2, 3, 1};
   int first_rb_slice[NFAPI_CC_MAX];
+  int n_rb_ul_tab[NFAPI_CC_MAX];
+
+  /* Init */
+  mac = RC.mac[module_idP];
+  cc = mac->common_channels;
+  UE_list = &(mac->UE_list);
+  sli = &(mac->slice_info);
+  memset(first_rb_slice, 0, NFAPI_CC_MAX * sizeof(int));
+  memset(n_rb_ul_tab, 0, NFAPI_CC_MAX * sizeof(int));
+  sched_frame = frameP;
+
+  if (sched_subframeP < subframeP) {
+    sched_frame++;
+  }
 
-  if (sched_subframeP < subframeP)
-      sched_frame++;
-
-  nfapi_hi_dci0_request_t        *hi_dci0_req = &mac->HI_DCI0_req[CC_id][subframeP];
-  nfapi_hi_dci0_request_body_t   *hi_dci0_req_body = &hi_dci0_req->hi_dci0_request_body;
+  /* NFAPI struct init */
+  nfapi_hi_dci0_request_t        *hi_dci0_req      = &(mac->HI_DCI0_req[CC_id][subframeP]);
+  nfapi_hi_dci0_request_body_t   *hi_dci0_req_body = &(hi_dci0_req->hi_dci0_request_body);
   nfapi_hi_dci0_request_pdu_t    *hi_dci0_pdu;
-
-  nfapi_ul_config_request_t *ul_req_tmp            = &mac->UL_req_tmp[CC_id][sched_subframeP];
-  nfapi_ul_config_request_body_t *ul_req_tmp_body  = &ul_req_tmp->ul_config_request_body;
+  nfapi_ul_config_request_t      *ul_req_tmp       = &(mac->UL_req_tmp[CC_id][sched_subframeP]);
+  nfapi_ul_config_request_body_t *ul_req_tmp_body  = &(ul_req_tmp->ul_config_request_body);
   nfapi_ul_config_ulsch_harq_information *ulsch_harq_information;
 
-	for (CC_id = 0; CC_id < RC.nb_mac_CC[module_idP]; ++CC_id) {
-    N_RB_UL = to_prb(cc[CC_id].ul_Bandwidth);
-		UE_list->first_rb_offset[CC_id][slice_idx] = cmin(N_RB_UL, sli->ul[slice_idx].first_rb);
-	}
+  hi_dci0_req->sfn_sf = (frameP << 4) + subframeP;
+
+  /* Note: RC.nb_mac_CC[module_idP] should be lower than or equal to NFAPI_CC_MAX */
+  for (CC_id = 0; CC_id < RC.nb_mac_CC[module_idP]; CC_id++) {
+    n_rb_ul_tab[CC_id] = to_prb(cc[CC_id].ul_Bandwidth); // return total number of PRB
+    UE_list->first_rb_offset[CC_id][slice_idx] = cmin(n_rb_ul_tab[CC_id], sli->ul[slice_idx].first_rb);
+  }
 
-  //LOG_D(MAC, "entering ulsch preprocesor\n");
+  /* ULSCH preprocessor: set UE_template->
+   * pre_allocated_nb_rb_ul[slice_idx]
+   * pre_assigned_mcs_ul
+   * pre_allocated_rb_table_index_ul
+   */
   ulsch_scheduler_pre_processor(module_idP, slice_idx, frameP, subframeP, sched_subframeP, first_rb);
 
-	for (CC_id = 0; CC_id < RC.nb_mac_CC[module_idP]; ++CC_id) {
+  for (CC_id = 0; CC_id < RC.nb_mac_CC[module_idP]; CC_id++) {
     first_rb_slice[CC_id] = first_rb[CC_id] + UE_list->first_rb_offset[CC_id][slice_idx];
   }
-  //LOG_D(MAC, "exiting ulsch preprocesor\n");
 
-  hi_dci0_req->sfn_sf = (frameP << 4) + subframeP;
-
-  // loop over all active UEs
-  for (UE_id = UE_list->head_ul; UE_id >= 0;
-       UE_id = UE_list->next_ul[UE_id]) {
+  // loop over all active UEs until end of function
+  for (int UE_id = UE_list->head_ul; UE_id >= 0; UE_id = UE_list->next_ul[UE_id]) {
+    if (!ue_ul_slice_membership(module_idP, UE_id, slice_idx)) {
+      continue;
+    }
 
-    if (!ue_ul_slice_membership(module_idP, UE_id, slice_idx))
-        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) {
+      LOG_D(MAC, "[eNB %d] frame %d, subframe %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_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);
-        continue;
+      continue;
     }
 
     rnti = UE_RNTI(module_idP, 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;
-    }
+      LOG_W(MAC, "[eNB %d] frame %d, subframe %d, UE %d: no RNTI \n",
+        module_idP,
+        frameP,
+        subframeP,
+        UE_id);
 
-    drop_ue = 0;
-    /* let's drop the UE if get_eNB_UE_stats returns NULL when calling it with any of the UE's active UL CCs */
-    /* TODO: refine?
-
-       for (n=0; n<UE_list->numactiveULCCs[UE_id]; n++) {
-       CC_id = UE_list->ordered_ULCCids[n][UE_id];
-
-       if (mac_xface->get_eNB_UE_stats(module_idP,CC_id,rnti) == NULL) {
-       LOG_W(MAC,"[eNB %d] frame %d subframe %d, UE %d/%x CC %d: no PHY context\n", module_idP,frameP,subframeP,UE_id,rnti,CC_id);
-       drop_ue = 1;
-       break;
-       }
-       } */
-    if (drop_ue == 1) {
-      /* we can't come here, ulsch_scheduler_pre_processor won't put in the list a UE with no PHY context */
-      abort();
-      /* TODO: this is a hack. Sometimes the UE has no PHY context but
-       * is still present in the MAC with 'ul_failure_timer' = 0 and
-       * 'ul_out_of_sync' = 0. It seems wrong and the UE stays there forever. Let's
-       * start an UL out of sync procedure in this case.
-       * The root cause of this problem has to be found and corrected.
-       * In the meantime, this hack...
-       */
-      if (UE_list->UE_sched_ctrl[UE_id].ul_failure_timer == 0 &&
-	  UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync == 0) {
-	LOG_W(MAC,
-	      "[eNB %d] frame %d subframe %d, UE %d/%x CC %d: UE in weird state, let's put it 'out of sync'\n",
-	      module_idP, frameP, subframeP, UE_id, rnti, CC_id);
-	// inform RRC of failure and clear timer
-	mac_eNB_rrc_ul_failure(module_idP, CC_id, frameP,
-			       subframeP, rnti);
-	UE_list->UE_sched_ctrl[UE_id].ul_failure_timer = 0;
-	UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync = 1;
-      }
       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
+
+    // loop over all active UL CC_ids for this UE until end of function
+    for (int 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);
 
-      /*
-	aggregation=get_aggregation(get_bw_index(module_idP,CC_id),
-	eNB_UE_stats->dl_cqi,
-	format0);
-      */
-
-      if (CCE_allocation_infeasible
-	  (module_idP, CC_id, 1, subframeP, aggregation, rnti)) {
-	LOG_W(MAC,
-	      "[eNB %d] frame %d subframe %d, UE %d/%x CC %d: not enough nCCE\n",
-	      module_idP, frameP, subframeP, UE_id, rnti, CC_id);
-	continue;	// break;
+      /* Be sure that there are some free RBs */
+      if (first_rb_slice[CC_id] >= n_rb_ul_tab[CC_id] - 1) {
+        LOG_W(MAC, "[eNB %d] frame %d, subframe %d, UE %d/%x CC %d: dropping, not enough RBs\n",
+          module_idP,
+          frameP,
+          subframeP,
+          UE_id,
+          rnti,
+          CC_id);
+
+        continue;
       }
 
-      /* be sure that there are some free RBs */
-      if (first_rb_slice[CC_id] >= N_RB_UL - 1) {
-	LOG_W(MAC,
-	      "[eNB %d] frame %d subframe %d, UE %d/%x CC %d: dropping, not enough RBs\n",
-	      module_idP, frameP, subframeP, UE_id, rnti, CC_id);
-	continue;
+      /* Should format_flag be 2 in CCE_allocation_infeasible??? */
+      /* This test seems to be way too long, can we provide an optimization? */
+      if (CCE_allocation_infeasible(module_idP, CC_id, 1, subframeP, aggregation, rnti)) {
+        LOG_W(MAC, "[eNB %d] frame %d, subframe %d, UE %d/%x CC %d: not enough CCE\n",
+          module_idP,
+          frameP,
+          subframeP,
+          UE_id,
+          rnti,
+          CC_id);
+
+        continue;
       }
-      //      if (eNB_UE_stats->mode == PUSCH) { // ue has a ulsch channel
 
-      UE_template = &UE_list->UE_template[CC_id][UE_id];
-      UE_sched_ctrl = &UE_list->UE_sched_ctrl[UE_id];
+      /* UE is active and can be scheduled, setting up struct */
+      UE_template_ptr = &(UE_list->UE_template[CC_id][UE_id]);
+      UE_sched_ctrl_ptr = &(UE_list->UE_sched_ctrl[UE_id]);
       harq_pid = subframe2harqpid(&cc[CC_id], sched_frame, sched_subframeP);
-      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);
-      LOG_D(MAC,
-	    "[eNB %d] frame %d subframe %d (sched_frame %d, sched_subframe %d), Checking PUSCH %d for UE %d/%x CC %d : aggregation level %d, N_RB_UL %d\n",
-	    module_idP, frameP, subframeP, sched_frame, sched_subframeP, harq_pid, UE_id, rnti,
-	    CC_id, aggregation, 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_is_to_be_scheduled(module_idP, CC_id, UE_id) > 0 || round > 0)	// || ((frameP%10)==0))
-	// 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_D(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
-	  UE_template->ul_SR = 0;
-	  status = mac_eNB_get_rrc_status(module_idP, rnti);
-	  cqi_req = 0;
+      round_index = UE_sched_ctrl_ptr->round_UL[CC_id][harq_pid];
+
+      AssertFatal(round_index < 8, "round %d > 7 for UE %d/%x\n",
+        round_index,
+        UE_id,
+        rnti);
+
+      LOG_D(MAC, "[eNB %d] frame %d subframe %d (sched_frame %d, sched_subframe %d), Checking PUSCH %d for UE %d/%x CC %d : aggregation level %d, N_RB_UL %d\n",
+        module_idP,
+        frameP,
+        subframeP,
+        sched_frame,
+        sched_subframeP,
+        harq_pid,
+        UE_id,
+        rnti,
+        CC_id,
+        aggregation,
+        n_rb_ul_tab[CC_id]);
+
+      /* Seems unused, only for debug */
+      RC.eNB[module_idP][CC_id]->pusch_stats_BO[UE_id][(frameP * 10) + subframeP] = UE_template_ptr->estimated_ul_buffer;
+      VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_BO, UE_template_ptr->estimated_ul_buffer);
 
-	  if (status >= RRC_CONNECTED && UE_sched_ctrl->cqi_req_timer > 30) { 
-	    if (UE_sched_ctrl->cqi_received == 0) {
-	      if (nfapi_mode) {
-	    	  cqi_req = 0;
-	      } else {
-	    	  cqi_req = 1;
-		   // To be safe , do not ask CQI in special Subframes:36.213/7.2.3 CQI definition
-			if (cc[CC_id].tdd_Config) {
-			  switch (cc[CC_id].tdd_Config->subframeAssignment) {
-				  case 1:
-					if( subframeP == 1 || subframeP == 6 ) cqi_req=0;
-					break;
-				  case 3:
-					if( subframeP == 1 ) cqi_req=0;
-					break;
-				  default:
-					LOG_E(MAC," TDD config not supported\n");
-					break;
-			  }
-			}
-			if(cqi_req == 1) UE_sched_ctrl->cqi_req_flag |= 1 << sched_subframeP;
-	      }
-	    }
-	    else if (UE_sched_ctrl->cqi_received == 1) {
-	      UE_sched_ctrl->cqi_req_flag = 0;
-	      UE_sched_ctrl->cqi_received = 0;
-	      UE_sched_ctrl->cqi_req_timer = 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
-	  //is not in dBm, unit from nfapi, converting to dBm: ToDo: Noise power hard coded to 30
-	  normalized_rx_power = (5*UE_sched_ctrl->pusch_snr[CC_id]-640)/10+30;
-	  target_rx_power= mac->puSch10xSnr/10 + 30;
-	  //printf("\n mac->puSch10xSnr = %d,  normalized_rx_power = %d, target_rx_power = %d \n",mac->puSch10xSnr,normalized_rx_power,target_rx_power);
-	  // 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
-		tpc_accumulated--;
-	      } else if (normalized_rx_power < (target_rx_power - 4)) {
-		tpc = 2;	//+1
-		tpc_accumulated++;
-	      } 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,
-		  tpc_accumulated, normalized_rx_power,
-		  target_rx_power);
-	  }
-	  // 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_template->mcs_UL[harq_pid] = cmin(UE_template->pre_assigned_mcs_ul, sli->ul[slice_idx].maxmcs);
-		UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs1= UE_template->mcs_UL[harq_pid];
-		//cmin (UE_template->pre_assigned_mcs_ul, openair_daq_vars.target_ue_ul_mcs); // adjust, based on user-defined MCS
-	    if (UE_template->pre_allocated_rb_table_index_ul >= 0) {
-	      rb_table_index = UE_template->pre_allocated_rb_table_index_ul;
-	    } else {
-	      UE_template->mcs_UL[harq_pid] = 10;	//cmin (10, openair_daq_vars.target_ue_ul_mcs);
-	      rb_table_index = 5;	// for PHR
-	    }
-
-	    UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs2 = UE_template->mcs_UL[harq_pid];
-	    //            buffer_occupancy = UE_template->ul_total_buffer;
-
-
-	    while (((rb_table[rb_table_index] > (N_RB_UL - first_rb_slice[CC_id]))
-                    || (rb_table[rb_table_index] > 45))
-                    && (rb_table_index > 0)) {
-	      rb_table_index--;
-	    }
-
-	    UE_template->TBS_UL[harq_pid] = get_TBS_UL(UE_template->mcs_UL[harq_pid],
-						       rb_table[rb_table_index]);
-	    UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used_rx += rb_table[rb_table_index];
-	    UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_TBS = UE_template->TBS_UL[harq_pid];
-            UE_list->eNB_UE_stats[CC_id][UE_id].total_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(first_rb_slice[CC_id]),
-	      T_INT(rb_table[rb_table_index]),
-	      T_INT(UE_template->TBS_UL[harq_pid]), T_INT(ndi));
-
-	    if (mac_eNB_get_rrc_status(module_idP, rnti) < RRC_CONNECTED)
-	      LOG_D(MAC,
-		    "[eNB %d][PUSCH %d/%x] CC_id %d Frame %d subframeP %d Scheduled UE %d (mcs %d, first rb %d, nb_rb %d, rb_table_index %d, TBS %d, harq_pid %d)\n",
-		    module_idP, harq_pid, rnti, CC_id, frameP,
-		    subframeP, UE_id,
-		    UE_template->mcs_UL[harq_pid],
-                first_rb_slice[CC_id], rb_table[rb_table_index],
-		    rb_table_index,
-		    UE_template->TBS_UL[harq_pid], harq_pid);
-
-	    // bad indices : 20 (40 PRB), 21 (45 PRB), 22 (48 PRB)
-	    //store for possible retransmission
-	    UE_template->nb_rb_ul[harq_pid] = rb_table[rb_table_index];
-	    UE_template->first_rb_ul[harq_pid] = first_rb_slice[CC_id];
-
-	    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 scheduled UL bytes by TBS, wait for UL sdus to do final update
-	    LOG_D(MAC,
-		  "[eNB %d] CC_id %d UE %d/%x : adjusting scheduled_ul_bytes, old %d, TBS %d\n",
-		  module_idP, CC_id, UE_id, rnti,
-		  UE_template->scheduled_ul_bytes,
-		  UE_template->TBS_UL[harq_pid]);
+      /*
+       * 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
+       */
+      /* Shouldn't this test be done earlier?? */
+      if (UE_is_to_be_scheduled(module_idP, CC_id, UE_id) > 0 || round_index > 0) {
+        LOG_D(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_index,
+          UE_template_ptr->ul_SR,
+          UE_sched_ctrl_ptr->ul_inactivity_timer,
+          UE_sched_ctrl_ptr->ul_failure_timer,
+          UE_sched_ctrl_ptr->cqi_req_timer);
+
+        // reset the scheduling request
+        UE_template_ptr->ul_SR = 0;
+        status = mac_eNB_get_rrc_status(module_idP, rnti);
+        cqi_req = 0;
+
+        /* Handle the aperiodic CQI report */
+        /* These aperiodic reports behave as periodic ones... */
+        if (status >= RRC_CONNECTED && UE_sched_ctrl_ptr->cqi_req_timer > 30) {
+          if (UE_sched_ctrl_ptr->cqi_received == 0) {
+            if (nfapi_mode) {
+              cqi_req = 0;
+            } else {
+              cqi_req = 1;
+
+              /* TDD: to be safe, do not ask CQI in special Subframes:36.213/7.2.3 CQI definition */
+              if (cc[CC_id].tdd_Config) {
+                switch (cc[CC_id].tdd_Config->subframeAssignment) {
+                  case 1:
+                    if(subframeP == 1 || subframeP == 6) {
+                      cqi_req=0;
+                    }
+                    break;
+
+                  case 3:
+                    if(subframeP == 1) {
+                      cqi_req=0;
+                    }
+                    break;
+
+                  default:
+                    LOG_E(MAC," TDD config not supported\n");
+                    break;
+                }
+              }
 
-            UE_template->scheduled_ul_bytes += UE_template->TBS_UL[harq_pid];
+              if(cqi_req == 1) {
+                UE_sched_ctrl_ptr->cqi_req_flag |= 1 << sched_subframeP;
+              }
+            }
+          } else {
+            UE_sched_ctrl_ptr->cqi_req_flag = 0;
+            UE_sched_ctrl_ptr->cqi_received = 0;
+            UE_sched_ctrl_ptr->cqi_req_timer = 0;
+          }
+        }
 
-            LOG_D(MAC, "scheduled_ul_bytes, new %d\n", UE_template->scheduled_ul_bytes);
+        /* 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)
+         * Is not in dBm, unit from nfapi, converting to dBm
+         * ToDo: Noise power hard coded to 30
+         */
+        normalized_rx_power = ((5 * UE_sched_ctrl_ptr->pusch_snr[CC_id] - 640) / 10) + 30;
+        target_rx_power = (mac->puSch10xSnr / 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
+         */
+        framex10psubframe = (UE_template_ptr->pusch_tpc_tx_frame * 10) + UE_template_ptr->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_ptr->pusch_tpc_tx_frame = frameP;
+          UE_template_ptr->pusch_tpc_tx_subframe = subframeP;
+
+          if (normalized_rx_power > (target_rx_power + 4)) {
+            tpc = 0; // -1
+            tpc_accumulated--;
+          } else if (normalized_rx_power < (target_rx_power - 4)) {
+            tpc = 2; // +1
+            tpc_accumulated++;
+          } else {
+            tpc = 1; // 0
+          }
+        } else {
+          tpc = 1; // 0
+        }
 
-	    // 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;
-
-	    hi_dci0_pdu = &hi_dci0_req_body->hi_dci0_pdu_list[hi_dci0_req_body->number_of_dci + hi_dci0_req_body->number_of_hi];
-	    memset((void *) hi_dci0_pdu, 0,sizeof(nfapi_hi_dci0_request_pdu_t));
-	    hi_dci0_pdu->pdu_type = NFAPI_HI_DCI0_DCI_PDU_TYPE;
-	    hi_dci0_pdu->pdu_size = 2 + sizeof(nfapi_hi_dci0_dci_pdu);
-	    hi_dci0_pdu->dci_pdu.dci_pdu_rel8.tl.tag = NFAPI_HI_DCI0_REQUEST_DCI_PDU_REL8_TAG;
-	    hi_dci0_pdu->dci_pdu.dci_pdu_rel8.dci_format = NFAPI_UL_DCI_FORMAT_0;
-	    hi_dci0_pdu->dci_pdu.dci_pdu_rel8.aggregation_level = aggregation;
-	    hi_dci0_pdu->dci_pdu.dci_pdu_rel8.rnti = rnti;
-	    hi_dci0_pdu->dci_pdu.dci_pdu_rel8.transmission_power = 6000;
-	    hi_dci0_pdu->dci_pdu.dci_pdu_rel8.resource_block_start = first_rb_slice[CC_id];
-	    hi_dci0_pdu->dci_pdu.dci_pdu_rel8.number_of_resource_block = rb_table[rb_table_index];
-	    hi_dci0_pdu->dci_pdu.dci_pdu_rel8.mcs_1 = UE_template->mcs_UL[harq_pid];
-	    hi_dci0_pdu->dci_pdu.dci_pdu_rel8.cyclic_shift_2_for_drms = cshift;
-	    hi_dci0_pdu->dci_pdu.dci_pdu_rel8.frequency_hopping_enabled_flag = 0;
-	    hi_dci0_pdu->dci_pdu.dci_pdu_rel8.new_data_indication_1 = ndi;
-	    hi_dci0_pdu->dci_pdu.dci_pdu_rel8.tpc = tpc;
-	    hi_dci0_pdu->dci_pdu.dci_pdu_rel8.cqi_csi_request = cqi_req;
-	    hi_dci0_pdu->dci_pdu.dci_pdu_rel8.dl_assignment_index = UE_template->DAI_ul[sched_subframeP];
-            hi_dci0_pdu->dci_pdu.dci_pdu_rel8.harq_pid = harq_pid;
-
-	    hi_dci0_req_body->number_of_dci++;
-	    hi_dci0_req_body->sfnsf = sfnsf_add_subframe(sched_frame, sched_subframeP, 0); //(frameP, subframeP, 4);
-	    hi_dci0_req_body->tl.tag = NFAPI_HI_DCI0_REQUEST_BODY_TAG;
-
-	    hi_dci0_req->sfn_sf = frameP<<4|subframeP; // sfnsf_add_subframe(sched_frame, sched_subframeP, 0); // sunday!
-	    hi_dci0_req->header.message_id = NFAPI_HI_DCI0_REQUEST;
-
-
-	    LOG_D(MAC,
-		  "[PUSCH %d] Frame %d, Subframe %d: Adding UL CONFIG.Request for UE %d/%x, ulsch_frame %d, ulsch_subframe %d\n",
-		  harq_pid, frameP, subframeP, UE_id, rnti,
-		  sched_frame, sched_subframeP);
-
-            ul_req_index = 0;
-            dlsch_flag = 0;
-            for(ul_req_index = 0;ul_req_index < ul_req_tmp_body->number_of_pdus;ul_req_index++){
-              if(ul_req_tmp_body->ul_config_pdu_list[ul_req_index].pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE &&
-                 ul_req_tmp_body->ul_config_pdu_list[ul_req_index].uci_harq_pdu.ue_information.ue_information_rel8.rnti == rnti){
-                dlsch_flag = 1;
-                LOG_D(MAC,"Frame %d, Subframe %d:rnti %x ul_req_index %d Switched UCI HARQ to ULSCH HARQ(first)\n",frameP,subframeP,rnti,ul_req_index);
-                break;
-              }
+        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,
+            tpc_accumulated,
+            normalized_rx_power,
+            target_rx_power);
+        }
+
+        /* New transmission */
+        if (round_index == 0) {
+          ndi = 1 - UE_template_ptr->oldNDI_UL[harq_pid]; // NDI: new data indicator
+          UE_template_ptr->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_template_ptr->mcs_UL[harq_pid] = cmin(UE_template_ptr->pre_assigned_mcs_ul, sli->ul[slice_idx].maxmcs);
+          UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs1= UE_template_ptr->mcs_UL[harq_pid];
+
+          if (UE_template_ptr->pre_allocated_rb_table_index_ul >= 0) {
+            rb_table_index = UE_template_ptr->pre_allocated_rb_table_index_ul;
+          } else {
+            UE_template_ptr->mcs_UL[harq_pid] = 10;
+            rb_table_index = 5; // for PHR
+          }
+
+          UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs2 = UE_template_ptr->mcs_UL[harq_pid];
+
+          while (((rb_table[rb_table_index] > (n_rb_ul_tab[CC_id] - first_rb_slice[CC_id])) ||
+                  (rb_table[rb_table_index] > 45)) && (rb_table_index > 0)) {
+            rb_table_index--;
+          }
+
+          UE_template_ptr->TBS_UL[harq_pid] = get_TBS_UL(UE_template_ptr->mcs_UL[harq_pid], rb_table[rb_table_index]);
+          UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used_rx += rb_table[rb_table_index];
+          UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_TBS = UE_template_ptr->TBS_UL[harq_pid];
+          UE_list->eNB_UE_stats[CC_id][UE_id].total_ulsch_TBS += UE_template_ptr->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_ptr->mcs_UL[harq_pid]),
+            T_INT(first_rb_slice[CC_id]),
+            T_INT(rb_table[rb_table_index]),
+            T_INT(UE_template_ptr->TBS_UL[harq_pid]),
+            T_INT(ndi));
+
+          /* Store information for possible retransmission */
+          UE_template_ptr->nb_rb_ul[harq_pid] = rb_table[rb_table_index];
+          UE_template_ptr->first_rb_ul[harq_pid] = first_rb_slice[CC_id];
+          UE_sched_ctrl_ptr->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_ptr->ul_scheduled);
+          }
+
+          /* Adjust scheduled UL bytes by TBS, wait for UL sdus to do final update */
+          LOG_D(MAC, "[eNB %d] CC_id %d UE %d/%x : adjusting scheduled_ul_bytes, old %d, TBS %d\n",
+            module_idP,
+            CC_id,
+            UE_id,
+            rnti,
+            UE_template_ptr->scheduled_ul_bytes,
+            UE_template_ptr->TBS_UL[harq_pid]);
+
+          UE_template_ptr->scheduled_ul_bytes += UE_template_ptr->TBS_UL[harq_pid];
+
+          LOG_D(MAC, "scheduled_ul_bytes, new %d\n",
+            UE_template_ptr->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_ptr->cshift[harq_pid] = cshift;
+
+          /* Setting DCI0 NFAPI struct */
+          hi_dci0_pdu = &hi_dci0_req_body->hi_dci0_pdu_list[hi_dci0_req_body->number_of_dci + hi_dci0_req_body->number_of_hi];
+          memset((void *) hi_dci0_pdu, 0,sizeof(nfapi_hi_dci0_request_pdu_t));
+          hi_dci0_pdu->pdu_type = NFAPI_HI_DCI0_DCI_PDU_TYPE;
+          hi_dci0_pdu->pdu_size = 2 + sizeof(nfapi_hi_dci0_dci_pdu);
+          hi_dci0_pdu->dci_pdu.dci_pdu_rel8.tl.tag = NFAPI_HI_DCI0_REQUEST_DCI_PDU_REL8_TAG;
+          hi_dci0_pdu->dci_pdu.dci_pdu_rel8.dci_format = NFAPI_UL_DCI_FORMAT_0;
+          hi_dci0_pdu->dci_pdu.dci_pdu_rel8.aggregation_level = aggregation;
+          hi_dci0_pdu->dci_pdu.dci_pdu_rel8.rnti = rnti;
+          hi_dci0_pdu->dci_pdu.dci_pdu_rel8.transmission_power = 6000;
+          hi_dci0_pdu->dci_pdu.dci_pdu_rel8.resource_block_start = first_rb_slice[CC_id];
+          hi_dci0_pdu->dci_pdu.dci_pdu_rel8.number_of_resource_block = rb_table[rb_table_index];
+          hi_dci0_pdu->dci_pdu.dci_pdu_rel8.mcs_1 = UE_template_ptr->mcs_UL[harq_pid];
+          hi_dci0_pdu->dci_pdu.dci_pdu_rel8.cyclic_shift_2_for_drms = cshift;
+          hi_dci0_pdu->dci_pdu.dci_pdu_rel8.frequency_hopping_enabled_flag = 0;
+          hi_dci0_pdu->dci_pdu.dci_pdu_rel8.new_data_indication_1 = ndi;
+          hi_dci0_pdu->dci_pdu.dci_pdu_rel8.tpc = tpc;
+          hi_dci0_pdu->dci_pdu.dci_pdu_rel8.cqi_csi_request = cqi_req;
+          hi_dci0_pdu->dci_pdu.dci_pdu_rel8.dl_assignment_index = UE_template_ptr->DAI_ul[sched_subframeP];
+          hi_dci0_pdu->dci_pdu.dci_pdu_rel8.harq_pid = harq_pid;
+          hi_dci0_req_body->number_of_dci++;
+          hi_dci0_req_body->sfnsf = sfnsf_add_subframe(sched_frame, sched_subframeP, 0);
+          hi_dci0_req_body->tl.tag = NFAPI_HI_DCI0_REQUEST_BODY_TAG;
+          hi_dci0_req->sfn_sf = frameP << 4 | subframeP;
+          hi_dci0_req->header.message_id = NFAPI_HI_DCI0_REQUEST;
+
+          LOG_D(MAC, "[PUSCH %d] Frame %d, Subframe %d: Adding UL CONFIG.Request for UE %d/%x, ulsch_frame %d, ulsch_subframe %d\n",
+            harq_pid,
+            frameP,
+            subframeP,
+            UE_id,
+            rnti,
+            sched_frame,
+            sched_subframeP);
+
+          ul_req_index = 0;
+          dlsch_flag = 0;
+
+          for(ul_req_index = 0; ul_req_index < ul_req_tmp_body->number_of_pdus; ul_req_index++) {
+            if(ul_req_tmp_body->ul_config_pdu_list[ul_req_index].pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE &&
+               ul_req_tmp_body->ul_config_pdu_list[ul_req_index].uci_harq_pdu.ue_information.ue_information_rel8.rnti == rnti) {
+
+              dlsch_flag = 1;
+
+              LOG_D(MAC, "Frame %d, Subframe %d:rnti %x ul_req_index %d Switched UCI HARQ to ULSCH HARQ(first)\n",
+                frameP,
+                subframeP,
+                rnti,
+                ul_req_index);
+
+              break;
             }
+          }
+
+          /* Add UL_config PDUs */
+          fill_nfapi_ulsch_config_request_rel8(&ul_req_tmp_body->ul_config_pdu_list[ul_req_index],
+            cqi_req,
+            cc,
+            UE_template_ptr->physicalConfigDedicated,
+            get_tmode(module_idP, CC_id, UE_id),
+            mac->ul_handle,
+            rnti,
+            first_rb_slice[CC_id],     // resource_block_start
+            rb_table[rb_table_index],  // number_of_resource_blocks
+            UE_template_ptr->mcs_UL[harq_pid],
+            cshift,    // cyclic_shift_2_for_drms
+            0,         // frequency_hopping_enabled_flag
+            0,         // frequency_hopping_bits
+            ndi,       // new_data_indication
+            0,         // redundancy_version
+            harq_pid,  // harq_process_number
+            0,         // ul_tx_mode
+            0,         // current_tx_nb
+            0,         // n_srs
+            get_TBS_UL(UE_template_ptr->mcs_UL[harq_pid], rb_table[rb_table_index]));
+
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+          /* This is a BL/CE UE allocation */
+          if (UE_template_ptr->rach_resource_type > 0) {
+            fill_nfapi_ulsch_config_request_emtc(&ul_req_tmp_body->ul_config_pdu_list[ul_req_index],
+              UE_template_ptr->rach_resource_type > 2 ? 2 : 1,
+              1,  // total_number_of_repetitions
+              1,  // repetition_number
+              (frameP * 10) + subframeP);
+          }
 
-	    // Add UL_config PDUs
-	    fill_nfapi_ulsch_config_request_rel8(&ul_req_tmp_body->ul_config_pdu_list[ul_req_index], cqi_req, cc, UE_template->physicalConfigDedicated, get_tmode(module_idP, CC_id, UE_id), mac->ul_handle, rnti, first_rb_slice[CC_id], // resource_block_start
-						 rb_table[rb_table_index],	// 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
-						 ndi,	// new_data_indication
-						 0,	// redundancy_version
-						 harq_pid,	// harq_process_number
-						 0,	// ul_tx_mode
-						 0,	// current_tx_nb
-						 0,	// n_srs
-						 get_TBS_UL
-						 (UE_template->
-						  mcs_UL[harq_pid],
-						  rb_table
-						  [rb_table_index]));
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-	    if (UE_template->rach_resource_type > 0) {	// This is a BL/CE UE allocation
-	      fill_nfapi_ulsch_config_request_emtc(&ul_req_tmp_body->ul_config_pdu_list[ul_req_index], UE_template->rach_resource_type > 2 ? 2 : 1, 1,	//total_number_of_repetitions
-						   1,	//repetition_number
-						   (frameP *
-						    10) +
-						   subframeP);
-	    }
 #endif
-            if(dlsch_flag == 1){
-              if(cqi_req == 1){
-                 ul_req_tmp_body->ul_config_pdu_list[ul_req_index].pdu_type = NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE;
-                 ulsch_harq_information = &ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.harq_information;
-                 ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag=NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG;
-                 ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = 0;    // last symbol not punctured
-                 ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks = rb_table[rb_table_index];
-
-              }else{
-                ul_req_tmp_body->ul_config_pdu_list[ul_req_index].pdu_type = NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE;
-                ulsch_harq_information = &ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.harq_information;
-                ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG;
-                ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = 0;  // last symbol not punctured
-                ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks = rb_table[rb_table_index];
-              }
-              fill_nfapi_ulsch_harq_information(module_idP, CC_id,rnti, ulsch_harq_information,subframeP);
-            }else{
-              ul_req_tmp_body->number_of_pdus++;
+
+          if (dlsch_flag == 1) {
+            if (cqi_req == 1) {
+              ul_req_tmp_body->ul_config_pdu_list[ul_req_index].pdu_type = NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE;
+              ulsch_harq_information = &ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.harq_information;
+              ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG;
+              ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = 0;  // last symbol not punctured
+              ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks = rb_table[rb_table_index];
+            } else {
+              ul_req_tmp_body->ul_config_pdu_list[ul_req_index].pdu_type = NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE;
+              ulsch_harq_information = &ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.harq_information;
+              ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG;
+              ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = 0;  // last symbol not punctured
+              ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks = rb_table[rb_table_index];
             }
 
-	    ul_req_tmp->header.message_id = NFAPI_UL_CONFIG_REQUEST;
-	    ul_req_tmp_body->tl.tag = NFAPI_UL_CONFIG_REQUEST_BODY_TAG;
-	    mac->ul_handle++;
-
-	    uint16_t ul_sched_frame = sched_frame;
-	    uint16_t ul_sched_subframeP = sched_subframeP;
-
-	    //add_subframe(&ul_sched_frame, &ul_sched_subframeP, 2);
-	    ul_req_tmp->sfn_sf = ul_sched_frame<<4|ul_sched_subframeP;
-
-	    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);
-	    LOG_D(MAC,"[PUSCH %d] SFN/SF:%04d%d UL_CFG:SFN/SF:%04d%d CQI:%d for UE %d/%x\n", harq_pid,frameP,subframeP,ul_sched_frame,ul_sched_subframeP,cqi_req,UE_id,rnti);
-
-	    // increment first rb for next UE allocation
-        first_rb_slice[CC_id] += rb_table[rb_table_index];
-	  } 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(first_rb_slice[CC_id]),
-	      T_INT(rb_table[rb_table_index]), T_INT(round));
-
-	    // Add UL_config PDUs
-	    LOG_D(MAC,
-		  "[PUSCH %d] Frame %d, Subframe %d: Adding UL CONFIG.Request for UE %d/%x, ulsch_frame %d, ulsch_subframe %d\n",
-		  harq_pid, frameP, subframeP, UE_id, rnti,
-		  sched_frame, sched_subframeP);
-            ul_req_index = 0;
-            dlsch_flag = 0;
-            for(ul_req_index = 0;ul_req_index < ul_req_tmp_body->number_of_pdus;ul_req_index++){
-              if(ul_req_tmp_body->ul_config_pdu_list[ul_req_index].pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE &&
-                 ul_req_tmp_body->ul_config_pdu_list[ul_req_index].uci_harq_pdu.ue_information.ue_information_rel8.rnti == rnti){
-                dlsch_flag = 1;
-                LOG_D(MAC,"Frame %d, Subframe %d:rnti %x ul_req_index %d Switched UCI HARQ to ULSCH HARQ(first)\n",frameP,subframeP,rnti,ul_req_index);
-                break;
-              }
+            fill_nfapi_ulsch_harq_information(module_idP, CC_id,rnti, ulsch_harq_information,subframeP);
+
+          } else {
+            ul_req_tmp_body->number_of_pdus++;
+          }
+
+          ul_req_tmp->header.message_id = NFAPI_UL_CONFIG_REQUEST;
+          ul_req_tmp_body->tl.tag = NFAPI_UL_CONFIG_REQUEST_BODY_TAG;
+          mac->ul_handle++;
+          ul_req_tmp->sfn_sf = sched_frame << 4 | sched_subframeP;
+
+          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);
+
+          LOG_D(MAC, "[PUSCH %d] SFN/SF:%04d%d UL_CFG:SFN/SF:%04d%d CQI:%d for UE %d/%x\n",
+            harq_pid,
+            frameP,
+            subframeP,
+            sched_frame,
+            sched_subframeP,
+            cqi_req,
+            UE_id,
+            rnti);
+
+          /* Increment first rb for next UE allocation */
+          first_rb_slice[CC_id] += rb_table[rb_table_index];
+
+        } else { // round_index > 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_ptr->mcs_UL[harq_pid]),
+            T_INT(first_rb_slice[CC_id]),
+            T_INT(rb_table[rb_table_index]),
+            T_INT(round_index));
+
+          /* Add UL_config PDUs */
+          LOG_D(MAC, "[PUSCH %d] Frame %d, Subframe %d: Adding UL CONFIG.Request for UE %d/%x, ulsch_frame %d, ulsch_subframe %d\n",
+            harq_pid,
+            frameP,
+            subframeP,
+            UE_id,
+            rnti,
+            sched_frame,
+            sched_subframeP);
+
+          ul_req_index = 0;
+          dlsch_flag = 0;
+
+          for(ul_req_index = 0; ul_req_index < ul_req_tmp_body->number_of_pdus; ul_req_index++) {
+            if(ul_req_tmp_body->ul_config_pdu_list[ul_req_index].pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE &&
+               ul_req_tmp_body->ul_config_pdu_list[ul_req_index].uci_harq_pdu.ue_information.ue_information_rel8.rnti == rnti) {
+
+              dlsch_flag = 1;
+
+              LOG_D(MAC, "Frame %d, Subframe %d:rnti %x ul_req_index %d Switched UCI HARQ to ULSCH HARQ(first)\n",
+                frameP,
+                subframeP,
+                rnti,
+                ul_req_index);
+
+              break;
             }
-	    fill_nfapi_ulsch_config_request_rel8(&ul_req_tmp_body->ul_config_pdu_list[ul_req_index], cqi_req, cc, UE_template->physicalConfigDedicated, get_tmode(module_idP, CC_id, UE_id), mac->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]);
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-	    if (UE_template->rach_resource_type > 0) {	// This is a BL/CE UE allocation
-	      fill_nfapi_ulsch_config_request_emtc(&ul_req_tmp_body->ul_config_pdu_list[ul_req_index], UE_template->rach_resource_type > 2 ? 2 : 1, 1,	//total_number_of_repetitions
-						   1,	//repetition_number
-						   (frameP *
-						    10) +
-						   subframeP);
-	    }
+          }
+
+          fill_nfapi_ulsch_config_request_rel8(&ul_req_tmp_body->ul_config_pdu_list[ul_req_index],
+            cqi_req,
+            cc,
+            UE_template_ptr->physicalConfigDedicated,
+            get_tmode(module_idP, CC_id, UE_id),
+            mac->ul_handle,
+            rnti,
+            UE_template_ptr->first_rb_ul[harq_pid], // resource_block_start
+            UE_template_ptr->nb_rb_ul[harq_pid],    // number_of_resource_blocks
+            UE_template_ptr->mcs_UL[harq_pid],
+            cshift, // cyclic_shift_2_for_drms
+            0,      // frequency_hopping_enabled_flag
+            0,      // frequency_hopping_bits
+            UE_template_ptr->oldNDI_UL[harq_pid], // new_data_indication
+            rvidx_tab[round_index & 3],           // redundancy_version
+            harq_pid,  // harq_process_number
+            0, // ul_tx_mode
+            0, // current_tx_nb
+            0, // n_srs
+            UE_template_ptr->TBS_UL[harq_pid]);
+
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+
+          /* This is a BL/CE UE allocation */
+          if (UE_template_ptr->rach_resource_type > 0) {
+            fill_nfapi_ulsch_config_request_emtc(&ul_req_tmp_body->ul_config_pdu_list[ul_req_index],
+              UE_template_ptr->rach_resource_type > 2 ? 2 : 1,
+              1, // total_number_of_repetitions
+              1, // repetition_number
+              (frameP * 10) + subframeP);
+          }
+
 #endif
-            if(dlsch_flag == 1){
-              if(cqi_req == 1){
-                ul_req_tmp_body->ul_config_pdu_list[ul_req_index].pdu_type = NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE;
-                ulsch_harq_information = &ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.harq_information;
-                ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag=NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG;
-                ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = 0;    // last symbol not punctured
-                ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks = UE_template->nb_rb_ul[harq_pid];
-
-              }else{
-                ul_req_tmp_body->ul_config_pdu_list[ul_req_index].pdu_type = NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE;
-                ulsch_harq_information = &ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.harq_information;
-                ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG;
-                ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = 0;  // last symbol not punctured
-                ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks = UE_template->nb_rb_ul[harq_pid];
-              }
-              fill_nfapi_ulsch_harq_information(module_idP, CC_id,rnti, ulsch_harq_information,subframeP);
-            }else{
-              ul_req_tmp_body->number_of_pdus++;
+
+          if(dlsch_flag == 1) {
+            if(cqi_req == 1) {
+              ul_req_tmp_body->ul_config_pdu_list[ul_req_index].pdu_type = NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE;
+              ulsch_harq_information = &ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.harq_information;
+              ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag=
+                NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG;
+              ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = 0;    // last symbol not punctured
+              ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks =
+                UE_template_ptr->nb_rb_ul[harq_pid];
+            } else {
+              ul_req_tmp_body->ul_config_pdu_list[ul_req_index].pdu_type = NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE;
+              ulsch_harq_information = &ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.harq_information;
+              ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag =
+                NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG;
+              ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = 0;  // last symbol not punctured
+              ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks =
+                UE_template_ptr->nb_rb_ul[harq_pid];
             }
 
-	    mac->ul_handle++;
+            fill_nfapi_ulsch_harq_information(module_idP, CC_id,rnti, ulsch_harq_information, subframeP);
 
-	    ul_req_tmp_body->tl.tag = NFAPI_UL_CONFIG_REQUEST_BODY_TAG;
+          } else {
+            ul_req_tmp_body->number_of_pdus++;
+          }
 
-	    ul_req_tmp->sfn_sf = sched_frame<<4|sched_subframeP;
-	    ul_req_tmp->header.message_id = NFAPI_UL_CONFIG_REQUEST;
+          mac->ul_handle++;
+          ul_req_tmp_body->tl.tag = NFAPI_UL_CONFIG_REQUEST_BODY_TAG;
+          ul_req_tmp->sfn_sf = sched_frame<<4|sched_subframeP;
+          ul_req_tmp->header.message_id = NFAPI_UL_CONFIG_REQUEST;
+
+          LOG_D(MAC, "[PUSCH %d] Frame %d, Subframe %d: Adding UL CONFIG.Request for UE %d/%x, ulsch_frame %d, ulsch_subframe %d cqi_req %d\n",
+            harq_pid,
+            frameP,
+            subframeP,
+            UE_id,
+            rnti,
+            sched_frame,
+            sched_subframeP,
+            cqi_req);
+        }  // end of round > 0
+      }  // UE_is_to_be_scheduled
+    }  // loop over all active CC_ids
+  }  // loop over UE_ids
+}
 
-	    LOG_D(MAC,"[PUSCH %d] Frame %d, Subframe %d: Adding UL CONFIG.Request for UE %d/%x, ulsch_frame %d, ulsch_subframe %d cqi_req %d\n",
-		  harq_pid,frameP,subframeP,UE_id,rnti,sched_frame,sched_subframeP,cqi_req);
-	  }		/*
-			  else if (round > 0) { //we schedule a retransmission
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+void schedule_ulsch_rnti_emtc(module_id_t   module_idP,
+			     frame_t       frameP,
+			     sub_frame_t   subframeP,
+			     unsigned char sched_subframeP,
+			     int          *emtc_active)
+{
+  int               UE_id;
+  rnti_t            rnti           = -1;
+  uint8_t           round          = 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;
+  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;
+
+  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;
 
-			  ndi = UE_template->oldNDI_UL[harq_pid];
+  nfapi_ul_config_request_body_t *ul_req_tmp       = &eNB->UL_req_tmp[CC_id][sched_subframeP].ul_config_request_body;
 
-			  if ((round&3)==0) {
-			  mcs = openair_daq_vars.target_ue_ul_mcs;
-			  } else {
-			  mcs = rvidx_tab[round&3] + 28; //not correct for round==4!
+  // loop over all active UEs
+  if ((frameP&1) == 1) return;
 
-			  }
+  for (UE_id=UE_list->head_ul; UE_id>=0; UE_id=UE_list->next_ul[UE_id]) {
 
-			  LOG_I(MAC,"[eNB %d][PUSCH %d/%x] CC_id %d Frame %d subframeP %d Scheduled UE retransmission (mcs %d, first rb %d, nb_rb %d, harq_pid %d, round %d)\n",
-			  module_idP,UE_id,rnti,CC_id,frameP,subframeP,mcs,
-			  first_rb[CC_id],UE_template->nb_rb_ul[harq_pid],
-			  harq_pid, round);
+    if (UE_list->UE_template[UE_PCCID(module_idP,UE_id)][UE_id].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);
+      continue;
+    }
+
+    rnti = UE_RNTI(module_idP,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);
+
+
+      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);
+      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);
+
+      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;
+
+          }
+          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;
+
+          // 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==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;
 
-			  rballoc = mac_xface->computeRIV(frame_parms->N_RB_UL,
-			  first_rb[CC_id],
-			  UE_template->nb_rb_ul[harq_pid]);
-			  first_rb[CC_id]+=UE_template->nb_rb_ul[harq_pid];  // increment for next UE allocation
 
-			  UE_list->eNB_UE_stats[CC_id][UE_id].num_retransmission_rx+=1;
-			  UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used_retx_rx=UE_template->nb_rb_ul[harq_pid];
-			  UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used_rx+=UE_template->nb_rb_ul[harq_pid];
-			  UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs1=mcs;
-			  UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs2=mcs;
-			  }
-			*/
+            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);
 
-	}			// UE_is_to_be_scheduled
-    }			// loop over UE_id
-  }				// loop of CC_id
+            // 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);
+
+
+            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 > 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++;
+
+          }
+        } // UE_is_to_be_scheduled
+    } // ULCCs
+  } // loop over UE_id
 }
+#endif
diff --git a/openair2/LAYER2/MAC/l1_helpers.c b/openair2/LAYER2/MAC/l1_helpers.c
index bd640a6c88e539a6f8bcb8cca08b35037d1f446c..9b26413cb1b468a3960ffb1402d39820743b9641 100644
--- a/openair2/LAYER2/MAC/l1_helpers.c
+++ b/openair2/LAYER2/MAC/l1_helpers.c
@@ -36,7 +36,7 @@
 
 int8_t get_Po_NOMINAL_PUSCH(module_id_t module_idP, uint8_t CC_id)
 {
-    RACH_ConfigCommon_t *rach_ConfigCommon = NULL;
+    LTE_RACH_ConfigCommon_t *rach_ConfigCommon = NULL;
 
     AssertFatal(CC_id == 0,
 		"Transmission on secondary CCs is not supported yet\n");
diff --git a/openair2/LAYER2/MAC/lte_transport_init.c b/openair2/LAYER2/MAC/lte_transport_init.c
deleted file mode 100644
index e1f21f21e44935e7bf071b9377e6e69548201506..0000000000000000000000000000000000000000
--- a/openair2/LAYER2/MAC/lte_transport_init.c
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * 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
- */
-
-#define UL_RB_ALLOC mac_xface->computeRIV(mac_xface->frame_parms->N_RB_UL,0,24)
-#define BCCH_RB_ALLOC mac_xface->computeRIV(mac_xface->frame_parms->N_RB_UL,0,4)
-#define RA_RB_ALLOC mac_xface->computeRIV(mac_xface->frame_parms->N_RB_UL,0,4)
-#define DLSCH_RB_ALLOC 0x1fff
-#include "extern.h"
-
-
-void init_transport_channels(unsigned char transmission_mode)
-{
-
-    // init DCI structures for testing
-
-    UL_alloc_pdu.type = 0;
-    UL_alloc_pdu.hopping = 0;
-    UL_alloc_pdu.rballoc = UL_RB_ALLOC;
-    UL_alloc_pdu.mcs = 2;
-    UL_alloc_pdu.ndi = 1;
-    UL_alloc_pdu.TPC = 0;
-    UL_alloc_pdu.cqi_req = 1;
-
-    /*
-       BCCH_alloc_pdu.type               = 1;
-       BCCH_alloc_pdu.vrb_type           = 0;
-       BCCH_alloc_pdu.rballoc            = BCCH_RB_ALLOC;
-       BCCH_alloc_pdu.ndi      = 1;
-       BCCH_alloc_pdu.rv       = 1;
-       BCCH_alloc_pdu.mcs      = 1;
-       BCCH_alloc_pdu.harq_pid = 0;
-       BCCH_alloc_pdu.TPC      = 1;      // set to 3 PRB
-
-       // for FDD mode
-       BCCH_alloc_pdu_fdd.type               = 1;
-       BCCH_alloc_pdu_fdd.vrb_type           = 0;
-       BCCH_alloc_pdu_fdd.rballoc            = BCCH_RB_ALLOC;
-       BCCH_alloc_pdu_fdd.ndi      = 1;
-       BCCH_alloc_pdu_fdd.rv       = 1;
-       BCCH_alloc_pdu_fdd.mcs      = 1;
-       BCCH_alloc_pdu_fdd.harq_pid = 0;
-       BCCH_alloc_pdu_fdd.TPC      = 1;      // set to 3 PRB
-     */
-
-    DLSCH_alloc_pdu1A.type = 1;
-    DLSCH_alloc_pdu1A.vrb_type = 0;
-    DLSCH_alloc_pdu1A.rballoc = BCCH_RB_ALLOC;
-    DLSCH_alloc_pdu1A.ndi = 1;
-    DLSCH_alloc_pdu1A.rv = 1;
-    DLSCH_alloc_pdu1A.mcs = 2;
-    DLSCH_alloc_pdu1A.harq_pid = 0;
-    DLSCH_alloc_pdu1A.TPC = 1;	// set to 3 PRB
-
-    DLSCH_alloc_pdu1A_fdd.type = 1;
-    DLSCH_alloc_pdu1A_fdd.vrb_type = 0;
-    DLSCH_alloc_pdu1A_fdd.rballoc = BCCH_RB_ALLOC;
-    DLSCH_alloc_pdu1A_fdd.ndi = 1;
-    DLSCH_alloc_pdu1A_fdd.rv = 1;
-    DLSCH_alloc_pdu1A_fdd.mcs = 2;
-    DLSCH_alloc_pdu1A_fdd.harq_pid = 0;
-    DLSCH_alloc_pdu1A_fdd.TPC = 1;	// set to 3 PRB
-
-    RA_alloc_pdu.type = 1;
-    RA_alloc_pdu.vrb_type = 0;
-    RA_alloc_pdu.rballoc = RA_RB_ALLOC;
-    RA_alloc_pdu.ndi = 1;
-    RA_alloc_pdu.rv = 0;
-    RA_alloc_pdu.mcs = 0;
-    RA_alloc_pdu.harq_pid = 0;
-    RA_alloc_pdu.TPC = 1;
-
-    RA_alloc_pdu_fdd.type = 1;
-    RA_alloc_pdu_fdd.vrb_type = 0;
-    RA_alloc_pdu_fdd.rballoc = RA_RB_ALLOC;
-    RA_alloc_pdu_fdd.ndi = 1;
-    RA_alloc_pdu_fdd.rv = 1;
-    RA_alloc_pdu_fdd.mcs = 1;
-    RA_alloc_pdu_fdd.harq_pid = 0;
-    RA_alloc_pdu_fdd.TPC = 1;
-
-
-    DLSCH_alloc_pdu1.rballoc = 0xf;
-    DLSCH_alloc_pdu1.TPC = 0;
-    DLSCH_alloc_pdu1.dai = 0;
-    DLSCH_alloc_pdu1.harq_pid = 0;
-    DLSCH_alloc_pdu1.tb_swap = 0;
-    DLSCH_alloc_pdu1.mcs1 = 4;
-    DLSCH_alloc_pdu1.ndi1 = 1;
-    DLSCH_alloc_pdu1.rv1 = 0;
-
-    // Forget second codeword
-    if (transmission_mode == 6) {
-	DLSCH_alloc_pdu1.tpmi = 5;	// PUSCH_PRECODING0
-    } else {
-	DLSCH_alloc_pdu1.tpmi = 0;
-    }
-
-    DLSCH_alloc_pdu2.rah = 0;
-    DLSCH_alloc_pdu2.rballoc = DLSCH_RB_ALLOC;
-    DLSCH_alloc_pdu2.TPC = 0;
-    DLSCH_alloc_pdu2.dai = 0;
-    DLSCH_alloc_pdu2.harq_pid = 0;
-    DLSCH_alloc_pdu2.tb_swap = 0;
-    DLSCH_alloc_pdu2.mcs1 = 4;
-    DLSCH_alloc_pdu2.ndi1 = 1;
-    DLSCH_alloc_pdu2.rv1 = 0;
-
-    // Forget second codeword
-    if (transmission_mode == 6) {
-	DLSCH_alloc_pdu2.tpmi = 5;	// PUSCH_PRECODING0
-    } else {
-	DLSCH_alloc_pdu2.tpmi = 0;
-    }
-}
diff --git a/openair2/LAYER2/MAC/mac.h b/openair2/LAYER2/MAC/mac.h
index f9c1d86de47961e35f839e36bfe550ee9296f788..fc457c2ee75ca8378e86ee9d995ca69197871401 100644
--- a/openair2/LAYER2/MAC/mac.h
+++ b/openair2/LAYER2/MAC/mac.h
@@ -1,4 +1,4 @@
-/*
+ /*
  * 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.
@@ -44,29 +44,29 @@
 #include <string.h>
 
 #include "COMMON/platform_constants.h"
-#include "BCCH-BCH-Message.h"
-#include "RadioResourceConfigCommon.h"
-#include "RadioResourceConfigCommonSIB.h"
-#include "RadioResourceConfigDedicated.h"
-#include "MeasGapConfig.h"
-#include "SchedulingInfoList.h"
-#include "TDD-Config.h"
-#include "RACH-ConfigCommon.h"
-#include "MeasObjectToAddModList.h"
-#include "MobilityControlInfo.h"
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-#include "MBSFN-AreaInfoList-r9.h"
-#include "MBSFN-SubframeConfigList.h"
-#include "PMCH-InfoList-r9.h"
+#include "LTE_BCCH-BCH-Message.h"
+#include "LTE_RadioResourceConfigCommon.h"
+#include "LTE_RadioResourceConfigCommonSIB.h"
+#include "LTE_RadioResourceConfigDedicated.h"
+#include "LTE_MeasGapConfig.h"
+#include "LTE_SchedulingInfoList.h"
+#include "LTE_TDD-Config.h"
+#include "LTE_RACH-ConfigCommon.h"
+#include "LTE_MeasObjectToAddModList.h"
+#include "LTE_MobilityControlInfo.h"
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+#include "LTE_MBSFN-AreaInfoList-r9.h"
+#include "LTE_MBSFN-SubframeConfigList.h"
+#include "LTE_PMCH-InfoList-r9.h"
 #endif
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-#include "SCellToAddMod-r10.h"
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#include "LTE_SCellToAddMod-r10.h"
 #endif
-#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
-#include "SystemInformationBlockType1-v1310-IEs.h"
-#include "SystemInformationBlockType18-r12.h"
+#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
+#include "LTE_SystemInformationBlockType1-v1310-IEs.h"
+#include "LTE_SystemInformationBlockType18-r12.h"
 #endif
-#include "RadioResourceConfigCommonSIB.h"
+#include "LTE_RadioResourceConfigCommonSIB.h"
 #include "nfapi_interface.h"
 #include "PHY_INTERFACE/IF_Module.h"
 
@@ -92,7 +92,7 @@
 #define DCH_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 (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 
 // Mask for identifying subframe for MBMS
 #define MBSFN_TDD_SF3 0x80	// for TDD
@@ -381,7 +381,7 @@ typedef struct {
     uint8_t payload[PCCH_PAYLOAD_SIZE_MAX];
 } __attribute__ ((__packed__)) PCCH_PDU;
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 /*! \brief MCCH payload */
 typedef struct {
     uint8_t payload[MCCH_PAYLOAD_SIZE_MAX];
@@ -438,7 +438,7 @@ typedef struct {
 /*!\brief LCID of padding LCID for DLSCH */
 #define SHORT_PADDING 31
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#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
@@ -897,18 +897,15 @@ typedef struct {
     uint32_t pucch_tpc_tx_frame;
     uint32_t pucch_tpc_tx_subframe;
 
-#ifdef LOCALIZATION
-    eNB_UE_estimated_distances distance;
-#endif
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
     uint8_t rach_resource_type;
     uint16_t mpdcch_repetition_cnt;
     frame_t Msg2_frame;
 #endif
     sub_frame_t Msg2_subframe;
 
-    PhysicalConfigDedicated_t *physicalConfigDedicated;
+    LTE_PhysicalConfigDedicated_t *physicalConfigDedicated;
 
 } UE_TEMPLATE;
 
@@ -979,6 +976,7 @@ typedef struct {
     uint16_t feedback_cnt[NFAPI_CC_MAX];
     uint16_t timing_advance;
     uint16_t timing_advance_r9;
+    uint8_t tpc_accumulated[NFAPI_CC_MAX];
     uint8_t periodic_wideband_cqi[NFAPI_CC_MAX];
     uint8_t periodic_wideband_spatial_diffcqi[NFAPI_CC_MAX];
     uint8_t periodic_wideband_pmi[NFAPI_CC_MAX];
@@ -998,67 +996,71 @@ typedef struct {
     uint8_t crnti_reconfigurationcomplete_flag;
     uint8_t cqi_req_flag;
 } UE_sched_ctrl;
+
 /*! \brief eNB template for the Random access information */
 typedef struct {
-    /// Flag to indicate this process is active
-    RA_state state;
-    /// Subframe where preamble was received
-    uint8_t preamble_subframe;
-    /// Subframe where Msg2 is to be sent
-    uint8_t Msg2_subframe;
-    /// Frame where Msg2 is to be sent
-    frame_t Msg2_frame;
-    /// Subframe where Msg3 is to be sent
-    sub_frame_t Msg3_subframe;
-    /// Frame where Msg3 is to be sent
-    frame_t Msg3_frame;
-    /// Delay cnt for Msg4 transmission (waiting for RRC message piggyback)
-    int Msg4_delay_cnt;
-    /// Subframe where Msg4 is to be sent
-    sub_frame_t Msg4_subframe;
-    /// Frame where Msg4 is to be sent
-    frame_t Msg4_frame;
-    /// harq_pid used for Msg4 transmission
-    uint8_t harq_pid;
-    /// UE RNTI allocated during RAR
-    rnti_t rnti;
-    /// RA RNTI allocated from received PRACH
-    uint16_t RA_rnti;
-    /// Received preamble_index
-    uint8_t preamble_index;
-    /// Received UE Contention Resolution Identifier
-    uint8_t cont_res_id[6];
-    /// Timing offset indicated by PHY
-    int16_t timing_offset;
-    /// Timeout for RRC connection
-    int16_t RRC_timer;
-    /// Msg3 first RB
-    uint8_t msg3_first_rb;
-    /// Msg3 number of RB
-    uint8_t msg3_nb_rb;
-    /// Msg3 MCS
-    uint8_t msg3_mcs;
-    /// Msg3 TPC command
-    uint8_t msg3_TPC;
-    /// Msg3 ULdelay command
-    uint8_t msg3_ULdelay;
-    /// Msg3 cqireq command
-    uint8_t msg3_cqireq;
-    /// Round of Msg3 HARQ
-    uint8_t msg3_round;
-    /// TBS used for Msg4
-    int msg4_TBsize;
-    /// MCS used for Msg4
-    int msg4_mcs;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-    uint8_t rach_resource_type;
-    uint8_t msg2_mpdcch_repetition_cnt;
-    uint8_t msg4_mpdcch_repetition_cnt;
-    uint8_t msg2_narrowband;
-    uint8_t msg34_narrowband;
+  /// Flag to indicate this process is active
+  RA_state state;
+  /// Subframe where preamble was received
+  uint8_t preamble_subframe;
+  /// Subframe where Msg2 is to be sent
+  uint8_t Msg2_subframe;
+  /// Frame where Msg2 is to be sent
+  frame_t Msg2_frame;
+  /// Subframe where Msg3 is to be sent
+  sub_frame_t Msg3_subframe;
+  /// Frame where Msg3 is to be sent
+  frame_t Msg3_frame;
+  /// Delay cnt for Msg4 transmission (waiting for RRC message piggyback)
+  int Msg4_delay_cnt;
+  /// Subframe where Msg4 is to be sent
+  sub_frame_t Msg4_subframe;
+  /// Frame where Msg4 is to be sent
+  frame_t Msg4_frame;
+  /// harq_pid used for Msg4 transmission
+  uint8_t harq_pid;
+  /// UE RNTI allocated during RAR
+  rnti_t rnti;
+  /// RA RNTI allocated from received PRACH
+  uint16_t RA_rnti;
+  /// Received preamble_index
+  uint8_t preamble_index;
+  /// Received UE Contention Resolution Identifier
+  uint8_t cont_res_id[6];
+  /// Timing offset indicated by PHY
+  int16_t timing_offset;
+  /// Timeout for RRC connection
+  int16_t RRC_timer;
+  /// Msg3 first RB
+  uint8_t msg3_first_rb;
+  /// Msg3 number of RB
+  uint8_t msg3_nb_rb;
+  /// Msg3 MCS
+  uint8_t msg3_mcs;
+  /// Msg3 TPC command
+  uint8_t msg3_TPC;
+  /// Msg3 ULdelay command
+  uint8_t msg3_ULdelay;
+  /// Msg3 cqireq command
+  uint8_t msg3_cqireq;
+  /// Round of Msg3 HARQ
+  uint8_t msg3_round;
+  /// TBS used for Msg4
+  int msg4_TBsize;
+  /// MCS used for Msg4
+  int msg4_mcs;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  uint8_t rach_resource_type;
+  uint8_t msg2_mpdcch_repetition_cnt;
+  int     msg2_mpdcch_done;
+  uint8_t msg4_mpdcch_repetition_cnt;
+  int     msg4_mpdcch_done;
+  uint8_t msg2_narrowband;
+  uint8_t msg34_narrowband;
+  int     msg4_rrc_sdu_length;
 #endif
-    int32_t  crnti_rrc_mui;
-    int8_t   crnti_harq_pid;
+  int32_t  crnti_rrc_mui;
+  int8_t   crnti_harq_pid;
 } RA_t;
 
 
@@ -1072,44 +1074,40 @@ typedef struct {
 } SBMAP_CONF;
 /*! \brief UE list used by eNB to order UEs/CC for scheduling*/
 typedef struct {
-    /// Dedicated information for UEs
-    struct PhysicalConfigDedicated
-	*physicalConfigDedicated[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB];
-    /// DLSCH pdu
-    DLSCH_PDU DLSCH_pdu[NFAPI_CC_MAX][2][MAX_MOBILES_PER_ENB];
-    /// DCI template and MAC connection parameters for UEs
-    UE_TEMPLATE UE_template[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB];
-    /// DCI template and MAC connection for RA processes
-    int pCC_id[MAX_MOBILES_PER_ENB];
-    /// sorted downlink component carrier for the scheduler
-    int ordered_CCids[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB];
-    /// number of downlink active component carrier
-    int numactiveCCs[MAX_MOBILES_PER_ENB];
-    /// sorted uplink component carrier for the scheduler
-    int ordered_ULCCids[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB];
-    /// number of uplink active component carrier
-    int numactiveULCCs[MAX_MOBILES_PER_ENB];
-    /// number of downlink active component carrier
-    uint8_t dl_CC_bitmap[MAX_MOBILES_PER_ENB];
-    /// eNB to UE statistics
-    eNB_UE_STATS eNB_UE_stats[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB];
-    /// scheduling control info
-    UE_sched_ctrl UE_sched_ctrl[MAX_MOBILES_PER_ENB];
-    int next[MAX_MOBILES_PER_ENB];
-    int head;
-    int next_ul[MAX_MOBILES_PER_ENB];
-    int head_ul;
-    int avail;
-    int num_UEs;
-    boolean_t active[MAX_MOBILES_PER_ENB];
-
-    /// Sorting criteria for the UE list in the MAC preprocessor
-    uint16_t sorting_criteria[MAX_NUM_SLICES][CR_NUM];
-    uint16_t first_rb_offset[NFAPI_CC_MAX][MAX_NUM_SLICES];
-
-    int assoc_dl_slice_idx[MAX_MOBILES_PER_ENB];
-    int assoc_ul_slice_idx[MAX_MOBILES_PER_ENB];
 
+  DLSCH_PDU DLSCH_pdu[NFAPI_CC_MAX][2][MAX_MOBILES_PER_ENB];
+  /// DCI template and MAC connection parameters for UEs
+  UE_TEMPLATE UE_template[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB];
+  /// DCI template and MAC connection for RA processes
+  int pCC_id[MAX_MOBILES_PER_ENB];
+  /// sorted downlink component carrier for the scheduler
+  int ordered_CCids[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB];
+  /// number of downlink active component carrier
+  int numactiveCCs[MAX_MOBILES_PER_ENB];
+  /// sorted uplink component carrier for the scheduler
+  int ordered_ULCCids[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB];
+  /// number of uplink active component carrier
+  int numactiveULCCs[MAX_MOBILES_PER_ENB];
+  /// number of downlink active component carrier
+  uint8_t dl_CC_bitmap[MAX_MOBILES_PER_ENB];
+  /// eNB to UE statistics
+  eNB_UE_STATS eNB_UE_stats[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB];
+  /// scheduling control info
+  UE_sched_ctrl UE_sched_ctrl[MAX_MOBILES_PER_ENB];
+  int next[MAX_MOBILES_PER_ENB];
+  int head;
+  int next_ul[MAX_MOBILES_PER_ENB];
+  int head_ul;
+  int avail;
+  int num_UEs;
+  boolean_t active[MAX_MOBILES_PER_ENB];
+
+  /// Sorting criteria for the UE list in the MAC preprocessor
+  uint16_t sorting_criteria[MAX_NUM_SLICES][CR_NUM];
+  uint16_t first_rb_offset[NFAPI_CC_MAX][MAX_NUM_SLICES];
+
+  int assoc_dl_slice_idx[MAX_MOBILES_PER_ENB];
+  int assoc_ul_slice_idx[MAX_MOBILES_PER_ENB];
 } UE_list_t;
 
 /*! \brief deleting control information*/
@@ -1246,14 +1244,14 @@ typedef struct {
     int Ncp;
     int eutra_band;
     uint32_t dl_CarrierFreq;
-    BCCH_BCH_Message_t *mib;
-    RadioResourceConfigCommonSIB_t *radioResourceConfigCommon;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-    RadioResourceConfigCommonSIB_t *radioResourceConfigCommon_BR;
+    LTE_BCCH_BCH_Message_t *mib;
+    LTE_RadioResourceConfigCommonSIB_t *radioResourceConfigCommon;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+    LTE_RadioResourceConfigCommonSIB_t *radioResourceConfigCommon_BR;
 #endif
-    TDD_Config_t *tdd_Config;
-    SchedulingInfoList_t *schedulingInfoList;
-    ARFCN_ValueEUTRA_t ul_CarrierFreq;
+    LTE_TDD_Config_t *tdd_Config;
+    LTE_SchedulingInfoList_t *schedulingInfoList;
+    LTE_ARFCN_ValueEUTRA_t ul_CarrierFreq;
     long ul_Bandwidth;
     /// Outgoing MIB PDU for PHY
     MIB_PDU MIB_pdu;
@@ -1276,10 +1274,10 @@ typedef struct {
     /// VRB map for common channels and retransmissions by PHICH
     uint8_t vrb_map_UL[100];
     /// MBSFN SubframeConfig
-    struct MBSFN_SubframeConfig *mbsfn_SubframeConfig[8];
+    struct LTE_MBSFN_SubframeConfig *mbsfn_SubframeConfig[8];
     /// number of subframe allocation pattern available for MBSFN sync area
     uint8_t num_sf_allocation_pattern;
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
     /// MBMS Flag
     uint8_t MBMS_flag;
     /// Outgoing MCCH pdu for PHY
@@ -1293,17 +1291,17 @@ typedef struct {
     /// number of active MBSFN area
     uint8_t num_active_mbsfn_area;
     /// MBSFN Area Info
-    struct MBSFN_AreaInfo_r9 *mbsfn_AreaInfo[MAX_MBSFN_AREA];
+    struct LTE_MBSFN_AreaInfo_r9 *mbsfn_AreaInfo[MAX_MBSFN_AREA];
     /// PMCH Config
-    struct PMCH_Config_r9 *pmch_Config[MAX_PMCH_perMBSFN];
+    struct LTE_PMCH_Config_r9 *pmch_Config[MAX_PMCH_perMBSFN];
     /// MBMS session info list
-    struct MBMS_SessionInfoList_r9 *mbms_SessionList[MAX_PMCH_perMBSFN];
+    struct LTE_MBMS_SessionInfoList_r9 *mbms_SessionList[MAX_PMCH_perMBSFN];
     /// Outgoing MCH pdu for PHY
     MCH_PDU MCH_pdu;
 #endif
-#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
     /// Rel13 parameters from SIB1
-    SystemInformationBlockType1_v1310_IEs_t *sib1_v13ext;
+    LTE_SystemInformationBlockType1_v1310_IEs_t *sib1_v13ext;
     /// Counter for SIB1-BR scheduling
     int SIB1_BR_cnt;
     /// Outgoing BCCH-BR pdu for PHY
@@ -1457,9 +1455,9 @@ typedef struct {
     /// default value is false
     uint16_t ttiBundling;
     /// default value is release
-    struct DRX_Config *drx_config;
+    struct LTE_DRX_Config *drx_config;
     /// default value is release
-    struct MAC_MainConfig__phr_Config *phr_config;
+    struct LTE_MAC_MainConfig__phr_Config *phr_config;
     ///timer before triggering a periodic PHR
     uint16_t periodicPHR_Timer;
     ///timer before triggering a prohibit PHR
@@ -1501,30 +1499,30 @@ typedef struct {
     /// uplink active flag
     uint8_t ul_active;
     /// pointer to RRC PHY configuration
-    RadioResourceConfigCommonSIB_t *radioResourceConfigCommon;
+    LTE_RadioResourceConfigCommonSIB_t *radioResourceConfigCommon;
     /// pointer to RACH_ConfigDedicated (NULL when not active, i.e. upon HO completion or T304 expiry)
-    struct RACH_ConfigDedicated *rach_ConfigDedicated;
+    struct LTE_RACH_ConfigDedicated *rach_ConfigDedicated;
     /// pointer to RRC PHY configuration
-    struct PhysicalConfigDedicated *physicalConfigDedicated;
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+    struct LTE_PhysicalConfigDedicated *physicalConfigDedicated;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
   /// pointer to RRC PHY configuration SCEll
-  struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10;
+  struct LTE_PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10;
   /// Preconfiguration for Sidelink
-  struct SL_Preconfiguration_r12 *SL_Preconfiguration;
+  struct LTE_SL_Preconfiguration_r12 *SL_Preconfiguration;
   /// RX Pool for Sidelink from SIB18
-  SL_CommRxPoolList_r12_t	 commRxPool_r12;
+  LTE_SL_CommRxPoolList_r12_t	 commRxPool_r12;
   /// TX Pool Normal for Sidelink from SIB18
-  struct SL_CommTxPoolList_r12	*commTxPoolNormalCommon_r12;
+  struct LTE_SL_CommTxPoolList_r12	*commTxPoolNormalCommon_r12;
   /// TX Pool Exceptional for Sidelink from SIB18
-  struct SL_CommTxPoolList_r12	*commTxPoolExceptional_r12;
+  struct LTE_SL_CommTxPoolList_r12	*commTxPoolExceptional_r12;
   /// Common Sync Config for Sidelink from SIB18
-  struct SL_SyncConfigList_r12	*commSyncConfig_r12;
+  struct LTE_SL_SyncConfigList_r12	*commSyncConfig_r12;
   /// Dedicated Sync TX control for Sidelink
-  struct SL_SyncTxControl_r12 *sl_SyncTxControl_r12;
+  struct LTE_SL_SyncTxControl_r12 *sl_SyncTxControl_r12;
   /// Dedicated Discovery TX control for Sidelink
-  struct SL_DiscConfig_r12	*sl_DiscConfig_r12;
+  struct LTE_SL_DiscConfig_r12	*sl_DiscConfig_r12;
   /// Dedicated TX config for Sidelink
-  struct SL_CommConfig_r12	*sl_CommConfig_r12;
+  struct LTE_SL_CommConfig_r12	*sl_CommConfig_r12;
   //SL sourceL2ID
   uint32_t sourceL2Id;
   //SL groupL2Id
@@ -1538,17 +1536,17 @@ typedef struct {
 
 #endif
     /// pointer to TDD Configuration (NULL for FDD)
-    TDD_Config_t *tdd_Config;
+    LTE_TDD_Config_t *tdd_Config;
     /// Number of adjacent cells to measure
     uint8_t n_adj_cells;
     /// Array of adjacent physical cell ids
     uint32_t adj_cell_id[6];
     /// Pointer to RRC MAC configuration
-    MAC_MainConfig_t *macConfig;
+    LTE_MAC_MainConfig_t *macConfig;
     /// Pointer to RRC Measurement gap configuration
-    MeasGapConfig_t *measGapConfig;
+    LTE_MeasGapConfig_t *measGapConfig;
     /// Pointers to LogicalChannelConfig indexed by LogicalChannelIdentity. Note NULL means LCHAN is inactive.
-    LogicalChannelConfig_t *logicalChannelConfig[MAX_NUM_LCID];
+    LTE_LogicalChannelConfig_t *logicalChannelConfig[MAX_NUM_LCID];
     /// Scheduling Information
     UE_SCHEDULING_INFO scheduling_info;
     /// Outgoing CCCH pdu for PHY
@@ -1557,7 +1555,7 @@ typedef struct {
     RAR_PDU RAR_pdu;
     /// Incoming DLSCH pdu for PHY
     DLSCH_PDU DLSCH_pdu[MAX_MOBILES_PER_ENB][2];
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
     int sltx_active;
     SLSCH_t slsch;
     SLDCH_t sldch;
@@ -1613,16 +1611,16 @@ typedef struct {
     uint8_t periodBSRTimer_expires_flag;
 
     /// MBSFN_Subframe Configuration
-    struct MBSFN_SubframeConfig *mbsfn_SubframeConfig[8];	// FIXME replace 8 by MAX_MBSFN_AREA?
+    struct LTE_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 (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
     /// number of active MBSFN area
     uint8_t num_active_mbsfn_area;
     /// MBSFN Area Info
-    struct MBSFN_AreaInfo_r9 *mbsfn_AreaInfo[MAX_MBSFN_AREA];
+    struct LTE_MBSFN_AreaInfo_r9 *mbsfn_AreaInfo[MAX_MBSFN_AREA];
     /// PMCH Config
-    struct PMCH_Config_r9 *pmch_Config[MAX_PMCH_perMBSFN];
+    struct LTE_PMCH_Config_r9 *pmch_Config[MAX_PMCH_perMBSFN];
     /// MCCH status
     uint8_t mcch_status;
     /// MSI status
@@ -1630,7 +1628,7 @@ typedef struct {
     uint8_t msi_current_alloc;
     uint8_t msi_pmch;
 
-    struct MBSFN_SubframeConfig *commonSF_Alloc_r9_mbsfn_SubframeConfig[8]; // FIXME replace 8 by MAX_MBSFN_AREA?
+    struct LTE_MBSFN_SubframeConfig *commonSF_Alloc_r9_mbsfn_SubframeConfig[8]; // FIXME replace 8 by MAX_MBSFN_AREA?
     uint8_t commonSF_AllocPeriod_r9;
     int common_num_sf_alloc;
 
diff --git a/openair2/LAYER2/MAC/mac_extern.h b/openair2/LAYER2/MAC/mac_extern.h
index ca72882471f11122633b5dc76af58740f73ce757..fd9ffb6a87ebce7c297cb0c8b3fce8b25aee361d 100644
--- a/openair2/LAYER2/MAC/mac_extern.h
+++ b/openair2/LAYER2/MAC/mac_extern.h
@@ -64,7 +64,8 @@ extern eNB_DLSCH_INFO eNB_dlsch_info[NUMBER_OF_eNB_MAX][MAX_NUM_CCs][MAX_MOBILES
 extern unsigned char NB_INST;
 #endif
 extern unsigned char NB_eNB_INST;
-extern unsigned char NB_UE_INST;
+extern uint16_t NB_UE_INST;
+extern uint16_t NB_THREAD_INST;
 extern unsigned char NB_RN_INST;
 extern unsigned short NODE_ID[1];
 
diff --git a/openair2/LAYER2/MAC/mac_proto.h b/openair2/LAYER2/MAC/mac_proto.h
index cff9309864f19b028917d865c98285fecaf1afe7..6824e1b056fec72e7257850296b173d0825d6f46 100644
--- a/openair2/LAYER2/MAC/mac_proto.h
+++ b/openair2/LAYER2/MAC/mac_proto.h
@@ -113,6 +113,12 @@ void schedule_ulsch_rnti(module_id_t module_idP, int slice_idx, frame_t frameP,
 			 unsigned char sched_subframe,
 			 uint16_t * first_rb);
 
+void schedule_ulsch_rnti_emtc(module_id_t   module_idP,
+			      frame_t       frameP,
+			      sub_frame_t   subframeP,
+			      unsigned char sched_subframeP,
+			      int          *emtc_active);
+
 /** \brief Second stage of DLSCH scheduling, after schedule_SI, schedule_RA and schedule_dlsch have been called.  This routine first allocates random frequency assignments for SI and RA SDUs using distributed VRB allocations and adds the corresponding DCI SDU to the DCI buffer for PHY.  It then loops over the UE specific DCIs previously allocated and fills in the remaining DCI fields related to frequency allocation.  It assumes localized allocation of type 0 (DCI.rah=0).  The allocation is done for tranmission modes 1,2,4.
 @param Mod_id Instance of eNB
 @param frame Frame index
@@ -133,7 +139,9 @@ void schedule_dlsch(module_id_t module_idP, frame_t frameP,
 
 void schedule_ue_spec(module_id_t module_idP, int slice_idxP,
 		      frame_t frameP,sub_frame_t subframe, int *mbsfn_flag);
-
+void schedule_ue_spec_br(module_id_t   module_idP,
+			 frame_t       frameP,
+			 sub_frame_t   subframeP);
 void schedule_ue_spec_phy_test(module_id_t module_idP,frame_t frameP,sub_frame_t subframe,int *mbsfn_flag);
 void schedule_ulsch_phy_test(module_id_t module_idP,frame_t frameP,sub_frame_t subframeP);
 
@@ -290,7 +298,7 @@ void eNB_dlsch_ulsch_scheduler(module_id_t module_idP, frame_t frameP, sub_frame
 void initiate_ra_proc(module_id_t module_idP, int CC_id, frame_t frameP,
 		      sub_frame_t subframeP, uint16_t preamble_index,
 		      int16_t timing_offset, uint16_t rnti
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 		      , uint8_t rach_resource_type
 #endif
     );
@@ -309,7 +317,7 @@ unsigned short fill_rar(const module_id_t module_idP,
 			const uint16_t N_RB_UL,
 			const uint8_t input_buffer_length);
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 unsigned short fill_rar_br(eNB_MAC_INST * eNB,
 			   int CC_id,
 			   RA_t * ra,
@@ -444,7 +452,7 @@ uint8_t get_aggregation(uint8_t bw_index, uint8_t cqi, uint8_t dci_fmt);
 
 int8_t find_active_UEs_with_traffic(module_id_t module_idP);
 
-void init_CCE_table(int module_idP, int CC_idP);
+void init_CCE_table(int *CCE_table);
 
 int get_nCCE_offset(int *CCE_table,
 		    const unsigned char L,
@@ -465,7 +473,7 @@ void set_ue_dai(sub_frame_t subframeP,
 		int UE_id,
 		uint8_t CC_id, uint8_t tdd_config, UE_list_t * UE_list);
 
-uint8_t frame_subframe2_dl_harq_pid(TDD_Config_t *tdd_Config, int abs_frameP, sub_frame_t subframeP);
+uint8_t frame_subframe2_dl_harq_pid(LTE_TDD_Config_t *tdd_Config, int abs_frameP, sub_frame_t subframeP);
 /** \brief First stage of PCH Scheduling. Gets a PCH SDU from RRC if available and computes the MCS required to transport it as a function of the SDU length.  It assumes a length less than or equal to 64 bytes (MCS 6, 3 PRBs).
 @param Mod_id Instance ID of eNB
 @param frame Frame index
@@ -549,7 +557,7 @@ void ue_send_sl_sdu(module_id_t module_idP,
 	       sl_discovery_flag_t sl_discovery_flag
 		    );
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 /* \brief Called by PHY to transfer MCH transport block to ue MAC.
 @param Mod_id Index of module instance
 @param frame Frame index
@@ -694,12 +702,11 @@ int to_prb(int);
 int to_rbg(int);
 int mac_init(void);
 int add_new_ue(module_id_t Mod_id, int CC_id, rnti_t rnti, int harq_pid
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 	       , uint8_t rach_resource_type
 #endif
     );
 int rrc_mac_remove_ue(module_id_t Mod_id, rnti_t rntiP);
-void rrc_mac_signal_ue_release(module_id_t Mod_id, rnti_t rntiP);
 
 void store_dlsch_buffer(module_id_t Mod_id, int slice_idx, frame_t frameP, sub_frame_t subframeP);
 void assign_rbs_required(module_id_t Mod_id, int slice_idx, frame_t frameP, sub_frame_t subframe, uint16_t nb_rbs_required[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB], int min_rb_unit[NFAPI_CC_MAX]);
@@ -727,7 +734,7 @@ void ulsch_scheduler_pre_processor(module_id_t module_idP, int slice_idx, int fr
 				   uint16_t * first_rb);
 void store_ulsch_buffer(module_id_t module_idP, int frameP,
 			sub_frame_t subframeP);
-void sort_ue_ul(module_id_t module_idP, int frameP, sub_frame_t subframeP);
+void sort_ue_ul(module_id_t module_idP, int slice_idx, int frameP, sub_frame_t subframeP, rnti_t *rntiTable);
 void assign_max_mcs_min_rb(module_id_t module_idP, int slice_idx, int frameP,
 			   sub_frame_t subframeP, uint16_t * first_rb);
 void adjust_bsr_info(int buffer_occupancy, uint16_t TBS,
@@ -957,46 +964,46 @@ int rrc_mac_config_req_eNB(module_id_t module_idP,
 			   int p_eNB,
 			   int Ncp,
 			   int eutra_band, uint32_t dl_CarrierFreq,
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 			   int pbch_repetition,
 #endif
 			   rnti_t rntiP,
-			   BCCH_BCH_Message_t * mib,
-			   RadioResourceConfigCommonSIB_t *
+			   LTE_BCCH_BCH_Message_t * mib,
+			   LTE_RadioResourceConfigCommonSIB_t *
 			   radioResourceConfigCommon,
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-			   RadioResourceConfigCommonSIB_t *
-			   radioResourceConfigCommon_BR,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+			   LTE_RadioResourceConfigCommonSIB_t *
+			   LTE_radioResourceConfigCommon_BR,
 #endif
-			   struct PhysicalConfigDedicated
+			   struct LTE_PhysicalConfigDedicated
 			   *physicalConfigDedicated,
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-			   SCellToAddMod_r10_t * sCellToAddMod_r10,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+			   LTE_SCellToAddMod_r10_t * sCellToAddMod_r10,
 			   //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
 #endif
-			   MeasObjectToAddMod_t ** measObj,
-			   MAC_MainConfig_t * mac_MainConfig,
+			   LTE_MeasObjectToAddMod_t ** measObj,
+			   LTE_MAC_MainConfig_t * mac_MainConfig,
 			   long logicalChannelIdentity,
-			   LogicalChannelConfig_t * logicalChannelConfig,
-			   MeasGapConfig_t * measGapConfig,
-			   TDD_Config_t * tdd_Config,
-			   MobilityControlInfo_t * mobilityControlInfo,
-			   SchedulingInfoList_t * schedulingInfoList,
+			   LTE_LogicalChannelConfig_t * logicalChannelConfig,
+			   LTE_MeasGapConfig_t * measGapConfig,
+			   LTE_TDD_Config_t * tdd_Config,
+			   LTE_MobilityControlInfo_t * mobilityControlInfo,
+			   LTE_SchedulingInfoList_t * schedulingInfoList,
 			   uint32_t ul_CarrierFreq,
 			   long *ul_Bandwidth,
-			   AdditionalSpectrumEmission_t *
+			   LTE_AdditionalSpectrumEmission_t *
 			   additionalSpectrumEmission,
-			   struct MBSFN_SubframeConfigList
+			   struct LTE_MBSFN_SubframeConfigList
 			   *mbsfn_SubframeConfigList
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
 			   ,
 			   uint8_t MBMS_Flag,
-			   MBSFN_AreaInfoList_r9_t * mbsfn_AreaInfoList,
-			   PMCH_InfoList_r9_t * pmch_InfoList
+			   LTE_MBSFN_AreaInfoList_r9_t * mbsfn_AreaInfoList,
+			   LTE_PMCH_InfoList_r9_t * pmch_InfoList
 #endif
-#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
 			   ,
-			   SystemInformationBlockType1_v1310_IEs_t *
+			   LTE_SystemInformationBlockType1_v1310_IEs_t *
 			   sib1_ext_r13
 #endif
     );
@@ -1024,40 +1031,40 @@ int rrc_mac_config_req_eNB(module_id_t module_idP,
 int rrc_mac_config_req_ue(module_id_t module_idP,
 			  int CC_id,
 			  uint8_t eNB_index,
-			  RadioResourceConfigCommonSIB_t *
+			  LTE_RadioResourceConfigCommonSIB_t *
 			  radioResourceConfigCommon,
-			  struct PhysicalConfigDedicated
+			  struct LTE_PhysicalConfigDedicated
 			  *physicalConfigDedicated,
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-			  SCellToAddMod_r10_t * sCellToAddMod_r10,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+			  LTE_SCellToAddMod_r10_t * sCellToAddMod_r10,
 			  //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
 #endif
-			  MeasObjectToAddMod_t ** measObj,
-			  MAC_MainConfig_t * mac_MainConfig,
+			  LTE_MeasObjectToAddMod_t ** measObj,
+			  LTE_MAC_MainConfig_t * mac_MainConfig,
 			  long logicalChannelIdentity,
-			  LogicalChannelConfig_t * logicalChannelConfig,
-			  MeasGapConfig_t * measGapConfig,
-			  TDD_Config_t * tdd_Config,
-			  MobilityControlInfo_t * mobilityControlInfo,
+			  LTE_LogicalChannelConfig_t * logicalChannelConfig,
+			  LTE_MeasGapConfig_t * measGapConfig,
+			  LTE_TDD_Config_t * tdd_Config,
+			  LTE_MobilityControlInfo_t * mobilityControlInfo,
 			  uint8_t * SIwindowsize,
 			  uint16_t * SIperiod,
-			  ARFCN_ValueEUTRA_t * ul_CarrierFreq,
+			  LTE_ARFCN_ValueEUTRA_t * ul_CarrierFreq,
 			  long *ul_Bandwidth,
-			  AdditionalSpectrumEmission_t *
+			  LTE_AdditionalSpectrumEmission_t *
 			  additionalSpectrumEmission,
-			  struct MBSFN_SubframeConfigList
+			  struct LTE_MBSFN_SubframeConfigList
 			  *mbsfn_SubframeConfigList
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 			  ,
 			  uint8_t MBMS_Flag,
-			  MBSFN_AreaInfoList_r9_t * mbsfn_AreaInfoList,
-			  PMCH_InfoList_r9_t * pmch_InfoList
+			  LTE_MBSFN_AreaInfoList_r9_t * mbsfn_AreaInfoList,
+			  LTE_PMCH_InfoList_r9_t * pmch_InfoList
 #endif
 #ifdef CBA
 			  ,
 			  uint8_t num_active_cba_groups, uint16_t cba_rnti
 #endif
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 			  ,config_action_t config_action
 			  ,const uint32_t * const sourceL2Id
 			  ,const uint32_t * const destinationL2Id
@@ -1085,11 +1092,11 @@ uint16_t mac_computeRIV(uint16_t N_RB_DL, uint16_t RBstart,
 
 int get_phich_resource_times6(COMMON_channels_t * cc);
 
-uint8_t frame_subframe2_dl_harq_pid(TDD_Config_t *tdd_Config, int abs_frameP, sub_frame_t subframeP);
+uint8_t frame_subframe2_dl_harq_pid(LTE_TDD_Config_t *tdd_Config, int abs_frameP, sub_frame_t subframeP);
 
 uint8_t ul_subframe2_k_phich(COMMON_channels_t * cc, sub_frame_t ul_subframe);
 
-unsigned char ul_ACK_subframe2M(TDD_Config_t *tdd_Config,unsigned char subframe);
+unsigned char ul_ACK_subframe2M(LTE_TDD_Config_t *tdd_Config,unsigned char subframe);
 
 int to_rbg(int dl_Bandwidth);
 
@@ -1114,17 +1121,17 @@ void get_srs_pos(COMMON_channels_t * cc, uint16_t isrs,
 		 uint16_t * psrsPeriodicity, uint16_t * psrsOffset);
 
 void get_csi_params(COMMON_channels_t * cc,
-		    struct CQI_ReportPeriodic *cqi_PMI_ConfigIndex,
+		    struct LTE_CQI_ReportPeriodic *cqi_PMI_ConfigIndex,
 		    uint16_t * Npd, uint16_t * N_OFFSET_CQI, int *H);
 
 uint8_t get_rel8_dl_cqi_pmi_size(UE_sched_ctrl * sched_ctl, int CC_idP,
 				 COMMON_channels_t * cc, uint8_t tmode,
-				 struct CQI_ReportPeriodic
+				 struct LTE_CQI_ReportPeriodic
 				 *cqi_ReportPeriodic);
 
 uint8_t get_dl_cqi_pmi_size_pusch(COMMON_channels_t * cc, uint8_t tmode,
 				  uint8_t ri,
-				  CQI_ReportModeAperiodic_t *
+				  LTE_CQI_ReportModeAperiodic_t *
 				  cqi_ReportModeAperiodic);
 void extract_pucch_csi(module_id_t mod_idP, int CC_idP, int UE_id,
 		       frame_t frameP, sub_frame_t subframeP,
@@ -1141,7 +1148,7 @@ uint16_t fill_nfapi_tx_req(nfapi_tx_request_body_t * tx_req_body,
 void fill_nfapi_ulsch_config_request_rel8(nfapi_ul_config_request_pdu_t *
 					  ul_config_pdu, uint8_t cqi_req,
 					  COMMON_channels_t * cc,
-					  struct PhysicalConfigDedicated
+					  struct LTE_PhysicalConfigDedicated
 					  *physicalConfigDedicated,
 					  uint8_t tmode, uint32_t handle,
 					  uint16_t rnti,
@@ -1160,7 +1167,7 @@ void fill_nfapi_ulsch_config_request_rel8(nfapi_ul_config_request_pdu_t *
 					  uint8_t current_tx_nb,
 					  uint8_t n_srs, uint16_t size);
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 void fill_nfapi_ulsch_config_request_emtc(nfapi_ul_config_request_pdu_t *
 					  ul_config_pdu, uint8_t ue_type,
 					  uint16_t
@@ -1237,7 +1244,7 @@ uint8_t get_tmode(module_id_t module_idP, int CC_idP, int UE_idP);
 uint8_t get_ul_req_index(module_id_t module_idP, int CC_idP,
 			 sub_frame_t subframeP);
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 int get_numnarrowbandbits(long dl_Bandwidth);
 
 int mpdcch_sf_condition(eNB_MAC_INST * eNB, int CC_id, frame_t frameP,
diff --git a/openair2/LAYER2/MAC/mac_vars.h b/openair2/LAYER2/MAC/mac_vars.h
index 76842afd38358bed4baeb0ff3b72d0c68cf728db..7126301a7c82292a399914bb455f713059912b39 100644
--- a/openair2/LAYER2/MAC/mac_vars.h
+++ b/openair2/LAYER2/MAC/mac_vars.h
@@ -95,7 +95,7 @@ const uint8_t cqi2fmt2x_agg[MAX_SUPPORTED_BW][CQI_VALUE_RANGE] = {
 
 uint32_t RRC_CONNECTION_FLAG;
 
-UE_MAC_INST *UE_mac_inst;	//[NB_MODULE_MAX];
+UE_MAC_INST *UE_mac_inst = NULL;	//[NB_MODULE_MAX];
 MAC_RLC_XFACE *Mac_rlc_xface;
 
 /// Primary component carrier index of eNB
@@ -109,7 +109,8 @@ eNB_DLSCH_INFO eNB_dlsch_info[NUMBER_OF_eNB_MAX][MAX_NUM_CCs][MAX_MOBILES_PER_EN
 
 #ifdef OPENAIR2
 unsigned char NB_eNB_INST = 0;
-unsigned char NB_UE_INST = 0;
+uint16_t NB_UE_INST = 0;
+uint16_t NB_THREAD_INST = 0;
 unsigned char NB_RN_INST = 0;
 unsigned char NB_INST = 0;
 #endif
@@ -124,7 +125,7 @@ DCI1A_5MHz_TDD_1_6_t BCCH_alloc_pdu;
 DCI1A_5MHz_TDD_1_6_t CCCH_alloc_pdu;
 DCI1_5MHz_TDD_t DLSCH_alloc_pdu;
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 DCI1C_5MHz_t MCCH_alloc_pdu;
 #endif
 
diff --git a/openair2/LAYER2/MAC/main_ue.c b/openair2/LAYER2/MAC/main_ue.c
index 95f25c7ff51b72648bf1c9d2a4e5d058bce2baa3..1168ed265abde1667da8f9e28f5395c96d093bc4 100644
--- a/openair2/LAYER2/MAC/main_ue.c
+++ b/openair2/LAYER2/MAC/main_ue.c
@@ -43,7 +43,8 @@
 
 
 #include "common/ran_context.h"
-
+extern FILL_UL_INFO_MUTEX_t fill_ul_mutex;
+extern uint8_t nfapi_mode;
 extern void openair_rrc_top_init_ue( int eMBMS_active, char* uecap_xer, uint8_t cba_group_active, uint8_t HO_active);
 
 void dl_phy_sync_success(module_id_t module_idP, frame_t frameP, unsigned char eNB_index, uint8_t first_sync)	//init as MR
@@ -103,6 +104,15 @@ mac_top_init_ue(int eMBMS_active, char *uecap_xer,
 	UE_mac_inst = NULL;
     }
 
+    // mutex below are used for multiple UE's L2 FAPI simulation.
+    if (nfapi_mode == 3){
+      pthread_mutex_init(&fill_ul_mutex.rx_mutex,NULL);
+      pthread_mutex_init(&fill_ul_mutex.crc_mutex,NULL);
+      pthread_mutex_init(&fill_ul_mutex.sr_mutex,NULL);
+      pthread_mutex_init(&fill_ul_mutex.harq_mutex,NULL);
+      pthread_mutex_init(&fill_ul_mutex.cqi_mutex,NULL);
+      pthread_mutex_init(&fill_ul_mutex.rach_mutex,NULL);
+    }
 
     LOG_I(MAC, "[MAIN] calling RRC\n");
     openair_rrc_top_init_ue(eMBMS_active, uecap_xer, cba_group_active,
diff --git a/openair2/LAYER2/MAC/pre_processor.c b/openair2/LAYER2/MAC/pre_processor.c
index 5846720c7f71a357a338631110853e708d33e4e7..142515d43189329fc281d13f71279cf61e944fae 100644
--- a/openair2/LAYER2/MAC/pre_processor.c
+++ b/openair2/LAYER2/MAC/pre_processor.c
@@ -68,12 +68,12 @@ int phy_stats_exist(module_id_t Mod_id, int rnti)
   UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list;
   if (UE_id == -1) {
     LOG_W(MAC, "[eNB %d] UE %x not found, should be there (in phy_stats_exist)\n",
-	  Mod_id, rnti);
+    Mod_id, rnti);
     return 0;
   }
   if (UE_list->numactiveCCs[UE_id] == 0) {
     LOG_W(MAC, "[eNB %d] UE %x has no active CC (in phy_stats_exist)\n",
-	  Mod_id, rnti);
+    Mod_id, rnti);
     return 0;
   }
   for (i = 0; i < UE_list->numactiveCCs[UE_id]; i++) {
@@ -91,7 +91,6 @@ store_dlsch_buffer(module_id_t Mod_id,
                    int slice_idx,
                    frame_t frameP,
                    sub_frame_t subframeP) {
-
   int UE_id, lcid;
   rnti_t rnti;
   mac_rlc_status_resp_t rlc_status;
@@ -100,13 +99,12 @@ store_dlsch_buffer(module_id_t Mod_id,
 
   for (UE_id = 0; UE_id < MAX_MOBILES_PER_ENB; UE_id++) {
     if (UE_list->active[UE_id] != TRUE)
-	    continue;
+      continue;
 
     if (!ue_dl_slice_membership(Mod_id, UE_id, slice_idx))
       continue;
 
     UE_template = &UE_list->UE_template[UE_PCCID(Mod_id, UE_id)][UE_id];
-
     // clear logical channel interface variables
     UE_template->dl_buffer_total = 0;
     UE_template->dl_pdus_total = 0;
@@ -121,25 +119,23 @@ store_dlsch_buffer(module_id_t Mod_id,
     rnti = UE_RNTI(Mod_id, UE_id);
 
     for (lcid = 0; lcid < MAX_NUM_LCID; ++lcid) {    // loop over all the logical channels
-
-	    rlc_status = mac_rlc_status_ind(Mod_id, rnti, Mod_id, frameP, subframeP,
-				   ENB_FLAG_YES, MBMS_FLAG_NO, lcid, 0
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-                   ,0, 0
-#endif
-                   );
+      rlc_status = mac_rlc_status_ind(Mod_id, rnti, Mod_id, frameP, subframeP,
+                                      ENB_FLAG_YES, MBMS_FLAG_NO, lcid, 0
+    #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                                      ,0, 0
+    #endif
+                                     );
       UE_template->dl_buffer_info[lcid] = rlc_status.bytes_in_buffer;    //storing the dlsch buffer for each logical channel
       UE_template->dl_pdus_in_buffer[lcid] = rlc_status.pdus_in_buffer;
       UE_template->dl_buffer_head_sdu_creation_time[lcid] = rlc_status.head_sdu_creation_time;
       UE_template->dl_buffer_head_sdu_creation_time_max =
-              cmax(UE_template->dl_buffer_head_sdu_creation_time_max, rlc_status.head_sdu_creation_time);
+        cmax(UE_template->dl_buffer_head_sdu_creation_time_max, rlc_status.head_sdu_creation_time);
       UE_template->dl_buffer_head_sdu_remaining_size_to_send[lcid] = rlc_status.head_sdu_remaining_size_to_send;
       UE_template->dl_buffer_head_sdu_is_segmented[lcid] = rlc_status.head_sdu_is_segmented;
       UE_template->dl_buffer_total += UE_template->dl_buffer_info[lcid];    //storing the total dlsch buffer
       UE_template->dl_pdus_total += UE_template->dl_pdus_in_buffer[lcid];
 
-#ifdef DEBUG_eNB_SCHEDULER
-
+      #ifdef DEBUG_eNB_SCHEDULER
       /* note for dl_buffer_head_sdu_remaining_size_to_send[lcid] :
        * 0 if head SDU has not been segmented (yet), else remaining size not already segmented and sent
        */
@@ -152,9 +148,7 @@ store_dlsch_buffer(module_id_t Mod_id,
               UE_template->dl_buffer_head_sdu_creation_time[lcid],
               UE_template->dl_buffer_head_sdu_remaining_size_to_send[lcid],
               UE_template->dl_buffer_head_sdu_is_segmented[lcid]);
-
-#endif
-
+      #endif
 
     }
 
@@ -178,11 +172,8 @@ assign_rbs_required(module_id_t Mod_id,
                     frame_t frameP,
                     sub_frame_t subframe,
                     uint16_t nb_rbs_required[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB],
-                    int min_rb_unit[NFAPI_CC_MAX])
-{
-
+                    int min_rb_unit[NFAPI_CC_MAX]) {
   uint16_t TBS = 0;
-
   int UE_id, n, i, j, CC_id, pCCid, tmp;
   UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list;
   slice_info_t *sli = &RC.mac[Mod_id]->slice_info;
@@ -192,25 +183,27 @@ assign_rbs_required(module_id_t Mod_id,
   // clear rb allocations across all CC_id
   for (UE_id = 0; UE_id < MAX_MOBILES_PER_ENB; UE_id++) {
     if (UE_list->active[UE_id] != TRUE) continue;
+
     if (!ue_dl_slice_membership(Mod_id, UE_id, slice_idx)) continue;
+
     pCCid = UE_PCCID(Mod_id, UE_id);
 
     //update CQI information across component carriers
     for (n = 0; n < UE_list->numactiveCCs[UE_id]; n++) {
-
       CC_id = UE_list->ordered_CCids[n][UE_id];
       eNB_UE_stats = &UE_list->eNB_UE_stats[CC_id][UE_id];
-//      eNB_UE_stats->dlsch_mcs1 = cmin(cqi_to_mcs[UE_list->UE_sched_ctrl[UE_id].dl_cqi[CC_id]], sli->dl[slice_idx].maxmcs);
+      //      eNB_UE_stats->dlsch_mcs1 = cmin(cqi_to_mcs[UE_list->UE_sched_ctrl[UE_id].dl_cqi[CC_id]], sli->dl[slice_idx].maxmcs);
       eNB_UE_stats->dlsch_mcs1 = cmin(cqi2mcs(UE_list->UE_sched_ctrl[UE_id].dl_cqi[CC_id]), sli->dl[slice_idx].maxmcs);
-
     }
 
     // provide the list of CCs sorted according to MCS
     for (i = 0; i < UE_list->numactiveCCs[UE_id]; ++i) {
       eNB_UE_stats_i = &UE_list->eNB_UE_stats[UE_list->ordered_CCids[i][UE_id]][UE_id];
+
       for (j = i + 1; j < UE_list->numactiveCCs[UE_id]; j++) {
         DevAssert(j < NFAPI_CC_MAX);
         eNB_UE_stats_j = &UE_list->eNB_UE_stats[UE_list->ordered_CCids[j][UE_id]][UE_id];
+
         if (eNB_UE_stats_j->dlsch_mcs1 > eNB_UE_stats_i->dlsch_mcs1) {
           tmp = UE_list->ordered_CCids[i][UE_id];
           UE_list->ordered_CCids[i][UE_id] = UE_list->ordered_CCids[j][UE_id];
@@ -233,18 +226,15 @@ assign_rbs_required(module_id_t Mod_id,
         }
 
         TBS = get_TBS_DL(eNB_UE_stats->dlsch_mcs1, nb_rbs_required[CC_id][UE_id]);
-
         LOG_D(MAC,
               "[preprocessor] start RB assignement for UE %d CC_id %d dl buffer %d (RB unit %d, MCS %d, TBS %d) \n",
               UE_id, CC_id,
               UE_list->UE_template[pCCid][UE_id].dl_buffer_total,
               nb_rbs_required[CC_id][UE_id],
               eNB_UE_stats->dlsch_mcs1, TBS);
-
         N_RB_DL = to_prb(RC.mac[Mod_id]->common_channels[CC_id].mib->message.dl_Bandwidth);
-
         UE_list->UE_sched_ctrl[UE_id].max_rbs_allowed_slice[CC_id][slice_idx] =
-                nb_rbs_allowed_slice(sli->dl[slice_idx].pct, N_RB_DL);
+          nb_rbs_allowed_slice(sli->dl[slice_idx].pct, N_RB_DL);
 
         /* calculating required number of RBs for each UE */
         while (TBS < UE_list->UE_template[pCCid][UE_id].dl_buffer_total) {
@@ -255,6 +245,7 @@ assign_rbs_required(module_id_t Mod_id,
             nb_rbs_required[CC_id][UE_id] = UE_list->UE_sched_ctrl[UE_id].max_rbs_allowed_slice[CC_id][slice_idx];
             break;
           }
+
           TBS = get_TBS_DL(eNB_UE_stats->dlsch_mcs1, nb_rbs_required[CC_id][UE_id]);
         } // end of while
 
@@ -263,7 +254,6 @@ assign_rbs_required(module_id_t Mod_id,
               Mod_id, frameP, UE_id, CC_id, min_rb_unit[CC_id],
               nb_rbs_required[CC_id][UE_id], TBS,
               eNB_UE_stats->dlsch_mcs1);
-
         sli->pre_processor_results[slice_idx].mcs[CC_id][UE_id] = eNB_UE_stats->dlsch_mcs1;
       }
     }
@@ -275,7 +265,6 @@ assign_rbs_required(module_id_t Mod_id,
 int
 maxround(module_id_t Mod_id, uint16_t rnti, int frame,
          sub_frame_t subframe, uint8_t ul_flag) {
-
   uint8_t round, round_max = 0, UE_id;
   int CC_id, harq_pid;
   UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list;
@@ -283,11 +272,10 @@ maxround(module_id_t Mod_id, uint16_t rnti, int frame,
 
   for (CC_id = 0; CC_id < RC.nb_mac_CC[Mod_id]; CC_id++) {
     cc = &RC.mac[Mod_id]->common_channels[CC_id];
-
     UE_id = find_UE_id(Mod_id, rnti);
-    harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frame ,subframe);
-
+    harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frame,subframe);
     round = UE_list->UE_sched_ctrl[UE_id].round[CC_id][harq_pid];
+
     if (round > round_max) {
       round_max = round;
     }
@@ -329,44 +317,39 @@ long min_lcgidpriority(module_id_t Mod_id, int32_t UE_id) {
 }
 
 struct sort_ue_dl_params {
-    int Mod_idP;
-    int frameP;
-    int subframeP;
-    int slice_idx;
+  int Mod_idP;
+  int frameP;
+  int subframeP;
+  int slice_idx;
 };
 
-static int ue_dl_compare(const void *_a, const void *_b, void *_params)
-{
+static int ue_dl_compare(const void *_a, const void *_b, void *_params) {
   struct sort_ue_dl_params *params = _params;
   UE_list_t *UE_list = &RC.mac[params->Mod_idP]->UE_list;
-
   int i;
   int slice_idx = params->slice_idx;
   int UE_id1 = *(const int *) _a;
   int UE_id2 = *(const int *) _b;
-
   int rnti1 = UE_RNTI(params->Mod_idP, UE_id1);
   int pCC_id1 = UE_PCCID(params->Mod_idP, UE_id1);
   int round1 = maxround(params->Mod_idP, rnti1, params->frameP, params->subframeP, 1);
-
   int rnti2 = UE_RNTI(params->Mod_idP, UE_id2);
   int pCC_id2 = UE_PCCID(params->Mod_idP, UE_id2);
   int round2 = maxround(params->Mod_idP, rnti2, params->frameP, params->subframeP, 1);
-
   int cqi1 = maxcqi(params->Mod_idP, UE_id1);
   int cqi2 = maxcqi(params->Mod_idP, UE_id2);
-
   long lcgid1 = min_lcgidpriority(params->Mod_idP, UE_id1);
   long lcgid2 = min_lcgidpriority(params->Mod_idP, UE_id2);
 
   for (i = 0; i < CR_NUM; ++i) {
     switch (UE_list->sorting_criteria[slice_idx][i]) {
-
       case CR_ROUND :
         if (round1 > round2)
           return -1;
+
         if (round1 < round2)
           return 1;
+
         break;
 
       case CR_SRB12 :
@@ -375,41 +358,50 @@ static int ue_dl_compare(const void *_a, const void *_b, void *_params)
             UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_info[1] +
             UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_info[2])
           return -1;
+
         if (UE_list->UE_template[pCC_id1][UE_id1].dl_buffer_info[1] +
             UE_list->UE_template[pCC_id1][UE_id1].dl_buffer_info[2] <
             UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_info[1] +
             UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_info[2])
           return 1;
+
         break;
 
       case CR_HOL :
         if (UE_list-> UE_template[pCC_id1][UE_id1].dl_buffer_head_sdu_creation_time_max >
             UE_list-> UE_template[pCC_id2][UE_id2].dl_buffer_head_sdu_creation_time_max)
           return -1;
+
         if (UE_list-> UE_template[pCC_id1][UE_id1].dl_buffer_head_sdu_creation_time_max <
             UE_list-> UE_template[pCC_id2][UE_id2].dl_buffer_head_sdu_creation_time_max)
           return 1;
+
         break;
 
       case CR_LC :
         if (UE_list->UE_template[pCC_id1][UE_id1].dl_buffer_total >
             UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_total)
           return -1;
+
         if (UE_list->UE_template[pCC_id1][UE_id1].dl_buffer_total <
             UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_total)
           return 1;
+
         break;
 
       case CR_CQI :
         if (cqi1 > cqi2)
           return -1;
+
         if (cqi1 < cqi2)
           return 1;
+
         break;
 
       case CR_LCP :
         if (lcgid1 < lcgid2)
           return -1;
+
         if (lcgid1 > lcgid2)
           return 1;
 
@@ -418,12 +410,11 @@ static int ue_dl_compare(const void *_a, const void *_b, void *_params)
     }
   }
 
-    return 0;
+  return 0;
 }
 
 void decode_sorting_policy(module_id_t Mod_idP, int slice_idx) {
   int i;
-
   UE_list_t *UE_list = &RC.mac[Mod_idP]->UE_list;
   uint32_t policy = RC.mac[Mod_idP]->slice_info.dl[slice_idx].sorting;
   uint32_t mask = 0x0000000F;
@@ -431,6 +422,7 @@ void decode_sorting_policy(module_id_t Mod_idP, int slice_idx) {
 
   for (i = 0; i < CR_NUM; ++i) {
     criterion = (uint16_t) (policy >> 4 * (CR_NUM - 1 - i) & mask);
+
     if (criterion >= CR_NUM) {
       LOG_W(MAC,
             "Invalid criterion in slice index %d ID %d policy, revert to default policy \n",
@@ -438,14 +430,14 @@ void decode_sorting_policy(module_id_t Mod_idP, int slice_idx) {
       RC.mac[Mod_idP]->slice_info.dl[slice_idx].sorting = 0x12345;
       break;
     }
+
     UE_list->sorting_criteria[slice_idx][i] = criterion;
   }
 }
 
 void decode_slice_positioning(module_id_t Mod_idP,
                               int slice_idx,
-                              uint8_t slice_allocation_mask[NFAPI_CC_MAX][N_RBG_MAX])
-{
+                              uint8_t slice_allocation_mask[NFAPI_CC_MAX][N_RBG_MAX]) {
   uint8_t CC_id;
   int RBG, start_frequency, end_frequency;
 
@@ -458,6 +450,7 @@ void decode_slice_positioning(module_id_t Mod_idP,
 
   start_frequency = RC.mac[Mod_idP]->slice_info.dl[slice_idx].pos_low;
   end_frequency = RC.mac[Mod_idP]->slice_info.dl[slice_idx].pos_high;
+
   for (CC_id = 0; CC_id < RC.nb_mac_CC[Mod_idP]; ++CC_id) {
     for (RBG = start_frequency; RBG <= end_frequency; ++RBG) {
       slice_allocation_mask[CC_id][RBG] = 1;
@@ -467,20 +460,20 @@ void decode_slice_positioning(module_id_t Mod_idP,
 
 
 // This fuction sorts the UE in order their dlsch buffer and CQI
-void sort_UEs(module_id_t Mod_idP, int slice_idx, int frameP, sub_frame_t subframeP)
-{
+void sort_UEs(module_id_t Mod_idP, int slice_idx, int frameP, sub_frame_t subframeP) {
   int i;
   int list[MAX_MOBILES_PER_ENB];
   int list_size = 0;
   struct sort_ue_dl_params params = {Mod_idP, frameP, subframeP, slice_idx};
-
   UE_list_t *UE_list = &RC.mac[Mod_idP]->UE_list;
 
   for (i = 0; i < MAX_MOBILES_PER_ENB; i++) {
-
     if (UE_list->active[i] == FALSE) continue;
+
     if (UE_RNTI(Mod_idP, i) == NOT_A_RNTI) continue;
+
     if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1) continue;
+
     if (!ue_dl_slice_membership(Mod_idP, i, slice_idx)) continue;
 
     list[list_size] = i;
@@ -488,12 +481,12 @@ void sort_UEs(module_id_t Mod_idP, int slice_idx, int frameP, sub_frame_t subfra
   }
 
   decode_sorting_policy(Mod_idP, slice_idx);
-
   qsort_r(list, list_size, sizeof(int), ue_dl_compare, &params);
 
   if (list_size) {
     for (i = 0; i < list_size - 1; ++i)
       UE_list->next[list[i]] = list[i + 1];
+
     UE_list->next[list[list_size - 1]] = -1;
     UE_list->head = list[0];
   } else {
@@ -502,18 +495,18 @@ void sort_UEs(module_id_t Mod_idP, int slice_idx, int frameP, sub_frame_t subfra
 }
 
 void dlsch_scheduler_pre_processor_partitioning(module_id_t Mod_id,
-                                                int slice_idx,
-                                                const uint8_t rbs_retx[NFAPI_CC_MAX])
-{
+    int slice_idx,
+    const uint8_t rbs_retx[NFAPI_CC_MAX]) {
   int UE_id, CC_id, N_RB_DL, i;
   UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list;
   UE_sched_ctrl *ue_sched_ctl;
   uint16_t available_rbs;
 
   for (UE_id = UE_list->head; UE_id >= 0; UE_id = UE_list->next[UE_id]) {
-
     if (UE_RNTI(Mod_id, UE_id) == NOT_A_RNTI) continue;
+
     if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync == 1) continue;
+
     if (!ue_dl_slice_membership(Mod_id, UE_id, slice_idx)) continue;
 
     ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
@@ -522,6 +515,7 @@ void dlsch_scheduler_pre_processor_partitioning(module_id_t Mod_id,
       CC_id = UE_list->ordered_CCids[i][UE_id];
       N_RB_DL = to_prb(RC.mac[Mod_id]->common_channels[CC_id].mib->message.dl_Bandwidth);
       available_rbs = nb_rbs_allowed_slice(RC.mac[Mod_id]->slice_info.dl[slice_idx].pct, N_RB_DL);
+
       if (rbs_retx[CC_id] < available_rbs)
         ue_sched_ctl->max_rbs_allowed_slice[CC_id][slice_idx] = available_rbs - rbs_retx[CC_id];
       else
@@ -531,16 +525,14 @@ void dlsch_scheduler_pre_processor_partitioning(module_id_t Mod_id,
 }
 
 void dlsch_scheduler_pre_processor_accounting(module_id_t Mod_id,
-                                              int slice_idx,
-                                              frame_t frameP,
-                                              sub_frame_t subframeP,
-                                              int min_rb_unit[NFAPI_CC_MAX],
-                                              uint16_t nb_rbs_required[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB],
-                                              uint16_t nb_rbs_accounted[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB])
-{
+    int slice_idx,
+    frame_t frameP,
+    sub_frame_t subframeP,
+    int min_rb_unit[NFAPI_CC_MAX],
+    uint16_t nb_rbs_required[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB],
+    uint16_t nb_rbs_accounted[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB]) {
   int UE_id, CC_id;
   int i;
-
   rnti_t rnti;
   uint8_t harq_pid, round;
   uint16_t available_rbs[NFAPI_CC_MAX];
@@ -550,7 +542,6 @@ void dlsch_scheduler_pre_processor_accounting(module_id_t Mod_id,
   int ue_count_newtx[NFAPI_CC_MAX];
   int ue_count_retx[NFAPI_CC_MAX];
   //uint8_t ue_retx_flag[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB];
-
   UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list;
   UE_sched_ctrl *ue_sched_ctl;
   COMMON_channels_t *cc;
@@ -571,15 +562,18 @@ void dlsch_scheduler_pre_processor_accounting(module_id_t Mod_id,
   // Find total UE count, and account the RBs required for retransmissions
   for (UE_id = UE_list->head; UE_id >= 0; UE_id = UE_list->next[UE_id]) {
     rnti = UE_RNTI(Mod_id, UE_id);
+
     if (rnti == NOT_A_RNTI) continue;
+
     if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync == 1) continue;
+
     if (!ue_dl_slice_membership(Mod_id, UE_id, slice_idx)) continue;
 
     for (i = 0; i < UE_num_active_CC(UE_list, UE_id); ++i) {
       CC_id = UE_list->ordered_CCids[i][UE_id];
       ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
       cc = &RC.mac[Mod_id]->common_channels[CC_id];
-      harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frameP ,subframeP);
+      harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frameP,subframeP);
       round = ue_sched_ctl->round[CC_id][harq_pid];
 
       if (nb_rbs_required[CC_id][UE_id] > 0) {
@@ -603,46 +597,53 @@ void dlsch_scheduler_pre_processor_accounting(module_id_t Mod_id,
 
   for (CC_id = 0; CC_id < RC.nb_mac_CC[Mod_id]; ++CC_id) {
     if (UE_list->head < 0) continue; // no UEs in list
-      // max_rbs_allowed_slice is saved in every UE, so take it from the first one
+
+    // max_rbs_allowed_slice is saved in every UE, so take it from the first one
     ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_list->head];
     available_rbs[CC_id] = ue_sched_ctl->max_rbs_allowed_slice[CC_id][slice_idx];
   }
 
   switch (RC.mac[Mod_id]->slice_info.dl[slice_idx].accounting) {
-
     // If greedy scheduling, try to account all the required RBs
     case POL_GREEDY:
-
       for (UE_id = UE_list->head; UE_id >= 0; UE_id = UE_list->next[UE_id]) {
         rnti = UE_RNTI(Mod_id, UE_id);
+
         if (rnti == NOT_A_RNTI) continue;
+
         if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync == 1) continue;
+
         if (!ue_dl_slice_membership(Mod_id, UE_id, slice_idx)) continue;
 
         for (i = 0; i < UE_num_active_CC(UE_list, UE_id); i++) {
           CC_id = UE_list->ordered_CCids[i][UE_id];
+
           if (available_rbs[CC_id] == 0) continue;
+
           nb_rbs_accounted[CC_id][UE_id] = cmin(nb_rbs_required[CC_id][UE_id], available_rbs[CC_id]);
           available_rbs[CC_id] -= nb_rbs_accounted[CC_id][UE_id];
         }
       }
+
       break;
 
     // Use the old, fair algorithm
     // Loop over all active UEs and account the avg number of RBs to each UE, based on all non-retx UEs.
     // case POL_FAIR:
     default:
+
       // FIXME: This is not ideal, why loop on UEs to find average_rbs_per_user[], that is per-CC?
       // TODO: Look how to loop on active CCs only without using the UE_num_active_CC() function.
       for (UE_id = UE_list->head; UE_id >= 0; UE_id = UE_list->next[UE_id]) {
         rnti = UE_RNTI(Mod_id, UE_id);
 
         if (rnti == NOT_A_RNTI) continue;
+
         if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync == 1) continue;
+
         if (!ue_dl_slice_membership(Mod_id, UE_id, slice_idx)) continue;
 
         for (i = 0; i < UE_num_active_CC(UE_list, UE_id); ++i) {
-
           CC_id = UE_list->ordered_CCids[i][UE_id];
           ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
           available_rbs[CC_id] = ue_sched_ctl->max_rbs_allowed_slice[CC_id][slice_idx];
@@ -662,8 +663,11 @@ void dlsch_scheduler_pre_processor_accounting(module_id_t Mod_id,
       // extend nb_rbs_required to capture per LCID RB required
       for (UE_id = UE_list->head; UE_id >= 0; UE_id = UE_list->next[UE_id]) {
         rnti = UE_RNTI(Mod_id, UE_id);
+
         if (rnti == NOT_A_RNTI) continue;
+
         if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync == 1) continue;
+
         if (!ue_dl_slice_membership(Mod_id, UE_id, slice_idx)) continue;
 
         for (i = 0; i < UE_num_active_CC(UE_list, UE_id); i++) {
@@ -671,25 +675,26 @@ void dlsch_scheduler_pre_processor_accounting(module_id_t Mod_id,
           nb_rbs_accounted[CC_id][UE_id] = cmin(average_rbs_per_user[CC_id], nb_rbs_required[CC_id][UE_id]);
         }
       }
+
       break;
   }
 
-
-
-
   // Check retransmissions
   // TODO: Do this once at the beginning
   for (UE_id = UE_list->head; UE_id >= 0; UE_id = UE_list->next[UE_id]) {
     rnti = UE_RNTI(Mod_id, UE_id);
+
     if (rnti == NOT_A_RNTI) continue;
+
     if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync == 1) continue;
+
     if (!ue_dl_slice_membership(Mod_id, UE_id, slice_idx)) continue;
 
     for (i = 0; i < UE_num_active_CC(UE_list, UE_id); i++) {
       CC_id = UE_list->ordered_CCids[i][UE_id];
       ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
       cc = &RC.mac[Mod_id]->common_channels[CC_id];
-      harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frameP ,subframeP);
+      harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frameP,subframeP);
       round = ue_sched_ctl->round[CC_id][harq_pid];
 
       // control channel or retransmission
@@ -702,23 +707,23 @@ void dlsch_scheduler_pre_processor_accounting(module_id_t Mod_id,
 }
 
 void dlsch_scheduler_pre_processor_positioning(module_id_t Mod_id,
-                                               int slice_idx,
-                                               int min_rb_unit[NFAPI_CC_MAX],
-                                               uint16_t nb_rbs_required[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB],
-                                               uint16_t nb_rbs_accounted[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB],
-                                               uint16_t nb_rbs_remaining[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB],
-                                               uint8_t rballoc_sub[NFAPI_CC_MAX][N_RBG_MAX],
-                                               uint8_t MIMO_mode_indicator[NFAPI_CC_MAX][N_RBG_MAX])
-{
+    int slice_idx,
+    int min_rb_unit[NFAPI_CC_MAX],
+    uint16_t nb_rbs_required[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB],
+    uint16_t nb_rbs_accounted[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB],
+    uint16_t nb_rbs_remaining[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB],
+    uint8_t rballoc_sub[NFAPI_CC_MAX][N_RBG_MAX],
+    uint8_t MIMO_mode_indicator[NFAPI_CC_MAX][N_RBG_MAX]) {
   int UE_id, CC_id;
   int i;
-#ifdef TM5
+
+  #ifdef TM5
   uint8_t transmission_mode;
-#endif
+  #endif
+
   uint8_t slice_allocation_mask[NFAPI_CC_MAX][N_RBG_MAX];
   int N_RBG[NFAPI_CC_MAX];
   UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list;
-
   decode_slice_positioning(Mod_id, slice_idx, slice_allocation_mask);
 
   for (CC_id = 0; CC_id < RC.nb_mac_CC[Mod_id]; CC_id++) {
@@ -728,17 +733,19 @@ void dlsch_scheduler_pre_processor_positioning(module_id_t Mod_id,
 
   // Try to allocate accounted RBs
   for (UE_id = UE_list->head; UE_id >= 0; UE_id = UE_list->next[UE_id]) {
-
     if (UE_RNTI(Mod_id, UE_id) == NOT_A_RNTI) continue;
+
     if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync == 1) continue;
+
     if (!ue_dl_slice_membership(Mod_id, UE_id, slice_idx)) continue;
 
     for (i = 0; i < UE_num_active_CC(UE_list, UE_id); i++) {
       CC_id = UE_list->ordered_CCids[i][UE_id];
       nb_rbs_remaining[CC_id][UE_id] = nb_rbs_accounted[CC_id][UE_id];
-#ifdef TM5
+
+      #ifdef TM5
       transmission_mode = get_tmode(Mod_id, CC_id, UE_id);
-#endif
+      #endif
 
       if (nb_rbs_required[CC_id][UE_id] > 0)
         LOG_D(MAC,
@@ -764,191 +771,183 @@ void dlsch_scheduler_pre_processor_positioning(module_id_t Mod_id,
                                              slice_allocation_mask,
                                              MIMO_mode_indicator);
 
-#ifdef TM5
+      #ifdef TM5
       // data chanel TM5: to be revisited
-        if ((round == 0) &&
-        (transmission_mode == 5) &&
-        (ue_sched_ctl->dl_pow_off[CC_id] != 1)) {
-
+      if ((round == 0) &&
+          (transmission_mode == 5) &&
+          (ue_sched_ctl->dl_pow_off[CC_id] != 1)) {
         for (j = 0; j < N_RBG[CC_id]; j += 2) {
-
-            if ((((j == (N_RBG[CC_id] - 1))
-              && (rballoc_sub[CC_id][j] == 0)
-              && (ue_sched_ctl->
-                  rballoc_sub_UE[CC_id][j] == 0))
-             || ((j < (N_RBG[CC_id] - 1))
-                 && (rballoc_sub[CC_id][j + 1] == 0)
-                 &&
-                 (ue_sched_ctl->rballoc_sub_UE
-                  [CC_id][j + 1] == 0)))
-            && (nb_rbs_remaining[CC_id][UE_id]
-                > 0)) {
-
+          if ((((j == (N_RBG[CC_id] - 1))
+                && (rballoc_sub[CC_id][j] == 0)
+                && (ue_sched_ctl->
+                    rballoc_sub_UE[CC_id][j] == 0))
+               || ((j < (N_RBG[CC_id] - 1))
+                   && (rballoc_sub[CC_id][j + 1] == 0)
+                   &&
+                   (ue_sched_ctl->rballoc_sub_UE
+                    [CC_id][j + 1] == 0)))
+              && (nb_rbs_remaining[CC_id][UE_id]
+                  > 0)) {
             for (i = UE_list->next[UE_id + 1]; i >= 0;
                  i = UE_list->next[i]) {
-
-                UE_id2 = i;
-                rnti2 = UE_RNTI(Mod_id, UE_id2);
-                ue_sched_ctl2 =
+              UE_id2 = i;
+              rnti2 = UE_RNTI(Mod_id, UE_id2);
+              ue_sched_ctl2 =
                 &UE_list->UE_sched_ctrl[UE_id2];
-                round2 = ue_sched_ctl2->round[CC_id];
-                if (rnti2 == NOT_A_RNTI)
+              round2 = ue_sched_ctl2->round[CC_id];
+
+              if (rnti2 == NOT_A_RNTI)
                 continue;
-                if (UE_list->
-                UE_sched_ctrl
-                [UE_id2].ul_out_of_sync == 1)
+
+              if (UE_list->
+                  UE_sched_ctrl
+                  [UE_id2].ul_out_of_sync == 1)
                 continue;
 
-                eNB_UE_stats2 =
+              eNB_UE_stats2 =
                 UE_list->
                 eNB_UE_stats[CC_id][UE_id2];
-                //mac_xface->get_ue_active_harq_pid(Mod_id,CC_id,rnti2,frameP,subframeP,&harq_pid2,&round2,0);
-
-                if ((mac_eNB_get_rrc_status
-                 (Mod_id,
-                  rnti2) >= RRC_RECONFIGURED)
-                && (round2 == 0)
-                &&
-                (get_tmode(Mod_id, CC_id, UE_id2)
-                 == 5)
-                && (ue_sched_ctl->
-                    dl_pow_off[CC_id] != 1)) {
+              //mac_xface->get_ue_active_harq_pid(Mod_id,CC_id,rnti2,frameP,subframeP,&harq_pid2,&round2,0);
 
+              if ((mac_eNB_get_rrc_status
+                   (Mod_id,
+                    rnti2) >= RRC_RECONFIGURED)
+                  && (round2 == 0)
+                  &&
+                  (get_tmode(Mod_id, CC_id, UE_id2)
+                   == 5)
+                  && (ue_sched_ctl->
+                      dl_pow_off[CC_id] != 1)) {
                 if ((((j == (N_RBG[CC_id] - 1))
                       &&
                       (ue_sched_ctl->rballoc_sub_UE
                        [CC_id][j] == 0))
                      || ((j < (N_RBG[CC_id] - 1))
-                     &&
-                     (ue_sched_ctl->
-                      rballoc_sub_UE[CC_id][j +
-                                1]
-                      == 0)))
+                         &&
+                         (ue_sched_ctl->
+                          rballoc_sub_UE[CC_id][j +
+                                                1]
+                          == 0)))
                     &&
                     (nb_rbs_remaining
                      [CC_id]
                      [UE_id2] > 0)) {
-
-                    if ((((eNB_UE_stats2->
-                       DL_pmi_single ^
-                       eNB_UE_stats1->
-                       DL_pmi_single)
-                      << (14 - j)) & 0xc000) == 0x4000) {	//MU-MIMO only for 25 RBs configuration
-
+                  if ((((eNB_UE_stats2->
+                         DL_pmi_single ^
+                         eNB_UE_stats1->
+                         DL_pmi_single)
+                        << (14 - j)) & 0xc000) == 0x4000) { //MU-MIMO only for 25 RBs configuration
                     rballoc_sub[CC_id][j] = 1;
                     ue_sched_ctl->
-                        rballoc_sub_UE[CC_id]
-                        [j] = 1;
+                    rballoc_sub_UE[CC_id]
+                    [j] = 1;
                     ue_sched_ctl2->
-                        rballoc_sub_UE[CC_id]
-                        [j] = 1;
+                    rballoc_sub_UE[CC_id]
+                    [j] = 1;
                     MIMO_mode_indicator[CC_id]
-                        [j] = 0;
+                    [j] = 0;
 
                     if (j < N_RBG[CC_id] - 1) {
-                        rballoc_sub[CC_id][j +
-                                   1] =
-                        1;
-                        ue_sched_ctl->
-                        rballoc_sub_UE
-                        [CC_id][j + 1] = 1;
-                        ue_sched_ctl2->rballoc_sub_UE
-                        [CC_id][j + 1] = 1;
-                        MIMO_mode_indicator
-                        [CC_id][j + 1]
+                      rballoc_sub[CC_id][j +
+                                         1] =
+                                           1;
+                      ue_sched_ctl->
+                      rballoc_sub_UE
+                      [CC_id][j + 1] = 1;
+                      ue_sched_ctl2->rballoc_sub_UE
+                      [CC_id][j + 1] = 1;
+                      MIMO_mode_indicator
+                      [CC_id][j + 1]
                         = 0;
                     }
 
                     ue_sched_ctl->
-                        dl_pow_off[CC_id]
-                        = 0;
+                    dl_pow_off[CC_id]
+                      = 0;
                     ue_sched_ctl2->
-                        dl_pow_off[CC_id]
-                        = 0;
-
+                    dl_pow_off[CC_id]
+                      = 0;
 
                     if ((j == N_RBG[CC_id] - 1)
                         && ((N_RB_DL == 25)
-                        || (N_RB_DL ==
-                            50))) {
-
-                        nb_rbs_remaining
-                        [CC_id][UE_id] =
+                            || (N_RB_DL ==
+                                50))) {
+                      nb_rbs_remaining
+                      [CC_id][UE_id] =
                         nb_rbs_remaining
                         [CC_id][UE_id] -
                         min_rb_unit[CC_id]
                         + 1;
-                        ue_sched_ctl->pre_nb_available_rbs
-                        [CC_id] =
+                      ue_sched_ctl->pre_nb_available_rbs
+                      [CC_id] =
                         ue_sched_ctl->pre_nb_available_rbs
                         [CC_id] +
                         min_rb_unit[CC_id]
                         - 1;
-                        nb_rbs_remaining
-                        [CC_id][UE_id2] =
+                      nb_rbs_remaining
+                      [CC_id][UE_id2] =
                         nb_rbs_remaining
                         [CC_id][UE_id2] -
                         min_rb_unit[CC_id]
                         + 1;
-                        ue_sched_ctl2->pre_nb_available_rbs
-                        [CC_id] =
+                      ue_sched_ctl2->pre_nb_available_rbs
+                      [CC_id] =
                         ue_sched_ctl2->pre_nb_available_rbs
                         [CC_id] +
                         min_rb_unit[CC_id]
                         - 1;
                     } else {
-
-                        nb_rbs_remaining
-                        [CC_id][UE_id] =
+                      nb_rbs_remaining
+                      [CC_id][UE_id] =
                         nb_rbs_remaining
                         [CC_id][UE_id] - 4;
-                        ue_sched_ctl->pre_nb_available_rbs
-                        [CC_id] =
+                      ue_sched_ctl->pre_nb_available_rbs
+                      [CC_id] =
                         ue_sched_ctl->pre_nb_available_rbs
                         [CC_id] + 4;
-                        nb_rbs_remaining
-                        [CC_id][UE_id2] =
+                      nb_rbs_remaining
+                      [CC_id][UE_id2] =
                         nb_rbs_remaining
                         [CC_id][UE_id2] -
                         4;
-                        ue_sched_ctl2->pre_nb_available_rbs
-                        [CC_id] =
+                      ue_sched_ctl2->pre_nb_available_rbs
+                      [CC_id] =
                         ue_sched_ctl2->pre_nb_available_rbs
                         [CC_id] + 4;
                     }
-
                     break;
-                    }
-                }
+                  }
                 }
+              }
             }
-            }
-        }
+          }
         }
-#endif
+      }
+      #endif
+
     }
   }
 }
 
 void dlsch_scheduler_pre_processor_intraslice_sharing(module_id_t Mod_id,
-                                                      int slice_idx,
-                                                      int min_rb_unit[NFAPI_CC_MAX],
-                                                      uint16_t nb_rbs_required[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB],
-                                                      uint16_t nb_rbs_accounted[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB],
-                                                      uint16_t nb_rbs_remaining[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB],
-                                                      uint8_t rballoc_sub[NFAPI_CC_MAX][N_RBG_MAX],
-                                                      uint8_t MIMO_mode_indicator[NFAPI_CC_MAX][N_RBG_MAX])
-{
+    int slice_idx,
+    int min_rb_unit[NFAPI_CC_MAX],
+    uint16_t nb_rbs_required[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB],
+    uint16_t nb_rbs_accounted[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB],
+    uint16_t nb_rbs_remaining[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB],
+    uint8_t rballoc_sub[NFAPI_CC_MAX][N_RBG_MAX],
+    uint8_t MIMO_mode_indicator[NFAPI_CC_MAX][N_RBG_MAX]) {
   int UE_id, CC_id;
   int i;
-#ifdef TM5
+
+  #ifdef TM5
   uint8_t transmission_mode;
-#endif
+  #endif
+
   UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list;
   int N_RBG[NFAPI_CC_MAX];
   slice_info_t *sli = &RC.mac[Mod_id]->slice_info;
   uint8_t (*slice_allocation_mask)[N_RBG_MAX] = sli->pre_processor_results[slice_idx].slice_allocation_mask;
-
   decode_slice_positioning(Mod_id, slice_idx, slice_allocation_mask);
 
   for (CC_id = 0; CC_id < RC.nb_mac_CC[Mod_id]; CC_id++) {
@@ -958,20 +957,23 @@ void dlsch_scheduler_pre_processor_intraslice_sharing(module_id_t Mod_id,
 
   // Remaining RBs are allocated to high priority UEs
   for (UE_id = UE_list->head; UE_id >= 0; UE_id = UE_list->next[UE_id]) {
-
     if (UE_RNTI(Mod_id, UE_id) == NOT_A_RNTI) continue;
+
     if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync == 1) continue;
+
     if (!ue_dl_slice_membership(Mod_id, UE_id, slice_idx)) continue;
 
     for (i = 0; i < UE_num_active_CC(UE_list, UE_id); i++) {
       CC_id = UE_list->ordered_CCids[i][UE_id];
       nb_rbs_remaining[CC_id][UE_id] =
-              nb_rbs_required[CC_id][UE_id] - nb_rbs_accounted[CC_id][UE_id] + nb_rbs_remaining[CC_id][UE_id];
+        nb_rbs_required[CC_id][UE_id] - nb_rbs_accounted[CC_id][UE_id] + nb_rbs_remaining[CC_id][UE_id];
+
       if (nb_rbs_remaining[CC_id][UE_id] < 0)
         abort();
-#ifdef TM5
+
+      #ifdef TM5
       transmission_mode = get_tmode(Mod_id, CC_id, UE_id);
-#endif
+      #endif
 
       if (nb_rbs_required[CC_id][UE_id] > 0)
         LOG_D(MAC,
@@ -997,168 +999,161 @@ void dlsch_scheduler_pre_processor_intraslice_sharing(module_id_t Mod_id,
                                              slice_allocation_mask,
                                              MIMO_mode_indicator);
 
-#ifdef TM5
+      #ifdef TM5
       // data chanel TM5: to be revisited
-    if ((round == 0) &&
-    (transmission_mode == 5) &&
-    (ue_sched_ctl->dl_pow_off[CC_id] != 1)) {
-
-    for (j = 0; j < N_RBG[CC_id]; j += 2) {
-
-        if ((((j == (N_RBG[CC_id] - 1))
-          && (rballoc_sub[CC_id][j] == 0)
-          && (ue_sched_ctl->
-              rballoc_sub_UE[CC_id][j] == 0))
-         || ((j < (N_RBG[CC_id] - 1))
-             && (rballoc_sub[CC_id][j + 1] == 0)
-             &&
-             (ue_sched_ctl->rballoc_sub_UE
-              [CC_id][j + 1] == 0)))
-        && (nb_rbs_remaining[CC_id][UE_id]
-            > 0)) {
-
-        for (i = UE_list->next[UE_id + 1]; i >= 0;
-             i = UE_list->next[i]) {
-
-            UE_id2 = i;
-            rnti2 = UE_RNTI(Mod_id, UE_id2);
-            ue_sched_ctl2 =
-            &UE_list->UE_sched_ctrl[UE_id2];
-            round2 = ue_sched_ctl2->round[CC_id];
-            if (rnti2 == NOT_A_RNTI)
-            continue;
-            if (UE_list->
-            UE_sched_ctrl
-            [UE_id2].ul_out_of_sync == 1)
-            continue;
-
-            eNB_UE_stats2 =
-            UE_list->
-            eNB_UE_stats[CC_id][UE_id2];
-            //mac_xface->get_ue_active_harq_pid(Mod_id,CC_id,rnti2,frameP,subframeP,&harq_pid2,&round2,0);
-
-            if ((mac_eNB_get_rrc_status
-             (Mod_id,
-              rnti2) >= RRC_RECONFIGURED)
-            && (round2 == 0)
-            &&
-            (get_tmode(Mod_id, CC_id, UE_id2)
-             == 5)
-            && (ue_sched_ctl->
-                dl_pow_off[CC_id] != 1)) {
-
-            if ((((j == (N_RBG[CC_id] - 1))
+      if ((round == 0) &&
+          (transmission_mode == 5) &&
+          (ue_sched_ctl->dl_pow_off[CC_id] != 1)) {
+        for (j = 0; j < N_RBG[CC_id]; j += 2) {
+          if ((((j == (N_RBG[CC_id] - 1))
+                && (rballoc_sub[CC_id][j] == 0)
+                && (ue_sched_ctl->
+                    rballoc_sub_UE[CC_id][j] == 0))
+               || ((j < (N_RBG[CC_id] - 1))
+                   && (rballoc_sub[CC_id][j + 1] == 0)
+                   &&
+                   (ue_sched_ctl->rballoc_sub_UE
+                    [CC_id][j + 1] == 0)))
+              && (nb_rbs_remaining[CC_id][UE_id]
+                  > 0)) {
+            for (i = UE_list->next[UE_id + 1]; i >= 0;
+                 i = UE_list->next[i]) {
+              UE_id2 = i;
+              rnti2 = UE_RNTI(Mod_id, UE_id2);
+              ue_sched_ctl2 =
+                &UE_list->UE_sched_ctrl[UE_id2];
+              round2 = ue_sched_ctl2->round[CC_id];
+
+              if (rnti2 == NOT_A_RNTI)
+                continue;
+
+              if (UE_list->
+                  UE_sched_ctrl
+                  [UE_id2].ul_out_of_sync == 1)
+                continue;
+
+              eNB_UE_stats2 =
+                UE_list->
+                eNB_UE_stats[CC_id][UE_id2];
+              //mac_xface->get_ue_active_harq_pid(Mod_id,CC_id,rnti2,frameP,subframeP,&harq_pid2,&round2,0);
+
+              if ((mac_eNB_get_rrc_status
+                   (Mod_id,
+                    rnti2) >= RRC_RECONFIGURED)
+                  && (round2 == 0)
                   &&
-                  (ue_sched_ctl->rballoc_sub_UE
-                   [CC_id][j] == 0))
-                 || ((j < (N_RBG[CC_id] - 1))
-                 &&
-                 (ue_sched_ctl->
-                  rballoc_sub_UE[CC_id][j +
-                            1]
-                  == 0)))
-                &&
-                (nb_rbs_remaining
-                 [CC_id]
-                 [UE_id2] > 0)) {
-
-                if ((((eNB_UE_stats2->
-                   DL_pmi_single ^
-                   eNB_UE_stats1->
-                   DL_pmi_single)
-                  << (14 - j)) & 0xc000) == 0x4000) {	//MU-MIMO only for 25 RBs configuration
-
-                rballoc_sub[CC_id][j] = 1;
-                ue_sched_ctl->
+                  (get_tmode(Mod_id, CC_id, UE_id2)
+                   == 5)
+                  && (ue_sched_ctl->
+                      dl_pow_off[CC_id] != 1)) {
+                if ((((j == (N_RBG[CC_id] - 1))
+                      &&
+                      (ue_sched_ctl->rballoc_sub_UE
+                       [CC_id][j] == 0))
+                     || ((j < (N_RBG[CC_id] - 1))
+                         &&
+                         (ue_sched_ctl->
+                          rballoc_sub_UE[CC_id][j +
+                                                1]
+                          == 0)))
+                    &&
+                    (nb_rbs_remaining
+                     [CC_id]
+                     [UE_id2] > 0)) {
+                  if ((((eNB_UE_stats2->
+                         DL_pmi_single ^
+                         eNB_UE_stats1->
+                         DL_pmi_single)
+                        << (14 - j)) & 0xc000) == 0x4000) { //MU-MIMO only for 25 RBs configuration
+                    rballoc_sub[CC_id][j] = 1;
+                    ue_sched_ctl->
                     rballoc_sub_UE[CC_id]
                     [j] = 1;
-                ue_sched_ctl2->
+                    ue_sched_ctl2->
                     rballoc_sub_UE[CC_id]
                     [j] = 1;
-                MIMO_mode_indicator[CC_id]
+                    MIMO_mode_indicator[CC_id]
                     [j] = 0;
 
-                if (j < N_RBG[CC_id] - 1) {
-                    rballoc_sub[CC_id][j +
-                               1] =
-                    1;
-                    ue_sched_ctl->
-                    rballoc_sub_UE
-                    [CC_id][j + 1] = 1;
-                    ue_sched_ctl2->rballoc_sub_UE
-                    [CC_id][j + 1] = 1;
-                    MIMO_mode_indicator
-                    [CC_id][j + 1]
-                    = 0;
-                }
+                    if (j < N_RBG[CC_id] - 1) {
+                      rballoc_sub[CC_id][j +
+                                         1] =
+                                           1;
+                      ue_sched_ctl->
+                      rballoc_sub_UE
+                      [CC_id][j + 1] = 1;
+                      ue_sched_ctl2->rballoc_sub_UE
+                      [CC_id][j + 1] = 1;
+                      MIMO_mode_indicator
+                      [CC_id][j + 1]
+                        = 0;
+                    }
 
-                ue_sched_ctl->
+                    ue_sched_ctl->
                     dl_pow_off[CC_id]
-                    = 0;
-                ue_sched_ctl2->
+                      = 0;
+                    ue_sched_ctl2->
                     dl_pow_off[CC_id]
-                    = 0;
-
-
-                if ((j == N_RBG[CC_id] - 1)
-                    && ((N_RB_DL == 25)
-                    || (N_RB_DL ==
-                        50))) {
-
-                    nb_rbs_remaining
-                    [CC_id][UE_id] =
-                    nb_rbs_remaining
-                    [CC_id][UE_id] -
-                    min_rb_unit[CC_id]
-                    + 1;
-                    ue_sched_ctl->pre_nb_available_rbs
-                    [CC_id] =
-                    ue_sched_ctl->pre_nb_available_rbs
-                    [CC_id] +
-                    min_rb_unit[CC_id]
-                    - 1;
-                    nb_rbs_remaining
-                    [CC_id][UE_id2] =
-                    nb_rbs_remaining
-                    [CC_id][UE_id2] -
-                    min_rb_unit[CC_id]
-                    + 1;
-                    ue_sched_ctl2->pre_nb_available_rbs
-                    [CC_id] =
-                    ue_sched_ctl2->pre_nb_available_rbs
-                    [CC_id] +
-                    min_rb_unit[CC_id]
-                    - 1;
-                } else {
-
-                    nb_rbs_remaining
-                    [CC_id][UE_id] =
-                    nb_rbs_remaining
-                    [CC_id][UE_id] - 4;
-                    ue_sched_ctl->pre_nb_available_rbs
-                    [CC_id] =
-                    ue_sched_ctl->pre_nb_available_rbs
-                    [CC_id] + 4;
-                    nb_rbs_remaining
-                    [CC_id][UE_id2] =
-                    nb_rbs_remaining
-                    [CC_id][UE_id2] -
-                    4;
-                    ue_sched_ctl2->pre_nb_available_rbs
-                    [CC_id] =
-                    ue_sched_ctl2->pre_nb_available_rbs
-                    [CC_id] + 4;
-                }
+                      = 0;
+
+                    if ((j == N_RBG[CC_id] - 1)
+                        && ((N_RB_DL == 25)
+                            || (N_RB_DL ==
+                                50))) {
+                      nb_rbs_remaining
+                      [CC_id][UE_id] =
+                        nb_rbs_remaining
+                        [CC_id][UE_id] -
+                        min_rb_unit[CC_id]
+                        + 1;
+                      ue_sched_ctl->pre_nb_available_rbs
+                      [CC_id] =
+                        ue_sched_ctl->pre_nb_available_rbs
+                        [CC_id] +
+                        min_rb_unit[CC_id]
+                        - 1;
+                      nb_rbs_remaining
+                      [CC_id][UE_id2] =
+                        nb_rbs_remaining
+                        [CC_id][UE_id2] -
+                        min_rb_unit[CC_id]
+                        + 1;
+                      ue_sched_ctl2->pre_nb_available_rbs
+                      [CC_id] =
+                        ue_sched_ctl2->pre_nb_available_rbs
+                        [CC_id] +
+                        min_rb_unit[CC_id]
+                        - 1;
+                    } else {
+                      nb_rbs_remaining
+                      [CC_id][UE_id] =
+                        nb_rbs_remaining
+                        [CC_id][UE_id] - 4;
+                      ue_sched_ctl->pre_nb_available_rbs
+                      [CC_id] =
+                        ue_sched_ctl->pre_nb_available_rbs
+                        [CC_id] + 4;
+                      nb_rbs_remaining
+                      [CC_id][UE_id2] =
+                        nb_rbs_remaining
+                        [CC_id][UE_id2] -
+                        4;
+                      ue_sched_ctl2->pre_nb_available_rbs
+                      [CC_id] =
+                        ue_sched_ctl2->pre_nb_available_rbs
+                        [CC_id] + 4;
+                    }
 
-                break;
+                    break;
+                  }
                 }
+              }
             }
-            }
-        }
+          }
         }
-    }
-    }
-#endif
+      }
+      #endif
+
     }
   }
 }
@@ -1170,24 +1165,19 @@ dlsch_scheduler_pre_processor(module_id_t Mod_id,
                               frame_t frameP,
                               sub_frame_t subframeP,
                               int *mbsfn_flag,
-                              uint8_t rballoc_sub[NFAPI_CC_MAX][N_RBG_MAX])
-{
+                              uint8_t rballoc_sub[NFAPI_CC_MAX][N_RBG_MAX]) {
   int UE_id;
   uint8_t CC_id;
   uint16_t i, j;
-
   int min_rb_unit[NFAPI_CC_MAX];
-
   slice_info_t *sli = &RC.mac[Mod_id]->slice_info;
   uint16_t (*nb_rbs_required)[MAX_MOBILES_PER_ENB]  = sli->pre_processor_results[slice_idx].nb_rbs_required;
   uint16_t (*nb_rbs_accounted)[MAX_MOBILES_PER_ENB] = sli->pre_processor_results[slice_idx].nb_rbs_accounted;
   uint16_t (*nb_rbs_remaining)[MAX_MOBILES_PER_ENB] = sli->pre_processor_results[slice_idx].nb_rbs_remaining;
   uint8_t  (*MIMO_mode_indicator)[N_RBG_MAX]     = sli->pre_processor_results[slice_idx].MIMO_mode_indicator;
-
   UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list;
   UE_sched_ctrl *ue_sched_ctl;
-//  int rrc_status = RRC_IDLE;
-
+  //  int rrc_status = RRC_IDLE;
 #ifdef TM5
   int harq_pid1 = 0;
   int round1 = 0, round2 = 0;
@@ -1198,7 +1188,6 @@ dlsch_scheduler_pre_processor(module_id_t Mod_id,
   LTE_eNB_UE_stats *eNB_UE_stats2 = NULL;
   UE_sched_ctrl *ue_sched_ctl1, *ue_sched_ctl2;
 #endif
-
   // Initialize scheduling information for all active UEs
   memset(&sli->pre_processor_results[slice_idx], 0, sizeof(sli->pre_processor_results[slice_idx]));
   // FIXME: After the memset above, some of the resets in reset() are redundant
@@ -1208,46 +1197,43 @@ dlsch_scheduler_pre_processor(module_id_t Mod_id,
                                       rballoc_sub,
                                       MIMO_mode_indicator,
                                       mbsfn_flag); // FIXME: Not sure if useful
-
   // STATUS
   // Store the DLSCH buffer for each logical channel
   store_dlsch_buffer(Mod_id, slice_idx, frameP, subframeP);
-
   // Calculate the number of RBs required by each UE on the basis of logical channel's buffer
   assign_rbs_required(Mod_id, slice_idx, frameP, subframeP, nb_rbs_required, min_rb_unit);
-
   // Sorts the user on the basis of dlsch logical channel buffer and CQI
   sort_UEs(Mod_id, slice_idx, frameP, subframeP);
-
   // ACCOUNTING
   // This procedure decides the number of RBs to allocate
   dlsch_scheduler_pre_processor_accounting(Mod_id, slice_idx, frameP, subframeP,
-                                           min_rb_unit,
-                                           nb_rbs_required,
-                                           nb_rbs_accounted);
+      min_rb_unit,
+      nb_rbs_required,
+      nb_rbs_accounted);
   // POSITIONING
   // This procedure does the main allocation of the RBs
   dlsch_scheduler_pre_processor_positioning(Mod_id, slice_idx,
-                                            min_rb_unit,
-                                            nb_rbs_required,
-                                            nb_rbs_accounted,
-                                            nb_rbs_remaining,
-                                            rballoc_sub,
-                                            MIMO_mode_indicator);
+      min_rb_unit,
+      nb_rbs_required,
+      nb_rbs_accounted,
+      nb_rbs_remaining,
+      rballoc_sub,
+      MIMO_mode_indicator);
 
   // SHARING
   // If there are available RBs left in the slice, allocate them to the highest priority UEs
   if (RC.mac[Mod_id]->slice_info.intraslice_share_active) {
     dlsch_scheduler_pre_processor_intraslice_sharing(Mod_id, slice_idx,
-                                                     min_rb_unit,
-                                                     nb_rbs_required,
-                                                     nb_rbs_accounted,
-                                                     nb_rbs_remaining,
-                                                     rballoc_sub,
-                                                     MIMO_mode_indicator);
+        min_rb_unit,
+        nb_rbs_required,
+        nb_rbs_accounted,
+        nb_rbs_remaining,
+        rballoc_sub,
+        MIMO_mode_indicator);
   }
 
 #ifdef TM5
+
   // This has to be revisited!!!!
   for (CC_id = 0; CC_id < RC.nb_mac_CC[Mod_id]; CC_id++) {
     COMMON_channels_t *cc = &RC.mac[Mod_id]->common_channels[CC_id];
@@ -1258,42 +1244,42 @@ dlsch_scheduler_pre_processor(module_id_t Mod_id,
 
     for (j = 0; j < N_RBG; j++) {
       if (MIMO_mode_indicator[CC_id][j] == 2) {
-      i1 = i1 + 1;
+        i1 = i1 + 1;
       } else if (MIMO_mode_indicator[CC_id][j] == 1) {
-      i2 = i2 + 1;
+        i2 = i2 + 1;
       } else if (MIMO_mode_indicator[CC_id][j] == 0) {
-      i3 = i3 + 1;
+        i3 = i3 + 1;
       }
     }
 
     if ((i1 < N_RBG) && (i2 > 0) && (i3 == 0)) {
       PHY_vars_eNB_g[Mod_id][CC_id]->check_for_SUMIMO_transmissions =
-      PHY_vars_eNB_g[Mod_id][CC_id]->
-      check_for_SUMIMO_transmissions + 1;
+        PHY_vars_eNB_g[Mod_id][CC_id]->
+        check_for_SUMIMO_transmissions + 1;
     }
 
     if (i3 == N_RBG && i1 == 0 && i2 == 0) {
       PHY_vars_eNB_g[Mod_id][CC_id]->FULL_MUMIMO_transmissions =
-      PHY_vars_eNB_g[Mod_id][CC_id]->FULL_MUMIMO_transmissions +
-      1;
+        PHY_vars_eNB_g[Mod_id][CC_id]->FULL_MUMIMO_transmissions +
+        1;
     }
 
     if ((i1 < N_RBG) && (i3 > 0)) {
       PHY_vars_eNB_g[Mod_id][CC_id]->check_for_MUMIMO_transmissions =
-      PHY_vars_eNB_g[Mod_id][CC_id]->
-      check_for_MUMIMO_transmissions + 1;
+        PHY_vars_eNB_g[Mod_id][CC_id]->
+        check_for_MUMIMO_transmissions + 1;
     }
 
     PHY_vars_eNB_g[Mod_id][CC_id]->check_for_total_transmissions =
       PHY_vars_eNB_g[Mod_id][CC_id]->check_for_total_transmissions +
       1;
-
   }
+
 #endif
 
   for (UE_id = UE_list->head; UE_id >= 0; UE_id = UE_list->next[UE_id]) {
-
     ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
+
     for (i = 0; i < UE_num_active_CC(UE_list, UE_id); i++) {
       CC_id = UE_list->ordered_CCids[i][UE_id];
       //PHY_vars_eNB_g[Mod_id]->mu_mimo_mode[UE_id].dl_pow_off = dl_pow_off[UE_id];
@@ -1330,9 +1316,7 @@ dlsch_scheduler_pre_processor_reset(module_id_t module_idP,
                                     uint16_t nb_rbs_required[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB],
                                     uint8_t rballoc_sub[NFAPI_CC_MAX][N_RBG_MAX],
                                     uint8_t MIMO_mode_indicator[NFAPI_CC_MAX][N_RBG_MAX],
-                                    int *mbsfn_flag)
-{
-
+                                    int *mbsfn_flag) {
   int UE_id;
   uint8_t CC_id;
   int i, j;
@@ -1340,17 +1324,15 @@ dlsch_scheduler_pre_processor_reset(module_id_t module_idP,
   UE_sched_ctrl *ue_sched_ctl;
   int N_RB_DL, RBGsize, RBGsize_last;
   int N_RBG[NFAPI_CC_MAX];
-
 #ifdef SF0_LIMIT
   int sf0_lower, sf0_upper;
 #endif
-
   rnti_t rnti;
   uint8_t *vrb_map;
   COMMON_channels_t *cc;
-//
-  for (CC_id = 0; CC_id < RC.nb_mac_CC[module_idP]; CC_id++) {
 
+  //
+  for (CC_id = 0; CC_id < RC.nb_mac_CC[module_idP]; CC_id++) {
     LOG_D(MAC, "Running preprocessor for UE %d (%x)\n", UE_id,(int)(UE_RNTI(module_idP, UE_id)));
     // initialize harq_pid and round
     cc = &RC.mac[module_idP]->common_channels[CC_id];
@@ -1361,13 +1343,10 @@ dlsch_scheduler_pre_processor_reset(module_id_t module_idP,
       continue;
 
     for (UE_id = 0; UE_id < MAX_MOBILES_PER_ENB; ++UE_id) {
-
-
       UE_list = &RC.mac[module_idP]->UE_list;
       ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
       rnti = UE_RNTI(module_idP, UE_id);
 
-
       if (rnti == NOT_A_RNTI)
         continue;
 
@@ -1378,11 +1357,11 @@ dlsch_scheduler_pre_processor_reset(module_id_t module_idP,
         continue;
 
       LOG_D(MAC, "Running preprocessor for UE %d (%x)\n", UE_id, rnti);
+
       // initialize harq_pid and round
       if (ue_sched_ctl->ta_timer)
         ue_sched_ctl->ta_timer--;
 
-
       /*
          eNB_UE_stats *eNB_UE_stats;
 
@@ -1440,7 +1419,6 @@ dlsch_scheduler_pre_processor_reset(module_id_t module_idP,
          VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_TIMING_ADVANCE,ue_sched_ctl->ta_update);
          }
        */
-
       nb_rbs_required[CC_id][UE_id] = 0;
       ue_sched_ctl->pre_nb_available_rbs[CC_id] = 0;
       ue_sched_ctl->dl_pow_off[CC_id] = 2;
@@ -1451,32 +1429,38 @@ dlsch_scheduler_pre_processor_reset(module_id_t module_idP,
     }
 
     N_RB_DL = to_prb(RC.mac[module_idP]->common_channels[CC_id].mib->message.dl_Bandwidth);
-
 #ifdef SF0_LIMIT
+
     switch (N_RBG[CC_id]) {
       case 6:
         sf0_lower = 0;
         sf0_upper = 5;
         break;
+
       case 8:
         sf0_lower = 2;
         sf0_upper = 5;
         break;
+
       case 13:
         sf0_lower = 4;
         sf0_upper = 7;
         break;
+
       case 17:
         sf0_lower = 7;
         sf0_upper = 9;
         break;
+
       case 25:
         sf0_lower = 11;
         sf0_upper = 13;
         break;
+
       default:
         AssertFatal(1 == 0, "unsupported RBs (%d)\n", N_RB_DL);
     }
+
 #endif
 
     switch (N_RB_DL) {
@@ -1484,37 +1468,43 @@ dlsch_scheduler_pre_processor_reset(module_id_t module_idP,
         RBGsize = 1;
         RBGsize_last = 1;
         break;
+
       case 15:
         RBGsize = 2;
         RBGsize_last = 1;
         break;
+
       case 25:
         RBGsize = 2;
         RBGsize_last = 1;
         break;
+
       case 50:
         RBGsize = 3;
         RBGsize_last = 2;
         break;
+
       case 75:
         RBGsize = 4;
         RBGsize_last = 3;
         break;
+
       case 100:
         RBGsize = 4;
         RBGsize_last = 4;
         break;
+
       default:
         AssertFatal(1 == 0, "unsupported RBs (%d)\n", N_RB_DL);
     }
 
     vrb_map = RC.mac[module_idP]->common_channels[CC_id].vrb_map;
+
     // Initialize Subbands according to VRB map
     for (i = 0; i < N_RBG[CC_id]; i++) {
       int rb_size = i == N_RBG[CC_id] - 1 ? RBGsize_last : RBGsize;
-
-
 #ifdef SF0_LIMIT
+
       // for avoiding 6+ PRBs around DC in subframe 0 (avoid excessive errors)
       /* TODO: make it proper - allocate those RBs, do not "protect" them, but
         * compute number of available REs and limit MCS according to the
@@ -1522,6 +1512,7 @@ dlsch_scheduler_pre_processor_reset(module_id_t module_idP,
         */
       if (subframeP == 0 && i >= sf0_lower && i <= sf0_upper)
         rballoc_sub[CC_id][i] = 1;
+
 #endif
 
       // for SI-RNTI,RA-RNTI and P-RNTI allocations
@@ -1532,8 +1523,9 @@ dlsch_scheduler_pre_processor_reset(module_id_t module_idP,
           break;
         }
       }
+
       //LOG_D(MAC, "Frame %d Subframe %d CC_id %d RBG %i : rb_alloc %d\n",
-            //frameP, subframeP, CC_id, i, rballoc_sub[CC_id][i]);
+      //frameP, subframeP, CC_id, i, rballoc_sub[CC_id][i]);
       MIMO_mode_indicator[CC_id][i] = 2;
     }
   }
@@ -1550,8 +1542,7 @@ dlsch_scheduler_pre_processor_allocate(module_id_t Mod_id,
                                        uint16_t nb_rbs_remaining[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB],
                                        uint8_t rballoc_sub[NFAPI_CC_MAX][N_RBG_MAX],
                                        uint8_t slice_allocation_mask[NFAPI_CC_MAX][N_RBG_MAX],
-                                       uint8_t MIMO_mode_indicator[NFAPI_CC_MAX][N_RBG_MAX])
-{
+                                       uint8_t MIMO_mode_indicator[NFAPI_CC_MAX][N_RBG_MAX]) {
   int i;
   int tm = get_tmode(Mod_id, CC_id, UE_id);
   UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list;
@@ -1559,12 +1550,16 @@ dlsch_scheduler_pre_processor_allocate(module_id_t Mod_id,
   int N_RB_DL = to_prb(RC.mac[Mod_id]->common_channels[CC_id].mib->message.dl_Bandwidth);
 
   for (i = 0; i < N_RBG; i++) {
-
     if (rballoc_sub[CC_id][i] != 0) continue;
+
     if (ue_sched_ctl->rballoc_sub_UE[CC_id][i] != 0) continue;
+
     if (nb_rbs_remaining[CC_id][UE_id] <= 0) continue;
+
     if (ue_sched_ctl->pre_nb_available_rbs[CC_id] >= nb_rbs_required[CC_id][UE_id]) continue;
+
     if (ue_sched_ctl->dl_pow_off[CC_id] == 0) continue;
+
     if (slice_allocation_mask[CC_id][i] == 0) continue;
 
     if ((i == N_RBG - 1) && ((N_RB_DL == 25) || (N_RB_DL == 50))) {
@@ -1573,9 +1568,11 @@ dlsch_scheduler_pre_processor_allocate(module_id_t Mod_id,
         rballoc_sub[CC_id][i] = 1;
         ue_sched_ctl->rballoc_sub_UE[CC_id][i] = 1;
         MIMO_mode_indicator[CC_id][i] = 1;
+
         if (tm == 5) {
           ue_sched_ctl->dl_pow_off[CC_id] = 1;
         }
+
         nb_rbs_remaining[CC_id][UE_id] = nb_rbs_remaining[CC_id][UE_id] - min_rb_unit + 1;
         ue_sched_ctl->pre_nb_available_rbs[CC_id] = ue_sched_ctl->pre_nb_available_rbs[CC_id] + min_rb_unit - 1;
       }
@@ -1585,9 +1582,11 @@ dlsch_scheduler_pre_processor_allocate(module_id_t Mod_id,
         rballoc_sub[CC_id][i] = 1;
         ue_sched_ctl->rballoc_sub_UE[CC_id][i] = 1;
         MIMO_mode_indicator[CC_id][i] = 1;
+
         if (tm == 5) {
           ue_sched_ctl->dl_pow_off[CC_id] = 1;
         }
+
         nb_rbs_remaining[CC_id][UE_id] = nb_rbs_remaining[CC_id][UE_id] - min_rb_unit;
         ue_sched_ctl->pre_nb_available_rbs[CC_id] = ue_sched_ctl->pre_nb_available_rbs[CC_id] + min_rb_unit;
       }
@@ -1603,249 +1602,204 @@ void ulsch_scheduler_pre_processor(module_id_t module_idP,
                                    int frameP,
                                    sub_frame_t subframeP,
                                    unsigned char sched_subframeP,
-                                   uint16_t *first_rb)
-{
-    int16_t i;
-    uint16_t UE_id, n, r;
-    uint8_t CC_id, harq_pid;
-    uint16_t nb_allocated_rbs[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB],
-	total_allocated_rbs[NFAPI_CC_MAX],
-	average_rbs_per_user[NFAPI_CC_MAX];
-    int16_t total_remaining_rbs[NFAPI_CC_MAX];
-    uint16_t total_ue_count[NFAPI_CC_MAX];
-    rnti_t rnti = -1;
-    UE_list_t *UE_list = &RC.mac[module_idP]->UE_list;
-    slice_info_t *sli = &RC.mac[module_idP]->slice_info;
-    UE_TEMPLATE *UE_template = 0;
-    UE_sched_ctrl *ue_sched_ctl;
-    int N_RB_UL = 0;
-    uint16_t available_rbs, first_rb_offset;
-
-    LOG_D(MAC, "In ulsch_preprocessor: assign max mcs min rb\n");
-    // maximize MCS and then allocate required RB according to the buffer occupancy with the limit of max available UL RB
-    assign_max_mcs_min_rb(module_idP, slice_idx, frameP, subframeP, first_rb);
-
-    LOG_D(MAC, "In ulsch_preprocessor: sort ue \n");
-    // sort ues
-    sort_ue_ul(module_idP, frameP, subframeP);
-
-
-    // we need to distribute RBs among UEs
-    // step1:  reset the vars
-    for (CC_id = 0; CC_id < RC.nb_mac_CC[module_idP]; CC_id++) {
-      total_allocated_rbs[CC_id] = 0;
-      total_remaining_rbs[CC_id] = 0;
-      average_rbs_per_user[CC_id] = 0;
-      total_ue_count[CC_id] = 0;
-    }
+                                   uint16_t *first_rb) {
+  int UE_id;
+  uint16_t n;
+  uint8_t CC_id, harq_pid;
+  uint16_t nb_allocated_rbs[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB];
+  uint16_t total_allocated_rbs[NFAPI_CC_MAX];
+  uint16_t average_rbs_per_user[NFAPI_CC_MAX];
+  int16_t total_remaining_rbs[NFAPI_CC_MAX];
+  uint16_t total_ue_count[NFAPI_CC_MAX];
+  UE_list_t *UE_list = &RC.mac[module_idP]->UE_list;
+  slice_info_t *sli = &RC.mac[module_idP]->slice_info;
+  UE_TEMPLATE *UE_template = 0;
+  UE_sched_ctrl *ue_sched_ctl;
+  int N_RB_UL = 0;
+  uint16_t available_rbs, first_rb_offset;
+  rnti_t rntiTable[MAX_MOBILES_PER_ENB];        // Rnti array => Add SSR 12-2018
+
+  // sort ues
+  LOG_D(MAC, "In ulsch_preprocessor: sort ue \n");
+   sort_ue_ul(module_idP, slice_idx, frameP, subframeP, rntiTable);
+  // maximize MCS and then allocate required RB according to the buffer occupancy with the limit of max available UL RB
+  LOG_D(MAC, "In ulsch_preprocessor: assign max mcs min rb\n");
+  assign_max_mcs_min_rb(module_idP, slice_idx, frameP, subframeP, first_rb);
+  // we need to distribute RBs among UEs
+  // step1:  reset the vars
+  uint8_t CC_nb = (uint8_t) RC.nb_mac_CC[module_idP];
+
+  for (CC_id = 0; CC_id < CC_nb; CC_id++) {
+    total_allocated_rbs[CC_id] = 0;
+    total_remaining_rbs[CC_id] = 0;
+    average_rbs_per_user[CC_id] = 0;
+    total_ue_count[CC_id] = 0;
+  }
 
-    // Step 1.5: Calculate total_ue_count
-    for (i = UE_list->head_ul; i >= 0; i = UE_list->next_ul[i]) {
-      for (n = 0; n < UE_list->numactiveULCCs[i]; n++) {
-        // This is the actual CC_id in the list
-        CC_id = UE_list->ordered_ULCCids[n][i];
-        UE_template = &UE_list->UE_template[CC_id][i];
-        if (!ue_ul_slice_membership(module_idP, i, slice_idx))
-          continue;
-        if (UE_template->pre_allocated_nb_rb_ul[slice_idx] > 0) {
-          total_ue_count[CC_id] += 1;
-        }
+  // Step 1.5: Calculate total_ue_count
+  for (UE_id = UE_list->head_ul; UE_id >= 0; UE_id = UE_list->next_ul[UE_id]) {
+    // This is not the actual CC_id in the list
+    for (n = 0; n < UE_list->numactiveULCCs[UE_id]; n++) {
+      CC_id = UE_list->ordered_ULCCids[n][UE_id];
+      UE_template = &UE_list->UE_template[CC_id][UE_id];
+
+      if (UE_template->pre_allocated_nb_rb_ul[slice_idx] > 0) {
+        total_ue_count[CC_id]++;
       }
     }
+  }
 
-    LOG_D(MAC, "In ulsch_preprocessor: step2 \n");
-    // step 2: calculate the average rb per UE
-    for (i = UE_list->head_ul; i >= 0; i = UE_list->next_ul[i]) {
-
-      rnti = UE_RNTI(module_idP, i);
-      UE_id = i;
+  // step 2: calculate the average rb per UE
+  LOG_D(MAC, "In ulsch_preprocessor: step2 \n");
+  for (UE_id = UE_list->head_ul; UE_id >= 0; UE_id = UE_list->next_ul[UE_id]) {
+    if (UE_list->UE_template[CC_id][UE_id].rach_resource_type > 0) continue;
 
-      if (rnti == NOT_A_RNTI)
-        continue;
+    LOG_D(MAC, "In ulsch_preprocessor: handling UE %d/%x\n",
+          UE_id,
+          rntiTable[UE_id]);
 
-      if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1)
-        continue;
-
-      if (!ue_ul_slice_membership(module_idP, UE_id, slice_idx))
-          continue;
+    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];
+      LOG_D(MAC, "In ulsch_preprocessor: handling UE %d/%x CCid %d\n",
+            UE_id,
+            rntiTable[UE_id],
+            CC_id);
+      /*
+          if((mac_xface->get_nCCE_max(module_idP,CC_id,3,subframeP) - nCCE_to_be_used[CC_id])  > (1<<aggregation)) {
+          nCCE_to_be_used[CC_id] = nCCE_to_be_used[CC_id] + (1<<aggregation);
+          max_num_ue_to_be_scheduled+=1;
+          } */
+      N_RB_UL = to_prb(RC.mac[module_idP]->common_channels[CC_id].ul_Bandwidth);
+      ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
+      ue_sched_ctl->max_rbs_allowed_slice_uplink[CC_id][slice_idx] =
+        nb_rbs_allowed_slice(sli->ul[slice_idx].pct, N_RB_UL);
+      first_rb_offset = UE_list->first_rb_offset[CC_id][slice_idx];
+      available_rbs =
+        cmin(ue_sched_ctl->max_rbs_allowed_slice_uplink[CC_id][slice_idx], N_RB_UL - first_rb[CC_id] - first_rb_offset);
 
-      LOG_D(MAC, "In ulsch_preprocessor: handling UE %d/%x\n", UE_id,
-            rnti);
-      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];
-        LOG_D(MAC,
-              "In ulsch_preprocessor: handling UE %d/%x CCid %d\n",
-              UE_id, rnti, CC_id);
+      if (available_rbs < 0)
+        available_rbs = 0;
 
+      if (total_ue_count[CC_id] == 0) {
         average_rbs_per_user[CC_id] = 0;
+      } else if (total_ue_count[CC_id] == 1) {    // increase the available RBs, special case,
+        average_rbs_per_user[CC_id] = (uint16_t) (available_rbs + 1);
+      } else if (total_ue_count[CC_id] <= available_rbs) {
+        average_rbs_per_user[CC_id] = (uint16_t) floor(available_rbs / total_ue_count[CC_id]);
+      } else {
+        average_rbs_per_user[CC_id] = 1;
+        LOG_W(MAC, "[eNB %d] frame %d subframe %d: UE %d CC %d: can't get average rb per user (should not be here)\n",
+              module_idP,
+              frameP,
+              subframeP,
+              UE_id,
+              CC_id);
+      }
 
-        /*
-           if((mac_xface->get_nCCE_max(module_idP,CC_id,3,subframeP) - nCCE_to_be_used[CC_id])  > (1<<aggregation)) {
-           nCCE_to_be_used[CC_id] = nCCE_to_be_used[CC_id] + (1<<aggregation);
-           max_num_ue_to_be_scheduled+=1;
-           } */
-
-
-
-        N_RB_UL = to_prb(RC.mac[module_idP]->common_channels[CC_id].ul_Bandwidth);
-        ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
-        ue_sched_ctl->max_rbs_allowed_slice_uplink[CC_id][slice_idx] =
-                nb_rbs_allowed_slice(sli->ul[slice_idx].pct, N_RB_UL);
-
-        first_rb_offset = UE_list->first_rb_offset[CC_id][slice_idx];
-        available_rbs = cmin(ue_sched_ctl->max_rbs_allowed_slice_uplink[CC_id][slice_idx],
-                             N_RB_UL - first_rb[CC_id] - first_rb_offset);
-        if (available_rbs < 0)
-          available_rbs = 0;
-
-        if (total_ue_count[CC_id] == 0) {
-          average_rbs_per_user[CC_id] = 0;
-        } else if (total_ue_count[CC_id] == 1) {    // increase the available RBs, special case,
-          average_rbs_per_user[CC_id] = (uint16_t) (available_rbs + 1);
-        } else if (total_ue_count[CC_id] <= available_rbs) {
-          average_rbs_per_user[CC_id] = (uint16_t) floor(available_rbs / total_ue_count[CC_id]);
-        } else {
-          average_rbs_per_user[CC_id] = 1;
-          LOG_W(MAC,
-                "[eNB %d] frame %d subframe %d: UE %d CC %d: can't get average rb per user (should not be here)\n",
-                module_idP, frameP, subframeP, UE_id, CC_id);
-        }
-        if (total_ue_count[CC_id] > 0)
-          LOG_D(MAC, "[eNB %d] Frame %d subframe %d: total ue to be scheduled %d\n",
-                module_idP, frameP, subframeP, total_ue_count[CC_id]);
+      if (total_ue_count[CC_id] > 0) {
+        LOG_D(MAC, "[eNB %d] Frame %d subframe %d: total ue to be scheduled %d\n",
+              module_idP,
+              frameP,
+              subframeP,
+              total_ue_count[CC_id]);
       }
     }
+  }
 
-    // step 3: assigne RBS
-    for (i = UE_list->head_ul; i >= 0; i = UE_list->next_ul[i]) {
-      rnti = UE_RNTI(module_idP, i);
-
-      if (rnti == NOT_A_RNTI)
-        continue;
-      if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1)
-        continue;
-      if (!ue_ul_slice_membership(module_idP, i, slice_idx))
-        continue;
-
-
-      UE_id = i;
+  // step 3: assigne RBS
+  for (UE_id = UE_list->head_ul; UE_id >= 0; UE_id = UE_list->next_ul[UE_id]) {
+    // if (continueTable[UE_id]) continue;
 
-      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];
-        UE_template = &UE_list->UE_template[CC_id][UE_id];
-        harq_pid = subframe2harqpid(&RC.mac[module_idP]->common_channels[CC_id],
-                                    frameP, sched_subframeP);
+    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];
+      UE_template = &UE_list->UE_template[CC_id][UE_id];
+      harq_pid = subframe2harqpid(&RC.mac[module_idP]->common_channels[CC_id],
+                                  frameP, sched_subframeP);
 
-        //      mac_xface->get_ue_active_harq_pid(module_idP,CC_id,rnti,frameP,subframeP,&harq_pid,&round,openair_harq_UL);
+      //      mac_xface->get_ue_active_harq_pid(module_idP,CC_id,rnti,frameP,subframeP,&harq_pid,&round,openair_harq_UL);
 
-        if (UE_list->UE_sched_ctrl[UE_id].round_UL[CC_id] > 0) {
-          nb_allocated_rbs[CC_id][UE_id] = UE_list->UE_template[CC_id][UE_id].nb_rb_ul[harq_pid];
-        } else {
-          nb_allocated_rbs[CC_id][UE_id] =
-                  cmin(UE_list->UE_template[CC_id][UE_id].pre_allocated_nb_rb_ul[slice_idx],
-                       average_rbs_per_user[CC_id]);
-        }
-
-        total_allocated_rbs[CC_id] += nb_allocated_rbs[CC_id][UE_id];
-        LOG_D(MAC,
-              "In ulsch_preprocessor: assigning %d RBs for UE %d/%x CCid %d, harq_pid %d\n",
-              nb_allocated_rbs[CC_id][UE_id], UE_id, rnti, CC_id,
-              harq_pid);
+      if (UE_list->UE_sched_ctrl[UE_id].round_UL[CC_id] > 0) {
+        nb_allocated_rbs[CC_id][UE_id] = UE_list->UE_template[CC_id][UE_id].nb_rb_ul[harq_pid];
+      } else {
+        nb_allocated_rbs[CC_id][UE_id] =
+          cmin(UE_list->UE_template[CC_id][UE_id].pre_allocated_nb_rb_ul[slice_idx], average_rbs_per_user[CC_id]);
       }
-    }
-
-    // step 4: assigne the remaining RBs and set the pre_allocated rbs accordingly
-  for (r = 0; r < 2; r++) {
 
-    for (i = UE_list->head_ul; i >= 0; i = UE_list->next_ul[i]) {
-      rnti = UE_RNTI(module_idP, i);
+      total_allocated_rbs[CC_id] += nb_allocated_rbs[CC_id][UE_id];
+      LOG_D(MAC, "In ulsch_preprocessor: assigning %d RBs for UE %d/%x CCid %d, harq_pid %d\n",
+            nb_allocated_rbs[CC_id][UE_id],
+            UE_id,
+            rntiTable[UE_id],
+            CC_id,
+            harq_pid);
+    }
+  }
 
-      if (rnti == NOT_A_RNTI)
-        continue;
-      if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1)
-        continue;
-      if (!ue_ul_slice_membership(module_idP, i, slice_idx))
-        continue;
+  // step 4: assigne the remaining RBs and set the pre_allocated rbs accordingly
+  for (UE_id = UE_list->head_ul; UE_id >= 0; UE_id = UE_list->next_ul[UE_id]) {
+    // if (continueTable[UE_id]) continue;
 
-      UE_id = i;
-      ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
+    ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
 
-      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];
-        UE_template = &UE_list->UE_template[CC_id][UE_id];
-        N_RB_UL = to_prb(RC.mac[module_idP]->common_channels[CC_id].ul_Bandwidth);
-        first_rb_offset = UE_list->first_rb_offset[CC_id][slice_idx];
-        available_rbs = cmin(ue_sched_ctl->max_rbs_allowed_slice_uplink[CC_id][slice_idx],
-                             N_RB_UL - first_rb[CC_id] - first_rb_offset);
-        total_remaining_rbs[CC_id] = available_rbs - total_allocated_rbs[CC_id];
+    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];
+      UE_template = &UE_list->UE_template[CC_id][UE_id];
+      N_RB_UL = to_prb(RC.mac[module_idP]->common_channels[CC_id].ul_Bandwidth);
+      first_rb_offset = UE_list->first_rb_offset[CC_id][slice_idx];
+      available_rbs = cmin(ue_sched_ctl->max_rbs_allowed_slice_uplink[CC_id][slice_idx], N_RB_UL - first_rb[CC_id] - first_rb_offset);
+      total_remaining_rbs[CC_id] = available_rbs - total_allocated_rbs[CC_id];
 
-        if (total_ue_count[CC_id] == 1) {
-          total_remaining_rbs[CC_id] += 1;
-        }
+      if (total_ue_count[CC_id] == 1) {
+        total_remaining_rbs[CC_id]++;
+      }
 
-        if (r == 0) {
-          while ((UE_template->pre_allocated_nb_rb_ul[slice_idx] > 0)
-                 && (nb_allocated_rbs[CC_id][UE_id] < UE_template->pre_allocated_nb_rb_ul[slice_idx])
-                 && (total_remaining_rbs[CC_id] > 0)) {
-            nb_allocated_rbs[CC_id][UE_id] =
-                    cmin(nb_allocated_rbs[CC_id][UE_id] + 1,
-                         UE_template->pre_allocated_nb_rb_ul[slice_idx]);
-            total_remaining_rbs[CC_id]--;
-            total_allocated_rbs[CC_id]++;
-          }
-        } else {
-          UE_template->pre_allocated_nb_rb_ul[slice_idx] =
-                  nb_allocated_rbs[CC_id][UE_id];
-          LOG_D(MAC,
-                "******************UL Scheduling Information for UE%d CC_id %d ************************\n",
-                UE_id, CC_id);
-          LOG_D(MAC,
-                "[eNB %d] total RB allocated for UE%d CC_id %d  = %d\n",
-                module_idP, UE_id, CC_id,
-                UE_template->pre_allocated_nb_rb_ul[slice_idx]);
-        }
+      while (UE_template->pre_allocated_nb_rb_ul[slice_idx] > 0 &&
+             nb_allocated_rbs[CC_id][UE_id] < UE_template->pre_allocated_nb_rb_ul[slice_idx] &&
+             total_remaining_rbs[CC_id] > 0) {
+        nb_allocated_rbs[CC_id][UE_id] = cmin(nb_allocated_rbs[CC_id][UE_id] + 1, UE_template->pre_allocated_nb_rb_ul[slice_idx]);
+        total_remaining_rbs[CC_id]--;
+        total_allocated_rbs[CC_id]++;
       }
+
+      UE_template->pre_allocated_nb_rb_ul[slice_idx] = nb_allocated_rbs[CC_id][UE_id];
+      LOG_D(MAC, "******************UL Scheduling Information for UE%d CC_id %d ************************\n",
+            UE_id,
+            CC_id);
+      LOG_D(MAC, "[eNB %d] total RB allocated for UE%d CC_id %d  = %d\n",
+            module_idP,
+            UE_id,
+            CC_id,
+            UE_template->pre_allocated_nb_rb_ul[slice_idx]);
     }
   }
+
+  return;
 }
 
 void
-assign_max_mcs_min_rb(module_id_t module_idP, int slice_idx, int frameP,
-		      sub_frame_t subframeP, uint16_t * first_rb)
-{
-
+assign_max_mcs_min_rb(module_id_t module_idP,
+                      int slice_idx,
+                      int frameP,
+                      sub_frame_t subframeP,
+                      uint16_t *first_rb) {
   int i;
   uint16_t n, UE_id;
   uint8_t CC_id;
-  rnti_t rnti = -1;
   int mcs;
   int rb_table_index = 0, tbs, tx_power;
   eNB_MAC_INST *eNB = RC.mac[module_idP];
   UE_list_t *UE_list = &eNB->UE_list;
-  slice_info_t *sli = &RC.mac[module_idP]->slice_info;
-
+  slice_info_t *sli = &eNB->slice_info;
   UE_TEMPLATE *UE_template;
   UE_sched_ctrl *ue_sched_ctl;
   int Ncp;
   int N_RB_UL;
   int first_rb_offset, available_rbs;
 
-  for (i = 0; i < MAX_MOBILES_PER_ENB; i++) {
-    if (UE_list->active[i] != TRUE)
-      continue;
-
-    rnti = UE_RNTI(module_idP, i);
-
-    if (rnti == NOT_A_RNTI)
-      continue;
-    if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1)
-      continue;
-    if (!ue_ul_slice_membership(module_idP, i, slice_idx))
-      continue;
-
+  for (i = UE_list->head_ul; i >= 0; i = UE_list->next_ul[i]) {
     if (UE_list->UE_sched_ctrl[i].phr_received == 1) {
       /* if we've received the power headroom information the UE, we can go to
        * maximum mcs */
@@ -1860,22 +1814,18 @@ assign_max_mcs_min_rb(module_id_t module_idP, int slice_idx, int frameP,
     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];
-
-
-
-      AssertFatal(CC_id < RC.nb_mac_CC[module_idP],
-                  "CC_id %u should be < %u, loop n=%u < numactiveULCCs[%u]=%u",
-                  CC_id, NFAPI_CC_MAX, n, UE_id,
+      AssertFatal(CC_id < RC.nb_mac_CC[module_idP], "CC_id %u should be < %u, loop n=%u < numactiveULCCs[%u]=%u",
+                  CC_id,
+                  NFAPI_CC_MAX,
+                  n,
+                  UE_id,
                   UE_list->numactiveULCCs[UE_id]);
-
       UE_template = &UE_list->UE_template[CC_id][UE_id];
       UE_template->pre_assigned_mcs_ul = mcs;
       ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
-
-      Ncp = RC.mac[module_idP]->common_channels[CC_id].Ncp;
-      N_RB_UL = to_prb(RC.mac[module_idP]->common_channels[CC_id].ul_Bandwidth);
-      ue_sched_ctl->max_rbs_allowed_slice_uplink[CC_id][slice_idx] =
-              nb_rbs_allowed_slice(sli->ul[slice_idx].pct, N_RB_UL);
+      Ncp = eNB->common_channels[CC_id].Ncp;
+      N_RB_UL = to_prb(eNB->common_channels[CC_id].ul_Bandwidth);
+      ue_sched_ctl->max_rbs_allowed_slice_uplink[CC_id][slice_idx] = nb_rbs_allowed_slice(sli->ul[slice_idx].pct, N_RB_UL);
 
       int bytes_to_schedule = UE_template->estimated_ul_buffer - UE_template->scheduled_ul_bytes;
       if (bytes_to_schedule < 0) bytes_to_schedule = 0;
@@ -1885,13 +1835,10 @@ assign_max_mcs_min_rb(module_id_t module_idP, int slice_idx, int frameP,
       if (bits_to_schedule > 0) {
         tbs = get_TBS_UL(UE_template->pre_assigned_mcs_ul, 3) << 3; // 1 or 2 PRB with cqi enabled does not work well!
         rb_table_index = 2;
-
         // fixme: set use_srs flag
         tx_power = estimate_ue_tx_power(tbs, rb_table[rb_table_index], 0, Ncp, 0);
 
-        while ((((UE_template->phr_info - tx_power) < 0)
-              || (tbs > bits_to_schedule))
-              && (UE_template->pre_assigned_mcs_ul > 3)) {
+        while ((UE_template->phr_info - tx_power < 0 || tbs > bits_to_schedule) && UE_template->pre_assigned_mcs_ul > 3) {
           // LOG_I(MAC,"UE_template->phr_info %d tx_power %d mcs %d\n", UE_template->phr_info,tx_power, mcs);
           UE_template->pre_assigned_mcs_ul--;
           tbs = get_TBS_UL(UE_template->pre_assigned_mcs_ul, rb_table[rb_table_index]) << 3;
@@ -1899,13 +1846,13 @@ assign_max_mcs_min_rb(module_id_t module_idP, int slice_idx, int frameP,
         }
 
         first_rb_offset = UE_list->first_rb_offset[CC_id][slice_idx];
-        available_rbs = cmin(ue_sched_ctl->max_rbs_allowed_slice_uplink[CC_id][slice_idx],
-                             N_RB_UL - first_rb[CC_id] - first_rb_offset);
+        available_rbs =
+          cmin(ue_sched_ctl->max_rbs_allowed_slice_uplink[CC_id][slice_idx], N_RB_UL - first_rb[CC_id] - first_rb_offset);
 
-        while ((tbs < bits_to_schedule)
-               && (rb_table[rb_table_index] < available_rbs)
-               && ((UE_template->phr_info - tx_power) > 0)
-               && (rb_table_index < 32)) {
+        while (tbs < bits_to_schedule &&
+               rb_table[rb_table_index] < available_rbs &&
+               UE_template->phr_info - tx_power > 0 &&
+               rb_table_index < 32) {
           rb_table_index++;
           tbs = get_TBS_UL(UE_template->pre_assigned_mcs_ul, rb_table[rb_table_index]) << 3;
           tx_power = estimate_ue_tx_power(tbs, rb_table[rb_table_index], 0, Ncp, 0);
@@ -1914,16 +1861,20 @@ assign_max_mcs_min_rb(module_id_t module_idP, int slice_idx, int frameP,
         if (rb_table[rb_table_index] > (available_rbs - 1)) {
           rb_table_index--;
         }
+
         // 1 or 2 PRB with cqi enabled does not work well
         if (rb_table[rb_table_index] < 3) {
-            rb_table_index = 2;	//3PRB
+          rb_table_index = 2; //3PRB
         }
 
         UE_template->pre_allocated_rb_table_index_ul = rb_table_index;
         UE_template->pre_allocated_nb_rb_ul[slice_idx] = rb_table[rb_table_index];
-        LOG_D(MAC,
-              "[eNB %d] frame %d subframe %d: for UE %d CC %d: pre-assigned mcs %d, pre-allocated rb_table[%d]=%d RBs (phr %d, tx power %d)\n",
-              module_idP, frameP, subframeP, UE_id, CC_id,
+        LOG_D(MAC, "[eNB %d] frame %d subframe %d: for UE %d CC %d: pre-assigned mcs %d, pre-allocated rb_table[%d]=%d RBs (phr %d, tx power %d)\n",
+              module_idP,
+              frameP,
+              subframeP,
+              UE_id,
+              CC_id,
               UE_template->pre_assigned_mcs_ul,
               UE_template->pre_allocated_rb_table_index_ul,
               UE_template->pre_allocated_nb_rb_ul[slice_idx],
@@ -1947,91 +1898,97 @@ assign_max_mcs_min_rb(module_id_t module_idP, int slice_idx, int frameP,
 }
 
 struct sort_ue_ul_params {
-    int module_idP;
-    int frameP;
-    int subframeP;
+  int module_idP;
+  int frameP;
+  int subframeP;
 };
 
-static int ue_ul_compare(const void *_a, const void *_b, void *_params)
-{
-    struct sort_ue_ul_params *params = _params;
-    UE_list_t *UE_list = &RC.mac[params->module_idP]->UE_list;
-
-    int UE_id1 = *(const int *) _a;
-    int UE_id2 = *(const int *) _b;
-
-    int rnti1 = UE_RNTI(params->module_idP, UE_id1);
-    int pCCid1 = UE_PCCID(params->module_idP, UE_id1);
-    int round1 = maxround(params->module_idP, rnti1, params->frameP,
-			  params->subframeP, 1);
-
-    int rnti2 = UE_RNTI(params->module_idP, UE_id2);
-    int pCCid2 = UE_PCCID(params->module_idP, UE_id2);
-    int round2 = maxround(params->module_idP, rnti2, params->frameP,
-			  params->subframeP, 1);
-
-    if (round1 > round2)
-	return -1;
-    if (round1 < round2)
-	return 1;
-
-    if (UE_list->UE_template[pCCid1][UE_id1].ul_buffer_info[LCGID0] >
-	UE_list->UE_template[pCCid2][UE_id2].ul_buffer_info[LCGID0])
-	return -1;
-    if (UE_list->UE_template[pCCid1][UE_id1].ul_buffer_info[LCGID0] <
-	UE_list->UE_template[pCCid2][UE_id2].ul_buffer_info[LCGID0])
-	return 1;
-
-    int bytes_to_schedule1 = UE_list->UE_template[pCCid1][UE_id1].estimated_ul_buffer - UE_list->UE_template[pCCid1][UE_id1].scheduled_ul_bytes;
-    if (bytes_to_schedule1 < 0) bytes_to_schedule1 = 0;
-    int bytes_to_schedule2 = UE_list->UE_template[pCCid2][UE_id2].estimated_ul_buffer - UE_list->UE_template[pCCid2][UE_id2].scheduled_ul_bytes;
-    if (bytes_to_schedule2 < 0) bytes_to_schedule2 = 0;
-
-    if (bytes_to_schedule1 > bytes_to_schedule2)
-	return -1;
-    if (bytes_to_schedule1 < bytes_to_schedule2)
-	return 1;
-
-    if (UE_list->UE_template[pCCid1][UE_id1].pre_assigned_mcs_ul >
-	UE_list->UE_template[pCCid2][UE_id2].pre_assigned_mcs_ul)
-	return -1;
-    if (UE_list->UE_template[pCCid1][UE_id1].pre_assigned_mcs_ul <
-	UE_list->UE_template[pCCid2][UE_id2].pre_assigned_mcs_ul)
-	return 1;
+static int ue_ul_compare(const void *_a, const void *_b, void *_params) {
+  struct sort_ue_ul_params *params = _params;
+  UE_list_t *UE_list = &RC.mac[params->module_idP]->UE_list;
+  int UE_id1 = *(const int *) _a;
+  int UE_id2 = *(const int *) _b;
+  int rnti1 = UE_RNTI(params->module_idP, UE_id1);
+  int pCCid1 = UE_PCCID(params->module_idP, UE_id1);
+  int round1 = maxround(params->module_idP, rnti1, params->frameP,
+                        params->subframeP, 1);
+  int rnti2 = UE_RNTI(params->module_idP, UE_id2);
+  int pCCid2 = UE_PCCID(params->module_idP, UE_id2);
+  int round2 = maxround(params->module_idP, rnti2, params->frameP,
+                        params->subframeP, 1);
 
-    return 0;
+  if (round1 > round2)
+    return -1;
+
+  if (round1 < round2)
+    return 1;
+
+  if (UE_list->UE_template[pCCid1][UE_id1].ul_buffer_info[LCGID0] >
+      UE_list->UE_template[pCCid2][UE_id2].ul_buffer_info[LCGID0])
+    return -1;
+
+  if (UE_list->UE_template[pCCid1][UE_id1].ul_buffer_info[LCGID0] <
+      UE_list->UE_template[pCCid2][UE_id2].ul_buffer_info[LCGID0])
+    return 1;
+
+  int bytes_to_schedule1 = UE_list->UE_template[pCCid1][UE_id1].estimated_ul_buffer - UE_list->UE_template[pCCid1][UE_id1].scheduled_ul_bytes;
+
+  if (bytes_to_schedule1 < 0) bytes_to_schedule1 = 0;
+
+  int bytes_to_schedule2 = UE_list->UE_template[pCCid2][UE_id2].estimated_ul_buffer - UE_list->UE_template[pCCid2][UE_id2].scheduled_ul_bytes;
+
+  if (bytes_to_schedule2 < 0) bytes_to_schedule2 = 0;
+
+  if (bytes_to_schedule1 > bytes_to_schedule2)
+    return -1;
+
+  if (bytes_to_schedule1 < bytes_to_schedule2)
+    return 1;
+
+  if (UE_list->UE_template[pCCid1][UE_id1].pre_assigned_mcs_ul >
+      UE_list->UE_template[pCCid2][UE_id2].pre_assigned_mcs_ul)
+    return -1;
+
+  if (UE_list->UE_template[pCCid1][UE_id1].pre_assigned_mcs_ul <
+      UE_list->UE_template[pCCid2][UE_id2].pre_assigned_mcs_ul)
+    return 1;
+
+  return 0;
 }
 
-void sort_ue_ul(module_id_t module_idP, int frameP, sub_frame_t subframeP)
+void
+sort_ue_ul(module_id_t module_idP,
+           int slice_idx,
+           int frameP,
+           sub_frame_t subframeP,
+           rnti_t *rntiTable)
 {
-    int i;
-    int list[MAX_MOBILES_PER_ENB];
-    int list_size = 0;
-    int rnti;
-    struct sort_ue_ul_params params = { module_idP, frameP, subframeP };
-
-    UE_list_t *UE_list = &RC.mac[module_idP]->UE_list;
-
-    for (i = 0; i < MAX_MOBILES_PER_ENB; i++) {
-	if (UE_list->active[i] == FALSE)
-	    continue;
-	if ((rnti = UE_RNTI(module_idP, i)) == NOT_A_RNTI)
-	    continue;
-	if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1)
-	    continue;
-
-	list[list_size] = i;
-	list_size++;
+  int i;
+  int list[MAX_MOBILES_PER_ENB];
+  int list_size = 0;
+  struct sort_ue_ul_params params = { module_idP, frameP, subframeP };
+  UE_list_t *UE_list = &RC.mac[module_idP]->UE_list;
+
+  for (i = 0; i < MAX_MOBILES_PER_ENB; i++) {
+    rntiTable[i] = UE_RNTI(module_idP, i);
+    // Valid element and is not the actual CC_id in the list
+    if (UE_list->active[i] == TRUE &&
+        rntiTable[i] != NOT_A_RNTI &&
+        UE_list->UE_sched_ctrl[i].ul_out_of_sync != 1 &&
+        ue_ul_slice_membership(module_idP, i, slice_idx)) {
+      list[list_size++] = i; // Add to list
     }
+  }
 
-    qsort_r(list, list_size, sizeof(int), ue_ul_compare, &params);
+  qsort_r(list, list_size, sizeof(int), ue_ul_compare, &params);
 
-    if (list_size) {
-	for (i = 0; i < list_size - 1; i++)
-	    UE_list->next_ul[list[i]] = list[i + 1];
-	UE_list->next_ul[list[list_size - 1]] = -1;
-	UE_list->head_ul = list[0];
-    } else {
-	UE_list->head_ul = -1;
-    }
+  if (list_size) {                          // At mimimum one list element
+    for (i = 0; i < list_size - 1; i++)
+      UE_list->next_ul[list[i]] = list[i + 1];
+
+    UE_list->next_ul[list[list_size - 1]] = -1;
+    UE_list->head_ul = list[0];
+  } else {                                  // No element
+    UE_list->head_ul = -1;
+  }
 }
diff --git a/openair2/LAYER2/MAC/ra_procedures.c b/openair2/LAYER2/MAC/ra_procedures.c
index aeabbd092a32c02dee9ba16fdabf6deab593b0ec..d139c8bd472de11fe9350090f0f451c11d32db03 100644
--- a/openair2/LAYER2/MAC/ra_procedures.c
+++ b/openair2/LAYER2/MAC/ra_procedures.c
@@ -57,12 +57,12 @@ get_prach_resources(module_id_t module_idP,
 		    uint8_t eNB_index,
 		    uint8_t t_id,
 		    uint8_t first_Msg3,
-		    RACH_ConfigDedicated_t * rach_ConfigDedicated)
+		    LTE_RACH_ConfigDedicated_t * rach_ConfigDedicated)
 {
     uint8_t Msg3_size = UE_mac_inst[module_idP].RA_Msg3_size;
     PRACH_RESOURCES_t *prach_resources =
 	&UE_mac_inst[module_idP].RA_prach_resources;
-    RACH_ConfigCommon_t *rach_ConfigCommon = NULL;
+    LTE_RACH_ConfigCommon_t *rach_ConfigCommon = NULL;
     uint8_t noGroupB = 0;
     uint8_t f_id = 0, num_prach = 0;
     int numberOfRA_Preambles;
@@ -311,8 +311,8 @@ PRACH_RESOURCES_t *ue_get_rach(module_id_t module_idP, int CC_id,
 
     uint8_t lcid = CCCH;
     uint16_t Size16;
-    struct RACH_ConfigCommon *rach_ConfigCommon =
-	(struct RACH_ConfigCommon *) NULL;
+    struct LTE_RACH_ConfigCommon *rach_ConfigCommon =
+	(struct LTE_RACH_ConfigCommon *) NULL;
     int32_t frame_diff = 0;
     uint8_t dcch_header_len = 0;
     uint16_t sdu_lengths;
@@ -408,7 +408,7 @@ PRACH_RESOURCES_t *ue_get_rach(module_id_t module_idP, int CC_id,
 				       UE_mac_inst[module_idP].crnti,
 				       eNB_indexP, frameP, subframeP,
 				       ENB_FLAG_NO, MBMS_FLAG_NO, DCCH, 6
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                ,0, 0
 #endif
                );
@@ -428,7 +428,7 @@ PRACH_RESOURCES_t *ue_get_rach(module_id_t module_idP, int CC_id,
 
 		sdu_lengths = mac_rlc_data_req(module_idP, UE_mac_inst[module_idP].crnti, eNB_indexP, frameP, ENB_FLAG_NO, MBMS_FLAG_NO, DCCH, 6,	//not used
 						  (char *) &ulsch_buff[0]
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 						  ,0,
 						  0
 #endif
@@ -553,37 +553,37 @@ PRACH_RESOURCES_t *ue_get_rach(module_id_t module_idP, int CC_id,
 		int preambleTransMax = -1;
 		switch (rach_ConfigCommon->ra_SupervisionInfo.
 			preambleTransMax) {
-		case PreambleTransMax_n3:
+		case LTE_PreambleTransMax_n3:
 		    preambleTransMax = 3;
 		    break;
-		case PreambleTransMax_n4:
+		case LTE_PreambleTransMax_n4:
 		    preambleTransMax = 4;
 		    break;
-		case PreambleTransMax_n5:
+		case LTE_PreambleTransMax_n5:
 		    preambleTransMax = 5;
 		    break;
-		case PreambleTransMax_n6:
+		case LTE_PreambleTransMax_n6:
 		    preambleTransMax = 6;
 		    break;
-		case PreambleTransMax_n7:
+		case LTE_PreambleTransMax_n7:
 		    preambleTransMax = 7;
 		    break;
-		case PreambleTransMax_n8:
+		case LTE_PreambleTransMax_n8:
 		    preambleTransMax = 8;
 		    break;
-		case PreambleTransMax_n10:
+		case LTE_PreambleTransMax_n10:
 		    preambleTransMax = 10;
 		    break;
-		case PreambleTransMax_n20:
+		case LTE_PreambleTransMax_n20:
 		    preambleTransMax = 20;
 		    break;
-		case PreambleTransMax_n50:
+		case LTE_PreambleTransMax_n50:
 		    preambleTransMax = 50;
 		    break;
-		case PreambleTransMax_n100:
+		case LTE_PreambleTransMax_n100:
 		    preambleTransMax = 100;
 		    break;
-		case PreambleTransMax_n200:
+		case LTE_PreambleTransMax_n200:
 		    preambleTransMax = 200;
 		    break;
 		}
diff --git a/openair2/LAYER2/MAC/rar_tools.c b/openair2/LAYER2/MAC/rar_tools.c
index 2e6b47ff60464c320326a8d48455e47fc43792d2..9279970ba60dc71ba811c31629ae00410876769a 100644
--- a/openair2/LAYER2/MAC/rar_tools.c
+++ b/openair2/LAYER2/MAC/rar_tools.c
@@ -108,87 +108,103 @@ fill_rar(const module_id_t module_idP,
     return (ra->rnti);
 }
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 //------------------------------------------------------------------------------
-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)
+
+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
+			   )
 //------------------------------------------------------------------------------
 {
 
-    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);
-    //  uint8_t nb,reps;
-    uint8_t rballoc;
-    uint8_t mcs, TPC, ULdelay, cqireq;
-    int input_buffer_length;
-
-
-    AssertFatal(ra != NULL, "RA is null \n");
-
-    // 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;
-
-    AssertFatal(1 == 0, "RAR for BL/CE Still to be finished ...\n");
-
-    // Copy the Msg2 narrowband
-    ra->msg34_narrowband = ra->msg2_narrowband;
-
-    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;
-	//    nb      = 0;
-	rballoc = mac_computeRIV(6, 1 + ce_level, 1);	// one PRB only for UL Grant in position 1+ce_level within Narrowband
-	rar[1] |= (rballoc & 15) << (4 - N_NB_index);	// Hopping = 0 (bit 3), 3 MSBs of rballoc
-
-	//    reps    = 4;
-	mcs = 7;
-	TPC = 3;		// no power increase
-	ULdelay = 0;
-	cqireq = 0;
-	rar[2] |= ((mcs & 0x8) >> 3);	// mcs 10
-	rar[3] =
-	    (((mcs & 0x7) << 5)) | ((TPC & 7) << 2) | ((ULdelay & 1) << 1)
-	    | (cqireq & 1);
-    } else {			// CE level 2,3 => CEModeB
-
-	input_buffer_length = 5;
-
-	rar[3] = (uint8_t) (ra->rnti >> 8);
-	rar[4] = (uint8_t) (ra->rnti & 0xff);
-    }
-    LOG_D(MAC,
-	  "[RAPROC] Frame %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, *(uint8_t *) rarh, rar[0], rar[1], rar[2], rar[3],
-	  rar[4], rar[5], ce_level, ra->rnti, 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);
-    }
-
-    return (ra->rnti);
+  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;
+
+
+  AssertFatal(ra != NULL, "RA is null \n");
+
+  // 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;
+
+  // 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
+    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;
+
+    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);
+
+    uint32_t buffer = 0;
+    buffer |= ra->msg34_narrowband << (16 + (4 - N_NB_index));
+    buffer |= ((rballoc & 0xFF) << (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[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],
+        ce_level,
+        ra->rnti,
+        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);
+  }
+
+  return (ra->rnti);
 }
 #endif
 
diff --git a/openair2/LAYER2/MAC/ue_procedures.c b/openair2/LAYER2/MAC/ue_procedures.c
index 2c99b79ce8057860a4f3870c6dcd6a302854f7d7..9d32835e07ad9bcc8c391180baeb8d38d523be7f 100644
--- a/openair2/LAYER2/MAC/ue_procedures.c
+++ b/openair2/LAYER2/MAC/ue_procedures.c
@@ -65,11 +65,12 @@
 #define DEBUG_HEADER_PARSING 1
 #define ENABLE_MAC_PAYLOAD_DEBUG 1
 
-extern uint8_t usim_test;
 
 extern UL_IND_t *UL_INFO;
 
 extern uint8_t  nfapi_mode;
+extern int next_ra_frame;
+extern module_id_t next_Mod_id;
 
 /*
  *
@@ -96,22 +97,22 @@ void ue_init_mac(module_id_t module_idP)
     LOG_I(MAC, "[UE%d] Applying default macMainConfig\n", module_idP);
     //UE_mac_inst[module_idP].scheduling_info.macConfig=NULL;
     UE_mac_inst[module_idP].scheduling_info.retxBSR_Timer =
-	RetxBSR_Timer_r12_sf10240;
+	LTE_RetxBSR_Timer_r12_sf10240;
     UE_mac_inst[module_idP].scheduling_info.periodicBSR_Timer =
-	PeriodicBSR_Timer_r12_infinity;
+	LTE_PeriodicBSR_Timer_r12_infinity;
     UE_mac_inst[module_idP].scheduling_info.periodicPHR_Timer =
-	MAC_MainConfig__phr_Config__setup__periodicPHR_Timer_sf20;
+	LTE_MAC_MainConfig__phr_Config__setup__periodicPHR_Timer_sf20;
     UE_mac_inst[module_idP].scheduling_info.prohibitPHR_Timer =
-	MAC_MainConfig__phr_Config__setup__prohibitPHR_Timer_sf20;
+	LTE_MAC_MainConfig__phr_Config__setup__prohibitPHR_Timer_sf20;
     UE_mac_inst[module_idP].scheduling_info.PathlossChange_db =
-	MAC_MainConfig__phr_Config__setup__dl_PathlossChange_dB1;
+	LTE_MAC_MainConfig__phr_Config__setup__dl_PathlossChange_dB1;
     UE_mac_inst[module_idP].PHR_state =
-	MAC_MainConfig__phr_Config_PR_setup;
+	LTE_MAC_MainConfig__phr_Config_PR_setup;
     UE_mac_inst[module_idP].scheduling_info.SR_COUNTER = 0;
     UE_mac_inst[module_idP].scheduling_info.sr_ProhibitTimer = 0;
     UE_mac_inst[module_idP].scheduling_info.sr_ProhibitTimer_Running = 0;
     UE_mac_inst[module_idP].scheduling_info.maxHARQ_Tx =
-	MAC_MainConfig__ul_SCH_Config__maxHARQ_Tx_n5;
+	LTE_MAC_MainConfig__ul_SCH_Config__maxHARQ_Tx_n5;
     UE_mac_inst[module_idP].scheduling_info.ttiBundling = 0;
     UE_mac_inst[module_idP].scheduling_info.extendedBSR_Sizes_r10 = 0;
     UE_mac_inst[module_idP].scheduling_info.extendedPHR_r10 = 0;
@@ -304,14 +305,14 @@ ue_get_SR(module_id_t module_idP, int CC_id, frame_t frameP,
     // determin the measurement gap
     if (UE_mac_inst[module_idP].measGapConfig != NULL) {
 	if (UE_mac_inst[module_idP].measGapConfig->choice.setup.
-	    gapOffset.present == MeasGapConfig__setup__gapOffset_PR_gp0) {
+	    gapOffset.present == LTE_MeasGapConfig__setup__gapOffset_PR_gp0) {
 	    MGRP = 40;
 	    gapOffset =
 		UE_mac_inst[module_idP].measGapConfig->choice.
 		setup.gapOffset.choice.gp0;
 	} else if (UE_mac_inst[module_idP].measGapConfig->choice.
 		   setup.gapOffset.present ==
-		   MeasGapConfig__setup__gapOffset_PR_gp1) {
+		   LTE_MeasGapConfig__setup__gapOffset_PR_gp1) {
 	    MGRP = 80;
 	    gapOffset =
 		UE_mac_inst[module_idP].measGapConfig->choice.
@@ -558,31 +559,34 @@ ue_send_sdu(module_id_t module_idP,
 		LOG_T(MAC, "\n");
 #endif
 
-		mac_rrc_data_ind_ue(module_idP,
-				 CC_id,
-				 frameP, subframeP,
-				 UE_mac_inst[module_idP].crnti,
-				 CCCH,
-				 (uint8_t *) payload_ptr,
-				 rx_lengths[i], eNB_index, 0);
-
-	    } else if ((rx_lcids[i] == DCCH) || (rx_lcids[i] == DCCH1)) {
-		LOG_D(MAC,
-		      "[UE %d] Frame %d : DLSCH -> DL-DCCH%d, RRC message (eNB %d, %d bytes)\n",
-		      module_idP, frameP, rx_lcids[i], eNB_index,
-		      rx_lengths[i]);
-		mac_rlc_data_ind(module_idP, UE_mac_inst[module_idP].crnti,
-				 eNB_index, frameP, ENB_FLAG_NO,
-				 MBMS_FLAG_NO, rx_lcids[i],
-				 (char *) payload_ptr, rx_lengths[i], 1,
-				 NULL);
-
-	    } else if ((rx_lcids[i] < NB_RB_MAX) && (rx_lcids[i] > DCCH1)) {
-
-		LOG_D(MAC,
-		      "[UE %d] Frame %d : DLSCH -> DL-DTCH%d (eNB %d, %d bytes)\n",
-		      module_idP, frameP, rx_lcids[i], eNB_index,
-		      rx_lengths[i]);
+      mac_rrc_data_ind_ue(module_idP,
+			  CC_id,
+			  frameP,subframeP,
+			  UE_mac_inst[module_idP].crnti,
+			  CCCH,
+			  (uint8_t*)payload_ptr,
+			  rx_lengths[i],
+			  eNB_index,
+			  0
+			  );
+
+    } else if ((rx_lcids[i] == DCCH) || (rx_lcids[i] == DCCH1)) {
+      LOG_D(MAC,"[UE %d] Frame %d : DLSCH -> DL-DCCH%d, RRC message (eNB %d, %d bytes)\n", module_idP, frameP, rx_lcids[i],eNB_index,rx_lengths[i]);
+      mac_rlc_data_ind(module_idP,
+                       UE_mac_inst[module_idP].crnti,
+		       eNB_index,
+                       frameP,
+                       ENB_FLAG_NO,
+                       MBMS_FLAG_NO,
+                       rx_lcids[i],
+                       (char *)payload_ptr,
+                       rx_lengths[i],
+                       1,
+                       NULL);
+
+    } else if ((rx_lcids[i]  < NB_RB_MAX) && (rx_lcids[i] > DCCH1 )) {
+
+      LOG_D(MAC,"[UE %d] Frame %d : DLSCH -> DL-DTCH%d (eNB %d, %d bytes)\n", module_idP, frameP,rx_lcids[i], eNB_index,rx_lengths[i]);
 
 #if defined(ENABLE_MAC_PAYLOAD_DEBUG)
 		int j;
@@ -621,6 +625,7 @@ ue_decode_si(module_id_t module_idP, int CC_id, frame_t frameP,
 #if UE_TIMING_TRACE
     start_meas(&UE_mac_inst[module_idP].rx_si);
 #endif
+
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME
 	(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_SI, VCD_FUNCTION_IN);
 
@@ -633,6 +638,7 @@ ue_decode_si(module_id_t module_idP, int CC_id, frame_t frameP,
 		     0);
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME
 	(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_SI, VCD_FUNCTION_OUT);
+
 #if UE_TIMING_TRACE
     stop_meas(&UE_mac_inst[module_idP].rx_si);
 #endif
@@ -658,6 +664,7 @@ ue_decode_p(module_id_t module_idP, int CC_id, frame_t frameP,
 #if UE_TIMING_TRACE
     start_meas(&UE_mac_inst[module_idP].rx_p);
 #endif
+
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME
 	(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_PCCH, VCD_FUNCTION_IN);
 
@@ -671,6 +678,7 @@ ue_decode_p(module_id_t module_idP, int CC_id, frame_t frameP,
 		     0);
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME
 	(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_PCCH, VCD_FUNCTION_OUT);
+
 #if UE_TIMING_TRACE
     stop_meas(&UE_mac_inst[module_idP].rx_p);
 #endif
@@ -689,7 +697,7 @@ ue_decode_p(module_id_t module_idP, int CC_id, frame_t frameP,
     }
 }
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 unsigned char *parse_mch_header(unsigned char *mac_header,
 				unsigned char *num_sdu,
 				unsigned char *rx_lcids,
@@ -1017,7 +1025,7 @@ int ue_query_p_mch(module_id_t module_idP, uint32_t frameP, uint32_t subframe, i
     if (UE_mac_inst[module_idP].commonSF_Alloc_r9_mbsfn_SubframeConfig[i] == NULL)
       continue;
 
-    if (UE_mac_inst[module_idP].commonSF_Alloc_r9_mbsfn_SubframeConfig[i]->subframeAllocation.present == MBSFN_SubframeConfig__subframeAllocation_PR_oneFrame) // one-frameP format
+    if (UE_mac_inst[module_idP].commonSF_Alloc_r9_mbsfn_SubframeConfig[i]->subframeAllocation.present == LTE_MBSFN_SubframeConfig__subframeAllocation_PR_oneFrame) // one-frameP format
       continue;
 
     // four-frameP format
@@ -1032,7 +1040,7 @@ int ue_query_p_mch(module_id_t module_idP, uint32_t frameP, uint32_t subframe, i
     if (UE_mac_inst[module_idP].commonSF_Alloc_r9_mbsfn_SubframeConfig[i] == NULL)
       continue;
 
-    if (UE_mac_inst[module_idP].commonSF_Alloc_r9_mbsfn_SubframeConfig[i]->subframeAllocation.present == MBSFN_SubframeConfig__subframeAllocation_PR_oneFrame) // one-frameP format
+    if (UE_mac_inst[module_idP].commonSF_Alloc_r9_mbsfn_SubframeConfig[i]->subframeAllocation.present == LTE_MBSFN_SubframeConfig__subframeAllocation_PR_oneFrame) // one-frameP format
       continue;
 
     // four-frameP format
@@ -1167,7 +1175,7 @@ int ue_query_mch(module_id_t module_idP, uint8_t CC_id, uint32_t frameP, uint32_
       break;
     }
 
-    if (UE_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.present == MBSFN_SubframeConfig__subframeAllocation_PR_oneFrame) { // one-frameP format
+    if (UE_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.present == LTE_MBSFN_SubframeConfig__subframeAllocation_PR_oneFrame) { // one-frameP format
       if (frameP % mbsfn_period == mbsfn_alloc_offset) { // MBSFN frameP
 
         if (UE_mac_inst[module_idP].pmch_Config[0]) {
@@ -1372,7 +1380,7 @@ int ue_query_mch(module_id_t module_idP, uint8_t CC_id, uint32_t frameP, uint32_
           if (UE_mac_inst[module_idP].commonSF_Alloc_r9_mbsfn_SubframeConfig[i] == NULL)
             continue;
 
-          if (UE_mac_inst[module_idP].commonSF_Alloc_r9_mbsfn_SubframeConfig[i]->subframeAllocation.present != MBSFN_SubframeConfig__subframeAllocation_PR_oneFrame)
+          if (UE_mac_inst[module_idP].commonSF_Alloc_r9_mbsfn_SubframeConfig[i]->subframeAllocation.present != LTE_MBSFN_SubframeConfig__subframeAllocation_PR_oneFrame)
             continue;
 
           uint32_t common_mbsfn_SubframeConfig = UE_mac_inst[module_idP].commonSF_Alloc_r9_mbsfn_SubframeConfig[i]->subframeAllocation.choice.oneFrame.buf[0];
@@ -1919,7 +1927,7 @@ ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP,
     }
     // periodicBSR-Timer expires, trigger BSR
     if ((UE_mac_inst[module_idP].scheduling_info.periodicBSR_Timer !=
-	 PeriodicBSR_Timer_r12_infinity)
+	  LTE_PeriodicBSR_Timer_r12_infinity)
 	&& (UE_mac_inst[module_idP].scheduling_info.periodicBSR_SF == 0)) {
 	// Trigger BSR Periodic
 	UE_mac_inst[module_idP].BSR_reporting_active |=
@@ -2020,7 +2028,7 @@ ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP,
 	    {
 
 		// Workaround for issue in OAI eNB or EPC which are not able to process SRB2 message multiplexed with SRB1 on the same MAC PDU
-		if ((usim_test == 0) && (lcid == DCCH1)
+		if (( get_softmodem_params()->usim_test == 0) && (lcid == DCCH1)
 		    && (lcid_rlc_pdu_count == 0) && (num_sdus)) {
 
 		    // Skip SRB2 multiplex if at least one SRB1 SDU is already multiplexed
@@ -2055,7 +2063,7 @@ ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP,
 							 lcid,
 							 buflen_remain,
 							 (char *)&ulsch_buff[sdu_length_total]
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 							 ,0,
                               0
 #endif
@@ -2071,7 +2079,7 @@ ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP,
 		if (sdu_lengths[num_sdus]) {
 		    sdu_length_total += sdu_lengths[num_sdus];
 		    sdu_lcids[num_sdus] = lcid;
-		    LOG_D(MAC,
+		    LOG_I(MAC,
 			  "[UE %d] TX Multiplex RLC PDU TX Got %d bytes for LcId%d\n",
 			  module_idP, sdu_lengths[num_sdus], lcid);
 
@@ -2447,7 +2455,7 @@ ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP,
 	// Reset Periodic Timer except when BSR is truncated
 	if ((bsr_t == NULL)
 	    && (UE_mac_inst[module_idP].scheduling_info.
-		periodicBSR_Timer != PeriodicBSR_Timer_r12_infinity)) {
+		periodicBSR_Timer != LTE_PeriodicBSR_Timer_r12_infinity)) {
 	    UE_mac_inst[module_idP].scheduling_info.periodicBSR_SF =
 		get_sf_periodicBSRTimer(UE_mac_inst
 					[module_idP].scheduling_info.
@@ -2506,8 +2514,8 @@ ue_scheduler(const module_id_t module_idP,
     int bucketsizeduration_max = -1;
     // mac_rlc_status_resp_t rlc_status[MAX_NUM_LCGID]; // 4
     // int8_t lcg_id;
-    struct RACH_ConfigCommon *rach_ConfigCommon =
-	(struct RACH_ConfigCommon *) NULL;
+    struct LTE_RACH_ConfigCommon *rach_ConfigCommon =
+	(struct LTE_RACH_ConfigCommon *) NULL;
     protocol_ctxt_t ctxt;
 
 #if defined(ENABLE_ITTI)
@@ -2524,44 +2532,50 @@ ue_scheduler(const module_id_t module_idP,
 				   UE_mac_inst[module_idP].crnti, txFrameP,
 				   txSubframeP, eNB_indexP);
 #if defined(ENABLE_ITTI)
+    if(module_idP == 0){
+      do {
+	  // Checks if a message has been sent to MAC sub-task
+	  itti_poll_msg(TASK_MAC_UE, &msg_p);
 
-    do {
-	// Checks if a message has been sent to MAC sub-task
-	itti_poll_msg(TASK_MAC_UE, &msg_p);
+	    if (msg_p != NULL) {
 
-	if (msg_p != NULL) {
+	      switch (ITTI_MSG_ID(msg_p)) {
+	      case RRC_MAC_CCCH_DATA_REQ:
+		  LOG_I(MAC,
+		        "Received %s from %s: instance %d, frameP %d, eNB_index %d\n",
+		        ITTI_MSG_NAME(msg_p), ITTI_MSG_ORIGIN_NAME(msg_p), ITTI_MSG_INSTANCE(msg_p),
+		        RRC_MAC_CCCH_DATA_REQ(msg_p).frame,
+		        RRC_MAC_CCCH_DATA_REQ(msg_p).enb_index);
 
-	    switch (ITTI_MSG_ID(msg_p)) {
-	    case RRC_MAC_CCCH_DATA_REQ:
-		LOG_I(MAC,
-		      "Received %s from %s: instance %d, frameP %d, eNB_index %d\n",
-		      ITTI_MSG_NAME(msg_p), ITTI_MSG_ORIGIN_NAME(msg_p), ITTI_MSG_INSTANCE(msg_p),
-		      RRC_MAC_CCCH_DATA_REQ(msg_p).frame,
-		      RRC_MAC_CCCH_DATA_REQ(msg_p).enb_index);
+		  // TODO process CCCH data req.
+		  break;
 
-		// TODO process CCCH data req.
-		break;
 
+	      default:
+		  LOG_E(MAC, "Received unexpected message %s\n", ITTI_MSG_NAME(msg_p));
+		  break;
+	      }
 
-	    default:
-		LOG_E(MAC, "Received unexpected message %s\n", ITTI_MSG_NAME(msg_p));
-		break;
+	      result = itti_free(ITTI_MSG_ORIGIN_ID(msg_p), msg_p);
+	      AssertFatal(result == EXIT_SUCCESS,
+			  "Failed to free memory (%d)!\n", result);
 	    }
-
-	    result = itti_free(ITTI_MSG_ORIGIN_ID(msg_p), msg_p);
-	    AssertFatal(result == EXIT_SUCCESS,
-			"Failed to free memory (%d)!\n", result);
-	}
-    }
+      }
     while (msg_p != NULL);
-
+    }
 #endif
 
     //Mac_rlc_xface->frameP=frameP;
     //Rrc_xface->Frame_index=Mac_rlc_xface->frameP;
     //if (subframe%5 == 0)
     //LG#ifdef EXMIMO
-    pdcp_run(&ctxt);
+
+    // data to/from NETLINK is treated in pdcp_run.
+    // one socket is used in multiple UE's L2 FAPI simulator and
+    // only first UE need to do this.
+    if(module_idP == 0){
+      pdcp_run(&ctxt);
+    }
     //#endif
     UE_mac_inst[module_idP].txFrame = txFrameP;
     UE_mac_inst[module_idP].txSubframe = txSubframeP;
@@ -2600,7 +2614,7 @@ ue_scheduler(const module_id_t module_idP,
 	      eNB_indexP);
 	//Invalid...need to add another MAC UE state for re-connection procedure
 	phy_config_afterHO_ue(module_idP, 0, eNB_indexP,
-			      (MobilityControlInfo_t *) NULL, 1);
+			      (LTE_MobilityControlInfo_t *) NULL, 1);
 	//return(3);
 	break;
 
@@ -2765,7 +2779,7 @@ ue_scheduler(const module_id_t module_idP,
 	 physicalConfigDedicated->schedulingRequestConfig == NULL)
 	|| (UE_mac_inst[module_idP].
 	    physicalConfigDedicated->schedulingRequestConfig->present ==
-	    SchedulingRequestConfig_PR_release)) {
+	    LTE_SchedulingRequestConfig_PR_release)) {
 
 	// initiate RA with CRNTI included in msg3 (no contention) as descibed in 36.321 sec 5.1.5
 
@@ -2776,7 +2790,7 @@ ue_scheduler(const module_id_t module_idP,
     }
     // Put this in a function
     // Call PHR procedure as described in Section 5.4.6 in 36.321
-    if (UE_mac_inst[module_idP].PHR_state == MAC_MainConfig__phr_Config_PR_setup) {	// normal operation
+    if (UE_mac_inst[module_idP].PHR_state == LTE_MAC_MainConfig__phr_Config_PR_setup) {	// normal operation
 
 	if (UE_mac_inst[module_idP].PHR_reconfigured == 1) {	// upon (re)configuration of the power headroom reporting functionality by upper layers
 	    UE_mac_inst[module_idP].PHR_reporting_active = 1;
@@ -3037,7 +3051,7 @@ update_bsr(module_id_t module_idP, frame_t frameP,
 		    rlc_status = mac_rlc_status_ind(module_idP, UE_mac_inst[module_idP].crnti,eNB_index,frameP,subframeP,ENB_FLAG_NO,MBMS_FLAG_NO,
 		                                    lcid,
 		                                    0xFFFF //TBS is not used in RLC at this step, set a special value for debug
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                                           ,0, 0
 #endif
                                           );
@@ -3182,63 +3196,63 @@ int get_sf_periodicBSRTimer(uint8_t sf_offset)
 {
 
     switch (sf_offset) {
-    case PeriodicBSR_Timer_r12_sf5:
+    case LTE_PeriodicBSR_Timer_r12_sf5:
 	return 5;
 	break;
 
-    case PeriodicBSR_Timer_r12_sf10:
+    case LTE_PeriodicBSR_Timer_r12_sf10:
 	return 10;
 	break;
 
-    case PeriodicBSR_Timer_r12_sf16:
+    case LTE_PeriodicBSR_Timer_r12_sf16:
 	return 16;
 	break;
 
-    case PeriodicBSR_Timer_r12_sf20:
+    case LTE_PeriodicBSR_Timer_r12_sf20:
 	return 20;
 	break;
 
-    case PeriodicBSR_Timer_r12_sf32:
+    case LTE_PeriodicBSR_Timer_r12_sf32:
 	return 32;
 	break;
 
-    case PeriodicBSR_Timer_r12_sf40:
+    case LTE_PeriodicBSR_Timer_r12_sf40:
 	return 40;
 	break;
 
-    case PeriodicBSR_Timer_r12_sf64:
+    case LTE_PeriodicBSR_Timer_r12_sf64:
 	return 64;
 	break;
 
-    case PeriodicBSR_Timer_r12_sf80:
+    case LTE_PeriodicBSR_Timer_r12_sf80:
 	return 80;
 	break;
 
-    case PeriodicBSR_Timer_r12_sf128:
+    case LTE_PeriodicBSR_Timer_r12_sf128:
 	return 128;
 	break;
 
-    case PeriodicBSR_Timer_r12_sf160:
+    case LTE_PeriodicBSR_Timer_r12_sf160:
 	return 160;
 	break;
 
-    case PeriodicBSR_Timer_r12_sf320:
+    case LTE_PeriodicBSR_Timer_r12_sf320:
 	return 320;
 	break;
 
-    case PeriodicBSR_Timer_r12_sf640:
+    case LTE_PeriodicBSR_Timer_r12_sf640:
 	return 640;
 	break;
 
-    case PeriodicBSR_Timer_r12_sf1280:
+    case LTE_PeriodicBSR_Timer_r12_sf1280:
 	return 1280;
 	break;
 
-    case PeriodicBSR_Timer_r12_sf2560:
+    case LTE_PeriodicBSR_Timer_r12_sf2560:
 	return 2560;
 	break;
 
-    case PeriodicBSR_Timer_r12_infinity:
+    case LTE_PeriodicBSR_Timer_r12_infinity:
     default:
 	return 0xFFFF;
 	break;
@@ -3249,27 +3263,27 @@ int get_sf_retxBSRTimer(uint8_t sf_offset)
 {
 
     switch (sf_offset) {
-    case RetxBSR_Timer_r12_sf320:
+    case LTE_RetxBSR_Timer_r12_sf320:
 	return 320;
 	break;
 
-    case RetxBSR_Timer_r12_sf640:
+    case LTE_RetxBSR_Timer_r12_sf640:
 	return 640;
 	break;
 
-    case RetxBSR_Timer_r12_sf1280:
+    case LTE_RetxBSR_Timer_r12_sf1280:
 	return 1280;
 	break;
 
-    case RetxBSR_Timer_r12_sf2560:
+    case LTE_RetxBSR_Timer_r12_sf2560:
 	return 2560;
 	break;
 
-    case RetxBSR_Timer_r12_sf5120:
+    case LTE_RetxBSR_Timer_r12_sf5120:
 	return 5120;
 	break;
 
-    case RetxBSR_Timer_r12_sf10240:
+    case LTE_RetxBSR_Timer_r12_sf10240:
 	return 10240;
 	break;
 
@@ -3283,32 +3297,32 @@ int get_ms_bucketsizeduration(uint8_t bucketsizeduration)
 {
 
     switch (bucketsizeduration) {
-    case LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50:
+    case LTE_LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50:
 	return
 	    50;
 	break;
 
-    case LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms100:
+    case LTE_LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms100:
 	return
 	    100;
 	break;
 
-    case LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms150:
+    case LTE_LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms150:
 	return
 	    150;
 	break;
 
-    case LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms300:
+    case LTE_LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms300:
 	return
 	    300;
 	break;
 
-    case LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms500:
+    case LTE_LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms500:
 	return
 	    500;
 	break;
 
-    case LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms1000:
+    case LTE_LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms1000:
 	return
 	    1000;
 	break;
@@ -3369,19 +3383,19 @@ int get_sf_prohibitPHR_Timer(uint8_t prohibitPHR_Timer)
 int get_db_dl_PathlossChange(uint8_t dl_PathlossChange)
 {
     switch (dl_PathlossChange) {
-    case MAC_MainConfig__phr_Config__setup__dl_PathlossChange_dB1:
+    case LTE_MAC_MainConfig__phr_Config__setup__dl_PathlossChange_dB1:
 	return 1;
 	break;
 
-    case MAC_MainConfig__phr_Config__setup__dl_PathlossChange_dB3:
+    case LTE_MAC_MainConfig__phr_Config__setup__dl_PathlossChange_dB3:
 	return 3;
 	break;
 
-    case MAC_MainConfig__phr_Config__setup__dl_PathlossChange_dB6:
+    case LTE_MAC_MainConfig__phr_Config__setup__dl_PathlossChange_dB6:
 	return 6;
 	break;
 
-    case MAC_MainConfig__phr_Config__setup__dl_PathlossChange_infinity:
+    case LTE_MAC_MainConfig__phr_Config__setup__dl_PathlossChange_infinity:
     default:
 	return -1;
 	break;
@@ -3478,7 +3492,7 @@ SLSCH_t *ue_get_slsch(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_
                ue->slsch_lcid,
                req,
                (char*)(ue->slsch_pdu.payload + sizeof(SLSCH_SUBHEADER_24_Bit_DST_LONG))
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                ,ue->sourceL2Id,
                ue->destinationL2Id
 #endif
diff --git a/openair2/LAYER2/Makefile.inc b/openair2/LAYER2/Makefile.inc
deleted file mode 100644
index 2f5cea7555462e485dcf00b0d1ec9dc10a98feb5..0000000000000000000000000000000000000000
--- a/openair2/LAYER2/Makefile.inc
+++ /dev/null
@@ -1,118 +0,0 @@
-ifeq ($(OPENAIR2),1)
-EXTRA_CFLAGS += -DOPENAIR2
-endif
-EXTRA_CFLAGS += -DASSERT
-EXTRA_CFLAGS += -DNO_RRM
-
-COMMON_DIR = $(OPENAIR2_TOP)/COMMON
-L2_INTERFACE_DIR = $(OPENAIR2_TOP)/RRC/L2_INTERFACE
-RLC_UM_DIR = $(OPENAIR2_TOP)/LAYER2/RLC/UM_v9.3.0
-RLC_AM_DIR = $(OPENAIR2_TOP)/LAYER2/RLC/AM_v9.3.0
-RLC_TM_DIR = $(OPENAIR2_TOP)/LAYER2/RLC/TM_v9.3.0
-RLC_DIR = $(OPENAIR2_TOP)/LAYER2/RLC
-PDCP_DIR = $(OPENAIR2_TOP)/LAYER2/PDCP_v10.1.0
-PHY_INTERFACE_DIR = $(OPENAIR2_TOP)/PHY_INTERFACE
-RRC_DIR = $(OPENAIR2_TOP)/RRC/LITE
-L2_INTERFACE_DIR = $(OPENAIR2_TOP)/RRC/L2_INTERFACE
-MAC_DIR = $(OPENAIR2_TOP)/LAYER2/MAC
-RRC_CELL_DIR = $(OPENAIR2_TOP)/RRC/CELLULAR
-
-SOURCES_L2 +=  $(OPENAIR2_TOP)/LAYER2/openair2_proc.c 
-
-SOURCES_L2 +=  $(PDCP_DIR)/pdcp.c
-SOURCES_L2 +=  $(PDCP_DIR)/pdcp_fifo.c
-SOURCES_L2 +=  $(PDCP_DIR)/pdcp_sequence_manager.c
-SOURCES_L2 +=  $(PDCP_DIR)/pdcp_primitives.c
-SOURCES_L2 +=  $(PDCP_DIR)/pdcp_util.c
-SOURCES_L2 +=  $(PDCP_DIR)/pdcp_security.c
-SOURCES_L2 +=  $(PDCP_DIR)/pdcp_netlink.c
-
-SOURCES_L2 +=  $(RLC_AM_DIR)/rlc_am.c
-SOURCES_L2 +=  $(RLC_AM_DIR)/rlc_am_init.c
-SOURCES_L2 +=  $(RLC_AM_DIR)/rlc_am_timer_poll_retransmit.c
-SOURCES_L2 +=  $(RLC_AM_DIR)/rlc_am_timer_reordering.c
-SOURCES_L2 +=  $(RLC_AM_DIR)/rlc_am_timer_status_prohibit.c
-SOURCES_L2 +=  $(RLC_AM_DIR)/rlc_am_segment.c
-SOURCES_L2 +=  $(RLC_AM_DIR)/rlc_am_segments_holes.c
-SOURCES_L2 +=  $(RLC_AM_DIR)/rlc_am_in_sdu.c
-SOURCES_L2 +=  $(RLC_AM_DIR)/rlc_am_receiver.c
-SOURCES_L2 +=  $(RLC_AM_DIR)/rlc_am_retransmit.c
-SOURCES_L2 +=  $(RLC_AM_DIR)/rlc_am_windows.c
-SOURCES_L2 +=  $(RLC_AM_DIR)/rlc_am_rx_list.c
-SOURCES_L2 +=  $(RLC_AM_DIR)/rlc_am_reassembly.c
-SOURCES_L2 +=  $(RLC_AM_DIR)/rlc_am_status_report.c
-
-
-SOURCES_L2 +=  $(RLC_TM_DIR)/rlc_tm.c
-SOURCES_L2 +=  $(RLC_TM_DIR)/rlc_tm_init.c
-
-SOURCES_L2 +=  $(RLC_UM_DIR)/rlc_um.c
-SOURCES_L2 +=  $(RLC_UM_DIR)/rlc_um_fsm.c
-SOURCES_L2 +=  $(RLC_UM_DIR)/rlc_um_control_primitives.c
-SOURCES_L2 +=  $(RLC_UM_DIR)/rlc_um_segment.c
-SOURCES_L2 +=  $(RLC_UM_DIR)/rlc_um_reassembly.c
-SOURCES_L2 +=  $(RLC_UM_DIR)/rlc_um_receiver.c
-SOURCES_L2 +=  $(RLC_UM_DIR)/rlc_um_dar.c
-
-SOURCES_L2 +=  $(RLC_DIR)/rlc_mac.c
-SOURCES_L2 +=  $(RLC_DIR)/rlc.c
-SOURCES_L2 +=  $(RLC_DIR)/rlc_rrc.c
-SOURCES_L2 +=  $(RLC_DIR)/rlc_mpls.c
-
-RRC_OBJS =  $(RRC_DIR)/rrc_UE.o
-ifeq ($(ENABLE_RAL),1)
-RRC_OBJS +=  $(RRC_DIR)/rrc_UE_ral.o
-RRC_OBJS +=  $(RRC_DIR)/rrc_eNB_ral.o
-endif
-
-RRC_OBJS += $(RRC_DIR)/rrc_eNB.o
-RRC_OBJS += $(RRC_DIR)/rrc_eNB_UE_context.o
-RRC_OBJS += $(RRC_DIR)/rrc_eNB_S1AP.o
-ifdef USE_MME
-RRC_OBJS += $(RRC_DIR)/rrc_eNB_GTPV1U.o
-endif
-RRC_OBJS += $(RRC_DIR)/rrc_common.o
-RRC_OBJS += $(RRC_DIR)/L2_interface.o
-
-MAC_OBJS =  $(MAC_DIR)/lte_transport_init.o
-MAC_OBJS += $(MAC_DIR)/main.o
-MAC_OBJS += $(MAC_DIR)/ue_procedures.o
-MAC_OBJS += $(MAC_DIR)/ra_procedures.o
-MAC_OBJS += $(MAC_DIR)/l1_helpers.o
-MAC_OBJS += $(MAC_DIR)/rar_tools.o
-MAC_OBJS += $(MAC_DIR)/eNB_scheduler.o
-MAC_OBJS += $(MAC_DIR)/eNB_scheduler_dlsch.o
-MAC_OBJS += $(MAC_DIR)/eNB_scheduler_ulsch.o
-MAC_OBJS += $(MAC_DIR)/eNB_scheduler_mch.o
-MAC_OBJS += $(MAC_DIR)/eNB_scheduler_bch.o
-MAC_OBJS += $(MAC_DIR)/eNB_scheduler_primitives.o
-MAC_OBJS += $(MAC_DIR)/eNB_scheduler_RA.o
-MAC_OBJS += $(MAC_DIR)/pre_processor.o
-MAC_OBJS += $(MAC_DIR)/config.o
-
-L2_INTERFACE_OBJS = $(L2_INTERFACE_DIR)/openair_rrc_L2_interface.o
-
-L2_OBJS=$(addsuffix .o,$(basename $(SOURCES_L2))) $(PHY_INTERFACE_OBJS) $(MAC_OBJS) $(L2_INTERFACE_OBJS)
-
-L2_incl =  -I$(OPENAIR2_TOP)
-L2_incl =  -I$(OPENAIR_DIR)/common/utils/msc
-L2_incl += -I$(COMMON_DIR)
-L2_incl += -I$(RLC_DIR)
-L2_incl += -I$(RLC_AM_DIR)
-L2_incl += -I$(RLC_UM_DIR)
-L2_incl += -I$(RLC_TM_DIR)
-L2_incl += -I$(PDCP_DIR)
-L2_incl += -I$(OPENAIR3)/MESH
-L2_incl += -I$(OPENAIR2_TOP)/RRC/LITE/MESSAGES
-L2_incl += -I$(OPENAIR3)/MESH/RRM
-
-ifeq ($(rrc_cellular),1)
-  include $(RRC_CELL_DIR)/Makefile.inc
-  L2_OBJS += $(RRC_CELLULAR_OBJS)
-  L2_incl += -I$(OPENAIR2_TOP)/RRC/CELLULAR
-  EXTRA_CFLAGS += -DRRC_CELLULAR -DCELLULAR
-else
-  L2_OBJS += $(RRC_OBJS)
-  L2_incl += -I$(OPENAIR2_TOP)/RRC/LITE
-endif
-
diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp.c
index 076b5c3c6962026aae227ab7eb81510a603fa47f..790be174e2bcaf049ccaff5b6e46fe2075c91fda 100644
--- a/openair2/LAYER2/PDCP_v10.1.0/pdcp.c
+++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp.c
@@ -50,37 +50,40 @@
 #include "common/utils/LOG/vcd_signal_dumper.h"
 #include "msc.h"
 #include "common/ngran_types.h"
-
+#include "targets/COMMON/openairinterface5g_limits.h"
 #if defined(ENABLE_SECURITY)
-# include "UTIL/OSA/osa_defs.h"
+  #include "UTIL/OSA/osa_defs.h"
 #endif
 
 #if defined(ENABLE_ITTI)
-# include "intertask_interface.h"
+  #include "intertask_interface.h"
 #endif
 
 #if defined(LINK_ENB_PDCP_TO_GTPV1U)
-#  include "gtpv1u_eNB_task.h"
-#  include "gtpv1u.h"
+  #include "gtpv1u_eNB_task.h"
+  #include "gtpv1u.h"
 #endif
 
 #include "ENB_APP/enb_config.h"
 #include "LAYER2/PROTO_AGENT/proto_agent.h"
 
 extern int otg_enabled;
-
+#if defined(ENABLE_USE_MME)
+  extern uint8_t nfapi_mode;
+#endif
 #include "common/ran_context.h"
 extern RAN_CONTEXT_t RC;
+hash_table_t  *pdcp_coll_p = NULL;
 
 #ifdef MBMS_MULTICAST_OUT
-# include <sys/types.h>
-# include <sys/socket.h>
-# include <netinet/in.h>
-# include <netinet/ip.h>
-# include <netinet/udp.h>
-# include <unistd.h>
-
-static int mbms_socket = -1;
+  #include <sys/types.h>
+  #include <sys/socket.h>
+  #include <netinet/in.h>
+  #include <netinet/ip.h>
+  #include <netinet/udp.h>
+  #include <unistd.h>
+
+  static int mbms_socket = -1;
 #endif
 
 //-----------------------------------------------------------------------------
@@ -92,7 +95,7 @@ static int mbms_socket = -1;
  * code at targets/TEST/PDCP/test_pdcp.c:test_pdcp_data_req()
  */
 boolean_t pdcp_data_req(
-  protocol_ctxt_t*  ctxt_pP,
+  protocol_ctxt_t  *ctxt_pP,
   const srb_flag_t     srb_flagP,
   const rb_id_t        rb_idP,
   const mui_t          muiP,
@@ -100,14 +103,13 @@ boolean_t pdcp_data_req(
   const sdu_size_t     sdu_buffer_sizeP,
   unsigned char *const sdu_buffer_pP,
   const pdcp_transmission_mode_t modeP
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-    ,const uint32_t * const sourceL2Id
-    ,const uint32_t * const destinationL2Id
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  ,const uint32_t *const sourceL2Id
+  ,const uint32_t *const destinationL2Id
 #endif
 )
 //-----------------------------------------------------------------------------
 {
-
   pdcp_t            *pdcp_p          = NULL;
   uint8_t            i               = 0;
   uint8_t            pdcp_header_len = 0;
@@ -117,24 +119,17 @@ boolean_t pdcp_data_req(
   mem_block_t       *pdcp_pdu_p      = NULL;
   rlc_op_status_t    rlc_status;
   boolean_t          ret             = TRUE;
-
   hash_key_t         key             = HASHTABLE_NOT_A_KEY_VALUE;
   hashtable_rc_t     h_rc;
   uint8_t            rb_offset= (srb_flagP == 0) ? DTCH -1 : 0;
   uint16_t           pdcp_uid=0;
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_DATA_REQ,VCD_FUNCTION_IN);
   CHECK_CTXT_ARGS(ctxt_pP);
-
-
-  if (srb_flagP == 0) 
-  LOG_D(PDCP, "pdcp data req on drb %d, size %d, rnti %x, node_type %d \n", 
-              rb_idP, pdcp_pdu_size, ctxt_pP->rnti, RC.rrc[ctxt_pP->module_id]->node_type);
-
-
-
 #if T_TRACER
+
   if (ctxt_pP->enb_flag != ENB_FLAG_NO)
     T(T_ENB_PDCP_DL, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->rnti), T_INT(rb_idP), T_INT(sdu_buffer_sizeP));
+
 #endif
 
   if (sdu_buffer_sizeP == 0) {
@@ -146,34 +141,34 @@ boolean_t pdcp_data_req(
    * XXX MAX_IP_PACKET_SIZE is 4096, shouldn't this be MAX SDU size, which is 8188 bytes?
    */
   AssertFatal(sdu_buffer_sizeP<= MAX_IP_PACKET_SIZE,"Requested SDU size (%d) is bigger than that can be handled by PDCP (%u)!\n",
-          sdu_buffer_sizeP, MAX_IP_PACKET_SIZE);
-  
+              sdu_buffer_sizeP, MAX_IP_PACKET_SIZE);
+
   if (modeP == PDCP_TRANSMISSION_MODE_TRANSPARENT) {
     AssertError (rb_idP < NB_RB_MBMS_MAX, return FALSE, "RB id is too high (%u/%d) %u %u!\n", rb_idP, NB_RB_MBMS_MAX, ctxt_pP->module_id, ctxt_pP->rnti);
   } else {
     if (srb_flagP) {
       AssertError (rb_idP < 3, return FALSE, "RB id is too high (%u/%d) %u %u!\n", rb_idP, 3, ctxt_pP->module_id, ctxt_pP->rnti);
     } else {
-      AssertError (rb_idP < maxDRB, return FALSE, "RB id is too high (%u/%d) %u %u!\n", rb_idP, maxDRB, ctxt_pP->module_id, ctxt_pP->rnti);
+      AssertError (rb_idP < LTE_maxDRB, return FALSE, "RB id is too high (%u/%d) %u %u!\n", rb_idP, LTE_maxDRB, ctxt_pP->module_id, ctxt_pP->rnti);
     }
   }
 
   key = PDCP_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, srb_flagP);
-  h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p);
+  h_rc = hashtable_get(pdcp_coll_p, key, (void **)&pdcp_p);
 
   if (h_rc != HASH_TABLE_OK) {
     if (modeP != PDCP_TRANSMISSION_MODE_TRANSPARENT) {
       LOG_W(PDCP, PROTOCOL_CTXT_FMT" Instance is not configured for rb_id %d Ignoring SDU...\n",
-	    PROTOCOL_CTXT_ARGS(ctxt_pP),
-	    rb_idP);
+            PROTOCOL_CTXT_ARGS(ctxt_pP),
+            rb_idP);
       ctxt_pP->configured=FALSE;
       return FALSE;
     }
-  }else{
+  } else {
     // instance for a given RB is configured
     ctxt_pP->configured=TRUE;
   }
-    
+
   if (ctxt_pP->enb_flag == ENB_FLAG_YES) {
     start_meas(&eNB_pdcp_stats[ctxt_pP->module_id].data_req);
   } else {
@@ -190,7 +185,7 @@ boolean_t pdcp_data_req(
       memcpy(&pdcp_pdu_p->data[0], sdu_buffer_pP, sdu_buffer_sizeP);
 #if defined(DEBUG_PDCP_PAYLOAD)
       rlc_util_print_hex_octets(PDCP,
-                                (unsigned char*)&pdcp_pdu_p->data[0],
+                                (unsigned char *)&pdcp_pdu_p->data[0],
                                 sdu_buffer_sizeP);
 #endif
       if (RC.rrc[ctxt_pP->module_id]->node_type == ngran_eNB_CU
@@ -205,7 +200,7 @@ boolean_t pdcp_data_req(
       } else {
         rlc_status = rlc_data_req(ctxt_pP, srb_flagP, MBMS_FLAG_YES, rb_idP, muiP,
                                   confirmP, sdu_buffer_sizeP, pdcp_pdu_p
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                                   ,NULL, NULL
 #endif
                                   );
@@ -231,13 +226,11 @@ boolean_t pdcp_data_req(
     }
 
     pdcp_pdu_size = sdu_buffer_sizeP + pdcp_header_len + pdcp_tailer_len;
-
     LOG_D(PDCP, PROTOCOL_PDCP_CTXT_FMT"Data request notification  pdu size %d (header%d, trailer%d)\n",
           PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p),
           pdcp_pdu_size,
           pdcp_header_len,
           pdcp_tailer_len);
-
     /*
      * Allocate a new block for the new PDU (i.e. PDU header and SDU payload)
      */
@@ -249,7 +242,6 @@ boolean_t pdcp_data_req(
        *
        * Place User Plane PDCP Data PDU header first
        */
-
       if (srb_flagP) { // this Control plane PDCP Data PDU
         pdcp_control_plane_data_pdu_header pdu_header;
         pdu_header.sn = pdcp_get_next_tx_seq_number(pdcp_p);
@@ -257,7 +249,7 @@ boolean_t pdcp_data_req(
         memset(&pdu_header.mac_i[0],0,PDCP_CONTROL_PLANE_DATA_PDU_MAC_I_SIZE);
         memset(&pdcp_pdu_p->data[sdu_buffer_sizeP + pdcp_header_len],0,PDCP_CONTROL_PLANE_DATA_PDU_MAC_I_SIZE);
 
-        if (pdcp_serialize_control_plane_data_pdu_with_SRB_sn_buffer((unsigned char*)pdcp_pdu_p->data, &pdu_header) == FALSE) {
+        if (pdcp_serialize_control_plane_data_pdu_with_SRB_sn_buffer((unsigned char *)pdcp_pdu_p->data, &pdu_header) == FALSE) {
           LOG_E(PDCP, PROTOCOL_PDCP_CTXT_FMT" Cannot fill PDU buffer with relevant header fields!\n",
                 PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p));
 
@@ -276,12 +268,11 @@ boolean_t pdcp_data_req(
         pdu_header.sn = pdcp_get_next_tx_seq_number(pdcp_p);
         current_sn = pdu_header.sn ;
 
-        if (pdcp_serialize_user_plane_data_pdu_with_long_sn_buffer((unsigned char*)pdcp_pdu_p->data, &pdu_header) == FALSE) {
+        if (pdcp_serialize_user_plane_data_pdu_with_long_sn_buffer((unsigned char *)pdcp_pdu_p->data, &pdu_header) == FALSE) {
           LOG_E(PDCP, PROTOCOL_PDCP_CTXT_FMT" Cannot fill PDU buffer with relevant header fields!\n",
                 PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p));
-         
-          if (ctxt_pP->enb_flag == ENB_FLAG_YES) {
 
+          if (ctxt_pP->enb_flag == ENB_FLAG_YES) {
             stop_meas(&eNB_pdcp_stats[ctxt_pP->module_id].data_req);
           } else {
             stop_meas(&UE_pdcp_stats[ctxt_pP->module_id].data_req);
@@ -300,7 +291,6 @@ boolean_t pdcp_data_req(
               "There must be a problem with PDCP initialization, ignoring this PDU...\n",
               PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p),
               current_sn);
-
         free_mem_block(pdcp_pdu_p, __func__);
 
         if (ctxt_pP->enb_flag == ENB_FLAG_YES) {
@@ -314,7 +304,6 @@ boolean_t pdcp_data_req(
       }
 
       LOG_D(PDCP, "Sequence number %d is assigned to current PDU\n", current_sn);
-
       /* Then append data... */
       memcpy(&pdcp_pdu_p->data[pdcp_header_len], sdu_buffer_pP, sdu_buffer_sizeP);
 
@@ -330,7 +319,6 @@ boolean_t pdcp_data_req(
       if ((pdcp_p->security_activated != 0) &&
           (((pdcp_p->cipheringAlgorithm) != 0) ||
            ((pdcp_p->integrityProtAlgorithm) != 0))) {
-
         if (ctxt_pP->enb_flag == ENB_FLAG_YES) {
           start_meas(&eNB_pdcp_stats[ctxt_pP->module_id].apply_security);
         } else {
@@ -340,7 +328,7 @@ boolean_t pdcp_data_req(
         pdcp_apply_security(ctxt_pP,
                             pdcp_p,
                             srb_flagP,
-                            rb_idP % maxDRB,
+                            rb_idP % LTE_maxDRB,
                             pdcp_header_len,
                             current_sn,
                             pdcp_pdu_p->data,
@@ -354,7 +342,6 @@ boolean_t pdcp_data_req(
       }
 
 #endif
-
       /* Print octets of outgoing data in hexadecimal form */
       LOG_D(PDCP, "Following content with size %d will be sent over RLC (PDCP PDU header is the first two bytes)\n",
             pdcp_pdu_size);
@@ -385,7 +372,6 @@ boolean_t pdcp_data_req(
      * Ask sublayer to transmit data and check return value
      * to see if RLC succeeded
      */
-
     LOG_DUMPMSG(PDCP,DEBUG_PDCP,(char *)pdcp_pdu_p->data,pdcp_pdu_size,
                 "[MSG] PDCP DL %s PDU on rb_id %d\n",(srb_flagP)? "CONTROL" : "DATA", rb_idP);
 
@@ -419,7 +405,7 @@ boolean_t pdcp_data_req(
 
         rlc_status = rlc_data_req(ctxt_pP, srb_flagP, MBMS_FLAG_NO, rb_idP, muiP,
             confirmP, pdcp_pdu_size, pdcp_pdu_p
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                              ,sourceL2Id
                              ,destinationL2Id
 #endif
@@ -457,9 +443,7 @@ boolean_t pdcp_data_req(
     else // SRB
 #endif /*UETARGET*/ 
     {
-     LOG_I(PDCP, "Sending F1AP_DL_RRC_MESSAGE with ITTI\n");
 
-      //It should never get here
       if ((RC.rrc[ctxt_pP->module_id]->node_type  == ngran_eNB_CU)   ||
         (RC.rrc[ctxt_pP->module_id]->node_type   == ngran_ng_eNB_CU)||
         (RC.rrc[ctxt_pP->module_id]->node_type   == ngran_gNB_CU)  ) {
@@ -536,7 +520,7 @@ boolean_t pdcp_data_req(
    * so we return TRUE afterwards
    */
 
-  for (pdcp_uid=0; pdcp_uid< MAX_MOBILES_PER_ENB;pdcp_uid++){
+  for (pdcp_uid=0; pdcp_uid< MAX_MOBILES_PER_ENB; pdcp_uid++) {
     if (pdcp_enb[ctxt_pP->module_id].rnti[pdcp_uid] == ctxt_pP->rnti )
       break;
   }
@@ -547,26 +531,23 @@ boolean_t pdcp_data_req(
   Pdcp_stats_tx_bytes[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]+=sdu_buffer_sizeP;
   Pdcp_stats_tx_bytes_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]+=sdu_buffer_sizeP;
   Pdcp_stats_tx_sn[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]=current_sn;
-
   Pdcp_stats_tx_aiat[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]+= (pdcp_enb[ctxt_pP->module_id].sfn - Pdcp_stats_tx_iat[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]);
-  Pdcp_stats_tx_aiat_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]+= (pdcp_enb[ctxt_pP->module_id].sfn - Pdcp_stats_tx_iat[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]); 
+  Pdcp_stats_tx_aiat_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]+= (pdcp_enb[ctxt_pP->module_id].sfn - Pdcp_stats_tx_iat[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]);
   Pdcp_stats_tx_iat[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]=pdcp_enb[ctxt_pP->module_id].sfn;
-    
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_DATA_REQ,VCD_FUNCTION_OUT);
   return ret;
- 
 }
 
 
 //-----------------------------------------------------------------------------
 boolean_t
 pdcp_data_ind(
-  const protocol_ctxt_t* const ctxt_pP,
+  const protocol_ctxt_t *const ctxt_pP,
   const srb_flag_t   srb_flagP,
   const MBMS_flag_t  MBMS_flagP,
   const rb_id_t      rb_idP,
   const sdu_size_t   sdu_buffer_sizeP,
-  mem_block_t* const sdu_buffer_pP
+  mem_block_t *const sdu_buffer_pP
 )
 //-----------------------------------------------------------------------------
 {
@@ -582,21 +563,20 @@ pdcp_data_ind(
   hash_key_t      key             = HASHTABLE_NOT_A_KEY_VALUE;
   hashtable_rc_t  h_rc;
   uint8_t      rb_offset= (srb_flagP == 0) ? DTCH -1 :0;
-  uint16_t     pdcp_uid=0;      
+  uint16_t     pdcp_uid=0;
   uint8_t      oo_flag=0;
 #if defined(LINK_ENB_PDCP_TO_GTPV1U)
   MessageDef  *message_p        = NULL;
   uint8_t     *gtpu_buffer_p    = NULL;
 #endif
-
-
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_DATA_IND,VCD_FUNCTION_IN);
   LOG_DUMPMSG(PDCP,DEBUG_PDCP,(char *)sdu_buffer_pP->data,sdu_buffer_sizeP,
               "[MSG] PDCP UL %s PDU on rb_id %d\n", (srb_flagP)? "CONTROL" : "DATA", rb_idP);
-
 #if T_TRACER
+
   if (ctxt_pP->enb_flag != ENB_FLAG_NO)
     T(T_ENB_PDCP_UL, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->rnti), T_INT(rb_idP), T_INT(sdu_buffer_sizeP));
+
 #endif
 
   if (MBMS_flagP) {
@@ -615,7 +595,6 @@ pdcp_data_ind(
             rb_idP,
             sdu_buffer_sizeP,
             ctxt_pP->enb_flag);
-
     } else {
       LOG_D(PDCP, "Data indication notification for PDCP entity from UE %x to eNB %u "
             "and radio bearer ID %d rlc sdu size %d ctxt_pP->enb_flag %d\n",
@@ -625,21 +604,20 @@ pdcp_data_ind(
             sdu_buffer_sizeP,
             ctxt_pP->enb_flag);
     }
-
   } else {
-    rb_id = rb_idP % maxDRB;
-    AssertError (rb_id < maxDRB, return FALSE, "RB id is too high (%u/%d) %u UE %x!\n",
+    rb_id = rb_idP % LTE_maxDRB;
+    AssertError (rb_id < LTE_maxDRB, return FALSE, "RB id is too high (%u/%d) %u UE %x!\n",
                  rb_id,
-                 maxDRB,
+                 LTE_maxDRB,
                  ctxt_pP->module_id,
                  ctxt_pP->rnti);
     AssertError (rb_id > 0, return FALSE, "RB id is too low (%u/%d) %u UE %x!\n",
                  rb_id,
-                 maxDRB,
+                 LTE_maxDRB,
                  ctxt_pP->module_id,
                  ctxt_pP->rnti);
     key = PDCP_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_id, srb_flagP);
-    h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p);
+    h_rc = hashtable_get(pdcp_coll_p, key, (void **)&pdcp_p);
 
     if (h_rc != HASH_TABLE_OK) {
       LOG_W(PDCP,
@@ -674,16 +652,16 @@ pdcp_data_ind(
     if (srb_flagP) { //SRB1/2
       pdcp_header_len = PDCP_CONTROL_PLANE_DATA_PDU_SN_SIZE;
       pdcp_tailer_len = PDCP_CONTROL_PLANE_DATA_PDU_MAC_I_SIZE;
-      sequence_number =   pdcp_get_sequence_number_of_pdu_with_SRB_sn((unsigned char*)sdu_buffer_pP->data);
+      sequence_number =   pdcp_get_sequence_number_of_pdu_with_SRB_sn((unsigned char *)sdu_buffer_pP->data);
     } else { // DRB
       pdcp_tailer_len = 0;
 
       if (pdcp_p->seq_num_size == PDCP_SN_7BIT) {
         pdcp_header_len = PDCP_USER_PLANE_DATA_PDU_SHORT_SN_HEADER_SIZE;
-        sequence_number =     pdcp_get_sequence_number_of_pdu_with_short_sn((unsigned char*)sdu_buffer_pP->data);
+        sequence_number =     pdcp_get_sequence_number_of_pdu_with_short_sn((unsigned char *)sdu_buffer_pP->data);
       } else if (pdcp_p->seq_num_size == PDCP_SN_12BIT) {
         pdcp_header_len = PDCP_USER_PLANE_DATA_PDU_LONG_SN_HEADER_SIZE;
-        sequence_number =     pdcp_get_sequence_number_of_pdu_with_long_sn((unsigned char*)sdu_buffer_pP->data);
+        sequence_number =     pdcp_get_sequence_number_of_pdu_with_long_sn((unsigned char *)sdu_buffer_pP->data);
       } else {
         //sequence_number = 4095;
         LOG_E(PDCP,
@@ -765,19 +743,18 @@ pdcp_data_ind(
 
 #endif
       //rrc_lite_data_ind(module_id, //Modified MW - L2 Interface
-  	MSC_LOG_TX_MESSAGE(
-  	    (ctxt_pP->enb_flag == ENB_FLAG_NO)? MSC_PDCP_UE:MSC_PDCP_ENB,
+      MSC_LOG_TX_MESSAGE(
+        (ctxt_pP->enb_flag == ENB_FLAG_NO)? MSC_PDCP_UE:MSC_PDCP_ENB,
         (ctxt_pP->enb_flag == ENB_FLAG_NO)? MSC_RRC_UE:MSC_RRC_ENB,
         NULL,0,
         PROTOCOL_PDCP_CTXT_FMT" DATA-IND len %u",
         PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP, pdcp_p),
         sdu_buffer_sizeP - pdcp_header_len - pdcp_tailer_len);
-        rrc_data_ind(ctxt_pP,
-		   rb_id,
-		   sdu_buffer_sizeP - pdcp_header_len - pdcp_tailer_len,
-		   (uint8_t*)&sdu_buffer_pP->data[pdcp_header_len]);
-        free_mem_block(sdu_buffer_pP, __func__);
-
+      rrc_data_ind(ctxt_pP,
+                   rb_id,
+                   sdu_buffer_sizeP - pdcp_header_len - pdcp_tailer_len,
+                   (uint8_t *)&sdu_buffer_pP->data[pdcp_header_len]);
+      free_mem_block(sdu_buffer_pP, __func__);
 
       // free_mem_block(new_sdu, __func__);
       if (ctxt_pP->enb_flag) {
@@ -818,7 +795,6 @@ pdcp_data_ind(
       } else {
         stop_meas(&UE_pdcp_stats[ctxt_pP->module_id].validate_security);
       }
-
     }
 
 #endif
@@ -841,7 +817,6 @@ pdcp_data_ind(
   }
 
   // XXX Decompression would be done at this point
-
   /*
    * After checking incoming sequence number PDCP header
    * has to be stripped off so here we copy SDU buffer starting
@@ -857,13 +832,13 @@ pdcp_data_ind(
             sdu_buffer_sizeP - payload_offset );
 
     MSC_LOG_TX_MESSAGE(
-    		MSC_PDCP_ENB,
-    		MSC_GTPU_ENB,
-    		NULL,0,
-    		"0 GTPV1U_ENB_TUNNEL_DATA_REQ  ue %x rab %u len %u\n",
-    		ctxt_pP->rnti,
-    		rb_id + 4,
-    		sdu_buffer_sizeP - payload_offset);
+      MSC_PDCP_ENB,
+      MSC_GTPU_ENB,
+      NULL,0,
+      "0 GTPV1U_ENB_TUNNEL_DATA_REQ  ue %x rab %u len %u",
+      ctxt_pP->rnti,
+      rb_id + 4,
+      sdu_buffer_sizeP - payload_offset);
     //LOG_T(PDCP,"Sending to GTPV1U %d bytes\n", sdu_buffer_sizeP - payload_offset);
     gtpu_buffer_p = itti_malloc(TASK_PDCP_ENB, TASK_GTPV1_U,
                                 sdu_buffer_sizeP - payload_offset + GTPU_HEADER_OVERHEAD_MAX);
@@ -877,26 +852,25 @@ pdcp_data_ind(
     GTPV1U_ENB_TUNNEL_DATA_REQ(message_p).rnti         = ctxt_pP->rnti;
     GTPV1U_ENB_TUNNEL_DATA_REQ(message_p).rab_id       = rb_id + 4;
     itti_send_msg_to_task(TASK_GTPV1_U, INSTANCE_DEFAULT, message_p);
-    packet_forwarded = TRUE;    
+    packet_forwarded = TRUE;
   }
-  
+
 #else
   packet_forwarded = FALSE;
 #endif
-
 #ifdef MBMS_MULTICAST_OUT
+
   if ((MBMS_flagP != 0) && (mbms_socket != -1)) {
-    struct iphdr   *ip_header = (struct iphdr*)&sdu_buffer_pP->data[payload_offset];
-    struct udphdr *udp_header = (struct udphdr*)&sdu_buffer_pP->data[payload_offset + sizeof(struct iphdr)];
+    struct iphdr   *ip_header = (struct iphdr *)&sdu_buffer_pP->data[payload_offset];
+    struct udphdr *udp_header = (struct udphdr *)&sdu_buffer_pP->data[payload_offset + sizeof(struct iphdr)];
     struct sockaddr_in dest_addr;
-
     dest_addr.sin_family      = AF_INET;
     dest_addr.sin_port        = udp_header->dest;
     dest_addr.sin_addr.s_addr = ip_header->daddr;
-
-    sendto(mbms_socket, &sdu_buffer_pP->data[payload_offset], sdu_buffer_sizeP - payload_offset, MSG_DONTWAIT, (struct sockaddr*)&dest_addr, sizeof(dest_addr));
+    sendto(mbms_socket, &sdu_buffer_pP->data[payload_offset], sdu_buffer_sizeP - payload_offset, MSG_DONTWAIT, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
     packet_forwarded = TRUE;
   }
+
 #endif
 
   if (FALSE == packet_forwarded) {
@@ -919,47 +893,58 @@ pdcp_data_ind(
       if (ctxt_pP->enb_flag == ENB_FLAG_NO) {
         ((pdcp_data_ind_header_t *) new_sdu_p->data)->rb_id = rb_id;
 #if defined(ENABLE_USE_MME)
+
         /* for the UE compiled in S1 mode, we need 1 here
          * for the UE compiled in noS1 mode, we need 0
          * TODO: be sure of this
          */
-        ((pdcp_data_ind_header_t*) new_sdu_p->data)->inst  = 1;
+        if (nfapi_mode == 3) {
+#ifdef UESIM_EXPANSION
+          ((pdcp_data_ind_header_t *) new_sdu_p->data)->inst  = 0;
+#else
+          ((pdcp_data_ind_header_t *) new_sdu_p->data)->inst  = ctxt_pP->module_id;
+#endif
+        } else {
+          ((pdcp_data_ind_header_t *) new_sdu_p->data)->inst  = 1;
+        }
+
 #endif
       } else {
-        ((pdcp_data_ind_header_t*) new_sdu_p->data)->rb_id = rb_id + (ctxt_pP->module_id * maxDRB);
+        ((pdcp_data_ind_header_t *) new_sdu_p->data)->rb_id = rb_id + (ctxt_pP->module_id * LTE_maxDRB);
+        ((pdcp_data_ind_header_t *) new_sdu_p->data)->inst  = ctxt_pP->module_id;
       }
-      ((pdcp_data_ind_header_t*) new_sdu_p->data)->inst  = ctxt_pP->module_id;
 
+      // new_sdu_p->data->inst is set again in UE case so move to above.
+      //Panos: Commented this out because it cancels the assignment in #if defined(ENABLE_USE_MME) case
+      //((pdcp_data_ind_header_t*) new_sdu_p->data)->inst  = ctxt_pP->module_id;
 #ifdef DEBUG_PDCP_FIFO_FLUSH_SDU
       static uint32_t pdcp_inst = 0;
-      ((pdcp_data_ind_header_t*) new_sdu_p->data)->inst = pdcp_inst++;
-      LOG_D(PDCP, "inst=%d size=%d\n", ((pdcp_data_ind_header_t*) new_sdu_p->data)->inst, ((pdcp_data_ind_header_t *) new_sdu_p->data)->data_size);
+      ((pdcp_data_ind_header_t *) new_sdu_p->data)->inst = pdcp_inst++;
+      LOG_D(PDCP, "inst=%d size=%d\n", ((pdcp_data_ind_header_t *) new_sdu_p->data)->inst, ((pdcp_data_ind_header_t *) new_sdu_p->data)->data_size);
 #endif
-
+      //((pdcp_data_ind_header_t*) new_sdu_p->data)->inst = 1; //pdcp_inst++;
       memcpy(&new_sdu_p->data[sizeof (pdcp_data_ind_header_t)], \
              &sdu_buffer_pP->data[payload_offset], \
              sdu_buffer_sizeP - payload_offset);
       list_add_tail_eurecom (new_sdu_p, sdu_list_p);
-
-      
-      
     }
 
-  /* Print octets of incoming data in hexadecimal form */
-  LOG_D(PDCP, "Following content has been received from RLC (%d,%d)(PDCP header has already been removed):\n",
-	sdu_buffer_sizeP  - payload_offset + (int)sizeof(pdcp_data_ind_header_t),
-	sdu_buffer_sizeP  - payload_offset);
-  //util_print_hex_octets(PDCP, &new_sdu_p->data[sizeof (pdcp_data_ind_header_t)], sdu_buffer_sizeP - payload_offset);
-  //util_flush_hex_octets(PDCP, &new_sdu_p->data[sizeof (pdcp_data_ind_header_t)], sdu_buffer_sizeP - payload_offset);
-  
-  
+    /* Print octets of incoming data in hexadecimal form */
+    LOG_D(PDCP, "Following content has been received from RLC (%d,%d)(PDCP header has already been removed):\n",
+          sdu_buffer_sizeP  - payload_offset + (int)sizeof(pdcp_data_ind_header_t),
+          sdu_buffer_sizeP  - payload_offset);
+    //util_print_hex_octets(PDCP, &new_sdu_p->data[sizeof (pdcp_data_ind_header_t)], sdu_buffer_sizeP - payload_offset);
+    //util_flush_hex_octets(PDCP, &new_sdu_p->data[sizeof (pdcp_data_ind_header_t)], sdu_buffer_sizeP - payload_offset);
+
 #if defined(STOP_ON_IP_TRAFFIC_OVERLOAD)
-    else {
-      AssertFatal(0, PROTOCOL_PDCP_CTXT_FMT" PDCP_DATA_IND SDU DROPPED, OUT OF MEMORY \n",
-                  PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP, pdcp_p));
-    }
-#endif
+    /* This was an "orphan else" in tag 2019.w07 and discovered during merge.
+     * Commenting so it could be reintegrated. */
+    //else {
+    //  AssertFatal(0, PROTOCOL_PDCP_CTXT_FMT" PDCP_DATA_IND SDU DROPPED, OUT OF MEMORY \n",
+    //              PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP, pdcp_p));
+    //}
 
+#endif
   }
 
   /* Update PDCP statistics */
@@ -995,53 +980,53 @@ pdcp_data_ind(
   return TRUE;
 }
 
-void pdcp_update_stats(const protocol_ctxt_t* const  ctxt_pP){
-
+void pdcp_update_stats(const protocol_ctxt_t *const  ctxt_pP) {
   uint16_t           pdcp_uid = 0;
   uint8_t            rb_id     = 0;
-  
- // these stats are measured for both eNB and UE on per seond basis 
-  for (rb_id =0; rb_id < NB_RB_MAX; rb_id ++){
-    for (pdcp_uid=0; pdcp_uid< MAX_MOBILES_PER_ENB;pdcp_uid++){
+
+  // these stats are measured for both eNB and UE on per seond basis
+  for (rb_id =0; rb_id < NB_RB_MAX; rb_id ++) {
+    for (pdcp_uid=0; pdcp_uid< MAX_MOBILES_PER_ENB; pdcp_uid++) {
       //printf("frame %d and subframe %d \n", pdcp_enb[ctxt_pP->module_id].frame, pdcp_enb[ctxt_pP->module_id].subframe);
       // tx stats
       if (Pdcp_stats_tx_window_ms[ctxt_pP->module_id][pdcp_uid] > 0 &&
-          pdcp_enb[ctxt_pP->module_id].sfn % Pdcp_stats_tx_window_ms[ctxt_pP->module_id][pdcp_uid] == 0){
-	// unit: bit/s
-	Pdcp_stats_tx_throughput_w[ctxt_pP->module_id][pdcp_uid][rb_id]=Pdcp_stats_tx_bytes_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]*8;
-	Pdcp_stats_tx_w[ctxt_pP->module_id][pdcp_uid][rb_id]= Pdcp_stats_tx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id];
-	Pdcp_stats_tx_bytes_w[ctxt_pP->module_id][pdcp_uid][rb_id]= Pdcp_stats_tx_bytes_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id];
-	if (Pdcp_stats_tx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id] > 0){
-	  Pdcp_stats_tx_aiat_w[ctxt_pP->module_id][pdcp_uid][rb_id]=(Pdcp_stats_tx_aiat_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]/Pdcp_stats_tx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]);
-	}else {
-	  Pdcp_stats_tx_aiat_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0;
-	}
-	// reset the tmp vars 
-	Pdcp_stats_tx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0;
-	Pdcp_stats_tx_bytes_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0;
-	Pdcp_stats_tx_aiat_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0;
-	
+          pdcp_enb[ctxt_pP->module_id].sfn % Pdcp_stats_tx_window_ms[ctxt_pP->module_id][pdcp_uid] == 0) {
+        // unit: bit/s
+        Pdcp_stats_tx_throughput_w[ctxt_pP->module_id][pdcp_uid][rb_id]=Pdcp_stats_tx_bytes_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]*8;
+        Pdcp_stats_tx_w[ctxt_pP->module_id][pdcp_uid][rb_id]= Pdcp_stats_tx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id];
+        Pdcp_stats_tx_bytes_w[ctxt_pP->module_id][pdcp_uid][rb_id]= Pdcp_stats_tx_bytes_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id];
+
+        if (Pdcp_stats_tx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id] > 0) {
+          Pdcp_stats_tx_aiat_w[ctxt_pP->module_id][pdcp_uid][rb_id]=(Pdcp_stats_tx_aiat_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]/Pdcp_stats_tx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]);
+        } else {
+          Pdcp_stats_tx_aiat_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0;
+        }
+
+        // reset the tmp vars
+        Pdcp_stats_tx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0;
+        Pdcp_stats_tx_bytes_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0;
+        Pdcp_stats_tx_aiat_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0;
       }
+
       if (Pdcp_stats_rx_window_ms[ctxt_pP->module_id][pdcp_uid] > 0 &&
-          pdcp_enb[ctxt_pP->module_id].sfn % Pdcp_stats_rx_window_ms[ctxt_pP->module_id][pdcp_uid] == 0){
-	// rx stats
-	Pdcp_stats_rx_goodput_w[ctxt_pP->module_id][pdcp_uid][rb_id]=Pdcp_stats_rx_bytes_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]*8;
-	Pdcp_stats_rx_w[ctxt_pP->module_id][pdcp_uid][rb_id]= 	Pdcp_stats_rx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id];
-	Pdcp_stats_rx_bytes_w[ctxt_pP->module_id][pdcp_uid][rb_id]= Pdcp_stats_rx_bytes_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id];
-	
-	if(Pdcp_stats_rx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id] > 0){
-	  Pdcp_stats_rx_aiat_w[ctxt_pP->module_id][pdcp_uid][rb_id]= (Pdcp_stats_rx_aiat_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]/Pdcp_stats_rx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]);
-	} else {
-	  Pdcp_stats_rx_aiat_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0;
-	}
-	
-	// reset the tmp vars 
-	Pdcp_stats_rx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0;
-	Pdcp_stats_rx_bytes_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0;
-	Pdcp_stats_rx_aiat_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0;
-      } 
+          pdcp_enb[ctxt_pP->module_id].sfn % Pdcp_stats_rx_window_ms[ctxt_pP->module_id][pdcp_uid] == 0) {
+        // rx stats
+        Pdcp_stats_rx_goodput_w[ctxt_pP->module_id][pdcp_uid][rb_id]=Pdcp_stats_rx_bytes_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]*8;
+        Pdcp_stats_rx_w[ctxt_pP->module_id][pdcp_uid][rb_id]=   Pdcp_stats_rx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id];
+        Pdcp_stats_rx_bytes_w[ctxt_pP->module_id][pdcp_uid][rb_id]= Pdcp_stats_rx_bytes_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id];
+
+        if(Pdcp_stats_rx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id] > 0) {
+          Pdcp_stats_rx_aiat_w[ctxt_pP->module_id][pdcp_uid][rb_id]= (Pdcp_stats_rx_aiat_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]/Pdcp_stats_rx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]);
+        } else {
+          Pdcp_stats_rx_aiat_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0;
+        }
+
+        // reset the tmp vars
+        Pdcp_stats_rx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0;
+        Pdcp_stats_rx_bytes_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0;
+        Pdcp_stats_rx_aiat_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0;
+      }
     }
-    
   }
 }
 
@@ -1049,11 +1034,10 @@ void pdcp_update_stats(const protocol_ctxt_t* const  ctxt_pP){
 //-----------------------------------------------------------------------------
 void
 pdcp_run (
-  const protocol_ctxt_t* const  ctxt_pP
+  const protocol_ctxt_t *const  ctxt_pP
 )
 //-----------------------------------------------------------------------------
 {
-  
   if (ctxt_pP->enb_flag) {
     start_meas(&eNB_pdcp_stats[ctxt_pP->module_id].pdcp_run);
   } else {
@@ -1061,12 +1045,10 @@ pdcp_run (
   }
 
   pdcp_enb[ctxt_pP->module_id].sfn++; // range: 0 to 18,446,744,073,709,551,615
-  pdcp_enb[ctxt_pP->module_id].frame=ctxt_pP->frame; // 1023 
+  pdcp_enb[ctxt_pP->module_id].frame=ctxt_pP->frame; // 1023
   pdcp_enb[ctxt_pP->module_id].subframe= ctxt_pP->subframe;
   pdcp_update_stats(ctxt_pP);
-   
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_RUN, VCD_FUNCTION_IN);
-
 #if defined(ENABLE_ITTI)
   MessageDef   *msg_p;
   int           result;
@@ -1077,68 +1059,66 @@ pdcp_run (
     itti_poll_msg (ctxt_pP->enb_flag ? TASK_PDCP_ENB : TASK_PDCP_UE, &msg_p);
 
     if (msg_p != NULL) {
-
       switch (ITTI_MSG_ID(msg_p)) {
-      case RRC_DCCH_DATA_REQ:
-	PROTOCOL_CTXT_SET_BY_MODULE_ID(
-          &ctxt,
-          RRC_DCCH_DATA_REQ (msg_p).module_id,
-          RRC_DCCH_DATA_REQ (msg_p).enb_flag,
-          RRC_DCCH_DATA_REQ (msg_p).rnti,
-          RRC_DCCH_DATA_REQ (msg_p).frame, 
-	  0,
-	  RRC_DCCH_DATA_REQ (msg_p).eNB_index);
-
-        LOG_I(PDCP, PROTOCOL_CTXT_FMT"Received %s from %s: instance %d, rb_id %d, muiP %d, confirmP %d, mode %d\n",
-              PROTOCOL_CTXT_ARGS(&ctxt),
-              ITTI_MSG_NAME (msg_p),
-              ITTI_MSG_ORIGIN_NAME(msg_p),
-              ITTI_MSG_INSTANCE (msg_p),
-              RRC_DCCH_DATA_REQ (msg_p).rb_id,
-              RRC_DCCH_DATA_REQ (msg_p).muip,
-              RRC_DCCH_DATA_REQ (msg_p).confirmp,
-              RRC_DCCH_DATA_REQ (msg_p).mode);
-
-        log_dump(PDCP, RRC_DCCH_DATA_REQ (msg_p).sdu_p, RRC_DCCH_DATA_REQ (msg_p).sdu_size, LOG_DUMP_CHAR,"[MSG] pdcp run\n");
-
-        result = pdcp_data_req (&ctxt,
-                                SRB_FLAG_YES,
-                                RRC_DCCH_DATA_REQ (msg_p).rb_id,
-                                RRC_DCCH_DATA_REQ (msg_p).muip,
-                                RRC_DCCH_DATA_REQ (msg_p).confirmp,
-                                RRC_DCCH_DATA_REQ (msg_p).sdu_size,
-                                RRC_DCCH_DATA_REQ (msg_p).sdu_p,
-                                RRC_DCCH_DATA_REQ (msg_p).mode
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-                                , NULL, NULL
+        case RRC_DCCH_DATA_REQ:
+          PROTOCOL_CTXT_SET_BY_MODULE_ID(
+            &ctxt,
+            RRC_DCCH_DATA_REQ (msg_p).module_id,
+            RRC_DCCH_DATA_REQ (msg_p).enb_flag,
+            RRC_DCCH_DATA_REQ (msg_p).rnti,
+            RRC_DCCH_DATA_REQ (msg_p).frame,
+            0,
+            RRC_DCCH_DATA_REQ (msg_p).eNB_index);
+          LOG_D(PDCP, PROTOCOL_CTXT_FMT"Received %s from %s: instance %d, rb_id %d, muiP %d, confirmP %d, mode %d\n",
+                PROTOCOL_CTXT_ARGS(&ctxt),
+                ITTI_MSG_NAME (msg_p),
+                ITTI_MSG_ORIGIN_NAME(msg_p),
+                ITTI_MSG_INSTANCE (msg_p),
+                RRC_DCCH_DATA_REQ (msg_p).rb_id,
+                RRC_DCCH_DATA_REQ (msg_p).muip,
+                RRC_DCCH_DATA_REQ (msg_p).confirmp,
+                RRC_DCCH_DATA_REQ (msg_p).mode);
+          LOG_D(PDCP, "Before calling pdcp_data_req from pdcp_run! RRC_DCCH_DATA_REQ (msg_p).rb_id: %d \n", RRC_DCCH_DATA_REQ (msg_p).rb_id);
+          result = pdcp_data_req (&ctxt,
+                                  SRB_FLAG_YES,
+                                  RRC_DCCH_DATA_REQ (msg_p).rb_id,
+                                  RRC_DCCH_DATA_REQ (msg_p).muip,
+                                  RRC_DCCH_DATA_REQ (msg_p).confirmp,
+                                  RRC_DCCH_DATA_REQ (msg_p).sdu_size,
+                                  RRC_DCCH_DATA_REQ (msg_p).sdu_p,
+                                  RRC_DCCH_DATA_REQ (msg_p).mode
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                                  , NULL, NULL
 #endif
-                                );
-        if (result != TRUE)
-          LOG_E(PDCP, "PDCP data request failed!\n");
+                                 );
 
-        // Message buffer has been processed, free it now.
-        result = itti_free (ITTI_MSG_ORIGIN_ID(msg_p), RRC_DCCH_DATA_REQ (msg_p).sdu_p);
-        AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
-        break;
+          if (result != TRUE)
+            LOG_E(PDCP, "PDCP data request failed!\n");
 
-      case RRC_PCCH_DATA_REQ:
-      {
-        sdu_size_t     sdu_buffer_sizeP;
-        sdu_buffer_sizeP = RRC_PCCH_DATA_REQ(msg_p).sdu_size;
-        uint8_t CC_id = RRC_PCCH_DATA_REQ(msg_p).CC_id;
-        uint8_t ue_index = RRC_PCCH_DATA_REQ(msg_p).ue_index;
-        RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_paging[ue_index] = sdu_buffer_sizeP;
-        if (sdu_buffer_sizeP > 0) {
-        	memcpy(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].paging[ue_index], RRC_PCCH_DATA_REQ(msg_p).sdu_p, sdu_buffer_sizeP);
-        }
-        //paging pdcp log
-        LOG_D(PDCP, "PDCP Received RRC_PCCH_DATA_REQ CC_id %d length %d \n", CC_id, sdu_buffer_sizeP);
-      }
-      break;
+          // Message buffer has been processed, free it now.
+          result = itti_free (ITTI_MSG_ORIGIN_ID(msg_p), RRC_DCCH_DATA_REQ (msg_p).sdu_p);
+          AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
+          break;
 
-      default:
-        LOG_E(PDCP, "Received unexpected message %s\n", ITTI_MSG_NAME (msg_p));
+        case RRC_PCCH_DATA_REQ: {
+          sdu_size_t     sdu_buffer_sizeP;
+          sdu_buffer_sizeP = RRC_PCCH_DATA_REQ(msg_p).sdu_size;
+          uint8_t CC_id = RRC_PCCH_DATA_REQ(msg_p).CC_id;
+          uint8_t ue_index = RRC_PCCH_DATA_REQ(msg_p).ue_index;
+          RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_paging[ue_index] = sdu_buffer_sizeP;
+
+          if (sdu_buffer_sizeP > 0) {
+            memcpy(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].paging[ue_index], RRC_PCCH_DATA_REQ(msg_p).sdu_p, sdu_buffer_sizeP);
+          }
+
+          //paging pdcp log
+          LOG_D(PDCP, "PDCP Received RRC_PCCH_DATA_REQ CC_id %d length %d \n", CC_id, sdu_buffer_sizeP);
+        }
         break;
+
+        default:
+          LOG_E(PDCP, "Received unexpected message %s\n", ITTI_MSG_NAME (msg_p));
+          break;
       }
 
       result = itti_free (ITTI_MSG_ORIGIN_ID(msg_p), msg_p);
@@ -1147,7 +1127,6 @@ pdcp_run (
   } while(msg_p != NULL);
 
 #endif
-
   // IP/NAS -> PDCP traffic : TX, read the pkt from the upper layer buffer
 #if defined(LINK_ENB_PDCP_TO_GTPV1U)
 
@@ -1160,9 +1139,7 @@ pdcp_run (
   // PDCP -> NAS/IP traffic: RX
   if (ctxt_pP->enb_flag) {
     start_meas(&eNB_pdcp_stats[ctxt_pP->module_id].pdcp_ip);
-  }
-
-  else {
+  } else {
     start_meas(&UE_pdcp_stats[ctxt_pP->module_id].pdcp_ip);
   }
 
@@ -1179,6 +1156,7 @@ pdcp_run (
   } else {
     stop_meas(&UE_pdcp_stats[ctxt_pP->module_id].pdcp_run);
   }
+
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_RUN, VCD_FUNCTION_OUT);
 }
 
@@ -1217,46 +1195,49 @@ void pdcp_init_stats_UE(module_id_t mod, uint16_t uid)
   }
 }
 
-void pdcp_add_UE(const protocol_ctxt_t* const  ctxt_pP){
+void pdcp_add_UE(const protocol_ctxt_t *const  ctxt_pP) {
   int i, ue_flag=1; //, ret=-1; to be decied later
-  for (i=0; i < MAX_MOBILES_PER_ENB; i++){
+
+  for (i=0; i < MAX_MOBILES_PER_ENB; i++) {
     if (pdcp_enb[ctxt_pP->module_id].rnti[i] == ctxt_pP->rnti) {
       ue_flag=-1;
       break;
     }
   }
-  if (ue_flag == 1 ){
-    for (i=0; i < MAX_MOBILES_PER_ENB ; i++){
-      if (pdcp_enb[ctxt_pP->module_id].rnti[i] == 0 ){
-	pdcp_enb[ctxt_pP->module_id].rnti[i]=ctxt_pP->rnti;
-	pdcp_enb[ctxt_pP->module_id].uid[i]=i;
-	pdcp_enb[ctxt_pP->module_id].num_ues++;
-	LOG_I(PDCP,"add new uid is %d %x\n\n", i, ctxt_pP->rnti);
+
+  if (ue_flag == 1 ) {
+    for (i=0; i < MAX_MOBILES_PER_ENB ; i++) {
+      if (pdcp_enb[ctxt_pP->module_id].rnti[i] == 0 ) {
+        pdcp_enb[ctxt_pP->module_id].rnti[i]=ctxt_pP->rnti;
+        pdcp_enb[ctxt_pP->module_id].uid[i]=i;
+        pdcp_enb[ctxt_pP->module_id].num_ues++;
+        printf("add new uid is %d %x\n\n", i, ctxt_pP->rnti);
         pdcp_init_stats_UE(ctxt_pP->module_id, i);
-	// ret=1;
-	break;
+        // ret=1;
+        break;
       }
     }
   }
+
   //return ret;
 }
 
 //-----------------------------------------------------------------------------
 boolean_t
 pdcp_remove_UE(
-  const protocol_ctxt_t* const  ctxt_pP
+  const protocol_ctxt_t *const  ctxt_pP
 )
 //-----------------------------------------------------------------------------
 {
-  DRB_Identity_t  srb_id         = 0;
-  DRB_Identity_t  drb_id         = 0;
+  LTE_DRB_Identity_t  srb_id         = 0;
+  LTE_DRB_Identity_t  drb_id         = 0;
   hash_key_t      key            = HASHTABLE_NOT_A_KEY_VALUE;
   hashtable_rc_t  h_rc;
-  int i; 
-   // check and remove SRBs first
+  int i;
+  // check and remove SRBs first
 
-  for(int i = 0;i<MAX_MOBILES_PER_ENB;i++){
-    if(pdcp_eNB_UE_instance_to_rnti[i] == ctxt_pP->rnti){
+  for(int i = 0; i<MAX_MOBILES_PER_ENB; i++) {
+    if(pdcp_eNB_UE_instance_to_rnti[i] == ctxt_pP->rnti) {
       pdcp_eNB_UE_instance_to_rnti[i] = NOT_A_RNTI;
       break;
     }
@@ -1267,27 +1248,26 @@ pdcp_remove_UE(
     h_rc = hashtable_remove(pdcp_coll_p, key);
   }
 
-  for (drb_id=0; drb_id<maxDRB; drb_id++) {
+  for (drb_id=0; drb_id<LTE_maxDRB; drb_id++) {
     key = PDCP_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, drb_id, SRB_FLAG_NO);
     h_rc = hashtable_remove(pdcp_coll_p, key);
-
   }
 
   (void)h_rc; /* remove gcc warning "set but not used" */
 
   // remove ue for pdcp enb inst
-   for (i=0; i < MAX_MOBILES_PER_ENB; i++) {
+  for (i=0; i < MAX_MOBILES_PER_ENB; i++) {
     if (pdcp_enb[ctxt_pP->module_id].rnti[i] == ctxt_pP->rnti ) {
       LOG_I(PDCP, "remove uid is %d/%d %x\n", i,
-	    pdcp_enb[ctxt_pP->module_id].uid[i],
-	    pdcp_enb[ctxt_pP->module_id].rnti[i]);
+            pdcp_enb[ctxt_pP->module_id].uid[i],
+            pdcp_enb[ctxt_pP->module_id].rnti[i]);
       pdcp_enb[ctxt_pP->module_id].uid[i]=0;
       pdcp_enb[ctxt_pP->module_id].rnti[i]=0;
       pdcp_enb[ctxt_pP->module_id].num_ues--;
       break;
     }
   }
-   
+
   return 1;
 }
 
@@ -1295,47 +1275,45 @@ pdcp_remove_UE(
 //-----------------------------------------------------------------------------
 boolean_t
 rrc_pdcp_config_asn1_req (
-  const protocol_ctxt_t* const  ctxt_pP,
-  SRB_ToAddModList_t  *const srb2add_list_pP,
-  DRB_ToAddModList_t  *const drb2add_list_pP,
-  DRB_ToReleaseList_t *const drb2release_list_pP,
+  const protocol_ctxt_t *const  ctxt_pP,
+  LTE_SRB_ToAddModList_t  *const srb2add_list_pP,
+  LTE_DRB_ToAddModList_t  *const drb2add_list_pP,
+  LTE_DRB_ToReleaseList_t *const drb2release_list_pP,
   const uint8_t                   security_modeP,
   uint8_t                  *const kRRCenc_pP,
   uint8_t                  *const kRRCint_pP,
   uint8_t                  *const kUPenc_pP
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-  ,PMCH_InfoList_r9_t*  const pmch_InfoList_r9_pP
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+  ,LTE_PMCH_InfoList_r9_t  *const pmch_InfoList_r9_pP
 #endif
-  ,rb_id_t                 *const defaultDRB 
+  ,rb_id_t                 *const defaultDRB
 )
 //-----------------------------------------------------------------------------
 {
   long int        lc_id          = 0;
-  DRB_Identity_t  srb_id         = 0;
+  LTE_DRB_Identity_t  srb_id     = 0;
   long int        mch_id         = 0;
   rlc_mode_t      rlc_type       = RLC_MODE_NONE;
-  DRB_Identity_t  drb_id         = 0;
-  DRB_Identity_t *pdrb_id_p      = NULL;
+  LTE_DRB_Identity_t  drb_id     = 0;
+  LTE_DRB_Identity_t *pdrb_id_p  = NULL;
   uint8_t         drb_sn         = 12;
   uint8_t         srb_sn         = 5; // fixed sn for SRBs
   uint8_t         drb_report     = 0;
   long int        cnt            = 0;
   uint16_t        header_compression_profile = 0;
   config_action_t action                     = CONFIG_ACTION_ADD;
-  SRB_ToAddMod_t *srb_toaddmod_p = NULL;
-  DRB_ToAddMod_t *drb_toaddmod_p = NULL;
+  LTE_SRB_ToAddMod_t *srb_toaddmod_p = NULL;
+  LTE_DRB_ToAddMod_t *drb_toaddmod_p = NULL;
   pdcp_t         *pdcp_p         = NULL;
-
   hash_key_t      key            = HASHTABLE_NOT_A_KEY_VALUE;
   hashtable_rc_t  h_rc;
   hash_key_t      key_defaultDRB = HASHTABLE_NOT_A_KEY_VALUE;
   hashtable_rc_t  h_defaultDRB_rc;
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
   int i,j;
-  MBMS_SessionInfoList_r9_t *mbms_SessionInfoList_r9_p = NULL;
-  MBMS_SessionInfo_r9_t     *MBMS_SessionInfo_p        = NULL;
+  LTE_MBMS_SessionInfoList_r9_t *mbms_SessionInfoList_r9_p = NULL;
+  LTE_MBMS_SessionInfo_r9_t     *MBMS_SessionInfo_p        = NULL;
 #endif
-
   LOG_T(PDCP, PROTOCOL_CTXT_FMT" %s() SRB2ADD %p DRB2ADD %p DRB2RELEASE %p\n",
         PROTOCOL_CTXT_ARGS(ctxt_pP),
         __FUNCTION__,
@@ -1352,7 +1330,7 @@ rrc_pdcp_config_asn1_req (
       rlc_type = RLC_MODE_AM;
       lc_id = srb_id;
       key = PDCP_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, srb_id, SRB_FLAG_YES);
-      h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p);
+      h_rc = hashtable_get(pdcp_coll_p, key, (void **)&pdcp_p);
 
       if (h_rc == HASH_TABLE_OK) {
         action = CONFIG_ACTION_MODIFY;
@@ -1370,9 +1348,8 @@ rrc_pdcp_config_asn1_req (
                 key);
           free(pdcp_p);
           return TRUE;
-
-      } else {
-	  LOG_D(PDCP, PROTOCOL_PDCP_CTXT_FMT" CONFIG_ACTION_ADD key 0x%"PRIx64"\n",
+        } else {
+          LOG_D(PDCP, PROTOCOL_PDCP_CTXT_FMT" CONFIG_ACTION_ADD key 0x%"PRIx64"\n",
                 PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP, pdcp_p),
                 key);
         }
@@ -1380,15 +1357,37 @@ rrc_pdcp_config_asn1_req (
 
       if (srb_toaddmod_p->rlc_Config) {
         switch (srb_toaddmod_p->rlc_Config->present) {
-        case SRB_ToAddMod__rlc_Config_PR_NOTHING:
-          break;
+          case LTE_SRB_ToAddMod__rlc_Config_PR_NOTHING:
+            break;
+
+          case LTE_SRB_ToAddMod__rlc_Config_PR_explicitValue:
+            switch (srb_toaddmod_p->rlc_Config->choice.explicitValue.present) {
+              case LTE_RLC_Config_PR_NOTHING:
+                break;
+
+              default:
+                pdcp_config_req_asn1 (
+                  ctxt_pP,
+                  pdcp_p,
+                  SRB_FLAG_YES,
+                  rlc_type,
+                  action,
+                  lc_id,
+                  mch_id,
+                  srb_id,
+                  srb_sn,
+                  0, // drb_report
+                  0, // header compression
+                  security_modeP,
+                  kRRCenc_pP,
+                  kRRCint_pP,
+                  kUPenc_pP);
+                break;
+            }
 
-        case SRB_ToAddMod__rlc_Config_PR_explicitValue:
-          switch (srb_toaddmod_p->rlc_Config->choice.explicitValue.present) {
-          case RLC_Config_PR_NOTHING:
             break;
 
-          default:
+          case LTE_SRB_ToAddMod__rlc_Config_PR_defaultValue:
             pdcp_config_req_asn1 (
               ctxt_pP,
               pdcp_p,
@@ -1405,34 +1404,12 @@ rrc_pdcp_config_asn1_req (
               kRRCenc_pP,
               kRRCint_pP,
               kUPenc_pP);
+            // already the default values
             break;
-          }
 
-          break;
-
-        case SRB_ToAddMod__rlc_Config_PR_defaultValue:
-        	pdcp_config_req_asn1 (
-        	              ctxt_pP,
-        	              pdcp_p,
-        	              SRB_FLAG_YES,
-        	              rlc_type,
-        	              action,
-        	              lc_id,
-        	              mch_id,
-        	              srb_id,
-        	              srb_sn,
-        	              0, // drb_report
-        	              0, // header compression
-        	              security_modeP,
-        	              kRRCenc_pP,
-        	              kRRCint_pP,
-        	              kUPenc_pP);
-          // already the default values
-          break;
-
-        default:
-          DevParam(srb_toaddmod_p->rlc_Config->present, ctxt_pP->module_id, ctxt_pP->rnti);
-          break;
+          default:
+            DevParam(srb_toaddmod_p->rlc_Config->present, ctxt_pP->module_id, ctxt_pP->rnti);
+            break;
         }
       }
     }
@@ -1442,10 +1419,9 @@ rrc_pdcp_config_asn1_req (
 
   if (drb2add_list_pP != NULL) {
     for (cnt=0; cnt<drb2add_list_pP->list.count; cnt++) {
-
       drb_toaddmod_p = drb2add_list_pP->list.array[cnt];
-
       drb_id = drb_toaddmod_p->drb_Identity;// + drb_id_offset;
+
       if (drb_toaddmod_p->logicalChannelIdentity) {
         lc_id = *(drb_toaddmod_p->logicalChannelIdentity);
       } else {
@@ -1459,16 +1435,15 @@ rrc_pdcp_config_asn1_req (
         continue;
       }
 
-      DevCheck4(drb_id < maxDRB, drb_id, maxDRB, ctxt_pP->module_id, ctxt_pP->rnti);
+      DevCheck4(drb_id < LTE_maxDRB, drb_id, LTE_maxDRB, ctxt_pP->module_id, ctxt_pP->rnti);
       key = PDCP_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, drb_id, SRB_FLAG_NO);
-      h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p);
+      h_rc = hashtable_get(pdcp_coll_p, key, (void **)&pdcp_p);
 
       if (h_rc == HASH_TABLE_OK) {
         action = CONFIG_ACTION_MODIFY;
         LOG_D(PDCP, PROTOCOL_PDCP_CTXT_FMT" CONFIG_ACTION_MODIFY key 0x%"PRIx64"\n",
               PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP, pdcp_p),
               key);
-
       } else {
         action = CONFIG_ACTION_ADD;
         pdcp_p = calloc(1, sizeof(pdcp_t));
@@ -1498,7 +1473,7 @@ rrc_pdcp_config_asn1_req (
           LOG_D(PDCP, PROTOCOL_PDCP_CTXT_FMT" CONFIG_ACTION_ADD ADD key 0x%"PRIx64"\n",
                 PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP, pdcp_p),
                 key);
-         }
+        }
       }
 
       if (drb_toaddmod_p->pdcp_Config) {
@@ -1508,7 +1483,7 @@ rrc_pdcp_config_asn1_req (
 
         if (drb_toaddmod_p->pdcp_Config->rlc_AM) {
           drb_report = drb_toaddmod_p->pdcp_Config->rlc_AM->statusReportRequired;
-          drb_sn = PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits; // default SN size
+          drb_sn = LTE_PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits; // default SN size
           rlc_type = RLC_MODE_AM;
         }
 
@@ -1518,44 +1493,44 @@ rrc_pdcp_config_asn1_req (
         }
 
         switch (drb_toaddmod_p->pdcp_Config->headerCompression.present) {
-        case PDCP_Config__headerCompression_PR_NOTHING:
-        case PDCP_Config__headerCompression_PR_notUsed:
-          header_compression_profile=0x0;
-          break;
-
-        case PDCP_Config__headerCompression_PR_rohc:
-
-          // parse the struc and get the rohc profile
-          if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0001) {
-            header_compression_profile=0x0001;
-          } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0002) {
-            header_compression_profile=0x0002;
-          } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0003) {
-            header_compression_profile=0x0003;
-          } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0004) {
-            header_compression_profile=0x0004;
-          } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0006) {
-            header_compression_profile=0x0006;
-          } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0101) {
-            header_compression_profile=0x0101;
-          } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0102) {
-            header_compression_profile=0x0102;
-          } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0103) {
-            header_compression_profile=0x0103;
-          } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0104) {
-            header_compression_profile=0x0104;
-          } else {
+          case LTE_PDCP_Config__headerCompression_PR_NOTHING:
+          case LTE_PDCP_Config__headerCompression_PR_notUsed:
             header_compression_profile=0x0;
-            LOG_W(PDCP,"unknown header compresion profile\n");
-          }
+            break;
 
-          // set the applicable profile
-          break;
+          case LTE_PDCP_Config__headerCompression_PR_rohc:
+
+            // parse the struc and get the rohc profile
+            if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0001) {
+              header_compression_profile=0x0001;
+            } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0002) {
+              header_compression_profile=0x0002;
+            } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0003) {
+              header_compression_profile=0x0003;
+            } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0004) {
+              header_compression_profile=0x0004;
+            } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0006) {
+              header_compression_profile=0x0006;
+            } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0101) {
+              header_compression_profile=0x0101;
+            } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0102) {
+              header_compression_profile=0x0102;
+            } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0103) {
+              header_compression_profile=0x0103;
+            } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0104) {
+              header_compression_profile=0x0104;
+            } else {
+              header_compression_profile=0x0;
+              LOG_W(PDCP,"unknown header compresion profile\n");
+            }
+
+            // set the applicable profile
+            break;
 
-        default:
-          LOG_W(PDCP,PROTOCOL_PDCP_CTXT_FMT"[RB %ld] unknown drb_toaddmod->PDCP_Config->headerCompression->present \n",
-                PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p), drb_id);
-          break;
+          default:
+            LOG_W(PDCP,PROTOCOL_PDCP_CTXT_FMT"[RB %ld] unknown drb_toaddmod->PDCP_Config->headerCompression->present \n",
+                  PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p), drb_id);
+            break;
         }
 
         pdcp_config_req_asn1 (
@@ -1583,7 +1558,7 @@ rrc_pdcp_config_asn1_req (
       pdrb_id_p = drb2release_list_pP->list.array[cnt];
       drb_id =  *pdrb_id_p;
       key = PDCP_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, drb_id, SRB_FLAG_NO);
-      h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p);
+      h_rc = hashtable_get(pdcp_coll_p, key, (void **)&pdcp_p);
 
       if (h_rc != HASH_TABLE_OK) {
         LOG_E(PDCP, PROTOCOL_CTXT_FMT" PDCP REMOVE FAILED drb_id %ld\n",
@@ -1591,8 +1566,8 @@ rrc_pdcp_config_asn1_req (
               drb_id);
         continue;
       }
-      lc_id = pdcp_p->lcid;
 
+      lc_id = pdcp_p->lcid;
       action = CONFIG_ACTION_REMOVE;
       pdcp_config_req_asn1 (
         ctxt_pP,
@@ -1615,7 +1590,7 @@ rrc_pdcp_config_asn1_req (
       if ((defaultDRB != NULL) && (*defaultDRB == drb_id)) {
         // default DRB being removed. nevertheless this shouldn't happen as removing default DRB is not allowed in standard
         key_defaultDRB = PDCP_COLL_KEY_DEFAULT_DRB_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag);
-        h_defaultDRB_rc = hashtable_get(pdcp_coll_p, key_defaultDRB, (void**)&pdcp_p);
+        h_defaultDRB_rc = hashtable_get(pdcp_coll_p, key_defaultDRB, (void **)&pdcp_p);
 
         if (h_defaultDRB_rc == HASH_TABLE_OK) {
           h_defaultDRB_rc = hashtable_remove(pdcp_coll_p, key_defaultDRB);
@@ -1628,7 +1603,7 @@ rrc_pdcp_config_asn1_req (
     }
   }
 
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
 
   if (pmch_InfoList_r9_pP != NULL) {
     for (i=0; i<pmch_InfoList_r9_pP->list.count; i++) {
@@ -1636,16 +1611,18 @@ rrc_pdcp_config_asn1_req (
 
       for (j=0; j<mbms_SessionInfoList_r9_p->list.count; j++) {
         MBMS_SessionInfo_p = mbms_SessionInfoList_r9_p->list.array[j];
+
         if (MBMS_SessionInfo_p->sessionId_r9)
           lc_id = MBMS_SessionInfo_p->sessionId_r9->buf[0];
         else
           lc_id = MBMS_SessionInfo_p->logicalChannelIdentity_r9;
+
         mch_id = MBMS_SessionInfo_p->tmgi_r9.serviceId_r9.buf[2]; //serviceId is 3-octet string
-//        mch_id = j;
+        //        mch_id = j;
 
         // can set the mch_id = i
         if (ctxt_pP->enb_flag) {
-          drb_id =  (mch_id * maxSessionPerPMCH ) + lc_id ;//+ (maxDRB + 3)*MAX_MOBILES_PER_ENB; // 1
+          drb_id =  (mch_id * LTE_maxSessionPerPMCH ) + lc_id ;//+ (LTE_maxDRB + 3)*MAX_MOBILES_PER_ENB; // 1
 
           if (pdcp_mbms_array_eNB[ctxt_pP->module_id][mch_id][lc_id].instanciated_instance == TRUE) {
             action = CONFIG_ACTION_MBMS_MODIFY;
@@ -1653,7 +1630,7 @@ rrc_pdcp_config_asn1_req (
             action = CONFIG_ACTION_MBMS_ADD;
           }
         } else {
-          drb_id =  (mch_id * maxSessionPerPMCH ) + lc_id; // + (maxDRB + 3); // 15
+          drb_id =  (mch_id * LTE_maxSessionPerPMCH ) + lc_id; // + (LTE_maxDRB + 3); // 15
 
           if (pdcp_mbms_array_ue[ctxt_pP->module_id][mch_id][lc_id].instanciated_instance == TRUE) {
             action = CONFIG_ACTION_MBMS_MODIFY;
@@ -1663,13 +1640,12 @@ rrc_pdcp_config_asn1_req (
         }
 
         LOG_D(PDCP, "lc_id (%02ld) mch_id(%02x,%02x,%02x) drb_id(%ld) action(%d)\n",
-          lc_id,
-          MBMS_SessionInfo_p->tmgi_r9.serviceId_r9.buf[0],
-          MBMS_SessionInfo_p->tmgi_r9.serviceId_r9.buf[1],
-          MBMS_SessionInfo_p->tmgi_r9.serviceId_r9.buf[2],
-          drb_id,
-          action);
-
+              lc_id,
+              MBMS_SessionInfo_p->tmgi_r9.serviceId_r9.buf[0],
+              MBMS_SessionInfo_p->tmgi_r9.serviceId_r9.buf[1],
+              MBMS_SessionInfo_p->tmgi_r9.serviceId_r9.buf[2],
+              drb_id,
+              action);
         pdcp_config_req_asn1 (
           ctxt_pP,
           NULL,  // unused for MBMS
@@ -1697,8 +1673,8 @@ rrc_pdcp_config_asn1_req (
 //-----------------------------------------------------------------------------
 boolean_t
 pdcp_config_req_asn1 (
-  const protocol_ctxt_t* const  ctxt_pP,
-  pdcp_t         * const        pdcp_pP,
+  const protocol_ctxt_t *const  ctxt_pP,
+  pdcp_t          *const        pdcp_pP,
   const srb_flag_t              srb_flagP,
   const rlc_mode_t              rlc_modeP,
   const config_action_t         actionP,
@@ -1714,179 +1690,183 @@ pdcp_config_req_asn1 (
   uint8_t         *const        kUPenc_pP)
 //-----------------------------------------------------------------------------
 {
-  
   switch (actionP) {
-  case CONFIG_ACTION_ADD:
-    DevAssert(pdcp_pP != NULL);
-    if (ctxt_pP->enb_flag == ENB_FLAG_YES) {
-      pdcp_pP->is_ue = FALSE;
-      pdcp_add_UE(ctxt_pP);
-      
-      //pdcp_eNB_UE_instance_to_rnti[ctxtP->module_id] = ctxt_pP->rnti;
-//      pdcp_eNB_UE_instance_to_rnti[pdcp_eNB_UE_instance_to_rnti_index] = ctxt_pP->rnti;
-      if( srb_flagP == SRB_FLAG_NO ) {
-          for(int i = 0;i<MAX_MOBILES_PER_ENB;i++){
-              if(pdcp_eNB_UE_instance_to_rnti[pdcp_eNB_UE_instance_to_rnti_index] == NOT_A_RNTI){
-                  break;
-              }
-              pdcp_eNB_UE_instance_to_rnti_index = (pdcp_eNB_UE_instance_to_rnti_index + 1) % MAX_MOBILES_PER_ENB;
+    case CONFIG_ACTION_ADD:
+      DevAssert(pdcp_pP != NULL);
+
+      if (ctxt_pP->enb_flag == ENB_FLAG_YES) {
+        pdcp_pP->is_ue = FALSE;
+        pdcp_add_UE(ctxt_pP);
+
+        //pdcp_eNB_UE_instance_to_rnti[ctxtP->module_id] = ctxt_pP->rnti;
+        //      pdcp_eNB_UE_instance_to_rnti[pdcp_eNB_UE_instance_to_rnti_index] = ctxt_pP->rnti;
+        if( srb_flagP == SRB_FLAG_NO ) {
+          for(int i = 0; i<MAX_MOBILES_PER_ENB; i++) {
+            if(pdcp_eNB_UE_instance_to_rnti[pdcp_eNB_UE_instance_to_rnti_index] == NOT_A_RNTI) {
+              break;
+            }
+
+            pdcp_eNB_UE_instance_to_rnti_index = (pdcp_eNB_UE_instance_to_rnti_index + 1) % MAX_MOBILES_PER_ENB;
           }
+
           pdcp_eNB_UE_instance_to_rnti[pdcp_eNB_UE_instance_to_rnti_index] = ctxt_pP->rnti;
           pdcp_eNB_UE_instance_to_rnti_index = (pdcp_eNB_UE_instance_to_rnti_index + 1) % MAX_MOBILES_PER_ENB;
+        }
+
+        //pdcp_eNB_UE_instance_to_rnti_index = (pdcp_eNB_UE_instance_to_rnti_index + 1) % MAX_MOBILES_PER_ENB;
+      } else {
+        pdcp_pP->is_ue = TRUE;
+        pdcp_UE_UE_module_id_to_rnti[ctxt_pP->module_id] = ctxt_pP->rnti;
       }
-      //pdcp_eNB_UE_instance_to_rnti_index = (pdcp_eNB_UE_instance_to_rnti_index + 1) % MAX_MOBILES_PER_ENB;
-    } else {
-      pdcp_pP->is_ue = TRUE;
-      pdcp_UE_UE_module_id_to_rnti[ctxt_pP->module_id] = ctxt_pP->rnti;
-    }
-    pdcp_pP->is_srb                     = (srb_flagP == SRB_FLAG_YES) ? TRUE : FALSE;
-    pdcp_pP->lcid                       = lc_idP;
-    pdcp_pP->rb_id                      = rb_idP;
-    pdcp_pP->header_compression_profile = header_compression_profileP;
-    pdcp_pP->status_report              = rb_reportP;
-
-    if (rb_snP == PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits) {
-      pdcp_pP->seq_num_size = PDCP_SN_12BIT;
-    } else if (rb_snP == PDCP_Config__rlc_UM__pdcp_SN_Size_len7bits) {
-      pdcp_pP->seq_num_size = PDCP_SN_7BIT;
-    } else {
-      pdcp_pP->seq_num_size = PDCP_SN_5BIT;
-    }
 
+      pdcp_pP->is_srb                     = (srb_flagP == SRB_FLAG_YES) ? TRUE : FALSE;
+      pdcp_pP->lcid                       = lc_idP;
+      pdcp_pP->rb_id                      = rb_idP;
+      pdcp_pP->header_compression_profile = header_compression_profileP;
+      pdcp_pP->status_report              = rb_reportP;
 
-    pdcp_pP->rlc_mode                         = rlc_modeP;
-    pdcp_pP->next_pdcp_tx_sn                  = 0;
-    pdcp_pP->next_pdcp_rx_sn                  = 0;
-    pdcp_pP->next_pdcp_rx_sn_before_integrity = 0;
-    pdcp_pP->tx_hfn                           = 0;
-    pdcp_pP->rx_hfn                           = 0;
-    pdcp_pP->last_submitted_pdcp_rx_sn        = 4095;
-    pdcp_pP->first_missing_pdu                = -1;
-    pdcp_pP->rx_hfn_offset                    = 0;
+      if (rb_snP == LTE_PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits) {
+        pdcp_pP->seq_num_size = PDCP_SN_12BIT;
+      } else if (rb_snP == LTE_PDCP_Config__rlc_UM__pdcp_SN_Size_len7bits) {
+        pdcp_pP->seq_num_size = PDCP_SN_7BIT;
+      } else {
+        pdcp_pP->seq_num_size = PDCP_SN_5BIT;
+      }
 
-    LOG_I(PDCP, PROTOCOL_PDCP_CTXT_FMT" Action ADD  LCID %d (%s id %d) "
+      pdcp_pP->rlc_mode                         = rlc_modeP;
+      pdcp_pP->next_pdcp_tx_sn                  = 0;
+      pdcp_pP->next_pdcp_rx_sn                  = 0;
+      pdcp_pP->next_pdcp_rx_sn_before_integrity = 0;
+      pdcp_pP->tx_hfn                           = 0;
+      pdcp_pP->rx_hfn                           = 0;
+      pdcp_pP->last_submitted_pdcp_rx_sn        = 4095;
+      pdcp_pP->first_missing_pdu                = -1;
+      pdcp_pP->rx_hfn_offset                    = 0;
+      LOG_I(PDCP, PROTOCOL_PDCP_CTXT_FMT" Action ADD  LCID %d (%s id %d) "
             "configured with SN size %d bits and RLC %s\n",
-          PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_pP),
-          lc_idP,
-	  (srb_flagP == SRB_FLAG_YES) ? "SRB" : "DRB",
+            PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_pP),
+            lc_idP,
+            (srb_flagP == SRB_FLAG_YES) ? "SRB" : "DRB",
+            rb_idP,
+            pdcp_pP->seq_num_size,
+            (rlc_modeP == RLC_MODE_AM ) ? "AM" : (rlc_modeP == RLC_MODE_TM) ? "TM" : "UM");
+
+      /* Setup security */
+      if (security_modeP != 0xff) {
+        pdcp_config_set_security(
+          ctxt_pP,
+          pdcp_pP,
           rb_idP,
-          pdcp_pP->seq_num_size,
-	  (rlc_modeP == RLC_MODE_AM ) ? "AM" : (rlc_modeP == RLC_MODE_TM) ? "TM" : "UM");
-    /* Setup security */
-    if (security_modeP != 0xff) {
-      pdcp_config_set_security(
-        ctxt_pP,
-        pdcp_pP,
-        rb_idP,
-        lc_idP,
-        security_modeP,
-        kRRCenc_pP,
-        kRRCint_pP,
-        kUPenc_pP);
-    }
-    break;
+          lc_idP,
+          security_modeP,
+          kRRCenc_pP,
+          kRRCint_pP,
+          kUPenc_pP);
+      }
 
-  case CONFIG_ACTION_MODIFY:
-    DevAssert(pdcp_pP != NULL);
-    pdcp_pP->header_compression_profile=header_compression_profileP;
-    pdcp_pP->status_report = rb_reportP;
-    pdcp_pP->rlc_mode = rlc_modeP;
+      break;
 
-    /* Setup security */
-    if (security_modeP != 0xff) {
-      pdcp_config_set_security(
-        ctxt_pP,
-        pdcp_pP,
-        rb_idP,
-        lc_idP,
-        security_modeP,
-        kRRCenc_pP,
-        kRRCint_pP,
-        kUPenc_pP);
-    }
+    case CONFIG_ACTION_MODIFY:
+      DevAssert(pdcp_pP != NULL);
+      pdcp_pP->header_compression_profile=header_compression_profileP;
+      pdcp_pP->status_report = rb_reportP;
+      pdcp_pP->rlc_mode = rlc_modeP;
 
-    if (rb_snP == PDCP_Config__rlc_UM__pdcp_SN_Size_len7bits) {
-      pdcp_pP->seq_num_size = 7;
-    } else if (rb_snP == PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits) {
-      pdcp_pP->seq_num_size = 12;
-    } else {
-      pdcp_pP->seq_num_size=5;
-    }
+      /* Setup security */
+      if (security_modeP != 0xff) {
+        pdcp_config_set_security(
+          ctxt_pP,
+          pdcp_pP,
+          rb_idP,
+          lc_idP,
+          security_modeP,
+          kRRCenc_pP,
+          kRRCint_pP,
+          kUPenc_pP);
+      }
 
-    LOG_I(PDCP,PROTOCOL_PDCP_CTXT_FMT" Action MODIFY LCID %d "
+      if (rb_snP == LTE_PDCP_Config__rlc_UM__pdcp_SN_Size_len7bits) {
+        pdcp_pP->seq_num_size = 7;
+      } else if (rb_snP == LTE_PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits) {
+        pdcp_pP->seq_num_size = 12;
+      } else {
+        pdcp_pP->seq_num_size=5;
+      }
+
+      LOG_I(PDCP,PROTOCOL_PDCP_CTXT_FMT" Action MODIFY LCID %d "
             "RB id %d reconfigured with SN size %d and RLC %s \n",
-          PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_pP),
-          lc_idP,
-          rb_idP,
-          rb_snP,
+            PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_pP),
+            lc_idP,
+            rb_idP,
+            rb_snP,
             (rlc_modeP == RLC_MODE_AM) ? "AM" : (rlc_modeP == RLC_MODE_TM) ? "TM" : "UM");
-    break;
+      break;
 
-  case CONFIG_ACTION_REMOVE:
-    DevAssert(pdcp_pP != NULL);
-//#warning "TODO pdcp_module_id_to_rnti"
-    //pdcp_module_id_to_rnti[ctxt_pP.module_id ][dst_id] = NOT_A_RNTI;
-    LOG_D(PDCP, PROTOCOL_PDCP_CTXT_FMT" CONFIG_ACTION_REMOVE LCID %d RBID %d configured\n",
-          PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_pP),
-          lc_idP,
-          rb_idP);
+    case CONFIG_ACTION_REMOVE:
+      DevAssert(pdcp_pP != NULL);
+      //#warning "TODO pdcp_module_id_to_rnti"
+      //pdcp_module_id_to_rnti[ctxt_pP.module_id ][dst_id] = NOT_A_RNTI;
+      LOG_D(PDCP, PROTOCOL_PDCP_CTXT_FMT" CONFIG_ACTION_REMOVE LCID %d RBID %d configured\n",
+            PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_pP),
+            lc_idP,
+            rb_idP);
 
-   if (ctxt_pP->enb_flag == ENB_FLAG_YES) {
-     // pdcp_remove_UE(ctxt_pP);
-   }
+      if (ctxt_pP->enb_flag == ENB_FLAG_YES) {
+        // pdcp_remove_UE(ctxt_pP);
+      }
 
-    /* Security keys */
-    if (pdcp_pP->kUPenc != NULL) {
-      free(pdcp_pP->kUPenc);
-    }
+      /* Security keys */
+      if (pdcp_pP->kUPenc != NULL) {
+        free(pdcp_pP->kUPenc);
+      }
 
-    if (pdcp_pP->kRRCint != NULL) {
-      free(pdcp_pP->kRRCint);
-    }
+      if (pdcp_pP->kRRCint != NULL) {
+        free(pdcp_pP->kRRCint);
+      }
 
-    if (pdcp_pP->kRRCenc != NULL) {
-      free(pdcp_pP->kRRCenc);
-    }
+      if (pdcp_pP->kRRCenc != NULL) {
+        free(pdcp_pP->kRRCenc);
+      }
 
-    memset(pdcp_pP, 0, sizeof(pdcp_t));
-    break;
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-
-  case CONFIG_ACTION_MBMS_ADD:
-  case CONFIG_ACTION_MBMS_MODIFY:
-    LOG_D(PDCP," %s service_id/mch index %d, session_id/lcid %d, rbid %d configured\n",
-          //PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_pP),
-          actionP == CONFIG_ACTION_MBMS_ADD ? "CONFIG_ACTION_MBMS_ADD" : "CONFIG_ACTION_MBMS_MODIFY",
-          mch_idP,
-          lc_idP,
-          rb_idP);
+      memset(pdcp_pP, 0, sizeof(pdcp_t));
+      break;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+
+    case CONFIG_ACTION_MBMS_ADD:
+    case CONFIG_ACTION_MBMS_MODIFY:
+      LOG_D(PDCP," %s service_id/mch index %d, session_id/lcid %d, rbid %d configured\n",
+            //PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_pP),
+            actionP == CONFIG_ACTION_MBMS_ADD ? "CONFIG_ACTION_MBMS_ADD" : "CONFIG_ACTION_MBMS_MODIFY",
+            mch_idP,
+            lc_idP,
+            rb_idP);
 
-    if (ctxt_pP->enb_flag == ENB_FLAG_YES) {
-      pdcp_mbms_array_eNB[ctxt_pP->module_id][mch_idP][lc_idP].instanciated_instance = TRUE ;
-      pdcp_mbms_array_eNB[ctxt_pP->module_id][mch_idP][lc_idP].rb_id = rb_idP;
-    } else {
-      pdcp_mbms_array_ue[ctxt_pP->module_id][mch_idP][lc_idP].instanciated_instance = TRUE ;
-      pdcp_mbms_array_ue[ctxt_pP->module_id][mch_idP][lc_idP].rb_id = rb_idP;
-    }
+      if (ctxt_pP->enb_flag == ENB_FLAG_YES) {
+        pdcp_mbms_array_eNB[ctxt_pP->module_id][mch_idP][lc_idP].instanciated_instance = TRUE ;
+        pdcp_mbms_array_eNB[ctxt_pP->module_id][mch_idP][lc_idP].rb_id = rb_idP;
+      } else {
+        pdcp_mbms_array_ue[ctxt_pP->module_id][mch_idP][lc_idP].instanciated_instance = TRUE ;
+        pdcp_mbms_array_ue[ctxt_pP->module_id][mch_idP][lc_idP].rb_id = rb_idP;
+      }
 
-    break;
+      break;
 #endif
 
-  case CONFIG_ACTION_SET_SECURITY_MODE:
-    pdcp_config_set_security(
-      ctxt_pP,
-      pdcp_pP,
-      rb_idP,
-      lc_idP,
-      security_modeP,
-      kRRCenc_pP,
-      kRRCint_pP,
-      kUPenc_pP);
-    break;
-
-  default:
-    DevParam(actionP, ctxt_pP->module_id, ctxt_pP->rnti);
-    break;
+    case CONFIG_ACTION_SET_SECURITY_MODE:
+      pdcp_config_set_security(
+        ctxt_pP,
+        pdcp_pP,
+        rb_idP,
+        lc_idP,
+        security_modeP,
+        kRRCenc_pP,
+        kRRCint_pP,
+        kUPenc_pP);
+      break;
+
+    default:
+      DevParam(actionP, ctxt_pP->module_id, ctxt_pP->rnti);
+      break;
   }
 
   return 0;
@@ -1895,14 +1875,14 @@ pdcp_config_req_asn1 (
 //-----------------------------------------------------------------------------
 void
 pdcp_config_set_security(
-  const protocol_ctxt_t* const  ctxt_pP,
-  pdcp_t         * const pdcp_pP,
+  const protocol_ctxt_t *const  ctxt_pP,
+  pdcp_t          *const pdcp_pP,
   const rb_id_t         rb_idP,
   const uint16_t        lc_idP,
   const uint8_t         security_modeP,
-  uint8_t        * const kRRCenc,
-  uint8_t        * const kRRCint,
-  uint8_t        * const  kUPenc)
+  uint8_t         *const kRRCenc,
+  uint8_t         *const kRRCint,
+  uint8_t         *const  kUPenc)
 //-----------------------------------------------------------------------------
 {
   DevAssert(pdcp_pP != NULL);
@@ -1910,30 +1890,27 @@ pdcp_config_set_security(
   if ((security_modeP >= 0) && (security_modeP <= 0x77)) {
     pdcp_pP->cipheringAlgorithm     = security_modeP & 0x0f;
     pdcp_pP->integrityProtAlgorithm = (security_modeP>>4) & 0xf;
-
     LOG_D(PDCP, PROTOCOL_PDCP_CTXT_FMT" CONFIG_ACTION_SET_SECURITY_MODE: cipheringAlgorithm %d integrityProtAlgorithm %d\n",
           PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_pP),
-            pdcp_pP->cipheringAlgorithm,
-            pdcp_pP->integrityProtAlgorithm);
-
+          pdcp_pP->cipheringAlgorithm,
+          pdcp_pP->integrityProtAlgorithm);
     pdcp_pP->kRRCenc = kRRCenc;
     pdcp_pP->kRRCint = kRRCint;
     pdcp_pP->kUPenc  = kUPenc;
-
     /* Activate security */
     pdcp_pP->security_activated = 1;
-	MSC_LOG_EVENT(
-	  (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
-	  "0 Set security ciph %X integ %x UE %"PRIx16" ",
-	  pdcp_pP->cipheringAlgorithm,
-	  pdcp_pP->integrityProtAlgorithm,
-	  ctxt_pP->rnti);
+    MSC_LOG_EVENT(
+      (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
+      "0 Set security ciph %X integ %x UE %"PRIx16" ",
+      pdcp_pP->cipheringAlgorithm,
+      pdcp_pP->integrityProtAlgorithm,
+      ctxt_pP->rnti);
   } else {
-	  MSC_LOG_EVENT(
-	    (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
-	    "0 Set security failed UE %"PRIx16" ",
-	    ctxt_pP->rnti);
-	  LOG_E(PDCP,PROTOCOL_PDCP_CTXT_FMT"  bad security mode %d",
+    MSC_LOG_EVENT(
+      (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
+      "0 Set security failed UE %"PRIx16" ",
+      ctxt_pP->rnti);
+    LOG_E(PDCP,PROTOCOL_PDCP_CTXT_FMT"  bad security mode %d",
           PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_pP),
           security_modeP);
   }
@@ -1942,7 +1919,7 @@ pdcp_config_set_security(
 //-----------------------------------------------------------------------------
 void
 rrc_pdcp_config_req (
-  const protocol_ctxt_t* const  ctxt_pP,
+  const protocol_ctxt_t *const  ctxt_pP,
   const srb_flag_t srb_flagP,
   const uint32_t actionP,
   const rb_id_t rb_idP,
@@ -1952,102 +1929,23 @@ rrc_pdcp_config_req (
   pdcp_t *pdcp_p = NULL;
   hash_key_t       key           = PDCP_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, srb_flagP);
   hashtable_rc_t   h_rc;
-  h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p);
+  h_rc = hashtable_get(pdcp_coll_p, key, (void **)&pdcp_p);
 
   if (h_rc == HASH_TABLE_OK) {
-
-  /*
-   * Initialize sequence number state variables of relevant PDCP entity
-   */
-  switch (actionP) {
-  case CONFIG_ACTION_ADD:
-    pdcp_p->is_srb = srb_flagP;
-    pdcp_p->rb_id  = rb_idP;
-
-    if (ctxt_pP->enb_flag == ENB_FLAG_NO) {
-      pdcp_p->is_ue = TRUE;
-      pdcp_UE_UE_module_id_to_rnti[ctxt_pP->module_id] = ctxt_pP->rnti;
-    } else {
-      pdcp_p->is_ue = FALSE;
-    }
-
-    pdcp_p->next_pdcp_tx_sn = 0;
-    pdcp_p->next_pdcp_rx_sn = 0;
-    pdcp_p->tx_hfn = 0;
-    pdcp_p->rx_hfn = 0;
-    /* SN of the last PDCP SDU delivered to upper layers */
-    pdcp_p->last_submitted_pdcp_rx_sn = 4095;
-
-    if (rb_idP < DTCH) { // SRB
-      pdcp_p->seq_num_size = 5;
-    } else { // DRB
-      pdcp_p->seq_num_size = 12;
-    }
-
-    pdcp_p->first_missing_pdu = -1;
-    LOG_D(PDCP,PROTOCOL_PDCP_CTXT_FMT" Config request : Action ADD:  radio bearer id %d (already added) configured\n",
-	  PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p),
-	  rb_idP);
-    break;
-
-  case CONFIG_ACTION_MODIFY:
-    break;
-
-  case CONFIG_ACTION_REMOVE:
-      LOG_D(PDCP, PROTOCOL_PDCP_CTXT_FMT" CONFIG_ACTION_REMOVE: radio bearer id %d configured\n",
-            PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p),
-            rb_idP);
-    pdcp_p->next_pdcp_tx_sn = 0;
-    pdcp_p->next_pdcp_rx_sn = 0;
-    pdcp_p->tx_hfn = 0;
-    pdcp_p->rx_hfn = 0;
-    pdcp_p->last_submitted_pdcp_rx_sn = 4095;
-    pdcp_p->seq_num_size = 0;
-    pdcp_p->first_missing_pdu = -1;
-    pdcp_p->security_activated = 0;
-      h_rc = hashtable_remove(pdcp_coll_p, key);
-
-    break;
-
-  case CONFIG_ACTION_SET_SECURITY_MODE:
-    if ((security_modeP >= 0) && (security_modeP <= 0x77)) {
-      pdcp_p->cipheringAlgorithm= security_modeP & 0x0f;
-      pdcp_p->integrityProtAlgorithm = (security_modeP>>4) & 0xf;
-        LOG_D(PDCP, PROTOCOL_PDCP_CTXT_FMT" CONFIG_ACTION_SET_SECURITY_MODE: cipheringAlgorithm %d integrityProtAlgorithm %d\n",
-              PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p),
-            pdcp_p->cipheringAlgorithm,
-            pdcp_p->integrityProtAlgorithm );
-    } else {
-        LOG_W(PDCP,PROTOCOL_PDCP_CTXT_FMT" bad security mode %d", PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p), security_modeP);
-    }
-
-    break;
-
-  default:
-      DevParam(actionP, ctxt_pP->module_id, ctxt_pP->rnti);
-    break;
-  }
-  } else {
+    /*
+     * Initialize sequence number state variables of relevant PDCP entity
+     */
     switch (actionP) {
-    case CONFIG_ACTION_ADD:
-      pdcp_p = calloc(1, sizeof(pdcp_t));
-      h_rc = hashtable_insert(pdcp_coll_p, key, pdcp_p);
-
-      if (h_rc != HASH_TABLE_OK) {
-        LOG_E(PDCP, PROTOCOL_PDCP_CTXT_FMT" PDCP ADD FAILED\n",
-              PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP, pdcp_p));
-        free(pdcp_p);
-
-      } else {
+      case CONFIG_ACTION_ADD:
         pdcp_p->is_srb = srb_flagP;
         pdcp_p->rb_id  = rb_idP;
 
         if (ctxt_pP->enb_flag == ENB_FLAG_NO) {
           pdcp_p->is_ue = TRUE;
-	  pdcp_UE_UE_module_id_to_rnti[ctxt_pP->module_id] = ctxt_pP->rnti;
+          pdcp_UE_UE_module_id_to_rnti[ctxt_pP->module_id] = ctxt_pP->rnti;
         } else {
           pdcp_p->is_ue = FALSE;
-	}
+        }
 
         pdcp_p->next_pdcp_tx_sn = 0;
         pdcp_p->next_pdcp_rx_sn = 0;
@@ -2058,46 +1956,119 @@ rrc_pdcp_config_req (
 
         if (rb_idP < DTCH) { // SRB
           pdcp_p->seq_num_size = 5;
-
         } else { // DRB
           pdcp_p->seq_num_size = 12;
         }
 
         pdcp_p->first_missing_pdu = -1;
-        LOG_D(PDCP,PROTOCOL_PDCP_CTXT_FMT" Inserting PDCP instance in collection key 0x%"PRIx64"\n",
-              PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p), key);
-        LOG_D(PDCP,PROTOCOL_PDCP_CTXT_FMT" Config request : Action ADD:  radio bearer id %d configured\n",
+        LOG_D(PDCP,PROTOCOL_PDCP_CTXT_FMT" Config request : Action ADD:  radio bearer id %d (already added) configured\n",
               PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p),
               rb_idP);
-      }
+        break;
 
-      break;
+      case CONFIG_ACTION_MODIFY:
+        break;
 
-    case CONFIG_ACTION_REMOVE:
-      LOG_D(PDCP, PROTOCOL_CTXT_FMT" CONFIG_REQ PDCP CONFIG_ACTION_REMOVE PDCP instance not found\n",
-            PROTOCOL_CTXT_ARGS(ctxt_pP));
-      break;
+      case CONFIG_ACTION_REMOVE:
+        LOG_D(PDCP, PROTOCOL_PDCP_CTXT_FMT" CONFIG_ACTION_REMOVE: radio bearer id %d configured\n",
+              PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p),
+              rb_idP);
+        pdcp_p->next_pdcp_tx_sn = 0;
+        pdcp_p->next_pdcp_rx_sn = 0;
+        pdcp_p->tx_hfn = 0;
+        pdcp_p->rx_hfn = 0;
+        pdcp_p->last_submitted_pdcp_rx_sn = 4095;
+        pdcp_p->seq_num_size = 0;
+        pdcp_p->first_missing_pdu = -1;
+        pdcp_p->security_activated = 0;
+        h_rc = hashtable_remove(pdcp_coll_p, key);
+        break;
 
-    default:
-      LOG_E(PDCP, PROTOCOL_CTXT_FMT" CONFIG_REQ PDCP NOT FOUND\n",
-            PROTOCOL_CTXT_ARGS(ctxt_pP));
+      case CONFIG_ACTION_SET_SECURITY_MODE:
+        if ((security_modeP >= 0) && (security_modeP <= 0x77)) {
+          pdcp_p->cipheringAlgorithm= security_modeP & 0x0f;
+          pdcp_p->integrityProtAlgorithm = (security_modeP>>4) & 0xf;
+          LOG_D(PDCP, PROTOCOL_PDCP_CTXT_FMT" CONFIG_ACTION_SET_SECURITY_MODE: cipheringAlgorithm %d integrityProtAlgorithm %d\n",
+                PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p),
+                pdcp_p->cipheringAlgorithm,
+                pdcp_p->integrityProtAlgorithm );
+        } else {
+          LOG_W(PDCP,PROTOCOL_PDCP_CTXT_FMT" bad security mode %d", PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p), security_modeP);
+        }
+
+        break;
+
+      default:
+        DevParam(actionP, ctxt_pP->module_id, ctxt_pP->rnti);
+        break;
+    }
+  } else {
+    switch (actionP) {
+      case CONFIG_ACTION_ADD:
+        pdcp_p = calloc(1, sizeof(pdcp_t));
+        h_rc = hashtable_insert(pdcp_coll_p, key, pdcp_p);
+
+        if (h_rc != HASH_TABLE_OK) {
+          LOG_E(PDCP, PROTOCOL_PDCP_CTXT_FMT" PDCP ADD FAILED\n",
+                PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP, pdcp_p));
+          free(pdcp_p);
+        } else {
+          pdcp_p->is_srb = srb_flagP;
+          pdcp_p->rb_id  = rb_idP;
+
+          if (ctxt_pP->enb_flag == ENB_FLAG_NO) {
+            pdcp_p->is_ue = TRUE;
+            pdcp_UE_UE_module_id_to_rnti[ctxt_pP->module_id] = ctxt_pP->rnti;
+          } else {
+            pdcp_p->is_ue = FALSE;
+          }
+
+          pdcp_p->next_pdcp_tx_sn = 0;
+          pdcp_p->next_pdcp_rx_sn = 0;
+          pdcp_p->tx_hfn = 0;
+          pdcp_p->rx_hfn = 0;
+          /* SN of the last PDCP SDU delivered to upper layers */
+          pdcp_p->last_submitted_pdcp_rx_sn = 4095;
+
+          if (rb_idP < DTCH) { // SRB
+            pdcp_p->seq_num_size = 5;
+          } else { // DRB
+            pdcp_p->seq_num_size = 12;
+          }
+
+          pdcp_p->first_missing_pdu = -1;
+          LOG_D(PDCP,PROTOCOL_PDCP_CTXT_FMT" Inserting PDCP instance in collection key 0x%"PRIx64"\n",
+                PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p), key);
+          LOG_D(PDCP,PROTOCOL_PDCP_CTXT_FMT" Config request : Action ADD:  radio bearer id %d configured\n",
+                PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p),
+                rb_idP);
+        }
+
+        break;
+
+      case CONFIG_ACTION_REMOVE:
+        LOG_D(PDCP, PROTOCOL_CTXT_FMT" CONFIG_REQ PDCP CONFIG_ACTION_REMOVE PDCP instance not found\n",
+              PROTOCOL_CTXT_ARGS(ctxt_pP));
+        break;
+
+      default:
+        LOG_E(PDCP, PROTOCOL_CTXT_FMT" CONFIG_REQ PDCP NOT FOUND\n",
+              PROTOCOL_CTXT_ARGS(ctxt_pP));
     }
   }
 }
 
 
 //-----------------------------------------------------------------------------
- 
+
 int
 pdcp_module_init (
   void
 )
 //-----------------------------------------------------------------------------
 {
- 
 #ifdef PDCP_USE_RT_FIFO
   int ret;
-
   ret=rtf_create(PDCP2NW_DRIVER_FIFO,32768);
 
   if (ret < 0) {
@@ -2112,7 +2083,6 @@ pdcp_module_init (
 
   if (ret < 0) {
     LOG_E(PDCP, "Cannot create NW_DRIVER2PDCP_FIFO fifo %d (ERROR %d)\n", NW_DRIVER2PDCP_FIFO, ret);
-
     return -1;
   } else {
     LOG_D(PDCP, "Created NW_DRIVER2PDCP_FIFO fifo %d\n", NW_DRIVER2PDCP_FIFO);
@@ -2123,18 +2093,17 @@ pdcp_module_init (
   pdcp_input_sdu_remaining_size_to_read=0;
   pdcp_input_sdu_size_read=0;
 #endif
-
   return 0;
 }
 
 //-----------------------------------------------------------------------------
 void
 pdcp_free (
-  void* pdcp_pP
+  void *pdcp_pP
 )
 //-----------------------------------------------------------------------------
 {
-  pdcp_t* pdcp_p = (pdcp_t*)pdcp_pP;
+  pdcp_t *pdcp_p = (pdcp_t *)pdcp_pP;
 
   if (pdcp_p != NULL) {
     if (pdcp_p->kUPenc != NULL) {
@@ -2168,10 +2137,9 @@ void pdcp_module_cleanup (void)
 void pdcp_layer_init(void)
 //-----------------------------------------------------------------------------
 {
-
   module_id_t       instance;
   int i,j;
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
   mbms_session_id_t session_id;
   mbms_service_id_t service_id;
 #endif
@@ -2179,28 +2147,29 @@ void pdcp_layer_init(void)
    * Initialize SDU list
    */
   list_init(&pdcp_sdu_list, NULL);
-  pdcp_coll_p = hashtable_create ((maxDRB + 2) * 16, NULL, pdcp_free);
+  pdcp_coll_p = hashtable_create ((LTE_maxDRB + 2) * NUMBER_OF_UE_MAX, NULL, pdcp_free);
   AssertFatal(pdcp_coll_p != NULL, "UNRECOVERABLE error, PDCP hashtable_create failed");
 
   for (instance = 0; instance < MAX_MOBILES_PER_ENB; instance++) {
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 
-    for (service_id = 0; service_id < maxServiceCount; service_id++) {
-      for (session_id = 0; session_id < maxSessionPerPMCH; session_id++) {
+    for (service_id = 0; service_id < LTE_maxServiceCount; service_id++) {
+      for (session_id = 0; session_id < LTE_maxSessionPerPMCH; session_id++) {
         memset(&pdcp_mbms_array_ue[instance][service_id][session_id], 0, sizeof(pdcp_mbms_t));
       }
     }
+
 #endif
     pdcp_eNB_UE_instance_to_rnti[instance] = NOT_A_RNTI;
   }
-  pdcp_eNB_UE_instance_to_rnti_index = 0; 
 
-    
+  pdcp_eNB_UE_instance_to_rnti_index = 0;
+
   for (instance = 0; instance < NUMBER_OF_eNB_MAX; instance++) {
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 
-    for (service_id = 0; service_id < maxServiceCount; service_id++) {
-      for (session_id = 0; session_id < maxSessionPerPMCH; session_id++) {
+    for (service_id = 0; service_id < LTE_maxServiceCount; service_id++) {
+      for (session_id = 0; session_id < LTE_maxSessionPerPMCH; session_id++) {
         memset(&pdcp_mbms_array_eNB[instance][service_id][session_id], 0, sizeof(pdcp_mbms_t));
       }
     }
@@ -2210,28 +2179,25 @@ void pdcp_layer_init(void)
 
 #ifdef MBMS_MULTICAST_OUT
   mbms_socket = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
+
   if (mbms_socket == -1)
     LOG_W(PDCP, "Could not create RAW socket, MBMS packets will not be put to the network\n");
-#endif
 
+#endif
   LOG_I(PDCP, "PDCP layer has been initialized\n");
-
   pdcp_output_sdu_bytes_to_write=0;
   pdcp_output_header_bytes_to_write=0;
   pdcp_input_sdu_remaining_size_to_read=0;
-
   memset(pdcp_enb, 0, sizeof(pdcp_enb_t));
-
-  
   memset(Pdcp_stats_tx_window_ms, 0, sizeof(Pdcp_stats_tx_window_ms));
   memset(Pdcp_stats_rx_window_ms, 0, sizeof(Pdcp_stats_rx_window_ms));
-  for (i =0; i< MAX_eNB ; i ++){
-    for (j=0; j< MAX_MOBILES_PER_ENB;j++){
+  for (i = 0; i < MAX_eNB; i++) {
+    for (j = 0; j < MAX_MOBILES_PER_ENB; j++) {
       Pdcp_stats_tx_window_ms[i][j]=100;
       Pdcp_stats_rx_window_ms[i][j]=100;
     }
   }
-  
+
   memset(Pdcp_stats_tx, 0, sizeof(Pdcp_stats_tx));
   memset(Pdcp_stats_tx_w, 0, sizeof(Pdcp_stats_tx_w));
   memset(Pdcp_stats_tx_tmp_w, 0, sizeof(Pdcp_stats_tx_tmp_w));
@@ -2242,8 +2208,6 @@ void pdcp_layer_init(void)
   memset(Pdcp_stats_tx_throughput_w, 0, sizeof(Pdcp_stats_tx_throughput_w));
   memset(Pdcp_stats_tx_aiat, 0, sizeof(Pdcp_stats_tx_aiat));
   memset(Pdcp_stats_tx_iat, 0, sizeof(Pdcp_stats_tx_iat));
-  
-
   memset(Pdcp_stats_rx, 0, sizeof(Pdcp_stats_rx));
   memset(Pdcp_stats_rx_w, 0, sizeof(Pdcp_stats_rx_w));
   memset(Pdcp_stats_rx_tmp_w, 0, sizeof(Pdcp_stats_rx_tmp_w));
@@ -2255,7 +2219,6 @@ void pdcp_layer_init(void)
   memset(Pdcp_stats_rx_aiat, 0, sizeof(Pdcp_stats_rx_aiat));
   memset(Pdcp_stats_rx_iat, 0, sizeof(Pdcp_stats_rx_iat));
   memset(Pdcp_stats_rx_outoforder, 0, sizeof(Pdcp_stats_rx_outoforder));
-    
 }
 
 //-----------------------------------------------------------------------------
@@ -2263,15 +2226,17 @@ void pdcp_layer_cleanup (void)
 //-----------------------------------------------------------------------------
 {
   list_free (&pdcp_sdu_list);
-  hashtable_destroy(pdcp_coll_p);
+  hashtable_destroy(&pdcp_coll_p);
 #ifdef MBMS_MULTICAST_OUT
+
   if(mbms_socket != -1) {
     close(mbms_socket);
     mbms_socket = -1;
   }
+
 #endif
 }
 
 #ifdef PDCP_USE_RT_FIFO
-EXPORT_SYMBOL(pdcp_2_nas_irq);
+  EXPORT_SYMBOL(pdcp_2_nas_irq);
 #endif //PDCP_USE_RT_FIFO
diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp.h b/openair2/LAYER2/PDCP_v10.1.0/pdcp.h
index 63cbf1194494470a73292423935a9cde3bebdce2..f4be09a84384a99ca4be2cf4899ed589123bd925 100644
--- a/openair2/LAYER2/PDCP_v10.1.0/pdcp.h
+++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp.h
@@ -42,13 +42,13 @@
 #include "RRC/LTE/rrc_defs.h"
 #include "COMMON/platform_constants.h"
 #include "COMMON/platform_types.h"
-#include "DRB-ToAddMod.h"
-#include "DRB-ToAddModList.h"
-#include "SRB-ToAddMod.h"
-#include "SRB-ToAddModList.h"
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-#include "MBMS-SessionInfoList-r9.h"
-#include "PMCH-InfoList-r9.h"
+#include "LTE_DRB-ToAddMod.h"
+#include "LTE_DRB-ToAddModList.h"
+#include "LTE_SRB-ToAddMod.h"
+#include "LTE_SRB-ToAddModList.h"
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+#include "LTE_MBMS-SessionInfoList-r9.h"
+#include "LTE_PMCH-InfoList-r9.h"
 #endif
 
 
@@ -195,7 +195,7 @@ typedef struct pdcp_s {
 
 } pdcp_t;
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 typedef struct pdcp_mbms_s {
   boolean_t instanciated_instance;
   rb_id_t   rb_id;
@@ -232,7 +232,7 @@ boolean_t pdcp_data_req(
               const sdu_size_t sdu_buffer_size,
               unsigned char* const sdu_buffer,
               const pdcp_transmission_mode_t mode
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
               ,const uint32_t * const sourceL2Id
               ,const uint32_t * const destinationL2Id
 #endif
@@ -292,15 +292,15 @@ void rrc_pdcp_config_req (
 */
 boolean_t rrc_pdcp_config_asn1_req (
     const protocol_ctxt_t* const  ctxt_pP,
-    SRB_ToAddModList_t  *const srb2add_list,
-    DRB_ToAddModList_t  *const drb2add_list,
-    DRB_ToReleaseList_t *const drb2release_list,
+    LTE_SRB_ToAddModList_t  *const srb2add_list,
+    LTE_DRB_ToAddModList_t  *const drb2add_list,
+    LTE_DRB_ToReleaseList_t *const drb2release_list,
     const uint8_t                   security_modeP,
     uint8_t                  *const kRRCenc,
     uint8_t                  *const kRRCint,
     uint8_t                  *const kUPenc
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-    ,PMCH_InfoList_r9_t  *pmch_InfoList_r9
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+    ,LTE_PMCH_InfoList_r9_t  *pmch_InfoList_r9
 #endif
     ,rb_id_t                 *const defaultDRB 
   );
@@ -404,7 +404,7 @@ typedef struct pdcp_data_req_header_s {
   sdu_size_t          data_size;
   signed int          inst;
   ip_traffic_type_t   traffic_type;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   uint32_t sourceL2Id;
   uint32_t destinationL2Id;
 #endif
@@ -415,7 +415,7 @@ typedef struct pdcp_data_ind_header_s {
   sdu_size_t          data_size;
   signed int          inst;
   ip_traffic_type_t   dummy_traffic_type;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   uint32_t sourceL2Id;
   uint32_t destinationL2Id;
 #endif
@@ -429,7 +429,7 @@ struct pdcp_netlink_element_s {
 };
 
 //TTN for D2D (PC5S)
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 #define PDCP_SOCKET_PORT_NO 9999 //temporary value
 #define PC5_SIGNALLING_PAYLOAD_SIZE   100  //should be updated with a correct value
 int pdcp_pc5_sockfd;
@@ -499,9 +499,9 @@ pdcp_stats_t              eNB_pdcp_stats[NUMBER_OF_eNB_MAX];
 rnti_t                 pdcp_UE_UE_module_id_to_rnti[MAX_MOBILES_PER_ENB];
 rnti_t                 pdcp_eNB_UE_instance_to_rnti[MAX_MOBILES_PER_ENB]; // for noS1 mode
 unsigned int           pdcp_eNB_UE_instance_to_rnti_index;
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-pdcp_mbms_t               pdcp_mbms_array_ue[MAX_MOBILES_PER_ENB][maxServiceCount][maxSessionPerPMCH];   // some constants from openair2/RRC/LTE/MESSAGES/asn1_constants.h
-pdcp_mbms_t               pdcp_mbms_array_eNB[NUMBER_OF_eNB_MAX][maxServiceCount][maxSessionPerPMCH]; // some constants from openair2/RRC/LTE/MESSAGES/asn1_constants.h
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+pdcp_mbms_t               pdcp_mbms_array_ue[MAX_MOBILES_PER_ENB][LTE_maxServiceCount][LTE_maxSessionPerPMCH];   // some constants from openair2/RRC/LTE/MESSAGES/asn1_constants.h
+pdcp_mbms_t               pdcp_mbms_array_eNB[NUMBER_OF_eNB_MAX][LTE_maxServiceCount][LTE_maxSessionPerPMCH]; // some constants from openair2/RRC/LTE/MESSAGES/asn1_constants.h
 #endif
 sdu_size_t             pdcp_output_sdu_bytes_to_write;
 sdu_size_t             pdcp_output_header_bytes_to_write;
@@ -542,7 +542,7 @@ sdu_size_t             pdcp_input_sdu_remaining_size_to_read;
     (((hash_key_t)(sESSION_ID)) << 37) | \
     (((hash_key_t)(0x0000000000000001))  << 63))
 
-hash_table_t  *pdcp_coll_p;
+extern hash_table_t  *pdcp_coll_p;
 
 #endif
 /*@}*/
diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c
index ae1679e0097a91740388024c24d61eb6d01007d9..1cbc9e9a195c9c5fe5131b9d449b1ec12873bfc9 100644
--- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c
+++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c
@@ -82,10 +82,13 @@ extern struct msghdr nas_msg_tx;
 extern struct msghdr nas_msg_rx;
 
 unsigned char pdcp_read_state_g = 0;
+extern uint8_t nfapi_mode;
+#ifdef UESIM_EXPANSION
+extern uint16_t inst_pdcp_list[NUMBER_OF_UE_MAX];
+#endif
 #endif
 
 extern Packet_OTG_List_t *otg_pdcp_buffer;
-
 #if defined(LINK_ENB_PDCP_TO_GTPV1U)
 #  include "gtpv1u_eNB_task.h"
 #  include "gtpv1u_eNB_defs.h"
@@ -168,7 +171,12 @@ int pdcp_fifo_flush_sdus(const protocol_ctxt_t* const  ctxt_pP)
             ((pdcp_data_ind_header_t*) sdu_p->data)->inst,
             ((pdcp_data_ind_header_t *) sdu_p->data)->data_size);
 #else
-      ((pdcp_data_ind_header_t *)(sdu_p->data))->inst = 0;
+      // Raphael: was suppressed by Raymond --> should be suppressed?
+      // value of sdu_p->data->inst is set in pdcp_data_ind
+      // it's necessary to set 1 in case of UE with S1.
+      //if (ctxt_pP->enb_flag){
+      //  ((pdcp_data_ind_header_t *)(sdu_p->data))->inst = 0;
+      //}
 #endif
 
 #if defined(LINK_ENB_PDCP_TO_GTPV1U)
@@ -178,7 +186,7 @@ int pdcp_fifo_flush_sdus(const protocol_ctxt_t* const  ctxt_pP)
          LOG_D(PDCP,"Sending to GTPV1U %d bytes\n", ((pdcp_data_ind_header_t *)(sdu_p->data))->data_size);
          gtpv1u_new_data_req(
                ctxt_pP->module_id, //gtpv1u_data_t *gtpv1u_data_p,
-               ctxt_pP->rnti,//rb_id/maxDRB, TO DO UE ID
+               ctxt_pP->rnti,//rb_id/LTE_maxDRB, TO DO UE ID
                ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id + 4,
                &(((uint8_t *) sdu_p->data)[sizeof (pdcp_data_ind_header_t)]),
                ((pdcp_data_ind_header_t *)(sdu_p->data))->data_size,
@@ -195,14 +203,14 @@ int pdcp_fifo_flush_sdus(const protocol_ctxt_t* const  ctxt_pP)
 
 #endif /* defined(ENABLE_USE_MME) */
 #ifdef PDCP_DEBUG
-      LOG_D(PDCP, "PDCP->IP TTI %d INST %d: Preparing %d Bytes of data from rab %d to Nas_mesh\n",
+      LOG_I(PDCP, "PDCP->IP TTI %d INST %d: Preparing %d Bytes of data from rab %d to Nas_mesh\n",
             ctxt_pP->frame, ((pdcp_data_ind_header_t *)(sdu_p->data))->inst,
             ((pdcp_data_ind_header_t *)(sdu_p->data))->data_size, ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id);
 #endif //PDCP_DEBUG
       cont = 0;
 
 //TTN - for D2D (PC5S)
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
       sidelink_pc5s_element *sl_pc5s_msg_recv = NULL;
       char send_buf[BUFSIZE];
       int rb_id = ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id;
@@ -452,7 +460,7 @@ int pdcp_fifo_read_input_sdus (const protocol_ctxt_t* const  ctxt_pP)
       pdcp_data_req(&ctxt, SRB_FLAG_NO, rab_id, RLC_MUI_UNDEFINED,
                     RLC_SDU_CONFIRM_NO, len, (unsigned char *)nl_rx_buf,
                     PDCP_TRANSMISSION_MODE_DATA
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                     , NULL, NULL
 #endif
                    );
@@ -488,7 +496,7 @@ int pdcp_fifo_read_input_sdus (const protocol_ctxt_t* const  ctxt_pP)
    pdcp_t*                        pdcp_p    = NULL;
 
 //TTN for D2D (PC5S)
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
    int prose_addr_len;
    char send_buf[BUFSIZE], receive_buf[BUFSIZE];
    //int optval;
@@ -509,7 +517,7 @@ int pdcp_fifo_read_input_sdus (const protocol_ctxt_t* const  ctxt_pP)
 
    while (pdcp_netlink_dequeue_element(ctxt_pP, &data_p) != 0) {
       DevAssert(data_p != NULL);
-      rab_id = data_p->pdcp_read_header.rb_id % maxDRB;
+      rab_id = data_p->pdcp_read_header.rb_id % LTE_maxDRB;
       // ctxt_pP->rnti is NOT_A_RNTI
       ctxt_cpy.rnti = pdcp_module_id_to_rnti[ctxt_cpy.module_id][data_p->pdcp_read_header.inst];
       key = PDCP_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_cpy.rnti, ctxt_pP->enb_flag, rab_id, SRB_FLAG_NO);
@@ -526,7 +534,7 @@ int pdcp_fifo_read_input_sdus (const protocol_ctxt_t* const  ctxt_pP)
 
       CHECK_CTXT_ARGS(&ctxt_cpy);
 
-      AssertFatal (rab_id    < maxDRB,                       "RB id is too high (%u/%d)!\n", rab_id, maxDRB);
+      AssertFatal (rab_id    < LTE_maxDRB,                       "RB id is too high (%u/%d)!\n", rab_id, LTE_maxDRB);
 
       if (rab_id != 0) {
          LOG_D(PDCP, "[FRAME %05d][%s][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ "
@@ -543,7 +551,7 @@ int pdcp_fifo_read_input_sdus (const protocol_ctxt_t* const  ctxt_pP)
          if ((data_p->pdcp_read_header.traffic_type == TRAFFIC_IPV6_TYPE_MULTICAST) /*TRAFFIC_IPV6_TYPE_MULTICAST */ ||
                (data_p->pdcp_read_header.traffic_type == TRAFFIC_IPV4_TYPE_MULTICAST) /*TRAFFIC_IPV4_TYPE_MULTICAST */ ||
                (data_p->pdcp_read_header.traffic_type == TRAFFIC_IPV4_TYPE_BROADCAST) /*TRAFFIC_IPV4_TYPE_BROADCAST */ ) {
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
             PDCP_TRANSMISSION_MODE_TRANSPARENT;
 #else
             pdcp_mode= PDCP_TRANSMISSION_MODE_DATA;
@@ -561,13 +569,13 @@ int pdcp_fifo_read_input_sdus (const protocol_ctxt_t* const  ctxt_pP)
 #endif
          pdcp_data_req(&ctxt_cpy,
                SRB_FLAG_NO,
-               rab_id % maxDRB,
+               rab_id % LTE_maxDRB,
                RLC_MUI_UNDEFINED,
                RLC_SDU_CONFIRM_NO,
                data_p->pdcp_read_header.data_size,
                data_p->data,
                pdcp_mode
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                ,NULL, NULL
 #endif
                );
@@ -595,7 +603,7 @@ int pdcp_fifo_read_input_sdus (const protocol_ctxt_t* const  ctxt_pP)
                      data_p->pdcp_read_header.data_size,
                      data_p->data,
                      PDCP_TRANSMISSION_MODE_DATA
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                      ,NULL, NULL
 #endif
                      );
@@ -612,7 +620,7 @@ int pdcp_fifo_read_input_sdus (const protocol_ctxt_t* const  ctxt_pP)
                data_p->pdcp_read_header.data_size,
                data_p->data,
                PDCP_TRANSMISSION_MODE_DATA
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                ,NULL, NULL
 #endif
                );
@@ -632,7 +640,7 @@ int pdcp_fifo_read_input_sdus (const protocol_ctxt_t* const  ctxt_pP)
 
 
 //TTN for D2D (PC5S)
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
    prose_addr_len = sizeof(prose_pdcp_addr);
    // receive a message from ProSe App
    memset(receive_buf, 0, BUFSIZE);
@@ -680,18 +688,18 @@ int pdcp_fifo_read_input_sdus (const protocol_ctxt_t* const  ctxt_pP)
             ctxt.frame         = ctxt_cpy.frame;
             ctxt.enb_flag      = ENB_FLAG_YES;
             ctxt.module_id     = pc5s_header.inst  +  oai_emulation.info.first_enb_local;
-            ctxt.rnti          = oai_emulation.info.eNB_ue_module_id_to_rnti[ctxt.module_id ][pc5s_header->rb_id / maxDRB + oai_emulation.info.first_ue_local];
-            rab_id    = pc5s_header->rb_id % maxDRB;
+            ctxt.rnti          = oai_emulation.info.eNB_ue_module_id_to_rnti[ctxt.module_id ][pc5s_header->rb_id / LTE_maxDRB + oai_emulation.info.first_ue_local];
+            rab_id    = pc5s_header->rb_id % LTE_maxDRB;
          } else {
             ctxt.frame         = ctxt_cpy.frame;
             ctxt.enb_flag      = ENB_FLAG_NO;
             ctxt.module_id     = pc5s_header->inst - oai_emulation.info.nb_enb_local + oai_emulation.info.first_ue_local;
             ctxt.rnti          = pdcp_UE_UE_module_id_to_rnti[ctxt.module_id];
-            rab_id    = pc5s_header->rb_id % maxDRB;
+            rab_id    = pc5s_header->rb_id % LTE_maxDRB;
          }
 
          CHECK_CTXT_ARGS(&ctxt);
-         AssertFatal (rab_id    < maxDRB,                       "RB id is too high (%u/%d)!\n", rab_id, maxDRB);
+         AssertFatal (rab_id    < LTE_maxDRB,                       "RB id is too high (%u/%d)!\n", rab_id, LTE_maxDRB);
          /*LGpdcp_read_header.inst = (pc5s_header.inst >= oai_emulation.info.nb_enb_local) ? \
                   pc5s_header.inst - oai_emulation.info.nb_enb_local+ NB_eNB_INST + oai_emulation.info.first_ue_local :
                   pc5s_header.inst +  oai_emulation.info.first_enb_local;*/
@@ -706,11 +714,11 @@ int pdcp_fifo_read_input_sdus (const protocol_ctxt_t* const  ctxt_pP)
 
          if (ctxt_cpy.enb_flag) {
             ctxt.module_id = 0;
-            rab_id      = pc5s_header->rb_id % maxDRB;
+            rab_id      = pc5s_header->rb_id % LTE_maxDRB;
             ctxt.rnti          = pdcp_eNB_UE_instance_to_rnti[pdcp_eNB_UE_instance_to_rnti_index];
          } else {
             ctxt.module_id = 0;
-            rab_id      = pc5s_header->rb_id % maxDRB;
+            rab_id      = pc5s_header->rb_id % LTE_maxDRB;
             ctxt.rnti          = pdcp_UE_UE_module_id_to_rnti[ctxt.module_id];
          }
 #endif
@@ -719,14 +727,14 @@ int pdcp_fifo_read_input_sdus (const protocol_ctxt_t* const  ctxt_pP)
          if (!ctxt.enb_flag) {
             if (rab_id != 0) {
                if (rab_id == UE_IP_DEFAULT_RAB_ID) {
-                  LOG_I(PDCP, "PDCP_COLL_KEY_DEFAULT_DRB_VALUE(module_id=%d, rnti=%x, enb_flag=%d)\n",
+                  LOG_D(PDCP, "PDCP_COLL_KEY_DEFAULT_DRB_VALUE(module_id=%d, rnti=%x, enb_flag=%d)\n",
                         ctxt.module_id, ctxt.rnti, ctxt.enb_flag);
                   key = PDCP_COLL_KEY_DEFAULT_DRB_VALUE(ctxt.module_id, ctxt.rnti, ctxt.enb_flag);
                   h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p);
-                  LOG_I(PDCP,"request key %x : (%d,%x,%d,%d)\n",
+                  LOG_D(PDCP,"request key %x : (%d,%x,%d,%d)\n",
                         (uint8_t)key,ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id);
                } else {
-                  rab_id = rab_id % maxDRB;
+                  rab_id = rab_id % LTE_maxDRB;
                   LOG_I(PDCP, "PDCP_COLL_KEY_VALUE(module_id=%d, rnti=%x, enb_flag=%d, rab_id=%d, SRB_FLAG=%d)\n",
                         ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id, SRB_FLAG_NO);
                   key = PDCP_COLL_KEY_VALUE(ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id, SRB_FLAG_NO);
@@ -774,7 +782,7 @@ int pdcp_fifo_read_input_sdus (const protocol_ctxt_t* const  ctxt_pP)
                         pc5s_header->data_size,
                         (unsigned char *)receive_buf,
                         PDCP_TRANSMISSION_MODE_DATA
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                         ,&pc5s_header->sourceL2Id
                         ,&pc5s_header->destinationL2Id
 #endif
@@ -832,7 +840,7 @@ int pdcp_fifo_read_input_sdus (const protocol_ctxt_t* const  ctxt_pP)
                      pc5s_header->data_size,
                      (unsigned char *)receive_buf,
                      PDCP_TRANSMISSION_MODE_DATA
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                      ,&pc5s_header->sourceL2Id
                      ,&pc5s_header->destinationL2Id
 #endif
@@ -897,18 +905,18 @@ int pdcp_fifo_read_input_sdus (const protocol_ctxt_t* const  ctxt_pP)
                   ctxt.frame         = ctxt_cpy.frame;
                   ctxt.enb_flag      = ENB_FLAG_YES;
                   ctxt.module_id     = pdcp_read_header_g.inst  +  oai_emulation.info.first_enb_local;
-                  ctxt.rnti          = oai_emulation.info.eNB_ue_module_id_to_rnti[ctxt.module_id ][pdcp_read_header_g.rb_id / maxDRB + oai_emulation.info.first_ue_local];
-                  rab_id    = pdcp_read_header_g.rb_id % maxDRB;
+                  ctxt.rnti          = oai_emulation.info.eNB_ue_module_id_to_rnti[ctxt.module_id ][pdcp_read_header_g.rb_id / LTE_maxDRB + oai_emulation.info.first_ue_local];
+                  rab_id    = pdcp_read_header_g.rb_id % LTE_maxDRB;
                } else {
                   ctxt.frame         = ctxt_cpy.frame;
                   ctxt.enb_flag      = ENB_FLAG_NO;
                   ctxt.module_id     = pdcp_read_header_g.inst - oai_emulation.info.nb_enb_local + oai_emulation.info.first_ue_local;
                   ctxt.rnti          = pdcp_UE_UE_module_id_to_rnti[ctxt.module_id];
-                  rab_id    = pdcp_read_header_g.rb_id % maxDRB;
+                  rab_id    = pdcp_read_header_g.rb_id % LTE_maxDRB;
                }
 
                CHECK_CTXT_ARGS(&ctxt);
-               AssertFatal (rab_id    < maxDRB,                       "RB id is too high (%u/%d)!\n", rab_id, maxDRB);
+               AssertFatal (rab_id    < LTE_maxDRB,                       "RB id is too high (%u/%d)!\n", rab_id, LTE_maxDRB);
                /*LGpdcp_read_header.inst = (pdcp_read_header_g.inst >= oai_emulation.info.nb_enb_local) ? \
                   pdcp_read_header_g.inst - oai_emulation.info.nb_enb_local+ NB_eNB_INST + oai_emulation.info.first_ue_local :
                   pdcp_read_header_g.inst +  oai_emulation.info.first_enb_local;*/
@@ -924,11 +932,19 @@ int pdcp_fifo_read_input_sdus (const protocol_ctxt_t* const  ctxt_pP)
 #endif
           if (ctxt_cpy.enb_flag) {
             ctxt.module_id = 0;
-            rab_id      = pdcp_read_header_g.rb_id % maxDRB;
-            ctxt.rnti          = pdcp_eNB_UE_instance_to_rnti[pdcp_read_header_g.rb_id / maxDRB];
+            rab_id      = pdcp_read_header_g.rb_id % LTE_maxDRB;
+            ctxt.rnti          = pdcp_eNB_UE_instance_to_rnti[pdcp_read_header_g.rb_id / LTE_maxDRB];
           } else {
-            ctxt.module_id = 0;
-            rab_id      = pdcp_read_header_g.rb_id % maxDRB;
+            if (nfapi_mode == 3) {
+#ifdef UESIM_EXPANSION
+              ctxt.module_id = inst_pdcp_list[pdcp_read_header_g.inst];
+#else
+              ctxt.module_id = pdcp_read_header_g.inst;
+#endif
+            } else {
+              ctxt.module_id = 0;
+            }
+            rab_id      = pdcp_read_header_g.rb_id % LTE_maxDRB;
             ctxt.rnti          = pdcp_UE_UE_module_id_to_rnti[ctxt.module_id];
           }
 
@@ -936,7 +952,7 @@ int pdcp_fifo_read_input_sdus (const protocol_ctxt_t* const  ctxt_pP)
 
           if (ctxt.enb_flag) {
             if (rab_id != 0) {
-              rab_id = rab_id % maxDRB;
+              rab_id = rab_id % LTE_maxDRB;
               key = PDCP_COLL_KEY_VALUE(ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id, SRB_FLAG_NO);
               h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p);
 
@@ -979,7 +995,7 @@ int pdcp_fifo_read_input_sdus (const protocol_ctxt_t* const  ctxt_pP)
                               pdcp_read_header_g.data_size,
                               (unsigned char *)NLMSG_DATA(nas_nlh_rx),
                               PDCP_TRANSMISSION_MODE_DATA
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                               ,NULL, NULL
 #endif
                               );
@@ -1016,7 +1032,7 @@ int pdcp_fifo_read_input_sdus (const protocol_ctxt_t* const  ctxt_pP)
                                  pdcp_read_header_g.data_size,
                                  (unsigned char *)NLMSG_DATA(nas_nlh_rx),
                                  PDCP_TRANSMISSION_MODE_DATA
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                                 ,NULL, NULL
 #endif
                                 );
@@ -1033,7 +1049,7 @@ int pdcp_fifo_read_input_sdus (const protocol_ctxt_t* const  ctxt_pP)
                         LOG_D(PDCP,"request key %x : (%d,%x,%d,%d)\n",
                         		(uint8_t)key,ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id);
                      } else {
-                        rab_id = rab_id % maxDRB;
+                        rab_id = rab_id % LTE_maxDRB;
                         LOG_D(PDCP, "PDCP_COLL_KEY_VALUE(module_id=%d, rnti=%x, enb_flag=%d, rab_id=%d, SRB_FLAG=%d)\n",
                               ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id, SRB_FLAG_NO);
                         key = PDCP_COLL_KEY_VALUE(ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id, SRB_FLAG_NO);
@@ -1072,7 +1088,7 @@ int pdcp_fifo_read_input_sdus (const protocol_ctxt_t* const  ctxt_pP)
                                           pdcp_read_header_g.rb_id,
                                           rab_id,
                                           pdcp_read_header_g.data_size);
-
+                        if(nfapi_mode == 3){
                         pdcp_data_req(
                               &ctxt,
                               SRB_FLAG_NO,
@@ -1082,11 +1098,27 @@ int pdcp_fifo_read_input_sdus (const protocol_ctxt_t* const  ctxt_pP)
                               pdcp_read_header_g.data_size,
                               (unsigned char *)NLMSG_DATA(nas_nlh_rx),
                               PDCP_TRANSMISSION_MODE_DATA
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                              ,NULL
+                              ,NULL
+#endif
+                              );
+                        }else{
+                        pdcp_data_req(
+                              &ctxt,
+                              SRB_FLAG_NO,
+                              rab_id,
+                              RLC_MUI_UNDEFINED,
+                              RLC_SDU_CONFIRM_NO,
+                              pdcp_read_header_g.data_size,
+                              (unsigned char *)NLMSG_DATA(nas_nlh_rx),
+                              PDCP_TRANSMISSION_MODE_DATA
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                               ,&pdcp_read_header_g.sourceL2Id
                               ,&pdcp_read_header_g.destinationL2Id
 #endif
                               );
+                        }
                      } else {
                         MSC_LOG_RX_DISCARDED_MESSAGE(
                               (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
@@ -1130,7 +1162,22 @@ int pdcp_fifo_read_input_sdus (const protocol_ctxt_t* const  ctxt_pP)
                                        pdcp_read_header_g.rb_id,
                                        DEFAULT_RAB_ID,
                                        pdcp_read_header_g.data_size);
-
+                     if(nfapi_mode == 3){
+                     pdcp_data_req (
+                           &ctxt,
+                           SRB_FLAG_NO,
+                           DEFAULT_RAB_ID,
+                           RLC_MUI_UNDEFINED,
+                           RLC_SDU_CONFIRM_NO,
+                           pdcp_read_header_g.data_size,
+                           (unsigned char *)NLMSG_DATA(nas_nlh_rx),
+                           PDCP_TRANSMISSION_MODE_DATA
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                           ,NULL
+                           ,NULL
+#endif
+                               );
+                     }else{
                      pdcp_data_req (
                            &ctxt,
                            SRB_FLAG_NO,
@@ -1140,11 +1187,12 @@ int pdcp_fifo_read_input_sdus (const protocol_ctxt_t* const  ctxt_pP)
                            pdcp_read_header_g.data_size,
                            (unsigned char *)NLMSG_DATA(nas_nlh_rx),
                            PDCP_TRANSMISSION_MODE_DATA
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                            ,&pdcp_read_header_g.sourceL2Id
                            ,&pdcp_read_header_g.destinationL2Id
 #endif
                            );
+                     }
                   }
                }
 
@@ -1189,7 +1237,7 @@ void pdcp_fifo_read_input_sdus_from_otg (const protocol_ctxt_t* const  ctxt_pP)
 
 
 //TTN for D2D (PC5S)
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 
 void
 pdcp_pc5_socket_init() {
diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_proto_extern.h b/openair2/LAYER2/PDCP_v10.1.0/pdcp_proto_extern.h
index 291ec5e2a728a8f2cb421f0acb52cd3096b9ba84..676ece7b3a1863eeeae9bb15323ff7aa7cacce44 100644
--- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_proto_extern.h
+++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp_proto_extern.h
@@ -53,7 +53,7 @@ extern int  reception_from_rohc_bs(void);
 extern BOOL     pdcp_data_ind (module_id_t module_idP, rb_id_t rab_idP, sdu_size_t data_sizeP, mem_block_t * sduP, uint8_t is_data_plane);
 extern BOOL     pdcp_data_req (module_id_t module_id, uint32_t frame, uint8_t eNB_flag, rb_id_t rab_id, uint32_t muiP, uint32_t confirmP, sdu_size_t sdu_buffer_size, unsigned char* sdu_buffer,
                                uint8_t is_data_pdu
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                                ,const uint32_t * const sourceL2Id
                                ,const uint32_t * const destinationL2Id
 #endif
diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_security.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp_security.c
index ca8ead768a38a3c6ca191130d4e79e9077269170..2a4c15531daf3b37608e25c093e0a47a92428520 100644
--- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_security.c
+++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp_security.c
@@ -62,7 +62,7 @@ uint32_t pdcp_get_next_count_tx(
     /* 5 bits length SN */
     count = ((pdcp_pP->tx_hfn << 5)  | (pdcp_sn & 0x001F));
   } else {
-    if (pdcp_pP->seq_num_size == PDCP_Config__rlc_UM__pdcp_SN_Size_len7bits) {
+    if (pdcp_pP->seq_num_size == LTE_PDCP_Config__rlc_UM__pdcp_SN_Size_len7bits) {
       count = ((pdcp_pP->tx_hfn << 7) | (pdcp_sn & 0x07F));
     } else { /*Default is the 12 bits length SN */
       count = ((pdcp_pP->tx_hfn << 12) | (pdcp_sn & 0x0FFF));
@@ -88,7 +88,7 @@ uint32_t pdcp_get_next_count_rx(
     /* 5 bits length SN */
     count = (((pdcp_pP->rx_hfn + pdcp_pP->rx_hfn_offset) << 5)  | (pdcp_sn & 0x001F));
   } else {
-    if (pdcp_pP->seq_num_size == PDCP_Config__rlc_UM__pdcp_SN_Size_len7bits) {
+    if (pdcp_pP->seq_num_size == LTE_PDCP_Config__rlc_UM__pdcp_SN_Size_len7bits) {
       /* 7 bits length SN */
       count = (((pdcp_pP->rx_hfn + pdcp_pP->rx_hfn_offset) << 7) | (pdcp_sn & 0x007F));
     } else { // default
diff --git a/openair2/LAYER2/PROTO_AGENT/cu_test.c b/openair2/LAYER2/PROTO_AGENT/cu_test.c
index a611c0edf110677ecbe5a2ea865936e627dbc3a9..2827b9c9a0535813d9bd2fc9550382016a2ab0d8 100644
--- a/openair2/LAYER2/PROTO_AGENT/cu_test.c
+++ b/openair2/LAYER2/PROTO_AGENT/cu_test.c
@@ -126,7 +126,7 @@ rlc_op_status_t rlc_data_req     (const protocol_ctxt_t* const ctxt_pP,
                                   confirm_t    confirmP,
                                   sdu_size_t   sdu_sizeP,
                                   mem_block_t *sdu_pP
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                                   ,const uint32_t * const sourceL2Id
                                   ,const uint32_t * const destinationL2Id
 #endif
diff --git a/openair2/LAYER2/PROTO_AGENT/du_test.c b/openair2/LAYER2/PROTO_AGENT/du_test.c
index 2084db3298d392901a2827b504d714fa0964a166..7fa9971f5a6b995b201d8cee083e90d8f1363766 100644
--- a/openair2/LAYER2/PROTO_AGENT/du_test.c
+++ b/openair2/LAYER2/PROTO_AGENT/du_test.c
@@ -31,7 +31,7 @@ rlc_op_status_t rlc_data_req     (const protocol_ctxt_t* const ctxt_pP,
                                   confirm_t    confirmP,
                                   sdu_size_t   sdu_sizeP,
                                   mem_block_t *sdu_pP
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                                   ,const uint32_t * const sourceL2Id
                                   ,const uint32_t * const destinationL2Id
 #endif
diff --git a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am.c b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am.c
index eda3bd76e4df7f8336cdb9fcf585d2b56177cfa6..30173b62ffacf81ebead5d3edca31e941a5b54e9 100644
--- a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am.c
+++ b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am.c
@@ -25,9 +25,7 @@
 #include "platform_types.h"
 #include "platform_constants.h"
 //-----------------------------------------------------------------------------
-#if ENABLE_ITTI
-# include "intertask_interface.h"
-#endif
+
 #include "assertions.h"
 #include "msc.h"
 #include "hashtable.h"
@@ -39,178 +37,151 @@
 #include "list.h"
 #include "LAYER2/MAC/mac_extern.h"
 #include "common/utils/LOG/log.h"
-#include "UL-AM-RLC.h"
-#include "DL-AM-RLC.h"
+#include "LTE_UL-AM-RLC.h"
+#include "LTE_DL-AM-RLC.h"
 
-#define TRACE_RLC_AM_PDU 1
 //-----------------------------------------------------------------------------
 uint32_t
 rlc_am_get_status_pdu_buffer_occupancy(
-  rlc_am_entity_t * const      rlc_pP){
-
-	//Compute Max Status PDU size according to what has been received and not received in the window [vrR vrMS[
-
-    // minimum header size in bits to be transmitted: D/C + CPT + ACK_SN + E1
-	uint32_t                    nb_bits_to_transmit	  = RLC_AM_PDU_D_C_BITS + RLC_AM_STATUS_PDU_CPT_LENGTH + RLC_AM_SN_BITS + RLC_AM_PDU_E_BITS;
-	mem_block_t                  *cursor_p              = rlc_pP->receiver_buffer.head;
-    rlc_am_pdu_info_t            *pdu_info_cursor_p     = NULL;
-    int                           waited_so             = 0;
-
-	rlc_sn_t sn_cursor = rlc_pP->vr_r;
-	rlc_sn_t sn_prev = rlc_pP->vr_r;
-	rlc_sn_t sn_end = rlc_pP->vr_ms;
-	boolean_t	segment_loop_end	  = false;
-
-
-	if (sn_prev != sn_end)
-	{
-		while ((RLC_AM_DIFF_SN(sn_prev,rlc_pP->vr_r) < RLC_AM_DIFF_SN(sn_end,rlc_pP->vr_r)) && (cursor_p != NULL))
-		{
-			pdu_info_cursor_p     = &((rlc_am_rx_pdu_management_t*)(cursor_p->data))->pdu_info;
-			sn_cursor             = pdu_info_cursor_p->sn;
-
-			// Add holes between sn_prev and sn_cursor
-			while ((sn_prev != sn_cursor) && (sn_prev != sn_end))
-			{
-				  /* Add 1 NACK_SN + E1 + E2 */
-				  nb_bits_to_transmit += (RLC_AM_SN_BITS + (RLC_AM_PDU_E_BITS << 1));
-				  sn_prev = RLC_AM_NEXT_SN(sn_prev);
-			} //end while (sn_prev != sn_cursor)
-
-			/* Handle case sn_cursor is partially received */
-			/* Each gap will add NACK_SN + E1 + E2 + SOStart + SOEnd */
-			if ((((rlc_am_rx_pdu_management_t*)(cursor_p->data))->all_segments_received == 0) && (RLC_AM_DIFF_SN(sn_cursor,rlc_pP->vr_r) < RLC_AM_DIFF_SN(sn_end,rlc_pP->vr_r)))
-			{
-                 /* Check lsf */
-				  segment_loop_end = (pdu_info_cursor_p->lsf == 1);
-
-	    		  /* Fill for [0 SO[ if SO not null */
-	    		  if (pdu_info_cursor_p->so) {
-	    			  nb_bits_to_transmit += (RLC_AM_SN_BITS + (RLC_AM_PDU_E_BITS << 1) + (RLC_AM_STATUS_PDU_SO_LENGTH << 1));
-	                  waited_so = pdu_info_cursor_p->so + pdu_info_cursor_p->payload_size;
-	    		  }
-	    		  else {
-	        		  waited_so = pdu_info_cursor_p->payload_size;
-	    		  }
-
-                  /* Go to next segment */
-                  cursor_p = cursor_p->next;
-                  if (cursor_p != NULL)
-                  {
-                      pdu_info_cursor_p     = &((rlc_am_rx_pdu_management_t*)(cursor_p->data))->pdu_info;
-                  }
+  rlc_am_entity_t *const      rlc_pP) {
+  //Compute Max Status PDU size according to what has been received and not received in the window [vrR vrMS[
+  // minimum header size in bits to be transmitted: D/C + CPT + ACK_SN + E1
+  uint32_t                    nb_bits_to_transmit   = RLC_AM_PDU_D_C_BITS + RLC_AM_STATUS_PDU_CPT_LENGTH + RLC_AM_SN_BITS + RLC_AM_PDU_E_BITS;
+  mem_block_t                  *cursor_p              = rlc_pP->receiver_buffer.head;
+  rlc_am_pdu_info_t            *pdu_info_cursor_p     = NULL;
+  int                           waited_so             = 0;
+  rlc_sn_t sn_cursor = rlc_pP->vr_r;
+  rlc_sn_t sn_prev = rlc_pP->vr_r;
+  rlc_sn_t sn_end = rlc_pP->vr_ms;
+  boolean_t segment_loop_end    = false;
+
+  if (sn_prev != sn_end) {
+    while ((RLC_AM_DIFF_SN(sn_prev,rlc_pP->vr_r) < RLC_AM_DIFF_SN(sn_end,rlc_pP->vr_r)) && (cursor_p != NULL)) {
+      pdu_info_cursor_p     = &((rlc_am_rx_pdu_management_t *)(cursor_p->data))->pdu_info;
+      sn_cursor             = pdu_info_cursor_p->sn;
+
+      // Add holes between sn_prev and sn_cursor
+      while ((sn_prev != sn_cursor) && (sn_prev != sn_end)) {
+        /* Add 1 NACK_SN + E1 + E2 */
+        nb_bits_to_transmit += (RLC_AM_SN_BITS + (RLC_AM_PDU_E_BITS << 1));
+        sn_prev = RLC_AM_NEXT_SN(sn_prev);
+      } //end while (sn_prev != sn_cursor)
+
+      /* Handle case sn_cursor is partially received */
+      /* Each gap will add NACK_SN + E1 + E2 + SOStart + SOEnd */
+      if ((((rlc_am_rx_pdu_management_t *)(cursor_p->data))->all_segments_received == 0) && (RLC_AM_DIFF_SN(sn_cursor,rlc_pP->vr_r) < RLC_AM_DIFF_SN(sn_end,rlc_pP->vr_r))) {
+        /* Check lsf */
+        segment_loop_end = (pdu_info_cursor_p->lsf == 1);
+
+        /* Fill for [0 SO[ if SO not null */
+        if (pdu_info_cursor_p->so) {
+          nb_bits_to_transmit += (RLC_AM_SN_BITS + (RLC_AM_PDU_E_BITS << 1) + (RLC_AM_STATUS_PDU_SO_LENGTH << 1));
+          waited_so = pdu_info_cursor_p->so + pdu_info_cursor_p->payload_size;
+        } else {
+          waited_so = pdu_info_cursor_p->payload_size;
+        }
+
+        /* Go to next segment */
+        cursor_p = cursor_p->next;
+
+        if (cursor_p != NULL) {
+          pdu_info_cursor_p     = &((rlc_am_rx_pdu_management_t *)(cursor_p->data))->pdu_info;
+        }
+
+        /* Fill following gaps if any */
+        while (!segment_loop_end) {
+          if ((cursor_p != NULL) && (pdu_info_cursor_p->sn == sn_cursor)) {
+            /* Check lsf */
+            segment_loop_end = (pdu_info_cursor_p->lsf == 1);
+
+            if (waited_so < pdu_info_cursor_p->so) {
+              nb_bits_to_transmit += (RLC_AM_SN_BITS + (RLC_AM_PDU_E_BITS << 1) + (RLC_AM_STATUS_PDU_SO_LENGTH << 1));
+            } else {
+              /* contiguous segment: only update waited_so */
+              /* Assuming so and payload_size updated according to duplication removal done at reception ... */
+              waited_so += pdu_info_cursor_p->payload_size;
+            }
+
+            /* Go to next received PDU or PDU Segment */
+            cursor_p = cursor_p->next;
+
+            if (cursor_p != NULL) {
+              pdu_info_cursor_p     = &((rlc_am_rx_pdu_management_t *)(cursor_p->data))->pdu_info;
+            }
+          } else {
+            /* Fill last gap assuming LSF is not received */
+            nb_bits_to_transmit += (RLC_AM_SN_BITS + (RLC_AM_PDU_E_BITS << 1) + (RLC_AM_STATUS_PDU_SO_LENGTH << 1));
+            segment_loop_end = true;
+          }
+        } // end while (!segment_loop_end)
+      } // end if segments
+      else {
+        /* Go to next received PDU or PDU segment with different SN */
+        do {
+          cursor_p = cursor_p->next;
+        } while ((cursor_p != NULL) && (((rlc_am_rx_pdu_management_t *)(cursor_p->data))->pdu_info.sn == sn_cursor));
+      }
 
-	    		  /* Fill following gaps if any */
-	    		  while (!segment_loop_end)
-	    		  {
-	    			  if ((cursor_p != NULL) && (pdu_info_cursor_p->sn == sn_cursor))
-	    			  {
-		                  /* Check lsf */
-	    				  segment_loop_end = (pdu_info_cursor_p->lsf == 1);
-
-            			  if (waited_so < pdu_info_cursor_p->so) {
-    	                      nb_bits_to_transmit += (RLC_AM_SN_BITS + (RLC_AM_PDU_E_BITS << 1) + (RLC_AM_STATUS_PDU_SO_LENGTH << 1));
-            			  }
-            			  else {
-            				  /* contiguous segment: only update waited_so */
-            				  /* Assuming so and payload_size updated according to duplication removal done at reception ... */
-            				  waited_so += pdu_info_cursor_p->payload_size;
-            			  }
-
-            			  /* Go to next received PDU or PDU Segment */
-            			  cursor_p = cursor_p->next;
-    	                  if (cursor_p != NULL)
-    	                  {
-    		                  pdu_info_cursor_p     = &((rlc_am_rx_pdu_management_t*)(cursor_p->data))->pdu_info;
-    	                  }
-	    			  }
-	    			  else
-	    			  {
-	    				  /* Fill last gap assuming LSF is not received */
-	    				  nb_bits_to_transmit += (RLC_AM_SN_BITS + (RLC_AM_PDU_E_BITS << 1) + (RLC_AM_STATUS_PDU_SO_LENGTH << 1));
-	    				  segment_loop_end = true;
-	    			  }
-	    		  } // end while (!segment_loop_end)
-			} // end if segments
-			else
-			{
-				  /* Go to next received PDU or PDU segment with different SN */
-				  do
-				  {
-					  cursor_p = cursor_p->next;
-				  } while ((cursor_p != NULL) && (((rlc_am_rx_pdu_management_t*)(cursor_p->data))->pdu_info.sn == sn_cursor));
-			}
-
-			sn_prev = RLC_AM_NEXT_SN(sn_cursor);
-		}
-	} // end if (sn_prev != sn_end)
-
-	// round up to the greatest byte
-	return ((nb_bits_to_transmit + 7) >> 3);
+      sn_prev = RLC_AM_NEXT_SN(sn_cursor);
+    }
+  } // end if (sn_prev != sn_end)
 
+  // round up to the greatest byte
+  return ((nb_bits_to_transmit + 7) >> 3);
 }
 
 //-----------------------------------------------------------------------------
 uint32_t
 rlc_am_get_buffer_occupancy_in_bytes (
-  const protocol_ctxt_t* const ctxt_pP,
-  rlc_am_entity_t * const      rlc_pP)
-{
+  const protocol_ctxt_t *const ctxt_pP,
+  rlc_am_entity_t *const      rlc_pP) {
   // priority of control trafic
   rlc_pP->status_buffer_occupancy = 0;
-  if ((rlc_pP->status_requested) && !(rlc_pP->status_requested & RLC_AM_STATUS_NO_TX_MASK)) {
-      rlc_pP->status_buffer_occupancy = rlc_am_get_status_pdu_buffer_occupancy(rlc_pP);
-#if TRACE_RLC_AM_BO
-
-        LOG_D(RLC, PROTOCOL_CTXT_FMT RB_AM_FMT" BO : CONTROL PDU %d bytes \n",
-              PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
-			rlc_pP->status_buffer_occupancy);
 
-#endif
+  if ((rlc_pP->status_requested) && !(rlc_pP->status_requested & RLC_AM_STATUS_NO_TX_MASK)) {
+    rlc_pP->status_buffer_occupancy = rlc_am_get_status_pdu_buffer_occupancy(rlc_pP);
+    LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT" BO : CONTROL PDU %d bytes \n",
+          PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
+          rlc_pP->status_buffer_occupancy);
   }
 
-
-#if TRACE_RLC_AM_BO
-
-  if ((rlc_pP->status_buffer_occupancy + rlc_pP->retrans_num_bytes_to_retransmit + rlc_pP->sdu_buffer_occupancy + max_li_overhead + header_overhead) > 0) {
-    LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT" BO : STATUS  BUFFER %d bytes \n", PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP), rlc_pP->status_buffer_occupancy);
-    LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT" BO : RETRANS BUFFER %d bytes \n", PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP), rlc_pP->retrans_num_bytes_to_retransmit);
-    LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT" BO : SDU     BUFFER %d bytes + li_overhead %d bytes header_overhead %d bytes (nb sdu not segmented %d)\n",
-          PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
-          rlc_pP->sdu_buffer_occupancy,
-          0,
-          0,
-          rlc_pP->nb_sdu_no_segmented);
+  if ( LOG_DEBUGFLAG(DEBUG_RLC)) {
+    if ((rlc_pP->status_buffer_occupancy + rlc_pP->retrans_num_bytes_to_retransmit + rlc_pP->sdu_buffer_occupancy ) > 0) {
+      LOG_UI(RLC, PROTOCOL_RLC_AM_CTXT_FMT" BO : STATUS  BUFFER %d bytes \n", PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP), rlc_pP->status_buffer_occupancy);
+      LOG_UI(RLC, PROTOCOL_RLC_AM_CTXT_FMT" BO : RETRANS BUFFER %d bytes \n", PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP), rlc_pP->retrans_num_bytes_to_retransmit);
+      LOG_UI(RLC, PROTOCOL_RLC_AM_CTXT_FMT" BO : SDU	BUFFER %d bytes + li_overhead %d bytes header_overhead %d bytes (nb sdu not segmented %d)\n",
+             PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
+             rlc_pP->sdu_buffer_occupancy,
+             0,
+             0,
+             rlc_pP->nb_sdu_no_segmented);
+    }
   }
 
-#endif
   return rlc_pP->status_buffer_occupancy + rlc_pP->retrans_num_bytes_to_retransmit + rlc_pP->sdu_buffer_occupancy;
 }
 //-----------------------------------------------------------------------------
 void
 rlc_am_release (
-  const protocol_ctxt_t* const ctxt_pP,
-  rlc_am_entity_t * const      rlc_pP
-)
-{
+  const protocol_ctxt_t *const ctxt_pP,
+  rlc_am_entity_t *const      rlc_pP
+) {
   // empty
 }
 //-----------------------------------------------------------------------------
 void
 config_req_rlc_am (
-  const protocol_ctxt_t* const ctxt_pP,
+  const protocol_ctxt_t *const ctxt_pP,
   const srb_flag_t             srb_flagP,
-  const rlc_am_info_t  *       config_am_pP,
+  const rlc_am_info_t         *config_am_pP,
   const rb_id_t                rb_idP,
-  const logical_chan_id_t      chan_idP 
-)
-{
+  const logical_chan_id_t      chan_idP
+) {
   rlc_union_t       *rlc_union_p = NULL;
   rlc_am_entity_t *l_rlc_p         = NULL;
   hash_key_t       key           = RLC_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, srb_flagP);
   hashtable_rc_t   h_rc;
-
-  h_rc = hashtable_get(rlc_coll_p, key, (void**)&rlc_union_p);
+  h_rc = hashtable_get(rlc_coll_p, key, (void **)&rlc_union_p);
 
   if (h_rc == HASH_TABLE_OK) {
     l_rlc_p = &rlc_union_p->rlc.am;
@@ -237,50 +208,47 @@ config_req_rlc_am (
           PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,l_rlc_p));
   }
 }
-uint16_t pollPDU_tab[PollPDU_pInfinity+1]= {4,8,16,32,64,128,256,RLC_AM_POLL_PDU_INFINITE}; //PollPDU_pInfinity is chosen to 0xFFFF for now
-uint32_t maxRetxThreshold_tab[UL_AM_RLC__maxRetxThreshold_t32+1]= {1,2,3,4,6,8,16,32};
-uint32_t pollByte_tab[PollByte_spare1]= {25000,50000,75000,100000,125000,250000,375000,500000,750000,1000000,1250000,1500000,2000000,3000000,RLC_AM_POLL_BYTE_INFINITE}; // PollByte_kBinfinity is chosen to 0xFFFFFFFF for now
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-uint32_t PollRetransmit_tab[T_PollRetransmit_spare5]= {5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,105,110,115,120,125,130,135,140,145,150,155,160,165,170,175,180,185,190,195,200,205,210,215,220,225,230,235,240,245,250,300,350,400,450,500,800,1000,2000,4000};
+uint16_t pollPDU_tab[LTE_PollPDU_pInfinity+1]= {4,8,16,32,64,128,256,RLC_AM_POLL_PDU_INFINITE}; //PollPDU_pInfinity is chosen to 0xFFFF for now
+uint32_t maxRetxThreshold_tab[LTE_UL_AM_RLC__maxRetxThreshold_t32+1]= {1,2,3,4,6,8,16,32};
+uint32_t pollByte_tab[LTE_PollByte_spare1]= {25000,50000,75000,100000,125000,250000,375000,500000,750000,1000000,1250000,1500000,2000000,3000000,RLC_AM_POLL_BYTE_INFINITE}; // PollByte_kBinfinity is chosen to 0xFFFFFFFF for now
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+uint32_t PollRetransmit_tab[LTE_T_PollRetransmit_spare5]= {5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,105,110,115,120,125,130,135,140,145,150,155,160,165,170,175,180,185,190,195,200,205,210,215,220,225,230,235,240,245,250,300,350,400,450,500,800,1000,2000,4000};
 uint32_t am_t_Reordering_tab[32]= {0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,110,120,130,140,150,160,170,180,190,200,1600};
-uint32_t t_StatusProhibit_tab[T_StatusProhibit_spare2]= {0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,105,110,115,120,125,130,135,140,145,150,155,160,165,170,175,180,185,190,195,200,205,210,215,220,225,230,235,240,245,250,300,350,400,450,500,800,1000,1200,1600,2000,2400};
+uint32_t t_StatusProhibit_tab[LTE_T_StatusProhibit_spare2]= {0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,105,110,115,120,125,130,135,140,145,150,155,160,165,170,175,180,185,190,195,200,205,210,215,220,225,230,235,240,245,250,300,350,400,450,500,800,1000,1200,1600,2000,2400};
 #else
-uint32_t PollRetransmit_tab[T_PollRetransmit_spare9]= {5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,105,110,115,120,125,130,135,140,145,150,155,160,165,170,175,180,185,190,195,200,205,210,215,220,225,230,235,240,245,250,300,350,400,450,500};
-uint32_t am_t_Reordering_tab[T_Reordering_spare1]= {0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,110,120,130,140,150,160,170,180,190,200};
-uint32_t t_StatusProhibit_tab[T_StatusProhibit_spare8]= {0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,105,110,115,120,125,130,135,140,145,150,155,160,165,170,175,180,185,190,195,200,205,210,215,220,225,230,235,240,245,250,300,350,400,450,500};
+uint32_t PollRetransmit_tab[LTE_T_PollRetransmit_spare9]= {5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,105,110,115,120,125,130,135,140,145,150,155,160,165,170,175,180,185,190,195,200,205,210,215,220,225,230,235,240,245,250,300,350,400,450,500};
+uint32_t am_t_Reordering_tab[LTE_T_Reordering_spare1]= {0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,110,120,130,140,150,160,170,180,190,200};
+uint32_t t_StatusProhibit_tab[LTE_T_StatusProhibit_spare8]= {0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,105,110,115,120,125,130,135,140,145,150,155,160,165,170,175,180,185,190,195,200,205,210,215,220,225,230,235,240,245,250,300,350,400,450,500};
 #endif
 
 //-----------------------------------------------------------------------------
 void config_req_rlc_am_asn1 (
-  const protocol_ctxt_t* const         ctxt_pP,
+  const protocol_ctxt_t *const         ctxt_pP,
   const srb_flag_t                     srb_flagP,
-  const struct RLC_Config__am  * const config_am_pP,
+  const struct LTE_RLC_Config__am   *const config_am_pP,
   const rb_id_t                        rb_idP,
-  const logical_chan_id_t              chan_idP)
-{
+  const logical_chan_id_t              chan_idP) {
   rlc_union_t     *rlc_union_p   = NULL;
   rlc_am_entity_t *l_rlc_p         = NULL;
   hash_key_t       key           = RLC_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, srb_flagP);
   hashtable_rc_t   h_rc;
-
-  h_rc = hashtable_get(rlc_coll_p, key, (void**)&rlc_union_p);
+  h_rc = hashtable_get(rlc_coll_p, key, (void **)&rlc_union_p);
 
   if (h_rc == HASH_TABLE_OK) {
     l_rlc_p = &rlc_union_p->rlc.am;
 
-    if ((config_am_pP->ul_AM_RLC.maxRetxThreshold <= UL_AM_RLC__maxRetxThreshold_t32) &&
-        (config_am_pP->ul_AM_RLC.pollPDU<=PollPDU_pInfinity) &&
-        (config_am_pP->ul_AM_RLC.pollByte<PollByte_spare1) &&
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-        (config_am_pP->ul_AM_RLC.t_PollRetransmit<T_PollRetransmit_spare5) &&
+    if ((config_am_pP->ul_AM_RLC.maxRetxThreshold <= LTE_UL_AM_RLC__maxRetxThreshold_t32) &&
+        (config_am_pP->ul_AM_RLC.pollPDU<=LTE_PollPDU_pInfinity) &&
+        (config_am_pP->ul_AM_RLC.pollByte<LTE_PollByte_spare1) &&
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+        (config_am_pP->ul_AM_RLC.t_PollRetransmit<LTE_T_PollRetransmit_spare5) &&
         (config_am_pP->dl_AM_RLC.t_Reordering<32) &&
-        (config_am_pP->dl_AM_RLC.t_StatusProhibit<T_StatusProhibit_spare2) ) {
+        (config_am_pP->dl_AM_RLC.t_StatusProhibit<LTE_T_StatusProhibit_spare2) ) {
 #else
-        (config_am_pP->ul_AM_RLC.t_PollRetransmit<T_PollRetransmit_spare9) &&
-        (config_am_pP->dl_AM_RLC.t_Reordering<T_Reordering_spare1) &&
-        (config_am_pP->dl_AM_RLC.t_StatusProhibit<T_StatusProhibit_spare8) ) {
+        (config_am_pP->ul_AM_RLC.t_PollRetransmitLTE_T_PollRetransmit_spare9) &&
+        (config_am_pP->dl_AM_RLC.t_Reordering<LTE_T_Reordering_spare1) &&
+        (config_am_pP->dl_AM_RLC.t_StatusProhibit<LTE_T_StatusProhibit_spare8) ) {
 #endif
-
       MSC_LOG_RX_MESSAGE(
         (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
         (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RRC_ENB:MSC_RRC_UE,
@@ -292,7 +260,6 @@ void config_req_rlc_am_asn1 (
         PollRetransmit_tab[config_am_pP->ul_AM_RLC.t_PollRetransmit],
         am_t_Reordering_tab[config_am_pP->dl_AM_RLC.t_Reordering],
         t_StatusProhibit_tab[config_am_pP->dl_AM_RLC.t_StatusProhibit]);
-
       LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT" CONFIG_REQ (max_retx_threshold=%d poll_pdu=%d poll_byte=%d t_poll_retransmit=%d t_reord=%d t_status_prohibit=%d)\n",
             PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,l_rlc_p),
             maxRetxThreshold_tab[config_am_pP->ul_AM_RLC.maxRetxThreshold],
@@ -301,7 +268,6 @@ void config_req_rlc_am_asn1 (
             PollRetransmit_tab[config_am_pP->ul_AM_RLC.t_PollRetransmit],
             am_t_Reordering_tab[config_am_pP->dl_AM_RLC.t_Reordering],
             t_StatusProhibit_tab[config_am_pP->dl_AM_RLC.t_StatusProhibit]);
-
       rlc_am_init(ctxt_pP, l_rlc_p);
       rlc_am_set_debug_infos(ctxt_pP, l_rlc_p, srb_flagP, rb_idP, chan_idP);
       rlc_am_configure(ctxt_pP, l_rlc_p,
@@ -311,7 +277,8 @@ void config_req_rlc_am_asn1 (
                        PollRetransmit_tab[config_am_pP->ul_AM_RLC.t_PollRetransmit],
                        am_t_Reordering_tab[config_am_pP->dl_AM_RLC.t_Reordering],
                        t_StatusProhibit_tab[config_am_pP->dl_AM_RLC.t_StatusProhibit]);
-    } else {
+    }
+    else {
       MSC_LOG_RX_DISCARDED_MESSAGE(
         (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
         (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RRC_ENB:MSC_RRC_UE,
@@ -320,7 +287,6 @@ void config_req_rlc_am_asn1 (
         MSC_AS_TIME_FMT" "PROTOCOL_RLC_AM_MSC_FMT" CONFIG-REQ",
         MSC_AS_TIME_ARGS(ctxt_pP),
         PROTOCOL_RLC_AM_MSC_ARGS(ctxt_pP, l_rlc_p));
-
       LOG_D(RLC,
             PROTOCOL_RLC_AM_CTXT_FMT"ILLEGAL CONFIG_REQ (max_retx_threshold=%ld poll_pdu=%ld poll_byte=%ld t_poll_retransmit=%ld t_reord=%ld t_status_prohibit=%ld), RLC-AM NOT CONFIGURED\n",
             PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,l_rlc_p),
@@ -339,36 +305,35 @@ void config_req_rlc_am_asn1 (
 
 //-----------------------------------------------------------------------------
 void rlc_am_stat_req (
-  const protocol_ctxt_t* const         ctxt_pP,
-  rlc_am_entity_t * const              rlc_pP,
-  unsigned int* stat_tx_pdcp_sdu,
-  unsigned int* stat_tx_pdcp_bytes,
-  unsigned int* stat_tx_pdcp_sdu_discarded,
-  unsigned int* stat_tx_pdcp_bytes_discarded,
-  unsigned int* stat_tx_data_pdu,
-  unsigned int* stat_tx_data_bytes,
-  unsigned int* stat_tx_retransmit_pdu_by_status,
-  unsigned int* stat_tx_retransmit_bytes_by_status,
-  unsigned int* stat_tx_retransmit_pdu,
-  unsigned int* stat_tx_retransmit_bytes,
-  unsigned int* stat_tx_control_pdu,
-  unsigned int* stat_tx_control_bytes,
-  unsigned int* stat_rx_pdcp_sdu,
-  unsigned int* stat_rx_pdcp_bytes,
-  unsigned int* stat_rx_data_pdus_duplicate,
-  unsigned int* stat_rx_data_bytes_duplicate,
-  unsigned int* stat_rx_data_pdu,
-  unsigned int* stat_rx_data_bytes,
-  unsigned int* stat_rx_data_pdu_dropped,
-  unsigned int* stat_rx_data_bytes_dropped,
-  unsigned int* stat_rx_data_pdu_out_of_window,
-  unsigned int* stat_rx_data_bytes_out_of_window,
-  unsigned int* stat_rx_control_pdu,
-  unsigned int* stat_rx_control_bytes,
-  unsigned int* stat_timer_reordering_timed_out,
-  unsigned int* stat_timer_poll_retransmit_timed_out,
-  unsigned int* stat_timer_status_prohibit_timed_out)
-{
+  const protocol_ctxt_t *const         ctxt_pP,
+  rlc_am_entity_t *const              rlc_pP,
+  unsigned int *stat_tx_pdcp_sdu,
+  unsigned int *stat_tx_pdcp_bytes,
+  unsigned int *stat_tx_pdcp_sdu_discarded,
+  unsigned int *stat_tx_pdcp_bytes_discarded,
+  unsigned int *stat_tx_data_pdu,
+  unsigned int *stat_tx_data_bytes,
+  unsigned int *stat_tx_retransmit_pdu_by_status,
+  unsigned int *stat_tx_retransmit_bytes_by_status,
+  unsigned int *stat_tx_retransmit_pdu,
+  unsigned int *stat_tx_retransmit_bytes,
+  unsigned int *stat_tx_control_pdu,
+  unsigned int *stat_tx_control_bytes,
+  unsigned int *stat_rx_pdcp_sdu,
+  unsigned int *stat_rx_pdcp_bytes,
+  unsigned int *stat_rx_data_pdus_duplicate,
+  unsigned int *stat_rx_data_bytes_duplicate,
+  unsigned int *stat_rx_data_pdu,
+  unsigned int *stat_rx_data_bytes,
+  unsigned int *stat_rx_data_pdu_dropped,
+  unsigned int *stat_rx_data_bytes_dropped,
+  unsigned int *stat_rx_data_pdu_out_of_window,
+  unsigned int *stat_rx_data_bytes_out_of_window,
+  unsigned int *stat_rx_control_pdu,
+  unsigned int *stat_rx_control_bytes,
+  unsigned int *stat_timer_reordering_timed_out,
+  unsigned int *stat_timer_poll_retransmit_timed_out,
+  unsigned int *stat_timer_status_prohibit_timed_out) {
   *stat_tx_pdcp_sdu                     = rlc_pP->stat_tx_pdcp_sdu;
   *stat_tx_pdcp_bytes                   = rlc_pP->stat_tx_pdcp_bytes;
   *stat_tx_pdcp_sdu_discarded           = rlc_pP->stat_tx_pdcp_sdu_discarded;
@@ -396,15 +361,13 @@ void rlc_am_stat_req (
   *stat_timer_reordering_timed_out      = rlc_pP->stat_timer_reordering_timed_out;
   *stat_timer_poll_retransmit_timed_out = rlc_pP->stat_timer_poll_retransmit_timed_out;
   *stat_timer_status_prohibit_timed_out = rlc_pP->stat_timer_status_prohibit_timed_out;
-
 }
 //-----------------------------------------------------------------------------
 void
 rlc_am_get_pdus (
-  const protocol_ctxt_t* const ctxt_pP,
-  rlc_am_entity_t * const      rlc_pP
-)
-{
+  const protocol_ctxt_t *const ctxt_pP,
+  rlc_am_entity_t *const      rlc_pP
+) {
   //int display_flag = 0;
   // 5.1.3.1 Transmit operations
   // 5.1.3.1.1
@@ -412,31 +375,27 @@ rlc_am_get_pdus (
   // The transmitting side of an AM RLC entity shall prioritize transmission of RLC control PDUs over RLC data PDUs.
   // The transmitting side of an AM RLC entity shall prioritize retransmission of RLC data PDUs over transmission of new
   // AMD PDUs.
-
-
   switch (rlc_pP->protocol_state) {
-
-  case RLC_NULL_STATE:
-    break;
-
-  case RLC_DATA_TRANSFER_READY_STATE:
-
-    // TRY TO SEND CONTROL PDU FIRST
-    if ((rlc_pP->nb_bytes_requested_by_mac >= 2) &&
-    		((rlc_pP->status_requested) && !(rlc_pP->status_requested & RLC_AM_STATUS_NO_TX_MASK))) {
-      // When STATUS reporting has been triggered, the receiving side of an AM RLC entity shall:
-      // - if t-StatusProhibit is not running:
-      //     - at the first transmission opportunity indicated by lower layer, construct a STATUS PDU and deliver it to lower layer;
-      // - else:
-      //     - at the first transmission opportunity indicated by lower layer after t-StatusProhibit expires, construct a single
-      //       STATUS PDU even if status reporting was triggered several times while t-StatusProhibit was running and
-      //       deliver it to lower layer;
-      //
-      // When a STATUS PDU has been delivered to lower layer, the receiving side of an AM RLC entity shall:
-      //     - start t-StatusProhibit.
-
+    case RLC_NULL_STATE:
+      break;
+
+    case RLC_DATA_TRANSFER_READY_STATE:
+
+      // TRY TO SEND CONTROL PDU FIRST
+      if ((rlc_pP->nb_bytes_requested_by_mac >= 2) &&
+          ((rlc_pP->status_requested) && !(rlc_pP->status_requested & RLC_AM_STATUS_NO_TX_MASK))) {
+        // When STATUS reporting has been triggered, the receiving side of an AM RLC entity shall:
+        // - if t-StatusProhibit is not running:
+        //     - at the first transmission opportunity indicated by lower layer, construct a STATUS PDU and deliver it to lower layer;
+        // - else:
+        //     - at the first transmission opportunity indicated by lower layer after t-StatusProhibit expires, construct a single
+        //       STATUS PDU even if status reporting was triggered several times while t-StatusProhibit was running and
+        //       deliver it to lower layer;
+        //
+        // When a STATUS PDU has been delivered to lower layer, the receiving side of an AM RLC entity shall:
+        //     - start t-StatusProhibit.
         rlc_am_send_status_pdu(ctxt_pP, rlc_pP);
-        mem_block_t* pdu = list_remove_head(&rlc_pP->control_pdu_list);
+        mem_block_t *pdu = list_remove_head(&rlc_pP->control_pdu_list);
 
         if (pdu) {
           list_add_tail_eurecom (pdu, &rlc_pP->pdus_to_mac_layer);
@@ -445,89 +404,81 @@ rlc_am_get_pdus (
           rlc_am_start_timer_status_prohibit(ctxt_pP, rlc_pP);
           return;
         }
-      }
-      else {
-              LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT" DELAYED SENT STATUS PDU (Available MAC Data %u)(T-PROHIBIT %u) (DELAY FLAG %u)\n",
+      } else {
+        LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT" DELAYED SENT STATUS PDU (Available MAC Data %u)(T-PROHIBIT %u) (DELAY FLAG %u)\n",
               PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
-					rlc_pP->nb_bytes_requested_by_mac,rlc_pP->t_status_prohibit.ms_time_out,(rlc_pP->status_requested & RLC_AM_STATUS_TRIGGERED_DELAYED));
-    }
+              rlc_pP->nb_bytes_requested_by_mac,rlc_pP->t_status_prohibit.ms_time_out,(rlc_pP->status_requested & RLC_AM_STATUS_TRIGGERED_DELAYED));
+      }
 
-    // THEN TRY TO SEND RETRANS PDU
+      // THEN TRY TO SEND RETRANS PDU
       if ((rlc_pP->retrans_num_bytes_to_retransmit) && (rlc_pP->nb_bytes_requested_by_mac > 2)) {
+        /* Get 1 AM data PDU or PDU segment to retransmit */
+        mem_block_t *pdu_retx = rlc_am_get_pdu_to_retransmit(ctxt_pP, rlc_pP);
 
-      /* Get 1 AM data PDU or PDU segment to retransmit */
-      mem_block_t* pdu_retx = rlc_am_get_pdu_to_retransmit(ctxt_pP, rlc_pP);
-
-      if (pdu_retx != NULL) {
-    	  list_add_tail_eurecom (pdu_retx, &rlc_pP->pdus_to_mac_layer);
-
+        if (pdu_retx != NULL) {
+          list_add_tail_eurecom (pdu_retx, &rlc_pP->pdus_to_mac_layer);
           return;
         }
-        }
+      }
 
-    // THEN TRY TO SEND NEW DATA PDU
-    if ((rlc_pP->nb_bytes_requested_by_mac > 2) && (rlc_pP->sdu_buffer_occupancy) && (rlc_pP->vt_s != rlc_pP->vt_ms)) {
-      rlc_am_segment_10(ctxt_pP, rlc_pP);
-      list_add_list (&rlc_pP->segmentation_pdu_list, &rlc_pP->pdus_to_mac_layer);
+      // THEN TRY TO SEND NEW DATA PDU
+      if ((rlc_pP->nb_bytes_requested_by_mac > 2) && (rlc_pP->sdu_buffer_occupancy) && (rlc_pP->vt_s != rlc_pP->vt_ms)) {
+        rlc_am_segment_10(ctxt_pP, rlc_pP);
+        list_add_list (&rlc_pP->segmentation_pdu_list, &rlc_pP->pdus_to_mac_layer);
 
-      if (rlc_pP->pdus_to_mac_layer.head != NULL) {
-        rlc_pP->stat_tx_data_pdu                   += 1;
-        rlc_pP->stat_tx_data_bytes                 += (((struct mac_tb_req*)(rlc_pP->pdus_to_mac_layer.head->data))->tb_size);
-        return;
+        if (rlc_pP->pdus_to_mac_layer.head != NULL) {
+          rlc_pP->stat_tx_data_pdu                   += 1;
+          rlc_pP->stat_tx_data_bytes                 += (((struct mac_tb_req *)(rlc_pP->pdus_to_mac_layer.head->data))->tb_size);
+          return;
+        }
       }
-    }
 
+      break;
 
-    break;
-
-  default:
-    LOG_E(RLC, PROTOCOL_RLC_AM_CTXT_FMT" MAC_DATA_REQ UNKNOWN PROTOCOL STATE 0x%02X\n",
-          PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
-          rlc_pP->protocol_state);
+    default:
+      LOG_E(RLC, PROTOCOL_RLC_AM_CTXT_FMT" MAC_DATA_REQ UNKNOWN PROTOCOL STATE 0x%02X\n",
+            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
+            rlc_pP->protocol_state);
   }
 }
 //-----------------------------------------------------------------------------
 void
 rlc_am_rx (
-  const protocol_ctxt_t* const ctxt_pP,
-  void * const                 arg_pP,
+  const protocol_ctxt_t *const ctxt_pP,
+  void *const                 arg_pP,
   struct mac_data_ind          data_indP
-)
-{
+) {
   rlc_am_entity_t *rlc = (rlc_am_entity_t *) arg_pP;
 
   switch (rlc->protocol_state) {
-
-  case RLC_NULL_STATE:
-    LOG_I(RLC, PROTOCOL_RLC_AM_CTXT_FMT" ERROR MAC_DATA_IND IN RLC_NULL_STATE\n", PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP, rlc));
-    list_free (&data_indP.data);
-    break;
-
-  case RLC_DATA_TRANSFER_READY_STATE:
-    rlc_am_receive_routing (ctxt_pP, rlc, data_indP);
-    break;
-
-  default:
-    LOG_E(RLC, PROTOCOL_RLC_AM_CTXT_FMT" TX UNKNOWN PROTOCOL STATE 0x%02X\n", PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP, rlc), rlc->protocol_state);
-    list_free (&data_indP.data);
+    case RLC_NULL_STATE:
+      LOG_I(RLC, PROTOCOL_RLC_AM_CTXT_FMT" ERROR MAC_DATA_IND IN RLC_NULL_STATE\n", PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP, rlc));
+      list_free (&data_indP.data);
+      break;
+
+    case RLC_DATA_TRANSFER_READY_STATE:
+      rlc_am_receive_routing (ctxt_pP, rlc, data_indP);
+      break;
+
+    default:
+      LOG_E(RLC, PROTOCOL_RLC_AM_CTXT_FMT" TX UNKNOWN PROTOCOL STATE 0x%02X\n", PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP, rlc), rlc->protocol_state);
+      list_free (&data_indP.data);
   }
 }
 
 //-----------------------------------------------------------------------------
 struct mac_status_resp
 rlc_am_mac_status_indication (
-  const protocol_ctxt_t* const ctxt_pP,
-  void * const                 rlc_pP,
+  const protocol_ctxt_t *const ctxt_pP,
+  void *const                 rlc_pP,
   const uint16_t               tb_sizeP,
   struct mac_status_ind        tx_statusP,
-  const eNB_flag_t enb_flagP)
-{
+  const eNB_flag_t enb_flagP) {
   struct mac_status_resp  status_resp;
   uint16_t  sdu_size = 0;
   uint16_t  sdu_remaining_size = 0;
   int32_t diff_time=0;
   rlc_am_entity_t *rlc = (rlc_am_entity_t *) rlc_pP;
-
   status_resp.buffer_occupancy_in_bytes        = 0;
   status_resp.buffer_occupancy_in_pdus         = 0;
   status_resp.head_sdu_remaining_size_to_send  = 0;
@@ -561,31 +512,27 @@ rlc_am_mac_status_indication (
   // For eNB scheduler : Add Max RLC header size for new PDU
   // For UE : do not add RLC header part to be compliant with BSR definition in 36.321
   if (enb_flagP == ENB_FLAG_YES) {
-	  uint32_t max_li_overhead = 0;
-	  uint32_t header_overhead = 0;
+    uint32_t max_li_overhead = 0;
+    uint32_t header_overhead = 0;
 
-	   if (rlc->nb_sdu_no_segmented > 1) {
-	   	/* This computation assumes there is no SDU with size greater than 2047 bytes, otherwise a new PDU must be built except for LI15 configuration from Rel12*/
-	 	  uint32_t num_li = rlc->nb_sdu_no_segmented - 1;
-	       max_li_overhead = num_li + (num_li >> 1) + (num_li & 1);
-	   }
+    if (rlc->nb_sdu_no_segmented > 1) {
+      /* This computation assumes there is no SDU with size greater than 2047 bytes, otherwise a new PDU must be built except for LI15 configuration from Rel12*/
+      uint32_t num_li = rlc->nb_sdu_no_segmented - 1;
+      max_li_overhead = num_li + (num_li >> 1) + (num_li & 1);
+    }
 
-	   if (rlc->sdu_buffer_occupancy > 0) {
-	     header_overhead = 2;
-	   }
+    if (rlc->sdu_buffer_occupancy > 0) {
+      header_overhead = 2;
+    }
 
-	   status_resp.buffer_occupancy_in_bytes += (header_overhead + max_li_overhead);
+    status_resp.buffer_occupancy_in_bytes += (header_overhead + max_li_overhead);
   }
 
-
   if ((rlc->input_sdus[rlc->current_sdu_index].mem_block != NULL) && (status_resp.buffer_occupancy_in_bytes)) {
-
     //status_resp.buffer_occupancy_in_bytes += ((rlc_am_entity_t *) rlc)->tx_header_min_length_in_bytes;
     status_resp.buffer_occupancy_in_pdus = rlc->nb_sdu;
     diff_time =   ctxt_pP->frame - ((rlc_am_tx_sdu_management_t *) (rlc->input_sdus[rlc->current_sdu_index].mem_block->data))->sdu_creation_time;
-
     status_resp.head_sdu_creation_time = (diff_time > 0 ) ? (uint32_t) diff_time :  (uint32_t)(0xffffffff - diff_time + ctxt_pP->frame) ;
-
     sdu_size            = ((rlc_am_tx_sdu_management_t *) (rlc->input_sdus[rlc->current_sdu_index].mem_block->data))->sdu_size;
     sdu_remaining_size  = ((rlc_am_tx_sdu_management_t *) (rlc->input_sdus[rlc->current_sdu_index].mem_block->data))->sdu_remaining_size;
     status_resp.head_sdu_remaining_size_to_send = sdu_remaining_size;
@@ -595,83 +542,71 @@ rlc_am_mac_status_indication (
     } else {
       status_resp.head_sdu_is_segmented = 1;
     }
-
   } else {
-	  /* Not so many possibilities ... */
-	  /* either buffer_occupancy_in_bytes = 0 and that's it */
-	  /* or we have segmented all received SDUs and buffer occupancy is then made of retransmissions and/or status pdu pending */
-	  /* then consider only retransmission buffer for the specific BO values used by eNB scheduler (not used up to now...) */
-	  if (rlc->retrans_num_bytes_to_retransmit) {
-		  status_resp.buffer_occupancy_in_pdus = rlc->retrans_num_pdus;
-		  status_resp.head_sdu_remaining_size_to_send = rlc->retrans_num_bytes_to_retransmit;
-		  status_resp.head_sdu_is_segmented = 1;
-			    }
-			  }
-#if MESSAGE_CHART_GENERATOR_RLC_MAC
-  MSC_LOG_RX_MESSAGE(
-    (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
-    (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_MAC_ENB:MSC_MAC_UE,
-    NULL,0,
-    MSC_AS_TIME_FMT" "PROTOCOL_RLC_AM_MSC_FMT" STATUS-IND %u",
-    MSC_AS_TIME_ARGS(ctxt_pP),
-    PROTOCOL_RLC_AM_MSC_ARGS(ctxt_pP, rlc),
-    tb_sizeP);
-  MSC_LOG_TX_MESSAGE(
-    (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
-    (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_MAC_ENB:MSC_MAC_UE,
-    NULL,0,
-    MSC_AS_TIME_FMT" "PROTOCOL_RLC_AM_MSC_FMT" STATUS-RESP BO:%u/n%u(%u)  %s sdu remain %u",
-    MSC_AS_TIME_ARGS(ctxt_pP),
-    PROTOCOL_RLC_AM_MSC_ARGS(ctxt_pP, rlc),
-    status_resp.buffer_occupancy_in_bytes,
-    status_resp.buffer_occupancy_in_pdus,rlc->nb_sdu,
-    (status_resp.head_sdu_is_segmented)?"sdu seg":"sdu not seg",
-    status_resp.head_sdu_remaining_size_to_send);
-#endif
+    /* Not so many possibilities ... */
+    /* either buffer_occupancy_in_bytes = 0 and that's it */
+    /* or we have segmented all received SDUs and buffer occupancy is then made of retransmissions and/or status pdu pending */
+    /* then consider only retransmission buffer for the specific BO values used by eNB scheduler (not used up to now...) */
+    if (rlc->retrans_num_bytes_to_retransmit) {
+      status_resp.buffer_occupancy_in_pdus = rlc->retrans_num_pdus;
+      status_resp.head_sdu_remaining_size_to_send = rlc->retrans_num_bytes_to_retransmit;
+      status_resp.head_sdu_is_segmented = 1;
+    }
+  }
 
-#if TRACE_RLC_AM_TX_STATUS
+  if (MESSAGE_CHART_GENERATOR) {
+    MSC_LOG_RX_MESSAGE(
+      (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
+      (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_MAC_ENB:MSC_MAC_UE,
+      NULL,0,
+      MSC_AS_TIME_FMT" "PROTOCOL_RLC_AM_MSC_FMT" STATUS-IND %u",
+      MSC_AS_TIME_ARGS(ctxt_pP),
+      PROTOCOL_RLC_AM_MSC_ARGS(ctxt_pP, rlc),
+      tb_sizeP);
+    MSC_LOG_TX_MESSAGE(
+      (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
+      (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_MAC_ENB:MSC_MAC_UE,
+      NULL,0,
+      MSC_AS_TIME_FMT" "PROTOCOL_RLC_AM_MSC_FMT" STATUS-RESP BO:%u/n%u(%u)  %s sdu remain %u",
+      MSC_AS_TIME_ARGS(ctxt_pP),
+      PROTOCOL_RLC_AM_MSC_ARGS(ctxt_pP, rlc),
+      status_resp.buffer_occupancy_in_bytes,
+      status_resp.buffer_occupancy_in_pdus,rlc->nb_sdu,
+      (status_resp.head_sdu_is_segmented)?"sdu seg":"sdu not seg",
+      status_resp.head_sdu_remaining_size_to_send);
+  }
 
-  if (tb_sizeP > 0) {
-    LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT" MAC_STATUS_INDICATION (DATA) %d bytes -> %d bytes\n",
-          PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
-          tb_sizeP,
-          status_resp.buffer_occupancy_in_bytes);
-    /*if ((tx_statusP.tx_status == MAC_TX_STATUS_SUCCESSFUL) && (tx_statusP.no_pdu)) {
-        msg ("[FRAME %5u][%s][RLC_AM][MOD %u/%u][RB %u] MAC_STATUS_INDICATION  TX STATUS   SUCCESSFUL %d PDUs\n",rlc->module_id,
-    rlc->rb_id, ctxt_pP->frame, tx_statusP.no_pdu);
+  if (LOG_DEBUGFLAG(DEBUG_RLC)) {
+    if (tb_sizeP > 0) {
+      LOG_UI(RLC, PROTOCOL_RLC_AM_CTXT_FMT" MAC_STATUS_INDICATION (DATA) %d bytes -> %d bytes\n",
+             PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc),
+             tb_sizeP,
+             status_resp.buffer_occupancy_in_bytes);
     }
-    if ((tx_statusP.tx_status == MAC_TX_STATUS_UNSUCCESSFUL) && (tx_statusP.no_pdu)) {
-        msg ("[FRAME %5u][%s][RLC_AM][MOD %u/%u][RB %u] MAC_STATUS_INDICATION  TX STATUS UNSUCCESSFUL %d PDUs\n",rlc->module_id, rlc->rb_id,
-    ctxt_pP->frame, tx_statusP.no_pdu);
-    }*/
   }
 
-#endif
   return status_resp;
 }
 
 //-----------------------------------------------------------------------------
 void
 rlc_am_set_nb_bytes_requested_by_mac (
-  void * const            rlc_pP,
+  void *const            rlc_pP,
   const tb_size_t         tb_sizeP
-)
-{
-	((rlc_am_entity_t *) rlc_pP)->nb_bytes_requested_by_mac = tb_sizeP;
+) {
+  ((rlc_am_entity_t *) rlc_pP)->nb_bytes_requested_by_mac = tb_sizeP;
 }
 
 //-----------------------------------------------------------------------------
 struct mac_data_req
 rlc_am_mac_data_request (
-  const protocol_ctxt_t* const ctxt_pP,
-  void * const                 rlc_pP,
+  const protocol_ctxt_t *const ctxt_pP,
+  void *const                 rlc_pP,
   const eNB_flag_t        enb_flagP
-)
-{
+) {
   struct mac_data_req data_req;
   rlc_am_entity_t *l_rlc_p = (rlc_am_entity_t *) rlc_pP;
   unsigned int nb_bytes_requested_by_mac = ((rlc_am_entity_t *) rlc_pP)->nb_bytes_requested_by_mac;
-#if TRACE_RLC_AM_PDU || MESSAGE_CHART_GENERATOR
   rlc_am_pdu_info_t   pdu_info;
   rlc_am_pdu_sn_10_t *rlc_am_pdu_sn_10_p;
   mem_block_t        *tb_p;
@@ -679,9 +614,6 @@ rlc_am_mac_data_request (
   int                 num_nack;
   char                message_string[9000];
   size_t              message_string_size = 0;
-#   if ENABLE_ITTI
-  MessageDef         *msg_p;
-#   endif
   int                 octet_index, index;
   /* for no gcc warnings */
   (void)num_nack;
@@ -689,8 +621,6 @@ rlc_am_mac_data_request (
   (void)message_string_size;
   (void)octet_index;
   (void)index;
-#endif
-
   list_init (&data_req.data, NULL);
   rlc_am_get_pdus (ctxt_pP, l_rlc_p);
   list_add_list (&l_rlc_p->pdus_to_mac_layer, &data_req.data);
@@ -704,217 +634,197 @@ rlc_am_mac_data_request (
   }
 
   if (enb_flagP) {
-	  // redundant in UE MAC Tx processing and not used in eNB ...
-  data_req.buffer_occupancy_in_bytes   = rlc_am_get_buffer_occupancy_in_bytes(ctxt_pP, l_rlc_p);
+    // redundant in UE MAC Tx processing and not used in eNB ...
+    data_req.buffer_occupancy_in_bytes   = rlc_am_get_buffer_occupancy_in_bytes(ctxt_pP, l_rlc_p);
   }
-  data_req.rlc_info.rlc_protocol_state = l_rlc_p->protocol_state;
-
-#if TRACE_RLC_AM_PDU || MESSAGE_CHART_GENERATOR
 
-  if (data_req.data.nb_elements > 0) {
+  data_req.rlc_info.rlc_protocol_state = l_rlc_p->protocol_state;
 
+  if ( (MESSAGE_CHART_GENERATOR || LOG_DEBUGFLAG(DEBUG_RLC))&& data_req.data.nb_elements > 0) {
     tb_p = data_req.data.head;
 
     while (tb_p != NULL) {
-
-      rlc_am_pdu_sn_10_p = (rlc_am_pdu_sn_10_t*)((struct mac_tb_req *) (tb_p->data))->data_ptr;
+      rlc_am_pdu_sn_10_p = (rlc_am_pdu_sn_10_t *)((struct mac_tb_req *) (tb_p->data))->data_ptr;
       tb_size_in_bytes   = ((struct mac_tb_req *) (tb_p->data))->tb_size;
 
       if ((((struct mac_tb_req *) (tb_p->data))->data_ptr[0] & RLC_DC_MASK) == RLC_DC_DATA_PDU ) {
         if (rlc_am_get_data_pdu_infos(ctxt_pP,l_rlc_p,rlc_am_pdu_sn_10_p, tb_size_in_bytes, &pdu_info) >= 0) {
-#if MESSAGE_CHART_GENERATOR
-          message_string_size = 0;
-          message_string_size += sprintf(&message_string[message_string_size],
-                                         MSC_AS_TIME_FMT" "PROTOCOL_RLC_AM_MSC_FMT" DATA SN %u size %u RF %u P %u FI %u",
-                                         MSC_AS_TIME_ARGS(ctxt_pP),
-                                         PROTOCOL_RLC_AM_MSC_ARGS(ctxt_pP, l_rlc_p),
-                                         pdu_info.sn,
-                                         tb_size_in_bytes,
-                                         pdu_info.rf,
-                                         pdu_info.p,
-                                         pdu_info.fi);
-
-          if (pdu_info.rf) {
-            message_string_size += sprintf(&message_string[message_string_size], " LSF %u\n", pdu_info.lsf);
-            message_string_size += sprintf(&message_string[message_string_size], " SO %u\n", pdu_info.so);
-          }
+          if (MESSAGE_CHART_GENERATOR) {
+            message_string_size = 0;
+            message_string_size += sprintf(&message_string[message_string_size],
+                                           MSC_AS_TIME_FMT" "PROTOCOL_RLC_AM_MSC_FMT" DATA SN %u size %u RF %u P %u FI %u",
+                                           MSC_AS_TIME_ARGS(ctxt_pP),
+                                           PROTOCOL_RLC_AM_MSC_ARGS(ctxt_pP, l_rlc_p),
+                                           pdu_info.sn,
+                                           tb_size_in_bytes,
+                                           pdu_info.rf,
+                                           pdu_info.p,
+                                           pdu_info.fi);
+
+            if (pdu_info.rf) {
+              message_string_size += sprintf(&message_string[message_string_size], " LSF %u\n", pdu_info.lsf);
+              message_string_size += sprintf(&message_string[message_string_size], " SO %u\n", pdu_info.so);
+            }
 
-          if (pdu_info.e) {
-            message_string_size += sprintf(&message_string[message_string_size], "| HE:");
+            if (pdu_info.e) {
+              message_string_size += sprintf(&message_string[message_string_size], "| HE:");
 
-            for (index=0; index < pdu_info.num_li; index++) {
-              message_string_size += sprintf(&message_string[message_string_size], " LI %u", pdu_info.li_list[index]);
+              for (index=0; index < pdu_info.num_li; index++) {
+                message_string_size += sprintf(&message_string[message_string_size], " LI %u", pdu_info.li_list[index]);
+              }
             }
-          }
-
-          MSC_LOG_TX_MESSAGE(
-            (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
-            (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_UE:MSC_RLC_ENB,
-            (char*)rlc_am_pdu_sn_10_p,
-            tb_size_in_bytes,
-            message_string);
 
-#endif
-#   if ENABLE_ITTI
-          message_string_size = 0;
-          message_string_size += sprintf(&message_string[message_string_size], "Bearer      : %u\n", l_rlc_p->rb_id);
-          message_string_size += sprintf(&message_string[message_string_size], "PDU size    : %u\n", tb_size_in_bytes);
-          message_string_size += sprintf(&message_string[message_string_size], "Header size : %u\n", pdu_info.header_size);
-          message_string_size += sprintf(&message_string[message_string_size], "Payload size: %u\n", pdu_info.payload_size);
-
-          if (pdu_info.rf) {
-            message_string_size += sprintf(&message_string[message_string_size], "PDU type    : RLC AM DATA REQ: AMD PDU segment\n\n");
-          } else {
-            message_string_size += sprintf(&message_string[message_string_size], "PDU type    : RLC AM DATA REQ: AMD PDU\n\n");
+            MSC_LOG_TX_MESSAGE(
+              (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
+              (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_UE:MSC_RLC_ENB,
+              (char *)rlc_am_pdu_sn_10_p,
+              tb_size_in_bytes,
+              message_string);
           }
 
-          message_string_size += sprintf(&message_string[message_string_size], "Header      :\n");
-          message_string_size += sprintf(&message_string[message_string_size], "  D/C       : %u\n", pdu_info.d_c);
-          message_string_size += sprintf(&message_string[message_string_size], "  RF        : %u\n", pdu_info.rf);
-          message_string_size += sprintf(&message_string[message_string_size], "  P         : %u\n", pdu_info.p);
-          message_string_size += sprintf(&message_string[message_string_size], "  FI        : %u\n", pdu_info.fi);
-          message_string_size += sprintf(&message_string[message_string_size], "  E         : %u\n", pdu_info.e);
-          message_string_size += sprintf(&message_string[message_string_size], "  SN        : %u\n", pdu_info.sn);
-
-          if (pdu_info.rf) {
-            message_string_size += sprintf(&message_string[message_string_size], "  LSF       : %u\n", pdu_info.lsf);
-            message_string_size += sprintf(&message_string[message_string_size], "  SO        : %u\n", pdu_info.so);
-          }
+          if ( LOG_DEBUGFLAG(DEBUG_RLC)) {
+            message_string_size = 0;
+            message_string_size += sprintf(&message_string[message_string_size], "Bearer      : %u\n", l_rlc_p->rb_id);
+            message_string_size += sprintf(&message_string[message_string_size], "PDU size    : %u\n", tb_size_in_bytes);
+            message_string_size += sprintf(&message_string[message_string_size], "Header size : %u\n", pdu_info.header_size);
+            message_string_size += sprintf(&message_string[message_string_size], "Payload size: %u\n", pdu_info.payload_size);
 
-          if (pdu_info.e) {
-            message_string_size += sprintf(&message_string[message_string_size], "\nHeader extension  : \n");
+            if (pdu_info.rf) {
+              message_string_size += sprintf(&message_string[message_string_size], "PDU type    : RLC AM DATA REQ: AMD PDU segment\n\n");
+            } else {
+              message_string_size += sprintf(&message_string[message_string_size], "PDU type    : RLC AM DATA REQ: AMD PDU\n\n");
+            }
 
-            for (index=0; index < pdu_info.num_li; index++) {
-              message_string_size += sprintf(&message_string[message_string_size], "  LI        : %u\n", pdu_info.li_list[index]);
+            message_string_size += sprintf(&message_string[message_string_size], "Header      :\n");
+            message_string_size += sprintf(&message_string[message_string_size], "  D/C       : %u\n", pdu_info.d_c);
+            message_string_size += sprintf(&message_string[message_string_size], "  RF        : %u\n", pdu_info.rf);
+            message_string_size += sprintf(&message_string[message_string_size], "  P         : %u\n", pdu_info.p);
+            message_string_size += sprintf(&message_string[message_string_size], "  FI        : %u\n", pdu_info.fi);
+            message_string_size += sprintf(&message_string[message_string_size], "  E         : %u\n", pdu_info.e);
+            message_string_size += sprintf(&message_string[message_string_size], "  SN        : %u\n", pdu_info.sn);
+
+            if (pdu_info.rf) {
+              message_string_size += sprintf(&message_string[message_string_size], "  LSF       : %u\n", pdu_info.lsf);
+              message_string_size += sprintf(&message_string[message_string_size], "  SO        : %u\n", pdu_info.so);
             }
-          }
 
-          message_string_size += sprintf(&message_string[message_string_size], "\nPayload  : \n");
-          message_string_size += sprintf(&message_string[message_string_size], "------+-------------------------------------------------|\n");
-          message_string_size += sprintf(&message_string[message_string_size], "      |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |\n");
-          message_string_size += sprintf(&message_string[message_string_size], "------+-------------------------------------------------|\n");
+            if (pdu_info.e) {
+              message_string_size += sprintf(&message_string[message_string_size], "\nHeader extension  : \n");
 
-          for (octet_index = 0; octet_index < pdu_info.payload_size; octet_index++) {
-            if ((octet_index % 16) == 0) {
-              if (octet_index != 0) {
-                message_string_size += sprintf(&message_string[message_string_size], " |\n");
+              for (index=0; index < pdu_info.num_li; index++) {
+                message_string_size += sprintf(&message_string[message_string_size], "  LI        : %u\n", pdu_info.li_list[index]);
               }
-
-              message_string_size += sprintf(&message_string[message_string_size], " %04d |", octet_index);
             }
 
-            /*
-             * Print every single octet in hexadecimal form
-             */
-            message_string_size += sprintf(&message_string[message_string_size], " %02x", pdu_info.payload[octet_index]);
-            /*
-             * Align newline and pipes according to the octets in groups of 2
-             */
-          }
+            message_string_size += sprintf(&message_string[message_string_size], "\nPayload  : \n");
+            message_string_size += sprintf(&message_string[message_string_size], "------+-------------------------------------------------|\n");
+            message_string_size += sprintf(&message_string[message_string_size], "      |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |\n");
+            message_string_size += sprintf(&message_string[message_string_size], "------+-------------------------------------------------|\n");
 
-          /*
-           * Append enough spaces and put final pipe
-           */
-          for (index = octet_index; index < 16; ++index) {
-            message_string_size += sprintf(&message_string[message_string_size], "   ");
-          }
+            for (octet_index = 0; octet_index < pdu_info.payload_size; octet_index++) {
+              if ((octet_index % 16) == 0) {
+                if (octet_index != 0) {
+                  message_string_size += sprintf(&message_string[message_string_size], " |\n");
+                }
 
-          message_string_size += sprintf(&message_string[message_string_size], " |\n");
+                message_string_size += sprintf(&message_string[message_string_size], " %04d |", octet_index);
+              }
 
-          msg_p = itti_alloc_new_message_sized (ctxt_pP->enb_flag > 0 ? TASK_RLC_ENB:TASK_RLC_UE , RLC_AM_DATA_PDU_REQ, message_string_size + sizeof (IttiMsgText));
-          msg_p->ittiMsg.rlc_am_data_pdu_req.size = message_string_size;
-          memcpy(&msg_p->ittiMsg.rlc_am_data_pdu_req.text, message_string, message_string_size);
+              /*
+               * Print every single octet in hexadecimal form
+               */
+              message_string_size += sprintf(&message_string[message_string_size], " %02x", pdu_info.payload[octet_index]);
+              /*
+               * Align newline and pipes according to the octets in groups of 2
+               */
+            }
 
-          itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
+            /*
+             * Append enough spaces and put final pipe
+             */
+            for (index = octet_index; index < 16; ++index) {
+              message_string_size += sprintf(&message_string[message_string_size], "   ");
+            }
 
-# else
-          rlc_am_display_data_pdu_infos(ctxt_pP, l_rlc_p, &pdu_info);
-# endif
+            LOG_UI(RLC,"%s\n",message_string);
+          } /* LOG_DEBUGFLAG(DEBUG_RLC) */
         }
       } else {
         if (rlc_am_get_control_pdu_infos(rlc_am_pdu_sn_10_p, &tb_size_in_bytes, &l_rlc_p->control_pdu_info) >= 0) {
           tb_size_in_bytes   = ((struct mac_tb_req *) (tb_p->data))->tb_size; //tb_size_in_bytes modified by rlc_am_get_control_pdu_infos!
-#if MESSAGE_CHART_GENERATOR
-          message_string_size = 0;
-          message_string_size += sprintf(&message_string[message_string_size],
-                                         MSC_AS_TIME_FMT" "PROTOCOL_RLC_AM_MSC_FMT" STATUS ACK_SN %u",
-                                         MSC_AS_TIME_ARGS(ctxt_pP),
-                                         PROTOCOL_RLC_AM_MSC_ARGS(ctxt_pP, l_rlc_p),
-                                         l_rlc_p->control_pdu_info.ack_sn);
-
-          for (num_nack = 0; num_nack < l_rlc_p->control_pdu_info.num_nack; num_nack++) {
-            if (l_rlc_p->control_pdu_info.nack_list[num_nack].e2) {
-              message_string_size += sprintf(&message_string[message_string_size], "  NACK SN %u SO START %u SO END %u",
-            		  l_rlc_p->control_pdu_info.nack_list[num_nack].nack_sn,
-                                             l_rlc_p->control_pdu_info.nack_list[num_nack].so_start,
-                                             l_rlc_p->control_pdu_info.nack_list[num_nack].so_end);
 
-            } else {
-              message_string_size += sprintf(&message_string[message_string_size], "  NACK SN %u",
-            		  l_rlc_p->control_pdu_info.nack_list[num_nack].nack_sn);
+          if (MESSAGE_CHART_GENERATOR ) {
+            message_string_size = 0;
+            message_string_size += sprintf(&message_string[message_string_size],
+                                           MSC_AS_TIME_FMT" "PROTOCOL_RLC_AM_MSC_FMT" STATUS ACK_SN %u",
+                                           MSC_AS_TIME_ARGS(ctxt_pP),
+                                           PROTOCOL_RLC_AM_MSC_ARGS(ctxt_pP, l_rlc_p),
+                                           l_rlc_p->control_pdu_info.ack_sn);
+
+            for (num_nack = 0; num_nack < l_rlc_p->control_pdu_info.num_nack; num_nack++) {
+              if (l_rlc_p->control_pdu_info.nack_list[num_nack].e2) {
+                message_string_size += sprintf(&message_string[message_string_size], "  NACK SN %u SO START %u SO END %u",
+                                               l_rlc_p->control_pdu_info.nack_list[num_nack].nack_sn,
+                                               l_rlc_p->control_pdu_info.nack_list[num_nack].so_start,
+                                               l_rlc_p->control_pdu_info.nack_list[num_nack].so_end);
+              } else {
+                message_string_size += sprintf(&message_string[message_string_size], "  NACK SN %u",
+                                               l_rlc_p->control_pdu_info.nack_list[num_nack].nack_sn);
+              }
             }
-          }
-
-          MSC_LOG_TX_MESSAGE(
-            (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
-            (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_UE:MSC_RLC_ENB,
-            (char*)rlc_am_pdu_sn_10_p,
-            tb_size_in_bytes,
-            message_string);
 
-#endif
-#   if ENABLE_ITTI
-          message_string_size = 0;
-          message_string_size += sprintf(&message_string[message_string_size], "Bearer      : %u\n", l_rlc_p->rb_id);
-          message_string_size += sprintf(&message_string[message_string_size], "PDU size    : %u\n", tb_size_in_bytes);
-          message_string_size += sprintf(&message_string[message_string_size], "PDU type    : RLC AM DATA REQ: STATUS PDU\n\n");
-          message_string_size += sprintf(&message_string[message_string_size], "Header      :\n");
-          message_string_size += sprintf(&message_string[message_string_size], "  D/C       : %u\n", l_rlc_p->control_pdu_info.d_c);
-          message_string_size += sprintf(&message_string[message_string_size], "  CPT       : %u\n", l_rlc_p->control_pdu_info.cpt);
-          message_string_size += sprintf(&message_string[message_string_size], "  ACK_SN    : %u\n", l_rlc_p->control_pdu_info.ack_sn);
-          message_string_size += sprintf(&message_string[message_string_size], "  E1        : %u\n", l_rlc_p->control_pdu_info.e1);
-
-          for (num_nack = 0; num_nack < l_rlc_p->control_pdu_info.num_nack; num_nack++) {
-            if (l_rlc_p->control_pdu_info.nack_list[num_nack].e2) {
-              message_string_size += sprintf(&message_string[message_string_size], "  NACK SN %04d SO START %05d SO END %05d",
-                                             l_rlc_p->control_pdu_info.nack_list[num_nack].nack_sn,
-                                             l_rlc_p->control_pdu_info.nack_list[num_nack].so_start,
-                                             l_rlc_p->control_pdu_info.nack_list[num_nack].so_end);
-            } else {
-              message_string_size += sprintf(&message_string[message_string_size], "  NACK SN %04d",  l_rlc_p->control_pdu_info.nack_list[num_nack].nack_sn);
-            }
+            MSC_LOG_TX_MESSAGE(
+              (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
+              (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_UE:MSC_RLC_ENB,
+              (char *)rlc_am_pdu_sn_10_p,
+              tb_size_in_bytes,
+              message_string);
           }
 
-          msg_p = itti_alloc_new_message_sized (ctxt_pP->enb_flag > 0 ? TASK_RLC_ENB:TASK_RLC_UE , RLC_AM_STATUS_PDU_REQ, message_string_size + sizeof (IttiMsgText));
-          msg_p->ittiMsg.rlc_am_status_pdu_req.size = message_string_size;
-          memcpy(&msg_p->ittiMsg.rlc_am_status_pdu_req.text, message_string, message_string_size);
-
-          itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
+          if ( LOG_DEBUGFLAG(DEBUG_RLC)) {
+            message_string_size = 0;
+            message_string_size += sprintf(&message_string[message_string_size], "Bearer      : %u\n", l_rlc_p->rb_id);
+            message_string_size += sprintf(&message_string[message_string_size], "PDU size    : %u\n", tb_size_in_bytes);
+            message_string_size += sprintf(&message_string[message_string_size], "PDU type    : RLC AM DATA REQ: STATUS PDU\n\n");
+            message_string_size += sprintf(&message_string[message_string_size], "Header      :\n");
+            message_string_size += sprintf(&message_string[message_string_size], "  D/C       : %u\n", l_rlc_p->control_pdu_info.d_c);
+            message_string_size += sprintf(&message_string[message_string_size], "  CPT       : %u\n", l_rlc_p->control_pdu_info.cpt);
+            message_string_size += sprintf(&message_string[message_string_size], "  ACK_SN    : %u\n", l_rlc_p->control_pdu_info.ack_sn);
+            message_string_size += sprintf(&message_string[message_string_size], "  E1        : %u\n", l_rlc_p->control_pdu_info.e1);
+
+            for (num_nack = 0; num_nack < l_rlc_p->control_pdu_info.num_nack; num_nack++) {
+              if (l_rlc_p->control_pdu_info.nack_list[num_nack].e2) {
+                message_string_size += sprintf(&message_string[message_string_size], "  NACK SN %04d SO START %05d SO END %05d",
+                                               l_rlc_p->control_pdu_info.nack_list[num_nack].nack_sn,
+                                               l_rlc_p->control_pdu_info.nack_list[num_nack].so_start,
+                                               l_rlc_p->control_pdu_info.nack_list[num_nack].so_end);
+              } else {
+                message_string_size += sprintf(&message_string[message_string_size], "  NACK SN %04d",  l_rlc_p->control_pdu_info.nack_list[num_nack].nack_sn);
+              }
+            }
 
-#   endif
+            LOG_UI(RLC,"%s\n",message_string);
+          } /* LOG_DEBUGFLAG(DEBUG_RLC) */
         }
       }
 
       tb_p = tb_p->next;
-    }
-  }
+    } /* while */
+  } /* MESSAGE_CHART_GENERATOR && data_req.data.nb_elements > 0 */
 
-#endif
   return data_req;
 }
 //-----------------------------------------------------------------------------
 void
 rlc_am_mac_data_indication (
-  const protocol_ctxt_t* const ctxt_pP,
-  void * const                 rlc_pP,
+  const protocol_ctxt_t *const ctxt_pP,
+  void *const                 rlc_pP,
   struct mac_data_ind          data_indP
-)
-{
-  rlc_am_entity_t*           l_rlc_p = (rlc_am_entity_t*) rlc_pP;
+) {
+  rlc_am_entity_t           *l_rlc_p = (rlc_am_entity_t *) rlc_pP;
   /*rlc_am_control_pdu_info_t control_pdu_info;
   int                       num_li;
   int16_t                     tb_size;*/
-#if TRACE_RLC_AM_PDU || MESSAGE_CHART_GENERATOR
   rlc_am_pdu_info_t   pdu_info;
   rlc_am_pdu_sn_10_t *rlc_am_pdu_sn_10_p;
   mem_block_t        *tb_p;
@@ -922,9 +832,6 @@ rlc_am_mac_data_indication (
   int                 num_nack;
   char                message_string[7000];
   size_t              message_string_size = 0;
-#   if ENABLE_ITTI
-  MessageDef         *msg_p;
-#   endif
   int                 octet_index, index;
   /* for no gcc warnings */
   (void)num_nack;
@@ -932,243 +839,209 @@ rlc_am_mac_data_indication (
   (void)message_string_size;
   (void)octet_index;
   (void)index;
-#endif
-
   (void)l_rlc_p; /* avoid gcc warning "unused variable" */
 
-#if TRACE_RLC_AM_PDU || MESSAGE_CHART_GENERATOR
-
-  if (data_indP.data.nb_elements > 0) {
-
-    tb_p = data_indP.data.head;
-
-    while (tb_p != NULL) {
-
-      rlc_am_pdu_sn_10_p = (rlc_am_pdu_sn_10_t*)((struct mac_tb_ind *) (tb_p->data))->data_ptr;
-      tb_size_in_bytes   = ((struct mac_tb_ind *) (tb_p->data))->size;
-      LOG_I(RLC, "In rlc_am_mac_indication: size %d\n",tb_size_in_bytes);
+  if ( LOG_DEBUGFLAG(DEBUG_RLC) || MESSAGE_CHART_GENERATOR ) {
+    if (data_indP.data.nb_elements > 0) {
+      tb_p = data_indP.data.head;
+
+      while (tb_p != NULL) {
+        rlc_am_pdu_sn_10_p = (rlc_am_pdu_sn_10_t *)((struct mac_tb_ind *) (tb_p->data))->data_ptr;
+        tb_size_in_bytes   = ((struct mac_tb_ind *) (tb_p->data))->size;
+
+        if ((((struct mac_tb_ind *) (tb_p->data))->data_ptr[0] & RLC_DC_MASK) == RLC_DC_DATA_PDU ) {
+          if (rlc_am_get_data_pdu_infos(ctxt_pP,l_rlc_p,rlc_am_pdu_sn_10_p, tb_size_in_bytes, &pdu_info) >= 0) {
+            if (MESSAGE_CHART_GENERATOR) {
+              message_string_size = 0;
+              message_string_size += sprintf(&message_string[message_string_size],
+                                             MSC_AS_TIME_FMT" "PROTOCOL_RLC_AM_MSC_FMT" DATA SN %u size %u RF %u P %u FI %u",
+                                             MSC_AS_TIME_ARGS(ctxt_pP),
+                                             PROTOCOL_RLC_AM_MSC_ARGS(ctxt_pP, l_rlc_p),
+                                             pdu_info.sn,
+                                             tb_size_in_bytes,
+                                             pdu_info.rf,
+                                             pdu_info.p,
+                                             pdu_info.fi);
+
+              if (pdu_info.rf) {
+                message_string_size += sprintf(&message_string[message_string_size], " LSF %u\n", pdu_info.lsf);
+                message_string_size += sprintf(&message_string[message_string_size], " SO %u\n", pdu_info.so);
+              }
 
-      if ((((struct mac_tb_ind *) (tb_p->data))->data_ptr[0] & RLC_DC_MASK) == RLC_DC_DATA_PDU ) {
-        if (rlc_am_get_data_pdu_infos(ctxt_pP,l_rlc_p,rlc_am_pdu_sn_10_p, tb_size_in_bytes, &pdu_info) >= 0) {
-#if MESSAGE_CHART_GENERATOR
-          message_string_size = 0;
-          message_string_size += sprintf(&message_string[message_string_size],
-                                         MSC_AS_TIME_FMT" "PROTOCOL_RLC_AM_MSC_FMT" DATA SN %u size %u RF %u P %u FI %u",
-                                         MSC_AS_TIME_ARGS(ctxt_pP),
-                                         PROTOCOL_RLC_AM_MSC_ARGS(ctxt_pP, l_rlc_p),
-                                         pdu_info.sn,
-                                         tb_size_in_bytes,
-                                         pdu_info.rf,
-                                         pdu_info.p,
-                                         pdu_info.fi);
-
-          if (pdu_info.rf) {
-            message_string_size += sprintf(&message_string[message_string_size], " LSF %u\n", pdu_info.lsf);
-            message_string_size += sprintf(&message_string[message_string_size], " SO %u\n", pdu_info.so);
-          }
+              if (pdu_info.e) {
+                message_string_size += sprintf(&message_string[message_string_size], "| HE:");
 
-          if (pdu_info.e) {
-            message_string_size += sprintf(&message_string[message_string_size], "| HE:");
+                for (index=0; index < pdu_info.num_li; index++) {
+                  message_string_size += sprintf(&message_string[message_string_size], " LI %u", pdu_info.li_list[index]);
+                }
+              }
 
-            for (index=0; index < pdu_info.num_li; index++) {
-              message_string_size += sprintf(&message_string[message_string_size], " LI %u", pdu_info.li_list[index]);
+              MSC_LOG_RX_MESSAGE(
+                (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
+                (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_UE:MSC_RLC_ENB,
+                (char *)rlc_am_pdu_sn_10_p,
+                tb_size_in_bytes,
+                message_string);
             }
-          }
 
-          MSC_LOG_RX_MESSAGE(
-            (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
-            (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_UE:MSC_RLC_ENB,
-            (char*)rlc_am_pdu_sn_10_p,
-            tb_size_in_bytes,
-            message_string);
+            if ( LOG_DEBUGFLAG(DEBUG_RLC)) {
+              message_string_size += sprintf(&message_string[message_string_size], "Bearer	: %u\n", l_rlc_p->rb_id);
+              message_string_size += sprintf(&message_string[message_string_size], "PDU size	: %u\n", tb_size_in_bytes);
+              message_string_size += sprintf(&message_string[message_string_size], "Header size : %u\n", pdu_info.header_size);
+              message_string_size += sprintf(&message_string[message_string_size], "Payload size: %u\n", pdu_info.payload_size);
 
-#endif
+              if (pdu_info.rf) {
+                message_string_size += sprintf(&message_string[message_string_size], "PDU type    : RLC AM DATA IND: AMD PDU segment\n\n");
+              } else {
+                message_string_size += sprintf(&message_string[message_string_size], "PDU type    : RLC AM DATA IND: AMD PDU\n\n");
+              }
 
-#   if ENABLE_ITTI && TRACE_RLC_AM_PDU
-          message_string_size += sprintf(&message_string[message_string_size], "Bearer      : %u\n", l_rlc_p->rb_id);
-          message_string_size += sprintf(&message_string[message_string_size], "PDU size    : %u\n", tb_size_in_bytes);
-          message_string_size += sprintf(&message_string[message_string_size], "Header size : %u\n", pdu_info.header_size);
-          message_string_size += sprintf(&message_string[message_string_size], "Payload size: %u\n", pdu_info.payload_size);
+              message_string_size += sprintf(&message_string[message_string_size], "Header      :\n");
+              message_string_size += sprintf(&message_string[message_string_size], "  D/C       : %u\n", pdu_info.d_c);
+              message_string_size += sprintf(&message_string[message_string_size], "  RF        : %u\n", pdu_info.rf);
+              message_string_size += sprintf(&message_string[message_string_size], "  P         : %u\n", pdu_info.p);
+              message_string_size += sprintf(&message_string[message_string_size], "  FI        : %u\n", pdu_info.fi);
+              message_string_size += sprintf(&message_string[message_string_size], "  E         : %u\n", pdu_info.e);
+              message_string_size += sprintf(&message_string[message_string_size], "  SN        : %u\n", pdu_info.sn);
+
+              if (pdu_info.rf) {
+                message_string_size += sprintf(&message_string[message_string_size], "  LSF       : %u\n", pdu_info.lsf);
+                message_string_size += sprintf(&message_string[message_string_size], "  SO        : %u\n", pdu_info.so);
+              }
 
-          if (pdu_info.rf) {
-            message_string_size += sprintf(&message_string[message_string_size], "PDU type    : RLC AM DATA IND: AMD PDU segment\n\n");
-          } else {
-            message_string_size += sprintf(&message_string[message_string_size], "PDU type    : RLC AM DATA IND: AMD PDU\n\n");
-          }
+              if (pdu_info.e) {
+                message_string_size += sprintf(&message_string[message_string_size], "\nHeader extension  : \n");
 
-          message_string_size += sprintf(&message_string[message_string_size], "Header      :\n");
-          message_string_size += sprintf(&message_string[message_string_size], "  D/C       : %u\n", pdu_info.d_c);
-          message_string_size += sprintf(&message_string[message_string_size], "  RF        : %u\n", pdu_info.rf);
-          message_string_size += sprintf(&message_string[message_string_size], "  P         : %u\n", pdu_info.p);
-          message_string_size += sprintf(&message_string[message_string_size], "  FI        : %u\n", pdu_info.fi);
-          message_string_size += sprintf(&message_string[message_string_size], "  E         : %u\n", pdu_info.e);
-          message_string_size += sprintf(&message_string[message_string_size], "  SN        : %u\n", pdu_info.sn);
-
-          if (pdu_info.rf) {
-            message_string_size += sprintf(&message_string[message_string_size], "  LSF       : %u\n", pdu_info.lsf);
-            message_string_size += sprintf(&message_string[message_string_size], "  SO        : %u\n", pdu_info.so);
-          }
+                for (index=0; index < pdu_info.num_li; index++) {
+                  message_string_size += sprintf(&message_string[message_string_size], "  LI        : %u\n", pdu_info.li_list[index]);
+                }
+              }
 
-          if (pdu_info.e) {
-            message_string_size += sprintf(&message_string[message_string_size], "\nHeader extension  : \n");
+              message_string_size += sprintf(&message_string[message_string_size], "\nPayload  : \n");
+              message_string_size += sprintf(&message_string[message_string_size], "------+-------------------------------------------------|\n");
+              message_string_size += sprintf(&message_string[message_string_size], "      |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |\n");
+              message_string_size += sprintf(&message_string[message_string_size], "------+-------------------------------------------------|\n");
 
-            for (index=0; index < pdu_info.num_li; index++) {
-              message_string_size += sprintf(&message_string[message_string_size], "  LI        : %u\n", pdu_info.li_list[index]);
-            }
-          }
+              for (octet_index = 0; octet_index < pdu_info.payload_size; octet_index++) {
+                if ((octet_index % 16) == 0) {
+                  if (octet_index != 0) {
+                    message_string_size += sprintf(&message_string[message_string_size], " |\n");
+                  }
 
-          message_string_size += sprintf(&message_string[message_string_size], "\nPayload  : \n");
-          message_string_size += sprintf(&message_string[message_string_size], "------+-------------------------------------------------|\n");
-          message_string_size += sprintf(&message_string[message_string_size], "      |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |\n");
-          message_string_size += sprintf(&message_string[message_string_size], "------+-------------------------------------------------|\n");
+                  message_string_size += sprintf(&message_string[message_string_size], " %04d |", octet_index);
+                }
 
-          for (octet_index = 0; octet_index < pdu_info.payload_size; octet_index++) {
-            if ((octet_index % 16) == 0) {
-              if (octet_index != 0) {
-                message_string_size += sprintf(&message_string[message_string_size], " |\n");
+                /*
+                 * Print every single octet in hexadecimal form
+                 */
+                message_string_size += sprintf(&message_string[message_string_size], " %02x", pdu_info.payload[octet_index]);
+                /*
+                 * Align newline and pipes according to the octets in groups of 2
+                 */
               }
 
-              message_string_size += sprintf(&message_string[message_string_size], " %04d |", octet_index);
-            }
-
-            /*
-             * Print every single octet in hexadecimal form
-             */
-            message_string_size += sprintf(&message_string[message_string_size], " %02x", pdu_info.payload[octet_index]);
-            /*
-             * Align newline and pipes according to the octets in groups of 2
-             */
-          }
+              /*
+               * Append enough spaces and put final pipe
+               */
+              for (index = octet_index; index < 16; ++index) {
+                message_string_size += sprintf(&message_string[message_string_size], "   ");
+              }
 
-          /*
-           * Append enough spaces and put final pipe
-           */
-          for (index = octet_index; index < 16; ++index) {
-            message_string_size += sprintf(&message_string[message_string_size], "   ");
+              LOG_UI(RLC,"%s\n",message_string);
+            } /* LOG_DEBUGFLAG */
           }
+        } else {
+          if (rlc_am_get_control_pdu_infos(rlc_am_pdu_sn_10_p, &tb_size_in_bytes, &l_rlc_p->control_pdu_info) >= 0) {
+            if (MESSAGE_CHART_GENERATOR) {
+              message_string_size = 0;
+              message_string_size += sprintf(&message_string[message_string_size],
+                                             MSC_AS_TIME_FMT" "PROTOCOL_RLC_AM_MSC_FMT" STATUS size ACK_SN %u",
+                                             MSC_AS_TIME_ARGS(ctxt_pP),
+                                             PROTOCOL_RLC_AM_MSC_ARGS(ctxt_pP, l_rlc_p),
+                                             l_rlc_p->control_pdu_info.ack_sn);
+
+              for (num_nack = 0; num_nack < l_rlc_p->control_pdu_info.num_nack; num_nack++) {
+                if (l_rlc_p->control_pdu_info.nack_list[num_nack].e2) {
+                  message_string_size += sprintf(&message_string[message_string_size], "  NACK SN %u SO START %u SO END %u",
+                                                 l_rlc_p->control_pdu_info.nack_list[num_nack].nack_sn,
+                                                 l_rlc_p->control_pdu_info.nack_list[num_nack].so_start,
+                                                 l_rlc_p->control_pdu_info.nack_list[num_nack].so_end);
+                } else {
+                  message_string_size += sprintf(&message_string[message_string_size], "  NACK SN %u",
+                                                 l_rlc_p->control_pdu_info.nack_list[num_nack].nack_sn);
+                }
+              }
 
-          message_string_size += sprintf(&message_string[message_string_size], " |\n");
-
-          msg_p = itti_alloc_new_message_sized (ctxt_pP->enb_flag > 0 ? TASK_RLC_ENB:TASK_RLC_UE , RLC_AM_DATA_PDU_IND, message_string_size + sizeof (IttiMsgText));
-          msg_p->ittiMsg.rlc_am_data_pdu_ind.size = message_string_size;
-          memcpy(&msg_p->ittiMsg.rlc_am_data_pdu_ind.text, message_string, message_string_size);
-
-          itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
-
-# else
-          rlc_am_display_data_pdu_infos(ctxt_pP, l_rlc_p, &pdu_info);
-# endif
-        }
-      } else {
-        if (rlc_am_get_control_pdu_infos(rlc_am_pdu_sn_10_p, &tb_size_in_bytes, &l_rlc_p->control_pdu_info) >= 0) {
-#if MESSAGE_CHART_GENERATOR
-          message_string_size = 0;
-          message_string_size += sprintf(&message_string[message_string_size],
-                                         MSC_AS_TIME_FMT" "PROTOCOL_RLC_AM_MSC_FMT" STATUS size ACK_SN %u",
-                                         MSC_AS_TIME_ARGS(ctxt_pP),
-                                         PROTOCOL_RLC_AM_MSC_ARGS(ctxt_pP, l_rlc_p),
-                                         l_rlc_p->control_pdu_info.ack_sn);
-
-          for (num_nack = 0; num_nack < l_rlc_p->control_pdu_info.num_nack; num_nack++) {
-            if (l_rlc_p->control_pdu_info.nack_list[num_nack].e2) {
-              message_string_size += sprintf(&message_string[message_string_size], "  NACK SN %u SO START %u SO END %u",
-                                             l_rlc_p->control_pdu_info.nack_list[num_nack].nack_sn,
-                                             l_rlc_p->control_pdu_info.nack_list[num_nack].so_start,
-                                             l_rlc_p->control_pdu_info.nack_list[num_nack].so_end);
-
-            } else {
-              message_string_size += sprintf(&message_string[message_string_size], "  NACK SN %u",
-                                             l_rlc_p->control_pdu_info.nack_list[num_nack].nack_sn);
+              MSC_LOG_RX_MESSAGE(
+                (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
+                (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_UE:MSC_RLC_ENB,
+                (char *)rlc_am_pdu_sn_10_p,
+                tb_size_in_bytes,
+                message_string);
             }
-          }
-
-          MSC_LOG_RX_MESSAGE(
-            (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
-            (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_UE:MSC_RLC_ENB,
-            (char*)rlc_am_pdu_sn_10_p,
-            tb_size_in_bytes,
-            message_string);
 
-#endif
+            if ( LOG_DEBUGFLAG(DEBUG_RLC)) {
+              message_string_size = 0;
+              message_string_size += sprintf(&message_string[message_string_size], "Bearer      : %u\n", l_rlc_p->rb_id);
+              message_string_size += sprintf(&message_string[message_string_size], "PDU size    : %u\n", ((struct mac_tb_ind *) (tb_p->data))->size);
+              message_string_size += sprintf(&message_string[message_string_size], "PDU type    : RLC AM DATA IND: STATUS PDU\n\n");
+              message_string_size += sprintf(&message_string[message_string_size], "Header      :\n");
+              message_string_size += sprintf(&message_string[message_string_size], "  D/C       : %u\n", l_rlc_p->control_pdu_info.d_c);
+              message_string_size += sprintf(&message_string[message_string_size], "  CPT       : %u\n", l_rlc_p->control_pdu_info.cpt);
+              message_string_size += sprintf(&message_string[message_string_size], "  ACK_SN    : %u\n", l_rlc_p->control_pdu_info.ack_sn);
+              message_string_size += sprintf(&message_string[message_string_size], "  E1        : %u\n", l_rlc_p->control_pdu_info.e1);
+
+              for (num_nack = 0; num_nack < l_rlc_p->control_pdu_info.num_nack; num_nack++) {
+                if (l_rlc_p->control_pdu_info.nack_list[num_nack].e2) {
+                  message_string_size += sprintf(&message_string[message_string_size], "  NACK SN %04d SO START %05d SO END %05d",
+                                                 l_rlc_p->control_pdu_info.nack_list[num_nack].nack_sn,
+                                                 l_rlc_p->control_pdu_info.nack_list[num_nack].so_start,
+                                                 l_rlc_p->control_pdu_info.nack_list[num_nack].so_end);
+                } else {
+                  message_string_size += sprintf(&message_string[message_string_size], "  NACK SN %04d",  l_rlc_p->control_pdu_info.nack_list[num_nack].nack_sn);
+                }
+              }
 
-#   if ENABLE_ITTI && TRACE_RLC_AM_PDU
-          message_string_size = 0;
-          message_string_size += sprintf(&message_string[message_string_size], "Bearer      : %u\n", l_rlc_p->rb_id);
-          message_string_size += sprintf(&message_string[message_string_size], "PDU size    : %u\n", ((struct mac_tb_ind *) (tb_p->data))->size);
-          message_string_size += sprintf(&message_string[message_string_size], "PDU type    : RLC AM DATA IND: STATUS PDU\n\n");
-          message_string_size += sprintf(&message_string[message_string_size], "Header      :\n");
-          message_string_size += sprintf(&message_string[message_string_size], "  D/C       : %u\n", l_rlc_p->control_pdu_info.d_c);
-          message_string_size += sprintf(&message_string[message_string_size], "  CPT       : %u\n", l_rlc_p->control_pdu_info.cpt);
-          message_string_size += sprintf(&message_string[message_string_size], "  ACK_SN    : %u\n", l_rlc_p->control_pdu_info.ack_sn);
-          message_string_size += sprintf(&message_string[message_string_size], "  E1        : %u\n", l_rlc_p->control_pdu_info.e1);
-
-          for (num_nack = 0; num_nack < l_rlc_p->control_pdu_info.num_nack; num_nack++) {
-            if (l_rlc_p->control_pdu_info.nack_list[num_nack].e2) {
-              message_string_size += sprintf(&message_string[message_string_size], "  NACK SN %04d SO START %05d SO END %05d",
-                                             l_rlc_p->control_pdu_info.nack_list[num_nack].nack_sn,
-                                             l_rlc_p->control_pdu_info.nack_list[num_nack].so_start,
-                                             l_rlc_p->control_pdu_info.nack_list[num_nack].so_end);
-            } else {
-              message_string_size += sprintf(&message_string[message_string_size], "  NACK SN %04d",  l_rlc_p->control_pdu_info.nack_list[num_nack].nack_sn);
+              LOG_UI(RLC, "%s\n",message_string);
             }
           }
-
-          msg_p = itti_alloc_new_message_sized (ctxt_pP->enb_flag > 0 ? TASK_RLC_ENB:TASK_RLC_UE , RLC_AM_STATUS_PDU_IND, message_string_size + sizeof (IttiMsgText));
-          msg_p->ittiMsg.rlc_am_status_pdu_ind.size = message_string_size;
-          memcpy(&msg_p->ittiMsg.rlc_am_status_pdu_ind.text, message_string, message_string_size);
-
-          itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
-
-#   endif
         }
-      }
 
-      tb_p = tb_p->next;
+        tb_p = tb_p->next;
+      }
     }
-  }
+  } /* LOG_DEBUGFLAG(RLC) || MESSAGE_TRACE_GENERATOR) */
 
-#endif
   rlc_am_rx (ctxt_pP, rlc_pP, data_indP);
 }
 
 //-----------------------------------------------------------------------------
 void
 rlc_am_data_req (
-  const protocol_ctxt_t* const ctxt_pP,
-  void * const                rlc_pP,
-  mem_block_t * const         sdu_pP)
-{
+  const protocol_ctxt_t *const ctxt_pP,
+  void *const                rlc_pP,
+  mem_block_t *const         sdu_pP) {
   rlc_am_entity_t     *l_rlc_p = (rlc_am_entity_t *) rlc_pP;
   uint32_t             mui;
   uint16_t             data_offset;
   uint16_t             data_size;
-#if TRACE_RLC_AM_PDU
   char                 message_string[7000];
   size_t               message_string_size = 0;
-#if ENABLE_ITTI
-  MessageDef          *msg_p;
-#endif
   int                  octet_index, index;
-#endif
-
   RLC_AM_MUTEX_LOCK(&l_rlc_p->lock_input_sdus, ctxt_pP, l_rlc_p);
 
   if ((l_rlc_p->input_sdus[l_rlc_p->next_sdu_index].mem_block == NULL) &&
       (l_rlc_p->input_sdus[l_rlc_p->next_sdu_index].flags.segmented == 0) &&
       (((l_rlc_p->next_sdu_index + 1) % RLC_AM_SDU_CONTROL_BUFFER_SIZE) != l_rlc_p->current_sdu_index)) {
-
-
     memset(&l_rlc_p->input_sdus[l_rlc_p->next_sdu_index], 0, sizeof(rlc_am_tx_sdu_management_t));
     l_rlc_p->input_sdus[l_rlc_p->next_sdu_index].mem_block = sdu_pP;
-
     mui         = ((struct rlc_am_data_req *) (sdu_pP->data))->mui;
     data_offset = ((struct rlc_am_data_req *) (sdu_pP->data))->data_offset;
     data_size   = ((struct rlc_am_data_req *) (sdu_pP->data))->data_size;
-
     MSC_LOG_RX_MESSAGE(
       (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
       (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
-      (const char*)(&sdu_pP->data[data_offset]),
+      (const char *)(&sdu_pP->data[data_offset]),
       data_size,
       MSC_AS_TIME_FMT" "PROTOCOL_RLC_AM_MSC_FMT" DATA-REQ size %u mui %u",
       MSC_AS_TIME_ARGS(ctxt_pP),
@@ -1176,68 +1049,53 @@ rlc_am_data_req (
       data_size,
       mui);
 
+    if (LOG_DEBUGFLAG(DEBUG_RLC)) {
+      message_string_size += sprintf(&message_string[message_string_size], "Bearer      : %u\n", l_rlc_p->rb_id);
+      message_string_size += sprintf(&message_string[message_string_size], "SDU size    : %u\n", data_size);
+      message_string_size += sprintf(&message_string[message_string_size], "MUI         : %u\n", mui);
+      message_string_size += sprintf(&message_string[message_string_size], "CONF        : %u\n", ((struct rlc_am_data_req *) (sdu_pP->data))->conf);
+      message_string_size += sprintf(&message_string[message_string_size], "\nPayload  : \n");
+      message_string_size += sprintf(&message_string[message_string_size], "------+-------------------------------------------------|\n");
+      message_string_size += sprintf(&message_string[message_string_size], "      |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |\n");
+      message_string_size += sprintf(&message_string[message_string_size], "------+-------------------------------------------------|\n");
+
+      for (octet_index = 0; octet_index < data_size; octet_index++) {
+        if ((octet_index % 16) == 0) {
+          if (octet_index != 0) {
+            message_string_size += sprintf(&message_string[message_string_size], " |\n");
+          }
 
-#if TRACE_RLC_AM_PDU
-    message_string_size += sprintf(&message_string[message_string_size], "Bearer      : %u\n", l_rlc_p->rb_id);
-    message_string_size += sprintf(&message_string[message_string_size], "SDU size    : %u\n", data_size);
-    message_string_size += sprintf(&message_string[message_string_size], "MUI         : %u\n", mui);
-    message_string_size += sprintf(&message_string[message_string_size], "CONF        : %u\n", ((struct rlc_am_data_req *) (sdu_pP->data))->conf);
-
-    message_string_size += sprintf(&message_string[message_string_size], "\nPayload  : \n");
-    message_string_size += sprintf(&message_string[message_string_size], "------+-------------------------------------------------|\n");
-    message_string_size += sprintf(&message_string[message_string_size], "      |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |\n");
-    message_string_size += sprintf(&message_string[message_string_size], "------+-------------------------------------------------|\n");
-
-    for (octet_index = 0; octet_index < data_size; octet_index++) {
-      if ((octet_index % 16) == 0) {
-        if (octet_index != 0) {
-          message_string_size += sprintf(&message_string[message_string_size], " |\n");
+          message_string_size += sprintf(&message_string[message_string_size], " %04d |", octet_index);
         }
 
-        message_string_size += sprintf(&message_string[message_string_size], " %04d |", octet_index);
+        /*
+         * Print every single octet in hexadecimal form
+         */
+        message_string_size += sprintf(&message_string[message_string_size], " %02x", ((uint8_t *)(&sdu_pP->data[data_offset]))[octet_index]);
+        /*
+         * Align newline and pipes according to the octets in groups of 2
+         */
       }
 
       /*
-       * Print every single octet in hexadecimal form
+       * Append enough spaces and put final pipe
        */
-      message_string_size += sprintf(&message_string[message_string_size], " %02x", ((uint8_t*)(&sdu_pP->data[data_offset]))[octet_index]);
-      /*
-       * Align newline and pipes according to the octets in groups of 2
-       */
-    }
-
-    /*
-     * Append enough spaces and put final pipe
-     */
-    for (index = octet_index; index < 16; ++index) {
-      message_string_size += sprintf(&message_string[message_string_size], "   ");
-    }
-
-    message_string_size += sprintf(&message_string[message_string_size], " |\n");
-
-#   if ENABLE_ITTI
-    msg_p = itti_alloc_new_message_sized (ctxt_pP->enb_flag > 0 ? TASK_RLC_ENB:TASK_RLC_UE , RLC_AM_SDU_REQ, message_string_size + sizeof (IttiMsgText));
-    msg_p->ittiMsg.rlc_am_sdu_req.size = message_string_size;
-    memcpy(&msg_p->ittiMsg.rlc_am_sdu_req.text, message_string, message_string_size);
-
-    itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
+      for (index = octet_index; index < 16; ++index) {
+        message_string_size += sprintf(&message_string[message_string_size], "   ");
+      }
 
-#   else
-    LOG_T(RLC, "%s", message_string);
-#   endif
-#endif
+      message_string_size += sprintf(&message_string[message_string_size], " |\n");
+      LOG_UI(RLC, "%s\n", message_string);
+    } /* LOG_DEBUGFLAG(RLC) */
 
     l_rlc_p->stat_tx_pdcp_sdu   += 1;
     l_rlc_p->stat_tx_pdcp_bytes += data_size;
-
     l_rlc_p->input_sdus[l_rlc_p->next_sdu_index].mui      = mui;
     l_rlc_p->input_sdus[l_rlc_p->next_sdu_index].sdu_size = data_size;
-
     l_rlc_p->sdu_buffer_occupancy += data_size;
     l_rlc_p->nb_sdu += 1;
     l_rlc_p->nb_sdu_no_segmented += 1;
-
-    l_rlc_p->input_sdus[l_rlc_p->next_sdu_index].first_byte = (uint8_t*)(&sdu_pP->data[data_offset]);
+    l_rlc_p->input_sdus[l_rlc_p->next_sdu_index].first_byte = (uint8_t *)(&sdu_pP->data[data_offset]);
     l_rlc_p->input_sdus[l_rlc_p->next_sdu_index].sdu_remaining_size = l_rlc_p->input_sdus[l_rlc_p->next_sdu_index].sdu_size;
     l_rlc_p->input_sdus[l_rlc_p->next_sdu_index].sdu_segmented_size = 0;
     l_rlc_p->input_sdus[l_rlc_p->next_sdu_index].sdu_creation_time  = ctxt_pP->frame;
@@ -1251,43 +1109,44 @@ rlc_am_data_req (
     l_rlc_p->input_sdus[l_rlc_p->next_sdu_index].flags.no_new_sdu_segmented_in_last_pdu = 0;
     //l_rlc_p->input_sdus[l_rlc_p->next_sdu_index].li_index_for_discard = -1;
     l_rlc_p->next_sdu_index = (l_rlc_p->next_sdu_index + 1) % RLC_AM_SDU_CONTROL_BUFFER_SIZE;
-    if (l_rlc_p->channel_id <3)
-    {
-    LOG_I(RLC, PROTOCOL_RLC_AM_CTXT_FMT" RLC_AM_DATA_REQ size %d Bytes,  NB SDU %d current_sdu_index=%d next_sdu_index=%d conf %d mui %d vtA %d vtS %d\n",
-          PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,l_rlc_p),
-          data_size,
-          l_rlc_p->nb_sdu,
-          l_rlc_p->current_sdu_index,
-          l_rlc_p->next_sdu_index,
-          ((struct rlc_am_data_req *) (sdu_pP->data))->conf,
-          mui,
-		  l_rlc_p->vt_a,
-		  l_rlc_p->vt_s);
+
+    if (l_rlc_p->channel_id <3) {
+      LOG_I(RLC, PROTOCOL_RLC_AM_CTXT_FMT" RLC_AM_DATA_REQ size %d Bytes,  NB SDU %d current_sdu_index=%d next_sdu_index=%d conf %d mui %d vtA %d vtS %d\n",
+            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,l_rlc_p),
+            data_size,
+            l_rlc_p->nb_sdu,
+            l_rlc_p->current_sdu_index,
+            l_rlc_p->next_sdu_index,
+            ((struct rlc_am_data_req *) (sdu_pP->data))->conf,
+            mui,
+            l_rlc_p->vt_a,
+            l_rlc_p->vt_s);
     }
   } else {
-#if MESSAGE_CHART_GENERATOR
-    mui         = ((struct rlc_am_data_req*) (sdu_pP->data))->mui;
-    data_offset = ((struct rlc_am_data_req*) (sdu_pP->data))->data_offset;
-    data_size   = ((struct rlc_am_data_req*) (sdu_pP->data))->data_size;
-    MSC_LOG_RX_DISCARDED_MESSAGE(
-      (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
-      (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
-      (const char*)(&sdu_pP->data[data_offset]),
-      data_size,
-      MSC_AS_TIME_FMT" "PROTOCOL_RLC_AM_MSC_FMT" DATA-REQ size %u mui %u",
-      MSC_AS_TIME_ARGS(ctxt_pP),
-      PROTOCOL_RLC_AM_MSC_ARGS(ctxt_pP, l_rlc_p),
-      data_size,
-      mui);
-#endif
+    if( MESSAGE_CHART_GENERATOR) {
+      mui   = ((struct rlc_am_data_req *) (sdu_pP->data))->mui;
+      data_offset = ((struct rlc_am_data_req *) (sdu_pP->data))->data_offset;
+      data_size   = ((struct rlc_am_data_req *) (sdu_pP->data))->data_size;
+      MSC_LOG_RX_DISCARDED_MESSAGE(
+        (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
+        (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
+        (const char *)(&sdu_pP->data[data_offset]),
+        data_size,
+        MSC_AS_TIME_FMT" "PROTOCOL_RLC_AM_MSC_FMT" DATA-REQ size %u mui %u",
+        MSC_AS_TIME_ARGS(ctxt_pP),
+        PROTOCOL_RLC_AM_MSC_ARGS(ctxt_pP, l_rlc_p),
+        data_size,
+        mui);
+    }
+
     LOG_W(RLC, PROTOCOL_RLC_AM_CTXT_FMT" RLC_AM_DATA_REQ BUFFER FULL, NB SDU %d current_sdu_index=%d next_sdu_index=%d size_input_sdus_buffer=%d vtA=%d vtS=%d\n",
           PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,l_rlc_p),
           l_rlc_p->nb_sdu,
           l_rlc_p->current_sdu_index,
           l_rlc_p->next_sdu_index,
           RLC_AM_SDU_CONTROL_BUFFER_SIZE,
-		  l_rlc_p->vt_a,
-		  l_rlc_p->vt_s);
+          l_rlc_p->vt_a,
+          l_rlc_p->vt_s);
     LOG_W(RLC, "                                        input_sdus[].mem_block=%p next input_sdus[].flags.segmented=%d\n",
           l_rlc_p->input_sdus[l_rlc_p->next_sdu_index].mem_block, l_rlc_p->input_sdus[l_rlc_p->next_sdu_index].flags.segmented);
     l_rlc_p->stat_tx_pdcp_sdu_discarded   += 1;
diff --git a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am.h b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am.h
index 952082187e576ae3ae7fe7ecaf5bfa4f93002ee4..75213116a7d04deef939aa86d742249f57efa5e0 100644
--- a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am.h
+++ b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am.h
@@ -55,7 +55,7 @@
 #        include "rlc_am_rx_list.h"
 #        include "rlc_am_reassembly.h"
 #        include "rlc_am_init.h"
-#        include "RLC-Config.h"
+#        include "LTE_RLC-Config.h"
 #        include "assertions.h"
 //#        include "rlc_am_test.h"
 
@@ -138,7 +138,7 @@ config_req_rlc_am (
 void config_req_rlc_am_asn1 (
                 const protocol_ctxt_t* const ctxtP,
                 const srb_flag_t srb_flagP,
-                const struct RLC_Config__am * const config_amP,
+                const struct LTE_RLC_Config__am * const config_amP,
                 const rb_id_t rb_idP,
                 const logical_chan_id_t chan_idP);
 
diff --git a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_proto_extern.h b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_proto_extern.h
deleted file mode 100644
index 4690bba42e5b91f4721d727b38d41da928e0c55a..0000000000000000000000000000000000000000
--- a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_proto_extern.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * 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
- */
-
diff --git a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_reassembly.c b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_reassembly.c
index d2fe1d1bfd66ed0e7617e781e45cb1231af0e403..369c7fd0da56576168243e6c8de429a2f557e773 100644
--- a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_reassembly.c
+++ b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_reassembly.c
@@ -23,9 +23,7 @@
 #define RLC_AM_REASSEMBLY_C 1
 #include "platform_types.h"
 //-----------------------------------------------------------------------------
-#if ENABLE_ITTI
-# include "intertask_interface.h"
-#endif
+
 #include "assertions.h"
 #include "rlc.h"
 #include "rlc_am.h"
@@ -37,19 +35,17 @@
 //-----------------------------------------------------------------------------
 inline void
 rlc_am_clear_rx_sdu (
-  const protocol_ctxt_t* const ctxt_pP,
-  rlc_am_entity_t * const      rlc_pP)
-{
+  const protocol_ctxt_t *const ctxt_pP,
+  rlc_am_entity_t *const      rlc_pP) {
   rlc_pP->output_sdu_size_to_write = 0;
 }
 //-----------------------------------------------------------------------------
 void
 rlc_am_reassembly (
-  const protocol_ctxt_t* const ctxt_pP,
-  rlc_am_entity_t * const rlc_pP,
-  uint8_t * src_pP,
-  const int32_t lengthP)
-{
+  const protocol_ctxt_t *const ctxt_pP,
+  rlc_am_entity_t *const rlc_pP,
+  uint8_t *src_pP,
+  const int32_t lengthP) {
   LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PAYLOAD] reassembly()  %d bytes\n",
         PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
         lengthP);
@@ -57,6 +53,7 @@ rlc_am_reassembly (
   if (rlc_pP->output_sdu_in_construction == NULL) {
     rlc_pP->output_sdu_in_construction = get_free_mem_block (RLC_SDU_MAX_SIZE, __func__);
     rlc_pP->output_sdu_size_to_write = 0;
+
     //assert(rlc_pP->output_sdu_in_construction != NULL);
     if(rlc_pP->output_sdu_in_construction == NULL) {
       LOG_E(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PAYLOAD] output_sdu_in_construction is NULL\n",
@@ -66,7 +63,6 @@ rlc_am_reassembly (
   }
 
   if (rlc_pP->output_sdu_in_construction != NULL) {
-
     // check if no overflow in size
     if ((rlc_pP->output_sdu_size_to_write + lengthP) <= RLC_SDU_MAX_SIZE) {
       memcpy (&rlc_pP->output_sdu_in_construction->data[rlc_pP->output_sdu_size_to_write], src_pP, lengthP);
@@ -93,18 +89,8 @@ rlc_am_reassembly (
 //-----------------------------------------------------------------------------
 void
 rlc_am_send_sdu (
-  const protocol_ctxt_t* const ctxt_pP,
-  rlc_am_entity_t * const      rlc_pP)
-{
-#   if TRACE_RLC_AM_PDU
-  char                 message_string[7000];
-  size_t               message_string_size = 0;
-#if ENABLE_ITTI
-  MessageDef          *msg_p;
-#endif
-  int                  octet_index, index;
-#endif
-
+  const protocol_ctxt_t *const ctxt_pP,
+  rlc_am_entity_t *const      rlc_pP) {
   if ((rlc_pP->output_sdu_in_construction)) {
     LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[SEND_SDU] %d bytes sdu %p\n",
           PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
@@ -120,73 +106,62 @@ rlc_am_send_sdu (
                                    rlc_pP->output_sdu_size_to_write,
                                    rlc_pP->output_sdu_in_construction);
 #else
-#   if TRACE_RLC_AM_PDU
-      message_string_size += sprintf(&message_string[message_string_size], "Bearer      : %u\n", rlc_pP->rb_id);
-      message_string_size += sprintf(&message_string[message_string_size], "SDU size    : %u\n", rlc_pP->output_sdu_size_to_write);
-
-      message_string_size += sprintf(&message_string[message_string_size], "\nPayload  : \n");
-      message_string_size += sprintf(&message_string[message_string_size], "------+-------------------------------------------------|\n");
-      message_string_size += sprintf(&message_string[message_string_size], "      |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |\n");
-      message_string_size += sprintf(&message_string[message_string_size], "------+-------------------------------------------------|\n");
-
-      for (octet_index = 0; octet_index < rlc_pP->output_sdu_size_to_write; octet_index++) {
-        if ((octet_index % 16) == 0) {
-          if (octet_index != 0) {
-            message_string_size += sprintf(&message_string[message_string_size], " |\n");
+
+      if ( LOG_DEBUGFLAG(DEBUG_RLC)) {
+        char                 message_string[7000];
+        size_t               message_string_size = 0;
+        int                  octet_index, index;
+        message_string_size += sprintf(&message_string[message_string_size], "Bearer	  : %u\n", rlc_pP->rb_id);
+        message_string_size += sprintf(&message_string[message_string_size], "SDU size    : %u\n", rlc_pP->output_sdu_size_to_write);
+        message_string_size += sprintf(&message_string[message_string_size], "\nPayload  : \n");
+        message_string_size += sprintf(&message_string[message_string_size], "------+-------------------------------------------------|\n");
+        message_string_size += sprintf(&message_string[message_string_size], "      |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |\n");
+        message_string_size += sprintf(&message_string[message_string_size], "------+-------------------------------------------------|\n");
+
+        for (octet_index = 0; octet_index < rlc_pP->output_sdu_size_to_write; octet_index++) {
+          if ((octet_index % 16) == 0) {
+            if (octet_index != 0) {
+              message_string_size += sprintf(&message_string[message_string_size], " |\n");
+            }
+
+            message_string_size += sprintf(&message_string[message_string_size], " %04d |", octet_index);
           }
 
-          message_string_size += sprintf(&message_string[message_string_size], " %04d |", octet_index);
+          /*
+           * Print every single octet in hexadecimal form
+           */
+          message_string_size += sprintf(&message_string[message_string_size],
+                                         " %02x",
+                                         rlc_pP->output_sdu_in_construction->data[octet_index]);
+          /*
+           * Align newline and pipes according to the octets in groups of 2
+           */
         }
 
         /*
-         * Print every single octet in hexadecimal form
+         * Append enough spaces and put final pipe
          */
-        message_string_size += sprintf(&message_string[message_string_size],
-                                       " %02x",
-                                       rlc_pP->output_sdu_in_construction->data[octet_index]);
-        /*
-         * Align newline and pipes according to the octets in groups of 2
-         */
-      }
+        for (index = octet_index; index < 16; ++index) {
+          message_string_size += sprintf(&message_string[message_string_size], "   ");
+        }
 
-      /*
-       * Append enough spaces and put final pipe
-       */
-      for (index = octet_index; index < 16; ++index) {
-        message_string_size += sprintf(&message_string[message_string_size], "   ");
+        message_string_size += sprintf(&message_string[message_string_size], " |\n");
+        LOG_T(RLC, "%s", message_string);
       }
 
-      message_string_size += sprintf(&message_string[message_string_size], " |\n");
-
-
-
-#      if ENABLE_ITTI
-      msg_p = itti_alloc_new_message_sized (ctxt_pP->enb_flag > 0 ? TASK_RLC_ENB:TASK_RLC_UE ,
-                                            RLC_AM_SDU_IND,
-                                            message_string_size + sizeof (IttiMsgText));
-      msg_p->ittiMsg.rlc_am_sdu_ind.size = message_string_size;
-      memcpy(&msg_p->ittiMsg.rlc_am_sdu_ind.text, message_string, message_string_size);
-
-      itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
-
-#      else
-      LOG_T(RLC, "%s", message_string);
-#      endif
-#   endif
 #if !ENABLE_ITTI
       RLC_AM_MUTEX_UNLOCK(&rlc_pP->lock_input_sdus);
 #endif
       MSC_LOG_TX_MESSAGE(
         (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
         (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
-        (const char*)(rlc_pP->output_sdu_in_construction->data),
+        (const char *)(rlc_pP->output_sdu_in_construction->data),
         rlc_pP->output_sdu_size_to_write,
         MSC_AS_TIME_FMT" "PROTOCOL_RLC_AM_MSC_FMT" DATA-IND size %u",
         MSC_AS_TIME_ARGS(ctxt_pP),
         PROTOCOL_RLC_AM_MSC_ARGS(ctxt_pP,rlc_pP),
         rlc_pP->output_sdu_size_to_write
       );
-
       rlc_data_ind (ctxt_pP,
                     BOOL_NOT(rlc_pP->is_data_plane),
                     MBMS_FLAG_NO,
@@ -203,16 +178,16 @@ rlc_am_send_sdu (
             PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
       //msg("[RLC_AM][MOD %d] Freeing mem_block ...\n", rlc_pP->module_id);
       //free_mem_block (rlc_pP->output_sdu_in_construction, __func__);
-//Assertion(eNB)_PRAN_DesignDocument_annex No.764
-     LOG_E(RLC, PROTOCOL_RLC_AM_CTXT_FMT" SEND SDU REQUESTED %d bytes\n",
-             PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
-             rlc_pP->output_sdu_size_to_write);
-/*
-      AssertFatal(3==4,
-                  PROTOCOL_RLC_AM_CTXT_FMT" SEND SDU REQUESTED %d bytes",
-                  PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
-                  rlc_pP->output_sdu_size_to_write);
-*/
+      //Assertion(eNB)_PRAN_DesignDocument_annex No.764
+      LOG_E(RLC, PROTOCOL_RLC_AM_CTXT_FMT" SEND SDU REQUESTED %d bytes\n",
+            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
+            rlc_pP->output_sdu_size_to_write);
+      /*
+            AssertFatal(3==4,
+                        PROTOCOL_RLC_AM_CTXT_FMT" SEND SDU REQUESTED %d bytes",
+                        PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
+                        rlc_pP->output_sdu_size_to_write);
+      */
     }
 
     rlc_pP->output_sdu_size_to_write = 0;
@@ -221,191 +196,189 @@ rlc_am_send_sdu (
 //-----------------------------------------------------------------------------
 void
 rlc_am_reassemble_pdu(
-  const protocol_ctxt_t* const ctxt_pP,
-  rlc_am_entity_t * const      rlc_pP,
-  mem_block_t * const          tb_pP,
-  boolean_t free_rlc_pdu)
-{
+  const protocol_ctxt_t *const ctxt_pP,
+  rlc_am_entity_t *const      rlc_pP,
+  mem_block_t *const          tb_pP,
+  boolean_t free_rlc_pdu) {
   int i,j;
-
-  rlc_am_pdu_info_t* pdu_info        = &((rlc_am_rx_pdu_management_t*)(tb_pP->data))->pdu_info;
+  rlc_am_pdu_info_t *pdu_info        = &((rlc_am_rx_pdu_management_t *)(tb_pP->data))->pdu_info;
   LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PDU] TRY REASSEMBLY PDU SN=%03d\n",
         PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
         pdu_info->sn);
-#if TRACE_RLC_AM_RX_DECODE
-  rlc_am_display_data_pdu_infos(ctxt_pP, rlc_pP, pdu_info);
-#endif
+
+  if ( LOG_DEBUGFLAG(DEBUG_RLC)) {
+    rlc_am_display_data_pdu_infos(ctxt_pP, rlc_pP, pdu_info);
+  }
 
   if (pdu_info->e == RLC_E_FIXED_PART_DATA_FIELD_FOLLOW) {
     switch (pdu_info->fi) {
-    case RLC_FI_1ST_BYTE_DATA_IS_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_LAST_BYTE_SDU:
-      LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PDU] TRY REASSEMBLY PDU NO E_LI FI=11 (00)\n",
-            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
-      // one complete SDU
-      rlc_am_send_sdu(ctxt_pP, rlc_pP); // may be not necessary
-      rlc_am_reassembly (ctxt_pP, rlc_pP, pdu_info->payload, pdu_info->payload_size);
-      rlc_am_send_sdu(ctxt_pP, rlc_pP); // may be not necessary
-      //rlc_pP->reassembly_missing_sn_detected = 0;
-      break;
-
-    case RLC_FI_1ST_BYTE_DATA_IS_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_NOT_LAST_BYTE_SDU:
-      LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PDU] TRY REASSEMBLY PDU NO E_LI FI=10 (01)\n",
-            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
-      // one beginning segment of SDU in PDU
-      rlc_am_send_sdu(ctxt_pP, rlc_pP); // may be not necessary
-      rlc_am_reassembly (ctxt_pP, rlc_pP,pdu_info->payload, pdu_info->payload_size);
-      //rlc_pP->reassembly_missing_sn_detected = 0;
-      break;
-
-    case RLC_FI_1ST_BYTE_DATA_IS_NOT_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_LAST_BYTE_SDU:
-      LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PDU] TRY REASSEMBLY PDU NO E_LI FI=01 (10)\n",
-            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
-      // one last segment of SDU
-      //if (rlc_pP->reassembly_missing_sn_detected == 0) {
-      rlc_am_reassembly (ctxt_pP, rlc_pP, pdu_info->payload, pdu_info->payload_size);
-      rlc_am_send_sdu(ctxt_pP, rlc_pP);
-      //} // else { clear sdu already done
-      //rlc_pP->reassembly_missing_sn_detected = 0;
-      break;
-
-    case RLC_FI_1ST_BYTE_DATA_IS_NOT_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_NOT_LAST_BYTE_SDU:
-      LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PDU] TRY REASSEMBLY PDU NO E_LI FI=00 (11)\n",
-            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
-      //if (rlc_pP->reassembly_missing_sn_detected == 0) {
-      // one whole segment of SDU in PDU
-      rlc_am_reassembly (ctxt_pP, rlc_pP, pdu_info->payload, pdu_info->payload_size);
-      //} else {
-      //    rlc_pP->reassembly_missing_sn_detected = 1; // not necessary but for readability of the code
-      //}
-
-      break;
-
-    default:
-//Assertion(eNB)_PRAN_DesignDocument_annex No.1428
-      LOG_E(RLC, "RLC_E_FIXED_PART_DATA_FIELD_FOLLOW error pdu_info->fi[%d]\n", pdu_info->fi);
-//      assert(0 != 0);
+      case RLC_FI_1ST_BYTE_DATA_IS_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_LAST_BYTE_SDU:
+        LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PDU] TRY REASSEMBLY PDU NO E_LI FI=11 (00)\n",
+              PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
+        // one complete SDU
+        rlc_am_send_sdu(ctxt_pP, rlc_pP); // may be not necessary
+        rlc_am_reassembly (ctxt_pP, rlc_pP, pdu_info->payload, pdu_info->payload_size);
+        rlc_am_send_sdu(ctxt_pP, rlc_pP); // may be not necessary
+        //rlc_pP->reassembly_missing_sn_detected = 0;
+        break;
+
+      case RLC_FI_1ST_BYTE_DATA_IS_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_NOT_LAST_BYTE_SDU:
+        LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PDU] TRY REASSEMBLY PDU NO E_LI FI=10 (01)\n",
+              PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
+        // one beginning segment of SDU in PDU
+        rlc_am_send_sdu(ctxt_pP, rlc_pP); // may be not necessary
+        rlc_am_reassembly (ctxt_pP, rlc_pP,pdu_info->payload, pdu_info->payload_size);
+        //rlc_pP->reassembly_missing_sn_detected = 0;
+        break;
+
+      case RLC_FI_1ST_BYTE_DATA_IS_NOT_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_LAST_BYTE_SDU:
+        LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PDU] TRY REASSEMBLY PDU NO E_LI FI=01 (10)\n",
+              PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
+        // one last segment of SDU
+        //if (rlc_pP->reassembly_missing_sn_detected == 0) {
+        rlc_am_reassembly (ctxt_pP, rlc_pP, pdu_info->payload, pdu_info->payload_size);
+        rlc_am_send_sdu(ctxt_pP, rlc_pP);
+        //} // else { clear sdu already done
+        //rlc_pP->reassembly_missing_sn_detected = 0;
+        break;
+
+      case RLC_FI_1ST_BYTE_DATA_IS_NOT_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_NOT_LAST_BYTE_SDU:
+        LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PDU] TRY REASSEMBLY PDU NO E_LI FI=00 (11)\n",
+              PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
+        //if (rlc_pP->reassembly_missing_sn_detected == 0) {
+        // one whole segment of SDU in PDU
+        rlc_am_reassembly (ctxt_pP, rlc_pP, pdu_info->payload, pdu_info->payload_size);
+        //} else {
+        //    rlc_pP->reassembly_missing_sn_detected = 1; // not necessary but for readability of the code
+        //}
+        break;
+
+      default:
+        //Assertion(eNB)_PRAN_DesignDocument_annex No.1428
+        LOG_E(RLC, "RLC_E_FIXED_PART_DATA_FIELD_FOLLOW error pdu_info->fi[%d]\n", pdu_info->fi);
+        //      assert(0 != 0);
     }
   } else {
     switch (pdu_info->fi) {
-    case RLC_FI_1ST_BYTE_DATA_IS_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_LAST_BYTE_SDU:
-      LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PDU] TRY REASSEMBLY PDU FI=11 (00) Li=",
-            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
-
-      for (i=0; i < pdu_info->num_li; i++) {
-        LOG_D(RLC, "%d ",pdu_info->li_list[i]);
-      }
+      case RLC_FI_1ST_BYTE_DATA_IS_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_LAST_BYTE_SDU:
+        LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PDU] TRY REASSEMBLY PDU FI=11 (00) Li=",
+              PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
 
-      LOG_D(RLC, "\n");
-      //msg(" remaining size %d\n",size);
-      // N complete SDUs
-      rlc_am_send_sdu(ctxt_pP, rlc_pP);
-      j = 0;
+        for (i=0; i < pdu_info->num_li; i++) {
+          LOG_D(RLC, "%d ",pdu_info->li_list[i]);
+        }
 
-      for (i = 0; i < pdu_info->num_li; i++) {
-        rlc_am_reassembly (ctxt_pP, rlc_pP, &pdu_info->payload[j], pdu_info->li_list[i]);
+        LOG_D(RLC, "\n");
+        //msg(" remaining size %d\n",size);
+        // N complete SDUs
         rlc_am_send_sdu(ctxt_pP, rlc_pP);
-        j = j + pdu_info->li_list[i];
-      }
+        j = 0;
 
-      if (pdu_info->hidden_size > 0) { // normally should always be > 0 but just for help debug
-        // data is already ok, done by last loop above
-        rlc_am_reassembly (ctxt_pP, rlc_pP, &pdu_info->payload[j], pdu_info->hidden_size);
-        rlc_am_send_sdu(ctxt_pP, rlc_pP);
-      }
+        for (i = 0; i < pdu_info->num_li; i++) {
+          rlc_am_reassembly (ctxt_pP, rlc_pP, &pdu_info->payload[j], pdu_info->li_list[i]);
+          rlc_am_send_sdu(ctxt_pP, rlc_pP);
+          j = j + pdu_info->li_list[i];
+        }
 
-      //rlc_pP->reassembly_missing_sn_detected = 0;
-      break;
+        if (pdu_info->hidden_size > 0) { // normally should always be > 0 but just for help debug
+          // data is already ok, done by last loop above
+          rlc_am_reassembly (ctxt_pP, rlc_pP, &pdu_info->payload[j], pdu_info->hidden_size);
+          rlc_am_send_sdu(ctxt_pP, rlc_pP);
+        }
 
-    case RLC_FI_1ST_BYTE_DATA_IS_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_NOT_LAST_BYTE_SDU:
-      LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PDU] TRY REASSEMBLY PDU FI=10 (01) Li=",
-            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
+        //rlc_pP->reassembly_missing_sn_detected = 0;
+        break;
 
-      for (i=0; i < pdu_info->num_li; i++) {
-        LOG_D(RLC, "%d ",pdu_info->li_list[i]);
-      }
+      case RLC_FI_1ST_BYTE_DATA_IS_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_NOT_LAST_BYTE_SDU:
+        LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PDU] TRY REASSEMBLY PDU FI=10 (01) Li=",
+              PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
 
-      LOG_D(RLC, "\n");
-      //msg(" remaining size %d\n",size);
-      // N complete SDUs + one segment of SDU in PDU
-      rlc_am_send_sdu(ctxt_pP, rlc_pP);
-      j = 0;
+        for (i=0; i < pdu_info->num_li; i++) {
+          LOG_D(RLC, "%d ",pdu_info->li_list[i]);
+        }
 
-      for (i = 0; i < pdu_info->num_li; i++) {
-        rlc_am_reassembly (ctxt_pP, rlc_pP, &pdu_info->payload[j], pdu_info->li_list[i]);
+        LOG_D(RLC, "\n");
+        //msg(" remaining size %d\n",size);
+        // N complete SDUs + one segment of SDU in PDU
         rlc_am_send_sdu(ctxt_pP, rlc_pP);
-        j = j + pdu_info->li_list[i];
-      }
+        j = 0;
 
-      if (pdu_info->hidden_size > 0) { // normally should always be > 0 but just for help debug
-        // data is already ok, done by last loop above
-        rlc_am_reassembly (ctxt_pP, rlc_pP, &pdu_info->payload[j], pdu_info->hidden_size);
-      }
+        for (i = 0; i < pdu_info->num_li; i++) {
+          rlc_am_reassembly (ctxt_pP, rlc_pP, &pdu_info->payload[j], pdu_info->li_list[i]);
+          rlc_am_send_sdu(ctxt_pP, rlc_pP);
+          j = j + pdu_info->li_list[i];
+        }
 
-      //rlc_pP->reassembly_missing_sn_detected = 0;
-      break;
+        if (pdu_info->hidden_size > 0) { // normally should always be > 0 but just for help debug
+          // data is already ok, done by last loop above
+          rlc_am_reassembly (ctxt_pP, rlc_pP, &pdu_info->payload[j], pdu_info->hidden_size);
+        }
 
-    case RLC_FI_1ST_BYTE_DATA_IS_NOT_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_LAST_BYTE_SDU:
-      LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PDU] TRY REASSEMBLY PDU FI=01 (10) Li=",
-            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
+        //rlc_pP->reassembly_missing_sn_detected = 0;
+        break;
 
-      for (i=0; i < pdu_info->num_li; i++) {
-        LOG_D(RLC, "%d ",pdu_info->li_list[i]);
-      }
+      case RLC_FI_1ST_BYTE_DATA_IS_NOT_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_LAST_BYTE_SDU:
+        LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PDU] TRY REASSEMBLY PDU FI=01 (10) Li=",
+              PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
 
-      LOG_D(RLC, "\n");
-      //msg(" remaining size %d\n",size);
-      // one last segment of SDU + N complete SDUs in PDU
-      j = 0;
+        for (i=0; i < pdu_info->num_li; i++) {
+          LOG_D(RLC, "%d ",pdu_info->li_list[i]);
+        }
 
-      for (i = 0; i < pdu_info->num_li; i++) {
-        rlc_am_reassembly (ctxt_pP, rlc_pP, &pdu_info->payload[j], pdu_info->li_list[i]);
-        rlc_am_send_sdu(ctxt_pP, rlc_pP);
-        j = j + pdu_info->li_list[i];
-      }
+        LOG_D(RLC, "\n");
+        //msg(" remaining size %d\n",size);
+        // one last segment of SDU + N complete SDUs in PDU
+        j = 0;
 
-      if (pdu_info->hidden_size > 0) { // normally should always be > 0 but just for help debug
-        // data is already ok, done by last loop above
-        rlc_am_reassembly (ctxt_pP, rlc_pP, &pdu_info->payload[j], pdu_info->hidden_size);
-        rlc_am_send_sdu(ctxt_pP, rlc_pP);
-      }
+        for (i = 0; i < pdu_info->num_li; i++) {
+          rlc_am_reassembly (ctxt_pP, rlc_pP, &pdu_info->payload[j], pdu_info->li_list[i]);
+          rlc_am_send_sdu(ctxt_pP, rlc_pP);
+          j = j + pdu_info->li_list[i];
+        }
 
-      //rlc_pP->reassembly_missing_sn_detected = 0;
-      break;
+        if (pdu_info->hidden_size > 0) { // normally should always be > 0 but just for help debug
+          // data is already ok, done by last loop above
+          rlc_am_reassembly (ctxt_pP, rlc_pP, &pdu_info->payload[j], pdu_info->hidden_size);
+          rlc_am_send_sdu(ctxt_pP, rlc_pP);
+        }
 
-    case RLC_FI_1ST_BYTE_DATA_IS_NOT_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_NOT_LAST_BYTE_SDU:
-      LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PDU] TRY REASSEMBLY PDU FI=00 (11) Li=",
-            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
+        //rlc_pP->reassembly_missing_sn_detected = 0;
+        break;
 
-      for (i=0; i < pdu_info->num_li; i++) {
-        LOG_D(RLC, "%d ",pdu_info->li_list[i]);
-      }
+      case RLC_FI_1ST_BYTE_DATA_IS_NOT_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_NOT_LAST_BYTE_SDU:
+        LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PDU] TRY REASSEMBLY PDU FI=00 (11) Li=",
+              PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
 
-      LOG_D(RLC, "\n");
-      //msg(" remaining size %d\n",size);
-      j = 0;
+        for (i=0; i < pdu_info->num_li; i++) {
+          LOG_D(RLC, "%d ",pdu_info->li_list[i]);
+        }
 
-      for (i = 0; i < pdu_info->num_li; i++) {
-        rlc_am_reassembly (ctxt_pP, rlc_pP, &pdu_info->payload[j], pdu_info->li_list[i]);
-        rlc_am_send_sdu(ctxt_pP, rlc_pP);
-        j = j + pdu_info->li_list[i];
-      }
+        LOG_D(RLC, "\n");
+        //msg(" remaining size %d\n",size);
+        j = 0;
 
-      if (pdu_info->hidden_size > 0) { // normally should always be > 0 but just for help debug
-        // data is already ok, done by last loop above
-        rlc_am_reassembly (ctxt_pP, rlc_pP, &pdu_info->payload[j], pdu_info->hidden_size);
-      }
+        for (i = 0; i < pdu_info->num_li; i++) {
+          rlc_am_reassembly (ctxt_pP, rlc_pP, &pdu_info->payload[j], pdu_info->li_list[i]);
+          rlc_am_send_sdu(ctxt_pP, rlc_pP);
+          j = j + pdu_info->li_list[i];
+        }
+
+        if (pdu_info->hidden_size > 0) { // normally should always be > 0 but just for help debug
+          // data is already ok, done by last loop above
+          rlc_am_reassembly (ctxt_pP, rlc_pP, &pdu_info->payload[j], pdu_info->hidden_size);
+        }
 
-      //rlc_pP->reassembly_missing_sn_detected = 0;
-      break;
+        //rlc_pP->reassembly_missing_sn_detected = 0;
+        break;
 
-    default:
-//Assertion(eNB)_PRAN_DesignDocument_annex No.1429
-      LOG_E(RLC, "not RLC_E_FIXED_PART_DATA_FIELD_FOLLOW error pdu_info->fi[%d]\n", pdu_info->fi);
-//      assert(1 != 1);
+      default:
+        //Assertion(eNB)_PRAN_DesignDocument_annex No.1429
+        LOG_E(RLC, "not RLC_E_FIXED_PART_DATA_FIELD_FOLLOW error pdu_info->fi[%d]\n", pdu_info->fi);
+        //      assert(1 != 1);
     }
   }
 
   if (free_rlc_pdu) {
-	  free_mem_block(tb_pP, __func__);
+    free_mem_block(tb_pP, __func__);
   }
 }
diff --git a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_status_report.c b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_status_report.c
index 917f1a1791d733bc9a63701fc2bef0d92e6f1506..5c68aecf61397e88c58f249bb0e3fa5936a54e26 100644
--- a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_status_report.c
+++ b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_status_report.c
@@ -27,59 +27,19 @@
 #include "platform_types.h"
 //-----------------------------------------------------------------------------
 #if ENABLE_ITTI
-# include "intertask_interface.h"
+  #include "intertask_interface.h"
 #endif
 #include "assertions.h"
 #include "list.h"
 #include "rlc_am.h"
 #include "common/utils/LOG/log.h"
 
-#   if ENABLE_ITTI
-//-----------------------------------------------------------------------------
-void
-rlc_am_itti_display_status_ind_infos(
-  const protocol_ctxt_t* const            ctxt_pP,
-  const rlc_am_entity_t *const            rlc_pP,
-  const rlc_am_control_pdu_info_t *const  pdu_info_pP)
-{
-  char                 message_string[1000];
-  size_t               message_string_size = 0;
-  MessageDef          *msg_p;
-
-  int num_nack;
-
-  if (!pdu_info_pP->d_c) {
-    message_string_size += sprintf(&message_string[message_string_size], "Bearer      : %u\n", rlc_pP->rb_id);
-    message_string_size += sprintf(&message_string[message_string_size], "CONTROL PDU ACK SN %04d", pdu_info_pP->ack_sn);
-
-    for (num_nack = 0; num_nack < pdu_info_pP->num_nack; num_nack++) {
-      if (pdu_info_pP->nack_list[num_nack].e2) {
-        message_string_size += sprintf(&message_string[message_string_size], "\n\tNACK SN %04d SO START %05d SO END %05d",  pdu_info_pP->nack_list[num_nack].nack_sn,
-                                       pdu_info_pP->nack_list[num_nack].so_start,
-                                       pdu_info_pP->nack_list[num_nack].so_end);
-      } else {
-        message_string_size += sprintf(&message_string[message_string_size], "\n\tNACK SN %04d",  pdu_info_pP->nack_list[num_nack].nack_sn);
-      }
-    }
-
-    message_string_size += sprintf(&message_string[message_string_size], "\n");
-
-    msg_p = itti_alloc_new_message_sized (ctxt_pP->enb_flag > 0 ? TASK_RLC_ENB:TASK_RLC_UE , RLC_AM_STATUS_PDU_IND, message_string_size + sizeof (IttiMsgText));
-    msg_p->ittiMsg.rlc_am_status_pdu_ind.size = message_string_size;
-    memcpy(&msg_p->ittiMsg.rlc_am_status_pdu_ind.text, message_string, message_string_size);
-
-    itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
-  }
-}
-
-#   endif
 
 //-----------------------------------------------------------------------------
 uint16_t rlc_am_read_bit_field(
-  uint8_t** data_ppP,
-  unsigned int* bit_pos_pP,
-  const signed int bits_to_readP)
-{
+  uint8_t **data_ppP,
+  unsigned int *bit_pos_pP,
+  const signed int bits_to_readP) {
   uint16_t        value     = 0;
   unsigned int bits_read = 0;
   signed int bits_to_read = bits_to_readP;
@@ -113,11 +73,10 @@ uint16_t rlc_am_read_bit_field(
 //-----------------------------------------------------------------------------
 void
 rlc_am_write8_bit_field(
-  uint8_t** data_ppP,
-  unsigned int* bit_pos_pP,
+  uint8_t **data_ppP,
+  unsigned int *bit_pos_pP,
   const signed int bits_to_writeP,
-  const uint8_t valueP)
-{
+  const uint8_t valueP) {
   unsigned int available_bits;
   signed int bits_to_write= bits_to_writeP;
 
@@ -148,11 +107,10 @@ rlc_am_write8_bit_field(
 //-----------------------------------------------------------------------------
 void
 rlc_am_write16_bit_field(
-  uint8_t** data_ppP,
-  unsigned int* bit_pos_pP,
+  uint8_t **data_ppP,
+  unsigned int *bit_pos_pP,
   signed int bits_to_writeP,
-  const uint16_t valueP)
-{
+  const uint16_t valueP) {
   //assert(bits_to_writeP <= 16);
   if(bits_to_writeP > 16) {
     LOG_E(RLC, "bits_to_writeP error. %d\n", bits_to_writeP);
@@ -168,15 +126,12 @@ rlc_am_write16_bit_field(
 //-----------------------------------------------------------------------------
 signed int
 rlc_am_get_control_pdu_infos(
-  rlc_am_pdu_sn_10_t* const        header_pP,
-  sdu_size_t * const               total_size_pP,
-  rlc_am_control_pdu_info_t* const pdu_info_pP)
-{
+  rlc_am_pdu_sn_10_t *const        header_pP,
+  sdu_size_t *const               total_size_pP,
+  rlc_am_control_pdu_info_t *const pdu_info_pP) {
   memset(pdu_info_pP, 0, sizeof (rlc_am_control_pdu_info_t));
-
   pdu_info_pP->d_c = header_pP->b1 >> 7;
 
-
   if (!pdu_info_pP->d_c) {
     pdu_info_pP->cpt    = (header_pP->b1 >> 4) & 0x07;
 
@@ -191,7 +146,7 @@ rlc_am_get_control_pdu_infos(
     if (pdu_info_pP->e1) {
       unsigned int nack_to_read  = 1;
       unsigned int bit_pos       = 7; // range from 0 (MSB/left) to 7 (LSB/right)
-      uint8_t*        byte_pos_p      = &header_pP->b2;
+      uint8_t        *byte_pos_p      = &header_pP->b2;
 
       while (nack_to_read)  {
         pdu_info_pP->nack_list[pdu_info_pP->num_nack].nack_sn = rlc_am_read_bit_field(&byte_pos_p, &bit_pos, 10);
@@ -214,9 +169,11 @@ rlc_am_get_control_pdu_infos(
         if (!pdu_info_pP->nack_list[pdu_info_pP->num_nack - 1].e1) {
           nack_to_read = 0;
           *total_size_pP = *total_size_pP - (sdu_size_t)((uint64_t)byte_pos_p + (uint64_t)((bit_pos + 7)/8) - (uint64_t)header_pP);
+
           if (*total_size_pP != 0) {
             LOG_E(RLC, "[RLC_AM_GET_CONTROL_PDU_INFOS][FIRST]header_pP->b1=%d,header_pP->b2=%d\n",header_pP->b1,header_pP->b2);
           }
+
           return 0;
         }
 
@@ -230,9 +187,11 @@ rlc_am_get_control_pdu_infos(
     } else {
       *total_size_pP = *total_size_pP - 2;
     }
+
     if (*total_size_pP != 0) {
       LOG_E(RLC, "[RLC_AM_GET_CONTROL_PDU_INFOS][SECOND]header_pP->b1=%d,header_pP->b2=%d\n",header_pP->b1,header_pP->b2);
     }
+
     return 0;
   } else {
     return -1;
@@ -241,9 +200,8 @@ rlc_am_get_control_pdu_infos(
 //-----------------------------------------------------------------------------
 void
 rlc_am_display_control_pdu_infos(
-  const rlc_am_control_pdu_info_t* const pdu_info_pP
-)
-{
+  const rlc_am_control_pdu_info_t *const pdu_info_pP
+) {
   int num_nack;
 
   if (!pdu_info_pP->d_c) {
@@ -267,25 +225,23 @@ rlc_am_display_control_pdu_infos(
 //-----------------------------------------------------------------------------
 void
 rlc_am_receive_process_control_pdu(
-  const protocol_ctxt_t* const  ctxt_pP,
+  const protocol_ctxt_t *const  ctxt_pP,
   rlc_am_entity_t *const rlc_pP,
-  mem_block_t* const tb_pP,
-  uint8_t** first_byte_ppP,
-  sdu_size_t * const tb_size_in_bytes_pP)
-{
-  rlc_am_pdu_sn_10_t *rlc_am_pdu_sn_10_p = (rlc_am_pdu_sn_10_t*)*first_byte_ppP;
+  mem_block_t *const tb_pP,
+  uint8_t **first_byte_ppP,
+  sdu_size_t *const tb_size_in_bytes_pP) {
+  rlc_am_pdu_sn_10_t *rlc_am_pdu_sn_10_p = (rlc_am_pdu_sn_10_t *)*first_byte_ppP;
   sdu_size_t          initial_pdu_size   = *tb_size_in_bytes_pP;
   rlc_sn_t        ack_sn    = RLC_AM_NEXT_SN(rlc_pP->vt_a);
   rlc_sn_t        sn_cursor = rlc_pP->vt_a;
-  rlc_sn_t		vt_a_new  = rlc_pP->vt_a;
-  rlc_sn_t		sn_data_cnf;
+  rlc_sn_t    vt_a_new  = rlc_pP->vt_a;
+  rlc_sn_t    sn_data_cnf;
   rlc_sn_t        nack_sn,prev_nack_sn;
-  sdu_size_t		data_cnf_so_stop = 0x7FFF;
+  sdu_size_t    data_cnf_so_stop = 0x7FFF;
   unsigned int nack_index;
   boolean_t status = TRUE;
 
   if (rlc_am_get_control_pdu_infos(rlc_am_pdu_sn_10_p, tb_size_in_bytes_pP, &rlc_pP->control_pdu_info) >= 0) {
-
     rlc_am_tx_buffer_display(ctxt_pP, rlc_pP, " TX BUFFER BEFORE PROCESS OF STATUS PDU");
     LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT" RX CONTROL PDU VT(A) %04d VT(S) %04d POLL_SN %04d ACK_SN %04d\n",
           PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
@@ -294,7 +250,6 @@ rlc_am_receive_process_control_pdu(
           rlc_pP->poll_sn,
           rlc_pP->control_pdu_info.ack_sn);
     rlc_am_display_control_pdu_infos(&rlc_pP->control_pdu_info);
-
     ack_sn    = rlc_pP->control_pdu_info.ack_sn;
     // 5.2.1 Retransmission
     //
@@ -326,8 +281,7 @@ rlc_am_receive_process_control_pdu(
 
     /* Note : ackSn can be equal to current vtA only in case the status pdu contains a list of nack_sn with same value = vtA with SOStart/SOEnd */
     /* and meaning the report is not complete due to not enough ressources to fill all SOStart/SOEnd of this NACK_SN */
-    if (RLC_AM_DIFF_SN(rlc_pP->vt_s,rlc_pP->vt_a) >= RLC_AM_DIFF_SN(ack_sn,rlc_pP->vt_a))
-    {
+    if (RLC_AM_DIFF_SN(rlc_pP->vt_s,rlc_pP->vt_a) >= RLC_AM_DIFF_SN(ack_sn,rlc_pP->vt_a)) {
       if (rlc_pP->control_pdu_info.num_nack == 0) {
         while (sn_cursor != ack_sn) {
           rlc_am_ack_pdu(ctxt_pP, rlc_pP, sn_cursor,TRUE);
@@ -342,63 +296,56 @@ rlc_am_receive_process_control_pdu(
         prev_nack_sn = 0x3FFF;
 
         while (sn_cursor != nack_sn) {
-            rlc_am_ack_pdu(ctxt_pP, rlc_pP, sn_cursor,TRUE);
-            sn_cursor = RLC_AM_NEXT_SN(sn_cursor);
+          rlc_am_ack_pdu(ctxt_pP, rlc_pP, sn_cursor,TRUE);
+          sn_cursor = RLC_AM_NEXT_SN(sn_cursor);
         }
 
         vt_a_new = nack_sn;
-
         // catch DataCfn
         rlc_am_tx_data_pdu_management_t *tx_data_pdu_buffer_p = &rlc_pP->tx_data_pdu_buffer[nack_sn % RLC_AM_WINDOW_SIZE];
+
         if (tx_data_pdu_buffer_p->retx_payload_size == tx_data_pdu_buffer_p->payload_size) {
-        	sn_data_cnf   = RLC_AM_PREV_SN(nack_sn);
-        }
-        else if (tx_data_pdu_buffer_p->nack_so_start != 0) {
-        	sn_data_cnf       = nack_sn;
-        	data_cnf_so_stop    = tx_data_pdu_buffer_p->nack_so_start - 1;
-        }
-        else {
-        	sn_data_cnf       = RLC_AM_PREV_SN(nack_sn);
+          sn_data_cnf   = RLC_AM_PREV_SN(nack_sn);
+        } else if (tx_data_pdu_buffer_p->nack_so_start != 0) {
+          sn_data_cnf       = nack_sn;
+          data_cnf_so_stop    = tx_data_pdu_buffer_p->nack_so_start - 1;
+        } else {
+          sn_data_cnf       = RLC_AM_PREV_SN(nack_sn);
         }
 
-
         while ((sn_cursor != ack_sn) && (status)) {
           if (sn_cursor != nack_sn) {
             rlc_am_ack_pdu(ctxt_pP,
                            rlc_pP,
                            sn_cursor,
-						   FALSE);
+                           FALSE);
           } else {
-        	status = rlc_am_nack_pdu (ctxt_pP,
-                             rlc_pP,
-							 nack_sn,
-							 prev_nack_sn,
-                             rlc_pP->control_pdu_info.nack_list[nack_index].so_start,
-                             rlc_pP->control_pdu_info.nack_list[nack_index].so_end);
-
+            status = rlc_am_nack_pdu (ctxt_pP,
+                                      rlc_pP,
+                                      nack_sn,
+                                      prev_nack_sn,
+                                      rlc_pP->control_pdu_info.nack_list[nack_index].so_start,
+                                      rlc_pP->control_pdu_info.nack_list[nack_index].so_end);
             nack_index = nack_index + 1;
             prev_nack_sn = nack_sn;
 
             if (nack_index < rlc_pP->control_pdu_info.num_nack) {
-               nack_sn = rlc_pP->control_pdu_info.nack_list[nack_index].nack_sn;
-            }
-            else if (nack_sn != ack_sn) {
-            	/* general case*/
-            	nack_sn = ack_sn;
-            }
-            else {
-            	/*specific case when the sender did not have enough TBS to fill all SOStart SOEnd for this NACK_SN */
-            	break;
+              nack_sn = rlc_pP->control_pdu_info.nack_list[nack_index].nack_sn;
+            } else if (nack_sn != ack_sn) {
+              /* general case*/
+              nack_sn = ack_sn;
+            } else {
+              /*specific case when the sender did not have enough TBS to fill all SOStart SOEnd for this NACK_SN */
+              break;
             }
           }
+
           if (prev_nack_sn != nack_sn) {
-        	  /* do not increment sn_cursor in case of several informations for the same nack_sn */
-              sn_cursor = (sn_cursor + 1)  & RLC_AM_SN_MASK;
+            /* do not increment sn_cursor in case of several informations for the same nack_sn */
+            sn_cursor = (sn_cursor + 1)  & RLC_AM_SN_MASK;
           }
         }
       }
-
-
     } else {
       LOG_E(RLC, PROTOCOL_RLC_AM_CTXT_FMT" WARNING CONTROL PDU ACK SN %d OUT OF WINDOW vtA=%d vtS=%d\n",
             PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),ack_sn,rlc_pP->vt_a,rlc_pP->vt_s);
@@ -413,61 +360,57 @@ rlc_am_receive_process_control_pdu(
   }
 
   if (status) {
-      /* Check for Stopping TpollReTx */
-      if ((rlc_pP->poll_sn != RLC_SN_UNDEFINED) &&
-          (RLC_AM_DIFF_SN(ack_sn,rlc_pP->vt_a) > RLC_AM_DIFF_SN(rlc_pP->poll_sn,rlc_pP->vt_a))) {
-        rlc_am_stop_and_reset_timer_poll_retransmit(ctxt_pP, rlc_pP);
-        rlc_pP->poll_sn = RLC_SN_UNDEFINED;
-      }
-
-      //TODO : this part does not cover all cases of Data Cnf and move it at the end of Status PDU processing
-      sn_cursor = rlc_pP->vt_a;
-
-      // Fix Issue 238 : check sn_data_cnf has been transmitted
-      if ((rlc_pP->tx_data_pdu_buffer[sn_data_cnf % RLC_AM_WINDOW_SIZE].flags.transmitted) &&
-    		  (rlc_pP->tx_data_pdu_buffer[sn_data_cnf % RLC_AM_WINDOW_SIZE].sn == sn_data_cnf)) {
-    	  /* Handle all acked PDU up to and excluding sn_data_cnf */
-          while (sn_cursor != sn_data_cnf) {
-        	  rlc_am_pdu_sdu_data_cnf(ctxt_pP,rlc_pP,sn_cursor);
-        	  sn_cursor = RLC_AM_NEXT_SN(sn_cursor);
-          }
+    /* Check for Stopping TpollReTx */
+    if ((rlc_pP->poll_sn != RLC_SN_UNDEFINED) &&
+        (RLC_AM_DIFF_SN(ack_sn,rlc_pP->vt_a) > RLC_AM_DIFF_SN(rlc_pP->poll_sn,rlc_pP->vt_a))) {
+      rlc_am_stop_and_reset_timer_poll_retransmit(ctxt_pP, rlc_pP);
+      rlc_pP->poll_sn = RLC_SN_UNDEFINED;
+    }
 
-          // Handle last SN. TO DO : case of PDU partially ACKED with SDU to be data conf
-          if (data_cnf_so_stop == 0x7FFF) {
-        	  rlc_am_pdu_sdu_data_cnf(ctxt_pP,rlc_pP,sn_data_cnf);
-          }
+    //TODO : this part does not cover all cases of Data Cnf and move it at the end of Status PDU processing
+    sn_cursor = rlc_pP->vt_a;
 
-          LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT" RECEIVE STATUS PDU ACK_SN=%d NewvtA=%d OldvtA=%d SnDataCnf=%d DataCnfSOStop=%d vtS=%d\n",
-                      PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),ack_sn,vt_a_new,rlc_pP->vt_a,sn_data_cnf,data_cnf_so_stop,rlc_pP->vt_s);
+    // Fix Issue 238 : check sn_data_cnf has been transmitted
+    if ((rlc_pP->tx_data_pdu_buffer[sn_data_cnf % RLC_AM_WINDOW_SIZE].flags.transmitted) &&
+        (rlc_pP->tx_data_pdu_buffer[sn_data_cnf % RLC_AM_WINDOW_SIZE].sn == sn_data_cnf)) {
+      /* Handle all acked PDU up to and excluding sn_data_cnf */
+      while (sn_cursor != sn_data_cnf) {
+        rlc_am_pdu_sdu_data_cnf(ctxt_pP,rlc_pP,sn_cursor);
+        sn_cursor = RLC_AM_NEXT_SN(sn_cursor);
       }
-      else {
-          LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT" RECEIVE STATUS PDU WITH NO SDU CNF ACK_SN=%d NewvtA=%d OldvtA=%d vtS=%d\n",
-                      PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),ack_sn,vt_a_new,rlc_pP->vt_a,rlc_pP->vt_s);
+
+      // Handle last SN. TO DO : case of PDU partially ACKED with SDU to be data conf
+      if (data_cnf_so_stop == 0x7FFF) {
+        rlc_am_pdu_sdu_data_cnf(ctxt_pP,rlc_pP,sn_data_cnf);
       }
 
-      /* Update vtA and vtMS */
-      rlc_pP->vt_a = vt_a_new;
-      rlc_pP->vt_ms = (rlc_pP->vt_a + RLC_AM_WINDOW_SIZE) & RLC_AM_SN_MASK;
-  }
+      LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT" RECEIVE STATUS PDU ACK_SN=%d NewvtA=%d OldvtA=%d SnDataCnf=%d DataCnfSOStop=%d vtS=%d\n",
+            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),ack_sn,vt_a_new,rlc_pP->vt_a,sn_data_cnf,data_cnf_so_stop,rlc_pP->vt_s);
+    } else {
+      LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT" RECEIVE STATUS PDU WITH NO SDU CNF ACK_SN=%d NewvtA=%d OldvtA=%d vtS=%d\n",
+            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),ack_sn,vt_a_new,rlc_pP->vt_a,rlc_pP->vt_s);
+    }
 
-  *first_byte_ppP = (uint8_t*)((uint64_t)*first_byte_ppP + initial_pdu_size - *tb_size_in_bytes_pP);
+    /* Update vtA and vtMS */
+    rlc_pP->vt_a = vt_a_new;
+    rlc_pP->vt_ms = (rlc_pP->vt_a + RLC_AM_WINDOW_SIZE) & RLC_AM_SN_MASK;
+  }
 
+  *first_byte_ppP = (uint8_t *)((uint64_t)*first_byte_ppP + initial_pdu_size - *tb_size_in_bytes_pP);
   free_mem_block(tb_pP, __func__);
   rlc_am_tx_buffer_display(ctxt_pP, rlc_pP, NULL);
 }
 //-----------------------------------------------------------------------------
 int
 rlc_am_write_status_pdu(
-  const protocol_ctxt_t* const     ctxt_pP,
+  const protocol_ctxt_t *const     ctxt_pP,
   rlc_am_entity_t *const           rlc_pP,
-  rlc_am_pdu_sn_10_t* const        rlc_am_pdu_sn_10_pP,
-  rlc_am_control_pdu_info_t* const pdu_info_pP)
-{
+  rlc_am_pdu_sn_10_t *const        rlc_am_pdu_sn_10_pP,
+  rlc_am_control_pdu_info_t *const pdu_info_pP) {
   unsigned int bit_pos       = 4; // range from 0 (MSB/left) to 7 (LSB/right)
-  uint8_t*        byte_pos_p    = &rlc_am_pdu_sn_10_pP->b1;
+  uint8_t        *byte_pos_p    = &rlc_am_pdu_sn_10_pP->b1;
   unsigned int index         = 0;
   unsigned int num_bytes     = 0;
-
   rlc_am_write16_bit_field(&byte_pos_p, &bit_pos, 10, pdu_info_pP->ack_sn);
 
   if (pdu_info_pP->num_nack > 0) {
@@ -495,20 +438,17 @@ rlc_am_write_status_pdu(
     num_bytes += 1;
   }
 
-#if TRACE_RLC_AM_STATUS_CREATION
   LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT" WROTE STATUS PDU %d BYTES\n",
         PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
         num_bytes);
-#endif
   return num_bytes;
 }
 //-----------------------------------------------------------------------------
 void
 rlc_am_send_status_pdu(
-  const protocol_ctxt_t* const  ctxt_pP,
+  const protocol_ctxt_t *const  ctxt_pP,
   rlc_am_entity_t *const rlc_pP
-)
-{
+) {
   // When STATUS reporting has been triggered, the receiving side of an AM RLC entity shall:
   // - if t-StatusProhibit is not running:
   //     - at the first transmission opportunity indicated by lower layer, construct a STATUS PDU and deliver it to lower layer;
@@ -530,10 +470,9 @@ rlc_am_send_status_pdu(
   //             - include in the STATUS PDU a set of NACK_SN, SOstart and SOend
   //     - set the ACK_SN to the SN of the next not received RLC Data PDU which is not indicated as missing in the
   //       resulting STATUS PDU.
-
   signed int                    nb_bits_to_transmit   = rlc_pP->nb_bytes_requested_by_mac << 3;
   // minimum header size in bits to be transmitted: D/C + CPT + ACK_SN + E1
-  signed int                    nb_bits_transmitted	  = RLC_AM_PDU_D_C_BITS + RLC_AM_STATUS_PDU_CPT_LENGTH + RLC_AM_SN_BITS + RLC_AM_PDU_E_BITS;
+  signed int                    nb_bits_transmitted   = RLC_AM_PDU_D_C_BITS + RLC_AM_STATUS_PDU_CPT_LENGTH + RLC_AM_SN_BITS + RLC_AM_PDU_E_BITS;
   rlc_am_control_pdu_info_t     control_pdu_info;
   rlc_am_pdu_info_t            *pdu_info_cursor_p     = NULL;
   rlc_sn_t                      sn_cursor             = 0;
@@ -543,325 +482,278 @@ rlc_am_send_status_pdu(
   int                           waited_so             = 0;
   mem_block_t                  *tb_p                  = NULL;
   sdu_size_t                    pdu_size              = 0;
-  boolean_t						status_report_completed	= false;
-  boolean_t						segment_loop_end	  = false;
-
+  boolean_t           status_report_completed = false;
+  boolean_t           segment_loop_end    = false;
   memset(&control_pdu_info, 0, sizeof(rlc_am_control_pdu_info_t));
-
-#if TRACE_RLC_AM_STATUS_CREATION
   LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[SEND-STATUS] nb_bits_to_transmit %d (15 already allocated for header)\n",
         PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
         nb_bits_to_transmit);
   rlc_am_rx_list_display(rlc_pP, " DISPLAY BEFORE CONSTRUCTION OF STATUS REPORT");
-#endif
 
   /* Handle no NACK first */
   if (rlc_pP->vr_r == rlc_pP->vr_ms) {
-
-	  control_pdu_info.ack_sn = rlc_pP->vr_ms;
-	  status_report_completed = true;
-#if TRACE_RLC_AM_STATUS_CREATION
-          LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[SEND-STATUS] LINE %d ALL ACK WITH ACK_SN %04d\n",
-                PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
-                __LINE__,
-				rlc_pP->vr_ms);
-#endif
-  }
-  else if ((cursor_p != NULL) && ((nb_bits_transmitted + RLC_AM_SN_BITS + (RLC_AM_PDU_E_BITS << 1)) <= nb_bits_to_transmit)) {
-
-    pdu_info_cursor_p       = &((rlc_am_rx_pdu_management_t*)(cursor_p->data))->pdu_info;
+    control_pdu_info.ack_sn = rlc_pP->vr_ms;
+    status_report_completed = true;
+    LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[SEND-STATUS] LINE %d ALL ACK WITH ACK_SN %04d\n",
+          PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
+          __LINE__,
+          rlc_pP->vr_ms);
+  } else if ((cursor_p != NULL) && ((nb_bits_transmitted + RLC_AM_SN_BITS + (RLC_AM_PDU_E_BITS << 1)) <= nb_bits_to_transmit)) {
+    pdu_info_cursor_p       = &((rlc_am_rx_pdu_management_t *)(cursor_p->data))->pdu_info;
     sn_cursor             = pdu_info_cursor_p->sn;
-
     /* Set E1 bit for the presence of first NACK_SN/E1/E2 */
     control_pdu_info.e1 = 1;
 
     // 12 bits = size of NACK_SN field + E1, E2 bits
     // 42 bits = size of NACK_SN field + SO_START, SO_END fields, E1, E2 bits
     while ((!status_report_completed) && (RLC_AM_DIFF_SN(sn_nack,rlc_pP->vr_r) < RLC_AM_DIFF_SN(rlc_pP->vr_ms,rlc_pP->vr_r))
-    		&& (cursor_p != NULL) && (nb_bits_transmitted <= nb_bits_to_transmit)) {
-
-      pdu_info_cursor_p       = &((rlc_am_rx_pdu_management_t*)(cursor_p->data))->pdu_info;
+           && (cursor_p != NULL) && (nb_bits_transmitted <= nb_bits_to_transmit)) {
+      pdu_info_cursor_p       = &((rlc_am_rx_pdu_management_t *)(cursor_p->data))->pdu_info;
       sn_cursor             = pdu_info_cursor_p->sn;
-      all_segments_received = ((rlc_am_rx_pdu_management_t*)(cursor_p->data))->all_segments_received;
+      all_segments_received = ((rlc_am_rx_pdu_management_t *)(cursor_p->data))->all_segments_received;
 
       /* First fill NACK_SN with each missing PDU between current sn_nack and sn_cursor */
       while ((sn_nack != sn_cursor) && (RLC_AM_DIFF_SN(sn_nack,rlc_pP->vr_r) < RLC_AM_DIFF_SN(rlc_pP->vr_ms,rlc_pP->vr_r))) {
-    	  if (nb_bits_transmitted + RLC_AM_SN_BITS + (RLC_AM_PDU_E_BITS << 1) <= nb_bits_to_transmit) {
-    		  /* Fill NACK_SN infos */
-              control_pdu_info.nack_list[control_pdu_info.num_nack].nack_sn   = sn_nack;
-              control_pdu_info.nack_list[control_pdu_info.num_nack].so_start  = 0;
-              control_pdu_info.nack_list[control_pdu_info.num_nack].so_end    = RLC_AM_STATUS_PDU_SO_END_ALL_BYTES;
-              control_pdu_info.nack_list[control_pdu_info.num_nack].e2        = 0;
-              /* Set E1 for next NACK_SN. The last one will be cleared */
-              control_pdu_info.nack_list[control_pdu_info.num_nack].e1  = 1;
-              control_pdu_info.num_nack += 1;
-              nb_bits_transmitted += (RLC_AM_SN_BITS + (RLC_AM_PDU_E_BITS << 1));
-#if TRACE_RLC_AM_STATUS_CREATION
+        if (nb_bits_transmitted + RLC_AM_SN_BITS + (RLC_AM_PDU_E_BITS << 1) <= nb_bits_to_transmit) {
+          /* Fill NACK_SN infos */
+          control_pdu_info.nack_list[control_pdu_info.num_nack].nack_sn   = sn_nack;
+          control_pdu_info.nack_list[control_pdu_info.num_nack].so_start  = 0;
+          control_pdu_info.nack_list[control_pdu_info.num_nack].so_end    = RLC_AM_STATUS_PDU_SO_END_ALL_BYTES;
+          control_pdu_info.nack_list[control_pdu_info.num_nack].e2        = 0;
+          /* Set E1 for next NACK_SN. The last one will be cleared */
+          control_pdu_info.nack_list[control_pdu_info.num_nack].e1  = 1;
+          control_pdu_info.num_nack += 1;
+          nb_bits_transmitted += (RLC_AM_SN_BITS + (RLC_AM_PDU_E_BITS << 1));
           LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[SEND-STATUS] LINE %d PREPARE SENDING NACK %04d\n",
                 PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
                 __LINE__,
-				sn_nack);
-#endif
-    		  sn_nack = RLC_AM_NEXT_SN(sn_nack);
-    	  }
-    	  else {
-    		  /* Not enough UL TBS*/
-    		  /* latest value of sn_nack shall be used as ACK_SN */
-    		  control_pdu_info.ack_sn = sn_nack;
-    		  status_report_completed = true;
-#if TRACE_RLC_AM_STATUS_CREATION
+                sn_nack);
+          sn_nack = RLC_AM_NEXT_SN(sn_nack);
+        } else {
+          /* Not enough UL TBS*/
+          /* latest value of sn_nack shall be used as ACK_SN */
+          control_pdu_info.ack_sn = sn_nack;
+          status_report_completed = true;
           LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[SEND-STATUS] LINE %d NOT ENOUGH TBS STOP WITH ACK_SN %04d\n",
                 PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
                 __LINE__,
-				sn_nack);
-#endif
-    		  break;
-    	  }
+                sn_nack);
+          break;
+        }
       }
 
       if (sn_nack == rlc_pP->vr_ms) {
-    	  break;
+        break;
       }
 
       /* Now process all Segments of sn_cursor if PDU not fully received */
       if ((!status_report_completed) && (all_segments_received == 0) && (sn_cursor != rlc_pP->vr_ms)) {
-    	  //AssertFatal (sn_nack == sn_cursor, "RLC AM Tx Status PDU Data sn_nack=%d and sn_cursor=%d should be equal LcId=%d\n",sn_nack,sn_cursor, rlc_pP->channel_id);
-      	if(sn_nack != sn_cursor){
-      		LOG_E(RLC, "RLC AM Tx Status PDU Data sn_nack=%d and sn_cursor=%d should be equal LcId=%d\n",sn_nack,sn_cursor, rlc_pP->channel_id);
-      	}
-
-    	  /* First ensure there is enough TBS for at least 1 SOStart/SOEnd, else break */
+        //AssertFatal (sn_nack == sn_cursor, "RLC AM Tx Status PDU Data sn_nack=%d and sn_cursor=%d should be equal LcId=%d\n",sn_nack,sn_cursor, rlc_pP->channel_id);
+        if(sn_nack != sn_cursor) {
+          LOG_E(RLC, "RLC AM Tx Status PDU Data sn_nack=%d and sn_cursor=%d should be equal LcId=%d\n",sn_nack,sn_cursor, rlc_pP->channel_id);
+        }
+        /* First ensure there is enough TBS for at least 1 SOStart/SOEnd, else break */
         else if ((nb_bits_transmitted + RLC_AM_SN_BITS + (RLC_AM_PDU_E_BITS << 1) + (RLC_AM_STATUS_PDU_SO_LENGTH << 1)) <= nb_bits_to_transmit) {
-    		  /* Init loop flags */
+          /* Init loop flags */
+          /* Check lsf */
+          segment_loop_end = (pdu_info_cursor_p->lsf == 1);
+
+          /* Init first SO Start according to first segment */
+          if (pdu_info_cursor_p->so) {
+            /* Fill the first SO */
+            control_pdu_info.nack_list[control_pdu_info.num_nack].nack_sn   = sn_cursor;
+            control_pdu_info.nack_list[control_pdu_info.num_nack].so_start  = 0;
+            control_pdu_info.nack_list[control_pdu_info.num_nack].so_end    = pdu_info_cursor_p->so - 1;
+            control_pdu_info.nack_list[control_pdu_info.num_nack].e2        = 1;
+            /* Set E1 for next NACK_SN. The last one will be cleared */
+            control_pdu_info.nack_list[control_pdu_info.num_nack].e1  = 1;
+            control_pdu_info.num_nack += 1;
+            nb_bits_transmitted += (RLC_AM_SN_BITS + (RLC_AM_PDU_E_BITS << 1) + (RLC_AM_STATUS_PDU_SO_LENGTH << 1));
+            LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[SEND-STATUS] LINE %d PREPARE SENDING NACK %04d SO START %05d SO END %05d\n",
+                  PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
+                  __LINE__,
+                  sn_cursor,
+                  0,
+                  pdu_info_cursor_p->so - 1);
+            waited_so = pdu_info_cursor_p->so + pdu_info_cursor_p->payload_size;
+          } else {
+            waited_so = pdu_info_cursor_p->payload_size;
+          }
+
+          /* Go to next segment */
+          cursor_p = cursor_p->next;
+
+          if (cursor_p != NULL) {
+            pdu_info_cursor_p     = &((rlc_am_rx_pdu_management_t *)(cursor_p->data))->pdu_info;
+          }
+
+          /* Find the first discontinuity and then fill SOStart/SOEnd */
+          while (!segment_loop_end) {
+            if ((cursor_p != NULL) && (pdu_info_cursor_p->sn == sn_cursor)) {
+              /* PDU segment is for the same SN*/
               /* Check lsf */
-    		  segment_loop_end = (pdu_info_cursor_p->lsf == 1);
+              segment_loop_end = (pdu_info_cursor_p->lsf == 1);
 
-    		  /* Init first SO Start according to first segment */
-    		  if (pdu_info_cursor_p->so) {
-    			  /* Fill the first SO */
+              if (waited_so < pdu_info_cursor_p->so) {
+                /* SO is greater than previous received portion : gap identified to fill */
+                if ((nb_bits_transmitted + RLC_AM_SN_BITS + (RLC_AM_PDU_E_BITS << 1) + (RLC_AM_STATUS_PDU_SO_LENGTH << 1)) <= nb_bits_to_transmit) {
                   control_pdu_info.nack_list[control_pdu_info.num_nack].nack_sn   = sn_cursor;
-                  control_pdu_info.nack_list[control_pdu_info.num_nack].so_start  = 0;
+                  control_pdu_info.nack_list[control_pdu_info.num_nack].so_start  = waited_so;
                   control_pdu_info.nack_list[control_pdu_info.num_nack].so_end    = pdu_info_cursor_p->so - 1;
                   control_pdu_info.nack_list[control_pdu_info.num_nack].e2        = 1;
                   /* Set E1 for next NACK_SN. The last one will be cleared */
                   control_pdu_info.nack_list[control_pdu_info.num_nack].e1  = 1;
                   control_pdu_info.num_nack += 1;
                   nb_bits_transmitted += (RLC_AM_SN_BITS + (RLC_AM_PDU_E_BITS << 1) + (RLC_AM_STATUS_PDU_SO_LENGTH << 1));
-#if TRACE_RLC_AM_STATUS_CREATION
-            LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[SEND-STATUS] LINE %d PREPARE SENDING NACK %04d SO START %05d SO END %05d\n",
-                  PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
-                  __LINE__,
-				  sn_cursor,
-                  0,
-				  pdu_info_cursor_p->so - 1);
-#endif
-                  waited_so = pdu_info_cursor_p->so + pdu_info_cursor_p->payload_size;
-    		  }
-    		  else {
-        		  waited_so = pdu_info_cursor_p->payload_size;
-    		  }
+                  LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[SEND-STATUS] LINE %d PREPARE SENDING NACK %04d SO START %05d SO END %05d\n",
+                        PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
+                        __LINE__,
+                        sn_cursor,
+                        waited_so,
+                        pdu_info_cursor_p->so);
+                } else {
+                  /* Not enough resources to set a SOStart/SEnd, then set ACK_SN to current NACK_SN and stop Status PDU build */
+                  control_pdu_info.ack_sn = sn_cursor;
+                  status_report_completed = true;
+                  segment_loop_end = true;
+                  break;
+                }
+              } else {
+                /* contiguous segment: only update waited_so */
+                /* Assuming so and payload_size updated according to duplication removal done at reception ... */
+                waited_so += pdu_info_cursor_p->payload_size;
+              }
 
-              /* Go to next segment */
+              /* Go to next received PDU or PDU Segment */
               cursor_p = cursor_p->next;
-              if (cursor_p != NULL)
-              {
-                  pdu_info_cursor_p     = &((rlc_am_rx_pdu_management_t*)(cursor_p->data))->pdu_info;
+
+              if (cursor_p != NULL) {
+                pdu_info_cursor_p     = &((rlc_am_rx_pdu_management_t *)(cursor_p->data))->pdu_info;
+              }
+            } //end if (cursor_p != NULL) && (pdu_info_cursor_p->sn == sn_cursor)
+            else {
+              /* Previous PDU segment was the last one and did not have lsf indication : fill the latest gap */
+              if ((nb_bits_transmitted + RLC_AM_SN_BITS + (RLC_AM_PDU_E_BITS << 1) + (RLC_AM_STATUS_PDU_SO_LENGTH << 1)) <= nb_bits_to_transmit) {
+                control_pdu_info.nack_list[control_pdu_info.num_nack].nack_sn   = sn_cursor;
+                control_pdu_info.nack_list[control_pdu_info.num_nack].so_start  = waited_so;
+                control_pdu_info.nack_list[control_pdu_info.num_nack].so_end    = RLC_AM_STATUS_PDU_SO_END_ALL_BYTES;
+                control_pdu_info.nack_list[control_pdu_info.num_nack].e2        = 1;
+                /* Set E1 for next NACK_SN. The last one will be cleared */
+                control_pdu_info.nack_list[control_pdu_info.num_nack].e1  = 1;
+                control_pdu_info.num_nack += 1;
+                nb_bits_transmitted += (RLC_AM_SN_BITS + (RLC_AM_PDU_E_BITS << 1) + (RLC_AM_STATUS_PDU_SO_LENGTH << 1));
+                LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[SEND-STATUS] LINE %d PREPARE SENDING LAST NACK %04d SO START %05d SO END %05d\n",
+                      PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
+                      __LINE__,
+                      sn_cursor,
+                      waited_so,
+                      RLC_AM_STATUS_PDU_SO_END_ALL_BYTES);
+              } else {
+                /* Not enough resources to set a SOStart/SEnd, then set ACK_SN to current NACK_SN and stop Status PDU build */
+                control_pdu_info.ack_sn = sn_cursor;
+                status_report_completed = true;
               }
 
-    		  /* Find the first discontinuity and then fill SOStart/SOEnd */
-    		  while (!segment_loop_end) {
-    			  if ((cursor_p != NULL) && (pdu_info_cursor_p->sn == sn_cursor)) {
-
-					  /* PDU segment is for the same SN*/
-					  /* Check lsf */
-					  segment_loop_end = (pdu_info_cursor_p->lsf == 1);
-
-					  if (waited_so < pdu_info_cursor_p->so) {
-						  /* SO is greater than previous received portion : gap identified to fill */
-						  if ((nb_bits_transmitted + RLC_AM_SN_BITS + (RLC_AM_PDU_E_BITS << 1) + (RLC_AM_STATUS_PDU_SO_LENGTH << 1)) <= nb_bits_to_transmit) {
-							  control_pdu_info.nack_list[control_pdu_info.num_nack].nack_sn   = sn_cursor;
-							  control_pdu_info.nack_list[control_pdu_info.num_nack].so_start  = waited_so;
-							  control_pdu_info.nack_list[control_pdu_info.num_nack].so_end    = pdu_info_cursor_p->so - 1;
-							  control_pdu_info.nack_list[control_pdu_info.num_nack].e2        = 1;
-							  /* Set E1 for next NACK_SN. The last one will be cleared */
-							  control_pdu_info.nack_list[control_pdu_info.num_nack].e1  = 1;
-							  control_pdu_info.num_nack += 1;
-							  nb_bits_transmitted += (RLC_AM_SN_BITS + (RLC_AM_PDU_E_BITS << 1) + (RLC_AM_STATUS_PDU_SO_LENGTH << 1));
-#if TRACE_RLC_AM_STATUS_CREATION
-		LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[SEND-STATUS] LINE %d PREPARE SENDING NACK %04d SO START %05d SO END %05d\n",
-			  PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
-			  __LINE__,
-			  sn_cursor,
-			  waited_so,
-			  pdu_info_cursor_p->so);
-#endif
-						  }
-						  else {
-							  /* Not enough resources to set a SOStart/SEnd, then set ACK_SN to current NACK_SN and stop Status PDU build */
-							  control_pdu_info.ack_sn = sn_cursor;
-							  status_report_completed = true;
-							  segment_loop_end = true;
-							  break;
-						  }
-					  }
-					  else {
-						  /* contiguous segment: only update waited_so */
-						  /* Assuming so and payload_size updated according to duplication removal done at reception ... */
-						  waited_so += pdu_info_cursor_p->payload_size;
-					  }
-
-					  /* Go to next received PDU or PDU Segment */
-					  cursor_p = cursor_p->next;
-	                  if (cursor_p != NULL)
-	                  {
-		                  pdu_info_cursor_p     = &((rlc_am_rx_pdu_management_t*)(cursor_p->data))->pdu_info;
-	                  }
-
-    			  } //end if (cursor_p != NULL) && (pdu_info_cursor_p->sn == sn_cursor)
-    			  else {
-    				  /* Previous PDU segment was the last one and did not have lsf indication : fill the latest gap */
-    		    	  if ((nb_bits_transmitted + RLC_AM_SN_BITS + (RLC_AM_PDU_E_BITS << 1) + (RLC_AM_STATUS_PDU_SO_LENGTH << 1)) <= nb_bits_to_transmit) {
-    	                      control_pdu_info.nack_list[control_pdu_info.num_nack].nack_sn   = sn_cursor;
-    	                      control_pdu_info.nack_list[control_pdu_info.num_nack].so_start  = waited_so;
-    	                      control_pdu_info.nack_list[control_pdu_info.num_nack].so_end    = RLC_AM_STATUS_PDU_SO_END_ALL_BYTES;
-    	                      control_pdu_info.nack_list[control_pdu_info.num_nack].e2        = 1;
-    	                      /* Set E1 for next NACK_SN. The last one will be cleared */
-    	                      control_pdu_info.nack_list[control_pdu_info.num_nack].e1  = 1;
-    	                      control_pdu_info.num_nack += 1;
-    	                      nb_bits_transmitted += (RLC_AM_SN_BITS + (RLC_AM_PDU_E_BITS << 1) + (RLC_AM_STATUS_PDU_SO_LENGTH << 1));
-#if TRACE_RLC_AM_STATUS_CREATION
-            LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[SEND-STATUS] LINE %d PREPARE SENDING LAST NACK %04d SO START %05d SO END %05d\n",
-                  PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
-                  __LINE__,
-				  sn_cursor,
-				  waited_so,
-				  RLC_AM_STATUS_PDU_SO_END_ALL_BYTES);
-#endif
-     		    	  }
-    		    	  else {
-    		    		  /* Not enough resources to set a SOStart/SEnd, then set ACK_SN to current NACK_SN and stop Status PDU build */
-    		    		  control_pdu_info.ack_sn = sn_cursor;
-    		    		  status_report_completed = true;
-    		    	  }
-
-    		    	  segment_loop_end = true;
-    			  }
-    		  } //end  while (!segment_loop_end)
-    	  } // end if enough resource for transmitting at least one SOStart/SOEnd
-    	  else {
-    		  /* Not enough UL TBS to set at least one SOStart/SOEnd */
-    		  /* latest value of sn_nack shall be used as ACK_SN */
-    		  control_pdu_info.ack_sn = sn_nack;
-    		  status_report_completed = true;
-    	  }
+              segment_loop_end = true;
+            }
+          } //end  while (!segment_loop_end)
+        } // end if enough resource for transmitting at least one SOStart/SOEnd
+        else {
+          /* Not enough UL TBS to set at least one SOStart/SOEnd */
+          /* latest value of sn_nack shall be used as ACK_SN */
+          control_pdu_info.ack_sn = sn_nack;
+          status_report_completed = true;
+        }
       } // end while on all PDU segments of sn_cursor
       else {
-    	  /* Go to next received PDU or PDU segment with different SN */
-    	  do {
-    		  	  cursor_p = cursor_p->next;
-    	  	  } while ((cursor_p != NULL) && (((rlc_am_rx_pdu_management_t*)(cursor_p->data))->pdu_info.sn == sn_cursor));
+        /* Go to next received PDU or PDU segment with different SN */
+        do {
+          cursor_p = cursor_p->next;
+        } while ((cursor_p != NULL) && (((rlc_am_rx_pdu_management_t *)(cursor_p->data))->pdu_info.sn == sn_cursor));
       }
 
       /* Increment sn_nack except if sn_cursor = vrMS and if current SN was not fully received */
       if (RLC_AM_DIFF_SN(sn_cursor,rlc_pP->vr_r) < RLC_AM_DIFF_SN(rlc_pP->vr_ms,rlc_pP->vr_r)) {
-    	  sn_nack = RLC_AM_NEXT_SN(sn_cursor);
-      }
-      else {
-    	  sn_nack = rlc_pP->vr_ms;
+        sn_nack = RLC_AM_NEXT_SN(sn_cursor);
+      } else {
+        sn_nack = rlc_pP->vr_ms;
       }
-
-
     } // End main while NACK_SN
 
     /* Clear E1 of last nack_sn entry */
-//	AssertFatal ((control_pdu_info.num_nack) || (all_segments_received == 0), "RLC AM Tx Status PDU Data Error no NACK_SN vrR=%d vrMS=%d lastSN_NACK=%d Completed=%d NbBytesAvailable=%d LcId=%d\n",
-//	        rlc_pP->vr_r,rlc_pP->vr_ms,sn_nack,status_report_completed,(nb_bits_to_transmit >> 3),rlc_pP->channel_id);
-  	if (!((control_pdu_info.num_nack) || (all_segments_received == 0))){
-  		LOG_E(RLC, "RLC AM Tx Status PDU Data Error no NACK_SN vrR=%d vrMS=%d lastSN_NACK=%d Completed=%d NbBytesAvailable=%d LcId=%d\n",
-		        rlc_pP->vr_r,rlc_pP->vr_ms,sn_nack,status_report_completed,(nb_bits_to_transmit >> 3),rlc_pP->channel_id);
-  		return;
-  	}
-  	
-	if (control_pdu_info.num_nack) {
-	    control_pdu_info.nack_list[control_pdu_info.num_nack - 1].e1  = 0;
-	}
+    //  AssertFatal ((control_pdu_info.num_nack) || (all_segments_received == 0), "RLC AM Tx Status PDU Data Error no NACK_SN vrR=%d vrMS=%d lastSN_NACK=%d Completed=%d NbBytesAvailable=%d LcId=%d\n",
+    //          rlc_pP->vr_r,rlc_pP->vr_ms,sn_nack,status_report_completed,(nb_bits_to_transmit >> 3),rlc_pP->channel_id);
+    if (!((control_pdu_info.num_nack) || (all_segments_received == 0))) {
+      LOG_E(RLC, "RLC AM Tx Status PDU Data Error no NACK_SN vrR=%d vrMS=%d lastSN_NACK=%d Completed=%d NbBytesAvailable=%d LcId=%d\n",
+            rlc_pP->vr_r,rlc_pP->vr_ms,sn_nack,status_report_completed,(nb_bits_to_transmit >> 3),rlc_pP->channel_id);
+      return;
+    }
 
+    if (control_pdu_info.num_nack) {
+      control_pdu_info.nack_list[control_pdu_info.num_nack - 1].e1  = 0;
+    }
 
     /* Set ACK_SN unless it was set before */
-    if (!status_report_completed){
-
-    	control_pdu_info.ack_sn = sn_nack;
+    if (!status_report_completed) {
+      control_pdu_info.ack_sn = sn_nack;
     }
-
   } else {
-	/* reception buffer empty or not enough TBS for filling at least 1 NACK_SN + E1 + E2 */
+    /* reception buffer empty or not enough TBS for filling at least 1 NACK_SN + E1 + E2 */
     control_pdu_info.ack_sn = rlc_pP->vr_r;
-#if TRACE_RLC_AM_STATUS_CREATION
     LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[SEND-STATUS] LINE %d PREPARE SENDING ACK %04d  = VR(R)\n",
           PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
           __LINE__,
           control_pdu_info.ack_sn);
-#endif
   }
 
-
   //msg ("[FRAME %5u][%s][RLC_AM][MOD %u/%u][RB %u] nb_bits_to_transmit %d\n",
   //     rlc_pP->module_id, rlc_pP->rb_id, ctxt_pP->frame,nb_bits_to_transmit);
-
-#if TRACE_RLC_AM_STATUS_CREATION
   LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[SEND-STATUS] LINE %d PREPARE SENDING ACK %04d NUM NACK %d\n",
         PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
         __LINE__,
         control_pdu_info.ack_sn,
         control_pdu_info.num_nack);
-#endif
-
-
   /* encode the control pdu */
   pdu_size = (nb_bits_transmitted + 7) >> 3;
-//  AssertFatal (pdu_size <= rlc_pP->nb_bytes_requested_by_mac, "RLC AM Tx Status PDU Data size=%d bigger than remaining TBS=%d nb_bits_transmitted=%d LcId=%d\n",
-//		  pdu_size,rlc_pP->nb_bytes_requested_by_mac,nb_bits_transmitted, rlc_pP->channel_id);
-	if(pdu_size > rlc_pP->nb_bytes_requested_by_mac){
-		LOG_E(RLC, "RLC AM Tx Status PDU Data size=%d bigger than remaining TBS=%d nb_bits_transmitted=%d LcId=%d\n",
-		  pdu_size,rlc_pP->nb_bytes_requested_by_mac,nb_bits_transmitted, rlc_pP->channel_id);
-		return;
-	}
 
+  //  AssertFatal (pdu_size <= rlc_pP->nb_bytes_requested_by_mac, "RLC AM Tx Status PDU Data size=%d bigger than remaining TBS=%d nb_bits_transmitted=%d LcId=%d\n",
+  //      pdu_size,rlc_pP->nb_bytes_requested_by_mac,nb_bits_transmitted, rlc_pP->channel_id);
+  if(pdu_size > rlc_pP->nb_bytes_requested_by_mac) {
+    LOG_E(RLC, "RLC AM Tx Status PDU Data size=%d bigger than remaining TBS=%d nb_bits_transmitted=%d LcId=%d\n",
+          pdu_size,rlc_pP->nb_bytes_requested_by_mac,nb_bits_transmitted, rlc_pP->channel_id);
+    return;
+  }
 
-#if TRACE_RLC_AM_STATUS_CREATION
   LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[SEND-STATUS] LINE %d forecast pdu_size %d\n",
         PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
         __LINE__,
         pdu_size);
-#endif
   tb_p = get_free_mem_block(sizeof(struct mac_tb_req) + pdu_size, __func__);
+
   if(tb_p == NULL) return;
+
   memset(tb_p->data, 0, sizeof(struct mac_tb_req) + pdu_size);
   //estimation only ((struct mac_tb_req*)(tb_p->data))->tb_size  = pdu_size;
-  ((struct mac_tb_req*)(tb_p->data))->data_ptr         = (uint8_t*)&(tb_p->data[sizeof(struct mac_tb_req)]);
-
+  ((struct mac_tb_req *)(tb_p->data))->data_ptr         = (uint8_t *)&(tb_p->data[sizeof(struct mac_tb_req)]);
   // warning reuse of pdu_size
   // TODO : rlc_am_write_status_pdu should be rewritten as not very tested ...
-  pdu_size = rlc_am_write_status_pdu(ctxt_pP, rlc_pP,(rlc_am_pdu_sn_10_t*)(((struct mac_tb_req*)(tb_p->data))->data_ptr), &control_pdu_info);
-  ((struct mac_tb_req*)(tb_p->data))->tb_size  = pdu_size;
+  pdu_size = rlc_am_write_status_pdu(ctxt_pP, rlc_pP,(rlc_am_pdu_sn_10_t *)(((struct mac_tb_req *)(tb_p->data))->data_ptr), &control_pdu_info);
+  ((struct mac_tb_req *)(tb_p->data))->tb_size  = pdu_size;
   //assert((((struct mac_tb_req*)(tb_p->data))->tb_size) < 3000);
-
-#if TRACE_RLC_AM_STATUS_CREATION
   LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[SEND-STATUS] SEND STATUS PDU SIZE %d, rlc_pP->nb_bytes_requested_by_mac %d, nb_bits_to_transmit>>3 %d\n",
         PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
         pdu_size,
         rlc_pP->nb_bytes_requested_by_mac,
         nb_bits_to_transmit >> 3);
-#endif
 
-//  AssertFatal (pdu_size == ((nb_bits_transmitted + 7) >> 3), "RLC AM Tx Status PDU Data encoding size=%d different than expected=%d LcId=%d\n",
-//  		  pdu_size,((nb_bits_transmitted + 7) >> 3), rlc_pP->channel_id);
-	if(pdu_size != ((nb_bits_transmitted + 7) >> 3)){
-		LOG_E(RLC, "RLC AM Tx Status PDU Data encoding size=%d different than expected=%d LcId=%d\n",
-  		  pdu_size,((nb_bits_transmitted + 7) >> 3), rlc_pP->channel_id);
-		pdu_size = 0;
-		return;
-	}
+  //  AssertFatal (pdu_size == ((nb_bits_transmitted + 7) >> 3), "RLC AM Tx Status PDU Data encoding size=%d different than expected=%d LcId=%d\n",
+  //        pdu_size,((nb_bits_transmitted + 7) >> 3), rlc_pP->channel_id);
+  if(pdu_size != ((nb_bits_transmitted + 7) >> 3)) {
+    LOG_E(RLC, "RLC AM Tx Status PDU Data encoding size=%d different than expected=%d LcId=%d\n",
+          pdu_size,((nb_bits_transmitted + 7) >> 3), rlc_pP->channel_id);
+    pdu_size = 0;
+    return;
+  }
 
   // remaining bytes to transmit for RLC (retrans pdus and new data pdus)
   rlc_pP->nb_bytes_requested_by_mac = rlc_pP->nb_bytes_requested_by_mac - pdu_size;
@@ -869,7 +761,6 @@ rlc_am_send_status_pdu(
   list_add_head(tb_p, &rlc_pP->control_pdu_list);
   rlc_pP->stat_tx_control_pdu   += 1;
   rlc_pP->stat_tx_control_bytes += pdu_size;
-
 }
 
 
diff --git a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_test.c b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_test.c
index d9eb6de7cccf4c1de70f3d19ca42e466bb7ef23e..7a95a62787a58c65e114ca76bf4723e2c9c15ade 100644
--- a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_test.c
+++ b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_test.c
@@ -128,6 +128,8 @@ void rlc_am_v9_3_0_test_windows()
   rlc_am_entity_t am2;
   unsigned int    i;
   unsigned int    j;
+  memset(am1,0,sizeof(rlc_am_entity_t));
+  memset(am2,0,sizeof(rlc_am_entity_t));
 
   rlc_am_init(&am1, g_frame);
   rlc_am_init(&am2, g_frame);
@@ -215,19 +217,16 @@ void rlc_am_v9_3_0_test_windows()
       assert(rlc_am_in_rx_window(&am1, i) == 0);
     }
   }
-
 }
 //-----------------------------------------------------------------------------
 void rlc_am_v9_3_0_test_read_write_bit_field()
 //-----------------------------------------------------------------------------
 {
   unsigned int bit_pos_write       = 0; // range from 0 (MSB/left) to 7 (LSB/right)
-  uint8_t*        byte_pos_write      = g_buffer;
-
+  uint8_t        *byte_pos_write      = g_buffer;
   unsigned int bit_pos_read       = 0; // range from 0 (MSB/left) to 7 (LSB/right)
-  uint8_t*        byte_pos_read      = g_buffer;
+  uint8_t        *byte_pos_read      = g_buffer;
   uint16_t        read_value;
-
   memset (g_buffer, 0, sizeof(g_buffer));
   // byte 0
   rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 1);
@@ -240,7 +239,6 @@ void rlc_am_v9_3_0_test_read_write_bit_field()
   rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 0);
   assert(g_buffer[0] == 0x96);
   assert(g_buffer[1] == 0x00);
-
   // byte 1
   rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 1);
   rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 1);
@@ -251,10 +249,8 @@ void rlc_am_v9_3_0_test_read_write_bit_field()
   rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 0);
   rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 1);
   assert(g_buffer[0] == 0x96);
-
   assert(g_buffer[1] == 0xD9);
   assert(g_buffer[2] == 0x00);
-
   // byte 2
   rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 0);
   rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 0);
@@ -266,7 +262,6 @@ void rlc_am_v9_3_0_test_read_write_bit_field()
   rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 1);
   assert(g_buffer[0] == 0x96);
   assert(g_buffer[1] == 0xD9);
-
   assert(g_buffer[2] == 0x11);
   assert(g_buffer[3] == 0x00);
   // byte 3 & 4
@@ -282,7 +277,6 @@ void rlc_am_v9_3_0_test_read_write_bit_field()
   assert(g_buffer[0] == 0x96);
   assert(g_buffer[1] == 0xD9);
   assert(g_buffer[2] == 0x11);
-
   assert(g_buffer[3] == 0x99);
   assert(g_buffer[4] == 0xA7);
   assert(g_buffer[5] == 0x00);
@@ -298,7 +292,6 @@ void rlc_am_v9_3_0_test_read_write_bit_field()
   assert(g_buffer[2] == 0x11);
   assert(g_buffer[3] == 0x99);
   assert(g_buffer[4] == 0xA7);
-
   assert(g_buffer[5] == 0xF4);
   assert(g_buffer[6] == 0x86);
   assert(g_buffer[7] == 0x00);
@@ -317,7 +310,6 @@ void rlc_am_v9_3_0_test_read_write_bit_field()
   assert(g_buffer[4] == 0xA7);
   assert(g_buffer[5] == 0xF4);
   assert(g_buffer[6] == 0x86);
-
   assert(g_buffer[7] == 0xCD);
   assert(g_buffer[8] == 0x7D);
   assert(g_buffer[9] == 0x58);
@@ -337,7 +329,6 @@ void rlc_am_v9_3_0_test_read_write_bit_field()
   assert(g_buffer[7]  == 0xCD);
   assert(g_buffer[8]  == 0x7D);
   assert(g_buffer[9]  == 0x58);
-
   assert(g_buffer[10] == 0xAA);
   assert(g_buffer[11] == 0xDB);
   assert(g_buffer[12] == 0xAA);
@@ -368,7 +359,6 @@ void rlc_am_v9_3_0_test_read_write_bit_field()
   assert(g_buffer[12] == 0xAA);
   assert(g_buffer[13] == 0xBD);
   assert(g_buffer[14] == 0x34);
-
   assert(g_buffer[15] == 0xE0);
   assert(g_buffer[16] == 0x3F);
   assert(g_buffer[17] == 0x84);
@@ -385,7 +375,6 @@ void rlc_am_v9_3_0_test_read_write_bit_field()
   assert(g_buffer[28] == 0x87);
   assert(g_buffer[29] == 0x88);
   assert(g_buffer[30] == 0x00);
-
   // 0x96 0xD9
   read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 1);// b0
   assert(read_value == 1);
@@ -419,7 +408,6 @@ void rlc_am_v9_3_0_test_read_write_bit_field()
   assert(read_value == 0);
   read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 1);// b15
   assert(read_value == 1);
-
   //  0x11 0x99
   read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 2);
   assert(read_value == 0);
@@ -439,7 +427,6 @@ void rlc_am_v9_3_0_test_read_write_bit_field()
   assert(read_value == 2);
   read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 2);
   assert(read_value == 1);
-
   //  0xA7 0xF4 0x86 0xCD 0x7D;
   read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 10);
   assert(read_value == 0x29F);
@@ -449,10 +436,8 @@ void rlc_am_v9_3_0_test_read_write_bit_field()
   assert(read_value == 0x1B3);
   read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 10);
   assert(read_value == 0x17D);
-
   //  0x58 0xAA 0xDB 0xAA 0xBD 0x34
   //  0xE0 0x3F 0x84 0xBA 0x91 0xEC
-
   read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 1);
   assert(read_value == 0);
   read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 10);
@@ -475,7 +460,6 @@ void rlc_am_v9_3_0_test_read_write_bit_field()
   assert(read_value == 0x2EA);
   read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 10);
   assert(read_value == 0x11E);
-
   bit_pos_read  = 0;
   byte_pos_read = g_buffer;
   // 0x96 0xD9 0x11 0x99 0xA7 0xF4 0x86 0xCD 0x7D 0x58 0xAA 0xDB 0xAA 0xBD 0x34
@@ -523,30 +507,24 @@ void rlc_am_v9_3_0_test_send_sdu(rlc_am_entity_t *am_txP, int sdu_indexP)
     printf("[FRAME %05d][RLC][MOD %02d][RB %02d] TX SDU %d %04d bytes\n",g_frame,am_txP->module_id, am_txP->rb_id, sdu_indexP, strlen(g_sdus[sdu_indexP]) + 1);
     memset (sdu->data, 0, sizeof (struct rlc_am_data_req_alloc));
     strcpy (&sdu->data[sizeof (struct rlc_am_data_req_alloc)],g_sdus[sdu_indexP]);
-
     ((struct rlc_am_data_req *) (sdu->data))->data_size = strlen(g_sdus[sdu_indexP])+ 1;
     ((struct rlc_am_data_req *) (sdu->data))->conf = 1;
     ((struct rlc_am_data_req *) (sdu->data))->mui  = g_mui++;
     ((struct rlc_am_data_req *) (sdu->data))->data_offset = sizeof (struct rlc_am_data_req_alloc);
     rlc_am_data_req(am_txP, g_frame, sdu);
-
     g_send_sdu_ids[g_send_id_write_index[am_txP->rb_id]++][am_txP->rb_id] = sdu_indexP;
     assert(g_send_id_write_index[am_txP->rb_id] < TEST_MAX_SEND_SDU);
   } else {
     printf("Out of memory error\n");
-//    exit(-1);
+    //    exit(-1);
   }
 }
 //-----------------------------------------------------------------------------
-void rlc_am_v9_3_0_test_mac_rlc_loop (struct mac_data_ind *data_indP,  struct mac_data_req *data_requestP, int* drop_countP, int *tx_packetsP,
-                                      int* dropped_tx_packetsP) //-----------------------------------------------------------------------------
-{
-
-
-  mem_block_t* tb_src;
-  mem_block_t* tb_dst;
+void rlc_am_v9_3_0_test_mac_rlc_loop (struct mac_data_ind *data_indP,  struct mac_data_req *data_requestP, int *drop_countP, int *tx_packetsP,
+                                      int *dropped_tx_packetsP) { //-----------------------------------------------------------------------------
+  mem_block_t *tb_src;
+  mem_block_t *tb_dst;
   unsigned int tb_size;
-
   data_indP->no_tb = 0;
 
   while (data_requestP->data.nb_elements > 0) {
@@ -554,10 +532,9 @@ void rlc_am_v9_3_0_test_mac_rlc_loop (struct mac_data_ind *data_indP,  struct ma
 
     if (tb_src != NULL) {
       tb_size = ((struct mac_tb_req *) (tb_src->data))->tb_size_in_bits >> 3;
-      printf("[RLC-LOOP] FOUND TB SIZE IN BITS %d IN BYTES %d sizeof (mac_rlc_max_rx_header_size_t) %d\n",
+      printf("[RLC-LOOP] FOUND TB SIZE IN BITS %d IN BYTES %u sizeof (mac_rlc_max_rx_header_size_t) %d\n",
              ((struct mac_tb_req *) (tb_src->data))->tb_size_in_bits,
              tb_size, sizeof (mac_rlc_max_rx_header_size_t));
-
       *tx_packetsP = *tx_packetsP + 1;
 
       if (*drop_countP == 0) {
@@ -568,16 +545,14 @@ void rlc_am_v9_3_0_test_mac_rlc_loop (struct mac_data_ind *data_indP,  struct ma
           ((struct mac_tb_ind *) (tb_dst->data))->data_ptr         = &tb_dst->data[sizeof (mac_rlc_max_rx_header_size_t)];
           ((struct mac_tb_ind *) (tb_dst->data))->size             = tb_size;
           ((struct mac_tb_ind *) (tb_dst->data))->error_indication = 0;
-
           memcpy(((struct mac_tb_ind *) (tb_dst->data))->data_ptr,
                  &((struct mac_tb_req *) (tb_src->data))->data_ptr[0],
                  tb_size);
-
           list_add_tail_eurecom(tb_dst, &data_indP->data);
           data_indP->no_tb  += 1;
         } else {
           printf("Out of memory error\n");
-//          exit(-1);
+          //          exit(-1);
         }
       } else {
         printf("[RLC-LOOP] DROPPING 1 TB\n");
@@ -607,8 +582,6 @@ void rlc_am_v9_3_0_test_exchange_pdus(rlc_am_entity_t *am_txP,
   struct mac_status_ind  tx_status;
   struct mac_status_resp mac_rlc_status_resp_tx;
   struct mac_status_resp mac_rlc_status_resp_rx;
-
-
   memset(&data_request_tx, 0, sizeof(struct mac_data_req));
   memset(&data_request_rx, 0, sizeof(struct mac_data_req));
   memset(&data_ind_tx,     0, sizeof(struct mac_data_ind));
@@ -616,19 +589,15 @@ void rlc_am_v9_3_0_test_exchange_pdus(rlc_am_entity_t *am_txP,
   memset(&tx_status,       0, sizeof(struct mac_status_ind));
   memset(&mac_rlc_status_resp_tx, 0, sizeof(struct mac_status_resp));
   memset(&mac_rlc_status_resp_rx, 0, sizeof(struct mac_status_resp));
-
   mac_rlc_status_resp_tx = rlc_am_mac_status_indication(am_txP, g_frame, bytes_txP, tx_status);
   data_request_tx        = rlc_am_mac_data_request(am_txP, g_frame);
   mac_rlc_status_resp_rx = rlc_am_mac_status_indication(am_rxP, g_frame, bytes_rxP, tx_status);
   data_request_rx        = rlc_am_mac_data_request(am_rxP, g_frame);
-
-
   rlc_am_v9_3_0_test_mac_rlc_loop(&data_ind_rx, &data_request_tx, &g_drop_tx, &g_tx_packets, &g_dropped_tx_packets);
   rlc_am_v9_3_0_test_mac_rlc_loop(&data_ind_tx, &data_request_rx, &g_drop_rx, &g_rx_packets, &g_dropped_rx_packets);
   rlc_am_mac_data_indication(am_rxP, g_frame, am_txP->is_enb, data_ind_rx);
   rlc_am_mac_data_indication(am_txP, g_frame, am_txP->is_enb, data_ind_tx);
   g_frame += 1;
-
   //rlc_am_tx_buffer_display(am_txP,NULL);
   //assert(am_txP->t_status_prohibit.time_out != 1);
   //assert(am_rxP->t_status_prohibit.time_out != 1);
@@ -660,14 +629,12 @@ void rlc_am_v9_3_0_test_data_ind (module_id_t module_idP, rb_id_t rb_idP, sdu_si
       assert(g_send_id_write_index[rb_idP^1] > g_send_id_read_index[rb_idP]);
 
       if (g_send_sdu_ids[g_send_id_read_index[rb_idP]][rb_idP^1] != i) {
-
         printf("[FRAME %05d][RLC][MOD %d][RB %d][DATA-IND] g_send_sdu_ids[%d] = %d\n",g_frame,module_idP, rb_idP,  g_send_id_read_index[rb_idP]-2,
                g_send_sdu_ids[g_send_id_read_index[rb_idP]-2][rb_idP^1]);
         printf("[FRAME %05d][RLC][MOD %d][RB %d][DATA-IND] g_send_sdu_ids[%d] = %d\n",g_frame,module_idP, rb_idP,  g_send_id_read_index[rb_idP]-1,
                g_send_sdu_ids[g_send_id_read_index[rb_idP]-1][rb_idP^1]);
         printf("[FRAME %05d][RLC][MOD %d][RB %d][DATA-IND] g_send_sdu_ids[%d] = %d\n",g_frame,module_idP, rb_idP,  g_send_id_read_index[rb_idP],
                g_send_sdu_ids[g_send_id_read_index[rb_idP]][rb_idP^1]);
-
         printf("[FRAME %05d][RLC][MOD %d][RB %d][DATA-IND] g_send_id_read_index = %d sdu sent = %d\n",g_frame,module_idP, rb_idP,  g_send_id_read_index[rb_idP], i);
       }
 
@@ -693,17 +660,13 @@ void rlc_am_v9_3_0_test_tx_rx()
   uint32_t                 t_reordering       = 5000;
   uint32_t                 t_status_prohibit  = 10;
   int                   i,j,r;
-
   srand (0);
-
   rlc_am_init(&g_am_tx, g_frame);
   rlc_am_init(&g_am_rx, g_frame);
   rlc_am_set_debug_infos(&g_am_tx, g_frame, 0, 0, 0, 1, 1 /* LC-id = DRB-id */);
   rlc_am_set_debug_infos(&g_am_rx, g_frame, 1, 1, 1, 1, 1 /* LC-id = DRB-id */);
-
   rlc_am_configure(&g_am_tx, g_frame, max_retx_threshold, poll_pdu, poll_byte, t_poll_retransmit, t_reordering, t_status_prohibit);
   rlc_am_configure(&g_am_rx, g_frame, max_retx_threshold, poll_pdu, poll_byte, t_poll_retransmit, t_reordering, t_status_prohibit);
-
 #ifdef TEST1
   srand (0);
   rlc_am_v9_3_0_test_reset_sdus();
@@ -730,7 +693,6 @@ void rlc_am_v9_3_0_test_tx_rx()
   rlc_am_rx_list_display(&g_am_rx, "RLC-AM RX:");
   assert (g_send_id_read_index[1] == g_send_id_write_index[0]);
   printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_am_v9_3_0_test 1: END OF SIMPLE TEST SEVERAL SDUs IN PDU\n\n\n\n");
-
   rlc_am_v9_3_0_test_reset_sdus();
 
   // RANDOM TESTS
@@ -800,7 +762,6 @@ void rlc_am_v9_3_0_test_tx_rx()
   rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 2000, 200);
   rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 2000, 200);
   rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 2000, 200);
-
   rlc_am_v9_3_0_test_send_sdu(&g_am_tx, 1);
   rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 30, 200);
   rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 31, 200);
@@ -957,7 +918,6 @@ void rlc_am_v9_3_0_test_tx_rx()
   rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);
   rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);
   rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);
-
   t_poll_retransmit = 6;
   rlc_am_configure(&g_am_tx, g_frame, max_retx_threshold, poll_pdu, poll_byte, t_poll_retransmit, t_reordering, t_status_prohibit);
 
@@ -1178,7 +1138,6 @@ void rlc_am_v9_3_0_test_tx_rx()
         assert (g_send_id_read_index[0] == g_send_id_write_index[1]);
         printf("REAL BLER TX=%d (TARGET=%d) BLER RX=%d (TARGET=%d) \n",(g_dropped_tx_packets*100)/g_tx_packets, g_target_tx_error_rate,
                (g_dropped_rx_packets*100)/g_rx_packets, g_target_rx_error_rate);
-
       }
     }
 
@@ -1193,11 +1152,10 @@ void rlc_am_v9_3_0_test_print_trace (void)
   size_t size;
   char **strings;
   size_t i;
-
   size = backtrace (array, 100);
   strings = backtrace_symbols (array, size);
+  printf ("Obtained %lu stack frames.\n", (unsigned long)size);
 
-  printf ("Obtained %d stack frames.\n", size);
 
   for (i = 0; i < size; i++) {
     printf ("%s\n", strings[i]);
@@ -1213,15 +1171,10 @@ void rlc_am_v9_3_0_test(void)
   //     initscr();
   //     cbreak();
   //     keypad(stdscr, TRUE);
-
-
-
   // under test
   pool_buffer_init();
   set_comp_log(RLC, LOG_ERR, LOG_MED, 1);
-
   rlc_am_v9_3_0_test_tx_rx();
-
   // already tested
   rlc_am_v9_3_0_test_windows();
   rlc_am_v9_3_0_test_read_write_bit_field();
diff --git a/openair2/LAYER2/RLC/UM_v9.3.0/Makefile b/openair2/LAYER2/RLC/UM_v9.3.0/Makefile
deleted file mode 100644
index 2d56c809cb98d638b7ba36997f7d69912e33b110..0000000000000000000000000000000000000000
--- a/openair2/LAYER2/RLC/UM_v9.3.0/Makefile
+++ /dev/null
@@ -1,49 +0,0 @@
-CFLAGS +=  -I$(RLC_DIR)
-CFLAGS +=  -I$(RLC_UM_DIR)
-CFLAGS +=  -I$(RLC_AM_DIR)
-CFLAGS +=  -I$(COMMON_DIR)
-CFLAGS +=  -I$(TRACE_DIR)
-CFLAGS +=  -I$(LISTS_DIR)
-CFLAGS +=  -I$(MEM_DIR)
-
-DEBUG_FLAGS += -O2
-
-OBJ = rlc_um.o rlc_um_segment.o 
-
-
-############################################################
-#
-# The following should be identical in all Makefiles
-#
-#define the target object files
-
-ifdef TARGETDIR
-	TARGETOBJ = $(addprefix ${TARGETDIR}/, ${OBJ})
-	TARGETLIB = ${TARGETDIR}/Lib.a
-endif
-
-include $(TARGETOBJ:.o=.d)
-
-# Look for source files in the parent directory
-%.o: ../%.c %.d
-	$(CCC) -c ${DEBUG_FLAGS} ${CFLAGS} ${INCLUDE} -o $@ $<
-
-# Rule to remake and keep the .d dependency Makefiles
-# Note that the sed command includes adding the TARGETDIR
-#  and that ! is used for s delimiter
-%.d: ../%.c
-	$(SHELL) -ec '$(CCC) -MM $(CFLAGS) $< \
-	| sed '\''s!\($(*F)\)\.o[ :]*!$(TARGETDIR)/\1.o $@ : !g'\'' > $@ ;\
-	[ -s $@ ] || rm -f $@'
-.PRECIOUS: %.d
-
-all: ${TARGETLIB}
-
-${TARGETLIB}: ${TARGETOBJ}
-	ar -rv ${TARGETLIB} ${TARGETOBJ}
-
-clean:
-	rm -f ${TARGETDIR}/*.o ${TARGETDIR}/*.a
-
-clean_dep:
-	rm -f ${TARGETDIR}/*.d
diff --git a/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um.c b/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um.c
index f04fd6681935ddadc08b6f63c832436357984d16..b59a6025f51bc2e3748e65355293af5bc4eb0eae 100644
--- a/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um.c
+++ b/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um.c
@@ -27,7 +27,7 @@
 #include "platform_constants.h"
 //-----------------------------------------------------------------------------
 #if ENABLE_ITTI
-# include "intertask_interface.h"
+  #include "intertask_interface.h"
 #endif
 #include "assertions.h"
 #include "msc.h"
@@ -43,24 +43,23 @@
 
 //-----------------------------------------------------------------------------
 void rlc_um_stat_req     (rlc_um_entity_t *rlc_pP,
-                          unsigned int* stat_tx_pdcp_sdu,
-                          unsigned int* stat_tx_pdcp_bytes,
-                          unsigned int* stat_tx_pdcp_sdu_discarded,
-                          unsigned int* stat_tx_pdcp_bytes_discarded,
-                          unsigned int* stat_tx_data_pdu,
-                          unsigned int* stat_tx_data_bytes,
-                          unsigned int* stat_rx_pdcp_sdu,
-                          unsigned int* stat_rx_pdcp_bytes,
-                          unsigned int* stat_rx_data_pdus_duplicate,
-                          unsigned int* stat_rx_data_bytes_duplicate,
-                          unsigned int* stat_rx_data_pdu,
-                          unsigned int* stat_rx_data_bytes,
-                          unsigned int* stat_rx_data_pdu_dropped,
-                          unsigned int* stat_rx_data_bytes_dropped,
-                          unsigned int* stat_rx_data_pdu_out_of_window,
-                          unsigned int* stat_rx_data_bytes_out_of_window,
-                          unsigned int* stat_timer_reordering_timed_out)
-{
+                          unsigned int *stat_tx_pdcp_sdu,
+                          unsigned int *stat_tx_pdcp_bytes,
+                          unsigned int *stat_tx_pdcp_sdu_discarded,
+                          unsigned int *stat_tx_pdcp_bytes_discarded,
+                          unsigned int *stat_tx_data_pdu,
+                          unsigned int *stat_tx_data_bytes,
+                          unsigned int *stat_rx_pdcp_sdu,
+                          unsigned int *stat_rx_pdcp_bytes,
+                          unsigned int *stat_rx_data_pdus_duplicate,
+                          unsigned int *stat_rx_data_bytes_duplicate,
+                          unsigned int *stat_rx_data_pdu,
+                          unsigned int *stat_rx_data_bytes,
+                          unsigned int *stat_rx_data_pdu_dropped,
+                          unsigned int *stat_rx_data_bytes_dropped,
+                          unsigned int *stat_rx_data_pdu_out_of_window,
+                          unsigned int *stat_rx_data_bytes_out_of_window,
+                          unsigned int *stat_timer_reordering_timed_out) {
   *stat_tx_pdcp_sdu                     = rlc_pP->stat_tx_pdcp_sdu;
   *stat_tx_pdcp_bytes                   = rlc_pP->stat_tx_pdcp_bytes;
   *stat_tx_pdcp_sdu_discarded           = rlc_pP->stat_tx_pdcp_sdu_discarded;
@@ -81,8 +80,7 @@ void rlc_um_stat_req     (rlc_um_entity_t *rlc_pP,
 }
 //-----------------------------------------------------------------------------
 uint32_t
-rlc_um_get_buffer_occupancy (rlc_um_entity_t *rlc_pP)
-{
+rlc_um_get_buffer_occupancy (rlc_um_entity_t *rlc_pP) {
   if (rlc_pP->buffer_occupancy > 0) {
     return rlc_pP->buffer_occupancy;
   } else {
@@ -91,351 +89,294 @@ rlc_um_get_buffer_occupancy (rlc_um_entity_t *rlc_pP)
 }
 //-----------------------------------------------------------------------------
 void
-rlc_um_get_pdus (const protocol_ctxt_t* const ctxt_pP, void *argP)
-{
+rlc_um_get_pdus (const protocol_ctxt_t *const ctxt_pP, void *argP) {
   rlc_um_entity_t *rlc_p = (rlc_um_entity_t *) argP;
 
   switch (rlc_p->protocol_state) {
+    case RLC_NULL_STATE:
+      // from 3GPP TS 25.322 V9.2.0 p43
+      // In the NULL state the RLC entity does not exist and therefore it is
+      // not possible to transfer any data through it.
+      // Upon reception of a CRLC-CONFIG-Req from upper layer indicating
+      // establishment, the RLC entity:
+      //   - is created; and
+      //   - enters the DATA_TRANSFER_READY state.
+      break;
+
+    case RLC_DATA_TRANSFER_READY_STATE:
+
+      // from 3GPP TS 25.322 V9.2.0 p43-44
+      // In the DATA_TRANSFER_READY state, unacknowledged mode data can be
+      // exchanged between the entities according to subclause 11.2.
+      // Upon reception of a CRLC-CONFIG-Req from upper layer indicating
+      // release, the RLC entity:
+      // -enters the NULL state; and
+      // -is considered as being terminated.
+      // Upon reception of a CRLC-CONFIG-Req from upper layer indicating
+      // modification, the RLC entity:
+      // - stays in the DATA_TRANSFER_READY state;
+      // - modifies only the protocol parameters and timers as indicated by
+      // upper layers.
+      // Upon reception of a CRLC-SUSPEND-Req from upper layers, the RLC
+      // entity:
+      // - enters the LOCAL_SUSPEND state.
+
+      // SEND DATA TO MAC
+      if (rlc_p->tx_sn_length == 10) {
+        rlc_um_segment_10 (ctxt_pP, rlc_p);
+      }
 
-  case RLC_NULL_STATE:
-    // from 3GPP TS 25.322 V9.2.0 p43
-    // In the NULL state the RLC entity does not exist and therefore it is
-    // not possible to transfer any data through it.
-    // Upon reception of a CRLC-CONFIG-Req from upper layer indicating
-    // establishment, the RLC entity:
-    //   - is created; and
-    //   - enters the DATA_TRANSFER_READY state.
-    break;
-
-  case RLC_DATA_TRANSFER_READY_STATE:
-
-    // from 3GPP TS 25.322 V9.2.0 p43-44
-    // In the DATA_TRANSFER_READY state, unacknowledged mode data can be
-    // exchanged between the entities according to subclause 11.2.
-    // Upon reception of a CRLC-CONFIG-Req from upper layer indicating
-    // release, the RLC entity:
-    // -enters the NULL state; and
-    // -is considered as being terminated.
-    // Upon reception of a CRLC-CONFIG-Req from upper layer indicating
-    // modification, the RLC entity:
-    // - stays in the DATA_TRANSFER_READY state;
-    // - modifies only the protocol parameters and timers as indicated by
-    // upper layers.
-    // Upon reception of a CRLC-SUSPEND-Req from upper layers, the RLC
-    // entity:
-    // - enters the LOCAL_SUSPEND state.
-
-    // SEND DATA TO MAC
-    if (rlc_p->tx_sn_length == 10) {
-      rlc_um_segment_10 (ctxt_pP, rlc_p);
-    }
-
-    if (rlc_p->tx_sn_length == 5) {
-      rlc_um_segment_5 (ctxt_pP, rlc_p);
-    }
+      if (rlc_p->tx_sn_length == 5) {
+        rlc_um_segment_5 (ctxt_pP, rlc_p);
+      }
 
-    break;
-
-  case RLC_LOCAL_SUSPEND_STATE:
-    // from 3GPP TS 25.322 V9.2.0 p44
-    // In the LOCAL_SUSPEND state, the RLC entity is suspended, i.e. it does
-    // not send UMD PDUs with "Sequence Number" greater than or equal to a
-    // certain specified value (see subclause 9.7.5).
-    // Upon reception of a CRLC-CONFIG-Req from upper layer indicating
-    // release, the RLC entity:
-    // - enters the NULL state; and
-    // - is considered as being terminated.
-    // Upon reception of a CRLC-RESUME-Req from upper layers, the RLC entity:
-    // - enters the DATA_TRANSFER_READY state; and
-    // - resumes the data transmission.
-    // Upon reception of a CRLC-CONFIG-Req from upper layer indicating
-    // modification, the RLC entity:
-    // - stays in the LOCAL_SUSPEND state;
-    // - modifies only the protocol parameters and timers as indicated by
-    //   upper layers.
-
-    // TO DO TAKE CARE OF SN : THE IMPLEMENTATION OF THIS FUNCTIONNALITY IS NOT CRITICAL
-    break;
-
-  default:
-    LOG_E(RLC, PROTOCOL_RLC_UM_CTXT_FMT" MAC_DATA_REQ UNKNOWN PROTOCOL STATE %02X hex\n",
-          PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP,rlc_p),
-          rlc_p->protocol_state);
+      break;
+
+    case RLC_LOCAL_SUSPEND_STATE:
+      // from 3GPP TS 25.322 V9.2.0 p44
+      // In the LOCAL_SUSPEND state, the RLC entity is suspended, i.e. it does
+      // not send UMD PDUs with "Sequence Number" greater than or equal to a
+      // certain specified value (see subclause 9.7.5).
+      // Upon reception of a CRLC-CONFIG-Req from upper layer indicating
+      // release, the RLC entity:
+      // - enters the NULL state; and
+      // - is considered as being terminated.
+      // Upon reception of a CRLC-RESUME-Req from upper layers, the RLC entity:
+      // - enters the DATA_TRANSFER_READY state; and
+      // - resumes the data transmission.
+      // Upon reception of a CRLC-CONFIG-Req from upper layer indicating
+      // modification, the RLC entity:
+      // - stays in the LOCAL_SUSPEND state;
+      // - modifies only the protocol parameters and timers as indicated by
+      //   upper layers.
+      // TO DO TAKE CARE OF SN : THE IMPLEMENTATION OF THIS FUNCTIONNALITY IS NOT CRITICAL
+      break;
+
+    default:
+      LOG_E(RLC, PROTOCOL_RLC_UM_CTXT_FMT" MAC_DATA_REQ UNKNOWN PROTOCOL STATE %02X hex\n",
+            PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP,rlc_p),
+            rlc_p->protocol_state);
   }
 }
 
 //-----------------------------------------------------------------------------
 void
-rlc_um_rx (const protocol_ctxt_t* const ctxt_pP, void *argP, struct mac_data_ind data_indP)
-{
+rlc_um_rx (const protocol_ctxt_t *const ctxt_pP, void *argP, struct mac_data_ind data_indP) {
   rlc_um_entity_t    *l_rlc_p = (rlc_um_entity_t *) argP;
-#if TRACE_RLC_UM_PDU || MESSAGE_CHART_GENERATOR
   char  message_string[10000];
   mem_block_t        *tb_p;
   int16_t               tb_size_in_bytes;
   size_t              message_string_size = 0;
   rlc_um_pdu_info_t   pdu_info;
   int index;
-#endif
-#if TRACE_RLC_UM_PDU
   int                 octet_index;
-#   if ENABLE_ITTI
-  MessageDef         *msg_p;
-#   endif
-#endif
 
   switch (l_rlc_p->protocol_state) {
+    case RLC_NULL_STATE:
+      // from 3GPP TS 25.322 V9.2.0 p43
+      // In the NULL state the RLC entity does not exist and therefore it is
+      // not possible to transfer any data through it.
+      // Upon reception of a CRLC-CONFIG-Req from upper layer indicating
+      // establishment, the RLC entity:
+      //   - is created; and
+      //   - enters the DATA_TRANSFER_READY state.
+      LOG_I(RLC, PROTOCOL_RLC_UM_CTXT_FMT" ERROR MAC_DATA_IND IN RLC_NULL_STATE\n",
+            PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP,l_rlc_p));
+
+      if (data_indP.data.nb_elements > 0 && MESSAGE_CHART_GENERATOR) {
+        tb_p = data_indP.data.head;
+
+        while (tb_p != NULL) {
+          tb_size_in_bytes   = ((struct mac_tb_ind *) (tb_p->data))->size;
+          rlc_um_get_pdu_infos(ctxt_pP,l_rlc_p,(rlc_um_pdu_sn_10_t *) ((struct mac_tb_ind *) (tb_p->data))->data_ptr, tb_size_in_bytes, &pdu_info, l_rlc_p->rx_sn_length);
+          message_string_size = 0;
+          message_string_size += sprintf(&message_string[message_string_size],
+                                         MSC_AS_TIME_FMT" "PROTOCOL_RLC_UM_MSC_FMT"DATA SN %u size %u FI %u",
+                                         MSC_AS_TIME_ARGS(ctxt_pP),
+                                         PROTOCOL_RLC_UM_MSC_ARGS(ctxt_pP, l_rlc_p),
+                                         pdu_info.sn,
+                                         tb_size_in_bytes,
+                                         pdu_info.fi);
+
+          if (pdu_info.e) {
+            message_string_size += sprintf(&message_string[message_string_size], "| HE:");
+
+            for (index=0; index < pdu_info.num_li; index++) {
+              message_string_size += sprintf(&message_string[message_string_size], " LI %u", pdu_info.li_list[index]);
+            }
+          }
 
-  case RLC_NULL_STATE:
-    // from 3GPP TS 25.322 V9.2.0 p43
-    // In the NULL state the RLC entity does not exist and therefore it is
-    // not possible to transfer any data through it.
-    // Upon reception of a CRLC-CONFIG-Req from upper layer indicating
-    // establishment, the RLC entity:
-    //   - is created; and
-    //   - enters the DATA_TRANSFER_READY state.
-    LOG_I(RLC, PROTOCOL_RLC_UM_CTXT_FMT" ERROR MAC_DATA_IND IN RLC_NULL_STATE\n",
-          PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP,l_rlc_p));
-#if MESSAGE_CHART_GENERATOR
-
-    if (data_indP.data.nb_elements > 0) {
-      tb_p = data_indP.data.head;
-
-      while (tb_p != NULL) {
-        tb_size_in_bytes   = ((struct mac_tb_ind*) (tb_p->data))->size;
-        rlc_um_get_pdu_infos(ctxt_pP,l_rlc_p,(rlc_um_pdu_sn_10_t*) ((struct mac_tb_ind*) (tb_p->data))->data_ptr, tb_size_in_bytes, &pdu_info, l_rlc_p->rx_sn_length);
-        message_string_size = 0;
-        message_string_size += sprintf(&message_string[message_string_size],
-                                       MSC_AS_TIME_FMT" "PROTOCOL_RLC_UM_MSC_FMT"DATA SN %u size %u FI %u",
-                                       MSC_AS_TIME_ARGS(ctxt_pP),
-                                       PROTOCOL_RLC_UM_MSC_ARGS(ctxt_pP, l_rlc_p),
-                                       pdu_info.sn,
-                                       tb_size_in_bytes,
-                                       pdu_info.fi);
-
-        if (pdu_info.e) {
-          message_string_size += sprintf(&message_string[message_string_size], "| HE:");
-
-          for (index=0; index < pdu_info.num_li; index++) {
-            message_string_size += sprintf(&message_string[message_string_size], " LI %u", pdu_info.li_list[index]);
-        }
+          MSC_LOG_RX_DISCARDED_MESSAGE(
+            (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
+            (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_UE:MSC_RLC_ENB,
+            (const char *)pdu_info.payload,
+            tb_size_in_bytes,
+            message_string);
+          tb_p = tb_p->next;
         }
+      }/*MESSAGE_CHART_GENERATOR*/
+
+      list_free (&data_indP.data);
+      break;
+
+    case RLC_DATA_TRANSFER_READY_STATE:
+      // from 3GPP TS 25.322 V9.2.0 p43-44
+      // In the DATA_TRANSFER_READY state, unacknowledged mode data can be
+      // exchanged between the entities according to subclause 11.2.
+      // Upon reception of a CRLC-CONFIG-Req from upper layer indicating
+      // release, the RLC entity:
+      // -enters the NULL state; and
+      // -is considered as being terminated.
+      // Upon reception of a CRLC-CONFIG-Req from upper layer indicating
+      // modification, the RLC entity:
+      // - stays in the DATA_TRANSFER_READY state;
+      // - modifies only the protocol parameters and timers as indicated by
+      // upper layers.
+      // Upon reception of a CRLC-SUSPEND-Req from upper layers, the RLC
+      // entity:
+      // - enters the LOCAL_SUSPEND state.
+      data_indP.tb_size = data_indP.tb_size >> 3;
+
+      if (data_indP.data.nb_elements > 0 && (MESSAGE_CHART_GENERATOR || LOG_DEBUGFLAG(DEBUG_RLC))) {
+        LOG_D(RLC, PROTOCOL_RLC_UM_CTXT_FMT" MAC_DATA_IND %d TBs\n",
+              PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP,l_rlc_p),
+              data_indP.data.nb_elements);
+        tb_p = data_indP.data.head;
+
+        while (tb_p != NULL) {
+          tb_size_in_bytes   = ((struct mac_tb_ind *) (tb_p->data))->size;
+          rlc_um_get_pdu_infos(ctxt_pP,
+                               l_rlc_p,(rlc_um_pdu_sn_10_t *) ((struct mac_tb_ind *) (tb_p->data))->data_ptr,
+                               tb_size_in_bytes,
+                               &pdu_info,
+                               l_rlc_p->rx_sn_length);
+
+          if (MESSAGE_CHART_GENERATOR) {
+            message_string_size = 0;
+            message_string_size += sprintf(&message_string[message_string_size],
+                                           MSC_AS_TIME_FMT" "PROTOCOL_RLC_UM_MSC_FMT"DATA SN %u size %u FI %u",
+                                           MSC_AS_TIME_ARGS(ctxt_pP),
+                                           PROTOCOL_RLC_UM_MSC_ARGS(ctxt_pP, l_rlc_p),
+                                           pdu_info.sn,
+                                           tb_size_in_bytes,
+                                           pdu_info.fi);
+
+            if (pdu_info.e) {
+              message_string_size += sprintf(&message_string[message_string_size], "| HE:");
+
+              for (index=0; index < pdu_info.num_li; index++) {
+                message_string_size += sprintf(&message_string[message_string_size], " LI  %u", pdu_info.li_list[index]);
+              }
+            }
 
-        MSC_LOG_RX_DISCARDED_MESSAGE(
-          (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
-          (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_UE:MSC_RLC_ENB,
-          (const char*)pdu_info.payload,
-          tb_size_in_bytes,
-          message_string);
-
-        tb_p = tb_p->next;
-      }
-    }
-
-#endif
-    list_free (&data_indP.data);
-    break;
-
-  case RLC_DATA_TRANSFER_READY_STATE:
-    // from 3GPP TS 25.322 V9.2.0 p43-44
-    // In the DATA_TRANSFER_READY state, unacknowledged mode data can be
-    // exchanged between the entities according to subclause 11.2.
-    // Upon reception of a CRLC-CONFIG-Req from upper layer indicating
-    // release, the RLC entity:
-    // -enters the NULL state; and
-    // -is considered as being terminated.
-    // Upon reception of a CRLC-CONFIG-Req from upper layer indicating
-    // modification, the RLC entity:
-    // - stays in the DATA_TRANSFER_READY state;
-    // - modifies only the protocol parameters and timers as indicated by
-    // upper layers.
-    // Upon reception of a CRLC-SUSPEND-Req from upper layers, the RLC
-    // entity:
-    // - enters the LOCAL_SUSPEND state.
-    data_indP.tb_size = data_indP.tb_size >> 3;
-
-#if TRACE_RLC_UM_PDU || MESSAGE_CHART_GENERATOR
-
-    if (data_indP.data.nb_elements > 0) {
-      LOG_D(RLC, PROTOCOL_RLC_UM_CTXT_FMT" MAC_DATA_IND %d TBs\n",
-            PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP,l_rlc_p),
-            data_indP.data.nb_elements);
-
-      tb_p = data_indP.data.head;
-
-      while (tb_p != NULL) {
-        tb_size_in_bytes   = ((struct mac_tb_ind *) (tb_p->data))->size;
-        rlc_um_get_pdu_infos(ctxt_pP,
-                             l_rlc_p,(rlc_um_pdu_sn_10_t*) ((struct mac_tb_ind*) (tb_p->data))->data_ptr,
-                             tb_size_in_bytes,
-                             &pdu_info,
-                             l_rlc_p->rx_sn_length);
-
-#if MESSAGE_CHART_GENERATOR
-        message_string_size = 0;
-        message_string_size += sprintf(&message_string[message_string_size],
-                                       MSC_AS_TIME_FMT" "PROTOCOL_RLC_UM_MSC_FMT"DATA SN %u size %u FI %u",
-                                       MSC_AS_TIME_ARGS(ctxt_pP),
-                                       PROTOCOL_RLC_UM_MSC_ARGS(ctxt_pP, l_rlc_p),
-                                       pdu_info.sn,
-                                       tb_size_in_bytes,
-                                       pdu_info.fi);
-
-        if (pdu_info.e) {
-          message_string_size += sprintf(&message_string[message_string_size], "| HE:");
-
-          for (index=0; index < pdu_info.num_li; index++) {
-            message_string_size += sprintf(&message_string[message_string_size], " LI  %u", pdu_info.li_list[index]);
+            MSC_LOG_RX_MESSAGE(
+              (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
+              (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_UE:MSC_RLC_ENB,
+              (char *)pdu_info.payload,
+              tb_size_in_bytes,
+              message_string);
           }
-        }
 
-        MSC_LOG_RX_MESSAGE(
-          (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
-          (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_UE:MSC_RLC_ENB,
-          (char*)pdu_info.payload,
-          tb_size_in_bytes,
-          message_string);
-
-#endif
-#if TRACE_RLC_UM_PDU
-        message_string_size = 0;
-        message_string_size += sprintf(&message_string[message_string_size], "Bearer      : %u\n", l_rlc_p->rb_id);
-        message_string_size += sprintf(&message_string[message_string_size], "PDU size    : %u\n", tb_size_in_bytes);
-        message_string_size += sprintf(&message_string[message_string_size], "Header size : %u\n", pdu_info.header_size);
-        message_string_size += sprintf(&message_string[message_string_size], "Payload size: %u\n", pdu_info.payload_size);
-        message_string_size += sprintf(&message_string[message_string_size], "PDU type    : RLC UM DATA IND: UMD PDU\n\n");
-
-        message_string_size += sprintf(&message_string[message_string_size], "Header      :\n");
-        message_string_size += sprintf(&message_string[message_string_size], "  FI        : %u\n", pdu_info.fi);
-        message_string_size += sprintf(&message_string[message_string_size], "  E         : %u\n", pdu_info.e);
-        message_string_size += sprintf(&message_string[message_string_size], "  SN        : %u\n", pdu_info.sn);
-
-        if (pdu_info.e) {
-          message_string_size += sprintf(&message_string[message_string_size], "\nHeader extension  : \n");
-
-          for (index=0; index < pdu_info.num_li; index++) {
-            message_string_size += sprintf(&message_string[message_string_size], "  LI        : %u\n", pdu_info.li_list[index]);
-          }
-        }
+          if (LOG_DEBUGFLAG(DEBUG_RLC)) {
+            message_string_size = 0;
+            message_string_size += sprintf(&message_string[message_string_size], "Bearer      : %u\n", l_rlc_p->rb_id);
+            message_string_size += sprintf(&message_string[message_string_size], "PDU size    : %u\n", tb_size_in_bytes);
+            message_string_size += sprintf(&message_string[message_string_size], "Header size : %u\n", pdu_info.header_size);
+            message_string_size += sprintf(&message_string[message_string_size], "Payload size: %u\n", pdu_info.payload_size);
+            message_string_size += sprintf(&message_string[message_string_size], "PDU type    : RLC UM DATA IND: UMD PDU\n\n");
+            message_string_size += sprintf(&message_string[message_string_size], "Header      :\n");
+            message_string_size += sprintf(&message_string[message_string_size], "  FI	    : %u\n", pdu_info.fi);
+            message_string_size += sprintf(&message_string[message_string_size], "  E	    : %u\n", pdu_info.e);
+            message_string_size += sprintf(&message_string[message_string_size], "  SN	    : %u\n", pdu_info.sn);
+
+            if (pdu_info.e) {
+              message_string_size += sprintf(&message_string[message_string_size], "\nHeader extension  : \n");
+
+              for (index=0; index < pdu_info.num_li; index++) {
+                message_string_size += sprintf(&message_string[message_string_size], "  LI        : %u\n", pdu_info.li_list[index]);
+              }
+            }
 
-        message_string_size += sprintf(&message_string[message_string_size], "\nPayload  : \n");
-        message_string_size += sprintf(&message_string[message_string_size], "------+-------------------------------------------------|\n");
-        message_string_size += sprintf(&message_string[message_string_size], "      |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |\n");
-        message_string_size += sprintf(&message_string[message_string_size], "------+-------------------------------------------------|\n");
+            message_string_size += sprintf(&message_string[message_string_size], "\nPayload  : \n");
+            message_string_size += sprintf(&message_string[message_string_size], "------+-------------------------------------------------|\n");
+            message_string_size += sprintf(&message_string[message_string_size], "      |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |\n");
+            message_string_size += sprintf(&message_string[message_string_size], "------+-------------------------------------------------|\n");
+
+            for (octet_index = 0; octet_index < pdu_info.payload_size; octet_index++) {
+              if ((octet_index % 16) == 0) {
+                if (octet_index != 0) {
+                  message_string_size += sprintf(&message_string[message_string_size], " |\n");
+                }
+
+                message_string_size += sprintf(&message_string[message_string_size], " %04d |", octet_index);
+              }
+
+              /*
+               * Print every single octet in hexadecimal form
+               */
+              message_string_size += sprintf(&message_string[message_string_size], " %02x", pdu_info.payload[octet_index]);
+              /*
+               * Align newline and pipes according to the octets in groups of 2
+               */
+            }
 
-        for (octet_index = 0; octet_index < pdu_info.payload_size; octet_index++) {
-          if ((octet_index % 16) == 0) {
-            if (octet_index != 0) {
-              message_string_size += sprintf(&message_string[message_string_size], " |\n");
+            /*
+             * Append enough spaces and put final pipe
+             */
+            for (index = octet_index; index < 16; ++index) {
+              message_string_size += sprintf(&message_string[message_string_size], "   ");
             }
 
-            message_string_size += sprintf(&message_string[message_string_size], " %04d |", octet_index);
+            message_string_size += sprintf(&message_string[message_string_size], " |\n");
+            LOG_UI(RLC, "%s|\n", message_string);
           }
 
-          /*
-           * Print every single octet in hexadecimal form
-           */
-          message_string_size += sprintf(&message_string[message_string_size], " %02x", pdu_info.payload[octet_index]);
-          /*
-           * Align newline and pipes according to the octets in groups of 2
-           */
+          tb_p = tb_p->next;
         }
-
-        /*
-         * Append enough spaces and put final pipe
-         */
-        for (index = octet_index; index < 16; ++index) {
-          message_string_size += sprintf(&message_string[message_string_size], "   ");
-        }
-
-        message_string_size += sprintf(&message_string[message_string_size], " |\n");
-
-#   if ENABLE_ITTI
-        msg_p = itti_alloc_new_message_sized (ctxt_pP->enb_flag ? TASK_RLC_ENB:TASK_RLC_UE , RLC_UM_DATA_PDU_IND, message_string_size + sizeof (IttiMsgText));
-        msg_p->ittiMsg.rlc_um_data_pdu_ind.size = message_string_size;
-        memcpy(&msg_p->ittiMsg.rlc_um_data_pdu_ind.text, message_string, message_string_size);
-
-        itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
-
-# else
-        LOG_T(RLC, "%s", message_string);
-# endif // ENABLE_ITTI
-#endif // TRACE_RLC_UM_PDU
-
-        tb_p = tb_p->next;
       }
-    }
 
-#endif
-    rlc_um_receive (ctxt_pP, l_rlc_p, data_indP);
-    break;
-
-  case RLC_LOCAL_SUSPEND_STATE:
-    // from 3GPP TS 25.322 V9.2.0 p44
-    // In the LOCAL_SUSPEND state, the RLC entity is suspended, i.e. it does
-    // not send UMD PDUs with "Sequence Number" greater than or equal to a
-    // certain specified value (see subclause 9.7.5).
-    // Upon reception of a CRLC-CONFIG-Req from upper layer indicating
-    // release, the RLC entity:
-    // - enters the NULL state; and
-    // - is considered as being terminated.
-    // Upon reception of a CRLC-RESUME-Req from upper layers, the RLC entity:
-    // - enters the DATA_TRANSFER_READY state; and
-    // - resumes the data transmission.
-    // Upon reception of a CRLC-CONFIG-Req from upper layer indicating
-    // modification, the RLC entity:
-    // - stays in the LOCAL_SUSPEND state;
-    // - modifies only the protocol parameters and timers as indicated by
-    //   upper layers.
-    LOG_I(RLC, PROTOCOL_RLC_UM_CTXT_FMT" RLC_LOCAL_SUSPEND_STATE\n",
-          PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP,l_rlc_p));
-    /*if (data_indP.data.nb_elements > 0) {
-        LOG_D(RLC, "[FRAME %05d][%s][RLC_UM][MOD %02u/%02u][RB %02d] MAC_DATA_IND %d TBs\n", l_rlc_p->module_id, l_rlc_p->rb_id, ctxt_pP->frame, data_indP.data.nb_elements);
-        rlc_p[l_rlc_p->module_id].m_mscgen_trace_length = sprintf(rlc_p[l_rlc_p->module_id].m_mscgen_trace, "[MSC_MSG][FRAME %05d][MAC_%s][MOD %02d][][--- MAC_DATA_IND/ %d TB(s) ",
-            ctxt_pP->frame,
-            (ctxt_pP->enb_flag) ? "eNB":"UE",
-            l_rlc_p->module_id,
-            data_indP.data.nb_elements);
-
-        tb = data_indP.data.head;
-        while (tb != NULL) {
-            rlc_p[l_rlc_p->module_id].m_mscgen_trace_length += sprintf(&rlc_p[l_rlc_p->module_id].m_mscgen_trace[rlc_p[l_rlc_p->module_id].m_mscgen_trace_length], " SN %d %c%c%c %d Bytes ",
-                                                                (((struct mac_tb_ind *) (tb->data))->data_ptr[1]) +  (((uint16_t)((((struct mac_tb_ind *) (tb->data))->data_ptr[0]) & 0x03)) << 8),
-                                                                (((struct mac_tb_ind *) (tb->data))->data_ptr[0] & 0x10) ?  '}':'{',
-                                                                (((struct mac_tb_ind *) (tb->data))->data_ptr[0] & 0x08) ?  '{':'}',
-                                                                (((struct mac_tb_ind *) (tb->data))->data_ptr[0] & 0x04) ?  'E':'_',
-                                                                ((struct mac_tb_ind *) (tb->data))->size);
-            tb = tb->next;
-        }
-        rlc_p[l_rlc_p->module_id].m_mscgen_trace_length += sprintf(&rlc_p[l_rlc_p->module_id].m_mscgen_trace[rlc_p[l_rlc_p->module_id].m_mscgen_trace_length], " DROPPED RLC LOCAL SUSPEND STATE ---X][RLC_UM][MOD %02d][RB %02d]\n",
-            l_rlc_p->module_id,
-            l_rlc_p->rb_id);
-
-        rlc_p[l_rlc_p->module_id].m_mscgen_trace[rlc_p[l_rlc_p->module_id].m_mscgen_trace_length] = 0;
-        LOG_D(RLC, "%s", rlc_p[l_rlc_p->module_id].m_mscgen_trace);
-    }*/
-    list_free (&data_indP.data);
-    break;
-
-  default:
-    LOG_E(RLC, PROTOCOL_RLC_UM_CTXT_FMT" TX UNKNOWN PROTOCOL STATE %02X hex\n",
-          PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP,l_rlc_p),
-          l_rlc_p->protocol_state);
-    list_free (&data_indP.data);
+      rlc_um_receive (ctxt_pP, l_rlc_p, data_indP);
+      break;
+
+    case RLC_LOCAL_SUSPEND_STATE:
+      // from 3GPP TS 25.322 V9.2.0 p44
+      // In the LOCAL_SUSPEND state, the RLC entity is suspended, i.e. it does
+      // not send UMD PDUs with "Sequence Number" greater than or equal to a
+      // certain specified value (see subclause 9.7.5).
+      // Upon reception of a CRLC-CONFIG-Req from upper layer indicating
+      // release, the RLC entity:
+      // - enters the NULL state; and
+      // - is considered as being terminated.
+      // Upon reception of a CRLC-RESUME-Req from upper layers, the RLC entity:
+      // - enters the DATA_TRANSFER_READY state; and
+      // - resumes the data transmission.
+      // Upon reception of a CRLC-CONFIG-Req from upper layer indicating
+      // modification, the RLC entity:
+      // - stays in the LOCAL_SUSPEND state;
+      // - modifies only the protocol parameters and timers as indicated by
+      //   upper layers.
+      LOG_I(RLC, PROTOCOL_RLC_UM_CTXT_FMT" RLC_LOCAL_SUSPEND_STATE\n",
+            PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP,l_rlc_p));
+      list_free (&data_indP.data);
+      break;
+
+    default:
+      LOG_E(RLC, PROTOCOL_RLC_UM_CTXT_FMT" TX UNKNOWN PROTOCOL STATE %02X hex\n",
+            PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP,l_rlc_p),
+            l_rlc_p->protocol_state);
+      list_free (&data_indP.data);
   }
 }
 
 //-----------------------------------------------------------------------------
 struct mac_status_resp
-rlc_um_mac_status_indication (const protocol_ctxt_t* const ctxt_pP, void *rlc_pP, uint16_t tbs_sizeP, struct mac_status_ind tx_statusP,const eNB_flag_t enb_flagP)
-{
+rlc_um_mac_status_indication (const protocol_ctxt_t *const ctxt_pP, void *rlc_pP, uint16_t tbs_sizeP, struct mac_status_ind tx_statusP,const eNB_flag_t enb_flagP) {
   struct mac_status_resp status_resp;
   uint16_t  sdu_size = 0;
   uint16_t  sdu_remaining_size = 0;
   int32_t diff_time=0;
-  rlc_um_entity_t   *rlc_p = NULL;
+  rlc_um_entity_t   *rlc_p = (rlc_um_entity_t *) rlc_pP;
   mem_block_t       *mb_p = NULL;
-
   status_resp.buffer_occupancy_in_pdus         = 0;
   status_resp.buffer_occupancy_in_bytes        = 0;
   status_resp.head_sdu_remaining_size_to_send  = 0;
@@ -443,31 +384,24 @@ rlc_um_mac_status_indication (const protocol_ctxt_t* const ctxt_pP, void *rlc_pP
   status_resp.head_sdu_is_segmented            = 0;
 
   if (rlc_pP) {
-
-    rlc_p = (rlc_um_entity_t *) rlc_pP;
     status_resp.rlc_info.rlc_protocol_state      = rlc_p->protocol_state;
     rlc_um_check_timer_dar_time_out(ctxt_pP, rlc_p);
-
     rlc_p->nb_bytes_requested_by_mac = tbs_sizeP;
-
     status_resp.buffer_occupancy_in_bytes = rlc_um_get_buffer_occupancy (rlc_p);
 
     if ((status_resp.buffer_occupancy_in_bytes > 0) && ((mb_p = list_get_head(&rlc_p->input_sdus)) != NULL)) {
-
       if (enb_flagP == ENB_FLAG_YES) {
-    	  /* For eNB: add minimum RLC UM header size for the scheduler */
-    	  /* For UE : RLC header part is not taken into account for BSR reporting (cf 36.321) */
-          status_resp.buffer_occupancy_in_bytes += rlc_p->tx_header_min_length_in_bytes;
+        /* For eNB: add minimum RLC UM header size for the scheduler */
+        /* For UE : RLC header part is not taken into account for BSR reporting (cf 36.321) */
+        status_resp.buffer_occupancy_in_bytes += rlc_p->tx_header_min_length_in_bytes;
       }
-      status_resp.buffer_occupancy_in_pdus = rlc_p->input_sdus.nb_elements;
 
+      status_resp.buffer_occupancy_in_pdus = rlc_p->input_sdus.nb_elements;
       diff_time =   ctxt_pP->frame - ((struct rlc_um_tx_sdu_management *)mb_p->data)->sdu_creation_time;
       status_resp.head_sdu_creation_time = (diff_time > 0 ) ? (uint32_t) diff_time :  (uint32_t)(0xffffffff - diff_time + ctxt_pP->frame) ;
       //msg("rlc_p status for ctxt_pP->frame %d diff time %d resp %d\n", ctxt_pP->frame, diff_time,status_resp.head_sdu_creation_time) ;
-
       sdu_size            = ((struct rlc_um_tx_sdu_management *) mb_p->data)->sdu_size;
       sdu_remaining_size  = ((struct rlc_um_tx_sdu_management *) mb_p->data)->sdu_remaining_size;
-
       status_resp.head_sdu_remaining_size_to_send = sdu_remaining_size;
 
       if (sdu_size == sdu_remaining_size)  {
@@ -475,35 +409,31 @@ rlc_um_mac_status_indication (const protocol_ctxt_t* const ctxt_pP, void *rlc_pP
       } else {
         status_resp.head_sdu_is_segmented = 1;
       }
-
     } else {
     }
 
-    //msg("[FRAME %05d][%s][RLC_UM][MOD %02u/%02u][RB %02d] MAC_STATUS_INDICATION BO = %d\n", ((rlc_um_entity_t *) rlc_pP)->module_id, ((rlc_um_entity_t *) rlc_pP)->rb_id, status_resp.buffer_occupancy_in_bytes);
+    status_resp.rlc_info.rlc_protocol_state = rlc_p->protocol_state;
 
-    status_resp.rlc_info.rlc_protocol_state = ((rlc_um_entity_t *) rlc_pP)->protocol_state;
-#if TRACE_RLC_UM_TX_STATUS
+    if (LOG_DEBUGFLAG(DEBUG_RLC)) {
+      if (( rlc_p->rb_id > 0) && (status_resp.buffer_occupancy_in_bytes > 0)) {
+        LOG_UI(RLC, PROTOCOL_RLC_UM_CTXT_FMT"MAC_STATUS_INDICATION (DATA) %d bytes requested -> %d bytes available\n",
+               PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP,rlc_p),
+               tbs_sizeP,
+               status_resp.buffer_occupancy_in_bytes);
 
-    if ((((rlc_um_entity_t *) rlc_pP)->rb_id > 0) && (status_resp.buffer_occupancy_in_bytes > 0)) {
-      LOG_D(RLC, PROTOCOL_RLC_UM_CTXT_FMT" MAC_STATUS_INDICATION (DATA) %d bytes requested -> %d bytes available\n",
-            PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP,rlc_pP),
-            tbs_sizeP,
-            status_resp.buffer_occupancy_in_bytes);
-
-      if ((tx_statusP.tx_status == MAC_TX_STATUS_SUCCESSFUL) && (tx_statusP.no_pdu)) {
-        LOG_D(RLC, PROTOCOL_RLC_UM_CTXT_FMT" MAC_STATUS_INDICATION  TX STATUS   SUCCESSFUL %d PDUs\n",
-              PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP,rlc_pP),
-              tx_statusP.no_pdu);
-      }
+        if ((tx_statusP.tx_status == MAC_TX_STATUS_SUCCESSFUL) && (tx_statusP.no_pdu)) {
+          LOG_D(RLC, PROTOCOL_RLC_UM_CTXT_FMT" MAC_STATUS_INDICATION  TX STATUS   SUCCESSFUL %d PDUs\n",
+                PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP,rlc_p),
+                tx_statusP.no_pdu);
+        }
 
-      if ((tx_statusP.tx_status == MAC_TX_STATUS_UNSUCCESSFUL) && (tx_statusP.no_pdu)) {
-        LOG_D(RLC, PROTOCOL_RLC_UM_CTXT_FMT" MAC_STATUS_INDICATION  TX STATUS UNSUCCESSFUL %d PDUs\n",
-              PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP,rlc_pP),
-              tx_statusP.no_pdu);
+        if ((tx_statusP.tx_status == MAC_TX_STATUS_UNSUCCESSFUL) && (tx_statusP.no_pdu)) {
+          LOG_UI(RLC, PROTOCOL_RLC_UM_CTXT_FMT" MAC_STATUS_INDICATION  TX STATUS UNSUCCESSFUL %d PDUs\n",
+                 PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP,rlc_p),
+                 tx_statusP.no_pdu);
+        }
       }
     }
-
-#endif
   } else {
     LOG_E(RLC, "[RLC] rlc_um_mac_status_indication RLC NULL!!!\n");
   }
@@ -514,44 +444,34 @@ rlc_um_mac_status_indication (const protocol_ctxt_t* const ctxt_pP, void *rlc_pP
 //-----------------------------------------------------------------------------
 void
 rlc_um_set_nb_bytes_requested_by_mac (
-  void *				rlc_pP,
-  const tb_size_t		tb_sizeP
-)
-{
-	((rlc_um_entity_t *) rlc_pP)->nb_bytes_requested_by_mac = tb_sizeP;
+  void         *rlc_pP,
+  const tb_size_t   tb_sizeP
+) {
+  ((rlc_um_entity_t *) rlc_pP)->nb_bytes_requested_by_mac = tb_sizeP;
 }
 
 //-----------------------------------------------------------------------------
 struct mac_data_req
-rlc_um_mac_data_request (const protocol_ctxt_t* const ctxt_pP, void *rlc_pP,const eNB_flag_t  enb_flagP)
-{
+rlc_um_mac_data_request (const protocol_ctxt_t *const ctxt_pP, void *rlc_pP,const eNB_flag_t  enb_flagP) {
   struct mac_data_req data_req;
   int16_t               tb_size_in_bytes;
   mem_block_t        *tb_p;
-#if TRACE_RLC_UM_PDU || MESSAGE_CHART_GENERATOR
   char  message_string[10000];
   size_t              message_string_size = 0;
-#   if ENABLE_ITTI
-  MessageDef         *msg_p;
-#   endif
   rlc_um_pdu_info_t   pdu_info;
   int                 octet_index, index;
-#endif
   rlc_um_entity_t *l_rlc_p = (rlc_um_entity_t *) rlc_pP;
-
   rlc_um_get_pdus(ctxt_pP, l_rlc_p);
-
   list_init (&data_req.data, NULL);
   list_add_list (&l_rlc_p->pdus_to_mac_layer, &data_req.data);
 
-
   if (enb_flagP) {
-	  // redundant in UE MAC Tx processing and not used in eNB scheduler ...
-	  data_req.buffer_occupancy_in_bytes = rlc_um_get_buffer_occupancy (l_rlc_p);
+    // redundant in UE MAC Tx processing and not used in eNB scheduler ...
+    data_req.buffer_occupancy_in_bytes = rlc_um_get_buffer_occupancy (l_rlc_p);
 
-	  if (data_req.buffer_occupancy_in_bytes > 0) {
-	    data_req.buffer_occupancy_in_bytes += l_rlc_p->tx_header_min_length_in_bytes;
-	  }
+    if (data_req.buffer_occupancy_in_bytes > 0) {
+      data_req.buffer_occupancy_in_bytes += l_rlc_p->tx_header_min_length_in_bytes;
+    }
   }
 
   data_req.rlc_info.rlc_protocol_state = l_rlc_p->protocol_state;
@@ -561,7 +481,6 @@ rlc_um_mac_data_request (const protocol_ctxt_t* const ctxt_pP, void *rlc_pP,cons
 
     while (tb_p != NULL) {
       tb_size_in_bytes   = ((struct mac_tb_req *) (tb_p->data))->tb_size;
-
       LOG_D(RLC, PROTOCOL_RLC_UM_CTXT_FMT" MAC_DATA_REQUEST  TB SIZE %u\n",
             PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP,l_rlc_p),
             ((struct mac_tb_req *) (tb_p->data))->tb_size);
@@ -574,156 +493,130 @@ rlc_um_mac_data_request (const protocol_ctxt_t* const ctxt_pP, void *rlc_pP,cons
         tb_p = tb_p->next;
         continue;
       }
-        
-#if TRACE_RLC_UM_PDU || MESSAGE_CHART_GENERATOR
-      rlc_um_get_pdu_infos(ctxt_pP, l_rlc_p,(rlc_um_pdu_sn_10_t*) ((struct mac_tb_req*) (tb_p->data))->data_ptr, tb_size_in_bytes, &pdu_info, l_rlc_p->rx_sn_length);
-#endif
-#if MESSAGE_CHART_GENERATOR
-      message_string_size = 0;
-      message_string_size += sprintf(&message_string[message_string_size],
-                                     MSC_AS_TIME_FMT" "PROTOCOL_RLC_UM_MSC_FMT" DATA SN %u size %u FI %u",
-                                     MSC_AS_TIME_ARGS(ctxt_pP),
-                                     PROTOCOL_RLC_UM_MSC_ARGS(ctxt_pP, l_rlc_p),
-                                     pdu_info.sn,
-                                     tb_size_in_bytes,
-                                     pdu_info.fi);
-
-      if (pdu_info.e) {
-        message_string_size += sprintf(&message_string[message_string_size], "|HE:");
-
-        for (index=0; index < pdu_info.num_li; index++) {
-          message_string_size += sprintf(&message_string[message_string_size], " LI %u", pdu_info.li_list[index]);
-        }
-      }
 
-      MSC_LOG_TX_MESSAGE(
-        (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
-        (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_UE:MSC_RLC_ENB,
-        (const char*)pdu_info.payload,
-        pdu_info.payload_size,
-        message_string);
+      if (MESSAGE_CHART_GENERATOR || LOG_DEBUGFLAG(DEBUG_RLC) ) {
+        rlc_um_get_pdu_infos(ctxt_pP, l_rlc_p,(rlc_um_pdu_sn_10_t *) ((struct mac_tb_req *) (tb_p->data))->data_ptr, tb_size_in_bytes, &pdu_info, l_rlc_p->rx_sn_length);
 
-#endif
-#if TRACE_RLC_UM_PDU
-      message_string_size = 0;
-      message_string_size += sprintf(&message_string[message_string_size], "Bearer      : %u\n", l_rlc_p->rb_id);
-      message_string_size += sprintf(&message_string[message_string_size], "PDU size    : %u\n", tb_size_in_bytes);
-      message_string_size += sprintf(&message_string[message_string_size], "Header size : %u\n", pdu_info.header_size);
-      message_string_size += sprintf(&message_string[message_string_size], "Payload size: %u\n", pdu_info.payload_size);
-      message_string_size += sprintf(&message_string[message_string_size], "PDU type    : RLC UM DATA IND: UMD PDU\n\n");
-
-      message_string_size += sprintf(&message_string[message_string_size], "Header      :\n");
-      message_string_size += sprintf(&message_string[message_string_size], "  FI        : %u\n", pdu_info.fi);
-      message_string_size += sprintf(&message_string[message_string_size], "  E         : %u\n", pdu_info.e);
-      message_string_size += sprintf(&message_string[message_string_size], "  SN        : %u\n", pdu_info.sn);
-
-      if (pdu_info.e) {
-        message_string_size += sprintf(&message_string[message_string_size], "\nHeader extension  : \n");
-
-        for (index=0; index < pdu_info.num_li; index++) {
-          message_string_size += sprintf(&message_string[message_string_size], "  LI        : %u\n", pdu_info.li_list[index]);
-        }
-      }
+        if(MESSAGE_CHART_GENERATOR) {
+          message_string_size = 0;
+          message_string_size += sprintf(&message_string[message_string_size],
+                                         MSC_AS_TIME_FMT" "PROTOCOL_RLC_UM_MSC_FMT" DATA SN %u size %u FI %u",
+                                         MSC_AS_TIME_ARGS(ctxt_pP),
+                                         PROTOCOL_RLC_UM_MSC_ARGS(ctxt_pP, l_rlc_p),
+                                         pdu_info.sn,
+                                         tb_size_in_bytes,
+                                         pdu_info.fi);
 
-      message_string_size += sprintf(&message_string[message_string_size], "\nPayload  : \n");
-      message_string_size += sprintf(&message_string[message_string_size], "------+-------------------------------------------------|\n");
-      message_string_size += sprintf(&message_string[message_string_size], "      |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |\n");
-      message_string_size += sprintf(&message_string[message_string_size], "------+-------------------------------------------------|\n");
+          if (pdu_info.e) {
+            message_string_size += sprintf(&message_string[message_string_size], "|HE:");
 
-      for (octet_index = 0; octet_index < pdu_info.payload_size; octet_index++) {
-        if ((octet_index % 16) == 0) {
-          if (octet_index != 0) {
-            message_string_size += sprintf(&message_string[message_string_size], " |\n");
+            for (index=0; index < pdu_info.num_li; index++) {
+              message_string_size += sprintf(&message_string[message_string_size], " LI %u", pdu_info.li_list[index]);
+            }
           }
 
-          message_string_size += sprintf(&message_string[message_string_size], " %04d |", octet_index);
+          MSC_LOG_TX_MESSAGE(
+            (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
+            (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_UE:MSC_RLC_ENB,
+            (const char *)pdu_info.payload,
+            pdu_info.payload_size,
+            message_string);
         }
 
-        /*
-         * Print every single octet in hexadecimal form
-         */
-        message_string_size += sprintf(&message_string[message_string_size], " %02x", pdu_info.payload[octet_index]);
-        /*
-         * Align newline and pipes according to the octets in groups of 2
-         */
-      }
+        if(LOG_DEBUGFLAG(DEBUG_RLC)) {
+          message_string_size = 0;
+          message_string_size += sprintf(&message_string[message_string_size], "Bearer	  : %u\n", l_rlc_p->rb_id);
+          message_string_size += sprintf(&message_string[message_string_size], "PDU size    : %u\n", tb_size_in_bytes);
+          message_string_size += sprintf(&message_string[message_string_size], "Header size : %u\n", pdu_info.header_size);
+          message_string_size += sprintf(&message_string[message_string_size], "Payload size: %u\n", pdu_info.payload_size);
+          message_string_size += sprintf(&message_string[message_string_size], "PDU type    : RLC UM DATA IND: UMD PDU\n\n");
+          message_string_size += sprintf(&message_string[message_string_size], "Header	  :\n");
+          message_string_size += sprintf(&message_string[message_string_size], "  FI	  : %u\n", pdu_info.fi);
+          message_string_size += sprintf(&message_string[message_string_size], "  E	  : %u\n", pdu_info.e);
+          message_string_size += sprintf(&message_string[message_string_size], "  SN	  : %u\n", pdu_info.sn);
+
+          if (pdu_info.e) {
+            message_string_size += sprintf(&message_string[message_string_size], "\nHeader extension  : \n");
+
+            for (index=0; index < pdu_info.num_li; index++) {
+              message_string_size += sprintf(&message_string[message_string_size], "  LI        : %u\n", pdu_info.li_list[index]);
+            }
+          }
 
-      /*
-       * Append enough spaces and put final pipe
-       */
-      for (index = octet_index; index < 16; ++index) {
-        message_string_size += sprintf(&message_string[message_string_size], "   ");
-      }
+          message_string_size += sprintf(&message_string[message_string_size], "\nPayload  : \n");
+          message_string_size += sprintf(&message_string[message_string_size], "------+-------------------------------------------------|\n");
+          message_string_size += sprintf(&message_string[message_string_size], "      |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |\n");
+          message_string_size += sprintf(&message_string[message_string_size], "------+-------------------------------------------------|\n");
 
-      message_string_size += sprintf(&message_string[message_string_size], " |\n");
+          for (octet_index = 0; octet_index < pdu_info.payload_size; octet_index++) {
+            if ((octet_index % 16) == 0) {
+              if (octet_index != 0) {
+                message_string_size += sprintf(&message_string[message_string_size], " |\n");
+              }
 
-#   if ENABLE_ITTI
-      msg_p = itti_alloc_new_message_sized (ctxt_pP->enb_flag > 0 ? TASK_RLC_ENB:TASK_RLC_UE , RLC_UM_DATA_PDU_REQ, message_string_size + sizeof (IttiMsgText));
-      msg_p->ittiMsg.rlc_um_data_pdu_req.size = message_string_size;
-      memcpy(&msg_p->ittiMsg.rlc_um_data_pdu_req.text, message_string, message_string_size);
+              message_string_size += sprintf(&message_string[message_string_size], " %04d |", octet_index);
+            }
 
-      itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
+            /*
+             * Print every single octet in hexadecimal form
+             */
+            message_string_size += sprintf(&message_string[message_string_size], " %02x", pdu_info.payload[octet_index]);
+            /*
+             * Align newline and pipes according to the octets in groups of 2
+             */
+          }
+
+          /*
+           * Append enough spaces and put final pipe
+           */
+          for (index = octet_index; index < 16; ++index) {
+            message_string_size += sprintf(&message_string[message_string_size], "   ");
+          }
+
+          message_string_size += sprintf(&message_string[message_string_size], " |\n");
+          LOG_UI(RLC, "%s\n", message_string);
+        } /*LOG_DEBUGFLAG(DEBUG_RLC) */
+      } /* MESSAGE_CHART_GENERATOR || LOG_DEBUGFLAG(DEBUG_RLC) */
 
-# else
-      LOG_T(RLC, "%s", message_string);
-# endif
-#endif
       tb_p = tb_p->next;
-    }
-  }
+    } /* while (tb_p != NULL) */
+  } /* if (data_req.data.nb_elements > 0) */
 
   return data_req;
 }
 
 //-----------------------------------------------------------------------------
 void
-rlc_um_mac_data_indication (const protocol_ctxt_t* const ctxt_pP, void *rlc_pP, struct mac_data_ind data_indP)
-{
+rlc_um_mac_data_indication (const protocol_ctxt_t *const ctxt_pP, void *rlc_pP, struct mac_data_ind data_indP) {
   rlc_um_rx (ctxt_pP, rlc_pP, data_indP);
   rlc_um_check_timer_dar_time_out(ctxt_pP, rlc_pP);
 }
 
 //-----------------------------------------------------------------------------
 void
-rlc_um_data_req (const protocol_ctxt_t* const ctxt_pP, void *rlc_pP, mem_block_t *sdu_pP)
-{
+rlc_um_data_req (const protocol_ctxt_t *const ctxt_pP, void *rlc_pP, mem_block_t *sdu_pP) {
   rlc_um_entity_t *rlc_p = (rlc_um_entity_t *) rlc_pP;
-
-#if TRACE_RLC_UM_PDU
-#if ENABLE_ITTI
-  MessageDef          *msg_p;
-#   endif
   uint16_t             data_offset;
   uint16_t             data_size;
   size_t               message_string_size = 0;
   int                  octet_index, index;
   char                 message_string[7000];
-#endif
-
   LOG_D(RLC, PROTOCOL_RLC_UM_CTXT_FMT" RLC_UM_DATA_REQ size %d Bytes, BO %d , NB SDU %d\n",
         PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP,rlc_p),
         ((struct rlc_um_data_req *) (sdu_pP->data))->data_size,
         rlc_p->buffer_occupancy,
         rlc_p->input_sdus.nb_elements);
-
-  /*rlc_util_print_hex_octets(
-      RLC,
-      (uint8_t*)&sdu_pP->data[sizeof (struct rlc_um_data_req_alloc)],
-      ((struct rlc_um_data_req *) (sdu_pP->data))->data_size);*/
-
   // IMPORTANT : do not change order of affectations
   ((struct rlc_um_tx_sdu_management *) (sdu_pP->data))->sdu_size = ((struct rlc_um_data_req *) (sdu_pP->data))->data_size;
   //rlc_p->nb_sdu += 1;
-  ((struct rlc_um_tx_sdu_management *) (sdu_pP->data))->first_byte = (uint8_t*)&sdu_pP->data[sizeof (struct rlc_um_data_req_alloc)];
+  ((struct rlc_um_tx_sdu_management *) (sdu_pP->data))->first_byte = (uint8_t *)&sdu_pP->data[sizeof (struct rlc_um_data_req_alloc)];
   ((struct rlc_um_tx_sdu_management *) (sdu_pP->data))->sdu_remaining_size = ((struct rlc_um_tx_sdu_management *)
       (sdu_pP->data))->sdu_size;
   ((struct rlc_um_tx_sdu_management *) (sdu_pP->data))->sdu_segmented_size = 0;
   ((struct rlc_um_tx_sdu_management *) (sdu_pP->data))->sdu_creation_time = ctxt_pP->frame;
   //rlc_p->next_sdu_index = (rlc_p->next_sdu_index + 1) % rlc_p->size_input_sdus_buffer;
-
   rlc_p->stat_tx_pdcp_sdu   += 1;
   rlc_p->stat_tx_pdcp_bytes += ((struct rlc_um_tx_sdu_management *) (sdu_pP->data))->sdu_size;
-
   MSC_LOG_RX_MESSAGE(
     (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
     (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
@@ -732,74 +625,61 @@ rlc_um_data_req (const protocol_ctxt_t* const ctxt_pP, void *rlc_pP, mem_block_t
     MSC_AS_TIME_FMT" "PROTOCOL_RLC_UM_MSC_FMT" DATA-REQ size %u",
     MSC_AS_TIME_ARGS(ctxt_pP),
     PROTOCOL_RLC_UM_MSC_ARGS(ctxt_pP, rlc_p),
-    ((struct rlc_um_tx_sdu_management*) (sdu_pP->data))->sdu_size);
-
-
-#   if TRACE_RLC_UM_PDU
-  data_offset = sizeof (struct rlc_um_data_req_alloc);
-  data_size   = ((struct rlc_um_tx_sdu_management *)(sdu_pP->data))->sdu_size;
-  message_string_size += sprintf(&message_string[message_string_size], "Bearer      : %u\n", rlc_p->rb_id);
-  message_string_size += sprintf(&message_string[message_string_size], "SDU size    : %u\n", data_size);
-
-  message_string_size += sprintf(&message_string[message_string_size], "\nPayload  : \n");
-  message_string_size += sprintf(&message_string[message_string_size], "------+-------------------------------------------------|\n");
-  message_string_size += sprintf(&message_string[message_string_size], "      |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |\n");
-  message_string_size += sprintf(&message_string[message_string_size], "------+-------------------------------------------------|\n");
+    ((struct rlc_um_tx_sdu_management *) (sdu_pP->data))->sdu_size);
+
+  if (LOG_DEBUGFLAG(DEBUG_RLC) ) {
+    data_offset = sizeof (struct rlc_um_data_req_alloc);
+    data_size = ((struct rlc_um_tx_sdu_management *)(sdu_pP->data))->sdu_size;
+    message_string_size += sprintf(&message_string[message_string_size], "Bearer      : %u\n", rlc_p->rb_id);
+    message_string_size += sprintf(&message_string[message_string_size], "SDU size    : %u\n", data_size);
+    message_string_size += sprintf(&message_string[message_string_size], "\nPayload  : \n");
+    message_string_size += sprintf(&message_string[message_string_size], "------+-------------------------------------------------|\n");
+    message_string_size += sprintf(&message_string[message_string_size], "	|  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |\n");
+    message_string_size += sprintf(&message_string[message_string_size], "------+-------------------------------------------------|\n");
+
+    for (octet_index = 0; octet_index < data_size; octet_index++) {
+      if ((octet_index % 16) == 0) {
+        if (octet_index != 0) {
+          message_string_size += sprintf(&message_string[message_string_size], " |\n");
+        }
 
-  for (octet_index = 0; octet_index < data_size; octet_index++) {
-    if ((octet_index % 16) == 0) {
-      if (octet_index != 0) {
-        message_string_size += sprintf(&message_string[message_string_size], " |\n");
+        message_string_size += sprintf(&message_string[message_string_size], " %04d |", octet_index);
       }
 
-      message_string_size += sprintf(&message_string[message_string_size], " %04d |", octet_index);
+      /*
+       * Print every single octet in hexadecimal form
+       */
+      message_string_size += sprintf(&message_string[message_string_size], " %02x", ((uint8_t *)(&sdu_pP->data[data_offset]))[octet_index]);
+      /*
+       * Align newline and pipes according to the octets in groups of 2
+       */
     }
 
     /*
-     * Print every single octet in hexadecimal form
-     */
-    message_string_size += sprintf(&message_string[message_string_size], " %02x", ((uint8_t*)(&sdu_pP->data[data_offset]))[octet_index]);
-    /*
-     * Align newline and pipes according to the octets in groups of 2
+     * Append enough spaces and put final pipe
      */
-  }
+    for (index = octet_index; index < 16; ++index) {
+      message_string_size += sprintf(&message_string[message_string_size], "   ");
+    }
 
-  /*
-   * Append enough spaces and put final pipe
-   */
-  for (index = octet_index; index < 16; ++index) {
-    message_string_size += sprintf(&message_string[message_string_size], "   ");
+    LOG_UI(RLC, "%s|\n", message_string);
   }
 
-  message_string_size += sprintf(&message_string[message_string_size], " |\n");
-
-#   if ENABLE_ITTI
-  msg_p = itti_alloc_new_message_sized (ctxt_pP->enb_flag > 0 ? TASK_RLC_ENB:TASK_RLC_UE , RLC_UM_SDU_REQ, message_string_size + sizeof (IttiMsgText));
-  msg_p->ittiMsg.rlc_um_sdu_req.size = message_string_size;
-  memcpy(&msg_p->ittiMsg.rlc_um_sdu_req.text, message_string, message_string_size);
-
-  itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
-
-#else
-  LOG_T(RLC, "%s", message_string);
-#endif
-#   endif
   RLC_UM_MUTEX_LOCK(&rlc_p->lock_input_sdus, ctxt_pP, rlc_p);
   rlc_p->buffer_occupancy += ((struct rlc_um_tx_sdu_management *) (sdu_pP->data))->sdu_size;
   list_add_tail_eurecom(sdu_pP, &rlc_p->input_sdus);
   RLC_UM_MUTEX_UNLOCK(&rlc_p->lock_input_sdus);
-#if DEBUG_RLC_CONGESTION
-#if MESSAGE_CHART_GENERATOR
-  if (rlc_p->buffer_occupancy > 4096) {
+
+  if (MESSAGE_CHART_GENERATOR) {
+    if (rlc_p->buffer_occupancy > 4096) {
       MSC_LOG_EVENT((ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,\
-                             "0 "PROTOCOL_RLC_AM_MSC_FMT" BO %u bytes",\
-                             PROTOCOL_RLC_AM_MSC_ARGS(ctxt_pP,rlc_pP), rlc_p->buffer_occupancy);
+                    "0 "PROTOCOL_RLC_AM_MSC_FMT" BO %u bytes",\
+                    PROTOCOL_RLC_AM_MSC_ARGS(ctxt_pP,rlc_p), rlc_p->buffer_occupancy);
+    }
   }
-#else
-  LOG_W(RLC, PROTOCOL_RLC_UM_CTXT_FMT" BO %d , NB SDU %d\n",
+
+  LOG_T(RLC, PROTOCOL_RLC_UM_CTXT_FMT" BO %d , NB SDU %d\n",
         PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP,rlc_p),
         rlc_p->buffer_occupancy,
         rlc_p->input_sdus.nb_elements);
-#endif
-#endif
 }
diff --git a/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_control_primitives.c b/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_control_primitives.c
index b422748292077c29c7591091575a69d77f5ec7b6..6cb849091a5a8ef4a9a68226b8e8f3b4cf617cf5 100644
--- a/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_control_primitives.c
+++ b/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_control_primitives.c
@@ -32,7 +32,7 @@
 #include "common/utils/LOG/log.h"
 
 #include "rlc_um_control_primitives.h"
-#include "T-Reordering.h"
+#include "LTE_T-Reordering.h"
 #include "msc.h"
 
 //-----------------------------------------------------------------------------
@@ -78,10 +78,10 @@ void config_req_rlc_um (
   }
 }
 //-----------------------------------------------------------------------------
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 const uint32_t t_Reordering_tab[32] = {0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,110,120,130,140,150,160,170,180,190,200,1600};
 #else
-const uint32_t t_Reordering_tab[T_Reordering_spare1] = {0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,110,120,130,140,150,160,170,180,190,200};
+const uint32_t t_Reordering_tab[LTE_T_Reordering_spare1] = {0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,110,120,130,140,150,160,170,180,190,200};
 #endif
 
 void config_req_rlc_um_asn1 (
@@ -90,11 +90,11 @@ void config_req_rlc_um_asn1 (
   const MBMS_flag_t         mbms_flagP,
   const mbms_session_id_t   mbms_session_idP,
   const mbms_service_id_t   mbms_service_idP,
-  const UL_UM_RLC_t       * const ul_rlc_pP,
-  const DL_UM_RLC_t       * const dl_rlc_pP,
+  const LTE_UL_UM_RLC_t   * const ul_rlc_pP,
+  const LTE_DL_UM_RLC_t   * const dl_rlc_pP,
   const rb_id_t             rb_idP,
   const logical_chan_id_t   chan_idP
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
  ,const uint32_t            sourceL2Id
  ,const uint32_t            destinationL2Id
 #endif
@@ -108,7 +108,7 @@ void config_req_rlc_um_asn1 (
   hash_key_t       key                 = RLC_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, srb_flagP);
   hashtable_rc_t   h_rc;
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 
   if (mbms_flagP) {
     //AssertFatal(dl_rlc_pP, "No RLC UM DL config");
@@ -173,11 +173,11 @@ void config_req_rlc_um_asn1 (
 
     if (ul_rlc_pP != NULL) {
       switch (ul_rlc_pP->sn_FieldLength) {
-      case SN_FieldLength_size5:
+      case LTE_SN_FieldLength_size5:
         ul_sn_FieldLength = 5;
         break;
 
-      case SN_FieldLength_size10:
+      case LTE_SN_FieldLength_size10:
         ul_sn_FieldLength = 10;
         break;
 
@@ -201,11 +201,11 @@ void config_req_rlc_um_asn1 (
 
     if (dl_rlc_pP != NULL) {
       switch (dl_rlc_pP->sn_FieldLength) {
-      case SN_FieldLength_size5:
+      case LTE_SN_FieldLength_size5:
         dl_sn_FieldLength = 5;
         break;
 
-      case SN_FieldLength_size10:
+      case LTE_SN_FieldLength_size10:
         dl_sn_FieldLength = 10;
         break;
 
@@ -226,7 +226,7 @@ void config_req_rlc_um_asn1 (
         return;
       }
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
       if (dl_rlc_pP->t_Reordering<32) {
 #else
       if (dl_rlc_pP->t_Reordering<T_Reordering_spare1) {
diff --git a/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_control_primitives.h b/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_control_primitives.h
index 524b75fe16dc99ff5995b9d4a3690198d3eb32d7..bf127450503bc471cc476be50926c9d2ff07f37f 100644
--- a/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_control_primitives.h
+++ b/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_control_primitives.h
@@ -40,8 +40,8 @@
 #        include "rlc_um_structs.h"
 #        include "rlc_um_constants.h"
 #        include "platform_types.h"
-#        include "DL-UM-RLC.h"
-#        include "UL-UM-RLC.h"
+#        include "LTE_DL-UM-RLC.h"
+#        include "LTE_UL-UM-RLC.h"
 //-----------------------------------------------------------------------------
 
 typedef volatile struct {
@@ -97,11 +97,11 @@ void config_req_rlc_um_asn1 (
                                       const MBMS_flag_t        mbms_flagP,
                                       const mbms_session_id_t  mbms_session_idP,
                                       const mbms_service_id_t  mbms_service_idP,
-                                      const UL_UM_RLC_t       * const ul_rlc_pP,
-                                      const DL_UM_RLC_t       * const dl_rlc_pP,
+                                      const LTE_UL_UM_RLC_t  * const ul_rlc_pP,
+                                      const LTE_DL_UM_RLC_t  * const dl_rlc_pP,
                                       const rb_id_t            rb_idP,
                                       const logical_chan_id_t  chan_idP
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                                       ,const uint32_t          sourceL2Id
                                       ,const uint32_t          destinationL2Id
 #endif
diff --git a/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_test.c b/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_test.c
index 4d238ea84175da06fa29faaad63813b505c3eafe..fda84879be06681705e62bbd15b1b7fe3f769284 100644
--- a/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_test.c
+++ b/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_test.c
@@ -125,7 +125,7 @@ static int8_t *g_sdus[] = {"En dépit de son volontarisme affiché, le premier m
 #define RLC_2_PRINT_BUFFER_LEN 10000
 static char rlc_2_print_buffer[RLC_2_PRINT_BUFFER_LEN];
 //-----------------------------------------------------------------------------
-void rlc_util_print_hex_octets(comp_name_t componentP, unsigned char* dataP, unsigned long sizeP)
+void rlc_util_print_hex_octets(comp_name_t componentP, unsigned char *dataP, unsigned long sizeP)
 //-----------------------------------------------------------------------------
 {
   unsigned long octet_index = 0;
@@ -136,7 +136,6 @@ void rlc_util_print_hex_octets(comp_name_t componentP, unsigned char* dataP, uns
     return;
   }
 
-
   LOG_D(RLC, "------+-------------------------------------------------|\n");
   LOG_D(RLC, "      |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |\n");
   LOG_D(RLC, "------+-------------------------------------------------|\n");
@@ -149,7 +148,8 @@ void rlc_util_print_hex_octets(comp_name_t componentP, unsigned char* dataP, uns
         buffer_marker = 0;
       }
 
-      buffer_marker+=snprintf(&rlc_2_print_buffer[buffer_marker], RLC_2_PRINT_BUFFER_LEN - buffer_marker, " %04ld |", octet_index);
+      buffer_marker+=snprintf(&rlc_2_print_buffer[buffer_marker], RLC_2_PRINT_BUFFER_LEN - buffer_marker,
+                              " %04lu |", octet_index);
     }
 
     /*
@@ -180,17 +180,13 @@ void rlc_um_v9_3_0_test_windows_10()
   rlc_um_entity_t um1;
   rlc_um_entity_t um2;
   unsigned int    h,w, sn, result;
-
   uint32_t             timer_reordering = 2000;
   uint32_t             sn_field_length  = 10;
   uint32_t             is_mXch          = 0; // boolean, true if configured for MTCH or MCCH
-
   rlc_um_init(&um1);
   rlc_um_init(&um2);
-
   rlc_um_set_debug_infos(&um1, g_frame, 0, 0, 0, 1, 1 /*LC-id = RAB-id*/);
   rlc_um_set_debug_infos(&um2, g_frame, 1, 1, 1, 1, 1 /*LC-id = RAB-id*/);
-
   rlc_um_configure(&um1, g_frame, timer_reordering, sn_field_length, sn_field_length, is_mXch);
   rlc_um_configure(&um2, g_frame, timer_reordering, sn_field_length, sn_field_length, is_mXch);
 
@@ -223,7 +219,6 @@ void rlc_um_v9_3_0_test_windows_10()
         assert(rlc_um_in_window(&um1, g_frame, (um1.vr_uh - um1.rx_um_window_size) & RLC_UM_SN_10_BITS_MASK, sn, (um1.vr_uh -1) & RLC_UM_SN_10_BITS_MASK) < 0);
         assert(rlc_um_in_reordering_window(&um1, g_frame, sn) < 0);
       }
-
     }
   }
 }
@@ -234,17 +229,13 @@ void rlc_um_v9_3_0_test_windows_5()
   rlc_um_entity_t um1;
   rlc_um_entity_t um2;
   unsigned int    h,w, sn, result;
-
   uint32_t             timer_reordering = 2000;
   uint32_t             sn_field_length  = 5;
   uint32_t             is_mXch          = 0; // boolean, true if configured for MTCH or MCCH
-
   rlc_um_init(&um1);
   rlc_um_init(&um2);
-
   rlc_um_set_debug_infos(&um1, g_frame, 0, 0, 0, 1, 1 /* LC-id = DRB-id */);
   rlc_um_set_debug_infos(&um2, g_frame, 1, 1, 1, 1, 1 /* LC-id = DRB-id */);
-
   rlc_um_configure(&um1, g_frame, timer_reordering, sn_field_length, sn_field_length, is_mXch);
   rlc_um_configure(&um2, g_frame, timer_reordering, sn_field_length, sn_field_length, is_mXch);
 
@@ -277,7 +268,6 @@ void rlc_um_v9_3_0_test_windows_5()
         assert(rlc_um_in_window(&um1, g_frame, (um1.vr_uh - um1.rx_um_window_size) & RLC_UM_SN_5_BITS_MASK, sn, (um1.vr_uh -1) & RLC_UM_SN_5_BITS_MASK) < 0);
         assert(rlc_um_in_reordering_window(&um1, g_frame, sn) < 0);
       }
-
     }
   }
 }
@@ -308,25 +298,23 @@ void rlc_um_v9_3_0_test_send_sdu(rlc_um_entity_t *um_txP, int sdu_indexP)
     printf("[FRAME %05d][RLC][MOD %02d][RB %02d] TX SDU %d %04d bytes\n",g_frame,um_txP->module_id, um_txP->rb_id, sdu_indexP, strlen(g_sdus[sdu_indexP]) + 1);
     memset (sdu->data, 0, sizeof (struct rlc_um_data_req_alloc));
     strcpy (&sdu->data[sizeof (struct rlc_um_data_req_alloc)],g_sdus[sdu_indexP]);
-
     ((struct rlc_um_data_req *) (sdu->data))->data_size = strlen(g_sdus[sdu_indexP])+ 1;
     ((struct rlc_um_data_req *) (sdu->data))->data_offset = sizeof (struct rlc_um_data_req_alloc);
     rlc_um_data_req(um_txP, g_frame, sdu);
-
     g_send_sdu_ids[g_send_id_write_index[um_txP->rb_id]++][um_txP->rb_id] = sdu_indexP;
     assert(g_send_id_write_index[um_txP->rb_id] < TEST_MAX_SEND_SDU);
   } else {
     printf("Out of memory error\n");
-//    exit(-1);
+    //    exit(-1);
   }
 }
 
 //-----------------------------------------------------------------------------
-void rlc_um_v9_3_0_buffer_delayed_rx_mac_data_ind(struct mac_data_ind* data_indP, signed int time_delayedP)
+void rlc_um_v9_3_0_buffer_delayed_rx_mac_data_ind(struct mac_data_ind *data_indP, signed int time_delayedP)
 //-----------------------------------------------------------------------------
 {
   int   frame_modulo;
-  mem_block_t* tb;
+  mem_block_t *tb;
 
   if (time_delayedP <= 0) {
     frame_modulo = g_frame % MAX_TIME_DELAYED_PDU_DUE_TO_HARQ;
@@ -351,11 +339,11 @@ void rlc_um_v9_3_0_buffer_delayed_rx_mac_data_ind(struct mac_data_ind* data_indP
   assert(data_indP->data.head == NULL);
 }
 //-----------------------------------------------------------------------------
-void rlc_um_v9_3_0_buffer_delayed_tx_mac_data_ind(struct mac_data_ind* data_indP, signed int time_delayedP)
+void rlc_um_v9_3_0_buffer_delayed_tx_mac_data_ind(struct mac_data_ind *data_indP, signed int time_delayedP)
 //-----------------------------------------------------------------------------
 {
   int   frame_modulo;
-  mem_block_t* tb;
+  mem_block_t *tb;
 
   if (time_delayedP <= 0) {
     frame_modulo = g_frame % MAX_TIME_DELAYED_PDU_DUE_TO_HARQ;
@@ -381,16 +369,13 @@ void rlc_um_v9_3_0_buffer_delayed_tx_mac_data_ind(struct mac_data_ind* data_indP
 }
 
 //-----------------------------------------------------------------------------
-void rlc_um_v9_3_0_test_mac_rlc_loop (struct mac_data_ind* data_indP,  struct mac_data_req* data_requestP, int* drop_countP, int* tx_packetsP,
-                                      int* dropped_tx_packetsP)
+void rlc_um_v9_3_0_test_mac_rlc_loop (struct mac_data_ind *data_indP,  struct mac_data_req *data_requestP, int *drop_countP, int *tx_packetsP,
+                                      int *dropped_tx_packetsP)
 //-----------------------------------------------------------------------------
 {
-
-
-  mem_block_t* tb_src;
-  mem_block_t* tb_dst;
+  mem_block_t *tb_src;
+  mem_block_t *tb_dst;
   unsigned int tb_size;
-
   data_indP->no_tb = 0;
 
   while (data_requestP->data.nb_elements > 0) {
@@ -398,14 +383,14 @@ void rlc_um_v9_3_0_test_mac_rlc_loop (struct mac_data_ind* data_indP,  struct ma
 
     if (tb_src != NULL) {
       tb_size = ((struct mac_tb_req *) (tb_src->data))->tb_size_in_bits >> 3;
-      printf("[RLC-LOOP] FOUND TB SIZE IN BITS %d IN BYTES %d sizeof (mac_rlc_max_rx_header_size_t) %d\n",
+      printf("[RLC-LOOP] FOUND TB SIZE IN BITS %d IN BYTES %u sizeof (mac_rlc_max_rx_header_size_t) %d\n",
              ((struct mac_tb_req *) (tb_src->data))->tb_size_in_bits,
              tb_size, sizeof (mac_rlc_max_rx_header_size_t));
-
       *tx_packetsP = *tx_packetsP + 1;
 
       if (*drop_countP == 0) {
         tb_dst  = get_free_mem_block(sizeof (mac_rlc_max_rx_header_size_t) + tb_size, __func__);
+
         if (tb_dst != NULL) {
           memset(tb_dst->data, 0, sizeof (mac_rlc_max_rx_header_size_t) + tb_size);
           //printf("[RLC-LOOP] Testing tb_dst (1)\n");
@@ -415,18 +400,16 @@ void rlc_um_v9_3_0_test_mac_rlc_loop (struct mac_data_ind* data_indP,  struct ma
           ((struct mac_tb_ind *) (tb_dst->data))->data_ptr         = &tb_dst->data[sizeof (mac_rlc_max_rx_header_size_t)];
           ((struct mac_tb_ind *) (tb_dst->data))->size             = tb_size;
           ((struct mac_tb_ind *) (tb_dst->data))->error_indication = 0;
-
           memcpy(((struct mac_tb_ind *) (tb_dst->data))->data_ptr,
                  &((struct mac_tb_req *) (tb_src->data))->data_ptr[0],
                  tb_size);
-
           list_add_tail_eurecom(tb_dst, &data_indP->data);
           data_indP->no_tb  += 1;
           //printf("[RLC-LOOP] Testing tb_dst (2)\n");
           check_free_mem_block(tb_dst, __func__);
         } else {
           printf("Out of memory error\n");
-//          exit(-1);
+          //          exit(-1);
         }
       } else {
         printf("[RLC-LOOP] DROPPING 1 TB\n");
@@ -434,10 +417,8 @@ void rlc_um_v9_3_0_test_mac_rlc_loop (struct mac_data_ind* data_indP,  struct ma
         *dropped_tx_packetsP = *dropped_tx_packetsP + 1;
       }
 
-
       //printf("[RLC-LOOP] Testing tb_src\n");
       check_free_mem_block(tb_src, __func__);
-
       free_mem_block(tb_src, __func__);
 
       if (data_indP->no_tb > 0) {
@@ -460,8 +441,6 @@ void rlc_um_v9_3_0_test_exchange_pdus(rlc_um_entity_t *um_txP,
   struct mac_status_ind  tx_status;
   struct mac_status_resp mac_rlc_status_resp_tx;
   struct mac_status_resp mac_rlc_status_resp_rx;
-
-
   memset(&data_request_tx, 0, sizeof(struct mac_data_req));
   memset(&data_request_rx, 0, sizeof(struct mac_data_req));
   memset(&data_ind_tx,     0, sizeof(struct mac_data_ind));
@@ -469,13 +448,10 @@ void rlc_um_v9_3_0_test_exchange_pdus(rlc_um_entity_t *um_txP,
   memset(&tx_status,       0, sizeof(struct mac_status_ind));
   memset(&mac_rlc_status_resp_tx, 0, sizeof(struct mac_status_resp));
   memset(&mac_rlc_status_resp_rx, 0, sizeof(struct mac_status_resp));
-
   mac_rlc_status_resp_tx = rlc_um_mac_status_indication(um_txP, g_frame, 1, bytes_txP, tx_status,ENB_FLAG_YES);
   data_request_tx        = rlc_um_mac_data_request(um_txP, g_frame);
   mac_rlc_status_resp_rx = rlc_um_mac_status_indication(um_rxP, g_frame, 0, bytes_rxP, tx_status,ENB_FLAG_YES);
   data_request_rx        = rlc_um_mac_data_request(um_rxP, g_frame);
-
-
   rlc_um_v9_3_0_test_mac_rlc_loop(&data_ind_rx, &data_request_tx, &g_drop_tx, &g_tx_packets, &g_dropped_tx_packets);
   rlc_um_v9_3_0_test_mac_rlc_loop(&data_ind_tx, &data_request_rx, &g_drop_rx, &g_rx_packets, &g_dropped_rx_packets);
   rlc_um_mac_data_indication(um_rxP, g_frame, um_rxP->is_enb, data_ind_rx);
@@ -506,8 +482,6 @@ void rlc_um_v9_3_0_test_exchange_delayed_pdus(rlc_um_entity_t *um_txP,
   struct mac_status_resp mac_rlc_status_resp_tx;
   struct mac_status_resp mac_rlc_status_resp_rx;
   int                    frame_modulo = g_frame % MAX_TIME_DELAYED_PDU_DUE_TO_HARQ;
-
-
   memset(&data_request_tx, 0, sizeof(struct mac_data_req));
   memset(&data_request_rx, 0, sizeof(struct mac_data_req));
   memset(&data_ind_tx,     0, sizeof(struct mac_data_ind));
@@ -515,23 +489,16 @@ void rlc_um_v9_3_0_test_exchange_delayed_pdus(rlc_um_entity_t *um_txP,
   memset(&tx_status,       0, sizeof(struct mac_status_ind));
   memset(&mac_rlc_status_resp_tx, 0, sizeof(struct mac_status_resp));
   memset(&mac_rlc_status_resp_rx, 0, sizeof(struct mac_status_resp));
-
   mac_rlc_status_resp_tx = rlc_um_mac_status_indication(um_txP, g_frame, 1, bytes_txP, tx_status,ENB_FLAG_YES);
   data_request_tx        = rlc_um_mac_data_request(um_txP, g_frame);
   mac_rlc_status_resp_rx = rlc_um_mac_status_indication(um_rxP, g_frame, 0, bytes_rxP, tx_status,ENB_FLAG_YES);
   data_request_rx        = rlc_um_mac_data_request(um_rxP, g_frame);
-
-
   rlc_um_v9_3_0_test_mac_rlc_loop(&data_ind_rx, &data_request_tx, &g_drop_tx, &g_tx_packets, &g_dropped_tx_packets);
   rlc_um_v9_3_0_test_mac_rlc_loop(&data_ind_tx, &data_request_rx, &g_drop_rx, &g_rx_packets, &g_dropped_rx_packets);
-
   rlc_um_v9_3_0_buffer_delayed_rx_mac_data_ind(&data_ind_rx, time_tx_delayedP);
   rlc_um_v9_3_0_buffer_delayed_tx_mac_data_ind(&data_ind_tx, time_rx_delayedP);
-
-
   rlc_um_mac_data_indication(um_rxP, g_frame, um_rxP->is_enb, g_rx_delayed_indications[frame_modulo]);
   memset(&g_rx_delayed_indications[frame_modulo], 0, sizeof(struct mac_data_ind));
-
   rlc_um_mac_data_indication(um_txP, g_frame, um_txP->is_enb, g_tx_delayed_indications[frame_modulo]);
   memset(&g_tx_delayed_indications[frame_modulo], 0, sizeof(struct mac_data_ind));
 
@@ -564,14 +531,12 @@ void rlc_um_v9_3_0_test_data_ind (module_id_t module_idP, rb_id_t rb_idP, sdu_si
         assert(g_send_id_write_index[rb_idP^1] > g_send_id_read_index[rb_idP]);
 
         if (g_send_sdu_ids[g_send_id_read_index[rb_idP]][rb_idP^1] != i) {
-
           printf("[FRAME %05d][RLC][MOD %d][RB %d][DATA-IND] g_send_sdu_ids[%d] = %d\n",g_frame,module_idP, rb_idP,  g_send_id_read_index[rb_idP]-2,
                  g_send_sdu_ids[g_send_id_read_index[rb_idP]-2][rb_idP^1]);
           printf("[FRAME %05d][RLC][MOD %d][RB %d][DATA-IND] g_send_sdu_ids[%d] = %d\n",g_frame,module_idP, rb_idP,  g_send_id_read_index[rb_idP]-1,
                  g_send_sdu_ids[g_send_id_read_index[rb_idP]-1][rb_idP^1]);
           printf("[FRAME %05d][RLC][MOD %d][RB %d][DATA-IND] g_send_sdu_ids[%d] = %d\n",g_frame,module_idP, rb_idP,  g_send_id_read_index[rb_idP],
                  g_send_sdu_ids[g_send_id_read_index[rb_idP]][rb_idP^1]);
-
           printf("[FRAME %05d][RLC][MOD %d][RB %d][DATA-IND] g_send_id_read_index = %d sdu sent = %d\n",g_frame,module_idP, rb_idP,  g_send_id_read_index[rb_idP], i);
         }
 
@@ -607,23 +572,15 @@ void rlc_um_v9_3_0_test_reordering(uint32_t sn_field_lengthP)
 {
   rlc_um_info_t     um_info;
   int                   i,j,r;
-
   um_info.timer_reordering = (32 * sn_field_lengthP * sn_field_lengthP)/100;
   um_info.sn_field_length  = sn_field_lengthP;
   um_info.is_mXch          = 0;
-
   srand (0);
   config_req_rlc_um (&um_tx, 0,0,0, &um_info, 0, SIGNALLING_RADIO_BEARER, SIGNALLING_RADIO_BEARER /*LC-id = DRB-id*/);
   config_req_rlc_um (&um_rx, 0,1,1, &um_info, 1, SIGNALLING_RADIO_BEARER, SIGNALLING_RADIO_BEARER /*LC-id = DRB-id*/);
-
   rlc_um_display_rx_window(&um_tx);
-
   rlc_um_display_rx_window(&um_rx);
-
-
   srand (0);
-
-
   // BIG SDU SMALL PDUS NO ERRORS
   rlc_um_v9_3_0_test_reset_sdus();
 
@@ -665,21 +622,16 @@ void rlc_um_v9_3_0_test_reordering(uint32_t sn_field_lengthP)
     rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 2000, 200, 0, 0, INCREMENT_FRAME_YES);
     rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 2000, 200, 0, 0, INCREMENT_FRAME_YES);
     rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 2000, 200, 0, 0, INCREMENT_FRAME_YES);
-
     assert (g_send_id_read_index[1] == g_send_id_write_index[0]);
     printf("\n\n\n\n\n\n\n\n");
-
   }
 
   printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_um_v9_3_0_test_reordering 3: END OF TEST BIG SDU, SMALL PDUs\n\n\n\n");
-
   rlc_um_v9_3_0_test_reset_sdus();
 
   for (j = 0; j < 16; j++) {
     //i = getchar();
-
     rlc_um_v9_3_0_test_reset_sdus();
-
     rlc_um_v9_3_0_test_send_sdu(&um_tx, 1);
 
     for (i = 0; i < 32; i++) {
@@ -688,8 +640,6 @@ void rlc_um_v9_3_0_test_reordering(uint32_t sn_field_lengthP)
 
     rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 2000, 200, 0, 0, INCREMENT_FRAME_YES);
     assert (g_send_id_read_index[1] == g_send_id_write_index[0]);
-
-
     rlc_um_v9_3_0_test_send_sdu(&um_tx, 1);
     rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 3, 200, 0, 0, INCREMENT_FRAME_YES);
     rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 3, 200, 0, 0, INCREMENT_FRAME_YES);
@@ -702,7 +652,6 @@ void rlc_um_v9_3_0_test_reordering(uint32_t sn_field_lengthP)
     rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 2000, 200, 0, 0, INCREMENT_FRAME_YES);
     printf("g_send_id_read_index[1]=%d g_send_id_write_index[0]=%d Loop %d (1)\n", g_send_id_read_index[1], g_send_id_write_index[0], j);
     assert (g_send_id_read_index[1] != g_send_id_write_index[0]);
-
     rlc_um_v9_3_0_test_send_sdu(&um_tx, 1);
     rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 3, 200, 0, 0, INCREMENT_FRAME_YES);
 
@@ -716,7 +665,6 @@ void rlc_um_v9_3_0_test_reordering(uint32_t sn_field_lengthP)
 
     rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 2000, 200, 0, 0, INCREMENT_FRAME_YES);
     printf("g_send_id_read_index[1]=%d g_send_id_write_index[0]=%d Loop %d (2)\n", g_send_id_read_index[1], g_send_id_write_index[0], j);
-
     assert (g_send_id_read_index[1] != g_send_id_write_index[0]);
   }
 
@@ -728,21 +676,14 @@ void rlc_um_v9_3_0_test_tx_rx_10(void)
 {
   rlc_um_info_t     um_info;
   int                   i,j,r;
-
-
   um_info.timer_reordering = 32;
   um_info.sn_field_length  = 10;
   um_info.is_mXch          = 0;
-
   srand (0);
   config_req_rlc_um (&um_tx, 0,0,0, &um_info, 0, SIGNALLING_RADIO_BEARER, SIGNALLING_RADIO_BEARER /*LC-id = DRB-id*/);
   config_req_rlc_um (&um_rx, 0,1,1, &um_info, 1, SIGNALLING_RADIO_BEARER, SIGNALLING_RADIO_BEARER /*LC-id = DRB-id*/);
-
   rlc_um_display_rx_window(&um_tx);
-
   rlc_um_display_rx_window(&um_rx);
-
-
 #ifdef TEST1
   srand (0);
   rlc_um_v9_3_0_test_reset_sdus();
@@ -765,7 +706,6 @@ void rlc_um_v9_3_0_test_tx_rx_10(void)
   rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 1000, 200);
   rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 1000, 200);
   rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 1000, 200);
-
   assert (g_send_id_read_index[1] == g_send_id_write_index[0]);
   printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_um_v9_3_0_test 1: END OF SIMPLE TEST SEVERAL SDUs IN PDU\n\n\n\n");
   sleep(2);
@@ -837,7 +777,6 @@ void rlc_um_v9_3_0_test_tx_rx_10(void)
   rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 2000, 200);
   rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 2000, 200);
   rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 2000, 200);
-
   rlc_um_v9_3_0_test_send_sdu(&um_tx, 1);
   rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 30, 200);
   rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 31, 200);
@@ -983,8 +922,6 @@ void rlc_um_v9_3_0_test_tx_rx_10(void)
           rlc_um_v9_3_0_test_send_sdu(&um_tx, g_random_sdu);
           g_random_sdu = rand() % 37;
           //rlc_um_v9_3_0_test_send_sdu(&um_rx, g_random_sdu);
-
-
           g_random_nb_frames   = rand() % 4;
 
           for (j = 0; j < g_random_nb_frames; j++) {
@@ -995,7 +932,6 @@ void rlc_um_v9_3_0_test_tx_rx_10(void)
 
           //rlc_um_display_rx_window(&um_tx);
           rlc_um_display_rx_window(&um_rx);
-
           int dropped = (rand() % 3);
 
           if ((dropped == 0) && (g_tx_packets > 0)) {
@@ -1028,7 +964,6 @@ void rlc_um_v9_3_0_test_tx_rx_10(void)
                g_target_tx_error_rate,
                (g_rx_packets >0)?(g_dropped_rx_packets*100)/g_rx_packets:0,
                g_target_rx_error_rate);
-
       }
     }
 
@@ -1057,21 +992,14 @@ void rlc_um_v9_3_0_test_tx_rx_5(void)
 {
   rlc_um_info_t     um_info;
   int                   i,j,r;
-
-
   um_info.timer_reordering = 32;
   um_info.sn_field_length  = 5;
   um_info.is_mXch          = 0;
-
   srand (0);
   config_req_rlc_um (&um_tx, 0,0,0, &um_info, 0, SIGNALLING_RADIO_BEARER, SIGNALLING_RADIO_BEARER /*LC-id = DRB-id*/);
   config_req_rlc_um (&um_rx, 0,1,1, &um_info, 1, SIGNALLING_RADIO_BEARER, SIGNALLING_RADIO_BEARER /*LC-id = DRB-id*/);
-
   rlc_um_display_rx_window(&um_tx);
-
   rlc_um_display_rx_window(&um_rx);
-
-
 #ifdef TEST1
   srand (0);
   printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_um_v9_3_0_test_5 1: START OF SIMPLE TEST SEVERAL SDUs IN PDU\n\n\n\n");
@@ -1095,7 +1023,6 @@ void rlc_um_v9_3_0_test_tx_rx_5(void)
   rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 1000, 200);
   rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 1000, 200);
   rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 1000, 200);
-
   assert (g_send_id_read_index[1] == g_send_id_write_index[0]);
   printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_um_v9_3_0_test_5 1: END OF SIMPLE TEST SEVERAL SDUs IN PDU\n\n\n\n");
   sleep(2);
@@ -1163,7 +1090,6 @@ void rlc_um_v9_3_0_test_tx_rx_5(void)
   rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 2000, 200);
   rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 2000, 200);
   rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 2000, 200);
-
   rlc_um_v9_3_0_test_send_sdu(&um_tx, 1);
   rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 26, 200);
   rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 27, 200);
@@ -1301,8 +1227,6 @@ void rlc_um_v9_3_0_test_tx_rx_5(void)
           rlc_um_v9_3_0_test_send_sdu(&um_tx, g_random_sdu);
           g_random_sdu = rand() % 37;
           //rlc_um_v9_3_0_test_send_sdu(&um_rx, g_random_sdu);
-
-
           g_random_nb_frames   = rand() % 4;
 
           for (j = 0; j < g_random_nb_frames; j++) {
@@ -1313,7 +1237,6 @@ void rlc_um_v9_3_0_test_tx_rx_5(void)
 
           //rlc_um_display_rx_window(&um_tx);
           rlc_um_display_rx_window(&um_rx);
-
           int dropped = (rand() % 3);
 
           if ((dropped == 0) && (g_tx_packets > 0)) {
@@ -1346,7 +1269,6 @@ void rlc_um_v9_3_0_test_tx_rx_5(void)
                g_target_tx_error_rate,
                (g_rx_packets >0)?(g_dropped_rx_packets*100)/g_rx_packets:0,
                g_target_rx_error_rate);
-
       }
     }
 
@@ -1378,11 +1300,9 @@ void rlc_um_v9_3_0_test_print_trace (void)
   size_t size;
   char **strings;
   size_t i;
-
   size = backtrace (array, 100);
   strings = backtrace_symbols (array, size);
-
-  printf ("Obtained %d stack frames.\n", size);
+  printf ("Obtained %lu stack frames.\n", (unsigned long)size);
 
   for (i = 0; i < size; i++) {
     printf ("%s\n", strings[i]);
@@ -1395,23 +1315,15 @@ void rlc_um_v9_3_0_test(void)
 //-----------------------------------------------------------------------------
 {
   pool_buffer_init();
-
   set_comp_log(RLC, LOG_TRACE, LOG_MED, 1);
-
-
   // tested OK
   rlc_um_v9_3_0_test_reordering(10);
-
   rlc_um_v9_3_0_test_tx_rx_10();
-
   // tested OK
   rlc_um_v9_3_0_test_windows_10();
-
   rlc_um_v9_3_0_test_tx_rx_5();
   rlc_um_v9_3_0_test_windows_5();
   rlc_um_v9_3_0_test_reordering(5);
-
-
   printf("rlc_um_v9_3_0_test: END OF TESTS\n");
   exit(0);
 }
diff --git a/openair2/LAYER2/RLC/rlc.c b/openair2/LAYER2/RLC/rlc.c
index 8ffe80c9f90c2c288c6e8c50f2a71e030bcf4d72..16e344555cc8c81cd68fd806158b15482f6afdc1 100644
--- a/openair2/LAYER2/RLC/rlc.c
+++ b/openair2/LAYER2/RLC/rlc.c
@@ -34,19 +34,19 @@
 #include "common/utils/LOG/log.h"
 #include "UTIL/OCG/OCG_vars.h"
 #include "common/utils/LOG/vcd_signal_dumper.h"
-
+#include "targets/COMMON/openairinterface5g_limits.h"
 #include "assertions.h"
 
 #include "common/ran_context.h"
 extern RAN_CONTEXT_t RC;
 
 extern boolean_t pdcp_data_ind(
-  const protocol_ctxt_t* const ctxt_pP,
+  const protocol_ctxt_t *const ctxt_pP,
   const srb_flag_t srb_flagP,
   const MBMS_flag_t MBMS_flagP,
   const rb_id_t rb_idP,
   const sdu_size_t sdu_buffer_sizeP,
-  mem_block_t* const sdu_buffer_pP);
+  mem_block_t *const sdu_buffer_pP);
 
 #define DEBUG_RLC_PDCP_INTERFACE 1
 //#define TRACE_RLC_PAYLOAD 1
@@ -57,7 +57,7 @@ extern boolean_t pdcp_data_ind(
 #include "proto_agent.h"
 
 //-----------------------------------------------------------------------------
-void rlc_util_print_hex_octets(comp_name_t componentP, unsigned char* dataP, const signed long sizeP)
+void rlc_util_print_hex_octets(comp_name_t componentP, unsigned char *dataP, const signed long sizeP)
 //-----------------------------------------------------------------------------
 {
   unsigned long octet_index = 0;
@@ -66,9 +66,6 @@ void rlc_util_print_hex_octets(comp_name_t componentP, unsigned char* dataP, con
     return;
   }
 
-
-
-
   LOG_T(componentP, "+-----+-------------------------------------------------+\n");
   LOG_T(componentP, "|     |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |\n");
   LOG_T(componentP, "+-----+-------------------------------------------------+\n");
@@ -105,38 +102,37 @@ void rlc_util_print_hex_octets(comp_name_t componentP, unsigned char* dataP, con
 
 //-----------------------------------------------------------------------------
 rlc_op_status_t rlc_stat_req     (
-  const protocol_ctxt_t* const ctxt_pP,
+  const protocol_ctxt_t *const ctxt_pP,
   const srb_flag_t    srb_flagP,
   const rb_id_t       rb_idP,
-  unsigned int* stat_rlc_mode,
-  unsigned int* stat_tx_pdcp_sdu,
-  unsigned int* stat_tx_pdcp_bytes,
-  unsigned int* stat_tx_pdcp_sdu_discarded,
-  unsigned int* stat_tx_pdcp_bytes_discarded,
-  unsigned int* stat_tx_data_pdu,
-  unsigned int* stat_tx_data_bytes,
-  unsigned int* stat_tx_retransmit_pdu_by_status,
-  unsigned int* stat_tx_retransmit_bytes_by_status,
-  unsigned int* stat_tx_retransmit_pdu,
-  unsigned int* stat_tx_retransmit_bytes,
-  unsigned int* stat_tx_control_pdu,
-  unsigned int* stat_tx_control_bytes,
-  unsigned int* stat_rx_pdcp_sdu,
-  unsigned int* stat_rx_pdcp_bytes,
-  unsigned int* stat_rx_data_pdus_duplicate,
-  unsigned int* stat_rx_data_bytes_duplicate,
-  unsigned int* stat_rx_data_pdu,
-  unsigned int* stat_rx_data_bytes,
-  unsigned int* stat_rx_data_pdu_dropped,
-  unsigned int* stat_rx_data_bytes_dropped,
-  unsigned int* stat_rx_data_pdu_out_of_window,
-  unsigned int* stat_rx_data_bytes_out_of_window,
-  unsigned int* stat_rx_control_pdu,
-  unsigned int* stat_rx_control_bytes,
-  unsigned int* stat_timer_reordering_timed_out,
-  unsigned int* stat_timer_poll_retransmit_timed_out,
-  unsigned int* stat_timer_status_prohibit_timed_out)
-{
+  unsigned int *stat_rlc_mode,
+  unsigned int *stat_tx_pdcp_sdu,
+  unsigned int *stat_tx_pdcp_bytes,
+  unsigned int *stat_tx_pdcp_sdu_discarded,
+  unsigned int *stat_tx_pdcp_bytes_discarded,
+  unsigned int *stat_tx_data_pdu,
+  unsigned int *stat_tx_data_bytes,
+  unsigned int *stat_tx_retransmit_pdu_by_status,
+  unsigned int *stat_tx_retransmit_bytes_by_status,
+  unsigned int *stat_tx_retransmit_pdu,
+  unsigned int *stat_tx_retransmit_bytes,
+  unsigned int *stat_tx_control_pdu,
+  unsigned int *stat_tx_control_bytes,
+  unsigned int *stat_rx_pdcp_sdu,
+  unsigned int *stat_rx_pdcp_bytes,
+  unsigned int *stat_rx_data_pdus_duplicate,
+  unsigned int *stat_rx_data_bytes_duplicate,
+  unsigned int *stat_rx_data_pdu,
+  unsigned int *stat_rx_data_bytes,
+  unsigned int *stat_rx_data_pdu_dropped,
+  unsigned int *stat_rx_data_bytes_dropped,
+  unsigned int *stat_rx_data_pdu_out_of_window,
+  unsigned int *stat_rx_data_bytes_out_of_window,
+  unsigned int *stat_rx_control_pdu,
+  unsigned int *stat_rx_control_bytes,
+  unsigned int *stat_timer_reordering_timed_out,
+  unsigned int *stat_timer_poll_retransmit_timed_out,
+  unsigned int *stat_timer_status_prohibit_timed_out) {
   //-----------------------------------------------------------------------------
   rlc_mode_t             rlc_mode        = RLC_MODE_NONE;
   rlc_union_t           *rlc_union_p     = NULL;
@@ -144,182 +140,183 @@ rlc_op_status_t rlc_stat_req     (
   hashtable_rc_t         h_rc;
 
   //AssertFatal (rb_idP < NB_RB_MAX, "RB id is too high (%u/%d)!\n", rb_idP, NB_RB_MAX);
-	if(rb_idP >= NB_RB_MAX){
-		LOG_E(RLC, "RB id is too high (%u/%d)!\n", rb_idP, NB_RB_MAX);
-		return RLC_OP_STATUS_BAD_PARAMETER;
-	}
-	
+  if(rb_idP >= NB_RB_MAX) {
+    LOG_E(RLC, "RB id is too high (%u/%d)!\n", rb_idP, NB_RB_MAX);
+    return RLC_OP_STATUS_BAD_PARAMETER;
+  }
+
   key = RLC_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, srb_flagP);
-  h_rc = hashtable_get(rlc_coll_p, key, (void**)&rlc_union_p);
+  h_rc = hashtable_get(rlc_coll_p, key, (void **)&rlc_union_p);
 
   if (h_rc == HASH_TABLE_OK) {
     rlc_mode = rlc_union_p->mode;
   }
+
   *stat_rlc_mode                     = rlc_mode;
+
   switch (rlc_mode) {
-  case RLC_MODE_NONE:
-    *stat_tx_pdcp_sdu                     = 0;
-    *stat_tx_pdcp_bytes                   = 0;
-    *stat_tx_pdcp_sdu_discarded           = 0;
-    *stat_tx_pdcp_bytes_discarded         = 0;
-    *stat_tx_data_pdu                     = 0;
-    *stat_tx_data_bytes                   = 0;
-    *stat_tx_retransmit_pdu_by_status     = 0;
-    *stat_tx_retransmit_bytes_by_status   = 0;
-    *stat_tx_retransmit_pdu               = 0;
-    *stat_tx_retransmit_bytes             = 0;
-    *stat_tx_control_pdu                  = 0;
-    *stat_tx_control_bytes                = 0;
-    *stat_rx_pdcp_sdu                     = 0;
-    *stat_rx_pdcp_bytes                   = 0;
-    *stat_rx_data_pdus_duplicate          = 0;
-    *stat_rx_data_bytes_duplicate         = 0;
-    *stat_rx_data_pdu                     = 0;
-    *stat_rx_data_bytes                   = 0;
-    *stat_rx_data_pdu_dropped             = 0;
-    *stat_rx_data_bytes_dropped           = 0;
-    *stat_rx_data_pdu_out_of_window       = 0;
-    *stat_rx_data_bytes_out_of_window     = 0;
-    *stat_rx_control_pdu                  = 0;
-    *stat_rx_control_bytes                = 0;
-    *stat_timer_reordering_timed_out      = 0;
-    *stat_timer_poll_retransmit_timed_out = 0;
-    *stat_timer_status_prohibit_timed_out = 0;
-    return RLC_OP_STATUS_BAD_PARAMETER;
-    break;
-
-  case RLC_MODE_AM:
-    rlc_am_stat_req(ctxt_pP,
-                    &rlc_union_p->rlc.am,
-                    stat_tx_pdcp_sdu,
-                    stat_tx_pdcp_bytes,
-                    stat_tx_pdcp_sdu_discarded,
-                    stat_tx_pdcp_bytes_discarded,
-                    stat_tx_data_pdu,
-                    stat_tx_data_bytes,
-                    stat_tx_retransmit_pdu_by_status,
-                    stat_tx_retransmit_bytes_by_status,
-                    stat_tx_retransmit_pdu,
-                    stat_tx_retransmit_bytes,
-                    stat_tx_control_pdu,
-                    stat_tx_control_bytes,
-                    stat_rx_pdcp_sdu,
-                    stat_rx_pdcp_bytes,
-                    stat_rx_data_pdus_duplicate,
-                    stat_rx_data_bytes_duplicate,
-                    stat_rx_data_pdu,
-                    stat_rx_data_bytes,
-                    stat_rx_data_pdu_dropped,
-                    stat_rx_data_bytes_dropped,
-                    stat_rx_data_pdu_out_of_window,
-                    stat_rx_data_bytes_out_of_window,
-                    stat_rx_control_pdu,
-                    stat_rx_control_bytes,
-                    stat_timer_reordering_timed_out,
-                    stat_timer_poll_retransmit_timed_out,
-                    stat_timer_status_prohibit_timed_out);
-    return RLC_OP_STATUS_OK;
-    break;
-
-  case RLC_MODE_UM:
-    *stat_tx_retransmit_pdu_by_status     = 0;
-    *stat_tx_retransmit_bytes_by_status   = 0;
-    *stat_tx_retransmit_pdu               = 0;
-    *stat_tx_retransmit_bytes             = 0;
-    *stat_tx_control_pdu                  = 0;
-    *stat_tx_control_bytes                = 0;
-    *stat_rx_data_pdu_dropped             = 0;
-    *stat_rx_data_bytes_dropped           = 0;
-    *stat_rx_data_pdu_out_of_window       = 0;
-    *stat_rx_data_bytes_out_of_window     = 0;
-    *stat_timer_poll_retransmit_timed_out = 0;
-    *stat_timer_status_prohibit_timed_out = 0;
-    rlc_um_stat_req (&rlc_union_p->rlc.um,
-                     stat_tx_pdcp_sdu,
-                     stat_tx_pdcp_bytes,
-                     stat_tx_pdcp_sdu_discarded,
-                     stat_tx_pdcp_bytes_discarded,
-                     stat_tx_data_pdu,
-                     stat_tx_data_bytes,
-                     stat_rx_pdcp_sdu,
-                     stat_rx_pdcp_bytes,
-                     stat_rx_data_pdus_duplicate,
-                     stat_rx_data_bytes_duplicate,
-                     stat_rx_data_pdu,
-                     stat_rx_data_bytes,
-                     stat_rx_data_pdu_dropped,
-                     stat_rx_data_bytes_dropped,
-                     stat_rx_data_pdu_out_of_window,
-                     stat_rx_data_bytes_out_of_window,
-                     stat_timer_reordering_timed_out);
-    return RLC_OP_STATUS_OK;
-    break;
-
-  case RLC_MODE_TM:
-    *stat_tx_pdcp_sdu                     = 0;
-    *stat_tx_pdcp_bytes                   = 0;
-    *stat_tx_pdcp_sdu_discarded           = 0;
-    *stat_tx_pdcp_bytes_discarded         = 0;
-    *stat_tx_data_pdu                     = 0;
-    *stat_tx_data_bytes                   = 0;
-    *stat_tx_retransmit_pdu_by_status     = 0;
-    *stat_tx_retransmit_bytes_by_status   = 0;
-    *stat_tx_retransmit_pdu               = 0;
-    *stat_tx_retransmit_bytes             = 0;
-    *stat_tx_control_pdu                  = 0;
-    *stat_tx_control_bytes                = 0;
-    *stat_rx_pdcp_sdu                     = 0;
-    *stat_rx_pdcp_bytes                   = 0;
-    *stat_rx_data_pdus_duplicate          = 0;
-    *stat_rx_data_bytes_duplicate         = 0;
-    *stat_rx_data_pdu                     = 0;
-    *stat_rx_data_bytes                   = 0;
-    *stat_rx_data_pdu_dropped             = 0;
-    *stat_rx_data_bytes_dropped           = 0;
-    *stat_rx_data_pdu_out_of_window       = 0;
-    *stat_rx_data_bytes_out_of_window     = 0;
-    *stat_rx_control_pdu                  = 0;
-    *stat_rx_control_bytes                = 0;
-    *stat_timer_reordering_timed_out      = 0;
-    *stat_timer_poll_retransmit_timed_out = 0;
-    *stat_timer_status_prohibit_timed_out = 0;
-    return RLC_OP_STATUS_BAD_PARAMETER;
-    break;
-
-  default:
-    *stat_tx_pdcp_sdu                     = 0;
-    *stat_tx_pdcp_bytes                   = 0;
-    *stat_tx_pdcp_sdu_discarded           = 0;
-    *stat_tx_pdcp_bytes_discarded         = 0;
-    *stat_tx_data_pdu                     = 0;
-    *stat_tx_data_bytes                   = 0;
-    *stat_tx_retransmit_pdu_by_status     = 0;
-    *stat_tx_retransmit_bytes_by_status   = 0;
-    *stat_tx_retransmit_pdu               = 0;
-    *stat_tx_retransmit_bytes             = 0;
-    *stat_tx_control_pdu                  = 0;
-    *stat_tx_control_bytes                = 0;
-    *stat_rx_pdcp_sdu                     = 0;
-    *stat_rx_pdcp_bytes                   = 0;
-    *stat_rx_data_pdus_duplicate          = 0;
-    *stat_rx_data_bytes_duplicate         = 0;
-    *stat_rx_data_pdu                     = 0;
-    *stat_rx_data_bytes                   = 0;
-    *stat_rx_data_pdu_dropped             = 0;
-    *stat_rx_data_bytes_dropped           = 0;
-    *stat_rx_data_pdu_out_of_window       = 0;
-    *stat_rx_data_bytes_out_of_window     = 0;
-    *stat_rx_control_pdu                  = 0;
-    *stat_rx_control_bytes                = 0;
-
-    *stat_timer_poll_retransmit_timed_out = 0;
-    *stat_timer_status_prohibit_timed_out = 0;
-    return RLC_OP_STATUS_BAD_PARAMETER;
+    case RLC_MODE_NONE:
+      *stat_tx_pdcp_sdu                     = 0;
+      *stat_tx_pdcp_bytes                   = 0;
+      *stat_tx_pdcp_sdu_discarded           = 0;
+      *stat_tx_pdcp_bytes_discarded         = 0;
+      *stat_tx_data_pdu                     = 0;
+      *stat_tx_data_bytes                   = 0;
+      *stat_tx_retransmit_pdu_by_status     = 0;
+      *stat_tx_retransmit_bytes_by_status   = 0;
+      *stat_tx_retransmit_pdu               = 0;
+      *stat_tx_retransmit_bytes             = 0;
+      *stat_tx_control_pdu                  = 0;
+      *stat_tx_control_bytes                = 0;
+      *stat_rx_pdcp_sdu                     = 0;
+      *stat_rx_pdcp_bytes                   = 0;
+      *stat_rx_data_pdus_duplicate          = 0;
+      *stat_rx_data_bytes_duplicate         = 0;
+      *stat_rx_data_pdu                     = 0;
+      *stat_rx_data_bytes                   = 0;
+      *stat_rx_data_pdu_dropped             = 0;
+      *stat_rx_data_bytes_dropped           = 0;
+      *stat_rx_data_pdu_out_of_window       = 0;
+      *stat_rx_data_bytes_out_of_window     = 0;
+      *stat_rx_control_pdu                  = 0;
+      *stat_rx_control_bytes                = 0;
+      *stat_timer_reordering_timed_out      = 0;
+      *stat_timer_poll_retransmit_timed_out = 0;
+      *stat_timer_status_prohibit_timed_out = 0;
+      return RLC_OP_STATUS_BAD_PARAMETER;
+      break;
+
+    case RLC_MODE_AM:
+      rlc_am_stat_req(ctxt_pP,
+                      &rlc_union_p->rlc.am,
+                      stat_tx_pdcp_sdu,
+                      stat_tx_pdcp_bytes,
+                      stat_tx_pdcp_sdu_discarded,
+                      stat_tx_pdcp_bytes_discarded,
+                      stat_tx_data_pdu,
+                      stat_tx_data_bytes,
+                      stat_tx_retransmit_pdu_by_status,
+                      stat_tx_retransmit_bytes_by_status,
+                      stat_tx_retransmit_pdu,
+                      stat_tx_retransmit_bytes,
+                      stat_tx_control_pdu,
+                      stat_tx_control_bytes,
+                      stat_rx_pdcp_sdu,
+                      stat_rx_pdcp_bytes,
+                      stat_rx_data_pdus_duplicate,
+                      stat_rx_data_bytes_duplicate,
+                      stat_rx_data_pdu,
+                      stat_rx_data_bytes,
+                      stat_rx_data_pdu_dropped,
+                      stat_rx_data_bytes_dropped,
+                      stat_rx_data_pdu_out_of_window,
+                      stat_rx_data_bytes_out_of_window,
+                      stat_rx_control_pdu,
+                      stat_rx_control_bytes,
+                      stat_timer_reordering_timed_out,
+                      stat_timer_poll_retransmit_timed_out,
+                      stat_timer_status_prohibit_timed_out);
+      return RLC_OP_STATUS_OK;
+      break;
+
+    case RLC_MODE_UM:
+      *stat_tx_retransmit_pdu_by_status     = 0;
+      *stat_tx_retransmit_bytes_by_status   = 0;
+      *stat_tx_retransmit_pdu               = 0;
+      *stat_tx_retransmit_bytes             = 0;
+      *stat_tx_control_pdu                  = 0;
+      *stat_tx_control_bytes                = 0;
+      *stat_rx_data_pdu_dropped             = 0;
+      *stat_rx_data_bytes_dropped           = 0;
+      *stat_rx_data_pdu_out_of_window       = 0;
+      *stat_rx_data_bytes_out_of_window     = 0;
+      *stat_timer_poll_retransmit_timed_out = 0;
+      *stat_timer_status_prohibit_timed_out = 0;
+      rlc_um_stat_req (&rlc_union_p->rlc.um,
+                       stat_tx_pdcp_sdu,
+                       stat_tx_pdcp_bytes,
+                       stat_tx_pdcp_sdu_discarded,
+                       stat_tx_pdcp_bytes_discarded,
+                       stat_tx_data_pdu,
+                       stat_tx_data_bytes,
+                       stat_rx_pdcp_sdu,
+                       stat_rx_pdcp_bytes,
+                       stat_rx_data_pdus_duplicate,
+                       stat_rx_data_bytes_duplicate,
+                       stat_rx_data_pdu,
+                       stat_rx_data_bytes,
+                       stat_rx_data_pdu_dropped,
+                       stat_rx_data_bytes_dropped,
+                       stat_rx_data_pdu_out_of_window,
+                       stat_rx_data_bytes_out_of_window,
+                       stat_timer_reordering_timed_out);
+      return RLC_OP_STATUS_OK;
+      break;
+
+    case RLC_MODE_TM:
+      *stat_tx_pdcp_sdu                     = 0;
+      *stat_tx_pdcp_bytes                   = 0;
+      *stat_tx_pdcp_sdu_discarded           = 0;
+      *stat_tx_pdcp_bytes_discarded         = 0;
+      *stat_tx_data_pdu                     = 0;
+      *stat_tx_data_bytes                   = 0;
+      *stat_tx_retransmit_pdu_by_status     = 0;
+      *stat_tx_retransmit_bytes_by_status   = 0;
+      *stat_tx_retransmit_pdu               = 0;
+      *stat_tx_retransmit_bytes             = 0;
+      *stat_tx_control_pdu                  = 0;
+      *stat_tx_control_bytes                = 0;
+      *stat_rx_pdcp_sdu                     = 0;
+      *stat_rx_pdcp_bytes                   = 0;
+      *stat_rx_data_pdus_duplicate          = 0;
+      *stat_rx_data_bytes_duplicate         = 0;
+      *stat_rx_data_pdu                     = 0;
+      *stat_rx_data_bytes                   = 0;
+      *stat_rx_data_pdu_dropped             = 0;
+      *stat_rx_data_bytes_dropped           = 0;
+      *stat_rx_data_pdu_out_of_window       = 0;
+      *stat_rx_data_bytes_out_of_window     = 0;
+      *stat_rx_control_pdu                  = 0;
+      *stat_rx_control_bytes                = 0;
+      *stat_timer_reordering_timed_out      = 0;
+      *stat_timer_poll_retransmit_timed_out = 0;
+      *stat_timer_status_prohibit_timed_out = 0;
+      return RLC_OP_STATUS_BAD_PARAMETER;
+      break;
+
+    default:
+      *stat_tx_pdcp_sdu                     = 0;
+      *stat_tx_pdcp_bytes                   = 0;
+      *stat_tx_pdcp_sdu_discarded           = 0;
+      *stat_tx_pdcp_bytes_discarded         = 0;
+      *stat_tx_data_pdu                     = 0;
+      *stat_tx_data_bytes                   = 0;
+      *stat_tx_retransmit_pdu_by_status     = 0;
+      *stat_tx_retransmit_bytes_by_status   = 0;
+      *stat_tx_retransmit_pdu               = 0;
+      *stat_tx_retransmit_bytes             = 0;
+      *stat_tx_control_pdu                  = 0;
+      *stat_tx_control_bytes                = 0;
+      *stat_rx_pdcp_sdu                     = 0;
+      *stat_rx_pdcp_bytes                   = 0;
+      *stat_rx_data_pdus_duplicate          = 0;
+      *stat_rx_data_bytes_duplicate         = 0;
+      *stat_rx_data_pdu                     = 0;
+      *stat_rx_data_bytes                   = 0;
+      *stat_rx_data_pdu_dropped             = 0;
+      *stat_rx_data_bytes_dropped           = 0;
+      *stat_rx_data_pdu_out_of_window       = 0;
+      *stat_rx_data_bytes_out_of_window     = 0;
+      *stat_rx_control_pdu                  = 0;
+      *stat_rx_control_bytes                = 0;
+      *stat_timer_poll_retransmit_timed_out = 0;
+      *stat_timer_status_prohibit_timed_out = 0;
+      return RLC_OP_STATUS_BAD_PARAMETER;
   }
 }
 
 //-----------------------------------------------------------------------------
-rlc_op_status_t rlc_data_req     (const protocol_ctxt_t* const ctxt_pP,
+rlc_op_status_t rlc_data_req     (const protocol_ctxt_t *const ctxt_pP,
                                   const srb_flag_t   srb_flagP,
                                   const MBMS_flag_t  MBMS_flagP,
                                   const rb_id_t      rb_idP,
@@ -327,12 +324,11 @@ rlc_op_status_t rlc_data_req     (const protocol_ctxt_t* const ctxt_pP,
                                   confirm_t    confirmP,
                                   sdu_size_t   sdu_sizeP,
                                   mem_block_t *sdu_pP
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-                                  ,const uint32_t * const sourceL2Id
-                                  ,const uint32_t * const destinationL2Id
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  ,const uint32_t *const sourceL2Id
+  ,const uint32_t *const destinationL2Id
 #endif
-                                  )
-{
+                                 ) {
   //-----------------------------------------------------------------------------
   
  
@@ -341,8 +337,7 @@ rlc_op_status_t rlc_data_req     (const protocol_ctxt_t* const ctxt_pP,
   rlc_union_t           *rlc_union_p = NULL;
   hash_key_t             key         = HASHTABLE_NOT_A_KEY_VALUE;
   hashtable_rc_t         h_rc;
-
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
   rlc_mbms_id_t         *mbms_id_p  = NULL;
   logical_chan_id_t      log_ch_id  = 0;
 #endif
@@ -356,49 +351,48 @@ rlc_op_status_t rlc_data_req     (const protocol_ctxt_t* const ctxt_pP,
         sdu_sizeP,
         sdu_pP);
 #endif
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 #else
   AssertFatal(MBMS_flagP == 0, "MBMS_flagP %u", MBMS_flagP);
 #endif
-
 #if T_TRACER
+
   if (ctxt_pP->enb_flag)
     T(T_ENB_RLC_DL, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->rnti), T_INT(rb_idP), T_INT(sdu_sizeP));
+
 #endif
 
   if (MBMS_flagP) {
     //AssertFatal (rb_idP < NB_RB_MBMS_MAX, "RB id is too high (%u/%d)!\n", rb_idP, NB_RB_MBMS_MAX);
-  	if(rb_idP >= NB_RB_MBMS_MAX){
-  		LOG_E(RLC, "RB id is too high (%u/%d)!\n", rb_idP, NB_RB_MBMS_MAX);
-  		return RLC_OP_STATUS_BAD_PARAMETER;
-  	}
+    if(rb_idP >= NB_RB_MBMS_MAX) {
+      LOG_E(RLC, "RB id is too high (%u/%d)!\n", rb_idP, NB_RB_MBMS_MAX);
+      return RLC_OP_STATUS_BAD_PARAMETER;
+    }
   } else {
     //AssertFatal (rb_idP < NB_RB_MAX, "RB id is too high (%u/%d)!\n", rb_idP, NB_RB_MAX);
-  	if(rb_idP >= NB_RB_MAX){
-  		LOG_E(RLC, "RB id is too high (%u/%d)!\n", rb_idP, NB_RB_MAX);
-  		return RLC_OP_STATUS_BAD_PARAMETER;
-  	}
+    if(rb_idP >= NB_RB_MAX) {
+      LOG_E(RLC, "RB id is too high (%u/%d)!\n", rb_idP, NB_RB_MAX);
+      return RLC_OP_STATUS_BAD_PARAMETER;
+    }
   }
 
   //DevAssert(sdu_pP != NULL);
-	if(sdu_pP == NULL){
-		LOG_E(RLC, "sdu_pP == NULL\n");
-		return RLC_OP_STATUS_BAD_PARAMETER;
-	}
-	
+  if(sdu_pP == NULL) {
+    LOG_E(RLC, "sdu_pP == NULL\n");
+    return RLC_OP_STATUS_BAD_PARAMETER;
+  }
+
   //DevCheck(sdu_sizeP > 0, sdu_sizeP, 0, 0);
   if(sdu_sizeP <= 0) {
     LOG_E(RLC, "sdu_sizeP %d, file %s, line %d\n", sdu_sizeP, __FILE__ ,__LINE__);
     return RLC_OP_STATUS_BAD_PARAMETER;
   }
 
-#if (RRC_VERSION < MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION < MAKE_VERSION(10, 0, 0))
   DevCheck(MBMS_flagP == 0, MBMS_flagP, 0, 0);
 #endif
-
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_IN);
-
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 
   if (MBMS_flagP == TRUE) {
     if (ctxt_pP->enb_flag) {
@@ -411,24 +405,31 @@ rlc_op_status_t rlc_data_req     (const protocol_ctxt_t* const ctxt_pP,
 
     key = RLC_COLL_KEY_MBMS_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, mbms_id_p->service_id, mbms_id_p->session_id);
   }
-  if (sourceL2Id && destinationL2Id){
-     key = RLC_COLL_KEY_SOURCE_DEST_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, *sourceL2Id, *destinationL2Id, srb_flagP);
-     //key_lcid = RLC_COLL_KEY_LCID_SOURCE_DEST_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, chan_idP, *sourceL2Id, *destinationL2Id, srb_flagP);
+
+  if (sourceL2Id && destinationL2Id) {
+    LOG_D (RLC, "RLC_COLL_KEY_VALUE: ctxt_pP->module_id: %d, ctxt_pP->rnti: %d, ctxt_pP->enb_flag: %d, rb_idP:%d, srb_flagP: %d \n \n", ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP,
+           srb_flagP);
+    key = RLC_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, srb_flagP);
+    //Thinh's line originally uncommented
+    //key = RLC_COLL_KEY_SOURCE_DEST_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, *sourceL2Id, *destinationL2Id, srb_flagP);
+    //key_lcid = RLC_COLL_KEY_LCID_SOURCE_DEST_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, chan_idP, *sourceL2Id, *destinationL2Id, srb_flagP);
   } else
 #endif
   {
+    LOG_D (RLC, "RLC_COLL_KEY_VALUE: ctxt_pP->module_id: %d, ctxt_pP->rnti: %d, ctxt_pP->enb_flag: %d, rb_idP:%d, srb_flagP: %d \n \n", ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP,
+           srb_flagP);
     key = RLC_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, srb_flagP);
   }
 
-  h_rc = hashtable_get(rlc_coll_p, key, (void**)&rlc_union_p);
+  h_rc = hashtable_get(rlc_coll_p, key, (void **)&rlc_union_p);
 
   if (h_rc == HASH_TABLE_OK) {
     rlc_mode = rlc_union_p->mode;
   } else {
     rlc_mode = RLC_MODE_NONE;
     //AssertFatal (0 , "RLC not configured key %ju\n", key);
-  	LOG_E(RLC, "not configured key %lu\n", key);
-  	return RLC_OP_STATUS_OUT_OF_RESSOURCES;
+    LOG_E(RLC, "not configured key %lu\n", key);
+    return RLC_OP_STATUS_OUT_OF_RESSOURCES;
   }
 
   if (MBMS_flagP == 0) {
@@ -436,114 +437,108 @@ rlc_op_status_t rlc_data_req     (const protocol_ctxt_t* const ctxt_pP,
           PROTOCOL_CTXT_ARGS(ctxt_pP),
           rb_idP);
 #if defined(TRACE_RLC_PAYLOAD)
-    rlc_util_print_hex_octets(RLC, (unsigned char*)sdu_pP->data, sdu_sizeP);
+    rlc_util_print_hex_octets(RLC, (unsigned char *)sdu_pP->data, sdu_sizeP);
 #endif
-
 #ifdef DEBUG_RLC_DATA_REQ
     LOG_D(RLC,"RLC_TYPE : %d\n", rlc_mode);
 #endif
 
     switch (rlc_mode) {
-    case RLC_MODE_NONE:
-      free_mem_block(sdu_pP, __func__);
-      LOG_E(RLC, PROTOCOL_CTXT_FMT" Received RLC_MODE_NONE as rlc_type for rb_id %u\n",
-            PROTOCOL_CTXT_ARGS(ctxt_pP),
-            rb_idP);
-      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
-      return RLC_OP_STATUS_BAD_PARAMETER;
+      case RLC_MODE_NONE:
+        free_mem_block(sdu_pP, __func__);
+        LOG_E(RLC, PROTOCOL_CTXT_FMT" Received RLC_MODE_NONE as rlc_type for rb_id %u\n",
+              PROTOCOL_CTXT_ARGS(ctxt_pP),
+              rb_idP);
+        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
+        return RLC_OP_STATUS_BAD_PARAMETER;
 
-    case RLC_MODE_AM:
+      case RLC_MODE_AM:
 #ifdef DEBUG_RLC_DATA_REQ
-      LOG_D(RLC,"RLC_MODE_AM\n");
+        LOG_D(RLC,"RLC_MODE_AM\n");
 #endif
-      new_sdu_p = get_free_mem_block (sdu_sizeP + sizeof (struct rlc_am_data_req_alloc), __func__);
+        new_sdu_p = get_free_mem_block (sdu_sizeP + sizeof (struct rlc_am_data_req_alloc), __func__);
 
-      if (new_sdu_p != NULL) {
-        // PROCESS OF COMPRESSION HERE:
-        memset (new_sdu_p->data, 0, sizeof (struct rlc_am_data_req_alloc));
-        memcpy (&new_sdu_p->data[sizeof (struct rlc_am_data_req_alloc)], &sdu_pP->data[0], sdu_sizeP);
-
-        ((struct rlc_am_data_req *) (new_sdu_p->data))->data_size = sdu_sizeP;
-        ((struct rlc_am_data_req *) (new_sdu_p->data))->conf = confirmP;
-        ((struct rlc_am_data_req *) (new_sdu_p->data))->mui  = muiP;
-        ((struct rlc_am_data_req *) (new_sdu_p->data))->data_offset = sizeof (struct rlc_am_data_req_alloc);
-        free_mem_block(sdu_pP, __func__);
-        rlc_am_data_req(ctxt_pP, &rlc_union_p->rlc.am, new_sdu_p);
-        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
-        return RLC_OP_STATUS_OK;
-      } else {
-        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
-        free_mem_block(sdu_pP, __func__);
-        return RLC_OP_STATUS_INTERNAL_ERROR;
-      }
-
-      break;
+        if (new_sdu_p != NULL) {
+          // PROCESS OF COMPRESSION HERE:
+          memset (new_sdu_p->data, 0, sizeof (struct rlc_am_data_req_alloc));
+          memcpy (&new_sdu_p->data[sizeof (struct rlc_am_data_req_alloc)], &sdu_pP->data[0], sdu_sizeP);
+          ((struct rlc_am_data_req *) (new_sdu_p->data))->data_size = sdu_sizeP;
+          ((struct rlc_am_data_req *) (new_sdu_p->data))->conf = confirmP;
+          ((struct rlc_am_data_req *) (new_sdu_p->data))->mui  = muiP;
+          ((struct rlc_am_data_req *) (new_sdu_p->data))->data_offset = sizeof (struct rlc_am_data_req_alloc);
+          free_mem_block(sdu_pP, __func__);
+          rlc_am_data_req(ctxt_pP, &rlc_union_p->rlc.am, new_sdu_p);
+          VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
+          return RLC_OP_STATUS_OK;
+        } else {
+          VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
+          free_mem_block(sdu_pP, __func__);
+          return RLC_OP_STATUS_INTERNAL_ERROR;
+        }
 
-    case RLC_MODE_UM:
-      /* TODO: this is a hack, needs better solution. Let's not use too
-       * much memory and store at maximum 5 millions bytes.
-       */
-      /* look for HACK_RLC_UM_LIMIT for others places related to the hack. Please do not remove this comment. */
-      if (rlc_um_get_buffer_occupancy(&rlc_union_p->rlc.um) > 5000000) {
-        free_mem_block(sdu_pP, __func__);
-        return RLC_OP_STATUS_OUT_OF_RESSOURCES;
-      }
+        break;
 
-      new_sdu_p = get_free_mem_block (sdu_sizeP + sizeof (struct rlc_um_data_req_alloc), __func__);
+      case RLC_MODE_UM:
 
-      if (new_sdu_p != NULL) {
-        // PROCESS OF COMPRESSION HERE:
-        memset (new_sdu_p->data, 0, sizeof (struct rlc_um_data_req_alloc));
-        memcpy (&new_sdu_p->data[sizeof (struct rlc_um_data_req_alloc)], &sdu_pP->data[0], sdu_sizeP);
+        /* TODO: this is a hack, needs better solution. Let's not use too
+         * much memory and store at maximum 5 millions bytes.
+         */
+        /* look for HACK_RLC_UM_LIMIT for others places related to the hack. Please do not remove this comment. */
+        if (rlc_um_get_buffer_occupancy(&rlc_union_p->rlc.um) > 5000000) {
+          free_mem_block(sdu_pP, __func__);
+          return RLC_OP_STATUS_OUT_OF_RESSOURCES;
+        }
 
-        ((struct rlc_um_data_req *) (new_sdu_p->data))->data_size = sdu_sizeP;
-        ((struct rlc_um_data_req *) (new_sdu_p->data))->data_offset = sizeof (struct rlc_um_data_req_alloc);
-        free_mem_block(sdu_pP, __func__);
+        new_sdu_p = get_free_mem_block (sdu_sizeP + sizeof (struct rlc_um_data_req_alloc), __func__);
 
-        rlc_um_data_req(ctxt_pP, &rlc_union_p->rlc.um, new_sdu_p);
+        if (new_sdu_p != NULL) {
+          // PROCESS OF COMPRESSION HERE:
+          memset (new_sdu_p->data, 0, sizeof (struct rlc_um_data_req_alloc));
+          memcpy (&new_sdu_p->data[sizeof (struct rlc_um_data_req_alloc)], &sdu_pP->data[0], sdu_sizeP);
+          ((struct rlc_um_data_req *) (new_sdu_p->data))->data_size = sdu_sizeP;
+          ((struct rlc_um_data_req *) (new_sdu_p->data))->data_offset = sizeof (struct rlc_um_data_req_alloc);
+          free_mem_block(sdu_pP, __func__);
+          rlc_um_data_req(ctxt_pP, &rlc_union_p->rlc.um, new_sdu_p);
+          //free_mem_block(new_sdu, __func__);
+          VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
+          return RLC_OP_STATUS_OK;
+        } else {
+          VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
+          free_mem_block(sdu_pP, __func__);
+          return RLC_OP_STATUS_INTERNAL_ERROR;
+        }
 
-        //free_mem_block(new_sdu, __func__);
-        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
-        return RLC_OP_STATUS_OK;
-      } else {
-        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
-        free_mem_block(sdu_pP, __func__);
-        return RLC_OP_STATUS_INTERNAL_ERROR;
-      }
+        break;
 
-      break;
+      case RLC_MODE_TM:
+        new_sdu_p = get_free_mem_block (sdu_sizeP + sizeof (struct rlc_tm_data_req_alloc), __func__);
 
-    case RLC_MODE_TM:
-      new_sdu_p = get_free_mem_block (sdu_sizeP + sizeof (struct rlc_tm_data_req_alloc), __func__);
+        if (new_sdu_p != NULL) {
+          // PROCESS OF COMPRESSION HERE:
+          memset (new_sdu_p->data, 0, sizeof (struct rlc_tm_data_req_alloc));
+          memcpy (&new_sdu_p->data[sizeof (struct rlc_tm_data_req_alloc)], &sdu_pP->data[0], sdu_sizeP);
+          ((struct rlc_tm_data_req *) (new_sdu_p->data))->data_size = sdu_sizeP;
+          ((struct rlc_tm_data_req *) (new_sdu_p->data))->data_offset = sizeof (struct rlc_tm_data_req_alloc);
+          free_mem_block(sdu_pP, __func__);
+          rlc_tm_data_req(ctxt_pP, &rlc_union_p->rlc.tm, new_sdu_p);
+          VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
+          return RLC_OP_STATUS_OK;
+        } else {
+          //handle_event(ERROR,"FILE %s FONCTION rlc_data_req() LINE %s : out of memory\n", __FILE__, __LINE__);
+          VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
+          free_mem_block(sdu_pP, __func__);
+          return RLC_OP_STATUS_INTERNAL_ERROR;
+        }
 
-      if (new_sdu_p != NULL) {
-        // PROCESS OF COMPRESSION HERE:
-        memset (new_sdu_p->data, 0, sizeof (struct rlc_tm_data_req_alloc));
-        memcpy (&new_sdu_p->data[sizeof (struct rlc_tm_data_req_alloc)], &sdu_pP->data[0], sdu_sizeP);
+        break;
 
-        ((struct rlc_tm_data_req *) (new_sdu_p->data))->data_size = sdu_sizeP;
-        ((struct rlc_tm_data_req *) (new_sdu_p->data))->data_offset = sizeof (struct rlc_tm_data_req_alloc);
+      default:
         free_mem_block(sdu_pP, __func__);
-        rlc_tm_data_req(ctxt_pP, &rlc_union_p->rlc.tm, new_sdu_p);
-        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
-        return RLC_OP_STATUS_OK;
-      } else {
-        //handle_event(ERROR,"FILE %s FONCTION rlc_data_req() LINE %s : out of memory\n", __FILE__, __LINE__);
         VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
-        free_mem_block(sdu_pP, __func__);
         return RLC_OP_STATUS_INTERNAL_ERROR;
-      }
-
-      break;
-
-    default:
-      free_mem_block(sdu_pP, __func__);
-      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
-      return RLC_OP_STATUS_INTERNAL_ERROR;
-
     }
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
   } else { /* MBMS_flag != 0 */
     //  LOG_I(RLC,"DUY rlc_data_req: mbms_rb_id in RLC instant is: %d\n", mbms_rb_id);
     if (sdu_pP != NULL) {
@@ -559,7 +554,6 @@ rlc_op_status_t rlc_data_req     (const protocol_ctxt_t* const ctxt_pP,
           ((struct rlc_um_data_req *) (new_sdu_p->data))->data_offset = sizeof (struct rlc_um_data_req_alloc);
           free_mem_block(sdu_pP, __func__);
           rlc_um_data_req(ctxt_pP, &rlc_union_p->rlc.um, new_sdu_p);
-
           //free_mem_block(new_sdu, __func__);
           VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
           return RLC_OP_STATUS_OK;
@@ -580,8 +574,7 @@ rlc_op_status_t rlc_data_req     (const protocol_ctxt_t* const ctxt_pP,
 
 #else
   }
-  else  /* MBMS_flag != 0 */
-  {
+  else { /* MBMS_flag != 0 */
     free_mem_block(sdu_pP, __func__);
     LOG_E(RLC, "MBMS_flag != 0 while Rel10/Rel14 is not defined...\n");
     //handle_event(ERROR,"FILE %s FONCTION rlc_data_req() LINE %s : parameter module_id out of bounds :%d\n", __FILE__, __LINE__, module_idP);
@@ -594,54 +587,50 @@ rlc_op_status_t rlc_data_req     (const protocol_ctxt_t* const ctxt_pP,
 
 //-----------------------------------------------------------------------------
 void rlc_data_ind     (
-  const protocol_ctxt_t* const ctxt_pP,
+  const protocol_ctxt_t *const ctxt_pP,
   const srb_flag_t  srb_flagP,
   const MBMS_flag_t MBMS_flagP,
   const rb_id_t     rb_idP,
   const sdu_size_t  sdu_sizeP,
-  mem_block_t      *sdu_pP)
-{
+  mem_block_t      *sdu_pP) {
   //-----------------------------------------------------------------------------
-
-
 #if defined(TRACE_RLC_PAYLOAD)
   LOG_D(RLC, PROTOCOL_CTXT_FMT"[%s %u] Display of rlc_data_ind: size %u\n",
         PROTOCOL_CTXT_ARGS(ctxt_pP),
         (srb_flagP) ? "SRB" : "DRB",
         rb_idP,
         sdu_sizeP);
-
-  //  rlc_util_print_hex_octets(RLC, (unsigned char*)sdu_pP->data, sdu_sizeP);
+  rlc_util_print_hex_octets(RLC, (unsigned char *)sdu_pP->data, sdu_sizeP);
 #endif
-
 #if T_TRACER
+
   if (ctxt_pP->enb_flag)
     T(T_ENB_RLC_UL, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->rnti), T_INT(rb_idP), T_INT(sdu_sizeP));
+
 #endif
-#ifndef UETARGET
    if (ctxt_pP->enb_flag == 1)
    {
      switch (RC.rrc[ctxt_pP->module_id]->node_type){
-       case ngran_eNB_CU    :
-       case ngran_ng_eNB_CU :
-       case ngran_gNB_CU    :
-        LOG_E(RLC, "Can't be CU, Bad Node type %d\n",RC.rrc[ctxt_pP->module_id]->node_type);
-        break ;
-       case ngran_eNB_DU    : 
-       case ngran_gNB_DU    :
+       case ngran_eNB_CU:
+       case ngran_ng_eNB_CU:
+       case ngran_gNB_CU:
+         LOG_E(RLC, "Can't be CU, Bad Node type %d\n",RC.rrc[ctxt_pP->module_id]->node_type);
+         break;
+       case ngran_eNB_DU:
+       case ngran_gNB_DU:
          if (srb_flagP == 1)
            DU_send_UL_RRC_MESSAGE_TRANSFER(ctxt_pP,
 	  				   rb_idP,
 					     sdu_sizeP,
 					     sdu_pP->data);
          else
-             proto_agent_send_pdcp_data_ind (
-              ctxt_pP,
-              srb_flagP,
-              MBMS_flagP,
-              rb_idP,
-              sdu_sizeP,
-              sdu_pP);
+           proto_agent_send_pdcp_data_ind (
+             ctxt_pP,
+             srb_flagP,
+             MBMS_flagP,
+             rb_idP,
+             sdu_sizeP,
+             sdu_pP);
      
        break;
 
@@ -657,25 +646,14 @@ void rlc_data_ind     (
      }
 
    }
-#else
-   pdcp_data_ind (
-		  ctxt_pP,
-		  srb_flagP,
-		  MBMS_flagP,
-		  rb_idP,
-		  sdu_sizeP,
-		  sdu_pP);
-#endif
 }
 //-----------------------------------------------------------------------------
-void rlc_data_conf     (const protocol_ctxt_t* const ctxt_pP,
+void rlc_data_conf     (const protocol_ctxt_t *const ctxt_pP,
                         const srb_flag_t      srb_flagP,
                         const rb_id_t         rb_idP,
                         const mui_t           muiP,
-                        const rlc_tx_status_t statusP)
-{
+                        const rlc_tx_status_t statusP) {
   //-----------------------------------------------------------------------------
-
   if (srb_flagP) {
     if (rlc_rrc_data_conf != NULL) {
       rlc_rrc_data_conf (ctxt_pP, rb_idP , muiP, statusP);
@@ -684,20 +662,17 @@ void rlc_data_conf     (const protocol_ctxt_t* const ctxt_pP,
 }
 //-----------------------------------------------------------------------------
 int
-rlc_module_init (void)
-{
+rlc_module_init (void) {
   //-----------------------------------------------------------------------------
   int          k;
   module_id_t  module_id1;
-
   /* for no gcc warnings */
   (void)k;
-
   LOG_D(RLC, "MODULE INIT\n");
   rlc_rrc_data_ind  = NULL;
   rlc_rrc_data_conf = NULL;
+  rlc_coll_p = hashtable_create ((LTE_maxDRB + 2) * NUMBER_OF_UE_MAX, NULL, rb_free_rlc_union);
 
-  rlc_coll_p = hashtable_create ((maxDRB + 2) * 16, NULL, rb_free_rlc_union);
   //AssertFatal(rlc_coll_p != NULL, "UNRECOVERABLE error, RLC hashtable_create failed");
   if(rlc_coll_p == NULL) {
     LOG_E(RLC, "UNRECOVERABLE error, RLC hashtable_create failed\n");
@@ -705,7 +680,7 @@ rlc_module_init (void)
   }
 
   for (module_id1=0; module_id1 < MAX_MOBILES_PER_ENB; module_id1++) {
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 
     for (k=0; k < RLC_MAX_MBMS_LC; k++) {
       rlc_mbms_lcid2service_session_id_ue[module_id1][k].service_id = 0;
@@ -720,7 +695,7 @@ rlc_module_init (void)
   }
 
   for (module_id1=0; module_id1 < NUMBER_OF_eNB_MAX; module_id1++) {
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 
     for (k=0; k < RLC_MAX_MBMS_LC; k++) {
       rlc_mbms_lcid2service_session_id_eNB[module_id1][k].service_id = 0;
@@ -735,7 +710,6 @@ rlc_module_init (void)
   }
 
   pool_buffer_init();
-
   return(0);
 }
 //-----------------------------------------------------------------------------
@@ -743,12 +717,11 @@ void
 rlc_module_cleanup (void)
 //-----------------------------------------------------------------------------
 {
-  hashtable_destroy(rlc_coll_p);
+  hashtable_destroy(&rlc_coll_p);
 }
 //-----------------------------------------------------------------------------
 void
-rlc_layer_init (void)
-{
+rlc_layer_init (void) {
   //-----------------------------------------------------------------------------
 }
 //-----------------------------------------------------------------------------
diff --git a/openair2/LAYER2/RLC/rlc.h b/openair2/LAYER2/RLC/rlc.h
index cedfbe17dee885c3c4d2135608fe771a789200c3..fbb13373a308cfa8c2d34e9134d87e2ed110db9d 100644
--- a/openair2/LAYER2/RLC/rlc.h
+++ b/openair2/LAYER2/RLC/rlc.h
@@ -44,19 +44,19 @@
 #    include "rlc_am_structs.h"
 #    include "rlc_tm_structs.h"
 #    include "rlc_um_structs.h"
-#    include "asn_constant.h"
+#    include "LTE_asn_constant.h"
 #    include "common/utils/LOG/log.h"
 #    include "mem_block.h"
 //#    include "PHY/defs.h"
-#    include "RLC-Config.h"
-#    include "DRB-ToAddMod.h"
-#    include "DRB-ToAddModList.h"
-#    include "SRB-ToAddMod.h"
-#    include "SRB-ToAddModList.h"
-#    include "DRB-ToReleaseList.h"
-
-#if defined(Rel10) || defined(Rel14)
-#include "PMCH-InfoList-r9.h"
+#    include "LTE_RLC-Config.h"
+#    include "LTE_DRB-ToAddMod.h"
+#    include "LTE_DRB-ToAddModList.h"
+#    include "LTE_SRB-ToAddMod.h"
+#    include "LTE_SRB-ToAddModList.h"
+#    include "LTE_DRB-ToReleaseList.h"
+
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+#include "LTE_PMCH-InfoList-r9.h"
 #endif
 
 typedef uint64_t hash_key_t;
@@ -132,8 +132,8 @@ typedef struct {
 //   PRIVATE INTERNALS OF RLC
 //-----------------------------------------------------------------------------
 
-#define  RLC_MAX_MBMS_LC (maxSessionPerPMCH * maxServiceCount)
-#define  RLC_MAX_LC  ((max_val_DRB_Identity+1)* MAX_MOBILES_PER_ENB)
+#define  RLC_MAX_MBMS_LC (LTE_maxSessionPerPMCH * LTE_maxServiceCount)
+#define  RLC_MAX_LC  ((max_val_LTE_DRB_Identity+1)* MAX_MOBILES_PER_ENB)
 
 void (*rlc_rrc_data_ind)(
                 const protocol_ctxt_t* const ctxtP,
@@ -183,7 +183,7 @@ typedef struct rlc_mbms_id_s {
   mbms_session_id_t       session_id;
 } rlc_mbms_id_t;
 
-#if (RRC_VERSION < MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION < MAKE_VERSION(10, 0, 0))
 #    if !defined(maxServiceCount)
 //unused arrays rlc_mbms_array_ue rlc_mbms_array_eNB
 #        define maxServiceCount 1
@@ -285,7 +285,7 @@ struct mac_data_ind   mac_rlc_deserialize_tb (char*, tb_size_t, num_tb_t, crc_t
 //-----------------------------------------------------------------------------
 //   PUBLIC INTERFACE WITH RRC
 //-----------------------------------------------------------------------------
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 /*! \fn rlc_op_status_t rrc_rlc_config_asn1_req (const protocol_ctxt_t* const ctxtP, const srb_flag_t srb_flagP, const SRB_ToAddMod_t* const srb2addmod, const DRB_ToAddModList_t* const drb2add_listP, const DRB_ToReleaseList_t*  const drb2release_listP, const PMCH_InfoList_r9_t * const pmch_info_listP)
 * \brief  Function for RRC to configure a Radio Bearer.
 * \param[in]  ctxtP              Running context.
@@ -297,10 +297,10 @@ struct mac_data_ind   mac_rlc_deserialize_tb (char*, tb_size_t, num_tb_t, crc_t
 */
 rlc_op_status_t rrc_rlc_config_asn1_req (
                   const protocol_ctxt_t* const,
-                  const SRB_ToAddModList_t* const ,
-                  const DRB_ToAddModList_t* const ,
-                  const DRB_ToReleaseList_t* const ,
-                  const PMCH_InfoList_r9_t * const pmch_info_listP ,
+                  const LTE_SRB_ToAddModList_t* const ,
+                  const LTE_DRB_ToAddModList_t* const ,
+                  const LTE_DRB_ToReleaseList_t* const ,
+                  const LTE_PMCH_InfoList_r9_t * const pmch_info_listP ,
                   const uint32_t ,
                   const uint32_t );
 #else
@@ -314,9 +314,9 @@ rlc_op_status_t rrc_rlc_config_asn1_req (
 */
 rlc_op_status_t rrc_rlc_config_asn1_req (
                   const protocol_ctxt_t* const,
-                  const SRB_ToAddModList_t* const ,
-                  const DRB_ToAddModList_t* const ,
-                  const DRB_ToReleaseList_t* const );
+                  const LTE_SRB_ToAddModList_t* const ,
+                  const LTE_DRB_ToAddModList_t* const ,
+                  const LTE_DRB_ToReleaseList_t* const );
 #endif
 
 
@@ -358,7 +358,7 @@ rlc_op_status_t rrc_rlc_remove_rlc   (const protocol_ctxt_t* const, const srb_fl
 * \return     A status about the processing, OK or error code.
 */
 rlc_union_t*  rrc_rlc_add_rlc      (const protocol_ctxt_t* const, const srb_flag_t,  const  MBMS_flag_t MBMS_flagP, const  rb_id_t, logical_chan_id_t, rlc_mode_t
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   ,const uint32_t  sourceL2Id,
   const uint32_t  destinationL2Id
 #endif
@@ -424,7 +424,7 @@ void rrc_rlc_register_rrc (rrc_data_ind_cb_t rrc_data_indP, rrc_data_conf_cb_t r
 * \return     A status about the processing, OK or error code.
 */
 tbs_size_t            mac_rlc_data_req     (const module_id_t, const rnti_t, const eNB_index_t, const frame_t, const  eNB_flag_t, const  MBMS_flag_t, logical_chan_id_t, const tb_size_t,char*
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                                                            ,const uint32_t sourceL2Id
                                                            ,const uint32_t destinationL2Id
 #endif
@@ -459,7 +459,7 @@ void                  mac_rlc_data_ind     (const module_id_t, const rnti_t, con
 * \return     The maximum number of bytes that the RLC instance can send in the next transmission sequence.
 */
 mac_rlc_status_resp_t mac_rlc_status_ind   (const module_id_t, const rnti_t, const eNB_index_t, const frame_t, const sub_frame_t, const  eNB_flag_t, const  MBMS_flag_t, logical_chan_id_t, tb_size_t
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                                                            ,const uint32_t sourceL2Id
                                                            ,const uint32_t destinationL2Id
 #endif
@@ -514,7 +514,7 @@ rlc_op_status_t rlc_data_req     (
              const confirm_t ,
              const sdu_size_t ,
              mem_block_t * const
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
              ,const uint32_t * const
              ,const uint32_t * const
 #endif
diff --git a/openair2/LAYER2/RLC/rlc_mac.c b/openair2/LAYER2/RLC/rlc_mac.c
index 9d540a18e88d323bbbfa297bf76cbaa5a41752fc..df4bac2e090c877600e37416d78bc1914b8c472e 100644
--- a/openair2/LAYER2/RLC/rlc_mac.c
+++ b/openair2/LAYER2/RLC/rlc_mac.c
@@ -128,7 +128,7 @@ tbs_size_t mac_rlc_data_req(
   const logical_chan_id_t channel_idP,
   const tb_size_t         tb_sizeP,
   char             *buffer_pP
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   ,const uint32_t sourceL2Id
   ,const uint32_t destinationL2Id
 #endif
@@ -180,7 +180,7 @@ tbs_size_t mac_rlc_data_req(
     }
   } else {
     key = RLC_COLL_KEY_LCID_VALUE(module_idP, rntiP, enb_flagP, channel_idP, srb_flag);
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
     if ((sourceL2Id > 0) && (destinationL2Id > 0))
        key = RLC_COLL_KEY_LCID_SOURCE_DEST_VALUE(module_idP, rntiP, enb_flagP, channel_idP, sourceL2Id, destinationL2Id, srb_flag);
 #endif
@@ -254,6 +254,7 @@ void mac_rlc_data_ind     (
   srb_flag_t             srb_flag        = (channel_idP <= 2) ? SRB_FLAG_YES : SRB_FLAG_NO;
   protocol_ctxt_t     ctxt;
 
+
   PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, module_idP, enb_flagP, rntiP, frameP, 0, eNB_index);
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_MAC_RLC_DATA_IND,VCD_FUNCTION_IN);
@@ -330,7 +331,7 @@ mac_rlc_status_resp_t mac_rlc_status_ind(
   const MBMS_flag_t       MBMS_flagP,
   const logical_chan_id_t channel_idP,
   const tb_size_t         tb_sizeP
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   ,const uint32_t sourceL2Id
   ,const uint32_t destinationL2Id
 #endif
@@ -363,7 +364,7 @@ mac_rlc_status_resp_t mac_rlc_status_ind(
 
     key = RLC_COLL_KEY_MBMS_VALUE(module_idP, rntiP, enb_flagP, mbms_id_p->service_id, mbms_id_p->session_id);
   } else {
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
     if ((sourceL2Id > 0) && (destinationL2Id > 0)) {
        key = RLC_COLL_KEY_SOURCE_DEST_VALUE(module_idP, rntiP, enb_flagP, channel_idP, sourceL2Id, destinationL2Id, srb_flag);
     } else
diff --git a/openair2/LAYER2/RLC/rlc_mpls.c b/openair2/LAYER2/RLC/rlc_mpls.c
index 8c6cea379b91a2d94585598ad79edb39ca951c84..d6f7afa12d2ef99b22c7265b4519fb94e596605a 100644
--- a/openair2/LAYER2/RLC/rlc_mpls.c
+++ b/openair2/LAYER2/RLC/rlc_mpls.c
@@ -41,7 +41,7 @@ rlc_op_status_t mpls_rlc_data_req     (
   //-----------------------------------------------------------------------------
   // third arg should be set to 1 or 0
   return rlc_data_req(ctxtP, SRB_FLAG_NO, MBMS_FLAG_NO, rb_idP, RLC_MUI_UNDEFINED, RLC_SDU_CONFIRM_NO, sdu_sizeP, sduP
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                       ,NULL, NULL
 #endif
                       );
diff --git a/openair2/LAYER2/RLC/rlc_rrc.c b/openair2/LAYER2/RLC/rlc_rrc.c
index 8977e422b60591d100fd809aa36643c090469cb2..63c24d6e3c96e648d1050d9666bd5071d34ceb3b 100644
--- a/openair2/LAYER2/RLC/rlc_rrc.c
+++ b/openair2/LAYER2/RLC/rlc_rrc.c
@@ -33,25 +33,25 @@
 #include "rlc_um.h"
 #include "rlc_tm.h"
 #include "common/utils/LOG/log.h"
-#include "RLC-Config.h"
-#include "DRB-ToAddMod.h"
-#include "DRB-ToAddModList.h"
-#include "SRB-ToAddMod.h"
-#include "SRB-ToAddModList.h"
-#include "DL-UM-RLC.h"
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-#include "PMCH-InfoList-r9.h"
+#include "LTE_RLC-Config.h"
+#include "LTE_DRB-ToAddMod.h"
+#include "LTE_DRB-ToAddModList.h"
+#include "LTE_SRB-ToAddMod.h"
+#include "LTE_SRB-ToAddModList.h"
+#include "LTE_DL-UM-RLC.h"
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+#include "LTE_PMCH-InfoList-r9.h"
 #endif
 
 #include "LAYER2/MAC/mac_extern.h"
 #include "assertions.h"
 //-----------------------------------------------------------------------------
 rlc_op_status_t rrc_rlc_config_asn1_req (const protocol_ctxt_t   * const ctxt_pP,
-    const SRB_ToAddModList_t   * const srb2add_listP,
-    const DRB_ToAddModList_t   * const drb2add_listP,
-    const DRB_ToReleaseList_t  * const drb2release_listP
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-    ,const PMCH_InfoList_r9_t * const pmch_InfoList_r9_pP
+    const LTE_SRB_ToAddModList_t   * const srb2add_listP,
+    const LTE_DRB_ToAddModList_t   * const drb2add_listP,
+    const LTE_DRB_ToReleaseList_t  * const drb2release_listP
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+    ,const LTE_PMCH_InfoList_r9_t * const pmch_InfoList_r9_pP
     ,const uint32_t sourceL2Id
     ,const uint32_t destinationL2Id
 #endif
@@ -60,21 +60,21 @@ rlc_op_status_t rrc_rlc_config_asn1_req (const protocol_ctxt_t   * const ctxt_pP
   //-----------------------------------------------------------------------------
   rb_id_t                rb_id           = 0;
   logical_chan_id_t      lc_id           = 0;
-  DRB_Identity_t         drb_id          = 0;
-  DRB_Identity_t*        pdrb_id         = NULL;
+  LTE_DRB_Identity_t     drb_id          = 0;
+  LTE_DRB_Identity_t*    pdrb_id         = NULL;
   long int               cnt             = 0;
-  const SRB_ToAddMod_t  *srb_toaddmod_p  = NULL;
-  const DRB_ToAddMod_t  *drb_toaddmod_p  = NULL;
+  const LTE_SRB_ToAddMod_t  *srb_toaddmod_p  = NULL;
+  const LTE_DRB_ToAddMod_t  *drb_toaddmod_p  = NULL;
   rlc_union_t           *rlc_union_p     = NULL;
   hash_key_t             key             = HASHTABLE_NOT_A_KEY_VALUE;
   hashtable_rc_t         h_rc;
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
   int                        i, j;
-  MBMS_SessionInfoList_r9_t *mbms_SessionInfoList_r9_p = NULL;
-  MBMS_SessionInfo_r9_t     *MBMS_SessionInfo_p        = NULL;
+  LTE_MBMS_SessionInfoList_r9_t *mbms_SessionInfoList_r9_p = NULL;
+  LTE_MBMS_SessionInfo_r9_t     *MBMS_SessionInfo_p        = NULL;
   mbms_session_id_t          mbms_session_id;
   mbms_service_id_t          mbms_service_id;
-  DL_UM_RLC_t                dl_um_rlc;
+  LTE_DL_UM_RLC_t                dl_um_rlc;
 
 
 #endif
@@ -97,17 +97,17 @@ rlc_op_status_t rrc_rlc_config_asn1_req (const protocol_ctxt_t   * const ctxt_pP
 
       if (srb_toaddmod_p->rlc_Config) {
         switch (srb_toaddmod_p->rlc_Config->present) {
-        case SRB_ToAddMod__rlc_Config_PR_NOTHING:
+        case LTE_SRB_ToAddMod__rlc_Config_PR_NOTHING:
           break;
 
-        case SRB_ToAddMod__rlc_Config_PR_explicitValue:
+        case LTE_SRB_ToAddMod__rlc_Config_PR_explicitValue:
           switch (srb_toaddmod_p->rlc_Config->choice.explicitValue.present) {
-          case RLC_Config_PR_NOTHING:
+          case LTE_RLC_Config_PR_NOTHING:
             break;
 
-          case RLC_Config_PR_am:
+          case LTE_RLC_Config_PR_am:
             if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_YES, MBMS_FLAG_NO, rb_id, lc_id, RLC_MODE_AM
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                                 ,0,
                                 0
 #endif
@@ -125,9 +125,9 @@ rlc_op_status_t rrc_rlc_config_asn1_req (const protocol_ctxt_t   * const ctxt_pP
 
             break;
 
-          case RLC_Config_PR_um_Bi_Directional:
+          case LTE_RLC_Config_PR_um_Bi_Directional:
             if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_YES, MBMS_FLAG_NO, rb_id, lc_id, RLC_MODE_UM
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                                 ,0,
                                 0
 #endif
@@ -141,7 +141,7 @@ rlc_op_status_t rrc_rlc_config_asn1_req (const protocol_ctxt_t   * const ctxt_pP
                 &srb_toaddmod_p->rlc_Config->choice.explicitValue.choice.um_Bi_Directional.ul_UM_RLC,
                 &srb_toaddmod_p->rlc_Config->choice.explicitValue.choice.um_Bi_Directional.dl_UM_RLC,
                 rb_id, lc_id
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                ,0, 0
 #endif
                );
@@ -153,9 +153,9 @@ rlc_op_status_t rrc_rlc_config_asn1_req (const protocol_ctxt_t   * const ctxt_pP
 
             break;
 
-          case RLC_Config_PR_um_Uni_Directional_UL:
+          case LTE_RLC_Config_PR_um_Uni_Directional_UL:
             if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_YES, MBMS_FLAG_NO, rb_id, lc_id, RLC_MODE_UM
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                                  ,0,
                                  0
 #endif
@@ -169,7 +169,7 @@ rlc_op_status_t rrc_rlc_config_asn1_req (const protocol_ctxt_t   * const ctxt_pP
                 &srb_toaddmod_p->rlc_Config->choice.explicitValue.choice.um_Uni_Directional_UL.ul_UM_RLC,
                 NULL,
                 rb_id, lc_id
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                ,0, 0
 #endif
                );
@@ -181,9 +181,9 @@ rlc_op_status_t rrc_rlc_config_asn1_req (const protocol_ctxt_t   * const ctxt_pP
 
             break;
 
-          case RLC_Config_PR_um_Uni_Directional_DL:
+          case LTE_RLC_Config_PR_um_Uni_Directional_DL:
             if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_YES, MBMS_FLAG_NO, rb_id, lc_id, RLC_MODE_UM
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                                  ,0,
                                  0
 #endif
@@ -197,7 +197,7 @@ rlc_op_status_t rrc_rlc_config_asn1_req (const protocol_ctxt_t   * const ctxt_pP
                 NULL,
                 &srb_toaddmod_p->rlc_Config->choice.explicitValue.choice.um_Uni_Directional_DL.dl_UM_RLC,
                 rb_id, lc_id
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                ,0, 0
 #endif
                );
@@ -218,19 +218,19 @@ rlc_op_status_t rrc_rlc_config_asn1_req (const protocol_ctxt_t   * const ctxt_pP
 
           break;
 
-        case SRB_ToAddMod__rlc_Config_PR_defaultValue:
+        case LTE_SRB_ToAddMod__rlc_Config_PR_defaultValue:
 //#warning TO DO SRB_ToAddMod__rlc_Config_PR_defaultValue
           LOG_I(RRC, "RLC SRB1 is default value !!\n");
-          struct RLC_Config__am  *  config_am_pP = &srb_toaddmod_p->rlc_Config->choice.explicitValue.choice.am;
-          config_am_pP->dl_AM_RLC.t_Reordering     = T_Reordering_ms35;
-          config_am_pP->dl_AM_RLC.t_StatusProhibit = T_StatusProhibit_ms0;
-          config_am_pP->ul_AM_RLC.t_PollRetransmit = T_PollRetransmit_ms45;
-          config_am_pP->ul_AM_RLC.pollPDU          = PollPDU_pInfinity;
-          config_am_pP->ul_AM_RLC.pollByte         = PollByte_kBinfinity;
-          config_am_pP->ul_AM_RLC.maxRetxThreshold = UL_AM_RLC__maxRetxThreshold_t4;
+          struct LTE_RLC_Config__am  *  config_am_pP = &srb_toaddmod_p->rlc_Config->choice.explicitValue.choice.am;
+          config_am_pP->dl_AM_RLC.t_Reordering     = LTE_T_Reordering_ms35;
+          config_am_pP->dl_AM_RLC.t_StatusProhibit = LTE_T_StatusProhibit_ms0;
+          config_am_pP->ul_AM_RLC.t_PollRetransmit = LTE_T_PollRetransmit_ms45;
+          config_am_pP->ul_AM_RLC.pollPDU          = LTE_PollPDU_pInfinity;
+          config_am_pP->ul_AM_RLC.pollByte         = LTE_PollByte_kBinfinity;
+          config_am_pP->ul_AM_RLC.maxRetxThreshold = LTE_UL_AM_RLC__maxRetxThreshold_t4;
 
           if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_YES, MBMS_FLAG_NO, rb_id, lc_id, RLC_MODE_AM
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                                ,0,
                                0
 #endif
@@ -294,12 +294,12 @@ rlc_op_status_t rrc_rlc_config_asn1_req (const protocol_ctxt_t   * const ctxt_pP
       if (drb_toaddmod_p->rlc_Config) {
 
         switch (drb_toaddmod_p->rlc_Config->present) {
-        case RLC_Config_PR_NOTHING:
+        case LTE_RLC_Config_PR_NOTHING:
           break;
 
-        case RLC_Config_PR_am:
+        case LTE_RLC_Config_PR_am:
           if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_NO, MBMS_FLAG_NO, drb_id, lc_id, RLC_MODE_AM
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                                ,0,
                                0
 #endif
@@ -313,9 +313,9 @@ rlc_op_status_t rrc_rlc_config_asn1_req (const protocol_ctxt_t   * const ctxt_pP
 
           break;
 
-        case RLC_Config_PR_um_Bi_Directional:
+        case LTE_RLC_Config_PR_um_Bi_Directional:
           if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_NO, MBMS_FLAG_NO, drb_id, lc_id, RLC_MODE_UM
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                                ,sourceL2Id,
                                destinationL2Id
 #endif
@@ -329,7 +329,7 @@ rlc_op_status_t rrc_rlc_config_asn1_req (const protocol_ctxt_t   * const ctxt_pP
               &drb_toaddmod_p->rlc_Config->choice.um_Bi_Directional.ul_UM_RLC,
               &drb_toaddmod_p->rlc_Config->choice.um_Bi_Directional.dl_UM_RLC,
               drb_id, lc_id
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
               ,sourceL2Id,
               destinationL2Id
 #endif
@@ -338,9 +338,9 @@ rlc_op_status_t rrc_rlc_config_asn1_req (const protocol_ctxt_t   * const ctxt_pP
 
           break;
 
-        case RLC_Config_PR_um_Uni_Directional_UL:
+        case LTE_RLC_Config_PR_um_Uni_Directional_UL:
           if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_NO, MBMS_FLAG_NO, drb_id, lc_id, RLC_MODE_UM
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                               ,0,
                                0
 #endif
@@ -354,7 +354,7 @@ rlc_op_status_t rrc_rlc_config_asn1_req (const protocol_ctxt_t   * const ctxt_pP
               &drb_toaddmod_p->rlc_Config->choice.um_Uni_Directional_UL.ul_UM_RLC,
               NULL,
               drb_id, lc_id
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                ,0, 0
 #endif
                );
@@ -362,9 +362,9 @@ rlc_op_status_t rrc_rlc_config_asn1_req (const protocol_ctxt_t   * const ctxt_pP
 
           break;
 
-        case RLC_Config_PR_um_Uni_Directional_DL:
+        case LTE_RLC_Config_PR_um_Uni_Directional_DL:
           if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_NO, MBMS_FLAG_NO, drb_id, lc_id, RLC_MODE_UM
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                               ,0,
                                0
 #endif
@@ -378,7 +378,7 @@ rlc_op_status_t rrc_rlc_config_asn1_req (const protocol_ctxt_t   * const ctxt_pP
               NULL,
               &drb_toaddmod_p->rlc_Config->choice.um_Uni_Directional_DL.dl_UM_RLC,
               drb_id, lc_id
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                ,0, 0
 #endif
                );
@@ -406,7 +406,7 @@ rlc_op_status_t rrc_rlc_config_asn1_req (const protocol_ctxt_t   * const ctxt_pP
     }
   }
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 
   if (pmch_InfoList_r9_pP != NULL) {
     for (i=0; i<pmch_InfoList_r9_pP->list.count; i++) {
@@ -424,13 +424,13 @@ rlc_op_status_t rrc_rlc_config_asn1_req (const protocol_ctxt_t   * const ctxt_pP
 
         // can set the mch_id = i
         if (ctxt_pP->enb_flag) {
-          rb_id =  (mbms_service_id * maxSessionPerPMCH ) + mbms_session_id;//+ (maxDRB + 3) * MAX_MOBILES_PER_ENB; // 1
+          rb_id =  (mbms_service_id * LTE_maxSessionPerPMCH ) + mbms_session_id;//+ (LTE_maxDRB + 3) * MAX_MOBILES_PER_ENB; // 1
           rlc_mbms_lcid2service_session_id_eNB[ctxt_pP->module_id][lc_id].service_id                     = mbms_service_id;
           rlc_mbms_lcid2service_session_id_eNB[ctxt_pP->module_id][lc_id].session_id                     = mbms_session_id;
           rlc_mbms_enb_set_lcid_by_rb_id(ctxt_pP->module_id,rb_id,lc_id);
 
         } else {
-          rb_id =  (mbms_service_id * maxSessionPerPMCH ) + mbms_session_id; // + (maxDRB + 3); // 15
+          rb_id =  (mbms_service_id * LTE_maxSessionPerPMCH ) + mbms_session_id; // + (LTE_maxDRB + 3); // 15
           rlc_mbms_lcid2service_session_id_ue[ctxt_pP->module_id][lc_id].service_id                    = mbms_service_id;
           rlc_mbms_lcid2service_session_id_ue[ctxt_pP->module_id][lc_id].session_id                    = mbms_session_id;
           rlc_mbms_ue_set_lcid_by_rb_id(ctxt_pP->module_id,rb_id,lc_id);
@@ -461,8 +461,8 @@ rlc_op_status_t rrc_rlc_config_asn1_req (const protocol_ctxt_t   * const ctxt_pP
               mbms_session_id,
               mbms_service_id
              );
-        dl_um_rlc.sn_FieldLength = SN_FieldLength_size5;
-        dl_um_rlc.t_Reordering   = T_Reordering_ms0;
+        dl_um_rlc.sn_FieldLength = LTE_SN_FieldLength_size5;
+        dl_um_rlc.t_Reordering   = LTE_T_Reordering_ms0;
 
         config_req_rlc_um_asn1 (
           ctxt_pP,
@@ -473,7 +473,7 @@ rlc_op_status_t rrc_rlc_config_asn1_req (const protocol_ctxt_t   * const ctxt_pP
           NULL,
           &dl_um_rlc,
           rb_id, lc_id
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
           ,0, 0
 #endif
                );
@@ -536,7 +536,7 @@ rlc_op_status_t rrc_rlc_remove_ue (
                        rb_id);
   }
 
-  for (rb_id = 1; rb_id <= maxDRB; rb_id++) {
+  for (rb_id = 1; rb_id <= LTE_maxDRB; rb_id++) {
     rrc_rlc_remove_rlc(ctxt_pP,
                        SRB_FLAG_NO,
                        MBMS_FLAG_NO,
@@ -560,14 +560,14 @@ rlc_op_status_t rrc_rlc_remove_rlc   (
   hash_key_t             key_lcid        = HASHTABLE_NOT_A_KEY_VALUE;
   hashtable_rc_t         h_lcid_rc;
   rlc_union_t           *rlc_union_p = NULL;
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
   rlc_mbms_id_t         *mbms_id_p  = NULL;
 #endif
 
   /* for no gcc warnings */
   (void)lcid;
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 
   if (MBMS_flagP == TRUE) {
     if (ctxt_pP->enb_flag) {
@@ -658,7 +658,7 @@ rlc_union_t* rrc_rlc_add_rlc   (
   const rb_id_t           rb_idP,
   const logical_chan_id_t chan_idP,
   const rlc_mode_t        rlc_modeP
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   ,const uint32_t sourceL2Id,
   const uint32_t  destinationL2Id
 #endif
@@ -671,7 +671,7 @@ rlc_union_t* rrc_rlc_add_rlc   (
   hash_key_t             key_lcid    = HASHTABLE_NOT_A_KEY_VALUE;
   hashtable_rc_t         h_lcid_rc;
   rlc_union_t           *rlc_union_p = NULL;
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
   rlc_mbms_id_t         *mbms_id_p  = NULL;
   logical_chan_id_t      lcid            = 0;
 #endif
@@ -691,7 +691,7 @@ rlc_union_t* rrc_rlc_add_rlc   (
 
   }
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 
   if (MBMS_flagP == TRUE) {
     if (ctxt_pP->enb_flag) {
@@ -741,7 +741,7 @@ rlc_union_t* rrc_rlc_add_rlc   (
     h_lcid_rc = hashtable_insert(rlc_coll_p, key_lcid, rlc_union_p);
 
     if ((h_rc == HASH_TABLE_OK) && (h_lcid_rc == HASH_TABLE_OK)) {
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 
       if (MBMS_flagP == TRUE) {
         LOG_I(RLC, PROTOCOL_CTXT_FMT" RLC service id %u session id %u rrc_rlc_add_rlc\n",
@@ -806,7 +806,7 @@ rlc_op_status_t rrc_rlc_config_req   (
 
   case CONFIG_ACTION_ADD:
     if (rrc_rlc_add_rlc(ctxt_pP, srb_flagP, MBMS_FLAG_NO, rb_idP, rb_idP, rlc_infoP.rlc_mode
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                         ,0,
                         0
 #endif
@@ -885,7 +885,7 @@ rlc_op_status_t rrc_rlc_data_req     (
   if (sdu != NULL) {
     memcpy (sdu->data, sduP, sdu_sizeP);
     return rlc_data_req(ctxt_pP, SRB_FLAG_YES, MBMS_flagP, rb_idP, muiP, confirmP, sdu_sizeP, sdu
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                         ,NULL, NULL
 #endif
                         );
diff --git a/openair2/LAYER2/openair2_proc.c b/openair2/LAYER2/openair2_proc.c
index fcfade4720bd022130654692947d213a0e84268c..2251344c47f1c6714bfdcf9b6c3a3ea613c0248f 100644
--- a/openair2/LAYER2/openair2_proc.c
+++ b/openair2/LAYER2/openair2_proc.c
@@ -39,644 +39,586 @@
 #include "common/ran_context.h"
 
 static mapping rrc_status_names[] = {
-  {"RRC_INACTIVE", 0},
-  {"RRC_IDLE", 1},
-  {"RRC_SI_RECEIVED",2},
-  {"RRC_CONNECTED",3},
-  {"RRC_RECONFIGURED",4},
-  {"RRC_HO_EXECUTION",5},
-  {NULL, -1}
+    {"RRC_INACTIVE", 0},
+    {"RRC_IDLE", 1},
+    {"RRC_SI_RECEIVED",2},
+    {"RRC_CONNECTED",3},
+    {"RRC_RECONFIGURED",4},
+    {"RRC_HO_EXECUTION",5},
+    {NULL, -1}
 };
 
 extern RAN_CONTEXT_t RC;
 
-int dump_eNB_l2_stats(char *buffer, int length)
-{
-
-  int eNB_id,UE_id,number_of_cards;
-  int len= length;
-  int CC_id=0;
-  int i;
-  protocol_ctxt_t      ctxt;
-  rlc_op_status_t rlc_status;
-  unsigned int stat_rlc_mode;
-  unsigned int stat_tx_pdcp_sdu;
-  unsigned int stat_tx_pdcp_bytes;
-  unsigned int stat_tx_pdcp_sdu_discarded;
-  unsigned int stat_tx_pdcp_bytes_discarded;
-  unsigned int stat_tx_data_pdu;
-  unsigned int  stat_tx_data_bytes;
-  unsigned int  stat_tx_retransmit_pdu_by_status;
-  unsigned int  stat_tx_retransmit_bytes_by_status;
-  unsigned int stat_tx_retransmit_pdu;
-  unsigned int  stat_tx_retransmit_bytes;
-  unsigned int  stat_tx_control_pdu;
-  unsigned int  stat_tx_control_bytes;
-  unsigned int  stat_rx_pdcp_sdu;
-  unsigned int  stat_rx_pdcp_bytes;
-  unsigned int  stat_rx_data_pdus_duplicate;
-  unsigned int  stat_rx_data_bytes_duplicate;
-  unsigned int  stat_rx_data_pdu;
-  unsigned int  stat_rx_data_bytes;
-  unsigned int  stat_rx_data_pdu_dropped;
-  unsigned int  stat_rx_data_bytes_dropped;
-  unsigned int  stat_rx_data_pdu_out_of_window;
-  unsigned int  stat_rx_data_bytes_out_of_window;
-  unsigned int  stat_rx_control_pdu;
-  unsigned int  stat_rx_control_bytes;
-  unsigned int  stat_timer_reordering_timed_out;
-  unsigned int  stat_timer_poll_retransmit_timed_out;
-  unsigned int  stat_timer_status_prohibit_timed_out;
-
+int dump_eNB_l2_stats(char *buffer, int length) {
+    int eNB_id,UE_id,number_of_cards;
+    int len= length;
+    int CC_id=0;
+    int i;
+    protocol_ctxt_t      ctxt;
+    rlc_op_status_t rlc_status;
+    unsigned int stat_rlc_mode;
+    unsigned int stat_tx_pdcp_sdu;
+    unsigned int stat_tx_pdcp_bytes;
+    unsigned int stat_tx_pdcp_sdu_discarded;
+    unsigned int stat_tx_pdcp_bytes_discarded;
+    unsigned int stat_tx_data_pdu;
+    unsigned int  stat_tx_data_bytes;
+    unsigned int  stat_tx_retransmit_pdu_by_status;
+    unsigned int  stat_tx_retransmit_bytes_by_status;
+    unsigned int stat_tx_retransmit_pdu;
+    unsigned int  stat_tx_retransmit_bytes;
+    unsigned int  stat_tx_control_pdu;
+    unsigned int  stat_tx_control_bytes;
+    unsigned int  stat_rx_pdcp_sdu;
+    unsigned int  stat_rx_pdcp_bytes;
+    unsigned int  stat_rx_data_pdus_duplicate;
+    unsigned int  stat_rx_data_bytes_duplicate;
+    unsigned int  stat_rx_data_pdu;
+    unsigned int  stat_rx_data_bytes;
+    unsigned int  stat_rx_data_pdu_dropped;
+    unsigned int  stat_rx_data_bytes_dropped;
+    unsigned int  stat_rx_data_pdu_out_of_window;
+    unsigned int  stat_rx_data_bytes_out_of_window;
+    unsigned int  stat_rx_control_pdu;
+    unsigned int  stat_rx_control_bytes;
+    unsigned int  stat_timer_reordering_timed_out;
+    unsigned int  stat_timer_poll_retransmit_timed_out;
+    unsigned int  stat_timer_status_prohibit_timed_out;
 #ifdef EXMIMO
-  number_of_cards=1;
+    number_of_cards=1;
 #else
-  number_of_cards=NB_eNB_INST;
+    number_of_cards=NB_eNB_INST;
 #endif
-  eNB_MAC_INST *eNB;
-  UE_list_t *UE_list;
-
-  for (eNB_id=0; eNB_id<number_of_cards; eNB_id++) {
-    /* reset the values */
-    eNB = RC.mac[eNB_id];
-    UE_list = &eNB->UE_list;
-
-    for (CC_id=0 ; CC_id < MAX_NUM_CCs; CC_id++) {
-      eNB->eNB_stats[CC_id].dlsch_bitrate= 0;
-
-      len += sprintf(&buffer[len],"eNB %d CC %d Frame %d: Active UEs %d, Available PRBs %d, nCCE %d, Scheduling decisions %d, Missed Deadlines %d \n",
-                     eNB_id, CC_id, eNB->frame,
-                     eNB->eNB_stats[CC_id].num_dlactive_UEs,
-                     eNB->eNB_stats[CC_id].available_prbs,
-                     eNB->eNB_stats[CC_id].available_ncces,
-		     eNB->eNB_stats[CC_id].sched_decisions,
-		     eNB->eNB_stats[CC_id].missed_deadlines);
-      
-      len += sprintf(&buffer[len],"BCCH , NB_TX_MAC = %d, transmitted bytes (TTI %d, total %d) MCS (TTI %d)\n",
-		     eNB->eNB_stats[CC_id].total_num_bcch_pdu,
-		     eNB->eNB_stats[CC_id].bcch_buffer,
-		     eNB->eNB_stats[CC_id].total_bcch_buffer,
-		     eNB->eNB_stats[CC_id].bcch_mcs);
-
-      len += sprintf(&buffer[len],"PCCH , NB_TX_MAC = %d, transmitted bytes (TTI %d, total %d) MCS (TTI %d)\n",
-         eNB->eNB_stats[CC_id].total_num_pcch_pdu,
-         eNB->eNB_stats[CC_id].pcch_buffer,
-         eNB->eNB_stats[CC_id].total_pcch_buffer,
-         eNB->eNB_stats[CC_id].pcch_mcs);
-      
-      eNB->eNB_stats[CC_id].dlsch_bitrate=((eNB->eNB_stats[CC_id].dlsch_bytes_tx*8)/((eNB->frame + 1)*10));
-      eNB->eNB_stats[CC_id].total_dlsch_pdus_tx+=eNB->eNB_stats[CC_id].dlsch_pdus_tx;
-      eNB->eNB_stats[CC_id].total_dlsch_bytes_tx+=eNB->eNB_stats[CC_id].dlsch_bytes_tx;
-      eNB->eNB_stats[CC_id].total_dlsch_bitrate=((eNB->eNB_stats[CC_id].total_dlsch_bytes_tx*8)/((eNB->frame + 1)*10));
-
-      eNB->eNB_stats[CC_id].ulsch_bitrate=((eNB->eNB_stats[CC_id].ulsch_bytes_rx*8)/((eNB->frame + 1)*10));
-      eNB->eNB_stats[CC_id].total_ulsch_bitrate=((eNB->eNB_stats[CC_id].total_ulsch_bytes_rx*8)/((eNB->frame + 1)*10));
-
-      len += sprintf(&buffer[len],"DLSCH bitrate (TTI %u, avg %u) kbps, Transmitted bytes (TTI %u, total %u), Transmitted PDU (TTI %u, total %u) \n",
-                     eNB->eNB_stats[CC_id].dlsch_bitrate,
-                     eNB->eNB_stats[CC_id].total_dlsch_bitrate,
-                     eNB->eNB_stats[CC_id].dlsch_bytes_tx,
-                     eNB->eNB_stats[CC_id].total_dlsch_bytes_tx,
-                     eNB->eNB_stats[CC_id].dlsch_pdus_tx,
-                     eNB->eNB_stats[CC_id].total_dlsch_pdus_tx);
-
-      len += sprintf(&buffer[len],"ULSCH bitrate (TTI %u, avg %u) kbps, Received bytes (TTI %u, total %u), Received PDU (TTI %lu, total %u) \n",
-                     eNB->eNB_stats[CC_id].ulsch_bitrate,
-                     eNB->eNB_stats[CC_id].total_ulsch_bitrate,
-                     eNB->eNB_stats[CC_id].ulsch_bytes_rx,
-                     eNB->eNB_stats[CC_id].total_ulsch_bytes_rx,
-                     eNB->eNB_stats[CC_id].ulsch_pdus_rx,
-                     eNB->eNB_stats[CC_id].total_ulsch_pdus_rx);
-    }
+    eNB_MAC_INST *eNB;
+    UE_list_t *UE_list;
+
+    for (eNB_id=0; eNB_id<number_of_cards; eNB_id++) {
+        /* reset the values */
+        eNB = RC.mac[eNB_id];
+        UE_list = &eNB->UE_list;
+
+        for (CC_id=0 ; CC_id < MAX_NUM_CCs; CC_id++) {
+            eNB->eNB_stats[CC_id].dlsch_bitrate= 0;
+            len += sprintf(&buffer[len],"eNB %d CC %d Frame %d: Active UEs %d, Available PRBs %d, nCCE %d, Scheduling decisions %d, Missed Deadlines %d \n",
+                           eNB_id, CC_id, eNB->frame,
+                           eNB->eNB_stats[CC_id].num_dlactive_UEs,
+                           eNB->eNB_stats[CC_id].available_prbs,
+                           eNB->eNB_stats[CC_id].available_ncces,
+                           eNB->eNB_stats[CC_id].sched_decisions,
+                           eNB->eNB_stats[CC_id].missed_deadlines);
+            len += sprintf(&buffer[len],"BCCH , NB_TX_MAC = %d, transmitted bytes (TTI %d, total %d) MCS (TTI %d)\n",
+                           eNB->eNB_stats[CC_id].total_num_bcch_pdu,
+                           eNB->eNB_stats[CC_id].bcch_buffer,
+                           eNB->eNB_stats[CC_id].total_bcch_buffer,
+                           eNB->eNB_stats[CC_id].bcch_mcs);
+            len += sprintf(&buffer[len],"PCCH , NB_TX_MAC = %d, transmitted bytes (TTI %d, total %d) MCS (TTI %d)\n",
+                           eNB->eNB_stats[CC_id].total_num_pcch_pdu,
+                           eNB->eNB_stats[CC_id].pcch_buffer,
+                           eNB->eNB_stats[CC_id].total_pcch_buffer,
+                           eNB->eNB_stats[CC_id].pcch_mcs);
+            eNB->eNB_stats[CC_id].dlsch_bitrate=((eNB->eNB_stats[CC_id].dlsch_bytes_tx*8)/((eNB->frame + 1)*10));
+            eNB->eNB_stats[CC_id].total_dlsch_pdus_tx+=eNB->eNB_stats[CC_id].dlsch_pdus_tx;
+            eNB->eNB_stats[CC_id].total_dlsch_bytes_tx+=eNB->eNB_stats[CC_id].dlsch_bytes_tx;
+            eNB->eNB_stats[CC_id].total_dlsch_bitrate=((eNB->eNB_stats[CC_id].total_dlsch_bytes_tx*8)/((eNB->frame + 1)*10));
+            eNB->eNB_stats[CC_id].ulsch_bitrate=((eNB->eNB_stats[CC_id].ulsch_bytes_rx*8)/((eNB->frame + 1)*10));
+            eNB->eNB_stats[CC_id].total_ulsch_bitrate=((eNB->eNB_stats[CC_id].total_ulsch_bytes_rx*8)/((eNB->frame + 1)*10));
+            len += sprintf(&buffer[len],"DLSCH bitrate (TTI %u, avg %u) kbps, Transmitted bytes (TTI %u, total %u), Transmitted PDU (TTI %u, total %u) \n",
+                           eNB->eNB_stats[CC_id].dlsch_bitrate,
+                           eNB->eNB_stats[CC_id].total_dlsch_bitrate,
+                           eNB->eNB_stats[CC_id].dlsch_bytes_tx,
+                           eNB->eNB_stats[CC_id].total_dlsch_bytes_tx,
+                           eNB->eNB_stats[CC_id].dlsch_pdus_tx,
+                           eNB->eNB_stats[CC_id].total_dlsch_pdus_tx);
+            len += sprintf(&buffer[len],"ULSCH bitrate (TTI %u, avg %u) kbps, Received bytes (TTI %u, total %u), Received PDU (TTI %lu, total %u) \n",
+                           eNB->eNB_stats[CC_id].ulsch_bitrate,
+                           eNB->eNB_stats[CC_id].total_ulsch_bitrate,
+                           eNB->eNB_stats[CC_id].ulsch_bytes_rx,
+                           eNB->eNB_stats[CC_id].total_ulsch_bytes_rx,
+                           eNB->eNB_stats[CC_id].ulsch_pdus_rx,
+                           eNB->eNB_stats[CC_id].total_ulsch_pdus_rx);
+        }
+
+        len += sprintf(&buffer[len],"\n");
+
+        for (UE_id=UE_list->head; UE_id>=0; UE_id=UE_list->next[UE_id]) {
+            for (i=0; i<UE_list->numactiveCCs[UE_id]; i++) {
+                CC_id=UE_list->ordered_CCids[i][UE_id];
+                UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_bitrate=((UE_list->eNB_UE_stats[CC_id][UE_id].TBS*8)/((eNB->frame + 1)*10));
+                UE_list->eNB_UE_stats[CC_id][UE_id].total_dlsch_bitrate= ((UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes*8)/((eNB->frame + 1)*10));
+                UE_list->eNB_UE_stats[CC_id][UE_id].total_overhead_bytes+=  UE_list->eNB_UE_stats[CC_id][UE_id].overhead_bytes;
+                UE_list->eNB_UE_stats[CC_id][UE_id].avg_overhead_bytes=((UE_list->eNB_UE_stats[CC_id][UE_id].total_overhead_bytes*8)/((eNB->frame + 1)*10));
+                UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_bitrate=((UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_TBS*8)/((eNB->frame + 1)*10));
+                UE_list->eNB_UE_stats[CC_id][UE_id].total_ulsch_bitrate= ((UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes_rx*8)/((eNB->frame + 1)*10));
+                len += sprintf(&buffer[len],"[MAC] UE %d (DLSCH),status %s, RNTI %x : CQI %d, MCS1 %d, MCS2 %d, RB (tx %d, retx %d, total %d), ncce (tx %d, retx %d) \n",
+                               UE_id,
+                               map_int_to_str(rrc_status_names, UE_list->eNB_UE_stats[CC_id][UE_id].rrc_status),
+                               UE_list->eNB_UE_stats[CC_id][UE_id].crnti,
+                               UE_list->UE_sched_ctrl[UE_id].dl_cqi[CC_id],
+                               UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs1,
+                               UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs2,
+                               UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used,
+                               UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used_retx,
+                               UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used,
+                               UE_list->eNB_UE_stats[CC_id][UE_id].ncce_used,
+                               UE_list->eNB_UE_stats[CC_id][UE_id].ncce_used_retx
+                              );
+                len += sprintf(&buffer[len],
+                               "[MAC] DLSCH bitrate (TTI %d, avg %d), Transmitted bytes "
+                               "(TTI %d, total %"PRIu64"), Total Transmitted PDU %d, Overhead "
+                               "(TTI %"PRIu64", total %"PRIu64", avg %"PRIu64")\n",
+                               UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_bitrate,
+                               UE_list->eNB_UE_stats[CC_id][UE_id].total_dlsch_bitrate,
+                               UE_list->eNB_UE_stats[CC_id][UE_id].TBS,
+                               UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes,
+                               UE_list->eNB_UE_stats[CC_id][UE_id].total_num_pdus,
+                               UE_list->eNB_UE_stats[CC_id][UE_id].overhead_bytes,
+                               UE_list->eNB_UE_stats[CC_id][UE_id].total_overhead_bytes,
+                               UE_list->eNB_UE_stats[CC_id][UE_id].avg_overhead_bytes
+                              );
+                len += sprintf(&buffer[len],"[MAC] UE %d (ULSCH), Status %s, Failute timer %d, RNTI %x : rx power (normalized %d,  target %d), MCS (pre %d, post %d), RB (rx %d, retx %d, total %d), Current TBS %d \n",
+                               UE_id,
+                               map_int_to_str(rrc_status_names, UE_list->eNB_UE_stats[CC_id][UE_id].rrc_status),
+                               UE_list->UE_sched_ctrl[UE_id].ul_failure_timer,
+                               UE_list->eNB_UE_stats[CC_id][UE_id].crnti,
+                               UE_list->eNB_UE_stats[CC_id][UE_id].normalized_rx_power,
+                               UE_list->eNB_UE_stats[CC_id][UE_id].target_rx_power,
+                               UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs1,
+                               UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs2,
+                               UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used_rx,
+                               UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used_retx_rx,
+                               UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used_rx,
+                               UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_TBS
+                              );
+                len += sprintf(&buffer[len],
+                               "[MAC] ULSCH bitrate (TTI %d, avg %d), received bytes (total %"PRIu64"),"
+                               "Total received PDU %d, Total errors %d\n",
+                               UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_bitrate,
+                               UE_list->eNB_UE_stats[CC_id][UE_id].total_ulsch_bitrate,
+                               UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes_rx,
+                               UE_list->eNB_UE_stats[CC_id][UE_id].total_num_pdus_rx,
+                               UE_list->eNB_UE_stats[CC_id][UE_id].num_errors_rx);
+                len+= sprintf(&buffer[len],"[MAC] Received PHR PH = %d (db)\n", UE_list->UE_template[CC_id][UE_id].phr_info);
+                len+= sprintf(&buffer[len],"[MAC] Estimated size LCGID[0][1][2][3] = %u %u %u %u\n",
+                              UE_list->UE_template[CC_id][UE_id].ul_buffer_info[LCGID0],
+                              UE_list->UE_template[CC_id][UE_id].ul_buffer_info[LCGID1],
+                              UE_list->UE_template[CC_id][UE_id].ul_buffer_info[LCGID2],
+                              UE_list->UE_template[CC_id][UE_id].ul_buffer_info[LCGID3]
+                             );
+            }
+
+            PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt,
+                                           eNB_id,
+                                           ENB_FLAG_YES,
+                                           UE_list->eNB_UE_stats[0][UE_id].crnti,//UE_PCCID(eNB_id,UE_id)][UE_id].crnti,
+                                           eNB->frame,
+                                           eNB->subframe,
+                                           eNB_id);
+            rlc_status = rlc_stat_req(&ctxt,
+                                      SRB_FLAG_YES,
+                                      DCCH,
+                                      &stat_rlc_mode,
+                                      &stat_tx_pdcp_sdu,
+                                      &stat_tx_pdcp_bytes,
+                                      &stat_tx_pdcp_sdu_discarded,
+                                      &stat_tx_pdcp_bytes_discarded,
+                                      &stat_tx_data_pdu,
+                                      &stat_tx_data_bytes,
+                                      &stat_tx_retransmit_pdu_by_status,
+                                      &stat_tx_retransmit_bytes_by_status,
+                                      &stat_tx_retransmit_pdu,
+                                      &stat_tx_retransmit_bytes,
+                                      &stat_tx_control_pdu,
+                                      &stat_tx_control_bytes,
+                                      &stat_rx_pdcp_sdu,
+                                      &stat_rx_pdcp_bytes,
+                                      &stat_rx_data_pdus_duplicate,
+                                      &stat_rx_data_bytes_duplicate,
+                                      &stat_rx_data_pdu,
+                                      &stat_rx_data_bytes,
+                                      &stat_rx_data_pdu_dropped,
+                                      &stat_rx_data_bytes_dropped,
+                                      &stat_rx_data_pdu_out_of_window,
+                                      &stat_rx_data_bytes_out_of_window,
+                                      &stat_rx_control_pdu,
+                                      &stat_rx_control_bytes,
+                                      &stat_timer_reordering_timed_out,
+                                      &stat_timer_poll_retransmit_timed_out,
+                                      &stat_timer_status_prohibit_timed_out);
+
+            if (rlc_status == RLC_OP_STATUS_OK) {
+                len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, NB_SDU_TO_TX = %u (bytes %u)\tNB_SDU_TO_TX_DISC %u (bytes %u)\n",
+                             (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE",
+                             stat_tx_pdcp_sdu,
+                             stat_tx_pdcp_bytes,
+                             stat_tx_pdcp_sdu_discarded,
+                             stat_tx_pdcp_bytes_discarded);
+                len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, NB_TX_DATA   = %u (bytes %u)\tNB_TX_CONTROL %u (bytes %u)\tNB_TX_RETX %u (bytes %u)\tNB_TX_RETX_BY_STATUS = %u (bytes %u)\n",
+                             (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE",
+                             stat_tx_data_pdu,
+                             stat_tx_data_bytes,
+                             stat_tx_control_pdu,
+                             stat_tx_control_bytes,
+                             stat_tx_retransmit_pdu,
+                             stat_tx_retransmit_bytes,
+                             stat_tx_retransmit_pdu_by_status,
+                             stat_tx_retransmit_bytes_by_status);
+                len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, NB_RX_DATA   = %u (bytes %u)\tNB_RX_CONTROL %u (bytes %u)\tNB_RX_DUPL %u (bytes %u)\tNB_RX_DROP = %u (bytes %u)\tNB_RX_OUT_OF_WINDOW = %u (bytes %u)\n",
+                             (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE",
+                             stat_rx_data_pdu,
+                             stat_rx_data_bytes,
+                             stat_rx_control_pdu,
+                             stat_rx_control_bytes,
+                             stat_rx_data_pdus_duplicate,
+                             stat_rx_data_bytes_duplicate,
+                             stat_rx_data_pdu_dropped,
+                             stat_rx_data_bytes_dropped,
+                             stat_rx_data_pdu_out_of_window,
+                             stat_rx_data_bytes_out_of_window);
+                len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, RX_REODERING_TIMEOUT = %u\tRX_POLL_RET_TIMEOUT %u\tRX_PROHIBIT_TIME_OUT %u\n",
+                             (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE",
+                             stat_timer_reordering_timed_out,
+                             stat_timer_poll_retransmit_timed_out,
+                             stat_timer_status_prohibit_timed_out);
+                len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, NB_SDU_TO_RX = %u (bytes %u)\n",
+                             (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE",
+                             stat_rx_pdcp_sdu,
+                             stat_rx_pdcp_bytes);
+            }
 
-    len += sprintf(&buffer[len],"\n");
-
-    for (UE_id=UE_list->head; UE_id>=0; UE_id=UE_list->next[UE_id]) {
-      for (i=0; i<UE_list->numactiveCCs[UE_id]; i++) {
-        CC_id=UE_list->ordered_CCids[i][UE_id];
-	
-	UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_bitrate=((UE_list->eNB_UE_stats[CC_id][UE_id].TBS*8)/((eNB->frame + 1)*10));
-        UE_list->eNB_UE_stats[CC_id][UE_id].total_dlsch_bitrate= ((UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes*8)/((eNB->frame + 1)*10));
-        UE_list->eNB_UE_stats[CC_id][UE_id].total_overhead_bytes+=  UE_list->eNB_UE_stats[CC_id][UE_id].overhead_bytes;
-        UE_list->eNB_UE_stats[CC_id][UE_id].avg_overhead_bytes=((UE_list->eNB_UE_stats[CC_id][UE_id].total_overhead_bytes*8)/((eNB->frame + 1)*10));
-	
-	UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_bitrate=((UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_TBS*8)/((eNB->frame + 1)*10));
-        UE_list->eNB_UE_stats[CC_id][UE_id].total_ulsch_bitrate= ((UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes_rx*8)/((eNB->frame + 1)*10));
-       
-        len += sprintf(&buffer[len],"[MAC] UE %d (DLSCH),status %s, RNTI %x : CQI %d, MCS1 %d, MCS2 %d, RB (tx %d, retx %d, total %d), ncce (tx %d, retx %d) \n",
-                       UE_id,
-                       map_int_to_str(rrc_status_names, UE_list->eNB_UE_stats[CC_id][UE_id].rrc_status),
-                       UE_list->eNB_UE_stats[CC_id][UE_id].crnti,
-                       UE_list->UE_sched_ctrl[UE_id].dl_cqi[CC_id],
-                       UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs1,
-                       UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs2,
-                       UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used,
-                       UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used_retx,
-                       UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used,
-                       UE_list->eNB_UE_stats[CC_id][UE_id].ncce_used,
-                       UE_list->eNB_UE_stats[CC_id][UE_id].ncce_used_retx
-                      );
-
-        len += sprintf(&buffer[len],
-                       "[MAC] DLSCH bitrate (TTI %d, avg %d), Transmitted bytes "
-                       "(TTI %d, total %"PRIu64"), Total Transmitted PDU %d, Overhead "
-                       "(TTI %"PRIu64", total %"PRIu64", avg %"PRIu64")\n",
-                       UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_bitrate,
-                       UE_list->eNB_UE_stats[CC_id][UE_id].total_dlsch_bitrate,
-                       UE_list->eNB_UE_stats[CC_id][UE_id].TBS,
-                       UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes,
-                       UE_list->eNB_UE_stats[CC_id][UE_id].total_num_pdus,
-                       UE_list->eNB_UE_stats[CC_id][UE_id].overhead_bytes,
-                       UE_list->eNB_UE_stats[CC_id][UE_id].total_overhead_bytes,
-                       UE_list->eNB_UE_stats[CC_id][UE_id].avg_overhead_bytes
-                      );
-        
-
-	len += sprintf(&buffer[len],"[MAC] UE %d (ULSCH), Status %s, Failute timer %d, RNTI %x : rx power (normalized %d,  target %d), MCS (pre %d, post %d), RB (rx %d, retx %d, total %d), Current TBS %d \n",
-                       UE_id,
-                       map_int_to_str(rrc_status_names, UE_list->eNB_UE_stats[CC_id][UE_id].rrc_status),
-		       UE_list->UE_sched_ctrl[UE_id].ul_failure_timer,
-                       UE_list->eNB_UE_stats[CC_id][UE_id].crnti,
-		       UE_list->eNB_UE_stats[CC_id][UE_id].normalized_rx_power,
-		       UE_list->eNB_UE_stats[CC_id][UE_id].target_rx_power,
-		       UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs1,
-		       UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs2,
-		       UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used_rx,
-		       UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used_retx_rx,
-		       UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used_rx,
-		       UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_TBS
-		       );
-
-	len += sprintf(&buffer[len],
-                       "[MAC] ULSCH bitrate (TTI %d, avg %d), received bytes (total %"PRIu64"),"
-                       "Total received PDU %d, Total errors %d\n", 
-		       UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_bitrate,
-                       UE_list->eNB_UE_stats[CC_id][UE_id].total_ulsch_bitrate,
-                       UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes_rx,
-                       UE_list->eNB_UE_stats[CC_id][UE_id].total_num_pdus_rx,
-                       UE_list->eNB_UE_stats[CC_id][UE_id].num_errors_rx);
-
-        len+= sprintf(&buffer[len],"[MAC] Received PHR PH = %d (db)\n", UE_list->UE_template[CC_id][UE_id].phr_info);
-        len+= sprintf(&buffer[len],"[MAC] Estimated size LCGID[0][1][2][3] = %u %u %u %u\n",
-                      UE_list->UE_template[CC_id][UE_id].ul_buffer_info[LCGID0],
-                      UE_list->UE_template[CC_id][UE_id].ul_buffer_info[LCGID1],
-                      UE_list->UE_template[CC_id][UE_id].ul_buffer_info[LCGID2],
-                      UE_list->UE_template[CC_id][UE_id].ul_buffer_info[LCGID3]
-                     );
-      }
-      
-      PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt,
-				     eNB_id,
-				     ENB_FLAG_YES,
-				     UE_list->eNB_UE_stats[0][UE_id].crnti,//UE_PCCID(eNB_id,UE_id)][UE_id].crnti, 
-				     eNB->frame,
-				     eNB->subframe,
-				     eNB_id);
-
-      rlc_status = rlc_stat_req(&ctxt,
-				SRB_FLAG_YES,
-				DCCH,
-				&stat_rlc_mode,
-				&stat_tx_pdcp_sdu,
-				&stat_tx_pdcp_bytes,
-				&stat_tx_pdcp_sdu_discarded,
-				&stat_tx_pdcp_bytes_discarded,
-				&stat_tx_data_pdu,
-				&stat_tx_data_bytes,
-				&stat_tx_retransmit_pdu_by_status,
-				&stat_tx_retransmit_bytes_by_status,
-				&stat_tx_retransmit_pdu,
-				&stat_tx_retransmit_bytes,
-				&stat_tx_control_pdu,
-				&stat_tx_control_bytes,
-				&stat_rx_pdcp_sdu,
-				&stat_rx_pdcp_bytes,
-				&stat_rx_data_pdus_duplicate,
-				&stat_rx_data_bytes_duplicate,
-				&stat_rx_data_pdu,
-				&stat_rx_data_bytes,
-				&stat_rx_data_pdu_dropped,
-				&stat_rx_data_bytes_dropped,
-				&stat_rx_data_pdu_out_of_window,
-				&stat_rx_data_bytes_out_of_window,
-				&stat_rx_control_pdu,
-				&stat_rx_control_bytes,
-				&stat_timer_reordering_timed_out,
-				&stat_timer_poll_retransmit_timed_out,
-				&stat_timer_status_prohibit_timed_out);
-      
-      if (rlc_status == RLC_OP_STATUS_OK) {
-	len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, NB_SDU_TO_TX = %d (bytes %d)\tNB_SDU_TO_TX_DISC %d (bytes %d)\n",
-		     (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE",
-		     stat_tx_pdcp_sdu,
-		     stat_tx_pdcp_bytes,
-		     stat_tx_pdcp_sdu_discarded,
-		     stat_tx_pdcp_bytes_discarded);
-	
-	len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, NB_TX_DATA   = %d (bytes %d)\tNB_TX_CONTROL %d (bytes %d)\tNB_TX_RETX %d (bytes %d)\tNB_TX_RETX_BY_STATUS = %d (bytes %d)\n",
-		     (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE",
-		     stat_tx_data_pdu,
-		     stat_tx_data_bytes,
-		     stat_tx_control_pdu,
-		     stat_tx_control_bytes,
-		     stat_tx_retransmit_pdu,
-		     stat_tx_retransmit_bytes,
-		     stat_tx_retransmit_pdu_by_status,
-		     stat_tx_retransmit_bytes_by_status);
-		
-	
-	len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, NB_RX_DATA   = %d (bytes %d)\tNB_RX_CONTROL %d (bytes %d)\tNB_RX_DUPL %d (bytes %d)\tNB_RX_DROP = %d (bytes %d)\tNB_RX_OUT_OF_WINDOW = %d (bytes %d)\n",
-		     (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE",
-		     stat_rx_data_pdu,
-		     stat_rx_data_bytes,
-		     stat_rx_control_pdu,
-		     stat_rx_control_bytes,
-		     stat_rx_data_pdus_duplicate,
-		     stat_rx_data_bytes_duplicate,
-		     stat_rx_data_pdu_dropped,
-		     stat_rx_data_bytes_dropped,
-		     stat_rx_data_pdu_out_of_window,
-		     stat_rx_data_bytes_out_of_window);
-	
-
-	len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, RX_REODERING_TIMEOUT = %d\tRX_POLL_RET_TIMEOUT %d\tRX_PROHIBIT_TIME_OUT %d\n",
-		     (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE",
-		     stat_timer_reordering_timed_out,
-		     stat_timer_poll_retransmit_timed_out,
-		     stat_timer_status_prohibit_timed_out);
-
-	len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, NB_SDU_TO_RX = %d (bytes %d)\n",
-		     (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE",
-		     stat_rx_pdcp_sdu,
-		     stat_rx_pdcp_bytes);
-      }
-      
-      rlc_status = rlc_stat_req(&ctxt,
-				SRB_FLAG_NO,
-				DTCH-2, // DRB_IDENTITY
-				&stat_rlc_mode,
-				&stat_tx_pdcp_sdu,
-				&stat_tx_pdcp_bytes,
-				&stat_tx_pdcp_sdu_discarded,
-				&stat_tx_pdcp_bytes_discarded,
-				&stat_tx_data_pdu,
-				&stat_tx_data_bytes,
-				&stat_tx_retransmit_pdu_by_status,
-				&stat_tx_retransmit_bytes_by_status,
-				&stat_tx_retransmit_pdu,
-				&stat_tx_retransmit_bytes,
-				&stat_tx_control_pdu,
-				&stat_tx_control_bytes,
-				&stat_rx_pdcp_sdu,
-				&stat_rx_pdcp_bytes,
-				&stat_rx_data_pdus_duplicate,
-				&stat_rx_data_bytes_duplicate,
-				&stat_rx_data_pdu,
-				&stat_rx_data_bytes,
-				&stat_rx_data_pdu_dropped,
-				&stat_rx_data_bytes_dropped,
-				&stat_rx_data_pdu_out_of_window,
-				&stat_rx_data_bytes_out_of_window,
-				&stat_rx_control_pdu,
-				&stat_rx_control_bytes,
-				&stat_timer_reordering_timed_out,
-				&stat_timer_poll_retransmit_timed_out,
-				&stat_timer_status_prohibit_timed_out);
-      
-      if (rlc_status == RLC_OP_STATUS_OK) {
-	len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, NB_SDU_TO_TX = %d (bytes %d)\tNB_SDU_TO_TX_DISC %d (bytes %d)\n",
-		     (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE",
-		     stat_tx_pdcp_sdu,
-		     stat_tx_pdcp_bytes,
-		     stat_tx_pdcp_sdu_discarded,
-		     stat_tx_pdcp_bytes_discarded);
-	
-	len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, NB_TX_DATA   = %d (bytes %d)\tNB_TX_CONTROL %d (bytes %d)\tNB_TX_RETX %d (bytes %d)\tNB_TX_RETX_BY_STATUS = %d (bytes %d)\n",
-		     (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE",
-		     stat_tx_data_pdu,
-		     stat_tx_data_bytes,
-		     stat_tx_control_pdu,
-		     stat_tx_control_bytes,
-		     stat_tx_retransmit_pdu,
-		     stat_tx_retransmit_bytes,
-		     stat_tx_retransmit_pdu_by_status,
-		     stat_tx_retransmit_bytes_by_status);
-		
-	
-	len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, NB_RX_DATA   = %d (bytes %d)\tNB_RX_CONTROL %d (bytes %d)\tNB_RX_DUPL %d (bytes %d)\tNB_RX_DROP = %d (bytes %d)\tNB_RX_OUT_OF_WINDOW = %d (bytes %d)\n",
-		     (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE",
-		     stat_rx_data_pdu,
-		     stat_rx_data_bytes,
-		     stat_rx_control_pdu,
-		     stat_rx_control_bytes,
-		     stat_rx_data_pdus_duplicate,
-		     stat_rx_data_bytes_duplicate,
-		     stat_rx_data_pdu_dropped,
-		     stat_rx_data_bytes_dropped,
-		     stat_rx_data_pdu_out_of_window,
-		     stat_rx_data_bytes_out_of_window);
-	
-
-	len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, RX_REODERING_TIMEOUT = %d\tRX_POLL_RET_TIMEOUT %d\tRX_PROHIBIT_TIME_OUT %d\n",
-		     (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE",
-		     stat_timer_reordering_timed_out,
-		     stat_timer_poll_retransmit_timed_out,
-		     stat_timer_status_prohibit_timed_out);
-
-	len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, NB_SDU_TO_RX = %d (bytes %d)\n",
-		     (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE",
-		     stat_rx_pdcp_sdu,
-		     stat_rx_pdcp_bytes);
-
-      }  		
+            rlc_status = rlc_stat_req(&ctxt,
+                                      SRB_FLAG_NO,
+                                      DTCH-2, // DRB_IDENTITY
+                                      &stat_rlc_mode,
+                                      &stat_tx_pdcp_sdu,
+                                      &stat_tx_pdcp_bytes,
+                                      &stat_tx_pdcp_sdu_discarded,
+                                      &stat_tx_pdcp_bytes_discarded,
+                                      &stat_tx_data_pdu,
+                                      &stat_tx_data_bytes,
+                                      &stat_tx_retransmit_pdu_by_status,
+                                      &stat_tx_retransmit_bytes_by_status,
+                                      &stat_tx_retransmit_pdu,
+                                      &stat_tx_retransmit_bytes,
+                                      &stat_tx_control_pdu,
+                                      &stat_tx_control_bytes,
+                                      &stat_rx_pdcp_sdu,
+                                      &stat_rx_pdcp_bytes,
+                                      &stat_rx_data_pdus_duplicate,
+                                      &stat_rx_data_bytes_duplicate,
+                                      &stat_rx_data_pdu,
+                                      &stat_rx_data_bytes,
+                                      &stat_rx_data_pdu_dropped,
+                                      &stat_rx_data_bytes_dropped,
+                                      &stat_rx_data_pdu_out_of_window,
+                                      &stat_rx_data_bytes_out_of_window,
+                                      &stat_rx_control_pdu,
+                                      &stat_rx_control_bytes,
+                                      &stat_timer_reordering_timed_out,
+                                      &stat_timer_poll_retransmit_timed_out,
+                                      &stat_timer_status_prohibit_timed_out);
+
+            if (rlc_status == RLC_OP_STATUS_OK) {
+                len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, NB_SDU_TO_TX = %u (bytes %u)\tNB_SDU_TO_TX_DISC %u (bytes %u)\n",
+                             (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE",
+                             stat_tx_pdcp_sdu,
+                             stat_tx_pdcp_bytes,
+                             stat_tx_pdcp_sdu_discarded,
+                             stat_tx_pdcp_bytes_discarded);
+                len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, NB_TX_DATA   = %u (bytes %u)\tNB_TX_CONTROL %u (bytes %u)\tNB_TX_RETX %u (bytes %u)\tNB_TX_RETX_BY_STATUS = %u (bytes %u)\n",
+                             (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE",
+                             stat_tx_data_pdu,
+                             stat_tx_data_bytes,
+                             stat_tx_control_pdu,
+                             stat_tx_control_bytes,
+                             stat_tx_retransmit_pdu,
+                             stat_tx_retransmit_bytes,
+                             stat_tx_retransmit_pdu_by_status,
+                             stat_tx_retransmit_bytes_by_status);
+                len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, NB_RX_DATA   = %u (bytes %u)\tNB_RX_CONTROL %u (bytes %u)\tNB_RX_DUPL %u (bytes %u)\tNB_RX_DROP = %u (bytes %u)\tNB_RX_OUT_OF_WINDOW = %u (bytes %u)\n",
+                             (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE",
+                             stat_rx_data_pdu,
+                             stat_rx_data_bytes,
+                             stat_rx_control_pdu,
+                             stat_rx_control_bytes,
+                             stat_rx_data_pdus_duplicate,
+                             stat_rx_data_bytes_duplicate,
+                             stat_rx_data_pdu_dropped,
+                             stat_rx_data_bytes_dropped,
+                             stat_rx_data_pdu_out_of_window,
+                             stat_rx_data_bytes_out_of_window);
+                len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, RX_REODERING_TIMEOUT = %u\tRX_POLL_RET_TIMEOUT %u\tRX_PROHIBIT_TIME_OUT %u\n",
+                             (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE",
+                             stat_timer_reordering_timed_out,
+                             stat_timer_poll_retransmit_timed_out,
+                             stat_timer_status_prohibit_timed_out);
+                len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, NB_SDU_TO_RX = %u (bytes %u)\n",
+                             (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE",
+                             stat_rx_pdcp_sdu,
+                             stat_rx_pdcp_bytes);
+            }
+        }
     }
-  }
-  
-  return len + 1 /* SR: for trailing \0 */;
-}
 
+    return len + 1 /* SR: for trailing \0 */;
+}
 #ifdef PROC
-int openair2_stats_read(char *buffer, char **my_buffer, off_t off, int length)
-{
-
-  int len = 0,fg,Overhead, Sign;
-  unsigned int i,j,k,kk;
-  unsigned int Mod_id = 0,CH_index;
-  unsigned int tx_pdcp_sdu;
-  unsigned int tx_pdcp_sdu_discarded;
-  unsigned int tx_retransmit_pdu_unblock;
-  unsigned int tx_retransmit_pdu_by_status;
-  unsigned int tx_retransmit_pdu;
-  unsigned int tx_data_pdu;
-  unsigned int tx_control_pdu;
-  unsigned int rx_sdu;
-  unsigned int rx_error_pdu;
-  unsigned int rx_data_pdu;
-  unsigned int rx_data_pdu_out_of_window;
-  unsigned int rx_control_pdu;
-
-  //    if (mac_xface->is_cluster_head == 0) {
-  for (k=0; k<NB_INST; k++) {
-
-
-
-    if (Mac_rlc_xface->Is_cluster_head[k] == 0) {
+int openair2_stats_read(char *buffer, char **my_buffer, off_t off, int length) {
+    int len = 0,fg,Overhead, Sign;
+    unsigned int i,j,k,kk;
+    unsigned int Mod_id = 0,CH_index;
+    unsigned int tx_pdcp_sdu;
+    unsigned int tx_pdcp_sdu_discarded;
+    unsigned int tx_retransmit_pdu_unblock;
+    unsigned int tx_retransmit_pdu_by_status;
+    unsigned int tx_retransmit_pdu;
+    unsigned int tx_data_pdu;
+    unsigned int tx_control_pdu;
+    unsigned int rx_sdu;
+    unsigned int rx_error_pdu;
+    unsigned int rx_data_pdu;
+    unsigned int rx_data_pdu_out_of_window;
+    unsigned int rx_control_pdu;
+
+    //    if (mac_xface->is_cluster_head == 0) {
+    for (k=0; k<NB_INST; k++) {
+        if (Mac_rlc_xface->Is_cluster_head[k] == 0) {
 #ifndef PHY_EMUL_ONE_MACHINE
-      Mod_id=k-NB_CH_INST;
-
-      len+=sprintf(&buffer[len],"UE TTI: %d\n",Mac_rlc_xface->frame);
-
-      for (CH_index = 0; CH_index<NB_CNX_UE; CH_index++) {
-
-
-        if (UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Active==1) {
-          len+=sprintf(&buffer[len],"CH %d: Wideband SINR %d dB---\n",
-                       CH_index,UE_mac_inst[Mod_id].Def_meas[CH_index].Wideband_sinr);
-          len+=sprintf(&buffer[len],"CH %d: Subband SINR (dB) :",
-                       CH_index);
-
-          for (fg=0; fg<NUMBER_OF_MEASUREMENT_SUBBANDS; fg++) {
-            len+=sprintf(&buffer[len],"%d ",UE_mac_inst[Mod_id].Def_meas[CH_index].Sinr_meas[0][fg]);
-          }
-
-          len+=sprintf(&buffer[len],"\n");
-
-
-          len+=sprintf(&buffer[len],"BCCH %d, NB_RX_MAC = %d (%d errors)\n",
-                       UE_mac_inst[Mod_id].Bcch_lchan[CH_index].Lchan_info.Lchan_id.Index,
-                       UE_mac_inst[Mod_id].Bcch_lchan[CH_index].Lchan_info.NB_RX,
-                       UE_mac_inst[Mod_id].Bcch_lchan[CH_index].Lchan_info.NB_RX_ERRORS);
-
-
-
-          len+=sprintf(&buffer[len],"CCCH %d, NB_RX_MAC = %d (%d errors)\n",
-                       UE_mac_inst[Mod_id].Ccch_lchan[CH_index].Lchan_info.Lchan_id.Index,
-                       UE_mac_inst[Mod_id].Ccch_lchan[CH_index].Lchan_info.NB_RX,
-                       UE_mac_inst[Mod_id].Ccch_lchan[CH_index].Lchan_info.NB_RX_ERRORS);
-
-
-          len+=sprintf(&buffer[len],"LCHAN %d (DCCH), NB_TX_MAC = %d (%d bits/TTI, %d kbits/sec), NB_RX_MAC = %d (%d errors)\n",
-                       UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.Lchan_id.Index,
-                       UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.NB_TX,
-                       UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.output_rate,
-                       (10*UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.output_rate)>>5,
-                       UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.NB_RX,
-                       UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.NB_RX_ERRORS);
-
-          for(i=1; i<NB_RAB_MAX; i++) {
-            if (UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Active==1) {
-              Overhead=UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.output_rate - Pdcp_stats_tx_rate[k][CH_index][i];
-
-              if(Overhead<0) {
-                Overhead=-Overhead;
-                Sign=-1;
-              } else {
-                Sign=1;
-              }
-
-              len+=sprintf(&buffer[len],
-                           "[PDCP]LCHAN %d: NB_TX = %d ,Tx_rate =(%d bits/TTI ,%d Kbits/s), NB_RX = %d ,Rx_rate =(%d bits/TTI ,%d Kbits/s) , LAYER2 TX OVERHEAD: %d Kbits/s\n",
-                           UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index,
-                           Pdcp_stats_tx[k][CH_index][i],
-                           Pdcp_stats_tx_rate[k][CH_index][i],
-                           (10*Pdcp_stats_tx_rate[k][CH_index][i])>>5,
-                           Pdcp_stats_rx[k][CH_index][i],
-                           Pdcp_stats_rx_rate[k][CH_index][i],
-                           (10*Pdcp_stats_rx_rate[k][CH_index][i])>>5,
-                           Sign*(10*Overhead)>>5);
-
-
-              int status =  rlc_stat_req     (k,
-                                              UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index,
-                                              &tx_pdcp_sdu,
-                                              &tx_pdcp_sdu_discarded,
-                                              &tx_retransmit_pdu_unblock,
-                                              &tx_retransmit_pdu_by_status,
-                                              &tx_retransmit_pdu,
-                                              &tx_data_pdu,
-                                              &tx_control_pdu,
-                                              &rx_sdu,
-                                              &rx_error_pdu,
-                                              &rx_data_pdu,
-                                              &rx_data_pdu_out_of_window,
-                                              &rx_control_pdu) ;
-
-              if (status == RLC_OP_STATUS_OK) {
-                len+=sprintf(&buffer[len],"RLC LCHAN %d, NB_SDU_TO_TX = %d\tNB_SDU_DISC %d\tNB_RX_SDU %d\n",
-                             UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index,
+            Mod_id=k-NB_CH_INST;
+            len+=sprintf(&buffer[len],"UE TTI: %d\n",Mac_rlc_xface->frame);
+
+            for (CH_index = 0; CH_index<NB_CNX_UE; CH_index++) {
+                if (UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Active==1) {
+                    len+=sprintf(&buffer[len],"CH %u: Wideband SINR %d dB---\n",
+                                 CH_index,UE_mac_inst[Mod_id].Def_meas[CH_index].Wideband_sinr);
+                    len+=sprintf(&buffer[len],"CH %u: Subband SINR (dB) :",
+                                 CH_index);
+
+                    for (fg=0; fg<NUMBER_OF_MEASUREMENT_SUBBANDS; fg++) {
+                        len+=sprintf(&buffer[len],"%d ",UE_mac_inst[Mod_id].Def_meas[CH_index].Sinr_meas[0][fg]);
+                    }
+
+                    len+=sprintf(&buffer[len],"\n");
+                    len+=sprintf(&buffer[len],"BCCH %d, NB_RX_MAC = %d (%d errors)\n",
+                                 UE_mac_inst[Mod_id].Bcch_lchan[CH_index].Lchan_info.Lchan_id.Index,
+                                 UE_mac_inst[Mod_id].Bcch_lchan[CH_index].Lchan_info.NB_RX,
+                                 UE_mac_inst[Mod_id].Bcch_lchan[CH_index].Lchan_info.NB_RX_ERRORS);
+                    len+=sprintf(&buffer[len],"CCCH %d, NB_RX_MAC = %d (%d errors)\n",
+                                 UE_mac_inst[Mod_id].Ccch_lchan[CH_index].Lchan_info.Lchan_id.Index,
+                                 UE_mac_inst[Mod_id].Ccch_lchan[CH_index].Lchan_info.NB_RX,
+                                 UE_mac_inst[Mod_id].Ccch_lchan[CH_index].Lchan_info.NB_RX_ERRORS);
+                    len+=sprintf(&buffer[len],"LCHAN %d (DCCH), NB_TX_MAC = %d (%d bits/TTI, %d kbits/sec), NB_RX_MAC = %d (%d errors)\n",
+                                 UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.Lchan_id.Index,
+                                 UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.NB_TX,
+                                 UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.output_rate,
+                                 (10*UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.output_rate)>>5,
+                                 UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.NB_RX,
+                                 UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.NB_RX_ERRORS);
+
+                    for(i=1; i<NB_RAB_MAX; i++) {
+                        if (UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Active==1) {
+                            Overhead=UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.output_rate - Pdcp_stats_tx_rate[k][CH_index][i];
+
+                            if(Overhead<0) {
+                                Overhead=-Overhead;
+                                Sign=-1;
+                            } else {
+                                Sign=1;
+                            }
+
+                            len+=sprintf(&buffer[len],
+                                         "[PDCP]LCHAN %d: NB_TX = %d ,Tx_rate =(%d bits/TTI ,%d Kbits/s), NB_RX = %d ,Rx_rate =(%d bits/TTI ,%d Kbits/s) , LAYER2 TX OVERHEAD: %d Kbits/s\n",
+                                         UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index,
+                                         Pdcp_stats_tx[k][CH_index][i],
+                                         Pdcp_stats_tx_rate[k][CH_index][i],
+                                         (10*Pdcp_stats_tx_rate[k][CH_index][i])>>5,
+                                         Pdcp_stats_rx[k][CH_index][i],
+                                         Pdcp_stats_rx_rate[k][CH_index][i],
+                                         (10*Pdcp_stats_rx_rate[k][CH_index][i])>>5,
+                                         Sign*(10*Overhead)>>5);
+                            int status =  rlc_stat_req     (k,
+                                                            UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index,
+                                                            &tx_pdcp_sdu,
+                                                            &tx_pdcp_sdu_discarded,
+                                                            &tx_retransmit_pdu_unblock,
+                                                            &tx_retransmit_pdu_by_status,
+                                                            &tx_retransmit_pdu,
+                                                            &tx_data_pdu,
+                                                            &tx_control_pdu,
+                                                            &rx_sdu,
+                                                            &rx_error_pdu,
+                                                            &rx_data_pdu,
+                                                            &rx_data_pdu_out_of_window,
+                                                            &rx_control_pdu) ;
+
+                            if (status == RLC_OP_STATUS_OK) {
+                                len+=sprintf(&buffer[len],"RLC LCHAN %d, NB_SDU_TO_TX = %u\tNB_SDU_DISC %u\tNB_RX_SDU %u\n",
+                                             UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index,
+                                             tx_pdcp_sdu,
+                                             tx_pdcp_sdu_discarded,
+                                             rx_sdu);
+                                len+=sprintf(&buffer[len],"RLC LCHAN %d, NB_TB_TX_DATA = %u\tNB_TB_TX_CONTROL %u\tNB_TX_TB_RETRANS %u",
+                                             UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index,
+                                             tx_data_pdu,
+                                             tx_control_pdu,
+                                             tx_retransmit_pdu);
+                                len+=sprintf(&buffer[len],"\tRLC LCHAN %d, NB_TX_TB_RETRANS_BY_STATUS = %u\tNB_TX_TB_RETRANS_PADD %u\n",
+                                             UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index,
+                                             tx_retransmit_pdu_by_status,
+                                             tx_retransmit_pdu_unblock);
+                                len+=sprintf(&buffer[len],"RLC LCHAN %d, NB_RX_DATA = %u\tNB_RX_TB_OUT_WIN %u\tNB_RX_TB_CORRUPT %u\n",
+                                             UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index,
+                                             rx_data_pdu,
+                                             rx_data_pdu_out_of_window,
+                                             rx_error_pdu);
+                            }
+
+                            len+=sprintf(&buffer[len],"[MAC]: LCHAN %d, NB_TX_MAC = %d (%d bits/TTI, %d kbits/s), NB_RX_MAC = %d (%d errors)\n",
+                                         UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index,
+                                         UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_TX,
+                                         UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.output_rate,
+                                         (10*UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.output_rate)>>5,
+                                         UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_RX,
+                                         UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_RX_ERRORS);
+                            len+=sprintf(&buffer[len],"        TX per TB: ");
+
+                            for(kk=0; kk<MAX_NUMBER_TB_PER_LCHAN/2; kk++) {
+                                len+=sprintf(&buffer[len],"%d . ",UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_TX_TB[kk]);
+                            }
+
+                            len+=sprintf(&buffer[len],"\n");
+                            len+=sprintf(&buffer[len],"        RXerr per TB: ");
+
+                            for(kk=0; kk<MAX_NUMBER_TB_PER_LCHAN/2; kk++)
+                                len+=sprintf(&buffer[len],"%d/%d . ",UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_RX_ERRORS_TB[kk],
+                                             UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_RX_TB[kk]);
+
+                            len+=sprintf(&buffer[len],"\n");
+                        }
+                    }
+                }
+            }
+
+#endif //PHY_EMUL_ONE_MACHINE
+        } else if(Mac_rlc_xface->Is_cluster_head[k] ==1) {
+            Mod_id=k;
+            len+=sprintf(&buffer[len],
+                         "-------------------------------------------------------------------CH %d: TTI: %d------------------------------------------------------------------\n",
+                         NODE_ID[Mod_id],Mac_rlc_xface->frame);
+
+            for(i=1; i<=NB_CNX_CH; i++) {
+                if (CH_mac_inst[Mod_id].Dcch_lchan[i].Active==1) {
+                    len+=sprintf(&buffer[len],"\nMR index %u: DL SINR (feedback) %d dB, CQI: %s\n\n",
+                                 i,//CH_rrc_inst[Mod_id].Info.UE_list[i].L2_id[0],
+                                 CH_mac_inst[Mod_id].Def_meas[i].Wideband_sinr,
+                                 print_cqi(CH_mac_inst[Mod_id].Def_meas[i].cqi));
+                    len+=sprintf(&buffer[len],
+                                 "[MAC] LCHAN %d (DCCH), NB_TX_MAC= %d (%d bits/TTI, %d kbits/s), NB_RX_MAC= %d (errors %d, sacch errors %d, sach errors %d, sach_missing %d)\n\n",
+                                 CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.Lchan_id.Index,
+                                 CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_TX,
+                                 CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.output_rate,
+                                 (10*CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.output_rate)>>5,
+                                 CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX,
+                                 CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX_ERRORS,
+                                 CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX_SACCH_ERRORS,
+                                 CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX_SACH_ERRORS,
+                                 CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX_SACH_MISSING);
+
+                    for(j=0; j<NB_RAB_MAX; j++) {
+                        if (CH_mac_inst[Mod_id].Dtch_lchan[j][i].Active==1) {
+                            Overhead=CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.output_rate - Pdcp_stats_tx_rate[k][i][j];
+
+                            if(Overhead<0) {
+                                Overhead=-Overhead;
+                                Sign=-1;
+                            } else {
+                                Sign=1;
+                            }
+
+                            len+=sprintf(&buffer[len],
+                                         "[PDCP]LCHAN %d: NB_TX = %d ,Tx_rate =(%d bits/TTI ,%d Kbits/s), NB_RX = %d ,Rx_rate =(%d bits/TTI ,%d Kbits/s), LAYER2 TX OVERHEAD= %d Kbits/s\n",
+                                         CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index,
+                                         Pdcp_stats_tx[k][i][j],
+                                         Pdcp_stats_tx_rate[k][i][j],
+                                         (10*Pdcp_stats_tx_rate[k][i][j])>>5,
+                                         Pdcp_stats_rx[k][i][j],
+                                         Pdcp_stats_rx_rate[k][i][j],
+                                         (10*Pdcp_stats_rx_rate[k][i][j])>>5,
+                                         Sign*(10*Overhead)>>5);
+                            int status =  rlc_stat_req     (k,
+                                                            CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index,
+                                                            &tx_pdcp_sdu,
+                                                            &tx_pdcp_sdu_discarded,
+                                                            &tx_retransmit_pdu_unblock,
+                                                            &tx_retransmit_pdu_by_status,
+                                                            &tx_retransmit_pdu,
+                                                            &tx_data_pdu,
+                                                            &tx_control_pdu,
+                                                            &rx_sdu,
+                                                            &rx_error_pdu,
+                                                            &rx_data_pdu,
+                                                            &rx_data_pdu_out_of_window,
+                                                            &rx_control_pdu) ;
+                            /*
+                            if (status == RLC_OP_STATUS_OK) {
+                            len+=sprintf(&buffer[len],"\t[RLC] LCHAN %d, NB_SDU_TO_TX = %d\tNB_SDU_DISC %d\tNB_RX_SDU %d\n",
+                                CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index,
                              tx_pdcp_sdu,
                              tx_pdcp_sdu_discarded,
                              rx_sdu);
-                len+=sprintf(&buffer[len],"RLC LCHAN %d, NB_TB_TX_DATA = %d\tNB_TB_TX_CONTROL %d\tNB_TX_TB_RETRANS %d",
-                             UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index,
+                            len+=sprintf(&buffer[len],"\t[RLC] LCHAN %d, NB_TB_TX_DATA = %d\tNB_TB_TX_CONTROL %d\tNB_TX_TB_RETRANS %\n",
+                                CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index,
                              tx_data_pdu,
                              tx_control_pdu,
                              tx_retransmit_pdu);
-                len+=sprintf(&buffer[len],"\tRLC LCHAN %d, NB_TX_TB_RETRANS_BY_STATUS = %d\tNB_TX_TB_RETRANS_PADD %d\n",
-                             UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index,
+                            len+=sprintf(&buffer[len],"\t[RLC] LCHAN %d, NB_TX_TB_RETRANS_BY_STATUS = %d\tNB_TX_TB_RETRANS_PADD %d\n",
+                                CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index,
                              tx_retransmit_pdu_by_status,
                              tx_retransmit_pdu_unblock);
-                len+=sprintf(&buffer[len],"RLC LCHAN %d, NB_RX_DATA = %d\tNB_RX_TB_OUT_WIN %d\tNB_RX_TB_CORRUPT %d\n",
-                             UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index,
+                            len+=sprintf(&buffer[len],"\t[RLC] LCHAN %d, NB_RX_DATA = %d\tNB_RX_TB_OUT_WIN %d\tNB_RX_TB_CORRUPT %d\n",
+                                CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index,
                              rx_data_pdu,
                              rx_data_pdu_out_of_window,
                              rx_error_pdu);
-              }
-
-              len+=sprintf(&buffer[len],"[MAC]: LCHAN %d, NB_TX_MAC = %d (%d bits/TTI, %d kbits/s), NB_RX_MAC = %d (%d errors)\n",
-                           UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index,
-                           UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_TX,
-                           UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.output_rate,
-                           (10*UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.output_rate)>>5,
-                           UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_RX,
-                           UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_RX_ERRORS);
-              len+=sprintf(&buffer[len],"        TX per TB: ");
-
-              for(kk=0; kk<MAX_NUMBER_TB_PER_LCHAN/2; kk++) {
-                len+=sprintf(&buffer[len],"%d . ",UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_TX_TB[kk]);
-              }
-
-              len+=sprintf(&buffer[len],"\n");
-              len+=sprintf(&buffer[len],"        RXerr per TB: ");
-
-              for(kk=0; kk<MAX_NUMBER_TB_PER_LCHAN/2; kk++)
-                len+=sprintf(&buffer[len],"%d/%d . ",UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_RX_ERRORS_TB[kk],
-                             UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_RX_TB[kk]);
-
-              len+=sprintf(&buffer[len],"\n");
-
-
-
+                            }
+                            */
+                            len+=sprintf(&buffer[len],
+                                         "[MAC]LCHAN %d (CNX %u,RAB %u), NB_TX_MAC= %d (%d bits/TTI, %d kbit/s), NB_RX_MAC= %d (errors %d, sacch_errors %d, sach_errors %d, sach_missing %d)\n",
+                                         CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index,
+                                         i,j,
+                                         CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_TX,
+                                         CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.output_rate,
+                                         (10*CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.output_rate)>>5,
+                                         CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX,
+                                         CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_ERRORS,
+                                         CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_SACCH_ERRORS,
+                                         CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_SACH_ERRORS,
+                                         CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_SACH_MISSING);
+                            len+=sprintf(&buffer[len],"[MAC][SCHEDULER] TX Arrival Rate %d, TX Service Rate %d, RX Arrival rate %d, RX Service rate %d, NB_BW_REQ_RX %d\n\n",
+                                         CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Arrival_rate,
+                                         CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Tx_rate,
+                                         CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Req_rate,
+                                         CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Rx_rate,
+                                         CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_BW_REQ_RX);
+                            /*
+                                    len+=sprintf(&buffer[len],"        TX per TB: ");
+                                    for(kk=0;kk<MAX_NUMBER_TB_PER_LCHAN/2;kk++)
+                                len+=sprintf(&buffer[len],"%d.",CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_TX_TB[kk]);
+                                    len+=sprintf(&buffer[len],"\n");
+                                    len+=sprintf(&buffer[len],"        RXerr per TB: ");
+                                    for(kk=0;kk<MAX_NUMBER_TB_PER_LCHAN/2;kk++)
+                                len+=sprintf(&buffer[len],"%d/%d . ",CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_ERRORS_TB[kk],
+                                       CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_TB[kk]);
+                                    len+=sprintf(&buffer[len],"\n");
+                            */
+                        }
+                    }
+                }
             }
-
-          }
         }
-      }
-
-#endif //PHY_EMUL_ONE_MACHINE
-    } else if(Mac_rlc_xface->Is_cluster_head[k] ==1) {
-
-      Mod_id=k;
-      len+=sprintf(&buffer[len],
-                   "-------------------------------------------------------------------CH %d: TTI: %d------------------------------------------------------------------\n",
-                   NODE_ID[Mod_id],Mac_rlc_xface->frame);
-
-      for(i=1; i<=NB_CNX_CH; i++) {
-        if (CH_mac_inst[Mod_id].Dcch_lchan[i].Active==1) {
-          len+=sprintf(&buffer[len],"\nMR index %d: DL SINR (feedback) %d dB, CQI: %s\n\n",
-                       i,//CH_rrc_inst[Mod_id].Info.UE_list[i].L2_id[0],
-                       CH_mac_inst[Mod_id].Def_meas[i].Wideband_sinr,
-                       print_cqi(CH_mac_inst[Mod_id].Def_meas[i].cqi));
-
-          len+=sprintf(&buffer[len],
-                       "[MAC] LCHAN %d (DCCH), NB_TX_MAC= %d (%d bits/TTI, %d kbits/s), NB_RX_MAC= %d (errors %d, sacch errors %d, sach errors %d, sach_missing %d)\n\n",
-                       CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.Lchan_id.Index,
-                       CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_TX,
-                       CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.output_rate,
-                       (10*CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.output_rate)>>5,
-                       CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX,
-                       CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX_ERRORS,
-                       CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX_SACCH_ERRORS,
-                       CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX_SACH_ERRORS,
-                       CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX_SACH_MISSING);
-
-          for(j=0; j<NB_RAB_MAX; j++) {
-            if (CH_mac_inst[Mod_id].Dtch_lchan[j][i].Active==1) {
-              Overhead=CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.output_rate - Pdcp_stats_tx_rate[k][i][j];
-
-              if(Overhead<0) {
-                Overhead=-Overhead;
-                Sign=-1;
-              } else {
-                Sign=1;
-              }
-
-              len+=sprintf(&buffer[len],
-                           "[PDCP]LCHAN %d: NB_TX = %d ,Tx_rate =(%d bits/TTI ,%d Kbits/s), NB_RX = %d ,Rx_rate =(%d bits/TTI ,%d Kbits/s), LAYER2 TX OVERHEAD= %d Kbits/s\n",
-                           CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index,
-                           Pdcp_stats_tx[k][i][j],
-                           Pdcp_stats_tx_rate[k][i][j],
-                           (10*Pdcp_stats_tx_rate[k][i][j])>>5,
-                           Pdcp_stats_rx[k][i][j],
-                           Pdcp_stats_rx_rate[k][i][j],
-                           (10*Pdcp_stats_rx_rate[k][i][j])>>5,
-                           Sign*(10*Overhead)>>5);
-              int status =  rlc_stat_req     (k,
-                                              CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index,
-                                              &tx_pdcp_sdu,
-                                              &tx_pdcp_sdu_discarded,
-                                              &tx_retransmit_pdu_unblock,
-                                              &tx_retransmit_pdu_by_status,
-                                              &tx_retransmit_pdu,
-                                              &tx_data_pdu,
-                                              &tx_control_pdu,
-                                              &rx_sdu,
-                                              &rx_error_pdu,
-                                              &rx_data_pdu,
-                                              &rx_data_pdu_out_of_window,
-                                              &rx_control_pdu) ;
-              /*
-              if (status == RLC_OP_STATUS_OK) {
-              len+=sprintf(&buffer[len],"\t[RLC] LCHAN %d, NB_SDU_TO_TX = %d\tNB_SDU_DISC %d\tNB_RX_SDU %d\n",
-                  CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index,
-               tx_pdcp_sdu,
-               tx_pdcp_sdu_discarded,
-               rx_sdu);
-              len+=sprintf(&buffer[len],"\t[RLC] LCHAN %d, NB_TB_TX_DATA = %d\tNB_TB_TX_CONTROL %d\tNB_TX_TB_RETRANS %\n",
-                  CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index,
-               tx_data_pdu,
-               tx_control_pdu,
-               tx_retransmit_pdu);
-              len+=sprintf(&buffer[len],"\t[RLC] LCHAN %d, NB_TX_TB_RETRANS_BY_STATUS = %d\tNB_TX_TB_RETRANS_PADD %d\n",
-                  CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index,
-               tx_retransmit_pdu_by_status,
-               tx_retransmit_pdu_unblock);
-              len+=sprintf(&buffer[len],"\t[RLC] LCHAN %d, NB_RX_DATA = %d\tNB_RX_TB_OUT_WIN %d\tNB_RX_TB_CORRUPT %d\n",
-                  CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index,
-               rx_data_pdu,
-               rx_data_pdu_out_of_window,
-               rx_error_pdu);
-              }
-              */
-              len+=sprintf(&buffer[len],
-                           "[MAC]LCHAN %d (CNX %d,RAB %d), NB_TX_MAC= %d (%d bits/TTI, %d kbit/s), NB_RX_MAC= %d (errors %d, sacch_errors %d, sach_errors %d, sach_missing %d)\n",
-                           CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index,
-                           i,j,
-                           CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_TX,
-                           CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.output_rate,
-                           (10*CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.output_rate)>>5,
-                           CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX,
-                           CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_ERRORS,
-                           CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_SACCH_ERRORS,
-                           CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_SACH_ERRORS,
-                           CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_SACH_MISSING);
-              len+=sprintf(&buffer[len],"[MAC][SCHEDULER] TX Arrival Rate %d, TX Service Rate %d, RX Arrival rate %d, RX Service rate %d, NB_BW_REQ_RX %d\n\n",
-                           CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Arrival_rate,
-                           CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Tx_rate,
-                           CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Req_rate,
-                           CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Rx_rate,
-                           CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_BW_REQ_RX);
-
-              /*
-                      len+=sprintf(&buffer[len],"        TX per TB: ");
-                      for(kk=0;kk<MAX_NUMBER_TB_PER_LCHAN/2;kk++)
-                  len+=sprintf(&buffer[len],"%d.",CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_TX_TB[kk]);
-                      len+=sprintf(&buffer[len],"\n");
-                      len+=sprintf(&buffer[len],"        RXerr per TB: ");
-                      for(kk=0;kk<MAX_NUMBER_TB_PER_LCHAN/2;kk++)
-                  len+=sprintf(&buffer[len],"%d/%d . ",CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_ERRORS_TB[kk],
-                         CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_TB[kk]);
-                      len+=sprintf(&buffer[len],"\n");
-              */
-            }
-          }
-        }
-      }
-
     }
-  }
 
-  return len;
+    return len;
 }
 
 #endif
diff --git a/openair2/LAYER2/register.h b/openair2/LAYER2/register.h
deleted file mode 100644
index 8a4aeb5b12336011cbc80aff0a6f547a411b49c4..0000000000000000000000000000000000000000
--- a/openair2/LAYER2/register.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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
- */
-
-/*________________________rrc_register.h________________________
-
- Authors : Hicham Anouar, Raymond Knopp
- Company : EURECOM
- Emails  : anouar@eurecom.fr,  knopp@eurecom.fr
-________________________________________________________________*/
-
-#ifndef __MAC_RRC_REGISTER_H__
-#    define __MAC_RRC_REGISTER_H__
-#include "COMMON/mac_rrc_primitives.h"
-/** @defgroup _mac_impl_register RRC Registration interface
- * @ingroup _mac_impl_
- *@{
- */
-MAC_RLC_XFACE* mac_rrc_register(RRC_XFACE* RRC_xface);
-int mac_rrc_unregister(RRC_XFACE *RRC_xface);
-#endif
diff --git a/openair2/NETWORK_DRIVER/LITE/RB_TOOL/Makefile b/openair2/NETWORK_DRIVER/LITE/RB_TOOL/Makefile
old mode 100755
new mode 100644
diff --git a/openair2/NETWORK_DRIVER/LITE/RB_TOOL/rb_tool.c b/openair2/NETWORK_DRIVER/LITE/RB_TOOL/rb_tool.c
index e918f209e37f3dab584a81a3bdcbd6f67f077550..465e134d768ee0ca4dc5f6cb09a4cb5f3e22ea51 100644
--- a/openair2/NETWORK_DRIVER/LITE/RB_TOOL/rb_tool.c
+++ b/openair2/NETWORK_DRIVER/LITE/RB_TOOL/rb_tool.c
@@ -46,22 +46,22 @@
 
 
 #define NIPADDR(addr) \
-        (uint8_t)(addr & 0x000000FF), \
-        (uint8_t)((addr & 0x0000FF00) >> 8), \
-        (uint8_t)((addr & 0x00FF0000) >> 16), \
-        (uint8_t)((addr & 0xFF000000) >> 24)
+  (uint8_t)(addr & 0x000000FF), \
+  (uint8_t)((addr & 0x0000FF00) >> 8), \
+  (uint8_t)((addr & 0x00FF0000) >> 16), \
+  (uint8_t)((addr & 0xFF000000) >> 24)
 
 
 
 #define NIP6ADDR(addr) \
-        ntohs((addr)->s6_addr16[0]), \
-        ntohs((addr)->s6_addr16[1]), \
-        ntohs((addr)->s6_addr16[2]), \
-        ntohs((addr)->s6_addr16[3]), \
-        ntohs((addr)->s6_addr16[4]), \
-        ntohs((addr)->s6_addr16[5]), \
-        ntohs((addr)->s6_addr16[6]), \
-        ntohs((addr)->s6_addr16[7])
+  ntohs((addr)->s6_addr16[0]), \
+  ntohs((addr)->s6_addr16[1]), \
+  ntohs((addr)->s6_addr16[2]), \
+  ntohs((addr)->s6_addr16[3]), \
+  ntohs((addr)->s6_addr16[4]), \
+  ntohs((addr)->s6_addr16[5]), \
+  ntohs((addr)->s6_addr16[6]), \
+  ntohs((addr)->s6_addr16[7])
 
 
 // Global variables
@@ -76,12 +76,9 @@ struct oai_nw_drv_ioctl gifr;
 void IAL_NAS_ioctl_init(int inst)
 //---------------------------------------------------------------------------
 {
-
   struct oai_nw_drv_msg_statistic_reply *msgrep;
   int err,rc;
-
   sprintf(gifr.name, "oai%d",inst);
-
   // Get an UDP IPv6 socket ??
   fd=socket(AF_INET6, SOCK_DGRAM, 0);
 
@@ -91,7 +88,6 @@ void IAL_NAS_ioctl_init(int inst)
   }
 
   sprintf(gifr.name, "oai%d",inst);
-
   gifr.type =  OAI_NW_DRV_MSG_STATISTIC_REQUEST;
   memset ((void *)dummy_buffer,0,800);
   gifr.msg= &(dummy_buffer[0]);
@@ -160,7 +156,6 @@ int main(int argc,char **argv)
   char                                     addr_str[46];
   char                                     mask_len_delims[] = "/";
   char                                     *result;
-
   // scan options
   rb[0] = '\0';
   cx[0] = '\0';
@@ -171,155 +166,154 @@ int main(int argc,char **argv)
 
   while ((c = getopt (argc, argv, "adr:i:c:f:l:m:s:t:x:y:z:")) != -1)
     switch (c) {
-    case 'a':
-      action = ADD_RB;
-      break;
-
-    case 'd':
-      action = DEL_RB;
-      break;
-
-    case 'r':
-      strcpy(rb,optarg);
-      rbset = 1;
-      break;
-
-    case 'i':
-      strcpy(inst,optarg);
-      instset = 1;
-      break;
-
-    case 'c':
-      strcpy(cx,optarg);
-      cxset = 1;
-      break;
-
-    case 'f':
-      strcpy(classref,optarg);
-      classrefset = 1;
-      break;
-
-    case 'l':
-      strcpy(mpls_outgoinglabel,optarg);
-      mpls_outlabelset=1;
-      break;
-
-    case 'm':
-      strcpy(mpls_incominglabel,optarg);
-      mpls_inlabelset=1;
-      break;
-
-    case 's':
-      result = strtok( optarg, mask_len_delims );
-
-      if ( result != NULL ) {
-        inet_aton(result,&saddr_ipv4);
-        printf("Arg Source Addr IPv4 string: %s\n",result);
-        saddr_ipv4set = 1;
-      } else {
-        printf("Arg Source Addr IPv4 string: ERROR\n");
+      case 'a':
+        action = ADD_RB;
         break;
-      }
 
-      result = strtok( NULL, mask_len_delims );
+      case 'd':
+        action = DEL_RB;
+        break;
 
-      if ( result != NULL ) {
-        splen = atoi(result);
-      } else {
-        splen = 32;
-      }
+      case 'r':
+        strcpy(rb,optarg);
+        rbset = 1;
+        break;
 
-      printf("Arg Source Addr IPv4 mask len: %d\n",splen);
-      break;
+      case 'i':
+        strcpy(inst,optarg);
+        instset = 1;
+        break;
 
-    case 't':
-      result = strtok( optarg, mask_len_delims );
+      case 'c':
+        strcpy(cx,optarg);
+        cxset = 1;
+        break;
 
-      if ( result != NULL ) {
-        inet_aton(result,&daddr_ipv4);
-        printf("Arg Dest Addr IPv4 string: %s\n",result);
-        daddr_ipv4set = 1;
-      } else {
-        printf("Arg Dest Addr IPv4 string: ERROR\n");
+      case 'f':
+        strcpy(classref,optarg);
+        classrefset = 1;
+        break;
+
+      case 'l':
+        strcpy(mpls_outgoinglabel,optarg);
+        mpls_outlabelset=1;
         break;
-      }
 
-      result = strtok( NULL, mask_len_delims );
+      case 'm':
+        strcpy(mpls_incominglabel,optarg);
+        mpls_inlabelset=1;
+        break;
 
-      if ( result != NULL ) {
-        dplen = atoi(result);
-      } else {
-        dplen = 32;
-      }
+      case 's':
+        result = strtok( optarg, mask_len_delims );
 
-      printf("Arg Dest Addr IPv4 mask len: %d\n",dplen);
-      break;
+        if ( result != NULL ) {
+          inet_aton(result,&saddr_ipv4);
+          printf("Arg Source Addr IPv4 string: %s\n",result);
+          saddr_ipv4set = 1;
+        } else {
+          printf("Arg Source Addr IPv4 string: ERROR\n");
+          break;
+        }
 
-    case 'x':
-      result = strtok( optarg, mask_len_delims );
+        result = strtok( NULL, mask_len_delims );
 
-      if ( result != NULL ) {
-        printf("Arg Source Addr IPv6 string: %s\n",result);
-        inet_pton(AF_INET6,result,(void *)&saddr_ipv6);
-        saddr_ipv6set = 1;
-      } else {
-        printf("Arg Source Addr IPv6 string: ERROR\n");
+        if ( result != NULL ) {
+          splen = atoi(result);
+        } else {
+          splen = 32;
+        }
+
+        printf("Arg Source Addr IPv4 mask len: %d\n",splen);
         break;
-      }
 
-      result = strtok( NULL, mask_len_delims );
+      case 't':
+        result = strtok( optarg, mask_len_delims );
 
-      if ( result != NULL ) {
-        splen = atoi(result);
-      } else {
-        splen = 128;
-      }
+        if ( result != NULL ) {
+          inet_aton(result,&daddr_ipv4);
+          printf("Arg Dest Addr IPv4 string: %s\n",result);
+          daddr_ipv4set = 1;
+        } else {
+          printf("Arg Dest Addr IPv4 string: ERROR\n");
+          break;
+        }
 
-      printf("Arg Source Addr IPv6 mask len: %d\n",splen);
-      break;
+        result = strtok( NULL, mask_len_delims );
 
-    case 'y':
-      result = strtok( optarg, mask_len_delims );
+        if ( result != NULL ) {
+          dplen = atoi(result);
+        } else {
+          dplen = 32;
+        }
 
-      if ( result != NULL ) {
-        printf("Arg Dest Addr IPv6 string: %s\n",result);
-        inet_pton(AF_INET6,result,(void *)&daddr_ipv6);
-        daddr_ipv6set = 1;
-      } else {
-        printf("Arg Dest Addr IPv6 string: ERROR\n");
+        printf("Arg Dest Addr IPv4 mask len: %d\n",dplen);
         break;
-      }
 
-      result = strtok( NULL, mask_len_delims );
+      case 'x':
+        result = strtok( optarg, mask_len_delims );
 
-      if ( result != NULL ) {
-        dplen = atoi(result);
-      } else {
-        dplen = 128;
-      }
+        if ( result != NULL ) {
+          printf("Arg Source Addr IPv6 string: %s\n",result);
+          inet_pton(AF_INET6,result,(void *)&saddr_ipv6);
+          saddr_ipv6set = 1;
+        } else {
+          printf("Arg Source Addr IPv6 string: ERROR\n");
+          break;
+        }
 
-      printf("Arg Dest Addr IPv6 mask len: %d\n",dplen);
-      break;
+        result = strtok( NULL, mask_len_delims );
 
-    case 'z':
-      dscpset=1;
-      strcpy(dscp,optarg);
-      break;
+        if ( result != NULL ) {
+          splen = atoi(result);
+        } else {
+          splen = 128;
+        }
 
-    case '?':
-      if (isprint (optopt))
-        fprintf (stderr, "Unknown option `-%c'.\n", optopt);
-      else
-        fprintf (stderr,
-                 "Unknown option character `\\x%x'.\n",
-                 optopt);
+        printf("Arg Source Addr IPv6 mask len: %d\n",splen);
+        break;
 
-      return 1;
+      case 'y':
+        result = strtok( optarg, mask_len_delims );
 
-    default:
-      abort ();
-    }
+        if ( result != NULL ) {
+          printf("Arg Dest Addr IPv6 string: %s\n",result);
+          inet_pton(AF_INET6,result,(void *)&daddr_ipv6);
+          daddr_ipv6set = 1;
+        } else {
+          printf("Arg Dest Addr IPv6 string: ERROR\n");
+          break;
+        }
 
+        result = strtok( NULL, mask_len_delims );
+
+        if ( result != NULL ) {
+          dplen = atoi(result);
+        } else {
+          dplen = 128;
+        }
+
+        printf("Arg Dest Addr IPv6 mask len: %d\n",dplen);
+        break;
+
+      case 'z':
+        dscpset=1;
+        strcpy(dscp,optarg);
+        break;
+
+      case '?':
+        if (isprint (optopt))
+          fprintf (stderr, "Unknown option `-%c'.\n", optopt);
+        else
+          fprintf (stderr,
+                   "Unknown option character `\\x%x'.\n",
+                   optopt);
+
+        return 1;
+
+      default:
+        abort ();
+    }
 
   printf ("action = %d, rb = %s,cx = %s\n", action, rb, cx);
 
@@ -364,13 +358,11 @@ int main(int argc,char **argv)
   }
 
   IAL_NAS_ioctl_init(atoi(inst));
-
   msgreq = (struct oai_nw_drv_msg_rb_establishment_request *)(gifr.msg);
   msgreq->rab_id = atoi(rb);
   msgreq->lcr = atoi(cx);
   msgreq->qos = 0;
 
-
   if (action == ADD_RB) {
     gifr.type =  OAI_NW_DRV_MSG_RB_ESTABLISHMENT_REQUEST;
     printf("OAI_NW_DRV_MSG_RB_ESTABLISHMENT_REQUEST: RB %d LCR %d QOS %d\n ", msgreq->rab_id, msgreq->lcr, msgreq->qos);
@@ -405,8 +397,6 @@ int main(int argc,char **argv)
       printf(" IPV4: Dest    = %d.%d.%d.%d/%d\n", NIPADDR(msgreq_class->daddr.ipv4), msgreq_class->dplen);
       gifr.type                = OAI_NW_DRV_MSG_CLASS_ADD_REQUEST;
       err=ioctl(fd, OAI_NW_DRV_IOCTL_RRM, &gifr);
-
-
       msgreq_class->rab_id     = atoi(rb);
       msgreq_class->lcr        = atoi(cx);
       msgreq_class->version    = 4;
@@ -420,7 +410,6 @@ int main(int argc,char **argv)
       printf("OAI_NW_DRV_MSG_CLASS_ADD_REQUEST: OAI_NW_DRV_DIRECTION_RECEIVE RB %d LCR %d ClassRef %d ", msgreq_class->rab_id, msgreq_class->lcr, msgreq_class->classref);
       printf("IPV4: Source  = %d.%d.%d.%d/%d ", NIPADDR(msgreq_class->saddr.ipv4), msgreq_class->splen);
       printf("IPV4: Dest    = %d.%d.%d.%d/%d\n", NIPADDR(msgreq_class->daddr.ipv4), msgreq_class->dplen);
-
       gifr.type =  OAI_NW_DRV_MSG_CLASS_ADD_REQUEST;
       err=ioctl(fd, OAI_NW_DRV_IOCTL_RRM, &gifr);
     }
@@ -443,7 +432,6 @@ int main(int argc,char **argv)
       msgreq_class->fct        = OAI_NW_DRV_FCT_QOS_SEND;
       // TO BE FIXED WHEN WE CAN SPECIFY A PROTOCOL-based rule
       msgreq_class->protocol   = OAI_NW_DRV_PROTOCOL_DEFAULT;
-
       memcpy(&msgreq_class->saddr.ipv6,&saddr_ipv6,16);
       memcpy(&msgreq_class->daddr.ipv6,&daddr_ipv6,16);
       printf("OAI_NW_DRV_MSG_CLASS_ADD_REQUEST: OAI_NW_DRV_DIRECTION_SEND RB %d LCR %d ClassRef %d ", msgreq_class->rab_id, msgreq_class->lcr, msgreq_class->classref);
@@ -451,7 +439,6 @@ int main(int argc,char **argv)
       printf("IPV6: Dest    = %x:%x:%x:%x:%x:%x:%x:%x/%d\n", NIP6ADDR(&msgreq_class->daddr.ipv6), msgreq_class->dplen);
       gifr.type =  OAI_NW_DRV_MSG_CLASS_ADD_REQUEST;
       err=ioctl(fd, OAI_NW_DRV_IOCTL_RRM, &gifr);
-
       msgreq_class->rab_id     = atoi(rb);
       msgreq_class->lcr        = atoi(cx);
       msgreq_class->dplen      = splen;
@@ -468,7 +455,6 @@ int main(int argc,char **argv)
     }
 
     if (mpls_inlabelset == 1) {
-
       msgreq_class = (struct oai_nw_drv_msg_class_add_request *)(gifr.msg);
       msgreq_class->rab_id = atoi(rb);
       msgreq_class->lcr = atoi(cx);
@@ -483,40 +469,26 @@ int main(int argc,char **argv)
       //msgreq_class->classref = 4 + (msgreq_class->lcr<<3);
       msgreq_class->dir=OAI_NW_DRV_DIRECTION_SEND;
       msgreq_class->fct=OAI_NW_DRV_FCT_QOS_SEND;
-
       // TO BE FIXED WHEN WE CAN SPECIFY A PROTOCOL-based rule
       msgreq_class->protocol = OAI_NW_DRV_PROTOCOL_DEFAULT;
-
       mpls_outlabel = atoi(mpls_outgoinglabel);
-
-      printf("Setting MPLS outlabel %d with exp %d\n",mpls_outlabel,msgreq_class->dscp);
-
+      printf("Setting MPLS outlabel %u with exp %d\n",mpls_outlabel,msgreq_class->dscp);
       msgreq_class->daddr.mpls_label = mpls_outlabel;
-
       gifr.type =  OAI_NW_DRV_MSG_CLASS_ADD_REQUEST;
       err=ioctl(fd, OAI_NW_DRV_IOCTL_RRM, &gifr);
-
       msgreq_class->rab_id = atoi(rb);
       msgreq_class->lcr = atoi(cx);
-
       msgreq_class->classref = atoi(classref) + 1 + (msgreq_class->lcr<<8);
       //msgreq_class->classref = 5 + (msgreq_class->lcr<<3);
       msgreq_class->dir=OAI_NW_DRV_DIRECTION_RECEIVE;
-
-
       // TO BE FIXED WHEN WE CAN SPECIFY A PROTOCOL-based rule
       msgreq_class->protocol = OAI_NW_DRV_PROTOCOL_DEFAULT;
-
       mpls_inlabel  = atoi(mpls_incominglabel);
-
-      printf("Setting MPLS inlabel %d with exp %d\n",mpls_inlabel,msgreq_class->dscp);
-
+      printf("Setting MPLS inlabel %u with exp %d\n",mpls_inlabel,msgreq_class->dscp);
       msgreq_class->daddr.mpls_label = mpls_inlabel;
-
       gifr.type =  OAI_NW_DRV_MSG_CLASS_ADD_REQUEST;
       err=ioctl(fd, OAI_NW_DRV_IOCTL_RRM, &gifr);
     }
-
   } else if (action == DEL_RB) {
     gifr.type =  OAI_NW_DRV_MSG_RB_RELEASE_REQUEST;
     err=ioctl(fd, OAI_NW_DRV_IOCTL_RRM, &gifr);
diff --git a/openair2/NETWORK_DRIVER/MESH/RB_TOOL/rb_tool.c b/openair2/NETWORK_DRIVER/MESH/RB_TOOL/rb_tool.c
index 8e231895d97a0961da97e9f060c673a5cbe80e39..e02bf896c30399dba28555056dd917fd3fb063dd 100644
--- a/openair2/NETWORK_DRIVER/MESH/RB_TOOL/rb_tool.c
+++ b/openair2/NETWORK_DRIVER/MESH/RB_TOOL/rb_tool.c
@@ -108,12 +108,9 @@ int NAS_RALconnect(void)
 void IAL_NAS_ioctl_init(int inst)
 //---------------------------------------------------------------------------
 {
-
   struct nas_msg_statistic_reply *msgrep;
   int err;
-
   sprintf(gifr.name, "oai%d",inst);
-
   // Get an UDP IPv6 socket ??
   fd=socket(AF_INET6, SOCK_DGRAM, 0);
 
@@ -123,7 +120,6 @@ void IAL_NAS_ioctl_init(int inst)
   }
 
   sprintf(gifr.name, "oai%d",inst);
-
   gifr.type =  NAS_MSG_STATISTIC_REQUEST;
   memset ((void *)dummy_buffer,0,800);
   gifr.msg= &(dummy_buffer[0]);
@@ -139,8 +135,6 @@ void IAL_NAS_ioctl_init(int inst)
   printf("tx_bytes = %u, rx_bytes = %u\n", msgrep->tx_bytes, msgrep->rx_bytes);
   printf("tx_errors = %u, rx_errors = %u\n", msgrep->tx_errors, msgrep->rx_errors);
   printf("tx_dropped = %u, rx_dropped = %u\n", msgrep->tx_dropped, msgrep->rx_dropped);
-
-
 }
 
 
@@ -160,11 +154,7 @@ int main(int argc,char **argv)
   in_addr_t saddr_ipv4 = 0,daddr_ipv4 = 0;
   struct in6_addr saddr_ipv6,daddr_ipv6;
   unsigned int mpls_outlabel=0,mpls_inlabel=0;
-
   char addr_str[46];
-
-
-
   // scan options
   rb[0] = '\0';
   cx[0] = '\0';
@@ -174,89 +164,87 @@ int main(int argc,char **argv)
 
   while ((c = getopt (argc, argv, "adr:i:c:l:m:s:t:x:y:z:")) != -1)
     switch (c) {
-    case 'a':
-      action = ADD_RB;
-      break;
-
-    case 'd':
-      action = DEL_RB;
-      break;
-
-    case 'r':
-      strcpy(rb,optarg);
-      rbset = 1;
-      break;
-
-    case 'i':
-      strcpy(inst,optarg);
-      instset = 1;
-      break;
-
-    case 'c':
-      strcpy(cx,optarg);
-      cxset = 1;
-      break;
-
-    case 'l':
-      strcpy(mpls_outgoinglabel,optarg);
-      mpls_outlabelset=1;
-      break;
-
-    case 'm':
-      strcpy(mpls_incominglabel,optarg);
-      mpls_inlabelset=1;
-      break;
-
-    case 's': {
-      struct in_addr a;
-      inet_aton(optarg,&a);
-      saddr_ipv4 = a.s_addr;
-      saddr_ipv4set = 1;
-      break;
-    }
-
-    case 't': {
-      struct in_addr a;
-      inet_aton(optarg,&a);
-      daddr_ipv4 = a.s_addr;
-      daddr_ipv4set = 1;
-      break;
-    }
-
-    case 'x':
-      printf("IPv6: %s\n",optarg);
-      inet_pton(AF_INET6,optarg,(void *)&saddr_ipv6);
-      saddr_ipv6set = 1;
-      break;
-
-    case 'y':
-      inet_pton(AF_INET6,optarg,(void *)&daddr_ipv6);
-      daddr_ipv6set = 1;
-      break;
-
-    case 'z':
-      dscpset=1;
-      strcpy(dscp,optarg);
-      break;
-
-    case '?':
-      if (isprint (optopt))
-        fprintf (stderr, "Unknown option `-%c'.\n", optopt);
-      else
-        fprintf (stderr,
-                 "Unknown option character `\\x%x'.\n",
-                 optopt);
-
-      return 1;
-
-    default:
-      abort ();
+      case 'a':
+        action = ADD_RB;
+        break;
+
+      case 'd':
+        action = DEL_RB;
+        break;
+
+      case 'r':
+        strcpy(rb,optarg);
+        rbset = 1;
+        break;
+
+      case 'i':
+        strcpy(inst,optarg);
+        instset = 1;
+        break;
+
+      case 'c':
+        strcpy(cx,optarg);
+        cxset = 1;
+        break;
+
+      case 'l':
+        strcpy(mpls_outgoinglabel,optarg);
+        mpls_outlabelset=1;
+        break;
+
+      case 'm':
+        strcpy(mpls_incominglabel,optarg);
+        mpls_inlabelset=1;
+        break;
+
+      case 's': {
+        struct in_addr a;
+        inet_aton(optarg,&a);
+        saddr_ipv4 = a.s_addr;
+        saddr_ipv4set = 1;
+        break;
+      }
+
+      case 't': {
+        struct in_addr a;
+        inet_aton(optarg,&a);
+        daddr_ipv4 = a.s_addr;
+        daddr_ipv4set = 1;
+        break;
+      }
+
+      case 'x':
+        printf("IPv6: %s\n",optarg);
+        inet_pton(AF_INET6,optarg,(void *)&saddr_ipv6);
+        saddr_ipv6set = 1;
+        break;
+
+      case 'y':
+        inet_pton(AF_INET6,optarg,(void *)&daddr_ipv6);
+        daddr_ipv6set = 1;
+        break;
+
+      case 'z':
+        dscpset=1;
+        strcpy(dscp,optarg);
+        break;
+
+      case '?':
+        if (isprint (optopt))
+          fprintf (stderr, "Unknown option `-%c'.\n", optopt);
+        else
+          fprintf (stderr,
+                   "Unknown option character `\\x%x'.\n",
+                   optopt);
+
+        return 1;
+
+      default:
+        abort ();
     }
 
-
   printf ("action = %d, rb = %s,cx = %s\n", action, rb, cx);
 
-
   if (rbset==0) {
     printf("ERROR: Specify a RAB id!!\n");
     exit(-1);
@@ -293,31 +281,27 @@ int main(int argc,char **argv)
   }
 
   IAL_NAS_ioctl_init(atoi(inst));
-
   msgreq = (struct nas_msg_rb_establishment_request *)(gifr.msg);
   msgreq->rab_id = atoi(rb);
   msgreq->lcr = atoi(cx);
   msgreq->qos = 0;
 
-
   if (action == ADD_RB) {
     gifr.type =  NAS_MSG_RB_ESTABLISHMENT_REQUEST;
     err=ioctl(fd, NAS_IOCTL_RRM, &gifr);
-    if (err == -1) perror("ioctl");
 
+    if (err == -1) perror("ioctl");
 
     if (saddr_ipv4set == 1) {
       msgreq_class = (struct nas_msg_class_add_request *)(gifr.msg);
       msgreq_class->rab_id = atoi(rb);
       msgreq_class->lcr = atoi(cx);
       msgreq_class->version = 4;
-
       msgreq_class->classref = 0 + (msgreq_class->lcr<<3);
       msgreq_class->dir = NAS_DIRECTION_SEND;
       msgreq_class->fct = NAS_FCT_QOS_SEND;
       msgreq_class->saddr.ipv4 = saddr_ipv4;
       msgreq_class->daddr.ipv4 = daddr_ipv4;
-
       // TO BE FIXED WHEN WE CAN SPECIFY A PROTOCOL-based rule
       msgreq_class->protocol = NAS_PROTOCOL_DEFAULT;
 
@@ -326,21 +310,20 @@ int main(int argc,char **argv)
       else
         msgreq_class->dscp=atoi(dscp);
 
-
       gifr.type =  NAS_MSG_CLASS_ADD_REQUEST;
       err=ioctl(fd, NAS_IOCTL_RRM, &gifr);
+
       if (err == -1) perror("ioctl");
+
       msgreq_class->rab_id = atoi(rb);
       msgreq_class->lcr = atoi(cx);
-
       msgreq_class->classref = 1+(msgreq_class->lcr<<3);
       msgreq_class->dir = NAS_DIRECTION_RECEIVE;
-
-
       msgreq_class->daddr.ipv4 = saddr_ipv4;
       msgreq_class->saddr.ipv4 = daddr_ipv4;
       gifr.type =  NAS_MSG_CLASS_ADD_REQUEST;
       err=ioctl(fd, NAS_IOCTL_RRM, &gifr);
+
       if (err == -1) perror("ioctl");
     }
 
@@ -358,38 +341,32 @@ int main(int argc,char **argv)
       msgreq_class->classref = 2+(msgreq_class->lcr<<3);
       msgreq_class->dir=NAS_DIRECTION_SEND;
       msgreq_class->fct=NAS_FCT_QOS_SEND;
-
       // TO BE FIXED WHEN WE CAN SPECIFY A PROTOCOL-based rule
       msgreq_class->protocol = NAS_PROTOCOL_DEFAULT;
-
       memcpy(&msgreq_class->saddr.ipv6,&saddr_ipv6,16);
       memcpy(&msgreq_class->daddr.ipv6,&daddr_ipv6,16);
-
       inet_ntop(AF_INET6,(void *)&saddr_ipv6,addr_str,46);
       printf("IPV6: Source %s\n",addr_str);
       inet_ntop(AF_INET6,(void *)&daddr_ipv6,addr_str,46);
       printf("IPV6: Dest %s\n",addr_str);
-
       gifr.type =  NAS_MSG_CLASS_ADD_REQUEST;
       err=ioctl(fd, NAS_IOCTL_RRM, &gifr);
+
       if (err == -1) perror("ioctl");
 
       msgreq_class->rab_id = atoi(rb);
       msgreq_class->lcr = atoi(cx);
-
       msgreq_class->classref = 3+(msgreq_class->lcr<<3);
       msgreq_class->dir=NAS_DIRECTION_RECEIVE;
       memcpy(&msgreq_class->daddr.ipv6,&saddr_ipv6,16);
       memcpy(&msgreq_class->saddr.ipv6,&daddr_ipv6,16);
       gifr.type =  NAS_MSG_CLASS_ADD_REQUEST;
       err=ioctl(fd, NAS_IOCTL_RRM, &gifr);
-      if (err == -1) perror("ioctl");
-
 
+      if (err == -1) perror("ioctl");
     }
 
     if (mpls_inlabelset == 1) {
-
       msgreq_class = (struct nas_msg_class_add_request *)(gifr.msg);
       msgreq_class->rab_id = atoi(rb);
       msgreq_class->lcr = atoi(cx);
@@ -403,50 +380,34 @@ int main(int argc,char **argv)
       msgreq_class->classref = 4 + (msgreq_class->lcr<<3);
       msgreq_class->dir=NAS_DIRECTION_SEND;
       msgreq_class->fct=NAS_FCT_QOS_SEND;
-
       // TO BE FIXED WHEN WE CAN SPECIFY A PROTOCOL-based rule
       msgreq_class->protocol = NAS_PROTOCOL_DEFAULT;
-
       mpls_outlabel = atoi(mpls_outgoinglabel);
-
-      printf("Setting MPLS outlabel %d with exp %d\n",mpls_outlabel,msgreq_class->dscp);
-
+      printf("Setting MPLS outlabel %u with exp %d\n",mpls_outlabel,msgreq_class->dscp);
       msgreq_class->daddr.mpls_label = mpls_outlabel;
-
       gifr.type =  NAS_MSG_CLASS_ADD_REQUEST;
       err=ioctl(fd, NAS_IOCTL_RRM, &gifr);
+
       if (err == -1) perror("ioctl");
 
       msgreq_class->rab_id = atoi(rb);
       msgreq_class->lcr = atoi(cx);
-
       msgreq_class->classref = 5 + (msgreq_class->lcr<<3);
       msgreq_class->dir=NAS_DIRECTION_RECEIVE;
-
-
       // TO BE FIXED WHEN WE CAN SPECIFY A PROTOCOL-based rule
       msgreq_class->protocol = NAS_PROTOCOL_DEFAULT;
-
       mpls_inlabel  = atoi(mpls_incominglabel);
-
-      printf("Setting MPLS inlabel %d with exp %d\n",mpls_inlabel,msgreq_class->dscp);
-
+      printf("Setting MPLS inlabel %u with exp %d\n",mpls_inlabel,msgreq_class->dscp);
       msgreq_class->daddr.mpls_label = mpls_inlabel;
-
       gifr.type =  NAS_MSG_CLASS_ADD_REQUEST;
       err=ioctl(fd, NAS_IOCTL_RRM, &gifr);
-      if (err == -1) perror("ioctl");
-
 
+      if (err == -1) perror("ioctl");
     }
   } else if (action == DEL_RB) {
     gifr.type =  NAS_MSG_RB_RELEASE_REQUEST;
     err=ioctl(fd, NAS_IOCTL_RRM, &gifr);
+
     if (err == -1) perror("ioctl");
   }
-
-
-
-
-
 }
diff --git a/openair2/NETWORK_DRIVER/MESH/classifier.c b/openair2/NETWORK_DRIVER/MESH/classifier.c
index a22ac2f20045b4457b9ec6adaeed72d931a0555a..15ac51158c404368e559042229c5a33003b85391 100644
--- a/openair2/NETWORK_DRIVER/MESH/classifier.c
+++ b/openair2/NETWORK_DRIVER/MESH/classifier.c
@@ -37,7 +37,7 @@
 //#define MPLS
 
 #ifdef MPLS
-#include <net/mpls.h>
+  #include <net/mpls.h>
 #endif
 
 
@@ -46,12 +46,9 @@
 
 //---------------------------------------------------------------------------
 // Add a new classifier rule (send direction)
-struct classifier_entity *nas_CLASS_add_sclassifier(struct cx_entity *cx, uint8_t dscp, uint16_t classref)
-{
+struct classifier_entity *nas_CLASS_add_sclassifier(struct cx_entity *cx, uint8_t dscp, uint16_t classref) {
   //---------------------------------------------------------------------------
   struct classifier_entity *gc;
-
-
 #ifdef NAS_DEBUG_CLASS
   printk("NAS_CLASS_ADD_SCLASSIFIER: begin for dscp %d, classref %d\n", dscp,classref);
 #endif
@@ -91,8 +88,7 @@ struct classifier_entity *nas_CLASS_add_sclassifier(struct cx_entity *cx, uint8_
 // Add a new classifier rule (receive direction)
 struct classifier_entity *nas_CLASS_add_rclassifier(uint8_t dscp,
     uint16_t classref,
-    struct nas_priv *gpriv)
-{
+    struct nas_priv *gpriv) {
   //---------------------------------------------------------------------------
   struct classifier_entity *gc;
 #ifdef NAS_DEBUG_CLASS
@@ -125,8 +121,7 @@ struct classifier_entity *nas_CLASS_add_rclassifier(uint8_t dscp,
 
 //---------------------------------------------------------------------------
 // Add a new classifier rule (forwarding)
-struct classifier_entity *nas_CLASS_add_fclassifier(struct cx_entity *cx, uint8_t dscp, uint16_t classref)
-{
+struct classifier_entity *nas_CLASS_add_fclassifier(struct cx_entity *cx, uint8_t dscp, uint16_t classref) {
   //---------------------------------------------------------------------------
   struct classifier_entity *gc;
 #ifdef NAS_DEBUG_CLASS
@@ -166,8 +161,7 @@ struct classifier_entity *nas_CLASS_add_fclassifier(struct cx_entity *cx, uint8_
 
 
 //---------------------------------------------------------------------------
-void nas_CLASS_flush_sclassifier(struct cx_entity *cx)
-{
+void nas_CLASS_flush_sclassifier(struct cx_entity *cx) {
   //---------------------------------------------------------------------------
   uint8_t dscpi;
   struct classifier_entity *gc;
@@ -196,8 +190,7 @@ void nas_CLASS_flush_sclassifier(struct cx_entity *cx)
 #endif
 }
 //---------------------------------------------------------------------------
-void nas_CLASS_flush_fclassifier(struct cx_entity *cx)
-{
+void nas_CLASS_flush_fclassifier(struct cx_entity *cx) {
   //---------------------------------------------------------------------------
   uint8_t dscpi;
   struct classifier_entity *gc;
@@ -227,8 +220,7 @@ void nas_CLASS_flush_fclassifier(struct cx_entity *cx)
 }
 
 //---------------------------------------------------------------------------
-void nas_CLASS_flush_rclassifier(struct nas_priv *gpriv)
-{
+void nas_CLASS_flush_rclassifier(struct nas_priv *gpriv) {
   //---------------------------------------------------------------------------
   uint8_t dscpi;
   struct classifier_entity *gc;
@@ -251,8 +243,7 @@ void nas_CLASS_flush_rclassifier(struct nas_priv *gpriv)
 
 //---------------------------------------------------------------------------
 // Delete a classifier rule (send direction)
-void nas_CLASS_del_sclassifier(struct cx_entity *cx, uint8_t dscp, uint16_t classref)
-{
+void nas_CLASS_del_sclassifier(struct cx_entity *cx, uint8_t dscp, uint16_t classref) {
   //---------------------------------------------------------------------------
   struct classifier_entity *p,*np;
 #ifdef NAS_DEBUG_CLASS
@@ -295,8 +286,7 @@ void nas_CLASS_del_sclassifier(struct cx_entity *cx, uint8_t dscp, uint16_t clas
 
 //---------------------------------------------------------------------------
 // Delete a classifier rule (send direction)
-void nas_CLASS_del_fclassifier(struct cx_entity *cx, uint8_t dscp, uint16_t classref)
-{
+void nas_CLASS_del_fclassifier(struct cx_entity *cx, uint8_t dscp, uint16_t classref) {
   //---------------------------------------------------------------------------
   struct classifier_entity *p,*np;
 #ifdef NAS_DEBUG_CLASS
@@ -339,8 +329,7 @@ void nas_CLASS_del_fclassifier(struct cx_entity *cx, uint8_t dscp, uint16_t clas
 
 //---------------------------------------------------------------------------
 // Delete a classifier rule (receive direction)
-void nas_CLASS_del_rclassifier(uint8_t dscp, uint16_t classref,struct nas_priv *gpriv)
-{
+void nas_CLASS_del_rclassifier(uint8_t dscp, uint16_t classref,struct nas_priv *gpriv) {
   //---------------------------------------------------------------------------
   struct classifier_entity *p,*np;
 #ifdef NAS_DEBUG_CLASS
@@ -379,8 +368,7 @@ struct cx_entity *nas_CLASS_cx6(struct sk_buff *skb,
                                 unsigned char dscp,
                                 struct nas_priv *gpriv,
                                 int inst,
-                                unsigned char *cx_searcher)
-{
+                                unsigned char *cx_searcher) {
   //---------------------------------------------------------------------------
   unsigned char cxi;
   unsigned int *addr,*dst=NULL;
@@ -388,17 +376,12 @@ struct cx_entity *nas_CLASS_cx6(struct sk_buff *skb,
   struct classifier_entity *p=NULL;
 
   if (skb!=NULL) {
-
     for (cxi=*cx_searcher; cxi<NAS_CX_MAX; cxi++) {
-
       (*cx_searcher)++;
-
       p = gpriv->cx[cxi].sclassifier[dscp];
 
       while (p!=NULL) {
         if (p->version == 6) {   // verify that this is an IPv4 rule
-
-
           if ((addr = (unsigned int *)(&(p->daddr.ipv6)))== NULL) {
             printk("nas_CLASS_cx6: addr is null \n");
             p = p->next;
@@ -409,9 +392,8 @@ struct cx_entity *nas_CLASS_cx6(struct sk_buff *skb,
           printk("cx %d : %X,%X.%X,%X\n",cxi,addr[0],addr[1],addr[2],addr[3]);
 #endif //NAS_DEBUG_CLASS
 
-          //if ((dst = (unsigned int*)&(((struct rt6_info *)skbdst)->rt6i_gateway)) == 0){
-          if ( (dst = &((struct iphdr*)(skb_network_header(skb)))->daddr) == NULL) {
 
+          if ( (dst = &((struct iphdr *)(skb_network_header(skb)))->daddr) == NULL) {
             printk("nas_CLASS_cx6: dst addr is null \n");
             p = p->next;
             continue;
@@ -446,11 +428,15 @@ struct cx_entity *nas_CLASS_cx6(struct sk_buff *skb,
     }
   }
 
-  printk("nas_CLASS_cx6 NOT FOUND: %X.%X.%X.%X\n",
-         dst[0],
-         dst[1],
-         dst[2],
-         dst[3]);
+
+  if (dst ) {
+    printk("nas_CLASS_cx6 NOT FOUND: %X.%X.%X.%X\n",
+           dst[0],
+           dst[1],
+           dst[2],
+           dst[3]);
+  }
+
   return default_ip;
 }
 
@@ -460,8 +446,7 @@ struct cx_entity *nas_CLASS_cx4(struct sk_buff *skb,
                                 unsigned char dscp,
                                 struct nas_priv *gpriv,
                                 int inst,
-                                unsigned char *cx_searcher)
-{
+                                unsigned char *cx_searcher) {
   //---------------------------------------------------------------------------
   unsigned char cxi;
   unsigned char *addr;
@@ -473,10 +458,9 @@ struct cx_entity *nas_CLASS_cx4(struct sk_buff *skb,
   //    return(gpriv->cx);  //dump to clusterhead
 
   if (skb!=NULL) {
-    daddr = ((struct iphdr*)(skb_network_header(skb)))->daddr;
+    daddr = ((struct iphdr *)(skb_network_header(skb)))->daddr;
 
     if (daddr!=0) {
-
 #ifdef NAS_DEBUG_CLASS
       printk("[NAS][CLASS][IPv4] Searching for %d.%d.%d.%d\n",
              ((unsigned char *)&daddr)[0],
@@ -491,7 +475,6 @@ struct cx_entity *nas_CLASS_cx4(struct sk_buff *skb,
 
         while (p!=NULL) {
           if (p->version == 4) {   // verify that this is an IPv4 rule
-
 #ifdef NAS_DEBUG_CLASS
             addr = (char *)(&(p->daddr.ipv4));
             printk("found classifier cx %d for destination: %d.%d.%d.%d\n",cxi,addr[0],addr[1],addr[2],addr[3]);
@@ -536,32 +519,23 @@ struct cx_entity *nas_CLASS_MPLS(struct sk_buff *skb,
                                  unsigned char exp,
                                  struct nas_priv *gpriv,
                                  int inst,
-                                 unsigned char *cx_searcher)
-{
+                                 unsigned char *cx_searcher) {
   //---------------------------------------------------------------------------
   unsigned char cxi;
-
   struct cx_entity *default_label=NULL;
   struct classifier_entity *p=NULL;
-
   //  if (inst >0)
   //    return(gpriv->cx);  //dump to clusterhead
-
-
 #ifdef NAS_DEBUG_CLASS
-
-
   printk("[NAS][CLASS][MPLS] Searching for label %d\n",MPLSCB(skb)->label);
 #endif
 
   for (cxi=*cx_searcher; cxi<NAS_CX_MAX; ++cxi) {
-
     (*cx_searcher)++;
     p = gpriv->cx[cxi].sclassifier[exp];
 
     while (p!=NULL) {
       if (p->version == NAS_MPLS_VERSION_CODE) {   // verify that this is an MPLS rule
-
 #ifdef NAS_DEBUG_CLASS
         printk("cx %d : label %d\n",cxi,p->daddr.mpls_label);
 #endif //NAS_DEBUG_CLASS
@@ -588,11 +562,8 @@ struct cx_entity *nas_CLASS_MPLS(struct sk_buff *skb,
       // goto to next classification rule for the connection
       p = p->next;
     }
-
   }
 
-
-
   return default_label;
 }
 
@@ -600,8 +571,7 @@ struct cx_entity *nas_CLASS_MPLS(struct sk_buff *skb,
 
 //---------------------------------------------------------------------------
 // Search the sending function
-void nas_CLASS_send(struct sk_buff *skb,int inst)
-{
+void nas_CLASS_send(struct sk_buff *skb,int inst) {
   //---------------------------------------------------------------------------
   struct classifier_entity *p, *sp;
   uint8_t *protocolh,version;
@@ -609,15 +579,10 @@ void nas_CLASS_send(struct sk_buff *skb,int inst)
   uint16_t classref;
   struct cx_entity *cx;
   //unsigned int i;
-
   //unsigned int router_adv = 0;
   struct net_device *dev=nasdev[inst];
-
   struct nas_priv *gpriv=netdev_priv(dev);
-
   unsigned char cx_searcher,no_connection=1;
-
-
 #ifdef NAS_DEBUG_CLASS
   printk("NAS_CLASS_SEND: begin - inst %d\n",inst);
 #endif
@@ -629,9 +594,7 @@ void nas_CLASS_send(struct sk_buff *skb,int inst)
     return;
   }
 
-
 #ifdef NAS_DEBUG_SEND
-
   printk("[NAS][CLASS][SEND] Got packet from kernel:\n");
 
   for (i=0; i<256; i++)
@@ -641,80 +604,65 @@ void nas_CLASS_send(struct sk_buff *skb,int inst)
 #endif
   // find all connections related to socket
   cx_searcher = 0;
-
   no_connection = 1;
-
   //while (cx_searcher<NAS_CX_MAX) {
-
   cx = NULL;
 
   // Address classification
   switch (ntohs(skb->protocol)) {
-  case ETH_P_IPV6:
-    version = 6;
-
-    protocolh=nas_TOOL_get_protocol6(
-                (struct ipv6hdr *)(skb_network_header(skb)),
-                &protocol);
-    dscp=nas_TOOL_get_dscp6(
-           (struct ipv6hdr *)(skb_network_header(skb))
-         );
+    case ETH_P_IPV6:
+      version = 6;
+      protocolh=nas_TOOL_get_protocol6(
+                  (struct ipv6hdr *)(skb_network_header(skb)),
+                  &protocol);
+      dscp=nas_TOOL_get_dscp6(
+             (struct ipv6hdr *)(skb_network_header(skb))
+           );
 #ifdef NAS_DEBUG_CLASS
-    printk("NAS_CLASS_SEND: %p %d %p %d %p \n",skb, dscp, gpriv, inst, &cx_searcher);
+      printk("NAS_CLASS_SEND: %p %d %p %d %p \n",skb, dscp, gpriv, inst, &cx_searcher);
 #endif
-    cx=nas_CLASS_cx6(skb,dscp,gpriv,inst,&cx_searcher);
-
-
+      cx=nas_CLASS_cx6(skb,dscp,gpriv,inst,&cx_searcher);
 #ifdef NAS_DEBUG_CLASS
-    printk("NAS_CLASS_SEND: Got IPv6 packet, dscp = %d\n",dscp);
+      printk("NAS_CLASS_SEND: Got IPv6 packet, dscp = %d\n",dscp);
 #endif
-    break;
-
-  case ETH_P_IP:
-
+      break;
 
-    dscp=nas_TOOL_get_dscp4((struct iphdr *)(skb_network_header(skb)));
-    cx=nas_CLASS_cx4(skb,dscp,gpriv,inst,&cx_searcher);
-    protocolh=nas_TOOL_get_protocol4(
-                (struct iphdr *)(skb_network_header(skb)),
-                &protocol);
+    case ETH_P_IP:
+      dscp=nas_TOOL_get_dscp4((struct iphdr *)(skb_network_header(skb)));
+      cx=nas_CLASS_cx4(skb,dscp,gpriv,inst,&cx_searcher);
+      protocolh=nas_TOOL_get_protocol4(
+                  (struct iphdr *)(skb_network_header(skb)),
+                  &protocol);
 #ifdef NAS_DEBUG_CLASS
-    printk("NAS_CLASS_SEND: Got IPv4 packet (%x), dscp = %d, cx = %x\n",ntohs(skb->protocol),dscp,cx);
+      printk("NAS_CLASS_SEND: Got IPv4 packet (%x), dscp = %d, cx = %x\n",ntohs(skb->protocol),dscp,cx);
 #endif
-    version = 4;
-
-    break;
+      version = 4;
+      break;
 #ifdef MPLS
 
-  case ETH_P_MPLS_UC:
-    cx=nas_CLASS_MPLS(skb,MPLSCB(skb)->exp,gpriv,inst,&cx_searcher);
-
+    case ETH_P_MPLS_UC:
+      cx=nas_CLASS_MPLS(skb,MPLSCB(skb)->exp,gpriv,inst,&cx_searcher);
 #ifdef NAS_DEBUG_CLASS
-    printk("NAS_CLASS_SEND: Got MPLS unicast packet, exp = %d, label = %d, cx = %x\n",MPLSCB(skb)->exp,MPLSCB(skb)->label,cx);
+      printk("NAS_CLASS_SEND: Got MPLS unicast packet, exp = %d, label = %d, cx = %x\n",MPLSCB(skb)->exp,MPLSCB(skb)->label,cx);
 #endif
-
-    dscp = MPLSCB(skb)->exp;
-    version = NAS_MPLS_VERSION_CODE;
-    protocol = version;
-    break;
+      dscp = MPLSCB(skb)->exp;
+      version = NAS_MPLS_VERSION_CODE;
+      protocol = version;
+      break;
 #endif
 
-  default:
-    printk("NAS_CLASS_SEND: Unknown protocol\n");
-    version = 0;
-    return;
+    default:
+      printk("NAS_CLASS_SEND: Unknown protocol\n");
+      version = 0;
+      return;
   }
 
-
-
   // If a valid connection for the DSCP/EXP with destination address
   // is found scan all protocol-based classification rules
 
   if (cx) {
-
     classref=0;
     sp=NULL;
-
 #ifdef NAS_DEBUG_CLASS
     printk("[NAS][CLASSIFIER] DSCP/EXP %d : looking for classifier entry\n",dscp);
 #endif
@@ -738,12 +686,10 @@ void nas_CLASS_send(struct sk_buff *skb,int inst)
         classref=sp->classref;
         break;
       }
-
     }
 
     if (sp!=NULL) {
 #ifdef NAS_DEBUG_CLASS
-
       char sfct[10], sprotocol[10];
 
       if (sp->fct==nas_COMMON_QOS_send)
@@ -759,41 +705,38 @@ void nas_CLASS_send(struct sk_buff *skb,int inst)
         strcpy(sfct, "dc");
 
       switch(protocol) {
-      case NAS_PROTOCOL_UDP:
-        strcpy(sprotocol, "udp");
-        printk("udp packet\n");
-        break;
-
-      case NAS_PROTOCOL_TCP:
-        strcpy(sprotocol, "tcp");
-        printk("tcp packet\n");
-        break;
-
-      case NAS_PROTOCOL_ICMP4:
-        strcpy(sprotocol, "icmp4");
-        printk("icmp4 packet\n");
-        break;
-
-      case NAS_PROTOCOL_ICMP6:
-        strcpy(sprotocol, "icmp6");
-        print_TOOL_pk_icmp6((struct icmp6hdr*)protocolh);
-        break;
+        case NAS_PROTOCOL_UDP:
+          strcpy(sprotocol, "udp");
+          printk("udp packet\n");
+          break;
+
+        case NAS_PROTOCOL_TCP:
+          strcpy(sprotocol, "tcp");
+          printk("tcp packet\n");
+          break;
+
+        case NAS_PROTOCOL_ICMP4:
+          strcpy(sprotocol, "icmp4");
+          printk("icmp4 packet\n");
+          break;
+
+        case NAS_PROTOCOL_ICMP6:
+          strcpy(sprotocol, "icmp6");
+          print_TOOL_pk_icmp6((struct icmp6hdr *)protocolh);
+          break;
 #ifdef MPLS
 
-      case NAS_MPLS_VERSION_CODE:
-        strcpy(sprotocol,"mpls");
-        break;
+        case NAS_MPLS_VERSION_CODE:
+          strcpy(sprotocol,"mpls");
+          break;
 #endif
       }
 
       printk("NAS_CLASS_SEND: (dscp %u, %s) received, (classref %u, fct %s, rab_id %u) classifier rule\n",
              dscp, sprotocol, sp->classref, sfct, sp->rab_id);
 #endif
-
       sp->fct(skb, cx, sp,inst, NULL);
-
     } // if classifier entry match found
-
     else {
       printk("NAS_CLASS_SEND: no corresponding item in the classifier, so the message is dropped\n");
       //  nas_COMMON_del_send(skb, cx, NULL,inst);
@@ -802,20 +745,14 @@ void nas_CLASS_send(struct sk_buff *skb,int inst)
     no_connection = 0;
   }   // if connection found
 
-
 #ifdef NAS_DEBUG_CLASS
 
   if (no_connection == 1)
     printk("NAS_CLASS_SEND: no corresponding connection, so the message is dropped\n");
 
 #endif /* NAS_DEBUG_CLASS */
-
-
   //  }   // while loop over connections
-
-
 #ifdef NAS_DEBUG_CLASS
   printk("NAS_CLASS_SEND: end\n");
 #endif
-
 }
diff --git a/openair2/NETWORK_DRIVER/MESH/local.h b/openair2/NETWORK_DRIVER/MESH/local.h
index e23188d357006d2bebf16f58c5650cbea5d39266..f3f30f92244148cc0ee8f571306e66e4b9f9cb2f 100644
--- a/openair2/NETWORK_DRIVER/MESH/local.h
+++ b/openair2/NETWORK_DRIVER/MESH/local.h
@@ -64,6 +64,8 @@
 #include "rrc_nas_primitives.h"
 #include "COMMON/platform_types.h"
 
+#define MAKE_VERSION(a,b,c) ((a)*256+(b)*16+(c))
+
 struct rb_entity {
   nasRadioBearerId_t rab_id;
   nasSapId_t sapi;
@@ -160,6 +162,10 @@ typedef struct pdcp_data_req_header_s {
   sdu_size_t          data_size;
   signed int          inst;
   ip_traffic_type_t   traffic_type;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  uint32_t sourceL2Id;
+  uint32_t destinationL2Id;
+#endif
 } pdcp_data_req_header_t;
 
 typedef struct pdcp_data_ind_header_s {
@@ -167,6 +173,10 @@ typedef struct pdcp_data_ind_header_s {
   sdu_size_t          data_size;
   signed int          inst;
   ip_traffic_type_t   dummy_traffic_type;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  uint32_t sourceL2Id;
+  uint32_t destinationL2Id;
+#endif
 } pdcp_data_ind_header_t;
 
 extern struct net_device *nasdev[NB_INSTANCES_MAX];
diff --git a/openair2/NETWORK_DRIVER/UE_IP/README b/openair2/NETWORK_DRIVER/UE_IP/README
old mode 100755
new mode 100644
diff --git a/openair2/NETWORK_DRIVER/UE_IP/common.c b/openair2/NETWORK_DRIVER/UE_IP/common.c
index b21ca5f2dcc7bd9c8fab015f9f95d5b546fa4b77..1f0545270828579ca49903ea2aa9989d7898224e 100644
--- a/openair2/NETWORK_DRIVER/UE_IP/common.c
+++ b/openair2/NETWORK_DRIVER/UE_IP/common.c
@@ -248,7 +248,7 @@ ue_ip_common_ip2wireless(
   //---------------------------------------------------------------------------
   struct pdcp_data_req_header_s     pdcph;
   ue_ip_priv_t                     *priv_p=netdev_priv(ue_ip_dev[instP]);
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   ipversion_t         *ipv_p             = NULL;
   unsigned int         hard_header_len   = 0;
   unsigned char       *src_addr          = 0;
@@ -304,7 +304,16 @@ ue_ip_common_ip2wireless(
     if (dst_addr) {
       printk("[UE_IP_DRV][%s] Dest %d.%d.%d.%d\n",__FUNCTION__, dst_addr[0],dst_addr[1],dst_addr[2],dst_addr[3]);
     }
-
+    // modify inst by IP address for the U-Plane of multiple UEs while L2 fapi simulator start
+#ifdef UESIM_EXPANSION
+    if ((src_addr[3] - 2)> instP) {
+        pdcph.inst = src_addr[3] - 2;
+        printk("[UE_IP_DRV] change INST from %d to %d\n",instP, pdcph.inst);
+        instP = src_addr[3] - 2;
+        priv_p=netdev_priv(ue_ip_dev[instP]);
+    }
+#endif
+    // modify inst by IP address for the U-Plane of multiple UEs while L2 fapi simulator end
     //get Ipv4 address and pass to PCDP header
     printk("[UE_IP_DRV] source Id: 0x%08x\n",pdcph.sourceL2Id );
     printk("[UE_IP_DRV] destinationL2Id Id: 0x%08x\n",pdcph.destinationL2Id );
diff --git a/openair2/NETWORK_DRIVER/UE_IP/device.c b/openair2/NETWORK_DRIVER/UE_IP/device.c
index 47c820fe775330dd0aa9de35052667f31e4b0266..4f295543dca310e933694d9b296a7f2c0b7ce87b 100644
--- a/openair2/NETWORK_DRIVER/UE_IP/device.c
+++ b/openair2/NETWORK_DRIVER/UE_IP/device.c
@@ -394,7 +394,7 @@ int init_module (void)
 
   for (inst=0; inst<UE_IP_NB_INSTANCES_MAX; inst++) {
     printk("[UE_IP_DRV][%s] begin init instance %d\n", __FUNCTION__,inst);
-    sprintf(devicename,"oip%d",inst);
+    sprintf(devicename,"oip%d",inst+1);
 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0)
     ue_ip_dev[inst]  = alloc_netdev(sizeof(ue_ip_priv_t),devicename, ue_ip_init);
 #else
diff --git a/openair2/NETWORK_DRIVER/UE_IP/local.h b/openair2/NETWORK_DRIVER/UE_IP/local.h
index e590109b131ed0f1fe537ce93bcb202de35b948b..4a918a5c94835022fcf11df1907c8d6bfac5e3cf 100644
--- a/openair2/NETWORK_DRIVER/UE_IP/local.h
+++ b/openair2/NETWORK_DRIVER/UE_IP/local.h
@@ -90,7 +90,7 @@ typedef struct pdcp_data_req_header_s {
   sdu_size_t          data_size;
   signed int          inst;
   ip_traffic_type_t   traffic_type;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   uint32_t sourceL2Id;
   uint32_t destinationL2Id;
 #endif
@@ -101,7 +101,7 @@ typedef struct pdcp_data_ind_header_s {
   sdu_size_t          data_size;
   signed int          inst;
   ip_traffic_type_t   dummy_traffic_type;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   uint32_t sourceL2Id;
   uint32_t destinationL2Id;
 #endif
diff --git a/openair2/NETWORK_DRIVER/UE_IP/netlink.c b/openair2/NETWORK_DRIVER/UE_IP/netlink.c
index e8e36619d1b6942dcc0c1bbc73e353078baddcb5..658ae19aba91cc2718710f59f691ca58ba327a28 100644
--- a/openair2/NETWORK_DRIVER/UE_IP/netlink.c
+++ b/openair2/NETWORK_DRIVER/UE_IP/netlink.c
@@ -110,7 +110,7 @@ int ue_ip_netlink_init(void)
 # if LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0)
                 THIS_MODULE,
 # endif
-                &cfg
+                &cfg);
 #else /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0) */
   nas_nl_sk = netlink_kernel_create(
                 &init_net,
@@ -120,7 +120,7 @@ int ue_ip_netlink_init(void)
                 &nasmesh_mutex, // NULL
                 THIS_MODULE);
 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0) */
-              );
+
 
 
   if (nas_nl_sk == NULL) {
diff --git a/openair2/PHY_INTERFACE/IF_Module.c b/openair2/PHY_INTERFACE/IF_Module.c
index bd9f4bb8b22a11ab908a11fa62442db3017eb7af..8d08b956cf2df5da90f6d5f32e774a2618aa0803 100644
--- a/openair2/PHY_INTERFACE/IF_Module.c
+++ b/openair2/PHY_INTERFACE/IF_Module.c
@@ -33,13 +33,13 @@ void handle_rach(UL_IND_t *UL_info) {
 		     UL_info->rach_ind.rach_indication_body.preamble_list[0].preamble_rel8.preamble,
 		     UL_info->rach_ind.rach_indication_body.preamble_list[0].preamble_rel8.timing_advance,
 		     UL_info->rach_ind.rach_indication_body.preamble_list[0].preamble_rel8.rnti
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 		     ,0
 #endif
 		     );
   }
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0)) 
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   if (UL_info->rach_ind_br.rach_indication_body.number_of_preambles>0) {
 
     AssertFatal(UL_info->rach_ind_br.rach_indication_body.number_of_preambles<5,"More than 4 preambles not supported\n");
@@ -47,7 +47,10 @@ void handle_rach(UL_IND_t *UL_info) {
       AssertFatal(UL_info->rach_ind_br.rach_indication_body.preamble_list[i].preamble_rel13.rach_resource_type>0,
 		  "Got regular PRACH preamble, not BL/CE\n");
       LOG_D(MAC,"Frame %d, Subframe %d Calling initiate_ra_proc (CE_level %d)\n",UL_info->frame,UL_info->subframe,
+
 	    UL_info->rach_ind_br.rach_indication_body.preamble_list[i].preamble_rel13.rach_resource_type-1);
+      UL_info->rach_ind_br.rach_indication_body.number_of_preambles=0;
+
       initiate_ra_proc(UL_info->module_id,
 		       UL_info->CC_id,
 		       UL_info->frame,
diff --git a/openair2/PHY_INTERFACE/IF_Module.h b/openair2/PHY_INTERFACE/IF_Module.h
index 0390a9055179d236615b399b9717b6f021c369e4..b6ede7d598a05f1e06e802fb0d52b46a96510b50 100644
--- a/openair2/PHY_INTERFACE/IF_Module.h
+++ b/openair2/PHY_INTERFACE/IF_Module.h
@@ -76,7 +76,7 @@ typedef struct{
   /// RACH indication list
   nfapi_rach_indication_t rach_ind;
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   /// RACH indication list for BR UEs
   nfapi_rach_indication_t rach_ind_br;
 #endif
@@ -128,6 +128,17 @@ typedef struct IF_Module_s{
   pthread_mutex_t if_mutex;
 }IF_Module_t;
 
+// These mutex is used for multiple UEs L2 FAPI simulator.
+// Each UEs set these value in UL and UL_INFO is shared in all UE's thread.
+typedef struct {
+  pthread_mutex_t rx_mutex;
+  pthread_mutex_t crc_mutex;
+  pthread_mutex_t sr_mutex;
+  pthread_mutex_t harq_mutex;
+  pthread_mutex_t cqi_mutex;
+  pthread_mutex_t rach_mutex;
+}FILL_UL_INFO_MUTEX_t;
+
 /*Initial */
 IF_Module_t *IF_Module_init(int Mod_id);
 void IF_Module_kill(int Mod_id);
diff --git a/openair2/PHY_INTERFACE/IF_Module_NB_IoT.h b/openair2/PHY_INTERFACE/IF_Module_NB_IoT.h
index 479bd47d947d0c2fd79c96b84c72badf21557712..954eaaa2813b5f60b5e24e6ba9a7a7e306b5bbe3 100644
--- a/openair2/PHY_INTERFACE/IF_Module_NB_IoT.h
+++ b/openair2/PHY_INTERFACE/IF_Module_NB_IoT.h
@@ -10,7 +10,7 @@
 
 #include "nfapi_interface.h"
 //#include "openair1/PHY/LTE_TRANSPORT/defs_NB_IoT.h"
-#include "PhysicalConfigDedicated-NB-r13.h"
+#include "LTE_PhysicalConfigDedicated-NB-r13.h"
 //#include "openair2/PHY_INTERFACE/IF_Module_NB_IoT.h"
 #include "openair2/COMMON/platform_types.h"
 //#include "openair1/SCHED/IF_Module_L1_primitives_NB_IoT.h"
@@ -54,7 +54,7 @@ typedef struct{
 	uint16_t npdcch_Offset_USS; //Alfa_offset (see TS 36.213 ch 16.6)
 
 
-	ACK_NACK_NumRepetitions_NB_r13_t *ack_nack_numRepetitions_MSG4; //pointer to the first cell of a list of ack_nack_num_repetitions
+	LTE_ACK_NACK_NumRepetitions_NB_r13_t *ack_nack_numRepetitions_MSG4; //pointer to the first cell of a list of ack_nack_num_repetitions
 
     //ulPowerControlCommon (UE side)
     uint16_t p0_nominal_npusch;
diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.c b/openair2/PHY_INTERFACE/phy_stub_UE.c
index 166616c368069279247ab3dcb18ddebf0e49692f..8d625fbdc59337c86d4609e9a386314e411243c5 100644
--- a/openair2/PHY_INTERFACE/phy_stub_UE.c
+++ b/openair2/PHY_INTERFACE/phy_stub_UE.c
@@ -25,7 +25,11 @@ extern int oai_nfapi_rach_ind(nfapi_rach_indication_t *rach_ind);
 void configure_nfapi_pnf(char *vnf_ip_addr, int vnf_p5_port, char *pnf_ip_addr, int pnf_p7_port, int vnf_p7_port);
 
 
-
+UL_IND_t *UL_INFO = NULL;
+nfapi_tx_request_pdu_t* tx_request_pdu_list = NULL;
+nfapi_dl_config_request_t* dl_config_req = NULL;
+nfapi_ul_config_request_t* ul_config_req = NULL;
+nfapi_hi_dci0_request_t* hi_dci0_req = NULL;
 
 //extern uint8_t nfapi_pnf;
 //UL_IND_t *UL_INFO;
@@ -47,7 +51,9 @@ void fill_rx_indication_UE_MAC(module_id_t Mod_id,int frame,int subframe, UL_IND
 	  int timing_advance_update;
 
 
-	  pthread_mutex_lock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
+	  // pthread_mutex_lock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
+	  // change for mutiple UE's simulation.
+	  pthread_mutex_lock(&fill_ul_mutex.rx_mutex);
 
 
 	  UL_INFO->rx_ind.sfn_sf                    = frame<<4| subframe;
@@ -65,7 +71,11 @@ void fill_rx_indication_UE_MAC(module_id_t Mod_id,int frame,int subframe, UL_IND
 	  //pdu->rx_indication_rel8.length         = eNB->ulsch[UE_id]->harq_processes[harq_pid]->TBS>>3;
 	  pdu->rx_indication_rel8.length         = buflen;
 	  pdu->rx_indication_rel8.offset         = 1;   // DJP - I dont understand - but broken unless 1 ????  0;  // filled in at the end of the UL_INFO formation
-	  pdu->data                              = ulsch_buffer;
+
+	  // ulsch_buffer is necessary to keep its value.
+	  //pdu->data                              = ulsch_buffer;
+	  pdu->data = malloc(buflen);
+	  memcpy(pdu->data,ulsch_buffer,buflen);
 	  // estimate timing advance for MAC
 	  //sync_pos                               = lte_est_timing_advance_pusch(eNB,UE_id);
 	  timing_advance_update                  = 0;  // Don't know what to put here
@@ -80,7 +90,9 @@ void fill_rx_indication_UE_MAC(module_id_t Mod_id,int frame,int subframe, UL_IND
 
 	  UL_INFO->rx_ind.rx_indication_body.number_of_pdus++;
 	  UL_INFO->rx_ind.sfn_sf = frame<<4 | subframe;
-	  pthread_mutex_unlock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
+	  // pthread_mutex_unlock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
+	  // change for mutiple UE's simulation.
+	  pthread_mutex_unlock(&fill_ul_mutex.rx_mutex);
 
 
 }
@@ -88,7 +100,9 @@ void fill_rx_indication_UE_MAC(module_id_t Mod_id,int frame,int subframe, UL_IND
 void fill_sr_indication_UE_MAC(int Mod_id,int frame,int subframe, UL_IND_t *UL_INFO, uint16_t rnti) {
 
 
-  pthread_mutex_lock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
+  // change for mutiple UE's simulation.
+  //pthread_mutex_lock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
+  pthread_mutex_lock(&fill_ul_mutex.sr_mutex);
 
   nfapi_sr_indication_t       *sr_ind = &UL_INFO->sr_ind;
   nfapi_sr_indication_body_t  *sr_ind_body =    &sr_ind->sr_indication_body;
@@ -122,13 +136,17 @@ void fill_sr_indication_UE_MAC(int Mod_id,int frame,int subframe, UL_IND_t *UL_I
 
   //UL_INFO->rx_ind.rx_indication_body.number_of_pdus++;
   sr_ind_body->number_of_srs++;
-  pthread_mutex_unlock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
+  // change for mutiple UE's simulation.
+  // pthread_mutex_unlock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
+  pthread_mutex_unlock(&fill_ul_mutex.sr_mutex);
 }
 
 
 void fill_crc_indication_UE_MAC(int Mod_id,int frame,int subframe, UL_IND_t *UL_INFO, uint8_t crc_flag, int index, uint16_t rnti) {
 
-  pthread_mutex_lock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
+  // change for mutiple UE's simulation.
+  //pthread_mutex_lock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
+  pthread_mutex_lock(&fill_ul_mutex.crc_mutex);
 
   // REMEMBER HAVE EXCHANGED THE FOLLOWING TWO LINES HERE!
   nfapi_crc_indication_pdu_t *pdu =   &UL_INFO->crc_ind.crc_indication_body.crc_pdu_list[UL_INFO->crc_ind.crc_indication_body.number_of_crcs];
@@ -151,14 +169,21 @@ void fill_crc_indication_UE_MAC(int Mod_id,int frame,int subframe, UL_IND_t *UL_
 
   LOG_D(PHY, "%s() rnti:%04x pdus:%d\n", __FUNCTION__, pdu->rx_ue_information.rnti, UL_INFO->crc_ind.crc_indication_body.number_of_crcs);
 
-  pthread_mutex_unlock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
+  // change for mutiple UE's simulation.
+  // pthread_mutex_unlock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
+  pthread_mutex_unlock(&fill_ul_mutex.crc_mutex);
 }
 
 void fill_rach_indication_UE_MAC(int Mod_id,int frame,int subframe, UL_IND_t *UL_INFO, uint8_t ra_PreambleIndex, uint16_t ra_RNTI) {
 
 	LOG_D(MAC, "fill_rach_indication_UE_MAC 1 \n");
-	pthread_mutex_lock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
-	UL_INFO = (UL_IND_t*)malloc(sizeof(UL_IND_t));
+
+	// change for mutiple UE's simulation.
+	// pthread_mutex_lock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
+	pthread_mutex_lock(&fill_ul_mutex.rach_mutex);
+
+	// memory allocation and free memory of UL_INFO are done in UE_phy_stub_single_thread_rxn_txnp4.
+	// UL_INFO = (UL_IND_t*)malloc(sizeof(UL_IND_t));
 
 	    UL_INFO->rach_ind.rach_indication_body.number_of_preambles                 = 1;
 
@@ -195,16 +220,22 @@ void fill_rach_indication_UE_MAC(int Mod_id,int frame,int subframe, UL_IND_t *UL
 	          // with that branch.
 	          oai_nfapi_rach_ind(&UL_INFO->rach_ind);
 	          free(UL_INFO->rach_ind.rach_indication_body.preamble_list);
-	          free(UL_INFO);
+
+	         // memory allocation and free memory of UL_INFO are done in UE_phy_stub_single_thread_rxn_txnp4.
+	          //free(UL_INFO);
 
 	        //}
-	      pthread_mutex_unlock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
+	      // change for mutiple UE's simulation.
+	      // pthread_mutex_unlock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
+	      pthread_mutex_unlock(&fill_ul_mutex.rach_mutex);
 
 }
 
 void fill_ulsch_cqi_indication_UE_MAC(int Mod_id, uint16_t frame,uint8_t subframe, UL_IND_t *UL_INFO, uint16_t rnti) {
 
-	pthread_mutex_lock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
+	// change for mutiple UE's simulation.
+	//pthread_mutex_lock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
+	pthread_mutex_lock(&fill_ul_mutex.cqi_mutex);
 	nfapi_cqi_indication_pdu_t *pdu         = &UL_INFO->cqi_ind.cqi_pdu_list[UL_INFO->cqi_ind.number_of_cqis];
 	nfapi_cqi_indication_raw_pdu_t *raw_pdu = &UL_INFO->cqi_ind.cqi_raw_pdu_list[UL_INFO->cqi_ind.number_of_cqis];
 
@@ -233,14 +264,18 @@ void fill_ulsch_cqi_indication_UE_MAC(int Mod_id, uint16_t frame,uint8_t subfram
 
 
   UL_INFO->cqi_ind.number_of_cqis++;
-  pthread_mutex_unlock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
-
+  // change for mutiple UE's simulation.
+  //pthread_mutex_unlock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
+  pthread_mutex_unlock(&fill_ul_mutex.cqi_mutex);
 }
 
 void fill_ulsch_harq_indication_UE_MAC(int Mod_id, int frame,int subframe, UL_IND_t *UL_INFO, nfapi_ul_config_ulsch_harq_information *harq_information, uint16_t rnti)
 {
 
-  pthread_mutex_lock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
+  // change for mutiple UE's simulation.
+  //pthread_mutex_lock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
+  pthread_mutex_lock(&fill_ul_mutex.harq_mutex);
+
   nfapi_harq_indication_pdu_t *pdu =   &UL_INFO->harq_ind.harq_indication_body.harq_pdu_list[UL_INFO->harq_ind.harq_indication_body.number_of_harqs];
   int i;
 
@@ -271,8 +306,9 @@ void fill_ulsch_harq_indication_UE_MAC(int Mod_id, int frame,int subframe, UL_IN
     }
 
   UL_INFO->harq_ind.harq_indication_body.number_of_harqs++;
-  pthread_mutex_unlock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
-}
+  // change for mutiple UE's simulation.
+  //pthread_mutex_unlock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
+  pthread_mutex_unlock(&fill_ul_mutex.harq_mutex);}
 
 
 void fill_uci_harq_indication_UE_MAC(int Mod_id,
@@ -285,7 +321,10 @@ void fill_uci_harq_indication_UE_MAC(int Mod_id,
 			      uint16_t tdd_multiplexing_mask*/) {
 
 
-  pthread_mutex_lock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
+  // change for mutiple UE's simulation.
+  //pthread_mutex_lock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
+  pthread_mutex_lock(&fill_ul_mutex.harq_mutex);
+
   nfapi_harq_indication_t *ind       = &UL_INFO->harq_ind;
   nfapi_harq_indication_body_t *body = &ind->harq_indication_body;
   nfapi_harq_indication_pdu_t *pdu =   &body->harq_pdu_list[UL_INFO->harq_ind.harq_indication_body.number_of_harqs];
@@ -311,6 +350,7 @@ void fill_uci_harq_indication_UE_MAC(int Mod_id,
   else if (SNRtimes10 >  635) pdu->ul_cqi_information.ul_cqi=255;
   else                        pdu->ul_cqi_information.ul_cqi=(640+SNRtimes10)/5;
   pdu->ul_cqi_information.channel = 0;
+  if(harq_information->harq_information_rel9_fdd.tl.tag == NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL9_FDD_TAG){
       if ((harq_information->harq_information_rel9_fdd.ack_nack_mode == 0) &&
           (harq_information->harq_information_rel9_fdd.harq_size == 1)) {
 
@@ -332,12 +372,31 @@ void fill_uci_harq_indication_UE_MAC(int Mod_id,
       pdu->harq_indication_fdd_rel13.harq_tb_n[1] = 1; // Assuming always an ACK (No NACK or DTX)
 
     }
-    else AssertFatal(1==0,"only format 1a/b for now, received \n");
+  }else if(harq_information->harq_information_rel10_tdd.tl.tag == NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL10_TDD_TAG ){
+      if ((harq_information->harq_information_rel10_tdd.ack_nack_mode == 0) &&
+          (harq_information->harq_information_rel10_tdd.harq_size == 1)) {
+        pdu->harq_indication_tdd_rel13.tl.tag = NFAPI_HARQ_INDICATION_TDD_REL13_TAG;
+        pdu->harq_indication_tdd_rel13.mode = 0;
+        pdu->harq_indication_tdd_rel13.number_of_ack_nack = 1;
+        pdu->harq_indication_tdd_rel13.harq_data[0].bundling.value_0 = 1;
+
+      }  else if ((harq_information->harq_information_rel10_tdd.ack_nack_mode == 1) &&
+                  (harq_information->harq_information_rel10_tdd.harq_size == 2)) {
+        pdu->harq_indication_tdd_rel13.tl.tag = NFAPI_HARQ_INDICATION_TDD_REL13_TAG;
+        pdu->harq_indication_tdd_rel13.mode = 0;
+        pdu->harq_indication_tdd_rel13.number_of_ack_nack = 1;
+        pdu->harq_indication_tdd_rel13.harq_data[0].bundling.value_0 = 1;
+        pdu->harq_indication_tdd_rel13.harq_data[1].bundling.value_0 = 1;
+
+      }
+  } else AssertFatal(1==0,"only format 1a/b for now, received \n");
 
 
   UL_INFO->harq_ind.harq_indication_body.number_of_harqs++;
   LOG_D(PHY,"Incremented eNB->UL_INFO.harq_ind.number_of_harqs:%d\n", UL_INFO->harq_ind.harq_indication_body.number_of_harqs);
-  pthread_mutex_unlock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
+  // change for mutiple UE's simulation.
+  //pthread_mutex_unlock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
+  pthread_mutex_unlock(&fill_ul_mutex.harq_mutex);
 
 }
 
@@ -590,7 +649,7 @@ int dl_config_req_UE_MAC(nfapi_dl_config_request_t* req, module_id_t Mod_id) //,
   //Mod_id = 0; // Currently static (only for one UE) but this should change.
 
   /*struct PHY_VARS_eNB_s *eNB = RC.eNB[0][0];
-  eNB_rxtx_proc_t *proc = &eNB->proc.proc_rxtx[0];*/
+  L1_rxtx_proc_t *proc = &eNB->proc.L1_proc;*/
   nfapi_dl_config_request_pdu_t* dl_config_pdu_list = req->dl_config_request_body.dl_config_pdu_list;
   nfapi_dl_config_request_pdu_t *dl_config_pdu_tmp;
 
@@ -622,7 +681,8 @@ int dl_config_req_UE_MAC(nfapi_dl_config_request_t* req, module_id_t Mod_id) //,
 				//if(tx_request_pdu_list[dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index].segments[0].segment_data!= NULL && tx_request_pdu_list[dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index].segments[0].segment_length >0){
 				*/
 
-				if(dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index <= tx_req_num_elems -1){
+				// to avoid unexpected error , add check pdu_index is more than 0.
+				if((dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index >= 0) &&(dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index <= tx_req_num_elems -1)){
 				//if(tx_request_pdu_list + dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index!= NULL){
 
 					LOG_E(MAC, "dl_config_req_UE_MAC 2 Received data: sfn/sf:%d PDU[%d] size:%d, TX_PDU index: %d, tx_req_num_elems: %d \n", NFAPI_SFNSF2DEC(req->sfn_sf), i, dl_config_pdu_list[i].pdu_size, dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index, tx_req_num_elems);
@@ -941,14 +1001,14 @@ void UE_config_stub_pnf(void) {
 
 /* Dummy functions*/
 
-void handle_nfapi_hi_dci0_dci_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t *proc,
+void handle_nfapi_hi_dci0_dci_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,L1_rxtx_proc_t *proc,
                                   nfapi_hi_dci0_request_pdu_t *hi_dci0_config_pdu)
 {
 
 }
 
 
-void handle_nfapi_hi_dci0_hi_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t *proc,
+void handle_nfapi_hi_dci0_hi_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,L1_rxtx_proc_t *proc,
                                  nfapi_hi_dci0_request_pdu_t *hi_dci0_config_pdu)
 {
 
@@ -957,14 +1017,14 @@ void handle_nfapi_hi_dci0_hi_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rx
 
 void handle_nfapi_dci_dl_pdu(PHY_VARS_eNB *eNB,
                              int frame, int subframe,
-                             eNB_rxtx_proc_t *proc,
+                             L1_rxtx_proc_t *proc,
                              nfapi_dl_config_request_pdu_t *dl_config_pdu)
 {
 
 }
 
 
-void handle_nfapi_bch_pdu(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
+void handle_nfapi_bch_pdu(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc,
                           nfapi_dl_config_request_pdu_t *dl_config_pdu,
                           uint8_t *sdu)
 {
@@ -972,7 +1032,7 @@ void handle_nfapi_bch_pdu(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
 }
 
 
-void handle_nfapi_dlsch_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_proc_t *proc,
+void handle_nfapi_dlsch_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,L1_rxtx_proc_t *proc,
                             nfapi_dl_config_request_pdu_t *dl_config_pdu,
                             uint8_t codeword_index,
                             uint8_t *sdu)
@@ -981,7 +1041,7 @@ void handle_nfapi_dlsch_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,eNB_rxtx_pr
 }
 
 
-void handle_nfapi_ul_pdu(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
+void handle_nfapi_ul_pdu(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc,
                          nfapi_ul_config_request_pdu_t *ul_config_pdu,
                          uint16_t frame,uint8_t subframe,uint8_t srs_present)
 {
diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.h b/openair2/PHY_INTERFACE/phy_stub_UE.h
index 9060951b26068a974ed92c7b21e25772054ac96b..21fb8518fad866e88c1d78f21aecd232657916c4 100644
--- a/openair2/PHY_INTERFACE/phy_stub_UE.h
+++ b/openair2/PHY_INTERFACE/phy_stub_UE.h
@@ -17,19 +17,23 @@
 //#include "openair1/PHY/defs.h"
 //#include "openair1/PHY/LTE_TRANSPORT/defs.h"
 
-UL_IND_t *UL_INFO;
-
-nfapi_tx_request_pdu_t* tx_request_pdu_list;
+// this mutex is used to set multiple UE's UL value in L2 FAPI simulator.
+FILL_UL_INFO_MUTEX_t fill_ul_mutex;
+//below 2 difinitions move to phy_stub_UE.c to add initialization when difinition.
+extern UL_IND_t *UL_INFO;
+extern nfapi_tx_request_pdu_t* tx_request_pdu_list;
 // New
 /// Pointers to config_request types. Used from nfapi callback functions.
-nfapi_dl_config_request_t* dl_config_req;
-nfapi_ul_config_request_t* ul_config_req;
-nfapi_hi_dci0_request_t* hi_dci0_req;
+//below 3 difinitions move to phy_stub_UE.c to add initialization when difinition.
+extern nfapi_dl_config_request_t* dl_config_req;
+extern nfapi_ul_config_request_t* ul_config_req;
+extern nfapi_hi_dci0_request_t* hi_dci0_req;
 
 int	tx_req_num_elems;
 
-int next_ra_frame;
-module_id_t next_Mod_id;
+//below 2 difinitions move to lte-ue.c to add initialization when difinition.
+//int next_ra_frame;
+//module_id_t next_Mod_id;
 eth_params_t         stub_eth_params;
 
 
diff --git a/openair2/RRC/L2_INTERFACE/openair_rrc_L2_interface.c b/openair2/RRC/L2_INTERFACE/openair_rrc_L2_interface.c
index 2815ee3688e7c55490be05f26a2068f21bac0e64..c64fd09bfcc1d0049f2ff260d7eefceb9e19a168 100644
--- a/openair2/RRC/L2_INTERFACE/openair_rrc_L2_interface.c
+++ b/openair2/RRC/L2_INTERFACE/openair_rrc_L2_interface.c
@@ -72,7 +72,7 @@ mac_rrc_data_req(
 }
 
 //------------------------------------------------------------------------------
-int8_t
+/*int8_t
 mac_rrc_data_ind(
   const module_id_t     module_idP,
   const int             CC_idP,
@@ -100,7 +100,7 @@ mac_rrc_data_ind(
            eNB_indexP,
            mbsfn_sync_area)
         );
-}
+}*/
 
 //------------------------------------------------------------------------------
 void
diff --git a/openair2/RRC/L2_INTERFACE/openair_rrc_L2_interface.h b/openair2/RRC/L2_INTERFACE/openair_rrc_L2_interface.h
index 22fa2755d47b20dad5d5000876e5836c1db6d8fc..270436b029d3b673a9aef9f11d6fa811097061aa 100644
--- a/openair2/RRC/L2_INTERFACE/openair_rrc_L2_interface.h
+++ b/openair2/RRC/L2_INTERFACE/openair_rrc_L2_interface.h
@@ -45,7 +45,7 @@ mac_rrc_data_req(
   const uint8_t         mbsfn_sync_areaP
 );
 
-int8_t
+/*int8_t
 mac_rrc_data_ind(
   const module_id_t     module_idP,
   const int             CC_id,
@@ -83,7 +83,7 @@ mac_rrc_data_ind_ue(
   const sdu_size_t      sdu_lenP,
   const mac_enb_index_t eNB_indexP,
   const uint8_t         mbsfn_sync_area
-);
+);*/
 
 void mac_lite_sync_ind(
   const module_id_t module_idP,
diff --git a/openair2/RRC/LITE/rrc_common.c b/openair2/RRC/LITE/rrc_common.c
new file mode 100644
index 0000000000000000000000000000000000000000..027a6299927abdb01014c431914c0e0fdfcefe50
--- /dev/null
+++ b/openair2/RRC/LITE/rrc_common.c
@@ -0,0 +1,495 @@
+/*
+ * 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
+ */
+
+/*! \file rrc_common.c
+ * \brief rrc common procedures for eNB and UE
+ * \author Navid Nikaein and Raymond Knopp
+ * \date 2011 - 2014
+ * \version 1.0
+ * \company Eurecom
+ * \email:  navid.nikaein@eurecom.fr and raymond.knopp@eurecom.fr
+ */
+
+#include "defs.h"
+#include "extern.h"
+#include "LAYER2/MAC/extern.h"
+#include "COMMON/openair_defs.h"
+#include "COMMON/platform_types.h"
+#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"
+#include "LAYER2/RLC/rlc.h"
+#include "COMMON/mac_rrc_primitives.h"
+#include "UTIL/LOG/log.h"
+#include "asn1_msg.h"
+#include "pdcp.h"
+#include "UTIL/LOG/vcd_signal_dumper.h"
+#include "rrc_eNB_UE_context.h"
+#include "common/ran_context.h"
+
+#ifdef LOCALIZATION
+#include <sys/time.h>
+#endif
+
+#define DEBUG_RRC 1
+extern RAN_CONTEXT_t RC;
+extern UE_MAC_INST *UE_mac_inst;
+
+extern mui_t rrc_eNB_mui;
+
+//configure  BCCH & CCCH Logical Channels and associated rrc_buffers, configure associated SRBs
+//-----------------------------------------------------------------------------
+void
+openair_rrc_on(
+  const protocol_ctxt_t* const ctxt_pP
+)
+//-----------------------------------------------------------------------------
+{
+  unsigned short i;
+  int            CC_id;
+
+  if (ctxt_pP->enb_flag == ENB_FLAG_YES) {
+    LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" OPENAIR RRC IN....\n",
+          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
+    for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
+      rrc_config_buffer (&RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SI, BCCH, 1);
+      RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SI.Active = 1;
+      rrc_config_buffer (&RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0, CCCH, 1);
+      RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Active = 1;
+    }
+  } else {
+    LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" OPENAIR RRC IN....\n",
+          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
+
+    for (i = 0; i < NB_eNB_INST; i++) {
+      LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" Activating CCCH (eNB %d)\n",
+            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP), i);
+      UE_rrc_inst[ctxt_pP->module_id].Srb0[i].Srb_id = CCCH;
+      memcpy (&UE_rrc_inst[ctxt_pP->module_id].Srb0[i].Lchan_desc[0], &CCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
+      memcpy (&UE_rrc_inst[ctxt_pP->module_id].Srb0[i].Lchan_desc[1], &CCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
+      rrc_config_buffer (&UE_rrc_inst[ctxt_pP->module_id].Srb0[i], CCCH, 1);
+      UE_rrc_inst[ctxt_pP->module_id].Srb0[i].Active = 1;
+    }
+  }
+}
+
+//-----------------------------------------------------------------------------
+int
+rrc_init_global_param(
+  void
+)
+//-----------------------------------------------------------------------------
+{
+
+  //#ifdef USER_MODE
+  //  Rrc_xface = (RRC_XFACE*)malloc16(sizeof(RRC_XFACE));
+  //#endif //USRE_MODE
+
+  //  Rrc_xface->openair_rrc_top_init = openair_rrc_top_init;
+  //  Rrc_xface->openair_rrc_eNB_init = openair_rrc_eNB_init;
+  //  Rrc_xface->openair_rrc_UE_init  = openair_rrc_ue_init;
+  //  Rrc_xface->mac_rrc_data_ind     = mac_rrc_data_ind;
+  //Rrc_xface->mac_rrc_data_req     = mac_rrc_data_req;
+  // Rrc_xface->rrc_data_indP        = (void *)rlcrrc_data_ind;
+  //  Rrc_xface->rrc_rx_tx            = rrc_rx_tx;
+  //  Rrc_xface->mac_rrc_meas_ind     = mac_rrc_meas_ind;
+  //  Rrc_xface->get_rrc_status       = get_rrc_status;
+
+  //Rrc_xface->rrc_get_status = ...
+
+  //  Mac_rlc_xface->mac_out_of_sync_ind=mac_out_of_sync_ind;
+
+#ifndef NO_RRM
+  //  Rrc_xface->fn_rrc=fn_rrc;
+#endif
+  //  LOG_D(RRC, "[RRC]INIT_GLOBAL_PARAM: Mac_rlc_xface %p, rrc_rlc_register %p,rlcrrc_data_ind%p\n",Mac_rlc_xface,Mac_rlc_xface->rrc_rlc_register_rrc,rlcrrc_data_ind);
+  /*
+   if((Mac_rlc_xface==NULL) || (Mac_rlc_xface->rrc_rlc_register_rrc==NULL) ||
+   (rlcrrc_data_ind==NULL)) {
+   LOG_E(RRC,"Data structured is not initialized \n");
+   return -1;
+   }
+   */
+  rrc_rlc_register_rrc (rrc_data_ind, NULL); //register with rlc
+
+  DCCH_LCHAN_DESC.transport_block_size = 4;
+  DCCH_LCHAN_DESC.max_transport_blocks = 16;
+  DCCH_LCHAN_DESC.Delay_class = 1;
+  DTCH_DL_LCHAN_DESC.transport_block_size = 52;
+  DTCH_DL_LCHAN_DESC.max_transport_blocks = 20;
+  DTCH_DL_LCHAN_DESC.Delay_class = 1;
+  DTCH_UL_LCHAN_DESC.transport_block_size = 52;
+  DTCH_UL_LCHAN_DESC.max_transport_blocks = 20;
+  DTCH_UL_LCHAN_DESC.Delay_class = 1;
+
+  Rlc_info_um.rlc_mode = RLC_MODE_UM;
+  Rlc_info_um.rlc.rlc_um_info.timer_reordering = 5;
+  Rlc_info_um.rlc.rlc_um_info.sn_field_length = 10;
+  Rlc_info_um.rlc.rlc_um_info.is_mXch = 0;
+  //Rlc_info_um.rlc.rlc_um_info.sdu_discard_mode=16;
+
+  Rlc_info_am_config.rlc_mode = RLC_MODE_AM;
+  Rlc_info_am_config.rlc.rlc_am_info.max_retx_threshold = 50;
+  Rlc_info_am_config.rlc.rlc_am_info.poll_pdu = 8;
+  Rlc_info_am_config.rlc.rlc_am_info.poll_byte = 1000;
+  Rlc_info_am_config.rlc.rlc_am_info.t_poll_retransmit = 15;
+  Rlc_info_am_config.rlc.rlc_am_info.t_reordering = 50;
+  Rlc_info_am_config.rlc.rlc_am_info.t_status_prohibit = 10;
+
+  return 0;
+}
+
+//-----------------------------------------------------------------------------
+void
+rrc_config_buffer(
+  SRB_INFO* Srb_info,
+  uint8_t Lchan_type,
+  uint8_t Role
+)
+//-----------------------------------------------------------------------------
+{
+
+  Srb_info->Rx_buffer.payload_size = 0;
+  Srb_info->Tx_buffer.payload_size = 0;
+}
+
+
+//-----------------------------------------------------------------------------
+void
+rrc_t310_expiration(
+  const protocol_ctxt_t* const ctxt_pP,
+  const uint8_t                 eNB_index
+)
+//-----------------------------------------------------------------------------
+{
+
+  if (UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].State != RRC_CONNECTED) {
+    LOG_D(RRC, "Timer 310 expired, going to RRC_IDLE\n");
+    UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].State = RRC_IDLE;
+    UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].UE_index = 0xffff;
+    UE_rrc_inst[ctxt_pP->module_id].Srb0[eNB_index].Rx_buffer.payload_size = 0;
+    UE_rrc_inst[ctxt_pP->module_id].Srb0[eNB_index].Tx_buffer.payload_size = 0;
+    UE_rrc_inst[ctxt_pP->module_id].Srb1[eNB_index].Srb_info.Rx_buffer.payload_size = 0;
+    UE_rrc_inst[ctxt_pP->module_id].Srb1[eNB_index].Srb_info.Tx_buffer.payload_size = 0;
+
+    if (UE_rrc_inst[ctxt_pP->module_id].Srb2[eNB_index].Active == 1) {
+      msg ("[RRC Inst %d] eNB_index %d, Remove RB %d\n ", ctxt_pP->module_id, eNB_index,
+           UE_rrc_inst[ctxt_pP->module_id].Srb2[eNB_index].Srb_info.Srb_id);
+      rrc_pdcp_config_req (ctxt_pP,
+                           SRB_FLAG_YES,
+                           CONFIG_ACTION_REMOVE,
+                           UE_rrc_inst[ctxt_pP->module_id].Srb2[eNB_index].Srb_info.Srb_id,
+                           0);
+      rrc_rlc_config_req (ctxt_pP,
+                          SRB_FLAG_YES,
+                          MBMS_FLAG_NO,
+                          CONFIG_ACTION_REMOVE,
+                          UE_rrc_inst[ctxt_pP->module_id].Srb2[eNB_index].Srb_info.Srb_id,
+                          Rlc_info_um);
+      UE_rrc_inst[ctxt_pP->module_id].Srb2[eNB_index].Active = 0;
+      UE_rrc_inst[ctxt_pP->module_id].Srb2[eNB_index].Status = IDLE;
+      UE_rrc_inst[ctxt_pP->module_id].Srb2[eNB_index].Next_check_frame = 0;
+    }
+  } else { // Restablishment procedure
+    LOG_D(RRC, "Timer 310 expired, trying RRCRestablishment ...\n");
+  }
+}
+
+//-----------------------------------------------------------------------------
+RRC_status_t
+rrc_rx_tx(
+  protocol_ctxt_t* const ctxt_pP,
+  const uint8_t      enb_indexP,
+  const int          CC_id
+)
+//-----------------------------------------------------------------------------
+{
+  //uint8_t        UE_id;
+  int32_t        current_timestamp_ms, ref_timestamp_ms;
+  struct timeval ts;
+  struct rrc_eNB_ue_context_s   *ue_context_p = NULL,*ue_to_be_removed = NULL;
+
+#ifdef LOCALIZATION
+  double                         estimated_distance;
+  protocol_ctxt_t                ctxt;
+#endif
+  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX,VCD_FUNCTION_IN);
+
+  if(ctxt_pP->enb_flag == ENB_FLAG_NO) {
+    // check timers
+
+    if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T300_active == 1) {
+      if ((UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T300_cnt % 10) == 0)
+        LOG_D(RRC,
+              "[UE %d][RAPROC] Frame %d T300 Count %d ms\n", ctxt_pP->module_id, ctxt_pP->frame, UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T300_cnt);
+
+      if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T300_cnt
+          == T300[UE_rrc_inst[ctxt_pP->module_id].sib2[enb_indexP]->ue_TimersAndConstants.t300]) {
+        UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T300_active = 0;
+        // ALLOW CCCH to be used
+        UE_rrc_inst[ctxt_pP->module_id].Srb0[enb_indexP].Tx_buffer.payload_size = 0;
+        rrc_ue_generate_RRCConnectionRequest (ctxt_pP, enb_indexP);
+        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX,VCD_FUNCTION_OUT);
+        return (RRC_ConnSetup_failed);
+      }
+
+      UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T300_cnt++;
+    }
+
+    if ((UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].SIStatus&2)>0) {
+      if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].N310_cnt
+          == N310[UE_rrc_inst[ctxt_pP->module_id].sib2[enb_indexP]->ue_TimersAndConstants.n310]) {
+	LOG_I(RRC,"Activating T310\n");
+        UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_active = 1;
+      }
+    } else { // in case we have not received SIB2 yet
+      /*      if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].N310_cnt == 100) {
+        UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].N310_cnt = 0;
+
+	}*/
+      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX,VCD_FUNCTION_OUT);
+      return RRC_OK;
+    }
+
+    if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_active == 1) {
+      if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].N311_cnt
+          == N311[UE_rrc_inst[ctxt_pP->module_id].sib2[enb_indexP]->ue_TimersAndConstants.n311]) {
+        UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_active = 0;
+        UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].N311_cnt = 0;
+      }
+
+      if ((UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_cnt % 10) == 0) {
+        LOG_D(RRC, "[UE %d] Frame %d T310 Count %d ms\n", ctxt_pP->module_id, ctxt_pP->frame, UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_cnt);
+      }
+
+      if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_cnt    == T310[UE_rrc_inst[ctxt_pP->module_id].sib2[enb_indexP]->ue_TimersAndConstants.t310]) {
+        UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_active = 0;
+        rrc_t310_expiration (ctxt_pP, enb_indexP);
+        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX,VCD_FUNCTION_OUT);
+	LOG_I(RRC,"Returning RRC_PHY_RESYNCH: T310 expired\n");
+        return RRC_PHY_RESYNCH;
+      }
+
+      UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_cnt++;
+    }
+
+    if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T304_active==1) {
+      if ((UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T304_cnt % 10) == 0)
+        LOG_D(RRC,"[UE %d][RAPROC] Frame %d T304 Count %d ms\n",ctxt_pP->module_id,ctxt_pP->frame,
+              UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T304_cnt);
+
+      if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T304_cnt == 0) {
+        UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T304_active = 0;
+        UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.measFlag = 1;
+        LOG_E(RRC,"[UE %d] Handover failure..initiating connection re-establishment procedure... \n",
+              ctxt_pP->module_id);
+        //Implement 36.331, section 5.3.5.6 here
+        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX,VCD_FUNCTION_OUT);
+        return(RRC_Handover_failed);
+      }
+
+      UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T304_cnt--;
+    }
+
+    // Layer 3 filtering of RRC measurements
+    if (UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[0] != NULL) {
+      ue_meas_filtering(ctxt_pP,enb_indexP);
+    }
+
+    ue_measurement_report_triggering(ctxt_pP,enb_indexP);
+
+    if (UE_rrc_inst[ctxt_pP->module_id].Info[0].handoverTarget > 0) {
+      LOG_I(RRC,"[UE %d] Frame %d : RRC handover initiated\n", ctxt_pP->module_id, ctxt_pP->frame);
+    }
+
+    if((UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].State == RRC_HO_EXECUTION)   &&
+        (UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.targetCellId != 0xFF)) {
+      UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].State= RRC_IDLE;
+      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX,VCD_FUNCTION_OUT);
+      return(RRC_HO_STARTED);
+    }
+
+  } else { // eNB
+    check_handovers(ctxt_pP);
+    // counetr, and get the value and aggregate
+
+
+    // check for UL failure
+    RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(RC.rrc[ctxt_pP->module_id]->rrc_ue_head)) {
+      LOG_D(RRC,"SFN.SN %d.%d => release timer %d/%d\n",ctxt_pP->frame,ctxt_pP->subframe,
+	    ue_context_p->ue_context.ue_release_timer,ue_context_p->ue_context.ue_release_timer_thres);
+      if ((ctxt_pP->frame == 0) && (ctxt_pP->subframe==0)) {
+	if (ue_context_p->ue_context.Initialue_identity_s_TMSI.presence == TRUE) {
+	  LOG_I(RRC,"UE rnti %x:S-TMSI %x failure timer %d/20000\n",
+		ue_context_p->ue_context.rnti,
+		ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi,
+		ue_context_p->ue_context.ul_failure_timer);
+	}
+	else {
+	  LOG_I(RRC,"UE rnti %x failure timer %d/20000\n",
+		ue_context_p->ue_context.rnti,
+		ue_context_p->ue_context.ul_failure_timer);
+	}
+      }
+      if (ue_context_p->ue_context.ul_failure_timer>0) {
+	ue_context_p->ue_context.ul_failure_timer++;
+	if (ue_context_p->ue_context.ul_failure_timer >= 20000) {
+	  // remove UE after 20 seconds after MAC has indicated UL failure
+	  LOG_I(RRC,"Removing UE %x instance (failure)\n",ue_context_p->ue_context.rnti);
+	  ue_to_be_removed = ue_context_p;
+	  break;
+	}
+      }
+      if (ue_context_p->ue_context.ue_release_timer>0) {
+	ue_context_p->ue_context.ue_release_timer++;
+	if (ue_context_p->ue_context.ue_release_timer >=
+	    ue_context_p->ue_context.ue_release_timer_thres) {
+	  LOG_I(RRC,"Removing UE %x instance (release timer %d)\n",ue_context_p->ue_context.rnti,ue_context_p->ue_context.ue_release_timer);
+	  ue_to_be_removed = ue_context_p;
+	  exit(-1);
+	  break;
+	}
+      }
+    }
+    if (ue_to_be_removed)
+      rrc_eNB_free_UE(ctxt_pP->module_id,ue_to_be_removed);
+
+#ifdef RRC_LOCALIZATION
+
+    /* for the localization, only primary CC_id might be relevant*/
+    gettimeofday(&ts, NULL);
+    current_timestamp_ms = ts.tv_sec * 1000 + ts.tv_usec / 1000;
+    ref_timestamp_ms = RC.rrc[ctxt_pP->module_id]->reference_timestamp_ms;
+    RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(RC.rrc[ctxt_pP->module_id]->rrc_ue_head)) {
+      ctxt = *ctxt_pP;
+      ctxt.rnti = ue_context_p->ue_context.rnti;
+      estimated_distance = rrc_get_estimated_ue_distance(
+                             &ctxt,
+                             CC_id,
+                             RC.rrc[ctxt_pP->module_id]->loc_type);
+
+      if ((current_timestamp_ms - ref_timestamp_ms > RC.rrc[ctxt_pP->module_id]->aggregation_period_ms) &&
+          estimated_distance != -1) {
+        LOG_D(LOCALIZE, " RRC [UE/id %d -> eNB/id %d] timestamp %d frame %d estimated r = %f\n",
+              ctxt.rnti,
+              ctxt_pP->module_id,
+              current_timestamp_ms,
+              ctxt_pP->frame,
+              estimated_distance);
+        LOG_D(LOCALIZE, " RRC status %d\n", ue_context_p->ue_context.Status);
+        push_front(&RC.rrc[ctxt_pP->module_id]->loc_list,
+                   estimated_distance);
+        RC.rrc[ctxt_pP->module_id]->reference_timestamp_ms = current_timestamp_ms;
+      }
+    }
+
+#endif
+    (void)ts; /* remove gcc warning "unused variable" */
+    (void)ref_timestamp_ms; /* remove gcc warning "unused variable" */
+    (void)current_timestamp_ms; /* remove gcc warning "unused variable" */
+  }
+
+  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX,VCD_FUNCTION_OUT);
+  return (RRC_OK);
+}
+
+//-----------------------------------------------------------------------------
+long
+binary_search_int(
+  int elements[],
+  long numElem,
+  int value
+)
+//-----------------------------------------------------------------------------
+{
+  long first, last, middle, search = -1;
+  first = 0;
+  last = numElem-1;
+  middle = (first+last)/2;
+
+  if(value < elements[0]) {
+    return first;
+  }
+
+  if(value > elements[last]) {
+    return last;
+  }
+
+  while (first <= last) {
+    if (elements[middle] < value) {
+      first = middle+1;
+    } else if (elements[middle] == value) {
+      search = middle+1;
+      break;
+    } else {
+      last = middle -1;
+    }
+
+    middle = (first+last)/2;
+  }
+
+  if (first > last) {
+    LOG_E(RRC,"Error in binary search!");
+  }
+
+  return search;
+}
+
+/* This is a binary search routine which operates on an array of floating
+   point numbers and returns the index of the range the value lies in
+   Used for RSRP and RSRQ measurement mapping. Can potentially be used for other things
+*/
+//-----------------------------------------------------------------------------
+long
+binary_search_float(
+  float elements[],
+  long numElem,
+  float value
+)
+//-----------------------------------------------------------------------------
+{
+  long first, last, middle;
+  first = 0;
+  last = numElem-1;
+  middle = (first+last)/2;
+
+  if(value <= elements[0]) {
+    return first;
+  }
+
+  if(value >= elements[last]) {
+    return last;
+  }
+
+  while (last - first > 1) {
+    if (elements[middle] > value) {
+      last = middle;
+    } else {
+      first = middle;
+    }
+
+    middle = (first+last)/2;
+  }
+
+  if (first < 0 || first >= numElem) {
+    LOG_E(RRC,"\n Error in binary search float!");
+  }
+
+  return first;
+}
diff --git a/openair2/RRC/LTE/L2_interface.c b/openair2/RRC/LTE/L2_interface.c
index f008b0698cf9c4b17c84bbe57503e5ee211532e9..947a38c63768ee4347dbc98a77e78027ebbbd4f2 100644
--- a/openair2/RRC/LTE/L2_interface.c
+++ b/openair2/RRC/LTE/L2_interface.c
@@ -38,7 +38,7 @@
 #include "common/ran_context.h"
 
 #if defined(ENABLE_ITTI)
-# include "intertask_interface.h"
+  #include "intertask_interface.h"
 #endif
 
 #include "flexran_agent_extern.h"
@@ -55,7 +55,7 @@ mac_rrc_data_req(
   const rb_id_t     Srb_id,
   const rnti_t      rnti,
   const uint8_t     Nb_tb,
-  uint8_t*    const buffer_pP,
+  uint8_t    *const buffer_pP,
   const uint8_t     mbsfn_sync_area
 )
 //--------------------------------------------------------------------------
@@ -65,198 +65,161 @@ mac_rrc_data_req(
   uint8_t Sdu_size                = 0;
   uint8_t sfn                     = (uint8_t)((frameP>>2)&0xff);
 
-
   if (LOG_DEBUGFLAG(DEBUG_RRC)) {
     LOG_D(RRC,"[eNB %d] mac_rrc_data_req to SRB ID=%d\n",Mod_idP,Srb_id);
   }
 
   eNB_RRC_INST *rrc;
   rrc_eNB_carrier_data_t *carrier;
-  BCCH_BCH_Message_t *mib;
-
-
-    rrc     = RC.rrc[Mod_idP];
-    carrier = &rrc->carrier[0];
-    mib     = &carrier->mib;
+  LTE_BCCH_BCH_Message_t *mib;
+  rrc     = RC.rrc[Mod_idP];
+  carrier = &rrc->carrier[0];
+  mib     = &carrier->mib;
+
+  if((Srb_id & RAB_OFFSET) == BCCH) {
+    if(RC.rrc[Mod_idP]->carrier[CC_id].SI.Active==0) {
+      return 0;
+    }
 
-    if((Srb_id & RAB_OFFSET) == BCCH) {
-      if(RC.rrc[Mod_idP]->carrier[CC_id].SI.Active==0) {
-        return 0;
-      }
+    // All even frames transmit SIB in SF 5
+    AssertFatal(RC.rrc[Mod_idP]->carrier[CC_id].sizeof_SIB1 != 255,
+                "[eNB %d] MAC Request for SIB1 and SIB1 not initialized\n",Mod_idP);
 
-      // All even frames transmit SIB in SF 5
-      AssertFatal(RC.rrc[Mod_idP]->carrier[CC_id].sizeof_SIB1 != 255, 
-		  "[eNB %d] MAC Request for SIB1 and SIB1 not initialized\n",Mod_idP);
+    if ((frameP%2) == 0) {
+      memcpy(&buffer_pP[0],
+             RC.rrc[Mod_idP]->carrier[CC_id].SIB1,
+             RC.rrc[Mod_idP]->carrier[CC_id].sizeof_SIB1);
 
-      if ((frameP%2) == 0) {
-        memcpy(&buffer_pP[0],
-               RC.rrc[Mod_idP]->carrier[CC_id].SIB1,
-               RC.rrc[Mod_idP]->carrier[CC_id].sizeof_SIB1);
+      if (LOG_DEBUGFLAG(DEBUG_RRC)) {
+        LOG_T(RRC,"[eNB %d] Frame %d : BCCH request => SIB 1\n",Mod_idP,frameP);
 
-        if (LOG_DEBUGFLAG(DEBUG_RRC)) {
-          LOG_T(RRC,"[eNB %d] Frame %d : BCCH request => SIB 1\n",Mod_idP,frameP);
+        for (int i=0; i<RC.rrc[Mod_idP]->carrier[CC_id].sizeof_SIB1; i++) {
+          LOG_T(RRC,"%x.",buffer_pP[i]);
+        }
 
-          for (int i=0; i<RC.rrc[Mod_idP]->carrier[CC_id].sizeof_SIB1; i++) {
-            LOG_T(RRC,"%x.",buffer_pP[i]);
-          }
+        LOG_T(RRC,"\n");
+      } /* LOG_DEBUGFLAG(DEBUG_RRC) */
 
-          LOG_T(RRC,"\n");
-        } /* LOG_DEBUGFLAG(DEBUG_RRC) */
+      return (RC.rrc[Mod_idP]->carrier[CC_id].sizeof_SIB1);
+    } // All RFN mod 8 transmit SIB2-3 in SF 5
+    else if ((frameP%8) == 1) {
+      memcpy(&buffer_pP[0],
+             RC.rrc[Mod_idP]->carrier[CC_id].SIB23,
+             RC.rrc[Mod_idP]->carrier[CC_id].sizeof_SIB23);
 
-        return (RC.rrc[Mod_idP]->carrier[CC_id].sizeof_SIB1);
-      } // All RFN mod 8 transmit SIB2-3 in SF 5
-      else if ((frameP%8) == 1) {
-        memcpy(&buffer_pP[0],
-               RC.rrc[Mod_idP]->carrier[CC_id].SIB23,
-               RC.rrc[Mod_idP]->carrier[CC_id].sizeof_SIB23);
+      if (LOG_DEBUGFLAG(DEBUG_RRC)) {
+        LOG_T(RRC,"[eNB %d] Frame %d BCCH request => SIB 2-3\n",Mod_idP,frameP);
 
-        if (LOG_DEBUGFLAG(DEBUG_RRC)) {
-          LOG_T(RRC,"[eNB %d] Frame %d BCCH request => SIB 2-3\n",Mod_idP,frameP);
+        for (int i=0; i<RC.rrc[Mod_idP]->carrier[CC_id].sizeof_SIB23; i++) {
+          LOG_T(RRC,"%x.",buffer_pP[i]);
+        }
 
-          for (int i=0; i<RC.rrc[Mod_idP]->carrier[CC_id].sizeof_SIB23; i++) {
-               LOG_T(RRC,"%x.",buffer_pP[i]);
-          }
+        LOG_T(RRC,"\n");
+      } /* LOG_DEBUGFLAG(DEBUG_RRC) */
 
-          LOG_T(RRC,"\n");
-        } /* LOG_DEBUGFLAG(DEBUG_RRC) */
-        return(RC.rrc[Mod_idP]->carrier[CC_id].sizeof_SIB23);
-      } else {
-        return(0);
-      }
+      return(RC.rrc[Mod_idP]->carrier[CC_id].sizeof_SIB23);
+    } else {
+      return(0);
     }
-    if( (Srb_id & RAB_OFFSET ) == MIBCH) {
-
-        mib->message.systemFrameNumber.buf = &sfn;
-	enc_rval = uper_encode_to_buffer(&asn_DEF_BCCH_BCH_Message,
-					 NULL,
-					 (void*)mib,
-					 carrier->MIB,
-					 24);
-//	LOG_D(RRC,"Encoded MIB for frame %d (%p), bits %lu\n",sfn,carrier->MIB,enc_rval.encoded);
-	buffer_pP[0]=carrier->MIB[0];
-	buffer_pP[1]=carrier->MIB[1];
-	buffer_pP[2]=carrier->MIB[2];
-	AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
-		     enc_rval.failed_type->name, enc_rval.encoded);
-	return(3);
-    }
-
-    if( (Srb_id & RAB_OFFSET ) == CCCH) {
+  }
 
-      struct rrc_eNB_ue_context_s *ue_context_p = rrc_eNB_get_ue_context(RC.rrc[Mod_idP],rnti);
-      
-      if (ue_context_p == NULL) return(0);
-      eNB_RRC_UE_t *ue_p = &ue_context_p->ue_context; 
-      LOG_T(RRC,"[eNB %d] Frame %d CCCH request (Srb_id %d, rnti %x)\n",Mod_idP,frameP, Srb_id,rnti);
+  if( (Srb_id & RAB_OFFSET ) == MIBCH) {
+    mib->message.systemFrameNumber.buf = &sfn;
+    enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_BCCH_BCH_Message,
+                                     NULL,
+                                     (void *)mib,
+                                     carrier->MIB,
+                                     24);
+    LOG_D(RRC,"Encoded MIB for frame %d (%p), bits %lu\n",sfn,carrier->MIB,enc_rval.encoded);
+    buffer_pP[0]=carrier->MIB[0];
+    buffer_pP[1]=carrier->MIB[1];
+    buffer_pP[2]=carrier->MIB[2];
+    AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
+                 enc_rval.failed_type->name, enc_rval.encoded);
+    return(3);
+  }
 
-/*      if(ue_p->Srb0.Active==0) {
-        LOG_E(RRC,"[eNB %d] CCCH Not active (%p, rnti %x)\n",Mod_idP,ue_p,ue_p->rnti);
-        return(0);
-      } */
+  if( (Srb_id & RAB_OFFSET ) == CCCH) {
 
-      Srb_info=&ue_p->Srb0;
+    struct rrc_eNB_ue_context_s *ue_context_p = rrc_eNB_get_ue_context(RC.rrc[Mod_idP],rnti);
 
-      // check if data is there for MAC
-      if(Srb_info->Tx_buffer.payload_size>0) { //Fill buffer
-        LOG_D(RRC,"[eNB %d] CCCH (%p) has %d bytes (dest: %p, src %p)\n",Mod_idP,Srb_info,Srb_info->Tx_buffer.payload_size,buffer_pP,Srb_info->Tx_buffer.Payload);
+    if (ue_context_p == NULL) return(0);
+    eNB_RRC_UE_t *ue_p = &ue_context_p->ue_context;
+    LOG_T(RRC,"[eNB %d] Frame %d CCCH request (Srb_id %d, rnti %x)\n",Mod_idP,frameP, Srb_id,rnti);
 
-        memcpy(buffer_pP,Srb_info->Tx_buffer.Payload,Srb_info->Tx_buffer.payload_size);
-        Sdu_size = Srb_info->Tx_buffer.payload_size;
-        Srb_info->Tx_buffer.payload_size=0;
-      }
+    Srb_info=&ue_p->Srb0;
 
-      return (Sdu_size);
+    // check if data is there for MAC
+    if(Srb_info->Tx_buffer.payload_size>0) { //Fill buffer
+      LOG_D(RRC,"[eNB %d] CCCH (%p) has %d bytes (dest: %p, src %p)\n",Mod_idP,Srb_info,Srb_info->Tx_buffer.payload_size,buffer_pP,Srb_info->Tx_buffer.Payload);
+      memcpy(buffer_pP,Srb_info->Tx_buffer.Payload,Srb_info->Tx_buffer.payload_size);
+      Sdu_size = Srb_info->Tx_buffer.payload_size;
+      Srb_info->Tx_buffer.payload_size=0;
     }
 
-    if( (Srb_id & RAB_OFFSET ) == PCCH) {
-      LOG_T(RRC,"[eNB %d] Frame %d PCCH request (Srb_id %d)\n",Mod_idP,frameP, Srb_id);
-
-      // check if data is there for MAC
-      if(RC.rrc[Mod_idP]->carrier[CC_id].sizeof_paging[mbsfn_sync_area] > 0) { //Fill buffer
-        LOG_D(RRC,"[eNB %d] PCCH (%p) has %d bytes\n",Mod_idP,&RC.rrc[Mod_idP]->carrier[CC_id].paging[mbsfn_sync_area],
-               RC.rrc[Mod_idP]->carrier[CC_id].sizeof_paging[mbsfn_sync_area]);
+    return (Sdu_size);
+  }
 
-        memcpy(buffer_pP, RC.rrc[Mod_idP]->carrier[CC_id].paging[mbsfn_sync_area], RC.rrc[Mod_idP]->carrier[CC_id].sizeof_paging[mbsfn_sync_area]);
-        Sdu_size = RC.rrc[Mod_idP]->carrier[CC_id].sizeof_paging[mbsfn_sync_area];
-        RC.rrc[Mod_idP]->carrier[CC_id].sizeof_paging[mbsfn_sync_area] = 0;
-      }
+  if( (Srb_id & RAB_OFFSET ) == PCCH) {
+    LOG_T(RRC,"[eNB %d] Frame %d PCCH request (Srb_id %d)\n",Mod_idP,frameP, Srb_id);
 
-      return (Sdu_size);
+    // check if data is there for MAC
+    if(RC.rrc[Mod_idP]->carrier[CC_id].sizeof_paging[mbsfn_sync_area] > 0) { //Fill buffer
+      LOG_D(RRC,"[eNB %d] PCCH (%p) has %d bytes\n",Mod_idP,&RC.rrc[Mod_idP]->carrier[CC_id].paging[mbsfn_sync_area],
+            RC.rrc[Mod_idP]->carrier[CC_id].sizeof_paging[mbsfn_sync_area]);
+      memcpy(buffer_pP, RC.rrc[Mod_idP]->carrier[CC_id].paging[mbsfn_sync_area], RC.rrc[Mod_idP]->carrier[CC_id].sizeof_paging[mbsfn_sync_area]);
+      Sdu_size = RC.rrc[Mod_idP]->carrier[CC_id].sizeof_paging[mbsfn_sync_area];
+      RC.rrc[Mod_idP]->carrier[CC_id].sizeof_paging[mbsfn_sync_area] = 0;
     }
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-
-    if((Srb_id & RAB_OFFSET) == MCCH) {
-      if(RC.rrc[Mod_idP]->carrier[CC_id].MCCH_MESS[mbsfn_sync_area].Active==0) {
-        return 0;  // this parameter is set in function init_mcch in rrc_eNB.c
-      }
+    return (Sdu_size);
+  }
 
-      memcpy(&buffer_pP[0],
-             RC.rrc[Mod_idP]->carrier[CC_id].MCCH_MESSAGE[mbsfn_sync_area],
-             RC.rrc[Mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[mbsfn_sync_area]);
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 
-     if (LOG_DEBUGFLAG(DEBUG_RRC)) {
-       LOG_D(RRC,"[eNB %d] Frame %d : MCCH request => MCCH_MESSAGE \n",Mod_idP,frameP);
+  if((Srb_id & RAB_OFFSET) == MCCH) {
+    if(RC.rrc[Mod_idP]->carrier[CC_id].MCCH_MESS[mbsfn_sync_area].Active==0) {
+      return 0;  // this parameter is set in function init_mcch in rrc_eNB.c
+    }
 
-       for (int i=0; i<RC.rrc[Mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[mbsfn_sync_area]; i++) {
-            LOG_T(RRC,"%x.",buffer_pP[i]);
-       }
+    memcpy(&buffer_pP[0],
+           RC.rrc[Mod_idP]->carrier[CC_id].MCCH_MESSAGE[mbsfn_sync_area],
+           RC.rrc[Mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[mbsfn_sync_area]);
 
-       LOG_T(RRC,"\n");
-     } /* LOG_DEBUGFLAG(DEBUG_RRC) */
+    if (LOG_DEBUGFLAG(DEBUG_RRC)) {
+      LOG_D(RRC,"[eNB %d] Frame %d : MCCH request => MCCH_MESSAGE \n",Mod_idP,frameP);
 
-     return (RC.rrc[Mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[mbsfn_sync_area]);
-    }
+      for (int i=0; i<RC.rrc[Mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[mbsfn_sync_area]; i++) {
+        LOG_T(RRC,"%x.",buffer_pP[i]);
+      }
 
-#endif // #if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+      LOG_T(RRC,"\n");
+    } /* LOG_DEBUGFLAG(DEBUG_RRC) */
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-    if ((Srb_id & RAB_OFFSET) == BCCH_SIB1_BR){
-        memcpy(&buffer_pP[0],
-               RC.rrc[Mod_idP]->carrier[CC_id].SIB1_BR,
-               RC.rrc[Mod_idP]->carrier[CC_id].sizeof_SIB1_BR);
-        return (RC.rrc[Mod_idP]->carrier[CC_id].sizeof_SIB1_BR);
-    }
+    return (RC.rrc[Mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[mbsfn_sync_area]);
+  }
 
-    if ((Srb_id & RAB_OFFSET) == BCCH_SI_BR){ // First SI message with SIB2/3
-        memcpy(&buffer_pP[0],
-               RC.rrc[Mod_idP]->carrier[CC_id].SIB23_BR,
-               RC.rrc[Mod_idP]->carrier[CC_id].sizeof_SIB23_BR);
-        return (RC.rrc[Mod_idP]->carrier[CC_id].sizeof_SIB23_BR);
-    }
+#endif // #if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 
-#endif
+  if ((Srb_id & RAB_OFFSET) == BCCH_SIB1_BR) {
+    memcpy(&buffer_pP[0],
+           RC.rrc[Mod_idP]->carrier[CC_id].SIB1_BR,
+           RC.rrc[Mod_idP]->carrier[CC_id].sizeof_SIB1_BR);
+    return (RC.rrc[Mod_idP]->carrier[CC_id].sizeof_SIB1_BR);
+  }
 
+  if ((Srb_id & RAB_OFFSET) == BCCH_SI_BR) { // First SI message with SIB2/3
+    memcpy(&buffer_pP[0],
+           RC.rrc[Mod_idP]->carrier[CC_id].SIB23_BR,
+           RC.rrc[Mod_idP]->carrier[CC_id].sizeof_SIB23_BR);
+    return (RC.rrc[Mod_idP]->carrier[CC_id].sizeof_SIB23_BR);
+  }
 
+#endif
   return(0);
 }
 
-//--------------------------------------------------------------------------
-// int8_t
-// mac_du_data_ind(
-//   const module_id_t     module_idP,
-//   const int             CC_idP,
-//   const int             UE_id,
-//   const rnti_t          rntiP,
-//   const uint8_t        *sduP,
-//   const sdu_size_t      sdu_lenP
-// )
-// //--------------------------------------------------------------------------
-// {
-//   printf(
-//       "[F1 %d][RAPROC] CC_id %d current_rnti %x Received Msg3 from already registered UE %d: length %d, offset %ld\n",
-//       module_idP, CC_idP, rntiP,
-//       UE_id, sdu_lenP, sduP);
-
-//   DU_send_INITIAL_UL_RRC_MESSAGE_TRANSFER(
-//       module_idP,
-//       CC_idP,
-//       UE_id,
-//       rntiP,  
-//       sduP,
-//       sdu_lenP
-//   );
-// }
 
 //------------------------------------------------------------------------------
 int8_t
@@ -268,9 +231,13 @@ mac_rrc_data_ind(
   const int             UE_id,
   const rnti_t          rntiP,
   const rb_id_t         srb_idP,
-  const uint8_t*        sduP,
+  const uint8_t        *sduP,
   const sdu_size_t      sdu_lenP,
   const uint8_t         mbsfn_sync_areaP
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  , const boolean_t		brOption
+#endif
+
 )
 //--------------------------------------------------------------------------
 {
@@ -294,60 +261,46 @@ mac_rrc_data_ind(
   SRB_INFO *Srb_info;
   protocol_ctxt_t ctxt;
   sdu_size_t      sdu_size = 0;
-
   /* for no gcc warnings */
   (void)sdu_size;
-
   /*
   int si_window;
    */
   PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, module_idP, ENB_FLAG_YES, rntiP, frameP, sub_frameP,0);
 
   if((srb_idP & RAB_OFFSET) == CCCH) {
-    LOG_I(RRC,"[eNB %d] Received SDU for CCCH on SRB 0 (%d,%x)\n",module_idP,
-	  ctxt.module_id,ctxt.rnti);
-
-    /*
-      // create a ue_context with rnti as random value, will be updated when Attach Request is received
-    struct rrc_eNB_ue_context_s  *ue_context_p = rrc_eNB_get_next_free_ue_context(&ctxt,
-										  rntiP
-										  );
-    
-    eNB_RRC_UE_t *ue_p = &ue_context_p->ue_context; 
-    SRB_INFO *srb_info_p = &ue_p->Srb0;
-
-      LOG_I(RRC,"Decoding CCCH : inst %d, CC_id %d, ue_context %p (rnti %x), sib_info_p->Rx_buffer.payload_size %d\n",
-	    module_idP,CC_id,ue_p, ue_p->rnti,sdu_lenP);
-      AssertFatal(sdu_lenP <= RRC_BUFFER_SIZE_MAX,
-		  "CCCH message has size %d > %d\n",sdu_lenP,RRC_BUFFER_SIZE_MAX);
-        
-     
-      memcpy(srb_info_p->Rx_buffer.Payload,
-             sduP,
-             sdu_lenP);
-      srb_info_p->Rx_buffer.payload_size = sdu_lenP;
-      srb_info_p->Active = 1;
-    */    
-
+    LOG_D(RRC,"[eNB %d] Received SDU for CCCH on SRB %d\n",module_idP,Srb_info->Srb_id);
+    /*Srb_info = &RC.rrc[module_idP]->carrier[CC_id].Srb0;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+    ctxt.brOption = brOption;
+#endif
+    if (sdu_lenP > 0) {
+      memcpy(Srb_info->Rx_buffer.Payload,sduP,sdu_lenP);
+      Srb_info->Rx_buffer.payload_size = sdu_lenP;
+      rrc_eNB_decode_ccch(&ctxt, Srb_info, CC_id);
+    }*/
     if (sdu_lenP > 0)  rrc_eNB_decode_ccch(&ctxt, sduP, sdu_lenP, CC_id);
-    
   }
+
   if((srb_idP & RAB_OFFSET) == DCCH) {
-      struct rrc_eNB_ue_context_s*    ue_context_p = NULL;
-      ue_context_p = rrc_eNB_get_ue_context(RC.rrc[ctxt.module_id],rntiP);
-      if(ue_context_p){
-        rrc_eNB_generate_defaultRRCConnectionReconfiguration(&ctxt,
-            ue_context_p,
-            0);
-        ue_context_p->ue_context.Status = RRC_RECONFIGURED;
-      }
+    struct rrc_eNB_ue_context_s    *ue_context_p = NULL;
+    ue_context_p = rrc_eNB_get_ue_context(RC.rrc[ctxt.module_id],rntiP);
+
+    if(ue_context_p) {
+      rrc_eNB_generate_defaultRRCConnectionReconfiguration(&ctxt,
+          ue_context_p,
+          0);
+      ue_context_p->ue_context.Status = RRC_RECONFIGURED;
     }
+  }
 
   return(0);
-
 }
 
 //------------------------------------------------------------------------------
+/*
+* Get RRC status (Connected, Idle...) of UE from RNTI
+*/
 int
 mac_eNB_get_rrc_status(
   const module_id_t Mod_idP,
@@ -355,10 +308,8 @@ mac_eNB_get_rrc_status(
 )
 //------------------------------------------------------------------------------
 {
-  struct rrc_eNB_ue_context_s* ue_context_p = NULL;
-  ue_context_p = rrc_eNB_get_ue_context(
-                   RC.rrc[Mod_idP],
-                   rntiP);
+  struct rrc_eNB_ue_context_s *ue_context_p = NULL;
+  ue_context_p = rrc_eNB_get_ue_context(RC.rrc[Mod_idP], rntiP);
 
   if (ue_context_p != NULL) {
     return(ue_context_p->ue_context.Status);
@@ -368,22 +319,21 @@ mac_eNB_get_rrc_status(
 }
 
 void mac_eNB_rrc_ul_failure(const module_id_t Mod_instP,
-			    const int CC_idP,
-			    const frame_t frameP,
-			    const sub_frame_t subframeP,
-			    const rnti_t rntiP)
-{
-  struct rrc_eNB_ue_context_s* ue_context_p = NULL;
+                            const int CC_idP,
+                            const frame_t frameP,
+                            const sub_frame_t subframeP,
+                            const rnti_t rntiP) {
+  struct rrc_eNB_ue_context_s *ue_context_p = NULL;
   ue_context_p = rrc_eNB_get_ue_context(
                    RC.rrc[Mod_instP],
                    rntiP);
 
   if (ue_context_p != NULL) {
     LOG_I(RRC,"Frame %d, Subframe %d: UE %x UL failure, activating timer\n",frameP,subframeP,rntiP);
+
     if(ue_context_p->ue_context.ul_failure_timer == 0)
       ue_context_p->ue_context.ul_failure_timer=1;
-  }
-  else {
+  } else {
     LOG_W(RRC,"Frame %d, Subframe %d: UL failure: UE %x unknown \n",frameP,subframeP,rntiP);
   }
   if (flexran_agent_get_rrc_xface(Mod_instP)) {
@@ -395,33 +345,31 @@ void mac_eNB_rrc_ul_failure(const module_id_t Mod_instP,
 }
 
 void mac_eNB_rrc_uplane_failure(const module_id_t Mod_instP,
-                const int CC_idP,
-                const frame_t frameP,
-                const sub_frame_t subframeP,
-                const rnti_t rntiP)
-{
-    struct rrc_eNB_ue_context_s* ue_context_p = NULL;
-    ue_context_p = rrc_eNB_get_ue_context(
-                     RC.rrc[Mod_instP],
-                     rntiP);
-    if (ue_context_p != NULL) {
-      LOG_I(RRC,"Frame %d, Subframe %d: UE %x U-Plane failure, activating timer\n",frameP,subframeP,rntiP);
-
-      if(ue_context_p->ue_context.ul_failure_timer == 0)
-          ue_context_p->ue_context.ul_failure_timer=19999;
-    }
-    else {
-      LOG_W(RRC,"Frame %d, Subframe %d: U-Plane failure: UE %x unknown \n",frameP,subframeP,rntiP);
-    }
+                                const int CC_idP,
+                                const frame_t frameP,
+                                const sub_frame_t subframeP,
+                                const rnti_t rntiP) {
+  struct rrc_eNB_ue_context_s *ue_context_p = NULL;
+  ue_context_p = rrc_eNB_get_ue_context(
+                   RC.rrc[Mod_instP],
+                   rntiP);
+
+  if (ue_context_p != NULL) {
+    LOG_I(RRC,"Frame %d, Subframe %d: UE %x U-Plane failure, activating timer\n",frameP,subframeP,rntiP);
+
+    if(ue_context_p->ue_context.ul_failure_timer == 0)
+      ue_context_p->ue_context.ul_failure_timer=19999;
+  } else {
+    LOG_W(RRC,"Frame %d, Subframe %d: U-Plane failure: UE %x unknown \n",frameP,subframeP,rntiP);
+  }
 }
 
-void mac_eNB_rrc_ul_in_sync(const module_id_t Mod_instP, 
-			    const int CC_idP, 
-			    const frame_t frameP,
-			    const sub_frame_t subframeP,
-			    const rnti_t rntiP)
-{
-  struct rrc_eNB_ue_context_s* ue_context_p = NULL;
+void mac_eNB_rrc_ul_in_sync(const module_id_t Mod_instP,
+                            const int CC_idP,
+                            const frame_t frameP,
+                            const sub_frame_t subframeP,
+                            const rnti_t rntiP) {
+  struct rrc_eNB_ue_context_s *ue_context_p = NULL;
   ue_context_p = rrc_eNB_get_ue_context(
                    RC.rrc[Mod_instP],
                    rntiP);
diff --git a/openair2/RRC/LTE/L2_interface_ue.c b/openair2/RRC/LTE/L2_interface_ue.c
index 3b7219af42913d844ca30f96a8029cc85aab60a6..9dfbeed61e4316109f909f4842f181d624831f9c 100644
--- a/openair2/RRC/LTE/L2_interface_ue.c
+++ b/openair2/RRC/LTE/L2_interface_ue.c
@@ -63,7 +63,7 @@ mac_rrc_data_req_ue(
   LOG_D(RRC,"[eNB %d] mac_rrc_data_req to SRB ID=%d\n",Mod_idP,Srb_id);
 
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
      LOG_D(RRC,"[UE %d] Frame %d Filling SL DISCOVERY SRB_ID %d\n",Mod_idP,frameP,Srb_id);
      LOG_D(RRC,"[UE %d] Frame %d buffer_pP status %d,\n",Mod_idP,frameP, UE_rrc_inst[Mod_idP].SL_Discovery[eNB_index].Tx_buffer.payload_size);
 
@@ -217,7 +217,7 @@ mac_rrc_data_ind_ue(
       }
     }
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 
     if ((srb_idP & RAB_OFFSET) == MCCH) {
       LOG_T(RRC,"[UE %d] Frame %d: Received SDU on MBSFN sync area %d for MCCH on SRB %d from eNB %d\n",
@@ -253,7 +253,7 @@ mac_rrc_data_ind_ue(
     	decode_SL_Discovery_Message(&ctxt, eNB_indexP, sduP, sdu_lenP);
     }
 
-#endif // #if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#endif // #if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 
   return(0);
 
@@ -327,7 +327,7 @@ rrc_data_req_ue(
            sdu_sizeP,
            buffer_pP,
            modeP
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
            ,NULL, NULL
 #endif
            );
diff --git a/openair2/RRC/LTE/MESSAGES/Makefile.inc b/openair2/RRC/LTE/MESSAGES/Makefile.inc
deleted file mode 100644
index aa17ad51ca9a50d77011378c2da83e2374baa11b..0000000000000000000000000000000000000000
--- a/openair2/RRC/LTE/MESSAGES/Makefile.inc
+++ /dev/null
@@ -1,91 +0,0 @@
-
-current_release_asn1_module=$(strip $(notdir $(wildcard $(OPENAIR2_DIR)/RRC/LITE/MESSAGES/asn1c/ASN1_files/.lock-*)))
-
-ifdef CBA
-    COMMON_CFLAGS += -DRel10
-    COMMON_CFLAGS += -DCBA
-    ifneq ($(current_release_asn1_module), .lock-rel10-cba)
-        tmp3:=$(shell cd $(OPENAIR2_DIR)/RRC/LITE/MESSAGES ;\
-                rm -f ${ASN_MODULE_SOURCES} $(ASN_MODULE_HEADERS) *.o *.d ;\
-                cd $(OPENAIR2_DIR)/RRC/LITE/MESSAGES/asn1c/ASN1_files/ ;\
-                rm EUTRA-RRC-Definitions.asn ;\
-                ln -s EUTRA-RRC-Definitions-a20-lola.asn EUTRA-RRC-Definitions.asn ; \
-                cd $(OPENAIR_TARGETS)/SIMU/USER/ ;\
-                rm -f $(ASN1_MSG_OBJS1) ;\
-                rm -f $(OPENAIR2_DIR)/RRC/LITE/MESSAGES/Makefile.inc.generated ;\
-                rm -f $(OPENAIR2_DIR)/RRC/LITE/MESSAGES/Makefile.am.sample ;\
-                rm -f $(L2_OBJS) ;\
-                rm -f *.o ;\
-                rm -f oaisim ;\
-                rm -f $(OPENAIR2_DIR)/RRC/LITE/MESSAGES/asn1c/ASN1_files/.lock-* ;\
-                touch $(OPENAIR2_DIR)/RRC/LITE/MESSAGES/asn1c/ASN1_files/.lock-rel10-cba ;\
-                /bin/bash $(OPENAIR_TARGETS)/SCRIPTS/asn1_generate_rrc_messaging_c_code.bash ;\
-                cd $(OPENAIR2_DIR)/RRC/LITE/MESSAGES ;\
-                awk '/converter-sample.c/ {exit} // {print}' Makefile.am.sample > Makefile.inc.generated  )
-    endif
-
-else ifdef Rel10
-   COMMON_CFLAGS += -DRel10
-   ifneq  ($(current_release_asn1_module), .lock-rel10)
-      tmp3:=$(shell cd $(OPENAIR2_DIR)/RRC/LITE/MESSAGES ;\
-              rm -f ${ASN_MODULE_SOURCES} $(ASN_MODULE_HEADERS) *.o *.d ;\
-              cd $(OPENAIR2_DIR)/RRC/LITE/MESSAGES/asn1c/ASN1_files/ ;\
-              rm EUTRA-RRC-Definitions.asn ;\
-              ln -s EUTRA-RRC-Definitions-a20.asn EUTRA-RRC-Definitions.asn ;\
-              cd $(OPENAIR_TARGETS)/SIMU/USER/ ;\
-              rm -f $(ASN1_MSG_OBJS1) ;\
-              rm -f $(OPENAIR2_DIR)/RRC/LITE/MESSAGES/Makefile.inc.generated ;\
-              rm -f $(OPENAIR2_DIR)/RRC/LITE/MESSAGES/Makefile.am.sample ;\
-              rm -f $(L2_OBJS) ;\
-              rm -f *.o ;\
-              rm -f oaisim ;\
-              rm -f $(OPENAIR2_DIR)/RRC/LITE/MESSAGES/asn1c/ASN1_files/.lock-* ;\
-              touch $(OPENAIR2_DIR)/RRC/LITE/MESSAGES/asn1c/ASN1_files/.lock-rel10 ;\
-              /bin/bash $(OPENAIR_TARGETS)/SCRIPTS/asn1_generate_rrc_messaging_c_code.bash ;\
-              cd $(OPENAIR2_DIR)/RRC/LITE/MESSAGES ;\
-              awk '/converter-sample.c/ {exit} // {print}' Makefile.am.sample > Makefile.inc.generated  )
-   endif
-
-else # default is rel 8
-   COMMON_CFLAGS += -DRel8
-   ifneq  ($(current_release_asn1_module), .lock-rel8)
-       tmp3:=$(shell cd $(OPENAIR2_DIR)/RRC/LITE/MESSAGES ;\
-               rm -f ${ASN_MODULE_SOURCES} $(ASN_MODULE_HEADERS) *.o *.d ;\
-               cd $(OPENAIR2_DIR)/RRC/LITE/MESSAGES/asn1c/ASN1_files/ ;\
-               rm EUTRA-RRC-Definitions.asn ;\
-               ln -s EUTRA-RRC-Definitions-86.asn EUTRA-RRC-Definitions.asn ;\
-               cd $(OPENAIR_TARGETS)/SIMU/USER/ ;\
-               rm -f $(ASN1_MSG_OBJS1) ;\
-               rm -f $(OPENAIR2_DIR)/RRC/LITE/MESSAGES/Makefile.inc.generated ;\
-               rm -f $(OPENAIR2_DIR)/RRC/LITE/MESSAGES/Makefile.am.sample ;\
-               rm -f $(L2_OBJS);\
-               rm -f *.o ;\
-               rm -f oaisim ;\
-               rm -f $(OPENAIR2_DIR)/RRC/LITE/MESSAGES/asn1c/ASN1_files/.lock-* ;\
-               touch $(OPENAIR2_DIR)/RRC/LITE/MESSAGES/asn1c/ASN1_files/.lock-rel8 ;\
-               /bin/bash $(OPENAIR_TARGETS)/SCRIPTS/asn1_generate_rrc_messaging_c_code.bash ;\
-               cd $(OPENAIR2_DIR)/RRC/LITE/MESSAGES ;\
-               awk '/converter-sample.c/ {exit} // {print}' Makefile.am.sample > Makefile.inc.generated  )
-    endif
-
-endif
-
-tmp:=$(shell cd $(OPENAIR2_DIR)/RRC/LITE/MESSAGES ;\
-       if [ ! -s Makefile.am.sample ] ; then \
-           /bin/bash $(OPENAIR_TARGETS)/SCRIPTS/asn1_generate_rrc_messaging_c_code.bash ;\
-       fi ;\
-       if [ ! -s Makefile.inc.generated ] ; then  \
-           awk '/converter-sample.c/ {exit} // {print}' Makefile.am.sample > Makefile.inc.generated ;\
-       fi )
-
-include $(OPENAIR2_DIR)/RRC/LITE/MESSAGES/Makefile.inc.generated
-
-ASN_CONVERTER_SOURCES+=asn1_msg.c
- 
-#COMMON_CFLAGS += -DEMIT_ASN_DEBUG=1
-
-EXTRA_CFLAGS += -I. -I$(OPENAIR2_DIR)/RRC/LITE/MESSAGES 
-
-ASN1_MODULE_OBJS=${ASN_MODULE_SOURCES:.c=.o}
-ASN1_CONVERTER_OBJS=${ASN_CONVERTER_SOURCES:.c=.o} 
-ASN1_MSG_OBJS=$(ASN1_MODULE_OBJS) $(ASN1_CONVERTER_OBJS)
diff --git a/openair2/RRC/LTE/MESSAGES/asn1_msg.c b/openair2/RRC/LTE/MESSAGES/asn1_msg.c
index 405efbd7b98e3393c9b591632e60210f1e716ab5..39445c859f13a7b66319e9a19098c463cb44b3dc 100644
--- a/openair2/RRC/LTE/MESSAGES/asn1_msg.c
+++ b/openair2/RRC/LTE/MESSAGES/asn1_msg.c
@@ -20,13 +20,13 @@
  */
 
 /*! \file asn1_msg.c
-* \brief primitives to build the asn1 messages
-* \author Raymond Knopp and Navid Nikaein
-* \date 2011
-* \version 1.0
-* \company Eurecom
-* \email: raymond.knopp@eurecom.fr and  navid.nikaein@eurecom.fr
-*/
+ * \brief primitives to build the asn1 messages
+ * \author Raymond Knopp and Navid Nikaein
+ * \date 2011
+ * \version 1.0
+ * \company Eurecom
+ * \email: raymond.knopp@eurecom.fr and  navid.nikaein@eurecom.fr
+ */
 
 #include <stdio.h>
 #include <sys/types.h>
@@ -39,56 +39,61 @@
 #include <asn_application.h>
 #include <asn_internal.h> /* for _ASN_DEFAULT_STACK_MAX */
 #include <per_encoder.h>
-
+#include "targets/RT/USER/lte-softmodem.h"
 #include "assertions.h"
-#include "RRCConnectionRequest.h"
-#include "UL-CCCH-Message.h"
-#include "UL-DCCH-Message.h"
-#include "DL-CCCH-Message.h"
-#include "DL-DCCH-Message.h"
-#include "PCCH-Message.h"
+#include "LTE_RRCConnectionRequest.h"
+#include "LTE_UL-CCCH-Message.h"
+#include "LTE_UL-DCCH-Message.h"
+#include "LTE_DL-CCCH-Message.h"
+#include "LTE_DL-DCCH-Message.h"
+#include "LTE_PCCH-Message.h"
 #include "openair3/UTILS/conversions.h"
-#include "EstablishmentCause.h"
-#include "RRCConnectionSetup.h"
-#include "SRB-ToAddModList.h"
-#include "DRB-ToAddModList.h"
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-#include "MCCH-Message.h"
-//#define MRB1 1
+#include "LTE_EstablishmentCause.h"
+#include "LTE_RRCConnectionSetup.h"
+#include "LTE_SRB-ToAddModList.h"
+#include "LTE_DRB-ToAddModList.h"
+#include "LTE_HandoverPreparationInformation.h"
+#include "LTE_HandoverCommand.h"
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+  #include "LTE_MCCH-Message.h"
+  //#define MRB1 1
 #endif
 
 #include "RRC/LTE/rrc_defs.h"
 #include "RRC/LTE/rrc_extern.h"
-#include "RRCConnectionSetupComplete.h"
-#include "RRCConnectionReconfigurationComplete.h"
-#include "RRCConnectionReconfiguration.h"
-#include "MasterInformationBlock.h"
-#include "SystemInformation.h"
+#include "LTE_RRCConnectionSetupComplete.h"
+#include "LTE_RRCConnectionReconfigurationComplete.h"
+#include "LTE_RRCConnectionReconfiguration.h"
+#include "LTE_MasterInformationBlock.h"
+#include "LTE_SystemInformation.h"
+
+
+#include "LTE_SystemInformationBlockType1.h"
+#include "LTE_SystemInformationBlockType1-BR-r13.h"
 
-#include "SystemInformationBlockType1.h"
 
-#include "SIB-Type.h"
+#include "LTE_SIB-Type.h"
 
-#include "BCCH-DL-SCH-Message.h"
-#include "SBCCH-SL-BCH-MessageType.h"
-#include "SBCCH-SL-BCH-Message.h"
+#include "LTE_BCCH-DL-SCH-Message.h"
+#include "LTE_SBCCH-SL-BCH-MessageType.h"
+#include "LTE_SBCCH-SL-BCH-Message.h"
 
 //#include "PHY/defs.h"
 
-#include "MeasObjectToAddModList.h"
-#include "ReportConfigToAddModList.h"
-#include "MeasIdToAddModList.h"
+#include "LTE_MeasObjectToAddModList.h"
+#include "LTE_ReportConfigToAddModList.h"
+#include "LTE_MeasIdToAddModList.h"
 #include "enb_config.h"
 
 #if defined(ENABLE_ITTI)
-# include "intertask_interface.h"
+  #include "intertask_interface.h"
 #endif
 
 #include "common/ran_context.h"
 #include "secu_defs.h"
 
 #if !defined (msg)
-#define msg printf
+  #define msg printf
 #endif
 
 
@@ -99,26 +104,25 @@ typedef struct xer_sprint_string_s {
 } xer_sprint_string_t;
 
 extern unsigned char NB_eNB_INST;
-extern uint8_t usim_test;
+
 
 extern RAN_CONTEXT_t RC;
 
 uint16_t two_tier_hexagonal_cellIds[7] = {0,1,2,4,5,7,8};
 uint16_t two_tier_hexagonal_adjacent_cellIds[7][6] = {{1,2,4,5,7,8},    // CellId 0
-  {11,18,2,0,8,15}, // CellId 1
-  {18,13,3,4,0,1},  // CellId 2
-  {2,3,14,6,5,0},   // CellId 4
-  {0,4,6,16,9,7},   // CellId 5
-  {8,0,5,9,17,12},  // CellId 7
-  {15,1,0,7,12,10}
+						      {11,18,2,0,8,15}, // CellId 1
+						      {18,13,3,4,0,1},  // CellId 2
+						      {2,3,14,6,5,0},   // CellId 4
+						      {0,4,6,16,9,7},   // CellId 5
+						      {8,0,5,9,17,12},  // CellId 7
+						      {15,1,0,7,12,10}
 };// CellId 8
 
 /*
  * This is a helper function for xer_sprint, which directs all incoming data
  * into the provided string.
  */
-static int xer__print2s (const void *buffer, size_t size, void *app_key)
-{
+static int xer__print2s (const void *buffer, size_t size, void *app_key) {
   xer_sprint_string_t *string_buffer = (xer_sprint_string_t *) app_key;
   size_t string_remaining = string_buffer->string_size - string_buffer->string_index;
 
@@ -134,15 +138,12 @@ static int xer__print2s (const void *buffer, size_t size, void *app_key)
   return 0;
 }
 
-int xer_sprint (char *string, size_t string_size, asn_TYPE_descriptor_t *td, void *sptr)
-{
+int xer_sprint (char *string, size_t string_size, asn_TYPE_descriptor_t *td, void *sptr) {
   asn_enc_rval_t er;
   xer_sprint_string_t string_buffer;
-
   string_buffer.string = string;
   string_buffer.string_size = string_size;
   string_buffer.string_index = 0;
-
   er = xer_encode(td, sptr, XER_F_BASIC, xer__print2s, &string_buffer);
 
   if (er.encoded < 0) {
@@ -158,14 +159,12 @@ int xer_sprint (char *string, size_t string_size, asn_TYPE_descriptor_t *td, voi
   return er.encoded;
 }
 
-uint16_t get_adjacent_cell_id(uint8_t Mod_id,uint8_t index)
-{
+uint16_t get_adjacent_cell_id(uint8_t Mod_id,uint8_t index) {
   return(two_tier_hexagonal_adjacent_cellIds[Mod_id][index]);
 }
 /* This only works for the hexagonal topology...need a more general function for other topologies */
 
-uint8_t get_adjacent_cell_mod_id(uint16_t phyCellId)
-{
+uint8_t get_adjacent_cell_mod_id(uint16_t phyCellId) {
   uint8_t i;
 
   for(i=0; i<7; i++) {
@@ -178,95 +177,81 @@ uint8_t get_adjacent_cell_mod_id(uint16_t phyCellId)
   return 0xFF; //error!
 }
 
-uint8_t do_MIB(rrc_eNB_carrier_data_t *carrier, uint32_t N_RB_DL, uint32_t phich_Resource, uint32_t phich_duration, uint32_t frame)
-{
+
+uint8_t do_MIB(rrc_eNB_carrier_data_t *carrier, uint32_t N_RB_DL, uint32_t phich_Resource, uint32_t phich_duration, uint32_t frame
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+	       , uint32_t schedulingInfoSIB1
+#endif
+	       ) {
 
   asn_enc_rval_t enc_rval;
-  BCCH_BCH_Message_t *mib=&carrier->mib ;
+  LTE_BCCH_BCH_Message_t *mib=&carrier->mib ;
   uint8_t sfn = (uint8_t)((frame>>2)&0xff);
-  uint16_t *spare= calloc(1, sizeof(uint16_t));
+  uint16_t *spare = calloc(1, sizeof(uint16_t));
+
   if (spare == NULL) abort();
 
   switch (N_RB_DL) {
+    case 6:
+      mib->message.dl_Bandwidth = LTE_MasterInformationBlock__dl_Bandwidth_n6;
+      break;
 
-  case 6:
-    mib->message.dl_Bandwidth = MasterInformationBlock__dl_Bandwidth_n6;
-    break;
+    case 15:
+      mib->message.dl_Bandwidth = LTE_MasterInformationBlock__dl_Bandwidth_n15;
+      break;
 
-  case 15:
-    mib->message.dl_Bandwidth = MasterInformationBlock__dl_Bandwidth_n15;
-    break;
+    case 25:
+      mib->message.dl_Bandwidth = LTE_MasterInformationBlock__dl_Bandwidth_n25;
+      break;
 
-  case 25:
-    mib->message.dl_Bandwidth = MasterInformationBlock__dl_Bandwidth_n25;
-    break;
+    case 50:
+      mib->message.dl_Bandwidth = LTE_MasterInformationBlock__dl_Bandwidth_n50;
+      break;
 
-  case 50:
-    mib->message.dl_Bandwidth = MasterInformationBlock__dl_Bandwidth_n50;
-    break;
+    case 75:
+      mib->message.dl_Bandwidth = LTE_MasterInformationBlock__dl_Bandwidth_n75;
+      break;
 
-  case 75:
-    mib->message.dl_Bandwidth = MasterInformationBlock__dl_Bandwidth_n75;
-    break;
+    case 100:
+      mib->message.dl_Bandwidth = LTE_MasterInformationBlock__dl_Bandwidth_n100;
+      break;
 
-  case 100:
-    mib->message.dl_Bandwidth = MasterInformationBlock__dl_Bandwidth_n100;
-    break;
-  default:
-    AssertFatal(1==0,"Unknown dl_Bandwidth %d\n",N_RB_DL);
+    default:
+      AssertFatal(1==0,"Unknown dl_Bandwidth %d\n",N_RB_DL);
   }
 
-  AssertFatal(phich_Resource <= PHICH_Config__phich_Resource_two,"Illegal phich_Resource\n");
+  AssertFatal(phich_Resource <= LTE_PHICH_Config__phich_Resource_two,"Illegal phich_Resource\n");
   mib->message.phich_Config.phich_Resource = phich_Resource;
-  AssertFatal(phich_duration <= PHICH_Config__phich_Duration_extended,"Illegal phich_Duration\n");
+  AssertFatal(phich_duration <= LTE_PHICH_Config__phich_Duration_extended,"Illegal phich_Duration\n");
   mib->message.phich_Config.phich_Duration = phich_duration;
-  LOG_I(RRC,"[MIB] systemBandwidth %x, phich_duration %x, phich_resource %x,sfn %x\n",
-         (uint32_t)mib->message.dl_Bandwidth,
-         (uint32_t)phich_duration,
-         (uint32_t)phich_Resource,
-         (uint32_t)sfn);
-
+  LOG_I(RRC,"[MIB] systemBandwidth %x, phich_duration %x, phich_resource %x, sfn %x\n",
+        (uint32_t)mib->message.dl_Bandwidth,
+        (uint32_t)phich_duration,
+        (uint32_t)phich_Resource,
+        (uint32_t)sfn);
   mib->message.systemFrameNumber.buf = &sfn;
   mib->message.systemFrameNumber.size = 1;
   mib->message.systemFrameNumber.bits_unused=0;
   mib->message.spare.buf = (uint8_t *)spare;
-#if (RRC_VERSION < MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION < MAKE_VERSION(14, 0, 0))
   mib->message.spare.size = 2;
   mib->message.spare.bits_unused = 6;  // This makes a spare of 10 bits
 #else
   mib->message.spare.size = 1;
   mib->message.spare.bits_unused = 3;  // This makes a spare of 5 bits
-  mib->message.schedulingInfoSIB1_BR_r13 = 0; // turn off eMTC
-#endif
+  mib->message.schedulingInfoSIB1_BR_r13 = schedulingInfoSIB1; // turn on/off eMTC
+  LOG_I(RRC,"[MIB] schedulingInfoSIB1 %d\n",
+	(uint32_t)mib->message.schedulingInfoSIB1_BR_r13);
 
-  enc_rval = uper_encode_to_buffer(&asn_DEF_BCCH_BCH_Message,
+#endif
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_BCCH_BCH_Message,
                                    NULL,
-                                   (void*)mib,
+                                   (void *)mib,
                                    carrier->MIB,
                                    24);
   AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
                enc_rval.failed_type->name, enc_rval.encoded);
 
-  /*
-#if defined(ENABLE_ITTI)
-# if !defined(DISABLE_XER_SPRINT)
-  {
-    char        message_string[20000];
-    size_t      message_string_size;
-
-    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_BCCH_BCH_Message, (void *) &mib)) > 0) {
-      MessageDef *msg_p;
-
-      msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_BCCH, message_string_size + sizeof (IttiMsgText));
-      msg_p->ittiMsg.rrc_dl_bcch.size = message_string_size;
-      memcpy(&msg_p->ittiMsg.rrc_dl_bcch.text, message_string, message_string_size);
-
-      itti_send_msg_to_task(TASK_UNKNOWN, enb_module_idP, msg_p);
-    }
-  }
-# endif
-#endif
-  */
   if (enc_rval.encoded==-1) {
     return(-1);
   }
@@ -276,58 +261,55 @@ uint8_t do_MIB(rrc_eNB_carrier_data_t *carrier, uint32_t N_RB_DL, uint32_t phich
 
 //TTN for D2D
 // 3GPP 36.331 (Section 5.10.7.4)
-uint8_t do_MIB_SL(const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index, uint32_t frame, uint8_t subframe, uint8_t in_coverage, uint8_t mode)
-{
+uint8_t do_MIB_SL(const protocol_ctxt_t *const ctxt_pP, const uint8_t eNB_index, uint32_t frame, uint8_t subframe, uint8_t in_coverage, uint8_t mode) {
+  asn_enc_rval_t enc_rval;
+  LTE_SBCCH_SL_BCH_MessageType_t *mib_sl = &UE_rrc_inst[ctxt_pP->module_id].mib_sl[eNB_index];
+  uint8_t sfn = (uint8_t)((frame>>2)&0xff);
+  UE_rrc_inst[ctxt_pP->module_id].MIB = (uint8_t *) malloc16(4);
 
-   asn_enc_rval_t enc_rval;
-   SBCCH_SL_BCH_MessageType_t *mib_sl = &UE_rrc_inst[ctxt_pP->module_id].mib_sl[eNB_index];
-   uint8_t sfn = (uint8_t)((frame>>2)&0xff);
-   UE_rrc_inst[ctxt_pP->module_id].MIB = (uint8_t*) malloc16(4);
-
-   if (in_coverage > 0 ){
-      //in coverage
-      mib_sl->inCoverage_r12 = TRUE;
-      mib_sl->sl_Bandwidth_r12 = *UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index]->freqInfo.ul_Bandwidth;
-      if (UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index]->tdd_Config) {
-         mib_sl->tdd_ConfigSL_r12.subframeAssignmentSL_r12 = UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index]->tdd_Config->subframeAssignment;
-      } else {
-         mib_sl->tdd_ConfigSL_r12.subframeAssignmentSL_r12 = TDD_ConfigSL_r12__subframeAssignmentSL_r12_none;
-      }
-      //if triggered by sl communication
-      if (UE_rrc_inst[ctxt_pP->module_id].sib18[eNB_index]->commConfig_r12->commSyncConfig_r12->list.array[0]->txParameters_r12->syncInfoReserved_r12){
-         mib_sl->reserved_r12 = *UE_rrc_inst[ctxt_pP->module_id].sib18[eNB_index]->commConfig_r12->commSyncConfig_r12->list.array[0]->txParameters_r12->syncInfoReserved_r12;
-      }
-      //if triggered by sl discovery
-      if (UE_rrc_inst[ctxt_pP->module_id].sib19[eNB_index]->discConfig_r12->discSyncConfig_r12->list.array[0]->txParameters_r12->syncInfoReserved_r12){
-              mib_sl->reserved_r12 = *UE_rrc_inst[ctxt_pP->module_id].sib19[eNB_index]->discConfig_r12->discSyncConfig_r12->list.array[0]->txParameters_r12->syncInfoReserved_r12;
-       }
-      //Todo - if triggered by v2x
-   } else {
-   //Todo - out of coverage for V2X
-   // Todo - UE has a selected SyncRef UE
-   mib_sl->inCoverage_r12 = FALSE;
-   //set sl-Bandwidth, subframeAssignmentSL and reserved from the pre-configured parameters
-   }
-
-   //set FrameNumber, subFrameNumber
-   mib_sl->directFrameNumber_r12.buf =  &sfn;
-   mib_sl->directFrameNumber_r12.size = 1;
-   mib_sl->directFrameNumber_r12.bits_unused=0;
-   mib_sl->directSubframeNumber_r12 = subframe;
+  if (in_coverage > 0 ) {
+    //in coverage
+    mib_sl->inCoverage_r12 = TRUE;
+    mib_sl->sl_Bandwidth_r12 = *UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index]->freqInfo.ul_Bandwidth;
 
+    if (UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index]->tdd_Config) {
+      mib_sl->tdd_ConfigSL_r12.subframeAssignmentSL_r12 = UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index]->tdd_Config->subframeAssignment;
+    } else {
+      mib_sl->tdd_ConfigSL_r12.subframeAssignmentSL_r12 = LTE_TDD_ConfigSL_r12__subframeAssignmentSL_r12_none;
+    }
 
-  LOG_I(RRC,"[MIB-SL] sfn %x, subframe %x\n", (uint32_t)sfn, (uint8_t)subframe);
+    //if triggered by sl communication
+    if (UE_rrc_inst[ctxt_pP->module_id].sib18[eNB_index]->commConfig_r12->commSyncConfig_r12->list.array[0]->txParameters_r12->syncInfoReserved_r12) {
+      mib_sl->reserved_r12 = *UE_rrc_inst[ctxt_pP->module_id].sib18[eNB_index]->commConfig_r12->commSyncConfig_r12->list.array[0]->txParameters_r12->syncInfoReserved_r12;
+    }
+
+    //if triggered by sl discovery
+    if (UE_rrc_inst[ctxt_pP->module_id].sib19[eNB_index]->discConfig_r12->discSyncConfig_r12->list.array[0]->txParameters_r12->syncInfoReserved_r12) {
+      mib_sl->reserved_r12 = *UE_rrc_inst[ctxt_pP->module_id].sib19[eNB_index]->discConfig_r12->discSyncConfig_r12->list.array[0]->txParameters_r12->syncInfoReserved_r12;
+    }
 
+    //Todo - if triggered by v2x
+  } else {
+    //Todo - out of coverage for V2X
+    // Todo - UE has a selected SyncRef UE
+    mib_sl->inCoverage_r12 = FALSE;
+    //set sl-Bandwidth, subframeAssignmentSL and reserved from the pre-configured parameters
+  }
 
-  enc_rval = uper_encode_to_buffer(&asn_DEF_SBCCH_SL_BCH_Message,
+  //set FrameNumber, subFrameNumber
+  mib_sl->directFrameNumber_r12.buf =  &sfn;
+  mib_sl->directFrameNumber_r12.size = 1;
+  mib_sl->directFrameNumber_r12.bits_unused=0;
+  mib_sl->directSubframeNumber_r12 = subframe;
+  LOG_I(RRC,"[MIB-SL] sfn %x, subframe %x\n", (uint32_t)sfn, (uint8_t)subframe);
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_SBCCH_SL_BCH_Message,
                                    NULL,
-                                   (void*)mib_sl,
+                                   (void *)mib_sl,
                                    UE_rrc_inst[ctxt_pP->module_id].MIB,
                                    24);
   AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
                enc_rval.failed_type->name, enc_rval.encoded);
 
-
   if (enc_rval.encoded==-1) {
     return(-1);
   }
@@ -338,48 +320,58 @@ uint8_t do_MIB_SL(const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index,
 
 uint8_t do_SIB1(rrc_eNB_carrier_data_t *carrier,
 		int Mod_id,int CC_id
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                , BOOLEAN_t brOption
+#endif
 #if defined(ENABLE_ITTI)
-                , RrcConfigurationReq *configuration
+  , RrcConfigurationReq *configuration
 #endif
-               )
-{
-
+               ) {
   //  SystemInformation_t systemInformation;
 #if defined(ENABLE_ITTI)
   int num_plmn = configuration->num_plmn;
 #else
   int num_plmn = 1;
 #endif
-  PLMN_IdentityInfo_t PLMN_identity_info[num_plmn];
-  MCC_MNC_Digit_t dummy_mcc[num_plmn][3], dummy_mnc[num_plmn][3];
+  LTE_PLMN_IdentityInfo_t PLMN_identity_info[num_plmn];
+  LTE_MCC_MNC_Digit_t dummy_mcc[num_plmn][3], dummy_mnc[num_plmn][3];
   asn_enc_rval_t enc_rval;
-  SchedulingInfo_t schedulingInfo;
-  SIB_Type_t sib_type;
+  LTE_SchedulingInfo_t schedulingInfo;
+  LTE_SIB_Type_t sib_type;
+
+  uint8_t *buffer;
+  LTE_BCCH_DL_SCH_Message_t *bcch_message;
+  LTE_SystemInformationBlockType1_t **sib1;
+
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  if (brOption) {
+    buffer       = carrier->SIB1_BR;
+    bcch_message = &carrier->siblock1_BR;
+    sib1         = &carrier->sib1_BR;
+  }
+  else
+#endif
+    {
+      buffer       = carrier->SIB1;
+      bcch_message = &carrier->siblock1;
+      sib1         = &carrier->sib1;
+    }
 
-  uint8_t *buffer                      = carrier->SIB1;
-  BCCH_DL_SCH_Message_t *bcch_message  = &carrier->siblock1;
-  SystemInformationBlockType1_t **sib1 = &carrier->sib1;
-  int i;
+  memset(bcch_message,0,sizeof(LTE_BCCH_DL_SCH_Message_t));
+  bcch_message->message.present = LTE_BCCH_DL_SCH_MessageType_PR_c1;
+  bcch_message->message.choice.c1.present = LTE_BCCH_DL_SCH_MessageType__c1_PR_systemInformationBlockType1;
 
-  
-  memset(bcch_message,0,sizeof(BCCH_DL_SCH_Message_t));
-  bcch_message->message.present = BCCH_DL_SCH_MessageType_PR_c1;
-  bcch_message->message.choice.c1.present = BCCH_DL_SCH_MessageType__c1_PR_systemInformationBlockType1;
   //  memcpy(&bcch_message.message.choice.c1.choice.systemInformationBlockType1,sib1,sizeof(SystemInformationBlockType1_t));
-
   *sib1 = &bcch_message->message.choice.c1.choice.systemInformationBlockType1;
-
-  memset(PLMN_identity_info,0,num_plmn * sizeof(PLMN_IdentityInfo_t));
-  memset(&schedulingInfo,0,sizeof(SchedulingInfo_t));
-  memset(&sib_type,0,sizeof(SIB_Type_t));
+  memset(PLMN_identity_info,0,num_plmn * sizeof(LTE_PLMN_IdentityInfo_t));
+  memset(&schedulingInfo,0,sizeof(LTE_SchedulingInfo_t));
+  memset(&sib_type,0,sizeof(LTE_SIB_Type_t));
 
   /* as per TS 36.311, up to 6 PLMN_identity_info are allowed in list -> add one by one */
-  for (i = 0; i < configuration->num_plmn; ++i) {
+  for (int i = 0; i < configuration->num_plmn; ++i) {
     PLMN_identity_info[i].plmn_Identity.mcc = CALLOC(1,sizeof(*PLMN_identity_info[i].plmn_Identity.mcc));
     memset(PLMN_identity_info[i].plmn_Identity.mcc,0,sizeof(*PLMN_identity_info[i].plmn_Identity.mcc));
-
     asn_set_empty(&PLMN_identity_info[i].plmn_Identity.mcc->list);//.size=0;
-
 #if defined(ENABLE_ITTI)
     dummy_mcc[i][0] = (configuration->mcc[i] / 100) % 10;
     dummy_mcc[i][1] = (configuration->mcc[i] / 10) % 10;
@@ -392,7 +384,6 @@ uint8_t do_SIB1(rrc_eNB_carrier_data_t *carrier,
     ASN_SEQUENCE_ADD(&PLMN_identity_info[i].plmn_Identity.mcc->list,&dummy_mcc[i][0]);
     ASN_SEQUENCE_ADD(&PLMN_identity_info[i].plmn_Identity.mcc->list,&dummy_mcc[i][1]);
     ASN_SEQUENCE_ADD(&PLMN_identity_info[i].plmn_Identity.mcc->list,&dummy_mcc[i][2]);
-
     PLMN_identity_info[i].plmn_Identity.mnc.list.size=0;
     PLMN_identity_info[i].plmn_Identity.mnc.list.count=0;
 #if defined(ENABLE_ITTI)
@@ -426,12 +417,10 @@ uint8_t do_SIB1(rrc_eNB_carrier_data_t *carrier,
     }
 
     //assign_enum(&PLMN_identity_info.cellReservedForOperatorUse,PLMN_IdentityInfo__cellReservedForOperatorUse_notReserved);
-    PLMN_identity_info[i].cellReservedForOperatorUse=PLMN_IdentityInfo__cellReservedForOperatorUse_notReserved;
-
+    PLMN_identity_info[i].cellReservedForOperatorUse=LTE_PLMN_IdentityInfo__cellReservedForOperatorUse_notReserved;
     ASN_SEQUENCE_ADD(&(*sib1)->cellAccessRelatedInfo.plmn_IdentityList.list,&PLMN_identity_info[i]);
   }
 
-
   // 16 bits
   (*sib1)->cellAccessRelatedInfo.trackingAreaCode.buf = MALLOC(2);
 #if defined(ENABLE_ITTI)
@@ -441,16 +430,15 @@ uint8_t do_SIB1(rrc_eNB_carrier_data_t *carrier,
   (*sib1)->cellAccessRelatedInfo.trackingAreaCode.buf[0] = 0x00;
   (*sib1)->cellAccessRelatedInfo.trackingAreaCode.buf[1] = 0x01;
 #endif
-  (*sib1)->cellAccessRelatedInfo.trackingAreaCode.size=2;
-  (*sib1)->cellAccessRelatedInfo.trackingAreaCode.bits_unused=0;
-
+  (*sib1)->cellAccessRelatedInfo.trackingAreaCode.size = 2;
+  (*sib1)->cellAccessRelatedInfo.trackingAreaCode.bits_unused = 0;
   // 28 bits
   (*sib1)->cellAccessRelatedInfo.cellIdentity.buf = MALLOC(8);
 #if defined(ENABLE_ITTI)
   (*sib1)->cellAccessRelatedInfo.cellIdentity.buf[0] = (configuration->cell_identity >> 20) & 0xff;
   (*sib1)->cellAccessRelatedInfo.cellIdentity.buf[1] = (configuration->cell_identity >> 12) & 0xff;
-  (*sib1)->cellAccessRelatedInfo.cellIdentity.buf[2] = (configuration->cell_identity >>  4) & 0xff;
-  (*sib1)->cellAccessRelatedInfo.cellIdentity.buf[3] = (configuration->cell_identity <<  4) & 0xf0;
+  (*sib1)->cellAccessRelatedInfo.cellIdentity.buf[2] = (configuration->cell_identity >> 4) & 0xff;
+  (*sib1)->cellAccessRelatedInfo.cellIdentity.buf[3] = (configuration->cell_identity << 4) & 0xf0;
 #else
   (*sib1)->cellAccessRelatedInfo.cellIdentity.buf[0] = 0x00;
   (*sib1)->cellAccessRelatedInfo.cellIdentity.buf[1] = 0x00;
@@ -459,89 +447,444 @@ uint8_t do_SIB1(rrc_eNB_carrier_data_t *carrier,
 #endif
   (*sib1)->cellAccessRelatedInfo.cellIdentity.size=4;
   (*sib1)->cellAccessRelatedInfo.cellIdentity.bits_unused=4;
-
   //  assign_enum(&(*sib1)->cellAccessRelatedInfo.cellBarred,SystemInformationBlockType1__cellAccessRelatedInfo__cellBarred_notBarred);
-  (*sib1)->cellAccessRelatedInfo.cellBarred=SystemInformationBlockType1__cellAccessRelatedInfo__cellBarred_notBarred;
-
+  (*sib1)->cellAccessRelatedInfo.cellBarred=LTE_SystemInformationBlockType1__cellAccessRelatedInfo__cellBarred_notBarred;
   //  assign_enum(&(*sib1)->cellAccessRelatedInfo.intraFreqReselection,SystemInformationBlockType1__cellAccessRelatedInfo__intraFreqReselection_allowed);
-  (*sib1)->cellAccessRelatedInfo.intraFreqReselection=SystemInformationBlockType1__cellAccessRelatedInfo__intraFreqReselection_notAllowed;
+  (*sib1)->cellAccessRelatedInfo.intraFreqReselection=LTE_SystemInformationBlockType1__cellAccessRelatedInfo__intraFreqReselection_notAllowed;
   (*sib1)->cellAccessRelatedInfo.csg_Indication=0;
-
   (*sib1)->cellSelectionInfo.q_RxLevMin=-65;
   (*sib1)->cellSelectionInfo.q_RxLevMinOffset=NULL;
   //(*sib1)->p_Max = CALLOC(1, sizeof(P_Max_t));
-  //*((*sib1)->p_Max) = 23;
+  // *((*sib1)->p_Max) = 23;
   (*sib1)->freqBandIndicator =
 #if defined(ENABLE_ITTI)
     configuration->eutra_band[CC_id];
 #else
-    7;
+  7;
 #endif
-
-  schedulingInfo.si_Periodicity=SchedulingInfo__si_Periodicity_rf8;
-
+  schedulingInfo.si_Periodicity=LTE_SchedulingInfo__si_Periodicity_rf8;
   // This is for SIB2/3
-  sib_type=SIB_Type_sibType3;
+  sib_type=LTE_SIB_Type_sibType3;
   ASN_SEQUENCE_ADD(&schedulingInfo.sib_MappingInfo.list,&sib_type);
   ASN_SEQUENCE_ADD(&(*sib1)->schedulingInfoList.list,&schedulingInfo);
-
   //  ASN_SEQUENCE_ADD(&schedulingInfo.sib_MappingInfo.list,NULL);
-
 #if defined(ENABLE_ITTI)
 
   if (configuration->frame_type[CC_id] == TDD)
 #endif
   {
-    (*sib1)->tdd_Config =                             CALLOC(1,sizeof(struct TDD_Config));
-
+    (*sib1)->tdd_Config =                             CALLOC(1,sizeof(struct LTE_TDD_Config));
     (*sib1)->tdd_Config->subframeAssignment =
 #if defined(ENABLE_ITTI)
-      configuration->tdd_config[CC_id];
+	configuration->tdd_config[CC_id];
 #else
-      3;
+      3; // +kogo this was frame_parms->tdd_config
 #endif
-
     (*sib1)->tdd_Config->specialSubframePatterns =
 #if defined(ENABLE_ITTI)
-      configuration->tdd_config_s[CC_id];
+	configuration->tdd_config_s[CC_id];
 #else
-    0;
+      0;
 #endif
-  }
+    }
 
-  (*sib1)->si_WindowLength=SystemInformationBlockType1__si_WindowLength_ms20;
-  (*sib1)->systemInfoValueTag=0;
-  //  (*sib1).nonCriticalExtension = calloc(1,sizeof(*(*sib1).nonCriticalExtension));
+  (*sib1)->si_WindowLength = LTE_SystemInformationBlockType1__si_WindowLength_ms20;
+  (*sib1)->systemInfoValueTag = 0;
 
-#ifdef XER_PRINT
-  xer_fprint(stdout, &asn_DEF_BCCH_DL_SCH_Message, (void*)bcch_message);
-#endif
-  enc_rval = uper_encode_to_buffer(&asn_DEF_BCCH_DL_SCH_Message,
-                                   NULL,
-                                   (void*)bcch_message,
-                                   buffer,
-                                   100);
-  AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
-               enc_rval.failed_type->name, enc_rval.encoded);
 
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  (*sib1)->nonCriticalExtension = calloc(1, sizeof(LTE_SystemInformationBlockType1_v890_IEs_t));
+
+  LTE_SystemInformationBlockType1_v890_IEs_t *sib1_890 = (*sib1)->nonCriticalExtension;
+  sib1_890->lateNonCriticalExtension = NULL;
+  sib1_890->nonCriticalExtension = calloc(1, sizeof(LTE_SystemInformationBlockType1_v920_IEs_t));
+  memset(sib1_890->nonCriticalExtension, 0, sizeof(LTE_SystemInformationBlockType1_v920_IEs_t));
+
+  LTE_SystemInformationBlockType1_v920_IEs_t *sib1_920 = (*sib1_890).nonCriticalExtension;
+  sib1_920->ims_EmergencySupport_r9 = NULL; // ptr
+  sib1_920->cellSelectionInfo_v920 = NULL;
+  sib1_920->nonCriticalExtension = calloc(1, sizeof(LTE_SystemInformationBlockType1_v1130_IEs_t));
+  memset(sib1_920->nonCriticalExtension, 0, sizeof(LTE_SystemInformationBlockType1_v1130_IEs_t));
+
+  //////Rel11
+  LTE_SystemInformationBlockType1_v1130_IEs_t *sib1_1130 = sib1_920->nonCriticalExtension;
+
+  sib1_1130->tdd_Config_v1130 = NULL; // ptr
+  sib1_1130->cellSelectionInfo_v1130 = NULL; // ptr
+  sib1_1130->nonCriticalExtension = calloc(1, sizeof(LTE_SystemInformationBlockType1_v1250_IEs_t));
+  memset(sib1_1130->nonCriticalExtension, 0, sizeof(LTE_SystemInformationBlockType1_v1250_IEs_t));
+
+  ///Rel12
+  LTE_SystemInformationBlockType1_v1250_IEs_t *sib1_1250 = sib1_1130->nonCriticalExtension;
+  sib1_1250->cellAccessRelatedInfo_v1250.category0Allowed_r12 = NULL; // long*
+  sib1_1250->cellSelectionInfo_v1250 = NULL;
+  sib1_1250->freqBandIndicatorPriority_r12 = 0; // long* // FIXME
+  sib1_1250->nonCriticalExtension = NULL;
+
+  ////Rel1310
 #if defined(ENABLE_ITTI)
-# if !defined(DISABLE_XER_SPRINT)
+  if ((configuration->schedulingInfoSIB1_BR_r13[CC_id] != 0) &&
+      (brOption==TRUE))
   {
-    char        message_string[10000];
-    size_t      message_string_size;
+      sib1_1250->nonCriticalExtension = calloc(1, sizeof(LTE_SystemInformationBlockType1_v1310_IEs_t));
+      memset(sib1_1250->nonCriticalExtension, 0, sizeof(LTE_SystemInformationBlockType1_v1310_IEs_t));
+      LTE_SystemInformationBlockType1_v1310_IEs_t *sib1_1310 = sib1_1250->nonCriticalExtension;
+
+
+      if (configuration->hyperSFN_r13[CC_id])
+      {
+          sib1_1310->hyperSFN_r13 = calloc(1, sizeof(BIT_STRING_t)); // type
+          memset(sib1_1310->hyperSFN_r13, 0, sizeof(BIT_STRING_t));
+          sib1_1310->hyperSFN_r13->buf = calloc(2, sizeof(uint8_t));
+          memmove(sib1_1310->hyperSFN_r13->buf, configuration->hyperSFN_r13[CC_id], 2 * sizeof(uint8_t));
+          sib1_1310->hyperSFN_r13->size = 2;
+          sib1_1310->hyperSFN_r13->bits_unused = 6;
+      }
+      else
+          sib1_1310->hyperSFN_r13 = NULL;
 
-    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_BCCH_DL_SCH_Message, (void *)bcch_message)) > 0) {
-      MessageDef *msg_p;
+      if (configuration->eDRX_Allowed_r13[CC_id])
+      {
+          sib1_1310->eDRX_Allowed_r13 = calloc(1, sizeof(long));
+          *sib1_1310->eDRX_Allowed_r13 = *configuration->eDRX_Allowed_r13[CC_id];
+      }
+      else
+          sib1_1310->eDRX_Allowed_r13 = NULL; // long*
+
+      if (configuration->cellSelectionInfoCE_r13[CC_id])
+      {
+          sib1_1310->cellSelectionInfoCE_r13 = calloc(1, sizeof(LTE_CellSelectionInfoCE_r13_t));
+          memset(sib1_1310->cellSelectionInfoCE_r13, 0, sizeof(LTE_CellSelectionInfoCE_r13_t));
+          sib1_1310->cellSelectionInfoCE_r13->q_RxLevMinCE_r13 = configuration->q_RxLevMinCE_r13[CC_id]; // (Q_RxLevMin_t) long
+          if (configuration->q_QualMinRSRQ_CE_r13[CC_id])
+          {
+              sib1_1310->cellSelectionInfoCE_r13->q_QualMinRSRQ_CE_r13 = calloc(1, sizeof(long));
+              *sib1_1310->cellSelectionInfoCE_r13->q_QualMinRSRQ_CE_r13 = *configuration->q_QualMinRSRQ_CE_r13[CC_id];
+          }
+          else
+              sib1_1310->cellSelectionInfoCE_r13->q_QualMinRSRQ_CE_r13 = NULL;
+      }
+      else
+          sib1_1310->cellSelectionInfoCE_r13 = NULL;
 
-      msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_BCCH, message_string_size + sizeof (IttiMsgText));
-      msg_p->ittiMsg.rrc_dl_bcch.size = message_string_size;
-      memcpy(&msg_p->ittiMsg.rrc_dl_bcch.text, message_string, message_string_size);
-      itti_send_msg_to_task(TASK_UNKNOWN, Mod_id, msg_p);
-    }
+      if (configuration->bandwidthReducedAccessRelatedInfo_r13[CC_id])
+      {
+
+
+          sib1_1310->bandwidthReducedAccessRelatedInfo_r13
+                  = calloc(1, sizeof(struct LTE_SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13));
+
+          LOG_I(RRC,"Allocating memory for BR access of SI (%p)\n",
+                sib1_1310->bandwidthReducedAccessRelatedInfo_r13);
+
+          sib1_1310->bandwidthReducedAccessRelatedInfo_r13->si_WindowLength_BR_r13
+                  = configuration->si_WindowLength_BR_r13[CC_id]; // 0
+
+
+          sib1_1310->bandwidthReducedAccessRelatedInfo_r13->si_RepetitionPattern_r13
+                  = configuration->si_RepetitionPattern_r13[CC_id]; // 0
+
+
+
+          sib1_1310->bandwidthReducedAccessRelatedInfo_r13->schedulingInfoList_BR_r13 = calloc(1, sizeof(LTE_SchedulingInfoList_BR_r13_t));
+
+          LTE_SchedulingInfo_BR_r13_t *schedulinginfo_br_13 = calloc(1, sizeof(LTE_SchedulingInfo_BR_r13_t));
+          memset(schedulinginfo_br_13, 0, sizeof(LTE_SchedulingInfo_BR_r13_t));
+
+          int num_sched_info_br = configuration->scheduling_info_br_size[CC_id];
+          int index;
+          for (index = 0; index < num_sched_info_br; ++index)
+          {
+
+              schedulinginfo_br_13->si_Narrowband_r13 = configuration->si_Narrowband_r13[CC_id][index];
+              schedulinginfo_br_13->si_TBS_r13 = configuration->si_TBS_r13[CC_id][index];
+              LOG_I(RRC,"Adding (%d,%d) to scheduling_info_br_13\n",(int)schedulinginfo_br_13->si_Narrowband_r13,(int)schedulinginfo_br_13->si_TBS_r13);
+              ASN_SEQUENCE_ADD(&sib1_1310->bandwidthReducedAccessRelatedInfo_r13->schedulingInfoList_BR_r13->list, schedulinginfo_br_13);
+          }
+
+
+          if (configuration->fdd_DownlinkOrTddSubframeBitmapBR_r13[CC_id])
+          {
+              sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_DownlinkOrTddSubframeBitmapBR_r13
+                  = calloc(1, sizeof(struct LTE_SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13__fdd_DownlinkOrTddSubframeBitmapBR_r13));
+              memset(sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_DownlinkOrTddSubframeBitmapBR_r13, 0,
+                 sizeof(sizeof(struct LTE_SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13__fdd_DownlinkOrTddSubframeBitmapBR_r13)));
+
+              if (*configuration->fdd_DownlinkOrTddSubframeBitmapBR_r13[CC_id])
+              {
+                  sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_DownlinkOrTddSubframeBitmapBR_r13->present
+                         = LTE_SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13__fdd_DownlinkOrTddSubframeBitmapBR_r13_PR_subframePattern10_r13;
+
+                  sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_DownlinkOrTddSubframeBitmapBR_r13->choice.subframePattern10_r13.buf = calloc(2, sizeof(uint8_t));
+                  memmove(sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_DownlinkOrTddSubframeBitmapBR_r13->choice.subframePattern10_r13.buf, &configuration->fdd_DownlinkOrTddSubframeBitmapBR_val_r13[CC_id], 2 * sizeof(uint8_t));
+                  sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_DownlinkOrTddSubframeBitmapBR_r13->choice.subframePattern10_r13.size = 2;
+                  sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_DownlinkOrTddSubframeBitmapBR_r13->choice.subframePattern10_r13.bits_unused = 6;
+              }
+              else
+              {
+                  sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_DownlinkOrTddSubframeBitmapBR_r13->present
+                        = LTE_SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13__fdd_DownlinkOrTddSubframeBitmapBR_r13_PR_subframePattern40_r13;
+
+                  sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_DownlinkOrTddSubframeBitmapBR_r13->choice.subframePattern40_r13.buf = calloc(5, sizeof(uint8_t));
+//                  memmove(sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_DownlinkOrTddSubframeBitmapBR_r13->choice.subframePattern40_r13.buf, &configuration->fdd_DownlinkOrTddSubframeBitmapBR_val_r13[CC_id], 5 * sizeof(uint8_t));
+                  int bm_index;
+                  for (bm_index = 0; bm_index < 5; bm_index++)
+                  {
+                      sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_DownlinkOrTddSubframeBitmapBR_r13->choice.subframePattern40_r13.buf[bm_index] = 0xFF;
+                  }
+                  sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_DownlinkOrTddSubframeBitmapBR_r13->choice.subframePattern40_r13.size = 5;
+                  sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_DownlinkOrTddSubframeBitmapBR_r13->choice.subframePattern40_r13.bits_unused = 0;
+              }
+
+          }
+          else
+          {
+              sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_DownlinkOrTddSubframeBitmapBR_r13 = NULL;
+          }
+
+          if (configuration->fdd_UplinkSubframeBitmapBR_r13[CC_id])
+          {
+              sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_UplinkSubframeBitmapBR_r13 = calloc(1, sizeof(BIT_STRING_t));
+              memset(sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_UplinkSubframeBitmapBR_r13, 0, sizeof(BIT_STRING_t));
+              sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_UplinkSubframeBitmapBR_r13->buf = calloc(2, sizeof(uint8_t));
+              memmove(sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_UplinkSubframeBitmapBR_r13->buf, configuration->fdd_UplinkSubframeBitmapBR_r13[CC_id],
+                  2 * sizeof(uint8_t));
+             sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_UplinkSubframeBitmapBR_r13->size = 2;
+             sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_UplinkSubframeBitmapBR_r13->bits_unused = 6;
+          }
+          else
+          {
+              sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_UplinkSubframeBitmapBR_r13 = NULL;
+          }
+
+
+          sib1_1310->bandwidthReducedAccessRelatedInfo_r13->startSymbolBR_r13 = configuration->startSymbolBR_r13[CC_id];
+          sib1_1310->bandwidthReducedAccessRelatedInfo_r13->si_HoppingConfigCommon_r13
+                  = configuration->si_HoppingConfigCommon_r13[CC_id];
+
+          if (configuration->si_ValidityTime_r13[CC_id])
+          {
+              sib1_1310->bandwidthReducedAccessRelatedInfo_r13->si_ValidityTime_r13 = calloc(1, sizeof(long));
+              memset(sib1_1310->bandwidthReducedAccessRelatedInfo_r13->si_ValidityTime_r13, 0, sizeof(long));
+              *sib1_1310->bandwidthReducedAccessRelatedInfo_r13->si_ValidityTime_r13 = *configuration->si_ValidityTime_r13[CC_id];
+
+          }
+          else
+          {
+              sib1_1310->bandwidthReducedAccessRelatedInfo_r13->si_ValidityTime_r13 = NULL;
+          }
+
+
+          LTE_SystemInfoValueTagSI_r13_t *systemInfoValueTagSi_r13;
+          int num_system_info_value_tag = configuration->system_info_value_tag_SI_size[CC_id];
+          if (num_system_info_value_tag > 0)
+          {
+              sib1_1310->bandwidthReducedAccessRelatedInfo_r13->systemInfoValueTagList_r13 = calloc(1, sizeof(LTE_SystemInfoValueTagList_r13_t));
+              for (index = 0; index < num_system_info_value_tag; ++index)
+              {
+                  systemInfoValueTagSi_r13 = CALLOC(1, sizeof(LTE_SystemInfoValueTagSI_r13_t));
+                  if (configuration->systemInfoValueTagSi_r13[CC_id][index])
+                  {
+                      *systemInfoValueTagSi_r13 = configuration->systemInfoValueTagSi_r13[CC_id][index];
+                  }
+                  else
+                  {
+                      *systemInfoValueTagSi_r13 = 0;
+                  }
+                  ASN_SEQUENCE_ADD(&sib1_1310->bandwidthReducedAccessRelatedInfo_r13->systemInfoValueTagList_r13->list, systemInfoValueTagSi_r13);
+              }
+
+          }
+          else
+          {
+              sib1_1310->bandwidthReducedAccessRelatedInfo_r13->systemInfoValueTagList_r13 = NULL;
+          }
+
+      }
+      else
+      {
+          sib1_1310->bandwidthReducedAccessRelatedInfo_r13 = NULL;
+      }
+
+      sib1_1310->nonCriticalExtension = calloc(1, sizeof(LTE_SystemInformationBlockType1_v1320_IEs_t));
+      memset(sib1_1310->nonCriticalExtension, 0, sizeof(LTE_SystemInformationBlockType1_v1320_IEs_t));
+
+      /////Rel1320
+      LTE_SystemInformationBlockType1_v1320_IEs_t *sib1_1320 = sib1_1310->nonCriticalExtension;
+
+
+
+      if (configuration->freqHoppingParametersDL_r13[CC_id])
+      {
+          sib1_1320->freqHoppingParametersDL_r13 = calloc(1, sizeof(struct LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13));
+          memset(sib1_1320->freqHoppingParametersDL_r13, 0, sizeof(struct LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13));
+
+
+          if (configuration->mpdcch_pdsch_HoppingNB_r13[CC_id])
+          {
+              sib1_1320->freqHoppingParametersDL_r13->mpdcch_pdsch_HoppingNB_r13 = calloc(1, sizeof(long));
+              *sib1_1320->freqHoppingParametersDL_r13->mpdcch_pdsch_HoppingNB_r13 = *configuration->mpdcch_pdsch_HoppingNB_r13[CC_id];
+          }
+          else
+              sib1_1320->freqHoppingParametersDL_r13->mpdcch_pdsch_HoppingNB_r13 = NULL;
+
+          sib1_1320->freqHoppingParametersDL_r13->interval_DLHoppingConfigCommonModeA_r13 = calloc(1, sizeof(struct LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13__interval_DLHoppingConfigCommonModeA_r13));
+          memset(sib1_1320->freqHoppingParametersDL_r13->interval_DLHoppingConfigCommonModeA_r13, 0, sizeof(struct LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13__interval_DLHoppingConfigCommonModeA_r13));
+
+          if (configuration->interval_DLHoppingConfigCommonModeA_r13[CC_id])
+          {
+              sib1_1320->freqHoppingParametersDL_r13->interval_DLHoppingConfigCommonModeA_r13->present = LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13__interval_DLHoppingConfigCommonModeA_r13_PR_interval_FDD_r13;
+              sib1_1320->freqHoppingParametersDL_r13->interval_DLHoppingConfigCommonModeA_r13->choice.interval_FDD_r13 = configuration->interval_DLHoppingConfigCommonModeA_r13_val[CC_id];
+          }
+          else
+          {
+              sib1_1320->freqHoppingParametersDL_r13->interval_DLHoppingConfigCommonModeA_r13->present = LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13__interval_DLHoppingConfigCommonModeA_r13_PR_interval_TDD_r13;
+              sib1_1320->freqHoppingParametersDL_r13->interval_DLHoppingConfigCommonModeA_r13->choice.interval_TDD_r13 = configuration->interval_DLHoppingConfigCommonModeA_r13_val[CC_id];
+          }
+
+          sib1_1320->freqHoppingParametersDL_r13->interval_DLHoppingConfigCommonModeB_r13 = calloc(1, sizeof(struct LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13__interval_DLHoppingConfigCommonModeB_r13));
+          memset(sib1_1320->freqHoppingParametersDL_r13->interval_DLHoppingConfigCommonModeB_r13, 0, sizeof(struct LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13__interval_DLHoppingConfigCommonModeB_r13));
+
+          if (configuration->interval_DLHoppingConfigCommonModeB_r13[CC_id])
+          {
+              sib1_1320->freqHoppingParametersDL_r13->interval_DLHoppingConfigCommonModeB_r13->present = LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13__interval_DLHoppingConfigCommonModeB_r13_PR_interval_FDD_r13;
+              sib1_1320->freqHoppingParametersDL_r13->interval_DLHoppingConfigCommonModeB_r13->choice.interval_FDD_r13 = configuration->interval_DLHoppingConfigCommonModeB_r13_val[CC_id];
+          }
+          else
+          {
+              sib1_1320->freqHoppingParametersDL_r13->interval_DLHoppingConfigCommonModeB_r13->present = LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13__interval_DLHoppingConfigCommonModeB_r13_PR_interval_TDD_r13;
+              sib1_1320->freqHoppingParametersDL_r13->interval_DLHoppingConfigCommonModeB_r13->choice.interval_TDD_r13 = configuration->interval_DLHoppingConfigCommonModeB_r13_val[CC_id];
+          }
+
+          if (configuration->mpdcch_pdsch_HoppingOffset_r13[CC_id])
+          {
+
+              sib1_1320->freqHoppingParametersDL_r13->mpdcch_pdsch_HoppingOffset_r13 = calloc(1, sizeof(long));
+              *sib1_1320->freqHoppingParametersDL_r13->mpdcch_pdsch_HoppingOffset_r13 = *configuration->mpdcch_pdsch_HoppingOffset_r13[CC_id];
+          }
+          else
+              sib1_1320->freqHoppingParametersDL_r13->mpdcch_pdsch_HoppingOffset_r13 = NULL;
+
+      }
+      else
+          sib1_1320->freqHoppingParametersDL_r13 = NULL;
+
+      sib1_1320->nonCriticalExtension = NULL;
   }
-# endif
+#else
+  sib1_1250->nonCriticalExtension = calloc(1, sizeof(LTE_SystemInformationBlockType1_v1310_IEs_t));
+  memset(sib1_1250->nonCriticalExtension, 0, sizeof(LTE_SystemInformationBlockType1_v1310_IEs_t));
+  SystemInformationBlockType1_v1310_IEs_t *sib1_1310 = sib1_1250->nonCriticalExtension;
+
+  sib1_1310->hyperSFN_r13 = calloc(1, sizeof(BIT_STRING_t)); // type
+  memset(sib1_1310->hyperSFN_r13, 0, sizeof(BIT_STRING_t));
+  sib1_1310->hyperSFN_r13->buf = calloc(2, sizeof(uint8_t));
+  memset(sib1_1310->hyperSFN_r13->buf, 0, 2*sizeof(uint8_t));
+  sib1_1310->hyperSFN_r13->size = 2;
+  sib1_1310->hyperSFN_r13->bits_unused = 6;
+
+  sib1_1310->eDRX_Allowed_r13 = NULL; // long*
+  sib1_1310->cellSelectionInfoCE_r13 = calloc(1, sizeof(LTE_CellSelectionInfoCE_r13_t));
+  memset(sib1_1310->cellSelectionInfoCE_r13, 0, sizeof(LTE_CellSelectionInfoCE_r13_t));
+  sib1_1310->cellSelectionInfoCE_r13->q_RxLevMinCE_r13 = -70; // (Q_RxLevMin_t) long
+  sib1_1310->cellSelectionInfoCE_r13->q_QualMinRSRQ_CE_r13 = NULL; // (Q_RxLevMin_t) *long
+
+  sib1_1310->bandwidthReducedAccessRelatedInfo_r13
+    = calloc(1, sizeof(struct LTE_SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13));
+
+  sib1_1310->bandwidthReducedAccessRelatedInfo_r13->si_WindowLength_BR_r13
+    = LTE_SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13__si_WindowLength_BR_r13_ms20; // 0
+
+
+  sib1_1310->bandwidthReducedAccessRelatedInfo_r13->si_RepetitionPattern_r13
+    = LTE_SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13__si_RepetitionPattern_r13_everyRF; // 0
+
+  sib1_1310->bandwidthReducedAccessRelatedInfo_r13->schedulingInfoList_BR_r13 = calloc(1, sizeof(LTE_SchedulingInfoList_BR_r13_t));
+  SchedulingInfo_BR_r13_t *schedulinginfo_br_13 = calloc(1, sizeof(LTE_SchedulingInfo_BR_r13_t));
+  memset(schedulinginfo_br_13, 0, sizeof(LTE_SchedulingInfo_BR_r13_t));
+  schedulinginfo_br_13->si_Narrowband_r13 = 1;
+  schedulinginfo_br_13->si_TBS_r13 = LTE_SchedulingInfo_BR_r13__si_TBS_r13_b152;
+  ASN_SEQUENCE_ADD(&sib1_1310->bandwidthReducedAccessRelatedInfo_r13->schedulingInfoList_BR_r13->list, schedulinginfo_br_13);
+
+  sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_DownlinkOrTddSubframeBitmapBR_r13
+    = calloc(1, sizeof(struct LTE_SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13__fdd_DownlinkOrTddSubframeBitmapBR_r13));
+  memset(sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_DownlinkOrTddSubframeBitmapBR_r13, 0,
+	 sizeof(sizeof(struct LTE_SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13__fdd_DownlinkOrTddSubframeBitmapBR_r13)));
+
+  sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_DownlinkOrTddSubframeBitmapBR_r13->present
+    = LTE_SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13__fdd_DownlinkOrTddSubframeBitmapBR_r13_PR_subframePattern10_r13;
+  sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_DownlinkOrTddSubframeBitmapBR_r13->choice.subframePattern10_r13.buf = calloc(2, sizeof(uint8_t));
+  memset(sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_DownlinkOrTddSubframeBitmapBR_r13->choice.subframePattern10_r13.buf, 0, 2 * sizeof(uint8_t));
+  sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_DownlinkOrTddSubframeBitmapBR_r13->choice.subframePattern10_r13.size = 2;
+  sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_DownlinkOrTddSubframeBitmapBR_r13->choice.subframePattern10_r13.bits_unused = 6;
+
+  sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_UplinkSubframeBitmapBR_r13 = calloc(1, sizeof(BIT_STRING_t));
+  memset(sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_UplinkSubframeBitmapBR_r13, 0, sizeof(BIT_STRING_t));
+  sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_UplinkSubframeBitmapBR_r13->buf = calloc(2, sizeof(uint8_t));
+  memset(sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_UplinkSubframeBitmapBR_r13->buf, 0,
+	 2 * sizeof(uint8_t));
+  sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_UplinkSubframeBitmapBR_r13->size = 2;
+  sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_UplinkSubframeBitmapBR_r13->bits_unused = 6;
+  sib1_1310->bandwidthReducedAccessRelatedInfo_r13->startSymbolBR_r13 = 1;
+  sib1_1310->bandwidthReducedAccessRelatedInfo_r13->si_HoppingConfigCommon_r13
+    = LTE_SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13__si_HoppingConfigCommon_r13_on;
+
+  sib1_1310->bandwidthReducedAccessRelatedInfo_r13->si_ValidityTime_r13 = calloc(1, sizeof(long));
+  memset(sib1_1310->bandwidthReducedAccessRelatedInfo_r13->si_ValidityTime_r13, 0, sizeof(long));
+  *sib1_1310->bandwidthReducedAccessRelatedInfo_r13->si_ValidityTime_r13
+    = LTE_SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13__si_ValidityTime_r13_true;
+
+
+  sib1_1310->bandwidthReducedAccessRelatedInfo_r13->systemInfoValueTagList_r13 = calloc(1, sizeof(LTE_SystemInfoValueTagList_r13_t));
+  LTE_SystemInfoValueTagSI_r13_t *systemInfoValueTagSi_r13 = CALLOC(1, sizeof(LTE_SystemInfoValueTagSI_r13_t));
+  *systemInfoValueTagSi_r13 = 0;
+  ASN_SEQUENCE_ADD(&sib1_1310->bandwidthReducedAccessRelatedInfo_r13->systemInfoValueTagList_r13->list, systemInfoValueTagSi_r13);
+
+  sib1_1310->nonCriticalExtension = calloc(1, sizeof(LTE_SystemInformationBlockType1_v1320_IEs_t));
+  memset(sib1_1310->nonCriticalExtension, 0, sizeof(LTE_SystemInformationBlockType1_v1320_IEs_t));
+
+  /////Rel1320
+  LTE_SystemInformationBlockType1_v1320_IEs_t *sib1_1320 = sib1_1310->nonCriticalExtension;
+  sib1_1320->freqHoppingParametersDL_r13 = calloc(1, sizeof(struct LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13));
+  memset(sib1_1320->freqHoppingParametersDL_r13, 0, sizeof(struct LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13));
+
+  sib1_1320->freqHoppingParametersDL_r13->mpdcch_pdsch_HoppingNB_r13 = calloc(1, sizeof(long));
+  *sib1_1320->freqHoppingParametersDL_r13->mpdcch_pdsch_HoppingNB_r13 = LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13__mpdcch_pdsch_HoppingNB_r13_nb2;
+
+
+  sib1_1320->freqHoppingParametersDL_r13->interval_DLHoppingConfigCommonModeA_r13 = calloc(1, sizeof(struct LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13__interval_DLHoppingConfigCommonModeA_r13));
+  memset(sib1_1320->freqHoppingParametersDL_r13->interval_DLHoppingConfigCommonModeA_r13, 0, sizeof(struct LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13__interval_DLHoppingConfigCommonModeA_r13));
+  sib1_1320->freqHoppingParametersDL_r13->interval_DLHoppingConfigCommonModeA_r13->present = LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13__interval_DLHoppingConfigCommonModeA_r13_PR_interval_FDD_r13;
+  sib1_1320->freqHoppingParametersDL_r13->interval_DLHoppingConfigCommonModeA_r13->choice.interval_FDD_r13 = LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13__interval_DLHoppingConfigCommonModeA_r13__interval_FDD_r13_int1;
+
+  sib1_1320->freqHoppingParametersDL_r13->interval_DLHoppingConfigCommonModeB_r13 = calloc(1, sizeof(struct LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13__interval_DLHoppingConfigCommonModeB_r13));
+  memset(sib1_1320->freqHoppingParametersDL_r13->interval_DLHoppingConfigCommonModeB_r13, 0, sizeof(struct LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13__interval_DLHoppingConfigCommonModeB_r13));
+  sib1_1320->freqHoppingParametersDL_r13->interval_DLHoppingConfigCommonModeB_r13->present = LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13__interval_DLHoppingConfigCommonModeB_r13_PR_interval_FDD_r13;
+  sib1_1320->freqHoppingParametersDL_r13->interval_DLHoppingConfigCommonModeB_r13->choice.interval_FDD_r13 = LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13__interval_DLHoppingConfigCommonModeB_r13__interval_FDD_r13_int2;
+
+
+  sib1_1320->freqHoppingParametersDL_r13->mpdcch_pdsch_HoppingOffset_r13 = calloc(1, sizeof(long));
+  *sib1_1320->freqHoppingParametersDL_r13->mpdcch_pdsch_HoppingOffset_r13 = 1;
+
+  sib1_1320->nonCriticalExtension = NULL;
+#endif
 #endif
 
+  (*sib1)->si_WindowLength=LTE_SystemInformationBlockType1__si_WindowLength_ms20;
+  (*sib1)->systemInfoValueTag=0;
+  //  (*sib1).nonCriticalExtension = calloc(1,sizeof(*(*sib1).nonCriticalExtension));
+
+  if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
+    xer_fprint(stdout, &asn_DEF_LTE_BCCH_DL_SCH_Message, (void *)bcch_message);
+  }
+
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_BCCH_DL_SCH_Message,
+                                   NULL,
+                                   (void *)bcch_message,
+                                   buffer,
+                                   100);
+  AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
+               enc_rval.failed_type->name, enc_rval.encoded);
   LOG_D(RRC,"[eNB] SystemInformationBlockType1 Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
 
   if (enc_rval.encoded==-1) {
@@ -551,55 +894,75 @@ uint8_t do_SIB1(rrc_eNB_carrier_data_t *carrier,
   return((enc_rval.encoded+7)/8);
 }
 
+
+
+
+
 uint8_t do_SIB23(uint8_t Mod_id,
 
-                 int CC_id
+		 int CC_id
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+		 , BOOLEAN_t brOption
+#endif
 #if defined(ENABLE_ITTI)
-                 , RrcConfigurationReq *configuration
+		 , RrcConfigurationReq *configuration
 #endif
-                )
-{
-
-  struct SystemInformation_r8_IEs__sib_TypeAndInfo__Member *sib2_part,*sib3_part;
-
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-  //TTN - for D2D
-  struct SystemInformation_r8_IEs__sib_TypeAndInfo__Member *sib18_part, *sib19_part, *sib21_part;
-  SL_CommRxPoolList_r12_t *SL_CommRxPoolList; //for SIB18
-  struct SL_CommResourcePool_r12 *SL_CommResourcePool; //for SIB18
-  SL_DiscRxPoolList_r12_t *SL_DiscRxPoolList; //for SIB19 (discRxPool)
-  struct SL_DiscResourcePool_r12 *SL_DiscResourcePool; //for SIB19 (discRxPool)
+		 ) {
+  struct LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member *sib2_part,*sib3_part;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+
+  int eMTC_configured=configuration->eMTC_configured;
+  struct LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member *sib18_part, *sib19_part, *sib21_part;
+  LTE_SL_CommRxPoolList_r12_t *SL_CommRxPoolList; //for SIB18
+  struct LTE_SL_CommResourcePool_r12 *SL_CommResourcePool; //for SIB18
+  LTE_SL_DiscRxPoolList_r12_t *SL_DiscRxPoolList; //for SIB19 (discRxPool)
+  struct LTE_SL_DiscResourcePool_r12 *SL_DiscResourcePool; //for SIB19 (discRxPool)
   //SL_DiscRxPoolList_r12_t *SL_DiscRxPoolPSList; //for SIB19 (discRxPoolPS)
   //struct SL_DiscResourcePool_r12 *SL_DiscResourcePoolPS; //for SIB19 (discRxPoolPS)
   //struct SL_V2X_ConfigCommon_r14 *SL_V2X_ConfigCommon;
 #endif
-
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-  struct SystemInformation_r8_IEs__sib_TypeAndInfo__Member *sib13_part;
-  MBSFN_SubframeConfigList_t *MBSFNSubframeConfigList;
-  MBSFN_AreaInfoList_r9_t *MBSFNArea_list;
-  struct MBSFN_AreaInfo_r9 *MBSFN_Area1, *MBSFN_Area2;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+  struct LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member *sib13_part=NULL;
+  LTE_MBSFN_SubframeConfigList_t *MBSFNSubframeConfigList;
+  LTE_MBSFN_AreaInfoList_r9_t *MBSFNArea_list;
+  struct LTE_MBSFN_AreaInfo_r9 *MBSFN_Area1, *MBSFN_Area2;
 #endif
   asn_enc_rval_t enc_rval;
 
-  uint8_t                           *buffer       = RC.rrc[Mod_id]->carrier[CC_id].SIB23;
-  BCCH_DL_SCH_Message_t             *bcch_message = &RC.rrc[Mod_id]->carrier[CC_id].systemInformation;
-  SystemInformationBlockType2_t     **sib2        = &RC.rrc[Mod_id]->carrier[CC_id].sib2;
-  SystemInformationBlockType3_t     **sib3        = &RC.rrc[Mod_id]->carrier[CC_id].sib3;
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-  SystemInformationBlockType13_r9_t **sib13       = &RC.rrc[Mod_id]->carrier[CC_id].sib13;
-  uint8_t                           MBMS_flag     = RC.rrc[Mod_id]->carrier[CC_id].MBMS_flag;
+
+  LTE_BCCH_DL_SCH_Message_t         *bcch_message = &RC.rrc[Mod_id]->carrier[CC_id].systemInformation;
+  uint8_t                       *buffer;
+  LTE_SystemInformationBlockType2_t **sib2;
+  RadioResourceConfig           *rrconfig;
+
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  if (brOption) {
+    buffer   = RC.rrc[Mod_id]->carrier[CC_id].SIB23_BR;
+    sib2     = &RC.rrc[Mod_id]->carrier[CC_id].sib2_BR;
+    rrconfig = &configuration->radioresourceconfig_BR[CC_id];
+    LOG_I(RRC,"Running SIB2/3 Encoding for eMTC\n");
+  }
+  else
 #endif
+    {
+      buffer   = RC.rrc[Mod_id]->carrier[CC_id].SIB23;
+      sib2     = &RC.rrc[Mod_id]->carrier[CC_id].sib2;
+      rrconfig = &configuration->radioresourceconfig[CC_id];
+    }
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+  LTE_SystemInformationBlockType3_t       **sib3        = &RC.rrc[Mod_id]->carrier[CC_id].sib3;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+  LTE_SystemInformationBlockType13_r9_t   **sib13       = &RC.rrc[Mod_id]->carrier[CC_id].sib13;
+#endif
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
   //TTN - for D2D
-  SystemInformationBlockType18_r12_t     **sib18        = &RC.rrc[Mod_id]->carrier[CC_id].sib18;
-  SystemInformationBlockType19_r12_t     **sib19        = &RC.rrc[Mod_id]->carrier[CC_id].sib19;
-  SystemInformationBlockType21_r14_t     **sib21        = &RC.rrc[Mod_id]->carrier[CC_id].sib21;
+  LTE_SystemInformationBlockType18_r12_t     **sib18        = &RC.rrc[Mod_id]->carrier[CC_id].sib18;
+  LTE_SystemInformationBlockType19_r12_t     **sib19        = &RC.rrc[Mod_id]->carrier[CC_id].sib19;
+  LTE_SystemInformationBlockType21_r14_t     **sib21        = &RC.rrc[Mod_id]->carrier[CC_id].sib21;
 #endif
 
   if (bcch_message) {
-    memset(bcch_message,0,sizeof(BCCH_DL_SCH_Message_t));
+    memset(bcch_message,0,sizeof(LTE_BCCH_DL_SCH_Message_t));
   } else {
     LOG_E(RRC,"[eNB %d] BCCH_MESSAGE is null, exiting\n", Mod_id);
     exit(-1);
@@ -615,335 +978,648 @@ uint8_t do_SIB23(uint8_t Mod_id,
     exit(-1);
   }
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-  LOG_I(RRC,"[eNB %d] Configuration SIB2/3, MBMS = %d\n", Mod_id, MBMS_flag);
+
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+  LOG_I(RRC,"[eNB %d] Configuration SIB2/3, eMBMS = %d\n", Mod_id, configuration->eMBMS_configured);
 #else
   LOG_I(RRC,"[eNB %d] Configuration SIB2/3\n", Mod_id);
 #endif
-  sib2_part = CALLOC(1,sizeof(struct SystemInformation_r8_IEs__sib_TypeAndInfo__Member));
-  sib3_part = CALLOC(1,sizeof(struct SystemInformation_r8_IEs__sib_TypeAndInfo__Member));
-  memset(sib2_part,0,sizeof(struct SystemInformation_r8_IEs__sib_TypeAndInfo__Member));
-  memset(sib3_part,0,sizeof(struct SystemInformation_r8_IEs__sib_TypeAndInfo__Member));
-
-  sib2_part->present = SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib2;
-  sib3_part->present = SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib3;
-
+  sib2_part = CALLOC(1,sizeof(struct LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member));
+  sib3_part = CALLOC(1,sizeof(struct LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member));
+  memset(sib2_part,0,sizeof(struct LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member));
+  memset(sib3_part,0,sizeof(struct LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member));
+  sib2_part->present = LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib2;
+  sib3_part->present = LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib3;
   *sib2 = &sib2_part->choice.sib2;
   *sib3 = &sib3_part->choice.sib3;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-
-  if (MBMS_flag > 0) {
-    sib13_part = CALLOC(1,sizeof(struct SystemInformation_r8_IEs__sib_TypeAndInfo__Member));
-    memset(sib13_part,0,sizeof(struct SystemInformation_r8_IEs__sib_TypeAndInfo__Member));
-    sib13_part->present = SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib13_v920;
+  if ((configuration->eMBMS_configured > 0) && (brOption==FALSE)) {
+    sib13_part = CALLOC(1,sizeof(struct LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member));
+    memset(sib13_part,0,sizeof(struct LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member));
+    sib13_part->present = LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib13_v920;
     *sib13 = &sib13_part->choice.sib13_v920;
   }
 
 #endif
-
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  if (configuration->SL_configured > 0) {
   //TTN - for D2D
-  sib18_part = CALLOC(1,sizeof(struct SystemInformation_r8_IEs__sib_TypeAndInfo__Member));
-  sib19_part = CALLOC(1,sizeof(struct SystemInformation_r8_IEs__sib_TypeAndInfo__Member));
-  sib21_part = CALLOC(1,sizeof(struct SystemInformation_r8_IEs__sib_TypeAndInfo__Member));
-  memset(sib18_part,0,sizeof(struct SystemInformation_r8_IEs__sib_TypeAndInfo__Member));
-  memset(sib19_part,0,sizeof(struct SystemInformation_r8_IEs__sib_TypeAndInfo__Member));
-  memset(sib21_part,0,sizeof(struct SystemInformation_r8_IEs__sib_TypeAndInfo__Member));
-
-  sib18_part->present = SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib18_v1250;
-  sib19_part->present = SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib19_v1250;
-  sib21_part->present = SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib21_v1430;
-
-  *sib18 = &sib18_part->choice.sib18_v1250;
-  *sib19 = &sib19_part->choice.sib19_v1250;
-  *sib21 = &sib21_part->choice.sib21_v1430;
-
+    sib18_part = CALLOC(1,sizeof(struct LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member));
+    sib19_part = CALLOC(1,sizeof(struct LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member));
+    sib21_part = CALLOC(1,sizeof(struct LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member));
+    memset(sib18_part,0,sizeof(struct LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member));
+    memset(sib19_part,0,sizeof(struct LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member));
+    memset(sib21_part,0,sizeof(struct LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member));
+
+    sib18_part->present = LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib18_v1250;
+    sib19_part->present = LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib19_v1250;
+    sib21_part->present = LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib21_v1430;
+
+    *sib18 = &sib18_part->choice.sib18_v1250;
+    *sib19 = &sib19_part->choice.sib19_v1250;
+    *sib21 = &sib21_part->choice.sib21_v1430;
+  }
 #endif
-
-
   // sib2
-
   (*sib2)->ac_BarringInfo = NULL;
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
   (*sib2)->ext1 = NULL;
   (*sib2)->ext2 = NULL;
 #endif
-
 #if defined(ENABLE_ITTI)
-
-  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.numberOfRA_Preambles                         = configuration->rach_numberOfRA_Preambles[CC_id];
+  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.numberOfRA_Preambles                         = rrconfig->rach_numberOfRA_Preambles;
   (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.preamblesGroupAConfig                        = NULL;
 
-  if (configuration->rach_preamblesGroupAConfig[CC_id]) {
+  if (rrconfig->rach_preamblesGroupAConfig) {
     (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.preamblesGroupAConfig
-      = CALLOC(1,sizeof(struct RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig));
+      = CALLOC(1,sizeof(struct LTE_RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig));
     (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.preamblesGroupAConfig->sizeOfRA_PreamblesGroupA
-      = configuration->rach_sizeOfRA_PreamblesGroupA[CC_id];
+      = rrconfig->rach_sizeOfRA_PreamblesGroupA;
     (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.preamblesGroupAConfig->messageSizeGroupA
-      = configuration->rach_messageSizeGroupA[CC_id];
+      = rrconfig->rach_messageSizeGroupA;
     (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.preamblesGroupAConfig->messagePowerOffsetGroupB
-      = configuration->rach_messagePowerOffsetGroupB[CC_id];
+      = rrconfig->rach_messagePowerOffsetGroupB;
+  }
+
+  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.powerRampingParameters.powerRampingStep                   = rrconfig->rach_powerRampingStep;
+  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.powerRampingParameters.preambleInitialReceivedTargetPower = rrconfig->rach_preambleInitialReceivedTargetPower;
+  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.preambleTransMax                       = rrconfig->rach_preambleTransMax;
+  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.ra_ResponseWindowSize                  = rrconfig->rach_raResponseWindowSize;
+  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.mac_ContentionResolutionTimer          = rrconfig->rach_macContentionResolutionTimer;
+  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.maxHARQ_Msg3Tx                                            = rrconfig->rach_maxHARQ_Msg3Tx;
+
+  if (eMTC_configured>0) {
+    (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ext1 = calloc(1, sizeof(struct LTE_RACH_ConfigCommon__ext1));
+    memset((*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ext1, 0, sizeof(struct LTE_RACH_ConfigCommon__ext1));
+
+    if (rrconfig->preambleTransMax_CE_r13) {
+      (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ext1->preambleTransMax_CE_r13 = calloc(1, sizeof(LTE_PreambleTransMax_t));
+      *(*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ext1->preambleTransMax_CE_r13 = *rrconfig->preambleTransMax_CE_r13; // to be re-initialized when we find the enum
+    }
+    else (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ext1->preambleTransMax_CE_r13 = NULL;
+
+
+    (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ext1->rach_CE_LevelInfoList_r13 = calloc(1, sizeof(LTE_RACH_CE_LevelInfoList_r13_t));
+    memset((*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ext1->rach_CE_LevelInfoList_r13, 0, sizeof(LTE_RACH_CE_LevelInfoList_r13_t));
+
+    LTE_RACH_CE_LevelInfo_r13_t *rach_ce_levelinfo_r13;
+    int num_rach_ce_level_info = configuration->rach_CE_LevelInfoList_r13_size[CC_id];
+    int index;
+    for (index = 0; index < num_rach_ce_level_info; ++index) {
+      rach_ce_levelinfo_r13 = calloc(1, sizeof(LTE_RACH_CE_LevelInfo_r13_t));
+      if (configuration->rach_CE_LevelInfoList_r13_size[CC_id]) {
+          rach_ce_levelinfo_r13->preambleMappingInfo_r13.firstPreamble_r13 = configuration->firstPreamble_r13[CC_id][index];
+          rach_ce_levelinfo_r13->preambleMappingInfo_r13.lastPreamble_r13  = configuration->lastPreamble_r13[CC_id][index];
+          rach_ce_levelinfo_r13->ra_ResponseWindowSize_r13                 = configuration->ra_ResponseWindowSize_r13[CC_id][index];
+          rach_ce_levelinfo_r13->mac_ContentionResolutionTimer_r13         = configuration->mac_ContentionResolutionTimer_r13[CC_id][index];
+          rach_ce_levelinfo_r13->rar_HoppingConfig_r13                     = configuration->rar_HoppingConfig_r13[CC_id][index];
+      }
+      else
+      {
+          rach_ce_levelinfo_r13->preambleMappingInfo_r13.firstPreamble_r13 = 0;
+          rach_ce_levelinfo_r13->preambleMappingInfo_r13.lastPreamble_r13 = 63;
+          rach_ce_levelinfo_r13->ra_ResponseWindowSize_r13 = LTE_RACH_CE_LevelInfo_r13__ra_ResponseWindowSize_r13_sf80;
+          rach_ce_levelinfo_r13->mac_ContentionResolutionTimer_r13 = LTE_RACH_CE_LevelInfo_r13__mac_ContentionResolutionTimer_r13_sf200;
+          rach_ce_levelinfo_r13->rar_HoppingConfig_r13 = LTE_RACH_CE_LevelInfo_r13__rar_HoppingConfig_r13_off;
+      }
+      ASN_SEQUENCE_ADD(&(*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ext1->rach_CE_LevelInfoList_r13->list, rach_ce_levelinfo_r13);
+    }
   }
 
-  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.powerRampingParameters.powerRampingStep                   = configuration->rach_powerRampingStep[CC_id];
-  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.powerRampingParameters.preambleInitialReceivedTargetPower =
-    configuration->rach_preambleInitialReceivedTargetPower[CC_id];
-  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.preambleTransMax                       = configuration->rach_preambleTransMax[CC_id];
-  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.ra_ResponseWindowSize                  = configuration->rach_raResponseWindowSize[CC_id];
-  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.mac_ContentionResolutionTimer          =
-    configuration->rach_macContentionResolutionTimer[CC_id];
-  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.maxHARQ_Msg3Tx                                            = configuration->rach_maxHARQ_Msg3Tx[CC_id];
 
   // BCCH-Config
   (*sib2)->radioResourceConfigCommon.bcch_Config.modificationPeriodCoeff
-    = configuration->bcch_modificationPeriodCoeff[CC_id];
-
+    = rrconfig->bcch_modificationPeriodCoeff;
   // PCCH-Config
   (*sib2)->radioResourceConfigCommon.pcch_Config.defaultPagingCycle
-    = configuration->pcch_defaultPagingCycle[CC_id];
+    = rrconfig->pcch_defaultPagingCycle;
   (*sib2)->radioResourceConfigCommon.pcch_Config.nB
-    = configuration->pcch_nB[CC_id];
-
+    = rrconfig->pcch_nB;
   // PRACH-Config
   (*sib2)->radioResourceConfigCommon.prach_Config.rootSequenceIndex
-    = configuration->prach_root[CC_id];
+    = rrconfig->prach_root;
   (*sib2)->radioResourceConfigCommon.prach_Config.prach_ConfigInfo.prach_ConfigIndex
-    = configuration->prach_config_index[CC_id];
+    = rrconfig->prach_config_index;
   (*sib2)->radioResourceConfigCommon.prach_Config.prach_ConfigInfo.highSpeedFlag
-    = configuration->prach_high_speed[CC_id];
+    = rrconfig->prach_high_speed;
   (*sib2)->radioResourceConfigCommon.prach_Config.prach_ConfigInfo.zeroCorrelationZoneConfig
-    = configuration->prach_zero_correlation[CC_id];
+    = rrconfig->prach_zero_correlation;
   (*sib2)->radioResourceConfigCommon.prach_Config.prach_ConfigInfo.prach_FreqOffset
-    = configuration->prach_freq_offset[CC_id];
-
+    = rrconfig->prach_freq_offset;
   // PDSCH-Config
   (*sib2)->radioResourceConfigCommon.pdsch_ConfigCommon.referenceSignalPower
-    = configuration->pdsch_referenceSignalPower[CC_id];
+    = rrconfig->pdsch_referenceSignalPower;
   (*sib2)->radioResourceConfigCommon.pdsch_ConfigCommon.p_b
-    = configuration->pdsch_p_b[CC_id];
-
+    = rrconfig->pdsch_p_b;
   // PUSCH-Config
   (*sib2)->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.n_SB
-    = configuration->pusch_n_SB[CC_id];
+    = rrconfig->pusch_n_SB;
   (*sib2)->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.hoppingMode
-    = configuration->pusch_hoppingMode[CC_id];
+    = rrconfig->pusch_hoppingMode;
   (*sib2)->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.pusch_HoppingOffset
-    = configuration->pusch_hoppingOffset[CC_id];
+    = rrconfig->pusch_hoppingOffset;
   (*sib2)->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.enable64QAM
-    = configuration->pusch_enable64QAM[CC_id];
+    = rrconfig->pusch_enable64QAM;
   (*sib2)->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.groupHoppingEnabled
-    = configuration->pusch_groupHoppingEnabled[CC_id];
+    = rrconfig->pusch_groupHoppingEnabled;
   (*sib2)->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH
-    = configuration->pusch_groupAssignment[CC_id];
+    = rrconfig->pusch_groupAssignment;
   (*sib2)->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled
-    = configuration->pusch_sequenceHoppingEnabled[CC_id];
+    = rrconfig->pusch_sequenceHoppingEnabled;
   (*sib2)->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.cyclicShift
-    = configuration->pusch_nDMRS1[CC_id];
-
+    = rrconfig->pusch_nDMRS1;
   // PUCCH-Config
-
   (*sib2)->radioResourceConfigCommon.pucch_ConfigCommon.deltaPUCCH_Shift
-    = configuration->pucch_delta_shift[CC_id];
+    = rrconfig->pucch_delta_shift;
   (*sib2)->radioResourceConfigCommon.pucch_ConfigCommon.nRB_CQI
-    = configuration->pucch_nRB_CQI[CC_id];
+    = rrconfig->pucch_nRB_CQI;
   (*sib2)->radioResourceConfigCommon.pucch_ConfigCommon.nCS_AN
-    = configuration->pucch_nCS_AN[CC_id];
-//#if (RRC_VERSION < MAKE_VERSION(10, 0, 0))
+    = rrconfig->pucch_nCS_AN;
   (*sib2)->radioResourceConfigCommon.pucch_ConfigCommon.n1PUCCH_AN
-    = configuration->pucch_n1_AN[CC_id];
-//#endif
+    = rrconfig->pucch_n1_AN;
 
   // SRS Config
-  if (configuration->srs_enable[CC_id]==1) {
+  if (rrconfig->srs_enable == 1) {
     (*sib2)->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.present
-      = SoundingRS_UL_ConfigCommon_PR_setup;
+      = LTE_SoundingRS_UL_ConfigCommon_PR_setup;
     (*sib2)->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_BandwidthConfig
-      = configuration->srs_BandwidthConfig[CC_id];
+      = rrconfig->srs_BandwidthConfig;
     (*sib2)->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_SubframeConfig
-      = configuration->srs_SubframeConfig[CC_id];
+      = rrconfig->srs_SubframeConfig;
     (*sib2)->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.ackNackSRS_SimultaneousTransmission
-      = configuration->srs_ackNackST[CC_id];
+      = rrconfig->srs_ackNackST;
 
-    if (configuration->srs_MaxUpPts[CC_id]) {
+    if (rrconfig->srs_MaxUpPts) {
       (*sib2)->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_MaxUpPts
-        = CALLOC(1,sizeof(long));
+	= CALLOC(1,sizeof(long));
       *(*sib2)->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_MaxUpPts=1;
     } else {
       (*sib2)->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_MaxUpPts = NULL;
     }
+
     RC.rrc[Mod_id]->srs_enable[CC_id] = 1;
   } else {
     RC.rrc[Mod_id]->srs_enable[CC_id] = 0;
-    (*sib2)->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.present=SoundingRS_UL_ConfigCommon_PR_release;
+    (*sib2)->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.present=LTE_SoundingRS_UL_ConfigCommon_PR_release;
     (*sib2)->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.release=0;
   }
 
   // uplinkPowerControlCommon
-
   (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.p0_NominalPUSCH
-    = configuration->pusch_p0_Nominal[CC_id];
+    = rrconfig->pusch_p0_Nominal;
   (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.p0_NominalPUCCH
-    = configuration->pucch_p0_Nominal[CC_id];
+    = rrconfig->pucch_p0_Nominal;
   (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.alpha
-    = configuration->pusch_alpha[CC_id];
+    = rrconfig->pusch_alpha;
   (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format1
-    = configuration->pucch_deltaF_Format1[CC_id];
+    = rrconfig->pucch_deltaF_Format1;
   (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format1b
-    = configuration->pucch_deltaF_Format1b[CC_id];
+    = rrconfig->pucch_deltaF_Format1b;
   (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2
-    = configuration->pucch_deltaF_Format2[CC_id];
+    = rrconfig->pucch_deltaF_Format2;
   (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2a
-    = configuration->pucch_deltaF_Format2a[CC_id];
+    = rrconfig->pucch_deltaF_Format2a;
   (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2b
-    = configuration->pucch_deltaF_Format2b[CC_id];
+    = rrconfig->pucch_deltaF_Format2b;
   (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.deltaPreambleMsg3
-    = configuration->msg3_delta_Preamble[CC_id];
+    = rrconfig->msg3_delta_Preamble;
   (*sib2)->radioResourceConfigCommon.ul_CyclicPrefixLength
-    = configuration->ul_CyclicPrefixLength[CC_id];
+    = rrconfig->ul_CyclicPrefixLength;
+
+  if (eMTC_configured>0) {
+    (*sib2)->radioResourceConfigCommon.ext4 = calloc(1, sizeof(struct LTE_RadioResourceConfigCommonSIB__ext4));
+    memset((*sib2)->radioResourceConfigCommon.ext4, 0, sizeof(struct LTE_RadioResourceConfigCommonSIB__ext4));
+    (*sib2)->radioResourceConfigCommon.ext4->bcch_Config_v1310 = NULL; //calloc(1, sizeof(BCCH_Config_v1310_t));
+    //memset((*sib2)->radioResourceConfigCommon.ext4->bcch_Config_v1310, 0, sizeof(BCCH_Config_v1310_t));
+    //(*sib2)->radioResourceConfigCommon.ext4->bcch_Config_v1310->modificationPeriodCoeff_v1310 = BCCH_Config_v1310__modificationPeriodCoeff_v1310_n64;
+
+    if (configuration->pcch_config_v1310) {
+      (*sib2)->radioResourceConfigCommon.ext4->pcch_Config_v1310 = CALLOC(1, sizeof(LTE_PCCH_Config_v1310_t));
+      (*sib2)->radioResourceConfigCommon.ext4->pcch_Config_v1310->paging_narrowBands_r13 = configuration->paging_narrowbands_r13[CC_id];
+      (*sib2)->radioResourceConfigCommon.ext4->pcch_Config_v1310->mpdcch_NumRepetition_Paging_r13 = configuration->mpdcch_numrepetition_paging_r13[CC_id];
+      if (configuration->nb_v1310[CC_id])
+      {
+          (*sib2)->radioResourceConfigCommon.ext4->pcch_Config_v1310->nB_v1310 = CALLOC(1, sizeof(long));
+          *(*sib2)->radioResourceConfigCommon.ext4->pcch_Config_v1310->nB_v1310 = *configuration->nb_v1310[CC_id];
+      }
+      else
+      {
+          (*sib2)->radioResourceConfigCommon.ext4->pcch_Config_v1310->nB_v1310 = NULL;
+      }
+    }
+    else (*sib2)->radioResourceConfigCommon.ext4->pcch_Config_v1310 = NULL;
 
-  // UE Timers and Constants
 
-  (*sib2)->ue_TimersAndConstants.t300
-    = configuration->ue_TimersAndConstants_t300[CC_id];
-  (*sib2)->ue_TimersAndConstants.t301
-    = configuration->ue_TimersAndConstants_t301[CC_id];
-  (*sib2)->ue_TimersAndConstants.t310
-    = configuration->ue_TimersAndConstants_t310[CC_id];
-  (*sib2)->ue_TimersAndConstants.n310
-    = configuration->ue_TimersAndConstants_n310[CC_id];
-  (*sib2)->ue_TimersAndConstants.t311
-    = configuration->ue_TimersAndConstants_t311[CC_id];
-  (*sib2)->ue_TimersAndConstants.n311
-    = configuration->ue_TimersAndConstants_n311[CC_id];
 
-#else
-  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.numberOfRA_Preambles=RACH_ConfigCommon__preambleInfo__numberOfRA_Preambles_n64;
-  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.preamblesGroupAConfig = NULL;
-  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.powerRampingParameters.powerRampingStep=RACH_ConfigCommon__powerRampingParameters__powerRampingStep_dB2;
-  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.powerRampingParameters.preambleInitialReceivedTargetPower=
-    RACH_ConfigCommon__powerRampingParameters__preambleInitialReceivedTargetPower_dBm_100;
-  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.preambleTransMax=RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n10;
-  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.ra_ResponseWindowSize=RACH_ConfigCommon__ra_SupervisionInfo__ra_ResponseWindowSize_sf10;
-  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.mac_ContentionResolutionTimer=
-    RACH_ConfigCommon__ra_SupervisionInfo__mac_ContentionResolutionTimer_sf48;
-  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.maxHARQ_Msg3Tx = 4;
 
-  // BCCH-Config
-  (*sib2)->radioResourceConfigCommon.bcch_Config.modificationPeriodCoeff=BCCH_Config__modificationPeriodCoeff_n2;
+    if (configuration->sib2_freq_hoppingParameters_r13_exists[CC_id]) {
 
-  // PCCH-Config
-  (*sib2)->radioResourceConfigCommon.pcch_Config.defaultPagingCycle = PCCH_Config__defaultPagingCycle_rf128;
-  (*sib2)->radioResourceConfigCommon.pcch_Config.nB=PCCH_Config__nB_oneT;
+      (*sib2)->radioResourceConfigCommon.ext4->freqHoppingParameters_r13 = CALLOC(1, sizeof(LTE_FreqHoppingParameters_r13_t));
 
-  // PRACH-Config
-  (*sib2)->radioResourceConfigCommon.prach_Config.rootSequenceIndex=Mod_id;//0;//384;
-  (*sib2)->radioResourceConfigCommon.prach_Config.prach_ConfigInfo.prach_ConfigIndex = 0;//3;
-  (*sib2)->radioResourceConfigCommon.prach_Config.prach_ConfigInfo.highSpeedFlag = 0;
-  (*sib2)->radioResourceConfigCommon.prach_Config.prach_ConfigInfo.zeroCorrelationZoneConfig = 1;//12;
-  (*sib2)->radioResourceConfigCommon.prach_Config.prach_ConfigInfo.prach_FreqOffset = 2;
+      if (configuration->sib2_interval_ULHoppingConfigCommonModeA_r13[CC_id]) {
+          (*sib2)->radioResourceConfigCommon.ext4->freqHoppingParameters_r13->interval_ULHoppingConfigCommonModeA_r13
+                  = CALLOC(1, sizeof(struct LTE_FreqHoppingParameters_r13__interval_ULHoppingConfigCommonModeA_r13));
+          if (*configuration->sib2_interval_ULHoppingConfigCommonModeA_r13[CC_id] == 0) {
+              (*sib2)->radioResourceConfigCommon.ext4->freqHoppingParameters_r13->interval_ULHoppingConfigCommonModeA_r13->present
+                      = LTE_FreqHoppingParameters_r13__interval_ULHoppingConfigCommonModeA_r13_PR_interval_FDD_r13;
+              (*sib2)->radioResourceConfigCommon.ext4->freqHoppingParameters_r13->interval_ULHoppingConfigCommonModeA_r13->choice.interval_FDD_r13
+                      = configuration->sib2_interval_ULHoppingConfigCommonModeA_r13_val[CC_id];
 
-  // PDSCH-Config
-  (*sib2)->radioResourceConfigCommon.pdsch_ConfigCommon.referenceSignalPower=0;  // corresponds to 24.7 dBm 5 MHz/ 27.7 10 MHz/ 30.7 20 MHz
+          }
+          else
+          {
+              (*sib2)->radioResourceConfigCommon.ext4->freqHoppingParameters_r13->interval_ULHoppingConfigCommonModeA_r13->present
+                      = LTE_FreqHoppingParameters_r13__interval_ULHoppingConfigCommonModeA_r13_PR_interval_TDD_r13;
+              (*sib2)->radioResourceConfigCommon.ext4->freqHoppingParameters_r13->interval_ULHoppingConfigCommonModeA_r13->choice.interval_TDD_r13
+                      = configuration->sib2_interval_ULHoppingConfigCommonModeA_r13_val[CC_id];
+
+          }
+      }
+      else (*sib2)->radioResourceConfigCommon.ext4->freqHoppingParameters_r13->interval_ULHoppingConfigCommonModeA_r13 = NULL;
 
 
-  (*sib2)->radioResourceConfigCommon.pdsch_ConfigCommon.p_b=0;
+      if (configuration->sib2_interval_ULHoppingConfigCommonModeB_r13[CC_id]) {
+          (*sib2)->radioResourceConfigCommon.ext4->freqHoppingParameters_r13->interval_ULHoppingConfigCommonModeB_r13
+                  = CALLOC(1, sizeof(struct LTE_FreqHoppingParameters_r13__interval_ULHoppingConfigCommonModeB_r13));
+          if (*configuration->sib2_interval_ULHoppingConfigCommonModeB_r13[CC_id] == 0)  {
+              (*sib2)->radioResourceConfigCommon.ext4->freqHoppingParameters_r13->interval_ULHoppingConfigCommonModeB_r13->present
+                      = LTE_FreqHoppingParameters_r13__interval_ULHoppingConfigCommonModeB_r13_PR_interval_FDD_r13;
+              (*sib2)->radioResourceConfigCommon.ext4->freqHoppingParameters_r13->interval_ULHoppingConfigCommonModeB_r13->choice.interval_FDD_r13
+                      = configuration->sib2_interval_ULHoppingConfigCommonModeB_r13_val[CC_id];
+          }
+          else {
+              (*sib2)->radioResourceConfigCommon.ext4->freqHoppingParameters_r13->interval_ULHoppingConfigCommonModeB_r13->present
+                      = LTE_FreqHoppingParameters_r13__interval_ULHoppingConfigCommonModeB_r13_PR_interval_TDD_r13;
+              (*sib2)->radioResourceConfigCommon.ext4->freqHoppingParameters_r13->interval_ULHoppingConfigCommonModeB_r13->choice.interval_TDD_r13
+                      = configuration->sib2_interval_ULHoppingConfigCommonModeB_r13_val[CC_id];
+          }
+      }
+      else (*sib2)->radioResourceConfigCommon.ext4->freqHoppingParameters_r13->interval_ULHoppingConfigCommonModeB_r13 = NULL;
+    }
+    else (*sib2)->radioResourceConfigCommon.ext4->freqHoppingParameters_r13 = NULL;
+  // pdsch_ConfigCommon_v1310
+    (*sib2)->radioResourceConfigCommon.ext4->pdsch_ConfigCommon_v1310 = CALLOC(1,sizeof(LTE_PDSCH_ConfigCommon_v1310_t));
+
+    if (configuration->pdsch_maxNumRepetitionCEmodeA_r13[CC_id]) {
+        (*sib2)->radioResourceConfigCommon.ext4->pdsch_ConfigCommon_v1310->pdsch_maxNumRepetitionCEmodeA_r13 = CALLOC(1, sizeof(long));
+        *(*sib2)->radioResourceConfigCommon.ext4->pdsch_ConfigCommon_v1310->pdsch_maxNumRepetitionCEmodeA_r13 = *configuration->pdsch_maxNumRepetitionCEmodeA_r13[CC_id];
+    } else {
+        (*sib2)->radioResourceConfigCommon.ext4->pdsch_ConfigCommon_v1310->pdsch_maxNumRepetitionCEmodeA_r13 = NULL;
+    }
+
+    if (configuration->pdsch_maxNumRepetitionCEmodeB_r13[CC_id]) {
+        (*sib2)->radioResourceConfigCommon.ext4->pdsch_ConfigCommon_v1310->pdsch_maxNumRepetitionCEmodeB_r13 = CALLOC(1, sizeof(long)); // check if they're really long
+      *(*sib2)->radioResourceConfigCommon.ext4->pdsch_ConfigCommon_v1310->pdsch_maxNumRepetitionCEmodeB_r13 = *configuration->pdsch_maxNumRepetitionCEmodeB_r13[CC_id];
+    } else {
+      (*sib2)->radioResourceConfigCommon.ext4->pdsch_ConfigCommon_v1310->pdsch_maxNumRepetitionCEmodeB_r13 = NULL;
+    }
+
+  //  *(*sib2)->radioResourceConfigCommon.ext4->pdsch_ConfigCommon_v1310->pdsch_maxNumRepetitionCEmodeA_r13 = 0;
+  //  (*sib2)->radioResourceConfigCommon.ext4->pdsch_ConfigCommon_v1310->pdsch_maxNumRepetitionCEmodeB_r13 = NULL;
+
+  //  pusch_ConfigCommon_v1310
+    (*sib2)->radioResourceConfigCommon.ext4->pusch_ConfigCommon_v1310 = calloc(1,sizeof(LTE_PUSCH_ConfigCommon_v1310_t));
+
+    if (configuration->pusch_maxNumRepetitionCEmodeA_r13[CC_id]) {
+        (*sib2)->radioResourceConfigCommon.ext4->pusch_ConfigCommon_v1310->pusch_maxNumRepetitionCEmodeA_r13 = calloc(1,sizeof(long));
+        *(*sib2)->radioResourceConfigCommon.ext4->pusch_ConfigCommon_v1310->pusch_maxNumRepetitionCEmodeA_r13 = *configuration->pusch_maxNumRepetitionCEmodeA_r13[CC_id];
+    } else {
+        (*sib2)->radioResourceConfigCommon.ext4->pusch_ConfigCommon_v1310->pusch_maxNumRepetitionCEmodeA_r13 = NULL;
+    }
+
+    if (configuration->pusch_maxNumRepetitionCEmodeB_r13[CC_id]) {
+        (*sib2)->radioResourceConfigCommon.ext4->pusch_ConfigCommon_v1310->pusch_maxNumRepetitionCEmodeB_r13 = CALLOC(1, sizeof(long));
+        *(*sib2)->radioResourceConfigCommon.ext4->pusch_ConfigCommon_v1310->pusch_maxNumRepetitionCEmodeB_r13 = *configuration->pusch_maxNumRepetitionCEmodeB_r13[CC_id];
+    } else {
+      (*sib2)->radioResourceConfigCommon.ext4->pusch_ConfigCommon_v1310->pusch_maxNumRepetitionCEmodeB_r13 = NULL;
+    }
+
+    if (configuration->pusch_HoppingOffset_v1310[CC_id]) {
+        (*sib2)->radioResourceConfigCommon.ext4->pusch_ConfigCommon_v1310->pusch_HoppingOffset_v1310 = CALLOC(1, sizeof(long));
+        *(*sib2)->radioResourceConfigCommon.ext4->pusch_ConfigCommon_v1310->pusch_HoppingOffset_v1310 = *configuration->pusch_HoppingOffset_v1310[CC_id];
+    } else {
+        (*sib2)->radioResourceConfigCommon.ext4->pusch_ConfigCommon_v1310->pusch_HoppingOffset_v1310 = NULL;
+    }
+
+  //  *(*sib2)->radioResourceConfigCommon.ext4->pusch_ConfigCommon_v1310->pusch_maxNumRepetitionCEmodeA_r13 = 0;
+  //  (*sib2)->radioResourceConfigCommon.ext4->pusch_ConfigCommon_v1310->pusch_maxNumRepetitionCEmodeB_r13 = NULL;
+  //  (*sib2)->radioResourceConfigCommon.ext4->pusch_ConfigCommon_v1310->pusch_HoppingOffset_v1310 = NULL;
+
+
+    if (rrconfig->prach_ConfigCommon_v1310) {
+      (*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310 = calloc(1, sizeof(LTE_PRACH_ConfigSIB_v1310_t));
+      memset((*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310, 0, sizeof(LTE_PRACH_ConfigSIB_v1310_t));
+
+      LTE_RSRP_Range_t *rsrp_range;
+      int num_rsrp_range = configuration->rsrp_range_list_size[CC_id];
+      int rsrp_index;
+      for (rsrp_index = 0; rsrp_index < num_rsrp_range; ++rsrp_index) {
+          rsrp_range = CALLOC(1, sizeof(LTE_RSRP_Range_t));
+          if (configuration->rsrp_range_list_size[CC_id]) *rsrp_range = configuration->rsrp_range[CC_id][rsrp_index];
+          else                                            *rsrp_range = 60;
+          ASN_SEQUENCE_ADD(&(*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310->rsrp_ThresholdsPrachInfoList_r13.list, rsrp_range);
+      }
+
+      (*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310->mpdcch_startSF_CSS_RA_r13 = NULL;
+
+      if (rrconfig->mpdcch_startSF_CSS_RA_r13) {
+          (*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310->mpdcch_startSF_CSS_RA_r13 = calloc(1, sizeof(struct LTE_PRACH_ConfigSIB_v1310__mpdcch_startSF_CSS_RA_r13));
+          memset((*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310->mpdcch_startSF_CSS_RA_r13, 0, sizeof(struct LTE_PRACH_ConfigSIB_v1310__mpdcch_startSF_CSS_RA_r13));
+
+          if (*rrconfig->mpdcch_startSF_CSS_RA_r13) {
+              (*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310->mpdcch_startSF_CSS_RA_r13->present = LTE_PRACH_ConfigSIB_v1310__mpdcch_startSF_CSS_RA_r13_PR_fdd_r13;
+              (*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310->mpdcch_startSF_CSS_RA_r13->choice.fdd_r13 = rrconfig->mpdcch_startSF_CSS_RA_r13_val;
+          }
+          else {
+              (*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310->mpdcch_startSF_CSS_RA_r13->present = LTE_PRACH_ConfigSIB_v1310__mpdcch_startSF_CSS_RA_r13_PR_tdd_r13;
+              (*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310->mpdcch_startSF_CSS_RA_r13->choice.tdd_r13 = rrconfig->mpdcch_startSF_CSS_RA_r13_val;
+          }
+      }
+
+      if (rrconfig->prach_HoppingOffset_r13) {
+          (*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310->prach_HoppingOffset_r13 = calloc(1, sizeof(long));
+          *(*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310->prach_HoppingOffset_r13 = *rrconfig->prach_HoppingOffset_r13;
+      }
+      else (*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310->prach_HoppingOffset_r13 = NULL;
+
+      LTE_PRACH_ParametersCE_r13_t *prach_parametersce_r13;
+
+      int num_prach_parameters_ce = configuration->prach_parameters_list_size[CC_id];
+      int prach_parameters_index;
+      AssertFatal(num_prach_parameters_ce > 0, "PRACH CE parameter list is empty\n");
+
+      for (prach_parameters_index = 0; prach_parameters_index < num_prach_parameters_ce; ++prach_parameters_index) {
+          prach_parametersce_r13 = CALLOC(1, sizeof(LTE_PRACH_ParametersCE_r13_t));
+          prach_parametersce_r13->prach_ConfigIndex_r13 = configuration->prach_config_index[CC_id][prach_parameters_index];
+          prach_parametersce_r13->prach_FreqOffset_r13 = configuration->prach_freq_offset[CC_id][prach_parameters_index];
+
+          AssertFatal(configuration->prach_StartingSubframe_r13[CC_id][prach_parameters_index]!=NULL,
+                      "configuration->prach_StartingSubframe_r13[%d][%d] is null",
+                      (int)CC_id,(int)prach_parameters_index);
+          if (configuration->prach_StartingSubframe_r13[CC_id][prach_parameters_index]){
+              prach_parametersce_r13->prach_StartingSubframe_r13 = CALLOC(1, sizeof(long));
+              *prach_parametersce_r13->prach_StartingSubframe_r13 = *configuration->prach_StartingSubframe_r13[CC_id][prach_parameters_index];
+          }
+          else prach_parametersce_r13->prach_StartingSubframe_r13 = NULL;
+
+
+          if (configuration->maxNumPreambleAttemptCE_r13[CC_id][prach_parameters_index]) {
+              prach_parametersce_r13->maxNumPreambleAttemptCE_r13 = CALLOC(1, sizeof(long));
+              *prach_parametersce_r13->maxNumPreambleAttemptCE_r13 = *configuration->maxNumPreambleAttemptCE_r13[CC_id][prach_parameters_index];
+          }
+          else prach_parametersce_r13->maxNumPreambleAttemptCE_r13 = NULL;
+
+          prach_parametersce_r13->numRepetitionPerPreambleAttempt_r13 = configuration->numRepetitionPerPreambleAttempt_r13[CC_id][prach_parameters_index];
+          prach_parametersce_r13->mpdcch_NumRepetition_RA_r13 = configuration->mpdcch_NumRepetition_RA_r13[CC_id][prach_parameters_index];
+          prach_parametersce_r13->prach_HoppingConfig_r13 = configuration->prach_HoppingConfig_r13[CC_id][prach_parameters_index];
+
+          long *maxavailablenarrowband;
+          int num_narrow_bands = configuration->max_available_narrow_band_size[CC_id][prach_parameters_index];
+          int narrow_band_index;
+          for (narrow_band_index = 0; narrow_band_index < num_narrow_bands; narrow_band_index++)
+          {
+              maxavailablenarrowband = CALLOC(1, sizeof(long));
+              *maxavailablenarrowband = configuration->max_available_narrow_band[CC_id][prach_parameters_index][narrow_band_index];
+              ASN_SEQUENCE_ADD(&prach_parametersce_r13->mpdcch_NarrowbandsToMonitor_r13.list, maxavailablenarrowband);
+          }
+
+
+          prach_parametersce_r13->mpdcch_NumRepetition_RA_r13 = LTE_PRACH_ParametersCE_r13__mpdcch_NumRepetition_RA_r13_r1;
+          prach_parametersce_r13->prach_HoppingConfig_r13 = LTE_PRACH_ParametersCE_r13__prach_HoppingConfig_r13_off;
+
+
+          ASN_SEQUENCE_ADD(&(*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310->prach_ParametersListCE_r13.list, prach_parametersce_r13);
+      }
+    }
+    else (*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310 = NULL;
+
+
+
+    (*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310 = calloc(1, sizeof(LTE_PUCCH_ConfigCommon_v1310_t));
+    memset((*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310, 0, sizeof(LTE_PUCCH_ConfigCommon_v1310_t));
+    (*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310->n1PUCCH_AN_InfoList_r13 = calloc(1, sizeof(LTE_N1PUCCH_AN_InfoList_r13_t));
+
+    int num_pucch_info_list = configuration->pucch_info_value_size[CC_id];
+    int pucch_index;
+    long *pucch_info_value;
+    for (pucch_index = 0; pucch_index <  num_pucch_info_list; ++pucch_index) {
+      pucch_info_value = CALLOC(1, sizeof(long));
+      if (configuration->pucch_info_value_size[CC_id]) *pucch_info_value = configuration->pucch_info_value[CC_id][pucch_index];
+      else                                             *pucch_info_value = 0;
+
+      ASN_SEQUENCE_ADD(&(*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310->n1PUCCH_AN_InfoList_r13->list, pucch_info_value);
+    }
+
+    if (configuration->pucch_NumRepetitionCE_Msg4_Level0_r13[CC_id]) {
+      (*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310->pucch_NumRepetitionCE_Msg4_Level0_r13  = CALLOC(1, sizeof(long));
+      *(*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310->pucch_NumRepetitionCE_Msg4_Level0_r13 =  *configuration->pucch_NumRepetitionCE_Msg4_Level0_r13[CC_id];
+    }
+    else (*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310->pucch_NumRepetitionCE_Msg4_Level0_r13 = NULL;
+
+    if (configuration->pucch_NumRepetitionCE_Msg4_Level1_r13[CC_id]) {
+      (*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310->pucch_NumRepetitionCE_Msg4_Level1_r13  = CALLOC(1, sizeof(long));
+      *(*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310->pucch_NumRepetitionCE_Msg4_Level1_r13 =  *configuration->pucch_NumRepetitionCE_Msg4_Level1_r13[CC_id];
+    }
+    else (*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310->pucch_NumRepetitionCE_Msg4_Level1_r13 = NULL;
+
+
+    if (configuration->pucch_NumRepetitionCE_Msg4_Level2_r13[CC_id]) {
+      (*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310->pucch_NumRepetitionCE_Msg4_Level2_r13  = CALLOC(1, sizeof(long));
+      *(*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310->pucch_NumRepetitionCE_Msg4_Level2_r13 =  *configuration->pucch_NumRepetitionCE_Msg4_Level2_r13[CC_id];
+    }
+    else (*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310->pucch_NumRepetitionCE_Msg4_Level2_r13 = NULL;
+
+    if (configuration->pucch_NumRepetitionCE_Msg4_Level3_r13[CC_id]) {
+      (*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310->pucch_NumRepetitionCE_Msg4_Level3_r13  = CALLOC(1, sizeof(long));
+      *(*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310->pucch_NumRepetitionCE_Msg4_Level3_r13 =  *configuration->pucch_NumRepetitionCE_Msg4_Level3_r13[CC_id];
+    }
+    else (*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310->pucch_NumRepetitionCE_Msg4_Level3_r13 = NULL;
+
+  } // eMTC_configured>0
+  //-----------------------------------------------------------------------------------------------------------------------------------------
+
+
+  // UE Timers and Constants
+  (*sib2)->ue_TimersAndConstants.t300
+    = rrconfig->ue_TimersAndConstants_t300;
+  (*sib2)->ue_TimersAndConstants.t301
+    = rrconfig->ue_TimersAndConstants_t301;
+  (*sib2)->ue_TimersAndConstants.t310
+    = rrconfig->ue_TimersAndConstants_t310;
+  (*sib2)->ue_TimersAndConstants.n310
+    = rrconfig->ue_TimersAndConstants_n310;
+  (*sib2)->ue_TimersAndConstants.t311
+    = rrconfig->ue_TimersAndConstants_t311;
+  (*sib2)->ue_TimersAndConstants.n311
+    = rrconfig->ue_TimersAndConstants_n311;
+#else
+  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.numberOfRA_Preambles=LTE_RACH_ConfigCommon__preambleInfo__numberOfRA_Preambles_n64;
+  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.preamblesGroupAConfig = NULL;
+  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.powerRampingParameters.powerRampingStep=LTE_RACH_ConfigCommon__powerRampingParameters__powerRampingStep_dB2;
+  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.powerRampingParameters.preambleInitialReceivedTargetPower=
+    RACH_ConfigCommon__powerRampingParameters__preambleInitialReceivedTargetPower_dBm_100;
+  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.preambleTransMax=LTE_RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n10;
+  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.ra_ResponseWindowSize=LTE_RACH_ConfigCommon__ra_SupervisionInfo__ra_ResponseWindowSize_sf10;
+  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.mac_ContentionResolutionTimer=
+    LTE_RACH_ConfigCommon__ra_SupervisionInfo__mac_ContentionResolutionTimer_sf48;
+  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.maxHARQ_Msg3Tx = 4;
+
+  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ext1 = calloc(1, sizeof(struct LTE_RACH_ConfigCommon__ext1));
+  memset((*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ext1, 0, sizeof(struct LTE_RACH_ConfigCommon__ext1));
+  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ext1->preambleTransMax_CE_r13 = calloc(1, sizeof(LTE_PreambleTransMax_t));
+  *(*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ext1->preambleTransMax_CE_r13 = LTE_PreambleTransMax_n5; // to be re-initialized when we find the enum
+  (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ext1->rach_CE_LevelInfoList_r13 = calloc(1, sizeof(LTE_RACH_CE_LevelInfoList_r13_t));
+  memset((*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ext1->rach_CE_LevelInfoList_r13, 0, sizeof(LTE_RACH_CE_LevelInfoList_r13_t));
+
+  LTE_RACH_CE_LevelInfo_r13_t *rach_ce_levelinfo_r13 = calloc(1, sizeof(LTE_RACH_CE_LevelInfo_r13_t));
+  memset(rach_ce_levelinfo_r13, 0, sizeof(LTE_RACH_CE_LevelInfo_r13_t));
+  rach_ce_levelinfo_r13->preambleMappingInfo_r13.firstPreamble_r13 = 0;
+  rach_ce_levelinfo_r13->preambleMappingInfo_r13.lastPreamble_r13 = 63;
+  rach_ce_levelinfo_r13->ra_ResponseWindowSize_r13 = LTE_RACH_CE_LevelInfo_r13__ra_ResponseWindowSize_r13_sf80;
+  rach_ce_levelinfo_r13->mac_ContentionResolutionTimer_r13 = LTE_RACH_CE_LevelInfo_r13__mac_ContentionResolutionTimer_r13_sf200;
+  rach_ce_levelinfo_r13->rar_HoppingConfig_r13 = LTE_RACH_CE_LevelInfo_r13__rar_HoppingConfig_r13_off;
 
+  ASN_SEQUENCE_ADD(&(*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ext1->rach_CE_LevelInfoList_r13->list, rach_ce_levelinfo_r13);
+
+  // BCCH-Config
+  (*sib2)->radioResourceConfigCommon.bcch_Config.modificationPeriodCoeff=LTE_BCCH_Config__modificationPeriodCoeff_n2;
+
+  // PCCH-Config
+  (*sib2)->radioResourceConfigCommon.pcch_Config.defaultPagingCycle = LTE_PCCH_Config__defaultPagingCycle_rf128;
+  (*sib2)->radioResourceConfigCommon.pcch_Config.nB=LTE_PCCH_Config__nB_oneT;
+  // PRACH-Config
+  (*sib2)->radioResourceConfigCommon.prach_Config.rootSequenceIndex = Mod_id;//0;//384;
+  (*sib2)->radioResourceConfigCommon.prach_Config.prach_ConfigInfo.prach_ConfigIndex = 0;//3;
+  (*sib2)->radioResourceConfigCommon.prach_Config.prach_ConfigInfo.highSpeedFlag = 0;
+  (*sib2)->radioResourceConfigCommon.prach_Config.prach_ConfigInfo.zeroCorrelationZoneConfig = 1;//12;
+  (*sib2)->radioResourceConfigCommon.prach_Config.prach_ConfigInfo.prach_FreqOffset = 2;
+  // PDSCH-Config
+  (*sib2)->radioResourceConfigCommon.pdsch_ConfigCommon.referenceSignalPower=0;  // corresponds to 24.7 dBm 5 MHz/ 27.7 10 MHz/ 30.7 20 MHz
+  (*sib2)->radioResourceConfigCommon.pdsch_ConfigCommon.p_b=0;
   // PUSCH-Config
   (*sib2)->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.n_SB=1;
-  (*sib2)->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.hoppingMode=PUSCH_ConfigCommon__pusch_ConfigBasic__hoppingMode_interSubFrame;
+  (*sib2)->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.hoppingMode=LTE_PUSCH_ConfigCommon__pusch_ConfigBasic__hoppingMode_interSubFrame;
   (*sib2)->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.pusch_HoppingOffset=0;
   (*sib2)->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.enable64QAM=0;
   (*sib2)->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.groupHoppingEnabled=1;
   (*sib2)->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH=0;
   (*sib2)->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled=0;
   (*sib2)->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.cyclicShift=0;
-
   // PUCCH-Config
-
-  (*sib2)->radioResourceConfigCommon.pucch_ConfigCommon.deltaPUCCH_Shift=PUCCH_ConfigCommon__deltaPUCCH_Shift_ds1;
+  (*sib2)->radioResourceConfigCommon.pucch_ConfigCommon.deltaPUCCH_Shift=LTE_PUCCH_ConfigCommon__deltaPUCCH_Shift_ds1;
   (*sib2)->radioResourceConfigCommon.pucch_ConfigCommon.nRB_CQI = 1;
   (*sib2)->radioResourceConfigCommon.pucch_ConfigCommon.nCS_AN = 0;
   (*sib2)->radioResourceConfigCommon.pucch_ConfigCommon.n1PUCCH_AN = 32;
-
-
-  (*sib2)->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.present=SoundingRS_UL_ConfigCommon_PR_release;
+  (*sib2)->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.present=LTE_SoundingRS_UL_ConfigCommon_PR_release;
   (*sib2)->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.release=0;
-
   // uplinkPowerControlCommon
-
   (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.p0_NominalPUSCH = -108;
   (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.p0_NominalPUCCH = -108;
-  (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.alpha=UplinkPowerControlCommon__alpha_al1;
-  (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format1=DeltaFList_PUCCH__deltaF_PUCCH_Format1_deltaF2;
-  (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format1b=DeltaFList_PUCCH__deltaF_PUCCH_Format1b_deltaF3;
-
-  (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2=DeltaFList_PUCCH__deltaF_PUCCH_Format2_deltaF0;
-
-  (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2a=DeltaFList_PUCCH__deltaF_PUCCH_Format2a_deltaF0;
-
-  (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2b=DeltaFList_PUCCH__deltaF_PUCCH_Format2b_deltaF0;
-
+  (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.alpha=LTE_UplinkPowerControlCommon__alpha_al1;
+  (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format1=LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format1_deltaF2;
+  (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format1b=LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format1b_deltaF3;
+  (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2=LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format2_deltaF0;
+  (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2a=LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format2a_deltaF0;
+  (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2b=LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format2b_deltaF0;
   (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.deltaPreambleMsg3 = 6;
-
   (*sib2)->radioResourceConfigCommon.ul_CyclicPrefixLength=UL_CyclicPrefixLength_len1;
 
-  (*sib2)->ue_TimersAndConstants.t300=UE_TimersAndConstants__t300_ms1000;
+  (*sib2)->radioResourceConfigCommon.ext4 = calloc(1, sizeof(struct LTE_RadioResourceConfigCommonSIB__ext4));
+  memset((*sib2)->radioResourceConfigCommon.ext4, 0, sizeof(struct LTE_RadioResourceConfigCommonSIB__ext4));
+  (*sib2)->radioResourceConfigCommon.ext4->bcch_Config_v1310 = calloc(1, sizeof(LTE_BCCH_Config_v1310_t));
+  memset((*sib2)->radioResourceConfigCommon.ext4->bcch_Config_v1310, 0, sizeof(LTE_BCCH_Config_v1310_t));
+  (*sib2)->radioResourceConfigCommon.ext4->bcch_Config_v1310->modificationPeriodCoeff_v1310 = LTE_BCCH_Config_v1310__modificationPeriodCoeff_v1310_n64;
+  (*sib2)->radioResourceConfigCommon.ext4->pcch_Config_v1310 = NULL;
+  (*sib2)->radioResourceConfigCommon.ext4->freqHoppingParameters_r13 = NULL;
+  (*sib2)->radioResourceConfigCommon.ext4->pdsch_ConfigCommon_v1310 = NULL;
+  (*sib2)->radioResourceConfigCommon.ext4->pusch_ConfigCommon_v1310 = NULL;
+  (*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310 = calloc(1, sizeof(LTE_PRACH_ConfigSIB_v1310_t));
+  memset((*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310, 0, sizeof(PRACH_ConfigSIB_v1310_t));
+
+  LTE_RSRP_Range_t rsrp_range = 60;
+  ASN_SEQUENCE_ADD(&(*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310->rsrp_ThresholdsPrachInfoList_r13.list, &rsrp_range);
+
+  (*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310->mpdcch_startSF_CSS_RA_r13 = calloc(1, sizeof(struct LTE_PRACH_ConfigSIB_v1310__mpdcch_startSF_CSS_RA_r13));
+  memset((*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310->mpdcch_startSF_CSS_RA_r13, 0, sizeof(struct LTE_PRACH_ConfigSIB_v1310__mpdcch_startSF_CSS_RA_r13));
+  (*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310->mpdcch_startSF_CSS_RA_r13->present = LTE_PRACH_ConfigSIB_v1310__mpdcch_startSF_CSS_RA_r13_PR_fdd_r13;
+  (*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310->mpdcch_startSF_CSS_RA_r13->choice.fdd_r13 = LTE_PRACH_ConfigSIB_v1310__mpdcch_startSF_CSS_RA_r13__fdd_r13_v5;
+  (*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310->prach_HoppingOffset_r13 = NULL;
+
+  LTE_PRACH_ParametersCE_r13_t *prach_parametersce_r13 = calloc(1, sizeof(LTE_PRACH_ParametersCE_r13_t));
+  memset(prach_parametersce_r13, 0, sizeof(LTE_PRACH_ParametersCE_r13_t));
+
+  prach_parametersce_r13->prach_ConfigIndex_r13 = 3;
+  prach_parametersce_r13->prach_FreqOffset_r13 = 1;
+  prach_parametersce_r13->prach_StartingSubframe_r13 = NULL;
+  prach_parametersce_r13->maxNumPreambleAttemptCE_r13 = calloc(1, sizeof(long));
+  *prach_parametersce_r13->maxNumPreambleAttemptCE_r13 = LTE_PRACH_ParametersCE_r13__maxNumPreambleAttemptCE_r13_n3;
+  prach_parametersce_r13->numRepetitionPerPreambleAttempt_r13 = LTE_PRACH_ParametersCE_r13__numRepetitionPerPreambleAttempt_r13_n1;
+
+  long maxavailablenarrowband = 2;
+  ASN_SEQUENCE_ADD(&prach_parametersce_r13->mpdcch_NarrowbandsToMonitor_r13.list, &maxavailablenarrowband);
+
+  prach_parametersce_r13->mpdcch_NumRepetition_RA_r13 = LTE_PRACH_ParametersCE_r13__mpdcch_NumRepetition_RA_r13_r1;
+  prach_parametersce_r13->prach_HoppingConfig_r13 = LTE_PRACH_ParametersCE_r13__prach_HoppingConfig_r13_off;
+  ASN_SEQUENCE_ADD(&(*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310->prach_ParametersListCE_r13.list, prach_parametersce_r13);
+
+  (*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310 = calloc(1, sizeof(LTE_PUCCH_ConfigCommon_v1310_t));
+  memset((*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310, 0, sizeof(LTE_PUCCH_ConfigCommon_v1310_t));
+
+  (*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310->n1PUCCH_AN_InfoList_r13 = calloc(1, sizeof(LTE_N1PUCCH_AN_InfoList_r13_t));
+  long pucch_info_value1 = 0;
+  long pucch_info_value2 = 2;
+  ASN_SEQUENCE_ADD(&(*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310->n1PUCCH_AN_InfoList_r13->list, &pucch_info_value1);
+  ASN_SEQUENCE_ADD(&(*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310->n1PUCCH_AN_InfoList_r13->list, &pucch_info_value2);
+  (*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310->pucch_NumRepetitionCE_Msg4_Level0_r13 = NULL;
+  (*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310->pucch_NumRepetitionCE_Msg4_Level1_r13 = NULL;
+  (*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310->pucch_NumRepetitionCE_Msg4_Level2_r13 = NULL;
+  (*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310->pucch_NumRepetitionCE_Msg4_Level3_r13 = NULL;
 
+  (*sib2)->ue_TimersAndConstants.t300=UE_TimersAndConstants__t300_ms1000;
   (*sib2)->ue_TimersAndConstants.t301=UE_TimersAndConstants__t301_ms1000;
-
   (*sib2)->ue_TimersAndConstants.t310=UE_TimersAndConstants__t310_ms1000;
-
   (*sib2)->ue_TimersAndConstants.n310=UE_TimersAndConstants__n310_n20;
-
   (*sib2)->ue_TimersAndConstants.t311=UE_TimersAndConstants__t311_ms10000;
-
   (*sib2)->ue_TimersAndConstants.n311=UE_TimersAndConstants__n311_n1;
 
 #endif
-
   (*sib2)->freqInfo.additionalSpectrumEmission = 1;
   (*sib2)->freqInfo.ul_CarrierFreq = NULL;
   (*sib2)->freqInfo.ul_Bandwidth = NULL;
   //  (*sib2)->mbsfn_SubframeConfigList = NULL;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-
-  if (MBMS_flag > 0) {
+  if (configuration->eMBMS_configured > 0) {
     LOG_I(RRC,"Adding MBSFN subframe Configuration 1 to SIB2\n");
-    MBSFN_SubframeConfig_t *sib2_mbsfn_SubframeConfig1;
-    (*sib2)->mbsfn_SubframeConfigList = CALLOC(1,sizeof(struct MBSFN_SubframeConfigList));
+    LTE_MBSFN_SubframeConfig_t *sib2_mbsfn_SubframeConfig1;
+    (*sib2)->mbsfn_SubframeConfigList = CALLOC(1,sizeof(struct LTE_MBSFN_SubframeConfigList));
     MBSFNSubframeConfigList = (*sib2)->mbsfn_SubframeConfigList;
-
     sib2_mbsfn_SubframeConfig1= CALLOC(1,sizeof(*sib2_mbsfn_SubframeConfig1));
-    memset((void*)sib2_mbsfn_SubframeConfig1,0,sizeof(*sib2_mbsfn_SubframeConfig1));
-
-    sib2_mbsfn_SubframeConfig1->radioframeAllocationPeriod= MBSFN_SubframeConfig__radioframeAllocationPeriod_n4;
+    memset((void *)sib2_mbsfn_SubframeConfig1,0,sizeof(*sib2_mbsfn_SubframeConfig1));
+    sib2_mbsfn_SubframeConfig1->radioframeAllocationPeriod= LTE_MBSFN_SubframeConfig__radioframeAllocationPeriod_n4;
     sib2_mbsfn_SubframeConfig1->radioframeAllocationOffset= 1;
-    sib2_mbsfn_SubframeConfig1->subframeAllocation.present= MBSFN_SubframeConfig__subframeAllocation_PR_oneFrame;
+    sib2_mbsfn_SubframeConfig1->subframeAllocation.present= LTE_MBSFN_SubframeConfig__subframeAllocation_PR_oneFrame;
     sib2_mbsfn_SubframeConfig1->subframeAllocation.choice.oneFrame.buf= MALLOC(1);
     sib2_mbsfn_SubframeConfig1->subframeAllocation.choice.oneFrame.size= 1;
     sib2_mbsfn_SubframeConfig1->subframeAllocation.choice.oneFrame.bits_unused= 2;
-
     sib2_mbsfn_SubframeConfig1->subframeAllocation.choice.oneFrame.buf[0]=0x38<<2;
 
     ASN_SEQUENCE_ADD(&MBSFNSubframeConfigList->list,sib2_mbsfn_SubframeConfig1);
 
-    if (MBMS_flag == 4 ) {
+
+    if (configuration->eMBMS_configured == 4 ) {
       LOG_I(RRC,"Adding MBSFN subframe Configuration 2 to SIB2\n");
-      MBSFN_SubframeConfig_t *sib2_mbsfn_SubframeConfig2;
+      LTE_MBSFN_SubframeConfig_t *sib2_mbsfn_SubframeConfig2;
       sib2_mbsfn_SubframeConfig2= CALLOC(1,sizeof(*sib2_mbsfn_SubframeConfig2));
-      memset((void*)sib2_mbsfn_SubframeConfig2,0,sizeof(*sib2_mbsfn_SubframeConfig2));
-
-      sib2_mbsfn_SubframeConfig2->radioframeAllocationPeriod= MBSFN_SubframeConfig__radioframeAllocationPeriod_n4;
+      memset((void *)sib2_mbsfn_SubframeConfig2,0,sizeof(*sib2_mbsfn_SubframeConfig2));
+      sib2_mbsfn_SubframeConfig2->radioframeAllocationPeriod= LTE_MBSFN_SubframeConfig__radioframeAllocationPeriod_n4;
       sib2_mbsfn_SubframeConfig2->radioframeAllocationOffset= 1;
-      sib2_mbsfn_SubframeConfig2->subframeAllocation.present= MBSFN_SubframeConfig__subframeAllocation_PR_oneFrame;
+      sib2_mbsfn_SubframeConfig2->subframeAllocation.present= LTE_MBSFN_SubframeConfig__subframeAllocation_PR_oneFrame;
       sib2_mbsfn_SubframeConfig2->subframeAllocation.choice.oneFrame.buf= MALLOC(1);
       sib2_mbsfn_SubframeConfig2->subframeAllocation.choice.oneFrame.size= 1;
       sib2_mbsfn_SubframeConfig2->subframeAllocation.choice.oneFrame.bits_unused= 2;
-
       sib2_mbsfn_SubframeConfig2->subframeAllocation.choice.oneFrame.buf[0]=0x07<<2;
-     
 
       ASN_SEQUENCE_ADD(&MBSFNSubframeConfigList->list,sib2_mbsfn_SubframeConfig2);
     }
@@ -952,17 +1628,13 @@ uint8_t do_SIB23(uint8_t Mod_id,
 #else // no MBMS transmission
   (*sib2)->mbsfn_SubframeConfigList = NULL;
 #endif
-
-  (*sib2)->timeAlignmentTimerCommon=TimeAlignmentTimer_infinity;//TimeAlignmentTimer_sf5120;
-
+  (*sib2)->timeAlignmentTimerCommon=LTE_TimeAlignmentTimer_infinity;//TimeAlignmentTimer_sf5120;
   /// (*SIB3)
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
   (*sib3)->ext1 = NULL;
 #endif
-  (*sib3)->cellReselectionInfoCommon.q_Hyst=SystemInformationBlockType3__cellReselectionInfoCommon__q_Hyst_dB4;
-
+  (*sib3)->cellReselectionInfoCommon.q_Hyst=LTE_SystemInformationBlockType3__cellReselectionInfoCommon__q_Hyst_dB4;
   (*sib3)->cellReselectionInfoCommon.speedStateReselectionPars=NULL;
-
   (*sib3)->cellReselectionServingFreqInfo.s_NonIntraSearch=NULL;
   (*sib3)->cellReselectionServingFreqInfo.threshServingLow=31;
   (*sib3)->cellReselectionServingFreqInfo.cellReselectionPriority=7;
@@ -972,70 +1644,70 @@ uint8_t do_SIB23(uint8_t Mod_id,
   (*sib3)->intraFreqCellReselectionInfo.s_IntraSearch = CALLOC(1,sizeof(*(*sib3)->intraFreqCellReselectionInfo.s_IntraSearch));
   *(*sib3)->intraFreqCellReselectionInfo.s_IntraSearch = 31;
   (*sib3)->intraFreqCellReselectionInfo.allowedMeasBandwidth=CALLOC(1,sizeof(*(*sib3)->intraFreqCellReselectionInfo.allowedMeasBandwidth));
-
-  *(*sib3)->intraFreqCellReselectionInfo.allowedMeasBandwidth = AllowedMeasBandwidth_mbw6;
-
+  *(*sib3)->intraFreqCellReselectionInfo.allowedMeasBandwidth = LTE_AllowedMeasBandwidth_mbw6;
   (*sib3)->intraFreqCellReselectionInfo.presenceAntennaPort1 = 0;
   (*sib3)->intraFreqCellReselectionInfo.neighCellConfig.buf = CALLOC(8,1);
   (*sib3)->intraFreqCellReselectionInfo.neighCellConfig.size = 1;
   (*sib3)->intraFreqCellReselectionInfo.neighCellConfig.buf[0] = 1 << 6;
   (*sib3)->intraFreqCellReselectionInfo.neighCellConfig.bits_unused = 6;
   (*sib3)->intraFreqCellReselectionInfo.t_ReselectionEUTRA = 1;
-  (*sib3)->intraFreqCellReselectionInfo.t_ReselectionEUTRA_SF = (struct SpeedStateScaleFactors *)NULL;
+  (*sib3)->intraFreqCellReselectionInfo.t_ReselectionEUTRA_SF = (struct LTE_SpeedStateScaleFactors *)NULL;
+
+  (*sib3)->ext1 = CALLOC(1, sizeof(struct LTE_SystemInformationBlockType3__ext1));
+  (*sib3)->ext1->s_IntraSearch_v920 = CALLOC(1, sizeof(struct LTE_SystemInformationBlockType3__ext1__s_IntraSearch_v920));
+  (*sib3)->ext1->s_IntraSearch_v920->s_IntraSearchP_r9 = 31; // FIXME
+  (*sib3)->ext1->s_IntraSearch_v920->s_IntraSearchQ_r9 = 4;
+
+  (*sib3)->ext4 = CALLOC(1, sizeof(struct LTE_SystemInformationBlockType3__ext4));
+  (*sib3)->ext4->cellSelectionInfoCE_r13 = CALLOC(1, sizeof(LTE_CellSelectionInfoCE_r13_t));
+  (*sib3)->ext4->cellSelectionInfoCE_r13->q_RxLevMinCE_r13 = -70;
+  (*sib3)->ext4->cellSelectionInfoCE_r13->q_QualMinRSRQ_CE_r13 = NULL;
+  (*sib3)->ext4->t_ReselectionEUTRA_CE_r13 = CALLOC(1, sizeof(LTE_T_ReselectionEUTRA_CE_r13_t));
+  *(*sib3)->ext4->t_ReselectionEUTRA_CE_r13 = 2;
 
   // SIB13
   // fill in all elements of SIB13 if present
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
 
-  if (MBMS_flag > 0 ) {
+  if (configuration->eMBMS_configured > 0 ) {
     //  Notification for mcch change
-    (*sib13)->notificationConfig_r9.notificationRepetitionCoeff_r9= MBMS_NotificationConfig_r9__notificationRepetitionCoeff_r9_n2;
+    (*sib13)->notificationConfig_r9.notificationRepetitionCoeff_r9= LTE_MBMS_NotificationConfig_r9__notificationRepetitionCoeff_r9_n2;
     (*sib13)->notificationConfig_r9.notificationOffset_r9= 0;
     (*sib13)->notificationConfig_r9.notificationSF_Index_r9= 1;
-
     //  MBSFN-AreaInfoList
     MBSFNArea_list= &(*sib13)->mbsfn_AreaInfoList_r9;//CALLOC(1,sizeof(*MBSFNArea_list));
     memset(MBSFNArea_list,0,sizeof(*MBSFNArea_list));
     // MBSFN Area 1
     MBSFN_Area1= CALLOC(1, sizeof(*MBSFN_Area1));
     MBSFN_Area1->mbsfn_AreaId_r9= 1;
-    MBSFN_Area1->non_MBSFNregionLength= MBSFN_AreaInfo_r9__non_MBSFNregionLength_s2;
+    MBSFN_Area1->non_MBSFNregionLength= LTE_MBSFN_AreaInfo_r9__non_MBSFNregionLength_s2;
     MBSFN_Area1->notificationIndicator_r9= 0;
-    MBSFN_Area1->mcch_Config_r9.mcch_RepetitionPeriod_r9= MBSFN_AreaInfo_r9__mcch_Config_r9__mcch_RepetitionPeriod_r9_rf32;
+    MBSFN_Area1->mcch_Config_r9.mcch_RepetitionPeriod_r9= LTE_MBSFN_AreaInfo_r9__mcch_Config_r9__mcch_RepetitionPeriod_r9_rf32;
     MBSFN_Area1->mcch_Config_r9.mcch_Offset_r9= 1; // in accordance with mbsfn subframe configuration in sib2
-    MBSFN_Area1->mcch_Config_r9.mcch_ModificationPeriod_r9= MBSFN_AreaInfo_r9__mcch_Config_r9__mcch_ModificationPeriod_r9_rf512;
+    MBSFN_Area1->mcch_Config_r9.mcch_ModificationPeriod_r9= LTE_MBSFN_AreaInfo_r9__mcch_Config_r9__mcch_ModificationPeriod_r9_rf512;
     //  Subframe Allocation Info
     MBSFN_Area1->mcch_Config_r9.sf_AllocInfo_r9.buf= MALLOC(1);
     MBSFN_Area1->mcch_Config_r9.sf_AllocInfo_r9.size= 1;
-
     MBSFN_Area1->mcch_Config_r9.sf_AllocInfo_r9.buf[0]=0x20<<2;  // FDD: SF1
-    
-
     MBSFN_Area1->mcch_Config_r9.sf_AllocInfo_r9.bits_unused= 2;
-
-    MBSFN_Area1->mcch_Config_r9.signallingMCS_r9= MBSFN_AreaInfo_r9__mcch_Config_r9__signallingMCS_r9_n7;
-
+    MBSFN_Area1->mcch_Config_r9.signallingMCS_r9= LTE_MBSFN_AreaInfo_r9__mcch_Config_r9__signallingMCS_r9_n7;
     ASN_SEQUENCE_ADD(&MBSFNArea_list->list,MBSFN_Area1);
 
     //MBSFN Area 2: currently only activated for eMBMS relaying
-    if (MBMS_flag == 4 ) {
+    if (configuration->eMBMS_configured == 4 ) {
       MBSFN_Area2= CALLOC(1, sizeof(*MBSFN_Area2));
       MBSFN_Area2->mbsfn_AreaId_r9= 2;
-      MBSFN_Area2->non_MBSFNregionLength= MBSFN_AreaInfo_r9__non_MBSFNregionLength_s2;
+      MBSFN_Area2->non_MBSFNregionLength= LTE_MBSFN_AreaInfo_r9__non_MBSFNregionLength_s2;
       MBSFN_Area2->notificationIndicator_r9= 1;
-      MBSFN_Area2->mcch_Config_r9.mcch_RepetitionPeriod_r9= MBSFN_AreaInfo_r9__mcch_Config_r9__mcch_RepetitionPeriod_r9_rf32;
+      MBSFN_Area2->mcch_Config_r9.mcch_RepetitionPeriod_r9= LTE_MBSFN_AreaInfo_r9__mcch_Config_r9__mcch_RepetitionPeriod_r9_rf32;
       MBSFN_Area2->mcch_Config_r9.mcch_Offset_r9= 1;
-      MBSFN_Area2->mcch_Config_r9.mcch_ModificationPeriod_r9= MBSFN_AreaInfo_r9__mcch_Config_r9__mcch_ModificationPeriod_r9_rf512;
+      MBSFN_Area2->mcch_Config_r9.mcch_ModificationPeriod_r9= LTE_MBSFN_AreaInfo_r9__mcch_Config_r9__mcch_ModificationPeriod_r9_rf512;
       // Subframe Allocation Info
       MBSFN_Area2->mcch_Config_r9.sf_AllocInfo_r9.buf= MALLOC(1);
       MBSFN_Area2->mcch_Config_r9.sf_AllocInfo_r9.size= 1;
       MBSFN_Area2->mcch_Config_r9.sf_AllocInfo_r9.bits_unused= 2;
-
       MBSFN_Area2->mcch_Config_r9.sf_AllocInfo_r9.buf[0]=0x04<<2;  // FDD: SF6
-     
-
-      MBSFN_Area2->mcch_Config_r9.signallingMCS_r9= MBSFN_AreaInfo_r9__mcch_Config_r9__signallingMCS_r9_n7;
-
+      MBSFN_Area2->mcch_Config_r9.signallingMCS_r9= LTE_MBSFN_AreaInfo_r9__mcch_Config_r9__signallingMCS_r9_n7;
       ASN_SEQUENCE_ADD(&MBSFNArea_list->list,MBSFN_Area2);
     }
 
@@ -1043,353 +1715,318 @@ uint8_t do_SIB23(uint8_t Mod_id,
   }
 
 #endif
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+  if (configuration->SL_configured>0) {
+    //TTN - for D2D
+    // SIB18
+    //commRxPool_r12
+    (*sib18)->commConfig_r12 = CALLOC (1, sizeof(*(*sib18)->commConfig_r12));
+    SL_CommRxPoolList= &(*sib18)->commConfig_r12->commRxPool_r12;
+    memset(SL_CommRxPoolList,0,sizeof(*SL_CommRxPoolList));
+    SL_CommResourcePool = CALLOC(1, sizeof(*SL_CommResourcePool));
+    memset(SL_CommResourcePool,0,sizeof(*SL_CommResourcePool));
+    SL_CommResourcePool->sc_CP_Len_r12 = configuration->rxPool_sc_CP_Len[CC_id];
+    SL_CommResourcePool->sc_Period_r12 = configuration->rxPool_sc_Period[CC_id];
+    SL_CommResourcePool->data_CP_Len_r12  = configuration->rxPool_data_CP_Len[CC_id];
+    //sc_TF_ResourceConfig_r12
+    SL_CommResourcePool->sc_TF_ResourceConfig_r12.prb_Num_r12 = configuration->rxPool_ResourceConfig_prb_Num[CC_id];
+    SL_CommResourcePool->sc_TF_ResourceConfig_r12.prb_Start_r12 = configuration->rxPool_ResourceConfig_prb_Start[CC_id];
+    SL_CommResourcePool->sc_TF_ResourceConfig_r12.prb_End_r12 = configuration->rxPool_ResourceConfig_prb_End[CC_id];
+    SL_CommResourcePool->sc_TF_ResourceConfig_r12.offsetIndicator_r12.present = configuration->rxPool_ResourceConfig_offsetIndicator_present[CC_id];
+
+    if (SL_CommResourcePool->sc_TF_ResourceConfig_r12.offsetIndicator_r12.present == LTE_SL_OffsetIndicator_r12_PR_small_r12 ) {
+      SL_CommResourcePool->sc_TF_ResourceConfig_r12.offsetIndicator_r12.choice.small_r12 = configuration->rxPool_ResourceConfig_offsetIndicator_choice[CC_id] ;
+    } else if (SL_CommResourcePool->sc_TF_ResourceConfig_r12.offsetIndicator_r12.present == LTE_SL_OffsetIndicator_r12_PR_large_r12 ) {
+      SL_CommResourcePool->sc_TF_ResourceConfig_r12.offsetIndicator_r12.choice.large_r12 = configuration->rxPool_ResourceConfig_offsetIndicator_choice[CC_id] ;
+    }
 
+    SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.present = configuration->rxPool_ResourceConfig_subframeBitmap_present[CC_id];
+
+    if (SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.present == LTE_SubframeBitmapSL_r12_PR_bs4_r12) {
+      //for BS4
+      SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.size = configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
+      SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf  = (uint8_t *)configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
+      SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.bits_unused = configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
+    } else if (SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.present == LTE_SubframeBitmapSL_r12_PR_bs8_r12) {
+      //for BS8
+      SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs8_r12.size = configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
+      SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs8_r12.buf  = (uint8_t *)configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
+      SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs8_r12.bits_unused = configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
+    } else if (SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.present == LTE_SubframeBitmapSL_r12_PR_bs12_r12) {
+      //for BS12
+      SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs12_r12.size = configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
+      SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs12_r12.buf  = (uint8_t *)configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
+      SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs12_r12.bits_unused = configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
+    } else if (SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.present == LTE_SubframeBitmapSL_r12_PR_bs16_r12) {
+      //for BS16
+      SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs16_r12.size = configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
+      SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs16_r12.buf  = (uint8_t *)configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
+      SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs16_r12.bits_unused = configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
+    } else if (SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.present == LTE_SubframeBitmapSL_r12_PR_bs30_r12) {
+      //for BS30
+      SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs30_r12.size = configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
+      SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs30_r12.buf  = (uint8_t *)configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
+      SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs30_r12.bits_unused = configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
+    } else if (SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.present == LTE_SubframeBitmapSL_r12_PR_bs40_r12) {
+      //for BS40
+      SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.size = configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
+      SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.buf  = (uint8_t *)configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
+      SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.bits_unused = configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
+    } else if (SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.present == LTE_SubframeBitmapSL_r12_PR_bs42_r12) {
+      //for BS42
+      SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs42_r12.size = configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
+      SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs42_r12.buf  = (uint8_t *)configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
+      SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs42_r12.bits_unused = configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
+    }
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-  //TTN - for D2D
-  // SIB18
-  //commRxPool_r12
-  (*sib18)->commConfig_r12 = CALLOC (1, sizeof(*(*sib18)->commConfig_r12));
-  SL_CommRxPoolList= &(*sib18)->commConfig_r12->commRxPool_r12;
-  memset(SL_CommRxPoolList,0,sizeof(*SL_CommRxPoolList));
-
-  SL_CommResourcePool = CALLOC(1, sizeof(*SL_CommResourcePool));
-  memset(SL_CommResourcePool,0,sizeof(*SL_CommResourcePool));
-
-  SL_CommResourcePool->sc_CP_Len_r12 = configuration->rxPool_sc_CP_Len[CC_id];
-  SL_CommResourcePool->sc_Period_r12 = configuration->rxPool_sc_Period[CC_id];
-  SL_CommResourcePool->data_CP_Len_r12  = configuration->rxPool_data_CP_Len[CC_id];
-  //sc_TF_ResourceConfig_r12
-  SL_CommResourcePool->sc_TF_ResourceConfig_r12.prb_Num_r12 = configuration->rxPool_ResourceConfig_prb_Num[CC_id];
-  SL_CommResourcePool->sc_TF_ResourceConfig_r12.prb_Start_r12 = configuration->rxPool_ResourceConfig_prb_Start[CC_id];
-  SL_CommResourcePool->sc_TF_ResourceConfig_r12.prb_End_r12 = configuration->rxPool_ResourceConfig_prb_End[CC_id];
-  SL_CommResourcePool->sc_TF_ResourceConfig_r12.offsetIndicator_r12.present = configuration->rxPool_ResourceConfig_offsetIndicator_present[CC_id];
-
-  if (SL_CommResourcePool->sc_TF_ResourceConfig_r12.offsetIndicator_r12.present == SL_OffsetIndicator_r12_PR_small_r12 ) {
-     SL_CommResourcePool->sc_TF_ResourceConfig_r12.offsetIndicator_r12.choice.small_r12 = configuration->rxPool_ResourceConfig_offsetIndicator_choice[CC_id] ;
-  } else if (SL_CommResourcePool->sc_TF_ResourceConfig_r12.offsetIndicator_r12.present == SL_OffsetIndicator_r12_PR_large_r12 ){
-     SL_CommResourcePool->sc_TF_ResourceConfig_r12.offsetIndicator_r12.choice.large_r12 = configuration->rxPool_ResourceConfig_offsetIndicator_choice[CC_id] ;
-  }
-
-  SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.present = configuration->rxPool_ResourceConfig_subframeBitmap_present[CC_id];
-  if (SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.present == SubframeBitmapSL_r12_PR_bs4_r12){
-     //for BS4
-     SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.size = configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
-     SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf  = (uint8_t *)configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
-     SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.bits_unused = configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
-  } else if (SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.present == SubframeBitmapSL_r12_PR_bs8_r12){
-     //for BS8
-     SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs8_r12.size = configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
-     SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs8_r12.buf  = (uint8_t *)configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
-     SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs8_r12.bits_unused = configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
-  } else if (SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.present == SubframeBitmapSL_r12_PR_bs12_r12){
-     //for BS12
-     SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs12_r12.size = configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
-     SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs12_r12.buf  = (uint8_t *)configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
-     SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs12_r12.bits_unused = configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
-  }else if (SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.present == SubframeBitmapSL_r12_PR_bs16_r12){
-     //for BS16
-     SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs16_r12.size = configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
-     SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs16_r12.buf  = (uint8_t *)configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
-     SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs16_r12.bits_unused = configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
-  }else if (SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.present == SubframeBitmapSL_r12_PR_bs30_r12){
-     //for BS30
-     SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs30_r12.size = configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
-     SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs30_r12.buf  = (uint8_t *)configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
-     SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs30_r12.bits_unused = configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
-  }else if (SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.present == SubframeBitmapSL_r12_PR_bs40_r12){
-     //for BS40
-     SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.size = configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
-     SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.buf  = (uint8_t *)configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
-     SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.bits_unused = configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
-  }else if (SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.present == SubframeBitmapSL_r12_PR_bs42_r12){
-     //for BS42
-     SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs42_r12.size = configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
-     SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs42_r12.buf  = (uint8_t *)configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
-     SL_CommResourcePool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs42_r12.bits_unused = configuration->rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
-  }
-
-  //dataHoppingConfig_r12
-  SL_CommResourcePool->dataHoppingConfig_r12.hoppingParameter_r12 = 0;
-  SL_CommResourcePool->dataHoppingConfig_r12.numSubbands_r12  =  SL_HoppingConfigComm_r12__numSubbands_r12_ns1;
-  SL_CommResourcePool->dataHoppingConfig_r12.rb_Offset_r12 = 0;
-
-  //ue_SelectedResourceConfig_r12
-  SL_CommResourcePool->ue_SelectedResourceConfig_r12 = CALLOC (1, sizeof (*SL_CommResourcePool->ue_SelectedResourceConfig_r12));
-  SL_CommResourcePool->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.prb_Num_r12 = 20;
-  SL_CommResourcePool->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.prb_Start_r12 = 5;
-  SL_CommResourcePool->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.prb_End_r12 = 44;
-  SL_CommResourcePool->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.offsetIndicator_r12.present = SL_OffsetIndicator_r12_PR_small_r12;
-  SL_CommResourcePool->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.offsetIndicator_r12.choice.small_r12 = 0 ;
-  SL_CommResourcePool->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.present = SubframeBitmapSL_r12_PR_bs40_r12;
-  SL_CommResourcePool->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.size = 5;
-  SL_CommResourcePool->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf  = CALLOC(1,5);
-  SL_CommResourcePool->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.bits_unused = 0;
-  SL_CommResourcePool->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf[0] = 0xF0;
-  SL_CommResourcePool->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf[1] = 0xFF;
-  SL_CommResourcePool->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf[2] = 0xFF;
-  SL_CommResourcePool->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf[3] = 0xFF;
-  SL_CommResourcePool->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf[4] = 0xFF;
-  //SL_CommResourcePool->ue_SelectedResourceConfig_r12->trpt_Subset_r12 = CALLOC (1, sizeof(*SL_CommResourcePool->ue_SelectedResourceConfig_r12->trpt_Subset_r12));
-  //rxParametersNCell_r12
-  SL_CommResourcePool->rxParametersNCell_r12 = CALLOC (1, sizeof (*SL_CommResourcePool->rxParametersNCell_r12));
-  SL_CommResourcePool->rxParametersNCell_r12->tdd_Config_r12 = CALLOC (1, sizeof (*SL_CommResourcePool->rxParametersNCell_r12->tdd_Config_r12));
-  SL_CommResourcePool->rxParametersNCell_r12->tdd_Config_r12->subframeAssignment = 0 ;
-  SL_CommResourcePool->rxParametersNCell_r12->tdd_Config_r12->specialSubframePatterns = 0;
-  SL_CommResourcePool->rxParametersNCell_r12->syncConfigIndex_r12 = 0;
-  //txParameters_r12
-  SL_CommResourcePool->txParameters_r12 = CALLOC (1, sizeof (*SL_CommResourcePool->txParameters_r12));
-  SL_CommResourcePool->txParameters_r12->sc_TxParameters_r12.alpha_r12 = Alpha_r12_al0;
-  SL_CommResourcePool->txParameters_r12->sc_TxParameters_r12.p0_r12 = 0;
-
-  SL_CommResourcePool->ext1 = NULL ;
-  //end SL_CommResourcePool
-  //add SL_CommResourcePool to SL_CommRxPoolList
-  ASN_SEQUENCE_ADD(&SL_CommRxPoolList->list,SL_CommResourcePool);
-  //end commRxPool_r12
-
-  //TODO:  commTxPoolNormalCommon_r12, similar to commRxPool_r12
-  //TODO: commTxPoolExceptional_r12
-  //TODO: commSyncConfig_r12
-  // may add commTxResourceUC-ReqAllowed with Ext1
-  (*sib18)->ext1 = NULL;
-  (*sib18)->lateNonCriticalExtension = NULL;
-  // end SIB18
-
-  // SIB19
-  // fill in all elements of SIB19 if present
-
-  //discConfig_r12
-  (*sib19)->discConfig_r12 = CALLOC (1, sizeof(*(*sib19)->discConfig_r12));
-  SL_DiscRxPoolList = &(*sib19)->discConfig_r12->discRxPool_r12;
-  memset(SL_DiscRxPoolList,0,sizeof(*SL_DiscRxPoolList));
-  //fill SL_DiscResourcePool
-  SL_DiscResourcePool = CALLOC(1, sizeof(*SL_DiscResourcePool));
-
-  SL_DiscResourcePool->cp_Len_r12 = configuration->discRxPool_cp_Len[CC_id];
-  SL_DiscResourcePool->discPeriod_r12 = configuration->discRxPool_discPeriod[CC_id];
-  //sc_TF_ResourceConfig_r12
-  SL_DiscResourcePool->numRetx_r12 = configuration->discRxPool_numRetx[CC_id];
-  SL_DiscResourcePool->numRepetition_r12 = configuration->discRxPool_numRepetition[CC_id];
-  SL_DiscResourcePool->tf_ResourceConfig_r12.prb_Num_r12 = configuration->discRxPool_ResourceConfig_prb_Num[CC_id];
-  SL_DiscResourcePool->tf_ResourceConfig_r12.prb_Start_r12 = configuration->discRxPool_ResourceConfig_prb_Start[CC_id];
-  SL_DiscResourcePool->tf_ResourceConfig_r12.prb_End_r12 = configuration->discRxPool_ResourceConfig_prb_End[CC_id];
-  SL_DiscResourcePool->tf_ResourceConfig_r12.offsetIndicator_r12.present = configuration->discRxPool_ResourceConfig_offsetIndicator_present[CC_id];
-  if (SL_DiscResourcePool->tf_ResourceConfig_r12.offsetIndicator_r12.present == SL_OffsetIndicator_r12_PR_small_r12 ) {
-     SL_DiscResourcePool->tf_ResourceConfig_r12.offsetIndicator_r12.choice.small_r12 = configuration->discRxPool_ResourceConfig_offsetIndicator_choice[CC_id] ;
-  } else if (SL_DiscResourcePool->tf_ResourceConfig_r12.offsetIndicator_r12.present == SL_OffsetIndicator_r12_PR_large_r12 ){
-     SL_DiscResourcePool->tf_ResourceConfig_r12.offsetIndicator_r12.choice.large_r12 = configuration->discRxPool_ResourceConfig_offsetIndicator_choice[CC_id] ;
-  }
-  SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.present = configuration->discRxPool_ResourceConfig_subframeBitmap_present[CC_id];
-  if (SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.present == SubframeBitmapSL_r12_PR_bs4_r12){
-     //for BS4
-     SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.size = configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
-     SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf  =  (uint8_t *)configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
-     SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.bits_unused = configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
-  } else if (SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.present == SubframeBitmapSL_r12_PR_bs8_r12){
-     //for BS8
-     SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs8_r12.size = configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
-     SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs8_r12.buf  = (uint8_t *)configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
-     SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs8_r12.bits_unused = configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
-  } else if (SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.present == SubframeBitmapSL_r12_PR_bs12_r12){
-     //for BS12
-     SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs12_r12.size = configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
-     SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs12_r12.buf  = (uint8_t *)configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
-     SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs12_r12.bits_unused = configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
-  }else if (SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.present == SubframeBitmapSL_r12_PR_bs16_r12){
-     //for BS16
-     SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs16_r12.size = configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
-     SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs16_r12.buf  = (uint8_t *)configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
-     SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs16_r12.bits_unused = configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
-  }else if (SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.present == SubframeBitmapSL_r12_PR_bs30_r12){
-     //for BS30
-     SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs30_r12.size = configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
-     SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs30_r12.buf  = (uint8_t *)configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
-     SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs30_r12.bits_unused = configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
-  }else if (SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.present == SubframeBitmapSL_r12_PR_bs40_r12){
-     //for BS40
-     SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.size = configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
-     SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.buf  = (uint8_t *)configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
-     SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.bits_unused = configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
-  }else if (SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.present == SubframeBitmapSL_r12_PR_bs42_r12){
-     //for BS42
-     SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs42_r12.size = configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
-     SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs42_r12.buf  = (uint8_t *)configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
-     SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs42_r12.bits_unused = configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
-  }
-
-  //add SL_DiscResourcePool to SL_DiscRxPoolList
-  ASN_SEQUENCE_ADD(&SL_DiscRxPoolList->list,SL_DiscResourcePool);
+    //dataHoppingConfig_r12
+    SL_CommResourcePool->dataHoppingConfig_r12.hoppingParameter_r12 = 0;
+    SL_CommResourcePool->dataHoppingConfig_r12.numSubbands_r12  =  LTE_SL_HoppingConfigComm_r12__numSubbands_r12_ns1;
+    SL_CommResourcePool->dataHoppingConfig_r12.rb_Offset_r12 = 0;
+    //ue_SelectedResourceConfig_r12
+    SL_CommResourcePool->ue_SelectedResourceConfig_r12 = CALLOC (1, sizeof (*SL_CommResourcePool->ue_SelectedResourceConfig_r12));
+    SL_CommResourcePool->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.prb_Num_r12 = 20;
+    SL_CommResourcePool->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.prb_Start_r12 = 5;
+    SL_CommResourcePool->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.prb_End_r12 = 44;
+    SL_CommResourcePool->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.offsetIndicator_r12.present = LTE_SL_OffsetIndicator_r12_PR_small_r12;
+    SL_CommResourcePool->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.offsetIndicator_r12.choice.small_r12 = 0 ;
+    SL_CommResourcePool->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.present = LTE_SubframeBitmapSL_r12_PR_bs40_r12;
+    SL_CommResourcePool->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.size = 5;
+    SL_CommResourcePool->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf  = CALLOC(1,5);
+    SL_CommResourcePool->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.bits_unused = 0;
+    SL_CommResourcePool->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf[0] = 0xF0;
+    SL_CommResourcePool->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf[1] = 0xFF;
+    SL_CommResourcePool->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf[2] = 0xFF;
+    SL_CommResourcePool->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf[3] = 0xFF;
+    SL_CommResourcePool->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf[4] = 0xFF;
+    //SL_CommResourcePool->ue_SelectedResourceConfig_r12->trpt_Subset_r12 = CALLOC (1, sizeof(*SL_CommResourcePool->ue_SelectedResourceConfig_r12->trpt_Subset_r12));
+    //rxParametersNCell_r12
+    SL_CommResourcePool->rxParametersNCell_r12 = CALLOC (1, sizeof (*SL_CommResourcePool->rxParametersNCell_r12));
+    SL_CommResourcePool->rxParametersNCell_r12->tdd_Config_r12 = CALLOC (1, sizeof (*SL_CommResourcePool->rxParametersNCell_r12->tdd_Config_r12));
+    SL_CommResourcePool->rxParametersNCell_r12->tdd_Config_r12->subframeAssignment = 0 ;
+    SL_CommResourcePool->rxParametersNCell_r12->tdd_Config_r12->specialSubframePatterns = 0;
+    SL_CommResourcePool->rxParametersNCell_r12->syncConfigIndex_r12 = 0;
+    //txParameters_r12
+    SL_CommResourcePool->txParameters_r12 = CALLOC (1, sizeof (*SL_CommResourcePool->txParameters_r12));
+    SL_CommResourcePool->txParameters_r12->sc_TxParameters_r12.alpha_r12 = LTE_Alpha_r12_al0;
+    SL_CommResourcePool->txParameters_r12->sc_TxParameters_r12.p0_r12 = 0;
+    SL_CommResourcePool->ext1 = NULL ;
+    //end SL_CommResourcePool
+    //add SL_CommResourcePool to SL_CommRxPoolList
+    ASN_SEQUENCE_ADD(&SL_CommRxPoolList->list,SL_CommResourcePool);
+    //end commRxPool_r12
+    //TODO:  commTxPoolNormalCommon_r12, similar to commRxPool_r12
+    //TODO: commTxPoolExceptional_r12
+    //TODO: commSyncConfig_r12
+    // may add commTxResourceUC-ReqAllowed with Ext1
+    (*sib18)->ext1 = NULL;
+    (*sib18)->lateNonCriticalExtension = NULL;
+    // end SIB18
+    // SIB19
+    // fill in all elements of SIB19 if present
+    //discConfig_r12
+    (*sib19)->discConfig_r12 = CALLOC (1, sizeof(*(*sib19)->discConfig_r12));
+    SL_DiscRxPoolList = &(*sib19)->discConfig_r12->discRxPool_r12;
+    memset(SL_DiscRxPoolList,0,sizeof(*SL_DiscRxPoolList));
+    //fill SL_DiscResourcePool
+    SL_DiscResourcePool = CALLOC(1, sizeof(*SL_DiscResourcePool));
+    SL_DiscResourcePool->cp_Len_r12 = configuration->discRxPool_cp_Len[CC_id];
+    SL_DiscResourcePool->discPeriod_r12 = configuration->discRxPool_discPeriod[CC_id];
+    //sc_TF_ResourceConfig_r12
+    SL_DiscResourcePool->numRetx_r12 = configuration->discRxPool_numRetx[CC_id];
+    SL_DiscResourcePool->numRepetition_r12 = configuration->discRxPool_numRepetition[CC_id];
+    SL_DiscResourcePool->tf_ResourceConfig_r12.prb_Num_r12 = configuration->discRxPool_ResourceConfig_prb_Num[CC_id];
+    SL_DiscResourcePool->tf_ResourceConfig_r12.prb_Start_r12 = configuration->discRxPool_ResourceConfig_prb_Start[CC_id];
+    SL_DiscResourcePool->tf_ResourceConfig_r12.prb_End_r12 = configuration->discRxPool_ResourceConfig_prb_End[CC_id];
+    SL_DiscResourcePool->tf_ResourceConfig_r12.offsetIndicator_r12.present = configuration->discRxPool_ResourceConfig_offsetIndicator_present[CC_id];
+
+    if (SL_DiscResourcePool->tf_ResourceConfig_r12.offsetIndicator_r12.present == LTE_SL_OffsetIndicator_r12_PR_small_r12 ) {
+      SL_DiscResourcePool->tf_ResourceConfig_r12.offsetIndicator_r12.choice.small_r12 = configuration->discRxPool_ResourceConfig_offsetIndicator_choice[CC_id] ;
+    } else if (SL_DiscResourcePool->tf_ResourceConfig_r12.offsetIndicator_r12.present == LTE_SL_OffsetIndicator_r12_PR_large_r12 ) {
+      SL_DiscResourcePool->tf_ResourceConfig_r12.offsetIndicator_r12.choice.large_r12 = configuration->discRxPool_ResourceConfig_offsetIndicator_choice[CC_id] ;
+    }
 
-/*
-  //for DiscRxPoolPS
-  (*sib19)->ext1 = CALLOC (1, sizeof(*(*sib19)->ext1));
-  (*sib19)->ext1->discConfigPS_13 = CALLOC (1, sizeof(*((*sib19)->ext1->discConfigPS_13)));
-
-  SL_DiscRxPoolPSList = &(*sib19)->ext1->discConfigPS_13->discRxPoolPS_r13;
-  memset(SL_DiscRxPoolPSList,0,sizeof(*SL_DiscRxPoolPSList));
-  //fill SL_DiscResourcePool
-  SL_DiscResourcePoolPS = CALLOC(1, sizeof(*SL_DiscResourcePoolPS));
-
-  SL_DiscResourcePoolPS->cp_Len_r12 = configuration->discRxPoolPS_cp_Len[CC_id];
-  SL_DiscResourcePoolPS->discPeriod_r12 = configuration->discRxPoolPS_discPeriod[CC_id];
-  //sc_TF_ResourceConfig_r12
-  SL_DiscResourcePoolPS->numRetx_r12 = configuration->discRxPoolPS_numRetx[CC_id];
-  SL_DiscResourcePoolPS->numRepetition_r12 =  configuration->discRxPoolPS_numRepetition[CC_id];
-
-  SL_DiscResourcePoolPS->tf_ResourceConfig_r12.prb_Num_r12 = configuration->discRxPoolPS_ResourceConfig_prb_Num[CC_id];
-  SL_DiscResourcePoolPS->tf_ResourceConfig_r12.prb_Start_r12 = configuration->discRxPoolPS_ResourceConfig_prb_Start[CC_id];
-  SL_DiscResourcePoolPS->tf_ResourceConfig_r12.prb_End_r12 = configuration->discRxPoolPS_ResourceConfig_prb_End[CC_id];
-
-  SL_DiscResourcePoolPS->tf_ResourceConfig_r12.offsetIndicator_r12.present = configuration->discRxPoolPS_ResourceConfig_offsetIndicator_present[CC_id];
-  if (SL_DiscResourcePoolPS->tf_ResourceConfig_r12.offsetIndicator_r12.present == SL_OffsetIndicator_r12_PR_small_r12 ) {
-     SL_DiscResourcePoolPS->tf_ResourceConfig_r12.offsetIndicator_r12.choice.small_r12 = configuration->discRxPoolPS_ResourceConfig_offsetIndicator_choice[CC_id] ;
-  } else if (SL_DiscResourcePoolPS->tf_ResourceConfig_r12.offsetIndicator_r12.present == SL_OffsetIndicator_r12_PR_large_r12 ){
-     SL_DiscResourcePoolPS->tf_ResourceConfig_r12.offsetIndicator_r12.choice.large_r12 = configuration->discRxPoolPS_ResourceConfig_offsetIndicator_choice[CC_id] ;
-  }
-
-  SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.present = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_present[CC_id];
-  if (SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.present == SubframeBitmapSL_r12_PR_bs4_r12){
-     //for BS4
-     SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.size = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
-     SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf  = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
-     SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.bits_unused = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
-  } else if (SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.present == SubframeBitmapSL_r12_PR_bs8_r12){
-     //for BS8
-     SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs8_r12.size = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
-     SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs8_r12.buf  = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
-     SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs8_r12.bits_unused = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
-  } else if (SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.present == SubframeBitmapSL_r12_PR_bs12_r12){
-     //for BS12
-     SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs12_r12.size = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
-     SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs12_r12.buf  = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
-     SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs12_r12.bits_unused = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
-  }else if (SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.present == SubframeBitmapSL_r12_PR_bs16_r12){
-     //for BS16
-     SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs16_r12.size = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
-     SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs16_r12.buf  = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
-     SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs16_r12.bits_unused = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
-  }else if (SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.present == SubframeBitmapSL_r12_PR_bs30_r12){
-     //for BS30
-     SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs30_r12.size = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
-     SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs30_r12.buf  = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
-     SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs30_r12.bits_unused = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
-  }else if (SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.present == SubframeBitmapSL_r12_PR_bs40_r12){
-     //for BS40
-     SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.size = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
-     SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.buf  = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
-     SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.bits_unused = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
-  }else if (SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.present == SubframeBitmapSL_r12_PR_bs42_r12){
-     //for BS42
-     SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs42_r12.size = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
-     SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs42_r12.buf  = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
-     SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs42_r12.bits_unused = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
-  }
-
-  //add SL_DiscResourcePool to SL_DiscRxPoolList
-  ASN_SEQUENCE_ADD(&SL_DiscRxPoolPSList->list,SL_DiscResourcePoolPS);
-*/
-
-  (*sib19)->lateNonCriticalExtension = NULL;
-  //end SIB19
-
-  //SIB21
-  (*sib21)->sl_V2X_ConfigCommon_r14 = CALLOC (1, sizeof(*(*sib21)->sl_V2X_ConfigCommon_r14));
-  //SL_V2X_ConfigCommon= (*sib21)->sl_V2X_ConfigCommon_r14;
-  memset((*sib21)->sl_V2X_ConfigCommon_r14,0,sizeof(*(*sib21)->sl_V2X_ConfigCommon_r14));
-
-  struct SL_CommRxPoolListV2X_r14 *SL_CommRxPoolListV2X;
-  struct SL_CommResourcePoolV2X_r14 *SL_CommResourcePoolV2X;
-  (*sib21)->sl_V2X_ConfigCommon_r14->v2x_CommRxPool_r14 = CALLOC(1, sizeof(*(*sib21)->sl_V2X_ConfigCommon_r14->v2x_CommRxPool_r14));
-  SL_CommRxPoolListV2X = (*sib21)->sl_V2X_ConfigCommon_r14->v2x_CommRxPool_r14;
-
-  SL_CommResourcePoolV2X = CALLOC(1, sizeof(*SL_CommResourcePoolV2X));
-  memset(SL_CommResourcePoolV2X,0,sizeof(*SL_CommResourcePoolV2X));
-
-  SL_CommResourcePoolV2X->sl_OffsetIndicator_r14 = CALLOC(1, sizeof(*SL_CommResourcePoolV2X->sl_OffsetIndicator_r14));
-  SL_CommResourcePoolV2X->sl_OffsetIndicator_r14->present  = SL_OffsetIndicator_r12_PR_small_r12;
-  SL_CommResourcePoolV2X->sl_OffsetIndicator_r14->choice.small_r12 = 0;
-  SL_CommResourcePoolV2X->sl_Subframe_r14.present = SubframeBitmapSL_r14_PR_bs40_r14;
-  SL_CommResourcePoolV2X->sl_Subframe_r14.choice.bs40_r14.size =  5;
-  SL_CommResourcePoolV2X->sl_Subframe_r14.choice.bs40_r14.buf =  CALLOC(1,5);
-  SL_CommResourcePoolV2X->sl_Subframe_r14.choice.bs40_r14.bits_unused = 0;
-  SL_CommResourcePoolV2X->sl_Subframe_r14.choice.bs40_r14.buf[0] = 0xF0;
-  SL_CommResourcePoolV2X->sl_Subframe_r14.choice.bs40_r14.buf[1] = 0xFF;
-  SL_CommResourcePoolV2X->sl_Subframe_r14.choice.bs40_r14.buf[2] = 0xFF;
-  SL_CommResourcePoolV2X->sl_Subframe_r14.choice.bs40_r14.buf[3] = 0xFF;
-  SL_CommResourcePoolV2X->sl_Subframe_r14.choice.bs40_r14.buf[4] = 0xFF;
-
-  SL_CommResourcePoolV2X->adjacencyPSCCH_PSSCH_r14 = 1;
-  SL_CommResourcePoolV2X->sizeSubchannel_r14 = 10;
-  SL_CommResourcePoolV2X->numSubchannel_r14 =  5;
-  SL_CommResourcePoolV2X->startRB_Subchannel_r14 = 10;
-
-  //rxParametersNCell_r12
-  SL_CommResourcePoolV2X->rxParametersNCell_r14 = CALLOC (1, sizeof (*SL_CommResourcePoolV2X->rxParametersNCell_r14));
-  SL_CommResourcePoolV2X->rxParametersNCell_r14->tdd_Config_r14 = CALLOC (1, sizeof (*SL_CommResourcePoolV2X->rxParametersNCell_r14->tdd_Config_r14));
-  SL_CommResourcePoolV2X->rxParametersNCell_r14->tdd_Config_r14->subframeAssignment = 0 ;
-  SL_CommResourcePoolV2X->rxParametersNCell_r14->tdd_Config_r14->specialSubframePatterns = 0;
-  SL_CommResourcePoolV2X->rxParametersNCell_r14->syncConfigIndex_r14 = 0;
-
-  ASN_SEQUENCE_ADD(&SL_CommRxPoolListV2X->list,SL_CommResourcePoolV2X);
-  //end SIB21
-#endif
- 
+    SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.present = configuration->discRxPool_ResourceConfig_subframeBitmap_present[CC_id];
+
+    if (SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.present == LTE_SubframeBitmapSL_r12_PR_bs4_r12) {
+      //for BS4
+      SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.size = configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
+      SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf  =  (uint8_t *)configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
+      SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.bits_unused = configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
+    } else if (SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.present == LTE_SubframeBitmapSL_r12_PR_bs8_r12) {
+      //for BS8
+      SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs8_r12.size = configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
+      SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs8_r12.buf  = (uint8_t *)configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
+      SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs8_r12.bits_unused = configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
+    } else if (SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.present == LTE_SubframeBitmapSL_r12_PR_bs12_r12) {
+      //for BS12
+      SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs12_r12.size = configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
+      SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs12_r12.buf  = (uint8_t *)configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
+      SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs12_r12.bits_unused = configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
+    } else if (SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.present == LTE_SubframeBitmapSL_r12_PR_bs16_r12) {
+      //for BS16
+      SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs16_r12.size = configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
+      SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs16_r12.buf  = (uint8_t *)configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
+      SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs16_r12.bits_unused = configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
+    } else if (SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.present == LTE_SubframeBitmapSL_r12_PR_bs30_r12) {
+      //for BS30
+      SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs30_r12.size = configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
+      SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs30_r12.buf  = (uint8_t *)configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
+      SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs30_r12.bits_unused = configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
+    } else if (SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.present == LTE_SubframeBitmapSL_r12_PR_bs40_r12) {
+      //for BS40
+      SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.size = configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
+      SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.buf  = (uint8_t *)configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
+      SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.bits_unused = configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
+    } else if (SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.present == LTE_SubframeBitmapSL_r12_PR_bs42_r12) {
+      //for BS42
+      SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs42_r12.size = configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
+      SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs42_r12.buf  = (uint8_t *)configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
+      SL_DiscResourcePool->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs42_r12.bits_unused = configuration->discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
+    }
 
-  bcch_message->message.present = BCCH_DL_SCH_MessageType_PR_c1;
-  bcch_message->message.choice.c1.present = BCCH_DL_SCH_MessageType__c1_PR_systemInformation;
+    //add SL_DiscResourcePool to SL_DiscRxPoolList
+    ASN_SEQUENCE_ADD(&SL_DiscRxPoolList->list,SL_DiscResourcePool);
+    /*
+    //for DiscRxPoolPS
+    (*sib19)->ext1 = CALLOC (1, sizeof(*(*sib19)->ext1));
+    (*sib19)->ext1->discConfigPS_13 = CALLOC (1, sizeof(*((*sib19)->ext1->discConfigPS_13)));
+
+    SL_DiscRxPoolPSList = &(*sib19)->ext1->discConfigPS_13->discRxPoolPS_r13;
+    memset(SL_DiscRxPoolPSList,0,sizeof(*SL_DiscRxPoolPSList));
+    //fill SL_DiscResourcePool
+    SL_DiscResourcePoolPS = CALLOC(1, sizeof(*SL_DiscResourcePoolPS));
+
+    SL_DiscResourcePoolPS->cp_Len_r12 = configuration->discRxPoolPS_cp_Len[CC_id];
+    SL_DiscResourcePoolPS->discPeriod_r12 = configuration->discRxPoolPS_discPeriod[CC_id];
+    //sc_TF_ResourceConfig_r12
+    SL_DiscResourcePoolPS->numRetx_r12 = configuration->discRxPoolPS_numRetx[CC_id];
+    SL_DiscResourcePoolPS->numRepetition_r12 =  configuration->discRxPoolPS_numRepetition[CC_id];
+
+    SL_DiscResourcePoolPS->tf_ResourceConfig_r12.prb_Num_r12 = configuration->discRxPoolPS_ResourceConfig_prb_Num[CC_id];
+    SL_DiscResourcePoolPS->tf_ResourceConfig_r12.prb_Start_r12 = configuration->discRxPoolPS_ResourceConfig_prb_Start[CC_id];
+    SL_DiscResourcePoolPS->tf_ResourceConfig_r12.prb_End_r12 = configuration->discRxPoolPS_ResourceConfig_prb_End[CC_id];
+
+    SL_DiscResourcePoolPS->tf_ResourceConfig_r12.offsetIndicator_r12.present = configuration->discRxPoolPS_ResourceConfig_offsetIndicator_present[CC_id];
+    if (SL_DiscResourcePoolPS->tf_ResourceConfig_r12.offsetIndicator_r12.present == SL_OffsetIndicator_r12_PR_small_r12 ) {
+    SL_DiscResourcePoolPS->tf_ResourceConfig_r12.offsetIndicator_r12.choice.small_r12 = configuration->discRxPoolPS_ResourceConfig_offsetIndicator_choice[CC_id] ;
+    } else if (SL_DiscResourcePoolPS->tf_ResourceConfig_r12.offsetIndicator_r12.present == SL_OffsetIndicator_r12_PR_large_r12 ){
+    SL_DiscResourcePoolPS->tf_ResourceConfig_r12.offsetIndicator_r12.choice.large_r12 = configuration->discRxPoolPS_ResourceConfig_offsetIndicator_choice[CC_id] ;
+    }
+
+    SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.present = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_present[CC_id];
+    if (SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.present == SubframeBitmapSL_r12_PR_bs4_r12){
+    //for BS4
+    SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.size = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
+    SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf  = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
+    SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.bits_unused = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
+    } else if (SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.present == SubframeBitmapSL_r12_PR_bs8_r12){
+    //for BS8
+    SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs8_r12.size = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
+    SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs8_r12.buf  = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
+    SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs8_r12.bits_unused = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
+    } else if (SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.present == SubframeBitmapSL_r12_PR_bs12_r12){
+    //for BS12
+    SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs12_r12.size = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
+    SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs12_r12.buf  = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
+    SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs12_r12.bits_unused = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
+    }else if (SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.present == SubframeBitmapSL_r12_PR_bs16_r12){
+    //for BS16
+    SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs16_r12.size = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
+    SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs16_r12.buf  = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
+    SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs16_r12.bits_unused = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
+    }else if (SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.present == SubframeBitmapSL_r12_PR_bs30_r12){
+    //for BS30
+    SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs30_r12.size = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
+    SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs30_r12.buf  = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
+    SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs30_r12.bits_unused = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
+    }else if (SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.present == SubframeBitmapSL_r12_PR_bs40_r12){
+    //for BS40
+    SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.size = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
+    SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.buf  = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
+    SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.bits_unused = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
+    }else if (SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.present == SubframeBitmapSL_r12_PR_bs42_r12){
+    //for BS42
+    SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs42_r12.size = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_size[CC_id];
+    SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs42_r12.buf  = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_buf[CC_id];;
+    SL_DiscResourcePoolPS->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs42_r12.bits_unused = configuration->discRxPoolPS_ResourceConfig_subframeBitmap_choice_bs_bits_unused[CC_id];
+    }
 
+    //add SL_DiscResourcePool to SL_DiscRxPoolList
+    ASN_SEQUENCE_ADD(&SL_DiscRxPoolPSList->list,SL_DiscResourcePoolPS);
+    */
+    (*sib19)->lateNonCriticalExtension = NULL;
+    //end SIB19
+    //SIB21
+    (*sib21)->sl_V2X_ConfigCommon_r14 = CALLOC (1, sizeof(*(*sib21)->sl_V2X_ConfigCommon_r14));
+    //SL_V2X_ConfigCommon= (*sib21)->sl_V2X_ConfigCommon_r14;
+    memset((*sib21)->sl_V2X_ConfigCommon_r14,0,sizeof(*(*sib21)->sl_V2X_ConfigCommon_r14));
+    struct LTE_SL_CommRxPoolListV2X_r14 *SL_CommRxPoolListV2X;
+    struct LTE_SL_CommResourcePoolV2X_r14 *SL_CommResourcePoolV2X;
+    (*sib21)->sl_V2X_ConfigCommon_r14->v2x_CommRxPool_r14 = CALLOC(1, sizeof(*(*sib21)->sl_V2X_ConfigCommon_r14->v2x_CommRxPool_r14));
+    SL_CommRxPoolListV2X = (*sib21)->sl_V2X_ConfigCommon_r14->v2x_CommRxPool_r14;
+    SL_CommResourcePoolV2X = CALLOC(1, sizeof(*SL_CommResourcePoolV2X));
+    memset(SL_CommResourcePoolV2X,0,sizeof(*SL_CommResourcePoolV2X));
+    SL_CommResourcePoolV2X->sl_OffsetIndicator_r14 = CALLOC(1, sizeof(*SL_CommResourcePoolV2X->sl_OffsetIndicator_r14));
+    SL_CommResourcePoolV2X->sl_OffsetIndicator_r14->present  = LTE_SL_OffsetIndicator_r12_PR_small_r12;
+    SL_CommResourcePoolV2X->sl_OffsetIndicator_r14->choice.small_r12 = 0;
+    SL_CommResourcePoolV2X->sl_Subframe_r14.present = LTE_SubframeBitmapSL_r14_PR_bs40_r14;
+    SL_CommResourcePoolV2X->sl_Subframe_r14.choice.bs40_r14.size =  5;
+    SL_CommResourcePoolV2X->sl_Subframe_r14.choice.bs40_r14.buf =  CALLOC(1,5);
+    SL_CommResourcePoolV2X->sl_Subframe_r14.choice.bs40_r14.bits_unused = 0;
+    SL_CommResourcePoolV2X->sl_Subframe_r14.choice.bs40_r14.buf[0] = 0xF0;
+    SL_CommResourcePoolV2X->sl_Subframe_r14.choice.bs40_r14.buf[1] = 0xFF;
+    SL_CommResourcePoolV2X->sl_Subframe_r14.choice.bs40_r14.buf[2] = 0xFF;
+    SL_CommResourcePoolV2X->sl_Subframe_r14.choice.bs40_r14.buf[3] = 0xFF;
+    SL_CommResourcePoolV2X->sl_Subframe_r14.choice.bs40_r14.buf[4] = 0xFF;
+    SL_CommResourcePoolV2X->adjacencyPSCCH_PSSCH_r14 = 1;
+    SL_CommResourcePoolV2X->sizeSubchannel_r14 = 10;
+    SL_CommResourcePoolV2X->numSubchannel_r14 =  5;
+    SL_CommResourcePoolV2X->startRB_Subchannel_r14 = 10;
+    //rxParametersNCell_r12
+    SL_CommResourcePoolV2X->rxParametersNCell_r14 = CALLOC (1, sizeof (*SL_CommResourcePoolV2X->rxParametersNCell_r14));
+    SL_CommResourcePoolV2X->rxParametersNCell_r14->tdd_Config_r14 = CALLOC (1, sizeof (*SL_CommResourcePoolV2X->rxParametersNCell_r14->tdd_Config_r14));
+    SL_CommResourcePoolV2X->rxParametersNCell_r14->tdd_Config_r14->subframeAssignment = 0 ;
+    SL_CommResourcePoolV2X->rxParametersNCell_r14->tdd_Config_r14->specialSubframePatterns = 0;
+    SL_CommResourcePoolV2X->rxParametersNCell_r14->syncConfigIndex_r14 = 0;
+    ASN_SEQUENCE_ADD(&SL_CommRxPoolListV2X->list,SL_CommResourcePoolV2X);
+    //end SIB21
+  }
+#endif
+  bcch_message->message.present = LTE_BCCH_DL_SCH_MessageType_PR_c1;
+  bcch_message->message.choice.c1.present = LTE_BCCH_DL_SCH_MessageType__c1_PR_systemInformation;
   /*  memcpy((void*)&bcch_message.message.choice.c1.choice.systemInformation,
    (void*)systemInformation,
    sizeof(SystemInformation_t));*/
+  bcch_message->message.choice.c1.choice.systemInformation.criticalExtensions.present = LTE_SystemInformation__criticalExtensions_PR_systemInformation_r8;
 
-  bcch_message->message.choice.c1.choice.systemInformation.criticalExtensions.present = SystemInformation__criticalExtensions_PR_systemInformation_r8;
   bcch_message->message.choice.c1.choice.systemInformation.criticalExtensions.choice.systemInformation_r8.sib_TypeAndInfo.list.count=0;
-
   //  asn_set_empty(&systemInformation->criticalExtensions.choice.systemInformation_r8.sib_TypeAndInfo.list);//.size=0;
   //  systemInformation->criticalExtensions.choice.systemInformation_r8.sib_TypeAndInfo.list.count=0;
   ASN_SEQUENCE_ADD(&bcch_message->message.choice.c1.choice.systemInformation.criticalExtensions.choice.systemInformation_r8.sib_TypeAndInfo.list,
                    sib2_part);
   ASN_SEQUENCE_ADD(&bcch_message->message.choice.c1.choice.systemInformation.criticalExtensions.choice.systemInformation_r8.sib_TypeAndInfo.list,
                    sib3_part);
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 
-  if (MBMS_flag > 0) {
-    ASN_SEQUENCE_ADD(&bcch_message->message.choice.c1.choice.systemInformation.criticalExtensions.choice.systemInformation_r8.sib_TypeAndInfo.list,sib13_part);
+  if (configuration->eMBMS_configured > 0) {
+    ASN_SEQUENCE_ADD(&bcch_message->message.choice.c1.choice.systemInformation.criticalExtensions.choice.systemInformation_r8.sib_TypeAndInfo.list, sib13_part);
   }
+
 #endif
 
   if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-     xer_fprint(stdout, &asn_DEF_BCCH_DL_SCH_Message, (void*)bcch_message);
+    xer_fprint(stdout, &asn_DEF_LTE_BCCH_DL_SCH_Message, (void *)bcch_message);
   }
-  enc_rval = uper_encode_to_buffer(&asn_DEF_BCCH_DL_SCH_Message,
+
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_BCCH_DL_SCH_Message,
                                    NULL,
-                                   (void*)bcch_message,
+                                   (void *)bcch_message,
                                    buffer,
                                    900);
   AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
                enc_rval.failed_type->name, enc_rval.encoded);
 
-
-#if defined(ENABLE_ITTI)
-# if !defined(DISABLE_XER_SPRINT)
-  {
-    char        message_string[15000];
-    size_t      message_string_size;
-
-    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_BCCH_DL_SCH_Message, (void *)bcch_message)) > 0) {
-      MessageDef *msg_p;
-
-      msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_BCCH, message_string_size + sizeof (IttiMsgText));
-      msg_p->ittiMsg.rrc_dl_bcch.size = message_string_size;
-      memcpy(&msg_p->ittiMsg.rrc_dl_bcch.text, message_string, message_string_size);
-
-      itti_send_msg_to_task(TASK_UNKNOWN, Mod_id, msg_p);
-    }
-  }
-# endif
-#endif
-
   LOG_D(RRC,"[eNB] SystemInformation Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
 
   if (enc_rval.encoded==-1) {
@@ -1400,26 +2037,19 @@ uint8_t do_SIB23(uint8_t Mod_id,
   return((enc_rval.encoded+7)/8);
 }
 
-uint8_t do_RRCConnectionRequest(uint8_t Mod_id, uint8_t *buffer,uint8_t *rv)
-{
-
+uint8_t do_RRCConnectionRequest(uint8_t Mod_id, uint8_t *buffer,uint8_t *rv) {
   asn_enc_rval_t enc_rval;
   uint8_t buf[5],buf2=0;
-
-  UL_CCCH_Message_t ul_ccch_msg;
-
-  RRCConnectionRequest_t *rrcConnectionRequest;
-
-  memset((void *)&ul_ccch_msg,0,sizeof(UL_CCCH_Message_t));
-
-  ul_ccch_msg.message.present           = UL_CCCH_MessageType_PR_c1;
-  ul_ccch_msg.message.choice.c1.present = UL_CCCH_MessageType__c1_PR_rrcConnectionRequest;
+  LTE_UL_CCCH_Message_t ul_ccch_msg;
+  LTE_RRCConnectionRequest_t *rrcConnectionRequest;
+  memset((void *)&ul_ccch_msg,0,sizeof(LTE_UL_CCCH_Message_t));
+  ul_ccch_msg.message.present           = LTE_UL_CCCH_MessageType_PR_c1;
+  ul_ccch_msg.message.choice.c1.present = LTE_UL_CCCH_MessageType__c1_PR_rrcConnectionRequest;
   rrcConnectionRequest          = &ul_ccch_msg.message.choice.c1.choice.rrcConnectionRequest;
-
-  rrcConnectionRequest->criticalExtensions.present = RRCConnectionRequest__criticalExtensions_PR_rrcConnectionRequest_r8;
+  rrcConnectionRequest->criticalExtensions.present = LTE_RRCConnectionRequest__criticalExtensions_PR_rrcConnectionRequest_r8;
 
   if (1) {
-    rrcConnectionRequest->criticalExtensions.choice.rrcConnectionRequest_r8.ue_Identity.present = InitialUE_Identity_PR_randomValue;
+    rrcConnectionRequest->criticalExtensions.choice.rrcConnectionRequest_r8.ue_Identity.present = LTE_InitialUE_Identity_PR_randomValue;
     rrcConnectionRequest->criticalExtensions.choice.rrcConnectionRequest_r8.ue_Identity.choice.randomValue.size = 5;
     rrcConnectionRequest->criticalExtensions.choice.rrcConnectionRequest_r8.ue_Identity.choice.randomValue.bits_unused = 0;
     rrcConnectionRequest->criticalExtensions.choice.rrcConnectionRequest_r8.ue_Identity.choice.randomValue.buf = buf;
@@ -1429,7 +2059,7 @@ uint8_t do_RRCConnectionRequest(uint8_t Mod_id, uint8_t *buffer,uint8_t *rv)
     rrcConnectionRequest->criticalExtensions.choice.rrcConnectionRequest_r8.ue_Identity.choice.randomValue.buf[3] = rv[3];
     rrcConnectionRequest->criticalExtensions.choice.rrcConnectionRequest_r8.ue_Identity.choice.randomValue.buf[4] = rv[4];
   } else {
-    rrcConnectionRequest->criticalExtensions.choice.rrcConnectionRequest_r8.ue_Identity.present = InitialUE_Identity_PR_s_TMSI;
+    rrcConnectionRequest->criticalExtensions.choice.rrcConnectionRequest_r8.ue_Identity.present = LTE_InitialUE_Identity_PR_s_TMSI;
     rrcConnectionRequest->criticalExtensions.choice.rrcConnectionRequest_r8.ue_Identity.choice.s_TMSI.mmec.size = 1;
     rrcConnectionRequest->criticalExtensions.choice.rrcConnectionRequest_r8.ue_Identity.choice.s_TMSI.mmec.bits_unused = 0;
     rrcConnectionRequest->criticalExtensions.choice.rrcConnectionRequest_r8.ue_Identity.choice.s_TMSI.mmec.buf = buf;
@@ -1443,242 +2073,186 @@ uint8_t do_RRCConnectionRequest(uint8_t Mod_id, uint8_t *buffer,uint8_t *rv)
     rrcConnectionRequest->criticalExtensions.choice.rrcConnectionRequest_r8.ue_Identity.choice.s_TMSI.m_TMSI.buf[3] = 0x9a;
   }
 
-  rrcConnectionRequest->criticalExtensions.choice.rrcConnectionRequest_r8.establishmentCause = EstablishmentCause_mo_Signalling; //EstablishmentCause_mo_Data;
-
+  rrcConnectionRequest->criticalExtensions.choice.rrcConnectionRequest_r8.establishmentCause = LTE_EstablishmentCause_mo_Signalling; //EstablishmentCause_mo_Data;
   rrcConnectionRequest->criticalExtensions.choice.rrcConnectionRequest_r8.spare.buf = &buf2;
   rrcConnectionRequest->criticalExtensions.choice.rrcConnectionRequest_r8.spare.size=1;
   rrcConnectionRequest->criticalExtensions.choice.rrcConnectionRequest_r8.spare.bits_unused = 7;
 
+  if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
+    xer_fprint(stdout, &asn_DEF_LTE_UL_CCCH_Message, (void *)&ul_ccch_msg);
+  }
 
-  enc_rval = uper_encode_to_buffer(&asn_DEF_UL_CCCH_Message,
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_UL_CCCH_Message,
                                    NULL,
-                                   (void*)&ul_ccch_msg,
+                                   (void *)&ul_ccch_msg,
                                    buffer,
                                    100);
   AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
-               enc_rval.failed_type->name, enc_rval.encoded);
-
-#if defined(ENABLE_ITTI)
-# if !defined(DISABLE_XER_SPRINT)
-  {
-    char        message_string[20000];
-    size_t      message_string_size;
-
-    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_UL_CCCH_Message, (void *) &ul_ccch_msg)) > 0) {
-      MessageDef *msg_p;
-
-      msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, RRC_UL_CCCH, message_string_size + sizeof (IttiMsgText));
-      msg_p->ittiMsg.rrc_ul_ccch.size = message_string_size;
-      memcpy(&msg_p->ittiMsg.rrc_ul_ccch.text, message_string, message_string_size);
-
-      itti_send_msg_to_task(TASK_UNKNOWN, NB_eNB_INST + Mod_id, msg_p);
-    }
-  }
-# endif
-#endif
-
+	       enc_rval.failed_type->name, enc_rval.encoded);
   LOG_D(RRC,"[UE] RRCConnectionRequest Encoded %zd bits (%zd bytes) \n",enc_rval.encoded,(enc_rval.encoded+7)/8);
-
   return((enc_rval.encoded+7)/8);
-
 }
 
 
 //TTN for D2D - 3GPP TS 36.331 (Section 5.10.2.3)
-uint8_t do_SidelinkUEInformation(uint8_t Mod_id, uint8_t *buffer,  SL_DestinationInfoList_r12_t  *destinationInfoList, long *discTxResourceReq, SL_TRIGGER_t mode)
-{
-
-   asn_enc_rval_t enc_rval;
-   UL_DCCH_Message_t ul_dcch_msg;
-   SidelinkUEInformation_r12_t *sidelinkUEInformation;
-   ARFCN_ValueEUTRA_r9_t carrierFreq = 25655;//sidelink communication frequency (hardcoded - should come from SIB2)
-
-   memset((void *)&ul_dcch_msg,0,sizeof(UL_DCCH_Message_t));
-   ul_dcch_msg.message.present = UL_DCCH_MessageType_PR_messageClassExtension;
-   ul_dcch_msg.message.choice.messageClassExtension.present  = UL_DCCH_MessageType__messageClassExtension_PR_c2;
-   ul_dcch_msg.message.choice.messageClassExtension.choice.c2.present =  UL_DCCH_MessageType__messageClassExtension__c2_PR_sidelinkUEInformation_r12;
-   sidelinkUEInformation            = &ul_dcch_msg.message.choice.messageClassExtension.choice.c2.choice.sidelinkUEInformation_r12;
-
-   //3GPP TS 36.331 (Section 5.10.2.3)
-   sidelinkUEInformation->criticalExtensions.present = SidelinkUEInformation_r12__criticalExtensions_PR_c1;
-   sidelinkUEInformation->criticalExtensions.choice.c1.present = SidelinkUEInformation_r12__criticalExtensions__c1_PR_sidelinkUEInformation_r12;
-   switch(mode) {
-   //if SIB18 is available
-   case SL_RECEIVE_COMMUNICATION: // to receive sidelink communication
+uint8_t do_SidelinkUEInformation(uint8_t Mod_id, uint8_t *buffer,  LTE_SL_DestinationInfoList_r12_t  *destinationInfoList, long *discTxResourceReq, SL_TRIGGER_t mode) {
+  asn_enc_rval_t enc_rval;
+  LTE_UL_DCCH_Message_t ul_dcch_msg;
+  LTE_SidelinkUEInformation_r12_t *sidelinkUEInformation;
+  LTE_ARFCN_ValueEUTRA_r9_t carrierFreq = 25655;//sidelink communication frequency (hardcoded - should come from SIB2)
+  memset((void *)&ul_dcch_msg,0,sizeof(LTE_UL_DCCH_Message_t));
+  ul_dcch_msg.message.present = LTE_UL_DCCH_MessageType_PR_messageClassExtension;
+  ul_dcch_msg.message.choice.messageClassExtension.present  = LTE_UL_DCCH_MessageType__messageClassExtension_PR_c2;
+  ul_dcch_msg.message.choice.messageClassExtension.choice.c2.present =  LTE_UL_DCCH_MessageType__messageClassExtension__c2_PR_sidelinkUEInformation_r12;
+  sidelinkUEInformation            = &ul_dcch_msg.message.choice.messageClassExtension.choice.c2.choice.sidelinkUEInformation_r12;
+  //3GPP TS 36.331 (Section 5.10.2.3)
+  sidelinkUEInformation->criticalExtensions.present = LTE_SidelinkUEInformation_r12__criticalExtensions_PR_c1;
+  sidelinkUEInformation->criticalExtensions.choice.c1.present = LTE_SidelinkUEInformation_r12__criticalExtensions__c1_PR_sidelinkUEInformation_r12;
+
+  switch(mode) {
+    //if SIB18 is available
+    case SL_RECEIVE_COMMUNICATION: // to receive sidelink communication
       sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commRxInterestedFreq_r12 = CALLOC(1,
-            sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commRxInterestedFreq_r12));
-      memcpy((void*)sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commRxInterestedFreq_r12, (void*)&carrierFreq,
-            sizeof(ARFCN_ValueEUTRA_r9_t));
+          sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commRxInterestedFreq_r12));
+      memcpy((void *)sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commRxInterestedFreq_r12, (void *)&carrierFreq,
+             sizeof(LTE_ARFCN_ValueEUTRA_r9_t));
       break;
 
-   case SL_TRANSMIT_NON_RELAY_ONE_TO_MANY: //to transmit non-relay related one-to-many sidelink communication
+    case SL_TRANSMIT_NON_RELAY_ONE_TO_MANY: //to transmit non-relay related one-to-many sidelink communication
       //commTxResourceReq
       sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commTxResourceReq_r12 = CALLOC(1,
-            sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commTxResourceReq_r12));
+          sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commTxResourceReq_r12));
       sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commTxResourceReq_r12->carrierFreq_r12 = CALLOC(1,
-            sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commTxResourceReq_r12->carrierFreq_r12));
-      memcpy((void*)sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commTxResourceReq_r12->carrierFreq_r12, (void*)&carrierFreq,
-            sizeof(ARFCN_ValueEUTRA_r9_t));
+          sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commTxResourceReq_r12->carrierFreq_r12));
+      memcpy((void *)sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commTxResourceReq_r12->carrierFreq_r12, (void *)&carrierFreq,
+             sizeof(LTE_ARFCN_ValueEUTRA_r9_t));
       memcpy(&sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commTxResourceReq_r12->destinationInfoList_r12,
-            destinationInfoList,
-            sizeof(SL_DestinationInfoList_r12_t));
+             destinationInfoList,
+             sizeof(LTE_SL_DestinationInfoList_r12_t));
       break;
 
-   case SL_TRANSMIT_NON_RELAY_ONE_TO_ONE://transmit non-relay related one-to-one sidelink communication
+    case SL_TRANSMIT_NON_RELAY_ONE_TO_ONE://transmit non-relay related one-to-one sidelink communication
       //if commTxResourceUC-ReqAllowed is included in SIB18
       sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension = CALLOC(1,
-            sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension));
-
+          sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension));
       sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceReqUC_r13 = CALLOC(1,
-            sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceReqUC_r13));
+          sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceReqUC_r13));
       sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceReqUC_r13->carrierFreq_r12 = CALLOC(1,
-            sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceReqUC_r13->carrierFreq_r12));
-      memcpy((void*)sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceReqUC_r13->carrierFreq_r12, (void*)&carrierFreq,
-            sizeof (ARFCN_ValueEUTRA_r9_t));
+          sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceReqUC_r13->carrierFreq_r12));
+      memcpy((void *)sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceReqUC_r13->carrierFreq_r12, (void *)&carrierFreq,
+             sizeof (LTE_ARFCN_ValueEUTRA_r9_t));
       memcpy(&sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceReqUC_r13->destinationInfoList_r12,
-            destinationInfoList,
-            sizeof(SL_DestinationInfoList_r12_t));
+             destinationInfoList,
+             sizeof(LTE_SL_DestinationInfoList_r12_t));
       break;
 
-   case SL_TRANSMIT_RELAY_ONE_TO_ONE: //transmit relay related one-to-one sidelink communication
+    case SL_TRANSMIT_RELAY_ONE_TO_ONE: //transmit relay related one-to-one sidelink communication
       //if SIB19 includes discConfigRelay and UE acts a relay or UE has a selected relay
       sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension = CALLOC(1,
-            sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension));
+          sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension));
       sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13= CALLOC(1,
-            sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13));
+          sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13));
       sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelayUC_r13 = CALLOC(1,
-            sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelayUC_r13));
+          sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelayUC_r13));
       memcpy(&sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelayUC_r13->destinationInfoList_r12,
-            destinationInfoList,
-            sizeof(*destinationInfoList));
+             destinationInfoList,
+             sizeof(*destinationInfoList));
       //set ue-type to relayUE or remoteUE
-      sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->ue_Type_r13 =SidelinkUEInformation_v1310_IEs__commTxResourceInfoReqRelay_r13__ue_Type_r13_relayUE;
+      sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->ue_Type_r13
+        =LTE_SidelinkUEInformation_v1310_IEs__commTxResourceInfoReqRelay_r13__ue_Type_r13_relayUE;
       //sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12->nonCriticalExtension->commTxResourceInfoReqRelay_r13->ue_Type_r13 =SidelinkUEInformation_v1310_IEs__commTxResourceInfoReqRelay_r13__ue_Type_r13_remoteUE;
       break;
 
-   case SL_TRANSMIT_RELAY_ONE_TO_MANY: //transmit relay related one-to-many sidelink communication
+    case SL_TRANSMIT_RELAY_ONE_TO_MANY: //transmit relay related one-to-many sidelink communication
       //if SIB19 includes discConfigRelay and UE acts a relay
       //set ue-type to relayUE
       sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension = CALLOC(1,
-            sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension));
+          sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension));
       sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13= CALLOC(1,
-            sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13));
+          sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13));
       sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelay_r13 = CALLOC(1,
-            sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelay_r13));
-      sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->ue_Type_r13 =SidelinkUEInformation_v1310_IEs__commTxResourceInfoReqRelay_r13__ue_Type_r13_relayUE;
+          sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelay_r13));
+      sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->ue_Type_r13 =
+        LTE_SidelinkUEInformation_v1310_IEs__commTxResourceInfoReqRelay_r13__ue_Type_r13_relayUE;
       memcpy(&sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelay_r13->destinationInfoList_r12,
-            destinationInfoList,
-            sizeof(*destinationInfoList));
+             destinationInfoList,
+             sizeof(*destinationInfoList));
       break;
 
-      //if SIB19 is available
-      //we consider only one frequency  - a serving frequency
-   case SL_RECEIVE_DISCOVERY: //receive sidelink discovery announcements
-
+    //if SIB19 is available
+    //we consider only one frequency  - a serving frequency
+    case SL_RECEIVE_DISCOVERY: //receive sidelink discovery announcements
       sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.discRxInterest_r12 = CALLOC(1,
-            sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.discRxInterest_r12));
-      *sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.discRxInterest_r12 = SidelinkUEInformation_r12_IEs__discRxInterest_r12_true;
+          sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.discRxInterest_r12));
+      *sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.discRxInterest_r12 = LTE_SidelinkUEInformation_r12_IEs__discRxInterest_r12_true;
       break;
-   case SL_TRANSMIT_NON_PS_DISCOVERY://to transmit non-PS related sidelink discovery announcements
+
+    case SL_TRANSMIT_NON_PS_DISCOVERY://to transmit non-PS related sidelink discovery announcements
       //for the first frequency
       sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.discTxResourceReq_r12 = CALLOC(1,
-            sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.discTxResourceReq_r12));
-
-      memcpy((void*)sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.discTxResourceReq_r12,
-            (void*)discTxResourceReq,
-            sizeof(long));
+          sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.discTxResourceReq_r12));
+      memcpy((void *)sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.discTxResourceReq_r12,
+             (void *)discTxResourceReq,
+             sizeof(long));
       //for additional frequency
       break;
 
-   case SL_TRANSMIT_PS_DISCOVERY://to transmit PS related sidelink discovery announcements
+    case SL_TRANSMIT_PS_DISCOVERY://to transmit PS related sidelink discovery announcements
       //if to transmit non-relay PS related discovery announcements and SIB19 includes discConfigPS
       //if UE is acting as relay UE and SIB includes discConfigRelay (relay threshold condition)
       //if relay UE/has a selected relay UE and if SIB19 includes discConfigRelay
       sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension = CALLOC(1,
-            sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension));
+          sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension));
       sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->discTxResourceReqPS_r13 = CALLOC(1,
-            sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->discTxResourceReqPS_r13));
+          sizeof(*sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->discTxResourceReqPS_r13));
       sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->discTxResourceReqPS_r13->discTxResourceReq_r13 = *discTxResourceReq;
       break;
-      //SIB21
-   case SL_RECEIVE_V2X:
+
+    //SIB21
+    case SL_RECEIVE_V2X:
       //TODO
       break;
-   case SL_TRANSMIT_V2X:
+
+    case SL_TRANSMIT_V2X:
       //TODO
       break;
-      //TODO: request sidelink discovery transmission/reception gaps
-      //TODO: report the system information parameters related to sidelink discovery of carriers other than the primary
-   default:
-      break;
-   }
-
-   if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-      xer_fprint(stdout, &asn_DEF_UL_DCCH_Message, (void*)&ul_dcch_msg);
-   }
-
-
-   enc_rval = uper_encode_to_buffer(&asn_DEF_UL_DCCH_Message,
-         NULL,                                   
-         (void*)&ul_dcch_msg,
-         buffer,
-         100);
-   AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
-         enc_rval.failed_type->name, enc_rval.encoded);
-
-#if defined(ENABLE_ITTI)
-# if !defined(DISABLE_XER_SPRINT)
-   {
-      char        message_string[20000];
-      size_t      message_string_size;
 
-      if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_UL_DCCH_Message, (void *) &ul_dcch_msg)) > 0) {
-         MessageDef *msg_p;
-
-         msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, RRC_UL_DCCH, message_string_size + sizeof (IttiMsgText));
-         msg_p->ittiMsg.rrc_ul_dcch.size = message_string_size;
-         memcpy(&msg_p->ittiMsg.rrc_ul_dcch.text, message_string, message_string_size);
-
-         itti_send_msg_to_task(TASK_UNKNOWN, NB_eNB_INST + Mod_id, msg_p);
-      }
-   }
-# endif
-#endif
-
-#ifdef USER_MODE
-   LOG_D(RRC,"SidelinkUEInformation Encoded %d bits (%d bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
-#endif
+    //TODO: request sidelink discovery transmission/reception gaps
+    //TODO: report the system information parameters related to sidelink discovery of carriers other than the primary
+    default:
+      break;
+  }
 
-   return((enc_rval.encoded+7)/8);
+  if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
+    xer_fprint(stdout, &asn_DEF_LTE_UL_DCCH_Message, (void *)&ul_dcch_msg);
+  }
 
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_UL_DCCH_Message,
+                                   NULL,
+                                   (void *)&ul_dcch_msg,
+                                   buffer,
+                                   100);
+  AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
+               enc_rval.failed_type->name, enc_rval.encoded);
+  LOG_D(RRC,"SidelinkUEInformation Encoded %d bits (%d bytes)\n",(uint32_t)enc_rval.encoded,(uint32_t)((enc_rval.encoded+7)/8));
+  return((enc_rval.encoded+7)/8);
 }
 
-
-uint8_t do_RRCConnectionSetupComplete(uint8_t Mod_id, uint8_t *buffer, const uint8_t Transaction_id, const int dedicatedInfoNASLength, const char *dedicatedInfoNAS)
-{
-
+uint8_t do_RRCConnectionSetupComplete(uint8_t Mod_id, uint8_t *buffer, const uint8_t Transaction_id, const int dedicatedInfoNASLength, const char *dedicatedInfoNAS) {
 
   asn_enc_rval_t enc_rval;
-
-  UL_DCCH_Message_t ul_dcch_msg;
-
-  RRCConnectionSetupComplete_t *rrcConnectionSetupComplete;
-
-  memset((void *)&ul_dcch_msg,0,sizeof(UL_DCCH_Message_t));
-
-  ul_dcch_msg.message.present           = UL_DCCH_MessageType_PR_c1;
-  ul_dcch_msg.message.choice.c1.present = UL_DCCH_MessageType__c1_PR_rrcConnectionSetupComplete;
+  LTE_UL_DCCH_Message_t ul_dcch_msg;
+  LTE_RRCConnectionSetupComplete_t *rrcConnectionSetupComplete;
+  memset((void *)&ul_dcch_msg,0,sizeof(LTE_UL_DCCH_Message_t));
+  ul_dcch_msg.message.present           = LTE_UL_DCCH_MessageType_PR_c1;
+  ul_dcch_msg.message.choice.c1.present = LTE_UL_DCCH_MessageType__c1_PR_rrcConnectionSetupComplete;
   rrcConnectionSetupComplete            = &ul_dcch_msg.message.choice.c1.choice.rrcConnectionSetupComplete;
-
   rrcConnectionSetupComplete->rrc_TransactionIdentifier = Transaction_id;
-  rrcConnectionSetupComplete->criticalExtensions.present = RRCConnectionSetupComplete__criticalExtensions_PR_c1;
-  rrcConnectionSetupComplete->criticalExtensions.choice.c1.present = RRCConnectionSetupComplete__criticalExtensions__c1_PR_rrcConnectionSetupComplete_r8;
-
+  rrcConnectionSetupComplete->criticalExtensions.present = LTE_RRCConnectionSetupComplete__criticalExtensions_PR_c1;
+  rrcConnectionSetupComplete->criticalExtensions.choice.c1.present = LTE_RRCConnectionSetupComplete__criticalExtensions__c1_PR_rrcConnectionSetupComplete_r8;
   rrcConnectionSetupComplete->criticalExtensions.choice.c1.choice.rrcConnectionSetupComplete_r8.nonCriticalExtension=CALLOC(1,
       sizeof(*rrcConnectionSetupComplete->criticalExtensions.choice.c1.choice.rrcConnectionSetupComplete_r8.nonCriticalExtension));
-
   rrcConnectionSetupComplete->criticalExtensions.choice.c1.choice.rrcConnectionSetupComplete_r8.selectedPLMN_Identity= 1;
-
   rrcConnectionSetupComplete->criticalExtensions.choice.c1.choice.rrcConnectionSetupComplete_r8.registeredMME =
     NULL;//calloc(1,sizeof(*rrcConnectionSetupComplete->criticalExtensions.choice.c1.choice.rrcConnectionSetupComplete_r8.registeredMME));
   /*
@@ -1699,97 +2273,54 @@ uint8_t do_RRCConnectionSetupComplete(uint8_t Mod_id, uint8_t *buffer, const uin
     rrcConnectionSetupComplete->criticalExtensions.choice.c1.choice.rrcConnectionSetupComplete_r8.registeredMME->mmec.size=1;
     rrcConnectionSetupComplete->criticalExtensions.choice.c1.choice.rrcConnectionSetupComplete_r8.registeredMME->mmec.bits_unused=0;
   */
+  if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
+    xer_fprint(stdout, &asn_DEF_LTE_UL_DCCH_Message, (void *)&ul_dcch_msg);
+  }
 
-  enc_rval = uper_encode_to_buffer(&asn_DEF_UL_DCCH_Message,
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_UL_DCCH_Message,
                                    NULL,
-                                   (void*)&ul_dcch_msg,
+                                   (void *)&ul_dcch_msg,
                                    buffer,
                                    100);
   AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
                enc_rval.failed_type->name, enc_rval.encoded);
-
-#if defined(ENABLE_ITTI)
-# if !defined(DISABLE_XER_SPRINT)
-  {
-    char        message_string[20000];
-    size_t      message_string_size;
-
-    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_UL_DCCH_Message, (void *) &ul_dcch_msg)) > 0) {
-      MessageDef *msg_p;
-
-      msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, RRC_UL_DCCH, message_string_size + sizeof (IttiMsgText));
-      msg_p->ittiMsg.rrc_ul_dcch.size = message_string_size;
-      memcpy(&msg_p->ittiMsg.rrc_ul_dcch.text, message_string, message_string_size);
-
-      itti_send_msg_to_task(TASK_UNKNOWN, NB_eNB_INST + Mod_id, msg_p);
-    }
-  }
-# endif
-#endif
-
-  LOG_D(RRC,"RRCConnectionSetupComplete Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
-
-  return((enc_rval.encoded+7)/8);
-
-}
+  LOG_D(RRC,"RRCConnectionSetupComplete Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
+  return((enc_rval.encoded+7)/8);
+}
 
 //------------------------------------------------------------------------------
 uint8_t
 do_RRCConnectionReconfigurationComplete(
-  const protocol_ctxt_t* const ctxt_pP,
-  uint8_t* buffer,
+  const protocol_ctxt_t *const ctxt_pP,
+  uint8_t *buffer,
   const uint8_t Transaction_id
 )
 //------------------------------------------------------------------------------
 {
-
-
   asn_enc_rval_t enc_rval;
-
-  UL_DCCH_Message_t ul_dcch_msg;
-
-  RRCConnectionReconfigurationComplete_t *rrcConnectionReconfigurationComplete;
-
-  memset((void *)&ul_dcch_msg,0,sizeof(UL_DCCH_Message_t));
-
-  ul_dcch_msg.message.present                     = UL_DCCH_MessageType_PR_c1;
-  ul_dcch_msg.message.choice.c1.present           = UL_DCCH_MessageType__c1_PR_rrcConnectionReconfigurationComplete;
+  LTE_UL_DCCH_Message_t ul_dcch_msg;
+  LTE_RRCConnectionReconfigurationComplete_t *rrcConnectionReconfigurationComplete;
+  memset((void *)&ul_dcch_msg,0,sizeof(LTE_UL_DCCH_Message_t));
+  ul_dcch_msg.message.present                     = LTE_UL_DCCH_MessageType_PR_c1;
+  ul_dcch_msg.message.choice.c1.present           = LTE_UL_DCCH_MessageType__c1_PR_rrcConnectionReconfigurationComplete;
   rrcConnectionReconfigurationComplete            = &ul_dcch_msg.message.choice.c1.choice.rrcConnectionReconfigurationComplete;
-
   rrcConnectionReconfigurationComplete->rrc_TransactionIdentifier = Transaction_id;
   rrcConnectionReconfigurationComplete->criticalExtensions.present =
-    RRCConnectionReconfigurationComplete__criticalExtensions_PR_rrcConnectionReconfigurationComplete_r8;
+    LTE_RRCConnectionReconfigurationComplete__criticalExtensions_PR_rrcConnectionReconfigurationComplete_r8;
   rrcConnectionReconfigurationComplete->criticalExtensions.choice.rrcConnectionReconfigurationComplete_r8.nonCriticalExtension=NULL;
 
-  enc_rval = uper_encode_to_buffer(&asn_DEF_UL_DCCH_Message,
+  if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
+    xer_fprint(stdout, &asn_DEF_LTE_UL_DCCH_Message, (void *)&ul_dcch_msg);
+  }
+
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_UL_DCCH_Message,
                                    NULL,
-                                   (void*)&ul_dcch_msg,
+                                   (void *)&ul_dcch_msg,
                                    buffer,
                                    100);
   AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
                enc_rval.failed_type->name, enc_rval.encoded);
-
-#if defined(ENABLE_ITTI)
-# if !defined(DISABLE_XER_SPRINT)
-  {
-    char        message_string[20000];
-    size_t      message_string_size;
-
-    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_UL_DCCH_Message, (void *) &ul_dcch_msg)) > 0) {
-      MessageDef *msg_p;
-
-      msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, RRC_UL_DCCH, message_string_size + sizeof (IttiMsgText));
-      msg_p->ittiMsg.rrc_ul_dcch.size = message_string_size;
-      memcpy(&msg_p->ittiMsg.rrc_ul_dcch.text, message_string, message_string_size);
-
-      itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
-    }
-  }
-# endif
-#endif
-
   LOG_D(RRC,"RRCConnectionReconfigurationComplete Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
-
   return((enc_rval.encoded+7)/8);
 }
 
@@ -1797,42 +2328,34 @@ do_RRCConnectionReconfigurationComplete(
 //------------------------------------------------------------------------------
 uint8_t
 do_RRCConnectionSetup(
-  const protocol_ctxt_t*     const ctxt_pP,
-  rrc_eNB_ue_context_t*      const ue_context_pP,
+  const protocol_ctxt_t     *const ctxt_pP,
+  rrc_eNB_ue_context_t      *const ue_context_pP,
   int                        CC_id,
-  uint8_t*                   const buffer,
+  uint8_t                   *const buffer,
   const uint8_t              transmission_mode,
   const uint8_t              Transaction_id,
-  SRB_ToAddModList_t  **SRB_configList,
-  struct PhysicalConfigDedicated  **physicalConfigDedicated)
-{
-
+  LTE_SRB_ToAddModList_t  **SRB_configList,
+  struct LTE_PhysicalConfigDedicated  **physicalConfigDedicated) {
   asn_enc_rval_t enc_rval;
   eNB_RRC_INST *rrc               = RC.rrc[ctxt_pP->module_id];
   rrc_eNB_carrier_data_t *carrier = &rrc->carrier[CC_id];
- 
-  long* logicalchannelgroup = NULL;
-  struct SRB_ToAddMod* SRB1_config = NULL;
-  struct SRB_ToAddMod__rlc_Config* SRB1_rlc_config = NULL;
-  struct SRB_ToAddMod__logicalChannelConfig* SRB1_lchan_config = NULL;
-  struct LogicalChannelConfig__ul_SpecificParameters* SRB1_ul_SpecificParameters = NULL;
-
+  long *logicalchannelgroup = NULL;
+  struct LTE_SRB_ToAddMod *SRB1_config = NULL;
+  struct LTE_SRB_ToAddMod__rlc_Config *SRB1_rlc_config = NULL;
+  struct LTE_SRB_ToAddMod__logicalChannelConfig *SRB1_lchan_config = NULL;
+  struct LTE_LogicalChannelConfig__ul_SpecificParameters *SRB1_ul_SpecificParameters = NULL;
 #ifdef CBA
-  struct PUSCH_CBAConfigDedicated_vlola*  pusch_CBAConfigDedicated_vlola = NULL;
-  long* betaOffset_CBA_Index = NULL;
-  long* cShift_CBA = NULL;
+  struct LTE_PUSCH_CBAConfigDedicated_vlola  *pusch_CBAConfigDedicated_vlola = NULL;
+  long *betaOffset_CBA_Index = NULL;
+  long *cShift_CBA = NULL;
 #endif
-  PhysicalConfigDedicated_t* physicalConfigDedicated2 = NULL;
-
-  DL_CCCH_Message_t dl_ccch_msg;
-
-  RRCConnectionSetup_t* rrcConnectionSetup = NULL;
-
+  LTE_PhysicalConfigDedicated_t *physicalConfigDedicated2 = NULL;
+  LTE_DL_CCCH_Message_t dl_ccch_msg;
+  LTE_RRCConnectionSetup_t *rrcConnectionSetup = NULL;
   LTE_DL_FRAME_PARMS *frame_parms = &RC.eNB[ctxt_pP->module_id][CC_id]->frame_parms;
-
-  memset((void *)&dl_ccch_msg,0,sizeof(DL_CCCH_Message_t));
-  dl_ccch_msg.message.present           = DL_CCCH_MessageType_PR_c1;
-  dl_ccch_msg.message.choice.c1.present = DL_CCCH_MessageType__c1_PR_rrcConnectionSetup;
+  memset((void *)&dl_ccch_msg,0,sizeof(LTE_DL_CCCH_Message_t));
+  dl_ccch_msg.message.present           = LTE_DL_CCCH_MessageType_PR_c1;
+  dl_ccch_msg.message.choice.c1.present = LTE_DL_CCCH_MessageType__c1_PR_rrcConnectionSetup;
   rrcConnectionSetup          = &dl_ccch_msg.message.choice.c1.choice.rrcConnectionSetup;
 
   // RRCConnectionSetup
@@ -1843,17 +2366,14 @@ do_RRCConnectionSetup(
     free(*SRB_configList);
   }
 
-  *SRB_configList = CALLOC(1,sizeof(SRB_ToAddModList_t));
-
+  *SRB_configList = CALLOC(1,sizeof(LTE_SRB_ToAddModList_t));
   /// SRB1
   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 = SRB_ToAddMod__rlc_Config_PR_explicitValue;
-  SRB1_rlc_config->choice.explicitValue.present=RLC_Config_PR_am;
+  SRB1_rlc_config->present = LTE_SRB_ToAddMod__rlc_Config_PR_explicitValue;
+  SRB1_rlc_config->choice.explicitValue.present=LTE_RLC_Config_PR_am;
 #if defined(ENABLE_ITTI)
   SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = rrc->srb1_timer_poll_retransmit;
   SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU          = rrc->srb1_poll_pdu;
@@ -1861,44 +2381,31 @@ do_RRCConnectionSetup(
   SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = rrc->srb1_max_retx_threshold;
   SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering     = rrc->srb1_timer_reordering;
   SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = rrc->srb1_timer_status_prohibit;
-#else 
-  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = T_PollRetransmit_ms20;;
-  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU          = PollPDU_p4;;
-  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte         = PollByte_kBinfinity;
-  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = UL_AM_RLC__maxRetxThreshold_t8;
-  SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering     = T_Reordering_ms35;
-  SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = T_StatusProhibit_ms0;
-#endif 
-
+#else
+  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = LTE_T_PollRetransmit_ms20;;
+  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU          = LTE_PollPDU_p4;;
+  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte         = LTE_PollByte_kBinfinity;
+  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = LTE_UL_AM_RLC__maxRetxThreshold_t8;
+  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_ms0;
+#endif
   SRB1_lchan_config = CALLOC(1,sizeof(*SRB1_lchan_config));
   SRB1_config->logicalChannelConfig   = SRB1_lchan_config;
-
-  SRB1_lchan_config->present = SRB_ToAddMod__logicalChannelConfig_PR_explicitValue;
+  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=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=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_configList)->list,SRB1_config);
-
   // PhysicalConfigDedicated
-
   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));
@@ -1906,10 +2413,12 @@ do_RRCConnectionSetup(
   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              = CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig));
+
   if (rrc->srs_enable[CC_id]==1)
     physicalConfigDedicated2->soundingRS_UL_ConfigDedicated = CALLOC(1,sizeof(*physicalConfigDedicated2->soundingRS_UL_ConfigDedicated));
   else
     physicalConfigDedicated2->soundingRS_UL_ConfigDedicated = NULL;
+
   physicalConfigDedicated2->antennaInfo                   = CALLOC(1,sizeof(*physicalConfigDedicated2->antennaInfo));
   physicalConfigDedicated2->schedulingRequestConfig       = CALLOC(1,sizeof(*physicalConfigDedicated2->schedulingRequestConfig));
 
@@ -1917,12 +2426,12 @@ do_RRCConnectionSetup(
   //assign_enum(&physicalConfigDedicated2->pdsch_ConfigDedicated->p_a,
   //        PDSCH_ConfigDedicated__p_a_dB0);
   if (carrier->p_eNB==2)
-    physicalConfigDedicated2->pdsch_ConfigDedicated->p_a=   PDSCH_ConfigDedicated__p_a_dB_3;
+    physicalConfigDedicated2->pdsch_ConfigDedicated->p_a=   LTE_PDSCH_ConfigDedicated__p_a_dB_3;
   else
-    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=PUCCH_ConfigDedicated__ackNackRepetition_PR_release;
+  physicalConfigDedicated2->pucch_ConfigDedicated->ackNackRepetition.present=LTE_PUCCH_ConfigDedicated__ackNackRepetition_PR_release;
   physicalConfigDedicated2->pucch_ConfigDedicated->ackNackRepetition.choice.release=0;
 
   if (carrier->sib1->tdd_Config == NULL) {
@@ -1930,265 +2439,678 @@ do_RRCConnectionSetup(
   } else { //TDD
     physicalConfigDedicated2->pucch_ConfigDedicated->tdd_AckNackFeedbackMode= CALLOC(1,sizeof(long));
     *(physicalConfigDedicated2->pucch_ConfigDedicated->tdd_AckNackFeedbackMode) =
-      PUCCH_ConfigDedicated__tdd_AckNackFeedbackMode_bundling;//PUCCH_ConfigDedicated__tdd_AckNackFeedbackMode_multiplexing;
+      LTE_PUCCH_ConfigDedicated__tdd_AckNackFeedbackMode_bundling;//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= UplinkPowerControlDedicated__deltaMCS_Enabled_en1;
+  physicalConfigDedicated2->uplinkPowerControlDedicated->deltaMCS_Enabled= LTE_UplinkPowerControlDedicated__deltaMCS_Enabled_en1;
   physicalConfigDedicated2->uplinkPowerControlDedicated->accumulationEnabled = 1;  // TRUE
   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=FilterCoefficient_fc4; // fc4 dB
-
+  *physicalConfigDedicated2->uplinkPowerControlDedicated->filterCoefficient=LTE_FilterCoefficient_fc4; // fc4 dB
   // TPC-PDCCH-Config
-
-  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->present=TPC_PDCCH_Config_PR_setup;
-  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_Index.present = TPC_Index_PR_indexOfFormat3;
+  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=TPC_PDCCH_Config_PR_setup;
-  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_Index.present = TPC_Index_PR_indexOfFormat3;
+  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;
-
   // CQI ReportConfig
-
   physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportModeAperiodic=CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportModeAperiodic));
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-  *physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportModeAperiodic= CQI_ReportModeAperiodic_rm30;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+  *physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportModeAperiodic= LTE_CQI_ReportModeAperiodic_rm30;
 #else
-  *physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportModeAperiodic=CQI_ReportConfig__cqi_ReportModeAperiodic_rm30; // HLC CQI, no PMI
+  *physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportModeAperiodic=LTE_CQI_ReportConfig__cqi_ReportModeAperiodic_rm30; // HLC CQI, no PMI
 #endif
   physicalConfigDedicated2->cqi_ReportConfig->nomPDSCH_RS_EPRE_Offset = 0; // 0 dB
   //physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic=NULL;
-  
   physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic=CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic));
-  physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->present =  CQI_ReportPeriodic_PR_release;
-    /*
-    physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->present =  CQI_ReportPeriodic_PR_setup;
-    physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.cqi_PUCCH_ResourceIndex = 0;  // n2_pucch
-    physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.cqi_pmi_ConfigIndex = 0;  // Icqi/pmi
-    physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present = CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_subbandCQI;  // subband CQI
-    physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.choice.subbandCQI.k=4;
-
-    physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.ri_ConfigIndex=NULL;
-    physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.simultaneousAckNackAndCQI=0;
-    */
+  physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->present =  LTE_CQI_ReportPeriodic_PR_release;
+  /*
+  physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->present =  CQI_ReportPeriodic_PR_setup;
+  physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.cqi_PUCCH_ResourceIndex = 0;  // n2_pucch
+  physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.cqi_pmi_ConfigIndex = 0;  // Icqi/pmi
+  physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present = CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_subbandCQI;  // subband CQI
+  physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.choice.subbandCQI.k=4;
+
+  physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.ri_ConfigIndex=NULL;
+  physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.simultaneousAckNackAndCQI=0;
+  */
 
   //soundingRS-UL-ConfigDedicated
   if (rrc->srs_enable[CC_id]==1) {
-    physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->present = SoundingRS_UL_ConfigDedicated_PR_setup;
+    physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->present = LTE_SoundingRS_UL_ConfigDedicated_PR_setup;
     physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.srs_Bandwidth =
-                                                             SoundingRS_UL_ConfigDedicated__setup__srs_Bandwidth_bw0;
+      LTE_SoundingRS_UL_ConfigDedicated__setup__srs_Bandwidth_bw0;
     physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.srs_HoppingBandwidth =
-          SoundingRS_UL_ConfigDedicated__setup__srs_HoppingBandwidth_hbw0;
+      LTE_SoundingRS_UL_ConfigDedicated__setup__srs_HoppingBandwidth_hbw0;
     physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.freqDomainPosition=0;
     physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.duration=1;
+
     if (carrier->sib1->tdd_Config==NULL) { // FDD
       if (carrier->sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.present
-	  == SoundingRS_UL_ConfigCommon_PR_setup)
-	if (carrier->sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_SubframeConfig!=0) 
-	  LOG_W(RRC,"This code has been optimized for SRS Subframe Config 0, but current config is %zd. Expect undefined behaviour!\n",
-		carrier->sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_SubframeConfig);
-      if (ue_context_pP->local_uid >=20) 
-	LOG_W(RRC,"This code has been optimized for up to 10 UEs, but current UE_id is %d. Expect undefined behaviour!\n",
-	      ue_context_pP->local_uid);
+          == LTE_SoundingRS_UL_ConfigCommon_PR_setup)
+        if (carrier->sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_SubframeConfig!=0)
+          LOG_W(RRC,"This code has been optimized for SRS Subframe Config 0, but current config is %zd. Expect undefined behaviour!\n",
+                carrier->sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_SubframeConfig);
+
+      if (ue_context_pP->local_uid >=20)
+        LOG_W(RRC,"This code has been optimized for up to 10 UEs, but current UE_id is %d. Expect undefined behaviour!\n",
+              ue_context_pP->local_uid);
+
       //the current code will allow for 20 UEs - to be revised for more
       physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.srs_ConfigIndex=7+ue_context_pP->local_uid/2;
       physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.transmissionComb= ue_context_pP->local_uid%2;
-    }
-    else {
+    } else {
       if (carrier->sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.present
-	  == SoundingRS_UL_ConfigCommon_PR_setup)
-	if (carrier->sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_SubframeConfig!=7) {
-	  LOG_W(RRC,"This code has been optimized for SRS Subframe Config 7 and TDD config 3, but current configs are %zd and %zd. Expect undefined behaviour!\n",
-		carrier->sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_SubframeConfig,
-		carrier->sib1->tdd_Config->subframeAssignment);
-	}
-      if (ue_context_pP->local_uid >=6) 
-	LOG_W(RRC,"This code has been optimized for up to 6 UEs, but current UE_id is %d. Expect undefined behaviour!\n",
-	      ue_context_pP->local_uid);
+          == LTE_SoundingRS_UL_ConfigCommon_PR_setup)
+        if (carrier->sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_SubframeConfig!=7) {
+          LOG_W(RRC,"This code has been optimized for SRS Subframe Config 7 and TDD config 3, but current configs are %zd and %zd. Expect undefined behaviour!\n",
+                carrier->sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_SubframeConfig,
+                carrier->sib1->tdd_Config->subframeAssignment);
+        }
+
+      if (ue_context_pP->local_uid >=6)
+        LOG_W(RRC,"This code has been optimized for up to 6 UEs, but current UE_id is %d. Expect undefined behaviour!\n",
+              ue_context_pP->local_uid);
+
       physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.srs_ConfigIndex=17+ue_context_pP->local_uid/2;
       physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.transmissionComb= ue_context_pP->local_uid%2;
     }
-    LOG_W(RRC,"local UID %d, srs ConfigIndex %zd, TransmissionComb %zd\n",ue_context_pP->local_uid,
-	  physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.srs_ConfigIndex,
-	  physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.transmissionComb);
 
+    LOG_W(RRC,"local UID %d, srs ConfigIndex %zd, TransmissionComb %zd\n",ue_context_pP->local_uid,
+          physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.srs_ConfigIndex,
+          physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.transmissionComb);
     physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.cyclicShift=
-          SoundingRS_UL_ConfigDedicated__setup__cyclicShift_cs0;
+      LTE_SoundingRS_UL_ConfigDedicated__setup__cyclicShift_cs0;
   }
 
-
   //AntennaInfoDedicated
   physicalConfigDedicated2->antennaInfo = CALLOC(1,sizeof(*physicalConfigDedicated2->antennaInfo));
-  physicalConfigDedicated2->antennaInfo->present = PhysicalConfigDedicated__antennaInfo_PR_explicitValue;
+  physicalConfigDedicated2->antennaInfo->present = LTE_PhysicalConfigDedicated__antennaInfo_PR_explicitValue;
   //assign_enum(&physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode,
   //     AntennaInfoDedicated__transmissionMode_tm2);
 
+  LOG_D(RRC,"physicalConfigDedicated2 %p, physicalConfigDedicated2->antennaInfo %p => %d\n",physicalConfigDedicated2,physicalConfigDedicated2->antennaInfo,transmission_mode);
+
+  switch (transmission_mode) {
+    default:
+      LOG_W(RRC,"At RRCConnectionSetup Transmission mode can only take values 1 or 2! Defaulting to 1!\n");
+
+    case 1:
+      physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     LTE_AntennaInfoDedicated__transmissionMode_tm1;
+      break;
+
+    case 2:
+      physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     LTE_AntennaInfoDedicated__transmissionMode_tm2;
+      break;
+      /*
+      case 3:
+      physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm3;
+      physicalConfigDedicated2->antennaInfo->choice.explicitValue.codebookSubsetRestriction=     CALLOC(1,
+          sizeof(*physicalConfigDedicated2->antennaInfo->choice.explicitValue.codebookSubsetRestriction));
+      physicalConfigDedicated2->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
+        AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm3;
+      physicalConfigDedicated2->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.buf= MALLOC(1);
+      physicalConfigDedicated2->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.buf[0] = 0xc0;
+      physicalConfigDedicated2->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.size=1;
+      physicalConfigDedicated2->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.bits_unused=6;
+
+      break;
+
+      case 4:
+      physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm4;
+      break;
+
+      case 5:
+      physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm5;
+      break;
+
+      case 6:
+      physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm6;
+      break;
+
+      case 7:
+      physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm7;
+      break;
+      */
+  }
+
+  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;
+
+  if (carrier->sib1->tdd_Config == NULL) {
+    physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_PUCCH_ResourceIndex = 71 - ue_context_pP->local_uid/10;//ue_context_pP->local_uid;
+  } else {
+    switch (carrier->sib1->tdd_Config->subframeAssignment) {
+      case 1:
+        switch(frame_parms->N_RB_UL) {
+          case 25:
+            physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_PUCCH_ResourceIndex = 15 - ue_context_pP->local_uid/4;
+            break;
+
+          case 50:
+            physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_PUCCH_ResourceIndex = 31 - ue_context_pP->local_uid/4;
+            break;
+
+          case 100:
+            physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_PUCCH_ResourceIndex = 63 - ue_context_pP->local_uid/4;
+            break;
+        }
+
+        break;
+
+      default:
+        physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_PUCCH_ResourceIndex = 71 - ue_context_pP->local_uid/10;//ue_context_pP->local_uid;
+        break;
+    }
+  }
+
+  if (carrier->sib1->tdd_Config == NULL) { // FDD
+    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 (carrier->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;
+
+      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;
+
+      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;
+  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 ;
+  rrcConnectionSetup->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r8.radioResourceConfigDedicated.srb_ToAddModList = *SRB_configList;
+  rrcConnectionSetup->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r8.radioResourceConfigDedicated.drb_ToAddModList = NULL;
+  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 = 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_dB1;  // Value dB1 =1 dB, dB3 = 3 dB
+
+  if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
+    xer_fprint(stdout, &asn_DEF_LTE_DL_CCCH_Message, (void *)&dl_ccch_msg);
+  }
+
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_DL_CCCH_Message,
+                                   NULL,
+                                   (void *)&dl_ccch_msg,
+                                   buffer,
+                                   100);
+
+  if(enc_rval.encoded == -1) {
+    LOG_I(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n",
+          enc_rval.failed_type->name, enc_rval.encoded);
+    return -1;
+  }
+
+  LOG_D(RRC,"RRCConnectionSetup Encoded %zd bits (%zd bytes) \n",
+        enc_rval.encoded,(enc_rval.encoded+7)/8);
+  //  FREEMEM(SRB_list);
+  //  free(SRB1_config);
+  //  free(SRB1_rlc_config);
+  //  free(SRB1_lchan_config);
+  //  free(SRB1_ul_SpecificParameters);
+  return((enc_rval.encoded+7)/8);
+}
+
+
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+uint8_t do_RRCConnectionSetup_BR(
+				 const protocol_ctxt_t*     const ctxt_pP,
+				 rrc_eNB_ue_context_t*      const ue_context_pP,
+				 int                              CC_id,
+				 uint8_t*                   const buffer,
+				 const uint8_t                    transmission_mode,
+				 const uint8_t                    Transaction_id,
+				 LTE_SRB_ToAddModList_t             **SRB_configList,
+				 struct LTE_PhysicalConfigDedicated **physicalConfigDedicated)
+{
+
+  asn_enc_rval_t enc_rval;
+  eNB_RRC_INST *rrc               = RC.rrc[ctxt_pP->module_id];
+  rrc_eNB_carrier_data_t *carrier = &rrc->carrier[CC_id];
+
+  long* logicalchannelgroup = NULL;
+  struct LTE_SRB_ToAddMod* SRB1_config = NULL;
+  struct LTE_SRB_ToAddMod__rlc_Config* SRB1_rlc_config = NULL;
+  struct LTE_SRB_ToAddMod__logicalChannelConfig* SRB1_lchan_config = NULL;
+  struct LTE_LogicalChannelConfig__ul_SpecificParameters* SRB1_ul_SpecificParameters = NULL;
+
+#ifdef CBA
+  struct PUSCH_CBAConfigDedicated_vlola*  pusch_CBAConfigDedicated_vlola = NULL;
+  long* betaOffset_CBA_Index = NULL;
+  long* cShift_CBA = NULL;
+#endif
+  LTE_PhysicalConfigDedicated_t* physicalConfigDedicated2 = NULL;
+
+  LTE_DL_CCCH_Message_t dl_ccch_msg;
+
+  LTE_RRCConnectionSetup_t* rrcConnectionSetup = NULL;
+
+  memset((void *)&dl_ccch_msg,0,sizeof(LTE_DL_CCCH_Message_t));
+  dl_ccch_msg.message.present           = LTE_DL_CCCH_MessageType_PR_c1;
+  dl_ccch_msg.message.choice.c1.present = LTE_DL_CCCH_MessageType__c1_PR_rrcConnectionSetup;
+  rrcConnectionSetup          = &dl_ccch_msg.message.choice.c1.choice.rrcConnectionSetup;
+
+  // RRCConnectionSetup
+  // Configure SRB1
+
+  //  *SRB_configList = CALLOC(1,sizeof(*SRB_configList));
+  if (*SRB_configList) {
+    free(*SRB_configList);
+  }
+
+  *SRB_configList = CALLOC(1,sizeof(LTE_SRB_ToAddModList_t));
+
+  /// SRB1
+  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; // check this
+
+  SRB1_rlc_config->present = LTE_SRB_ToAddMod__rlc_Config_PR_explicitValue;
+  SRB1_rlc_config->choice.explicitValue.present = LTE_RLC_Config_PR_am;
+#if defined(ENABLE_ITTI)
+  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = rrc->srb1_timer_poll_retransmit;
+  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU          = rrc->srb1_poll_pdu;
+  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte         = rrc->srb1_poll_byte;
+  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = rrc->srb1_max_retx_threshold;
+  SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering     = rrc->srb1_timer_reordering;
+  SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = rrc->srb1_timer_status_prohibit;
+#else
+  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = LTE_T_PollRetransmit_ms20; // FIXME should be 80
+  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU          = LTE_PollPDU_p4; // FIXME should be infinity
+  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte         = LTE_PollByte_kBinfinity;
+  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = LTE_UL_AM_RLC__maxRetxThreshold_t8;
+
+  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_ms0;
+#endif
+
+  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_configList)->list,SRB1_config);
+
+  // PhysicalConfigDedicated
+
+  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->tpc_PDCCH_ConfigPUCCH         = NULL;
+  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH         = NULL;
+
+  physicalConfigDedicated2->uplinkPowerControlDedicated   = CALLOC(1,sizeof(*physicalConfigDedicated2->uplinkPowerControlDedicated));
+  physicalConfigDedicated2->cqi_ReportConfig              = CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig));
+
+  if (rrc->srs_enable[CC_id])
+      physicalConfigDedicated2->soundingRS_UL_ConfigDedicated = CALLOC(1,sizeof(*physicalConfigDedicated2->soundingRS_UL_ConfigDedicated));
+  else
+      physicalConfigDedicated2->soundingRS_UL_ConfigDedicated = NULL;
+  physicalConfigDedicated2->antennaInfo                   = CALLOC(1,sizeof(*physicalConfigDedicated2->antennaInfo));
+  physicalConfigDedicated2->schedulingRequestConfig       = CALLOC(1,sizeof(*physicalConfigDedicated2->schedulingRequestConfig));
+#ifdef CBA
+  physicalConfigDedicated2->pusch_CBAConfigDedicated_vlola = CALLOC(1,sizeof(*physicalConfigDedicated2->pusch_CBAConfigDedicated_vlola));
+#endif
+
+  if (carrier->p_eNB==2)
+    physicalConfigDedicated2->pdsch_ConfigDedicated->p_a = LTE_PDSCH_ConfigDedicated__p_a_dB_3;
+  else
+    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;
+
+  // PUSCH
+  physicalConfigDedicated2->pusch_ConfigDedicated->betaOffset_ACK_Index = 10;
+  physicalConfigDedicated2->pusch_ConfigDedicated->betaOffset_RI_Index = 9;
+  physicalConfigDedicated2->pusch_ConfigDedicated->betaOffset_CQI_Index = 10;
+
+  //
+
+
+  if (carrier->sib1->tdd_Config == NULL) {
+    physicalConfigDedicated2->pucch_ConfigDedicated->tdd_AckNackFeedbackMode=NULL;//PUCCH_ConfigDedicated__tdd_AckNackFeedbackMode_multiplexing;
+  } else { //TDD
+    physicalConfigDedicated2->pucch_ConfigDedicated->tdd_AckNackFeedbackMode = CALLOC(1,sizeof(long));
+    *(physicalConfigDedicated2->pucch_ConfigDedicated->tdd_AckNackFeedbackMode) =
+      LTE_PUCCH_ConfigDedicated__tdd_AckNackFeedbackMode_bundling;//PUCCH_ConfigDedicated__tdd_AckNackFeedbackMode_multiplexing;
+  }
+
+  /// TODO to be reviewed
+  // 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;  // TRUE
+  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
+
+  // CQI ReportConfig
+  physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportModeAperiodic = CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportModeAperiodic));
+  *physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportModeAperiodic = LTE_CQI_ReportModeAperiodic_rm20;
+  physicalConfigDedicated2->cqi_ReportConfig->nomPDSCH_RS_EPRE_Offset = 0; // 0 dB
+  physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic = CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic));
+  physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->present = LTE_CQI_ReportPeriodic_PR_release;
+  physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->choice.release = (NULL_t)0;
+
+
+  /// TODO to be reviewed
+  if (rrc->srs_enable[CC_id]) {
+      physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->present = LTE_SoundingRS_UL_ConfigDedicated_PR_setup;
+      physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.srs_Bandwidth =
+              LTE_SoundingRS_UL_ConfigDedicated__setup__srs_Bandwidth_bw0;
+      physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.srs_HoppingBandwidth =
+              LTE_SoundingRS_UL_ConfigDedicated__setup__srs_HoppingBandwidth_hbw0;
+      physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.freqDomainPosition=0;
+      physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.duration=1;
+      if (carrier->sib1->tdd_Config==NULL) { // FDD
+          if (carrier->sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.present
+                  == LTE_SoundingRS_UL_ConfigCommon_PR_setup)
+              if (carrier->sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_SubframeConfig!=0)
+                  LOG_W(RRC,"This code has been optimized for SRS Subframe Config 0, but current config is %d. Expect undefined behaviour!\n",
+                        (int)carrier->sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_SubframeConfig);
+          if (ue_context_pP->local_uid >=20)
+              LOG_W(RRC,"This code has been optimized for up to 10 UEs, but current UE_id is %d. Expect undefined behaviour!\n",
+                    ue_context_pP->local_uid);
+          //the current code will allow for 20 UEs - to be revised for more
+          physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.srs_ConfigIndex=7+ue_context_pP->local_uid/2;
+          physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.transmissionComb= ue_context_pP->local_uid%2;
+      }
+      else {
+          if (carrier->sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.present
+                  == LTE_SoundingRS_UL_ConfigCommon_PR_setup)
+              if (carrier->sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_SubframeConfig!=7) {
+                  LOG_W(RRC,"This code has been optimized for SRS Subframe Config 7 and TDD config 3, but current configs are %d and %d. Expect undefined behaviour!\n",
+                        (int)carrier->sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_SubframeConfig,
+                        (int)carrier->sib1->tdd_Config->subframeAssignment);
+              }
+          if (ue_context_pP->local_uid >=6)
+              LOG_W(RRC,"This code has been optimized for up to 6 UEs, but current UE_id is %d. Expect undefined behaviour!\n",
+                    ue_context_pP->local_uid);
+          physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.srs_ConfigIndex=17+ue_context_pP->local_uid/2;
+          physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.transmissionComb= ue_context_pP->local_uid%2;
+      }
+      LOG_W(RRC,"local UID %d, srs ConfigIndex %d, TransmissionComb %d\n",ue_context_pP->local_uid,
+            (int)physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.srs_ConfigIndex,
+            (int)physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.transmissionComb);
+
+      physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.cyclicShift=
+              LTE_SoundingRS_UL_ConfigDedicated__setup__cyclicShift_cs0;
+  }
+
+  //AntennaInfoDedicated
+  physicalConfigDedicated2->antennaInfo = CALLOC(1,sizeof(*physicalConfigDedicated2->antennaInfo));
+  physicalConfigDedicated2->antennaInfo->present = LTE_PhysicalConfigDedicated__antennaInfo_PR_explicitValue;
+
   switch (transmission_mode) {
   default:
     LOG_W(RRC,"At RRCConnectionSetup Transmission mode can only take values 1 or 2! Defaulting to 1!\n");
   case 1:
-    physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm1;
+    physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     LTE_AntennaInfoDedicated__transmissionMode_tm1;
     break;
 
   case 2:
-    physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm2;
+    physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     LTE_AntennaInfoDedicated__transmissionMode_tm2;
     break;
     /*
-  case 3:
-    physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm3;
-    physicalConfigDedicated2->antennaInfo->choice.explicitValue.codebookSubsetRestriction=     CALLOC(1,
-        sizeof(*physicalConfigDedicated2->antennaInfo->choice.explicitValue.codebookSubsetRestriction));
-    physicalConfigDedicated2->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
+      case 3:
+      physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm3;
+      physicalConfigDedicated2->antennaInfo->choice.explicitValue.codebookSubsetRestriction=     CALLOC(1,
+      sizeof(*physicalConfigDedicated2->antennaInfo->choice.explicitValue.codebookSubsetRestriction));
+      physicalConfigDedicated2->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
       AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm3;
-    physicalConfigDedicated2->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.buf= MALLOC(1);
-    physicalConfigDedicated2->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.buf[0] = 0xc0;
-    physicalConfigDedicated2->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.size=1;
-    physicalConfigDedicated2->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.bits_unused=6;
+      physicalConfigDedicated2->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.buf= MALLOC(1);
+      physicalConfigDedicated2->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.buf[0] = 0xc0;
+      physicalConfigDedicated2->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.size=1;
+      physicalConfigDedicated2->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.bits_unused=6;
 
-    break;
+      break;
 
-  case 4:
-    physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm4;
-    break;
+      case 4:
+      physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm4;
+      break;
 
-  case 5:
-    physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm5;
-    break;
+      case 5:
+      physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm5;
+      break;
 
-  case 6:
-    physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm6;
-    break;
+      case 6:
+      physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm6;
+      break;
 
-  case 7:
-    physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm7;
-    break;
+      case 7:
+      physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm7;
+      break;
     */
   }
 
 
-  physicalConfigDedicated2->antennaInfo->choice.explicitValue.ue_TransmitAntennaSelection.present = AntennaInfoDedicated__ue_TransmitAntennaSelection_PR_release;
+  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 = SchedulingRequestConfig_PR_setup;
-  if (carrier->sib1->tdd_Config == NULL) {
-    physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_PUCCH_ResourceIndex = 71 - ue_context_pP->local_uid/10;//ue_context_pP->local_uid;
-  } else {
-      switch (carrier->sib1->tdd_Config->subframeAssignment) {
-      case 1:
-          switch(frame_parms->N_RB_UL){
-          case 25:
-              physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_PUCCH_ResourceIndex = 15 - ue_context_pP->local_uid/4;
-              break;
-          case 50:
-              physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_PUCCH_ResourceIndex = 31 - ue_context_pP->local_uid/4;
-              break;
-          case 100:
-              physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_PUCCH_ResourceIndex = 63 - ue_context_pP->local_uid/4;
-              break;
-          }
-          break;
-      default:
-          physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_PUCCH_ResourceIndex = 71 - ue_context_pP->local_uid/10;//ue_context_pP->local_uid;
-          break;
-      }
-  }
+  physicalConfigDedicated2->schedulingRequestConfig->present = LTE_SchedulingRequestConfig_PR_setup;
+  physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_PUCCH_ResourceIndex = 18;//ue_context_pP->local_uid;
 
   if (carrier->sib1->tdd_Config == NULL) { // FDD
-    physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 5+(ue_context_pP->local_uid%10);  // Isr = 5 (every 10 subframes, offset=2+UE_id mod3)
+    physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 76+(ue_context_pP->local_uid%10);  // Isr = 76 (every 80 subframes, offset=2+UE_id mod3)
   } else {
     switch (carrier->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..)
+															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;
+
+    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;
 
-    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;
+    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;
+    }
+  }
+
+
+  physicalConfigDedicated2->schedulingRequestConfig->choice.setup.dsr_TransMax = LTE_SchedulingRequestConfig__setup__dsr_TransMax_n16;
+
+  physicalConfigDedicated2->ext4 =  calloc(1, sizeof(struct LTE_PhysicalConfigDedicated__ext4) );
+  physicalConfigDedicated2->ext4->csi_RS_ConfigNZPToReleaseList_r11 = NULL;
+  physicalConfigDedicated2->ext4->csi_RS_ConfigNZPToAddModList_r11 = NULL;
+  physicalConfigDedicated2->ext4->csi_RS_ConfigZPToAddModList_r11 = NULL;
+  physicalConfigDedicated2->ext4->csi_RS_ConfigZPToReleaseList_r11 = NULL;
+
+  physicalConfigDedicated2->ext4->epdcch_Config_r11 = calloc(1, sizeof(struct LTE_EPDCCH_Config_r11 ));
+  physicalConfigDedicated2->ext4->epdcch_Config_r11->config_r11.present = LTE_EPDCCH_Config_r11__config_r11_PR_setup;
+  physicalConfigDedicated2->ext4->epdcch_Config_r11->config_r11.choice.setup.subframePatternConfig_r11 = NULL;
+  physicalConfigDedicated2->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11 = calloc(1,sizeof(long));
+  *physicalConfigDedicated2->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11 = 2;
+  physicalConfigDedicated2->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToReleaseList_r11 = NULL;
+
+
+  physicalConfigDedicated2->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11 = calloc(1, sizeof(LTE_EPDCCH_SetConfigToAddModList_r11_t));
+  //  memset(physicalConfigDedicated2->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11, 0, sizeof())
+  LTE_EPDCCH_SetConfig_r11_t *epdcch_setconfig_r11 = calloc(1, sizeof(LTE_EPDCCH_SetConfig_r11_t));
+  epdcch_setconfig_r11->setConfigId_r11 = 0;
+  epdcch_setconfig_r11->transmissionType_r11 = LTE_EPDCCH_SetConfig_r11__transmissionType_r11_distributed;
+  epdcch_setconfig_r11->resourceBlockAssignment_r11.numberPRB_Pairs_r11 = LTE_EPDCCH_SetConfig_r11__resourceBlockAssignment_r11__numberPRB_Pairs_r11_n2;
+  //epdcch_setconfig_r11->resourceBlockAssignment_r11.resourceBlockAssignment_r11 = calloc(0, sizeof(BIT_STRING_t));
+  epdcch_setconfig_r11->resourceBlockAssignment_r11.resourceBlockAssignment_r11.buf = calloc(1, 5 * sizeof(uint8_t));
+  epdcch_setconfig_r11->resourceBlockAssignment_r11.resourceBlockAssignment_r11.size = 5;
+  epdcch_setconfig_r11->resourceBlockAssignment_r11.resourceBlockAssignment_r11.bits_unused = 2;
+  memset(epdcch_setconfig_r11->resourceBlockAssignment_r11.resourceBlockAssignment_r11.buf, 0, 5 * sizeof(uint8_t));
+
+  epdcch_setconfig_r11->dmrs_ScramblingSequenceInt_r11 = 54;
+  epdcch_setconfig_r11->pucch_ResourceStartOffset_r11 = 0;
+  epdcch_setconfig_r11->re_MappingQCL_ConfigId_r11 = NULL;
+
+  epdcch_setconfig_r11->ext2 = calloc(1, sizeof(struct LTE_EPDCCH_SetConfig_r11__ext2));
+  epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310 = calloc(1,sizeof(struct LTE_EPDCCH_SetConfig_r11__ext2__numberPRB_Pairs_v1310));
+  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->choice.setup = LTE_EPDCCH_SetConfig_r11__ext2__numberPRB_Pairs_v1310__setup_n6;
+  epdcch_setconfig_r11->ext2->mpdcch_config_r13 = calloc(1, sizeof(struct LTE_EPDCCH_SetConfig_r11__ext2__mpdcch_config_r13));
+  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->choice.setup.csi_NumRepetitionCE_r13                = LTE_EPDCCH_SetConfig_r11__ext2__mpdcch_config_r13__setup__csi_NumRepetitionCE_r13_sf1;
+  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->choice.setup.mpdcch_StartSF_UESS_r13.present        = LTE_EPDCCH_SetConfig_r11__ext2__mpdcch_config_r13__setup__mpdcch_StartSF_UESS_r13_PR_fdd_r13;
+  epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_StartSF_UESS_r13.choice.fdd_r13 = LTE_EPDCCH_SetConfig_r11__ext2__mpdcch_config_r13__setup__mpdcch_StartSF_UESS_r13__fdd_r13_v1;
+  epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_NumRepetition_r13               = LTE_EPDCCH_SetConfig_r11__ext2__mpdcch_config_r13__setup__mpdcch_NumRepetition_r13_r1;
+  epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13                  = 3; // note: this is narrowband index 2
+  ASN_SEQUENCE_ADD(physicalConfigDedicated2->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11, epdcch_setconfig_r11);
+
+
+  // FIXME allocate physicalConfigDedicated2->ext7
+  physicalConfigDedicated2->ext7 = CALLOC(1, sizeof(struct LTE_PhysicalConfigDedicated__ext7));
+
+  physicalConfigDedicated2->ext7->pdsch_ConfigDedicated_v1310 = NULL; // has some parameters to be filled
+
+  physicalConfigDedicated2->ext7->pusch_ConfigDedicated_r13 = NULL;
+  physicalConfigDedicated2->ext7->pucch_ConfigDedicated_r13 = 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;
+  physicalConfigDedicated2->ext7->pdcch_CandidateReductions_r13 = NULL;
 
-    default:
-      physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 7;  // Isr = 5 (every 10 subframes, offset=2 for all UE0 etc..)
-      break;
-    }
-  }
+  physicalConfigDedicated2->ext7->cqi_ReportConfig_v1310 = NULL;
+
+  physicalConfigDedicated2->ext7->soundingRS_UL_ConfigDedicated_v1310 = NULL;
+  physicalConfigDedicated2->ext7->soundingRS_UL_ConfigDedicatedUpPTsExt_r13 = NULL;
+  physicalConfigDedicated2->ext7->soundingRS_UL_ConfigDedicatedAperiodic_v1310 = NULL;
+  physicalConfigDedicated2->ext7->soundingRS_UL_ConfigDedicatedAperiodicUpPTsExt_r13 = NULL;
+
+  physicalConfigDedicated2->ext7->csi_RS_Config_v1310 = NULL;
+
+  // FIXME ce_Mode_r13 allocation
+  physicalConfigDedicated2->ext7->ce_Mode_r13 = CALLOC(1, sizeof(struct LTE_PhysicalConfigDedicated__ext7__ce_Mode_r13));
+  physicalConfigDedicated2->ext7->ce_Mode_r13->present      = LTE_PhysicalConfigDedicated__ext7__ce_Mode_r13_PR_setup;
+  physicalConfigDedicated2->ext7->ce_Mode_r13->choice.setup = LTE_PhysicalConfigDedicated__ext7__ce_Mode_r13__setup_ce_ModeA;
+  physicalConfigDedicated2->ext7->csi_RS_ConfigNZPToAddModListExt_r13 = NULL;
+  physicalConfigDedicated2->ext7->csi_RS_ConfigNZPToReleaseListExt_r13 = NULL;
 
-  //  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 = SchedulingRequestConfig__setup__dsr_TransMax_n4;
 
   rrcConnectionSetup->rrc_TransactionIdentifier = Transaction_id;
-  rrcConnectionSetup->criticalExtensions.present = RRCConnectionSetup__criticalExtensions_PR_c1;
-  rrcConnectionSetup->criticalExtensions.choice.c1.present =RRCConnectionSetup__criticalExtensions__c1_PR_rrcConnectionSetup_r8 ;
+  rrcConnectionSetup->criticalExtensions.present = LTE_RRCConnectionSetup__criticalExtensions_PR_c1;
+  rrcConnectionSetup->criticalExtensions.choice.c1.present =LTE_RRCConnectionSetup__criticalExtensions__c1_PR_rrcConnectionSetup_r8 ;
   rrcConnectionSetup->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r8.radioResourceConfigDedicated.srb_ToAddModList = *SRB_configList;
   rrcConnectionSetup->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r8.radioResourceConfigDedicated.drb_ToAddModList = NULL;
   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;
-#ifdef CBA
-  betaOffset_CBA_Index = CALLOC(1,sizeof(long));
-  cShift_CBA = CALLOC(1,sizeof(long));
-  *betaOffset_CBA_Index=10; // need to be changed by Kaijie
-  *cShift_CBA=4;
-  physicalConfigDedicated2->pusch_CBAConfigDedicated_vlola->betaOffset_CBA_Index=betaOffset_CBA_Index;
-  physicalConfigDedicated2->pusch_CBAConfigDedicated_vlola->cShift_CBA=cShift_CBA;
-  rrcConnectionSetup->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r8.radioResourceConfigDedicated.sps_CBA_ConfigList_vlola = NULL;
-#endif
 
+#ifdef XER_PRINT
+  xer_fprint(stdout, &asn_DEF_DL_CCCH_Message, (void*)&dl_ccch_msg);
+#endif
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_DL_CCCH_Message,
+				   NULL,
+				   (void*)&dl_ccch_msg,
+				   buffer,
+				   100);
+  AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
+	       enc_rval.failed_type->name, enc_rval.encoded);
 
-  if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-     xer_fprint(stdout, &asn_DEF_DL_CCCH_Message, (void*)&dl_ccch_msg);
-  }
-  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_CCCH_Message,
-                                   NULL,
-                                   (void*)&dl_ccch_msg,
-                                   buffer,
-                                   100);
-  if(enc_rval.encoded == -1)
-  {
-     LOG_I(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n",
-           enc_rval.failed_type->name, enc_rval.encoded);
-     return -1;
-  }
 #if defined(ENABLE_ITTI)
 # if !defined(DISABLE_XER_SPRINT)
   {
     char        message_string[20000];
     size_t      message_string_size;
 
-    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_CCCH_Message, (void *) &dl_ccch_msg)) > 0) {
+    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_LTE_DL_CCCH_Message, (void *) &dl_ccch_msg)) > 0) {
       MessageDef *msg_p;
 
       msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_CCCH, message_string_size + sizeof (IttiMsgText));
@@ -2201,8 +3123,10 @@ do_RRCConnectionSetup(
 # endif
 #endif
 
-  LOG_D(RRC,"RRCConnectionSetup Encoded %zd bits (%zd bytes) \n",
-        enc_rval.encoded,(enc_rval.encoded+7)/8);
+#ifdef USER_MODE
+  LOG_D(RRC,"RRCConnectionSetup_BR Encoded %d bits (%d bytes), ecause %d\n",
+	enc_rval.encoded,(enc_rval.encoded+7)/8,ecause);
+#endif
 
   //  FREEMEM(SRB_list);
   //  free(SRB1_config);
@@ -2212,69 +3136,51 @@ do_RRCConnectionSetup(
 
   return((enc_rval.encoded+7)/8);
 }
+#endif
 
-//------------------------------------------------------------------------------
-uint8_t
-do_SecurityModeCommand(
-  const protocol_ctxt_t* const ctxt_pP,
-  uint8_t* const buffer,
-  const uint8_t Transaction_id,
-  const uint8_t cipheringAlgorithm,
-  const uint8_t integrityProtAlgorithm
-)
+
+
+
+uint8_t do_SecurityModeCommand(
+			       const protocol_ctxt_t *const ctxt_pP,
+			       uint8_t *const buffer,
+			       const uint8_t Transaction_id,
+			       const uint8_t cipheringAlgorithm,
+			       const uint8_t integrityProtAlgorithm
+			       )
 //------------------------------------------------------------------------------
 {
-  DL_DCCH_Message_t dl_dcch_msg;
+  LTE_DL_DCCH_Message_t dl_dcch_msg;
   asn_enc_rval_t enc_rval;
-
-  memset(&dl_dcch_msg,0,sizeof(DL_DCCH_Message_t));
-
-  dl_dcch_msg.message.present           = DL_DCCH_MessageType_PR_c1;
-  dl_dcch_msg.message.choice.c1.present = DL_DCCH_MessageType__c1_PR_securityModeCommand;
+  memset(&dl_dcch_msg,0,sizeof(LTE_DL_DCCH_Message_t));
+  dl_dcch_msg.message.present           = LTE_DL_DCCH_MessageType_PR_c1;
+  dl_dcch_msg.message.choice.c1.present = LTE_DL_DCCH_MessageType__c1_PR_securityModeCommand;
 
   dl_dcch_msg.message.choice.c1.choice.securityModeCommand.rrc_TransactionIdentifier = Transaction_id;
-  dl_dcch_msg.message.choice.c1.choice.securityModeCommand.criticalExtensions.present = SecurityModeCommand__criticalExtensions_PR_c1;
-
+  dl_dcch_msg.message.choice.c1.choice.securityModeCommand.criticalExtensions.present = LTE_SecurityModeCommand__criticalExtensions_PR_c1;
   dl_dcch_msg.message.choice.c1.choice.securityModeCommand.criticalExtensions.choice.c1.present =
-    SecurityModeCommand__criticalExtensions__c1_PR_securityModeCommand_r8;
+    LTE_SecurityModeCommand__criticalExtensions__c1_PR_securityModeCommand_r8;
   // the two following information could be based on the mod_id
   dl_dcch_msg.message.choice.c1.choice.securityModeCommand.criticalExtensions.choice.c1.choice.securityModeCommand_r8.securityConfigSMC.securityAlgorithmConfig.cipheringAlgorithm
-    = (CipheringAlgorithm_r12_t)cipheringAlgorithm;
+    = (LTE_CipheringAlgorithm_r12_t)cipheringAlgorithm;
   dl_dcch_msg.message.choice.c1.choice.securityModeCommand.criticalExtensions.choice.c1.choice.securityModeCommand_r8.securityConfigSMC.securityAlgorithmConfig.integrityProtAlgorithm
-    = (e_SecurityAlgorithmConfig__integrityProtAlgorithm)integrityProtAlgorithm;
+    = (e_LTE_SecurityAlgorithmConfig__integrityProtAlgorithm)integrityProtAlgorithm;
 
   if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-     xer_fprint(stdout, &asn_DEF_DL_DCCH_Message, (void*)&dl_dcch_msg);
+    xer_fprint(stdout, &asn_DEF_LTE_DL_DCCH_Message, (void *)&dl_dcch_msg);
   }
-  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_DCCH_Message,
+
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_DL_DCCH_Message,
                                    NULL,
-                                   (void*)&dl_dcch_msg,
+                                   (void *)&dl_dcch_msg,
                                    buffer,
                                    100);
-  if(enc_rval.encoded == -1)
-  {
-     LOG_I(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n",
-           enc_rval.failed_type->name, enc_rval.encoded);
-     return -1;
-  }
-#if defined(ENABLE_ITTI)
-# if !defined(DISABLE_XER_SPRINT)
-  {
-    char        message_string[20000];
-    size_t      message_string_size;
-
-    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_DCCH_Message, (void *) &dl_dcch_msg)) > 0) {
-      MessageDef *msg_p;
-
-      msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_DCCH, message_string_size + sizeof (IttiMsgText));
-      msg_p->ittiMsg.rrc_dl_dcch.size = message_string_size;
-      memcpy(&msg_p->ittiMsg.rrc_dl_dcch.text, message_string, message_string_size);
 
-      itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
-    }
+  if(enc_rval.encoded == -1) {
+    LOG_I(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n",
+          enc_rval.failed_type->name, enc_rval.encoded);
+    return -1;
   }
-# endif
-#endif
 
   LOG_D(RRC,"[eNB %d] securityModeCommand for UE %x Encoded %zd bits (%zd bytes)\n",
         ctxt_pP->module_id,
@@ -2284,8 +3190,8 @@ do_SecurityModeCommand(
 
   if (enc_rval.encoded==-1) {
     LOG_E(RRC,"[eNB %d] ASN1 : securityModeCommand encoding failed for UE %x\n",
-          ctxt_pP->module_id,
-          ctxt_pP->rnti);
+	  ctxt_pP->module_id,
+	  ctxt_pP->rnti);
     return(-1);
   }
 
@@ -2295,66 +3201,40 @@ do_SecurityModeCommand(
 }
 
 //------------------------------------------------------------------------------
-uint8_t
-do_UECapabilityEnquiry(
-  const protocol_ctxt_t* const ctxt_pP,
-  uint8_t*               const buffer,
-  const uint8_t                Transaction_id
-)
+uint8_t do_UECapabilityEnquiry( const protocol_ctxt_t *const ctxt_pP,
+				uint8_t               *const buffer,
+				const uint8_t                Transaction_id)
 //------------------------------------------------------------------------------
 {
-
-  DL_DCCH_Message_t dl_dcch_msg;
-
-  RAT_Type_t rat=RAT_Type_eutra;
+  LTE_DL_DCCH_Message_t dl_dcch_msg;
+  LTE_RAT_Type_t rat=LTE_RAT_Type_eutra;
   asn_enc_rval_t enc_rval;
-
-  memset(&dl_dcch_msg,0,sizeof(DL_DCCH_Message_t));
-
-  dl_dcch_msg.message.present           = DL_DCCH_MessageType_PR_c1;
-  dl_dcch_msg.message.choice.c1.present = DL_DCCH_MessageType__c1_PR_ueCapabilityEnquiry;
-
+  memset(&dl_dcch_msg,0,sizeof(LTE_DL_DCCH_Message_t));
+  dl_dcch_msg.message.present           = LTE_DL_DCCH_MessageType_PR_c1;
+  dl_dcch_msg.message.choice.c1.present = LTE_DL_DCCH_MessageType__c1_PR_ueCapabilityEnquiry;
   dl_dcch_msg.message.choice.c1.choice.ueCapabilityEnquiry.rrc_TransactionIdentifier = Transaction_id;
-
-  dl_dcch_msg.message.choice.c1.choice.ueCapabilityEnquiry.criticalExtensions.present = UECapabilityEnquiry__criticalExtensions_PR_c1;
+  dl_dcch_msg.message.choice.c1.choice.ueCapabilityEnquiry.criticalExtensions.present = LTE_UECapabilityEnquiry__criticalExtensions_PR_c1;
   dl_dcch_msg.message.choice.c1.choice.ueCapabilityEnquiry.criticalExtensions.choice.c1.present =
-    UECapabilityEnquiry__criticalExtensions__c1_PR_ueCapabilityEnquiry_r8;
+    LTE_UECapabilityEnquiry__criticalExtensions__c1_PR_ueCapabilityEnquiry_r8;
   dl_dcch_msg.message.choice.c1.choice.ueCapabilityEnquiry.criticalExtensions.choice.c1.choice.ueCapabilityEnquiry_r8.ue_CapabilityRequest.list.count=0;
   ASN_SEQUENCE_ADD(&dl_dcch_msg.message.choice.c1.choice.ueCapabilityEnquiry.criticalExtensions.choice.c1.choice.ueCapabilityEnquiry_r8.ue_CapabilityRequest.list,
-                   &rat);
+		   &rat);
 
   if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-     xer_fprint(stdout, &asn_DEF_DL_DCCH_Message, (void*)&dl_dcch_msg);
+    xer_fprint(stdout, &asn_DEF_LTE_DL_DCCH_Message, (void *)&dl_dcch_msg);
   }
-  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_DCCH_Message,
+
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_DL_DCCH_Message,
                                    NULL,
-                                   (void*)&dl_dcch_msg,
+                                   (void *)&dl_dcch_msg,
                                    buffer,
                                    100);
-  if(enc_rval.encoded == -1)
-  {
-     LOG_I(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n",
-           enc_rval.failed_type->name, enc_rval.encoded);
-     return -1;
-  }
-#if defined(ENABLE_ITTI)
-# if !defined(DISABLE_XER_SPRINT)
-  {
-    char        message_string[20000];
-    size_t      message_string_size;
-
-    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_DCCH_Message, (void *) &dl_dcch_msg)) > 0) {
-      MessageDef *msg_p;
-
-      msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_CCCH, message_string_size + sizeof (IttiMsgText));
-      msg_p->ittiMsg.rrc_dl_ccch.size = message_string_size;
-      memcpy(&msg_p->ittiMsg.rrc_dl_ccch.text, message_string, message_string_size);
 
-      itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
-    }
+  if(enc_rval.encoded == -1) {
+    LOG_I(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n",
+          enc_rval.failed_type->name, enc_rval.encoded);
+    return -1;
   }
-# endif
-#endif
 
   LOG_D(RRC,"[eNB %d] UECapabilityRequest for UE %x Encoded %zd bits (%zd bytes)\n",
         ctxt_pP->module_id,
@@ -2364,92 +3244,82 @@ do_UECapabilityEnquiry(
 
   if (enc_rval.encoded==-1) {
     LOG_E(RRC,"[eNB %d] ASN1 : UECapabilityRequest encoding failed for UE %x\n",
-          ctxt_pP->module_id,
-          ctxt_pP->rnti);
+	  ctxt_pP->module_id,
+	  ctxt_pP->rnti);
     return(-1);
   }
 
   return((enc_rval.encoded+7)/8);
 }
 
-//------------------------------------------------------------------------------
-uint16_t
-do_RRCConnectionReconfiguration(
-  const protocol_ctxt_t*        const ctxt_pP,
-  uint8_t                            *buffer,
-  uint8_t                             Transaction_id,
-  SRB_ToAddModList_t                 *SRB_list,
-  DRB_ToAddModList_t                 *DRB_list,
-  DRB_ToReleaseList_t                *DRB_list2,
-  struct SPS_Config                  *sps_Config,
-  struct PhysicalConfigDedicated     *physicalConfigDedicated,
-  MeasObjectToAddModList_t           *MeasObj_list,
-  ReportConfigToAddModList_t         *ReportConfig_list,
-  QuantityConfig_t                   *quantityConfig,
-  MeasIdToAddModList_t               *MeasId_list,
-  MAC_MainConfig_t                   *mac_MainConfig,
-  MeasGapConfig_t                    *measGapConfig,
-  MobilityControlInfo_t              *mobilityInfo,
-  struct MeasConfig__speedStatePars  *speedStatePars,
-  RSRP_Range_t                       *rsrp,
-  C_RNTI_t                           *cba_rnti,
-  struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList
-  *dedicatedInfoNASList,
-  SL_CommConfig_r12_t                *sl_CommConfig,
-  SL_DiscConfig_r12_t                *sl_DiscConfig
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-  , SCellToAddMod_r10_t  *SCell_config
-#endif
-
-)
-//------------------------------------------------------------------------------
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+uint16_t do_RRCConnectionReconfiguration_BR(const protocol_ctxt_t*        const ctxt_pP,
+					    uint8_t                            *buffer,
+					    uint8_t                             Transaction_id,
+					    LTE_SRB_ToAddModList_t                 *SRB_list,
+					    LTE_DRB_ToAddModList_t                 *DRB_list,
+					    LTE_DRB_ToReleaseList_t                *DRB_list2,
+					    struct LTE_SPS_Config                  *sps_Config,
+					    struct LTE_PhysicalConfigDedicated     *physicalConfigDedicated,
+					    LTE_MeasObjectToAddModList_t           *MeasObj_list,
+					    LTE_ReportConfigToAddModList_t         *ReportConfig_list,
+					    LTE_QuantityConfig_t                   *quantityConfig,
+					    LTE_MeasIdToAddModList_t               *MeasId_list,
+					    LTE_MAC_MainConfig_t                   *mac_MainConfig,
+					    LTE_MeasGapConfig_t                    *measGapConfig,
+					    LTE_MobilityControlInfo_t              *mobilityInfo,
+					    struct LTE_MeasConfig__speedStatePars  *speedStatePars,
+					    LTE_RSRP_Range_t                       *rsrp,
+					    LTE_C_RNTI_t                           *cba_rnti,
+					    struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList,
+					    LTE_SCellToAddMod_r10_t  *SCell_config)
 {
-
   asn_enc_rval_t enc_rval;
 
-  DL_DCCH_Message_t dl_dcch_msg;
-  RRCConnectionReconfiguration_t *rrcConnectionReconfiguration;
+  LTE_DL_DCCH_Message_t dl_dcch_msg;
+  LTE_RRCConnectionReconfiguration_t *rrcConnectionReconfiguration;
 
 
-  memset(&dl_dcch_msg,0,sizeof(DL_DCCH_Message_t));
+  memset(&dl_dcch_msg,0,sizeof(LTE_DL_DCCH_Message_t));
 
-  dl_dcch_msg.message.present           = DL_DCCH_MessageType_PR_c1;
-  dl_dcch_msg.message.choice.c1.present = DL_DCCH_MessageType__c1_PR_rrcConnectionReconfiguration;
+  dl_dcch_msg.message.present           = LTE_DL_DCCH_MessageType_PR_c1;
+  dl_dcch_msg.message.choice.c1.present = LTE_DL_DCCH_MessageType__c1_PR_rrcConnectionReconfiguration;
   rrcConnectionReconfiguration          = &dl_dcch_msg.message.choice.c1.choice.rrcConnectionReconfiguration;
 
   // RRCConnectionReconfiguration
   rrcConnectionReconfiguration->rrc_TransactionIdentifier = Transaction_id;
-  rrcConnectionReconfiguration->criticalExtensions.present = RRCConnectionReconfiguration__criticalExtensions_PR_c1;
-  rrcConnectionReconfiguration->criticalExtensions.choice.c1.present =RRCConnectionReconfiguration__criticalExtensions__c1_PR_rrcConnectionReconfiguration_r8 ;
+  rrcConnectionReconfiguration->criticalExtensions.present = LTE_RRCConnectionReconfiguration__criticalExtensions_PR_c1;
+  rrcConnectionReconfiguration->criticalExtensions.choice.c1.present =LTE_RRCConnectionReconfiguration__criticalExtensions__c1_PR_rrcConnectionReconfiguration_r8 ;
 
   rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated = CALLOC(1,
-      sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated));
+																	  sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated));
   rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->srb_ToAddModList = SRB_list;
   rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList = DRB_list;
   rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToReleaseList = DRB_list2;
   rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->sps_Config = sps_Config;
   rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->physicalConfigDedicated = physicalConfigDedicated;
-#ifdef CBA
-  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->cba_RNTI_vlola= cba_rnti;
-#endif
+  physicalConfigDedicated->cqi_ReportConfig = CALLOC(1, sizeof(struct LTE_CQI_ReportConfig));
+  physicalConfigDedicated->cqi_ReportConfig->cqi_ReportModeAperiodic = CALLOC(1, sizeof(LTE_CQI_ReportModeAperiodic_t));
+  *physicalConfigDedicated->cqi_ReportConfig->cqi_ReportModeAperiodic = LTE_CQI_ReportModeAperiodic_rm20;
+  physicalConfigDedicated->cqi_ReportConfig->nomPDSCH_RS_EPRE_Offset = 0;
 
   if (mac_MainConfig!=NULL) {
     rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->mac_MainConfig = CALLOC(1,
-        sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->mac_MainConfig));
+																			    sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->mac_MainConfig));
     rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->mac_MainConfig->present
-      =RadioResourceConfigDedicated__mac_MainConfig_PR_explicitValue;
+      =LTE_RadioResourceConfigDedicated__mac_MainConfig_PR_explicitValue;
     memcpy(&rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->mac_MainConfig->choice.explicitValue,
-           mac_MainConfig,
-           sizeof(*mac_MainConfig));
+	   mac_MainConfig,
+	   sizeof(*mac_MainConfig));
   } else {
     rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->mac_MainConfig=NULL;
   }
 
   if (MeasId_list != NULL) {
     rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig           = CALLOC(1,
-        sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig));
+																    sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig));
     memset((void*)rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig,
-           0, sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig));
+	   0, sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig));
 
     rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->reportConfigToAddModList = ReportConfig_list;
     rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measIdToAddModList       = MeasId_list;
@@ -2457,19 +3327,19 @@ do_RRCConnectionReconfiguration(
 
     if (quantityConfig!=NULL) {
       rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->quantityConfig = CALLOC(1,
-          sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->quantityConfig));
+																	    sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->quantityConfig));
       memcpy((void *)rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->quantityConfig,
-             (void *)quantityConfig,
-             sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->quantityConfig));
+	     (void *)quantityConfig,
+	     sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->quantityConfig));
     } else {
       rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->quantityConfig = NULL;
     }
 
     if(speedStatePars != NULL) {
       rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->speedStatePars = CALLOC(1,
-          sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->speedStatePars));
+																	    sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->speedStatePars));
       memcpy((void *)rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->speedStatePars,
-             (void *)speedStatePars,sizeof(*speedStatePars));
+	     (void *)speedStatePars,sizeof(*speedStatePars));
     } else {
       rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->speedStatePars = NULL;
     }
@@ -2481,9 +3351,9 @@ do_RRCConnectionReconfiguration(
 
   if (mobilityInfo !=NULL) {
     rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.mobilityControlInfo = CALLOC(1,
-        sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.mobilityControlInfo));
+																   sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.mobilityControlInfo));
     memcpy((void*)rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.mobilityControlInfo, (void*)mobilityInfo,
-           sizeof(MobilityControlInfo_t));
+	   sizeof(LTE_MobilityControlInfo_t));
 
   } else {
     rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.mobilityControlInfo  = NULL;
@@ -2491,60 +3361,18 @@ do_RRCConnectionReconfiguration(
 
   rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.dedicatedInfoNASList = dedicatedInfoNASList;
   rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.securityConfigHO     = NULL;
-  
-  //TTN for D2D
-  //allocate dedicated resource pools for SL communication (sl_CommConfig_r12)
-  if (sl_CommConfig != NULL) {
-     LOG_I(RRC,"[RRCConnectionReconfiguration] allocating a dedicated resource pool for SL communication \n");
-     rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension = CALLOC(1,
-           sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension));
-     rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension = CALLOC(1,
-           sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension));
-     rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension = CALLOC(1,
-           sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension));
-     rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension = CALLOC(1,
-           sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension));
-     rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension = CALLOC(1,
-           sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension));
-     rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_CommConfig_r12 = CALLOC(1,
-           sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_CommConfig_r12));
-     memcpy((void*)rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_CommConfig_r12, (void*)sl_CommConfig,
-               sizeof(SL_CommConfig_r12_t));
-  }
 
-  //allocate dedicated resource pools for SL discovery (sl_DiscConfig)
-  if (sl_DiscConfig != NULL){
-     LOG_I(RRC,"[RRCConnectionReconfiguration] allocating a dedicated resource pool for SL discovery \n");
-     rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension = CALLOC(1,
-            sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension));
-     rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension = CALLOC(1,
-            sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension));
-     rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension = CALLOC(1,
-            sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension));
-     rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension = CALLOC(1,
-            sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension));
-     rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension = CALLOC(1,
-            sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension));
-     rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_DiscConfig_r12 = CALLOC(1,
-            sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_DiscConfig_r12));
-     memcpy((void*)rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_DiscConfig_r12, (void*)sl_DiscConfig,
-            sizeof(SL_DiscConfig_r12_t));
-  }
-
-  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_DCCH_Message,
-                                   NULL,
-                                   (void*)&dl_dcch_msg,
-                                   buffer,
-                                   RRC_BUF_SIZE);
-  if(enc_rval.encoded == -1)
-  {
-     LOG_I(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n",
-           enc_rval.failed_type->name, enc_rval.encoded);
-     return -1;
-  }
-  if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-     xer_fprint(stdout,&asn_DEF_DL_DCCH_Message,(void*)&dl_dcch_msg);
-  }
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_DL_DCCH_Message,
+				   NULL,
+				   (void*)&dl_dcch_msg,
+				   buffer,
+				   RRC_BUF_SIZE);
+  AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed %s, %lu!\n",
+	       enc_rval.failed_type->name, enc_rval.encoded);
+
+#ifdef XER_PRINT
+  xer_fprint(stdout,&asn_DEF_DL_DCCH_Message,(void*)&dl_dcch_msg);
+#endif
 
 #if defined(ENABLE_ITTI)
 # if !defined(DISABLE_XER_SPRINT)
@@ -2552,7 +3380,7 @@ do_RRCConnectionReconfiguration(
     char        message_string[30000];
     size_t      message_string_size;
 
-    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_DCCH_Message, (void *) &dl_dcch_msg)) > 0) {
+    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_LTE_DL_DCCH_Message, (void *) &dl_dcch_msg)) > 0) {
       MessageDef *msg_p;
 
       msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_DCCH, message_string_size + sizeof (IttiMsgText));
@@ -2565,73 +3393,254 @@ do_RRCConnectionReconfiguration(
 # endif
 #endif
 
+
+  LOG_I(RRC,"RRCConnectionReconfiguration Encoded %d bits (%d bytes)\n",(int)enc_rval.encoded,(int)(enc_rval.encoded+7)/8);
+
+  return((enc_rval.encoded+7)/8);
+}
+#endif
+
+//------------------------------------------------------------------------------
+uint16_t do_RRCConnectionReconfiguration(const protocol_ctxt_t        *const ctxt_pP,
+					 uint8_t                            *buffer,
+					 uint8_t                             Transaction_id,
+					 LTE_SRB_ToAddModList_t                 *SRB_list,
+					 LTE_DRB_ToAddModList_t                 *DRB_list,
+					 LTE_DRB_ToReleaseList_t                *DRB_list2,
+					 struct LTE_SPS_Config                  *sps_Config,
+					 struct LTE_PhysicalConfigDedicated     *physicalConfigDedicated,
+					 LTE_MeasObjectToAddModList_t           *MeasObj_list,
+					 LTE_ReportConfigToAddModList_t         *ReportConfig_list,
+					 LTE_QuantityConfig_t                   *quantityConfig,
+					 LTE_MeasIdToAddModList_t               *MeasId_list,
+					 LTE_MAC_MainConfig_t                   *mac_MainConfig,
+					 LTE_MeasGapConfig_t                    *measGapConfig,
+					 LTE_MobilityControlInfo_t              *mobilityInfo,
+                                         LTE_SecurityConfigHO_t                 *securityConfigHO,
+					 struct LTE_MeasConfig__speedStatePars  *speedStatePars,
+					 LTE_RSRP_Range_t                       *rsrp,
+					 LTE_C_RNTI_t                           *cba_rnti,
+					 struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList
+					 *dedicatedInfoNASList,
+					 LTE_SL_CommConfig_r12_t                *sl_CommConfig,
+					 LTE_SL_DiscConfig_r12_t                *sl_DiscConfig
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+					 , LTE_SCellToAddMod_r10_t  *SCell_config
+#endif
+					 )
+//------------------------------------------------------------------------------
+{
+  asn_enc_rval_t enc_rval;
+  LTE_DL_DCCH_Message_t dl_dcch_msg;
+  LTE_RRCConnectionReconfiguration_t *rrcConnectionReconfiguration;
+  memset(&dl_dcch_msg,0,sizeof(LTE_DL_DCCH_Message_t));
+  dl_dcch_msg.message.present           = LTE_DL_DCCH_MessageType_PR_c1;
+  dl_dcch_msg.message.choice.c1.present = LTE_DL_DCCH_MessageType__c1_PR_rrcConnectionReconfiguration;
+  rrcConnectionReconfiguration          = &dl_dcch_msg.message.choice.c1.choice.rrcConnectionReconfiguration;
+  // RRCConnectionReconfiguration
+  rrcConnectionReconfiguration->rrc_TransactionIdentifier = Transaction_id;
+  rrcConnectionReconfiguration->criticalExtensions.present = LTE_RRCConnectionReconfiguration__criticalExtensions_PR_c1;
+  rrcConnectionReconfiguration->criticalExtensions.choice.c1.present = LTE_RRCConnectionReconfiguration__criticalExtensions__c1_PR_rrcConnectionReconfiguration_r8 ;
+  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated = CALLOC(1,
+																	  sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated));
+  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->srb_ToAddModList = SRB_list;
+  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList = DRB_list;
+  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToReleaseList = DRB_list2;
+  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->sps_Config = sps_Config;
+  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->physicalConfigDedicated = physicalConfigDedicated;
+#ifdef CBA
+  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->cba_RNTI_vlola= cba_rnti;
+#endif
+
+  if (mac_MainConfig!=NULL) {
+    rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->mac_MainConfig = CALLOC(1,
+																			    sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->mac_MainConfig));
+    rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->mac_MainConfig->present
+      =LTE_RadioResourceConfigDedicated__mac_MainConfig_PR_explicitValue;
+    memcpy(&rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->mac_MainConfig->choice.explicitValue,
+	   mac_MainConfig,
+	   sizeof(*mac_MainConfig));
+  } else {
+    rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->mac_MainConfig=NULL;
+  }
+
+  if (MeasId_list != NULL) {
+    rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig           = CALLOC(1,
+        sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig));
+    memset((void *)rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig,
+           0, sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig));
+
+    rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->reportConfigToAddModList = ReportConfig_list;
+    rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measIdToAddModList       = MeasId_list;
+    rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measObjectToAddModList   = MeasObj_list;
+
+    if (quantityConfig!=NULL) {
+      rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->quantityConfig = CALLOC(1,
+																	    sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->quantityConfig));
+      memcpy((void *)rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->quantityConfig,
+	     (void *)quantityConfig,
+	     sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->quantityConfig));
+    } else {
+      rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->quantityConfig = NULL;
+    }
+
+    if(speedStatePars != NULL) {
+      rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->speedStatePars = CALLOC(1,
+																	    sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->speedStatePars));
+      memcpy((void *)rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->speedStatePars,
+	     (void *)speedStatePars,sizeof(*speedStatePars));
+    } else {
+      rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->speedStatePars = NULL;
+    }
+
+    rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->s_Measure= rsrp;
+  } else {
+    rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig = NULL;
+  }
+
+  if (mobilityInfo !=NULL) {
+    rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.mobilityControlInfo = CALLOC(1,
+        sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.mobilityControlInfo));
+    memcpy((void *)rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.mobilityControlInfo, (void *)mobilityInfo,
+           sizeof(LTE_MobilityControlInfo_t));
+  } else {
+    rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.mobilityControlInfo  = NULL;
+  }
+
+  if (securityConfigHO != NULL) {
+    rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.securityConfigHO     = CALLOC(1,
+        sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.securityConfigHO));
+    memcpy((void*)rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.securityConfigHO, (void*)securityConfigHO,
+           sizeof(LTE_SecurityConfigHO_t));
+  } else {
+    rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.securityConfigHO     = NULL;
+  }
+
+  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.dedicatedInfoNASList = dedicatedInfoNASList;
+
+  //TTN for D2D
+  //allocate dedicated resource pools for SL communication (sl_CommConfig_r12)
+  if (sl_CommConfig != NULL) {
+    LOG_I(RRC,"[RRCConnectionReconfiguration] allocating a dedicated resource pool for SL communication \n");
+    rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension = CALLOC(1,
+        sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension));
+    rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension = CALLOC(1,
+        sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension));
+    rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension = CALLOC(1,
+        sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension));
+    rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension = CALLOC(1,
+        sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension));
+    rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension
+      = CALLOC(1,
+               sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension));
+    rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_CommConfig_r12
+      = CALLOC(1,
+               sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_CommConfig_r12));
+    memcpy((void *)
+           rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_CommConfig_r12,
+           (void *)sl_CommConfig,
+           sizeof(LTE_SL_CommConfig_r12_t));
+  }
+
+  //allocate dedicated resource pools for SL discovery (sl_DiscConfig)
+  if (sl_DiscConfig != NULL) {
+    LOG_I(RRC,"[RRCConnectionReconfiguration] allocating a dedicated resource pool for SL discovery \n");
+    rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension = CALLOC(1,
+        sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension));
+    rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension = CALLOC(1,
+        sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension));
+    rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension = CALLOC(1,
+        sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension));
+    rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension = CALLOC(1,
+        sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension));
+    rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension
+      = CALLOC(1,
+               sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension));
+    rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_DiscConfig_r12
+      = CALLOC(1,
+               sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_DiscConfig_r12));
+    memcpy((void *)
+           rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_DiscConfig_r12,
+           (void *)sl_DiscConfig,
+           sizeof(LTE_SL_DiscConfig_r12_t));
+  }
+
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_DL_DCCH_Message,
+                                   NULL,
+                                   (void *)&dl_dcch_msg,
+                                   buffer,
+                                   RRC_BUF_SIZE);
+
+  if(enc_rval.encoded == -1) {
+    LOG_I(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n",
+          enc_rval.failed_type->name, enc_rval.encoded);
+    return -1;
+  }
+
+  if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
+    xer_fprint(stdout,&asn_DEF_LTE_DL_DCCH_Message,(void *)&dl_dcch_msg);
+  }
+
   LOG_I(RRC,"RRCConnectionReconfiguration Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
   // for (i=0;i<30;i++)
   //    msg("%x.",buffer[i]);
   // msg("\n");
-
-
   return((enc_rval.encoded+7)/8);
 }
 
 //------------------------------------------------------------------------------
 uint8_t
 do_RRCConnectionReestablishment(
-  const protocol_ctxt_t*     const ctxt_pP,
-  rrc_eNB_ue_context_t*      const ue_context_pP,
+  const protocol_ctxt_t     *const ctxt_pP,
+  rrc_eNB_ue_context_t      *const ue_context_pP,
   int                              CC_id,
-  uint8_t*                   const buffer,
+  uint8_t                   *const buffer,
   const uint8_t                    transmission_mode,
   const uint8_t                    Transaction_id,
-  SRB_ToAddModList_t               **SRB_configList,
-  struct PhysicalConfigDedicated   **physicalConfigDedicated)
-{
+  LTE_SRB_ToAddModList_t               **SRB_configList,
+  struct LTE_PhysicalConfigDedicated   **physicalConfigDedicated) {
   asn_enc_rval_t enc_rval;
-
-  long* logicalchannelgroup = NULL;
-  struct SRB_ToAddMod* SRB1_config = NULL;
-  struct SRB_ToAddMod* SRB2_config = NULL;
-  struct SRB_ToAddMod__rlc_Config* SRB1_rlc_config = NULL;
-  struct SRB_ToAddMod__logicalChannelConfig* SRB1_lchan_config = NULL;
-  struct LogicalChannelConfig__ul_SpecificParameters* SRB1_ul_SpecificParameters = NULL;
+  long *logicalchannelgroup = NULL;
+  struct LTE_SRB_ToAddMod *SRB1_config = NULL;
+  struct LTE_SRB_ToAddMod *SRB2_config = NULL;
+  struct LTE_SRB_ToAddMod__rlc_Config *SRB1_rlc_config = NULL;
+  struct LTE_SRB_ToAddMod__logicalChannelConfig *SRB1_lchan_config = NULL;
+  struct LTE_LogicalChannelConfig__ul_SpecificParameters *SRB1_ul_SpecificParameters = NULL;
   eNB_RRC_INST *rrc               = RC.rrc[ctxt_pP->module_id];
-
 #ifdef CBA
-  struct PUSCH_CBAConfigDedicated_vlola* pusch_CBAConfigDedicated_vlola = NULL;
-  long* betaOffset_CBA_Index = NULL;
-  long* cShift_CBA = NULL;
+  struct LTE_PUSCH_CBAConfigDedicated_vlola *pusch_CBAConfigDedicated_vlola = NULL;
+  long *betaOffset_CBA_Index = NULL;
+  long *cShift_CBA = NULL;
 #endif
-  PhysicalConfigDedicated_t* physicalConfigDedicated2 = NULL;
-
-  DL_CCCH_Message_t dl_ccch_msg;
-
-  RRCConnectionReestablishment_t* rrcConnectionReestablishment = NULL;
-
+  LTE_PhysicalConfigDedicated_t *physicalConfigDedicated2 = NULL;
+  LTE_DL_CCCH_Message_t dl_ccch_msg;
+  LTE_RRCConnectionReestablishment_t *rrcConnectionReestablishment = NULL;
   int i = 0;
-  SRB_ToAddModList_t **SRB_configList2 = NULL;
+  LTE_SRB_ToAddModList_t **SRB_configList2 = NULL;
   SRB_configList2 = &ue_context_pP->ue_context.SRB_configList2[Transaction_id];
+
   if (*SRB_configList2) {
     free(*SRB_configList2);
   }
-  *SRB_configList2 = CALLOC(1, sizeof(SRB_ToAddModList_t));
 
-  memset((void *)&dl_ccch_msg, 0, sizeof(DL_CCCH_Message_t));
-  dl_ccch_msg.message.present           = DL_CCCH_MessageType_PR_c1;
-  dl_ccch_msg.message.choice.c1.present = DL_CCCH_MessageType__c1_PR_rrcConnectionReestablishment;
+  *SRB_configList2 = CALLOC(1, sizeof(LTE_SRB_ToAddModList_t));
+  memset((void *)&dl_ccch_msg, 0, sizeof(LTE_DL_CCCH_Message_t));
+  dl_ccch_msg.message.present           = LTE_DL_CCCH_MessageType_PR_c1;
+  dl_ccch_msg.message.choice.c1.present = LTE_DL_CCCH_MessageType__c1_PR_rrcConnectionReestablishment;
   rrcConnectionReestablishment          = &dl_ccch_msg.message.choice.c1.choice.rrcConnectionReestablishment;
 
   // RRCConnectionReestablishment
   // Configure SRB1
 
-
   // get old configuration of SRB2
   if (*SRB_configList != NULL) {
     for (i = 0; (i < (*SRB_configList)->list.count) && (i < 3); i++) {
       LOG_D(RRC, "(*SRB_configList)->list.array[%d]->srb_Identity=%ld\n",
-          i, (*SRB_configList)->list.array[i]->srb_Identity);
-      if ((*SRB_configList)->list.array[i]->srb_Identity == 2 ){
+            i, (*SRB_configList)->list.array[i]->srb_Identity);
+
+      if ((*SRB_configList)->list.array[i]->srb_Identity == 2 ) {
         SRB2_config = (*SRB_configList)->list.array[i];
-      } else if ((*SRB_configList)->list.array[i]->srb_Identity == 1 ){
+      } else if ((*SRB_configList)->list.array[i]->srb_Identity == 1 ) {
         SRB1_config = (*SRB_configList)->list.array[i];
       }
     }
@@ -2642,44 +3651,36 @@ do_RRCConnectionReestablishment(
     LOG_W(RRC,"SRB1 configuration does not exist in SRB configuration list, use default\n");
     /// SRB1
     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 = SRB_ToAddMod__rlc_Config_PR_explicitValue;
-    SRB1_rlc_config->choice.explicitValue.present=RLC_Config_PR_am;
-  #if defined(ENABLE_ITTI)
+    SRB1_rlc_config->present = LTE_SRB_ToAddMod__rlc_Config_PR_explicitValue;
+    SRB1_rlc_config->choice.explicitValue.present=LTE_RLC_Config_PR_am;
+#if defined(ENABLE_ITTI)
     SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = rrc->srb1_timer_poll_retransmit;
     SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU          = rrc->srb1_poll_pdu;
     SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte         = rrc->srb1_poll_byte;
     SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = rrc->srb1_max_retx_threshold;
     SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering     = rrc->srb1_timer_reordering;
     SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = rrc->srb1_timer_status_prohibit;
-  #else
-    SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = T_PollRetransmit_ms20;;
-    SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU          = PollPDU_p4;;
-    SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte         = PollByte_kBinfinity;
-    SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = UL_AM_RLC__maxRetxThreshold_t8;
-    SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering     = T_Reordering_ms35;
-    SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = T_StatusProhibit_ms0;
-  #endif
-
+#else
+    SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = LTE_T_PollRetransmit_ms20;;
+    SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU          = LTE_PollPDU_p4;;
+    SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte         = LTE_PollByte_kBinfinity;
+    SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = LTE_UL_AM_RLC__maxRetxThreshold_t8;
+    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_ms0;
+#endif
     SRB1_lchan_config = CALLOC(1, sizeof(*SRB1_lchan_config));
     SRB1_config->logicalChannelConfig = SRB1_lchan_config;
-
-    SRB1_lchan_config->present = SRB_ToAddMod__logicalChannelConfig_PR_explicitValue;
+    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=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=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;
@@ -2695,42 +3696,40 @@ do_RRCConnectionReestablishment(
     free(*SRB_configList);
   }
 
-  *SRB_configList = CALLOC(1, sizeof(SRB_ToAddModList_t));
-
+  *SRB_configList = CALLOC(1, sizeof(LTE_SRB_ToAddModList_t));
   ASN_SEQUENCE_ADD(&(*SRB_configList)->list,SRB1_config);
-
   physicalConfigDedicated2 = *physicalConfigDedicated;
-
   rrcConnectionReestablishment->rrc_TransactionIdentifier = Transaction_id;
-  rrcConnectionReestablishment->criticalExtensions.present = RRCConnectionReestablishment__criticalExtensions_PR_c1;
-  rrcConnectionReestablishment->criticalExtensions.choice.c1.present = RRCConnectionReestablishment__criticalExtensions__c1_PR_rrcConnectionReestablishment_r8;
+  rrcConnectionReestablishment->criticalExtensions.present = LTE_RRCConnectionReestablishment__criticalExtensions_PR_c1;
+  rrcConnectionReestablishment->criticalExtensions.choice.c1.present = LTE_RRCConnectionReestablishment__criticalExtensions__c1_PR_rrcConnectionReestablishment_r8;
   rrcConnectionReestablishment->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r8.radioResourceConfigDedicated.srb_ToAddModList = *SRB_configList;
   rrcConnectionReestablishment->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r8.radioResourceConfigDedicated.drb_ToAddModList = NULL;
   rrcConnectionReestablishment->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r8.radioResourceConfigDedicated.drb_ToReleaseList = NULL;
   rrcConnectionReestablishment->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r8.radioResourceConfigDedicated.sps_Config = NULL;
   rrcConnectionReestablishment->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r8.radioResourceConfigDedicated.physicalConfigDedicated = physicalConfigDedicated2;
   rrcConnectionReestablishment->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r8.radioResourceConfigDedicated.mac_MainConfig = NULL;
-
   uint8_t KeNB_star[32] = { 0 };
   uint16_t pci = rrc->carrier[CC_id].physCellId;
   uint32_t earfcn_dl = (uint32_t)freq_to_arfcn10(RC.mac[ctxt_pP->module_id]->common_channels[CC_id].eutra_band,
-                  rrc->carrier[CC_id].dl_CarrierFreq);
+                       rrc->carrier[CC_id].dl_CarrierFreq);
   bool     is_rel8_only = true;
+
   if (earfcn_dl > 65535) {
     is_rel8_only = false;
   }
 
   LOG_D(RRC, "pci=%d, eutra_band=%d, downlink_frequency=%d, earfcn_dl=%u, is_rel8_only=%s\n",
-      pci,
-      RC.mac[ctxt_pP->module_id]->common_channels[CC_id].eutra_band,
-      rrc->carrier[CC_id].dl_CarrierFreq,
-      earfcn_dl,
-      is_rel8_only == true ? "true": "false");
+        pci,
+        RC.mac[ctxt_pP->module_id]->common_channels[CC_id].eutra_band,
+        rrc->carrier[CC_id].dl_CarrierFreq,
+        earfcn_dl,
+        is_rel8_only == true ? "true": "false");
 #if defined(ENABLE_SECURITY)
+
   if (ue_context_pP->ue_context.nh_ncc >= 0) {
     derive_keNB_star(ue_context_pP->ue_context.nh, pci, earfcn_dl, is_rel8_only, KeNB_star);
     rrcConnectionReestablishment->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r8.nextHopChainingCount = ue_context_pP->ue_context.nh_ncc;
-  } else { // first HO 
+  } else { // first HO
     derive_keNB_star (ue_context_pP->ue_context.kenb, pci, earfcn_dl, is_rel8_only, KeNB_star);
     // LG: really 1
     rrcConnectionReestablishment->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r8.nextHopChainingCount = 0;
@@ -2742,300 +3741,211 @@ do_RRCConnectionReestablishment(
 #else
   rrcConnectionReestablishment->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r8.nextHopChainingCount = 0;
 #endif
-
   rrcConnectionReestablishment->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r8.nonCriticalExtension = NULL;
 
-  if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-     xer_fprint(stdout, &asn_DEF_DL_CCCH_Message, (void*)&dl_ccch_msg);
-  }
-  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_CCCH_Message,
-                                   NULL,
-                                   (void*)&dl_ccch_msg,
-                                   buffer,
-                                   100);
-  if(enc_rval.encoded == -1)
-  {
-     LOG_I(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n",
-           enc_rval.failed_type->name, enc_rval.encoded);
-     return -1;
-  }
-#if defined(ENABLE_ITTI)
-# if !defined(DISABLE_XER_SPRINT)
-  {
-    char        message_string[20000];
-    size_t      message_string_size;
-
-    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_CCCH_Message, (void *) &dl_ccch_msg)) > 0) {
-      MessageDef *msg_p;
-
-      msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_CCCH, message_string_size + sizeof (IttiMsgText));
-      msg_p->ittiMsg.rrc_dl_ccch.size = message_string_size;
-      memcpy(&msg_p->ittiMsg.rrc_dl_ccch.text, message_string, message_string_size);
-
-      itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
-    }
+  if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
+    xer_fprint(stdout, &asn_DEF_LTE_DL_CCCH_Message, (void *)&dl_ccch_msg);
   }
-# endif
-#endif
 
-#ifdef USER_MODE
-  LOG_D(RRC,"RRCConnectionReestablishment Encoded %zd bits (%zd bytes)\n",
-        enc_rval.encoded,(enc_rval.encoded+7)/8);
-#endif
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_DL_CCCH_Message,
+                                   NULL,
+                                   (void *)&dl_ccch_msg,
+                                   buffer,
+                                   100);
+
+  if(enc_rval.encoded == -1) {
+    LOG_E(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n",
+          enc_rval.failed_type->name, enc_rval.encoded);
+    return -1;
+  }
 
+  LOG_D(RRC,"RRCConnectionReestablishment Encoded %u bits (%u bytes)\n",
+        (uint32_t)enc_rval.encoded, (uint32_t)(enc_rval.encoded+7)/8);
   return((enc_rval.encoded+7)/8);
 }
 
 //------------------------------------------------------------------------------
-uint8_t
-do_RRCConnectionReestablishmentReject(
-  uint8_t                    Mod_id,
-  uint8_t*                   const buffer)
+uint8_t do_RRCConnectionReestablishmentReject(uint8_t                    Mod_id,
+					      uint8_t                   *const buffer)
 //------------------------------------------------------------------------------
 {
-
   asn_enc_rval_t enc_rval;
-
-  DL_CCCH_Message_t dl_ccch_msg;
-  RRCConnectionReestablishmentReject_t *rrcConnectionReestablishmentReject;
-
-  memset((void *)&dl_ccch_msg,0,sizeof(DL_CCCH_Message_t));
-  dl_ccch_msg.message.present           = DL_CCCH_MessageType_PR_c1;
-  dl_ccch_msg.message.choice.c1.present = DL_CCCH_MessageType__c1_PR_rrcConnectionReestablishmentReject;
+  LTE_DL_CCCH_Message_t dl_ccch_msg;
+  LTE_RRCConnectionReestablishmentReject_t *rrcConnectionReestablishmentReject;
+  memset((void *)&dl_ccch_msg,0,sizeof(LTE_DL_CCCH_Message_t));
+  dl_ccch_msg.message.present           = LTE_DL_CCCH_MessageType_PR_c1;
+  dl_ccch_msg.message.choice.c1.present = LTE_DL_CCCH_MessageType__c1_PR_rrcConnectionReestablishmentReject;
   rrcConnectionReestablishmentReject    = &dl_ccch_msg.message.choice.c1.choice.rrcConnectionReestablishmentReject;
-
   // RRCConnectionReestablishmentReject
-  rrcConnectionReestablishmentReject->criticalExtensions.present = RRCConnectionReestablishmentReject__criticalExtensions_PR_rrcConnectionReestablishmentReject_r8;
+  rrcConnectionReestablishmentReject->criticalExtensions.present = LTE_RRCConnectionReestablishmentReject__criticalExtensions_PR_rrcConnectionReestablishmentReject_r8;
 
   if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-     xer_fprint(stdout, &asn_DEF_DL_CCCH_Message, (void*)&dl_ccch_msg);
+    xer_fprint(stdout, &asn_DEF_LTE_DL_CCCH_Message, (void *)&dl_ccch_msg);
   }
-  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_CCCH_Message,
+
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_DL_CCCH_Message,
                                    NULL,
-                                   (void*)&dl_ccch_msg,
+                                   (void *)&dl_ccch_msg,
                                    buffer,
                                    100);
-  if(enc_rval.encoded == -1)
-  {
-     LOG_I(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n",
-           enc_rval.failed_type->name, enc_rval.encoded);
-     return -1;
-  }
-#if defined(ENABLE_ITTI)
-# if !defined(DISABLE_XER_SPRINT)
-  {
-    char        message_string[20000];
-    size_t      message_string_size;
 
-    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_CCCH_Message, (void *) &dl_ccch_msg)) > 0) {
-      MessageDef *msg_p;
-
-      msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_CCCH, message_string_size + sizeof (IttiMsgText));
-      msg_p->ittiMsg.rrc_dl_ccch.size = message_string_size;
-      memcpy(&msg_p->ittiMsg.rrc_dl_ccch.text, message_string, message_string_size);
-
-      itti_send_msg_to_task(TASK_UNKNOWN, Mod_id, msg_p);
-    }
+  if(enc_rval.encoded == -1) {
+    LOG_E(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n",
+          enc_rval.failed_type->name, enc_rval.encoded);
+    return -1;
   }
-# endif
-#endif
 
   LOG_D(RRC,"RRCConnectionReestablishmentReject Encoded %zd bits (%zd bytes)\n",
         enc_rval.encoded,(enc_rval.encoded+7)/8);
-
   return((enc_rval.encoded+7)/8);
 }
 
 //------------------------------------------------------------------------------
-uint8_t
-do_RRCConnectionReject(
-  uint8_t                    Mod_id,
-  uint8_t*                   const buffer)
+uint8_t do_RRCConnectionReject(uint8_t                    Mod_id,
+			       uint8_t                   *const buffer)
 //------------------------------------------------------------------------------
 {
-
   asn_enc_rval_t enc_rval;
-
-  DL_CCCH_Message_t dl_ccch_msg;
-  RRCConnectionReject_t *rrcConnectionReject;
-
-  memset((void *)&dl_ccch_msg,0,sizeof(DL_CCCH_Message_t));
-  dl_ccch_msg.message.present           = DL_CCCH_MessageType_PR_c1;
-  dl_ccch_msg.message.choice.c1.present = DL_CCCH_MessageType__c1_PR_rrcConnectionReject;
+  LTE_DL_CCCH_Message_t dl_ccch_msg;
+  LTE_RRCConnectionReject_t *rrcConnectionReject;
+  memset((void *)&dl_ccch_msg,0,sizeof(LTE_DL_CCCH_Message_t));
+  dl_ccch_msg.message.present           = LTE_DL_CCCH_MessageType_PR_c1;
+  dl_ccch_msg.message.choice.c1.present = LTE_DL_CCCH_MessageType__c1_PR_rrcConnectionReject;
   rrcConnectionReject                   = &dl_ccch_msg.message.choice.c1.choice.rrcConnectionReject;
-
   // RRCConnectionReject
-  rrcConnectionReject->criticalExtensions.present = RRCConnectionReject__criticalExtensions_PR_c1;
-  rrcConnectionReject->criticalExtensions.choice.c1.present = RRCConnectionReject__criticalExtensions__c1_PR_rrcConnectionReject_r8;
+  rrcConnectionReject->criticalExtensions.present = LTE_RRCConnectionReject__criticalExtensions_PR_c1;
+  rrcConnectionReject->criticalExtensions.choice.c1.present = LTE_RRCConnectionReject__criticalExtensions__c1_PR_rrcConnectionReject_r8;
   /* let's put a wait time of 1s for the moment */
   rrcConnectionReject->criticalExtensions.choice.c1.choice.rrcConnectionReject_r8.waitTime = 1;
 
   if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-     xer_fprint(stdout, &asn_DEF_DL_CCCH_Message, (void*)&dl_ccch_msg);
+    xer_fprint(stdout, &asn_DEF_LTE_DL_CCCH_Message, (void *)&dl_ccch_msg);
   }
-  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_CCCH_Message,
+
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_DL_CCCH_Message,
                                    NULL,
-                                   (void*)&dl_ccch_msg,
+                                   (void *)&dl_ccch_msg,
                                    buffer,
                                    100);
-  if(enc_rval.encoded == -1)
-  {
-     LOG_I(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n",
-           enc_rval.failed_type->name, enc_rval.encoded);
-     return -1;
-  }
-#if defined(ENABLE_ITTI)
-# if !defined(DISABLE_XER_SPRINT)
-  {
-    char        message_string[20000];
-    size_t      message_string_size;
-
-    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_CCCH_Message, (void *) &dl_ccch_msg)) > 0) {
-      MessageDef *msg_p;
-
-      msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_CCCH, message_string_size + sizeof (IttiMsgText));
-      msg_p->ittiMsg.rrc_dl_ccch.size = message_string_size;
-      memcpy(&msg_p->ittiMsg.rrc_dl_ccch.text, message_string, message_string_size);
 
-      itti_send_msg_to_task(TASK_UNKNOWN, Mod_id, msg_p);
-    }
+  if(enc_rval.encoded == -1) {
+    LOG_E(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n",
+          enc_rval.failed_type->name, enc_rval.encoded);
+    return -1;
   }
-# endif
-#endif
 
   LOG_D(RRC,"RRCConnectionReject Encoded %zd bits (%zd bytes)\n",
         enc_rval.encoded,(enc_rval.encoded+7)/8);
-
   return((enc_rval.encoded+7)/8);
 }
 
-uint8_t do_RRCConnectionRelease(
-  uint8_t                             Mod_id,
-  uint8_t                            *buffer,
-  uint8_t                             Transaction_id)
+uint8_t do_RRCConnectionRelease(uint8_t                             Mod_id,
+				uint8_t                            *buffer,
+				uint8_t                             Transaction_id)
 {
-
   asn_enc_rval_t enc_rval;
-
-  DL_DCCH_Message_t dl_dcch_msg;
-  RRCConnectionRelease_t *rrcConnectionRelease;
-
-
-  memset(&dl_dcch_msg,0,sizeof(DL_DCCH_Message_t));
-
-  dl_dcch_msg.message.present           = DL_DCCH_MessageType_PR_c1;
-  dl_dcch_msg.message.choice.c1.present = DL_DCCH_MessageType__c1_PR_rrcConnectionRelease;
+  LTE_DL_DCCH_Message_t dl_dcch_msg;
+  LTE_RRCConnectionRelease_t *rrcConnectionRelease;
+  memset(&dl_dcch_msg,0,sizeof(LTE_DL_DCCH_Message_t));
+  dl_dcch_msg.message.present           = LTE_DL_DCCH_MessageType_PR_c1;
+  dl_dcch_msg.message.choice.c1.present = LTE_DL_DCCH_MessageType__c1_PR_rrcConnectionRelease;
   rrcConnectionRelease                  = &dl_dcch_msg.message.choice.c1.choice.rrcConnectionRelease;
-
   // RRCConnectionRelease
   rrcConnectionRelease->rrc_TransactionIdentifier = Transaction_id;
-  rrcConnectionRelease->criticalExtensions.present = RRCConnectionRelease__criticalExtensions_PR_c1;
-  rrcConnectionRelease->criticalExtensions.choice.c1.present =RRCConnectionRelease__criticalExtensions__c1_PR_rrcConnectionRelease_r8 ;
-
-  rrcConnectionRelease->criticalExtensions.choice.c1.choice.rrcConnectionRelease_r8.releaseCause = ReleaseCause_other;
+  rrcConnectionRelease->criticalExtensions.present = LTE_RRCConnectionRelease__criticalExtensions_PR_c1;
+  rrcConnectionRelease->criticalExtensions.choice.c1.present =LTE_RRCConnectionRelease__criticalExtensions__c1_PR_rrcConnectionRelease_r8 ;
+  rrcConnectionRelease->criticalExtensions.choice.c1.choice.rrcConnectionRelease_r8.releaseCause = LTE_ReleaseCause_other;
   rrcConnectionRelease->criticalExtensions.choice.c1.choice.rrcConnectionRelease_r8.redirectedCarrierInfo = NULL;
   rrcConnectionRelease->criticalExtensions.choice.c1.choice.rrcConnectionRelease_r8.idleModeMobilityControlInfo = NULL;
-
   rrcConnectionRelease->criticalExtensions.choice.c1.choice.rrcConnectionRelease_r8.nonCriticalExtension=CALLOC(1,
       sizeof(*rrcConnectionRelease->criticalExtensions.choice.c1.choice.rrcConnectionRelease_r8.nonCriticalExtension));
 
-  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_DCCH_Message,
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_DL_DCCH_Message,
                                    NULL,
-                                   (void*)&dl_dcch_msg,
+                                   (void *)&dl_dcch_msg,
                                    buffer,
                                    RRC_BUF_SIZE);
-
   return((enc_rval.encoded+7)/8);
 }
 
 uint8_t TMGI[5] = {4,3,2,1,0};//TMGI is a string of octet, ref. TS 24.008 fig. 10.5.4a
 
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 uint8_t do_MBSFNAreaConfig(uint8_t Mod_id,
                            uint8_t sync_area,
                            uint8_t *buffer,
-                           MCCH_Message_t *mcch_message,
-                           MBSFNAreaConfiguration_r9_t **mbsfnAreaConfiguration)
-{
-
+                           LTE_MCCH_Message_t *mcch_message,
+                           LTE_MBSFNAreaConfiguration_r9_t **mbsfnAreaConfiguration) {
   asn_enc_rval_t enc_rval;
-  MBSFN_SubframeConfig_t *mbsfn_SubframeConfig1;
-  PMCH_Info_r9_t *pmch_Info_1;
-  MBMS_SessionInfo_r9_t *mbms_Session_1;
+  LTE_MBSFN_SubframeConfig_t *mbsfn_SubframeConfig1;
+  LTE_PMCH_Info_r9_t *pmch_Info_1;
+  LTE_MBMS_SessionInfo_r9_t *mbms_Session_1;
   // MBMS_SessionInfo_r9_t *mbms_Session_2;
   eNB_RRC_INST *rrc               = RC.rrc[Mod_id];
   rrc_eNB_carrier_data_t *carrier = &rrc->carrier[0];
- 
-
-  memset(mcch_message,0,sizeof(MCCH_Message_t));
-  mcch_message->message.present = MCCH_MessageType_PR_c1;
-  mcch_message->message.choice.c1.present = MCCH_MessageType__c1_PR_mbsfnAreaConfiguration_r9;
+  memset(mcch_message,0,sizeof(LTE_MCCH_Message_t));
+  mcch_message->message.present = LTE_MCCH_MessageType_PR_c1;
+  mcch_message->message.choice.c1.present = LTE_MCCH_MessageType__c1_PR_mbsfnAreaConfiguration_r9;
   *mbsfnAreaConfiguration = &mcch_message->message.choice.c1.choice.mbsfnAreaConfiguration_r9;
-
   // Common Subframe Allocation (CommonSF-Alloc-r9)
-
   mbsfn_SubframeConfig1= CALLOC(1,sizeof(*mbsfn_SubframeConfig1));
-  memset((void*)mbsfn_SubframeConfig1,0,sizeof(*mbsfn_SubframeConfig1));
+  memset((void *)mbsfn_SubframeConfig1,0,sizeof(*mbsfn_SubframeConfig1));
   //
-  mbsfn_SubframeConfig1->radioframeAllocationPeriod= MBSFN_SubframeConfig__radioframeAllocationPeriod_n4;
+  mbsfn_SubframeConfig1->radioframeAllocationPeriod= LTE_MBSFN_SubframeConfig__radioframeAllocationPeriod_n4;
   mbsfn_SubframeConfig1->radioframeAllocationOffset= 1;
-  mbsfn_SubframeConfig1->subframeAllocation.present= MBSFN_SubframeConfig__subframeAllocation_PR_oneFrame;
+  mbsfn_SubframeConfig1->subframeAllocation.present= LTE_MBSFN_SubframeConfig__subframeAllocation_PR_oneFrame;
   mbsfn_SubframeConfig1->subframeAllocation.choice.oneFrame.buf= MALLOC(1);
   mbsfn_SubframeConfig1->subframeAllocation.choice.oneFrame.size= 1;
   mbsfn_SubframeConfig1->subframeAllocation.choice.oneFrame.bits_unused= 2;
 
   // CURRENTLY WE ARE SUPPORITNG ONLY ONE sf ALLOCATION
   switch (sync_area) {
-  case 0:
-    if (carrier->sib1->tdd_Config != NULL) {// pattern 001110 for TDD
-      mbsfn_SubframeConfig1->subframeAllocation.choice.oneFrame.buf[0]=0x08<<2;// shift 2bits cuz 2last bits are unused.
-    } else { //111000
-      mbsfn_SubframeConfig1->subframeAllocation.choice.oneFrame.buf[0]=0x38<<2;
-    }
+    case 0:
+      if (carrier->sib1->tdd_Config != NULL) {// pattern 001110 for TDD
+        mbsfn_SubframeConfig1->subframeAllocation.choice.oneFrame.buf[0]=0x08<<2;// shift 2bits cuz 2last bits are unused.
+      } else { //111000
+        mbsfn_SubframeConfig1->subframeAllocation.choice.oneFrame.buf[0]=0x38<<2;
+      }
 
-    break;
+      break;
 
-  case 1:
-    if (carrier->sib1->tdd_Config != NULL) {
-      mbsfn_SubframeConfig1->subframeAllocation.choice.oneFrame.buf[0]=0x08<<2;// shift 2bits cuz 2last bits are unused.
-    } else { // 000111
-      mbsfn_SubframeConfig1->subframeAllocation.choice.oneFrame.buf[0]=0x07<<2;
-    }
+    case 1:
+      if (carrier->sib1->tdd_Config != NULL) {
+        mbsfn_SubframeConfig1->subframeAllocation.choice.oneFrame.buf[0]=0x08<<2;// shift 2bits cuz 2last bits are unused.
+      } else { // 000111
+        mbsfn_SubframeConfig1->subframeAllocation.choice.oneFrame.buf[0]=0x07<<2;
+      }
 
-  default :
-    break;
+    default :
+      break;
   }
 
   ASN_SEQUENCE_ADD(&(*mbsfnAreaConfiguration)->commonSF_Alloc_r9.list,mbsfn_SubframeConfig1);
-
   //  commonSF-AllocPeriod-r9
-  (*mbsfnAreaConfiguration)->commonSF_AllocPeriod_r9= MBSFNAreaConfiguration_r9__commonSF_AllocPeriod_r9_rf16;
-
+  (*mbsfnAreaConfiguration)->commonSF_AllocPeriod_r9= LTE_MBSFNAreaConfiguration_r9__commonSF_AllocPeriod_r9_rf16;
   // PMCHs Information List (PMCH-InfoList-r9)
   // PMCH_1  Config
-  pmch_Info_1 = CALLOC(1,sizeof(PMCH_Info_r9_t));
-  memset((void*)pmch_Info_1,0,sizeof(PMCH_Info_r9_t));
-
+  pmch_Info_1 = CALLOC(1,sizeof(LTE_PMCH_Info_r9_t));
+  memset((void *)pmch_Info_1,0,sizeof(LTE_PMCH_Info_r9_t));
   /*
    * take the value of last mbsfn subframe in this CSA period because there is only one PMCH in this mbsfn area
    * Note: this has to be set based on the subframeAllocation and CSA
    */
   pmch_Info_1->pmch_Config_r9.sf_AllocEnd_r9= 3;
   pmch_Info_1->pmch_Config_r9.dataMCS_r9= 7;
-  pmch_Info_1->pmch_Config_r9.mch_SchedulingPeriod_r9= PMCH_Config_r9__mch_SchedulingPeriod_r9_rf16;
-
+  pmch_Info_1->pmch_Config_r9.mch_SchedulingPeriod_r9= LTE_PMCH_Config_r9__mch_SchedulingPeriod_r9_rf16;
   // MBMSs-SessionInfoList-r9
   //  pmch_Info_1->mbms_SessionInfoList_r9 = CALLOC(1,sizeof(struct MBMS_SessionInfoList_r9));
   //  Session 1
-  mbms_Session_1 = CALLOC(1,sizeof(MBMS_SessionInfo_r9_t));
-  memset(mbms_Session_1,0,sizeof(MBMS_SessionInfo_r9_t));
+  mbms_Session_1 = CALLOC(1,sizeof(LTE_MBMS_SessionInfo_r9_t));
+  memset(mbms_Session_1,0,sizeof(LTE_MBMS_SessionInfo_r9_t));
   // TMGI value
-  mbms_Session_1->tmgi_r9.plmn_Id_r9.present= TMGI_r9__plmn_Id_r9_PR_plmn_Index_r9;
+  mbms_Session_1->tmgi_r9.plmn_Id_r9.present= LTE_TMGI_r9__plmn_Id_r9_PR_plmn_Index_r9;
   mbms_Session_1->tmgi_r9.plmn_Id_r9.choice.plmn_Index_r9= 1;
   // Service ID
   memset(&mbms_Session_1->tmgi_r9.serviceId_r9,0,sizeof(OCTET_STRING_t));// need to check
-  OCTET_STRING_fromBuf(&mbms_Session_1->tmgi_r9.serviceId_r9,(const char*)&TMGI[2],3);
+  OCTET_STRING_fromBuf(&mbms_Session_1->tmgi_r9.serviceId_r9,(const char *)&TMGI[2],3);
   // Session ID is still missing here, it can be used as an rab id or mrb id
   mbms_Session_1->sessionId_r9 = CALLOC(1,sizeof(OCTET_STRING_t));
   mbms_Session_1->sessionId_r9->buf= MALLOC(1);
@@ -3044,7 +3954,6 @@ uint8_t do_MBSFNAreaConfig(uint8_t Mod_id,
   // Logical Channel ID
   mbms_Session_1->logicalChannelIdentity_r9= MTCH;
   ASN_SEQUENCE_ADD(&pmch_Info_1->mbms_SessionInfoList_r9.list,mbms_Session_1);
-
   /*    //  Session 2
   //mbms_Session_2 = CALLOC(1,sizeof(MBMS_SessionInfo_r9_t));
   memset(mbms_Session_2,0,sizeof(MBMS_SessionInfo_r9_t));
@@ -3065,37 +3974,20 @@ uint8_t do_MBSFNAreaConfig(uint8_t Mod_id,
   ASN_SEQUENCE_ADD(&(*mbsfnAreaConfiguration)->pmch_InfoList_r9.list,pmch_Info_1);
 
   if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-     xer_fprint(stdout,&asn_DEF_MCCH_Message,(void*)mcch_message);
+    xer_fprint(stdout,&asn_DEF_LTE_MCCH_Message,(void *)mcch_message);
   }
-  enc_rval = uper_encode_to_buffer(&asn_DEF_MCCH_Message,
+
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_MCCH_Message,
                                    NULL,
-                                   (void*)mcch_message,
+                                   (void *)mcch_message,
                                    buffer,
                                    100);
-  if(enc_rval.encoded == -1)
-  {
-     LOG_I(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n",
-           enc_rval.failed_type->name, enc_rval.encoded);
-     return -1;
-  }
-#if defined(ENABLE_ITTI)
-# if !defined(DISABLE_XER_SPRINT)
-  {
-    char        message_string[20000];
-    size_t      message_string_size;
-
-    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_MCCH_Message, (void *) &mcch_message)) > 0) {
-      MessageDef *msg_p;
 
-      msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_MCCH, message_string_size);
-      msg_p->ittiMsg.rrc_dl_mcch.size = message_string_size;
-      memcpy(&msg_p->ittiMsg.rrc_dl_mcch.text, message_string, message_string_size);
-
-      itti_send_msg_to_task(TASK_UNKNOWN, Mod_id, msg_p);
-    }
+  if(enc_rval.encoded == -1) {
+    LOG_I(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n",
+          enc_rval.failed_type->name, enc_rval.encoded);
+    return -1;
   }
-# endif
-#endif
 
   LOG_D(RRC,"[eNB] MCCH Message Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
 
@@ -3108,26 +4000,20 @@ uint8_t do_MBSFNAreaConfig(uint8_t Mod_id,
 }
 #endif
 
-uint8_t do_MeasurementReport(uint8_t Mod_id, uint8_t *buffer,int measid,int phy_id,long rsrp_s,long rsrq_s,long rsrp_t,long rsrq_t)
-{
-
+uint8_t do_MeasurementReport(uint8_t Mod_id, uint8_t *buffer,int measid,int phy_id,long rsrp_s,long rsrq_s,long rsrp_t,long rsrq_t) {
   asn_enc_rval_t enc_rval;
-
-  UL_DCCH_Message_t ul_dcch_msg;
-
-  MeasurementReport_t  *measurementReport;
-
-  ul_dcch_msg.message.present                     = UL_DCCH_MessageType_PR_c1;
-  ul_dcch_msg.message.choice.c1.present           = UL_DCCH_MessageType__c1_PR_measurementReport;
+  LTE_UL_DCCH_Message_t ul_dcch_msg;
+  LTE_MeasurementReport_t  *measurementReport;
+  ul_dcch_msg.message.present                     = LTE_UL_DCCH_MessageType_PR_c1;
+  ul_dcch_msg.message.choice.c1.present           = LTE_UL_DCCH_MessageType__c1_PR_measurementReport;
   measurementReport            = &ul_dcch_msg.message.choice.c1.choice.measurementReport;
-
-  measurementReport->criticalExtensions.present=MeasurementReport__criticalExtensions_PR_c1;
-  measurementReport->criticalExtensions.choice.c1.present=MeasurementReport__criticalExtensions__c1_PR_measurementReport_r8;
+  measurementReport->criticalExtensions.present=LTE_MeasurementReport__criticalExtensions_PR_c1;
+  measurementReport->criticalExtensions.choice.c1.present=LTE_MeasurementReport__criticalExtensions__c1_PR_measurementReport_r8;
   measurementReport->criticalExtensions.choice.c1.choice.measurementReport_r8.nonCriticalExtension=CALLOC(1,
       sizeof(*measurementReport->criticalExtensions.choice.c1.choice.measurementReport_r8.nonCriticalExtension));
 
   measurementReport->criticalExtensions.choice.c1.choice.measurementReport_r8.measResults.measId=measid;
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
   measurementReport->criticalExtensions.choice.c1.choice.measurementReport_r8.measResults.measResultPCell.rsrpResult=rsrp_s;
   measurementReport->criticalExtensions.choice.c1.choice.measurementReport_r8.measResults.measResultPCell.rsrqResult=rsrq_s;
 #else
@@ -3136,40 +4022,31 @@ uint8_t do_MeasurementReport(uint8_t Mod_id, uint8_t *buffer,int measid,int phy_
 #endif
   measurementReport->criticalExtensions.choice.c1.choice.measurementReport_r8.measResults.measResultNeighCells=CALLOC(1,
       sizeof(*measurementReport->criticalExtensions.choice.c1.choice.measurementReport_r8.measResults.measResultNeighCells));
-  measurementReport->criticalExtensions.choice.c1.choice.measurementReport_r8.measResults.measResultNeighCells->present=MeasResults__measResultNeighCells_PR_measResultListEUTRA;
-
-  MeasResultListEUTRA_t  *measResultListEUTRA2;
+  measurementReport->criticalExtensions.choice.c1.choice.measurementReport_r8.measResults.measResultNeighCells->present=LTE_MeasResults__measResultNeighCells_PR_measResultListEUTRA;
+  LTE_MeasResultListEUTRA_t  *measResultListEUTRA2;
   measResultListEUTRA2 = CALLOC(1,sizeof(*measResultListEUTRA2));
-
-  struct MeasResultEUTRA *measresulteutra2;
+  struct LTE_MeasResultEUTRA *measresulteutra2;
   measresulteutra2 = CALLOC(1,sizeof(*measresulteutra2));
   measresulteutra2->physCellId=phy_id;//1;
-
-  struct MeasResultEUTRA__cgi_Info *measresult_cgi2;
+  struct LTE_MeasResultEUTRA__cgi_Info *measresult_cgi2;
   measresult_cgi2 = CALLOC(1,sizeof(*measresult_cgi2));
-
   memset(&measresult_cgi2->cellGlobalId.plmn_Identity,0,sizeof(measresult_cgi2->cellGlobalId.plmn_Identity));
-
   // measresult_cgi2->cellGlobalId.plmn_Identity.mcc=CALLOC(1,sizeof(measresult_cgi2->cellGlobalId.plmn_Identity.mcc));
   measresult_cgi2->cellGlobalId.plmn_Identity.mcc = CALLOC(1, sizeof(*measresult_cgi2->cellGlobalId.plmn_Identity.mcc));
-
   asn_set_empty(&measresult_cgi2->cellGlobalId.plmn_Identity.mcc->list);//.size=0;
-
-  MCC_MNC_Digit_t dummy;
+  LTE_MCC_MNC_Digit_t dummy;
   dummy=2;
   ASN_SEQUENCE_ADD(&measresult_cgi2->cellGlobalId.plmn_Identity.mcc->list,&dummy);
   dummy=6;
   ASN_SEQUENCE_ADD(&measresult_cgi2->cellGlobalId.plmn_Identity.mcc->list,&dummy);
   dummy=2;
   ASN_SEQUENCE_ADD(&measresult_cgi2->cellGlobalId.plmn_Identity.mcc->list,&dummy);
-
   measresult_cgi2->cellGlobalId.plmn_Identity.mnc.list.size=0;
   measresult_cgi2->cellGlobalId.plmn_Identity.mnc.list.count=0;
   dummy=8;
   ASN_SEQUENCE_ADD(&measresult_cgi2->cellGlobalId.plmn_Identity.mnc.list,&dummy);
   dummy=0;
   ASN_SEQUENCE_ADD(&measresult_cgi2->cellGlobalId.plmn_Identity.mnc.list,&dummy);
-
   measresult_cgi2->cellGlobalId.cellIdentity.buf=MALLOC(8);
   measresult_cgi2->cellGlobalId.cellIdentity.buf[0]=0x01;
   measresult_cgi2->cellGlobalId.cellIdentity.buf[1]=0x48;
@@ -3177,222 +4054,236 @@ uint8_t do_MeasurementReport(uint8_t Mod_id, uint8_t *buffer,int measid,int phy_
   measresult_cgi2->cellGlobalId.cellIdentity.buf[3]=0x03;
   measresult_cgi2->cellGlobalId.cellIdentity.size=4;
   measresult_cgi2->cellGlobalId.cellIdentity.bits_unused=4;
-
   measresult_cgi2->trackingAreaCode.buf = MALLOC(2);
   measresult_cgi2->trackingAreaCode.buf[0]=0x00;
   measresult_cgi2->trackingAreaCode.buf[1]=0x10;
   measresult_cgi2->trackingAreaCode.size=2;
   measresult_cgi2->trackingAreaCode.bits_unused=0;
-
-
   measresulteutra2->cgi_Info=measresult_cgi2;
-
-  struct MeasResultEUTRA__measResult meas2;
+  struct LTE_MeasResultEUTRA__measResult meas2;
   //    int rsrp_va=10;
-
   meas2.rsrpResult=&(rsrp_t);
   //&rsrp_va;
   meas2.rsrqResult=&(rsrq_t);
-
   measresulteutra2->measResult=meas2;
-
   ASN_SEQUENCE_ADD(&measResultListEUTRA2->list,measresulteutra2);
-
   measurementReport->criticalExtensions.choice.c1.choice.measurementReport_r8.measResults.measResultNeighCells->choice.measResultListEUTRA=*(measResultListEUTRA2);
 
-  enc_rval = uper_encode_to_buffer(&asn_DEF_UL_DCCH_Message,
+  if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
+    xer_fprint(stdout, &asn_DEF_LTE_UL_DCCH_Message, (void *)&ul_dcch_msg);
+  }
+
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_UL_DCCH_Message,
                                    NULL,
-                                   (void*)&ul_dcch_msg,
+                                   (void *)&ul_dcch_msg,
                                    buffer,
                                    100);
-  if(enc_rval.encoded == -1)
-  {
-     LOG_I(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n",
-           enc_rval.failed_type->name, enc_rval.encoded);
-     return -1;
-  }
-#if defined(ENABLE_ITTI)
-# if !defined(DISABLE_XER_SPRINT)
-  {
-    char        message_string[20000];
-    size_t      message_string_size;
-
-    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_UL_DCCH_Message, (void *) &ul_dcch_msg)) > 0) {
-      MessageDef *msg_p;
-
-      msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, RRC_DL_DCCH, message_string_size + sizeof (IttiMsgText));
-      msg_p->ittiMsg.rrc_dl_dcch.size = message_string_size;
-      memcpy(&msg_p->ittiMsg.rrc_dl_dcch.text, message_string, message_string_size);
 
-      itti_send_msg_to_task(TASK_UNKNOWN, NB_eNB_INST + Mod_id, msg_p);
-    }
+  if(enc_rval.encoded == -1) {
+    LOG_I(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n",
+          enc_rval.failed_type->name, enc_rval.encoded);
+    return -1;
   }
-# endif
-#endif
-
-  printf("Measurement Report Encoded %zu bits (%zu bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
 
   return((enc_rval.encoded+7)/8);
 }
 
-uint8_t do_DLInformationTransfer(uint8_t Mod_id, uint8_t **buffer, uint8_t transaction_id, uint32_t pdu_length, uint8_t *pdu_buffer)
-{
+uint8_t do_DLInformationTransfer(uint8_t Mod_id, uint8_t **buffer, uint8_t transaction_id, uint32_t pdu_length, uint8_t *pdu_buffer) {
   ssize_t encoded;
-
-  DL_DCCH_Message_t dl_dcch_msg;
-
-  memset(&dl_dcch_msg, 0, sizeof(DL_DCCH_Message_t));
-
-  dl_dcch_msg.message.present           = DL_DCCH_MessageType_PR_c1;
-  dl_dcch_msg.message.choice.c1.present = DL_DCCH_MessageType__c1_PR_dlInformationTransfer;
+  LTE_DL_DCCH_Message_t dl_dcch_msg;
+  memset(&dl_dcch_msg, 0, sizeof(LTE_DL_DCCH_Message_t));
+  dl_dcch_msg.message.present           = LTE_DL_DCCH_MessageType_PR_c1;
+  dl_dcch_msg.message.choice.c1.present = LTE_DL_DCCH_MessageType__c1_PR_dlInformationTransfer;
   dl_dcch_msg.message.choice.c1.choice.dlInformationTransfer.rrc_TransactionIdentifier = transaction_id;
-  dl_dcch_msg.message.choice.c1.choice.dlInformationTransfer.criticalExtensions.present = DLInformationTransfer__criticalExtensions_PR_c1;
-  dl_dcch_msg.message.choice.c1.choice.dlInformationTransfer.criticalExtensions.choice.c1.present = DLInformationTransfer__criticalExtensions__c1_PR_dlInformationTransfer_r8;
+  dl_dcch_msg.message.choice.c1.choice.dlInformationTransfer.criticalExtensions.present = LTE_DLInformationTransfer__criticalExtensions_PR_c1;
+  dl_dcch_msg.message.choice.c1.choice.dlInformationTransfer.criticalExtensions.choice.c1.present = LTE_DLInformationTransfer__criticalExtensions__c1_PR_dlInformationTransfer_r8;
   dl_dcch_msg.message.choice.c1.choice.dlInformationTransfer.criticalExtensions.choice.c1.choice.dlInformationTransfer_r8.dedicatedInfoType.present =
-    DLInformationTransfer_r8_IEs__dedicatedInfoType_PR_dedicatedInfoNAS;
+    LTE_DLInformationTransfer_r8_IEs__dedicatedInfoType_PR_dedicatedInfoNAS;
   dl_dcch_msg.message.choice.c1.choice.dlInformationTransfer.criticalExtensions.choice.c1.choice.dlInformationTransfer_r8.dedicatedInfoType.choice.dedicatedInfoNAS.size = pdu_length;
   dl_dcch_msg.message.choice.c1.choice.dlInformationTransfer.criticalExtensions.choice.c1.choice.dlInformationTransfer_r8.dedicatedInfoType.choice.dedicatedInfoNAS.buf = pdu_buffer;
-
-  encoded = uper_encode_to_new_buffer (&asn_DEF_DL_DCCH_Message, NULL, (void*) &dl_dcch_msg, (void **) buffer);
-
-  /*
-#if defined(ENABLE_ITTI)
-# if !defined(DISABLE_XER_SPRINT)
-  {
-    char        message_string[10000];
-    size_t      message_string_size;
-
-    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_DCCH_Message, (void *)&dl_dcch_msg)) > 0) {
-      MessageDef *msg_p;
-
-      msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_DCCH, message_string_size + sizeof (IttiMsgText));
-      msg_p->ittiMsg.rrc_dl_dcch.size = message_string_size;
-      memcpy(&msg_p->ittiMsg.rrc_dl_dcch.text, message_string, message_string_size);
-
-      itti_send_msg_to_task(TASK_UNKNOWN, Mod_id, msg_p);
-    }
-  }
-# endif
-#endif
-  */
-
+  encoded = uper_encode_to_new_buffer (&asn_DEF_LTE_DL_DCCH_Message, NULL, (void *) &dl_dcch_msg, (void **) buffer);
   return encoded;
 }
 
-uint8_t do_Paging(uint8_t Mod_id, uint8_t *buffer, ue_paging_identity_t ue_paging_identity, cn_domain_t cn_domain)
-{
+uint8_t do_Paging(uint8_t Mod_id, uint8_t *buffer, ue_paging_identity_t ue_paging_identity, cn_domain_t cn_domain) {
   LOG_D(RRC, "[eNB %d] do_Paging start\n", Mod_id);
   asn_enc_rval_t enc_rval;
-
-  PCCH_Message_t pcch_msg;
-  PagingRecord_t *paging_record_p;
+  LTE_PCCH_Message_t pcch_msg;
+  LTE_PagingRecord_t *paging_record_p;
   int j;
-
-  pcch_msg.message.present           = PCCH_MessageType_PR_c1;
-  pcch_msg.message.choice.c1.present = PCCH_MessageType__c1_PR_paging;
-
+  pcch_msg.message.present           = LTE_PCCH_MessageType_PR_c1;
+  pcch_msg.message.choice.c1.present = LTE_PCCH_MessageType__c1_PR_paging;
   pcch_msg.message.choice.c1.choice.paging.pagingRecordList = CALLOC(1,sizeof(*pcch_msg.message.choice.c1.choice.paging.pagingRecordList));
-
   pcch_msg.message.choice.c1.choice.paging.systemInfoModification = NULL;
   pcch_msg.message.choice.c1.choice.paging.etws_Indication = NULL;
   pcch_msg.message.choice.c1.choice.paging.nonCriticalExtension = NULL;
-
   asn_set_empty(&pcch_msg.message.choice.c1.choice.paging.pagingRecordList->list);
   pcch_msg.message.choice.c1.choice.paging.pagingRecordList->list.count = 0;
 
-  if ((paging_record_p = calloc(1, sizeof(PagingRecord_t))) == NULL) {
+  if ((paging_record_p = calloc(1, sizeof(LTE_PagingRecord_t))) == NULL) {
     /* Possible error on calloc */
     return (-1);
   }
 
-  memset(paging_record_p, 0, sizeof(PagingRecord_t));
+  memset(paging_record_p, 0, sizeof(LTE_PagingRecord_t));
 
   /* convert ue_paging_identity_t to PagingUE_Identity_t */
   if (ue_paging_identity.presenceMask == UE_PAGING_IDENTITY_s_tmsi) {
-    paging_record_p->ue_Identity.present = PagingUE_Identity_PR_s_TMSI;
+    paging_record_p->ue_Identity.present = LTE_PagingUE_Identity_PR_s_TMSI;
     MME_CODE_TO_OCTET_STRING(ue_paging_identity.choice.s_tmsi.mme_code,
                              &paging_record_p->ue_Identity.choice.s_TMSI.mmec);
     paging_record_p->ue_Identity.choice.s_TMSI.mmec.bits_unused = 0;
     M_TMSI_TO_OCTET_STRING(ue_paging_identity.choice.s_tmsi.m_tmsi,
-                             &paging_record_p->ue_Identity.choice.s_TMSI.m_TMSI);
+                           &paging_record_p->ue_Identity.choice.s_TMSI.m_TMSI);
     paging_record_p->ue_Identity.choice.s_TMSI.m_TMSI.bits_unused = 0;
   } else if (ue_paging_identity.presenceMask == UE_PAGING_IDENTITY_imsi) {
-    paging_record_p->ue_Identity.present = PagingUE_Identity_PR_imsi;
-    IMSI_Digit_t imsi_digit[21];
+    paging_record_p->ue_Identity.present = LTE_PagingUE_Identity_PR_imsi;
+    LTE_IMSI_Digit_t imsi_digit[21];
+
     for (j = 0; j< ue_paging_identity.choice.imsi.length; j++) {  /* IMSI size */
-      imsi_digit[j] = (IMSI_Digit_t)ue_paging_identity.choice.imsi.buffer[j];
+      imsi_digit[j] = (LTE_IMSI_Digit_t)ue_paging_identity.choice.imsi.buffer[j];
       ASN_SEQUENCE_ADD(&paging_record_p->ue_Identity.choice.imsi.list, &imsi_digit[j]);
     }
   }
 
   /* set cn_domain */
   if (cn_domain == CN_DOMAIN_PS) {
-    paging_record_p->cn_Domain = PagingRecord__cn_Domain_ps;
+    paging_record_p->cn_Domain = LTE_PagingRecord__cn_Domain_ps;
   } else {
-    paging_record_p->cn_Domain = PagingRecord__cn_Domain_cs;
+    paging_record_p->cn_Domain = LTE_PagingRecord__cn_Domain_cs;
   }
+
   /* add to list */
   ASN_SEQUENCE_ADD(&pcch_msg.message.choice.c1.choice.paging.pagingRecordList->list, paging_record_p);
   LOG_D(RRC, "[eNB %d] do_Paging paging_record: cn_Domain %ld, ue_paging_identity.presenceMask %d, PagingRecordList.count %d\n",
-          Mod_id, paging_record_p->cn_Domain, ue_paging_identity.presenceMask, pcch_msg.message.choice.c1.choice.paging.pagingRecordList->list.count);
+        Mod_id, paging_record_p->cn_Domain, ue_paging_identity.presenceMask, pcch_msg.message.choice.c1.choice.paging.pagingRecordList->list.count);
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_PCCH_Message, NULL, (void *)&pcch_msg, buffer, RRC_BUF_SIZE);
 
-  enc_rval = uper_encode_to_buffer(&asn_DEF_PCCH_Message, NULL, (void*)&pcch_msg, buffer, RRC_BUF_SIZE);
-  if(enc_rval.encoded == -1)
-  {
-     LOG_I(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n",
-           enc_rval.failed_type->name, enc_rval.encoded);
-     return -1;
+  if(enc_rval.encoded == -1) {
+    LOG_I(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n",
+          enc_rval.failed_type->name, enc_rval.encoded);
+    return -1;
   }
+
   if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-     xer_fprint(stdout, &asn_DEF_PCCH_Message, (void*)&pcch_msg);
+    xer_fprint(stdout, &asn_DEF_LTE_PCCH_Message, (void *)&pcch_msg);
   }
 
   return((enc_rval.encoded+7)/8);
 }
 
-uint8_t do_ULInformationTransfer(uint8_t **buffer, uint32_t pdu_length, uint8_t *pdu_buffer)
-{
+uint8_t do_ULInformationTransfer(uint8_t **buffer, uint32_t pdu_length, uint8_t *pdu_buffer) {
   ssize_t encoded;
-
-  UL_DCCH_Message_t ul_dcch_msg;
-
-  memset(&ul_dcch_msg, 0, sizeof(UL_DCCH_Message_t));
-
-  ul_dcch_msg.message.present           = UL_DCCH_MessageType_PR_c1;
-  ul_dcch_msg.message.choice.c1.present = UL_DCCH_MessageType__c1_PR_ulInformationTransfer;
-  ul_dcch_msg.message.choice.c1.choice.ulInformationTransfer.criticalExtensions.present = ULInformationTransfer__criticalExtensions_PR_c1;
-  ul_dcch_msg.message.choice.c1.choice.ulInformationTransfer.criticalExtensions.choice.c1.present = DLInformationTransfer__criticalExtensions__c1_PR_dlInformationTransfer_r8;
+  LTE_UL_DCCH_Message_t ul_dcch_msg;
+  memset(&ul_dcch_msg, 0, sizeof(LTE_UL_DCCH_Message_t));
+  ul_dcch_msg.message.present           = LTE_UL_DCCH_MessageType_PR_c1;
+  ul_dcch_msg.message.choice.c1.present = LTE_UL_DCCH_MessageType__c1_PR_ulInformationTransfer;
+  ul_dcch_msg.message.choice.c1.choice.ulInformationTransfer.criticalExtensions.present = LTE_ULInformationTransfer__criticalExtensions_PR_c1;
+  ul_dcch_msg.message.choice.c1.choice.ulInformationTransfer.criticalExtensions.choice.c1.present = LTE_DLInformationTransfer__criticalExtensions__c1_PR_dlInformationTransfer_r8;
   ul_dcch_msg.message.choice.c1.choice.ulInformationTransfer.criticalExtensions.choice.c1.choice.ulInformationTransfer_r8.dedicatedInfoType.present =
-    ULInformationTransfer_r8_IEs__dedicatedInfoType_PR_dedicatedInfoNAS;
+    LTE_ULInformationTransfer_r8_IEs__dedicatedInfoType_PR_dedicatedInfoNAS;
   ul_dcch_msg.message.choice.c1.choice.ulInformationTransfer.criticalExtensions.choice.c1.choice.ulInformationTransfer_r8.dedicatedInfoType.choice.dedicatedInfoNAS.size = pdu_length;
   ul_dcch_msg.message.choice.c1.choice.ulInformationTransfer.criticalExtensions.choice.c1.choice.ulInformationTransfer_r8.dedicatedInfoType.choice.dedicatedInfoNAS.buf = pdu_buffer;
+  encoded = uper_encode_to_new_buffer (&asn_DEF_LTE_UL_DCCH_Message, NULL, (void *) &ul_dcch_msg, (void **) buffer);
+  return encoded;
+}
+
+int do_HandoverPreparation(char *ho_buf, int ho_size, LTE_UE_EUTRA_Capability_t *ue_eutra_cap, int rrc_size)
+{
+  asn_enc_rval_t enc_rval;
+  LTE_HandoverPreparationInformation_t ho;
+  LTE_HandoverPreparationInformation_r8_IEs_t *ho_info;
+  LTE_UE_CapabilityRAT_Container_t *ue_cap_rat_container;
 
-  encoded = uper_encode_to_new_buffer (&asn_DEF_UL_DCCH_Message, NULL, (void*) &ul_dcch_msg, (void **) buffer);
+  char rrc_buf[rrc_size];
 
-  return encoded;
+  memset(rrc_buf, 0, rrc_size);
+
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_UE_EUTRA_Capability,
+                                   NULL,
+                                   ue_eutra_cap,
+                                   rrc_buf,
+                                   rrc_size);
+
+  /* TODO: free the OCTET_STRING */
+
+  AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
+               enc_rval.failed_type->name, enc_rval.encoded);
+
+
+  memset(&ho, 0, sizeof(ho));
+
+  ho.criticalExtensions.present = LTE_HandoverPreparationInformation__criticalExtensions_PR_c1;
+  ho.criticalExtensions.choice.c1.present = LTE_HandoverPreparationInformation__criticalExtensions__c1_PR_handoverPreparationInformation_r8;
+
+  ho_info = &ho.criticalExtensions.choice.c1.choice.handoverPreparationInformation_r8;
+  {
+      ue_cap_rat_container = (LTE_UE_CapabilityRAT_Container_t *)calloc(1,sizeof(LTE_UE_CapabilityRAT_Container_t));
+      ue_cap_rat_container->rat_Type = LTE_RAT_Type_eutra;
+
+      AssertFatal (OCTET_STRING_fromBuf(
+                   &ue_cap_rat_container->ueCapabilityRAT_Container,
+                   rrc_buf, rrc_size) != -1, "fatal: OCTET_STRING_fromBuf failed\n");
+
+      ASN_SEQUENCE_ADD(&ho_info->ue_RadioAccessCapabilityInfo.list, ue_cap_rat_container);
+  }
+
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_HandoverPreparationInformation,
+                                   NULL,
+                                   &ho,
+                                   ho_buf,
+                                   ho_size);
+
+  /* TODO: free the OCTET_STRING */
+
+  AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
+               enc_rval.failed_type->name, enc_rval.encoded);
+
+  return((enc_rval.encoded+7)/8);
 }
 
-OAI_UECapability_t *fill_ue_capability(char *UE_EUTRA_Capability_xer_fname)
+int do_HandoverCommand(char *ho_buf, int ho_size, char *rrc_buf, int rrc_size)
 {
-  static OAI_UECapability_t UECapability; /* TODO declared static to allow returning this has an address should be allocated in a cleaner way. */
-  static SupportedBandEUTRA_t Bandlist[4]; // the macro ASN_SEQUENCE_ADD() does not copy the source, but only stores a reference to it
-  static InterFreqBandInfo_t InterFreqBandInfo[4][4]; // the macro ASN_SEQUENCE_ADD() does not copy the source, but only stores a reference to it
-  static BandInfoEUTRA_t BandInfoEUTRA[4]; // the macro ASN_SEQUENCE_ADD() does not copy the source, but only stores a reference to it
+  asn_enc_rval_t enc_rval;
+  LTE_HandoverCommand_t ho;
+
+  memset(&ho, 0, sizeof(ho));
+
+  ho.criticalExtensions.present = LTE_HandoverCommand__criticalExtensions_PR_c1;
+  ho.criticalExtensions.choice.c1.present = LTE_HandoverCommand__criticalExtensions__c1_PR_handoverCommand_r8;
+
+  AssertFatal (OCTET_STRING_fromBuf(
+               &ho.criticalExtensions.choice.c1.choice.handoverCommand_r8.handoverCommandMessage,
+               rrc_buf, rrc_size) != -1, "fatal: OCTET_STRING_fromBuf failed\n");
+
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_HandoverCommand,
+                                   NULL,
+                                   &ho,
+                                   ho_buf,
+                                   ho_size);
+
+  /* TODO: free the OCTET_STRING */
 
+  AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
+               enc_rval.failed_type->name, enc_rval.encoded);
+
+  return((enc_rval.encoded+7)/8);
+}
+
+OAI_UECapability_t *fill_ue_capability(char *UE_EUTRA_Capability_xer_fname) {
+  static OAI_UECapability_t UECapability; /* TODO declared static to allow returning this has an address should be allocated in a cleaner way. */
+  static LTE_SupportedBandEUTRA_t Bandlist[4]; // the macro ASN_SEQUENCE_ADD() does not copy the source, but only stores a reference to it
+  static LTE_InterFreqBandInfo_t InterFreqBandInfo[4][4]; // the macro ASN_SEQUENCE_ADD() does not copy the source, but only stores a reference to it
+  static LTE_BandInfoEUTRA_t BandInfoEUTRA[4]; // the macro ASN_SEQUENCE_ADD() does not copy the source, but only stores a reference to it
   asn_enc_rval_t enc_rval;
   asn_dec_rval_t dec_rval;
-
-  long maxNumberROHC_ContextSessions = PDCP_Parameters__maxNumberROHC_ContextSessions_cs16;
+  long maxNumberROHC_ContextSessions = LTE_PDCP_Parameters__maxNumberROHC_ContextSessions_cs16;
   int i;
-
-  UE_EUTRA_Capability_t *UE_EUTRA_Capability;
+  LTE_UE_EUTRA_Capability_t *UE_EUTRA_Capability;
   char UE_EUTRA_Capability_xer[8192];
   size_t size;
-
   LOG_I(RRC,"Allocating %zu bytes for UE_EUTRA_Capability\n",sizeof(*UE_EUTRA_Capability));
-
   UE_EUTRA_Capability = CALLOC(1, sizeof(*UE_EUTRA_Capability));
-
   assert(UE_EUTRA_Capability);
 
   if (!UE_EUTRA_Capability_xer_fname)  {
@@ -3404,10 +4295,8 @@ OAI_UECapability_t *fill_ue_capability(char *UE_EUTRA_Capability_xer_fname)
     Bandlist[2].halfDuplex = 0;
     Bandlist[3].bandEUTRA  = 38;  // UL/DL 2570-2620, TDD
     Bandlist[3].halfDuplex = 0;
-
-    memset((void*)InterFreqBandInfo, 0, sizeof(InterFreqBandInfo));
-    memset((void*)BandInfoEUTRA, 0, sizeof(BandInfoEUTRA));
-
+    memset((void *)InterFreqBandInfo, 0, sizeof(InterFreqBandInfo));
+    memset((void *)BandInfoEUTRA, 0, sizeof(BandInfoEUTRA));
     InterFreqBandInfo[0][0].interFreqNeedForGaps = 0;
     InterFreqBandInfo[0][1].interFreqNeedForGaps = 1;
     InterFreqBandInfo[0][2].interFreqNeedForGaps = 1;
@@ -3424,8 +4313,6 @@ OAI_UECapability_t *fill_ue_capability(char *UE_EUTRA_Capability_xer_fname)
     InterFreqBandInfo[3][1].interFreqNeedForGaps = 1;
     InterFreqBandInfo[3][2].interFreqNeedForGaps = 1;
     InterFreqBandInfo[3][3].interFreqNeedForGaps = 0;
-
-
     UE_EUTRA_Capability->accessStratumRelease = 0;//AccessStratumRelease_rel8;
     UE_EUTRA_Capability->ue_Category          = 4;
     UE_EUTRA_Capability->pdcp_Parameters.supportedROHC_Profiles.profile0x0001=0;
@@ -3437,47 +4324,39 @@ OAI_UECapability_t *fill_ue_capability(char *UE_EUTRA_Capability_xer_fname)
     UE_EUTRA_Capability->pdcp_Parameters.supportedROHC_Profiles.profile0x0102=0;
     UE_EUTRA_Capability->pdcp_Parameters.supportedROHC_Profiles.profile0x0103=0;
     UE_EUTRA_Capability->pdcp_Parameters.supportedROHC_Profiles.profile0x0104=0;
-
     UE_EUTRA_Capability->pdcp_Parameters.maxNumberROHC_ContextSessions = &maxNumberROHC_ContextSessions;
-
     UE_EUTRA_Capability->phyLayerParameters.ue_TxAntennaSelectionSupported = 0;
     UE_EUTRA_Capability->phyLayerParameters.ue_SpecificRefSigsSupported    = 0;
     UE_EUTRA_Capability->rf_Parameters.supportedBandListEUTRA.list.count                          = 0;
-    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->rf_Parameters.supportedBandListEUTRA.list,(void*)&Bandlist[0]);
-    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->rf_Parameters.supportedBandListEUTRA.list,(void*)&Bandlist[1]);
-    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->rf_Parameters.supportedBandListEUTRA.list,(void*)&Bandlist[2]);
-    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->rf_Parameters.supportedBandListEUTRA.list,(void*)&Bandlist[3]);
-
-    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list,(void*)&BandInfoEUTRA[0]);
-    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list,(void*)&BandInfoEUTRA[1]);
-    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list,(void*)&BandInfoEUTRA[2]);
-    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list,(void*)&BandInfoEUTRA[3]);
-
-    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[0]->interFreqBandList.list,(void*)&InterFreqBandInfo[0][0]);
-    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[0]->interFreqBandList.list,(void*)&InterFreqBandInfo[0][1]);
-    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[0]->interFreqBandList.list,(void*)&InterFreqBandInfo[0][2]);
-    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[0]->interFreqBandList.list,(void*)&InterFreqBandInfo[0][3]);
-
-    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[1]->interFreqBandList.list,(void*)&InterFreqBandInfo[1][0]);
-    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[1]->interFreqBandList.list,(void*)&InterFreqBandInfo[1][1]);
-    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[1]->interFreqBandList.list,(void*)&InterFreqBandInfo[1][2]);
-    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[1]->interFreqBandList.list,(void*)&InterFreqBandInfo[1][3]);
-
-    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[2]->interFreqBandList.list,(void*)&InterFreqBandInfo[2][0]);
-    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[2]->interFreqBandList.list,(void*)&InterFreqBandInfo[2][1]);
-    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[2]->interFreqBandList.list,(void*)&InterFreqBandInfo[2][2]);
-    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[2]->interFreqBandList.list,(void*)&InterFreqBandInfo[2][3]);
-
-    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[3]->interFreqBandList.list,(void*)&InterFreqBandInfo[3][0]);
-    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[3]->interFreqBandList.list,(void*)&InterFreqBandInfo[3][1]);
-    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[3]->interFreqBandList.list,(void*)&InterFreqBandInfo[3][2]);
-    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[3]->interFreqBandList.list,(void*)&InterFreqBandInfo[3][3]);
+    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->rf_Parameters.supportedBandListEUTRA.list,(void *)&Bandlist[0]);
+    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->rf_Parameters.supportedBandListEUTRA.list,(void *)&Bandlist[1]);
+    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->rf_Parameters.supportedBandListEUTRA.list,(void *)&Bandlist[2]);
+    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->rf_Parameters.supportedBandListEUTRA.list,(void *)&Bandlist[3]);
+    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list,(void *)&BandInfoEUTRA[0]);
+    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list,(void *)&BandInfoEUTRA[1]);
+    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list,(void *)&BandInfoEUTRA[2]);
+    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list,(void *)&BandInfoEUTRA[3]);
+    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[0]->interFreqBandList.list,(void *)&InterFreqBandInfo[0][0]);
+    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[0]->interFreqBandList.list,(void *)&InterFreqBandInfo[0][1]);
+    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[0]->interFreqBandList.list,(void *)&InterFreqBandInfo[0][2]);
+    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[0]->interFreqBandList.list,(void *)&InterFreqBandInfo[0][3]);
+    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[1]->interFreqBandList.list,(void *)&InterFreqBandInfo[1][0]);
+    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[1]->interFreqBandList.list,(void *)&InterFreqBandInfo[1][1]);
+    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[1]->interFreqBandList.list,(void *)&InterFreqBandInfo[1][2]);
+    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[1]->interFreqBandList.list,(void *)&InterFreqBandInfo[1][3]);
+    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[2]->interFreqBandList.list,(void *)&InterFreqBandInfo[2][0]);
+    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[2]->interFreqBandList.list,(void *)&InterFreqBandInfo[2][1]);
+    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[2]->interFreqBandList.list,(void *)&InterFreqBandInfo[2][2]);
+    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[2]->interFreqBandList.list,(void *)&InterFreqBandInfo[2][3]);
+    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[3]->interFreqBandList.list,(void *)&InterFreqBandInfo[3][0]);
+    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[3]->interFreqBandList.list,(void *)&InterFreqBandInfo[3][1]);
+    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[3]->interFreqBandList.list,(void *)&InterFreqBandInfo[3][2]);
+    ASN_SEQUENCE_ADD(&UE_EUTRA_Capability->measParameters.bandListEUTRA.list.array[3]->interFreqBandList.list,(void *)&InterFreqBandInfo[3][3]);
 
     // UE_EUTRA_Capability->measParameters.bandListEUTRA.list.count                         = 0;  // no measurements on other bands
     // UE_EUTRA_Capability->featureGroupIndicators  // null
 
-    if(usim_test == 1)
-    {
+    if (get_softmodem_params()->usim_test == 1) {
       // featureGroup is mandatory for CMW tests
       // featureGroup is filled only for usim-test mode
       BIT_STRING_t *bit_string = CALLOC(1, sizeof(*bit_string));
@@ -3491,8 +4370,7 @@ OAI_UECapability_t *fill_ue_capability(char *UE_EUTRA_Capability_xer_fname)
 
     // UE_EUTRA_Capability->interRAT_Parameters     // null
   } else {
-
-    FILE* f = fopen(UE_EUTRA_Capability_xer_fname, "r");
+    FILE *f = fopen(UE_EUTRA_Capability_xer_fname, "r");
     assert(f);
     size = fread(UE_EUTRA_Capability_xer, 1, sizeof UE_EUTRA_Capability_xer, f);
     fclose(f);
@@ -3503,49 +4381,23 @@ OAI_UECapability_t *fill_ue_capability(char *UE_EUTRA_Capability_xer_fname)
       return(NULL);
     }
 
-    dec_rval = xer_decode(0, &asn_DEF_UE_EUTRA_Capability, (void*)UE_EUTRA_Capability, UE_EUTRA_Capability_xer, size);
+    dec_rval = xer_decode(0, &asn_DEF_LTE_UE_EUTRA_Capability, (void *)UE_EUTRA_Capability, UE_EUTRA_Capability_xer, size);
     assert(dec_rval.code == RC_OK);
   }
 
   UECapability.UE_EUTRA_Capability = UE_EUTRA_Capability;
+
   if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-     xer_fprint(stdout,&asn_DEF_UE_EUTRA_Capability,(void *)UE_EUTRA_Capability);
+    xer_fprint(stdout,&asn_DEF_LTE_UE_EUTRA_Capability,(void *)UE_EUTRA_Capability);
   }
-  enc_rval = uper_encode_to_buffer(&asn_DEF_UE_EUTRA_Capability,
+
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_UE_EUTRA_Capability,
                                    NULL,
-                                   (void*)UE_EUTRA_Capability,
+                                   (void *)UE_EUTRA_Capability,
                                    &UECapability.sdu[0],
                                    MAX_UE_CAPABILITY_SIZE);
   AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
-               enc_rval.failed_type->name, enc_rval.encoded);
-
-#if defined(ENABLE_ITTI)
-# if defined(DISABLE_XER_SPRINT)
-  {
-    MessageDef *msg_p;
-
-    msg_p = itti_alloc_new_message (TASK_RRC_UE, RRC_UE_EUTRA_CAPABILITY);
-    memcpy (&msg_p->ittiMsg, (void *) UE_EUTRA_Capability, sizeof(RrcUeEutraCapability));
-
-    itti_send_msg_to_task (TASK_UNKNOWN, NB_eNB_INST, msg_p);
-  }
-# else
-  {
-    char        message_string[10000];
-    size_t      message_string_size;
-
-    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_UE_EUTRA_Capability, (void *)UE_EUTRA_Capability)) > 0) {
-      MessageDef *msg_p;
-
-      msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, RRC_UE_EUTRA_CAPABILITY, message_string_size + sizeof (IttiMsgText));
-      msg_p->ittiMsg.rrc_ue_eutra_capability.size = message_string_size;
-      memcpy(&msg_p->ittiMsg.rrc_ue_eutra_capability.text, message_string, message_string_size);
-
-      itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, msg_p);
-    }
-  }
-# endif
-#endif
+	       enc_rval.failed_type->name, enc_rval.encoded);
 
   UECapability.sdu_size = (enc_rval.encoded + 7) / 8;
   LOG_I(PHY, "[RRC]UE Capability encoded, %d bytes (%zd bits)\n",
@@ -3561,7 +4413,6 @@ OAI_UECapability_t *fill_ue_capability(char *UE_EUTRA_Capability_xer_fname)
     LOG_D(PHY, "[RRC]UE Capability encoded, %s\n", sdu);
     free(sdu);
   }
-
   return(&UECapability);
 }
 
diff --git a/openair2/RRC/LTE/MESSAGES/asn1_msg.h b/openair2/RRC/LTE/MESSAGES/asn1_msg.h
index a4da38c0196a23efc250e90ac9f4d3fa3d1d83bc..eb9572f4d2617ed30519d3054ee34e7c7bd8b5f8 100644
--- a/openair2/RRC/LTE/MESSAGES/asn1_msg.h
+++ b/openair2/RRC/LTE/MESSAGES/asn1_msg.h
@@ -40,7 +40,7 @@
 #include <asn_internal.h> /* for _ASN_DEFAULT_STACK_MAX */
 
 #include "RRC/LTE/rrc_defs.h"
-#include "SL-DestinationInfoList-r12.h"
+#include "LTE_SL-DestinationInfoList-r12.h"
 
 /*
  * The variant of the above function which dumps the BASIC-XER (XER_F_BASIC)
@@ -57,14 +57,18 @@ uint16_t get_adjacent_cell_id(uint8_t Mod_id,uint8_t index);
 uint8_t get_adjacent_cell_mod_id(uint16_t phyCellId);
 
 /**
-\brief Generate configuration for SIB1 (eNB).
+\brief Generate configuration for MIB (eNB).
 @param carrier pointer to Carrier information
 @param N_RB_DL Number of downlink PRBs
 @param phich_Resource PHICH resoure parameter
 @param phich_duration PHICH duration parameter
 @param frame radio frame number
 @return size of encoded bit stream in bytes*/
-uint8_t do_MIB(rrc_eNB_carrier_data_t *carrier, uint32_t N_RB_DL, uint32_t phich_Resource, uint32_t phich_duration, uint32_t frame);
+uint8_t do_MIB(rrc_eNB_carrier_data_t *carrier, uint32_t N_RB_DL, uint32_t phich_Resource, uint32_t phich_duration, uint32_t frame
+#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
+	       , uint32_t schedulingInfoSIB1
+#endif
+	       );
 
 /**
 \brief Generate configuration for SIB1 (eNB).
@@ -72,11 +76,19 @@ uint8_t do_MIB(rrc_eNB_carrier_data_t *carrier, uint32_t N_RB_DL, uint32_t phich
 @param Mod_id Instance of eNB
 @param Component carrier Component carrier to configure
 @param configuration Pointer Configuration Request structure  
+@param br_flag Do for BL/CE UE configuration
 @return size of encoded bit stream in bytes*/
 
-uint8_t do_SIB1(rrc_eNB_carrier_data_t *carrier,int Mod_id,int CC_id, RrcConfigurationReq *configuration
+uint8_t do_SIB1(rrc_eNB_carrier_data_t *carrier,int Mod_id,int CC_id
+#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
+                , BOOLEAN_t brOption
+#endif
+#if defined(ENABLE_ITTI)
+                ,RrcConfigurationReq *configuration
+#endif
                );
 
+
 /**
 \brief Generate a default configuration for SIB2/SIB3 in one System Information PDU (eNB).
 @param Mod_id Index of eNB (used to derive some parameters)
@@ -90,8 +102,11 @@ uint8_t do_SIB1(rrc_eNB_carrier_data_t *carrier,int Mod_id,int CC_id, RrcConfigu
 
 uint8_t do_SIB23(uint8_t Mod_id,
                  int CC_id
+#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
+		 , BOOLEAN_t brOption
+#endif
 #if defined(ENABLE_ITTI)
-                 , RrcConfigurationReq *configuration
+  , RrcConfigurationReq *configuration
 #endif
                 );
 
@@ -110,21 +125,21 @@ uint8_t do_RRCConnectionRequest(uint8_t Mod_id, uint8_t *buffer,uint8_t *rv);
 @param discTxResourceReq Pointer to  number of discovery messages for discovery announcements for which  UE requests E-UTRAN to assign dedicated resources
 @param mode Indicates different requests from upper layers
 @returns Size of encoded bit stream in bytes*/
-uint8_t do_SidelinkUEInformation(uint8_t Mod_id, uint8_t *buffer, SL_DestinationInfoList_r12_t  *destinationInfoList, long *discTxResourceReq, SL_TRIGGER_t mode);
+uint8_t do_SidelinkUEInformation(uint8_t Mod_id, uint8_t *buffer, LTE_SL_DestinationInfoList_r12_t  *destinationInfoList, long *discTxResourceReq, SL_TRIGGER_t mode);
 
 /** \brief Generate an RRCConnectionSetupComplete UL-DCCH-Message (UE)
 @param buffer Pointer to PER-encoded ASN.1 description of UL-DCCH-Message PDU
 @returns Size of encoded bit stream in bytes*/
-uint8_t do_RRCConnectionSetupComplete(uint8_t Mod_id, uint8_t* buffer, const uint8_t Transaction_id, const int dedicatedInfoNASLength,
-                                      const char* dedicatedInfoNAS);
+uint8_t do_RRCConnectionSetupComplete(uint8_t Mod_id, uint8_t *buffer, const uint8_t Transaction_id, const int dedicatedInfoNASLength,
+                                      const char *dedicatedInfoNAS);
 
 /** \brief Generate an RRCConnectionReconfigurationComplete UL-DCCH-Message (UE)
 @param buffer Pointer to PER-encoded ASN.1 description of UL-DCCH-Message PDU
 @returns Size of encoded bit stream in bytes*/
 uint8_t
 do_RRCConnectionReconfigurationComplete(
-  const protocol_ctxt_t* const ctxt_pP,
-  uint8_t* buffer,
+  const protocol_ctxt_t *const ctxt_pP,
+  uint8_t *buffer,
   const uint8_t Transaction_id
 );
 
@@ -143,16 +158,56 @@ PhysicalConfigDedicated IEs.  The latter does not enable periodic CQI reporting
 @returns Size of encoded bit stream in bytes*/
 uint8_t
 do_RRCConnectionSetup(
-  const protocol_ctxt_t*     const ctxt_pP,
-  rrc_eNB_ue_context_t*      const ue_context_pP,
+  const protocol_ctxt_t     *const ctxt_pP,
+  rrc_eNB_ue_context_t      *const ue_context_pP,
   int                              CC_id,
-  uint8_t*                   const buffer,
+  uint8_t                   *const buffer,
   const uint8_t                    transmission_mode,
   const uint8_t                    Transaction_id,
-  SRB_ToAddModList_t**             SRB_configList,
-  struct PhysicalConfigDedicated** physicalConfigDedicated
+  LTE_SRB_ToAddModList_t             **SRB_configList,
+  struct LTE_PhysicalConfigDedicated **physicalConfigDedicated
+);
+#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
+uint8_t
+do_RRCConnectionSetup_BR(
+	const protocol_ctxt_t*     const ctxt_pP,
+	rrc_eNB_ue_context_t*      const ue_context_pP,
+	int                              CC_id,
+	uint8_t*                   const buffer,
+	const uint8_t                    transmission_mode,
+	const uint8_t                    Transaction_id,
+	LTE_SRB_ToAddModList_t**             SRB_configList,
+	struct LTE_PhysicalConfigDedicated** physicalConfigDedicated
 );
+#endif
+
 
+
+#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
+uint16_t
+do_RRCConnectionReconfiguration_BR(
+                   const protocol_ctxt_t*        const ctxt_pP,
+                   uint8_t                            *buffer,
+                   uint8_t                             Transaction_id,
+                   LTE_SRB_ToAddModList_t                 *SRB_list,
+                   LTE_DRB_ToAddModList_t                 *DRB_list,
+                   LTE_DRB_ToReleaseList_t                *DRB_list2,
+                   struct LTE_SPS_Config                  *sps_Config,
+                   struct LTE_PhysicalConfigDedicated     *physicalConfigDedicated,
+                   LTE_MeasObjectToAddModList_t           *MeasObj_list,
+                   LTE_ReportConfigToAddModList_t         *ReportConfig_list,
+                   LTE_QuantityConfig_t                   *quantityConfig,
+                   LTE_MeasIdToAddModList_t               *MeasId_list,
+                   LTE_MAC_MainConfig_t                   *mac_MainConfig,
+                   LTE_MeasGapConfig_t                    *measGapConfig,
+                   LTE_MobilityControlInfo_t              *mobilityInfo,
+                   struct LTE_MeasConfig__speedStatePars  *speedStatePars,
+                   LTE_RSRP_Range_t                       *rsrp,
+                   LTE_C_RNTI_t                           *cba_rnti,
+                   struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList,
+                   LTE_SCellToAddMod_r10_t  *SCell_config
+                   );
+#endif
 /**
 \brief Generate an RRCConnectionReconfiguration DL-DCCH-Message (eNB).  This routine configures SRBToAddMod (SRB2) and one DRBToAddMod
 (DRB3).  PhysicalConfigDedicated is not updated.
@@ -177,31 +232,32 @@ do_RRCConnectionSetup(
 
 uint16_t
 do_RRCConnectionReconfiguration(
-  const protocol_ctxt_t*        const ctxt_pP,
-    uint8_t                            *buffer,
-    uint8_t                             Transaction_id,
-    SRB_ToAddModList_t                 *SRB_list,
-    DRB_ToAddModList_t                 *DRB_list,
-    DRB_ToReleaseList_t                *DRB_list2,
-    struct SPS_Config                  *sps_Config,
-    struct PhysicalConfigDedicated     *physicalConfigDedicated,
-    MeasObjectToAddModList_t           *MeasObj_list,
-    ReportConfigToAddModList_t         *ReportConfig_list,
-    QuantityConfig_t                   *quantityConfig,
-    MeasIdToAddModList_t               *MeasId_list,
-    MAC_MainConfig_t                   *mac_MainConfig,
-    MeasGapConfig_t                    *measGapConfig,
-    MobilityControlInfo_t              *mobilityInfo,
-    struct MeasConfig__speedStatePars  *speedStatePars,
-    RSRP_Range_t                       *rsrp,
-    C_RNTI_t                           *cba_rnti,
-  struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList* dedicatedInfoNASList,
-  SL_CommConfig_r12_t                *sl_CommConfig,
-  SL_DiscConfig_r12_t                *sl_DiscConfig
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-    , SCellToAddMod_r10_t  *SCell_config
+  const protocol_ctxt_t        *const ctxt_pP,
+  uint8_t                            *buffer,
+  uint8_t                             Transaction_id,
+  LTE_SRB_ToAddModList_t                 *SRB_list,
+  LTE_DRB_ToAddModList_t                 *DRB_list,
+  LTE_DRB_ToReleaseList_t                *DRB_list2,
+  struct LTE_SPS_Config                  *sps_Config,
+  struct LTE_PhysicalConfigDedicated     *physicalConfigDedicated,
+  LTE_MeasObjectToAddModList_t           *MeasObj_list,
+  LTE_ReportConfigToAddModList_t         *ReportConfig_list,
+  LTE_QuantityConfig_t                   *quantityConfig,
+  LTE_MeasIdToAddModList_t               *MeasId_list,
+  LTE_MAC_MainConfig_t                   *mac_MainConfig,
+  LTE_MeasGapConfig_t                    *measGapConfig,
+  LTE_MobilityControlInfo_t              *mobilityInfo,
+  LTE_SecurityConfigHO_t                 *securityConfigHO,
+  struct LTE_MeasConfig__speedStatePars  *speedStatePars,
+  LTE_RSRP_Range_t                       *rsrp,
+  LTE_C_RNTI_t                           *cba_rnti,
+  struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList,
+  LTE_SL_CommConfig_r12_t                *sl_CommConfig,
+  LTE_SL_DiscConfig_r12_t                *sl_DiscConfig
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+  , LTE_SCellToAddMod_r10_t  *SCell_config
 #endif
-                                        );
+);
 /**
 \brief Generate an RRCConnectionReestablishment DL-CCCH-Message (eNB).  This routine configures SRB_ToAddMod (SRB1/SRB2) and
 PhysicalConfigDedicated IEs.  The latter does not enable periodic CQI reporting (PUCCH format 2/2a/2b) or SRS.
@@ -216,14 +272,14 @@ PhysicalConfigDedicated IEs.  The latter does not enable periodic CQI reporting
 @returns Size of encoded bit stream in bytes*/
 uint8_t
 do_RRCConnectionReestablishment(
-  const protocol_ctxt_t*     const ctxt_pP,
-  rrc_eNB_ue_context_t*      const ue_context_pP,
+  const protocol_ctxt_t     *const ctxt_pP,
+  rrc_eNB_ue_context_t      *const ue_context_pP,
   int                              CC_id,
-  uint8_t*                   const buffer,
+  uint8_t                   *const buffer,
   const uint8_t                    transmission_mode,
   const uint8_t                    Transaction_id,
-  SRB_ToAddModList_t               **SRB_configList,
-  struct PhysicalConfigDedicated   **physicalConfigDedicated);
+  LTE_SRB_ToAddModList_t               **SRB_configList,
+  struct LTE_PhysicalConfigDedicated   **physicalConfigDedicated);
 
 /**
 \brief Generate an RRCConnectionReestablishmentReject DL-CCCH-Message (eNB).
@@ -232,8 +288,8 @@ do_RRCConnectionReestablishment(
 @returns Size of encoded bit stream in bytes*/
 uint8_t
 do_RRCConnectionReestablishmentReject(
-    uint8_t                    Mod_id,
-    uint8_t*                   const buffer);
+  uint8_t                    Mod_id,
+  uint8_t                   *const buffer);
 
 /**
 \brief Generate an RRCConnectionReject DL-CCCH-Message (eNB).
@@ -242,8 +298,8 @@ do_RRCConnectionReestablishmentReject(
 @returns Size of encoded bit stream in bytes*/
 uint8_t
 do_RRCConnectionReject(
-    uint8_t                    Mod_id,
-    uint8_t*                   const buffer);
+  uint8_t                    Mod_id,
+  uint8_t                   *const buffer);
 
 /**
 \brief Generate an RRCConnectionRequest UL-CCCH-Message (UE) based on random string or S-TMSI.  This
@@ -261,7 +317,7 @@ uint8_t do_RRCConnectionRelease(uint8_t Mod_id, uint8_t *buffer,int Transaction_
  * @returns Size of encoded bit stream in bytes
 */
 uint8_t do_MCCHMessage(uint8_t *buffer);
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 /***
  * \brief Generate an MCCH-Message (eNB). This routine configures MBSFNAreaConfiguration (PMCH-InfoList and Subframe Allocation for MBMS data)
  * @param buffer Pointer to PER-encoded ASN.1 description of MCCH-Message PDU
@@ -270,8 +326,8 @@ uint8_t do_MCCHMessage(uint8_t *buffer);
 uint8_t do_MBSFNAreaConfig(uint8_t Mod_id,
                            uint8_t sync_area,
                            uint8_t *buffer,
-                           MCCH_Message_t *mcch_message,
-                           MBSFNAreaConfiguration_r9_t **mbsfnAreaConfiguration);
+                           LTE_MCCH_Message_t *mcch_message,
+                           LTE_MBSFNAreaConfiguration_r9_t **mbsfnAreaConfiguration);
 #endif
 
 uint8_t do_MeasurementReport(uint8_t Mod_id, uint8_t *buffer,int measid,int phy_id,long rsrp_s,long rsrq_s,long rsrp_t,long rsrq_t);
@@ -282,18 +338,22 @@ uint8_t do_Paging(uint8_t Mod_id, uint8_t *buffer, ue_paging_identity_t ue_pagin
 
 uint8_t do_ULInformationTransfer(uint8_t **buffer, uint32_t pdu_length, uint8_t *pdu_buffer);
 
-OAI_UECapability_t *fill_ue_capability(char *UE_EUTRA_Capability_xer);
+int do_HandoverPreparation(char *ho_buf, int ho_size, LTE_UE_EUTRA_Capability_t *ue_eutra_cap, int rrc_size);
+
+int do_HandoverCommand(char *ho_buf, int ho_size, char *rrc_buf, int rrc_size);
+
+OAI_UECapability_t *fill_ue_capability(char *LTE_UE_EUTRA_Capability_xer);
 
 uint8_t
 do_UECapabilityEnquiry(
-  const protocol_ctxt_t* const ctxt_pP,
-  uint8_t*               const buffer,
+  const protocol_ctxt_t *const ctxt_pP,
+  uint8_t               *const buffer,
   const uint8_t                Transaction_id
 );
 
 uint8_t do_SecurityModeCommand(
-  const protocol_ctxt_t* const ctxt_pP,
-  uint8_t* const buffer,
+  const protocol_ctxt_t *const ctxt_pP,
+  uint8_t *const buffer,
   const uint8_t Transaction_id,
   const uint8_t cipheringAlgorithm,
   const uint8_t integrityProtAlgorithm);
diff --git a/openair2/RRC/LTE/MESSAGES/asn1_msg_NB_IoT.c b/openair2/RRC/LTE/MESSAGES/asn1_msg_NB_IoT.c
index 20962f3ca159741224898017637a3400df005c90..480f5c35163bb94c69c8af5c21c904b84a650af3 100644
--- a/openair2/RRC/LTE/MESSAGES/asn1_msg_NB_IoT.c
+++ b/openair2/RRC/LTE/MESSAGES/asn1_msg_NB_IoT.c
@@ -43,26 +43,26 @@
 
 
 //#include for NB-IoT-------------------
-#include "RRCConnectionRequest-NB.h"
-#include "BCCH-DL-SCH-Message-NB.h"
-#include "UL-CCCH-Message-NB.h"
-#include "UL-DCCH-Message-NB.h"
-#include "DL-CCCH-Message-NB.h"
-#include "DL-DCCH-Message-NB.h"
-#include "EstablishmentCause-NB-r13.h"
-#include "RRCConnectionSetup-NB.h"
-#include "SRB-ToAddModList-NB-r13.h"
-#include "DRB-ToAddModList-NB-r13.h"
+#include "LTE_RRCConnectionRequest-NB.h"
+#include "LTE_BCCH-DL-SCH-Message-NB.h"
+#include "LTE_UL-CCCH-Message-NB.h"
+#include "LTE_UL-DCCH-Message-NB.h"
+#include "LTE_DL-CCCH-Message-NB.h"
+#include "LTE_DL-DCCH-Message-NB.h"
+#include "LTE_EstablishmentCause-NB-r13.h"
+#include "LTE_RRCConnectionSetup-NB.h"
+#include "LTE_SRB-ToAddModList-NB-r13.h"
+#include "LTE_DRB-ToAddModList-NB-r13.h"
 #include "RRC/LTE/defs_NB_IoT.h"
-#include "RRCConnectionSetupComplete-NB.h"
-#include "RRCConnectionReconfigurationComplete-NB.h"
-#include "RRCConnectionReconfiguration-NB.h"
-#include "MasterInformationBlock-NB.h"
-#include "SystemInformation-NB.h"
-#include "SystemInformationBlockType1.h"
-#include "SIB-Type-NB-r13.h"
-#include "RRCConnectionResume-NB.h"
-#include "RRCConnectionReestablishment-NB.h"
+#include "LTE_RRCConnectionSetupComplete-NB.h"
+#include "LTE_RRCConnectionReconfigurationComplete-NB.h"
+#include "LTE_RRCConnectionReconfiguration-NB.h"
+#include "LTE_MasterInformationBlock-NB.h"
+#include "LTE_SystemInformation-NB.h"
+#include "LTE_SystemInformationBlockType1.h"
+#include "LTE_SIB-Type-NB-r13.h"
+#include "LTE_RRCConnectionResume-NB.h"
+#include "LTE_RRCConnectionReestablishment-NB.h"
 #include "../defs_NB_IoT.h"
 //----------------------------------------
 
@@ -70,7 +70,7 @@
 #include "enb_config.h"
 
 #if defined(ENABLE_ITTI)
-# include "intertask_interface.h"
+  #include "intertask_interface.h"
 #endif
 
 
@@ -78,14 +78,12 @@
 
 /*do_MIB_NB_NB_IoT*/
 uint8_t do_MIB_NB_IoT(
-		rrc_eNB_carrier_data_NB_IoT_t *carrier,
-		uint16_t N_RB_DL,//may not needed--> for NB_IoT only 1 PRB is used
-		uint32_t frame,
-    uint32_t hyper_frame)
-{
+  rrc_eNB_carrier_data_NB_IoT_t *carrier,
+  uint16_t N_RB_DL,//may not needed--> for NB_IoT only 1 PRB is used
+  uint32_t frame,
+  uint32_t hyper_frame) {
   asn_enc_rval_t enc_rval;
-  BCCH_BCH_Message_NB_t *mib_NB_IoT = &(carrier->mib_NB_IoT);
-
+  LTE_BCCH_BCH_Message_NB_t *mib_NB_IoT = &(carrier->mib_NB_IoT);
   /*
    * systemFrameNumber-MSB: (TS 36.331 pag 576)
    * define the 4 MSB of the SFN (10 bits). The last significant 6 bits will be acquired implicitly by decoding the NPBCH
@@ -98,46 +96,39 @@ uint8_t do_MIB_NB_IoT(
    *
    * NOTE: in OAI never modify the SIB messages!!??
    */
-
   //XXX check if correct the bit assignment
   uint8_t sfn_MSB = (uint8_t)((frame>>6) & 0x0f); // all the 4 bits are set to 1
   uint8_t hsfn_LSB = (uint8_t)(hyper_frame & 0x03); //2 bits set to 1 (0x3 = 0011)
   uint16_t spare=0; //11 bits --> use uint16
-
   mib_NB_IoT->message.systemFrameNumber_MSB_r13.buf = &sfn_MSB;
   mib_NB_IoT->message.systemFrameNumber_MSB_r13.size = 1; //if expressed in byte
   mib_NB_IoT->message.systemFrameNumber_MSB_r13.bits_unused = 4; //is byte based (so how many bits you don't use of the 8 bits of a bite
-
   mib_NB_IoT->message.hyperSFN_LSB_r13.buf= &hsfn_LSB;
   mib_NB_IoT->message.hyperSFN_LSB_r13.size= 1;
   mib_NB_IoT->message.hyperSFN_LSB_r13.bits_unused = 6;
-
   //XXX to be set??
   mib_NB_IoT->message.spare.buf = (uint8_t *)&spare;
   mib_NB_IoT->message.spare.size = 2;
   mib_NB_IoT->message.spare.bits_unused = 5;
-
   //decide how to set it
   mib_NB_IoT->message.schedulingInfoSIB1_r13 =11; //see TS 36.213-->tables 16.4.1.3-3 ecc...
   mib_NB_IoT->message.systemInfoValueTag_r13= 0;
   mib_NB_IoT->message.ab_Enabled_r13 = 0;
-
   //to be decided
-  mib_NB_IoT->message.operationModeInfo_r13.present = MasterInformationBlock_NB__operationModeInfo_r13_PR_inband_SamePCI_r13;
+  mib_NB_IoT->message.operationModeInfo_r13.present = LTE_MasterInformationBlock_NB__operationModeInfo_r13_PR_inband_SamePCI_r13;
   mib_NB_IoT->message.operationModeInfo_r13.choice.inband_SamePCI_r13.eutra_CRS_SequenceInfo_r13 = 0;
-
   printf("[MIB] Initialization of frame information,sfn_MSB %x, hsfn_LSB %x\n",
          (uint32_t)sfn_MSB,
-		 (uint32_t)hsfn_LSB);
-
-  enc_rval = uper_encode_to_buffer(&asn_DEF_BCCH_BCH_Message_NB,
+         (uint32_t)hsfn_LSB);
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_BCCH_BCH_Message_NB,
                                    NULL,
-                                   (void*)mib_NB_IoT,
+                                   (void *)mib_NB_IoT,
                                    carrier->MIB_NB_IoT,
                                    100);
+
   if(enc_rval.encoded <= 0) {
-      LOG_E(RRC, "ASN1 message encoding failed (%s, %lu)!\n",
-               enc_rval.failed_type->name, enc_rval.encoded);
+    LOG_E(RRC, "ASN1 message encoding failed (%s, %lu)!\n",
+          enc_rval.failed_type->name, enc_rval.encoded);
   }
 
   if (enc_rval.encoded==-1) {
@@ -145,63 +136,47 @@ uint8_t do_MIB_NB_IoT(
   }
 
   return((enc_rval.encoded+7)/8);
-
 }
 
 /*do_SIB1_NB*/
 uint8_t do_SIB1_NB_IoT(uint8_t Mod_id, int CC_id,
-				rrc_eNB_carrier_data_NB_IoT_t *carrier,
-                NbIoTRrcConfigurationReq *configuration,
-				uint32_t frame
-               )
-{
-  BCCH_DL_SCH_Message_NB_t *bcch_message= &(carrier->siblock1_NB_IoT);
-  SystemInformationBlockType1_NB_t **sib1_NB_IoT= &(carrier->sib1_NB_IoT);
-  
-
+                       rrc_eNB_carrier_data_NB_IoT_t *carrier,
+                       NbIoTRrcConfigurationReq *configuration,
+                       uint32_t frame
+                      ) {
+  LTE_BCCH_DL_SCH_Message_NB_t *bcch_message= &(carrier->siblock1_NB_IoT);
+  LTE_SystemInformationBlockType1_NB_t **sib1_NB_IoT= &(carrier->sib1_NB_IoT);
   asn_enc_rval_t enc_rval;
-
-  PLMN_IdentityInfo_NB_r13_t PLMN_identity_info_NB_IoT;
-  MCC_MNC_Digit_t dummy_mcc[3],dummy_mnc[3];
-  SchedulingInfo_NB_r13_t *schedulingInfo_NB_IoT;
-  SIB_Type_NB_r13_t *sib_type_NB_IoT;
-
-
-  long* attachWithoutPDN_Connectivity = NULL;
+  LTE_PLMN_IdentityInfo_NB_r13_t PLMN_identity_info_NB_IoT;
+  LTE_MCC_MNC_Digit_t dummy_mcc[3],dummy_mnc[3];
+  LTE_SchedulingInfo_NB_r13_t *schedulingInfo_NB_IoT;
+  LTE_SIB_Type_NB_r13_t *sib_type_NB_IoT;
+  long *attachWithoutPDN_Connectivity = NULL;
   attachWithoutPDN_Connectivity = CALLOC(1,sizeof(long));
   long *nrs_CRS_PowerOffset=NULL;
   nrs_CRS_PowerOffset = CALLOC(1, sizeof(long));
   long *eutraControlRegionSize=NULL; //this parameter should be set only if we are considering in-band operating mode (samePCI or differentPCI)
-   eutraControlRegionSize = CALLOC(1,sizeof(long));
+  eutraControlRegionSize = CALLOC(1,sizeof(long));
   long systemInfoValueTagSI = 0;
-
-  memset(bcch_message,0,sizeof(BCCH_DL_SCH_Message_NB_t));
-  bcch_message->message.present = BCCH_DL_SCH_MessageType_NB_PR_c1;
-  bcch_message->message.choice.c1.present = BCCH_DL_SCH_MessageType_NB__c1_PR_systemInformationBlockType1_r13;
-
+  memset(bcch_message,0,sizeof(LTE_BCCH_DL_SCH_Message_NB_t));
+  bcch_message->message.present = LTE_BCCH_DL_SCH_MessageType_NB_PR_c1;
+  bcch_message->message.choice.c1.present = LTE_BCCH_DL_SCH_MessageType_NB__c1_PR_systemInformationBlockType1_r13;
   //allocation
   *sib1_NB_IoT = &bcch_message->message.choice.c1.choice.systemInformationBlockType1_r13;
-
-
   /*TS 36.331 v14.2.0 pag 589
    * hyperSFN-MSB
    * Indicates the 8 most significant bits of the hyper-SFN. Together with the hyper-LSB in MIB-NB the complete HSFN is build up
    */
   //FIXME see if correct
   uint8_t hyperSFN_MSB = (uint8_t) ((frame>>2)& 0xff);
-
   //XXX to be checked
   (*sib1_NB_IoT)->hyperSFN_MSB_r13.buf = &hyperSFN_MSB;
   (*sib1_NB_IoT)->hyperSFN_MSB_r13.size = 1;
   (*sib1_NB_IoT)->hyperSFN_MSB_r13.bits_unused = 0;
-
-  memset(&PLMN_identity_info_NB_IoT,0,sizeof(PLMN_IdentityInfo_NB_r13_t));
-
+  memset(&PLMN_identity_info_NB_IoT,0,sizeof(LTE_PLMN_IdentityInfo_NB_r13_t));
   PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc = CALLOC(1,sizeof(*PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc));
   memset(PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc,0,sizeof(*PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc));
-
   asn_set_empty(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc->list);//.size=0;
-
   //left as it is???
 #if defined(ENABLE_ITTI)
   dummy_mcc[0] = (configuration->mcc / 100) % 10;
@@ -215,11 +190,8 @@ uint8_t do_SIB1_NB_IoT(uint8_t Mod_id, int CC_id,
   ASN_SEQUENCE_ADD(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc->list,&dummy_mcc[0]);
   ASN_SEQUENCE_ADD(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc->list,&dummy_mcc[1]);
   ASN_SEQUENCE_ADD(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc->list,&dummy_mcc[2]);
-
   PLMN_identity_info_NB_IoT.plmn_Identity_r13.mnc.list.size=0;
   PLMN_identity_info_NB_IoT.plmn_Identity_r13.mnc.list.count=0;
-
-
 #if defined(ENABLE_ITTI)
 
   if (configuration->mnc >= 100) {
@@ -251,16 +223,12 @@ uint8_t do_SIB1_NB_IoT(uint8_t Mod_id, int CC_id,
   }
 
   //still set to "notReserved" as in the previous case
-  PLMN_identity_info_NB_IoT.cellReservedForOperatorUse_r13=PLMN_IdentityInfo_NB_r13__cellReservedForOperatorUse_r13_notReserved;
-
+  PLMN_identity_info_NB_IoT.cellReservedForOperatorUse_r13=LTE_PLMN_IdentityInfo_NB_r13__cellReservedForOperatorUse_r13_notReserved;
   *attachWithoutPDN_Connectivity = 0;
   PLMN_identity_info_NB_IoT.attachWithoutPDN_Connectivity_r13 = attachWithoutPDN_Connectivity;
-
   ASN_SEQUENCE_ADD(&(*sib1_NB_IoT)->cellAccessRelatedInfo_r13.plmn_IdentityList_r13.list,&PLMN_identity_info_NB_IoT);
-
   // 16 bits = 2 byte
   (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.buf = MALLOC(2); //MALLOC works in byte
-
   //lefts as it is?
 #if defined(ENABLE_ITTI)
   (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.buf[0] = (configuration->tac >> 8) & 0xff;
@@ -271,7 +239,6 @@ uint8_t do_SIB1_NB_IoT(uint8_t Mod_id, int CC_id,
 #endif
   (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.size=2;
   (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.bits_unused=0;
-
   // 28 bits --> i have to use 32 bits = 4 byte
   (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf = MALLOC(8); // why allocate 8 byte?
 #if defined(ENABLE_ITTI)
@@ -287,20 +254,14 @@ uint8_t do_SIB1_NB_IoT(uint8_t Mod_id, int CC_id,
 #endif
   (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.size=4;
   (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.bits_unused=4;
-
   //Still set to "notBarred" as in the previous case
-  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellBarred_r13=SystemInformationBlockType1_NB__cellAccessRelatedInfo_r13__cellBarred_r13_notBarred;
-
+  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellBarred_r13=LTE_SystemInformationBlockType1_NB__cellAccessRelatedInfo_r13__cellBarred_r13_notBarred;
   //Still Set to "notAllowed" like in the previous case
-  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.intraFreqReselection_r13=SystemInformationBlockType1_NB__cellAccessRelatedInfo_r13__intraFreqReselection_r13_notAllowed;
-
-
+  (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.intraFreqReselection_r13=LTE_SystemInformationBlockType1_NB__cellAccessRelatedInfo_r13__intraFreqReselection_r13_notAllowed;
   (*sib1_NB_IoT)->cellSelectionInfo_r13.q_RxLevMin_r13=-65; //which value?? TS 36.331 V14.2.1 pag. 589
   (*sib1_NB_IoT)->cellSelectionInfo_r13.q_QualMin_r13 = 0; //FIXME new parameter for SIB1-NB, not present in SIB1 (for cell reselection but if not used the UE should apply the default value)
-
-  (*sib1_NB_IoT)->p_Max_r13 = CALLOC(1, sizeof(P_Max_t));
+  (*sib1_NB_IoT)->p_Max_r13 = CALLOC(1, sizeof(LTE_P_Max_t));
   *((*sib1_NB_IoT)->p_Max_r13) = 23;
-
   //FIXME
   (*sib1_NB_IoT)->freqBandIndicator_r13 =
 #if defined(ENABLE_ITTI)
@@ -308,97 +269,79 @@ uint8_t do_SIB1_NB_IoT(uint8_t Mod_id, int CC_id,
 #else
     5; //if not configured we use band 5 (UL: 824 MHz - 849MHz / DL: 869 MHz - 894 MHz  FDD mode)
 #endif
-
-    //OPTIONAL new parameters, to be used?
-      /*
-       * freqBandInfo_r13
-       * multiBandInfoList_r13
-       * nrs_CRS_PowerOffset_r13
-       * sib1_NB_IoT->downlinkBitmap_r13.choice.subframePattern10_r13 =(is a BIT_STRING)
-       */
-
-
-   (*sib1_NB_IoT)->downlinkBitmap_r13 = CALLOC(1, sizeof(struct DL_Bitmap_NB_r13));
-   ((*sib1_NB_IoT)->downlinkBitmap_r13)->present= DL_Bitmap_NB_r13_PR_NOTHING;
-
-   *eutraControlRegionSize = 1;
-   (*sib1_NB_IoT)->eutraControlRegionSize_r13 = eutraControlRegionSize;
-
-
-   *nrs_CRS_PowerOffset= 0;
-   (*sib1_NB_IoT)->nrs_CRS_PowerOffset_r13 = nrs_CRS_PowerOffset;
-
-   schedulingInfo_NB_IoT = (SchedulingInfo_NB_r13_t*) malloc (3*sizeof(SchedulingInfo_NB_r13_t));
-   sib_type_NB_IoT = (SIB_Type_NB_r13_t *) malloc (3*sizeof(SIB_Type_NB_r13_t));
-
-  memset(&schedulingInfo_NB_IoT[0],0,sizeof(SchedulingInfo_NB_r13_t));
-  memset(&schedulingInfo_NB_IoT[1],0,sizeof(SchedulingInfo_NB_r13_t));
-  memset(&schedulingInfo_NB_IoT[2],0,sizeof(SchedulingInfo_NB_r13_t));    
-  memset(&sib_type_NB_IoT[0],0,sizeof(SIB_Type_NB_r13_t));
-  memset(&sib_type_NB_IoT[1],0,sizeof(SIB_Type_NB_r13_t));
-  memset(&sib_type_NB_IoT[2],0,sizeof(SIB_Type_NB_r13_t));
-
-
+  //OPTIONAL new parameters, to be used?
+  /*
+   * freqBandInfo_r13
+   * multiBandInfoList_r13
+   * nrs_CRS_PowerOffset_r13
+   * sib1_NB_IoT->downlinkBitmap_r13.choice.subframePattern10_r13 =(is a BIT_STRING)
+   */
+  (*sib1_NB_IoT)->downlinkBitmap_r13 = CALLOC(1, sizeof(struct LTE_DL_Bitmap_NB_r13));
+  ((*sib1_NB_IoT)->downlinkBitmap_r13)->present= LTE_DL_Bitmap_NB_r13_PR_NOTHING;
+  *eutraControlRegionSize = 1;
+  (*sib1_NB_IoT)->eutraControlRegionSize_r13 = eutraControlRegionSize;
+  *nrs_CRS_PowerOffset= 0;
+  (*sib1_NB_IoT)->nrs_CRS_PowerOffset_r13 = nrs_CRS_PowerOffset;
+  schedulingInfo_NB_IoT = (LTE_SchedulingInfo_NB_r13_t *) malloc (3*sizeof(LTE_SchedulingInfo_NB_r13_t));
+  sib_type_NB_IoT = (LTE_SIB_Type_NB_r13_t *) malloc (3*sizeof(LTE_SIB_Type_NB_r13_t));
+  memset(&schedulingInfo_NB_IoT[0],0,sizeof(LTE_SchedulingInfo_NB_r13_t));
+  memset(&schedulingInfo_NB_IoT[1],0,sizeof(LTE_SchedulingInfo_NB_r13_t));
+  memset(&schedulingInfo_NB_IoT[2],0,sizeof(LTE_SchedulingInfo_NB_r13_t));
+  memset(&sib_type_NB_IoT[0],0,sizeof(LTE_SIB_Type_NB_r13_t));
+  memset(&sib_type_NB_IoT[1],0,sizeof(LTE_SIB_Type_NB_r13_t));
+  memset(&sib_type_NB_IoT[2],0,sizeof(LTE_SIB_Type_NB_r13_t));
   // Now, follow the scheduler SIB configuration
   // There is only one sib2+sib3 common setting
-  schedulingInfo_NB_IoT[0].si_Periodicity_r13=SchedulingInfo_NB_r13__si_Periodicity_r13_rf4096;
-  schedulingInfo_NB_IoT[0].si_RepetitionPattern_r13=SchedulingInfo_NB_r13__si_RepetitionPattern_r13_every2ndRF; //This Indicates the starting radio frames within the SI window used for SI message transmission.
-  schedulingInfo_NB_IoT[0].si_TB_r13= SchedulingInfo_NB_r13__si_TB_r13_b680;//208 bits
-  
-
+  schedulingInfo_NB_IoT[0].si_Periodicity_r13=LTE_SchedulingInfo_NB_r13__si_Periodicity_r13_rf4096;
+  schedulingInfo_NB_IoT[0].si_RepetitionPattern_r13=
+    LTE_SchedulingInfo_NB_r13__si_RepetitionPattern_r13_every2ndRF; //This Indicates the starting radio frames within the SI window used for SI message transmission.
+  schedulingInfo_NB_IoT[0].si_TB_r13= LTE_SchedulingInfo_NB_r13__si_TB_r13_b680;//208 bits
   // This is for SIB2/3
   /*SIB3 --> There is no mapping information of SIB2 since it is always present
     *  in the first SystemInformation message
     * listed in the schedulingInfoList list.
     * */
-  sib_type_NB_IoT[0]=SIB_Type_NB_r13_sibType3_NB_r13;
-
+  sib_type_NB_IoT[0]=LTE_SIB_Type_NB_r13_sibType3_NB_r13;
   ASN_SEQUENCE_ADD(&schedulingInfo_NB_IoT[0].sib_MappingInfo_r13.list,&sib_type_NB_IoT[0]);
   ASN_SEQUENCE_ADD(&(*sib1_NB_IoT)->schedulingInfoList_r13.list,&schedulingInfo_NB_IoT[0]);
-
   //printf("[ASN Debug] SI P: %ld\n",(*sib1_NB_IoT)->schedulingInfoList_r13.list.array[0]->si_Periodicity_r13);
-
 #if defined(ENABLE_ITTI)
 
   if (configuration->frame_type == TDD)
 #endif
   {
-	//FIXME in NB-IoT mandatory to be FDD --> so must give an error
-	  LOG_E(RRC,"[NB-IoT %d] Frame Type is TDD --> not supported by NB-IoT, exiting\n", Mod_id); //correct?
-	  exit(-1);
+    //FIXME in NB-IoT mandatory to be FDD --> so must give an error
+    LOG_E(RRC,"[NB-IoT %d] Frame Type is TDD --> not supported by NB-IoT, exiting\n", Mod_id); //correct?
+    exit(-1);
   }
 
   //FIXME which value chose for the following parameter
-  (*sib1_NB_IoT)->si_WindowLength_r13=SystemInformationBlockType1_NB__si_WindowLength_r13_ms160;
+  (*sib1_NB_IoT)->si_WindowLength_r13=LTE_SystemInformationBlockType1_NB__si_WindowLength_r13_ms160;
   (*sib1_NB_IoT)->si_RadioFrameOffset_r13= 0;
-
   /*In Nb-IoT change/update of specific SI message can additionally be indicated by a SI message specific value tag
    * systemInfoValueTagSI (there is no SystemInfoValueTag in SIB1-NB but only in MIB-NB)
    *contained in systemInfoValueTagList_r13
    **/
   //FIXME correct?
-  (*sib1_NB_IoT)->systemInfoValueTagList_r13 = CALLOC(1, sizeof(struct SystemInfoValueTagList_NB_r13));
+  (*sib1_NB_IoT)->systemInfoValueTagList_r13 = CALLOC(1, sizeof(struct LTE_SystemInfoValueTagList_NB_r13));
   asn_set_empty(&(*sib1_NB_IoT)->systemInfoValueTagList_r13->list);
   ASN_SEQUENCE_ADD(&(*sib1_NB_IoT)->systemInfoValueTagList_r13->list,&systemInfoValueTagSI);
 
-
   if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-     xer_fprint(stdout, &asn_DEF_BCCH_DL_SCH_Message_NB, (void*)bcch_message);
+    xer_fprint(stdout, &asn_DEF_LTE_BCCH_DL_SCH_Message_NB, (void *)bcch_message);
   }
 
-
-  enc_rval = uper_encode_to_buffer(&asn_DEF_BCCH_DL_SCH_Message_NB,
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_BCCH_DL_SCH_Message_NB,
                                    NULL,
-                                   (void*)bcch_message,
+                                   (void *)bcch_message,
                                    carrier->SIB1_NB_IoT,
                                    100);
 
-  if (enc_rval.encoded > 0){ 
-       LOG_E(RRC,"ASN1 message encoding failed (%s, %lu)!\n",
-               enc_rval.failed_type->name, enc_rval.encoded);
+  if (enc_rval.encoded > 0) {
+    LOG_E(RRC,"ASN1 message encoding failed (%s, %lu)!\n",
+          enc_rval.failed_type->name, enc_rval.encoded);
   }
 
-
 #ifdef USER_MODE
   LOG_D(RRC,"[NB-IoT] SystemInformationBlockType1-NB Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
 #endif
@@ -415,120 +358,92 @@ uint8_t do_SIB1_NB_IoT(uint8_t Mod_id, int CC_id,
 uint8_t do_SIB23_NB_IoT(uint8_t Mod_id,
                         int CC_id,
                         rrc_eNB_carrier_data_NB_IoT_t *carrier,//MP: this is already a carrier[CC_id]
-                        NbIoTRrcConfigurationReq *configuration ) //openair2/COMMON/rrc_messages_types.h
-{
-  struct SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member *sib2_NB_part;
-  struct SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member *sib3_NB_part;
-
-  BCCH_DL_SCH_Message_NB_t *bcch_message = &(carrier->systemInformation_NB_IoT); //is the systeminformation-->BCCH_DL_SCH_Message_NB
-  SystemInformationBlockType2_NB_r13_t *sib2_NB_IoT;
-  SystemInformationBlockType3_NB_r13_t *sib3_NB_IoT;
-
+                        NbIoTRrcConfigurationReq *configuration ) { //openair2/COMMON/rrc_messages_types.h
+  struct LTE_SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member *sib2_NB_part;
+  struct LTE_SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member *sib3_NB_part;
+  LTE_BCCH_DL_SCH_Message_NB_t *bcch_message = &(carrier->systemInformation_NB_IoT); //is the systeminformation-->BCCH_DL_SCH_Message_NB
+  LTE_SystemInformationBlockType2_NB_r13_t *sib2_NB_IoT;
+  LTE_SystemInformationBlockType3_NB_r13_t *sib3_NB_IoT;
   asn_enc_rval_t enc_rval;
-  RACH_Info_NB_r13_t rach_Info_NB_IoT;
-  NPRACH_Parameters_NB_r13_t *nprach_parameters;
-
+  LTE_RACH_Info_NB_r13_t rach_Info_NB_IoT;
+  LTE_NPRACH_Parameters_NB_r13_t *nprach_parameters;
   //optional
   long *connEstFailOffset = NULL;
   connEstFailOffset = CALLOC(1, sizeof(long));
-
-//  RSRP_ThresholdsNPRACH_InfoList_NB_r13_t *rsrp_ThresholdsPrachInfoList;
-//  RSRP_Range_t rsrp_range;
-
-  ACK_NACK_NumRepetitions_NB_r13_t ack_nack_repetition;
-  struct NPUSCH_ConfigCommon_NB_r13__dmrs_Config_r13 *dmrs_config;
-  struct DL_GapConfig_NB_r13	*dl_Gap;
-
+  //  RSRP_ThresholdsNPRACH_InfoList_NB_r13_t *rsrp_ThresholdsPrachInfoList;
+  //  RSRP_Range_t rsrp_range;
+  LTE_ACK_NACK_NumRepetitions_NB_r13_t ack_nack_repetition;
+  struct LTE_NPUSCH_ConfigCommon_NB_r13__dmrs_Config_r13 *dmrs_config;
+  struct LTE_DL_GapConfig_NB_r13  *dl_Gap;
   long *srs_SubframeConfig;
   srs_SubframeConfig= CALLOC(1, sizeof(long));
 
-
   if (bcch_message) {
-    memset(bcch_message,0,sizeof(BCCH_DL_SCH_Message_NB_t));
+    memset(bcch_message,0,sizeof(LTE_BCCH_DL_SCH_Message_NB_t));
   } else {
     LOG_E(RRC,"[NB-IoT %d] BCCH_MESSAGE_NB is null, exiting\n", Mod_id);
     exit(-1);
   }
 
   //before schould be allocated memory somewhere?
-//  if (!carrier->sib2_NB_IoT) {
-//    LOG_E(RRC,"[NB-IoT %d] sib2_NB_IoT is null, exiting\n", Mod_id);
-//    exit(-1);
-//  }
-//
-//  if (!carrier->sib3_NB_IoT) {
-//    LOG_E(RRC,"[NB-IoT %d] sib3_NB_IoT is null, exiting\n", Mod_id);
-//    exit(-1);
-//  }
-
-
+  //  if (!carrier->sib2_NB_IoT) {
+  //    LOG_E(RRC,"[NB-IoT %d] sib2_NB_IoT is null, exiting\n", Mod_id);
+  //    exit(-1);
+  //  }
+  //
+  //  if (!carrier->sib3_NB_IoT) {
+  //    LOG_E(RRC,"[NB-IoT %d] sib3_NB_IoT is null, exiting\n", Mod_id);
+  //    exit(-1);
+  //  }
   LOG_I(RRC,"[NB-IoT %d] Configuration SIB2/3\n", Mod_id);
-
-  sib2_NB_part = CALLOC(1,sizeof(struct SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member));
-  sib3_NB_part = CALLOC(1,sizeof(struct SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member));
-  memset(sib2_NB_part,0,sizeof(struct SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member));
-  memset(sib3_NB_part,0,sizeof(struct SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member));
-
-  sib2_NB_part->present = SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member_PR_sib2_r13;
-  sib3_NB_part->present = SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member_PR_sib3_r13;
-
+  sib2_NB_part = CALLOC(1,sizeof(struct LTE_SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member));
+  sib3_NB_part = CALLOC(1,sizeof(struct LTE_SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member));
+  memset(sib2_NB_part,0,sizeof(struct LTE_SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member));
+  memset(sib3_NB_part,0,sizeof(struct LTE_SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member));
+  sib2_NB_part->present = LTE_SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member_PR_sib2_r13;
+  sib3_NB_part->present = LTE_SystemInformation_NB_r13_IEs__sib_TypeAndInfo_r13__Member_PR_sib3_r13;
   //may bug if not correct allocation of memory
   carrier->sib2_NB_IoT = &sib2_NB_part->choice.sib2_r13;
   carrier->sib3_NB_IoT = &sib3_NB_part->choice.sib3_r13;
   sib2_NB_IoT = carrier->sib2_NB_IoT;
   sib3_NB_IoT = carrier->sib3_NB_IoT;
-
-  nprach_parameters = (NPRACH_Parameters_NB_r13_t *) malloc (3*sizeof(NPRACH_Parameters_NB_r13_t));
-
-  memset(&nprach_parameters[0],0,sizeof(NPRACH_Parameters_NB_r13_t));
-  memset(&nprach_parameters[1],0,sizeof(NPRACH_Parameters_NB_r13_t));
-  memset(&nprach_parameters[2],0,sizeof(NPRACH_Parameters_NB_r13_t));
-
-/// SIB2-NB-----------------------------------------
-
+  nprach_parameters = (LTE_NPRACH_Parameters_NB_r13_t *) malloc (3*sizeof(LTE_NPRACH_Parameters_NB_r13_t));
+  memset(&nprach_parameters[0],0,sizeof(LTE_NPRACH_Parameters_NB_r13_t));
+  memset(&nprach_parameters[1],0,sizeof(LTE_NPRACH_Parameters_NB_r13_t));
+  memset(&nprach_parameters[2],0,sizeof(LTE_NPRACH_Parameters_NB_r13_t));
+  /// SIB2-NB-----------------------------------------
   //Barring is manage by ab-Enabled in MIB-NB (but is not a struct as ac-BarringInfo in LTE legacy)
-
   //RACH Config. Common--------------------------------------------------------------
   sib2_NB_IoT->radioResourceConfigCommon_r13.rach_ConfigCommon_r13.preambleTransMax_CE_r13 =
-   		  configuration->rach_preambleTransMax_CE_NB;
+    configuration->rach_preambleTransMax_CE_NB;
   sib2_NB_IoT->radioResourceConfigCommon_r13.rach_ConfigCommon_r13.powerRampingParameters_r13.powerRampingStep =
-	configuration->rach_powerRampingStep_NB;
+    configuration->rach_powerRampingStep_NB;
   sib2_NB_IoT->radioResourceConfigCommon_r13.rach_ConfigCommon_r13.powerRampingParameters_r13.preambleInitialReceivedTargetPower =
     configuration->rach_preambleInitialReceivedTargetPower_NB;
-
   rach_Info_NB_IoT.ra_ResponseWindowSize_r13 = configuration->rach_raResponseWindowSize_NB;
   rach_Info_NB_IoT.mac_ContentionResolutionTimer_r13 = configuration-> rach_macContentionResolutionTimer_NB;
   //rach_infoList max size = maxNPRACH-Resources-NB-r13 = 3
   ASN_SEQUENCE_ADD(&sib2_NB_IoT->radioResourceConfigCommon_r13.rach_ConfigCommon_r13.rach_InfoList_r13.list,&rach_Info_NB_IoT);
-
   //TS 36.331 pag 614 --> if not present the value to infinity sould be used
   *connEstFailOffset = 0;
-  
   sib2_NB_IoT->radioResourceConfigCommon_r13.rach_ConfigCommon_r13.connEstFailOffset_r13 = connEstFailOffset; /*OPTIONAL*/
-
-
   // BCCH-Config-NB-IoT----------------------------------------------------------------
   sib2_NB_IoT->radioResourceConfigCommon_r13.bcch_Config_r13.modificationPeriodCoeff_r13
     = configuration->bcch_modificationPeriodCoeff_NB;
-
   // PCCH-Config-NB-IoT-----------------------------------------------------------------
   sib2_NB_IoT->radioResourceConfigCommon_r13.pcch_Config_r13.defaultPagingCycle_r13
     = configuration->pcch_defaultPagingCycle_NB;
   sib2_NB_IoT->radioResourceConfigCommon_r13.pcch_Config_r13.nB_r13 = configuration->pcch_nB_NB;
   sib2_NB_IoT->radioResourceConfigCommon_r13.pcch_Config_r13.npdcch_NumRepetitionPaging_r13 = configuration-> pcch_npdcch_NumRepetitionPaging_NB;
-
   //NPRACH-Config-NB-IoT-----------------------------------------------------------------
-
-  sib2_NB_IoT->radioResourceConfigCommon_r13.nprach_Config_r13.rsrp_ThresholdsPrachInfoList_r13 = NULL; 
+  sib2_NB_IoT->radioResourceConfigCommon_r13.nprach_Config_r13.rsrp_ThresholdsPrachInfoList_r13 = NULL;
   sib2_NB_IoT->radioResourceConfigCommon_r13.nprach_Config_r13.nprach_CP_Length_r13 = configuration->nprach_CP_Length;
   /*OPTIONAL*/
-//   =CALLOC(1, sizeof(struct RSRP_ThresholdsNPRACH_InfoList_NB_r13)); //fatto uguale dopo
-//   rsrp_ThresholdsPrachInfoList = sib2_NB_IoT->radioResourceConfigCommon_r13.nprach_Config_r13.rsrp_ThresholdsPrachInfoList_r13;
-//   rsrp_range = configuration->nprach_rsrp_range_NB;
-//   ASN_SEQUENCE_ADD(&rsrp_ThresholdsPrachInfoList->list,rsrp_range);
-
+  //   =CALLOC(1, sizeof(struct RSRP_ThresholdsNPRACH_InfoList_NB_r13)); //fatto uguale dopo
+  //   rsrp_ThresholdsPrachInfoList = sib2_NB_IoT->radioResourceConfigCommon_r13.nprach_Config_r13.rsrp_ThresholdsPrachInfoList_r13;
+  //   rsrp_range = configuration->nprach_rsrp_range_NB;
+  //   ASN_SEQUENCE_ADD(&rsrp_ThresholdsPrachInfoList->list,rsrp_range);
   // According configuration to set the 3 CE level configuration setting
-
   nprach_parameters[0].nprach_Periodicity_r13               = configuration->nprach_Periodicity[0];
   nprach_parameters[0].nprach_StartTime_r13                 = configuration->nprach_StartTime[0];
   nprach_parameters[0].nprach_SubcarrierOffset_r13          = configuration->nprach_SubcarrierOffset[0];
@@ -539,7 +454,6 @@ uint8_t do_SIB23_NB_IoT(uint8_t Mod_id,
   nprach_parameters[0].npdcch_NumRepetitions_RA_r13         = configuration->npdcch_NumRepetitions_RA[0];
   nprach_parameters[0].npdcch_StartSF_CSS_RA_r13            = configuration->npdcch_StartSF_CSS_RA[0];
   nprach_parameters[0].npdcch_Offset_RA_r13                 = configuration->npdcch_Offset_RA[0];
-
   nprach_parameters[1].nprach_Periodicity_r13               = configuration->nprach_Periodicity[1];
   nprach_parameters[1].nprach_StartTime_r13                 = configuration->nprach_StartTime[1];
   nprach_parameters[1].nprach_SubcarrierOffset_r13          = configuration->nprach_SubcarrierOffset[1];
@@ -550,7 +464,6 @@ uint8_t do_SIB23_NB_IoT(uint8_t Mod_id,
   nprach_parameters[1].npdcch_NumRepetitions_RA_r13         = configuration->npdcch_NumRepetitions_RA[1];
   nprach_parameters[1].npdcch_StartSF_CSS_RA_r13            = configuration->npdcch_StartSF_CSS_RA[1];
   nprach_parameters[1].npdcch_Offset_RA_r13                 = configuration->npdcch_Offset_RA[1];
-
   nprach_parameters[2].nprach_Periodicity_r13               = configuration->nprach_Periodicity[2];
   nprach_parameters[2].nprach_StartTime_r13                 = configuration->nprach_StartTime[2];
   nprach_parameters[2].nprach_SubcarrierOffset_r13          = configuration->nprach_SubcarrierOffset[2];
@@ -561,40 +474,29 @@ uint8_t do_SIB23_NB_IoT(uint8_t Mod_id,
   nprach_parameters[2].npdcch_NumRepetitions_RA_r13         = configuration->npdcch_NumRepetitions_RA[2];
   nprach_parameters[2].npdcch_StartSF_CSS_RA_r13            = configuration->npdcch_StartSF_CSS_RA[2];
   nprach_parameters[2].npdcch_Offset_RA_r13                 = configuration->npdcch_Offset_RA[2];
-
-
   //nprach_parameterList have a max size of 3 possible nprach configuration (see maxNPRACH_Resources_NB_r13)
   ASN_SEQUENCE_ADD(&sib2_NB_IoT->radioResourceConfigCommon_r13.nprach_Config_r13.nprach_ParametersList_r13.list,&nprach_parameters[0]);
   ASN_SEQUENCE_ADD(&sib2_NB_IoT->radioResourceConfigCommon_r13.nprach_Config_r13.nprach_ParametersList_r13.list,&nprach_parameters[1]);
   ASN_SEQUENCE_ADD(&sib2_NB_IoT->radioResourceConfigCommon_r13.nprach_Config_r13.nprach_ParametersList_r13.list,&nprach_parameters[2]);
-  
   // NPDSCH-Config NB-IOT
   sib2_NB_IoT->radioResourceConfigCommon_r13.npdsch_ConfigCommon_r13.nrs_Power_r13= configuration->npdsch_nrs_Power;
-
-
   //NPUSCH-Config NB-IoT----------------------------------------------------------------
   //list of size 3 (see maxNPRACH_Resources_NB_r13)
   ack_nack_repetition = configuration-> npusch_ack_nack_numRepetitions_NB; //is an enumerative
   ASN_SEQUENCE_ADD(&(sib2_NB_IoT->radioResourceConfigCommon_r13.npusch_ConfigCommon_r13.ack_NACK_NumRepetitions_Msg4_r13.list) ,&ack_nack_repetition);
-
   *srs_SubframeConfig = configuration->npusch_srs_SubframeConfig_NB;
   sib2_NB_IoT->radioResourceConfigCommon_r13.npusch_ConfigCommon_r13.srs_SubframeConfig_r13= srs_SubframeConfig; /*OPTIONAL*/
-
-
   /*OPTIONAL*/
-  dmrs_config = CALLOC(1,sizeof(struct NPUSCH_ConfigCommon_NB_r13__dmrs_Config_r13));
+  dmrs_config = CALLOC(1,sizeof(struct LTE_NPUSCH_ConfigCommon_NB_r13__dmrs_Config_r13));
   dmrs_config->threeTone_CyclicShift_r13 = configuration->npusch_threeTone_CyclicShift_r13;
   dmrs_config->sixTone_CyclicShift_r13 = configuration->npusch_sixTone_CyclicShift_r13;
-
   /*OPTIONAL
    * -define the base sequence for a DMRS sequence in a cell with multi tone transmission (3,6,12) see TS 36.331 NPUSCH-Config-NB
    * -if not defined will be calculated based on the cellID once we configure the phy layer (rrc_mac_config_req) through the config_sib2 */
   dmrs_config->threeTone_BaseSequence_r13 = NULL;
   dmrs_config->sixTone_BaseSequence_r13 = NULL;
   dmrs_config->twelveTone_BaseSequence_r13 = NULL;
-
   sib2_NB_IoT->radioResourceConfigCommon_r13.npusch_ConfigCommon_r13.dmrs_Config_r13 = dmrs_config;
-
   //ulReferenceSignalsNPUSCH
   /*Reference Signal (RS) for UL in NB-IoT is called DRS (Demodulation Reference Signal)
    * sequence-group hopping can be enabled or disabled by means of the cell-specific parameter groupHoppingEnabled_r13
@@ -603,22 +505,17 @@ uint8_t do_SIB23_NB_IoT(uint8_t Mod_id,
    */
   sib2_NB_IoT->radioResourceConfigCommon_r13.npusch_ConfigCommon_r13.ul_ReferenceSignalsNPUSCH_r13.groupHoppingEnabled_r13= configuration->npusch_groupHoppingEnabled;
   sib2_NB_IoT->radioResourceConfigCommon_r13.npusch_ConfigCommon_r13.ul_ReferenceSignalsNPUSCH_r13.groupAssignmentNPUSCH_r13 =configuration->npusch_groupAssignmentNPUSCH_r13;
-
-
   //dl_GAP---------------------------------------------------------------------------------/*OPTIONAL*/
-  dl_Gap = CALLOC(1,sizeof(struct DL_GapConfig_NB_r13));
+  dl_Gap = CALLOC(1,sizeof(struct LTE_DL_GapConfig_NB_r13));
   dl_Gap->dl_GapDurationCoeff_r13= configuration-> dl_GapDurationCoeff_NB;
   dl_Gap->dl_GapPeriodicity_r13= configuration->dl_GapPeriodicity_NB;
   dl_Gap->dl_GapThreshold_r13= configuration->dl_GapThreshold_NB;
   sib2_NB_IoT->radioResourceConfigCommon_r13.dl_Gap_r13 = dl_Gap;
-
-
   // uplinkPowerControlCommon - NB-IoT------------------------------------------------------
   sib2_NB_IoT->radioResourceConfigCommon_r13.uplinkPowerControlCommon_r13.p0_NominalNPUSCH_r13 = configuration->npusch_p0_NominalNPUSCH;
   sib2_NB_IoT->radioResourceConfigCommon_r13.uplinkPowerControlCommon_r13.deltaPreambleMsg3_r13 = configuration->deltaPreambleMsg3;
   sib2_NB_IoT->radioResourceConfigCommon_r13.uplinkPowerControlCommon_r13.alpha_r13 = configuration->npusch_alpha;
   //no deltaFlist_PUCCH and no UL cyclic prefix
-
   // UE Timers and Constants -NB-IoT--------------------------------------------------------
   sib2_NB_IoT->ue_TimersAndConstants_r13.t300_r13 = configuration-> ue_TimersAndConstants_t300_NB;
   sib2_NB_IoT->ue_TimersAndConstants_r13.t301_r13 = configuration-> ue_TimersAndConstants_t301_NB;
@@ -626,61 +523,47 @@ uint8_t do_SIB23_NB_IoT(uint8_t Mod_id,
   sib2_NB_IoT->ue_TimersAndConstants_r13.t311_r13 = configuration-> ue_TimersAndConstants_t311_NB;
   sib2_NB_IoT->ue_TimersAndConstants_r13.n310_r13 = configuration-> ue_TimersAndConstants_n310_NB;
   sib2_NB_IoT->ue_TimersAndConstants_r13.n311_r13 = configuration-> ue_TimersAndConstants_n311_NB;
-
   //other SIB2-NB Parameters--------------------------------------------------------------------------------
   sib2_NB_IoT->freqInfo_r13.additionalSpectrumEmission_r13 = 1;
   sib2_NB_IoT->freqInfo_r13.ul_CarrierFreq_r13 = NULL; /*OPTIONAL*/
-
-  sib2_NB_IoT->timeAlignmentTimerCommon_r13=TimeAlignmentTimer_infinity;//TimeAlignmentTimer_sf5120;
-
+  sib2_NB_IoT->timeAlignmentTimerCommon_r13=LTE_TimeAlignmentTimer_infinity;//TimeAlignmentTimer_sf5120;
   /*OPTIONAL*/
   sib2_NB_IoT->multiBandInfoList_r13 = NULL;
-
-/// SIB3-NB-------------------------------------------------------
-
-  sib3_NB_IoT->cellReselectionInfoCommon_r13.q_Hyst_r13=SystemInformationBlockType3_NB_r13__cellReselectionInfoCommon_r13__q_Hyst_r13_dB4;
+  /// SIB3-NB-------------------------------------------------------
+  sib3_NB_IoT->cellReselectionInfoCommon_r13.q_Hyst_r13=LTE_SystemInformationBlockType3_NB_r13__cellReselectionInfoCommon_r13__q_Hyst_r13_dB4;
   sib3_NB_IoT->cellReselectionServingFreqInfo_r13.s_NonIntraSearch_r13=0; //or define in configuration?
-
   sib3_NB_IoT->intraFreqCellReselectionInfo_r13.q_RxLevMin_r13 = -70;
   //new
   sib3_NB_IoT->intraFreqCellReselectionInfo_r13.q_QualMin_r13 = CALLOC(1,sizeof(*sib3_NB_IoT->intraFreqCellReselectionInfo_r13.q_QualMin_r13));
   *(sib3_NB_IoT->intraFreqCellReselectionInfo_r13.q_QualMin_r13)= 10; //a caso
-
   sib3_NB_IoT->intraFreqCellReselectionInfo_r13.p_Max_r13 = NULL;
   sib3_NB_IoT->intraFreqCellReselectionInfo_r13.s_IntraSearchP_r13 = 31; // s_intraSearch --> s_intraSearchP!!! (they call in a different way)
   sib3_NB_IoT->intraFreqCellReselectionInfo_r13.t_Reselection_r13=1;
-
   //how to manage?
   sib3_NB_IoT->freqBandInfo_r13 = NULL;
   sib3_NB_IoT->multiBandInfoList_r13 = NULL;
-
-
-///BCCH message (generate the SI message)
-  bcch_message->message.present = BCCH_DL_SCH_MessageType_NB_PR_c1;
-  bcch_message->message.choice.c1.present = BCCH_DL_SCH_MessageType_NB__c1_PR_systemInformation_r13;
-
-  bcch_message->message.choice.c1.choice.systemInformation_r13.criticalExtensions.present = SystemInformation_NB__criticalExtensions_PR_systemInformation_r13;
+  ///BCCH message (generate the SI message)
+  bcch_message->message.present = LTE_BCCH_DL_SCH_MessageType_NB_PR_c1;
+  bcch_message->message.choice.c1.present = LTE_BCCH_DL_SCH_MessageType_NB__c1_PR_systemInformation_r13;
+  bcch_message->message.choice.c1.choice.systemInformation_r13.criticalExtensions.present = LTE_SystemInformation_NB__criticalExtensions_PR_systemInformation_r13;
   bcch_message->message.choice.c1.choice.systemInformation_r13.criticalExtensions.choice.systemInformation_r13.sib_TypeAndInfo_r13.list.count=0;
-
   ASN_SEQUENCE_ADD(&bcch_message->message.choice.c1.choice.systemInformation_r13.criticalExtensions.choice.systemInformation_r13.sib_TypeAndInfo_r13.list,
                    sib2_NB_part);
   ASN_SEQUENCE_ADD(&bcch_message->message.choice.c1.choice.systemInformation_r13.criticalExtensions.choice.systemInformation_r13.sib_TypeAndInfo_r13.list,
                    sib3_NB_part);
 
   if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-     xer_fprint(stdout, &asn_DEF_BCCH_DL_SCH_Message_NB, (void*)bcch_message);
+    xer_fprint(stdout, &asn_DEF_LTE_BCCH_DL_SCH_Message_NB, (void *)bcch_message);
   }
-  enc_rval = uper_encode_to_buffer(&asn_DEF_BCCH_DL_SCH_Message_NB,
+
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_BCCH_DL_SCH_Message_NB,
                                    NULL,
-                                   (void*)bcch_message,
+                                   (void *)bcch_message,
                                    carrier->SIB23_NB_IoT,
                                    900);
-//  AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
-//               enc_rval.failed_type->name, enc_rval.encoded);
-
-//#if defined(ENABLE_ITTI).....
-
-
+  //  AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
+  //               enc_rval.failed_type->name, enc_rval.encoded);
+  //#if defined(ENABLE_ITTI).....
 #ifdef USER_MODE
   LOG_D(RRC,"[NB-IoT] SystemInformation-NB Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
 #endif
@@ -692,270 +575,226 @@ uint8_t do_SIB23_NB_IoT(uint8_t Mod_id,
 
   carrier->sib2_NB_IoT = sib2_NB_IoT;
   carrier->sib3_NB_IoT = sib3_NB_IoT;
-
   return((enc_rval.encoded+7)/8);
 }
 
 /*do_RRCConnectionSetup_NB_IoT--> the aim is to establish SRB1 and SRB1bis(implicitly)*/
 uint8_t do_RRCConnectionSetup_NB_IoT(
-  const protocol_ctxt_t*     const ctxt_pP,
-  rrc_eNB_ue_context_NB_IoT_t*      const ue_context_pP,
+  const protocol_ctxt_t     *const ctxt_pP,
+  rrc_eNB_ue_context_NB_IoT_t      *const ue_context_pP,
   int                              CC_id,
-  uint8_t*                   const buffer, //Srb0.Tx_buffer.Payload
+  uint8_t                   *const buffer, //Srb0.Tx_buffer.Payload
   const uint8_t                    Transaction_id,
-  const NB_IoT_DL_FRAME_PARMS* const frame_parms, // maybe not used
-  SRB_ToAddModList_NB_r13_t**             SRB_configList_NB_IoT, //for both SRB1bis and SRB1
-  struct PhysicalConfigDedicated_NB_r13** physicalConfigDedicated_NB_IoT
+  const NB_IoT_DL_FRAME_PARMS *const frame_parms, // maybe not used
+  LTE_SRB_ToAddModList_NB_r13_t             **SRB_configList_NB_IoT, //for both SRB1bis and SRB1
+  struct LTE_PhysicalConfigDedicated_NB_r13 **physicalConfigDedicated_NB_IoT
 )
 
 {
+  asn_enc_rval_t enc_rval;
+  //MP:logical channel group not defined for Nb-IoT
+  //MP: logical channel priority pag 605 (is 1 for SRB1 and for SRB1bis should be the same)
+  //long* prioritySRB1 = NULL;
+  long *prioritySRB1bis = NULL;
+  BOOLEAN_t *logicalChannelSR_Prohibit =NULL; //pag 605
+  BOOLEAN_t *npusch_AllSymbols= NULL;
+  // struct SRB_ToAddMod_NB_r13* SRB1_config_NB = NULL;
+  // struct SRB_ToAddMod_NB_r13__rlc_Config_r13* SRB1_rlc_config_NB = NULL;
+  // struct SRB_ToAddMod_NB_r13__logicalChannelConfig_r13* SRB1_lchan_config_NB = NULL;
+  struct LTE_SRB_ToAddMod_NB_r13 *SRB1bis_config_NB_IoT = NULL;
+  struct LTE_SRB_ToAddMod_NB_r13__rlc_Config_r13 *SRB1bis_rlc_config_NB_IoT = NULL;
+  struct LTE_SRB_ToAddMod_NB_r13__logicalChannelConfig_r13 *SRB1bis_lchan_config_NB_IoT = NULL;
+  //No UL_specific parameters for NB-IoT in LogicalChanelConfig-NB
+  LTE_PhysicalConfigDedicated_NB_r13_t *physicalConfigDedicated2_NB_IoT = NULL;
+  LTE_DL_CCCH_Message_NB_t dl_ccch_msg_NB_IoT;
+  LTE_RRCConnectionSetup_NB_t *rrcConnectionSetup_NB_IoT = NULL;
+  memset((void *)&dl_ccch_msg_NB_IoT,0,sizeof(LTE_DL_CCCH_Message_NB_t));
+  dl_ccch_msg_NB_IoT.message.present = LTE_DL_CCCH_MessageType_NB_PR_c1;
+  dl_ccch_msg_NB_IoT.message.choice.c1.present = LTE_DL_CCCH_MessageType_NB__c1_PR_rrcConnectionSetup_r13;
+  rrcConnectionSetup_NB_IoT = &dl_ccch_msg_NB_IoT.message.choice.c1.choice.rrcConnectionSetup_r13;
+
+  if (*SRB_configList_NB_IoT) {
+    free(*SRB_configList_NB_IoT);
+  }
 
- asn_enc_rval_t enc_rval;
-
-
- //MP:logical channel group not defined for Nb-IoT
-
- //MP: logical channel priority pag 605 (is 1 for SRB1 and for SRB1bis should be the same)
- //long* prioritySRB1 = NULL;
- long* prioritySRB1bis = NULL;
- BOOLEAN_t* logicalChannelSR_Prohibit =NULL; //pag 605
- BOOLEAN_t* npusch_AllSymbols= NULL;
-
-// struct SRB_ToAddMod_NB_r13* SRB1_config_NB = NULL;
-// struct SRB_ToAddMod_NB_r13__rlc_Config_r13* SRB1_rlc_config_NB = NULL;
-// struct SRB_ToAddMod_NB_r13__logicalChannelConfig_r13* SRB1_lchan_config_NB = NULL;
-
- struct SRB_ToAddMod_NB_r13* SRB1bis_config_NB_IoT = NULL;
- struct SRB_ToAddMod_NB_r13__rlc_Config_r13* SRB1bis_rlc_config_NB_IoT = NULL;
- struct SRB_ToAddMod_NB_r13__logicalChannelConfig_r13* SRB1bis_lchan_config_NB_IoT = NULL;
-
- //No UL_specific parameters for NB-IoT in LogicalChanelConfig-NB
-
- PhysicalConfigDedicated_NB_r13_t* physicalConfigDedicated2_NB_IoT = NULL;
- DL_CCCH_Message_NB_t dl_ccch_msg_NB_IoT;
- RRCConnectionSetup_NB_t* rrcConnectionSetup_NB_IoT = NULL;
-
- memset((void *)&dl_ccch_msg_NB_IoT,0,sizeof(DL_CCCH_Message_NB_t));
- dl_ccch_msg_NB_IoT.message.present = DL_CCCH_MessageType_NB_PR_c1;
- dl_ccch_msg_NB_IoT.message.choice.c1.present = DL_CCCH_MessageType_NB__c1_PR_rrcConnectionSetup_r13;
- rrcConnectionSetup_NB_IoT = &dl_ccch_msg_NB_IoT.message.choice.c1.choice.rrcConnectionSetup_r13;
-
-
- if (*SRB_configList_NB_IoT) {
-   free(*SRB_configList_NB_IoT);
- }
- *SRB_configList_NB_IoT = CALLOC(1,sizeof(SRB_ToAddModList_NB_r13_t));
-
-/// SRB1--------------------
- {
-// SRB1_config_NB = CALLOC(1,sizeof(*SRB1_config_NB));
-//
-// //no srb_Identity in SRB_ToAddMod_NB
-//
-// SRB1_rlc_config_NB = CALLOC(1,sizeof(*SRB1_rlc_config_NB));
-// SRB1_config_NB->rlc_Config_r13   = SRB1_rlc_config_NB;
-//
-// SRB1_rlc_config_NB->present = SRB_ToAddMod_NB_r13__rlc_Config_r13_PR_explicitValue;
-// SRB1_rlc_config_NB->choice.explicitValue.present=RLC_Config_NB_r13_PR_am;//the only possible in NB_IoT
-//
-//// SRB1_rlc_config_NB->choice.explicitValue.choice.am.ul_AM_RLC_r13.t_PollRetransmit_r13 = enb_properties.properties[ctxt_pP->module_id]->srb1_timer_poll_retransmit_r13;
-//// SRB1_rlc_config_NB->choice.explicitValue.choice.am.ul_AM_RLC_r13.maxRetxThreshold_r13 = enb_properties.properties[ctxt_pP->module_id]->srb1_max_retx_threshold_r13;
-//// //(musT be disabled--> SRB1 config pag 640 specs )
-//// SRB1_rlc_config_NB->choice.explicitValue.choice.am.dl_AM_RLC_r13.enableStatusReportSN_Gap_r13 =NULL;
-//
-//
-// SRB1_rlc_config_NB->choice.explicitValue.choice.am.ul_AM_RLC_r13.t_PollRetransmit_r13 = T_PollRetransmit_NB_r13_ms25000;
-// SRB1_rlc_config_NB->choice.explicitValue.choice.am.ul_AM_RLC_r13.maxRetxThreshold_r13 = UL_AM_RLC_NB_r13__maxRetxThreshold_r13_t8;
-// //(musT be disabled--> SRB1 config pag 640 specs )
-// SRB1_rlc_config_NB->choice.explicitValue.choice.am.dl_AM_RLC_r13.enableStatusReportSN_Gap_r13 = NULL;
-//
-// SRB1_lchan_config_NB = CALLOC(1,sizeof(*SRB1_lchan_config_NB));
-// SRB1_config_NB->logicalChannelConfig_r13  = SRB1_lchan_config_NB;
-//
-// SRB1_lchan_config_NB->present = SRB_ToAddMod_NB_r13__logicalChannelConfig_r13_PR_explicitValue;
-//
-//
-// prioritySRB1 = CALLOC(1, sizeof(long));
-// *prioritySRB1 = 1;
-// SRB1_lchan_config_NB->choice.explicitValue.priority_r13 = prioritySRB1;
-//
-// logicalChannelSR_Prohibit = CALLOC(1, sizeof(BOOLEAN_t));
-// *logicalChannelSR_Prohibit = 1;
-// //schould be set to TRUE (specs pag 641)
-// SRB1_lchan_config_NB->choice.explicitValue.logicalChannelSR_Prohibit_r13 = logicalChannelSR_Prohibit;
-//
-// //ADD SRB1
-// ASN_SEQUENCE_ADD(&(*SRB_configList_NB_IoT)->list,SRB1_config_NB);
- }
-
-///SRB1bis (The configuration for SRB1 and SRB1bis is the same) the only difference is the logical channel identity = 3 but not set here
-
-		 SRB1bis_config_NB_IoT = CALLOC(1,sizeof(*SRB1bis_config_NB_IoT));
-
-		 //no srb_Identity in SRB_ToAddMod_NB
-		 SRB1bis_rlc_config_NB_IoT = CALLOC(1,sizeof(*SRB1bis_rlc_config_NB_IoT));
-		 SRB1bis_config_NB_IoT->rlc_Config_r13   = SRB1bis_rlc_config_NB_IoT;
-
-		 SRB1bis_rlc_config_NB_IoT->present = SRB_ToAddMod_NB_r13__rlc_Config_r13_PR_explicitValue;
-		 SRB1bis_rlc_config_NB_IoT->choice.explicitValue.present=RLC_Config_NB_r13_PR_am;//MP: the only possible RLC config in NB_IoT
-
-		 SRB1bis_rlc_config_NB_IoT->choice.explicitValue.choice.am.ul_AM_RLC_r13.t_PollRetransmit_r13 = T_PollRetransmit_NB_r13_ms25000;
-		 SRB1bis_rlc_config_NB_IoT->choice.explicitValue.choice.am.ul_AM_RLC_r13.maxRetxThreshold_r13 = UL_AM_RLC_NB_r13__maxRetxThreshold_r13_t8;
-		 //(musT be disabled--> SRB1 config pag 640 specs )
-		 SRB1bis_rlc_config_NB_IoT->choice.explicitValue.choice.am.dl_AM_RLC_r13.enableStatusReportSN_Gap_r13 =NULL;
-
-		 SRB1bis_lchan_config_NB_IoT = CALLOC(1,sizeof(*SRB1bis_lchan_config_NB_IoT));
-		 SRB1bis_config_NB_IoT->logicalChannelConfig_r13  = SRB1bis_lchan_config_NB_IoT;
-
-		 SRB1bis_lchan_config_NB_IoT->present = SRB_ToAddMod_NB_r13__logicalChannelConfig_r13_PR_explicitValue;
-
-		 prioritySRB1bis = CALLOC(1, sizeof(long));
-		 *prioritySRB1bis = 1; //same as SRB1?
-		 SRB1bis_lchan_config_NB_IoT->choice.explicitValue.priority_r13 = prioritySRB1bis;
-
-		 logicalChannelSR_Prohibit = CALLOC(1, sizeof(BOOLEAN_t));
-		 *logicalChannelSR_Prohibit = 1; //schould be set to TRUE (specs pag 641)
-		 SRB1bis_lchan_config_NB_IoT->choice.explicitValue.logicalChannelSR_Prohibit_r13 = logicalChannelSR_Prohibit;
-
-		 //ADD SRB1bis
-		 //MP: Actually there is no way to distinguish SRB1 and SRB1bis once put in the list
-		 //MP: SRB_ToAddModList_NB_r13_t size = 1
-		 ASN_SEQUENCE_ADD(&(*SRB_configList_NB_IoT)->list,SRB1bis_config_NB_IoT);
-
-
- // PhysicalConfigDedicated (NPDCCH, NPUSCH, CarrierConfig, UplinkPowerControl)
-
- physicalConfigDedicated2_NB_IoT = CALLOC(1,sizeof(*physicalConfigDedicated2_NB_IoT));
- *physicalConfigDedicated_NB_IoT = physicalConfigDedicated2_NB_IoT;
-
- physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13= CALLOC(1, sizeof(*physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13));
- physicalConfigDedicated2_NB_IoT->npdcch_ConfigDedicated_r13 = CALLOC(1,sizeof(*physicalConfigDedicated2_NB_IoT->npdcch_ConfigDedicated_r13));
- physicalConfigDedicated2_NB_IoT->npusch_ConfigDedicated_r13 = CALLOC(1,sizeof(*physicalConfigDedicated2_NB_IoT->npusch_ConfigDedicated_r13));
- physicalConfigDedicated2_NB_IoT->uplinkPowerControlDedicated_r13 = CALLOC(1,sizeof(*physicalConfigDedicated2_NB_IoT->uplinkPowerControlDedicated_r13));
-
- //no tpc, no cqi and no pucch, no pdsch, no soundingRS, no AntennaInfo, no scheduling request config
-
- /*
-  * NB-IoT supports the operation with either one or two antenna ports, AP0 and AP1.
-  * For the latter case, Space Frequency Block Coding (SFBC) is applied.
-  * Once selected, the same transmission scheme applies to NPBCH, NPDCCH, and NPDSCH.
-  * */
-
- //FIXME: MP: CarrierConfigDedicated check the set values ----------------------------------------------
-
+  *SRB_configList_NB_IoT = CALLOC(1,sizeof(LTE_SRB_ToAddModList_NB_r13_t));
+  /// SRB1--------------------
+  {
+    // SRB1_config_NB = CALLOC(1,sizeof(*SRB1_config_NB));
+    //
+    // //no srb_Identity in SRB_ToAddMod_NB
+    //
+    // SRB1_rlc_config_NB = CALLOC(1,sizeof(*SRB1_rlc_config_NB));
+    // SRB1_config_NB->rlc_Config_r13   = SRB1_rlc_config_NB;
+    //
+    // SRB1_rlc_config_NB->present = SRB_ToAddMod_NB_r13__rlc_Config_r13_PR_explicitValue;
+    // SRB1_rlc_config_NB->choice.explicitValue.present=RLC_Config_NB_r13_PR_am;//the only possible in NB_IoT
+    //
+    //// SRB1_rlc_config_NB->choice.explicitValue.choice.am.ul_AM_RLC_r13.t_PollRetransmit_r13 = enb_properties.properties[ctxt_pP->module_id]->srb1_timer_poll_retransmit_r13;
+    //// SRB1_rlc_config_NB->choice.explicitValue.choice.am.ul_AM_RLC_r13.maxRetxThreshold_r13 = enb_properties.properties[ctxt_pP->module_id]->srb1_max_retx_threshold_r13;
+    //// //(musT be disabled--> SRB1 config pag 640 specs )
+    //// SRB1_rlc_config_NB->choice.explicitValue.choice.am.dl_AM_RLC_r13.enableStatusReportSN_Gap_r13 =NULL;
+    //
+    //
+    // SRB1_rlc_config_NB->choice.explicitValue.choice.am.ul_AM_RLC_r13.t_PollRetransmit_r13 = T_PollRetransmit_NB_r13_ms25000;
+    // SRB1_rlc_config_NB->choice.explicitValue.choice.am.ul_AM_RLC_r13.maxRetxThreshold_r13 = UL_AM_RLC_NB_r13__maxRetxThreshold_r13_t8;
+    // //(musT be disabled--> SRB1 config pag 640 specs )
+    // SRB1_rlc_config_NB->choice.explicitValue.choice.am.dl_AM_RLC_r13.enableStatusReportSN_Gap_r13 = NULL;
+    //
+    // SRB1_lchan_config_NB = CALLOC(1,sizeof(*SRB1_lchan_config_NB));
+    // SRB1_config_NB->logicalChannelConfig_r13  = SRB1_lchan_config_NB;
+    //
+    // SRB1_lchan_config_NB->present = SRB_ToAddMod_NB_r13__logicalChannelConfig_r13_PR_explicitValue;
+    //
+    //
+    // prioritySRB1 = CALLOC(1, sizeof(long));
+    // *prioritySRB1 = 1;
+    // SRB1_lchan_config_NB->choice.explicitValue.priority_r13 = prioritySRB1;
+    //
+    // logicalChannelSR_Prohibit = CALLOC(1, sizeof(BOOLEAN_t));
+    // *logicalChannelSR_Prohibit = 1;
+    // //schould be set to TRUE (specs pag 641)
+    // SRB1_lchan_config_NB->choice.explicitValue.logicalChannelSR_Prohibit_r13 = logicalChannelSR_Prohibit;
+    //
+    // //ADD SRB1
+    // ASN_SEQUENCE_ADD(&(*SRB_configList_NB_IoT)->list,SRB1_config_NB);
+  }
+  ///SRB1bis (The configuration for SRB1 and SRB1bis is the same) the only difference is the logical channel identity = 3 but not set here
+  SRB1bis_config_NB_IoT = CALLOC(1,sizeof(*SRB1bis_config_NB_IoT));
+  //no srb_Identity in SRB_ToAddMod_NB
+  SRB1bis_rlc_config_NB_IoT = CALLOC(1,sizeof(*SRB1bis_rlc_config_NB_IoT));
+  SRB1bis_config_NB_IoT->rlc_Config_r13   = SRB1bis_rlc_config_NB_IoT;
+  SRB1bis_rlc_config_NB_IoT->present = LTE_SRB_ToAddMod_NB_r13__rlc_Config_r13_PR_explicitValue;
+  SRB1bis_rlc_config_NB_IoT->choice.explicitValue.present=LTE_RLC_Config_NB_r13_PR_am;//MP: the only possible RLC config in NB_IoT
+  SRB1bis_rlc_config_NB_IoT->choice.explicitValue.choice.am.ul_AM_RLC_r13.t_PollRetransmit_r13 = LTE_T_PollRetransmit_NB_r13_ms25000;
+  SRB1bis_rlc_config_NB_IoT->choice.explicitValue.choice.am.ul_AM_RLC_r13.maxRetxThreshold_r13 = LTE_UL_AM_RLC_NB_r13__maxRetxThreshold_r13_t8;
+  //(musT be disabled--> SRB1 config pag 640 specs )
+  SRB1bis_rlc_config_NB_IoT->choice.explicitValue.choice.am.dl_AM_RLC_r13.enableStatusReportSN_Gap_r13 =NULL;
+  SRB1bis_lchan_config_NB_IoT = CALLOC(1,sizeof(*SRB1bis_lchan_config_NB_IoT));
+  SRB1bis_config_NB_IoT->logicalChannelConfig_r13  = SRB1bis_lchan_config_NB_IoT;
+  SRB1bis_lchan_config_NB_IoT->present = LTE_SRB_ToAddMod_NB_r13__logicalChannelConfig_r13_PR_explicitValue;
+  prioritySRB1bis = CALLOC(1, sizeof(long));
+  *prioritySRB1bis = 1; //same as SRB1?
+  SRB1bis_lchan_config_NB_IoT->choice.explicitValue.priority_r13 = prioritySRB1bis;
+  logicalChannelSR_Prohibit = CALLOC(1, sizeof(BOOLEAN_t));
+  *logicalChannelSR_Prohibit = 1; //schould be set to TRUE (specs pag 641)
+  SRB1bis_lchan_config_NB_IoT->choice.explicitValue.logicalChannelSR_Prohibit_r13 = logicalChannelSR_Prohibit;
+  //ADD SRB1bis
+  //MP: Actually there is no way to distinguish SRB1 and SRB1bis once put in the list
+  //MP: SRB_ToAddModList_NB_r13_t size = 1
+  ASN_SEQUENCE_ADD(&(*SRB_configList_NB_IoT)->list,SRB1bis_config_NB_IoT);
+  // PhysicalConfigDedicated (NPDCCH, NPUSCH, CarrierConfig, UplinkPowerControl)
+  physicalConfigDedicated2_NB_IoT = CALLOC(1,sizeof(*physicalConfigDedicated2_NB_IoT));
+  *physicalConfigDedicated_NB_IoT = physicalConfigDedicated2_NB_IoT;
+  physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13= CALLOC(1, sizeof(*physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13));
+  physicalConfigDedicated2_NB_IoT->npdcch_ConfigDedicated_r13 = CALLOC(1,sizeof(*physicalConfigDedicated2_NB_IoT->npdcch_ConfigDedicated_r13));
+  physicalConfigDedicated2_NB_IoT->npusch_ConfigDedicated_r13 = CALLOC(1,sizeof(*physicalConfigDedicated2_NB_IoT->npusch_ConfigDedicated_r13));
+  physicalConfigDedicated2_NB_IoT->uplinkPowerControlDedicated_r13 = CALLOC(1,sizeof(*physicalConfigDedicated2_NB_IoT->uplinkPowerControlDedicated_r13));
+  //no tpc, no cqi and no pucch, no pdsch, no soundingRS, no AntennaInfo, no scheduling request config
+  /*
+   * NB-IoT supports the operation with either one or two antenna ports, AP0 and AP1.
+   * For the latter case, Space Frequency Block Coding (SFBC) is applied.
+   * Once selected, the same transmission scheme applies to NPBCH, NPDCCH, and NPDSCH.
+   * */
+  //FIXME: MP: CarrierConfigDedicated check the set values ----------------------------------------------
   //DL
+  physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.dl_CarrierFreq_r13.carrierFreq_r13=0;//random value set
+  physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.downlinkBitmapNonAnchor_r13= CALLOC(1,
+      sizeof(struct LTE_DL_CarrierConfigDedicated_NB_r13__downlinkBitmapNonAnchor_r13));
+  physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.downlinkBitmapNonAnchor_r13->present=
+    LTE_DL_CarrierConfigDedicated_NB_r13__downlinkBitmapNonAnchor_r13_PR_useNoBitmap_r13;
+  physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.dl_GapNonAnchor_r13 = CALLOC(1,sizeof(struct LTE_DL_CarrierConfigDedicated_NB_r13__dl_GapNonAnchor_r13));
+  physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.dl_GapNonAnchor_r13->present =
+    LTE_DL_CarrierConfigDedicated_NB_r13__dl_GapNonAnchor_r13_PR_useNoGap_r13;
+  physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.inbandCarrierInfo_r13= NULL;
+  //UL
+  physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->ul_CarrierConfig_r13.ul_CarrierFreq_r13= NULL;
+  // NPDCCH
+  physicalConfigDedicated2_NB_IoT->npdcch_ConfigDedicated_r13->npdcch_NumRepetitions_r13 =0;
+  physicalConfigDedicated2_NB_IoT->npdcch_ConfigDedicated_r13->npdcch_Offset_USS_r13 =0;
+  physicalConfigDedicated2_NB_IoT->npdcch_ConfigDedicated_r13->npdcch_StartSF_USS_r13=0;
+  // NPUSCH //(specs TS 36.331 v14.2.1 pag 643) /* OPTIONAL */
+  physicalConfigDedicated2_NB_IoT->npusch_ConfigDedicated_r13->ack_NACK_NumRepetitions_r13= NULL;
+  npusch_AllSymbols= CALLOC(1, sizeof(BOOLEAN_t));
+  *npusch_AllSymbols= 1; //TRUE
+  physicalConfigDedicated2_NB_IoT->npusch_ConfigDedicated_r13->npusch_AllSymbols_r13= npusch_AllSymbols; /* OPTIONAL */
+  physicalConfigDedicated2_NB_IoT->npusch_ConfigDedicated_r13->groupHoppingDisabled_r13=NULL; /* OPTIONAL */
+  // UplinkPowerControlDedicated
+  physicalConfigDedicated2_NB_IoT->uplinkPowerControlDedicated_r13->p0_UE_NPUSCH_r13 = 0; // 0 dB (specs TS36.331 v14.2.1 pag 643)
+  //Fill the rrcConnectionSetup-NB message
+  rrcConnectionSetup_NB_IoT->rrc_TransactionIdentifier = Transaction_id; //input value
+  rrcConnectionSetup_NB_IoT->criticalExtensions.present = LTE_RRCConnectionSetup_NB__criticalExtensions_PR_c1;
+  rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.present =LTE_RRCConnectionSetup_NB__criticalExtensions__c1_PR_rrcConnectionSetup_r13 ;
+  //MP: carry only SRB1bis at the moment and phyConfigDedicated
+  rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r13.radioResourceConfigDedicated_r13.srb_ToAddModList_r13 = *SRB_configList_NB_IoT;
+  rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r13.radioResourceConfigDedicated_r13.drb_ToAddModList_r13 = NULL;
+  rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r13.radioResourceConfigDedicated_r13.drb_ToReleaseList_r13 = NULL;
+  rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r13.radioResourceConfigDedicated_r13.rlf_TimersAndConstants_r13 = NULL;
+  rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r13.radioResourceConfigDedicated_r13.physicalConfigDedicated_r13 = physicalConfigDedicated2_NB_IoT;
+  rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r13.radioResourceConfigDedicated_r13.mac_MainConfig_r13 = NULL;
 
- physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.dl_CarrierFreq_r13.carrierFreq_r13=0;//random value set
- physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.downlinkBitmapNonAnchor_r13= CALLOC(1,sizeof(struct DL_CarrierConfigDedicated_NB_r13__downlinkBitmapNonAnchor_r13));
-		 physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.downlinkBitmapNonAnchor_r13->present=
-				 	 	 	 	 	 	 	 	 DL_CarrierConfigDedicated_NB_r13__downlinkBitmapNonAnchor_r13_PR_useNoBitmap_r13;
-
- physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.dl_GapNonAnchor_r13 = CALLOC(1,sizeof(struct DL_CarrierConfigDedicated_NB_r13__dl_GapNonAnchor_r13));
- physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.dl_GapNonAnchor_r13->present =
-		  	  	  	  	  	  	  	  	  	  	  DL_CarrierConfigDedicated_NB_r13__dl_GapNonAnchor_r13_PR_useNoGap_r13;
+  if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
+    xer_fprint(stdout, &asn_DEF_LTE_DL_CCCH_Message_NB, (void *)&dl_ccch_msg_NB_IoT);
+  }
 
- physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->dl_CarrierConfig_r13.inbandCarrierInfo_r13= NULL;
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_DL_CCCH_Message_NB,
+                                   NULL,
+                                   (void *)&dl_ccch_msg_NB_IoT,
+                                   buffer,
+                                   100);
 
-  //UL
- physicalConfigDedicated2_NB_IoT->carrierConfigDedicated_r13->ul_CarrierConfig_r13.ul_CarrierFreq_r13= NULL;
-
- // NPDCCH
- physicalConfigDedicated2_NB_IoT->npdcch_ConfigDedicated_r13->npdcch_NumRepetitions_r13 =0;
- physicalConfigDedicated2_NB_IoT->npdcch_ConfigDedicated_r13->npdcch_Offset_USS_r13 =0;
- physicalConfigDedicated2_NB_IoT->npdcch_ConfigDedicated_r13->npdcch_StartSF_USS_r13=0;
-
- // NPUSCH //(specs TS 36.331 v14.2.1 pag 643) /* OPTIONAL */
- physicalConfigDedicated2_NB_IoT->npusch_ConfigDedicated_r13->ack_NACK_NumRepetitions_r13= NULL;
- npusch_AllSymbols= CALLOC(1, sizeof(BOOLEAN_t));
- *npusch_AllSymbols= 1; //TRUE
- physicalConfigDedicated2_NB_IoT->npusch_ConfigDedicated_r13->npusch_AllSymbols_r13= npusch_AllSymbols; /* OPTIONAL */
- physicalConfigDedicated2_NB_IoT->npusch_ConfigDedicated_r13->groupHoppingDisabled_r13=NULL; /* OPTIONAL */
-
- // UplinkPowerControlDedicated
- physicalConfigDedicated2_NB_IoT->uplinkPowerControlDedicated_r13->p0_UE_NPUSCH_r13 = 0; // 0 dB (specs TS36.331 v14.2.1 pag 643)
-
-
- //Fill the rrcConnectionSetup-NB message
- rrcConnectionSetup_NB_IoT->rrc_TransactionIdentifier = Transaction_id; //input value
- rrcConnectionSetup_NB_IoT->criticalExtensions.present = RRCConnectionSetup_NB__criticalExtensions_PR_c1;
- rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.present =RRCConnectionSetup_NB__criticalExtensions__c1_PR_rrcConnectionSetup_r13 ;
- //MP: carry only SRB1bis at the moment and phyConfigDedicated
- rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r13.radioResourceConfigDedicated_r13.srb_ToAddModList_r13 = *SRB_configList_NB_IoT;
- rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r13.radioResourceConfigDedicated_r13.drb_ToAddModList_r13 = NULL;
- rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r13.radioResourceConfigDedicated_r13.drb_ToReleaseList_r13 = NULL;
- rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r13.radioResourceConfigDedicated_r13.rlf_TimersAndConstants_r13 = NULL;
- rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r13.radioResourceConfigDedicated_r13.physicalConfigDedicated_r13 = physicalConfigDedicated2_NB_IoT;
- rrcConnectionSetup_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r13.radioResourceConfigDedicated_r13.mac_MainConfig_r13 = NULL;
-
- if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-    xer_fprint(stdout, &asn_DEF_DL_CCCH_Message_NB, (void*)&dl_ccch_msg_NB_IoT);
- }
- enc_rval = uper_encode_to_buffer(&asn_DEF_DL_CCCH_Message_NB,
-                                  NULL,
-                                  (void*)&dl_ccch_msg_NB_IoT,
-                                  buffer,
-                                  100);
-
- if (enc_rval.encoded <= 0) {
-     LOG_E(RRC, "ASN1 message encoding failed (%s, %lu)!\n",
-              enc_rval.failed_type->name, enc_rval.encoded);
- }
+  if (enc_rval.encoded <= 0) {
+    LOG_E(RRC, "ASN1 message encoding failed (%s, %lu)!\n",
+          enc_rval.failed_type->name, enc_rval.encoded);
+  }
 
 #ifdef USER_MODE
- LOG_D(RRC,"RRCConnectionSetup-NB Encoded %zd bits (%zd bytes), ecause %d\n",
-       enc_rval.encoded,(enc_rval.encoded+7)/8,ecause);
+  LOG_D(RRC,"RRCConnectionSetup-NB Encoded %zd bits (%zd bytes), ecause %d\n",
+        enc_rval.encoded,(enc_rval.encoded+7)/8,ecause);
 #endif
-
- return((enc_rval.encoded+7)/8);
+  return((enc_rval.encoded+7)/8);
 }
 
 /*do_SecurityModeCommand - exactly the same as previous implementation*/
 uint8_t do_SecurityModeCommand_NB_IoT(
-  const protocol_ctxt_t* const ctxt_pP,
-  uint8_t* const buffer,
+  const protocol_ctxt_t *const ctxt_pP,
+  uint8_t *const buffer,
   const uint8_t Transaction_id,
   const uint8_t cipheringAlgorithm,
-  const uint8_t integrityProtAlgorithm)
-{
-  DL_DCCH_Message_NB_t dl_dcch_msg_NB_IoT;
+  const uint8_t integrityProtAlgorithm) {
+  LTE_DL_DCCH_Message_NB_t dl_dcch_msg_NB_IoT;
   asn_enc_rval_t enc_rval;
-
-  memset(&dl_dcch_msg_NB_IoT,0,sizeof(DL_DCCH_Message_NB_t));
-
-  dl_dcch_msg_NB_IoT.message.present = DL_DCCH_MessageType_NB_PR_c1;
-  dl_dcch_msg_NB_IoT.message.choice.c1.present = DL_DCCH_MessageType_NB__c1_PR_securityModeCommand_r13;
-
+  memset(&dl_dcch_msg_NB_IoT,0,sizeof(LTE_DL_DCCH_Message_NB_t));
+  dl_dcch_msg_NB_IoT.message.present = LTE_DL_DCCH_MessageType_NB_PR_c1;
+  dl_dcch_msg_NB_IoT.message.choice.c1.present = LTE_DL_DCCH_MessageType_NB__c1_PR_securityModeCommand_r13;
   dl_dcch_msg_NB_IoT.message.choice.c1.choice.securityModeCommand_r13.rrc_TransactionIdentifier = Transaction_id;
-  dl_dcch_msg_NB_IoT.message.choice.c1.choice.securityModeCommand_r13.criticalExtensions.present = SecurityModeCommand__criticalExtensions_PR_c1;
-
+  dl_dcch_msg_NB_IoT.message.choice.c1.choice.securityModeCommand_r13.criticalExtensions.present = LTE_SecurityModeCommand__criticalExtensions_PR_c1;
   dl_dcch_msg_NB_IoT.message.choice.c1.choice.securityModeCommand_r13.criticalExtensions.choice.c1.present =
-		  SecurityModeCommand__criticalExtensions__c1_PR_securityModeCommand_r8;
-
+    LTE_SecurityModeCommand__criticalExtensions__c1_PR_securityModeCommand_r8;
   // the two following information could be based on the mod_id
   dl_dcch_msg_NB_IoT.message.choice.c1.choice.securityModeCommand_r13.criticalExtensions.choice.c1.choice.securityModeCommand_r8.securityConfigSMC.securityAlgorithmConfig.cipheringAlgorithm
-    = (CipheringAlgorithm_r12_t)cipheringAlgorithm; //bug solved
-
+    = (LTE_CipheringAlgorithm_r12_t)cipheringAlgorithm; //bug solved
   dl_dcch_msg_NB_IoT.message.choice.c1.choice.securityModeCommand_r13.criticalExtensions.choice.c1.choice.securityModeCommand_r8.securityConfigSMC.securityAlgorithmConfig.integrityProtAlgorithm
-    = (e_SecurityAlgorithmConfig__integrityProtAlgorithm)integrityProtAlgorithm;
+    = (e_LTE_SecurityAlgorithmConfig__integrityProtAlgorithm)integrityProtAlgorithm;
 
-//only changed "asn_DEF_DL_DCCH_Message_NB"
+  //only changed "asn_DEF_DL_DCCH_Message_NB"
   if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-     xer_fprint(stdout, &asn_DEF_DL_DCCH_Message_NB, (void*)&dl_dcch_msg_NB_IoT);
+    xer_fprint(stdout, &asn_DEF_LTE_DL_DCCH_Message_NB, (void *)&dl_dcch_msg_NB_IoT);
   }
-  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_DCCH_Message_NB,
+
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_DL_DCCH_Message_NB,
                                    NULL,
-                                   (void*)&dl_dcch_msg_NB_IoT,
+                                   (void *)&dl_dcch_msg_NB_IoT,
                                    buffer,
                                    100);
+
   if (enc_rval.encoded <= 0) {
-      LOG_E(RRC, "ASN1 message encoding failed (%s, %lu)!\n",
-               enc_rval.failed_type->name, enc_rval.encoded);
+    LOG_E(RRC, "ASN1 message encoding failed (%s, %lu)!\n",
+          enc_rval.failed_type->name, enc_rval.encoded);
   }
 
-
-//#if defined(ENABLE_ITTI)
-//# if !defined(DISABLE_XER_SPRINT)....
-
+  //#if defined(ENABLE_ITTI)
+  //# if !defined(DISABLE_XER_SPRINT)....
 #ifdef USER_MODE
   LOG_D(RRC,"[NB-IoT %d] securityModeCommand-NB for UE %x Encoded %zd bits (%zd bytes)\n",
         ctxt_pP->module_id,
@@ -976,47 +815,43 @@ uint8_t do_SecurityModeCommand_NB_IoT(
 
 /*do_UECapabilityEnquiry_NB_IoT - very similar to legacy lte*/
 uint8_t do_UECapabilityEnquiry_NB_IoT(
-  const protocol_ctxt_t* const ctxt_pP,
-  uint8_t*               const buffer,
+  const protocol_ctxt_t *const ctxt_pP,
+  uint8_t               *const buffer,
   const uint8_t                Transaction_id
 )
 
 {
-
-  DL_DCCH_Message_NB_t dl_dcch_msg_NB_IoT;
+  LTE_DL_DCCH_Message_NB_t dl_dcch_msg_NB_IoT;
   //no RAT type in NB-IoT
   asn_enc_rval_t enc_rval;
-
-  memset(&dl_dcch_msg_NB_IoT,0,sizeof(DL_DCCH_Message_NB_t));
-
-  dl_dcch_msg_NB_IoT.message.present           = DL_DCCH_MessageType_NB_PR_c1;
-  dl_dcch_msg_NB_IoT.message.choice.c1.present = DL_DCCH_MessageType_NB__c1_PR_ueCapabilityEnquiry_r13;
-
+  memset(&dl_dcch_msg_NB_IoT,0,sizeof(LTE_DL_DCCH_Message_NB_t));
+  dl_dcch_msg_NB_IoT.message.present           = LTE_DL_DCCH_MessageType_NB_PR_c1;
+  dl_dcch_msg_NB_IoT.message.choice.c1.present = LTE_DL_DCCH_MessageType_NB__c1_PR_ueCapabilityEnquiry_r13;
   dl_dcch_msg_NB_IoT.message.choice.c1.choice.ueCapabilityEnquiry_r13.rrc_TransactionIdentifier = Transaction_id;
-
-  dl_dcch_msg_NB_IoT.message.choice.c1.choice.ueCapabilityEnquiry_r13.criticalExtensions.present = UECapabilityEnquiry_NB__criticalExtensions_PR_c1;
+  dl_dcch_msg_NB_IoT.message.choice.c1.choice.ueCapabilityEnquiry_r13.criticalExtensions.present = LTE_UECapabilityEnquiry_NB__criticalExtensions_PR_c1;
   dl_dcch_msg_NB_IoT.message.choice.c1.choice.ueCapabilityEnquiry_r13.criticalExtensions.choice.c1.present =
-		  UECapabilityEnquiry_NB__criticalExtensions__c1_PR_ueCapabilityEnquiry_r13;
+    LTE_UECapabilityEnquiry_NB__criticalExtensions__c1_PR_ueCapabilityEnquiry_r13;
 
   //no ue_CapabilityRequest (list of RAT_Type)
 
-//only changed "asn_DEF_DL_DCCH_Message_NB"
+  //only changed "asn_DEF_DL_DCCH_Message_NB"
   if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-     xer_fprint(stdout, &asn_DEF_DL_DCCH_Message_NB, (void*)&dl_dcch_msg_NB_IoT);
+    xer_fprint(stdout, &asn_DEF_LTE_DL_DCCH_Message_NB, (void *)&dl_dcch_msg_NB_IoT);
   }
-  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_DCCH_Message_NB,
+
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_DL_DCCH_Message_NB,
                                    NULL,
-                                   (void*)&dl_dcch_msg_NB_IoT,
+                                   (void *)&dl_dcch_msg_NB_IoT,
                                    buffer,
                                    100);
-  if (enc_rval.encoded <= 0) {
-     LOG_E(RRC, "ASN1 message encoding failed (%s, %lu)!\n",
-               enc_rval.failed_type->name, enc_rval.encoded);
-    }
 
-//#if defined(ENABLE_ITTI)
-//# if !defined(DISABLE_XER_SPRINT)....
+  if (enc_rval.encoded <= 0) {
+    LOG_E(RRC, "ASN1 message encoding failed (%s, %lu)!\n",
+          enc_rval.failed_type->name, enc_rval.encoded);
+  }
 
+  //#if defined(ENABLE_ITTI)
+  //# if !defined(DISABLE_XER_SPRINT)....
 #ifdef USER_MODE
   LOG_D(RRC,"[NB-IoT %d] UECapabilityEnquiry-NB for UE %x Encoded %zd bits (%zd bytes)\n",
         ctxt_pP->module_id,
@@ -1039,39 +874,32 @@ uint8_t do_UECapabilityEnquiry_NB_IoT(
  * (including RBs, MAC main configuration and physical channel configuration)
  * including any associated dedicated NAS information.*/
 uint16_t do_RRCConnectionReconfiguration_NB_IoT(
-  const protocol_ctxt_t*        const ctxt_pP,
-    uint8_t                            *buffer,
-    uint8_t                             Transaction_id,
-    SRB_ToAddModList_NB_r13_t          *SRB1_list_NB, //SRB_ConfigList2 (default)--> only SRB1
-    DRB_ToAddModList_NB_r13_t          *DRB_list_NB_IoT, //DRB_ConfigList (default)
-    DRB_ToReleaseList_NB_r13_t         *DRB_list2_NB_IoT, //is NULL when passed
-    struct PhysicalConfigDedicated_NB_r13     *physicalConfigDedicated_NB_IoT,
-	MAC_MainConfig_NB_r13_t                   *mac_MainConfig_NB_IoT,
-  struct RRCConnectionReconfiguration_NB_r13_IEs__dedicatedInfoNASList_r13* dedicatedInfoNASList_NB_IoT)
+  const protocol_ctxt_t        *const ctxt_pP,
+  uint8_t                            *buffer,
+  uint8_t                             Transaction_id,
+  LTE_SRB_ToAddModList_NB_r13_t          *SRB1_list_NB, //SRB_ConfigList2 (default)--> only SRB1
+  LTE_DRB_ToAddModList_NB_r13_t          *DRB_list_NB_IoT, //DRB_ConfigList (default)
+  LTE_DRB_ToReleaseList_NB_r13_t         *DRB_list2_NB_IoT, //is NULL when passed
+  struct LTE_PhysicalConfigDedicated_NB_r13     *physicalConfigDedicated_NB_IoT,
+  LTE_MAC_MainConfig_NB_r13_t                   *mac_MainConfig_NB_IoT,
+  struct LTE_RRCConnectionReconfiguration_NB_r13_IEs__dedicatedInfoNASList_r13 *dedicatedInfoNASList_NB_IoT)
 
 {
-
- //check on DRB_list if contains more than 2 DRB?
-
+  //check on DRB_list if contains more than 2 DRB?
   asn_enc_rval_t enc_rval;
-  DL_DCCH_Message_NB_t dl_dcch_msg_NB_IoT;
-  RRCConnectionReconfiguration_NB_t *rrcConnectionReconfiguration_NB;
-
-
-  memset(&dl_dcch_msg_NB_IoT,0,sizeof(DL_DCCH_Message_NB_t));
-
-  dl_dcch_msg_NB_IoT.message.present           = DL_DCCH_MessageType_NB_PR_c1;
-  dl_dcch_msg_NB_IoT.message.choice.c1.present = DL_DCCH_MessageType_NB__c1_PR_rrcConnectionReconfiguration_r13;
+  LTE_DL_DCCH_Message_NB_t dl_dcch_msg_NB_IoT;
+  LTE_RRCConnectionReconfiguration_NB_t *rrcConnectionReconfiguration_NB;
+  memset(&dl_dcch_msg_NB_IoT,0,sizeof(LTE_DL_DCCH_Message_NB_t));
+  dl_dcch_msg_NB_IoT.message.present           = LTE_DL_DCCH_MessageType_NB_PR_c1;
+  dl_dcch_msg_NB_IoT.message.choice.c1.present = LTE_DL_DCCH_MessageType_NB__c1_PR_rrcConnectionReconfiguration_r13;
   rrcConnectionReconfiguration_NB          = &dl_dcch_msg_NB_IoT.message.choice.c1.choice.rrcConnectionReconfiguration_r13;
-
   // RRCConnectionReconfiguration
   rrcConnectionReconfiguration_NB->rrc_TransactionIdentifier = Transaction_id;
-  rrcConnectionReconfiguration_NB->criticalExtensions.present = RRCConnectionReconfiguration_NB__criticalExtensions_PR_c1;
-  rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.present =RRCConnectionReconfiguration_NB__criticalExtensions__c1_PR_rrcConnectionReconfiguration_r13 ;
-
+  rrcConnectionReconfiguration_NB->criticalExtensions.present = LTE_RRCConnectionReconfiguration_NB__criticalExtensions_PR_c1;
+  rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.present =LTE_RRCConnectionReconfiguration_NB__criticalExtensions__c1_PR_rrcConnectionReconfiguration_r13 ;
   //RAdioResourceconfigDedicated
   rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13 =
-		  CALLOC(1,sizeof(*rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13));
+    CALLOC(1,sizeof(*rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13));
   rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->srb_ToAddModList_r13 = SRB1_list_NB; //only SRB1
   rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->drb_ToAddModList_r13 = DRB_list_NB_IoT;
   rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->drb_ToReleaseList_r13 = DRB_list2_NB_IoT; //NULL
@@ -1081,176 +909,126 @@ uint16_t do_RRCConnectionReconfiguration_NB_IoT(
 
   if (mac_MainConfig_NB_IoT!=NULL) {
     rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->mac_MainConfig_r13 =
-    		CALLOC(1, sizeof(*rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->mac_MainConfig_r13));
+      CALLOC(1, sizeof(*rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->mac_MainConfig_r13));
     rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->mac_MainConfig_r13->present
-      =RadioResourceConfigDedicated_NB_r13__mac_MainConfig_r13_PR_explicitValue_r13;
-   //why memcopy only this one?
+      =LTE_RadioResourceConfigDedicated_NB_r13__mac_MainConfig_r13_PR_explicitValue_r13;
+    //why memcopy only this one?
     memcpy(&rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->mac_MainConfig_r13->choice.explicitValue_r13,
            mac_MainConfig_NB_IoT, sizeof(*mac_MainConfig_NB_IoT));
-
   } else {
-	  rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->mac_MainConfig_r13=NULL;
+    rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.radioResourceConfigDedicated_r13->mac_MainConfig_r13=NULL;
   }
 
   //no measConfig, measIDlist
   //no mobilityControlInfo
-
   rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.dedicatedInfoNASList_r13 = dedicatedInfoNASList_NB_IoT;
   //mainly used for cell-reselection/handover purposes??
   rrcConnectionReconfiguration_NB->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r13.fullConfig_r13 = NULL;
-
-  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_DCCH_Message_NB,
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_DL_DCCH_Message_NB,
                                    NULL,
-                                   (void*)&dl_dcch_msg_NB_IoT,
+                                   (void *)&dl_dcch_msg_NB_IoT,
                                    buffer,
                                    RRC_BUF_SIZE);
+
   if (enc_rval.encoded <= 0) {
-     LOG_E(RRC, "ASN1 message encoding failed %s, %li\n",
-               enc_rval.failed_type->name, enc_rval.encoded);
+    LOG_E(RRC, "ASN1 message encoding failed %s, %li\n",
+          enc_rval.failed_type->name, enc_rval.encoded);
   }
 
   //changed only asn_DEF_DL_DCCH_Message_NB
   if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-     xer_fprint(stdout,&asn_DEF_DL_DCCH_Message_NB,(void*)&dl_dcch_msg_NB_IoT);
+    xer_fprint(stdout,&asn_DEF_LTE_DL_DCCH_Message_NB,(void *)&dl_dcch_msg_NB_IoT);
   }
 
-//#if defined(ENABLE_ITTI)
-//# if !defined(DISABLE_XER_SPRINT)...
-
-
+  //#if defined(ENABLE_ITTI)
+  //# if !defined(DISABLE_XER_SPRINT)...
   LOG_I(RRC,"RRCConnectionReconfiguration-NB Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
-
   return((enc_rval.encoded+7)/8);
 }
 
 /*do_RRCConnectionReestablishmentReject - exactly the same as legacy LTE*/
 uint8_t do_RRCConnectionReestablishmentReject_NB_IoT(
-    uint8_t                    Mod_id,
-    uint8_t*                   const buffer)
-{
-
+  uint8_t                    Mod_id,
+  uint8_t                   *const buffer) {
   asn_enc_rval_t enc_rval;
-
-  DL_CCCH_Message_NB_t dl_ccch_msg_NB_IoT;
-  RRCConnectionReestablishmentReject_t *rrcConnectionReestablishmentReject;
-
-  memset((void *)&dl_ccch_msg_NB_IoT,0,sizeof(DL_CCCH_Message_NB_t));
-  dl_ccch_msg_NB_IoT.message.present = DL_CCCH_MessageType_NB_PR_c1;
-  dl_ccch_msg_NB_IoT.message.choice.c1.present = DL_CCCH_MessageType_NB__c1_PR_rrcConnectionReestablishmentReject_r13;
+  LTE_DL_CCCH_Message_NB_t dl_ccch_msg_NB_IoT;
+  LTE_RRCConnectionReestablishmentReject_t *rrcConnectionReestablishmentReject;
+  memset((void *)&dl_ccch_msg_NB_IoT,0,sizeof(LTE_DL_CCCH_Message_NB_t));
+  dl_ccch_msg_NB_IoT.message.present = LTE_DL_CCCH_MessageType_NB_PR_c1;
+  dl_ccch_msg_NB_IoT.message.choice.c1.present = LTE_DL_CCCH_MessageType_NB__c1_PR_rrcConnectionReestablishmentReject_r13;
   rrcConnectionReestablishmentReject    = &dl_ccch_msg_NB_IoT.message.choice.c1.choice.rrcConnectionReestablishmentReject_r13;
-
   // RRCConnectionReestablishmentReject //exactly the same as LTE
-  rrcConnectionReestablishmentReject->criticalExtensions.present = RRCConnectionReestablishmentReject__criticalExtensions_PR_rrcConnectionReestablishmentReject_r8;
+  rrcConnectionReestablishmentReject->criticalExtensions.present = LTE_RRCConnectionReestablishmentReject__criticalExtensions_PR_rrcConnectionReestablishmentReject_r8;
 
   //Only change in "asn_DEF_DL_CCCH_Message_NB"
   if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-     xer_fprint(stdout, &asn_DEF_DL_CCCH_Message_NB, (void*)&dl_ccch_msg_NB_IoT);
+    xer_fprint(stdout, &asn_DEF_LTE_DL_CCCH_Message_NB, (void *)&dl_ccch_msg_NB_IoT);
   }
-  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_CCCH_Message_NB,
+
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_DL_CCCH_Message_NB,
                                    NULL,
-                                   (void*)&dl_ccch_msg_NB_IoT,
+                                   (void *)&dl_ccch_msg_NB_IoT,
                                    buffer,
                                    100);
+
   if (enc_rval.encoded <= 0) {
-     LOG_E(RRC,"ASN1 message encoding failed (%s, %lu)!\n",
-               enc_rval.failed_type->name, enc_rval.encoded);
+    LOG_E(RRC,"ASN1 message encoding failed (%s, %lu)!\n",
+          enc_rval.failed_type->name, enc_rval.encoded);
   }
 
   //Only change in "asn_DEF_DL_CCCH_Message_NB"
-#if defined(ENABLE_ITTI)
-# if !defined(DISABLE_XER_SPRINT)
-  {
-    char        message_string[20000];
-    size_t      message_string_size;
-
-    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_CCCH_Message_NB, (void *) &dl_ccch_msg_NB_IoT)) > 0) {
-      MessageDef *msg_p;
-
-      msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB_NB_IoT, RRC_DL_CCCH, message_string_size + sizeof (IttiMsgText));
-      msg_p->ittiMsg.rrc_dl_ccch.size = message_string_size;
-      memcpy(&msg_p->ittiMsg.rrc_dl_ccch.text, message_string, message_string_size);
-
-      itti_send_msg_to_task(TASK_UNKNOWN, Mod_id, msg_p);
-    }
-  }
-# endif
-#endif
-
 #ifdef USER_MODE
   LOG_D(RRC,"RRCConnectionReestablishmentReject Encoded %zd bits (%zd bytes)\n",
         enc_rval.encoded,(enc_rval.encoded+7)/8);
 #endif
-
   return((enc_rval.encoded+7)/8);
 }
 
 /*do_RRCConnectionReject_NB_IoT*/
 uint8_t do_RRCConnectionReject_NB_IoT(
-    uint8_t                    Mod_id,
-    uint8_t*                   const buffer)
+  uint8_t                    Mod_id,
+  uint8_t                   *const buffer)
 
 {
-
   asn_enc_rval_t enc_rval;
-
-  DL_CCCH_Message_NB_t          dl_ccch_msg_NB_IoT;
-  RRCConnectionReject_NB_t      *rrcConnectionReject_NB_IoT;
-
-  memset((void *)&dl_ccch_msg_NB_IoT,0,sizeof(DL_CCCH_Message_NB_t));
-  dl_ccch_msg_NB_IoT.message.present           = DL_CCCH_MessageType_NB_PR_c1;
-  dl_ccch_msg_NB_IoT.message.choice.c1.present = DL_CCCH_MessageType_NB__c1_PR_rrcConnectionReject_r13;
+  LTE_DL_CCCH_Message_NB_t          dl_ccch_msg_NB_IoT;
+  LTE_RRCConnectionReject_NB_t      *rrcConnectionReject_NB_IoT;
+  memset((void *)&dl_ccch_msg_NB_IoT,0,sizeof(LTE_DL_CCCH_Message_NB_t));
+  dl_ccch_msg_NB_IoT.message.present           = LTE_DL_CCCH_MessageType_NB_PR_c1;
+  dl_ccch_msg_NB_IoT.message.choice.c1.present = LTE_DL_CCCH_MessageType_NB__c1_PR_rrcConnectionReject_r13;
   rrcConnectionReject_NB_IoT = &dl_ccch_msg_NB_IoT.message.choice.c1.choice.rrcConnectionReject_r13;
-
   // RRCConnectionReject-NB_IoT
-  rrcConnectionReject_NB_IoT->criticalExtensions.present = RRCConnectionReject_NB__criticalExtensions_PR_c1;
-  rrcConnectionReject_NB_IoT->criticalExtensions.choice.c1.present = RRCConnectionReject_NB__criticalExtensions__c1_PR_rrcConnectionReject_r13;
+  rrcConnectionReject_NB_IoT->criticalExtensions.present = LTE_RRCConnectionReject_NB__criticalExtensions_PR_c1;
+  rrcConnectionReject_NB_IoT->criticalExtensions.choice.c1.present = LTE_RRCConnectionReject_NB__criticalExtensions__c1_PR_rrcConnectionReject_r13;
   /* let's put an extended wait time of 1s for the moment */
   rrcConnectionReject_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReject_r13.extendedWaitTime_r13 = 1;
   //new-use of suspend indication
   //If present, this field indicates that the UE should remain suspended and not release its stored context.
   rrcConnectionReject_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReject_r13.rrc_SuspendIndication_r13=
-		  CALLOC(1, sizeof(long));
+    CALLOC(1, sizeof(long));
   *(rrcConnectionReject_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReject_r13.rrc_SuspendIndication_r13)=
-		  RRCConnectionReject_NB_r13_IEs__rrc_SuspendIndication_r13_true;
+    LTE_RRCConnectionReject_NB_r13_IEs__rrc_SuspendIndication_r13_true;
 
   //Only Modified "asn_DEF_DL_CCCH_Message_NB"
   if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-     xer_fprint(stdout, &asn_DEF_DL_CCCH_Message_NB, (void*)&dl_ccch_msg_NB_IoT);
+    xer_fprint(stdout, &asn_DEF_LTE_DL_CCCH_Message_NB, (void *)&dl_ccch_msg_NB_IoT);
   }
-  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_CCCH_Message_NB,
+
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_DL_CCCH_Message_NB,
                                    NULL,
-                                   (void*)&dl_ccch_msg_NB_IoT,
+                                   (void *)&dl_ccch_msg_NB_IoT,
                                    buffer,
                                    100);
-  if (enc_rval.encoded <= 0) {
-     LOG_E(RRC, "ASN1 message encoding failed (%s, %ld)!\n",
-               enc_rval.failed_type->name, enc_rval.encoded);
-  }
-
-#if defined(ENABLE_ITTI)
-# if !defined(DISABLE_XER_SPRINT)
-  {
-    char        message_string[20000];
-    size_t      message_string_size;
-
-    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_CCCH_Message_NB, (void *) &dl_ccch_msg_NB_IoT)) > 0) {
-      MessageDef *msg_p;
-
-      msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB_NB_IoT, RRC_DL_CCCH, message_string_size + sizeof (IttiMsgText));
-      msg_p->ittiMsg.rrc_dl_ccch.size = message_string_size;
-      memcpy(&msg_p->ittiMsg.rrc_dl_ccch.text, message_string, message_string_size);
 
-      itti_send_msg_to_task(TASK_UNKNOWN, Mod_id, msg_p);
-    }
+  if (enc_rval.encoded <= 0) {
+    LOG_E(RRC, "ASN1 message encoding failed (%s, %ld)!\n",
+          enc_rval.failed_type->name, enc_rval.encoded);
   }
-# endif
-#endif
 
 #ifdef USER_MODE
   LOG_D(RRC,"RRCConnectionReject-NB Encoded %zd bits (%zd bytes)\n",
         enc_rval.encoded,(enc_rval.encoded+7)/8);
 #endif
-
   return((enc_rval.encoded+7)/8);
 }
 
@@ -1260,49 +1038,25 @@ uint8_t do_RRCConnectionReject_NB_IoT(
 
 /*do_DLInformationTransfer_NB*/
 uint8_t do_DLInformationTransfer_NB_IoT(
-		uint8_t Mod_id,
-		uint8_t **buffer,
-		uint8_t transaction_id,
-		uint32_t pdu_length,
-		uint8_t *pdu_buffer)
+  uint8_t Mod_id,
+  uint8_t **buffer,
+  uint8_t transaction_id,
+  uint32_t pdu_length,
+  uint8_t *pdu_buffer)
 
 {
   ssize_t encoded;
-
-  DL_DCCH_Message_NB_t dl_dcch_msg_NB_IoT;
-
-  memset(&dl_dcch_msg_NB_IoT, 0, sizeof(DL_DCCH_Message_NB_t));
-
-  dl_dcch_msg_NB_IoT.message.present           = DL_DCCH_MessageType_NB_PR_c1;
-  dl_dcch_msg_NB_IoT.message.choice.c1.present = DL_DCCH_MessageType_NB__c1_PR_dlInformationTransfer_r13;
+  LTE_DL_DCCH_Message_NB_t dl_dcch_msg_NB_IoT;
+  memset(&dl_dcch_msg_NB_IoT, 0, sizeof(LTE_DL_DCCH_Message_NB_t));
+  dl_dcch_msg_NB_IoT.message.present           = LTE_DL_DCCH_MessageType_NB_PR_c1;
+  dl_dcch_msg_NB_IoT.message.choice.c1.present = LTE_DL_DCCH_MessageType_NB__c1_PR_dlInformationTransfer_r13;
   dl_dcch_msg_NB_IoT.message.choice.c1.choice.dlInformationTransfer_r13.rrc_TransactionIdentifier = transaction_id;
-  dl_dcch_msg_NB_IoT.message.choice.c1.choice.dlInformationTransfer_r13.criticalExtensions.present = DLInformationTransfer_NB__criticalExtensions_PR_c1;
-  dl_dcch_msg_NB_IoT.message.choice.c1.choice.dlInformationTransfer_r13.criticalExtensions.choice.c1.present = DLInformationTransfer_NB__criticalExtensions__c1_PR_dlInformationTransfer_r13;
+  dl_dcch_msg_NB_IoT.message.choice.c1.choice.dlInformationTransfer_r13.criticalExtensions.present = LTE_DLInformationTransfer_NB__criticalExtensions_PR_c1;
+  dl_dcch_msg_NB_IoT.message.choice.c1.choice.dlInformationTransfer_r13.criticalExtensions.choice.c1.present = LTE_DLInformationTransfer_NB__criticalExtensions__c1_PR_dlInformationTransfer_r13;
   dl_dcch_msg_NB_IoT.message.choice.c1.choice.dlInformationTransfer_r13.criticalExtensions.choice.c1.choice.dlInformationTransfer_r13.dedicatedInfoNAS_r13.size = pdu_length;
   dl_dcch_msg_NB_IoT.message.choice.c1.choice.dlInformationTransfer_r13.criticalExtensions.choice.c1.choice.dlInformationTransfer_r13.dedicatedInfoNAS_r13.buf = pdu_buffer;
-
-  encoded = uper_encode_to_new_buffer (&asn_DEF_DL_DCCH_Message_NB, NULL, (void*) &dl_dcch_msg_NB_IoT, (void **) buffer);
-
+  encoded = uper_encode_to_new_buffer (&asn_DEF_LTE_DL_DCCH_Message_NB, NULL, (void *) &dl_dcch_msg_NB_IoT, (void **) buffer);
   //only change in "asn_DEF_DL_DCCH_Message_NB"
-#if defined(ENABLE_ITTI)
-# if !defined(DISABLE_XER_SPRINT)
-  {
-    char        message_string[10000];
-    size_t      message_string_size;
-
-    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_DCCH_Message_NB, (void *)&dl_dcch_msg_NB_IoT)) > 0) {
-      MessageDef *msg_p;
-
-      msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB_NB_IoT, RRC_DL_DCCH, message_string_size + sizeof (IttiMsgText));
-      msg_p->ittiMsg.rrc_dl_dcch.size = message_string_size;
-      memcpy(&msg_p->ittiMsg.rrc_dl_dcch.text, message_string, message_string_size);
-
-      itti_send_msg_to_task(TASK_UNKNOWN, Mod_id, msg_p);
-    }
-  }
-# endif
-#endif
-
   return encoded;
 }
 
@@ -1313,70 +1067,43 @@ uint8_t do_DLInformationTransfer_NB_IoT(
 
 /*do_RRCConnectionReestablishment_NB-->used to re-establish SRB1*/ //which parameter to use?
 uint8_t do_RRCConnectionReestablishment_NB_IoT(
-		uint8_t Mod_id,
-		uint8_t* const buffer,
-		const uint8_t     Transaction_id,
-		const NB_IoT_DL_FRAME_PARMS* const frame_parms, //to be changed
-		SRB_ToAddModList_NB_r13_t*      SRB_list_NB_IoT) //should contain SRB1 already configured?
-{
-
-	asn_enc_rval_t enc_rval;
-	DL_CCCH_Message_NB_t dl_ccch_msg_NB_IoT;
-	RRCConnectionReestablishment_NB_t* rrcConnectionReestablishment_NB_IoT;
-
-	memset(&dl_ccch_msg_NB_IoT, 0, sizeof(DL_CCCH_Message_NB_t));
-
-	dl_ccch_msg_NB_IoT.message.present = DL_CCCH_MessageType_NB_PR_c1;
-	dl_ccch_msg_NB_IoT.message.choice.c1.present = DL_CCCH_MessageType_NB__c1_PR_rrcConnectionReestablishment_r13;
-	rrcConnectionReestablishment_NB_IoT = &dl_ccch_msg_NB_IoT.message.choice.c1.choice.rrcConnectionReestablishment_r13;
-
-	//rrcConnectionReestablishment_NB
-	rrcConnectionReestablishment_NB_IoT->rrc_TransactionIdentifier = Transaction_id;
-	rrcConnectionReestablishment_NB_IoT->criticalExtensions.present = RRCConnectionReestablishment_NB__criticalExtensions_PR_c1;
-	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.present = RRCConnectionReestablishment_NB__criticalExtensions__c1_PR_rrcConnectionReestablishment_r13;
-
-	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.radioResourceConfigDedicated_r13.srb_ToAddModList_r13 = SRB_list_NB_IoT;
-	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.radioResourceConfigDedicated_r13.drb_ToAddModList_r13 = NULL;
-	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.radioResourceConfigDedicated_r13.drb_ToReleaseList_r13 = NULL;
-	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.radioResourceConfigDedicated_r13.rlf_TimersAndConstants_r13= NULL;
-	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.radioResourceConfigDedicated_r13.mac_MainConfig_r13= NULL;
-	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.radioResourceConfigDedicated_r13.physicalConfigDedicated_r13 = NULL;
-
-	rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.nextHopChainingCount_r13=0;
-
-	enc_rval = uper_encode_to_buffer(&asn_DEF_DL_CCCH_Message_NB,
-                                           NULL,
-	                                   (void*)&dl_ccch_msg_NB_IoT,
-	                                   buffer,
-	                                   RRC_BUF_SIZE);
-
-	if (enc_rval.encoded <= 0) {
-           LOG_E(RRC, "ASN1 message encoding failed (%s, %li)!\n",
-	               enc_rval.failed_type->name, enc_rval.encoded);
-        }
-
-        if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-           xer_fprint(stdout,&asn_DEF_DL_CCCH_Message_NB,(void*)&dl_ccch_msg_NB_IoT);
-        }
-
-#if defined(ENABLE_ITTI)
-# if !defined(DISABLE_XER_SPRINT)
-  {
-    char        message_string[30000];
-    size_t      message_string_size;
-
-    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_CCCH_Message_NB, (void *) &dl_ccch_msg_NB_IoT)) > 0) {
-      MessageDef *msg_p;
+  uint8_t Mod_id,
+  uint8_t *const buffer,
+  const uint8_t     Transaction_id,
+  const NB_IoT_DL_FRAME_PARMS *const frame_parms, //to be changed
+  LTE_SRB_ToAddModList_NB_r13_t      *SRB_list_NB_IoT) { //should contain SRB1 already configured?
+  asn_enc_rval_t enc_rval;
+  LTE_DL_CCCH_Message_NB_t dl_ccch_msg_NB_IoT;
+  LTE_RRCConnectionReestablishment_NB_t *rrcConnectionReestablishment_NB_IoT;
+  memset(&dl_ccch_msg_NB_IoT, 0, sizeof(LTE_DL_CCCH_Message_NB_t));
+  dl_ccch_msg_NB_IoT.message.present = LTE_DL_CCCH_MessageType_NB_PR_c1;
+  dl_ccch_msg_NB_IoT.message.choice.c1.present = LTE_DL_CCCH_MessageType_NB__c1_PR_rrcConnectionReestablishment_r13;
+  rrcConnectionReestablishment_NB_IoT = &dl_ccch_msg_NB_IoT.message.choice.c1.choice.rrcConnectionReestablishment_r13;
+  //rrcConnectionReestablishment_NB
+  rrcConnectionReestablishment_NB_IoT->rrc_TransactionIdentifier = Transaction_id;
+  rrcConnectionReestablishment_NB_IoT->criticalExtensions.present = LTE_RRCConnectionReestablishment_NB__criticalExtensions_PR_c1;
+  rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.present = LTE_RRCConnectionReestablishment_NB__criticalExtensions__c1_PR_rrcConnectionReestablishment_r13;
+  rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.radioResourceConfigDedicated_r13.srb_ToAddModList_r13 = SRB_list_NB_IoT;
+  rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.radioResourceConfigDedicated_r13.drb_ToAddModList_r13 = NULL;
+  rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.radioResourceConfigDedicated_r13.drb_ToReleaseList_r13 = NULL;
+  rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.radioResourceConfigDedicated_r13.rlf_TimersAndConstants_r13= NULL;
+  rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.radioResourceConfigDedicated_r13.mac_MainConfig_r13= NULL;
+  rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.radioResourceConfigDedicated_r13.physicalConfigDedicated_r13 = NULL;
+  rrcConnectionReestablishment_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r13.nextHopChainingCount_r13=0;
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_DL_CCCH_Message_NB,
+                                   NULL,
+                                   (void *)&dl_ccch_msg_NB_IoT,
+                                   buffer,
+                                   RRC_BUF_SIZE);
 
-      msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB_NB_IoT, RRC_DL_CCCH, message_string_size + sizeof (IttiMsgText));
-      msg_p->ittiMsg.rrc_dl_ccch.size = message_string_size;
-      memcpy(&msg_p->ittiMsg.rrc_dl_ccch.text, message_string, message_string_size);
+  if (enc_rval.encoded <= 0) {
+    LOG_E(RRC, "ASN1 message encoding failed (%s, %li)!\n",
+          enc_rval.failed_type->name, enc_rval.encoded);
+  }
 
-      itti_send_msg_to_task(TASK_UNKNOWN, Mod_id, msg_p);
-    }
+  if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
+    xer_fprint(stdout,&asn_DEF_LTE_DL_CCCH_Message_NB,(void *)&dl_ccch_msg_NB_IoT);
   }
-# endif
-#endif
 
   LOG_I(RRC,"RRCConnectionReestablishment-NB Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
   return 0;
@@ -1386,40 +1113,29 @@ uint8_t do_RRCConnectionReestablishment_NB_IoT(
 uint8_t do_RRCConnectionRelease_NB_IoT(
   uint8_t                             Mod_id,
   uint8_t                            *buffer,
- const uint8_t                             Transaction_id)
-{
-
+  const uint8_t                             Transaction_id) {
   asn_enc_rval_t enc_rval;
-
-  DL_DCCH_Message_NB_t dl_dcch_msg_NB_IoT;
-  RRCConnectionRelease_NB_t *rrcConnectionRelease_NB_IoT;
-
-
-  memset(&dl_dcch_msg_NB_IoT,0,sizeof(DL_DCCH_Message_NB_t));
-
-  dl_dcch_msg_NB_IoT.message.present           = DL_DCCH_MessageType_NB_PR_c1;
-  dl_dcch_msg_NB_IoT.message.choice.c1.present = DL_DCCH_MessageType_NB__c1_PR_rrcConnectionRelease_r13;
+  LTE_DL_DCCH_Message_NB_t dl_dcch_msg_NB_IoT;
+  LTE_RRCConnectionRelease_NB_t *rrcConnectionRelease_NB_IoT;
+  memset(&dl_dcch_msg_NB_IoT,0,sizeof(LTE_DL_DCCH_Message_NB_t));
+  dl_dcch_msg_NB_IoT.message.present           = LTE_DL_DCCH_MessageType_NB_PR_c1;
+  dl_dcch_msg_NB_IoT.message.choice.c1.present = LTE_DL_DCCH_MessageType_NB__c1_PR_rrcConnectionRelease_r13;
   rrcConnectionRelease_NB_IoT                  = &dl_dcch_msg_NB_IoT.message.choice.c1.choice.rrcConnectionRelease_r13;
-
   // RRCConnectionRelease
   rrcConnectionRelease_NB_IoT->rrc_TransactionIdentifier = Transaction_id;
-  rrcConnectionRelease_NB_IoT->criticalExtensions.present = RRCConnectionRelease_NB__criticalExtensions_PR_c1;
-  rrcConnectionRelease_NB_IoT->criticalExtensions.choice.c1.present =RRCConnectionRelease_NB__criticalExtensions__c1_PR_rrcConnectionRelease_r13 ;
-
-  rrcConnectionRelease_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionRelease_r13.releaseCause_r13 = ReleaseCause_NB_r13_other;
+  rrcConnectionRelease_NB_IoT->criticalExtensions.present = LTE_RRCConnectionRelease_NB__criticalExtensions_PR_c1;
+  rrcConnectionRelease_NB_IoT->criticalExtensions.choice.c1.present = LTE_RRCConnectionRelease_NB__criticalExtensions__c1_PR_rrcConnectionRelease_r13 ;
+  rrcConnectionRelease_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionRelease_r13.releaseCause_r13 = LTE_ReleaseCause_NB_r13_other;
   rrcConnectionRelease_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionRelease_r13.redirectedCarrierInfo_r13 = NULL;
   rrcConnectionRelease_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionRelease_r13.extendedWaitTime_r13 = NULL;
-
   //Why allocate memory for non critical extension?
   rrcConnectionRelease_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionRelease_r13.nonCriticalExtension=CALLOC(1,
       sizeof(*rrcConnectionRelease_NB_IoT->criticalExtensions.choice.c1.choice.rrcConnectionRelease_r13.nonCriticalExtension));
-
-  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_DCCH_Message_NB,
+  enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_DL_DCCH_Message_NB,
                                    NULL,
-                                   (void*)&dl_dcch_msg_NB_IoT,
+                                   (void *)&dl_dcch_msg_NB_IoT,
                                    buffer,
                                    RRC_BUF_SIZE);//check
-
   return((enc_rval.encoded+7)/8);
 }
 
diff --git a/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/36331-860.txt b/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/36331-860.txt
old mode 100755
new mode 100644
diff --git a/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/36331-a20.txt b/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/36331-a20.txt
old mode 100755
new mode 100644
diff --git a/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/36331-ah0.txt b/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/36331-ah0.txt
old mode 100755
new mode 100644
diff --git a/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/36331-c60.txt b/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/36331-c60.txt
old mode 100755
new mode 100644
diff --git a/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/EUTRA-InterNodeDefinitions-86.asn b/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/EUTRA-InterNodeDefinitions-86.asn
old mode 100755
new mode 100644
diff --git a/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/EUTRA-InterNodeDefinitions-a20.asn b/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/EUTRA-InterNodeDefinitions-a20.asn
old mode 100755
new mode 100644
diff --git a/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/EUTRA-RRC-Definitions-a20-lola.asn b/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/EUTRA-RRC-Definitions-a20-lola.asn
old mode 100755
new mode 100644
diff --git a/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/EUTRA-RRC-Definitions-a20.asn b/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/EUTRA-RRC-Definitions-a20.asn
old mode 100755
new mode 100644
diff --git a/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/EUTRA-RRC-Definitions-a20.asn.orig b/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/EUTRA-RRC-Definitions-a20.asn.orig
old mode 100755
new mode 100644
diff --git a/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/EUTRA-UE-Variables-86.asn b/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/EUTRA-UE-Variables-86.asn
old mode 100755
new mode 100644
diff --git a/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/EUTRA-UE-Variables-a20.asn b/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/EUTRA-UE-Variables-a20.asn
old mode 100755
new mode 100644
diff --git a/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-10.21.0.asn1 b/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-10.21.0.asn1
old mode 100755
new mode 100644
diff --git a/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-11.18.0.asn1 b/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-11.18.0.asn1
old mode 100755
new mode 100644
diff --git a/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-12.16.0.asn1 b/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-12.16.0.asn1
old mode 100755
new mode 100644
diff --git a/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-13.9.1.asn1 b/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-13.9.1.asn1
old mode 100755
new mode 100644
index b6f64a99ed835e7e320475b740e3b210ed07c242..ceb4a7cd3744b2c9c5d0400fb7a1201acf6943e3
--- a/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-13.9.1.asn1
+++ b/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-13.9.1.asn1
@@ -735,7 +735,7 @@ Paging-v1130-IEs ::=			SEQUENCE {
 }
 
 Paging-v1310-IEs ::=			SEQUENCE {
-	redistributionIndication-r13	ENUMERATED {true}					OPTIONAL,	--Need ON
+	redistributionIndication-r13	ENUMERATED {true}					OPTIONAL,	-- Need ON
 	systemInfoModification-eDRX-r13	ENUMERATED {true}					OPTIONAL,	-- Need ON
 	nonCriticalExtension			SEQUENCE {}							OPTIONAL
 }
diff --git a/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-14.4.0.asn1 b/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-14.4.0.asn1
old mode 100755
new mode 100644
diff --git a/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-14.6.2.asn1 b/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-14.6.2.asn1
old mode 100755
new mode 100644
diff --git a/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-14.7.0.asn1 b/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-14.7.0.asn1
old mode 100755
new mode 100644
diff --git a/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-15.1.0.asn1 b/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-15.1.0.asn1
old mode 100755
new mode 100644
diff --git a/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-15.2.1.asn1 b/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-15.2.1.asn1
old mode 100755
new mode 100644
diff --git a/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-15.2.2.asn1 b/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-15.2.2.asn1
old mode 100755
new mode 100644
diff --git a/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-8.21.0.asn1 b/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-8.21.0.asn1
old mode 100755
new mode 100644
diff --git a/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-9.18.0.asn1 b/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-9.18.0.asn1
old mode 100755
new mode 100644
diff --git a/openair2/RRC/LTE/defs_NB_IoT.h b/openair2/RRC/LTE/defs_NB_IoT.h
index 0cc8a37bc08ef4ce836a67f8a644dc8554eb6eea..160d92a610888b1c0e194c3e1d62db6109084e85 100644
--- a/openair2/RRC/LTE/defs_NB_IoT.h
+++ b/openair2/RRC/LTE/defs_NB_IoT.h
@@ -50,17 +50,17 @@
 
 //#include "SystemInformationBlockType1-NB.h"
 //#include "SystemInformation-NB.h"
-#include "RRCConnectionReconfiguration-NB.h"
-#include "RRCConnectionReconfigurationComplete-NB.h"
-#include "RRCConnectionSetup-NB.h"
-#include "RRCConnectionSetupComplete-NB.h"
-#include "RRCConnectionRequest-NB.h"
-#include "RRCConnectionReestablishmentRequest-NB.h"
-#include "BCCH-DL-SCH-Message-NB.h"
-#include "BCCH-BCH-Message-NB.h"
-#include "AS-Config-NB.h"
-#include "AS-Context-NB.h"
-#include "UE-Capability-NB-r13.h" //equivalent of UE-EUTRA-Capability.h
+#include "LTE_RRCConnectionReconfiguration-NB.h"
+#include "LTE_RRCConnectionReconfigurationComplete-NB.h"
+#include "LTE_RRCConnectionSetup-NB.h"
+#include "LTE_RRCConnectionSetupComplete-NB.h"
+#include "LTE_RRCConnectionRequest-NB.h"
+#include "LTE_RRCConnectionReestablishmentRequest-NB.h"
+#include "LTE_BCCH-DL-SCH-Message-NB.h"
+#include "LTE_BCCH-BCH-Message-NB.h"
+#include "LTE_AS-Config-NB.h"
+#include "LTE_AS-Context-NB.h"
+#include "LTE_UE-Capability-NB-r13.h" //equivalent of UE-EUTRA-Capability.h
 //-------------------
 
 #if defined(ENABLE_ITTI)
@@ -122,7 +122,7 @@ typedef struct UE_RRC_INFO_NB_IoT_s {
   uint8_t SIB1systemInfoValueTag;
   uint32_t SIStatus;
   uint32_t SIcnt;
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
   uint8_t MCCHStatus[8]; // MAX_MBSFN_AREA
 #endif
   uint8_t SIwindowsize; //!< Corresponds to the SIB1 si-WindowLength parameter. The unit is ms. Possible values are (final): 1,2,5,10,15,20,40
@@ -235,14 +235,14 @@ typedef struct SRB_INFO_TABLE_ENTRY_NB_IoT_s {
 //MEAS_REPORT_LIST_s not implemented in NB-IoT but is used at UE side
 //HANDOVER_INFO_UE not implemented in NB-IoT
 typedef struct HANDOVER_INFO_UE_NB_IoT_s {
-  PhysCellId_t targetCellId;
+  LTE_PhysCellId_t targetCellId;
   uint8_t measFlag;
 } HANDOVER_INFO_UE_NB_IoT;
 
 //NB-IoT eNB_RRC_UE_NB_IoT_s--(used as a context in eNB --> ue_context in rrc_eNB_ue_context)------
 typedef struct eNB_RRC_UE_NB_IoT_s {
 
-  EstablishmentCause_t               establishment_cause;
+  LTE_EstablishmentCause_t           establishment_cause;
   uint8_t                            primaryCC_id;
   //in NB-IoT only SRB0, SRB1 and SRB1bis (until AS security activation) exist
 
@@ -256,14 +256,14 @@ typedef struct eNB_RRC_UE_NB_IoT_s {
    * 					   message previously sent by the eNB (e.g. RRCConnectionSetup -- RRCConnectionSetupComplete)
    * 					   this because it could happen that more messages are transmitted at the same time
    */
-  SRB_ToAddModList_NB_r13_t*                SRB_configList;//for SRB1 and SRB1bis
-  SRB_ToAddModList_NB_r13_t*                SRB_configList2[RRC_TRANSACTION_IDENTIFIER_NUMBER];
-  DRB_ToAddModList_NB_r13_t*                DRB_configList; //for all the DRBs
-  DRB_ToAddModList_NB_r13_t*                DRB_configList2[RRC_TRANSACTION_IDENTIFIER_NUMBER]; //for the configured DRBs of a xid
+  LTE_SRB_ToAddModList_NB_r13_t*            SRB_configList;//for SRB1 and SRB1bis
+  LTE_SRB_ToAddModList_NB_r13_t*            SRB_configList2[RRC_TRANSACTION_IDENTIFIER_NUMBER];
+  LTE_DRB_ToAddModList_NB_r13_t*            DRB_configList; //for all the DRBs
+  LTE_DRB_ToAddModList_NB_r13_t*            DRB_configList2[RRC_TRANSACTION_IDENTIFIER_NUMBER]; //for the configured DRBs of a xid
   uint8_t                            		DRB_active[2];//in LTE was 8 --> at most 2 for NB-IoT
 
-  struct PhysicalConfigDedicated_NB_r13*    physicalConfigDedicated_NB_IoT;
-  MAC_MainConfig_NB_r13_t*           mac_MainConfig_NB_IoT;
+  struct LTE_PhysicalConfigDedicated_NB_r13*    physicalConfigDedicated_NB_IoT;
+  LTE_MAC_MainConfig_NB_r13_t*           mac_MainConfig_NB_IoT;
 
   //No SPS(semi-persistent scheduling) in NB-IoT
   //No Measurement report in NB-IoT
@@ -279,8 +279,8 @@ typedef struct eNB_RRC_UE_NB_IoT_s {
 #endif
 
   /* Used integrity/ciphering algorithms--> maintained the same for NB-IoT */
-  e_CipheringAlgorithm_r12     ciphering_algorithm; //Specs. TS 36.331 V14.1.0 pag 432 Change position of chipering enumerative w.r.t previous version
-  e_SecurityAlgorithmConfig__integrityProtAlgorithm integrity_algorithm;
+  e_LTE_CipheringAlgorithm_r12     ciphering_algorithm; //Specs. TS 36.331 V14.1.0 pag 432 Change position of chipering enumerative w.r.t previous version
+  e_LTE_SecurityAlgorithmConfig__integrityProtAlgorithm integrity_algorithm;
 
   uint8_t                            Status;
   rnti_t                             rnti;
@@ -290,10 +290,10 @@ typedef struct eNB_RRC_UE_NB_IoT_s {
 
   /* Information from UE RRC ConnectionRequest-NB-r13_IE--> NB-IoT */
   UE_S_TMSI_NB_IoT                          Initialue_identity_s_TMSI;
-  EstablishmentCause_NB_r13_t               establishment_cause_NB_IoT; //different set for NB-IoT
+  LTE_EstablishmentCause_NB_r13_t               establishment_cause_NB_IoT; //different set for NB-IoT
 
   /* Information from UE RRC ConnectionReestablishmentRequest-NB--> NB-IoT */
-  ReestablishmentCause_NB_r13_t             reestablishment_cause_NB_IoT; //different set for NB_IoT
+  LTE_ReestablishmentCause_NB_r13_t             reestablishment_cause_NB_IoT; //different set for NB_IoT
 
   /* UE id for initial connection to S1AP */
   uint16_t                           ue_initial_id;
@@ -389,18 +389,18 @@ typedef struct {
   uint16_t                          physCellId; //not stored in the MIB-NB but is getting through NPSS/NSSS
 
   //are the only static one (memory has been already allocated)
-  BCCH_BCH_Message_NB_t                mib_NB_IoT;
-  BCCH_DL_SCH_Message_NB_t             siblock1_NB_IoT; //SIB1-NB
-  BCCH_DL_SCH_Message_NB_t             systemInformation_NB_IoT; //SI
+  LTE_BCCH_BCH_Message_NB_t                mib_NB_IoT;
+  LTE_BCCH_DL_SCH_Message_NB_t             siblock1_NB_IoT; //SIB1-NB
+  LTE_BCCH_DL_SCH_Message_NB_t             systemInformation_NB_IoT; //SI
 
-  SystemInformationBlockType1_NB_t     		*sib1_NB_IoT;
-  SystemInformationBlockType2_NB_r13_t   	*sib2_NB_IoT;
-  SystemInformationBlockType3_NB_r13_t   	*sib3_NB_IoT;
+  LTE_SystemInformationBlockType1_NB_t     		*sib1_NB_IoT;
+  LTE_SystemInformationBlockType2_NB_r13_t   	*sib2_NB_IoT;
+  LTE_SystemInformationBlockType3_NB_r13_t   	*sib3_NB_IoT;
   //not implemented yet
-  SystemInformationBlockType4_NB_r13_t    	*sib4_NB_IoT;
-  SystemInformationBlockType5_NB_r13_t     	*sib5_NB_IoT;
-  SystemInformationBlockType14_NB_r13_t     *sib14_NB_IoT;
-  SystemInformationBlockType16_NB_r13_t     *sib16_NB_IoT;
+  LTE_SystemInformationBlockType4_NB_r13_t    	*sib4_NB_IoT;
+  LTE_SystemInformationBlockType5_NB_r13_t     	*sib5_NB_IoT;
+  LTE_SystemInformationBlockType14_NB_r13_t     *sib14_NB_IoT;
+  LTE_SystemInformationBlockType16_NB_r13_t     *sib16_NB_IoT;
 
 
   SRB_INFO_NB_IoT                          SI;
@@ -466,7 +466,7 @@ typedef struct OAI_UECapability_NB_IoT_s {
  uint8_t sdu[MAX_UE_CAPABILITY_SIZE_NB_IoT];
  uint8_t sdu_size;
 ////NB-IoT------
-  UE_Capability_NB_r13_t  UE_Capability_NB_IoT; //replace the UE_EUTRA_Capability of LTE
+  LTE_UE_Capability_NB_r13_t  UE_Capability_NB_IoT; //replace the UE_EUTRA_Capability of LTE
 } OAI_UECapability_NB_IoT_t;
 
 #define RRC_BUFFER_SIZE_MAX_NB_IoT 1024
@@ -501,7 +501,7 @@ typedef struct UE_RRC_INST_NB_IoT_s {
   SystemInformationBlockType1_t *sib1[NB_CNX_UE];
   SystemInformation_t *si[NB_CNX_UE]; //!< Temporary storage for an SI message. Decoding happens in decode_SI().
   */
-  SystemInformationBlockType2_t *sib2[NB_CNX_UE];
+  LTE_SystemInformationBlockType2_t *sib2[NB_CNX_UE];
   /*
   SystemInformationBlockType3_t *sib3[NB_CNX_UE];
   SystemInformationBlockType4_t *sib4[NB_CNX_UE];
@@ -513,7 +513,7 @@ typedef struct UE_RRC_INST_NB_IoT_s {
   SystemInformationBlockType10_t *sib10[NB_CNX_UE];
   SystemInformationBlockType11_t *sib11[NB_CNX_UE];
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
   uint8_t                           MBMS_flag;
   uint8_t *MCCH_MESSAGE[NB_CNX_UE];
   uint8_t sizeof_MCCH_MESSAGE[NB_CNX_UE];
diff --git a/openair2/RRC/LTE/extern_NB_IoT.h b/openair2/RRC/LTE/extern_NB_IoT.h
index f136b57b4787613605ad3f579f779b6005963598..f240e8b2159381376a6888a31665fd83a5f29229 100644
--- a/openair2/RRC/LTE/extern_NB_IoT.h
+++ b/openair2/RRC/LTE/extern_NB_IoT.h
@@ -33,7 +33,7 @@
 #include "RRC/LTE/defs_NB_IoT.h"
 #include "PHY_INTERFACE/IF_Module_NB_IoT.h"
 #include "LAYER2/RLC/rlc.h"
-#include "LogicalChannelConfig-NB-r13.h"
+#include "LTE_LogicalChannelConfig-NB-r13.h"
 #include "LAYER2/MAC/defs_NB_IoT.h"
 
 #include "common/ran_context.h"
@@ -48,8 +48,8 @@ extern PHY_Config_NB_IoT_t 						*config_INFO;
 
 extern rlc_info_t 							Rlc_info_am_NB_IoT,Rlc_info_am_config_NB_IoT;
 extern uint8_t 								DRB2LCHAN_NB_IoT[2];
-extern LogicalChannelConfig_NB_r13_t 		SRB1bis_logicalChannelConfig_defaultValue_NB_IoT;
-extern LogicalChannelConfig_NB_r13_t 		SRB1_logicalChannelConfig_defaultValue_NB_IoT;
+extern LTE_LogicalChannelConfig_NB_r13_t 		SRB1bis_logicalChannelConfig_defaultValue_NB_IoT;
+extern LTE_LogicalChannelConfig_NB_r13_t 		SRB1_logicalChannelConfig_defaultValue_NB_IoT;
 
 extern uint16_t 							T300_NB_IoT[8];
 extern uint16_t 							T301_NB_IoT[8];
diff --git a/openair2/RRC/LTE/proto_NB_IoT.h b/openair2/RRC/LTE/proto_NB_IoT.h
index de09d39fab7b100b9335489cae95a513068baea2..e5c5d8056b58e84f680a6f8041142ba58a90a55b 100644
--- a/openair2/RRC/LTE/proto_NB_IoT.h
+++ b/openair2/RRC/LTE/proto_NB_IoT.h
@@ -203,7 +203,7 @@ rrc_eNB_generate_dedicatedRRCConnectionReconfiguration_NB_IoT(
 void rrc_eNB_process_RRCConnectionSetupComplete_NB_IoT(
   const protocol_ctxt_t* const ctxt_pP,
   rrc_eNB_ue_context_NB_IoT_t*         ue_context_pP,
-  RRCConnectionSetupComplete_NB_r13_IEs_t * rrcConnectionSetupComplete_NB
+  LTE_RRCConnectionSetupComplete_NB_r13_IEs_t * rrcConnectionSetupComplete_NB
 );
 
 void rrc_eNB_generate_SecurityModeCommand_NB_IoT(
diff --git a/openair2/RRC/LTE/rrc_2_rrm_msg.c b/openair2/RRC/LTE/rrc_2_rrm_msg.c
deleted file mode 100644
index 87a0a3557b57a7ce4f636024e7d031f9352423f7..0000000000000000000000000000000000000000
--- a/openair2/RRC/LTE/rrc_2_rrm_msg.c
+++ /dev/null
@@ -1,439 +0,0 @@
-/*
- * 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
- */
-
-/*!
-*******************************************************************************
-
-\file       rrc_2_rrm_msg.c
-
-\brief     data formating for sending message over socket between RRC and RRM
-
-\author     BURLOT Pascal
-
-\date       16/07/08
-
-\par     Historique:
-        P.BURLOT 2009-01-20
-            bug fix (memeory leak)
-      Macro changed :
-      RRM_CALLOC() by RRM_CALLOC2() in msg_rrc_sensing_meas_ind()
-
-*******************************************************************************
-*/
-#ifdef RRC_EMUL
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include "L3_rrc_defs.h"
-#include "rrm_sock.h"
-#include "L3_rrc_interface.h"
-#include "rrc_rrm_msg.h"
-#include "rrm_util.h"
-
-#else
-
-#include "defs.h"
-
-#endif
-
-#ifdef TRACE
-//! Macro creant la chaine a partir du nom de la variable
-#define STRINGIZER(x) #x
-//! Tableau pour le mode trace faisant la translation entre le numero et le nom du message
-const char *Str_msg_rrc_rrm[NB_MSG_RRC_RRM] = {
-  STRINGIZER(RRM_RB_ESTABLISH_REQ     ),
-  STRINGIZER(RRC_RB_ESTABLISH_RESP    ),
-  STRINGIZER(RRC_RB_ESTABLISH_CFM     ),
-  STRINGIZER(RRM_RB_MODIFY_REQ        ),
-  STRINGIZER(RRC_RB_MODIFY_RESP       ),
-  STRINGIZER(RRC_RB_MODIFY_CFM        ),
-  STRINGIZER(RRM_RB_RELEASE_REQ       ),
-  STRINGIZER(RRC_RB_RELEASE_RESP      ),
-  STRINGIZER(RRC_MR_ATTACH_IND        ),
-  STRINGIZER(RRM_SENSING_MEAS_REQ     ),
-  STRINGIZER(RRC_SENSING_MEAS_RESP    ),
-  STRINGIZER(RRC_CX_ESTABLISH_IND     ),
-  STRINGIZER(RRC_PHY_SYNCH_TO_MR_IND  ),
-  STRINGIZER(RRC_PHY_SYNCH_TO_CH_IND  ),
-  STRINGIZER(RRCI_CX_ESTABLISH_RESP   ),
-  STRINGIZER(RRC_SENSING_MEAS_IND     ),
-  STRINGIZER(RRM_SENSING_MEAS_RESP    ),
-  STRINGIZER(RRC_RB_MEAS_IND          ),
-  STRINGIZER(RRM_RB_MEAS_RESP         ),
-  STRINGIZER(RRM_INIT_CH_REQ          ),
-  STRINGIZER(RRCI_INIT_MR_REQ         )
-} ;
-#endif
-
-/*!
-*******************************************************************************
-\brief  This function initialize the message header
-\return any return value
-*/
-static void init_rrc_msg_head(
-  msg_head_t    *msg_head , //!< message header to initialize
-  Instance_t     inst     , //!< Instance ID
-  MSG_RRC_RRM_T  msg_type , //!< type of message to initialize
-  unsigned int   size     , //!< size of message
-  Transaction_t  Trans_id   //!< transaction id associated to this message
-)
-{
-  if ( msg_head != NULL ) {
-    msg_head->start    = START_MSG ;
-    msg_head->msg_type = 0xFF & msg_type ;
-    msg_head->inst     = inst  ;
-    msg_head->Trans_id = Trans_id  ;
-    msg_head->size     = size;
-  }
-}
-
-
-/*!
-*******************************************************************************
-\brief  La fonction formate en un message generique de reponse pour les
-          fonctions :
-            - rrc_rb_establish_resp(),rrc_rb_modify_resp(),rrc_rb_modify_resp(),
-            - rrc_rb_release_resp() et rrc_sensing_meas_resp() .
-\return message formate
-*/
-msg_t mesg;
-msg_t *msg_rrc_generic_resp(
-  Instance_t    inst     , //!< Instance ID
-  MSG_RRC_RRM_T msg_type , //!< type of message
-  Transaction_t Trans_id   //!< Transaction ID
-)
-{
-  init_rrc_msg_head(&(mesg.head),inst, msg_type, 0 , Trans_id);
-  mesg.data = NULL ;
-
-  return &mesg ;
-}
-
-/*!
-*******************************************************************************
-\brief  La fonction formate en un message les parametres de la fonction
-        rrc_rb_establish_resp().
-\return message formate
-*/
-msg_t *msg_rrc_rb_establish_resp(
-  Instance_t    inst     , //!< Instance ID
-  Transaction_t Trans_id   //!< Transaction ID
-)
-{
-  return msg_rrc_generic_resp( inst, RRC_RB_ESTABLISH_RESP, Trans_id) ;
-}
-/*!
-*******************************************************************************
-\brief  La fonction formate en un message les parametres de la fonction
-        rrc_rb_establish_cfm().
-\return message formate
-*/
-rrc_rb_establish_cfm_t P_rb_est_cfm ;//= RRM_CALLOC(rrc_rb_establish_cfm_t , 1 ) ;
-msg_t *msg_rrc_rb_establish_cfm(
-  Instance_t    inst     , //!< Instance ID
-  RB_ID         Rb_id    , //!< Radio Bearer ID used by RRC
-  RB_TYPE       RB_type  , //!< Radio Bearer Type
-  Transaction_t Trans_id   //!< Transaction ID
-)
-{
-  //  msg_t mesg;
-
-  init_rrc_msg_head(&(mesg.head),inst,RRC_RB_ESTABLISH_CFM, sizeof( rrc_rb_establish_cfm_t ) ,Trans_id);
-  P_rb_est_cfm.Rb_id        = Rb_id ;
-  P_rb_est_cfm.RB_type      = RB_type ;
-  mesg.data = (char *) &P_rb_est_cfm ;
-  return &mesg ;
-
-}
-
-/*!
-*******************************************************************************
-\brief  La fonction formate en un message les parametres de la fonction
-        rrc_rb_modify_resp().
-\return message formate
-*/
-msg_t *msg_rrc_rb_modify_resp(
-  Instance_t    inst     , //!< Instance ID
-  Transaction_t Trans_id   //!< Transaction ID
-)
-{
-  return msg_rrc_generic_resp( inst,RRC_RB_MODIFY_RESP, Trans_id) ;
-}
-/*!
-*******************************************************************************
-\brief  La fonction formate en un message les parametres de la fonction
-        rrc_rb_modify_cfm().
-\return message formate
-*/
-rrc_rb_modify_cfm_t P_rb_md_cfm;
-msg_t *msg_rrc_rb_modify_cfm(
-  Instance_t    inst     , //!< Instance ID
-  RB_ID         Rb_id    , //!< Radio Bearer ID used by RRC
-  Transaction_t Trans_id   //!< Transaction ID
-)
-{
-  // msg_t mesg;
-  init_rrc_msg_head(&(mesg.head),inst,RRC_RB_MODIFY_CFM, sizeof( rrc_rb_modify_cfm_t ) ,Trans_id);
-  P_rb_md_cfm.Rb_id        = Rb_id ;
-  mesg.data = (char *) &P_rb_md_cfm ;
-  return &mesg ;
-
-}
-
-/*!
-*******************************************************************************
-\brief  La fonction formate en un message les parametres de la fonction
-          rrc_rb_release_resp().
-\return message formate
-*/
-msg_t *msg_rrc_rb_release_resp(
-  Instance_t    inst     , //!< Instance ID
-  Transaction_t Trans_id   //!< Transaction ID
-)
-{
-  return msg_rrc_generic_resp( inst,RRC_RB_RELEASE_RESP, Trans_id) ;
-}
-/*!
-*******************************************************************************
-\brief  La fonction formate en un message les parametres de la fonction
-        rrc_MR_attach_ind().
-\return message formate
-*/
-rrc_MR_attach_ind_t P_att_ind;
-msg_t * msg_rrc_MR_attach_ind(
-  Instance_t    inst     , //!< Instance ID
-  L2_ID         L2_id
-)
-{
-  // msg_t mesg;
-  init_rrc_msg_head(&(mesg.head),inst,RRC_MR_ATTACH_IND, sizeof( rrc_MR_attach_ind_t ) ,0);
-  memcpy( P_att_ind.L2_id.L2_id, L2_id.L2_id, sizeof(L2_ID) )  ;
-  mesg.data = (char *) &P_att_ind ;
-  return &mesg ;
-}
-
-/*!
-*******************************************************************************
-\brief  La fonction formate en un message les parametres de la fonction
-        rrc_sensing_meas_resp().
-\return message formate
-*/
-msg_t *msg_rrc_sensing_meas_resp(
-  Instance_t    inst     , //!< Instance ID
-  Transaction_t Trans_id   //!< Transaction ID
-)
-{
-  return msg_rrc_generic_resp( inst,RRC_SENSING_MEAS_RESP, Trans_id) ;
-}
-/*!
-*******************************************************************************
-\brief  La fonction formate en un message les parametres de la fonction
-        rrc_cx_establish_ind().
-\return message formate
-*/
-rrc_cx_establish_ind_t P_cx_est_ind;
-msg_t * msg_rrc_cx_establish_ind(
-  Instance_t     inst      , //!< Instance ID
-  L2_ID          L2_id     , //!< Layer 2 (MAC) ID
-  Transaction_t  Trans_id  , //!< Transaction ID
-  unsigned char *L3_info   , //!< Optional L3 Information
-  L3_INFO_T      L3_info_t , //!< Type of L3 Information
-  RB_ID          DTCH_B_id , //!< RBID of broadcast IP service (MR only)
-  RB_ID          DTCH_id     //!< RBID of default IP service (MR only)
-)
-{
-  //msg_t mesg;
-  init_rrc_msg_head(&(mesg.head),inst,RRC_CX_ESTABLISH_IND, sizeof( rrc_cx_establish_ind_t ) ,Trans_id);
-  memcpy( P_cx_est_ind.L2_id.L2_id, L2_id.L2_id, sizeof(L2_ID) )  ;
-  P_cx_est_ind.DTCH_B_id    = DTCH_B_id ;
-  P_cx_est_ind.DTCH_id      = DTCH_id   ;
-  P_cx_est_ind.L3_info_t    = L3_info_t ;
-
-  if ( L3_info_t == IPv4_ADDR ) {
-    memcpy( P_cx_est_ind.L3_info, L3_info, 4 );
-  } else if ( L3_info_t == IPv6_ADDR ) {
-    memcpy( P_cx_est_ind.L3_info, L3_info, 16 );
-  }
-
-  mesg.data = (char *) &P_cx_est_ind ;
-  return &mesg ;
-}
-/*!
-*******************************************************************************
-\brief  La fonction formate en un message les parametres de la fonction
-        rrc_phy_synch_to_MR_ind().
-\return message formate
-*/
-rrc_phy_synch_to_MR_ind_t P_snc_mr;
-msg_t * msg_rrc_phy_synch_to_MR_ind(
-  Instance_t     inst  , //!< Instance ID
-  L2_ID          L2_id
-)
-{
-  //msg_t smsg;
-  init_rrc_msg_head(&(mesg.head),inst,RRC_PHY_SYNCH_TO_MR_IND, sizeof( rrc_phy_synch_to_MR_ind_t ) ,0);
-  memcpy(&P_snc_mr.L2_id,(L2_ID*)&L2_id,sizeof(L2_ID));
-  mesg.data = (char *)&P_snc_mr ;
-  msg("[msg_rrc_phy_synch_to_MR_ind] from Inst :%d\n",mesg.head.inst);
-  return &mesg ;
-}
-/*!
-*******************************************************************************
-\brief  La fonction formate en un message les parametres de la fonction
-          rrc_phy_synch_to_CH_ind().
-\return message formate
-*/
-rrc_phy_synch_to_CH_ind_t P_snc_ch;
-msg_t * msg_rrc_phy_synch_to_CH_ind(
-  Instance_t   inst      , //!< Instance ID
-  unsigned int Ch_index  , //!< Clusterhead index
-  L2_ID        L2_id
-)
-{
-  //  msg_t smsg;
-  init_rrc_msg_head(&(mesg.head),inst, RRC_PHY_SYNCH_TO_CH_IND, sizeof( rrc_phy_synch_to_CH_ind_t ) ,0);
-  P_snc_ch.Ch_index     = Ch_index  ;
-  memcpy(&P_snc_ch.L2_id,(L2_ID*)&L2_id,sizeof(L2_ID));
-  mesg.data = (char *) &P_snc_ch;
-  msg("[msg_rrc_phy_synch_to_CH_ind] from Inst :%d\n",mesg.head.inst);
-  return &mesg ;
-}
-
-/*!
-*******************************************************************************
-\brief  La fonction formate en un message les parametres de la fonction
-          rrc_sensing_meas_ind().
-\return message formate
-*/
-rrc_sensing_meas_ind_t P_sens_ind;
-msg_t * msg_rrc_sensing_meas_ind(
-  Instance_t      inst         , //!< Instance ID
-  L2_ID           L2_id        , //!< Layer 2 ID (MAC) of sensing node
-  unsigned int    NB_meas      , //!< Layer 2 ID (MAC) of sensing node
-  SENSING_MEAS_T *Sensing_meas , //!< Sensing Information
-  Transaction_t   Trans_id       //!< Transaction ID
-)
-{
-
-  //  msg_t mesg;
-  unsigned int size = sizeof( rrc_sensing_meas_ind_t ) + (NB_meas-1) * sizeof(SENSING_MEAS_T) ;
-  // Note : (NB_meas-1) car la première est incorporé dans  rrc_sensing_meas_ind_t
-  init_rrc_msg_head(&(mesg.head),inst, RRC_SENSING_MEAS_IND, size ,Trans_id);
-  memcpy( P_sens_ind.L2_id.L2_id, L2_id.L2_id, sizeof(L2_ID) )  ;
-
-  if ( NB_meas > 0 ) {
-    memcpy( P_sens_ind.Sensing_meas , Sensing_meas, NB_meas * sizeof(SENSING_MEAS_T) )  ;
-  }
-
-  P_sens_ind.NB_meas      = NB_meas   ;
-  mesg.data = (char *) &P_sens_ind ;
-  return &mesg ;
-}
-
-/*!
-*******************************************************************************
-\brief  La fonction formate en un message les parametres de la fonction
-        rrc_rb_meas_ind().
-\return message formate
-*/
-rrc_rb_meas_ind_t P_rb_meas;
-msg_t * msg_rrc_rb_meas_ind(
-  Instance_t      inst         , //!< Instance ID
-  RB_ID           Rb_id        , //!< Radio Bearer ID
-  L2_ID           L2_id        , //!< Layer 2 (MAC) IDs for link
-  MEAS_MODE       Meas_mode    , //!< Measurement mode (periodic or event-driven)
-  MAC_RLC_MEAS_T *Mac_rlc_meas , //!< MAC/RLC measurements
-  Transaction_t   Trans_id       //!< Transaction ID
-)
-{
-  //msg_t mesg;
-  init_rrc_msg_head(&(mesg.head),inst, RRC_RB_MEAS_IND, sizeof( rrc_rb_meas_ind_t ) ,Trans_id);
-  memcpy( P_rb_meas.L2_id.L2_id, L2_id.L2_id, sizeof(L2_ID) )  ;
-  memcpy( &(P_rb_meas.Mac_rlc_meas), Mac_rlc_meas, sizeof(L2_ID) )  ;
-  P_rb_meas.Rb_id        = Rb_id     ;
-  P_rb_meas.Meas_mode    = Meas_mode ;
-  mesg.data = (char *) &P_rb_meas;
-  return &mesg ;
-
-}
-
-
-
-/*****************************************************************************/
-rrc_init_scan_req_t P_init_scan;
-msg_t * msg_rrc_init_scan_req(
-  Instance_t      inst         , //!< Instance ID
-  L2_ID           L2_id        , //!< Layer 2 (MAC) IDs for link
-  unsigned int Interv
-)
-{
-  //msg_t mesg;
-  msg("RRCI: inst %d sendind rrc_init_scan_req from FC %d %d\n",inst,L2_id.L2_id[0],L2_id.L2_id[7]);
-  init_rrc_msg_head(&(mesg.head),inst, RRC_INIT_SCAN_REQ, sizeof( rrc_init_scan_req_t ) ,0);
-  memcpy( &P_init_scan.L2_id.L2_id[0], &L2_id.L2_id[0], sizeof(L2_ID) )  ;
-  P_init_scan.interv=Interv;
-
-  return &mesg ;
-
-}
-
-
-
-/*****************************************************************************/
-
-rrc_update_sens_t P_update_sens;
-msg_t * msg_rrc_update_sens(
-  Instance_t      inst         , //!< Instance ID
-  Sens_ch_t *Sens,
-  L2_ID L2_id,
-  unsigned char NB_info
-)
-{
-  //msg_t mesg;
-  init_rrc_msg_head(&(mesg.head),inst, RRC_UPDATE_SENS, sizeof( rrc_update_sens_t ) ,0);
-  memcpy( &P_update_sens.L2_id.L2_id[0], &L2_id.L2_id[0], sizeof(L2_ID) )  ;
-  memcpy( &P_update_sens.Sens_meas[0], (rrc_update_sens_t *)Sens, NB_info*sizeof(Sens_ch_t) )  ;
-  P_update_sens.NB_info=NB_info;
-  return &mesg ;
-
-}
-
-
-
-/*****************************************************************************/
-
-rrc_end_scan_req_t P_end_scan;
-msg_t * msg_rrc_end_scan_req(
-  Instance_t      inst         , //!< Instance ID
-  unsigned char CH_index
-)
-{
-
-  //msg_t mesg;
-  msg("RRC: send END_SCAN_REQ, INST %d\n",inst);
-  init_rrc_msg_head(&(mesg.head),inst, RRC_END_SCAN_REQ, sizeof( rrc_end_scan_req_t ) ,0);
-  P_update_sens.L2_id.L2_id[0]=CH_index;
-  return &mesg ;
-
-}
-
diff --git a/openair2/RRC/LTE/rrc_UE.c b/openair2/RRC/LTE/rrc_UE.c
index b111f77871c1292afa40a366b8b2506dcfd2e23b..49f9e1674051dbaa753e388ebc1749e9f063dff2 100644
--- a/openair2/RRC/LTE/rrc_UE.c
+++ b/openair2/RRC/LTE/rrc_UE.c
@@ -44,33 +44,33 @@
 #include "common/utils/LOG/log.h"
 #include "common/utils/LOG/vcd_signal_dumper.h"
 #ifndef CELLULAR
-#include "RRC/LTE/MESSAGES/asn1_msg.h"
-#endif
-#include "RRCConnectionRequest.h"
-#include "RRCConnectionReconfiguration.h"
-#include "UL-CCCH-Message.h"
-#include "DL-CCCH-Message.h"
-#include "UL-DCCH-Message.h"
-#include "DL-DCCH-Message.h"
-#include "BCCH-DL-SCH-Message.h"
-#include "PCCH-Message.h"
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-#include "MCCH-Message.h"
-#endif
-#include "MeasConfig.h"
-#include "MeasGapConfig.h"
-#include "MeasObjectEUTRA.h"
-#include "TDD-Config.h"
-#include "UECapabilityEnquiry.h"
-#include "UE-CapabilityRequest.h"
+  #include "RRC/LTE/MESSAGES/asn1_msg.h"
+#endif
+#include "LTE_RRCConnectionRequest.h"
+#include "LTE_RRCConnectionReconfiguration.h"
+#include "LTE_UL-CCCH-Message.h"
+#include "LTE_DL-CCCH-Message.h"
+#include "LTE_UL-DCCH-Message.h"
+#include "LTE_DL-DCCH-Message.h"
+#include "LTE_BCCH-DL-SCH-Message.h"
+#include "LTE_PCCH-Message.h"
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+  #include "LTE_MCCH-Message.h"
+#endif
+#include "LTE_MeasConfig.h"
+#include "LTE_MeasGapConfig.h"
+#include "LTE_MeasObjectEUTRA.h"
+#include "LTE_TDD-Config.h"
+#include "LTE_UECapabilityEnquiry.h"
+#include "LTE_UE-CapabilityRequest.h"
 #include "RRC/NAS/nas_config.h"
 #include "RRC/NAS/rb_config.h"
 #if ENABLE_RAL
-#include "rrc_UE_ral.h"
+  #include "rrc_UE_ral.h"
 #endif
 
 #if defined(ENABLE_SECURITY)
-# include "UTIL/OSA/osa_defs.h"
+  #include "UTIL/OSA/osa_defs.h"
 #endif
 
 #include "pdcp.h"
@@ -78,60 +78,60 @@
 #include "msc.h"
 
 #if defined(ENABLE_ITTI)
-# include "intertask_interface.h"
+  #include "intertask_interface.h"
 #endif
 
 #include "SIMULATION/TOOLS/sim.h" // for taus
 
 #include "openair2/LAYER2/MAC/mac_extern.h"
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-#include "SL-Preconfiguration-r12.h"
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  #include "LTE_SL-Preconfiguration-r12.h"
 
-//for D2D
-int ctrl_sock_fd;
-#define BUFSIZE 1024
-struct sockaddr_in prose_app_addr;
-int slrb_id;
-int send_ue_information = 0;
+  //for D2D
+  int ctrl_sock_fd;
+  #define BUFSIZE 1024
+  struct sockaddr_in prose_app_addr;
+  int slrb_id;
+  int send_ue_information = 0;
 #endif
 
 // for malloc_clear
 #include "PHY/defs_UE.h"
 
 extern void pdcp_config_set_security(
-  const protocol_ctxt_t* const  ctxt_pP,
-  pdcp_t         * const pdcp_pP,
+  const protocol_ctxt_t *const  ctxt_pP,
+  pdcp_t          *const pdcp_pP,
   const rb_id_t         rb_idP,
   const uint16_t        lc_idP,
   const uint8_t         security_modeP,
-  uint8_t        * const kRRCenc,
-  uint8_t        * const kRRCint,
-  uint8_t        * const  kUPenc);
+  uint8_t         *const kRRCenc,
+  uint8_t         *const kRRCint,
+  uint8_t         *const  kUPenc);
 
 // internal prototypes
 
-void rrc_ue_process_securityModeCommand( const protocol_ctxt_t* const ctxt_pP, SecurityModeCommand_t* const securityModeCommand, const uint8_t eNB_index );
+void rrc_ue_process_securityModeCommand( const protocol_ctxt_t *const ctxt_pP, LTE_SecurityModeCommand_t *const securityModeCommand, const uint8_t eNB_index );
 
-static int decode_SI( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index );
+static int decode_SI( const protocol_ctxt_t *const ctxt_pP, const uint8_t eNB_index );
 
-static int decode_SIB1( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index, const uint8_t rsrq, const uint8_t rsrp );
+static int decode_SIB1( const protocol_ctxt_t *const ctxt_pP, const uint8_t eNB_index, const uint8_t rsrq, const uint8_t rsrp );
 
 /** \brief Generates/Encodes RRCConnnectionSetupComplete message at UE
  *  \param ctxt_pP Running context
  *  \param eNB_index Index of corresponding eNB/CH
  *  \param Transaction_id Transaction identifier
  */
-static void rrc_ue_generate_RRCConnectionSetupComplete( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index, const uint8_t Transaction_id );
+static void rrc_ue_generate_RRCConnectionSetupComplete( const protocol_ctxt_t *const ctxt_pP, const uint8_t eNB_index, const uint8_t Transaction_id );
 
 /** \brief Generates/Encodes RRCConnectionReconfigurationComplete message at UE
  *  \param ctxt_pP Running context
  *  \param eNB_index Index of corresponding eNB/CH
  *  \param Transaction_id RRC transaction identifier
  */
-static void rrc_ue_generate_RRCConnectionReconfigurationComplete( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index, const uint8_t Transaction_id );
+static void rrc_ue_generate_RRCConnectionReconfigurationComplete( const protocol_ctxt_t *const ctxt_pP, const uint8_t eNB_index, const uint8_t Transaction_id );
 
-static void rrc_ue_generate_MeasurementReport(protocol_ctxt_t* const ctxt_pP, uint8_t eNB_index );
+static void rrc_ue_generate_MeasurementReport(protocol_ctxt_t *const ctxt_pP, uint8_t eNB_index );
 
 static uint8_t check_trigger_meas_event(
   module_id_t module_idP,
@@ -139,12 +139,13 @@ static uint8_t check_trigger_meas_event(
   uint8_t eNB_index,
   uint8_t ue_cnx_index,
   uint8_t meas_index,
-  Q_OffsetRange_t ofn, Q_OffsetRange_t ocn, Hysteresis_t hys,
-  Q_OffsetRange_t ofs, Q_OffsetRange_t ocs, long a3_offset, TimeToTrigger_t ttt);
+  LTE_Q_OffsetRange_t ofn, LTE_Q_OffsetRange_t ocn, LTE_Hysteresis_t hys,
+  LTE_Q_OffsetRange_t ofs, LTE_Q_OffsetRange_t ocs, long a3_offset, LTE_TimeToTrigger_t ttt);
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 static void decode_MBSFNAreaConfiguration(module_id_t module_idP, uint8_t eNB_index, frame_t frameP,uint8_t mbsfn_sync_area);
-uint8_t rrc_ue_generate_SidelinkUEInformation( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index,SL_DestinationInfoList_r12_t  *destinationInfoList, long *discTxResourceReq, SL_TRIGGER_t mode);
+uint8_t rrc_ue_generate_SidelinkUEInformation( const protocol_ctxt_t *const ctxt_pP, const uint8_t eNB_index,LTE_SL_DestinationInfoList_r12_t  *destinationInfoList, long *discTxResourceReq,
+    SL_TRIGGER_t mode);
 #endif
 
 
@@ -157,36 +158,21 @@ uint8_t rrc_ue_generate_SidelinkUEInformation( const protocol_ctxt_t* const ctxt
 /*------------------------------------------------------------------------------*/
 /* to avoid gcc warnings when compiling with certain options */
 #if defined(ENABLE_USE_MME) || ENABLE_RAL
-static Rrc_State_t rrc_get_state (module_id_t ue_mod_idP)
-{
+static Rrc_State_t rrc_get_state (module_id_t ue_mod_idP) {
   return UE_rrc_inst[ue_mod_idP].RrcState;
 }
 #endif
 
-static Rrc_Sub_State_t rrc_get_sub_state (module_id_t ue_mod_idP)
-{
+static Rrc_Sub_State_t rrc_get_sub_state (module_id_t ue_mod_idP) {
   return UE_rrc_inst[ue_mod_idP].RrcSubState;
 }
 
-static int rrc_set_state (module_id_t ue_mod_idP, Rrc_State_t state)
-{
+static int rrc_set_state (module_id_t ue_mod_idP, Rrc_State_t state) {
   AssertFatal ((RRC_STATE_FIRST <= state) && (state <= RRC_STATE_LAST),
                "Invalid state %d!\n", state);
 
   if (UE_rrc_inst[ue_mod_idP].RrcState != state) {
     UE_rrc_inst[ue_mod_idP].RrcState = state;
-
-#if defined(ENABLE_ITTI)
-    {
-      MessageDef *msg_p;
-
-      msg_p = itti_alloc_new_message(TASK_RRC_UE, RRC_STATE_IND);
-      RRC_STATE_IND(msg_p).state = UE_rrc_inst[ue_mod_idP].RrcState;
-      RRC_STATE_IND(msg_p).sub_state = UE_rrc_inst[ue_mod_idP].RrcSubState;
-
-      itti_send_msg_to_task(TASK_UNKNOWN, UE_MODULE_ID_TO_INSTANCE(ue_mod_idP), msg_p);
-    }
-#endif
     return (1);
   }
 
@@ -194,43 +180,30 @@ static int rrc_set_state (module_id_t ue_mod_idP, Rrc_State_t state)
 }
 
 //-----------------------------------------------------------------------------
-static int rrc_set_sub_state( module_id_t ue_mod_idP, Rrc_Sub_State_t subState )
-{
+static int rrc_set_sub_state( module_id_t ue_mod_idP, Rrc_Sub_State_t subState ) {
 #if (defined(ENABLE_ITTI) && (defined(ENABLE_USE_MME) || ENABLE_RAL))
 
   switch (UE_rrc_inst[ue_mod_idP].RrcState) {
-  case RRC_STATE_INACTIVE:
-    AssertFatal ((RRC_SUB_STATE_INACTIVE_FIRST <= subState) && (subState <= RRC_SUB_STATE_INACTIVE_LAST),
-                 "Invalid sub state %d for state %d!\n", subState, UE_rrc_inst[ue_mod_idP].RrcState);
-    break;
-
-  case RRC_STATE_IDLE:
-    AssertFatal ((RRC_SUB_STATE_IDLE_FIRST <= subState) && (subState <= RRC_SUB_STATE_IDLE_LAST),
-                 "Invalid sub state %d for state %d!\n", subState, UE_rrc_inst[ue_mod_idP].RrcState);
-    break;
-
-  case RRC_STATE_CONNECTED:
-    AssertFatal ((RRC_SUB_STATE_CONNECTED_FIRST <= subState) && (subState <= RRC_SUB_STATE_CONNECTED_LAST),
-                 "Invalid sub state %d for state %d!\n", subState, UE_rrc_inst[ue_mod_idP].RrcState);
-    break;
+    case RRC_STATE_INACTIVE:
+      AssertFatal ((RRC_SUB_STATE_INACTIVE_FIRST <= subState) && (subState <= RRC_SUB_STATE_INACTIVE_LAST),
+                   "Invalid sub state %d for state %d!\n", subState, UE_rrc_inst[ue_mod_idP].RrcState);
+      break;
+
+    case RRC_STATE_IDLE:
+      AssertFatal ((RRC_SUB_STATE_IDLE_FIRST <= subState) && (subState <= RRC_SUB_STATE_IDLE_LAST),
+                   "Invalid sub state %d for state %d!\n", subState, UE_rrc_inst[ue_mod_idP].RrcState);
+      break;
+
+    case RRC_STATE_CONNECTED:
+      AssertFatal ((RRC_SUB_STATE_CONNECTED_FIRST <= subState) && (subState <= RRC_SUB_STATE_CONNECTED_LAST),
+                   "Invalid sub state %d for state %d!\n", subState, UE_rrc_inst[ue_mod_idP].RrcState);
+      break;
   }
 
 #endif
 
   if (UE_rrc_inst[ue_mod_idP].RrcSubState != subState) {
     UE_rrc_inst[ue_mod_idP].RrcSubState = subState;
-
-#if defined(ENABLE_ITTI)
-    {
-      MessageDef *msg_p;
-
-      msg_p = itti_alloc_new_message(TASK_RRC_UE, RRC_STATE_IND);
-      RRC_STATE_IND(msg_p).state = UE_rrc_inst[ue_mod_idP].RrcState;
-      RRC_STATE_IND(msg_p).sub_state = UE_rrc_inst[ue_mod_idP].RrcSubState;
-
-      itti_send_msg_to_task(TASK_UNKNOWN, UE_MODULE_ID_TO_INSTANCE(ue_mod_idP), msg_p);
-    }
-#endif
     return (1);
   }
 
@@ -240,96 +213,86 @@ static int rrc_set_sub_state( module_id_t ue_mod_idP, Rrc_Sub_State_t subState )
 //-----------------------------------------------------------------------------
 void
 openair_rrc_on_ue(
-  const protocol_ctxt_t* const ctxt_pP
+  const protocol_ctxt_t *const ctxt_pP
 )
 //-----------------------------------------------------------------------------
 {
   unsigned short i;
-
-
-    LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" UE?:OPENAIR RRC IN....\n",
-          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
-
-    for (i = 0; i < NB_eNB_INST; i++) {
-      LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" Activating CCCH (eNB %d)\n",
-            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP), i);
-      UE_rrc_inst[ctxt_pP->module_id].Srb0[i].Srb_id = CCCH;
-      memcpy (&UE_rrc_inst[ctxt_pP->module_id].Srb0[i].Lchan_desc[0], &CCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
-      memcpy (&UE_rrc_inst[ctxt_pP->module_id].Srb0[i].Lchan_desc[1], &CCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
-      rrc_config_buffer (&UE_rrc_inst[ctxt_pP->module_id].Srb0[i], CCCH, 1);
-      UE_rrc_inst[ctxt_pP->module_id].Srb0[i].Active = 1;
-    }
+  LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" UE?:OPENAIR RRC IN....\n",
+        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
+
+  for (i = 0; i < NB_eNB_INST; i++) {
+    LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" Activating CCCH (eNB %d)\n",
+          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP), i);
+    UE_rrc_inst[ctxt_pP->module_id].Srb0[i].Srb_id = CCCH;
+    memcpy (&UE_rrc_inst[ctxt_pP->module_id].Srb0[i].Lchan_desc[0], &CCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
+    memcpy (&UE_rrc_inst[ctxt_pP->module_id].Srb0[i].Lchan_desc[1], &CCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
+    rrc_config_buffer (&UE_rrc_inst[ctxt_pP->module_id].Srb0[i], CCCH, 1);
+    UE_rrc_inst[ctxt_pP->module_id].Srb0[i].Active = 1;
+  }
 }
 
 //-----------------------------------------------------------------------------
-static void init_SI_UE( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index )
-{
+static void init_SI_UE( const protocol_ctxt_t *const ctxt_pP, const uint8_t eNB_index ) {
   UE_rrc_inst[ctxt_pP->module_id].sizeof_SIB1[eNB_index] = 0;
   UE_rrc_inst[ctxt_pP->module_id].sizeof_SI[eNB_index] = 0;
-  UE_rrc_inst[ctxt_pP->module_id].SIB1[eNB_index] = (uint8_t*)malloc16_clear( 32 );
-  UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType1_t) );
-  UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType2_t) );
-  UE_rrc_inst[ctxt_pP->module_id].sib3[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType3_t) );
-  UE_rrc_inst[ctxt_pP->module_id].sib4[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType4_t) );
-  UE_rrc_inst[ctxt_pP->module_id].sib5[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType5_t) );
-  UE_rrc_inst[ctxt_pP->module_id].sib6[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType6_t) );
-  UE_rrc_inst[ctxt_pP->module_id].sib7[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType7_t) );
-  UE_rrc_inst[ctxt_pP->module_id].sib8[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType8_t) );
-  UE_rrc_inst[ctxt_pP->module_id].sib9[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType9_t) );
-  UE_rrc_inst[ctxt_pP->module_id].sib10[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType10_t) );
-  UE_rrc_inst[ctxt_pP->module_id].sib11[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType11_t) );
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-  UE_rrc_inst[ctxt_pP->module_id].sib12[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType12_r9_t) );
-  UE_rrc_inst[ctxt_pP->module_id].sib13[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType13_r9_t) );
-  UE_rrc_inst[ctxt_pP->module_id].sib18[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType18_r12_t) );
-  UE_rrc_inst[ctxt_pP->module_id].sib19[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType19_r12_t) );
-  UE_rrc_inst[ctxt_pP->module_id].sib21[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType21_r14_t) );
-
-#endif
-  UE_rrc_inst[ctxt_pP->module_id].SI[eNB_index] = (uint8_t*)malloc16_clear( 64 );
-
-  UE_rrc_inst[ctxt_pP->module_id].si[eNB_index] = (SystemInformation_t*)malloc16_clear( sizeof(SystemInformation_t) );
-
+  UE_rrc_inst[ctxt_pP->module_id].SIB1[eNB_index] = (uint8_t *)malloc16_clear( 32 );
+  UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index] = malloc16_clear( sizeof(LTE_SystemInformationBlockType1_t) );
+  UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index] = malloc16_clear( sizeof(LTE_SystemInformationBlockType2_t) );
+  UE_rrc_inst[ctxt_pP->module_id].sib3[eNB_index] = malloc16_clear( sizeof(LTE_SystemInformationBlockType3_t) );
+  UE_rrc_inst[ctxt_pP->module_id].sib4[eNB_index] = malloc16_clear( sizeof(LTE_SystemInformationBlockType4_t) );
+  UE_rrc_inst[ctxt_pP->module_id].sib5[eNB_index] = malloc16_clear( sizeof(LTE_SystemInformationBlockType5_t) );
+  UE_rrc_inst[ctxt_pP->module_id].sib6[eNB_index] = malloc16_clear( sizeof(LTE_SystemInformationBlockType6_t) );
+  UE_rrc_inst[ctxt_pP->module_id].sib7[eNB_index] = malloc16_clear( sizeof(LTE_SystemInformationBlockType7_t) );
+  UE_rrc_inst[ctxt_pP->module_id].sib8[eNB_index] = malloc16_clear( sizeof(LTE_SystemInformationBlockType8_t) );
+  UE_rrc_inst[ctxt_pP->module_id].sib9[eNB_index] = malloc16_clear( sizeof(LTE_SystemInformationBlockType9_t) );
+  UE_rrc_inst[ctxt_pP->module_id].sib10[eNB_index] = malloc16_clear( sizeof(LTE_SystemInformationBlockType10_t) );
+  UE_rrc_inst[ctxt_pP->module_id].sib11[eNB_index] = malloc16_clear( sizeof(LTE_SystemInformationBlockType11_t) );
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+  UE_rrc_inst[ctxt_pP->module_id].sib12[eNB_index] = malloc16_clear( sizeof(LTE_SystemInformationBlockType12_r9_t) );
+  UE_rrc_inst[ctxt_pP->module_id].sib13[eNB_index] = malloc16_clear( sizeof(LTE_SystemInformationBlockType13_r9_t) );
+  UE_rrc_inst[ctxt_pP->module_id].sib18[eNB_index] = malloc16_clear( sizeof(LTE_SystemInformationBlockType18_r12_t) );
+  UE_rrc_inst[ctxt_pP->module_id].sib19[eNB_index] = malloc16_clear( sizeof(LTE_SystemInformationBlockType19_r12_t) );
+  UE_rrc_inst[ctxt_pP->module_id].sib21[eNB_index] = malloc16_clear( sizeof(LTE_SystemInformationBlockType21_r14_t) );
+#endif
+  UE_rrc_inst[ctxt_pP->module_id].SI[eNB_index] = (uint8_t *)malloc16_clear( 64 );
+  UE_rrc_inst[ctxt_pP->module_id].si[eNB_index] = (LTE_SystemInformation_t *)malloc16_clear( sizeof(LTE_SystemInformation_t) );
   UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus = 0;
   UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIcnt    = 0;
 }
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-void init_SL_preconfig(UE_RRC_INST *UE, const uint8_t eNB_index )
-{
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+void init_SL_preconfig(UE_RRC_INST *UE, const uint8_t eNB_index ) {
   LOG_I(RRC,"Initializing Sidelink Pre-configuration for UE\n");
-
-  UE->SL_Preconfiguration[eNB_index] = malloc16_clear( sizeof(struct SL_Preconfiguration_r12) );
+  UE->SL_Preconfiguration[eNB_index] = malloc16_clear( sizeof(struct LTE_SL_Preconfiguration_r12) );
   UE->SL_Preconfiguration[eNB_index]->preconfigGeneral_r12.rohc_Profiles_r12.profile0x0001_r12       = true;
   UE->SL_Preconfiguration[eNB_index]->preconfigGeneral_r12.carrierFreq_r12                           = 3350;
   UE->SL_Preconfiguration[eNB_index]->preconfigGeneral_r12.maxTxPower_r12                            = 0;
   UE->SL_Preconfiguration[eNB_index]->preconfigGeneral_r12.additionalSpectrumEmission_r12            = 0;
-  UE->SL_Preconfiguration[eNB_index]->preconfigGeneral_r12.sl_bandwidth_r12                          = SL_PreconfigGeneral_r12__sl_bandwidth_r12_n50;
-  UE->SL_Preconfiguration[eNB_index]->preconfigGeneral_r12.tdd_ConfigSL_r12.subframeAssignmentSL_r12 = TDD_ConfigSL_r12__subframeAssignmentSL_r12_none;
-
-  UE->SL_Preconfiguration[eNB_index]->preconfigSync_r12.syncCP_Len_r12            = SL_CP_Len_r12_normal;
+  UE->SL_Preconfiguration[eNB_index]->preconfigGeneral_r12.sl_bandwidth_r12                          = LTE_SL_PreconfigGeneral_r12__sl_bandwidth_r12_n50;
+  UE->SL_Preconfiguration[eNB_index]->preconfigGeneral_r12.tdd_ConfigSL_r12.subframeAssignmentSL_r12 = LTE_TDD_ConfigSL_r12__subframeAssignmentSL_r12_none;
+  UE->SL_Preconfiguration[eNB_index]->preconfigSync_r12.syncCP_Len_r12            = LTE_SL_CP_Len_r12_normal;
   UE->SL_Preconfiguration[eNB_index]->preconfigSync_r12.syncOffsetIndicator1_r12  = 0;
   UE->SL_Preconfiguration[eNB_index]->preconfigSync_r12.syncOffsetIndicator2_r12  = 0;
   UE->SL_Preconfiguration[eNB_index]->preconfigSync_r12.syncTxParameters_r12      = 0;
   UE->SL_Preconfiguration[eNB_index]->preconfigSync_r12.syncTxThreshOoC_r12       = 0;
-  UE->SL_Preconfiguration[eNB_index]->preconfigSync_r12.filterCoefficient_r12     = FilterCoefficient_fc0;
-  UE->SL_Preconfiguration[eNB_index]->preconfigSync_r12.syncRefMinHyst_r12        = SL_PreconfigSync_r12__syncRefMinHyst_r12_dB0;
-  UE->SL_Preconfiguration[eNB_index]->preconfigSync_r12.syncRefDiffHyst_r12       = SL_PreconfigSync_r12__syncRefDiffHyst_r12_dB0;
-  UE->SL_Preconfiguration[eNB_index]->preconfigSync_r12.ext1                      = malloc16_clear(sizeof(struct SL_PreconfigSync_r12__ext1));
+  UE->SL_Preconfiguration[eNB_index]->preconfigSync_r12.filterCoefficient_r12     = LTE_FilterCoefficient_fc0;
+  UE->SL_Preconfiguration[eNB_index]->preconfigSync_r12.syncRefMinHyst_r12        = LTE_SL_PreconfigSync_r12__syncRefMinHyst_r12_dB0;
+  UE->SL_Preconfiguration[eNB_index]->preconfigSync_r12.syncRefDiffHyst_r12       = LTE_SL_PreconfigSync_r12__syncRefDiffHyst_r12_dB0;
+  UE->SL_Preconfiguration[eNB_index]->preconfigSync_r12.ext1                      = malloc16_clear(sizeof(struct LTE_SL_PreconfigSync_r12__ext1));
   UE->SL_Preconfiguration[eNB_index]->preconfigSync_r12.ext1->syncTxPeriodic_r13  = NULL;
-
-  struct SL_PreconfigCommPool_r12 *preconfigpool = malloc16_clear(sizeof(struct SL_PreconfigCommPool_r12));
-  preconfigpool->sc_CP_Len_r12                                                    = SL_CP_Len_r12_normal;
-  preconfigpool->sc_Period_r12                                                    = SL_PeriodComm_r12_sf40;
+  struct LTE_SL_PreconfigCommPool_r12 *preconfigpool = malloc16_clear(sizeof(struct LTE_SL_PreconfigCommPool_r12));
+  preconfigpool->sc_CP_Len_r12                                                    = LTE_SL_CP_Len_r12_normal;
+  preconfigpool->sc_Period_r12                                                    = LTE_SL_PeriodComm_r12_sf40;
   // 20 PRBs for SL communications
   preconfigpool->sc_TF_ResourceConfig_r12.prb_Num_r12                             = 20;
   preconfigpool->sc_TF_ResourceConfig_r12.prb_Start_r12                           = 5;
   preconfigpool->sc_TF_ResourceConfig_r12.prb_End_r12                             = 44;
   // Offset set to 0 subframes
-  preconfigpool->sc_TF_ResourceConfig_r12.offsetIndicator_r12.present             = SL_OffsetIndicator_r12_PR_small_r12;
+  preconfigpool->sc_TF_ResourceConfig_r12.offsetIndicator_r12.present             = LTE_SL_OffsetIndicator_r12_PR_small_r12;
   preconfigpool->sc_TF_ResourceConfig_r12.offsetIndicator_r12.choice.small_r12    = 0;
   // 40 ms SL Period
-  preconfigpool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.present              = SubframeBitmapSL_r12_PR_bs40_r12;
+  preconfigpool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.present              = LTE_SubframeBitmapSL_r12_PR_bs40_r12;
   preconfigpool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.buf         = CALLOC(1,5);
   preconfigpool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.size        = 5;
   preconfigpool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.bits_unused = 0;
@@ -340,17 +303,16 @@ void init_SL_preconfig(UE_RRC_INST *UE, const uint8_t eNB_index )
   preconfigpool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.buf[3]      = 0;
   preconfigpool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.buf[4]      = 0;
   preconfigpool->sc_TxParameters_r12                                              = 0;
-
-  preconfigpool->data_CP_Len_r12                                                  = SL_CP_Len_r12_normal;
+  preconfigpool->data_CP_Len_r12                                                  = LTE_SL_CP_Len_r12_normal;
   // 20 PRBs for SL communications
   preconfigpool->data_TF_ResourceConfig_r12.prb_Num_r12                             = 20;
   preconfigpool->data_TF_ResourceConfig_r12.prb_Start_r12                           = 5;
   preconfigpool->data_TF_ResourceConfig_r12.prb_End_r12                             = 44;
   // Offset set to 0 subframes
-  preconfigpool->data_TF_ResourceConfig_r12.offsetIndicator_r12.present             = SL_OffsetIndicator_r12_PR_small_r12;
+  preconfigpool->data_TF_ResourceConfig_r12.offsetIndicator_r12.present             = LTE_SL_OffsetIndicator_r12_PR_small_r12;
   preconfigpool->data_TF_ResourceConfig_r12.offsetIndicator_r12.choice.small_r12    = 0;
   // 40 ms SL Period
-  preconfigpool->data_TF_ResourceConfig_r12.subframeBitmap_r12.present              = SubframeBitmapSL_r12_PR_bs40_r12;
+  preconfigpool->data_TF_ResourceConfig_r12.subframeBitmap_r12.present              = LTE_SubframeBitmapSL_r12_PR_bs40_r12;
   preconfigpool->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.buf         = CALLOC(1,5);
   preconfigpool->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.size        = 5;
   preconfigpool->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.bits_unused = 0;
@@ -360,123 +322,117 @@ void init_SL_preconfig(UE_RRC_INST *UE, const uint8_t eNB_index )
   preconfigpool->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.buf[2]      = 0xFF;
   preconfigpool->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.buf[3]      = 0xFF;
   preconfigpool->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.buf[5]      = 0xFF;
-
   preconfigpool->dataHoppingConfig_r12.hoppingParameter_r12                         = 0;
-  preconfigpool->dataHoppingConfig_r12.numSubbands_r12                              = SL_HoppingConfigComm_r12__numSubbands_r12_ns1;
+  preconfigpool->dataHoppingConfig_r12.numSubbands_r12                              = LTE_SL_HoppingConfigComm_r12__numSubbands_r12_ns1;
   preconfigpool->dataHoppingConfig_r12.rb_Offset_r12                                = 0;
-
   preconfigpool->dataTxParameters_r12                                               = 0;
-
   ASN_SEQUENCE_ADD(&UE->SL_Preconfiguration[eNB_index]->preconfigComm_r12.list,preconfigpool);
-
   // Rel13 extensions
   UE->SL_Preconfiguration[eNB_index]->ext1 = NULL;
-/*
-  // Establish a SLRB (using DRB 3 for now)
-  protocol_ctxt_t ctxt;
-  PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, 0, ENB_FLAG_NO, 0x1234, 0, 0,0);
-
-  UE->DRB_config[0][0] = CALLOC(1,sizeof(struct DRB_ToAddMod));
-  UE->DRB_config[0][0]->eps_BearerIdentity = CALLOC(1, sizeof(long));
-  UE->DRB_config[0][0]->drb_Identity =  3;
-  UE->DRB_config[0][0]->eps_BearerIdentity = CALLOC(1, sizeof(long));
-  // allowed value 5..15, value : x+4
-  *(UE->DRB_config[0][0]->eps_BearerIdentity) = 3;
-  UE->DRB_config[0][0]->logicalChannelIdentity = CALLOC(1, sizeof(long));
-  *(UE->DRB_config[0][0]->logicalChannelIdentity) = UE->DRB_config[0][0]->drb_Identity; //(long) (ue_context_pP->ue_context.e_rab[i].param.e_rab_id + 2); // value : x+2
-
-  // TTN - Establish a new SLRB for PC5-S (using DRB 10 for now)
-  UE->DRB_config[0][1] = CALLOC(1,sizeof(struct DRB_ToAddMod));
-  UE->DRB_config[0][1]->eps_BearerIdentity = CALLOC(1, sizeof(long));
-  UE->DRB_config[0][1]->drb_Identity =  10;
-  UE->DRB_config[0][1]->eps_BearerIdentity = CALLOC(1, sizeof(long));
-  // allowed value 5..15, value : x+4
-  *(UE->DRB_config[0][1]->eps_BearerIdentity) = 10;
-  UE->DRB_config[0][1]->logicalChannelIdentity = CALLOC(1, sizeof(long));
-  *(UE->DRB_config[0][1]->logicalChannelIdentity) = UE->DRB_config[0][1]->drb_Identity; //(long) (ue_context_pP->ue_context.e_rab[i].param.e_rab_id + 2); // value : x+2
-
-  struct RLC_Config                  *DRB_rlc_config                   = CALLOC(1,sizeof(struct RLC_Config));
-  struct PDCP_Config                 *DRB_pdcp_config                  = CALLOC(1,sizeof(struct PDCP_Config));
-  struct PDCP_Config__rlc_UM         *PDCP_rlc_UM                      = CALLOC(1,sizeof(struct PDCP_Config__rlc_UM));
-  struct LogicalChannelConfig        *DRB_lchan_config                 = CALLOC(1,sizeof(struct LogicalChannelConfig));
-  struct LogicalChannelConfig__ul_SpecificParameters
-    *DRB_ul_SpecificParameters                                         = CALLOC(1, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
-  long                               *logicalchannelgroup_drb          = CALLOC(1, sizeof(long));
-
-  DRB_rlc_config->present = RLC_Config_PR_um_Bi_Directional;
-  DRB_rlc_config->choice.um_Bi_Directional.ul_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
-  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
-  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = T_Reordering_ms35;
-  UE->DRB_config[0][0]->rlc_Config = DRB_rlc_config;
-  UE->DRB_config[0][1]->rlc_Config = DRB_rlc_config;
-
-  DRB_pdcp_config = CALLOC(1, sizeof(*DRB_pdcp_config));
-  UE->DRB_config[0][0]->pdcp_Config = DRB_pdcp_config;
-  UE->DRB_config[0][1]->pdcp_Config = DRB_pdcp_config;
-  DRB_pdcp_config->discardTimer = CALLOC(1, sizeof(long));
-  *DRB_pdcp_config->discardTimer = PDCP_Config__discardTimer_infinity;
-  DRB_pdcp_config->rlc_AM = NULL;
-  DRB_pdcp_config->rlc_UM = NULL;
-
-  // avoid gcc warnings
-  (void)PDCP_rlc_UM;
-
-  DRB_pdcp_config->rlc_UM = PDCP_rlc_UM;
-  PDCP_rlc_UM->pdcp_SN_Size = PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits;
-  DRB_pdcp_config->headerCompression.present = PDCP_Config__headerCompression_PR_notUsed;
-
-  UE->DRB_config[0][0]->logicalChannelConfig = DRB_lchan_config;
-  UE->DRB_config[0][1]->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 = 12;    // lower priority than srb1, srb2 and other dedicated bearer
-  DRB_ul_SpecificParameters->prioritisedBitRate =LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_kBps8 ;
-    //LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
-  DRB_ul_SpecificParameters->bucketSizeDuration =
-    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 = 1;
-  DRB_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup_drb;
-
-  UE->DRB_configList = CALLOC(1,sizeof(DRB_ToAddModList_t));
-  ASN_SEQUENCE_ADD(&UE->DRB_configList->list,UE->DRB_config[0][0]);
-  ASN_SEQUENCE_ADD(&UE->DRB_configList->list,UE->DRB_config[0][1]);
-
-  rrc_pdcp_config_asn1_req(&ctxt,
-			   (SRB_ToAddModList_t *) NULL,
-			   UE->DRB_configList,
-			   (DRB_ToReleaseList_t*) NULL,
-			   0xff, NULL, NULL, NULL
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-                           , (PMCH_InfoList_r9_t *) NULL
-#endif
-                           ,NULL);
+  /*
+    // Establish a SLRB (using DRB 3 for now)
+    protocol_ctxt_t ctxt;
+    PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, 0, ENB_FLAG_NO, 0x1234, 0, 0,0);
+
+    UE->DRB_config[0][0] = CALLOC(1,sizeof(struct DRB_ToAddMod));
+    UE->DRB_config[0][0]->eps_BearerIdentity = CALLOC(1, sizeof(long));
+    UE->DRB_config[0][0]->drb_Identity =  3;
+    UE->DRB_config[0][0]->eps_BearerIdentity = CALLOC(1, sizeof(long));
+    // allowed value 5..15, value : x+4
+    *(UE->DRB_config[0][0]->eps_BearerIdentity) = 3;
+    UE->DRB_config[0][0]->logicalChannelIdentity = CALLOC(1, sizeof(long));
+    *(UE->DRB_config[0][0]->logicalChannelIdentity) = UE->DRB_config[0][0]->drb_Identity; //(long) (ue_context_pP->ue_context.e_rab[i].param.e_rab_id + 2); // value : x+2
+
+    // TTN - Establish a new SLRB for PC5-S (using DRB 10 for now)
+    UE->DRB_config[0][1] = CALLOC(1,sizeof(struct DRB_ToAddMod));
+    UE->DRB_config[0][1]->eps_BearerIdentity = CALLOC(1, sizeof(long));
+    UE->DRB_config[0][1]->drb_Identity =  10;
+    UE->DRB_config[0][1]->eps_BearerIdentity = CALLOC(1, sizeof(long));
+    // allowed value 5..15, value : x+4
+    *(UE->DRB_config[0][1]->eps_BearerIdentity) = 10;
+    UE->DRB_config[0][1]->logicalChannelIdentity = CALLOC(1, sizeof(long));
+    *(UE->DRB_config[0][1]->logicalChannelIdentity) = UE->DRB_config[0][1]->drb_Identity; //(long) (ue_context_pP->ue_context.e_rab[i].param.e_rab_id + 2); // value : x+2
+
+    struct RLC_Config                  *DRB_rlc_config                   = CALLOC(1,sizeof(struct RLC_Config));
+    struct PDCP_Config                 *DRB_pdcp_config                  = CALLOC(1,sizeof(struct PDCP_Config));
+    struct PDCP_Config__rlc_UM         *PDCP_rlc_UM                      = CALLOC(1,sizeof(struct PDCP_Config__rlc_UM));
+    struct LogicalChannelConfig        *DRB_lchan_config                 = CALLOC(1,sizeof(struct LogicalChannelConfig));
+    struct LogicalChannelConfig__ul_SpecificParameters
+      *DRB_ul_SpecificParameters                                         = CALLOC(1, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
+    long                               *logicalchannelgroup_drb          = CALLOC(1, sizeof(long));
+
+    DRB_rlc_config->present = RLC_Config_PR_um_Bi_Directional;
+    DRB_rlc_config->choice.um_Bi_Directional.ul_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
+    DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
+    DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = T_Reordering_ms35;
+    UE->DRB_config[0][0]->rlc_Config = DRB_rlc_config;
+    UE->DRB_config[0][1]->rlc_Config = DRB_rlc_config;
+
+    DRB_pdcp_config = CALLOC(1, sizeof(*DRB_pdcp_config));
+    UE->DRB_config[0][0]->pdcp_Config = DRB_pdcp_config;
+    UE->DRB_config[0][1]->pdcp_Config = DRB_pdcp_config;
+    DRB_pdcp_config->discardTimer = CALLOC(1, sizeof(long));
+    *DRB_pdcp_config->discardTimer = PDCP_Config__discardTimer_infinity;
+    DRB_pdcp_config->rlc_AM = NULL;
+    DRB_pdcp_config->rlc_UM = NULL;
+
+    // avoid gcc warnings
+    (void)PDCP_rlc_UM;
+
+    DRB_pdcp_config->rlc_UM = PDCP_rlc_UM;
+    PDCP_rlc_UM->pdcp_SN_Size = PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits;
+    DRB_pdcp_config->headerCompression.present = PDCP_Config__headerCompression_PR_notUsed;
+
+    UE->DRB_config[0][0]->logicalChannelConfig = DRB_lchan_config;
+    UE->DRB_config[0][1]->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 = 12;    // lower priority than srb1, srb2 and other dedicated bearer
+    DRB_ul_SpecificParameters->prioritisedBitRate =LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_kBps8 ;
+      //LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
+    DRB_ul_SpecificParameters->bucketSizeDuration =
+      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 = 1;
+    DRB_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup_drb;
+
+    UE->DRB_configList = CALLOC(1,sizeof(DRB_ToAddModList_t));
+    ASN_SEQUENCE_ADD(&UE->DRB_configList->list,UE->DRB_config[0][0]);
+    ASN_SEQUENCE_ADD(&UE->DRB_configList->list,UE->DRB_config[0][1]);
+
+    rrc_pdcp_config_asn1_req(&ctxt,
+           (SRB_ToAddModList_t *) NULL,
+           UE->DRB_configList,
+           (DRB_ToReleaseList_t*) NULL,
+           0xff, NULL, NULL, NULL
+  #if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                             , (LTE_PMCH_InfoList_r9_t *) NULL
+  #endif
+                             ,NULL);
 
-  rrc_rlc_config_asn1_req(&ctxt,
-			  (SRB_ToAddModList_t*)NULL,
-			  UE->DRB_configList,
-			  (DRB_ToReleaseList_t*)NULL
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-			  ,(PMCH_InfoList_r9_t *)NULL
-#endif
-			  );
-*/
+    rrc_rlc_config_asn1_req(&ctxt,
+          (SRB_ToAddModList_t*)NULL,
+          UE->DRB_configList,
+          (DRB_ToReleaseList_t*)NULL
+  #if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+          ,(LTE_PMCH_InfoList_r9_t *)NULL
+  #endif
+          );
+  */
 }
 
 #endif
 
 //-----------------------------------------------------------------------------
-void openair_rrc_ue_init_security( const protocol_ctxt_t* const ctxt_pP )
-{
+void openair_rrc_ue_init_security( const protocol_ctxt_t *const ctxt_pP ) {
 #if defined(ENABLE_SECURITY)
   //    uint8_t *kRRCenc;
   //    uint8_t *kRRCint;
   char ascii_buffer[65];
   uint8_t i;
-
   memset(UE_rrc_inst[ctxt_pP->module_id].kenb, ctxt_pP->module_id, 32);
 
   for (i = 0; i < 32; i++) {
@@ -490,8 +446,7 @@ void openair_rrc_ue_init_security( const protocol_ctxt_t* const ctxt_pP )
 }
 
 //-----------------------------------------------------------------------------
-char openair_rrc_ue_init( const module_id_t ue_mod_idP, const unsigned char eNB_index )
-{
+char openair_rrc_ue_init( const module_id_t ue_mod_idP, const unsigned char eNB_index ) {
   protocol_ctxt_t ctxt;
   PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_idP, ENB_FLAG_NO, NOT_A_RNTI, 0, 0,eNB_index);
   LOG_I(RRC,
@@ -499,7 +454,6 @@ char openair_rrc_ue_init( const module_id_t ue_mod_idP, const unsigned char eNB_
         PROTOCOL_RRC_CTXT_ARGS(&ctxt));
   rrc_set_state (ue_mod_idP, RRC_STATE_INACTIVE);
   rrc_set_sub_state (ue_mod_idP, RRC_SUB_STATE_INACTIVE);
-
   LOG_I(RRC,"[UE %d] INIT State = RRC_IDLE (eNB %d)\n",ctxt.module_id,eNB_index);
   UE_rrc_inst[ctxt.module_id].Info[eNB_index].State=RRC_IDLE;
   UE_rrc_inst[ctxt.module_id].Info[eNB_index].T300_active = 0;
@@ -510,28 +464,22 @@ char openair_rrc_ue_init( const module_id_t ue_mod_idP, const unsigned char eNB_
   UE_rrc_inst[ctxt.module_id].Srb1[eNB_index].Active=0;
   UE_rrc_inst[ctxt.module_id].Srb2[eNB_index].Active=0;
   UE_rrc_inst[ctxt.module_id].HandoverInfoUe.measFlag=1;
-  UE_rrc_inst[ctxt.module_id].ciphering_algorithm = CipheringAlgorithm_r12_eea0;
-#if (RRC_VERSION >= MAKE_VERSION(9, 2, 0))
-  UE_rrc_inst[ctxt.module_id].integrity_algorithm = SecurityAlgorithmConfig__integrityProtAlgorithm_eia0_v920;
+  UE_rrc_inst[ctxt.module_id].ciphering_algorithm = LTE_CipheringAlgorithm_r12_eea0;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 2, 0))
+  UE_rrc_inst[ctxt.module_id].integrity_algorithm = LTE_SecurityAlgorithmConfig__integrityProtAlgorithm_eia0_v920;
 #else
-  UE_rrc_inst[ctxt.module_id].integrity_algorithm = SecurityAlgorithmConfig__integrityProtAlgorithm_reserved;
+  UE_rrc_inst[ctxt.module_id].integrity_algorithm = LTE_SecurityAlgorithmConfig__integrityProtAlgorithm_reserved;
 #endif
-
   openair_rrc_ue_init_security(&ctxt);
   init_SI_UE(&ctxt,eNB_index);
   LOG_D(RRC,PROTOCOL_RRC_CTXT_FMT"  INIT: phy_sync_2_ch_ind\n",
         PROTOCOL_RRC_CTXT_ARGS(&ctxt));
-
-
-
 #ifndef NO_RRM
   send_msg(&S_rrc,msg_rrc_phy_synch_to_CH_ind(ctxt.module_id,eNB_index,UE_rrc_inst[ctxt.module_id].Mac_id));
 #endif
-
 #ifndef NO_RRM
   send_msg(&S_rrc,msg_rrc_phy_synch_to_CH_ind(ctxt.module_id,eNB_index,UE_rrc_inst[ctxt.module_id].Mac_id));
 #endif
-
 #ifdef NO_RRM //init ch SRB0, SRB1 & BDTCH
   openair_rrc_on_ue(&ctxt);
 #endif
@@ -544,18 +492,14 @@ char openair_rrc_ue_init( const module_id_t ue_mod_idP, const unsigned char eNB_
 
   UE_rrc_inst[ue_mod_idP].num_active_cba_groups = 0;
 #endif
-
   return 0;
 }
 
 //-----------------------------------------------------------------------------
-void rrc_ue_generate_RRCConnectionRequest( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index )
-{
-
+void rrc_ue_generate_RRCConnectionRequest( const protocol_ctxt_t *const ctxt_pP, const uint8_t eNB_index ) {
   uint8_t i=0,rv[6];
 
   if(UE_rrc_inst[ctxt_pP->module_id].Srb0[eNB_index].Tx_buffer.payload_size ==0) {
-
     // Get RRCConnectionRequest, fill random for now
     // Generate random byte stream for contention resolution
     for (i=0; i<6; i++) {
@@ -572,9 +516,8 @@ void rrc_ue_generate_RRCConnectionRequest( const protocol_ctxt_t* const ctxt_pP,
     UE_rrc_inst[ctxt_pP->module_id].Srb0[eNB_index].Tx_buffer.payload_size =
       do_RRCConnectionRequest(
         ctxt_pP->module_id,
-        (uint8_t*)UE_rrc_inst[ctxt_pP->module_id].Srb0[eNB_index].Tx_buffer.Payload,
+        (uint8_t *)UE_rrc_inst[ctxt_pP->module_id].Srb0[eNB_index].Tx_buffer.Payload,
         rv);
-
     LOG_I(RRC,"[UE %d] : Frame %d, Logical Channel UL-CCCH (SRB0), Generating RRCConnectionRequest (bytes %d, eNB %d)\n",
           ctxt_pP->module_id, ctxt_pP->frame, UE_rrc_inst[ctxt_pP->module_id].Srb0[eNB_index].Tx_buffer.payload_size, eNB_index);
 
@@ -585,7 +528,6 @@ void rrc_ue_generate_RRCConnectionRequest( const protocol_ctxt_t* const ctxt_pP,
     LOG_T(RRC,"\n");
     /*UE_rrc_inst[ue_mod_idP].Srb0[Idx].Tx_buffer.Payload[i] = taus()&0xff;
     UE_rrc_inst[ue_mod_idP].Srb0[Idx].Tx_buffer.payload_size =i; */
-
   }
 }
 
@@ -611,12 +553,11 @@ static const char const nas_attach_req_imsi[] = {
 //-----------------------------------------------------------------------------
 void
 rrc_t310_expiration(
-  const protocol_ctxt_t* const ctxt_pP,
+  const protocol_ctxt_t *const ctxt_pP,
   const uint8_t                 eNB_index
 )
 //-----------------------------------------------------------------------------
 {
-
   if (UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].State != RRC_CONNECTED) {
     LOG_D(RRC, "Timer 310 expired, going to RRC_IDLE\n");
     UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].State = RRC_IDLE;
@@ -628,7 +569,7 @@ rrc_t310_expiration(
 
     if (UE_rrc_inst[ctxt_pP->module_id].Srb2[eNB_index].Active == 1) {
       LOG_D (RRC,"[Inst %d] eNB_index %d, Remove RB %d\n ", ctxt_pP->module_id, eNB_index,
-           UE_rrc_inst[ctxt_pP->module_id].Srb2[eNB_index].Srb_info.Srb_id);
+             UE_rrc_inst[ctxt_pP->module_id].Srb2[eNB_index].Srb_info.Srb_id);
       rrc_pdcp_config_req (ctxt_pP,
                            SRB_FLAG_YES,
                            CONFIG_ACTION_REMOVE,
@@ -650,43 +591,36 @@ rrc_t310_expiration(
 }
 
 //-----------------------------------------------------------------------------
-static void rrc_ue_generate_RRCConnectionSetupComplete( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index, const uint8_t Transaction_id )
-{
-
+static void rrc_ue_generate_RRCConnectionSetupComplete( const protocol_ctxt_t *const ctxt_pP, const uint8_t eNB_index, const uint8_t Transaction_id ) {
   uint8_t    buffer[100];
   uint8_t    size;
-  const char * nas_msg;
+  const char *nas_msg;
   int   nas_msg_length;
-
 #if defined(ENABLE_ITTI) && defined(ENABLE_USE_MME)
-  nas_msg         = (char*) UE_rrc_inst[ctxt_pP->module_id].initialNasMsg.data;
+  nas_msg         = (char *) UE_rrc_inst[ctxt_pP->module_id].initialNasMsg.data;
   nas_msg_length  = UE_rrc_inst[ctxt_pP->module_id].initialNasMsg.length;
 #else
   nas_msg         = nas_attach_req_imsi;
   nas_msg_length  = sizeof(nas_attach_req_imsi);
 #endif
-
   size = do_RRCConnectionSetupComplete(ctxt_pP->module_id, buffer, Transaction_id, nas_msg_length, nas_msg);
-
   LOG_I(RRC,"[UE %d][RAPROC] Frame %d : Logical Channel UL-DCCH (SRB1), Generating RRCConnectionSetupComplete (bytes%d, eNB %d)\n",
         ctxt_pP->module_id,ctxt_pP->frame, size, eNB_index);
   LOG_D(RLC,
         "[FRAME %05d][RRC_UE][MOD %02d][][--- PDCP_DATA_REQ/%d Bytes (RRCConnectionSetupComplete to eNB %d MUI %d) --->][PDCP][MOD %02d][RB %02d]\n",
         ctxt_pP->frame, ctxt_pP->module_id+NB_eNB_INST, size, eNB_index, rrc_mui, ctxt_pP->module_id+NB_eNB_INST, DCCH);
   rrc_data_req_ue (
-		ctxt_pP,
-		DCCH,
-		rrc_mui++,
-		SDU_CONFIRM_NO,
-		size,
-		buffer,
-		PDCP_TRANSMISSION_MODE_CONTROL);
+    ctxt_pP,
+    DCCH,
+    rrc_mui++,
+    SDU_CONFIRM_NO,
+    size,
+    buffer,
+    PDCP_TRANSMISSION_MODE_CONTROL);
 }
 
 //-----------------------------------------------------------------------------
-void rrc_ue_generate_RRCConnectionReconfigurationComplete( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index, const uint8_t Transaction_id )
-{
-
+void rrc_ue_generate_RRCConnectionReconfigurationComplete( const protocol_ctxt_t *const ctxt_pP, const uint8_t eNB_index, const uint8_t Transaction_id ) {
   uint8_t buffer[32], size;
   size = do_RRCConnectionReconfigurationComplete(ctxt_pP, buffer, Transaction_id);
   LOG_I(RRC,PROTOCOL_RRC_CTXT_UE_FMT" Logical Channel UL-DCCH (SRB1), Generating RRCConnectionReconfigurationComplete (bytes %d, eNB_index %d)\n",
@@ -701,65 +635,34 @@ void rrc_ue_generate_RRCConnectionReconfigurationComplete( const protocol_ctxt_t
         UE_MODULE_ID_TO_INSTANCE(ctxt_pP->module_id),
         DCCH);
   rrc_data_req_ue (
-		ctxt_pP,
-		DCCH,
-		rrc_mui++,
-		SDU_CONFIRM_NO,
-		size,
-		buffer,
-		PDCP_TRANSMISSION_MODE_CONTROL);
+    ctxt_pP,
+    DCCH,
+    rrc_mui++,
+    SDU_CONFIRM_NO,
+    size,
+    buffer,
+    PDCP_TRANSMISSION_MODE_CONTROL);
 }
 
 
 //-----------------------------------------------------------------------------
 // Called by L2 interface (MAC)
-int rrc_ue_decode_ccch( const protocol_ctxt_t* const ctxt_pP, const SRB_INFO* const Srb_info, const uint8_t eNB_index )
-{
-  DL_CCCH_Message_t* dl_ccch_msg=NULL;
+int rrc_ue_decode_ccch( const protocol_ctxt_t *const ctxt_pP, const SRB_INFO *const Srb_info, const uint8_t eNB_index ) {
+  LTE_DL_CCCH_Message_t *dl_ccch_msg=NULL;
   asn_dec_rval_t dec_rval;
   int rval=0;
-
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_CCCH, VCD_FUNCTION_IN);
   //  LOG_D(RRC,"[UE %d] Decoding DL-CCCH message (%d bytes), State %d\n",ue_mod_idP,Srb_info->Rx_buffer.payload_size,
   //  UE_rrc_inst[ue_mod_idP].Info[eNB_index].State);
-
   dec_rval = uper_decode(NULL,
-                         &asn_DEF_DL_CCCH_Message,
-                         (void**)&dl_ccch_msg,
-                         (uint8_t*)Srb_info->Rx_buffer.Payload,
+                         &asn_DEF_LTE_DL_CCCH_Message,
+                         (void **)&dl_ccch_msg,
+                         (uint8_t *)Srb_info->Rx_buffer.Payload,
                          100,0,0);
 
   if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-     xer_fprint(stdout,&asn_DEF_DL_CCCH_Message,(void*)dl_ccch_msg);
-  }
-
-#if defined(ENABLE_ITTI)
-# if defined(DISABLE_ITTI_XER_PRINT)
-  {
-    MessageDef *msg_p;
-
-    msg_p = itti_alloc_new_message (TASK_RRC_UE, RRC_DL_CCCH_MESSAGE);
-    memcpy (&msg_p->ittiMsg, (void *) dl_ccch_msg, sizeof(RrcDlCcchMessage));
-
-    itti_send_msg_to_task (TASK_UNKNOWN, ctxt_pP->instance, msg_p);
+    xer_fprint(stdout,&asn_DEF_LTE_DL_CCCH_Message,(void *)dl_ccch_msg);
   }
-# else
-  {
-    char        message_string[10000];
-    size_t      message_string_size;
-
-    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_CCCH_Message, (void *)dl_ccch_msg)) > 0) {
-      MessageDef *msg_p;
-
-      msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, RRC_DL_CCCH, message_string_size + sizeof (IttiMsgText));
-      msg_p->ittiMsg.rrc_dl_ccch.size = message_string_size;
-      memcpy(&msg_p->ittiMsg.rrc_dl_ccch.text, message_string, message_string_size);
-
-      itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
-    }
-  }
-# endif
-#endif
 
   if ((dec_rval.code != RC_OK) && (dec_rval.consumed==0)) {
     LOG_E(RRC,"[UE %d] Frame %d : Failed to decode DL-CCCH-Message (%zu bytes)\n",ctxt_pP->module_id,ctxt_pP->frame,dec_rval.consumed);
@@ -767,75 +670,69 @@ int rrc_ue_decode_ccch( const protocol_ctxt_t* const ctxt_pP, const SRB_INFO* co
     return -1;
   }
 
-  if (dl_ccch_msg->message.present == DL_CCCH_MessageType_PR_c1) {
-
+  if (dl_ccch_msg->message.present == LTE_DL_CCCH_MessageType_PR_c1) {
     if (UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].State == RRC_SI_RECEIVED) {
-
       switch (dl_ccch_msg->message.choice.c1.present) {
+        case LTE_DL_CCCH_MessageType__c1_PR_NOTHING:
+          LOG_I(RRC, "[UE%d] Frame %d : Received PR_NOTHING on DL-CCCH-Message\n",
+                ctxt_pP->module_id,
+                ctxt_pP->frame);
+          rval = 0;
+          break;
 
-      case DL_CCCH_MessageType__c1_PR_NOTHING:
-        LOG_I(RRC, "[UE%d] Frame %d : Received PR_NOTHING on DL-CCCH-Message\n",
-              ctxt_pP->module_id,
-              ctxt_pP->frame);
-        rval = 0;
-        break;
-
-      case DL_CCCH_MessageType__c1_PR_rrcConnectionReestablishment:
-        LOG_I(RRC,
-              "[UE%d] Frame %d : Logical Channel DL-CCCH (SRB0), Received RRCConnectionReestablishment\n",
-              ctxt_pP->module_id,
-              ctxt_pP->frame);
-        rval = 0;
-        break;
-
-      case DL_CCCH_MessageType__c1_PR_rrcConnectionReestablishmentReject:
-        LOG_I(RRC,
-              "[UE%d] Frame %d : Logical Channel DL-CCCH (SRB0), Received RRCConnectionReestablishmentReject\n",
-              ctxt_pP->module_id,
-              ctxt_pP->frame);
-        rval = 0;
-        break;
-
-      case DL_CCCH_MessageType__c1_PR_rrcConnectionReject:
-        LOG_I(RRC,
-              "[UE%d] Frame %d : Logical Channel DL-CCCH (SRB0), Received RRCConnectionReject \n",
-              ctxt_pP->module_id,
-              ctxt_pP->frame);
-        rval = 0;
-        break;
-
-      case DL_CCCH_MessageType__c1_PR_rrcConnectionSetup:
-        LOG_I(RRC,
-              "[UE%d][RAPROC] Frame %d : Logical Channel DL-CCCH (SRB0), Received RRCConnectionSetup RNTI %x\n",
-              ctxt_pP->module_id,
-              ctxt_pP->frame,
-              ctxt_pP->rnti);
-        // Get configuration
+        case LTE_DL_CCCH_MessageType__c1_PR_rrcConnectionReestablishment:
+          LOG_I(RRC,
+                "[UE%d] Frame %d : Logical Channel DL-CCCH (SRB0), Received RRCConnectionReestablishment\n",
+                ctxt_pP->module_id,
+                ctxt_pP->frame);
+          rval = 0;
+          break;
 
-        // Release T300 timer
-        UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].T300_active = 0;
-        rrc_ue_process_radioResourceConfigDedicated(
-          ctxt_pP,
-          eNB_index,
-          &dl_ccch_msg->message.choice.c1.choice.rrcConnectionSetup.criticalExtensions.choice.c1.choice.rrcConnectionSetup_r8.radioResourceConfigDedicated);
+        case LTE_DL_CCCH_MessageType__c1_PR_rrcConnectionReestablishmentReject:
+          LOG_I(RRC,
+                "[UE%d] Frame %d : Logical Channel DL-CCCH (SRB0), Received RRCConnectionReestablishmentReject\n",
+                ctxt_pP->module_id,
+                ctxt_pP->frame);
+          rval = 0;
+          break;
 
-        rrc_set_state (ctxt_pP->module_id, RRC_STATE_CONNECTED);
-        rrc_set_sub_state (ctxt_pP->module_id, RRC_SUB_STATE_CONNECTED);
-        UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].rnti = ctxt_pP->rnti;
-        rrc_ue_generate_RRCConnectionSetupComplete(
-          ctxt_pP,
-          eNB_index,
-          dl_ccch_msg->message.choice.c1.choice.rrcConnectionSetup.rrc_TransactionIdentifier);
+        case LTE_DL_CCCH_MessageType__c1_PR_rrcConnectionReject:
+          LOG_I(RRC,
+                "[UE%d] Frame %d : Logical Channel DL-CCCH (SRB0), Received RRCConnectionReject \n",
+                ctxt_pP->module_id,
+                ctxt_pP->frame);
+          rval = 0;
+          break;
 
-        rval = 0;
-        break;
+        case LTE_DL_CCCH_MessageType__c1_PR_rrcConnectionSetup:
+          LOG_I(RRC,
+                "[UE%d][RAPROC] Frame %d : Logical Channel DL-CCCH (SRB0), Received RRCConnectionSetup RNTI %x\n",
+                ctxt_pP->module_id,
+                ctxt_pP->frame,
+                ctxt_pP->rnti);
+          // Get configuration
+          // Release T300 timer
+          UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].T300_active = 0;
+          rrc_ue_process_radioResourceConfigDedicated(
+            ctxt_pP,
+            eNB_index,
+            &dl_ccch_msg->message.choice.c1.choice.rrcConnectionSetup.criticalExtensions.choice.c1.choice.rrcConnectionSetup_r8.radioResourceConfigDedicated);
+          rrc_set_state (ctxt_pP->module_id, RRC_STATE_CONNECTED);
+          rrc_set_sub_state (ctxt_pP->module_id, RRC_SUB_STATE_CONNECTED);
+          UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].rnti = ctxt_pP->rnti;
+          rrc_ue_generate_RRCConnectionSetupComplete(
+            ctxt_pP,
+            eNB_index,
+            dl_ccch_msg->message.choice.c1.choice.rrcConnectionSetup.rrc_TransactionIdentifier);
+          rval = 0;
+          break;
 
-      default:
-        LOG_E(RRC, "[UE%d] Frame %d : Unknown message\n",
-              ctxt_pP->module_id,
-              ctxt_pP->frame);
-        rval = -1;
-        break;
+        default:
+          LOG_E(RRC, "[UE%d] Frame %d : Unknown message\n",
+                ctxt_pP->module_id,
+                ctxt_pP->frame);
+          rval = -1;
+          break;
       }
     }
   }
@@ -850,30 +747,21 @@ rrc_ue_establish_srb1(
   module_id_t ue_mod_idP,
   frame_t frameP,
   uint8_t eNB_index,
-  struct SRB_ToAddMod* SRB_config
+  struct LTE_SRB_ToAddMod *SRB_config
 )
 //-----------------------------------------------------------------------------
 {
   // add descriptor from RRC PDU
-
-
   UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Active = 1;
   UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Status = RADIO_CONFIG_OK;//RADIO CFG
   UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Srb_info.Srb_id = 1;
-
   // copy default configuration for now
   //  memcpy(&UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Srb_info.Lchan_desc[0],&DCCH_LCHAN_DESC,LCHAN_DESC_SIZE);
   //  memcpy(&UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Srb_info.Lchan_desc[1],&DCCH_LCHAN_DESC,LCHAN_DESC_SIZE);
-
-
   LOG_I(RRC,"[UE %d], CONFIG_SRB1 %d corresponding to eNB_index %d\n", ue_mod_idP,DCCH,eNB_index);
-
   //rrc_pdcp_config_req (ue_mod_idP+NB_eNB_INST, frameP, 0, CONFIG_ACTION_ADD, lchan_id,UNDEF_SECURITY_MODE);
   //  rrc_rlc_config_req(ue_mod_idP+NB_eNB_INST,frameP,0,CONFIG_ACTION_ADD,lchan_id,SIGNALLING_RADIO_BEARER,Rlc_info_am_config);
-
   //  UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Srb_info.Tx_buffer.payload_size=DEFAULT_MEAS_IND_SIZE+1;
-
-
   return(0);
 }
 
@@ -883,30 +771,21 @@ rrc_ue_establish_srb2(
   module_id_t ue_mod_idP,
   frame_t frameP,
   uint8_t eNB_index,
-  struct SRB_ToAddMod* SRB_config
+  struct LTE_SRB_ToAddMod *SRB_config
 )
 //-----------------------------------------------------------------------------
 {
   // add descriptor from RRC PDU
-
-
   UE_rrc_inst[ue_mod_idP].Srb2[eNB_index].Active = 1;
   UE_rrc_inst[ue_mod_idP].Srb2[eNB_index].Status = RADIO_CONFIG_OK;//RADIO CFG
   UE_rrc_inst[ue_mod_idP].Srb2[eNB_index].Srb_info.Srb_id = 2;
-
   // copy default configuration for now
   //  memcpy(&UE_rrc_inst[ue_mod_idP].Srb2[eNB_index].Srb_info.Lchan_desc[0],&DCCH_LCHAN_DESC,LCHAN_DESC_SIZE);
   //  memcpy(&UE_rrc_inst[ue_mod_idP].Srb2[eNB_index].Srb_info.Lchan_desc[1],&DCCH_LCHAN_DESC,LCHAN_DESC_SIZE);
-
-
   LOG_I(RRC,"[UE %d], CONFIG_SRB2 %d corresponding to eNB_index %d\n",ue_mod_idP,DCCH1,eNB_index);
-
   //rrc_pdcp_config_req (ue_mod_idP+NB_eNB_INST, frameP, 0, CONFIG_ACTION_ADD, lchan_id, UNDEF_SECURITY_MODE);
   //  rrc_rlc_config_req(ue_mod_idP+NB_eNB_INST,frameP,0,CONFIG_ACTION_ADD,lchan_id,SIGNALLING_RADIO_BEARER,Rlc_info_am_config);
-
   //  UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Srb_info.Tx_buffer.payload_size=DEFAULT_MEAS_IND_SIZE+1;
-
-
   return(0);
 }
 
@@ -916,7 +795,7 @@ rrc_ue_establish_drb(
   module_id_t ue_mod_idP,
   frame_t frameP,
   uint8_t eNB_index,
-  struct DRB_ToAddMod* DRB_config
+  struct LTE_DRB_ToAddMod *DRB_config
 )
 //-----------------------------------------------------------------------------
 {
@@ -928,7 +807,6 @@ rrc_ue_establish_drb(
   (void)ip_addr_offset3;
   (void)ip_addr_offset4;
 #endif
-
   LOG_I(RRC,"[UE %d] Frame %d: processing RRCConnectionReconfiguration: reconfiguring DRB %ld/LCID %d\n",
         ue_mod_idP, frameP, DRB_config->drb_Identity, (int)*DRB_config->logicalChannelIdentity);
   /*
@@ -954,7 +832,6 @@ rrc_ue_establish_drb(
           ue_mod_idP,
           ip_addr_offset3+ue_mod_idP,
           (long int)((eNB_index * maxDRB) + DRB_config->drb_Identity));
-
     rb_conf_ipv4(0,//add
                  ue_mod_idP,//cx align with the UE index
                  ip_addr_offset3+ue_mod_idP,//inst num_enb+ue_index
@@ -967,7 +844,6 @@ rrc_ue_establish_drb(
 
 #    endif
 #endif
-
   return(0);
 }
 
@@ -975,17 +851,16 @@ rrc_ue_establish_drb(
 //-----------------------------------------------------------------------------
 void
 rrc_ue_process_measConfig(
-  const protocol_ctxt_t* const       ctxt_pP,
+  const protocol_ctxt_t *const       ctxt_pP,
   const uint8_t                      eNB_index,
-  MeasConfig_t* const               measConfig
+  LTE_MeasConfig_t *const               measConfig
 )
 //-----------------------------------------------------------------------------
 {
-
   // This is the procedure described in 36.331 Section 5.5.2.1
   int i;
   long ind;
-  MeasObjectToAddMod_t *measObj;
+  LTE_MeasObjectToAddMod_t *measObj;
 
   if (measConfig->measObjectToRemoveList != NULL) {
     for (i=0; i<measConfig->measObjectToRemoveList->list.count; i++) {
@@ -1003,13 +878,13 @@ rrc_ue_process_measConfig(
 
       if (UE_rrc_inst[ctxt_pP->module_id].MeasObj[eNB_index][ind-1]) {
         LOG_D(RRC,"Modifying measurement object %ld\n",ind);
-        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].MeasObj[eNB_index][ind-1],
-               (char*)measObj,
-               sizeof(MeasObjectToAddMod_t));
+        memcpy((char *)UE_rrc_inst[ctxt_pP->module_id].MeasObj[eNB_index][ind-1],
+               (char *)measObj,
+               sizeof(LTE_MeasObjectToAddMod_t));
       } else {
         LOG_I(RRC,"Adding measurement object %ld\n",ind);
 
-        if (measObj->measObject.present == MeasObjectToAddMod__measObject_PR_measObjectEUTRA) {
+        if (measObj->measObject.present == LTE_MeasObjectToAddMod__measObject_PR_measObjectEUTRA) {
           LOG_I(RRC,"EUTRA Measurement : carrierFreq %ld, allowedMeasBandwidth %ld,presenceAntennaPort1 %d, neighCellConfig %d\n",
                 measObj->measObject.choice.measObjectEUTRA.carrierFreq,
                 measObj->measObject.choice.measObjectEUTRA.allowedMeasBandwidth,
@@ -1021,45 +896,43 @@ rrc_ue_process_measConfig(
     }
 
     LOG_I(RRC,"call rrc_mac_config_req \n");
-
     rrc_mac_config_req_ue(ctxt_pP->module_id,0,eNB_index,
-			  (RadioResourceConfigCommonSIB_t *)NULL,
-			  (struct PhysicalConfigDedicated *)NULL,
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-			  (SCellToAddMod_r10_t *)NULL,
-			  //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
-#endif
-			  UE_rrc_inst[ctxt_pP->module_id].MeasObj[eNB_index],
-			  (MAC_MainConfig_t *)NULL,
-			  0,
-			  (struct LogicalChannelConfig *)NULL,
-			  (MeasGapConfig_t *)NULL,
-			  (TDD_Config_t *)NULL,
-			  (MobilityControlInfo_t *)NULL,
-			  NULL,
-			  NULL,
-			  NULL,
-			  NULL,
-			  NULL,
-			  NULL
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-			  ,0,
-			  (MBSFN_AreaInfoList_r9_t *)NULL,
-			  (PMCH_InfoList_r9_t *)NULL
-
+                          (LTE_RadioResourceConfigCommonSIB_t *)NULL,
+                          (struct LTE_PhysicalConfigDedicated *)NULL,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                          (LTE_SCellToAddMod_r10_t *)NULL,
+                          //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
+#endif
+                          UE_rrc_inst[ctxt_pP->module_id].MeasObj[eNB_index],
+                          (LTE_MAC_MainConfig_t *)NULL,
+                          0,
+                          (struct LTE_LogicalChannelConfig *)NULL,
+                          (LTE_MeasGapConfig_t *)NULL,
+                          (LTE_TDD_Config_t *)NULL,
+                          (LTE_MobilityControlInfo_t *)NULL,
+                          NULL,
+                          NULL,
+                          NULL,
+                          NULL,
+                          NULL,
+                          NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+                          ,0,
+                          (LTE_MBSFN_AreaInfoList_r9_t *)NULL,
+                          (LTE_PMCH_InfoList_r9_t *)NULL
 #endif
 #ifdef CBA
-			  ,
-			  0,
-			  0
+                          ,
+                          0,
+                          0
 #endif
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-           ,
-           0,
-           NULL,
-           NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                          ,
+                          0,
+                          NULL,
+                          NULL
 #endif
-			  );
+                         );
   }
 
   if (measConfig->reportConfigToRemoveList != NULL) {
@@ -1077,9 +950,9 @@ rrc_ue_process_measConfig(
 
       if (UE_rrc_inst[ctxt_pP->module_id].ReportConfig[eNB_index][ind-1]) {
         LOG_I(RRC,"Modifying Report Configuration %ld\n",ind-1);
-        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].ReportConfig[eNB_index][ind-1],
-               (char*)measConfig->reportConfigToAddModList->list.array[i],
-               sizeof(ReportConfigToAddMod_t));
+        memcpy((char *)UE_rrc_inst[ctxt_pP->module_id].ReportConfig[eNB_index][ind-1],
+               (char *)measConfig->reportConfigToAddModList->list.array[i],
+               sizeof(LTE_ReportConfigToAddMod_t));
       } else {
         LOG_D(RRC,"Adding Report Configuration %ld %p \n",ind-1,measConfig->reportConfigToAddModList->list.array[i]);
         UE_rrc_inst[ctxt_pP->module_id].ReportConfig[eNB_index][ind-1] = measConfig->reportConfigToAddModList->list.array[i];
@@ -1090,9 +963,9 @@ rrc_ue_process_measConfig(
   if (measConfig->quantityConfig != NULL) {
     if (UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index]) {
       LOG_D(RRC,"Modifying Quantity Configuration \n");
-      memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index],
-             (char*)measConfig->quantityConfig,
-             sizeof(QuantityConfig_t));
+      memcpy((char *)UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index],
+             (char *)measConfig->quantityConfig,
+             sizeof(LTE_QuantityConfig_t));
     } else {
       LOG_D(RRC,"Adding Quantity configuration\n");
       UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index] = measConfig->quantityConfig;
@@ -1112,9 +985,9 @@ rrc_ue_process_measConfig(
 
       if (UE_rrc_inst[ctxt_pP->module_id].MeasId[eNB_index][ind-1]) {
         LOG_D(RRC,"Modifying Measurement ID %ld\n",ind-1);
-        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].MeasId[eNB_index][ind-1],
-               (char*)measConfig->measIdToAddModList->list.array[i],
-               sizeof(MeasIdToAddMod_t));
+        memcpy((char *)UE_rrc_inst[ctxt_pP->module_id].MeasId[eNB_index][ind-1],
+               (char *)measConfig->measIdToAddModList->list.array[i],
+               sizeof(LTE_MeasIdToAddMod_t));
       } else {
         LOG_D(RRC,"Adding Measurement ID %ld %p\n",ind-1,measConfig->measIdToAddModList->list.array[i]);
         UE_rrc_inst[ctxt_pP->module_id].MeasId[eNB_index][ind-1] = measConfig->measIdToAddModList->list.array[i];
@@ -1124,9 +997,9 @@ rrc_ue_process_measConfig(
 
   if (measConfig->measGapConfig !=NULL) {
     if (UE_rrc_inst[ctxt_pP->module_id].measGapConfig[eNB_index]) {
-      memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].measGapConfig[eNB_index],
-             (char*)measConfig->measGapConfig,
-             sizeof(MeasGapConfig_t));
+      memcpy((char *)UE_rrc_inst[ctxt_pP->module_id].measGapConfig[eNB_index],
+             (char *)measConfig->measGapConfig,
+             sizeof(LTE_MeasGapConfig_t));
     } else {
       UE_rrc_inst[ctxt_pP->module_id].measGapConfig[eNB_index] = measConfig->measGapConfig;
     }
@@ -1135,9 +1008,9 @@ rrc_ue_process_measConfig(
   if (measConfig->quantityConfig != NULL) {
     if (UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index]) {
       LOG_I(RRC,"Modifying Quantity Configuration \n");
-      memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index],
-             (char*)measConfig->quantityConfig,
-             sizeof(QuantityConfig_t));
+      memcpy((char *)UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index],
+             (char *)measConfig->quantityConfig,
+             sizeof(LTE_QuantityConfig_t));
     } else {
       LOG_I(RRC,"Adding Quantity configuration\n");
       UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index] = measConfig->quantityConfig;
@@ -1147,7 +1020,6 @@ rrc_ue_process_measConfig(
         (*UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index]->quantityConfigEUTRA->filterCoefficientRSRP)/4);
     UE_rrc_inst[ctxt_pP->module_id].filter_coeff_rsrq = 1./pow(2,
         (*UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index]->quantityConfigEUTRA->filterCoefficientRSRQ)/4);
-
     LOG_I(RRC,"[UE %d] set rsrp-coeff for eNB %d: %ld rsrq-coeff: %ld rsrp_factor: %f rsrq_factor: %f \n",
           ctxt_pP->module_id, eNB_index, // UE_rrc_inst[ue_mod_idP].Info[eNB_index].UE_index,
           *UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index]->quantityConfigEUTRA->filterCoefficientRSRP,
@@ -1162,7 +1034,7 @@ rrc_ue_process_measConfig(
 
   if (measConfig->speedStatePars != NULL) {
     if (UE_rrc_inst[ctxt_pP->module_id].speedStatePars) {
-      memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].speedStatePars,(char*)measConfig->speedStatePars,sizeof(struct MeasConfig__speedStatePars));
+      memcpy((char *)UE_rrc_inst[ctxt_pP->module_id].speedStatePars,(char *)measConfig->speedStatePars,sizeof(struct LTE_MeasConfig__speedStatePars));
     } else {
       UE_rrc_inst[ctxt_pP->module_id].speedStatePars = measConfig->speedStatePars;
     }
@@ -1174,234 +1046,195 @@ rrc_ue_process_measConfig(
 
 
 void
-rrc_ue_update_radioResourceConfigDedicated(RadioResourceConfigDedicated_t* radioResourceConfigDedicated,
-        const protocol_ctxt_t* const ctxt_pP,
-        uint8_t eNB_index)
-{
-    PhysicalConfigDedicated_t* physicalConfigDedicated2 = NULL;
-
-    physicalConfigDedicated2 = CALLOC(1,sizeof(*physicalConfigDedicated2));
-    physicalConfigDedicated2->pdsch_ConfigDedicated         = CALLOC(1,sizeof(*physicalConfigDedicated2->pdsch_ConfigDedicated));
-    physicalConfigDedicated2->pusch_ConfigDedicated         = CALLOC(1,sizeof(*physicalConfigDedicated2->pusch_ConfigDedicated));
-    physicalConfigDedicated2->pucch_ConfigDedicated         = CALLOC(1,sizeof(*physicalConfigDedicated2->pucch_ConfigDedicated));
-    physicalConfigDedicated2->cqi_ReportConfig              = CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig));
-    physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic
-                                                            = CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic));
-    physicalConfigDedicated2->soundingRS_UL_ConfigDedicated = CALLOC(1,sizeof(*physicalConfigDedicated2->soundingRS_UL_ConfigDedicated));
-    physicalConfigDedicated2->schedulingRequestConfig       = CALLOC(1,sizeof(*physicalConfigDedicated2->schedulingRequestConfig));
-    physicalConfigDedicated2->antennaInfo                   = CALLOC(1,sizeof(*physicalConfigDedicated2->antennaInfo));
-
-    physicalConfigDedicated2->uplinkPowerControlDedicated   = CALLOC(1,sizeof(*physicalConfigDedicated2->uplinkPowerControlDedicated));
-    physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH         = CALLOC(1,sizeof(*physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH));
-    physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH         = CALLOC(1,sizeof(*physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH));
-
-    // Update pdsch_ConfigDedicated
-    if(radioResourceConfigDedicated->physicalConfigDedicated->pdsch_ConfigDedicated != NULL)
-    {
-        LOG_I(RRC,"Update pdsch_ConfigDedicated config \n");
-
-        if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->pdsch_ConfigDedicated == NULL)
-            UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->pdsch_ConfigDedicated = CALLOC(1,sizeof(PDSCH_ConfigDedicated_t));
-
-        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->pdsch_ConfigDedicated,
-                (char*)radioResourceConfigDedicated->physicalConfigDedicated->pdsch_ConfigDedicated,
-                sizeof(physicalConfigDedicated2->pdsch_ConfigDedicated));
-    }
-    else
-    {
-        LOG_I(RRC,"Keep old config for pdsch_ConfigDedicated\n");
-    }
-
-    // Update pusch_ConfigDedicated
-    if(radioResourceConfigDedicated->physicalConfigDedicated->pusch_ConfigDedicated != NULL)
-    {
-        LOG_I(RRC,"Update pusch_ConfigDedicated config \n");
-
-        if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->pusch_ConfigDedicated == NULL)
-            UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->pusch_ConfigDedicated = CALLOC(1,sizeof(PUSCH_ConfigDedicated_t));
-
-        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->pusch_ConfigDedicated,
-                (char*)radioResourceConfigDedicated->physicalConfigDedicated->pusch_ConfigDedicated,
-                sizeof(physicalConfigDedicated2->pusch_ConfigDedicated));
-    }
-    else
-    {
-        LOG_I(RRC,"Keep old config for pusch_ConfigDedicated\n");
-    }
-
-    // Update pucch_ConfigDedicated
-    if(radioResourceConfigDedicated->physicalConfigDedicated->pucch_ConfigDedicated != NULL)
-    {
-        LOG_I(RRC,"Update pucch_ConfigDedicated config \n");
-        if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->pucch_ConfigDedicated == NULL)
-            UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->pucch_ConfigDedicated = CALLOC(1,sizeof(PUCCH_ConfigDedicated_t));
-
-        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->pucch_ConfigDedicated,
-                (char*)radioResourceConfigDedicated->physicalConfigDedicated->pucch_ConfigDedicated,
-                sizeof(physicalConfigDedicated2->pucch_ConfigDedicated));
-    }
-    else
-    {
-        LOG_I(RRC,"Keep old config for pucch_ConfigDedicated\n");
-    }
+rrc_ue_update_radioResourceConfigDedicated(LTE_RadioResourceConfigDedicated_t *radioResourceConfigDedicated,
+    const protocol_ctxt_t *const ctxt_pP,
+    uint8_t eNB_index) {
+  LTE_PhysicalConfigDedicated_t *physicalConfigDedicated2 = NULL;
+  physicalConfigDedicated2 = CALLOC(1,sizeof(*physicalConfigDedicated2));
+  physicalConfigDedicated2->pdsch_ConfigDedicated         = CALLOC(1,sizeof(*physicalConfigDedicated2->pdsch_ConfigDedicated));
+  physicalConfigDedicated2->pusch_ConfigDedicated         = CALLOC(1,sizeof(*physicalConfigDedicated2->pusch_ConfigDedicated));
+  physicalConfigDedicated2->pucch_ConfigDedicated         = CALLOC(1,sizeof(*physicalConfigDedicated2->pucch_ConfigDedicated));
+  physicalConfigDedicated2->cqi_ReportConfig              = CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig));
+  physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic
+    = CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic));
+  physicalConfigDedicated2->soundingRS_UL_ConfigDedicated = CALLOC(1,sizeof(*physicalConfigDedicated2->soundingRS_UL_ConfigDedicated));
+  physicalConfigDedicated2->schedulingRequestConfig       = CALLOC(1,sizeof(*physicalConfigDedicated2->schedulingRequestConfig));
+  physicalConfigDedicated2->antennaInfo                   = CALLOC(1,sizeof(*physicalConfigDedicated2->antennaInfo));
+  physicalConfigDedicated2->uplinkPowerControlDedicated   = CALLOC(1,sizeof(*physicalConfigDedicated2->uplinkPowerControlDedicated));
+  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH         = CALLOC(1,sizeof(*physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH));
+  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH         = CALLOC(1,sizeof(*physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH));
+
+  // Update pdsch_ConfigDedicated
+  if(radioResourceConfigDedicated->physicalConfigDedicated->pdsch_ConfigDedicated != NULL) {
+    LOG_I(RRC,"Update pdsch_ConfigDedicated config \n");
+
+    if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->pdsch_ConfigDedicated == NULL)
+      UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->pdsch_ConfigDedicated = CALLOC(1,sizeof(LTE_PDSCH_ConfigDedicated_t));
+
+    memcpy((char *)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->pdsch_ConfigDedicated,
+           (char *)radioResourceConfigDedicated->physicalConfigDedicated->pdsch_ConfigDedicated,
+           sizeof(physicalConfigDedicated2->pdsch_ConfigDedicated));
+  } else {
+    LOG_I(RRC,"Keep old config for pdsch_ConfigDedicated\n");
+  }
 
-    // Update cqi_ReportConfig
-    if(radioResourceConfigDedicated->physicalConfigDedicated->cqi_ReportConfig != NULL)
-    {
-        LOG_I(RRC,"Update cqi_ReportConfig config (size=%zu,%zu)\n", sizeof(*physicalConfigDedicated2->cqi_ReportConfig), sizeof(CQI_ReportConfig_t));
+  // Update pusch_ConfigDedicated
+  if(radioResourceConfigDedicated->physicalConfigDedicated->pusch_ConfigDedicated != NULL) {
+    LOG_I(RRC,"Update pusch_ConfigDedicated config \n");
 
-        if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->cqi_ReportConfig == NULL)
-            UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->cqi_ReportConfig = CALLOC(1,sizeof(CQI_ReportConfig_t));
+    if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->pusch_ConfigDedicated == NULL)
+      UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->pusch_ConfigDedicated = CALLOC(1,sizeof(LTE_PUSCH_ConfigDedicated_t));
 
-        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->cqi_ReportConfig,
-                (char*)radioResourceConfigDedicated->physicalConfigDedicated->cqi_ReportConfig,
-                sizeof(*physicalConfigDedicated2->cqi_ReportConfig));
+    memcpy((char *)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->pusch_ConfigDedicated,
+           (char *)radioResourceConfigDedicated->physicalConfigDedicated->pusch_ConfigDedicated,
+           sizeof(physicalConfigDedicated2->pusch_ConfigDedicated));
+  } else {
+    LOG_I(RRC,"Keep old config for pusch_ConfigDedicated\n");
+  }
 
-        if (radioResourceConfigDedicated->physicalConfigDedicated->cqi_ReportConfig->cqi_ReportPeriodic != NULL) {
-          LOG_I(RRC,"Update cqi_ReportPeriodic config (size=%zu,%zu)\n", sizeof(*physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic), sizeof(CQI_ReportPeriodic_t));
+  // Update pucch_ConfigDedicated
+  if(radioResourceConfigDedicated->physicalConfigDedicated->pucch_ConfigDedicated != NULL) {
+    LOG_I(RRC,"Update pucch_ConfigDedicated config \n");
 
-          if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->cqi_ReportConfig->cqi_ReportPeriodic == NULL)
-            UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->cqi_ReportConfig->cqi_ReportPeriodic = CALLOC(1,sizeof(CQI_ReportPeriodic_t));
+    if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->pucch_ConfigDedicated == NULL)
+      UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->pucch_ConfigDedicated = CALLOC(1,sizeof(LTE_PUCCH_ConfigDedicated_t));
 
-          memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->cqi_ReportConfig->cqi_ReportPeriodic,
-                  (char*)radioResourceConfigDedicated->physicalConfigDedicated->cqi_ReportConfig->cqi_ReportPeriodic,
-                  sizeof(*physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic));
-        }
-    }
-    else
-    {
-        LOG_I(RRC,"Keep old config for cqi_ReportConfig\n");
-    }
+    memcpy((char *)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->pucch_ConfigDedicated,
+           (char *)radioResourceConfigDedicated->physicalConfigDedicated->pucch_ConfigDedicated,
+           sizeof(physicalConfigDedicated2->pucch_ConfigDedicated));
+  } else {
+    LOG_I(RRC,"Keep old config for pucch_ConfigDedicated\n");
+  }
 
-    // Update schedulingRequestConfig
-    if(radioResourceConfigDedicated->physicalConfigDedicated->schedulingRequestConfig != NULL)
-    {
-        LOG_I(RRC,"Update schedulingRequestConfig config \n");
+  // Update cqi_ReportConfig
+  if(radioResourceConfigDedicated->physicalConfigDedicated->cqi_ReportConfig != NULL) {
+    LOG_I(RRC,"Update cqi_ReportConfig config (size=%zu,%zu)\n", sizeof(*physicalConfigDedicated2->cqi_ReportConfig), sizeof(LTE_CQI_ReportConfig_t));
 
-        if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->schedulingRequestConfig == NULL)
-            UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->schedulingRequestConfig = CALLOC(1,sizeof(SchedulingRequestConfig_t));
+    if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->cqi_ReportConfig == NULL)
+      UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->cqi_ReportConfig = CALLOC(1,sizeof(LTE_CQI_ReportConfig_t));
 
-        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->schedulingRequestConfig,
-                (char*)radioResourceConfigDedicated->physicalConfigDedicated->schedulingRequestConfig,
-                sizeof(physicalConfigDedicated2->schedulingRequestConfig));
-    }
-    else
-    {
-        LOG_I(RRC,"Keep old config for schedulingRequestConfig\n");
-    }
+    memcpy((char *)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->cqi_ReportConfig,
+           (char *)radioResourceConfigDedicated->physicalConfigDedicated->cqi_ReportConfig,
+           sizeof(*physicalConfigDedicated2->cqi_ReportConfig));
 
-    // Update soundingRS_UL_ConfigDedicated
-    if(radioResourceConfigDedicated->physicalConfigDedicated->soundingRS_UL_ConfigDedicated != NULL)
-    {
-        LOG_I(RRC,"Update soundingRS_UL_ConfigDedicated config \n");
+    if (radioResourceConfigDedicated->physicalConfigDedicated->cqi_ReportConfig->cqi_ReportPeriodic != NULL) {
+      LOG_I(RRC,"Update cqi_ReportPeriodic config (size=%zu,%zu)\n", sizeof(*physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic), sizeof(LTE_CQI_ReportPeriodic_t));
 
-        if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->soundingRS_UL_ConfigDedicated == NULL)
-            UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->soundingRS_UL_ConfigDedicated = CALLOC(1,sizeof(SoundingRS_UL_ConfigDedicated_t));
+      if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->cqi_ReportConfig->cqi_ReportPeriodic == NULL)
+        UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->cqi_ReportConfig->cqi_ReportPeriodic = CALLOC(1,sizeof(LTE_CQI_ReportPeriodic_t));
 
-        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->soundingRS_UL_ConfigDedicated,
-                (char*)radioResourceConfigDedicated->physicalConfigDedicated->soundingRS_UL_ConfigDedicated,
-                sizeof(physicalConfigDedicated2->soundingRS_UL_ConfigDedicated));
+      memcpy((char *)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->cqi_ReportConfig->cqi_ReportPeriodic,
+             (char *)radioResourceConfigDedicated->physicalConfigDedicated->cqi_ReportConfig->cqi_ReportPeriodic,
+             sizeof(*physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic));
     }
-    else
-    {
-        LOG_I(RRC,"Keep old config for soundingRS_UL_ConfigDedicated\n");
-    }
-
-    // Update antennaInfo
-    if(radioResourceConfigDedicated->physicalConfigDedicated->antennaInfo != NULL)
-    {
-        LOG_I(RRC,"Update antennaInfo config \n");
-
-        if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->antennaInfo == NULL)
-            UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->antennaInfo = CALLOC(1,sizeof(struct PhysicalConfigDedicated__antennaInfo));
+  } else {
+    LOG_I(RRC,"Keep old config for cqi_ReportConfig\n");
+  }
 
-        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->antennaInfo,
-                (char*)radioResourceConfigDedicated->physicalConfigDedicated->antennaInfo,
-                sizeof(physicalConfigDedicated2->antennaInfo));
+  // Update schedulingRequestConfig
+  if(radioResourceConfigDedicated->physicalConfigDedicated->schedulingRequestConfig != NULL) {
+    LOG_I(RRC,"Update schedulingRequestConfig config \n");
 
-        UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->antennaInfo->choice.explicitValue.transmissionMode =
-        		radioResourceConfigDedicated->physicalConfigDedicated->antennaInfo->choice.explicitValue.transmissionMode;
-        UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->antennaInfo->choice.explicitValue.codebookSubsetRestriction =
-        		radioResourceConfigDedicated->physicalConfigDedicated->antennaInfo->choice.explicitValue.codebookSubsetRestriction;
-        UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->antennaInfo->choice.explicitValue.ue_TransmitAntennaSelection =
-        		radioResourceConfigDedicated->physicalConfigDedicated->antennaInfo->choice.explicitValue.ue_TransmitAntennaSelection;
+    if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->schedulingRequestConfig == NULL)
+      UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->schedulingRequestConfig = CALLOC(1,sizeof(LTE_SchedulingRequestConfig_t));
 
-        LOG_I(PHY,"New Transmission Mode %ld \n",radioResourceConfigDedicated->physicalConfigDedicated->antennaInfo->choice.explicitValue.transmissionMode);
-        LOG_I(PHY,"Configured Transmission Mode %ld \n",UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->antennaInfo->choice.explicitValue.transmissionMode);
+    memcpy((char *)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->schedulingRequestConfig,
+           (char *)radioResourceConfigDedicated->physicalConfigDedicated->schedulingRequestConfig,
+           sizeof(physicalConfigDedicated2->schedulingRequestConfig));
+  } else {
+    LOG_I(RRC,"Keep old config for schedulingRequestConfig\n");
+  }
 
-    }
-    else
-    {
-        LOG_I(RRC,"Keep old config for antennaInfo\n");
-    }
+  // Update soundingRS_UL_ConfigDedicated
+  if(radioResourceConfigDedicated->physicalConfigDedicated->soundingRS_UL_ConfigDedicated != NULL) {
+    LOG_I(RRC,"Update soundingRS_UL_ConfigDedicated config \n");
 
+    if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->soundingRS_UL_ConfigDedicated == NULL)
+      UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->soundingRS_UL_ConfigDedicated = CALLOC(1,sizeof(LTE_SoundingRS_UL_ConfigDedicated_t));
 
-    // Update uplinkPowerControlDedicated
-    if(radioResourceConfigDedicated->physicalConfigDedicated->uplinkPowerControlDedicated != NULL)
-    {
-        LOG_I(RRC,"Update uplinkPowerControlDedicated config \n");
+    memcpy((char *)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->soundingRS_UL_ConfigDedicated,
+           (char *)radioResourceConfigDedicated->physicalConfigDedicated->soundingRS_UL_ConfigDedicated,
+           sizeof(physicalConfigDedicated2->soundingRS_UL_ConfigDedicated));
+  } else {
+    LOG_I(RRC,"Keep old config for soundingRS_UL_ConfigDedicated\n");
+  }
 
-        if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->uplinkPowerControlDedicated == NULL)
-            UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->uplinkPowerControlDedicated = CALLOC(1,sizeof(UplinkPowerControlDedicated_t));
+  // Update antennaInfo
+  if(radioResourceConfigDedicated->physicalConfigDedicated->antennaInfo != NULL) {
+    LOG_I(RRC,"Update antennaInfo config \n");
+
+    if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->antennaInfo == NULL)
+      UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->antennaInfo = CALLOC(1,sizeof(struct LTE_PhysicalConfigDedicated__antennaInfo));
+
+    memcpy((char *)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->antennaInfo,
+           (char *)radioResourceConfigDedicated->physicalConfigDedicated->antennaInfo,
+           sizeof(physicalConfigDedicated2->antennaInfo));
+    UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->antennaInfo->choice.explicitValue.transmissionMode =
+      radioResourceConfigDedicated->physicalConfigDedicated->antennaInfo->choice.explicitValue.transmissionMode;
+    UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->antennaInfo->choice.explicitValue.codebookSubsetRestriction =
+      radioResourceConfigDedicated->physicalConfigDedicated->antennaInfo->choice.explicitValue.codebookSubsetRestriction;
+    UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->antennaInfo->choice.explicitValue.ue_TransmitAntennaSelection =
+      radioResourceConfigDedicated->physicalConfigDedicated->antennaInfo->choice.explicitValue.ue_TransmitAntennaSelection;
+    LOG_I(PHY,"New Transmission Mode %ld \n",radioResourceConfigDedicated->physicalConfigDedicated->antennaInfo->choice.explicitValue.transmissionMode);
+    LOG_I(PHY,"Configured Transmission Mode %ld \n",UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->antennaInfo->choice.explicitValue.transmissionMode);
+  } else {
+    LOG_I(RRC,"Keep old config for antennaInfo\n");
+  }
 
-        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->uplinkPowerControlDedicated,
-                (char*)radioResourceConfigDedicated->physicalConfigDedicated->uplinkPowerControlDedicated,
-                sizeof(physicalConfigDedicated2->uplinkPowerControlDedicated));
-    }
-    else
-    {
-        LOG_I(RRC,"Keep old config for uplinkPowerControlDedicated\n");
-    }
+  // Update uplinkPowerControlDedicated
+  if(radioResourceConfigDedicated->physicalConfigDedicated->uplinkPowerControlDedicated != NULL) {
+    LOG_I(RRC,"Update uplinkPowerControlDedicated config \n");
 
-    // Update tpc_PDCCH_ConfigPUCCH
-    if(radioResourceConfigDedicated->physicalConfigDedicated->tpc_PDCCH_ConfigPUCCH != NULL)
-    {
-        LOG_I(RRC,"Update tpc_PDCCH_ConfigPUCCH config \n");
+    if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->uplinkPowerControlDedicated == NULL)
+      UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->uplinkPowerControlDedicated = CALLOC(1,sizeof(LTE_UplinkPowerControlDedicated_t));
 
-        if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->tpc_PDCCH_ConfigPUCCH == NULL)
-            UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->tpc_PDCCH_ConfigPUCCH = CALLOC(1,sizeof(TPC_PDCCH_Config_t));
+    memcpy((char *)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->uplinkPowerControlDedicated,
+           (char *)radioResourceConfigDedicated->physicalConfigDedicated->uplinkPowerControlDedicated,
+           sizeof(physicalConfigDedicated2->uplinkPowerControlDedicated));
+  } else {
+    LOG_I(RRC,"Keep old config for uplinkPowerControlDedicated\n");
+  }
 
-        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->tpc_PDCCH_ConfigPUCCH,
-                (char*)radioResourceConfigDedicated->physicalConfigDedicated->tpc_PDCCH_ConfigPUCCH,
-                sizeof(physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH));
-    }
-    else
-    {
-        LOG_I(RRC,"Keep old config for tpc_PDCCH_ConfigPUCCH\n");
-    }
+  // Update tpc_PDCCH_ConfigPUCCH
+  if(radioResourceConfigDedicated->physicalConfigDedicated->tpc_PDCCH_ConfigPUCCH != NULL) {
+    LOG_I(RRC,"Update tpc_PDCCH_ConfigPUCCH config \n");
 
-    // Update tpc_PDCCH_ConfigPUSCH
-    if(radioResourceConfigDedicated->physicalConfigDedicated->tpc_PDCCH_ConfigPUSCH != NULL)
-    {
-        LOG_I(RRC,"Update tpc_PDCCH_ConfigPUSCH config \n");
+    if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->tpc_PDCCH_ConfigPUCCH == NULL)
+      UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->tpc_PDCCH_ConfigPUCCH = CALLOC(1,sizeof(LTE_TPC_PDCCH_Config_t));
 
-        if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->tpc_PDCCH_ConfigPUSCH == NULL)
-            UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->tpc_PDCCH_ConfigPUSCH = CALLOC(1,sizeof(TPC_PDCCH_Config_t));
+    memcpy((char *)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->tpc_PDCCH_ConfigPUCCH,
+           (char *)radioResourceConfigDedicated->physicalConfigDedicated->tpc_PDCCH_ConfigPUCCH,
+           sizeof(physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH));
+  } else {
+    LOG_I(RRC,"Keep old config for tpc_PDCCH_ConfigPUCCH\n");
+  }
 
-        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->tpc_PDCCH_ConfigPUSCH,
-                (char*)radioResourceConfigDedicated->physicalConfigDedicated->tpc_PDCCH_ConfigPUSCH,
-                sizeof(physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH));
+  // Update tpc_PDCCH_ConfigPUSCH
+  if(radioResourceConfigDedicated->physicalConfigDedicated->tpc_PDCCH_ConfigPUSCH != NULL) {
+    LOG_I(RRC,"Update tpc_PDCCH_ConfigPUSCH config \n");
 
-    }
-    else
-    {
-        LOG_I(RRC,"Keep old config for tpc_PDCCH_ConfigPUSCH\n");
-    }
+    if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->tpc_PDCCH_ConfigPUSCH == NULL)
+      UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->tpc_PDCCH_ConfigPUSCH = CALLOC(1,sizeof(LTE_TPC_PDCCH_Config_t));
 
+    memcpy((char *)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->tpc_PDCCH_ConfigPUSCH,
+           (char *)radioResourceConfigDedicated->physicalConfigDedicated->tpc_PDCCH_ConfigPUSCH,
+           sizeof(physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH));
+  } else {
+    LOG_I(RRC,"Keep old config for tpc_PDCCH_ConfigPUSCH\n");
+  }
 }
 //-----------------------------------------------------------------------------
 void
 rrc_ue_process_radioResourceConfigDedicated(
-  const protocol_ctxt_t* const ctxt_pP,
+  const protocol_ctxt_t *const ctxt_pP,
   uint8_t eNB_index,
-  RadioResourceConfigDedicated_t* radioResourceConfigDedicated
+  LTE_RadioResourceConfigDedicated_t *radioResourceConfigDedicated
 )
 //-----------------------------------------------------------------------------
 {
-
   long SRB_id,DRB_id;
   int i,cnt;
-  LogicalChannelConfig_t *SRB1_logicalChannelConfig,*SRB2_logicalChannelConfig;
+  LTE_LogicalChannelConfig_t *SRB1_logicalChannelConfig,*SRB2_logicalChannelConfig;
 #ifdef CBA
   uint8_t cba_found = 0;
   uint16_t cba_RNTI;
@@ -1413,9 +1246,9 @@ rrc_ue_process_radioResourceConfigDedicated(
 
     if (UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]) {
 #if 1
-        rrc_ue_update_radioResourceConfigDedicated(radioResourceConfigDedicated, ctxt_pP, eNB_index);
+      rrc_ue_update_radioResourceConfigDedicated(radioResourceConfigDedicated, ctxt_pP, eNB_index);
 #else
-      memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index],(char*)radioResourceConfigDedicated->physicalConfigDedicated,
+      memcpy((char *)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index],(char *)radioResourceConfigDedicated->physicalConfigDedicated,
              sizeof(struct PhysicalConfigDedicated));
 #endif
     } else {
@@ -1426,10 +1259,10 @@ rrc_ue_process_radioResourceConfigDedicated(
 
   // Apply macMainConfig if present
   if (radioResourceConfigDedicated->mac_MainConfig) {
-    if (radioResourceConfigDedicated->mac_MainConfig->present == RadioResourceConfigDedicated__mac_MainConfig_PR_explicitValue) {
+    if (radioResourceConfigDedicated->mac_MainConfig->present == LTE_RadioResourceConfigDedicated__mac_MainConfig_PR_explicitValue) {
       if (UE_rrc_inst[ctxt_pP->module_id].mac_MainConfig[eNB_index]) {
-        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].mac_MainConfig[eNB_index],(char*)&radioResourceConfigDedicated->mac_MainConfig->choice.explicitValue,
-               sizeof(MAC_MainConfig_t));
+        memcpy((char *)UE_rrc_inst[ctxt_pP->module_id].mac_MainConfig[eNB_index],(char *)&radioResourceConfigDedicated->mac_MainConfig->choice.explicitValue,
+               sizeof(LTE_MAC_MainConfig_t));
       } else {
         UE_rrc_inst[ctxt_pP->module_id].mac_MainConfig[eNB_index] = &radioResourceConfigDedicated->mac_MainConfig->choice.explicitValue;
       }
@@ -1440,7 +1273,7 @@ rrc_ue_process_radioResourceConfigDedicated(
   if (radioResourceConfigDedicated->sps_Config) {
     if (UE_rrc_inst[ctxt_pP->module_id].sps_Config[eNB_index]) {
       memcpy(UE_rrc_inst[ctxt_pP->module_id].sps_Config[eNB_index],radioResourceConfigDedicated->sps_Config,
-             sizeof(struct SPS_Config));
+             sizeof(struct LTE_SPS_Config));
     } else {
       UE_rrc_inst[ctxt_pP->module_id].sps_Config[eNB_index] = radioResourceConfigDedicated->sps_Config;
     }
@@ -1476,7 +1309,6 @@ rrc_ue_process_radioResourceConfigDedicated(
   if (radioResourceConfigDedicated->srb_ToAddModList) {
     uint8_t *kRRCenc = NULL;
     uint8_t *kRRCint = NULL;
-
 #if defined(ENABLE_SECURITY)
     derive_key_rrc_enc(UE_rrc_inst[ctxt_pP->module_id].ciphering_algorithm,
                        UE_rrc_inst[ctxt_pP->module_id].kenb, &kRRCenc);
@@ -1486,29 +1318,27 @@ rrc_ue_process_radioResourceConfigDedicated(
     // Refresh SRBs
     rrc_pdcp_config_asn1_req(ctxt_pP,
                              radioResourceConfigDedicated->srb_ToAddModList,
-                             (DRB_ToAddModList_t*)NULL,
-                             (DRB_ToReleaseList_t*)NULL,
+                             (LTE_DRB_ToAddModList_t *)NULL,
+                             (LTE_DRB_ToReleaseList_t *)NULL,
                              UE_rrc_inst[ctxt_pP->module_id].ciphering_algorithm |
                              (UE_rrc_inst[ctxt_pP->module_id].integrity_algorithm << 4),
                              kRRCenc,
                              kRRCint,
                              NULL
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-                             ,(PMCH_InfoList_r9_t *)NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+                             ,(LTE_PMCH_InfoList_r9_t *)NULL
 #endif
                              ,NULL);
-
     // Refresh SRBs
     rrc_rlc_config_asn1_req(ctxt_pP,
                             radioResourceConfigDedicated->srb_ToAddModList,
-                            (DRB_ToAddModList_t*)NULL,
-                            (DRB_ToReleaseList_t*)NULL
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-                            ,(PMCH_InfoList_r9_t *)NULL
+                            (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
                            );
-
 #if ENABLE_RAL
     // first msg that includes srb config
     UE_rrc_inst[ctxt_pP->module_id].num_srb=radioResourceConfigDedicated->srb_ToAddModList->list.count;
@@ -1522,15 +1352,14 @@ rrc_ue_process_radioResourceConfigDedicated(
       if (SRB_id == 1) {
         if (UE_rrc_inst[ctxt_pP->module_id].SRB1_config[eNB_index]) {
           memcpy(UE_rrc_inst[ctxt_pP->module_id].SRB1_config[eNB_index],radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt],
-                 sizeof(struct SRB_ToAddMod));
+                 sizeof(struct LTE_SRB_ToAddMod));
         } else {
           UE_rrc_inst[ctxt_pP->module_id].SRB1_config[eNB_index] = radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt];
           rrc_ue_establish_srb1(ctxt_pP->module_id,ctxt_pP->frame,eNB_index,radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt]);
 
           if (UE_rrc_inst[ctxt_pP->module_id].SRB1_config[eNB_index]->logicalChannelConfig) {
-            if (UE_rrc_inst[ctxt_pP->module_id].SRB1_config[eNB_index]->logicalChannelConfig->present == SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
+            if (UE_rrc_inst[ctxt_pP->module_id].SRB1_config[eNB_index]->logicalChannelConfig->present == LTE_SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
               SRB1_logicalChannelConfig = &UE_rrc_inst[ctxt_pP->module_id].SRB1_config[eNB_index]->logicalChannelConfig->choice.explicitValue;
-
             } else {
               SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
             }
@@ -1540,56 +1369,55 @@ rrc_ue_process_radioResourceConfigDedicated(
 
           LOG_I(RRC, "[FRAME %05d][RRC_UE][MOD %02d][][--- MAC_CONFIG_REQ  (SRB1 eNB %d) --->][MAC_UE][MOD %02d][]\n",
                 ctxt_pP->frame, ctxt_pP->module_id, eNB_index, ctxt_pP->module_id);
-
           rrc_mac_config_req_ue(ctxt_pP->module_id,0,eNB_index,
-				(RadioResourceConfigCommonSIB_t *)NULL,
-				UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index],
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-				(SCellToAddMod_r10_t *)NULL,
-				//struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
-#endif
-				(MeasObjectToAddMod_t **)NULL,
-				UE_rrc_inst[ctxt_pP->module_id].mac_MainConfig[eNB_index],
-				1,
-				SRB1_logicalChannelConfig,
-				(MeasGapConfig_t *)NULL,
-				NULL,
-				NULL,
-				NULL,
-				NULL,
-				NULL,
-				NULL,
-				NULL,
-				NULL
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-				,
-				0,
-				(MBSFN_AreaInfoList_r9_t *)NULL,
-				(PMCH_InfoList_r9_t *)NULL
+                                (LTE_RadioResourceConfigCommonSIB_t *)NULL,
+                                UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index],
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                                (LTE_SCellToAddMod_r10_t *)NULL,
+                                //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
+#endif
+                                (LTE_MeasObjectToAddMod_t **)NULL,
+                                UE_rrc_inst[ctxt_pP->module_id].mac_MainConfig[eNB_index],
+                                1,
+                                SRB1_logicalChannelConfig,
+                                (LTE_MeasGapConfig_t *)NULL,
+                                NULL,
+                                NULL,
+                                NULL,
+                                NULL,
+                                NULL,
+                                NULL,
+                                NULL,
+                                NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+                                ,
+                                0,
+                                (LTE_MBSFN_AreaInfoList_r9_t *)NULL,
+                                (LTE_PMCH_InfoList_r9_t *)NULL
 #endif
 #ifdef CBA
-				,
-				0,
-				0
+                                ,
+                                0,
+                                0
 #endif
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-           ,
-           0,
-           NULL,
-           NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                                ,
+                                0,
+                                NULL,
+                                NULL
 #endif
-				);
+                               );
         }
       } else {
         if (UE_rrc_inst[ctxt_pP->module_id].SRB2_config[eNB_index]) {
           memcpy(UE_rrc_inst[ctxt_pP->module_id].SRB2_config[eNB_index],radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt],
-                 sizeof(struct SRB_ToAddMod));
+                 sizeof(struct LTE_SRB_ToAddMod));
         } else {
           UE_rrc_inst[ctxt_pP->module_id].SRB2_config[eNB_index] = radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt];
           rrc_ue_establish_srb2(ctxt_pP->module_id,ctxt_pP->frame,eNB_index,radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt]);
 
           if (UE_rrc_inst[ctxt_pP->module_id].SRB2_config[eNB_index]->logicalChannelConfig) {
-            if (UE_rrc_inst[ctxt_pP->module_id].SRB2_config[eNB_index]->logicalChannelConfig->present == SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
+            if (UE_rrc_inst[ctxt_pP->module_id].SRB2_config[eNB_index]->logicalChannelConfig->present == LTE_SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
               LOG_I(RRC,"Applying Explicit SRB2 logicalChannelConfig\n");
               SRB2_logicalChannelConfig = &UE_rrc_inst[ctxt_pP->module_id].SRB2_config[eNB_index]->logicalChannelConfig->choice.explicitValue;
             } else {
@@ -1606,44 +1434,43 @@ rrc_ue_process_radioResourceConfigDedicated(
                 eNB_index,
                 ctxt_pP->module_id);
           rrc_mac_config_req_ue(ctxt_pP->module_id,0,eNB_index,
-				(RadioResourceConfigCommonSIB_t *)NULL,
-				UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index],
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-				(SCellToAddMod_r10_t *)NULL,
-				//struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
-#endif
-				(MeasObjectToAddMod_t **)NULL,
-				UE_rrc_inst[ctxt_pP->module_id].mac_MainConfig[eNB_index],
-				2,
-				SRB2_logicalChannelConfig,
-				UE_rrc_inst[ctxt_pP->module_id].measGapConfig[eNB_index],
-				(TDD_Config_t *)NULL,
-				(MobilityControlInfo_t *)NULL,
-				NULL,
-				NULL,
-				NULL,
-				NULL,
-				NULL,
-				NULL
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-				,
-				0,
-				(MBSFN_AreaInfoList_r9_t *)NULL,
-				(PMCH_InfoList_r9_t *)NULL
-
+                                (LTE_RadioResourceConfigCommonSIB_t *)NULL,
+                                UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index],
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                                (LTE_SCellToAddMod_r10_t *)NULL,
+                                //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
+#endif
+                                (LTE_MeasObjectToAddMod_t **)NULL,
+                                UE_rrc_inst[ctxt_pP->module_id].mac_MainConfig[eNB_index],
+                                2,
+                                SRB2_logicalChannelConfig,
+                                UE_rrc_inst[ctxt_pP->module_id].measGapConfig[eNB_index],
+                                (LTE_TDD_Config_t *)NULL,
+                                (LTE_MobilityControlInfo_t *)NULL,
+                                NULL,
+                                NULL,
+                                NULL,
+                                NULL,
+                                NULL,
+                                NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+                                ,
+                                0,
+                                (LTE_MBSFN_AreaInfoList_r9_t *)NULL,
+                                (LTE_PMCH_InfoList_r9_t *)NULL
 #endif
 #ifdef CBA
-				,
-				0,
-				0
+                                ,
+                                0,
+                                0
 #endif
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-           ,
-           0,
-           NULL,
-           NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                                ,
+                                0,
+                                NULL,
+                                NULL
 #endif
-				);
+                               );
         }
       }
     }
@@ -1651,22 +1478,19 @@ rrc_ue_process_radioResourceConfigDedicated(
 
   // Establish DRBs if present
   if (radioResourceConfigDedicated->drb_ToAddModList) {
-
     if ( (UE_rrc_inst[ctxt_pP->module_id].defaultDRB == NULL) &&
          (radioResourceConfigDedicated->drb_ToAddModList->list.count >= 1) ) {
-        // configure the first DRB ID as the default DRB ID
-        UE_rrc_inst[ctxt_pP->module_id].defaultDRB = malloc(sizeof(rb_id_t));
-        *UE_rrc_inst[ctxt_pP->module_id].defaultDRB = radioResourceConfigDedicated->drb_ToAddModList->list.array[0]->drb_Identity;
-        LOG_I(RRC,"[UE %d] default DRB = %d\n",ctxt_pP->module_id, *UE_rrc_inst[ctxt_pP->module_id].defaultDRB);
-      }
+      // configure the first DRB ID as the default DRB ID
+      UE_rrc_inst[ctxt_pP->module_id].defaultDRB = malloc(sizeof(rb_id_t));
+      *UE_rrc_inst[ctxt_pP->module_id].defaultDRB = radioResourceConfigDedicated->drb_ToAddModList->list.array[0]->drb_Identity;
+      LOG_I(RRC,"[UE %d] default DRB = %d\n",ctxt_pP->module_id, *UE_rrc_inst[ctxt_pP->module_id].defaultDRB);
+    }
 
     uint8_t *kUPenc = NULL;
-
 #if defined(ENABLE_SECURITY)
     derive_key_up_enc(UE_rrc_inst[ctxt_pP->module_id].integrity_algorithm,
                       UE_rrc_inst[ctxt_pP->module_id].kenb, &kUPenc);
 #endif
-
     MSC_LOG_TX_MESSAGE(
       MSC_RRC_UE,
       MSC_PDCP_UE,
@@ -1677,29 +1501,27 @@ rrc_ue_process_radioResourceConfigDedicated(
       ctxt_pP->rnti,
       UE_rrc_inst[ctxt_pP->module_id].ciphering_algorithm |
       (UE_rrc_inst[ctxt_pP->module_id].integrity_algorithm << 4));
-
     // Refresh DRBs
     rrc_pdcp_config_asn1_req(ctxt_pP,
-                             (SRB_ToAddModList_t*)NULL,
+                             (LTE_SRB_ToAddModList_t *)NULL,
                              radioResourceConfigDedicated->drb_ToAddModList,
-                             (DRB_ToReleaseList_t*)NULL,
+                             (LTE_DRB_ToReleaseList_t *)NULL,
                              UE_rrc_inst[ctxt_pP->module_id].ciphering_algorithm |
                              (UE_rrc_inst[ctxt_pP->module_id].integrity_algorithm << 4),
                              NULL,
                              NULL,
                              kUPenc
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-                             ,(PMCH_InfoList_r9_t *)NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+                             ,(LTE_PMCH_InfoList_r9_t *)NULL
 #endif
                              , UE_rrc_inst[ctxt_pP->module_id].defaultDRB);
-
     // Refresh DRBs
     rrc_rlc_config_asn1_req(ctxt_pP,
-                            (SRB_ToAddModList_t*)NULL,
+                            (LTE_SRB_ToAddModList_t *)NULL,
                             radioResourceConfigDedicated->drb_ToAddModList,
-                            (DRB_ToReleaseList_t*)NULL
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-                            ,(PMCH_InfoList_r9_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
                            );
@@ -1710,7 +1532,7 @@ rrc_ue_process_radioResourceConfigDedicated(
       if (UE_rrc_inst[ctxt_pP->module_id].DRB_config[eNB_index][DRB_id]) {
         memcpy(UE_rrc_inst[ctxt_pP->module_id].DRB_config[eNB_index][DRB_id],
                radioResourceConfigDedicated->drb_ToAddModList->list.array[i],
-               sizeof(struct DRB_ToAddMod));
+               sizeof(struct LTE_DRB_ToAddMod));
       } else {
         UE_rrc_inst[ctxt_pP->module_id].DRB_config[eNB_index][DRB_id] = radioResourceConfigDedicated->drb_ToAddModList->list.array[i];
         rrc_ue_establish_drb(ctxt_pP->module_id,ctxt_pP->frame,eNB_index,radioResourceConfigDedicated->drb_ToAddModList->list.array[i]);
@@ -1721,44 +1543,43 @@ rrc_ue_process_radioResourceConfigDedicated(
               eNB_index,
               ctxt_pP->module_id);
         rrc_mac_config_req_ue(ctxt_pP->module_id,0,eNB_index,
-			      (RadioResourceConfigCommonSIB_t *)NULL,
-			      UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index],
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-			      (SCellToAddMod_r10_t *)NULL,
-			      //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
-#endif
-			      (MeasObjectToAddMod_t **)NULL,
-			      UE_rrc_inst[ctxt_pP->module_id].mac_MainConfig[eNB_index],
-			      *UE_rrc_inst[ctxt_pP->module_id].DRB_config[eNB_index][DRB_id]->logicalChannelIdentity,
-			      UE_rrc_inst[ctxt_pP->module_id].DRB_config[eNB_index][DRB_id]->logicalChannelConfig,
-			      UE_rrc_inst[ctxt_pP->module_id].measGapConfig[eNB_index],
-			      (TDD_Config_t*)NULL,
-			      (MobilityControlInfo_t *)NULL,
-			      NULL,
-			      NULL,
-			      NULL,
-			      NULL,
-			      NULL,
-			      NULL
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-			      ,
-			      0,
-			      (MBSFN_AreaInfoList_r9_t *)NULL,
-			      (PMCH_InfoList_r9_t *)NULL
+                              (LTE_RadioResourceConfigCommonSIB_t *)NULL,
+                              UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index],
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                              (LTE_SCellToAddMod_r10_t *)NULL,
+                              //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
+#endif
+                              (LTE_MeasObjectToAddMod_t **)NULL,
+                              UE_rrc_inst[ctxt_pP->module_id].mac_MainConfig[eNB_index],
+                              *UE_rrc_inst[ctxt_pP->module_id].DRB_config[eNB_index][DRB_id]->logicalChannelIdentity,
+                              UE_rrc_inst[ctxt_pP->module_id].DRB_config[eNB_index][DRB_id]->logicalChannelConfig,
+                              UE_rrc_inst[ctxt_pP->module_id].measGapConfig[eNB_index],
+                              (LTE_TDD_Config_t *)NULL,
+                              (LTE_MobilityControlInfo_t *)NULL,
+                              NULL,
+                              NULL,
+                              NULL,
+                              NULL,
+                              NULL,
+                              NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+                              ,
+                              0,
+                              (LTE_MBSFN_AreaInfoList_r9_t *)NULL,
+                              (LTE_PMCH_InfoList_r9_t *)NULL
 #endif
 #ifdef CBA
-			      ,
-			      UE_rrc_inst[ue_mod_idP].num_active_cba_groups, //
-			      UE_rrc_inst[ue_mod_idP].cba_rnti[0]
+                              ,
+                              UE_rrc_inst[ue_mod_idP].num_active_cba_groups, //
+                              UE_rrc_inst[ue_mod_idP].cba_rnti[0]
 #endif
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-           ,
-           0,
-           NULL,
-           NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                              ,
+                              0,
+                              NULL,
+                              NULL
 #endif
-			      );
-
+                             );
       }
     }
   }
@@ -1771,86 +1592,79 @@ rrc_ue_process_radioResourceConfigDedicated(
 //-----------------------------------------------------------------------------
 void
 rrc_ue_process_securityModeCommand(
-  const protocol_ctxt_t* const ctxt_pP,
-  SecurityModeCommand_t* const securityModeCommand,
+  const protocol_ctxt_t *const ctxt_pP,
+  LTE_SecurityModeCommand_t *const securityModeCommand,
   const uint8_t                eNB_index
 )
 //-----------------------------------------------------------------------------
 {
-
   asn_enc_rval_t enc_rval;
-
-  UL_DCCH_Message_t ul_dcch_msg;
+  LTE_UL_DCCH_Message_t ul_dcch_msg;
   // SecurityModeCommand_t SecurityModeCommand;
   uint8_t buffer[200];
   int i, securityMode;
-
   LOG_I(RRC,"[UE %d] SFN/SF %d/%d: Receiving from SRB1 (DL-DCCH), Processing securityModeCommand (eNB %d)\n",
         ctxt_pP->module_id,ctxt_pP->frame, ctxt_pP->subframe, eNB_index);
 
   switch (securityModeCommand->criticalExtensions.choice.c1.choice.securityModeCommand_r8.securityConfigSMC.securityAlgorithmConfig.cipheringAlgorithm) {
-  case CipheringAlgorithm_r12_eea0:
-    LOG_I(RRC,"[UE %d] Security algorithm is set to eea0\n",
-          ctxt_pP->module_id);
-    securityMode= CipheringAlgorithm_r12_eea0;
-    break;
-
-  case CipheringAlgorithm_r12_eea1:
-    LOG_I(RRC,"[UE %d] Security algorithm is set to eea1\n",ctxt_pP->module_id);
-    securityMode= CipheringAlgorithm_r12_eea1;
-    break;
-
-  case CipheringAlgorithm_r12_eea2:
-    LOG_I(RRC,"[UE %d] Security algorithm is set to eea2\n",
-          ctxt_pP->module_id);
-    securityMode = CipheringAlgorithm_r12_eea2;
-    break;
-
-  default:
-    LOG_I(RRC,"[UE %d] Security algorithm is set to none\n",ctxt_pP->module_id);
-    securityMode = CipheringAlgorithm_r12_spare1;
-    break;
+    case LTE_CipheringAlgorithm_r12_eea0:
+      LOG_I(RRC,"[UE %d] Security algorithm is set to eea0\n",
+            ctxt_pP->module_id);
+      securityMode= LTE_CipheringAlgorithm_r12_eea0;
+      break;
+
+    case LTE_CipheringAlgorithm_r12_eea1:
+      LOG_I(RRC,"[UE %d] Security algorithm is set to eea1\n",ctxt_pP->module_id);
+      securityMode= LTE_CipheringAlgorithm_r12_eea1;
+      break;
+
+    case LTE_CipheringAlgorithm_r12_eea2:
+      LOG_I(RRC,"[UE %d] Security algorithm is set to eea2\n",
+            ctxt_pP->module_id);
+      securityMode = LTE_CipheringAlgorithm_r12_eea2;
+      break;
+
+    default:
+      LOG_I(RRC,"[UE %d] Security algorithm is set to none\n",ctxt_pP->module_id);
+      securityMode = LTE_CipheringAlgorithm_r12_spare1;
+      break;
   }
 
   switch (securityModeCommand->criticalExtensions.choice.c1.choice.securityModeCommand_r8.securityConfigSMC.securityAlgorithmConfig.integrityProtAlgorithm) {
-  case SecurityAlgorithmConfig__integrityProtAlgorithm_eia1:
-    LOG_I(RRC,"[UE %d] Integrity protection algorithm is set to eia1\n",ctxt_pP->module_id);
-    securityMode |= 1 << 5;
-    break;
-
-  case SecurityAlgorithmConfig__integrityProtAlgorithm_eia2:
-    LOG_I(RRC,"[UE %d] Integrity protection algorithm is set to eia2\n",ctxt_pP->module_id);
-    securityMode |= 1 << 6;
-    break;
-
-  default:
-    LOG_I(RRC,"[UE %d] Integrity protection algorithm is set to none\n",ctxt_pP->module_id);
-    securityMode |= 0x70 ;
-    break;
+    case LTE_SecurityAlgorithmConfig__integrityProtAlgorithm_eia1:
+      LOG_I(RRC,"[UE %d] Integrity protection algorithm is set to eia1\n",ctxt_pP->module_id);
+      securityMode |= 1 << 5;
+      break;
+
+    case LTE_SecurityAlgorithmConfig__integrityProtAlgorithm_eia2:
+      LOG_I(RRC,"[UE %d] Integrity protection algorithm is set to eia2\n",ctxt_pP->module_id);
+      securityMode |= 1 << 6;
+      break;
+
+    default:
+      LOG_I(RRC,"[UE %d] Integrity protection algorithm is set to none\n",ctxt_pP->module_id);
+      securityMode |= 0x70 ;
+      break;
   }
 
   LOG_D(RRC,"[UE %d] security mode is %x \n",ctxt_pP->module_id, securityMode);
-
   /* Store the parameters received */
   UE_rrc_inst[ctxt_pP->module_id].ciphering_algorithm =
     securityModeCommand->criticalExtensions.choice.c1.choice.securityModeCommand_r8.securityConfigSMC.securityAlgorithmConfig.cipheringAlgorithm;
   UE_rrc_inst[ctxt_pP->module_id].integrity_algorithm =
     securityModeCommand->criticalExtensions.choice.c1.choice.securityModeCommand_r8.securityConfigSMC.securityAlgorithmConfig.integrityProtAlgorithm;
-
-  memset((void *)&ul_dcch_msg,0,sizeof(UL_DCCH_Message_t));
+  memset((void *)&ul_dcch_msg,0,sizeof(LTE_UL_DCCH_Message_t));
   //memset((void *)&SecurityModeCommand,0,sizeof(SecurityModeCommand_t));
-
-  ul_dcch_msg.message.present           = UL_DCCH_MessageType_PR_c1;
+  ul_dcch_msg.message.present           = LTE_UL_DCCH_MessageType_PR_c1;
 
   if (securityMode >= NO_SECURITY_MODE) {
-	  LOG_I(RRC, "rrc_ue_process_securityModeCommand, security mode complete case \n");
-    ul_dcch_msg.message.choice.c1.present = UL_DCCH_MessageType__c1_PR_securityModeComplete;
+    LOG_I(RRC, "rrc_ue_process_securityModeCommand, security mode complete case \n");
+    ul_dcch_msg.message.choice.c1.present = LTE_UL_DCCH_MessageType__c1_PR_securityModeComplete;
   } else {
-	  LOG_I(RRC, "rrc_ue_process_securityModeCommand, security mode failure case \n");
-    ul_dcch_msg.message.choice.c1.present = UL_DCCH_MessageType__c1_PR_securityModeFailure;
+    LOG_I(RRC, "rrc_ue_process_securityModeCommand, security mode failure case \n");
+    ul_dcch_msg.message.choice.c1.present = LTE_UL_DCCH_MessageType__c1_PR_securityModeFailure;
   }
 
-
 #if defined(ENABLE_SECURITY)
   uint8_t *kRRCenc = NULL;
   uint8_t *kUPenc = NULL;
@@ -1858,47 +1672,44 @@ rrc_ue_process_securityModeCommand(
   pdcp_t *pdcp_p = NULL;
   hash_key_t key = HASHTABLE_NOT_A_KEY_VALUE;
   hashtable_rc_t h_rc;
-
   key = PDCP_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti,
-      ctxt_pP->enb_flag, DCCH, SRB_FLAG_YES);
-  h_rc = hashtable_get(pdcp_coll_p, key, (void**) &pdcp_p);
+                            ctxt_pP->enb_flag, DCCH, SRB_FLAG_YES);
+  h_rc = hashtable_get(pdcp_coll_p, key, (void **) &pdcp_p);
 
   if (h_rc == HASH_TABLE_OK) {
     LOG_D(RRC, "PDCP_COLL_KEY_VALUE() returns valid key = %ld\n", key);
-
     LOG_D(RRC, "driving kRRCenc, kRRCint and kUPenc from KeNB="
-        "%02x%02x%02x%02x"
-        "%02x%02x%02x%02x"
-        "%02x%02x%02x%02x"
-        "%02x%02x%02x%02x"
-        "%02x%02x%02x%02x"
-        "%02x%02x%02x%02x"
-        "%02x%02x%02x%02x"
-        "%02x%02x%02x%02x\n",
-        UE_rrc_inst[ctxt_pP->module_id].kenb[0],  UE_rrc_inst[ctxt_pP->module_id].kenb[1],  UE_rrc_inst[ctxt_pP->module_id].kenb[2],  UE_rrc_inst[ctxt_pP->module_id].kenb[3],
-        UE_rrc_inst[ctxt_pP->module_id].kenb[4],  UE_rrc_inst[ctxt_pP->module_id].kenb[5],  UE_rrc_inst[ctxt_pP->module_id].kenb[6],  UE_rrc_inst[ctxt_pP->module_id].kenb[7],
-        UE_rrc_inst[ctxt_pP->module_id].kenb[8],  UE_rrc_inst[ctxt_pP->module_id].kenb[9],  UE_rrc_inst[ctxt_pP->module_id].kenb[10], UE_rrc_inst[ctxt_pP->module_id].kenb[11],
-        UE_rrc_inst[ctxt_pP->module_id].kenb[12], UE_rrc_inst[ctxt_pP->module_id].kenb[13], UE_rrc_inst[ctxt_pP->module_id].kenb[14], UE_rrc_inst[ctxt_pP->module_id].kenb[15],
-        UE_rrc_inst[ctxt_pP->module_id].kenb[16], UE_rrc_inst[ctxt_pP->module_id].kenb[17], UE_rrc_inst[ctxt_pP->module_id].kenb[18], UE_rrc_inst[ctxt_pP->module_id].kenb[19],
-        UE_rrc_inst[ctxt_pP->module_id].kenb[20], UE_rrc_inst[ctxt_pP->module_id].kenb[21], UE_rrc_inst[ctxt_pP->module_id].kenb[22], UE_rrc_inst[ctxt_pP->module_id].kenb[23],
-        UE_rrc_inst[ctxt_pP->module_id].kenb[24], UE_rrc_inst[ctxt_pP->module_id].kenb[25], UE_rrc_inst[ctxt_pP->module_id].kenb[26], UE_rrc_inst[ctxt_pP->module_id].kenb[27],
-        UE_rrc_inst[ctxt_pP->module_id].kenb[28], UE_rrc_inst[ctxt_pP->module_id].kenb[29], UE_rrc_inst[ctxt_pP->module_id].kenb[30], UE_rrc_inst[ctxt_pP->module_id].kenb[31]);
-
+          "%02x%02x%02x%02x"
+          "%02x%02x%02x%02x"
+          "%02x%02x%02x%02x"
+          "%02x%02x%02x%02x"
+          "%02x%02x%02x%02x"
+          "%02x%02x%02x%02x"
+          "%02x%02x%02x%02x"
+          "%02x%02x%02x%02x\n",
+          UE_rrc_inst[ctxt_pP->module_id].kenb[0],  UE_rrc_inst[ctxt_pP->module_id].kenb[1],  UE_rrc_inst[ctxt_pP->module_id].kenb[2],  UE_rrc_inst[ctxt_pP->module_id].kenb[3],
+          UE_rrc_inst[ctxt_pP->module_id].kenb[4],  UE_rrc_inst[ctxt_pP->module_id].kenb[5],  UE_rrc_inst[ctxt_pP->module_id].kenb[6],  UE_rrc_inst[ctxt_pP->module_id].kenb[7],
+          UE_rrc_inst[ctxt_pP->module_id].kenb[8],  UE_rrc_inst[ctxt_pP->module_id].kenb[9],  UE_rrc_inst[ctxt_pP->module_id].kenb[10], UE_rrc_inst[ctxt_pP->module_id].kenb[11],
+          UE_rrc_inst[ctxt_pP->module_id].kenb[12], UE_rrc_inst[ctxt_pP->module_id].kenb[13], UE_rrc_inst[ctxt_pP->module_id].kenb[14], UE_rrc_inst[ctxt_pP->module_id].kenb[15],
+          UE_rrc_inst[ctxt_pP->module_id].kenb[16], UE_rrc_inst[ctxt_pP->module_id].kenb[17], UE_rrc_inst[ctxt_pP->module_id].kenb[18], UE_rrc_inst[ctxt_pP->module_id].kenb[19],
+          UE_rrc_inst[ctxt_pP->module_id].kenb[20], UE_rrc_inst[ctxt_pP->module_id].kenb[21], UE_rrc_inst[ctxt_pP->module_id].kenb[22], UE_rrc_inst[ctxt_pP->module_id].kenb[23],
+          UE_rrc_inst[ctxt_pP->module_id].kenb[24], UE_rrc_inst[ctxt_pP->module_id].kenb[25], UE_rrc_inst[ctxt_pP->module_id].kenb[26], UE_rrc_inst[ctxt_pP->module_id].kenb[27],
+          UE_rrc_inst[ctxt_pP->module_id].kenb[28], UE_rrc_inst[ctxt_pP->module_id].kenb[29], UE_rrc_inst[ctxt_pP->module_id].kenb[30], UE_rrc_inst[ctxt_pP->module_id].kenb[31]);
     derive_key_rrc_enc(UE_rrc_inst[ctxt_pP->module_id].ciphering_algorithm,
-        UE_rrc_inst[ctxt_pP->module_id].kenb, &kRRCenc);
+                       UE_rrc_inst[ctxt_pP->module_id].kenb, &kRRCenc);
     derive_key_rrc_int(UE_rrc_inst[ctxt_pP->module_id].integrity_algorithm,
-        UE_rrc_inst[ctxt_pP->module_id].kenb, &kRRCint);
+                       UE_rrc_inst[ctxt_pP->module_id].kenb, &kRRCint);
     derive_key_up_enc(UE_rrc_inst[ctxt_pP->module_id].ciphering_algorithm,
-        UE_rrc_inst[ctxt_pP->module_id].kenb, &kUPenc);
+                      UE_rrc_inst[ctxt_pP->module_id].kenb, &kUPenc);
 
     if (securityMode != 0xff) {
       pdcp_config_set_security(ctxt_pP, pdcp_p, 0, 0,
-          UE_rrc_inst[ctxt_pP->module_id].ciphering_algorithm
-              | (UE_rrc_inst[ctxt_pP->module_id].integrity_algorithm << 4),
-          kRRCenc, kRRCint, kUPenc);
+                               UE_rrc_inst[ctxt_pP->module_id].ciphering_algorithm
+                               | (UE_rrc_inst[ctxt_pP->module_id].integrity_algorithm << 4),
+                               kRRCenc, kRRCint, kUPenc);
     } else {
       LOG_I(RRC, "skipped pdcp_config_set_security() as securityMode == 0x%02x",
-          securityMode);
+            securityMode);
     }
   } else {
     LOG_I(RRC, "Could not get PDCP instance where key=0x%ld\n", key);
@@ -1906,177 +1717,113 @@ rrc_ue_process_securityModeCommand(
 
 #endif //#if defined(ENABLE_SECURITY)
 
-  if (securityModeCommand->criticalExtensions.present == SecurityModeCommand__criticalExtensions_PR_c1) {
-    if (securityModeCommand->criticalExtensions.choice.c1.present != SecurityModeCommand__criticalExtensions__c1_PR_securityModeCommand_r8)
+  if (securityModeCommand->criticalExtensions.present == LTE_SecurityModeCommand__criticalExtensions_PR_c1) {
+    if (securityModeCommand->criticalExtensions.choice.c1.present != LTE_SecurityModeCommand__criticalExtensions__c1_PR_securityModeCommand_r8)
       LOG_W(RRC,"securityModeCommand->criticalExtensions.choice.c1.present (%d) != SecurityModeCommand__criticalExtensions__c1_PR_securityModeCommand_r8\n",
-	    securityModeCommand->criticalExtensions.choice.c1.present);
-    
-    
+            securityModeCommand->criticalExtensions.choice.c1.present);
+
     ul_dcch_msg.message.choice.c1.choice.securityModeComplete.rrc_TransactionIdentifier = securityModeCommand->rrc_TransactionIdentifier;
-    ul_dcch_msg.message.choice.c1.choice.securityModeComplete.criticalExtensions.present = SecurityModeCommand__criticalExtensions_PR_c1;
+    ul_dcch_msg.message.choice.c1.choice.securityModeComplete.criticalExtensions.present = LTE_SecurityModeCommand__criticalExtensions_PR_c1;
     ul_dcch_msg.message.choice.c1.choice.securityModeComplete.criticalExtensions.choice.securityModeComplete_r8.nonCriticalExtension =NULL;
-    
     LOG_I(RRC,"[UE %d] SFN/SF %d/%d: Receiving from SRB1 (DL-DCCH), encoding securityModeComplete (eNB %d), rrc_TransactionIdentifier: %ld\n",
-	  ctxt_pP->module_id,ctxt_pP->frame, ctxt_pP->subframe, eNB_index, securityModeCommand->rrc_TransactionIdentifier);
-    
-    enc_rval = uper_encode_to_buffer(&asn_DEF_UL_DCCH_Message,
+          ctxt_pP->module_id,ctxt_pP->frame, ctxt_pP->subframe, eNB_index, securityModeCommand->rrc_TransactionIdentifier);
+    enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_UL_DCCH_Message,
                                      NULL,
-				     (void*)&ul_dcch_msg,
-				     buffer,
-				     100);
+                                     (void *)&ul_dcch_msg,
+                                     buffer,
+                                     100);
     AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %jd)!\n",
-		 enc_rval.failed_type->name, enc_rval.encoded);
-    
+                 enc_rval.failed_type->name, enc_rval.encoded);
+
     if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-       xer_fprint(stdout, &asn_DEF_UL_DCCH_Message, (void*)&ul_dcch_msg);
-    }
-    
-#if defined(ENABLE_ITTI)
-# if !defined(DISABLE_XER_SPRINT)
-    {
-      char        message_string[20000];
-      size_t      message_string_size;
-      
-      if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_UL_DCCH_Message, (void *) &ul_dcch_msg)) > 0) {
-	MessageDef *msg_p;
-	
-	msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, RRC_UL_DCCH, message_string_size + sizeof (IttiMsgText));
-	msg_p->ittiMsg.rrc_ul_dcch.size = message_string_size;
-	memcpy(&msg_p->ittiMsg.rrc_ul_dcch.text, message_string, message_string_size);
-	
-	itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
-      }
+      xer_fprint(stdout, &asn_DEF_LTE_UL_DCCH_Message, (void *)&ul_dcch_msg);
     }
-# endif
-#endif
-
-      LOG_D(RRC, "securityModeComplete Encoded %zd bits (%zd bytes)\n", enc_rval.encoded, (enc_rval.encoded+7)/8);
 
-      for (i = 0; i < (enc_rval.encoded + 7) / 8; i++) {
-        LOG_T(RRC, "%02x.", buffer[i]);
-      }
+    LOG_D(RRC, "securityModeComplete Encoded %zd bits (%zd bytes)\n", enc_rval.encoded, (enc_rval.encoded+7)/8);
 
-      LOG_T(RRC, "\n");
-      rrc_data_req (
-		    ctxt_pP,
-		    DCCH,
-		    rrc_mui++,
-		    SDU_CONFIRM_NO,
-		    (enc_rval.encoded + 7) / 8,
-		    buffer,
-		    PDCP_TRANSMISSION_MODE_CONTROL);
+    for (i = 0; i < (enc_rval.encoded + 7) / 8; i++) {
+      LOG_T(RRC, "%02x.", buffer[i]);
     }
-    
-  else LOG_W(RRC,"securityModeCommand->criticalExtensions.present (%d) != SecurityModeCommand__criticalExtensions_PR_c1\n",
-	     securityModeCommand->criticalExtensions.present);
+
+    LOG_T(RRC, "\n");
+    rrc_data_req (
+      ctxt_pP,
+      DCCH,
+      rrc_mui++,
+      SDU_CONFIRM_NO,
+      (enc_rval.encoded + 7) / 8,
+      buffer,
+      PDCP_TRANSMISSION_MODE_CONTROL);
+  } else LOG_W(RRC,"securityModeCommand->criticalExtensions.present (%d) != SecurityModeCommand__criticalExtensions_PR_c1\n",
+                 securityModeCommand->criticalExtensions.present);
 }
 
 //-----------------------------------------------------------------------------
 void
 rrc_ue_process_ueCapabilityEnquiry(
-  const protocol_ctxt_t* const ctxt_pP,
-  UECapabilityEnquiry_t* UECapabilityEnquiry,
+  const protocol_ctxt_t *const ctxt_pP,
+  LTE_UECapabilityEnquiry_t *UECapabilityEnquiry,
   uint8_t eNB_index
 )
 //-----------------------------------------------------------------------------
 {
-
   asn_enc_rval_t enc_rval;
-
-  UL_DCCH_Message_t ul_dcch_msg;
-
-
-  UE_CapabilityRAT_Container_t ue_CapabilityRAT_Container;
-
+  LTE_UL_DCCH_Message_t ul_dcch_msg;
+  LTE_UE_CapabilityRAT_Container_t ue_CapabilityRAT_Container;
   uint8_t buffer[200];
   int i;
-
   LOG_I(RRC,"[UE %d] Frame %d: Receiving from SRB1 (DL-DCCH), Processing UECapabilityEnquiry (eNB %d)\n",
         ctxt_pP->module_id,
         ctxt_pP->frame,
         eNB_index);
-
-
-  memset((void *)&ul_dcch_msg,0,sizeof(UL_DCCH_Message_t));
-  memset((void *)&ue_CapabilityRAT_Container,0,sizeof(UE_CapabilityRAT_Container_t));
-
-  ul_dcch_msg.message.present           = UL_DCCH_MessageType_PR_c1;
-  ul_dcch_msg.message.choice.c1.present = UL_DCCH_MessageType__c1_PR_ueCapabilityInformation;
+  memset((void *)&ul_dcch_msg,0,sizeof(LTE_UL_DCCH_Message_t));
+  memset((void *)&ue_CapabilityRAT_Container,0,sizeof(LTE_UE_CapabilityRAT_Container_t));
+  ul_dcch_msg.message.present           = LTE_UL_DCCH_MessageType_PR_c1;
+  ul_dcch_msg.message.choice.c1.present = LTE_UL_DCCH_MessageType__c1_PR_ueCapabilityInformation;
   ul_dcch_msg.message.choice.c1.choice.ueCapabilityInformation.rrc_TransactionIdentifier = UECapabilityEnquiry->rrc_TransactionIdentifier;
-
-  ue_CapabilityRAT_Container.rat_Type = RAT_Type_eutra;
+  ue_CapabilityRAT_Container.rat_Type = LTE_RAT_Type_eutra;
   OCTET_STRING_fromBuf(&ue_CapabilityRAT_Container.ueCapabilityRAT_Container,
-                       (const char*)UE_rrc_inst[ctxt_pP->module_id].UECapability,
+                       (const char *)UE_rrc_inst[ctxt_pP->module_id].UECapability,
                        UE_rrc_inst[ctxt_pP->module_id].UECapability_size);
   //  ue_CapabilityRAT_Container.ueCapabilityRAT_Container.buf  = UE_rrc_inst[ue_mod_idP].UECapability;
   // ue_CapabilityRAT_Container.ueCapabilityRAT_Container.size = UE_rrc_inst[ue_mod_idP].UECapability_size;
+  AssertFatal(UECapabilityEnquiry->criticalExtensions.present == LTE_UECapabilityEnquiry__criticalExtensions_PR_c1,
+              "UECapabilityEnquiry->criticalExtensions.present (%d) != UECapabilityEnquiry__criticalExtensions_PR_c1 (%d)\n",
+              UECapabilityEnquiry->criticalExtensions.present,LTE_UECapabilityEnquiry__criticalExtensions_PR_c1);
 
-
-  AssertFatal(UECapabilityEnquiry->criticalExtensions.present == UECapabilityEnquiry__criticalExtensions_PR_c1,
-	      "UECapabilityEnquiry->criticalExtensions.present (%d) != UECapabilityEnquiry__criticalExtensions_PR_c1 (%d)\n",
-	      UECapabilityEnquiry->criticalExtensions.present,UECapabilityEnquiry__criticalExtensions_PR_c1);
-
-  if (UECapabilityEnquiry->criticalExtensions.choice.c1.present != UECapabilityEnquiry__criticalExtensions__c1_PR_ueCapabilityEnquiry_r8)
+  if (UECapabilityEnquiry->criticalExtensions.choice.c1.present != LTE_UECapabilityEnquiry__criticalExtensions__c1_PR_ueCapabilityEnquiry_r8)
     LOG_I(RRC,"UECapabilityEnquiry->criticalExtensions.choice.c1.present (%d) != UECapabilityEnquiry__criticalExtensions__c1_PR_ueCapabilityEnquiry_r8)\n",
-	  UECapabilityEnquiry->criticalExtensions.choice.c1.present);
-  
-  ul_dcch_msg.message.choice.c1.choice.ueCapabilityInformation.criticalExtensions.present           = UECapabilityInformation__criticalExtensions_PR_c1;
+          UECapabilityEnquiry->criticalExtensions.choice.c1.present);
+
+  ul_dcch_msg.message.choice.c1.choice.ueCapabilityInformation.criticalExtensions.present           = LTE_UECapabilityInformation__criticalExtensions_PR_c1;
   ul_dcch_msg.message.choice.c1.choice.ueCapabilityInformation.criticalExtensions.choice.c1.present =
-    UECapabilityInformation__criticalExtensions__c1_PR_ueCapabilityInformation_r8;
+    LTE_UECapabilityInformation__criticalExtensions__c1_PR_ueCapabilityInformation_r8;
   ul_dcch_msg.message.choice.c1.choice.ueCapabilityInformation.criticalExtensions.choice.c1.choice.ueCapabilityInformation_r8.ue_CapabilityRAT_ContainerList.list.count
     =0;
-  
+
   for (i=0; i<UECapabilityEnquiry->criticalExtensions.choice.c1.choice.ueCapabilityEnquiry_r8.ue_CapabilityRequest.list.count; i++) {
-    
     if (*UECapabilityEnquiry->criticalExtensions.choice.c1.choice.ueCapabilityEnquiry_r8.ue_CapabilityRequest.list.array[i]
-	== RAT_Type_eutra) {
+        == LTE_RAT_Type_eutra) {
       ASN_SEQUENCE_ADD(
-		       &ul_dcch_msg.message.choice.c1.choice.ueCapabilityInformation.criticalExtensions.choice.c1.choice.ueCapabilityInformation_r8.ue_CapabilityRAT_ContainerList.list,
-		       &ue_CapabilityRAT_Container);
-      
-      enc_rval = uper_encode_to_buffer(&asn_DEF_UL_DCCH_Message, NULL, (void*) &ul_dcch_msg, buffer, 100);
+        &ul_dcch_msg.message.choice.c1.choice.ueCapabilityInformation.criticalExtensions.choice.c1.choice.ueCapabilityInformation_r8.ue_CapabilityRAT_ContainerList.list,
+        &ue_CapabilityRAT_Container);
+      enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_UL_DCCH_Message, NULL, (void *) &ul_dcch_msg, buffer, 100);
       AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %jd)!\n",
-		   enc_rval.failed_type->name, enc_rval.encoded);
-      
+                   enc_rval.failed_type->name, enc_rval.encoded);
+
       if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-         xer_fprint(stdout, &asn_DEF_UL_DCCH_Message, (void*)&ul_dcch_msg);
-      }
-      
-#if defined(ENABLE_ITTI)
-# if !defined(DISABLE_XER_SPRINT)
-      {
-	char        message_string[20000];
-	size_t      message_string_size;
-	
-	if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_UL_DCCH_Message, (void *) &ul_dcch_msg)) > 0) {
-	  MessageDef *msg_p;
-	  
-	  msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, RRC_UL_DCCH, message_string_size + sizeof (IttiMsgText));
-	  msg_p->ittiMsg.rrc_ul_dcch.size = message_string_size;
-	  memcpy(&msg_p->ittiMsg.rrc_ul_dcch.text, message_string, message_string_size);
-	  
-	  itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
-	}
+        xer_fprint(stdout, &asn_DEF_LTE_UL_DCCH_Message, (void *)&ul_dcch_msg);
       }
-# endif
-#endif
-	
 
-          LOG_I(RRC,"UECapabilityInformation Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
-
-          for (i = 0; i < (enc_rval.encoded + 7) / 8; i++) {
-            LOG_T(RRC, "%02x.", buffer[i]);
-          }
-      
-      LOG_T(RRC, "\n");
+      LOG_I(RRC,"UECapabilityInformation Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
       rrc_data_req_ue (
-		    ctxt_pP,
-		    DCCH,
-		    rrc_mui++,
-		    SDU_CONFIRM_NO,
-		    (enc_rval.encoded + 7) / 8,
-		    buffer,
-		    PDCP_TRANSMISSION_MODE_CONTROL);
+        ctxt_pP,
+        DCCH,
+        rrc_mui++,
+        SDU_CONFIRM_NO,
+        (enc_rval.encoded + 7) / 8,
+        buffer,
+        PDCP_TRANSMISSION_MODE_CONTROL);
     }
   }
 }
@@ -2085,20 +1832,19 @@ rrc_ue_process_ueCapabilityEnquiry(
 //-----------------------------------------------------------------------------
 void
 rrc_ue_process_rrcConnectionReconfiguration(
-  const protocol_ctxt_t* const       ctxt_pP,
-  RRCConnectionReconfiguration_t *rrcConnectionReconfiguration,
+  const protocol_ctxt_t *const       ctxt_pP,
+  LTE_RRCConnectionReconfiguration_t *rrcConnectionReconfiguration,
   uint8_t eNB_index
 )
 //-----------------------------------------------------------------------------
 {
-
   LOG_I(RRC,"[UE %d] Frame %d: Receiving from SRB1 (DL-DCCH), Processing RRCConnectionReconfiguration (eNB %d)\n",
         ctxt_pP->module_id,ctxt_pP->frame,eNB_index);
 
-  if (rrcConnectionReconfiguration->criticalExtensions.present == RRCConnectionReconfiguration__criticalExtensions_PR_c1) {
+  if (rrcConnectionReconfiguration->criticalExtensions.present == LTE_RRCConnectionReconfiguration__criticalExtensions_PR_c1) {
     if (rrcConnectionReconfiguration->criticalExtensions.choice.c1.present ==
-        RRCConnectionReconfiguration__criticalExtensions__c1_PR_rrcConnectionReconfiguration_r8) {
-      RRCConnectionReconfiguration_r8_IEs_t* rrcConnectionReconfiguration_r8 =
+        LTE_RRCConnectionReconfiguration__criticalExtensions__c1_PR_rrcConnectionReconfiguration_r8) {
+      LTE_RRCConnectionReconfiguration_r8_IEs_t *rrcConnectionReconfiguration_r8 =
         &rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8;
 
       if (rrcConnectionReconfiguration_r8->mobilityControlInfo) {
@@ -2124,42 +1870,42 @@ rrc_ue_process_rrcConnectionReconfiguration(
       //TTN for D2D
       //if RRCConnectionReconfiguration message includes the sl-CommConfig
       if ((rrcConnectionReconfiguration_r8->nonCriticalExtension != NULL)
-            && (rrcConnectionReconfiguration_r8->nonCriticalExtension->nonCriticalExtension
-                  != NULL)
-                  && (rrcConnectionReconfiguration_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension
-                        != NULL)
-                        && (rrcConnectionReconfiguration_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension
-                              != NULL)
-                              && (rrcConnectionReconfiguration_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension
-                                    != NULL)
-                                    && (rrcConnectionReconfiguration_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_CommConfig_r12
-                                          != NULL)) {
-         if (rrcConnectionReconfiguration_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_CommConfig_r12->commTxResources_r12->present != SL_CommConfig_r12__commTxResources_r12_PR_NOTHING){
-            LOG_I(RRC,"sl-CommConfig is present\n");
-            //process sl-CommConfig
-            rrc_ue_process_sidelink_radioResourceConfig(ctxt_pP->module_id,eNB_index,
-                  (SystemInformationBlockType18_r12_t *)NULL,
-                  (SystemInformationBlockType19_r12_t *)NULL,
-                  rrcConnectionReconfiguration_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_CommConfig_r12,
-                  (SL_DiscConfig_r12_t *)NULL
-            );
-         }
-      }
-
-/*
-      //if RRCConnectionReconfiguration message includes the sl-DiscConfig
-      if (rrcConnectionReconfiguration_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_DiscConfig_r12->discTxResources_r12->present != SL_DiscConfig_r12__discTxResources_r12_PR_NOTHING ){
-         LOG_I(RRC,"sl-DiscConfig is present\n");
-         //process sl-DiscConfig
-         rrc_ue_process_sidelink_radioResourceConfig(ctxt_pP->module_id,eNB_index,
-               (SystemInformationBlockType18_r12_t *)NULL,
-               (SystemInformationBlockType19_r12_t *)NULL,
-               (SL_CommConfig_r12_t* )NULL,
-               rrcConnectionReconfiguration_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_DiscConfig_r12
-               );
+          && (rrcConnectionReconfiguration_r8->nonCriticalExtension->nonCriticalExtension
+              != NULL)
+          && (rrcConnectionReconfiguration_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension
+              != NULL)
+          && (rrcConnectionReconfiguration_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension
+              != NULL)
+          && (rrcConnectionReconfiguration_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension
+              != NULL)
+          && (rrcConnectionReconfiguration_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_CommConfig_r12
+              != NULL)) {
+        if (rrcConnectionReconfiguration_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_CommConfig_r12->commTxResources_r12->present !=
+            LTE_SL_CommConfig_r12__commTxResources_r12_PR_NOTHING) {
+          LOG_I(RRC,"sl-CommConfig is present\n");
+          //process sl-CommConfig
+          rrc_ue_process_sidelink_radioResourceConfig(ctxt_pP->module_id,eNB_index,
+              (LTE_SystemInformationBlockType18_r12_t *)NULL,
+              (LTE_SystemInformationBlockType19_r12_t *)NULL,
+              rrcConnectionReconfiguration_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_CommConfig_r12,
+              (LTE_SL_DiscConfig_r12_t *)NULL
+                                                     );
+        }
       }
-*/
 
+      /*
+            //if RRCConnectionReconfiguration message includes the sl-DiscConfig
+            if (rrcConnectionReconfiguration_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_DiscConfig_r12->discTxResources_r12->present != SL_DiscConfig_r12__discTxResources_r12_PR_NOTHING ){
+               LOG_I(RRC,"sl-DiscConfig is present\n");
+               //process sl-DiscConfig
+               rrc_ue_process_sidelink_radioResourceConfig(ctxt_pP->module_id,eNB_index,
+                     (SystemInformationBlockType18_r12_t *)NULL,
+                     (SystemInformationBlockType19_r12_t *)NULL,
+                     (SL_CommConfig_r12_t* )NULL,
+                     rrcConnectionReconfiguration_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_DiscConfig_r12
+                     );
+            }
+      */
 #if defined(ENABLE_ITTI)
 
       /* Check if there is dedicated NAS information to forward to NAS */
@@ -2172,12 +1918,10 @@ rrc_ue_process_rrcConnectionReconfiguration(
         for (list_count = 0; list_count < rrcConnectionReconfiguration_r8->dedicatedInfoNASList->list.count; list_count++) {
           pdu_length = rrcConnectionReconfiguration_r8->dedicatedInfoNASList->list.array[list_count]->size;
           pdu_buffer = rrcConnectionReconfiguration_r8->dedicatedInfoNASList->list.array[list_count]->buf;
-
           msg_p = itti_alloc_new_message(TASK_RRC_UE, NAS_CONN_ESTABLI_CNF);
           NAS_CONN_ESTABLI_CNF(msg_p).errCode = AS_SUCCESS;
           NAS_CONN_ESTABLI_CNF(msg_p).nasMsg.length = pdu_length;
           NAS_CONN_ESTABLI_CNF(msg_p).nasMsg.data = pdu_buffer;
-
           itti_send_msg_to_task(TASK_NAS_UE, ctxt_pP->instance, msg_p);
         }
 
@@ -2189,7 +1933,6 @@ rrc_ue_process_rrcConnectionReconfiguration(
         MessageDef                                 *message_ral_p = NULL;
         rrc_ral_connection_reestablishment_ind_t    connection_reestablishment_ind;
         int                                         i;
-
         message_ral_p = itti_alloc_new_message (TASK_RRC_UE, RRC_RAL_CONNECTION_REESTABLISHMENT_IND);
         memset(&connection_reestablishment_ind, 0, sizeof(rrc_ral_connection_reestablishment_ind_t));
         // TO DO ral_si_ind.plmn_id        = 0;
@@ -2214,7 +1957,6 @@ rrc_ue_process_rrcConnectionReconfiguration(
           connection_reestablishment_ind.num_srb      =
             rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->srb_ToAddModList->list.count +
             UE_rrc_inst[ctxt_pP->module_id].num_srb;
-
         } else {
           connection_reestablishment_ind.num_srb      += UE_rrc_inst[ctxt_pP->module_id].num_srb;
         }
@@ -2238,9 +1980,9 @@ rrc_ue_process_rrcConnectionReconfiguration(
 //-----------------------------------------------------------------------------
 void
 rrc_ue_process_mobilityControlInfo(
-  const protocol_ctxt_t* const       ctxt_pP,
+  const protocol_ctxt_t *const       ctxt_pP,
   const uint8_t                      eNB_index,
-  struct MobilityControlInfo* const mobilityControlInfo
+  struct LTE_MobilityControlInfo *const mobilityControlInfo
 )
 //-----------------------------------------------------------------------------
 {
@@ -2256,7 +1998,6 @@ rrc_ue_process_mobilityControlInfo(
 
   UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].T304_active = 1;
   UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].T304_cnt = T304[mobilityControlInfo->t304];
-
   /*
   drb2release_list = CALLOC (1, sizeof (*drb2release_list));
   lcid= CALLOC (1, sizeof (DRB_Identity_t)); // long
@@ -2282,22 +2023,20 @@ rrc_ue_process_mobilityControlInfo(
          NULL, // key rrc encryption
          NULL, // key rrc integrity
          NULL // key encryption
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+  #if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
          ,NULL
-#endif
+  #endif
          ,NULL);
 
   rrc_rlc_config_asn1_req(NB_eNB_INST+ue_mod_idP, frameP,0,eNB_index,
         NULL,// SRB_ToAddModList
         NULL,// DRB_ToAddModList
         drb2release_list // DRB_ToReleaseList
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+  #if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
         ,NULL
-#endif
+  #endif
         ,NULL);
    */
-
-
   //A little cleanup at RRC...
   //Copying current queue config to free RRC index
   /*
@@ -2319,53 +2058,49 @@ rrc_ue_process_mobilityControlInfo(
   LOG_I(RRC,
         "HO: Reset PDCP and RLC for configured RBs.. \n[FRAME %05d][RRC_UE][MOD %02d][][--- MAC_CONFIG_REQ  (SRB2 eNB %d) --->][MAC_UE][MOD %02d][]\n",
         ctxt_pP->frame, ctxt_pP->module_id, eNB_index, ctxt_pP->module_id);
-
   // Reset MAC and configure PHY
   rrc_mac_config_req_ue(ctxt_pP->module_id,
-			0,
-			eNB_index,
-			(RadioResourceConfigCommonSIB_t *)NULL,
-			(struct PhysicalConfigDedicated *)NULL,
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-			(SCellToAddMod_r10_t *)NULL,
-			//(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
-#endif
-			(MeasObjectToAddMod_t **)NULL,
-			(MAC_MainConfig_t *)NULL,
-			0,
-			(struct LogicalChannelConfig *)NULL,
-			(MeasGapConfig_t *)NULL,
-			(TDD_Config_t *)NULL,
-			mobilityControlInfo,
-			(uint8_t *)NULL,
-			(uint16_t *)NULL,
-			NULL,
-			NULL,
-			NULL,
-			NULL
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-			,0,
-			(MBSFN_AreaInfoList_r9_t *)NULL,
-			(PMCH_InfoList_r9_t *)NULL
+                        0,
+                        eNB_index,
+                        (LTE_RadioResourceConfigCommonSIB_t *)NULL,
+                        (struct LTE_PhysicalConfigDedicated *)NULL,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                        (LTE_SCellToAddMod_r10_t *)NULL,
+                        //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
+#endif
+                        (LTE_MeasObjectToAddMod_t **)NULL,
+                        (LTE_MAC_MainConfig_t *)NULL,
+                        0,
+                        (struct LTE_LogicalChannelConfig *)NULL,
+                        (LTE_MeasGapConfig_t *)NULL,
+                        (LTE_TDD_Config_t *)NULL,
+                        mobilityControlInfo,
+                        (uint8_t *)NULL,
+                        (uint16_t *)NULL,
+                        NULL,
+                        NULL,
+                        NULL,
+                        NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+                        ,0,
+                        (LTE_MBSFN_AreaInfoList_r9_t *)NULL,
+                        (LTE_PMCH_InfoList_r9_t *)NULL
 #endif
 #ifdef CBA
-			,0,
-			0
+                        ,0,
+                        0
 #endif
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-           ,
-           0,
-           NULL,
-           NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                        ,
+                        0,
+                        NULL,
+                        NULL
 #endif
-			);
-
+                       );
   // Re-establish PDCP for all RBs that are established
   // rrc_pdcp_config_req (ue_mod_idP+NB_eNB_INST, frameP, 0, CONFIG_ACTION_ADD, ue_mod_idP+DCCH);
   // rrc_pdcp_config_req (ue_mod_idP+NB_eNB_INST, frameP, 0, CONFIG_ACTION_ADD, ue_mod_idP+DCCH1);
   // rrc_pdcp_config_req (ue_mod_idP+NB_eNB_INST, frameP, 0, CONFIG_ACTION_ADD, ue_mod_idP+DTCH);
-
-
   // Re-establish RLC for all RBs that are established
   // rrc_rlc_config_req(ue_mod_idP+NB_eNB_INST,frameP,0,CONFIG_ACTION_ADD,ue_mod_idP+DCCH,SIGNALLING_RADIO_BEARER,Rlc_info_am_config);
   // rrc_rlc_config_req(ue_mod_idP+NB_eNB_INST,frameP,0,CONFIG_ACTION_ADD,ue_mod_idP+DCCH1,SIGNALLING_RADIO_BEARER,Rlc_info_am_config);
@@ -2387,16 +2122,15 @@ rrc_detach_from_eNB(
 //-----------------------------------------------------------------------------
 void
 rrc_ue_decode_dcch(
-  const protocol_ctxt_t* const ctxt_pP,
+  const protocol_ctxt_t *const ctxt_pP,
   const rb_id_t                Srb_id,
-  const uint8_t*         const Buffer,
+  const uint8_t         *const Buffer,
   const uint8_t                eNB_indexP
 )
 //-----------------------------------------------------------------------------
 {
-
   //DL_DCCH_Message_t dldcchmsg;
-  DL_DCCH_Message_t *dl_dcch_msg=NULL;//&dldcchmsg;
+  LTE_DL_DCCH_Message_t *dl_dcch_msg=NULL;//&dldcchmsg;
   //  asn_dec_rval_t dec_rval;
   // int i;
   uint8_t target_eNB_index=0xFF;
@@ -2410,336 +2144,296 @@ rrc_ue_decode_dcch(
     return;
   }
 
-  //memset(dl_dcch_msg,0,sizeof(DL_DCCH_Message_t));
-
-  // decode messages
-  //  LOG_D(RRC,"[UE %d] Decoding DL-DCCH message\n",ue_mod_idP);
-  /*
-  for (i=0;i<30;i++)
-    LOG_T(RRC,"%x.",Buffer[i]);
-  LOG_T(RRC, "\n");
-   */
   uper_decode(NULL,
-              &asn_DEF_DL_DCCH_Message,
-              (void**)&dl_dcch_msg,
-              (uint8_t*)Buffer,
+              &asn_DEF_LTE_DL_DCCH_Message,
+              (void **)&dl_dcch_msg,
+              (uint8_t *)Buffer,
               RRC_BUF_SIZE,0,0);
 
   if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-     xer_fprint(stdout,&asn_DEF_DL_DCCH_Message,(void*)dl_dcch_msg);
-  }
-
-#if defined(ENABLE_ITTI)
-# if defined(DISABLE_ITTI_XER_PRINT)
-  {
-    msg_p = itti_alloc_new_message (TASK_RRC_UE, RRC_DL_DCCH_MESSAGE);
-    memcpy (&msg_p->ittiMsg, (void *) dl_dcch_msg, sizeof(RrcDlDcchMessage));
-
-    itti_send_msg_to_task (TASK_UNKNOWN, ctxt_pP->instance, msg_p);
-  }
-# else
-  {
-    char        message_string[30000];
-    size_t      message_string_size;
-
-    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_DCCH_Message, (void *)dl_dcch_msg)) > 0) {
-      msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, RRC_DL_DCCH, message_string_size + sizeof (IttiMsgText));
-      msg_p->ittiMsg.rrc_dl_dcch.size = message_string_size;
-      memcpy(&msg_p->ittiMsg.rrc_dl_dcch.text, message_string, message_string_size);
-
-      itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
-    }
+    xer_fprint(stdout,&asn_DEF_LTE_DL_DCCH_Message,(void *)dl_dcch_msg);
   }
-# endif
-#endif
-
-  if (dl_dcch_msg->message.present == DL_DCCH_MessageType_PR_c1) {
 
+  if (dl_dcch_msg->message.present == LTE_DL_DCCH_MessageType_PR_c1) {
     if (UE_rrc_inst[ctxt_pP->module_id].Info[eNB_indexP].State >= RRC_CONNECTED) {
-
       switch (dl_dcch_msg->message.choice.c1.present) {
+        case LTE_DL_DCCH_MessageType__c1_PR_NOTHING:
+          LOG_I(RRC, "[UE %d] Frame %d : Received PR_NOTHING on DL-DCCH-Message\n",
+                ctxt_pP->module_id, ctxt_pP->frame);
+          return;
 
-      case DL_DCCH_MessageType__c1_PR_NOTHING:
-        LOG_I(RRC, "[UE %d] Frame %d : Received PR_NOTHING on DL-DCCH-Message\n",
-              ctxt_pP->module_id, ctxt_pP->frame);
-        return;
-
-      case DL_DCCH_MessageType__c1_PR_csfbParametersResponseCDMA2000:
-        break;
+        case LTE_DL_DCCH_MessageType__c1_PR_csfbParametersResponseCDMA2000:
+          break;
 
-      case DL_DCCH_MessageType__c1_PR_dlInformationTransfer: {
+        case LTE_DL_DCCH_MessageType__c1_PR_dlInformationTransfer: {
 #if defined(ENABLE_ITTI)
-        DLInformationTransfer_t *dlInformationTransfer = &dl_dcch_msg->message.choice.c1.choice.dlInformationTransfer;
-
-        if ((dlInformationTransfer->criticalExtensions.present == DLInformationTransfer__criticalExtensions_PR_c1)
-            && (dlInformationTransfer->criticalExtensions.choice.c1.present
-                == DLInformationTransfer__criticalExtensions__c1_PR_dlInformationTransfer_r8)
-            && (dlInformationTransfer->criticalExtensions.choice.c1.choice.dlInformationTransfer_r8.dedicatedInfoType.present
-                == DLInformationTransfer_r8_IEs__dedicatedInfoType_PR_dedicatedInfoNAS)) {
-          /* This message hold a dedicated info NAS payload, forward it to NAS */
-          struct DLInformationTransfer_r8_IEs__dedicatedInfoType *dedicatedInfoType =
+          LTE_DLInformationTransfer_t *dlInformationTransfer = &dl_dcch_msg->message.choice.c1.choice.dlInformationTransfer;
+
+          if ((dlInformationTransfer->criticalExtensions.present == LTE_DLInformationTransfer__criticalExtensions_PR_c1)
+              && (dlInformationTransfer->criticalExtensions.choice.c1.present
+                  == LTE_DLInformationTransfer__criticalExtensions__c1_PR_dlInformationTransfer_r8)
+              && (dlInformationTransfer->criticalExtensions.choice.c1.choice.dlInformationTransfer_r8.dedicatedInfoType.present
+                  == LTE_DLInformationTransfer_r8_IEs__dedicatedInfoType_PR_dedicatedInfoNAS)) {
+            /* This message hold a dedicated info NAS payload, forward it to NAS */
+            struct LTE_DLInformationTransfer_r8_IEs__dedicatedInfoType *dedicatedInfoType =
                 &dlInformationTransfer->criticalExtensions.choice.c1.choice.dlInformationTransfer_r8.dedicatedInfoType;
-          uint32_t pdu_length;
-          uint8_t *pdu_buffer;
-          MessageDef *msg_p;
-
-          pdu_length = dedicatedInfoType->choice.dedicatedInfoNAS.size;
-          pdu_buffer = dedicatedInfoType->choice.dedicatedInfoNAS.buf;
-
-          msg_p = itti_alloc_new_message(TASK_RRC_UE, NAS_DOWNLINK_DATA_IND);
-          NAS_DOWNLINK_DATA_IND(msg_p).UEid = ctxt_pP->module_id; // TODO set the UEid to something else ?
-          NAS_DOWNLINK_DATA_IND(msg_p).nasMsg.length = pdu_length;
-          NAS_DOWNLINK_DATA_IND(msg_p).nasMsg.data = pdu_buffer;
-
-          itti_send_msg_to_task(TASK_NAS_UE, ctxt_pP->instance, msg_p);
-        }
+            uint32_t pdu_length;
+            uint8_t *pdu_buffer;
+            MessageDef *msg_p;
+            pdu_length = dedicatedInfoType->choice.dedicatedInfoNAS.size;
+            pdu_buffer = dedicatedInfoType->choice.dedicatedInfoNAS.buf;
+            msg_p = itti_alloc_new_message(TASK_RRC_UE, NAS_DOWNLINK_DATA_IND);
+            NAS_DOWNLINK_DATA_IND(msg_p).UEid = ctxt_pP->module_id; // TODO set the UEid to something else ?
+            NAS_DOWNLINK_DATA_IND(msg_p).nasMsg.length = pdu_length;
+            NAS_DOWNLINK_DATA_IND(msg_p).nasMsg.data = pdu_buffer;
+            itti_send_msg_to_task(TASK_NAS_UE, ctxt_pP->instance, msg_p);
+          }
 
 #endif
-        break;
-      }
-
-      case DL_DCCH_MessageType__c1_PR_handoverFromEUTRAPreparationRequest:
-        break;
+          break;
+        }
 
-      case DL_DCCH_MessageType__c1_PR_mobilityFromEUTRACommand:
-        break;
+        case LTE_DL_DCCH_MessageType__c1_PR_handoverFromEUTRAPreparationRequest:
+          break;
 
-      case DL_DCCH_MessageType__c1_PR_rrcConnectionReconfiguration:
+        case LTE_DL_DCCH_MessageType__c1_PR_mobilityFromEUTRACommand:
+          break;
 
-        // first check if mobilityControlInfo  is present
-        if (dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.mobilityControlInfo
-            != NULL) {
-          /* 36.331, 5.3.5.4 Reception of an RRCConnectionReconfiguration including the mobilityControlInfo by the UE (handover)*/
-          if (UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.targetCellId
-              != dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.mobilityControlInfo->targetPhysCellId) {
-            LOG_W(RRC,
-                  "[UE %d] Frame %d: Handover target (%ld) is different from RSRP measured target (%ld)..\n",
-                  ctxt_pP->module_id,
-                  ctxt_pP->frame,
-                  dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.mobilityControlInfo->targetPhysCellId,
-                  UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.targetCellId);
-            return;
-          } else if ((target_eNB_index = get_adjacent_cell_mod_id(UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.targetCellId))
-                     == 0xFF) {
-            LOG_W(RRC,
-                  "[UE %d] Frame %d: ue_mod_idP of the target eNB not found, check the network topology\n",
-                  ctxt_pP->module_id,
-                  ctxt_pP->frame);
-            return;
-          } else {
-            LOG_I(RRC,
-                  "[UE% d] Frame %d: Received rrcConnectionReconfiguration with mobilityControlInfo \n",
-                  ctxt_pP->module_id,
-                  ctxt_pP->frame);
-            UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.measFlag = 1; // Ready to send more MeasReports if required
+        case LTE_DL_DCCH_MessageType__c1_PR_rrcConnectionReconfiguration:
+
+          // first check if mobilityControlInfo  is present
+          if (dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.mobilityControlInfo
+              != NULL) {
+            /* 36.331, 5.3.5.4 Reception of an RRCConnectionReconfiguration including the mobilityControlInfo by the UE (handover)*/
+            if (UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.targetCellId
+                != dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.mobilityControlInfo->targetPhysCellId) {
+              LOG_W(RRC,
+                    "[UE %d] Frame %d: Handover target (%ld) is different from RSRP measured target (%ld)..\n",
+                    ctxt_pP->module_id,
+                    ctxt_pP->frame,
+                    dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.mobilityControlInfo->targetPhysCellId,
+                    UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.targetCellId);
+              return;
+            } else if ((target_eNB_index = get_adjacent_cell_mod_id(UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.targetCellId))
+                       == 0xFF) {
+              LOG_W(RRC,
+                    "[UE %d] Frame %d: ue_mod_idP of the target eNB not found, check the network topology\n",
+                    ctxt_pP->module_id,
+                    ctxt_pP->frame);
+              return;
+            } else {
+              LOG_I(RRC,
+                    "[UE% d] Frame %d: Received rrcConnectionReconfiguration with mobilityControlInfo \n",
+                    ctxt_pP->module_id,
+                    ctxt_pP->frame);
+              UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.measFlag = 1; // Ready to send more MeasReports if required
+            }
           }
-        }
-
-        rrc_ue_process_rrcConnectionReconfiguration(
-          ctxt_pP,
-          &dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration,
-          eNB_indexP);
 
-        if (target_eNB_index != 0xFF) {
-          rrc_ue_generate_RRCConnectionReconfigurationComplete(
+          rrc_ue_process_rrcConnectionReconfiguration(
             ctxt_pP,
-            target_eNB_index,
-            dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.rrc_TransactionIdentifier);
-          UE_rrc_inst[ctxt_pP->module_id].Info[eNB_indexP].State = RRC_HO_EXECUTION;
-          UE_rrc_inst[ctxt_pP->module_id].Info[target_eNB_index].State = RRC_RECONFIGURED;
-          LOG_I(RRC, "[UE %d] State = RRC_RECONFIGURED during HO (eNB %d)\n",
-                ctxt_pP->module_id, target_eNB_index);
+            &dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration,
+            eNB_indexP);
+
+          if (target_eNB_index != 0xFF) {
+            rrc_ue_generate_RRCConnectionReconfigurationComplete(
+              ctxt_pP,
+              target_eNB_index,
+              dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.rrc_TransactionIdentifier);
+            UE_rrc_inst[ctxt_pP->module_id].Info[eNB_indexP].State = RRC_HO_EXECUTION;
+            UE_rrc_inst[ctxt_pP->module_id].Info[target_eNB_index].State = RRC_RECONFIGURED;
+            LOG_I(RRC, "[UE %d] State = RRC_RECONFIGURED during HO (eNB %d)\n",
+                  ctxt_pP->module_id, target_eNB_index);
 #if defined(ENABLE_ITTI)
 #if ENABLE_RAL
-          {
-            MessageDef                                 *message_ral_p = NULL;
-            rrc_ral_connection_reconfiguration_ho_ind_t connection_reconfiguration_ho_ind;
-            int                                         i;
-
-            message_ral_p = itti_alloc_new_message (TASK_RRC_UE, RRC_RAL_CONNECTION_RECONFIGURATION_HO_IND);
-            memset(&connection_reconfiguration_ho_ind, 0, sizeof(rrc_ral_connection_reconfiguration_ho_ind_t));
-            connection_reconfiguration_ho_ind.ue_id = ctxt_pP->module_id;
-
-            if (dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList
-                != NULL) {
-              connection_reconfiguration_ho_ind.num_drb      =
-                dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.count;
-
-              for (i=0; (
-                     i<dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.count)
-                   && (i < maxDRB); i++) {
-                // why minus 1 in RRC code for drb_identity ?
-                connection_reconfiguration_ho_ind.drb_id[i]   =
-                  dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.array[i]->drb_Identity;
+            {
+              MessageDef                                 *message_ral_p = NULL;
+              rrc_ral_connection_reconfiguration_ho_ind_t connection_reconfiguration_ho_ind;
+              int                                         i;
+              message_ral_p = itti_alloc_new_message (TASK_RRC_UE, RRC_RAL_CONNECTION_RECONFIGURATION_HO_IND);
+              memset(&connection_reconfiguration_ho_ind, 0, sizeof(rrc_ral_connection_reconfiguration_ho_ind_t));
+              connection_reconfiguration_ho_ind.ue_id = ctxt_pP->module_id;
+
+              if (dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList
+                  != NULL) {
+                connection_reconfiguration_ho_ind.num_drb      =
+                  dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.count;
+
+                for (i=0; (
+                       i<dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.count)
+                     && (i < maxDRB); i++) {
+                  // why minus 1 in RRC code for drb_identity ?
+                  connection_reconfiguration_ho_ind.drb_id[i]   =
+                    dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.array[i]->drb_Identity;
+                }
+              } else {
+                connection_reconfiguration_ho_ind.num_drb      = 0;
               }
-            } else {
-              connection_reconfiguration_ho_ind.num_drb      = 0;
-            }
 
-            if (dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->srb_ToAddModList
-                != NULL) {
-              connection_reconfiguration_ho_ind.num_srb      =
-                dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->srb_ToAddModList->list.count
-                +
-                UE_rrc_inst[ctxt_pP->module_id].num_srb;
-            } else {
-              connection_reconfiguration_ho_ind.num_srb      += UE_rrc_inst[ctxt_pP->module_id].num_srb;
-            }
+              if (dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->srb_ToAddModList
+                  != NULL) {
+                connection_reconfiguration_ho_ind.num_srb      =
+                  dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->srb_ToAddModList->list.count
+                  +
+                  UE_rrc_inst[ctxt_pP->module_id].num_srb;
+              } else {
+                connection_reconfiguration_ho_ind.num_srb      += UE_rrc_inst[ctxt_pP->module_id].num_srb;
+              }
 
-            if (connection_reconfiguration_ho_ind.num_srb > 2 ) {
-              connection_reconfiguration_ho_ind.num_srb =2;
-            }
+              if (connection_reconfiguration_ho_ind.num_srb > 2 ) {
+                connection_reconfiguration_ho_ind.num_srb =2;
+              }
 
-            memcpy (&message_ral_p->ittiMsg, (void *) &connection_reconfiguration_ho_ind, sizeof(rrc_ral_connection_reconfiguration_ho_ind_t));
-            //#warning "ue_mod_idP ? for instance ? => YES"
-            LOG_I(RRC, "Sending RRC_RAL_CONNECTION_RECONFIGURATION_HO_IND to mRAL\n");
-            itti_send_msg_to_task (TASK_RAL_UE, ctxt_pP->instance, message_ral_p);
-          }
+              memcpy (&message_ral_p->ittiMsg, (void *) &connection_reconfiguration_ho_ind, sizeof(rrc_ral_connection_reconfiguration_ho_ind_t));
+              //#warning "ue_mod_idP ? for instance ? => YES"
+              LOG_I(RRC, "Sending RRC_RAL_CONNECTION_RECONFIGURATION_HO_IND to mRAL\n");
+              itti_send_msg_to_task (TASK_RAL_UE, ctxt_pP->instance, message_ral_p);
+            }
 #endif
 #endif
-        } else {
-          rrc_ue_generate_RRCConnectionReconfigurationComplete(
-            ctxt_pP,
-            eNB_indexP,
-            dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.rrc_TransactionIdentifier);
-          UE_rrc_inst[ctxt_pP->module_id].Info[eNB_indexP].State = RRC_RECONFIGURED;
-          LOG_I(RRC, "[UE %d] State = RRC_RECONFIGURED (eNB %d)\n",
-                ctxt_pP->module_id,
-                eNB_indexP);
+          } else {
+            rrc_ue_generate_RRCConnectionReconfigurationComplete(
+              ctxt_pP,
+              eNB_indexP,
+              dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.rrc_TransactionIdentifier);
+            UE_rrc_inst[ctxt_pP->module_id].Info[eNB_indexP].State = RRC_RECONFIGURED;
+            LOG_I(RRC, "[UE %d] State = RRC_RECONFIGURED (eNB %d)\n",
+                  ctxt_pP->module_id,
+                  eNB_indexP);
 #if defined(ENABLE_ITTI)
 #if ENABLE_RAL
-          {
-            MessageDef                                 *message_ral_p = NULL;
-            rrc_ral_connection_reconfiguration_ind_t    connection_reconfiguration_ind;
-            int                                         i;
-
-            message_ral_p = itti_alloc_new_message (TASK_RRC_UE, RRC_RAL_CONNECTION_RECONFIGURATION_IND);
-            memset(&connection_reconfiguration_ind, 0, sizeof(rrc_ral_connection_reconfiguration_ind_t));
-            connection_reconfiguration_ind.ue_id = ctxt_pP->module_id;
-
-            if (dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList
-                != NULL) {
-              connection_reconfiguration_ind.num_drb      =
-                dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.count;
-
-              for (i=0; (
-                     i<dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.count)
-                   && (i < maxDRB); i++) {
-                // why minus 1 in RRC code for drb_identity ?
-                connection_reconfiguration_ind.drb_id[i]   =
-                  dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.array[i]->drb_Identity;
+            {
+              MessageDef                                 *message_ral_p = NULL;
+              rrc_ral_connection_reconfiguration_ind_t    connection_reconfiguration_ind;
+              int                                         i;
+              message_ral_p = itti_alloc_new_message (TASK_RRC_UE, RRC_RAL_CONNECTION_RECONFIGURATION_IND);
+              memset(&connection_reconfiguration_ind, 0, sizeof(rrc_ral_connection_reconfiguration_ind_t));
+              connection_reconfiguration_ind.ue_id = ctxt_pP->module_id;
+
+              if (dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList
+                  != NULL) {
+                connection_reconfiguration_ind.num_drb      =
+                  dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.count;
+
+                for (i=0; (
+                       i<dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.count)
+                     && (i < maxDRB); i++) {
+                  // why minus 1 in RRC code for drb_identity ?
+                  connection_reconfiguration_ind.drb_id[i]   =
+                    dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.array[i]->drb_Identity;
+                }
+              } else {
+                connection_reconfiguration_ind.num_drb      = 0;
               }
-            } else {
-              connection_reconfiguration_ind.num_drb      = 0;
-            }
 
-            if (dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->srb_ToAddModList
-                != NULL) {
-              connection_reconfiguration_ind.num_srb      =
-                dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->srb_ToAddModList->list.count
-                +
-                UE_rrc_inst[ctxt_pP->module_id].num_srb;
-            } else {
-              connection_reconfiguration_ind.num_srb      +=UE_rrc_inst[ctxt_pP->module_id].num_srb;
-            }
+              if (dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->srb_ToAddModList
+                  != NULL) {
+                connection_reconfiguration_ind.num_srb      =
+                  dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->srb_ToAddModList->list.count
+                  +
+                  UE_rrc_inst[ctxt_pP->module_id].num_srb;
+              } else {
+                connection_reconfiguration_ind.num_srb      +=UE_rrc_inst[ctxt_pP->module_id].num_srb;
+              }
 
-            if (connection_reconfiguration_ind.num_srb > 2 ) {
-              connection_reconfiguration_ind.num_srb =2;
-            }
+              if (connection_reconfiguration_ind.num_srb > 2 ) {
+                connection_reconfiguration_ind.num_srb =2;
+              }
 
-            memcpy (&message_ral_p->ittiMsg, (void *) &connection_reconfiguration_ind, sizeof(rrc_ral_connection_reconfiguration_ind_t));
-            //#warning "ue_mod_idP ? for instance ? => YES"
-            LOG_I(RRC, "Sending RRC_RAL_CONNECTION_RECONFIGURATION_IND to mRAL\n");
-            itti_send_msg_to_task (TASK_RAL_UE, ctxt_pP->instance, message_ral_p);
-          }
+              memcpy (&message_ral_p->ittiMsg, (void *) &connection_reconfiguration_ind, sizeof(rrc_ral_connection_reconfiguration_ind_t));
+              //#warning "ue_mod_idP ? for instance ? => YES"
+              LOG_I(RRC, "Sending RRC_RAL_CONNECTION_RECONFIGURATION_IND to mRAL\n");
+              itti_send_msg_to_task (TASK_RAL_UE, ctxt_pP->instance, message_ral_p);
+            }
 #endif
 #endif
+          }
 
-        }
+          //TTN test D2D (should not be here - in reality, this message will be triggered from ProSeApp)
+          if (send_ue_information == 0) {
+            LOG_I(RRC, "TEST SidelinkUEInformation [UE %d] Received  (eNB %d)\n",
+                  ctxt_pP->module_id, eNB_indexP);
+            LTE_SL_DestinationInfoList_r12_t *destinationInfoList = CALLOC(1, sizeof(LTE_SL_DestinationInfoList_r12_t));
+            LTE_SL_DestinationIdentity_r12_t *sl_destination_identity = CALLOC(1, sizeof(LTE_SL_DestinationIdentity_r12_t));
+            sl_destination_identity->size = 3;
+            sl_destination_identity->buf = CALLOC(1,3);
+            sl_destination_identity->buf[0] = 0x00;
+            sl_destination_identity->buf[1] = 0x00;
+            sl_destination_identity->buf[2] = 0x01;
+            sl_destination_identity->bits_unused = 0;
+            ASN_SEQUENCE_ADD(&destinationInfoList->list,sl_destination_identity);
+            rrc_ue_generate_SidelinkUEInformation(ctxt_pP, eNB_indexP, destinationInfoList, NULL, SL_TRANSMIT_NON_RELAY_ONE_TO_ONE);
+            send_ue_information ++;
+          }
 
-        //TTN test D2D (should not be here - in reality, this message will be triggered from ProSeApp)
-        if (send_ue_information == 0) {
-           LOG_I(RRC, "TEST SidelinkUEInformation [UE %d] Received  (eNB %d)\n",
-                 ctxt_pP->module_id, eNB_indexP);
-           SL_DestinationInfoList_r12_t *destinationInfoList = CALLOC(1, sizeof(SL_DestinationInfoList_r12_t));
-           SL_DestinationIdentity_r12_t *sl_destination_identity = CALLOC(1, sizeof(SL_DestinationIdentity_r12_t));
-           sl_destination_identity->size = 3;
-           sl_destination_identity->buf = CALLOC(1,3);
-           sl_destination_identity->buf[0] = 0x00;
-           sl_destination_identity->buf[1] = 0x00;
-           sl_destination_identity->buf[2] = 0x01;
-           sl_destination_identity->bits_unused = 0;
-           ASN_SEQUENCE_ADD(&destinationInfoList->list,sl_destination_identity);
-           rrc_ue_generate_SidelinkUEInformation(ctxt_pP, eNB_indexP, destinationInfoList, NULL, SL_TRANSMIT_NON_RELAY_ONE_TO_ONE);
-           send_ue_information ++;
-        }
-        break;
+          break;
 
-      case DL_DCCH_MessageType__c1_PR_rrcConnectionRelease:
+        case LTE_DL_DCCH_MessageType__c1_PR_rrcConnectionRelease:
 #if defined(ENABLE_ITTI)
-        msg_p = itti_alloc_new_message(TASK_RRC_UE, NAS_CONN_RELEASE_IND);
-
-        if ((dl_dcch_msg->message.choice.c1.choice.rrcConnectionRelease.criticalExtensions.present
-             == RRCConnectionRelease__criticalExtensions_PR_c1)
-            && (dl_dcch_msg->message.choice.c1.choice.rrcConnectionRelease.criticalExtensions.choice.c1.present
-                == RRCConnectionRelease__criticalExtensions__c1_PR_rrcConnectionRelease_r8)) {
-          NAS_CONN_RELEASE_IND(msg_p).cause =
-            dl_dcch_msg->message.choice.c1.choice.rrcConnectionRelease.criticalExtensions.choice.c1.choice.rrcConnectionRelease_r8.releaseCause;
-        }
+          msg_p = itti_alloc_new_message(TASK_RRC_UE, NAS_CONN_RELEASE_IND);
+
+          if ((dl_dcch_msg->message.choice.c1.choice.rrcConnectionRelease.criticalExtensions.present
+               == LTE_RRCConnectionRelease__criticalExtensions_PR_c1)
+              && (dl_dcch_msg->message.choice.c1.choice.rrcConnectionRelease.criticalExtensions.choice.c1.present
+                  == LTE_RRCConnectionRelease__criticalExtensions__c1_PR_rrcConnectionRelease_r8)) {
+            NAS_CONN_RELEASE_IND(msg_p).cause =
+              dl_dcch_msg->message.choice.c1.choice.rrcConnectionRelease.criticalExtensions.choice.c1.choice.rrcConnectionRelease_r8.releaseCause;
+          }
 
-        itti_send_msg_to_task(TASK_NAS_UE, ctxt_pP->instance, msg_p);
+          itti_send_msg_to_task(TASK_NAS_UE, ctxt_pP->instance, msg_p);
 #if ENABLE_RAL
-        msg_p = itti_alloc_new_message(TASK_RRC_UE, RRC_RAL_CONNECTION_RELEASE_IND);
-        RRC_RAL_CONNECTION_RELEASE_IND(msg_p).ue_id = ctxt_pP->module_id;
-        itti_send_msg_to_task(TASK_RAL_UE, ctxt_pP->instance, msg_p);
+          msg_p = itti_alloc_new_message(TASK_RRC_UE, RRC_RAL_CONNECTION_RELEASE_IND);
+          RRC_RAL_CONNECTION_RELEASE_IND(msg_p).ue_id = ctxt_pP->module_id;
+          itti_send_msg_to_task(TASK_RAL_UE, ctxt_pP->instance, msg_p);
 #endif
 #endif
-        break;
+          break;
 
-      case DL_DCCH_MessageType__c1_PR_securityModeCommand:
-        LOG_I(RRC, "[UE %d] Received securityModeCommand (eNB %d)\n",
-              ctxt_pP->module_id, eNB_indexP);
-        rrc_ue_process_securityModeCommand(
-          ctxt_pP,
-          &dl_dcch_msg->message.choice.c1.choice.securityModeCommand,
-          eNB_indexP);
-        break;
+        case LTE_DL_DCCH_MessageType__c1_PR_securityModeCommand:
+          LOG_I(RRC, "[UE %d] Received securityModeCommand (eNB %d)\n",
+                ctxt_pP->module_id, eNB_indexP);
+          rrc_ue_process_securityModeCommand(
+            ctxt_pP,
+            &dl_dcch_msg->message.choice.c1.choice.securityModeCommand,
+            eNB_indexP);
+          break;
 
-      case DL_DCCH_MessageType__c1_PR_ueCapabilityEnquiry:
-        LOG_I(RRC, "[UE %d] Received Capability Enquiry (eNB %d)\n",
-              ctxt_pP->module_id,
-              eNB_indexP);
-        rrc_ue_process_ueCapabilityEnquiry(
-          ctxt_pP,
-          &dl_dcch_msg->message.choice.c1.choice.ueCapabilityEnquiry,
-          eNB_indexP);
-        break;
+        case LTE_DL_DCCH_MessageType__c1_PR_ueCapabilityEnquiry:
+          LOG_I(RRC, "[UE %d] Received Capability Enquiry (eNB %d)\n",
+                ctxt_pP->module_id,
+                eNB_indexP);
+          rrc_ue_process_ueCapabilityEnquiry(
+            ctxt_pP,
+            &dl_dcch_msg->message.choice.c1.choice.ueCapabilityEnquiry,
+            eNB_indexP);
+          break;
 
-      case DL_DCCH_MessageType__c1_PR_counterCheck:
-        break;
+        case LTE_DL_DCCH_MessageType__c1_PR_counterCheck:
+          break;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
 
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-      case DL_DCCH_MessageType__c1_PR_ueInformationRequest_r9:
-        break;
+        case LTE_DL_DCCH_MessageType__c1_PR_ueInformationRequest_r9:
+          break;
 #endif
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-      case DL_DCCH_MessageType__c1_PR_loggedMeasurementConfiguration_r10:
-        break;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 
-      case DL_DCCH_MessageType__c1_PR_rnReconfiguration_r10:
-        break;
+        case LTE_DL_DCCH_MessageType__c1_PR_loggedMeasurementConfiguration_r10:
+          break;
+
+        case LTE_DL_DCCH_MessageType__c1_PR_rnReconfiguration_r10:
+          break;
 #endif
 
-      case DL_DCCH_MessageType__c1_PR_spare1:
-      case DL_DCCH_MessageType__c1_PR_spare2:
-      case DL_DCCH_MessageType__c1_PR_spare3:
-#if (RRC_VERSION < MAKE_VERSION(14, 0, 0))
-      case DL_DCCH_MessageType__c1_PR_spare4:
+        case LTE_DL_DCCH_MessageType__c1_PR_spare1:
+        case LTE_DL_DCCH_MessageType__c1_PR_spare2:
+        case LTE_DL_DCCH_MessageType__c1_PR_spare3:
+#if (LTE_RRC_VERSION < MAKE_VERSION(14, 0, 0))
+        case LTE_DL_DCCH_MessageType__c1_PR_spare4:
 #endif
-        break;
+          break;
 
-      default:
-        break;
+        default:
+          break;
       }
     }
   }
@@ -2756,8 +2450,7 @@ const char SIBType[12][6] = {"SIB3","SIB4","SIB5","SIB6","SIB7","SIB8","SIB9","S
 const char SIBPeriod[8][6]= {"rf8","rf16","rf32","rf64","rf128","rf256","rf512","ERR"};
 int siPeriod_int[7] = {80,160,320,640,1280,2560,5120};
 
-const char* SIBreserved( long value )
-{
+const char *SIBreserved( long value ) {
   if (value < 0 || value > 1)
     return "ERR";
 
@@ -2766,8 +2459,7 @@ const char* SIBreserved( long value )
 
   return "reserved";
 }
-const char* SIBbarred( long value )
-{
+const char *SIBbarred( long value ) {
   if (value < 0 || value > 1)
     return "ERR";
 
@@ -2776,8 +2468,7 @@ const char* SIBbarred( long value )
 
   return "barred";
 }
-const char* SIBallowed( long value )
-{
+const char *SIBallowed( long value ) {
   if (value < 0 || value > 1)
     return "ERR";
 
@@ -2786,23 +2477,21 @@ const char* SIBallowed( long value )
 
   return "allowed";
 }
-const char* SIB2SoundingPresent( int value )
-{
+const char *SIB2SoundingPresent( int value ) {
   switch (value) {
-  case SoundingRS_UL_ConfigCommon_PR_NOTHING:
-    return "NOTHING";
+    case LTE_SoundingRS_UL_ConfigCommon_PR_NOTHING:
+      return "NOTHING";
 
-  case SoundingRS_UL_ConfigCommon_PR_release:
-    return "release";
+    case LTE_SoundingRS_UL_ConfigCommon_PR_release:
+      return "release";
 
-  case SoundingRS_UL_ConfigCommon_PR_setup:
-    return "setup";
+    case LTE_SoundingRS_UL_ConfigCommon_PR_setup:
+      return "setup";
   }
 
   return "ERR";
 }
-const char* SIB2numberOfRA_Preambles( long value )
-{
+const char *SIB2numberOfRA_Preambles( long value ) {
   static char temp[4] = {0};
 
   if (value < 0 || value > 15)
@@ -2812,16 +2501,14 @@ const char* SIB2numberOfRA_Preambles( long value )
   temp[3] = 0; // terminate string
   return temp;
 }
-const char* SIB2powerRampingStep( long value )
-{
+const char *SIB2powerRampingStep( long value ) {
   if (value < 0 || value > 3)
     return "ERR";
 
   static const char str[4][4] = {"dB0","dB2","dB4","dB6"};
   return str[value];
 }
-const char* SIB2preambleInitialReceivedTargetPower( long value )
-{
+const char *SIB2preambleInitialReceivedTargetPower( long value ) {
   static char temp[8] = {0};
 
   if (value < 0 || value > 15)
@@ -2831,8 +2518,7 @@ const char* SIB2preambleInitialReceivedTargetPower( long value )
   temp[7] = 0; // terminate string
   return temp;
 }
-const char* SIB2preambleTransMax( long value )
-{
+const char *SIB2preambleTransMax( long value ) {
   static char temp[5] = {0};
 
   if (value < 0 || value > 10)
@@ -2844,27 +2530,26 @@ const char* SIB2preambleTransMax( long value )
   }
 
   switch (value) {
-  case 6:
-    return "n10";
+    case 6:
+      return "n10";
 
-  case 7:
-    return "n20";
+    case 7:
+      return "n20";
 
-  case 8:
-    return "n50";
+    case 8:
+      return "n50";
 
-  case 9:
-    return "n100";
+    case 9:
+      return "n100";
 
-  case 10:
-    return "n200";
+    case 10:
+      return "n200";
   }
 
   /* unreachable but gcc warns... */
   return "ERR";
 }
-const char* SIB2ra_ResponseWindowSize( long value )
-{
+const char *SIB2ra_ResponseWindowSize( long value ) {
   static char temp[4] = {0};
 
   if (value < 0 || value > 7)
@@ -2876,8 +2561,7 @@ const char* SIB2ra_ResponseWindowSize( long value )
   snprintf( temp, sizeof(temp), "sf%ld", value+2 );
   return temp;
 }
-const char* SIB2mac_ContentionResolutionTimer( long value )
-{
+const char *SIB2mac_ContentionResolutionTimer( long value ) {
   static char temp[5] = {0};
 
   if (value < 0 || value > 7)
@@ -2886,8 +2570,7 @@ const char* SIB2mac_ContentionResolutionTimer( long value )
   snprintf( temp, sizeof(temp), "sf%ld", 8 + value*8 );
   return temp;
 }
-const char* SIB2modificationPeriodCoeff( long value )
-{
+const char *SIB2modificationPeriodCoeff( long value ) {
   static char temp[32] = {0};
 
   if (value < 0 || value > 3)
@@ -2896,8 +2579,7 @@ const char* SIB2modificationPeriodCoeff( long value )
   snprintf( temp, sizeof(temp), "n%d", (int)pow(2,value+1) );
   return temp;
 }
-const char* SIB2defaultPagingCycle( long value )
-{
+const char *SIB2defaultPagingCycle( long value ) {
   static char temp[32] = {0};
 
   if (value < 0 || value > 3)
@@ -2906,8 +2588,7 @@ const char* SIB2defaultPagingCycle( long value )
   snprintf( temp, sizeof(temp), "rf%d", (int)pow(2,value+4) );
   return temp;
 }
-const char* SIB2nB( long value )
-{
+const char *SIB2nB( long value ) {
   if (value < 0 || value > 7)
     return "ERR";
 
@@ -2920,17 +2601,14 @@ const char* SIB2nB( long value )
 
 //-----------------------------------------------------------------------------
 int decode_BCCH_DLSCH_Message(
-  const protocol_ctxt_t* const ctxt_pP,
+  const protocol_ctxt_t *const ctxt_pP,
   const uint8_t                eNB_index,
-  uint8_t*               const Sdu,
+  uint8_t               *const Sdu,
   const uint8_t                Sdu_len,
   const uint8_t                rsrq,
-  const uint8_t                rsrp )
-{
-  BCCH_DL_SCH_Message_t *bcch_message = NULL;
-  SystemInformationBlockType1_t* sib1 = UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index];
-  int i;
-
+  const uint8_t                rsrp ) {
+  LTE_BCCH_DL_SCH_Message_t *bcch_message = NULL;
+  LTE_SystemInformationBlockType1_t *sib1 = UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index];
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_BCCH, VCD_FUNCTION_IN );
 
   if (((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&1) == 1) &&  // SIB1 received
@@ -2943,8 +2621,12 @@ int decode_BCCH_DLSCH_Message(
 
   rrc_set_sub_state( ctxt_pP->module_id, RRC_SUB_STATE_IDLE_RECEIVING_SIB );
 
+  if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
+    xer_fprint(stdout, &asn_DEF_LTE_BCCH_DL_SCH_Message,(void *)bcch_message );
+  }
+
   asn_dec_rval_t dec_rval = uper_decode_complete( NULL,
-                            &asn_DEF_BCCH_DL_SCH_Message,
+                            &asn_DEF_LTE_BCCH_DL_SCH_Message,
                             (void **)&bcch_message,
                             (const void *)Sdu,
                             Sdu_len );
@@ -2953,83 +2635,50 @@ int decode_BCCH_DLSCH_Message(
     LOG_E( RRC, "[UE %"PRIu8"] Failed to decode BCCH_DLSCH_MESSAGE (%zu bits)\n",
            ctxt_pP->module_id,
            dec_rval.consumed );
-    for (i=0;i<Sdu_len;i++)
-      printf("%02x ",Sdu[i]);
-    printf("\n");
+    log_dump(RRC, Sdu, Sdu_len, LOG_DUMP_CHAR,"   Received bytes:\n" );
     // free the memory
-    SEQUENCE_free( &asn_DEF_BCCH_DL_SCH_Message, (void*)bcch_message, 1 );
+    SEQUENCE_free( &asn_DEF_LTE_BCCH_DL_SCH_Message, (void *)bcch_message, 1 );
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_BCCH, VCD_FUNCTION_OUT );
     return -1;
   }
 
-#if defined(ENABLE_ITTI)
-# if defined(DISABLE_ITTI_XER_PRINT)
-  {
-    MessageDef *msg_p;
-
-    msg_p = itti_alloc_new_message (TASK_RRC_UE, RRC_DL_BCCH_MESSAGE);
-    memcpy (&msg_p->ittiMsg, (void *) bcch_message, sizeof(RrcDlBcchMessage));
-
-    itti_send_msg_to_task (TASK_UNKNOWN, ctxt_pP->instance, msg_p);
-  }
-# else
-  {
-    char        message_string[15000];
-    size_t      message_string_size;
-
-    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_BCCH_DL_SCH_Message, (void *)bcch_message)) > 0) {
-      MessageDef *msg_p;
-
-      msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, RRC_DL_BCCH, message_string_size + sizeof (IttiMsgText));
-      msg_p->ittiMsg.rrc_dl_bcch.size = message_string_size;
-      memcpy(&msg_p->ittiMsg.rrc_dl_bcch.text, message_string, message_string_size);
-
-      itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
-    }
-  }
-# endif
-#endif
-
-  if (bcch_message->message.present == BCCH_DL_SCH_MessageType_PR_c1) {
+  if (bcch_message->message.present == LTE_BCCH_DL_SCH_MessageType_PR_c1) {
     switch (bcch_message->message.choice.c1.present) {
-    case BCCH_DL_SCH_MessageType__c1_PR_systemInformationBlockType1:
-      if ((ctxt_pP->frame % 2) == 0) {
-        // even frame
-        if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&1) == 0) {
-          SystemInformationBlockType1_t* sib1 = UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index];
-          memcpy( (void*)sib1,
-                  (void*)&bcch_message->message.choice.c1.choice.systemInformationBlockType1,
-                  sizeof(SystemInformationBlockType1_t) );
-          LOG_D( RRC, "[UE %"PRIu8"] Decoding First SIB1\n", ctxt_pP->module_id );
-
-          decode_SIB1( ctxt_pP, eNB_index, rsrq, rsrp );
+      case LTE_BCCH_DL_SCH_MessageType__c1_PR_systemInformationBlockType1:
+        if ((ctxt_pP->frame % 2) == 0) {
+          // even frame
+          if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&1) == 0) {
+            LTE_SystemInformationBlockType1_t *sib1 = UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index];
+            memcpy( (void *)sib1,
+                    (void *)&bcch_message->message.choice.c1.choice.systemInformationBlockType1,
+                    sizeof(LTE_SystemInformationBlockType1_t) );
+            LOG_D( RRC, "[UE %"PRIu8"] Decoding First SIB1\n", ctxt_pP->module_id );
+            decode_SIB1( ctxt_pP, eNB_index, rsrq, rsrp );
+          }
         }
-      }
 
-      break;
+        break;
 
-    case BCCH_DL_SCH_MessageType__c1_PR_systemInformation:
-      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&1) == 1) {
-        // SIB1 with schedulingInfoList is available
-
-        SystemInformation_t* si = UE_rrc_inst[ctxt_pP->module_id].si[eNB_index];
-        memcpy( si,
-                &bcch_message->message.choice.c1.choice.systemInformation,
-                sizeof(SystemInformation_t) );
-
-        LOG_I( RRC, "[UE %"PRIu8"] Decoding SI for frameP %"PRIu32"\n",
-               ctxt_pP->module_id,
-               ctxt_pP->frame );
-        decode_SI( ctxt_pP, eNB_index );
-        //if (nfapi_mode == 3)
-        	UE_mac_inst[ctxt_pP->module_id].SI_Decoded = 1;
-      }
+      case LTE_BCCH_DL_SCH_MessageType__c1_PR_systemInformation:
+        if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&1) == 1) {
+          // SIB1 with schedulingInfoList is available
+          LTE_SystemInformation_t *si = UE_rrc_inst[ctxt_pP->module_id].si[eNB_index];
+          memcpy( si,
+                  &bcch_message->message.choice.c1.choice.systemInformation,
+                  sizeof(LTE_SystemInformation_t) );
+          LOG_I( RRC, "[UE %"PRIu8"] Decoding SI for frameP %"PRIu32"\n",
+                 ctxt_pP->module_id,
+                 ctxt_pP->frame );
+          decode_SI( ctxt_pP, eNB_index );
+          //if (nfapi_mode == 3)
+          UE_mac_inst[ctxt_pP->module_id].SI_Decoded = 1;
+        }
 
-      break;
+        break;
 
-    case BCCH_DL_SCH_MessageType__c1_PR_NOTHING:
-    default:
-      break;
+      case LTE_BCCH_DL_SCH_MessageType__c1_PR_NOTHING:
+      default:
+        break;
     }
   }
 
@@ -3043,24 +2692,20 @@ int decode_BCCH_DLSCH_Message(
   }
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_BCCH, VCD_FUNCTION_OUT );
-
   return 0;
 }
 
 //-----------------------------------------------------------------------------
 int decode_PCCH_DLSCH_Message(
-  const protocol_ctxt_t* const ctxt_pP,
+  const protocol_ctxt_t *const ctxt_pP,
   const uint8_t                eNB_index,
-  uint8_t*               const Sdu,
-  const uint8_t                Sdu_len)
-{
-  PCCH_Message_t *pcch_message = NULL;
+  uint8_t               *const Sdu,
+  const uint8_t                Sdu_len) {
+  LTE_PCCH_Message_t *pcch_message = NULL;
   int i;
-
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_PCCH, VCD_FUNCTION_IN );
-
   asn_dec_rval_t dec_rval = uper_decode_complete( NULL,
-                            &asn_DEF_PCCH_Message,
+                            &asn_DEF_LTE_PCCH_Message,
                             (void **)&pcch_message,
                             (const void *)Sdu,
                             Sdu_len );
@@ -3069,11 +2714,13 @@ int decode_PCCH_DLSCH_Message(
     LOG_E( RRC, "[UE %"PRIu8"] Failed to decode PCCH_MESSAGE (%zu bits)\n",
            ctxt_pP->module_id,
            dec_rval.consumed );
-    for (i=0;i<Sdu_len;i++)
+
+    for (i=0; i<Sdu_len; i++)
       printf("%02x ",Sdu[i]);
+
     printf("\n");
     // free the memory
-    SEQUENCE_free( &asn_DEF_PCCH_Message, (void*)pcch_message, 1 );
+    SEQUENCE_free( &asn_DEF_LTE_PCCH_Message, (void *)pcch_message, 1 );
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_PCCH, VCD_FUNCTION_OUT );
     return -1;
   }
@@ -3082,19 +2729,13 @@ int decode_PCCH_DLSCH_Message(
 }
 
 //-----------------------------------------------------------------------------
-int decode_SIB1( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index, const uint8_t rsrq, const uint8_t rsrp )
-{
-  SystemInformationBlockType1_t* sib1 = UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index];
-
+int decode_SIB1( const protocol_ctxt_t *const ctxt_pP, const uint8_t eNB_index, const uint8_t rsrq, const uint8_t rsrp ) {
+  LTE_SystemInformationBlockType1_t *sib1 = UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index];
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_UE_DECODE_SIB1, VCD_FUNCTION_IN );
-
   LOG_I( RRC, "[UE %d] : Dumping SIB 1\n", ctxt_pP->module_id );
-
-  PLMN_Identity_t *PLMN_identity = &sib1->cellAccessRelatedInfo.plmn_IdentityList.list.array[0]->plmn_Identity;
-
+  LTE_PLMN_Identity_t *PLMN_identity = &sib1->cellAccessRelatedInfo.plmn_IdentityList.list.array[0]->plmn_Identity;
   int mccdigits = PLMN_identity->mcc->list.count;
   int mncdigits = PLMN_identity->mnc.list.count;
-
   int mcc;
 
   if (mccdigits == 2) {
@@ -3111,10 +2752,10 @@ int decode_SIB1( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index,
     mnc = *PLMN_identity->mnc.list.array[0]*100 + *PLMN_identity->mnc.list.array[1]*10 + *PLMN_identity->mnc.list.array[2];
   }
 
-  LOG_I( RRC, "PLMN MCC %0*d, MNC %0*d, TAC 0x%04x\n", mccdigits, mcc, mncdigits, mnc, 
-       ((sib1->cellAccessRelatedInfo.trackingAreaCode.size == 2)?((sib1->cellAccessRelatedInfo.trackingAreaCode.buf[0]<<8) + sib1->cellAccessRelatedInfo.trackingAreaCode.buf[1]):0));
-  LOG_I( RRC, "cellReservedForOperatorUse                 : raw:%ld decoded:%s\n", sib1->cellAccessRelatedInfo.plmn_IdentityList.list.array[0]->cellReservedForOperatorUse, SIBreserved(sib1->cellAccessRelatedInfo.plmn_IdentityList.list.array[0]->cellReservedForOperatorUse) );
-
+  LOG_I( RRC, "PLMN MCC %0*d, MNC %0*d, TAC 0x%04x\n", mccdigits, mcc, mncdigits, mnc,
+         ((sib1->cellAccessRelatedInfo.trackingAreaCode.size == 2)?((sib1->cellAccessRelatedInfo.trackingAreaCode.buf[0]<<8) + sib1->cellAccessRelatedInfo.trackingAreaCode.buf[1]):0));
+  LOG_I( RRC, "cellReservedForOperatorUse                 : raw:%ld decoded:%s\n", sib1->cellAccessRelatedInfo.plmn_IdentityList.list.array[0]->cellReservedForOperatorUse,
+         SIBreserved(sib1->cellAccessRelatedInfo.plmn_IdentityList.list.array[0]->cellReservedForOperatorUse) );
   // search internal table for provider name
   int plmn_ind = 0;
 
@@ -3137,7 +2778,6 @@ int decode_SIB1( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index,
          sib1->cellAccessRelatedInfo.cellIdentity.buf[1],
          sib1->cellAccessRelatedInfo.cellIdentity.buf[2],
          sib1->cellAccessRelatedInfo.cellIdentity.buf[3] >> sib1->cellAccessRelatedInfo.cellIdentity.bits_unused);
-
   LOG_I( RRC, "cellAccessRelatedInfo.cellBarred           : raw:%ld decoded:%s\n", sib1->cellAccessRelatedInfo.cellBarred, SIBbarred(sib1->cellAccessRelatedInfo.cellBarred) );
   LOG_I( RRC, "cellAccessRelatedInfo.intraFreqReselection : raw:%ld decoded:%s\n", sib1->cellAccessRelatedInfo.intraFreqReselection, SIBallowed(sib1->cellAccessRelatedInfo.intraFreqReselection) );
   LOG_I( RRC, "cellAccessRelatedInfo.csg_Indication       : %d\n", sib1->cellAccessRelatedInfo.csg_Indication );
@@ -3189,70 +2829,63 @@ int decode_SIB1( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index,
 
   LOG_I( RRC, "siWindowLength                             : %s\n", siWindowLength[min(sib1->si_WindowLength,7)] );
   LOG_I( RRC, "systemInfoValueTag                         : %ld\n", sib1->systemInfoValueTag );
-
   UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIperiod     = siPeriod_int[sib1->schedulingInfoList.list.array[0]->si_Periodicity];
   UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIwindowsize = siWindowLength_int[sib1->si_WindowLength];
   LOG_I( RRC, "[FRAME unknown][RRC_UE][MOD %02"PRIu8"][][--- MAC_CONFIG_REQ (SIB1 params eNB %"PRIu8") --->][MAC_UE][MOD %02"PRIu8"][]\n",
          ctxt_pP->module_id, eNB_index, ctxt_pP->module_id );
-
   rrc_mac_config_req_ue(ctxt_pP->module_id, 0, eNB_index,
-			(RadioResourceConfigCommonSIB_t *)NULL,
-			(struct PhysicalConfigDedicated *)NULL,
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-			(SCellToAddMod_r10_t *)NULL,
-			//(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
-#endif
-			(MeasObjectToAddMod_t **)NULL,
-			(MAC_MainConfig_t *)NULL,
-			0,
-			(struct LogicalChannelConfig *)NULL,
-			(MeasGapConfig_t *)NULL,
-			UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index]->tdd_Config,
-			(MobilityControlInfo_t *) NULL,
-			&UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIwindowsize,
-			&UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIperiod,
-			NULL,
-			NULL,
-			NULL,
-			(MBSFN_SubframeConfigList_t *)NULL
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-			,0,
-			(MBSFN_AreaInfoList_r9_t *)NULL,
-			(PMCH_InfoList_r9_t *)NULL
-
+                        (LTE_RadioResourceConfigCommonSIB_t *)NULL,
+                        (struct LTE_PhysicalConfigDedicated *)NULL,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                        (LTE_SCellToAddMod_r10_t *)NULL,
+                        //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
+#endif
+                        (LTE_MeasObjectToAddMod_t **)NULL,
+                        (LTE_MAC_MainConfig_t *)NULL,
+                        0,
+                        (struct LTE_LogicalChannelConfig *)NULL,
+                        (LTE_MeasGapConfig_t *)NULL,
+                        UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index]->tdd_Config,
+                        (LTE_MobilityControlInfo_t *) NULL,
+                        &UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIwindowsize,
+                        &UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIperiod,
+                        NULL,
+                        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
 #ifdef CBA
-			,
-			0,
-			0
+                        ,
+                        0,
+                        0
 #endif
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-           ,
-           0,
-           NULL,
-           NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                        ,
+                        0,
+                        NULL,
+                        NULL
 #endif
-			);
-
+                       );
   LOG_I(RRC,"Setting SIStatus bit 0 to 1\n");
   UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus = 1;
   UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIB1systemInfoValueTag = sib1->systemInfoValueTag;
-
 #if defined(ENABLE_ITTI) && defined(ENABLE_USE_MME)
   {
     int cell_valid = 0;
 
-    if (sib1->cellAccessRelatedInfo.cellBarred == SystemInformationBlockType1__cellAccessRelatedInfo__cellBarred_notBarred) {
+    if (sib1->cellAccessRelatedInfo.cellBarred == LTE_SystemInformationBlockType1__cellAccessRelatedInfo__cellBarred_notBarred) {
       /* Cell is not barred */
       int plmn;
       int plmn_number;
-
       plmn_number = sib1->cellAccessRelatedInfo.plmn_IdentityList.list.count;
 
       /* Compare requested PLMN and PLMNs from SIB1*/
       for (plmn = 0; plmn < plmn_number; plmn++) {
-        PLMN_Identity_t *plmn_Identity;
-
+        LTE_PLMN_Identity_t *plmn_Identity;
         plmn_Identity = &sib1->cellAccessRelatedInfo.plmn_IdentityList.list.array[plmn]->plmn_Identity;
 
         if (
@@ -3278,7 +2911,6 @@ int decode_SIB1( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index,
         ) {
           /* PLMN match, send a confirmation to NAS */
           MessageDef  *msg_p;
-
           msg_p = itti_alloc_new_message(TASK_RRC_UE, NAS_CELL_SELECTION_CNF);
           NAS_CELL_SELECTION_CNF (msg_p).errCode = AS_SUCCESS;
           NAS_CELL_SELECTION_CNF (msg_p).cellID = BIT_STRING_to_uint32(&sib1->cellAccessRelatedInfo.cellIdentity);
@@ -3286,7 +2918,6 @@ int decode_SIB1( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index,
           NAS_CELL_SELECTION_CNF (msg_p).rat = 0xFF;
           NAS_CELL_SELECTION_CNF (msg_p).rsrq = rsrq;
           NAS_CELL_SELECTION_CNF (msg_p).rsrp = rsrp;
-
           itti_send_msg_to_task(TASK_NAS_UE, ctxt_pP->instance, msg_p);
           cell_valid = 1;
           break;
@@ -3297,23 +2928,19 @@ int decode_SIB1( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index,
     if (cell_valid == 0) {
       /* Cell can not be used, ask PHY to try the next one */
       MessageDef  *msg_p;
-
       msg_p = itti_alloc_new_message(TASK_RRC_UE, PHY_FIND_NEXT_CELL_REQ);
-
       itti_send_msg_to_task(TASK_PHY_UE, ctxt_pP->instance, msg_p);
+      LOG_E(RRC, "Synched with a cell, but PLMN doesn't match our SIM, the message PHY_FIND_NEXT_CELL_REQ is sent but lost in current UE implementation! \n");
     }
   }
 #endif
-
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_UE_DECODE_SIB1, VCD_FUNCTION_OUT );
-
   return 0;
 }
 
 
 //-----------------------------------------------------------------------------
- void dump_sib2( SystemInformationBlockType2_t *sib2 )
-{
+void dump_sib2( LTE_SystemInformationBlockType2_t *sib2 ) {
   // ac_BarringInfo
   if (sib2->ac_BarringInfo) {
     LOG_I( RRC, "ac_BarringInfo->ac_BarringForEmergency : %d\n",
@@ -3363,7 +2990,6 @@ int decode_SIB1( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index,
   LOG_I( RRC, "radioResourceConfigCommon.rach_ConfigCommon.powerRampingParameters.preambleInitialReceivedTargetPower : raw:%ld decoded:%s\n",
          sib2->radioResourceConfigCommon.rach_ConfigCommon.powerRampingParameters.preambleInitialReceivedTargetPower,
          SIB2preambleInitialReceivedTargetPower(sib2->radioResourceConfigCommon.rach_ConfigCommon.powerRampingParameters.preambleInitialReceivedTargetPower) );
-
   LOG_I( RRC, "radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.preambleTransMax              : raw:%ld decoded:%s\n",
          sib2->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.preambleTransMax,
          SIB2preambleTransMax(sib2->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.preambleTransMax) );
@@ -3373,15 +2999,12 @@ int decode_SIB1( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index,
   LOG_I( RRC, "radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.mac_ContentionResolutionTimer : raw:%ld decoded:%s\n",
          sib2->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.mac_ContentionResolutionTimer,
          SIB2mac_ContentionResolutionTimer(sib2->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.mac_ContentionResolutionTimer) );
-
   LOG_I( RRC, "radioResourceConfigCommon.rach_ConfigCommon.maxHARQ_Msg3Tx : %ld\n",
          sib2->radioResourceConfigCommon.rach_ConfigCommon.maxHARQ_Msg3Tx );
-
   // BCCH
   LOG_I( RRC, "radioResourceConfigCommon.bcch_Config.modificationPeriodCoeff : raw:%ld decoded:%s\n",
          sib2->radioResourceConfigCommon.bcch_Config.modificationPeriodCoeff,
          SIB2modificationPeriodCoeff(sib2->radioResourceConfigCommon.bcch_Config.modificationPeriodCoeff) );
-
   // PCCH
   LOG_I( RRC, "radioResourceConfigCommon.pcch_Config.defaultPagingCycle : raw:%ld decoded:%s\n",
          sib2->radioResourceConfigCommon.pcch_Config.defaultPagingCycle,
@@ -3389,7 +3012,6 @@ int decode_SIB1( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index,
   LOG_I( RRC, "radioResourceConfigCommon.pcch_Config.nB                 : raw:%ld decoded:%s\n",
          sib2->radioResourceConfigCommon.pcch_Config.nB,
          SIB2nB(sib2->radioResourceConfigCommon.pcch_Config.nB) );
-
   // PRACH
   LOG_I( RRC, "radioResourceConfigCommon.prach_Config.rootSequenceIndex                          : %ld\n",
          sib2->radioResourceConfigCommon.prach_Config.rootSequenceIndex );
@@ -3401,13 +3023,11 @@ int decode_SIB1( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index,
          sib2->radioResourceConfigCommon.prach_Config.prach_ConfigInfo.zeroCorrelationZoneConfig );
   LOG_I( RRC, "radioResourceConfigCommon.prach_Config.prach_ConfigInfo.prach_FreqOffset          : %ld\n",
          sib2->radioResourceConfigCommon.prach_Config.prach_ConfigInfo.prach_FreqOffset );
-
   // PDSCH-Config
   LOG_I( RRC, "radioResourceConfigCommon.pdsch_ConfigCommon.referenceSignalPower : %ld\n",
          sib2->radioResourceConfigCommon.pdsch_ConfigCommon.referenceSignalPower );
   LOG_I( RRC, "radioResourceConfigCommon.pdsch_ConfigCommon.p_b                  : %ld\n",
          sib2->radioResourceConfigCommon.pdsch_ConfigCommon.p_b );
-
   // PUSCH-Config
   LOG_I( RRC, "radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.n_SB                : %ld\n",
          sib2->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.n_SB );
@@ -3425,7 +3045,6 @@ int decode_SIB1( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index,
          sib2->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled );
   LOG_I( RRC, "radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.cyclicShift            : %ld\n",
          sib2->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.cyclicShift );
-
   // PUCCH-Config
   LOG_I( RRC, "radioResourceConfigCommon.pucch_ConfigCommon.deltaPUCCH_Shift : %ld\n",
          sib2->radioResourceConfigCommon.pucch_ConfigCommon.deltaPUCCH_Shift );
@@ -3435,13 +3054,12 @@ int decode_SIB1( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index,
          sib2->radioResourceConfigCommon.pucch_ConfigCommon.nCS_AN );
   LOG_I( RRC, "radioResourceConfigCommon.pucch_ConfigCommon.n1PUCCH_AN       : %ld\n",
          sib2->radioResourceConfigCommon.pucch_ConfigCommon.n1PUCCH_AN );
-
   // SoundingRS_UL_Config
   LOG_I( RRC, "radioResourceConfigCommon.soundingRS_UL_ConfigCommon.present : raw:%d decoded:%s\n",
          sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.present,
          SIB2SoundingPresent(sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.present) );
 
-  if (sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.present == SoundingRS_UL_ConfigCommon_PR_setup) {
+  if (sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.present == LTE_SoundingRS_UL_ConfigCommon_PR_setup) {
     LOG_I( RRC, "radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_BandwidthConfig                 : %ld\n",
            sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_BandwidthConfig );
     LOG_I( RRC, "radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_SubframeConfig                  : %ld\n",
@@ -3449,11 +3067,10 @@ int decode_SIB1( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index,
     LOG_I( RRC, "radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.ackNackSRS_SimultaneousTransmission : %d\n",
            sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.ackNackSRS_SimultaneousTransmission );
 
-    if(sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_MaxUpPts)
-    {
-    LOG_I( RRC, "radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_MaxUpPts                        : %ld\n",
-           /* TODO: check that it's okay to access [0] */
-           sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_MaxUpPts[0] );
+    if(sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_MaxUpPts) {
+      LOG_I( RRC, "radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_MaxUpPts                        : %ld\n",
+             /* TODO: check that it's okay to access [0] */
+             sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_MaxUpPts[0] );
     }
   }
 
@@ -3476,15 +3093,12 @@ int decode_SIB1( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index,
          sib2->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2b );
   LOG_I( RRC, "radioResourceConfigCommon.uplinkPowerControlCommon.deltaPreambleMsg3 : %ld\n",
          sib2->radioResourceConfigCommon.uplinkPowerControlCommon.deltaPreambleMsg3 );
-
   LOG_I( RRC, "radioResourceConfigCommon.ul_CyclicPrefixLength : %ld\n",
          sib2->radioResourceConfigCommon.ul_CyclicPrefixLength );
-
-#if (RRC_VERSION >= MAKE_VERSION(10, 2, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 2, 0))
   // UplinkPowerControlCommon_v1020
   // ...
 #endif
-
   LOG_I( RRC, "ue_TimersAndConstants.t300 : %ld\n", sib2->ue_TimersAndConstants.t300 );
   LOG_I( RRC, "ue_TimersAndConstants.t301 : %ld\n", sib2->ue_TimersAndConstants.t301 );
   LOG_I( RRC, "ue_TimersAndConstants.t310 : %ld\n", sib2->ue_TimersAndConstants.t310 );
@@ -3511,15 +3125,16 @@ int decode_SIB1( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index,
     LOG_I( RRC, "mbsfn_SubframeConfigList : not defined\n" );
 
   LOG_I( RRC, "timeAlignmentTimerCommon : %ld\n", sib2->timeAlignmentTimerCommon );
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
 
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
   if (sib2->lateNonCriticalExtension) {
     LOG_I( RRC, "lateNonCriticalExtension : %p\n", sib2->lateNonCriticalExtension );
   } else
     LOG_I( RRC, "lateNonCriticalExtension : not defined\n" );
+
 #endif
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
 
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
   if (sib2->ext1 && sib2->ext1->ssac_BarringForMMTEL_Voice_r9) {
     LOG_I( RRC, "ssac_BarringForMMTEL_Voice_r9->ac_BarringFactor       : %ld\n",
            sib2->ext1->ssac_BarringForMMTEL_Voice_r9->ac_BarringFactor );
@@ -3539,9 +3154,10 @@ int decode_SIB1( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index,
            BIT_STRING_to_uint32(&sib2->ext1->ssac_BarringForMMTEL_Video_r9->ac_BarringForSpecialAC) );
   } else
     LOG_I( RRC, "ssac_BarringForMMTEL_Video_r9 : not defined\n" );
+
 #endif
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
   if (sib2->ext2 && sib2->ext2->ac_BarringForCSFB_r10) {
     LOG_I( RRC, "ac_BarringForCSFB_r10->ac_BarringFactor       : %ld\n",
            sib2->ext2->ac_BarringForCSFB_r10->ac_BarringFactor );
@@ -3556,10 +3172,8 @@ int decode_SIB1( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index,
 }
 
 //-----------------------------------------------------------------------------
- void dump_sib3( SystemInformationBlockType3_t *sib3 )
-{
+void dump_sib3( LTE_SystemInformationBlockType3_t *sib3 ) {
   LOG_I( RRC, "Dumping SIB3 (see TS36.331 V8.21.0)\n" );
-
   int q_Hyst_dB = sib3->cellReselectionInfoCommon.q_Hyst; // sib3->cellReselectionInfoCommon.q_Hyst is a enumerated value
 
   if (q_Hyst_dB > 6)
@@ -3592,7 +3206,6 @@ int decode_SIB1( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index,
 
   LOG_I( RRC, "cellReselectionServingFreqInfo.threshServingLow : %ld\n", sib3->cellReselectionServingFreqInfo.threshServingLow );
   LOG_I( RRC, "cellReselectionServingFreqInfo.cellReselectionPriority : %ld\n", sib3->cellReselectionServingFreqInfo.cellReselectionPriority );
-
   LOG_I( RRC, "intraFreqCellReselectionInfo.q_RxLevMin : %ld\n", sib3->intraFreqCellReselectionInfo.q_RxLevMin );
 
   if (sib3->intraFreqCellReselectionInfo.p_Max) {
@@ -3629,7 +3242,6 @@ int Qoffsettab[31] = {-24,-22,-20,-18,-16,-14,-12,-10,-8,-6,-5,-4,-3,-2,-1,0,1,2
 int PhysCellIdRange[16] = {4,8,12,16,24,32,48,64,84,96,128,168,252,504,0,0};
 
 uint64_t arfcn_to_freq(long arfcn) {
-
   if (arfcn < 600)  // Band 1
     return((uint64_t)2110000000 + (arfcn*100000));
   else if (arfcn <1200) // Band 2
@@ -3703,86 +3315,102 @@ uint64_t arfcn_to_freq(long arfcn) {
     exit(1);
   }
 }
- void dump_sib5( SystemInformationBlockType5_t *sib5 )
-{
-  InterFreqCarrierFreqList_t interFreqCarrierFreqList = sib5->interFreqCarrierFreqList;
+void dump_sib5( LTE_SystemInformationBlockType5_t *sib5 ) {
+  LTE_InterFreqCarrierFreqList_t interFreqCarrierFreqList = sib5->interFreqCarrierFreqList;
   int i,j;
-  InterFreqCarrierFreqInfo_t *ifcfInfo;
-
+  LTE_InterFreqCarrierFreqInfo_t *ifcfInfo;
   LOG_I( RRC, "Dumping SIB5 (see TS36.331 V8.21.0)\n" );
 
-  for (i=0;i<interFreqCarrierFreqList.list.count;i++) {
+  for (i=0; i<interFreqCarrierFreqList.list.count; i++) {
     LOG_I(RRC, "SIB5 InterFreqCarrierFreq element %d/%d\n",i,interFreqCarrierFreqList.list.count);
     ifcfInfo = interFreqCarrierFreqList.list.array[i];
     LOG_I(RRC, "   DL Carrier Frequency/ARFCN : %ld/%ld\n",
-	  arfcn_to_freq(ifcfInfo->dl_CarrierFreq),
-	  ifcfInfo->dl_CarrierFreq);
+          arfcn_to_freq(ifcfInfo->dl_CarrierFreq),
+          ifcfInfo->dl_CarrierFreq);
     LOG_I(RRC,"   Q_RXLevMin : %ld\n", ifcfInfo->q_RxLevMin);
+
     if (ifcfInfo->p_Max != NULL)
       LOG_I(RRC,"   P_max : %ld\n", *ifcfInfo->p_Max);
+
     LOG_I(RRC,"   T_ReselectionEUTRA : %ld\n",ifcfInfo->t_ReselectionEUTRA);
+
     if (ifcfInfo->t_ReselectionEUTRA_SF) {
       LOG_I(RRC,"   t_ReselectionEUTRA_SF.sf_Medium %ld, t_ReselectionEUTRA_SF.sf_High %ld",
-	    ifcfInfo->t_ReselectionEUTRA_SF->sf_Medium,
-	    ifcfInfo->t_ReselectionEUTRA_SF->sf_High);
+            ifcfInfo->t_ReselectionEUTRA_SF->sf_Medium,
+            ifcfInfo->t_ReselectionEUTRA_SF->sf_High);
     }
+
     LOG_I(RRC,"   threshX_High : %ld\n",ifcfInfo->threshX_High);
     LOG_I(RRC,"   threshX_Low : %ld\n",ifcfInfo->threshX_Low);
+
     switch(ifcfInfo->allowedMeasBandwidth) {
-    case AllowedMeasBandwidth_mbw6:
-      LOG_I(RRC,"   AllowedMeasBandwidth : 6\n");
-      break;
-    case AllowedMeasBandwidth_mbw15:
-      LOG_I(RRC,"   AllowedMeasBandwidth : 15\n");
-      break;
-    case AllowedMeasBandwidth_mbw25:
-      LOG_I(RRC,"   AllowedMeasBandwidth : 25\n");
-      break;
-    case AllowedMeasBandwidth_mbw50:
-      LOG_I(RRC,"   AllowedMeasBandwidth : 50\n");
-      break;
-    case AllowedMeasBandwidth_mbw75:
-      LOG_I(RRC,"   AllowedMeasBandwidth : 75\n");
-      break;
-    case AllowedMeasBandwidth_mbw100:
-      LOG_I(RRC,"   AllowedMeasBandwidth : 100\n");
-      break;
+      case LTE_AllowedMeasBandwidth_mbw6:
+        LOG_I(RRC,"   AllowedMeasBandwidth : 6\n");
+        break;
+
+      case LTE_AllowedMeasBandwidth_mbw15:
+        LOG_I(RRC,"   AllowedMeasBandwidth : 15\n");
+        break;
+
+      case LTE_AllowedMeasBandwidth_mbw25:
+        LOG_I(RRC,"   AllowedMeasBandwidth : 25\n");
+        break;
+
+      case LTE_AllowedMeasBandwidth_mbw50:
+        LOG_I(RRC,"   AllowedMeasBandwidth : 50\n");
+        break;
+
+      case LTE_AllowedMeasBandwidth_mbw75:
+        LOG_I(RRC,"   AllowedMeasBandwidth : 75\n");
+        break;
+
+      case LTE_AllowedMeasBandwidth_mbw100:
+        LOG_I(RRC,"   AllowedMeasBandwidth : 100\n");
+        break;
     }
+
     if (ifcfInfo->presenceAntennaPort1)
       LOG_I(RRC,"   PresenceAntennaPort1 : True\n");
     else
       LOG_I(RRC,"   PresenceAntennaPort1 : False\n");
+
     if (ifcfInfo->cellReselectionPriority) {
       LOG_I(RRC,"   CellReselectionPriority : %ld\n",
-	    *ifcfInfo->cellReselectionPriority);
+            *ifcfInfo->cellReselectionPriority);
     }
+
     LOG_I(RRC,"   NeighCellConfig  : ");
-    for (j=0;j<ifcfInfo->neighCellConfig.size;j++) {
+
+    for (j=0; j<ifcfInfo->neighCellConfig.size; j++) {
       printf("%2x ",ifcfInfo->neighCellConfig.buf[j]);
     }
+
     printf("\n");
+
     if (ifcfInfo->q_OffsetFreq)
       LOG_I(RRC,"   Q_OffsetFreq : %d\n",Qoffsettab[*ifcfInfo->q_OffsetFreq]);
-    if (ifcfInfo->interFreqNeighCellList) {
-
-      for (j=0;j<ifcfInfo->interFreqNeighCellList->list.count;j++) {
-	LOG_I(RRC,"   Cell %d\n", j);
-	LOG_I(RRC,"      PhysCellId : %ld\n",ifcfInfo->interFreqNeighCellList->list.array[j]->physCellId);
-	LOG_I(RRC,"      Q_OffsetRange : %ld\n",ifcfInfo->interFreqNeighCellList->list.array[j]->q_OffsetCell);
 
+    if (ifcfInfo->interFreqNeighCellList) {
+      for (j=0; j<ifcfInfo->interFreqNeighCellList->list.count; j++) {
+        LOG_I(RRC,"   Cell %d\n", j);
+        LOG_I(RRC,"      PhysCellId : %ld\n",ifcfInfo->interFreqNeighCellList->list.array[j]->physCellId);
+        LOG_I(RRC,"      Q_OffsetRange : %ld\n",ifcfInfo->interFreqNeighCellList->list.array[j]->q_OffsetCell);
       }
     }
+
     if (ifcfInfo->interFreqBlackCellList) {
+      for (j=0; j<ifcfInfo->interFreqBlackCellList->list.count; j++) {
+        LOG_I(RRC,"   Cell %d\n", j);
+        LOG_I(RRC,"      PhysCellId start: %ld\n",ifcfInfo->interFreqBlackCellList->list.array[j]->start);
 
-      for (j=0;j<ifcfInfo->interFreqBlackCellList->list.count;j++) {
-	LOG_I(RRC,"   Cell %d\n", j);
-	LOG_I(RRC,"      PhysCellId start: %ld\n",ifcfInfo->interFreqBlackCellList->list.array[j]->start);
-	if (ifcfInfo->interFreqBlackCellList->list.array[i]->range) {
-	  LOG_I(RRC,"      PhysCellId Range : %ld\n",*ifcfInfo->interFreqBlackCellList->list.array[j]->range);
-	}
+        if (ifcfInfo->interFreqBlackCellList->list.array[i]->range) {
+          LOG_I(RRC,"      PhysCellId Range : %ld\n",*ifcfInfo->interFreqBlackCellList->list.array[j]->range);
+        }
       }
     }
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+
     if (ifcfInfo->ext1 && ifcfInfo->ext1->q_QualMin_r9)
       LOG_I(RRC,"   Q_QualMin_r9 : %ld\n",*ifcfInfo->ext1->q_QualMin_r9);
 
@@ -3790,14 +3418,13 @@ uint64_t arfcn_to_freq(long arfcn) {
       LOG_I(RRC,"   threshX_HighQ_r9 : %ld\n",ifcfInfo->ext1->threshX_Q_r9->threshX_HighQ_r9);
       LOG_I(RRC,"   threshX_LowQ_r9: %ld\n",ifcfInfo->ext1->threshX_Q_r9->threshX_LowQ_r9);
     }
+
 #endif
   }
-
 }
 
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
- void dump_sib13( SystemInformationBlockType13_r9_t *sib13 )
-{
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+void dump_sib13( LTE_SystemInformationBlockType13_r9_t *sib13 ) {
   LOG_I( RRC, "[UE] Dumping SIB13\n" );
   LOG_I( RRC, "[UE] dumping sib13 second time\n" );
   LOG_I( RRC, "[UE] NotificationRepetitionCoeff-r9 : %ld\n", sib13->notificationConfig_r9.notificationRepetitionCoeff_r9 );
@@ -3808,384 +3435,386 @@ uint64_t arfcn_to_freq(long arfcn) {
 
 //TTN - SIB18
 //-----------------------------------------------------------------------------
- void dump_sib18(SystemInformationBlockType18_r12_t *sib18){
-   LOG_I( RRC, "[UE] Dumping SIB18\n" );
-   for (int i = 0; i < sib18->commConfig_r12->commRxPool_r12.list.count; i++) {
-       LOG_I(RRC, " Contents of SIB18 %d/%d \n", i+1, sib18->commConfig_r12->commRxPool_r12.list.count);
-       LOG_I(RRC, " SIB18 rxPool_sc_CP_Len: %ld \n", sib18->commConfig_r12->commRxPool_r12.list.array[i]->sc_CP_Len_r12);
-       LOG_I(RRC, " SIB18 sc_Period_r12: %ld \n", sib18->commConfig_r12->commRxPool_r12.list.array[i]->sc_Period_r12);
-       LOG_I(RRC, " SIB18 data_CP_Len_r12: %ld \n", sib18->commConfig_r12->commRxPool_r12.list.array[i]->data_CP_Len_r12);
-       LOG_I(RRC, " SIB18 prb_Num_r12: %ld \n", sib18->commConfig_r12->commRxPool_r12.list.array[i]->sc_TF_ResourceConfig_r12.prb_Num_r12);
-       LOG_I(RRC, " SIB18 prb_Start_r12: %ld \n", sib18->commConfig_r12->commRxPool_r12.list.array[i]->sc_TF_ResourceConfig_r12.prb_Start_r12);
-       LOG_I(RRC, " SIB18 prb_End_r12: %ld \n", sib18->commConfig_r12->commRxPool_r12.list.array[i]->sc_TF_ResourceConfig_r12.prb_End_r12);
-       //to add more log
-     }
+void dump_sib18(LTE_SystemInformationBlockType18_r12_t *sib18) {
+  LOG_I( RRC, "[UE] Dumping SIB18\n" );
+
+  for (int i = 0; i < sib18->commConfig_r12->commRxPool_r12.list.count; i++) {
+    LOG_I(RRC, " Contents of SIB18 %d/%d \n", i+1, sib18->commConfig_r12->commRxPool_r12.list.count);
+    LOG_I(RRC, " SIB18 rxPool_sc_CP_Len: %ld \n", sib18->commConfig_r12->commRxPool_r12.list.array[i]->sc_CP_Len_r12);
+    LOG_I(RRC, " SIB18 sc_Period_r12: %ld \n", sib18->commConfig_r12->commRxPool_r12.list.array[i]->sc_Period_r12);
+    LOG_I(RRC, " SIB18 data_CP_Len_r12: %ld \n", sib18->commConfig_r12->commRxPool_r12.list.array[i]->data_CP_Len_r12);
+    LOG_I(RRC, " SIB18 prb_Num_r12: %ld \n", sib18->commConfig_r12->commRxPool_r12.list.array[i]->sc_TF_ResourceConfig_r12.prb_Num_r12);
+    LOG_I(RRC, " SIB18 prb_Start_r12: %ld \n", sib18->commConfig_r12->commRxPool_r12.list.array[i]->sc_TF_ResourceConfig_r12.prb_Start_r12);
+    LOG_I(RRC, " SIB18 prb_End_r12: %ld \n", sib18->commConfig_r12->commRxPool_r12.list.array[i]->sc_TF_ResourceConfig_r12.prb_End_r12);
+    //to add more log
+  }
 }
 
 //TTN -  SIB19
 //-----------------------------------------------------------------------------
- void dump_sib19(SystemInformationBlockType19_r12_t *sib19){
-   LOG_I( RRC, "[UE] Dumping SIB19\n" );
-   for (int i = 0; i < sib19->discConfig_r12->discRxPool_r12.list.count; i++) {
-       LOG_I(RRC, " Contents of SIB19 %d/%d \n", i+1, sib19->discConfig_r12->discRxPool_r12.list.count);
-       LOG_I(RRC, " SIB19 cp_Len_r12: %ld \n", sib19->discConfig_r12->discRxPool_r12.list.array[i]->cp_Len_r12);
-       LOG_I(RRC, " SIB19 discPeriod_r12: %ld \n", sib19->discConfig_r12->discRxPool_r12.list.array[i]->discPeriod_r12);
-       LOG_I(RRC, " SIB19 numRetx_r12: %ld \n", sib19->discConfig_r12->discRxPool_r12.list.array[i]->numRetx_r12);
-       LOG_I(RRC, " SIB19 numRepetition_r12: %ld \n", sib19->discConfig_r12->discRxPool_r12.list.array[i]->numRepetition_r12);
-       LOG_I(RRC, " SIB19 prb_Num_r12: %ld \n", sib19->discConfig_r12->discRxPool_r12.list.array[i]->tf_ResourceConfig_r12.prb_Num_r12);
-       LOG_I(RRC, " SIB19 prb_Start_r12: %ld \n", sib19->discConfig_r12->discRxPool_r12.list.array[i]->tf_ResourceConfig_r12.prb_Start_r12);
-       LOG_I(RRC, " SIB19 prb_End_r12: %ld \n", sib19->discConfig_r12->discRxPool_r12.list.array[i]->tf_ResourceConfig_r12.prb_End_r12);
-       //to add more log
-     }
+void dump_sib19(LTE_SystemInformationBlockType19_r12_t *sib19) {
+  LOG_I( RRC, "[UE] Dumping SIB19\n" );
+
+  for (int i = 0; i < sib19->discConfig_r12->discRxPool_r12.list.count; i++) {
+    LOG_I(RRC, " Contents of SIB19 %d/%d \n", i+1, sib19->discConfig_r12->discRxPool_r12.list.count);
+    LOG_I(RRC, " SIB19 cp_Len_r12: %ld \n", sib19->discConfig_r12->discRxPool_r12.list.array[i]->cp_Len_r12);
+    LOG_I(RRC, " SIB19 discPeriod_r12: %ld \n", sib19->discConfig_r12->discRxPool_r12.list.array[i]->discPeriod_r12);
+    LOG_I(RRC, " SIB19 numRetx_r12: %ld \n", sib19->discConfig_r12->discRxPool_r12.list.array[i]->numRetx_r12);
+    LOG_I(RRC, " SIB19 numRepetition_r12: %ld \n", sib19->discConfig_r12->discRxPool_r12.list.array[i]->numRepetition_r12);
+    LOG_I(RRC, " SIB19 prb_Num_r12: %ld \n", sib19->discConfig_r12->discRxPool_r12.list.array[i]->tf_ResourceConfig_r12.prb_Num_r12);
+    LOG_I(RRC, " SIB19 prb_Start_r12: %ld \n", sib19->discConfig_r12->discRxPool_r12.list.array[i]->tf_ResourceConfig_r12.prb_Start_r12);
+    LOG_I(RRC, " SIB19 prb_End_r12: %ld \n", sib19->discConfig_r12->discRxPool_r12.list.array[i]->tf_ResourceConfig_r12.prb_End_r12);
+    //to add more log
+  }
 }
 
- void dump_sib21(SystemInformationBlockType21_r14_t *sib21){
-    if ((sib21->sl_V2X_ConfigCommon_r14 != NULL) && (sib21->sl_V2X_ConfigCommon_r14->v2x_CommRxPool_r14 !=NULL) ){
-       for (int i = 0; i < sib21->sl_V2X_ConfigCommon_r14->v2x_CommRxPool_r14->list.count; i++) {
-          LOG_I(RRC, " Contents of SIB21 %d/%d \n", i+1, sib21->sl_V2X_ConfigCommon_r14->v2x_CommRxPool_r14->list.count);
-          LOG_I(RRC, " SIB21 sl_Subframe_r14: %d \n", sib21->sl_V2X_ConfigCommon_r14->v2x_CommRxPool_r14->list.array[i]->sl_Subframe_r14.present);
-          LOG_I(RRC, " SIB21 adjacencyPSCCH_PSSCH_r14: %d \n", sib21->sl_V2X_ConfigCommon_r14->v2x_CommRxPool_r14->list.array[i]->adjacencyPSCCH_PSSCH_r14);
-          LOG_I(RRC, " SIB21 sizeSubchannel_r14: %ld \n", sib21->sl_V2X_ConfigCommon_r14->v2x_CommRxPool_r14->list.array[i]->sizeSubchannel_r14);
-          LOG_I(RRC, " SIB21 numSubchannel_r14: %ld \n", sib21->sl_V2X_ConfigCommon_r14->v2x_CommRxPool_r14->list.array[i]->numSubchannel_r14);
-          LOG_I(RRC, " SIB21 startRB_Subchannel_r14: %ld \n", sib21->sl_V2X_ConfigCommon_r14->v2x_CommRxPool_r14->list.array[i]->startRB_Subchannel_r14);
-          //to add more log
-       }
+void dump_sib21(LTE_SystemInformationBlockType21_r14_t *sib21) {
+  if ((sib21->sl_V2X_ConfigCommon_r14 != NULL) && (sib21->sl_V2X_ConfigCommon_r14->v2x_CommRxPool_r14 !=NULL) ) {
+    for (int i = 0; i < sib21->sl_V2X_ConfigCommon_r14->v2x_CommRxPool_r14->list.count; i++) {
+      LOG_I(RRC, " Contents of SIB21 %d/%d \n", i+1, sib21->sl_V2X_ConfigCommon_r14->v2x_CommRxPool_r14->list.count);
+      LOG_I(RRC, " SIB21 sl_Subframe_r14: %d \n", sib21->sl_V2X_ConfigCommon_r14->v2x_CommRxPool_r14->list.array[i]->sl_Subframe_r14.present);
+      LOG_I(RRC, " SIB21 adjacencyPSCCH_PSSCH_r14: %d \n", sib21->sl_V2X_ConfigCommon_r14->v2x_CommRxPool_r14->list.array[i]->adjacencyPSCCH_PSSCH_r14);
+      LOG_I(RRC, " SIB21 sizeSubchannel_r14: %ld \n", sib21->sl_V2X_ConfigCommon_r14->v2x_CommRxPool_r14->list.array[i]->sizeSubchannel_r14);
+      LOG_I(RRC, " SIB21 numSubchannel_r14: %ld \n", sib21->sl_V2X_ConfigCommon_r14->v2x_CommRxPool_r14->list.array[i]->numSubchannel_r14);
+      LOG_I(RRC, " SIB21 startRB_Subchannel_r14: %ld \n", sib21->sl_V2X_ConfigCommon_r14->v2x_CommRxPool_r14->list.array[i]->startRB_Subchannel_r14);
+      //to add more log
     }
- }
+  }
+}
 
 
 #endif
 //-----------------------------------------------------------------------------
- int decode_SI( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index )
-{
-  SystemInformation_t** si = &UE_rrc_inst[ctxt_pP->module_id].si[eNB_index];
+int decode_SI( const protocol_ctxt_t *const ctxt_pP, const uint8_t eNB_index ) {
+  LTE_SystemInformation_t **si = &UE_rrc_inst[ctxt_pP->module_id].si[eNB_index];
   int new_sib = 0;
-  SystemInformationBlockType1_t* sib1 = UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index];
-
+  LTE_SystemInformationBlockType1_t *sib1 = UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index];
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_UE_DECODE_SI, VCD_FUNCTION_IN );
 
   // Dump contents
-  if ((*si)->criticalExtensions.present == SystemInformation__criticalExtensions_PR_systemInformation_r8 ||
-		  (*si)->criticalExtensions.present == SystemInformation__criticalExtensions_PR_criticalExtensionsFuture) {
+  if ((*si)->criticalExtensions.present == LTE_SystemInformation__criticalExtensions_PR_systemInformation_r8 ||
+#if (LTE_RRC_VERSION >= MAKE_VERSION(15, 3, 0))
+      (*si)->criticalExtensions.present == LTE_SystemInformation__criticalExtensions_PR_criticalExtensionsFuture_r15) {
+#else
+      (*si)->criticalExtensions.present == LTE_SystemInformation__criticalExtensions_PR_criticalExtensionsFuture) {
+#endif
     LOG_D( RRC, "[UE] (*si)->criticalExtensions.choice.systemInformation_r8.sib_TypeAndInfo.list.count %d\n",
            (*si)->criticalExtensions.choice.systemInformation_r8.sib_TypeAndInfo.list.count );
-  } else {
+  }
+  else {
     LOG_D( RRC, "[UE] Unknown criticalExtension version (not Rel8)\n" );
     return -1;
   }
 
   for (int i=0; i<(*si)->criticalExtensions.choice.systemInformation_r8.sib_TypeAndInfo.list.count; i++) {
-    struct SystemInformation_r8_IEs__sib_TypeAndInfo__Member *typeandinfo;
+    struct LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member *typeandinfo;
     typeandinfo = (*si)->criticalExtensions.choice.systemInformation_r8.sib_TypeAndInfo.list.array[i];
 
     switch(typeandinfo->present) {
-    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib2:
-      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&2) == 0) {
-	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=2;
-	new_sib=1;
-	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index], &typeandinfo->choice.sib2, sizeof(SystemInformationBlockType2_t) );
-	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB2 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
-	dump_sib2( UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index] );
-	LOG_I( RRC, "[FRAME %05"PRIu32"][RRC_UE][MOD %02"PRIu8"][][--- MAC_CONFIG_REQ (SIB2 params  eNB %"PRIu8") --->][MAC_UE][MOD %02"PRIu8"][]\n",
-	       ctxt_pP->frame, ctxt_pP->module_id, eNB_index, ctxt_pP->module_id );
-
-	rrc_mac_config_req_ue(ctxt_pP->module_id, 0, eNB_index,
-			      &UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index]->radioResourceConfigCommon,
-			      (struct PhysicalConfigDedicated *)NULL,
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-			      (SCellToAddMod_r10_t *)NULL,
-#endif
-			      (MeasObjectToAddMod_t **)NULL,
-			      (MAC_MainConfig_t *)NULL,
-			      0,
-			      (struct LogicalChannelConfig *)NULL,
-			      (MeasGapConfig_t *)NULL,
-			      (TDD_Config_t *)NULL,
-			      (MobilityControlInfo_t *)NULL,
-			      NULL,
-			      NULL,
-			      UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index]->freqInfo.ul_CarrierFreq,
-			      UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index]->freqInfo.ul_Bandwidth,
-			      &UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index]->freqInfo.additionalSpectrumEmission,
-			      UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index]->mbsfn_SubframeConfigList
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-			      ,0,
-			      (MBSFN_AreaInfoList_r9_t *)NULL,
-			      (PMCH_InfoList_r9_t *)NULL
-
+      case LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib2:
+        if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&2) == 0) {
+          UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=2;
+          new_sib=1;
+          memcpy( UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index], &typeandinfo->choice.sib2, sizeof(LTE_SystemInformationBlockType2_t) );
+          LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB2 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
+          dump_sib2( UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index] );
+          LOG_I( RRC, "[FRAME %05"PRIu32"][RRC_UE][MOD %02"PRIu8"][][--- MAC_CONFIG_REQ (SIB2 params  eNB %"PRIu8") --->][MAC_UE][MOD %02"PRIu8"][]\n",
+                 ctxt_pP->frame, ctxt_pP->module_id, eNB_index, ctxt_pP->module_id );
+          rrc_mac_config_req_ue(ctxt_pP->module_id, 0, eNB_index,
+                                &UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index]->radioResourceConfigCommon,
+                                (struct LTE_PhysicalConfigDedicated *)NULL,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                                (LTE_SCellToAddMod_r10_t *)NULL,
+#endif
+                                (LTE_MeasObjectToAddMod_t **)NULL,
+                                (LTE_MAC_MainConfig_t *)NULL,
+                                0,
+                                (struct LTE_LogicalChannelConfig *)NULL,
+                                (LTE_MeasGapConfig_t *)NULL,
+                                (LTE_TDD_Config_t *)NULL,
+                                (LTE_MobilityControlInfo_t *)NULL,
+                                NULL,
+                                NULL,
+                                UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index]->freqInfo.ul_CarrierFreq,
+                                UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index]->freqInfo.ul_Bandwidth,
+                                &UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index]->freqInfo.additionalSpectrumEmission,
+                                UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index]->mbsfn_SubframeConfigList
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+                                ,0,
+                                (LTE_MBSFN_AreaInfoList_r9_t *)NULL,
+                                (LTE_PMCH_InfoList_r9_t *)NULL
 #endif
 #ifdef CBA
-			      ,0,
-			      0
+                                ,0,
+                                0
 #endif
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-           ,
-           0,
-           NULL,
-           NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                                ,
+                                0,
+                                NULL,
+                                NULL
 #endif
-			      );
-	// After SI is received, prepare RRCConnectionRequest
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                               );
+          // After SI is received, prepare RRCConnectionRequest
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 
-	if (UE_rrc_inst[ctxt_pP->module_id].MBMS_flag < 3) // see -Q option
+          if (UE_rrc_inst[ctxt_pP->module_id].MBMS_flag < 3) // see -Q option
 #endif
 #if !(defined(ENABLE_ITTI) && defined(ENABLE_USE_MME))
-	  rrc_ue_generate_RRCConnectionRequest( ctxt_pP, eNB_index );
+            rrc_ue_generate_RRCConnectionRequest( ctxt_pP, eNB_index );
 
 #endif
 
-	if (UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].State == RRC_IDLE) {
-	  LOG_I( RRC, "[UE %d] Received SIB1/SIB2/SIB3 Switching to RRC_SI_RECEIVED\n", ctxt_pP->module_id );
-	  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].State = RRC_SI_RECEIVED;
+          if (UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].State == RRC_IDLE) {
+            LOG_I( RRC, "[UE %d] Received SIB1/SIB2/SIB3 Switching to RRC_SI_RECEIVED\n", ctxt_pP->module_id );
+            UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].State = RRC_SI_RECEIVED;
 #if ENABLE_RAL
-	  {
-	    MessageDef                            *message_ral_p = NULL;
-	    rrc_ral_system_information_ind_t       ral_si_ind;
-
-	    message_ral_p = itti_alloc_new_message (TASK_RRC_UE, RRC_RAL_SYSTEM_INFORMATION_IND);
-	    memset(&ral_si_ind, 0, sizeof(rrc_ral_system_information_ind_t));
-	    ral_si_ind.plmn_id.MCCdigit2 = '0';
-	    ral_si_ind.plmn_id.MCCdigit1 = '2';
-	    ral_si_ind.plmn_id.MNCdigit3 = '0';
-	    ral_si_ind.plmn_id.MCCdigit3 = '8';
-	    ral_si_ind.plmn_id.MNCdigit2 = '9';
-	    ral_si_ind.plmn_id.MNCdigit1 = '9';
-	    ral_si_ind.cell_id        = 1;
-	    ral_si_ind.dbm            = 0;
-	    //ral_si_ind.dbm            = fifo_dump_emos_UE.PHY_measurements->rx_rssi_dBm[eNB_index];
-	    // TO DO
-	    ral_si_ind.sinr           = 0;
-	    //ral_si_ind.sinr           = fifo_dump_emos_UE.PHY_measurements->subband_cqi_dB[eNB_index][phy_vars_ue->lte_frame_parms.nb_antennas_rx][0];
-	    // TO DO
-	    ral_si_ind.link_data_rate = 0;
-	    memcpy (&message_ral_p->ittiMsg, (void *) &ral_si_ind, sizeof(rrc_ral_system_information_ind_t));
+            {
+              MessageDef                            *message_ral_p = NULL;
+              rrc_ral_system_information_ind_t       ral_si_ind;
+              message_ral_p = itti_alloc_new_message (TASK_RRC_UE, RRC_RAL_SYSTEM_INFORMATION_IND);
+              memset(&ral_si_ind, 0, sizeof(rrc_ral_system_information_ind_t));
+              ral_si_ind.plmn_id.MCCdigit2 = '0';
+              ral_si_ind.plmn_id.MCCdigit1 = '2';
+              ral_si_ind.plmn_id.MNCdigit3 = '0';
+              ral_si_ind.plmn_id.MCCdigit3 = '8';
+              ral_si_ind.plmn_id.MNCdigit2 = '9';
+              ral_si_ind.plmn_id.MNCdigit1 = '9';
+              ral_si_ind.cell_id        = 1;
+              ral_si_ind.dbm            = 0;
+              //ral_si_ind.dbm            = fifo_dump_emos_UE.PHY_measurements->rx_rssi_dBm[eNB_index];
+              // TO DO
+              ral_si_ind.sinr           = 0;
+              //ral_si_ind.sinr           = fifo_dump_emos_UE.PHY_measurements->subband_cqi_dB[eNB_index][phy_vars_ue->lte_frame_parms.nb_antennas_rx][0];
+              // TO DO
+              ral_si_ind.link_data_rate = 0;
+              memcpy (&message_ral_p->ittiMsg, (void *) &ral_si_ind, sizeof(rrc_ral_system_information_ind_t));
 #warning "ue_mod_idP ? for instance ?"
-	    itti_send_msg_to_task (TASK_RAL_UE, UE_MODULE_ID_TO_INSTANCE(ctxt_pP->module_id), message_ral_p);
-	  }
+              itti_send_msg_to_task (TASK_RAL_UE, UE_MODULE_ID_TO_INSTANCE(ctxt_pP->module_id), message_ral_p);
+            }
 #endif
-	}
-      }
-      break; // case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib2
+          }
+        }
 
-    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib3:
-      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&4) == 0) {
-	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=4;
-	new_sib=1;
-	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib3[eNB_index], &typeandinfo->choice.sib3, sizeof(SystemInformationBlockType3_t) );
-	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB3 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
-	dump_sib3( UE_rrc_inst[ctxt_pP->module_id].sib3[eNB_index] );
+        break; // case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib2
 
-      }
-      break;
+      case LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib3:
+        if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&4) == 0) {
+          UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=4;
+          new_sib=1;
+          memcpy( UE_rrc_inst[ctxt_pP->module_id].sib3[eNB_index], &typeandinfo->choice.sib3, sizeof(LTE_SystemInformationBlockType3_t) );
+          LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB3 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
+          dump_sib3( UE_rrc_inst[ctxt_pP->module_id].sib3[eNB_index] );
+        }
 
-    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib4:
-      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&8) == 0) {
-	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=8;
-	new_sib=1;
-	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib4[eNB_index], &typeandinfo->choice.sib4, sizeof(SystemInformationBlockType4_t) );
-	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB4 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
-      }
+        break;
 
-      break;
+      case LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib4:
+        if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&8) == 0) {
+          UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=8;
+          new_sib=1;
+          memcpy( UE_rrc_inst[ctxt_pP->module_id].sib4[eNB_index], &typeandinfo->choice.sib4, sizeof(LTE_SystemInformationBlockType4_t) );
+          LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB4 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
+        }
 
-    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib5:
-      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&16) == 0) {
-	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=16;
-	new_sib=1;
+        break;
 
-	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib5[eNB_index], &typeandinfo->choice.sib5, sizeof(SystemInformationBlockType5_t) );
-	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB5 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
-	dump_sib5(UE_rrc_inst[ctxt_pP->module_id].sib5[eNB_index]);
-      }
-      break;
+      case LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib5:
+        if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&16) == 0) {
+          UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=16;
+          new_sib=1;
+          memcpy( UE_rrc_inst[ctxt_pP->module_id].sib5[eNB_index], &typeandinfo->choice.sib5, sizeof(LTE_SystemInformationBlockType5_t) );
+          LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB5 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
+          dump_sib5(UE_rrc_inst[ctxt_pP->module_id].sib5[eNB_index]);
+        }
 
-    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib6:
-      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&32) == 0) {
-	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=32;
-	new_sib=1;
+        break;
 
-	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib6[eNB_index], &typeandinfo->choice.sib6, sizeof(SystemInformationBlockType6_t) );
-	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB6 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
-      }
-      break;
+      case LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib6:
+        if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&32) == 0) {
+          UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=32;
+          new_sib=1;
+          memcpy( UE_rrc_inst[ctxt_pP->module_id].sib6[eNB_index], &typeandinfo->choice.sib6, sizeof(LTE_SystemInformationBlockType6_t) );
+          LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB6 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
+        }
 
-    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib7:
-      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&64) == 0) {
-	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=64;
-	new_sib=1;
-	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib7[eNB_index], &typeandinfo->choice.sib7, sizeof(SystemInformationBlockType7_t) );
-	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB7 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
-      }
-      break;
+        break;
 
-    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib8:
-      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&128) == 0) {
-	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=128;
-	new_sib=1;
-	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib8[eNB_index], &typeandinfo->choice.sib8, sizeof(SystemInformationBlockType8_t) );
-	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB8 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
-      }
-      break;
+      case LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib7:
+        if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&64) == 0) {
+          UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=64;
+          new_sib=1;
+          memcpy( UE_rrc_inst[ctxt_pP->module_id].sib7[eNB_index], &typeandinfo->choice.sib7, sizeof(LTE_SystemInformationBlockType7_t) );
+          LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB7 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
+        }
 
-    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib9:
-      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&256) == 0) {
-	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=256;
-	new_sib=1;
+        break;
 
-	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib9[eNB_index], &typeandinfo->choice.sib9, sizeof(SystemInformationBlockType9_t) );
-	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB9 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
-      }
-      break;
+      case LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib8:
+        if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&128) == 0) {
+          UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=128;
+          new_sib=1;
+          memcpy( UE_rrc_inst[ctxt_pP->module_id].sib8[eNB_index], &typeandinfo->choice.sib8, sizeof(LTE_SystemInformationBlockType8_t) );
+          LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB8 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
+        }
 
-    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib10:
-      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&512) == 0) {
-	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=512;
-	new_sib=1;
-	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib10[eNB_index], &typeandinfo->choice.sib10, sizeof(SystemInformationBlockType10_t) );
-	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB10 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
-      }
-      break;
+        break;
 
-    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib11:
-      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&1024) == 0) {
-	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=1024;
-	new_sib=1;
+      case LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib9:
+        if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&256) == 0) {
+          UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=256;
+          new_sib=1;
+          memcpy( UE_rrc_inst[ctxt_pP->module_id].sib9[eNB_index], &typeandinfo->choice.sib9, sizeof(LTE_SystemInformationBlockType9_t) );
+          LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB9 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
+        }
 
-	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib11[eNB_index], &typeandinfo->choice.sib11, sizeof(SystemInformationBlockType11_t) );
-	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB11 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
-      }
-      break;
+        break;
+
+      case LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib10:
+        if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&512) == 0) {
+          UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=512;
+          new_sib=1;
+          memcpy( UE_rrc_inst[ctxt_pP->module_id].sib10[eNB_index], &typeandinfo->choice.sib10, sizeof(LTE_SystemInformationBlockType10_t) );
+          LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB10 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
+        }
 
-#if (RRC_VERSION >= MAKE_VERSION(9, 2, 0))
+        break;
 
-    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib12_v920:
-      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&2048) == 0) {
-	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=2048;
-	new_sib=1;
-	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib12[eNB_index], &typeandinfo->choice.sib12_v920, sizeof(SystemInformationBlockType12_r9_t) );
-	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB12 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
-      }
-      break;
+      case LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib11:
+        if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&1024) == 0) {
+          UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=1024;
+          new_sib=1;
+          memcpy( UE_rrc_inst[ctxt_pP->module_id].sib11[eNB_index], &typeandinfo->choice.sib11, sizeof(LTE_SystemInformationBlockType11_t) );
+          LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB11 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
+        }
+
+        break;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 2, 0))
+
+      case LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib12_v920:
+        if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&2048) == 0) {
+          UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=2048;
+          new_sib=1;
+          memcpy( UE_rrc_inst[ctxt_pP->module_id].sib12[eNB_index], &typeandinfo->choice.sib12_v920, sizeof(LTE_SystemInformationBlockType12_r9_t) );
+          LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB12 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
+        }
+
+        break;
 
-    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib13_v920:
-      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&4096) == 0) {
-	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=4096;
-	new_sib=1;
-
-	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib13[eNB_index], &typeandinfo->choice.sib13_v920, sizeof(SystemInformationBlockType13_r9_t) );
-	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB13 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
-	dump_sib13( UE_rrc_inst[ctxt_pP->module_id].sib13[eNB_index] );
-	// adding here function to store necessary parameters for using in decode_MCCH_Message + maybe transfer to PHY layer
-	LOG_I( RRC, "[FRAME %05"PRIu32"][RRC_UE][MOD %02"PRIu8"][][--- MAC_CONFIG_REQ (SIB13 params eNB %"PRIu8") --->][MAC_UE][MOD %02"PRIu8"][]\n",
-	       ctxt_pP->frame, ctxt_pP->module_id, eNB_index, ctxt_pP->module_id);
-	rrc_mac_config_req_ue(ctxt_pP->module_id,0,eNB_index,
-			      (RadioResourceConfigCommonSIB_t *)NULL,
-			      (struct PhysicalConfigDedicated *)NULL,
-			      (SCellToAddMod_r10_t *)NULL,
-			      (MeasObjectToAddMod_t **)NULL,
-			      (MAC_MainConfig_t *)NULL,
-			      0,
-			      (struct LogicalChannelConfig *)NULL,
-			      (MeasGapConfig_t *)NULL,
-			      (TDD_Config_t *)NULL,
-			      (MobilityControlInfo_t *)NULL,
-			      NULL,
-			      NULL,
-			      NULL,
-			      NULL,
-			      NULL,
-			      (MBSFN_SubframeConfigList_t *)NULL,
-			      0,
-			      &UE_rrc_inst[ctxt_pP->module_id].sib13[eNB_index]->mbsfn_AreaInfoList_r9,
-			      (PMCH_InfoList_r9_t *)NULL
+      case LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib13_v920:
+        if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&4096) == 0) {
+          UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=4096;
+          new_sib=1;
+          memcpy( UE_rrc_inst[ctxt_pP->module_id].sib13[eNB_index], &typeandinfo->choice.sib13_v920, sizeof(LTE_SystemInformationBlockType13_r9_t) );
+          LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB13 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
+          dump_sib13( UE_rrc_inst[ctxt_pP->module_id].sib13[eNB_index] );
+          // adding here function to store necessary parameters for using in decode_MCCH_Message + maybe transfer to PHY layer
+          LOG_I( RRC, "[FRAME %05"PRIu32"][RRC_UE][MOD %02"PRIu8"][][--- MAC_CONFIG_REQ (SIB13 params eNB %"PRIu8") --->][MAC_UE][MOD %02"PRIu8"][]\n",
+                 ctxt_pP->frame, ctxt_pP->module_id, eNB_index, ctxt_pP->module_id);
+          rrc_mac_config_req_ue(ctxt_pP->module_id,0,eNB_index,
+                                (LTE_RadioResourceConfigCommonSIB_t *)NULL,
+                                (struct LTE_PhysicalConfigDedicated *)NULL,
+                                (LTE_SCellToAddMod_r10_t *)NULL,
+                                (LTE_MeasObjectToAddMod_t **)NULL,
+                                (LTE_MAC_MainConfig_t *)NULL,
+                                0,
+                                (struct LTE_LogicalChannelConfig *)NULL,
+                                (LTE_MeasGapConfig_t *)NULL,
+                                (LTE_TDD_Config_t *)NULL,
+                                (LTE_MobilityControlInfo_t *)NULL,
+                                NULL,
+                                NULL,
+                                NULL,
+                                NULL,
+                                NULL,
+                                (LTE_MBSFN_SubframeConfigList_t *)NULL,
+                                0,
+                                &UE_rrc_inst[ctxt_pP->module_id].sib13[eNB_index]->mbsfn_AreaInfoList_r9,
+                                (LTE_PMCH_InfoList_r9_t *)NULL
 #ifdef CBA
-			      ,0,
-			      0
+                                ,0,
+                                0
 #endif
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-           ,
-           0,
-           NULL,
-           NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                                ,
+                                0,
+                                NULL,
+                                NULL
 #endif
-			      );
-	break;
-      }
+                               );
+          break;
+        }
+
 #endif
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
       //SIB18
-    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib18_v1250:
-       if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&8192) == 0) {
+      case LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib18_v1250:
+        if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&8192) == 0) {
           UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=8192;
           new_sib=1;
-
-          memcpy( UE_rrc_inst[ctxt_pP->module_id].sib18[eNB_index], &typeandinfo->choice.sib18_v1250, sizeof(SystemInformationBlockType18_r12_t) );
+          memcpy( UE_rrc_inst[ctxt_pP->module_id].sib18[eNB_index], &typeandinfo->choice.sib18_v1250, sizeof(LTE_SystemInformationBlockType18_r12_t) );
           LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB18 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
           dump_sib18( UE_rrc_inst[ctxt_pP->module_id].sib18[eNB_index] );
           // adding here function to store necessary parameters to transfer to PHY layer
           LOG_I( RRC, "[FRAME %05"PRIu32"][RRC_UE][MOD %02"PRIu8"][][--- MAC_CONFIG_REQ (SIB18 params eNB %"PRIu8") --->][MAC_UE][MOD %02"PRIu8"][]\n",
-                ctxt_pP->frame, ctxt_pP->module_id, eNB_index, ctxt_pP->module_id);
-
+                 ctxt_pP->frame, ctxt_pP->module_id, eNB_index, ctxt_pP->module_id);
           //process SIB18 to transfer SL-related parameters to PHY
           rrc_ue_process_sidelink_radioResourceConfig(ctxt_pP->module_id,eNB_index,
-                UE_rrc_inst[ctxt_pP->module_id].sib18[eNB_index],
-                (SystemInformationBlockType19_r12_t *)NULL,
-                (SL_CommConfig_r12_t *)NULL,
-                (SL_DiscConfig_r12_t *)NULL
-          );
+              UE_rrc_inst[ctxt_pP->module_id].sib18[eNB_index],
+              (LTE_SystemInformationBlockType19_r12_t *)NULL,
+              (LTE_SL_CommConfig_r12_t *)NULL,
+              (LTE_SL_DiscConfig_r12_t *)NULL
+                                                     );
+        }
 
-       }
-       break;
+        break;
 
-       //SIB19
-    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib19_v1250:
-       if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&16384) == 0) {
+      //SIB19
+      case LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib19_v1250:
+        if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&16384) == 0) {
           UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=16384;
           new_sib=1;
-
-          memcpy( UE_rrc_inst[ctxt_pP->module_id].sib19[eNB_index], &typeandinfo->choice.sib19_v1250, sizeof(SystemInformationBlockType19_r12_t) );
+          memcpy( UE_rrc_inst[ctxt_pP->module_id].sib19[eNB_index], &typeandinfo->choice.sib19_v1250, sizeof(LTE_SystemInformationBlockType19_r12_t) );
           LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB19 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
           dump_sib19( UE_rrc_inst[ctxt_pP->module_id].sib19[eNB_index] );
           // adding here function to store necessary parameters to transfer to PHY layer
           LOG_I( RRC, "[FRAME %05"PRIu32"][RRC_UE][MOD %02"PRIu8"][][--- MAC_CONFIG_REQ (SIB19 params eNB %"PRIu8") --->][MAC_UE][MOD %02"PRIu8"][]\n",
-                ctxt_pP->frame, ctxt_pP->module_id, eNB_index, ctxt_pP->module_id);
+                 ctxt_pP->frame, ctxt_pP->module_id, eNB_index, ctxt_pP->module_id);
           //process SIB19 to transfer SL-related parameters to PHY
           rrc_ue_process_sidelink_radioResourceConfig(ctxt_pP->module_id,eNB_index,
-                (SystemInformationBlockType18_r12_t *)NULL,
-                UE_rrc_inst[ctxt_pP->module_id].sib19[eNB_index],
-                (SL_CommConfig_r12_t *)NULL,
-                (SL_DiscConfig_r12_t *)NULL
-          );
+              (LTE_SystemInformationBlockType18_r12_t *)NULL,
+              UE_rrc_inst[ctxt_pP->module_id].sib19[eNB_index],
+              (LTE_SL_CommConfig_r12_t *)NULL,
+              (LTE_SL_DiscConfig_r12_t *)NULL
+                                                     );
+        }
 
-       }
-       break;
+        break;
 
-       //SIB21
-    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib21_v1430:
-       if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&32768) == 0) {
+      //SIB21
+      case LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib21_v1430:
+        if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&32768) == 0) {
           UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=32768;
           new_sib=1;
-
-          memcpy( UE_rrc_inst[ctxt_pP->module_id].sib21[eNB_index], &typeandinfo->choice.sib21_v1430, sizeof(SystemInformationBlockType21_r14_t) );
+          memcpy( UE_rrc_inst[ctxt_pP->module_id].sib21[eNB_index], &typeandinfo->choice.sib21_v1430, sizeof(LTE_SystemInformationBlockType21_r14_t) );
           LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB21 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
           dump_sib21( UE_rrc_inst[ctxt_pP->module_id].sib21[eNB_index] );
           // adding here function to store necessary parameters to transfer to PHY layer
           LOG_I( RRC, "[FRAME %05"PRIu32"][RRC_UE][MOD %02"PRIu8"][][--- MAC_CONFIG_REQ (SIB21 params eNB %"PRIu8") --->][MAC_UE][MOD %02"PRIu8"][]\n",
-                ctxt_pP->frame, ctxt_pP->module_id, eNB_index, ctxt_pP->module_id);
+                 ctxt_pP->frame, ctxt_pP->module_id, eNB_index, ctxt_pP->module_id);
           //process SIB21
           //TODO
-       }
-       break;
-
+        }
 
+        break;
 #endif
-    default:
-      break;
-    }
 
+      default:
+        break;
+    }
   }
+
   if (new_sib == 1) {
     UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIcnt++;
 
@@ -4193,9 +3822,9 @@ uint64_t arfcn_to_freq(long arfcn) {
       rrc_set_sub_state( ctxt_pP->module_id, RRC_SUB_STATE_IDLE_SIB_COMPLETE );
 
     LOG_I(RRC,"SIStatus %x, SIcnt %d/%d\n",
-	  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus,
-	  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIcnt,
-	  sib1->schedulingInfoList.list.count);
+          UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus,
+          UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIcnt,
+          sib1->schedulingInfoList.list.count);
   }
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_UE_DECODE_SI  , VCD_FUNCTION_OUT);
@@ -4204,8 +3833,7 @@ uint64_t arfcn_to_freq(long arfcn) {
 
 // layer 3 filtering of RSRP (EUTRA) measurements: 36.331, Sec. 5.5.3.2
 //-----------------------------------------------------------------------------
-void ue_meas_filtering( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index )
-{
+void ue_meas_filtering( const protocol_ctxt_t *const ctxt_pP, const uint8_t eNB_index ) {
   float a  = UE_rrc_inst[ctxt_pP->module_id].filter_coeff_rsrp; // 'a' in 36.331 Sec. 5.5.3.2
   float a1 = UE_rrc_inst[ctxt_pP->module_id].filter_coeff_rsrq;
   //float rsrp_db, rsrq_db;
@@ -4216,18 +3844,17 @@ void ue_meas_filtering( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_
       if(UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[0]->quantityConfigEUTRA->filterCoefficientRSRP != NULL) {
         for (eNB_offset = 0; eNB_offset<1+get_n_adj_cells(ctxt_pP->module_id,0); eNB_offset++) {
           UE_rrc_inst[ctxt_pP->module_id].rsrp_db[eNB_offset] = get_RSRP(ctxt_pP->module_id,0,eNB_offset);
-	  /*
-	  (dB_fixed_times10(get_RSRP(ctxt_pP->module_id,0,eNB_offset))/10.0) -
-	  get_rx_total_gain_dB(ctxt_pP->module_id,0) -
-	  get_bw_gain_dB(ctxt_pP->module_id);
-	  */
+          /*
+          (dB_fixed_times10(get_RSRP(ctxt_pP->module_id,0,eNB_offset))/10.0) -
+          get_rx_total_gain_dB(ctxt_pP->module_id,0) -
+          get_bw_gain_dB(ctxt_pP->module_id);
+          */
           UE_rrc_inst[ctxt_pP->module_id].rsrp_db_filtered[eNB_offset] =
             (1.0-a)*UE_rrc_inst[ctxt_pP->module_id].rsrp_db_filtered[eNB_offset] +
             a*UE_rrc_inst[ctxt_pP->module_id].rsrp_db[eNB_offset];
-
           LOG_D(RRC,"RSRP_dBm: %3.2f \n",get_RSRP(ctxt_pP->module_id,0,eNB_offset));;
-	  /*          LOG_D(RRC,"gain_loss_dB: %d \n",get_rx_total_gain_dB(ctxt_pP->module_id,0));
-		      LOG_D(RRC,"gain_fixed_dB: %d \n",dB_fixed(frame_parms->N_RB_DL*12));*/
+          /*          LOG_D(RRC,"gain_loss_dB: %d \n",get_rx_total_gain_dB(ctxt_pP->module_id,0));
+                LOG_D(RRC,"gain_fixed_dB: %d \n",dB_fixed(frame_parms->N_RB_DL*12));*/
           LOG_D(PHY,"[UE %d] Frame %d, RRC Measurements => rssi %3.1f dBm (digital: %3.1f dB)\n",
                 ctxt_pP->module_id,
                 ctxt_pP->frame,
@@ -4265,21 +3892,18 @@ void ue_meas_filtering( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_
 
 //Below routine implements Measurement Reporting procedure from 36.331 Section 5.5.5
 //-----------------------------------------------------------------------------
- void rrc_ue_generate_MeasurementReport(protocol_ctxt_t* const ctxt_pP, uint8_t eNB_index )
-{
-
+void rrc_ue_generate_MeasurementReport(protocol_ctxt_t *const ctxt_pP, uint8_t eNB_index ) {
   uint8_t             buffer[32], size;
   uint8_t             i;
   uint8_t             target_eNB_offset;
-  MeasId_t         measId;
-  PhysCellId_t      targetCellId;
+  LTE_MeasId_t        measId;
+  LTE_PhysCellId_t    targetCellId;
   long             rsrp_t,rsrq_t;
   long             rsrp_s,rsrq_s;
   long             nElem, nElem1;
   float            rsrp_filtered, rsrq_filtered;
   static frame_t   pframe=0;
   int              result;
-
   nElem = 98;
   nElem1 = 35;
   target_eNB_offset = UE_rrc_inst[ctxt_pP->module_id].Info[0].handoverTarget; // eNB_offset of target eNB: used to obtain the mod_id of target eNB
@@ -4287,14 +3911,11 @@ void ue_meas_filtering( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_
   for (i=0; i<MAX_MEAS_ID; i++) {
     if (UE_rrc_inst[ctxt_pP->module_id].measReportList[0][i] != NULL) {
       measId = UE_rrc_inst[ctxt_pP->module_id].measReportList[0][i]->measId;
-
       // Note: Values in the meas report have to be the mapped values...to implement binary search for LUT
       rsrp_filtered = UE_rrc_inst[ctxt_pP->module_id].rsrp_db_filtered[eNB_index];//nid_cell];
       rsrp_s = binary_search_float(RSRP_meas_mapping,nElem, rsrp_filtered);
-
       rsrq_filtered = UE_rrc_inst[ctxt_pP->module_id].rsrq_db_filtered[eNB_index];//nid_cell]; //RSRQ of serving cell
       rsrq_s = binary_search_float(RSRQ_meas_mapping,nElem1,rsrq_filtered);//mapped RSRQ of serving cell
-
       LOG_D(RRC,"[UE %d] Frame %d: source eNB %d :rsrp_s: %ld rsrq_s: %ld rsrp_filtered: %f rsrq_filtered: %f \n",
             ctxt_pP->module_id,
             ctxt_pP->frame,
@@ -4305,7 +3926,6 @@ void ue_meas_filtering( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_
             rsrq_filtered);
       rsrp_t = binary_search_float(RSRP_meas_mapping,nElem,UE_rrc_inst[ctxt_pP->module_id].rsrp_db_filtered[target_eNB_offset]); //RSRP of target cell
       rsrq_t = binary_search_float(RSRQ_meas_mapping,nElem1,UE_rrc_inst[ctxt_pP->module_id].rsrq_db_filtered[target_eNB_offset]); //RSRQ of target cell
-
       LOG_D(RRC,"[UE %d] Frame %d: target eNB %d :rsrp_t: %ld rsrq_t: %ld rsrp_filtered: %f rsrq_filtered: %f \n",
             ctxt_pP->module_id,
             ctxt_pP->frame,
@@ -4314,7 +3934,6 @@ void ue_meas_filtering( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_
             rsrq_t,
             UE_rrc_inst[ctxt_pP->module_id].rsrp_db_filtered[target_eNB_offset],
             UE_rrc_inst[ctxt_pP->module_id].rsrq_db_filtered[target_eNB_offset]);
-
       //  if (measFlag == 1) {
       targetCellId = UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.targetCellId ;//get_adjacent_cell_id(ue_mod_idP,target_eNB_offset); //PhycellId of target cell
 
@@ -4333,10 +3952,10 @@ void ue_meas_filtering( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_
         LOG_I(RRC, "[UE %d] Frame %d : Generating Measurement Report for eNB %d\n",
               ctxt_pP->module_id, ctxt_pP->frame, eNB_index);
         result = pdcp_data_req(ctxt_pP,  SRB_FLAG_YES, DCCH, rrc_mui++, 0, size, buffer, PDCP_TRANSMISSION_MODE_DATA
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                                ,NULL, NULL
 #endif
-                               );
+                              );
         AssertFatal (result == TRUE, "PDCP data request failed!\n");
         //LOG_D(RRC, "[UE %d] Frame %d Sending MeasReport (%d bytes) through DCCH%d to PDCP \n",ue_mod_idP,frameP, size, DCCH);
       }
@@ -4349,18 +3968,17 @@ void ue_meas_filtering( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_
 
 // Measurement report triggering, described in 36.331 Section 5.5.4.1: called periodically
 //-----------------------------------------------------------------------------
-void ue_measurement_report_triggering(protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index )
-{
+void ue_measurement_report_triggering(protocol_ctxt_t *const ctxt_pP, const uint8_t eNB_index ) {
   uint8_t               i,j;
-  Hysteresis_t     hys;
-  TimeToTrigger_t  ttt_ms;
-  Q_OffsetRange_t  ofn;
-  Q_OffsetRange_t  ocn;
-  Q_OffsetRange_t  ofs = 0;
-  Q_OffsetRange_t  ocs = 0;
+  LTE_Hysteresis_t     hys;
+  LTE_TimeToTrigger_t  ttt_ms;
+  LTE_Q_OffsetRange_t  ofn;
+  LTE_Q_OffsetRange_t  ocn;
+  LTE_Q_OffsetRange_t  ofs = 0;
+  LTE_Q_OffsetRange_t  ocs = 0;
   long             a3_offset;
-  MeasObjectId_t   measObjId;
-  ReportConfigId_t reportConfigId;
+  LTE_MeasObjectId_t   measObjId;
+  LTE_ReportConfigId_t reportConfigId;
 
   for(i=0 ; i<NB_CNX_UE ; i++) {
     for(j=0 ; j<MAX_MEAS_ID ; j++) {
@@ -4369,15 +3987,15 @@ void ue_measurement_report_triggering(protocol_ctxt_t* const ctxt_pP, const uint
         reportConfigId = UE_rrc_inst[ctxt_pP->module_id].MeasId[i][j]->reportConfigId;
 
         if( /*UE_rrc_inst[ctxt_pP->module_id].MeasId[i][j] != NULL && */ UE_rrc_inst[ctxt_pP->module_id].MeasObj[i][measObjId-1] != NULL) {
-          if(UE_rrc_inst[ctxt_pP->module_id].MeasObj[i][measObjId-1]->measObject.present == MeasObjectToAddMod__measObject_PR_measObjectEUTRA) {
+          if(UE_rrc_inst[ctxt_pP->module_id].MeasObj[i][measObjId-1]->measObject.present == LTE_MeasObjectToAddMod__measObject_PR_measObjectEUTRA) {
             /* consider any neighboring cell detected on the associated frequency to be
              * applicable when the concerned cell is not included in the blackCellsToAddModList
              * defined within the VarMeasConfig for this measId */
             //    LOG_I(RRC,"event %d %d %p \n", measObjId,reportConfigId, UE_rrc_inst[ctxt_pP->module_id].ReportConfig[i][reportConfigId-1]);
             if((UE_rrc_inst[ctxt_pP->module_id].ReportConfig[i][reportConfigId-1] != NULL) &&
-                (UE_rrc_inst[ctxt_pP->module_id].ReportConfig[i][reportConfigId-1]->reportConfig.present==ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA) &&
+                (UE_rrc_inst[ctxt_pP->module_id].ReportConfig[i][reportConfigId-1]->reportConfig.present == LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA) &&
                 (UE_rrc_inst[ctxt_pP->module_id].ReportConfig[i][reportConfigId-1]->reportConfig.choice.reportConfigEUTRA.triggerType.present ==
-                 ReportConfigEUTRA__triggerType_PR_event)) {
+                 LTE_ReportConfigEUTRA__triggerType_PR_event)) {
               hys = UE_rrc_inst[ctxt_pP->module_id].ReportConfig[i][reportConfigId-1]->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.hysteresis;
               ttt_ms = timeToTrigger_ms[UE_rrc_inst[ctxt_pP->module_id].ReportConfig[i][reportConfigId
                                         -1]->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.timeToTrigger];
@@ -4390,65 +4008,65 @@ void ue_measurement_report_triggering(protocol_ctxt_t* const ctxt_pP, const uint
                           -1]->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA3.a3_Offset;
 
               switch (UE_rrc_inst[ctxt_pP->module_id].ReportConfig[i][reportConfigId-1]->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present) {
-              case ReportConfigEUTRA__triggerType__event__eventId_PR_eventA1:
-                LOG_D(RRC,"[UE %d] Frame %d : A1 event: check if serving becomes better than threshold\n",
-                      ctxt_pP->module_id, ctxt_pP->frame);
-                break;
-
-              case ReportConfigEUTRA__triggerType__event__eventId_PR_eventA2:
-                LOG_D(RRC,"[UE %d] Frame %d : A2 event, check if serving becomes worse than a threshold\n",
-                      ctxt_pP->module_id, ctxt_pP->frame);
-                break;
-
-              case ReportConfigEUTRA__triggerType__event__eventId_PR_eventA3:
-                LOG_D(RRC,"[UE %d] Frame %d : A3 event: check if a neighboring cell becomes offset better than serving to trigger a measurement event \n",
-                      ctxt_pP->module_id, ctxt_pP->frame);
-
-                if ((check_trigger_meas_event(
-                       ctxt_pP->module_id,
-                       ctxt_pP->frame,
-                       eNB_index,
-                       i,j,ofn,ocn,hys,ofs,ocs,a3_offset,ttt_ms)) &&
-                    (UE_rrc_inst[ctxt_pP->module_id].Info[0].State >= RRC_CONNECTED) &&
-                    (UE_rrc_inst[ctxt_pP->module_id].Info[0].T304_active == 0 )      &&
-                    (UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.measFlag == 1)) {
-                  //trigger measurement reporting procedure (36.331, section 5.5.5)
-                  if (UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j] == NULL) {
-                    UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j] = malloc(sizeof(MEAS_REPORT_LIST));
+                case LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA1:
+                  LOG_D(RRC,"[UE %d] Frame %d : A1 event: check if serving becomes better than threshold\n",
+                        ctxt_pP->module_id, ctxt_pP->frame);
+                  break;
+
+                case LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA2:
+                  LOG_D(RRC,"[UE %d] Frame %d : A2 event, check if serving becomes worse than a threshold\n",
+                        ctxt_pP->module_id, ctxt_pP->frame);
+                  break;
+
+                case LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA3:
+                  LOG_D(RRC,"[UE %d] Frame %d : A3 event: check if a neighboring cell becomes offset better than serving to trigger a measurement event \n",
+                        ctxt_pP->module_id, ctxt_pP->frame);
+
+                  if ((check_trigger_meas_event(
+                         ctxt_pP->module_id,
+                         ctxt_pP->frame,
+                         eNB_index,
+                         i,j,ofn,ocn,hys,ofs,ocs,a3_offset,ttt_ms)) &&
+                      (UE_rrc_inst[ctxt_pP->module_id].Info[0].State >= RRC_CONNECTED) &&
+                      (UE_rrc_inst[ctxt_pP->module_id].Info[0].T304_active == 0 )      &&
+                      (UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.measFlag == 1)) {
+                    //trigger measurement reporting procedure (36.331, section 5.5.5)
+                    if (UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j] == NULL) {
+                      UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j] = malloc(sizeof(MEAS_REPORT_LIST));
+                    }
+
+                    UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j]->measId = UE_rrc_inst[ctxt_pP->module_id].MeasId[i][j]->measId;
+                    UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j]->numberOfReportsSent = 0;
+                    rrc_ue_generate_MeasurementReport(
+                      ctxt_pP,
+                      eNB_index);
+                    UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.measFlag = 1;
+                    LOG_I(RRC,"[UE %d] Frame %d: A3 event detected, state: %d \n",
+                          ctxt_pP->module_id, ctxt_pP->frame, UE_rrc_inst[ctxt_pP->module_id].Info[0].State);
+                  } else {
+                    if(UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j] != NULL) {
+                      free(UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j]);
+                    }
+
+                    UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j] = NULL;
                   }
 
-                  UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j]->measId = UE_rrc_inst[ctxt_pP->module_id].MeasId[i][j]->measId;
-                  UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j]->numberOfReportsSent = 0;
-                  rrc_ue_generate_MeasurementReport(
-                    ctxt_pP,
-                    eNB_index);
-                  UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.measFlag = 1;
-                  LOG_I(RRC,"[UE %d] Frame %d: A3 event detected, state: %d \n",
-                        ctxt_pP->module_id, ctxt_pP->frame, UE_rrc_inst[ctxt_pP->module_id].Info[0].State);
-                } else {
-                  if(UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j] != NULL) {
-                    free(UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j]);
-                  }
-
-                  UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j] = NULL;
-                }
-
-                break;
+                  break;
 
-              case ReportConfigEUTRA__triggerType__event__eventId_PR_eventA4:
-                LOG_D(RRC,"[UE %d] Frame %d : received an A4 event, neighbor becomes offset better than a threshold\n",
-                      ctxt_pP->module_id, ctxt_pP->frame);
-                break;
+                case LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA4:
+                  LOG_D(RRC,"[UE %d] Frame %d : received an A4 event, neighbor becomes offset better than a threshold\n",
+                        ctxt_pP->module_id, ctxt_pP->frame);
+                  break;
 
-              case ReportConfigEUTRA__triggerType__event__eventId_PR_eventA5:
-                LOG_D(RRC,"[UE %d] Frame %d: received an A5 event, serving becomes worse than threshold 1 and neighbor becomes better than threshold 2\n",
-                      ctxt_pP->module_id, ctxt_pP->frame);
-                break;
+                case LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA5:
+                  LOG_D(RRC,"[UE %d] Frame %d: received an A5 event, serving becomes worse than threshold 1 and neighbor becomes better than threshold 2\n",
+                        ctxt_pP->module_id, ctxt_pP->frame);
+                  break;
 
-              default:
-                LOG_D(RRC,"Invalid ReportConfigEUTRA__triggerType__event__eventId: %d",
-                      UE_rrc_inst[ctxt_pP->module_id].ReportConfig[i][j]->reportConfig.choice.reportConfigEUTRA.triggerType.present);
-                break;
+                default:
+                  LOG_D(RRC,"Invalid ReportConfigEUTRA__triggerType__event__eventId: %d",
+                        UE_rrc_inst[ctxt_pP->module_id].ReportConfig[i][j]->reportConfig.choice.reportConfigEUTRA.triggerType.present);
+                  break;
               }
             }
           }
@@ -4461,24 +4079,22 @@ void ue_measurement_report_triggering(protocol_ctxt_t* const ctxt_pP, const uint
 //check_trigger_meas_event(ue_mod_idP, frameP, eNB_index, i,j,ofn,ocn,hys,ofs,ocs,a3_offset,ttt_ms)
 //-----------------------------------------------------------------------------
 
- uint8_t check_trigger_meas_event(
+uint8_t check_trigger_meas_event(
   module_id_t     ue_mod_idP,
   frame_t         frameP,
   uint8_t         eNB_index,
   uint8_t         ue_cnx_index,
   uint8_t         meas_index,
-  Q_OffsetRange_t ofn,
-  Q_OffsetRange_t ocn,
-  Hysteresis_t    hys,
-  Q_OffsetRange_t ofs,
-  Q_OffsetRange_t ocs,
+  LTE_Q_OffsetRange_t ofn,
+  LTE_Q_OffsetRange_t ocn,
+  LTE_Hysteresis_t    hys,
+  LTE_Q_OffsetRange_t ofs,
+  LTE_Q_OffsetRange_t ocs,
   long            a3_offset,
-  TimeToTrigger_t ttt )
-{
+  LTE_TimeToTrigger_t ttt ) {
   uint8_t eNB_offset;
   //  uint8_t currentCellIndex = frame_parms->Nid_cell;
   uint8_t tmp_offset;
-
   LOG_I(RRC,"[UE %d] ofn(%ld) ocn(%ld) hys(%ld) ofs(%ld) ocs(%ld) a3_offset(%ld) ttt(%ld) rssi %3.1f\n",
         ue_mod_idP,
         ofn,ocn,hys,ofs,ocs,a3_offset,ttt,
@@ -4508,8 +4124,8 @@ void ue_measurement_report_triggering(protocol_ctxt_t* const ctxt_pP, const uint
         LOG_D(RRC,"[UE %d] Frame %d eNB %d: Handover triggered: targetCellId: %ld currentCellId: %d eNB_offset: %d rsrp source: %3.1f rsrp target: %3.1f\n",
               ue_mod_idP, frameP, eNB_index,
               UE_rrc_inst->HandoverInfoUe.targetCellId,ue_cnx_index,eNB_offset,
-	      get_RSRP(ue_mod_idP,0,0),
-	      get_RSRP(ue_mod_idP,0,1));
+              get_RSRP(ue_mod_idP,0,0),
+              get_RSRP(ue_mod_idP,0,1));
         UE_rrc_inst->Info[0].handoverTarget = eNB_offset;
         //LOG_D(RRC,"PHY_ID: %d \n",UE_rrc_inst->HandoverInfoUe.targetCellId);
         return 1;
@@ -4524,14 +4140,11 @@ void ue_measurement_report_triggering(protocol_ctxt_t* const ctxt_pP, const uint
   return 0;
 }
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 //-----------------------------------------------------------------------------
-int decode_MCCH_Message( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index, const uint8_t* const Sdu, const uint8_t Sdu_len, const uint8_t mbsfn_sync_area )
-{
-
-  MCCH_Message_t               *mcch=NULL;
-  MBSFNAreaConfiguration_r9_t** mcch_message=&UE_rrc_inst[ctxt_pP->module_id].mcch_message[eNB_index];
-
+int decode_MCCH_Message( const protocol_ctxt_t *const ctxt_pP, const uint8_t eNB_index, const uint8_t *const Sdu, const uint8_t Sdu_len, const uint8_t mbsfn_sync_area ) {
+  LTE_MCCH_Message_t               *mcch=NULL;
+  LTE_MBSFNAreaConfiguration_r9_t **mcch_message=&UE_rrc_inst[ctxt_pP->module_id].mcch_message[eNB_index];
   asn_dec_rval_t                dec_rval;
 
   if (UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].MCCHStatus[mbsfn_sync_area] == 1) {
@@ -4542,7 +4155,7 @@ int decode_MCCH_Message( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB
     return 0; // avoid decoding to prevent memory bloating
   } else {
     dec_rval = uper_decode_complete(NULL,
-                                    &asn_DEF_MCCH_Message,
+                                    &asn_DEF_LTE_MCCH_Message,
                                     (void **)&mcch,
                                     (const void *)Sdu,
                                     Sdu_len);
@@ -4552,19 +4165,19 @@ int decode_MCCH_Message( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB
             ctxt_pP->module_id,
             dec_rval.consumed);
       //free the memory
-      SEQUENCE_free(&asn_DEF_MCCH_Message, (void*)mcch, 1);
+      SEQUENCE_free(&asn_DEF_LTE_MCCH_Message, (void *)mcch, 1);
       return -1;
     }
 
     if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-      xer_fprint(stdout, &asn_DEF_MCCH_Message, (void*)mcch);
+      xer_fprint(stdout, &asn_DEF_LTE_MCCH_Message, (void *)mcch);
     }
 
-    if (mcch->message.present == MCCH_MessageType_PR_c1) {
+    if (mcch->message.present == LTE_MCCH_MessageType_PR_c1) {
       LOG_D(RRC,"[UE %d] Found mcch message \n",
             ctxt_pP->module_id);
 
-      if(mcch->message.choice.c1.present == MCCH_MessageType__c1_PR_mbsfnAreaConfiguration_r9) {
+      if(mcch->message.choice.c1.present == LTE_MCCH_MessageType__c1_PR_mbsfnAreaConfiguration_r9) {
         /*
         memcpy((void*)*mcch_message,
          (void*)&mcch->message.choice.c1.choice.mbsfnAreaConfiguration_r9,
@@ -4579,7 +4192,6 @@ int decode_MCCH_Message( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB
           eNB_index,
           ctxt_pP->frame,
           mbsfn_sync_area);
-
       }
     }
   }
@@ -4588,16 +4200,14 @@ int decode_MCCH_Message( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB
 }
 
 //-----------------------------------------------------------------------------
- void decode_MBSFNAreaConfiguration( module_id_t ue_mod_idP, uint8_t eNB_index, frame_t frameP, uint8_t mbsfn_sync_area )
-{
+void decode_MBSFNAreaConfiguration( module_id_t ue_mod_idP, uint8_t eNB_index, frame_t frameP, uint8_t mbsfn_sync_area ) {
   uint8_t i;
   protocol_ctxt_t               ctxt;
-
   LOG_I(RRC,"[UE %d] Frame %d : Number of MCH(s) in the MBSFN Sync Area %d  is %d\n",
         ue_mod_idP, frameP, mbsfn_sync_area, UE_rrc_inst[ue_mod_idP].mcch_message[eNB_index]->pmch_InfoList_r9.list.count);
 
-  // Configure commonSF_Alloc 
-  for(i=0; i< UE_rrc_inst[ue_mod_idP].mcch_message[eNB_index]->commonSF_Alloc_r9.list.count;i++){
+  // Configure commonSF_Alloc
+  for(i=0; i< UE_rrc_inst[ue_mod_idP].mcch_message[eNB_index]->commonSF_Alloc_r9.list.count; i++) {
     LOG_W(RRC,"[UE %d] Frame %d, commonSF_Alloc_r9: radioframeAllocationPeriod(%ldn),radioframeAllocationOffset(%ld), subframeAllocation(%x,%x,%x)\n",
           ue_mod_idP, frameP,
           UE_rrc_inst[ue_mod_idP].mcch_message[eNB_index]->commonSF_Alloc_r9.list.array[i]->radioframeAllocationPeriod<<1,
@@ -4607,566 +4217,503 @@ int decode_MCCH_Message( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB
           UE_rrc_inst[ue_mod_idP].mcch_message[eNB_index]->commonSF_Alloc_r9.list.array[i]->subframeAllocation.choice.oneFrame.buf[2]);
     UE_mac_inst[ue_mod_idP].commonSF_Alloc_r9_mbsfn_SubframeConfig[i] = UE_rrc_inst[ue_mod_idP].mcch_message[eNB_index]->commonSF_Alloc_r9.list.array[i];
   }
+
   LOG_W(RRC,"[UE %d] Frame %d, commonSF_AllocPeriod_r9 %drf \n",
         ue_mod_idP, frameP,
         4<<UE_rrc_inst[ue_mod_idP].mcch_message[eNB_index]->commonSF_AllocPeriod_r9);
-
   // Configure commonSF_AllocPeriod
   UE_mac_inst[ue_mod_idP].commonSF_AllocPeriod_r9 = UE_rrc_inst[ue_mod_idP].mcch_message[eNB_index]->commonSF_AllocPeriod_r9;
-
   //  store to MAC/PHY necessary parameters for receiving MTCHs
-
   rrc_mac_config_req_ue(ue_mod_idP,0,eNB_index,
-			(RadioResourceConfigCommonSIB_t *)NULL,
-			(struct PhysicalConfigDedicated *)NULL,
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-			(SCellToAddMod_r10_t *)NULL,
-			//(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
-#endif
-			(MeasObjectToAddMod_t **)NULL,
-			(MAC_MainConfig_t *)NULL,
-			0,
-			(struct LogicalChannelConfig *)NULL,
-			(MeasGapConfig_t *)NULL,
-			(TDD_Config_t *)NULL,
-			(MobilityControlInfo_t *)NULL,
-			NULL,
-			NULL,
-			NULL,
-			NULL,
-			NULL,
-			(MBSFN_SubframeConfigList_t *)NULL
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-			,
-			0,
-			(MBSFN_AreaInfoList_r9_t *)NULL,
-			&UE_rrc_inst[ue_mod_idP].mcch_message[eNB_index]->pmch_InfoList_r9
-
+                        (LTE_RadioResourceConfigCommonSIB_t *)NULL,
+                        (struct LTE_PhysicalConfigDedicated *)NULL,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                        (LTE_SCellToAddMod_r10_t *)NULL,
+                        //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
+#endif
+                        (LTE_MeasObjectToAddMod_t **)NULL,
+                        (LTE_MAC_MainConfig_t *)NULL,
+                        0,
+                        (struct LTE_LogicalChannelConfig *)NULL,
+                        (LTE_MeasGapConfig_t *)NULL,
+                        (LTE_TDD_Config_t *)NULL,
+                        (LTE_MobilityControlInfo_t *)NULL,
+                        NULL,
+                        NULL,
+                        NULL,
+                        NULL,
+                        NULL,
+                        (LTE_MBSFN_SubframeConfigList_t *)NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+                        ,
+                        0,
+                        (LTE_MBSFN_AreaInfoList_r9_t *)NULL,
+                        &UE_rrc_inst[ue_mod_idP].mcch_message[eNB_index]->pmch_InfoList_r9
 #endif
 #ifdef CBA
-			,
-			0,
-			0
+                        ,
+                        0,
+                        0
 #endif
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-           ,
-           0,
-           NULL,
-           NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                        ,
+                        0,
+                        NULL,
+                        NULL
 #endif
-			);
-
+                       );
   UE_rrc_inst[ue_mod_idP].Info[eNB_index].MCCHStatus[mbsfn_sync_area] = 1;
-
   PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_idP, ENB_FLAG_NO, UE_rrc_inst[ue_mod_idP].Info[eNB_index].rnti, frameP, 0,eNB_index);
-
   // Config Radio Bearer for MBMS user data (similar way to configure for eNB side in init_MBMS function)
   rrc_pdcp_config_asn1_req(&ctxt,
                            NULL, // SRB_ToAddModList
                            NULL, // DRB_ToAddModList
-                           (DRB_ToReleaseList_t*)NULL,
+                           (LTE_DRB_ToReleaseList_t *)NULL,
                            0, // security mode
                            NULL, // key rrc encryption
                            NULL, // key rrc integrity
                            NULL // key encryption
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
                            ,&(UE_rrc_inst[ue_mod_idP].mcch_message[eNB_index]->pmch_InfoList_r9)
 #endif
                            ,NULL);
-
   rrc_rlc_config_asn1_req(&ctxt,
                           NULL,// SRB_ToAddModList
                           NULL,// DRB_ToAddModList
                           NULL,// DRB_ToReleaseList
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
                           &(UE_rrc_inst[ue_mod_idP].mcch_message[eNB_index]->pmch_InfoList_r9)
                           , 0, 0
 #endif
                          );
   // */
-
 }
 
 #endif // rel10
 
 #if defined(ENABLE_ITTI)
 //-----------------------------------------------------------------------------
-void *rrc_ue_task( void *args_p )
-{
+void *rrc_ue_task( void *args_p ) {
   MessageDef   *msg_p;
   instance_t    instance;
   unsigned int  ue_mod_id;
   int           result;
   SRB_INFO     *srb_info_p;
-
   protocol_ctxt_t  ctxt;
   itti_mark_task_ready (TASK_RRC_UE);
 
   while(1) {
     // Wait for a message
     itti_receive_msg (TASK_RRC_UE, &msg_p);
-
     instance = ITTI_MSG_INSTANCE (msg_p);
     ue_mod_id = UE_INSTANCE_TO_MODULE_ID(instance);
 
     switch (ITTI_MSG_ID(msg_p)) {
-    case TERMINATE_MESSAGE:
-      LOG_W(RRC, " *** Exiting RRC thread\n");
-      itti_exit_task ();
-      break;
+      case TERMINATE_MESSAGE:
+        LOG_W(RRC, " *** Exiting RRC thread\n");
+        itti_exit_task ();
+        break;
 
-    case MESSAGE_TEST:
-      LOG_D(RRC, "[UE %d] Received %s\n", ue_mod_id, ITTI_MSG_NAME (msg_p));
-      break;
+      case MESSAGE_TEST:
+        break;
 
       /* MAC messages */
-    case RRC_MAC_IN_SYNC_IND:
-      LOG_D(RRC, "[UE %d] Received %s: frameP %d, eNB %d\n", ue_mod_id, ITTI_MSG_NAME (msg_p),
-            RRC_MAC_IN_SYNC_IND (msg_p).frame, RRC_MAC_IN_SYNC_IND (msg_p).enb_index);
-
-      UE_rrc_inst[ue_mod_id].Info[RRC_MAC_IN_SYNC_IND (msg_p).enb_index].N310_cnt = 0;
-
-      if (UE_rrc_inst[ue_mod_id].Info[RRC_MAC_IN_SYNC_IND (msg_p).enb_index].T310_active == 1) {
-        UE_rrc_inst[ue_mod_id].Info[RRC_MAC_IN_SYNC_IND (msg_p).enb_index].N311_cnt++;
-      }
-
-      break;
-
-    case RRC_MAC_OUT_OF_SYNC_IND:
-      LOG_D(RRC, "[UE %d] Received %s: frameP %d, eNB %d\n", ue_mod_id, ITTI_MSG_NAME (msg_p),
-            RRC_MAC_OUT_OF_SYNC_IND (msg_p).frame, RRC_MAC_OUT_OF_SYNC_IND (msg_p).enb_index);
+      case RRC_MAC_IN_SYNC_IND:
+        LOG_D(RRC, "[UE %d] Received %s: frameP %d, eNB %d\n", ue_mod_id, ITTI_MSG_NAME (msg_p),
+              RRC_MAC_IN_SYNC_IND (msg_p).frame, RRC_MAC_IN_SYNC_IND (msg_p).enb_index);
+        UE_rrc_inst[ue_mod_id].Info[RRC_MAC_IN_SYNC_IND (msg_p).enb_index].N310_cnt = 0;
 
-      UE_rrc_inst[ue_mod_id].Info[RRC_MAC_OUT_OF_SYNC_IND (msg_p).enb_index].N310_cnt ++;
-      break;
-
-    case RRC_MAC_BCCH_DATA_IND:
-      LOG_D(RRC, "[UE %d] Received %s: frameP %d, eNB %d\n", ue_mod_id, ITTI_MSG_NAME (msg_p),
-            RRC_MAC_BCCH_DATA_IND (msg_p).frame, RRC_MAC_BCCH_DATA_IND (msg_p).enb_index);
-
-      //      PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, ENB_FLAG_NO, NOT_A_RNTI, RRC_MAC_BCCH_DATA_IND (msg_p).frame, 0);
-      PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, ENB_FLAG_NO, NOT_A_RNTI, RRC_MAC_BCCH_DATA_IND (msg_p).frame, 0,RRC_MAC_BCCH_DATA_IND (msg_p).enb_index);
-      decode_BCCH_DLSCH_Message (&ctxt,
-                                 RRC_MAC_BCCH_DATA_IND (msg_p).enb_index,
-                                 RRC_MAC_BCCH_DATA_IND (msg_p).sdu,
-                                 RRC_MAC_BCCH_DATA_IND (msg_p).sdu_size,
-                                 RRC_MAC_BCCH_DATA_IND (msg_p).rsrq,
-                                 RRC_MAC_BCCH_DATA_IND (msg_p).rsrp);
-      break;
-
-    case RRC_MAC_CCCH_DATA_CNF:
-      LOG_D(RRC, "[UE %d] Received %s: eNB %d\n", ue_mod_id, ITTI_MSG_NAME (msg_p),
-            RRC_MAC_CCCH_DATA_CNF (msg_p).enb_index);
-
-      // reset the tx buffer to indicate RRC that ccch was successfully transmitted (for example if contention resolution succeeds)
-      UE_rrc_inst[ue_mod_id].Srb0[RRC_MAC_CCCH_DATA_CNF (msg_p).enb_index].Tx_buffer.payload_size = 0;
-      break;
+        if (UE_rrc_inst[ue_mod_id].Info[RRC_MAC_IN_SYNC_IND (msg_p).enb_index].T310_active == 1) {
+          UE_rrc_inst[ue_mod_id].Info[RRC_MAC_IN_SYNC_IND (msg_p).enb_index].N311_cnt++;
+        }
 
-    case RRC_MAC_CCCH_DATA_IND:
-      LOG_D(RRC, "[UE %d] RNTI %x Received %s: frameP %d, eNB %d\n",
-            ue_mod_id,
-            RRC_MAC_CCCH_DATA_IND (msg_p).rnti,
-            ITTI_MSG_NAME (msg_p),
-            RRC_MAC_CCCH_DATA_IND (msg_p).frame,
-            RRC_MAC_CCCH_DATA_IND (msg_p).enb_index);
-
-      srb_info_p = &UE_rrc_inst[ue_mod_id].Srb0[RRC_MAC_CCCH_DATA_IND (msg_p).enb_index];
-
-      memcpy (srb_info_p->Rx_buffer.Payload, RRC_MAC_CCCH_DATA_IND (msg_p).sdu,
-              RRC_MAC_CCCH_DATA_IND (msg_p).sdu_size);
-      srb_info_p->Rx_buffer.payload_size = RRC_MAC_CCCH_DATA_IND (msg_p).sdu_size;
-      //      PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, ENB_FLAG_NO, RRC_MAC_CCCH_DATA_IND (msg_p).rnti, RRC_MAC_CCCH_DATA_IND (msg_p).frame, 0);
-      PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, ENB_FLAG_NO, RRC_MAC_CCCH_DATA_IND (msg_p).rnti, RRC_MAC_CCCH_DATA_IND (msg_p).frame, 0, RRC_MAC_CCCH_DATA_IND (msg_p).enb_index);
-      rrc_ue_decode_ccch (&ctxt,
-                          srb_info_p,
-                          RRC_MAC_CCCH_DATA_IND (msg_p).enb_index);
-      break;
+        break;
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+      case RRC_MAC_OUT_OF_SYNC_IND:
+        LOG_D(RRC, "[UE %d] Received %s: frameP %d, eNB %d\n", ue_mod_id, ITTI_MSG_NAME (msg_p),
+              RRC_MAC_OUT_OF_SYNC_IND (msg_p).frame, RRC_MAC_OUT_OF_SYNC_IND (msg_p).enb_index);
+        UE_rrc_inst[ue_mod_id].Info[RRC_MAC_OUT_OF_SYNC_IND (msg_p).enb_index].N310_cnt ++;
+        break;
 
-    case RRC_MAC_MCCH_DATA_IND:
-      LOG_D(RRC, "[UE %d] Received %s: frameP %d, eNB %d, mbsfn SA %d\n", ue_mod_id, ITTI_MSG_NAME (msg_p),
-            RRC_MAC_MCCH_DATA_IND (msg_p).frame, RRC_MAC_MCCH_DATA_IND (msg_p).enb_index, RRC_MAC_MCCH_DATA_IND (msg_p).mbsfn_sync_area);
+      case RRC_MAC_BCCH_DATA_IND:
+        LOG_D(RRC, "[UE %d] Received %s: frameP %d, eNB %d\n", ue_mod_id, ITTI_MSG_NAME (msg_p),
+              RRC_MAC_BCCH_DATA_IND (msg_p).frame, RRC_MAC_BCCH_DATA_IND (msg_p).enb_index);
+        //      PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, ENB_FLAG_NO, NOT_A_RNTI, RRC_MAC_BCCH_DATA_IND (msg_p).frame, 0);
+        PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, ENB_FLAG_NO, NOT_A_RNTI, RRC_MAC_BCCH_DATA_IND (msg_p).frame, 0,RRC_MAC_BCCH_DATA_IND (msg_p).enb_index);
+        decode_BCCH_DLSCH_Message (&ctxt,
+                                   RRC_MAC_BCCH_DATA_IND (msg_p).enb_index,
+                                   RRC_MAC_BCCH_DATA_IND (msg_p).sdu,
+                                   RRC_MAC_BCCH_DATA_IND (msg_p).sdu_size,
+                                   RRC_MAC_BCCH_DATA_IND (msg_p).rsrq,
+                                   RRC_MAC_BCCH_DATA_IND (msg_p).rsrp);
+        break;
 
-      //PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, ENB_FLAG_NO, M_RNTI, RRC_MAC_MCCH_DATA_IND (msg_p).frame, 0);
-      PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, ENB_FLAG_NO, M_RNTI, RRC_MAC_MCCH_DATA_IND (msg_p).frame, 0,RRC_MAC_MCCH_DATA_IND (msg_p).enb_index);
-      decode_MCCH_Message (
-        &ctxt,
-        RRC_MAC_MCCH_DATA_IND (msg_p).enb_index,
-        RRC_MAC_MCCH_DATA_IND (msg_p).sdu,
-        RRC_MAC_MCCH_DATA_IND (msg_p).sdu_size,
-        RRC_MAC_MCCH_DATA_IND (msg_p).mbsfn_sync_area);
-      break;
+      case RRC_MAC_CCCH_DATA_CNF:
+        LOG_D(RRC, "[UE %d] Received %s: eNB %d\n", ue_mod_id, ITTI_MSG_NAME (msg_p),
+              RRC_MAC_CCCH_DATA_CNF (msg_p).enb_index);
+        // reset the tx buffer to indicate RRC that ccch was successfully transmitted (for example if contention resolution succeeds)
+        UE_rrc_inst[ue_mod_id].Srb0[RRC_MAC_CCCH_DATA_CNF (msg_p).enb_index].Tx_buffer.payload_size = 0;
+        break;
 
-  /*  //TTN (for D2D)
-    case RRC_MAC_SL_DISCOVERY_DATA_IND:
-       LOG_D(RRC, "[UE %d] Received %s: frameP %d, eNB %d\n", ue_mod_id, ITTI_MSG_NAME (msg_p),
-             RRC_MAC_SL_DISCOVERY_DATA_IND (msg_p).frame, RRC_MAC_SL_DISCOVERY_DATA_IND (msg_p).enb_index);
-       PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, ENB_FLAG_NO, M_RNTI, RRC_MAC_SL_DISCOVERY_DATA_IND (msg_p).frame, 0,RRC_MAC_SL_DISCOVERY_DATA_IND (msg_p).enb_index);
-       //send to ProSeApp
-       break;
-*/
+      case RRC_MAC_CCCH_DATA_IND:
+        LOG_D(RRC, "[UE %d] RNTI %x Received %s: frameP %d, eNB %d\n",
+              ue_mod_id,
+              RRC_MAC_CCCH_DATA_IND (msg_p).rnti,
+              ITTI_MSG_NAME (msg_p),
+              RRC_MAC_CCCH_DATA_IND (msg_p).frame,
+              RRC_MAC_CCCH_DATA_IND (msg_p).enb_index);
+        srb_info_p = &UE_rrc_inst[ue_mod_id].Srb0[RRC_MAC_CCCH_DATA_IND (msg_p).enb_index];
+        memcpy (srb_info_p->Rx_buffer.Payload, RRC_MAC_CCCH_DATA_IND (msg_p).sdu,
+                RRC_MAC_CCCH_DATA_IND (msg_p).sdu_size);
+        srb_info_p->Rx_buffer.payload_size = RRC_MAC_CCCH_DATA_IND (msg_p).sdu_size;
+        //      PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, ENB_FLAG_NO, RRC_MAC_CCCH_DATA_IND (msg_p).rnti, RRC_MAC_CCCH_DATA_IND (msg_p).frame, 0);
+        PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, ENB_FLAG_NO, RRC_MAC_CCCH_DATA_IND (msg_p).rnti, RRC_MAC_CCCH_DATA_IND (msg_p).frame, 0, RRC_MAC_CCCH_DATA_IND (msg_p).enb_index);
+        rrc_ue_decode_ccch (&ctxt,
+                            srb_info_p,
+                            RRC_MAC_CCCH_DATA_IND (msg_p).enb_index);
+        break;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+
+      case RRC_MAC_MCCH_DATA_IND:
+        LOG_D(RRC, "[UE %d] Received %s: frameP %d, eNB %d, mbsfn SA %d\n", ue_mod_id, ITTI_MSG_NAME (msg_p),
+              RRC_MAC_MCCH_DATA_IND (msg_p).frame, RRC_MAC_MCCH_DATA_IND (msg_p).enb_index, RRC_MAC_MCCH_DATA_IND (msg_p).mbsfn_sync_area);
+        //PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, ENB_FLAG_NO, M_RNTI, RRC_MAC_MCCH_DATA_IND (msg_p).frame, 0);
+        PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, ENB_FLAG_NO, M_RNTI, RRC_MAC_MCCH_DATA_IND (msg_p).frame, 0,RRC_MAC_MCCH_DATA_IND (msg_p).enb_index);
+        decode_MCCH_Message (
+          &ctxt,
+          RRC_MAC_MCCH_DATA_IND (msg_p).enb_index,
+          RRC_MAC_MCCH_DATA_IND (msg_p).sdu,
+          RRC_MAC_MCCH_DATA_IND (msg_p).sdu_size,
+          RRC_MAC_MCCH_DATA_IND (msg_p).mbsfn_sync_area);
+        break;
+        /*  //TTN (for D2D)
+          case RRC_MAC_SL_DISCOVERY_DATA_IND:
+             LOG_D(RRC, "[UE %d] Received %s: frameP %d, eNB %d\n", ue_mod_id, ITTI_MSG_NAME (msg_p),
+                   RRC_MAC_SL_DISCOVERY_DATA_IND (msg_p).frame, RRC_MAC_SL_DISCOVERY_DATA_IND (msg_p).enb_index);
+             PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, ENB_FLAG_NO, M_RNTI, RRC_MAC_SL_DISCOVERY_DATA_IND (msg_p).frame, 0,RRC_MAC_SL_DISCOVERY_DATA_IND (msg_p).enb_index);
+             //send to ProSeApp
+             break;
+        */
 # endif
 
       /* PDCP messages */
-    case RRC_DCCH_DATA_IND:
-      PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, RRC_DCCH_DATA_IND (msg_p).module_id, ENB_FLAG_NO, RRC_DCCH_DATA_IND (msg_p).rnti, RRC_DCCH_DATA_IND (msg_p).frame, 0,RRC_DCCH_DATA_IND (msg_p).eNB_index);
-      LOG_D(RRC, "[UE %d] Received %s: frameP %d, DCCH %d, eNB %d\n",
-            RRC_DCCH_DATA_IND (msg_p).module_id,
-            ITTI_MSG_NAME (msg_p),
-            RRC_DCCH_DATA_IND (msg_p).frame,
-            RRC_DCCH_DATA_IND (msg_p).dcch_index,
-            RRC_DCCH_DATA_IND (msg_p).eNB_index);
-
-      LOG_D(RRC, PROTOCOL_RRC_CTXT_UE_FMT"Received %s DCCH %d, eNB %d\n",
-            PROTOCOL_RRC_CTXT_UE_ARGS(&ctxt),
-            ITTI_MSG_NAME (msg_p),
-            RRC_DCCH_DATA_IND (msg_p).dcch_index,
-            RRC_DCCH_DATA_IND (msg_p).eNB_index);
-      rrc_ue_decode_dcch (
-        &ctxt,
-        RRC_DCCH_DATA_IND (msg_p).dcch_index,
-        RRC_DCCH_DATA_IND (msg_p).sdu_p,
-        RRC_DCCH_DATA_IND (msg_p).eNB_index);
-      // Message buffer has been processed, free it now.
-      result = itti_free (ITTI_MSG_ORIGIN_ID(msg_p), RRC_DCCH_DATA_IND (msg_p).sdu_p);
-      AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
-      break;
-
+      case RRC_DCCH_DATA_IND:
+        PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, RRC_DCCH_DATA_IND (msg_p).module_id, ENB_FLAG_NO, RRC_DCCH_DATA_IND (msg_p).rnti, RRC_DCCH_DATA_IND (msg_p).frame, 0,RRC_DCCH_DATA_IND (msg_p).eNB_index);
+        LOG_D(RRC, "[UE %d] Received %s: frameP %d, DCCH %d, eNB %d\n",
+              RRC_DCCH_DATA_IND (msg_p).module_id,
+              ITTI_MSG_NAME (msg_p),
+              RRC_DCCH_DATA_IND (msg_p).frame,
+              RRC_DCCH_DATA_IND (msg_p).dcch_index,
+              RRC_DCCH_DATA_IND (msg_p).eNB_index);
+        LOG_D(RRC, PROTOCOL_RRC_CTXT_UE_FMT"Received %s DCCH %d, eNB %d\n",
+              PROTOCOL_RRC_CTXT_UE_ARGS(&ctxt),
+              ITTI_MSG_NAME (msg_p),
+              RRC_DCCH_DATA_IND (msg_p).dcch_index,
+              RRC_DCCH_DATA_IND (msg_p).eNB_index);
+        rrc_ue_decode_dcch (
+          &ctxt,
+          RRC_DCCH_DATA_IND (msg_p).dcch_index,
+          RRC_DCCH_DATA_IND (msg_p).sdu_p,
+          RRC_DCCH_DATA_IND (msg_p).eNB_index);
+        // Message buffer has been processed, free it now.
+        result = itti_free (ITTI_MSG_ORIGIN_ID(msg_p), RRC_DCCH_DATA_IND (msg_p).sdu_p);
+        AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
+        break;
 # if defined(ENABLE_USE_MME)
 
-    case NAS_KENB_REFRESH_REQ:
-        memcpy((void*)UE_rrc_inst[ue_mod_id].kenb, (void*)NAS_KENB_REFRESH_REQ(msg_p).kenb, sizeof(UE_rrc_inst[ue_mod_id].kenb));
-
+      case NAS_KENB_REFRESH_REQ:
+        memcpy((void *)UE_rrc_inst[ue_mod_id].kenb, (void *)NAS_KENB_REFRESH_REQ(msg_p).kenb, sizeof(UE_rrc_inst[ue_mod_id].kenb));
         LOG_D(RRC, "[UE %d] Received %s: refreshed RRC::KeNB = "
-            "%02x%02x%02x%02x"
-            "%02x%02x%02x%02x"
-            "%02x%02x%02x%02x"
-            "%02x%02x%02x%02x"
-            "%02x%02x%02x%02x"
-            "%02x%02x%02x%02x"
-            "%02x%02x%02x%02x"
-            "%02x%02x%02x%02x\n",
-            ue_mod_id, ITTI_MSG_NAME (msg_p),
-            UE_rrc_inst[ue_mod_id].kenb[0],  UE_rrc_inst[ue_mod_id].kenb[1],  UE_rrc_inst[ue_mod_id].kenb[2],  UE_rrc_inst[ue_mod_id].kenb[3],
-            UE_rrc_inst[ue_mod_id].kenb[4],  UE_rrc_inst[ue_mod_id].kenb[5],  UE_rrc_inst[ue_mod_id].kenb[6],  UE_rrc_inst[ue_mod_id].kenb[7],
-            UE_rrc_inst[ue_mod_id].kenb[8],  UE_rrc_inst[ue_mod_id].kenb[9],  UE_rrc_inst[ue_mod_id].kenb[10], UE_rrc_inst[ue_mod_id].kenb[11],
-            UE_rrc_inst[ue_mod_id].kenb[12], UE_rrc_inst[ue_mod_id].kenb[13], UE_rrc_inst[ue_mod_id].kenb[14], UE_rrc_inst[ue_mod_id].kenb[15],
-            UE_rrc_inst[ue_mod_id].kenb[16], UE_rrc_inst[ue_mod_id].kenb[17], UE_rrc_inst[ue_mod_id].kenb[18], UE_rrc_inst[ue_mod_id].kenb[19],
-            UE_rrc_inst[ue_mod_id].kenb[20], UE_rrc_inst[ue_mod_id].kenb[21], UE_rrc_inst[ue_mod_id].kenb[22], UE_rrc_inst[ue_mod_id].kenb[23],
-            UE_rrc_inst[ue_mod_id].kenb[24], UE_rrc_inst[ue_mod_id].kenb[25], UE_rrc_inst[ue_mod_id].kenb[26], UE_rrc_inst[ue_mod_id].kenb[27],
-            UE_rrc_inst[ue_mod_id].kenb[28], UE_rrc_inst[ue_mod_id].kenb[29], UE_rrc_inst[ue_mod_id].kenb[30], UE_rrc_inst[ue_mod_id].kenb[31]);
-
-      break;
+              "%02x%02x%02x%02x"
+              "%02x%02x%02x%02x"
+              "%02x%02x%02x%02x"
+              "%02x%02x%02x%02x"
+              "%02x%02x%02x%02x"
+              "%02x%02x%02x%02x"
+              "%02x%02x%02x%02x"
+              "%02x%02x%02x%02x\n",
+              ue_mod_id, ITTI_MSG_NAME (msg_p),
+              UE_rrc_inst[ue_mod_id].kenb[0],  UE_rrc_inst[ue_mod_id].kenb[1],  UE_rrc_inst[ue_mod_id].kenb[2],  UE_rrc_inst[ue_mod_id].kenb[3],
+              UE_rrc_inst[ue_mod_id].kenb[4],  UE_rrc_inst[ue_mod_id].kenb[5],  UE_rrc_inst[ue_mod_id].kenb[6],  UE_rrc_inst[ue_mod_id].kenb[7],
+              UE_rrc_inst[ue_mod_id].kenb[8],  UE_rrc_inst[ue_mod_id].kenb[9],  UE_rrc_inst[ue_mod_id].kenb[10], UE_rrc_inst[ue_mod_id].kenb[11],
+              UE_rrc_inst[ue_mod_id].kenb[12], UE_rrc_inst[ue_mod_id].kenb[13], UE_rrc_inst[ue_mod_id].kenb[14], UE_rrc_inst[ue_mod_id].kenb[15],
+              UE_rrc_inst[ue_mod_id].kenb[16], UE_rrc_inst[ue_mod_id].kenb[17], UE_rrc_inst[ue_mod_id].kenb[18], UE_rrc_inst[ue_mod_id].kenb[19],
+              UE_rrc_inst[ue_mod_id].kenb[20], UE_rrc_inst[ue_mod_id].kenb[21], UE_rrc_inst[ue_mod_id].kenb[22], UE_rrc_inst[ue_mod_id].kenb[23],
+              UE_rrc_inst[ue_mod_id].kenb[24], UE_rrc_inst[ue_mod_id].kenb[25], UE_rrc_inst[ue_mod_id].kenb[26], UE_rrc_inst[ue_mod_id].kenb[27],
+              UE_rrc_inst[ue_mod_id].kenb[28], UE_rrc_inst[ue_mod_id].kenb[29], UE_rrc_inst[ue_mod_id].kenb[30], UE_rrc_inst[ue_mod_id].kenb[31]);
+        break;
 
       /* NAS messages */
-    case NAS_CELL_SELECTION_REQ:
-
-      LOG_D(RRC, "[UE %d] Received %s: state %d, plmnID (%d%d%d.%d%d%d), rat %x\n", ue_mod_id, ITTI_MSG_NAME (msg_p), rrc_get_state(ue_mod_id),
-            NAS_CELL_SELECTION_REQ (msg_p).plmnID.MCCdigit1,
-            NAS_CELL_SELECTION_REQ (msg_p).plmnID.MCCdigit2,
-            NAS_CELL_SELECTION_REQ (msg_p).plmnID.MCCdigit3,
-            NAS_CELL_SELECTION_REQ (msg_p).plmnID.MNCdigit1,
-            NAS_CELL_SELECTION_REQ (msg_p).plmnID.MNCdigit2,
-            NAS_CELL_SELECTION_REQ (msg_p).plmnID.MNCdigit3,
-            NAS_CELL_SELECTION_REQ (msg_p).rat);
-
-      if (rrc_get_state(ue_mod_id) == RRC_STATE_INACTIVE) {
-        // have a look at MAC/main.c void dl_phy_sync_success(...)
-        openair_rrc_ue_init(ue_mod_id,0);
-      }
+      case NAS_CELL_SELECTION_REQ:
+        LOG_D(RRC, "[UE %d] Received %s: state %d, plmnID (%d%d%d.%d%d%d), rat %x\n", ue_mod_id, ITTI_MSG_NAME (msg_p), rrc_get_state(ue_mod_id),
+              NAS_CELL_SELECTION_REQ (msg_p).plmnID.MCCdigit1,
+              NAS_CELL_SELECTION_REQ (msg_p).plmnID.MCCdigit2,
+              NAS_CELL_SELECTION_REQ (msg_p).plmnID.MCCdigit3,
+              NAS_CELL_SELECTION_REQ (msg_p).plmnID.MNCdigit1,
+              NAS_CELL_SELECTION_REQ (msg_p).plmnID.MNCdigit2,
+              NAS_CELL_SELECTION_REQ (msg_p).plmnID.MNCdigit3,
+              NAS_CELL_SELECTION_REQ (msg_p).rat);
+
+        if (rrc_get_state(ue_mod_id) == RRC_STATE_INACTIVE) {
+          // have a look at MAC/main.c void dl_phy_sync_success(...)
+          openair_rrc_ue_init(ue_mod_id,0);
+        }
 
-      /* Save cell selection criterion */
-      {
-        UE_rrc_inst[ue_mod_id].plmnID = NAS_CELL_SELECTION_REQ (msg_p).plmnID;
-        UE_rrc_inst[ue_mod_id].rat = NAS_CELL_SELECTION_REQ (msg_p).rat;
-        LOG_D(RRC, "[UE %d] Save cell selection criterion MCC %X%X%X MNC %X%X%X\n",
-              ue_mod_id,
-              UE_rrc_inst[ue_mod_id].plmnID.MCCdigit1,
-              UE_rrc_inst[ue_mod_id].plmnID.MCCdigit2,
-              UE_rrc_inst[ue_mod_id].plmnID.MCCdigit3,
-              UE_rrc_inst[ue_mod_id].plmnID.MNCdigit1,
-              UE_rrc_inst[ue_mod_id].plmnID.MNCdigit2,
-              UE_rrc_inst[ue_mod_id].plmnID.MNCdigit3);
+        /* Save cell selection criterion */
+        {
+          UE_rrc_inst[ue_mod_id].plmnID = NAS_CELL_SELECTION_REQ (msg_p).plmnID;
+          UE_rrc_inst[ue_mod_id].rat = NAS_CELL_SELECTION_REQ (msg_p).rat;
+          LOG_D(RRC, "[UE %d] Save cell selection criterion MCC %X%X%X MNC %X%X%X\n",
+                ue_mod_id,
+                UE_rrc_inst[ue_mod_id].plmnID.MCCdigit1,
+                UE_rrc_inst[ue_mod_id].plmnID.MCCdigit2,
+                UE_rrc_inst[ue_mod_id].plmnID.MCCdigit3,
+                UE_rrc_inst[ue_mod_id].plmnID.MNCdigit1,
+                UE_rrc_inst[ue_mod_id].plmnID.MNCdigit2,
+                UE_rrc_inst[ue_mod_id].plmnID.MNCdigit3);
+        }
 
-      }
+        switch (rrc_get_state(ue_mod_id)) {
+          case RRC_STATE_INACTIVE: {
+            rrc_set_state (ue_mod_id, RRC_STATE_IDLE);
+            /* Fall through to next case */
+          }
 
-      switch (rrc_get_state(ue_mod_id)) {
-      case RRC_STATE_INACTIVE: {
-        /* Need to first activate lower layers */
-        MessageDef *message_p;
+          case RRC_STATE_IDLE: {
+            /* Ask to layer 1 to find a cell matching the criterion */
+            MessageDef *message_p;
+            message_p = itti_alloc_new_message(TASK_RRC_UE, PHY_FIND_CELL_REQ);
+            PHY_FIND_CELL_REQ (message_p).earfcn_start = 1;
+            PHY_FIND_CELL_REQ (message_p).earfcn_end = 1;
+            itti_send_msg_to_task(TASK_PHY_UE, UE_MODULE_ID_TO_INSTANCE(ue_mod_id), message_p);
+            rrc_set_sub_state (ue_mod_id, RRC_SUB_STATE_IDLE_SEARCHING);
+            break;
+          }
 
-        message_p = itti_alloc_new_message(TASK_RRC_UE, ACTIVATE_MESSAGE);
+          case RRC_STATE_CONNECTED:
+            /* should not happen */
+            LOG_E(RRC, "[UE %d] request %s in RRC state %d\n", ue_mod_id, ITTI_MSG_NAME (msg_p), rrc_get_state(ue_mod_id));
+            break;
 
-        itti_send_msg_to_task(TASK_L2L1, UE_MODULE_ID_TO_INSTANCE(ue_mod_id), message_p);
+          default:
+            LOG_E(RRC, "[UE %d] Invalid RRC state %d\n", ue_mod_id, rrc_get_state(ue_mod_id));
+            break;
+        }
 
-        rrc_set_state (ue_mod_id, RRC_STATE_IDLE);
-        /* Fall through to next case */
-      }
+        break;
 
-      case RRC_STATE_IDLE: {
-        /* Ask to layer 1 to find a cell matching the criterion */
-        MessageDef *message_p;
+      case NAS_CONN_ESTABLI_REQ:
+        LOG_D(RRC, "[UE %d] Received %s: cause %d, type %d, s_tmsi (mme code %"PRIu8", m-tmsi %"PRIu32"), plmnID (%d%d%d.%d%d%d)\n", ue_mod_id, ITTI_MSG_NAME (msg_p), NAS_CONN_ESTABLI_REQ (msg_p).cause,
+              NAS_CONN_ESTABLI_REQ (msg_p).type,
+              NAS_CONN_ESTABLI_REQ (msg_p).s_tmsi.MMEcode,
+              NAS_CONN_ESTABLI_REQ (msg_p).s_tmsi.m_tmsi,
+              NAS_CONN_ESTABLI_REQ (msg_p).plmnID.MCCdigit1,
+              NAS_CONN_ESTABLI_REQ (msg_p).plmnID.MCCdigit2,
+              NAS_CONN_ESTABLI_REQ (msg_p).plmnID.MCCdigit3,
+              NAS_CONN_ESTABLI_REQ (msg_p).plmnID.MNCdigit1,
+              NAS_CONN_ESTABLI_REQ (msg_p).plmnID.MNCdigit2,
+              NAS_CONN_ESTABLI_REQ (msg_p).plmnID.MNCdigit3);
+        //PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, ENB_FLAG_NO, NOT_A_RNTI, 0, 0);
+        PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, ENB_FLAG_NO, NOT_A_RNTI, 0, 0, 0);
+        UE_rrc_inst[ue_mod_id].initialNasMsg = NAS_CONN_ESTABLI_REQ (msg_p).initialNasMsg;
+
+        switch (rrc_get_state(ue_mod_id)) {
+          case RRC_STATE_IDLE: {
+            if (rrc_get_sub_state(ue_mod_id) == RRC_SUB_STATE_IDLE_SIB_COMPLETE) {
+              rrc_ue_generate_RRCConnectionRequest(&ctxt, 0);
+              LOG_D(RRC, "not sending connection request\n");
+              rrc_set_sub_state (ue_mod_id, RRC_SUB_STATE_IDLE_CONNECTING);
+            }
 
-        message_p = itti_alloc_new_message(TASK_RRC_UE, PHY_FIND_CELL_REQ);
+            break;
+          }
 
-        PHY_FIND_CELL_REQ (message_p).earfcn_start = 1;
-        PHY_FIND_CELL_REQ (message_p).earfcn_end = 1;
+          case RRC_STATE_INACTIVE:
+          case RRC_STATE_CONNECTED:
+            /* should not happen */
+            LOG_E(RRC, "[UE %d] request %s in RRC state %d\n", ue_mod_id, ITTI_MSG_NAME (msg_p), rrc_get_state(ue_mod_id));
+            break;
 
-        itti_send_msg_to_task(TASK_PHY_UE, UE_MODULE_ID_TO_INSTANCE(ue_mod_id), message_p);
-        rrc_set_sub_state (ue_mod_id, RRC_SUB_STATE_IDLE_SEARCHING);
+          default:
+            LOG_E(RRC, "[UE %d] Invalid RRC state %d\n", ue_mod_id, rrc_get_state(ue_mod_id));
+            break;
+        }
 
         break;
-      }
 
-      case RRC_STATE_CONNECTED:
-        /* should not happen */
-        LOG_E(RRC, "[UE %d] request %s in RRC state %d\n", ue_mod_id, ITTI_MSG_NAME (msg_p), rrc_get_state(ue_mod_id));
-        break;
+      case NAS_UPLINK_DATA_REQ: {
+        uint32_t length;
+        uint8_t *buffer;
+        LOG_D(RRC, "[UE %d] Received %s: UEid %d\n", ue_mod_id, ITTI_MSG_NAME (msg_p), NAS_UPLINK_DATA_REQ (msg_p).UEid);
+        /* Create message for PDCP (ULInformationTransfer_t) */
+        length = do_ULInformationTransfer(&buffer, NAS_UPLINK_DATA_REQ (msg_p).nasMsg.length, NAS_UPLINK_DATA_REQ (msg_p).nasMsg.data);
+        /* Transfer data to PDCP */
+        PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, ENB_FLAG_NO, UE_rrc_inst[ue_mod_id].Info[0].rnti, 0, 0,0);
+
+        // check if SRB2 is created, if yes request data_req on DCCH1 (SRB2)
+        if(UE_rrc_inst[ue_mod_id].SRB2_config[0] == NULL) {
+          rrc_data_req_ue (&ctxt,
+                           DCCH,
+                           rrc_mui++,
+                           SDU_CONFIRM_NO,
+                           length, buffer,
+                           PDCP_TRANSMISSION_MODE_CONTROL);
+        } else {
+          rrc_data_req_ue (&ctxt,
+                           DCCH1,
+                           rrc_mui++,
+                           SDU_CONFIRM_NO,
+                           length, buffer,
+                           PDCP_TRANSMISSION_MODE_CONTROL);
+        }
 
-      default:
-        LOG_E(RRC, "[UE %d] Invalid RRC state %d\n", ue_mod_id, rrc_get_state(ue_mod_id));
         break;
       }
 
-      break;
+# endif
+# if ENABLE_RAL
 
-    case NAS_CONN_ESTABLI_REQ:
-      LOG_D(RRC, "[UE %d] Received %s: cause %d, type %d, s_tmsi (mme code %"PRIu8", m-tmsi %"PRIu32"), plmnID (%d%d%d.%d%d%d)\n", ue_mod_id, ITTI_MSG_NAME (msg_p), NAS_CONN_ESTABLI_REQ (msg_p).cause,
-            NAS_CONN_ESTABLI_REQ (msg_p).type,
-            NAS_CONN_ESTABLI_REQ (msg_p).s_tmsi.MMEcode,
-            NAS_CONN_ESTABLI_REQ (msg_p).s_tmsi.m_tmsi,
-            NAS_CONN_ESTABLI_REQ (msg_p).plmnID.MCCdigit1,
-            NAS_CONN_ESTABLI_REQ (msg_p).plmnID.MCCdigit2,
-            NAS_CONN_ESTABLI_REQ (msg_p).plmnID.MCCdigit3,
-            NAS_CONN_ESTABLI_REQ (msg_p).plmnID.MNCdigit1,
-            NAS_CONN_ESTABLI_REQ (msg_p).plmnID.MNCdigit2,
-            NAS_CONN_ESTABLI_REQ (msg_p).plmnID.MNCdigit3);
-
-      //PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, ENB_FLAG_NO, NOT_A_RNTI, 0, 0);
-      PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, ENB_FLAG_NO, NOT_A_RNTI, 0, 0, 0);
-
-      UE_rrc_inst[ue_mod_id].initialNasMsg = NAS_CONN_ESTABLI_REQ (msg_p).initialNasMsg;
-
-      switch (rrc_get_state(ue_mod_id)) {
-      case RRC_STATE_IDLE: {
-        if (rrc_get_sub_state(ue_mod_id) == RRC_SUB_STATE_IDLE_SIB_COMPLETE) {
-          rrc_ue_generate_RRCConnectionRequest(&ctxt, 0);
-          LOG_D(RRC, "not sending connection request\n");
-
-          rrc_set_sub_state (ue_mod_id, RRC_SUB_STATE_IDLE_CONNECTING);
-        }
-
-        break;
-      }
-
-      case RRC_STATE_INACTIVE:
-      case RRC_STATE_CONNECTED:
-        /* should not happen */
-        LOG_E(RRC, "[UE %d] request %s in RRC state %d\n", ue_mod_id, ITTI_MSG_NAME (msg_p), rrc_get_state(ue_mod_id));
-        break;
-
-      default:
-        LOG_E(RRC, "[UE %d] Invalid RRC state %d\n", ue_mod_id, rrc_get_state(ue_mod_id));
-        break;
-      }
-
-      break;
-
-    case NAS_UPLINK_DATA_REQ: {
-      uint32_t length;
-      uint8_t *buffer;
-
-      LOG_D(RRC, "[UE %d] Received %s: UEid %d\n", ue_mod_id, ITTI_MSG_NAME (msg_p), NAS_UPLINK_DATA_REQ (msg_p).UEid);
-
-      /* Create message for PDCP (ULInformationTransfer_t) */
-      length = do_ULInformationTransfer(&buffer, NAS_UPLINK_DATA_REQ (msg_p).nasMsg.length, NAS_UPLINK_DATA_REQ (msg_p).nasMsg.data);
-
-      /* Transfer data to PDCP */
-      PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, ENB_FLAG_NO, UE_rrc_inst[ue_mod_id].Info[0].rnti, 0, 0,0);
-
-      // check if SRB2 is created, if yes request data_req on DCCH1 (SRB2)
-      if(UE_rrc_inst[ue_mod_id].SRB2_config[0] == NULL)
-      {
-          rrc_data_req_ue (&ctxt,
-                  DCCH,
-                  rrc_mui++,
-                  SDU_CONFIRM_NO,
-                  length, buffer,
-                  PDCP_TRANSMISSION_MODE_CONTROL);
-      }
-      else
-      {
-          rrc_data_req_ue (&ctxt,
-                  DCCH1,
-                  rrc_mui++,
-                  SDU_CONFIRM_NO,
-                  length, buffer,
-                  PDCP_TRANSMISSION_MODE_CONTROL);
-      }
-      break;
-    }
-
-# endif
-
-# if ENABLE_RAL
-
-    case RRC_RAL_SCAN_REQ:
-      LOG_D(RRC, "[UE %d] Received %s: state %d\n", ue_mod_id,ITTI_MSG_NAME (msg_p) );
-
-      switch (rrc_get_state(ue_mod_id)) {
-      case RRC_STATE_INACTIVE: {
-        /* Need to first activate lower layers */
-        MessageDef *message_p;
+      case RRC_RAL_SCAN_REQ:
+        LOG_D(RRC, "[UE %d] Received %s: state %d\n", ue_mod_id,ITTI_MSG_NAME (msg_p) );
 
-        message_p = itti_alloc_new_message(TASK_RRC_UE, ACTIVATE_MESSAGE);
-
-        itti_send_msg_to_task(TASK_L2L1, instance, message_p);
-
-        rrc_set_state (ue_mod_id, RRC_STATE_IDLE);
-        /* Fall through to next case */
-      }
-
-      case RRC_STATE_IDLE: {
-        if (rrc_get_sub_state(ue_mod_id) != RRC_SUB_STATE_IDLE_SEARCHING) {
-          /* Ask to layer 1 to find a cell matching the criterion */
-          MessageDef *message_p;
+        switch (rrc_get_state(ue_mod_id)) {
+          case RRC_STATE_INACTIVE: {
+            rrc_set_state (ue_mod_id, RRC_STATE_IDLE);
+            /* Fall through to next case */
+          }
 
-          message_p = itti_alloc_new_message(TASK_RRC_UE, PHY_FIND_CELL_REQ);
+          case RRC_STATE_IDLE: {
+            if (rrc_get_sub_state(ue_mod_id) != RRC_SUB_STATE_IDLE_SEARCHING) {
+              /* Ask to layer 1 to find a cell matching the criterion */
+              MessageDef *message_p;
+              message_p = itti_alloc_new_message(TASK_RRC_UE, PHY_FIND_CELL_REQ);
+              rrc_set_sub_state (ue_mod_id, RRC_SUB_STATE_IDLE_SEARCHING);
+              PHY_FIND_CELL_REQ (message_p).transaction_id = RRC_RAL_SCAN_REQ (msg_p).transaction_id;
+              PHY_FIND_CELL_REQ (message_p).earfcn_start   = 1;
+              PHY_FIND_CELL_REQ (message_p).earfcn_end     = 1; //44
+              itti_send_msg_to_task(TASK_PHY_UE, instance, message_p);
+            }
 
-          rrc_set_sub_state (ue_mod_id, RRC_SUB_STATE_IDLE_SEARCHING);
+            break;
+          }
 
-          PHY_FIND_CELL_REQ (message_p).transaction_id = RRC_RAL_SCAN_REQ (msg_p).transaction_id;
-          PHY_FIND_CELL_REQ (message_p).earfcn_start   = 1;
-          PHY_FIND_CELL_REQ (message_p).earfcn_end     = 1; //44
+          case RRC_STATE_CONNECTED:
+            /* should not happen */
+            LOG_E(RRC, "[UE %d] request %s in RRC state %d\n", ue_mod_id, ITTI_MSG_NAME (msg_p), rrc_get_state(ue_mod_id));
+            break;
 
-          itti_send_msg_to_task(TASK_PHY_UE, instance, message_p);
+          default:
+            LOG_E(RRC, "[UE %d] Invalid RRC state %d\n", ue_mod_id, rrc_get_state(ue_mod_id));
+            break;
         }
 
         break;
-      }
-
-      case RRC_STATE_CONNECTED:
-        /* should not happen */
-        LOG_E(RRC, "[UE %d] request %s in RRC state %d\n", ue_mod_id, ITTI_MSG_NAME (msg_p), rrc_get_state(ue_mod_id));
-        break;
-
-      default:
-        LOG_E(RRC, "[UE %d] Invalid RRC state %d\n", ue_mod_id, rrc_get_state(ue_mod_id));
-        break;
-      }
-
-      break;
-
-    case PHY_FIND_CELL_IND:
-      LOG_D(RRC, "[UE %d] Received %s: state %d\n", ue_mod_id, ITTI_MSG_NAME (msg_p), rrc_get_state(ue_mod_id));
-
-      switch (rrc_get_state(ue_mod_id)) {
-      case RRC_STATE_IDLE:
-        switch (rrc_get_sub_state(ue_mod_id)) {
-        case RRC_SUB_STATE_IDLE_SEARCHING: {
-          MessageDef *message_p;
-          int         i;
 
-          message_p = itti_alloc_new_message(TASK_RRC_UE, RRC_RAL_SCAN_CONF);
-
-          RRC_RAL_SCAN_CONF (message_p).transaction_id = PHY_FIND_CELL_IND(msg_p).transaction_id;
-          RRC_RAL_SCAN_CONF (message_p).num_scan_resp  = PHY_FIND_CELL_IND(msg_p).cell_nb;
+      case PHY_FIND_CELL_IND:
+        LOG_D(RRC, "[UE %d] Received %s: state %d\n", ue_mod_id, ITTI_MSG_NAME (msg_p), rrc_get_state(ue_mod_id));
+
+        switch (rrc_get_state(ue_mod_id)) {
+          case RRC_STATE_IDLE:
+            switch (rrc_get_sub_state(ue_mod_id)) {
+              case RRC_SUB_STATE_IDLE_SEARCHING: {
+                MessageDef *message_p;
+                int         i;
+                message_p = itti_alloc_new_message(TASK_RRC_UE, RRC_RAL_SCAN_CONF);
+                RRC_RAL_SCAN_CONF (message_p).transaction_id = PHY_FIND_CELL_IND(msg_p).transaction_id;
+                RRC_RAL_SCAN_CONF (message_p).num_scan_resp  = PHY_FIND_CELL_IND(msg_p).cell_nb;
+
+                for (i = 0 ; i < PHY_FIND_CELL_IND(msg_p).cell_nb; i++) {
+                  // TO DO
+                  memset(&RRC_RAL_SCAN_CONF (message_p).link_scan_resp[i].link_addr,  0, sizeof(ral_link_addr_t));
+                  // TO DO
+                  memset(&RRC_RAL_SCAN_CONF (message_p).link_scan_resp[i].network_id, 0, sizeof(ral_network_id_t));
+                  RRC_RAL_SCAN_CONF (message_p).link_scan_resp[i].sig_strength.choice     = RAL_SIG_STRENGTH_CHOICE_DBM;
+                  RRC_RAL_SCAN_CONF (message_p).link_scan_resp[i].sig_strength._union.dbm = PHY_FIND_CELL_IND(msg_p).cells[i].rsrp;
+                }
 
-          for (i = 0 ; i < PHY_FIND_CELL_IND(msg_p).cell_nb; i++) {
-            // TO DO
-            memset(&RRC_RAL_SCAN_CONF (message_p).link_scan_resp[i].link_addr,  0, sizeof(ral_link_addr_t));
-            // TO DO
-            memset(&RRC_RAL_SCAN_CONF (message_p).link_scan_resp[i].network_id, 0, sizeof(ral_network_id_t));
+                rrc_set_sub_state (ue_mod_id, RRC_SUB_STATE_IDLE);
+                itti_send_msg_to_task(TASK_RAL_UE, instance, message_p);
+                break;
+              }
 
-            RRC_RAL_SCAN_CONF (message_p).link_scan_resp[i].sig_strength.choice     = RAL_SIG_STRENGTH_CHOICE_DBM;
-            RRC_RAL_SCAN_CONF (message_p).link_scan_resp[i].sig_strength._union.dbm = PHY_FIND_CELL_IND(msg_p).cells[i].rsrp;
-          }
+              default:
+                LOG_E(RRC, "[UE %d] Invalid RRC state %d substate %d\n",
+                      ue_mod_id,
+                      rrc_get_state(ue_mod_id),
+                      rrc_get_sub_state(ue_mod_id));
+            }
 
-          rrc_set_sub_state (ue_mod_id, RRC_SUB_STATE_IDLE);
+            break;
 
-          itti_send_msg_to_task(TASK_RAL_UE, instance, message_p);
-          break;
-        }
+          case RRC_STATE_INACTIVE:
+          case RRC_STATE_CONNECTED:
+            /* should not happen */
+            LOG_E(RRC, "[UE %d] indication %s in RRC state %d\n", ue_mod_id, ITTI_MSG_NAME (msg_p), rrc_get_state(ue_mod_id));
+            break;
 
-        default:
-          LOG_E(RRC, "[UE %d] Invalid RRC state %d substate %d\n",
-                ue_mod_id,
-                rrc_get_state(ue_mod_id),
-                rrc_get_sub_state(ue_mod_id));
+          default:
+            LOG_E(RRC, "[UE %d] Invalid RRC state %d\n", ue_mod_id, rrc_get_state(ue_mod_id));
+            break;
         }
 
-        break;
+        break; // PHY_FIND_CELL_IND
 
-      case RRC_STATE_INACTIVE:
-      case RRC_STATE_CONNECTED:
-        /* should not happen */
-        LOG_E(RRC, "[UE %d] indication %s in RRC state %d\n", ue_mod_id, ITTI_MSG_NAME (msg_p), rrc_get_state(ue_mod_id));
-        break;
-
-      default:
-        LOG_E(RRC, "[UE %d] Invalid RRC state %d\n", ue_mod_id, rrc_get_state(ue_mod_id));
+      case PHY_MEAS_REPORT_IND: {
+        LOG_D(RRC, "[UE %d] Received %s\n", ue_mod_id, ITTI_MSG_NAME (msg_p));
+        MessageDef *message_p;
+        message_p = itti_alloc_new_message(TASK_RRC_UE, RRC_RAL_MEASUREMENT_REPORT_IND);
+        memcpy(&RRC_RAL_MEASUREMENT_REPORT_IND (message_p).threshold,
+               &PHY_MEAS_REPORT_IND(msg_p).threshold,
+               sizeof(RRC_RAL_MEASUREMENT_REPORT_IND (message_p).threshold));
+        memcpy(&RRC_RAL_MEASUREMENT_REPORT_IND (message_p).link_param,
+               &PHY_MEAS_REPORT_IND(msg_p).link_param,
+               sizeof(RRC_RAL_MEASUREMENT_REPORT_IND (message_p).link_param));
+        LOG_D(RRC, "[UE %d] PHY_MEAS_REPORT_IN: sending msg %s to %s \n", ue_mod_id, "RRC_RAL_MEASUREMENT_REPORT_IND", "TASK_RAL_UE");
+        itti_send_msg_to_task(TASK_RAL_UE, instance, message_p);
         break;
       }
 
-      break; // PHY_FIND_CELL_IND
-
-    case PHY_MEAS_REPORT_IND: {
-      MessageDef *message_p;
-      message_p = itti_alloc_new_message(TASK_RRC_UE, RRC_RAL_MEASUREMENT_REPORT_IND);
-
-      memcpy(&RRC_RAL_MEASUREMENT_REPORT_IND (message_p).threshold,
-             &PHY_MEAS_REPORT_IND(msg_p).threshold,
-             sizeof(RRC_RAL_MEASUREMENT_REPORT_IND (message_p).threshold));
+      case RRC_RAL_CONFIGURE_THRESHOLD_REQ:
+        LOG_D(RRC, "[UE %d] Received %s\n", ue_mod_id, ITTI_MSG_NAME (msg_p));
+        rrc_ue_ral_handle_configure_threshold_request(ue_mod_id, msg_p);
+        break;
 
-      memcpy(&RRC_RAL_MEASUREMENT_REPORT_IND (message_p).link_param,
-             &PHY_MEAS_REPORT_IND(msg_p).link_param,
-             sizeof(RRC_RAL_MEASUREMENT_REPORT_IND (message_p).link_param));
+      case RRC_RAL_CONNECTION_ESTABLISHMENT_REQ:
+        LOG_D(RRC, "[UE %d] Received %s\n", ue_mod_id, ITTI_MSG_NAME (msg_p));
 
-      LOG_D(RRC, "[UE %d] PHY_MEAS_REPORT_IN: sending msg %s to %s \n", ue_mod_id, "RRC_RAL_MEASUREMENT_REPORT_IND", "TASK_RAL_UE");
-      itti_send_msg_to_task(TASK_RAL_UE, instance, message_p);
-      break;
-    }
+        switch (rrc_get_state(ue_mod_id)) {
+          case RRC_STATE_IDLE: {
+            if (rrc_get_sub_state(ue_mod_id) == RRC_SUB_STATE_IDLE_SIB_COMPLETE) {
+              PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, ENB_FLAG_NO, UE_rrc_inst[ue_mod_id].Info[0].rnti, 0, 0, 0);
+              rrc_ue_generate_RRCConnectionRequest(&ctxt, 0);
+              LOG_D(RRC, "not sending connection request\n");
+              rrc_set_sub_state (ue_mod_id, RRC_SUB_STATE_IDLE_CONNECTING);
+            }
 
-    case RRC_RAL_CONFIGURE_THRESHOLD_REQ:
-      rrc_ue_ral_handle_configure_threshold_request(ue_mod_id, msg_p);
-      break;
+            break;
+          }
 
-    case RRC_RAL_CONNECTION_ESTABLISHMENT_REQ:
-      LOG_D(RRC, "[UE %d] Received %s\n", ue_mod_id, ITTI_MSG_NAME (msg_p));
+          case RRC_STATE_INACTIVE:
+          case RRC_STATE_CONNECTED:
+            /* should not happen */
+            LOG_E(RRC, "[UE %d] request %s in RRC state %d\n", ue_mod_id, ITTI_MSG_NAME (msg_p), rrc_get_state(ue_mod_id));
+            break;
 
-      switch (rrc_get_state(ue_mod_id)) {
-      case RRC_STATE_IDLE: {
-        if (rrc_get_sub_state(ue_mod_id) == RRC_SUB_STATE_IDLE_SIB_COMPLETE) {
-          PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, ENB_FLAG_NO, UE_rrc_inst[ue_mod_id].Info[0].rnti, 0, 0, 0);
-          rrc_ue_generate_RRCConnectionRequest(&ctxt, 0);
-          LOG_D(RRC, "not sending connection request\n");
-          rrc_set_sub_state (ue_mod_id, RRC_SUB_STATE_IDLE_CONNECTING);
+          default:
+            LOG_E(RRC, "[UE %d] Invalid RRC state %d\n", ue_mod_id, rrc_get_state(ue_mod_id));
+            break;
         }
 
         break;
-      }
 
-      case RRC_STATE_INACTIVE:
-      case RRC_STATE_CONNECTED:
-        /* should not happen */
-        LOG_E(RRC, "[UE %d] request %s in RRC state %d\n", ue_mod_id, ITTI_MSG_NAME (msg_p), rrc_get_state(ue_mod_id));
+      case RRC_RAL_CONNECTION_RELEASE_REQ:
+        LOG_D(RRC, "[UE %d] Received %s\n", ue_mod_id, ITTI_MSG_NAME (msg_p));
         break;
+#endif
 
       default:
-        LOG_E(RRC, "[UE %d] Invalid RRC state %d\n", ue_mod_id, rrc_get_state(ue_mod_id));
+        LOG_E(RRC, "[UE %d] Received unexpected message %s\n", ue_mod_id, ITTI_MSG_NAME (msg_p));
         break;
-      }
-
-      break;
-
-    case RRC_RAL_CONNECTION_RELEASE_REQ:
-      LOG_D(RRC, "[UE %d] Received %s\n", ue_mod_id, ITTI_MSG_NAME (msg_p));
-      break;
-#endif
-
-    default:
-      LOG_E(RRC, "[UE %d] Received unexpected message %s\n", ue_mod_id, ITTI_MSG_NAME (msg_p));
-      break;
     }
 
     result = itti_free (ITTI_MSG_ORIGIN_ID(msg_p), msg_p);
@@ -5182,28 +4729,24 @@ void *rrc_ue_task( void *args_p )
 /*------------------------------------------------------------------------------*/
 void
 openair_rrc_top_init_ue(
-			int eMBMS_active,
-			char* uecap_xer,
-			uint8_t cba_group_active,
-			uint8_t HO_active
+  int eMBMS_active,
+  char *uecap_xer,
+  uint8_t cba_group_active,
+  uint8_t HO_active
 )
 //-----------------------------------------------------------------------------
 {
-
   module_id_t         module_id;
   OAI_UECapability_t *UECap     = NULL;
   int                 CC_id;
-
   /* for no gcc warnings */
   (void)CC_id;
-
   LOG_D(RRC, "[OPENAIR][INIT] Init function start: NB_UE_INST=%d, NB_eNB_INST=%d\n", NB_UE_INST, NB_eNB_INST);
 
   if (NB_UE_INST > 0) {
-    UE_rrc_inst = (UE_RRC_INST*) malloc16(NB_UE_INST*sizeof(UE_RRC_INST));
+    UE_rrc_inst = (UE_RRC_INST *) malloc16(NB_UE_INST*sizeof(UE_RRC_INST));
     memset (UE_rrc_inst, 0, NB_UE_INST * sizeof(UE_RRC_INST));
     LOG_D(RRC, "ALLOCATE %d Bytes for UE_RRC_INST @ %p\n", (unsigned int)(NB_UE_INST*sizeof(UE_RRC_INST)), UE_rrc_inst);
-
     // fill UE capability
     UECap = fill_ue_capability (uecap_xer);
 
@@ -5213,7 +4756,7 @@ openair_rrc_top_init_ue(
       UE_rrc_inst[module_id].UECapability_size = UECap->sdu_size;
     }
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
     LOG_I(RRC,"[UE] eMBMS active state is %d \n", eMBMS_active);
 
     for (module_id=0; module_id<NB_UE_INST; module_id++) {
@@ -5221,18 +4764,15 @@ openair_rrc_top_init_ue(
     }
 
 #endif
-
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-  /* TODO: this is disabled for the moment because the standard UE
-   * crashes when calling this function.
-   */
-  //init_SL_preconfig(&UE_rrc_inst[module_id],0);
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+    /* TODO: this is disabled for the moment because the standard UE
+     * crashes when calling this function.
+     */
+    //init_SL_preconfig(&UE_rrc_inst[module_id],0);
 #endif
-
   } else {
     UE_rrc_inst = NULL;
   }
-
 }
 
 //-----------------------------------------------------------------------------
@@ -5242,1087 +4782,1029 @@ rrc_top_cleanup_ue(
 )
 //-----------------------------------------------------------------------------
 {
-
   if (NB_UE_INST > 0) free (UE_rrc_inst);
-
-
 }
 
 
 //-----------------------------------------------------------------------------
-uint8_t rrc_ue_generate_SidelinkUEInformation( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index,SL_DestinationInfoList_r12_t  *destinationInfoList, long *discTxResourceReq, SL_TRIGGER_t mode)
-{
-   uint8_t    size=0;
-   uint8_t buffer[100];
-
-   //Generate SidelinkUEInformation
-   if (((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&8192) > 0) && (destinationInfoList != NULL)) {//if SIB18 is available
-      size = do_SidelinkUEInformation(ctxt_pP->module_id, buffer, destinationInfoList, NULL, mode);
-      LOG_I(RRC,"[UE %d][RRC_UE] Frame %d : Logical Channel UL-DCCH, Generating SidelinkUEInformation (bytes%d, eNB %d)\n",
-            ctxt_pP->module_id,ctxt_pP->frame, size, eNB_index);
-      //return size;
-   }
-   if (((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&16384) > 0) && (discTxResourceReq != NULL)) {//if SIB19 is available
-      size = do_SidelinkUEInformation(ctxt_pP->module_id, buffer, NULL, discTxResourceReq, mode);
-      LOG_I(RRC,"[UE %d][RRC_UE] Frame %d : Logical Channel UL-DCCH, Generating SidelinkUEInformation (bytes%d, eNB %d)\n",
-            ctxt_pP->module_id,ctxt_pP->frame, size, eNB_index);
-     //return size;
-   }
-
-   rrc_data_req_ue (
-       ctxt_pP,
-       DCCH,
-       rrc_mui++,
-       SDU_CONFIRM_NO,
-       size,
-       buffer,
-       PDCP_TRANSMISSION_MODE_CONTROL);
-   return size;
+uint8_t rrc_ue_generate_SidelinkUEInformation( const protocol_ctxt_t *const ctxt_pP, const uint8_t eNB_index,LTE_SL_DestinationInfoList_r12_t  *destinationInfoList, long *discTxResourceReq,
+    SL_TRIGGER_t mode) {
+  uint8_t    size=0;
+  uint8_t buffer[100];
+
+  //Generate SidelinkUEInformation
+  if (((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&8192) > 0) && (destinationInfoList != NULL)) {//if SIB18 is available
+    size = do_SidelinkUEInformation(ctxt_pP->module_id, buffer, destinationInfoList, NULL, mode);
+    LOG_I(RRC,"[UE %d][RRC_UE] Frame %d : Logical Channel UL-DCCH, Generating SidelinkUEInformation (bytes%d, eNB %d)\n",
+          ctxt_pP->module_id,ctxt_pP->frame, size, eNB_index);
+    //return size;
+  }
+
+  if (((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&16384) > 0) && (discTxResourceReq != NULL)) {//if SIB19 is available
+    size = do_SidelinkUEInformation(ctxt_pP->module_id, buffer, NULL, discTxResourceReq, mode);
+    LOG_I(RRC,"[UE %d][RRC_UE] Frame %d : Logical Channel UL-DCCH, Generating SidelinkUEInformation (bytes%d, eNB %d)\n",
+          ctxt_pP->module_id,ctxt_pP->frame, size, eNB_index);
+    //return size;
+  }
+
+  rrc_data_req_ue (
+    ctxt_pP,
+    DCCH,
+    rrc_mui++,
+    SDU_CONFIRM_NO,
+    size,
+    buffer,
+    PDCP_TRANSMISSION_MODE_CONTROL);
+  return size;
 }
 
 
 // 3GPP 36.331 (Section 5.10.7.3)
-uint8_t fill_SLSS(const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index, SLSSID_r12_t *slss_id, uint8_t *subframe, uint8_t mode)
-{
-   long syncOffsetIndicator = 0;
-   switch(mode) {
-   case 1: //if triggered by SL discovery announcement and in-coverage
+uint8_t fill_SLSS(const protocol_ctxt_t *const ctxt_pP, const uint8_t eNB_index, LTE_SLSSID_r12_t *slss_id, uint8_t *subframe, uint8_t mode) {
+  long syncOffsetIndicator = 0;
+
+  switch(mode) {
+    case 1: //if triggered by SL discovery announcement and in-coverage
       //discSyncConfig_r12 contains only one element
       *slss_id = UE_rrc_inst[ctxt_pP->module_id].sib19[eNB_index]->discConfig_r12->discSyncConfig_r12->list.array[0]->slssid_r12;
       syncOffsetIndicator = UE_rrc_inst[ctxt_pP->module_id].sib19[eNB_index]->discConfig_r12->discSyncConfig_r12->list.array[0]->syncOffsetIndicator_r12;
       //select subframe for SLSS
       break;
-   case 2: //if triggered by SL communication and in-coverage
 
+    case 2: //if triggered by SL communication and in-coverage
       if (UE_rrc_inst[ctxt_pP->module_id].sib18[eNB_index]->commConfig_r12->commSyncConfig_r12->list.array[0]->txParameters_r12) {
-         *slss_id = UE_rrc_inst[ctxt_pP->module_id].sib18[eNB_index]->commConfig_r12->commSyncConfig_r12->list.array[0]->slssid_r12;
-         syncOffsetIndicator = UE_rrc_inst[ctxt_pP->module_id].sib18[eNB_index]->commConfig_r12->commSyncConfig_r12->list.array[0]->syncOffsetIndicator_r12;
-
-         //if RRC_CONNECTED (Todo: and if networkControlledSyncTx (RRCConnectionReconfiguration) is configured and set to On)
-         if (UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].State == RRC_CONNECTED){
-            //select subframe(s) indicated by syncOffsetIndicator
-            *subframe = syncOffsetIndicator;
-         } else {
-            //select subframe(s) indicated by syncOffsetIndicator within SC period
-         }
-         break;
-   case 3: //if triggered by V2X communication and in coverage
+        *slss_id = UE_rrc_inst[ctxt_pP->module_id].sib18[eNB_index]->commConfig_r12->commSyncConfig_r12->list.array[0]->slssid_r12;
+        syncOffsetIndicator = UE_rrc_inst[ctxt_pP->module_id].sib18[eNB_index]->commConfig_r12->commSyncConfig_r12->list.array[0]->syncOffsetIndicator_r12;
 
-      break;
-   case 4: //if triggered by V2X communication and out-of-coverage
+        //if RRC_CONNECTED (Todo: and if networkControlledSyncTx (RRCConnectionReconfiguration) is configured and set to On)
+        if (UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].State == RRC_CONNECTED) {
+          //select subframe(s) indicated by syncOffsetIndicator
+          *subframe = syncOffsetIndicator;
+        } else {
+          //select subframe(s) indicated by syncOffsetIndicator within SC period
+        }
 
-      break;
-   case 5: //if triggered by V2X communication and UE has GNSS as the synchronization reference
+        break;
 
-   default:
-      //if UE has a selected SyncRefUE
-      //TODO
-      //else (no SyncRefUE Selected)
-      //Todo  if trigger by V2X
-      //else randomly select an SLSSID from the set defined for out-of-coverage
-      *slss_id = 170;//hardcoded
-      //select the subframe according to syncOffsetIndicator1/2 from the preconfigured parameters
-      break;
+      case 3: //if triggered by V2X communication and in coverage
+        break;
+
+      case 4: //if triggered by V2X communication and out-of-coverage
+        break;
+
+      case 5: //if triggered by V2X communication and UE has GNSS as the synchronization reference
+      default:
+        //if UE has a selected SyncRefUE
+        //TODO
+        //else (no SyncRefUE Selected)
+        //Todo  if trigger by V2X
+        //else randomly select an SLSSID from the set defined for out-of-coverage
+        *slss_id = 170;//hardcoded
+        //select the subframe according to syncOffsetIndicator1/2 from the preconfigured parameters
+        break;
       }
-   }
-   return 0;
+  }
+
+  return 0;
 }
 
 
 //-----------------------------------------------------------------------------
 void
 rrc_ue_process_sidelink_radioResourceConfig(
-      module_id_t                      Mod_idP,
-      uint8_t                          eNB_index,
-      SystemInformationBlockType18_r12_t     *sib18,
-      SystemInformationBlockType19_r12_t     *sib19,
-      SL_CommConfig_r12_t* sl_CommConfig,
-      SL_DiscConfig_r12_t* sl_DiscConfig
+  module_id_t                      Mod_idP,
+  uint8_t                          eNB_index,
+  LTE_SystemInformationBlockType18_r12_t     *sib18,
+  LTE_SystemInformationBlockType19_r12_t     *sib19,
+  LTE_SL_CommConfig_r12_t *sl_CommConfig,
+  LTE_SL_DiscConfig_r12_t *sl_DiscConfig
 )
 //-----------------------------------------------------------------------------
 {
-   //process SIB18, configure MAC/PHY for receiving SL communication (RRC_IDLE and RRC_CONNECTED), for transmitting SL communication (RRC_IDLE)
-   if (sib18 != NULL) {
-      if (sib18->commConfig_r12 != NULL) {
-         //do not consider commTXPoolExceptional for the moment
-         //configure PHY/MAC to receive SL communication by using the RPs indicated by commRxPool
-         //sib18->commConfig_r12->commRxPool_r12
-         //TODO
-
-         if (sib18->commConfig_r12->commTxPoolNormalCommon_r12 !=NULL) { //commTxPoolNormalCommon - to transmit SL communication in RRC_IDLE
-            //maybe we don't consider this case for the moment since UE will immediately establish a RRC connection after receiving SIB messages
-            //configure PHY/MAC to transmit SL communication using the RPs indicated by the first entry in commTxPoolNormalCommon
-            //SL_CommResourcePool_r12_t sl_CommResourcePool = sib18->commConfig_r12->commTxPoolNormalCommon_r12->list.array[0];
-         }
+  //process SIB18, configure MAC/PHY for receiving SL communication (RRC_IDLE and RRC_CONNECTED), for transmitting SL communication (RRC_IDLE)
+  if (sib18 != NULL) {
+    if (sib18->commConfig_r12 != NULL) {
+      //do not consider commTXPoolExceptional for the moment
+      //configure PHY/MAC to receive SL communication by using the RPs indicated by commRxPool
+      //sib18->commConfig_r12->commRxPool_r12
+      //TODO
+      if (sib18->commConfig_r12->commTxPoolNormalCommon_r12 !=NULL) { //commTxPoolNormalCommon - to transmit SL communication in RRC_IDLE
+        //maybe we don't consider this case for the moment since UE will immediately establish a RRC connection after receiving SIB messages
+        //configure PHY/MAC to transmit SL communication using the RPs indicated by the first entry in commTxPoolNormalCommon
+        //SL_CommResourcePool_r12_t sl_CommResourcePool = sib18->commConfig_r12->commTxPoolNormalCommon_r12->list.array[0];
       }
-   }
-
-   //process SIB19, configure MAC/PHY for receiving SL discovery (RRC_IDLE and RRC_CONNECTED), for transmitting SL discovery (RRC_IDLE)
-   if (sib19 != NULL) {
-      //to receive non-PS related discovery announcements (discRxPool)
-      //sib19->discConfig_r12->discRxPool_r12;
-
-      //to receive PS related discovery announcements (discRxPoolPS)
-      //sib19->ext1->discConfigPS_13->discRxPoolPS_r13;
-
-      //to transmit non-PS related discovery in RRC_IDLE
-      //sib19->discConfig_r12->discTxPoolCommon_r12;
-
-      //to transmit PS related discovery in RRC_IDLE
-      //sib19->ext1->discConfigPS_13->discTxPoolPS_Common_r13;
-   }
-
-   //process sl_CommConfig, configure MAC/PHY for transmitting SL communication (RRC_CONNECTED)
-   if (sl_CommConfig != NULL) {
-
-      if (sl_CommConfig->commTxResources_r12 != NULL) {
-         switch (sl_CommConfig->commTxResources_r12->present){
-         case SL_CommConfig_r12__commTxResources_r12_PR_setup:
-            if (sl_CommConfig->commTxResources_r12->choice.setup.present == SL_CommConfig_r12__commTxResources_r12__setup_PR_scheduled_r12 ){
-
-               LOG_I(RRC,"[UE %d][RRC_UE] scheduled resource for SL, sl_RNTI size %lu  \n",
-                     Mod_idP, sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.sl_RNTI_r12.size );
-               LOG_I(RRC,"[UE %d][RRC_UE] scheduled resource for SL, sl_RNTI buf 0x%p \n",
-                     Mod_idP, sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.sl_RNTI_r12.buf );
-               LOG_I(RRC,"[UE %d][RRC_UE] scheduled resource for SL, Mac_MainConfig_r12.retx_BSR_TimerSL %ld \n",
-                     Mod_idP, sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.mac_MainConfig_r12.retx_BSR_TimerSL );
-               LOG_I(RRC,"[UE %d][RRC_UE] scheduled resource for SL, sc_CommTxConfig %ld \n",
-                     Mod_idP, sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.mac_MainConfig_r12.retx_BSR_TimerSL );
-               //configure scheduled resource for SL
-               //TODO
-            } else if (sl_CommConfig->commTxResources_r12->choice.setup.present == SL_CommConfig_r12__commTxResources_r12__setup_PR_ue_Selected_r12){
-               //configure dedicated resources (commTxPoolNormalDedicated) for SL from which UE can autonomously select
-               //sl_CommConfig->commTxResources_r12->choice.setup.choice.ue_Selected_r12.commTxPoolNormalDedicated_r12;
-
-               //for the moment, only pass the first entry (e.g., do not consider priorityList in commTxPoolNormalDedicated (3GPP 36.331 Section 5.10.4 1>2>3>4))
-               //sl_CommConfig->commTxResources_r12->choice.setup.choice.ue_Selected_r12.commTxPoolNormalDedicated_r12.poolToAddModList_r12->list.array[0];
-            } else {
-               //SL_CommConfig_r12__commTxResources_r12__setup_PR_NOTHING /* No components present */
-            }
-            break;
+    }
+  }
 
-         case SL_CommConfig_r12__commTxResources_r12_PR_release:
-            //release dedicated resources for SL communication
-            break;
+  //process SIB19, configure MAC/PHY for receiving SL discovery (RRC_IDLE and RRC_CONNECTED), for transmitting SL discovery (RRC_IDLE)
+  if (sib19 != NULL) {
+    //to receive non-PS related discovery announcements (discRxPool)
+    //sib19->discConfig_r12->discRxPool_r12;
+    //to receive PS related discovery announcements (discRxPoolPS)
+    //sib19->ext1->discConfigPS_13->discRxPoolPS_r13;
+    //to transmit non-PS related discovery in RRC_IDLE
+    //sib19->discConfig_r12->discTxPoolCommon_r12;
+    //to transmit PS related discovery in RRC_IDLE
+    //sib19->ext1->discConfigPS_13->discTxPoolPS_Common_r13;
+  }
 
-         case SL_CommConfig_r12__commTxResources_r12_PR_NOTHING: /* No components present */
-            break;
+  //process sl_CommConfig, configure MAC/PHY for transmitting SL communication (RRC_CONNECTED)
+  if (sl_CommConfig != NULL) {
+    if (sl_CommConfig->commTxResources_r12 != NULL) {
+      switch (sl_CommConfig->commTxResources_r12->present) {
+        case LTE_SL_CommConfig_r12__commTxResources_r12_PR_setup:
+          if (sl_CommConfig->commTxResources_r12->choice.setup.present == LTE_SL_CommConfig_r12__commTxResources_r12__setup_PR_scheduled_r12 ) {
+            LOG_I(RRC,"[UE %d][RRC_UE] scheduled resource for SL, sl_RNTI size %lu  \n",
+                  Mod_idP, sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.sl_RNTI_r12.size );
+            LOG_I(RRC,"[UE %d][RRC_UE] scheduled resource for SL, sl_RNTI buf 0x%p \n",
+                  Mod_idP, sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.sl_RNTI_r12.buf );
+            LOG_I(RRC,"[UE %d][RRC_UE] scheduled resource for SL, Mac_MainConfig_r12.retx_BSR_TimerSL %ld \n",
+                  Mod_idP, sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.mac_MainConfig_r12.retx_BSR_TimerSL );
+            LOG_I(RRC,"[UE %d][RRC_UE] scheduled resource for SL, sc_CommTxConfig %ld \n",
+                  Mod_idP, sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.mac_MainConfig_r12.retx_BSR_TimerSL );
+            //configure scheduled resource for SL
+            //TODO
+          } else if (sl_CommConfig->commTxResources_r12->choice.setup.present == LTE_SL_CommConfig_r12__commTxResources_r12__setup_PR_ue_Selected_r12) {
+            //configure dedicated resources (commTxPoolNormalDedicated) for SL from which UE can autonomously select
+            //sl_CommConfig->commTxResources_r12->choice.setup.choice.ue_Selected_r12.commTxPoolNormalDedicated_r12;
+            //for the moment, only pass the first entry (e.g., do not consider priorityList in commTxPoolNormalDedicated (3GPP 36.331 Section 5.10.4 1>2>3>4))
+            //sl_CommConfig->commTxResources_r12->choice.setup.choice.ue_Selected_r12.commTxPoolNormalDedicated_r12.poolToAddModList_r12->list.array[0];
+          } else {
+            //SL_CommConfig_r12__commTxResources_r12__setup_PR_NOTHING /* No components present */
+          }
 
-         default:
-            break;
-         }
+          break;
+
+        case LTE_SL_CommConfig_r12__commTxResources_r12_PR_release:
+          //release dedicated resources for SL communication
+          break;
+
+        case LTE_SL_CommConfig_r12__commTxResources_r12_PR_NOTHING: /* No components present */
+          break;
+
+        default:
+          break;
       }
+    }
+  }
 
-   }
-
-   //process sl_DiscConfig, configure MAC/PHY for transmitting SL discovery announcements (RRC_CONNECTED)
-   if (sl_DiscConfig != NULL) {
-      //dedicated resources for transmitting non-PS related discovery
-      if (sl_DiscConfig->discTxResources_r12 != NULL) {
-
-         switch (sl_DiscConfig->discTxResources_r12->present) {
-         case SL_DiscConfig_r12__discTxResources_r12_PR_setup:
-            if (sl_DiscConfig->discTxResources_r12->choice.setup.present == SL_DiscConfig_r12__discTxResources_r12__setup_PR_scheduled_r12) {
-               //sl_DiscConfig->discTxResources_r12->choice.setup.choice.scheduled_r12.discHoppingConfig_r12;
-               //sl_DiscConfig->discTxResources_r12->choice.setup.choice.scheduled_r12.discTF_IndexList_r12;
-               //sl_DiscConfig->discTxResources_r12->choice.setup.choice.scheduled_r12.discTxConfig_r12;
-            } else if (sl_DiscConfig->discTxResources_r12->choice.setup.present == SL_DiscConfig_r12__discTxResources_r12__setup_PR_ue_Selected_r12) {
-               //sl_DiscConfig->discTxResources_r12->choice.setup.choice.ue_Selected_r12.discTxPoolDedicated_r12;
-            } else {
-               //SL_DiscConfig_r12__discTxResources_r12__setup_PR_NOTHING,   /* No components present */
-            }
-            break;
-         case SL_DiscConfig_r12__discTxResources_r12_PR_release:
-            //release dedicated resources for SL discovery
-            break;
-         case SL_DiscConfig_r12__discTxResources_r12_PR_NOTHING: /* No components present */
-            break;
-         default:
-            break;
-         }
+  //process sl_DiscConfig, configure MAC/PHY for transmitting SL discovery announcements (RRC_CONNECTED)
+  if (sl_DiscConfig != NULL) {
+    //dedicated resources for transmitting non-PS related discovery
+    if (sl_DiscConfig->discTxResources_r12 != NULL) {
+      switch (sl_DiscConfig->discTxResources_r12->present) {
+        case LTE_SL_DiscConfig_r12__discTxResources_r12_PR_setup:
+          if (sl_DiscConfig->discTxResources_r12->choice.setup.present == LTE_SL_DiscConfig_r12__discTxResources_r12__setup_PR_scheduled_r12) {
+            //sl_DiscConfig->discTxResources_r12->choice.setup.choice.scheduled_r12.discHoppingConfig_r12;
+            //sl_DiscConfig->discTxResources_r12->choice.setup.choice.scheduled_r12.discTF_IndexList_r12;
+            //sl_DiscConfig->discTxResources_r12->choice.setup.choice.scheduled_r12.discTxConfig_r12;
+          } else if (sl_DiscConfig->discTxResources_r12->choice.setup.present == LTE_SL_DiscConfig_r12__discTxResources_r12__setup_PR_ue_Selected_r12) {
+            //sl_DiscConfig->discTxResources_r12->choice.setup.choice.ue_Selected_r12.discTxPoolDedicated_r12;
+          } else {
+            //SL_DiscConfig_r12__discTxResources_r12__setup_PR_NOTHING,   /* No components present */
+          }
+
+          break;
+
+        case LTE_SL_DiscConfig_r12__discTxResources_r12_PR_release:
+          //release dedicated resources for SL discovery
+          break;
+
+        case LTE_SL_DiscConfig_r12__discTxResources_r12_PR_NOTHING: /* No components present */
+          break;
 
+        default:
+          break;
       }
-      //dedicated resources for transmitting PS related discovery
-      if (sl_DiscConfig->ext2->discTxResourcesPS_r13 != NULL){
-         switch (sl_DiscConfig->ext2->discTxResourcesPS_r13->present) {
-         case SL_DiscConfig_r12__ext2__discTxResourcesPS_r13_PR_setup:
-            if (sl_DiscConfig->ext2->discTxResourcesPS_r13->choice.setup.present == SL_DiscConfig_r12__ext2__discTxResourcesPS_r13__setup_PR_scheduled_r13) {
-               //sl_DiscConfig->ext2->discTxResourcesPS_r13->choice.setup.choice.scheduled_r13.discHoppingConfig_r13;
-               //sl_DiscConfig->ext2->discTxResourcesPS_r13->choice.setup.choice.scheduled_r13.discTxConfig_r13
-            } else if (sl_DiscConfig->ext2->discTxResourcesPS_r13->choice.setup.present == SL_DiscConfig_r12__ext2__discTxResourcesPS_r13__setup_PR_ue_Selected_r13) {
-               //sl_DiscConfig->ext2->discTxResourcesPS_r13->choice.setup.choice.ue_Selected_r13.discTxPoolPS_Dedicated_r13;
-            } else {
-               //SL_DiscConfig_r12__ext2__discTxResourcesPS_r13__setup_PR_NOTHING, /* No components present */
-            }
+    }
 
-            break;
-         case SL_DiscConfig_r12__ext2__discTxResourcesPS_r13_PR_release:
-            break;
-         case SL_DiscConfig_r12__ext2__discTxResourcesPS_r13_PR_NOTHING:
-            /* No components present */
-            break;
-         default:
-            break;
-         }
+    //dedicated resources for transmitting PS related discovery
+    if (sl_DiscConfig->ext2->discTxResourcesPS_r13 != NULL) {
+      switch (sl_DiscConfig->ext2->discTxResourcesPS_r13->present) {
+        case LTE_SL_DiscConfig_r12__ext2__discTxResourcesPS_r13_PR_setup:
+          if (sl_DiscConfig->ext2->discTxResourcesPS_r13->choice.setup.present == LTE_SL_DiscConfig_r12__ext2__discTxResourcesPS_r13__setup_PR_scheduled_r13) {
+            //sl_DiscConfig->ext2->discTxResourcesPS_r13->choice.setup.choice.scheduled_r13.discHoppingConfig_r13;
+            //sl_DiscConfig->ext2->discTxResourcesPS_r13->choice.setup.choice.scheduled_r13.discTxConfig_r13
+          } else if (sl_DiscConfig->ext2->discTxResourcesPS_r13->choice.setup.present == LTE_SL_DiscConfig_r12__ext2__discTxResourcesPS_r13__setup_PR_ue_Selected_r13) {
+            //sl_DiscConfig->ext2->discTxResourcesPS_r13->choice.setup.choice.ue_Selected_r13.discTxPoolPS_Dedicated_r13;
+          } else {
+            //SL_DiscConfig_r12__ext2__discTxResourcesPS_r13__setup_PR_NOTHING, /* No components present */
+          }
+
+          break;
+
+        case LTE_SL_DiscConfig_r12__ext2__discTxResourcesPS_r13_PR_release:
+          break;
+
+        case LTE_SL_DiscConfig_r12__ext2__discTxResourcesPS_r13_PR_NOTHING:
+          /* No components present */
+          break;
+
+        default:
+          break;
       }
-   }
+    }
+  }
 }
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 //-----------------------------------------------------------
 void
-rrc_control_socket_init(){
-
-   struct sockaddr_in rrc_ctrl_socket_addr;
-   pthread_attr_t     attr;
-   struct sched_param sched_param;
-   int optval; // flag value for setsockopt
-   //int n; // message byte size
+rrc_control_socket_init() {
+  struct sockaddr_in rrc_ctrl_socket_addr;
+  pthread_attr_t     attr;
+  struct sched_param sched_param;
+  int optval; // flag value for setsockopt
+  //int n; // message byte size
+  // create the control socket
+  ctrl_sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
+
+  if (ctrl_sock_fd == -1) {
+    LOG_E(RRC,"[rrc_control_socket_init] :Error opening socket %d (%d:%s)\n",ctrl_sock_fd,errno, strerror(errno));
+    exit(EXIT_FAILURE);
+  }
 
+  //   if (ctrl_sock_fd < 0)
+  //      error("ERROR: Failed on opening socket");
+  optval = 1;
+  setsockopt(ctrl_sock_fd, SOL_SOCKET, SO_REUSEADDR,
+             (const void *)&optval , sizeof(int));
+  //build the server's  address
+  bzero((char *) &rrc_ctrl_socket_addr, sizeof(rrc_ctrl_socket_addr));
+  rrc_ctrl_socket_addr.sin_family = AF_INET;
+  rrc_ctrl_socket_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+  rrc_ctrl_socket_addr.sin_port = htons(CONTROL_SOCKET_PORT_NO);
+
+  // associate the parent socket with a port
+  if (bind(ctrl_sock_fd, (struct sockaddr *) &rrc_ctrl_socket_addr,
+           sizeof(rrc_ctrl_socket_addr)) < 0) {
+    LOG_E(RRC,"[rrc_control_socket_init] ERROR: Failed on binding the socket\n");
+    exit(1);
+  }
 
-   // create the control socket
-   ctrl_sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
-   if (ctrl_sock_fd == -1) {
-      LOG_E(RRC,"[rrc_control_socket_init] :Error opening socket %d (%d:%s)\n",ctrl_sock_fd,errno, strerror(errno));
-      exit(EXIT_FAILURE);
-   }
-   //   if (ctrl_sock_fd < 0)
-   //      error("ERROR: Failed on opening socket");
-   optval = 1;
-   setsockopt(ctrl_sock_fd, SOL_SOCKET, SO_REUSEADDR,
-         (const void *)&optval , sizeof(int));
-
-   //build the server's  address
-   bzero((char *) &rrc_ctrl_socket_addr, sizeof(rrc_ctrl_socket_addr));
-   rrc_ctrl_socket_addr.sin_family = AF_INET;
-   rrc_ctrl_socket_addr.sin_addr.s_addr = htonl(INADDR_ANY);
-   rrc_ctrl_socket_addr.sin_port = htons(CONTROL_SOCKET_PORT_NO);
-   // associate the parent socket with a port
-   if (bind(ctrl_sock_fd, (struct sockaddr *) &rrc_ctrl_socket_addr,
-         sizeof(rrc_ctrl_socket_addr)) < 0) {
-      LOG_E(RRC,"[rrc_control_socket_init] ERROR: Failed on binding the socket\n");
-      exit(1);
-   }
-   //create thread to listen to incoming packets
-   if (pthread_attr_init(&attr) != 0) {
-      LOG_E(RRC, "[rrc_control_socket_init]Failed to initialize pthread attribute for ProSe -> RRC communication (%d:%s)\n",
-            errno, strerror(errno));
-      exit(EXIT_FAILURE);
-   }
+  //create thread to listen to incoming packets
+  if (pthread_attr_init(&attr) != 0) {
+    LOG_E(RRC, "[rrc_control_socket_init]Failed to initialize pthread attribute for ProSe -> RRC communication (%d:%s)\n",
+          errno, strerror(errno));
+    exit(EXIT_FAILURE);
+  }
 
-   sched_param.sched_priority = 10;
+  sched_param.sched_priority = 10;
+  pthread_attr_setschedpolicy(&attr, SCHED_RR);
+  pthread_attr_setschedparam(&attr, &sched_param);
+  pthread_t rrc_control_socket_thread;
 
-   pthread_attr_setschedpolicy(&attr, SCHED_RR);
-   pthread_attr_setschedparam(&attr, &sched_param);
+  if (pthread_create(&rrc_control_socket_thread, &attr, rrc_control_socket_thread_fct, NULL) != 0) {
+    LOG_E(RRC, "[rrc_control_socket_init]Failed to create new thread for RRC/ProSeApp communication (%d:%s)\n",
+          errno, strerror(errno));
+    exit(EXIT_FAILURE);
+  }
 
-   pthread_t rrc_control_socket_thread;
+  pthread_setname_np( rrc_control_socket_thread, "RRC Control Socket" );
+}
 
-   if (pthread_create(&rrc_control_socket_thread, &attr, rrc_control_socket_thread_fct, NULL) != 0) {
-      LOG_E(RRC, "[rrc_control_socket_init]Failed to create new thread for RRC/ProSeApp communication (%d:%s)\n",
-            errno, strerror(errno));
+//--------------------------------------------------------
+void *rrc_control_socket_thread_fct(void *arg) {
+  int prose_addr_len;
+  char send_buf[BUFSIZE];
+  char receive_buf[BUFSIZE];
+  //int optval;
+  int n;
+  struct sidelink_ctrl_element *sl_ctrl_msg_recv = NULL;
+  struct sidelink_ctrl_element *sl_ctrl_msg_send = NULL;
+  uint32_t sourceL2Id, groupL2Id, destinationL2Id;
+  module_id_t         module_id = 0; //hardcoded for testing only
+  uint8_t type;
+  UE_RRC_INST *UE  = NULL;
+  protocol_ctxt_t ctxt;
+  struct LTE_RLC_Config                  *DRB_rlc_config                   = NULL;
+  struct LTE_PDCP_Config                 *DRB_pdcp_config                  = NULL;
+  struct LTE_PDCP_Config__rlc_UM         *PDCP_rlc_UM                      = NULL;
+  struct LTE_LogicalChannelConfig        *DRB_lchan_config                 = NULL;
+  struct LTE_LogicalChannelConfig__ul_SpecificParameters  *DRB_ul_SpecificParameters = NULL;
+  long                               *logicalchannelgroup_drb          = NULL;
+  int j = 0;
+  int i = 0;
+  //from the main program, listen for the incoming messages from control socket (ProSe App)
+  prose_addr_len = sizeof(prose_app_addr);
+
+  //int enable_notification = 1;
+  while (1) {
+    LOG_I(RRC,"Listening to incoming connection from ProSe App \n");
+    // receive a message from ProSe App
+    memset(receive_buf, 0, BUFSIZE);
+    n = recvfrom(ctrl_sock_fd, receive_buf, BUFSIZE, 0,
+                 (struct sockaddr *) &prose_app_addr, (socklen_t *)&prose_addr_len);
+
+    if (n < 0) {
+      LOG_E(RRC, "ERROR: Failed to receive from ProSe App\n");
       exit(EXIT_FAILURE);
-   }
-
-   pthread_setname_np( rrc_control_socket_thread, "RRC Control Socket" );
+    }
 
-}
+    //TODO: should store the address of ProSeApp [UE_rrc_inst] to be able to send UE state notification to the App
+    //sl_ctrl_msg_recv = (struct sidelink_ctrl_element *) receive_buf;
+    sl_ctrl_msg_recv = calloc(1, sizeof(struct sidelink_ctrl_element));
+    memcpy((void *)sl_ctrl_msg_recv, (void *)receive_buf, sizeof(struct sidelink_ctrl_element));
 
-//--------------------------------------------------------
-void *rrc_control_socket_thread_fct(void *arg)
-{
+    //process the message
+    switch (sl_ctrl_msg_recv->type) {
+      case SESSION_INIT_REQ:
+        if (LOG_DEBUGFLAG(DEBUG_CTRLSOCKET)) {
+          LOG_UI(RRC,"Received SessionInitializationRequest on socket from ProSe App (msg type: %d)\n", sl_ctrl_msg_recv->type);
+        }
 
-   int prose_addr_len;
-   char send_buf[BUFSIZE];
-   char receive_buf[BUFSIZE];
-   //int optval;
-   int n;
-   struct sidelink_ctrl_element *sl_ctrl_msg_recv = NULL;
-   struct sidelink_ctrl_element *sl_ctrl_msg_send = NULL;
-   uint32_t sourceL2Id, groupL2Id, destinationL2Id;
-   module_id_t         module_id = 0; //hardcoded for testing only
-   uint8_t type;
-   UE_RRC_INST *UE  = NULL;
-   protocol_ctxt_t ctxt;
-   struct RLC_Config                  *DRB_rlc_config                   = NULL;
-   struct PDCP_Config                 *DRB_pdcp_config                  = NULL;
-   struct PDCP_Config__rlc_UM         *PDCP_rlc_UM                      = NULL;
-   struct LogicalChannelConfig        *DRB_lchan_config                 = NULL;
-   struct LogicalChannelConfig__ul_SpecificParameters  *DRB_ul_SpecificParameters = NULL;
-   long                               *logicalchannelgroup_drb          = NULL;
-   int j = 0;
-   int i = 0;
-
-   //from the main program, listen for the incoming messages from control socket (ProSe App)
-   prose_addr_len = sizeof(prose_app_addr);
-   //int enable_notification = 1;
-   while (1) {
-      LOG_I(RRC,"Listening to incoming connection from ProSe App \n");
-      // receive a message from ProSe App
-      memset(receive_buf, 0, BUFSIZE);
-      n = recvfrom(ctrl_sock_fd, receive_buf, BUFSIZE, 0,
-            (struct sockaddr *) &prose_app_addr, (socklen_t *)&prose_addr_len);
-      if (n < 0){
-         LOG_E(RRC, "ERROR: Failed to receive from ProSe App\n");
-         exit(EXIT_FAILURE);
-      }
-      //TODO: should store the address of ProSeApp [UE_rrc_inst] to be able to send UE state notification to the App
+        //TODO: get SL_UE_STATE from lower layer
+        LOG_I(RRC,"Send UEStateInformation to ProSe App \n");
+        memset(send_buf, 0, BUFSIZE);
+        sl_ctrl_msg_send = calloc(1, sizeof(struct sidelink_ctrl_element));
+        sl_ctrl_msg_send->type = UE_STATUS_INFO;
+        sl_ctrl_msg_send->sidelinkPrimitive.ue_state = UE_STATE_OFF_NETWORK; //off-network
+        memcpy((void *)send_buf, (void *)sl_ctrl_msg_send, sizeof(struct sidelink_ctrl_element));
+        free(sl_ctrl_msg_send);
+        prose_addr_len = sizeof(prose_app_addr);
+        n = sendto(ctrl_sock_fd, (char *)send_buf, sizeof(struct sidelink_ctrl_element), 0, (struct sockaddr *)&prose_app_addr, prose_addr_len);
+
+        if (n < 0) {
+          LOG_E(RRC, "ERROR: Failed to send to ProSe App\n");
+          exit(EXIT_FAILURE);
+        }
 
-      //sl_ctrl_msg_recv = (struct sidelink_ctrl_element *) receive_buf;
-      sl_ctrl_msg_recv = calloc(1, sizeof(struct sidelink_ctrl_element));
-      memcpy((void *)sl_ctrl_msg_recv, (void *)receive_buf, sizeof(struct sidelink_ctrl_element));
+        if (LOG_DEBUGFLAG(DEBUG_CTRLSOCKET)) {
+          struct sidelink_ctrl_element *ptr_ctrl_msg = NULL;
+          ptr_ctrl_msg = (struct sidelink_ctrl_element *) send_buf;
+          LOG_UI(RRC,"[UEStateInformation] msg type: %d\n",ptr_ctrl_msg->type);
+          LOG_UI(RRC,"[UEStateInformation] UE state: %d\n",ptr_ctrl_msg->sidelinkPrimitive.ue_state);
+        }
 
-      //process the message
-      switch (sl_ctrl_msg_recv->type) {
-      case SESSION_INIT_REQ:
-         if (LOG_DEBUGFLAG(DEBUG_CTRLSOCKET)){
-           LOG_UI(RRC,"Received SessionInitializationRequest on socket from ProSe App (msg type: %d)\n", sl_ctrl_msg_recv->type);
-         }
-         //TODO: get SL_UE_STATE from lower layer
-
-         LOG_I(RRC,"Send UEStateInformation to ProSe App \n");
-         memset(send_buf, 0, BUFSIZE);
-
-         sl_ctrl_msg_send = calloc(1, sizeof(struct sidelink_ctrl_element));
-         sl_ctrl_msg_send->type = UE_STATUS_INFO;
-         sl_ctrl_msg_send->sidelinkPrimitive.ue_state = UE_STATE_OFF_NETWORK; //off-network
-         memcpy((void *)send_buf, (void *)sl_ctrl_msg_send, sizeof(struct sidelink_ctrl_element));
-         free(sl_ctrl_msg_send);
-
-         prose_addr_len = sizeof(prose_app_addr);
-         n = sendto(ctrl_sock_fd, (char *)send_buf, sizeof(struct sidelink_ctrl_element), 0, (struct sockaddr *)&prose_app_addr, prose_addr_len);
-         if (n < 0) {
-            LOG_E(RRC, "ERROR: Failed to send to ProSe App\n");
-            exit(EXIT_FAILURE);
-         }
-
-         if (LOG_DEBUGFLAG(DEBUG_CTRLSOCKET)){
-           struct sidelink_ctrl_element *ptr_ctrl_msg = NULL;
-           ptr_ctrl_msg = (struct sidelink_ctrl_element *) send_buf;
-           LOG_UI(RRC,"[UEStateInformation] msg type: %d\n",ptr_ctrl_msg->type);
-           LOG_UI(RRC,"[UEStateInformation] UE state: %d\n",ptr_ctrl_msg->sidelinkPrimitive.ue_state);
-         }
-         /*  if (enable_notification > 0) {
-              //create thread to send status notification (for testing purpose, status notification will be sent e.g., every 20 seconds)
-              pthread_t notification_thread;
-              if( pthread_create( &notification_thread , NULL ,  send_UE_status_notification , (void*) &sockfd) < 0)
-                 error("ERROR: could not create thread");
-           }
-           enable_notification = 0;
-          */
-         break;
+        /*  if (enable_notification > 0) {
+             //create thread to send status notification (for testing purpose, status notification will be sent e.g., every 20 seconds)
+             pthread_t notification_thread;
+             if( pthread_create( &notification_thread , NULL ,  send_UE_status_notification , (void*) &sockfd) < 0)
+                error("ERROR: could not create thread");
+          }
+          enable_notification = 0;
+         */
+        break;
 
       case GROUP_COMMUNICATION_ESTABLISH_REQ:
-         sourceL2Id = sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.sourceL2Id;
-         groupL2Id = sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.groupL2Id;
-
-         if (LOG_DEBUGFLAG(DEBUG_CTRLSOCKET)){
-           LOG_UI(RRC,"[GroupCommunicationEstablishReq] Received on socket from ProSe App (msg type: %d)\n",sl_ctrl_msg_recv->type);
-           LOG_UI(RRC,"[GroupCommunicationEstablishReq] source Id: 0x%08x\n",sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.sourceL2Id);
-           LOG_UI(RRC,"[GroupCommunicationEstablishReq] group Id: 0x%08x\n",sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.groupL2Id);
-           LOG_UI(RRC,"[GroupCommunicationEstablishReq] group IP Address: " IPV4_ADDR "\n",IPV4_ADDR_FORMAT(sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.groupIpAddress));
-         }
-
-         //store sourceL2Id/groupL2Id
-         UE_rrc_inst[module_id].sourceL2Id = sourceL2Id;
-         UE_rrc_inst[module_id].groupL2Id = groupL2Id;
-         j = 0;
-         i = 0;
-         for (i=0; i< MAX_NUM_DEST; i++) {
-            if ((UE_rrc_inst[module_id].destinationList[i] == 0) && (j == 0)) j = i+1;
-            if (UE_rrc_inst[module_id].destinationList[i] == groupL2Id) break; //group already exists!
-         }
-         if ((i == MAX_NUM_DEST) && (j > 0))  UE_mac_inst[module_id].destinationList[j-1] = groupL2Id;
-
-         // configure lower layers PDCP/MAC/PHY for this communication
-         //Establish a new RBID/LCID for this communication
-         // Establish a SLRB (using DRB 3 for now)
-         UE  = &UE_rrc_inst[module_id];
-         PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, 0, ENB_FLAG_NO, 0x1234, 0, 0,0);
-
-         UE->DRB_config[0][0] = CALLOC(1,sizeof(struct DRB_ToAddMod));
-         UE->DRB_config[0][0]->eps_BearerIdentity = CALLOC(1, sizeof(long));
-         UE->DRB_config[0][0]->drb_Identity =  3;
-         UE->DRB_config[0][0]->eps_BearerIdentity = CALLOC(1, sizeof(long));
-         // allowed value 5..15, value : x+4
-         *(UE->DRB_config[0][0]->eps_BearerIdentity) = 3;
-         UE->DRB_config[0][0]->logicalChannelIdentity = CALLOC(1, sizeof(long));
-         *(UE->DRB_config[0][0]->logicalChannelIdentity) = UE->DRB_config[0][0]->drb_Identity; //(long) (ue_context_pP->ue_context.e_rab[i].param.e_rab_id + 2); // value : x+2
-
-         DRB_rlc_config                   = CALLOC(1,sizeof(struct RLC_Config));
-         DRB_pdcp_config                  = CALLOC(1,sizeof(struct PDCP_Config));
-         PDCP_rlc_UM                      = CALLOC(1,sizeof(struct PDCP_Config__rlc_UM));
-         DRB_lchan_config                 = CALLOC(1,sizeof(struct LogicalChannelConfig));
-         DRB_ul_SpecificParameters                                         = CALLOC(1, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
-         logicalchannelgroup_drb          = CALLOC(1, sizeof(long));
-
-         DRB_rlc_config->present = RLC_Config_PR_um_Bi_Directional;
-         DRB_rlc_config->choice.um_Bi_Directional.ul_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
-         DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
-         DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = T_Reordering_ms35;
-         UE->DRB_config[0][0]->rlc_Config = DRB_rlc_config;
-
-         DRB_pdcp_config = CALLOC(1, sizeof(*DRB_pdcp_config));
-         UE->DRB_config[0][0]->pdcp_Config = DRB_pdcp_config;
-         DRB_pdcp_config->discardTimer = CALLOC(1, sizeof(long));
-         *DRB_pdcp_config->discardTimer = PDCP_Config__discardTimer_infinity;
-         DRB_pdcp_config->rlc_AM = NULL;
-         DRB_pdcp_config->rlc_UM = NULL;
-
-         /* avoid gcc warnings */
-         (void)PDCP_rlc_UM;
-
-         DRB_pdcp_config->rlc_UM = PDCP_rlc_UM;
-         PDCP_rlc_UM->pdcp_SN_Size = PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits;
-         DRB_pdcp_config->headerCompression.present = PDCP_Config__headerCompression_PR_notUsed;
-
-         UE->DRB_config[0][0]->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 = 12;    // lower priority than srb1, srb2 and other dedicated bearer
-         DRB_ul_SpecificParameters->prioritisedBitRate =LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_kBps8 ;
-         //LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
-         DRB_ul_SpecificParameters->bucketSizeDuration =
-               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 = 1;
-         DRB_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup_drb;
-
-         UE->DRB_configList = CALLOC(1,sizeof(DRB_ToAddModList_t));
-         ASN_SEQUENCE_ADD(&UE->DRB_configList->list,UE->DRB_config[0][0]);
-
-         rrc_pdcp_config_asn1_req(&ctxt,
-               (SRB_ToAddModList_t *) NULL,
-               UE->DRB_configList,
-               (DRB_ToReleaseList_t*) NULL,
-               0xff, NULL, NULL, NULL
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-               , (PMCH_InfoList_r9_t *) NULL
-#endif
-               ,NULL);
-
-
-         rrc_rlc_config_asn1_req(&ctxt,
-               (SRB_ToAddModList_t*)NULL,
-               UE->DRB_configList,
-               (DRB_ToReleaseList_t*)NULL
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-               ,(PMCH_InfoList_r9_t *)NULL
-               , 0, 0
-#endif
-         );
-
-         rrc_rlc_config_asn1_req(&ctxt,
-               (SRB_ToAddModList_t*)NULL,
-               UE->DRB_configList,
-               (DRB_ToReleaseList_t*)NULL
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-               ,(PMCH_InfoList_r9_t *)NULL
-               , sourceL2Id, groupL2Id
-#endif
-         );
-
-
-         //configure MAC with sourceL2Id/groupL2ID
-         rrc_mac_config_req_ue(module_id,0,0, //eNB_index =0
-               (RadioResourceConfigCommonSIB_t *)NULL,
-               (struct PhysicalConfigDedicated *)NULL,
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-               (SCellToAddMod_r10_t *)NULL,
-               //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
-#endif
-               (MeasObjectToAddMod_t **)NULL,
-               (MAC_MainConfig_t *)NULL,
-               3, //LCID
-               (struct LogicalChannelConfig *)NULL,
-               (MeasGapConfig_t *)NULL,
-               (TDD_Config_t *)NULL,
-               (MobilityControlInfo_t *)NULL,
-               NULL,
-               NULL,
-               NULL,
-               NULL,
-               NULL,
-               NULL
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-               ,0,
-               (MBSFN_AreaInfoList_r9_t *)NULL,
-               (PMCH_InfoList_r9_t *)NULL
+        sourceL2Id = sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.sourceL2Id;
+        groupL2Id = sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.groupL2Id;
+
+        if (LOG_DEBUGFLAG(DEBUG_CTRLSOCKET)) {
+          LOG_UI(RRC,"[GroupCommunicationEstablishReq] Received on socket from ProSe App (msg type: %d)\n",sl_ctrl_msg_recv->type);
+          LOG_UI(RRC,"[GroupCommunicationEstablishReq] source Id: 0x%08x\n",sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.sourceL2Id);
+          LOG_UI(RRC,"[GroupCommunicationEstablishReq] group Id: 0x%08x\n",sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.groupL2Id);
+          LOG_UI(RRC,"[GroupCommunicationEstablishReq] group IP Address: " IPV4_ADDR "\n",IPV4_ADDR_FORMAT(sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.groupIpAddress));
+        }
+
+        //store sourceL2Id/groupL2Id
+        UE_rrc_inst[module_id].sourceL2Id = sourceL2Id;
+        UE_rrc_inst[module_id].groupL2Id = groupL2Id;
+        j = 0;
+        i = 0;
 
+        for (i=0; i< MAX_NUM_DEST; i++) {
+          if ((UE_rrc_inst[module_id].destinationList[i] == 0) && (j == 0)) j = i+1;
+
+          if (UE_rrc_inst[module_id].destinationList[i] == groupL2Id) break; //group already exists!
+        }
+
+        if ((i == MAX_NUM_DEST) && (j > 0))  UE_mac_inst[module_id].destinationList[j-1] = groupL2Id;
+
+        // configure lower layers PDCP/MAC/PHY for this communication
+        //Establish a new RBID/LCID for this communication
+        // Establish a SLRB (using DRB 3 for now)
+        UE  = &UE_rrc_inst[module_id];
+        PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, 0, ENB_FLAG_NO, 0x1234, 0, 0,0);
+        UE->DRB_config[0][0] = CALLOC(1,sizeof(struct LTE_DRB_ToAddMod));
+        UE->DRB_config[0][0]->eps_BearerIdentity = CALLOC(1, sizeof(long));
+        UE->DRB_config[0][0]->drb_Identity =  3;
+        UE->DRB_config[0][0]->eps_BearerIdentity = CALLOC(1, sizeof(long));
+        // allowed value 5..15, value : x+4
+        *(UE->DRB_config[0][0]->eps_BearerIdentity) = 3;
+        UE->DRB_config[0][0]->logicalChannelIdentity = CALLOC(1, sizeof(long));
+        *(UE->DRB_config[0][0]->logicalChannelIdentity) = UE->DRB_config[0][0]->drb_Identity; //(long) (ue_context_pP->ue_context.e_rab[i].param.e_rab_id + 2); // value : x+2
+        DRB_rlc_config                   = CALLOC(1,sizeof(struct LTE_RLC_Config));
+        DRB_pdcp_config                  = CALLOC(1,sizeof(struct LTE_PDCP_Config));
+        PDCP_rlc_UM                      = CALLOC(1,sizeof(struct LTE_PDCP_Config__rlc_UM));
+        DRB_lchan_config                 = CALLOC(1,sizeof(struct LTE_LogicalChannelConfig));
+        DRB_ul_SpecificParameters                                         = CALLOC(1, sizeof(struct LTE_LogicalChannelConfig__ul_SpecificParameters));
+        logicalchannelgroup_drb          = CALLOC(1, sizeof(long));
+        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;
+        UE->DRB_config[0][0]->rlc_Config = DRB_rlc_config;
+        DRB_pdcp_config = CALLOC(1, sizeof(*DRB_pdcp_config));
+        UE->DRB_config[0][0]->pdcp_Config = DRB_pdcp_config;
+        DRB_pdcp_config->discardTimer = CALLOC(1, sizeof(long));
+        *DRB_pdcp_config->discardTimer = LTE_PDCP_Config__discardTimer_infinity;
+        DRB_pdcp_config->rlc_AM = NULL;
+        DRB_pdcp_config->rlc_UM = NULL;
+        /* avoid gcc warnings */
+        (void)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;
+        UE->DRB_config[0][0]->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 = 12;    // lower priority than srb1, srb2 and other dedicated bearer
+        DRB_ul_SpecificParameters->prioritisedBitRate =LTE_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_kBps8 ;
+        //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 = 1;
+        DRB_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup_drb;
+        UE->DRB_configList = CALLOC(1,sizeof(LTE_DRB_ToAddModList_t));
+        ASN_SEQUENCE_ADD(&UE->DRB_configList->list,UE->DRB_config[0][0]);
+        rrc_pdcp_config_asn1_req(&ctxt,
+                                 (LTE_SRB_ToAddModList_t *) NULL,
+                                 UE->DRB_configList,
+                                 (LTE_DRB_ToReleaseList_t *) NULL,
+                                 0xff, NULL, NULL, NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                                 , (LTE_PMCH_InfoList_r9_t *) NULL
+#endif
+                                 ,NULL);
+        rrc_rlc_config_asn1_req(&ctxt,
+                                (LTE_SRB_ToAddModList_t *)NULL,
+                                UE->DRB_configList,
+                                (LTE_DRB_ToReleaseList_t *)NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                                ,(LTE_PMCH_InfoList_r9_t *)NULL
+                                , 0, 0
+#endif
+                               );
+        rrc_rlc_config_asn1_req(&ctxt,
+                                (LTE_SRB_ToAddModList_t *)NULL,
+                                UE->DRB_configList,
+                                (LTE_DRB_ToReleaseList_t *)NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                                ,(LTE_PMCH_InfoList_r9_t *)NULL
+                                , sourceL2Id, groupL2Id
+#endif
+                               );
+        //configure MAC with sourceL2Id/groupL2ID
+        rrc_mac_config_req_ue(module_id,0,0, //eNB_index =0
+                              (LTE_RadioResourceConfigCommonSIB_t *)NULL,
+                              (struct LTE_PhysicalConfigDedicated *)NULL,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                              (LTE_SCellToAddMod_r10_t *)NULL,
+                              //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
+#endif
+                              (LTE_MeasObjectToAddMod_t **)NULL,
+                              (LTE_MAC_MainConfig_t *)NULL,
+                              3, //LCID
+                              (struct LTE_LogicalChannelConfig *)NULL,
+                              (LTE_MeasGapConfig_t *)NULL,
+                              (LTE_TDD_Config_t *)NULL,
+                              (LTE_MobilityControlInfo_t *)NULL,
+                              NULL,
+                              NULL,
+                              NULL,
+                              NULL,
+                              NULL,
+                              NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                              ,0,
+                              (LTE_MBSFN_AreaInfoList_r9_t *)NULL,
+                              (LTE_PMCH_InfoList_r9_t *)NULL
 #endif
 #ifdef CBA
-               ,
-               0,
-               0
-#endif
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-               ,CONFIG_ACTION_ADD,
-               &sourceL2Id,
-               &groupL2Id
-#endif
-         );
-
-         LOG_I(RRC,"Send GroupCommunicationEstablishResp to ProSe App\n");
-         memset(send_buf, 0, BUFSIZE);
-         sl_ctrl_msg_send = calloc(1, sizeof(struct sidelink_ctrl_element));
-         sl_ctrl_msg_send->type = GROUP_COMMUNICATION_ESTABLISH_RSP;
-         sl_ctrl_msg_send->sidelinkPrimitive.slrb_id = 3; //slrb_id
-
-         memcpy((void *)send_buf, (void *)sl_ctrl_msg_send, sizeof(struct sidelink_ctrl_element));
-         free(sl_ctrl_msg_send);
-
-         prose_addr_len = sizeof(prose_app_addr);
-         n = sendto(ctrl_sock_fd, (char *)send_buf, sizeof(struct sidelink_ctrl_element), 0, (struct sockaddr *)&prose_app_addr, prose_addr_len);
-         if (n < 0){
-            LOG_E(RRC, "ERROR: Failed to send to ProSe App\n");
-            exit(EXIT_FAILURE);
-         }
-
-         if (LOG_DEBUGFLAG(DEBUG_CTRLSOCKET)){
-           struct sidelink_ctrl_element *ptr_ctrl_msg = NULL;
-           ptr_ctrl_msg = (struct sidelink_ctrl_element *) send_buf;
-           LOG_UI(RRC,"[GroupCommunicationEstablishResponse]  msg type: %d\n",ptr_ctrl_msg->type);
-           LOG_UI(RRC,"[GroupCommunicationEstablishResponse]  slrb_id: %d\n",ptr_ctrl_msg->sidelinkPrimitive.slrb_id);
-         }
-         break;
+                              ,
+                              0,
+                              0
+#endif
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                              ,CONFIG_ACTION_ADD,
+                              &sourceL2Id,
+                              &groupL2Id
+#endif
+                             );
+        LOG_I(RRC,"Send GroupCommunicationEstablishResp to ProSe App\n");
+        memset(send_buf, 0, BUFSIZE);
+        sl_ctrl_msg_send = calloc(1, sizeof(struct sidelink_ctrl_element));
+        sl_ctrl_msg_send->type = GROUP_COMMUNICATION_ESTABLISH_RSP;
+        sl_ctrl_msg_send->sidelinkPrimitive.slrb_id = 3; //slrb_id
+        memcpy((void *)send_buf, (void *)sl_ctrl_msg_send, sizeof(struct sidelink_ctrl_element));
+        free(sl_ctrl_msg_send);
+        prose_addr_len = sizeof(prose_app_addr);
+        n = sendto(ctrl_sock_fd, (char *)send_buf, sizeof(struct sidelink_ctrl_element), 0, (struct sockaddr *)&prose_app_addr, prose_addr_len);
+
+        if (n < 0) {
+          LOG_E(RRC, "ERROR: Failed to send to ProSe App\n");
+          exit(EXIT_FAILURE);
+        }
+
+        if (LOG_DEBUGFLAG(DEBUG_CTRLSOCKET)) {
+          struct sidelink_ctrl_element *ptr_ctrl_msg = NULL;
+          ptr_ctrl_msg = (struct sidelink_ctrl_element *) send_buf;
+          LOG_UI(RRC,"[GroupCommunicationEstablishResponse]  msg type: %d\n",ptr_ctrl_msg->type);
+          LOG_UI(RRC,"[GroupCommunicationEstablishResponse]  slrb_id: %d\n",ptr_ctrl_msg->sidelinkPrimitive.slrb_id);
+        }
+
+        break;
 
       case GROUP_COMMUNICATION_RELEASE_REQ:
-         printf("-----------------------------------\n");
-         if (LOG_DEBUGFLAG(DEBUG_CTRLSOCKET)){
-           LOG_UI(RRC,"[GroupCommunicationReleaseRequest] Received on socket from ProSe App (msg type: %d)\n",sl_ctrl_msg_recv->type);
-           LOG_UI(RRC,"[GroupCommunicationReleaseRequest] Slrb Id: %i\n",sl_ctrl_msg_recv->sidelinkPrimitive.slrb_id);
-         }
-         //reset groupL2ID from MAC LAYER
-         UE_rrc_inst[module_id].groupL2Id = 0x00000000;
-         sourceL2Id = UE_rrc_inst[module_id].sourceL2Id;
-
-         rrc_mac_config_req_ue(module_id,0,0, //eNB_index =0
-                    (RadioResourceConfigCommonSIB_t *)NULL,
-                    (struct PhysicalConfigDedicated *)NULL,
-         #if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-                    (SCellToAddMod_r10_t *)NULL,
-                    //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
-         #endif
-                    (MeasObjectToAddMod_t **)NULL,
-                    (MAC_MainConfig_t *)NULL,
-                    0,
-                    (struct LogicalChannelConfig *)NULL,
-                    (MeasGapConfig_t *)NULL,
-                    (TDD_Config_t *)NULL,
-                    (MobilityControlInfo_t *)NULL,
-                    NULL,
-                    NULL,
-                    NULL,
-                    NULL,
-                    NULL,
-                    NULL
-         #if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-                    ,0,
-                    (MBSFN_AreaInfoList_r9_t *)NULL,
-                    (PMCH_InfoList_r9_t *)NULL
-
-         #endif
-         #ifdef CBA
-                    ,
-                    0,
-                    0
-         #endif
-         #if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-                    ,CONFIG_ACTION_REMOVE,
-                    &sourceL2Id,
-                    &destinationL2Id
-         #endif
-                    );
-
-
-         LOG_I(RRC,"Send GroupCommunicationReleaseResponse to ProSe App \n");
-         memset(send_buf, 0, BUFSIZE);
-
-         sl_ctrl_msg_send = calloc(1, sizeof(struct sidelink_ctrl_element));
-         sl_ctrl_msg_send->type = GROUP_COMMUNICATION_RELEASE_RSP;
-         //if the requested id exists -> release this ID
-         if (sl_ctrl_msg_recv->sidelinkPrimitive.slrb_id == slrb_id) {
-            sl_ctrl_msg_send->sidelinkPrimitive.group_comm_release_rsp = GROUP_COMMUNICATION_RELEASE_OK;
-            slrb_id = 0; //Reset slrb_id
-         } else {
-            sl_ctrl_msg_send->sidelinkPrimitive.group_comm_release_rsp = GROUP_COMMUNICATION_RELEASE_FAILURE;
-         }
-         memcpy((void *)send_buf, (void *)sl_ctrl_msg_send, sizeof(struct sidelink_ctrl_element));
-         free(sl_ctrl_msg_send);
-
-         prose_addr_len = sizeof(prose_app_addr);
-         n = sendto(ctrl_sock_fd, (char *)send_buf, sizeof(struct sidelink_ctrl_element), 0, (struct sockaddr *)&prose_app_addr, prose_addr_len);
-         if (n < 0){
-            LOG_E(RRC, "ERROR: Failed to send to ProSe App\n");
-            exit(EXIT_FAILURE);
-         }
-         break;
+        printf("-----------------------------------\n");
+
+        if (LOG_DEBUGFLAG(DEBUG_CTRLSOCKET)) {
+          LOG_UI(RRC,"[GroupCommunicationReleaseRequest] Received on socket from ProSe App (msg type: %d)\n",sl_ctrl_msg_recv->type);
+          LOG_UI(RRC,"[GroupCommunicationReleaseRequest] Slrb Id: %i\n",sl_ctrl_msg_recv->sidelinkPrimitive.slrb_id);
+        }
+
+        //reset groupL2ID from MAC LAYER
+        UE_rrc_inst[module_id].groupL2Id = 0x00000000;
+        sourceL2Id = UE_rrc_inst[module_id].sourceL2Id;
+        rrc_mac_config_req_ue(module_id,0,0, //eNB_index =0
+                              (LTE_RadioResourceConfigCommonSIB_t *)NULL,
+                              (struct LTE_PhysicalConfigDedicated *)NULL,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                              (LTE_SCellToAddMod_r10_t *)NULL,
+                              //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
+#endif
+                              (LTE_MeasObjectToAddMod_t **)NULL,
+                              (LTE_MAC_MainConfig_t *)NULL,
+                              0,
+                              (struct LTE_LogicalChannelConfig *)NULL,
+                              (LTE_MeasGapConfig_t *)NULL,
+                              (LTE_TDD_Config_t *)NULL,
+                              (LTE_MobilityControlInfo_t *)NULL,
+                              NULL,
+                              NULL,
+                              NULL,
+                              NULL,
+                              NULL,
+                              NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                              ,0,
+                              (LTE_MBSFN_AreaInfoList_r9_t *)NULL,
+                              (LTE_PMCH_InfoList_r9_t *)NULL
+#endif
+#ifdef CBA
+                              ,
+                              0,
+                              0
+#endif
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                              ,CONFIG_ACTION_REMOVE,
+                              &sourceL2Id,
+                              &destinationL2Id
+#endif
+                             );
+        LOG_I(RRC,"Send GroupCommunicationReleaseResponse to ProSe App \n");
+        memset(send_buf, 0, BUFSIZE);
+        sl_ctrl_msg_send = calloc(1, sizeof(struct sidelink_ctrl_element));
+        sl_ctrl_msg_send->type = GROUP_COMMUNICATION_RELEASE_RSP;
+
+        //if the requested id exists -> release this ID
+        if (sl_ctrl_msg_recv->sidelinkPrimitive.slrb_id == slrb_id) {
+          sl_ctrl_msg_send->sidelinkPrimitive.group_comm_release_rsp = GROUP_COMMUNICATION_RELEASE_OK;
+          slrb_id = 0; //Reset slrb_id
+        } else {
+          sl_ctrl_msg_send->sidelinkPrimitive.group_comm_release_rsp = GROUP_COMMUNICATION_RELEASE_FAILURE;
+        }
+
+        memcpy((void *)send_buf, (void *)sl_ctrl_msg_send, sizeof(struct sidelink_ctrl_element));
+        free(sl_ctrl_msg_send);
+        prose_addr_len = sizeof(prose_app_addr);
+        n = sendto(ctrl_sock_fd, (char *)send_buf, sizeof(struct sidelink_ctrl_element), 0, (struct sockaddr *)&prose_app_addr, prose_addr_len);
 
+        if (n < 0) {
+          LOG_E(RRC, "ERROR: Failed to send to ProSe App\n");
+          exit(EXIT_FAILURE);
+        }
+
+        break;
 
       case DIRECT_COMMUNICATION_ESTABLISH_REQ:
-         sourceL2Id = sl_ctrl_msg_recv->sidelinkPrimitive.direct_comm_establish_req.sourceL2Id;
-         destinationL2Id = sl_ctrl_msg_recv->sidelinkPrimitive.direct_comm_establish_req.destinationL2Id;
-
-         if (LOG_DEBUGFLAG(DEBUG_CTRLSOCKET)){
-           LOG_UI(RRC,"[DirectCommunicationEstablishReq] Received on socket from ProSe App (msg type: %d)\n",sl_ctrl_msg_recv->type);
-           LOG_UI(RRC,"[DirectCommunicationEstablishReq] source Id: 0x%08x\n",sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.sourceL2Id);
-           LOG_UI(RRC,"[DirectCommunicationEstablishReq] destination Id: 0x%08x\n",sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.groupL2Id);
-         }
-
-         //store sourceL2Id/destinationL2Id
-         UE_rrc_inst[module_id].sourceL2Id = sourceL2Id;
-         i = 0;
-         j = 0;
-         for (i=0; i< MAX_NUM_DEST; i++) {
-            if ((UE_rrc_inst[module_id].destinationList[i] == 0) && (j == 0)) j = i+1;
-            if (UE_rrc_inst[module_id].destinationList[i] == destinationL2Id) break; //destination already exists!
-         }
-         if ((i == MAX_NUM_DEST) && (j > 0))  UE_mac_inst[module_id].destinationList[j-1] = destinationL2Id;
-
-         // configure lower layers PDCP/MAC/PHY for this communication
-         //Establish a new RBID/LCID for this communication
-         // Establish a SLRB (using DRB 3 for now)
-         UE  = &UE_rrc_inst[module_id];
-         PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, 0, ENB_FLAG_NO, 0x1234, 0, 0,0);
-
-         UE->DRB_config[0][0] = CALLOC(1,sizeof(struct DRB_ToAddMod));
-         UE->DRB_config[0][0]->eps_BearerIdentity = CALLOC(1, sizeof(long));
-         UE->DRB_config[0][0]->drb_Identity =  3;
-         UE->DRB_config[0][0]->eps_BearerIdentity = CALLOC(1, sizeof(long));
-         // allowed value 5..15, value : x+4
-         *(UE->DRB_config[0][0]->eps_BearerIdentity) = 3;
-         UE->DRB_config[0][0]->logicalChannelIdentity = CALLOC(1, sizeof(long));
-         *(UE->DRB_config[0][0]->logicalChannelIdentity) = UE->DRB_config[0][0]->drb_Identity; //(long) (ue_context_pP->ue_context.e_rab[i].param.e_rab_id + 2); // value : x+2
-
-         DRB_rlc_config                   = CALLOC(1,sizeof(struct RLC_Config));
-         DRB_pdcp_config                  = CALLOC(1,sizeof(struct PDCP_Config));
-         PDCP_rlc_UM                      = CALLOC(1,sizeof(struct PDCP_Config__rlc_UM));
-         DRB_lchan_config                 = CALLOC(1,sizeof(struct LogicalChannelConfig));
-         DRB_ul_SpecificParameters                                         = CALLOC(1, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
-         logicalchannelgroup_drb          = CALLOC(1, sizeof(long));
-
-         DRB_rlc_config->present = RLC_Config_PR_um_Bi_Directional;
-         DRB_rlc_config->choice.um_Bi_Directional.ul_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
-         DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
-         DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = T_Reordering_ms35;
-         UE->DRB_config[0][0]->rlc_Config = DRB_rlc_config;
-
-         DRB_pdcp_config = CALLOC(1, sizeof(*DRB_pdcp_config));
-         UE->DRB_config[0][0]->pdcp_Config = DRB_pdcp_config;
-         DRB_pdcp_config->discardTimer = CALLOC(1, sizeof(long));
-         *DRB_pdcp_config->discardTimer = PDCP_Config__discardTimer_infinity;
-         DRB_pdcp_config->rlc_AM = NULL;
-         DRB_pdcp_config->rlc_UM = NULL;
-
-         /* avoid gcc warnings */
-         (void)PDCP_rlc_UM;
-
-         DRB_pdcp_config->rlc_UM = PDCP_rlc_UM;
-         PDCP_rlc_UM->pdcp_SN_Size = PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits;
-         DRB_pdcp_config->headerCompression.present = PDCP_Config__headerCompression_PR_notUsed;
-
-         UE->DRB_config[0][0]->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 = 12;    // lower priority than srb1, srb2 and other dedicated bearer
-         DRB_ul_SpecificParameters->prioritisedBitRate =LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_kBps8 ;
-         //LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
-         DRB_ul_SpecificParameters->bucketSizeDuration =
-               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 = 1;
-         DRB_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup_drb;
-
-         UE->DRB_configList = CALLOC(1,sizeof(DRB_ToAddModList_t));
-         ASN_SEQUENCE_ADD(&UE->DRB_configList->list,UE->DRB_config[0][0]);
-
-         rrc_pdcp_config_asn1_req(&ctxt,
-               (SRB_ToAddModList_t *) NULL,
-               UE->DRB_configList,
-               (DRB_ToReleaseList_t*) NULL,
-               0xff, NULL, NULL, NULL
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-               , (PMCH_InfoList_r9_t *) NULL
-#endif
-               ,NULL);
-
-
-         rrc_rlc_config_asn1_req(&ctxt,
-               (SRB_ToAddModList_t*)NULL,
-               UE->DRB_configList,
-               (DRB_ToReleaseList_t*)NULL
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-               ,(PMCH_InfoList_r9_t *)NULL
-               , 0, 0
-#endif
-         );
-
-         rrc_rlc_config_asn1_req(&ctxt,
-               (SRB_ToAddModList_t*)NULL,
-               UE->DRB_configList,
-               (DRB_ToReleaseList_t*)NULL
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-               ,(PMCH_InfoList_r9_t *)NULL
-               , sourceL2Id, destinationL2Id
-#endif
-         );
-
-
-         //configure MAC with sourceL2Id/destinationL2Id
-         rrc_mac_config_req_ue(module_id,0,0, //eNB_index =0
-               (RadioResourceConfigCommonSIB_t *)NULL,
-               (struct PhysicalConfigDedicated *)NULL,
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-               (SCellToAddMod_r10_t *)NULL,
-               //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
-#endif
-               (MeasObjectToAddMod_t **)NULL,
-               (MAC_MainConfig_t *)NULL,
-               3, //LCID
-               (struct LogicalChannelConfig *)NULL,
-               (MeasGapConfig_t *)NULL,
-               (TDD_Config_t *)NULL,
-               (MobilityControlInfo_t *)NULL,
-               NULL,
-               NULL,
-               NULL,
-               NULL,
-               NULL,
-               NULL
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-               ,0,
-               (MBSFN_AreaInfoList_r9_t *)NULL,
-               (PMCH_InfoList_r9_t *)NULL
+        sourceL2Id = sl_ctrl_msg_recv->sidelinkPrimitive.direct_comm_establish_req.sourceL2Id;
+        destinationL2Id = sl_ctrl_msg_recv->sidelinkPrimitive.direct_comm_establish_req.destinationL2Id;
+
+        if (LOG_DEBUGFLAG(DEBUG_CTRLSOCKET)) {
+          LOG_UI(RRC,"[DirectCommunicationEstablishReq] Received on socket from ProSe App (msg type: %d)\n",sl_ctrl_msg_recv->type);
+          LOG_UI(RRC,"[DirectCommunicationEstablishReq] source Id: 0x%08x\n",sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.sourceL2Id);
+          LOG_UI(RRC,"[DirectCommunicationEstablishReq] destination Id: 0x%08x\n",sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.groupL2Id);
+        }
 
+        //store sourceL2Id/destinationL2Id
+        UE_rrc_inst[module_id].sourceL2Id = sourceL2Id;
+        i = 0;
+        j = 0;
+
+        for (i=0; i< MAX_NUM_DEST; i++) {
+          if ((UE_rrc_inst[module_id].destinationList[i] == 0) && (j == 0)) j = i+1;
+
+          if (UE_rrc_inst[module_id].destinationList[i] == destinationL2Id) break; //destination already exists!
+        }
+
+        if ((i == MAX_NUM_DEST) && (j > 0))  UE_mac_inst[module_id].destinationList[j-1] = destinationL2Id;
+
+        // configure lower layers PDCP/MAC/PHY for this communication
+        //Establish a new RBID/LCID for this communication
+        // Establish a SLRB (using DRB 3 for now)
+        UE  = &UE_rrc_inst[module_id];
+        PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, 0, ENB_FLAG_NO, 0x1234, 0, 0,0);
+        UE->DRB_config[0][0] = CALLOC(1,sizeof(struct LTE_DRB_ToAddMod));
+        UE->DRB_config[0][0]->eps_BearerIdentity = CALLOC(1, sizeof(long));
+        UE->DRB_config[0][0]->drb_Identity =  3;
+        UE->DRB_config[0][0]->eps_BearerIdentity = CALLOC(1, sizeof(long));
+        // allowed value 5..15, value : x+4
+        *(UE->DRB_config[0][0]->eps_BearerIdentity) = 3;
+        UE->DRB_config[0][0]->logicalChannelIdentity = CALLOC(1, sizeof(long));
+        *(UE->DRB_config[0][0]->logicalChannelIdentity) = UE->DRB_config[0][0]->drb_Identity; //(long) (ue_context_pP->ue_context.e_rab[i].param.e_rab_id + 2); // value : x+2
+        DRB_rlc_config                   = CALLOC(1,sizeof(struct LTE_RLC_Config));
+        DRB_pdcp_config                  = CALLOC(1,sizeof(struct LTE_PDCP_Config));
+        PDCP_rlc_UM                      = CALLOC(1,sizeof(struct LTE_PDCP_Config__rlc_UM));
+        DRB_lchan_config                 = CALLOC(1,sizeof(struct LTE_LogicalChannelConfig));
+        DRB_ul_SpecificParameters                                         = CALLOC(1, sizeof(struct LTE_LogicalChannelConfig__ul_SpecificParameters));
+        logicalchannelgroup_drb          = CALLOC(1, sizeof(long));
+        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;
+        UE->DRB_config[0][0]->rlc_Config = DRB_rlc_config;
+        DRB_pdcp_config = CALLOC(1, sizeof(*DRB_pdcp_config));
+        UE->DRB_config[0][0]->pdcp_Config = DRB_pdcp_config;
+        DRB_pdcp_config->discardTimer = CALLOC(1, sizeof(long));
+        *DRB_pdcp_config->discardTimer = LTE_PDCP_Config__discardTimer_infinity;
+        DRB_pdcp_config->rlc_AM = NULL;
+        DRB_pdcp_config->rlc_UM = NULL;
+        /* avoid gcc warnings */
+        (void)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;
+        UE->DRB_config[0][0]->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 = 12;    // lower priority than srb1, srb2 and other dedicated bearer
+        DRB_ul_SpecificParameters->prioritisedBitRate =LTE_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_kBps8 ;
+        //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 = 1;
+        DRB_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup_drb;
+        UE->DRB_configList = CALLOC(1,sizeof(LTE_DRB_ToAddModList_t));
+        ASN_SEQUENCE_ADD(&UE->DRB_configList->list,UE->DRB_config[0][0]);
+        rrc_pdcp_config_asn1_req(&ctxt,
+                                 (LTE_SRB_ToAddModList_t *) NULL,
+                                 UE->DRB_configList,
+                                 (LTE_DRB_ToReleaseList_t *) NULL,
+                                 0xff, NULL, NULL, NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                                 , (LTE_PMCH_InfoList_r9_t *) NULL
+#endif
+                                 ,NULL);
+        rrc_rlc_config_asn1_req(&ctxt,
+                                (LTE_SRB_ToAddModList_t *)NULL,
+                                UE->DRB_configList,
+                                (LTE_DRB_ToReleaseList_t *)NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                                ,(LTE_PMCH_InfoList_r9_t *)NULL
+                                , 0, 0
+#endif
+                               );
+        rrc_rlc_config_asn1_req(&ctxt,
+                                (LTE_SRB_ToAddModList_t *)NULL,
+                                UE->DRB_configList,
+                                (LTE_DRB_ToReleaseList_t *)NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                                ,(LTE_PMCH_InfoList_r9_t *)NULL
+                                , sourceL2Id, destinationL2Id
+#endif
+                               );
+        //configure MAC with sourceL2Id/destinationL2Id
+        rrc_mac_config_req_ue(module_id,0,0, //eNB_index =0
+                              (LTE_RadioResourceConfigCommonSIB_t *)NULL,
+                              (struct LTE_PhysicalConfigDedicated *)NULL,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                              (LTE_SCellToAddMod_r10_t *)NULL,
+                              //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
+#endif
+                              (LTE_MeasObjectToAddMod_t **)NULL,
+                              (LTE_MAC_MainConfig_t *)NULL,
+                              3, //LCID
+                              (struct LTE_LogicalChannelConfig *)NULL,
+                              (LTE_MeasGapConfig_t *)NULL,
+                              (LTE_TDD_Config_t *)NULL,
+                              (LTE_MobilityControlInfo_t *)NULL,
+                              NULL,
+                              NULL,
+                              NULL,
+                              NULL,
+                              NULL,
+                              NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                              ,0,
+                              (LTE_MBSFN_AreaInfoList_r9_t *)NULL,
+                              (LTE_PMCH_InfoList_r9_t *)NULL
 #endif
 #ifdef CBA
-               ,
-               0,
-               0
-#endif
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-               ,CONFIG_ACTION_ADD,
-               &sourceL2Id,
-               &destinationL2Id
-#endif
-         );
-
-         LOG_I(RRC,"Send DirectCommunicationEstablishResp to ProSe App\n");
-         memset(send_buf, 0, BUFSIZE);
-         sl_ctrl_msg_send = calloc(1, sizeof(struct sidelink_ctrl_element));
-         sl_ctrl_msg_send->type = DIRECT_COMMUNICATION_ESTABLISH_RSP;
-         sl_ctrl_msg_send->sidelinkPrimitive.slrb_id = 3; //slrb_id
-
-         memcpy((void *)send_buf, (void *)sl_ctrl_msg_send, sizeof(struct sidelink_ctrl_element));
-         free(sl_ctrl_msg_send);
-
-         prose_addr_len = sizeof(prose_app_addr);
-         n = sendto(ctrl_sock_fd, (char *)send_buf, sizeof(struct sidelink_ctrl_element), 0, (struct sockaddr *)&prose_app_addr, prose_addr_len);
-         if (n < 0){
-            LOG_E(RRC, "ERROR: Failed to send to ProSe App\n");
-            exit(EXIT_FAILURE);
-         }
-
-
-         if (LOG_DEBUGFLAG(DEBUG_CTRLSOCKET)){
-           struct sidelink_ctrl_element *ptr_ctrl_msg = NULL;
-           ptr_ctrl_msg = (struct sidelink_ctrl_element *) send_buf;
-           LOG_UI(RRC,"[DirectCommunicationEstablishResponse]  msg type: %d\n",ptr_ctrl_msg->type);
-           LOG_UI(RRC,"[DirectCommunicationEstablishResponse]  slrb_id: %d\n",ptr_ctrl_msg->sidelinkPrimitive.slrb_id);
-         }
-         break;
+                              ,
+                              0,
+                              0
+#endif
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                              ,CONFIG_ACTION_ADD,
+                              &sourceL2Id,
+                              &destinationL2Id
+#endif
+                             );
+        LOG_I(RRC,"Send DirectCommunicationEstablishResp to ProSe App\n");
+        memset(send_buf, 0, BUFSIZE);
+        sl_ctrl_msg_send = calloc(1, sizeof(struct sidelink_ctrl_element));
+        sl_ctrl_msg_send->type = DIRECT_COMMUNICATION_ESTABLISH_RSP;
+        sl_ctrl_msg_send->sidelinkPrimitive.slrb_id = 3; //slrb_id
+        memcpy((void *)send_buf, (void *)sl_ctrl_msg_send, sizeof(struct sidelink_ctrl_element));
+        free(sl_ctrl_msg_send);
+        prose_addr_len = sizeof(prose_app_addr);
+        n = sendto(ctrl_sock_fd, (char *)send_buf, sizeof(struct sidelink_ctrl_element), 0, (struct sockaddr *)&prose_app_addr, prose_addr_len);
+
+        if (n < 0) {
+          LOG_E(RRC, "ERROR: Failed to send to ProSe App\n");
+          exit(EXIT_FAILURE);
+        }
+
+        if (LOG_DEBUGFLAG(DEBUG_CTRLSOCKET)) {
+          struct sidelink_ctrl_element *ptr_ctrl_msg = NULL;
+          ptr_ctrl_msg = (struct sidelink_ctrl_element *) send_buf;
+          LOG_UI(RRC,"[DirectCommunicationEstablishResponse]  msg type: %d\n",ptr_ctrl_msg->type);
+          LOG_UI(RRC,"[DirectCommunicationEstablishResponse]  slrb_id: %d\n",ptr_ctrl_msg->sidelinkPrimitive.slrb_id);
+        }
+
+        break;
 
       case PC5S_ESTABLISH_REQ:
-           type =  sl_ctrl_msg_recv->sidelinkPrimitive.pc5s_establish_req.type;
-           sourceL2Id = sl_ctrl_msg_recv->sidelinkPrimitive.pc5s_establish_req.sourceL2Id;
-           if (LOG_DEBUGFLAG(DEBUG_CTRLSOCKET)){
-             LOG_UI(RRC,"[PC5EstablishReq] Received on socket from ProSe App (msg type: %d)\n",sl_ctrl_msg_recv->type);
-             LOG_UI(RRC,"[PC5EstablishReq] type: %d\n",sl_ctrl_msg_recv->sidelinkPrimitive.pc5s_establish_req.type); //RX/TX
-             LOG_UI(RRC,"[PC5EstablishReq] source Id: 0x%08x \n",sl_ctrl_msg_recv->sidelinkPrimitive.pc5s_establish_req.sourceL2Id);
-           }
-         if (type > 0) {
-            destinationL2Id = sl_ctrl_msg_recv->sidelinkPrimitive.pc5s_establish_req.destinationL2Id;
-            if (LOG_DEBUGFLAG(DEBUG_CTRLSOCKET)){
-              LOG_UI(RRC,"[PC5EstablishReq] destination Id: 0x%08x \n",sl_ctrl_msg_recv->sidelinkPrimitive.pc5s_establish_req.destinationL2Id);
-            }
-         }
-
-         //store sourceL2Id/destinationL2Id
-         if (type > 0) { //TX
-            UE_rrc_inst[module_id].sourceL2Id = sourceL2Id;
-            j = 0;
-            i = 0;
-            for (i=0; i< MAX_NUM_DEST; i++) {
-               if ((UE_rrc_inst[module_id].destinationList[i] == 0) && (j == 0)) j = i+1;
-               if (UE_rrc_inst[module_id].destinationList[i] == destinationL2Id) break; //group already exists!
-            }
-            if ((i == MAX_NUM_DEST) && (j > 0))  UE_mac_inst[module_id].destinationList[j-1] = destinationL2Id;
-         } else {//RX
-            UE_rrc_inst[module_id].sourceL2Id = sourceL2Id;
-         }
-
-         // configure lower layers PDCP/MAC/PHY for this communication
-         //Establish a new RBID/LCID for this communication
-         // Establish a SLRB (using DRB 10 for now)
-         UE  = &UE_rrc_inst[module_id];
-         PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, 0, ENB_FLAG_NO, 0x1234, 0, 0,0);
-
-         UE->DRB_config[0][0] = CALLOC(1,sizeof(struct DRB_ToAddMod));
-         UE->DRB_config[0][0]->eps_BearerIdentity = CALLOC(1, sizeof(long));
-         UE->DRB_config[0][0]->drb_Identity =  10;
-         UE->DRB_config[0][0]->eps_BearerIdentity = CALLOC(1, sizeof(long));
-         // allowed value 5..15, value : x+4
-         *(UE->DRB_config[0][0]->eps_BearerIdentity) = 10;
-         UE->DRB_config[0][0]->logicalChannelIdentity = CALLOC(1, sizeof(long));
-         *(UE->DRB_config[0][0]->logicalChannelIdentity) = UE->DRB_config[0][0]->drb_Identity; //(long) (ue_context_pP->ue_context.e_rab[i].param.e_rab_id + 2); // value : x+2
-
-         DRB_rlc_config                   = CALLOC(1,sizeof(struct RLC_Config));
-         DRB_pdcp_config                  = CALLOC(1,sizeof(struct PDCP_Config));
-         PDCP_rlc_UM                      = CALLOC(1,sizeof(struct PDCP_Config__rlc_UM));
-         DRB_lchan_config                 = CALLOC(1,sizeof(struct LogicalChannelConfig));
-         DRB_ul_SpecificParameters                                         = CALLOC(1, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
-         logicalchannelgroup_drb          = CALLOC(1, sizeof(long));
-
-         DRB_rlc_config->present = RLC_Config_PR_um_Bi_Directional;
-         DRB_rlc_config->choice.um_Bi_Directional.ul_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
-         DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
-         DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = T_Reordering_ms35;
-         UE->DRB_config[0][0]->rlc_Config = DRB_rlc_config;
-
-         DRB_pdcp_config = CALLOC(1, sizeof(*DRB_pdcp_config));
-         UE->DRB_config[0][0]->pdcp_Config = DRB_pdcp_config;
-         DRB_pdcp_config->discardTimer = CALLOC(1, sizeof(long));
-         *DRB_pdcp_config->discardTimer = PDCP_Config__discardTimer_infinity;
-         DRB_pdcp_config->rlc_AM = NULL;
-         DRB_pdcp_config->rlc_UM = NULL;
-
-         /* avoid gcc warnings */
-         (void)PDCP_rlc_UM;
-
-         DRB_pdcp_config->rlc_UM = PDCP_rlc_UM;
-         PDCP_rlc_UM->pdcp_SN_Size = PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits;
-         DRB_pdcp_config->headerCompression.present = PDCP_Config__headerCompression_PR_notUsed;
-
-         UE->DRB_config[0][0]->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 = 12;    // lower priority than srb1, srb2 and other dedicated bearer
-         DRB_ul_SpecificParameters->prioritisedBitRate =LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_kBps8 ;
-         //LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
-         DRB_ul_SpecificParameters->bucketSizeDuration =
-               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 = 1;
-         DRB_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup_drb;
-
-         UE->DRB_configList = CALLOC(1,sizeof(DRB_ToAddModList_t));
-         ASN_SEQUENCE_ADD(&UE->DRB_configList->list,UE->DRB_config[0][0]);
-
-         rrc_pdcp_config_asn1_req(&ctxt,
-               (SRB_ToAddModList_t *) NULL,
-               UE->DRB_configList,
-               (DRB_ToReleaseList_t*) NULL,
-               0xff, NULL, NULL, NULL
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-               , (PMCH_InfoList_r9_t *) NULL
-#endif
-               ,NULL);
-
-
-         rrc_rlc_config_asn1_req(&ctxt,
-               (SRB_ToAddModList_t*)NULL,
-               UE->DRB_configList,
-               (DRB_ToReleaseList_t*)NULL
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-               ,(PMCH_InfoList_r9_t *)NULL
-               , 0, 0
-#endif
-         );
-
-         //TX
-         if (type > 0) {
-            rrc_rlc_config_asn1_req(&ctxt,
-                  (SRB_ToAddModList_t*)NULL,
-                  UE->DRB_configList,
-                  (DRB_ToReleaseList_t*)NULL
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-                  ,(PMCH_InfoList_r9_t *)NULL
-                  , sourceL2Id, destinationL2Id
-#endif
-            );
-
-            //configure MAC with sourceL2Id/groupL2ID
-            rrc_mac_config_req_ue(module_id,0,0, //eNB_index =0
-                  (RadioResourceConfigCommonSIB_t *)NULL,
-                  (struct PhysicalConfigDedicated *)NULL,
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-                  (SCellToAddMod_r10_t *)NULL,
-                  //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
-#endif
-                  (MeasObjectToAddMod_t **)NULL,
-                  (MAC_MainConfig_t *)NULL,
-                  10, //LCID
-                  (struct LogicalChannelConfig *)NULL,
-                  (MeasGapConfig_t *)NULL,
-                  (TDD_Config_t *)NULL,
-                  (MobilityControlInfo_t *)NULL,
-                  NULL,
-                  NULL,
-                  NULL,
-                  NULL,
-                  NULL,
-                  NULL
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-                  ,0,
-                  (MBSFN_AreaInfoList_r9_t *)NULL,
-                  (PMCH_InfoList_r9_t *)NULL
+        type =  sl_ctrl_msg_recv->sidelinkPrimitive.pc5s_establish_req.type;
+        sourceL2Id = sl_ctrl_msg_recv->sidelinkPrimitive.pc5s_establish_req.sourceL2Id;
 
-#endif
-#ifdef CBA
-                  ,
-                  0,
-                  0
-#endif
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-                  ,CONFIG_ACTION_ADD,
-                  &sourceL2Id,
-                  &destinationL2Id
-#endif
-            );
-         } else {//RX
-            //configure MAC with sourceL2Id/groupL2ID
-            rrc_mac_config_req_ue(module_id,0,0, //eNB_index =0
-                  (RadioResourceConfigCommonSIB_t *)NULL,
-                  (struct PhysicalConfigDedicated *)NULL,
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-                  (SCellToAddMod_r10_t *)NULL,
-                  //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
-#endif
-                  (MeasObjectToAddMod_t **)NULL,
-                  (MAC_MainConfig_t *)NULL,
-                  10, //LCID
-                  (struct LogicalChannelConfig *)NULL,
-                  (MeasGapConfig_t *)NULL,
-                  (TDD_Config_t *)NULL,
-                  (MobilityControlInfo_t *)NULL,
-                  NULL,
-                  NULL,
-                  NULL,
-                  NULL,
-                  NULL,
-                  NULL
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-                  ,0,
-                  (MBSFN_AreaInfoList_r9_t *)NULL,
-                  (PMCH_InfoList_r9_t *)NULL
+        if (LOG_DEBUGFLAG(DEBUG_CTRLSOCKET)) {
+          LOG_UI(RRC,"[PC5EstablishReq] Received on socket from ProSe App (msg type: %d)\n",sl_ctrl_msg_recv->type);
+          LOG_UI(RRC,"[PC5EstablishReq] type: %d\n",sl_ctrl_msg_recv->sidelinkPrimitive.pc5s_establish_req.type); //RX/TX
+          LOG_UI(RRC,"[PC5EstablishReq] source Id: 0x%08x \n",sl_ctrl_msg_recv->sidelinkPrimitive.pc5s_establish_req.sourceL2Id);
+        }
 
-#endif
-#ifdef CBA
-                  ,
-                  0,
-                  0
-#endif
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-                  ,CONFIG_ACTION_ADD,
-                  &sourceL2Id,
-                  NULL
-#endif
-            );
-
-         }
-
-         LOG_I(RRC,"Send PC5EstablishRsp to ProSe App\n");
-         memset(send_buf, 0, BUFSIZE);
-         sl_ctrl_msg_send = calloc(1, sizeof(struct sidelink_ctrl_element));
-         sl_ctrl_msg_send->type = PC5S_ESTABLISH_RSP;
-         sl_ctrl_msg_send->sidelinkPrimitive.pc5s_establish_rsp.slrbid_lcid28 = 10;
-         sl_ctrl_msg_send->sidelinkPrimitive.pc5s_establish_rsp.slrbid_lcid29 = 10;
-         sl_ctrl_msg_send->sidelinkPrimitive.pc5s_establish_rsp.slrbid_lcid30 = 10;
-         memcpy((void *)send_buf, (void *)sl_ctrl_msg_send, sizeof(struct sidelink_ctrl_element));
-
-         prose_addr_len = sizeof(prose_app_addr);
-         n = sendto(ctrl_sock_fd, (char *)send_buf, sizeof(struct sidelink_ctrl_element), 0, (struct sockaddr *)&prose_app_addr, prose_addr_len);
-//         free(sl_ctrl_msg_send);
-         if (n < 0){
-            LOG_E(RRC, "ERROR: Failed to send to ProSe App\n");
-            exit(EXIT_FAILURE);
-         }
-         break;
+        if (type > 0) {
+          destinationL2Id = sl_ctrl_msg_recv->sidelinkPrimitive.pc5s_establish_req.destinationL2Id;
 
+          if (LOG_DEBUGFLAG(DEBUG_CTRLSOCKET)) {
+            LOG_UI(RRC,"[PC5EstablishReq] destination Id: 0x%08x \n",sl_ctrl_msg_recv->sidelinkPrimitive.pc5s_establish_req.destinationL2Id);
+          }
+        }
 
-      case PC5_DISCOVERY_MESSAGE:
+        //store sourceL2Id/destinationL2Id
+        if (type > 0) { //TX
+          UE_rrc_inst[module_id].sourceL2Id = sourceL2Id;
+          j = 0;
+          i = 0;
 
-         if (LOG_DEBUGFLAG(DEBUG_CTRLSOCKET)){
-           LOG_UI(RRC,"[PC5DiscoveryMessage] Received on socket from ProSe App (msg type: %d)\n",sl_ctrl_msg_recv->type);
-         }
-        //prepare SL_Discovery buffer
-         if (UE_rrc_inst) {
-           memcpy((void*)&UE_rrc_inst[module_id].SL_Discovery[0].Tx_buffer.Payload[0], (void*)&sl_ctrl_msg_recv->sidelinkPrimitive.pc5_discovery_message.payload[0], PC5_DISCOVERY_PAYLOAD_SIZE);
-           UE_rrc_inst[module_id].SL_Discovery[0].Tx_buffer.payload_size = PC5_DISCOVERY_PAYLOAD_SIZE;
-           LOG_I(RRC,"[PC5DiscoveryMessage] Copied %d bytes\n",PC5_DISCOVERY_PAYLOAD_SIZE);
-         }
-         break;
-      default:
-         break;
-      }
-   }
-   free (sl_ctrl_msg_recv);
-   return 0;
-}
+          for (i=0; i< MAX_NUM_DEST; i++) {
+            if ((UE_rrc_inst[module_id].destinationList[i] == 0) && (j == 0)) j = i+1;
 
+            if (UE_rrc_inst[module_id].destinationList[i] == destinationL2Id) break; //group already exists!
+          }
 
-//-----------------------------------------------------------------------------
-int decode_SL_Discovery_Message(
-  const protocol_ctxt_t* const ctxt_pP,
-  const uint8_t                eNB_index,
-  const uint8_t*               Sdu,
-  const uint8_t                Sdu_len)
-{
+          if ((i == MAX_NUM_DEST) && (j > 0))  UE_mac_inst[module_id].destinationList[j-1] = destinationL2Id;
+        } else {//RX
+          UE_rrc_inst[module_id].sourceL2Id = sourceL2Id;
+        }
 
-   int prose_addr_len;
-   char send_buf[BUFSIZE];
-   int n;
-   struct sidelink_ctrl_element *sl_ctrl_msg_send = NULL;
+        // configure lower layers PDCP/MAC/PHY for this communication
+        //Establish a new RBID/LCID for this communication
+        // Establish a SLRB (using DRB 10 for now)
+        UE  = &UE_rrc_inst[module_id];
+        PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, 0, ENB_FLAG_NO, 0x1234, 0, 0,0);
+        UE->DRB_config[0][0] = CALLOC(1,sizeof(struct LTE_DRB_ToAddMod));
+        UE->DRB_config[0][0]->eps_BearerIdentity = CALLOC(1, sizeof(long));
+        UE->DRB_config[0][0]->drb_Identity =  10;
+        UE->DRB_config[0][0]->eps_BearerIdentity = CALLOC(1, sizeof(long));
+        // allowed value 5..15, value : x+4
+        *(UE->DRB_config[0][0]->eps_BearerIdentity) = 10;
+        UE->DRB_config[0][0]->logicalChannelIdentity = CALLOC(1, sizeof(long));
+        *(UE->DRB_config[0][0]->logicalChannelIdentity) = UE->DRB_config[0][0]->drb_Identity; //(long) (ue_context_pP->ue_context.e_rab[i].param.e_rab_id + 2); // value : x+2
+        DRB_rlc_config                   = CALLOC(1,sizeof(struct LTE_RLC_Config));
+        DRB_pdcp_config                  = CALLOC(1,sizeof(struct LTE_PDCP_Config));
+        PDCP_rlc_UM                      = CALLOC(1,sizeof(struct LTE_PDCP_Config__rlc_UM));
+        DRB_lchan_config                 = CALLOC(1,sizeof(struct LTE_LogicalChannelConfig));
+        DRB_ul_SpecificParameters                                         = CALLOC(1, sizeof(struct LTE_LogicalChannelConfig__ul_SpecificParameters));
+        logicalchannelgroup_drb          = CALLOC(1, sizeof(long));
+        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;
+        UE->DRB_config[0][0]->rlc_Config = DRB_rlc_config;
+        DRB_pdcp_config = CALLOC(1, sizeof(*DRB_pdcp_config));
+        UE->DRB_config[0][0]->pdcp_Config = DRB_pdcp_config;
+        DRB_pdcp_config->discardTimer = CALLOC(1, sizeof(long));
+        *DRB_pdcp_config->discardTimer = LTE_PDCP_Config__discardTimer_infinity;
+        DRB_pdcp_config->rlc_AM = NULL;
+        DRB_pdcp_config->rlc_UM = NULL;
+        /* avoid gcc warnings */
+        (void)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;
+        UE->DRB_config[0][0]->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 = 12;    // lower priority than srb1, srb2 and other dedicated bearer
+        DRB_ul_SpecificParameters->prioritisedBitRate = LTE_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_kBps8 ;
+        //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 = 1;
+        DRB_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup_drb;
+        UE->DRB_configList = CALLOC(1,sizeof(LTE_DRB_ToAddModList_t));
+        ASN_SEQUENCE_ADD(&UE->DRB_configList->list,UE->DRB_config[0][0]);
+        rrc_pdcp_config_asn1_req(&ctxt,
+                                 (LTE_SRB_ToAddModList_t *) NULL,
+                                 UE->DRB_configList,
+                                 (LTE_DRB_ToReleaseList_t *) NULL,
+                                 0xff, NULL, NULL, NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                                 , (LTE_PMCH_InfoList_r9_t *) NULL
+#endif
+                                 ,NULL);
+        rrc_rlc_config_asn1_req(&ctxt,
+                                (LTE_SRB_ToAddModList_t *)NULL,
+                                UE->DRB_configList,
+                                (LTE_DRB_ToReleaseList_t *)NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                                ,(LTE_PMCH_InfoList_r9_t *)NULL
+                                , 0, 0
+#endif
+                               );
 
-   //from the main program, listen for the incoming messages from control socket (ProSe App)
-   prose_addr_len = sizeof(prose_app_addr);
+        //TX
+        if (type > 0) {
+          rrc_rlc_config_asn1_req(&ctxt,
+                                  (LTE_SRB_ToAddModList_t *)NULL,
+                                  UE->DRB_configList,
+                                  (LTE_DRB_ToReleaseList_t *)NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                                  ,(LTE_PMCH_InfoList_r9_t *)NULL
+                                  , sourceL2Id, destinationL2Id
+#endif
+                                 );
+          //configure MAC with sourceL2Id/groupL2ID
+          rrc_mac_config_req_ue(module_id,0,0, //eNB_index =0
+                                (LTE_RadioResourceConfigCommonSIB_t *)NULL,
+                                (struct LTE_PhysicalConfigDedicated *)NULL,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                                (LTE_SCellToAddMod_r10_t *)NULL,
+                                //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
+#endif
+                                (LTE_MeasObjectToAddMod_t **)NULL,
+                                (LTE_MAC_MainConfig_t *)NULL,
+                                10, //LCID
+                                (struct LTE_LogicalChannelConfig *)NULL,
+                                (LTE_MeasGapConfig_t *)NULL,
+                                (LTE_TDD_Config_t *)NULL,
+                                (LTE_MobilityControlInfo_t *)NULL,
+                                NULL,
+                                NULL,
+                                NULL,
+                                NULL,
+                                NULL,
+                                NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                                ,0,
+                                (LTE_MBSFN_AreaInfoList_r9_t *)NULL,
+                                (LTE_PMCH_InfoList_r9_t *)NULL
+#endif
+#ifdef CBA
+                                ,
+                                0,
+                                0
+#endif
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                                ,CONFIG_ACTION_ADD,
+                                &sourceL2Id,
+                                &destinationL2Id
+#endif
+                               );
+        } else {//RX
+          //configure MAC with sourceL2Id/groupL2ID
+          rrc_mac_config_req_ue(module_id,0,0, //eNB_index =0
+                                (LTE_RadioResourceConfigCommonSIB_t *)NULL,
+                                (struct LTE_PhysicalConfigDedicated *)NULL,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                                (LTE_SCellToAddMod_r10_t *)NULL,
+                                //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
+#endif
+                                (LTE_MeasObjectToAddMod_t **)NULL,
+                                (LTE_MAC_MainConfig_t *)NULL,
+                                10, //LCID
+                                (struct LTE_LogicalChannelConfig *)NULL,
+                                (LTE_MeasGapConfig_t *)NULL,
+                                (LTE_TDD_Config_t *)NULL,
+                                (LTE_MobilityControlInfo_t *)NULL,
+                                NULL,
+                                NULL,
+                                NULL,
+                                NULL,
+                                NULL,
+                                NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                                ,0,
+                                (LTE_MBSFN_AreaInfoList_r9_t *)NULL,
+                                (LTE_PMCH_InfoList_r9_t *)NULL
+#endif
+#ifdef CBA
+                                ,
+                                0,
+                                0
+#endif
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                                ,CONFIG_ACTION_ADD,
+                                &sourceL2Id,
+                                NULL
+#endif
+                               );
+        }
 
-   //Store in Rx_buffer
-   memcpy((void*)&UE_rrc_inst[ctxt_pP->module_id].SL_Discovery[0].Rx_buffer.Payload[0], (void*)Sdu, Sdu_len);
-   UE_rrc_inst[ctxt_pP->module_id].SL_Discovery[0].Rx_buffer.payload_size = Sdu_len;
+        LOG_I(RRC,"Send PC5EstablishRsp to ProSe App\n");
+        memset(send_buf, 0, BUFSIZE);
+        sl_ctrl_msg_send = calloc(1, sizeof(struct sidelink_ctrl_element));
+        sl_ctrl_msg_send->type = PC5S_ESTABLISH_RSP;
+        sl_ctrl_msg_send->sidelinkPrimitive.pc5s_establish_rsp.slrbid_lcid28 = 10;
+        sl_ctrl_msg_send->sidelinkPrimitive.pc5s_establish_rsp.slrbid_lcid29 = 10;
+        sl_ctrl_msg_send->sidelinkPrimitive.pc5s_establish_rsp.slrbid_lcid30 = 10;
+        memcpy((void *)send_buf, (void *)sl_ctrl_msg_send, sizeof(struct sidelink_ctrl_element));
+        prose_addr_len = sizeof(prose_app_addr);
+        n = sendto(ctrl_sock_fd, (char *)send_buf, sizeof(struct sidelink_ctrl_element), 0, (struct sockaddr *)&prose_app_addr, prose_addr_len);
+
+        //         free(sl_ctrl_msg_send);
+        if (n < 0) {
+          LOG_E(RRC, "ERROR: Failed to send to ProSe App\n");
+          exit(EXIT_FAILURE);
+        }
 
-   memset(send_buf, 0, BUFSIZE);
-   //send to ProSeApp
-   memcpy((void *)send_buf, (void*)Sdu, Sdu_len);
-   prose_addr_len = sizeof(prose_app_addr);
+        break;
 
-   sl_ctrl_msg_send = calloc(1, sizeof(struct sidelink_ctrl_element));
-   sl_ctrl_msg_send->type = PC5_DISCOVERY_MESSAGE;
-   // TODO:  Add a check for the SDU size.
-   memcpy((void*)&sl_ctrl_msg_send->sidelinkPrimitive.pc5_discovery_message.payload[0], (void*) Sdu,  PC5_DISCOVERY_PAYLOAD_SIZE);
+      case PC5_DISCOVERY_MESSAGE:
+        if (LOG_DEBUGFLAG(DEBUG_CTRLSOCKET)) {
+          LOG_UI(RRC,"[PC5DiscoveryMessage] Received on socket from ProSe App (msg type: %d)\n",sl_ctrl_msg_recv->type);
+        }
 
-   memcpy((void *)send_buf, (void *)sl_ctrl_msg_send, sizeof(struct sidelink_ctrl_element));
-   free(sl_ctrl_msg_send);
+        //prepare SL_Discovery buffer
+        if (UE_rrc_inst) {
+          memcpy((void *)&UE_rrc_inst[module_id].SL_Discovery[0].Tx_buffer.Payload[0], (void *)&sl_ctrl_msg_recv->sidelinkPrimitive.pc5_discovery_message.payload[0], PC5_DISCOVERY_PAYLOAD_SIZE);
+          UE_rrc_inst[module_id].SL_Discovery[0].Tx_buffer.payload_size = PC5_DISCOVERY_PAYLOAD_SIZE;
+          LOG_I(RRC,"[PC5DiscoveryMessage] Copied %d bytes\n",PC5_DISCOVERY_PAYLOAD_SIZE);
+        }
 
-   prose_addr_len = sizeof(prose_app_addr);
+        break;
 
-   n = sendto(ctrl_sock_fd, (char *)send_buf, sizeof(struct sidelink_ctrl_element), 0, (struct sockaddr *)&prose_app_addr, prose_addr_len);
-   if (n < 0){
-      // TODO:  We should not just exit if the Prose App has not yet attached.  It creates a race condition.
-      LOG_I(RRC, "ERROR: Failed to send to ProSe App\n");
-      //exit(EXIT_FAILURE);
-   }
+      default:
+        break;
+    }
+  }
 
+  free (sl_ctrl_msg_recv);
+  return 0;
+}
 
 
+//-----------------------------------------------------------------------------
+int decode_SL_Discovery_Message(
+  const protocol_ctxt_t *const ctxt_pP,
+  const uint8_t                eNB_index,
+  const uint8_t               *Sdu,
+  const uint8_t                Sdu_len) {
+  int prose_addr_len;
+  char send_buf[BUFSIZE];
+  int n;
+  struct sidelink_ctrl_element *sl_ctrl_msg_send = NULL;
+  //from the main program, listen for the incoming messages from control socket (ProSe App)
+  prose_addr_len = sizeof(prose_app_addr);
+  //Store in Rx_buffer
+  memcpy((void *)&UE_rrc_inst[ctxt_pP->module_id].SL_Discovery[0].Rx_buffer.Payload[0], (void *)Sdu, Sdu_len);
+  UE_rrc_inst[ctxt_pP->module_id].SL_Discovery[0].Rx_buffer.payload_size = Sdu_len;
+  memset(send_buf, 0, BUFSIZE);
+  //send to ProSeApp
+  memcpy((void *)send_buf, (void *)Sdu, Sdu_len);
+  prose_addr_len = sizeof(prose_app_addr);
+  sl_ctrl_msg_send = calloc(1, sizeof(struct sidelink_ctrl_element));
+  sl_ctrl_msg_send->type = PC5_DISCOVERY_MESSAGE;
+  // TODO:  Add a check for the SDU size.
+  memcpy((void *)&sl_ctrl_msg_send->sidelinkPrimitive.pc5_discovery_message.payload[0], (void *) Sdu,  PC5_DISCOVERY_PAYLOAD_SIZE);
+  memcpy((void *)send_buf, (void *)sl_ctrl_msg_send, sizeof(struct sidelink_ctrl_element));
+  free(sl_ctrl_msg_send);
+  prose_addr_len = sizeof(prose_app_addr);
+  n = sendto(ctrl_sock_fd, (char *)send_buf, sizeof(struct sidelink_ctrl_element), 0, (struct sockaddr *)&prose_app_addr, prose_addr_len);
+
+  if (n < 0) {
+    // TODO:  We should not just exit if the Prose App has not yet attached.  It creates a race condition.
+    LOG_I(RRC, "ERROR: Failed to send to ProSe App\n");
+    //exit(EXIT_FAILURE);
+  }
+
   return(0);
 }
 
@@ -6331,112 +5813,111 @@ int decode_SL_Discovery_Message(
 //-----------------------------------------------------------------------------
 RRC_status_t
 rrc_rx_tx_ue(
-  protocol_ctxt_t* const ctxt_pP,
+  protocol_ctxt_t *const ctxt_pP,
   const uint8_t      enb_indexP,
   const int          CC_id
 )
 //-----------------------------------------------------------------------------
 {
-
 #ifdef LOCALIZATION
   double                         estimated_distance;
   protocol_ctxt_t                ctxt;
 #endif
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX,VCD_FUNCTION_IN);
 
-    // check timers
-
-    if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T300_active == 1) {
-      if ((UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T300_cnt % 10) == 0)
-        LOG_D(RRC,
-              "[UE %d][RAPROC] Frame %d T300 Count %d ms\n", ctxt_pP->module_id, ctxt_pP->frame, UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T300_cnt);
-
-      if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T300_cnt
-          == T300[UE_rrc_inst[ctxt_pP->module_id].sib2[enb_indexP]->ue_TimersAndConstants.t300]) {
-        UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T300_active = 0;
-        // ALLOW CCCH to be used
-        UE_rrc_inst[ctxt_pP->module_id].Srb0[enb_indexP].Tx_buffer.payload_size = 0;
-        rrc_ue_generate_RRCConnectionRequest (ctxt_pP, enb_indexP);
-        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX,VCD_FUNCTION_OUT);
-        return (RRC_ConnSetup_failed);
-      }
-
-      UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T300_cnt++;
-    }
+  // check timers
 
-    if ((UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].SIStatus&2)>0) {
-      if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].N310_cnt
-          == N310[UE_rrc_inst[ctxt_pP->module_id].sib2[enb_indexP]->ue_TimersAndConstants.n310]) {
-	LOG_I(RRC,"Activating T310\n");
-        UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_active = 1;
-      }
-    } else { // in case we have not received SIB2 yet
-      /*      if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].N310_cnt == 100) {
-        UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].N310_cnt = 0;
+  if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T300_active == 1) {
+    if ((UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T300_cnt % 10) == 0)
+      LOG_D(RRC,
+            "[UE %d][RAPROC] Frame %d T300 Count %d ms\n", ctxt_pP->module_id, ctxt_pP->frame, UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T300_cnt);
 
-	}*/
+    if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T300_cnt
+        == T300[UE_rrc_inst[ctxt_pP->module_id].sib2[enb_indexP]->ue_TimersAndConstants.t300]) {
+      UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T300_active = 0;
+      // ALLOW CCCH to be used
+      UE_rrc_inst[ctxt_pP->module_id].Srb0[enb_indexP].Tx_buffer.payload_size = 0;
+      rrc_ue_generate_RRCConnectionRequest (ctxt_pP, enb_indexP);
       VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX,VCD_FUNCTION_OUT);
-      return RRC_OK;
+      return (RRC_ConnSetup_failed);
     }
 
-    if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_active == 1) {
-      if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].N311_cnt
-          == N311[UE_rrc_inst[ctxt_pP->module_id].sib2[enb_indexP]->ue_TimersAndConstants.n311]) {
-        UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_active = 0;
-        UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].N311_cnt = 0;
-      }
-
-      if ((UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_cnt % 10) == 0) {
-        LOG_D(RRC, "[UE %d] Frame %d T310 Count %d ms\n", ctxt_pP->module_id, ctxt_pP->frame, UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_cnt);
-      }
-
-      if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_cnt    == T310[UE_rrc_inst[ctxt_pP->module_id].sib2[enb_indexP]->ue_TimersAndConstants.t310]) {
-        UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_active = 0;
-        rrc_t310_expiration (ctxt_pP, enb_indexP);
-        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX,VCD_FUNCTION_OUT);
-	LOG_I(RRC,"Returning RRC_PHY_RESYNCH: T310 expired\n"); 
-        return RRC_PHY_RESYNCH;
-      }
+    UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T300_cnt++;
+  }
 
-      UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_cnt++;
+  if ((UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].SIStatus&2)>0) {
+    if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].N310_cnt
+        == N310[UE_rrc_inst[ctxt_pP->module_id].sib2[enb_indexP]->ue_TimersAndConstants.n310]) {
+      LOG_I(RRC,"Activating T310\n");
+      UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_active = 1;
     }
+  } else { // in case we have not received SIB2 yet
+    /*      if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].N310_cnt == 100) {
+      UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].N310_cnt = 0;
 
-    if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T304_active==1) {
-      if ((UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T304_cnt % 10) == 0)
-        LOG_D(RRC,"[UE %d][RAPROC] Frame %d T304 Count %d ms\n",ctxt_pP->module_id,ctxt_pP->frame,
-              UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T304_cnt);
+    }*/
+    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX,VCD_FUNCTION_OUT);
+    return RRC_OK;
+  }
 
-      if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T304_cnt == 0) {
-        UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T304_active = 0;
-        UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.measFlag = 1;
-        LOG_E(RRC,"[UE %d] Handover failure..initiating connection re-establishment procedure... \n",
-              ctxt_pP->module_id);
-        //Implement 36.331, section 5.3.5.6 here
-        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX,VCD_FUNCTION_OUT);
-        return(RRC_Handover_failed);
-      }
+  if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_active == 1) {
+    if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].N311_cnt
+        == N311[UE_rrc_inst[ctxt_pP->module_id].sib2[enb_indexP]->ue_TimersAndConstants.n311]) {
+      UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_active = 0;
+      UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].N311_cnt = 0;
+    }
 
-      UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T304_cnt--;
+    if ((UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_cnt % 10) == 0) {
+      LOG_D(RRC, "[UE %d] Frame %d T310 Count %d ms\n", ctxt_pP->module_id, ctxt_pP->frame, UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_cnt);
     }
 
-    // Layer 3 filtering of RRC measurements
-    if (UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[0] != NULL) {
-      ue_meas_filtering(ctxt_pP,enb_indexP);
+    if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_cnt    == T310[UE_rrc_inst[ctxt_pP->module_id].sib2[enb_indexP]->ue_TimersAndConstants.t310]) {
+      UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_active = 0;
+      rrc_t310_expiration (ctxt_pP, enb_indexP);
+      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX,VCD_FUNCTION_OUT);
+      LOG_I(RRC,"Returning RRC_PHY_RESYNCH: T310 expired\n");
+      return RRC_PHY_RESYNCH;
     }
 
-    ue_measurement_report_triggering(ctxt_pP,enb_indexP);
+    UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_cnt++;
+  }
 
-    if (UE_rrc_inst[ctxt_pP->module_id].Info[0].handoverTarget > 0) {
-      LOG_I(RRC,"[UE %d] Frame %d : RRC handover initiated\n", ctxt_pP->module_id, ctxt_pP->frame);
-    }
+  if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T304_active==1) {
+    if ((UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T304_cnt % 10) == 0)
+      LOG_D(RRC,"[UE %d][RAPROC] Frame %d T304 Count %d ms\n",ctxt_pP->module_id,ctxt_pP->frame,
+            UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T304_cnt);
 
-    if((UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].State == RRC_HO_EXECUTION)   &&
-        (UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.targetCellId != 0xFF)) {
-      UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].State= RRC_IDLE;
+    if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T304_cnt == 0) {
+      UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T304_active = 0;
+      UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.measFlag = 1;
+      LOG_E(RRC,"[UE %d] Handover failure..initiating connection re-establishment procedure... \n",
+            ctxt_pP->module_id);
+      //Implement 36.331, section 5.3.5.6 here
       VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX,VCD_FUNCTION_OUT);
-      return(RRC_HO_STARTED);
+      return(RRC_Handover_failed);
     }
 
+    UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T304_cnt--;
+  }
+
+  // Layer 3 filtering of RRC measurements
+  if (UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[0] != NULL) {
+    ue_meas_filtering(ctxt_pP,enb_indexP);
+  }
+
+  ue_measurement_report_triggering(ctxt_pP,enb_indexP);
+
+  if (UE_rrc_inst[ctxt_pP->module_id].Info[0].handoverTarget > 0) {
+    LOG_I(RRC,"[UE %d] Frame %d : RRC handover initiated\n", ctxt_pP->module_id, ctxt_pP->frame);
+  }
+
+  if((UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].State == RRC_HO_EXECUTION)   &&
+      (UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.targetCellId != 0xFF)) {
+    UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].State= RRC_IDLE;
+    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX,VCD_FUNCTION_OUT);
+    return(RRC_HO_STARTED);
+  }
+
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX,VCD_FUNCTION_OUT);
   return (RRC_OK);
 }
diff --git a/openair2/RRC/LTE/rrc_defs.h b/openair2/RRC/LTE/rrc_defs.h
index d34cc390c66da386f9454159bca5b22cf2e94016..1ff91b8d995ba449bbef85c7a6341da82e45f7fe 100644
--- a/openair2/RRC/LTE/rrc_defs.h
+++ b/openair2/RRC/LTE/rrc_defs.h
@@ -65,10 +65,10 @@
 
 #define IPV4_ADDR    "%u.%u.%u.%u"
 #define IPV4_ADDR_FORMAT(aDDRESS)                 \
-      (uint8_t)((aDDRESS)  & 0x000000ff),         \
-      (uint8_t)(((aDDRESS) & 0x0000ff00) >> 8 ),  \
-      (uint8_t)(((aDDRESS) & 0x00ff0000) >> 16),  \
-      (uint8_t)(((aDDRESS) & 0xff000000) >> 24)
+  (uint8_t)((aDDRESS)  & 0x000000ff),         \
+  (uint8_t)(((aDDRESS) & 0x0000ff00) >> 8 ),  \
+  (uint8_t)(((aDDRESS) & 0x00ff0000) >> 16),  \
+  (uint8_t)(((aDDRESS) & 0xff000000) >> 24)
 
 
 //-----------------------------------------------------
@@ -85,74 +85,74 @@
 #define GROUP_COMMUNICATION_RELEASE_RSP     8
 #define PC5S_ESTABLISH_REQ                  9
 #define PC5S_ESTABLISH_RSP                  10
-#define PC5_DISCOVERY_MESSAGE          	  11
+#define PC5_DISCOVERY_MESSAGE             11
 
 
-#define PC5_DISCOVERY_PAYLOAD_SIZE	    29
+#define PC5_DISCOVERY_PAYLOAD_SIZE      29
 
 
 typedef enum {
-   UE_STATE_OFF_NETWORK,
-   UE_STATE_ON_NETWORK
+  UE_STATE_OFF_NETWORK,
+  UE_STATE_ON_NETWORK
 } SL_UE_STATE_t;
 
 typedef enum {
-   GROUP_COMMUNICATION_RELEASE_OK = 0,
-   GROUP_COMMUNICATION_RELEASE_FAILURE
+  GROUP_COMMUNICATION_RELEASE_OK = 0,
+  GROUP_COMMUNICATION_RELEASE_FAILURE
 } Group_Communication_Status_t;
 
 struct GroupCommunicationEstablishReq {
-   uint32_t sourceL2Id;
-   uint32_t groupL2Id;
-   uint32_t groupIpAddress;
-   uint8_t pppp;
+  uint32_t sourceL2Id;
+  uint32_t groupL2Id;
+  uint32_t groupIpAddress;
+  uint8_t pppp;
 };
 
 struct GroupCommunicationReleaseReq {
-   uint32_t sourceL2Id;
-   uint32_t groupL2Id;
-   int slrb_id;
+  uint32_t sourceL2Id;
+  uint32_t groupL2Id;
+  int slrb_id;
 };
 
 struct DirectCommunicationEstablishReq {
-   uint32_t sourceL2Id;
-   uint32_t destinationL2Id;
-   uint32_t pppp;
+  uint32_t sourceL2Id;
+  uint32_t destinationL2Id;
+  uint32_t pppp;
 };
 
-struct PC5SEstablishReq{
-   uint8_t type;
-   uint32_t sourceL2Id;
-   uint32_t destinationL2Id;
+struct PC5SEstablishReq {
+  uint8_t type;
+  uint32_t sourceL2Id;
+  uint32_t destinationL2Id;
 };
 
-struct PC5SEstablishRsp{
-   uint32_t slrbid_lcid28;
-   uint32_t slrbid_lcid29;
-   uint32_t slrbid_lcid30;
+struct PC5SEstablishRsp {
+  uint32_t slrbid_lcid28;
+  uint32_t slrbid_lcid29;
+  uint32_t slrbid_lcid30;
 };
 
 
 //PC5_DISCOVERY MESSAGE
 typedef struct  {
-   unsigned char payload[PC5_DISCOVERY_PAYLOAD_SIZE];
-   uint32_t measuredPower;
+  unsigned char payload[PC5_DISCOVERY_PAYLOAD_SIZE];
+  uint32_t measuredPower;
 }  __attribute__((__packed__)) PC5DiscoveryMessage ;
 
 
 struct sidelink_ctrl_element {
-   unsigned short type;
-   union {
-      struct GroupCommunicationEstablishReq group_comm_establish_req;
-      struct DirectCommunicationEstablishReq direct_comm_establish_req;
-      Group_Communication_Status_t group_comm_release_rsp;
-      //struct DirectCommunicationReleaseReq  direct_comm_release_req;
-      SL_UE_STATE_t ue_state;
-      int slrb_id;
-      struct PC5SEstablishReq pc5s_establish_req;
-      struct PC5SEstablishRsp pc5s_establish_rsp;
-      PC5DiscoveryMessage pc5_discovery_message;
-   } sidelinkPrimitive;
+  unsigned short type;
+  union {
+    struct GroupCommunicationEstablishReq group_comm_establish_req;
+    struct DirectCommunicationEstablishReq direct_comm_establish_req;
+    Group_Communication_Status_t group_comm_release_rsp;
+    //struct DirectCommunicationReleaseReq  direct_comm_release_req;
+    SL_UE_STATE_t ue_state;
+    int slrb_id;
+    struct PC5SEstablishReq pc5s_establish_req;
+    struct PC5SEstablishRsp pc5s_establish_rsp;
+    PC5DiscoveryMessage pc5_discovery_message;
+  } sidelinkPrimitive;
 };
 
 
@@ -168,33 +168,33 @@ void *send_UE_status_notification(void *);
 
 //#include "COMMON/openair_defs.h"
 #ifndef USER_MODE
-//#include <rtai.h>
+  //#include <rtai.h>
 #endif
 
-#include "SystemInformationBlockType1.h"
-#include "SystemInformation.h"
-#include "RRCConnectionReconfiguration.h"
-#include "RRCConnectionReconfigurationComplete.h"
-#include "RRCConnectionSetup.h"
-#include "RRCConnectionSetupComplete.h"
-#include "RRCConnectionRequest.h"
-#include "RRCConnectionReestablishmentRequest.h"
-#include "BCCH-DL-SCH-Message.h"
-#include "SBCCH-SL-BCH-MessageType.h"
-#include "BCCH-BCH-Message.h"
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-#include "MCCH-Message.h"
-#include "MBSFNAreaConfiguration-r9.h"
+#include "LTE_SystemInformationBlockType1.h"
+#include "LTE_SystemInformation.h"
+#include "LTE_RRCConnectionReconfiguration.h"
+#include "LTE_RRCConnectionReconfigurationComplete.h"
+#include "LTE_RRCConnectionSetup.h"
+#include "LTE_RRCConnectionSetupComplete.h"
+#include "LTE_RRCConnectionRequest.h"
+#include "LTE_RRCConnectionReestablishmentRequest.h"
+#include "LTE_BCCH-DL-SCH-Message.h"
+#include "LTE_SBCCH-SL-BCH-MessageType.h"
+#include "LTE_BCCH-BCH-Message.h"
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+  #include "LTE_MCCH-Message.h"
+  #include "LTE_MBSFNAreaConfiguration-r9.h"
 #endif
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-#include "SCellToAddMod-r10.h"
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+  #include "LTE_SCellToAddMod-r10.h"
 #endif
-#include "AS-Config.h"
-#include "AS-Context.h"
-#include "UE-EUTRA-Capability.h"
-#include "MeasResults.h"
-#if (RRC_VERSION >= MAKE_VERSION(12, 0, 0))
-#include "SidelinkUEInformation-r12.h"
+#include "LTE_AS-Config.h"
+#include "LTE_AS-Context.h"
+#include "LTE_UE-EUTRA-Capability.h"
+#include "LTE_MeasResults.h"
+#if (LTE_RRC_VERSION >= MAKE_VERSION(12, 0, 0))
+  #include "LTE_SidelinkUEInformation-r12.h"
 #endif
 
 /* for ImsiMobileIdentity_t */
@@ -203,67 +203,67 @@ void *send_UE_status_notification(void *);
 /* correct Rel(8|10)/Rel14 differences
  * the code is in favor of Rel14, those defines do the translation
  */
-#if (RRC_VERSION < MAKE_VERSION(14, 0, 0))
-#  define CipheringAlgorithm_r12_t e_SecurityAlgorithmConfig__cipheringAlgorithm
-#  define CipheringAlgorithm_r12_eea0 SecurityAlgorithmConfig__cipheringAlgorithm_eea0
-#  define CipheringAlgorithm_r12_eea1 SecurityAlgorithmConfig__cipheringAlgorithm_eea1
-#  define CipheringAlgorithm_r12_eea2 SecurityAlgorithmConfig__cipheringAlgorithm_eea2
-#  define CipheringAlgorithm_r12_spare1 SecurityAlgorithmConfig__cipheringAlgorithm_spare1
-#  define Alpha_r12_al0 UplinkPowerControlCommon__alpha_al0
-#  define Alpha_r12_al04 UplinkPowerControlCommon__alpha_al04
-#  define Alpha_r12_al05 UplinkPowerControlCommon__alpha_al05
-#  define Alpha_r12_al06 UplinkPowerControlCommon__alpha_al06
-#  define Alpha_r12_al07 UplinkPowerControlCommon__alpha_al07
-#  define Alpha_r12_al08 UplinkPowerControlCommon__alpha_al08
-#  define Alpha_r12_al09 UplinkPowerControlCommon__alpha_al09
-#  define Alpha_r12_al1 UplinkPowerControlCommon__alpha_al1
-#  define PreambleTransMax_n3 RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n3
-#  define PreambleTransMax_n4 RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n4
-#  define PreambleTransMax_n5 RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n5
-#  define PreambleTransMax_n6 RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n6
-#  define PreambleTransMax_n7 RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n7
-#  define PreambleTransMax_n8 RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n8
-#  define PreambleTransMax_n10 RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n10
-#  define PreambleTransMax_n20 RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n20
-#  define PreambleTransMax_n50 RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n50
-#  define PreambleTransMax_n100 RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n100
-#  define PreambleTransMax_n200 RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n200
-#  define PeriodicBSR_Timer_r12_sf5 MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_sf5
-#  define PeriodicBSR_Timer_r12_sf10 MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_sf10
-#  define PeriodicBSR_Timer_r12_sf16 MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_sf16
-#  define PeriodicBSR_Timer_r12_sf20 MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_sf20
-#  define PeriodicBSR_Timer_r12_sf32 MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_sf32
-#  define PeriodicBSR_Timer_r12_sf40 MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_sf40
-#  define PeriodicBSR_Timer_r12_sf64 MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_sf64
-#  define PeriodicBSR_Timer_r12_sf80 MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_sf80
-#  define PeriodicBSR_Timer_r12_sf128 MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_sf128
-#  define PeriodicBSR_Timer_r12_sf160 MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_sf160
-#  define PeriodicBSR_Timer_r12_sf320 MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_sf320
-#  define PeriodicBSR_Timer_r12_sf640 MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_sf640
-#  define PeriodicBSR_Timer_r12_sf1280 MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_sf1280
-#  define PeriodicBSR_Timer_r12_sf2560 MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_sf2560
-#  define PeriodicBSR_Timer_r12_infinity MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_infinity
-#  define RetxBSR_Timer_r12_sf320 MAC_MainConfig__ul_SCH_Config__retxBSR_Timer_sf320
-#  define RetxBSR_Timer_r12_sf640 MAC_MainConfig__ul_SCH_Config__retxBSR_Timer_sf640
-#  define RetxBSR_Timer_r12_sf1280 MAC_MainConfig__ul_SCH_Config__retxBSR_Timer_sf1280
-#  define RetxBSR_Timer_r12_sf2560 MAC_MainConfig__ul_SCH_Config__retxBSR_Timer_sf2560
-#  define RetxBSR_Timer_r12_sf5120 MAC_MainConfig__ul_SCH_Config__retxBSR_Timer_sf5120
-#  define RetxBSR_Timer_r12_sf10240 MAC_MainConfig__ul_SCH_Config__retxBSR_Timer_sf10240
+#if (LTE_RRC_VERSION < MAKE_VERSION(14, 0, 0))
+  #define CipheringAlgorithm_r12_t e_SecurityAlgorithmConfig__cipheringAlgorithm
+  #define CipheringAlgorithm_r12_eea0 SecurityAlgorithmConfig__cipheringAlgorithm_eea0
+  #define CipheringAlgorithm_r12_eea1 SecurityAlgorithmConfig__cipheringAlgorithm_eea1
+  #define CipheringAlgorithm_r12_eea2 SecurityAlgorithmConfig__cipheringAlgorithm_eea2
+  #define CipheringAlgorithm_r12_spare1 SecurityAlgorithmConfig__cipheringAlgorithm_spare1
+  #define Alpha_r12_al0 UplinkPowerControlCommon__alpha_al0
+  #define Alpha_r12_al04 UplinkPowerControlCommon__alpha_al04
+  #define Alpha_r12_al05 UplinkPowerControlCommon__alpha_al05
+  #define Alpha_r12_al06 UplinkPowerControlCommon__alpha_al06
+  #define Alpha_r12_al07 UplinkPowerControlCommon__alpha_al07
+  #define Alpha_r12_al08 UplinkPowerControlCommon__alpha_al08
+  #define Alpha_r12_al09 UplinkPowerControlCommon__alpha_al09
+  #define Alpha_r12_al1 UplinkPowerControlCommon__alpha_al1
+  #define PreambleTransMax_n3 RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n3
+  #define PreambleTransMax_n4 RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n4
+  #define PreambleTransMax_n5 RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n5
+  #define PreambleTransMax_n6 RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n6
+  #define PreambleTransMax_n7 RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n7
+  #define PreambleTransMax_n8 RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n8
+  #define PreambleTransMax_n10 RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n10
+  #define PreambleTransMax_n20 RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n20
+  #define PreambleTransMax_n50 RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n50
+  #define PreambleTransMax_n100 RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n100
+  #define PreambleTransMax_n200 RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n200
+  #define PeriodicBSR_Timer_r12_sf5 MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_sf5
+  #define PeriodicBSR_Timer_r12_sf10 MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_sf10
+  #define PeriodicBSR_Timer_r12_sf16 MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_sf16
+  #define PeriodicBSR_Timer_r12_sf20 MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_sf20
+  #define PeriodicBSR_Timer_r12_sf32 MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_sf32
+  #define PeriodicBSR_Timer_r12_sf40 MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_sf40
+  #define PeriodicBSR_Timer_r12_sf64 MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_sf64
+  #define PeriodicBSR_Timer_r12_sf80 MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_sf80
+  #define PeriodicBSR_Timer_r12_sf128 MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_sf128
+  #define PeriodicBSR_Timer_r12_sf160 MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_sf160
+  #define PeriodicBSR_Timer_r12_sf320 MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_sf320
+  #define PeriodicBSR_Timer_r12_sf640 MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_sf640
+  #define PeriodicBSR_Timer_r12_sf1280 MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_sf1280
+  #define PeriodicBSR_Timer_r12_sf2560 MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_sf2560
+  #define PeriodicBSR_Timer_r12_infinity MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_infinity
+  #define RetxBSR_Timer_r12_sf320 MAC_MainConfig__ul_SCH_Config__retxBSR_Timer_sf320
+  #define RetxBSR_Timer_r12_sf640 MAC_MainConfig__ul_SCH_Config__retxBSR_Timer_sf640
+  #define RetxBSR_Timer_r12_sf1280 MAC_MainConfig__ul_SCH_Config__retxBSR_Timer_sf1280
+  #define RetxBSR_Timer_r12_sf2560 MAC_MainConfig__ul_SCH_Config__retxBSR_Timer_sf2560
+  #define RetxBSR_Timer_r12_sf5120 MAC_MainConfig__ul_SCH_Config__retxBSR_Timer_sf5120
+  #define RetxBSR_Timer_r12_sf10240 MAC_MainConfig__ul_SCH_Config__retxBSR_Timer_sf10240
 #endif
 
 // This corrects something generated by asn1c which is different between Rel8 and Rel10
-#if (RRC_VERSION <= MAKE_VERSION(10, 0, 0))
-#define SystemInformation_r8_IEs__sib_TypeAndInfo__Member SystemInformation_r8_IEs_sib_TypeAndInfo_Member
-#define SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib2 SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib2
-#define SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib3 SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib3
-#define SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib4 SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib4
-#define SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib5 SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib5
-#define SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib6 SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib6
-#define SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib7 SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib7
-#define SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib8 SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib8
-#define SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib9 SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib9
-#define SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib10 SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib10
-#define SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib11 SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib11
+#if (LTE_RRC_VERSION <= MAKE_VERSION(10, 0, 0))
+  #define SystemInformation_r8_IEs__sib_TypeAndInfo__Member SystemInformation_r8_IEs_sib_TypeAndInfo_Member
+  #define SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib2 SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib2
+  #define SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib3 SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib3
+  #define SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib4 SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib4
+  #define SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib5 SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib5
+  #define SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib6 SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib6
+  #define SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib7 SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib7
+  #define SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib8 SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib8
+  #define SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib9 SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib9
+  #define SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib10 SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib10
+  #define SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib11 SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib11
 #endif
 
 
@@ -273,20 +273,20 @@ void *send_UE_status_notification(void *);
 #define NB_CNX_UE 2//MAX_MANAGED_RG_PER_MOBILE
 
 /*
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 #define SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib12_v920 SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib12_v920
 #define SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib13_v920 SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib13_v920
 #endif
 */
 //#include "L3_rrc_defs.h"
 #ifndef NO_RRM
-#include "L3_rrc_interface.h"
-#include "rrc_rrm_msg.h"
-#include "rrc_rrm_interface.h"
+  #include "L3_rrc_interface.h"
+  #include "rrc_rrm_msg.h"
+  #include "rrc_rrm_interface.h"
 #endif
 
 #if defined(ENABLE_ITTI)
-# include "intertask_interface.h"
+  #include "intertask_interface.h"
 #endif
 
 /* TODO: be sure this include is correct.
@@ -294,11 +294,11 @@ void *send_UE_status_notification(void *);
  * issue #186.
  */
 #if !defined(ENABLE_ITTI)
-# include "as_message.h"
+  #include "as_message.h"
 #endif
 
 #if defined(ENABLE_USE_MME)
-# include "commonDef.h"
+  #include "commonDef.h"
 #endif
 
 //--------
@@ -345,10 +345,13 @@ typedef enum UE_STATE_e {
 
 typedef enum HO_STATE_e {
   HO_IDLE=0,
-  HO_MEASURMENT,
+  HO_MEASUREMENT,
   HO_PREPARE,
   HO_CMD, // initiated by the src eNB
-  HO_COMPLETE // initiated by the target eNB
+  HO_COMPLETE, // initiated by the target eNB
+  HO_REQUEST,
+  HO_ACK,
+  HO_CONFIGURED
 } HO_STATE_t;
 
 typedef enum SL_TRIGGER_e {
@@ -388,10 +391,10 @@ typedef enum SL_TRIGGER_e {
 #define RRC_TRANSACTION_IDENTIFIER_NUMBER  3
 
 typedef struct {
-  unsigned short transport_block_size;                  /*!< \brief Minimum PDU size in bytes provided by RLC to MAC layer interface */
-  unsigned short max_transport_blocks;                  /*!< \brief Maximum PDU size in bytes provided by RLC to MAC layer interface */
-  unsigned long  Guaranteed_bit_rate;           /*!< \brief Guaranteed Bit Rate (average) to be offered by MAC layer scheduling*/
-  unsigned long  Max_bit_rate;                  /*!< \brief Maximum Bit Rate that can be offered by MAC layer scheduling*/
+  unsigned short transport_block_size;   /*!< \brief Minimum PDU size in bytes provided by RLC to MAC layer interface */
+  unsigned short max_transport_blocks;   /*!< \brief Maximum PDU size in bytes provided by RLC to MAC layer interface */
+  unsigned long  Guaranteed_bit_rate;    /*!< \brief Guaranteed Bit Rate (average) to be offered by MAC layer scheduling*/
+  unsigned long  Max_bit_rate;           /*!< \brief Maximum Bit Rate that can be offered by MAC layer scheduling*/
   uint8_t  Delay_class;                  /*!< \brief Delay class offered by MAC layer scheduling*/
   uint8_t  Target_bler;                  /*!< \brief Target Average Transport Block Error rate*/
   uint8_t  Lchan_t;                      /*!< \brief Logical Channel Type (BCCH,CCCH,DCCH,DTCH_B,DTCH,MRBCH)*/
@@ -404,7 +407,7 @@ typedef struct UE_RRC_INFO_s {
   uint8_t SIB1systemInfoValueTag;
   uint32_t SIStatus;
   uint32_t SIcnt;
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
   uint8_t MCCHStatus[8]; // MAX_MBSFN_AREA
 #endif
   uint8_t SIwindowsize; //!< Corresponds to the SIB1 si-WindowLength parameter. The unit is ms. Possible values are (final): 1,2,5,10,15,20,40
@@ -434,6 +437,7 @@ typedef enum e_rab_satus_e {
   E_RAB_STATUS_NEW,
   E_RAB_STATUS_DONE, // from the eNB perspective
   E_RAB_STATUS_ESTABLISHED, // get the reconfigurationcomplete form UE
+  E_RAB_STATUS_REESTABLISHED, // after HO
   E_RAB_STATUS_FAILED,
   E_RAB_STATUS_TORELEASE  // to release DRB between eNB and UE
 } e_rab_status_t;
@@ -447,18 +451,17 @@ typedef struct e_rab_param_s {
 } __attribute__ ((__packed__)) e_rab_param_t;
 #endif
 
-
-
 /* Intermediate structure for Handover management. Associated per-UE in eNB_RRC_INST */
 typedef struct HANDOVER_INFO_s {
   uint8_t ho_prepare;
   uint8_t ho_complete;
-  uint8_t modid_s; //module_idP of serving cell
-  uint8_t modid_t; //module_idP of target cell
+  HO_STATE_t state; //current state of handover
+  uint32_t modid_s; //module_idP of serving cell
+  uint32_t modid_t; //module_idP of target cell
   uint8_t ueid_s; //UE index in serving cell
   uint8_t ueid_t; //UE index in target cell
-  AS_Config_t as_config; /* these two parameters are taken from 36.331 section 10.2.2: HandoverPreparationInformation-r8-IEs */
-  AS_Context_t as_context; /* They are mandatory for HO */
+  LTE_AS_Config_t as_config; /* these two parameters are taken from 36.331 section 10.2.2: HandoverPreparationInformation-r8-IEs */
+  LTE_AS_Context_t as_context; /* They are mandatory for HO */
   uint8_t buf[RRC_BUF_SIZE];  /* ASN.1 encoded handoverCommandMessage */
   int size;   /* size of above message in bytes */
 } HANDOVER_INFO;
@@ -502,50 +505,54 @@ typedef struct SRB_INFO_TABLE_ENTRY_s {
 } SRB_INFO_TABLE_ENTRY;
 
 typedef struct MEAS_REPORT_LIST_s {
-  MeasId_t measId;
+  LTE_MeasId_t measId;
   //CellsTriggeredList  cellsTriggeredList;//OPTIONAL
   uint32_t numberOfReportsSent;
 } MEAS_REPORT_LIST;
 
 typedef struct HANDOVER_INFO_UE_s {
-  PhysCellId_t targetCellId;
+  LTE_PhysCellId_t targetCellId;
   uint8_t measFlag;
 } HANDOVER_INFO_UE;
 
-typedef struct RRC_CONTAINER_s{
-  char        *buffer;
-  uint8_t      size;
-} RRC_CONTAINER_t;
+typedef struct rrc_gummei_s {
+  uint16_t mcc;
+  uint16_t mnc;
+  uint8_t  mnc_len;
+  uint8_t  mme_code;
+  uint16_t mme_group_id;
+} rrc_gummei_t;
 
 typedef struct eNB_RRC_UE_s {
   uint8_t                            primaryCC_id;
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-  SCellToAddMod_r10_t                sCell_config[2];
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+  LTE_SCellToAddMod_r10_t            sCell_config[2];
 #endif
-  SRB_ToAddModList_t*                SRB_configList;
-  SRB_ToAddModList_t*                SRB_configList2[RRC_TRANSACTION_IDENTIFIER_NUMBER];
-  DRB_ToAddModList_t*                DRB_configList;
-  DRB_ToAddModList_t*                DRB_configList2[RRC_TRANSACTION_IDENTIFIER_NUMBER];
-  DRB_ToReleaseList_t*               DRB_Release_configList2[RRC_TRANSACTION_IDENTIFIER_NUMBER];
+  LTE_SRB_ToAddModList_t            *SRB_configList;
+  LTE_SRB_ToAddModList_t            *SRB_configList2[RRC_TRANSACTION_IDENTIFIER_NUMBER];
+  LTE_DRB_ToAddModList_t            *DRB_configList;
+  LTE_DRB_ToAddModList_t            *DRB_configList2[RRC_TRANSACTION_IDENTIFIER_NUMBER];
+  LTE_DRB_ToReleaseList_t           *DRB_Release_configList2[RRC_TRANSACTION_IDENTIFIER_NUMBER];
   uint8_t                            DRB_active[8];
-  struct PhysicalConfigDedicated*    physicalConfigDedicated;
-  struct SPS_Config*                 sps_Config;
-  MeasObjectToAddMod_t*              MeasObj[MAX_MEAS_OBJ];
-  struct ReportConfigToAddMod*       ReportConfig[MAX_MEAS_CONFIG];
-  struct QuantityConfig*             QuantityConfig;
-  struct MeasIdToAddMod*             MeasId[MAX_MEAS_ID];
-  MAC_MainConfig_t*                  mac_MainConfig;
-  MeasGapConfig_t*                   measGapConfig;
+  struct LTE_PhysicalConfigDedicated    *physicalConfigDedicated;
+  struct LTE_SPS_Config             *sps_Config;
+  LTE_MeasObjectToAddMod_t          *MeasObj[MAX_MEAS_OBJ];
+  struct LTE_ReportConfigToAddMod   *ReportConfig[MAX_MEAS_CONFIG];
+  struct LTE_QuantityConfig         *QuantityConfig;
+  struct LTE_MeasIdToAddMod         *MeasId[MAX_MEAS_ID];
+  LTE_MAC_MainConfig_t              *mac_MainConfig;
+  LTE_MeasGapConfig_t               *measGapConfig;
   SRB_INFO                           SI;
   SRB_INFO                           Srb0;
   SRB_INFO_TABLE_ENTRY               Srb1;
   SRB_INFO_TABLE_ENTRY               Srb2;
-  MeasConfig_t*                      measConfig;
-  HANDOVER_INFO*                     handover_info;
-  MeasResults_t*                     measResults;
+  LTE_MeasConfig_t                  *measConfig;
+  HANDOVER_INFO                     *handover_info;
+  LTE_MeasResults_t                 *measResults;
+  LTE_MobilityControlInfo_t         *mobilityInfo;
 
-  RRC_CONTAINER_t                    *security_mode_cmd;
-  UE_EUTRA_Capability_t*             UE_Capability;
+  LTE_UE_EUTRA_Capability_t         *UE_Capability;
+  int                                UE_Capability_size;
   ImsiMobileIdentity_t               imsi;
 
 #if defined(ENABLE_SECURITY)
@@ -556,20 +563,20 @@ typedef struct eNB_RRC_UE_s {
   int8_t  nh_ncc;
 #endif
   /* Used integrity/ciphering algorithms */
-  CipheringAlgorithm_r12_t                          ciphering_algorithm;
-  e_SecurityAlgorithmConfig__integrityProtAlgorithm integrity_algorithm;
+  LTE_CipheringAlgorithm_r12_t                          ciphering_algorithm;
+  e_LTE_SecurityAlgorithmConfig__integrityProtAlgorithm integrity_algorithm;
 
-  uint8_t                            Status;
+  uint8_t                            Status; // RRC status, type enum UE_STATE_t
   rnti_t                             rnti;
   uint64_t                           random_ue_identity;
 
 #if defined(ENABLE_ITTI)
   /* Information from UE RRC ConnectionRequest */
   UE_S_TMSI                          Initialue_identity_s_TMSI;
-  EstablishmentCause_t               establishment_cause;
+  LTE_EstablishmentCause_t           establishment_cause;
 
   /* Information from UE RRC ConnectionReestablishmentRequest */
-  ReestablishmentCause_t             reestablishment_cause;
+  LTE_ReestablishmentCause_t         reestablishment_cause;
 
   /* UE id for initial connection to S1AP */
   uint16_t                           ue_initial_id;
@@ -577,10 +584,17 @@ typedef struct eNB_RRC_UE_s {
   /* Information from S1AP initial_context_setup_req */
   uint32_t                           eNB_ue_s1ap_id :24;
 
+  uint32_t                           mme_ue_s1ap_id;
+  rrc_gummei_t                       ue_gummei;
+
   security_capabilities_t            security_capabilities;
 
+  int                                next_hop_chain_count;
+
+  uint8_t                            next_security_key[SECURITY_KEY_LENGTH];
+
   /* Total number of e_rab already setup in the list */
-  uint8_t                           setup_e_rabs;
+  uint8_t                            setup_e_rabs;
   /* Number of e_rab to be setup in the list */
   uint8_t                            nb_of_e_rabs;
   /* Number of e_rab to be modified in the list */
@@ -589,8 +603,12 @@ typedef struct eNB_RRC_UE_s {
   e_rab_param_t                      modify_e_rab[NB_RB_MAX];//[S1AP_MAX_E_RAB];
   /* list of e_rab to be setup by RRC layers */
   e_rab_param_t                      e_rab[NB_RB_MAX];//[S1AP_MAX_E_RAB];
+  /* UE aggregate maximum bitrate */
+  ambr_t ue_ambr;
   //release e_rabs
   uint8_t                            nb_release_of_e_rabs;
+  /* list of e_rab to be released by RRC layers */
+  uint8_t                            e_rabs_tobereleased[NB_RB_MAX];
   e_rab_failed_t                     e_rabs_release_failed[S1AP_MAX_E_RAB];
   // LG: For GTPV1 TUNNELS
   uint32_t                           enb_gtp_teid[S1AP_MAX_E_RAB];
@@ -606,6 +624,8 @@ typedef struct eNB_RRC_UE_s {
   uint32_t                           ue_release_timer_thres_rrc;
   uint32_t                           ue_reestablishment_timer;
   uint32_t                           ue_reestablishment_timer_thres;
+  /* RRC inactivity timer: on timeout, should release RRC connection for inactivity on all E-RABs */
+  uint32_t                           ue_rrc_inactivity_timer;
   uint8_t                            e_rab_release_command_flag;
   int8_t                             reestablishment_xid;
 } eNB_RRC_UE_t;
@@ -635,46 +655,49 @@ typedef struct {
   uint8_t                           sizeof_SIB1;
   uint8_t                           *SIB23;
   uint8_t                           sizeof_SIB23;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   uint8_t                           *SIB1_BR;
   uint8_t                           sizeof_SIB1_BR;
   uint8_t                           *SIB23_BR;
   uint8_t                           sizeof_SIB23_BR;
 #endif
-  int                               physCellId;
-  int                               Ncp;
-  int                               p_eNB;
-  uint32_t                          dl_CarrierFreq;
-  uint32_t                          ul_CarrierFreq;
-  uint32_t                          pbch_repetition;
-  BCCH_BCH_Message_t                mib;
-  BCCH_BCH_Message_t                *mib_DU;
-  BCCH_DL_SCH_Message_t             siblock1;
-  BCCH_DL_SCH_Message_t             *siblock1_DU;
-  BCCH_DL_SCH_Message_t             systemInformation;
+  int                                   physCellId;
+  int                                   Ncp;
+  int                                   p_eNB;
+  uint32_t                              dl_CarrierFreq;
+  uint32_t                              ul_CarrierFreq;
+  uint32_t                              eutra_band;
+  uint32_t                              N_RB_DL;
+  uint32_t                              pbch_repetition;
+  LTE_BCCH_BCH_Message_t                mib;
+  LTE_BCCH_BCH_Message_t                *mib_DU;
+  LTE_BCCH_DL_SCH_Message_t             siblock1;
+  LTE_BCCH_DL_SCH_Message_t             siblock1_BR;
+  LTE_BCCH_DL_SCH_Message_t             *siblock1_DU;
+  LTE_BCCH_DL_SCH_Message_t             systemInformation;
+  LTE_BCCH_DL_SCH_Message_t             systemInformation_BR;
   //  SystemInformation_t               systemInformation;
-  SystemInformationBlockType1_t     *sib1;
-  SystemInformationBlockType2_t     *sib2;
-  SystemInformationBlockType3_t     *sib3;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-  SystemInformationBlockType1_t     *sib1_BR;
-  SystemInformationBlockType2_t     *sib2_BR;
-  SystemInformationBlockType2_t     *sib3_BR;
+  LTE_SystemInformationBlockType1_t     *sib1;
+  LTE_SystemInformationBlockType2_t     *sib2;
+  LTE_SystemInformationBlockType3_t     *sib3;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  LTE_SystemInformationBlockType1_t     *sib1_BR;
+  LTE_SystemInformationBlockType2_t     *sib2_BR;
 #endif
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-  SystemInformationBlockType13_r9_t *sib13;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+  LTE_SystemInformationBlockType13_r9_t *sib13;
   uint8_t                           MBMS_flag;
   uint8_t                           num_mbsfn_sync_area;
   uint8_t                           **MCCH_MESSAGE; //  MAX_MBSFN_AREA
   uint8_t                           sizeof_MCCH_MESSAGE[8];// MAX_MBSFN_AREA
-  MCCH_Message_t            mcch;
-  MBSFNAreaConfiguration_r9_t       *mcch_message;
+  LTE_MCCH_Message_t                mcch;
+  LTE_MBSFNAreaConfiguration_r9_t  *mcch_message;
   SRB_INFO                          MCCH_MESS[8];// MAX_MBSFN_AREA
 #endif
   //TTN - SIB 18,19,21 for D2D
-  SystemInformationBlockType18_r12_t *sib18;
-  SystemInformationBlockType19_r12_t *sib19;
-  SystemInformationBlockType21_r14_t *sib21;
+  LTE_SystemInformationBlockType18_r12_t *sib18;
+  LTE_SystemInformationBlockType19_r12_t *sib19;
+  LTE_SystemInformationBlockType21_r14_t *sib21;
   // End - TTN
   SRB_INFO                          SI;
   uint8_t                           *paging[MAX_MOBILES_PER_ENB];
@@ -734,7 +757,7 @@ typedef struct eNB_RRC_INST_s {
 typedef struct OAI_UECapability_s {
   uint8_t sdu[MAX_UE_CAPABILITY_SIZE];
   uint8_t sdu_size;
-  UE_EUTRA_Capability_t *UE_EUTRA_Capability;
+  LTE_UE_EUTRA_Capability_t *UE_EUTRA_Capability;
 } OAI_UECapability_t;
 
 typedef struct UE_RRC_INST_s {
@@ -759,28 +782,28 @@ typedef struct UE_RRC_INST_s {
   uint8_t sizeof_SI[NB_CNX_UE];
   uint8_t SIB1Status[NB_CNX_UE];
   uint8_t SIStatus[NB_CNX_UE];
-  SystemInformationBlockType1_t *sib1[NB_CNX_UE];
-  SystemInformation_t *si[NB_CNX_UE]; //!< Temporary storage for an SI message. Decoding happens in decode_SI().
-  SystemInformationBlockType2_t *sib2[NB_CNX_UE];
-  SystemInformationBlockType3_t *sib3[NB_CNX_UE];
-  SystemInformationBlockType4_t *sib4[NB_CNX_UE];
-  SystemInformationBlockType5_t *sib5[NB_CNX_UE];
-  SystemInformationBlockType6_t *sib6[NB_CNX_UE];
-  SystemInformationBlockType7_t *sib7[NB_CNX_UE];
-  SystemInformationBlockType8_t *sib8[NB_CNX_UE];
-  SystemInformationBlockType9_t *sib9[NB_CNX_UE];
-  SystemInformationBlockType10_t *sib10[NB_CNX_UE];
-  SystemInformationBlockType11_t *sib11[NB_CNX_UE];
+  LTE_SystemInformationBlockType1_t *sib1[NB_CNX_UE];
+  LTE_SystemInformation_t *si[NB_CNX_UE]; //!< Temporary storage for an SI message. Decoding happens in decode_SI().
+  LTE_SystemInformationBlockType2_t *sib2[NB_CNX_UE];
+  LTE_SystemInformationBlockType3_t *sib3[NB_CNX_UE];
+  LTE_SystemInformationBlockType4_t *sib4[NB_CNX_UE];
+  LTE_SystemInformationBlockType5_t *sib5[NB_CNX_UE];
+  LTE_SystemInformationBlockType6_t *sib6[NB_CNX_UE];
+  LTE_SystemInformationBlockType7_t *sib7[NB_CNX_UE];
+  LTE_SystemInformationBlockType8_t *sib8[NB_CNX_UE];
+  LTE_SystemInformationBlockType9_t *sib9[NB_CNX_UE];
+  LTE_SystemInformationBlockType10_t *sib10[NB_CNX_UE];
+  LTE_SystemInformationBlockType11_t *sib11[NB_CNX_UE];
   uint8_t                           *MIB;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   //SIB18
-  SystemInformationBlockType18_r12_t *sib18[NB_CNX_UE];
-  SystemInformationBlockType19_r12_t *sib19[NB_CNX_UE];
-  SystemInformationBlockType21_r14_t *sib21[NB_CNX_UE];
+  LTE_SystemInformationBlockType18_r12_t *sib18[NB_CNX_UE];
+  LTE_SystemInformationBlockType19_r12_t *sib19[NB_CNX_UE];
+  LTE_SystemInformationBlockType21_r14_t *sib21[NB_CNX_UE];
 
-  SBCCH_SL_BCH_MessageType_t   mib_sl[NB_CNX_UE];
+  LTE_SBCCH_SL_BCH_MessageType_t   mib_sl[NB_CNX_UE];
   /// Preconfiguration for Sidelink
-  struct SL_Preconfiguration_r12 *SL_Preconfiguration[NB_CNX_UE];
+  struct LTE_SL_Preconfiguration_r12 *SL_Preconfiguration[NB_CNX_UE];
   //source L2 Id
   uint32_t sourceL2Id;
   //group L2 Id
@@ -788,41 +811,41 @@ typedef struct UE_RRC_INST_s {
   //current destination
   uint32_t destinationL2Id;
   //List of destinations
-   uint32_t destinationList[MAX_NUM_DEST];
+  uint32_t destinationList[MAX_NUM_DEST];
   //sl_discovery..
   SRB_INFO SL_Discovery[NB_CNX_UE];
 #endif
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
   uint8_t                           MBMS_flag;
   uint8_t *MCCH_MESSAGE[NB_CNX_UE];
   uint8_t sizeof_MCCH_MESSAGE[NB_CNX_UE];
   uint8_t MCCH_MESSAGEStatus[NB_CNX_UE];
-  MBSFNAreaConfiguration_r9_t       *mcch_message[NB_CNX_UE];
-  SystemInformationBlockType12_r9_t *sib12[NB_CNX_UE];
-  SystemInformationBlockType13_r9_t *sib13[NB_CNX_UE];
+  LTE_MBSFNAreaConfiguration_r9_t       *mcch_message[NB_CNX_UE];
+  LTE_SystemInformationBlockType12_r9_t *sib12[NB_CNX_UE];
+  LTE_SystemInformationBlockType13_r9_t *sib13[NB_CNX_UE];
 #endif
 #ifdef CBA
   uint8_t                         num_active_cba_groups;
   uint16_t                        cba_rnti[NUM_MAX_CBA_GROUP];
 #endif
   uint8_t                         num_srb;
-  struct SRB_ToAddMod             *SRB1_config[NB_CNX_UE];
-  struct SRB_ToAddMod             *SRB2_config[NB_CNX_UE];
-  struct DRB_ToAddMod             *DRB_config[NB_CNX_UE][8];
+  struct LTE_SRB_ToAddMod         *SRB1_config[NB_CNX_UE];
+  struct LTE_SRB_ToAddMod         *SRB2_config[NB_CNX_UE];
+  struct LTE_DRB_ToAddMod         *DRB_config[NB_CNX_UE][8];
   rb_id_t                         *defaultDRB; // remember the ID of the default DRB
-  MeasObjectToAddMod_t            *MeasObj[NB_CNX_UE][MAX_MEAS_OBJ];
-  struct ReportConfigToAddMod     *ReportConfig[NB_CNX_UE][MAX_MEAS_CONFIG];
-  struct QuantityConfig           *QuantityConfig[NB_CNX_UE];
-  struct MeasIdToAddMod           *MeasId[NB_CNX_UE][MAX_MEAS_ID];
-  MEAS_REPORT_LIST      *measReportList[NB_CNX_UE][MAX_MEAS_ID];
-  uint32_t           measTimer[NB_CNX_UE][MAX_MEAS_ID][6]; // 6 neighboring cells
-  RSRP_Range_t                    s_measure;
-  struct MeasConfig__speedStatePars *speedStatePars;
-  struct PhysicalConfigDedicated  *physicalConfigDedicated[NB_CNX_UE];
-  struct SPS_Config               *sps_Config[NB_CNX_UE];
-  MAC_MainConfig_t                *mac_MainConfig[NB_CNX_UE];
-  MeasGapConfig_t                 *measGapConfig[NB_CNX_UE];
+  LTE_MeasObjectToAddMod_t        *MeasObj[NB_CNX_UE][MAX_MEAS_OBJ];
+  struct LTE_ReportConfigToAddMod *ReportConfig[NB_CNX_UE][MAX_MEAS_CONFIG];
+  struct LTE_QuantityConfig       *QuantityConfig[NB_CNX_UE];
+  struct LTE_MeasIdToAddMod       *MeasId[NB_CNX_UE][MAX_MEAS_ID];
+  MEAS_REPORT_LIST                *measReportList[NB_CNX_UE][MAX_MEAS_ID];
+  uint32_t                        measTimer[NB_CNX_UE][MAX_MEAS_ID][6]; // 6 neighboring cells
+  LTE_RSRP_Range_t                s_measure;
+  struct LTE_MeasConfig__speedStatePars *speedStatePars;
+  struct LTE_PhysicalConfigDedicated  *physicalConfigDedicated[NB_CNX_UE];
+  struct LTE_SPS_Config           *sps_Config[NB_CNX_UE];
+  LTE_MAC_MainConfig_t            *mac_MainConfig[NB_CNX_UE];
+  LTE_MeasGapConfig_t             *measGapConfig[NB_CNX_UE];
   double                          filter_coeff_rsrp; // [7] ???
   double                          filter_coeff_rsrq; // [7] ???
   float                           rsrp_db[7];
@@ -837,12 +860,12 @@ typedef struct UE_RRC_INST_s {
 #endif
 
   /* Used integrity/ciphering algorithms */
-  CipheringAlgorithm_r12_t                          ciphering_algorithm;
-  e_SecurityAlgorithmConfig__integrityProtAlgorithm integrity_algorithm;
+  LTE_CipheringAlgorithm_r12_t                          ciphering_algorithm;
+  e_LTE_SecurityAlgorithmConfig__integrityProtAlgorithm integrity_algorithm;
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   /// Used for Sidelink Preconfiguration
-  DRB_ToAddModList_t *DRB_configList;
+  LTE_DRB_ToAddModList_t *DRB_configList;
 #endif
 } UE_RRC_INST;
 
diff --git a/openair2/RRC/LTE/rrc_eNB.c b/openair2/RRC/LTE/rrc_eNB.c
index 5afa0c1134b0321b0406b12ed19668796c9bb4ff..51f196eaf65682549e6434bcdf1245587333bc47 100644
--- a/openair2/RRC/LTE/rrc_eNB.c
+++ b/openair2/RRC/LTE/rrc_eNB.c
@@ -44,29 +44,30 @@
 #include "common/utils/LOG/log.h"
 #include "COMMON/mac_rrc_primitives.h"
 #include "RRC/LTE/MESSAGES/asn1_msg.h"
-#include "RRCConnectionRequest.h"
-#include "RRCConnectionReestablishmentRequest.h"
+#include "LTE_RRCConnectionRequest.h"
+#include "LTE_RRCConnectionReestablishmentRequest.h"
 //#include "ReestablishmentCause.h"
-#include "BCCH-BCH-Message.h"
-#include "UL-CCCH-Message.h"
-#include "DL-CCCH-Message.h"
-#include "UL-DCCH-Message.h"
-#include "DL-DCCH-Message.h"
-#include "TDD-Config.h"
-#include "HandoverCommand.h"
+#include "LTE_BCCH-BCH-Message.h"
+#include "LTE_UL-CCCH-Message.h"
+#include "LTE_DL-CCCH-Message.h"
+#include "LTE_UL-DCCH-Message.h"
+#include "LTE_DL-DCCH-Message.h"
+#include "LTE_TDD-Config.h"
+#include "LTE_HandoverPreparationInformation.h"
+#include "LTE_HandoverCommand.h"
 #include "rlc.h"
 #include "rrc_eNB_UE_context.h"
 #include "platform_types.h"
 #include "msc.h"
-#include "SL-CommConfig-r12.h"
-#include "PeriodicBSR-Timer-r12.h"
-#include "RetxBSR-Timer-r12.h"
+#include "LTE_SL-CommConfig-r12.h"
+#include "LTE_PeriodicBSR-Timer-r12.h"
+#include "LTE_RetxBSR-Timer-r12.h"
 #include "common/utils/LOG/vcd_signal_dumper.h"
 
 #include "T.h"
 
-//#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-#include "MeasResults.h"
+//#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#include "LTE_MeasResults.h"
 //#endif
 
 #include "RRC/NAS/nas_config.h"
@@ -75,29 +76,34 @@
 #include "OCG_extern.h"
 
 #if defined(ENABLE_SECURITY)
-#   include "UTIL/OSA/osa_defs.h"
+  #include "UTIL/OSA/osa_defs.h"
 #endif
 
 #if defined(ENABLE_USE_MME)
-#   include "rrc_eNB_S1AP.h"
-#   include "rrc_eNB_GTPV1U.h"
-#   if defined(ENABLE_ITTI)
-#   else
-#      include "../../S1AP/s1ap_eNB.h"
-#   endif
+  #include "rrc_eNB_S1AP.h"
+  #include "rrc_eNB_GTPV1U.h"
+  #if defined(ENABLE_ITTI)
+  #else
+    #include "../../S1AP/s1ap_eNB.h"
+  #endif
+  /* temporary warning removale while implementing noS1 */
+  /* as config option                                   */
 #else
-# define EPC_MODE_ENABLED 0
+  #ifdef EPC_MODE_ENABLED
+    #undef  EPC_MODE_ENABLED
+  #endif
+  #define EPC_MODE_ENABLED 0
 #endif
 
 #include "pdcp.h"
 #include "gtpv1u_eNB_task.h"
 
 #if defined(ENABLE_ITTI)
-#   include "intertask_interface.h"
+  #include "intertask_interface.h"
 #endif
 
 #if ENABLE_RAL
-#   include "rrc_eNB_ral.h"
+  #include "rrc_eNB_ral.h"
 #endif
 
 #include "SIMULATION/TOOLS/sim.h" // for taus
@@ -106,56 +112,48 @@
 extern RAN_CONTEXT_t RC;
 
 #ifdef PHY_EMUL
-extern EMULATION_VARS              *Emul_vars;
+  extern EMULATION_VARS              *Emul_vars;
 #endif
 extern eNB_MAC_INST                *eNB_mac_inst;
 extern UE_MAC_INST                 *UE_mac_inst;
-#ifdef BIGPHYSAREA
-extern void*                        bigphys_malloc(int);
-#endif
 
 extern uint16_t                     two_tier_hexagonal_cellIds[7];
 
 mui_t                               rrc_eNB_mui = 0;
 
+extern uint32_t to_earfcn_DL(int eutra_bandP, uint32_t dl_CarrierFreq, uint32_t bw);
+
 void
 openair_rrc_on(
-  const protocol_ctxt_t* const ctxt_pP
+  const protocol_ctxt_t *const ctxt_pP
 )
 //-----------------------------------------------------------------------------
 {
   int            CC_id;
+  LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" ENB:OPENAIR RRC IN....\n",
+        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
 
-    LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" ENB:OPENAIR RRC IN....\n",
-          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
-    for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
-      rrc_config_buffer (&RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SI, BCCH, 1);
-      RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SI.Active = 1;
-      //      rrc_config_buffer (&RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0, CCCH, 1);
-      //      RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Active = 1;
-    }
+  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
+    rrc_config_buffer (&RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SI, BCCH, 1);
+    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SI.Active = 1;
+  }
 }
 
 //-----------------------------------------------------------------------------
 static void
 init_SI(
   const protocol_ctxt_t* const ctxt_pP,
-  const int              CC_id
-#if defined(ENABLE_ITTI)
-  ,
+  const int              CC_id,
   RrcConfigurationReq * configuration
-#endif
 )
 //-----------------------------------------------------------------------------
 {
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
   int                                 i;
 #endif
-
-#if (RRC_VERSION >= MAKE_VERSION(13, 1, 0))
-  SystemInformationBlockType1_v1310_IEs_t *sib1_v13ext=(SystemInformationBlockType1_v1310_IEs_t *)NULL;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 1, 0))
+  LTE_SystemInformationBlockType1_v1310_IEs_t *sib1_v13ext=(LTE_SystemInformationBlockType1_v1310_IEs_t *)NULL;
 #endif
-
   LOG_D(RRC,"%s()\n\n\n\n",__FUNCTION__);
   eNB_RRC_INST *rrc = RC.rrc[ctxt_pP->module_id];
   rrc_eNB_carrier_data_t *carrier=&rrc->carrier[CC_id];
@@ -177,30 +175,36 @@ init_SI(
     carrier->Ncp             = configuration->prefix_type[CC_id];
     carrier->dl_CarrierFreq  = configuration->downlink_frequency[CC_id];
     carrier->ul_CarrierFreq  = configuration->downlink_frequency[CC_id]+ configuration->uplink_frequency_offset[CC_id];
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+    carrier->eutra_band      = configuration->eutra_band[CC_id];
+    carrier->N_RB_DL         = configuration->N_RB_DL[CC_id];
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
     carrier->pbch_repetition = configuration->pbch_repetition[CC_id];
+    LOG_I(RRC, "configuration->schedulingInfoSIB1_BR_r13[CC_id] %d\n",(int)configuration->schedulingInfoSIB1_BR_r13[CC_id]);
 #endif
 
     LOG_I(RRC, "Configuring MIB (N_RB_DL %d,phich_Resource %d,phich_Duration %d)\n", 
 	  (int)configuration->N_RB_DL[CC_id],
-	  (int)configuration->phich_resource[CC_id],
-	  (int)configuration->phich_duration[CC_id]);
-
-    carrier->sizeof_MIB= do_MIB(&rrc->carrier[CC_id],
-#ifdef ENABLE_ITTI
-	   configuration->N_RB_DL[CC_id],
-	   configuration->phich_resource[CC_id],
-	   configuration->phich_duration[CC_id]
-#else
-	   50,0,0
-#endif
-	   ,0);
+	  (int)configuration->radioresourceconfig[CC_id].phich_resource,
+	  (int)configuration->radioresourceconfig[CC_id].phich_duration);
+
+    carrier->sizeof_MIB = do_MIB(&rrc->carrier[CC_id],
+                                 configuration->N_RB_DL[CC_id],
+                                 configuration->radioresourceconfig[CC_id].phich_resource,
+                                 configuration->radioresourceconfig[CC_id].phich_duration,
+                                 0
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                                 ,configuration->schedulingInfoSIB1_BR_r13[CC_id]
+#endif
+   );
     
     
-    carrier->sizeof_SIB1 = do_SIB1(&rrc->carrier[CC_id],ctxt_pP->module_id,CC_id
-#if defined(ENABLE_ITTI)
-				   , configuration
+    carrier->sizeof_SIB1 = do_SIB1(&rrc->carrier[CC_id],
+                                   ctxt_pP->module_id,
+                                   CC_id
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                                   ,FALSE
 #endif
+                                   , configuration
 				   );
     
     AssertFatal(carrier->sizeof_SIB1 != 255,"FATAL, RC.rrc[enb_mod_idP].carrier[CC_id].sizeof_SIB1 == 255");
@@ -213,190 +217,206 @@ init_SI(
       (rrc->node_type == ngran_eNB)) { */ 
     carrier->SIB23 = (uint8_t*) malloc16(64);
     AssertFatal(carrier->SIB23!=NULL,"cannot allocate memory for SIB");
-    carrier->sizeof_SIB23 = do_SIB23(
-				     ctxt_pP->module_id,
-				     
-				     CC_id
-#if defined(ENABLE_ITTI)
-				     , configuration
+    carrier->sizeof_SIB23 = do_SIB23(ctxt_pP->module_id,
+                                     CC_id
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                                     ,FALSE
 #endif
-				     );
+                                     , configuration
+                                     );
     
     LOG_I(RRC,"do_SIB23, size %d \n ", carrier->sizeof_SIB23);
     
     AssertFatal(carrier->sizeof_SIB23 != 255,"FATAL, RC.rrc[mod].carrier[CC_id].sizeof_SIB23 == 255");
     
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  carrier->sizeof_SIB23_BR = 0;
+  if (configuration->schedulingInfoSIB1_BR_r13[CC_id]>0) {
+    carrier->SIB23_BR = (uint8_t*) malloc16(64);
+    AssertFatal(carrier->SIB23_BR!=NULL,"cannot allocate memory for SIB");
+    carrier->sizeof_SIB23_BR = do_SIB23(ctxt_pP->module_id,
+                                              CC_id
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                                              ,TRUE
+#endif
+                                              ,configuration
+                );
+  }
+#endif
     
     LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" SIB2/3 Contents (partial)\n",
-	  PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
+          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
     LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.n_SB = %ld\n",
-	  PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	  carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.
-	  pusch_ConfigBasic.n_SB);
+          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+          carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.n_SB);
     LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.hoppingMode = %ld\n",
-	  PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	  carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.
-	  pusch_ConfigBasic.hoppingMode);
+          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+          carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.hoppingMode);
     LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.pusch_HoppingOffset = %ld\n",
-	  PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	  carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.
-	  pusch_ConfigBasic.pusch_HoppingOffset);
+          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+          carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.pusch_HoppingOffset);
     LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.enable64QAM = %d\n",
-	  PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	  (int)carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.
-	  pusch_ConfigBasic.enable64QAM);
+          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+          (int)carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.enable64QAM);
     LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.groupHoppingEnabled = %d\n",
-	  PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	  (int)carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.
-	  ul_ReferenceSignalsPUSCH.groupHoppingEnabled);
+          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+          (int)carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.groupHoppingEnabled);
     LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.groupAssignmentPUSCH = %ld\n",
-	  PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	  carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.
-	  ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH);
+          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+          carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH);
     LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.sequenceHoppingEnabled = %d\n",
-	  PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	  (int)carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.
-	  ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled);
+          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+          (int)carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled);
     LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.cyclicShift  = %ld\n",
-	  PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	  carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.
-	  ul_ReferenceSignalsPUSCH.cyclicShift);
+          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+          carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.cyclicShift);
     
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
     
     if (carrier->MBMS_flag > 0) {
       for (i = 0; i < carrier->sib2->mbsfn_SubframeConfigList->list.count; i++) {
 	// SIB 2
 	//   LOG_D(RRC, "[eNB %d] mbsfn_SubframeConfigList.list.count = %ld\n", enb_mod_idP, RC.rrc[enb_mod_idP].sib2->mbsfn_SubframeConfigList->list.count);
-	LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" SIB13 contents for MBSFN subframe allocation %d/%d(partial)\n",
-	      PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	      i,
-	      carrier->sib2->mbsfn_SubframeConfigList->list.count);
-	LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" mbsfn_Subframe_pattern is  = %x\n",
-	      PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	      carrier->sib2->mbsfn_SubframeConfigList->list.array[i]->subframeAllocation.choice.oneFrame.buf[0] >> 0);
-	LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" radioframe_allocation_period  = %ld (just index number, not the real value)\n",
-	      PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	      carrier->sib2->mbsfn_SubframeConfigList->list.array[i]->radioframeAllocationPeriod);   // need to display the real value, using array of char (like in dumping SIB2)
-	LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" radioframe_allocation_offset  = %ld\n",
-	      PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	      carrier->sib2->mbsfn_SubframeConfigList->list.array[i]->radioframeAllocationOffset);
+        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" SIB13 contents for MBSFN subframe allocation %d/%d(partial)\n",
+              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+              i,
+              carrier->sib2->mbsfn_SubframeConfigList->list.count);
+        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" mbsfn_Subframe_pattern is  = %x\n",
+              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+              carrier->sib2->mbsfn_SubframeConfigList->list.array[i]->subframeAllocation.choice.oneFrame.buf[0] >> 0);
+        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" radioframe_allocation_period  = %ld (just index number, not the real value)\n",
+              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+              carrier->sib2->mbsfn_SubframeConfigList->list.array[i]->radioframeAllocationPeriod);   // need to display the real value, using array of char (like in dumping SIB2)
+        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" radioframe_allocation_offset  = %ld\n",
+              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+              carrier->sib2->mbsfn_SubframeConfigList->list.array[i]->radioframeAllocationOffset);
       }
       
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
       //   SIB13
       for (i = 0; i < carrier->sib13->mbsfn_AreaInfoList_r9.list.count; i++) {
-	LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" SIB13 contents for MBSFN sync area %d/%d (partial)\n",
-	      PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	      i,
-	      carrier->sib13->mbsfn_AreaInfoList_r9.list.count);
-	LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" MCCH Repetition Period: %ld (just index number, not real value)\n",
-	      PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	      carrier->sib13->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.mcch_RepetitionPeriod_r9);
-	LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" MCCH Offset: %ld\n",
-	      PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	      carrier->sib13->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.mcch_Offset_r9);
+        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" SIB13 contents for MBSFN sync area %d/%d (partial)\n",
+              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+              i,
+              carrier->sib13->mbsfn_AreaInfoList_r9.list.count);
+        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" MCCH Repetition Period: %ld (just index number, not real value)\n",
+              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+              carrier->sib13->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.mcch_RepetitionPeriod_r9);
+        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" MCCH Offset: %ld\n",
+              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+              carrier->sib13->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.mcch_Offset_r9);
       }
 #endif
     }
     else memset((void*)&carrier->sib13,0,sizeof(carrier->sib13));
     
     //TTN - SIB 18
-    for (int j = 0; j < carrier->sib18->commConfig_r12->commRxPool_r12.list.count; j++) {
-      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Contents of SIB18 %d/%d \n",
-	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	    j+1,
-	    carrier->sib18->commConfig_r12->commRxPool_r12.list.count);
-      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 rxPool_sc_CP_Len: %ld \n",
-	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	    carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_CP_Len_r12);
-      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 sc_Period_r12: %ld \n",
-	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	    carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_Period_r12);
-      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 data_CP_Len_r12: %ld \n",
-	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	    carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->data_CP_Len_r12);
-      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 prb_Num_r12: %ld \n",
-	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	    carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_TF_ResourceConfig_r12.prb_Num_r12);
-      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 prb_Start_r12: %ld \n",
-	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	    carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_TF_ResourceConfig_r12.prb_Start_r12);
-      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 prb_End_r12: %ld \n",
-	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	    carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_TF_ResourceConfig_r12.prb_End_r12);
-      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 offsetIndicator: %ld \n",
-	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	    carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_TF_ResourceConfig_r12.offsetIndicator_r12.choice.small_r12);
-      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 subframeBitmap_choice_bs_buf: %s \n",
-	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	    carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs16_r12.buf);
-      
-    }
-    
-    //TTN - SIB 19
-    for (int j = 0; j < carrier->sib19->discConfig_r12->discRxPool_r12.list.count; j++) {
-      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Contents of SIB19 %d/%d \n",
-	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	    j+1,
-	    carrier->sib19->discConfig_r12->discRxPool_r12.list.count);
-      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 cp_Len_r12: %ld \n",
-	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	    carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->cp_Len_r12);
-      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 discPeriod_r12: %ld \n",
-	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	    carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->discPeriod_r12);
-      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 numRetx_r12: %ld \n",
-	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	    carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->numRetx_r12);
-      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 numRepetition_r12: %ld \n",
-	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	    carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->numRepetition_r12);
-      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 prb_Num_r12: %ld \n",
-	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	    carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->tf_ResourceConfig_r12.prb_Num_r12);
-      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 prb_Start_r12: %ld \n",
-	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	    carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->tf_ResourceConfig_r12.prb_Start_r12);
-      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 prb_End_r12: %ld \n",
-	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	    carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->tf_ResourceConfig_r12.prb_End_r12);
-      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 offsetIndicator: %ld \n",
-	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	    carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->tf_ResourceConfig_r12.offsetIndicator_r12.choice.small_r12);
-      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 subframeBitmap_choice_bs_buf: %s \n",
-	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-	    carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs16_r12.buf);
+    if (configuration->SL_configured > 0) {
+      for (int j = 0; j < carrier->sib18->commConfig_r12->commRxPool_r12.list.count; j++) {
+        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Contents of SIB18 %d/%d \n",
+              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+              j+1,
+              carrier->sib18->commConfig_r12->commRxPool_r12.list.count);
+        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 rxPool_sc_CP_Len: %ld \n",
+              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+              carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_CP_Len_r12);
+        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 sc_Period_r12: %ld \n",
+              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+              carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_Period_r12);
+        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 data_CP_Len_r12: %ld \n",
+              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+              carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->data_CP_Len_r12);
+        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 prb_Num_r12: %ld \n",
+              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+              carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_TF_ResourceConfig_r12.prb_Num_r12);
+        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 prb_Start_r12: %ld \n",
+              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+              carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_TF_ResourceConfig_r12.prb_Start_r12);
+        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 prb_End_r12: %ld \n",
+              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+              carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_TF_ResourceConfig_r12.prb_End_r12);
+        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 offsetIndicator: %ld \n",
+              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+              carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_TF_ResourceConfig_r12.offsetIndicator_r12.choice.small_r12);
+        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 subframeBitmap_choice_bs_buf: %s \n",
+              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+              carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs16_r12.buf);
+      }
       
+      //TTN - SIB 19
+      for (int j = 0; j < carrier->sib19->discConfig_r12->discRxPool_r12.list.count; j++) {
+        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Contents of SIB19 %d/%d \n",
+              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+              j+1,
+        carrier->sib19->discConfig_r12->discRxPool_r12.list.count);
+        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 cp_Len_r12: %ld \n",
+        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+        carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->cp_Len_r12);
+        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 discPeriod_r12: %ld \n",
+        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+        carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->discPeriod_r12);
+        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 numRetx_r12: %ld \n",
+        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+        carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->numRetx_r12);
+        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 numRepetition_r12: %ld \n",
+        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+        carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->numRepetition_r12);
+        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 prb_Num_r12: %ld \n",
+        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+        carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->tf_ResourceConfig_r12.prb_Num_r12);
+        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 prb_Start_r12: %ld \n",
+        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+        carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->tf_ResourceConfig_r12.prb_Start_r12);
+        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 prb_End_r12: %ld \n",
+        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+        carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->tf_ResourceConfig_r12.prb_End_r12);
+        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 offsetIndicator: %ld \n",
+        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+        carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->tf_ResourceConfig_r12.offsetIndicator_r12.choice.small_r12);
+        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 subframeBitmap_choice_bs_buf: %s \n",
+        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+        carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs16_r12.buf);
+      }
     }
- 
 #endif
   }
    
   LOG_D(RRC,
-	PROTOCOL_RRC_CTXT_FMT" RRC_UE --- MAC_CONFIG_REQ (SIB1.tdd & SIB2 params) ---> MAC_UE\n",
-	PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
-
+        PROTOCOL_RRC_CTXT_FMT" RRC_UE --- MAC_CONFIG_REQ (SIB1.tdd & SIB2 params) ---> MAC_UE\n",
+        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
+#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
   // LTE-M stuff here (take out CU-DU for now)
   if (rrc->node_type == ngran_eNB) {
-#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
     if ((carrier->mib.message.schedulingInfoSIB1_BR_r13>0) && 
-	(carrier->sib1_BR!=NULL)) {
+        (carrier->sib1_BR!=NULL)) {
       AssertFatal(carrier->sib1_BR->nonCriticalExtension!=NULL,
-		  "sib2_br->nonCriticalExtension is null (v8.9)\n");
+                  "sib2_br->nonCriticalExtension is null (v8.9)\n");
       AssertFatal(carrier->sib1_BR->nonCriticalExtension->nonCriticalExtension!=NULL,
-		  "sib2_br->nonCriticalExtension is null (v9.2)\n");
+                  "sib2_br->nonCriticalExtension is null (v9.2)\n");
       AssertFatal(carrier->sib1_BR->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension!=NULL,
-		  "sib2_br->nonCriticalExtension is null (v11.3)\n");
+                  "sib2_br->nonCriticalExtension is null (v11.3)\n");
       AssertFatal(carrier->sib1_BR->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension!=NULL,
-		  "sib2_br->nonCriticalExtension is null (v12.5)\n");
+                  "sib2_br->nonCriticalExtension is null (v12.5)\n");
       AssertFatal(carrier->sib1_BR->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension!=NULL,
-		  "sib2_br->nonCriticalExtension is null (v13.10)\n");
+                  "sib2_br->nonCriticalExtension is null (v13.10)\n");
       sib1_v13ext = carrier->sib1_BR->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension;
+
+      // Basic Asserts for CE_level0 PRACH configuration
+      LTE_RadioResourceConfigCommonSIB_t *radioResourceConfigCommon_BR = &carrier[CC_id].sib2_BR->radioResourceConfigCommon;
+      struct LTE_PRACH_ConfigSIB_v1310 *ext4_prach=radioResourceConfigCommon_BR->ext4->prach_ConfigCommon_v1310;
+
+      LTE_PRACH_ParametersListCE_r13_t	 *prach_ParametersListCE_r13 = &ext4_prach->prach_ParametersListCE_r13;
+      AssertFatal(prach_ParametersListCE_r13->list.count>0,"prach_ParametersListCE_r13 is empty\n");
+                  LTE_PRACH_ParametersCE_r13_t *p = prach_ParametersListCE_r13->list.array[0];
+      AssertFatal(p->prach_StartingSubframe_r13 != NULL, "prach_StartingSubframe_r13 celevel0 is null\n");
+      AssertFatal((1<<p->numRepetitionPerPreambleAttempt_r13)<=(2<<*p->prach_StartingSubframe_r13),
+                  "prachce0->numReptitionPerPreambleAttempt_r13 %d > prach_StartingSubframe_r13 %d\n",
+                  1<<p->numRepetitionPerPreambleAttempt_r13,
+                  2<<*p->prach_StartingSubframe_r13);
     }
-#endif
   
   }
+#endif
   /*
   if (rrc->node_type == ngran_eNB_DU) {
     LOG_D(RRC, "About to call rrc_mac_config_req_eNB for ngran_eNB_DU\n");
@@ -407,18 +427,18 @@ init_SI(
 			   carrier->Ncp,
 			   carrier->sib1->freqBandIndicator,
 			   carrier->dl_CarrierFreq,
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 			   carrier->pbch_repetition,
 #endif
 			   0, // rnti
 			   (BCCH_BCH_Message_t *)
 			   &carrier->mib,
 			   (RadioResourceConfigCommonSIB_t *) NULL,
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 			   (RadioResourceConfigCommonSIB_t *) NULL,
 #endif
 			   (struct PhysicalConfigDedicated *)NULL,
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 			   (SCellToAddMod_r10_t *)NULL,
 			   //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
 #endif
@@ -433,13 +453,13 @@ init_SI(
 			   NULL,
 			   NULL,
 			   NULL
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
 			   ,
 			   carrier->MBMS_flag,
 			   NULL,
 			   (PMCH_InfoList_r9_t *) NULL
 #endif
-#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
 			   , 
 			   NULL
 #endif
@@ -451,58 +471,57 @@ init_SI(
     LOG_D(RRC, "About to call rrc_mac_config_req_eNB for ngran_eNB\n");
     
     rrc_mac_config_req_eNB(ctxt_pP->module_id, CC_id,
-			   carrier->physCellId,
-			   carrier->p_eNB,
-			   carrier->Ncp,
-			   carrier->sib1->freqBandIndicator,
-			   carrier->dl_CarrierFreq,
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-			   carrier->pbch_repetition,
-#endif
-			   0, // rnti
-			   (BCCH_BCH_Message_t *)
-			   &carrier->mib,
-			   (RadioResourceConfigCommonSIB_t *) &
-			   carrier->sib2->radioResourceConfigCommon,
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-			   (RadioResourceConfigCommonSIB_t *) &
-			   carrier->sib2_BR->radioResourceConfigCommon,
-#endif
-			   (struct PhysicalConfigDedicated *)NULL,
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-			   (SCellToAddMod_r10_t *)NULL,
-			   //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
-#endif
-			   (MeasObjectToAddMod_t **) NULL,
-			   (MAC_MainConfig_t *) NULL, 0,
-			   (struct LogicalChannelConfig *)NULL,
-			   (MeasGapConfig_t *) NULL,
-			   carrier->sib1->tdd_Config,
-			   NULL,
-			   &carrier->sib1->schedulingInfoList,
-			   carrier->ul_CarrierFreq,
-			   carrier->sib2->freqInfo.ul_Bandwidth,
-			   &carrier->sib2->freqInfo.additionalSpectrumEmission,
-			   (MBSFN_SubframeConfigList_t*) carrier->sib2->mbsfn_SubframeConfigList
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-			   ,
-			   carrier->MBMS_flag,
-			   (MBSFN_AreaInfoList_r9_t*) & carrier->sib13->mbsfn_AreaInfoList_r9,
-			   (PMCH_InfoList_r9_t *) NULL
-#endif
-#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
-			   , 
-			   sib1_v13ext
-#endif
-			   );
+                           carrier->physCellId,
+                           carrier->p_eNB,
+                           carrier->Ncp,
+                           carrier->sib1->freqBandIndicator,
+                           carrier->dl_CarrierFreq,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                           carrier->pbch_repetition,
+#endif
+                           0, // rnti
+                           (LTE_BCCH_BCH_Message_t *) &carrier->mib,
+                           (LTE_RadioResourceConfigCommonSIB_t *) &carrier->sib2->radioResourceConfigCommon,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                           (LTE_RadioResourceConfigCommonSIB_t *) &carrier->sib2_BR->radioResourceConfigCommon,
+#endif
+                           (struct LTE_PhysicalConfigDedicated *)NULL,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                           (LTE_SCellToAddMod_r10_t *)NULL,
+                           //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
+#endif
+                           (LTE_MeasObjectToAddMod_t **) NULL,
+                           (LTE_MAC_MainConfig_t *) NULL, 0,
+                           (struct LTE_LogicalChannelConfig *)NULL,
+                           (LTE_MeasGapConfig_t *) NULL,
+                           carrier->sib1->tdd_Config,
+                           NULL,
+                           &carrier->sib1->schedulingInfoList,
+                           carrier->ul_CarrierFreq,
+                           carrier->sib2->freqInfo.ul_Bandwidth,
+                           &carrier->sib2->freqInfo.additionalSpectrumEmission,
+                           (LTE_MBSFN_SubframeConfigList_t*) carrier->sib2->mbsfn_SubframeConfigList
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+                           ,
+                           carrier->MBMS_flag,
+                           (LTE_MBSFN_AreaInfoList_r9_t*) & carrier->sib13->mbsfn_AreaInfoList_r9,
+                           (LTE_PMCH_InfoList_r9_t *) NULL
+#endif
+#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
+                           ,
+                           sib1_v13ext
+#endif
+                           );
   }
-  // set flag to indicate that cell information is configured. This is required in DU to trigger  F1AP_SETUP procedure.
+
+	/* set flag to indicate that cell information is configured. This is required
+	 * in DU to trigger F1AP_SETUP procedure */
   pthread_mutex_lock(&rrc->cell_info_mutex);
   rrc->cell_info_configured=1;
   pthread_mutex_unlock(&rrc->cell_info_mutex);
 }
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 /*------------------------------------------------------------------------------*/
 static void
 init_MCCH(
@@ -511,95 +530,85 @@ init_MCCH(
 )
 //-----------------------------------------------------------------------------
 {
-
   int                                 sync_area = 0;
   // initialize RRC_eNB_INST MCCH entry
   eNB_RRC_INST *rrc = RC.rrc[enb_mod_idP];
 
   RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE =
-    malloc(RC.rrc[enb_mod_idP]->carrier[CC_id].num_mbsfn_sync_area * sizeof(uint8_t*));
+    malloc(RC.rrc[enb_mod_idP]->carrier[CC_id].num_mbsfn_sync_area * sizeof(uint8_t *));
 
   for (sync_area = 0; sync_area < RC.rrc[enb_mod_idP]->carrier[CC_id].num_mbsfn_sync_area; sync_area++) {
-
     RC.rrc[enb_mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] = 0;
     RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE[sync_area] = (uint8_t *) malloc16(32);
-
     AssertFatal(RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE[sync_area] != NULL,
-		"[eNB %d]init_MCCH: FATAL, no memory for MCCH MESSAGE allocated \n", enb_mod_idP);
+                "[eNB %d]init_MCCH: FATAL, no memory for MCCH MESSAGE allocated \n", enb_mod_idP);
     RC.rrc[enb_mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] = do_MBSFNAreaConfig(enb_mod_idP,
-											    sync_area,
-											    (uint8_t *)RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE[sync_area],
-											    &RC.rrc[enb_mod_idP]->carrier[CC_id].mcch,
-											    &RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message);
-    
+        sync_area,
+        (uint8_t *)RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE[sync_area],
+        &RC.rrc[enb_mod_idP]->carrier[CC_id].mcch,
+        &RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message);
     LOG_I(RRC, "mcch message pointer %p for sync area %d \n",
-	  RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE[sync_area],
-	  sync_area);
+          RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE[sync_area],
+          sync_area);
     LOG_D(RRC, "[eNB %d] MCCH_MESSAGE  contents for Sync Area %d (partial)\n", enb_mod_idP, sync_area);
     LOG_D(RRC, "[eNB %d] CommonSF_AllocPeriod_r9 %ld\n", enb_mod_idP,
-	  RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->commonSF_AllocPeriod_r9);
+          RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->commonSF_AllocPeriod_r9);
     LOG_D(RRC,
-	  "[eNB %d] CommonSF_Alloc_r9.list.count (number of MBSFN Subframe Pattern) %d\n",
-	  enb_mod_idP, RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->commonSF_Alloc_r9.list.count);
+          "[eNB %d] CommonSF_Alloc_r9.list.count (number of MBSFN Subframe Pattern) %d\n",
+          enb_mod_idP, RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->commonSF_Alloc_r9.list.count);
     LOG_D(RRC, "[eNB %d] MBSFN Subframe Pattern: %02x (in hex)\n",
-	  enb_mod_idP,
-	  RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->commonSF_Alloc_r9.list.array[0]->subframeAllocation.
-	  choice.oneFrame.buf[0]);
-    
+          enb_mod_idP,
+          RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->commonSF_Alloc_r9.list.array[0]->subframeAllocation.
+          choice.oneFrame.buf[0]);
     AssertFatal(RC.rrc[enb_mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] != 255,
-		"RC.rrc[enb_mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] == 255");
+                "RC.rrc[enb_mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] == 255");
     RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESS[sync_area].Active = 1;
   }
-  
 
   //Set the RC.rrc[enb_mod_idP]->MCCH_MESS.Active to 1 (allow to  transfer MCCH message RRC->MAC in function mac_rrc_data_req)
-
   // ??Configure MCCH logical channel
   // call mac_config_req with appropriate structure from ASN.1 description
-
-
   //  LOG_I(RRC, "DUY: serviceID is %d\n",RC.rrc[enb_mod_idP]->mcch_message->pmch_InfoList_r9.list.array[0]->mbms_SessionInfoList_r9.list.array[0]->tmgi_r9.serviceId_r9.buf[2]);
   //  LOG_I(RRC, "DUY: session ID is %d\n",RC.rrc[enb_mod_idP]->mcch_message->pmch_InfoList_r9.list.array[0]->mbms_SessionInfoList_r9.list.array[0]->sessionId_r9->buf[0]);
   if (rrc->node_type == ngran_eNB) {
     rrc_mac_config_req_eNB(enb_mod_idP, CC_id,
-			   0,0,0,0,0,
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-			   0,
-#endif
-			   0,//rnti
-			   (BCCH_BCH_Message_t *)NULL,
-			   (RadioResourceConfigCommonSIB_t *) NULL,
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-			   (RadioResourceConfigCommonSIB_t *) NULL,
-#endif
-			   (struct PhysicalConfigDedicated *)NULL,
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-			   (SCellToAddMod_r10_t *)NULL,
-			   //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
-#endif
-			   (MeasObjectToAddMod_t **) NULL,
-			   (MAC_MainConfig_t *) NULL,
-			   0,
-			   (struct LogicalChannelConfig *)NULL,
-			   (MeasGapConfig_t *) NULL,
-			   (TDD_Config_t *) NULL,
-			   (MobilityControlInfo_t *)NULL, 
-			   (SchedulingInfoList_t *) NULL, 
-			   0, NULL, NULL, (MBSFN_SubframeConfigList_t *) NULL
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-			   ,
-			   0,
-			   (MBSFN_AreaInfoList_r9_t *) NULL,
-			   (PMCH_InfoList_r9_t *) & (RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->pmch_InfoList_r9)
-#endif
-#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
-			   ,
-			   (SystemInformationBlockType1_v1310_IEs_t *)NULL
-#endif
-			   );
+                           0,0,0,0,0,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                           0,
+#endif
+                           0,//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
+                           (struct LTE_PhysicalConfigDedicated *)NULL,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                           (LTE_SCellToAddMod_r10_t *)NULL,
+                         //(struct LTE_PhysicalConfigDedicatedSCell_r10 *)NULL,
+#endif
+                           (LTE_MeasObjectToAddMod_t **) NULL,
+                           (LTE_MAC_MainConfig_t *) NULL,
+                           0,
+                           (struct LTE_LogicalChannelConfig *)NULL,
+                           (LTE_MeasGapConfig_t *) NULL,
+                           (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 *) & (RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->pmch_InfoList_r9)
+#endif
+#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
+                           ,
+                           (LTE_SystemInformationBlockType1_v1310_IEs_t *)NULL
+#endif
+                           );
   }
   //LOG_I(RRC,"DUY: lcid after rrc_mac_config_req is %02d\n",RC.rrc[enb_mod_idP]->mcch_message->pmch_InfoList_r9.list.array[0]->mbms_SessionInfoList_r9.list.array[0]->logicalChannelIdentity_r9);
-
 }
 
 //-----------------------------------------------------------------------------
@@ -615,33 +624,30 @@ static void init_MBMS(
 
   if (RC.rrc[enb_mod_idP]->carrier[CC_id].MBMS_flag > 0) {
     PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, enb_mod_idP, ENB_FLAG_YES, NOT_A_RNTI, frameP, 0,enb_mod_idP);
-
     LOG_D(RRC, "[eNB %d] Frame %d : Radio Bearer config request for MBMS\n", enb_mod_idP, frameP);   //check the lcid
     // Configuring PDCP and RLC for MBMS Radio Bearer
-
     rrc_pdcp_config_asn1_req(&ctxt,
-                             (SRB_ToAddModList_t  *)NULL,  // SRB_ToAddModList
-                             (DRB_ToAddModList_t  *)NULL,  // DRB_ToAddModList
-                             (DRB_ToReleaseList_t *)NULL,
+                             (LTE_SRB_ToAddModList_t *)NULL,   // LTE_SRB_ToAddModList
+                             (LTE_DRB_ToAddModList_t *)NULL,   // LTE_DRB_ToAddModList
+                             (LTE_DRB_ToReleaseList_t *)NULL,
                              0,     // security mode
                              NULL,  // key rrc encryption
                              NULL,  // key rrc integrity
                              NULL   // key encryption
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
                              , &(RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->pmch_InfoList_r9)
 #endif
                              ,NULL);
     
-    if ( (RC.rrc[enb_mod_idP]->node_type  != ngran_eNB_CU) ||
-	 (RC.rrc[enb_mod_idP]->node_type  != ngran_ng_eNB_CU) ||
-	 (RC.rrc[enb_mod_idP]->node_type  != ngran_gNB_CU)   ) {
+    if ((RC.rrc[enb_mod_idP]->node_type  != ngran_eNB_CU) ||
+        (RC.rrc[enb_mod_idP]->node_type  != ngran_ng_eNB_CU) ||
+        (RC.rrc[enb_mod_idP]->node_type  != ngran_gNB_CU)   ) {
       rrc_rlc_config_asn1_req(&ctxt,
-			      NULL, // SRB_ToAddModList
-			      NULL,   // DRB_ToAddModList
-			      NULL,   // DRB_ToReleaseList
-			      &(RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->pmch_InfoList_r9)
-
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                              NULL, // LTE_SRB_ToAddModList
+                              NULL,   // LTE_DRB_ToAddModList
+                              NULL,   // DRB_ToReleaseList
+                              &(RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->pmch_InfoList_r9)
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 			      ,0, 0
 #endif
 			      );
@@ -698,14 +704,14 @@ rrc_eNB_get_next_transaction_identifier(
 
 //-----------------------------------------------------------------------------
 // return the ue context if there is already an UE with ue_identityP, NULL otherwise
-static struct rrc_eNB_ue_context_s*
+static struct rrc_eNB_ue_context_s *
 rrc_eNB_ue_context_random_exist(
-  const protocol_ctxt_t* const ctxt_pP,
+  const protocol_ctxt_t *const ctxt_pP,
   const uint64_t               ue_identityP
 )
 //-----------------------------------------------------------------------------
 {
-  struct rrc_eNB_ue_context_s*        ue_context_p = NULL;
+  struct rrc_eNB_ue_context_s        *ue_context_p = NULL;
   RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(RC.rrc[ctxt_pP->module_id]->rrc_ue_head)) {
     if (ue_context_p->ue_context.random_ue_identity == ue_identityP)
       return ue_context_p;
@@ -714,47 +720,47 @@ rrc_eNB_ue_context_random_exist(
 }
 //-----------------------------------------------------------------------------
 // return the ue context if there is already an UE with the same S-TMSI(MMEC+M-TMSI), NULL otherwise
-static struct rrc_eNB_ue_context_s*
+static struct rrc_eNB_ue_context_s *
 rrc_eNB_ue_context_stmsi_exist(
-  const protocol_ctxt_t* const ctxt_pP,
+  const protocol_ctxt_t *const ctxt_pP,
   const mme_code_t             mme_codeP,
   const m_tmsi_t               m_tmsiP
 )
 //-----------------------------------------------------------------------------
 {
-  struct rrc_eNB_ue_context_s*        ue_context_p = NULL;
+  struct rrc_eNB_ue_context_s        *ue_context_p = NULL;
   RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(RC.rrc[ctxt_pP->module_id]->rrc_ue_head)) {
     LOG_I(RRC,"checking for UE S-TMSI %x, mme %x (%p): rnti %x",
-	  m_tmsiP, mme_codeP, ue_context_p, 
-	  ue_context_p->ue_context.rnti);
+          m_tmsiP, mme_codeP, ue_context_p,
+          ue_context_p->ue_context.rnti);
+
     if (ue_context_p->ue_context.Initialue_identity_s_TMSI.presence == TRUE) {
       printf("=> S-TMSI %x, MME %x\n",
-	    ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi,
-	    ue_context_p->ue_context.Initialue_identity_s_TMSI.mme_code);
+             ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi,
+             ue_context_p->ue_context.Initialue_identity_s_TMSI.mme_code);
+
       if (ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi == m_tmsiP)
         if (ue_context_p->ue_context.Initialue_identity_s_TMSI.mme_code == mme_codeP)
           return ue_context_p;
-    }
-    else
+    } else
       printf("\n");
-
   }
   return NULL;
 }
 
 //-----------------------------------------------------------------------------
 // return a new ue context structure if ue_identityP, ctxt_pP->rnti not found in collection
-struct rrc_eNB_ue_context_s*
+static struct rrc_eNB_ue_context_s *
 rrc_eNB_get_next_free_ue_context(
-  const protocol_ctxt_t* const ctxt_pP,
+  const protocol_ctxt_t *const ctxt_pP,
   const uint64_t               ue_identityP
 )
 //-----------------------------------------------------------------------------
 {
-  struct rrc_eNB_ue_context_s*        ue_context_p = NULL;
+  struct rrc_eNB_ue_context_s        *ue_context_p = NULL;
   ue_context_p = rrc_eNB_get_ue_context(
-					RC.rrc[ctxt_pP->module_id],
-					ctxt_pP->rnti);
+                   RC.rrc[ctxt_pP->module_id],
+                   ctxt_pP->rnti);
 
   if (ue_context_p == NULL) {
     ue_context_p = rrc_eNB_allocate_new_UE_context(RC.rrc[ctxt_pP->module_id]);
@@ -775,7 +781,6 @@ rrc_eNB_get_next_free_ue_context(
           PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
           ue_context_p->local_uid);
     return ue_context_p;
-
   } else {
     LOG_E(RRC,
           PROTOCOL_RRC_CTXT_UE_FMT" Cannot create new UE context, already exist\n",
@@ -788,8 +793,8 @@ rrc_eNB_get_next_free_ue_context(
 //-----------------------------------------------------------------------------
 void
 rrc_eNB_free_mem_UE_context(
-  const protocol_ctxt_t*               const ctxt_pP,
-  struct rrc_eNB_ue_context_s*         const ue_context_pP
+  const protocol_ctxt_t               *const ctxt_pP,
+  struct rrc_eNB_ue_context_s         *const ue_context_pP
 )
 //-----------------------------------------------------------------------------
 {
@@ -798,95 +803,96 @@ rrc_eNB_free_mem_UE_context(
         PROTOCOL_RRC_CTXT_UE_FMT" Clearing UE context 0x%p (free internal structs)\n",
         PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
         ue_context_pP);
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-  ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_SCellToAddMod_r10, &ue_context_pP->ue_context.sCell_config[0]);
-  ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_SCellToAddMod_r10, &ue_context_pP->ue_context.sCell_config[1]);
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+  ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_LTE_SCellToAddMod_r10, &ue_context_pP->ue_context.sCell_config[0]);
+  ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_LTE_SCellToAddMod_r10, &ue_context_pP->ue_context.sCell_config[1]);
 #endif
 
   if (ue_context_pP->ue_context.SRB_configList) {
-    ASN_STRUCT_FREE(asn_DEF_SRB_ToAddModList, ue_context_pP->ue_context.SRB_configList);
+    ASN_STRUCT_FREE(asn_DEF_LTE_SRB_ToAddModList, ue_context_pP->ue_context.SRB_configList);
     ue_context_pP->ue_context.SRB_configList = NULL;
   }
 
-  for(i = 0;i < RRC_TRANSACTION_IDENTIFIER_NUMBER;i++){
-      if (ue_context_pP->ue_context.SRB_configList2[i]) {
-          free(ue_context_pP->ue_context.SRB_configList2[i]);
-          ue_context_pP->ue_context.SRB_configList2[i] = NULL;
-      }
+  for(i = 0; i < RRC_TRANSACTION_IDENTIFIER_NUMBER; i++) {
+    if (ue_context_pP->ue_context.SRB_configList2[i]) {
+      free(ue_context_pP->ue_context.SRB_configList2[i]);
+      ue_context_pP->ue_context.SRB_configList2[i] = NULL;
+    }
   }
 
   if (ue_context_pP->ue_context.DRB_configList) {
-    ASN_STRUCT_FREE(asn_DEF_DRB_ToAddModList, ue_context_pP->ue_context.DRB_configList);
+    ASN_STRUCT_FREE(asn_DEF_LTE_DRB_ToAddModList, ue_context_pP->ue_context.DRB_configList);
     ue_context_pP->ue_context.DRB_configList = NULL;
   }
 
-  for(i = 0;i < RRC_TRANSACTION_IDENTIFIER_NUMBER;i++){
-      if (ue_context_pP->ue_context.DRB_configList2[i]) {
-          free(ue_context_pP->ue_context.DRB_configList2[i]);
-          ue_context_pP->ue_context.DRB_configList2[i] = NULL;
-      }
-      if (ue_context_pP->ue_context.DRB_Release_configList2[i]) {
-          free(ue_context_pP->ue_context.DRB_Release_configList2[i]);
-          ue_context_pP->ue_context.DRB_Release_configList2[i] = NULL;
-      }
+  for(i = 0; i < RRC_TRANSACTION_IDENTIFIER_NUMBER; i++) {
+    if (ue_context_pP->ue_context.DRB_configList2[i]) {
+      free(ue_context_pP->ue_context.DRB_configList2[i]);
+      ue_context_pP->ue_context.DRB_configList2[i] = NULL;
+    }
+
+    if (ue_context_pP->ue_context.DRB_Release_configList2[i]) {
+      free(ue_context_pP->ue_context.DRB_Release_configList2[i]);
+      ue_context_pP->ue_context.DRB_Release_configList2[i] = NULL;
+    }
   }
 
   memset(ue_context_pP->ue_context.DRB_active, 0, sizeof(ue_context_pP->ue_context.DRB_active));
 
   if (ue_context_pP->ue_context.physicalConfigDedicated) {
-    ASN_STRUCT_FREE(asn_DEF_PhysicalConfigDedicated, ue_context_pP->ue_context.physicalConfigDedicated);
+    ASN_STRUCT_FREE(asn_DEF_LTE_PhysicalConfigDedicated, ue_context_pP->ue_context.physicalConfigDedicated);
     ue_context_pP->ue_context.physicalConfigDedicated = NULL;
   }
 
   if (ue_context_pP->ue_context.sps_Config) {
-    ASN_STRUCT_FREE(asn_DEF_SPS_Config, ue_context_pP->ue_context.sps_Config);
+    ASN_STRUCT_FREE(asn_DEF_LTE_SPS_Config, ue_context_pP->ue_context.sps_Config);
     ue_context_pP->ue_context.sps_Config = NULL;
   }
 
   for (i=0; i < MAX_MEAS_OBJ; i++) {
     if (ue_context_pP->ue_context.MeasObj[i] != NULL) {
-      ASN_STRUCT_FREE(asn_DEF_MeasObjectToAddMod, ue_context_pP->ue_context.MeasObj[i]);
+      ASN_STRUCT_FREE(asn_DEF_LTE_MeasObjectToAddMod, ue_context_pP->ue_context.MeasObj[i]);
       ue_context_pP->ue_context.MeasObj[i] = NULL;
     }
   }
 
   for (i=0; i < MAX_MEAS_CONFIG; i++) {
     if (ue_context_pP->ue_context.ReportConfig[i] != NULL) {
-      ASN_STRUCT_FREE(asn_DEF_ReportConfigToAddMod, ue_context_pP->ue_context.ReportConfig[i]);
+      ASN_STRUCT_FREE(asn_DEF_LTE_ReportConfigToAddMod, ue_context_pP->ue_context.ReportConfig[i]);
       ue_context_pP->ue_context.ReportConfig[i] = NULL;
     }
   }
 
   if (ue_context_pP->ue_context.QuantityConfig) {
-    ASN_STRUCT_FREE(asn_DEF_QuantityConfig, ue_context_pP->ue_context.QuantityConfig);
+    ASN_STRUCT_FREE(asn_DEF_LTE_QuantityConfig, ue_context_pP->ue_context.QuantityConfig);
     ue_context_pP->ue_context.QuantityConfig = NULL;
   }
 
   if (ue_context_pP->ue_context.mac_MainConfig) {
-    ASN_STRUCT_FREE(asn_DEF_MAC_MainConfig, ue_context_pP->ue_context.mac_MainConfig);
+    ASN_STRUCT_FREE(asn_DEF_LTE_MAC_MainConfig, ue_context_pP->ue_context.mac_MainConfig);
     ue_context_pP->ue_context.mac_MainConfig = NULL;
   }
 
-/*  if (ue_context_pP->ue_context.measGapConfig) {
-    ASN_STRUCT_FREE(asn_DEF_MeasGapConfig, ue_context_pP->ue_context.measGapConfig);
-    ue_context_pP->ue_context.measGapConfig = NULL;
-  }*/
-    if (ue_context_pP->ue_context.handover_info) {
-      ASN_STRUCT_FREE(asn_DEF_Handover, ue_context_pP->ue_context.handover_info);
-      ue_context_pP->ue_context.handover_info = NULL;
-    }
+  /*  if (ue_context_pP->ue_context.measGapConfig) {
+      ASN_STRUCT_FREE(asn_DEF_LTE_MeasGapConfig, ue_context_pP->ue_context.measGapConfig);
+      ue_context_pP->ue_context.measGapConfig = NULL;
+    }*/
+  if (ue_context_pP->ue_context.handover_info) {
+    ASN_STRUCT_FREE(asn_DEF_LTE_Handover, ue_context_pP->ue_context.handover_info);
+    ue_context_pP->ue_context.handover_info = NULL;
+  }
 
   //SRB_INFO                           SI;
   //SRB_INFO                           Srb0;
   //SRB_INFO_TABLE_ENTRY               Srb1;
   //SRB_INFO_TABLE_ENTRY               Srb2;
   if (ue_context_pP->ue_context.measConfig) {
-    ASN_STRUCT_FREE(asn_DEF_MeasConfig, ue_context_pP->ue_context.measConfig);
+    ASN_STRUCT_FREE(asn_DEF_LTE_MeasConfig, ue_context_pP->ue_context.measConfig);
     ue_context_pP->ue_context.measConfig = NULL;
   }
 
   if (ue_context_pP->ue_context.measConfig) {
-    ASN_STRUCT_FREE(asn_DEF_MeasConfig, ue_context_pP->ue_context.measConfig);
+    ASN_STRUCT_FREE(asn_DEF_LTE_MeasConfig, ue_context_pP->ue_context.measConfig);
     ue_context_pP->ue_context.measConfig = NULL;
   }
 
@@ -915,32 +921,28 @@ rrc_eNB_free_mem_UE_context(
 }
 
 //-----------------------------------------------------------------------------
-// should be called when UE is lost by eNB
+/*
+* Should be called when UE context in eNB should be released
+* or when S1 command UE_CONTEXT_RELEASE_REQ should be sent
+*/
 void
-rrc_eNB_free_UE(const module_id_t enb_mod_idP,const struct rrc_eNB_ue_context_s*        const ue_context_pP)
+rrc_eNB_free_UE(
+  const module_id_t enb_mod_idP,
+  const struct rrc_eNB_ue_context_s *const ue_context_pP)
 //-----------------------------------------------------------------------------
 {
-
-
-  protocol_ctxt_t                     ctxt;
   rnti_t rnti = ue_context_pP->ue_context.rnti;
+
   if (enb_mod_idP >= NB_eNB_INST) {
-      LOG_I(RRC, "eNB inst invalid (%d/%d) for UE %x!\n",enb_mod_idP, NB_eNB_INST,rnti);
-      return;
+    LOG_E(RRC, "eNB instance invalid (%d/%d) for UE %x!\n",
+          enb_mod_idP,
+          NB_eNB_INST,
+          rnti);
+    return;
   }
-  /*  ue_context_p = rrc_eNB_get_ue_context(
-                   &RC.rrc[enb_mod_idP],
-                   rntiP
-                 );
-  */
-  if (NULL != ue_context_pP) {
-    PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, enb_mod_idP, ENB_FLAG_YES, rnti, 0, 0,enb_mod_idP);
-    LOG_W(RRC, "[eNB %d] Removing UE RNTI %x\n", enb_mod_idP, rnti);
 
    if(EPC_MODE_ENABLED) {
-
-     if((ue_context_pP->ue_context.ul_failure_timer >= 20000) &&
-  	(mac_eNB_get_rrc_status(enb_mod_idP,rnti) >= RRC_CONNECTED)) {
+     if((ue_context_pP->ue_context.ul_failure_timer >= 20000) && (mac_eNB_get_rrc_status(enb_mod_idP, rnti) >= RRC_CONNECTED)) {
       if (RC.rrc[enb_mod_idP]->node_type == ngran_eNB
           || RC.rrc[enb_mod_idP]->node_type == ngran_eNB_CU
           || RC.rrc[enb_mod_idP]->node_type == ngran_gNB_CU) {
@@ -952,245 +954,240 @@ rrc_eNB_free_UE(const module_id_t enb_mod_idP,const struct rrc_eNB_ue_context_s*
             21); // send cause 21: 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
-       *  triggering the S1 UE Context Release Request procedure
-       *  in order to allow the UE to perform the NAS recovery
-       *  procedure, see TS 23.401 [17].
-       */
-       return;
+        * If the E-UTRAN internal reason is a radio link failure detected in the eNB, the eNB shall wait a sufficient time before
+        *  triggering the S1 UE Context Release Request procedure in order to allow the UE to perform the NAS recovery
+        *  procedure, see TS 23.401 [17].
+        */
+      return;
+    }
+
+    if((ue_context_pP->ue_context.ue_rrc_inactivity_timer >= RC.rrc[enb_mod_idP]->configuration.rrc_inactivity_timer_thres) &&
+        (mac_eNB_get_rrc_status(enb_mod_idP, rnti) >= RRC_CONNECTED) &&
+        (RC.rrc[enb_mod_idP]->configuration.rrc_inactivity_timer_thres > 0)) {
+      LOG_I(RRC, "[eNB %d] S1AP_UE_CONTEXT_RELEASE_REQ sent for RNTI %x, cause 20, user inactivity\n",
+            enb_mod_idP,
+            rnti);
+      rrc_eNB_send_S1AP_UE_CONTEXT_RELEASE_REQ(enb_mod_idP, ue_context_pP, S1AP_CAUSE_RADIO_NETWORK, 20);
+      // send cause 20: user inactivity
+      return;
     }
   }
-    // add UE info to freeList
-    LOG_I(RRC, "put UE %x into freeList\n", rnti);
-    put_UE_in_freelist(enb_mod_idP, rnti, 1);
-  }
-}
 
-void remove_UE_from_freelist(module_id_t mod_id, rnti_t rnti)
-{
+  LOG_W(RRC, "[eNB %d] Removing UE RNTI %x\n",
+        enb_mod_idP,
+        rnti);
+  // add UE info to freeList
+  LOG_I(RRC, "Put UE %x into freeList\n",
+        rnti);
+  put_UE_in_freelist(enb_mod_idP, rnti, 1);
+}
 
-    eNB_MAC_INST                             *eNB_MAC = RC.mac[mod_id];
-    pthread_mutex_lock(&lock_ue_freelist);
-    UE_free_list_t                           *free_list = &eNB_MAC->UE_free_list;
-    free_list->UE_free_ctrl[free_list->head_freelist].rnti = 0;
-    free_list->head_freelist = (free_list->head_freelist + 1) % (NUMBER_OF_UE_MAX+1);
-    free_list->num_UEs--;
-    pthread_mutex_unlock(&lock_ue_freelist);
+void remove_UE_from_freelist(module_id_t mod_id, rnti_t rnti) {
+  eNB_MAC_INST                             *eNB_MAC = RC.mac[mod_id];
+  pthread_mutex_lock(&lock_ue_freelist);
+  UE_free_list_t                           *free_list = &eNB_MAC->UE_free_list;
+  free_list->UE_free_ctrl[free_list->head_freelist].rnti = 0;
+  free_list->head_freelist = (free_list->head_freelist + 1) % (NUMBER_OF_UE_MAX+1);
+  free_list->num_UEs--;
+  pthread_mutex_unlock(&lock_ue_freelist);
 }
 
-void put_UE_in_freelist(module_id_t mod_id, rnti_t rnti, boolean_t removeFlag)
-{
-    UE_free_list_t                           *free_list = NULL;
-    eNB_MAC_INST                             *eNB_MAC = RC.mac[mod_id];
-    pthread_mutex_lock(&lock_ue_freelist);
-    free_list = &eNB_MAC->UE_free_list;
-    free_list->UE_free_ctrl[free_list->tail_freelist].rnti = rnti;
-    free_list->UE_free_ctrl[free_list->tail_freelist].removeContextFlg = removeFlag;
-    free_list->num_UEs++;
-    free_list->tail_freelist = (free_list->tail_freelist + 1) % (NUMBER_OF_UE_MAX+1);
-    pthread_mutex_unlock(&lock_ue_freelist);
+void put_UE_in_freelist(module_id_t mod_id, rnti_t rnti, boolean_t removeFlag) {
+  UE_free_list_t                           *free_list = NULL;
+  eNB_MAC_INST                             *eNB_MAC = RC.mac[mod_id];
+  pthread_mutex_lock(&lock_ue_freelist);
+  free_list = &eNB_MAC->UE_free_list;
+  free_list->UE_free_ctrl[free_list->tail_freelist].rnti = rnti;
+  free_list->UE_free_ctrl[free_list->tail_freelist].removeContextFlg = removeFlag;
+  free_list->num_UEs++;
+  free_list->tail_freelist = (free_list->tail_freelist + 1) % (NUMBER_OF_UE_MAX+1);
+  pthread_mutex_unlock(&lock_ue_freelist);
 }
 
-void release_UE_in_freeList(module_id_t mod_id)
-{
-    int i, j , CC_id, pdu_number;
-    protocol_ctxt_t                           ctxt;
-    LTE_eNB_ULSCH_t                          *ulsch = NULL;
-    LTE_eNB_DLSCH_t                          *dlsch = NULL;
-    nfapi_ul_config_request_body_t           *ul_req_tmp = NULL;
-    PHY_VARS_eNB                             *eNB_PHY = NULL;
-    struct rrc_eNB_ue_context_s              *ue_context_pP = NULL;
-    eNB_MAC_INST                             *eNB_MAC = RC.mac[mod_id];
-    boolean_t                                 remove_UEContext;
-    rnti_t                                    rnti;
-    int                                       head, tail, ue_num;
-
-    pthread_mutex_lock(&lock_ue_freelist);
-    head = eNB_MAC->UE_free_list.head_freelist;
-    tail = eNB_MAC->UE_free_list.tail_freelist;
-    if(head == tail){
-        pthread_mutex_unlock(&lock_ue_freelist);
-        return;
-    }
-    if(tail < head){
-        tail = head + eNB_MAC->UE_free_list.num_UEs;
-    }
+void release_UE_in_freeList(module_id_t mod_id) {
+  int i, j, CC_id, pdu_number;
+  protocol_ctxt_t                           ctxt;
+  LTE_eNB_ULSCH_t                          *ulsch = NULL;
+  LTE_eNB_DLSCH_t                          *dlsch = NULL;
+  nfapi_ul_config_request_body_t           *ul_req_tmp = NULL;
+  PHY_VARS_eNB                             *eNB_PHY = NULL;
+  struct rrc_eNB_ue_context_s              *ue_context_pP = NULL;
+  eNB_MAC_INST                             *eNB_MAC = RC.mac[mod_id];
+  boolean_t                                 remove_UEContext;
+  rnti_t                                    rnti;
+  int                                       head, tail, ue_num;
+  pthread_mutex_lock(&lock_ue_freelist);
+  head = eNB_MAC->UE_free_list.head_freelist;
+  tail = eNB_MAC->UE_free_list.tail_freelist;
+
+  if(head == tail) {
     pthread_mutex_unlock(&lock_ue_freelist);
+    return;
+  }
 
-    for(ue_num = head; ue_num < tail; ue_num++){
-        ue_num = ue_num % (NUMBER_OF_UE_MAX+1);
-        rnti = eNB_MAC->UE_free_list.UE_free_ctrl[ue_num].rnti;
-        if(rnti != 0){
-            remove_UEContext = eNB_MAC->UE_free_list.UE_free_ctrl[ue_num].removeContextFlg;
-            PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, mod_id, ENB_FLAG_YES, rnti, 0, 0,mod_id);
-            for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
-              eNB_PHY = RC.eNB[mod_id][CC_id];
-              for (i=0; i<MAX_MOBILES_PER_ENB; i++) {
-                ulsch = eNB_PHY->ulsch[i];
-                if((ulsch != NULL) && (ulsch->rnti == rnti)){
-                  void clean_eNb_ulsch(LTE_eNB_ULSCH_t *ulsch);
-                  LOG_I(RRC, "clean_eNb_ulsch ulsch[%d] UE %x\n", i, rnti);
-                  clean_eNb_ulsch(ulsch);
-                }
-                if(eNB_PHY->uci_vars[i].rnti == rnti){
-                  LOG_I(MAC, "clean eNb uci_vars[%d] UE %x \n",i, rnti);
-                  memset(&eNB_PHY->uci_vars[i],0,sizeof(LTE_eNB_UCI));
-                }
-              }
-              for (i=0; i<MAX_MOBILES_PER_ENB; i++) {
-                dlsch = eNB_PHY->dlsch[i][0];
-                if((dlsch != NULL) && (dlsch->rnti == rnti)){
-                  void clean_eNb_dlsch(LTE_eNB_DLSCH_t *dlsch);
-                  LOG_I(RRC, "clean_eNb_dlsch dlsch[%d] UE %x \n", i, rnti);
-                  clean_eNb_dlsch(dlsch);
-                }
-              }
+  if(tail < head) {
+    tail = head + eNB_MAC->UE_free_list.num_UEs;
+  }
 
-              if (flexran_agent_get_rrc_xface(mod_id)) {
-                flexran_agent_get_rrc_xface(mod_id)->flexran_agent_notify_ue_state_change(mod_id,
-                            rnti, PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_DEACTIVATED);
-              }
+  pthread_mutex_unlock(&lock_ue_freelist);
+
+  for(ue_num = head; ue_num < tail; ue_num++) {
+    ue_num = ue_num % (NUMBER_OF_UE_MAX+1);
+    rnti = eNB_MAC->UE_free_list.UE_free_ctrl[ue_num].rnti;
+
+    if(rnti != 0) {
+      remove_UEContext = eNB_MAC->UE_free_list.UE_free_ctrl[ue_num].removeContextFlg;
+      PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, mod_id, ENB_FLAG_YES, rnti, 0, 0,mod_id);
+
+      for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
+        eNB_PHY = RC.eNB[mod_id][CC_id];
+
+        for (i=0; i<MAX_MOBILES_PER_ENB; i++) {
+          ulsch = eNB_PHY->ulsch[i];
+
+          if((ulsch != NULL) && (ulsch->rnti == rnti)) {
+            void clean_eNb_ulsch(LTE_eNB_ULSCH_t *ulsch);
+            LOG_I(RRC, "clean_eNb_ulsch ulsch[%d] UE %x\n", i, rnti);
+            clean_eNb_ulsch(ulsch);
+          }
+
+          if(eNB_PHY->uci_vars[i].rnti == rnti) {
+            LOG_I(MAC, "clean eNb uci_vars[%d] UE %x \n",i, rnti);
+            memset(&eNB_PHY->uci_vars[i],0,sizeof(LTE_eNB_UCI));
+          }
+        }
+
+        for (i=0; i<MAX_MOBILES_PER_ENB; i++) {
+          dlsch = eNB_PHY->dlsch[i][0];
+
+          if((dlsch != NULL) && (dlsch->rnti == rnti)) {
+            void clean_eNb_dlsch(LTE_eNB_DLSCH_t *dlsch);
+            LOG_I(RRC, "clean_eNb_dlsch dlsch[%d] UE %x \n", i, rnti);
+            clean_eNb_dlsch(dlsch);
+          }
+        }
 
-              for(j = 0; j < 10; j++){
-                ul_req_tmp = &eNB_MAC->UL_req_tmp[CC_id][j].ul_config_request_body;
-                if(ul_req_tmp){
-                  pdu_number = ul_req_tmp->number_of_pdus;
-                  for(int pdu_index = pdu_number-1; pdu_index >= 0; pdu_index--){
-                    if((ul_req_tmp->ul_config_pdu_list[pdu_index].ulsch_pdu.ulsch_pdu_rel8.rnti == rnti) ||
-                       (ul_req_tmp->ul_config_pdu_list[pdu_index].uci_harq_pdu.ue_information.ue_information_rel8.rnti == rnti) ||
-                       (ul_req_tmp->ul_config_pdu_list[pdu_index].uci_cqi_pdu.ue_information.ue_information_rel8.rnti == rnti) ||
-                       (ul_req_tmp->ul_config_pdu_list[pdu_index].uci_sr_pdu.ue_information.ue_information_rel8.rnti == rnti) ||
-                       (ul_req_tmp->ul_config_pdu_list[pdu_index].srs_pdu.srs_pdu_rel8.rnti == rnti)){
-                        LOG_I(RRC, "remove UE %x from ul_config_pdu_list %d/%d\n", rnti, pdu_index, pdu_number);
-                        if(pdu_index < pdu_number -1){
-                          memcpy(&ul_req_tmp->ul_config_pdu_list[pdu_index], &ul_req_tmp->ul_config_pdu_list[pdu_index+1], (pdu_number-1-pdu_index) * sizeof(nfapi_ul_config_request_pdu_t));
-                        }
-                        ul_req_tmp->number_of_pdus--;
-                    }
-                  }
+        if (flexran_agent_get_rrc_xface(mod_id)) {
+          flexran_agent_get_rrc_xface(mod_id)->flexran_agent_notify_ue_state_change(
+              mod_id, rnti, PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_DEACTIVATED);
+        }
+
+        for(j = 0; j < 10; j++) {
+          ul_req_tmp = &eNB_MAC->UL_req_tmp[CC_id][j].ul_config_request_body;
+
+          if(ul_req_tmp) {
+            pdu_number = ul_req_tmp->number_of_pdus;
+
+            for(int pdu_index = pdu_number-1; pdu_index >= 0; pdu_index--) {
+              if((ul_req_tmp->ul_config_pdu_list[pdu_index].ulsch_pdu.ulsch_pdu_rel8.rnti == rnti) ||
+                  (ul_req_tmp->ul_config_pdu_list[pdu_index].uci_harq_pdu.ue_information.ue_information_rel8.rnti == rnti) ||
+                  (ul_req_tmp->ul_config_pdu_list[pdu_index].uci_cqi_pdu.ue_information.ue_information_rel8.rnti == rnti) ||
+                  (ul_req_tmp->ul_config_pdu_list[pdu_index].uci_sr_pdu.ue_information.ue_information_rel8.rnti == rnti) ||
+                  (ul_req_tmp->ul_config_pdu_list[pdu_index].srs_pdu.srs_pdu_rel8.rnti == rnti)) {
+                LOG_I(RRC, "remove UE %x from ul_config_pdu_list %d/%d\n", rnti, pdu_index, pdu_number);
+
+                if(pdu_index < pdu_number -1) {
+                  memcpy(&ul_req_tmp->ul_config_pdu_list[pdu_index], &ul_req_tmp->ul_config_pdu_list[pdu_index+1], (pdu_number-1-pdu_index) * sizeof(nfapi_ul_config_request_pdu_t));
                 }
+
+                ul_req_tmp->number_of_pdus--;
               }
             }
-            if (RC.rrc[mod_id]->node_type != ngran_eNB_CU
-                && RC.rrc[mod_id]->node_type != ngran_ng_eNB_CU
-                && RC.rrc[mod_id]->node_type != ngran_gNB_CU) {
-              rrc_mac_remove_ue(mod_id,rnti);
-              rrc_rlc_remove_ue(&ctxt);
-            }
-            else if (RC.rrc[mod_id]->node_type == ngran_eNB_CU || RC.rrc[mod_id]->node_type == ngran_ng_eNB_CU) {
-              MessageDef *m = itti_alloc_new_message(TASK_RRC_ENB, F1AP_UE_CONTEXT_RELEASE_CMD);
-              F1AP_UE_CONTEXT_RELEASE_CMD(m).rnti = rnti;
-              F1AP_UE_CONTEXT_RELEASE_CMD(m).cause = F1AP_CAUSE_RADIO_NETWORK;
-              F1AP_UE_CONTEXT_RELEASE_CMD(m).cause_value = 10; // 10 = F1AP_CauseRadioNetwork_normal_release
-              F1AP_UE_CONTEXT_RELEASE_CMD(m).rrc_container = NULL;
-              F1AP_UE_CONTEXT_RELEASE_CMD(m).rrc_container_length = 0;
-              itti_send_msg_to_task(TASK_CU_F1, mod_id, m);
-            }
-            pdcp_remove_UE(&ctxt);
-
-            if(remove_UEContext){
-                ue_context_pP = rrc_eNB_get_ue_context(
-                                 RC.rrc[mod_id],rnti);
-                if(ue_context_pP){
-                    rrc_eNB_remove_ue_context(&ctxt,RC.rrc[mod_id],
-                        (struct rrc_eNB_ue_context_s*) ue_context_pP);
-                }
-            }
-            LOG_I(RRC, "[release_UE_in_freeList] remove UE %x from freeList\n", rnti);
-            remove_UE_from_freelist(mod_id, rnti);
+          }
         }
+      }
+
+      if (RC.rrc[mod_id]->node_type != ngran_eNB_CU
+          && RC.rrc[mod_id]->node_type != ngran_ng_eNB_CU
+          && RC.rrc[mod_id]->node_type != ngran_gNB_CU) {
+        rrc_mac_remove_ue(mod_id,rnti);
+        rrc_rlc_remove_ue(&ctxt);
+        pdcp_remove_UE(&ctxt);
+      }
+      else if (RC.rrc[mod_id]->node_type == ngran_eNB_CU || RC.rrc[mod_id]->node_type == ngran_ng_eNB_CU) {
+        MessageDef *m = itti_alloc_new_message(TASK_RRC_ENB, F1AP_UE_CONTEXT_RELEASE_CMD);
+        F1AP_UE_CONTEXT_RELEASE_CMD(m).rnti = rnti;
+        F1AP_UE_CONTEXT_RELEASE_CMD(m).cause = F1AP_CAUSE_RADIO_NETWORK;
+        F1AP_UE_CONTEXT_RELEASE_CMD(m).cause_value = 10; // 10 = F1AP_CauseRadioNetwork_normal_release
+        F1AP_UE_CONTEXT_RELEASE_CMD(m).rrc_container = NULL;
+        F1AP_UE_CONTEXT_RELEASE_CMD(m).rrc_container_length = 0;
+        itti_send_msg_to_task(TASK_CU_F1, mod_id, m);
+      }
+
+      if(remove_UEContext) {
+        ue_context_pP = rrc_eNB_get_ue_context(RC.rrc[mod_id],rnti);
+
+        if(ue_context_pP) {
+          rrc_eNB_remove_ue_context(&ctxt,RC.rrc[mod_id],
+                                    (struct rrc_eNB_ue_context_s *) ue_context_pP);
+        }
+      }
+
+      LOG_I(RRC, "[release_UE_in_freeList] remove UE %x from freeList\n", rnti);
+      remove_UE_from_freelist(mod_id, rnti);
     }
+  }
 }
 
 //-----------------------------------------------------------------------------
+/*
+* Process the rrc connection setup complete message from UE (SRB1 Active)
+*/
 void
 rrc_eNB_process_RRCConnectionSetupComplete(
-  const protocol_ctxt_t* const ctxt_pP,
-  rrc_eNB_ue_context_t*         ue_context_pP,
-  RRCConnectionSetupComplete_r8_IEs_t * rrcConnectionSetupComplete
+  const protocol_ctxt_t *const ctxt_pP,
+  rrc_eNB_ue_context_t *ue_context_pP,
+  LTE_RRCConnectionSetupComplete_r8_IEs_t *rrcConnectionSetupComplete
 )
 //-----------------------------------------------------------------------------
 {
   LOG_I(RRC,
-        PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel UL-DCCH, " "processing RRCConnectionSetupComplete from UE (SRB1 Active)\n",
+        PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel UL-DCCH, " "processing LTE_RRCConnectionSetupComplete from UE (SRB1 Active)\n",
         PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
-
-  ue_context_pP->ue_context.Srb1.Active=1;  
+  ue_context_pP->ue_context.Srb1.Active = 1;
+  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
   T(T_ENB_RRC_CONNECTION_SETUP_COMPLETE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
     T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
 
   if (EPC_MODE_ENABLED == 1) {
     // Forward message to S1AP layer
-    rrc_eNB_send_S1AP_NAS_FIRST_REQ(
-      ctxt_pP,
-      ue_context_pP,
-      rrcConnectionSetupComplete);
+    rrc_eNB_send_S1AP_NAS_FIRST_REQ(ctxt_pP, ue_context_pP, rrcConnectionSetupComplete);
   } else {
     // RRC loop back (no S1AP), send SecurityModeCommand to UE
-    rrc_eNB_generate_SecurityModeCommand(
-      ctxt_pP,
-      ue_context_pP);
-/*
-	 if ((RC.rrc[ctxt_pP->module_id]->node_type  == ngran_eNB_CU) ||
-		 (RC.rrc[ctxt_pP->module_id]->node_type  == ngran_gNB_CU)   ||
-		 (RC.rrc[ctxt_pP->module_id]->node_type  == ngran_ng_eNB_CU)) {
-
-message_p = itti_alloc_new_message (TASK_RRC_ENB, F1AP_UE_CONTEXT_SETUP_REQ);
-      F1AP_UE_CONTEXT_SETUP_REQ (message_p).rrc_container =  ue_p->Srb0.Tx_buffer.Payload;
-
-      F1AP_UE_CONTEXT_SETUP_REQ (message_p).rrc_container_length = ue_p->Srb0.Tx_buffer.payload_size;
-      F1AP_UE_CONTEXT_SETUP_REQ (message_p).gNB_CU_ue_id     = 0;  
-      F1AP_UE_CONTEXT_SETUP_REQ (message_p).gNB_DU_ue_id = 0;
-      F1AP_UE_CONTEXT_SETUP_REQ (message_p).old_gNB_DU_ue_id  = 0xFFFFFFFF; // unknown 
-      F1AP_UE_CONTEXT_SETUP_REQ (message_p).rnti = ue_p->rnti; 
-      F1AP_UE_CONTEXT_SETUP_REQ (message_p).srb_id = CCCH;  
-      F1AP_UE_CONTEXT_SETUP_REQ (message_p).execute_duplication      = 1;
-      F1AP_UE_CONTEXT_SETUP_REQ (message_p).RAT_frequency_priority_information.en_dc      = 0; 
-      itti_send_msg_to_task (TASK_CU_F1, ctxt_pP->module_id, message_p);
-      LOG_D(RRC, "Send F1AP_UE_CONTEXT_SETUP_REQ with ITTI\n");
-  }
-*/ 
-    // rrc_eNB_generate_UECapabilityEnquiry(enb_mod_idP,frameP,ue_mod_idP);
-
+    rrc_eNB_generate_SecurityModeCommand(ctxt_pP, ue_context_pP);
   }
 }
 
 //-----------------------------------------------------------------------------
 void
 rrc_eNB_generate_SecurityModeCommand(
-  const protocol_ctxt_t* const ctxt_pP,
-  rrc_eNB_ue_context_t*          const ue_context_pP
+  const protocol_ctxt_t *const ctxt_pP,
+  rrc_eNB_ue_context_t          *const ue_context_pP
 )
 //-----------------------------------------------------------------------------
 {
   uint8_t                             buffer[100];
   uint8_t                             size;
-
   T(T_ENB_RRC_SECURITY_MODE_COMMAND, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
     T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
-
   size = do_SecurityModeCommand(
            ctxt_pP,
            buffer,
            rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),
            ue_context_pP->ue_context.ciphering_algorithm,
            ue_context_pP->ue_context.integrity_algorithm);
-
-
   LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,size,"[MSG] RRC Security Mode Command\n");
-
   LOG_I(RRC,
         PROTOCOL_RRC_CTXT_UE_FMT" Logical Channel DL-DCCH, Generate SecurityModeCommand (bytes %d)\n",
         PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
         size);
-
   LOG_D(RRC,
         PROTOCOL_RRC_CTXT_UE_FMT" --- PDCP_DATA_REQ/%d Bytes (securityModeCommand to UE MUI %d) --->[PDCP][RB %02d]\n",
         PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
         size,
         rrc_eNB_mui,
         DCCH);
-
   MSC_LOG_TX_MESSAGE(
     MSC_RRC_ENB,
     MSC_RRC_UE,
@@ -1202,54 +1199,46 @@ rrc_eNB_generate_SecurityModeCommand(
     rrc_eNB_mui,
     size);
 
- if ((RC.rrc[ctxt_pP->module_id]->node_type  != ngran_eNB_DU) ||
-	   (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_DU)) {
-  LOG_I(RRC,"calling rrc_data_req :securityModeCommand\n");
-
-    rrc_data_req(
-	       ctxt_pP,
-	       DCCH,
-	       rrc_eNB_mui++,
-	       SDU_CONFIRM_NO,
-	       size,
-	       buffer,
-	       PDCP_TRANSMISSION_MODE_CONTROL);
- }
+  if ((RC.rrc[ctxt_pP->module_id]->node_type  != ngran_eNB_DU) ||
+      (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_DU)) {
+    LOG_I(RRC,"calling rrc_data_req :securityModeCommand\n");
 
+    rrc_data_req(ctxt_pP,
+                 DCCH,
+                 rrc_eNB_mui++,
+                 SDU_CONFIRM_NO,
+                 size,
+                 buffer,
+                 PDCP_TRANSMISSION_MODE_CONTROL);
+  }
 }
 
 //-----------------------------------------------------------------------------
 void
 rrc_eNB_generate_UECapabilityEnquiry(
-  const protocol_ctxt_t* const ctxt_pP,
-  rrc_eNB_ue_context_t*          const ue_context_pP
+  const protocol_ctxt_t *const ctxt_pP,
+  rrc_eNB_ue_context_t          *const ue_context_pP
 )
 //-----------------------------------------------------------------------------
 {
-
   uint8_t                             buffer[100];
   uint8_t                             size;
-
   T(T_ENB_RRC_UE_CAPABILITY_ENQUIRY, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
     T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
-
   size = do_UECapabilityEnquiry(
            ctxt_pP,
            buffer,
            rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id));
-
   LOG_I(RRC,
         PROTOCOL_RRC_CTXT_UE_FMT" Logical Channel DL-DCCH, Generate UECapabilityEnquiry (bytes %d)\n",
         PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
         size);
-
   LOG_D(RRC,
         PROTOCOL_RRC_CTXT_UE_FMT" --- PDCP_DATA_REQ/%d Bytes (UECapabilityEnquiry MUI %d) --->[PDCP][RB %02d]\n",
         PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
         size,
         rrc_eNB_mui,
         DCCH);
-
   MSC_LOG_TX_MESSAGE(
     MSC_RRC_ENB,
     MSC_RRC_UE,
@@ -1260,53 +1249,48 @@ rrc_eNB_generate_UECapabilityEnquiry(
     ue_context_pP->ue_context.rnti,
     rrc_eNB_mui,
     size);
-
   rrc_data_req(
-	       ctxt_pP,
-	       DCCH,
-	       rrc_eNB_mui++,
-	       SDU_CONFIRM_NO,
-	       size,
-	       buffer,
-	       PDCP_TRANSMISSION_MODE_CONTROL);
-
+    ctxt_pP,
+    DCCH,
+    rrc_eNB_mui++,
+    SDU_CONFIRM_NO,
+    size,
+    buffer,
+    PDCP_TRANSMISSION_MODE_CONTROL);
 }
 
 //-----------------------------------------------------------------------------
 void
 rrc_eNB_generate_RRCConnectionReject(
-  const protocol_ctxt_t* const ctxt_pP,
-  rrc_eNB_ue_context_t*          const ue_context_pP,
+  const protocol_ctxt_t *const ctxt_pP,
+  rrc_eNB_ue_context_t          *const ue_context_pP,
   const int                    CC_id
 )
 //-----------------------------------------------------------------------------
 {
-
   T(T_ENB_RRC_CONNECTION_REJECT, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
     T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
 
-  eNB_RRC_UE_t *ue_p = &ue_context_pP->ue_context; 
+  eNB_RRC_UE_t *ue_p = &ue_context_pP->ue_context;
   ue_p->Srb0.Tx_buffer.payload_size =
     do_RRCConnectionReject(ctxt_pP->module_id,
                           (uint8_t*) ue_p->Srb0.Tx_buffer.Payload);
 
   LOG_DUMPMSG(RRC,DEBUG_RRC,
               (char *)(ue_p->Srb0.Tx_buffer.Payload),
-	      ue_p->Srb0.Tx_buffer.payload_size,
+              ue_p->Srb0.Tx_buffer.payload_size,
               "[MSG] RRCConnectionReject\n");
-
   MSC_LOG_TX_MESSAGE(
     MSC_RRC_ENB,
     MSC_RRC_UE,
     ue_p->Srb0.Tx_buffer.Header,
     ue_p->Srb0.Tx_buffer.payload_size,
-    MSC_AS_TIME_FMT" RRCConnectionReject UE %x size %u",
+    MSC_AS_TIME_FMT" LTE_RRCConnectionReject UE %x size %u",
     MSC_AS_TIME_ARGS(ctxt_pP),
     ue_context_pP == NULL ? -1 : ue_context_pP->ue_context.rnti,
     ue_p->Srb0.Tx_buffer.payload_size);
-
   LOG_I(RRC,
-        PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel DL-CCCH, Generating RRCConnectionReject (bytes %d)\n",
+        PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel DL-CCCH, Generating LTE_RRCConnectionReject (bytes %d)\n",
         PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
         ue_p->Srb0.Tx_buffer.payload_size);
 }
@@ -1314,17 +1298,16 @@ rrc_eNB_generate_RRCConnectionReject(
 //-----------------------------------------------------------------------------
 void
 rrc_eNB_generate_RRCConnectionReestablishment(
-  const protocol_ctxt_t*         const ctxt_pP,
-  rrc_eNB_ue_context_t*          const ue_context_pP,
+  const protocol_ctxt_t         *const ctxt_pP,
+  rrc_eNB_ue_context_t          *const ue_context_pP,
   const int                            CC_id
 )
 //-----------------------------------------------------------------------------
 {
-  LogicalChannelConfig_t             *SRB1_logicalChannelConfig;
-  SRB_ToAddModList_t                 **SRB_configList;
-  SRB_ToAddMod_t                     *SRB1_config;
+  LTE_LogicalChannelConfig_t             *SRB1_logicalChannelConfig;
+  LTE_SRB_ToAddModList_t                 **SRB_configList;
+  LTE_SRB_ToAddMod_t                     *SRB1_config;
   int                                 cnt;
-
   T(T_ENB_RRC_CONNECTION_REESTABLISHMENT, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
     T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
 
@@ -1336,7 +1319,7 @@ rrc_eNB_generate_RRCConnectionReestablishment(
     do_RRCConnectionReestablishment(ctxt_pP,
                                     ue_context_pP,
                                     CC_id,
-                                    (uint8_t*) ue_p->Srb0.Tx_buffer.Payload,
+                                    (uint8_t *) ue_p->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,
@@ -1345,7 +1328,7 @@ rrc_eNB_generate_RRCConnectionReestablishment(
               (char *)(ue_p->Srb0.Tx_buffer.Payload),
               ue_p->Srb0.Tx_buffer.payload_size,
               "[MSG] RRCConnectionReestablishment\n"
-              );
+             );
   // configure SRB1 for UE
 
   if (*SRB_configList != NULL) {
@@ -1355,7 +1338,7 @@ rrc_eNB_generate_RRCConnectionReestablishment(
 
         if (SRB1_config->logicalChannelConfig) {
           if (SRB1_config->logicalChannelConfig->present ==
-              SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
+              LTE_SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
             SRB1_logicalChannelConfig = &SRB1_config->logicalChannelConfig->choice.explicitValue;
           } else {
             SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
@@ -1367,42 +1350,42 @@ rrc_eNB_generate_RRCConnectionReestablishment(
         LOG_D(RRC,
               PROTOCOL_RRC_CTXT_UE_FMT" RRC_eNB --- MAC_CONFIG_REQ  (SRB1) ---> MAC_eNB\n",
               PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
-	if (RC.rrc[ctxt_pP->module_id]->node_type == ngran_eNB) {
-	  rrc_mac_config_req_eNB(ctxt_pP->module_id,
-				 ue_context_pP->ue_context.primaryCC_id,
-				 0,0,0,0,0,
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-				 0,
-#endif
-				 ctxt_pP->rnti,
-				 (BCCH_BCH_Message_t *) NULL, 
-				 (RadioResourceConfigCommonSIB_t *) NULL,
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-				 (RadioResourceConfigCommonSIB_t *) NULL,
-#endif
-				 (struct PhysicalConfigDedicated* ) ue_context_pP->ue_context.physicalConfigDedicated,
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-				 (SCellToAddMod_r10_t *)NULL,
-				 //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
-#endif
-				 (MeasObjectToAddMod_t **) NULL,
-				 ue_context_pP->ue_context.mac_MainConfig,
-				 1,
-				 SRB1_logicalChannelConfig,
-				 ue_context_pP->ue_context.measGapConfig,
-				 (TDD_Config_t *) NULL,
-				 NULL,
-				 (SchedulingInfoList_t *) NULL,
-				 0, NULL, NULL, (MBSFN_SubframeConfigList_t *) NULL
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-				 , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
-#endif
-#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
-				 ,(SystemInformationBlockType1_v1310_IEs_t *)NULL 
-#endif
-				 );
-	}
-        break;
+        if (RC.rrc[ctxt_pP->module_id]->node_type == ngran_eNB) {
+          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
+                                 ctxt_pP->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
+                                 (struct LTE_PhysicalConfigDedicated * ) 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,
+                                 NULL,
+                                 (LTE_SchedulingInfoList_t *) NULL,
+                                 0, NULL, NULL, (LTE_MBSFN_SubframeConfigList_t *) NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 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
+                                );
+          break;
+        }
       }
     }
   }
@@ -1411,442 +1394,393 @@ rrc_eNB_generate_RRCConnectionReestablishment(
                      MSC_RRC_UE,
                      ue_p->Srb0.Tx_buffer.Header,
                      ue_p->Srb0.Tx_buffer.payload_size,
-                     MSC_AS_TIME_FMT" RRCConnectionReestablishment UE %x size %u",
+                     MSC_AS_TIME_FMT" LTE_RRCConnectionReestablishment UE %x size %u",
                      MSC_AS_TIME_ARGS(ctxt_pP),
                      ue_context_pP->ue_context.rnti,
                      ue_p->Srb0.Tx_buffer.payload_size);
 
   LOG_I(RRC,
-        PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel DL-CCCH, Generating RRCConnectionReestablishment (bytes %d)\n",
+        PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel DL-CCCH, Generating LTE_RRCConnectionReestablishment (bytes %d)\n",
         PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
         ue_p->Srb0.Tx_buffer.payload_size);
-  	if ( (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_eNB_CU) &&
-       (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_ng_eNB_CU)&& 
-       (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_CU)   ) { 	
+  if ((RC.rrc[ctxt_pP->module_id]->node_type  != ngran_eNB_CU) &&
+     (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_ng_eNB_CU) &&
+     (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_CU)) {
 	  int UE_id = find_UE_id(ctxt_pP->module_id, ctxt_pP->rnti);
 	  if(UE_id != -1){
 	    // activate release timer, if RRCComplete not received after 100 frames, remove UE
 	    RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].ue_reestablishment_reject_timer = 1;
 	    // remove UE after 100 frames after RRCConnectionReestablishmentRelease is triggered
 	    RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].ue_reestablishment_reject_timer_thres = 1000;
-	  }else{
+	  } else{
 	    LOG_E(RRC,
-	             PROTOCOL_RRC_CTXT_UE_FMT" Generating RRCConnectionReestablishment without UE_id(MAC) rnti %x\n",
-	            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ctxt_pP->rnti);
+	          PROTOCOL_RRC_CTXT_UE_FMT" Generating LTE_RRCConnectionReestablishment without UE_id(MAC) rnti %x\n",
+	          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP), ctxt_pP->rnti);
 	  }
-	}	
+  }
   // activate release timer, if RRCComplete not received after 100 frames, remove UE
   ue_context_pP->ue_context.ue_reestablishment_timer = 1;
-  // remove UE after 100 frames after RRCConnectionReestablishmentRelease is triggered
+  // remove UE after 100 frames after LTE_RRCConnectionReestablishmentRelease is triggered
   ue_context_pP->ue_context.ue_reestablishment_timer_thres = 1000;
 }
 
 //-----------------------------------------------------------------------------
 void
 rrc_eNB_process_RRCConnectionReestablishmentComplete(
-  const protocol_ctxt_t* const ctxt_pP,
+  const protocol_ctxt_t *const ctxt_pP,
   const rnti_t reestablish_rnti,
-  rrc_eNB_ue_context_t*         ue_context_pP,
+  rrc_eNB_ue_context_t         *ue_context_pP,
   const uint8_t xid,
-  RRCConnectionReestablishmentComplete_r8_IEs_t * rrcConnectionReestablishmentComplete
+  LTE_RRCConnectionReestablishmentComplete_r8_IEs_t *LTE_RRCConnectionReestablishmentComplete
 )
 //-----------------------------------------------------------------------------
 {
   LOG_I(RRC,
-        PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel UL-DCCH, processing RRCConnectionReestablishmentComplete from UE (SRB1 Active)\n",
+        PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel UL-DCCH, processing LTE_RRCConnectionReestablishmentComplete from UE (SRB1 Active)\n",
         PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
-
   T(T_ENB_RRC_CONNECTION_REESTABLISHMENT_COMPLETE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
     T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
-
-  DRB_ToAddModList_t*                 DRB_configList = ue_context_pP->ue_context.DRB_configList;
-  SRB_ToAddModList_t*                 SRB_configList = ue_context_pP->ue_context.SRB_configList;
-  SRB_ToAddModList_t**                SRB_configList2 = NULL;
-  DRB_ToAddModList_t**                DRB_configList2 = NULL;
-  struct SRB_ToAddMod                *SRB2_config = NULL;
-  struct DRB_ToAddMod                *DRB_config = NULL;
+  LTE_DRB_ToAddModList_t                 *DRB_configList = ue_context_pP->ue_context.DRB_configList;
+  LTE_SRB_ToAddModList_t                 *SRB_configList = ue_context_pP->ue_context.SRB_configList;
+  LTE_SRB_ToAddModList_t                **SRB_configList2 = NULL;
+  LTE_DRB_ToAddModList_t                **DRB_configList2 = NULL;
+  struct LTE_SRB_ToAddMod                *SRB2_config = NULL;
+  struct LTE_DRB_ToAddMod                *DRB_config = NULL;
   int i = 0;
   uint8_t                             buffer[RRC_BUF_SIZE];
   uint16_t                            size;
-  MeasObjectToAddModList_t           *MeasObj_list                     = NULL;
-  MeasObjectToAddMod_t               *MeasObj                          = NULL;
-  ReportConfigToAddModList_t         *ReportConfig_list                = NULL;
-  ReportConfigToAddMod_t             *ReportConfig_per, *ReportConfig_A1,
+  LTE_MeasObjectToAddModList_t       *MeasObj_list                     = NULL;
+  LTE_MeasObjectToAddMod_t           *MeasObj                          = NULL;
+  LTE_ReportConfigToAddModList_t     *ReportConfig_list                = NULL;
+  LTE_ReportConfigToAddMod_t         *ReportConfig_per, *ReportConfig_A1,
                                      *ReportConfig_A2, *ReportConfig_A3, *ReportConfig_A4, *ReportConfig_A5;
-  MeasIdToAddModList_t               *MeasId_list                      = NULL;
-  MeasIdToAddMod_t                   *MeasId0, *MeasId1, *MeasId2, *MeasId3, *MeasId4, *MeasId5;
-  RSRP_Range_t                       *rsrp                             = NULL;
-  struct MeasConfig__speedStatePars  *Sparams                          = NULL;
-  QuantityConfig_t                   *quantityConfig                   = NULL;
-  CellsToAddMod_t                    *CellToAdd                        = NULL;
-  CellsToAddModList_t                *CellsToAddModList                = NULL;
-  struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
-  DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
+  LTE_MeasIdToAddModList_t           *MeasId_list                      = NULL;
+  LTE_MeasIdToAddMod_t               *MeasId0, *MeasId1, *MeasId2, *MeasId3, *MeasId4, *MeasId5;
+  LTE_RSRP_Range_t                   *rsrp                             = NULL;
+  struct LTE_MeasConfig__speedStatePars  *Sparams                          = NULL;
+  LTE_QuantityConfig_t                   *quantityConfig                   = NULL;
+  LTE_CellsToAddMod_t                    *CellToAdd                        = NULL;
+  LTE_CellsToAddModList_t                *CellsToAddModList                = NULL;
+  struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
+  LTE_DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
   /* for no gcc warnings */
   (void)dedicatedInfoNas;
-  C_RNTI_t                           *cba_RNTI                         = NULL;
+  LTE_C_RNTI_t                           *cba_RNTI                         = NULL;
   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
   ue_context_pP->ue_context.reestablishment_xid = next_xid;
-
   SRB_configList2 = &ue_context_pP->ue_context.SRB_configList2[xid];
+
   // get old configuration of SRB2
   if (*SRB_configList2 != NULL) {
-    if((*SRB_configList2)->list.count!=0){
+    if((*SRB_configList2)->list.count!=0) {
       LOG_D(RRC, "SRB_configList2(%p) count is %d\n           SRB_configList2->list.array[0] addr is %p",
-          SRB_configList2, (*SRB_configList2)->list.count,  (*SRB_configList2)->list.array[0]);
+            SRB_configList2, (*SRB_configList2)->list.count,  (*SRB_configList2)->list.array[0]);
     }
+
     for (i = 0; (i < (*SRB_configList2)->list.count) && (i < 3); i++) {
-      if ((*SRB_configList2)->list.array[i]->srb_Identity == 2 ){
+      if ((*SRB_configList2)->list.array[i]->srb_Identity == 2 ) {
         LOG_D(RRC, "get SRB2_config from (ue_context_pP->ue_context.SRB_configList2[%d])\n", xid);
         SRB2_config = (*SRB_configList2)->list.array[i];
         break;
       }
     }
   }
-  SRB_configList2 = &ue_context_pP->ue_context.SRB_configList2[next_xid];
-  DRB_configList2 = &ue_context_pP->ue_context.DRB_configList2[next_xid];
 
-  if(SRB_configList2!=NULL){
-    if (*SRB_configList2) {
-      free(*SRB_configList2);
-      LOG_D(RRC, "free(ue_context_pP->ue_context.SRB_configList2[%d])\n", next_xid);
-    }
-  }else{
-      LOG_E(RRC, "SRB_configList2 is null\n");
-  }
-  *SRB_configList2 = CALLOC(1, sizeof(**SRB_configList2));
+  SRB_configList2 = &(ue_context_pP->ue_context.SRB_configList2[next_xid]);
+  DRB_configList2 = &(ue_context_pP->ue_context.DRB_configList2[next_xid]);
+
+  if (*SRB_configList2) {
+    free(*SRB_configList2);
+    LOG_D(RRC, "free(ue_context_pP->ue_context.SRB_configList2[%d])\n", next_xid);
+  }
+
+  *SRB_configList2 = CALLOC(1, sizeof(**SRB_configList2));
+
   if (SRB2_config != NULL) {
     // Add SRB2 to SRB configuration list
-
     ASN_SEQUENCE_ADD(&SRB_configList->list, SRB2_config);
     ASN_SEQUENCE_ADD(&(*SRB_configList2)->list, SRB2_config);
-
     LOG_D(RRC, "Add SRB2_config (srb_Identity:%ld) to ue_context_pP->ue_context.SRB_configList\n",
-            SRB2_config->srb_Identity);
+          SRB2_config->srb_Identity);
     LOG_D(RRC, "Add SRB2_config (srb_Identity:%ld) to ue_context_pP->ue_context.SRB_configList2[%d]\n",
-                SRB2_config->srb_Identity, next_xid);
+          SRB2_config->srb_Identity, next_xid);
   } else {
     // SRB configuration list only contains SRB1.
     LOG_W(RRC,"SRB2 configuration does not exist in SRB configuration list\n");
   }
 
-
-
-  if(DRB_configList2!=NULL){
-    if (*DRB_configList2) {
-      free(*DRB_configList2);
-      LOG_D(RRC, "free(ue_context_pP->ue_context.DRB_configList2[%d])\n", next_xid);
-    }
-  }else{
-      LOG_E(RRC, "DRB_configList2 is null\n");
+  if (*DRB_configList2) {
+    free(*DRB_configList2);
+    LOG_D(RRC, "free(ue_context_pP->ue_context.DRB_configList2[%d])\n", next_xid);
   }
+
   *DRB_configList2 = CALLOC(1, sizeof(**DRB_configList2));
 
   if (DRB_configList != NULL) {
     LOG_D(RRC, "get DRB_config from (ue_context_pP->ue_context.DRB_configList)\n");
+
     for (i = 0; (i < DRB_configList->list.count) && (i < 3); i++) {
       DRB_config = DRB_configList->list.array[i];
-
-      // Add DRB to DRB configuration list, for RRCConnectionReconfigurationComplete
+      // Add DRB to DRB configuration list, for LTE_RRCConnectionReconfigurationComplete
       ASN_SEQUENCE_ADD(&(*DRB_configList2)->list, DRB_config);
     }
   }
+
   ue_context_pP->ue_context.Srb1.Active = 1;
   //ue_context_pP->ue_context.Srb2.Srb_info.Srb_id = 2;
-
-#if defined(ENABLE_USE_MME) 
-    hashtable_rc_t    h_rc;
-    int               j;
-    rrc_ue_s1ap_ids_t* rrc_ue_s1ap_ids_p = NULL;
-    uint16_t ue_initial_id = ue_context_pP->ue_context.ue_initial_id;
-    uint32_t eNB_ue_s1ap_id = ue_context_pP->ue_context.eNB_ue_s1ap_id;
-    eNB_RRC_INST *rrc_instance_p = RC.rrc[ENB_INSTANCE_TO_MODULE_ID(ctxt_pP->instance)];
-    if (eNB_ue_s1ap_id > 0) {
-      h_rc = hashtable_get(rrc_instance_p->s1ap_id2_s1ap_ids, (hash_key_t)eNB_ue_s1ap_id, (void**)&rrc_ue_s1ap_ids_p);
-      if  (h_rc == HASH_TABLE_OK) {
-  	rrc_ue_s1ap_ids_p->ue_rnti = ctxt_pP->rnti;
-      }
-    }
-    if (ue_initial_id != 0) {
-      h_rc = hashtable_get(rrc_instance_p->initial_id2_s1ap_ids, (hash_key_t)ue_initial_id, (void**)&rrc_ue_s1ap_ids_p);
-      if  (h_rc == HASH_TABLE_OK) {
-  	rrc_ue_s1ap_ids_p->ue_rnti = ctxt_pP->rnti;
-      }
+#if defined(ENABLE_USE_MME)
+  hashtable_rc_t    h_rc;
+  int               j;
+  rrc_ue_s1ap_ids_t *rrc_ue_s1ap_ids_p = NULL;
+  uint16_t ue_initial_id = ue_context_pP->ue_context.ue_initial_id;
+  uint32_t eNB_ue_s1ap_id = ue_context_pP->ue_context.eNB_ue_s1ap_id;
+  eNB_RRC_INST *rrc_instance_p = RC.rrc[ENB_INSTANCE_TO_MODULE_ID(ctxt_pP->instance)];
+
+  if (eNB_ue_s1ap_id > 0) {
+    h_rc = hashtable_get(rrc_instance_p->s1ap_id2_s1ap_ids, (hash_key_t)eNB_ue_s1ap_id, (void **)&rrc_ue_s1ap_ids_p);
+
+    if  (h_rc == HASH_TABLE_OK) {
+      rrc_ue_s1ap_ids_p->ue_rnti = ctxt_pP->rnti;
     }
+  }
 
-    gtpv1u_enb_create_tunnel_req_t  create_tunnel_req;
-
-    /* Save e RAB information for later */
-    memset(&create_tunnel_req, 0 , sizeof(create_tunnel_req));
-
-    for ( j = 0, i = 0; i < NB_RB_MAX; i++) {
-      if (ue_context_pP->ue_context.e_rab[i].status == E_RAB_STATUS_ESTABLISHED || ue_context_pP->ue_context.e_rab[i].status == E_RAB_STATUS_DONE) {
-  	create_tunnel_req.eps_bearer_id[j]	 = ue_context_pP->ue_context.e_rab[i].param.e_rab_id;
-  	create_tunnel_req.sgw_S1u_teid[j]	 = ue_context_pP->ue_context.e_rab[i].param.gtp_teid;
+  if (ue_initial_id != 0) {
+    h_rc = hashtable_get(rrc_instance_p->initial_id2_s1ap_ids, (hash_key_t)ue_initial_id, (void **)&rrc_ue_s1ap_ids_p);
 
-  	memcpy(&create_tunnel_req.sgw_addr[j],
-  	       &ue_context_pP->ue_context.e_rab[i].param.sgw_addr,
-  	       sizeof(transport_layer_addr_t));
-  	j++;
-      }
+    if  (h_rc == HASH_TABLE_OK) {
+      rrc_ue_s1ap_ids_p->ue_rnti = ctxt_pP->rnti;
     }
+  }
 
-    create_tunnel_req.rnti       = ctxt_pP->rnti; // warning put zero above
-    create_tunnel_req.num_tunnels    = j;
+  gtpv1u_enb_create_tunnel_req_t  create_tunnel_req;
+  /* Save e RAB information for later */
+  memset(&create_tunnel_req, 0, sizeof(create_tunnel_req));
+
+  for ( j = 0, i = 0; i < NB_RB_MAX; i++) {
+    if (ue_context_pP->ue_context.e_rab[i].status == E_RAB_STATUS_ESTABLISHED || ue_context_pP->ue_context.e_rab[i].status == E_RAB_STATUS_DONE) {
+      create_tunnel_req.eps_bearer_id[j]   = ue_context_pP->ue_context.e_rab[i].param.e_rab_id;
+      create_tunnel_req.sgw_S1u_teid[j]  = ue_context_pP->ue_context.e_rab[i].param.gtp_teid;
+      memcpy(&create_tunnel_req.sgw_addr[j],
+             &ue_context_pP->ue_context.e_rab[i].param.sgw_addr,
+             sizeof(transport_layer_addr_t));
+      j++;
+    }
+  }
 
-    gtpv1u_update_s1u_tunnel(
-              ctxt_pP->instance,
-              &create_tunnel_req,
-              reestablish_rnti);
+  create_tunnel_req.rnti       = ctxt_pP->rnti; // warning put zero above
+  create_tunnel_req.num_tunnels    = j;
+  gtpv1u_update_s1u_tunnel(
+    ctxt_pP->instance,
+    &create_tunnel_req,
+    reestablish_rnti);
 #endif
   /* Update RNTI in ue_context */
   ue_context_pP->ue_id_rnti                    = ctxt_pP->rnti; // here ue_id_rnti is just a key, may be something else
   ue_context_pP->ue_context.rnti               = ctxt_pP->rnti;
 #if defined(ENABLE_USE_MME)
-    uint8_t send_security_mode_command = FALSE;
-    rrc_pdcp_config_security(
-        ctxt_pP,
-        ue_context_pP,
-        send_security_mode_command);
-    LOG_D(RRC, "set security successfully \n");
+  uint8_t send_security_mode_command = FALSE;
+  rrc_pdcp_config_security(
+    ctxt_pP,
+    ue_context_pP,
+    send_security_mode_command);
+  LOG_D(RRC, "set security successfully \n");
 #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);
-
-  //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measIdToAddModList = MeasId_list;
-
+  //  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 = MeasObjectToAddMod__measObject_PR_measObjectEUTRA;
+  MeasObj->measObject.present = LTE_MeasObjectToAddMod__measObject_PR_measObjectEUTRA;
   MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 3350; //band 7, 2.68GHz
   //MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 36090; //band 33, 1.909GHz
-  MeasObj->measObject.choice.measObjectEUTRA.allowedMeasBandwidth = AllowedMeasBandwidth_mbw25;
+  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 =
-    (CellsToAddModList_t *) CALLOC(1, sizeof(*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 = (CellsToAddMod_t *) CALLOC(1, sizeof(*CellToAdd));
+    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 = Q_OffsetRange_dB0;
-
+    CellToAdd->cellIndividualOffset = LTE_Q_OffsetRange_dB0;
     ASN_SEQUENCE_ADD(&CellsToAddModList->list, CellToAdd);
   }
 
   ASN_SEQUENCE_ADD(&MeasObj_list->list, MeasObj);
-  //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measObjectToAddModList = MeasObj_list;
-
+  //  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 = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
+  ReportConfig_per->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
   ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.present =
-    ReportConfigEUTRA__triggerType_PR_periodical;
+    LTE_ReportConfigEUTRA__triggerType_PR_periodical;
   ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.choice.periodical.purpose =
-    ReportConfigEUTRA__triggerType__periodical__purpose_reportStrongestCells;
-  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerQuantity = ReportConfigEUTRA__triggerQuantity_rsrp;
-  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
+    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 = ReportInterval_ms120;
-  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;
-
+  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 = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
+  ReportConfig_A1->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
   ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.present =
-    ReportConfigEUTRA__triggerType_PR_event;
+    LTE_ReportConfigEUTRA__triggerType_PR_event;
   ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
-    ReportConfigEUTRA__triggerType__event__eventId_PR_eventA1;
+    LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA1;
   ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA1.
-  a1_Threshold.present = ThresholdEUTRA_PR_threshold_RSRP;
+  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 = ReportConfigEUTRA__triggerQuantity_rsrp;
-  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
+  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 = ReportInterval_ms120;
-  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;
-
+  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);
 
-  if (RC.rrc[ctxt_pP->module_id]->HO_flag == 1 /*HO_MEASURMENT */ ) {
+  if (RC.rrc[ctxt_pP->module_id]->HO_flag == 1 /*HO_MEASUREMENT */ ) {
     LOG_I(RRC, "[eNB %d] frame %d: requesting A2, A3, A4, A5, and A6 event reporting\n",
           ctxt_pP->module_id, ctxt_pP->frame);
     ReportConfig_A2->reportConfigId = 3;
-    ReportConfig_A2->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
+    ReportConfig_A2->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
     ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.present =
-      ReportConfigEUTRA__triggerType_PR_event;
+      LTE_ReportConfigEUTRA__triggerType_PR_event;
     ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
-      ReportConfigEUTRA__triggerType__event__eventId_PR_eventA2;
+      LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA2;
     ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
-    eventA2.a2_Threshold.present = ThresholdEUTRA_PR_threshold_RSRP;
+    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 =
-      ReportConfigEUTRA__triggerQuantity_rsrp;
-    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
+      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 = ReportInterval_ms120;
-    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;
-
+    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 = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
+    ReportConfig_A3->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
     ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.present =
-      ReportConfigEUTRA__triggerType_PR_event;
+      LTE_ReportConfigEUTRA__triggerType_PR_event;
     ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
-      ReportConfigEUTRA__triggerType__event__eventId_PR_eventA3;
-
+      LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA3;
     ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA3.a3_Offset = 1;   //10;
     ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
     eventA3.reportOnLeave = 1;
-
     ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerQuantity =
-      ReportConfigEUTRA__triggerQuantity_rsrp;
-    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
+      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 = ReportInterval_ms120;
-    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;
-
+    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120;
+    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity;
     ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.hysteresis = 0.5; // FIXME ...hysteresis is of type long!
     ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.timeToTrigger =
-      TimeToTrigger_ms40;
+      LTE_TimeToTrigger_ms40;
     ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A3);
-
     ReportConfig_A4->reportConfigId = 5;
-    ReportConfig_A4->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
+    ReportConfig_A4->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
     ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.present =
-      ReportConfigEUTRA__triggerType_PR_event;
+      LTE_ReportConfigEUTRA__triggerType_PR_event;
     ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
-      ReportConfigEUTRA__triggerType__event__eventId_PR_eventA4;
+      LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA4;
     ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
-    eventA4.a4_Threshold.present = ThresholdEUTRA_PR_threshold_RSRP;
+    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 =
-      ReportConfigEUTRA__triggerQuantity_rsrp;
-    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
+      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 = ReportInterval_ms120;
-    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;
-
+    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 = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
+    ReportConfig_A5->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
     ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.present =
-      ReportConfigEUTRA__triggerType_PR_event;
+      LTE_ReportConfigEUTRA__triggerType_PR_event;
     ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
-      ReportConfigEUTRA__triggerType__event__eventId_PR_eventA5;
+      LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA5;
     ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
-    eventA5.a5_Threshold1.present = ThresholdEUTRA_PR_threshold_RSRP;
+    eventA5.a5_Threshold1.present = LTE_ThresholdEUTRA_PR_threshold_RSRP;
     ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
-    eventA5.a5_Threshold2.present = ThresholdEUTRA_PR_threshold_RSRP;
+    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 =
-      ReportConfigEUTRA__triggerQuantity_rsrp;
-    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
+      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 = ReportInterval_ms120;
-    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;
-
+    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);
-    //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->reportConfigToAddModList = ReportConfig_list;
-
-    rsrp = CALLOC(1, sizeof(RSRP_Range_t));
+    //  LTE_RRCConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->reportConfigToAddModList = ReportConfig_list;
+    rsrp = CALLOC(1, sizeof(LTE_RSRP_Range_t));
     *rsrp = 20;
-
     Sparams = CALLOC(1, sizeof(*Sparams));
-    Sparams->present = MeasConfig__speedStatePars_PR_setup;
-    Sparams->choice.setup.timeToTrigger_SF.sf_High = SpeedStateScaleFactors__sf_Medium_oDot75;
-    Sparams->choice.setup.timeToTrigger_SF.sf_Medium = SpeedStateScaleFactors__sf_High_oDot5;
+    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 = MobilityStateParameters__t_Evaluation_s60;
-    Sparams->choice.setup.mobilityStateParameters.t_HystNormal = MobilityStateParameters__t_HystNormal_s120;
-
+    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(struct QuantityConfigEUTRA));
+    quantityConfig->quantityConfigEUTRA = CALLOC(1, sizeof(struct LTE_QuantityConfigEUTRA));
     memset((void *)quantityConfig->quantityConfigEUTRA, 0, sizeof(*quantityConfig->quantityConfigEUTRA));
     quantityConfig->quantityConfigCDMA2000 = NULL;
     quantityConfig->quantityConfigGERAN = NULL;
@@ -1855,37 +1789,35 @@ rrc_eNB_process_RRCConnectionReestablishmentComplete(
       CALLOC(1, sizeof(*(quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP)));
     quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ =
       CALLOC(1, sizeof(*(quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ)));
-    *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP = FilterCoefficient_fc4;
-    *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ = FilterCoefficient_fc4;
-
+    *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP = LTE_FilterCoefficient_fc4;
+    *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ = LTE_FilterCoefficient_fc4;
     LOG_I(RRC,
           "[eNB %d] Frame %d: potential handover preparation: store the information in an intermediate structure in case of failure\n",
           ctxt_pP->module_id, ctxt_pP->frame);
     // store the information in an intermediate structure for Hanodver management
     //rrc_inst->handover_info.as_config.sourceRadioResourceConfig.srb_ToAddModList = CALLOC(1,sizeof());
     ue_context_pP->ue_context.handover_info = CALLOC(1, sizeof(*(ue_context_pP->ue_context.handover_info)));
-    //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.srb_ToAddModList,(void *)SRB_list,sizeof(SRB_ToAddModList_t));
+    //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.srb_ToAddModList,(void *)SRB_list,sizeof(LTE_SRB_ToAddModList_t));
     ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.srb_ToAddModList = *SRB_configList2;
-    //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.drb_ToAddModList,(void *)DRB_list,sizeof(DRB_ToAddModList_t));
+    //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.drb_ToAddModList,(void *)DRB_list,sizeof(LTE_DRB_ToAddModList_t));
     ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToAddModList = DRB_configList;
     ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToReleaseList = NULL;
     ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig =
       CALLOC(1, sizeof(*ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig));
-    memcpy((void*)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig,
-           (void *)ue_context_pP->ue_context.mac_MainConfig, sizeof(MAC_MainConfig_t));
+    memcpy((void *)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig,
+           (void *)ue_context_pP->ue_context.mac_MainConfig, sizeof(LTE_MAC_MainConfig_t));
     ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.physicalConfigDedicated =
-      CALLOC(1, sizeof(PhysicalConfigDedicated_t));
-    memcpy((void*)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.physicalConfigDedicated,
-           (void*)ue_context_pP->ue_context.physicalConfigDedicated, sizeof(PhysicalConfigDedicated_t));
+      CALLOC(1, sizeof(LTE_PhysicalConfigDedicated_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));
     ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.sps_Config = NULL;
     //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));
-
   }
 
 #ifdef CBA
   //struct PUSCH_CBAConfigDedicated_vlola  *pusch_CBAConfigDedicated_vlola;
   uint8_t                            *cba_RNTI_buf;
-  cba_RNTI = CALLOC(1, sizeof(C_RNTI_t));
+  cba_RNTI = CALLOC(1, sizeof(LTE_C_RNTI_t));
   cba_RNTI_buf = CALLOC(1, 2 * sizeof(uint8_t));
   cba_RNTI->buf = cba_RNTI_buf;
   cba_RNTI->size = 2;
@@ -1907,20 +1839,19 @@ rrc_eNB_process_RRCConnectionReestablishmentComplete(
   }
 
 #endif
-
 #if defined(ENABLE_ITTI)
   /* Initialize NAS list */
-  dedicatedInfoNASList = CALLOC(1, sizeof(struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));
+  dedicatedInfoNASList = CALLOC(1, sizeof(struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));
 
   /* Add all NAS PDUs to the list */
   for (i = 0; i < ue_context_pP->ue_context.nb_of_e_rabs; i++) {
     if (ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer != NULL) {
-      dedicatedInfoNas = CALLOC(1, sizeof(DedicatedInfoNAS_t));
+      dedicatedInfoNas = CALLOC(1, sizeof(LTE_DedicatedInfoNAS_t));
       memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t));
       OCTET_STRING_fromBuf(dedicatedInfoNas,
-         (char*)ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer,
+                           (char *)ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer,
                            ue_context_pP->ue_context.e_rab[i].param.nas_pdu.length);
-      LOG_D(RRC, "Add dedicatedInfoNas(%d) to dedicatedInfoNASList\n", i);
+      LOG_D(RRC, "Add LTE_DedicatedInfoNAS(%d) to LTE_DedicatedInfoNASList\n", i);
       ASN_SEQUENCE_ADD(&dedicatedInfoNASList->list, dedicatedInfoNas);
     }
 
@@ -1930,12 +1861,11 @@ rrc_eNB_process_RRCConnectionReestablishmentComplete(
       //      ue_context_pP->ue_context.e_rab[i].param.sgw_addr;
       //      ue_context_pP->ue_context.e_rab[i].param.gtp_teid;
     }
-
     /* TODO should test if e RAB are Ok before! */
     ue_context_pP->ue_context.e_rab[i].status = E_RAB_STATUS_DONE;
     ue_context_pP->ue_context.e_rab[i].xid    = xid;
     LOG_D(RRC, "setting the status for the default DRB (index %d) to (%d,%s)\n",
-    i, ue_context_pP->ue_context.e_rab[i].status, "E_RAB_STATUS_DONE");
+          i, ue_context_pP->ue_context.e_rab[i].status, "E_RAB_STATUS_DONE");
   }
 
   /* If list is empty free the list and reset the address */
@@ -1945,43 +1875,40 @@ rrc_eNB_process_RRCConnectionReestablishmentComplete(
   }
 
 #endif
-
-  // send RRCConnectionReconfiguration
+  // send LTE_RRCConnectionReconfiguration
   memset(buffer, 0, RRC_BUF_SIZE);
-
   size = do_RRCConnectionReconfiguration(ctxt_pP,
                                          buffer,
                                          next_xid,   //Transaction_id,
-                                         (SRB_ToAddModList_t*)*SRB_configList2, // SRB_configList
-                                         (DRB_ToAddModList_t*)DRB_configList,
-                                         (DRB_ToReleaseList_t*)NULL,  // DRB2_list,
-                                         (struct SPS_Config*)NULL,    // maybe ue_context_pP->ue_context.sps_Config,
-                                         (struct PhysicalConfigDedicated*)ue_context_pP->ue_context.physicalConfigDedicated,
+                                         (LTE_SRB_ToAddModList_t *)*SRB_configList2, // SRB_configList
+                                         (LTE_DRB_ToAddModList_t *)DRB_configList,
+                                         (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
-                                         (MeasObjectToAddModList_t*)MeasObj_list,  // MeasObj_list,
-                                         (ReportConfigToAddModList_t*)ReportConfig_list,  // ReportConfig_list,
-                                         (QuantityConfig_t*)quantityConfig,  //quantityConfig,
-                                         (MeasIdToAddModList_t*)NULL,
-#endif
-                                         (MAC_MainConfig_t*)ue_context_pP->ue_context.mac_MainConfig,
-                                         (MeasGapConfig_t*)NULL,
-                                         (MobilityControlInfo_t*)NULL,
-                                         (struct MeasConfig__speedStatePars*)Sparams, // Sparams,
-                                         (RSRP_Range_t*)rsrp, // rsrp,
-                                         (C_RNTI_t*)cba_RNTI,  // cba_RNTI
-                                         (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList*)dedicatedInfoNASList, //dedicatedInfoNASList
-                                         (SL_CommConfig_r12_t*)NULL,
-                                         (SL_DiscConfig_r12_t*)NULL
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-                                         , (SCellToAddMod_r10_t*)NULL
+                                         (LTE_MeasObjectToAddModList_t *)MeasObj_list, // MeasObj_list,
+                                         (LTE_ReportConfigToAddModList_t *)ReportConfig_list, // ReportConfig_list,
+                                         (LTE_QuantityConfig_t *)quantityConfig, //quantityConfig,
+                                         (LTE_MeasIdToAddModList_t *)NULL,
+#endif
+                                         (LTE_MAC_MainConfig_t *)ue_context_pP->ue_context.mac_MainConfig,
+                                         (LTE_MeasGapConfig_t *)NULL,
+                                         (LTE_MobilityControlInfo_t *)NULL,
+                                         (LTE_SecurityConfigHO_t *)NULL,
+                                         (struct LTE_MeasConfig__speedStatePars *)Sparams, // Sparams,
+                                         (LTE_RSRP_Range_t *)rsrp, // rsrp,
+                                         (LTE_C_RNTI_t *)cba_RNTI, // cba_RNTI
+                                         (struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *)dedicatedInfoNASList, //dedicatedInfoNASList
+                                         (LTE_SL_CommConfig_r12_t *)NULL,
+                                         (LTE_SL_DiscConfig_r12_t *)NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                                         , (LTE_SCellToAddMod_r10_t *)NULL
 #endif
                                         );
   LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,size,
               "[MSG] RRC Connection Reconfiguration\n");
-
-
 #if defined(ENABLE_ITTI)
 
   /* Free all NAS PDUs */
@@ -1994,78 +1921,77 @@ rrc_eNB_process_RRCConnectionReestablishmentComplete(
   }
 
 #endif
-  if(size==65535){
+
+  if(size==65535) {
     LOG_E(RRC,"RRC decode err!!! do_RRCConnectionReconfiguration\n");
     put_UE_in_freelist(ctxt_pP->module_id, reestablish_rnti, 0);
     return;
-  }else{
+  } else {
     LOG_I(RRC,
-          "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration (bytes %d, UE id %x)\n",
+          "[eNB %d] Frame %d, 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",
           ctxt_pP->frame, ctxt_pP->module_id, size, ue_context_pP->ue_context.rnti, rrc_eNB_mui, ctxt_pP->module_id, DCCH);
-
     MSC_LOG_TX_MESSAGE(
       MSC_RRC_ENB,
       MSC_RRC_UE,
       buffer,
       size,
-      MSC_AS_TIME_FMT" rrcConnectionReconfiguration UE %x MUI %d size %u",
+      MSC_AS_TIME_FMT" LTE_RRCConnectionReconfiguration UE %x MUI %d size %u",
       MSC_AS_TIME_ARGS(ctxt_pP),
       ue_context_pP->ue_context.rnti,
       rrc_eNB_mui,
       size);
-
     rrc_data_req(
-           ctxt_pP,
-           DCCH,
-           rrc_eNB_mui++,
-           SDU_CONFIRM_NO,
-           size,
-           buffer,
-           PDCP_TRANSMISSION_MODE_CONTROL);
+      ctxt_pP,
+      DCCH,
+      rrc_eNB_mui++,
+      SDU_CONFIRM_NO,
+      size,
+      buffer,
+      PDCP_TRANSMISSION_MODE_CONTROL);
   }
+
   // delete UE data of prior RNTI.  UE use current RNTI.
-//  protocol_ctxt_t ctxt_prior = *ctxt_pP;
-//  ctxt_prior.rnti = reestablish_rnti;
-//
-//  LTE_eNB_ULSCH_t *ulsch = NULL;
-//  nfapi_ul_config_request_body_t *ul_req_tmp = NULL;
-//  PHY_VARS_eNB *eNB_PHY = NULL;
-//  eNB_MAC_INST *eNB_MAC = RC.mac[ctxt_prior.module_id];
-//  for (int CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
-//    eNB_PHY = RC.eNB[ctxt_prior.module_id][CC_id];
-//    for (int i=0; i<MAX_MOBILES_PER_ENB; i++) {
-//      ulsch = eNB_PHY->ulsch[i];
-//      if((ulsch != NULL) && (ulsch->rnti == ctxt_prior.rnti)){
-//        void clean_eNb_ulsch(LTE_eNB_ULSCH_t *ulsch);
-//        LOG_I(RRC, "clean_eNb_ulsch UE %x \n", ctxt_prior.rnti);
-//        clean_eNb_ulsch(ulsch);
-//        break;
-//      }
-//    }
-//
-//    for(int j = 0; j < 10; j++){
-//      ul_req_tmp = &eNB_MAC->UL_req_tmp[CC_id][j].ul_config_request_body;
-//      if(ul_req_tmp){
-//        int pdu_number = ul_req_tmp->number_of_pdus;
-//        for(int pdu_index = pdu_number-1; pdu_index >= 0; pdu_index--){
-//          if(ul_req_tmp->ul_config_pdu_list[pdu_index].ulsch_pdu.ulsch_pdu_rel8.rnti == ctxt_prior.rnti){
-//            LOG_I(RRC, "remove UE %x from ul_config_pdu_list %d/%d\n", ctxt_prior.rnti, pdu_index, pdu_number);
-//            if(pdu_index < pdu_number -1){
-//               memcpy(&ul_req_tmp->ul_config_pdu_list[pdu_index], &ul_req_tmp->ul_config_pdu_list[pdu_index+1], (pdu_number-1-pdu_index) * sizeof(nfapi_ul_config_request_pdu_t));
-//            }
-//            ul_req_tmp->number_of_pdus--;
-//          }
-//        }
-//      }
-//    }
-//  }
-//  rrc_mac_remove_ue(ctxt_prior.module_id, ctxt_prior.rnti);
-//  rrc_rlc_remove_ue(&ctxt_prior);
-//  pdcp_remove_UE(&ctxt_prior);
+  //  protocol_ctxt_t ctxt_prior = *ctxt_pP;
+  //  ctxt_prior.rnti = reestablish_rnti;
+  //
+  //  LTE_eNB_ULSCH_t *ulsch = NULL;
+  //  nfapi_ul_config_request_body_t *ul_req_tmp = NULL;
+  //  PHY_VARS_eNB *eNB_PHY = NULL;
+  //  eNB_MAC_INST *eNB_MAC = RC.mac[ctxt_prior.module_id];
+  //  for (int CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
+  //    eNB_PHY = RC.eNB[ctxt_prior.module_id][CC_id];
+  //    for (int i=0; i<MAX_MOBILES_PER_ENB; i++) {
+  //      ulsch = eNB_PHY->ulsch[i];
+  //      if((ulsch != NULL) && (ulsch->rnti == ctxt_prior.rnti)){
+  //        void clean_eNb_ulsch(LTE_eNB_ULSCH_t *ulsch);
+  //        LOG_I(RRC, "clean_eNb_ulsch UE %x \n", ctxt_prior.rnti);
+  //        clean_eNb_ulsch(ulsch);
+  //        break;
+  //      }
+  //    }
+  //
+  //    for(int j = 0; j < 10; j++){
+  //      ul_req_tmp = &eNB_MAC->UL_req_tmp[CC_id][j].ul_config_request_body;
+  //      if(ul_req_tmp){
+  //        int pdu_number = ul_req_tmp->number_of_pdus;
+  //        for(int pdu_index = pdu_number-1; pdu_index >= 0; pdu_index--){
+  //          if(ul_req_tmp->ul_config_pdu_list[pdu_index].ulsch_pdu.ulsch_pdu_rel8.rnti == ctxt_prior.rnti){
+  //            LOG_I(RRC, "remove UE %x from ul_config_pdu_list %d/%d\n", ctxt_prior.rnti, pdu_index, pdu_number);
+  //            if(pdu_index < pdu_number -1){
+  //               memcpy(&ul_req_tmp->ul_config_pdu_list[pdu_index], &ul_req_tmp->ul_config_pdu_list[pdu_index+1], (pdu_number-1-pdu_index) * sizeof(nfapi_ul_config_request_pdu_t));
+  //            }
+  //            ul_req_tmp->number_of_pdus--;
+  //          }
+  //        }
+  //      }
+  //    }
+  //  }
+  //  rrc_mac_remove_ue(ctxt_prior.module_id, ctxt_prior.rnti);
+  //  rrc_rlc_remove_ue(&ctxt_prior);
+  //  pdcp_remove_UE(&ctxt_prior);
   // add UE info to freeList for RU_thread to remove the UE instead of remove it here
   LOG_I(RRC, "[RRCConnectionReestablishment]put UE %x into freeList\n", reestablish_rnti);
   put_UE_in_freelist(ctxt_pP->module_id, reestablish_rnti, 0);
@@ -2074,8 +2000,8 @@ rrc_eNB_process_RRCConnectionReestablishmentComplete(
 //-----------------------------------------------------------------------------
 void
 rrc_eNB_generate_RRCConnectionReestablishmentReject(
-  const protocol_ctxt_t* const ctxt_pP,
-  rrc_eNB_ue_context_t*          const ue_context_pP,
+  const protocol_ctxt_t *const ctxt_pP,
+  rrc_eNB_ue_context_t          *const ue_context_pP,
   const int                    CC_id
 )
 //-----------------------------------------------------------------------------
@@ -2084,13 +2010,14 @@ rrc_eNB_generate_RRCConnectionReestablishmentReject(
        (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_ng_eNB_CU)&& 
        (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_CU)   ) {
   int UE_id = find_UE_id(ctxt_pP->module_id, ctxt_pP->rnti);
-  if(UE_id != -1){
+
+  if(UE_id != -1) {
     RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].ue_reestablishment_reject_timer = 1;
     RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].ue_reestablishment_reject_timer_thres = 20;
-  }else{
+  } else {
     LOG_E(RRC,
-            PROTOCOL_RRC_CTXT_UE_FMT" Generating RRCConnectionReestablishmentReject without UE_id(MAC) rnti %x\n",
-            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ctxt_pP->rnti);
+          PROTOCOL_RRC_CTXT_UE_FMT" Generating LTE_RRCConnectionReestablishmentReject without UE_id(MAC) rnti %x\n",
+          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ctxt_pP->rnti);
   }
  }
   T(T_ENB_RRC_CONNECTION_REESTABLISHMENT_REJECT, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
@@ -2106,90 +2033,85 @@ rrc_eNB_generate_RRCConnectionReestablishmentReject(
               (char *)(ue_p->Srb0.Tx_buffer.Payload),
               ue_p->Srb0.Tx_buffer.payload_size,
               "[MSG] RRCConnectionReestablishmentReject\n");
-
-
   MSC_LOG_TX_MESSAGE(
     MSC_RRC_ENB,
     MSC_RRC_UE,
     ue_p->Srb0.Tx_buffer.Header,
     ue_p->Srb0.Tx_buffer.payload_size,
-    MSC_AS_TIME_FMT" RRCConnectionReestablishmentReject UE %x size %u",
+    MSC_AS_TIME_FMT" LTE_RRCConnectionReestablishmentReject UE %x size %u",
     MSC_AS_TIME_ARGS(ctxt_pP),
     ue_context_pP == NULL ? -1 : ue_context_pP->ue_context.rnti,
     ue_p->Srb0.Tx_buffer.payload_size);
 
   LOG_I(RRC,
-        PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel DL-CCCH, Generating RRCConnectionReestablishmentReject (bytes %d)\n",
+        PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel DL-CCCH, Generating LTE_RRCConnectionReestablishmentReject (bytes %d)\n",
         PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
         ue_p->Srb0.Tx_buffer.payload_size);
 }
 
 //-----------------------------------------------------------------------------
+/*
+* Generate the RRC Connection Release to UE.
+* If received, UE should switch to RRC_IDLE mode.
+*/
 void
 rrc_eNB_generate_RRCConnectionRelease(
-  const protocol_ctxt_t* const ctxt_pP,
-  rrc_eNB_ue_context_t*          const ue_context_pP
+  const protocol_ctxt_t *const ctxt_pP,
+  rrc_eNB_ue_context_t *const ue_context_pP
 )
 //-----------------------------------------------------------------------------
 {
-
-  uint8_t                             buffer[RRC_BUF_SIZE];
-  uint16_t                            size;
-
+  uint8_t buffer[RRC_BUF_SIZE];
+  uint16_t size = 0;
+  memset(buffer, 0, RRC_BUF_SIZE);
   T(T_ENB_RRC_CONNECTION_RELEASE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
     T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
-
-  memset(buffer, 0, RRC_BUF_SIZE);
   size = do_RRCConnectionRelease(ctxt_pP->module_id, buffer,rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id));
-  // set release timer
-  //ue_context_pP->ue_context.ue_release_timer=1;
-  // remove UE after 10 frames after RRCConnectionRelease is triggered
-  //ue_context_pP->ue_context.ue_release_timer_thres=100;
-    // set release timer
-//  ue_context_pP->ue_context.ue_release_timer_rrc = 1;
-  // remove UE after 10 frames after RRCConnectionRelease is triggered
-//  ue_context_pP->ue_context.ue_release_timer_thres_rrc = 100;
   ue_context_pP->ue_context.ue_reestablishment_timer = 0;
   ue_context_pP->ue_context.ue_release_timer = 0;
-  //ue_context_pP->ue_context.ue_release_timer_s1 = 0;
+  ue_context_pP->ue_context.ue_rrc_inactivity_timer = 0;
   LOG_I(RRC,
         PROTOCOL_RRC_CTXT_UE_FMT" Logical Channel DL-DCCH, Generate RRCConnectionRelease (bytes %d)\n",
         PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
         size);
-
   LOG_D(RRC,
         PROTOCOL_RRC_CTXT_UE_FMT" --- PDCP_DATA_REQ/%d Bytes (rrcConnectionRelease MUI %d) --->[PDCP][RB %u]\n",
         PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
         size,
         rrc_eNB_mui,
         DCCH);
-
   MSC_LOG_TX_MESSAGE(
     MSC_RRC_ENB,
     MSC_RRC_UE,
     buffer,
     size,
-    MSC_AS_TIME_FMT" rrcConnectionRelease UE %x MUI %d size %u",
+    MSC_AS_TIME_FMT" LTE_RRCConnectionRelease UE %x MUI %d size %u",
     MSC_AS_TIME_ARGS(ctxt_pP),
     ue_context_pP->ue_context.rnti,
     rrc_eNB_mui,
     size);
   pthread_mutex_lock(&rrc_release_freelist);
-  for(uint16_t release_num = 0;release_num < NUMBER_OF_UE_MAX;release_num++){
-    if(rrc_release_info.RRC_release_ctrl[release_num].flag == 0){
-      if(ue_context_pP->ue_context.ue_release_timer_s1 > 0){
+
+  for (uint16_t release_num = 0; release_num < NUMBER_OF_UE_MAX; release_num++) {
+    if (rrc_release_info.RRC_release_ctrl[release_num].flag == 0) {
+      if (ue_context_pP->ue_context.ue_release_timer_s1 > 0) {
         rrc_release_info.RRC_release_ctrl[release_num].flag = 1;
-      }else{
+      } else {
         rrc_release_info.RRC_release_ctrl[release_num].flag = 2;
       }
+
       rrc_release_info.RRC_release_ctrl[release_num].rnti = ctxt_pP->rnti;
       rrc_release_info.RRC_release_ctrl[release_num].rrc_eNB_mui = rrc_eNB_mui;
       rrc_release_info.num_UEs++;
-      LOG_D(RRC,"Generate DLSCH Release send: index %d rnti %x mui %d flag %d \n",release_num,
-             ctxt_pP->rnti, rrc_eNB_mui,rrc_release_info.RRC_release_ctrl[release_num].flag);
+      LOG_D(RRC, "Generate DLSCH Release send: index %d rnti %x mui %d flag %d \n",
+            release_num,
+            ctxt_pP->rnti,
+            rrc_eNB_mui,
+            rrc_release_info.RRC_release_ctrl[release_num].flag);
       break;
     }
   }
+
   pthread_mutex_unlock(&rrc_release_freelist);
   if (RC.rrc[ctxt_pP->module_id]->node_type == ngran_eNB_CU
       || RC.rrc[ctxt_pP->module_id]->node_type == ngran_ng_eNB_CU) {
@@ -2211,210 +2133,191 @@ rrc_eNB_generate_RRCConnectionRelease(
   }
 }
 
-uint8_t qci_to_priority[9]={2,4,3,5,1,6,7,8,9};
+uint8_t qci_to_priority[9]= {2,4,3,5,1,6,7,8,9};
 
 // TBD: this directive can be remived if we create a similar e_rab_param_t structure in RRC context
-#if defined(ENABLE_ITTI) 
+#if defined(ENABLE_ITTI)
 //-----------------------------------------------------------------------------
 void
-rrc_eNB_generate_dedicatedRRCConnectionReconfiguration(const protocol_ctxt_t* const ctxt_pP,
-						     rrc_eNB_ue_context_t*          const ue_context_pP,
-						     const uint8_t                ho_state
-						     )
+rrc_eNB_generate_dedicatedRRCConnectionReconfiguration(const protocol_ctxt_t *const ctxt_pP,
+    rrc_eNB_ue_context_t          *const ue_context_pP,
+    const uint8_t                ho_state
+                                                      )
 //-----------------------------------------------------------------------------
 {
-  
   uint8_t                             buffer[RRC_BUF_SIZE];
   uint16_t                            size;
   int i;
-  
-  struct DRB_ToAddMod                *DRB_config                       = NULL;
-  struct RLC_Config                  *DRB_rlc_config                   = NULL;
-  struct PDCP_Config                 *DRB_pdcp_config                  = NULL;
-  struct PDCP_Config__rlc_AM         *PDCP_rlc_AM                      = NULL;
-  struct PDCP_Config__rlc_UM         *PDCP_rlc_UM                      = NULL;
-  struct LogicalChannelConfig        *DRB_lchan_config                 = NULL;
-  struct LogicalChannelConfig__ul_SpecificParameters
+  struct LTE_DRB_ToAddMod                *DRB_config                       = NULL;
+  struct LTE_RLC_Config                  *DRB_rlc_config                   = NULL;
+  struct LTE_PDCP_Config                 *DRB_pdcp_config                  = NULL;
+  struct LTE_PDCP_Config__rlc_AM         *PDCP_rlc_AM                      = NULL;
+  struct LTE_PDCP_Config__rlc_UM         *PDCP_rlc_UM                      = NULL;
+  struct LTE_LogicalChannelConfig        *DRB_lchan_config                 = NULL;
+  struct LTE_LogicalChannelConfig__ul_SpecificParameters
     *DRB_ul_SpecificParameters        = NULL;
-  //  DRB_ToAddModList_t**                DRB_configList=&ue_context_pP->ue_context.DRB_configList; 
-  DRB_ToAddModList_t*                DRB_configList=ue_context_pP->ue_context.DRB_configList; 
-  DRB_ToAddModList_t**                DRB_configList2=NULL;
+  //  LTE_DRB_ToAddModList_t**                DRB_configList=&ue_context_pP->ue_context.DRB_configList;
+  LTE_DRB_ToAddModList_t                *DRB_configList=ue_context_pP->ue_context.DRB_configList;
+  LTE_DRB_ToAddModList_t                **DRB_configList2=NULL;
   //DRB_ToAddModList_t**                RRC_DRB_configList=&ue_context_pP->ue_context.DRB_configList;
-
-  struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
-  DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
+  struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
+  LTE_DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
   /* for no gcc warnings */
   (void)dedicatedInfoNas;
-
   long  *logicalchannelgroup_drb;
-//  int drb_identity_index=0;
-
+  //  int drb_identity_index=0;
   uint8_t xid = rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id);   //Transaction_id,
   DRB_configList2=&ue_context_pP->ue_context.DRB_configList2[xid];
+
   if (*DRB_configList2) {
     free(*DRB_configList2);
   }
+
   //*DRB_configList = CALLOC(1, sizeof(*DRB_configList));
-  *DRB_configList2 = CALLOC(1, sizeof(**DRB_configList2)); 
+  *DRB_configList2 = CALLOC(1, sizeof(**DRB_configList2));
   /* Initialize NAS list */
-  dedicatedInfoNASList = CALLOC(1, sizeof(struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));
-
+  dedicatedInfoNASList = CALLOC(1, sizeof(struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));
   int e_rab_done=0;
-  
-  for ( i = 0  ;
-	i < ue_context_pP->ue_context.setup_e_rabs ;
-	i++){
 
-    if (e_rab_done >= ue_context_pP->ue_context.nb_of_e_rabs){
-        break;
+  for ( i = 0  ;
+        i < ue_context_pP->ue_context.setup_e_rabs ;
+        i++) {
+    if (e_rab_done >= ue_context_pP->ue_context.nb_of_e_rabs) {
+      break;
     }
-    
+
     // bypass the new and already configured erabs
     if (ue_context_pP->ue_context.e_rab[i].status >= E_RAB_STATUS_DONE) {
-//      drb_identity_index++;
+      //      drb_identity_index++;
       continue;
     }
-        
-    DRB_config = CALLOC(1, sizeof(*DRB_config));
 
+    DRB_config = CALLOC(1, sizeof(*DRB_config));
     DRB_config->eps_BearerIdentity = CALLOC(1, sizeof(long));
     // allowed value 5..15, value : x+4
-    *(DRB_config->eps_BearerIdentity) = ue_context_pP->ue_context.e_rab[i].param.e_rab_id;//+ 4; // especial case generation  
-
- //   DRB_config->drb_Identity =  1 + drb_identity_index + e_rab_done;// + i ;// (DRB_Identity_t) ue_context_pP->ue_context.e_rab[i].param.e_rab_id;
-    // 1 + drb_identiy_index;  
+    *(DRB_config->eps_BearerIdentity) = ue_context_pP->ue_context.e_rab[i].param.e_rab_id;//+ 4; // especial case generation
+    //   DRB_config->drb_Identity =  1 + drb_identity_index + e_rab_done;// + i ;// (LTE_DRB_Identity_t) ue_context_pP->ue_context.e_rab[i].param.e_rab_id;
+    // 1 + drb_identiy_index;
     DRB_config->drb_Identity = i+1;
-
     DRB_config->logicalChannelIdentity = CALLOC(1, sizeof(long));
     *(DRB_config->logicalChannelIdentity) = DRB_config->drb_Identity + 2; //(long) (ue_context_pP->ue_context.e_rab[i].param.e_rab_id + 2); // value : x+2
-    
     DRB_rlc_config = CALLOC(1, sizeof(*DRB_rlc_config));
     DRB_config->rlc_Config = DRB_rlc_config;
-
     DRB_pdcp_config = CALLOC(1, sizeof(*DRB_pdcp_config));
     DRB_config->pdcp_Config = DRB_pdcp_config;
     DRB_pdcp_config->discardTimer = CALLOC(1, sizeof(long));
-    *DRB_pdcp_config->discardTimer = PDCP_Config__discardTimer_infinity;
+    *DRB_pdcp_config->discardTimer = LTE_PDCP_Config__discardTimer_infinity;
     DRB_pdcp_config->rlc_AM = NULL;
     DRB_pdcp_config->rlc_UM = NULL;
 
-
-    switch (ue_context_pP->ue_context.e_rab[i].param.qos.qci){
+    switch (ue_context_pP->ue_context.e_rab[i].param.qos.qci) {
       /*
        * type: realtime data with medium packer error rate
        * action: swtich to RLC UM
        */
-    case 1: // 100ms, 10^-2, p2, GBR
-    case 2: // 150ms, 10^-3, p4, GBR
-    case 3: // 50ms, 10^-3, p3, GBR
-    case 4:  // 300ms, 10^-6, p5 
-    case 7: // 100ms, 10^-3, p7, GBR
-    case 9: // 300ms, 10^-6, p9
-    case 65: // 75ms, 10^-2, p0.7, mission critical voice, GBR
-    case 66: // 100ms, 10^-2, p2, non-mission critical  voice , GBR
-      // RLC 
-      DRB_rlc_config->present = RLC_Config_PR_um_Bi_Directional;
-      DRB_rlc_config->choice.um_Bi_Directional.ul_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
-      DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
-      DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = T_Reordering_ms35;
-      // PDCP
-      PDCP_rlc_UM = CALLOC(1, sizeof(*PDCP_rlc_UM));
-      DRB_pdcp_config->rlc_UM = PDCP_rlc_UM;
-      PDCP_rlc_UM->pdcp_SN_Size = PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits;
-      break;
-      
+      case 1: // 100ms, 10^-2, p2, GBR
+      case 2: // 150ms, 10^-3, p4, GBR
+      case 3: // 50ms, 10^-3, p3, GBR
+      case 4:  // 300ms, 10^-6, p5
+      case 7: // 100ms, 10^-3, p7, GBR
+      case 9: // 300ms, 10^-6, p9
+      case 65: // 75ms, 10^-2, p0.7, mission critical voice, GBR
+      case 66: // 100ms, 10^-2, p2, non-mission critical  voice , GBR
+        // RLC
+        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;
+        // PDCP
+        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;
+        break;
+
       /*
        * type: non-realtime data with low packer error rate
        * action: swtich to RLC AM
        */
-    case 5:  // 100ms, 10^-6, p1 , IMS signaling 
-    case 6:  // 300ms, 10^-6, p6 
-    case 8: // 300ms, 10^-6, p8 
-    case 69: // 60ms, 10^-6, p0.5, mission critical delay sensitive data, Lowest Priority 
-    case 70: // 200ms, 10^-6, p5.5, mision critical data 
-      // RLC
-       DRB_rlc_config->present = RLC_Config_PR_am;
-       DRB_rlc_config->choice.am.ul_AM_RLC.t_PollRetransmit = T_PollRetransmit_ms50;
-       DRB_rlc_config->choice.am.ul_AM_RLC.pollPDU = PollPDU_p16;
-       DRB_rlc_config->choice.am.ul_AM_RLC.pollByte = PollByte_kBinfinity;
-       DRB_rlc_config->choice.am.ul_AM_RLC.maxRetxThreshold = UL_AM_RLC__maxRetxThreshold_t8;
-       DRB_rlc_config->choice.am.dl_AM_RLC.t_Reordering = T_Reordering_ms35;
-       DRB_rlc_config->choice.am.dl_AM_RLC.t_StatusProhibit = T_StatusProhibit_ms25;
-
-       // PDCP
-       PDCP_rlc_AM = CALLOC(1, sizeof(*PDCP_rlc_AM));
-       DRB_pdcp_config->rlc_AM = PDCP_rlc_AM;
-       PDCP_rlc_AM->statusReportRequired = FALSE;
-       
-       break;
-    default :
-      LOG_E(RRC,"not supported qci %d\n", ue_context_pP->ue_context.e_rab[i].param.qos.qci);
-      ue_context_pP->ue_context.e_rab[i].status = E_RAB_STATUS_FAILED; 
-      ue_context_pP->ue_context.e_rab[i].xid = xid;
-      e_rab_done++;
-      continue;
+      case 5:  // 100ms, 10^-6, p1 , IMS signaling
+      case 6:  // 300ms, 10^-6, p6
+      case 8: // 300ms, 10^-6, p8
+      case 69: // 60ms, 10^-6, p0.5, mission critical delay sensitive data, Lowest Priority
+      case 70: // 200ms, 10^-6, p5.5, mision critical data
+        // RLC
+        DRB_rlc_config->present = LTE_RLC_Config_PR_am;
+        DRB_rlc_config->choice.am.ul_AM_RLC.t_PollRetransmit = LTE_T_PollRetransmit_ms50;
+        DRB_rlc_config->choice.am.ul_AM_RLC.pollPDU = LTE_PollPDU_p16;
+        DRB_rlc_config->choice.am.ul_AM_RLC.pollByte = LTE_PollByte_kBinfinity;
+        DRB_rlc_config->choice.am.ul_AM_RLC.maxRetxThreshold = LTE_UL_AM_RLC__maxRetxThreshold_t8;
+        DRB_rlc_config->choice.am.dl_AM_RLC.t_Reordering = LTE_T_Reordering_ms35;
+        DRB_rlc_config->choice.am.dl_AM_RLC.t_StatusProhibit = LTE_T_StatusProhibit_ms25;
+        // PDCP
+        PDCP_rlc_AM = CALLOC(1, sizeof(*PDCP_rlc_AM));
+        DRB_pdcp_config->rlc_AM = PDCP_rlc_AM;
+        PDCP_rlc_AM->statusReportRequired = FALSE;
+        break;
+
+      default :
+        LOG_E(RRC,"not supported qci %d\n", ue_context_pP->ue_context.e_rab[i].param.qos.qci);
+        ue_context_pP->ue_context.e_rab[i].status = E_RAB_STATUS_FAILED;
+        ue_context_pP->ue_context.e_rab[i].xid = xid;
+        e_rab_done++;
+        continue;
     }
 
-    DRB_pdcp_config->headerCompression.present = PDCP_Config__headerCompression_PR_notUsed;
-    
+    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;
 
     if (ue_context_pP->ue_context.e_rab[i].param.qos.qci < 9 )
-      DRB_ul_SpecificParameters->priority = qci_to_priority[ue_context_pP->ue_context.e_rab[i].param.qos.qci-1] + 3; 
+      DRB_ul_SpecificParameters->priority = qci_to_priority[ue_context_pP->ue_context.e_rab[i].param.qos.qci-1] + 3;
     // ue_context_pP->ue_context.e_rab[i].param.qos.allocation_retention_priority.priority_level;
-    else 
+    else
       DRB_ul_SpecificParameters->priority= 4;
 
-    DRB_ul_SpecificParameters->prioritisedBitRate = LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_kBps8;
-      //LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
+    DRB_ul_SpecificParameters->prioritisedBitRate = LTE_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_kBps8;
+    //LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
     DRB_ul_SpecificParameters->bucketSizeDuration =
-      LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
-    
+      LTE_LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
     logicalchannelgroup_drb = CALLOC(1, sizeof(long));
     *logicalchannelgroup_drb = 1;//(i+1) % 3;
     DRB_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup_drb;
-
     ASN_SEQUENCE_ADD(&DRB_configList->list, DRB_config);
     ASN_SEQUENCE_ADD(&(*DRB_configList2)->list, DRB_config);
     //ue_context_pP->ue_context.DRB_configList2[drb_identity_index] = &(*DRB_configList);
-    
     LOG_I(RRC,"EPS ID %ld, DRB ID %ld (index %d), QCI %d, priority %ld, LCID %ld LCGID %ld \n",
-	  *DRB_config->eps_BearerIdentity,
-	  DRB_config->drb_Identity, i,
-	  ue_context_pP->ue_context.e_rab[i].param.qos.qci,
-	  DRB_ul_SpecificParameters->priority,
-	  *(DRB_config->logicalChannelIdentity),
-	  *DRB_ul_SpecificParameters->logicalChannelGroup	  
-	  );
-
+          *DRB_config->eps_BearerIdentity,
+          DRB_config->drb_Identity, i,
+          ue_context_pP->ue_context.e_rab[i].param.qos.qci,
+          DRB_ul_SpecificParameters->priority,
+          *(DRB_config->logicalChannelIdentity),
+          *DRB_ul_SpecificParameters->logicalChannelGroup
+         );
     e_rab_done++;
-    ue_context_pP->ue_context.e_rab[i].status = E_RAB_STATUS_DONE; 
+    ue_context_pP->ue_context.e_rab[i].status = E_RAB_STATUS_DONE;
     ue_context_pP->ue_context.e_rab[i].xid = xid;
-    
     {
       if (ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer != NULL) {
-	dedicatedInfoNas = CALLOC(1, sizeof(DedicatedInfoNAS_t));
-	memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t));
-	OCTET_STRING_fromBuf(dedicatedInfoNas, 
-			     (char*)ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer,
-			     ue_context_pP->ue_context.e_rab[i].param.nas_pdu.length);
-	ASN_SEQUENCE_ADD(&dedicatedInfoNASList->list, dedicatedInfoNas);
-	LOG_I(RRC,"add NAS info with size %d (rab id %d)\n",ue_context_pP->ue_context.e_rab[i].param.nas_pdu.length, i);
-      } 
-      else {
-	LOG_W(RRC,"Not received activate dedicated EPS bearer context request\n");
+        dedicatedInfoNas = CALLOC(1, sizeof(LTE_DedicatedInfoNAS_t));
+        memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t));
+        OCTET_STRING_fromBuf(dedicatedInfoNas,
+                             (char *)ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer,
+                             ue_context_pP->ue_context.e_rab[i].param.nas_pdu.length);
+        ASN_SEQUENCE_ADD(&dedicatedInfoNASList->list, dedicatedInfoNas);
+        LOG_I(RRC,"add NAS info with size %d (rab id %d)\n",ue_context_pP->ue_context.e_rab[i].param.nas_pdu.length, i);
+      } else {
+        LOG_W(RRC,"Not received activate dedicated EPS bearer context request\n");
       }
+
       /* TODO parameters yet to process ... */
       {
-	//      ue_context_pP->ue_context.e_rab[i].param.qos;
-	//      ue_context_pP->ue_context.e_rab[i].param.sgw_addr;
-	//      ue_context_pP->ue_context.e_rab[i].param.gtp_teid;
+        //      ue_context_pP->ue_context.e_rab[i].param.qos;
+        //      ue_context_pP->ue_context.e_rab[i].param.sgw_addr;
+        //      ue_context_pP->ue_context.e_rab[i].param.gtp_teid;
       }
     }
-    
   }
 
   /* If list is empty free the list and reset the address */
@@ -2423,33 +2326,29 @@ rrc_eNB_generate_dedicatedRRCConnectionReconfiguration(const protocol_ctxt_t* co
       free(dedicatedInfoNASList);
       dedicatedInfoNASList = NULL;
       LOG_W(RRC,"dedlicated NAS list is empty, free the list and reset the address\n");
-    }				
+    }
   } else {
     LOG_W(RRC,"dedlicated NAS list is empty\n");
   }
 
   memset(buffer, 0, RRC_BUF_SIZE);
-
-   size = do_RRCConnectionReconfiguration(ctxt_pP,
-					  buffer,
-					  xid,
-					  (SRB_ToAddModList_t*)NULL, 
-					  (DRB_ToAddModList_t*)*DRB_configList2,
-					  (DRB_ToReleaseList_t*)NULL,  // DRB2_list,
-                                         (struct SPS_Config*)NULL,    // *sps_Config,
-					  NULL, NULL, NULL, NULL,NULL,
-					  NULL, NULL,  NULL, NULL, NULL, NULL, 
-					  (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList*)dedicatedInfoNASList,
-					  (SL_CommConfig_r12_t*)NULL,
-					  (SL_DiscConfig_r12_t*)NULL
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-                                         , (SCellToAddMod_r10_t*)NULL
+  size = do_RRCConnectionReconfiguration(ctxt_pP,
+                                         buffer,
+                                         xid,
+                                         (LTE_SRB_ToAddModList_t *)NULL,
+                                         (LTE_DRB_ToAddModList_t *)*DRB_configList2,
+                                         (LTE_DRB_ToReleaseList_t *)NULL, // DRB2_list,
+                                         (struct LTE_SPS_Config *)NULL,   // *sps_Config,
+                                         NULL, NULL, NULL, NULL,NULL,
+                                         NULL, NULL,  NULL, NULL, NULL, NULL, NULL,
+                                         (struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *)dedicatedInfoNASList,
+                                         (LTE_SL_CommConfig_r12_t *)NULL,
+                                         (LTE_SL_DiscConfig_r12_t *)NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                                         , (LTE_SCellToAddMod_r10_t *)NULL
 #endif
                                         );
- 
   LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,size,"[MSG] RRC Connection Reconfiguration\n");
-
-
 #if defined(ENABLE_ITTI)
 
   /* Free all NAS PDUs */
@@ -2460,27 +2359,24 @@ rrc_eNB_generate_dedicatedRRCConnectionReconfiguration(const protocol_ctxt_t* co
       ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer = NULL;
     }
   }
-#endif
 
- LOG_I(RRC,
-        "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration (bytes %d, UE RNTI %x)\n",
+#endif
+  LOG_I(RRC,
+        "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate LTE_RRCConnectionReconfiguration (bytes %d, UE RNTI %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",
         ctxt_pP->frame, ctxt_pP->module_id, size, ue_context_pP->ue_context.rnti, rrc_eNB_mui, ctxt_pP->module_id, DCCH);
-
   MSC_LOG_TX_MESSAGE(
     MSC_RRC_ENB,
     MSC_RRC_UE,
     buffer,
     size,
-    MSC_AS_TIME_FMT" dedicated rrcConnectionReconfiguration UE %x MUI %d size %u",
+    MSC_AS_TIME_FMT" dedicated LTE_RRCConnectionReconfiguration UE %x MUI %d size %u",
     MSC_AS_TIME_ARGS(ctxt_pP),
     ue_context_pP->ue_context.rnti,
     rrc_eNB_mui,
     size);
-
   rrc_data_req(
     ctxt_pP,
     DCCH,
@@ -2489,40 +2385,35 @@ rrc_eNB_generate_dedicatedRRCConnectionReconfiguration(const protocol_ctxt_t* co
     size,
     buffer,
     PDCP_TRANSMISSION_MODE_CONTROL);
-
-
 }
 int
-rrc_eNB_modify_dedicatedRRCConnectionReconfiguration(const protocol_ctxt_t* const ctxt_pP,
-                             rrc_eNB_ue_context_t*          const ue_context_pP,
-                             const uint8_t                ho_state
-                             )
+rrc_eNB_modify_dedicatedRRCConnectionReconfiguration(const protocol_ctxt_t *const ctxt_pP,
+    rrc_eNB_ue_context_t          *const ue_context_pP,
+    const uint8_t                ho_state
+                                                    )
 //-----------------------------------------------------------------------------
 {
   uint8_t                             buffer[RRC_BUF_SIZE];
   uint16_t                            size;
   int i, j;
-
-  struct DRB_ToAddMod                *DRB_config                       = NULL;
-  struct RLC_Config                  *DRB_rlc_config                   = NULL;
-  struct PDCP_Config                 *DRB_pdcp_config                  = NULL;
-  struct PDCP_Config__rlc_AM         *PDCP_rlc_AM                      = NULL;
-  struct PDCP_Config__rlc_UM         *PDCP_rlc_UM                      = NULL;
-  struct LogicalChannelConfig        *DRB_lchan_config                 = NULL;
-  struct LogicalChannelConfig__ul_SpecificParameters
-  *DRB_ul_SpecificParameters        = NULL;
-  DRB_ToAddModList_t*                 DRB_configList = ue_context_pP->ue_context.DRB_configList;
-  DRB_ToAddModList_t*                DRB_configList2 = NULL;
-
-  struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
-  DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
+  struct LTE_DRB_ToAddMod                *DRB_config                       = NULL;
+  struct LTE_RLC_Config                  *DRB_rlc_config                   = NULL;
+  struct LTE_PDCP_Config                 *DRB_pdcp_config                  = NULL;
+  struct LTE_PDCP_Config__rlc_AM         *PDCP_rlc_AM                      = NULL;
+  struct LTE_PDCP_Config__rlc_UM         *PDCP_rlc_UM                      = NULL;
+  struct LTE_LogicalChannelConfig        *DRB_lchan_config                 = NULL;
+  struct LTE_LogicalChannelConfig__ul_SpecificParameters
+    *DRB_ul_SpecificParameters        = NULL;
+  LTE_DRB_ToAddModList_t                 *DRB_configList = ue_context_pP->ue_context.DRB_configList;
+  LTE_DRB_ToAddModList_t                *DRB_configList2 = NULL;
+  struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
+  LTE_DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
   /* for no gcc warnings */
   (void)dedicatedInfoNas;
-
   uint8_t xid = rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id);   // Transaction_id,
   DRB_configList2 = CALLOC(1, sizeof(*DRB_configList2));
   /* Initialize NAS list */
-  dedicatedInfoNASList = CALLOC(1, sizeof(struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));
+  dedicatedInfoNASList = CALLOC(1, sizeof(struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));
 
   for (i = 0; i < ue_context_pP->ue_context.nb_of_modify_e_rabs; i++) {
     // bypass the new and already configured erabs
@@ -2539,6 +2430,7 @@ rrc_eNB_modify_dedicatedRRCConnectionReconfiguration(const protocol_ctxt_t* cons
     }
 
     DRB_config = NULL;
+
     // search exist DRB_config
     for (j = 0; j < DRB_configList->list.count; j++) {
       if((uint8_t)*(DRB_configList->list.array[j]->eps_BearerIdentity) == ue_context_pP->ue_context.modify_e_rab[i].param.e_rab_id) {
@@ -2546,6 +2438,7 @@ rrc_eNB_modify_dedicatedRRCConnectionReconfiguration(const protocol_ctxt_t* cons
         break;
       }
     }
+
     if (NULL == DRB_config) {
       ue_context_pP->ue_context.modify_e_rab[i].xid = xid;
       ue_context_pP->ue_context.modify_e_rab[i].status = E_RAB_STATUS_FAILED;
@@ -2557,85 +2450,89 @@ rrc_eNB_modify_dedicatedRRCConnectionReconfiguration(const protocol_ctxt_t* cons
     }
 
     DRB_rlc_config = DRB_config->rlc_Config;
-
     DRB_pdcp_config = DRB_config->pdcp_Config;
-    *DRB_pdcp_config->discardTimer = PDCP_Config__discardTimer_infinity;
+    *DRB_pdcp_config->discardTimer = LTE_PDCP_Config__discardTimer_infinity;
+
     switch (ue_context_pP->ue_context.modify_e_rab[i].param.qos.qci) {
-    /*
-     * type: realtime data with medium packer error rate
-     * action: swtich to RLC UM
-     */
-    case 1: // 100ms, 10^-2, p2, GBR
-    case 2: // 150ms, 10^-3, p4, GBR
-    case 3: // 50ms, 10^-3, p3, GBR
-    case 4:  // 300ms, 10^-6, p5
-    case 7: // 100ms, 10^-3, p7, GBR
-    case 9: // 300ms, 10^-6, p9
-    case 65: // 75ms, 10^-2, p0.7, mission critical voice, GBR
-    case 66: // 100ms, 10^-2, p2, non-mission critical  voice , GBR
-      // RLC
-      DRB_rlc_config->present = RLC_Config_PR_um_Bi_Directional;
-      DRB_rlc_config->choice.um_Bi_Directional.ul_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
-      DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
-      DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = T_Reordering_ms35;
-      // PDCP
-      if (DRB_pdcp_config->rlc_AM) {
-        free(DRB_pdcp_config->rlc_AM);
-        DRB_pdcp_config->rlc_AM = NULL;
-      }
-      if (DRB_pdcp_config->rlc_UM) {
-        free(DRB_pdcp_config->rlc_UM);
-        DRB_pdcp_config->rlc_UM = NULL;
-      }
-      PDCP_rlc_UM = CALLOC(1, sizeof(*PDCP_rlc_UM));
-      DRB_pdcp_config->rlc_UM = PDCP_rlc_UM;
-      PDCP_rlc_UM->pdcp_SN_Size = PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits;
-      break;
+      /*
+       * type: realtime data with medium packer error rate
+       * action: swtich to RLC UM
+       */
+      case 1: // 100ms, 10^-2, p2, GBR
+      case 2: // 150ms, 10^-3, p4, GBR
+      case 3: // 50ms, 10^-3, p3, GBR
+      case 4:  // 300ms, 10^-6, p5
+      case 7: // 100ms, 10^-3, p7, GBR
+      case 9: // 300ms, 10^-6, p9
+      case 65: // 75ms, 10^-2, p0.7, mission critical voice, GBR
+      case 66: // 100ms, 10^-2, p2, non-mission critical  voice , GBR
+        // RLC
+        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;
+
+        // PDCP
+        if (DRB_pdcp_config->rlc_AM) {
+          free(DRB_pdcp_config->rlc_AM);
+          DRB_pdcp_config->rlc_AM = NULL;
+        }
 
-    /*
-     * type: non-realtime data with low packer error rate
-     * action: swtich to RLC AM
-     */
-    case 5:  // 100ms, 10^-6, p1 , IMS signaling
-    case 6:  // 300ms, 10^-6, p6
-    case 8: // 300ms, 10^-6, p8
-    case 69: // 60ms, 10^-6, p0.5, mission critical delay sensitive data, Lowest Priority
-    case 70: // 200ms, 10^-6, p5.5, mision critical data
-       // RLC
-       DRB_rlc_config->present = RLC_Config_PR_am;
-       DRB_rlc_config->choice.am.ul_AM_RLC.t_PollRetransmit = T_PollRetransmit_ms50;
-       DRB_rlc_config->choice.am.ul_AM_RLC.pollPDU = PollPDU_p16;
-       DRB_rlc_config->choice.am.ul_AM_RLC.pollByte = PollByte_kBinfinity;
-       DRB_rlc_config->choice.am.ul_AM_RLC.maxRetxThreshold = UL_AM_RLC__maxRetxThreshold_t8;
-       DRB_rlc_config->choice.am.dl_AM_RLC.t_Reordering = T_Reordering_ms35;
-       DRB_rlc_config->choice.am.dl_AM_RLC.t_StatusProhibit = T_StatusProhibit_ms25;
-
-       // PDCP
-       if (DRB_pdcp_config->rlc_AM) {
-         free(DRB_pdcp_config->rlc_AM);
-         DRB_pdcp_config->rlc_AM = NULL;
-       }
-       if (DRB_pdcp_config->rlc_UM) {
-         free(DRB_pdcp_config->rlc_UM);
-         DRB_pdcp_config->rlc_UM = NULL;
-       }
-       PDCP_rlc_AM = CALLOC(1, sizeof(*PDCP_rlc_AM));
-       DRB_pdcp_config->rlc_AM = PDCP_rlc_AM;
-       PDCP_rlc_AM->statusReportRequired = FALSE;
-
-       break;
-    default :
-      LOG_E(RRC, "not supported qci %d\n", ue_context_pP->ue_context.modify_e_rab[i].param.qos.qci);
-      ue_context_pP->ue_context.modify_e_rab[i].status = E_RAB_STATUS_FAILED;
-      ue_context_pP->ue_context.modify_e_rab[i].xid = xid;
-      ue_context_pP->ue_context.modify_e_rab[i].cause = S1AP_CAUSE_RADIO_NETWORK;
-      ue_context_pP->ue_context.modify_e_rab[i].cause_value = 37;//S1ap_CauseRadioNetwork_not_supported_QCI_value;
-      ue_context_pP->ue_context.nb_of_failed_e_rabs++;
-      continue;
-    }
+        if (DRB_pdcp_config->rlc_UM) {
+          free(DRB_pdcp_config->rlc_UM);
+          DRB_pdcp_config->rlc_UM = 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;
+        break;
+
+      /*
+       * type: non-realtime data with low packer error rate
+       * action: swtich to RLC AM
+       */
+      case 5:  // 100ms, 10^-6, p1 , IMS signaling
+      case 6:  // 300ms, 10^-6, p6
+      case 8: // 300ms, 10^-6, p8
+      case 69: // 60ms, 10^-6, p0.5, mission critical delay sensitive data, Lowest Priority
+      case 70: // 200ms, 10^-6, p5.5, mision critical data
+        // RLC
+        DRB_rlc_config->present = LTE_RLC_Config_PR_am;
+        DRB_rlc_config->choice.am.ul_AM_RLC.t_PollRetransmit = LTE_T_PollRetransmit_ms50;
+        DRB_rlc_config->choice.am.ul_AM_RLC.pollPDU = LTE_PollPDU_p16;
+        DRB_rlc_config->choice.am.ul_AM_RLC.pollByte = LTE_PollByte_kBinfinity;
+        DRB_rlc_config->choice.am.ul_AM_RLC.maxRetxThreshold = LTE_UL_AM_RLC__maxRetxThreshold_t8;
+        DRB_rlc_config->choice.am.dl_AM_RLC.t_Reordering = LTE_T_Reordering_ms35;
+        DRB_rlc_config->choice.am.dl_AM_RLC.t_StatusProhibit = LTE_T_StatusProhibit_ms25;
+
+        // PDCP
+        if (DRB_pdcp_config->rlc_AM) {
+          free(DRB_pdcp_config->rlc_AM);
+          DRB_pdcp_config->rlc_AM = NULL;
+        }
+
+        if (DRB_pdcp_config->rlc_UM) {
+          free(DRB_pdcp_config->rlc_UM);
+          DRB_pdcp_config->rlc_UM = NULL;
+        }
+
+        PDCP_rlc_AM = CALLOC(1, sizeof(*PDCP_rlc_AM));
+        DRB_pdcp_config->rlc_AM = PDCP_rlc_AM;
+        PDCP_rlc_AM->statusReportRequired = FALSE;
+        break;
 
-    DRB_pdcp_config->headerCompression.present = PDCP_Config__headerCompression_PR_notUsed;
+      default :
+        LOG_E(RRC, "not supported qci %d\n", ue_context_pP->ue_context.modify_e_rab[i].param.qos.qci);
+        ue_context_pP->ue_context.modify_e_rab[i].status = E_RAB_STATUS_FAILED;
+        ue_context_pP->ue_context.modify_e_rab[i].xid = xid;
+        ue_context_pP->ue_context.modify_e_rab[i].cause = S1AP_CAUSE_RADIO_NETWORK;
+        ue_context_pP->ue_context.modify_e_rab[i].cause_value = 37;//S1ap_CauseRadioNetwork_not_supported_QCI_value;
+        ue_context_pP->ue_context.nb_of_failed_e_rabs++;
+        continue;
+    }
 
+    DRB_pdcp_config->headerCompression.present = LTE_PDCP_Config__headerCompression_PR_notUsed;
     DRB_lchan_config = DRB_config->logicalChannelConfig;
     DRB_ul_SpecificParameters = DRB_lchan_config->ul_SpecificParameters;
 
@@ -2644,37 +2541,31 @@ rrc_eNB_modify_dedicatedRRCConnectionReconfiguration(const protocol_ctxt_t* cons
     else
       DRB_ul_SpecificParameters->priority= 4;
 
-    DRB_ul_SpecificParameters->prioritisedBitRate = LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_kBps8;
-
+    DRB_ul_SpecificParameters->prioritisedBitRate = LTE_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_kBps8;
     DRB_ul_SpecificParameters->bucketSizeDuration =
-      LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
-
+      LTE_LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
     ASN_SEQUENCE_ADD(&(DRB_configList2)->list, DRB_config);
-
     LOG_I(RRC, "EPS ID %ld, DRB ID %ld (index %d), QCI %d, priority %ld, LCID %ld LCGID %ld \n",
-      *DRB_config->eps_BearerIdentity,
-      DRB_config->drb_Identity, i,
-      ue_context_pP->ue_context.modify_e_rab[i].param.qos.qci,
-      DRB_ul_SpecificParameters->priority,
-      *(DRB_config->logicalChannelIdentity),
-      *DRB_ul_SpecificParameters->logicalChannelGroup
-      );
-
+          *DRB_config->eps_BearerIdentity,
+          DRB_config->drb_Identity, i,
+          ue_context_pP->ue_context.modify_e_rab[i].param.qos.qci,
+          DRB_ul_SpecificParameters->priority,
+          *(DRB_config->logicalChannelIdentity),
+          *DRB_ul_SpecificParameters->logicalChannelGroup
+         );
     //e_rab_done++;
     ue_context_pP->ue_context.modify_e_rab[i].status = E_RAB_STATUS_DONE;
     ue_context_pP->ue_context.modify_e_rab[i].xid = xid;
-
     {
       if (ue_context_pP->ue_context.modify_e_rab[i].param.nas_pdu.buffer != NULL) {
-        dedicatedInfoNas = CALLOC(1, sizeof(DedicatedInfoNAS_t));
+        dedicatedInfoNas = CALLOC(1, sizeof(LTE_DedicatedInfoNAS_t));
         memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t));
         OCTET_STRING_fromBuf(dedicatedInfoNas,
-                 (char*)ue_context_pP->ue_context.modify_e_rab[i].param.nas_pdu.buffer,
-                 ue_context_pP->ue_context.modify_e_rab[i].param.nas_pdu.length);
+                             (char *)ue_context_pP->ue_context.modify_e_rab[i].param.nas_pdu.buffer,
+                             ue_context_pP->ue_context.modify_e_rab[i].param.nas_pdu.length);
         ASN_SEQUENCE_ADD(&dedicatedInfoNASList->list, dedicatedInfoNas);
         LOG_I(RRC, "add NAS info with size %d (rab id %d)\n",ue_context_pP->ue_context.modify_e_rab[i].param.nas_pdu.length, i);
-      }
-      else {
+      } else {
         LOG_W(RRC, "Not received activate dedicated EPS bearer context request\n");
       }
     }
@@ -2692,27 +2583,24 @@ rrc_eNB_modify_dedicatedRRCConnectionReconfiguration(const protocol_ctxt_t* cons
   }
 
   memset(buffer, 0, RRC_BUF_SIZE);
-
-   size = do_RRCConnectionReconfiguration(ctxt_pP,
-					  buffer,
-					  xid,
-					  (SRB_ToAddModList_t*)NULL, 
-					  (DRB_ToAddModList_t*)DRB_configList2,
-					  (DRB_ToReleaseList_t*)NULL,  // DRB2_list,
-                                         (struct SPS_Config*)NULL,    // *sps_Config,
-					  NULL, NULL, NULL, NULL,NULL,
-					  NULL, NULL,  NULL, NULL, NULL, NULL, 
-					  (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList*)dedicatedInfoNASList,
-					  (SL_CommConfig_r12_t*)NULL,
-					  (SL_DiscConfig_r12_t*)NULL
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-					  , (SCellToAddMod_r10_t*)NULL
-#endif
-   	   	   	   	   	  );
-
+  size = do_RRCConnectionReconfiguration(ctxt_pP,
+                                         buffer,
+                                         xid,
+                                         (LTE_SRB_ToAddModList_t *)NULL,
+                                         (LTE_DRB_ToAddModList_t *)DRB_configList2,
+                                         (LTE_DRB_ToReleaseList_t *)NULL, // DRB2_list,
+                                         (struct LTE_SPS_Config *)NULL,   // *sps_Config,
+                                         NULL, NULL, NULL, NULL,NULL,
+                                         NULL, NULL,  NULL, NULL, NULL, NULL, NULL,
+                                         (struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *)dedicatedInfoNASList,
+                                         (LTE_SL_CommConfig_r12_t *)NULL,
+                                         (LTE_SL_DiscConfig_r12_t *)NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                                         , (LTE_SCellToAddMod_r10_t *)NULL
+#endif
+                                        );
   LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,size,
               "[MSG] RRC Connection Reconfiguration\n");
-
 #if defined(ENABLE_ITTI)
 
   /* Free all NAS PDUs */
@@ -2723,27 +2611,24 @@ rrc_eNB_modify_dedicatedRRCConnectionReconfiguration(const protocol_ctxt_t* cons
       ue_context_pP->ue_context.modify_e_rab[i].param.nas_pdu.buffer = NULL;
     }
   }
-#endif
 
- LOG_I(RRC,
-        "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration (bytes %d, UE RNTI %x)\n",
+#endif
+  LOG_I(RRC,
+        "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate LTE_RRCConnectionReconfiguration (bytes %d, UE RNTI %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",
         ctxt_pP->frame, ctxt_pP->module_id, size, ue_context_pP->ue_context.rnti, rrc_eNB_mui, ctxt_pP->module_id, DCCH);
-
   MSC_LOG_TX_MESSAGE(
     MSC_RRC_ENB,
     MSC_RRC_UE,
     buffer,
     size,
-    MSC_AS_TIME_FMT" dedicated rrcConnectionReconfiguration UE %x MUI %d size %u",
+    MSC_AS_TIME_FMT" dedicated LTE_RRCConnectionReconfiguration UE %x MUI %d size %u",
     MSC_AS_TIME_ARGS(ctxt_pP),
     ue_context_pP->ue_context.rnti,
     rrc_eNB_mui,
     size);
-
   rrc_data_req(
     ctxt_pP,
     DCCH,
@@ -2757,107 +2642,106 @@ rrc_eNB_modify_dedicatedRRCConnectionReconfiguration(const protocol_ctxt_t* cons
 
 //-----------------------------------------------------------------------------
 void
-rrc_eNB_generate_dedicatedRRCConnectionReconfiguration_release(  const protocol_ctxt_t*   const ctxt_pP,
-        rrc_eNB_ue_context_t*    const ue_context_pP,
-        uint8_t                  xid,
-        uint32_t                 nas_length,
-        uint8_t*                 nas_buffer)
+rrc_eNB_generate_dedicatedRRCConnectionReconfiguration_release(  const protocol_ctxt_t   *const ctxt_pP,
+    rrc_eNB_ue_context_t    *const ue_context_pP,
+    uint8_t                  xid,
+    uint32_t                 nas_length,
+    uint8_t                 *nas_buffer)
 //-----------------------------------------------------------------------------
 {
-    uint8_t                             buffer[RRC_BUF_SIZE];
-    int                                 i;
-    uint16_t                            size  = 0;
-    DRB_ToReleaseList_t**                DRB_Release_configList2=NULL;
-    DRB_Identity_t* DRB_release;
-    struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
-
-    DRB_Release_configList2=&ue_context_pP->ue_context.DRB_Release_configList2[xid];
-    if (*DRB_Release_configList2) {
-      free(*DRB_Release_configList2);
-    }
-    *DRB_Release_configList2 = CALLOC(1, sizeof(**DRB_Release_configList2));
-
-    for(i = 0; i < NB_RB_MAX; i++){
-        if((ue_context_pP->ue_context.e_rab[i].status == E_RAB_STATUS_TORELEASE) && ue_context_pP->ue_context.e_rab[i].xid == xid){
-            DRB_release = CALLOC(1, sizeof(DRB_Identity_t));
-            *DRB_release = i+1;
-            ASN_SEQUENCE_ADD(&(*DRB_Release_configList2)->list, DRB_release);
-            //free(DRB_release);
-        }
-    }
-
-    /* If list is empty free the list and reset the address */
-    if (nas_length > 0) {
-        DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
-        dedicatedInfoNASList = CALLOC(1, sizeof(struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));
-        dedicatedInfoNas = CALLOC(1, sizeof(DedicatedInfoNAS_t));
-        memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t));
-                       OCTET_STRING_fromBuf(dedicatedInfoNas,
-                              (char*)nas_buffer,
-                              nas_length);
-        ASN_SEQUENCE_ADD(&dedicatedInfoNASList->list, dedicatedInfoNas);
-        LOG_I(RRC,"add NAS info with size %d\n",nas_length);
-    } else {
-      LOG_W(RRC,"dedlicated NAS list is empty\n");
+  uint8_t                             buffer[RRC_BUF_SIZE];
+  int                                 i;
+  uint16_t                            size  = 0;
+  LTE_DRB_ToReleaseList_t                **DRB_Release_configList2=NULL;
+  LTE_DRB_Identity_t *DRB_release;
+  struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
+  DRB_Release_configList2=&ue_context_pP->ue_context.DRB_Release_configList2[xid];
+
+  if (*DRB_Release_configList2) {
+    free(*DRB_Release_configList2);
+  }
+
+  *DRB_Release_configList2 = CALLOC(1, sizeof(**DRB_Release_configList2));
+
+  for(i = 0; i < NB_RB_MAX; i++) {
+    if((ue_context_pP->ue_context.e_rab[i].status == E_RAB_STATUS_TORELEASE) && ue_context_pP->ue_context.e_rab[i].xid == xid) {
+      DRB_release = CALLOC(1, sizeof(LTE_DRB_Identity_t));
+      *DRB_release = i+1;
+      ASN_SEQUENCE_ADD(&(*DRB_Release_configList2)->list, DRB_release);
+      //free(DRB_release);
     }
+  }
 
-    memset(buffer, 0, RRC_BUF_SIZE);
-    size = do_RRCConnectionReconfiguration(ctxt_pP,
-                                    buffer,
-                                    xid,
-                                    NULL,
-                                    NULL,
-                                    (DRB_ToReleaseList_t*)*DRB_Release_configList2,
-                                    NULL,
-                                    NULL,
-                                    NULL,
-                                    NULL,
-                                    NULL,
-                                    NULL,
-                                    NULL,
-                                    NULL,
-                                    NULL,
-                                    NULL,
-                                    NULL,
-                                    NULL,
-                                    (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList*)dedicatedInfoNASList,
-                                    (SL_CommConfig_r12_t*)NULL,
-                                    (SL_DiscConfig_r12_t*)NULL
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-                                    , (SCellToAddMod_r10_t*)NULL
-#endif
-                                   );
-    ue_context_pP->ue_context.e_rab_release_command_flag = 1;
-    LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,size,
-                "[MSG] RRC Connection Reconfiguration\n");
+  /* If list is empty free the list and reset the address */
+  if (nas_length > 0) {
+    LTE_DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
+    dedicatedInfoNASList = CALLOC(1, sizeof(struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));
+    dedicatedInfoNas = CALLOC(1, sizeof(LTE_DedicatedInfoNAS_t));
+    memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t));
+    OCTET_STRING_fromBuf(dedicatedInfoNas,
+                         (char *)nas_buffer,
+                         nas_length);
+    ASN_SEQUENCE_ADD(&dedicatedInfoNASList->list, dedicatedInfoNas);
+    LOG_I(RRC,"add NAS info with size %d\n",nas_length);
+  } else {
+    LOG_W(RRC,"dedlicated NAS list is empty\n");
+  }
 
+  memset(buffer, 0, RRC_BUF_SIZE);
+  size = do_RRCConnectionReconfiguration(ctxt_pP,
+                                         buffer,
+                                         xid,
+                                         NULL,
+                                         NULL,
+                                         (LTE_DRB_ToReleaseList_t *)*DRB_Release_configList2,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         NULL,
+                                         (struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *)dedicatedInfoNASList,
+                                         (LTE_SL_CommConfig_r12_t *)NULL,
+                                         (LTE_SL_DiscConfig_r12_t *)NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                                         , (LTE_SCellToAddMod_r10_t *)NULL
+#endif
+                                        );
+  ue_context_pP->ue_context.e_rab_release_command_flag = 1;
+  LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,size,
+              "[MSG] RRC Connection Reconfiguration\n");
 #if defined(ENABLE_ITTI)
+
   /* Free all NAS PDUs */
   if (nas_length > 0) {
-      /* Free the NAS PDU buffer and invalidate it */
-      free(nas_buffer);
+    /* Free the NAS PDU buffer and invalidate it */
+    free(nas_buffer);
   }
-#endif
 
+#endif
   LOG_I(RRC,
-        "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration (bytes %d, UE RNTI %x)\n",
+        "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate LTE_RRCConnectionReconfiguration (bytes %d, UE RNTI %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",
         ctxt_pP->frame, ctxt_pP->module_id, size, ue_context_pP->ue_context.rnti, rrc_eNB_mui, ctxt_pP->module_id, DCCH);
-
   MSC_LOG_TX_MESSAGE(
     MSC_RRC_ENB,
     MSC_RRC_UE,
     buffer,
     size,
-    MSC_AS_TIME_FMT" dedicated rrcConnectionReconfiguration UE %x MUI %d size %u",
+    MSC_AS_TIME_FMT" dedicated LTE_RRCConnectionReconfiguration UE %x MUI %d size %u",
     MSC_AS_TIME_ARGS(ctxt_pP),
     ue_context_pP->ue_context.rnti,
     rrc_eNB_mui,
     size);
-
   rrc_data_req(
     ctxt_pP,
     DCCH,
@@ -2866,78 +2750,69 @@ rrc_eNB_generate_dedicatedRRCConnectionReconfiguration_release(  const protocol_
     size,
     buffer,
     PDCP_TRANSMISSION_MODE_CONTROL);
-
 }
-#endif 
+#endif
 //-----------------------------------------------------------------------------
 void
-rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t* const ctxt_pP,
-						     rrc_eNB_ue_context_t*          const ue_context_pP,
-						     const uint8_t                ho_state
-						     )
+rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t *const ctxt_pP,
+    rrc_eNB_ue_context_t          *const ue_context_pP,
+    const uint8_t                ho_state
+                                                    )
 //-----------------------------------------------------------------------------
 {
   uint8_t                             buffer[RRC_BUF_SIZE];
   uint16_t                            size;
   int                                 i;
-
-  // configure SRB1/SRB2, PhysicalConfigDedicated, MAC_MainConfig for UE
-  eNB_RRC_INST*                       rrc_inst = RC.rrc[ctxt_pP->module_id];
-  struct PhysicalConfigDedicated**    physicalConfigDedicated = &ue_context_pP->ue_context.physicalConfigDedicated;
-
-  struct SRB_ToAddMod                *SRB2_config                      = NULL;
-  struct SRB_ToAddMod__rlc_Config    *SRB2_rlc_config                  = NULL;
-  struct SRB_ToAddMod__logicalChannelConfig *SRB2_lchan_config         = NULL;
-  struct LogicalChannelConfig__ul_SpecificParameters
-      *SRB2_ul_SpecificParameters       = NULL;
-  SRB_ToAddModList_t*                 SRB_configList = ue_context_pP->ue_context.SRB_configList;
-  SRB_ToAddModList_t                 **SRB_configList2                  = NULL;
-
-  struct DRB_ToAddMod                *DRB_config                       = NULL;
-  struct RLC_Config                  *DRB_rlc_config                   = NULL;
-  struct PDCP_Config                 *DRB_pdcp_config                  = NULL;
-  struct PDCP_Config__rlc_AM         *PDCP_rlc_AM                      = NULL;
-  struct PDCP_Config__rlc_UM         *PDCP_rlc_UM                      = NULL;
-  struct LogicalChannelConfig        *DRB_lchan_config                 = NULL;
-  struct LogicalChannelConfig__ul_SpecificParameters
-      *DRB_ul_SpecificParameters        = NULL;
-  DRB_ToAddModList_t**                DRB_configList = &ue_context_pP->ue_context.DRB_configList;
-  DRB_ToAddModList_t**                DRB_configList2 = NULL;
-   MAC_MainConfig_t                   *mac_MainConfig                   = NULL;
-  MeasObjectToAddModList_t           *MeasObj_list                     = NULL;
-  MeasObjectToAddMod_t               *MeasObj                          = NULL;
-  ReportConfigToAddModList_t         *ReportConfig_list                = NULL;
-  ReportConfigToAddMod_t             *ReportConfig_per, *ReportConfig_A1,
-                                     *ReportConfig_A2, *ReportConfig_A3, *ReportConfig_A4, *ReportConfig_A5;
-  MeasIdToAddModList_t               *MeasId_list                      = NULL;
-  MeasIdToAddMod_t                   *MeasId0, *MeasId1, *MeasId2, *MeasId3, *MeasId4, *MeasId5;
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+  // 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                      = NULL;
+  struct LTE_SRB_ToAddMod__rlc_Config    *SRB2_rlc_config                  = NULL;
+  struct LTE_SRB_ToAddMod__logicalChannelConfig *SRB2_lchan_config         = NULL;
+  struct LTE_LogicalChannelConfig__ul_SpecificParameters
+    *SRB2_ul_SpecificParameters       = NULL;
+  LTE_SRB_ToAddModList_t                 *SRB_configList = ue_context_pP->ue_context.SRB_configList;
+  LTE_SRB_ToAddModList_t                 **SRB_configList2                  = NULL;
+  struct LTE_DRB_ToAddMod                *DRB_config                       = NULL;
+  struct LTE_RLC_Config                  *DRB_rlc_config                   = NULL;
+  struct LTE_PDCP_Config                 *DRB_pdcp_config                  = NULL;
+  struct LTE_PDCP_Config__rlc_AM         *PDCP_rlc_AM                      = NULL;
+  struct LTE_PDCP_Config__rlc_UM         *PDCP_rlc_UM                      = NULL;
+  struct LTE_LogicalChannelConfig        *DRB_lchan_config                 = NULL;
+  struct LTE_LogicalChannelConfig__ul_SpecificParameters
+    *DRB_ul_SpecificParameters        = NULL;
+  LTE_DRB_ToAddModList_t                **DRB_configList = &ue_context_pP->ue_context.DRB_configList;
+  LTE_DRB_ToAddModList_t                **DRB_configList2 = NULL;
+  LTE_MAC_MainConfig_t                   *mac_MainConfig                   = NULL;
+  LTE_MeasObjectToAddModList_t           *MeasObj_list                     = NULL;
+  LTE_MeasObjectToAddMod_t               *MeasObj                          = NULL;
+  LTE_ReportConfigToAddModList_t         *ReportConfig_list                = NULL;
+  LTE_ReportConfigToAddMod_t             *ReportConfig_per, *ReportConfig_A1,
+                                         *ReportConfig_A2, *ReportConfig_A3, *ReportConfig_A4, *ReportConfig_A5;
+  LTE_MeasIdToAddModList_t               *MeasId_list                      = NULL;
+  LTE_MeasIdToAddMod_t                   *MeasId0, *MeasId1, *MeasId2, *MeasId3, *MeasId4, *MeasId5;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
   long                               *sr_ProhibitTimer_r9              = NULL;
   //     uint8_t sCellIndexToAdd = rrc_find_free_SCell_index(enb_mod_idP, ue_mod_idP, 1);
   //uint8_t                            sCellIndexToAdd = 0;
 #endif
-
   long                               *logicalchannelgroup, *logicalchannelgroup_drb;
   long                               *maxHARQ_Tx, *periodicBSR_Timer;
-
-  RSRP_Range_t                       *rsrp                             = NULL;
-  struct MeasConfig__speedStatePars  *Sparams                          = NULL;
-  QuantityConfig_t                   *quantityConfig                   = NULL;
-  CellsToAddMod_t                    *CellToAdd                        = NULL;
-  CellsToAddModList_t                *CellsToAddModList                = NULL;
-  struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
-  DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
+  LTE_RSRP_Range_t                       *rsrp                             = NULL;
+  struct LTE_MeasConfig__speedStatePars  *Sparams                          = NULL;
+  LTE_QuantityConfig_t                   *quantityConfig                   = NULL;
+  //LTE_CellsToAddMod_t                    *CellToAdd                        = NULL;
+  //LTE_CellsToAddModList_t                *CellsToAddModList                = NULL;
+  struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
+  LTE_DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
   /* for no gcc warnings */
   (void)dedicatedInfoNas;
-
-  C_RNTI_t                           *cba_RNTI                         = NULL;
-
+  LTE_C_RNTI_t                           *cba_RNTI                         = NULL;
   uint8_t xid = rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id);   //Transaction_id,
-
 #ifdef CBA
   //struct PUSCH_CBAConfigDedicated_vlola  *pusch_CBAConfigDedicated_vlola;
   uint8_t                            *cba_RNTI_buf;
-  cba_RNTI = CALLOC(1, sizeof(C_RNTI_t));
+  cba_RNTI = CALLOC(1, sizeof(LTE_C_RNTI_t));
   cba_RNTI_buf = CALLOC(1, 2 * sizeof(uint8_t));
   cba_RNTI->buf = cba_RNTI_buf;
   cba_RNTI->size = 2;
@@ -2959,52 +2834,43 @@ rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t* cons
   }
 
 #endif
-
   T(T_ENB_RRC_CONNECTION_RECONFIGURATION, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
     T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
-
   // Configure SRB2
   /// SRB2
   SRB_configList2=&ue_context_pP->ue_context.SRB_configList2[xid];
+
   if (*SRB_configList2) {
     free(*SRB_configList2);
   }
+
   *SRB_configList2 = CALLOC(1, sizeof(**SRB_configList2));
   memset(*SRB_configList2, 0, sizeof(**SRB_configList2));
   SRB2_config = CALLOC(1, sizeof(*SRB2_config));
-
   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 = SRB_ToAddMod__rlc_Config_PR_explicitValue;
-  SRB2_rlc_config->choice.explicitValue.present = RLC_Config_PR_am;
-  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = T_PollRetransmit_ms15;
-  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU = PollPDU_p8;
-  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte = PollByte_kB1000;
-  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = UL_AM_RLC__maxRetxThreshold_t32;
-  SRB2_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering = T_Reordering_ms35;
-  SRB2_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = T_StatusProhibit_ms10;
-
+  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 = SRB_ToAddMod__logicalChannelConfig_PR_explicitValue;
-
+  SRB2_lchan_config->present = LTE_SRB_ToAddMod__logicalChannelConfig_PR_explicitValue;
   SRB2_ul_SpecificParameters = CALLOC(1, sizeof(*SRB2_ul_SpecificParameters));
-
   SRB2_ul_SpecificParameters->priority = 3; // let some priority for SRB1 and dedicated DRBs
   SRB2_ul_SpecificParameters->prioritisedBitRate =
-    LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
+    LTE_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
   SRB2_ul_SpecificParameters->bucketSizeDuration =
-    LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
-
+    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;
   // this list has the configuration for SRB1 and SRB2
   ASN_SEQUENCE_ADD(&SRB_configList->list, SRB2_config);
@@ -3017,61 +2883,56 @@ rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t* cons
   if (*DRB_configList) {
     free(*DRB_configList);
   }
+
   *DRB_configList = CALLOC(1, sizeof(**DRB_configList));
   memset(*DRB_configList, 0, sizeof(**DRB_configList));
-
   // list for the configured DRB for a this xid
   DRB_configList2=&ue_context_pP->ue_context.DRB_configList2[xid];
+
   if (*DRB_configList2) {
     free(*DRB_configList2);
   }
+
   *DRB_configList2 = CALLOC(1, sizeof(**DRB_configList2));
   memset(*DRB_configList2, 0, sizeof(**DRB_configList2));
-
-
   /// DRB
   DRB_config = CALLOC(1, sizeof(*DRB_config));
-
   DRB_config->eps_BearerIdentity = CALLOC(1, sizeof(long));
   *(DRB_config->eps_BearerIdentity) = 5L; // LW set to first value, allowed value 5..15, value : x+4
-  // DRB_config->drb_Identity = (DRB_Identity_t) 1; //allowed values 1..32
+  // 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 = (DRB_Identity_t) 1;  // (ue_mod_idP+1); //allowed values 1..32, value: x
+  DRB_config->drb_Identity = (LTE_DRB_Identity_t) 1;  // (ue_mod_idP+1); //allowed values 1..32, value: x
   DRB_config->logicalChannelIdentity = CALLOC(1, sizeof(long));
   *(DRB_config->logicalChannelIdentity) = (long)3; // value : x+2
   DRB_rlc_config = CALLOC(1, sizeof(*DRB_rlc_config));
   DRB_config->rlc_Config = DRB_rlc_config;
-
 #ifdef RRC_DEFAULT_RAB_IS_AM
-  DRB_rlc_config->present = RLC_Config_PR_am;
-  DRB_rlc_config->choice.am.ul_AM_RLC.t_PollRetransmit = T_PollRetransmit_ms50;
-  DRB_rlc_config->choice.am.ul_AM_RLC.pollPDU = PollPDU_p16;
-  DRB_rlc_config->choice.am.ul_AM_RLC.pollByte = PollByte_kBinfinity;
-  DRB_rlc_config->choice.am.ul_AM_RLC.maxRetxThreshold = UL_AM_RLC__maxRetxThreshold_t8;
-  DRB_rlc_config->choice.am.dl_AM_RLC.t_Reordering = T_Reordering_ms35;
-  DRB_rlc_config->choice.am.dl_AM_RLC.t_StatusProhibit = T_StatusProhibit_ms25;
+  DRB_rlc_config->present = LTE_RLC_Config_PR_am;
+  DRB_rlc_config->choice.am.ul_AM_RLC.t_PollRetransmit = LTE_T_PollRetransmit_ms50;
+  DRB_rlc_config->choice.am.ul_AM_RLC.pollPDU = LTE_PollPDU_p16;
+  DRB_rlc_config->choice.am.ul_AM_RLC.pollByte = LTE_PollByte_kBinfinity;
+  DRB_rlc_config->choice.am.ul_AM_RLC.maxRetxThreshold = LTE_UL_AM_RLC__maxRetxThreshold_t8;
+  DRB_rlc_config->choice.am.dl_AM_RLC.t_Reordering = LTE_T_Reordering_ms35;
+  DRB_rlc_config->choice.am.dl_AM_RLC.t_StatusProhibit = LTE_T_StatusProhibit_ms25;
 #else
-  DRB_rlc_config->present = RLC_Config_PR_um_Bi_Directional;
-  DRB_rlc_config->choice.um_Bi_Directional.ul_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
-  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
+  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;
 #ifdef CBA
-  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering   = T_Reordering_ms5;//T_Reordering_ms25;
+  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering   = LTE_T_Reordering_ms5;//T_Reordering_ms25;
 #else
-  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = T_Reordering_ms35;
+  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = LTE_T_Reordering_ms35;
 #endif
 #endif
-
   DRB_pdcp_config = CALLOC(1, sizeof(*DRB_pdcp_config));
   DRB_config->pdcp_Config = DRB_pdcp_config;
   DRB_pdcp_config->discardTimer = CALLOC(1, sizeof(long));
-  *DRB_pdcp_config->discardTimer = PDCP_Config__discardTimer_infinity;
+  *DRB_pdcp_config->discardTimer = LTE_PDCP_Config__discardTimer_infinity;
   DRB_pdcp_config->rlc_AM = NULL;
   DRB_pdcp_config->rlc_UM = NULL;
-
   /* avoid gcc warnings */
   (void)PDCP_rlc_AM;
   (void)PDCP_rlc_UM;
-
 #ifdef RRC_DEFAULT_RAB_IS_AM // EXMIMO_IOT
   PDCP_rlc_AM = CALLOC(1, sizeof(*PDCP_rlc_AM));
   DRB_pdcp_config->rlc_AM = PDCP_rlc_AM;
@@ -3079,62 +2940,47 @@ rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t* cons
 #else
   PDCP_rlc_UM = CALLOC(1, sizeof(*PDCP_rlc_UM));
   DRB_pdcp_config->rlc_UM = PDCP_rlc_UM;
-  PDCP_rlc_UM->pdcp_SN_Size = PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits;
+  PDCP_rlc_UM->pdcp_SN_Size = LTE_PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits;
 #endif
-  DRB_pdcp_config->headerCompression.present = PDCP_Config__headerCompression_PR_notUsed;
-
+  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 = 12;    // lower priority than srb1, srb2 and other dedicated bearer
-  DRB_ul_SpecificParameters->prioritisedBitRate =LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_kBps8 ;
-    //LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
+  DRB_ul_SpecificParameters->prioritisedBitRate =LTE_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_kBps8 ;
+  //LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
   DRB_ul_SpecificParameters->bucketSizeDuration =
-    LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
-
+    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_configList)->list, DRB_config);
   ASN_SEQUENCE_ADD(&(*DRB_configList2)->list, DRB_config);
-
   //ue_context_pP->ue_context.DRB_configList2[0] = &(*DRB_configList);
-
   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 = MAC_MainConfig__ul_SCH_Config__maxHARQ_Tx_n5;
+  *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 = PeriodicBSR_Timer_r12_sf64;
+  *periodicBSR_Timer = LTE_PeriodicBSR_Timer_r12_sf64;
   mac_MainConfig->ul_SCH_Config->periodicBSR_Timer = periodicBSR_Timer;
-  mac_MainConfig->ul_SCH_Config->retxBSR_Timer = RetxBSR_Timer_r12_sf320;
+  mac_MainConfig->ul_SCH_Config->retxBSR_Timer = LTE_RetxBSR_Timer_r12_sf320;
   mac_MainConfig->ul_SCH_Config->ttiBundling = 0; // FALSE
-
-  mac_MainConfig->timeAlignmentTimerDedicated = TimeAlignmentTimer_infinity;
-
+  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 = MAC_MainConfig__phr_Config_PR_setup;
-  mac_MainConfig->phr_Config->choice.setup.periodicPHR_Timer = MAC_MainConfig__phr_Config__setup__periodicPHR_Timer_sf20; // sf20 = 20 subframes
-
-  mac_MainConfig->phr_Config->choice.setup.prohibitPHR_Timer = MAC_MainConfig__phr_Config__setup__prohibitPHR_Timer_sf20; // sf20 = 20 subframes
-
-  mac_MainConfig->phr_Config->choice.setup.dl_PathlossChange = MAC_MainConfig__phr_Config__setup__dl_PathlossChange_dB1;  // Value dB1 =1 dB, dB3 = 3 dB
-
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+  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 MAC_MainConfig__ext1));
+  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
@@ -3144,44 +2990,44 @@ rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t* cons
   //TODO: change TM for secondary CC in SCelltoaddmodlist
   if (*physicalConfigDedicated) {
     if ((*physicalConfigDedicated)->antennaInfo) {
-      (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.transmissionMode = rrc_inst->configuration.ue_TransmissionMode[0];
-      LOG_D(RRC,"Setting transmission mode to %ld+1\n",rrc_inst->configuration.ue_TransmissionMode[0]);
-      if (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm3) {
+
+      (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.transmissionMode = rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode;
+      LOG_D(RRC,"Setting transmission mode to %ld+1\n",rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode);
+      if (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm3) {
 	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=     
-	  CALLOC(1,sizeof(AntennaInfoDedicated__codebookSubsetRestriction_PR));
+	  CALLOC(1,sizeof(LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR));
 	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
-	  AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm3;
+	  LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm3;
 	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.buf= MALLOC(1);
 	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.buf[0] = 0xc0;
 	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.size=1;
 	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.bits_unused=6;
       }
-      else if (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm4) {
+      else if (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm4) {
 	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=     
-	  CALLOC(1,sizeof(AntennaInfoDedicated__codebookSubsetRestriction_PR));
+	  CALLOC(1,sizeof(LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR));
 	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
-	  AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm4;
+	  LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm4;
 	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.buf= MALLOC(1);
 	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.buf[0] = 0xfc;
 	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.size=1;
 	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.bits_unused=2;
-
       }
-      else if (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm5) {
+      else if (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm5) {
 	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=     
-	  CALLOC(1,sizeof(AntennaInfoDedicated__codebookSubsetRestriction_PR));
+	  CALLOC(1,sizeof(LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR));
 	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
-	  AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm5;
+	  LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm5;
 	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.buf= MALLOC(1);
 	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.buf[0] = 0xf0;
 	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.size=1;
 	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.bits_unused=4;
       }
-      else if (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm6) {
+      else if (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm6) {
 	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=     
-	  CALLOC(1,sizeof(AntennaInfoDedicated__codebookSubsetRestriction_PR));
+	  CALLOC(1,sizeof(LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR));
 	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
-	  AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm6;
+	  LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm6;
 	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.buf= MALLOC(1);
 	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.buf[0] = 0xf0;
 	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.size=1;
@@ -3191,369 +3037,325 @@ rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t* cons
     else {
       LOG_E(RRC,"antenna_info not present in physical_config_dedicated. Not reconfiguring!\n");
     }
+
     if ((*physicalConfigDedicated)->cqi_ReportConfig) {
-      if ((rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm4) ||
-	  (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm5) ||
-	  (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm6)) {
+
+      if ((rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm4) ||
+	  (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm5) ||
+	  (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm6)) {
 	//feedback mode needs to be set as well
 	//TODO: I think this is taken into account in the PHY automatically based on the transmission mode variable
 	printf("setting cqi reporting mode to rm31\n");
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-	*((*physicalConfigDedicated)->cqi_ReportConfig->cqi_ReportModeAperiodic)=CQI_ReportModeAperiodic_rm31;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+        *((*physicalConfigDedicated)->cqi_ReportConfig->cqi_ReportModeAperiodic)=LTE_CQI_ReportModeAperiodic_rm31;
 #else
-	*((*physicalConfigDedicated)->cqi_ReportConfig->cqi_ReportModeAperiodic)=CQI_ReportConfig__cqi_ReportModeAperiodic_rm31; // HLC CQI, no PMI
+        *((*physicalConfigDedicated)->cqi_ReportConfig->cqi_ReportModeAperiodic)=LTE_CQI_ReportConfig__cqi_ReportModeAperiodic_rm31; // HLC CQI, no PMI
 #endif
       }
-    }
-    else {
+    } else {
       LOG_E(RRC,"cqi_ReportConfig not present in physical_config_dedicated. Not reconfiguring!\n");
     }
-  }
-  else {
-    LOG_E(RRC,"physical_config_dedicated not present in RRCConnectionReconfiguration. Not reconfiguring!\n");
+  } else {
+    LOG_E(RRC,"physical_config_dedicated not present in LTE_RRCConnectionReconfiguration. Not reconfiguring!\n");
   }
 
   // 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);
-
-  //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measIdToAddModList = MeasId_list;
-
+  //  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 = MeasObjectToAddMod__measObject_PR_measObjectEUTRA;
-  MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 3350; //band 7, 2.68GHz
-  //MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 36090; //band 33, 1.909GHz
-  MeasObj->measObject.choice.measObjectEUTRA.allowedMeasBandwidth = AllowedMeasBandwidth_mbw25;
+  MeasObj->measObject.present = LTE_MeasObjectToAddMod__measObject_PR_measObjectEUTRA;
+  MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = (LTE_ARFCN_ValueEUTRA_t)to_earfcn_DL(RC.rrc[ctxt_pP->module_id]->carrier[0].eutra_band, RC.rrc[ctxt_pP->module_id]->carrier[0].dl_CarrierFreq,
+      RC.rrc[ctxt_pP->module_id]->carrier[0].N_RB_DL);
+  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 =
-    (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 = (CellsToAddMod_t *) CALLOC(1, sizeof(*CellToAdd));
-    CellToAdd->cellIndex = i + 1;
-    CellToAdd->physCellId = get_adjacent_cell_id(ctxt_pP->module_id, i);
-    CellToAdd->cellIndividualOffset = Q_OffsetRange_dB0;
-
-    ASN_SEQUENCE_ADD(&CellsToAddModList->list, CellToAdd);
-  }
+//  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);
-  //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measObjectToAddModList = MeasObj_list;
-
+  //  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 = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
+  ReportConfig_per->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
   ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.present =
-    ReportConfigEUTRA__triggerType_PR_periodical;
+    LTE_ReportConfigEUTRA__triggerType_PR_periodical;
   ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.choice.periodical.purpose =
-    ReportConfigEUTRA__triggerType__periodical__purpose_reportStrongestCells;
-  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerQuantity = ReportConfigEUTRA__triggerQuantity_rsrp;
-  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
+    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 = ReportInterval_ms120;
-  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;
-
+  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 = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
+  ReportConfig_A1->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
   ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.present =
-    ReportConfigEUTRA__triggerType_PR_event;
+    LTE_ReportConfigEUTRA__triggerType_PR_event;
   ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
-    ReportConfigEUTRA__triggerType__event__eventId_PR_eventA1;
+    LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA1;
   ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA1.
-  a1_Threshold.present = ThresholdEUTRA_PR_threshold_RSRP;
+  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 = ReportConfigEUTRA__triggerQuantity_rsrp;
-  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
+  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 = ReportInterval_ms120;
-  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;
-
+  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);
-  
-  if (ho_state == 1 /*HO_MEASURMENT */ ) {
-    LOG_I(RRC, "[eNB %d] frame %d: requesting A2, A3, A4, A5, and A6 event reporting\n",
-          ctxt_pP->module_id, ctxt_pP->frame);
-    ReportConfig_A2->reportConfigId = 3;
-    ReportConfig_A2->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
-    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.present =
-      ReportConfigEUTRA__triggerType_PR_event;
-    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
-      ReportConfigEUTRA__triggerType__event__eventId_PR_eventA2;
-    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
-    eventA2.a2_Threshold.present = 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 =
-      ReportConfigEUTRA__triggerQuantity_rsrp;
-    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
-    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
-    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportInterval = ReportInterval_ms120;
-    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;
-
-    ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A2);
-
-    ReportConfig_A3->reportConfigId = 4;
-    ReportConfig_A3->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
-    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.present =
-      ReportConfigEUTRA__triggerType_PR_event;
-    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
-      ReportConfigEUTRA__triggerType__event__eventId_PR_eventA3;
 
-    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA3.a3_Offset = 1;   //10;
-    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
-    eventA3.reportOnLeave = 1;
+  //if (ho_state == 1 /*HO_MEASURMENT */ ) {
+  LOG_I(RRC, "[eNB %d] frame %d: requesting A2, A3, A4, and A5 event reporting\n",
+        ctxt_pP->module_id, ctxt_pP->frame);
+  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 = 0;   //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;
+  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.hysteresis = 0; // FIXME ...hysteresis is of type long!
+  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.timeToTrigger =
+    LTE_TimeToTrigger_ms40;
+  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);
+  //  LTE_RRCConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->reportConfigToAddModList = ReportConfig_list;
+  rsrp = CALLOC(1, sizeof(LTE_RSRP_Range_t));
+  *rsrp = 20;
+  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(struct LTE_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;
+#if 0
+  LOG_I(RRC,
+        "[eNB %d] Frame %d: potential handover preparation: store the information in an intermediate structure in case of failure\n",
+        ctxt_pP->module_id, ctxt_pP->frame);
+  // store the information in an intermediate structure for Hanodver management
+  //rrc_inst->handover_info.as_config.sourceRadioResourceConfig.srb_ToAddModList = CALLOC(1,sizeof());
+  ue_context_pP->ue_context.handover_info = CALLOC(1, sizeof(*(ue_context_pP->ue_context.handover_info)));
+  //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.srb_ToAddModList,(void *)SRB_list,sizeof(LTE_SRB_ToAddModList_t));
+  ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.srb_ToAddModList = *SRB_configList2;
+  //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.drb_ToAddModList,(void *)DRB_list,sizeof(LTE_DRB_ToAddModList_t));
+  ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToAddModList = *DRB_configList;
+  ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToReleaseList = NULL;
+  ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig =
+    CALLOC(1, sizeof(*ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig));
+  memcpy((void *)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig,
+         (void *)mac_MainConfig, sizeof(LTE_MAC_MainConfig_t));
+  ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.physicalConfigDedicated =
+    CALLOC(1, sizeof(LTE_PhysicalConfigDedicated_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));
+  ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.sps_Config = NULL;
+  //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));
+#endif
+  //}
 
-    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerQuantity =
-      ReportConfigEUTRA__triggerQuantity_rsrp;
-    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
-    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
-    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportInterval = ReportInterval_ms120;
-    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;
+#if defined(ENABLE_ITTI)
+  /* Initialize NAS list */
+  dedicatedInfoNASList = CALLOC(1, sizeof(struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));
 
-    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.hysteresis = 0.5; // FIXME ...hysteresis is of type long!
-    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.timeToTrigger =
-      TimeToTrigger_ms40;
-    ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A3);
+  /* Add all NAS PDUs to the list */
+  for (i = 0; i < ue_context_pP->ue_context.nb_of_e_rabs; i++) {
+    if (ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer != NULL) {
+      dedicatedInfoNas = CALLOC(1, sizeof(LTE_DedicatedInfoNAS_t));
+      memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t));
+      OCTET_STRING_fromBuf(dedicatedInfoNas,
+                           (char *)ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer,
+                           ue_context_pP->ue_context.e_rab[i].param.nas_pdu.length);
+      ASN_SEQUENCE_ADD(&dedicatedInfoNASList->list, dedicatedInfoNas);
+    }
 
-    ReportConfig_A4->reportConfigId = 5;
-    ReportConfig_A4->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
-    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.present =
-      ReportConfigEUTRA__triggerType_PR_event;
-    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
-      ReportConfigEUTRA__triggerType__event__eventId_PR_eventA4;
-    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
-    eventA4.a4_Threshold.present = ThresholdEUTRA_PR_threshold_RSRP;
-    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
-    eventA4.a4_Threshold.choice.threshold_RSRP = 10;
+    /* TODO parameters yet to process ... */
+    {
+      //      ue_context_pP->ue_context.e_rab[i].param.qos;
+      //      ue_context_pP->ue_context.e_rab[i].param.sgw_addr;
+      //      ue_context_pP->ue_context.e_rab[i].param.gtp_teid;
+    }
+    /* TODO should test if e RAB are Ok before! */
+    ue_context_pP->ue_context.e_rab[i].status = E_RAB_STATUS_DONE;
+    LOG_D(RRC, "setting the status for the default DRB (index %d) to (%d,%s)\n",
+          i, ue_context_pP->ue_context.e_rab[i].status, "E_RAB_STATUS_DONE");
+  }
 
-    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerQuantity =
-      ReportConfigEUTRA__triggerQuantity_rsrp;
-    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
-    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
-    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportInterval = ReportInterval_ms120;
-    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;
+  /* If list is empty free the list and reset the address */
+  if (dedicatedInfoNASList->list.count == 0) {
+    free(dedicatedInfoNASList);
+    dedicatedInfoNASList = NULL;
+  }
 
-    ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A4);
-
-    ReportConfig_A5->reportConfigId = 6;
-    ReportConfig_A5->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
-    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.present =
-      ReportConfigEUTRA__triggerType_PR_event;
-    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
-      ReportConfigEUTRA__triggerType__event__eventId_PR_eventA5;
-    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
-    eventA5.a5_Threshold1.present = ThresholdEUTRA_PR_threshold_RSRP;
-    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
-    eventA5.a5_Threshold2.present = 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 =
-      ReportConfigEUTRA__triggerQuantity_rsrp;
-    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
-    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
-    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportInterval = ReportInterval_ms120;
-    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;
-
-    ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A5);
-    //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->reportConfigToAddModList = ReportConfig_list;
-
-    rsrp = CALLOC(1, sizeof(RSRP_Range_t));
-    *rsrp = 20;
-
-    Sparams = CALLOC(1, sizeof(*Sparams));
-    Sparams->present = MeasConfig__speedStatePars_PR_setup;
-    Sparams->choice.setup.timeToTrigger_SF.sf_High = SpeedStateScaleFactors__sf_Medium_oDot75;
-    Sparams->choice.setup.timeToTrigger_SF.sf_Medium = SpeedStateScaleFactors__sf_High_oDot5;
-    Sparams->choice.setup.mobilityStateParameters.n_CellChangeHigh = 10;
-    Sparams->choice.setup.mobilityStateParameters.n_CellChangeMedium = 5;
-    Sparams->choice.setup.mobilityStateParameters.t_Evaluation = MobilityStateParameters__t_Evaluation_s60;
-    Sparams->choice.setup.mobilityStateParameters.t_HystNormal = MobilityStateParameters__t_HystNormal_s120;
-
-    quantityConfig = CALLOC(1, sizeof(*quantityConfig));
-    memset((void *)quantityConfig, 0, sizeof(*quantityConfig));
-    quantityConfig->quantityConfigEUTRA = CALLOC(1, sizeof(struct 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 = FilterCoefficient_fc4;
-    *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ = FilterCoefficient_fc4;
-
-    LOG_I(RRC,
-          "[eNB %d] Frame %d: potential handover preparation: store the information in an intermediate structure in case of failure\n",
-          ctxt_pP->module_id, ctxt_pP->frame);
-    // store the information in an intermediate structure for Hanodver management
-    //rrc_inst->handover_info.as_config.sourceRadioResourceConfig.srb_ToAddModList = CALLOC(1,sizeof());
-    ue_context_pP->ue_context.handover_info = CALLOC(1, sizeof(*(ue_context_pP->ue_context.handover_info)));
-    //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.srb_ToAddModList,(void *)SRB_list,sizeof(SRB_ToAddModList_t));
-    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.srb_ToAddModList = *SRB_configList2;
-    //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.drb_ToAddModList,(void *)DRB_list,sizeof(DRB_ToAddModList_t));
-    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToAddModList = *DRB_configList;
-    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToReleaseList = NULL;
-    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig =
-      CALLOC(1, sizeof(*ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig));
-    memcpy((void*)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig,
-           (void *)mac_MainConfig, sizeof(MAC_MainConfig_t));
-    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.physicalConfigDedicated =
-      CALLOC(1, sizeof(PhysicalConfigDedicated_t));
-    memcpy((void*)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.physicalConfigDedicated,
-           (void*)ue_context_pP->ue_context.physicalConfigDedicated, sizeof(PhysicalConfigDedicated_t));
-    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.sps_Config = NULL;
-    //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));
-
-  }
-
-#if defined(ENABLE_ITTI)
-  /* Initialize NAS list */
-  dedicatedInfoNASList = CALLOC(1, sizeof(struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));
-
-  /* Add all NAS PDUs to the list */
-  for (i = 0; i < ue_context_pP->ue_context.nb_of_e_rabs; i++) {
-    if (ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer != NULL) {
-      dedicatedInfoNas = CALLOC(1, sizeof(DedicatedInfoNAS_t));
-      memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t));
-      OCTET_STRING_fromBuf(dedicatedInfoNas, 
-			   (char*)ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer,
-                           ue_context_pP->ue_context.e_rab[i].param.nas_pdu.length);
-      ASN_SEQUENCE_ADD(&dedicatedInfoNASList->list, dedicatedInfoNas);
-    }
-
-    /* TODO parameters yet to process ... */
-    {
-      //      ue_context_pP->ue_context.e_rab[i].param.qos;
-      //      ue_context_pP->ue_context.e_rab[i].param.sgw_addr;
-      //      ue_context_pP->ue_context.e_rab[i].param.gtp_teid;
-    }
-
-    /* TODO should test if e RAB are Ok before! */
-    ue_context_pP->ue_context.e_rab[i].status = E_RAB_STATUS_DONE;
-    LOG_D(RRC, "setting the status for the default DRB (index %d) to (%d,%s)\n", 
-	  i, ue_context_pP->ue_context.e_rab[i].status, "E_RAB_STATUS_DONE");
-  }
-
-  /* If list is empty free the list and reset the address */
-  if (dedicatedInfoNASList->list.count == 0) {
-    free(dedicatedInfoNASList);
-    dedicatedInfoNASList = NULL;
-  }
-
-#endif
-
-  memset(buffer, 0, RRC_BUF_SIZE);
-
-  size = do_RRCConnectionReconfiguration(ctxt_pP,
-                                         buffer,
-                                         xid,   //Transaction_id,
-                                         (SRB_ToAddModList_t*)*SRB_configList2, // SRB_configList
-                                         (DRB_ToAddModList_t*)*DRB_configList,
-                                         (DRB_ToReleaseList_t*)NULL,  // DRB2_list,
-                                         (struct SPS_Config*)NULL,    // *sps_Config,
-                                         (struct PhysicalConfigDedicated*)*physicalConfigDedicated,
-#ifdef EXMIMO_IOT
-                                         NULL, NULL, NULL,NULL,
-#else
-                                         (MeasObjectToAddModList_t*)MeasObj_list,
-                                         (ReportConfigToAddModList_t*)ReportConfig_list,
-                                         (QuantityConfig_t*)quantityConfig,
-                                         (MeasIdToAddModList_t*)MeasId_list,
-#endif
-                                         (MAC_MainConfig_t*)mac_MainConfig,
-                                         (MeasGapConfig_t*)NULL,
-                                         (MobilityControlInfo_t*)NULL,
-                                         (struct MeasConfig__speedStatePars*)Sparams,
-                                         (RSRP_Range_t*)rsrp,
-                                         (C_RNTI_t*)cba_RNTI,
-                                         (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList*)dedicatedInfoNASList,
-                                         (SL_CommConfig_r12_t*)NULL,
-                                         (SL_DiscConfig_r12_t*)NULL
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-                                         , (SCellToAddMod_r10_t*)NULL
-#endif
-                                        );
-  LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,size,
-              "[MSG] RRC Connection Reconfiguration\n");
-
-#if defined(ENABLE_ITTI)
+#endif
+  memset(buffer, 0, RRC_BUF_SIZE);
+  size = do_RRCConnectionReconfiguration(ctxt_pP,
+                                         buffer,
+                                         xid,   //Transaction_id,
+                                         (LTE_SRB_ToAddModList_t *)*SRB_configList2, // SRB_configList
+                                         (LTE_DRB_ToAddModList_t *)*DRB_configList,
+                                         (LTE_DRB_ToReleaseList_t *)NULL, // DRB2_list,
+                                         (struct LTE_SPS_Config *)NULL,   // *sps_Config,
+                                         (struct LTE_PhysicalConfigDedicated *)*physicalConfigDedicated,
+//#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,
+//#endif
+                                         (LTE_MAC_MainConfig_t *)mac_MainConfig,
+                                         (LTE_MeasGapConfig_t *)NULL,
+                                         (LTE_MobilityControlInfo_t *)NULL,
+                                         (LTE_SecurityConfigHO_t *)NULL,
+                                         (struct LTE_MeasConfig__speedStatePars *)Sparams,
+                                         (LTE_RSRP_Range_t *)rsrp,
+                                         (LTE_C_RNTI_t *)cba_RNTI,
+                                         (struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *)dedicatedInfoNASList,
+                                         (LTE_SL_CommConfig_r12_t *)NULL,
+                                         (LTE_SL_DiscConfig_r12_t *)NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                                         , (LTE_SCellToAddMod_r10_t *)NULL
+#endif
+                                        );
+  LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,size,
+              "[MSG] RRC Connection Reconfiguration\n");
+#if defined(ENABLE_ITTI)
 
   /* Free all NAS PDUs */
   for (i = 0; i < ue_context_pP->ue_context.nb_of_e_rabs; i++) {
@@ -3565,106 +3367,94 @@ rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t* cons
   }
 
 #endif
-
   LOG_I(RRC,
-        "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration (bytes %d, UE id %x)\n",
+        "[eNB %d] Frame %d, 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",
         ctxt_pP->frame, ctxt_pP->module_id, size, ue_context_pP->ue_context.rnti, rrc_eNB_mui, ctxt_pP->module_id, DCCH);
-
   MSC_LOG_TX_MESSAGE(
     MSC_RRC_ENB,
     MSC_RRC_UE,
     buffer,
     size,
-    MSC_AS_TIME_FMT" rrcConnectionReconfiguration UE %x MUI %d size %u",
+    MSC_AS_TIME_FMT" LTE_RRCConnectionReconfiguration UE %x MUI %d size %u",
     MSC_AS_TIME_ARGS(ctxt_pP),
     ue_context_pP->ue_context.rnti,
     rrc_eNB_mui,
     size);
-
   rrc_data_req(
-	       ctxt_pP,
-	       DCCH,
-	       rrc_eNB_mui++,
-	       SDU_CONFIRM_NO,
-	       size,
-	       buffer,
-	       PDCP_TRANSMISSION_MODE_CONTROL);
+    ctxt_pP,
+    DCCH,
+    rrc_eNB_mui++,
+    SDU_CONFIRM_NO,
+    size,
+    buffer,
+    PDCP_TRANSMISSION_MODE_CONTROL);
 }
 
 //-----------------------------------------------------------------------------
 void
-flexran_rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t* const ctxt_pP,
-                 rrc_eNB_ue_context_t*          const ue_context_pP,
-                 const uint8_t                ho_state,
-                 agent_reconf_rrc * trig_param
-                 )
+flexran_rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t *const ctxt_pP,
+    rrc_eNB_ue_context_t          *const ue_context_pP,
+    const uint8_t                ho_state,
+    agent_reconf_rrc *trig_param
+                                                            )
 //-----------------------------------------------------------------------------
 {
   uint8_t                             buffer[RRC_BUF_SIZE];
   uint16_t                            size;
   int                                 i;
- 
-  // configure SRB1/SRB2, PhysicalConfigDedicated, MAC_MainConfig for UE
-  eNB_RRC_INST*                       rrc_inst = RC.rrc[ctxt_pP->module_id];
-  struct PhysicalConfigDedicated**    physicalConfigDedicated = &ue_context_pP->ue_context.physicalConfigDedicated;
-
-  struct SRB_ToAddMod                *SRB2_config                      = NULL;
-  struct SRB_ToAddMod__rlc_Config    *SRB2_rlc_config                  = NULL;
-  struct SRB_ToAddMod__logicalChannelConfig *SRB2_lchan_config         = NULL;
-  struct LogicalChannelConfig__ul_SpecificParameters
-      *SRB2_ul_SpecificParameters       = NULL;
-  SRB_ToAddModList_t*                 SRB_configList = ue_context_pP->ue_context.SRB_configList;
-  SRB_ToAddModList_t                 **SRB_configList2                  = NULL;
-
-  struct DRB_ToAddMod                *DRB_config                       = NULL;
-  struct RLC_Config                  *DRB_rlc_config                   = NULL;
-  struct PDCP_Config                 *DRB_pdcp_config                  = NULL;
-  struct PDCP_Config__rlc_AM         *PDCP_rlc_AM                      = NULL;
-  struct PDCP_Config__rlc_UM         *PDCP_rlc_UM                      = NULL;
-  struct LogicalChannelConfig        *DRB_lchan_config                 = NULL;
-  struct LogicalChannelConfig__ul_SpecificParameters
-      *DRB_ul_SpecificParameters        = NULL;
-  DRB_ToAddModList_t**                DRB_configList = &ue_context_pP->ue_context.DRB_configList;
-  DRB_ToAddModList_t**                DRB_configList2 = NULL;
-   MAC_MainConfig_t                   *mac_MainConfig                   = NULL;
-  MeasObjectToAddModList_t           *MeasObj_list                     = NULL;
-  MeasObjectToAddMod_t               *MeasObj                          = NULL;
-  ReportConfigToAddModList_t         *ReportConfig_list                = NULL;
-  ReportConfigToAddMod_t             *ReportConfig_per;//, *ReportConfig_A1,
-                                     // *ReportConfig_A2, *ReportConfig_A3, *ReportConfig_A4, *ReportConfig_A5;
-  MeasIdToAddModList_t               *MeasId_list                      = NULL;
-  MeasIdToAddMod_t                   *MeasId0; //, *MeasId1, *MeasId2, *MeasId3, *MeasId4, *MeasId5;
-#if Rel10
+  // 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                      = NULL;
+  struct LTE_SRB_ToAddMod__rlc_Config    *SRB2_rlc_config                  = NULL;
+  struct LTE_SRB_ToAddMod__logicalChannelConfig *SRB2_lchan_config         = NULL;
+  struct LTE_LogicalChannelConfig__ul_SpecificParameters
+    *SRB2_ul_SpecificParameters       = NULL;
+  LTE_SRB_ToAddModList_t                 *SRB_configList = ue_context_pP->ue_context.SRB_configList;
+  LTE_SRB_ToAddModList_t                 **SRB_configList2                  = NULL;
+  struct LTE_DRB_ToAddMod                *DRB_config                       = NULL;
+  struct LTE_RLC_Config                  *DRB_rlc_config                   = NULL;
+  struct LTE_PDCP_Config                 *DRB_pdcp_config                  = NULL;
+  struct LTE_PDCP_Config__rlc_AM         *PDCP_rlc_AM                      = NULL;
+  struct LTE_PDCP_Config__rlc_UM         *PDCP_rlc_UM                      = NULL;
+  struct LTE_LogicalChannelConfig        *DRB_lchan_config                 = NULL;
+  struct LTE_LogicalChannelConfig__ul_SpecificParameters
+    *DRB_ul_SpecificParameters        = NULL;
+  LTE_DRB_ToAddModList_t                **DRB_configList = &ue_context_pP->ue_context.DRB_configList;
+  LTE_DRB_ToAddModList_t                **DRB_configList2 = NULL;
+  LTE_MAC_MainConfig_t                   *mac_MainConfig                   = NULL;
+  LTE_MeasObjectToAddModList_t           *MeasObj_list                     = NULL;
+  LTE_MeasObjectToAddMod_t               *MeasObj                          = NULL;
+  LTE_ReportConfigToAddModList_t         *ReportConfig_list                = NULL;
+  LTE_ReportConfigToAddMod_t             *ReportConfig_per;//, *ReportConfig_A1,
+  // *ReportConfig_A2, *ReportConfig_A3, *ReportConfig_A4, *ReportConfig_A5;
+  LTE_MeasIdToAddModList_t               *MeasId_list                      = NULL;
+  LTE_MeasIdToAddMod_t                   *MeasId0; //, *MeasId1, *MeasId2, *MeasId3, *MeasId4, *MeasId5;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
   long                               *sr_ProhibitTimer_r9              = NULL;
   //     uint8_t sCellIndexToAdd = rrc_find_free_SCell_index(enb_mod_idP, ue_mod_idP, 1);
   //uint8_t                            sCellIndexToAdd = 0;
 #endif
-
   long                               *logicalchannelgroup, *logicalchannelgroup_drb;
   long                               *maxHARQ_Tx, *periodicBSR_Timer;
-
-  RSRP_Range_t                       *rsrp                             = NULL;
-  struct MeasConfig__speedStatePars  *Sparams                          = NULL;
-  QuantityConfig_t                   *quantityConfig                   = NULL;
-  CellsToAddMod_t                    *CellToAdd                        = NULL;
-  CellsToAddModList_t                *CellsToAddModList                = NULL;
-  struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
-  DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
+  LTE_RSRP_Range_t                       *rsrp                             = NULL;
+  struct LTE_MeasConfig__speedStatePars  *Sparams                          = NULL;
+  LTE_QuantityConfig_t                   *quantityConfig                   = NULL;
+  LTE_CellsToAddMod_t                    *CellToAdd                        = NULL;
+  LTE_CellsToAddModList_t                *CellsToAddModList                = NULL;
+  struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
+  LTE_DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
   /* for no gcc warnings */
   (void)dedicatedInfoNas;
-
-  C_RNTI_t                           *cba_RNTI                         = NULL;
-
+  LTE_C_RNTI_t                           *cba_RNTI                         = NULL;
   uint8_t xid = rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id);   //Transaction_id,
-
 #ifdef CBA
   //struct PUSCH_CBAConfigDedicated_vlola  *pusch_CBAConfigDedicated_vlola;
   uint8_t                            *cba_RNTI_buf;
-  cba_RNTI = CALLOC(1, sizeof(C_RNTI_t));
+  cba_RNTI = CALLOC(1, sizeof(LTE_C_RNTI_t));
   cba_RNTI_buf = CALLOC(1, 2 * sizeof(uint8_t));
   cba_RNTI->buf = cba_RNTI_buf;
   cba_RNTI->size = 2;
@@ -3686,52 +3476,43 @@ flexran_rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt
   }
 
 #endif
-
   T(T_ENB_RRC_CONNECTION_RECONFIGURATION, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
     T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
-
   // Configure SRB2
   /// SRB2
   SRB_configList2=&ue_context_pP->ue_context.SRB_configList2[xid];
+
   if (*SRB_configList2) {
     free(*SRB_configList2);
   }
+
   *SRB_configList2 = CALLOC(1, sizeof(**SRB_configList2));
   memset(*SRB_configList2, 0, sizeof(**SRB_configList2));
   SRB2_config = CALLOC(1, sizeof(*SRB2_config));
-
   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 = SRB_ToAddMod__rlc_Config_PR_explicitValue;
-  SRB2_rlc_config->choice.explicitValue.present = RLC_Config_PR_am;
-  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = T_PollRetransmit_ms15;
-  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU = PollPDU_p8;
-  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte = PollByte_kB1000;
-  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = UL_AM_RLC__maxRetxThreshold_t32;
-  SRB2_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering = T_Reordering_ms35;
-  SRB2_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = T_StatusProhibit_ms10;
-
+  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 = SRB_ToAddMod__logicalChannelConfig_PR_explicitValue;
-
+  SRB2_lchan_config->present = LTE_SRB_ToAddMod__logicalChannelConfig_PR_explicitValue;
   SRB2_ul_SpecificParameters = CALLOC(1, sizeof(*SRB2_ul_SpecificParameters));
-
   SRB2_ul_SpecificParameters->priority = 3; // let some priority for SRB1 and dedicated DRBs
   SRB2_ul_SpecificParameters->prioritisedBitRate =
-    LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
+    LTE_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
   SRB2_ul_SpecificParameters->bucketSizeDuration =
-    LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
-
+    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;
   // this list has the configuration for SRB1 and SRB2
   ASN_SEQUENCE_ADD(&SRB_configList->list, SRB2_config);
@@ -3744,61 +3525,56 @@ flexran_rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt
   if (*DRB_configList) {
     free(*DRB_configList);
   }
+
   *DRB_configList = CALLOC(1, sizeof(**DRB_configList));
   memset(*DRB_configList, 0, sizeof(**DRB_configList));
-
   // list for the configured DRB for a this xid
   DRB_configList2=&ue_context_pP->ue_context.DRB_configList2[xid];
+
   if (*DRB_configList2) {
     free(*DRB_configList2);
   }
+
   *DRB_configList2 = CALLOC(1, sizeof(**DRB_configList2));
   memset(*DRB_configList2, 0, sizeof(**DRB_configList2));
-
-
   /// DRB
   DRB_config = CALLOC(1, sizeof(*DRB_config));
-
   DRB_config->eps_BearerIdentity = CALLOC(1, sizeof(long));
   *(DRB_config->eps_BearerIdentity) = 5L; // LW set to first value, allowed value 5..15, value : x+4
-  // DRB_config->drb_Identity = (DRB_Identity_t) 1; //allowed values 1..32
+  // 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 = (DRB_Identity_t) 1;  // (ue_mod_idP+1); //allowed values 1..32, value: x
+  DRB_config->drb_Identity = (LTE_DRB_Identity_t) 1;  // (ue_mod_idP+1); //allowed values 1..32, value: x
   DRB_config->logicalChannelIdentity = CALLOC(1, sizeof(long));
   *(DRB_config->logicalChannelIdentity) = (long)3; // value : x+2
   DRB_rlc_config = CALLOC(1, sizeof(*DRB_rlc_config));
   DRB_config->rlc_Config = DRB_rlc_config;
-
 #ifdef RRC_DEFAULT_RAB_IS_AM
-  DRB_rlc_config->present = RLC_Config_PR_am;
-  DRB_rlc_config->choice.am.ul_AM_RLC.t_PollRetransmit = T_PollRetransmit_ms50;
-  DRB_rlc_config->choice.am.ul_AM_RLC.pollPDU = PollPDU_p16;
-  DRB_rlc_config->choice.am.ul_AM_RLC.pollByte = PollByte_kBinfinity;
-  DRB_rlc_config->choice.am.ul_AM_RLC.maxRetxThreshold = UL_AM_RLC__maxRetxThreshold_t8;
-  DRB_rlc_config->choice.am.dl_AM_RLC.t_Reordering = T_Reordering_ms35;
-  DRB_rlc_config->choice.am.dl_AM_RLC.t_StatusProhibit = T_StatusProhibit_ms25;
+  DRB_rlc_config->present = LTE_RLC_Config_PR_am;
+  DRB_rlc_config->choice.am.ul_AM_RLC.t_PollRetransmit = LTE_T_PollRetransmit_ms50;
+  DRB_rlc_config->choice.am.ul_AM_RLC.pollPDU = LTE_PollPDU_p16;
+  DRB_rlc_config->choice.am.ul_AM_RLC.pollByte = LTE_PollByte_kBinfinity;
+  DRB_rlc_config->choice.am.ul_AM_RLC.maxRetxThreshold = LTE_UL_AM_RLC__maxRetxThreshold_t8;
+  DRB_rlc_config->choice.am.dl_AM_RLC.t_Reordering = LTE_T_Reordering_ms35;
+  DRB_rlc_config->choice.am.dl_AM_RLC.t_StatusProhibit = LTE_T_StatusProhibit_ms25;
 #else
-  DRB_rlc_config->present = RLC_Config_PR_um_Bi_Directional;
-  DRB_rlc_config->choice.um_Bi_Directional.ul_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
-  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
+  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;
 #ifdef CBA
-  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering   = T_Reordering_ms5;//T_Reordering_ms25;
+  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering   = LTE_T_Reordering_ms5;//T_Reordering_ms25;
 #else
-  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = T_Reordering_ms35;
+  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = LTE_T_Reordering_ms35;
 #endif
 #endif
-
   DRB_pdcp_config = CALLOC(1, sizeof(*DRB_pdcp_config));
   DRB_config->pdcp_Config = DRB_pdcp_config;
   DRB_pdcp_config->discardTimer = CALLOC(1, sizeof(long));
-  *DRB_pdcp_config->discardTimer = PDCP_Config__discardTimer_infinity;
+  *DRB_pdcp_config->discardTimer = LTE_PDCP_Config__discardTimer_infinity;
   DRB_pdcp_config->rlc_AM = NULL;
   DRB_pdcp_config->rlc_UM = NULL;
-
   /* avoid gcc warnings */
   (void)PDCP_rlc_AM;
   (void)PDCP_rlc_UM;
-
 #ifdef RRC_DEFAULT_RAB_IS_AM // EXMIMO_IOT
   PDCP_rlc_AM = CALLOC(1, sizeof(*PDCP_rlc_AM));
   DRB_pdcp_config->rlc_AM = PDCP_rlc_AM;
@@ -3806,62 +3582,47 @@ flexran_rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt
 #else
   PDCP_rlc_UM = CALLOC(1, sizeof(*PDCP_rlc_UM));
   DRB_pdcp_config->rlc_UM = PDCP_rlc_UM;
-  PDCP_rlc_UM->pdcp_SN_Size = PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits;
+  PDCP_rlc_UM->pdcp_SN_Size = LTE_PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits;
 #endif
-  DRB_pdcp_config->headerCompression.present = PDCP_Config__headerCompression_PR_notUsed;
-
+  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 = 12;    // lower priority than srb1, srb2 and other dedicated bearer
-  DRB_ul_SpecificParameters->prioritisedBitRate =LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_kBps8 ;
-    //LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
+  DRB_ul_SpecificParameters->prioritisedBitRate = LTE_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_kBps8 ;
+  //LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
   DRB_ul_SpecificParameters->bucketSizeDuration =
-    LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
-
+    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_configList)->list, DRB_config);
   ASN_SEQUENCE_ADD(&(*DRB_configList2)->list, DRB_config);
-
   //ue_context_pP->ue_context.DRB_configList2[0] = &(*DRB_configList);
-
   mac_MainConfig = CALLOC(1, sizeof(*mac_MainConfig));
-  // ue_context_pP->ue_context.mac_MainConfig = mac_MainConfig;
-
+  // ue_context_pP->ue_context.mac_MainConfig = LTE_MAC_MainConfig;
   mac_MainConfig->ul_SCH_Config = CALLOC(1, sizeof(*mac_MainConfig->ul_SCH_Config));
-
   maxHARQ_Tx = CALLOC(1, sizeof(long));
-  *maxHARQ_Tx = MAC_MainConfig__ul_SCH_Config__maxHARQ_Tx_n5;
+  *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 = PeriodicBSR_Timer_r12_sf64;
+  *periodicBSR_Timer = LTE_PeriodicBSR_Timer_r12_sf64;
   mac_MainConfig->ul_SCH_Config->periodicBSR_Timer = periodicBSR_Timer;
-  mac_MainConfig->ul_SCH_Config->retxBSR_Timer = RetxBSR_Timer_r12_sf320;
+  mac_MainConfig->ul_SCH_Config->retxBSR_Timer = LTE_RetxBSR_Timer_r12_sf320;
   mac_MainConfig->ul_SCH_Config->ttiBundling = 0; // FALSE
-
-  mac_MainConfig->timeAlignmentTimerDedicated = TimeAlignmentTimer_infinity;
-
+  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 = MAC_MainConfig__phr_Config_PR_setup;
-  mac_MainConfig->phr_Config->choice.setup.periodicPHR_Timer = MAC_MainConfig__phr_Config__setup__periodicPHR_Timer_sf20; // sf20 = 20 subframes
-
-  mac_MainConfig->phr_Config->choice.setup.prohibitPHR_Timer = MAC_MainConfig__phr_Config__setup__prohibitPHR_Timer_sf20; // sf20 = 20 subframes
-
-  mac_MainConfig->phr_Config->choice.setup.dl_PathlossChange = MAC_MainConfig__phr_Config__setup__dl_PathlossChange_dB1;  // Value dB1 =1 dB, dB3 = 3 dB
-
-#ifdef Rel10
+  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(10, 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 MAC_MainConfig__ext1));
+  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
@@ -3871,274 +3632,233 @@ flexran_rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt
   //TODO: change TM for secondary CC in SCelltoaddmodlist
   if (*physicalConfigDedicated) {
     if ((*physicalConfigDedicated)->antennaInfo) {
-      (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.transmissionMode = rrc_inst->configuration.ue_TransmissionMode[0];
-      LOG_D(RRC,"Setting transmission mode to %ld+1\n",rrc_inst->configuration.ue_TransmissionMode[0]);
-      if (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm3) {
-  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=     
-    CALLOC(1,sizeof(AntennaInfoDedicated__codebookSubsetRestriction_PR));
-  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
-    AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm3;
-  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.buf= MALLOC(1);
-  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.buf[0] = 0xc0;
-  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.size=1;
-  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.bits_unused=6;
+      (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.transmissionMode = rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode;
+      LOG_D(RRC,"Setting transmission mode to %ld+1\n",rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode);
+      if (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm3) {
+	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=
+	  CALLOC(1,sizeof(LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR));
+	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
+	  LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm3;
+	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.buf= MALLOC(1);
+	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.buf[0] = 0xc0;
+	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.size=1;
+	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.bits_unused=6;
+      } else if (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm4) {
+	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=
+	  CALLOC(1,sizeof(LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR));
+	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
+	  LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm4;
+	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.buf= MALLOC(1);
+	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.buf[0] = 0xfc;
+	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.size=1;
+	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.bits_unused=2;
       }
-      else if (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm4) {
-  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=     
-    CALLOC(1,sizeof(AntennaInfoDedicated__codebookSubsetRestriction_PR));
-  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
-    AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm4;
-  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.buf= MALLOC(1);
-  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.buf[0] = 0xfc;
-  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.size=1;
-  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.bits_unused=2;
+      else if (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm5) {
 
+	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=
+	  CALLOC(1,sizeof(LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR));
+	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
+	  LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm5;
+	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.buf= MALLOC(1);
+	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.buf[0] = 0xf0;
+	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.size=1;
+	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.bits_unused=4;
       }
-      else if (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm5) {
-  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=     
-    CALLOC(1,sizeof(AntennaInfoDedicated__codebookSubsetRestriction_PR));
-  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
-    AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm5;
-  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.buf= MALLOC(1);
-  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.buf[0] = 0xf0;
-  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.size=1;
-  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.bits_unused=4;
-      }
-      else if (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm6) {
-  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=     
-    CALLOC(1,sizeof(AntennaInfoDedicated__codebookSubsetRestriction_PR));
-  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
-    AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm6;
-  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.buf= MALLOC(1);
-  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.buf[0] = 0xf0;
-  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.size=1;
-  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.bits_unused=4;
+
+      else if (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm6) {
+	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=
+	  CALLOC(1,sizeof(LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR));
+	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
+	  LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm6;
+	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.buf= MALLOC(1);
+	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.buf[0] = 0xf0;
+	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.size=1;
+	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.bits_unused=4;
+
       }
     }
     else {
       LOG_E(RRC,"antenna_info not present in physical_config_dedicated. Not reconfiguring!\n");
     }
+
     if ((*physicalConfigDedicated)->cqi_ReportConfig) {
-      if ((rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm4) ||
-    (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm5) ||
-    (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm6)) {
-  //feedback mode needs to be set as well
-  //TODO: I think this is taken into account in the PHY automatically based on the transmission mode variable
-  printf("setting cqi reporting mode to rm31\n");
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-  *((*physicalConfigDedicated)->cqi_ReportConfig->cqi_ReportModeAperiodic)=CQI_ReportModeAperiodic_rm31;
+      if ((rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm4) ||
+	  (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm5) ||
+	  (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm6)) {
+
+	//feedback mode needs to be set as well
+	//TODO: I think this is taken into account in the PHY automatically based on the transmission mode variable
+	printf("setting cqi reporting mode to rm31\n");
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+        *((*physicalConfigDedicated)->cqi_ReportConfig->cqi_ReportModeAperiodic)=LTE_CQI_ReportModeAperiodic_rm31;
 #else
-  *((*physicalConfigDedicated)->cqi_ReportConfig->cqi_ReportModeAperiodic)=CQI_ReportConfig__cqi_ReportModeAperiodic_rm31; // HLC CQI, no PMI
+        *((*physicalConfigDedicated)->cqi_ReportConfig->cqi_ReportModeAperiodic)=LTE_CQI_ReportConfig__cqi_ReportModeAperiodic_rm31; // HLC CQI, no PMI
 #endif
       }
-    }
-    else {
+    } else {
       LOG_E(RRC,"cqi_ReportConfig not present in physical_config_dedicated. Not reconfiguring!\n");
     }
-  }
-  else {
-    LOG_E(RRC,"physical_config_dedicated not present in RRCConnectionReconfiguration. Not reconfiguring!\n");
+  } else {
+    LOG_E(RRC,"physical_config_dedicated not present in LTE_RRCConnectionReconfiguration. Not reconfiguring!\n");
   }
 
   // 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);
-
   /*
    * Add one EUTRA Measurement Object
   */
-
   MeasObj_list = CALLOC(1, sizeof(*MeasObj_list));
   memset((void *)MeasObj_list, 0, sizeof(*MeasObj_list));
-
-  // Configure MeasObject 
-
+  // Configure MeasObject
   MeasObj = CALLOC(1, sizeof(*MeasObj));
   memset((void *)MeasObj, 0, sizeof(*MeasObj));
-
   MeasObj->measObjectId = 1;
-  MeasObj->measObject.present = MeasObjectToAddMod__measObject_PR_measObjectEUTRA;
+  MeasObj->measObject.present = LTE_MeasObjectToAddMod__measObject_PR_measObjectEUTRA;
   MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 3350; //band 7, 2.68GHz
   //MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 36090; //band 33, 1.909GHz
-  MeasObj->measObject.choice.measObjectEUTRA.allowedMeasBandwidth = AllowedMeasBandwidth_mbw25;
+  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 =
-    (CellsToAddModList_t *) CALLOC(1, sizeof(*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 = (CellsToAddMod_t *) CALLOC(1, sizeof(*CellToAdd));
+    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 = Q_OffsetRange_dB0;
-
+    CellToAdd->cellIndividualOffset = LTE_Q_OffsetRange_dB0;
     ASN_SEQUENCE_ADD(&CellsToAddModList->list, CellToAdd);
   }
 
   ASN_SEQUENCE_ADD(&MeasObj_list->list, MeasObj);
-  //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measObjectToAddModList = MeasObj_list;
+  //  LTE_RRCConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measObjectToAddModList = MeasObj_list;
 
   // Report Configurations for periodical, A1-A5 events
 
   /* RRC Strategy Measurement */
 
-
-  if (strcmp("one_shot", trig_param->trigger_policy) == 0){
-
-      trig_param->report_interval = 0;
-      trig_param->report_amount = 0;
-
+  if (strcmp("one_shot", trig_param->trigger_policy) == 0) {
+    trig_param->report_interval = 0;
+    trig_param->report_amount = 0;
+  } else if (strcmp("event_driven", trig_param->trigger_policy) == 0) {
+    trig_param->report_interval = 6;
+    trig_param->report_amount = 2;
+  } else if (strcmp("periodical", trig_param->trigger_policy) == 0) {
+    trig_param->report_interval = 1;
+    trig_param->report_amount = 7;
+  } else {
+    LOG_E(FLEXRAN_AGENT, "There is something wrong on RRC agent!");
   }
 
-  else if (strcmp("event_driven", trig_param->trigger_policy) == 0){
+  ReportConfig_list = CALLOC(1, sizeof(*ReportConfig_list));
+  ReportConfig_per = CALLOC(1, sizeof(*ReportConfig_per));
+  // Periodical Measurement Report
+  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.triggerType.choice.event.timeToTrigger = TimeToTrigger_ms40;
+  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 = trig_param->report_interval ;//ReportInterval_ms2048; // RRC counter frame- ms1024 is 1ms
+  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportAmount = trig_param->report_amount; //ReportConfigEUTRA__reportAmount_r2; // put r1 to see once, r2 for 2 times and ...
+  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_per);
+  quantityConfig = CALLOC(1, sizeof(*quantityConfig));
+  memset((void *)quantityConfig, 0, sizeof(*quantityConfig));
+  quantityConfig->quantityConfigEUTRA = CALLOC(1, sizeof(struct LTE_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;
+#if defined(ENABLE_ITTI)
+  /* Initialize NAS list */
+  dedicatedInfoNASList = CALLOC(1, sizeof(struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));
 
-      trig_param->report_interval = 6;
-      trig_param->report_amount = 2;
+  /* Add all NAS PDUs to the list */
+  for (i = 0; i < ue_context_pP->ue_context.nb_of_e_rabs; i++) {
+    if (ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer != NULL) {
+      dedicatedInfoNas = CALLOC(1, sizeof(LTE_DedicatedInfoNAS_t));
+      memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t));
+      OCTET_STRING_fromBuf(dedicatedInfoNas,
+                           (char *)ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer,
+                           ue_context_pP->ue_context.e_rab[i].param.nas_pdu.length);
+      ASN_SEQUENCE_ADD(&dedicatedInfoNASList->list, dedicatedInfoNas);
+    }
 
+    /* TODO parameters yet to process ... */
+    // {
+    //      ue_context_pP->ue_context.e_rab[i].param.qos;
+    //      ue_context_pP->ue_context.e_rab[i].param.sgw_addr;
+    //      ue_context_pP->ue_context.e_rab[i].param.gtp_teid;
+    // }
+    /* TODO should test if e RAB are Ok before! */
+    ue_context_pP->ue_context.e_rab[i].status = E_RAB_STATUS_DONE;
+    LOG_D(RRC, "setting the status for the default DRB (index %d) to (%d,%s)\n",
+          i, ue_context_pP->ue_context.e_rab[i].status, "E_RAB_STATUS_DONE");
   }
 
-  else if (strcmp("periodical", trig_param->trigger_policy) == 0){
-
-      trig_param->report_interval = 1;
-      trig_param->report_amount = 7;
-
+  /* If list is empty free the list and reset the address */
+  if (dedicatedInfoNASList->list.count == 0) {
+    free(dedicatedInfoNASList);
+    dedicatedInfoNASList = NULL;
   }
 
-  else {
-
-     LOG_E(FLEXRAN_AGENT, "There is something wrong on RRC agent!");
-  }
-
-
-
-  ReportConfig_list = CALLOC(1, sizeof(*ReportConfig_list));
-
-  ReportConfig_per = CALLOC(1, sizeof(*ReportConfig_per));
-
-    // Periodical Measurement Report
-
-  ReportConfig_per->reportConfigId = 1;
-  ReportConfig_per->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
-
-    ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.present =
-      ReportConfigEUTRA__triggerType_PR_periodical;
-
-    ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.choice.periodical.purpose =
-      ReportConfigEUTRA__triggerType__periodical__purpose_reportStrongestCells;
-
-    // ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.timeToTrigger = TimeToTrigger_ms40;  
-    ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerQuantity = ReportConfigEUTRA__triggerQuantity_rsrp;
-   ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
-   ReportConfig_per->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
-   ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportInterval = trig_param->report_interval ;//ReportInterval_ms2048; // RRC counter frame- ms1024 is 1ms   
-
-   ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportAmount = trig_param->report_amount; //ReportConfigEUTRA__reportAmount_r2; // put r1 to see once, r2 for 2 times and ...
-
-
-  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_per);
-
-
-
-    quantityConfig = CALLOC(1, sizeof(*quantityConfig));
-    memset((void *)quantityConfig, 0, sizeof(*quantityConfig));
-    quantityConfig->quantityConfigEUTRA = CALLOC(1, sizeof(struct 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 = FilterCoefficient_fc4;
-    *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ = FilterCoefficient_fc4;
-
-  
-#if defined(ENABLE_ITTI)
-  /* Initialize NAS list */
-  dedicatedInfoNASList = CALLOC(1, sizeof(struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));
-
-  /* Add all NAS PDUs to the list */
-  for (i = 0; i < ue_context_pP->ue_context.nb_of_e_rabs; i++) {
-    if (ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer != NULL) {
-      dedicatedInfoNas = CALLOC(1, sizeof(DedicatedInfoNAS_t));
-      memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t));
-      OCTET_STRING_fromBuf(dedicatedInfoNas, 
-         (char*)ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer,
-                           ue_context_pP->ue_context.e_rab[i].param.nas_pdu.length);
-      ASN_SEQUENCE_ADD(&dedicatedInfoNASList->list, dedicatedInfoNas);
-    }
-
-    /* TODO parameters yet to process ... */
-    // {
-      //      ue_context_pP->ue_context.e_rab[i].param.qos;
-      //      ue_context_pP->ue_context.e_rab[i].param.sgw_addr;
-      //      ue_context_pP->ue_context.e_rab[i].param.gtp_teid;
-    // }
-
-    /* TODO should test if e RAB are Ok before! */
-    ue_context_pP->ue_context.e_rab[i].status = E_RAB_STATUS_DONE;
-    LOG_D(RRC, "setting the status for the default DRB (index %d) to (%d,%s)\n", 
-    i, ue_context_pP->ue_context.e_rab[i].status, "E_RAB_STATUS_DONE");
-  }
-
-  /* If list is empty free the list and reset the address */
-  if (dedicatedInfoNASList->list.count == 0) {
-    free(dedicatedInfoNASList);
-    dedicatedInfoNASList = NULL;
-  }
-
-#endif
-
-  memset(buffer, 0, RRC_BUF_SIZE);
-  
-  size = do_RRCConnectionReconfiguration(ctxt_pP,
-                                         buffer,
-                                         xid,   //Transaction_id,
-                                         (SRB_ToAddModList_t*)NULL, // SRB_configList
-                                         (DRB_ToAddModList_t*)NULL,
-                                         (DRB_ToReleaseList_t*)NULL,  // DRB2_list,
-                                         (struct SPS_Config*)NULL,    // *sps_Config,
-                                         (struct PhysicalConfigDedicated*)*physicalConfigDedicated,
-// #ifdef EXMIMO_IOT
-//                                          NULL, NULL, NULL,NULL,
-// #else
-                                         (MeasObjectToAddModList_t*)MeasObj_list,
-                                         (ReportConfigToAddModList_t*)ReportConfig_list,
-                                         (QuantityConfig_t*)quantityConfig,
-                                         (MeasIdToAddModList_t*)MeasId_list,
-// #endif
-                                         (MAC_MainConfig_t*)mac_MainConfig,
-                                         (MeasGapConfig_t*)NULL,
-                                         (MobilityControlInfo_t*)NULL,
-                                         (struct MeasConfig__speedStatePars*)Sparams,
-                                         (RSRP_Range_t*)rsrp,
-                                         (C_RNTI_t*)cba_RNTI,
-                                         (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList*)dedicatedInfoNASList,
-                                         (SL_CommConfig_r12_t*)NULL,
-                                         (SL_DiscConfig_r12_t*)NULL
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-                                         , (SCellToAddMod_r10_t*)NULL
-#endif
-                                        );
-  LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,size,
-              "[MSG] RRC Connection Reconfiguration\n");
-
-#if defined(ENABLE_ITTI)
+#endif
+  memset(buffer, 0, RRC_BUF_SIZE);
+  size = do_RRCConnectionReconfiguration(ctxt_pP,
+                                         buffer,
+                                         xid,   //Transaction_id,
+                                         (LTE_SRB_ToAddModList_t *)NULL, // SRB_configList
+                                         (LTE_DRB_ToAddModList_t *)NULL,
+                                         (LTE_DRB_ToReleaseList_t *)NULL, // DRB2_list,
+                                         (struct LTE_SPS_Config *)NULL,   // *sps_Config,
+                                         (struct LTE_PhysicalConfigDedicated *)*physicalConfigDedicated,
+                                         // #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,
+                                         // #endif
+                                         (LTE_MAC_MainConfig_t *)mac_MainConfig,
+                                         (LTE_MeasGapConfig_t *)NULL,
+                                         (LTE_MobilityControlInfo_t *)NULL,
+                                         (LTE_SecurityConfigHO_t *)NULL,
+                                         (struct LTE_MeasConfig__speedStatePars *)Sparams,
+                                         (LTE_RSRP_Range_t *)rsrp,
+                                         (LTE_C_RNTI_t *)cba_RNTI,
+                                         (struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *)dedicatedInfoNASList,
+                                         (LTE_SL_CommConfig_r12_t *)NULL,
+                                         (LTE_SL_DiscConfig_r12_t *)NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                                         , (LTE_SCellToAddMod_r10_t *)NULL
+#endif
+                                        );
+  LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,size,
+              "[MSG] RRC Connection Reconfiguration\n");
+#if defined(ENABLE_ITTI)
 
   /* Free all NAS PDUs */
   for (i = 0; i < ue_context_pP->ue_context.nb_of_e_rabs; i++) {
@@ -4150,51 +3870,45 @@ flexran_rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt
   }
 
 #endif
-
   LOG_I(RRC,
-        "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration (bytes %d, UE id %x)\n",
+        "[eNB %d] Frame %d, 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",
         ctxt_pP->frame, ctxt_pP->module_id, size, ue_context_pP->ue_context.rnti, rrc_eNB_mui, ctxt_pP->module_id, DCCH);
-
   MSC_LOG_TX_MESSAGE(
     MSC_RRC_ENB,
     MSC_RRC_UE,
     buffer,
     size,
-    MSC_AS_TIME_FMT" rrcConnectionReconfiguration UE %x MUI %d size %u",
+    MSC_AS_TIME_FMT" LTE_RRCConnectionReconfiguration UE %x MUI %d size %u",
     MSC_AS_TIME_ARGS(ctxt_pP),
     ue_context_pP->ue_context.rnti,
     rrc_eNB_mui,
     size);
-
   rrc_data_req(
-         ctxt_pP,
-         DCCH,
-         rrc_eNB_mui++,
-         SDU_CONFIRM_NO,
-         size,
-         buffer,
-         PDCP_TRANSMISSION_MODE_CONTROL);
+    ctxt_pP,
+    DCCH,
+    rrc_eNB_mui++,
+    SDU_CONFIRM_NO,
+    size,
+    buffer,
+    PDCP_TRANSMISSION_MODE_CONTROL);
 }
 
 
 //-----------------------------------------------------------------------------
 int
 rrc_eNB_generate_RRCConnectionReconfiguration_SCell(
-  const protocol_ctxt_t* const ctxt_pP,
-  rrc_eNB_ue_context_t* const ue_context_pP,
+  const protocol_ctxt_t *const ctxt_pP,
+  rrc_eNB_ue_context_t *const ue_context_pP,
   uint32_t dl_CarrierFreq_r10
 )
 //-----------------------------------------------------------------------------
 {
-
   uint8_t size;
   uint8_t buffer[100];
-
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
   uint8_t sCellIndexToAdd = 0; //one SCell so far
 
   //   uint8_t sCellIndexToAdd;
@@ -4211,51 +3925,49 @@ rrc_eNB_generate_RRCConnectionReconfiguration_SCell(
   size = do_RRCConnectionReconfiguration(ctxt_pP,
                                          buffer,
                                          rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),//Transaction_id,
-                                         (SRB_ToAddModList_t*)NULL,
-                                         (DRB_ToAddModList_t*)NULL,
-                                         (DRB_ToReleaseList_t*)NULL,
-                                         (struct SPS_Config*)NULL,
-                                         (struct PhysicalConfigDedicated*)NULL,
-                                         (MeasObjectToAddModList_t*)NULL,
-                                         (ReportConfigToAddModList_t*)NULL,
-                                         (QuantityConfig_t*)NULL,
-                                         (MeasIdToAddModList_t*)NULL,
-                                         (MAC_MainConfig_t*)NULL,
-                                         (MeasGapConfig_t*)NULL,
-                                         (MobilityControlInfo_t*)NULL,
-                                         (struct MeasConfig__speedStatePars*)NULL,
-                                         (RSRP_Range_t*)NULL,
-                                         (C_RNTI_t*)NULL,
-                                         (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList*)NULL,
-                                         (SL_CommConfig_r12_t*)NULL,
-                                         (SL_DiscConfig_r12_t*)NULL
-
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                                         (LTE_SRB_ToAddModList_t *)NULL,
+                                         (LTE_DRB_ToAddModList_t *)NULL,
+                                         (LTE_DRB_ToReleaseList_t *)NULL,
+                                         (struct LTE_SPS_Config *)NULL,
+                                         (struct LTE_PhysicalConfigDedicated *)NULL,
+                                         (LTE_MeasObjectToAddModList_t *)NULL,
+                                         (LTE_ReportConfigToAddModList_t *)NULL,
+                                         (LTE_QuantityConfig_t *)NULL,
+                                         (LTE_MeasIdToAddModList_t *)NULL,
+                                         (LTE_MAC_MainConfig_t *)NULL,
+                                         (LTE_MeasGapConfig_t *)NULL,
+                                         (LTE_MobilityControlInfo_t *)NULL,
+                                         (LTE_SecurityConfigHO_t *)NULL,
+                                         (struct LTE_MeasConfig__speedStatePars *)NULL,
+                                         (LTE_RSRP_Range_t *)NULL,
+                                         (LTE_C_RNTI_t *)NULL,
+                                         (struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *)NULL,
+                                         (LTE_SL_CommConfig_r12_t *)NULL,
+                                         (LTE_SL_DiscConfig_r12_t *)NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
                                          , ue_context_pP->ue_context.sCell_config
 #endif
                                         );
-  LOG_I(RRC,"[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration (bytes %d, UE id %x)\n",
+  LOG_I(RRC,"[eNB %d] Frame %d, 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);
-
   MSC_LOG_TX_MESSAGE(
     MSC_RRC_ENB,
     MSC_RRC_UE,
     buffer,
     size,
-    MSC_AS_TIME_FMT" rrcConnectionReconfiguration UE %x MUI %d size %u",
+    MSC_AS_TIME_FMT" LTE_RRCConnectionReconfiguration UE %x MUI %d size %u",
     MSC_AS_TIME_ARGS(ctxt_pP),
     ue_context_pP->ue_context.rnti,
     rrc_eNB_mui,
     size);
-
   rrc_data_req(
-	       ctxt_pP,
-	       DCCH,
-	       rrc_eNB_mui++,
-	       SDU_CONFIRM_NO,
-	       size,
-	       buffer,
-	       PDCP_TRANSMISSION_MODE_CONTROL);
+    ctxt_pP,
+    DCCH,
+    rrc_eNB_mui++,
+    SDU_CONFIRM_NO,
+    size,
+    buffer,
+    PDCP_TRANSMISSION_MODE_CONTROL);
   return(0);
 }
 
@@ -4263,135 +3975,229 @@ rrc_eNB_generate_RRCConnectionReconfiguration_SCell(
 //-----------------------------------------------------------------------------
 void
 rrc_eNB_process_MeasurementReport(
-  const protocol_ctxt_t* const ctxt_pP,
-  rrc_eNB_ue_context_t*         ue_context_pP,
-  const MeasResults_t*   const measResults2
+  const protocol_ctxt_t *const ctxt_pP,
+  rrc_eNB_ue_context_t         *ue_context_pP,
+  const LTE_MeasResults_t   *const measResults2
 )
 //-----------------------------------------------------------------------------
 {
   int i=0;
   int neighboring_cells=-1;
-  
+  int ncell_index = 0;
+  long ncell_max = -150;
   T(T_ENB_RRC_MEASUREMENT_REPORT, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
     T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
 
   if (measResults2 == NULL )
     return;
-  
-  if (measResults2->measId > 0 ){
-     if (ue_context_pP->ue_context.measResults == NULL) {
-       ue_context_pP->ue_context.measResults = CALLOC(1, sizeof(MeasResults_t));
-     }
-     ue_context_pP->ue_context.measResults->measId=measResults2->measId; 
-     ue_context_pP->ue_context.measResults->measResultPCell.rsrpResult=measResults2->measResultPCell.rsrpResult;
-     ue_context_pP->ue_context.measResults->measResultPCell.rsrqResult=measResults2->measResultPCell.rsrqResult;
-     LOG_D(RRC, "[eNB %d]Frame %d: UE %x (Measurement Id %d): RSRP of Source %ld\n", ctxt_pP->module_id, ctxt_pP->frame, ctxt_pP->rnti, (int)measResults2->measId, ue_context_pP->ue_context.measResults->measResultPCell.rsrpResult-140);
-     LOG_D(RRC, "[eNB %d]Frame %d: UE %x (Measurement Id %d): RSRQ of Source %ld\n", ctxt_pP->module_id, ctxt_pP->frame, ctxt_pP->rnti, (int)measResults2->measId, ue_context_pP->ue_context.measResults->measResultPCell.rsrqResult/2 - 20);
-   }
-   if (measResults2->measResultNeighCells == NULL)
-     return;
-
-   if (measResults2->measResultNeighCells->choice.measResultListEUTRA.list.count > 0) {
-     neighboring_cells = measResults2->measResultNeighCells->choice.measResultListEUTRA.list.count;
-     
-     if (ue_context_pP->ue_context.measResults->measResultNeighCells == NULL) {
-       
-       ue_context_pP->ue_context.measResults->measResultNeighCells = CALLOC(1, sizeof(*measResults2->measResultNeighCells)*neighboring_cells);
-     }
-     ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.count = neighboring_cells;
-     for (i=0; i < neighboring_cells; i++){
-       memcpy (ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i],
-	       measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i],
-	       sizeof(MeasResultListEUTRA_t));
-       
-       LOG_D(RRC, "Physical Cell Id %d\n",
-	     (int)ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->physCellId);
-       LOG_D(RRC, "RSRP of Target %d\n",
-	     (int)*(ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrpResult));
-       LOG_D(RRC, "RSRQ of Target %d\n",
-	     (int)*(ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrqResult));
-     }
-   }
 
-// #if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+  if (measResults2->measId > 0 ) {
+    if (ue_context_pP->ue_context.measResults == NULL) {
+      ue_context_pP->ue_context.measResults = CALLOC(1, sizeof(LTE_MeasResults_t));
+    }
 
-  
-// #else
-  // LOG_I(RRC, "RSRP of Source %d\n", measResults2->measResultServCell.rsrpResult);
-  // LOG_I(RRC, "RSRQ of Source %d\n", measResults2->measResultServCell.rsrqResult);
-// #endif
-
-  // if (ue_context_pP->ue_context.handover_info->ho_prepare != 0xF0) {
-  //   rrc_eNB_generate_HandoverPreparationInformation(ctxt_pP,
-  //       ue_context_pP,
-  //       measResults2->measResultNeighCells->choice.
-  //       measResultListEUTRA.list.array[0]->physCellId);
-  // } else {
-  //   LOG_D(RRC, "[eNB %d] Frame %d: Ignoring MeasReport from UE %x as Handover is in progress... \n", ctxt_pP->module_id, ctxt_pP->frame,
-  //         ctxt_pP->rnti);
-  // }
-
-  //Look for IP address of the target eNB
-  //Send Handover Request -> target eNB
-  //Wait for Handover Acknowledgement <- target eNB
-  //Send Handover Command
-
-  //x2delay();
-  //    handover_request_x2(ue_mod_idP,enb_mod_idP,measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[0]->physCellId);
-
-  //    uint8_t buffer[100];
-  //    int size=rrc_eNB_generate_Handover_Command_TeNB(0,0,buffer);
-  //
-  //      send_check_message((char*)buffer,size);
-  //send_handover_command();
+    ue_context_pP->ue_context.measResults->measId=measResults2->measId;
+
+    switch (measResults2->measId) {
+      case 1:
+        LOG_D(RRC,"Periodic report at frame %d and subframe %d \n", ctxt_pP->frame, ctxt_pP->subframe);
+        break;
+
+      case 2:
+        LOG_D(RRC,"A1 event report (Serving becomes better than absolute threshold) at frame %d and subframe %d \n", ctxt_pP->frame, ctxt_pP->subframe);
+        break;
+
+      case 3:
+        LOG_D(RRC,"A2 event report (Serving becomes worse than absolute threshold) at frame %d and subframe %d \n", ctxt_pP->frame, ctxt_pP->subframe);
+        break;
+
+      case 4:
+        LOG_D(RRC,"A3 event report (Neighbour becomes amount of offset better than PCell) at frame %d and subframe %d \n", ctxt_pP->frame, ctxt_pP->subframe);
+        break;
+
+      case 5:
+        LOG_D(RRC,"A4 event report (Neighbour becomes better than absolute threshold) at frame %d and subframe %d \n", ctxt_pP->frame, ctxt_pP->subframe);
+        break;
+
+      case 6:
+        LOG_D(RRC,"A5 event report (PCell becomes worse than absolute threshold1 AND Neighbour becomes better than another absolute threshold2) at frame %d and subframe %d \n", ctxt_pP->frame,
+              ctxt_pP->subframe);
+        break;
+
+      default:
+        LOG_D(RRC,"Other event report frame %d and subframe %d \n", ctxt_pP->frame, ctxt_pP->subframe);
+        break;
+    }
+
+    ue_context_pP->ue_context.measResults->measResultPCell.rsrpResult=measResults2->measResultPCell.rsrpResult;
+    ue_context_pP->ue_context.measResults->measResultPCell.rsrqResult=measResults2->measResultPCell.rsrqResult;
+    LOG_D(RRC, "[eNB %d]Frame %d: UE %x (Measurement Id %d): RSRP of Source %ld\n", ctxt_pP->module_id, ctxt_pP->frame, ctxt_pP->rnti, (int)measResults2->measId,
+          ue_context_pP->ue_context.measResults->measResultPCell.rsrpResult-140);
+    LOG_D(RRC, "[eNB %d]Frame %d: UE %x (Measurement Id %d): RSRQ of Source %ld\n", ctxt_pP->module_id, ctxt_pP->frame, ctxt_pP->rnti, (int)measResults2->measId,
+          ue_context_pP->ue_context.measResults->measResultPCell.rsrqResult/2 - 20);
+  }
+
+  if (measResults2->measResultNeighCells == NULL)
+    return;
 
+  if (measResults2->measResultNeighCells->choice.measResultListEUTRA.list.count > 0) {
+    neighboring_cells = measResults2->measResultNeighCells->choice.measResultListEUTRA.list.count;
+
+    if (ue_context_pP->ue_context.measResults->measResultNeighCells == NULL) {
+      ue_context_pP->ue_context.measResults->measResultNeighCells = CALLOC(1, sizeof(*ue_context_pP->ue_context.measResults->measResultNeighCells));
+    }
+
+    for (i=0; i < neighboring_cells; i++) {
+      if (i>=ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.count) {
+        //printf("NeighCells number: %d \n", ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.count);
+        ASN_SEQUENCE_ADD(&ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list,measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i]);
+      }
+
+      ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->physCellId =
+        measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->physCellId;
+      ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrpResult =
+        measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrpResult;
+      ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrqResult =
+        measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrqResult;
+      LOG_D(RRC, "Physical Cell Id %d\n",
+            (int)ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->physCellId);
+      LOG_D(RRC, "RSRP of Target %ld\n",
+            (*ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrpResult)-140);
+      LOG_D(RRC, "RSRQ of Target %ld\n",
+            (*ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrqResult)/2 - 20);
+
+      if ( *measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrpResult >= ncell_max ) {
+        ncell_max = *measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrpResult;
+        ncell_index = i;
+      }
+
+      //LOG_D(RRC, "Physical Cell Id2 %d\n",
+      //(int)measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->physCellId);
+      //LOG_D(RRC, "RSRP of Target2 %ld\n",
+      //(*(measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->
+      //measResult.rsrpResult))-140);
+      //LOG_D(RRC, "RSRQ of Target2 %ld\n",
+      //(*(measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->
+      //measResult.rsrqResult))/2 - 20);
+    }
+  }
+
+  /* Decide whether to trigger HO or not */
+  if (!(measResults2->measId == 4))
+    return;
+
+  LOG_D(RRC, "A3 event is triggered...\n");
+
+  /* if the UE is not in handover mode, start handover procedure */
+  if (ue_context_pP->ue_context.Status != RRC_HO_EXECUTION) {
+    MessageDef      *msg;
+    LOG_I(RRC, "Send HO preparation message at frame %d and subframe %d \n", ctxt_pP->frame, ctxt_pP->subframe);
+    /* HO info struct may not be needed anymore */
+    ue_context_pP->ue_context.handover_info = CALLOC(1, sizeof(*(ue_context_pP->ue_context.handover_info)));
+    ue_context_pP->ue_context.Status = RRC_HO_EXECUTION;
+    ue_context_pP->ue_context.handover_info->state = HO_REQUEST;
+    /* HO Preparation message */
+    msg = itti_alloc_new_message(TASK_RRC_ENB, X2AP_HANDOVER_REQ);
+    rrc_eNB_generate_HandoverPreparationInformation(
+      ue_context_pP,
+      X2AP_HANDOVER_REQ(msg).rrc_buffer,
+      &X2AP_HANDOVER_REQ(msg).rrc_buffer_size);
+    X2AP_HANDOVER_REQ(msg).source_rnti = ctxt_pP->rnti;
+    X2AP_HANDOVER_REQ(msg).old_eNB_ue_x2ap_id = 0;
+    X2AP_HANDOVER_REQ(msg).target_physCellId = measResults2->measResultNeighCells->choice.
+        measResultListEUTRA.list.array[ncell_index]->physCellId;
+    X2AP_HANDOVER_REQ(msg).ue_gummei.mcc = ue_context_pP->ue_context.ue_gummei.mcc;
+    X2AP_HANDOVER_REQ(msg).ue_gummei.mnc = ue_context_pP->ue_context.ue_gummei.mnc;
+    X2AP_HANDOVER_REQ(msg).ue_gummei.mnc_len = ue_context_pP->ue_context.ue_gummei.mnc_len;
+    X2AP_HANDOVER_REQ(msg).ue_gummei.mme_code = ue_context_pP->ue_context.ue_gummei.mme_code;
+    X2AP_HANDOVER_REQ(msg).ue_gummei.mme_group_id = ue_context_pP->ue_context.ue_gummei.mme_group_id;
+    // Don't know how to get this ID?
+    X2AP_HANDOVER_REQ(msg).mme_ue_s1ap_id = ue_context_pP->ue_context.mme_ue_s1ap_id;
+    X2AP_HANDOVER_REQ(msg).security_capabilities = ue_context_pP->ue_context.security_capabilities;
+    memcpy (X2AP_HANDOVER_REQ(msg).kenb,
+            ue_context_pP->ue_context.kenb,
+            32);
+    X2AP_HANDOVER_REQ(msg).kenb_ncc = ue_context_pP->ue_context.kenb_ncc;
+    //X2AP_HANDOVER_REQ(msg).ue_ambr=ue_context_pP->ue_context.ue_ambr;
+    X2AP_HANDOVER_REQ(msg).nb_e_rabs_tobesetup = ue_context_pP->ue_context.setup_e_rabs;
+
+    for (int i=0; i<ue_context_pP->ue_context.setup_e_rabs; i++) {
+      X2AP_HANDOVER_REQ(msg).e_rabs_tobesetup[i].e_rab_id = ue_context_pP->ue_context.e_rab[i].param.e_rab_id;
+      X2AP_HANDOVER_REQ(msg).e_rabs_tobesetup[i].eNB_addr = ue_context_pP->ue_context.e_rab[i].param.sgw_addr;
+      X2AP_HANDOVER_REQ(msg).e_rabs_tobesetup[i].gtp_teid = ue_context_pP->ue_context.e_rab[i].param.gtp_teid;
+      X2AP_HANDOVER_REQ(msg).e_rab_param[i].qos.qci = ue_context_pP->ue_context.e_rab[i].param.qos.qci;
+      X2AP_HANDOVER_REQ(msg).e_rab_param[i].qos.allocation_retention_priority.priority_level = ue_context_pP->ue_context.e_rab[i].param.qos.allocation_retention_priority.priority_level;
+      X2AP_HANDOVER_REQ(msg).e_rab_param[i].qos.allocation_retention_priority.pre_emp_capability = ue_context_pP->ue_context.e_rab[i].param.qos.allocation_retention_priority.pre_emp_capability;
+      X2AP_HANDOVER_REQ(msg).e_rab_param[i].qos.allocation_retention_priority.pre_emp_vulnerability = ue_context_pP->ue_context.e_rab[i].param.qos.allocation_retention_priority.pre_emp_vulnerability;
+    }
+
+    /* TODO: don't do that, X2AP should find the target by itself */
+    //X2AP_HANDOVER_REQ(msg).target_mod_id = 0;
+    LOG_I(RRC,
+          "[eNB %d] Frame %d: potential handover preparation: store the information in an intermediate structure in case of failure\n",
+          ctxt_pP->module_id, ctxt_pP->frame);
+    itti_send_msg_to_task(TASK_X2AP, ENB_MODULE_ID_TO_INSTANCE(ctxt_pP->module_id), msg);
+  } else {
+    LOG_D(RRC, "[eNB %d] Frame %d: Ignoring MeasReport from UE %x as Handover is in progress... \n", ctxt_pP->module_id, ctxt_pP->frame,
+          ctxt_pP->rnti);
+  }
 }
 
 //-----------------------------------------------------------------------------
 void
 rrc_eNB_generate_HandoverPreparationInformation(
-  const protocol_ctxt_t* const ctxt_pP,
-  rrc_eNB_ue_context_t* const ue_context_pP,
-  PhysCellId_t                 targetPhyId
+  //const protocol_ctxt_t* const ctxt_pP,
+  rrc_eNB_ue_context_t *const ue_context_pP,
+  uint8_t                     *buffer,
+  int                          *_size
+) {
+  memset(buffer, 0, RRC_BUF_SIZE);
+  char *ho_buf = (char *) buffer;
+  int ho_size;
+  ho_size = do_HandoverPreparation(ho_buf, 1024, ue_context_pP->ue_context.UE_Capability, ue_context_pP->ue_context.UE_Capability_size);
+  *_size = ho_size;
+}
+
+#if 0
+//-----------------------------------------------------------------------------
+void
+rrc_eNB_generate_HandoverPreparationInformation(
+  const protocol_ctxt_t *const ctxt_pP,
+  rrc_eNB_ue_context_t *const ue_context_pP,
+  LTE_PhysCellId_t            targetPhyId
 )
 //-----------------------------------------------------------------------------
 {
-  struct rrc_eNB_ue_context_s*        ue_context_target_p = NULL;
+  struct rrc_eNB_ue_context_s        *ue_context_target_p = NULL;
   //uint8_t                             UE_id_target        = -1;
   uint8_t                             mod_id_target = get_adjacent_cell_mod_id(targetPhyId);
   HANDOVER_INFO                      *handoverInfo = CALLOC(1, sizeof(*handoverInfo));
   /*
      uint8_t buffer[100];
      uint8_t size;
-     struct PhysicalConfigDedicated  **physicalConfigDedicated = &RC.rrc[enb_mod_idP]->physicalConfigDedicated[ue_mod_idP];
+     struct LTE_PhysicalConfigDedicated  **physicalConfigDedicated = &RC.rrc[enb_mod_idP]->physicalConfigDedicated[ue_mod_idP];
      RadioResourceConfigDedicated_t *radioResourceConfigDedicated = CALLOC(1,sizeof(RadioResourceConfigDedicated_t));
    */
-
   T(T_ENB_RRC_HANDOVER_PREPARATION_INFORMATION, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
     T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
-
   handoverInfo->as_config.antennaInfoCommon.antennaPortsCount = 0;    //Not used 0- but check value
   handoverInfo->as_config.sourceDl_CarrierFreq = 36090;   //Verify!
-
   memcpy((void *)&handoverInfo->as_config.sourceMasterInformationBlock,
-         (void*)&RC.rrc[ctxt_pP->module_id]->carrier[0] /* CROUX TBC */.mib, sizeof(MasterInformationBlock_t));
+         (void *)&RC.rrc[ctxt_pP->module_id]->carrier[0] /* CROUX TBC */.mib, sizeof(LTE_MasterInformationBlock_t));
   memcpy((void *)&handoverInfo->as_config.sourceMeasConfig,
-         (void*)ue_context_pP->ue_context.measConfig, sizeof(MeasConfig_t));
-
+         (void *)ue_context_pP->ue_context.measConfig, sizeof(LTE_MeasConfig_t));
   // FIXME handoverInfo not used...
   free( handoverInfo );
   handoverInfo = 0;
-
   //to be configured
-  memset((void*)&ue_context_pP->ue_context.handover_info->as_config.sourceSecurityAlgorithmConfig,
-         0, sizeof(SecurityAlgorithmConfig_t));
-
-  memcpy((void*)&ue_context_pP->ue_context.handover_info->as_config.sourceSystemInformationBlockType1,
-         (void*)&RC.rrc[ctxt_pP->module_id]->carrier[0] /* CROUX TBC */.SIB1, sizeof(SystemInformationBlockType1_t));
-  memcpy((void*)&ue_context_pP->ue_context.handover_info->as_config.sourceSystemInformationBlockType2,
-         (void*)&RC.rrc[ctxt_pP->module_id]->carrier[0] /* CROUX TBC */.SIB23, sizeof(SystemInformationBlockType2_t));
+  memset((void *)&ue_context_pP->ue_context.handover_info->as_config.sourceSecurityAlgorithmConfig,
+         0, sizeof(LTE_SecurityAlgorithmConfig_t));
+  memcpy((void *)&ue_context_pP->ue_context.handover_info->as_config.sourceSystemInformationBlockType1,
+         (void *)&RC.rrc[ctxt_pP->module_id]->carrier[0] /* CROUX TBC */.SIB1, sizeof(LTE_SystemInformationBlockType1_t));
+  memcpy((void *)&ue_context_pP->ue_context.handover_info->as_config.sourceSystemInformationBlockType2,
+         (void *)&RC.rrc[ctxt_pP->module_id]->carrier[0] /* CROUX TBC */.SIB23, sizeof(LTE_SystemInformationBlockType2_t));
   ue_context_pP->ue_context.handover_info->as_context.reestablishmentInfo =
-    CALLOC(1, sizeof(ReestablishmentInfo_t));
+    CALLOC(1, sizeof(LTE_ReestablishmentInfo_t));
   ue_context_pP->ue_context.handover_info->as_context.reestablishmentInfo->sourcePhysCellId =
     RC.rrc[ctxt_pP->module_id]->carrier[0] /* CROUX TBC */.physCellId;
   ue_context_pP->ue_context.handover_info->as_context.reestablishmentInfo->targetCellShortMAC_I.buf = NULL;  // Check values later
@@ -4428,12 +4234,12 @@ rrc_eNB_generate_HandoverPreparationInformation(
             mod_id_target);
       ue_context_target_p->ue_context.handover_info =
         CALLOC(1, sizeof(*(ue_context_target_p->ue_context.handover_info)));
-      memcpy((void*)&ue_context_target_p->ue_context.handover_info->as_context,
-             (void*)&ue_context_pP->ue_context.handover_info->as_context,
-             sizeof(AS_Context_t));
-      memcpy((void*)&ue_context_target_p->ue_context.handover_info->as_config,
-             (void*)&ue_context_pP->ue_context.handover_info->as_config,
-             sizeof(AS_Config_t));
+      memcpy((void *)&ue_context_target_p->ue_context.handover_info->as_context,
+             (void *)&ue_context_pP->ue_context.handover_info->as_context,
+             sizeof(LTE_AS_Context_t));
+      memcpy((void *)&ue_context_target_p->ue_context.handover_info->as_config,
+             (void *)&ue_context_pP->ue_context.handover_info->as_config,
+             sizeof(LTE_AS_Config_t));
       ue_context_target_p->ue_context.handover_info->ho_prepare = 0x00;// 0xFF;
       ue_context_target_p->ue_context.handover_info->ho_complete = 0;
       ue_context_pP->ue_context.handover_info->modid_t = mod_id_target;
@@ -4442,30 +4248,167 @@ rrc_eNB_generate_HandoverPreparationInformation(
       ue_context_target_p->ue_context.handover_info->modid_t = mod_id_target;
       ue_context_target_p->ue_context.handover_info->modid_s = ctxt_pP->module_id;
       ue_context_target_p->ue_context.handover_info->ueid_t  = ue_context_target_p->ue_context.rnti;
-
     } else {
       LOG_E(RRC, "\nError in obtaining free UE id in target eNB %ld for handover \n", targetPhyId);
     }
-
   } else {
     LOG_E(RRC, "\nError in obtaining Module ID of target eNB for handover \n");
   }
 }
+#endif
+
+void rrc_eNB_process_handoverPreparationInformation(int mod_id, x2ap_handover_req_t *m) {
+  struct rrc_eNB_ue_context_s        *ue_context_target_p = NULL;
+  /* TODO: get proper UE rnti */
+  int rnti = taus() & 0xffff;
+  int i;
+  //global_rnti = rnti;
+  //HandoverPreparationInformation_t *ho = NULL;
+  //HandoverPreparationInformation_r8_IEs_t *ho_info;
+  //asn_dec_rval_t                      dec_rval;
+  ue_context_target_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti);
+
+  if (ue_context_target_p != NULL) {
+    LOG_E(RRC, "\nError in obtaining free UE id in target eNB for handover \n");
+    return;
+  }
+
+  ue_context_target_p = rrc_eNB_allocate_new_UE_context(RC.rrc[mod_id]);
+
+  if (ue_context_target_p == NULL) {
+    LOG_E(RRC, "Cannot create new UE context\n");
+    return;
+  }
+
+  ue_context_target_p->ue_id_rnti = rnti;
+  ue_context_target_p->ue_context.rnti = rnti;
+  RB_INSERT(rrc_ue_tree_s, &RC.rrc[mod_id]->rrc_ue_head, ue_context_target_p);
+  LOG_D(RRC, "eNB %d: Created new UE context uid %u\n", mod_id, ue_context_target_p->local_uid);
+  ue_context_target_p->ue_context.handover_info = CALLOC(1, sizeof(*(ue_context_target_p->ue_context.handover_info)));
+  //ue_context_target_p->ue_context.handover_info->source_x2id = m->source_x2id;
+  ue_context_target_p->ue_context.Status = RRC_HO_EXECUTION;
+  ue_context_target_p->ue_context.handover_info->state = HO_ACK;
+  /* TODO: remove this hack */
+  //ue_context_target_p->ue_context.handover_info->modid_t = mod_id;
+  ue_context_target_p->ue_context.handover_info->modid_t = m->target_mod_id;
+  //ue_context_target_p->ue_context.handover_info->modid_s = 1-mod_id;
+  //ue_context_target_p->ue_context.handover_info->ueid_s  = m->source_rnti;
+  memset (ue_context_target_p->ue_context.nh, 0, 32);
+  ue_context_target_p->ue_context.nh_ncc = -1;
+  memcpy (ue_context_target_p->ue_context.kenb, m->kenb, 32);
+  ue_context_target_p->ue_context.kenb_ncc = m->kenb_ncc;
+  ue_context_target_p->ue_context.security_capabilities.encryption_algorithms = m->security_capabilities.encryption_algorithms;
+  ue_context_target_p->ue_context.security_capabilities.integrity_algorithms = m->security_capabilities.integrity_algorithms;
+  /*
+  dec_rval = uper_decode(NULL,
+                         &asn_DEF_HandoverPreparationInformation,
+                         (void **)&ho,
+                         m->rrc_buffer,
+                         m->rrc_buffer_size, 0, 0);
+
+  if (dec_rval.code != RC_OK ||
+      ho->criticalExtensions.present != HandoverPreparationInformation__criticalExtensions_PR_c1 ||
+      ho->criticalExtensions.choice.c1.present != HandoverPreparationInformation__criticalExtensions__c1_PR_handoverPreparationInformation_r8) {
+    LOG_E(RRC, "could not decode Handover Preparation\n");
+    abort();
+  }
+
+  ho_info = &ho->criticalExtensions.choice.c1.choice.handoverPreparationInformation_r8;
+
+  if (ue_context_target_p->ue_context.UE_Capability) {
+    LOG_I(RRC, "freeing old UE capabilities for UE %x\n", rnti);
+    ASN_STRUCT_FREE(asn_DEF_UE_EUTRA_Capability,
+                    ue_context_target_p->ue_context.UE_Capability);
+    ue_context_target_p->ue_context.UE_Capability = 0;
+  }
+
+  dec_rval = uper_decode(NULL,
+                         &asn_DEF_UE_EUTRA_Capability,
+                         (void **)&ue_context_target_p->ue_context.UE_Capability,
+                         ho_info->ue_RadioAccessCapabilityInfo.list.array[0]->ueCapabilityRAT_Container.buf,
+                         ho_info->ue_RadioAccessCapabilityInfo.list.array[0]->ueCapabilityRAT_Container.size, 0, 0);
+
+  ue_context_target_p->ue_context.UE_Capability_size = ho_info->ue_RadioAccessCapabilityInfo.list.array[0]->ueCapabilityRAT_Container.size;
+
+  if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
+     xer_fprint(stdout, &asn_DEF_UE_EUTRA_Capability, ue_context_target_p->ue_context.UE_Capability);
+  }
+
+  if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) {
+      LOG_E(RRC, "Failed to decode UE capabilities (%zu bytes)\n", dec_rval.consumed);
+      ASN_STRUCT_FREE(asn_DEF_UE_EUTRA_Capability,
+                      ue_context_target_p->ue_context.UE_Capability);
+      ue_context_target_p->ue_context.UE_Capability = 0;
+  }
+  */
+  ue_context_target_p->ue_context.nb_of_e_rabs = m->nb_e_rabs_tobesetup;
+  ue_context_target_p->ue_context.setup_e_rabs = m->nb_e_rabs_tobesetup;
+  ue_context_target_p->ue_context.mme_ue_s1ap_id = m->mme_ue_s1ap_id;
+  ue_context_target_p->ue_context.ue_gummei.mcc = m->ue_gummei.mcc;
+  ue_context_target_p->ue_context.ue_gummei.mnc = m->ue_gummei.mnc;
+  ue_context_target_p->ue_context.ue_gummei.mnc_len = m->ue_gummei.mnc_len;
+  ue_context_target_p->ue_context.ue_gummei.mme_code = m->ue_gummei.mme_code;
+  ue_context_target_p->ue_context.ue_gummei.mme_group_id = m->ue_gummei.mme_group_id;
+  LOG_I(RRC, "eNB %d: Update the E-RABS %u\n", mod_id, ue_context_target_p->ue_context.nb_of_e_rabs);
+
+  for (i = 0; i < ue_context_target_p->ue_context.nb_of_e_rabs; i++) {
+    ue_context_target_p->ue_context.e_rab[i].status = E_RAB_STATUS_NEW;
+    ue_context_target_p->ue_context.e_rab[i].param.e_rab_id = m->e_rabs_tobesetup[i].e_rab_id;
+    ue_context_target_p->ue_context.e_rab[i].param.sgw_addr = m->e_rabs_tobesetup[i].eNB_addr;
+    ue_context_target_p->ue_context.e_rab[i].param.gtp_teid= m->e_rabs_tobesetup[i].gtp_teid;
+    LOG_I(RRC, "eNB %d: Update the UE context after HO, e_rab_id %u gtp_teid %u\n", mod_id,
+          ue_context_target_p->ue_context.e_rab[i].param.e_rab_id,
+          ue_context_target_p->ue_context.e_rab[i].param.gtp_teid);
+  }
+}
+
+void rrc_eNB_process_handoverCommand(
+  int                         mod_id,
+  struct rrc_eNB_ue_context_s *ue_context,
+  x2ap_handover_req_ack_t     *m) {
+  asn_dec_rval_t dec_rval;
+  LTE_HandoverCommand_t *ho = NULL;
+  dec_rval = uper_decode(
+               NULL,
+               &asn_DEF_LTE_HandoverCommand,
+               (void **)&ho,
+               m->rrc_buffer,
+               m->rrc_buffer_size,
+               0,
+               0);
+
+  if (dec_rval.code != RC_OK ||
+      ho->criticalExtensions.present != LTE_HandoverCommand__criticalExtensions_PR_c1 ||
+      ho->criticalExtensions.choice.c1.present != LTE_HandoverCommand__criticalExtensions__c1_PR_handoverCommand_r8) {
+    LOG_E(RRC, "could not decode Handover Command\n");
+    abort();
+  }
+
+  unsigned char *buf = ho->criticalExtensions.choice.c1.choice.handoverCommand_r8.handoverCommandMessage.buf;
+  int size = ho->criticalExtensions.choice.c1.choice.handoverCommand_r8.handoverCommandMessage.size;
+
+  if (size > RRC_BUF_SIZE) {
+    printf("%s:%d: fatal\n", __FILE__, __LINE__);
+    abort();
+  }
+
+  memcpy(ue_context->ue_context.handover_info->buf, buf, size);
+  ue_context->ue_context.handover_info->size = size;
+}
 
+#if 0
 //-----------------------------------------------------------------------------
 void
 rrc_eNB_process_handoverPreparationInformation(
-  const protocol_ctxt_t* const ctxt_pP,
-  rrc_eNB_ue_context_t*           const ue_context_pP
+  const protocol_ctxt_t *const ctxt_pP,
+  rrc_eNB_ue_context_t           *const ue_context_pP
 )
 //-----------------------------------------------------------------------------
 {
   T(T_ENB_RRC_HANDOVER_PREPARATION_INFORMATION, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
     T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
-
-
   LOG_I(RRC,
-        "[eNB %d] Frame %d : Logical Channel UL-DCCH, processing RRCHandoverPreparationInformation, sending RRCConnectionReconfiguration to UE %d \n",
+        "[eNB %d] Frame %d : Logical Channel UL-DCCH, processing RRCHandoverPreparationInformation, sending LTE_RRCConnectionReconfiguration to UE %d \n",
         ctxt_pP->module_id, ctxt_pP->frame, ue_context_pP->ue_context.rnti);
   rrc_eNB_generate_RRCConnectionReconfiguration_handover(
     ctxt_pP,
@@ -4473,17 +4416,85 @@ rrc_eNB_process_handoverPreparationInformation(
     NULL,
     0);
 }
+#endif
+
+void
+check_handovers(
+  protocol_ctxt_t *const ctxt_pP
+)
+//-----------------------------------------------------------------------------
+{
+  int                                 result;
+  struct rrc_eNB_ue_context_s        *ue_context_p;
+  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;
+
+    if (ue_context_p->ue_context.Status == RRC_HO_EXECUTION && ue_context_p->ue_context.handover_info != NULL) {
+      /* in the source, UE in HO_PREPARE mode */
+      if (ue_context_p->ue_context.handover_info->state == HO_PREPARE) {
+        LOG_D(RRC,
+              "[eNB %d] Frame %d: Incoming handover detected for new UE_id %x) \n",
+              ctxt_pP->module_id,
+              ctxt_pP->frame,
+              ctxt_pP->rnti);
+        // source eNB generates rrcconnectionreconfiguration to prepare the HO
+        LOG_I(RRC,
+              "[eNB %d] Frame %d : Logical Channel UL-DCCH, processing RRCHandoverPreparationInformation, sending RRCConnectionReconfiguration to UE %d \n",
+              ctxt_pP->module_id, ctxt_pP->frame, ue_context_p->ue_context.rnti);
+        result = pdcp_data_req(ctxt_pP,
+                               SRB_FLAG_YES,
+                               DCCH,
+                               rrc_eNB_mui++,
+                               SDU_CONFIRM_NO,
+                               ue_context_p->ue_context.handover_info->size,
+                               ue_context_p->ue_context.handover_info->buf,
+                               PDCP_TRANSMISSION_MODE_CONTROL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                               ,NULL, NULL
+#endif
+                              );
+        AssertFatal(result == TRUE, "PDCP data request failed!\n");
+        ue_context_p->ue_context.handover_info->state = HO_COMPLETE;
+        LOG_I(RRC, "RRC Sends RRCConnectionReconfiguration to UE %d  at frame %d and subframe %d \n", ue_context_p->ue_context.rnti, ctxt_pP->frame,ctxt_pP->subframe);
+      }
 
+      /* in the target, UE in HO_ACK mode */
+      if (ue_context_p->ue_context.handover_info->state == HO_ACK) {
+        MessageDef *msg;
+        // Configure target
+        ue_context_p->ue_context.handover_info->state = HO_CONFIGURED;
+        msg = itti_alloc_new_message(TASK_RRC_ENB, X2AP_HANDOVER_REQ_ACK);
+        rrc_eNB_generate_HO_RRCConnectionReconfiguration(ctxt_pP, ue_context_p, X2AP_HANDOVER_REQ_ACK(msg).rrc_buffer,
+            &X2AP_HANDOVER_REQ_ACK(msg).rrc_buffer_size);
+        rrc_eNB_configure_rbs_handover(ue_context_p,ctxt_pP);
+        /* TODO: remove this hack */
+        //X2AP_HANDOVER_REQ_ACK(msg).target_mod_id = 1 - ctxt_pP->module_id;
+        X2AP_HANDOVER_REQ_ACK(msg).target_mod_id = ue_context_p->ue_context.handover_info->modid_t;
+        //X2AP_HANDOVER_REQ_ACK(msg).source_x2id = ue_context_p->ue_context.handover_info->source_x2id;
+        /* Call admission control not implemented yet */
+        X2AP_HANDOVER_REQ_ACK(msg).nb_e_rabs_tobesetup = ue_context_p->ue_context.setup_e_rabs;
+
+        for (int i=0; i<ue_context_p->ue_context.setup_e_rabs; i++) {
+          X2AP_HANDOVER_REQ_ACK(msg).e_rabs_tobesetup[i].e_rab_id = ue_context_p->ue_context.e_rab[i].param.e_rab_id;
+        }
+
+        itti_send_msg_to_task(TASK_X2AP, ENB_MODULE_ID_TO_INSTANCE(ctxt_pP->module_id), msg);
+        LOG_I(RRC, "RRC Sends X2 HO ACK to the source eNB at frame %d and subframe %d \n", ctxt_pP->frame,ctxt_pP->subframe);
+      }
+    }
+  }
+}
 
+#if 0
 //-----------------------------------------------------------------------------
 void
 check_handovers(
-  protocol_ctxt_t* const ctxt_pP
+  protocol_ctxt_t *const ctxt_pP
 )
 //-----------------------------------------------------------------------------
 {
   int                                 result;
-  struct rrc_eNB_ue_context_s*        ue_context_p;
+  struct rrc_eNB_ue_context_s        *ue_context_p;
   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;
 
@@ -4496,7 +4507,7 @@ check_handovers(
               ctxt_pP->rnti,
               ctxt_pP->module_id,
               ue_context_p->ue_context.handover_info->modid_t);
-        // source eNB generates rrcconnectionreconfiguration to prepare the HO
+        // source eNB generates LTE_RRCConnectionreconfiguration to prepare the HO
         rrc_eNB_process_handoverPreparationInformation(
           ctxt_pP,
           ue_context_p);
@@ -4520,95 +4531,1078 @@ check_handovers(
                                ue_context_p->ue_context.handover_info->size,
                                ue_context_p->ue_context.handover_info->buf,
                                PDCP_TRANSMISSION_MODE_CONTROL
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                                ,NULL, NULL
 #endif
-                               );
+                              );
+
         //AssertFatal(result == TRUE, "PDCP data request failed!\n");
-        if(result != TRUE)
-        {
+        if(result != TRUE) {
           LOG_I(RRC, "PDCP data request failed!\n");
           return;
         }
+
         ue_context_p->ue_context.handover_info->ho_complete = 0xF2;
       }
     }
   }
 }
+#endif
 
-// 5.3.5.4 RRCConnectionReconfiguration including the mobilityControlInfo to prepare the UE handover
-//-----------------------------------------------------------------------------
 void
-rrc_eNB_generate_RRCConnectionReconfiguration_handover(
-  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_generate_HO_RRCConnectionReconfiguration(const protocol_ctxt_t *const ctxt_pP,
+    rrc_eNB_ue_context_t  *const ue_context_pP,
+    uint8_t               *buffer,
+    int                    *_size
+    //const uint8_t        ho_state
+                                                )
 //-----------------------------------------------------------------------------
 {
-  T(T_ENB_RRC_CONNECTION_RECONFIGURATION, 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];
+  uint16_t                            size;
   int                                 i;
   uint8_t                             rv[2];
-  uint16_t                            Idx;
   // configure SRB1/SRB2, PhysicalConfigDedicated, MAC_MainConfig for UE
-  eNB_RRC_INST*                       rrc_inst = RC.rrc[ctxt_pP->module_id];
-  struct PhysicalConfigDedicated**    physicalConfigDedicated = &ue_context_pP->ue_context.physicalConfigDedicated;
-
-  struct SRB_ToAddMod                *SRB2_config;
-  struct SRB_ToAddMod__rlc_Config    *SRB2_rlc_config;
-  struct SRB_ToAddMod__logicalChannelConfig *SRB2_lchan_config;
-  struct LogicalChannelConfig__ul_SpecificParameters *SRB2_ul_SpecificParameters;
-  LogicalChannelConfig_t             *SRB1_logicalChannelConfig = NULL;
-  SRB_ToAddModList_t*                 SRB_configList = ue_context_pP->ue_context.SRB_configList;    // not used in this context: may be removed
-  SRB_ToAddModList_t                 *SRB_configList2;
-
-  struct DRB_ToAddMod                *DRB_config;
-  struct RLC_Config                  *DRB_rlc_config;
-  struct PDCP_Config                 *DRB_pdcp_config;
-  struct PDCP_Config__rlc_UM         *PDCP_rlc_UM;
-  struct LogicalChannelConfig        *DRB_lchan_config;
-  struct LogicalChannelConfig__ul_SpecificParameters *DRB_ul_SpecificParameters;
-  DRB_ToAddModList_t                 *DRB_configList2;
-
-  MAC_MainConfig_t                   *mac_MainConfig;
-  MeasObjectToAddModList_t           *MeasObj_list;
-  MeasObjectToAddMod_t               *MeasObj;
-  ReportConfigToAddModList_t         *ReportConfig_list;
-  ReportConfigToAddMod_t             *ReportConfig_per, *ReportConfig_A1,
-                                     *ReportConfig_A2, *ReportConfig_A3, *ReportConfig_A4, *ReportConfig_A5;
-  MeasIdToAddModList_t               *MeasId_list;
-  MeasIdToAddMod_t                   *MeasId0, *MeasId1, *MeasId2, *MeasId3, *MeasId4, *MeasId5;
-  QuantityConfig_t                   *quantityConfig;
-  MobilityControlInfo_t              *mobilityInfo;
+  eNB_RRC_INST                       *rrc_inst = RC.rrc[ctxt_pP->module_id];
+  struct LTE_PhysicalConfigDedicated **physicalConfigDedicated = &ue_context_pP->ue_context.physicalConfigDedicated;
+  // phy config dedicated
+  LTE_PhysicalConfigDedicated_t      *physicalConfigDedicated2;
+  // srb 1: for HO
+  struct LTE_SRB_ToAddMod            *SRB1_config                      = NULL;
+  struct LTE_SRB_ToAddMod__rlc_Config *SRB1_rlc_config                 = NULL;
+  struct LTE_SRB_ToAddMod__logicalChannelConfig *SRB1_lchan_config     = NULL;
+  struct LTE_LogicalChannelConfig__ul_SpecificParameters
+    *SRB1_ul_SpecificParameters       = NULL;
+  struct LTE_SRB_ToAddMod            *SRB2_config                      = NULL;
+  struct LTE_SRB_ToAddMod__rlc_Config *SRB2_rlc_config                 = NULL;
+  struct LTE_SRB_ToAddMod__logicalChannelConfig *SRB2_lchan_config     = NULL;
+  struct LTE_LogicalChannelConfig__ul_SpecificParameters
+    *SRB2_ul_SpecificParameters       = NULL;
+  LTE_SRB_ToAddModList_t             *SRB_configList = ue_context_pP->ue_context.SRB_configList;
+  LTE_SRB_ToAddModList_t             **SRB_configList2                 = NULL;
+  struct LTE_DRB_ToAddMod            *DRB_config                       = NULL;
+  struct LTE_RLC_Config              *DRB_rlc_config                   = NULL;
+  struct LTE_PDCP_Config             *DRB_pdcp_config                  = NULL;
+  struct LTE_PDCP_Config__rlc_AM     *PDCP_rlc_AM                      = NULL;
+  struct LTE_PDCP_Config__rlc_UM     *PDCP_rlc_UM                      = NULL;
+  struct LTE_LogicalChannelConfig    *DRB_lchan_config                 = NULL;
+  struct LTE_LogicalChannelConfig__ul_SpecificParameters
+    *DRB_ul_SpecificParameters        = NULL;
+  LTE_DRB_ToAddModList_t            **DRB_configList = &ue_context_pP->ue_context.DRB_configList;
+  LTE_DRB_ToAddModList_t            **DRB_configList2 = NULL;
+  LTE_MAC_MainConfig_t               *mac_MainConfig                   = NULL;
+  LTE_MeasObjectToAddModList_t       *MeasObj_list                     = NULL;
+  LTE_MeasObjectToAddMod_t           *MeasObj                          = NULL;
+  LTE_ReportConfigToAddModList_t     *ReportConfig_list                = NULL;
+  LTE_ReportConfigToAddMod_t         *ReportConfig_per, *ReportConfig_A1,
+                                     *ReportConfig_A2, *ReportConfig_A3, *ReportConfig_A4, *ReportConfig_A5;
+  LTE_MeasIdToAddModList_t           *MeasId_list                      = NULL;
+  LTE_MeasIdToAddMod_t               *MeasId0, *MeasId1, *MeasId2, *MeasId3, *MeasId4, *MeasId5;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+  long                               *sr_ProhibitTimer_r9              = NULL;
+  //     uint8_t sCellIndexToAdd = rrc_find_free_SCell_index(enb_mod_idP, ue_mod_idP, 1);
+  //uint8_t                            sCellIndexToAdd = 0;
+#endif
+  long                               *logicalchannelgroup, *logicalchannelgroup_drb;
+  long                               *maxHARQ_Tx, *periodicBSR_Timer;
+  LTE_RSRP_Range_t                   *rsrp                             = NULL;
+  struct LTE_MeasConfig__speedStatePars *Sparams                       = NULL;
+  LTE_QuantityConfig_t               *quantityConfig                   = NULL;
+  LTE_MobilityControlInfo_t          *mobilityInfo                     = NULL;
+  LTE_SecurityConfigHO_t             *securityConfigHO                 = NULL;
+  //CellsToAddMod_t                    *CellToAdd                        = NULL;
+  //CellsToAddModList_t                *CellsToAddModList                = NULL;
+  struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
+  LTE_DedicatedInfoNAS_t             *dedicatedInfoNas                 = NULL;
+  /* for no gcc warnings */
+  (void)dedicatedInfoNas;
+  LTE_C_RNTI_t                       *cba_RNTI                         = NULL;
+  uint8_t xid = rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id);   //Transaction_id,
+#ifdef CBA
+  //struct PUSCH_CBAConfigDedicated_vlola  *pusch_CBAConfigDedicated_vlola;
+  uint8_t                            *cba_RNTI_buf;
+  cba_RNTI = CALLOC(1, sizeof(C_RNTI_t));
+  cba_RNTI_buf = CALLOC(1, 2 * sizeof(uint8_t));
+  cba_RNTI->buf = cba_RNTI_buf;
+  cba_RNTI->size = 2;
+  cba_RNTI->bits_unused = 0;
+
+  // associate UEs to the CBa groups as a function of their UE id
+  if (rrc_inst->num_active_cba_groups) {
+    cba_RNTI->buf[0] = rrc_inst->cba_rnti[ue_mod_idP % rrc_inst->num_active_cba_groups] & 0xff;
+    cba_RNTI->buf[1] = 0xff;
+    LOG_D(RRC,
+          "[eNB %d] Frame %d: cba_RNTI = %x in group %d is attribued to UE %d\n",
+          enb_mod_idP, frameP,
+          rrc_inst->cba_rnti[ue_mod_idP % rrc_inst->num_active_cba_groups],
+          ue_mod_idP % rrc_inst->num_active_cba_groups, ue_mod_idP);
+  } else {
+    cba_RNTI->buf[0] = 0x0;
+    cba_RNTI->buf[1] = 0x0;
+    LOG_D(RRC, "[eNB %d] Frame %d: no cba_RNTI is configured for UE %d\n", enb_mod_idP, frameP, ue_mod_idP);
+  }
+
+#endif
+  T(T_ENB_RRC_CONNECTION_RECONFIGURATION, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
+    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
+  rv[0] = (ue_context_pP->ue_context.rnti >> 8) & 255;
+  rv[1] = ue_context_pP->ue_context.rnti & 255;
+  LOG_I(RRC, "target UE rnti = %x (decimal: %d)\n", ue_context_pP->ue_context.rnti, ue_context_pP->ue_context.rnti);
+  LOG_D(RRC, "[eNB %d] Frame %d : handover preparation: add target eNB SRB1 and PHYConfigDedicated reconfiguration\n",
+        ctxt_pP->module_id, ctxt_pP->frame);
+
+  if (SRB_configList) {
+    free(SRB_configList);
+  }
+
+  SRB_configList = CALLOC(1, sizeof(*SRB_configList));
+  memset(SRB_configList, 0, 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_configList->list, SRB1_config);
+  ue_context_pP->ue_context.SRB_configList = SRB_configList;
+  // Configure SRB2
+  /// SRB2
+  SRB_configList2=&ue_context_pP->ue_context.SRB_configList2[xid];
+
+  if (*SRB_configList2) {
+    free(*SRB_configList2);
+  }
+
+  *SRB_configList2 = CALLOC(1, sizeof(**SRB_configList2));
+  memset(*SRB_configList2, 0, sizeof(**SRB_configList2));
+  SRB2_config = CALLOC(1, sizeof(*SRB2_config));
+  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 = 3; // let some priority for SRB1 and dedicated DRBs
+  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;
+  // this list has the configuration for SRB1 and SRB2
+  ASN_SEQUENCE_ADD(&SRB_configList->list, SRB2_config);
+  // this list has only the configuration for SRB2
+  ASN_SEQUENCE_ADD(&(*SRB_configList2)->list, SRB2_config);
+
+  // Configure DRB
+  //*DRB_configList = CALLOC(1, sizeof(*DRB_configList));
+  // list for all the configured DRB
+  if (*DRB_configList) {
+    free(*DRB_configList);
+  }
+
+  *DRB_configList = CALLOC(1, sizeof(**DRB_configList));
+  memset(*DRB_configList, 0, sizeof(**DRB_configList));
+  // list for the configured DRB for a this xid
+  DRB_configList2=&ue_context_pP->ue_context.DRB_configList2[xid];
+
+  if (*DRB_configList2) {
+    free(*DRB_configList2);
+  }
+
+  *DRB_configList2 = CALLOC(1, sizeof(**DRB_configList2));
+  memset(*DRB_configList2, 0, sizeof(**DRB_configList2));
+  /// DRB
+  DRB_config = CALLOC(1, sizeof(*DRB_config));
+  DRB_config->eps_BearerIdentity = CALLOC(1, sizeof(long));
+  *(DRB_config->eps_BearerIdentity) = 5L; // LW set to first value, allowed value 5..15, value : x+4
+  // DRB_config->drb_Identity = (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, value: x
+  DRB_config->logicalChannelIdentity = CALLOC(1, sizeof(long));
+  *(DRB_config->logicalChannelIdentity) = (long)3; // value : x+2
+  DRB_rlc_config = CALLOC(1, sizeof(*DRB_rlc_config));
+  DRB_config->rlc_Config = DRB_rlc_config;
+#ifdef RRC_DEFAULT_RAB_IS_AM
+  DRB_rlc_config->present = RLC_Config_PR_am;
+  DRB_rlc_config->choice.am.ul_AM_RLC.t_PollRetransmit = T_PollRetransmit_ms50;
+  DRB_rlc_config->choice.am.ul_AM_RLC.pollPDU = PollPDU_p16;
+  DRB_rlc_config->choice.am.ul_AM_RLC.pollByte = PollByte_kBinfinity;
+  DRB_rlc_config->choice.am.ul_AM_RLC.maxRetxThreshold = UL_AM_RLC__maxRetxThreshold_t8;
+  DRB_rlc_config->choice.am.dl_AM_RLC.t_Reordering = T_Reordering_ms35;
+  DRB_rlc_config->choice.am.dl_AM_RLC.t_StatusProhibit = T_StatusProhibit_ms25;
+#else
+  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;
+#ifdef CBA
+  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering   = LTE_T_Reordering_ms5;//T_Reordering_ms25;
+#else
+  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = LTE_T_Reordering_ms35;
+#endif
+#endif
+  DRB_pdcp_config = CALLOC(1, sizeof(*DRB_pdcp_config));
+  DRB_config->pdcp_Config = DRB_pdcp_config;
+  DRB_pdcp_config->discardTimer = CALLOC(1, sizeof(long));
+  *DRB_pdcp_config->discardTimer = LTE_PDCP_Config__discardTimer_infinity;
+  DRB_pdcp_config->rlc_AM = NULL;
+  DRB_pdcp_config->rlc_UM = NULL;
+  /* avoid gcc warnings */
+  (void)PDCP_rlc_AM;
+  (void)PDCP_rlc_UM;
+#ifdef RRC_DEFAULT_RAB_IS_AM // EXMIMO_IOT
+  PDCP_rlc_AM = CALLOC(1, sizeof(*PDCP_rlc_AM));
+  DRB_pdcp_config->rlc_AM = PDCP_rlc_AM;
+  PDCP_rlc_AM->statusReportRequired = FALSE;
+#else
+  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;
+#endif
+  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 = 12;    // lower priority than srb1, srb2 and other dedicated bearer
+  DRB_ul_SpecificParameters->prioritisedBitRate =LTE_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_kBps8 ;
+  //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_configList)->list, DRB_config);
+  ASN_SEQUENCE_ADD(&(*DRB_configList2)->list, DRB_config);
+  //ue_context_pP->ue_context.DRB_configList2[0] = &(*DRB_configList);
+  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->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_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
+
+  //change the transmission mode for the primary component carrier
+  //TODO: add codebook subset restriction here
+  //TODO: change TM for secondary CC in SCelltoaddmodlist
+  /// now reconfigure phy config dedicated
+  if (*physicalConfigDedicated) {
+    free(*physicalConfigDedicated);
+  }
+
+  //if (*physicalConfigDedicated) {
+  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 = NULL; //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;
+  //if ((*physicalConfigDedicated)->antennaInfo) {
+  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.transmissionMode = rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode;
+  LOG_D(RRC,"Setting transmission mode to %ld+1\n",rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode);
+
+  if (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm3) {
+    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=
+      CALLOC(1,sizeof(LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR));
+    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
+      LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm3;
+    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.buf= MALLOC(1);
+    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.buf[0] = 0xc0;
+    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.size=1;
+    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.bits_unused=6;
+  } else if (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm4) {
+    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=
+      CALLOC(1,sizeof(LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR));
+    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
+      LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm4;
+    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.buf= MALLOC(1);
+    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.buf[0] = 0xfc;
+    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.size=1;
+    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.bits_unused=2;
+  } else if (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm5) {
+    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=
+      CALLOC(1,sizeof(LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR));
+    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
+      LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm5;
+    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.buf= MALLOC(1);
+    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.buf[0] = 0xf0;
+    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.size=1;
+    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.bits_unused=4;
+  } else if (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm6) {
+    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=
+      CALLOC(1,sizeof(LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR));
+    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
+      LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm6;
+    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.buf= MALLOC(1);
+    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.buf[0] = 0xf0;
+    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.size=1;
+    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.bits_unused=4;
+  }
+
+  physicalConfigDedicated2->antennaInfo->choice.explicitValue.ue_TransmitAntennaSelection.present =
+    LTE_AntennaInfoDedicated__ue_TransmitAntennaSelection_PR_release;
+  physicalConfigDedicated2->antennaInfo->choice.explicitValue.ue_TransmitAntennaSelection.choice.release = 0;
+  //}
+  //else {
+  //LOG_E(RRC,"antenna_info not present in physical_config_dedicated. Not reconfiguring!\n");
+  //}
+  // CQI ReportConfig
+  physicalConfigDedicated2->cqi_ReportConfig = CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig));
+  physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportModeAperiodic = CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportModeAperiodic));
+  physicalConfigDedicated2->cqi_ReportConfig->nomPDSCH_RS_EPRE_Offset = 0; // 0 dB
+  //physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic=NULL;
+  physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic=CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic));
+  physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->present =  LTE_CQI_ReportPeriodic_PR_release;
+
+  //if ((*physicalConfigDedicated)->cqi_ReportConfig) {
+  if ((rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm4) ||
+      (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm5) ||
+      (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm6)) {
+    //feedback mode needs to be set as well
+    //TODO: I think this is taken into account in the PHY automatically based on the transmission mode variable
+    printf("setting cqi reporting mode to rm31\n");
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+    *((*physicalConfigDedicated)->cqi_ReportConfig->cqi_ReportModeAperiodic)=LTE_CQI_ReportModeAperiodic_rm31;
+#else
+    *((*physicalConfigDedicated)->cqi_ReportConfig->cqi_ReportModeAperiodic)=CQI_ReportConfig__cqi_ReportModeAperiodic_rm31; // HLC CQI, no PMI
+#endif
+  } else {
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+    *physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportModeAperiodic= LTE_CQI_ReportModeAperiodic_rm30;
+#else
+    *physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportModeAperiodic=CQI_ReportConfig__cqi_ReportModeAperiodic_rm30; // HLC CQI, no PMI
+#endif
+  }
+
+  //}
+  //else {
+  //LOG_E(RRC,"cqi_ReportConfig not present in physical_config_dedicated. Not reconfiguring!\n");
+  //}
+  // SchedulingRequestConfig
+  physicalConfigDedicated2->schedulingRequestConfig->present = LTE_SchedulingRequestConfig_PR_setup;
+  physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_PUCCH_ResourceIndex = ue_context_pP->local_uid;
+
+  if (rrc_inst->carrier[0].sib1->tdd_Config==NULL) {  // FDD
+    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;
+
+      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;
+
+      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;
+  //}
+  //else {
+  //LOG_E(RRC,"physical_config_dedicated not present in RRCConnectionReconfiguration. Not reconfiguring!\n");
+  //}
+  // 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);
+  //  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 = (LTE_ARFCN_ValueEUTRA_t)to_earfcn_DL(RC.rrc[ctxt_pP->module_id]->carrier[0].eutra_band, RC.rrc[ctxt_pP->module_id]->carrier[0].dl_CarrierFreq,
+      RC.rrc[ctxt_pP->module_id]->carrier[0].N_RB_DL);
+  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 =
+  //(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 = (CellsToAddMod_t *) CALLOC(1, sizeof(*CellToAdd));
+  //CellToAdd->cellIndex = 1;//i + 1;
+  //CellToAdd->physCellId = 1;//get_adjacent_cell_id(ctxt_pP->module_id, i);
+  //CellToAdd->cellIndividualOffset = Q_OffsetRange_dB0;
+  //ASN_SEQUENCE_ADD(&CellsToAddModList->list, CellToAdd);
+  //}
+  ASN_SEQUENCE_ADD(&MeasObj_list->list, MeasObj);
+  //  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);
+  //  if (ho_state == 1 /*HO_MEASUREMENT */ ) {
+  LOG_I(RRC, "[eNB %d] frame %d: requesting A2, A3, A4, and A5 event reporting\n",
+        ctxt_pP->module_id, ctxt_pP->frame);
+  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 = 0;   //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;
+  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.hysteresis = 0; // FIXME ...hysteresis is of type long!
+  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.timeToTrigger =
+    LTE_TimeToTrigger_ms40;
+  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);
+  //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->reportConfigToAddModList = ReportConfig_list;
+  rsrp = CALLOC(1, sizeof(RSRP_Range_t));
+  *rsrp = 20;
+  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(struct LTE_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 = ue_context_pP->ue_context.mobilityInfo;
+
+  if (mobilityInfo) {
+    free(mobilityInfo);
+  }
+
+  mobilityInfo = CALLOC(1, sizeof(*mobilityInfo));
+  memset((void *)mobilityInfo, 0, sizeof(*mobilityInfo));
+  mobilityInfo->targetPhysCellId = RC.rrc[ctxt_pP->module_id]->carrier[0].physCellId;
+  //(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, // get_adjacent_cell_mod_id(mobilityInfo->targetPhysCellId),
+        ue_context_pP->ue_context.rnti);
+  mobilityInfo->additionalSpectrumEmission = CALLOC(1, sizeof(*mobilityInfo->additionalSpectrumEmission));
+  *mobilityInfo->additionalSpectrumEmission = (LTE_AdditionalSpectrumEmission_t) 1;  //Check this value!
+  mobilityInfo->t304 = LTE_MobilityControlInfo__t304_ms200;    // 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(TDD_Config_t));
+  //memcpy((void *)mobilityInfo->radioResourceConfigCommon.tdd_Config,(void *)rrc_inst->sib1->tdd_Config,sizeof(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 = (LTE_ARFCN_ValueEUTRA_t)to_earfcn_DL(RC.rrc[ctxt_pP->module_id]->carrier[0].eutra_band, RC.rrc[ctxt_pP->module_id]->carrier[0].dl_CarrierFreq,
+      RC.rrc[ctxt_pP->module_id]->carrier[0].N_RB_DL);
+  mobilityInfo->carrierFreq->ul_CarrierFreq = NULL;
+  mobilityInfo->carrierBandwidth = CALLOC(1, sizeof(
+      *mobilityInfo->carrierBandwidth));    //CALLOC(1,sizeof(struct CarrierBandwidthEUTRA));  AllowedMeasBandwidth_mbw25
+  mobilityInfo->carrierBandwidth->dl_Bandwidth = LTE_CarrierBandwidthEUTRA__dl_Bandwidth_n25;
+  mobilityInfo->carrierBandwidth->ul_Bandwidth = NULL;
+  mobilityInfo->rach_ConfigDedicated = NULL;
+  ue_context_pP->ue_context.mobilityInfo = mobilityInfo;
+#if 0
+  LOG_I(RRC,
+        "[eNB %d] Frame %d: potential handover preparation: store the information in an intermediate structure in case of failure\n",
+        ctxt_pP->module_id, ctxt_pP->frame);
+  // store the information in an intermediate structure for Hanodver management
+  //rrc_inst->handover_info.as_config.sourceRadioResourceConfig.srb_ToAddModList = CALLOC(1,sizeof());
+  ue_context_pP->ue_context.handover_info = CALLOC(1, sizeof(*(ue_context_pP->ue_context.handover_info)));
+  //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.srb_ToAddModList,(void *)SRB_list,sizeof(SRB_ToAddModList_t));
+  ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.srb_ToAddModList = *SRB_configList2;
+  //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.drb_ToAddModList,(void *)DRB_list,sizeof(DRB_ToAddModList_t));
+  ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToAddModList = *DRB_configList;
+  ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToReleaseList = NULL;
+  ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig =
+    CALLOC(1, sizeof(*ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig));
+  memcpy((void *)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig,
+         (void *)mac_MainConfig, sizeof(MAC_MainConfig_t));
+  ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.physicalConfigDedicated =
+    CALLOC(1, sizeof(PhysicalConfigDedicated_t));
+  memcpy((void *)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.physicalConfigDedicated,
+         (void *)ue_context_pP->ue_context.physicalConfigDedicated, sizeof(PhysicalConfigDedicated_t));
+  ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.sps_Config = NULL;
+  //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));
+#endif
+  //  }
+  securityConfigHO = CALLOC(1, sizeof(*securityConfigHO));
+  memset((void *)securityConfigHO, 0, sizeof(*securityConfigHO));
+  securityConfigHO->handoverType.present = LTE_SecurityConfigHO__handoverType_PR_intraLTE;
+  securityConfigHO->handoverType.choice.intraLTE.securityAlgorithmConfig = NULL; /* TODO: to be checked */
+  securityConfigHO->handoverType.choice.intraLTE.keyChangeIndicator = 0;
+  securityConfigHO->handoverType.choice.intraLTE.nextHopChainingCount = 0;
+#if defined(ENABLE_ITTI)
+  /* Initialize NAS list */
+  dedicatedInfoNASList = CALLOC(1, sizeof(struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));
+
+  /* Add all NAS PDUs to the list */
+  for (i = 0; i < ue_context_pP->ue_context.nb_of_e_rabs; i++) {
+    if (ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer != NULL) {
+      dedicatedInfoNas = CALLOC(1, sizeof(LTE_DedicatedInfoNAS_t));
+      memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t));
+      OCTET_STRING_fromBuf(dedicatedInfoNas,
+                           (char *)ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer,
+                           ue_context_pP->ue_context.e_rab[i].param.nas_pdu.length);
+      ASN_SEQUENCE_ADD(&dedicatedInfoNASList->list, dedicatedInfoNas);
+    }
+
+    /* TODO parameters yet to process ... */
+    {
+      //      ue_context_pP->ue_context.e_rab[i].param.qos;
+      //      ue_context_pP->ue_context.e_rab[i].param.sgw_addr;
+      //      ue_context_pP->ue_context.e_rab[i].param.gtp_teid;
+    }
+    /* TODO should test if e RAB are Ok before! */
+    ue_context_pP->ue_context.e_rab[i].status = E_RAB_STATUS_DONE;
+    LOG_D(RRC, "setting the status for the default DRB (index %d) to (%d,%s)\n",
+          i, ue_context_pP->ue_context.e_rab[i].status, "E_RAB_STATUS_DONE");
+  }
+
+  /* If list is empty free the list and reset the address */
+  if (dedicatedInfoNASList->list.count == 0) {
+    free(dedicatedInfoNASList);
+    dedicatedInfoNASList = NULL;
+  }
+
+#endif
+  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;
+  rrc_size = do_RRCConnectionReconfiguration(ctxt_pP,
+             (unsigned char *)rrc_buf,
+             xid,   //Transaction_id,
+             NULL, // SRB_configList
+             NULL,
+             NULL,  // DRB2_list,
+             (struct LTE_SPS_Config *)NULL,   // *sps_Config,
+             (struct LTE_PhysicalConfigDedicated *)*physicalConfigDedicated,
+             //#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,
+             //#endif
+             (LTE_MAC_MainConfig_t *)mac_MainConfig,
+             (LTE_MeasGapConfig_t *)NULL,
+             (LTE_MobilityControlInfo_t *)mobilityInfo,
+             (LTE_SecurityConfigHO_t *)securityConfigHO,
+             (struct LTE_MeasConfig__speedStatePars *)Sparams,
+             (LTE_RSRP_Range_t *)rsrp,
+             (LTE_C_RNTI_t *)cba_RNTI,
+             (struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *)dedicatedInfoNASList,
+             (LTE_SL_CommConfig_r12_t *)NULL,
+             (LTE_SL_DiscConfig_r12_t *)NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+             , (LTE_SCellToAddMod_r10_t *)NULL
+#endif
+                                            );
+
+  if (rrc_size <= 0) {
+    printf("%s:%d: fatal\n", __FILE__, __LINE__);
+    abort();
+  }
+
+  char *ho_buf = (char *)buffer;
+  int ho_size;
+  ho_size = do_HandoverCommand(
+              ho_buf, 1024 /* TODO: this is the value found in struct x2ap_handover_req_ack_s for array rrc_buffer */,
+              rrc_buf,
+              rrc_size);
+  *_size = size = ho_size;
+  LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,size,
+              "[MSG] RRC Connection Reconfiguration handover\n");
+#if defined(ENABLE_ITTI)
+
+  /* Free all NAS PDUs */
+  for (i = 0; i < ue_context_pP->ue_context.nb_of_e_rabs; i++) {
+    if (ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer != NULL) {
+      /* Free the NAS PDU buffer and invalidate it */
+      free(ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer);
+      ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer = NULL;
+    }
+  }
+
+#endif
+  LOG_I(RRC,
+        "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration handover (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 handover to UE %x MUI %d) --->][PDCP][MOD %u][RB %u]\n",
+        ctxt_pP->frame, ctxt_pP->module_id, size, ue_context_pP->ue_context.rnti, rrc_eNB_mui, ctxt_pP->module_id, DCCH);
+  MSC_LOG_TX_MESSAGE(
+    MSC_RRC_ENB,
+    MSC_RRC_UE,
+    buffer,
+    size,
+    MSC_AS_TIME_FMT" rrcConnectionReconfiguration handover UE %x MUI %d size %u",
+    MSC_AS_TIME_ARGS(ctxt_pP),
+    ue_context_pP->ue_context.rnti,
+    rrc_eNB_mui,
+    size);
+}
+
+void
+rrc_eNB_configure_rbs_handover(struct rrc_eNB_ue_context_s *ue_context_p, protocol_ctxt_t *const ctxt_pP) {
+  uint16_t                            Idx;
+  Idx = DCCH;
+#if 1
+  // Activate the radio bearers
+  // SRB1
+  ue_context_p->ue_context.Srb1.Active = 1;
+  ue_context_p->ue_context.Srb1.Srb_info.Srb_id = Idx;
+  memcpy(&ue_context_p->ue_context.Srb1.Srb_info.Lchan_desc[0], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
+  memcpy(&ue_context_p->ue_context.Srb1.Srb_info.Lchan_desc[1], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
+  // SRB2
+  ue_context_p->ue_context.Srb2.Active = 1;
+  ue_context_p->ue_context.Srb2.Srb_info.Srb_id = Idx;
+  memcpy(&ue_context_p->ue_context.Srb2.Srb_info.Lchan_desc[0], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
+  memcpy(&ue_context_p->ue_context.Srb2.Srb_info.Lchan_desc[1], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
+#endif
+  LOG_I(RRC, "[eNB %d] CALLING RLC CONFIG SRB1 (rbid %d) for UE %x\n",
+        ctxt_pP->module_id, Idx, ue_context_p->ue_context.rnti);
+  // Configure PDCP/RLC for the target
+  rrc_pdcp_config_asn1_req(ctxt_pP,
+                           ue_context_p->ue_context.SRB_configList,
+                           (LTE_DRB_ToAddModList_t *) NULL,
+                           (LTE_DRB_ToReleaseList_t *) NULL,
+                           0xff,
+                           NULL,
+                           NULL,
+                           NULL
+#if defined(Rel10) || defined(Rel14)
+                           , (LTE_PMCH_InfoList_r9_t *) NULL
+#endif
+                           , NULL);
+  rrc_rlc_config_asn1_req(ctxt_pP,
+                          ue_context_p->ue_context.SRB_configList,
+                          (LTE_DRB_ToAddModList_t *) NULL,
+                          (LTE_DRB_ToReleaseList_t *) NULL
+#if defined(Rel10) || defined(Rel14)
+                          , (LTE_PMCH_InfoList_r9_t *) NULL
+                          , 0, 0
+#endif
+                         );
+  // 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);
+  // Configure MAC for the target
+  rrc_mac_config_req_eNB(
+    ctxt_pP->module_id,
+    ue_context_p->ue_context.primaryCC_id,
+    0,0,0,0,0,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+    0,
+#endif
+    ue_context_p->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_p->ue_context.physicalConfigDedicated,
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+    (LTE_SCellToAddMod_r10_t *)NULL,
+    //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
+#endif
+    (LTE_MeasObjectToAddMod_t **) NULL,
+    ue_context_p->ue_context.mac_MainConfig,
+    1,
+    NULL,//SRB1_logicalChannelConfig,
+    ue_context_p->ue_context.measGapConfig,
+    (LTE_TDD_Config_t *) NULL,
+    (LTE_MobilityControlInfo_t *) ue_context_p->ue_context.mobilityInfo,
+    (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
+  );
+//#if 0
+//}
+//#endif
+}
+
+#if 0
+// 5.3.5.4 LTE_RRCConnectionReconfiguration including the mobilityControlInfo to prepare the UE handover
+//-----------------------------------------------------------------------------
+void
+rrc_eNB_generate_RRCConnectionReconfiguration_handover(
+  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
+)
+//-----------------------------------------------------------------------------
+{
+  T(T_ENB_RRC_CONNECTION_RECONFIGURATION, 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 (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
   long                               *sr_ProhibitTimer_r9;
 #endif
-
   long                               *logicalchannelgroup, *logicalchannelgroup_drb;
   long                               *maxHARQ_Tx, *periodicBSR_Timer;
-
-  // RSRP_Range_t *rsrp;
-  struct MeasConfig__speedStatePars  *Sparams;
-  CellsToAddMod_t                    *CellToAdd;
-  CellsToAddModList_t                *CellsToAddModList;
+  // LTE_RSRP_Range_t *rsrp;
+  struct LTE_MeasConfig__speedStatePars  *Sparams;
+  LTE_CellsToAddMod_t                    *CellToAdd;
+  LTE_CellsToAddModList_t                *CellsToAddModList;
   // srb 1: for HO
-  struct SRB_ToAddMod                *SRB1_config;
-  struct SRB_ToAddMod__rlc_Config    *SRB1_rlc_config;
-  struct SRB_ToAddMod__logicalChannelConfig *SRB1_lchan_config;
-  struct LogicalChannelConfig__ul_SpecificParameters *SRB1_ul_SpecificParameters;
+  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
-  PhysicalConfigDedicated_t          *physicalConfigDedicated2;
-  struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList;
+  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);
 
@@ -4625,44 +5619,33 @@ rrc_eNB_generate_RRCConnectionReconfiguration_handover(
   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 = SRB_ToAddMod__rlc_Config_PR_explicitValue;
-  SRB1_rlc_config->choice.explicitValue.present = RLC_Config_PR_am;
-  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = T_PollRetransmit_ms15;
-  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU = PollPDU_p8;
-  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte = PollByte_kB1000;
-  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = UL_AM_RLC__maxRetxThreshold_t16;
-  SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering = T_Reordering_ms35;
-  SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = T_StatusProhibit_ms10;
-
+  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 = SRB_ToAddMod__logicalChannelConfig_PR_explicitValue;
+  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 =
-    LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
-
+    LTE_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
   //assign_enum(&SRB1_ul_SpecificParameters->bucketSizeDuration,LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50);
   SRB1_ul_SpecificParameters->bucketSizeDuration =
-    LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
-
+    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 =
@@ -4683,52 +5666,46 @@ rrc_eNB_generate_RRCConnectionReconfiguration_handover(
   // PDSCH
   //assign_enum(&physicalConfigDedicated2->pdsch_ConfigDedicated->p_a,
   //          PDSCH_ConfigDedicated__p_a_dB0);
-  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 =
-    PUCCH_ConfigDedicated__ackNackRepetition_PR_release;
+    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 =
-    UplinkPowerControlDedicated__deltaMCS_Enabled_en1;
+    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 = FilterCoefficient_fc4;  // fc4 dB
-
+  *physicalConfigDedicated2->uplinkPowerControlDedicated->filterCoefficient = LTE_FilterCoefficient_fc4;  // fc4 dB
   // TPC-PDCCH-Config
-  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->present = TPC_PDCCH_Config_PR_setup;
-  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_Index.present = TPC_Index_PR_indexOfFormat3;
+  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 = TPC_PDCCH_Config_PR_setup;
-  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_Index.present = TPC_Index_PR_indexOfFormat3;
+  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;
-
   // CQI ReportConfig
   /*
      physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportModeAperiodic=CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportModeAperiodic));
@@ -4745,7 +5722,6 @@ rrc_eNB_generate_RRCConnectionReconfiguration_handover(
      physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.ri_ConfigIndex=NULL;
      physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.simultaneousAckNackAndCQI=0;
    */
-
   //soundingRS-UL-ConfigDedicated
   /*
      physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->present = SoundingRS_UL_ConfigDedicated_PR_setup;
@@ -4760,37 +5736,35 @@ rrc_eNB_generate_RRCConnectionReconfiguration_handover(
      assign_enum(&physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.cyclicShift,
      SoundingRS_UL_ConfigDedicated__setup__cyclicShift_cs0);
    */
-
   //AntennaInfoDedicated
   physicalConfigDedicated2->antennaInfo = CALLOC(1, sizeof(*physicalConfigDedicated2->antennaInfo));
-  physicalConfigDedicated2->antennaInfo->present = PhysicalConfigDedicated__antennaInfo_PR_explicitValue;
+  physicalConfigDedicated2->antennaInfo->present = LTE_PhysicalConfigDedicated__antennaInfo_PR_explicitValue;
   //assign_enum(&physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode,
-  //     AntennaInfoDedicated__transmissionMode_tm2);
+  //     LTE_AntennaInfoDedicated__transmissionMode_tm2);
   /*
      switch (transmission_mode){
      case 1:
-     physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm1;
+     physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     LTE_AntennaInfoDedicated__transmissionMode_tm1;
      break;
      case 2:
-     physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm2;
+     physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     LTE_AntennaInfoDedicated__transmissionMode_tm2;
      break;
      case 4:
-     physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm4;
+     physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     LTE_AntennaInfoDedicated__transmissionMode_tm4;
      break;
      case 5:
-     physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm5;
+     physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     LTE_AntennaInfoDedicated__transmissionMode_tm5;
      break;
      case 6:
-     physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm6;
+     physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     LTE_AntennaInfoDedicated__transmissionMode_tm6;
      break;
      }
    */
   physicalConfigDedicated2->antennaInfo->choice.explicitValue.ue_TransmitAntennaSelection.present =
-    AntennaInfoDedicated__ue_TransmitAntennaSelection_PR_release;
+    LTE_AntennaInfoDedicated__ue_TransmitAntennaSelection_PR_release;
   physicalConfigDedicated2->antennaInfo->choice.explicitValue.ue_TransmitAntennaSelection.choice.release = 0;
-
   // SchedulingRequestConfig
-  physicalConfigDedicated2->schedulingRequestConfig->present = SchedulingRequestConfig_PR_setup;
+  physicalConfigDedicated2->schedulingRequestConfig->present = LTE_SchedulingRequestConfig_PR_setup;
   physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_PUCCH_ResourceIndex = ue_context_pP->local_uid;
 
   if (rrc_inst->carrier[0].sib1->tdd_Config==NULL) {  // FD
@@ -4798,24 +5772,24 @@ rrc_eNB_generate_RRCConnectionReconfiguration_handover(
         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;
+      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;
 
-    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;
+      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;
 
-    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;
+      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;
+      default:
+        physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 7; // Isr = 5 (every 10 subframes, offset=2 for all UE0 etc..)
+        break;
     }
   }
 
@@ -4823,387 +5797,318 @@ rrc_eNB_generate_RRCConnectionReconfiguration_handover(
   //SchedulingRequestConfig__setup__dsr_TransMax_n4);
   //  assign_enum(&physicalConfigDedicated2->schedulingRequestConfig->choice.setup.dsr_TransMax = SchedulingRequestConfig__setup__dsr_TransMax_n4;
   physicalConfigDedicated2->schedulingRequestConfig->choice.setup.dsr_TransMax =
-    SchedulingRequestConfig__setup__dsr_TransMax_n4;
-
+    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);
   if (RC.rrc[ctxt_pP->module_id]->node_type == ngran_eNB) {
-    rrc_mac_config_req_eNB(
-			   ctxt_pP->module_id,
-			   ue_context_pP->ue_context.primaryCC_id,
-			   0,0,0,0,0,
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-			   0,
+    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,
-			   (BCCH_BCH_Message_t *) NULL,
-			   (RadioResourceConfigCommonSIB_t*) NULL,
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-			   (RadioResourceConfigCommonSIB_t*) NULL,
-#endif
-			   ue_context_pP->ue_context.physicalConfigDedicated,
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-			   (SCellToAddMod_r10_t *)NULL,
-			   //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
-#endif
-			   (MeasObjectToAddMod_t **) NULL,
-			   ue_context_pP->ue_context.mac_MainConfig,
-			   1,
-			   SRB1_logicalChannelConfig,
-			   ue_context_pP->ue_context.measGapConfig,
-			   (TDD_Config_t*) NULL,
-			   (MobilityControlInfo_t*) NULL,
-			   (SchedulingInfoList_t*) NULL,
-			   0,
-			   NULL,
-			   NULL,
-			   (MBSFN_SubframeConfigList_t *) NULL
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-			   , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
-#endif
-#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
-			   ,
-			   (SystemInformationBlockType1_v1310_IEs_t *)NULL
-#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 = SRB_ToAddMod__rlc_Config_PR_explicitValue;
-  SRB2_rlc_config->choice.explicitValue.present = RLC_Config_PR_am;
-  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = T_PollRetransmit_ms15;
-  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU = PollPDU_p8;
-  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte = PollByte_kB1000;
-  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = UL_AM_RLC__maxRetxThreshold_t32;
-  SRB2_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering = T_Reordering_ms35;
-  SRB2_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = T_StatusProhibit_ms10;
-
+  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 = SRB_ToAddMod__logicalChannelConfig_PR_explicitValue;
-
+  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 =
-    LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
+    LTE_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
   SRB2_ul_SpecificParameters->bucketSizeDuration =
-    LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
-
+    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 = (DRB_Identity_t) 1; //allowed values 1..32
+  //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 = (DRB_Identity_t) 1;  // (ue_mod_idP+1); //allowed values 1..32
+  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 = RLC_Config_PR_um_Bi_Directional;
-  DRB_rlc_config->choice.um_Bi_Directional.ul_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
-  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
-  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = T_Reordering_ms35;
-
+  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 = PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits;
-  DRB_pdcp_config->headerCompression.present = PDCP_Config__headerCompression_PR_notUsed;
-
+  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 =
-    LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
+    LTE_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
   DRB_ul_SpecificParameters->bucketSizeDuration =
-    LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
-
+    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 = MAC_MainConfig__ul_SCH_Config__maxHARQ_Tx_n5;
+  *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 = PeriodicBSR_Timer_r12_sf64;
+  *periodicBSR_Timer = LTE_PeriodicBSR_Timer_r12_sf64;
   mac_MainConfig->ul_SCH_Config->periodicBSR_Timer = periodicBSR_Timer;
-
-  mac_MainConfig->ul_SCH_Config->retxBSR_Timer = RetxBSR_Timer_r12_sf320;
-
+  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 = MAC_MainConfig__phr_Config_PR_setup;
-  mac_MainConfig->phr_Config->choice.setup.periodicPHR_Timer = MAC_MainConfig__phr_Config__setup__periodicPHR_Timer_sf20; // sf20 = 20 subframes
-
-  mac_MainConfig->phr_Config->choice.setup.prohibitPHR_Timer = MAC_MainConfig__phr_Config__setup__prohibitPHR_Timer_sf20; // sf20 = 20 subframes
-
-  mac_MainConfig->phr_Config->choice.setup.dl_PathlossChange = MAC_MainConfig__phr_Config__setup__dl_PathlossChange_dB1;  // Value dB1 =1 dB, dB3 = 3 dB
-
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+  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 MAC_MainConfig__ext1));
+  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);
-
-  //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measIdToAddModList = MeasId_list;
-
+  //  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 = MeasObjectToAddMod__measObject_PR_measObjectEUTRA;
+  MeasObj->measObject.present = LTE_MeasObjectToAddMod__measObject_PR_measObjectEUTRA;
   MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 36090;
-  MeasObj->measObject.choice.measObjectEUTRA.allowedMeasBandwidth = AllowedMeasBandwidth_mbw25;
+  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 =
-    (CellsToAddModList_t *) CALLOC(1, sizeof(*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 = (CellsToAddMod_t *) CALLOC(1, sizeof(*CellToAdd));
+    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 = Q_OffsetRange_dB0;
-
+    CellToAdd->cellIndividualOffset = LTE_Q_OffsetRange_dB0;
     ASN_SEQUENCE_ADD(&CellsToAddModList->list, CellToAdd);
   }
 
   ASN_SEQUENCE_ADD(&MeasObj_list->list, MeasObj);
-  //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measObjectToAddModList = MeasObj_list;
-
+  //  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 = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
+  ReportConfig_per->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
   ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.present =
-    ReportConfigEUTRA__triggerType_PR_periodical;
+    LTE_ReportConfigEUTRA__triggerType_PR_periodical;
   ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.choice.periodical.purpose =
-    ReportConfigEUTRA__triggerType__periodical__purpose_reportStrongestCells;
-  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerQuantity = ReportConfigEUTRA__triggerQuantity_rsrp;
-  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
+    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 = ReportInterval_ms120;
-  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;
-
+  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 = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
+  ReportConfig_A1->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
   ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.present =
-    ReportConfigEUTRA__triggerType_PR_event;
+    LTE_ReportConfigEUTRA__triggerType_PR_event;
   ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
-    ReportConfigEUTRA__triggerType__event__eventId_PR_eventA1;
+    LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA1;
   ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA1.
-  a1_Threshold.present = ThresholdEUTRA_PR_threshold_RSRP;
+  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 = ReportConfigEUTRA__triggerQuantity_rsrp;
-  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
+  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 = ReportInterval_ms120;
-  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;
-
+  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 = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
+  ReportConfig_A2->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
   ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.present =
-    ReportConfigEUTRA__triggerType_PR_event;
+    LTE_ReportConfigEUTRA__triggerType_PR_event;
   ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
-    ReportConfigEUTRA__triggerType__event__eventId_PR_eventA2;
+    LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA2;
   ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA2.
-  a2_Threshold.present = ThresholdEUTRA_PR_threshold_RSRP;
+  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 = ReportConfigEUTRA__triggerQuantity_rsrp;
-  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
+  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 = ReportInterval_ms120;
-  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;
-
+  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 = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
+  ReportConfig_A3->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
   ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.present =
-    ReportConfigEUTRA__triggerType_PR_event;
+    LTE_ReportConfigEUTRA__triggerType_PR_event;
   ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
-    ReportConfigEUTRA__triggerType__event__eventId_PR_eventA3;
+    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 = ReportConfigEUTRA__triggerQuantity_rsrp;
-  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
+  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 = ReportInterval_ms120;
-  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;
-
+  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 = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
+  ReportConfig_A4->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
   ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.present =
-    ReportConfigEUTRA__triggerType_PR_event;
+    LTE_ReportConfigEUTRA__triggerType_PR_event;
   ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
-    ReportConfigEUTRA__triggerType__event__eventId_PR_eventA4;
+    LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA4;
   ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA4.
-  a4_Threshold.present = ThresholdEUTRA_PR_threshold_RSRP;
+  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 = ReportConfigEUTRA__triggerQuantity_rsrp;
-  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
+  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 = ReportInterval_ms120;
-  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;
-
+  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 = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
+  ReportConfig_A5->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
   ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.present =
-    ReportConfigEUTRA__triggerType_PR_event;
+    LTE_ReportConfigEUTRA__triggerType_PR_event;
   ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
-    ReportConfigEUTRA__triggerType__event__eventId_PR_eventA5;
+    LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA5;
   ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
-  eventA5.a5_Threshold1.present = ThresholdEUTRA_PR_threshold_RSRP;
+  eventA5.a5_Threshold1.present = LTE_ThresholdEUTRA_PR_threshold_RSRP;
   ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
-  eventA5.a5_Threshold2.present = ThresholdEUTRA_PR_threshold_RSRP;
+  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 = ReportConfigEUTRA__triggerQuantity_rsrp;
-  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
+  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 = ReportInterval_ms120;
-  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;
-
+  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 = MeasConfig__speedStatePars_PR_setup;
-  Sparams->choice.setup.timeToTrigger_SF.sf_High = SpeedStateScaleFactors__sf_Medium_oDot75;
-  Sparams->choice.setup.timeToTrigger_SF.sf_Medium = SpeedStateScaleFactors__sf_High_oDot5;
+  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 = MobilityStateParameters__t_Evaluation_s60;
-  Sparams->choice.setup.mobilityStateParameters.t_HystNormal = MobilityStateParameters__t_HystNormal_s120;
-
+  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));
@@ -5215,105 +6120,93 @@ rrc_eNB_generate_RRCConnectionReconfiguration_handover(
     CALLOC(1, sizeof(*quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP));
   quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ =
     CALLOC(1, sizeof(*quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ));
-  *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP = FilterCoefficient_fc4;
-  *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ = FilterCoefficient_fc4;
-
+  *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 =
-    (PhysCellId_t) two_tier_hexagonal_cellIds[ue_context_pP->ue_context.handover_info->modid_t];
+    (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 = MobilityControlInfo__t304_ms50;    // need to configure an appropriate value here
-
+  *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(RACH_ConfigCommon_t));
+         (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(PRACH_ConfigInfo_t));
-
+         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(PDSCH_ConfigCommon_t));
+         (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(PUSCH_ConfigCommon_t));
+         (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(PUCCH_ConfigCommon_t));
+         (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(SoundingRS_UL_ConfigCommon_t));
+         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(UplinkPowerControlCommon_t));
+         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(TDD_Config_t));
-  //memcpy((void *)mobilityInfo->radioResourceConfigCommon.tdd_Config,(void *)rrc_inst->sib1->tdd_Config,sizeof(TDD_Config_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 CarrierBandwidthEUTRA));  AllowedMeasBandwidth_mbw25
-  mobilityInfo->carrierBandwidth->dl_Bandwidth = CarrierBandwidthEUTRA__dl_Bandwidth_n25;
+      *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(SRB_ToAddModList_t));
-  memcpy((void*)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToAddModList,
-         (void*)DRB_configList2,
-         sizeof(DRB_ToAddModList_t));
+         (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(MAC_MainConfig_t));
-  memcpy((void*)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.physicalConfigDedicated,
-         (void*)ue_context_pP->ue_context.physicalConfigDedicated,
-         sizeof(PhysicalConfigDedicated_t));
+  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));
@@ -5327,81 +6220,77 @@ rrc_eNB_generate_RRCConnectionReconfiguration_handover(
   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 
+  // 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,
-                           (DRB_ToAddModList_t *) NULL, (DRB_ToReleaseList_t *) NULL, 0xff, NULL, NULL, NULL
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-                           , (PMCH_InfoList_r9_t *) NULL
+                           (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);
   if ( (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_eNB_CU) &&
        (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_ng_eNB_CU)&& 
        (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_CU)   ) {
     rrc_rlc_config_asn1_req(&ctxt,
-			    ue_context_pP->ue_context.SRB_configList,
-			    (DRB_ToAddModList_t *) NULL, (DRB_ToReleaseList_t *) NULL
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-			    , (PMCH_InfoList_r9_t *) NULL
-			    , 0, 0
+                            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;
-
-  //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->reportConfigToAddModList = ReportConfig_list;
+  //  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,
-           (SL_CommConfig_r12_t*)NULL,
-           (SL_DiscConfig_r12_t*)NULL
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-           , NULL   // SCellToAddMod_r10_t
+  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 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 RRCConnectionReconfiguration for handover (bytes %d, UE rnti %x)\n",
-        ctxt_pP->module_id, ctxt_pP->frame, size, ue_context_pP->ue_context.rnti);
+           );
+
+  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 == SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
+     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 {
@@ -5412,7 +6301,6 @@ rrc_eNB_generate_RRCConnectionReconfiguration_handover(
      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);
@@ -5420,40 +6308,40 @@ rrc_eNB_generate_RRCConnectionReconfiguration_handover(
   //pdcp_data_req (ctxt_pP->module_id, frameP, 1, (ue_mod_idP * NB_RB_MAX) + DCCH,rrc_eNB_mui++, 0, size, (char *) buffer, 1);
 
   if (RC.rrc[ctxt_pP->module_id]->node_type == ngran_eNB) {
-    rrc_mac_config_req_eNB(
-			   ctxt_pP->module_id,
-			   ue_context_pP->ue_context.primaryCC_id,
-			   0,0,0,0,0,
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-			   0,
-#endif
-			   ue_context_pP->ue_context.rnti,
-			   (BCCH_BCH_Message_t *) NULL,
-			   (RadioResourceConfigCommonSIB_t *) NULL,
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-			   (RadioResourceConfigCommonSIB_t *) NULL,
-#endif
-			   ue_context_pP->ue_context.physicalConfigDedicated,
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-			   (SCellToAddMod_r10_t *)NULL,
-			   //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
-#endif
-			   (MeasObjectToAddMod_t **) NULL,
-			   ue_context_pP->ue_context.mac_MainConfig,
-			   1,
-			   SRB1_logicalChannelConfig,
-			   ue_context_pP->ue_context.measGapConfig,
-			   (TDD_Config_t *) NULL,
-			   (MobilityControlInfo_t *) mobilityInfo,
-			   (SchedulingInfoList_t *) NULL, 0, NULL, NULL, (MBSFN_SubframeConfigList_t *) NULL
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-			   , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
-#endif
-#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
-			   ,
-			   (SystemInformationBlockType1_v1310_IEs_t *)NULL
-#endif
-			   );
+    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;
@@ -5461,7 +6349,7 @@ rrc_eNB_generate_RRCConnectionReconfiguration_handover(
      handoverCommand.criticalExtensions.choice.c1.choice.handoverCommand_r8.handoverCommandMessage.buf = buffer;
      handoverCommand.criticalExtensions.choice.c1.choice.handoverCommand_r8.handoverCommandMessage.size = size;
    */
-//#warning "COMPILATION PROBLEM"
+  //#warning "COMPILATION PROBLEM"
 #ifdef PROBLEM_COMPILATION_RESOLVED
 
   if (sourceModId != 0xFF) {
@@ -5485,18 +6373,19 @@ rrc_eNB_generate_RRCConnectionReconfiguration_handover(
 
 #endif
 }
+#endif
 
 /*
   void ue_rrc_process_rrcConnectionReconfiguration(uint8_t enb_mod_idP,frame_t frameP,
-  RRCConnectionReconfiguration_t *rrcConnectionReconfiguration,
+  LTE_RRCConnectionReconfiguration_t *rrcConnectionReconfiguration,
   uint8_t CH_index) {
 
-  if (rrcConnectionReconfiguration->criticalExtensions.present == RRCConnectionReconfiguration__criticalExtensions_PR_c1)
-  if (rrcConnectionReconfiguration->criticalExtensions.choice.c1.present == RRCConnectionReconfiguration__criticalExtensions__c1_PR_rrcConnectionReconfiguration_r8) {
+  if (rrcConnectionReconfiguration->criticalExtensions.present == LTE_RRCConnectionReconfiguration__criticalExtensions_PR_c1)
+  if (rrcConnectionReconfiguration->criticalExtensions.choice.c1.present == LTE_RRCConnectionReconfiguration__criticalExtensions__c1_PR_rrcConnectionReconfiguration_r8) {
 
   if (rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated) {
   rrc_ue_process_radioResourceConfigDedicated(enb_mod_idP,frameP,CH_index,
-  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated);
+  LTE_RRCConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated);
 
   }
 
@@ -5506,10 +6395,14 @@ rrc_eNB_generate_RRCConnectionReconfiguration_handover(
 */
 
 //-----------------------------------------------------------------------------
+/*
+* 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 protocol_ctxt_t *const ctxt_pP,
+  rrc_eNB_ue_context_t        *ue_context_pP,
   const uint8_t xid
 )
 //-----------------------------------------------------------------------------
@@ -5522,20 +6415,16 @@ rrc_eNB_process_RRCConnectionReconfigurationComplete(
   (void)oip_ifup;
   (void)dest_ip_offset;
 #endif
-
   uint8_t                            *kRRCenc = NULL;
   uint8_t                            *kRRCint = NULL;
   uint8_t                            *kUPenc = NULL;
   ue_context_pP->ue_context.ue_reestablishment_timer = 0;
-
-  DRB_ToAddModList_t*                 DRB_configList = ue_context_pP->ue_context.DRB_configList2[xid];
-  SRB_ToAddModList_t*                 SRB_configList = ue_context_pP->ue_context.SRB_configList2[xid];
-  DRB_ToReleaseList_t*                DRB_Release_configList2 = ue_context_pP->ue_context.DRB_Release_configList2[xid];
-  DRB_Identity_t*                     drb_id_p      = NULL;
-
+  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));
-
 #if defined(ENABLE_SECURITY)
 
   /* Derive the keys from kenb */
@@ -5549,9 +6438,7 @@ rrc_eNB_process_RRCConnectionReconfigurationComplete(
                      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);
-
 #endif
-
   // Refresh SRBs/DRBs
   MSC_LOG_TX_MESSAGE(
     MSC_RRC_ENB,
@@ -5561,12 +6448,11 @@ rrc_eNB_process_RRCConnectionReconfigurationComplete(
     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, 
-//    (DRB_ToReleaseList_t *) NULL,
+    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),
@@ -5575,60 +6461,59 @@ rrc_eNB_process_RRCConnectionReconfigurationComplete(
     kRRCenc,
     kRRCint,
     kUPenc
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-    , (PMCH_InfoList_r9_t *) NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+    , (LTE_PMCH_InfoList_r9_t *) NULL
 #endif
     ,NULL);
   if ( (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_eNB_CU) && 
        (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_ng_eNB_CU)&& 
        (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_CU)   ) {
     // Refresh SRBs/DRBs
-    rrc_rlc_config_asn1_req(
-			    ctxt_pP,
-			    SRB_configList, // NULL,  //LG-RK 14/05/2014 SRB_configList,
-			    DRB_configList,
-			    //    (DRB_ToReleaseList_t *) NULL
-			    DRB_Release_configList2
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-			    , (PMCH_InfoList_r9_t *) NULL
-			    , 0, 0
-#endif
-			    );
+    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);
+      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,
+        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);
+              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
 
   if (DRB_configList != NULL) {
     for (i = 0; i < DRB_configList->list.count; i++) {  // num max DRB (11-3-8)
       if (DRB_configList->list.array[i]) {
-	drb_id = (int)DRB_configList->list.array[i]->drb_Identity;
+        drb_id = (int)DRB_configList->list.array[i]->drb_Identity;
         LOG_I(RRC,
-              "[eNB %d] Frame  %d : Logical Channel UL-DCCH, Received RRCConnectionReconfigurationComplete from UE rnti %x, reconfiguring DRB %d/LCID %d\n",
+              "[eNB %d] Frame  %d : Logical Channel UL-DCCH, Received LTE_RRCConnectionReconfigurationComplete from UE rnti %x, reconfiguring DRB %d/LCID %d\n",
               ctxt_pP->module_id,
               ctxt_pP->frame,
               ctxt_pP->rnti,
@@ -5636,7 +6521,7 @@ rrc_eNB_process_RRCConnectionReconfigurationComplete(
               (int)*DRB_configList->list.array[i]->logicalChannelIdentity);
         // for pre-ci tests
         LOG_I(RRC,
-              "[eNB %d] Frame  %d : Logical Channel UL-DCCH, Received RRCConnectionReconfigurationComplete from UE %u, reconfiguring DRB %d/LCID %d\n",
+              "[eNB %d] Frame  %d : Logical Channel UL-DCCH, Received LTE_RRCConnectionReconfigurationComplete from UE %u, reconfiguring DRB %d/LCID %d\n",
               ctxt_pP->module_id,
               ctxt_pP->frame,
               oai_emulation.info.eNB_ue_local_uid_to_ue_module_id[ctxt_pP->module_id][ue_context_pP->local_uid],
@@ -5663,11 +6548,11 @@ rrc_eNB_process_RRCConnectionReconfigurationComplete(
                 ctxt_pP->module_id);
           oip_ifup = nas_config(
                        ctxt_pP->module_id,   // interface index
-                       ctxt_pP->module_id + 1,   // thrid octet
+                       ctxtReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA_pP->module_id + 1,   // thrid octet
                        ctxt_pP->module_id + 1);  // fourth octet
 
           if (oip_ifup == 0) {    // interface is up --> send a config the DRB
-            module_id_t ue_module_id; 
+            module_id_t ue_module_id;
             dest_ip_offset = 8;
             LOG_I(OIP,
                   "[eNB %d] Config the oai%d to send/receive pkt on DRB %ld to/from the protocol stack\n",
@@ -5687,7 +6572,6 @@ rrc_eNB_process_RRCConnectionReconfigurationComplete(
 
 #   endif
 #endif
-
           LOG_D(RRC,
                 PROTOCOL_RRC_CTXT_UE_FMT" RRC_eNB --- MAC_CONFIG_REQ  (DRB) ---> MAC_eNB\n",
                 PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
@@ -5697,102 +6581,100 @@ rrc_eNB_process_RRCConnectionReconfigurationComplete(
           }
 
 	  if (RC.rrc[ctxt_pP->module_id]->node_type == ngran_eNB) {
-	    rrc_mac_config_req_eNB(
-				   ctxt_pP->module_id,
-				   ue_context_pP->ue_context.primaryCC_id,
-				   0,0,0,0,0,
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-				   0,
-#endif
-				   ue_context_pP->ue_context.rnti,
-				   (BCCH_BCH_Message_t *) NULL,
-				   (RadioResourceConfigCommonSIB_t *) NULL,
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-				   (RadioResourceConfigCommonSIB_t *) NULL,
-#endif
-				   ue_context_pP->ue_context.physicalConfigDedicated,
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-				   (SCellToAddMod_r10_t *)NULL,
-				   //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
-#endif
-				   (MeasObjectToAddMod_t **) NULL,
-				   ue_context_pP->ue_context.mac_MainConfig,
-				   DRB2LCHAN[i],
-				   DRB_configList->list.array[i]->logicalChannelConfig,
-				   ue_context_pP->ue_context.measGapConfig,
-				   (TDD_Config_t *) NULL,
-				   NULL,
-				   (SchedulingInfoList_t *) NULL,
-				   0, NULL, NULL, (MBSFN_SubframeConfigList_t *) NULL
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-				   , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
-#endif
-#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
-				   ,
-				   (SystemInformationBlockType1_v1310_IEs_t *)NULL
+	    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,
+                             DRB2LCHAN[i],
+                             DRB_configList->list.array[i]->logicalChannelConfig,
+                             ue_context_pP->ue_context.measGapConfig,
+                             (LTE_TDD_Config_t *) NULL,
+                             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
-				   );
-	  }
-	} else {        // remove LCHAN from MAC/PHY
+      );
+    }
+  } else {        // remove LCHAN from MAC/PHY
 
         if (ue_context_pP->ue_context.DRB_active[drb_id] == 1) {
             // DRB has just been removed so remove RLC + PDCP for DRB
             /*      rrc_pdcp_config_req (ctxt_pP->module_id, frameP, 1, CONFIG_ACTION_REMOVE,
                (ue_mod_idP * NB_RB_MAX) + DRB2LCHAN[i],UNDEF_SECURITY_MODE);
              */
-	    if ( (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_eNB_CU) ||
-		 (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_ng_eNB_CU) ||
-		 (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_CU)   ) {
-	      rrc_rlc_config_req(
-				 ctxt_pP,
-				 SRB_FLAG_NO,
-				 MBMS_FLAG_NO,
-				 CONFIG_ACTION_REMOVE,
-				 DRB2LCHAN[i],
-				 Rlc_info_um);
-	    }
+          if ( (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_eNB_CU) ||
+             (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_ng_eNB_CU) ||
+             (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_CU)   ) {
+            rrc_rlc_config_req(ctxt_pP,
+                               SRB_FLAG_NO,
+                               MBMS_FLAG_NO,
+                               CONFIG_ACTION_REMOVE,
+                               DRB2LCHAN[i],
+                               Rlc_info_um);
+          }
           }
 
           ue_context_pP->ue_context.DRB_active[drb_id] = 0;
           LOG_D(RRC,
                 PROTOCOL_RRC_CTXT_UE_FMT" RRC_eNB --- MAC_CONFIG_REQ  (DRB) ---> MAC_eNB\n",
                 PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
-	  if (RC.rrc[ctxt_pP->module_id]->node_type == ngran_eNB) {
-	    rrc_mac_config_req_eNB(ctxt_pP->module_id,
-				   ue_context_pP->ue_context.primaryCC_id,
-				   0,0,0,0,0,
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-				   0,
-#endif
-				   ue_context_pP->ue_context.rnti,
-				   (BCCH_BCH_Message_t *) NULL,
-				   (RadioResourceConfigCommonSIB_t *) NULL,
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-				   (RadioResourceConfigCommonSIB_t *) NULL,
-#endif
-				   ue_context_pP->ue_context.physicalConfigDedicated,
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-				   (SCellToAddMod_r10_t *)NULL,
-				   //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
-#endif
-				   (MeasObjectToAddMod_t **) NULL,
-				   ue_context_pP->ue_context.mac_MainConfig,
-				   DRB2LCHAN[i],
-				   (LogicalChannelConfig_t *) NULL,
-				   (MeasGapConfig_t *) NULL,
-				   (TDD_Config_t *) NULL,
-				   NULL, 
-				   (SchedulingInfoList_t *) NULL,
-				   0, NULL, NULL, NULL
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-				   , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
-#endif
-#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
-				   ,
-				   (SystemInformationBlockType1_v1310_IEs_t *)NULL
-#endif
-				   );
-	  }
+          if (RC.rrc[ctxt_pP->module_id]->node_type == ngran_eNB) {
+            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,
+                                   DRB2LCHAN[i],
+                                   (LTE_LogicalChannelConfig_t *) NULL,
+                                   (LTE_MeasGapConfig_t *) NULL,
+                                   (LTE_TDD_Config_t *) NULL,
+                                   NULL,
+                                   (LTE_SchedulingInfoList_t *) NULL,
+                                   0, NULL, NULL, 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
+                                  );
+          }
         }
       }
     }
@@ -5800,34 +6682,39 @@ rrc_eNB_process_RRCConnectionReconfigurationComplete(
     ue_context_pP->ue_context.DRB_configList2[xid] = NULL;
   }
 
-  if(DRB_Release_configList2 != NULL){
-      for (i = 0; i < DRB_Release_configList2->list.count; i++) {
-          if (DRB_Release_configList2->list.array[i]) {
-              drb_id_p = DRB_Release_configList2->list.array[i];
-              drb_id = *drb_id_p;
-              if (ue_context_pP->ue_context.DRB_active[drb_id] == 1) {
-                  ue_context_pP->ue_context.DRB_active[drb_id] = 0;
-              }
-          }
+  if(DRB_Release_configList2 != NULL) {
+    for (i = 0; i < DRB_Release_configList2->list.count; i++) {
+      if (DRB_Release_configList2->list.array[i]) {
+        drb_id_p = DRB_Release_configList2->list.array[i];
+        drb_id = *drb_id_p;
+
+        if (ue_context_pP->ue_context.DRB_active[drb_id] == 1) {
+          ue_context_pP->ue_context.DRB_active[drb_id] = 0;
+        }
       }
-      free(DRB_Release_configList2);
-      ue_context_pP->ue_context.DRB_Release_configList2[xid] = NULL;
+    }
+
+    free(DRB_Release_configList2);
+    ue_context_pP->ue_context.DRB_Release_configList2[xid] = NULL;
   }
 }
 
 //-----------------------------------------------------------------------------
-void
-rrc_eNB_generate_RRCConnectionSetup(
-  const protocol_ctxt_t* const ctxt_pP,
-  rrc_eNB_ue_context_t*          const ue_context_pP,
-  const int                    CC_id
-)
+void rrc_eNB_generate_RRCConnectionSetup(const protocol_ctxt_t *const ctxt_pP,
+					 rrc_eNB_ue_context_t          *const ue_context_pP,
+					 const int                    CC_id
+					 )
 //-----------------------------------------------------------------------------
 {
 
-  LogicalChannelConfig_t             *SRB1_logicalChannelConfig;  //,*SRB2_logicalChannelConfig;
-  SRB_ToAddModList_t                **SRB_configList;
-  SRB_ToAddMod_t                     *SRB1_config;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  boolean_t is_mtc = ctxt_pP->brOption;
+#endif
+
+  LTE_LogicalChannelConfig_t             *SRB1_logicalChannelConfig;  //,*SRB2_logicalChannelConfig;
+  LTE_SRB_ToAddModList_t                **SRB_configList;
+  LTE_SRB_ToAddMod_t                     *SRB1_config;
+
   int                                 cnt;
   MessageDef                            *message_p;
      
@@ -5837,20 +6724,33 @@ rrc_eNB_generate_RRCConnectionSetup(
   eNB_RRC_UE_t *ue_p = &ue_context_pP->ue_context; 
 
   SRB_configList = &ue_p->SRB_configList;
-  ue_p->Srb0.Tx_buffer.payload_size =
-    do_RRCConnectionSetup(ctxt_pP,
-                          ue_context_pP,
-                          CC_id,
-                          (uint8_t*) ue_p->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 *)(ue_p->Srb0.Tx_buffer.Payload),
-              ue_p->Srb0.Tx_buffer.payload_size,
-              "[MSG] RRC Connection Setup\n");
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  if (is_mtc) {
+    ue_p->Srb0.Tx_buffer.payload_size =
+      do_RRCConnectionSetup_BR(ctxt_pP,
+			       ue_context_pP,
+			       CC_id,
+			       (uint8_t*) ue_p->Srb0.Tx_buffer.Payload,
+			       (const 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);
+  } else
+#endif
+  {
+    ue_p->Srb0.Tx_buffer.payload_size =
+      do_RRCConnectionSetup(ctxt_pP,
+                            ue_context_pP,
+                            CC_id,
+                            (uint8_t*) ue_p->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 *)(ue_p->Srb0.Tx_buffer.Payload),
+                ue_p->Srb0.Tx_buffer.payload_size,
+                "[MSG] RRC Connection Setup\n");
 
   // configure SRB1/SRB2, PhysicalConfigDedicated, MAC_MainConfig for UE
    switch (RC.rrc[ctxt_pP->module_id]->node_type){
@@ -5889,7 +6789,7 @@ rrc_eNB_generate_RRCConnectionSetup(
 
         if (SRB1_config->logicalChannelConfig) {
           if (SRB1_config->logicalChannelConfig->present ==
-              SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
+              LTE_SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
             SRB1_logicalChannelConfig = &SRB1_config->logicalChannelConfig->choice.explicitValue;
           } else {
             SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
@@ -5901,46 +6801,46 @@ rrc_eNB_generate_RRCConnectionSetup(
         LOG_D(RRC,
               PROTOCOL_RRC_CTXT_UE_FMT" RRC_eNB --- MAC_CONFIG_REQ  (SRB1) ---> MAC_eNB\n",
               PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
-	if (RC.rrc[ctxt_pP->module_id]->node_type == ngran_eNB) {
-	  rrc_mac_config_req_eNB(
-				 ctxt_pP->module_id,
-				 ue_context_pP->ue_context.primaryCC_id,
-				 0,0,0,0,0,
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-				 0,
-#endif
-				 ue_context_pP->ue_context.rnti,
-				 (BCCH_BCH_Message_t *) NULL,
-				 (RadioResourceConfigCommonSIB_t *) NULL,
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-				 (RadioResourceConfigCommonSIB_t *) NULL,
-#endif
-				 ue_context_pP->ue_context.physicalConfigDedicated,
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-				 (SCellToAddMod_r10_t *)NULL,
-				 //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
-#endif
-				 (MeasObjectToAddMod_t **) NULL,
-				 ue_context_pP->ue_context.mac_MainConfig,
-				 1,
-				 SRB1_logicalChannelConfig,
-				 ue_context_pP->ue_context.measGapConfig,
-				 (TDD_Config_t *) NULL,
-				 NULL,
-				 (SchedulingInfoList_t *) NULL,
-				 0, NULL, NULL, (MBSFN_SubframeConfigList_t *) NULL
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-				 , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
-#endif
-#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
-				 ,
-				 (SystemInformationBlockType1_v1310_IEs_t *)NULL
-#endif
-				 );
-	}
+        if (RC.rrc[ctxt_pP->module_id]->node_type == ngran_eNB) {
+          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,
+                                 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
+          );
+        }
       }
     }
   }
+
   break;
  default : 
     LOG_W(RRC, "Unknown node type %d\n", RC.rrc[ctxt_pP->module_id]->node_type);		
@@ -5967,6 +6867,7 @@ rrc_eNB_generate_RRCConnectionSetup(
    ue_context_pP->ue_context.ue_release_timer=1;
    // remove UE after 10 frames after RRCConnectionRelease is triggered
    ue_context_pP->ue_context.ue_release_timer_thres=1000;
+  }
 }
 
 void setup_ngran_CU(eNB_RRC_INST *rrc) {
@@ -5981,27 +6882,26 @@ openair_rrc_eNB_configuration(
   const module_id_t enb_mod_idP, RrcConfigurationReq *rrc_configuration_req
 )
 #else
-char
-openair_rrc_eNB_init(
-  const module_id_t enb_mod_idP
-)
+char openair_rrc_eNB_init(
+			  const module_id_t enb_mod_idP
+			  )
 #endif
 //-----------------------------------------------------------------------------
 {
   protocol_ctxt_t ctxt;
   int             CC_id;
-
   PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, enb_mod_idP, ENB_FLAG_YES, NOT_A_RNTI, 0, 0,enb_mod_idP);
   LOG_I(RRC,
         PROTOCOL_RRC_CTXT_FMT" Init...\n",
         PROTOCOL_RRC_CTXT_ARGS(&ctxt));
-
 #if OCP_FRAMEWORK
+
   while ( RC.rrc[enb_mod_idP] == NULL ) {
     LOG_E(RRC, "RC.rrc not yet initialized, waiting 1 second\n");
     sleep(1);
   }
-#endif 
+
+#endif
   AssertFatal(RC.rrc[enb_mod_idP] != NULL, "RC.rrc not initialized!");
   AssertFatal(MAX_MOBILES_PER_ENB < (module_id_t)0xFFFFFFFFFFFFFFFF, " variable overflow");
   //    for (j = 0; j < MAX_MOBILES_PER_ENB; j++)
@@ -6029,30 +6929,24 @@ openair_rrc_eNB_init(
   //    for (j = 0; j < (MAX_MOBILES_PER_ENB + 1); j++) {
   //        RC.rrc[enb_mod_idP]->Srb2[j].Active = 0;
   //    }
-
-
   RC.rrc[ctxt.module_id]->initial_id2_s1ap_ids = hashtable_create (MAX_MOBILES_PER_ENB * 2, NULL, NULL);
   RC.rrc[ctxt.module_id]->s1ap_id2_s1ap_ids    = hashtable_create (MAX_MOBILES_PER_ENB * 2, NULL, NULL);
 
   /// System Information INIT
-
   LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Checking release \n",
         PROTOCOL_RRC_CTXT_ARGS(&ctxt));
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
   // can clear it at runtime
   RC.rrc[ctxt.module_id]->carrier[0].MBMS_flag = 0;
-
   // This has to come from some top-level configuration
   // only CC_id 0 is logged
-#if (RRC_VERSION < MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION < MAKE_VERSION(10, 0, 0))
   LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Rel10 RRC detected, MBMS flag %d\n",
 #else
   LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Rel14 RRC detected, MBMS flag %d\n",
 #endif
         PROTOCOL_RRC_CTXT_ARGS(&ctxt),
         RC.rrc[ctxt.module_id]->carrier[0].MBMS_flag);
-
 #else
   LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Rel8 RRC\n", PROTOCOL_RRC_CTXT_ARGS(&ctxt));
 #endif
@@ -6076,7 +6970,6 @@ openair_rrc_eNB_init(
           RC.rrc[ctxt.module_id]->carrier[CC_id].cba_rnti[3],
           RC.rrc[ctxt.module_id]->carrier[CC_id].num_active_cba_groups);
   }
-
 #endif
 
   for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
@@ -6086,32 +6979,33 @@ openair_rrc_eNB_init(
             , &RC.rrc[enb_mod_idP]->configuration
 #endif
            );
+
     for (int ue_id = 0; ue_id < MAX_MOBILES_PER_ENB; ue_id++) {
-        RC.rrc[ctxt.module_id]->carrier[CC_id].sizeof_paging[ue_id] = 0;
-        RC.rrc[ctxt.module_id]->carrier[CC_id].paging[ue_id] = (uint8_t*) malloc16(256);
+      RC.rrc[ctxt.module_id]->carrier[CC_id].sizeof_paging[ue_id] = 0;
+      RC.rrc[ctxt.module_id]->carrier[CC_id].paging[ue_id] = (uint8_t *) malloc16(256);
     }
   }
-
   rrc_init_global_param();
+
   for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
     switch (RC.rrc[ctxt.module_id]->carrier[CC_id].MBMS_flag) {
-    case 1:
-    case 2:
-    case 3:
-      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Configuring 1 MBSFN sync area\n", PROTOCOL_RRC_CTXT_ARGS(&ctxt));
-      RC.rrc[ctxt.module_id]->carrier[CC_id].num_mbsfn_sync_area = 1;
-      break;
+      case 1:
+      case 2:
+      case 3:
+        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Configuring 1 MBSFN sync area\n", PROTOCOL_RRC_CTXT_ARGS(&ctxt));
+        RC.rrc[ctxt.module_id]->carrier[CC_id].num_mbsfn_sync_area = 1;
+        break;
 
-    case 4:
-      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Configuring 2 MBSFN sync area\n", PROTOCOL_RRC_CTXT_ARGS(&ctxt));
-      RC.rrc[ctxt.module_id]->carrier[CC_id].num_mbsfn_sync_area = 2;
-      break;
+      case 4:
+        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Configuring 2 MBSFN sync area\n", PROTOCOL_RRC_CTXT_ARGS(&ctxt));
+        RC.rrc[ctxt.module_id]->carrier[CC_id].num_mbsfn_sync_area = 2;
+        break;
 
-    default:
-      RC.rrc[ctxt.module_id]->carrier[CC_id].num_mbsfn_sync_area = 0;
-      break;
+      default:
+        RC.rrc[ctxt.module_id]->carrier[CC_id].num_mbsfn_sync_area = 0;
+        break;
     }
 
     // if we are here the RC.rrc[enb_mod_idP]->MBMS_flag > 0,
@@ -6121,8 +7015,8 @@ openair_rrc_eNB_init(
       /// MTCH data bearer init
       init_MBMS(ctxt.module_id, CC_id, 0);
     }
-#endif
 
+#endif
     openair_rrc_top_init_eNB(RC.rrc[ctxt.module_id]->carrier[CC_id].MBMS_flag,0);
   }
 	
@@ -6142,7 +7036,6 @@ openair_rrc_eNB_init(
     setup_ngran_CU(RC.rrc[ctxt.module_id]);
 	
   return 0;
-
 }
 
 /*------------------------------------------------------------------------------*/
@@ -6155,21 +7048,18 @@ rrc_eNB_decode_ccch(
 )
 //-----------------------------------------------------------------------------
 {
-  module_id_t                                   Idx;
-  asn_dec_rval_t                      dec_rval;
-  UL_CCCH_Message_t                  *ul_ccch_msg = NULL;
-  RRCConnectionRequest_r8_IEs_t*                rrcConnectionRequest = NULL;
-  RRCConnectionReestablishmentRequest_r8_IEs_t* rrcConnectionReestablishmentRequest = NULL;
+  module_id_t                                       Idx;
+  asn_dec_rval_t                                    dec_rval;
+  LTE_UL_CCCH_Message_t                             *ul_ccch_msg = NULL;
+  LTE_RRCConnectionRequest_r8_IEs_t                *rrcConnectionRequest = NULL;
+  LTE_RRCConnectionReestablishmentRequest_r8_IEs_t *rrcConnectionReestablishmentRequest = NULL;
   int                                 i, rval;
-  struct rrc_eNB_ue_context_s*                  ue_context_p = NULL;
+  struct rrc_eNB_ue_context_s                  *ue_context_p = NULL;
   uint64_t                                      random_value = 0;
   int                                           stmsi_received = 0;
-
   T(T_ENB_RRC_UL_CCCH_DATA_IN, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
     T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
-
   //memset(ul_ccch_msg,0,sizeof(UL_CCCH_Message_t));
-
   LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Decoding UL CCCH %x.%x.%x.%x.%x.%x (%p)\n",
         PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
         ((uint8_t*) buffer)[0],
@@ -6180,14 +7070,13 @@ rrc_eNB_decode_ccch(
         ((uint8_t *) buffer)[5], (uint8_t *) buffer);
   dec_rval = uper_decode(
                NULL,
-               &asn_DEF_UL_CCCH_Message,
-               (void**)&ul_ccch_msg,
-               (uint8_t*) buffer,
+               &asn_DEF_LTE_UL_CCCH_Message,
+               (void **)&ul_ccch_msg,
+               (uint8_t *) buffer,
                100,
                0,
                0);
 
-
   for (i = 0; i < 8; i++) {
     LOG_T(RRC, "%x.", ((uint8_t *) & ul_ccch_msg)[i]);
   }
@@ -6199,518 +7088,499 @@ rrc_eNB_decode_ccch(
     return -1;
   }
 
-  if (ul_ccch_msg->message.present == UL_CCCH_MessageType_PR_c1) {
-
+  if (ul_ccch_msg->message.present == LTE_UL_CCCH_MessageType_PR_c1) {
     switch (ul_ccch_msg->message.choice.c1.present) {
+      case LTE_UL_CCCH_MessageType__c1_PR_NOTHING:
+        LOG_I(RRC,
+              PROTOCOL_RRC_CTXT_FMT" Received PR_NOTHING on UL-CCCH-Message\n",
+              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
+        break;
 
-    case UL_CCCH_MessageType__c1_PR_NOTHING:
-      LOG_I(RRC,
-            PROTOCOL_RRC_CTXT_FMT" Received PR_NOTHING on UL-CCCH-Message\n",
-            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
-      break;
+      case LTE_UL_CCCH_MessageType__c1_PR_rrcConnectionReestablishmentRequest:
+        T(T_ENB_RRC_CONNECTION_REESTABLISHMENT_REQUEST, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
+          T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
+        LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)(buffer), buffer_length,
+                    "[MSG] RRC Connection Reestablishment Request\n");
+        LOG_D(RRC,
+              PROTOCOL_RRC_CTXT_UE_FMT"MAC_eNB--- MAC_DATA_IND (rrcConnectionReestablishmentRequest on SRB0) --> RRC_eNB\n",
+              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
+        rrcConnectionReestablishmentRequest =
+          &ul_ccch_msg->message.choice.c1.choice.rrcConnectionReestablishmentRequest.criticalExtensions.choice.rrcConnectionReestablishmentRequest_r8;
+        LOG_I(RRC,
+              PROTOCOL_RRC_CTXT_UE_FMT" LTE_RRCConnectionReestablishmentRequest cause %s\n",
+              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
+              ((rrcConnectionReestablishmentRequest->reestablishmentCause == LTE_ReestablishmentCause_otherFailure) ?    "Other Failure" :
+               (rrcConnectionReestablishmentRequest->reestablishmentCause == LTE_ReestablishmentCause_handoverFailure) ? "Handover Failure" :
+               "reconfigurationFailure"));
+        /*{
+        uint64_t                            c_rnti = 0;
+
+        memcpy(((uint8_t *) & c_rnti) + 3, rrcConnectionReestablishmentRequest.UE_identity.c_RNTI.buf,
+        rrcConnectionReestablishmentRequest.UE_identity.c_RNTI.size);
+        ue_mod_id = rrc_eNB_get_UE_index(enb_mod_idP, c_rnti);
+        }
 
-    case UL_CCCH_MessageType__c1_PR_rrcConnectionReestablishmentRequest:
-      T(T_ENB_RRC_CONNECTION_REESTABLISHMENT_REQUEST, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
-        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
+        if ((RC.rrc[enb_mod_idP]->phyCellId == rrcConnectionReestablishmentRequest.UE_identity.physCellId) &&
+        (ue_mod_id != UE_INDEX_INVALID)){
+        rrc_eNB_generate_RRCConnectionReestablishment(enb_mod_idP, frameP, ue_mod_id);
+        }else {
+        rrc_eNB_generate_RRCConnectionReestablishmentReject(enb_mod_idP, frameP, ue_mod_id);
+        }
+        */
+        /* reject all reestablishment attempts for the moment */
+        //      rrc_eNB_generate_RRCConnectionReestablishmentReject(ctxt_pP,
+        //                       rrc_eNB_get_ue_context(RC.rrc[ctxt_pP->module_id], ctxt_pP->rnti),
+        //                       CC_id);
+        {
+          uint16_t                          c_rnti = 0;
 
-      LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)(buffer),
-                  buffer_length,
-                  "[MSG] RRC Connection Reestablishment Request\n");
+          if (rrcConnectionReestablishmentRequest->ue_Identity.physCellId != RC.rrc[ctxt_pP->module_id]->carrier[CC_id].physCellId) {
+            LOG_E(RRC,
+                  PROTOCOL_RRC_CTXT_UE_FMT" LTE_RRCConnectionReestablishmentRequest ue_Identity.physCellId(%ld) is not equal to current physCellId(%d), let's reject the UE\n",
+                  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
+                  rrcConnectionReestablishmentRequest->ue_Identity.physCellId,
+                  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].physCellId);
+            rrc_eNB_generate_RRCConnectionReestablishmentReject(ctxt_pP, ue_context_p, CC_id);
+            break;
+          }
 
-      LOG_D(RRC,
-            PROTOCOL_RRC_CTXT_UE_FMT"MAC_eNB--- MAC_DATA_IND (rrcConnectionReestablishmentRequest on SRB0) --> RRC_eNB\n",
-            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
-      rrcConnectionReestablishmentRequest =
-        &ul_ccch_msg->message.choice.c1.choice.rrcConnectionReestablishmentRequest.criticalExtensions.choice.rrcConnectionReestablishmentRequest_r8;
-      LOG_I(RRC,
-            PROTOCOL_RRC_CTXT_UE_FMT" RRCConnectionReestablishmentRequest cause %s\n",
-            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
-            ((rrcConnectionReestablishmentRequest->reestablishmentCause == ReestablishmentCause_otherFailure) ?    "Other Failure" :
-             (rrcConnectionReestablishmentRequest->reestablishmentCause == ReestablishmentCause_handoverFailure) ? "Handover Failure" :
-             "reconfigurationFailure"));
-      /*{
-      uint64_t                            c_rnti = 0;
-
-      memcpy(((uint8_t *) & c_rnti) + 3, rrcConnectionReestablishmentRequest.UE_identity.c_RNTI.buf,
-      rrcConnectionReestablishmentRequest.UE_identity.c_RNTI.size);
-      ue_mod_id = rrc_eNB_get_UE_index(enb_mod_idP, c_rnti);
-      }
+          LOG_D(RRC, "physCellId is %ld\n", rrcConnectionReestablishmentRequest->ue_Identity.physCellId);
 
-      if ((RC.rrc[enb_mod_idP]->phyCellId == rrcConnectionReestablishmentRequest.UE_identity.physCellId) &&
-      (ue_mod_id != UE_INDEX_INVALID)){
-      rrc_eNB_generate_RRCConnectionReestablishment(enb_mod_idP, frameP, ue_mod_id);
-      }else {
-      rrc_eNB_generate_RRCConnectionReestablishmentReject(enb_mod_idP, frameP, ue_mod_id);
-      }
-      */
-      /* reject all reestablishment attempts for the moment */
-//      rrc_eNB_generate_RRCConnectionReestablishmentReject(ctxt_pP,
-//                       rrc_eNB_get_ue_context(RC.rrc[ctxt_pP->module_id], ctxt_pP->rnti),
-//                       CC_id);
-{
-      uint16_t                          c_rnti = 0;
+          for (i = 0; i < rrcConnectionReestablishmentRequest->ue_Identity.shortMAC_I.size; i++) {
+            LOG_D(RRC, "rrcConnectionReestablishmentRequest->ue_Identity.shortMAC_I.buf[%d] = %x\n",
+                  i, rrcConnectionReestablishmentRequest->ue_Identity.shortMAC_I.buf[i]);
+          }
 
-      if (rrcConnectionReestablishmentRequest->ue_Identity.physCellId != RC.rrc[ctxt_pP->module_id]->carrier[CC_id].physCellId) {
-        LOG_E(RRC,
-              PROTOCOL_RRC_CTXT_UE_FMT" RRCConnectionReestablishmentRequest ue_Identity.physCellId(%ld) is not equal to current physCellId(%d), let's reject the UE\n",
-              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
-              rrcConnectionReestablishmentRequest->ue_Identity.physCellId,
-              RC.rrc[ctxt_pP->module_id]->carrier[CC_id].physCellId);
-        rrc_eNB_generate_RRCConnectionReestablishmentReject(ctxt_pP, ue_context_p, CC_id);
-        break;
-      }
-      LOG_D(RRC, "physCellId is %ld\n", rrcConnectionReestablishmentRequest->ue_Identity.physCellId);
+          if (rrcConnectionReestablishmentRequest->ue_Identity.c_RNTI.size == 0 ||
+              rrcConnectionReestablishmentRequest->ue_Identity.c_RNTI.size > 2) {
+            LOG_E(RRC,
+                  PROTOCOL_RRC_CTXT_UE_FMT" LTE_RRCConnectionReestablishmentRequest c_RNTI range error, let's reject the UE\n",
+                  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
+            rrc_eNB_generate_RRCConnectionReestablishmentReject(ctxt_pP, ue_context_p, CC_id);
+            break;
+          }
 
-      for (i = 0; i < rrcConnectionReestablishmentRequest->ue_Identity.shortMAC_I.size; i++) {
-        LOG_D(RRC, "rrcConnectionReestablishmentRequest->ue_Identity.shortMAC_I.buf[%d] = %x\n",
-            i, rrcConnectionReestablishmentRequest->ue_Identity.shortMAC_I.buf[i]);
-      }
+          c_rnti = BIT_STRING_to_uint16(&rrcConnectionReestablishmentRequest->ue_Identity.c_RNTI);
+          LOG_D(RRC, "c_rnti is %x\n", c_rnti);
+          ue_context_p = rrc_eNB_get_ue_context(RC.rrc[ctxt_pP->module_id], c_rnti);
 
-      if (rrcConnectionReestablishmentRequest->ue_Identity.c_RNTI.size == 0 ||
-          rrcConnectionReestablishmentRequest->ue_Identity.c_RNTI.size > 2) {
-        LOG_E(RRC,
-              PROTOCOL_RRC_CTXT_UE_FMT" RRCConnectionReestablishmentRequest c_RNTI range error, let's reject the UE\n",
-              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
-        rrc_eNB_generate_RRCConnectionReestablishmentReject(ctxt_pP, ue_context_p, CC_id);
-        break;
+          if (ue_context_p == NULL) {
+            LOG_E(RRC,
+                  PROTOCOL_RRC_CTXT_UE_FMT" LTE_RRCConnectionReestablishmentRequest without UE context, let's reject the UE\n",
+                  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
+            rrc_eNB_generate_RRCConnectionReestablishmentReject(ctxt_pP, ue_context_p, CC_id);
+            break;
+          }
 
-      }
+          int UE_id = find_UE_id(ctxt_pP->module_id, c_rnti);
 
-      c_rnti = BIT_STRING_to_uint16(&rrcConnectionReestablishmentRequest->ue_Identity.c_RNTI);
-      LOG_D(RRC, "c_rnti is %x\n", c_rnti);
+          if(UE_id == -1) {
+            LOG_E(RRC,
+                  PROTOCOL_RRC_CTXT_UE_FMT" LTE_RRCConnectionReestablishmentRequest without UE_id(MAC) rnti %x, let's reject the UE\n",
+                  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),c_rnti);
+            rrc_eNB_generate_RRCConnectionReestablishmentReject(ctxt_pP, ue_context_p, CC_id);
+            break;
+          }
 
-      ue_context_p = rrc_eNB_get_ue_context(RC.rrc[ctxt_pP->module_id], c_rnti);
-      if (ue_context_p == NULL) {
-        LOG_E(RRC,
-              PROTOCOL_RRC_CTXT_UE_FMT" RRCConnectionReestablishmentRequest without UE context, let's reject the UE\n",
-              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
-        rrc_eNB_generate_RRCConnectionReestablishmentReject(ctxt_pP, ue_context_p, CC_id);
-        break;
-      }
-      if ( (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_eNB_CU) &&
-       (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_ng_eNB_CU)&& 
-       (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_CU)   ) {
-  		int UE_id = find_UE_id(ctxt_pP->module_id, c_rnti);
-      	if(UE_id == -1){
-          LOG_E(RRC,
-                PROTOCOL_RRC_CTXT_UE_FMT" RRCConnectionReestablishmentRequest without UE_id(MAC) rnti %x, let's reject the UE\n",
-                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),c_rnti);
-          rrc_eNB_generate_RRCConnectionReestablishmentReject(ctxt_pP, ue_context_p, CC_id);
-          break;
-      	}
-	    if((RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].ue_reestablishment_reject_timer > 0) &&
-	         (RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].ue_reestablishment_reject_timer_thres > 20)){
-	      LOG_E(RRC,
-	             PROTOCOL_RRC_CTXT_UE_FMT" RCConnectionReestablishmentComplete(Previous) don't receive, delete the Previous UE\n",
-	             PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
-	      RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].ue_reestablishment_reject_timer = 1000;
-	      ue_context_p->ue_context.ue_reestablishment_timer = 0;
-	    }
-  	 }	
-      if(ue_context_p->ue_context.ue_reestablishment_timer > 0){
-    	  LOG_E(RRC,
-                PROTOCOL_RRC_CTXT_UE_FMT" RRRCConnectionReconfigurationComplete(Previous) don't receive, delete the Previous UE\n",
-                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
-          ue_context_p->ue_context.Status = RRC_RECONFIGURED;
-          protocol_ctxt_t  ctxt_old_p;
-          PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt_old_p,
-                                        ctxt_pP->instance,
-                                        ENB_FLAG_YES,
-                                        c_rnti,
-                                        ctxt_pP->frame,
-                                        ctxt_pP->subframe);
-          rrc_eNB_process_RRCConnectionReconfigurationComplete(&ctxt_old_p,
-                                                                ue_context_p,
-                                                                ue_context_p->ue_context.reestablishment_xid);
-          LOG_E(RRC, "RRRCConnectionReconfigurationComplete: ue_context_p->ue_context.nb_of_e_rabs = %d \n", ue_context_p->ue_context.nb_of_e_rabs);
-          for (uint8_t e_rab = 0; e_rab < ue_context_p->ue_context.nb_of_e_rabs; e_rab++) {
-            LOG_E(RRC, "RRRCConnectionReconfigurationComplete: ue_context_p->ue_context.e_rab[e_rab].status = %d \n", ue_context_p->ue_context.e_rab[e_rab].status);
-            if (ue_context_p->ue_context.e_rab[e_rab].status == E_RAB_STATUS_DONE) {
-              ue_context_p->ue_context.e_rab[e_rab].status = E_RAB_STATUS_ESTABLISHED;
-            } else {
-              ue_context_p->ue_context.e_rab[e_rab].status = E_RAB_STATUS_FAILED;
+          if((RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].ue_reestablishment_reject_timer > 0) &&
+              (RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].ue_reestablishment_reject_timer_thres > 20)) {
+            LOG_E(RRC,
+                  PROTOCOL_RRC_CTXT_UE_FMT" RCConnectionReestablishmentComplete(Previous) don't receive, delete the Previous UE\n",
+                  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
+            RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].ue_reestablishment_reject_timer = 1000;
+            ue_context_p->ue_context.ue_reestablishment_timer = 0;
+          }
+
+          if(ue_context_p->ue_context.ue_reestablishment_timer > 0) {
+            LOG_E(RRC,
+                  PROTOCOL_RRC_CTXT_UE_FMT" RRRCConnectionReconfigurationComplete(Previous) don't receive, delete the Previous UE\n",
+                  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
+            ue_context_p->ue_context.Status = RRC_RECONFIGURED;
+            protocol_ctxt_t  ctxt_old_p;
+            PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt_old_p,
+                                          ctxt_pP->instance,
+                                          ENB_FLAG_YES,
+                                          c_rnti,
+                                          ctxt_pP->frame,
+                                          ctxt_pP->subframe);
+            rrc_eNB_process_RRCConnectionReconfigurationComplete(&ctxt_old_p,
+                ue_context_p,
+                ue_context_p->ue_context.reestablishment_xid);
+
+            for (uint8_t e_rab = 0; e_rab < ue_context_p->ue_context.nb_of_e_rabs; e_rab++) {
+              if (ue_context_p->ue_context.e_rab[e_rab].status == E_RAB_STATUS_DONE) {
+                ue_context_p->ue_context.e_rab[e_rab].status = E_RAB_STATUS_ESTABLISHED;
+              } else {
+                ue_context_p->ue_context.e_rab[e_rab].status = E_RAB_STATUS_FAILED;
+              }
+            }
+          }
+
+          LOG_D(RRC,
+                PROTOCOL_RRC_CTXT_UE_FMT" UE context: %p\n",
+                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
+                ue_context_p);
+          /* reset timers */
+          ue_context_p->ue_context.ul_failure_timer = 0;
+          ue_context_p->ue_context.ue_release_timer = 0;
+          ue_context_p->ue_context.ue_reestablishment_timer = 0;
+          ue_context_p->ue_context.ue_release_timer_s1 = 0;
+          ue_context_p->ue_context.ue_release_timer_rrc = 0;
+          ue_context_p->ue_context.reestablishment_xid = -1;
+
+          // insert C-RNTI to map
+          for (i = 0; i < MAX_MOBILES_PER_ENB; i++) {
+            if (reestablish_rnti_map[i][0] == 0) {
+              reestablish_rnti_map[i][0] = ctxt_pP->rnti;
+              reestablish_rnti_map[i][1] = c_rnti;
+              break;
             }
           }
-      }
-      LOG_D(RRC,
-            PROTOCOL_RRC_CTXT_UE_FMT" UE context: %p\n",
-            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
-            ue_context_p);
-      /* reset timers */
-      ue_context_p->ue_context.ul_failure_timer = 0;
-      ue_context_p->ue_context.ue_release_timer = 0;
-      ue_context_p->ue_context.ue_reestablishment_timer = 0;
-      ue_context_p->ue_context.ue_release_timer_s1 = 0;
-      ue_context_p->ue_context.ue_release_timer_rrc = 0;
-      ue_context_p->ue_context.reestablishment_xid = -1;
-
-      // insert C-RNTI to map
-      for (i = 0; i < MAX_MOBILES_PER_ENB; i++) {
-        if (reestablish_rnti_map[i][0] == 0) {
-          reestablish_rnti_map[i][0] = ctxt_pP->rnti;
-          reestablish_rnti_map[i][1] = c_rnti;
-          break;
-        }
-      }
-      LOG_D(RRC, "reestablish_rnti_map[%d] [0] %x, [1] %x\n",
-            i, reestablish_rnti_map[i][0], reestablish_rnti_map[i][1]);
 
+          LOG_D(RRC, "reestablish_rnti_map[%d] [0] %x, [1] %x\n",
+                i, reestablish_rnti_map[i][0], reestablish_rnti_map[i][1]);
 #if defined(ENABLE_ITTI)
-      ue_context_p->ue_context.reestablishment_cause = rrcConnectionReestablishmentRequest->reestablishmentCause;
-      LOG_D(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Accept connection reestablishment request from UE physCellId %ld cause %ld\n",
-            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
-            rrcConnectionReestablishmentRequest->ue_Identity.physCellId,
-            ue_context_p->ue_context.reestablishment_cause);
+          ue_context_p->ue_context.reestablishment_cause = rrcConnectionReestablishmentRequest->reestablishmentCause;
+          LOG_D(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Accept connection reestablishment request from UE physCellId %ld cause %ld\n",
+                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
+                rrcConnectionReestablishmentRequest->ue_Identity.physCellId,
+                ue_context_p->ue_context.reestablishment_cause);
 #else
-        LOG_D(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Accept connection restablishment request for UE\n",
-              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
+          LOG_D(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Accept connection restablishment request for UE\n",
+                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
 #endif
-
 #ifndef NO_RRM
-      send_msg(&S_rrc, msg_rrc_MR_attach_ind(ctxt_pP->module_id, Mac_id));
+          send_msg(&S_rrc, msg_rrc_MR_attach_ind(ctxt_pP->module_id, Mac_id));
 #else
-
-      ue_context_p->ue_context.primaryCC_id = CC_id;
-
-      //LG COMMENT Idx = (ue_mod_idP * NB_RB_MAX) + DCCH;
-      Idx = DCCH;
-      // SRB1
-      ue_context_p->ue_context.Srb1.Active = 1;
-      ue_context_p->ue_context.Srb1.Srb_info.Srb_id = Idx;
-      memcpy(&ue_context_p->ue_context.Srb1.Srb_info.Lchan_desc[0],
-             &DCCH_LCHAN_DESC,
-             LCHAN_DESC_SIZE);
-      memcpy(&ue_context_p->ue_context.Srb1.Srb_info.Lchan_desc[1],
-             &DCCH_LCHAN_DESC,
-             LCHAN_DESC_SIZE);
-
-      // SRB2: set  it to go through SRB1 with id 1 (DCCH)
-      ue_context_p->ue_context.Srb2.Active = 1;
-      ue_context_p->ue_context.Srb2.Srb_info.Srb_id = Idx;
-      memcpy(&ue_context_p->ue_context.Srb2.Srb_info.Lchan_desc[0],
-             &DCCH_LCHAN_DESC,
-             LCHAN_DESC_SIZE);
-      memcpy(&ue_context_p->ue_context.Srb2.Srb_info.Lchan_desc[1],
-             &DCCH_LCHAN_DESC,
-             LCHAN_DESC_SIZE);
-
-      rrc_eNB_generate_RRCConnectionReestablishment(ctxt_pP, ue_context_p, CC_id);
-      LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT"CALLING RLC CONFIG SRB1 (rbid %d)\n",
-            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
-            Idx);
-
-      MSC_LOG_TX_MESSAGE(MSC_RRC_ENB,
-                         MSC_PDCP_ENB,
-                         NULL,
-                         0,
-                         MSC_AS_TIME_FMT" CONFIG_REQ UE %x SRB",
-                         MSC_AS_TIME_ARGS(ctxt_pP),
-                         ue_context_p->ue_context.rnti);
-
-      rrc_pdcp_config_asn1_req(ctxt_pP,
-                               ue_context_p->ue_context.SRB_configList,
-                               (DRB_ToAddModList_t *) NULL,
-                               (DRB_ToReleaseList_t*) NULL,
-                               0xff,
-                               NULL,
-                               NULL,
-                               NULL
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-                               , (PMCH_InfoList_r9_t *) NULL
-#endif
-                               ,NULL);
-
-      if ( (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_eNB_CU) &&
-	   (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_ng_eNB_CU)&& 
-	   (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_CU)   ) {
-	rrc_rlc_config_asn1_req(ctxt_pP,
-				ue_context_p->ue_context.SRB_configList,
-				(DRB_ToAddModList_t*) NULL,
-				(DRB_ToReleaseList_t*) NULL
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-				, (PMCH_InfoList_r9_t *) NULL,
-				0,0
+          ue_context_p->ue_context.primaryCC_id = CC_id;
+          //LG COMMENT Idx = (ue_mod_idP * NB_RB_MAX) + DCCH;
+          Idx = DCCH;
+          // SRB1
+          ue_context_p->ue_context.Srb1.Active = 1;
+          ue_context_p->ue_context.Srb1.Srb_info.Srb_id = Idx;
+          memcpy(&ue_context_p->ue_context.Srb1.Srb_info.Lchan_desc[0],
+                 &DCCH_LCHAN_DESC,
+                 LCHAN_DESC_SIZE);
+          memcpy(&ue_context_p->ue_context.Srb1.Srb_info.Lchan_desc[1],
+                 &DCCH_LCHAN_DESC,
+                 LCHAN_DESC_SIZE);
+          // SRB2: set  it to go through SRB1 with id 1 (DCCH)
+          ue_context_p->ue_context.Srb2.Active = 1;
+          ue_context_p->ue_context.Srb2.Srb_info.Srb_id = Idx;
+          memcpy(&ue_context_p->ue_context.Srb2.Srb_info.Lchan_desc[0],
+                 &DCCH_LCHAN_DESC,
+                 LCHAN_DESC_SIZE);
+          memcpy(&ue_context_p->ue_context.Srb2.Srb_info.Lchan_desc[1],
+                 &DCCH_LCHAN_DESC,
+                 LCHAN_DESC_SIZE);
+          rrc_eNB_generate_RRCConnectionReestablishment(ctxt_pP, ue_context_p, CC_id);
+          LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT"CALLING RLC CONFIG SRB1 (rbid %d)\n",
+                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
+                Idx);
+          MSC_LOG_TX_MESSAGE(MSC_RRC_ENB,
+                             MSC_PDCP_ENB,
+                             NULL,
+                             0,
+                             MSC_AS_TIME_FMT" CONFIG_REQ UE %x SRB",
+                             MSC_AS_TIME_ARGS(ctxt_pP),
+                             ue_context_p->ue_context.rnti);
+          rrc_pdcp_config_asn1_req(ctxt_pP,
+                                   ue_context_p->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);
+          if ((RC.rrc[ctxt_pP->module_id]->node_type  != ngran_eNB_CU) &&
+             (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_ng_eNB_CU)&&
+             (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_CU)   ) {
+            rrc_rlc_config_asn1_req(ctxt_pP,
+                                    ue_context_p->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
-				);
-      }
-
+                                   );
+        }
 #endif //NO_RRM
-	}
-    break;
+        }
+        break;
 
-    case UL_CCCH_MessageType__c1_PR_rrcConnectionRequest:
-      T(T_ENB_RRC_CONNECTION_REQUEST, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
-        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
+      case LTE_UL_CCCH_MessageType__c1_PR_rrcConnectionRequest:
+        T(T_ENB_RRC_CONNECTION_REQUEST, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
+          T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
 
       LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,
                   buffer_length,
-                  "[MSG] RRC Connection Request\n");
-
-      LOG_D(RRC,
-            PROTOCOL_RRC_CTXT_UE_FMT"MAC_eNB --- MAC_DATA_IND  (rrcConnectionRequest on SRB0) --> RRC_eNB\n",
-            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
-      ue_context_p = rrc_eNB_get_ue_context(
-                       RC.rrc[ctxt_pP->module_id],
-                       ctxt_pP->rnti);
-
-      if (ue_context_p != NULL) {
-      	LOG_D(RRC,"ue_context_p already exist %p %d %x \n", ue_context_p, ctxt_pP->module_id, ctxt_pP->rnti);
-        // erase content
-        rrc_eNB_free_mem_UE_context(ctxt_pP, ue_context_p);
+                    "[MSG] RRC Connection Request\n");
+        LOG_D(RRC,
+              PROTOCOL_RRC_CTXT_UE_FMT"MAC_eNB --- MAC_DATA_IND  (rrcConnectionRequest on SRB0) --> RRC_eNB\n",
+              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
+        ue_context_p = rrc_eNB_get_ue_context(
+                         RC.rrc[ctxt_pP->module_id],
+                         ctxt_pP->rnti);
 
-        MSC_LOG_RX_DISCARDED_MESSAGE(
-          MSC_RRC_ENB,
-          MSC_RRC_UE,
-          buffer,
-          dec_rval.consumed,
-          MSC_AS_TIME_FMT" RRCConnectionRequest UE %x size %u (UE already in context)",
-          MSC_AS_TIME_ARGS(ctxt_pP),
-          ue_context_p->ue_context.rnti,
-          dec_rval.consumed);
-      } else {
-        rrcConnectionRequest = &ul_ccch_msg->message.choice.c1.choice.rrcConnectionRequest.criticalExtensions.choice.rrcConnectionRequest_r8;
-        {
-          if (InitialUE_Identity_PR_randomValue == rrcConnectionRequest->ue_Identity.present) {
-	    if(rrcConnectionRequest->ue_Identity.choice.randomValue.size != 5)
-	      {
-		LOG_I(RRC, "wrong InitialUE-Identity randomValue size, expected 5, provided %lu",
-		      (long unsigned int)rrcConnectionRequest->ue_Identity.choice.randomValue.size);
-		return -1;
-	      }
-            memcpy(((uint8_t*) & random_value) + 3,
-                   rrcConnectionRequest->ue_Identity.choice.randomValue.buf,
-                   rrcConnectionRequest->ue_Identity.choice.randomValue.size);
-            /* if there is already a registered UE (with another RNTI) with this random_value,
-             * the current one must be removed from MAC/PHY (zombie UE)
-             */
-            if ((ue_context_p = rrc_eNB_ue_context_random_exist(ctxt_pP, random_value))) {
-              LOG_W(RRC, "new UE rnti %x (coming with random value) is already there as UE %x, removing %x from MAC/PHY\n",
-                    ctxt_pP->rnti, ue_context_p->ue_context.rnti, ue_context_p->ue_context.rnti);
-              ue_context_p->ue_context.ul_failure_timer = 20000;
-            }
-            ue_context_p = rrc_eNB_get_next_free_ue_context(ctxt_pP, random_value);
-	    	ue_context_p->ue_context.Srb0.Srb_id=0;
-	    	ue_context_p->ue_context.Srb0.Active=1;
-	    	memcpy(ue_context_p->ue_context.Srb0.Rx_buffer.Payload,
-	    		   buffer,
-	    		   buffer_length);
-
-	    	ue_context_p->ue_context.Srb0.Rx_buffer.payload_size=buffer_length;
-
-          } else if (InitialUE_Identity_PR_s_TMSI == rrcConnectionRequest->ue_Identity.present) {
-            /* Save s-TMSI */
-            S_TMSI_t   s_TMSI = rrcConnectionRequest->ue_Identity.choice.s_TMSI;
-            mme_code_t mme_code = BIT_STRING_to_uint8(&s_TMSI.mmec);
-            m_tmsi_t   m_tmsi   = BIT_STRING_to_uint32(&s_TMSI.m_TMSI);
-            random_value = (((uint64_t)mme_code) << 32) | m_tmsi;
-            if ((ue_context_p = rrc_eNB_ue_context_stmsi_exist(ctxt_pP, mme_code, m_tmsi))) {
-	      LOG_I(RRC," S-TMSI exists, ue_context_p %p, old rnti %x => %x\n",ue_context_p,ue_context_p->ue_context.rnti,ctxt_pP->rnti);
-
-	      if ( (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_eNB_CU) ||
-		   (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_ng_eNB_CU) ||
-		   (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_CU)   ) {
-		rrc_mac_remove_ue(ctxt_pP->module_id, ue_context_p->ue_context.rnti);
-	      }
-	      else {
-                MessageDef *m = itti_alloc_new_message(TASK_RRC_ENB, F1AP_UE_CONTEXT_RELEASE_CMD);
-                F1AP_UE_CONTEXT_RELEASE_CMD(m).rnti = ctxt_pP->rnti;
-                F1AP_UE_CONTEXT_RELEASE_CMD(m).cause = F1AP_CAUSE_RADIO_NETWORK;
-                F1AP_UE_CONTEXT_RELEASE_CMD(m).cause_value = 10; // 10 = F1AP_CauseRadioNetwork_normal_release
-                F1AP_UE_CONTEXT_RELEASE_CMD(m).rrc_container = NULL;
-                F1AP_UE_CONTEXT_RELEASE_CMD(m).rrc_container_length = 0;
-                itti_send_msg_to_task(TASK_CU_F1, ctxt_pP->module_id, m);
-	      }
-	      stmsi_received=1;
-              /* replace rnti in the context */
-              /* for that, remove the context from the RB tree */
-              RB_REMOVE(rrc_ue_tree_s, &RC.rrc[ctxt_pP->module_id]->rrc_ue_head, ue_context_p);
-              /* and insert again, after changing rnti everywhere it has to be changed */
-              ue_context_p->ue_id_rnti = ctxt_pP->rnti;
-	      ue_context_p->ue_context.rnti = ctxt_pP->rnti;
-              RB_INSERT(rrc_ue_tree_s, &RC.rrc[ctxt_pP->module_id]->rrc_ue_head, ue_context_p);
-              /* reset timers */
-              ue_context_p->ue_context.ul_failure_timer = 0;
-              ue_context_p->ue_context.ue_release_timer = 0;
-              ue_context_p->ue_context.ue_reestablishment_timer = 0;
-              ue_context_p->ue_context.ue_release_timer_s1 = 0;
-              ue_context_p->ue_context.ue_release_timer_rrc = 0;
-              ue_context_p->ue_context.reestablishment_xid = -1;
-            } else {
-	      LOG_I(RRC," S-TMSI doesn't exist, setting Initialue_identity_s_TMSI.m_tmsi to %p => %x\n",ue_context_p,m_tmsi);
-//              ue_context_p = rrc_eNB_get_next_free_ue_context(ctxt_pP, NOT_A_RANDOM_UE_IDENTITY);
-              ue_context_p = rrc_eNB_get_next_free_ue_context(ctxt_pP,random_value);
-              if (ue_context_p == NULL)
-                LOG_E(RRC, "%s:%d:%s: rrc_eNB_get_next_free_ue_context returned NULL\n", __FILE__, __LINE__, __FUNCTION__);
-              if (ue_context_p != NULL) {
-	        ue_context_p->ue_context.Initialue_identity_s_TMSI.presence = TRUE;
-	        ue_context_p->ue_context.Initialue_identity_s_TMSI.mme_code = mme_code;
-	        ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi = m_tmsi;
-              } else {
-                /* TODO: do we have to break here? */
-                //break;
+        if (ue_context_p != NULL) {
+          // erase content
+          rrc_eNB_free_mem_UE_context(ctxt_pP, ue_context_p);
+          MSC_LOG_RX_DISCARDED_MESSAGE(
+            MSC_RRC_ENB,
+            MSC_RRC_UE,
+            buffer,
+            dec_rval.consumed,
+            MSC_AS_TIME_FMT" LTE_RRCConnectionRequest UE %x size %u (UE already in context)",
+            MSC_AS_TIME_ARGS(ctxt_pP),
+            ue_context_p->ue_context.rnti,
+            dec_rval.consumed);
+        } else {
+          rrcConnectionRequest = &ul_ccch_msg->message.choice.c1.choice.rrcConnectionRequest.criticalExtensions.choice.rrcConnectionRequest_r8;
+          {
+            if (LTE_InitialUE_Identity_PR_randomValue == rrcConnectionRequest->ue_Identity.present) {
+              if(rrcConnectionRequest->ue_Identity.choice.randomValue.size != 5) {
+                LOG_I(RRC, "wrong InitialUE-Identity randomValue size, expected 5, provided %lu",
+                      (long unsigned int)rrcConnectionRequest->ue_Identity.choice.randomValue.size);
+                return -1;
               }
-            }
 
-            MSC_LOG_RX_MESSAGE(
-              MSC_RRC_ENB,
-              MSC_RRC_UE,
-              buffer,
-              dec_rval.consumed,
-              MSC_AS_TIME_FMT" RRCConnectionRequest UE %x size %u (s-TMSI mmec %u m_TMSI %u random UE id (0x%" PRIx64 ")",
-              MSC_AS_TIME_ARGS(ctxt_pP),
-              ue_context_p->ue_context.rnti,
-              dec_rval.consumed,
-              ue_context_p->ue_context.Initialue_identity_s_TMSI.mme_code,
-              ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi,
-              ue_context_p->ue_context.random_ue_identity);
-          } else {
-            LOG_E(RRC,
-                  PROTOCOL_RRC_CTXT_UE_FMT" RRCConnectionRequest without random UE identity or S-TMSI not supported, let's reject the UE\n",
-                  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
-            rrc_eNB_generate_RRCConnectionReject(ctxt_pP,
-						 rrc_eNB_get_ue_context(RC.rrc[ctxt_pP->module_id], ctxt_pP->rnti),
-						 CC_id);
-            // navid:
-            break;
-          }
+              memcpy(((uint8_t *) & random_value) + 3,
+                     rrcConnectionRequest->ue_Identity.choice.randomValue.buf,
+                     rrcConnectionRequest->ue_Identity.choice.randomValue.size);
+
+              /* if there is already a registered UE (with another RNTI) with this random_value,
+               * the current one must be removed from MAC/PHY (zombie UE)
+               */
+              if ((ue_context_p = rrc_eNB_ue_context_random_exist(ctxt_pP, random_value))) {
+                LOG_W(RRC, "new UE rnti %x (coming with random value) is already there as UE %x, removing %x from MAC/PHY\n",
+                      ctxt_pP->rnti, ue_context_p->ue_context.rnti, ue_context_p->ue_context.rnti);
+                ue_context_p->ue_context.ul_failure_timer = 20000;
+              }
 
-        }
-        LOG_D(RRC,
-              PROTOCOL_RRC_CTXT_UE_FMT" UE context: %p\n",
-              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
-              ue_context_p);
+              ue_context_p = rrc_eNB_get_next_free_ue_context(ctxt_pP, random_value);
+
+              // TODO MERGE
+              //ue_context_p->ue_context.Srb0.Srb_id=0;
+              //ue_context_p->ue_context.Srb0.Active=1;
+              //memcpy(ue_context_p->ue_context.Srb0.Rx_buffer.Payload,
+              //     buffer,
+              //     buffer_length);
+              //ue_context_p->ue_context.Srb0.Rx_buffer.payload_size=buffer_length;
+
+            } else if (LTE_InitialUE_Identity_PR_s_TMSI == rrcConnectionRequest->ue_Identity.present) {
+              /* Save s-TMSI */
+              LTE_S_TMSI_t   s_TMSI = rrcConnectionRequest->ue_Identity.choice.s_TMSI;
+              mme_code_t mme_code = BIT_STRING_to_uint8(&s_TMSI.mmec);
+              m_tmsi_t   m_tmsi   = BIT_STRING_to_uint32(&s_TMSI.m_TMSI);
+              random_value = (((uint64_t)mme_code) << 32) | m_tmsi;
+
+              if ((ue_context_p = rrc_eNB_ue_context_stmsi_exist(ctxt_pP, mme_code, m_tmsi))) {
+                LOG_I(RRC," S-TMSI exists, ue_context_p %p, old rnti %x => %x\n",ue_context_p,ue_context_p->ue_context.rnti,ctxt_pP->rnti);
+
+                if ((RC.rrc[ctxt_pP->module_id]->node_type  != ngran_eNB_CU) ||
+                    (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_ng_eNB_CU) ||
+                    (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_CU)   ) {
+                  rrc_mac_remove_ue(ctxt_pP->module_id, ue_context_p->ue_context.rnti);
+                }
+                else {
+                  MessageDef *m = itti_alloc_new_message(TASK_RRC_ENB, F1AP_UE_CONTEXT_RELEASE_CMD);
+                  F1AP_UE_CONTEXT_RELEASE_CMD(m).rnti = ctxt_pP->rnti;
+                  F1AP_UE_CONTEXT_RELEASE_CMD(m).cause = F1AP_CAUSE_RADIO_NETWORK;
+                  F1AP_UE_CONTEXT_RELEASE_CMD(m).cause_value = 10; // 10 = F1AP_CauseRadioNetwork_normal_release
+                  F1AP_UE_CONTEXT_RELEASE_CMD(m).rrc_container = NULL;
+                  F1AP_UE_CONTEXT_RELEASE_CMD(m).rrc_container_length = 0;
+                  itti_send_msg_to_task(TASK_CU_F1, ctxt_pP->module_id, m);
+                }
 
-        if (ue_context_p != NULL) {
+                stmsi_received=1;
+                /* replace rnti in the context */
+                /* for that, remove the context from the RB tree */
+                RB_REMOVE(rrc_ue_tree_s, &RC.rrc[ctxt_pP->module_id]->rrc_ue_head, ue_context_p);
+                /* and insert again, after changing rnti everywhere it has to be changed */
+                ue_context_p->ue_id_rnti = ctxt_pP->rnti;
+                ue_context_p->ue_context.rnti = ctxt_pP->rnti;
+                RB_INSERT(rrc_ue_tree_s, &RC.rrc[ctxt_pP->module_id]->rrc_ue_head, ue_context_p);
+                /* reset timers */
+                ue_context_p->ue_context.ul_failure_timer = 0;
+                ue_context_p->ue_context.ue_release_timer = 0;
+                ue_context_p->ue_context.ue_reestablishment_timer = 0;
+                ue_context_p->ue_context.ue_release_timer_s1 = 0;
+                ue_context_p->ue_context.ue_release_timer_rrc = 0;
+                ue_context_p->ue_context.reestablishment_xid = -1;
+              } else {
+                LOG_I(RRC," S-TMSI doesn't exist, setting Initialue_identity_s_TMSI.m_tmsi to %p => %x\n",ue_context_p,m_tmsi);
+                //              ue_context_p = rrc_eNB_get_next_free_ue_context(ctxt_pP, NOT_A_RANDOM_UE_IDENTITY);
+                ue_context_p = rrc_eNB_get_next_free_ue_context(ctxt_pP,random_value);
+
+                if (ue_context_p == NULL)
+                  LOG_E(RRC, "%s:%d:%s: rrc_eNB_get_next_free_ue_context returned NULL\n", __FILE__, __LINE__, __FUNCTION__);
+
+                if (ue_context_p != NULL) {
+                  ue_context_p->ue_context.Initialue_identity_s_TMSI.presence = TRUE;
+                  ue_context_p->ue_context.Initialue_identity_s_TMSI.mme_code = mme_code;
+                  ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi = m_tmsi;
+                } else {
+                  /* TODO: do we have to break here? */
+                  //break;
+                }
+              }
+
+              MSC_LOG_RX_MESSAGE(
+                MSC_RRC_ENB,
+                MSC_RRC_UE,
+                buffer,
+                dec_rval.consumed,
+                MSC_AS_TIME_FMT" RRCConnectionRequest UE %x size %u (s-TMSI mmec %u m_TMSI %u random UE id (0x%" PRIx64 ")",
+                MSC_AS_TIME_ARGS(ctxt_pP),
+                ue_context_p->ue_context.rnti,
+                dec_rval.consumed,
+                ue_context_p->ue_context.Initialue_identity_s_TMSI.mme_code,
+                ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi,
+                ue_context_p->ue_context.random_ue_identity);
+            } else {
+              LOG_E(RRC,
+                    PROTOCOL_RRC_CTXT_UE_FMT" RRCConnectionRequest without random UE identity or S-TMSI not supported, let's reject the UE\n",
+                    PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
+              rrc_eNB_generate_RRCConnectionReject(ctxt_pP,
+                                                   rrc_eNB_get_ue_context(RC.rrc[ctxt_pP->module_id], ctxt_pP->rnti),
+                                                   CC_id);
+              break;
+            }
+          }
+          LOG_D(RRC,
+                PROTOCOL_RRC_CTXT_UE_FMT" UE context: %p\n",
+                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
+                ue_context_p);
 
+          if (ue_context_p != NULL) {
 #if defined(ENABLE_ITTI)
-          ue_context_p->ue_context.establishment_cause = rrcConnectionRequest->establishmentCause;
-          ue_context_p->ue_context.reestablishment_cause = ReestablishmentCause_spare1;
-	  if (stmsi_received==0)
-	    LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Accept new connection from UE random UE identity (0x%" PRIx64 ") MME code %u TMSI %u cause %ld\n",
-		  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
-		  ue_context_p->ue_context.random_ue_identity,
-		  ue_context_p->ue_context.Initialue_identity_s_TMSI.mme_code,
-		  ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi,
-		  ue_context_p->ue_context.establishment_cause);
-	  else
-	    LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Accept new connection from UE  MME code %u TMSI %u cause %ld\n",
-		  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
-		  ue_context_p->ue_context.Initialue_identity_s_TMSI.mme_code,
-		  ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi,
-		  ue_context_p->ue_context.establishment_cause);
+            ue_context_p->ue_context.establishment_cause = rrcConnectionRequest->establishmentCause;
+            ue_context_p->ue_context.reestablishment_cause = LTE_ReestablishmentCause_spare1;
+
+            if (stmsi_received==0)
+              LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Accept new connection from UE random UE identity (0x%" PRIx64 ") MME code %u TMSI %u cause %ld\n",
+                    PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
+                    ue_context_p->ue_context.random_ue_identity,
+                    ue_context_p->ue_context.Initialue_identity_s_TMSI.mme_code,
+                    ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi,
+                    ue_context_p->ue_context.establishment_cause);
+            else
+              LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Accept new connection from UE  MME code %u TMSI %u cause %ld\n",
+                    PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
+                    ue_context_p->ue_context.Initialue_identity_s_TMSI.mme_code,
+                    ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi,
+                    ue_context_p->ue_context.establishment_cause);
+
 #else
-          LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Accept new connection for UE random UE identity (0x%" PRIx64 ")\n",
-                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
-                ue_context_p->ue_context.random_ue_identity);
+            LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Accept new connection for UE random UE identity (0x%" PRIx64 ")\n",
+                  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
+                  ue_context_p->ue_context.random_ue_identity);
 #endif
-          if (stmsi_received == 0)
-	    RC.rrc[ctxt_pP->module_id]->Nb_ue++;
 
-        } else {
-          // no context available
-	  if (flexran_agent_get_rrc_xface(ctxt_pP->module_id)) {
-	    flexran_agent_get_rrc_xface(ctxt_pP->module_id)->flexran_agent_notify_ue_state_change(ctxt_pP->module_id,
-										      ctxt_pP->rnti,
-										      PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_DEACTIVATED);
-	  }
-          LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Can't create new context for UE random UE identity (0x%" PRIx64 ")\n",
-                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
-                random_value);
-
-          if (RC.rrc[ctxt_pP->module_id] == ngran_eNB)
-	     rrc_mac_remove_ue(ctxt_pP->module_id,ctxt_pP->rnti);
-          else if (RC.rrc[ctxt_pP->module_id]->node_type == ngran_eNB_CU || 
-                   RC.rrc[ctxt_pP->module_id]->node_type == ngran_ng_eNB_CU) {
-            MessageDef *m = itti_alloc_new_message(TASK_RRC_ENB, F1AP_UE_CONTEXT_RELEASE_CMD);
-            F1AP_UE_CONTEXT_RELEASE_CMD(m).rnti = ctxt_pP->rnti;
-            F1AP_UE_CONTEXT_RELEASE_CMD(m).cause = F1AP_CAUSE_RADIO_NETWORK;
-            F1AP_UE_CONTEXT_RELEASE_CMD(m).cause_value = 10; // 10 = F1AP_CauseRadioNetwork_normal_release
-            F1AP_UE_CONTEXT_RELEASE_CMD(m).rrc_container = NULL;
-            F1AP_UE_CONTEXT_RELEASE_CMD(m).rrc_container_length = 0;
-            itti_send_msg_to_task(TASK_CU_F1, ctxt_pP->module_id, m);
-          }
+            if (stmsi_received == 0)
+              RC.rrc[ctxt_pP->module_id]->Nb_ue++;
+          } else {
+            // no context available
+            if (flexran_agent_get_rrc_xface(ctxt_pP->module_id)) {
+              flexran_agent_get_rrc_xface(ctxt_pP->module_id)->flexran_agent_notify_ue_state_change(ctxt_pP->module_id,
+                  ctxt_pP->rnti,
+                  PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_DEACTIVATED);
+            }
 
-          return -1;
+            LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Can't create new context for UE random UE identity (0x%" PRIx64 ")\n",
+                  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
+                  random_value);
+            if (RC.rrc[ctxt_pP->module_id] == ngran_eNB)
+              rrc_mac_remove_ue(ctxt_pP->module_id,ctxt_pP->rnti);
+            else if (RC.rrc[ctxt_pP->module_id]->node_type == ngran_eNB_CU ||
+                RC.rrc[ctxt_pP->module_id]->node_type == ngran_ng_eNB_CU) {
+              MessageDef *m = itti_alloc_new_message(TASK_RRC_ENB, F1AP_UE_CONTEXT_RELEASE_CMD);
+              F1AP_UE_CONTEXT_RELEASE_CMD(m).rnti = ctxt_pP->rnti;
+              F1AP_UE_CONTEXT_RELEASE_CMD(m).cause = F1AP_CAUSE_RADIO_NETWORK;
+              F1AP_UE_CONTEXT_RELEASE_CMD(m).cause_value = 10; // 10 = F1AP_CauseRadioNetwork_normal_release
+              F1AP_UE_CONTEXT_RELEASE_CMD(m).rrc_container = NULL;
+              F1AP_UE_CONTEXT_RELEASE_CMD(m).rrc_container_length = 0;
+              itti_send_msg_to_task(TASK_CU_F1, ctxt_pP->module_id, m);
+            }
+            return -1;
+          }
         }
-      }
 
 #ifndef NO_RRM
-      send_msg(&S_rrc, msg_rrc_MR_attach_ind(ctxt_pP->module_id, Mac_id));
+        send_msg(&S_rrc, msg_rrc_MR_attach_ind(ctxt_pP->module_id, Mac_id));
 #else
-
-      ue_context_p->ue_context.primaryCC_id = CC_id;
-
-      //LG COMMENT Idx = (ue_mod_idP * NB_RB_MAX) + DCCH;
-      Idx = DCCH;
-      // SRB1
-      ue_context_p->ue_context.Srb1.Active = 1;
-      ue_context_p->ue_context.Srb1.Srb_info.Srb_id = Idx;
-      memcpy(&ue_context_p->ue_context.Srb1.Srb_info.Lchan_desc[0],
-             &DCCH_LCHAN_DESC,
-             LCHAN_DESC_SIZE);
-      memcpy(&ue_context_p->ue_context.Srb1.Srb_info.Lchan_desc[1],
-             &DCCH_LCHAN_DESC,
-             LCHAN_DESC_SIZE);
-
-      // SRB2: set  it to go through SRB1 with id 1 (DCCH)
-      ue_context_p->ue_context.Srb2.Active = 1;
-      ue_context_p->ue_context.Srb2.Srb_info.Srb_id = Idx;
-      memcpy(&ue_context_p->ue_context.Srb2.Srb_info.Lchan_desc[0],
-             &DCCH_LCHAN_DESC,
-             LCHAN_DESC_SIZE);
-      memcpy(&ue_context_p->ue_context.Srb2.Srb_info.Lchan_desc[1],
-             &DCCH_LCHAN_DESC,
-             LCHAN_DESC_SIZE);
-      
-      rrc_eNB_generate_RRCConnectionSetup(ctxt_pP, ue_context_p, CC_id);
-      LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT"CALLING RLC CONFIG SRB1 (rbid %d)\n",
-            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
-            Idx);
-
-      MSC_LOG_TX_MESSAGE(
-        MSC_RRC_ENB,
-        MSC_PDCP_ENB,
-        NULL,
-        0,
-        MSC_AS_TIME_FMT" CONFIG_REQ UE %x SRB",
-        MSC_AS_TIME_ARGS(ctxt_pP),
-        ue_context_p->ue_context.rnti);
-
-      rrc_pdcp_config_asn1_req(ctxt_pP,
-                               ue_context_p->ue_context.SRB_configList,
-                               (DRB_ToAddModList_t *) NULL,
-                               (DRB_ToReleaseList_t*) NULL,
-                               0xff,
-                               NULL,
-                               NULL,
-                               NULL
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-                               , (PMCH_InfoList_r9_t *) NULL
-#endif
-                               ,NULL);
-
-	if ( (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_eNB_CU) &&
-	     (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_ng_eNB_CU) &&
-	     (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_CU)   ) {
-	 
-	 	 rrc_rlc_config_asn1_req(ctxt_pP,
-	 	 	ue_context_p->ue_context.SRB_configList,
-	 	 	(DRB_ToAddModList_t*) NULL,
-	 	 	(DRB_ToReleaseList_t*) NULL
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-            , (PMCH_InfoList_r9_t *) NULL
-            , 0, 0
-#endif
-            );
+        ue_context_p->ue_context.primaryCC_id = CC_id;
+        //LG COMMENT Idx = (ue_mod_idP * NB_RB_MAX) + DCCH;
+        Idx = DCCH;
+        // SRB1
+        ue_context_p->ue_context.Srb1.Active = 1;
+        ue_context_p->ue_context.Srb1.Srb_info.Srb_id = Idx;
+        memcpy(&ue_context_p->ue_context.Srb1.Srb_info.Lchan_desc[0],
+               &DCCH_LCHAN_DESC,
+               LCHAN_DESC_SIZE);
+        memcpy(&ue_context_p->ue_context.Srb1.Srb_info.Lchan_desc[1],
+               &DCCH_LCHAN_DESC,
+               LCHAN_DESC_SIZE);
+        // SRB2: set  it to go through SRB1 with id 1 (DCCH)
+        ue_context_p->ue_context.Srb2.Active = 1;
+        ue_context_p->ue_context.Srb2.Srb_info.Srb_id = Idx;
+        memcpy(&ue_context_p->ue_context.Srb2.Srb_info.Lchan_desc[0],
+               &DCCH_LCHAN_DESC,
+               LCHAN_DESC_SIZE);
+        memcpy(&ue_context_p->ue_context.Srb2.Srb_info.Lchan_desc[1],
+               &DCCH_LCHAN_DESC,
+               LCHAN_DESC_SIZE);
+        rrc_eNB_generate_RRCConnectionSetup(ctxt_pP, ue_context_p, CC_id);
+        LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT"CALLING RLC CONFIG SRB1 (rbid %d)\n",
+              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
+              Idx);
+        MSC_LOG_TX_MESSAGE(
+          MSC_RRC_ENB,
+          MSC_PDCP_ENB,
+          NULL,
+          0,
+          MSC_AS_TIME_FMT" CONFIG_REQ UE %x SRB",
+          MSC_AS_TIME_ARGS(ctxt_pP),
+          ue_context_p->ue_context.rnti);
+        rrc_pdcp_config_asn1_req(ctxt_pP,
+                                 ue_context_p->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);
+
+        if ( (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_eNB_CU) &&
+             (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_ng_eNB_CU) &&
+             (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_CU)   ) {
+          rrc_rlc_config_asn1_req(ctxt_pP,
+                                  ue_context_p->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
+                                 );
+        }
 #endif //NO_RRM
-	}
-      break;
+        break;
 
-    default:
-      LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Unknown message\n",
-            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
-      rval = -1;
-      break;
+      default:
+        LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Unknown message\n",
+              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
+        rval = -1;
+        break;
     }
 
     rval = 0;
@@ -6726,28 +7596,21 @@ rrc_eNB_decode_ccch(
 //-----------------------------------------------------------------------------
 int
 rrc_eNB_decode_dcch(
-  const protocol_ctxt_t* const ctxt_pP,
+  const protocol_ctxt_t *const ctxt_pP,
   const rb_id_t                Srb_id,
-  const uint8_t*    const      Rx_sdu,
+  const uint8_t    *const      Rx_sdu,
   const sdu_size_t             sdu_sizeP
 )
 //-----------------------------------------------------------------------------
 {
-
   asn_dec_rval_t                      dec_rval;
   //UL_DCCH_Message_t uldcchmsg;
-  UL_DCCH_Message_t                  *ul_dcch_msg = NULL; //&uldcchmsg;
+  LTE_UL_DCCH_Message_t               *ul_dcch_msg = NULL; //&uldcchmsg;
   int i;
-  struct rrc_eNB_ue_context_s*        ue_context_p = NULL;
-#if defined(ENABLE_ITTI)
-#   if defined(ENABLE_USE_MME)
-  MessageDef *                        msg_delete_tunnels_p = NULL;
+  struct rrc_eNB_ue_context_s        *ue_context_p = NULL;
+  MessageDef                         *msg_delete_tunnels_p = NULL;
   uint8_t                             xid;
-#endif
-#endif
-
-  int dedicated_DRB=0; 
-
+  int dedicated_DRB=0;
   T(T_ENB_RRC_UL_DCCH_DATA_IN, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
     T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
 
@@ -6760,19 +7623,18 @@ rrc_eNB_decode_dcch(
           PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
           Srb_id);
   }
-  //memset(ul_dcch_msg,0,sizeof(UL_DCCH_Message_t));
 
+  //memset(ul_dcch_msg,0,sizeof(UL_DCCH_Message_t));
   LOG_D(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Decoding UL-DCCH Message\n",
         PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
   dec_rval = uper_decode(
                NULL,
-               &asn_DEF_UL_DCCH_Message,
-               (void**)&ul_dcch_msg,
+               &asn_DEF_LTE_UL_DCCH_Message,
+               (void **)&ul_dcch_msg,
                Rx_sdu,
                sdu_sizeP,
                0,
                0);
-
   {
     for (i = 0; i < sdu_sizeP; i++) {
       LOG_T(RRC, "%x.", Rx_sdu[i]);
@@ -6792,179 +7654,192 @@ rrc_eNB_decode_dcch(
                    RC.rrc[ctxt_pP->module_id],
                    ctxt_pP->rnti);
 
-  if (ul_dcch_msg->message.present == UL_DCCH_MessageType_PR_c1) {
-
+  if (ul_dcch_msg->message.present == LTE_UL_DCCH_MessageType_PR_c1) {
     switch (ul_dcch_msg->message.choice.c1.present) {
-    case UL_DCCH_MessageType__c1_PR_NOTHING:   /* No components present */
-      break;
-
-    case UL_DCCH_MessageType__c1_PR_csfbParametersRequestCDMA2000:
-      break;
-
-    case UL_DCCH_MessageType__c1_PR_measurementReport:
-      // to avoid segmentation fault
-      if(!ue_context_p){
-        LOG_I(RRC, "Processing measurementReport UE %x, ue_context_p is NULL\n", ctxt_pP->rnti);
+      case LTE_UL_DCCH_MessageType__c1_PR_NOTHING:   /* No components present */
         break;
-      }
-      LOG_D(RRC,
-            PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND "
-            "%d bytes (measurementReport) ---> RRC_eNB\n",
-            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
-            DCCH,
-            sdu_sizeP);
-      rrc_eNB_process_MeasurementReport(
-        ctxt_pP,
-        ue_context_p,
-        &ul_dcch_msg->message.choice.c1.choice.measurementReport.
-        criticalExtensions.choice.c1.choice.measurementReport_r8.measResults);
-      break;
 
-    case UL_DCCH_MessageType__c1_PR_rrcConnectionReconfigurationComplete:
-      // to avoid segmentation fault
-      if(!ue_context_p){
-        LOG_I(RRC, "Processing RRCConnectionReconfigurationComplete UE %x, ue_context_p is NULL\n", ctxt_pP->rnti);
+      case LTE_UL_DCCH_MessageType__c1_PR_csfbParametersRequestCDMA2000:
         break;
-      }
-      LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)(Rx_sdu),sdu_sizeP,
-                  "[MSG] RRC Connection Reconfiguration Complete\n");
-
-      MSC_LOG_RX_MESSAGE(
-        MSC_RRC_ENB,
-        MSC_RRC_UE,
-        Rx_sdu,
-        sdu_sizeP,
-        MSC_AS_TIME_FMT" RRCConnectionReconfigurationComplete UE %x size %u",
-        MSC_AS_TIME_ARGS(ctxt_pP),
-        ue_context_p->ue_context.rnti,
-        sdu_sizeP);
-
-      LOG_D(RRC,
-            PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
-            "(RRCConnectionReconfigurationComplete) ---> RRC_eNB]\n",
-            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
-            DCCH,
-            sdu_sizeP);
-
-      if (ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.criticalExtensions.
-          present ==
-          RRCConnectionReconfigurationComplete__criticalExtensions_PR_rrcConnectionReconfigurationComplete_r8) {
-	/*NN: revise the condition */
-	/*FK: left the condition as is for the case MME is used (S1 mode) but setting  dedicated_DRB = 1 otherwise (noS1 mode) so that no second RRCReconfiguration message activationg more DRB is sent as this causes problems with the nasmesh driver.*/
-        if (EPC_MODE_ENABLED) {
-  	  if (ue_context_p->ue_context.Status == RRC_RECONFIGURED){
-  	    dedicated_DRB = 1;
-  	    LOG_I(RRC,
-  		  PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_RECONFIGURED (reconfigure default DRB /dedicated DRB, xid %ld)\n",
-  		  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
-  	    //clear
-  	    // FIX ME: MAC context does not exist in CU
-  	    if ((RC.rrc[ctxt_pP->module_id]->node_type  != ngran_eNB_CU) &&
-       		(RC.rrc[ctxt_pP->module_id]->node_type  != ngran_ng_eNB_CU)&& 
-       		(RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_CU)   ) {
-  		    int16_t UE_id = find_UE_id(ctxt_pP->module_id, ctxt_pP->rnti);
-	  	    if(UE_id == -1){
-	  	      LOG_E(RRC,
-	  		    PROTOCOL_RRC_CTXT_UE_FMT" RRCConnectionReconfigurationComplete without rnti %x, fault\n",
-	  		    PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ctxt_pP->rnti);
-	  	      break;
-	  	    }
-  		
-	  	    if(RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].crnti_reconfigurationcomplete_flag == 1){
-	  	      LOG_I(RRC,
-	  		    PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_RECONFIGURED (dedicated DRB, xid %ld) C-RNTI Complete\n",
-	  		    PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
-	  	      dedicated_DRB = 2;
-	  	      RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].crnti_reconfigurationcomplete_flag = 0;
-	  	    }
-	  	  	else {
-	  	    dedicated_DRB = 0;
-	  	    ue_context_p->ue_context.Status = RRC_RECONFIGURED;
-	  	    LOG_I(RRC,
-	  		  PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_RECONFIGURED (default DRB, xid %ld)\n",
-	  		  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
-	  	  	}
-	  	} else{
-			dedicated_DRB = 0;
-	  	    ue_context_p->ue_context.Status = RRC_RECONFIGURED;
-	  	    LOG_I(RRC,
-	  		  PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_RECONFIGURED (default DRB, xid %ld)\n",
-	  		  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
-	  		}
-  	  		ue_context_p->ue_context.reestablishment_xid = -1;
-        } else {
-  	  ue_context_p->ue_context.Status = RRC_RECONFIGURED;
-  	  LOG_I(RRC,
-  	      PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_RECONFIGURED (default DRB, xid %ld)\n",
-  	      PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
-  	}
-  }
-	
-	rrc_eNB_process_RRCConnectionReconfigurationComplete(
+
+      case LTE_UL_DCCH_MessageType__c1_PR_measurementReport:
+
+        // to avoid segmentation fault
+        if(!ue_context_p) {
+          LOG_I(RRC, "Processing measurementReport UE %x, ue_context_p is NULL\n", ctxt_pP->rnti);
+          break;
+        }
+
+        LOG_D(RRC,
+              PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND "
+              "%d bytes (measurementReport) ---> RRC_eNB\n",
+              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
+              DCCH,
+              sdu_sizeP);
+        rrc_eNB_process_MeasurementReport(
           ctxt_pP,
           ue_context_p,
-	  ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
-
-	//WARNING:Inform the controller about the UE activation. Should be moved to RRC agent in the future
-	if (flexran_agent_get_rrc_xface(ctxt_pP->module_id)) {
-	  flexran_agent_get_rrc_xface(ctxt_pP->module_id)->flexran_agent_notify_ue_state_change(ctxt_pP->module_id,
-										ue_context_p->ue_id_rnti,
-										PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_UPDATED);
-	}
-      }
+          &ul_dcch_msg->message.choice.c1.choice.measurementReport.
+          criticalExtensions.choice.c1.choice.measurementReport_r8.measResults);
+        break;
+
+      case LTE_UL_DCCH_MessageType__c1_PR_rrcConnectionReconfigurationComplete:
+
+        // to avoid segmentation fault
+        if(!ue_context_p) {
+          LOG_I(RRC, "Processing LTE_RRCConnectionReconfigurationComplete UE %x, ue_context_p is NULL\n", ctxt_pP->rnti);
+          break;
+        }
+
+        LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)(Rx_sdu),sdu_sizeP,
+                    "[MSG] RRC Connection Reconfiguration Complete\n");
+        MSC_LOG_RX_MESSAGE(
+          MSC_RRC_ENB,
+          MSC_RRC_UE,
+          Rx_sdu,
+          sdu_sizeP,
+          MSC_AS_TIME_FMT" LTE_RRCConnectionReconfigurationComplete UE %x size %u",
+          MSC_AS_TIME_ARGS(ctxt_pP),
+          ue_context_p->ue_context.rnti,
+          sdu_sizeP);
+        LOG_D(RRC,
+              PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
+              "(RRCConnectionReconfigurationComplete) ---> RRC_eNB]\n",
+              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
+              DCCH,
+              sdu_sizeP);
+
+        if (ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.criticalExtensions.
+            present ==
+            LTE_RRCConnectionReconfigurationComplete__criticalExtensions_PR_rrcConnectionReconfigurationComplete_r8) {
+          /*NN: revise the condition */
+          /*FK: left the condition as is for the case MME is used (S1 mode) but setting  dedicated_DRB = 1 otherwise (noS1 mode) so that no second RRCReconfiguration message activationg more DRB is sent as this causes problems with the nasmesh driver.*/
+          if (EPC_MODE_ENABLED) {
+            if (ue_context_p->ue_context.Status == RRC_RECONFIGURED) {
+              dedicated_DRB = 1;
+              LOG_I(RRC,
+                    PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_RECONFIGURED (dedicated DRB, xid %ld)\n",
+                    PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
+              //clear
+              int16_t UE_id = find_UE_id(ctxt_pP->module_id, ctxt_pP->rnti);
+
+              if(UE_id == -1) {
+                LOG_E(RRC,
+                      PROTOCOL_RRC_CTXT_UE_FMT" RRCConnectionReconfigurationComplete without rnti %x, fault\n",
+                      PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ctxt_pP->rnti);
+                break;
+              }
+
+              AssertFatal(RC.rrc[ctxt_pP->module_id]->node_type != ngran_eNB_CU
+                          && RC.rrc[ctxt_pP->module_id]->node_type  != ngran_ng_eNB_CU
+                          && RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_CU,
+                          "CU cannot decode DCCH: no access to RC.mac[]\n");
+
+              if(RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].crnti_reconfigurationcomplete_flag == 1) {
+                LOG_I(RRC,
+                      PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_RECONFIGURED (dedicated DRB, xid %ld) C-RNTI Complete\n",
+                      PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
+                dedicated_DRB = 2;
+                RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].crnti_reconfigurationcomplete_flag = 0;
+              }
+            } else if (ue_context_p->ue_context.Status == RRC_HO_EXECUTION) {
+              int16_t UE_id = find_UE_id(ctxt_pP->module_id, ctxt_pP->rnti);
+
+              if(UE_id == -1) {
+                LOG_E(RRC,
+                      PROTOCOL_RRC_CTXT_UE_FMT" RRCConnectionReconfigurationComplete without rnti %x, fault\n",
+                      PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ctxt_pP->rnti);
+                break;
+              }
+
+              dedicated_DRB = 3;
+              RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].crnti_reconfigurationcomplete_flag = 0;
+              ue_context_p->ue_context.Status = RRC_RECONFIGURED;
+              LOG_I(RRC,
+                    PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_HO_EXECUTION (xid %ld)\n",
+                    PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
+            } else {
+              dedicated_DRB = 0;
+              ue_context_p->ue_context.Status = RRC_RECONFIGURED;
+              LOG_I(RRC,
+                    PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_RECONFIGURED (default DRB, xid %ld)\n",
+                    PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
+            }
+
+            ue_context_p->ue_context.reestablishment_xid = -1;
+          } else {
+            dedicated_DRB = 1;
+            ue_context_p->ue_context.Status = RRC_RECONFIGURED;
+            LOG_I(RRC,
+                  PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_RECONFIGURED (dedicated DRB, xid %ld)\n",
+                  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
+          }
+
+          rrc_eNB_process_RRCConnectionReconfigurationComplete(
+            ctxt_pP,
+            ue_context_p,
+            ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
+
+          //WARNING:Inform the controller about the UE activation. Should be moved to RRC agent in the future
+          if (flexran_agent_get_rrc_xface(ctxt_pP->module_id)) {
+            flexran_agent_get_rrc_xface(ctxt_pP->module_id)->flexran_agent_notify_ue_state_change(ctxt_pP->module_id,
+                ue_context_p->ue_id_rnti,
+                PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_UPDATED);
+          }
+        }
+
 #if defined(ENABLE_ITTI)
 #if defined(ENABLE_USE_MME)
-	if (dedicated_DRB == 1){
-//	  rrc_eNB_send_S1AP_E_RAB_SETUP_RESP(ctxt_pP,
-//					     ue_context_p,
-//					     ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
-if (ue_context_p->ue_context.nb_of_modify_e_rabs > 0) {
-            rrc_eNB_send_S1AP_E_RAB_MODIFY_RESP(ctxt_pP,
-                             ue_context_p,
-                             ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
 
+        if (dedicated_DRB == 1) {
+          //    rrc_eNB_send_S1AP_E_RAB_SETUP_RESP(ctxt_pP,
+          //               ue_context_p,
+          //               ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
+          if (ue_context_p->ue_context.nb_of_modify_e_rabs > 0) {
+            rrc_eNB_send_S1AP_E_RAB_MODIFY_RESP(ctxt_pP,
+                                                ue_context_p,
+                                                ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
             ue_context_p->ue_context.nb_of_modify_e_rabs = 0;
             ue_context_p->ue_context.nb_of_failed_e_rabs = 0;
             memset(ue_context_p->ue_context.modify_e_rab, 0, sizeof(ue_context_p->ue_context.modify_e_rab));
+
             for(int i = 0; i < NB_RB_MAX; i++) {
               ue_context_p->ue_context.modify_e_rab[i].xid = -1;
             }
-
-          } else if(ue_context_p->ue_context.e_rab_release_command_flag == 1){
+          } else if(ue_context_p->ue_context.e_rab_release_command_flag == 1) {
             xid = ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier;
             ue_context_p->ue_context.e_rab_release_command_flag = 0;
             //gtp tunnel delete
             msg_delete_tunnels_p = itti_alloc_new_message(TASK_RRC_ENB, GTPV1U_ENB_DELETE_TUNNEL_REQ);
             memset(&GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p), 0, sizeof(GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p)));
             GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p).rnti = ue_context_p->ue_context.rnti;
-            for(i = 0; i < NB_RB_MAX; i++){
-               if(xid == ue_context_p->ue_context.e_rab[i].xid){
-                 GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p).eps_bearer_id[GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p).num_erab++] = ue_context_p->ue_context.enb_gtp_ebi[i];
-                 ue_context_p->ue_context.enb_gtp_teid[i] = 0;
-                 memset(&ue_context_p->ue_context.enb_gtp_addrs[i], 0, sizeof(ue_context_p->ue_context.enb_gtp_addrs[i]));
-                 ue_context_p->ue_context.enb_gtp_ebi[i]  = 0;
-               }
+
+            for(i = 0; i < NB_RB_MAX; i++) {
+              if(xid == ue_context_p->ue_context.e_rab[i].xid) {
+                GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p).eps_bearer_id[GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p).num_erab++] = ue_context_p->ue_context.enb_gtp_ebi[i];
+                ue_context_p->ue_context.enb_gtp_teid[i] = 0;
+                memset(&ue_context_p->ue_context.enb_gtp_addrs[i], 0, sizeof(ue_context_p->ue_context.enb_gtp_addrs[i]));
+                ue_context_p->ue_context.enb_gtp_ebi[i]  = 0;
+              }
             }
+
             itti_send_msg_to_task(TASK_GTPV1_U, ctxt_pP->instance, msg_delete_tunnels_p);
             //S1AP_E_RAB_RELEASE_RESPONSE
             rrc_eNB_send_S1AP_E_RAB_RELEASE_RESPONSE(ctxt_pP,
-                    ue_context_p,
-                    xid);
+                ue_context_p,
+                xid);
           } else {
-              rrc_eNB_send_S1AP_E_RAB_SETUP_RESP(ctxt_pP,
-                             ue_context_p,
-                             ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
+            rrc_eNB_send_S1AP_E_RAB_SETUP_RESP(ctxt_pP,
+                                               ue_context_p,
+                                               ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
           }
-  }else if(dedicated_DRB == 0){
-                LOG_D(RRC, "Sending rrc_eNB_send_S1AP_INITIAL_CONTEXT_SETUP_RESP, establishment cause %ld\n",
-  		ue_context_p->ue_context.reestablishment_cause );
-  		// NN: not sure what we need to send S1AP_INITIAL_CONTEXT_SETUP_RESP only with this cause?
-        //if(ue_context_p->ue_context.reestablishment_cause == ReestablishmentCause_spare1){
-	    	rrc_eNB_send_S1AP_INITIAL_CONTEXT_SETUP_RESP(ctxt_pP,
-						       ue_context_p);
-        // } else 
-           {
-            ue_context_p->ue_context.reestablishment_cause = ReestablishmentCause_spare1;
+        } else if(dedicated_DRB == 0) {
+          if(ue_context_p->ue_context.reestablishment_cause == LTE_ReestablishmentCause_spare1) {
+            rrc_eNB_send_S1AP_INITIAL_CONTEXT_SETUP_RESP(ctxt_pP,
+                ue_context_p);
+          } else {
+            ue_context_p->ue_context.reestablishment_cause = LTE_ReestablishmentCause_spare1;
+
             for (uint8_t e_rab = 0; e_rab < ue_context_p->ue_context.nb_of_e_rabs; e_rab++) {
               if (ue_context_p->ue_context.e_rab[e_rab].status == E_RAB_STATUS_DONE) {
                 ue_context_p->ue_context.e_rab[e_rab].status = E_RAB_STATUS_ESTABLISHED;
@@ -6973,461 +7848,460 @@ if (ue_context_p->ue_context.nb_of_modify_e_rabs > 0) {
               }
             }
           }
-  }else if(dedicated_DRB == 2){
-             for (uint8_t e_rab = 0; e_rab < ue_context_p->ue_context.nb_of_e_rabs; e_rab++) {
-               if (ue_context_p->ue_context.e_rab[e_rab].status == E_RAB_STATUS_DONE) {
-                 ue_context_p->ue_context.e_rab[e_rab].status = E_RAB_STATUS_ESTABLISHED;
-               } else {
-                 ue_context_p->ue_context.e_rab[e_rab].status = E_RAB_STATUS_FAILED;
-               }
-             }
-         }
-#endif   
+        } else if(dedicated_DRB == 2) {
+          for (uint8_t e_rab = 0; e_rab < ue_context_p->ue_context.nb_of_e_rabs; e_rab++) {
+            if (ue_context_p->ue_context.e_rab[e_rab].status == E_RAB_STATUS_DONE) {
+              ue_context_p->ue_context.e_rab[e_rab].status = E_RAB_STATUS_ESTABLISHED;
+            } else {
+              ue_context_p->ue_context.e_rab[e_rab].status = E_RAB_STATUS_FAILED;
+            }
+          }
+        } else if(dedicated_DRB == 3) { //x2 path switch
+          for (uint8_t e_rab = 0; e_rab < ue_context_p->ue_context.nb_of_e_rabs; e_rab++) {
+            if (ue_context_p->ue_context.e_rab[e_rab].status == E_RAB_STATUS_DONE) {
+              ue_context_p->ue_context.e_rab[e_rab].status = E_RAB_STATUS_ESTABLISHED;
+            } else {
+              ue_context_p->ue_context.e_rab[e_rab].status = E_RAB_STATUS_FAILED;
+            }
+          }
+
+          LOG_I(RRC,"issue rrc_eNB_send_PATH_SWITCH_REQ \n");
+          rrc_eNB_send_PATH_SWITCH_REQ(ctxt_pP,ue_context_p);
+        }
+
+#endif
 #else  // establish a dedicated bearer 
-      if (dedicated_DRB == 0 ) {
-	//	ue_context_p->ue_context.e_rab[0].status = E_RAB_STATUS_ESTABLISHED;
-	rrc_eNB_reconfigure_DRBs(ctxt_pP,ue_context_p);
-      }
-#endif 
-      break;
 
-    case UL_DCCH_MessageType__c1_PR_rrcConnectionReestablishmentComplete:
-      T(T_ENB_RRC_CONNECTION_REESTABLISHMENT_COMPLETE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
-        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
+        if (dedicated_DRB == 0 ) {
+          //  ue_context_p->ue_context.e_rab[0].status = E_RAB_STATUS_ESTABLISHED;
+          rrc_eNB_reconfigure_DRBs(ctxt_pP,ue_context_p);
+        }
+
+#endif
+        break;
 
-      LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
-                  "[MSG] RRC Connection Reestablishment Complete\n");
+      case LTE_UL_DCCH_MessageType__c1_PR_rrcConnectionReestablishmentComplete:
+        T(T_ENB_RRC_CONNECTION_REESTABLISHMENT_COMPLETE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
+          T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
+        LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
+                    "[MSG] RRC Connection Reestablishment Complete\n");
+        MSC_LOG_RX_MESSAGE(
+          MSC_RRC_ENB,
+          MSC_RRC_UE,
+          Rx_sdu,
+          sdu_sizeP,
+          MSC_AS_TIME_FMT" LTE_RRCConnectionReestablishmentComplete UE %x size %u",
+          MSC_AS_TIME_ARGS(ctxt_pP),
+          ue_context_p->ue_context.rnti,
+          sdu_sizeP);
+        LOG_I(RRC,
+              PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
+              "(rrcConnectionReestablishmentComplete) ---> RRC_eNB\n",
+              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
+              DCCH,
+              sdu_sizeP);
+        {
+          rnti_t reestablish_rnti = 0;
+
+          // select C-RNTI from map
+          for (i = 0; i < MAX_MOBILES_PER_ENB; i++) {
+            if (reestablish_rnti_map[i][0] == ctxt_pP->rnti) {
+              reestablish_rnti = reestablish_rnti_map[i][1];
+              ue_context_p = rrc_eNB_get_ue_context(
+                               RC.rrc[ctxt_pP->module_id],
+                               reestablish_rnti);
+              // clear currentC-RNTI from map
+              reestablish_rnti_map[i][0] = 0;
+              reestablish_rnti_map[i][1] = 0;
+              break;
+            }
+          }
 
-      MSC_LOG_RX_MESSAGE(
-        MSC_RRC_ENB,
-        MSC_RRC_UE,
-        Rx_sdu,
-        sdu_sizeP,
-        MSC_AS_TIME_FMT" rrcConnectionReestablishmentComplete UE %x size %u",
-        MSC_AS_TIME_ARGS(ctxt_pP),
-        ue_context_p->ue_context.rnti,
-        sdu_sizeP);
+          LOG_D(RRC, "reestablish_rnti_map[%d] [0] %x, [1] %x\n",
+                i, reestablish_rnti_map[i][0], reestablish_rnti_map[i][1]);
 
-      LOG_I(RRC,
-            PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
-            "(rrcConnectionReestablishmentComplete) ---> RRC_eNB\n",
-            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
-            DCCH,
-            sdu_sizeP);
-       {
-        rnti_t reestablish_rnti = 0;
-        // select C-RNTI from map
-        for (i = 0; i < MAX_MOBILES_PER_ENB; i++) {
-          if (reestablish_rnti_map[i][0] == ctxt_pP->rnti) {
-            reestablish_rnti = reestablish_rnti_map[i][1];
-            ue_context_p = rrc_eNB_get_ue_context(
-                              RC.rrc[ctxt_pP->module_id],
-                              reestablish_rnti);
-            // clear currentC-RNTI from map
-            reestablish_rnti_map[i][0] = 0;
-            reestablish_rnti_map[i][1] = 0;
+          if (!ue_context_p) {
+            LOG_E(RRC,
+                  PROTOCOL_RRC_CTXT_UE_FMT" LTE_RRCConnectionReestablishmentComplete without UE context, falt\n",
+                  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
             break;
           }
+
+          //clear
+          int UE_id = find_UE_id(ctxt_pP->module_id, ctxt_pP->rnti);
+
+          if(UE_id == -1) {
+            LOG_E(RRC,
+                  PROTOCOL_RRC_CTXT_UE_FMT" LTE_RRCConnectionReestablishmentComplete without UE_id(MAC) rnti %x, fault\n",
+                  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ctxt_pP->rnti);
+            break;
+          }
+
+          RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].ue_reestablishment_reject_timer = 0;
+          ue_context_p->ue_context.ue_reestablishment_timer = 0;
+
+          if (ul_dcch_msg->message.choice.c1.choice.rrcConnectionReestablishmentComplete.criticalExtensions.present ==
+              LTE_RRCConnectionReestablishmentComplete__criticalExtensions_PR_rrcConnectionReestablishmentComplete_r8) {
+            rrc_eNB_process_RRCConnectionReestablishmentComplete(ctxt_pP, reestablish_rnti, ue_context_p,
+                ul_dcch_msg->message.choice.c1.choice.rrcConnectionReestablishmentComplete.rrc_TransactionIdentifier,
+                &ul_dcch_msg->message.choice.c1.choice.rrcConnectionReestablishmentComplete.criticalExtensions.choice.rrcConnectionReestablishmentComplete_r8);
+
+            //WARNING:Inform the controller about the UE activation. Should be moved to RRC agent in the future
+            if (flexran_agent_get_rrc_xface(ctxt_pP->module_id)) {
+              flexran_agent_get_rrc_xface(ctxt_pP->module_id)->flexran_agent_notify_ue_state_change(ctxt_pP->module_id,
+                  ue_context_p->ue_id_rnti,
+                  PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_ACTIVATED);
+            }
+          }
+
+          //ue_context_p->ue_context.ue_release_timer = 0;
+          ue_context_p->ue_context.ue_reestablishment_timer = 1;
+          // remove UE after 100 frames after LTE_RRCConnectionReestablishmentRelease is triggered
+          ue_context_p->ue_context.ue_reestablishment_timer_thres = 1000;
         }
-        LOG_D(RRC, "reestablish_rnti_map[%d] [0] %x, [1] %x\n",
-              i, reestablish_rnti_map[i][0], reestablish_rnti_map[i][1]);
+        break;
 
-        if (!ue_context_p) {
-          LOG_E(RRC,
-                PROTOCOL_RRC_CTXT_UE_FMT" RRCConnectionReestablishmentComplete without UE context, falt\n",
-                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
+      case LTE_UL_DCCH_MessageType__c1_PR_rrcConnectionSetupComplete:
+
+        // to avoid segmentation fault
+        if(!ue_context_p) {
+          LOG_I(RRC, "Processing LTE_RRCConnectionSetupComplete UE %x, ue_context_p is NULL\n", ctxt_pP->rnti);
           break;
         }
-        //clear
-        if ((RC.rrc[ctxt_pP->module_id]->node_type  != ngran_eNB_CU) &&
-       		(RC.rrc[ctxt_pP->module_id]->node_type  != ngran_ng_eNB_CU)&& 
-       		(RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_CU)   ) {
-    		int UE_id = find_UE_id(ctxt_pP->module_id, ctxt_pP->rnti);
-	        if(UE_id == -1){
-	          LOG_E(RRC,
-	                PROTOCOL_RRC_CTXT_UE_FMT" RRCConnectionReestablishmentComplete without UE_id(MAC) rnti %x, fault\n",
-	                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ctxt_pP->rnti);
-	          break;
-	        }
-	    
-       		 RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].ue_reestablishment_reject_timer = 0;
-       		 ue_context_p->ue_context.ue_reestablishment_timer = 0;
-		}
-        if (ul_dcch_msg->message.choice.c1.choice.rrcConnectionReestablishmentComplete.criticalExtensions.present ==
-            RRCConnectionReestablishmentComplete__criticalExtensions_PR_rrcConnectionReestablishmentComplete_r8) {
-          rrc_eNB_process_RRCConnectionReestablishmentComplete(ctxt_pP, reestablish_rnti, ue_context_p,
-              ul_dcch_msg->message.choice.c1.choice.rrcConnectionReestablishmentComplete.rrc_TransactionIdentifier,
-              &ul_dcch_msg->message.choice.c1.choice.rrcConnectionReestablishmentComplete.criticalExtensions.choice.rrcConnectionReestablishmentComplete_r8);
 
-          if (flexran_agent_get_rrc_xface(ctxt_pP->module_id)) {
-            flexran_agent_get_rrc_xface(ctxt_pP->module_id)->flexran_agent_notify_ue_state_change(ctxt_pP->module_id,
-                                                                                      ue_context_p->ue_id_rnti,
-                                                                                      PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_ACTIVATED);
+        LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
+                    "[MSG] RRC Connection SetupComplete\n");
+        MSC_LOG_RX_MESSAGE(
+          MSC_RRC_ENB,
+          MSC_RRC_UE,
+          Rx_sdu,
+          sdu_sizeP,
+          MSC_AS_TIME_FMT" LTE_RRCConnectionSetupComplete UE %x size %u",
+          MSC_AS_TIME_ARGS(ctxt_pP),
+          ue_context_p->ue_context.rnti,
+          sdu_sizeP);
+        LOG_D(RRC,
+              PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
+              "(RRCConnectionSetupComplete) ---> RRC_eNB\n",
+              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
+              DCCH,
+              sdu_sizeP);
+
+        if (ul_dcch_msg->message.choice.c1.choice.rrcConnectionSetupComplete.criticalExtensions.present ==
+            LTE_RRCConnectionSetupComplete__criticalExtensions_PR_c1) {
+          if (ul_dcch_msg->message.choice.c1.choice.rrcConnectionSetupComplete.criticalExtensions.choice.c1.
+              present ==
+              LTE_RRCConnectionSetupComplete__criticalExtensions__c1_PR_rrcConnectionSetupComplete_r8) {
+            /* TODO MERGE: test, was if with empty DU clause */
+            AssertFatal(RC.rrc[ctxt_pP->module_id]->node_type != ngran_eNB_DU && RC.rrc[ctxt_pP->module_id]->node_type != ngran_gNB_DU,
+                        "should not be reached in DU\n");
+            rrc_eNB_process_RRCConnectionSetupComplete(
+              ctxt_pP,
+              ue_context_p,
+              &ul_dcch_msg->message.choice.c1.choice.rrcConnectionSetupComplete.criticalExtensions.choice.c1.choice.rrcConnectionSetupComplete_r8);
+            LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_CONNECTED \n",
+                  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
+
+            //WARNING:Inform the controller about the UE activation. Should be moved to RRC agent in the future
+            if (flexran_agent_get_rrc_xface(ctxt_pP->module_id)) {
+              flexran_agent_get_rrc_xface(ctxt_pP->module_id)->flexran_agent_notify_ue_state_change(ctxt_pP->module_id,
+                  ue_context_p->ue_id_rnti,
+                  PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_ACTIVATED);
+            }
           }
         }
-        //ue_context_p->ue_context.ue_release_timer = 0;
-        ue_context_p->ue_context.ue_reestablishment_timer = 1;
-        // remove UE after 100 frames after RRCConnectionReestablishmentRelease is triggered
-        ue_context_p->ue_context.ue_reestablishment_timer_thres = 1000;
-      }
-      break;
 
-    case UL_DCCH_MessageType__c1_PR_rrcConnectionSetupComplete:
-      // to avoid segmentation fault
-      if(!ue_context_p){
-        LOG_I(RRC, "Processing RRCConnectionSetupComplete UE %x, ue_context_p is NULL\n", ctxt_pP->rnti);
+        ue_context_p->ue_context.ue_release_timer=0;
         break;
-      }
-      LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
-                  "[MSG] RRC Connection SetupComplete\n");
-
-      MSC_LOG_RX_MESSAGE(
-        MSC_RRC_ENB,
-        MSC_RRC_UE,
-        Rx_sdu,
-        sdu_sizeP,
-        MSC_AS_TIME_FMT" RRCConnectionSetupComplete UE %x size %u",
-        MSC_AS_TIME_ARGS(ctxt_pP),
-        ue_context_p->ue_context.rnti,
-        sdu_sizeP);
-
-      LOG_D(RRC,
-            PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
-            "(RRCConnectionSetupComplete) ---> RRC_eNB\n",
-            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
-            DCCH,
-            sdu_sizeP);
-
-      if (ul_dcch_msg->message.choice.c1.choice.rrcConnectionSetupComplete.criticalExtensions.present ==
-          RRCConnectionSetupComplete__criticalExtensions_PR_c1) {
-        if (ul_dcch_msg->message.choice.c1.choice.rrcConnectionSetupComplete.criticalExtensions.choice.c1.
-            present ==
-            RRCConnectionSetupComplete__criticalExtensions__c1_PR_rrcConnectionSetupComplete_r8) {
-          
-          if ((RC.rrc[ctxt_pP->module_id]->node_type  == ngran_eNB_DU) ||
-	          (RC.rrc[ctxt_pP->module_id]->node_type  == ngran_gNB_DU)  ) {
-/*
-            MessageDef                            *message_p;
-          	message_p = itti_alloc_new_message (TASK_RRC_ENB, F1AP_UL_RRC_MESSAGE);
-      		F1AP_UL_RRC_MESSAGE (message_p).rrc_container =  (uint8_t*)&ul_dcch_msg->message.choice.c1.choice.rrcConnectionSetupComplete.criticalExtensions.choice.c1.choice.rrcConnectionSetupComplete_r8;
-            F1AP_UL_RRC_MESSAGE (message_p).rrc_container_length = strlen(&ul_dcch_msg->message.choice.c1.choice.rrcConnectionSetupComplete.criticalExtensions.choice.c1.choice.rrcConnectionSetupComplete_r8);
-      	    F1AP_UL_RRC_MESSAGE (message_p).gNB_CU_ue_id     = 0;  
-      		F1AP_UL_RRC_MESSAGE (message_p).gNB_DU_ue_id = 0;
-      		F1AP_UL_RRC_MESSAGE (message_p).rnti = ue_context_p->ue_context.rnti; 
-      		F1AP_UL_RRC_MESSAGE (message_p).srb_id = DCCH;  
-      		itti_send_msg_to_task (TASK_DU_F1, ctxt_pP->module_id, message_p);
-      		LOG_D(RRC, "Send F1AP_UL_RRC_MESSAGE with ITTI\n");*/
-		  } else { // eNB or CU node type 
-          		rrc_eNB_process_RRCConnectionSetupComplete(
-           		  ctxt_pP,
-                  ue_context_p,
-                  &ul_dcch_msg->message.choice.c1.choice.rrcConnectionSetupComplete.criticalExtensions.choice.c1.choice.rrcConnectionSetupComplete_r8);
-                ue_context_p->ue_context.Status = RRC_CONNECTED;
-                LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_CONNECTED \n",
-                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
-	     }
-	  //WARNING:Inform the controller about the UE activation. Should be moved to RRC agent in the future
-	  if (flexran_agent_get_rrc_xface(ctxt_pP->module_id)) {
-	    flexran_agent_get_rrc_xface(ctxt_pP->module_id)->flexran_agent_notify_ue_state_change(ctxt_pP->module_id,
-										  ue_context_p->ue_id_rnti,
-										  PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_ACTIVATED);
-	  }
+
+      case LTE_UL_DCCH_MessageType__c1_PR_securityModeComplete:
+        T(T_ENB_RRC_SECURITY_MODE_COMPLETE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
+          T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
+
+        // to avoid segmentation fault
+        if(!ue_context_p) {
+          LOG_I(RRC, "Processing securityModeComplete UE %x, ue_context_p is NULL\n", ctxt_pP->rnti);
+          break;
         }
-      }
 
-      ue_context_p->ue_context.ue_release_timer=0;
-      break;
+        LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
+                    "[MSG] RRC Security Mode Complete\n");
+        MSC_LOG_RX_MESSAGE(
+          MSC_RRC_ENB,
+          MSC_RRC_UE,
+          Rx_sdu,
+          sdu_sizeP,
+          MSC_AS_TIME_FMT" securityModeComplete UE %x size %u",
+          MSC_AS_TIME_ARGS(ctxt_pP),
+          ue_context_p->ue_context.rnti,
+          sdu_sizeP);
+        LOG_I(RRC,
+              PROTOCOL_RRC_CTXT_UE_FMT" received securityModeComplete on UL-DCCH %d from UE\n",
+              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
+              DCCH);
+        LOG_D(RRC,
+              PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
+              "(securityModeComplete) ---> RRC_eNB\n",
+              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
+              DCCH,
+              sdu_sizeP);
+
+        if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
+          xer_fprint(stdout, &asn_DEF_LTE_UL_DCCH_Message, (void *)ul_dcch_msg);
+        }
 
-    case UL_DCCH_MessageType__c1_PR_securityModeComplete:
-      T(T_ENB_RRC_SECURITY_MODE_COMPLETE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
-        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
-      // to avoid segmentation fault
-      if(!ue_context_p){
-        LOG_I(RRC, "Processing securityModeComplete UE %x, ue_context_p is NULL\n", ctxt_pP->rnti);
+        // confirm with PDCP about the security mode for DCCH
+        //rrc_pdcp_config_req (enb_mod_idP, frameP, 1,CONFIG_ACTION_SET_SECURITY_MODE, (ue_mod_idP * NB_RB_MAX) + DCCH, 0x77);
+        // continue the procedure
+        rrc_eNB_generate_UECapabilityEnquiry(
+          ctxt_pP,
+          ue_context_p);
         break;
-      }
-      LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
-                  "[MSG] RRC Security Mode Complete\n");
 
+      case LTE_UL_DCCH_MessageType__c1_PR_securityModeFailure:
+        T(T_ENB_RRC_SECURITY_MODE_FAILURE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
+          T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
+        LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
+                    "[MSG] RRC Security Mode Failure\n");
+        MSC_LOG_RX_MESSAGE(
+          MSC_RRC_ENB,
+          MSC_RRC_UE,
+          Rx_sdu,
+          sdu_sizeP,
+          MSC_AS_TIME_FMT" securityModeFailure UE %x size %u",
+          MSC_AS_TIME_ARGS(ctxt_pP),
+          ue_context_p->ue_context.rnti,
+          sdu_sizeP);
+        LOG_W(RRC,
+              PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
+              "(securityModeFailure) ---> RRC_eNB\n",
+              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
+              DCCH,
+              sdu_sizeP);
+
+        if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
+          xer_fprint(stdout, &asn_DEF_LTE_UL_DCCH_Message, (void *)ul_dcch_msg);
+        }
 
-      MSC_LOG_RX_MESSAGE(
-        MSC_RRC_ENB,
-        MSC_RRC_UE,
-        Rx_sdu,
-        sdu_sizeP,
-        MSC_AS_TIME_FMT" securityModeComplete UE %x size %u",
-        MSC_AS_TIME_ARGS(ctxt_pP),
-        ue_context_p->ue_context.rnti,
-        sdu_sizeP);
+        // cancel the security mode in PDCP
+        // followup with the remaining procedure
+        //#warning "LG Removed rrc_eNB_generate_UECapabilityEnquiry after receiving securityModeFailure"
+        rrc_eNB_generate_UECapabilityEnquiry(ctxt_pP, ue_context_p);
+        break;
 
-      LOG_I(RRC,
-            PROTOCOL_RRC_CTXT_UE_FMT" received securityModeComplete on UL-DCCH %d from UE\n",
-            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
-            DCCH);
-      LOG_D(RRC,
-            PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
-            "(securityModeComplete) ---> RRC_eNB\n",
-            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
-            DCCH,
-            sdu_sizeP);
-      if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-         xer_fprint(stdout, &asn_DEF_UL_DCCH_Message, (void *)ul_dcch_msg);
-      }
-      // confirm with PDCP about the security mode for DCCH
-      //rrc_pdcp_config_req (enb_mod_idP, frameP, 1,CONFIG_ACTION_SET_SECURITY_MODE, (ue_mod_idP * NB_RB_MAX) + DCCH, 0x77);
-      // continue the procedure
-      rrc_eNB_generate_UECapabilityEnquiry(
-        ctxt_pP,
-        ue_context_p);
-      break;
+      case LTE_UL_DCCH_MessageType__c1_PR_ueCapabilityInformation:
+        T(T_ENB_RRC_UE_CAPABILITY_INFORMATION, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
+          T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
 
-    case UL_DCCH_MessageType__c1_PR_securityModeFailure:
-      T(T_ENB_RRC_SECURITY_MODE_FAILURE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
-        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
-
-      LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
-                  "[MSG] RRC Security Mode Failure\n");
-
-      MSC_LOG_RX_MESSAGE(
-        MSC_RRC_ENB,
-        MSC_RRC_UE,
-        Rx_sdu,
-        sdu_sizeP,
-        MSC_AS_TIME_FMT" securityModeFailure UE %x size %u",
-        MSC_AS_TIME_ARGS(ctxt_pP),
-        ue_context_p->ue_context.rnti,
-        sdu_sizeP);
-
-      LOG_W(RRC,
-            PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
-            "(securityModeFailure) ---> RRC_eNB\n",
-            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
-            DCCH,
-            sdu_sizeP);
-      if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-         xer_fprint(stdout, &asn_DEF_UL_DCCH_Message, (void *)ul_dcch_msg);
-      }
-      // cancel the security mode in PDCP
+        // to avoid segmentation fault
+        if(!ue_context_p) {
+          LOG_I(RRC, "Processing ueCapabilityInformation UE %x, ue_context_p is NULL\n", ctxt_pP->rnti);
+          break;
+        }
+
+        LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
+                    "[MSG] RRC UECapablility Information\n");
+        MSC_LOG_RX_MESSAGE(
+          MSC_RRC_ENB,
+          MSC_RRC_UE,
+          Rx_sdu,
+          sdu_sizeP,
+          MSC_AS_TIME_FMT" ueCapabilityInformation UE %x size %u",
+          MSC_AS_TIME_ARGS(ctxt_pP),
+          ue_context_p->ue_context.rnti,
+          sdu_sizeP);
+        LOG_I(RRC,
+              PROTOCOL_RRC_CTXT_UE_FMT" received ueCapabilityInformation on UL-DCCH %d from UE\n",
+              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
+              DCCH);
+        LOG_D(RRC,
+              PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
+              "(UECapabilityInformation) ---> RRC_eNB\n",
+              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
+              DCCH,
+              sdu_sizeP);
 
-      // followup with the remaining procedure
-//#warning "LG Removed rrc_eNB_generate_UECapabilityEnquiry after receiving securityModeFailure"
-      rrc_eNB_generate_UECapabilityEnquiry(ctxt_pP, ue_context_p);
-      break;
+        if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
+          xer_fprint(stdout, &asn_DEF_LTE_UL_DCCH_Message, (void *)ul_dcch_msg);
+        }
 
-    case UL_DCCH_MessageType__c1_PR_ueCapabilityInformation:
-      T(T_ENB_RRC_UE_CAPABILITY_INFORMATION, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
-        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
-      // to avoid segmentation fault
-      if(!ue_context_p){
-          LOG_I(RRC, "Processing ueCapabilityInformation UE %x, ue_context_p is NULL\n", ctxt_pP->rnti);
-          break;
-      }
+        LOG_I(RRC, "got UE capabilities for UE %x\n", ctxt_pP->rnti);
 
-      LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
-                  "[MSG] RRC UECapablility Information\n");
+        if (ue_context_p->ue_context.UE_Capability) {
+          LOG_I(RRC, "freeing old UE capabilities for UE %x\n", ctxt_pP->rnti);
+          ASN_STRUCT_FREE(asn_DEF_LTE_UE_EUTRA_Capability,
+                          ue_context_p->ue_context.UE_Capability);
+          ue_context_p->ue_context.UE_Capability = 0;
+        }
 
-      MSC_LOG_RX_MESSAGE(
-        MSC_RRC_ENB,
-        MSC_RRC_UE,
-        Rx_sdu,
-        sdu_sizeP,
-        MSC_AS_TIME_FMT" ueCapabilityInformation UE %x size %u",
-        MSC_AS_TIME_ARGS(ctxt_pP),
-        ue_context_p->ue_context.rnti,
-        sdu_sizeP);
+        dec_rval = uper_decode(NULL,
+                               &asn_DEF_LTE_UE_EUTRA_Capability,
+                               (void **)&ue_context_p->ue_context.UE_Capability,
+                               ul_dcch_msg->message.choice.c1.choice.ueCapabilityInformation.criticalExtensions.
+                               choice.c1.choice.ueCapabilityInformation_r8.ue_CapabilityRAT_ContainerList.list.
+                               array[0]->ueCapabilityRAT_Container.buf,
+                               ul_dcch_msg->message.choice.c1.choice.ueCapabilityInformation.criticalExtensions.
+                               choice.c1.choice.ueCapabilityInformation_r8.ue_CapabilityRAT_ContainerList.list.
+                               array[0]->ueCapabilityRAT_Container.size, 0, 0);
+        ue_context_p->ue_context.UE_Capability_size = ul_dcch_msg->message.choice.c1.choice.ueCapabilityInformation.criticalExtensions.
+            choice.c1.choice.ueCapabilityInformation_r8.ue_CapabilityRAT_ContainerList.list.
+            array[0]->ueCapabilityRAT_Container.size;
+
+        if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
+          xer_fprint(stdout, &asn_DEF_LTE_UE_EUTRA_Capability, ue_context_p->ue_context.UE_Capability);
+        }
 
-      LOG_I(RRC,
-            PROTOCOL_RRC_CTXT_UE_FMT" received ueCapabilityInformation on UL-DCCH %d from UE\n",
-            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
-            DCCH);
-      LOG_D(RRC,
-            PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
-            "(UECapabilityInformation) ---> RRC_eNB\n",
-            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
-            DCCH,
-            sdu_sizeP);
-      if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-          xer_fprint(stdout, &asn_DEF_UL_DCCH_Message, (void *)ul_dcch_msg);
-      }
-      LOG_I(RRC, "got UE capabilities for UE %x\n", ctxt_pP->rnti);
-      if (ue_context_p->ue_context.UE_Capability) {
-        LOG_I(RRC, "freeing old UE capabilities for UE %x\n", ctxt_pP->rnti);
-        ASN_STRUCT_FREE(asn_DEF_UE_EUTRA_Capability,
-                        ue_context_p->ue_context.UE_Capability);
-        ue_context_p->ue_context.UE_Capability = 0;
-      }
-      dec_rval = uper_decode(NULL,
-                             &asn_DEF_UE_EUTRA_Capability,
-                             (void **)&ue_context_p->ue_context.UE_Capability,
-                             ul_dcch_msg->message.choice.c1.choice.ueCapabilityInformation.criticalExtensions.
-                             choice.c1.choice.ueCapabilityInformation_r8.ue_CapabilityRAT_ContainerList.list.
-                             array[0]->ueCapabilityRAT_Container.buf,
-                             ul_dcch_msg->message.choice.c1.choice.ueCapabilityInformation.criticalExtensions.
-                             choice.c1.choice.ueCapabilityInformation_r8.ue_CapabilityRAT_ContainerList.list.
-                             array[0]->ueCapabilityRAT_Container.size, 0, 0);
-      if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-         xer_fprint(stdout, &asn_DEF_UE_EUTRA_Capability, ue_context_p->ue_context.UE_Capability);
-      }
+        if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) {
+          LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Failed to decode UE capabilities (%zu bytes)\n",
+                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
+                dec_rval.consumed);
+          ASN_STRUCT_FREE(asn_DEF_LTE_UE_EUTRA_Capability,
+                          ue_context_p->ue_context.UE_Capability);
+          ue_context_p->ue_context.UE_Capability = 0;
+        }
 
-      if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) {
-        LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Failed to decode UE capabilities (%zu bytes)\n",
-              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
-              dec_rval.consumed);
-        ASN_STRUCT_FREE(asn_DEF_UE_EUTRA_Capability,
-                        ue_context_p->ue_context.UE_Capability);
-        ue_context_p->ue_context.UE_Capability = 0;
-      }
+        if (EPC_MODE_ENABLED) {
+          if (EPC_MODE_ENABLED == 1) {
+            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;
 
-      if (EPC_MODE_ENABLED) {
+          for (i = 0; i < ue_context_p->ue_context.nb_of_e_rabs; i++) {
+            ue_context_p->ue_context.e_rab[i].status = E_RAB_STATUS_NEW;
+            ue_context_p->ue_context.e_rab[i].param.e_rab_id = 1+i;
+            ue_context_p->ue_context.e_rab[i].param.qos.qci=9;
+          }
 
-        if (EPC_MODE_ENABLED == 1) {
-  	  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;
-  	for (i = 0; i < ue_context_p->ue_context.nb_of_e_rabs; i++){
-  	  ue_context_p->ue_context.e_rab[i].status = E_RAB_STATUS_NEW;
-  	  ue_context_p->ue_context.e_rab[i].param.e_rab_id = 1+i;
-  	  ue_context_p->ue_context.e_rab[i].param.qos.qci=9;
-  	}
-  	ue_context_p->ue_context.setup_e_rabs =ue_context_p->ue_context.nb_of_e_rabs;
-      }
+          ue_context_p->ue_context.setup_e_rabs =ue_context_p->ue_context.nb_of_e_rabs;
+        }
 
-      rrc_eNB_generate_defaultRRCConnectionReconfiguration(ctxt_pP,
-          ue_context_p,
-          RC.rrc[ctxt_pP->module_id]->HO_flag);
-      break;
+        rrc_eNB_generate_defaultRRCConnectionReconfiguration(ctxt_pP,
+            ue_context_p,
+            RC.rrc[ctxt_pP->module_id]->HO_flag);
+        break;
 
-    case UL_DCCH_MessageType__c1_PR_ulHandoverPreparationTransfer:
-      T(T_ENB_RRC_UL_HANDOVER_PREPARATION_TRANSFER, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
-        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
+      case LTE_UL_DCCH_MessageType__c1_PR_ulHandoverPreparationTransfer:
+        T(T_ENB_RRC_UL_HANDOVER_PREPARATION_TRANSFER, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
+          T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
+        break;
 
-      break;
+      case LTE_UL_DCCH_MessageType__c1_PR_ulInformationTransfer:
+        T(T_ENB_RRC_UL_INFORMATION_TRANSFER, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
+          T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
 
-    case UL_DCCH_MessageType__c1_PR_ulInformationTransfer:
-      T(T_ENB_RRC_UL_INFORMATION_TRANSFER, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
-        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
-      // to avoid segmentation fault
-      if(!ue_context_p){
+        // to avoid segmentation fault
+        if(!ue_context_p) {
           LOG_I(RRC, "Processing ulInformationTransfer UE %x, ue_context_p is NULL\n", ctxt_pP->rnti);
           break;
-      }
-
-      LOG_D(RRC,"[MSG] RRC UL Information Transfer \n");
-      LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
-                  "[MSG] RRC UL Information Transfer \n");
-
-      MSC_LOG_RX_MESSAGE(
-        MSC_RRC_ENB,
-        MSC_RRC_UE,
-        Rx_sdu,
-        sdu_sizeP,
-        MSC_AS_TIME_FMT" ulInformationTransfer UE %x size %u",
-        MSC_AS_TIME_ARGS(ctxt_pP),
-        ue_context_p->ue_context.rnti,
-        sdu_sizeP);
-
-      if (EPC_MODE_ENABLED == 1) {
-        rrc_eNB_send_S1AP_UPLINK_NAS(ctxt_pP,
-                                     ue_context_p,
-                                     ul_dcch_msg);
-      }
-      break;
-
-    case UL_DCCH_MessageType__c1_PR_counterCheckResponse:
-      T(T_ENB_RRC_COUNTER_CHECK_RESPONSE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
-        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
+        }
 
-      break;
+        LOG_D(RRC,"[MSG] RRC UL Information Transfer \n");
+        LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
+                    "[MSG] RRC UL Information Transfer \n");
+        MSC_LOG_RX_MESSAGE(
+          MSC_RRC_ENB,
+          MSC_RRC_UE,
+          Rx_sdu,
+          sdu_sizeP,
+          MSC_AS_TIME_FMT" ulInformationTransfer UE %x size %u",
+          MSC_AS_TIME_ARGS(ctxt_pP),
+          ue_context_p->ue_context.rnti,
+          sdu_sizeP);
 
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+        if (EPC_MODE_ENABLED == 1) {
+          rrc_eNB_send_S1AP_UPLINK_NAS(ctxt_pP,
+                                       ue_context_p,
+                                       ul_dcch_msg);
+        }
 
-    case UL_DCCH_MessageType__c1_PR_ueInformationResponse_r9:
-      T(T_ENB_RRC_UE_INFORMATION_RESPONSE_R9, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
-        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
+        break;
 
-      break;
+      case LTE_UL_DCCH_MessageType__c1_PR_counterCheckResponse:
+        T(T_ENB_RRC_COUNTER_CHECK_RESPONSE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
+          T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
+        break;
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
 
-    case UL_DCCH_MessageType__c1_PR_proximityIndication_r9:
-      T(T_ENB_RRC_PROXIMITY_INDICATION_R9, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
-        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
+      case LTE_UL_DCCH_MessageType__c1_PR_ueInformationResponse_r9:
+        T(T_ENB_RRC_UE_INFORMATION_RESPONSE_R9, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
+          T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
+        break;
 
-      break;
+      case LTE_UL_DCCH_MessageType__c1_PR_proximityIndication_r9:
+        T(T_ENB_RRC_PROXIMITY_INDICATION_R9, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
+          T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
+        break;
 #endif
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-    case UL_DCCH_MessageType__c1_PR_rnReconfigurationComplete_r10:
-      T(T_ENB_RRC_RECONFIGURATION_COMPLETE_R10, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
-        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
-
-      break;
-
-    case UL_DCCH_MessageType__c1_PR_mbmsCountingResponse_r10:
-      T(T_ENB_RRC_MBMS_COUNTING_RESPONSE_R10, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
-        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
-
-      break;
+      case LTE_UL_DCCH_MessageType__c1_PR_rnReconfigurationComplete_r10:
+        T(T_ENB_RRC_RECONFIGURATION_COMPLETE_R10, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
+          T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
+        break;
 
-    case UL_DCCH_MessageType__c1_PR_interFreqRSTDMeasurementIndication_r10:
-      T(T_ENB_RRC_INTER_FREQ_RSTD_MEASUREMENT_INDICATION, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
-        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
+      case LTE_UL_DCCH_MessageType__c1_PR_mbmsCountingResponse_r10:
+        T(T_ENB_RRC_MBMS_COUNTING_RESPONSE_R10, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
+          T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
+        break;
 
-      break;
+      case LTE_UL_DCCH_MessageType__c1_PR_interFreqRSTDMeasurementIndication_r10:
+        T(T_ENB_RRC_INTER_FREQ_RSTD_MEASUREMENT_INDICATION, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
+          T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
+        break;
 #endif
 
-    default:
-      T(T_ENB_RRC_UNKNOW_MESSAGE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
-        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
-
-      LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Unknown message %s:%u\n",
-            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
-            __FILE__, __LINE__);
-      return -1;
+      default:
+        T(T_ENB_RRC_UNKNOW_MESSAGE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
+          T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
+        LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Unknown message %s:%u\n",
+              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
+              __FILE__, __LINE__);
+        return -1;
     }
 
     return 0;
     //TTN for D2D
-  } else if (ul_dcch_msg->message.present == UL_DCCH_MessageType_PR_messageClassExtension){
-     LOG_I(RRC, "THINH [UL_DCCH_MessageType_PR_messageClassExtension]\n");
+  } else if (ul_dcch_msg->message.present == LTE_UL_DCCH_MessageType_PR_messageClassExtension) {
+    LOG_I(RRC, "THINH [LTE_UL_DCCH_MessageType_PR_messageClassExtension]\n");
 
-     switch (ul_dcch_msg->message.choice.messageClassExtension.present) {
-     case UL_DCCH_MessageType__messageClassExtension_PR_NOTHING: /* No components present */
+    switch (ul_dcch_msg->message.choice.messageClassExtension.present) {
+      case LTE_UL_DCCH_MessageType__messageClassExtension_PR_NOTHING: /* No components present */
         break;
-     case UL_DCCH_MessageType__messageClassExtension_PR_c2: //SidelinkUEInformation
-     //case UL_DCCH_MessageType__messageClassExtension__c2_PR_sidelinkUEInformation_r12: //SidelinkUEInformation
-        LOG_I(RRC,"THINH [UL_DCCH_MessageType__messageClassExtension_PR_c2]\n");
 
+      case LTE_UL_DCCH_MessageType__messageClassExtension_PR_c2: //SidelinkUEInformation
+        //case UL_DCCH_MessageType__messageClassExtension__c2_PR_sidelinkUEInformation_r12: //SidelinkUEInformation
+        LOG_I(RRC,"THINH [LTE_UL_DCCH_MessageType__messageClassExtension_PR_c2]\n");
         LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
                     "[MSG] RRC SidelinkUEInformation \n");
-
         MSC_LOG_RX_MESSAGE(
-              MSC_RRC_ENB,
-              MSC_RRC_UE,
-              Rx_sdu,
-              sdu_sizeP,
-              MSC_AS_TIME_FMT" SidelinkUEInformation UE %x size %u",
-              MSC_AS_TIME_ARGS(ctxt_pP),
-              ue_context_p->ue_context.rnti,
-              sdu_sizeP);
-
+          MSC_RRC_ENB,
+          MSC_RRC_UE,
+          Rx_sdu,
+          sdu_sizeP,
+          MSC_AS_TIME_FMT" SidelinkUEInformation UE %x size %u",
+          MSC_AS_TIME_ARGS(ctxt_pP),
+          ue_context_p->ue_context.rnti,
+          sdu_sizeP);
         LOG_I(RRC,
               PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
               "(SidelinkUEInformation) ---> RRC_eNB\n",
               PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
               DCCH,
               sdu_sizeP);
-
         rrc_eNB_process_SidelinkUEInformation(
-              ctxt_pP,
-              ue_context_p,
-              &ul_dcch_msg->message.choice.messageClassExtension.choice.c2.choice.sidelinkUEInformation_r12);
+          ctxt_pP,
+          ue_context_p,
+          &ul_dcch_msg->message.choice.messageClassExtension.choice.c2.choice.sidelinkUEInformation_r12);
         break;
-     default:
+
+      default:
         break;
-     }
-     //end TTN
+    }
+
+    //end TTN
   } else {
     LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Unknown error %s:%u\n",
           PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
@@ -7439,16 +8313,15 @@ if (ue_context_p->ue_context.nb_of_modify_e_rabs > 0) {
 }
 
 #if defined(ENABLE_ITTI)
-void rrc_eNB_reconfigure_DRBs (const protocol_ctxt_t* const ctxt_pP,
-			       rrc_eNB_ue_context_t*  ue_context_pP){
-
+void rrc_eNB_reconfigure_DRBs (const protocol_ctxt_t *const ctxt_pP,
+                               rrc_eNB_ue_context_t  *ue_context_pP) {
   int i;
   int e_rab_done=0;
-  for (i = 0; 
+
+  for (i = 0;
        i < 3;//NB_RB_MAX - 3;  // S1AP_MAX_E_RAB
        i++) {
-    
-    if ( ue_context_pP->ue_context.e_rab[i].status < E_RAB_STATUS_DONE){ 
+    if ( ue_context_pP->ue_context.e_rab[i].status < E_RAB_STATUS_DONE) {
       ue_context_pP->ue_context.e_rab[i].status = E_RAB_STATUS_NEW;
       ue_context_pP->ue_context.e_rab[i].param.e_rab_id = i + 1;
       ue_context_pP->ue_context.e_rab[i].param.qos.qci = i % 9;
@@ -7457,18 +8330,17 @@ void rrc_eNB_reconfigure_DRBs (const protocol_ctxt_t* const ctxt_pP,
       ue_context_pP->ue_context.e_rab[i].param.qos.allocation_retention_priority.pre_emp_vulnerability= PRE_EMPTION_VULNERABILITY_DISABLED;
       ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer = NULL;
       ue_context_pP->ue_context.e_rab[i].param.nas_pdu.length = 0;
-      //	memset (ue_context_pP->ue_context.e_rab[i].param.sgw_addr.buffer,0,20);
+      //  memset (ue_context_pP->ue_context.e_rab[i].param.sgw_addr.buffer,0,20);
       ue_context_pP->ue_context.e_rab[i].param.sgw_addr.length = 0;
       ue_context_pP->ue_context.e_rab[i].param.gtp_teid=0;
-      
       ue_context_pP->ue_context.nb_of_e_rabs++;
       e_rab_done++;
-      LOG_I(RRC,"setting up the dedicated DRBs %d (index %d) status %d \n", 
-	    ue_context_pP->ue_context.e_rab[i].param.e_rab_id, i, ue_context_pP->ue_context.e_rab[i].status);
+      LOG_I(RRC,"setting up the dedicated DRBs %d (index %d) status %d \n",
+            ue_context_pP->ue_context.e_rab[i].param.e_rab_id, i, ue_context_pP->ue_context.e_rab[i].status);
     }
   }
+
   ue_context_pP->ue_context.setup_e_rabs+=e_rab_done;
- 
   rrc_eNB_generate_dedicatedRRCConnectionReconfiguration(ctxt_pP, ue_context_pP, 0);
 }
 
@@ -7501,16 +8373,16 @@ void handle_f1_setup_req(f1ap_setup_req_t *f1_setup_req) {
        
         memcpy((void*)rrc->carrier[0].MIB,f1_setup_req->mib[i],f1_setup_req->mib_length[i]);
         asn_dec_rval_t dec_rval = uper_decode_complete(NULL,
-        					       &asn_DEF_BCCH_BCH_Message,
+                         &asn_DEF_LTE_BCCH_BCH_Message,
         					       (void **)&rrc->carrier[0].mib_DU,
         					       f1_setup_req->mib[i],
         					       f1_setup_req->mib_length[i]);
         AssertFatal(dec_rval.code == RC_OK,
-        	    "[eNB_DU %"PRIu8"] Failed to decode BCCH_BCH_MESSAGE (%zu bits)\n",
+              "[eNB_DU %"PRIu8"] Failed to decode LTE_BCCH_BCH_MESSAGE (%zu bits)\n",
         	    j,
         	    dec_rval.consumed );	
-        BCCH_BCH_Message_t *mib = &rrc->carrier[0].mib;
-        BCCH_BCH_Message_t *mib_DU = rrc->carrier[0].mib_DU;
+        LTE_BCCH_BCH_Message_t *mib = &rrc->carrier[0].mib;
+        LTE_BCCH_BCH_Message_t *mib_DU = rrc->carrier[0].mib_DU;
         mib->message.dl_Bandwidth = mib_DU->message.dl_Bandwidth;
         mib->message.phich_Config.phich_Resource = mib_DU->message.phich_Config.phich_Resource;
         mib->message.phich_Config.phich_Duration = mib_DU->message.phich_Config.phich_Duration;
@@ -7519,20 +8391,20 @@ void handle_f1_setup_req(f1ap_setup_req_t *f1_setup_req) {
         rrc->carrier[0].sizeof_SIB1 = f1_setup_req->sib1_length[i];
         memcpy((void*)rrc->carrier[0].SIB1,f1_setup_req->sib1[i],f1_setup_req->sib1_length[i]); 
         dec_rval = uper_decode_complete(NULL,
-        				&asn_DEF_BCCH_DL_SCH_Message,
+                &asn_DEF_LTE_BCCH_DL_SCH_Message,
         				(void **)&rrc->carrier[0].siblock1_DU,
         				f1_setup_req->sib1[i],
         				f1_setup_req->sib1_length[i]);
         AssertFatal(dec_rval.code == RC_OK,
-        	    "[eNB_DU %"PRIu8"] Failed to decode BCCH_DLSCH_MESSAGE (%zu bits)\n",
+              "[eNB_DU %"PRIu8"] Failed to decode LTE_BCCH_DLSCH_MESSAGE (%zu bits)\n",
         	    j,
         	    dec_rval.consumed );	
         // Parse message and extract SystemInformationBlockType1 field
-        BCCH_DL_SCH_Message_t *bcch_message = rrc->carrier[0].siblock1_DU;
-        AssertFatal(bcch_message->message.present == BCCH_DL_SCH_MessageType_PR_c1,
-        	    "bcch_message->message.present != BCCH_DL_SCH_MessageType_PR_c1\n");
-        AssertFatal(bcch_message->message.choice.c1.present == BCCH_DL_SCH_MessageType__c1_PR_systemInformationBlockType1,
-        	    "bcch_message->message.choice.c1.present != BCCH_DL_SCH_MessageType__c1_PR_systemInformationBlockType1\n");
+        LTE_BCCH_DL_SCH_Message_t *bcch_message = rrc->carrier[0].siblock1_DU;
+        AssertFatal(bcch_message->message.present == LTE_BCCH_DL_SCH_MessageType_PR_c1,
+              "bcch_message->message.present != LTE_BCCH_DL_SCH_MessageType_PR_c1\n");
+        AssertFatal(bcch_message->message.choice.c1.present == LTE_BCCH_DL_SCH_MessageType__c1_PR_systemInformationBlockType1,
+              "bcch_message->message.choice.c1.present != LTE_BCCH_DL_SCH_MessageType__c1_PR_systemInformationBlockType1\n");
         rrc->carrier[0].sib1 = &bcch_message->message.choice.c1.choice.systemInformationBlockType1;
         rrc->carrier[0].physCellId = f1_setup_req->nr_pci[i];
         // prepare F1_SETUP_RESPONSE
@@ -7594,25 +8466,19 @@ void rrc_enb_init(void) {
 
 //-----------------------------------------------------------------------------
 void *rrc_enb_process_itti_msg(void *notUsed) {
-    MessageDef                         *msg_p;
-    const char                         *msg_name_p;
-    instance_t                          instance;
-    int                                rrc_inst;
-    int                                 result;
-    SRB_INFO                           *srb_info_p;
-    int                                 CC_id;
-
-    protocol_ctxt_t                     ctxt;
-
-    // Wait for a message
-    itti_receive_msg(TASK_RRC_ENB, &msg_p);
-
-    msg_name_p = ITTI_MSG_NAME(msg_p);
-    instance = ITTI_MSG_INSTANCE(msg_p);
-    
-    LOG_I(RRC,"Received message %s\n",msg_name_p);
+  MessageDef                         *msg_p;
+  const char                         *msg_name_p;
+  instance_t                          instance;
+  int                                 rrc_inst;
+  int                                 result;
+  protocol_ctxt_t                     ctxt;
+  // Wait for a message
+  itti_receive_msg(TASK_RRC_ENB, &msg_p);
+  msg_name_p = ITTI_MSG_NAME(msg_p);
+  instance = ITTI_MSG_INSTANCE(msg_p);
+  LOG_I(RRC,"Received message %s\n",msg_name_p);
 
-    switch (ITTI_MSG_ID(msg_p)) {
+  switch (ITTI_MSG_ID(msg_p)) {
     case TERMINATE_MESSAGE:
       LOG_W(RRC, " *** Exiting RRC thread\n");
       itti_exit_task();
@@ -7622,7 +8488,7 @@ void *rrc_enb_process_itti_msg(void *notUsed) {
       LOG_I(RRC, "[eNB %d] Received %s\n", instance, msg_name_p);
       break;
 
-      /* Messages from MAC */
+    /* Messages from MAC */
     case RRC_MAC_CCCH_DATA_IND:
 
       rrc_inst = RRC_MAC_CCCH_DATA_IND(msg_p).enb_index;
@@ -7633,48 +8499,20 @@ void *rrc_enb_process_itti_msg(void *notUsed) {
                                     RRC_MAC_CCCH_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 %s\n",
-            PROTOCOL_RRC_CTXT_UE_ARGS(&ctxt),
-            msg_name_p);
-
-      // this part will be done in rrc_eNB_decode_ccch
-      /*
-      struct rrc_eNB_ue_context_s *ue_context_p = rrc_eNB_get_ue_context(RC.rrc[rrc_inst],
-									 RRC_MAC_CCCH_DATA_IND(msg_p).rnti);
-
-      if (ue_context_p == NULL) {
 
-	// create a ue_context with rnti as random value, will be updated when Attach Request is received
-	ue_context_p = rrc_eNB_get_next_free_ue_context(&ctxt,
-							RRC_MAC_CCCH_DATA_IND(msg_p).rnti
-							);
-      }
-
-      eNB_RRC_UE_t *ue_p = &ue_context_p->ue_context; 
-      srb_info_p = &ue_p->Srb0;
-
-      LOG_I(RRC,"Decoding CCCH : inst %d, CC_id %d, ue_context %p (rnti %x), sib_info_p->Rx_buffer.payload_size %d\n",
-	    rrc_inst,CC_id,ue_p, ue_p->rnti,RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size);
-       
-      CC_id = RRC_MAC_CCCH_DATA_IND(msg_p).CC_id;
-      memcpy(srb_info_p->Rx_buffer.Payload,
-             RRC_MAC_CCCH_DATA_IND(msg_p).sdu,
-             RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size);
-      srb_info_p->Rx_buffer.payload_size = RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size;
-      srb_info_p->Active = 1;
-
-      rrc_eNB_decode_ccch(&ctxt, (uint8_t*)srb_info_p->Rx_buffer.Payload,srb_info_p->Rx_buffer.payload_size, CC_id);
-      */
       if (RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size >= RRC_BUFFER_SIZE_MAX) {
-          LOG_W(RRC, "CCCH message has size %d > %d\n",RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size,RRC_BUFFER_SIZE_MAX);
+        LOG_I(RRC, "CCCH message has size %d > %d\n",
+              RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size,RRC_BUFFER_SIZE_MAX);
+        break;
       }
-      rrc_eNB_decode_ccch(&ctxt, 
-      					  (uint8_t*)RRC_MAC_CCCH_DATA_IND(msg_p).sdu,
-             			  RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size,
-             			  RRC_MAC_CCCH_DATA_IND(msg_p).CC_id);
+
+      rrc_eNB_decode_ccch(&ctxt,
+                          (uint8_t*)RRC_MAC_CCCH_DATA_IND(msg_p).sdu,
+                          RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size,
+                          RRC_MAC_CCCH_DATA_IND(msg_p).CC_id);
       break;
-	    
-      /* Messages from PDCP */
+
+    /* Messages from PDCP */
     case RRC_DCCH_DATA_IND:
       PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt,
                                     instance,
@@ -7690,18 +8528,18 @@ void *rrc_enb_process_itti_msg(void *notUsed) {
                           RRC_DCCH_DATA_IND(msg_p).dcch_index,
                           RRC_DCCH_DATA_IND(msg_p).sdu_p,
                           RRC_DCCH_DATA_IND(msg_p).sdu_size);
-
       // Message buffer has been processed, free it now.
       result = itti_free(ITTI_MSG_ORIGIN_ID(msg_p), RRC_DCCH_DATA_IND(msg_p).sdu_p);
+
       if (result != EXIT_SUCCESS) {
-          LOG_I(RRC, "Failed to free memory (%d)!\n",result);
-          break;
+        LOG_I(RRC, "Failed to free memory (%d)!\n",result);
+        break;
       }
-      break;
 
+      break;
 #   if defined(ENABLE_USE_MME)
 
-      /* Messages from S1AP */
+    /* Messages from S1AP */
     case S1AP_DOWNLINK_NAS:
       rrc_eNB_process_S1AP_DOWNLINK_NAS(msg_p, msg_name_p, instance, &rrc_eNB_mui);
       break;
@@ -7718,8 +8556,8 @@ void *rrc_enb_process_itti_msg(void *notUsed) {
       LOG_D(RRC, "[eNB %d] Received Paging message from S1AP: %s\n", instance, msg_name_p);
       rrc_eNB_process_PAGING_IND(msg_p, msg_name_p, instance);
       break;
-  
-    case S1AP_E_RAB_SETUP_REQ: 
+
+    case S1AP_E_RAB_SETUP_REQ:
       rrc_eNB_process_S1AP_E_RAB_SETUP_REQ(msg_p, msg_name_p, instance);
       LOG_D(RRC, "[eNB %d] Received the message %s\n", instance, msg_name_p);
       break;
@@ -7731,7 +8569,7 @@ void *rrc_enb_process_itti_msg(void *notUsed) {
     case S1AP_E_RAB_RELEASE_COMMAND:
       rrc_eNB_process_S1AP_E_RAB_RELEASE_COMMAND(msg_p, msg_name_p, instance);
       break;
-    
+
     case S1AP_UE_CONTEXT_RELEASE_REQ:
       rrc_eNB_process_S1AP_UE_CONTEXT_RELEASE_REQ(msg_p, msg_name_p, instance);
       break;
@@ -7741,19 +8579,45 @@ void *rrc_enb_process_itti_msg(void *notUsed) {
       break;
 
     case GTPV1U_ENB_DELETE_TUNNEL_RESP:
+
       /* Nothing to do. Apparently everything is done in S1AP processing */
       //LOG_I(RRC, "[eNB %d] Received message %s, not processed because procedure not synched\n",
       //instance, msg_name_p);
-     if (rrc_eNB_get_ue_context(RC.rrc[instance], GTPV1U_ENB_DELETE_TUNNEL_RESP(msg_p).rnti)
-         && rrc_eNB_get_ue_context(RC.rrc[instance], GTPV1U_ENB_DELETE_TUNNEL_RESP(msg_p).rnti)->ue_context.ue_release_timer_rrc > 0) {
+      if (rrc_eNB_get_ue_context(RC.rrc[instance], GTPV1U_ENB_DELETE_TUNNEL_RESP(msg_p).rnti)
+          && rrc_eNB_get_ue_context(RC.rrc[instance], GTPV1U_ENB_DELETE_TUNNEL_RESP(msg_p).rnti)->ue_context.ue_release_timer_rrc > 0) {
         rrc_eNB_get_ue_context(RC.rrc[instance], GTPV1U_ENB_DELETE_TUNNEL_RESP(msg_p).rnti)->ue_context.ue_release_timer_rrc =
-        rrc_eNB_get_ue_context(RC.rrc[instance], GTPV1U_ENB_DELETE_TUNNEL_RESP(msg_p).rnti)->ue_context.ue_release_timer_thres_rrc;
+          rrc_eNB_get_ue_context(RC.rrc[instance], GTPV1U_ENB_DELETE_TUNNEL_RESP(msg_p).rnti)->ue_context.ue_release_timer_thres_rrc;
       }
+
       break;
 
+    case S1AP_PATH_SWITCH_REQ_ACK:
+      LOG_I(RRC, "[eNB %d] received path switch ack %s\n", instance, msg_name_p);
+      rrc_eNB_process_S1AP_PATH_SWITCH_REQ_ACK(msg_p, msg_name_p, instance);
+      break;
 #   endif
 
-      /* Messages from eNB app */
+    case X2AP_HANDOVER_REQ:
+      LOG_I(RRC, "[eNB %d] target eNB Receives X2 HO Req %s at frame %d subframe %d\n", instance, msg_name_p,
+            ctxt.frame, ctxt.subframe);
+      rrc_eNB_process_handoverPreparationInformation(instance, &X2AP_HANDOVER_REQ(msg_p));
+      break;
+
+    case X2AP_HANDOVER_REQ_ACK: {
+      struct rrc_eNB_ue_context_s        *ue_context_p = NULL;
+      ue_context_p = rrc_eNB_get_ue_context(RC.rrc[instance], ctxt.rnti);
+      LOG_I(RRC, "[eNB %d] source eNB receives the X2 HO ACK %s at frame %d subframe %d \n", instance, msg_name_p,
+            ctxt.frame,ctxt.subframe);
+      DevAssert(ue_context_p != NULL);
+
+      if (ue_context_p->ue_context.handover_info->state != HO_REQUEST) abort();
+
+      rrc_eNB_process_handoverCommand(instance, ue_context_p, &X2AP_HANDOVER_REQ_ACK(msg_p));
+      ue_context_p->ue_context.handover_info->state = HO_PREPARE;
+      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));
       openair_rrc_eNB_configuration(ENB_INSTANCE_TO_MODULE_ID(instance), &RRC_CONFIGURATION_REQ(msg_p));
@@ -7771,33 +8635,31 @@ void *rrc_enb_process_itti_msg(void *notUsed) {
     default:
       LOG_E(RRC, "[eNB %d] Received unexpected message %s\n", instance, msg_name_p);
       break;
-    }
+  }
 
-    result = itti_free(ITTI_MSG_ORIGIN_ID(msg_p), msg_p);
-    if (result != EXIT_SUCCESS) {
-        LOG_I(RRC, "Failed to free memory (%d)!\n",result);
-    }
-    msg_p = NULL;
-    return NULL;
+  result = itti_free(ITTI_MSG_ORIGIN_ID(msg_p), msg_p);
+
+  if (result != EXIT_SUCCESS) {
+    LOG_I(RRC, "Failed to free memory (%d)!\n",result);
+  }
+
+  msg_p = NULL;
+  return NULL;
 }
 
 //-----------------------------------------------------------------------------
-void*
+void *
 rrc_enb_task(
-  void* args_p
+  void *args_p
 )
 //-----------------------------------------------------------------------------
 {
   rrc_enb_init();
-
   itti_mark_task_ready(TASK_RRC_ENB);
   LOG_I(RRC,"Entering main loop of RRC message task\n");
 
-
   while (1) {
-
     (void) rrc_enb_process_itti_msg(NULL);
-
   }
 }
 #endif
@@ -7807,13 +8669,10 @@ void
 openair_rrc_top_init_eNB(int eMBMS_active,uint8_t HO_active)
 //-----------------------------------------------------------------------------
 {
-
   module_id_t         module_id;
   int                 CC_id;
-
   /* for no gcc warnings */
   (void)CC_id;
-
   LOG_D(RRC, "[OPENAIR][INIT] Init function start: NB_eNB_INST=%d\n", RC.nb_inst);
 
   if (RC.nb_inst > 0) {
@@ -7823,7 +8682,7 @@ openair_rrc_top_init_eNB(int eMBMS_active,uint8_t HO_active)
       RC.rrc[module_id]->HO_flag   = (uint8_t)HO_active;
     }
 
-#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
     LOG_I(RRC,"[eNB] eMBMS active state is %d \n", eMBMS_active);
 
     for (module_id=0; module_id<NB_eNB_INST; module_id++) {
@@ -7842,9 +8701,7 @@ openair_rrc_top_init_eNB(int eMBMS_active,uint8_t HO_active)
     }
 
 #endif
-  } 
-
-
+  }
 }
 
 //-----------------------------------------------------------------------------
@@ -7854,8 +8711,8 @@ rrc_top_cleanup_eNB(
 )
 //-----------------------------------------------------------------------------
 {
+  for (int i=0; i<RC.nb_inst; i++) free (RC.rrc[i]);
 
-  for (int i=0;i<RC.nb_inst;i++) free (RC.rrc[i]);
   free(RC.rrc);
 }
 
@@ -7864,121 +8721,139 @@ rrc_top_cleanup_eNB(
 //TTN - for D2D
 uint8_t
 rrc_eNB_process_SidelinkUEInformation(
-      const protocol_ctxt_t* const ctxt_pP,
-      rrc_eNB_ue_context_t*         ue_context_pP,
-      SidelinkUEInformation_r12_t * sidelinkUEInformation
+  const protocol_ctxt_t *const ctxt_pP,
+  rrc_eNB_ue_context_t         *ue_context_pP,
+  LTE_SidelinkUEInformation_r12_t *sidelinkUEInformation
 )
 //-----------------------------------------------------------------------------
 {
-   SL_DestinationInfoList_r12_t  *destinationInfoList;
-   int n_destinations = 0;
-   int n_discoveryMessages = 0;
-
-   LOG_I(RRC,
-         PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel UL-DCCH, " "processing SidelinkUEInformation from UE (SRB1 Active)\n",
-         PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
-
-   //For SL Communication
-   if (sidelinkUEInformation->criticalExtensions.present ==  SidelinkUEInformation_r12__criticalExtensions_PR_c1){
-      if (sidelinkUEInformation->criticalExtensions.choice.c1.present == SidelinkUEInformation_r12__criticalExtensions__c1_PR_sidelinkUEInformation_r12){
-         // express its interest to receive SL communication
-         if (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commRxInterestedFreq_r12 !=  NULL){
-
-         }
-
-         // express its interest to transmit  non-relay one-to-many SL communication
-         if ((sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commTxResourceReq_r12 != NULL) && (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commTxResourceReq_r12->carrierFreq_r12 != NULL)){
-            n_destinations = sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commTxResourceReq_r12->destinationInfoList_r12.list.count;
-            destinationInfoList = CALLOC(1, sizeof(SL_DestinationInfoList_r12_t));
-            for (int i=0; i< n_destinations; i++ ){
-               //sl_DestinationIdentityList[i] = *(sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commTxResourceReq_r12->destinationInfoList_r12.list.array[i]);
-               ASN_SEQUENCE_ADD(&destinationInfoList->list, sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commTxResourceReq_r12->destinationInfoList_r12.list.array[i]);
-            }
-            //generate RRC Reconfiguration
-            rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(ctxt_pP, ue_context_pP, destinationInfoList, 0);
-            return 0;
-
-         }
-
-         // express its interest to transmit  non-relay one-to-one SL communication
-         if ((sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension != NULL) && (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceReqUC_r13 != NULL)) {
-            if (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceReqUC_r13->carrierFreq_r12 != NULL){
-               n_destinations = sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceReqUC_r13->destinationInfoList_r12.list.count;
-               destinationInfoList = CALLOC(1, sizeof(SL_DestinationInfoList_r12_t));
-               for (int i=0; i< n_destinations; i++ ){
-                  //sl_DestinationIdentityList[i] = *(sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceReqUC_r13->destinationInfoList_r12.list.array[i]);
-                  ASN_SEQUENCE_ADD(&destinationInfoList->list,sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceReqUC_r13->destinationInfoList_r12.list.array[i]);
-               }
-               //generate RRC Reconfiguration
-               rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(ctxt_pP, ue_context_pP, destinationInfoList, 0);
-               return 0;
-            }
-         }
-
-         // express its interest to transmit relay related one-to-one SL communication
-         if ((sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension != NULL) &&(sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelayUC_r13 != NULL)) {
-            if (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelayUC_r13->destinationInfoList_r12.list.count > 0) {
-               n_destinations = sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelayUC_r13->destinationInfoList_r12.list.count;
-               destinationInfoList = CALLOC(1, sizeof(SL_DestinationInfoList_r12_t));
-               for (int i=0; i< n_destinations; i++ ){
-                  //sl_DestinationIdentityList[i] = *(sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelayUC_r13->destinationInfoList_r12.list.array[i]);
-                  ASN_SEQUENCE_ADD(&destinationInfoList->list, sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelayUC_r13->destinationInfoList_r12.list.array[i]);
-               }
-               //generate RRC Reconfiguration
-               rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(ctxt_pP, ue_context_pP, destinationInfoList, 0);
-               return 0;
-            }
-         }
-
-         //express its interest to transmit relay related one-to-many SL communication
-         if ((sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension != NULL) && (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13 != NULL)) {
-            if (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelay_r13->destinationInfoList_r12.list.count > 0){
-               n_destinations = sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelay_r13->destinationInfoList_r12.list.count;
-               destinationInfoList = CALLOC(1, sizeof(SL_DestinationInfoList_r12_t));
-               for (int i=0; i< n_destinations; i++ ){
-                  //sl_DestinationIdentityList[i] = *(sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelay_r13->destinationInfoList_r12.list.array[i]);
-                  ASN_SEQUENCE_ADD(&destinationInfoList->list,sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelay_r13->destinationInfoList_r12.list.array[i]);
-               }
-               //generate RRC Reconfiguration
-               rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(ctxt_pP, ue_context_pP, destinationInfoList, 0);
-               return 0;
-            }
-         }
-
-         //For SL Discovery
-         //express its interest to receive SL discovery announcements
-         //express its interest to transmit non-PS related discovery announcements
-         if (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.discTxResourceReq_r12 != NULL){
-            n_discoveryMessages = *(sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.discTxResourceReq_r12);
-            //generate RRC Reconfiguration
-            rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(ctxt_pP, ue_context_pP, NULL, n_discoveryMessages);
-            return 0;
-         }
-         //express its interest to transmit PS related discovery announcements
-         if ((sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension != NULL) && (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->discTxResourceReqPS_r13 !=NULL)) {
-            if (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->discTxResourceReqPS_r13->discTxResourceReq_r13 > 0){
-               n_discoveryMessages = sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->discTxResourceReqPS_r13->discTxResourceReq_r13;
-               //generate RRC Reconfiguration
-               rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(ctxt_pP, ue_context_pP, NULL, n_discoveryMessages);
-               return 0;
-            }
-         }
+  LTE_SL_DestinationInfoList_r12_t  *destinationInfoList;
+  int n_destinations = 0;
+  int n_discoveryMessages = 0;
+  LOG_I(RRC,
+        PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel UL-DCCH, " "processing SidelinkUEInformation from UE (SRB1 Active)\n",
+        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
+
+  //For SL Communication
+  if (sidelinkUEInformation->criticalExtensions.present == LTE_SidelinkUEInformation_r12__criticalExtensions_PR_c1) {
+    if (sidelinkUEInformation->criticalExtensions.choice.c1.present == LTE_SidelinkUEInformation_r12__criticalExtensions__c1_PR_sidelinkUEInformation_r12) {
+      // express its interest to receive SL communication
+      if (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commRxInterestedFreq_r12 !=  NULL) {
+      }
+
+      // express its interest to transmit  non-relay one-to-many SL communication
+      if ((sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commTxResourceReq_r12 != NULL) &&
+          (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commTxResourceReq_r12->carrierFreq_r12 != NULL)) {
+        n_destinations = sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commTxResourceReq_r12->destinationInfoList_r12.list.count;
+        destinationInfoList = CALLOC(1, sizeof(LTE_SL_DestinationInfoList_r12_t));
+
+        for (int i=0; i< n_destinations; i++ ) {
+          //sl_DestinationIdentityList[i] = *(sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commTxResourceReq_r12->destinationInfoList_r12.list.array[i]);
+          ASN_SEQUENCE_ADD(&destinationInfoList->list, sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commTxResourceReq_r12->destinationInfoList_r12.list.array[i]);
+        }
+
+        //generate RRC Reconfiguration
+        rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(ctxt_pP, ue_context_pP, destinationInfoList, 0);
+        return 0;
+      }
+
+      // express its interest to transmit  non-relay one-to-one SL communication
+      if ((sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension != NULL) &&
+          (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceReqUC_r13 != NULL)) {
+        if (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceReqUC_r13->carrierFreq_r12 != NULL) {
+          n_destinations = sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceReqUC_r13->destinationInfoList_r12.list.count;
+          destinationInfoList = CALLOC(1, sizeof(LTE_SL_DestinationInfoList_r12_t));
+
+          for (int i=0; i< n_destinations; i++ ) {
+            //sl_DestinationIdentityList[i] = *(sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceReqUC_r13->destinationInfoList_r12.list.array[i]);
+            ASN_SEQUENCE_ADD(&destinationInfoList->list,
+                             sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceReqUC_r13->destinationInfoList_r12.list.array[i]);
+          }
+
+          //generate RRC Reconfiguration
+          rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(ctxt_pP, ue_context_pP, destinationInfoList, 0);
+          return 0;
+        }
+      }
+
+      // express its interest to transmit relay related one-to-one SL communication
+      if ((sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension != NULL) &&
+          (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelayUC_r13 != NULL)) {
+        if (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelayUC_r13->destinationInfoList_r12.list.count
+            > 0) {
+          n_destinations =
+            sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelayUC_r13->destinationInfoList_r12.list.count;
+          destinationInfoList = CALLOC(1, sizeof(LTE_SL_DestinationInfoList_r12_t));
+
+          for (int i=0; i< n_destinations; i++ ) {
+            //sl_DestinationIdentityList[i] = *(sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelayUC_r13->destinationInfoList_r12.list.array[i]);
+            ASN_SEQUENCE_ADD(&destinationInfoList->list,
+                             sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelayUC_r13->destinationInfoList_r12.list.array[i]);
+          }
+
+          //generate RRC Reconfiguration
+          rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(ctxt_pP, ue_context_pP, destinationInfoList, 0);
+          return 0;
+        }
+      }
+
+      //express its interest to transmit relay related one-to-many SL communication
+      if ((sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension != NULL) &&
+          (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13 != NULL)) {
+        if (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelay_r13->destinationInfoList_r12.list.count
+            > 0) {
+          n_destinations =
+            sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelay_r13->destinationInfoList_r12.list.count;
+          destinationInfoList = CALLOC(1, sizeof(LTE_SL_DestinationInfoList_r12_t));
+
+          for (int i=0; i< n_destinations; i++ ) {
+            //sl_DestinationIdentityList[i] = *(sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelay_r13->destinationInfoList_r12.list.array[i]);
+            ASN_SEQUENCE_ADD(&destinationInfoList->list,
+                             sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelay_r13->destinationInfoList_r12.list.array[i]);
+          }
+
+          //generate RRC Reconfiguration
+          rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(ctxt_pP, ue_context_pP, destinationInfoList, 0);
+          return 0;
+        }
+      }
+
+      //For SL Discovery
+      //express its interest to receive SL discovery announcements
+      //express its interest to transmit non-PS related discovery announcements
+      if (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.discTxResourceReq_r12 != NULL) {
+        n_discoveryMessages = *(sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.discTxResourceReq_r12);
+        //generate RRC Reconfiguration
+        rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(ctxt_pP, ue_context_pP, NULL, n_discoveryMessages);
+        return 0;
+      }
+
+      //express its interest to transmit PS related discovery announcements
+      if ((sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension != NULL) &&
+          (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->discTxResourceReqPS_r13 !=NULL)) {
+        if (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->discTxResourceReqPS_r13->discTxResourceReq_r13 > 0) {
+          n_discoveryMessages = sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->discTxResourceReqPS_r13->discTxResourceReq_r13;
+          //generate RRC Reconfiguration
+          rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(ctxt_pP, ue_context_pP, NULL, n_discoveryMessages);
+          return 0;
+        }
       }
-   }
-   return 0;
+    }
+  }
+
+  return 0;
 }
 
 //-----------------------------------------------------------------------------
 int
 rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(
-  const protocol_ctxt_t* const ctxt_pP,
-  rrc_eNB_ue_context_t* const ue_context_pP,
-  SL_DestinationInfoList_r12_t  *destinationInfoList,
+  const protocol_ctxt_t *const ctxt_pP,
+  rrc_eNB_ue_context_t *const ue_context_pP,
+  LTE_SL_DestinationInfoList_r12_t  *destinationInfoList,
   int n_discoveryMessages
 )
 //-----------------------------------------------------------------------------
 {
-
   uint8_t                             buffer[RRC_BUF_SIZE];
   uint16_t                            size = -1;
   memset(buffer, 0, RRC_BUF_SIZE);
@@ -7986,58 +8861,56 @@ rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(
   // allocate dedicated pools for UE -sl-CommConfig/sl-DiscConfig (sl-V2X-ConfigDedicated)
   //populate dedicated resources for SL communication (sl-CommConfig)
   if ((destinationInfoList != NULL) && (destinationInfoList->list.count > 0)) {
-
-     LOG_I(RRC,"[eNB %d] Frame %d, Generate RRCConnectionReconfiguration_Sidelink (bytes %d, UE id %x), number of destinations %d\n",
-            ctxt_pP->module_id,ctxt_pP->frame, size, ue_context_pP->ue_context.rnti,destinationInfoList->list.count );
-     //get dedicated resources from available pool and assign to the UE
-     SL_CommConfig_r12_t  sl_CommConfig[destinationInfoList->list.count];
-     //get a RP from the available RPs
-     sl_CommConfig[0] = rrc_eNB_get_sidelink_commTXPool(ctxt_pP, ue_context_pP, destinationInfoList);
-
-     size = do_RRCConnectionReconfiguration(ctxt_pP,
-                   buffer,
-                   rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),   //Transaction_id
-                   (SRB_ToAddModList_t*)NULL,
-                   (DRB_ToAddModList_t*)NULL,
-                   (DRB_ToReleaseList_t*)NULL,  // DRB2_list,
-                   (struct SPS_Config*)NULL,    // *sps_Config,
-                   NULL, NULL, NULL, NULL,NULL,
-                   NULL, NULL,  NULL, NULL, NULL, NULL,
-                   (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList*)NULL,
-                   (SL_CommConfig_r12_t*)&sl_CommConfig,
-                   (SL_DiscConfig_r12_t*)NULL
-  #if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-                                           , (SCellToAddMod_r10_t*)NULL
-  #endif
-                                           );
-     //
+    LOG_I(RRC,"[eNB %d] Frame %d, Generate LTE_RRCConnectionReconfiguration_Sidelink (bytes %d, UE id %x), number of destinations %d\n",
+          ctxt_pP->module_id,ctxt_pP->frame, size, ue_context_pP->ue_context.rnti,destinationInfoList->list.count );
+    //get dedicated resources from available pool and assign to the UE
+    LTE_SL_CommConfig_r12_t  sl_CommConfig[destinationInfoList->list.count];
+    //get a RP from the available RPs
+    sl_CommConfig[0] = rrc_eNB_get_sidelink_commTXPool(ctxt_pP, ue_context_pP, destinationInfoList);
+    size = do_RRCConnectionReconfiguration(ctxt_pP,
+                                           buffer,
+                                           rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),   //Transaction_id
+                                           (LTE_SRB_ToAddModList_t *)NULL,
+                                           (LTE_DRB_ToAddModList_t *)NULL,
+                                           (LTE_DRB_ToReleaseList_t *)NULL, // DRB2_list,
+                                           (struct LTE_SPS_Config *)NULL,   // *sps_Config,
+                                           NULL, NULL, NULL, NULL,NULL,
+                                           NULL, NULL,  NULL, NULL, NULL, NULL, NULL,
+                                           (struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *)NULL,
+                                           (LTE_SL_CommConfig_r12_t *)&sl_CommConfig,
+                                           (LTE_SL_DiscConfig_r12_t *)NULL
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                                           , (LTE_SCellToAddMod_r10_t *)NULL
+#endif
+                                          );
+    //
   }
+
   //populate dedicated resources for SL discovery (sl-DiscConfig)
   if (n_discoveryMessages > 0) {
-     SL_DiscConfig_r12_t sl_DiscConfig[n_discoveryMessages];
-     //get a RP from the available RPs
-     sl_DiscConfig[0] = rrc_eNB_get_sidelink_discTXPool(ctxt_pP, ue_context_pP, n_discoveryMessages );
-     size = do_RRCConnectionReconfiguration(ctxt_pP,
-                   buffer,
-                   rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),   //Transaction_id
-                   (SRB_ToAddModList_t*)NULL,
-                   (DRB_ToAddModList_t*)NULL,
-                   (DRB_ToReleaseList_t*)NULL,  // DRB2_list,
-                   (struct SPS_Config*)NULL,    // *sps_Config,
-                   NULL, NULL, NULL, NULL,NULL,
-                   NULL, NULL,  NULL, NULL, NULL, NULL,
-                   (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList*)NULL,
-                   (SL_CommConfig_r12_t*)NULL,
-                   (SL_DiscConfig_r12_t*)&sl_DiscConfig
-  #if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-                                           , (SCellToAddMod_r10_t*)NULL
-  #endif
-                                           );
+    LTE_SL_DiscConfig_r12_t sl_DiscConfig[n_discoveryMessages];
+    //get a RP from the available RPs
+    sl_DiscConfig[0] = rrc_eNB_get_sidelink_discTXPool(ctxt_pP, ue_context_pP, n_discoveryMessages );
+    size = do_RRCConnectionReconfiguration(ctxt_pP,
+                                           buffer,
+                                           rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),   //Transaction_id
+                                           (LTE_SRB_ToAddModList_t *)NULL,
+                                           (LTE_DRB_ToAddModList_t *)NULL,
+                                           (LTE_DRB_ToReleaseList_t *)NULL, // DRB2_list,
+                                           (struct LTE_SPS_Config *)NULL,   // *sps_Config,
+                                           NULL, NULL, NULL, NULL,NULL,
+                                           NULL, NULL,  NULL, NULL, NULL, NULL, NULL,
+                                           (struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *)NULL,
+                                           (LTE_SL_CommConfig_r12_t *)NULL,
+                                           (LTE_SL_DiscConfig_r12_t *)&sl_DiscConfig
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
+                                           , (LTE_SCellToAddMod_r10_t *)NULL
+#endif
+                                          );
   }
 
-  LOG_I(RRC,"[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration_Sidelink (bytes %d, UE id %x)\n",
+  LOG_I(RRC,"[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate LTE_RRCConnectionReconfiguration_Sidelink (bytes %d, UE id %x)\n",
         ctxt_pP->module_id,ctxt_pP->frame, size, ue_context_pP->ue_context.rnti);
-
   rrc_data_req(
     ctxt_pP,
     DCCH,
@@ -8046,295 +8919,316 @@ rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(
     size,
     buffer,
     PDCP_TRANSMISSION_MODE_CONTROL);
-
   // rrc_data_req();
-
   return size;
 }
 
-SL_CommConfig_r12_t rrc_eNB_get_sidelink_commTXPool( const protocol_ctxt_t* const ctxt_pP, rrc_eNB_ue_context_t* const ue_context_pP,  SL_DestinationInfoList_r12_t  *destinationInfoList ){
-   // for the moment, use scheduled resource allocation
-   SL_CommConfig_r12_t  *sl_CommConfig;
-   SL_CommResourcePool_r12_t    *sc_CommTxConfig;
-
-   sl_CommConfig = CALLOC(1, sizeof(struct SL_CommConfig_r12));
-   sl_CommConfig->commTxResources_r12 = CALLOC(1, sizeof(*sl_CommConfig->commTxResources_r12));
-   sl_CommConfig->commTxResources_r12->present = SL_CommConfig_r12__commTxResources_r12_PR_setup;
-
-   sl_CommConfig->commTxResources_r12->choice.setup.present = SL_CommConfig_r12__commTxResources_r12__setup_PR_scheduled_r12;
-   sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.sl_RNTI_r12.size = 2;
-   sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.sl_RNTI_r12.buf = CALLOC(1,2);
-   sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.sl_RNTI_r12.buf[0] = 0x00;
-   sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.sl_RNTI_r12.buf[1] = 0x01;//ctxt_pP->rnti;//rnti
-   sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.sl_RNTI_r12.bits_unused = 0;
-   sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.mcs_r12 = CALLOC(1,sizeof(*sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.mcs_r12));
-   //*sl_CommConfig_test->commTxResources_r12->choice.setup.choice.scheduled_r12.mcs_r12 = 12; //Msc
-   sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.mac_MainConfig_r12.retx_BSR_TimerSL = RetxBSR_Timer_r12_sf320; //MacConfig, for testing only
-   //sl_CommConfig_test->commTxResources_r12->choice.setup.choice.scheduled_r12.sc_CommTxConfig_r12;
-
-   sc_CommTxConfig = & sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.sc_CommTxConfig_r12;
-
-   sc_CommTxConfig->sc_CP_Len_r12 = SL_CP_Len_r12_normal;
-   sc_CommTxConfig->sc_Period_r12 = SL_PeriodComm_r12_sf40;
-   sc_CommTxConfig->data_CP_Len_r12  = SL_CP_Len_r12_normal;
-   //sc_TF_ResourceConfig_r12
-   sc_CommTxConfig->sc_TF_ResourceConfig_r12.prb_Num_r12 = 20;
-   sc_CommTxConfig->sc_TF_ResourceConfig_r12.prb_Start_r12 = 5;
-   sc_CommTxConfig->sc_TF_ResourceConfig_r12.prb_End_r12 = 44;
-   sc_CommTxConfig->sc_TF_ResourceConfig_r12.offsetIndicator_r12.present = SL_OffsetIndicator_r12_PR_small_r12;
-   sc_CommTxConfig->sc_TF_ResourceConfig_r12.offsetIndicator_r12.choice.small_r12 = 0;
-
-   sc_CommTxConfig->sc_TF_ResourceConfig_r12.subframeBitmap_r12.present = SubframeBitmapSL_r12_PR_bs40_r12;
-   sc_CommTxConfig->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.size = 5;
-   sc_CommTxConfig->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.buf  = CALLOC(1,5);
-   sc_CommTxConfig->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.bits_unused = 0;
-   //dataHoppingConfig_r12
-   sc_CommTxConfig->dataHoppingConfig_r12.hoppingParameter_r12 = 0;
-   sc_CommTxConfig->dataHoppingConfig_r12.numSubbands_r12  =  SL_HoppingConfigComm_r12__numSubbands_r12_ns1;
-   sc_CommTxConfig->dataHoppingConfig_r12.rb_Offset_r12 = 0;
-   //ue_SelectedResourceConfig_r12
-   sc_CommTxConfig->ue_SelectedResourceConfig_r12 = CALLOC (1, sizeof (*sc_CommTxConfig->ue_SelectedResourceConfig_r12));
-   sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.prb_Num_r12 = 20;
-   sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.prb_Start_r12 = 5;
-   sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.prb_End_r12 = 44;
-   sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.offsetIndicator_r12.present = SL_OffsetIndicator_r12_PR_small_r12;
-   sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.offsetIndicator_r12.choice.small_r12 = 0 ;
-   sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.present = SubframeBitmapSL_r12_PR_bs40_r12;
-   sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.size = 5;
-   sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf  = CALLOC(1,5);
-   sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.bits_unused = 0;
-   sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf[0] = 0xF0;
-   sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf[1] = 0xFF;
-   sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf[2] = 0xFF;
-   sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf[3] = 0xFF;
-   sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf[4] = 0xFF;
-   //rxParametersNCell_r12
-   sc_CommTxConfig->rxParametersNCell_r12 = CALLOC (1, sizeof (*sc_CommTxConfig->rxParametersNCell_r12));
-   sc_CommTxConfig->rxParametersNCell_r12->tdd_Config_r12 = CALLOC (1, sizeof (*sc_CommTxConfig->rxParametersNCell_r12->tdd_Config_r12 ));
-   sc_CommTxConfig->rxParametersNCell_r12->tdd_Config_r12->subframeAssignment = 0 ;
-   sc_CommTxConfig->rxParametersNCell_r12->tdd_Config_r12->specialSubframePatterns = 0;
-   sc_CommTxConfig->rxParametersNCell_r12->syncConfigIndex_r12 = 0;
-   //txParameters_r12
-   sc_CommTxConfig->txParameters_r12 = CALLOC (1, sizeof (*sc_CommTxConfig->txParameters_r12));
-   sc_CommTxConfig->txParameters_r12->sc_TxParameters_r12.alpha_r12 = Alpha_r12_al0;
-   sc_CommTxConfig->txParameters_r12->sc_TxParameters_r12.p0_r12 = 0;
-   sc_CommTxConfig->ext1 = NULL ;
-
-   return *sl_CommConfig;
+LTE_SL_CommConfig_r12_t rrc_eNB_get_sidelink_commTXPool( const protocol_ctxt_t *const ctxt_pP, rrc_eNB_ue_context_t *const ue_context_pP, LTE_SL_DestinationInfoList_r12_t  *destinationInfoList ) {
+  // for the moment, use scheduled resource allocation
+  LTE_SL_CommConfig_r12_t  *sl_CommConfig;
+  LTE_SL_CommResourcePool_r12_t    *sc_CommTxConfig;
+  sl_CommConfig = CALLOC(1, sizeof(struct LTE_SL_CommConfig_r12));
+  sl_CommConfig->commTxResources_r12 = CALLOC(1, sizeof(*sl_CommConfig->commTxResources_r12));
+  sl_CommConfig->commTxResources_r12->present = LTE_SL_CommConfig_r12__commTxResources_r12_PR_setup;
+  sl_CommConfig->commTxResources_r12->choice.setup.present = LTE_SL_CommConfig_r12__commTxResources_r12__setup_PR_scheduled_r12;
+  sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.sl_RNTI_r12.size = 2;
+  sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.sl_RNTI_r12.buf = CALLOC(1,2);
+  sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.sl_RNTI_r12.buf[0] = 0x00;
+  sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.sl_RNTI_r12.buf[1] = 0x01;//ctxt_pP->rnti;//rnti
+  sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.sl_RNTI_r12.bits_unused = 0;
+  sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.mcs_r12 = CALLOC(1,sizeof(*sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.mcs_r12));
+  //*sl_CommConfig_test->commTxResources_r12->choice.setup.choice.scheduled_r12.mcs_r12 = 12; //Msc
+  sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.mac_MainConfig_r12.retx_BSR_TimerSL = LTE_RetxBSR_Timer_r12_sf320; //MacConfig, for testing only
+  //sl_CommConfig_test->commTxResources_r12->choice.setup.choice.scheduled_r12.sc_CommTxConfig_r12;
+  sc_CommTxConfig = & sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.sc_CommTxConfig_r12;
+  sc_CommTxConfig->sc_CP_Len_r12 = LTE_SL_CP_Len_r12_normal;
+  sc_CommTxConfig->sc_Period_r12 = LTE_SL_PeriodComm_r12_sf40;
+  sc_CommTxConfig->data_CP_Len_r12 = LTE_SL_CP_Len_r12_normal;
+  //sc_TF_ResourceConfig_r12
+  sc_CommTxConfig->sc_TF_ResourceConfig_r12.prb_Num_r12 = 20;
+  sc_CommTxConfig->sc_TF_ResourceConfig_r12.prb_Start_r12 = 5;
+  sc_CommTxConfig->sc_TF_ResourceConfig_r12.prb_End_r12 = 44;
+  sc_CommTxConfig->sc_TF_ResourceConfig_r12.offsetIndicator_r12.present = LTE_SL_OffsetIndicator_r12_PR_small_r12;
+  sc_CommTxConfig->sc_TF_ResourceConfig_r12.offsetIndicator_r12.choice.small_r12 = 0;
+  sc_CommTxConfig->sc_TF_ResourceConfig_r12.subframeBitmap_r12.present = LTE_SubframeBitmapSL_r12_PR_bs40_r12;
+  sc_CommTxConfig->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.size = 5;
+  sc_CommTxConfig->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.buf  = CALLOC(1,5);
+  sc_CommTxConfig->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.bits_unused = 0;
+  //dataHoppingConfig_r12
+  sc_CommTxConfig->dataHoppingConfig_r12.hoppingParameter_r12 = 0;
+  sc_CommTxConfig->dataHoppingConfig_r12.numSubbands_r12  = LTE_SL_HoppingConfigComm_r12__numSubbands_r12_ns1;
+  sc_CommTxConfig->dataHoppingConfig_r12.rb_Offset_r12 = 0;
+  //ue_SelectedResourceConfig_r12
+  sc_CommTxConfig->ue_SelectedResourceConfig_r12 = CALLOC (1, sizeof (*sc_CommTxConfig->ue_SelectedResourceConfig_r12));
+  sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.prb_Num_r12 = 20;
+  sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.prb_Start_r12 = 5;
+  sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.prb_End_r12 = 44;
+  sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.offsetIndicator_r12.present = LTE_SL_OffsetIndicator_r12_PR_small_r12;
+  sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.offsetIndicator_r12.choice.small_r12 = 0 ;
+  sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.present = LTE_SubframeBitmapSL_r12_PR_bs40_r12;
+  sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.size = 5;
+  sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf  = CALLOC(1,5);
+  sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.bits_unused = 0;
+  sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf[0] = 0xF0;
+  sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf[1] = 0xFF;
+  sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf[2] = 0xFF;
+  sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf[3] = 0xFF;
+  sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf[4] = 0xFF;
+  //rxParametersNCell_r12
+  sc_CommTxConfig->rxParametersNCell_r12 = CALLOC (1, sizeof (*sc_CommTxConfig->rxParametersNCell_r12));
+  sc_CommTxConfig->rxParametersNCell_r12->tdd_Config_r12 = CALLOC (1, sizeof (*sc_CommTxConfig->rxParametersNCell_r12->tdd_Config_r12 ));
+  sc_CommTxConfig->rxParametersNCell_r12->tdd_Config_r12->subframeAssignment = 0 ;
+  sc_CommTxConfig->rxParametersNCell_r12->tdd_Config_r12->specialSubframePatterns = 0;
+  sc_CommTxConfig->rxParametersNCell_r12->syncConfigIndex_r12 = 0;
+  //txParameters_r12
+  sc_CommTxConfig->txParameters_r12 = CALLOC (1, sizeof (*sc_CommTxConfig->txParameters_r12));
+  sc_CommTxConfig->txParameters_r12->sc_TxParameters_r12.alpha_r12 = LTE_Alpha_r12_al0;
+  sc_CommTxConfig->txParameters_r12->sc_TxParameters_r12.p0_r12 = 0;
+  sc_CommTxConfig->ext1 = NULL ;
+  return *sl_CommConfig;
 }
 
 
-SL_DiscConfig_r12_t rrc_eNB_get_sidelink_discTXPool( const protocol_ctxt_t* const ctxt_pP, rrc_eNB_ue_context_t* const ue_context_pP,  int n_discoveryMessages ){
-   //TODO
-   SL_DiscConfig_r12_t  sl_DiscConfig;
-   sl_DiscConfig.discTxResources_r12 = CALLOC(1,sizeof(*sl_DiscConfig.discTxResources_r12));
-   sl_DiscConfig.discTxResources_r12->present = SL_DiscConfig_r12__discTxResources_r12_PR_setup;
-   sl_DiscConfig.discTxResources_r12->choice.setup.present = SL_DiscConfig_r12__discTxResources_r12__setup_PR_scheduled_r12;
-   //sl_DiscConfig.discTxResources_r12->choice.setup.choice.scheduled_r12.discHoppingConfig_r12;
-   //sl_DiscConfig.discTxResources_r12->choice.setup.choice.scheduled_r12.discTF_IndexList_r12;
-   //sl_DiscConfig.discTxResources_r12->choice.setup.choice.scheduled_r12.discTxConfig_r12;
-   return sl_DiscConfig;
+LTE_SL_DiscConfig_r12_t rrc_eNB_get_sidelink_discTXPool( const protocol_ctxt_t *const ctxt_pP, rrc_eNB_ue_context_t *const ue_context_pP,  int n_discoveryMessages ) {
+  //TODO
+  LTE_SL_DiscConfig_r12_t  sl_DiscConfig;
+  sl_DiscConfig.discTxResources_r12 = CALLOC(1,sizeof(*sl_DiscConfig.discTxResources_r12));
+  sl_DiscConfig.discTxResources_r12->present = LTE_SL_DiscConfig_r12__discTxResources_r12_PR_setup;
+  sl_DiscConfig.discTxResources_r12->choice.setup.present = LTE_SL_DiscConfig_r12__discTxResources_r12__setup_PR_scheduled_r12;
+  //sl_DiscConfig.discTxResources_r12->choice.setup.choice.scheduled_r12.discHoppingConfig_r12;
+  //sl_DiscConfig.discTxResources_r12->choice.setup.choice.scheduled_r12.discTF_IndexList_r12;
+  //sl_DiscConfig.discTxResources_r12->choice.setup.choice.scheduled_r12.discTxConfig_r12;
+  return sl_DiscConfig;
 }
+
 RRC_status_t
 rrc_rx_tx(
-  protocol_ctxt_t* const ctxt_pP,
-  const int          CC_id
+  protocol_ctxt_t *const ctxt_pP,
+  const int        CC_id
 )
 //-----------------------------------------------------------------------------
 {
-  //uint8_t        UE_id;
-  int32_t        current_timestamp_ms, ref_timestamp_ms;
+  int32_t current_timestamp_ms = 0;
+  int32_t ref_timestamp_ms = 0;
   struct timeval ts;
-  struct rrc_eNB_ue_context_s   *ue_context_p = NULL,*ue_to_be_removed = NULL;
-
+  struct rrc_eNB_ue_context_s *ue_context_p = NULL;
+  struct rrc_eNB_ue_context_s *ue_to_be_removed = NULL;
 #ifdef LOCALIZATION
-  double                         estimated_distance;
-  protocol_ctxt_t                ctxt;
-#endif
-  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX,VCD_FUNCTION_IN);
-
-    check_handovers(ctxt_pP);
-    // counetr, and get the value and aggregate
-
-    // check for UL failure
-    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;
-      if ((ctxt_pP->frame == 0) && (ctxt_pP->subframe==0)) {
-	if (ue_context_p->ue_context.Initialue_identity_s_TMSI.presence == TRUE) {
-	  LOG_I(RRC,"UE rnti %x:S-TMSI %x failure timer %d/8\n",
-		ue_context_p->ue_context.rnti,
-		ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi,
-		ue_context_p->ue_context.ul_failure_timer);
-	}
-	else {
-	  LOG_I(RRC,"UE rnti %x failure timer %d/8\n",
-		ue_context_p->ue_context.rnti,
-		ue_context_p->ue_context.ul_failure_timer);
-	}
+  double estimated_distance = 0;
+  protocol_ctxt_t ctxt;
+#endif
+  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
+  // 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;
+
+    if ((ctxt_pP->frame == 0) && (ctxt_pP->subframe == 0)) {
+      if (ue_context_p->ue_context.Initialue_identity_s_TMSI.presence == TRUE) {
+        LOG_I(RRC, "UE rnti %x: S-TMSI %x failure timer %d/8\n",
+              ue_context_p->ue_context.rnti,
+              ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi,
+              ue_context_p->ue_context.ul_failure_timer);
+      } else {
+        LOG_I(RRC, "UE rnti %x failure timer %d/8\n",
+              ue_context_p->ue_context.rnti,
+              ue_context_p->ue_context.ul_failure_timer);
       }
-      if (ue_context_p->ue_context.ul_failure_timer>0) {
-	ue_context_p->ue_context.ul_failure_timer++;
-	if (ue_context_p->ue_context.ul_failure_timer >= 20000) {
-	  // remove UE after 20 seconds after MAC has indicated UL failure
-	  LOG_I(RRC,"Removing UE %x instance\n",ue_context_p->ue_context.rnti);
-	  ue_to_be_removed = ue_context_p;
-	  break;
-	}
+    }
+
+    if (ue_context_p->ue_context.ul_failure_timer > 0) {
+      ue_context_p->ue_context.ul_failure_timer++;
+
+      if (ue_context_p->ue_context.ul_failure_timer >= 20000) {
+        // remove UE after 20 seconds after MAC (or else) has indicated UL failure
+        LOG_I(RRC, "Removing UE %x instance, because of uplink failure timer timeout\n",
+              ue_context_p->ue_context.rnti);
+        ue_to_be_removed = ue_context_p;
+        break; // break RB_FOREACH
       }
-      if (ue_context_p->ue_context.ue_release_timer_s1>0) {
-        ue_context_p->ue_context.ue_release_timer_s1++;
-        if (ue_context_p->ue_context.ue_release_timer_s1 >=
-            ue_context_p->ue_context.ue_release_timer_thres_s1) {
-          LOG_I(RRC,"Removing UE %x instance Because of UE_CONTEXT_RELEASE_COMMAND not received after %d ms from sending request\n",
-                         ue_context_p->ue_context.rnti, ue_context_p->ue_context.ue_release_timer_thres_s1);
-//          ue_context_p->ue_context.ue_release_timer_s1 = 0;
+    }
+
+    if (ue_context_p->ue_context.ue_release_timer_s1 > 0) {
+      ue_context_p->ue_context.ue_release_timer_s1++;
+
+      if (ue_context_p->ue_context.ue_release_timer_s1 >= ue_context_p->ue_context.ue_release_timer_thres_s1) {
+        LOG_I(RRC, "Removing UE %x instance, because of UE_CONTEXT_RELEASE_COMMAND not received after %d ms from sending request\n",
+              ue_context_p->ue_context.rnti,
+              ue_context_p->ue_context.ue_release_timer_thres_s1);
 #if defined(ENABLE_USE_MME)
 #if defined(ENABLE_ITTI)
-          if (RC.rrc[ctxt_pP->module_id]->node_type != ngran_eNB_DU)
-            rrc_eNB_generate_RRCConnectionRelease(ctxt_pP, ue_context_p);
+        if (RC.rrc[ctxt_pP->module_id]->node_type != ngran_eNB_DU)
+          rrc_eNB_generate_RRCConnectionRelease(ctxt_pP, ue_context_p);
 #endif
 #else
-          ue_to_be_removed = ue_context_p;
-#endif
-          ue_context_p->ue_context.ue_release_timer_s1 = 0;
-          break;
-        }
+        ue_to_be_removed = ue_context_p;
+#endif
+        ue_context_p->ue_context.ue_release_timer_s1 = 0;
+        break; // break RB_FOREACH
+      } // end if timer_s1 timeout
+    } // end if timer_s1 > 0 (S1 UE_CONTEXT_RELEASE_REQ ongoing)
+
+    if (ue_context_p->ue_context.ue_release_timer_rrc > 0) {
+      ue_context_p->ue_context.ue_release_timer_rrc++;
+
+      if (ue_context_p->ue_context.ue_release_timer_rrc >= ue_context_p->ue_context.ue_release_timer_thres_rrc) {
+        LOG_I(RRC, "Removing UE %x instance after UE_CONTEXT_RELEASE_Complete (ue_release_timer_rrc timeout)\n",
+              ue_context_p->ue_context.rnti);
+        ue_context_p->ue_context.ue_release_timer_rrc = 0;
+        ue_to_be_removed = ue_context_p;
+        break; // break RB_FOREACH
       }
+    }
 
-      if (ue_context_p->ue_context.ue_release_timer_rrc>0) {
-        ue_context_p->ue_context.ue_release_timer_rrc++;
-        if (ue_context_p->ue_context.ue_release_timer_rrc >=
-          ue_context_p->ue_context.ue_release_timer_thres_rrc) {
-          LOG_I(RRC,"Removing UE %x instance After UE_CONTEXT_RELEASE_Complete\n", ue_context_p->ue_context.rnti);
-          ue_context_p->ue_context.ue_release_timer_rrc = 0;
-          ue_to_be_removed = ue_context_p;
-          ue_context_p->ue_context.ue_release_timer_rrc = 0;
-          break;
+    pthread_mutex_lock(&rrc_release_freelist);
+
+    if (rrc_release_info.num_UEs > 0) {
+      uint16_t release_total = 0;
+
+      for (uint16_t release_num = 0; release_num < NUMBER_OF_UE_MAX; release_num++) {
+        if (rrc_release_info.RRC_release_ctrl[release_num].flag > 0) {
+          release_total++;
         }
-      }
-       pthread_mutex_lock(&rrc_release_freelist);
-      if(rrc_release_info.num_UEs > 0){
-        uint16_t release_total = 0;
-        for(uint16_t release_num = 0;release_num < NUMBER_OF_UE_MAX;release_num++){
-          if(rrc_release_info.RRC_release_ctrl[release_num].flag > 0){
-            release_total++;
-          }
-          if( (rrc_release_info.RRC_release_ctrl[release_num].flag > 2) &&
-            (rrc_release_info.RRC_release_ctrl[release_num].rnti == ue_context_p->ue_context.rnti)){
-           ue_context_p->ue_context.ue_release_timer_rrc = 1;
-           ue_context_p->ue_context.ue_release_timer_thres_rrc = 100;
+
+        if ((rrc_release_info.RRC_release_ctrl[release_num].flag > 2) &&
+            (rrc_release_info.RRC_release_ctrl[release_num].rnti == ue_context_p->ue_context.rnti)) {
+          ue_context_p->ue_context.ue_release_timer_rrc = 1;
+          ue_context_p->ue_context.ue_release_timer_thres_rrc = 100;
 #if defined(ENABLE_USE_MME)
 #if defined(ENABLE_ITTI)
-           if (RC.rrc[ctxt_pP->module_id]->node_type != ngran_eNB_DU) {
-              if(rrc_release_info.RRC_release_ctrl[release_num].flag == 4){
-                rrc_eNB_send_S1AP_UE_CONTEXT_RELEASE_CPLT(ctxt_pP->module_id,
-                    ue_context_p->ue_context.eNB_ue_s1ap_id);
-              }
+          if (RC.rrc[ctxt_pP->module_id]->node_type != ngran_eNB_DU) {
+            if (rrc_release_info.RRC_release_ctrl[release_num].flag == 4) { // if timer_s1 == 0
+              rrc_eNB_send_S1AP_UE_CONTEXT_RELEASE_CPLT(ctxt_pP->module_id,
+                  ue_context_p->ue_context.eNB_ue_s1ap_id);
+            }
+          }
 
-              rrc_eNB_send_GTPV1U_ENB_DELETE_TUNNEL_REQ(ctxt_pP->module_id,
-                    ue_context_p);
-              // erase data of GTP tunnels in UE context
-              for (int e_rab = 0; e_rab < ue_context_p->ue_context.nb_of_e_rabs; e_rab++) {
-                ue_context_p->ue_context.enb_gtp_teid[e_rab] = 0;
-                memset(&ue_context_p->ue_context.enb_gtp_addrs[e_rab],
-                    0, sizeof(ue_context_p->ue_context.enb_gtp_addrs[e_rab]));
-                ue_context_p->ue_context.enb_gtp_ebi[e_rab]  = 0;
-              }
+          rrc_eNB_send_GTPV1U_ENB_DELETE_TUNNEL_REQ(ctxt_pP->module_id,
+                ue_context_p);
+          // erase data of GTP tunnels in UE context
+          for (int e_rab = 0; e_rab < ue_context_p->ue_context.nb_of_e_rabs; e_rab++) {
+            ue_context_p->ue_context.enb_gtp_teid[e_rab] = 0;
+            memset(&ue_context_p->ue_context.enb_gtp_addrs[e_rab],
+                0, sizeof(ue_context_p->ue_context.enb_gtp_addrs[e_rab]));
+            ue_context_p->ue_context.enb_gtp_ebi[e_rab]  = 0;
+          }
 
-              struct rrc_ue_s1ap_ids_s    *rrc_ue_s1ap_ids = NULL;
-              rrc_ue_s1ap_ids = rrc_eNB_S1AP_get_ue_ids(
-                     RC.rrc[ctxt_pP->module_id],
-                     0,
-                     ue_context_p->ue_context.eNB_ue_s1ap_id);
-              if (NULL != rrc_ue_s1ap_ids) {
-                rrc_eNB_S1AP_remove_ue_ids(
-                           RC.rrc[ctxt_pP->module_id],
-                           rrc_ue_s1ap_ids);
-              }
-           }
-#endif
-#endif
-           rrc_release_info.RRC_release_ctrl[release_num].flag = 0;
-           rrc_release_info.num_UEs--;
-           break;
-         }
-         if(release_total >= rrc_release_info.num_UEs)
-           break;
-         }
-       }
-       pthread_mutex_unlock(&rrc_release_freelist);
-
-      if (ue_context_p->ue_context.ue_reestablishment_timer>0) {
-        ue_context_p->ue_context.ue_reestablishment_timer++;
-        if (ue_context_p->ue_context.ue_reestablishment_timer >=
-            ue_context_p->ue_context.ue_reestablishment_timer_thres) {
-          LOG_I(RRC,"UE %d reestablishment_timer max\n",ue_context_p->ue_context.rnti);
-          ue_context_p->ue_context.ul_failure_timer = 20000;
-          ue_to_be_removed = ue_context_p;
-          ue_context_p->ue_context.ue_reestablishment_timer = 0;
-          break;
+          struct rrc_ue_s1ap_ids_s *rrc_ue_s1ap_ids = NULL;
+          rrc_ue_s1ap_ids = rrc_eNB_S1AP_get_ue_ids(RC.rrc[ctxt_pP->module_id], 0,
+                                                    ue_context_p->ue_context.eNB_ue_s1ap_id);
+
+          if (rrc_ue_s1ap_ids != NULL) {
+            rrc_eNB_S1AP_remove_ue_ids(RC.rrc[ctxt_pP->module_id], rrc_ue_s1ap_ids);
+          }
+
+#endif
+#endif
+          rrc_release_info.RRC_release_ctrl[release_num].flag = 0;
+          rrc_release_info.num_UEs--;
+          break; // break for (release_num)
+        } // end if ((rrc_release_info.RRC_release_ctrl[release_num].flag > 2) && ...
+
+        if (release_total >= rrc_release_info.num_UEs) {
+          break; // break for (release_num)
         }
-      }
+      } // end for (release_num)
+    } // end if (rrc_release_info.num_UEs > 0)
 
-      if (ue_context_p->ue_context.ue_release_timer>0) {
-	ue_context_p->ue_context.ue_release_timer++;
-	if (ue_context_p->ue_context.ue_release_timer >= 
-	    ue_context_p->ue_context.ue_release_timer_thres) {
-          LOG_I(RRC,"Removing UE %x instance\n",ue_context_p->ue_context.rnti);
-	  ue_to_be_removed = ue_context_p;
-          ue_context_p->ue_context.ue_release_timer = 0;
-	  break;
-	}
+    pthread_mutex_unlock(&rrc_release_freelist);
+
+    if ((ue_context_p->ue_context.ue_rrc_inactivity_timer > 0) && (RC.rrc[ctxt_pP->module_id]->configuration.rrc_inactivity_timer_thres > 0)) {
+      ue_context_p->ue_context.ue_rrc_inactivity_timer++; // (un)comment this line to (de)activate the RRC inactivity timer
+
+      if (ue_context_p->ue_context.ue_rrc_inactivity_timer >= RC.rrc[ctxt_pP->module_id]->configuration.rrc_inactivity_timer_thres) {
+        LOG_I(RRC, "Removing UE %x instance because of rrc_inactivity_timer timeout\n",
+              ue_context_p->ue_context.rnti);
+        ue_to_be_removed = ue_context_p;
+        break; // break RB_FOREACH
       }
     }
-    if (ue_to_be_removed) {
-      if(ue_to_be_removed->ue_context.ul_failure_timer >= 20000) {
-          ue_to_be_removed->ue_context.ue_release_timer_s1 = 1;
-          ue_to_be_removed->ue_context.ue_release_timer_thres_s1 = 100;
-          ue_to_be_removed->ue_context.ue_release_timer = 0;
-          ue_to_be_removed->ue_context.ue_reestablishment_timer = 0;
+
+    if (ue_context_p->ue_context.ue_reestablishment_timer > 0) {
+      ue_context_p->ue_context.ue_reestablishment_timer++;
+
+      if (ue_context_p->ue_context.ue_reestablishment_timer >= ue_context_p->ue_context.ue_reestablishment_timer_thres) {
+        LOG_I(RRC, "Removing UE %x instance because of reestablishment_timer timeout\n",
+              ue_context_p->ue_context.rnti);
+        ue_context_p->ue_context.ul_failure_timer = 20000; // lead to send S1 UE_CONTEXT_RELEASE_REQ
+        ue_to_be_removed = ue_context_p;
+        ue_context_p->ue_context.ue_reestablishment_timer = 0;
+        break; // break RB_FOREACH
       }
-      rrc_eNB_free_UE(ctxt_pP->module_id,ue_to_be_removed);
-      if(ue_to_be_removed->ue_context.ul_failure_timer >= 20000){
-        ue_to_be_removed->ue_context.ul_failure_timer = 0;
+    }
+
+    if (ue_context_p->ue_context.ue_release_timer > 0) {
+      ue_context_p->ue_context.ue_release_timer++;
+
+      if (ue_context_p->ue_context.ue_release_timer >= ue_context_p->ue_context.ue_release_timer_thres) {
+        LOG_I(RRC, "Removing UE %x instance because of RRC Connection Setup timer timeout\n",
+              ue_context_p->ue_context.rnti);
+        /*
+        * TODO: Naming problem here: ue_release_timer seems to have been used when RRC Connection Release was sent.
+        * It is no more the case.
+        * The timer should be renamed.
+        */
+        ue_to_be_removed = ue_context_p;
+        ue_context_p->ue_context.ue_release_timer = 0;
+        break; // break RB_FOREACH
       }
     }
+  } // end RB_FOREACH
+
+  if (ue_to_be_removed) {
+    if ((ue_to_be_removed->ue_context.ul_failure_timer >= 20000) ||
+        ((ue_to_be_removed->ue_context.ue_rrc_inactivity_timer >= RC.rrc[ctxt_pP->module_id]->configuration.rrc_inactivity_timer_thres) &&
+         (RC.rrc[ctxt_pP->module_id]->configuration.rrc_inactivity_timer_thres > 0))) {
+      ue_to_be_removed->ue_context.ue_release_timer_s1 = 1;
+      ue_to_be_removed->ue_context.ue_release_timer_thres_s1 = 100;
+      ue_to_be_removed->ue_context.ue_release_timer = 0;
+      ue_to_be_removed->ue_context.ue_reestablishment_timer = 0;
+    }
 
-#ifdef RRC_LOCALIZATION
+    rrc_eNB_free_UE(ctxt_pP->module_id, ue_to_be_removed);
 
-    /* for the localization, only primary CC_id might be relevant*/
-    gettimeofday(&ts, NULL);
-    current_timestamp_ms = ts.tv_sec * 1000 + ts.tv_usec / 1000;
-    ref_timestamp_ms = RC.rrc[ctxt_pP->module_id]->reference_timestamp_ms;
-    RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(RC.rrc[ctxt_pP->module_id]->rrc_ue_head)) {
-      ctxt = *ctxt_pP;
-      ctxt.rnti = ue_context_p->ue_context.rnti;
-      estimated_distance = rrc_get_estimated_ue_distance(
-                             &ctxt,
-                             CC_id,
-                             RC.rrc[ctxt_pP->module_id]->loc_type);
-
-      if ((current_timestamp_ms - ref_timestamp_ms > RC.rrc[ctxt_pP->module_id]->aggregation_period_ms) &&
-          estimated_distance != -1) {
-        LOG_D(LOCALIZE, " RRC [UE/id %d -> eNB/id %d] timestamp %d frame %d estimated r = %f\n",
-              ctxt.rnti,
-              ctxt_pP->module_id,
-              current_timestamp_ms,
-              ctxt_pP->frame,
-              estimated_distance);
-        LOG_D(LOCALIZE, " RRC status %d\n", ue_context_p->ue_context.Status);
-        push_front(&RC.rrc[ctxt_pP->module_id]->loc_list,
-                   estimated_distance);
-        RC.rrc[ctxt_pP->module_id]->reference_timestamp_ms = current_timestamp_ms;
-      }
+    if (ue_to_be_removed->ue_context.ul_failure_timer >= 20000) {
+      ue_to_be_removed->ue_context.ul_failure_timer = 0;
     }
 
-#endif
-    (void)ts; /* remove gcc warning "unused variable" */
-    (void)ref_timestamp_ms; /* remove gcc warning "unused variable" */
-    (void)current_timestamp_ms; /* remove gcc warning "unused variable" */
+    if ((ue_to_be_removed->ue_context.ue_rrc_inactivity_timer >= RC.rrc[ctxt_pP->module_id]->configuration.rrc_inactivity_timer_thres) &&
+        (RC.rrc[ctxt_pP->module_id]->configuration.rrc_inactivity_timer_thres > 0)) {
+      ue_to_be_removed->ue_context.ue_rrc_inactivity_timer = 0; //reset timer after S1 command UE context release request is sent
+    }
+  }
 
-  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX,VCD_FUNCTION_OUT);
-  return (RRC_OK);
+#ifdef RRC_LOCALIZATION
+  /* for the localization, only primary CC_id might be relevant*/
+  gettimeofday(&ts, NULL);
+  current_timestamp_ms = ts.tv_sec * 1000 + ts.tv_usec / 1000;
+  ref_timestamp_ms = RC.rrc[ctxt_pP->module_id]->reference_timestamp_ms;
+  RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(RC.rrc[ctxt_pP->module_id]->rrc_ue_head)) {
+    ctxt = *ctxt_pP;
+    ctxt.rnti = ue_context_p->ue_context.rnti;
+    estimated_distance = rrc_get_estimated_ue_distance(&ctxt, CC_id, RC.rrc[ctxt_pP->module_id]->loc_type);
+
+    if ((current_timestamp_ms - ref_timestamp_ms > RC.rrc[ctxt_pP->module_id]->aggregation_period_ms) &&
+        estimated_distance != -1) {
+      LOG_D(LOCALIZE, "RRC [UE/id %d -> eNB/id %d] timestamp %d frame %d estimated r = %f\n",
+            ctxt.rnti,
+            ctxt_pP->module_id,
+            current_timestamp_ms,
+            ctxt_pP->frame,
+            estimated_distance);
+      LOG_D(LOCALIZE, "RRC status %d\n",
+            ue_context_p->ue_context.Status);
+      push_front(&RC.rrc[ctxt_pP->module_id]->loc_list, estimated_distance);
+      RC.rrc[ctxt_pP->module_id]->reference_timestamp_ms = current_timestamp_ms;
+    } // end if
+  } // end RB_FOREACH
+#endif
+  (void)ts; /* remove gcc warning "unused variable" */
+  (void)ref_timestamp_ms; /* remove gcc warning "unused variable" */
+  (void)current_timestamp_ms; /* remove gcc warning "unused variable" */
+  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX, VCD_FUNCTION_OUT);
+  return RRC_OK;
 }
 
diff --git a/openair2/RRC/LTE/rrc_eNB_GTPV1U.c b/openair2/RRC/LTE/rrc_eNB_GTPV1U.c
index 2587ac94362af509749a86c4e2d7ecb58b30f7e6..54c77cc13ed9abdc2a1a88b40b9dfbe203f4845d 100644
--- a/openair2/RRC/LTE/rrc_eNB_GTPV1U.c
+++ b/openair2/RRC/LTE/rrc_eNB_GTPV1U.c
@@ -109,12 +109,9 @@ void rrc_eNB_send_GTPV1U_ENB_DELETE_TUNNEL_REQ(
     return;
   }
 
-  MSC_LOG_TX_MESSAGE(
-      MSC_RRC_ENB,
-      MSC_GTPU_ENB,
-      NULL,
-      0,
-      "0 GTPV1U_ENB_DELETE_TUNNEL_REQ rnti %x ", ue_context_pP->ue_context.rnti);
+  MSC_LOG_TX_MESSAGE(MSC_RRC_ENB, MSC_GTPU_ENB, NULL, 0,
+                     "0 GTPV1U_ENB_DELETE_TUNNEL_REQ rnti %x ",
+                     ue_context_pP->ue_context.eNB_ue_s1ap_id);
 
   MessageDef *msg = itti_alloc_new_message(TASK_RRC_ENB, GTPV1U_ENB_DELETE_TUNNEL_REQ);
   memset(&GTPV1U_ENB_DELETE_TUNNEL_REQ(msg), 0, sizeof(GTPV1U_ENB_DELETE_TUNNEL_REQ(msg)));
diff --git a/openair2/RRC/LTE/rrc_eNB_S1AP.c b/openair2/RRC/LTE/rrc_eNB_S1AP.c
index bd4db2ca14f33566d5287bf01b38d363e55832a5..4ebe85397457cc6c2b3e338dfba2e2c718f2969a 100644
--- a/openair2/RRC/LTE/rrc_eNB_S1AP.c
+++ b/openair2/RRC/LTE/rrc_eNB_S1AP.c
@@ -36,23 +36,28 @@
 # include "rrc_eNB_S1AP.h"
 # include "enb_config.h"
 # include "common/ran_context.h"
+# include "gtpv1u.h"
 
-# if defined(ENABLE_ITTI)
-#   include "asn1_conversions.h"
-#   include "intertask_interface.h"
-#   include "pdcp.h"
-#   include "pdcp_primitives.h"
-#   include "s1ap_eNB.h"
-# else
-#   include "../../S1AP/s1ap_eNB.h"
-# endif
+# include "s1ap_eNB_defs.h"
+# include "s1ap_eNB_management_procedures.h"
+# include "s1ap_eNB_ue_context.h"
+
+#if defined(ENABLE_ITTI)
+  #include "asn1_conversions.h"
+  #include "intertask_interface.h"
+  #include "pdcp.h"
+  #include "pdcp_primitives.h"
+  #include "s1ap_eNB.h"
+#else
+  #include "../../S1AP/s1ap_eNB.h"
+#endif
 
 #if defined(ENABLE_SECURITY)
-#   include "UTIL/OSA/osa_defs.h"
+  #include "UTIL/OSA/osa_defs.h"
 #endif
 #include "msc.h"
 
-#include "UERadioAccessCapabilityInformation.h"
+#include "LTE_UERadioAccessCapabilityInformation.h"
 
 #include "gtpv1u_eNB_task.h"
 #include "RRC/LTE/rrc_eNB_GTPV1U.h"
@@ -63,6 +68,11 @@
 
 extern RAN_CONTEXT_t RC;
 
+extern int
+gtpv1u_delete_s1u_tunnel(
+  const instance_t instanceP,
+  const gtpv1u_enb_delete_tunnel_req_t * const req_pP);
+
 /* Value to indicate an invalid UE initial id */
 static const uint16_t UE_INITIAL_ID_INVALID = 0;
 
@@ -74,33 +84,30 @@ static const uint16_t S1AP_ENCRYPTION_EEA2_MASK = 0x4000;
 static const uint16_t S1AP_INTEGRITY_EIA1_MASK = 0x8000;
 static const uint16_t S1AP_INTEGRITY_EIA2_MASK = 0x4000;
 
-#if (RRC_VERSION >= MAKE_VERSION(9, 2, 0))
-# define INTEGRITY_ALGORITHM_NONE SecurityAlgorithmConfig__integrityProtAlgorithm_eia0_v920
-#else
-#ifdef EXMIMO_IOT
-# define INTEGRITY_ALGORITHM_NONE SecurityAlgorithmConfig__integrityProtAlgorithm_eia2
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 2, 0))
+  #define INTEGRITY_ALGORITHM_NONE LTE_SecurityAlgorithmConfig__integrityProtAlgorithm_eia0_v920
 #else
-# define INTEGRITY_ALGORITHM_NONE SecurityAlgorithmConfig__integrityProtAlgorithm_reserved
-#endif
+  #ifdef EXMIMO_IOT
+    #define INTEGRITY_ALGORITHM_NONE LTE_SecurityAlgorithmConfig__integrityProtAlgorithm_eia2
+  #else
+    #define INTEGRITY_ALGORITHM_NONE LTE_SecurityAlgorithmConfig__integrityProtAlgorithm_reserved
+  #endif
 #endif
 
-void extract_imsi(uint8_t *pdu_buf, uint32_t pdu_len, rrc_eNB_ue_context_t *ue_context_pP)
-{
+void extract_imsi(uint8_t *pdu_buf, uint32_t pdu_len, rrc_eNB_ue_context_t *ue_context_pP) {
   /* Process NAS message locally to get the IMSI */
   nas_message_t nas_msg;
   memset(&nas_msg, 0, sizeof(nas_message_t));
-
   int size = 0;
-
   nas_message_security_header_t *header = &nas_msg.header;
   /* Decode the first octet of the header (security header type or EPS
   * bearer identity, and protocol discriminator) */
-  DECODE_U8((char *) pdu_buf, *(uint8_t*) (header), size);
+  DECODE_U8((char *) pdu_buf, *(uint8_t *) (header), size);
 
   /* Decode NAS message only if decodable*/
   if (!(header->security_header_type <= SECURITY_HEADER_TYPE_INTEGRITY_PROTECTED
-      && header->protocol_discriminator == EPS_MOBILITY_MANAGEMENT_MESSAGE
-      && pdu_len > NAS_MESSAGE_SECURITY_HEADER_SIZE))
+        && header->protocol_discriminator == EPS_MOBILITY_MANAGEMENT_MESSAGE
+        && pdu_len > NAS_MESSAGE_SECURITY_HEADER_SIZE))
     return;
 
   if (header->security_header_type != SECURITY_HEADER_TYPE_NOT_PROTECTED) {
@@ -114,11 +121,9 @@ void extract_imsi(uint8_t *pdu_buf, uint32_t pdu_len, rrc_eNB_ue_context_t *ue_c
    * can modify it as we want. The callee retains the original address! */
   pdu_buf += size;
   pdu_len -= size;
-
   /* Decode plain NAS message */
   EMM_msg *e_msg = &nas_msg.plain.emm;
   emm_msg_header_t *emm_header = &e_msg->header;
-
   /* First decode the EMM message header */
   int e_head_size = 0;
 
@@ -161,9 +166,13 @@ void extract_imsi(uint8_t *pdu_buf, uint32_t pdu_len, rrc_eNB_ue_context_t *ue_c
 
 # if defined(ENABLE_ITTI)
 //------------------------------------------------------------------------------
-struct rrc_ue_s1ap_ids_s*
+/*
+* Get the UE S1 struct containing hashtables S1_id/UE_id.
+* Is also used to set the S1_id of the UE, depending on inputs.
+*/
+struct rrc_ue_s1ap_ids_s *
 rrc_eNB_S1AP_get_ue_ids(
-  eNB_RRC_INST* const rrc_instance_pP,
+  eNB_RRC_INST *const rrc_instance_pP,
   const uint16_t ue_initial_id,
   const uint32_t eNB_ue_s1ap_id
 )
@@ -171,48 +180,135 @@ rrc_eNB_S1AP_get_ue_ids(
 {
   rrc_ue_s1ap_ids_t *result = NULL;
   rrc_ue_s1ap_ids_t *result2 = NULL;
+  /*****************************/
+  instance_t instance = 0;
+  s1ap_eNB_instance_t *s1ap_eNB_instance_p = NULL;
+  s1ap_eNB_ue_context_t *ue_desc_p = NULL;
+  rrc_eNB_ue_context_t *ue_context_p = NULL;
+  /*****************************/
   hashtable_rc_t     h_rc;
 
-  // we assume that a rrc_ue_s1ap_ids_s is initially inserted in initial_id2_s1ap_ids
-  if (eNB_ue_s1ap_id > 0) {
-	h_rc = hashtable_get(rrc_instance_pP->s1ap_id2_s1ap_ids, (hash_key_t)eNB_ue_s1ap_id, (void**)&result);
-  }
   if (ue_initial_id != UE_INITIAL_ID_INVALID) {
-    h_rc = hashtable_get(rrc_instance_pP->initial_id2_s1ap_ids, (hash_key_t)ue_initial_id, (void**)&result);
-	if  (h_rc == HASH_TABLE_OK) {
-	  if (eNB_ue_s1ap_id > 0) {
-	    h_rc = hashtable_get(rrc_instance_pP->s1ap_id2_s1ap_ids, (hash_key_t)eNB_ue_s1ap_id, (void**)&result2);
-	    if  (h_rc != HASH_TABLE_OK) {
-		  result2 = malloc(sizeof(*result2));
-		  if (NULL != result2) {
-		    *result2 = *result;
-		    result2->eNB_ue_s1ap_id = eNB_ue_s1ap_id;
-		    result->eNB_ue_s1ap_id  = eNB_ue_s1ap_id;
-            h_rc = hashtable_insert(rrc_instance_pP->s1ap_id2_s1ap_ids,
-		    		               (hash_key_t)eNB_ue_s1ap_id,
-		    		               result2);
+    h_rc = hashtable_get(rrc_instance_pP->initial_id2_s1ap_ids, (hash_key_t)ue_initial_id, (void **)&result);
+
+    if (h_rc == HASH_TABLE_OK) {
+      if (eNB_ue_s1ap_id > 0) {
+        h_rc = hashtable_get(rrc_instance_pP->s1ap_id2_s1ap_ids, (hash_key_t)eNB_ue_s1ap_id, (void **)&result2);
+
+        if (h_rc != HASH_TABLE_OK) { // this case is equivalent to associate eNB_ue_s1ap_id and ue_initial_id
+          result2 = malloc(sizeof(*result2));
+
+          if (NULL != result2) {
+            *result2 = *result;
+            result2->eNB_ue_s1ap_id = eNB_ue_s1ap_id;
+            result->eNB_ue_s1ap_id  = eNB_ue_s1ap_id;
+            h_rc = hashtable_insert(rrc_instance_pP->s1ap_id2_s1ap_ids, (hash_key_t)eNB_ue_s1ap_id, result2);
+
             if (h_rc != HASH_TABLE_OK) {
               LOG_E(S1AP, "[eNB %ld] Error while hashtable_insert in s1ap_id2_s1ap_ids eNB_ue_s1ap_id %"PRIu32"\n",
-		    		  rrc_instance_pP - RC.rrc[0], eNB_ue_s1ap_id);
+                    rrc_instance_pP - RC.rrc[0],
+                    eNB_ue_s1ap_id);
             }
-		  }
-		}
-	  }
-	}
-  }
+          }
+        } else { // here we should check that the association was done correctly
+          if ((result->ue_initial_id != result2->ue_initial_id) || (result->eNB_ue_s1ap_id != result2->eNB_ue_s1ap_id)) {
+            LOG_E(S1AP, "[eNB %ld] Error while hashtable_get, two rrc_ue_s1ap_ids_t that should be equal, are not:\n \
+              ue_initial_id 1 = %"PRIu16",\n \
+              ue_initial_id 2 = %"PRIu16",\n \
+              eNB_ue_s1ap_id 1 = %"PRIu32",\n \
+              eNB_ue_s1ap_id 2 = %"PRIu32"\n",
+                  rrc_instance_pP - RC.rrc[0],
+                  result->ue_initial_id,
+                  result2->ue_initial_id,
+                  result->eNB_ue_s1ap_id,
+                  result2->eNB_ue_s1ap_id);
+
+            // Still return *result
+          }
+        }
+      } // end if if (eNB_ue_s1ap_id > 0)
+    } else { // end if (h_rc == HASH_TABLE_OK)
+      LOG_E(S1AP, "[eNB %ld] In hashtable_get, couldn't find in initial_id2_s1ap_ids ue_initial_id %"PRIu16"\n",
+            rrc_instance_pP - RC.rrc[0],
+            ue_initial_id);
+
+      return NULL;
+      /*
+      * At the moment this is written, this case shouldn't (cannot) happen and is equivalent to an error.
+      * One could try to find the struct instance based on s1ap_id2_s1ap_ids and eNB_ue_s1ap_id (if > 0),
+      * but this behavior is not expected at the moment.
+      */
+    } // end else (h_rc != HASH_TABLE_OK)
+  } else { // end if (ue_initial_id != UE_INITIAL_ID_INVALID)
+    if (eNB_ue_s1ap_id > 0) {
+      h_rc = hashtable_get(rrc_instance_pP->s1ap_id2_s1ap_ids, (hash_key_t)eNB_ue_s1ap_id, (void **)&result);
+
+      if (h_rc != HASH_TABLE_OK) {
+        /*
+        * This case is uncommon, but can happen when:
+        * -> if the first NAS message was a Detach Request (non exhaustiv), the UE RRC context exist
+        * but is not associated with eNB_ue_s1ap_id
+        * -> ... (?)
+        */
+        LOG_E(S1AP, "[eNB %ld] In hashtable_get, couldn't find in s1ap_id2_s1ap_ids eNB_ue_s1ap_id %"PRIu32", trying to find it through S1AP context\n",
+              rrc_instance_pP - RC.rrc[0],
+              eNB_ue_s1ap_id);
+        instance = ENB_MODULE_ID_TO_INSTANCE(rrc_instance_pP - RC.rrc[0]); // get eNB instance
+        s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance); // get s1ap_eNB_instance
+
+        if (s1ap_eNB_instance_p != NULL) {
+          ue_desc_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, eNB_ue_s1ap_id); // get s1ap_eNB_ue_context
+        } else {
+          LOG_E(S1AP, "[eNB instance %d] Couldn't find the eNB S1AP context\n",
+              instance);
+
+          return NULL;
+        }
+
+        if (ue_desc_p != NULL) {
+          result = rrc_eNB_S1AP_get_ue_ids(rrc_instance_pP, ue_desc_p->ue_initial_id, eNB_ue_s1ap_id);
+
+          if (result != NULL) {
+            ue_context_p = rrc_eNB_get_ue_context(RC.rrc[ENB_INSTANCE_TO_MODULE_ID(instance)], result->ue_rnti);
+
+            if ((ue_context_p != NULL) && (ue_context_p->ue_context.eNB_ue_s1ap_id == 0)) {
+              ue_context_p->ue_context.eNB_ue_s1ap_id = eNB_ue_s1ap_id;
+            } else {
+              LOG_E(RRC, "[eNB %ld] Incoherence between RRC context and S1AP context (%d != %d) for UE RNTI %d or UE RRC context doesn't exist\n",
+                    rrc_instance_pP - RC.rrc[0],
+                    (ue_context_p==NULL)?99999:ue_context_p->ue_context.eNB_ue_s1ap_id,
+                    eNB_ue_s1ap_id,
+                    result->ue_rnti);
+            }
+          }
+        } else {
+          LOG_E(S1AP, "[eNB %ld] In hashtable_get, couldn't find in s1ap_id2_s1ap_ids eNB_ue_s1ap_id %"PRIu32", even when looking at S1AP context\n",
+                rrc_instance_pP - RC.rrc[0],
+                eNB_ue_s1ap_id);
+
+          return NULL;
+        }
+      } // end if (h_rc != HASH_TABLE_OK)
+    } // end if (eNB_ue_s1ap_id > 0)
+  } // end else (ue_initial_id == UE_INITIAL_ID_INVALID)
+
   return result;
 }
+
 //------------------------------------------------------------------------------
+/*
+* Remove UE ids (ue_initial_id and S1_id) from hashtables.
+*/
 void
 rrc_eNB_S1AP_remove_ue_ids(
-  eNB_RRC_INST*              const rrc_instance_pP,
-  struct rrc_ue_s1ap_ids_s* const ue_ids_pP
+  eNB_RRC_INST *const rrc_instance_pP,
+  struct rrc_ue_s1ap_ids_s *const ue_ids_pP
 )
 //------------------------------------------------------------------------------
 {
-  const uint16_t ue_initial_id  = ue_ids_pP->ue_initial_id;
-  const uint32_t eNB_ue_s1ap_id = ue_ids_pP->eNB_ue_s1ap_id;
+
   hashtable_rc_t h_rc;
+
   if (rrc_instance_pP == NULL) {
     LOG_E(RRC, "Bad RRC instance\n");
     return;
@@ -222,23 +318,26 @@ rrc_eNB_S1AP_remove_ue_ids(
     LOG_E(RRC, "Trying to free a NULL S1AP UE IDs\n");
     return;
   }
-
+  const uint16_t ue_initial_id  = ue_ids_pP->ue_initial_id;
+  const uint32_t eNB_ue_s1ap_id = ue_ids_pP->eNB_ue_s1ap_id;
   if (eNB_ue_s1ap_id > 0) {
-	h_rc = hashtable_remove(rrc_instance_pP->s1ap_id2_s1ap_ids, (hash_key_t)eNB_ue_s1ap_id);
-	if (h_rc != HASH_TABLE_OK) {
-	  LOG_W(RRC, "S1AP Did not find entry in hashtable s1ap_id2_s1ap_ids for eNB_ue_s1ap_id %u\n", eNB_ue_s1ap_id);
-	} else {
-	  LOG_W(RRC, "S1AP removed entry in hashtable s1ap_id2_s1ap_ids for eNB_ue_s1ap_id %u\n", eNB_ue_s1ap_id);
-	}
+    h_rc = hashtable_remove(rrc_instance_pP->s1ap_id2_s1ap_ids, (hash_key_t)eNB_ue_s1ap_id);
+
+    if (h_rc != HASH_TABLE_OK) {
+      LOG_W(RRC, "S1AP Did not find entry in hashtable s1ap_id2_s1ap_ids for eNB_ue_s1ap_id %u\n", eNB_ue_s1ap_id);
+    } else {
+      LOG_W(RRC, "S1AP removed entry in hashtable s1ap_id2_s1ap_ids for eNB_ue_s1ap_id %u\n", eNB_ue_s1ap_id);
+    }
   }
 
   if (ue_initial_id != UE_INITIAL_ID_INVALID) {
     h_rc = hashtable_remove(rrc_instance_pP->initial_id2_s1ap_ids, (hash_key_t)ue_initial_id);
-	if (h_rc != HASH_TABLE_OK) {
-	  LOG_W(RRC, "S1AP Did not find entry in hashtable initial_id2_s1ap_ids for ue_initial_id %u\n", ue_initial_id);
-	} else {
-	  LOG_W(RRC, "S1AP removed entry in hashtable initial_id2_s1ap_ids for ue_initial_id %u\n", ue_initial_id);
-	}
+
+    if (h_rc != HASH_TABLE_OK) {
+      LOG_W(RRC, "S1AP Did not find entry in hashtable initial_id2_s1ap_ids for ue_initial_id %u\n", ue_initial_id);
+    } else {
+      LOG_W(RRC, "S1AP removed entry in hashtable initial_id2_s1ap_ids for ue_initial_id %u\n", ue_initial_id);
+    }
   }
 }
 
@@ -276,25 +375,17 @@ get_next_ue_initial_id(
  *\param eNB_ue_s1ap_id The value sent by S1AP.
  *\return the UE index or UE_INDEX_INVALID if not found.
  */
-static struct rrc_eNB_ue_context_s*
+static struct rrc_eNB_ue_context_s *
 rrc_eNB_get_ue_context_from_s1ap_ids(
   const instance_t  instanceP,
   const uint16_t    ue_initial_idP,
   const uint32_t    eNB_ue_s1ap_idP
-)
-{
-  rrc_ue_s1ap_ids_t* temp = NULL;
-  temp =
-    rrc_eNB_S1AP_get_ue_ids(
-      RC.rrc[ENB_INSTANCE_TO_MODULE_ID(instanceP)],
-      ue_initial_idP,
-      eNB_ue_s1ap_idP);
-
-  if (temp) {
-
-    return rrc_eNB_get_ue_context(
-             RC.rrc[ENB_INSTANCE_TO_MODULE_ID(instanceP)],
-             temp->ue_rnti);
+) {
+  rrc_ue_s1ap_ids_t *temp = NULL;
+  temp = rrc_eNB_S1AP_get_ue_ids(RC.rrc[ENB_INSTANCE_TO_MODULE_ID(instanceP)], ue_initial_idP, eNB_ue_s1ap_idP);
+
+  if (temp != NULL) {
+    return rrc_eNB_get_ue_context(RC.rrc[ENB_INSTANCE_TO_MODULE_ID(instanceP)], temp->ue_rnti);
   }
 
   return NULL;
@@ -305,21 +396,19 @@ rrc_eNB_get_ue_context_from_s1ap_ids(
  *\param algorithms The bit mask of available algorithms received from S1AP.
  *\return the selected algorithm.
  */
-static CipheringAlgorithm_r12_t rrc_eNB_select_ciphering(uint16_t algorithms)
-{
-
-//#warning "Forced   return SecurityAlgorithmConfig__cipheringAlgorithm_eea0, to be deleted in future"
-  return CipheringAlgorithm_r12_eea0;
+static LTE_CipheringAlgorithm_r12_t rrc_eNB_select_ciphering(uint16_t algorithms) {
+  //#warning "Forced   return SecurityAlgorithmConfig__cipheringAlgorithm_eea0, to be deleted in future"
+  return LTE_CipheringAlgorithm_r12_eea0;
 
   if (algorithms & S1AP_ENCRYPTION_EEA2_MASK) {
-    return CipheringAlgorithm_r12_eea2;
+    return LTE_CipheringAlgorithm_r12_eea2;
   }
 
   if (algorithms & S1AP_ENCRYPTION_EEA1_MASK) {
-    return CipheringAlgorithm_r12_eea1;
+    return LTE_CipheringAlgorithm_r12_eea1;
   }
 
-  return CipheringAlgorithm_r12_eea0;
+  return LTE_CipheringAlgorithm_r12_eea0;
 }
 
 /*! \fn e_SecurityAlgorithmConfig__integrityProtAlgorithm rrc_eNB_select_integrity(uint16_t algorithms)
@@ -327,15 +416,13 @@ static CipheringAlgorithm_r12_t rrc_eNB_select_ciphering(uint16_t algorithms)
  *\param algorithms The bit mask of available algorithms received from S1AP.
  *\return the selected algorithm.
  */
-static e_SecurityAlgorithmConfig__integrityProtAlgorithm rrc_eNB_select_integrity(uint16_t algorithms)
-{
-
+static e_LTE_SecurityAlgorithmConfig__integrityProtAlgorithm rrc_eNB_select_integrity(uint16_t algorithms) {
   if (algorithms & S1AP_INTEGRITY_EIA2_MASK) {
-    return SecurityAlgorithmConfig__integrityProtAlgorithm_eia2;
+    return LTE_SecurityAlgorithmConfig__integrityProtAlgorithm_eia2;
   }
 
   if (algorithms & S1AP_INTEGRITY_EIA1_MASK) {
-    return SecurityAlgorithmConfig__integrityProtAlgorithm_eia1;
+    return LTE_SecurityAlgorithmConfig__integrityProtAlgorithm_eia1;
   }
 
   return INTEGRITY_ALGORITHM_NONE;
@@ -350,18 +437,15 @@ static e_SecurityAlgorithmConfig__integrityProtAlgorithm rrc_eNB_select_integrit
  */
 static int
 rrc_eNB_process_security(
-  const protocol_ctxt_t* const ctxt_pP,
-  rrc_eNB_ue_context_t*          const ue_context_pP,
-  security_capabilities_t* security_capabilities_pP
-)
-{
-  boolean_t                                         changed = FALSE;
-  CipheringAlgorithm_r12_t                          cipheringAlgorithm;
-  e_SecurityAlgorithmConfig__integrityProtAlgorithm integrityProtAlgorithm;
-
+  const protocol_ctxt_t *const ctxt_pP,
+  rrc_eNB_ue_context_t          *const ue_context_pP,
+  security_capabilities_t *security_capabilities_pP
+) {
+  boolean_t                                             changed = FALSE;
+  LTE_CipheringAlgorithm_r12_t                          cipheringAlgorithm;
+  e_LTE_SecurityAlgorithmConfig__integrityProtAlgorithm integrityProtAlgorithm;
   /* Save security parameters */
   ue_context_pP->ue_context.security_capabilities = *security_capabilities_pP;
-
   // translation
   LOG_D(RRC,
         "[eNB %d] NAS security_capabilities.encryption_algorithms %u AS ciphering_algorithm %lu NAS security_capabilities.integrity_algorithms %u AS integrity_algorithm %u\n",
@@ -392,7 +476,6 @@ rrc_eNB_process_security(
          (unsigned long)cipheringAlgorithm,
          integrityProtAlgorithm,
          changed ? "changed" : "same");
-
   return changed;
 }
 
@@ -404,16 +487,15 @@ rrc_eNB_process_security(
  */
 //------------------------------------------------------------------------------
 static void process_eNB_security_key (
-  const protocol_ctxt_t* const ctxt_pP,
-  rrc_eNB_ue_context_t*          const ue_context_pP,
-  uint8_t*               security_key_pP
+  const protocol_ctxt_t *const ctxt_pP,
+  rrc_eNB_ue_context_t          *const ue_context_pP,
+  uint8_t               *security_key_pP
 )
 //------------------------------------------------------------------------------
 {
 #if defined(ENABLE_SECURITY)
   char ascii_buffer[65];
   uint8_t i;
-
   /* Saves the security key */
   memcpy (ue_context_pP->ue_context.kenb, security_key_pP, SECURITY_KEY_LENGTH);
   memset (ue_context_pP->ue_context.nh, 0, SECURITY_KEY_LENGTH);
@@ -424,7 +506,6 @@ static void process_eNB_security_key (
   }
 
   ascii_buffer[2 * i] = '\0';
-
   LOG_I (RRC, "[eNB %d][UE %x] Saved security key %s\n", ctxt_pP->module_id, ue_context_pP->ue_context.rnti, ascii_buffer);
 #endif
 }
@@ -433,17 +514,14 @@ static void process_eNB_security_key (
 //------------------------------------------------------------------------------
 void
 rrc_pdcp_config_security(
-  const protocol_ctxt_t* const ctxt_pP,
-  rrc_eNB_ue_context_t*          const ue_context_pP,
+  const protocol_ctxt_t *const ctxt_pP,
+  rrc_eNB_ue_context_t          *const ue_context_pP,
   const uint8_t send_security_mode_command
 )
 //------------------------------------------------------------------------------
 {
-
 #if defined(ENABLE_SECURITY)
-
-
-  SRB_ToAddModList_t*                 SRB_configList = ue_context_pP->ue_context.SRB_configList;
+  LTE_SRB_ToAddModList_t             *SRB_configList = ue_context_pP->ue_context.SRB_configList;
   uint8_t                            *kRRCenc = NULL;
   uint8_t                            *kRRCint = NULL;
   uint8_t                            *kUPenc = NULL;
@@ -465,16 +543,13 @@ rrc_pdcp_config_security(
   derive_key_rrc_int(ue_context_pP->ue_context.integrity_algorithm,
                      ue_context_pP->ue_context.kenb,
                      &kRRCint);
-
 #if !defined(USRP_REC_PLAY)
   SET_LOG_DUMP(DEBUG_SECURITY) ;
 #endif
-  
 
   if ( LOG_DUMPFLAG( DEBUG_SECURITY ) ) {
     if (print_keys ==1 ) {
       print_keys =0;
-
       LOG_DUMPMSG(RRC, DEBUG_SECURITY, ue_context_pP->ue_context.kenb, 32,"\nKeNB:" );
       LOG_DUMPMSG(RRC, DEBUG_SECURITY, kRRCenc, 32,"\nKRRCenc:" );
       LOG_DUMPMSG(RRC, DEBUG_SECURITY, kRRCint, 32,"\nKRRCint:" );
@@ -482,8 +557,7 @@ rrc_pdcp_config_security(
   }
 
   key = PDCP_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, DCCH, SRB_FLAG_YES);
-  h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p);
-
+  h_rc = hashtable_get(pdcp_coll_p, key, (void **)&pdcp_p);
 
   if (h_rc == HASH_TABLE_OK) {
     pdcp_config_set_security(
@@ -511,8 +585,8 @@ rrc_pdcp_config_security(
 //------------------------------------------------------------------------------
 void
 rrc_eNB_send_S1AP_INITIAL_CONTEXT_SETUP_RESP(
-  const protocol_ctxt_t* const ctxt_pP,
-  rrc_eNB_ue_context_t*          const ue_context_pP
+  const protocol_ctxt_t *const ctxt_pP,
+  rrc_eNB_ue_context_t          *const ue_context_pP
 )
 //------------------------------------------------------------------------------
 {
@@ -520,7 +594,6 @@ rrc_eNB_send_S1AP_INITIAL_CONTEXT_SETUP_RESP(
   int e_rab;
   int e_rabs_done = 0;
   int e_rabs_failed = 0;
-
   msg_p = itti_alloc_new_message (TASK_RRC_ENB, S1AP_INITIAL_CONTEXT_SETUP_RESP);
   S1AP_INITIAL_CONTEXT_SETUP_RESP (msg_p).eNB_ue_s1ap_id = ue_context_pP->ue_context.eNB_ue_s1ap_id;
 
@@ -551,11 +624,8 @@ rrc_eNB_send_S1AP_INITIAL_CONTEXT_SETUP_RESP(
     ue_context_pP->ue_id_rnti,
     S1AP_INITIAL_CONTEXT_SETUP_RESP (msg_p).eNB_ue_s1ap_id,
     e_rabs_done, e_rabs_failed);
-
-
   S1AP_INITIAL_CONTEXT_SETUP_RESP (msg_p).nb_of_e_rabs = e_rabs_done;
   S1AP_INITIAL_CONTEXT_SETUP_RESP (msg_p).nb_of_e_rabs_failed = e_rabs_failed;
-
   itti_send_msg_to_task (TASK_S1AP, ctxt_pP->instance, msg_p);
 }
 # endif
@@ -563,55 +633,50 @@ rrc_eNB_send_S1AP_INITIAL_CONTEXT_SETUP_RESP(
 //------------------------------------------------------------------------------
 void
 rrc_eNB_send_S1AP_UPLINK_NAS(
-  const protocol_ctxt_t*    const ctxt_pP,
-  rrc_eNB_ue_context_t*             const ue_context_pP,
-  UL_DCCH_Message_t*        const ul_dcch_msg
+  const protocol_ctxt_t    *const ctxt_pP,
+  rrc_eNB_ue_context_t             *const ue_context_pP,
+  LTE_UL_DCCH_Message_t        *const ul_dcch_msg
 )
 //------------------------------------------------------------------------------
 {
 #if defined(ENABLE_ITTI)
   {
-    ULInformationTransfer_t *ulInformationTransfer = &ul_dcch_msg->message.choice.c1.choice.ulInformationTransfer;
+    LTE_ULInformationTransfer_t *ulInformationTransfer = &ul_dcch_msg->message.choice.c1.choice.ulInformationTransfer;
 
-    if ((ulInformationTransfer->criticalExtensions.present == ULInformationTransfer__criticalExtensions_PR_c1)
-    && (ulInformationTransfer->criticalExtensions.choice.c1.present
-    == ULInformationTransfer__criticalExtensions__c1_PR_ulInformationTransfer_r8)
-    && (ulInformationTransfer->criticalExtensions.choice.c1.choice.ulInformationTransfer_r8.dedicatedInfoType.present
-    == ULInformationTransfer_r8_IEs__dedicatedInfoType_PR_dedicatedInfoNAS)) {
+    if ((ulInformationTransfer->criticalExtensions.present == LTE_ULInformationTransfer__criticalExtensions_PR_c1)
+        && (ulInformationTransfer->criticalExtensions.choice.c1.present
+            == LTE_ULInformationTransfer__criticalExtensions__c1_PR_ulInformationTransfer_r8)
+        && (ulInformationTransfer->criticalExtensions.choice.c1.choice.ulInformationTransfer_r8.dedicatedInfoType.present
+            == LTE_ULInformationTransfer_r8_IEs__dedicatedInfoType_PR_dedicatedInfoNAS)) {
       /* This message hold a dedicated info NAS payload, forward it to NAS */
-      struct ULInformationTransfer_r8_IEs__dedicatedInfoType *dedicatedInfoType =
-          &ulInformationTransfer->criticalExtensions.choice.c1.choice.ulInformationTransfer_r8.dedicatedInfoType;
+      struct LTE_ULInformationTransfer_r8_IEs__dedicatedInfoType *dedicatedInfoType =
+        &ulInformationTransfer->criticalExtensions.choice.c1.choice.ulInformationTransfer_r8.dedicatedInfoType;
       uint32_t pdu_length;
       uint8_t *pdu_buffer;
       MessageDef *msg_p;
-
       pdu_length = dedicatedInfoType->choice.dedicatedInfoNAS.size;
       pdu_buffer = dedicatedInfoType->choice.dedicatedInfoNAS.buf;
-
       msg_p = itti_alloc_new_message (TASK_RRC_ENB, S1AP_UPLINK_NAS);
       S1AP_UPLINK_NAS (msg_p).eNB_ue_s1ap_id = ue_context_pP->ue_context.eNB_ue_s1ap_id;
       S1AP_UPLINK_NAS (msg_p).nas_pdu.length = pdu_length;
       S1AP_UPLINK_NAS (msg_p).nas_pdu.buffer = pdu_buffer;
-
       extract_imsi(S1AP_UPLINK_NAS (msg_p).nas_pdu.buffer,
                    S1AP_UPLINK_NAS (msg_p).nas_pdu.length,
                    ue_context_pP);
-
       itti_send_msg_to_task (TASK_S1AP, ctxt_pP->instance, msg_p);
     }
   }
 #else
   {
-    ULInformationTransfer_t *ulInformationTransfer;
+    LTE_ULInformationTransfer_t *ulInformationTransfer;
     ulInformationTransfer =
     &ul_dcch_msg->message.choice.c1.choice.
     ulInformationTransfer;
 
     if (ulInformationTransfer->criticalExtensions.present ==
-    ULInformationTransfer__criticalExtensions_PR_c1) {
+        LTE_ULInformationTransfer__criticalExtensions_PR_c1) {
       if (ulInformationTransfer->criticalExtensions.choice.c1.present ==
-      ULInformationTransfer__criticalExtensions__c1_PR_ulInformationTransfer_r8) {
-
+          LTE_ULInformationTransfer__criticalExtensions__c1_PR_ulInformationTransfer_r8) {
         ULInformationTransfer_r8_IEs_t
         *ulInformationTransferR8;
         ulInformationTransferR8 =
@@ -619,15 +684,13 @@ rrc_eNB_send_S1AP_UPLINK_NAS(
         c1.choice.ulInformationTransfer_r8;
 
         if (ulInformationTransferR8->dedicatedInfoType.present ==
-            ULInformationTransfer_r8_IEs__dedicatedInfoType_PR_dedicatedInfoNAS) {
-
+            LTE_ULInformationTransfer_r8_IEs__dedicatedInfoType_PR_dedicatedInfoNAS) {
           extract_imsi(ulInformationTransferR8->dedicatedInfoType.choice.dedicatedInfoNAS.buf,
                        ulInformationTransferR8->dedicatedInfoType.choice.dedicatedInfoNAS.size,
                        ue_context_pP);
-
           s1ap_eNB_new_data_request (mod_id, ue_index,
-              ulInformationTransferR8->dedicatedInfoType.choice.dedicatedInfoNAS.buf,
-              ulInformationTransferR8->dedicatedInfoType.choice.dedicatedInfoNAS.size);
+                                     ulInformationTransferR8->dedicatedInfoType.choice.dedicatedInfoNAS.buf,
+                                     ulInformationTransferR8->dedicatedInfoType.choice.dedicatedInfoNAS.size);
         }
       }
     }
@@ -637,123 +700,116 @@ rrc_eNB_send_S1AP_UPLINK_NAS(
 
 //------------------------------------------------------------------------------
 void rrc_eNB_send_S1AP_UE_CAPABILITIES_IND(
-  const protocol_ctxt_t* const ctxt_pP,
-  rrc_eNB_ue_context_t*          const ue_context_pP,
-  UL_DCCH_Message_t* ul_dcch_msg
+  const protocol_ctxt_t *const ctxt_pP,
+  rrc_eNB_ue_context_t          *const ue_context_pP,
+  LTE_UL_DCCH_Message_t *ul_dcch_msg
 )
 //------------------------------------------------------------------------------
 {
-  UECapabilityInformation_t *ueCapabilityInformation = &ul_dcch_msg->message.choice.c1.choice.ueCapabilityInformation;
+  LTE_UECapabilityInformation_t *ueCapabilityInformation = &ul_dcch_msg->message.choice.c1.choice.ueCapabilityInformation;
   /* 4096 is arbitrary, should be big enough */
   unsigned char buf[4096];
   unsigned char *buf2;
-  UERadioAccessCapabilityInformation_t rac;
+  LTE_UERadioAccessCapabilityInformation_t rac;
 
-  if (ueCapabilityInformation->criticalExtensions.present != UECapabilityInformation__criticalExtensions_PR_c1
-      || ueCapabilityInformation->criticalExtensions.choice.c1.present != UECapabilityInformation__criticalExtensions__c1_PR_ueCapabilityInformation_r8) {
+  if (ueCapabilityInformation->criticalExtensions.present != LTE_UECapabilityInformation__criticalExtensions_PR_c1
+      || ueCapabilityInformation->criticalExtensions.choice.c1.present != LTE_UECapabilityInformation__criticalExtensions__c1_PR_ueCapabilityInformation_r8) {
     LOG_E(RRC, "[eNB %d][UE %x] bad UE capabilities\n", ctxt_pP->module_id, ue_context_pP->ue_context.rnti);
     return;
   }
 
-  asn_enc_rval_t ret = uper_encode_to_buffer(&asn_DEF_UECapabilityInformation, NULL, ueCapabilityInformation, buf, 4096);
+  asn_enc_rval_t ret = uper_encode_to_buffer(&asn_DEF_LTE_UECapabilityInformation, NULL, ueCapabilityInformation, buf, 4096);
 
   if (ret.encoded == -1) abort();
 
-  memset(&rac, 0, sizeof(UERadioAccessCapabilityInformation_t));
-
-  rac.criticalExtensions.present = UERadioAccessCapabilityInformation__criticalExtensions_PR_c1;
-  rac.criticalExtensions.choice.c1.present = UERadioAccessCapabilityInformation__criticalExtensions__c1_PR_ueRadioAccessCapabilityInformation_r8;
+  memset(&rac, 0, sizeof(LTE_UERadioAccessCapabilityInformation_t));
+  rac.criticalExtensions.present = LTE_UERadioAccessCapabilityInformation__criticalExtensions_PR_c1;
+  rac.criticalExtensions.choice.c1.present = LTE_UERadioAccessCapabilityInformation__criticalExtensions__c1_PR_ueRadioAccessCapabilityInformation_r8;
   rac.criticalExtensions.choice.c1.choice.ueRadioAccessCapabilityInformation_r8.ue_RadioAccessCapabilityInfo.buf = buf;
   rac.criticalExtensions.choice.c1.choice.ueRadioAccessCapabilityInformation_r8.ue_RadioAccessCapabilityInfo.size = (ret.encoded+7)/8;
   rac.criticalExtensions.choice.c1.choice.ueRadioAccessCapabilityInformation_r8.nonCriticalExtension = NULL;
-
   /* 8192 is arbitrary, should be big enough */
   buf2 = malloc16(8192);
+
   if (buf2 == NULL) abort();
 
-  ret = uper_encode_to_buffer(&asn_DEF_UERadioAccessCapabilityInformation, NULL, &rac, buf2, 8192);
+  ret = uper_encode_to_buffer(&asn_DEF_LTE_UERadioAccessCapabilityInformation, NULL, &rac, buf2, 8192);
 
   if (ret.encoded == -1) abort();
 
   MessageDef *msg_p;
-
   msg_p = itti_alloc_new_message (TASK_RRC_ENB, S1AP_UE_CAPABILITIES_IND);
   S1AP_UE_CAPABILITIES_IND (msg_p).eNB_ue_s1ap_id = ue_context_pP->ue_context.eNB_ue_s1ap_id;
   S1AP_UE_CAPABILITIES_IND (msg_p).ue_radio_cap.length = (ret.encoded+7)/8;
   S1AP_UE_CAPABILITIES_IND (msg_p).ue_radio_cap.buffer = buf2;
-
   itti_send_msg_to_task (TASK_S1AP, ctxt_pP->instance, msg_p);
 }
 
 //------------------------------------------------------------------------------
+/*
+* Initial UE NAS message on S1AP.
+*/
 void
 rrc_eNB_send_S1AP_NAS_FIRST_REQ(
-  const protocol_ctxt_t* const ctxt_pP,
-  rrc_eNB_ue_context_t*          const ue_context_pP,
-  RRCConnectionSetupComplete_r8_IEs_t* rrcConnectionSetupComplete
+  const protocol_ctxt_t *const ctxt_pP,
+  rrc_eNB_ue_context_t *const ue_context_pP,
+  LTE_RRCConnectionSetupComplete_r8_IEs_t *rrcConnectionSetupComplete
 )
 //------------------------------------------------------------------------------
-
-
 {
-  eNB_RRC_INST *rrc=RC.rrc[ctxt_pP->module_id];
+  eNB_RRC_INST *rrc = RC.rrc[ctxt_pP->module_id];
 #if defined(ENABLE_ITTI)
   {
-    MessageDef*         message_p         = NULL;
-    rrc_ue_s1ap_ids_t*  rrc_ue_s1ap_ids_p = NULL;
+    MessageDef         *message_p         = NULL;
+    rrc_ue_s1ap_ids_t  *rrc_ue_s1ap_ids_p = NULL;
     hashtable_rc_t      h_rc;
-
-    message_p = itti_alloc_new_message (TASK_RRC_ENB, S1AP_NAS_FIRST_REQ);
+    message_p = itti_alloc_new_message(TASK_RRC_ENB, S1AP_NAS_FIRST_REQ);
     memset(&message_p->ittiMsg.s1ap_nas_first_req, 0, sizeof(s1ap_nas_first_req_t));
-
-    ue_context_pP->ue_context.ue_initial_id = get_next_ue_initial_id (ctxt_pP->module_id);
-    S1AP_NAS_FIRST_REQ (message_p).ue_initial_id = ue_context_pP->ue_context.ue_initial_id;
-
+    ue_context_pP->ue_context.ue_initial_id = get_next_ue_initial_id(ctxt_pP->module_id);
+    S1AP_NAS_FIRST_REQ(message_p).ue_initial_id = ue_context_pP->ue_context.ue_initial_id;
     rrc_ue_s1ap_ids_p = malloc(sizeof(*rrc_ue_s1ap_ids_p));
     rrc_ue_s1ap_ids_p->ue_initial_id  = ue_context_pP->ue_context.ue_initial_id;
     rrc_ue_s1ap_ids_p->eNB_ue_s1ap_id = UE_INITIAL_ID_INVALID;
     rrc_ue_s1ap_ids_p->ue_rnti        = ctxt_pP->rnti;
-
     h_rc = hashtable_insert(RC.rrc[ctxt_pP->module_id]->initial_id2_s1ap_ids,
-    		               (hash_key_t)ue_context_pP->ue_context.ue_initial_id,
-    		               rrc_ue_s1ap_ids_p);
+                            (hash_key_t)ue_context_pP->ue_context.ue_initial_id,
+                            rrc_ue_s1ap_ids_p);
+
     if (h_rc != HASH_TABLE_OK) {
       LOG_E(S1AP, "[eNB %d] Error while hashtable_insert in initial_id2_s1ap_ids ue_initial_id %u\n",
-    		  ctxt_pP->module_id, ue_context_pP->ue_context.ue_initial_id);
+            ctxt_pP->module_id,
+            ue_context_pP->ue_context.ue_initial_id);
     }
 
     /* Assume that cause is coded in the same way in RRC and S1ap, just check that the value is in S1ap range */
     AssertFatal(ue_context_pP->ue_context.establishment_cause < RRC_CAUSE_LAST,
-    "Establishment cause invalid (%jd/%d) for eNB %d!",
-    ue_context_pP->ue_context.establishment_cause, RRC_CAUSE_LAST, ctxt_pP->module_id);
-
+                "Establishment cause invalid (%jd/%d) for eNB %d!",
+                ue_context_pP->ue_context.establishment_cause,
+                RRC_CAUSE_LAST,
+                ctxt_pP->module_id);
     S1AP_NAS_FIRST_REQ (message_p).establishment_cause = ue_context_pP->ue_context.establishment_cause;
-
-    /* Forward NAS message */S1AP_NAS_FIRST_REQ (message_p).nas_pdu.buffer =
-    rrcConnectionSetupComplete->dedicatedInfoNAS.buf;
+    /* Forward NAS message */
+    S1AP_NAS_FIRST_REQ (message_p).nas_pdu.buffer = rrcConnectionSetupComplete->dedicatedInfoNAS.buf;
     S1AP_NAS_FIRST_REQ (message_p).nas_pdu.length = rrcConnectionSetupComplete->dedicatedInfoNAS.size;
-
     extract_imsi(S1AP_NAS_FIRST_REQ (message_p).nas_pdu.buffer,
                  S1AP_NAS_FIRST_REQ (message_p).nas_pdu.length,
                  ue_context_pP);
-
     /* Fill UE identities with available information */
     {
       S1AP_NAS_FIRST_REQ (message_p).ue_identity.presenceMask = UE_IDENTITIES_NONE;
 
       if (ue_context_pP->ue_context.Initialue_identity_s_TMSI.presence) {
         /* Fill s-TMSI */
-        UE_S_TMSI* s_TMSI = &ue_context_pP->ue_context.Initialue_identity_s_TMSI;
-
+        UE_S_TMSI *s_TMSI = &ue_context_pP->ue_context.Initialue_identity_s_TMSI;
         S1AP_NAS_FIRST_REQ (message_p).ue_identity.presenceMask |= UE_IDENTITIES_s_tmsi;
         S1AP_NAS_FIRST_REQ (message_p).ue_identity.s_tmsi.mme_code = s_TMSI->mme_code;
         S1AP_NAS_FIRST_REQ (message_p).ue_identity.s_tmsi.m_tmsi = s_TMSI->m_tmsi;
         LOG_I(S1AP, "[eNB %d] Build S1AP_NAS_FIRST_REQ with s_TMSI: MME code %u M-TMSI %u ue %x\n",
-            ctxt_pP->module_id,
-            S1AP_NAS_FIRST_REQ (message_p).ue_identity.s_tmsi.mme_code,
-            S1AP_NAS_FIRST_REQ (message_p).ue_identity.s_tmsi.m_tmsi,
-            ue_context_pP->ue_context.rnti);
-      }
+              ctxt_pP->module_id,
+              S1AP_NAS_FIRST_REQ (message_p).ue_identity.s_tmsi.mme_code,
+              S1AP_NAS_FIRST_REQ (message_p).ue_identity.s_tmsi.m_tmsi,
+              ue_context_pP->ue_context.rnti);
+      } // end if S-TMSI presence
 
       /* selected_plmn_identity: IE is 1-based, convert to 0-based (C array) */
       int selected_plmn_identity = rrcConnectionSetupComplete->selectedPLMN_Identity - 1;
@@ -761,8 +817,7 @@ rrc_eNB_send_S1AP_NAS_FIRST_REQ(
 
       if (rrcConnectionSetupComplete->registeredMME != NULL) {
         /* Fill GUMMEI */
-        struct RegisteredMME *r_mme = rrcConnectionSetupComplete->registeredMME;
-
+        struct LTE_RegisteredMME *r_mme = rrcConnectionSetupComplete->registeredMME;
         S1AP_NAS_FIRST_REQ (message_p).ue_identity.presenceMask |= UE_IDENTITIES_gummei;
 
         if (r_mme->plmn_Identity != NULL) {
@@ -770,9 +825,9 @@ rrc_eNB_send_S1AP_NAS_FIRST_REQ(
             /* Use first indicated PLMN MCC if it is defined */
             S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mcc = *r_mme->plmn_Identity->mcc->list.array[selected_plmn_identity];
             LOG_I(S1AP, "[eNB %d] Build S1AP_NAS_FIRST_REQ adding in s_TMSI: GUMMEI MCC %u ue %x\n",
-                ctxt_pP->module_id,
-                S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mcc,
-                ue_context_pP->ue_context.rnti);
+                  ctxt_pP->module_id,
+                  S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mcc,
+                  ue_context_pP->ue_context.rnti);
           }
 
           if (r_mme->plmn_Identity->mnc.list.count > 0) {
@@ -783,32 +838,36 @@ rrc_eNB_send_S1AP_NAS_FIRST_REQ(
                   S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mnc,
                   ue_context_pP->ue_context.rnti);
           }
-        } else {
+        } else { // end if plmn_Identity != NULL
           S1AP_NAS_FIRST_REQ(message_p).ue_identity.gummei.mcc = rrc->configuration.mcc[selected_plmn_identity];
           S1AP_NAS_FIRST_REQ(message_p).ue_identity.gummei.mnc = rrc->configuration.mnc[selected_plmn_identity];
           S1AP_NAS_FIRST_REQ(message_p).ue_identity.gummei.mnc_len = rrc->configuration.mnc_digit_length[selected_plmn_identity];
-        }
+        } // end else (plmn_Identity == NULL)
 
         S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mme_code     = BIT_STRING_to_uint8 (&r_mme->mmec);
         S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mme_group_id = BIT_STRING_to_uint16 (&r_mme->mmegi);
 
-        MSC_LOG_TX_MESSAGE(
-          MSC_S1AP_ENB,
-          MSC_S1AP_MME,
-          (const char *)&message_p->ittiMsg.s1ap_nas_first_req,
-          sizeof(s1ap_nas_first_req_t),
-          MSC_AS_TIME_FMT" S1AP_NAS_FIRST_REQ eNB %u UE %x",
-          MSC_AS_TIME_ARGS(ctxt_pP),
-          ctxt_pP->module_id,
-          ctxt_pP->rnti);
-
+        ue_context_pP->ue_context.ue_gummei.mcc = S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mcc;
+        ue_context_pP->ue_context.ue_gummei.mnc = S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mnc;
+        ue_context_pP->ue_context.ue_gummei.mnc_len = S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mnc_len;
+        ue_context_pP->ue_context.ue_gummei.mme_code = S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mme_code;
+        ue_context_pP->ue_context.ue_gummei.mme_group_id = S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mme_group_id;
+
+        MSC_LOG_TX_MESSAGE(MSC_S1AP_ENB,
+                           MSC_S1AP_MME,
+                           (const char *)&message_p->ittiMsg.s1ap_nas_first_req,
+                           sizeof(s1ap_nas_first_req_t),
+                           MSC_AS_TIME_FMT" S1AP_NAS_FIRST_REQ eNB %u UE %x",
+                           MSC_AS_TIME_ARGS(ctxt_pP),
+                           ctxt_pP->module_id,
+                           ctxt_pP->rnti);
         LOG_I(S1AP, "[eNB %d] Build S1AP_NAS_FIRST_REQ adding in s_TMSI: GUMMEI mme_code %u mme_group_id %u ue %x\n",
               ctxt_pP->module_id,
               S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mme_code,
               S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mme_group_id,
               ue_context_pP->ue_context.rnti);
-      }
-    }
+      } // end if MME info present
+    } // end "Fill UE identities with available information" sub-part
     itti_send_msg_to_task (TASK_S1AP, ctxt_pP->instance, message_p);
   }
 #else
@@ -828,10 +887,10 @@ rrc_eNB_send_S1AP_NAS_FIRST_REQ(
 //------------------------------------------------------------------------------
 int
 rrc_eNB_process_S1AP_DOWNLINK_NAS(
-  MessageDef* msg_p,
-  const char* msg_name,
+  MessageDef *msg_p,
+  const char *msg_name,
   instance_t instance,
-  mui_t* rrc_eNB_mui
+  mui_t *rrc_eNB_mui
 )
 //------------------------------------------------------------------------------
 {
@@ -839,15 +898,12 @@ rrc_eNB_process_S1AP_DOWNLINK_NAS(
   uint32_t eNB_ue_s1ap_id;
   uint32_t length;
   uint8_t *buffer;
-  uint8_t srb_id; 
-  
-  struct rrc_eNB_ue_context_s* ue_context_p = NULL;
+  uint8_t srb_id;
+  struct rrc_eNB_ue_context_s *ue_context_p = NULL;
   protocol_ctxt_t              ctxt;
   ue_initial_id = S1AP_DOWNLINK_NAS (msg_p).ue_initial_id;
   eNB_ue_s1ap_id = S1AP_DOWNLINK_NAS (msg_p).eNB_ue_s1ap_id;
   ue_context_p = rrc_eNB_get_ue_context_from_s1ap_ids(instance, ue_initial_id, eNB_ue_s1ap_id);
-
-
   LOG_I(RRC, "[eNB %d] Received %s: ue_initial_id %d, eNB_ue_s1ap_id %d\n",
         instance,
         msg_name,
@@ -855,7 +911,6 @@ rrc_eNB_process_S1AP_DOWNLINK_NAS(
         eNB_ue_s1ap_id);
 
   if (ue_context_p == NULL) {
-
     MSC_LOG_RX_MESSAGE(
       MSC_RRC_ENB,
       MSC_S1AP_ENB,
@@ -865,20 +920,14 @@ rrc_eNB_process_S1AP_DOWNLINK_NAS(
       0,0,//MSC_AS_TIME_ARGS(ctxt_pP),
       ue_initial_id,
       eNB_ue_s1ap_id);
-
     /* Can not associate this message to an UE index, send a failure to S1AP and discard it! */
     MessageDef *msg_fail_p;
-
     LOG_W(RRC, "[eNB %d] In S1AP_DOWNLINK_NAS: unknown UE from S1AP ids (%d, %d)\n", instance, ue_initial_id, eNB_ue_s1ap_id);
-
     msg_fail_p = itti_alloc_new_message (TASK_RRC_ENB, S1AP_NAS_NON_DELIVERY_IND);
     S1AP_NAS_NON_DELIVERY_IND (msg_fail_p).eNB_ue_s1ap_id = eNB_ue_s1ap_id;
     S1AP_NAS_NON_DELIVERY_IND (msg_fail_p).nas_pdu.length = S1AP_DOWNLINK_NAS (msg_p).nas_pdu.length;
     S1AP_NAS_NON_DELIVERY_IND (msg_fail_p).nas_pdu.buffer = S1AP_DOWNLINK_NAS (msg_p).nas_pdu.buffer;
-
     // TODO add failure cause when defined!
-
-
     MSC_LOG_TX_MESSAGE(
       MSC_RRC_ENB,
       MSC_S1AP_ENB,
@@ -888,14 +937,11 @@ rrc_eNB_process_S1AP_DOWNLINK_NAS(
       0,0,//MSC_AS_TIME_ARGS(ctxt_pP),
       ue_initial_id,
       eNB_ue_s1ap_id);
-
     itti_send_msg_to_task (TASK_S1AP, instance, msg_fail_p);
     return (-1);
   } else {
     PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, ENB_FLAG_YES, ue_context_p->ue_context.rnti, 0, 0);
-
     srb_id = ue_context_p->ue_context.Srb2.Srb_info.Srb_id;
-  
 
     /* Is it the first income from S1AP ? */
     if (ue_context_p->ue_context.eNB_ue_s1ap_id == 0) {
@@ -911,8 +957,6 @@ rrc_eNB_process_S1AP_DOWNLINK_NAS(
       0,0,//MSC_AS_TIME_ARGS(ctxt_pP),
       ue_initial_id,
       S1AP_DOWNLINK_NAS (msg_p).eNB_ue_s1ap_id);
-
-
     /* Create message for PDCP (DLInformationTransfer_t) */
     length = do_DLInformationTransfer (
                instance,
@@ -920,36 +964,32 @@ rrc_eNB_process_S1AP_DOWNLINK_NAS(
                rrc_eNB_get_next_transaction_identifier (instance),
                S1AP_DOWNLINK_NAS (msg_p).nas_pdu.length,
                S1AP_DOWNLINK_NAS (msg_p).nas_pdu.buffer);
-
     LOG_DUMPMSG(RRC,DEBUG_RRC,buffer,length,"[MSG] RRC DL Information Transfer\n");
-    /* 
-     * switch UL or DL NAS message without RRC piggybacked to SRB2 if active. 
+    /*
+     * switch UL or DL NAS message without RRC piggybacked to SRB2 if active.
      */
     /* Transfer data to PDCP */
     rrc_data_req (
-		  &ctxt,
-		  srb_id,
-		  *rrc_eNB_mui++,
-		  SDU_CONFIRM_NO,
-		  length,
-		  buffer,
-		  PDCP_TRANSMISSION_MODE_CONTROL);
-    
+      &ctxt,
+      srb_id,
+      *rrc_eNB_mui++,
+      SDU_CONFIRM_NO,
+      length,
+      buffer,
+      PDCP_TRANSMISSION_MODE_CONTROL);
     return (0);
   }
 }
 
 /*------------------------------------------------------------------------------*/
-int rrc_eNB_process_S1AP_INITIAL_CONTEXT_SETUP_REQ(MessageDef *msg_p, const char *msg_name, instance_t instance)
-{
+int rrc_eNB_process_S1AP_INITIAL_CONTEXT_SETUP_REQ(MessageDef *msg_p, const char *msg_name, instance_t instance) {
   uint16_t                        ue_initial_id;
   uint32_t                        eNB_ue_s1ap_id;
   //MessageDef                     *message_gtpv1u_p = NULL;
   gtpv1u_enb_create_tunnel_req_t  create_tunnel_req;
   gtpv1u_enb_create_tunnel_resp_t create_tunnel_resp;
-  uint8_t                         inde_list[NB_RB_MAX - 3]={0};
-
-  struct rrc_eNB_ue_context_s* ue_context_p = NULL;
+  uint8_t                         inde_list[NB_RB_MAX - 3]= {0};
+  struct rrc_eNB_ue_context_s *ue_context_p = NULL;
   protocol_ctxt_t              ctxt;
   ue_initial_id  = S1AP_INITIAL_CONTEXT_SETUP_REQ (msg_p).ue_initial_id;
   eNB_ue_s1ap_id = S1AP_INITIAL_CONTEXT_SETUP_REQ (msg_p).eNB_ue_s1ap_id;
@@ -960,64 +1000,51 @@ int rrc_eNB_process_S1AP_INITIAL_CONTEXT_SETUP_REQ(MessageDef *msg_p, const char
   if (ue_context_p == NULL) {
     /* Can not associate this message to an UE index, send a failure to S1AP and discard it! */
     MessageDef *msg_fail_p = NULL;
-
     LOG_W(RRC, "[eNB %d] In S1AP_INITIAL_CONTEXT_SETUP_REQ: unknown UE from S1AP ids (%d, %d)\n", instance, ue_initial_id, eNB_ue_s1ap_id);
-
     msg_fail_p = itti_alloc_new_message (TASK_RRC_ENB, S1AP_INITIAL_CONTEXT_SETUP_FAIL);
     S1AP_INITIAL_CONTEXT_SETUP_FAIL (msg_fail_p).eNB_ue_s1ap_id = eNB_ue_s1ap_id;
-
     // TODO add failure cause when defined!
-
     itti_send_msg_to_task (TASK_S1AP, instance, msg_fail_p);
     return (-1);
   } else {
-
     PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, ENB_FLAG_YES, ue_context_p->ue_context.rnti, 0, 0);
     ue_context_p->ue_context.eNB_ue_s1ap_id = S1AP_INITIAL_CONTEXT_SETUP_REQ (msg_p).eNB_ue_s1ap_id;
+    ue_context_p->ue_context.mme_ue_s1ap_id = S1AP_INITIAL_CONTEXT_SETUP_REQ (msg_p).mme_ue_s1ap_id;
 
     /* Save e RAB information for later */
     {
       int i;
-
-      memset(&create_tunnel_req, 0 , sizeof(create_tunnel_req));
+      memset(&create_tunnel_req, 0, sizeof(create_tunnel_req));
       ue_context_p->ue_context.nb_of_e_rabs = S1AP_INITIAL_CONTEXT_SETUP_REQ (msg_p).nb_of_e_rabs;
-     
-      LOG_E(RRC, "rrc_eNB_process_S1AP_INITIAL_CONTEXT_SETUP_REQ: ue_context_p->ue_context.nb_of_e_rabs = %d \n", ue_context_p->ue_context.nb_of_e_rabs);
+
       for (i = 0; i < ue_context_p->ue_context.nb_of_e_rabs; i++) {
         ue_context_p->ue_context.e_rab[i].status = E_RAB_STATUS_NEW;
         ue_context_p->ue_context.e_rab[i].param = S1AP_INITIAL_CONTEXT_SETUP_REQ (msg_p).e_rab_param[i];
-
-
         create_tunnel_req.eps_bearer_id[i]       = S1AP_INITIAL_CONTEXT_SETUP_REQ (msg_p).e_rab_param[i].e_rab_id;
         create_tunnel_req.sgw_S1u_teid[i]        = S1AP_INITIAL_CONTEXT_SETUP_REQ (msg_p).e_rab_param[i].gtp_teid;
-
         memcpy(&create_tunnel_req.sgw_addr[i],
                &S1AP_INITIAL_CONTEXT_SETUP_REQ (msg_p).e_rab_param[i].sgw_addr,
                sizeof(transport_layer_addr_t));
         inde_list[create_tunnel_req.num_tunnels]= i;
         create_tunnel_req.num_tunnels++;
       }
-    
-      create_tunnel_req.rnti       = ue_context_p->ue_context.rnti; // warning put zero above
-//      create_tunnel_req.num_tunnels    = i;
 
+      create_tunnel_req.rnti       = ue_context_p->ue_context.rnti; // warning put zero above
+      //      create_tunnel_req.num_tunnels    = i;
       gtpv1u_create_s1u_tunnel(
         instance,
         &create_tunnel_req,
         &create_tunnel_resp);
-
       rrc_eNB_process_GTPV1U_CREATE_TUNNEL_RESP(
-          &ctxt,
-          &create_tunnel_resp,
-          &inde_list[0]); 
+        &ctxt,
+        &create_tunnel_resp,
+        &inde_list[0]);
       ue_context_p->ue_context.setup_e_rabs=ue_context_p->ue_context.nb_of_e_rabs;
     }
-
     /* TODO parameters yet to process ... */
     {
       //      S1AP_INITIAL_CONTEXT_SETUP_REQ(msg_p).ue_ambr;
     }
-
     rrc_eNB_process_security (
       &ctxt,
       ue_context_p,
@@ -1026,10 +1053,8 @@ int rrc_eNB_process_S1AP_INITIAL_CONTEXT_SETUP_REQ(MessageDef *msg_p, const char
       &ctxt,
       ue_context_p,
       S1AP_INITIAL_CONTEXT_SETUP_REQ(msg_p).security_key);
-
     {
       uint8_t send_security_mode_command = TRUE;
-
 #ifndef EXMIMO_IOT
 
       if ((ue_context_p->ue_context.ciphering_algorithm == SecurityAlgorithmConfig__cipheringAlgorithm_eea0)
@@ -1044,7 +1069,6 @@ int rrc_eNB_process_S1AP_INITIAL_CONTEXT_SETUP_REQ(MessageDef *msg_p, const char
         send_security_mode_command);
 
       if (send_security_mode_command) {
-
         rrc_eNB_generate_SecurityModeCommand (
           &ctxt,
           ue_context_p);
@@ -1092,30 +1116,23 @@ int rrc_eNB_process_S1AP_INITIAL_CONTEXT_SETUP_REQ(MessageDef *msg_p, const char
 }
 
 /*------------------------------------------------------------------------------*/
-int rrc_eNB_process_S1AP_UE_CTXT_MODIFICATION_REQ(MessageDef *msg_p, const char *msg_name, instance_t instance)
-{
+int rrc_eNB_process_S1AP_UE_CTXT_MODIFICATION_REQ(MessageDef *msg_p, const char *msg_name, instance_t instance) {
   uint32_t eNB_ue_s1ap_id;
-  struct rrc_eNB_ue_context_s* ue_context_p = NULL;
+  struct rrc_eNB_ue_context_s *ue_context_p = NULL;
   protocol_ctxt_t              ctxt;
-
   eNB_ue_s1ap_id = S1AP_UE_CTXT_MODIFICATION_REQ (msg_p).eNB_ue_s1ap_id;
   ue_context_p   = rrc_eNB_get_ue_context_from_s1ap_ids(instance, UE_INITIAL_ID_INVALID, eNB_ue_s1ap_id);
 
   if (ue_context_p == NULL) {
     /* Can not associate this message to an UE index, send a failure to S1AP and discard it! */
     MessageDef *msg_fail_p;
-
     LOG_W(RRC, "[eNB %d] In S1AP_UE_CTXT_MODIFICATION_REQ: unknown UE from eNB_ue_s1ap_id (%d)\n", instance, eNB_ue_s1ap_id);
-
     msg_fail_p = itti_alloc_new_message (TASK_RRC_ENB, S1AP_UE_CTXT_MODIFICATION_FAIL);
     S1AP_UE_CTXT_MODIFICATION_FAIL (msg_fail_p).eNB_ue_s1ap_id = eNB_ue_s1ap_id;
-
     // TODO add failure cause when defined!
-
     itti_send_msg_to_task (TASK_S1AP, instance, msg_fail_p);
     return (-1);
   } else {
-
     PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, ENB_FLAG_YES, ue_context_p->ue_context.rnti, 0, 0);
     /* TODO parameters yet to process ... */
     {
@@ -1141,85 +1158,72 @@ int rrc_eNB_process_S1AP_UE_CTXT_MODIFICATION_REQ(MessageDef *msg_p, const char
         &ctxt,
         ue_context_p,
         S1AP_UE_CTXT_MODIFICATION_REQ(msg_p).security_key);
-
       /* TODO reconfigure lower layers... */
     }
 
     /* Send the response */
     {
       MessageDef *msg_resp_p;
-
       msg_resp_p = itti_alloc_new_message(TASK_RRC_ENB, S1AP_UE_CTXT_MODIFICATION_RESP);
       S1AP_UE_CTXT_MODIFICATION_RESP(msg_resp_p).eNB_ue_s1ap_id = eNB_ue_s1ap_id;
-
       itti_send_msg_to_task(TASK_S1AP, instance, msg_resp_p);
     }
-
     return (0);
   }
 }
 
 /*------------------------------------------------------------------------------*/
-int rrc_eNB_process_S1AP_UE_CONTEXT_RELEASE_REQ (MessageDef *msg_p, const char *msg_name, instance_t instance)
-{
+int rrc_eNB_process_S1AP_UE_CONTEXT_RELEASE_REQ (MessageDef *msg_p, const char *msg_name, instance_t instance) {
   uint32_t eNB_ue_s1ap_id;
-  struct rrc_eNB_ue_context_s* ue_context_p = NULL;
-
+  struct rrc_eNB_ue_context_s *ue_context_p = NULL;
   eNB_ue_s1ap_id = S1AP_UE_CONTEXT_RELEASE_REQ(msg_p).eNB_ue_s1ap_id;
   ue_context_p   = rrc_eNB_get_ue_context_from_s1ap_ids(instance, UE_INITIAL_ID_INVALID, eNB_ue_s1ap_id);
 
   if (ue_context_p == NULL) {
     /* Can not associate this message to an UE index, send a failure to S1AP and discard it! */
     MessageDef *msg_fail_p;
-
     LOG_W(RRC, "[eNB %d] In S1AP_UE_CONTEXT_RELEASE_REQ: unknown UE from eNB_ue_s1ap_id (%d)\n",
           instance,
           eNB_ue_s1ap_id);
-
     msg_fail_p = itti_alloc_new_message(TASK_RRC_ENB, S1AP_UE_CONTEXT_RELEASE_RESP); /* TODO change message ID. */
     S1AP_UE_CONTEXT_RELEASE_RESP(msg_fail_p).eNB_ue_s1ap_id = eNB_ue_s1ap_id;
-
     // TODO add failure cause when defined!
-
     itti_send_msg_to_task(TASK_S1AP, instance, msg_fail_p);
     return (-1);
   } else {
     /* TODO release context. */
-
     /* Send the response */
     {
       MessageDef *msg_resp_p;
-
       msg_resp_p = itti_alloc_new_message(TASK_RRC_ENB, S1AP_UE_CONTEXT_RELEASE_RESP);
       S1AP_UE_CONTEXT_RELEASE_RESP(msg_resp_p).eNB_ue_s1ap_id = eNB_ue_s1ap_id;
-
       itti_send_msg_to_task(TASK_S1AP, instance, msg_resp_p);
     }
-
     return (0);
   }
 }
 
 //------------------------------------------------------------------------------
-void rrc_eNB_send_S1AP_UE_CONTEXT_RELEASE_REQ (
-  const module_id_t                        enb_mod_idP,
-  const rrc_eNB_ue_context_t*        const ue_context_pP,
-  const s1ap_Cause_t                       causeP,
-  const long                               cause_valueP
-)
+/*
+* Send the S1 command UE_CONTEXT_RELEASE_REQUEST to the MME.
+*/
+void
+rrc_eNB_send_S1AP_UE_CONTEXT_RELEASE_REQ(
+  const module_id_t enb_mod_idP,
+  const rrc_eNB_ue_context_t *const ue_context_pP,
+  const s1ap_Cause_t causeP,
+  const long cause_valueP)
 //------------------------------------------------------------------------------
 {
   if (ue_context_pP == NULL) {
-    LOG_W(RRC,
-          "[eNB] In S1AP_UE_CONTEXT_RELEASE_COMMAND: invalid  UE\n");
+    LOG_E(RRC, "[eNB] In S1AP_UE_CONTEXT_RELEASE_REQ: invalid UE\n");
   } else {
-	  MSC_LOG_TX_MESSAGE(
-			  MSC_RRC_ENB,
-	  		  MSC_S1AP_ENB,
-	  		  NULL,0,
-	  		  "0 S1AP_UE_CONTEXT_RELEASE_REQ eNB_ue_s1ap_id 0x%06"PRIX32" ",
-	  		  ue_context_pP->ue_context.eNB_ue_s1ap_id);
-
+    MSC_LOG_TX_MESSAGE(MSC_RRC_ENB,
+                       MSC_S1AP_ENB,
+                       NULL,
+                       0,
+                       "0 S1AP_UE_CONTEXT_RELEASE_REQ eNB_ue_s1ap_id 0x%06"PRIX32" ",
+                       ue_context_pP->ue_context.eNB_ue_s1ap_id);
     MessageDef *msg_context_release_req_p = NULL;
     msg_context_release_req_p = itti_alloc_new_message(TASK_RRC_ENB, S1AP_UE_CONTEXT_RELEASE_REQ);
     S1AP_UE_CONTEXT_RELEASE_REQ(msg_context_release_req_p).eNB_ue_s1ap_id = ue_context_pP->ue_context.eNB_ue_s1ap_id;
@@ -1234,12 +1238,9 @@ void rrc_eNB_send_S1AP_UE_CONTEXT_RELEASE_CPLT(
   uint32_t eNB_ue_s1ap_id
 )
 {
-  MSC_LOG_TX_MESSAGE(
-      MSC_RRC_ENB,
-      MSC_S1AP_ENB,
-      NULL,0,
-      "0 S1AP_UE_CONTEXT_RELEASE_COMPLETE eNB_ue_s1ap_id 0x%06"PRIX32" ",
-      eNB_ue_s1ap_id);
+  MSC_LOG_TX_MESSAGE(MSC_RRC_ENB, MSC_S1AP_ENB, NULL, 0,
+                     "0 S1AP_UE_CONTEXT_RELEASE_COMPLETE eNB_ue_s1ap_id 0x%06"PRIX32" ",
+                     eNB_ue_s1ap_id);
 
   MessageDef *msg = itti_alloc_new_message(TASK_RRC_ENB, S1AP_UE_CONTEXT_RELEASE_COMPLETE);
   S1AP_UE_CONTEXT_RELEASE_COMPLETE(msg).eNB_ue_s1ap_id = eNB_ue_s1ap_id;
@@ -1247,81 +1248,65 @@ void rrc_eNB_send_S1AP_UE_CONTEXT_RELEASE_CPLT(
 }
 
 
-/*------------------------------------------------------------------------------*/
-int rrc_eNB_process_S1AP_UE_CONTEXT_RELEASE_COMMAND (MessageDef *msg_p, const char *msg_name, instance_t instance)
-{
-  uint32_t eNB_ue_s1ap_id;
-  protocol_ctxt_t              ctxt;
+//-----------------------------------------------------------------------------
+/*
+* Process the S1 command UE_CONTEXT_RELEASE_COMMAND, sent by MME.
+* The eNB should remove all e-rab, S1 context, and other context of the UE.
+*/
+int
+rrc_eNB_process_S1AP_UE_CONTEXT_RELEASE_COMMAND(
+  MessageDef *msg_p,
+  const char *msg_name,
+  instance_t instance) {
+  //-----------------------------------------------------------------------------
+  uint32_t eNB_ue_s1ap_id = 0;
+  protocol_ctxt_t ctxt;
   struct rrc_eNB_ue_context_s *ue_context_p = NULL;
-  struct rrc_ue_s1ap_ids_s    *rrc_ue_s1ap_ids = NULL;
-
+  struct rrc_ue_s1ap_ids_s *rrc_ue_s1ap_ids = NULL;
   eNB_ue_s1ap_id = S1AP_UE_CONTEXT_RELEASE_COMMAND(msg_p).eNB_ue_s1ap_id;
-
-
-  ue_context_p   = rrc_eNB_get_ue_context_from_s1ap_ids(instance, UE_INITIAL_ID_INVALID, eNB_ue_s1ap_id);
+  ue_context_p = rrc_eNB_get_ue_context_from_s1ap_ids(instance, UE_INITIAL_ID_INVALID, eNB_ue_s1ap_id);
 
   if (ue_context_p == NULL) {
     /* Can not associate this message to an UE index */
-    MessageDef *msg_complete_p;
-
-    LOG_W(RRC,
-          "[eNB %d] In S1AP_UE_CONTEXT_RELEASE_COMMAND: unknown UE from eNB_ue_s1ap_id (%d)\n",
+    MessageDef *msg_complete_p = NULL;
+    LOG_W(RRC, "[eNB %d] In S1AP_UE_CONTEXT_RELEASE_COMMAND: unknown UE from eNB_ue_s1ap_id (%d)\n",
           instance,
           eNB_ue_s1ap_id);
-
-    MSC_LOG_EVENT(
-          MSC_RRC_ENB,
-  		  "0 S1AP_UE_CONTEXT_RELEASE_COMPLETE eNB_ue_s1ap_id 0x%06"PRIX32" context not found",
-  		eNB_ue_s1ap_id);
-
-    MSC_LOG_TX_MESSAGE(
-          MSC_RRC_ENB,
-  		  MSC_S1AP_ENB,
-  		  NULL,0,
-  		  "0 S1AP_UE_CONTEXT_RELEASE_COMPLETE eNB_ue_s1ap_id 0x%06"PRIX32" ",
-  		eNB_ue_s1ap_id);
-
+    MSC_LOG_EVENT(MSC_RRC_ENB, "0 S1AP_UE_CONTEXT_RELEASE_COMPLETE eNB_ue_s1ap_id 0x%06"PRIX32" context not found",
+                  eNB_ue_s1ap_id);
+    MSC_LOG_TX_MESSAGE(MSC_RRC_ENB,
+                       MSC_S1AP_ENB,
+                       NULL,
+                       0,
+                       "0 S1AP_UE_CONTEXT_RELEASE_COMPLETE eNB_ue_s1ap_id 0x%06"PRIX32" ",
+                       eNB_ue_s1ap_id);
     msg_complete_p = itti_alloc_new_message(TASK_RRC_ENB, S1AP_UE_CONTEXT_RELEASE_COMPLETE);
     S1AP_UE_CONTEXT_RELEASE_COMPLETE(msg_complete_p).eNB_ue_s1ap_id = eNB_ue_s1ap_id;
     itti_send_msg_to_task(TASK_S1AP, instance, msg_complete_p);
+    rrc_ue_s1ap_ids = rrc_eNB_S1AP_get_ue_ids(RC.rrc[instance], UE_INITIAL_ID_INVALID, eNB_ue_s1ap_id);
 
-    rrc_ue_s1ap_ids = rrc_eNB_S1AP_get_ue_ids(
-    		RC.rrc[instance],
-    		UE_INITIAL_ID_INVALID,
-    		eNB_ue_s1ap_id);
-
-    if (NULL != rrc_ue_s1ap_ids) {
-      rrc_eNB_S1AP_remove_ue_ids(
-    		  RC.rrc[instance],
-    		  rrc_ue_s1ap_ids);
+    if (rrc_ue_s1ap_ids != NULL) {
+      rrc_eNB_S1AP_remove_ue_ids(RC.rrc[instance], rrc_ue_s1ap_ids);
     }
-    return (-1);
+
+    return -1;
   } else {
     ue_context_p->ue_context.ue_release_timer_s1 = 0;
     PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, ENB_FLAG_YES, ue_context_p->ue_context.rnti, 0, 0);
     rrc_eNB_generate_RRCConnectionRelease(&ctxt, ue_context_p);
-    /*
-          LOG_W(RRC,
-                  "[eNB %d] In S1AP_UE_CONTEXT_RELEASE_COMMAND: TODO call rrc_eNB_connection_release for eNB %d\n",
-                  instance,
-                  eNB_ue_s1ap_id);
-    */
-    return (0);
+    return 0;
   }
 }
 
-int rrc_eNB_process_S1AP_E_RAB_SETUP_REQ(MessageDef *msg_p, const char *msg_name, instance_t instance)
-{
+int rrc_eNB_process_S1AP_E_RAB_SETUP_REQ(MessageDef *msg_p, const char *msg_name, instance_t instance) {
   uint16_t                        ue_initial_id;
   uint32_t                        eNB_ue_s1ap_id;
   gtpv1u_enb_create_tunnel_req_t  create_tunnel_req;
   gtpv1u_enb_create_tunnel_resp_t create_tunnel_resp;
-  uint8_t                         inde_list[NB_RB_MAX - 3]={0};
-
-  struct rrc_eNB_ue_context_s* ue_context_p = NULL;
+  uint8_t                         inde_list[NB_RB_MAX - 3]= {0};
+  struct rrc_eNB_ue_context_s *ue_context_p = NULL;
   protocol_ctxt_t              ctxt;
   uint8_t                      e_rab_done;
-
   ue_initial_id  = S1AP_E_RAB_SETUP_REQ (msg_p).ue_initial_id;
   eNB_ue_s1ap_id = S1AP_E_RAB_SETUP_REQ (msg_p).eNB_ue_s1ap_id;
   ue_context_p   = rrc_eNB_get_ue_context_from_s1ap_ids(instance, ue_initial_id, eNB_ue_s1ap_id);
@@ -1331,185 +1316,159 @@ int rrc_eNB_process_S1AP_E_RAB_SETUP_REQ(MessageDef *msg_p, const char *msg_name
   if (ue_context_p == NULL) {
     /* Can not associate this message to an UE index, send a failure to S1AP and discard it! */
     MessageDef *msg_fail_p = NULL;
-
     LOG_W(RRC, "[eNB %d] In S1AP_E_RAB_SETUP_REQ: unknown UE from S1AP ids (%d, %d)\n", instance, ue_initial_id, eNB_ue_s1ap_id);
-
     msg_fail_p = itti_alloc_new_message (TASK_RRC_ENB, S1AP_E_RAB_SETUP_REQUEST_FAIL);
     S1AP_E_RAB_SETUP_REQ  (msg_fail_p).eNB_ue_s1ap_id = eNB_ue_s1ap_id;
-
     // TODO add failure cause when defined!
-
     itti_send_msg_to_task (TASK_S1AP, instance, msg_fail_p);
     return (-1);
   } else {
-
     PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, ENB_FLAG_YES, ue_context_p->ue_context.rnti, 0, 0);
     ue_context_p->ue_context.eNB_ue_s1ap_id = S1AP_E_RAB_SETUP_REQ  (msg_p).eNB_ue_s1ap_id;
-
     /* Save e RAB information for later */
     {
       int i;
-
-      memset(&create_tunnel_req, 0 , sizeof(create_tunnel_req));
+      memset(&create_tunnel_req, 0, sizeof(create_tunnel_req));
       uint8_t nb_e_rabs_tosetup = S1AP_E_RAB_SETUP_REQ  (msg_p).nb_e_rabs_tosetup;
       e_rab_done = 0;
 
       // keep the previous bearer
       // the index for the rec
-      for (i = 0; 
-	  // i < nb_e_rabs_tosetup; 
-           i < NB_RB_MAX - 3;  // loop all e-rabs in e_rab[] 
-	   i++) {
-	//if (ue_context_p->ue_context.e_rab[i+ue_context_p->ue_context.setup_e_rabs].status == E_RAB_STATUS_DONE) 
-	//  LOG_W(RRC,"E-RAB already configured, reconfiguring\n");
+      for (i = 0;
+           // i < nb_e_rabs_tosetup;
+           i < NB_RB_MAX - 3;  // loop all e-rabs in e_rab[]
+           i++) {
+        //if (ue_context_p->ue_context.e_rab[i+ue_context_p->ue_context.setup_e_rabs].status == E_RAB_STATUS_DONE)
+        //  LOG_W(RRC,"E-RAB already configured, reconfiguring\n");
         // check e-rab status, if e rab status is greater than E_RAB_STATUS_DONE, don't not config this one
         if(ue_context_p->ue_context.e_rab[i].status >= E_RAB_STATUS_DONE)
-            continue;
+          continue;
+
         //ue_context_p->ue_context.e_rab[i+ue_context_p->ue_context.setup_e_rabs].status = E_RAB_STATUS_NEW;
         //ue_context_p->ue_context.e_rab[i+ue_context_p->ue_context.setup_e_rabs].param = S1AP_E_RAB_SETUP_REQ  (msg_p).e_rab_setup_params[i];
         ue_context_p->ue_context.e_rab[i].status = E_RAB_STATUS_NEW;
         ue_context_p->ue_context.e_rab[i].param = S1AP_E_RAB_SETUP_REQ  (msg_p).e_rab_setup_params[e_rab_done];
-
         create_tunnel_req.eps_bearer_id[e_rab_done]       = S1AP_E_RAB_SETUP_REQ  (msg_p).e_rab_setup_params[e_rab_done].e_rab_id;
         create_tunnel_req.sgw_S1u_teid[e_rab_done]        = S1AP_E_RAB_SETUP_REQ  (msg_p).e_rab_setup_params[e_rab_done].gtp_teid;
-
         memcpy(&create_tunnel_req.sgw_addr[e_rab_done],
                & S1AP_E_RAB_SETUP_REQ (msg_p).e_rab_setup_params[e_rab_done].sgw_addr,
                sizeof(transport_layer_addr_t));
-	
-	LOG_I(RRC,"E_RAB setup REQ: local index %d teid %u, eps id %d \n", 
-	      i,
-	      create_tunnel_req.sgw_S1u_teid[e_rab_done],
-	       create_tunnel_req.eps_bearer_id[i] );
+        LOG_I(RRC,"E_RAB setup REQ: local index %d teid %u, eps id %d \n",
+              i,
+              create_tunnel_req.sgw_S1u_teid[e_rab_done],
+              create_tunnel_req.eps_bearer_id[i] );
         inde_list[e_rab_done] = i;
-        e_rab_done++;        
-        if(e_rab_done >= nb_e_rabs_tosetup){
-            break;
+        e_rab_done++;
+
+        if(e_rab_done >= nb_e_rabs_tosetup) {
+          break;
         }
       }
+
       ue_context_p->ue_context.nb_of_e_rabs=nb_e_rabs_tosetup;
-     
-     
       create_tunnel_req.rnti       = ue_context_p->ue_context.rnti; // warning put zero above
       create_tunnel_req.num_tunnels    = e_rab_done;
-      
       // NN: not sure if we should create a new tunnel: need to check teid, etc.
       gtpv1u_create_s1u_tunnel(
         instance,
         &create_tunnel_req,
         &create_tunnel_resp);
-
       rrc_eNB_process_GTPV1U_CREATE_TUNNEL_RESP(
-          &ctxt,
-          &create_tunnel_resp,
-          &inde_list[0]);
-
+        &ctxt,
+        &create_tunnel_resp,
+        &inde_list[0]);
       ue_context_p->ue_context.setup_e_rabs+=nb_e_rabs_tosetup;
-
     }
-
     /* TODO parameters yet to process ... */
     {
       //      S1AP_INITIAL_CONTEXT_SETUP_REQ(msg_p).ue_ambr;
     }
-
     rrc_eNB_generate_dedicatedRRCConnectionReconfiguration(&ctxt, ue_context_p, 0);
-							 
     return (0);
   }
 }
 
 /*NN: careful about the typcast of xid (long -> uint8_t*/
-int rrc_eNB_send_S1AP_E_RAB_SETUP_RESP(const protocol_ctxt_t* const ctxt_pP,
-				   rrc_eNB_ue_context_t*          const ue_context_pP,
-				   uint8_t xid ){  
-
+int rrc_eNB_send_S1AP_E_RAB_SETUP_RESP(const protocol_ctxt_t *const ctxt_pP,
+                                       rrc_eNB_ue_context_t          *const ue_context_pP,
+                                       uint8_t xid ) {
   MessageDef      *msg_p         = NULL;
   int e_rab;
   int e_rabs_done = 0;
   int e_rabs_failed = 0;
-    
   msg_p = itti_alloc_new_message (TASK_RRC_ENB, S1AP_E_RAB_SETUP_RESP);
   S1AP_E_RAB_SETUP_RESP (msg_p).eNB_ue_s1ap_id = ue_context_pP->ue_context.eNB_ue_s1ap_id;
- 
-  for (e_rab = 0; e_rab <  ue_context_pP->ue_context.setup_e_rabs ; e_rab++) {
 
-    /* only respond to the corresponding transaction */ 
+  for (e_rab = 0; e_rab <  ue_context_pP->ue_context.setup_e_rabs ; e_rab++) {
+    /* only respond to the corresponding transaction */
     //if (((xid+1)%4) == ue_context_pP->ue_context.e_rab[e_rab].xid) {
     if (xid == ue_context_pP->ue_context.e_rab[e_rab].xid) {
-      
       if (ue_context_pP->ue_context.e_rab[e_rab].status == E_RAB_STATUS_DONE) {
-     
-	S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rabs_done].e_rab_id = ue_context_pP->ue_context.e_rab[e_rab].param.e_rab_id;
-	// TODO add other information from S1-U when it will be integrated
-	S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rabs_done].gtp_teid = ue_context_pP->ue_context.enb_gtp_teid[e_rab];
-	S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rabs_done].eNB_addr = ue_context_pP->ue_context.enb_gtp_addrs[e_rab];
-	//S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rab].eNB_addr.length += 4;
-	ue_context_pP->ue_context.e_rab[e_rab].status = E_RAB_STATUS_ESTABLISHED;
-	
-	LOG_I (RRC,"enb_gtp_addr (msg index %d, e_rab index %d, status %d, xid %d): nb_of_e_rabs %d,  e_rab_id %d, teid: %u, addr: %d.%d.%d.%d \n ",
-	       e_rabs_done,  e_rab, ue_context_pP->ue_context.e_rab[e_rab].status, xid,
-	       ue_context_pP->ue_context.nb_of_e_rabs,
-	       S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rabs_done].e_rab_id,
-	       S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rabs_done].gtp_teid,
-	       S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rabs_done].eNB_addr.buffer[0],
-	       S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rabs_done].eNB_addr.buffer[1],
-	       S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rabs_done].eNB_addr.buffer[2],
-	       S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rabs_done].eNB_addr.buffer[3]);
-	
-	e_rabs_done++;
-      } else if ((ue_context_pP->ue_context.e_rab[e_rab].status == E_RAB_STATUS_NEW)  || 
-		 (ue_context_pP->ue_context.e_rab[e_rab].status == E_RAB_STATUS_ESTABLISHED)){
-	LOG_D (RRC,"E-RAB is NEW or already ESTABLISHED\n");
-      }else { /* to be improved */
-	ue_context_pP->ue_context.e_rab[e_rab].status = E_RAB_STATUS_FAILED;
-	S1AP_E_RAB_SETUP_RESP  (msg_p).e_rabs_failed[e_rabs_failed].e_rab_id = ue_context_pP->ue_context.e_rab[e_rab].param.e_rab_id;
-	e_rabs_failed++;
-	// TODO add cause when it will be integrated
-      } 
-      
+        S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rabs_done].e_rab_id = ue_context_pP->ue_context.e_rab[e_rab].param.e_rab_id;
+        // TODO add other information from S1-U when it will be integrated
+        S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rabs_done].gtp_teid = ue_context_pP->ue_context.enb_gtp_teid[e_rab];
+        S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rabs_done].eNB_addr = ue_context_pP->ue_context.enb_gtp_addrs[e_rab];
+        //S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rab].eNB_addr.length += 4;
+        ue_context_pP->ue_context.e_rab[e_rab].status = E_RAB_STATUS_ESTABLISHED;
+        LOG_I (RRC,"enb_gtp_addr (msg index %d, e_rab index %d, status %d, xid %d): nb_of_e_rabs %d,  e_rab_id %d, teid: %u, addr: %d.%d.%d.%d \n ",
+               e_rabs_done,  e_rab, ue_context_pP->ue_context.e_rab[e_rab].status, xid,
+               ue_context_pP->ue_context.nb_of_e_rabs,
+               S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rabs_done].e_rab_id,
+               S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rabs_done].gtp_teid,
+               S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rabs_done].eNB_addr.buffer[0],
+               S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rabs_done].eNB_addr.buffer[1],
+               S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rabs_done].eNB_addr.buffer[2],
+               S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rabs_done].eNB_addr.buffer[3]);
+        e_rabs_done++;
+      } else if ((ue_context_pP->ue_context.e_rab[e_rab].status == E_RAB_STATUS_NEW)  ||
+                 (ue_context_pP->ue_context.e_rab[e_rab].status == E_RAB_STATUS_ESTABLISHED)) {
+        LOG_D (RRC,"E-RAB is NEW or already ESTABLISHED\n");
+      } else { /* to be improved */
+        ue_context_pP->ue_context.e_rab[e_rab].status = E_RAB_STATUS_FAILED;
+        S1AP_E_RAB_SETUP_RESP  (msg_p).e_rabs_failed[e_rabs_failed].e_rab_id = ue_context_pP->ue_context.e_rab[e_rab].param.e_rab_id;
+        e_rabs_failed++;
+        // TODO add cause when it will be integrated
+      }
+
       S1AP_E_RAB_SETUP_RESP (msg_p).nb_of_e_rabs = e_rabs_done;
       S1AP_E_RAB_SETUP_RESP (msg_p).nb_of_e_rabs_failed = e_rabs_failed;
-      // NN: add conditions for e_rabs_failed 
+      // NN: add conditions for e_rabs_failed
     } else {
-      /*debug info for the xid */ 
+      /*debug info for the xid */
       LOG_D(RRC,"xid does not corresponds  (context e_rab index %d, status %d, xid %d/%d) \n ",
-      	     e_rab, ue_context_pP->ue_context.e_rab[e_rab].status, xid, ue_context_pP->ue_context.e_rab[e_rab].xid);
-    } 
+            e_rab, ue_context_pP->ue_context.e_rab[e_rab].status, xid, ue_context_pP->ue_context.e_rab[e_rab].xid);
+    }
   }
-      if ((e_rabs_done > 0) ){  
-
-	LOG_I(RRC,"S1AP_E_RAB_SETUP_RESP: sending the message: nb_of_erabs %d, total e_rabs %d, index %d\n",
-	      ue_context_pP->ue_context.nb_of_e_rabs, ue_context_pP->ue_context.setup_e_rabs, e_rab);
-	MSC_LOG_TX_MESSAGE(
-			   MSC_RRC_ENB,
-			   MSC_S1AP_ENB,
-			   (const char *)&S1AP_E_RAB_SETUP_RESP (msg_p),
-			   sizeof(s1ap_e_rab_setup_resp_t),
-			   MSC_AS_TIME_FMT" E_RAB_SETUP_RESP UE %X eNB_ue_s1ap_id %u e_rabs:%u succ %u fail",
-			   MSC_AS_TIME_ARGS(ctxt_pP),
-			   ue_context_pP->ue_id_rnti,
-			   S1AP_E_RAB_SETUP_RESP (msg_p).eNB_ue_s1ap_id,
-			   e_rabs_done, e_rabs_failed);
-	
-	
-	itti_send_msg_to_task (TASK_S1AP, ctxt_pP->instance, msg_p);
-      }
+
+  if ((e_rabs_done > 0) ) {
+    LOG_I(RRC,"S1AP_E_RAB_SETUP_RESP: sending the message: nb_of_erabs %d, total e_rabs %d, index %d\n",
+          ue_context_pP->ue_context.nb_of_e_rabs, ue_context_pP->ue_context.setup_e_rabs, e_rab);
+    MSC_LOG_TX_MESSAGE(
+      MSC_RRC_ENB,
+      MSC_S1AP_ENB,
+      (const char *)&S1AP_E_RAB_SETUP_RESP (msg_p),
+      sizeof(s1ap_e_rab_setup_resp_t),
+      MSC_AS_TIME_FMT" E_RAB_SETUP_RESP UE %X eNB_ue_s1ap_id %u e_rabs:%u succ %u fail",
+      MSC_AS_TIME_ARGS(ctxt_pP),
+      ue_context_pP->ue_id_rnti,
+      S1AP_E_RAB_SETUP_RESP (msg_p).eNB_ue_s1ap_id,
+      e_rabs_done, e_rabs_failed);
+    itti_send_msg_to_task (TASK_S1AP, ctxt_pP->instance, msg_p);
+  }
+
   for(int i = 0; i < NB_RB_MAX; i++) {
-      ue_context_pP->ue_context.e_rab[i].xid = -1;
+    ue_context_pP->ue_context.e_rab[i].xid = -1;
   }
-  
+
   return 0;
 }
 
-int rrc_eNB_process_S1AP_E_RAB_MODIFY_REQ(MessageDef *msg_p, const char *msg_name, instance_t instance)
-{
+int rrc_eNB_process_S1AP_E_RAB_MODIFY_REQ(MessageDef *msg_p, const char *msg_name, instance_t instance) {
   int                             i;
   uint16_t                        ue_initial_id;
   uint32_t                        eNB_ue_s1ap_id;
-  struct rrc_eNB_ue_context_s* ue_context_p = NULL;
+  struct rrc_eNB_ue_context_s *ue_context_p = NULL;
   protocol_ctxt_t              ctxt;
-
   ue_initial_id  = S1AP_E_RAB_MODIFY_REQ (msg_p).ue_initial_id;
   eNB_ue_s1ap_id = S1AP_E_RAB_MODIFY_REQ (msg_p).eNB_ue_s1ap_id;
   ue_context_p   = rrc_eNB_get_ue_context_from_s1ap_ids(instance, ue_initial_id, eNB_ue_s1ap_id);
@@ -1521,27 +1480,23 @@ int rrc_eNB_process_S1AP_E_RAB_MODIFY_REQ(MessageDef *msg_p, const char *msg_nam
     LOG_W(RRC, "[eNB %d] In S1AP_E_RAB_MODIFY_REQ: unknown UE from S1AP ids (%d, %d)\n", instance, ue_initial_id, eNB_ue_s1ap_id);
     int nb_of_e_rabs_failed = 0;
     MessageDef *msg_fail_p = NULL;
-
     msg_fail_p = itti_alloc_new_message (TASK_RRC_ENB, S1AP_E_RAB_MODIFY_RESP);
-
     S1AP_E_RAB_MODIFY_RESP (msg_fail_p).eNB_ue_s1ap_id = S1AP_E_RAB_MODIFY_REQ (msg_p).eNB_ue_s1ap_id;
     S1AP_E_RAB_MODIFY_RESP (msg_fail_p).nb_of_e_rabs = 0;
 
     for (nb_of_e_rabs_failed = 0; nb_of_e_rabs_failed < S1AP_E_RAB_MODIFY_REQ (msg_p).nb_e_rabs_tomodify; nb_of_e_rabs_failed++) {
       S1AP_E_RAB_MODIFY_RESP (msg_fail_p).e_rabs_failed[nb_of_e_rabs_failed].e_rab_id =
-              S1AP_E_RAB_MODIFY_REQ (msg_p).e_rab_modify_params[nb_of_e_rabs_failed].e_rab_id;
+        S1AP_E_RAB_MODIFY_REQ (msg_p).e_rab_modify_params[nb_of_e_rabs_failed].e_rab_id;
       S1AP_E_RAB_MODIFY_RESP (msg_fail_p).e_rabs_failed[nb_of_e_rabs_failed].cause = S1AP_CAUSE_RADIO_NETWORK;
       S1AP_E_RAB_MODIFY_RESP (msg_fail_p).e_rabs_failed[nb_of_e_rabs_failed].cause_value = 31;//S1ap_CauseRadioNetwork_multiple_E_RAB_ID_instances;
     }
-    S1AP_E_RAB_MODIFY_RESP (msg_fail_p).nb_of_e_rabs_failed = nb_of_e_rabs_failed;
 
+    S1AP_E_RAB_MODIFY_RESP (msg_fail_p).nb_of_e_rabs_failed = nb_of_e_rabs_failed;
     itti_send_msg_to_task(TASK_S1AP, instance, msg_fail_p);
     return (-1);
-
   } else {
     PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, ENB_FLAG_YES, ue_context_p->ue_context.rnti, 0, 0);
     ue_context_p->ue_context.eNB_ue_s1ap_id = eNB_ue_s1ap_id;
-
     /* Save e RAB information for later */
     {
       int j;
@@ -1555,9 +1510,10 @@ int rrc_eNB_process_S1AP_E_RAB_MODIFY_REQ(MessageDef *msg_p, const char *msg_nam
           // already treated
           continue;
         }
+
         for (j = i+1; j < S1AP_E_RAB_MODIFY_REQ (msg_p).nb_e_rabs_tomodify; j++) {
           if (is_treated[j] == FALSE &&
-            S1AP_E_RAB_MODIFY_REQ(msg_p).e_rab_modify_params[j].e_rab_id == S1AP_E_RAB_MODIFY_REQ(msg_p).e_rab_modify_params[i].e_rab_id) {
+              S1AP_E_RAB_MODIFY_REQ(msg_p).e_rab_modify_params[j].e_rab_id == S1AP_E_RAB_MODIFY_REQ(msg_p).e_rab_modify_params[i].e_rab_id) {
             // handle multiple E-RAB ID
             ue_context_p->ue_context.modify_e_rab[j].status = E_RAB_STATUS_NEW;
             ue_context_p->ue_context.modify_e_rab[j].param.e_rab_id = S1AP_E_RAB_MODIFY_REQ(msg_p).e_rab_modify_params[j].e_rab_id;
@@ -1568,6 +1524,7 @@ int rrc_eNB_process_S1AP_E_RAB_MODIFY_REQ(MessageDef *msg_p, const char *msg_nam
             is_treated[j] = TRUE;
           }
         }
+
         if (is_treated[i] == TRUE) {
           // handle multiple E-RAB ID
           ue_context_p->ue_context.modify_e_rab[i].status = E_RAB_STATUS_NEW;
@@ -1591,9 +1548,10 @@ int rrc_eNB_process_S1AP_E_RAB_MODIFY_REQ(MessageDef *msg_p, const char *msg_nam
 
         for (j = 0; j < NB_RB_MAX-3; j++) {
           if (ue_context_p->ue_context.e_rab[j].param.e_rab_id == S1AP_E_RAB_MODIFY_REQ(msg_p).e_rab_modify_params[i].e_rab_id) {
-            if(ue_context_p->ue_context.e_rab[j].status == E_RAB_STATUS_TORELEASE || ue_context_p->ue_context.e_rab[j].status == E_RAB_STATUS_DONE){
+            if(ue_context_p->ue_context.e_rab[j].status == E_RAB_STATUS_TORELEASE || ue_context_p->ue_context.e_rab[j].status == E_RAB_STATUS_DONE) {
               break;
             }
+
             ue_context_p->ue_context.modify_e_rab[i].status = E_RAB_STATUS_NEW;
             ue_context_p->ue_context.modify_e_rab[i].cause = S1AP_CAUSE_NOTHING;
             ue_context_p->ue_context.modify_e_rab[i].param.e_rab_id = S1AP_E_RAB_MODIFY_REQ(msg_p).e_rab_modify_params[i].e_rab_id;
@@ -1602,7 +1560,6 @@ int rrc_eNB_process_S1AP_E_RAB_MODIFY_REQ(MessageDef *msg_p, const char *msg_nam
             ue_context_p->ue_context.modify_e_rab[i].param.nas_pdu.buffer = S1AP_E_RAB_MODIFY_REQ(msg_p).e_rab_modify_params[i].nas_pdu.buffer;
             ue_context_p->ue_context.modify_e_rab[i].param.sgw_addr = ue_context_p->ue_context.e_rab[j].param.sgw_addr;
             ue_context_p->ue_context.modify_e_rab[i].param.gtp_teid = ue_context_p->ue_context.e_rab[j].param.gtp_teid;
-
             is_treated[i] = TRUE;
             break;
           }
@@ -1622,7 +1579,6 @@ int rrc_eNB_process_S1AP_E_RAB_MODIFY_REQ(MessageDef *msg_p, const char *msg_nam
       ue_context_p->ue_context.nb_of_modify_e_rabs = S1AP_E_RAB_MODIFY_REQ  (msg_p).nb_e_rabs_tomodify;
       ue_context_p->ue_context.nb_of_failed_e_rabs = nb_of_failed_e_rabs;
     }
-
     /* TODO parameters yet to process ... */
     {
       //      S1AP_INITIAL_CONTEXT_SETUP_REQ(msg_p).ue_ambr;
@@ -1637,36 +1593,31 @@ int rrc_eNB_process_S1AP_E_RAB_MODIFY_REQ(MessageDef *msg_p, const char *msg_nam
     {
       int nb_of_e_rabs_failed = 0;
       MessageDef *msg_fail_p = NULL;
-
       msg_fail_p = itti_alloc_new_message (TASK_RRC_ENB, S1AP_E_RAB_MODIFY_RESP);
-
       S1AP_E_RAB_MODIFY_RESP (msg_fail_p).eNB_ue_s1ap_id = S1AP_E_RAB_MODIFY_REQ (msg_p).eNB_ue_s1ap_id;
-//      S1AP_E_RAB_MODIFY_RESP (msg_fail_p).e_rabs[S1AP_MAX_E_RAB];
+      //      S1AP_E_RAB_MODIFY_RESP (msg_fail_p).e_rabs[S1AP_MAX_E_RAB];
       S1AP_E_RAB_MODIFY_RESP (msg_fail_p).nb_of_e_rabs = 0;
 
       for(nb_of_e_rabs_failed = 0; nb_of_e_rabs_failed < ue_context_p->ue_context.nb_of_failed_e_rabs; nb_of_e_rabs_failed++) {
         S1AP_E_RAB_MODIFY_RESP (msg_fail_p).e_rabs_failed[nb_of_e_rabs_failed].e_rab_id =
-                ue_context_p->ue_context.modify_e_rab[nb_of_e_rabs_failed].param.e_rab_id;
+          ue_context_p->ue_context.modify_e_rab[nb_of_e_rabs_failed].param.e_rab_id;
         S1AP_E_RAB_MODIFY_RESP (msg_fail_p).e_rabs_failed[nb_of_e_rabs_failed].cause = ue_context_p->ue_context.modify_e_rab[nb_of_e_rabs_failed].cause;
       }
-      S1AP_E_RAB_MODIFY_RESP (msg_fail_p).nb_of_e_rabs_failed = nb_of_e_rabs_failed;
 
+      S1AP_E_RAB_MODIFY_RESP (msg_fail_p).nb_of_e_rabs_failed = nb_of_e_rabs_failed;
       itti_send_msg_to_task (TASK_S1AP, instance, msg_fail_p);
-
       ue_context_p->ue_context.nb_of_modify_e_rabs = 0;
       ue_context_p->ue_context.nb_of_failed_e_rabs = 0;
       memset(ue_context_p->ue_context.modify_e_rab, 0, sizeof(ue_context_p->ue_context.modify_e_rab));
-
       return (0);
     }
   }  // end of ue_context_p != NULL
 }
 
 /*NN: careful about the typcast of xid (long -> uint8_t*/
-int rrc_eNB_send_S1AP_E_RAB_MODIFY_RESP(const protocol_ctxt_t* const ctxt_pP,
-           rrc_eNB_ue_context_t*          const ue_context_pP,
-           uint8_t xid ) {
-
+int rrc_eNB_send_S1AP_E_RAB_MODIFY_RESP(const protocol_ctxt_t *const ctxt_pP,
+                                        rrc_eNB_ue_context_t          *const ue_context_pP,
+                                        uint8_t xid ) {
   MessageDef      *msg_p         = NULL;
   int i;
   int e_rab;
@@ -1676,7 +1627,6 @@ int rrc_eNB_send_S1AP_E_RAB_MODIFY_RESP(const protocol_ctxt_t* const ctxt_pP,
   S1AP_E_RAB_MODIFY_RESP (msg_p).eNB_ue_s1ap_id = ue_context_pP->ue_context.eNB_ue_s1ap_id;
 
   for (e_rab = 0; e_rab < ue_context_pP->ue_context.nb_of_modify_e_rabs; e_rab++) {
-
     /* only respond to the corresponding transaction */
     if (xid == ue_context_pP->ue_context.modify_e_rab[e_rab].xid) {
       if (ue_context_pP->ue_context.modify_e_rab[e_rab].status == E_RAB_STATUS_DONE) {
@@ -1689,202 +1639,200 @@ int rrc_eNB_send_S1AP_E_RAB_MODIFY_RESP(const protocol_ctxt_t* const ctxt_pP,
             break;
           }
         }
+
         if (i < ue_context_pP->ue_context.setup_e_rabs) {
           S1AP_E_RAB_MODIFY_RESP (msg_p).e_rabs[e_rabs_done].e_rab_id = ue_context_pP->ue_context.modify_e_rab[e_rab].param.e_rab_id;
-              // TODO add other information from S1-U when it will be integrated
-
+          // TODO add other information from S1-U when it will be integrated
           LOG_D (RRC,"enb_gtp_addr (msg index %d, e_rab index %d, status %d, xid %d): nb_of_modify_e_rabs %d,  e_rab_id %d \n ",
-              e_rabs_done,  e_rab, ue_context_pP->ue_context.modify_e_rab[e_rab].status, xid,
-              ue_context_pP->ue_context.nb_of_modify_e_rabs,
-              S1AP_E_RAB_MODIFY_RESP (msg_p).e_rabs[e_rabs_done].e_rab_id);
-
+                 e_rabs_done,  e_rab, ue_context_pP->ue_context.modify_e_rab[e_rab].status, xid,
+                 ue_context_pP->ue_context.nb_of_modify_e_rabs,
+                 S1AP_E_RAB_MODIFY_RESP (msg_p).e_rabs[e_rabs_done].e_rab_id);
           e_rabs_done++;
         } else {
           // unexpected
           S1AP_E_RAB_MODIFY_RESP (msg_p).e_rabs_failed[e_rabs_failed].e_rab_id = ue_context_pP->ue_context.modify_e_rab[e_rab].param.e_rab_id;
-
           S1AP_E_RAB_MODIFY_RESP (msg_p).e_rabs_failed[e_rabs_failed].cause = S1AP_CAUSE_RADIO_NETWORK;
           S1AP_E_RAB_MODIFY_RESP (msg_p).e_rabs_failed[e_rabs_failed].cause_value = 30;//S1ap_CauseRadioNetwork_unknown_E_RAB_ID;
-
           e_rabs_failed++;
         }
       } else if ((ue_context_pP->ue_context.modify_e_rab[e_rab].status == E_RAB_STATUS_NEW) ||
-          (ue_context_pP->ue_context.modify_e_rab[e_rab].status == E_RAB_STATUS_ESTABLISHED)){
+                 (ue_context_pP->ue_context.modify_e_rab[e_rab].status == E_RAB_STATUS_ESTABLISHED)) {
         LOG_D (RRC,"E-RAB is NEW or already ESTABLISHED\n");
       } else {  /* status == E_RAB_STATUS_FAILED; */
         S1AP_E_RAB_MODIFY_RESP (msg_p).e_rabs_failed[e_rabs_failed].e_rab_id = ue_context_pP->ue_context.modify_e_rab[e_rab].param.e_rab_id;
         // add failure cause when defined
         S1AP_E_RAB_MODIFY_RESP (msg_p).e_rabs_failed[e_rabs_failed].cause = ue_context_pP->ue_context.modify_e_rab[e_rab].cause;
-
         e_rabs_failed++;
       }
     } else {
       /*debug info for the xid */
       LOG_D(RRC,"xid does not corresponds  (context e_rab index %d, status %d, xid %d/%d) \n ",
-             e_rab, ue_context_pP->ue_context.modify_e_rab[e_rab].status, xid, ue_context_pP->ue_context.modify_e_rab[e_rab].xid);
+            e_rab, ue_context_pP->ue_context.modify_e_rab[e_rab].status, xid, ue_context_pP->ue_context.modify_e_rab[e_rab].xid);
     }
   }
 
-
   S1AP_E_RAB_MODIFY_RESP (msg_p).nb_of_e_rabs = e_rabs_done;
   S1AP_E_RAB_MODIFY_RESP (msg_p).nb_of_e_rabs_failed = e_rabs_failed;
+
   // NN: add conditions for e_rabs_failed
   if (e_rabs_done > 0 || e_rabs_failed > 0) {
     LOG_D(RRC,"S1AP_E_RAB_MODIFY_RESP: sending the message: nb_of_modify_e_rabs %d, total e_rabs %d, index %d\n",
-    ue_context_pP->ue_context.nb_of_modify_e_rabs, ue_context_pP->ue_context.setup_e_rabs, e_rab);
-MSC_LOG_TX_MESSAGE(
-     MSC_RRC_ENB,
-     MSC_S1AP_ENB,
-     (const char *)&S1AP_E_RAB_SETUP_RESP (msg_p),
-     sizeof(s1ap_e_rab_setup_resp_t),
-     MSC_AS_TIME_FMT" E_RAB_MODIFY_RESP UE %X eNB_ue_s1ap_id %u e_rabs:%u succ %u fail",
-     MSC_AS_TIME_ARGS(ctxt_pP),
-     ue_context_pP->ue_id_rnti,
-     S1AP_E_RAB_MODIFY_RESP (msg_p).eNB_ue_s1ap_id,
-     e_rabs_done, e_rabs_failed);
-
+          ue_context_pP->ue_context.nb_of_modify_e_rabs, ue_context_pP->ue_context.setup_e_rabs, e_rab);
+    MSC_LOG_TX_MESSAGE(
+      MSC_RRC_ENB,
+      MSC_S1AP_ENB,
+      (const char *)&S1AP_E_RAB_SETUP_RESP (msg_p),
+      sizeof(s1ap_e_rab_setup_resp_t),
+      MSC_AS_TIME_FMT" E_RAB_MODIFY_RESP UE %X eNB_ue_s1ap_id %u e_rabs:%u succ %u fail",
+      MSC_AS_TIME_ARGS(ctxt_pP),
+      ue_context_pP->ue_id_rnti,
+      S1AP_E_RAB_MODIFY_RESP (msg_p).eNB_ue_s1ap_id,
+      e_rabs_done, e_rabs_failed);
     itti_send_msg_to_task (TASK_S1AP, ctxt_pP->instance, msg_p);
   }
 
   return 0;
 }
-int rrc_eNB_process_S1AP_E_RAB_RELEASE_COMMAND(MessageDef *msg_p, const char *msg_name, instance_t instance){
-    uint32_t                        eNB_ue_s1ap_id;
-    struct rrc_eNB_ue_context_s*    ue_context_p = NULL;
-    protocol_ctxt_t                 ctxt;
-    e_rab_release_t e_rab_release_params[S1AP_MAX_E_RAB];
-    uint8_t nb_e_rabs_torelease;
-    int erab;
-    int i;
-    uint8_t b_existed,is_existed;
-    uint8_t xid;
-    uint8_t e_rab_release_drb;
-    MessageDef *                    msg_delete_tunnels_p = NULL;
-    e_rab_release_drb = 0;
-    memcpy(&e_rab_release_params[0], &(S1AP_E_RAB_RELEASE_COMMAND (msg_p).e_rab_release_params[0]), sizeof(e_rab_release_t)*S1AP_MAX_E_RAB);
-
-    eNB_ue_s1ap_id = S1AP_E_RAB_RELEASE_COMMAND (msg_p).eNB_ue_s1ap_id;
-    nb_e_rabs_torelease = S1AP_E_RAB_RELEASE_COMMAND (msg_p).nb_e_rabs_torelease;
-    ue_context_p   = rrc_eNB_get_ue_context_from_s1ap_ids(instance, UE_INITIAL_ID_INVALID, eNB_ue_s1ap_id);
-    if(ue_context_p != NULL){
-        PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, ENB_FLAG_YES, ue_context_p->ue_context.rnti, 0, 0);
-
-        xid = rrc_eNB_get_next_transaction_identifier(ctxt.module_id);
-
-        LOG_D(RRC,"S1AP-E-RAB Release Command: MME_UE_S1AP_ID %d  ENB_UE_S1AP_ID %d release_e_rabs %d \n",
-            S1AP_E_RAB_RELEASE_COMMAND (msg_p).mme_ue_s1ap_id, eNB_ue_s1ap_id,nb_e_rabs_torelease);
-        for(erab = 0; erab < nb_e_rabs_torelease; erab++){
-            b_existed = 0;
-            is_existed = 0;
-            for ( i = erab-1;  i>= 0; i--){
-                if (e_rab_release_params[erab].e_rab_id == e_rab_release_params[i].e_rab_id){
-                    is_existed = 1;
-                    break;
-                }
-            }
-            if(is_existed == 1){
-                //e_rab_id is existed
-                continue;
-            }
-            for ( i = 0;  i < NB_RB_MAX; i++){
-                if (e_rab_release_params[erab].e_rab_id == ue_context_p->ue_context.e_rab[i].param.e_rab_id){
-                    b_existed = 1;
-                    break;
-                }
-            }
-            if(b_existed == 0) {
-                //no e_rab_id
-                ue_context_p->ue_context.e_rabs_release_failed[ue_context_p->ue_context.nb_release_of_e_rabs].e_rab_id = e_rab_release_params[erab].e_rab_id;
-                ue_context_p->ue_context.e_rabs_release_failed[ue_context_p->ue_context.nb_release_of_e_rabs].cause = S1AP_CAUSE_RADIO_NETWORK;
-                ue_context_p->ue_context.e_rabs_release_failed[ue_context_p->ue_context.nb_release_of_e_rabs].cause_value = 30;
-                ue_context_p->ue_context.nb_release_of_e_rabs++;
-            } else {
-                if(ue_context_p->ue_context.e_rab[i].status == E_RAB_STATUS_FAILED){
-                    ue_context_p->ue_context.e_rab[i].xid = xid;
-                    continue;
-                } else if(ue_context_p->ue_context.e_rab[i].status == E_RAB_STATUS_ESTABLISHED){
-                    ue_context_p->ue_context.e_rab[i].status = E_RAB_STATUS_TORELEASE;
-                    ue_context_p->ue_context.e_rab[i].xid = xid;
-                    e_rab_release_drb++;
-                }else{
-                    //e_rab_id status NG
-                    ue_context_p->ue_context.e_rabs_release_failed[ue_context_p->ue_context.nb_release_of_e_rabs].e_rab_id = e_rab_release_params[erab].e_rab_id;
-                    ue_context_p->ue_context.e_rabs_release_failed[ue_context_p->ue_context.nb_release_of_e_rabs].cause = S1AP_CAUSE_RADIO_NETWORK;
-                    ue_context_p->ue_context.e_rabs_release_failed[ue_context_p->ue_context.nb_release_of_e_rabs].cause_value = 0;
-                    ue_context_p->ue_context.nb_release_of_e_rabs++;
-                }
-            }
+int rrc_eNB_process_S1AP_E_RAB_RELEASE_COMMAND(MessageDef *msg_p, const char *msg_name, instance_t instance) {
+  uint32_t                        eNB_ue_s1ap_id;
+  struct rrc_eNB_ue_context_s    *ue_context_p = NULL;
+  protocol_ctxt_t                 ctxt;
+  e_rab_release_t e_rab_release_params[S1AP_MAX_E_RAB];
+  uint8_t nb_e_rabs_torelease;
+  int erab;
+  int i;
+  uint8_t b_existed,is_existed;
+  uint8_t xid;
+  uint8_t e_rab_release_drb;
+  MessageDef                     *msg_delete_tunnels_p = NULL;
+  e_rab_release_drb = 0;
+  memcpy(&e_rab_release_params[0], &(S1AP_E_RAB_RELEASE_COMMAND (msg_p).e_rab_release_params[0]), sizeof(e_rab_release_t)*S1AP_MAX_E_RAB);
+  eNB_ue_s1ap_id = S1AP_E_RAB_RELEASE_COMMAND (msg_p).eNB_ue_s1ap_id;
+  nb_e_rabs_torelease = S1AP_E_RAB_RELEASE_COMMAND (msg_p).nb_e_rabs_torelease;
+  ue_context_p   = rrc_eNB_get_ue_context_from_s1ap_ids(instance, UE_INITIAL_ID_INVALID, eNB_ue_s1ap_id);
+
+  if(ue_context_p != NULL) {
+    PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, ENB_FLAG_YES, ue_context_p->ue_context.rnti, 0, 0);
+    xid = rrc_eNB_get_next_transaction_identifier(ctxt.module_id);
+    LOG_D(RRC,"S1AP-E-RAB Release Command: MME_UE_S1AP_ID %d  ENB_UE_S1AP_ID %d release_e_rabs %d \n",
+          S1AP_E_RAB_RELEASE_COMMAND (msg_p).mme_ue_s1ap_id, eNB_ue_s1ap_id,nb_e_rabs_torelease);
+
+    for(erab = 0; erab < nb_e_rabs_torelease; erab++) {
+      b_existed = 0;
+      is_existed = 0;
+
+      for ( i = erab-1;  i>= 0; i--) {
+        if (e_rab_release_params[erab].e_rab_id == e_rab_release_params[i].e_rab_id) {
+          is_existed = 1;
+          break;
         }
-        if(e_rab_release_drb > 0) {
-            //RRCConnectionReconfiguration To UE
-            rrc_eNB_generate_dedicatedRRCConnectionReconfiguration_release(&ctxt, ue_context_p, xid, S1AP_E_RAB_RELEASE_COMMAND (msg_p).nas_pdu.length, S1AP_E_RAB_RELEASE_COMMAND (msg_p).nas_pdu.buffer);
-        } else {
-            //gtp tunnel delete
-            msg_delete_tunnels_p = itti_alloc_new_message(TASK_RRC_ENB, GTPV1U_ENB_DELETE_TUNNEL_REQ);
-            memset(&GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p), 0, sizeof(GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p)));
-            GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p).rnti = ue_context_p->ue_context.rnti;
-            for(i = 0; i < NB_RB_MAX; i++){
-               if(xid == ue_context_p->ue_context.e_rab[i].xid){
-                 GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p).eps_bearer_id[GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p).num_erab++] = ue_context_p->ue_context.enb_gtp_ebi[i];
-                 ue_context_p->ue_context.enb_gtp_teid[i] = 0;
-                 memset(&ue_context_p->ue_context.enb_gtp_addrs[i], 0, sizeof(ue_context_p->ue_context.enb_gtp_addrs[i]));
-                 ue_context_p->ue_context.enb_gtp_ebi[i]  = 0;
-               }
-            }
+      }
 
-            itti_send_msg_to_task(TASK_GTPV1_U, instance, msg_delete_tunnels_p);
+      if(is_existed == 1) {
+        //e_rab_id is existed
+        continue;
+      }
 
-            //S1AP_E_RAB_RELEASE_RESPONSE
-            rrc_eNB_send_S1AP_E_RAB_RELEASE_RESPONSE(&ctxt, ue_context_p, xid);
+      for ( i = 0;  i < NB_RB_MAX; i++) {
+        if (e_rab_release_params[erab].e_rab_id == ue_context_p->ue_context.e_rab[i].param.e_rab_id) {
+          b_existed = 1;
+          break;
+        }
+      }
+
+      if(b_existed == 0) {
+        //no e_rab_id
+        ue_context_p->ue_context.e_rabs_release_failed[ue_context_p->ue_context.nb_release_of_e_rabs].e_rab_id = e_rab_release_params[erab].e_rab_id;
+        ue_context_p->ue_context.e_rabs_release_failed[ue_context_p->ue_context.nb_release_of_e_rabs].cause = S1AP_CAUSE_RADIO_NETWORK;
+        ue_context_p->ue_context.e_rabs_release_failed[ue_context_p->ue_context.nb_release_of_e_rabs].cause_value = 30;
+        ue_context_p->ue_context.nb_release_of_e_rabs++;
+      } else {
+        if(ue_context_p->ue_context.e_rab[i].status == E_RAB_STATUS_FAILED) {
+          ue_context_p->ue_context.e_rab[i].xid = xid;
+          continue;
+        } else if(ue_context_p->ue_context.e_rab[i].status == E_RAB_STATUS_ESTABLISHED) {
+          ue_context_p->ue_context.e_rab[i].status = E_RAB_STATUS_TORELEASE;
+          ue_context_p->ue_context.e_rab[i].xid = xid;
+          e_rab_release_drb++;
+        } else {
+          //e_rab_id status NG
+          ue_context_p->ue_context.e_rabs_release_failed[ue_context_p->ue_context.nb_release_of_e_rabs].e_rab_id = e_rab_release_params[erab].e_rab_id;
+          ue_context_p->ue_context.e_rabs_release_failed[ue_context_p->ue_context.nb_release_of_e_rabs].cause = S1AP_CAUSE_RADIO_NETWORK;
+          ue_context_p->ue_context.e_rabs_release_failed[ue_context_p->ue_context.nb_release_of_e_rabs].cause_value = 0;
+          ue_context_p->ue_context.nb_release_of_e_rabs++;
         }
+      }
+    }
+
+    if(e_rab_release_drb > 0) {
+      //RRCConnectionReconfiguration To UE
+      rrc_eNB_generate_dedicatedRRCConnectionReconfiguration_release(&ctxt, ue_context_p, xid, S1AP_E_RAB_RELEASE_COMMAND (msg_p).nas_pdu.length, S1AP_E_RAB_RELEASE_COMMAND (msg_p).nas_pdu.buffer);
     } else {
-        LOG_E(RRC,"S1AP-E-RAB Release Command: MME_UE_S1AP_ID %d  ENB_UE_S1AP_ID %d  Error ue_context_p NULL \n",
-            S1AP_E_RAB_RELEASE_COMMAND (msg_p).mme_ue_s1ap_id, S1AP_E_RAB_RELEASE_COMMAND (msg_p).eNB_ue_s1ap_id);
-         return -1;
+      //gtp tunnel delete
+      msg_delete_tunnels_p = itti_alloc_new_message(TASK_RRC_ENB, GTPV1U_ENB_DELETE_TUNNEL_REQ);
+      memset(&GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p), 0, sizeof(GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p)));
+      GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p).rnti = ue_context_p->ue_context.rnti;
+
+      for(i = 0; i < NB_RB_MAX; i++) {
+        if(xid == ue_context_p->ue_context.e_rab[i].xid) {
+          GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p).eps_bearer_id[GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p).num_erab++] = ue_context_p->ue_context.enb_gtp_ebi[i];
+          ue_context_p->ue_context.enb_gtp_teid[i] = 0;
+          memset(&ue_context_p->ue_context.enb_gtp_addrs[i], 0, sizeof(ue_context_p->ue_context.enb_gtp_addrs[i]));
+          ue_context_p->ue_context.enb_gtp_ebi[i]  = 0;
+        }
+      }
+
+      itti_send_msg_to_task(TASK_GTPV1_U, instance, msg_delete_tunnels_p);
+      //S1AP_E_RAB_RELEASE_RESPONSE
+      rrc_eNB_send_S1AP_E_RAB_RELEASE_RESPONSE(&ctxt, ue_context_p, xid);
     }
+  } else {
+    LOG_E(RRC,"S1AP-E-RAB Release Command: MME_UE_S1AP_ID %d  ENB_UE_S1AP_ID %d  Error ue_context_p NULL \n",
+          S1AP_E_RAB_RELEASE_COMMAND (msg_p).mme_ue_s1ap_id, S1AP_E_RAB_RELEASE_COMMAND (msg_p).eNB_ue_s1ap_id);
+    return -1;
+  }
 
-    return 0;
+  return 0;
 }
 
 
-int rrc_eNB_send_S1AP_E_RAB_RELEASE_RESPONSE(const protocol_ctxt_t* const ctxt_pP, rrc_eNB_ue_context_t* const ue_context_pP, uint8_t xid){
-    int e_rabs_released = 0;
-    MessageDef   *msg_p;
+int rrc_eNB_send_S1AP_E_RAB_RELEASE_RESPONSE(const protocol_ctxt_t *const ctxt_pP, rrc_eNB_ue_context_t *const ue_context_pP, uint8_t xid) {
+  int e_rabs_released = 0;
+  MessageDef   *msg_p;
+  msg_p = itti_alloc_new_message (TASK_RRC_ENB, S1AP_E_RAB_RELEASE_RESPONSE);
+  S1AP_E_RAB_RELEASE_RESPONSE (msg_p).eNB_ue_s1ap_id = ue_context_pP->ue_context.eNB_ue_s1ap_id;
 
-    msg_p = itti_alloc_new_message (TASK_RRC_ENB, S1AP_E_RAB_RELEASE_RESPONSE);
-    S1AP_E_RAB_RELEASE_RESPONSE (msg_p).eNB_ue_s1ap_id = ue_context_pP->ue_context.eNB_ue_s1ap_id;
-    
-    for (int i = 0;  i < NB_RB_MAX; i++){
-        if (xid == ue_context_pP->ue_context.e_rab[i].xid){
-            S1AP_E_RAB_RELEASE_RESPONSE (msg_p).e_rab_release[e_rabs_released].e_rab_id = ue_context_pP->ue_context.e_rab[i].param.e_rab_id;
-            e_rabs_released++;
-            //clear
-            memset(&ue_context_pP->ue_context.e_rab[i],0,sizeof(e_rab_param_t));
-        }
-    }
-    S1AP_E_RAB_RELEASE_RESPONSE (msg_p).nb_of_e_rabs_released = e_rabs_released;
-    S1AP_E_RAB_RELEASE_RESPONSE (msg_p).nb_of_e_rabs_failed = ue_context_pP->ue_context.nb_release_of_e_rabs;
-    memcpy(&(S1AP_E_RAB_RELEASE_RESPONSE (msg_p).e_rabs_failed[0]),&ue_context_pP->ue_context.e_rabs_release_failed[0],sizeof(e_rab_failed_t)*ue_context_pP->ue_context.nb_release_of_e_rabs);
-
-    ue_context_pP->ue_context.setup_e_rabs -= e_rabs_released;
-    LOG_I(RRC,"S1AP-E-RAB RELEASE RESPONSE: ENB_UE_S1AP_ID %d release_e_rabs %d setup_e_rabs %d \n",
-              S1AP_E_RAB_RELEASE_RESPONSE (msg_p).eNB_ue_s1ap_id,
-              e_rabs_released, ue_context_pP->ue_context.setup_e_rabs);
-    
-    itti_send_msg_to_task (TASK_S1AP, ctxt_pP->instance, msg_p);
-    //clear xid
-    for(int i = 0; i < NB_RB_MAX; i++) {
-        ue_context_pP->ue_context.e_rab[i].xid = -1;
+  for (int i = 0;  i < NB_RB_MAX; i++) {
+    if (xid == ue_context_pP->ue_context.e_rab[i].xid) {
+      S1AP_E_RAB_RELEASE_RESPONSE (msg_p).e_rab_release[e_rabs_released].e_rab_id = ue_context_pP->ue_context.e_rab[i].param.e_rab_id;
+      e_rabs_released++;
+      //clear
+      memset(&ue_context_pP->ue_context.e_rab[i],0,sizeof(e_rab_param_t));
     }
-    //clear release e_rabs
-    ue_context_pP->ue_context.nb_release_of_e_rabs = 0;
-    memset(&ue_context_pP->ue_context.e_rabs_release_failed[0],0,sizeof(e_rab_failed_t)*S1AP_MAX_E_RAB);
-    return 0;
+  }
+
+  S1AP_E_RAB_RELEASE_RESPONSE (msg_p).nb_of_e_rabs_released = e_rabs_released;
+  S1AP_E_RAB_RELEASE_RESPONSE (msg_p).nb_of_e_rabs_failed = ue_context_pP->ue_context.nb_release_of_e_rabs;
+  memcpy(&(S1AP_E_RAB_RELEASE_RESPONSE (msg_p).e_rabs_failed[0]),&ue_context_pP->ue_context.e_rabs_release_failed[0],sizeof(e_rab_failed_t)*ue_context_pP->ue_context.nb_release_of_e_rabs);
+  ue_context_pP->ue_context.setup_e_rabs -= e_rabs_released;
+  LOG_I(RRC,"S1AP-E-RAB RELEASE RESPONSE: ENB_UE_S1AP_ID %d release_e_rabs %d setup_e_rabs %d \n",
+        S1AP_E_RAB_RELEASE_RESPONSE (msg_p).eNB_ue_s1ap_id,
+        e_rabs_released, ue_context_pP->ue_context.setup_e_rabs);
+  itti_send_msg_to_task (TASK_S1AP, ctxt_pP->instance, msg_p);
+
+  //clear xid
+  for(int i = 0; i < NB_RB_MAX; i++) {
+    ue_context_pP->ue_context.e_rab[i].xid = -1;
+  }
+
+  //clear release e_rabs
+  ue_context_pP->ue_context.nb_release_of_e_rabs = 0;
+  memset(&ue_context_pP->ue_context.e_rabs_release_failed[0],0,sizeof(e_rab_failed_t)*S1AP_MAX_E_RAB);
+  return 0;
 }
 
 /*------------------------------------------------------------------------------*/
-int rrc_eNB_process_PAGING_IND(MessageDef *msg_p, const char *msg_name, instance_t instance)
-{
+int rrc_eNB_process_PAGING_IND(MessageDef *msg_p, const char *msg_name, instance_t instance) {
   const unsigned int Ttab[4] = {32,64,128,256};
   uint8_t Tc,Tue;  /* DRX cycle of UE */
   uint32_t pcch_nB;  /* 4T, 2T, T, T/2, T/4, T/8, T/16, T/32 */
@@ -1892,136 +1840,380 @@ int rrc_eNB_process_PAGING_IND(MessageDef *msg_p, const char *msg_name, instance
   uint32_t Ns = 0;  /* Ns: max(1,nB/T) */
   uint8_t i_s;  /* i_s = floor(UE_ID/N) mod Ns */
   uint32_t T;  /* DRX cycle */
+
   for (uint16_t tai_size = 0; tai_size < S1AP_PAGING_IND(msg_p).tai_size; tai_size++) {
-       LOG_D(RRC,"[eNB %d] In S1AP_PAGING_IND: MCC %d, MNC %d, TAC %d\n", instance, S1AP_PAGING_IND(msg_p).plmn_identity[tai_size].mcc,
-             S1AP_PAGING_IND(msg_p).plmn_identity[tai_size].mnc, S1AP_PAGING_IND(msg_p).tac[tai_size]);
-      for (uint8_t j = 0; j < RC.rrc[instance]->configuration.num_plmn; j++) {
-          if (RC.rrc[instance]->configuration.mcc[j] == S1AP_PAGING_IND(msg_p).plmn_identity[tai_size].mcc
-              && RC.rrc[instance]->configuration.mnc[j] == S1AP_PAGING_IND(msg_p).plmn_identity[tai_size].mnc
-              && RC.rrc[instance]->configuration.tac == S1AP_PAGING_IND(msg_p).tac[tai_size]) {
-              for (uint8_t CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
-                  lte_frame_type_t frame_type = RC.eNB[instance][CC_id]->frame_parms.frame_type;
-                  /* get nB from configuration */
-                  /* get default DRX cycle from configuration */
-                  Tc = (uint8_t)RC.rrc[instance]->configuration.pcch_defaultPagingCycle[CC_id];
-                  if (Tc < PCCH_Config__defaultPagingCycle_rf32 || Tc > PCCH_Config__defaultPagingCycle_rf256) {
-                      continue;
-                  }
-                  Tue = (uint8_t)S1AP_PAGING_IND(msg_p).paging_drx;
-                  /* set T = min(Tc,Tue) */
-                  T = Tc < Tue ? Ttab[Tc] : Ttab[Tue];
-                  /* set pcch_nB = PCCH-Config->nB */
-                  pcch_nB = (uint32_t)RC.rrc[instance]->configuration.pcch_nB[CC_id];
-                  switch (pcch_nB) {
-                    case PCCH_Config__nB_fourT:
-                        Ns = 4;
-                        break;
-                    case PCCH_Config__nB_twoT:
-                        Ns = 2;
-                        break;
-                    default:
-                        Ns = 1;
-                        break;
-                  }
-                  /* set N = min(T,nB) */
-                  if (pcch_nB > PCCH_Config__nB_oneT) {
-                    switch (pcch_nB) {
-                    case PCCH_Config__nB_halfT:
-                      N = T/2;
-                      break;
-                    case PCCH_Config__nB_quarterT:
-                      N = T/4;
-                      break;
-                    case PCCH_Config__nB_oneEighthT:
-                      N = T/8;
-                      break;
-                    case PCCH_Config__nB_oneSixteenthT:
-                      N = T/16;
-                      break;
-                    case PCCH_Config__nB_oneThirtySecondT:
-                      N = T/32;
-                      break;
-                    default:
-                      /* pcch_nB error */
-                      LOG_E(RRC, "[eNB %d] In S1AP_PAGING_IND:  pcch_nB error (pcch_nB %d) \n",
-                          instance, pcch_nB);
-                      return (-1);
-                    }
-                  } else {
-                    N = T;
-                  }
-
-                  /* insert data to UE_PF_PO or update data in UE_PF_PO */
-                  pthread_mutex_lock(&ue_pf_po_mutex);
-                  uint8_t i = 0;
-                  for (i = 0; i < MAX_MOBILES_PER_ENB; i++) {
-                    if ((UE_PF_PO[CC_id][i].enable_flag == TRUE && UE_PF_PO[CC_id][i].ue_index_value == (uint16_t)(S1AP_PAGING_IND(msg_p).ue_index_value))
-                        || (UE_PF_PO[CC_id][i].enable_flag != TRUE)) {
-                        /* set T = min(Tc,Tue) */
-                        UE_PF_PO[CC_id][i].T = T;
-                        /* set UE_ID */
-                        UE_PF_PO[CC_id][i].ue_index_value = (uint16_t)S1AP_PAGING_IND(msg_p).ue_index_value;
-                        /* calculate PF and PO */
-                        /* set PF_min : SFN mod T = (T div N)*(UE_ID mod N) */
-                        UE_PF_PO[CC_id][i].PF_min = (T / N) * (UE_PF_PO[CC_id][i].ue_index_value % N);
-                        /* set PO */
-                        /* i_s = floor(UE_ID/N) mod Ns */
-                        i_s = (uint8_t)((UE_PF_PO[CC_id][i].ue_index_value / N) % Ns);
-                        if (Ns == 1) {
-                            UE_PF_PO[CC_id][i].PO = (frame_type==FDD) ? 9 : 0;
-                        } else if (Ns==2) {
-                            UE_PF_PO[CC_id][i].PO = (frame_type==FDD) ? (4+(5*i_s)) : (5*i_s);
-                        } else if (Ns==4) {
-                            UE_PF_PO[CC_id][i].PO = (frame_type==FDD) ? (4*(i_s&1)+(5*(i_s>>1))) : ((i_s&1)+(5*(i_s>>1)));
-                        }
-                        if (UE_PF_PO[CC_id][i].enable_flag == TRUE) {
-                            //paging exist UE log
-                            LOG_D(RRC,"[eNB %d] CC_id %d In S1AP_PAGING_IND: Update exist UE %d, T %d, PF %d, PO %d\n", instance, CC_id, UE_PF_PO[CC_id][i].ue_index_value, T, UE_PF_PO[CC_id][i].PF_min, UE_PF_PO[CC_id][i].PO);
-                        } else {
-                            /* set enable_flag */
-                            UE_PF_PO[CC_id][i].enable_flag = TRUE;
-                            //paging new UE log
-                            LOG_D(RRC,"[eNB %d] CC_id %d In S1AP_PAGING_IND: Insert a new UE %d, T %d, PF %d, PO %d\n", instance, CC_id, UE_PF_PO[CC_id][i].ue_index_value, T, UE_PF_PO[CC_id][i].PF_min, UE_PF_PO[CC_id][i].PO);
-                        }
-                        break;
-                    }
-                  }
-                  pthread_mutex_unlock(&ue_pf_po_mutex);
-
-                  uint32_t length;
-                  uint8_t buffer[RRC_BUF_SIZE];
-                  uint8_t *message_buffer;
-                  /* Transfer data to PDCP */
-                  MessageDef *message_p;
-                  message_p = itti_alloc_new_message (TASK_RRC_ENB, RRC_PCCH_DATA_REQ);
-                  /* Create message for PDCP (DLInformationTransfer_t) */
-                  length = do_Paging (instance,
-                                      buffer,
-                                      S1AP_PAGING_IND(msg_p).ue_paging_identity,
-                                      S1AP_PAGING_IND(msg_p).cn_domain);
-                  if(length == -1)
-                  {
-                    LOG_I(RRC, "do_Paging error");
-                    return -1;
-                  }
-                  message_buffer = itti_malloc (TASK_RRC_ENB, TASK_PDCP_ENB, length);
-                  /* Uses a new buffer to avoid issue with PDCP buffer content that could be changed by PDCP (asynchronous message handling). */
-                  memcpy (message_buffer, buffer, length);
-                  RRC_PCCH_DATA_REQ (message_p).sdu_size  = length;
-                  RRC_PCCH_DATA_REQ (message_p).sdu_p     = message_buffer;
-                  RRC_PCCH_DATA_REQ (message_p).mode      = PDCP_TRANSMISSION_MODE_TRANSPARENT;  /* not used */
-                  RRC_PCCH_DATA_REQ (message_p).rnti      = P_RNTI;
-                  RRC_PCCH_DATA_REQ (message_p).ue_index  = i;
-                  RRC_PCCH_DATA_REQ (message_p).CC_id  = CC_id;
-                  LOG_D(RRC, "[eNB %d] CC_id %d In S1AP_PAGING_IND: send encdoed buffer to PDCP buffer_size %d\n", instance, CC_id, length);
-                  itti_send_msg_to_task (TASK_PDCP_ENB, instance, message_p);
+
+    LOG_D(RRC,"[eNB %d] In S1AP_PAGING_IND: MCC %d, MNC %d, TAC %d\n", instance, S1AP_PAGING_IND(msg_p).plmn_identity[tai_size].mcc,
+          S1AP_PAGING_IND(msg_p).plmn_identity[tai_size].mnc, S1AP_PAGING_IND(msg_p).tac[tai_size]);
+
+    for (uint8_t j = 0; j < RC.rrc[instance]->configuration.num_plmn; j++) {
+      if (RC.rrc[instance]->configuration.mcc[j] == S1AP_PAGING_IND(msg_p).plmn_identity[tai_size].mcc
+          && RC.rrc[instance]->configuration.mnc[j] == S1AP_PAGING_IND(msg_p).plmn_identity[tai_size].mnc
+          && RC.rrc[instance]->configuration.tac == S1AP_PAGING_IND(msg_p).tac[tai_size]) {
+        for (uint8_t CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
+          lte_frame_type_t frame_type = RC.eNB[instance][CC_id]->frame_parms.frame_type;
+          /* get nB from configuration */
+          /* get default DRX cycle from configuration */
+          Tc = (uint8_t)RC.rrc[instance]->configuration.radioresourceconfig[CC_id].pcch_defaultPagingCycle;
+
+          if (Tc < LTE_PCCH_Config__defaultPagingCycle_rf32 || Tc > LTE_PCCH_Config__defaultPagingCycle_rf256) {
+            continue;
+          }
+
+          Tue = (uint8_t)S1AP_PAGING_IND(msg_p).paging_drx;
+          /* set T = min(Tc,Tue) */
+          T = Tc < Tue ? Ttab[Tc] : Ttab[Tue];
+          /* set pcch_nB = PCCH-Config->nB */
+	  pcch_nB = (uint32_t)RC.rrc[instance]->configuration.radioresourceconfig[CC_id].pcch_nB;
+          switch (pcch_nB) {
+            case LTE_PCCH_Config__nB_fourT:
+              Ns = 4;
+              break;
+
+            case LTE_PCCH_Config__nB_twoT:
+              Ns = 2;
+              break;
+
+            default:
+              Ns = 1;
+              break;
+          }
+
+          /* set N = min(T,nB) */
+          if (pcch_nB > LTE_PCCH_Config__nB_oneT) {
+            switch (pcch_nB) {
+              case LTE_PCCH_Config__nB_halfT:
+                N = T/2;
+                break;
+
+              case LTE_PCCH_Config__nB_quarterT:
+                N = T/4;
+                break;
+
+              case LTE_PCCH_Config__nB_oneEighthT:
+                N = T/8;
+                break;
+
+              case LTE_PCCH_Config__nB_oneSixteenthT:
+                N = T/16;
+                break;
+
+              case LTE_PCCH_Config__nB_oneThirtySecondT:
+                N = T/32;
+                break;
+
+              default:
+                /* pcch_nB error */
+                LOG_E(RRC, "[eNB %d] In S1AP_PAGING_IND:  pcch_nB error (pcch_nB %d) \n",
+                      instance, pcch_nB);
+                return (-1);
+            }
+          } else {
+            N = T;
+          }
+
+          /* insert data to UE_PF_PO or update data in UE_PF_PO */
+          pthread_mutex_lock(&ue_pf_po_mutex);
+          uint8_t i = 0;
+
+          for (i = 0; i < MAX_MOBILES_PER_ENB; i++) {
+            if ((UE_PF_PO[CC_id][i].enable_flag == TRUE && UE_PF_PO[CC_id][i].ue_index_value == (uint16_t)(S1AP_PAGING_IND(msg_p).ue_index_value))
+                || (UE_PF_PO[CC_id][i].enable_flag != TRUE)) {
+              /* set T = min(Tc,Tue) */
+              UE_PF_PO[CC_id][i].T = T;
+              /* set UE_ID */
+              UE_PF_PO[CC_id][i].ue_index_value = (uint16_t)S1AP_PAGING_IND(msg_p).ue_index_value;
+              /* calculate PF and PO */
+              /* set PF_min : SFN mod T = (T div N)*(UE_ID mod N) */
+              UE_PF_PO[CC_id][i].PF_min = (T / N) * (UE_PF_PO[CC_id][i].ue_index_value % N);
+              /* set PO */
+              /* i_s = floor(UE_ID/N) mod Ns */
+              i_s = (uint8_t)((UE_PF_PO[CC_id][i].ue_index_value / N) % Ns);
+
+              if (Ns == 1) {
+                UE_PF_PO[CC_id][i].PO = (frame_type==FDD) ? 9 : 0;
+              } else if (Ns==2) {
+                UE_PF_PO[CC_id][i].PO = (frame_type==FDD) ? (4+(5*i_s)) : (5*i_s);
+              } else if (Ns==4) {
+                UE_PF_PO[CC_id][i].PO = (frame_type==FDD) ? (4*(i_s&1)+(5*(i_s>>1))) : ((i_s&1)+(5*(i_s>>1)));
+              }
+
+              if (UE_PF_PO[CC_id][i].enable_flag == TRUE) {
+                //paging exist UE log
+                LOG_D(RRC,"[eNB %d] CC_id %d In S1AP_PAGING_IND: Update exist UE %d, T %d, PF %d, PO %d\n", instance, CC_id, UE_PF_PO[CC_id][i].ue_index_value, T, UE_PF_PO[CC_id][i].PF_min, UE_PF_PO[CC_id][i].PO);
+              } else {
+                /* set enable_flag */
+                UE_PF_PO[CC_id][i].enable_flag = TRUE;
+                //paging new UE log
+                LOG_D(RRC,"[eNB %d] CC_id %d In S1AP_PAGING_IND: Insert a new UE %d, T %d, PF %d, PO %d\n", instance, CC_id, UE_PF_PO[CC_id][i].ue_index_value, T, UE_PF_PO[CC_id][i].PF_min, UE_PF_PO[CC_id][i].PO);
               }
+
+              break;
+            }
           }
+
+          pthread_mutex_unlock(&ue_pf_po_mutex);
+          uint32_t length;
+          uint8_t buffer[RRC_BUF_SIZE];
+          uint8_t *message_buffer;
+          /* Transfer data to PDCP */
+          MessageDef *message_p;
+          message_p = itti_alloc_new_message (TASK_RRC_ENB, RRC_PCCH_DATA_REQ);
+          /* Create message for PDCP (DLInformationTransfer_t) */
+          length = do_Paging (instance,
+                              buffer,
+                              S1AP_PAGING_IND(msg_p).ue_paging_identity,
+                              S1AP_PAGING_IND(msg_p).cn_domain);
+
+          if(length == -1) {
+            LOG_I(RRC, "do_Paging error");
+            return -1;
+          }
+
+          message_buffer = itti_malloc (TASK_RRC_ENB, TASK_PDCP_ENB, length);
+          /* Uses a new buffer to avoid issue with PDCP buffer content that could be changed by PDCP (asynchronous message handling). */
+          memcpy (message_buffer, buffer, length);
+          RRC_PCCH_DATA_REQ (message_p).sdu_size  = length;
+          RRC_PCCH_DATA_REQ (message_p).sdu_p     = message_buffer;
+          RRC_PCCH_DATA_REQ (message_p).mode      = PDCP_TRANSMISSION_MODE_TRANSPARENT;  /* not used */
+          RRC_PCCH_DATA_REQ (message_p).rnti      = P_RNTI;
+          RRC_PCCH_DATA_REQ (message_p).ue_index  = i;
+          RRC_PCCH_DATA_REQ (message_p).CC_id  = CC_id;
+          LOG_D(RRC, "[eNB %d] CC_id %d In S1AP_PAGING_IND: send encdoed buffer to PDCP buffer_size %d\n", instance, CC_id, length);
+          itti_send_msg_to_task (TASK_PDCP_ENB, instance, message_p);
+        }
       }
+    }
   }
 
   return (0);
 }
 
+/*NN: careful about the typcast of xid (long -> uint8_t*/
+int rrc_eNB_send_PATH_SWITCH_REQ(const protocol_ctxt_t* const ctxt_pP,
+				  rrc_eNB_ue_context_t*          const ue_context_pP){
+
+  MessageDef      *msg_p         = NULL;
+  int e_rab = 0;
+  int e_rabs_done = 0;
+
+  rrc_ue_s1ap_ids_t*  rrc_ue_s1ap_ids_p = NULL;
+  hashtable_rc_t      h_rc;
+
+  gtpv1u_enb_create_tunnel_req_t  create_tunnel_req;
+  gtpv1u_enb_create_tunnel_resp_t create_tunnel_resp;
+
+  uint8_t inde_list[ue_context_pP->ue_context.nb_of_e_rabs];
+  memset(inde_list, 0, ue_context_pP->ue_context.nb_of_e_rabs*sizeof(uint8_t));
+
+  msg_p = itti_alloc_new_message (TASK_RRC_ENB, S1AP_PATH_SWITCH_REQ);
+
+  ue_context_pP->ue_context.ue_initial_id = get_next_ue_initial_id (ctxt_pP->module_id);
+  S1AP_PATH_SWITCH_REQ (msg_p).ue_initial_id = ue_context_pP->ue_context.ue_initial_id;
+
+  rrc_ue_s1ap_ids_p = malloc(sizeof(*rrc_ue_s1ap_ids_p));
+  rrc_ue_s1ap_ids_p->ue_initial_id  = ue_context_pP->ue_context.ue_initial_id;
+  rrc_ue_s1ap_ids_p->eNB_ue_s1ap_id = UE_INITIAL_ID_INVALID;
+  rrc_ue_s1ap_ids_p->ue_rnti        = ctxt_pP->rnti;
+
+  h_rc = hashtable_insert(RC.rrc[ctxt_pP->module_id]->initial_id2_s1ap_ids,
+		               (hash_key_t)ue_context_pP->ue_context.ue_initial_id,
+                               rrc_ue_s1ap_ids_p);
+  if (h_rc != HASH_TABLE_OK) {
+    LOG_E(S1AP, "[eNB %d] Error while hashtable_insert in initial_id2_s1ap_ids ue_initial_id %u\n",
+	  ctxt_pP->module_id, ue_context_pP->ue_context.ue_initial_id);
+  }
+
+  S1AP_PATH_SWITCH_REQ (msg_p).eNB_ue_s1ap_id = ue_context_pP->ue_context.eNB_ue_s1ap_id;
+
+  S1AP_PATH_SWITCH_REQ (msg_p).mme_ue_s1ap_id = ue_context_pP->ue_context.mme_ue_s1ap_id;
+
+  S1AP_PATH_SWITCH_REQ (msg_p).ue_gummei.mcc = ue_context_pP->ue_context.ue_gummei.mcc;
+  S1AP_PATH_SWITCH_REQ (msg_p).ue_gummei.mnc = ue_context_pP->ue_context.ue_gummei.mnc;
+  S1AP_PATH_SWITCH_REQ (msg_p).ue_gummei.mnc_len = ue_context_pP->ue_context.ue_gummei.mnc_len;
+  S1AP_PATH_SWITCH_REQ (msg_p).ue_gummei.mme_code = ue_context_pP->ue_context.ue_gummei.mme_code;
+  S1AP_PATH_SWITCH_REQ (msg_p).ue_gummei.mme_group_id = ue_context_pP->ue_context.ue_gummei.mme_group_id;
+
+  S1AP_PATH_SWITCH_REQ (msg_p).security_capabilities.encryption_algorithms=ue_context_pP->ue_context.security_capabilities.encryption_algorithms;
+  S1AP_PATH_SWITCH_REQ (msg_p).security_capabilities.integrity_algorithms=ue_context_pP->ue_context.security_capabilities.integrity_algorithms;
+
+  LOG_I (RRC,"Path switch request: nb nb_of_e_rabs %u status %u\n",
+          ue_context_pP->ue_context.nb_of_e_rabs,
+          ue_context_pP->ue_context.e_rab[e_rab].status);
+
+  memset(&create_tunnel_req, 0 , sizeof(create_tunnel_req));
+  // the context for UE to be handovered is obtained through ho_req message
+  for (e_rab = 0; e_rab <  ue_context_pP->ue_context.nb_of_e_rabs ; e_rab++) {
+
+    if (ue_context_pP->ue_context.e_rab[e_rab].status == E_RAB_STATUS_ESTABLISHED) {
+
+      create_tunnel_req.eps_bearer_id[e_rabs_done]       = ue_context_pP->ue_context.e_rab[e_rab].param.e_rab_id;
+      create_tunnel_req.sgw_S1u_teid[e_rabs_done]        = ue_context_pP->ue_context.e_rab[e_rab].param.gtp_teid;
+      memcpy(&create_tunnel_req.sgw_addr[e_rabs_done],
+             &ue_context_pP->ue_context.e_rab[e_rab].param.sgw_addr,
+             sizeof(transport_layer_addr_t));
+
+      inde_list[e_rabs_done] = e_rab;
+      e_rabs_done++;
+    }
+  }
+
+  S1AP_PATH_SWITCH_REQ (msg_p).nb_of_e_rabs = e_rabs_done;
+
+  create_tunnel_req.rnti           = ue_context_pP->ue_context.rnti;
+  create_tunnel_req.num_tunnels    = e_rabs_done;
+
+  gtpv1u_create_s1u_tunnel(
+      ctxt_pP->instance,
+      &create_tunnel_req,
+      &create_tunnel_resp);
+
+  rrc_eNB_process_GTPV1U_CREATE_TUNNEL_RESP(
+        ctxt_pP,
+        &create_tunnel_resp,
+        &inde_list[0]);
+
+  for (e_rab = 0; e_rab < e_rabs_done; e_rab++) {
+
+      S1AP_PATH_SWITCH_REQ (msg_p).e_rabs_tobeswitched[e_rab].e_rab_id = create_tunnel_resp.eps_bearer_id[e_rab];
+      S1AP_PATH_SWITCH_REQ (msg_p).e_rabs_tobeswitched[e_rab].gtp_teid = create_tunnel_resp.enb_S1u_teid[e_rab];
+      S1AP_PATH_SWITCH_REQ (msg_p).e_rabs_tobeswitched[e_rab].eNB_addr = create_tunnel_resp.enb_addr;
+
+      LOG_I (RRC,"enb_gtp_addr (msg index %d, e_rab index %d, status %d): nb_of_e_rabs %d,  e_rab_id %d, teid: %u, addr: %d.%d.%d.%d \n ",
+	     e_rabs_done,  e_rab, ue_context_pP->ue_context.e_rab[inde_list[e_rab]].status,
+	     ue_context_pP->ue_context.nb_of_e_rabs,
+	     S1AP_PATH_SWITCH_REQ (msg_p).e_rabs_tobeswitched[e_rab].e_rab_id,
+	     S1AP_PATH_SWITCH_REQ (msg_p).e_rabs_tobeswitched[e_rab].gtp_teid,
+	     S1AP_PATH_SWITCH_REQ (msg_p).e_rabs_tobeswitched[e_rab].eNB_addr.buffer[0],
+	     S1AP_PATH_SWITCH_REQ (msg_p).e_rabs_tobeswitched[e_rab].eNB_addr.buffer[1],
+	     S1AP_PATH_SWITCH_REQ (msg_p).e_rabs_tobeswitched[e_rab].eNB_addr.buffer[2],
+	     S1AP_PATH_SWITCH_REQ (msg_p).e_rabs_tobeswitched[e_rab].eNB_addr.buffer[3]);
+  }
+
+    // NN: add conditions for e_rabs_failed
+    if (e_rabs_done > 0) {
+
+      LOG_I(RRC,"S1AP_PATH_SWITCH_REQ: sending the message: nb_of_erabstobeswitched %d, total e_rabs %d, index %d\n",
+	    ue_context_pP->ue_context.nb_of_e_rabs, ue_context_pP->ue_context.setup_e_rabs, e_rab);
+
+      MSC_LOG_TX_MESSAGE(
+			 MSC_RRC_ENB,
+			 MSC_S1AP_ENB,
+			 (const char *)&S1AP_PATH_SWITCH_REQ (msg_p),
+			 sizeof(s1ap_path_switch_req_t),
+			 MSC_AS_TIME_FMT" PATH_SWITCH_REQ UE %X eNB_ue_s1ap_id %u e_rabs:%u succ",
+			 MSC_AS_TIME_ARGS(ctxt_pP),
+			 ue_context_pP->ue_id_rnti,
+			 S1AP_PATH_SWITCH_REQ (msg_p).eNB_ue_s1ap_id,
+			 e_rabs_done);
+
+
+	itti_send_msg_to_task (TASK_S1AP, ctxt_pP->instance, msg_p);
+     }
+
+  return 0;
+}
+
+int rrc_eNB_process_S1AP_PATH_SWITCH_REQ_ACK (MessageDef *msg_p, const char *msg_name, instance_t instance)
+{
+  uint16_t                        ue_initial_id;
+  uint32_t                        eNB_ue_s1ap_id;
+  //gtpv1u_enb_create_tunnel_req_t  create_tunnel_req;
+  //gtpv1u_enb_create_tunnel_resp_t create_tunnel_resp;
+
+  gtpv1u_enb_delete_tunnel_req_t  delete_tunnel_req;
+
+  struct rrc_eNB_ue_context_s* ue_context_p = NULL;
+  protocol_ctxt_t              ctxt;
+  int i;
+
+  ue_initial_id  = S1AP_PATH_SWITCH_REQ_ACK (msg_p).ue_initial_id;
+  eNB_ue_s1ap_id = S1AP_PATH_SWITCH_REQ_ACK (msg_p).eNB_ue_s1ap_id;
+  ue_context_p   = rrc_eNB_get_ue_context_from_s1ap_ids(instance, ue_initial_id, eNB_ue_s1ap_id);
+  LOG_I(RRC, "[eNB %d] Received %s: ue_initial_id %d, eNB_ue_s1ap_id %d, nb_of_e_rabs %d\n",
+        instance, msg_name, ue_initial_id, eNB_ue_s1ap_id, S1AP_E_RAB_SETUP_REQ (msg_p).nb_e_rabs_tosetup);
+
+  if (ue_context_p == NULL) {
+    /* Can not associate this message to an UE index, send a failure to S1AP and discard it! */
+    //MessageDef *msg_fail_p = NULL;
+
+    LOG_W(RRC, "[eNB %d] In S1AP_PATH_SWITCH_REQ_ACK: unknown UE from S1AP ids (%d, %d)\n", instance, ue_initial_id, eNB_ue_s1ap_id);
+
+    //msg_fail_p = itti_alloc_new_message (TASK_RRC_ENB, S1AP_PATH_SWITCH_REQ_ACK_FAIL);
+    //S1AP_PATH_SWITCH_REQ_ACK  (msg_fail_p).eNB_ue_s1ap_id = eNB_ue_s1ap_id;
+
+    // TODO add failure cause when defined!
+
+    //itti_send_msg_to_task (TASK_S1AP, instance, msg_fail_p);
+    return (-1);
+  } else {
+
+    PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, ENB_FLAG_YES, ue_context_p->ue_context.rnti, 0, 0);
+    ue_context_p->ue_context.eNB_ue_s1ap_id = S1AP_PATH_SWITCH_REQ_ACK (msg_p).eNB_ue_s1ap_id;
+    ue_context_p->ue_context.mme_ue_s1ap_id = S1AP_PATH_SWITCH_REQ_ACK (msg_p).mme_ue_s1ap_id;
+
+    /* Save e RAB information for later */
+    {
+      for (i = 0;
+	   i < ue_context_p->ue_context.setup_e_rabs; // go over total number of e_rabs received through x2_ho_req msg
+	   i++) {
+	// assume that we are releasing all the DRBs
+	ue_context_p->ue_context.e_rab[i].status =  E_RAB_STATUS_TORELEASE;
+      }
+
+      //memset(&create_tunnel_req, 0 , sizeof(create_tunnel_req));
+      //uint8_t nb_e_rabs_tobeswitched = S1AP_PATH_SWITCH_REQ_ACK (msg_p).nb_e_rabs_tobeswitched;
+
+      // keep the previous bearer
+      // the index for the rec
+      for (i = 0;
+	   i < 1;//nb_e_rabs_tobeswitched; // go over total number of e_rabs received through x2_ho_req msg
+	   i++) {
+        LOG_I(RRC,"Bearer re-established with ID: %d\n", ue_context_p->ue_context.e_rab[i].param.e_rab_id);
+	/* Harmonize with enb_gtp_teid, enb_gtp_addrs, and enb_gtp_rbi vars in the top level structure */
+	ue_context_p->ue_context.e_rab[i].status =  E_RAB_STATUS_REESTABLISHED;
+	//ue_context_p->ue_context.e_rab[i].param.e_rab_id = S1AP_PATH_SWITCH_REQ_ACK (msg_p).e_rabs_tobeswitched[i].e_rab_id;
+	//ue_context_p->ue_context.e_rab[i].param.sgw_addr= S1AP_PATH_SWITCH_REQ_ACK (msg_p).e_rabs_tobeswitched[i].sgw_addr;
+	//ue_context_p->ue_context.e_rab[i].param.gtp_teid = S1AP_PATH_SWITCH_REQ_ACK (msg_p).e_rabs_tobeswitched[i].gtp_teid;
+	/* Tunnel must have been already created in X2_HO_REQ procedure */
+      }
+
+      ue_context_p->ue_context.setup_e_rabs=i;
+      ue_context_p->ue_context.nb_of_e_rabs=i;
+    }
+
+    ue_context_p->ue_context.ue_ambr=S1AP_PATH_SWITCH_REQ_ACK (msg_p).ue_ambr;
+
+
+    ue_context_p->ue_context.nb_release_of_e_rabs = S1AP_PATH_SWITCH_REQ_ACK (msg_p).nb_e_rabs_tobereleased;
+    memset(&delete_tunnel_req, 0 , sizeof(delete_tunnel_req));
+    for (i = 0;
+	 i < ue_context_p->ue_context.nb_release_of_e_rabs;
+	 i++) {
+      LOG_I(RRC,"Bearer released with ID: %d\n", ue_context_p->ue_context.e_rab[i].param.e_rab_id);
+      ue_context_p->ue_context.e_rabs_tobereleased[i]=S1AP_PATH_SWITCH_REQ_ACK (msg_p).e_rabs_tobereleased[i].e_rab_id;
+      delete_tunnel_req.eps_bearer_id[i]       = S1AP_PATH_SWITCH_REQ_ACK (msg_p).e_rabs_tobereleased[i].e_rab_id;
+
+    }
+    if (ue_context_p->ue_context.nb_release_of_e_rabs>0){
+      delete_tunnel_req.rnti= ue_context_p->ue_context.rnti;
+      delete_tunnel_req.num_erab= ue_context_p->ue_context.nb_release_of_e_rabs;
+      /* this could also be done through ITTI message */
+      gtpv1u_delete_s1u_tunnel(instance,
+			       &delete_tunnel_req);
+      /* TBD: release the DRB not admitted */
+      //rrc_eNB_generate_dedicatedRRCConnectionReconfiguration(&ctxt, ue_context_p, 0);
+    }
+
+    /* Security key */
+    ue_context_p->ue_context.next_hop_chain_count=S1AP_PATH_SWITCH_REQ_ACK (msg_p).next_hop_chain_count;
+    memcpy ( ue_context_p->ue_context.next_security_key,
+	     S1AP_PATH_SWITCH_REQ_ACK (msg_p).next_security_key,
+	     SECURITY_KEY_LENGTH);
+
+    return (0);
+  }
+}
+
 # endif /* defined(ENABLE_ITTI) */
 #endif /* defined(ENABLE_USE_MME) */
diff --git a/openair2/RRC/LTE/rrc_eNB_S1AP.h b/openair2/RRC/LTE/rrc_eNB_S1AP.h
index f16fa30408afd602b52f37b31fbf17a5c58ba803..a0a8d181159408bca6562426bbcee17f2cd86638 100644
--- a/openair2/RRC/LTE/rrc_eNB_S1AP.h
+++ b/openair2/RRC/LTE/rrc_eNB_S1AP.h
@@ -33,7 +33,7 @@
 
 # if defined(ENABLE_USE_MME)
 
-#include "UL-DCCH-Message.h"
+#include "LTE_UL-DCCH-Message.h"
 
 /* Up link procedures */
 
@@ -106,7 +106,7 @@ void
 rrc_eNB_send_S1AP_UPLINK_NAS(
   const protocol_ctxt_t*    const ctxt_pP,
   rrc_eNB_ue_context_t*          const ue_context_pP,
-  UL_DCCH_Message_t* const ul_dcch_msg
+  LTE_UL_DCCH_Message_t* const ul_dcch_msg
 );
 
 /*! \fn void rrc_eNB_send_S1AP_UE_CAPABILITIES_IND(const protocol_ctxt_t   * const ctxt_pP, eNB_RRC_UE_t * const ue_context_pP, UL_DCCH_Message_t *ul_dcch_msg)
@@ -118,7 +118,7 @@ rrc_eNB_send_S1AP_UPLINK_NAS(
 void rrc_eNB_send_S1AP_UE_CAPABILITIES_IND(
   const protocol_ctxt_t* const ctxt_pP,
   rrc_eNB_ue_context_t*          const ue_context_pP,
-  UL_DCCH_Message_t* ul_dcch_msg
+  LTE_UL_DCCH_Message_t* ul_dcch_msg
 );
 
 /*! \fn rrc_eNB_send_S1AP_NAS_FIRST_REQ(const protocol_ctxt_t* const ctxt_pP,eNB_RRC_UE_t *const ue_context_pP, RRCConnectionSetupComplete_r8_IEs_t *rrcConnectionSetupComplete)
@@ -132,7 +132,7 @@ void
 rrc_eNB_send_S1AP_NAS_FIRST_REQ(
   const protocol_ctxt_t* const ctxt_pP,
   rrc_eNB_ue_context_t*          const ue_context_pP,
-  RRCConnectionSetupComplete_r8_IEs_t* rrcConnectionSetupComplete
+  LTE_RRCConnectionSetupComplete_r8_IEs_t* rrcConnectionSetupComplete
 );
 
 
@@ -279,6 +279,10 @@ int rrc_eNB_process_S1AP_E_RAB_RELEASE_COMMAND(MessageDef *msg_p, const char *ms
  */
 int rrc_eNB_send_S1AP_E_RAB_RELEASE_RESPONSE(const protocol_ctxt_t* const ctxt_pP, rrc_eNB_ue_context_t*  const ue_context_pP, uint8_t xid );
 
+int rrc_eNB_send_PATH_SWITCH_REQ(const protocol_ctxt_t* const ctxt_pP,
+				  rrc_eNB_ue_context_t*          const ue_context_pP);
+int rrc_eNB_process_S1AP_PATH_SWITCH_REQ_ACK (MessageDef *msg_p, const char *msg_name, instance_t instance);
+
 #   endif
 # endif /* defined(ENABLE_USE_MME) */
 #endif /* RRC_ENB_S1AP_H_ */
diff --git a/openair2/RRC/LTE/rrc_extern.h b/openair2/RRC/LTE/rrc_extern.h
index 59200fb9cc4250c6e9cd13f457b779fd6ed0e757..e3b9ecb00be2dd745c31ad0d1beb468c99c55fad 100644
--- a/openair2/RRC/LTE/rrc_extern.h
+++ b/openair2/RRC/LTE/rrc_extern.h
@@ -40,8 +40,8 @@ extern UE_RRC_INST *UE_rrc_inst;
 
 extern uint8_t DRB2LCHAN[8];
 
-extern LogicalChannelConfig_t SRB1_logicalChannelConfig_defaultValue;
-extern LogicalChannelConfig_t SRB2_logicalChannelConfig_defaultValue;
+extern LTE_LogicalChannelConfig_t SRB1_logicalChannelConfig_defaultValue;
+extern LTE_LogicalChannelConfig_t SRB2_logicalChannelConfig_defaultValue;
 
 
 #ifndef PHY_EMUL
@@ -51,9 +51,8 @@ extern LogicalChannelConfig_t SRB2_logicalChannelConfig_defaultValue;
 extern unsigned char NB_INST;
 #endif
 extern unsigned char NB_eNB_INST;
-extern unsigned char NB_UE_INST;
+extern uint16_t NB_UE_INST;
 extern unsigned short NODE_ID[1];
-extern void* bigphys_malloc(int);
 #endif
 
 
diff --git a/openair2/RRC/LTE/rrc_proto.h b/openair2/RRC/LTE/rrc_proto.h
index ab2de2d17aca2bb5fa58af783cf741bfbaa1a489..b9277b59a39d48447f98f479a1b0c9c20575d3be 100644
--- a/openair2/RRC/LTE/rrc_proto.h
+++ b/openair2/RRC/LTE/rrc_proto.h
@@ -32,7 +32,7 @@
  */
 
 #include "RRC/LTE/rrc_defs.h"
-
+#include "x2ap_messages_types.h"
 #include "flexran_agent_extern.h"
 
 //main.c
@@ -105,7 +105,7 @@ rrc_ue_decode_dcch(
   const uint8_t                eNB_indexP
 );
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 int decode_SL_Discovery_Message(
   const protocol_ctxt_t* const ctxt_pP,
   const uint8_t                eNB_index,
@@ -129,7 +129,7 @@ rrc_ue_generate_RRCConnectionRequest(
 void
 rrc_ue_process_rrcConnectionReconfiguration(
   const protocol_ctxt_t* const       ctxt_pP,
-  RRCConnectionReconfiguration_t* rrcConnectionReconfiguration,
+  LTE_RRCConnectionReconfiguration_t* rrcConnectionReconfiguration,
   uint8_t eNB_index
 );
 
@@ -139,7 +139,7 @@ rrc_ue_process_rrcConnectionReconfiguration(
     \param eNB_index Index of corresponding eNB/CH
     \param SRB_config Pointer to SRB_ToAddMod IE from configuration
     @returns 0 on success*/
-int32_t  rrc_ue_establish_srb1(module_id_t module_idP,frame_t frameP,uint8_t eNB_index,struct SRB_ToAddMod *SRB_config);
+int32_t  rrc_ue_establish_srb1(module_id_t module_idP,frame_t frameP,uint8_t eNB_index,struct LTE_SRB_ToAddMod *SRB_config);
 
 /** \brief Establish SRB2 based on configuration in SRB_ToAddMod structure.  Configures RLC/PDCP accordingly
     \param module_idP Instance ID of UE
@@ -147,14 +147,14 @@ int32_t  rrc_ue_establish_srb1(module_id_t module_idP,frame_t frameP,uint8_t eNB
     \param eNB_index Index of corresponding eNB/CH
     \param SRB_config Pointer to SRB_ToAddMod IE from configuration
     @returns 0 on success*/
-int32_t  rrc_ue_establish_srb2(module_id_t module_idP,frame_t frameP, uint8_t eNB_index,struct SRB_ToAddMod *SRB_config);
+int32_t  rrc_ue_establish_srb2(module_id_t module_idP,frame_t frameP, uint8_t eNB_index,struct LTE_SRB_ToAddMod *SRB_config);
 
 /** \brief Establish a DRB according to DRB_ToAddMod structure
     \param module_idP Instance ID of UE
     \param eNB_index Index of corresponding CH/eNB
     \param DRB_config Pointer to DRB_ToAddMod IE from configuration
     @returns 0 on success */
-int32_t  rrc_ue_establish_drb(module_id_t module_idP,frame_t frameP,uint8_t eNB_index,struct DRB_ToAddMod *DRB_config);
+int32_t  rrc_ue_establish_drb(module_id_t module_idP,frame_t frameP,uint8_t eNB_index,struct LTE_DRB_ToAddMod *DRB_config);
 
 /** \brief Process MobilityControlInfo Message to proceed with handover and configure PHY/MAC
     \param ctxt_pP Running context
@@ -165,7 +165,7 @@ void
 rrc_ue_process_mobilityControlInfo(
   const protocol_ctxt_t* const       ctxt_pP,
   const uint8_t                      eNB_index,
-  struct MobilityControlInfo* const mobilityControlInfo
+  struct LTE_MobilityControlInfo* const mobilityControlInfo
 );
 
 /** \brief Process a measConfig Message and configure PHY/MAC
@@ -176,7 +176,7 @@ void
 rrc_ue_process_measConfig(
   const protocol_ctxt_t* const       ctxt_pP,
   const uint8_t                      eNB_index,
-  MeasConfig_t* const               measConfig
+  LTE_MeasConfig_t* const               measConfig
 );
 
 /** \brief Process a RadioResourceConfigDedicated Message and configure PHY/MAC
@@ -186,7 +186,7 @@ rrc_ue_process_measConfig(
 void rrc_ue_process_radioResourceConfigDedicated(
   const protocol_ctxt_t* const ctxt_pP,
   uint8_t eNB_index,
-  RadioResourceConfigDedicated_t *radioResourceConfigDedicated);
+  LTE_RadioResourceConfigDedicated_t *radioResourceConfigDedicated);
 
 
 /** \brief Process a RadioResourceConfig and configure PHY/MAC for SL communication/discovery
@@ -199,10 +199,10 @@ void rrc_ue_process_radioResourceConfigDedicated(
 void rrc_ue_process_sidelink_radioResourceConfig(
   module_id_t Mod_idP,
   uint8_t eNB_index,
-  SystemInformationBlockType18_r12_t     *sib18,
-  SystemInformationBlockType19_r12_t     *sib19,
-  SL_CommConfig_r12_t* sl_CommConfig,
-  SL_DiscConfig_r12_t* sl_DiscConfig);
+  LTE_SystemInformationBlockType18_r12_t     *sib18,
+  LTE_SystemInformationBlockType19_r12_t     *sib19,
+  LTE_SL_CommConfig_r12_t* sl_CommConfig,
+  LTE_SL_DiscConfig_r12_t* sl_DiscConfig);
 
 /** \brief Init control socket to listen to incoming packets from ProSe App
  *
@@ -270,7 +270,7 @@ void
 rrc_eNB_process_RRCConnectionSetupComplete(
   const protocol_ctxt_t* const ctxt_pP,
   rrc_eNB_ue_context_t*        ue_context_pP,
-  RRCConnectionSetupComplete_r8_IEs_t* rrcConnectionSetupComplete
+  LTE_RRCConnectionSetupComplete_r8_IEs_t* rrcConnectionSetupComplete
 );
 
 /**\brief Process the RRCConnectionReconfigurationComplete based on information coming from UE
@@ -310,6 +310,15 @@ flexran_rrc_eNB_generate_defaultRRCConnectionReconfiguration(
 							     const uint8_t ho_state,
 							     agent_reconf_rrc * trig_param
 							     );
+void
+rrc_eNB_generate_HO_RRCConnectionReconfiguration(const protocol_ctxt_t* const ctxt_pP,
+                                                 rrc_eNB_ue_context_t*  const ue_context_pP,
+                                                 uint8_t*               buffer,
+                                                 int                    *_size
+                                                 //const uint8_t        ho_state
+                                                 );
+void
+rrc_eNB_configure_rbs_handover(struct rrc_eNB_ue_context_s* ue_context_p, protocol_ctxt_t* const ctxt_pP);
 
 int freq_to_arfcn10(int band, unsigned long freq);
 
@@ -350,6 +359,8 @@ void *rrc_enb_task(void *args_p);
 void *rrc_ue_task(void *args_p);
 #endif
 
+void rrc_eNB_process_handoverPreparationInformation(int mod_id, x2ap_handover_req_t *m);
+
 /**\brief Generate/decode the handover RRCConnectionReconfiguration at eNB
    \param module_idP Instance ID for eNB/CH
    \param frame Frame index
@@ -371,7 +382,7 @@ int
 rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(
       const protocol_ctxt_t* const ctxt_pP,
       rrc_eNB_ue_context_t*           const ue_context_pP,
-      SL_DestinationInfoList_r12_t  *destinationInfoList,
+      LTE_SL_DestinationInfoList_r12_t  *destinationInfoList,
       int n_discoveryMessages
 );
 
@@ -382,24 +393,24 @@ uint8_t
 rrc_eNB_process_SidelinkUEInformation(
       const protocol_ctxt_t* const ctxt_pP,
       rrc_eNB_ue_context_t*         ue_context_pP,
-      SidelinkUEInformation_r12_t*  sidelinkUEInformation
+      LTE_SidelinkUEInformation_r12_t*  sidelinkUEInformation
 );
 
 /** \brief Get a Resource Pool to transmit SL communication
     \param ctxt_pP Running context
     \param ue_context_pP UE context
     \param destinationInfoList Pointer to the list of SL destinations*/
-SL_CommConfig_r12_t rrc_eNB_get_sidelink_commTXPool(
+LTE_SL_CommConfig_r12_t rrc_eNB_get_sidelink_commTXPool(
       const protocol_ctxt_t* const ctxt_pP,
       rrc_eNB_ue_context_t* const ue_context_pP,
-      SL_DestinationInfoList_r12_t  *destinationInfoList
+      LTE_SL_DestinationInfoList_r12_t  *destinationInfoList
 );
 
 /** \brief Get a Resource Pool for Discovery
     \param ctxt_pP Running context
     \param ue_context_pP UE context
     \param n_discoveryMessages Number of discovery messages*/
-SL_DiscConfig_r12_t rrc_eNB_get_sidelink_discTXPool(
+LTE_SL_DiscConfig_r12_t rrc_eNB_get_sidelink_discTXPool(
       const protocol_ctxt_t* const ctxt_pP,
       rrc_eNB_ue_context_t* const ue_context_pP,
       int n_discoveryMessages
@@ -435,6 +446,9 @@ mac_rrc_data_ind(
   const uint8_t*        sduP,
   const sdu_size_t      sdu_lenP,
   const uint8_t         mbsfn_sync_areaP
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  , const boolean_t		brOption
+#endif
 );
 
 int8_t
@@ -575,14 +589,16 @@ void
 rrc_eNB_process_MeasurementReport(
   const protocol_ctxt_t* const ctxt_pP,
   rrc_eNB_ue_context_t*        ue_context_pP,
-  const MeasResults_t*   const measResults2
+  const LTE_MeasResults_t*   const measResults2
 );
 
 void
 rrc_eNB_generate_HandoverPreparationInformation(
-  const protocol_ctxt_t* const ctxt_pP,
+  //const protocol_ctxt_t* const ctxt_pP,
   rrc_eNB_ue_context_t*          const ue_context_pP,
-  PhysCellId_t targetPhyId
+  uint8_t*                     buffer,
+  int                          *_size
+  //LTE_PhysCellId_t targetPhyId
 );
 
 void
diff --git a/openair2/RRC/LTE/rrc_vars.h b/openair2/RRC/LTE/rrc_vars.h
index 028a59f7d96915928827a8c24090f40a7efc7c7a..512d421168d80c2808726eff0c8129c88fbfaaae 100644
--- a/openair2/RRC/LTE/rrc_vars.h
+++ b/openair2/RRC/LTE/rrc_vars.h
@@ -38,7 +38,7 @@
 
 UE_PF_PO_t UE_PF_PO[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB];
 pthread_mutex_t ue_pf_po_mutex;
-UE_RRC_INST *UE_rrc_inst;
+UE_RRC_INST *UE_rrc_inst = NULL;
 #include "LAYER2/MAC/mac_extern.h"
 #define MAX_U32 0xFFFFFFFF
 
@@ -47,34 +47,34 @@ uint8_t DRB2LCHAN[8];
 long logicalChannelGroup0 = 0;
 long  logicalChannelSR_Mask_r9=0;
 
-struct LogicalChannelConfig__ul_SpecificParameters LCSRB1 =  {1,
-         LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity,
+struct LTE_LogicalChannelConfig__ul_SpecificParameters LCSRB1 =  {1,
+         LTE_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity,
          0,
          &logicalChannelGroup0
 };
-struct LogicalChannelConfig__ul_SpecificParameters LCSRB2 =  {3,
-         LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity,
+struct LTE_LogicalChannelConfig__ul_SpecificParameters LCSRB2 =  {3,
+         LTE_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity,
          0,
          &logicalChannelGroup0
 };
 
 
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-struct LogicalChannelConfig__ext1 logicalChannelSR_Mask_r9_ext1 = {
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+struct LTE_LogicalChannelConfig__ext1 logicalChannelSR_Mask_r9_ext1 = {
          logicalChannelSR_Mask_r9: &logicalChannelSR_Mask_r9
 };
 #endif
 
 // These are the default SRB configurations from 36.331 (Chapter 9, p. 176-179 in v8.6)
-LogicalChannelConfig_t  SRB1_logicalChannelConfig_defaultValue = {ul_SpecificParameters: &LCSRB1
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+LTE_LogicalChannelConfig_t  SRB1_logicalChannelConfig_defaultValue = {ul_SpecificParameters: &LCSRB1
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
                                                                   ,
                                                                   ext1: &logicalChannelSR_Mask_r9_ext1
 #endif
                                                                  };
 
-LogicalChannelConfig_t SRB2_logicalChannelConfig_defaultValue = {ul_SpecificParameters: &LCSRB2
-#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+LTE_LogicalChannelConfig_t SRB2_logicalChannelConfig_defaultValue = {ul_SpecificParameters: &LCSRB2
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
                                                                  ,
                                                                  ext1: &logicalChannelSR_Mask_r9_ext1
 #endif
diff --git a/openair2/RRC/NAS/Makefile.inc b/openair2/RRC/NAS/Makefile.inc
deleted file mode 100644
index ea1a8a7a813ede23899803438439d620c13c8505..0000000000000000000000000000000000000000
--- a/openair2/RRC/NAS/Makefile.inc
+++ /dev/null
@@ -1,4 +0,0 @@
-#ifeq ($(NAS_FLAG),1) 
-NAS_OBJS  = $(OPENAIR2_TOP)/RRC/NAS/nas_config.o
-NAS_OBJS += $(OPENAIR2_TOP)/RRC/NAS/rb_config.o
-#endif
diff --git a/openair2/UTIL/ASYNC_IF/message_queue.c b/openair2/UTIL/ASYNC_IF/message_queue.c
index 460c58bcd1a1073ed1a1c2daa5527cafb4f5c289..2279a067b4547e8bea6edbeda98bd3968b9ebb85 100644
--- a/openair2/UTIL/ASYNC_IF/message_queue.c
+++ b/openair2/UTIL/ASYNC_IF/message_queue.c
@@ -211,10 +211,11 @@ int main(void)
   sprintf(s, "hello");
   if (message_put(q, s, 6, 0)) goto error;
   destroy_message_queue(q);
-
+  free(s);
   return 0;
 
 error:
+  free(s);
   printf("error\n");
   return 1;
 }
diff --git a/openair2/UTIL/BIGPHYS/bigphys.c b/openair2/UTIL/BIGPHYS/bigphys.c
deleted file mode 100644
index 219a0c8d1b42eb99fb54abcefbc1bd65d73e45fb..0000000000000000000000000000000000000000
--- a/openair2/UTIL/BIGPHYS/bigphys.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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 "defs.h"
-#include "linux/module.h"
-
-#ifdef BIGPHYSAREA
-#ifdef ARCH_64
-char *bigphys_ptr,*bigphys_current;
-#else //ARCH_64
-unsigned int bigphys_ptr,bigphys_current;
-#endif //ARCH_64
-
-// return pointer to memory in big physical area aligned to 16 bytes
-
-void* bigphys_malloc(int n)
-{
-
-
-
-  int n2 = n + ((16-(n%16))%16);
-#ifdef ARCH_64
-  char *bigphys_old;
-#else
-  unsigned int bigphys_old;
-#endif
-
-  printk("[BIGPHYSAREA] Calling bigphys_malloc for %d (%d) bytes\n",n,n2);
-
-#ifdef ARCH_64
-  printk("[BIGPHYSAREA] Allocated Memory @ %p\n",bigphys_current);
-#endif
-  bigphys_old = bigphys_current;
-  bigphys_current += n2;
-
-#ifdef ARCH_64
-  printk("[BIGPHYSAREA] Allocated Memory top now @ %p\n",bigphys_current);
-  return ((void *)(bigphys_old));
-#else //ARCH_64
-  //printk("[BIGPHYSAREA] Allocated Memory %d\n",bigphys_current-bigphys_ptr);
-  return ((void *)(bigphys_old));
-#endif //ARCH_64
-}
-
-EXPORT_SYMBOL(bigphys_malloc);
-#endif
-
-
-
diff --git a/openair2/UTIL/BIGPHYS/defs.h b/openair2/UTIL/BIGPHYS/defs.h
deleted file mode 100644
index 69368a6d727f94fb9dfe16a90e6433bf6cd79382..0000000000000000000000000000000000000000
--- a/openair2/UTIL/BIGPHYS/defs.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * 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
- */
-
-void* bigphys_malloc(int);
diff --git a/openair2/UTIL/FIFO/pad_list.c b/openair2/UTIL/FIFO/pad_list.c
index 32a9f3519640a020df52ebc60add66f9a0fb3bac..e15041118d0f182492d34f596c829c988c0dd371 100644
--- a/openair2/UTIL/FIFO/pad_list.c
+++ b/openair2/UTIL/FIFO/pad_list.c
@@ -35,25 +35,19 @@
 //#include <mpi.h>
 
 
-void job_list_init (Job_List_t * listP)
-{
-
+void job_list_init (Job_List_t *listP) {
   listP->tail = NULL;
   listP->head = NULL;
   listP->nb_elements = 0;
 }
 
-void event_list_init (Event_List_t * listP)
-{
-
+void event_list_init (Event_List_t *listP) {
   listP->tail = NULL;
   listP->head = NULL;
   listP->nb_elements = 0;
 }
 
-void pkt_list_init (Packet_OTG_List_t * listP)
-{
-
+void pkt_list_init (Packet_OTG_List_t *listP) {
   listP->tail = NULL;
   listP->head = NULL;
   listP->nb_elements = 0;
@@ -61,8 +55,7 @@ void pkt_list_init (Packet_OTG_List_t * listP)
 
 //-----------------------------------------------------------------------------
 
-void job_list_free (Job_List_t * listP)
-{
+void job_list_free (Job_List_t *listP) {
   Job_elt_t *le;
 
   while ((le = job_list_remove_head (listP))) {
@@ -70,8 +63,7 @@ void job_list_free (Job_List_t * listP)
   }
 }
 
-void event_list_free (Event_List_t * listP)
-{
+void event_list_free (Event_List_t *listP) {
   Event_elt_t *le;
 
   while ((le = event_list_remove_head (listP))) {
@@ -79,8 +71,7 @@ void event_list_free (Event_List_t * listP)
   }
 }
 
-void pkt_list_free (Packet_OTG_List_t * listP)
-{
+void pkt_list_free (Packet_OTG_List_t *listP) {
   Packet_otg_elt_t *le;
 
   while ((le = pkt_list_remove_head (listP))) {
@@ -90,18 +81,15 @@ void pkt_list_free (Packet_OTG_List_t * listP)
 
 //-----------------------------------------------------------------------------
 
-Job_elt_t * job_list_get_head (Job_List_t * listP)
-{
+Job_elt_t *job_list_get_head (Job_List_t *listP) {
   return listP->head;
 }
 
-Event_elt_t * event_list_get_head (Event_List_t * listP)
-{
+Event_elt_t *event_list_get_head (Event_List_t *listP) {
   return listP->head;
 }
 
-Packet_otg_elt_t * pkt_list_get_head (Packet_OTG_List_t * listP)
-{
+Packet_otg_elt_t *pkt_list_get_head (Packet_OTG_List_t *listP) {
   return listP->head;
 }
 
@@ -112,9 +100,7 @@ Packet_otg_elt_t * pkt_list_get_head (Packet_OTG_List_t * listP)
  *  @param  pointer on targeted list
  *  @return pointer on removed Job_elt_t
  */
-Job_elt_t * job_list_remove_head (Job_List_t * listP)
-{
-
+Job_elt_t *job_list_remove_head (Job_List_t *listP) {
   // access optimisation
   Job_elt_t *head;
   head = listP->head;
@@ -137,9 +123,7 @@ Job_elt_t * job_list_remove_head (Job_List_t * listP)
   return head;
 }
 
-Event_elt_t * event_list_remove_head (Event_List_t * listP)
-{
-
+Event_elt_t *event_list_remove_head (Event_List_t *listP) {
   // access optimisation
   Event_elt_t *head;
   head = listP->head;
@@ -162,9 +146,7 @@ Event_elt_t * event_list_remove_head (Event_List_t * listP)
   return head;
 }
 
-Packet_otg_elt_t * pkt_list_remove_head (Packet_OTG_List_t * listP)
-{
-
+Packet_otg_elt_t *pkt_list_remove_head (Packet_OTG_List_t *listP) {
   // access optimisation
   Packet_otg_elt_t *head;
   head = listP->head;
@@ -189,9 +171,7 @@ Packet_otg_elt_t * pkt_list_remove_head (Packet_OTG_List_t * listP)
 
 //-----------------------------------------------------------------------------
 
-Job_elt_t * job_list_remove_element (Job_elt_t * elementP, Job_List_t * listP)
-{
-
+Job_elt_t *job_list_remove_element (Job_elt_t *elementP, Job_List_t *listP) {
   // access optimisation;
   Job_elt_t *head;
 
@@ -233,9 +213,7 @@ Job_elt_t * job_list_remove_element (Job_elt_t * elementP, Job_List_t * listP)
   return elementP;
 }
 
-Event_elt_t * event_list_remove_element (Event_elt_t * elementP, Event_List_t * listP)
-{
-
+Event_elt_t *event_list_remove_element (Event_elt_t *elementP, Event_List_t *listP) {
   // access optimisation;
   Event_elt_t *head;
 
@@ -277,9 +255,7 @@ Event_elt_t * event_list_remove_element (Event_elt_t * elementP, Event_List_t *
   return elementP;
 }
 
-Packet_otg_elt_t * pkt_list_remove_element (Packet_otg_elt_t * elementP, Packet_OTG_List_t * listP)
-{
-
+Packet_otg_elt_t *pkt_list_remove_element (Packet_otg_elt_t *elementP, Packet_OTG_List_t *listP) {
   // access optimisation;
   Packet_otg_elt_t *head;
 
@@ -328,9 +304,7 @@ Packet_otg_elt_t * pkt_list_remove_element (Packet_otg_elt_t * elementP, Packet_
  *  @return pointer on removed Job_elt_t
  */
 
-void job_list_add_head (Job_elt_t * elementP, Job_List_t * listP)
-{
-
+void job_list_add_head (Job_elt_t *elementP, Job_List_t *listP) {
   // access optimisation;
   Job_elt_t *head;
 
@@ -349,9 +323,7 @@ void job_list_add_head (Job_elt_t * elementP, Job_List_t * listP)
   }
 }
 
-void event_list_add_head (Event_elt_t * elementP, Event_List_t * listP)
-{
-
+void event_list_add_head (Event_elt_t *elementP, Event_List_t *listP) {
   // access optimisation;
   Event_elt_t *head;
 
@@ -370,9 +342,7 @@ void event_list_add_head (Event_elt_t * elementP, Event_List_t * listP)
   }
 }
 
-void pkt_list_add_head (Packet_otg_elt_t * elementP, Packet_OTG_List_t * listP)
-{
-
+void pkt_list_add_head (Packet_otg_elt_t *elementP, Packet_OTG_List_t *listP) {
   // access optimisation;
   Packet_otg_elt_t *head;
 
@@ -391,14 +361,12 @@ void pkt_list_add_head (Packet_otg_elt_t * elementP, Packet_OTG_List_t * listP)
   }
 }
 
-void event_list_add_element (Event_elt_t * elementP, Event_elt_t * previous, Event_List_t * listP)
-{
-
+void event_list_add_element (Event_elt_t *elementP, Event_elt_t *previous, Event_List_t *listP) {
   // access optimisation;
   Event_elt_t *next;
-  elementP->next = NULL;
 
   if (elementP != NULL && previous != NULL) {
+    elementP->next = NULL;
     next = previous->next;
     listP->nb_elements = listP->nb_elements + 1;
 
@@ -420,8 +388,7 @@ void event_list_add_element (Event_elt_t * elementP, Event_elt_t * previous, Eve
  *  @param  pointer on targeted list
  *  @return pointer on removed Job_elt_t
  */
-void job_list_add_tail_eurecom (Job_elt_t * elementP, Job_List_t * listP)
-{
+void job_list_add_tail_eurecom (Job_elt_t *elementP, Job_List_t *listP) {
   Job_elt_t *tail;
 
   if (elementP != NULL) {
@@ -443,8 +410,7 @@ void job_list_add_tail_eurecom (Job_elt_t * elementP, Job_List_t * listP)
   }
 }
 
-void event_list_add_tail_eurecom (Event_elt_t * elementP, Event_List_t * listP)
-{
+void event_list_add_tail_eurecom (Event_elt_t *elementP, Event_List_t *listP) {
   Event_elt_t *tail;
 
   if (elementP != NULL) {
@@ -466,8 +432,7 @@ void event_list_add_tail_eurecom (Event_elt_t * elementP, Event_List_t * listP)
   }
 }
 
-void pkt_list_add_tail_eurecom (Packet_otg_elt_t * elementP, Packet_OTG_List_t * listP)
-{
+void pkt_list_add_tail_eurecom (Packet_otg_elt_t *elementP, Packet_OTG_List_t *listP) {
   Packet_otg_elt_t *tail;
 
   if (elementP != NULL) {
@@ -490,14 +455,11 @@ void pkt_list_add_tail_eurecom (Packet_otg_elt_t * elementP, Packet_OTG_List_t *
 }
 
 //-----------------------------------------------------------------------------
-void job_list_add_list (Job_List_t * sublistP, Job_List_t * listP)
-{
-
+void job_list_add_list (Job_List_t *sublistP, Job_List_t *listP) {
   if (sublistP) {
     if (sublistP->head) {
       // access optimisation
       Job_elt_t *tail;
-
       tail = listP->tail;
 
       // almost one element
@@ -517,14 +479,11 @@ void job_list_add_list (Job_List_t * sublistP, Job_List_t * listP)
   }
 }
 
-void event_list_add_list (Event_List_t * sublistP, Event_List_t * listP)
-{
-
+void event_list_add_list (Event_List_t *sublistP, Event_List_t *listP) {
   if (sublistP) {
     if (sublistP->head) {
       // access optimisation
       Event_elt_t *tail;
-
       tail = listP->tail;
 
       // almost one element
@@ -544,14 +503,11 @@ void event_list_add_list (Event_List_t * sublistP, Event_List_t * listP)
   }
 }
 
-void pkt_list_add_list (Packet_OTG_List_t * sublistP, Packet_OTG_List_t * listP)
-{
-
+void pkt_list_add_list (Packet_OTG_List_t *sublistP, Packet_OTG_List_t *listP) {
   if (sublistP) {
     if (sublistP->head) {
       // access optimisation
       Packet_otg_elt_t *tail;
-
       tail = listP->tail;
 
       // almost one element
@@ -572,11 +528,8 @@ void pkt_list_add_list (Packet_OTG_List_t * sublistP, Packet_OTG_List_t * listP)
 }
 
 //-----------------------------------------------------------------------------
-void job_list_display (Job_List_t * listP)
-{
-
+void job_list_display (Job_List_t *listP) {
   //Correct the output once the content of struct Job is fixed
-
   /*Job_elt_t *cursor;
   unsigned short nb_elements = 0;
 
@@ -605,8 +558,7 @@ void job_list_display (Job_List_t * listP)
   }*/
 }
 
-void event_list_display (Event_List_t * listP)
-{
+void event_list_display (Event_List_t *listP) {
   Event_elt_t *cursor;
   unsigned short nb_elements = 0;
 
@@ -630,8 +582,7 @@ void event_list_display (Event_List_t * listP)
   }
 }
 
-void pkt_list_display (Packet_OTG_List_t * listP)
-{
+void pkt_list_display (Packet_OTG_List_t *listP) {
   Packet_otg_elt_t *cursor;
   unsigned short nb_elements = 0;
 
diff --git a/openair2/UTIL/MATH/taus.c b/openair2/UTIL/MATH/taus.c
index 632b1544dd0970b484fbe0a2ef4d585cae550604..6f1b2214e51b92ec07cbc21d9699664077f40633 100644
--- a/openair2/UTIL/MATH/taus.c
+++ b/openair2/UTIL/MATH/taus.c
@@ -41,9 +41,7 @@ unsigned int s0[MAX_NUM_COMPS], s1[MAX_NUM_COMPS], s2[MAX_NUM_COMPS], b[MAX_NUM_
 
 
 
-inline unsigned int taus(unsigned int comp)
-{
-
+inline unsigned int taus(unsigned int comp) {
   b[comp] = (((s0[comp] << 13) ^ s0[comp]) >> 19);
   s0[comp] = (((s0[comp] & 0xFFFFFFFE) << 12)^  b[comp]);
   b[comp] = (((s1[comp] << 2) ^ s1[comp]) >> 25);
@@ -54,42 +52,36 @@ inline unsigned int taus(unsigned int comp)
   return r[comp];
 }
 
-void set_taus_seed(unsigned int seed_type)
-{
-
+void set_taus_seed(unsigned int seed_type) {
   unsigned int i; // i index of component
 
   for (i=MIN_NUM_COMPS; i < MAX_NUM_COMPS  ; i ++)  {
-
     switch (seed_type) {
-    case 0: // use rand func
-      if (i == 0) srand(time(NULL));
-
-      s0[i] = ((unsigned int)rand());
-      s1[i] = ((unsigned int)rand());
-      s2[i] = ((unsigned int)rand());
-      printf("Initial seeds use rand: s0[%d] = 0x%x, s1[%d] = 0x%x, s2[%d] = 0x%x\n", i, s0[i], i, s1[i], i, s2[i]);
-      break;
-
-    case 1: // use rand with seed
-      if (i == 0) srand(0x1e23d851);
-
-      s0[i] = ((unsigned int)rand());
-      s1[i] = ((unsigned int)rand());
-      s2[i] = ((unsigned int)rand());
-      printf("Initial seeds use rand with seed : s0[%d] = 0x%x, s1[%d] = 0x%x, s2[%d] = 0x%x\n", i, s0[i], i, s1[i], i, s2[i]);
-
-      break;
-
-    default:
-      break;
-
+      case 0: // use rand func
+        if (i == 0) srand(time(NULL));
+
+        s0[i] = ((unsigned int)rand());
+        s1[i] = ((unsigned int)rand());
+        s2[i] = ((unsigned int)rand());
+        printf("Initial seeds use rand: s0[%u] = 0x%x, s1[%u] = 0x%x, s2[%u] = 0x%x\n", i, s0[i], i, s1[i], i, s2[i]);
+        break;
+
+      case 1: // use rand with seed
+        if (i == 0) srand(0x1e23d851);
+
+        s0[i] = ((unsigned int)rand());
+        s1[i] = ((unsigned int)rand());
+        s2[i] = ((unsigned int)rand());
+        printf("Initial seeds use rand with seed : s0[%u] = 0x%x, s1[%u] = 0x%x, s2[%u] = 0x%x\n", i, s0[i], i, s1[i], i, s2[i]);
+        break;
+
+      default:
+        break;
     }
   }
 }
 
-int get_rand (unsigned int comp)
-{
+int get_rand (unsigned int comp) {
   if ((comp > MIN_NUM_COMPS) && (comp < MAX_NUM_COMPS))
     return r[comp];
   else {
@@ -98,9 +90,7 @@ int get_rand (unsigned int comp)
   }
 }
 
-unsigned int dtaus(unsigned int comp, unsigned int a, unsigned b)
-{
-
+unsigned int dtaus(unsigned int comp, unsigned int a, unsigned b) {
   return (int) (((double)taus(comp)/(double)0xffffffff)* (double)(b-a) + (double)a);
 }
 /*
diff --git a/openair2/UTIL/Makefile.inc b/openair2/UTIL/Makefile.inc
deleted file mode 100644
index fac8d7e9a17885e0f03f321217b69fa547f4ab78..0000000000000000000000000000000000000000
--- a/openair2/UTIL/Makefile.inc
+++ /dev/null
@@ -1,108 +0,0 @@
-MEM_DIR = $(OPENAIR2_TOP)/UTIL/MEM
-LIST_DIR = $(OPENAIR2_TOP)/UTIL/LISTS
-FIFO_DIR = $(OPENAIR2_TOP)/UTIL/FIFO
-MATH_DIR = $(OPENAIR2_TOP)/UTIL/MATH
-TIMER_DIR = $(OPENAIR2_TOP)/UTIL/TIMER
-LOG_DIR=$(OPENAIR2_TOP)/UTIL/LOG
-OCG_DIR=$(OPENAIR2_TOP)/UTIL/OCG
-OPT_DIR=$(OPENAIR2_TOP)/UTIL/OPT
-OMG_DIR=$(OPENAIR2_TOP)/UTIL/OMG
-OTG_DIR=$(OPENAIR2_TOP)/UTIL/OTG
-CLI_DIR=$(OPENAIR2_TOP)/UTIL/CLI
-OMV_DIR=$(OPENAIR2_TOP)/UTIL/OMV
-LFDS_DIR=$(OPENAIR2_TOP)/UTIL/LFDS/liblfds6.1.1/liblfds611
-OSA_DIR=$(OPENAIR2_TOP)/UTIL/OSA
-
-LIST_OBJ =  $(LIST_DIR)/list.o
-
-FIFO_OBJ =  $(FIFO_DIR)/pad_list.o
-
-LIST_OBJ +=  $(LIST_DIR)/list2.o
-
-TIMER_OBJ +=  $(TIMER_DIR)/umts_timer.o
-
-MEM_OBJ +=  $(MEM_DIR)/mem_block.o
-
-LOG_OBJS =  $(LOG_DIR)/log.o
-LOG_OBJS +=  $(LOG_DIR)/vcd_signal_dumper.o
-
-OCG_OBJS  =  $(OCG_DIR)/OCG.o
-OCG_OBJS +=  $(OCG_DIR)/OCG_create_dir.o
-OCG_OBJS +=  $(OCG_DIR)/OCG_detect_file.o
-OCG_OBJS +=  $(OCG_DIR)/OCG_generate_report.o
-OCG_OBJS +=  $(OCG_DIR)/OCG_parse_filename.o
-OCG_OBJS +=  $(OCG_DIR)/OCG_parse_XML.o
-OCG_OBJS +=  $(OCG_DIR)/OCG_save_XML.o
-
-ifdef SECU
-OSA_OBJS  = $(OSA_DIR)/osa_key_deriver.o
-OSA_OBJS += $(OSA_DIR)/osa_stream_eia.o
-OSA_OBJS += $(OSA_DIR)/osa_stream_eea.o
-OSA_OBJS += $(OSA_DIR)/osa_snow3g.o
-OSA_OBJS += $(OSA_DIR)/osa_rijndael.o
-endif
-
-OPT_OBJS =  $(OPT_DIR)/probe.o
-
-OMG_OBJS =  $(OMG_DIR)/omg.o
-OMG_OBJS +=  $(OMG_DIR)/common.o
-OMG_OBJS +=  $(OMG_DIR)/job.o
-OMG_OBJS +=  $(OMG_DIR)/static.o
-OMG_OBJS +=  $(OMG_DIR)/rwp.o
-OMG_OBJS +=  $(OMG_DIR)/rwalk.o
-#OMG_OBJS +=  $(OMG_DIR)/omg_hashtable.o
-OMG_OBJS +=  $(OMG_DIR)/mobility_parser.o
-OMG_OBJS +=  $(OMG_DIR)/trace.o
-OMG_OBJS +=  $(OMG_DIR)/sumo.o
-OMG_OBJS +=  $(OMG_DIR)/id_manager.o
-OMG_OBJS +=  $(OMG_DIR)/client_traci_OMG.o
-OMG_OBJS +=  $(OMG_DIR)/storage_traci_OMG.o
-OMG_OBJS +=  $(OMG_DIR)/socket_traci_OMG.o
-OMG_OBJS +=  $(OMG_DIR)/steadystaterwp.o
-OMG_OBJS +=  $(OMG_DIR)/grid.o
-OMG_OBJS +=  $(OMG_DIR)/trace_hashtable.o
-
-
-OTG_OBJS =  $(OTG_DIR)/otg_tx.o
-OTG_OBJS +=  $(OTG_DIR)/otg.o
-OTG_OBJS +=  $(OTG_DIR)/otg_rx.o
-OTG_OBJS +=  $(OTG_DIR)/otg_kpi.o
-OTG_OBJS +=  $(OTG_DIR)/otg_form.o
-OTG_OBJS +=  $(OTG_DIR)/otg_models.o
-
-MATH_OBJS  =  $(MATH_DIR)/oml.o
-
-CLI_OBJ  =  $(CLI_DIR)/cli_server.o
-CLI_OBJ  +=  $(CLI_DIR)/cli.o
-CLI_OBJ  +=  $(CLI_DIR)/cli_cmd.o
-
-UTIL_OBJ =              \
-    $(OSA_OBJS)         \
-    $(FIFO_OBJ)         \
-    $(LIST_OBJ)         \
-    $(TIMER_OBJ)        \
-    $(MEM_OBJ)          \
-    $(LOG_OBJS)         \
-    $(OCG_OBJS)         \
-    $(MATH_OBJS)        \
-    $(OTG_OBJS)         \
-    $(CLI_OBJ)          \
-    $(OMG_OBJS)         \
-    $(OPT_OBJS)
-
-UTIL_incl = \
-    -I$(OPENAIR2_TOP)/UTIL      \
-    -I$(OSA_DIR)                \
-    -I$(LFDS_DIR)/inc           \
-    -I$(MEM_DIR)                \
-    -I$(LIST_DIR)               \
-    -I$(FIFO_DIR)               \
-    -I$(OCG_DIR)                \
-    -I$(LOG_DIR)                \
-    -I$(MATH_DIR)               \
-    -I$(TIMER_DIR)              \
-    -I$(OMG_DIR)                \
-    -I$(OTG_DIR)                \
-    -I$(CLI_DIR)                \
-    -I$(OPT_DIR)                \
-    -I$(OMV_DIR)
diff --git a/openair2/UTIL/OCG/OCG_config_mobi.c b/openair2/UTIL/OCG/OCG_config_mobi.c
index cef4c5543b0705f90c9122c0ec6e69dd8d208417..b3100a421463dbc6bc8d3c1e7222c7166b2907cb 100644
--- a/openair2/UTIL/OCG/OCG_config_mobi.c
+++ b/openair2/UTIL/OCG/OCG_config_mobi.c
@@ -39,84 +39,60 @@
 #include "OCG_config_mobi.h"
 /*----------------------------------------------------------------------------*/
 
-int config_mobi(char mobigen_filename[FILENAME_LENGTH_MAX], char filename[FILENAME_LENGTH_MAX])
-{
+int config_mobi(char mobigen_filename[FILENAME_LENGTH_MAX], char filename[FILENAME_LENGTH_MAX]) {
   // for the xml writer, refer to http://xmlsoft.org/html/libxml-xmlwriter.html
-
-  char dir_to_mobigen_file[FILENAME_LENGTH_MAX + DIR_LENGTH_MAX] = "";
+  char dir_to_mobigen_file[FILENAME_LENGTH_MAX + DIR_LENGTH_MAX];
   char mobi_file[FILENAME_LENGTH_MAX + DIR_LENGTH_MAX] = "";
   xmlTextWriterPtr writer;
-
   strcpy(dir_to_mobigen_file, DIR_TO_MOBIGEN);
   strcat(dir_to_mobigen_file, mobigen_filename);
   /* Create a new XmlWriter for uri, with no compression. */
   writer = xmlNewTextWriterFilename(dir_to_mobigen_file, 0);
-
   // set the output format of the XML file
   xmlTextWriterSetIndent(writer, 1);
   xmlTextWriterSetIndentString(writer, "	");
-
   /* Start the document with the xml default for the version,
    * encoding ISO 8859-1 and the default for the standalone
    * declaration. */
   xmlTextWriterStartDocument(writer, NULL, NULL, NULL);
-
   /* Start an element named "EXAMPLE". Since this is the first
    * element, this will be the root element of the document. */
   xmlTextWriterStartElement(writer, "universe");
-
   /* Write an element named "X_ORDER_ID" as child of HEADER. */
   xmlTextWriterWriteFormatElement(writer, "dimx", "%lf", oai_emulation.topo_config.area.x);
-
   /* Write an element named "X_ORDER_ID" as child of HEADER. */
   xmlTextWriterWriteFormatElement(writer, "dimy", "%lf", oai_emulation.topo_config.area.y);
-
   xmlTextWriterWriteFormatElement(writer, "seed", "%d", 1);
-
   xmlTextWriterStartElement(writer, "extension");
   xmlTextWriterWriteAttribute(writer, "class", "de.uni_stuttgart.informatik.canu.mobisim.simulations.TimeSimulation");
   xmlTextWriterWriteFormatAttribute(writer, "param", "%lf", oai_emulation.emu_config.emu_time);
   xmlTextWriterEndElement(writer);
-
   xmlTextWriterStartElement(writer, "extension");
   xmlTextWriterWriteAttribute(writer, "class", "de.uni_stuttgart.informatik.canu.spatialmodel.core.SpatialModel");
   xmlTextWriterWriteFormatAttribute(writer, "max_x", "%lf", oai_emulation.topo_config.area.x);
   xmlTextWriterWriteFormatAttribute(writer, "max_y", "%lf", oai_emulation.topo_config.area.y);
   xmlTextWriterWriteAttribute(writer, "min_x", "0");
   xmlTextWriterWriteAttribute(writer, "min_y", "0");
-
   xmlTextWriterWriteFormatElement(writer, "dump_boundary_points", "%s", "false");
-
   xmlTextWriterWriteFormatElement(writer, "separated_flow", "%s", "false");
-
   xmlTextWriterWriteFormatElement(writer, "max_traffic_lights", "%d", 500);
-
   xmlTextWriterEndElement(writer);
-
   xmlTextWriterStartElement(writer, "extension");
   xmlTextWriterWriteAttribute(writer, "class", "de.uni_stuttgart.informatik.canu.mobisim.extensions.ReportNodeMobility");
-
   strcpy(mobi_file, MOBI_XML_FOLDER);
   strcat(mobi_file, filename);
   xmlTextWriterWriteAttribute(writer, "output", mobi_file);
-
   xmlTextWriterWriteFormatElement(writer, "step", "%d", 1);
-
   xmlTextWriterEndElement(writer);
-
   xmlTextWriterStartElement(writer, "nodegroup");
   xmlTextWriterWriteAttribute(writer, "car2x", "false");
   xmlTextWriterWriteAttribute(writer, "id", "");
   xmlTextWriterWriteAttribute(writer, "n", "50");
   xmlTextWriterWriteAttribute(writer, "type", "car");
-
   xmlTextWriterStartElement(writer, "position");
   xmlTextWriterWriteAttribute(writer, "random", "true");
-
   xmlTextWriterWriteFormatElement(writer, "z", "%s", "0.0");
-
   xmlTextWriterEndElement(writer);
-
   xmlTextWriterStartElement(writer, "extension");
   xmlTextWriterWriteAttribute(writer, "class", "de.uni_stuttgart.informatik.canu.mobisim.mobilitymodels.RandomWaypointWalk");
 
@@ -134,12 +110,8 @@ int config_mobi(char mobigen_filename[FILENAME_LENGTH_MAX], char filename[FILENA
 
   // Close the element named HEADER.
   xmlTextWriterEndElement(writer);
-
-
   xmlTextWriterEndDocument(writer);
-
   xmlFreeTextWriter(writer);
-
   return MODULE_OK;
 }
 
diff --git a/openair2/UTIL/OCG/OCG_generate_report.c b/openair2/UTIL/OCG/OCG_generate_report.c
index fa1ed191e62afa1cc9fa7cb1d9b8a5f38ac9dcc6..a48b3a7af7583bf46628dfe5053364ca65886dd8 100644
--- a/openair2/UTIL/OCG/OCG_generate_report.c
+++ b/openair2/UTIL/OCG/OCG_generate_report.c
@@ -42,39 +42,29 @@
 /*----------------------------------------------------------------------------*/
 
 
-int generate_report(char dst_dir[DIR_LENGTH_MAX], char filename[FILENAME_LENGTH_MAX])
-{
+int generate_report(char dst_dir[DIR_LENGTH_MAX], char filename[FILENAME_LENGTH_MAX]) {
   // for the xml writer, refer to http://xmlsoft.org/html/libxml-xmlwriter.html
-
-  char dst_file[FILENAME_LENGTH_MAX + DIR_LENGTH_MAX] = "";
-  strncat(dst_file, dst_dir, FILENAME_LENGTH_MAX + DIR_LENGTH_MAX - strlen(dst_file) - 1);
-  strncat(dst_file, filename, FILENAME_LENGTH_MAX + DIR_LENGTH_MAX - strlen(dst_file) - 1);
-
+  char dst_file[FILENAME_LENGTH_MAX + DIR_LENGTH_MAX];
+  strncpy(dst_file, dst_dir, FILENAME_LENGTH_MAX + DIR_LENGTH_MAX - strlen(filename) - 1);
+  strcat(dst_file, filename);
   xmlTextWriterPtr writer;
-
   writer = xmlNewTextWriterFilename(dst_file, 0);
-
   // set the output format of the XML file
   xmlTextWriterSetIndent(writer, 1);
-  xmlTextWriterSetIndentString(writer,(unsigned char*) "	");
-
+  xmlTextWriterSetIndentString(writer,(unsigned char *) "	");
   xmlTextWriterStartDocument(writer, NULL, NULL, NULL);
-
   /* Write an element named "X_ORDER_ID" as child of HEADER. */
-  xmlTextWriterWriteFormatElement(writer,(unsigned char*) "COMMENT           ", "	in this output file, %d means NOT_PROCESSED; %d means NO_FILE; %d means ERROR; %d means OK	", MODULE_NOT_PROCESSED,
+  xmlTextWriterWriteFormatElement(writer,(unsigned char *) "COMMENT           ", "	in this output file, %d means NOT_PROCESSED; %d means NO_FILE; %d means ERROR; %d means OK	", MODULE_NOT_PROCESSED,
                                   NO_FILE, MODULE_ERROR, MODULE_OK);
-  xmlTextWriterWriteFormatElement(writer,(unsigned char*) "OCG_GET_OPT       ", "	%d	", get_opt_OK);
-  xmlTextWriterWriteFormatElement(writer,(unsigned char*) "OCG_DETECT_FILE   ", "	%d	", detect_file_OK);
-  xmlTextWriterWriteFormatElement(writer,(unsigned char*) "OCG_PARSE_FILENAME", "	%d	", parse_filename_OK);
-  xmlTextWriterWriteFormatElement(writer,(unsigned char*) "OCG_CREATE_DIR    ", "	%d	", create_dir_OK);
-  xmlTextWriterWriteFormatElement(writer,(unsigned char*) "OCG_PARSE_XML     ", "	%d	", parse_XML_OK);
-  xmlTextWriterWriteFormatElement(writer,(unsigned char*) "OCG_SAVE_XML      ", "	%d	", save_XML_OK);
+  xmlTextWriterWriteFormatElement(writer,(unsigned char *) "OCG_GET_OPT       ", "	%d	", get_opt_OK);
+  xmlTextWriterWriteFormatElement(writer,(unsigned char *) "OCG_DETECT_FILE   ", "	%d	", detect_file_OK);
+  xmlTextWriterWriteFormatElement(writer,(unsigned char *) "OCG_PARSE_FILENAME", "	%d	", parse_filename_OK);
+  xmlTextWriterWriteFormatElement(writer,(unsigned char *) "OCG_CREATE_DIR    ", "	%d	", create_dir_OK);
+  xmlTextWriterWriteFormatElement(writer,(unsigned char *) "OCG_PARSE_XML     ", "	%d	", parse_XML_OK);
+  xmlTextWriterWriteFormatElement(writer,(unsigned char *) "OCG_SAVE_XML      ", "	%d	", save_XML_OK);
   //  xmlTextWriterWriteFormatElement(writer, "OCG_CALL_EMU      ", " %d  ", call_emu_OK);
-
   xmlTextWriterEndDocument(writer);
-
   xmlFreeTextWriter(writer);
-
   LOG_I(OCG, "A report of OCG is generated in directory \"%s\"\n\n", dst_dir);
   return MODULE_OK;
 }
diff --git a/openair2/UTIL/OMG/README.TXT b/openair2/UTIL/OMG/README.TXT
old mode 100755
new mode 100644
diff --git a/openair2/UTIL/OMG/omg.c b/openair2/UTIL/OMG/omg.c
index 6a1ada01568b1d079b69f1e05264de868ff00fff..f13da86c9f7395f6d2076aa9325ae3f535239ac4 100644
--- a/openair2/UTIL/OMG/omg.c
+++ b/openair2/UTIL/OMG/omg.c
@@ -46,21 +46,20 @@
 #include "grid.h"
 #include "steadystaterwp.h"
 #ifdef SUMO_IF
-#include "sumo.h"
-#endif 
+  #include "sumo.h"
+#endif
 #include "../OMV/structures.h"
 //#define STANDALONE
 
 float n_frames = 20.0;
 
-int omv_write (int pfd, node_list * ue_node_list, Data_Flow_Unit omv_data);
+int omv_write (int pfd, node_list *ue_node_list, Data_Flow_Unit omv_data);
 void omv_end (int pfd, Data_Flow_Unit omv_data);
 int omv_enabled;
 
 /*initialze global parameters*/
 void
-init_omg_global_params (void)
-{
+init_omg_global_params (void) {
   int mob_t, node_t, i;
   xloc_div = 10.0;
   yloc_div = 10.0;
@@ -86,92 +85,86 @@ init_omg_global_params (void)
 
 /*initiate mobility generator*/
 void
-init_mobility_generator (omg_global_param omg_param_list[])
-{
+init_mobility_generator (omg_global_param omg_param_list[]) {
   int node_t, mobility_t;
 
   for (node_t = eNB; node_t < MAX_NUM_NODE_TYPES; node_t++) {
-
     mobility_t = omg_param_list[node_t].mobility_type;
 
     switch (mobility_t) {
+      case STATIC:
+        start_static_generator (omg_param_list[node_t]);
+        break;
 
-    case STATIC:
-      start_static_generator (omg_param_list[node_t]);
-      break;
-
-    case RWP:
-      start_rwp_generator (omg_param_list[node_t]);
-      break;
+      case RWP:
+        start_rwp_generator (omg_param_list[node_t]);
+        break;
 
-    case RWALK:
-      start_rwalk_generator (omg_param_list[node_t]);
-      break;
+      case RWALK:
+        start_rwalk_generator (omg_param_list[node_t]);
+        break;
 
-    case TRACE:
-      start_trace_generator (omg_param_list[node_t]);
-      break;
+      case TRACE:
+        start_trace_generator (omg_param_list[node_t]);
+        break;
 #ifdef SUMO_IF
-    case SUMO:
-      start_sumo_generator (omg_param_list[node_t]);
-      break;
-#endif 
-    case STEADY_RWP:
-      start_steadystaterwp_generator (omg_param_list[node_t]);
-      break;
 
-    default:
-      LOG_W (OMG, "Unsupported generator\n");
-    }
+      case SUMO:
+        start_sumo_generator (omg_param_list[node_t]);
+        break;
+#endif
 
+      case STEADY_RWP:
+        start_steadystaterwp_generator (omg_param_list[node_t]);
+        break;
 
+      default:
+        LOG_W (OMG, "Unsupported generator\n");
+    }
   }
-
 }
 
 /**************************************************************************************/
 /*stop sumo mobiity generator*/
 void
-stop_mobility_generator (omg_global_param * omg_param_list)
-{
+stop_mobility_generator (omg_global_param *omg_param_list) {
   int i;
 
   for (i = 0; i < MAX_NUM_NODE_TYPES; i++) {
     switch (omg_param_list[i].mobility_type) {
+      case STATIC:
+        break;
 
-    case STATIC:
-      break;
-
-    case RWP:
-      break;
+      case RWP:
+        break;
 
-    case RWALK:
-      break;
+      case RWALK:
+        break;
 
-    case TRACE:
-      clear_list ();
-      break;
+      case TRACE:
+        clear_list ();
+        break;
 
-    case STEADY_RWP:
-      break;
+      case STEADY_RWP:
+        break;
 #ifdef SUMO_IF
-    case SUMO:
-      stop_sumo_generator ();
-      //LOG_D(OMG," --------OMG will interface with SUMO for mobility generation-------- \n");
-      break;
-#endif 
-    default:
-      LOG_W (OMG, "Unsupported generator\n");
+
+      case SUMO:
+        stop_sumo_generator ();
+        //LOG_D(OMG," --------OMG will interface with SUMO for mobility generation-------- \n");
+        break;
+#endif
+
+      default:
+        LOG_W (OMG, "Unsupported generator\n");
     }
   }
-
 }
 
 /*****************************************************************************/
 
 void
-update_nodes (double cur_time)
-{
+update_nodes (double cur_time) {
   //LOG_D(OMG, "UPDATE NODES" );
   int i = 0;
 
@@ -180,38 +173,38 @@ update_nodes (double cur_time)
       update_node_vector (i, cur_time);
     }
   }
-
 }
 
 
 void
-update_node_vector (int mobility_type, double cur_time)
-{
+update_node_vector (int mobility_type, double cur_time) {
   //set_time(cur_time);
   switch (mobility_type) {
-  case RWP:
-    update_rwp_nodes (cur_time);
-    break;
+    case RWP:
+      update_rwp_nodes (cur_time);
+      break;
 
-  case RWALK:
-    update_rwalk_nodes (cur_time);
-    break;
+    case RWALK:
+      update_rwalk_nodes (cur_time);
+      break;
 
-  case TRACE:
-    update_trace_nodes (cur_time);
-    break;
+    case TRACE:
+      update_trace_nodes (cur_time);
+      break;
 #ifdef SUMO_IF
-  case SUMO:
-    // printf("in SUMO case \n");
-    update_sumo_nodes (cur_time);
-    break;
-#endif 
-  case STEADY_RWP:
-    update_steadystaterwp_nodes (cur_time);
-    break;
-
-  default:
-    LOG_W (OMG, "STATIC or Unsupported generator\n");
+
+    case SUMO:
+      // printf("in SUMO case \n");
+      update_sumo_nodes (cur_time);
+      break;
+#endif
+
+    case STEADY_RWP:
+      update_steadystaterwp_nodes (cur_time);
+      break;
+
+    default:
+      LOG_W (OMG, "STATIC or Unsupported generator\n");
   }
 }
 
@@ -219,50 +212,45 @@ update_node_vector (int mobility_type, double cur_time)
 
 /*return updated node position for a given node type*/
 node_list *
-get_current_positions (int mobility_type, int node_type, double cur_time)
-{
-
-
+get_current_positions (int mobility_type, int node_type, double cur_time) {
   get_nodes_positions (mobility_type, cur_time);
   return node_vector[node_type];
-
 }
 
 /*update current position of nodes for specific mobility type*/
 void
-get_nodes_positions (int mobility_type, double cur_time)
-{
+get_nodes_positions (int mobility_type, double cur_time) {
   //printf("%d \n",mobility_type);
-
   switch (mobility_type) {
-  case STATIC:
-    break;
+    case STATIC:
+      break;
 
-  case RWP:
-    get_rwp_positions_updated (cur_time);
-    break;
+    case RWP:
+      get_rwp_positions_updated (cur_time);
+      break;
 
-  case RWALK:
-    get_rwalk_positions_updated (cur_time);
-    break;
+    case RWALK:
+      get_rwalk_positions_updated (cur_time);
+      break;
 
-  case TRACE:
-    get_trace_positions_updated (cur_time);
-    break;
+    case TRACE:
+      get_trace_positions_updated (cur_time);
+      break;
 #ifdef SUMO_IF
-  case SUMO:
-    LOG_I (OMG, "getting positions from SUMO\n");
-    get_sumo_positions_updated (cur_time);
-    break;
-#endif 
-  case STEADY_RWP:
-    get_steadystaterwp_positions_updated (cur_time);
-    break;
-
-  default:
-    LOG_E (OMG, " Unsupported generator \n");
-  }
 
+    case SUMO:
+      LOG_I (OMG, "getting positions from SUMO\n");
+      get_sumo_positions_updated (cur_time);
+      break;
+#endif
+
+    case STEADY_RWP:
+      get_steadystaterwp_positions_updated (cur_time);
+      break;
+
+    default:
+      LOG_E (OMG, " Unsupported generator \n");
+  }
 }
 
 /***************************************************************/
@@ -270,10 +258,8 @@ get_nodes_positions (int mobility_type, double cur_time)
 // get the position for a specific node
 
 node_struct *
-get_node_position (int node_type, int nid)
-{
+get_node_position (int node_type, int nid) {
   node_list *tmp;
-
   tmp = node_vector[node_type];
 
   while (tmp != NULL) {
@@ -289,15 +275,12 @@ get_node_position (int node_type, int nid)
 
 /*set new mobility for a node*/
 void
-set_new_mob_type (int id, int node_t, int mob_t, double cur_time)
-{
-
+set_new_mob_type (int id, int node_t, int mob_t, double cur_time) {
   int prev_mob;
   node_list *tmp;
   //job_list *tmp2, *prev_job;
   pair_struct *pair;
   double pause_p;
-
   //find previous mobility type
   tmp = node_vector[node_t];
 
@@ -313,7 +296,6 @@ set_new_mob_type (int id, int node_t, int mob_t, double cur_time)
   //end
 
   if (tmp != NULL && prev_mob != mob_t) {
-
     //initialize node position
     if (mob_t == STATIC || mob_t == RWP || mob_t == RWALK || mob_t == STEADY_RWP) {
       tmp->node->x_pos =
@@ -341,61 +323,57 @@ set_new_mob_type (int id, int node_t, int mob_t, double cur_time)
     //end
 
     switch (mob_t) {
-
-    case STATIC:
-
-      break;
-
-    case RWP:
-      pair = (pair_struct *) malloc (sizeof (struct pair_struct));
-      pair->b = tmp->node;
-      sleep_rwp_node (pair, cur_time);
-      job_vector[RWP] = addjob (pair, job_vector[RWP]);
-      break;
-
-    case RWALK:
-      pair = (pair_struct *) malloc (sizeof (struct pair_struct));
-      pair->b = tmp->node;
-      sleep_rwalk_node (pair, cur_time);
-      job_vector[RWALK] = addjob (pair, job_vector[RWALK]);
-      break;
-
-    case STEADY_RWP:
-      tmp->node->event_num = 0;
-      pair = (pair_struct *) malloc (sizeof (struct pair_struct));
-      pair->b = tmp->node;
-      pause_p = pause_probability (omg_param_list[node_t]);
-
-      if (randomgen (0, 1) < pause_p)
-        sleep_steadystaterwp_node (pair, cur_time);
-      else
-        move_steadystaterwp_node (pair, cur_time);
-
-      break;
+      case STATIC:
+        break;
+
+      case RWP:
+        pair = (pair_struct *) malloc (sizeof (struct pair_struct));
+        pair->b = tmp->node;
+        sleep_rwp_node (pair, cur_time);
+        job_vector[RWP] = addjob (pair, job_vector[RWP]);
+        break;
+
+      case RWALK:
+        pair = (pair_struct *) malloc (sizeof (struct pair_struct));
+        pair->b = tmp->node;
+        sleep_rwalk_node (pair, cur_time);
+        job_vector[RWALK] = addjob (pair, job_vector[RWALK]);
+        break;
+
+      case STEADY_RWP:
+        tmp->node->event_num = 0;
+        pair = (pair_struct *) malloc (sizeof (struct pair_struct));
+        pair->b = tmp->node;
+        pause_p = pause_probability (omg_param_list[node_t]);
+
+        if (randomgen (0, 1) < pause_p)
+          sleep_steadystaterwp_node (pair, cur_time);
+        else
+          move_steadystaterwp_node (pair, cur_time);
+
+        break;
 #ifdef SUMO_IF
-    case SUMO:
-      LOG_E (OMG, "not possible to change mobility type to sumo \n");
-      break;
+
+      case SUMO:
+        LOG_E (OMG, "not possible to change mobility type to sumo \n");
+        break;
 #endif
-    case TRACE:
-      LOG_E (OMG, "not possible to change mobility type to trace \n");
-      break;
 
-    default:
-      LOG_E (OMG, " Unsupported generator \n");
-    }
+      case TRACE:
+        LOG_E (OMG, "not possible to change mobility type to trace \n");
+        break;
 
+      default:
+        LOG_E (OMG, " Unsupported generator \n");
+    }
   }
-
-
 }
 
 #ifdef STANDALONE
 
 /************************** get options ************************************/
 void
-usage (void)
-{
+usage (void) {
   fprintf (stderr,
            "\n\t-X: assign maximum width of the simulation area for UE nodes(X_max)"
            "\n\t-x: assign minimum width of the simulation area for UE nodes(X_min)"
@@ -443,8 +421,7 @@ usage (void)
 
 
 int
-get_options (int argc, char *argv[])
-{
+get_options (int argc, char *argv[]) {
   int node_t;
   char tag;
 
@@ -452,345 +429,342 @@ get_options (int argc, char *argv[])
             getopt (argc, argv,
                     "U:u:E:e:R:r:A:a:B:b:C:c:D:d:f:g:hI:i:J:j:k:L:l:N:n:P:p:S:s:T:t:vW:w:X:x:Y:y:Z:z:"))
          != EOF) {
-
-
     switch (tag) {
-
-    case 'U':
-      if (atoi (optarg) < 0) {
-        usage ();
-        exit (1);
-      }
-
-      omg_param_list[UE].nodes = atoi (optarg);
-      LOG_D (OMG, "#Number of UE nodes : %d \n",
-             omg_param_list[UE].nodes);
-      break;
-
-    case 'E':
-      if (atoi (optarg) < 0) {
-        usage ();
-        exit (1);
-      }
-
-      omg_param_list[eNB].nodes = atoi (optarg);
-      LOG_D (OMG, "#Number of eNB nodes : %d \n",
-             omg_param_list[eNB].nodes);
-      break;
-
-    case 'R':
-      if (atoi (optarg) < 0) {
-        usage ();
-        exit (1);
-      }
-
-      omg_param_list[RELAY].nodes = atoi (optarg);
-      LOG_D (OMG, "#Number of relay nodes : %d \n",
-             omg_param_list[RELAY].nodes);
-      break;
-
-    case 'k':
-      if (atof (optarg) < 0)
-        LOG_E (OMG, "#Number of frames can not be negative \n");
-
-      n_frames = abs (atof (optarg));
-      LOG_D (OMG, "#Number of frames : %f \n", n_frames);
-      break;
-
-    case 'u':
-      if (atoi (optarg) < 0 || atoi (optarg) >= MAX_NUM_MOB_TYPES) {
-        usage ();
-        exit (1);
-      }
-
-      omg_param_list[UE].mobility_type = atoi (optarg);
-      LOG_D (OMG, "#UE nodes mobility type: %d \n",
-             omg_param_list[UE].mobility_type);
-      break;
-
-    case 'e':
-      if (atoi (optarg) < 0 || atoi (optarg) >= MAX_NUM_MOB_TYPES) {
+      case 'U':
+        if (atoi (optarg) < 0) {
+          usage ();
+          exit (1);
+        }
+
+        omg_param_list[UE].nodes = atoi (optarg);
+        LOG_D (OMG, "#Number of UE nodes : %d \n",
+               omg_param_list[UE].nodes);
+        break;
+
+      case 'E':
+        if (atoi (optarg) < 0) {
+          usage ();
+          exit (1);
+        }
+
+        omg_param_list[eNB].nodes = atoi (optarg);
+        LOG_D (OMG, "#Number of eNB nodes : %d \n",
+               omg_param_list[eNB].nodes);
+        break;
+
+      case 'R':
+        if (atoi (optarg) < 0) {
+          usage ();
+          exit (1);
+        }
+
+        omg_param_list[RELAY].nodes = atoi (optarg);
+        LOG_D (OMG, "#Number of relay nodes : %d \n",
+               omg_param_list[RELAY].nodes);
+        break;
+
+      case 'k':
+        if (atof (optarg) < 0)
+          LOG_E (OMG, "#Number of frames can not be negative \n");
+
+        n_frames = abs (atof (optarg));
+        LOG_D (OMG, "#Number of frames : %f \n", n_frames);
+        break;
+
+      case 'u':
+        if (atoi (optarg) < 0 || atoi (optarg) >= MAX_NUM_MOB_TYPES) {
+          usage ();
+          exit (1);
+        }
+
+        omg_param_list[UE].mobility_type = atoi (optarg);
+        LOG_D (OMG, "#UE nodes mobility type: %d \n",
+               omg_param_list[UE].mobility_type);
+        break;
+
+      case 'e':
+        if (atoi (optarg) < 0 || atoi (optarg) >= MAX_NUM_MOB_TYPES) {
+          usage ();
+          exit (1);
+        }
+
+        omg_param_list[eNB].mobility_type = atoi (optarg);
+        LOG_D (OMG, "#eNB nodes mobility type: %d \n",
+               omg_param_list[eNB].mobility_type);
+        break;
+
+      case 'r':
+        if (atoi (optarg) < 0 || atoi (optarg) >= MAX_NUM_MOB_TYPES) {
+          usage ();
+          exit (1);
+        }
+
+        omg_param_list[RELAY].mobility_type = atoi (optarg);
+        LOG_D (OMG, "#relay nodes mobility type: %d \n",
+               omg_param_list[RELAY].mobility_type);
+        break;
+
+      case 's':
+        if (atof (optarg) < 0)
+          LOG_E (OMG, "#min sleep can not be negative \n");
+
+        omg_param_list[UE].min_sleep = fabs (atof (optarg));
+        LOG_D (OMG, "#UE min sleep is set to: %.2f \n",
+               omg_param_list[UE].min_sleep);
+        break;
+
+      case 'S':
+        if (atof (optarg) < 0)
+          LOG_E (OMG, "#max_sleep can not be negative \n");
+
+        omg_param_list[UE].max_sleep = fabs (atof (optarg));
+        LOG_D (OMG, "#UE max_sleep is set to : %.2f \n",
+               omg_param_list[UE].max_sleep);
+        break;
+
+      case 'l':
+        if (atof (optarg) < 0)
+          LOG_E (OMG, "#min sleep can not be negative or zero \n");
+
+        if (atof (optarg) != 0)
+          omg_param_list[eNB].min_sleep = fabs (atof (optarg));
+
+        LOG_D (OMG, "#eNB min sleep is set to : %.2f \n",
+               omg_param_list[eNB].min_sleep);
+        break;
+
+      case 'L':
+        if (atof (optarg) <= 0)
+          LOG_E (OMG, "#max_sleep can not be negative or zero \n");
+
+        if (atof (optarg) != 0)
+          omg_param_list[eNB].max_sleep = fabs (atof (optarg));
+
+        LOG_D (OMG, "#eNB max_sleep is set to : %.2f \n",
+               omg_param_list[eNB].max_sleep);
+        break;
+
+      case 'p':
+        if (atof (optarg) < 0)
+          LOG_E (OMG, "#min sleep can not be negative \n");
+
+        omg_param_list[RELAY].min_sleep = fabs (atof (optarg));
+        LOG_D (OMG, "#relay min sleep is set to: %.2f \n",
+               omg_param_list[RELAY].min_sleep);
+        break;
+
+      case 'P':
+        if (atof (optarg) < 0)
+          LOG_E (OMG, "#max_sleep can not be negative \n");
+
+        omg_param_list[RELAY].max_sleep = fabs (atof (optarg));
+        LOG_D (OMG, "#relay max_sleep is set to : %.2f \n",
+               omg_param_list[RELAY].max_sleep);
+        break;
+
+      case 'd':
+        if (atof (optarg) < 0)
+          LOG_E (OMG, "#min_speed  can not be negative \n");
+
+        if (atof (optarg) != 0)
+          omg_param_list[UE].min_speed = fabs (atof (optarg));
+
+        LOG_D (OMG, "#UE min_speed is set to: %.2f \n",
+               omg_param_list[UE].min_speed);
+        break;
+
+      case 'D':
+        if (atof (optarg) < 0)
+          LOG_E (OMG, "#max_speed  can not be negative \n");
+
+        omg_param_list[UE].max_speed = fabs (atof (optarg));
+        LOG_D (OMG, "#UE max_speed is set to: %.2f \n",
+               omg_param_list[UE].max_speed);
+        break;
+
+      case 'i':
+        if (atof (optarg) < 0)
+          LOG_E (OMG, "#min_speed  can not be negative \n");
+
+        if (atof (optarg) != 0)
+          omg_param_list[eNB].min_speed = fabs (atof (optarg));
+
+        LOG_D (OMG, "#eNB min_speed is set to: %.2f \n",
+               omg_param_list[eNB].min_speed);
+        break;
+
+      case 'I':
+        if (atof (optarg) < 0)
+          LOG_E (OMG, "#max_speed  can not be negative \n");
+
+        omg_param_list[eNB].max_speed = fabs (atof (optarg));
+        LOG_D (OMG, "#eNB max_speed is set to : %.2f \n",
+               omg_param_list[eNB].max_speed);
+        break;
+
+      case 'a':
+        if (atof (optarg) < 0)
+          LOG_E (OMG, "#min_speed  can not be negative \n");
+
+        if (atof (optarg) != 0)
+          omg_param_list[RELAY].min_speed = fabs (atof (optarg));
+
+        LOG_D (OMG, "#relay min_speed is set to : %.2f \n",
+               omg_param_list[RELAY].min_speed);
+        break;
+
+      case 'A':
+        if (atof (optarg) < 0)
+          LOG_E (OMG, "#max_speed  can not be negative \n");
+
+        omg_param_list[RELAY].max_speed = fabs (atof (optarg));
+        LOG_D (OMG, "#relay max_speed is set to: %.2f \n",
+               omg_param_list[RELAY].max_speed);
+        break;
+
+      case 'v':
+        omv_enabled = 1;
+        break;
+
+      case 'X':
+        omg_param_list[UE].max_x = fabs (atof (optarg));
+        LOG_D (OMG, "#UE X_max : %.2f \n", omg_param_list[UE].max_x);
+        break;
+
+      case 'x':
+        omg_param_list[UE].min_x = fabs (atof (optarg));
+        LOG_D (OMG, "#UE X_min : %.2f \n", omg_param_list[UE].min_x);
+        break;
+
+      case 'C':
+        omg_param_list[eNB].max_x = fabs (atof (optarg));
+        LOG_D (OMG, "#eNB X_max : %.2f \n", omg_param_list[eNB].max_x);
+        break;
+
+      case 'c':
+        omg_param_list[eNB].min_x = fabs (atof (optarg));
+        LOG_D (OMG, "#eNB X_min : %.2f \n", omg_param_list[eNB].min_x);
+        break;
+
+      case 'B':
+        omg_param_list[RELAY].max_x = fabs (atof (optarg));
+        LOG_D (OMG, "#relay X_max : %.2f \n", omg_param_list[RELAY].max_x);
+        break;
+
+      case 'b':
+        omg_param_list[RELAY].min_x = fabs (atof (optarg));
+        LOG_D (OMG, "#relay X_min : %.2f \n", omg_param_list[RELAY].min_x);
+        break;
+
+      case 'Y':
+        omg_param_list[UE].max_y = fabs (atof (optarg));
+        LOG_D (OMG, "#UE Y_max : %.2f \n", omg_param_list[UE].max_y);
+        break;
+
+      case 'y':
+        omg_param_list[UE].min_y = fabs (atof (optarg));
+        LOG_D (OMG, "#UE Y_min : %.2f \n", omg_param_list[UE].min_y);
+        break;
+
+      case 'Z':
+        omg_param_list[eNB].max_y = fabs (atof (optarg));
+        LOG_D (OMG, "#eNB Y_max : %.2f \n", omg_param_list[eNB].max_y);
+        break;
+
+      case 'z':
+        omg_param_list[eNB].min_y = fabs (atof (optarg));
+        LOG_D (OMG, "#eNB Y_min : %.2f \n", omg_param_list[eNB].min_y);
+        break;
+
+      case 'W':
+        omg_param_list[RELAY].max_y = fabs (atof (optarg));
+        LOG_D (OMG, "#relay Y_max : %.2f \n", omg_param_list[RELAY].max_y);
+        break;
+
+      case 'w':
+        omg_param_list[RELAY].min_y = fabs (atof (optarg));
+        LOG_D (OMG, "#relay Y_min : %.2f \n", omg_param_list[RELAY].min_y);
+        break;
+
+      case 'J':
+        if (atof (optarg) < 0)
+          LOG_E (OMG, "#Journey_time_max can not be negative \n");
+
+        omg_param_list[UE].max_journey_time = fabs (atof (optarg));
+        LOG_D (OMG, "UE Journey_time_max : %.2f \n",
+               omg_param_list[UE].max_journey_time);
+        break;
+
+      case 'j':
+        if (atof (optarg) < 0)
+          LOG_E (OMG, "#Journey_time_min can not be negative \n");
+
+        omg_param_list[UE].min_journey_time = fabs (atof (optarg));
+        LOG_D (OMG, "#UE Journey_time_min : %.2f \n",
+               omg_param_list[UE].min_journey_time);
+        break;
+
+      case 'T':
+        if (atof (optarg) < 0)
+          LOG_E (OMG, "#Journey_time_max can not be negative \n");
+
+        omg_param_list[eNB].max_journey_time = fabs (atof (optarg));
+        LOG_D (OMG, "#eNB Journey_time_max : %.2f \n",
+               omg_param_list[eNB].max_journey_time);
+        break;
+
+      case 't':
+        if (atof (optarg) < 0)
+          LOG_E (OMG, "#Journey_time_min can not be negative \n");
+
+        omg_param_list[eNB].min_journey_time = fabs (atof (optarg));
+        LOG_D (OMG, "#eNB Journey_time_min : %.2f \n",
+               omg_param_list[eNB].min_journey_time);
+        break;
+
+      case 'N':
+        if (atof (optarg) < 0)
+          LOG_E (OMG, "#Journey_time_max can not be negative \n");
+
+        omg_param_list[RELAY].max_journey_time = fabs (atof (optarg));
+        LOG_D (OMG, "#relay Journey_time_max : %.2f \n",
+               omg_param_list[RELAY].max_journey_time);
+        break;
+
+      case 'n':
+        if (atof (optarg) < 0)
+          LOG_E (OMG, "#Journey_time_min can not be negative \n");
+
+        omg_param_list[RELAY].min_journey_time = fabs (atof (optarg));
+        LOG_D (OMG, "#relay Journey_time_min : %.2f \n",
+               omg_param_list[RELAY].min_journey_time);
+        break;
+
+      case 'f':
+        for (node_t = eNB; node_t < MAX_NUM_NODE_TYPES; node_t++) {
+          omg_param_list[node_t].seed = atoi (optarg);
+          LOG_D (OMG, "#Seed is %d \n", omg_param_list[node_t].seed);
+        }
+
+        break;
+
+      case 'g':
+        if (atoi (optarg) < 1 || atoi (optarg) > 2) {
+          LOG_E (OMG, "#value given for graph should be 1 or 2 \n");
+          exit (-1);
+        }
+
+        grid = abs (atof (optarg));
+        LOG_D (OMG, "#graph value is %d \n", grid);
+        break;
+
+      case 'h':
         usage ();
-        exit (1);
-      }
-
-      omg_param_list[eNB].mobility_type = atoi (optarg);
-      LOG_D (OMG, "#eNB nodes mobility type: %d \n",
-             omg_param_list[eNB].mobility_type);
-      break;
+        break;
 
-    case 'r':
-      if (atoi (optarg) < 0 || atoi (optarg) >= MAX_NUM_MOB_TYPES) {
+      default:
         usage ();
         exit (1);
-      }
-
-      omg_param_list[RELAY].mobility_type = atoi (optarg);
-      LOG_D (OMG, "#relay nodes mobility type: %d \n",
-             omg_param_list[RELAY].mobility_type);
-      break;
-
-    case 's':
-      if (atof (optarg) < 0)
-        LOG_E (OMG, "#min sleep can not be negative \n");
-
-      omg_param_list[UE].min_sleep = fabs (atof (optarg));
-      LOG_D (OMG, "#UE min sleep is set to: %.2f \n",
-             omg_param_list[UE].min_sleep);
-      break;
-
-    case 'S':
-      if (atof (optarg) < 0)
-        LOG_E (OMG, "#max_sleep can not be negative \n");
-
-      omg_param_list[UE].max_sleep = fabs (atof (optarg));
-      LOG_D (OMG, "#UE max_sleep is set to : %.2f \n",
-             omg_param_list[UE].max_sleep);
-      break;
-
-    case 'l':
-      if (atof (optarg) < 0)
-        LOG_E (OMG, "#min sleep can not be negative or zero \n");
-
-      if (atof (optarg) != 0)
-        omg_param_list[eNB].min_sleep = fabs (atof (optarg));
-
-      LOG_D (OMG, "#eNB min sleep is set to : %.2f \n",
-             omg_param_list[eNB].min_sleep);
-      break;
-
-    case 'L':
-      if (atof (optarg) <= 0)
-        LOG_E (OMG, "#max_sleep can not be negative or zero \n");
-
-      if (atof (optarg) != 0)
-        omg_param_list[eNB].max_sleep = fabs (atof (optarg));
-
-      LOG_D (OMG, "#eNB max_sleep is set to : %.2f \n",
-             omg_param_list[eNB].max_sleep);
-      break;
-
-    case 'p':
-      if (atof (optarg) < 0)
-        LOG_E (OMG, "#min sleep can not be negative \n");
-
-      omg_param_list[RELAY].min_sleep = fabs (atof (optarg));
-      LOG_D (OMG, "#relay min sleep is set to: %.2f \n",
-             omg_param_list[RELAY].min_sleep);
-      break;
-
-    case 'P':
-      if (atof (optarg) < 0)
-        LOG_E (OMG, "#max_sleep can not be negative \n");
-
-      omg_param_list[RELAY].max_sleep = fabs (atof (optarg));
-      LOG_D (OMG, "#relay max_sleep is set to : %.2f \n",
-             omg_param_list[RELAY].max_sleep);
-      break;
-
-    case 'd':
-      if (atof (optarg) < 0)
-        LOG_E (OMG, "#min_speed  can not be negative \n");
-
-      if (atof (optarg) != 0)
-        omg_param_list[UE].min_speed = fabs (atof (optarg));
-
-      LOG_D (OMG, "#UE min_speed is set to: %.2f \n",
-             omg_param_list[UE].min_speed);
-      break;
-
-    case 'D':
-      if (atof (optarg) < 0)
-        LOG_E (OMG, "#max_speed  can not be negative \n");
-
-      omg_param_list[UE].max_speed = fabs (atof (optarg));
-      LOG_D (OMG, "#UE max_speed is set to: %.2f \n",
-             omg_param_list[UE].max_speed);
-      break;
-
-    case 'i':
-      if (atof (optarg) < 0)
-        LOG_E (OMG, "#min_speed  can not be negative \n");
-
-      if (atof (optarg) != 0)
-        omg_param_list[eNB].min_speed = fabs (atof (optarg));
-
-      LOG_D (OMG, "#eNB min_speed is set to: %.2f \n",
-             omg_param_list[eNB].min_speed);
-      break;
-
-    case 'I':
-      if (atof (optarg) < 0)
-        LOG_E (OMG, "#max_speed  can not be negative \n");
-
-      omg_param_list[eNB].max_speed = fabs (atof (optarg));
-      LOG_D (OMG, "#eNB max_speed is set to : %.2f \n",
-             omg_param_list[eNB].max_speed);
-      break;
-
-    case 'a':
-      if (atof (optarg) < 0)
-        LOG_E (OMG, "#min_speed  can not be negative \n");
-
-      if (atof (optarg) != 0)
-        omg_param_list[RELAY].min_speed = fabs (atof (optarg));
-
-      LOG_D (OMG, "#relay min_speed is set to : %.2f \n",
-             omg_param_list[RELAY].min_speed);
-      break;
-
-    case 'A':
-      if (atof (optarg) < 0)
-        LOG_E (OMG, "#max_speed  can not be negative \n");
-
-      omg_param_list[RELAY].max_speed = fabs (atof (optarg));
-      LOG_D (OMG, "#relay max_speed is set to: %.2f \n",
-             omg_param_list[RELAY].max_speed);
-      break;
-
-    case 'v':
-      omv_enabled = 1;
-      break;
-
-    case 'X':
-      omg_param_list[UE].max_x = fabs (atof (optarg));
-      LOG_D (OMG, "#UE X_max : %.2f \n", omg_param_list[UE].max_x);
-      break;
-
-    case 'x':
-      omg_param_list[UE].min_x = fabs (atof (optarg));
-      LOG_D (OMG, "#UE X_min : %.2f \n", omg_param_list[UE].min_x);
-      break;
-
-    case 'C':
-      omg_param_list[eNB].max_x = fabs (atof (optarg));
-      LOG_D (OMG, "#eNB X_max : %.2f \n", omg_param_list[eNB].max_x);
-      break;
-
-    case 'c':
-      omg_param_list[eNB].min_x = fabs (atof (optarg));
-      LOG_D (OMG, "#eNB X_min : %.2f \n", omg_param_list[eNB].min_x);
-      break;
-
-    case 'B':
-      omg_param_list[RELAY].max_x = fabs (atof (optarg));
-      LOG_D (OMG, "#relay X_max : %.2f \n", omg_param_list[RELAY].max_x);
-      break;
-
-    case 'b':
-      omg_param_list[RELAY].min_x = fabs (atof (optarg));
-      LOG_D (OMG, "#relay X_min : %.2f \n", omg_param_list[RELAY].min_x);
-      break;
-
-    case 'Y':
-      omg_param_list[UE].max_y = fabs (atof (optarg));
-      LOG_D (OMG, "#UE Y_max : %.2f \n", omg_param_list[UE].max_y);
-      break;
-
-    case 'y':
-      omg_param_list[UE].min_y = fabs (atof (optarg));
-      LOG_D (OMG, "#UE Y_min : %.2f \n", omg_param_list[UE].min_y);
-      break;
-
-    case 'Z':
-      omg_param_list[eNB].max_y = fabs (atof (optarg));
-      LOG_D (OMG, "#eNB Y_max : %.2f \n", omg_param_list[eNB].max_y);
-      break;
-
-    case 'z':
-      omg_param_list[eNB].min_y = fabs (atof (optarg));
-      LOG_D (OMG, "#eNB Y_min : %.2f \n", omg_param_list[eNB].min_y);
-      break;
-
-    case 'W':
-      omg_param_list[RELAY].max_y = fabs (atof (optarg));
-      LOG_D (OMG, "#relay Y_max : %.2f \n", omg_param_list[RELAY].max_y);
-      break;
-
-    case 'w':
-      omg_param_list[RELAY].min_y = fabs (atof (optarg));
-      LOG_D (OMG, "#relay Y_min : %.2f \n", omg_param_list[RELAY].min_y);
-      break;
-
-    case 'J':
-      if (atof (optarg) < 0)
-        LOG_E (OMG, "#Journey_time_max can not be negative \n");
-
-      omg_param_list[UE].max_journey_time = fabs (atof (optarg));
-      LOG_D (OMG, "UE Journey_time_max : %.2f \n",
-             omg_param_list[UE].max_journey_time);
-      break;
-
-    case 'j':
-      if (atof (optarg) < 0)
-        LOG_E (OMG, "#Journey_time_min can not be negative \n");
-
-      omg_param_list[UE].min_journey_time = fabs (atof (optarg));
-      LOG_D (OMG, "#UE Journey_time_min : %.2f \n",
-             omg_param_list[UE].min_journey_time);
-      break;
-
-    case 'T':
-      if (atof (optarg) < 0)
-        LOG_E (OMG, "#Journey_time_max can not be negative \n");
-
-      omg_param_list[eNB].max_journey_time = fabs (atof (optarg));
-      LOG_D (OMG, "#eNB Journey_time_max : %.2f \n",
-             omg_param_list[eNB].max_journey_time);
-      break;
-
-    case 't':
-      if (atof (optarg) < 0)
-        LOG_E (OMG, "#Journey_time_min can not be negative \n");
-
-      omg_param_list[eNB].min_journey_time = fabs (atof (optarg));
-      LOG_D (OMG, "#eNB Journey_time_min : %.2f \n",
-             omg_param_list[eNB].min_journey_time);
-      break;
-
-    case 'N':
-      if (atof (optarg) < 0)
-        LOG_E (OMG, "#Journey_time_max can not be negative \n");
-
-      omg_param_list[RELAY].max_journey_time = fabs (atof (optarg));
-      LOG_D (OMG, "#relay Journey_time_max : %.2f \n",
-             omg_param_list[RELAY].max_journey_time);
-      break;
-
-    case 'n':
-      if (atof (optarg) < 0)
-        LOG_E (OMG, "#Journey_time_min can not be negative \n");
-
-      omg_param_list[RELAY].min_journey_time = fabs (atof (optarg));
-      LOG_D (OMG, "#relay Journey_time_min : %.2f \n",
-             omg_param_list[RELAY].min_journey_time);
-      break;
-
-    case 'f':
-      for (node_t = eNB; node_t < MAX_NUM_NODE_TYPES; node_t++) {
-        omg_param_list[node_t].seed = atoi (optarg);
-        LOG_D (OMG, "#Seed is %d \n", omg_param_list[node_t].seed);
-      }
-
-      break;
-
-    case 'g':
-      if (atoi (optarg) < 1 || atoi (optarg) > 2) {
-        LOG_E (OMG, "#value given for graph should be 1 or 2 \n");
-        exit (-1);
-      }
-
-      grid = abs (atof (optarg));
-      LOG_D (OMG, "#graph value is %d \n", grid);
-      break;
-
-    case 'h':
-      usage ();
-      break;
-
-    default:
-      usage ();
-      exit (1);
     }
   }
 
@@ -800,8 +774,7 @@ get_options (int argc, char *argv[])
 /**************************** main **********************************/
 
 int
-main (int argc, char *argv[])
-{
+main (int argc, char *argv[]) {
   int i, node_type;
   double cur_time = 0.0;
   double ms = 0.0;
@@ -824,8 +797,6 @@ main (int argc, char *argv[])
 
   //default parameters
   for (node_type = eNB; node_type < MAX_NUM_NODE_TYPES; node_type++) {
-
-
     if (node_type == UE)
       omg_param_list[node_type].nodes = 5;
     else
@@ -857,22 +828,16 @@ main (int argc, char *argv[])
     omg_param_list[node_type].sumo_port = 8890;
   }
 
-
   init_omg_global_params ();  //initialize global paramaters
-
   get_options (argc, argv); // overwrite the default params if any input parameter
 
   for (node_type = eNB; node_type < MAX_NUM_NODE_TYPES; node_type++) {
     omg_param_list[node_type].max_vertices =
       max_vertices_ongrid (omg_param_list[node_type]);
-
     omg_param_list[node_type].max_block_num =
       max_connecteddomains_ongrid (omg_param_list[node_type]);
-
   }
 
-
-
   init_mobility_generator (omg_param_list); //initialize choosen mobility generator
 
   // ****************init omv********************
@@ -884,30 +849,25 @@ main (int argc, char *argv[])
     LOG_I (EMU, "Stating the OMV path %s pfd[0] %d pfd[1] %d \n", full_name,
            pfd[0], pfd[1]);
 
-
-
-
-
     switch (fork ()) {
-    case -1:
-      perror ("fork failed \n");
-      break;
-
-    case 0:
-      if (close (pfd[1]) == -1)
-        perror ("close on write\n");
-
-      sprintf (fdstr, "%d", pfd[0]);
-      sprintf (num_enb, "%d", 1);
-      sprintf (num_ue, "%d", omg_param_list[UE].nodes);
-      sprintf (x_area, "%f", omg_param_list[UE].max_x);
-      sprintf (y_area, "%f", omg_param_list[UE].max_y);
-      sprintf (z_area, "%f", 200.0);
-      sprintf (frames, "%d", (int) n_frames);
-
-      execl (full_name, "OMV", fdstr, frames, num_enb, num_ue, x_area,
-             y_area, z_area, NULL);
-      perror ("error in execl the OMV");
+      case -1:
+        perror ("fork failed \n");
+        break;
+
+      case 0:
+        if (close (pfd[1]) == -1)
+          perror ("close on write\n");
+
+        sprintf (fdstr, "%d", pfd[0]);
+        sprintf (num_enb, "%d", 1);
+        sprintf (num_ue, "%d", omg_param_list[UE].nodes);
+        sprintf (x_area, "%f", omg_param_list[UE].max_x);
+        sprintf (y_area, "%f", omg_param_list[UE].max_y);
+        sprintf (z_area, "%f", 200.0);
+        sprintf (frames, "%d", (int) n_frames);
+        execl (full_name, "OMV", fdstr, frames, num_enb, num_ue, x_area,
+               y_area, z_area, NULL);
+        perror ("error in execl the OMV");
     }
 
     //parent
@@ -918,7 +878,6 @@ main (int argc, char *argv[])
   //******************************
 
   for (emu_info_time = 0.0; emu_info_time <= n_frames; emu_info_time += 0.1) {
-
     update_nodes (emu_info_time);
     time_s = round (emu_info_time * 1000.0);
 
@@ -929,7 +888,6 @@ main (int argc, char *argv[])
                                node_type, emu_info_time);
 
       if (current_positions != NULL)
-
         display_job_list (emu_info_time,
                           job_vector[omg_param_list
                                      [node_type].mobility_type]);
@@ -939,12 +897,9 @@ main (int argc, char *argv[])
          nodes_avgspeed(job_vector[omg_param_list [node_type].mobility_type])); */
     }
 
-
     //display current postion of nodes
     if (omv_enabled == 1)
       omv_write (pfd[1], node_vector[SUMO], omv_data);
-
-
   }
 
   /*LOG_I(OMG,"#-----event average-----\n");
@@ -953,22 +908,19 @@ main (int argc, char *argv[])
      if(events[i]!=0)
      LOG_D(OMG,"%d %d \n",i,event_sum[i]/events[i]);
      } */
-
   stop_mobility_generator (omg_param_list);
 
   if (omv_enabled == 1)
     omv_end (pfd[1], omv_data);
 
   //clear_mem();
-
   return 0;
 }
 
 
 /**********************************sumo****************************/
 int
-omv_write (int pfd, node_list * ue_node_list, Data_Flow_Unit omv_data)
-{
+omv_write (int pfd, node_list *ue_node_list, Data_Flow_Unit omv_data) {
   int i = 0, j;
   omv_data.end = 0;
   // enb
@@ -979,7 +931,7 @@ omv_write (int pfd, node_list * ue_node_list, Data_Flow_Unit omv_data)
   omv_data.geo[i].node_type = 0;  //eNB
   omv_data.geo[i].Neighbors = 0;
 
-  for (i = 1; i < omg_param_list[SUMO].nodes + 1; i++) {
+  for (i = 1; i < omg_param_list[SUMO-1].nodes + 1; i++) {
     if (ue_node_list != NULL) {
       omv_data.geo[i].x =
         (int) (ue_node_list->node->x_pos <
@@ -988,7 +940,7 @@ omv_write (int pfd, node_list * ue_node_list, Data_Flow_Unit omv_data)
         (int) (ue_node_list->node->y_pos <
                0.0) ? 0.0 : ue_node_list->node->y_pos;
       omv_data.geo[i].z = 1.0;
-      omv_data.geo[i].mobility_type = omg_param_list[SUMO].mobility_type;
+      omv_data.geo[i].mobility_type = omg_param_list[SUMO-1].mobility_type;
       omv_data.geo[i].node_type = 1;  //UE
       ue_node_list = ue_node_list->next;
       omv_data.geo[i].Neighbors = 0;
@@ -1004,8 +956,7 @@ omv_write (int pfd, node_list * ue_node_list, Data_Flow_Unit omv_data)
 }
 
 void
-omv_end (int pfd, Data_Flow_Unit omv_data)
-{
+omv_end (int pfd, Data_Flow_Unit omv_data) {
   omv_data.end = 1;
 
   if (write (pfd, &omv_data, sizeof (struct Data_Flow_Unit)) == -1)
diff --git a/openair2/UTIL/OMG/omg_hashtable.c b/openair2/UTIL/OMG/omg_hashtable.c
index 32b3840af3966e51dc32469e1dce68e04a51beaa..a545c5fc6227da90c08bc11310d10a9f51b83dd9 100644
--- a/openair2/UTIL/OMG/omg_hashtable.c
+++ b/openair2/UTIL/OMG/omg_hashtable.c
@@ -43,8 +43,7 @@
  * @returns hash_table_element_t object when success
  * @returns NULL when no memory
  */
-hash_table_element_t * hash_table_element_new(void)
-{
+hash_table_element_t *hash_table_element_new(void) {
   //INFO("creating a new hash table element");
   return calloc(1, hash_table_element_s);
 }
@@ -54,8 +53,7 @@ hash_table_element_t * hash_table_element_new(void)
  * @param table table from which element has to be deleted
  * @param element hash table element to be deleted
  */
-void hash_table_element_delete(omg_hash_table_t * table, hash_table_element_t * element)
-{
+void hash_table_element_delete(omg_hash_table_t *table, hash_table_element_t *element) {
   //INFO("Deleting an hash table element");
   if (table->mode == MODE_COPY) {
     free(element->value);
@@ -74,8 +72,7 @@ void hash_table_element_delete(omg_hash_table_t * table, hash_table_element_t *
  * @returns omg_hash_table_t object which references the hash table
  * @returns NULL when no memory
  */
-omg_hash_table_t * hash_table_new(hash_table_mode_t mode)
-{
+omg_hash_table_t *hash_table_new(hash_table_mode_t mode) {
   //INFO("Creating a new hash table");
   omg_hash_table_t *table = calloc(1, SIZEOF_HASH_TABLE);
 
@@ -102,14 +99,13 @@ omg_hash_table_t * hash_table_new(hash_table_mode_t mode)
  * Function to delete the hash table
  * @param table hash table to be deleted
  */
-void hash_table_delete(omg_hash_table_t * table)
-{
+void hash_table_delete(omg_hash_table_t *table) {
   //INFO("Deleating a hash table");
   size_t i=0;
 
   for (; i<HASH_LEN; i++) {
     while (table->store_house[i]) {
-      hash_table_element_t * temp = table->store_house[i];
+      hash_table_element_t *temp = table->store_house[i];
       table->store_house[i] = table->store_house[i]->next;
       hash_table_element_delete(table, temp);
     }
@@ -129,8 +125,7 @@ void hash_table_delete(omg_hash_table_t * table)
  * @returns 0 on sucess
  * @returns -1 when no memory
  */
-int hash_table_add(omg_hash_table_t * table, void * key, size_t key_len, void * value, size_t value_len)
-{
+int hash_table_add(omg_hash_table_t *table, void *key, size_t key_len, void *value, size_t value_len) {
   if ((table->key_count / table->key_num) >= table->key_ratio) {
     //LOG("Ratio(%d) reached the set limit %d\nExpanding hash_table", (table->key_count / table->key_num), table->key_ratio);
     hash_table_resize(table, table->key_num*2);
@@ -138,7 +133,7 @@ int hash_table_add(omg_hash_table_t * table, void * key, size_t key_len, void *
   }
 
   size_t hash = HASH(key, key_len);
-  hash_table_element_t * element = hash_table_element_new();
+  hash_table_element_t *element = hash_table_element_new();
 
   if (!element) {
     //INFO("Cannot allocate memory for element");
@@ -197,7 +192,7 @@ int hash_table_add(omg_hash_table_t * table, void * key, size_t key_len, void *
     table->key_count++;
   } else {
     //LOG("Conflicts adding element at %d", (int)hash);
-    hash_table_element_t * temp = table->store_house[hash];
+    hash_table_element_t *temp = table->store_house[hash];
 
     while(temp->next) {
       while(temp->next && temp->next->key_len!=key_len) {
@@ -234,8 +229,7 @@ int hash_table_add(omg_hash_table_t * table, void * key, size_t key_len, void *
  * @returns 0 on sucess
  * @returns -1 when key is not found
  */
-int hash_table_remove(omg_hash_table_t * table, void * key, size_t key_len)
-{
+int hash_table_remove(omg_hash_table_t *table, void *key, size_t key_len) {
   //INFO("Deleting a key-value pair from the hash table");
   if ((table->key_num/ table->key_count) >= table->key_ratio) {
     //LOG("Ratio(%d) reached the set limit %d\nContracting hash_table", (table->key_num / table->key_count), table->key_ratio);
@@ -290,8 +284,7 @@ int hash_table_remove(omg_hash_table_t * table, void * key, size_t key_len)
  * @returns NULL when key is not found in the hash table
  * @returns void* pointer to the value in the table
  */
-void * hash_table_lookup(omg_hash_table_t * table, void * key, size_t key_len)
-{
+void *hash_table_lookup(omg_hash_table_t *table, void *key, size_t key_len) {
   size_t hash = HASH(key, key_len);
 
   //LOG("Looking up a key-value pair for hash -> %d", (int)hash);
@@ -328,8 +321,7 @@ void * hash_table_lookup(omg_hash_table_t * table, void * key, size_t key_len)
  * @returns 0 when key is not found
  * @returns 1 when key is found
  */
-int hash_table_has_key(omg_hash_table_t * table, void * key, size_t key_len)
-{
+int hash_table_has_key(omg_hash_table_t *table, void *key, size_t key_len) {
   size_t hash = HASH(key, key_len);
 
   //LOG("Searching for key with hash -> %d", (int)hash);
@@ -365,11 +357,10 @@ int hash_table_has_key(omg_hash_table_t * table, void * key, size_t key_len)
  * @param keys a void** pointer where keys are filled in (memory allocated internally and must be freed)
  * @return total number of keys filled in keys
  */
-size_t hash_table_get_keys(omg_hash_table_t * table, void ** keys)
-{
+size_t hash_table_get_keys(omg_hash_table_t *table, void **keys) {
   size_t i = 0;
   size_t count = 0;
-  keys = calloc(table->key_count, sizeof(void *));
+  keys = calloc(table->key_count, sizeof(void *)*HASH_LEN);
 
   for(i=0; i<HASH_LEN; i++) {
     if (table->store_house[i]) {
@@ -403,8 +394,7 @@ size_t hash_table_get_keys(omg_hash_table_t * table, void ** keys)
  * @returns 1 when no memory
  * @returns count of elements
  */
-size_t hash_table_get_elements(omg_hash_table_t * table, hash_table_element_t *** elements)
-{
+size_t hash_table_get_elements(omg_hash_table_t *table, hash_table_element_t *** elements) {
   size_t i = 0;
   size_t count = 0;
   (*elements) = (hash_table_element_t **) calloc(table->key_count, sizeof(hash_table_element_t *));
@@ -446,8 +436,7 @@ size_t hash_table_get_elements(omg_hash_table_t * table, hash_table_element_t **
  * @param max_key max value of the hash to be returned by the function
  * @returns hash value belonging to [0, max_key)
  */
-uint16_t hash_table_do_hash(void * key, size_t key_len, uint16_t max_key)
-{
+uint16_t hash_table_do_hash(void *key, size_t key_len, uint16_t max_key) {
   uint16_t *ptr = (uint16_t *) key;
   uint16_t hash = 0xbabe; // WHY NOT
   size_t i = 0;
@@ -469,10 +458,9 @@ uint16_t hash_table_do_hash(void * key, size_t key_len, uint16_t max_key)
  * @returns -2 when no emmory for new store house
  * @returns 0 when sucess
  */
-int hash_table_resize(omg_hash_table_t *table, size_t len)
-{
+int hash_table_resize(omg_hash_table_t *table, size_t len) {
   //LOG("resizing hash table from %d to %d", table->key_num, len);
-  hash_table_element_t ** elements;
+  hash_table_element_t **elements;
   size_t count;
   // FIXME traversing the elements twice, change it some time soon
   count = hash_table_get_elements(table, &elements);
@@ -483,7 +471,7 @@ int hash_table_resize(omg_hash_table_t *table, size_t len)
   }
 
   // keep the current store house in case we dont get more memory
-  hash_table_element_t ** temp = table->store_house;
+  hash_table_element_t **temp = table->store_house;
   table->store_house = calloc(len, sizeof(hash_table_element_t *));
 
   if (!table->store_house) {
diff --git a/openair2/UTIL/OPT/opt.h b/openair2/UTIL/OPT/opt.h
index b4ff3b5006bbf4b5ad9b1d4bdc4ac7c731a9ae1a..5ae19f9b552e1f08d3206b81ac5196c4e17f7310 100644
--- a/openair2/UTIL/OPT/opt.h
+++ b/openair2/UTIL/OPT/opt.h
@@ -33,26 +33,23 @@ This header file must be included */
 #define OPT_H_
 
 #ifndef sys_include
-#define sys_include
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
-#include <time.h>
+  #define sys_include
+  #include <sys/types.h>
+  #include <sys/socket.h>
+  #include <netinet/in.h>
+  #include <arpa/inet.h>
+  #include <netdb.h>
+  #include <stdio.h>
+  #include <stdlib.h>
+  #include <string.h>
+  #include <errno.h>
+  #include <unistd.h>
+  #include <time.h>
 #endif
 #ifndef project_include
-#define project_include
-#include "common/utils/LOG/log_if.h"
-// #include "UTIL/LOG/log_extern.h"
-//#include "PHY/defs.h"
-//#include "PHY/extern.h"
-#include "PHY/impl_defs_lte.h"
+  #define project_include
+  #include "common/utils/LOG/log_if.h"
+  #include "PHY/impl_defs_lte.h"
 #endif
 
 #define PACKET_MAC_LTE_DEFAULT_UDP_PORT (9999)
@@ -65,6 +62,32 @@ typedef guint8   gboolean;
 #include "packet-mac-lte.h"
 #include "mac_pcap.h"
 
+/* OPT parameters definitions */
+#define OPT_CONFIGPREFIX "opt"
+
+#define CONFIG_HLP_TYPEMON       "Type of L2 monitoring messages: none,pcap,wireshark  \n"
+#define CONFIG_HLP_L2MONIP       "ip address for wireshark messages \n"
+#define CONFIG_HLP_L2MONPATH     "file path for pcap  messages on localhost \n"
+/*-----------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
+/*                                            command line parameters for LOG utility                                                                                    */
+/*   optname                     helpstr                paramflags                      XXXptr                  defXXXval                            type       numelt   */
+/*-----------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
+#define OPT_PARAMS_DESC {  \
+    {"type" ,                    CONFIG_HLP_TYPEMON,     0,                      strptr:&in_type,                  defstrval:"none",               TYPE_STRING,    0},       \
+    {"ip" ,                      CONFIG_HLP_L2MONIP,     0,                      strptr:&in_ip,                    defstrval:"127.0.0.1",          TYPE_STRING,    0},       \
+    {"path" ,                    CONFIG_HLP_L2MONPATH,   0,                      strptr:&in_path,                  defstrval:"/tmp/oai_opt.pcap",  TYPE_STRING,    0},       \
+  }
+
+#define OPTTYPE_IDX 0
+/* check function for opt parameters */
+#define OPTTYPE_OKSTRINGS {"none","pcap","wireshark"}
+#define OPTTYPE_VALUES    {OPT_NONE,OPT_PCAP,OPT_WIRESHARK}
+#define OPTPARAMS_CHECK_DESC { \
+    { .s3a= { config_checkstr_assign_integer,  OPTTYPE_OKSTRINGS,OPTTYPE_VALUES ,3}} ,\
+    { .s5= {NULL }} ,                   \
+    { .s5= {NULL }} ,                   \
+  }
+
 #ifdef OCP_FRAMEWORK
 #include <enums.h>
 #else
@@ -82,9 +105,7 @@ typedef enum radio_type_e {
   RADIO_TYPE_MAX
 } radio_type_t;
 
-extern trace_mode_t opt_type;
-extern char in_ip[40];
-extern char in_path[FILENAME_MAX];
+
 
 /**
  * function def
@@ -94,7 +115,7 @@ void trace_pdu(int direction, uint8_t *pdu_buffer, unsigned int pdu_buffer_size,
                int ueid, int rntiType, int rnti, uint16_t sysFrame, uint8_t subframe,
                int oob_event, int oob_event_value);
 
-int init_opt(char *path, char *ip);
+int init_opt(void);
 
 void terminate_opt(void);
 
diff --git a/openair2/UTIL/OPT/probe.c b/openair2/UTIL/OPT/probe.c
index a1e53671682a10f0f984cbcd831b98c0116378e2..b032784028ee4dc7f2349e615cc7bbef5a6cbc6d 100644
--- a/openair2/UTIL/OPT/probe.c
+++ b/openair2/UTIL/OPT/probe.c
@@ -90,7 +90,7 @@ what about the implementation
 
 #include <pthread.h>
 #include <stdint.h>
-
+#include "common/config/config_userapi.h"
 #include "opt.h"
 
 int opt_enabled=0;
@@ -98,8 +98,8 @@ int opt_enabled=0;
 //static unsigned char g_PDUBuffer[1600];
 //static unsigned int g_PDUOffset;
 
-char in_ip[40];
-char in_path[FILENAME_MAX];
+static char *in_ip;
+static char *in_path;
 FILE *file_fd = NULL;
 pcap_hdr_t file_header = {
   0xa1b2c3d4,   /* magic number */
@@ -133,17 +133,15 @@ static void SendFrame(guint8 radioType, guint8 direction, guint8 rntiType,
 static int MAC_LTE_PCAP_WritePDU(MAC_Context_Info_t *context,
                                  const unsigned char *PDU, unsigned int length);
 
-static void *opt_listener_thread(void *arg)
-{
+static void *opt_listener_thread(void *arg) {
   ssize_t ret;
   struct sockaddr_in from_address;
   socklen_t socklen = sizeof(from_address);
-
   memset(&from_address, 0, sizeof(from_address));
 
   while(1) {
     /* Simply drop packets */
-    ret = recvfrom(opt_listener.sd, NULL, 0, 0, (struct sockaddr*)&from_address,
+    ret = recvfrom(opt_listener.sd, NULL, 0, 0, (struct sockaddr *)&from_address,
                    &socklen);
 
     if (ret == 0) {
@@ -165,17 +163,13 @@ static void *opt_listener_thread(void *arg)
 }
 
 static
-int opt_create_listener_socket(char *ip_address, uint16_t port)
-{
+int opt_create_listener_socket(char *ip_address, uint16_t port) {
   /* Create an UDP socket and listen on it.
    * Silently discard PDU received.
    */
-
   int sd = -1;
   int ret = -1;
-
   memset(&opt_listener, 0, sizeof(opt_listener_t));
-
   sd = socket(AF_INET, SOCK_DGRAM, 0);
 
   if (sd < 0) {
@@ -190,8 +184,7 @@ int opt_create_listener_socket(char *ip_address, uint16_t port)
   /* Listening only on provided IP address */
   opt_listener.address.sin_addr.s_addr = inet_addr(ip_address);
   opt_listener.address.sin_port = htons(port);
-
-  ret = bind(opt_listener.sd, (struct sockaddr*) &opt_listener.address, sizeof(opt_listener.address));
+  ret = bind(opt_listener.sd, (struct sockaddr *) &opt_listener.address, sizeof(opt_listener.address));
 
   if (ret != 0) {
     LOG_E(OPT, "Failed to bind socket to (%s:%u): %s\n",
@@ -231,49 +224,39 @@ static void SendFrame(guint8 radioType, guint8 direction, guint8 rntiType,
                       guint16 rnti, guint16 ueid, guint16 sfnSf,
                       guint8 isPredefinedData, guint8 retx, guint8 crcStatus,
                       guint8 oob_event, guint8 oob_event_value,
-                      uint8_t *pdu_buffer, unsigned int pdu_buffer_size)
-{
+                      uint8_t *pdu_buffer, unsigned int pdu_buffer_size) {
   unsigned char frameBuffer[9000];
   unsigned int frameOffset;
-
   ssize_t bytesSent;
   frameOffset = 0;
   uint16_t tmp16;
-
   memcpy(frameBuffer+frameOffset, MAC_LTE_START_STRING,
          strlen(MAC_LTE_START_STRING));
   frameOffset += strlen(MAC_LTE_START_STRING);
-
   /******************************************************************************/
   /* Now write out fixed fields (the mandatory elements of struct mac_lte_info) */
   frameBuffer[frameOffset++] = radioType;
   frameBuffer[frameOffset++] = direction;
   frameBuffer[frameOffset++] = rntiType;
-
   /*************************************/
   /* Now optional fields               */
-
   /* RNTI */
   frameBuffer[frameOffset++] = MAC_LTE_RNTI_TAG;
   tmp16 = htons(rnti);
   memcpy(frameBuffer+frameOffset, &tmp16, 2);
   frameOffset += 2;
-
   /* UEId */
   frameBuffer[frameOffset++] = MAC_LTE_UEID_TAG;
   tmp16 = htons(ueid);
   memcpy(frameBuffer+frameOffset, &tmp16, 2);
   frameOffset += 2;
-
   /* Subframe number */
   frameBuffer[frameOffset++] = MAC_LTE_FRAME_SUBFRAME_TAG;
   tmp16 = htons(sfnSf); // frame counter : this will give an expert info as wireshark expects SF and not F
   memcpy(frameBuffer+frameOffset, &tmp16, 2);
   frameOffset += 2;
-
   frameBuffer[frameOffset++] = MAC_LTE_CRC_STATUS_TAG;
   frameBuffer[frameOffset++] = crcStatus;
-  
 #ifdef WIRESHARK_DEV
   frameOffset += 2;
   tmp16 = htons(sfnSf); // subframe
@@ -293,55 +276,55 @@ static void SendFrame(guint8 radioType, guint8 direction, guint8 rntiType,
     frameBuffer[frameOffset++] = retx;
   }
 
-//#ifdef WIRESHARK_DEV
+  //#ifdef WIRESHARK_DEV
 
   /* Relating to out-of-band events */
   /* N.B. dissector will only look to these fields if length is 0... */
   if (pdu_buffer_size==0) {
     switch (oob_event) {
-    case ltemac_send_preamble :
-      LOG_D(OPT,"ltemac_send_preamble event %02x."
-          //"%02x."
-          "%02x.%02x\n",
-          MAC_LTE_SEND_PREAMBLE_TAG,
-          //ltemac_send_preamble,
-          rnti,
-          oob_event_value);
-      //frameBuffer[frameOffset++]=0;
-      //frameBuffer[frameOffset++]=0;
-      //frameBuffer[frameOffset++]=0;
-      frameBuffer[frameOffset++] = MAC_LTE_SEND_PREAMBLE_TAG;
-      //frameBuffer[frameOffset++]=ltemac_send_preamble;
-      frameBuffer[frameOffset++]=rnti; // is the preamble
-      frameBuffer[frameOffset++]=oob_event_value;
-      break;
-
-    case ltemac_send_sr:
-      frameBuffer[frameOffset++]=MAC_LTE_SR_TAG ;
-      frameOffset+=2;
-      frameBuffer[frameOffset++]=rnti;
-      frameOffset++;
-      frameBuffer[frameOffset++]=oob_event_value;
-      frameOffset++;
-      break;
-
-    case ltemac_sr_failure:
-    default:
-      LOG_W(OPT,"not implemeneted yet\n");
-      break;
+      case ltemac_send_preamble :
+        LOG_D(OPT,"ltemac_send_preamble event %02x."
+              //"%02x."
+              "%02x.%02x\n",
+              MAC_LTE_SEND_PREAMBLE_TAG,
+              //ltemac_send_preamble,
+              rnti,
+              oob_event_value);
+        //frameBuffer[frameOffset++]=0;
+        //frameBuffer[frameOffset++]=0;
+        //frameBuffer[frameOffset++]=0;
+        frameBuffer[frameOffset++] = MAC_LTE_SEND_PREAMBLE_TAG;
+        //frameBuffer[frameOffset++]=ltemac_send_preamble;
+        frameBuffer[frameOffset++]=rnti; // is the preamble
+        frameBuffer[frameOffset++]=oob_event_value;
+        break;
+
+      case ltemac_send_sr:
+        frameBuffer[frameOffset++]=MAC_LTE_SR_TAG ;
+        frameOffset+=2;
+        frameBuffer[frameOffset++]=rnti;
+        frameOffset++;
+        frameBuffer[frameOffset++]=oob_event_value;
+        frameOffset++;
+        break;
+
+      case ltemac_sr_failure:
+      default:
+        LOG_W(OPT,"not implemeneted yet\n");
+        break;
     }
   }
 
-//#endif
+  //#endif
   /***************************************/
   /* Now write the MAC PDU               */
   frameBuffer[frameOffset++] = MAC_LTE_PAYLOAD_TAG;
-  
+
   /* Append actual PDU  */
   //memcpy(frameBuffer+frameOffset, g_PDUBuffer, g_PDUOffset);
   //frameOffset += g_PDUOffset;
   if (pdu_buffer != NULL) {
-    memcpy(frameBuffer+frameOffset, (void*)pdu_buffer, pdu_buffer_size);
+    memcpy(frameBuffer+frameOffset, (void *)pdu_buffer, pdu_buffer_size);
     frameOffset += pdu_buffer_size;
   }
 
@@ -358,44 +341,36 @@ static void SendFrame(guint8 radioType, guint8 direction, guint8 rntiType,
 
 /* Write an individual PDU (PCAP packet header + mac-context + mac-pdu) */
 static int MAC_LTE_PCAP_WritePDU(MAC_Context_Info_t *context,
-                                 const uint8_t *PDU, unsigned int length)
-{
+                                 const uint8_t *PDU, unsigned int length) {
   pcaprec_hdr_t packet_header;
   uint8_t context_header[256];
   int offset = 0;
   unsigned short tmp16;
-
   /*****************************************************************/
   /* Context information (same as written by UDP heuristic clients */
   context_header[offset++] = context->radioType;
   context_header[offset++] = context->direction;
   context_header[offset++] = context->rntiType;
-
   /* RNTI */
   context_header[offset++] = MAC_LTE_RNTI_TAG;
   tmp16 = htons(context->rnti);
   memcpy(context_header+offset, &tmp16, 2);
   offset += 2;
-
   /* UEId */
   context_header[offset++] = MAC_LTE_UEID_TAG;
   tmp16 = htons(context->ueid);
   memcpy(context_header+offset, &tmp16, 2);
   offset += 2;
-
   /* Subframe number */
   context_header[offset++] = MAC_LTE_FRAME_SUBFRAME_TAG;
   tmp16 = htons(context->subFrameNumber);
   memcpy(context_header+offset, &tmp16, 2);
   offset += 2;
-
   /* CRC Status */
   context_header[offset++] = MAC_LTE_CRC_STATUS_TAG;
   context_header[offset++] = context->crcStatusOK;
-
   /* Data tag immediately preceding PDU */
   context_header[offset++] = MAC_LTE_PAYLOAD_TAG;
-
   /****************************************************************/
   /* PCAP Header                                                  */
   /* TODO: Timestamp might want to be relative to a more sensible
@@ -404,13 +379,11 @@ static int MAC_LTE_PCAP_WritePDU(MAC_Context_Info_t *context,
   packet_header.ts_usec = (context->subframesSinceCaptureStart % 1000) * 1000;
   packet_header.incl_len = offset + length;
   packet_header.orig_len = offset + length;
-
   /***************************************************************/
   /* Now write everything to the file                            */
   fwrite(&packet_header, sizeof(pcaprec_hdr_t), 1, file_fd);
   fwrite(context_header, 1, offset, file_fd);
   fwrite(PDU, 1, length, file_fd);
-
   return 1;
 }
 #include <common/ran_context.h>
@@ -419,117 +392,129 @@ extern RAN_CONTEXT_t RC;
 /* Remote serveraddress (where Wireshark is running) */
 void trace_pdu(int direction, uint8_t *pdu_buffer, unsigned int pdu_buffer_size,
                int ueid, int rntiType, int rnti, uint16_t sysFrameNumber, uint8_t subFrameNumber, int oob_event,
-               int oob_event_value)
-{
+               int oob_event_value) {
   MAC_Context_Info_t pdu_context;
   int radioType=FDD_RADIO;
+
   if (RC.eNB[0][0]!=NULL)
     radioType=RC.eNB[0][0]->frame_parms.frame_type== FDD ? FDD_RADIO:TDD_RADIO;
+
   if (PHY_vars_UE_g[0][0] != NULL)
     radioType=PHY_vars_UE_g[0][0]->frame_parms.frame_type== FDD ? FDD_RADIO:TDD_RADIO;
+
   switch (opt_type) {
-  case OPT_WIRESHARK :
-    if (g_socksd == -1) {
-      return;
-    }
+    case OPT_WIRESHARK :
+      if (g_socksd == -1) {
+        return;
+      }
+
+      SendFrame( radioType,
+                 (direction == DIRECTION_DOWNLINK) ? DIRECTION_DOWNLINK : DIRECTION_UPLINK,
+                 rntiType, rnti, ueid, (sysFrameNumber<<4) + subFrameNumber,
+                 1, 0, 1,  //guint8 isPredefinedData, guint8 retx, guint8 crcStatus
+                 oob_event,oob_event_value,
+                 pdu_buffer, pdu_buffer_size);
+      break;
 
-    SendFrame( radioType,
-              (direction == DIRECTION_DOWNLINK) ? DIRECTION_DOWNLINK : DIRECTION_UPLINK,
-              rntiType, rnti, ueid, (sysFrameNumber<<4) + subFrameNumber,
-              1, 0, 1,  //guint8 isPredefinedData, guint8 retx, guint8 crcStatus
-              oob_event,oob_event_value,
-              pdu_buffer, pdu_buffer_size);
-    break;
-
-  case OPT_PCAP:
-    if (file_fd == NULL) {
-      return;
-    }
+    case OPT_PCAP:
+      if (file_fd == NULL) {
+        return;
+      }
+
+      pdu_context.radioType =  radioType;
+      pdu_context.direction = (direction == DIRECTION_DOWNLINK) ? DIRECTION_DOWNLINK
+                              : DIRECTION_UPLINK;
+      pdu_context.rntiType = rntiType;
+      pdu_context.rnti = rnti;
+      pdu_context.ueid = ueid;
+      pdu_context.isRetx = 0;
+      pdu_context.crcStatusOK =1;
+      pdu_context.sysFrameNumber = sysFrameNumber;
+      pdu_context.subFrameNumber = subFrameNumber;
+      pdu_context.subframesSinceCaptureStart = subframesSinceCaptureStart++;
+      MAC_LTE_PCAP_WritePDU( &pdu_context, pdu_buffer, pdu_buffer_size);
+      break;
 
-    pdu_context.radioType =  radioType;
-    pdu_context.direction = (direction == DIRECTION_DOWNLINK) ? DIRECTION_DOWNLINK
-                            : DIRECTION_UPLINK;
-    pdu_context.rntiType = rntiType;
-    pdu_context.rnti = rnti;
-    pdu_context.ueid = ueid;
-    pdu_context.isRetx = 0;
-    pdu_context.crcStatusOK =1;
-    pdu_context.sysFrameNumber = sysFrameNumber;
-    pdu_context.subFrameNumber = subFrameNumber;
-    pdu_context.subframesSinceCaptureStart = subframesSinceCaptureStart++;
-    MAC_LTE_PCAP_WritePDU( &pdu_context, pdu_buffer, pdu_buffer_size);
-    break;
-
-  case OPT_TSHARK:
-  default:
-    break;
+    case OPT_TSHARK:
+    default:
+      break;
   }
 }
 /*---------------------------------------------------*/
-int init_opt(char *path, char *ip)
-{
+int init_opt(void) {
+  char *in_type=NULL;
+  paramdef_t opt_params[]          = OPT_PARAMS_DESC ;
+  checkedparam_t opt_checkParams[] = OPTPARAMS_CHECK_DESC;
   uint16_t in_port;
+  config_set_checkfunctions(opt_params, opt_checkParams,
+                            sizeof(opt_params)/sizeof(paramdef_t));
+  config_get( opt_params,sizeof(opt_params)/sizeof(paramdef_t),OPT_CONFIGPREFIX);
   subframesSinceCaptureStart = 0;
-
-  if (path != NULL) {
-    strncpy( in_path, path, sizeof(in_path) );
-    in_path[sizeof(in_path) - 1] = 0; // terminate string
+  int tmptype = config_get_processedint( &(opt_params[OPTTYPE_IDX]));
+
+  if (tmptype == OPT_NONE) {
+    opt_enabled=0;
+    LOG_I(OPT,"OPT disabled\n");
+    return 0;
+  } else if (tmptype == OPT_PCAP && strlen(in_path) > 0) {
+    opt_type = OPT_PCAP;
+    opt_enabled=1;
+    LOG_I(OPT,"Enabling OPT for PCAP  with the following file %s \n",in_path);
+  } else if (tmptype == OPT_WIRESHARK && strlen(in_ip) > 0) {
+    opt_enabled=1;
+    opt_type = OPT_WIRESHARK;
+    LOG_I(OPT,"Enabling OPT for wireshark for local interface %s\n",in_ip);
   } else {
-    strcpy( in_path, "/tmp/opt.pcap" );
-  }
-
-  if (ip != NULL) {
-    strncpy( in_ip, ip, sizeof(in_ip) );
-    in_ip[sizeof(in_ip) - 1] = 0; // terminate string
-  } else {
-    strcpy( in_ip, "127.0.0.1" );
+    LOG_E(OPT,"Invalid OPT configuration\n");
+    config_printhelp(opt_params,sizeof(opt_params)/sizeof(paramdef_t),OPT_CONFIGPREFIX);
   }
 
   in_port = PACKET_MAC_LTE_DEFAULT_UDP_PORT;
 
   // trace_mode
   switch (opt_type) {
-  case OPT_WIRESHARK:
+    case OPT_WIRESHARK:
 
-    /* Create local server socket only if using localhost address */
-    if (strcmp(in_ip, "127.0.0.1") == 0) {
-      opt_create_listener_socket(in_ip, in_port);
-    }
+      /* Create local server socket only if using localhost address */
+      if (strcmp(in_ip, "127.0.0.1") == 0) {
+        opt_create_listener_socket(in_ip, in_port);
+      }
 
-    g_socksd = socket(AF_INET, SOCK_DGRAM, 0);
+      g_socksd = socket(AF_INET, SOCK_DGRAM, 0);
 
-    if (g_socksd == -1) {
-      LOG_E(OPT, "Error trying to create socket (errno=%d)\n", errno);
-      LOG_E(OPT, "CREATING SOCKET FAILED\n");
-      return (-1);
-    }
+      if (g_socksd == -1) {
+        LOG_E(OPT, "Error trying to create socket (errno=%d)\n", errno);
+        LOG_E(OPT, "CREATING SOCKET FAILED\n");
+        return (-1);
+      }
 
-    /* Get remote IP address from the function argument */
-    g_serv_addr.sin_family = AF_INET;
-    g_serv_addr.sin_port = htons(in_port);
-    g_serv_addr.sin_addr.s_addr = inet_addr(in_ip);
-    break;
+      /* Get remote IP address from the function argument */
+      g_serv_addr.sin_family = AF_INET;
+      g_serv_addr.sin_port = htons(in_port);
+      g_serv_addr.sin_addr.s_addr = inet_addr(in_ip);
+      break;
 
-  case OPT_PCAP:
-    file_fd = fopen(in_path, "w");
+    case OPT_PCAP:
+      file_fd = fopen(in_path, "w");
 
-    if (file_fd == NULL) {
-      LOG_D(OPT, "Failed to open file \"%s\" for writing\n", in_path);
-      return (-1);
-    }
-    /* Write the file header */
-    fwrite(&file_header, sizeof(pcap_hdr_t), 1, file_fd);
-    break;
+      if (file_fd == NULL) {
+        LOG_D(OPT, "Failed to open file \"%s\" for writing\n", in_path);
+        return (-1);
+      }
 
-  case OPT_TSHARK:
-    LOG_W(OPT, "Tshark is currently not supported\n");
-    opt_type = OPT_NONE;
-    break;
+      /* Write the file header */
+      fwrite(&file_header, sizeof(pcap_hdr_t), 1, file_fd);
+      break;
 
-  default:
-    opt_type = OPT_NONE;
-    LOG_W(OPT, "supported Option\n");
-    break;
+    case OPT_TSHARK:
+      LOG_W(OPT, "Tshark is currently not supported\n");
+      opt_type = OPT_NONE;
+      break;
+
+    default:
+      opt_type = OPT_NONE;
+      LOG_W(OPT, "supported Option\n");
+      break;
   }
 
   if ( opt_type == OPT_WIRESHARK )
@@ -543,8 +528,7 @@ int init_opt(char *path, char *ip)
   // memset(mac_info, 0, sizeof(mac_lte_info)+pdu_buffer_size + 8);
   return (1);
 }
-void terminate_opt(void)
-{
+void terminate_opt(void) {
   /* Close local socket */
   //  free(mac_info);
   if (opt_type != OPT_NONE) {
@@ -552,18 +536,18 @@ void terminate_opt(void)
   }
 
   switch (opt_type) {
-  case OPT_WIRESHARK:
-    close(g_socksd);
-    g_socksd = -1;
-    break;
-
-  case OPT_PCAP:
-    fclose (file_fd);
-    file_fd = NULL;
-    break;
-
-  default:
-    break;
+    case OPT_WIRESHARK:
+      close(g_socksd);
+      g_socksd = -1;
+      break;
+
+    case OPT_PCAP:
+      fclose (file_fd);
+      file_fd = NULL;
+      break;
+
+    default:
+      break;
   }
 }
 
diff --git a/openair2/UTIL/OTG/main.c b/openair2/UTIL/OTG/main.c
index 1ee9b0edd7600df62ccd4acb8d9c1a2cc6194ecc..023033c45fbc603820b7890bddac690000fc275d 100644
--- a/openair2/UTIL/OTG/main.c
+++ b/openair2/UTIL/OTG/main.c
@@ -53,9 +53,7 @@ int simu_time=0, duration=0, seed=0, simu_mode=0;
 
 // init OTG with config parameters
 
-void init_config_otg(char *protocol, char *ip_version)
-{
-
+void init_config_otg(char *protocol, char *ip_version) {
   int i, j, k;
 
   if (simu_time>0)
@@ -70,25 +68,19 @@ void init_config_otg(char *protocol, char *ip_version)
 
   printf("duration %d, seeds %d \n", duration, g_otg->seed);
 
-
   for (i=0; i<(NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX); i++) {
-
-
-
     if (duration>0)
       g_otg->duration[i]=duration;
     else
       g_otg->duration[i]=10000;
 
-
     g_otg->dst_port[i]=DST_PORT;
-    g_otg->dst_ip[i]=(char*)malloc(100*sizeof(char*));
+    g_otg->dst_ip[i]=(char *)malloc(100*sizeof(char *));
     g_otg->dst_ip[i]=DST_IP;
     g_otg->dst_ip[i]=DST_IP;
 
     //config ip version
 
-
     if (ip_version !=NULL) {
       if ((strcmp(ip_version,"IP4")==0) ||(strcmp(ip_version,"ip4")==0))
         g_otg->ip_v[i]=IPV4;
@@ -97,7 +89,6 @@ void init_config_otg(char *protocol, char *ip_version)
     } else
       g_otg->ip_v[i]=IPV4;
 
-
     //config transport protocol version
     if (protocol!=NULL) {
       if ((strcmp(protocol,"TCP")==0) ||(strcmp(protocol,"tcp")==0))
@@ -123,20 +114,13 @@ void init_config_otg(char *protocol, char *ip_version)
         g_otg->size_std_dev[i][j][k]=PKTS_SIZE_STD_DEV;
         g_otg->size_lambda[i][j][k]=PKTS_SIZE_LAMBDA;
       }
-
     }
-
-
   }
-
-
-
 }
 
 
 
-int main_below_ip()
-{
+int main_below_ip() {
   int i, j, k, l, rtt_owd ,rx_otg=0, simu_time=0, ctime=0, nb_round=0;
   float p;
   char *packet;
@@ -145,25 +129,17 @@ int main_below_ip()
   printf(" max enb %d, max ue %d \n", NUMBER_OF_eNB_MAX, NUMBER_OF_UE_MAX);
 
   do {
-
     nb_round=nb_round+1;
 
     // for (stime=0; stime < SIMU_TIME; stime++) // discrete event generation : tick, stime generate the ctime
     for (i=0; i<(NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX); i++) {
-
       for (j=0; j<(NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX); j++) {
-
         for (k=0; k<MAX_NUM_TRAFFIC_STATE; k++) {
           LOG_I(OTG,"OTG emulation src=%d, dst=%d, state=%d \n", i, j, k);
-
-
-
           ctime=0; // set the ctime to 0
 
           do {
-
             if (simu_time> SIMU_TIME) {
-
               otg_info->ctime=SIMU_TIME;
               return(0);
             }
@@ -172,21 +148,16 @@ int main_below_ip()
             char *packet=NULL;
             /*packet=packet_gen(i, j, k, ctime);*/ packet=packet_gen(i, j, ctime, &pkt_size);
 
-
-
             if (packet!=NULL) {
               if ((ceil(g_otg->duration[i]*uniform_rng()))==ctime)  {
-                printf("DROP PACKET (i=%d,j=%d) seq num=%d\n",i, j, otg_info->seq_num[i][j]);
-
+                printf("DROP PACKET (i=%d,j=%d) seq num=%d\n",i, j, (int)otg_info->seq_num[i][j]);
               } else  {
-                printf("SEND PACKET (i=%d,j=%d) seq num=%d\n",i, j, otg_info->seq_num[i][j]);
-
+                printf("SEND PACKET (i=%d,j=%d) seq num=%d\n",i, j, (int)otg_info->seq_num[i][j]);
                 rtt_owd=ceil(uniform_rng()*8.56);
                 LOG_I(OTG,"one way delay= %d , (src=%d, dst=%d, state=%d)\n", rtt_owd, i, j, k);
                 ctime+=rtt_owd;
                 otg_info->rx_pkt_owd[i][j]=rtt_owd;
                 simu_time+=rtt_owd;
-
                 //rx_packet_out=check_packet(i, j, ctime, packet);
                 rx_packet_out=otg_rx_pkt(i,j, ctime, packet, pkt_size);
                 //if (rx_packet_out==NULL)
@@ -196,18 +167,15 @@ int main_below_ip()
                 //    rx_packet_out=NULL;
                 free(packet);
                 //  }
-
                 //}
-
                 //Do not increase the ctime and simu_time with the one way delay.
                 ctime-=rtt_owd;
                 simu_time-=rtt_owd;
-
-
-                LOG_I(OTG,"PKTS INFO:: (src=%d, dst=%d, state=%d),NB PKTS=%d  ,sequence NB=%d,  RTT (one way)ms= %d \n ",i, j, k, otg_info->tx_num_pkt[i][j], otg_info->seq_num[i][j], otg_info->rx_pkt_owd[i][j]);
+                LOG_I(OTG,"PKTS INFO:: (src=%d, dst=%d, state=%d),NB PKTS=%d  ,sequence NB=%d,  RTT (one way)ms= %d \n ",
+                      i, j, k, (int)otg_info->tx_num_pkt[i][j], (int)otg_info->seq_num[i][j], (int)otg_info->rx_pkt_owd[i][j]);
               }
             } else
-              printf("Node (i=%d,j=%d) seq num=%d, ctime %d, prb %lf\n",i, j, otg_info->seq_num[i][j], ctime,(ceil(g_otg->duration[i]*uniform_rng())));
+              printf("Node (i=%d,j=%d) seq num=%d, ctime %d, prb %lf\n",i, j, (int)otg_info->seq_num[i][j], ctime,(ceil(g_otg->duration[i]*uniform_rng())));
 
             LOG_I(OTG,"Time:: ctime=%d, duration=%d, simu_time=%d, max=%d, (src=%d, dst=%d, state=%d) \n", ctime,  g_otg->duration[i],simu_time, SIMU_TIME, i, j,k);
             ctime+=1;
@@ -215,27 +183,19 @@ int main_below_ip()
           } while (ctime<=g_otg->duration[i]) ;
         }
 
-
-
         if  (otg_info->tx_num_pkt[i][j]>otg_info->rx_num_pkt[i][j])
-          LOG_I(OTG,"STAT: (LOSS):: (src=%d, dst=%d) NB packet TX= %d,  NB packet RX = %d, seq NUM=%d\n ",i, j, otg_info->tx_num_pkt[i][j], otg_info->rx_num_pkt[i][j],otg_info->seq_num[i][j] );
+          LOG_I(OTG,"STAT: (LOSS):: (src=%d, dst=%d) NB packet TX= %d,  NB packet RX = %d, seq NUM=%d\n ",
+                i, j, (int)otg_info->tx_num_pkt[i][j], (int)otg_info->rx_num_pkt[i][j],(int)otg_info->seq_num[i][j] );
         else
-          LOG_I(OTG,"STAT: :: (src=%d, dst=%d) NB packet TX= %d,  NB packet RX= %d, seq NUM=%d \n ",i, j, otg_info->tx_num_pkt[i][j], otg_info->rx_num_pkt[i][j], otg_info->seq_num[i][j]);
-
-
-
+          LOG_I(OTG,"STAT: :: (src=%d, dst=%d) NB packet TX= %d,  NB packet RX= %d, seq NUM=%d \n ",
+                i, j, (int)otg_info->tx_num_pkt[i][j], (int)otg_info->rx_num_pkt[i][j], (int)otg_info->seq_num[i][j]);
       }
     }
-
-
-
   } while (simu_time<=SIMU_TIME);
-
 }
 
 
-int main_above_ip()
-{
+int main_above_ip() {
   int i, j, k,  simu_time=0, ctime=0, nb_round=0;
   char *packet=NULL;
   printf(" max enb %d, max ue %d \n", NUMBER_OF_eNB_MAX, NUMBER_OF_UE_MAX);
@@ -244,9 +204,7 @@ int main_above_ip()
     nb_round=nb_round+1;
 
     for (i=0; i<(NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX); i++) {
-
       for (j=0; j<(NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX); j++) {
-
         for (k=0; k<MAX_NUM_TRAFFIC_STATE; k++) {
           LOG_I(OTG,"SOCKET:: OTG emulation src=%d, dst=%d, state=%d \n", i, j, k);
           ctime=0;
@@ -255,57 +213,44 @@ int main_above_ip()
       }
     }
 
-
     ctime+=1;
     simu_time+=1;
   } while (simu_time<=SIMU_TIME);
-
 }
 
 
 
 
 
-void config_traffic_type(char *traffic)
-{
+void config_traffic_type(char *traffic) {
   Application application;
   int i,j;
 
   if (strcmp(traffic, "SCBR")==0)
     application=SCBR;
-
   else if (strcmp(traffic, "OPENARENA")==0)
     application=OPENARENA;
-
   else if (strcmp(traffic, "BICYCLE_RACE")==0)
     application=BICYCLE_RACE;
-
   else if (strcmp(traffic, "AUTO_PILOT")==0)
     application=AUTO_PILOT;
-
   else if (strcmp(traffic, "TEAM_FORTRESS")==0)
     application=TEAM_FORTRESS;
-
   else
     application=NO_PREDEFINED_TRAFFIC;
 
   printf("Config Application: %d \n", application);
 
   for (i=0; i<(NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX); i++) {
-
     for (j=0; j<(NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX); j++) {
-
       g_otg->application_type[i][j] =application;
-
     }
   }
-
 }
 
 
 
-cunstom_config(simu_time, duration)
-{
+cunstom_config(simu_time, duration) {
   int i;
 
   //--config introduced Global simulation time for each node
@@ -321,37 +266,23 @@ cunstom_config(simu_time, duration)
 
 
 
-int main (int argc, char **argv)
-{
-
-
+int main (int argc, char **argv) {
   int i,j, tx;
-
   char *protocol=NULL;
   char *ip_version=NULL;
   char *traffic=NULL;
-
-
-
-
   init_all_otg();
   otg_info->ctime=0;
   LOG_I(OTG,"Emulation time %d \n ", otg_info->ctime);
   g_otg->num_nodes=NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX;
   LOG_I(OTG,"OTG emulation number of nodes= %d \n", g_otg->num_nodes);
 
-
-
   for (i = 1; i <argc ; i ++) {
     if ('-' == argv[i][0]) {
-
       if(('h' == argv[i][1]) || ('H' == argv[i][1])) {
         printf("Help OTG: \n./otg [-M [s (socket mode)] [b (Below IP)]] [-T (Simu Time)] [-d (duration per node)] [-s (seed)] [-P (protocol: TCP or UDP)] [-I (ip version: IP4 or IP6)] -A [(application: CBR, AUTO_PILOT, BICYCLE_RACE, OPENARENA, TEAM_FORTRESS)]\n");
         return(0);
-
-      }
-
-      else if ('M' == argv[i][1]) {
+      } else if ('M' == argv[i][1]) {
         if (strcmp("s",argv[i+1])==0) {
           printf("Above IP: SOCKET MODE \n");
           simu_mode=1;
@@ -359,89 +290,53 @@ int main (int argc, char **argv)
           printf("Below IP: IPC/RPC MODE\n");
           simu_mode=0;
         }
-
-      }
-
-      else if ('T' == argv[i][1]) {
+      } else if ('T' == argv[i][1]) {
         simu_time=atoi(argv[i+1]);
         printf("simu_time=%d\n", simu_time);
-      }
-
-
-      else if ('d' == argv[i][1]) {
+      } else if ('d' == argv[i][1]) {
         duration=atoi(argv[i+1]);
         printf("duration node=%d\n", duration);
-      }
-
-      else if ('s' == argv[i][1]) {
+      } else if ('s' == argv[i][1]) {
         seed=atoi(argv[i+1]);
         printf("seed val =%d\n", seed);
-      }
-
-
-      else if ('P' == argv[i][1]) {
+      } else if ('P' == argv[i][1]) {
         protocol=argv[i+1];
 
         if ((strcmp(argv[i+1],"TCP")==0) || (strcmp(argv[i+1],"UDP")==0) || (strcmp(argv[i+1],"tcp")==0) || (strcmp(argv[i+1],"udp")==0)) {
           protocol=argv[i+1];
           printf("Protocol=%s\n", protocol);
         }
-      }
-
-      else if ('I' == argv[i][1]) {
+      } else if ('I' == argv[i][1]) {
         if ((strcmp(argv[i+1],"IP4")==0) || (strcmp(argv[i+1],"IP6")==0) || (strcmp(argv[i+1],"ip4")==0) || (strcmp(argv[i+1],"ip6")==0)) {
           ip_version=argv[i+1];
           printf("IP version=%s\n", ip_version);
         }
-
-
-      }
-
-      else if ('A' == argv[i][1]) {
+      } else if ('A' == argv[i][1]) {
         if ((strcmp(argv[i+1],"CBR")==0) || (strcmp(argv[i+1],"AUTO_PILOT")==0) || (strcmp(argv[i+1],"BICYCLE_RACE")==0) || (strcmp(argv[i+1],"OPENARENA")==0) || (strcmp(argv[i+1],"TEAM_FORTRESS")==0))
           traffic=argv[i+1];
 
         config_traffic_type(traffic);
-
       }
-
-
     }
-
-
-
   }
 
-
-
   if (traffic!=NULL)
     init_predef_traffic();
   else
     init_config_otg(protocol, ip_version);
 
-
   init_seeds(g_otg->seed);
   cunstom_config(simu_time, duration);
 
-
-
   if (simu_mode==0)
     tx=main_below_ip();
-
   else if (simu_mode==1)
     tx=main_above_ip();
 
-
-
   // Compute KPI after the end of the simu
   kpi_gen();
-
   free_otg();
-
-
-
   return 0;
-
 }
 
 
diff --git a/openair2/UTIL/OTG/otg_form.c b/openair2/UTIL/OTG/otg_form.c
index 6994e658961b9ec76795320b24c66f8b908ea631..aea5d3888277edf14c94aa2bfcd25217b453c001 100644
--- a/openair2/UTIL/OTG/otg_form.c
+++ b/openair2/UTIL/OTG/otg_form.c
@@ -38,31 +38,25 @@
 extern unsigned char NB_eNB_INST;
 extern unsigned char NB_UE_INST;
 
-FD_otg * form_dl, *form_ul;
+FD_otg *form_dl, *form_ul;
 FL_FORM *fclock;
 unsigned int clear_cmpt_ul=0;
 unsigned int clear_cmpt_dl=0;
 
 
-FD_otg *create_form_otg(void)
-{
+FD_otg *create_form_otg(void) {
   FL_OBJECT *obj;
   FD_otg *fdui = (FD_otg *) fl_calloc(1, sizeof(*fdui));
-
   fdui->otg = fl_bgn_form(FL_NO_BOX, 550, 550);
   obj = fl_add_box(FL_UP_BOX,0,0,900,700,"");
   fdui->owd = fl_add_xyplot(FL_NORMAL_XYPLOT,50,30,450,190,"Delay(ms)");
   fl_set_object_color(fdui->owd,FL_BLACK,FL_YELLOW);
   fdui->throughput = fl_add_xyplot(FL_NORMAL_XYPLOT,50,300,450,190,"Throughput(Kbit/s)");
   fl_set_object_color(fdui->throughput,FL_BLACK,FL_YELLOW);
-
-
   obj = fl_add_button(FL_NORMAL_BUTTON,250,510,50,30,"Exit");
   fl_set_object_callback(obj, exit_cb, 0);
   fdui->loss_ratio=fl_add_text(FL_NORMAL_TEXT,5,510,220,20,"NB Loss pkts");
   fdui->simu_time=fl_add_text(FL_NORMAL_TEXT,370,510,250,30,"Simulation Time");
-
-
   fl_end_form();
   fdui->otg->fdui = fdui;
   return fdui;
@@ -70,18 +64,15 @@ FD_otg *create_form_otg(void)
 
 //For more details about object parameters, refer to: http://xforms-toolkit.org/doc/xforms_25.html
 
-void show_otg_form()
-{
+void show_otg_form() {
   int eNB_id;
   char title[255];
   char *tArgv[] = { "OTG", "OTG" };
   int tArgc = 2;
-
   int major_owd = 6;
   int minor_owd = 3;
   int major_thr = 5;
   int minor_thr = 2;
-
   fl_initialize(&tArgc,tArgv,"OTG",0,0);
 
   for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) { //NB_eNB_INST
@@ -98,9 +89,6 @@ void show_otg_form()
 
     fl_set_xyplot_ytics(form_dl->throughput,major_thr, minor_thr);
     fl_set_xyplot_ybounds(form_dl->throughput,0,1000);
-
-
-
     form_ul= create_form_otg ();
     sprintf (title, "LTE UE->eNB (UL)");
     fl_show_form (form_ul->otg, FL_PLACE_HOTSPOT, FL_FULLBORDER, title);
@@ -116,20 +104,15 @@ void show_otg_form()
     //fl_set_xyplot_xgrid (form_ul->throughput, FL_GRID_MAJOR);
     fl_set_xyplot_ytics(form_ul->throughput,major_thr, minor_thr);
     fl_set_xyplot_ybounds(form_ul->throughput,0,1000);
-
-
   }
 
   //create_form_clock();
   //fl_show_form(fclock, FL_PLACE_CENTER,FL_TRANSIENT,"clocks");
   //fl_do_forms();
-
   fl_check_forms();
 }
 
-void add_tab_metric(int src, int dst, float owd, float throughput, int ctime)
-{
-
+void add_tab_metric(int src, int dst, float owd, float throughput, int ctime) {
   if (otg_forms_info->init_forms==0) {
     show_otg_form();
     otg_forms_info->init_forms=1;
@@ -158,9 +141,7 @@ void add_tab_metric(int src, int dst, float owd, float throughput, int ctime)
 }
 
 
-void plot_graphes_ul(int src, int dst, int ctime) //UE -->eNB
-{
-
+void plot_graphes_ul(int src, int dst, int ctime) { //UE -->eNB
   int i, src_idx=1, curve_id=1;
   char loss_rate[100];
   char simu_time[100];
@@ -169,12 +150,8 @@ void plot_graphes_ul(int src, int dst, int ctime) //UE -->eNB
   int y_key_position=75;
 
   if (otg_forms_info->idx_ul[src][dst]==MAX_SAMPLES-1) {
-
     fl_update_display(1); //the function flushes the X buffer so the drawing requests are on their way to the server
 
-
-
-
     if (otg_forms_info->is_data_plot_ul == -1)
       otg_forms_info->is_data_plot_ul=src;
 
@@ -184,17 +161,13 @@ void plot_graphes_ul(int src, int dst, int ctime) //UE -->eNB
       sprintf(curve_label, "%d%s%d", src,"-->", dst);
       fl_set_xyplot_key(form_ul->owd, 0, curve_label);
       fl_set_xyplot_key_position(form_ul->owd, x_key_position,y_key_position,   FL_ALIGN_BOTTOM_LEFT);
-
       fl_set_xyplot_data (form_ul->throughput, otg_forms_info->data_ctime_ul[src][dst],
                           otg_forms_info->data_throughput_ul[src][dst], otg_forms_info->idx_ul[src][dst], "", "time", "kbit/s");
       fl_set_xyplot_key(form_ul->throughput, 0, curve_label);
       fl_set_xyplot_key_font(form_ul->throughput, FL_BOLD_STYLE, FL_HUGE_SIZE);
       fl_set_xyplot_key_position(form_ul->throughput, x_key_position,y_key_position , FL_ALIGN_BOTTOM_LEFT);
-
-
-
       otg_kpi_nb_loss_pkts();
-      sprintf(loss_rate, "%s%d","NB Loss pkts UL=", otg_info->total_loss_ul);
+      sprintf(loss_rate, "%s%u","NB Loss pkts UL=", otg_info->total_loss_ul);
       fl_set_object_label(form_ul->loss_ratio, loss_rate);
       sprintf(simu_time, "%s%d","Simulation Time(ms)=", ctime);
       fl_set_object_label(form_ul->simu_time, simu_time);
@@ -204,20 +177,16 @@ void plot_graphes_ul(int src, int dst, int ctime) //UE -->eNB
       sprintf(curve_label, "%d%s%d", otg_forms_info->is_data_plot_ul,"-->", dst);
       fl_set_xyplot_key(form_ul->owd, 0, curve_label);
       fl_set_xyplot_key_position(form_ul->owd, x_key_position,y_key_position,   FL_ALIGN_BOTTOM_LEFT);
-
-
       fl_set_xyplot_data (form_ul->throughput, otg_forms_info->data_ctime_ul[otg_forms_info->is_data_plot_ul][dst],
                           otg_forms_info->data_throughput_ul[otg_forms_info->is_data_plot_ul][dst], otg_forms_info->idx_ul[otg_forms_info->is_data_plot_ul][dst], "", "time", "kbit/s");
       sprintf(curve_label, "%d%s%d", otg_forms_info->is_data_plot_ul,"-->", dst);
       fl_set_xyplot_key(form_ul->throughput, 0, curve_label);
       fl_set_xyplot_key_position(form_ul->throughput, x_key_position,y_key_position , FL_ALIGN_BOTTOM_LEFT);
-
       otg_kpi_nb_loss_pkts();
-      sprintf(loss_rate, "%s%d","NB Loss pkts UL=",otg_info->total_loss_ul);
+      sprintf(loss_rate, "%s%u","NB Loss pkts UL=",otg_info->total_loss_ul);
       fl_set_object_label(form_ul->loss_ratio, loss_rate);
       sprintf(simu_time, "%s%d","Simulation Time(ms)=", ctime);
       fl_set_object_label(form_ul->simu_time, simu_time);
-
     }
 
     for (src_idx=1; src_idx<=NB_UE_INST; src_idx++) {
@@ -229,9 +198,6 @@ void plot_graphes_ul(int src, int dst, int ctime) //UE -->eNB
         sprintf(curve_label, "%d%s%d", src_idx,"-->", dst);
         fl_set_xyplot_key(form_ul->owd, curve_id-1, curve_label);
         fl_set_xyplot_key_position(form_ul->owd, x_key_position,y_key_position,   FL_ALIGN_BOTTOM_LEFT);
-
-
-
         fl_add_xyplot_overlay(form_ul->throughput,curve_id++,
                               otg_forms_info->data_ctime_ul[src_idx][dst],
                               otg_forms_info->data_throughput_ul[src_idx][dst],
@@ -242,7 +208,6 @@ void plot_graphes_ul(int src, int dst, int ctime) //UE -->eNB
       }
     }
 
-
     for (i=0; i<otg_forms_info->idx_ul[src][dst]; i++) {
       otg_forms_info->data_ctime_ul[src][dst][otg_forms_info->idx_ul[src][dst]]=i;
       otg_forms_info->data_owd_ul[src][dst][i]= otg_forms_info->data_owd_ul[src][dst][i+1];
@@ -253,14 +218,11 @@ void plot_graphes_ul(int src, int dst, int ctime) //UE -->eNB
   }
 
   fl_check_forms();
-
 }
 
 
 
-void plot_graphes_dl(int src, int dst, int ctime)  //eNB -->UE
-{
-
+void plot_graphes_dl(int src, int dst, int ctime) { //eNB -->UE
   int i, dst_idx=1, curve_id=1;
   char loss_rate[100];
   char curve_label[100];
@@ -269,11 +231,8 @@ void plot_graphes_dl(int src, int dst, int ctime)  //eNB -->UE
   int y_key_position=75;
 
   if (otg_forms_info->idx_dl[src][dst]==MAX_SAMPLES-1) {
-
     fl_update_display(1); //the function flushes the X buffer so the drawing requests are on their way to the server
 
-
-
     if (otg_forms_info->is_data_plot_dl == -1)
       otg_forms_info->is_data_plot_dl=dst;
 
@@ -289,12 +248,10 @@ void plot_graphes_dl(int src, int dst, int ctime)  //eNB -->UE
       fl_set_xyplot_key(form_dl->throughput, 0, curve_label);
       fl_set_xyplot_key_position(form_dl->throughput, x_key_position,y_key_position,   FL_ALIGN_BOTTOM_LEFT);
       otg_kpi_nb_loss_pkts();
-      sprintf(loss_rate, "%s%d","NB Loss pkts DL=",otg_info->total_loss_dl);
+      sprintf(loss_rate, "%s%u","NB Loss pkts DL=",otg_info->total_loss_dl);
       fl_set_object_label(form_dl->loss_ratio, loss_rate);
-
       sprintf(simu_time, "%s%d","Simulation Time(ms)=", ctime);
       fl_set_object_label(form_dl->simu_time, simu_time);
-
     } else {
       fl_set_xyplot_data (form_dl->owd, otg_forms_info->data_ctime_dl[src][otg_forms_info->is_data_plot_dl],
                           otg_forms_info->data_owd_dl[src][otg_forms_info->is_data_plot_dl], otg_forms_info->idx_dl[src][otg_forms_info->is_data_plot_dl], "", "time", "ms");
@@ -306,9 +263,8 @@ void plot_graphes_dl(int src, int dst, int ctime)  //eNB -->UE
       sprintf(curve_label, "%d%s%d", src,"-->",otg_forms_info->is_data_plot_dl);
       fl_set_xyplot_key(form_dl->throughput, 0, curve_label);
       fl_set_xyplot_key_position(form_dl->throughput,x_key_position,y_key_position,   FL_ALIGN_BOTTOM_LEFT);
-
       otg_kpi_nb_loss_pkts();
-      sprintf(loss_rate, "%s%d","NB Loss pkts DL=",otg_info->total_loss_dl);
+      sprintf(loss_rate, "%s%u","NB Loss pkts DL=",otg_info->total_loss_dl);
       fl_set_object_label(form_dl->loss_ratio, loss_rate);
       sprintf(simu_time, "%s%d","Simulation Time(ms)=", ctime);
       fl_set_object_label(form_dl->simu_time, simu_time);
@@ -323,7 +279,6 @@ void plot_graphes_dl(int src, int dst, int ctime)  //eNB -->UE
         sprintf(curve_label, "%d%s%d", src,"-->", dst_idx);
         fl_set_xyplot_key(form_dl->owd,  curve_id-1, curve_label);
         fl_set_xyplot_key_position(form_dl->owd, x_key_position,y_key_position,   FL_ALIGN_BOTTOM_LEFT);
-
         fl_add_xyplot_overlay(form_dl->throughput,curve_id++,
                               otg_forms_info->data_ctime_dl[src][dst_idx],
                               otg_forms_info->data_throughput_dl[src][dst_idx],
@@ -331,8 +286,6 @@ void plot_graphes_dl(int src, int dst, int ctime)  //eNB -->UE
         sprintf(curve_label, "%d%s%d", src,"-->", dst_idx);
         fl_set_xyplot_key(form_dl->throughput,  curve_id-1, curve_label);
         fl_set_xyplot_key_position(form_dl->throughput, x_key_position,y_key_position,   FL_ALIGN_BOTTOM_LEFT);
-
-
       }
     }
 
@@ -346,7 +299,6 @@ void plot_graphes_dl(int src, int dst, int ctime)  //eNB -->UE
   }
 
   fl_check_forms();
-
 }
 
 
@@ -354,14 +306,12 @@ void plot_graphes_dl(int src, int dst, int ctime)  //eNB -->UE
 
 
 
-void exit_cb(FL_OBJECT *ob, long q)
-{
+void exit_cb(FL_OBJECT *ob, long q) {
   fl_finish();
   exit(0);
 }
 
-void create_form_clock(void)
-{
+void create_form_clock(void) {
   FL_OBJECT *obj;
 
   if (fclock)
@@ -369,22 +319,18 @@ void create_form_clock(void)
 
   fclock = fl_bgn_form(FL_NO_BOX,500,350);
   obj = fl_add_box(FL_UP_BOX,0,0,500,350,"");
-
   obj = fl_add_clock(FL_DIGITAL_CLOCK,185,20,150,35,"");
   fl_set_object_boxtype(obj,FL_ROUNDED_BOX);
   fl_set_object_color(obj,FL_COL1,FL_BLACK);
   fl_set_object_lsize(obj,FL_MEDIUM_SIZE);
   fl_set_object_lstyle(obj,FL_BOLD_STYLE);
-
   obj = fl_add_clock(FL_ANALOG_CLOCK,30,70,220,200,"");
   fl_set_object_boxtype(obj,FL_UP_BOX);
-
   obj = fl_add_clock(FL_ANALOG_CLOCK,260,70,220,200,"");
   fl_set_object_boxtype(obj,FL_OVAL3D_UPBOX);
   obj = fl_add_button(FL_NORMAL_BUTTON,375,300,110,35,"Exit");
   fl_set_object_callback(obj, exit_cb, 0);
   fl_end_form();
-
   fl_scale_form(fclock, 0.7, 0.7);
 }
 
diff --git a/openair2/UTIL/OTG/otg_kpi.c b/openair2/UTIL/OTG/otg_kpi.c
index 94a0a53d5c54025b6e7c340cfa2a3dbe8af69010..3af84adc8b303275048733b9255a6f3c92be52c9 100644
--- a/openair2/UTIL/OTG/otg_kpi.c
+++ b/openair2/UTIL/OTG/otg_kpi.c
@@ -43,23 +43,22 @@ unsigned int start_log_jitter=0;
 extern unsigned char NB_eNB_INST;
 extern unsigned char NB_UE_INST;
 
-void tx_throughput(int src, int dst, int application)
-{
-
+void tx_throughput(int src, int dst, int application) {
   if (otg_info->tx_num_bytes[src][dst][application]>0) {
     //  otg_info->tx_throughput[src][dst][application]=((double)otg_info->tx_num_bytes[src][dst][application] *1000*8)/ (get_ctime()*1024); // unit Kbit/sec, if ctime in ms
     if ((g_otg->flow_start[src][dst][application]+g_otg->flow_duration[src][dst][application]) < get_ctime() )
-      otg_info->tx_throughput[src][dst][application]=((double)otg_info->tx_num_bytes[src][dst][application] *1000*8)/ ((g_otg->flow_start[src][dst][application]+g_otg->flow_duration[src][dst][application])*1024); // unit Kbit/sec, if ctime in ms
+      otg_info->tx_throughput[src][dst][application]=((double)otg_info->tx_num_bytes[src][dst][application] *1000*8)/ ((g_otg->flow_start[src][dst][application]+g_otg->flow_duration[src][dst][application])
+          *1024); // unit Kbit/sec, if ctime in ms
     else if (g_otg->flow_start[src][dst][application] < get_ctime() )
       otg_info->tx_throughput[src][dst][application]=((double)otg_info->tx_num_bytes[src][dst][application] *1000*8)/ ((get_ctime() - g_otg->flow_start[src][dst][application])*1024);
-    else 
+    else
       LOG_W(OTG, "[src %d][dst %d][app %d] flow start time less than the simu time (start %d, duration %d, ctime %d)\n",
-	    src, dst, application,
-	    g_otg->flow_start[src][dst][application],
-	    g_otg->flow_duration[src][dst][application],
-	    get_ctime());
+            src, dst, application,
+            g_otg->flow_start[src][dst][application],
+            g_otg->flow_duration[src][dst][application],
+            get_ctime());
   }
-  
+
   if (otg_info->tx_num_bytes_background[src][dst]>0)
     otg_info->tx_throughput_background[src][dst]=((double)otg_info->tx_num_bytes_background[src][dst]*1000*8)/ (get_ctime()*1024); // unit Kbit/sec, if ctime in ms
 
@@ -71,26 +70,24 @@ void tx_throughput(int src, int dst, int application)
     //    LOG_I(OTG,"DUY, get_ctime() [i=%d,j=%d,k=%d] = %.d\n", src,dst,application,get_ctime());
     LOG_I(OTG,"otg_multicast_info->tx_num_bytes[i=%d,j=%d,k=%d] = %.d\n", src,dst,application,otg_multicast_info->tx_num_bytes[src][dst][application]);
   }
-
 }
 
 
 
-void rx_goodput(int src, int dst, int application)
-{
-
+void rx_goodput(int src, int dst, int application) {
   if (otg_info->rx_num_bytes[src][dst][application]>0) {
     // otg_info->rx_goodput[src][dst][application]=((double)otg_info->rx_num_bytes[src][dst][application]*1000*8)/(get_ctime()*1024); // unit kB/sec, if ctime in ms
-if ((g_otg->flow_start[src][dst][application]+g_otg->flow_duration[src][dst][application]) < get_ctime() )
-      otg_info->rx_goodput[src][dst][application]=((double)otg_info->rx_num_bytes[src][dst][application] *1000*8)/ ((g_otg->flow_start[src][dst][application]+g_otg->flow_duration[src][dst][application])*1024); // unit Kbit/sec, if ctime in ms
+    if ((g_otg->flow_start[src][dst][application]+g_otg->flow_duration[src][dst][application]) < get_ctime() )
+      otg_info->rx_goodput[src][dst][application]=((double)otg_info->rx_num_bytes[src][dst][application] *1000*8)/ ((g_otg->flow_start[src][dst][application]+g_otg->flow_duration[src][dst][application])
+          *1024); // unit Kbit/sec, if ctime in ms
     else if (g_otg->flow_start[src][dst][application] < get_ctime() )
       otg_info->rx_goodput[src][dst][application]=((double)otg_info->rx_num_bytes[src][dst][application] *1000*8)/ ((get_ctime() - g_otg->flow_start[src][dst][application])*1024);
-    else 
+    else
       LOG_W(OTG, "[src %d][dst %d][app %d] flow start time less than the simu time (start %d, duration %d, ctime %d)\n",
-	    src, dst, application,
-	    g_otg->flow_start[src][dst][application],
-	    g_otg->flow_duration[src][dst][application],
-	    get_ctime());
+            src, dst, application,
+            g_otg->flow_start[src][dst][application],
+            g_otg->flow_duration[src][dst][application],
+            get_ctime());
   }
 
   if (otg_info->rx_num_bytes_background[src][dst]>0)
@@ -105,9 +102,7 @@ if ((g_otg->flow_start[src][dst][application]+g_otg->flow_duration[src][dst][app
 
 
 
-void rx_loss_rate_pkts(int src, int dst, int application)
-{
-
+void rx_loss_rate_pkts(int src, int dst, int application) {
   if (otg_info->rx_num_pkt[src][dst][application]<otg_info->tx_num_pkt[src][dst][application])
     otg_info->rx_loss_rate[src][dst][application]= 1 - ((double)otg_info->rx_num_pkt[src][dst][application]/otg_info->tx_num_pkt[src][dst][application]);
   else
@@ -127,26 +122,20 @@ void rx_loss_rate_pkts(int src, int dst, int application)
     otg_multicast_info->rx_loss_rate[src][dst]= 1 - ((double)otg_multicast_info->rx_num_pkt[src][dst][application]/otg_multicast_info->tx_num_pkt[src][dst][0]);
   else
     otg_multicast_info->rx_loss_rate[src][dst]=0;
-
 }
 
 
-void rx_loss_rate_bytes(int src, int dst, int application)
-{
-
+void rx_loss_rate_bytes(int src, int dst, int application) {
   if (otg_info->rx_num_pkt[src][dst][application]<otg_info->tx_num_pkt[src][dst][application])
     otg_info->rx_loss_rate[src][dst][application]= 1 - ((double)otg_info->rx_num_bytes[src][dst][application]/otg_info->tx_num_bytes[src][dst][application]);
   else
     otg_info->rx_loss_rate[src][dst][application]=0;
 
   LOG_I(OTG, "loss rate (src=%d, dst=%d, appli %d ):: = %lf(bytes) \n",src, dst, application, otg_info->rx_loss_rate[src][dst][application]);
-
 }
 
-void otg_kpi_nb_loss_pkts(void)
-{
+void otg_kpi_nb_loss_pkts(void) {
   unsigned int i,j,k;
-
   otg_info->total_loss_dl=0;
   otg_info->total_loss_ul=0;
 
@@ -162,9 +151,7 @@ void otg_kpi_nb_loss_pkts(void)
   }
 }
 
-void average_pkt_jitter(int src, int dst, int application)
-{
-
+void average_pkt_jitter(int src, int dst, int application) {
   if (otg_info->rx_jitter_sample[src][dst][application] > 0 ) {
     otg_info->rx_jitter_avg[src][dst][application]/= otg_info->rx_jitter_sample[src][dst][application];
     otg_info->rx_jitter_avg_e2e[src][dst][application]/= otg_info->rx_jitter_sample[src][dst][application];
@@ -189,13 +176,10 @@ void average_pkt_jitter(int src, int dst, int application)
 
     LOG_T(OTG,"average_jitter_dl %lf average_jitter_ul %lf \n",otg_info->average_jitter_dl_e2e,otg_info->average_jitter_ul_e2e);
   }
-
 }
 
-void average_total_jitter(void)
-{
+void average_total_jitter(void) {
   unsigned int i,j,k;
-
   otg_info->average_jitter_dl=0;
   otg_info->average_jitter_ul=0;
   otg_info->average_jitter_dl_e2e=0;
@@ -207,7 +191,6 @@ void average_total_jitter(void)
         if (i<NB_eNB_INST) {
           otg_info->average_jitter_dl+=otg_info->rx_jitter_avg[i][j][k];
           otg_info->average_jitter_dl_e2e+=otg_info->rx_jitter_avg_e2e[i][j][k];
-
         } else {
           otg_info->average_jitter_ul+=otg_info->rx_jitter_avg[i][j][k];
           otg_info->average_jitter_ul_e2e+=otg_info->rx_jitter_avg_e2e[i][j][k];
@@ -221,10 +204,8 @@ void average_total_jitter(void)
   // otg_info->average_jitter_ul/= (float)NB_UE_INST;
 }
 
-void kpi_gen()
-{
+void kpi_gen() {
   int i, j,k;
-
   int tx_total_bytes_dl=0;
   int tx_total_pkts_dl=0;
   int rx_total_bytes_dl=0;
@@ -233,13 +214,10 @@ void kpi_gen()
   int tx_total_pkts_ul=0;
   int rx_total_bytes_ul=0;
   int rx_total_pkts_ul=0;
-
   float min_owd_dl=0;
   float max_owd_dl=0;
-
   float min_owd_dl_e2e=0;
   float max_owd_dl_e2e=0;
-
   int tx_total_bytes_dl_background=0;
   int tx_total_pkts_dl_background=0;
   int rx_total_bytes_dl_background=0;
@@ -248,27 +226,18 @@ void kpi_gen()
   int tx_total_pkts_ul_background=0;
   int rx_total_bytes_ul_background=0;
   int rx_total_pkts_ul_background=0;
-
   float min_owd_ul=0;
   float max_owd_ul=0;
   float min_owd_ul_e2e=0;
   float max_owd_ul_e2e=0;
-
-
   int tx_total_bytes_dl_multicast=0;
   int tx_total_pkts_dl_multicast=0;
   int rx_total_bytes_dl_multicast=0;
   int rx_total_pkts_dl_multicast=0;
-
-
   int num_active_source=0;
-
-
   int dl_ok=1,ul_ok=1;
-
   char traffic_type[12];
   char traffic[30];
-
 #ifdef STANDALONE
   FILE *file;
   file = fopen("log_OTG.txt", "w");
@@ -281,11 +250,8 @@ void kpi_gen()
 
 #endif
 
-
-
   for (i=0; i<(NB_eNB_INST + NB_UE_INST); i++) {
     for (j=0; j<(NB_eNB_INST + NB_UE_INST); j++) {
-
       /*background stats*/
       if (i<NB_eNB_INST) {
         tx_total_bytes_dl_background+=otg_info->tx_num_bytes_background[i][j];
@@ -300,7 +266,6 @@ void kpi_gen()
       }
 
       for (k=0; k<MAX_NUM_APPLICATION; k++) {
-
         tx_throughput(i,j,k);
         rx_goodput(i,j,k);
         rx_loss_rate_pkts(i,j,k);
@@ -319,7 +284,6 @@ void kpi_gen()
           tx_total_pkts_dl_multicast+=otg_multicast_info->tx_num_pkt[i][j][k];
           rx_total_bytes_dl_multicast+=otg_multicast_info->rx_num_bytes[i][j][k];
           rx_total_pkts_dl_multicast+=otg_multicast_info->rx_num_pkt[i][j][k];
-
 #ifdef STANDALONE
           LOG_I(OTG,"No stats for multicast ");       // do nothing
 #else
@@ -329,21 +293,17 @@ void kpi_gen()
           if (otg_multicast_info->tx_num_bytes[i][j][k]>0) {
             LOG_I(OTG,"----------------------------------------------------------\n");
             LOG_I(OTG,"Total Time (multicast) (ms)= %d \n", otg_info->ctime+1);
-
             //   LOG_I(OTG,"[%s] Multicast [eNB:%d -> UE:%d] \n",traffic_type, i, j);
-
             LOG_I(OTG,"[MULTICAST] Total packets(TX)= %d \n", otg_multicast_info->tx_num_pkt[i][j][k]);
             LOG_I(OTG,"[MULTICAST] Total bytes(TX)= %d \n", otg_multicast_info->tx_num_bytes[i][j][k]);
             LOG_I(OTG,"[MULTICAST] Total packets(RX)= %d \n", otg_multicast_info->rx_num_pkt[i][j][k]);
             LOG_I(OTG,"[MULTICAST] Total bytes(RX)= %d \n", otg_multicast_info->rx_num_bytes[i][j][k]);
-
             LOG_I(OTG,"[MULTICAST] TX throughput = %.7f (Kbit/s) \n", otg_multicast_info->tx_throughput[i][j]);
             LOG_I(OTG,"[MULTICAST] RX goodput = %.7f (Kbit/s) \n", otg_multicast_info->rx_goodput[i][j]);
             //   if (otg_multicast_info->rx_loss_rate[i][j]>0){
             //  LOG_I(OTG,"[MULTICAST] Loss rate = %lf \n", (otg_multicast_info->rx_loss_rate[i][j]));
             //  LOG_I(OTG,"[MULTICAST] NB Lost  packets=%d \n", (otg_multicast_info->tx_num_pkt[i][j][k]-otg_multicast_info->rx_num_pkt[i][j][k]));
             //}
-
             // if ((g_otg->background_stats==1)&&(otg_info->tx_num_bytes_background[i][j]>0)){
             LOG_F(OTG,"----------------------------------------------------------\n");
             LOG_F(OTG,"Total Time (multicast) (ms)= %d \n", otg_info->ctime+1);
@@ -363,12 +323,9 @@ void kpi_gen()
           }
 
 #endif
-
         }// end for multicast
 
-
         if ((otg_info->tx_throughput[i][j][k]>0)||((otg_info->tx_throughput_background[i][j]>0) && (otg_info->tx_num_bytes[i][j][k]>0)))  {
-
           num_active_source+=1;
 
           if (i<NB_eNB_INST) { // DL
@@ -392,7 +349,6 @@ void kpi_gen()
 
             if ((max_owd_dl_e2e<otg_info->rx_owd_max_e2e[i][j][k]) || (max_owd_dl_e2e==0))
               max_owd_dl_e2e=otg_info->rx_owd_max_e2e[i][j][k];
-
           } else { // UL
             tx_total_bytes_ul+=otg_info->tx_num_bytes[i][j][k];
             tx_total_pkts_ul+=otg_info->tx_num_pkt[i][j][k];
@@ -414,7 +370,6 @@ void kpi_gen()
 
             if ((max_owd_ul_e2e<otg_info->rx_owd_max_e2e[i][j][k]) || (max_owd_ul_e2e==0))
               max_owd_ul_e2e=otg_info->rx_owd_max_e2e[i][j][k];
-
           }
 
           //LOG_D(OTG,"KPI: (src=%d, dst=%d, appli %d) NB packet TX= %d,  NB packet RX= %d\n ",i, j,  otg_info->tx_num_pkt[i][j][k],  otg_info->rx_num_pkt[i][j][k]);
@@ -432,9 +387,7 @@ void kpi_gen()
             traffic[sizeof(traffic) - 1] = 0; // terminate string
           }
 
-
 #ifdef STANDALONE
-
           fprintf(file,"----------------------------------------------------------\n");
           fprintf(file,"Total Time (ms)= %d \n", otg_info->ctime+1);
 
@@ -467,8 +420,6 @@ void kpi_gen()
             }
           }
           */
-
-
 #else
           LOG_I(OTG,"----------------------------------------------------------\n");
           LOG_I(OTG,"Total Time (ms)= %d \n", otg_info->ctime+1);
@@ -555,15 +506,11 @@ void kpi_gen()
             }
           */
 #endif
-
         }
 
         //     if ((otg_multicast_info->tx_throughput[i][j]>0) && (otg_info->tx_num_bytes[i][j][k]>0))  {
-
       }// end loop of k
 
-
-
 #ifdef STANDALONE
 
       if ((g_otg->background_stats==1)&&(otg_info->tx_num_bytes_background[i][j]>0)) {
@@ -629,14 +576,10 @@ void kpi_gen()
       }
 
 #endif
-
-
     }// end loop of j
   }// end loop of i
 
-
   //  average_total_jitter();
-
 #ifdef STANDALONE
   fprintf (file,"**************** TOTAL DL RESULTS ******************\n");
   fprintf(file,"Total Time= %d \n", otg_info->ctime+1);
@@ -723,7 +666,6 @@ void kpi_gen()
     LOG_I(OTG,"[MULTICAST] RX throughput = %.7f(Kbit/s) \n", ((double)rx_total_bytes_dl_multicast*1000*8)/(otg_info->ctime*1024));
   }
 
-
   LOG_F(OTG,"**************** TOTAL DL RESULTS ******************\n");
   LOG_F(OTG,"Total Time (ms)= %d \n", otg_info->ctime+1);
   LOG_F(OTG,"[DATA] Total packets(TX)= %d \n", tx_total_pkts_dl);
@@ -762,8 +704,6 @@ void kpi_gen()
     LOG_F(OTG,"[MULTICAST] RX throughput = %.7f(Kbit/s) \n", ((double)rx_total_bytes_dl_multicast*1000*8)/(otg_info->ctime*1024));
   }
 
-
-
   LOG_I(OTG,"**************** TOTAL UL RESULTS ******************\n");
   LOG_I(OTG,"Total Time (ms)= %d \n", otg_info->ctime+1);
   LOG_I(OTG,"[DATA] Total packets(TX)= %d \n", tx_total_pkts_ul);
@@ -795,7 +735,6 @@ void kpi_gen()
     LOG_I(OTG,"[BACKGROUND] Total bytes(RX)= %d \n", rx_total_bytes_ul_background);
     LOG_I(OTG,"[BACKGROUND] TX throughput = %.7f(Kbit/s) \n", ((double)tx_total_bytes_ul_background*1000*8)/(otg_info->ctime*1024));
     LOG_I(OTG,"[BACKGROUND] RX throughput = %.7f(Kbit/s) \n", ((double)rx_total_bytes_ul_background*1000*8)/(otg_info->ctime*1024));
-
   }
 
   LOG_F(OTG,"**************** TOTAL UL RESULTS ******************\n");
@@ -825,7 +764,6 @@ void kpi_gen()
     LOG_F(OTG,"[BACKGROUND] Total bytes(RX)= %d \n", rx_total_bytes_ul_background);
     LOG_F(OTG,"[BACKGROUND] TX throughput = %.7f(Kbit/s) \n", ((double)tx_total_bytes_ul_background*1000*8)/(otg_info->ctime*1024));
     LOG_F(OTG,"[BACKGROUND] RX throughput = %.7f(Kbit/s) \n", ((double)rx_total_bytes_ul_background*1000*8)/(otg_info->ctime*1024));
-
   }
 
   if ((dl_ok == 1 ) && (ul_ok ==1))
@@ -837,8 +775,7 @@ void kpi_gen()
 }
 
 
-void add_log_metric(int src, int dst, int ctime, double metric, unsigned int label)
-{
+void add_log_metric(int src, int dst, int ctime, double metric, unsigned int label) {
   unsigned int i;
   unsigned int j;
   unsigned int node_actif=0;
@@ -846,28 +783,27 @@ void add_log_metric(int src, int dst, int ctime, double metric, unsigned int lab
   //LOG_I(OTG,"[%d][%d] LOGG_ADDED ctime=%d, metric=%.2f  \n", src, dst, ctime, metric);
 
   switch (label) {
-  case OTG_LATENCY:
-    add_log_label(label, &start_log_latency);
-    break;
-
-  case OTG_LATENCY_BG:
-    add_log_label(label, &start_log_latency_bg);
-    break;
-
-  case OTG_GP:
-    add_log_label(label, &start_log_GP);
-    break;
-
-  case OTG_GP_BG:
-    add_log_label(label, &start_log_GP_bg);
-    break;
-
-  case OTG_JITTER:
-    add_log_label(label, &start_log_GP_bg);
-    break;
-
-  default:
-    LOG_E(OTG, "File label unknown %d \n", label);
+    case OTG_LATENCY:
+      add_log_label(label, &start_log_latency);
+      break;
+
+    case OTG_LATENCY_BG:
+      add_log_label(label, &start_log_latency_bg);
+      break;
+
+    case OTG_GP:
+      add_log_label(label, &start_log_GP);
+      break;
+
+    case OTG_GP_BG:
+      add_log_label(label, &start_log_GP_bg);
+      break;
+
+    case OTG_JITTER:
+      add_log_label(label, &start_log_GP_bg);
+      break;
+    default:
+      LOG_E(OTG, "File label unknown %u \n", label);
   }
 
   LOG_F(label,"%d ", ctime);
@@ -892,8 +828,7 @@ void add_log_metric(int src, int dst, int ctime, double metric, unsigned int lab
 
 
 
-void  add_log_label(unsigned int label, unsigned int * start_log_metric)
-{
+void  add_log_label(unsigned int label, unsigned int *start_log_metric) {
   unsigned int i;
   unsigned int j;
   unsigned int node_actif=0;
@@ -910,7 +845,7 @@ void  add_log_label(unsigned int label, unsigned int * start_log_metric)
           node_actif++;
 
         if (node_actif>0)
-          LOG_F(label,"%d->%d ", i, j);
+          LOG_F(label,"%u->%u ", i, j);
       }
     }
 
diff --git a/openair2/UTIL/OTG/otg_rx.c b/openair2/UTIL/OTG/otg_rx.c
index 46cad30cb8b78a5d16b5264e8e8d0826b76da9a4..a8b18e23b7aa5f6f84b84ae7d5f2fe449ca93d69 100644
--- a/openair2/UTIL/OTG/otg_rx.c
+++ b/openair2/UTIL/OTG/otg_rx.c
@@ -38,9 +38,9 @@
 #include "otg_kpi.h"
 
 #ifdef ENABLE_DB_STATS
-#include <mysql.h>
-#include <m_ctype.h>
-#include <sql_common.h>
+  #include <mysql.h>
+  #include <m_ctype.h>
+  #include <sql_common.h>
 #endif
 
 extern unsigned char NB_eNB_INST;
@@ -54,12 +54,10 @@ extern unsigned char NB_UE_INST;
 #define MIN(x,y) ((x)<(y)?(x):(y))
 
 // Check if the packet is well received or not and extract data
-int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buffer_tx, const unsigned int size)
-{
-
+int otg_rx_pkt(const int dst_instanceP, const int ctime, const char *const buffer_tx, const unsigned int size) {
   int              bytes_read      = 0;
-  otg_hdr_info_t * otg_hdr_info_rx;
-  otg_hdr_t *      otg_hdr_rx;
+  otg_hdr_info_t *otg_hdr_info_rx;
+  otg_hdr_t       *otg_hdr_rx;
   int              is_size_ok      = 0;
   unsigned int     seq_num_rx;
   unsigned int     nb_loss_pkts;
@@ -70,26 +68,22 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff
   if (buffer_tx!=NULL) {
     otg_hdr_info_rx = (otg_hdr_info_t *) (&buffer_tx[bytes_read]);
     bytes_read += sizeof (otg_hdr_info_t);
-
-    LOG_D(OTG,"otg_rx_pkt functions: destination %d, size %d, otg_hdr_info_rx->flag %.4x, otg_hdr_info_rx->size %d \n",
+    LOG_D(OTG,"otg_rx_pkt functions: destination %d, size %u, otg_hdr_info_rx->flag %.4x, otg_hdr_info_rx->size %u \n",
           dst_instanceP,
           size,
           otg_hdr_info_rx->flag,
           otg_hdr_info_rx->size);
 
-
     if (((otg_hdr_info_rx->flag == 0xffff) ||
          (otg_hdr_info_rx->flag == 0xbbbb) ||
          (otg_hdr_info_rx->flag == 0x1000)) &&
         (otg_hdr_info_rx->size == size )) { //data traffic
-
       LOG_I(OTG,"MAX_RX_INFO %d %d \n",NB_eNB_INST,  NB_UE_INST);
-
       /*is_size_ok= 0;
       if (( otg_hdr_info_rx->size ) == size ) {*/
       is_size_ok= 1;
       otg_hdr_rx = (otg_hdr_t *) (&buffer_tx[bytes_read]);
-      LOG_I(OTG,"[SRC %d][DST %d] [FLOW_idx %d][APP TYPE %d] RX INFO pkt at time %d: flag 0x %x, seq number %d, tx time %d, size (hdr %d, pdcp %d) \n",
+      LOG_I(OTG,"[SRC %u][DST %u] [FLOW_idx %u][APP TYPE %u] RX INFO pkt at time %d: flag 0x %x, seq number %u, tx time %u, size (hdr %u, pdcp %u) \n",
             otg_hdr_rx->src_instance,
             otg_hdr_rx->dst_instance,
             otg_hdr_rx->flow_id,
@@ -99,14 +93,12 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff
             otg_hdr_rx->seq_num,
             otg_hdr_rx->time,
             otg_hdr_info_rx->size, size);
-
       bytes_read += sizeof (otg_hdr_t);
-
       src_instance = otg_hdr_rx->src_instance;
       dst_instance = otg_hdr_rx->dst_instance;
 
       if (dst_instance != dst_instanceP) {
-//#warning "LG: TODO think about multicast traffic"
+        //#warning "LG: TODO think about multicast traffic"
         /* TODO: fix this LOG, a lot of missing parameters, replaced by a simple basic version */
         /*LOG_W(OTG,"[SRC %d][DST %d] [FLOW_idx %d][APP TYPE %d] RX INFO pkt at time %d: flag 0x %x, seq number %d, tx time %d, size (hdr %d, pdcp %d)  not for dest instance %u\n",
               dst_instanceP);*/
@@ -114,7 +106,7 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff
       }
 
       if(otg_hdr_rx->traffic_type > MAX_NUM_APPLICATION) {
-        LOG_W(OTG,"RX packet: application type out of range %d for the pair of (src %d, dst %d) \n",
+        LOG_W(OTG,"RX packet: application type out of range %u for the pair of (src %u, dst %u) \n",
               otg_hdr_rx->traffic_type, src_instance, dst_instance);
         otg_hdr_rx->traffic_type=0;
       }
@@ -135,7 +127,7 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff
         //  rx_check_loss(src_instance, dst_instance, otg_hdr_info_rx->flag, otg_hdr_rx->seq_num, &seq_num_rx, &nb_loss_pkts);
         //  otg_multicast_info->loss_rate[src_instance][dst_instance][otg_hdr_rx->traffic_type]=nb_loss_pkts;
         //otg_multicast_info->rx_sn[src_instance][dst_instance][otg_hdr_rx->traffic_type]=seq_num_rx;
-        LOG_I(OTG,"received a multicast packet with size %d sn %d ran owd %d loss rate %d\n",
+        LOG_I(OTG,"received a multicast packet with size %u sn %u ran owd %u loss rate %u\n",
               otg_hdr_info_rx->size, seq_num_rx, ctime- otg_hdr_rx->time, nb_loss_pkts);
         //return 0;
       }  /** background traffic **/
@@ -148,10 +140,8 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff
           nb_loss_pkts=otg_info->nb_loss_pkts_background_ul[src_instance][dst_instance];
       }
 
-
-      LOG_D(OTG,"[%d][%d] AGGREGATION LEVEL (RX) %d \n", src_instance, dst_instance, otg_hdr_rx->aggregation_level);
+      LOG_D(OTG,"[%u][%u] AGGREGATION LEVEL (RX) %u \n", src_instance, dst_instance, otg_hdr_rx->aggregation_level);
       otg_info->aggregation_level[src_instance][dst_instance]=otg_hdr_rx->aggregation_level;
-
       /* Loss and out of sequence data management */
       lost_packet= rx_check_loss(
                      src_instance,
@@ -161,11 +151,9 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff
                      &seq_num_rx,
                      &nb_loss_pkts);
 
-
       if (otg_info->owd_const[src_instance][dst_instance][otg_hdr_rx->flow_id]==0)
         owd_const_gen(src_instance,dst_instance,otg_hdr_rx->flow_id, otg_hdr_rx->traffic_type);
 
-
       /******/
       /*
       float owd_const_capillary_v=owd_const_capillary()/2;
@@ -185,7 +173,7 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff
         otg_info->radio_access_delay[src_instance][dst_instance]=(float) (ctime- otg_hdr_rx->time);
         otg_multicast_info->radio_access_delay[src_instance][dst_instance]=(float) (ctime- otg_hdr_rx->time);
       } else {
-        LOG_I(OTG,"received packet has tx time %d greater than the current time %d\n",otg_hdr_rx->time,ctime );
+        LOG_I(OTG,"received packet has tx time %u greater than the current time %d\n",otg_hdr_rx->time,ctime );
         otg_info->radio_access_delay[src_instance][dst_instance] = 0;
         otg_multicast_info->radio_access_delay[src_instance][dst_instance]=0;
       }
@@ -196,8 +184,7 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff
       otg_info->rx_pkt_owd_e2e[src_instance][dst_instance]=
         otg_info->owd_const[src_instance][dst_instance][otg_hdr_rx->flow_id] + otg_info->radio_access_delay[src_instance][dst_instance];
       otg_multicast_info->rx_pkt_owd[src_instance][dst_instance]=otg_multicast_info->radio_access_delay[src_instance][dst_instance];
-
-      LOG_D(OTG, "[src %d][dst %d] ctime %d tx time %d: OWD %lf E2E OWD %lf \n",
+      LOG_D(OTG, "[src %u][dst %u] ctime %d tx time %u: OWD %lf E2E OWD %lf \n",
             src_instance,
             dst_instance,
             ctime,
@@ -217,7 +204,7 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff
           otg_info->rx_pkt_jitter[src_instance][dst_instance]=
             abs(otg_info->rx_pkt_owd_history[src_instance][dst_instance][0] - otg_info->rx_pkt_owd_history[src_instance][dst_instance][1]);
 
-        LOG_D(OTG,"The packet jitter for the pair (src %d, dst %d)) at %d is %lf (current %lf, previous %lf) \n",
+        LOG_D(OTG,"The packet jitter for the pair (src %u, dst %u)) at %d is %lf (current %lf, previous %lf) \n",
               src_instance, dst_instance, ctime, otg_info->rx_pkt_jitter[src_instance][dst_instance],
               otg_info->rx_pkt_owd_history[src_instance][dst_instance][0], otg_info->rx_pkt_owd_history[src_instance][dst_instance][1]);
         // e2e
@@ -230,26 +217,24 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff
           otg_info->rx_pkt_jitter_e2e[src_instance][dst_instance]=
             abs(otg_info->rx_pkt_owd_history_e2e[src_instance][dst_instance][0] - otg_info->rx_pkt_owd_history_e2e[src_instance][dst_instance][1]);
 
-        LOG_D(OTG,"The packet jitter for the pair (src %d, dst %d)) at %d is %lf (current %lf, previous %lf) \n",
+        LOG_D(OTG,"The packet jitter for the pair (src %u, dst %u)) at %d is %lf (current %lf, previous %lf) \n",
               src_instance,
               dst_instance,
               ctime,
               otg_info->rx_pkt_jitter_e2e[src_instance][dst_instance],
               otg_info->rx_pkt_owd_history_e2e[src_instance][dst_instance][0],
               otg_info->rx_pkt_owd_history_e2e[src_instance][dst_instance][1]);
-
       }
 
       if (otg_hdr_info_rx->flag == 0x1000) {
-        LOG_I(OTG,"[SRC%d -> DST %d] Received a multicast packet at time %d with size %d, seq num %d, ran owd %d number loss packet %d\n",
+        LOG_I(OTG,"[SRC%u -> DST %u] Received a multicast packet at time %d with size %u, seq num %u, ran owd %u number loss packet %u\n",
               src_instance,
               dst_instance,
               ctime,otg_hdr_info_rx->size,
               otg_hdr_rx->seq_num,
               ctime - otg_hdr_rx->time,
               nb_loss_pkts);
-
-        LOG_I(OTG,"INFO LATENCY :: [SRC %d][DST %d] radio access %.2f (tx time %d, ctime %d), OWD:%d (ms):\n",
+        LOG_I(OTG,"INFO LATENCY :: [SRC %u][DST %u] radio access %.2f (tx time %u, ctime %d), OWD:%d (ms):\n",
               src_instance,
               dst_instance,
               otg_multicast_info->radio_access_delay[src_instance][dst_instance],
@@ -286,8 +271,7 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff
 
         otg_multicast_info->rx_total_bytes_dl+=otg_hdr_info_rx->size;
       } else {
-
-        LOG_I(OTG,"[SRC %d][DST %d] Stats :: radio access latency %.2f (tx time %d, ctime %d) jitter %.2f, Estimated E2E OWD:%.2f (ms):\n",
+        LOG_I(OTG,"[SRC %u][DST %u] Stats :: radio access latency %.2f (tx time %u, ctime %d) jitter %.2f, Estimated E2E OWD:%.2f (ms):\n",
               src_instance,
               dst_instance,
               otg_info->radio_access_delay[src_instance][dst_instance],
@@ -296,7 +280,6 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff
               otg_info->rx_pkt_owd_e2e[src_instance][dst_instance]);
 
         if (otg_hdr_info_rx->flag == 0xffff) {
-
           if (otg_info->rx_owd_max[src_instance][dst_instance][otg_hdr_rx->traffic_type]==0) {
             otg_info->rx_owd_max[src_instance][dst_instance][otg_hdr_rx->traffic_type]=otg_info->rx_pkt_owd[src_instance][dst_instance];
             otg_info->rx_owd_min[src_instance][dst_instance][otg_hdr_rx->traffic_type]=otg_info->rx_pkt_owd[src_instance][dst_instance];
@@ -332,7 +315,6 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff
             otg_info->rx_jitter_avg_e2e[src_instance][dst_instance][otg_hdr_rx->traffic_type] +=  otg_info->rx_pkt_jitter_e2e[src_instance][dst_instance];
             otg_info->rx_jitter_sample[src_instance][dst_instance][otg_hdr_rx->traffic_type] +=1;
           }
-
         }
 
         if (g_otg->curve==1) {
@@ -355,15 +337,12 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff
           otg_info->rx_total_bytes_dl+=otg_hdr_info_rx->size;
         else
           otg_info->rx_total_bytes_ul+=otg_hdr_info_rx->size;
-
       }
 
       //LOG_I(OTG,"RX INFO :: RTT MIN(one way) ms: %.2f, RTT MAX(one way) ms: %.2f \n", otg_info->rx_owd_min[src][dst], otg_info->rx_owd_max[src][dst]);
-
       /* xforms part: add metrics  */
-
       //printf("payload_size %d, header_size %d \n", otg_hdr_rx->pkts_size, otg_hdr_rx->hdr_type);
-      LOG_I(OTG,"[RX] OTG packet, PACKET SIZE [SRC %d][DST %d]: Flag (0x%x), Traffic %d, time(%d), Seq num (%d), Total size (%d)\n",
+      LOG_I(OTG,"[RX] OTG packet, PACKET SIZE [SRC %u][DST %u]: Flag (0x%x), Traffic %u, time(%d), Seq num (%u), Total size (%u)\n",
             src_instance,
             dst_instance,
             otg_hdr_info_rx->flag,
@@ -372,7 +351,6 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff
             otg_hdr_rx->seq_num, size);
       /*LOG_I(OTG,"details::RX [SRC %d][DST %d]: Flag (0x%x), time(%d), Seq num (%d), Total size (%d), header(%d), payload (%d) \n",  src, dst, otg_hdr_info_rx->flag, ctime, otg_hdr_rx->seq_num, size, strlen(packet_rx->header), strlen(packet_rx->payload));*/
 
-
       if (otg_hdr_info_rx->flag == 0xffff) {
         otg_info->rx_num_pkt[src_instance][dst_instance][otg_hdr_rx->traffic_type]+=1;
         otg_info->rx_num_bytes[src_instance][dst_instance][otg_hdr_rx->traffic_type]+=otg_hdr_info_rx->size;
@@ -402,7 +380,6 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff
                          otg_hdr_rx->time,
                          ((otg_hdr_info_rx->size*1000*8)/(otg_info->rx_pkt_owd[src_instance][dst_instance]*1024 )),
                          OTG_GP); /* compute the throughput in Kbit/s  */
-
       } else if (otg_hdr_info_rx->flag == 0x1000) {
         otg_multicast_info->rx_num_pkt[src_instance][dst_instance][otg_hdr_rx->traffic_type]+=1;
         otg_multicast_info->rx_num_bytes[src_instance][dst_instance][otg_hdr_rx->traffic_type]+=otg_hdr_info_rx->size;
@@ -446,18 +423,17 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff
 
       if (is_size_ok == 0) {
         otg_hdr_rx = (otg_hdr_t *) (&buffer_tx[bytes_read]);
-        LOG_W(OTG,"[SRC %d][DST %d] RX pkt: seq number %d size mis-matche (hdr %d, pdcp %d) \n",
+        LOG_W(OTG,"[SRC %u][DST %u] RX pkt: seq number %u size mis-matche (hdr %u, pdcp %u) \n",
               src_instance, dst_instance, otg_hdr_rx->seq_num, otg_hdr_info_rx->size, size);
         otg_info->nb_loss_pkts_otg[src_instance][dst_instance]++;
       }
 
       return(0);
     } else {
-      LOG_W(OTG,"RX: Not an OTG pkt, forward to upper layer (flag %x, size %d, pdcp_size %d) FIX ME \n",
+      LOG_W(OTG,"RX: Not an OTG pkt, forward to upper layer (flag %x, size %u, pdcp_size %u) FIX ME \n",
             otg_hdr_info_rx->flag, otg_hdr_info_rx->size, size);
       return(1); //to be fixed on the real case to one
     }
-
   }
 
   return(0);
@@ -471,10 +447,8 @@ int rx_check_loss(
   const int dst,
   const unsigned int flag,
   const int seq_num,
-  unsigned int * const seq_num_rx,
-  unsigned int * const nb_loss_pkts)
-{
-
+  unsigned int *const seq_num_rx,
+  unsigned int *const nb_loss_pkts) {
   /* Loss and out of sequence data management, we have 3 case : */
   /* (1) Receieved packet corresponds to the expected one, in terms of the sequence number*/
   int lost_packet=0;
@@ -509,8 +483,7 @@ void owd_const_gen(
   const int src,
   const int dst,
   const int flow_id,
-  const unsigned int flag)
-{
+  const unsigned int flag) {
   otg_info->owd_const[src][dst][flow_id]=(owd_const_mobile_core()+owd_const_IP_backbone()+owd_const_application())/2;
 
   if ((flag==M2M)||(flag==M2M_TRAFFIC)||(flag==AUTO_PILOT_L)||(flag==AUTO_PILOT_M)||(flag==AUTO_PILOT_H)||(flag==VIRTUAL_GAME_L)||(flag==VIRTUAL_GAME_M)|| (flag==VIRTUAL_GAME_H)||(flag==VIRTUAL_GAME_F)
@@ -523,8 +496,7 @@ void owd_const_gen(
 
 
 
-float owd_const_capillary(void)
-{
+float owd_const_capillary(void) {
   /*return (uniform_dist(MIN_APPLICATION_PROCESSING_GATEWAY_DELAY, MAX_APPLICATION_PROCESSING_GATEWAY_DELAY) +
    uniform_dist(MIN_FORMATING_TRANSFERRING_DELAY, MAX_FORMATING_TRANSFERRING_DELAY) +
    uniform_dist(MIN_ACCESS_DELAY, MAX_ACCESS_DELAY) +
@@ -534,8 +506,7 @@ float owd_const_capillary(void)
 }
 
 
-float owd_const_mobile_core(void)
-{
+float owd_const_mobile_core(void) {
   /*double delay;
   // this is a delay model for a loaded GGSN according to
   //"M. Laner, P. Svoboda and M. Rupp, Latency Analysis of 3G Network Components, EW'12, Poznan, Poland, 2012", table 2, page 6.
@@ -559,15 +530,12 @@ float owd_const_mobile_core(void)
   return ((double)MIN_U_PLANE_CORE_IP_ACCESS_DELAY+ (double)MAX_U_PLANE_CORE_IP_ACCESS_DELAY + (double)MIN_FW_PROXY_DELAY + (double)MAX_FW_PROXY_DELAY)/2;
 }
 
-float owd_const_IP_backbone(void)
-{
+float owd_const_IP_backbone(void) {
   /*return uniform_dist(MIN_NETWORK_ACCESS_DELAY,MAX_NETWORK_ACCESS_DELAY);*/
   return ((double)MIN_NETWORK_ACCESS_DELAY+(double)MAX_NETWORK_ACCESS_DELAY)/2;
-
 }
 
-float owd_const_application(void)
-{
+float owd_const_application(void) {
   /*return uniform_dist(MIN_APPLICATION_ACESS_DELAY, MAX_APPLICATION_ACESS_DELAY);*/
   return ((double)MIN_APPLICATION_ACESS_DELAY+(double)MAX_APPLICATION_ACESS_DELAY)/2;
 }
diff --git a/openair2/UTIL/OTG/otg_tx.c b/openair2/UTIL/OTG/otg_tx.c
index ac3ffd0fb29b0bfdf7666c13e7122b9d7b76d6b8..2459bb7338860747e488f1edfc98d98ca407cbfa 100644
--- a/openair2/UTIL/OTG/otg_tx.c
+++ b/openair2/UTIL/OTG/otg_tx.c
@@ -305,10 +305,10 @@ unsigned char *packet_gen(
       otg_info->tx_num_pkt[src_instance][dst_instance][otg_info->traffic_type[src_instance][dst_instance]]+=1;
 
       if (size!=strlen(payload))
-        LOG_E(OTG,"[%d][%d] [0x %x] The expected packet size does not match the payload size : size %d, strlen %zu, seq_num %d packet: |%s|%s| \n",
+        LOG_E(OTG,"[%d][%d] [0x %x] The expected packet size does not match the payload size : size %u, strlen %zu, seq_num %u packet: |%s|%s| \n",
               src_instance, dst_instance, flag,   size, strlen(payload), seq_num, header, payload);
       else
-        LOG_D(OTG,"[%d][%d] 0x %x][m2m Aggre %d][Flow %d][Type %d/%s] TX INFO pkt at time %d Size= [payload %d] [Total %zu] with seq num %d, state=%d : |%s|%s| \n",
+        LOG_D(OTG,"[%d][%d] 0x %x][m2m Aggre %u][Flow %u][Type %u/%s] TX INFO pkt at time %d Size= [payload %u] [Total %zu] with seq num %u, state=%u : |%s|%s| \n",
               src_instance, dst_instance, flag,
               otg_info->m2m_aggregation[src_instance][dst_instance],
               otg_info->flow_id[src_instance][dst_instance],
@@ -316,7 +316,7 @@ unsigned char *packet_gen(
               map_int_to_str(otg_app_type_names,otg_info->traffic_type[src_instance][dst_instance]),
               ctime,  size, header_size+strlen(payload), seq_num,state, header, payload);
 
-      LOG_D(OTG, "[%d]MY_SEQ %d \n", otg_info->traffic_type[src_instance][dst_instance], otg_info->seq_num[src_instance][dst_instance][otg_info->traffic_type[src_instance][dst_instance]] );
+      LOG_D(OTG, "[%u]MY_SEQ %d \n", otg_info->traffic_type[src_instance][dst_instance], otg_info->seq_num[src_instance][dst_instance][otg_info->traffic_type[src_instance][dst_instance]] );
     } else {
       if ((g_otg->aggregation_level[src_instance][dst_instance][application]*otg_info->size_background[src_instance][dst_instance])<=PAYLOAD_MAX)
         otg_info->size_background[src_instance][dst_instance]=g_otg->aggregation_level[src_instance][dst_instance][application]*otg_info->size_background[src_instance][dst_instance];
@@ -335,7 +335,7 @@ unsigned char *packet_gen(
       otg_info->seq_num_background[src_instance][dst_instance]+=1;
 
       if (otg_info->size_background[src_instance][dst_instance]!=strlen(payload))
-        LOG_E(OTG,"[%d][%d] [0x %x] The expected packet size does not match the payload size : size %d, strlen %zu, seq num %d, packet |%s|%s| \n",
+        LOG_E(OTG,"[%d][%d] [0x %x] The expected packet size does not match the payload size : size %d, strlen %zu, seq num %u, packet |%s|%s| \n",
               src_instance,
               dst_instance,
               flag,
@@ -345,7 +345,7 @@ unsigned char *packet_gen(
               header,
               payload);
       else
-        LOG_D(OTG,"[%d][%d][0x %x][%d] TX INFO pkt at time %s size is %d with seq num %d, state=%d : |%s|%s| \n",
+        LOG_D(OTG,"[%d][%d][0x %x][%d] TX INFO pkt at time %s size is %d with seq num %u, state=%u : |%s|%s| \n",
               src_instance,
               dst_instance,
               flag,
@@ -367,7 +367,7 @@ unsigned char *packet_gen(
       otg_info->tx_total_bytes_ul+=buffer_size;
 
     if (otg_info->traffic_type[src_instance][dst_instance] > MAX_NUM_APPLICATION) {
-      LOG_W(OTG,"application type out of range %d for the pair of (src %d, dst %d) \n",
+      LOG_W(OTG,"application type out of range %u for the pair of (src %d, dst %d) \n",
             otg_info->traffic_type[src_instance][dst_instance], src_instance, dst_instance);
       otg_info->traffic_type[src_instance][dst_instance]=0;
     }
@@ -425,7 +425,7 @@ unsigned char *packet_gen_multicast(
           g_otg_multicast->idt_max[src_instance][dst_instance][app]));
       size = ceil(uniform_dist(g_otg_multicast->size_min[src_instance][dst_instance][app],
                                g_otg_multicast->size_max[src_instance][dst_instance][app]));
-      LOG_D(OTG, "ptime %d, ctime %d idt %d (min %d, max %d) size %d (min %d, max %d)\n",
+      LOG_D(OTG, "ptime %d, ctime %d idt %d (min %d, max %d) size %u (min %d, max %d)\n",
             otg_multicast_info->ptime[src_instance][dst_instance][application],
             ctime,
             otg_multicast_info->idt[src_instance][dst_instance][app],
@@ -459,10 +459,10 @@ unsigned char *packet_gen_multicast(
             otg_multicast_info->tx_num_bytes[src_instance][dst_instance][app]);
 
       if (size!=strlen(payload))
-        LOG_E(OTG,"[src %d][dst %d] The expected packet size does not match the payload size : size %d, strlen %zu \n",
+        LOG_E(OTG,"[src %d][dst %d] The expected packet size does not match the payload size : size %u, strlen %zu \n",
               src_instance, dst_instance, size, strlen(payload));
       else {
-        LOG_I(OTG,"[src %d][dst %d]TX INFO pkt at time %d Size= [payload %d] [Total %zu] with seq num %d: |%s|%s| \n",
+        LOG_I(OTG,"[src %d][dst %d]TX INFO pkt at time %d Size= [payload %u] [Total %zu] with seq num %d: |%s|%s| \n",
               src_instance,
               dst_instance,
               ctime,
@@ -557,7 +557,7 @@ int check_data_transmit(
   // for (application=0; application<g_otg->application_idx[src_instance][dst_instance]; application++){
   otg_info->gen_pkts=0;
 
-  LOG_T(OTG,"FLOW_INFO [src %d][dst %d] [IDX %d] [APPLICATION TYPE %d] MAX %d [M2M %d ]\n",
+  LOG_T(OTG,"FLOW_INFO [src %d][dst %d] [IDX %d] [APPLICATION TYPE %d] MAX %u [M2M %u ]\n",
         src_instance, dst_instance, app,
         g_otg->application_type[src_instance][dst_instance][app],
         g_otg->application_idx[src_instance][dst_instance],
@@ -605,7 +605,7 @@ int check_data_transmit(
 
       if (((state==PU_STATE)||(state==ED_STATE))|| (otg_info->idt[src_instance][dst_instance][app]==0)
           || (( (ctime-otg_info->ptime[src_instance][dst_instance][app]) >= otg_info->idt[src_instance][dst_instance][app] ) )) {
-        LOG_D(OTG,"[TX] OTG packet: Time To Transmit::OK (Source= %d, Destination= %d, Application %d, State= %d) , (IDT= %d ,ctime= %d, ptime= %d) \n",
+        LOG_D(OTG,"[TX] OTG packet: Time To Transmit::OK (Source= %d, Destination= %d, Application %d, State= %u) , (IDT= %d ,ctime= %d, ptime= %d) \n",
               src_instance,
               dst_instance ,
               app,
@@ -654,7 +654,7 @@ int check_data_transmit(
         if   (g_otg->m2m[src_instance][dst_instance][app]==M2M)
           otg_info->traffic_type[src_instance][dst_instance]=app;//g_otg->application_idx[src_instance][dst_instance];//M2M;
 
-        LOG_D(OTG,"[BACKGROUND=%d] Time To Transmit [SRC %d][DST %d][APPLI %d] \n", otg_info->traffic_type_background[src_instance][dst_instance], src_instance, dst_instance, app);
+        LOG_D(OTG,"[BACKGROUND=%u] Time To Transmit [SRC %d][DST %d][APPLI %d] \n", otg_info->traffic_type_background[src_instance][dst_instance], src_instance, dst_instance, app);
       }
 
     }
@@ -720,7 +720,7 @@ void header_size_gen(
     if ((g_otg->application_type[src_instance][dst_instance][application]==VOIP_G711)||(g_otg->application_type[src_instance][dst_instance][application]==VOIP_G729))
       size_header+=RTP_HEADER;
 
-    LOG_D(OTG,"Header size is %d [IP V=%d][PROTO=%d]\n",  size_header, g_otg->ip_v[src_instance][dst_instance][application],g_otg->trans_proto[src_instance][dst_instance][application]);
+    LOG_D(OTG,"Header size is %u [IP V=%d][PROTO=%d]\n",  size_header, g_otg->ip_v[src_instance][dst_instance][application],g_otg->trans_proto[src_instance][dst_instance][application]);
     otg_info->header_size_app[src_instance][dst_instance][application]=size_header;
   }
 }
@@ -889,7 +889,7 @@ unsigned char * serialize_buffer(
   otg_hdr_p->traffic_type=traffic_type;
   byte_tx_count += sizeof(otg_hdr_t);
 
-  LOG_I(OTG,"traffic type %d\n",otg_hdr_p->traffic_type);
+  LOG_I(OTG,"traffic type %u\n",otg_hdr_p->traffic_type);
   // copy the header first
   memcpy(&tx_buffer[byte_tx_count], header, strlen(header));
   byte_tx_count += strlen(header);
@@ -1953,7 +1953,7 @@ int header_size_gen_background(
     otg_info->header_size_background[src_instance][dst_instance]=size_header;
   }
 
-  LOG_D(OTG," [SRC %d][DST %d]  BACKGROUND TRAFFIC:: size header %d \n", src_instance, dst_instance, otg_info->header_size_background[src_instance][dst_instance]);
+  LOG_D(OTG," [SRC %d][DST %d]  BACKGROUND TRAFFIC:: size header %u \n", src_instance, dst_instance, otg_info->header_size_background[src_instance][dst_instance]);
   return otg_info->header_size_background[src_instance][dst_instance];
 }
 
@@ -1987,7 +1987,7 @@ void state_management(
 
       if (ctime>otg_info->start_holding_time_off[src_instance][dst_instance][application]) {
         otg_info->c_holding_time_off[src_instance][dst_instance][application]= ctime - otg_info->start_holding_time_off[src_instance][dst_instance][application];
-        LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%d] STATE:: OFF Holding Time %d (%d, %d)\n", src_instance, dst_instance,application , g_otg->aggregation_level[src_instance][dst_instance][application],
+        LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%u] STATE:: OFF Holding Time %u (%d, %u)\n", src_instance, dst_instance,application , g_otg->aggregation_level[src_instance][dst_instance][application],
               otg_info->c_holding_time_off[src_instance][dst_instance][application], ctime, otg_info->start_holding_time_off[src_instance][dst_instance][application]);
       }
 
@@ -1997,7 +1997,7 @@ void state_management(
                 +g_otg->prob_off_pe[src_instance][dst_instance][application])))
            && (otg_info->c_holding_time_off[src_instance][dst_instance][application]>=g_otg->holding_time_off_pu[src_instance][dst_instance][application])) {
         otg_info->state[src_instance][dst_instance][application]=PU_STATE;
-        LOG_I(OTG,"[%d][%d][Appli id %d][Agg Level=%d] NEW STATE:: OFF-->PU  %d  (ctime %d, start %d )\n", src_instance, dst_instance,application,
+        LOG_I(OTG,"[%d][%d][Appli id %d][Agg Level=%u] NEW STATE:: OFF-->PU  %u  (ctime %d, start %u )\n", src_instance, dst_instance,application,
               g_otg->aggregation_level[src_instance][dst_instance][application], otg_info->c_holding_time_off[src_instance][dst_instance][application], ctime,
               otg_info->start_holding_time_off[src_instance][dst_instance][application]);
         otg_info->state_transition_prob[src_instance][dst_instance][application]=uniform_dist(0,1);
@@ -2007,7 +2007,7 @@ void state_management(
                    && (otg_info->state_transition_prob[src_instance][dst_instance][application]< 1-g_otg->prob_off_pe[src_instance][dst_instance][application]))
                   && (otg_info->c_holding_time_off[src_instance][dst_instance][application]>=g_otg->holding_time_off_ed[src_instance][dst_instance][application])) {
         otg_info->state[src_instance][dst_instance][application]=ED_STATE;
-        LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%d] NEW STATE:: OFF-->ED \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]);
+        LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%u] NEW STATE:: OFF-->ED \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]);
         otg_info->state_transition_prob[src_instance][dst_instance][application]=uniform_dist(0,1);
       }
 
@@ -2015,13 +2015,13 @@ void state_management(
                 && (otg_info->state_transition_prob[src_instance][dst_instance][application]<=1))
                && (otg_info->c_holding_time_off[src_instance][dst_instance]>=g_otg->holding_time_off_pe[src_instance][dst_instance])) {
         otg_info->state[src_instance][dst_instance][application]=PE_STATE;
-        LOG_I(OTG,"[%d][%d][Appli id %d][Agg Level=%d] NEW STATE:: OFF-->PE \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]);
+        LOG_I(OTG,"[%d][%d][Appli id %d][Agg Level=%u] NEW STATE:: OFF-->PE \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]);
         otg_info->state_transition_prob[src_instance][dst_instance][application]=uniform_dist(0,1);
 
       } else {
         otg_info->c_holding_time_off[src_instance][dst_instance][application]= ctime - otg_info->start_holding_time_off[src_instance][dst_instance][application];
         otg_info->state_transition_prob[src_instance][dst_instance][application]=uniform_dist(0,1);
-        LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%d] STATE:: OFF\n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]);
+        LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%u] STATE:: OFF\n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]);
       }
 
       break;
@@ -2033,20 +2033,20 @@ void state_management(
         otg_info->state[src_instance][dst_instance][application]=OFF_STATE;
         otg_info->start_holding_time_off[src_instance][dst_instance][application]=ctime;
         otg_info->c_holding_time_off[src_instance][dst_instance][application]=0;
-        LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%d] NEW STATE:: PU-->OFF \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]);
+        LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%u] NEW STATE:: PU-->OFF \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]);
         otg_info->state_transition_prob[src_instance][dst_instance][application]=uniform_dist(0,1);
       } else if  ((otg_info->state_transition_prob[src_instance][dst_instance][application]<=1-g_otg->prob_pu_pe[src_instance][dst_instance][application])
                   && (otg_info->state_transition_prob[src_instance][dst_instance][application]>1-(g_otg->prob_pu_ed[src_instance][dst_instance][application]
                       +g_otg->prob_pu_pe[src_instance][dst_instance][application]))) {
         //otg_info->state[src_instance][dst_instance]=ON_STATE;
         otg_info->state[src_instance][dst_instance][application]=ED_STATE;
-        LOG_I(OTG,"[%d][%d][Appli id %d][Agg Level=%d] NEW STATE:: PU-->ED \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]);
+        LOG_I(OTG,"[%d][%d][Appli id %d][Agg Level=%u] NEW STATE:: PU-->ED \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]);
         otg_info->state_transition_prob[src_instance][dst_instance][application]=uniform_dist(0,1);
       } else { /*if (otg_info->state_transition_prob[src_instance][dst_instance]>=g_otg->prob_pu_ed)*/
         //otg_info->state[src_instance][dst_instance]=ON_STATE;
         otg_info->state[src_instance][dst_instance][application]=PE_STATE;
         otg_info->start_holding_time_pe_off[src_instance][dst_instance][application]=ctime;
-        LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%d] NEW STATE:: PU-->PE \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]);
+        LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%u] NEW STATE:: PU-->PE \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]);
         otg_info->state_transition_prob[src_instance][dst_instance][application]=uniform_dist(0,1);
       }
 
@@ -2059,20 +2059,20 @@ void state_management(
         otg_info->state[src_instance][dst_instance][application]=OFF_STATE;
         otg_info->start_holding_time_off[src_instance][dst_instance][application]=ctime;
         otg_info->c_holding_time_off[src_instance][dst_instance][application]=0;
-        LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%d] NEW STATE:: ED-->OFF \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]);
+        LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%u] NEW STATE:: ED-->OFF \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]);
         otg_info->state_transition_prob[src_instance][dst_instance][application]=uniform_dist(0,1);
       } else if  ((otg_info->state_transition_prob[src_instance][dst_instance][application]>=1-(g_otg->prob_ed_pu[src_instance][dst_instance][application] +
                    g_otg->prob_ed_pe[src_instance][dst_instance][application] ))
                   && (otg_info->state_transition_prob[src_instance][dst_instance][application]<1-g_otg->prob_ed_pe[src_instance][dst_instance][application]))  {
         //otg_info->state[src_instance][dst_instance]=ON_STATE;
         otg_info->state[src_instance][dst_instance][application]=PE_STATE;
-        LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%d] NEW STATE:: ED-->PU \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]);
+        LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%u] NEW STATE:: ED-->PU \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]);
         otg_info->state_transition_prob[src_instance][dst_instance][application]=uniform_dist(0,1);
       } else { /*if ((otg_info->state_transition_prob[src_instance][dst_instance]>=1-g_otg->prob_ed_pe)&&(otg_info->state_transition_prob[src_instance][dst_instance]<=1)) */
         //otg_info->state[src_instance][dst_instance]=ON_STATE;
         otg_info->state[src_instance][dst_instance][application]=PE_STATE;
         otg_info->start_holding_time_pe_off[src_instance][dst_instance][application]=ctime;
-        LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%d] NEW STATE:: ED-->PE \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]);
+        LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%u] NEW STATE:: ED-->PE \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]);
         otg_info->state_transition_prob[src_instance][dst_instance][application]=uniform_dist(0,1);
       }
 
@@ -2082,7 +2082,7 @@ void state_management(
       if (g_otg->holding_time_pe_off[src_instance][dst_instance][application]<=otg_info->c_holding_time_pe_off[src_instance][dst_instance][application]) {
         //otg_info->state[src_instance][dst_instance]=OFF_STATE;
         otg_info->state[src_instance][dst_instance][application]=OFF_STATE;
-        LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%d] NEW STATE:: PE->OFF\n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]);
+        LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%u] NEW STATE:: PE->OFF\n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]);
         otg_info->c_holding_time_pe_off[src_instance][dst_instance][application]=0;
         otg_info->state_transition_prob[src_instance][dst_instance][application]=uniform_dist(0,1);
         otg_info->start_holding_time_off[src_instance][dst_instance][application]=ctime;
@@ -2097,7 +2097,7 @@ void state_management(
       break;
 
     default:
-      LOG_W(OTG,"Unknown state(%d) \n", otg_info->state[src_instance][dst_instance][application]);
+      LOG_W(OTG,"Unknown state(%u) \n", otg_info->state[src_instance][dst_instance][application]);
       otg_info->state[src_instance][dst_instance][application]= OFF_STATE; // switch to default state
 
       break;
@@ -2145,13 +2145,13 @@ void voip_traffic(
       if (ctime>otg_info->start_voip_silence[src_instance][dst_instance][application])
         otg_info->c_holding_time_silence[src_instance][dst_instance][application]= ctime - otg_info->start_voip_silence[src_instance][dst_instance][application];
 
-      LOG_D(OTG,"[%d][%d][Appli id %d] VOIP STATE:: SILENCE %d (ctime=%d, start=%d)\n", src_instance, dst_instance,application,
+      LOG_D(OTG,"[%d][%d][Appli id %d] VOIP STATE:: SILENCE %u (ctime=%d, start=%u)\n", src_instance, dst_instance,application,
             otg_info->c_holding_time_silence[src_instance][dst_instance][application], ctime, otg_info->start_voip_silence[src_instance][dst_instance][application]);
     }
 
     if (otg_info->c_holding_time_silence[src_instance][dst_instance][application]>=otg_info->silence_time[src_instance][dst_instance][application]) {
       otg_info->voip_state[src_instance][dst_instance][application]=SIMPLE_TALK;
-      LOG_I(OTG,"[%d][%d][Appli id %d] NEW VOIP STATE :: SILENCE-->TALK  %d  (ctime=%d, start=%d )\n", src_instance, dst_instance,application ,
+      LOG_I(OTG,"[%d][%d][Appli id %d] NEW VOIP STATE :: SILENCE-->TALK  %u  (ctime=%d, start=%u )\n", src_instance, dst_instance,application ,
             otg_info->c_holding_time_silence[src_instance][dst_instance][application], ctime, otg_info->start_voip_silence[src_instance][dst_instance][application]);
       otg_info->start_voip_talk[src_instance][dst_instance][application]=ctime;
       otg_info->c_holding_time_talk[src_instance][dst_instance][application]=0;
@@ -2160,7 +2160,7 @@ void voip_traffic(
       if (ctime>otg_info->start_voip_silence[src_instance][dst_instance][application])
         otg_info->c_holding_time_silence[src_instance][dst_instance][application]= ctime - otg_info->start_voip_silence[src_instance][dst_instance][application];
 
-      LOG_I(OTG,"[%d][%d][Appli id %d] STATE:: SILENCE [timer:%d] \n", src_instance, dst_instance,application, otg_info->c_holding_time_silence[src_instance][dst_instance][application]);
+      LOG_I(OTG,"[%d][%d][Appli id %d] STATE:: SILENCE [timer:%u] \n", src_instance, dst_instance,application, otg_info->c_holding_time_silence[src_instance][dst_instance][application]);
     }
 
     break;
@@ -2168,7 +2168,7 @@ void voip_traffic(
   case SIMPLE_TALK:
     if (otg_info->c_holding_time_talk[src_instance][dst_instance][application]>=otg_info->simple_talk_time[src_instance][dst_instance][application]) {
       otg_info->voip_state[src_instance][dst_instance][application]=SILENCE;
-      LOG_I(OTG,"[%d][%d][Appli id %d] NEW VOIP STATE:: TALK-->SILENCE  %d  (ctime=%d, start=%d )\n", src_instance, dst_instance,application ,
+      LOG_I(OTG,"[%d][%d][Appli id %d] NEW VOIP STATE:: TALK-->SILENCE  %u  (ctime=%d, start=%u )\n", src_instance, dst_instance,application ,
             otg_info->c_holding_time_talk[src_instance][dst_instance][application], ctime, otg_info->start_voip_talk[src_instance][dst_instance][application]);
       otg_info->start_voip_silence[src_instance][dst_instance][application]=ctime;
       otg_info->c_holding_time_silence[src_instance][dst_instance][application]=0;
@@ -2177,15 +2177,15 @@ void voip_traffic(
       if (ctime>otg_info->start_voip_talk[src_instance][dst_instance][application])
         otg_info->c_holding_time_talk[src_instance][dst_instance][application]= ctime - otg_info->start_voip_talk[src_instance][dst_instance][application];
 
-      LOG_I(OTG,"[%d][%d][Appli id %d] VOIP STATE:: TALK [timer:%d]\n", src_instance, dst_instance,application, otg_info->c_holding_time_talk[src_instance][dst_instance][application]);
-      LOG_I(OTG, "test_talk [ctime %d] [start talk %d] [%d] \n",ctime, otg_info->start_voip_talk[src_instance][dst_instance][application],
+      LOG_I(OTG,"[%d][%d][Appli id %d] VOIP STATE:: TALK [timer:%u]\n", src_instance, dst_instance,application, otg_info->c_holding_time_talk[src_instance][dst_instance][application]);
+      LOG_I(OTG, "test_talk [ctime %d] [start talk %u] [%u] \n",ctime, otg_info->start_voip_talk[src_instance][dst_instance][application],
             otg_info->c_holding_time_talk[src_instance][dst_instance][application] );
     }
 
     break;
 
   default:
-    LOG_W(OTG,"Unknown VOIP state(%d) \n", otg_info->voip_state[src_instance][dst_instance][application]);
+    LOG_W(OTG,"Unknown VOIP state(%u) \n", otg_info->voip_state[src_instance][dst_instance][application]);
     otg_info->voip_state[src_instance][dst_instance][application]= SILENCE; // switch to default state
 
     break;
diff --git a/openair2/UTIL/OTG/otg_tx_socket.c b/openair2/UTIL/OTG/otg_tx_socket.c
index 026dc3e8b836344ea81099aa7b59a4df829acf3b..073b9b6ddd83f1fb22579ffea539ca6a823f1e34 100644
--- a/openair2/UTIL/OTG/otg_tx_socket.c
+++ b/openair2/UTIL/OTG/otg_tx_socket.c
@@ -36,28 +36,28 @@
 
 #ifdef WIN32 /* si vous êtes sous Windows */
 
-#include <winsock2.h>
+  #include <winsock2.h>
 
 #elif defined (linux) /* si vous êtes sous Linux */
 
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <unistd.h> /* close */
-#include <netdb.h> /* gethostbyname */
-#include <errno.h>
-
-#define INVALID_SOCKET -1
-#define SOCKET_ERROR -1
-#define closesocket(s) close(s)
-typedef int SOCKET;
-typedef struct sockaddr_in SOCKADDR_IN;
-typedef struct sockaddr SOCKADDR;
-typedef struct in_addr IN_ADDR;
+  #include <sys/types.h>
+  #include <sys/socket.h>
+  #include <netinet/in.h>
+  #include <arpa/inet.h>
+  #include <unistd.h> /* close */
+  #include <netdb.h> /* gethostbyname */
+  #include <errno.h>
+
+  #define INVALID_SOCKET -1
+  #define SOCKET_ERROR -1
+  #define closesocket(s) close(s)
+  typedef int SOCKET;
+  typedef struct sockaddr_in SOCKADDR_IN;
+  typedef struct sockaddr SOCKADDR;
+  typedef struct in_addr IN_ADDR;
 #else /* sinon vous êtes sur une plateforme non supportée */
 
-#error not defined for this platform
+  #error not defined for this platform
 
 #endif
 
@@ -67,11 +67,8 @@ control_hdr_t *control_hdr;
 
 
 
-void socket_packet_send(int src, int dst, int state,int ctime)
-{
-
+void socket_packet_send(int src, int dst, int state,int ctime) {
   init_control_header();
-
   LOG_I(OTG,"SOCKET:: IP version %d, Transport Protocol %d \n", g_otg->ip_v[src], g_otg->trans_proto[src]);
 
   if ((g_otg->ip_v[src]==1) && (g_otg->trans_proto[src]==2))
@@ -85,29 +82,20 @@ void socket_packet_send(int src, int dst, int state,int ctime)
 
   if ((g_otg->ip_v[src]==2) && (g_otg->trans_proto[src]==1))
     client_socket_udp_ip6(src, dst, state, ctime);
-
-
-
 }
 
 
 
 
-void client_socket_tcp_ip4(int src, int dst, int state, int ctime)
-{
-
+void client_socket_tcp_ip4(int src, int dst, int state, int ctime) {
 #define PORT 7777
-
-
   LOG_I(OTG,"SOCKET:: TCP-IP4 :: src= %d , dst= %d , state= %d \n", src, dst, state);
-
 #if defined (WIN32)
   WSADATA WSAData;
   int erreur = WSAStartup(MAKEWORD(2,2), &WSAData);
 #else
   int erreur = 0;
 #endif
-
   SOCKET sock;
   SOCKADDR_IN sin;
   int sock_err;
@@ -118,94 +106,69 @@ void client_socket_tcp_ip4(int src, int dst, int state, int ctime)
   if(!erreur) {
     /* Create socket */
     sock = socket(AF_INET, SOCK_STREAM, 0);
-
     /* Configure the connection */
     sin.sin_addr.s_addr = inet_addr(g_otg->dst_ip[src]);
     sin.sin_family = AF_INET;
     sin.sin_port = htons(PORT);
-
     /* connection is ok */
-
     printf("SOCKET:: TCP-IP4 :: \n");
 
-    if(connect(sock, (SOCKADDR*)&sin, sizeof(sin)) != SOCKET_ERROR) {
+    if(connect(sock, (SOCKADDR *)&sin, sizeof(sin)) != SOCKET_ERROR) {
       LOG_I(OTG,"SOCKET:: TCP-IP4 :: Create socket %s with dst port %d\n", inet_ntoa(sin.sin_addr), htons(sin.sin_port));
       ctime=0;
       LOG_I(OTG,"SOCKET:: TCP-IP4 :: ctime=%d, duration=%d \n", ctime, g_otg->duration[src]);
-
       init_control_header();
 
-
       do {
         //payload=NULL;
         //payload=packet_gen_socket(src, dst, state, ctime);
         //payload="CCCCC";
-
         char *payload_rest;
         payload_rest=packet_gen_socket(src, dst, state, ctime);
 
         if (payload_rest!=NULL) {
-
-
-
           payload_t *payload;
           payload= malloc(sizeof(payload_t));
           // Data serialization
           char *tx_buffer;
           tx_buffer= (char *)malloc(PAYLOAD_MAX);
-
           payload->control_hdr=otg_info_hdr_gen(src, dst, TCP, IPV4);
-
           payload->payload_rest=payload_rest;
           memcpy(tx_buffer, payload->control_hdr, sizeof (control_hdr_t));
           memcpy(tx_buffer+ sizeof (control_hdr_t), payload->payload_rest, strlen(payload_rest));
-
-
           int total_size=sizeof(control_hdr_t) + strlen(payload_rest);
 
-
           if((sock_err = send(sock, tx_buffer, total_size, 0)) != SOCKET_ERROR)
             LOG_I(OTG,"SOCKET:: TCP-IP4 :: Payload to send size :: %d \n",sock_err);
           else
             LOG_I(OTG,"SOCKET:: TCP-IP4 :: Transmission Error\n");
-
+          free(payload);
+          free(tx_buffer);
         }
 
         ctime+=1;
-
-
       } while (ctime<=g_otg->duration[src]) ;
-
-
     }
     /* connection is not possible..." */
     else
       LOG_I(OTG,"SOCKET:: TCP-IP4 :: connection is not possible to connect \n");
 
-
     /* close the socket */
     closesocket(sock);
-
   }
 }
 
 
 
-void client_socket_udp_ip4(int src, int dst, int state,int ctime)
-{
-
+void client_socket_udp_ip4(int src, int dst, int state,int ctime) {
   char *payload_rest;
   signed int udp_send;
-
-
-
   int sockfd, ok, addr_in_size;
   u_short portnum = 12345;
   struct sockaddr_in *to;
   struct hostent *toinfo;
   char *htoname = "127.0.0.1";
   u_long toaddr;
-
   LOG_I(OTG,"SOCKET:: UDP-IP4 :: src= %d , dst= %d , state= %d \n", src, dst, state);
   to = (struct sockaddr_in *)malloc(sizeof(struct sockaddr_in));
 
@@ -226,7 +189,6 @@ void client_socket_udp_ip4(int src, int dst, int state,int ctime)
 
   to->sin_port = portnum;
 
-
   //
   /*
 
@@ -238,8 +200,6 @@ void client_socket_udp_ip4(int src, int dst, int state,int ctime)
     memset(control_hdr, 0, sizeof(control_hdr_t));
   */
   //
-
-
   if((sockfd = socket (PF_INET, SOCK_DGRAM, 0)) == -1) {
     LOG_W(OTG,"SOCKET:: UDP-IP4 :: Error %d in socket: %s\n",errno,sys_errlist[errno]);
     exit(errno);
@@ -249,21 +209,20 @@ void client_socket_udp_ip4(int src, int dst, int state,int ctime)
     payload_rest=packet_gen_socket(src, dst, state, ctime);
 
     if (payload_rest!=NULL) {
-
       payload_t *payload;
       payload= malloc(sizeof(payload_t));
       // Data serialization
       char *tx_buffer;
       tx_buffer= (char *)malloc(PAYLOAD_MAX);
-
-
+      if (tx_buffer == NULL || payload == NULL) {
+          LOG_E(OTG,"Memory allocation failed\n");
+          return;
+      }
       payload->control_hdr=otg_info_hdr_gen(src, dst, UDP, IPV4);
       payload->payload_rest=payload_rest;
       memcpy(tx_buffer, payload->control_hdr, sizeof (control_hdr_t));
       memcpy(tx_buffer+ sizeof (control_hdr_t), payload->payload_rest, strlen(payload_rest));
       int total_size=sizeof(control_hdr_t) + strlen(payload_rest);
-
-
       udp_send=sendto(sockfd, tx_buffer,total_size ,0,(struct sockaddr *)to,addr_in_size);
       LOG_I(OTG,"SOCKET:: UDP-IP4 :: Payload to send :: data sent:%d \n", udp_send);
       // Update TX OTG info
@@ -271,69 +230,42 @@ void client_socket_udp_ip4(int src, int dst, int state,int ctime)
       //otg_info->rx_num_bytes[src][dst]+=  udp_send + (HDR_IP_v4 + HDR_UDP);
       //
 
-      if (NULL != payload) {
-        payload=NULL;
-        free(payload);
-      }
-
-      if (NULL != tx_buffer) {
-        tx_buffer=NULL;
-        free(tx_buffer);
-      }
-
-
-
+      free(payload);
+      free(tx_buffer);
     }
 
     if(udp_send == -1) {
       LOG_I(OTG,"SOCKET:: UDP-IP4 :: Transmission Error\n");
       exit(errno);
-    }
-
-    else
+    } else
       LOG_I(OTG,"SOCKET:: UDP-IP4 :: No data to transmit\n");
 
     ctime+=1;
-
-
   } while (ctime<=g_otg->duration[src]) ;
 
   closesocket(sockfd);
-
 }
 
 
-void client_socket_tcp_ip6(int src, int dst, int state,int ctime)
-{
+void client_socket_tcp_ip6(int src, int dst, int state,int ctime) {
   printf("client TCP IPv6\n");
-
 }
 
-void client_socket_udp_ip6(int src, int dst, int state,int ctime)
-{
+void client_socket_udp_ip6(int src, int dst, int state,int ctime) {
   printf("client UDP IPv6\n");
-
 }
 
 
 
 
-char* packet_gen_socket(int src, int dst, int state, int ctime)
-{
-
+char *packet_gen_socket(int src, int dst, int state, int ctime) {
   int size;
   char *payload=NULL;
-
-
   set_ctime(ctime);
   LOG_I(OTG,"SOCKET :: num_nodes_tx:: %d , seed:: %d \n", g_otg->num_nodes, g_otg->seed);
-
   LOG_I(OTG,"SOCKET :: NODE_INFO (Source= %d, Destination= %d,State= %d) ctime %d \n", src, dst, state, otg_info->ctime);
-
-
   LOG_I(OTG,"SOCKET :: INFO_SIM (src=%d, dst=%d, state=%d) application=%d, idt dist =%d, pkts dist= %d\n", src, dst, state, g_otg->application_type[src][dst], g_otg->idt_dist[src][dst][state],
         g_otg->size_dist[src][dst][state]);
-
   LOG_I(OTG,"SOCKET :: Transmission info: idt=%d, simulation time=%d \n", otg_info->idt[src][dst], ctime);
 
   // do not generate packet for this pair of src, dst : no app type and/or idt are defined
@@ -352,7 +284,6 @@ char* packet_gen_socket(int src, int dst, int state, int ctime)
   //end pre-config
 
   if ((otg_info->idt[src][dst]==(ctime-otg_info->ptime[src][dst][state])) || (otg_info->idt[src][dst]==0)) {
-
     LOG_I(OTG,"SOCKET :: Time To Transmit (Source= %d, Destination= %d,State= %d) , (IDT= %d ,simu time= %d, previous packet time= %d) \n", src, dst, state ,otg_info->idt[src][dst], ctime,
           otg_info->ptime[src][dst][state]);
     otg_info->ptime[src][dst][state]=ctime;
@@ -362,8 +293,6 @@ char* packet_gen_socket(int src, int dst, int state, int ctime)
     return 0; // do not generate the packet, and keep the idt
   }
 
-
-
   size=size_dist(src, dst, state);
   LOG_I(OTG,"SOCKET :: Generate Packet for (Source= %d, Destination= %d,State= %d) , pkt size dist= %d, simu time= %d ,packet size=%d \n",
         src, dst, state, g_otg->size_dist[src][dst][state], otg_info->ctime, size);
@@ -374,15 +303,12 @@ char* packet_gen_socket(int src, int dst, int state, int ctime)
     size=(5* sizeof(int))+10;
 
   payload=payload_pkts(size);
-
   return(payload);
-
 }
 
 
 
-control_hdr_t *otg_info_hdr_gen(int src, int dst, int trans_proto, int ip_v)
-{
+control_hdr_t *otg_info_hdr_gen(int src, int dst, int trans_proto, int ip_v) {
   control_hdr->src=src;
   control_hdr->dst=dst;
   control_hdr->trans_proto=trans_proto;
@@ -391,15 +317,11 @@ control_hdr_t *otg_info_hdr_gen(int src, int dst, int trans_proto, int ip_v)
   LOG_I(OTG,"SOCKET :: control header src %d\n",control_hdr->dst);
   LOG_I(OTG,"SOCKET :: control header src %d\n",control_hdr->trans_proto);
   LOG_I(OTG,"SOCKET :: control header src %d\n",control_hdr->ip_v);
-
-
   return control_hdr;
-
 }
 
 
-void init_control_header()
-{
+void init_control_header() {
   //set otg header to 0
   control_hdr = calloc(1, sizeof(control_hdr_t));
 
diff --git a/openair2/UTIL/TIMER/umts_timer.c b/openair2/UTIL/TIMER/umts_timer.c
deleted file mode 100644
index 1691fac363865c4b77ccfc9a9a22e9ef6bee2008..0000000000000000000000000000000000000000
--- a/openair2/UTIL/TIMER/umts_timer.c
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- * 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
- */
-
-/***************************************************************************
-                          umts_timer.c  -  description
-                             -------------------
-  AUTHOR  : Lionel GAUTHIER
-  COMPANY : EURECOM
-  EMAIL   : Lionel.Gauthier@eurecom.fr
-
-
-
- ***************************************************************************/
-//#include "rtos_header.h"
-#include "platform_types.h"
-
-#include "list.h"
-#include "umts_timer_struct.h"
-#include "mem_block.h"
-#include "openair_defs.h"
-//-----------------------------------------------------------------------------
-void
-umts_timer_check_time_out (list2_t * atimer_listP, uint32_t current_frame_tick_millisecondsP)
-{
-  //-----------------------------------------------------------------------------
-  struct timer_unit *timer;
-  mem_block_t      *mem_unit;
-  uint8_t              time_out = 255;
-  mem_unit = atimer_listP->head;
-
-  // do it simple now.
-  while ((mem_unit) && (time_out)) {
-    timer = (struct timer_unit *) (mem_unit->data);
-
-    if ((current_frame_tick_millisecondsP - timer->frame_tick_start) >= timer->frame_time_out) {
-
-      mem_unit = list2_remove_head (atimer_listP);
-      (*(timer->proc)) (timer->protocol, timer->timer_id);
-      free_mem_block (mem_unit, __func__);
-
-      mem_unit = atimer_listP->head;
-    } else {
-      time_out = 0;
-    }
-  }
-}
-
-//-----------------------------------------------------------------------------
-void
-umts_timer_delete_timer (list2_t * atimer_listP, void *timer_idP)
-{
-  //-----------------------------------------------------------------------------
-  mem_block_t      *mem_unit;
-  mem_unit = atimer_listP->head;
-
-  while ((mem_unit)) {
-    if (((struct timer_unit *) (mem_unit->data))->timer_id == timer_idP) {
-      list2_remove_element (mem_unit, atimer_listP);
-      free_mem_block (mem_unit, __func__);
-      return;
-    }
-
-    mem_unit = mem_unit->next;
-  }
-}
-
-//-----------------------------------------------------------------------------
-mem_block_t      *
-umts_add_timer_list_up (list2_t * atimer_listP, void (*procP) (void *, void *), void *protocolP, void *timer_idP, uint32_t frame_time_outP, uint32_t current_frame_tick_millisecondsP)
-{
-  //-----------------------------------------------------------------------------
-  struct mem_block_t *mb;
-  struct timer_unit *timer;
-  mem_block_t      *mem_unit;
-  int32_t             remaining_time;
-  uint8_t              inserted = 0;
-
-  mb = get_free_mem_block (sizeof (struct timer_unit), __func__);
-  if(mb==NULL) return NULL;
-  ((struct timer_unit *) (mb->data))->proc = procP;
-  ((struct timer_unit *) (mb->data))->protocol = protocolP;
-  ((struct timer_unit *) (mb->data))->timer_id = timer_idP;
-  ((struct timer_unit *) (mb->data))->frame_time_out = frame_time_outP;
-  ((struct timer_unit *) (mb->data))->frame_tick_start = current_frame_tick_millisecondsP;
-
-  // insert the timer in list in ascending order
-  mem_unit = atimer_listP->head;
-
-  while ((mem_unit) && (!inserted)) {
-    timer = (struct timer_unit *) (mem_unit->data);
-
-    remaining_time = timer->frame_time_out - current_frame_tick_millisecondsP + timer->frame_tick_start;
-
-    // not timed out
-    if ((remaining_time > 0) && (frame_time_outP < remaining_time)) {
-      inserted = 255;
-
-      if (mem_unit == atimer_listP->head) {
-#ifdef DEBUG_TIMER
-        msg ("[TIMER][CREATION] added timer_id %p at head time out %d current time %d proc %p \n", timer_idP, frame_time_outP, current_frame_tick_millisecondsP, *procP);
-#endif
-        list2_add_head (mb, atimer_listP);
-      } else {
-#ifdef DEBUG_TIMER
-        msg ("[TIMER][CREATION] inserted timer_id %p  time out %d current time %d proc %p \n", timer_idP, frame_time_outP, current_frame_tick_millisecondsP, *procP);
-#endif
-        mb->previous = mem_unit->previous;
-        mb->next = mem_unit;
-        mem_unit->previous->next = mb;
-        mem_unit->previous = mb;
-      }
-    } else {
-      mem_unit = mem_unit->next;
-    }
-  }
-
-  if (!inserted) {
-#ifdef DEBUG_TIMER
-    msg ("[TIMER][CREATION] added timer_id %p at tail time out %d current time %d proc %p \n", timer_idP, frame_time_outP, current_frame_tick_millisecondsP, *procP);
-#endif
-    list2_add_tail (mb, atimer_listP);
-  }
-
-  return mb;
-}
-
-//-----------------------------------------------------------------------------
-void
-umts_stop_all_timers (list2_t * atimer_listP)
-{
-  //-----------------------------------------------------------------------------
-  list2_free (atimer_listP);
-}
-
-//-----------------------------------------------------------------------------
-void
-umts_stop_all_timers_except (list2_t * atimer_listP, void (*procP) (void *, void *))
-{
-  //-----------------------------------------------------------------------------
-  struct timer_unit *timer;
-  mem_block_t      *mem_unit;
-  mem_block_t      *mem_unit_to_delete;
-  mem_unit = atimer_listP->head;
-
-  while ((mem_unit)) {
-    timer = (struct timer_unit *) (mem_unit->data);
-
-    if (timer->proc != procP) {
-      mem_unit_to_delete = mem_unit;
-      mem_unit = mem_unit->next;
-      list2_remove_element (mem_unit_to_delete, atimer_listP);
-      free_mem_block (mem_unit_to_delete, __func__);
-    } else {
-      mem_unit = mem_unit->next;
-    }
-  }
-}
diff --git a/openair2/UTIL/TIMER/umts_timer.h b/openair2/UTIL/TIMER/umts_timer.h
deleted file mode 100644
index 077b55cf0c6bf3b5b249e861a7bfaa5046352993..0000000000000000000000000000000000000000
--- a/openair2/UTIL/TIMER/umts_timer.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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
- */
-
-/***************************************************************************
-                          umts_timer.h  -  description
-                             -------------------
-  AUTHOR  : Lionel GAUTHIER
-  COMPANY : EURECOM
-  EMAIL   : Lionel.Gauthier@eurecom.fr
-
-
- ***************************************************************************/
-#ifndef __UMTS_TIMER_H__
-#    define __UMTS_TIMER_H__
-
-
-#    include "platform_types.h"
-#    include "lists_proto_extern.h"
-#    include "mem_mngt_proto_extern.h"
-
-#    define UMTS_TIMER_NOT_STARTED  0x00
-#    define UMTS_TIMER_STARTED      0x01
-#    define UMTS_TIMER_TIMED_OUT    0x02
-
-
-void            umts_timer_check_time_out (list2_t * atimer_listP, uint32_t current_frame_tick_millisecondsP);
-mem_block      *umts_add_timer_list_up (list2_t * atimer_listP, void (*procP) (void *, void *), void *protocolP, void *timer_idP, uint32_t frame_time_outP, uint32_t current_frame_tick_millisecondsP);
-
-struct timer_unit {
-
-  void            (*proc) (void *, void *);     // proc executed when time_out
-  void           *protocol;     // arg should be a pointer on a allocated protocol entity private struct including its variables
-  void           *timer_id;     // arg should be a value or a pointer identifying the timer
-  // Example: rlc_am_sdu_discard_time_out(rlc_am, sdu)
-  uint32_t             frame_time_out;
-  uint32_t             frame_tick_start;
-};
-#endif
diff --git a/openair2/UTIL/TIMER/umts_timer_proto_extern.h b/openair2/UTIL/TIMER/umts_timer_proto_extern.h
deleted file mode 100644
index b43b347e465360e1ded7332c41d1e9372e6e2533..0000000000000000000000000000000000000000
--- a/openair2/UTIL/TIMER/umts_timer_proto_extern.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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
- */
-
-/***************************************************************************
-                          umts_timer_proto_extern.h  -  description
-                             -------------------
-  AUTHOR  : Lionel GAUTHIER
-  COMPANY : EURECOM
-  EMAIL   : Lionel.Gauthier@eurecom.fr
-
-
- ***************************************************************************/
-#ifndef __UMTS_TIMER_PROTO_EXTERN_H__
-#    define __UMTS_TIMER_PROTO_EXTERN_H__
-
-#    include "platform_types.h"
-#    include "list.h"
-#    include "mem_block.h"
-
-extern void     umts_timer_check_time_out (list2_t * atimer_listP, uint32_t current_frame_tick_millisecondsP);
-extern void     umts_timer_delete_timer (list2_t * atimer_listP, void *timer_idP);
-extern mem_block_t *umts_add_timer_list_up (list2_t * atimer_listP, void (*procP) (void *, void *), void *protocolP, void *timer_idP, uint32_t frame_time_outP,
-    uint32_t current_frame_tick_millisecondsP);
-extern void     umts_stop_all_timers (list2_t * atimer_listP);
-extern void     umts_stop_all_timers_except (list2_t * atimer_listP, void (*procP) (void *, void *));
-#endif
diff --git a/openair2/UTIL/TIMER/umts_timer_struct.h b/openair2/UTIL/TIMER/umts_timer_struct.h
deleted file mode 100644
index c4886c7f80241eac6e83cad74db6b98939f8f52f..0000000000000000000000000000000000000000
--- a/openair2/UTIL/TIMER/umts_timer_struct.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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
- */
-
-/***************************************************************************
-                          umts_timer_struct.h  -  description
-                             -------------------
-  AUTHOR  : Lionel GAUTHIER
-  COMPANY : EURECOM
-  EMAIL   : Lionel.Gauthier@eurecom.fr
-
-
-
- ***************************************************************************/
-#ifndef __UMTS_TIMER_STRUCT_H__
-#    define __UMTS_TIMER_STRUCT_H__
-
-#    include "platform_types.h"
-
-struct timer_unit {
-
-  void            (*proc) (void *, void *);     // proc executed when time_out
-  void           *protocol;     // arg should be a pointer on a allocated protocol entity private struct including its variables
-  void           *timer_id;     // arg should be a value or a pointer identifying the timer
-  // Example: rlc_am_sdu_discard_time_out(rlc_am, sdu)
-  uint32_t             frame_time_out;
-  uint32_t             frame_tick_start;
-};
-#endif
diff --git a/openair2/X2AP/MESSAGES/ASN1/R10/x2ap-10.7.0.asn1 b/openair2/X2AP/MESSAGES/ASN1/R10/x2ap-10.7.0.asn1
old mode 100755
new mode 100644
diff --git a/openair2/X2AP/MESSAGES/ASN1/R11/x2ap-11.9.0.asn1 b/openair2/X2AP/MESSAGES/ASN1/R11/x2ap-11.9.0.asn1
old mode 100755
new mode 100644
diff --git a/openair2/X2AP/MESSAGES/ASN1/R12/x2ap-12.8.0.asn1 b/openair2/X2AP/MESSAGES/ASN1/R12/x2ap-12.8.0.asn1
old mode 100755
new mode 100644
diff --git a/openair2/X2AP/MESSAGES/ASN1/R13/x2ap-13.7.0.asn1 b/openair2/X2AP/MESSAGES/ASN1/R13/x2ap-13.7.0.asn1
old mode 100755
new mode 100644
diff --git a/openair2/X2AP/MESSAGES/ASN1/R14/x2ap-14.6.0.asn1 b/openair2/X2AP/MESSAGES/ASN1/R14/x2ap-14.6.0.asn1
old mode 100755
new mode 100644
diff --git a/openair2/X2AP/MESSAGES/ASN1/R15/x2ap-15.1.0.asn1 b/openair2/X2AP/MESSAGES/ASN1/R15/x2ap-15.1.0.asn1
old mode 100755
new mode 100644
diff --git a/openair2/X2AP/MESSAGES/ASN1/R15/x2ap-15.2.0.asn1 b/openair2/X2AP/MESSAGES/ASN1/R15/x2ap-15.2.0.asn1
old mode 100755
new mode 100644
diff --git a/openair2/X2AP/MESSAGES/ASN1/R8/x2ap-8.9.0.asn1 b/openair2/X2AP/MESSAGES/ASN1/R8/x2ap-8.9.0.asn1
old mode 100755
new mode 100644
diff --git a/openair2/X2AP/MESSAGES/ASN1/R9/x2ap-9.6.0.asn1 b/openair2/X2AP/MESSAGES/ASN1/R9/x2ap-9.6.0.asn1
old mode 100755
new mode 100644
diff --git a/openair2/X2AP/Makefile.inc b/openair2/X2AP/Makefile.inc
deleted file mode 100755
index a301a9934e924736868412284605a76a4946b668..0000000000000000000000000000000000000000
--- a/openair2/X2AP/Makefile.inc
+++ /dev/null
@@ -1,107 +0,0 @@
-
-ASN1MESSAGESDIR=$(X2AP_DIR)/MESSAGES
-ASN1DIR=$(ASN1MESSAGESDIR)/ASN1
-
-#//ifeq ($(USE_MME), R10)
-#//	ASN1RELDIR=R10.7
-#//else
-#//ASN1RELDIR=R11.2
-#//endif
-
-# TEMP
-ASN1RELDIR=R11.2
-
-
-include $(ASN1DIR)/$(ASN1RELDIR)/Makefile.inc
-
-libx2ap_OBJECTS = \
-	x2ap.o        \
-	x2ap_common.o \
-	$(addprefix MESSAGES/ASN1/$(ASN1RELDIR)/, $(X2AP_ASN_MODULE_SOURCES))
-
-
-
-# pull in dependency info for *existing* .o files
--include $(OUTDIR)/*.d
-
-CFLAGS =            \
-	-Wall           \
-	-DENB_MODE      \
-	-DENABLE_USE_MME    \
-	-I.        \
-	-I$(ASN1MESSAGESDIR)/ASN1/$(ASN1RELDIR) \
-	-I$(ASN1MESSAGESDIR) \
-	-I$(OUTDIR)     \
-	-I../UTILS      \
-	$(ADD_CFLAGS)       \
-	$(X2AP_CFLAGS)      \
-	-Wuninitialized     \
-	-Werror=implicit-function-declaration
-
-X2AP_GENERATED =    \
-	$(OUTDIR)/x2ap_encoder.o    \
-	$(OUTDIR)/x2ap_decoder.o    \
-	$(OUTDIR)/x2ap_xer_print.o
-
-$(OUTDIR)/%.o : %.c
-	@echo "Compiling $<"
-	@echo "Compiling $<  with CFLAGS= $(CFLAGS)"
-	@if [ ! -d $(dir $@) ]; then mkdir -p $(dir $@); fi;
-	@$(CC) -c $(CFLAGS) -o $@ $<
-	@$(CC) -MM $(CFLAGS) $< > $(basename $@).d
-	@mv -f $(basename $@).d $(basename $@).d.tmp
-	@sed -e 's|.*:|$@:|' < $(basename $@).d.tmp > $(basename $@).d
-	@sed -e 's/.*://' -e 's/\\$$//' < $(basename $@).d.tmp | fmt -1 | \
-	sed -e 's/^ *//' -e 's/$$/:/' >> $(basename $@).d
-	@rm -f $(basename $@).d.tmp
-
-$(X2AP_GENERATED): %.o : %.c
-	@echo "Compiling $<"
-	@echo "Compiling $<  with CFLAGS= $(CFLAGS)"
-	@if [ ! -d $(dir $@) ]; then mkdir -p $(dir $@); fi;
-	@$(CC) -c $(CFLAGS) -o $@ $<
-	@$(CC) -MM $(CFLAGS) $< > $(basename $@).d
-	@mv -f $(basename $@).d $(basename $@).d.tmp
-	@sed -e 's|.*:|$@:|' < $(basename $@).d.tmp > $(basename $@).d
-	@sed -e 's/.*://' -e 's/\\$$//' < $(basename $@).d.tmp | fmt -1 | \
-	sed -e 's/^ *//' -e 's/$$/:/' >> $(basename $@).d
-	@rm -f $(basename $@).d.tmp
-
-
-$(OUTDIR)/x2ap_ieregen.stamp: $(ASN1DIR)/$(ASN1RELDIR)/X2AP-PDU-Contents.asn $(ASN1DIR)/asn1tostruct.py
-	@if [ ! -d $(OUTDIR) ]; then mkdir -p $(OUTDIR); fi;
-	@python $(ASN1DIR)/asn1tostruct.py -f$< -o$(OUTDIR) 
-	@echo Timestamp > $@
-
-#ProtocolExtensionContainer
-#$(ASN1DIR)/$(ASN1RELDIR)/X2AP-PDU.asn 
-
-$(OUTDIR)/x2ap_asn1regen.stamp:  $(ASN1DIR)/$(ASN1RELDIR)/X2AP-CommonDataTypes.asn  $(ASN1DIR)/$(ASN1RELDIR)/X2AP-Constants.asn $(ASN1DIR)/$(ASN1RELDIR)/X2AP-IEs.asn  $(ASN1DIR)/$(ASN1RELDIR)/X2AP-PDU.asn   
-	@echo "Timestamp DIR " $(ASN1DIR) " DIRREL " $(ASN1RELDIR)
-#	(cd $(ASN1DIR)/$(ASN1RELDIR) && asn1c -fhave_native64 -gen-PER -fcompound-names $^)
-	(cd $(ASN1MESSAGESDIR) && asn1c -fhave_native64 -gen-PER -fcompound-names -fskeletons-copy $^)
-	@echo "Timestamp X2AP_CFLAGS: " $(X2AP_CFLAGS)
-	@echo Timestamp > $@	
-
-$(OUTDIR)/libx2ap.a: $(OUTDIR)/x2ap_ieregen.stamp $(OUTDIR)/x2ap_asn1regen.stamp $(X2AP_GENERATED) $(addprefix $(OUTDIR)/,$(libx2ap_OBJECTS))
-	@echo Creating X2AP archive
-	@echo libx2ap_OBJECTS $(libx2ap_OBJECTS)
-	@$(AR) rcs $@ $(X2AP_GENERATED) $(addprefix $(OUTDIR)/,$(libx2ap_OBJECTS))
-
-clean:
-	@$(RM_F_V) $(OUTDIR)/*.o
-	@$(RM_F_V) $(OUTDIR)/*.d
-	@$(RM_F_V) $(addprefix $(OUTDIR)/MESSAGES/ASN1/$(ASN1RELDIR), $(X2AP_ASN_MODULE_SOURCES))
-	@$(RM_F_V) $(addprefix $(OUTDIR)/MESSAGES/ASN1/$(ASN1RELDIR), $(X2AP_ASN_MODULE_SOURCES:.o=.d))
-	@$(RM_F_V) $(OUTDIR)/libx2ap.a
-	@$(RM_F_V) $(OUTDIR)/x2ap_asn1regen.stamp
-	@$(RM_F_V) $(OUTDIR)/x2ap_ieregen.stamp
-	@$(RM_F_V) $(OUTDIR)/x2ap_decoder.c $(OUTDIR)/x2ap_encoder.c
-	@$(RM_F_V) $(OUTDIR)/x2ap_xer_print.c $(OUTDIR)/x2ap_ies_defs.h
-
-cleanall: clean
-	@$(RM_F_V) $(addprefix $(OUTDIR)/MESSAGES/ASN1/$(ASN1RELDIR), $(X2AP_ASN_MODULE_SOURCES:.o=.c))
-	@$(RM_F_V) $(addprefix $(OUTDIR)/MESSAGES/ASN1/$(ASN1RELDIR), $(X2AP_ASN_MODULE_SOURCES:.o=.h))
-
-showcflags:
-	@echo x2ap cflags: $(CFLAGS)
diff --git a/openair2/X2AP/x2ap_eNB.c b/openair2/X2AP/x2ap_eNB.c
index 9058cc5c774c4c6b7ca22a37dfad7700e538968f..9305c34ac7e03f33ee51810fadec69c6c808fad4 100644
--- a/openair2/X2AP/x2ap_eNB.c
+++ b/openair2/X2AP/x2ap_eNB.c
@@ -19,6 +19,13 @@
  *      contact@openairinterface.org
  */
 
+/*! \file x2ap_eNB.c
+ * \brief x2ap tasks for eNB
+ * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr>
+ * \date 2018
+ * \version 1.0
+ */
+
 #include <pthread.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -64,33 +71,31 @@ void x2ap_eNB_register_eNB(x2ap_eNB_instance_t *instance_p,
                            uint32_t             enb_port_for_X2C,
                            int                  multi_sd);
 
+static
+void x2ap_eNB_handle_handover_req(instance_t instance,
+                                  x2ap_handover_req_t *x2ap_handover_req);
 
 static
-void x2ap_eNB_handle_sctp_data_ind(instance_t instance, sctp_data_ind_t *sctp_data_ind) {
+void x2ap_eNB_handle_handover_req_ack(instance_t instance,
+                                      x2ap_handover_req_ack_t *x2ap_handover_req_ack);
 
+static
+void x2ap_eNB_handle_sctp_data_ind(instance_t instance, sctp_data_ind_t *sctp_data_ind) {
   int result;
-
   DevAssert(sctp_data_ind != NULL);
-
   x2ap_eNB_handle_message(instance, sctp_data_ind->assoc_id, sctp_data_ind->stream,
                           sctp_data_ind->buffer, sctp_data_ind->buffer_length);
-
   result = itti_free(TASK_UNKNOWN, sctp_data_ind->buffer);
   AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
-
 }
 
 static
-void x2ap_eNB_handle_sctp_association_resp(instance_t instance, sctp_new_association_resp_t *sctp_new_association_resp)
-{
+void x2ap_eNB_handle_sctp_association_resp(instance_t instance, sctp_new_association_resp_t *sctp_new_association_resp) {
   x2ap_eNB_instance_t *instance_p;
   x2ap_eNB_data_t *x2ap_enb_data_p;
-
   DevAssert(sctp_new_association_resp != NULL);
-
-printf("x2ap_eNB_handle_sctp_association_resp at 1\n");
-dump_trees();
-
+  printf("x2ap_eNB_handle_sctp_association_resp at 1\n");
+  dump_trees();
   instance_p = x2ap_eNB_get_instance(instance);
   DevAssert(instance_p != NULL);
 
@@ -99,13 +104,15 @@ dump_trees();
    */
   if (sctp_new_association_resp->assoc_id != -1) {
     x2ap_enb_data_p = x2ap_get_eNB(instance_p, sctp_new_association_resp->assoc_id,
-                                       sctp_new_association_resp->ulp_cnx_id);
+                                   sctp_new_association_resp->ulp_cnx_id);
+
     if (x2ap_enb_data_p != NULL) {
       /* some sanity check - to be refined at some point */
       if (sctp_new_association_resp->sctp_state != SCTP_STATE_ESTABLISHED) {
         X2AP_ERROR("x2ap_enb_data_p not NULL and sctp state not SCTP_STATE_ESTABLISHED, what to do?\n");
         abort();
       }
+
       x2ap_enb_data_p->in_streams  = sctp_new_association_resp->in_streams;
       x2ap_enb_data_p->out_streams = sctp_new_association_resp->out_streams;
       return;
@@ -113,70 +120,60 @@ dump_trees();
   }
 
   x2ap_enb_data_p = x2ap_get_eNB(instance_p, -1,
-                                     sctp_new_association_resp->ulp_cnx_id);
+                                 sctp_new_association_resp->ulp_cnx_id);
   DevAssert(x2ap_enb_data_p != NULL);
-
-printf("x2ap_eNB_handle_sctp_association_resp at 2\n");
-dump_trees();
+  printf("x2ap_eNB_handle_sctp_association_resp at 2\n");
+  dump_trees();
 
   if (sctp_new_association_resp->sctp_state != SCTP_STATE_ESTABLISHED) {
     X2AP_WARN("Received unsuccessful result for SCTP association (%u), instance %d, cnx_id %u\n",
               sctp_new_association_resp->sctp_state,
               instance,
               sctp_new_association_resp->ulp_cnx_id);
-
     x2ap_handle_x2_setup_message(x2ap_enb_data_p,
-				 sctp_new_association_resp->sctp_state == SCTP_STATE_SHUTDOWN);
-
+                                 sctp_new_association_resp->sctp_state == SCTP_STATE_SHUTDOWN);
     return;
   }
 
-printf("x2ap_eNB_handle_sctp_association_resp at 3\n");
-dump_trees();
-
+  printf("x2ap_eNB_handle_sctp_association_resp at 3\n");
+  dump_trees();
   /* Update parameters */
   x2ap_enb_data_p->assoc_id    = sctp_new_association_resp->assoc_id;
   x2ap_enb_data_p->in_streams  = sctp_new_association_resp->in_streams;
   x2ap_enb_data_p->out_streams = sctp_new_association_resp->out_streams;
-
-printf("x2ap_eNB_handle_sctp_association_resp at 4\n");
-dump_trees();
-
+  printf("x2ap_eNB_handle_sctp_association_resp at 4\n");
+  dump_trees();
   /* Prepare new x2 Setup Request */
   x2ap_eNB_generate_x2_setup_request(instance_p, x2ap_enb_data_p);
 }
 
 static
-void x2ap_eNB_handle_sctp_association_ind(instance_t instance, sctp_new_association_ind_t *sctp_new_association_ind)
-{
+void x2ap_eNB_handle_sctp_association_ind(instance_t instance, sctp_new_association_ind_t *sctp_new_association_ind) {
   x2ap_eNB_instance_t *instance_p;
   x2ap_eNB_data_t *x2ap_enb_data_p;
-
-printf("x2ap_eNB_handle_sctp_association_ind at 1 (called for instance %d)\n", instance);
-dump_trees();
+  printf("x2ap_eNB_handle_sctp_association_ind at 1 (called for instance %d)\n", instance);
+  dump_trees();
   DevAssert(sctp_new_association_ind != NULL);
-
   instance_p = x2ap_eNB_get_instance(instance);
   DevAssert(instance_p != NULL);
-
   x2ap_enb_data_p = x2ap_get_eNB(instance_p, sctp_new_association_ind->assoc_id, -1);
+
   if (x2ap_enb_data_p != NULL) abort();
-//  DevAssert(x2ap_enb_data_p != NULL);
+
+  //  DevAssert(x2ap_enb_data_p != NULL);
   if (x2ap_enb_data_p == NULL) {
     /* Create new eNB descriptor */
     x2ap_enb_data_p = calloc(1, sizeof(*x2ap_enb_data_p));
     DevAssert(x2ap_enb_data_p != NULL);
-
     x2ap_enb_data_p->cnx_id                = x2ap_eNB_fetch_add_global_cnx_id();
-
     x2ap_enb_data_p->x2ap_eNB_instance = instance_p;
-
     /* Insert the new descriptor in list of known eNB
      * but not yet associated.
      */
     RB_INSERT(x2ap_enb_map, &instance_p->x2ap_enb_head, x2ap_enb_data_p);
     x2ap_enb_data_p->state = X2AP_ENB_STATE_CONNECTED;
     instance_p->x2_target_enb_nb++;
+
     if (instance_p->x2_target_enb_pending_nb > 0) {
       instance_p->x2_target_enb_pending_nb--;
     }
@@ -184,37 +181,31 @@ dump_trees();
     X2AP_WARN("x2ap_enb_data_p already exists\n");
   }
 
-printf("x2ap_eNB_handle_sctp_association_ind at 2\n");
-dump_trees();
+  printf("x2ap_eNB_handle_sctp_association_ind at 2\n");
+  dump_trees();
   /* Update parameters */
   x2ap_enb_data_p->assoc_id    = sctp_new_association_ind->assoc_id;
   x2ap_enb_data_p->in_streams  = sctp_new_association_ind->in_streams;
   x2ap_enb_data_p->out_streams = sctp_new_association_ind->out_streams;
-
-printf("x2ap_eNB_handle_sctp_association_ind at 3\n");
-dump_trees();
+  printf("x2ap_eNB_handle_sctp_association_ind at 3\n");
+  dump_trees();
 }
 
 int x2ap_eNB_init_sctp (x2ap_eNB_instance_t *instance_p,
-			net_ip_address_t    *local_ip_addr,
-			uint32_t enb_port_for_X2C)
-{
+                        net_ip_address_t    *local_ip_addr,
+                        uint32_t enb_port_for_X2C) {
   // Create and alloc new message
   MessageDef                             *message;
   sctp_init_t                            *sctp_init  = NULL;
-
   DevAssert(instance_p != NULL);
   DevAssert(local_ip_addr != NULL);
-
   message = itti_alloc_new_message (TASK_X2AP, SCTP_INIT_MSG_MULTI_REQ);
   sctp_init = &message->ittiMsg.sctp_init_multi;
-
   sctp_init->port = enb_port_for_X2C;
   sctp_init->ppid = X2AP_SCTP_PPID;
   sctp_init->ipv4 = 1;
   sctp_init->ipv6 = 0;
   sctp_init->nb_ipv4_addr = 1;
-
 #if 0
   memcpy(&sctp_init->ipv4_address,
          local_ip_addr,
@@ -227,9 +218,7 @@ int x2ap_eNB_init_sctp (x2ap_eNB_instance_t *instance_p,
    */
   sctp_init->nb_ipv6_addr = 0;
   sctp_init->ipv6_address[0] = "0:0:0:0:0:0:0:1";
-
   return itti_send_msg_to_task (TASK_SCTP, instance_p->instance, message);
-
 }
 
 static void x2ap_eNB_register_eNB(x2ap_eNB_instance_t *instance_p,
@@ -237,47 +226,33 @@ static void x2ap_eNB_register_eNB(x2ap_eNB_instance_t *instance_p,
                                   net_ip_address_t    *local_ip_addr,
                                   uint16_t             in_streams,
                                   uint16_t             out_streams,
-				  uint32_t	       enb_port_for_X2C,
-                                  int                  multi_sd)
-{
-
+                                  uint32_t         enb_port_for_X2C,
+                                  int                  multi_sd) {
   MessageDef                       *message                   = NULL;
   sctp_new_association_req_multi_t *sctp_new_association_req  = NULL;
   x2ap_eNB_data_t                  *x2ap_enb_data             = NULL;
-
   DevAssert(instance_p != NULL);
   DevAssert(target_eNB_ip_address != NULL);
-
   message = itti_alloc_new_message(TASK_X2AP, SCTP_NEW_ASSOCIATION_REQ_MULTI);
-
   sctp_new_association_req = &message->ittiMsg.sctp_new_association_req_multi;
-
   sctp_new_association_req->port = enb_port_for_X2C;
   sctp_new_association_req->ppid = X2AP_SCTP_PPID;
-
   sctp_new_association_req->in_streams  = in_streams;
   sctp_new_association_req->out_streams = out_streams;
-
   sctp_new_association_req->multi_sd = multi_sd;
-
   memcpy(&sctp_new_association_req->remote_address,
          target_eNB_ip_address,
          sizeof(*target_eNB_ip_address));
-
   memcpy(&sctp_new_association_req->local_address,
          local_ip_addr,
          sizeof(*local_ip_addr));
-
   /* Create new eNB descriptor */
   x2ap_enb_data = calloc(1, sizeof(*x2ap_enb_data));
   DevAssert(x2ap_enb_data != NULL);
-
   x2ap_enb_data->cnx_id                = x2ap_eNB_fetch_add_global_cnx_id();
   sctp_new_association_req->ulp_cnx_id = x2ap_enb_data->cnx_id;
-
   x2ap_enb_data->assoc_id          = -1;
   x2ap_enb_data->x2ap_eNB_instance = instance_p;
-
   /* Insert the new descriptor in list of known eNB
    * but not yet associated.
    */
@@ -285,18 +260,14 @@ static void x2ap_eNB_register_eNB(x2ap_eNB_instance_t *instance_p,
   x2ap_enb_data->state = X2AP_ENB_STATE_WAITING;
   instance_p->x2_target_enb_nb ++;
   instance_p->x2_target_enb_pending_nb ++;
-
   itti_send_msg_to_task(TASK_SCTP, instance_p->instance, message);
 }
 
 static
 void x2ap_eNB_handle_register_eNB(instance_t instance,
-				  x2ap_register_enb_req_t *x2ap_register_eNB)
-{
+                                  x2ap_register_enb_req_t *x2ap_register_eNB) {
   x2ap_eNB_instance_t *new_instance;
-
   DevAssert(x2ap_register_eNB != NULL);
-
   /* Look if the provided instance already exists */
   new_instance = x2ap_eNB_get_instance(instance);
 
@@ -308,13 +279,10 @@ void x2ap_eNB_handle_register_eNB(instance_t instance,
     DevCheck(new_instance->mcc == x2ap_register_eNB->mcc, new_instance->mcc, x2ap_register_eNB->mcc, 0);
     DevCheck(new_instance->mnc == x2ap_register_eNB->mnc, new_instance->mnc, x2ap_register_eNB->mnc, 0);
     X2AP_WARN("eNB[%d] already registered\n", instance);
-  }
-  else {
+  } else {
     new_instance = calloc(1, sizeof(x2ap_eNB_instance_t));
     DevAssert(new_instance != NULL);
-
     RB_INIT(&new_instance->x2ap_enb_head);
-
     /* Copy usefull parameters */
     new_instance->instance         = instance;
     new_instance->eNB_name         = x2ap_register_eNB->eNB_name;
@@ -324,10 +292,9 @@ void x2ap_eNB_handle_register_eNB(instance_t instance,
     new_instance->mcc              = x2ap_register_eNB->mcc;
     new_instance->mnc              = x2ap_register_eNB->mnc;
     new_instance->mnc_digit_length = x2ap_register_eNB->mnc_digit_length;
-
     new_instance->num_cc           = x2ap_register_eNB->num_cc;
 
-    for (int i = 0; i< x2ap_register_eNB->num_cc; i++){
+    for (int i = 0; i< x2ap_register_eNB->num_cc; i++) {
       new_instance->eutra_band[i]              = x2ap_register_eNB->eutra_band[i];
       new_instance->downlink_frequency[i]      = x2ap_register_eNB->downlink_frequency[i];
       new_instance->uplink_frequency_offset[i] = x2ap_register_eNB->uplink_frequency_offset[i];
@@ -343,44 +310,40 @@ void x2ap_eNB_handle_register_eNB(instance_t instance,
     memcpy(new_instance->target_enb_x2_ip_address,
            x2ap_register_eNB->target_enb_x2_ip_address,
            x2ap_register_eNB->nb_x2 * sizeof(net_ip_address_t));
-
     new_instance->nb_x2             = x2ap_register_eNB->nb_x2;
     new_instance->enb_x2_ip_address = x2ap_register_eNB->enb_x2_ip_address;
     new_instance->sctp_in_streams   = x2ap_register_eNB->sctp_in_streams;
     new_instance->sctp_out_streams  = x2ap_register_eNB->sctp_out_streams;
     new_instance->enb_port_for_X2C  = x2ap_register_eNB->enb_port_for_X2C;
-
     /* Add the new instance to the list of eNB (meaningfull in virtual mode) */
     x2ap_eNB_insert_new_instance(new_instance);
-
     X2AP_INFO("Registered new eNB[%d] and %s eNB id %u\n",
-               instance,
-               x2ap_register_eNB->cell_type == CELL_MACRO_ENB ? "macro" : "home",
-               x2ap_register_eNB->eNB_id);
+              instance,
+              x2ap_register_eNB->cell_type == CELL_MACRO_ENB ? "macro" : "home",
+              x2ap_register_eNB->eNB_id);
+
     /* initiate the SCTP listener */
     if (x2ap_eNB_init_sctp(new_instance,&x2ap_register_eNB->enb_x2_ip_address,x2ap_register_eNB->enb_port_for_X2C) <  0 ) {
-          X2AP_ERROR ("Error while sending SCTP_INIT_MSG to SCTP \n");
-          return;
+      X2AP_ERROR ("Error while sending SCTP_INIT_MSG to SCTP \n");
+      return;
     }
-      X2AP_INFO("eNB[%d] eNB id %u acting as a listner (server)\n",
-                instance, x2ap_register_eNB->eNB_id);
+
+    X2AP_INFO("eNB[%d] eNB id %u acting as a listner (server)\n",
+              instance, x2ap_register_eNB->eNB_id);
   }
 }
 
 static
 void x2ap_eNB_handle_sctp_init_msg_multi_cnf(
-        instance_t instance_id,
-        sctp_init_msg_multi_cnf_t *m)
-{
+  instance_t instance_id,
+  sctp_init_msg_multi_cnf_t *m) {
   x2ap_eNB_instance_t *instance;
   int index;
-
   DevAssert(m != NULL);
-
   instance = x2ap_eNB_get_instance(instance_id);
   DevAssert(instance != NULL);
-
   instance->multi_sd = m->multi_sd;
+
   /* Exit if CNF message reports failure.
    * Failure means multi_sd < 0.
    */
@@ -392,72 +355,133 @@ void x2ap_eNB_handle_sctp_init_msg_multi_cnf(
   /* Trying to connect to the provided list of eNB ip address */
 
   for (index = 0; index < instance->nb_x2; index++) {
-
-      X2AP_INFO("eNB[%d] eNB id %u acting as an initiator (client)\n",
-                instance_id, instance->eNB_id);
-      x2ap_eNB_register_eNB(instance,
-                            &instance->target_enb_x2_ip_address[index],
-                            &instance->enb_x2_ip_address,
-                            instance->sctp_in_streams,
-                            instance->sctp_out_streams,
-                            instance->enb_port_for_X2C,
-                            instance->multi_sd);
+    X2AP_INFO("eNB[%d] eNB id %u acting as an initiator (client)\n",
+              instance_id, instance->eNB_id);
+    x2ap_eNB_register_eNB(instance,
+                          &instance->target_enb_x2_ip_address[index],
+                          &instance->enb_x2_ip_address,
+                          instance->sctp_in_streams,
+                          instance->sctp_out_streams,
+                          instance->enb_port_for_X2C,
+                          instance->multi_sd);
   }
 }
 
-void *x2ap_task(void *arg)
+static
+void x2ap_eNB_handle_handover_req(instance_t instance,
+                                  x2ap_handover_req_t *x2ap_handover_req)
 {
+  /* TODO: remove this hack (the goal is to find the correct
+   * eNodeB structure for the target) - we need a proper way for RRC
+   * and X2AP to identify eNodeBs
+   * RRC knows about mod_id and X2AP knows about eNB_id (eNB_ID in
+   * the configuration file)
+   * as far as I understand.. CROUX
+   */
+  x2ap_eNB_instance_t *instance_p;
+  x2ap_eNB_data_t     *target;
+
+  int target_enb_id = x2ap_handover_req->target_physCellId;
+
+  instance_p = x2ap_eNB_pci_get_instance(target_enb_id);
+  DevAssert(instance_p != NULL);
+
+  //instance_p = x2ap_eNB_get_instance(instance);
+  //DevAssert(instance_p != NULL);
+
+  target = x2ap_is_eNB_id_in_list(instance_p->eNB_id);
+  DevAssert(target != NULL);
+
+  /* store rnti at index 0 */
+  //x2id_to_source_rnti[0] = x2ap_handover_req->source_rnti;
+  x2ap_eNB_generate_x2_handover_request(target, x2ap_handover_req);
+}
+
+static
+void x2ap_eNB_handle_handover_req_ack(instance_t instance,
+                                      x2ap_handover_req_ack_t *x2ap_handover_req_ack)
+{
+  /* TODO: remove this hack (the goal is to find the correct
+   * eNodeB structure for the other end) - we need a proper way for RRC
+   * and X2AP to identify eNodeBs
+   * RRC knows about mod_id and X2AP knows about eNB_id (eNB_ID in
+   * the configuration file)
+   * as far as I understand.. CROUX
+   */
+  x2ap_eNB_instance_t *instance_p;
+  x2ap_eNB_data_t     *target;
+  int target_enb_id = x2ap_handover_req_ack->target_mod_id;
+
+  instance_p = x2ap_eNB_get_instance(instance);
+  DevAssert(instance_p != NULL);
+
+  target = x2ap_is_eNB_id_in_list(target_enb_id);
+  DevAssert(target != NULL);
+
+  x2ap_eNB_generate_x2_handover_request_ack(target, x2ap_handover_req_ack);
+  //x2ap_eNB_generate_x2_handover_req_ack(instance_p, target, x2ap_handover_req_ack->source_x2id,
+          //x2ap_handover_req_ack->rrc_buffer, x2ap_handover_req_ack->rrc_buffer_size);
+}
+
+void *x2ap_task(void *arg) {
   MessageDef *received_msg = NULL;
   int         result;
-
   X2AP_DEBUG("Starting X2AP layer\n");
-
   x2ap_eNB_prepare_internal_data();
-
   itti_mark_task_ready(TASK_X2AP);
 
   while (1) {
     itti_receive_msg(TASK_X2AP, &received_msg);
+
     switch (ITTI_MSG_ID(received_msg)) {
-    case TERMINATE_MESSAGE:
-      X2AP_WARN(" *** Exiting X2AP thread\n");
-      itti_exit_task();
-      break;
-
-    case X2AP_REGISTER_ENB_REQ:
-      x2ap_eNB_handle_register_eNB(ITTI_MESSAGE_GET_INSTANCE(received_msg),
-                                   &X2AP_REGISTER_ENB_REQ(received_msg));
-      break;
-
-    case SCTP_INIT_MSG_MULTI_CNF:
-      x2ap_eNB_handle_sctp_init_msg_multi_cnf(ITTI_MESSAGE_GET_INSTANCE(received_msg),
-                                              &received_msg->ittiMsg.sctp_init_msg_multi_cnf);
-      break;
-
-    case SCTP_NEW_ASSOCIATION_RESP:
-      x2ap_eNB_handle_sctp_association_resp(ITTI_MESSAGE_GET_INSTANCE(received_msg),
-					    &received_msg->ittiMsg.sctp_new_association_resp);
-      break;
-
-    case SCTP_NEW_ASSOCIATION_IND:
-      x2ap_eNB_handle_sctp_association_ind(ITTI_MESSAGE_GET_INSTANCE(received_msg),
-					   &received_msg->ittiMsg.sctp_new_association_ind);
-      break;
-
-    case SCTP_DATA_IND:
-      x2ap_eNB_handle_sctp_data_ind(ITTI_MESSAGE_GET_INSTANCE(received_msg),
-                                           &received_msg->ittiMsg.sctp_data_ind);
-      break;
-
-    default:
-      X2AP_ERROR("Received unhandled message: %d:%s\n",
-                 ITTI_MSG_ID(received_msg), ITTI_MSG_NAME(received_msg));
-      break;
+      case TERMINATE_MESSAGE:
+        X2AP_WARN(" *** Exiting X2AP thread\n");
+        itti_exit_task();
+        break;
+
+      case X2AP_REGISTER_ENB_REQ:
+        x2ap_eNB_handle_register_eNB(ITTI_MESSAGE_GET_INSTANCE(received_msg),
+                                     &X2AP_REGISTER_ENB_REQ(received_msg));
+        break;
+
+      case X2AP_HANDOVER_REQ:
+        x2ap_eNB_handle_handover_req(ITTI_MESSAGE_GET_INSTANCE(received_msg),
+                                     &X2AP_HANDOVER_REQ(received_msg));
+        break;
+
+      case X2AP_HANDOVER_REQ_ACK:
+        x2ap_eNB_handle_handover_req_ack(ITTI_MESSAGE_GET_INSTANCE(received_msg),
+                                         &X2AP_HANDOVER_REQ_ACK(received_msg));
+        break;
+
+      case SCTP_INIT_MSG_MULTI_CNF:
+        x2ap_eNB_handle_sctp_init_msg_multi_cnf(ITTI_MESSAGE_GET_INSTANCE(received_msg),
+                                                &received_msg->ittiMsg.sctp_init_msg_multi_cnf);
+        break;
+
+      case SCTP_NEW_ASSOCIATION_RESP:
+        x2ap_eNB_handle_sctp_association_resp(ITTI_MESSAGE_GET_INSTANCE(received_msg),
+                                              &received_msg->ittiMsg.sctp_new_association_resp);
+        break;
+
+      case SCTP_NEW_ASSOCIATION_IND:
+        x2ap_eNB_handle_sctp_association_ind(ITTI_MESSAGE_GET_INSTANCE(received_msg),
+                                             &received_msg->ittiMsg.sctp_new_association_ind);
+        break;
+
+      case SCTP_DATA_IND:
+        x2ap_eNB_handle_sctp_data_ind(ITTI_MESSAGE_GET_INSTANCE(received_msg),
+                                      &received_msg->ittiMsg.sctp_data_ind);
+        break;
+
+      default:
+        X2AP_ERROR("Received unhandled message: %d:%s\n",
+                   ITTI_MSG_ID(received_msg), ITTI_MSG_NAME(received_msg));
+        break;
     }
 
     result = itti_free (ITTI_MSG_ORIGIN_ID(received_msg), received_msg);
     AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
-
     received_msg = NULL;
   }
 
diff --git a/openair2/X2AP/x2ap_eNB.h b/openair2/X2AP/x2ap_eNB.h
index 1a19416122d0918fa20896b6f580c858758db90e..5433a890883c94d750594fd4a99e848ef449c343 100644
--- a/openair2/X2AP/x2ap_eNB.h
+++ b/openair2/X2AP/x2ap_eNB.h
@@ -19,6 +19,13 @@
  *      contact@openairinterface.org
  */
 
+/*! \file x2ap_eNB.h
+ * \brief x2ap tasks for eNB
+ * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr>
+ * \date 2018
+ * \version 1.0
+ */
+
 #include <stdio.h>
 #include <stdint.h>
 
diff --git a/openair2/X2AP/x2ap_eNB_decoder.c b/openair2/X2AP/x2ap_eNB_decoder.c
index f156d96d175beab05523d01625cd34324bc1e1a5..553cf8e559c1d38b3969e33a2e21384c6401a326 100644
--- a/openair2/X2AP/x2ap_eNB_decoder.c
+++ b/openair2/X2AP/x2ap_eNB_decoder.c
@@ -19,6 +19,13 @@
  *      contact@openairinterface.org
  */
 
+/*! \file x2ap_eNB_decoder.c
+ * \brief x2ap decoder procedures for eNB
+ * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr>
+ * \date 2018
+ * \version 1.0
+ */
+
 #include <stdio.h>
 
 #include "assertions.h"
@@ -33,7 +40,12 @@ static int x2ap_eNB_decode_initiating_message(X2AP_X2AP_PDU_t *pdu)
   switch(pdu->choice.initiatingMessage.procedureCode) {
 
     case X2AP_ProcedureCode_id_x2Setup:
-      asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_X2AP_X2AP_PDU, 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_handoverPreparation:
+      //asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_X2AP_X2AP_PDU, pdu);
       X2AP_INFO("x2ap_eNB_decode_initiating_message!\n");
       break;
 
@@ -54,7 +66,12 @@ static int x2ap_eNB_decode_successful_outcome(X2AP_X2AP_PDU_t *pdu)
 
   switch(pdu->choice.successfulOutcome.procedureCode) {
     case X2AP_ProcedureCode_id_x2Setup:
-      asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_X2AP_X2AP_PDU, pdu);
+      //asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_X2AP_X2AP_PDU, pdu);
+      X2AP_INFO("x2ap_eNB_decode_successfuloutcome_message!\n");
+      break;
+
+    case X2AP_ProcedureCode_id_handoverPreparation:
+      //asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_X2AP_X2AP_PDU, pdu);
       X2AP_INFO("x2ap_eNB_decode_successfuloutcome_message!\n");
       break;
 
@@ -73,7 +90,7 @@ static int x2ap_eNB_decode_unsuccessful_outcome(X2AP_X2AP_PDU_t *pdu)
 
   switch(pdu->choice.unsuccessfulOutcome.procedureCode) {
     case X2AP_ProcedureCode_id_x2Setup:
-      asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_X2AP_X2AP_PDU, pdu);
+      //asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_X2AP_X2AP_PDU, pdu);
       X2AP_INFO("x2ap_eNB_decode_unsuccessfuloutcome_message!\n");
       break;
 
@@ -99,8 +116,9 @@ int x2ap_eNB_decode_pdu(X2AP_X2AP_PDU_t *pdu, const uint8_t *const buffer, uint3
                         length,
                         0,
                         0);
-
-  xer_fprint(stdout, &asn_DEF_X2AP_X2AP_PDU, pdu);
+  if (asn1_xer_print) {
+    xer_fprint(stdout, &asn_DEF_X2AP_X2AP_PDU, pdu);
+  }
 
   if (dec_ret.code != RC_OK) {
     X2AP_ERROR("Failed to decode pdu\n");
diff --git a/openair2/X2AP/x2ap_eNB_decoder.h b/openair2/X2AP/x2ap_eNB_decoder.h
index 9527225856b2f67415a7fe895720cf782072b2ca..e3fa8b44e88ad15393ea103b687efec6be5d7f32 100644
--- a/openair2/X2AP/x2ap_eNB_decoder.h
+++ b/openair2/X2AP/x2ap_eNB_decoder.h
@@ -19,6 +19,13 @@
  *      contact@openairinterface.org
  */
 
+/*! \file x2ap_eNB_decoder.h
+ * \brief x2ap decoder procedures for eNB
+ * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr>
+ * \date 2018
+ * \version 1.0
+ */
+
 #ifndef X2AP_ENB_DECODER_H_
 #define X2AP_ENB_DECODER_H_
 
diff --git a/openair2/X2AP/x2ap_eNB_defs.h b/openair2/X2AP/x2ap_eNB_defs.h
index b3736b1c6b3492a18f2a96641836346ec6de5c52..b3b95b8dd77a5549f8fda4f4c14e14d8d3534f91 100644
--- a/openair2/X2AP/x2ap_eNB_defs.h
+++ b/openair2/X2AP/x2ap_eNB_defs.h
@@ -19,6 +19,13 @@
  *      contact@openairinterface.org
  */
 
+/*! \file x2ap_eNB_defs.h
+ * \brief x2ap struct definitions for eNB
+ * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr>
+ * \date 2018
+ * \version 1.0
+ */
+
 #include <stdint.h>
 
 #include "queue.h"
@@ -156,6 +163,7 @@ typedef struct x2ap_eNB_instance_s {
   uint32_t                downlink_frequency[MAX_NUM_CCs];
   int32_t                 uplink_frequency_offset[MAX_NUM_CCs];
   uint32_t                Nid_cell[MAX_NUM_CCs];
+  uint32_t                Nid_target_cell[MAX_NUM_CCs];
   int16_t                 N_RB_DL[MAX_NUM_CCs];
   lte_frame_type_t        frame_type[MAX_NUM_CCs];
   uint32_t                fdd_earfcn_DL[MAX_NUM_CCs];
diff --git a/openair2/X2AP/x2ap_eNB_encoder.c b/openair2/X2AP/x2ap_eNB_encoder.c
index 1eb617a7f1ddec817a88648fe25ddbef2ac9ad7c..8b1c030d35d0b14d588475cf317d450f2fa3e686 100644
--- a/openair2/X2AP/x2ap_eNB_encoder.c
+++ b/openair2/X2AP/x2ap_eNB_encoder.c
@@ -19,6 +19,13 @@
  *      contact@openairinterface.org
  */
 
+/*! \file x2ap_eNB_encoder.c
+ * \brief x2ap encoder procedures for eNB
+ * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr>
+ * \date 2018
+ * \version 1.0
+ */
+
 #include <stdio.h>
 #include <string.h>
 #include <stdint.h>
diff --git a/openair2/X2AP/x2ap_eNB_encoder.h b/openair2/X2AP/x2ap_eNB_encoder.h
index 04c77583b4f27c05fcc723100784bf418bf26c3a..f451a3fb2626e6119b7a0158d4f4394a8f0cb9d1 100644
--- a/openair2/X2AP/x2ap_eNB_encoder.h
+++ b/openair2/X2AP/x2ap_eNB_encoder.h
@@ -19,6 +19,13 @@
  *      contact@openairinterface.org
  */
 
+/*! \file x2ap_eNB_encoder.h
+ * \brief x2ap encoder procedures for eNB
+ * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr>
+ * \date 2018
+ * \version 1.0
+ */
+
 #ifndef X2AP_ENB_ENCODER_H_
 #define X2AP_ENB_ENCODER_H_
 
diff --git a/openair2/X2AP/x2ap_eNB_generate_messages.c b/openair2/X2AP/x2ap_eNB_generate_messages.c
index 9c5a281506730409d8cf9b7048e4d68b90e826a7..b9a2dae04ce18069c79dbad880ba19fe1f2ffaf1 100644
--- a/openair2/X2AP/x2ap_eNB_generate_messages.c
+++ b/openair2/X2AP/x2ap_eNB_generate_messages.c
@@ -19,12 +19,22 @@
  *      contact@openairinterface.org
  */
 
+/*! \file x2ap_eNB_generate_messages.c
+ * \brief x2ap procedures for eNB
+ * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr>
+ * \date 2018
+ * \version 1.0
+ */
+
 #include "intertask_interface.h"
 
+#include "X2AP_LastVisitedCell-Item.h"
+
 #include "x2ap_common.h"
 #include "x2ap_eNB.h"
 #include "x2ap_eNB_generate_messages.h"
 #include "x2ap_eNB_encoder.h"
+#include "x2ap_eNB_decoder.h"
 
 #include "x2ap_eNB_itti_messaging.h"
 
@@ -403,3 +413,314 @@ int x2ap_eNB_set_cause (X2AP_Cause_t * cause_p,
 
   return 0;
 }
+
+int x2ap_eNB_generate_x2_handover_request (x2ap_eNB_data_t *x2ap_eNB_data_p,
+                                           x2ap_handover_req_t *x2ap_handover_req)
+{
+
+  X2AP_X2AP_PDU_t                     pdu;
+  X2AP_HandoverRequest_t              *out;
+  X2AP_HandoverRequest_IEs_t          *ie;
+  X2AP_E_RABs_ToBeSetup_ItemIEs_t     *e_RABS_ToBeSetup_ItemIEs;
+  X2AP_E_RABs_ToBeSetup_Item_t        *e_RABs_ToBeSetup_Item;
+  X2AP_LastVisitedCell_Item_t         *lastVisitedCell_Item;
+
+  x2ap_eNB_instance_t                 *instance_p;
+
+  uint8_t  *buffer;
+  uint32_t  len;
+  int       ret = 0;
+
+  DevAssert(x2ap_eNB_data_p != NULL);
+
+  /* get the eNB instance */
+  instance_p = x2ap_eNB_data_p->x2ap_eNB_instance;
+
+  DevAssert(instance_p != NULL);
+
+
+  /* Prepare the X2AP handover message to encode */
+  memset(&pdu, 0, sizeof(pdu));
+  pdu.present = X2AP_X2AP_PDU_PR_initiatingMessage;
+  pdu.choice.initiatingMessage.procedureCode = X2AP_ProcedureCode_id_handoverPreparation;
+  pdu.choice.initiatingMessage.criticality = X2AP_Criticality_reject;
+  pdu.choice.initiatingMessage.value.present = X2AP_InitiatingMessage__value_PR_HandoverRequest;
+  out = &pdu.choice.initiatingMessage.value.choice.HandoverRequest;
+
+  /* mandatory */
+  ie = (X2AP_HandoverRequest_IEs_t *)calloc(1, sizeof(X2AP_HandoverRequest_IEs_t));
+  ie->id = X2AP_ProtocolIE_ID_id_Old_eNB_UE_X2AP_ID;
+  ie->criticality = X2AP_Criticality_reject;
+  ie->value.present = X2AP_HandoverRequest_IEs__value_PR_UE_X2AP_ID;
+  ie->value.choice.UE_X2AP_ID = x2ap_handover_req->old_eNB_ue_x2ap_id;
+  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+
+  /* mandatory */
+  ie = (X2AP_HandoverRequest_IEs_t *)calloc(1, sizeof(X2AP_HandoverRequest_IEs_t));
+  ie->id = X2AP_ProtocolIE_ID_id_Cause;
+  ie->criticality = X2AP_Criticality_ignore;
+  ie->value.present = X2AP_HandoverRequest_IEs__value_PR_Cause;
+  ie->value.choice.Cause.present = X2AP_Cause_PR_radioNetwork;
+  ie->value.choice.Cause.choice.radioNetwork = X2AP_CauseRadioNetwork_handover_desirable_for_radio_reasons;
+  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+
+  /* mandatory */
+  ie = (X2AP_HandoverRequest_IEs_t *)calloc(1, sizeof(X2AP_HandoverRequest_IEs_t));
+  ie->id = X2AP_ProtocolIE_ID_id_TargetCell_ID;
+  ie->criticality = X2AP_Criticality_reject;
+  ie->value.present = X2AP_HandoverRequest_IEs__value_PR_ECGI;
+  MCC_MNC_TO_PLMNID(instance_p->mcc, instance_p->mnc, instance_p->mnc_digit_length,
+                       &ie->value.choice.ECGI.pLMN_Identity);
+  MACRO_ENB_ID_TO_CELL_IDENTITY(instance_p->eNB_id, 0, &ie->value.choice.ECGI.eUTRANcellIdentifier);
+  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+
+  /* mandatory */
+  ie = (X2AP_HandoverRequest_IEs_t *)calloc(1, sizeof(X2AP_HandoverRequest_IEs_t));
+  ie->id = X2AP_ProtocolIE_ID_id_GUMMEI_ID;
+  ie->criticality = X2AP_Criticality_reject;
+  ie->value.present = X2AP_HandoverRequest_IEs__value_PR_GUMMEI;
+  MCC_MNC_TO_PLMNID(instance_p->mcc, instance_p->mnc, instance_p->mnc_digit_length,
+                       &ie->value.choice.GUMMEI.gU_Group_ID.pLMN_Identity);
+  //@TODO: consider to update these values
+  INT16_TO_OCTET_STRING(x2ap_handover_req->ue_gummei.mme_group_id, &ie->value.choice.GUMMEI.gU_Group_ID.mME_Group_ID);
+  MME_CODE_TO_OCTET_STRING(x2ap_handover_req->ue_gummei.mme_code, &ie->value.choice.GUMMEI.mME_Code);
+  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+
+  /* mandatory */
+  ie = (X2AP_HandoverRequest_IEs_t *)calloc(1, sizeof(X2AP_HandoverRequest_IEs_t));
+  ie->id = X2AP_ProtocolIE_ID_id_UE_ContextInformation;
+  ie->criticality = X2AP_Criticality_reject;
+  ie->value.present = X2AP_HandoverRequest_IEs__value_PR_UE_ContextInformation;
+  //@TODO: consider to update this value
+  ie->value.choice.UE_ContextInformation.mME_UE_S1AP_ID = x2ap_handover_req->mme_ue_s1ap_id;
+
+  KENB_STAR_TO_BIT_STRING(x2ap_handover_req->kenb,&ie->value.choice.UE_ContextInformation.aS_SecurityInformation.key_eNodeB_star);
+
+  if (x2ap_handover_req->kenb_ncc >=0) { // Check this condition
+    ie->value.choice.UE_ContextInformation.aS_SecurityInformation.nextHopChainingCount = x2ap_handover_req->kenb_ncc;
+  }
+  else {
+    ie->value.choice.UE_ContextInformation.aS_SecurityInformation.nextHopChainingCount = 1;
+  }
+
+  ENCRALG_TO_BIT_STRING(x2ap_handover_req->security_capabilities.encryption_algorithms,
+              &ie->value.choice.UE_ContextInformation.uESecurityCapabilities.encryptionAlgorithms);
+
+  INTPROTALG_TO_BIT_STRING(x2ap_handover_req->security_capabilities.integrity_algorithms,
+              &ie->value.choice.UE_ContextInformation.uESecurityCapabilities.integrityProtectionAlgorithms);
+
+  //@TODO: update with proper UEAMPR
+  UEAGMAXBITRTD_TO_ASN_PRIMITIVES(3L,&ie->value.choice.UE_ContextInformation.uEaggregateMaximumBitRate.uEaggregateMaximumBitRateDownlink);
+  UEAGMAXBITRTU_TO_ASN_PRIMITIVES(6L,&ie->value.choice.UE_ContextInformation.uEaggregateMaximumBitRate.uEaggregateMaximumBitRateUplink);
+  {
+    for (int i=0;i<x2ap_handover_req->nb_e_rabs_tobesetup;i++) {
+      e_RABS_ToBeSetup_ItemIEs = (X2AP_E_RABs_ToBeSetup_ItemIEs_t *)calloc(1,sizeof(X2AP_E_RABs_ToBeSetup_ItemIEs_t));
+      e_RABS_ToBeSetup_ItemIEs->id = X2AP_ProtocolIE_ID_id_E_RABs_ToBeSetup_Item;
+      e_RABS_ToBeSetup_ItemIEs->criticality = X2AP_Criticality_ignore;
+      e_RABS_ToBeSetup_ItemIEs->value.present = X2AP_E_RABs_ToBeSetup_ItemIEs__value_PR_E_RABs_ToBeSetup_Item;
+      e_RABs_ToBeSetup_Item = &e_RABS_ToBeSetup_ItemIEs->value.choice.E_RABs_ToBeSetup_Item;
+      {
+        e_RABs_ToBeSetup_Item->e_RAB_ID = x2ap_handover_req->e_rabs_tobesetup[i].e_rab_id;
+        e_RABs_ToBeSetup_Item->e_RAB_Level_QoS_Parameters.qCI = x2ap_handover_req->e_rab_param[i].qos.qci;
+        e_RABs_ToBeSetup_Item->e_RAB_Level_QoS_Parameters.allocationAndRetentionPriority.priorityLevel = x2ap_handover_req->e_rab_param[i].qos.allocation_retention_priority.priority_level;
+        e_RABs_ToBeSetup_Item->e_RAB_Level_QoS_Parameters.allocationAndRetentionPriority.pre_emptionCapability = x2ap_handover_req->e_rab_param[i].qos.allocation_retention_priority.pre_emp_capability;
+        e_RABs_ToBeSetup_Item->e_RAB_Level_QoS_Parameters.allocationAndRetentionPriority.pre_emptionVulnerability = x2ap_handover_req->e_rab_param[i].qos.allocation_retention_priority.pre_emp_vulnerability;
+        e_RABs_ToBeSetup_Item->uL_GTPtunnelEndpoint.transportLayerAddress.size = (uint8_t)(x2ap_handover_req->e_rabs_tobesetup[i].eNB_addr.length/8);
+        e_RABs_ToBeSetup_Item->uL_GTPtunnelEndpoint.transportLayerAddress.bits_unused = x2ap_handover_req->e_rabs_tobesetup[i].eNB_addr.length%8;
+        e_RABs_ToBeSetup_Item->uL_GTPtunnelEndpoint.transportLayerAddress.buf =
+                        calloc(1,e_RABs_ToBeSetup_Item->uL_GTPtunnelEndpoint.transportLayerAddress.size);
+
+        memcpy (e_RABs_ToBeSetup_Item->uL_GTPtunnelEndpoint.transportLayerAddress.buf,
+                        x2ap_handover_req->e_rabs_tobesetup[i].eNB_addr.buffer,
+                        e_RABs_ToBeSetup_Item->uL_GTPtunnelEndpoint.transportLayerAddress.size);
+
+        INT32_TO_OCTET_STRING(x2ap_handover_req->e_rabs_tobesetup[i].gtp_teid,&e_RABs_ToBeSetup_Item->uL_GTPtunnelEndpoint.gTP_TEID);
+      }
+      ASN_SEQUENCE_ADD(&ie->value.choice.UE_ContextInformation.e_RABs_ToBeSetup_List.list, e_RABS_ToBeSetup_ItemIEs);
+    }
+  }
+
+  OCTET_STRING_fromBuf(&ie->value.choice.UE_ContextInformation.rRC_Context, (char*) x2ap_handover_req->rrc_buffer, x2ap_handover_req->rrc_buffer_size);
+
+  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+
+  /* mandatory */
+  ie = (X2AP_HandoverRequest_IEs_t *)calloc(1, sizeof(X2AP_HandoverRequest_IEs_t));
+  ie->id = X2AP_ProtocolIE_ID_id_UE_HistoryInformation;
+  ie->criticality = X2AP_Criticality_ignore;
+  ie->value.present = X2AP_HandoverRequest_IEs__value_PR_UE_HistoryInformation;
+  //@TODO: consider to update this value
+  {
+   lastVisitedCell_Item = (X2AP_LastVisitedCell_Item_t *)calloc(1, sizeof(X2AP_LastVisitedCell_Item_t));
+   lastVisitedCell_Item->present = X2AP_LastVisitedCell_Item_PR_e_UTRAN_Cell;
+   MCC_MNC_TO_PLMNID(instance_p->mcc, instance_p->mnc, instance_p->mnc_digit_length,
+                       &lastVisitedCell_Item->choice.e_UTRAN_Cell.global_Cell_ID.pLMN_Identity);
+   MACRO_ENB_ID_TO_CELL_IDENTITY(0, 0, &lastVisitedCell_Item->choice.e_UTRAN_Cell.global_Cell_ID.eUTRANcellIdentifier);
+   lastVisitedCell_Item->choice.e_UTRAN_Cell.cellType.cell_Size = X2AP_Cell_Size_small;
+   lastVisitedCell_Item->choice.e_UTRAN_Cell.time_UE_StayedInCell = 2;
+   ASN_SEQUENCE_ADD(&ie->value.choice.UE_HistoryInformation.list, lastVisitedCell_Item);
+  }
+
+  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+
+  if (x2ap_eNB_encode_pdu(&pdu, &buffer, &len) < 0) {
+    X2AP_ERROR("Failed to encode X2 handover request\n");
+    abort();
+    return -1;
+  }
+
+  MSC_LOG_TX_MESSAGE (MSC_X2AP_SRC_ENB, MSC_X2AP_TARGET_ENB, NULL, 0, "0 X2Handover/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;
+}
+
+int x2ap_eNB_generate_x2_handover_request_ack (x2ap_eNB_data_t *x2ap_eNB_data_p,
+                                               x2ap_handover_req_ack_t *x2ap_handover_req_ack)
+{
+
+  X2AP_X2AP_PDU_t                        pdu;
+  X2AP_HandoverRequestAcknowledge_t      *out;
+  X2AP_HandoverRequestAcknowledge_IEs_t  *ie;
+  X2AP_E_RABs_Admitted_ItemIEs_t         *e_RABS_Admitted_ItemIEs;
+  X2AP_E_RABs_Admitted_Item_t            *e_RABs_Admitted_Item;
+
+  x2ap_eNB_instance_t                 *instance_p;
+
+  uint8_t  *buffer;
+  uint32_t  len;
+  int       ret = 0;
+
+  DevAssert(x2ap_eNB_data_p != NULL);
+
+  /* get the eNB instance */
+  instance_p = x2ap_eNB_data_p->x2ap_eNB_instance;
+
+  DevAssert(instance_p != NULL);
+
+  /* Prepare the X2AP handover message to encode */
+  memset(&pdu, 0, sizeof(pdu));
+  pdu.present = X2AP_X2AP_PDU_PR_successfulOutcome;
+  pdu.choice.successfulOutcome.procedureCode = X2AP_ProcedureCode_id_handoverPreparation;
+  pdu.choice.successfulOutcome.criticality = X2AP_Criticality_reject;
+  pdu.choice.successfulOutcome.value.present = X2AP_SuccessfulOutcome__value_PR_HandoverRequestAcknowledge;
+  out = &pdu.choice.successfulOutcome.value.choice.HandoverRequestAcknowledge;
+
+  /* mandatory */
+  ie = (X2AP_HandoverRequestAcknowledge_IEs_t *)calloc(1, sizeof(X2AP_HandoverRequestAcknowledge_IEs_t));
+  ie->id = X2AP_ProtocolIE_ID_id_Old_eNB_UE_X2AP_ID;
+  ie->criticality = X2AP_Criticality_ignore;
+  ie->value.present = X2AP_HandoverRequestAcknowledge_IEs__value_PR_UE_X2AP_ID;
+  ie->value.choice.UE_X2AP_ID = 0;
+  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+
+  /* mandatory */
+  ie = (X2AP_HandoverRequestAcknowledge_IEs_t *)calloc(1, sizeof(X2AP_HandoverRequestAcknowledge_IEs_t));
+  ie->id = X2AP_ProtocolIE_ID_id_New_eNB_UE_X2AP_ID;
+  ie->criticality = X2AP_Criticality_ignore;
+  ie->value.present = X2AP_HandoverRequestAcknowledge_IEs__value_PR_UE_X2AP_ID_1;
+  ie->value.choice.UE_X2AP_ID = 0;
+  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+
+  /* mandatory */
+  ie = (X2AP_HandoverRequestAcknowledge_IEs_t *)calloc(1, sizeof(X2AP_HandoverRequestAcknowledge_IEs_t));
+  ie->id = X2AP_ProtocolIE_ID_id_E_RABs_Admitted_List;
+  ie->criticality = X2AP_Criticality_ignore;
+  ie->value.present = X2AP_HandoverRequestAcknowledge_IEs__value_PR_E_RABs_Admitted_List;
+
+  {
+      for (int i=0;i<x2ap_handover_req_ack->nb_e_rabs_tobesetup;i++) {
+        e_RABS_Admitted_ItemIEs = (X2AP_E_RABs_Admitted_ItemIEs_t *)calloc(1,sizeof(X2AP_E_RABs_Admitted_ItemIEs_t));
+        e_RABS_Admitted_ItemIEs->id = X2AP_ProtocolIE_ID_id_E_RABs_Admitted_Item;
+        e_RABS_Admitted_ItemIEs->criticality = X2AP_Criticality_ignore;
+        e_RABS_Admitted_ItemIEs->value.present = X2AP_E_RABs_Admitted_ItemIEs__value_PR_E_RABs_Admitted_Item;
+        e_RABs_Admitted_Item = &e_RABS_Admitted_ItemIEs->value.choice.E_RABs_Admitted_Item;
+        {
+          e_RABs_Admitted_Item->e_RAB_ID = x2ap_handover_req_ack->e_rabs_tobesetup[i].e_rab_id;
+        }
+        ASN_SEQUENCE_ADD(&ie->value.choice.E_RABs_Admitted_List.list, e_RABS_Admitted_ItemIEs);
+      }
+  }
+
+  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+
+  /* mandatory */
+  ie = (X2AP_HandoverRequestAcknowledge_IEs_t *)calloc(1, sizeof(X2AP_HandoverRequestAcknowledge_IEs_t));
+  ie->id = X2AP_ProtocolIE_ID_id_TargeteNBtoSource_eNBTransparentContainer;
+  ie->criticality = X2AP_Criticality_ignore;
+  ie->value.present = X2AP_HandoverRequestAcknowledge_IEs__value_PR_TargeteNBtoSource_eNBTransparentContainer;
+
+  OCTET_STRING_fromBuf(&ie->value.choice.TargeteNBtoSource_eNBTransparentContainer, (char*) x2ap_handover_req_ack->rrc_buffer, x2ap_handover_req_ack->rrc_buffer_size);
+
+  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+
+  if (x2ap_eNB_encode_pdu(&pdu, &buffer, &len) < 0) {
+    X2AP_ERROR("Failed to encode X2 handover response\n");
+    abort();
+    return -1;
+  }
+
+  MSC_LOG_TX_MESSAGE (MSC_X2AP_SRC_ENB, MSC_X2AP_TARGET_ENB, NULL, 0, "0 X2Handover/successfulOutcome 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;
+}
+
+int x2ap_eNB_generate_x2_ue_context_release (x2ap_eNB_data_t *x2ap_eNB_data_p)
+{
+
+  X2AP_X2AP_PDU_t                pdu;
+  X2AP_UEContextRelease_t        *out;
+  X2AP_UEContextRelease_IEs_t    *ie;
+
+  x2ap_eNB_instance_t               *instance_p;
+
+  uint8_t  *buffer;
+  uint32_t  len;
+  int       ret = 0;
+
+  DevAssert(x2ap_eNB_data_p != NULL);
+
+  /* get the eNB instance */
+  instance_p = x2ap_eNB_data_p->x2ap_eNB_instance;
+
+  DevAssert(instance_p != NULL);
+
+  /* Prepare the X2AP ue context relase message to encode */
+  memset(&pdu, 0, sizeof(pdu));
+  pdu.present = X2AP_X2AP_PDU_PR_initiatingMessage;
+  pdu.choice.initiatingMessage.procedureCode = X2AP_ProcedureCode_id_uEContextRelease;
+  pdu.choice.initiatingMessage.criticality = X2AP_Criticality_ignore;
+  pdu.choice.initiatingMessage.value.present = X2AP_InitiatingMessage__value_PR_UEContextRelease;
+  out = &pdu.choice.initiatingMessage.value.choice.UEContextRelease;
+
+  /* mandatory */
+  ie = (X2AP_UEContextRelease_IEs_t *)calloc(1, sizeof(X2AP_UEContextRelease_IEs_t));
+  ie->id = X2AP_ProtocolIE_ID_id_Old_eNB_UE_X2AP_ID;
+  ie->criticality = X2AP_Criticality_reject;
+  ie->value.present = X2AP_UEContextRelease_IEs__value_PR_UE_X2AP_ID;
+  ie->value.choice.UE_X2AP_ID = 0;
+  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+
+  /* mandatory */
+  ie = (X2AP_UEContextRelease_IEs_t *)calloc(1, sizeof(X2AP_UEContextRelease_IEs_t));
+  ie->id = X2AP_ProtocolIE_ID_id_New_eNB_UE_X2AP_ID;
+  ie->criticality = X2AP_Criticality_reject;
+  ie->value.present = X2AP_UEContextRelease_IEs__value_PR_UE_X2AP_ID_1;
+  ie->value.choice.UE_X2AP_ID = 0;
+  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+
+  if (x2ap_eNB_encode_pdu(&pdu, &buffer, &len) < 0) {
+    X2AP_ERROR("Failed to encode X2 UE Context Release\n");
+    abort();
+    return -1;
+  }
+
+  MSC_LOG_TX_MESSAGE (MSC_X2AP_SRC_ENB, MSC_X2AP_TARGET_ENB, NULL, 0, "0 X2UEContextRelease/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 ced4ecab456ec48739bfdd912fb73117d79c6359..0cadc88c0787d85a654943a16f8038ae0580cd41 100644
--- a/openair2/X2AP/x2ap_eNB_generate_messages.h
+++ b/openair2/X2AP/x2ap_eNB_generate_messages.h
@@ -19,6 +19,13 @@
  *      contact@openairinterface.org
  */
 
+/*! \file x2ap_eNB_generate_messages.h
+ * \brief x2ap procedures for eNB
+ * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr>
+ * \date 2018
+ * \version 1.0
+ */
+
 #ifndef X2AP_ENB_GENERATE_MESSAGES_H_
 #define X2AP_ENB_GENERATE_MESSAGES_H_
 
@@ -26,9 +33,9 @@
 #include "x2ap_common.h"
 
 int x2ap_eNB_generate_x2_setup_request(x2ap_eNB_instance_t *instance_p,
-				       x2ap_eNB_data_t *x2ap_enb_data_p);
+				       x2ap_eNB_data_t *x2ap_eNB_data_p);
 
-int x2ap_eNB_generate_x2_setup_response(x2ap_eNB_data_t *x2ap_enb_data_p);
+int x2ap_eNB_generate_x2_setup_response(x2ap_eNB_data_t *x2ap_eNB_data_p);
 
 int x2ap_eNB_generate_x2_setup_failure(instance_t instance,
                                        uint32_t assoc_id,
@@ -40,4 +47,11 @@ int x2ap_eNB_set_cause (X2AP_Cause_t * cause_p,
                         X2AP_Cause_PR cause_type,
                         long cause_value);
 
+int x2ap_eNB_generate_x2_handover_request (x2ap_eNB_data_t *x2ap_eNB_data_p,
+                                           x2ap_handover_req_t *x2ap_handover_req);
+
+int x2ap_eNB_generate_x2_handover_request_ack (x2ap_eNB_data_t *x2ap_eNB_data_p,
+                                               x2ap_handover_req_ack_t *x2ap_handover_req_ack);
+
+int x2ap_eNB_generate_x2_ue_context_release (x2ap_eNB_data_t *x2ap_eNB_data_p);
 #endif /*  X2AP_ENB_GENERATE_MESSAGES_H_ */
diff --git a/openair2/X2AP/x2ap_eNB_handler.c b/openair2/X2AP/x2ap_eNB_handler.c
index a16a3da5a8ac9d3b5fd998875fed3e61cd8cc5fc..27dfc8bd8539d18bbb984e365fe2deabf55df7dc 100644
--- a/openair2/X2AP/x2ap_eNB_handler.c
+++ b/openair2/X2AP/x2ap_eNB_handler.c
@@ -18,6 +18,14 @@
  * For more information about the OpenAirInterface (OAI) Software Alliance:
  *      contact@openairinterface.org
  */
+
+/*! \file x2ap_eNB_handler.c
+ * \brief x2ap handler procedures for eNB
+ * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr>
+ * \date 2018
+ * \version 1.0
+ */
+
 #include <stdint.h>
 
 #include "intertask_interface.h"
@@ -52,9 +60,20 @@ int x2ap_eNB_handle_x2_setup_failure (instance_t instance,
                                       uint32_t stream,
                                       X2AP_X2AP_PDU_t *pdu);
 
+static
+int x2ap_eNB_handle_handover_preparation (instance_t instance,
+                                          uint32_t assoc_id,
+                                          uint32_t stream,
+                                          X2AP_X2AP_PDU_t *pdu);
+static
+int x2ap_eNB_handle_handover_response (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] = {
-  { 0, 0, 0 }, /* handoverPreparation */
+  { x2ap_eNB_handle_handover_preparation, x2ap_eNB_handle_handover_response, 0 }, /* handoverPreparation */
   { 0, 0, 0 }, /* handoverCancel */
   { 0, 0, 0 }, /* loadIndication */
   { 0, 0, 0 }, /* errorIndication */
@@ -143,41 +162,105 @@ int x2ap_eNB_handle_message(instance_t instance, uint32_t assoc_id, int32_t stre
                                 const uint8_t *const data, const uint32_t data_length)
 {
   X2AP_X2AP_PDU_t pdu;
-  int ret;
+  int ret = 0;
 
   DevAssert(data != NULL);
 
   memset(&pdu, 0, sizeof(pdu));
 
+  //printf("Data length received: %d\n", data_length);
+
   if (x2ap_eNB_decode_pdu(&pdu, data, data_length) < 0) {
     X2AP_ERROR("Failed to decode PDU\n");
     return -1;
   }
 
-  /* Checking procedure Code and direction of message */
-  if (pdu.choice.initiatingMessage.procedureCode > sizeof(x2ap_messages_callback) / (3 * sizeof(
-        x2ap_message_decoded_callback))
-      || (pdu.present > X2AP_X2AP_PDU_PR_unsuccessfulOutcome)) {
-    X2AP_ERROR("[SCTP %d] Either procedureCode %ld or direction %d exceed expected\n",
-               assoc_id, pdu.choice.initiatingMessage.procedureCode, pdu.present);
-    ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_X2AP_X2AP_PDU, &pdu);
-    return -1;
-  }
+  switch (pdu.present) {
 
-  /* No handler present.
-   * This can mean not implemented or no procedure for eNB (wrong direction).
-   */
-  if (x2ap_messages_callback[pdu.choice.initiatingMessage.procedureCode][pdu.present - 1] == NULL) {
-    X2AP_ERROR("[SCTP %d] No handler for procedureCode %ld in %s\n",
-                assoc_id, pdu.choice.initiatingMessage.procedureCode,
-               x2ap_direction2String(pdu.present - 1));
-    ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_X2AP_X2AP_PDU, &pdu);
-    return -1;
-  }
+  case X2AP_X2AP_PDU_PR_initiatingMessage:
+    /* Checking procedure Code and direction of message */
+    if (pdu.choice.initiatingMessage.procedureCode > sizeof(x2ap_messages_callback) / (3 * sizeof(
+          x2ap_message_decoded_callback))) {
+        //|| (pdu.present > X2AP_X2AP_PDU_PR_unsuccessfulOutcome)) {
+      X2AP_ERROR("[SCTP %d] Either procedureCode %ld exceed expected\n",
+                 assoc_id, pdu.choice.initiatingMessage.procedureCode);
+      ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_X2AP_X2AP_PDU, &pdu);
+      return -1;
+    }
+
+    /* No handler present.
+     * This can mean not implemented or no procedure for eNB (wrong direction).
+     */
+    if (x2ap_messages_callback[pdu.choice.initiatingMessage.procedureCode][pdu.present - 1] == NULL) {
+      X2AP_ERROR("[SCTP %d] No handler for procedureCode %ld in %s\n",
+                  assoc_id, pdu.choice.initiatingMessage.procedureCode,
+                 x2ap_direction2String(pdu.present - 1));
+      ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_X2AP_X2AP_PDU, &pdu);
+      return -1;
+    }
+    /* Calling the right handler */
+    ret = (*x2ap_messages_callback[pdu.choice.initiatingMessage.procedureCode][pdu.present - 1])
+        (instance, assoc_id, stream, &pdu);
+    break;
+
+  case X2AP_X2AP_PDU_PR_successfulOutcome:
+    /* Checking procedure Code and direction of message */
+    if (pdu.choice.successfulOutcome.procedureCode > sizeof(x2ap_messages_callback) / (3 * sizeof(
+          x2ap_message_decoded_callback))) {
+        //|| (pdu.present > X2AP_X2AP_PDU_PR_unsuccessfulOutcome)) {
+      X2AP_ERROR("[SCTP %d] Either procedureCode %ld exceed expected\n",
+                 assoc_id, pdu.choice.successfulOutcome.procedureCode);
+      ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_X2AP_X2AP_PDU, &pdu);
+      return -1;
+    }
+
+    /* No handler present.
+     * This can mean not implemented or no procedure for eNB (wrong direction).
+     */
+    if (x2ap_messages_callback[pdu.choice.successfulOutcome.procedureCode][pdu.present - 1] == NULL) {
+      X2AP_ERROR("[SCTP %d] No handler for procedureCode %ld in %s\n",
+                  assoc_id, pdu.choice.successfulOutcome.procedureCode,
+                 x2ap_direction2String(pdu.present - 1));
+      ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_X2AP_X2AP_PDU, &pdu);
+      return -1;
+    }
+    /* Calling the right handler */
+    ret = (*x2ap_messages_callback[pdu.choice.successfulOutcome.procedureCode][pdu.present - 1])
+        (instance, assoc_id, stream, &pdu);
+    break;
+
+  case X2AP_X2AP_PDU_PR_unsuccessfulOutcome:
+    /* Checking procedure Code and direction of message */
+    if (pdu.choice.unsuccessfulOutcome.procedureCode > sizeof(x2ap_messages_callback) / (3 * sizeof(
+          x2ap_message_decoded_callback))) {
+        //|| (pdu.present > X2AP_X2AP_PDU_PR_unsuccessfulOutcome)) {
+      X2AP_ERROR("[SCTP %d] Either procedureCode %ld exceed expected\n",
+                 assoc_id, pdu.choice.unsuccessfulOutcome.procedureCode);
+      ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_X2AP_X2AP_PDU, &pdu);
+      return -1;
+    }
 
-  /* Calling the right handler */
-  ret = (*x2ap_messages_callback[pdu.choice.initiatingMessage.procedureCode][pdu.present - 1])
+    /* No handler present.
+     * This can mean not implemented or no procedure for eNB (wrong direction).
+     */
+    if (x2ap_messages_callback[pdu.choice.unsuccessfulOutcome.procedureCode][pdu.present - 1] == NULL) {
+      X2AP_ERROR("[SCTP %d] No handler for procedureCode %ld in %s\n",
+                  assoc_id, pdu.choice.unsuccessfulOutcome.procedureCode,
+                  x2ap_direction2String(pdu.present - 1));
+      ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_X2AP_X2AP_PDU, &pdu);
+      return -1;
+    }
+    /* Calling the right handler */
+    ret = (*x2ap_messages_callback[pdu.choice.unsuccessfulOutcome.procedureCode][pdu.present - 1])
         (instance, assoc_id, stream, &pdu);
+    break;
+
+  default:
+    X2AP_ERROR("[SCTP %d] Direction %d exceed expected\n",
+               assoc_id, pdu.present);
+    break;
+  }
+
   ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_X2AP_X2AP_PDU, &pdu);
   return ret;
 }
@@ -191,6 +274,7 @@ x2ap_eNB_handle_x2_setup_request(instance_t instance,
 
   X2AP_X2SetupRequest_t              *x2SetupRequest;
   X2AP_X2SetupRequest_IEs_t          *ie;
+  ServedCells__Member                *servedCellMember;
 
   x2ap_eNB_data_t                    *x2ap_eNB_data;
   uint32_t                           eNB_id = 0;
@@ -219,27 +303,31 @@ x2ap_eNB_handle_x2_setup_request(instance_t instance,
 
   X2AP_FIND_PROTOCOLIE_BY_ID(X2AP_X2SetupRequest_IEs_t, ie, x2SetupRequest,
                              X2AP_ProtocolIE_ID_id_GlobalENB_ID, true);
-
-  if (ie->value.choice.GlobalENB_ID.eNB_ID.present == X2AP_ENB_ID_PR_home_eNB_ID) {
+  if (ie == NULL ) {
+    X2AP_ERROR("%s %d: ie is a NULL pointer \n",__FILE__,__LINE__);
+    return -1;
+  } else {
+    if (ie->value.choice.GlobalENB_ID.eNB_ID.present == X2AP_ENB_ID_PR_home_eNB_ID) {
     // Home eNB ID = 28 bits
-    uint8_t  *eNB_id_buf = ie->value.choice.GlobalENB_ID.eNB_ID.choice.home_eNB_ID.buf;
+      uint8_t  *eNB_id_buf = ie->value.choice.GlobalENB_ID.eNB_ID.choice.home_eNB_ID.buf;
 
-    if (ie->value.choice.GlobalENB_ID.eNB_ID.choice.macro_eNB_ID.size != 28) {
+      if (ie->value.choice.GlobalENB_ID.eNB_ID.choice.macro_eNB_ID.size != 28) {
       //TODO: handle case were size != 28 -> notify ? reject ?
-    }
+      }
 
-    eNB_id = (eNB_id_buf[0] << 20) + (eNB_id_buf[1] << 12) + (eNB_id_buf[2] << 4) + ((eNB_id_buf[3] & 0xf0) >> 4);
-    X2AP_DEBUG("Home eNB id: %07x\n", eNB_id);
-  } else {
+      eNB_id = (eNB_id_buf[0] << 20) + (eNB_id_buf[1] << 12) + (eNB_id_buf[2] << 4) + ((eNB_id_buf[3] & 0xf0) >> 4);
+      X2AP_DEBUG("Home eNB id: %07x\n", eNB_id);
+    } else {
     // Macro eNB = 20 bits
-    uint8_t *eNB_id_buf = ie->value.choice.GlobalENB_ID.eNB_ID.choice.macro_eNB_ID.buf;
+      uint8_t *eNB_id_buf = ie->value.choice.GlobalENB_ID.eNB_ID.choice.macro_eNB_ID.buf;
 
-    if (ie->value.choice.GlobalENB_ID.eNB_ID.choice.macro_eNB_ID.size != 20) {
+      if (ie->value.choice.GlobalENB_ID.eNB_ID.choice.macro_eNB_ID.size != 20) {
       //TODO: handle case were size != 20 -> notify ? reject ?
-    }
+      }
 
-    eNB_id = (eNB_id_buf[0] << 12) + (eNB_id_buf[1] << 4) + ((eNB_id_buf[2] & 0xf0) >> 4);
-    X2AP_DEBUG("macro eNB id: %05x\n", eNB_id);
+      eNB_id = (eNB_id_buf[0] << 12) + (eNB_id_buf[1] << 4) + ((eNB_id_buf[2] & 0xf0) >> 4);
+      X2AP_DEBUG("macro eNB id: %05x\n", eNB_id);
+    }
   }
 
   X2AP_DEBUG("Adding eNB to the list of associated eNBs\n");
@@ -283,6 +371,21 @@ x2ap_eNB_handle_x2_setup_request(instance_t instance,
      */
   }
 
+  /* Set proper pci */
+  X2AP_FIND_PROTOCOLIE_BY_ID(X2AP_X2SetupRequest_IEs_t, ie, x2SetupRequest,
+                             X2AP_ProtocolIE_ID_id_ServedCells, true);
+
+  if (ie == NULL ) {
+    X2AP_ERROR("%s %d: ie is a NULL pointer \n",__FILE__,__LINE__);
+    return -1;
+  } else if (ie->value.choice.ServedCells.list.count > 0) {
+    x2ap_eNB_data->x2ap_eNB_instance->num_cc = ie->value.choice.ServedCells.list.count;
+    for (int i=0; i<ie->value.choice.ServedCells.list.count;i++) {
+      servedCellMember = (ServedCells__Member *)ie->value.choice.ServedCells.list.array[i];
+      x2ap_eNB_data->x2ap_eNB_instance->Nid_target_cell[i] = servedCellMember->servedCellInfo.pCI;
+    }
+  }
+
   return x2ap_eNB_generate_x2_setup_response(x2ap_eNB_data);
 }
 
@@ -295,6 +398,7 @@ int x2ap_eNB_handle_x2_setup_response(instance_t instance,
 
   X2AP_X2SetupResponse_t              *x2SetupResponse;
   X2AP_X2SetupResponse_IEs_t          *ie;
+  ServedCells__Member                 *servedCellMember;
 
   x2ap_eNB_data_t                     *x2ap_eNB_data;
   uint32_t                            eNB_id = 0;
@@ -322,6 +426,10 @@ int x2ap_eNB_handle_x2_setup_response(instance_t instance,
   X2AP_FIND_PROTOCOLIE_BY_ID(X2AP_X2SetupResponse_IEs_t, ie, x2SetupResponse,
                              X2AP_ProtocolIE_ID_id_GlobalENB_ID, true);
 
+  if (ie == NULL ) {
+    X2AP_ERROR("%s %d: ie is a NULL pointer \n",__FILE__,__LINE__);
+    return -1;
+  }
   if (ie->value.choice.GlobalENB_ID.eNB_ID.present == X2AP_ENB_ID_PR_home_eNB_ID) {
     // Home eNB ID = 28 bits
     uint8_t  *eNB_id_buf = ie->value.choice.GlobalENB_ID.eNB_ID.choice.home_eNB_ID.buf;
@@ -367,6 +475,21 @@ int x2ap_eNB_handle_x2_setup_response(instance_t instance,
      */
   }
 
+  /* Set proper pci */
+  X2AP_FIND_PROTOCOLIE_BY_ID(X2AP_X2SetupResponse_IEs_t, ie, x2SetupResponse,
+                             X2AP_ProtocolIE_ID_id_ServedCells, true);
+
+  if (ie == NULL ) {
+    X2AP_ERROR("%s %d: ie is a NULL pointer \n",__FILE__,__LINE__);
+    return -1;
+  } else if (ie->value.choice.ServedCells.list.count > 0) {
+    x2ap_eNB_data->x2ap_eNB_instance->num_cc = ie->value.choice.ServedCells.list.count;
+    for (int i=0; i<ie->value.choice.ServedCells.list.count;i++) {
+      servedCellMember = (ServedCells__Member *)ie->value.choice.ServedCells.list.array[i];
+      x2ap_eNB_data->x2ap_eNB_instance->Nid_target_cell[i] = servedCellMember->servedCellInfo.pCI;
+    }
+  }
+
   /* Optionaly set the target eNB name */
 
   /* The association is now ready as source and target eNBs know parameters of each other.
@@ -416,7 +539,10 @@ int x2ap_eNB_handle_x2_setup_failure(instance_t instance,
   X2AP_FIND_PROTOCOLIE_BY_ID(X2AP_X2SetupFailure_IEs_t, ie, x2SetupFailure,
                              X2AP_ProtocolIE_ID_id_Cause, true);
 
-
+  if (ie == NULL ) {
+    X2AP_ERROR("%s %d: ie is a NULL pointer \n",__FILE__,__LINE__);
+    return -1;
+  }
   // need a FSM to handle all cases
   if ((ie->value.choice.Cause.present == X2AP_Cause_PR_misc) &&
       (ie->value.choice.Cause.choice.misc == X2AP_CauseMisc_unspecified)) {
@@ -430,3 +556,173 @@ int x2ap_eNB_handle_x2_setup_failure(instance_t instance,
 
   return 0;
 }
+
+static
+int x2ap_eNB_handle_handover_preparation (instance_t instance,
+                                          uint32_t assoc_id,
+                                          uint32_t stream,
+                                          X2AP_X2AP_PDU_t *pdu)
+{
+
+  X2AP_HandoverRequest_t             *x2HandoverRequest;
+  X2AP_HandoverRequest_IEs_t         *ie;
+
+  X2AP_E_RABs_ToBeSetup_ItemIEs_t    *e_RABS_ToBeSetup_ItemIEs;
+  X2AP_E_RABs_ToBeSetup_Item_t       *e_RABs_ToBeSetup_Item;
+
+  x2ap_eNB_data_t                    *x2ap_eNB_data;
+  MessageDef                         *msg;
+
+  DevAssert (pdu != NULL);
+  x2HandoverRequest = &pdu->choice.initiatingMessage.value.choice.HandoverRequest;
+
+  if (stream == 0) {
+    X2AP_ERROR ("Received new x2 handover request on stream == 0\n");
+    /* TODO: send a x2 failure response */
+    return 0;
+  }
+
+  X2AP_DEBUG ("Received a new X2 handover request\n");
+
+  x2ap_eNB_data = x2ap_get_eNB(NULL, assoc_id, 0);
+  DevAssert(x2ap_eNB_data != NULL);
+
+  msg = itti_alloc_new_message(TASK_X2AP, X2AP_HANDOVER_REQ);
+
+  X2AP_FIND_PROTOCOLIE_BY_ID(X2AP_HandoverRequest_IEs_t, ie, x2HandoverRequest,
+                             X2AP_ProtocolIE_ID_id_Old_eNB_UE_X2AP_ID, true);
+  //X2AP_HANDOVER_REQ(msg).source_rnti = ctxt_pP->rnti;
+  //X2AP_HANDOVER_REQ(m).source_x2id = x2HandoverRequest->old_eNB_UE_X2AP_ID;
+  if (ie == NULL ) {
+    X2AP_ERROR("%s %d: ie is a NULL pointer \n",__FILE__,__LINE__);
+    return -1;
+  } else {
+    X2AP_HANDOVER_REQ(msg).old_eNB_ue_x2ap_id = ie->value.choice.UE_X2AP_ID;
+  }
+
+  //X2AP_HANDOVER_REQ(msg).target_physCellId = measResults2->measResultNeighCells->choice.
+                                               //measResultListEUTRA.list.array[ncell_index]->physCellId;
+  X2AP_FIND_PROTOCOLIE_BY_ID(X2AP_HandoverRequest_IEs_t, ie, x2HandoverRequest,
+                             X2AP_ProtocolIE_ID_id_GUMMEI_ID, true);
+
+  TBCD_TO_MCC_MNC(&ie->value.choice.ECGI.pLMN_Identity, X2AP_HANDOVER_REQ(msg).ue_gummei.mcc,
+                  X2AP_HANDOVER_REQ(msg).ue_gummei.mnc, X2AP_HANDOVER_REQ(msg).ue_gummei.mnc_len);
+  OCTET_STRING_TO_INT8(&ie->value.choice.GUMMEI.mME_Code, X2AP_HANDOVER_REQ(msg).ue_gummei.mme_code);
+  OCTET_STRING_TO_INT16(&ie->value.choice.GUMMEI.gU_Group_ID.mME_Group_ID, X2AP_HANDOVER_REQ(msg).ue_gummei.mme_group_id);
+
+  X2AP_FIND_PROTOCOLIE_BY_ID(X2AP_HandoverRequest_IEs_t, ie, x2HandoverRequest,
+                             X2AP_ProtocolIE_ID_id_UE_ContextInformation, true);
+
+  if (ie == NULL ) {
+    X2AP_ERROR("%s %d: ie is a NULL pointer \n",__FILE__,__LINE__);
+    return -1;
+  }
+
+  X2AP_HANDOVER_REQ(msg).mme_ue_s1ap_id = ie->value.choice.UE_ContextInformation.mME_UE_S1AP_ID;
+  X2AP_HANDOVER_REQ(msg).target_mod_id = x2ap_eNB_data->x2ap_eNB_instance->eNB_id;
+  X2AP_HANDOVER_REQ(msg).security_capabilities.encryption_algorithms =
+    BIT_STRING_to_uint16(&ie->value.choice.UE_ContextInformation.uESecurityCapabilities.encryptionAlgorithms);
+  X2AP_HANDOVER_REQ(msg).security_capabilities.integrity_algorithms =
+    BIT_STRING_to_uint16(&ie->value.choice.UE_ContextInformation.uESecurityCapabilities.integrityProtectionAlgorithms);
+
+  //X2AP_HANDOVER_REQ(msg).ue_ambr=ue_context_pP->ue_context.ue_ambr;
+
+  if ((ie->value.choice.UE_ContextInformation.aS_SecurityInformation.key_eNodeB_star.buf) &&
+          (ie->value.choice.UE_ContextInformation.aS_SecurityInformation.key_eNodeB_star.size == 32)) {
+    memcpy(X2AP_HANDOVER_REQ(msg).kenb, ie->value.choice.UE_ContextInformation.aS_SecurityInformation.key_eNodeB_star.buf, 32);
+    X2AP_HANDOVER_REQ(msg).kenb_ncc = ie->value.choice.UE_ContextInformation.aS_SecurityInformation.nextHopChainingCount;
+  } else {
+    X2AP_WARN ("Size of eNB key star does not match the expected value\n");
+  }
+
+  if (ie->value.choice.UE_ContextInformation.e_RABs_ToBeSetup_List.list.count > 0) {
+
+    X2AP_HANDOVER_REQ(msg).nb_e_rabs_tobesetup = ie->value.choice.UE_ContextInformation.e_RABs_ToBeSetup_List.list.count;
+
+    for (int i=0;i<ie->value.choice.UE_ContextInformation.e_RABs_ToBeSetup_List.list.count;i++) {
+      e_RABS_ToBeSetup_ItemIEs = (X2AP_E_RABs_ToBeSetup_ItemIEs_t *) ie->value.choice.UE_ContextInformation.e_RABs_ToBeSetup_List.list.array[i];
+      e_RABs_ToBeSetup_Item = &e_RABS_ToBeSetup_ItemIEs->value.choice.E_RABs_ToBeSetup_Item;
+
+      X2AP_HANDOVER_REQ(msg).e_rabs_tobesetup[i].e_rab_id = e_RABs_ToBeSetup_Item->e_RAB_ID ;
+
+      memcpy(X2AP_HANDOVER_REQ(msg).e_rabs_tobesetup[i].eNB_addr.buffer,
+                     e_RABs_ToBeSetup_Item->uL_GTPtunnelEndpoint.transportLayerAddress.buf,
+                     e_RABs_ToBeSetup_Item->uL_GTPtunnelEndpoint.transportLayerAddress.size);
+
+      X2AP_HANDOVER_REQ(msg).e_rabs_tobesetup[i].eNB_addr.length =
+                      e_RABs_ToBeSetup_Item->uL_GTPtunnelEndpoint.transportLayerAddress.size * 8 - e_RABs_ToBeSetup_Item->uL_GTPtunnelEndpoint.transportLayerAddress.bits_unused;
+
+      OCTET_STRING_TO_INT32(&e_RABs_ToBeSetup_Item->uL_GTPtunnelEndpoint.gTP_TEID,
+                                                X2AP_HANDOVER_REQ(msg).e_rabs_tobesetup[i].gtp_teid);
+
+      X2AP_HANDOVER_REQ(msg).e_rab_param[i].qos.qci = e_RABs_ToBeSetup_Item->e_RAB_Level_QoS_Parameters.qCI;
+      X2AP_HANDOVER_REQ(msg).e_rab_param[i].qos.allocation_retention_priority.priority_level = e_RABs_ToBeSetup_Item->e_RAB_Level_QoS_Parameters.allocationAndRetentionPriority.priorityLevel;
+      X2AP_HANDOVER_REQ(msg).e_rab_param[i].qos.allocation_retention_priority.pre_emp_capability = e_RABs_ToBeSetup_Item->e_RAB_Level_QoS_Parameters.allocationAndRetentionPriority.pre_emptionCapability;
+      X2AP_HANDOVER_REQ(msg).e_rab_param[i].qos.allocation_retention_priority.pre_emp_vulnerability = e_RABs_ToBeSetup_Item->e_RAB_Level_QoS_Parameters.allocationAndRetentionPriority.pre_emptionVulnerability;
+    }
+
+  }
+  else {
+    X2AP_ERROR ("Can't decode the e_RABs_ToBeSetup_List \n");
+  }
+
+  X2AP_RRC_Context_t *c = &ie->value.choice.UE_ContextInformation.rRC_Context;
+
+  if (c->size > 1024 /* TODO: this is the size of rrc_buffer in struct x2ap_handover_req_ack_s*/)
+    { printf("%s:%d: fatal: buffer too big\n", __FILE__, __LINE__); abort(); }
+
+  memcpy(X2AP_HANDOVER_REQ_ACK(msg).rrc_buffer, c->buf, c->size);
+  X2AP_HANDOVER_REQ_ACK(msg).rrc_buffer_size = c->size;
+
+  itti_send_msg_to_task(TASK_RRC_ENB, x2ap_eNB_data->x2ap_eNB_instance->instance, msg);
+
+  return 0;
+}
+
+static
+int x2ap_eNB_handle_handover_response (instance_t instance,
+                                       uint32_t assoc_id,
+                                       uint32_t stream,
+                                       X2AP_X2AP_PDU_t *pdu)
+{
+  X2AP_HandoverRequestAcknowledge_t             *x2HandoverRequestAck;
+  X2AP_HandoverRequestAcknowledge_IEs_t         *ie;
+
+  x2ap_eNB_data_t                               *x2ap_eNB_data;
+  MessageDef                                    *msg;
+
+  DevAssert (pdu != NULL);
+  x2HandoverRequestAck = &pdu->choice.successfulOutcome.value.choice.HandoverRequestAcknowledge;
+
+  if (stream == 0) {
+    X2AP_ERROR ("Received new x2 handover response on stream == 0\n");
+    /* TODO: send a x2 failure response */
+    return 0;
+  }
+
+  X2AP_DEBUG ("Received a new X2 handover response\n");
+
+  x2ap_eNB_data = x2ap_get_eNB(NULL, assoc_id, 0);
+  DevAssert(x2ap_eNB_data != NULL);
+
+
+  msg = itti_alloc_new_message(TASK_X2AP, X2AP_HANDOVER_REQ_ACK);
+  /* TODO: fill the message */
+  //extern int x2id_to_source_rnti[1];
+  //X2AP_HANDOVER_REQ_ACK(m).source_x2id = x2HandoverRequestAck->old_eNB_UE_X2AP_ID;
+  //X2AP_HANDOVER_REQ_ACK(m).source_rnti = x2id_to_source_rnti[x2HandoverRequestAck->old_eNB_UE_X2AP_ID];
+
+  X2AP_FIND_PROTOCOLIE_BY_ID(X2AP_HandoverRequestAcknowledge_IEs_t, ie, x2HandoverRequestAck,
+                             X2AP_ProtocolIE_ID_id_TargeteNBtoSource_eNBTransparentContainer, true);
+
+  X2AP_TargeteNBtoSource_eNBTransparentContainer_t *c = &ie->value.choice.TargeteNBtoSource_eNBTransparentContainer;
+
+  if (c->size > 1024 /* TODO: this is the size of rrc_buffer in struct x2ap_handover_req_ack_s*/)
+    { printf("%s:%d: fatal: buffer too big\n", __FILE__, __LINE__); abort(); }
+
+  memcpy(X2AP_HANDOVER_REQ_ACK(msg).rrc_buffer, c->buf, c->size);
+  X2AP_HANDOVER_REQ_ACK(msg).rrc_buffer_size = c->size;
+
+  itti_send_msg_to_task(TASK_RRC_ENB, x2ap_eNB_data->x2ap_eNB_instance->instance, msg);
+  return 0;
+}
diff --git a/openair2/X2AP/x2ap_eNB_handler.h b/openair2/X2AP/x2ap_eNB_handler.h
index 6d47f82aaf20981ec9763bb4c41c08baad924d63..5826ffc54c424984482a83e3210f018dcde9eafa 100644
--- a/openair2/X2AP/x2ap_eNB_handler.h
+++ b/openair2/X2AP/x2ap_eNB_handler.h
@@ -19,6 +19,13 @@
  *      contact@openairinterface.org
  */
 
+/*! \file x2ap_eNB_handler.h
+ * \brief x2ap handler procedures for eNB
+ * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr>
+ * \date 2018
+ * \version 1.0
+ */
+
 #ifndef X2AP_ENB_HANDLERS_H_
 #define X2AP_ENB_HANDLERS_H_
 
diff --git a/openair2/X2AP/x2ap_eNB_itti_messaging.c b/openair2/X2AP/x2ap_eNB_itti_messaging.c
index 9283d967d4cdb8a8e295160ef7bcc39730e25b17..7573d9be898a8bd0643b9e5ffa4be85c9052ae89 100644
--- a/openair2/X2AP/x2ap_eNB_itti_messaging.c
+++ b/openair2/X2AP/x2ap_eNB_itti_messaging.c
@@ -19,6 +19,13 @@
  *      contact@openairinterface.org
  */
 
+/*! \file x2ap_eNB_itti_messaging.c
+ * \brief x2ap tasks for eNB
+ * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr>
+ * \date 2018
+ * \version 1.0
+ */
+
 #include "intertask_interface.h"
 
 #include "x2ap_eNB_itti_messaging.h"
diff --git a/openair2/X2AP/x2ap_eNB_itti_messaging.h b/openair2/X2AP/x2ap_eNB_itti_messaging.h
index 55bf58b6605260c85c70b4d5887f768c42f3e49f..ee946880ac3c3b69ca51b58ee0c327260ea3ed6d 100644
--- a/openair2/X2AP/x2ap_eNB_itti_messaging.h
+++ b/openair2/X2AP/x2ap_eNB_itti_messaging.h
@@ -19,6 +19,13 @@
  *      contact@openairinterface.org
  */
 
+/*! \file x2ap_eNB_itti_messaging.h
+ * \brief x2ap tasks for eNB
+ * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr>
+ * \date 2018
+ * \version 1.0
+ */
+
 #ifndef X2AP_ENB_ITTI_MESSAGING_H_
 #define X2AP_ENB_ITTI_MESSAGING_H_
 
diff --git a/openair2/X2AP/x2ap_eNB_management_procedures.c b/openair2/X2AP/x2ap_eNB_management_procedures.c
index ed5c16de7d1805f7f78509701c113e9173cf5f74..cd329e50d024ddaae348e869305f61b434d276ef 100644
--- a/openair2/X2AP/x2ap_eNB_management_procedures.c
+++ b/openair2/X2AP/x2ap_eNB_management_procedures.c
@@ -19,6 +19,13 @@
  *      contact@openairinterface.org
  */
 
+/*! \file x2ap_eNB_management_procedures.c
+ * \brief x2ap tasks for eNB
+ * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr>
+ * \date 2018
+ * \version 1.0
+ */
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
@@ -162,6 +169,22 @@ x2ap_eNB_instance_t *x2ap_eNB_get_instance(instance_t instance)
   return NULL;
 }
 
+x2ap_eNB_instance_t *x2ap_eNB_pci_get_instance(uint32_t pci)
+{
+  x2ap_eNB_instance_t *temp = NULL;
+
+  STAILQ_FOREACH(temp, &x2ap_eNB_internal_data.x2ap_eNB_instances_head,
+                 x2ap_eNB_entries) {
+    for (int i=0; i<temp->num_cc;i++) {
+      if (temp->Nid_target_cell[i] == pci) {
+        /* Matching occurence */
+        return temp;
+      }
+    }
+  }
+
+  return NULL;
+}
 
 /// utility functions
 
diff --git a/openair2/X2AP/x2ap_eNB_management_procedures.h b/openair2/X2AP/x2ap_eNB_management_procedures.h
index 4c4da5251f494e7490133987dbc53ee618b080ca..6eb430b2b00699818132cc23f546635b14f95f49 100644
--- a/openair2/X2AP/x2ap_eNB_management_procedures.h
+++ b/openair2/X2AP/x2ap_eNB_management_procedures.h
@@ -19,6 +19,13 @@
  *      contact@openairinterface.org
  */
 
+/*! \file x2ap_eNB_management_procedures.h
+ * \brief x2ap tasks for eNB
+ * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr>
+ * \date 2018
+ * \version 1.0
+ */
+
 #ifndef X2AP_ENB_MANAGEMENT_PROCEDURES_H_
 #define X2AP_ENB_MANAGEMENT_PROCEDURES_H
 
@@ -30,6 +37,8 @@ void x2ap_eNB_insert_new_instance(x2ap_eNB_instance_t *new_instance_p);
 
 x2ap_eNB_instance_t *x2ap_eNB_get_instance(uint8_t mod_id);
 
+x2ap_eNB_instance_t *x2ap_eNB_pci_get_instance(uint32_t pci);
+
 uint16_t x2ap_eNB_fetch_add_global_cnx_id(void);
 
 void x2ap_eNB_prepare_internal_data(void);
diff --git a/openair3/COMMON/as_message.h b/openair3/COMMON/as_message.h
deleted file mode 100644
index 30810a325eace63c944b947bfb8c0a6487094e80..0000000000000000000000000000000000000000
--- a/openair3/COMMON/as_message.h
+++ /dev/null
@@ -1,578 +0,0 @@
-/*
- * Copyright (c) 2015, EURECOM (www.eurecom.fr)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this
- *    list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- *    this list of conditions and the following disclaimer in the documentation
- *    and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and documentation are those
- * of the authors and should not be interpreted as representing official policies,
- * either expressed or implied, of the FreeBSD Project.
- */
-
-
-/*****************************************************************************
-
-Source      as_message.h
-
-Version     0.1
-
-Date        2012/10/18
-
-Product     NAS stack
-
-Subsystem   Application Programming Interface
-
-Author      Frederic Maurel
-
-Description Defines the messages supported by the Access Stratum sublayer
-        protocol (usually RRC and S1AP for E-UTRAN) and functions used
-        to encode and decode
-
-*****************************************************************************/
-#ifndef __AS_MESSAGE_H__
-#define __AS_MESSAGE_H__
-
-#include "commonDef.h"
-#include "networkDef.h"
-
-/****************************************************************************/
-/*********************  G L O B A L    C O N S T A N T S  *******************/
-/****************************************************************************/
-
-/*
- * --------------------------------------------------------------------------
- *              Access Stratum message types
- * --------------------------------------------------------------------------
- */
-#define AS_REQUEST  0x0100
-#define AS_RESPONSE 0x0200
-#define AS_INDICATION   0x0400
-#define AS_CONFIRM  0x0800
-
-/*
- * --------------------------------------------------------------------------
- *          Access Stratum message identifiers
- * --------------------------------------------------------------------------
- */
-
-/* Broadcast information */
-#define AS_BROADCAST_INFO       0x01
-#define AS_BROADCAST_INFO_IND       (AS_BROADCAST_INFO | AS_INDICATION)
-
-/* Cell information relevant for cell selection processing */
-#define AS_CELL_INFO            0x02
-#define AS_CELL_INFO_REQ        (AS_CELL_INFO | AS_REQUEST)
-#define AS_CELL_INFO_CNF        (AS_CELL_INFO | AS_CONFIRM)
-#define AS_CELL_INFO_IND        (AS_CELL_INFO | AS_INDICATION)
-
-/* Paging information */
-#define AS_PAGING           0x03
-#define AS_PAGING_REQ           (AS_PAGING | AS_REQUEST)
-#define AS_PAGING_IND           (AS_PAGING | AS_INDICATION)
-
-/* NAS signalling connection establishment */
-#define AS_NAS_ESTABLISH        0x04
-#define AS_NAS_ESTABLISH_REQ        (AS_NAS_ESTABLISH | AS_REQUEST)
-#define AS_NAS_ESTABLISH_IND        (AS_NAS_ESTABLISH | AS_INDICATION)
-#define AS_NAS_ESTABLISH_RSP        (AS_NAS_ESTABLISH | AS_RESPONSE)
-#define AS_NAS_ESTABLISH_CNF        (AS_NAS_ESTABLISH | AS_CONFIRM)
-
-/* NAS signalling connection release */
-#define AS_NAS_RELEASE          0x05
-#define AS_NAS_RELEASE_REQ      (AS_NAS_RELEASE | AS_REQUEST)
-#define AS_NAS_RELEASE_IND      (AS_NAS_RELEASE | AS_INDICATION)
-
-/* Uplink information transfer */
-#define AS_UL_INFO_TRANSFER     0x06
-#define AS_UL_INFO_TRANSFER_REQ     (AS_UL_INFO_TRANSFER | AS_REQUEST)
-#define AS_UL_INFO_TRANSFER_CNF     (AS_UL_INFO_TRANSFER | AS_CONFIRM)
-#define AS_UL_INFO_TRANSFER_IND     (AS_UL_INFO_TRANSFER | AS_INDICATION)
-
-/* Downlink information transfer */
-#define AS_DL_INFO_TRANSFER     0x07
-#define AS_DL_INFO_TRANSFER_REQ     (AS_DL_INFO_TRANSFER | AS_REQUEST)
-#define AS_DL_INFO_TRANSFER_CNF     (AS_DL_INFO_TRANSFER | AS_CONFIRM)
-#define AS_DL_INFO_TRANSFER_IND     (AS_DL_INFO_TRANSFER | AS_INDICATION)
-
-/* Radio Access Bearer establishment */
-#define AS_RAB_ESTABLISH        0x08
-#define AS_RAB_ESTABLISH_REQ        (AS_RAB_ESTABLISH | AS_REQUEST)
-#define AS_RAB_ESTABLISH_IND        (AS_RAB_ESTABLISH | AS_INDICATION)
-#define AS_RAB_ESTABLISH_RSP        (AS_RAB_ESTABLISH | AS_RESPONSE)
-#define AS_RAB_ESTABLISH_CNF        (AS_RAB_ESTABLISH | AS_CONFIRM)
-
-/* Radio Access Bearer release */
-#define AS_RAB_RELEASE          0x09
-#define AS_RAB_RELEASE_REQ      (AS_RAB_RELEASE | AS_REQUEST)
-#define AS_RAB_RELEASE_IND      (AS_RAB_RELEASE | AS_INDICATION)
-
-/* NAS Cause */
-#define EPS_SERVICES_AND_NON_EPS_SERVICES_NOT_ALLOWED (8)
-#define EPS_SERVICES_NOT_ALLOWED                      (7)
-#define PLMN_NOT_ALLOWED                              (11)
-#define TRACKING_AREA_NOT_ALLOWED                     (12)
-#define ROAMING_NOT_ALLOWED_IN_THIS_TRACKING_AREA     (13)
-#define EPS_SERVICES_NOT_ALLOWED_IN_THIS_PLMN         (14)
-#define NO_SUITABLE_CELLS_IN_TRACKING_AREA            (15)
-#define NETWORK_FAILURE                               (17)
-#define ESM_FAILURE                                   (19)
-
-typedef enum nas_cause_s {
-  NAS_CAUSE_EPS_SERVICES_AND_NON_EPS_SERVICES_NOT_ALLOWED = EPS_SERVICES_AND_NON_EPS_SERVICES_NOT_ALLOWED,
-  NAS_CAUSE_EPS_SERVICES_NOT_ALLOWED                  = EPS_SERVICES_NOT_ALLOWED,
-  NAS_CAUSE_PLMN_NOT_ALLOWED                          = PLMN_NOT_ALLOWED,
-  NAS_CAUSE_TRACKING_AREA_NOT_ALLOWED                 = TRACKING_AREA_NOT_ALLOWED,
-  NAS_CAUSE_ROAMING_NOT_ALLOWED_IN_THIS_TRACKING_AREA = ROAMING_NOT_ALLOWED_IN_THIS_TRACKING_AREA,
-  NAS_CAUSE_EPS_SERVICES_NOT_ALLOWED_IN_THIS_PLMN     = EPS_SERVICES_NOT_ALLOWED_IN_THIS_PLMN,
-  NAS_CAUSE_NO_SUITABLE_CELLS_IN_TRACKING_AREA        = NO_SUITABLE_CELLS_IN_TRACKING_AREA,
-  NAS_CAUSE_NETWORK_FAILURE                           = NETWORK_FAILURE,
-  NAS_CAUSE_ESM_FAILURE                               = ESM_FAILURE
-} nas_cause_t;
-
-/*
- * --------------------------------------------------------------------------
- *          Access Stratum message global parameters
- * --------------------------------------------------------------------------
- */
-
-/* Error code */
-typedef enum nas_error_code_s {
-  AS_SUCCESS = 1, /* Success code, transaction is going on    */
-  AS_TERMINATED_NAS,  /* Transaction terminated by NAS        */
-  AS_TERMINATED_AS,   /* Transaction terminated by AS         */
-  AS_FAILURE      /* Failure code                 */
-} nas_error_code_t;
-
-/* Core network domain */
-typedef enum core_network_s {
-  AS_PS = 1,      /* Packet-Switched  */
-  AS_CS       /* Circuit-Switched */
-} core_network_t;
-
-/* SAE Temporary Mobile Subscriber Identity */
-typedef struct as_stmsi_s {
-  uint8_t MMEcode;    /* MME code that allocated the GUTI     */
-  uint32_t m_tmsi;    /* M-Temporary Mobile Subscriber Identity   */
-} as_stmsi_t;
-
-/* Dedicated NAS information */
-typedef struct as_nas_info_s {
-  uint32_t length;    /* Length of the NAS information data       */
-  Byte_t* data;   /* Dedicated NAS information data container */
-} as_nas_info_t;
-
-/* Radio Access Bearer identity */
-typedef uint8_t as_rab_id_t;
-
-/****************************************************************************/
-/************************  G L O B A L    T Y P E S  ************************/
-/****************************************************************************/
-
-/*
- * --------------------------------------------------------------------------
- *              Broadcast information
- * --------------------------------------------------------------------------
- */
-
-/*
- * AS->NAS - Broadcast information indication
- * AS may asynchronously report to NAS available PLMNs within specific
- * location area
- */
-typedef struct broadcast_info_ind_s {
-#define PLMN_LIST_MAX_SIZE  6
-  PLMN_LIST_T(PLMN_LIST_MAX_SIZE) plmnIDs; /* List of PLMN identifiers */
-  ci_t cellID;    /* Identity of the cell serving the listed PLMNs */
-  tac_t tac;      /* Code of the tracking area the cell belongs to */
-} broadcast_info_ind_t;
-
-/*
- * --------------------------------------------------------------------------
- *     Cell information relevant for cell selection processing
- * --------------------------------------------------------------------------
- */
-
-/* Radio access technologies supported by the network */
-#define AS_GSM              (1 << NET_ACCESS_GSM)
-#define AS_COMPACT          (1 << NET_ACCESS_COMPACT)
-#define AS_UTRAN            (1 << NET_ACCESS_UTRAN)
-#define AS_EGPRS            (1 << NET_ACCESS_EGPRS)
-#define AS_HSDPA            (1 << NET_ACCESS_HSDPA)
-#define AS_HSUPA            (1 << NET_ACCESS_HSUPA)
-#define AS_HSDUPA           (1 << NET_ACCESS_HSDUPA)
-#define AS_EUTRAN           (1 << NET_ACCESS_EUTRAN)
-
-/*
- * NAS->AS - Cell Information request
- * NAS request AS to search for a suitable cell belonging to the selected
- * PLMN to camp on.
- */
-typedef struct cell_info_req_s {
-  plmn_t plmnID;  /* Selected PLMN identity           */
-  Byte_t rat;     /* Bitmap - set of radio access technologies    */
-} cell_info_req_t;
-
-/*
- * AS->NAS - Cell Information confirm
- * AS search for a suitable cell and respond to NAS. If found, the cell
- * is selected to camp on.
- */
-typedef struct cell_info_cnf_s {
-  uint8_t errCode;    /* Error code                     */
-  ci_t cellID;    /* Identity of the cell serving the selected PLMN */
-  tac_t tac;      /* Code of the tracking area the cell belongs to  */
-  AcT_t rat;      /* Radio access technology supported by the cell  */
-  uint8_t rsrq;   /* Reference signal received quality         */
-  uint8_t rsrp;   /* Reference signal received power       */
-} cell_info_cnf_t;
-
-/*
- * AS->NAS - Cell Information indication
- * AS may change cell selection if a more suitable cell is found.
- */
-typedef struct cell_info_ind_s {
-  ci_t cellID;    /* Identity of the new serving cell      */
-  tac_t tac;      /* Code of the tracking area the cell belongs to */
-} cell_info_ind_t;
-
-/*
- * --------------------------------------------------------------------------
- *              Paging information
- * --------------------------------------------------------------------------
- */
-
-/* Paging cause */
-typedef enum paging_cause_s {
-  AS_CONNECTION_ESTABLISH,    /* Establish NAS signalling connection  */
-  AS_EPS_ATTACH,      /* Perform local detach and initiate EPS
-                 * attach procedure         */
-  AS_CS_FALLBACK      /* Inititate CS fallback procedure  */
-} paging_cause_t;
-
-/*
- * NAS->AS - Paging Information request
- * NAS requests the AS that NAS signalling messages or user data is pending
- * to be sent.
- */
-typedef struct paging_req_s {
-  as_stmsi_t s_tmsi;  /* UE identity                  */
-  uint8_t CN_domain;  /* Core network domain              */
-} paging_req_t;
-
-/*
- * AS->NAS - Paging Information indication
- * AS reports to the NAS that appropriate procedure has to be initiated.
- */
-typedef struct paging_ind_s {
-  paging_cause_t cause;  /* Paging cause                 */
-} paging_ind_t;
-
-/*
- * --------------------------------------------------------------------------
- *          NAS signalling connection establishment
- * --------------------------------------------------------------------------
- */
-
-/* Cause of RRC connection establishment */
-typedef enum as_cause_s {
-  AS_CAUSE_UNKNOWN    = 0,
-  AS_CAUSE_EMERGENCY  = NET_ESTABLISH_CAUSE_EMERGENCY,
-  AS_CAUSE_HIGH_PRIO  = NET_ESTABLISH_CAUSE_HIGH_PRIO,
-  AS_CAUSE_MT_ACCESS  = NET_ESTABLISH_CAUSE_MT_ACCESS,
-  AS_CAUSE_MO_SIGNAL  = NET_ESTABLISH_CAUSE_MO_SIGNAL,
-  AS_CAUSE_MO_DATA    = NET_ESTABLISH_CAUSE_MO_DATA,
-  AS_CAUSE_V1020      = NET_ESTABLISH_CAUSE_V1020
-} as_cause_t;
-
-/* Type of the call associated to the RRC connection establishment */
-typedef enum as_call_type_s {
-  AS_TYPE_ORIGINATING_SIGNAL  = NET_ESTABLISH_TYPE_ORIGINATING_SIGNAL,
-  AS_TYPE_EMERGENCY_CALLS     = NET_ESTABLISH_TYPE_EMERGENCY_CALLS,
-  AS_TYPE_ORIGINATING_CALLS   = NET_ESTABLISH_TYPE_ORIGINATING_CALLS,
-  AS_TYPE_TERMINATING_CALLS   = NET_ESTABLISH_TYPE_TERMINATING_CALLS,
-  AS_TYPE_MO_CS_FALLBACK      = NET_ESTABLISH_TYPE_MO_CS_FALLBACK
-} as_call_type_t;
-
-/*
- * NAS->AS - NAS signalling connection establishment request
- * NAS requests the AS to perform the RRC connection establishment procedure
- * to transfer initial NAS message to the network while UE is in IDLE mode.
- */
-typedef struct nas_establish_req_s {
-  as_cause_t      cause;          /* RRC connection establishment cause   */
-  as_call_type_t  type;           /* RRC associated call type             */
-  as_stmsi_t      s_tmsi;         /* UE identity                          */
-  plmn_t          plmnID;         /* Selected PLMN identity               */
-  as_nas_info_t   initialNasMsg;  /* Initial NAS message to transfer      */
-} nas_establish_req_t;
-
-/*
- * AS->NAS - NAS signalling connection establishment indication
- * AS transfers the initial NAS message to the NAS.
- */
-typedef struct nas_establish_ind_s {
-  uint32_t      UEid;          /* UE lower layer identifier               */
-  tac_t         tac;           /* Code of the tracking area the initiating
-                                  * UE belongs to                           */
-  as_cause_t    asCause;       /* Establishment cause                     */
-  as_nas_info_t initialNasMsg; /* Initial NAS message to transfer         */
-} nas_establish_ind_t;
-
-/*
- * NAS->AS - NAS signalling connection establishment response
- * NAS responds to the AS that initial answer message has to be provided to
- * the UE.
- */
-typedef struct nas_establish_rsp_s {
-  uint32_t         UEid;         /* UE lower layer identifier   */
-  as_stmsi_t       s_tmsi;       /* UE identity                 */
-  nas_error_code_t errCode;      /* Transaction status          */
-  as_nas_info_t    nasMsg;       /* NAS message to transfer     */
-  uint32_t         nas_ul_count; /* UL NAS COUNT                */
-  uint16_t         selected_encryption_algorithm;
-  uint16_t         selected_integrity_algorithm;
-} nas_establish_rsp_t;
-
-/*
- * AS->NAS - NAS signalling connection establishment confirm
- * AS transfers the initial answer message to the NAS.
- */
-typedef struct nas_establish_cnf_s {
-  uint32_t         UEid;            /* UE lower layer identifier   */
-  nas_error_code_t errCode;         /* Transaction status          */
-  as_nas_info_t    nasMsg;          /* NAS message to transfer     */
-  uint32_t         ul_nas_count;
-  uint16_t         selected_encryption_algorithm;
-  uint16_t         selected_integrity_algorithm;
-} nas_establish_cnf_t;
-
-/*
- * --------------------------------------------------------------------------
- *          NAS signalling connection release
- * --------------------------------------------------------------------------
- */
-
-/* Release cause */
-typedef enum release_cause_s {
-  AS_AUTHENTICATION_FAILURE = 1,  /* Authentication procedure failed   */
-  AS_DETACH                       /* Detach requested                  */
-} release_cause_t;
-
-/*
- * NAS->AS - NAS signalling connection release request
- * NAS requests the termination of the connection with the UE.
- */
-typedef struct nas_release_req_s {
-  uint32_t UEid;          /* UE lower layer identifier    */
-  as_stmsi_t s_tmsi;      /* UE identity                  */
-  release_cause_t cause;  /* Release cause                */
-} nas_release_req_t;
-
-/*
- * AS->NAS - NAS signalling connection release indication
- * AS reports that connection has been terminated by the network.
- */
-typedef struct nas_release_ind_s {
-  release_cause_t cause;      /* Release cause            */
-} nas_release_ind_t;
-
-/*
- * --------------------------------------------------------------------------
- *              NAS information transfer
- * --------------------------------------------------------------------------
- */
-
-/*
- * NAS->AS - Uplink data transfer request
- * NAS requests the AS to transfer uplink information to the NAS that
- * operates at the network side.
- */
-typedef struct ul_info_transfer_req_s {
-  uint32_t UEid;      /* UE lower layer identifier        */
-  as_stmsi_t s_tmsi;      /* UE identity              */
-  as_nas_info_t nasMsg;   /* Uplink NAS message           */
-} ul_info_transfer_req_t;
-
-/*
- * AS->NAS - Uplink data transfer confirm
- * AS immediately notifies the NAS whether uplink information has been
- * successfully sent to the network or not.
- */
-typedef struct ul_info_transfer_cnf_s {
-  uint32_t         UEid;      /* UE lower layer identifier        */
-  nas_error_code_t errCode;   /* Transaction status               */
-} ul_info_transfer_cnf_t;
-
-/*
- * AS->NAS - Uplink data transfer indication
- * AS delivers the uplink information message to the NAS that operates
- * at the network side.
- */
-typedef struct ul_info_transfer_ind_s {
-  uint32_t UEid;          /* UE lower layer identifier        */
-  as_nas_info_t nasMsg;   /* Uplink NAS message           */
-} ul_info_transfer_ind_t;
-
-/*
- * NAS->AS - Downlink data transfer request
- * NAS requests the AS to transfer downlink information to the NAS that
- * operates at the UE side.
- */
-typedef ul_info_transfer_req_t dl_info_transfer_req_t;
-
-/*
- * AS->NAS - Downlink data transfer confirm
- * AS immediately notifies the NAS whether downlink information has been
- * successfully sent to the network or not.
- */
-typedef ul_info_transfer_cnf_t dl_info_transfer_cnf_t;
-
-/*
- * AS->NAS - Downlink data transfer indication
- * AS delivers the downlink information message to the NAS that operates
- * at the UE side.
- */
-typedef ul_info_transfer_ind_t dl_info_transfer_ind_t;
-
-/*
- * --------------------------------------------------------------------------
- *          Radio Access Bearer establishment
- * --------------------------------------------------------------------------
- */
-
-/* TODO: Quality of Service parameters */
-typedef struct {} as_qos_t;
-
-/*
- * NAS->AS - Radio access bearer establishment request
- * NAS requests the AS to allocate transmission resources to radio access
- * bearer initialized at the network side.
- */
-typedef struct rab_establish_req_s {
-  as_stmsi_t s_tmsi;      /* UE identity                      */
-  as_rab_id_t rabID;      /* Radio access bearer identity     */
-  as_qos_t QoS;           /* Requested Quality of Service     */
-} rab_establish_req_t;
-
-/*
- * AS->NAS - Radio access bearer establishment indication
- * AS notifies the NAS that specific radio access bearer has to be setup.
- */
-typedef struct rab_establish_ind_s {
-  as_rab_id_t rabID;      /* Radio access bearer identity     */
-} rab_establish_ind_t;
-
-/*
- * NAS->AS - Radio access bearer establishment response
- * NAS responds to AS whether the specified radio access bearer has been
- * successfully setup or not.
- */
-typedef struct rab_establish_rsp_s {
-  as_stmsi_t       s_tmsi;        /* UE identity                      */
-  as_rab_id_t      rabID;         /* Radio access bearer identity     */
-  nas_error_code_t errCode;       /* Transaction status               */
-} rab_establish_rsp_t;
-
-/*
- * AS->NAS - Radio access bearer establishment confirm
- * AS notifies NAS whether the specified radio access bearer has been
- * successfully setup at the UE side or not.
- */
-typedef struct rab_establish_cnf_s {
-  as_rab_id_t rabID;          /* Radio access bearer identity     */
-  nas_error_code_t errCode;   /* Transaction status               */
-} rab_establish_cnf_t;
-
-/*
- * --------------------------------------------------------------------------
- *              Radio Access Bearer release
- * --------------------------------------------------------------------------
- */
-
-/*
- * NAS->AS - Radio access bearer release request
- * NAS requests the AS to release transmission resources previously allocated
- * to specific radio access bearer at the network side.
- */
-typedef struct rab_release_req_s {
-  as_stmsi_t s_tmsi;      /* UE identity                      */
-  as_rab_id_t rabID;      /* Radio access bearer identity     */
-} rab_release_req_t;
-
-/*
- * AS->NAS - Radio access bearer release indication
- * AS notifies NAS that specific radio access bearer has been released.
- */
-typedef struct rab_release_ind_s {
-  as_rab_id_t rabID;      /* Radio access bearer identity     */
-} rab_release_ind_t;
-
-/*
- * --------------------------------------------------------------------------
- *  Structure of the AS messages handled by the network sublayer
- * --------------------------------------------------------------------------
- */
-typedef struct as_message_s {
-  uint16_t msgID;
-  union {
-    broadcast_info_ind_t broadcast_info_ind;
-    cell_info_req_t cell_info_req;
-    cell_info_cnf_t cell_info_cnf;
-    cell_info_ind_t cell_info_ind;
-    paging_req_t paging_req;
-    paging_ind_t paging_ind;
-    nas_establish_req_t nas_establish_req;
-    nas_establish_ind_t nas_establish_ind;
-    nas_establish_rsp_t nas_establish_rsp;
-    nas_establish_cnf_t nas_establish_cnf;
-    nas_release_req_t nas_release_req;
-    nas_release_ind_t nas_release_ind;
-    ul_info_transfer_req_t ul_info_transfer_req;
-    ul_info_transfer_cnf_t ul_info_transfer_cnf;
-    ul_info_transfer_ind_t ul_info_transfer_ind;
-    dl_info_transfer_req_t dl_info_transfer_req;
-    dl_info_transfer_cnf_t dl_info_transfer_cnf;
-    dl_info_transfer_ind_t dl_info_transfer_ind;
-    rab_establish_req_t rab_establish_req;
-    rab_establish_ind_t rab_establish_ind;
-    rab_establish_rsp_t rab_establish_rsp;
-    rab_establish_cnf_t rab_establish_cnf;
-    rab_release_req_t rab_release_req;
-    rab_release_ind_t rab_release_ind;
-  } __attribute__((__packed__)) msg;
-} as_message_t;
-
-/****************************************************************************/
-/********************  G L O B A L    V A R I A B L E S  ********************/
-/****************************************************************************/
-
-/****************************************************************************/
-/******************  E X P O R T E D    F U N C T I O N S  ******************/
-/****************************************************************************/
-
-int as_message_decode(const char* buffer, as_message_t* msg, int length);
-
-int as_message_encode(char* buffer, as_message_t* msg, int length);
-
-/* Implemented in the network_api.c body file */
-int as_message_send(as_message_t* as_msg);
-
-#endif /* __AS_MESSAGE_H__*/
diff --git a/openair3/COMMON/gtpv1_u_messages_def.h b/openair3/COMMON/gtpv1_u_messages_def.h
deleted file mode 100644
index 4308853515aac828a59e3fec050507d80a48adde..0000000000000000000000000000000000000000
--- a/openair3/COMMON/gtpv1_u_messages_def.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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
- */
-
-MESSAGE_DEF(GTPV1U_CREATE_TUNNEL_REQ,   MESSAGE_PRIORITY_MED, Gtpv1uCreateTunnelReq,  gtpv1uCreateTunnelReq)
-MESSAGE_DEF(GTPV1U_CREATE_TUNNEL_RESP,  MESSAGE_PRIORITY_MED, Gtpv1uCreateTunnelResp, gtpv1uCreateTunnelResp)
-MESSAGE_DEF(GTPV1U_UPDATE_TUNNEL_REQ,   MESSAGE_PRIORITY_MED, Gtpv1uUpdateTunnelReq,  gtpv1uUpdateTunnelReq)
-MESSAGE_DEF(GTPV1U_UPDATE_TUNNEL_RESP,  MESSAGE_PRIORITY_MED, Gtpv1uUpdateTunnelResp, gtpv1uUpdateTunnelResp)
-MESSAGE_DEF(GTPV1U_DELETE_TUNNEL_REQ,   MESSAGE_PRIORITY_MED, Gtpv1uDeleteTunnelReq,  gtpv1uDeleteTunnelReq)
-MESSAGE_DEF(GTPV1U_DELETE_TUNNEL_RESP,  MESSAGE_PRIORITY_MED, Gtpv1uDeleteTunnelResp, gtpv1uDeleteTunnelResp)
-MESSAGE_DEF(GTPV1U_TUNNEL_DATA_IND,     MESSAGE_PRIORITY_MED, Gtpv1uTunnelDataInd,    gtpv1uTunnelDataInd)
-MESSAGE_DEF(GTPV1U_TUNNEL_DATA_REQ,     MESSAGE_PRIORITY_MED, Gtpv1uTunnelDataReq,    gtpv1uTunnelDataReq)
diff --git a/openair3/COMMON/gtpv1_u_messages_types.h b/openair3/COMMON/gtpv1_u_messages_types.h
deleted file mode 100644
index 594325647b255092af0274c2d41bdbffc9a7d3b6..0000000000000000000000000000000000000000
--- a/openair3/COMMON/gtpv1_u_messages_types.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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 GTPV1_U_MESSAGES_TYPES_H_
-#define GTPV1_U_MESSAGES_TYPES_H_
-
-#include "../SGW-LITE/sgw_lite_ie_defs.h"
-
-typedef struct {
-  Teid_t           context_teid;               ///< Tunnel Endpoint Identifier
-  ebi_t            eps_bearer_id;
-} Gtpv1uCreateTunnelReq;
-
-typedef struct {
-  uint8_t  status;           ///< Status of S1U endpoint creation (Failed = 0xFF or Success = 0x0)
-  Teid_t   context_teid;     ///< local SGW S11 Tunnel Endpoint Identifier
-  Teid_t   S1u_teid;         ///< Tunnel Endpoint Identifier
-  ebi_t    eps_bearer_id;
-} Gtpv1uCreateTunnelResp;
-
-typedef struct {
-  Teid_t           context_teid;     ///< S11 Tunnel Endpoint Identifier
-  Teid_t           sgw_S1u_teid;     ///< SGW S1U local Tunnel Endpoint Identifier
-  Teid_t           enb_S1u_teid;     ///< eNB S1U Tunnel Endpoint Identifier
-  ip_address_t     enb_ip_address_for_S1u;
-  ebi_t            eps_bearer_id;
-} Gtpv1uUpdateTunnelReq;
-
-typedef struct {
-  uint8_t          status;           ///< Status (Failed = 0xFF or Success = 0x0)
-  Teid_t           context_teid;     ///< S11 Tunnel Endpoint Identifier
-  Teid_t           sgw_S1u_teid;     ///< SGW S1U local Tunnel Endpoint Identifier
-  Teid_t           enb_S1u_teid;     ///< eNB S1U Tunnel Endpoint Identifier
-  ebi_t            eps_bearer_id;
-} Gtpv1uUpdateTunnelResp;
-
-typedef struct {
-  Teid_t           context_teid;   ///< local SGW S11 Tunnel Endpoint Identifier
-  Teid_t           S1u_teid;       ///< local S1U Tunnel Endpoint Identifier to be deleted
-} Gtpv1uDeleteTunnelReq;
-
-typedef struct {
-  uint8_t  status;           ///< Status of S1U endpoint deleteion (Failed = 0xFF or Success = 0x0)
-  Teid_t   context_teid;     ///< local SGW S11 Tunnel Endpoint Identifier
-  Teid_t   S1u_teid;         ///< local S1U Tunnel Endpoint Identifier to be deleted
-} Gtpv1uDeleteTunnelResp;
-
-typedef struct {
-  uint8_t  *buffer;
-  uint32_t  length;
-  uint32_t  offset;                       ///< start of message offset in buffer
-  Teid_t    local_S1u_teid;               ///< Tunnel Endpoint Identifier
-} Gtpv1uTunnelDataInd;
-
-typedef struct {
-  uint8_t  *buffer;
-  uint32_t  length;
-  uint32_t  offset;                       ///< start of message offset in buffer
-  Teid_t    local_S1u_teid;               ///< Tunnel Endpoint Identifier
-  Teid_t    S1u_enb_teid;                 ///< Tunnel Endpoint Identifier
-} Gtpv1uTunnelDataReq;
-
-#endif /* GTPV1_U_MESSAGES_TYPES_H_ */
diff --git a/openair3/COMMON/messages_def.h b/openair3/COMMON/messages_def.h
deleted file mode 100644
index 1c1cdbaf0f0dc32476c35e3e51f416de52899bdc..0000000000000000000000000000000000000000
--- a/openair3/COMMON/messages_def.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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
- */
-
-// These messages files are mandatory and must always be placed in first position
-#include "intertask_messages_def.h"
-#include "timer_messages_def.h"
-
-// Messages files used between tasks
-#include "gtpv1_u_messages_def.h"
-#include "ip_forward_messages_def.h"
-#include "nas_messages_def.h"
-#include "s11_messages_def.h"
-#include "s1ap_messages_def.h"
-#include "s6a_messages_def.h"
-#include "sctp_messages_def.h"
-#include "sgw_lite_def.h"
-#include "udp_messages_def.h"
-#include "mme_app_messages_def.h"
diff --git a/openair3/COMMON/nas_messages_def.h b/openair3/COMMON/nas_messages_def.h
deleted file mode 100644
index 9bdcde4fdf06293338e7ef8659776b2a0fffaec1..0000000000000000000000000000000000000000
--- a/openair3/COMMON/nas_messages_def.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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
- */
-
-//WARNING: Do not include this header directly. Use intertask_interface.h instead.
-
-// Messages for NAS logging
-MESSAGE_DEF(NAS_DL_EMM_RAW_MSG,                 MESSAGE_PRIORITY_MED,   nas_raw_msg_t,              nas_dl_emm_raw_msg)
-MESSAGE_DEF(NAS_UL_EMM_RAW_MSG,                 MESSAGE_PRIORITY_MED,   nas_raw_msg_t,              nas_ul_emm_raw_msg)
-
-MESSAGE_DEF(NAS_DL_EMM_PLAIN_MSG,               MESSAGE_PRIORITY_MED,   nas_emm_plain_msg_t,        nas_dl_emm_plain_msg)
-MESSAGE_DEF(NAS_UL_EMM_PLAIN_MSG,               MESSAGE_PRIORITY_MED,   nas_emm_plain_msg_t,        nas_ul_emm_plain_msg)
-MESSAGE_DEF(NAS_DL_EMM_PROTECTED_MSG,           MESSAGE_PRIORITY_MED,   nas_emm_protected_msg_t,    nas_dl_emm_protected_msg)
-MESSAGE_DEF(NAS_UL_EMM_PROTECTED_MSG,           MESSAGE_PRIORITY_MED,   nas_emm_protected_msg_t,    nas_ul_emm_protected_msg)
-
-MESSAGE_DEF(NAS_DL_ESM_RAW_MSG,                 MESSAGE_PRIORITY_MED,   nas_raw_msg_t,              nas_dl_esm_raw_msg)
-MESSAGE_DEF(NAS_UL_ESM_RAW_MSG,                 MESSAGE_PRIORITY_MED,   nas_raw_msg_t,              nas_ul_esm_raw_msg)
-
-MESSAGE_DEF(NAS_DL_ESM_PLAIN_MSG,               MESSAGE_PRIORITY_MED,   nas_esm_plain_msg_t,        nas_dl_esm_plain_msg)
-MESSAGE_DEF(NAS_UL_ESM_PLAIN_MSG,               MESSAGE_PRIORITY_MED,   nas_esm_plain_msg_t,        nas_ul_esm_plain_msg)
-MESSAGE_DEF(NAS_DL_ESM_PROTECTED_MSG,           MESSAGE_PRIORITY_MED,   nas_esm_protected_msg_t,    nas_dl_esm_protected_msg)
-MESSAGE_DEF(NAS_UL_ESM_PROTECTED_MSG,           MESSAGE_PRIORITY_MED,   nas_esm_protected_msg_t,    nas_ul_esm_protected_msg)
-
-/* */
-MESSAGE_DEF(NAS_PAGING_IND,                     MESSAGE_PRIORITY_MED,   nas_paging_ind_t,           nas_paging_ind)
-MESSAGE_DEF(NAS_PDN_CONNECTIVITY_REQ,           MESSAGE_PRIORITY_MED,   nas_pdn_connectivity_req_t, nas_pdn_connectivity_req)
-MESSAGE_DEF(NAS_CONNECTION_ESTABLISHMENT_IND,   MESSAGE_PRIORITY_MED,   nas_conn_est_ind_t,         nas_conn_est_ind)
-MESSAGE_DEF(NAS_CONNECTION_ESTABLISHMENT_CNF,   MESSAGE_PRIORITY_MED,   nas_conn_est_cnf_t,         nas_conn_est_cnf)
-MESSAGE_DEF(NAS_CONNECTION_RELEASE_IND,         MESSAGE_PRIORITY_MED,   nas_conn_rel_ind_t,         nas_conn_rel_ind)
-MESSAGE_DEF(NAS_UPLINK_DATA_IND,                MESSAGE_PRIORITY_MED,   nas_ul_data_ind_t,          nas_ul_data_ind)
-MESSAGE_DEF(NAS_DOWNLINK_DATA_REQ,              MESSAGE_PRIORITY_MED,   nas_dl_data_req_t,          nas_dl_data_req)
-MESSAGE_DEF(NAS_DOWNLINK_DATA_CNF,              MESSAGE_PRIORITY_MED,   nas_dl_data_cnf_t,          nas_dl_data_cnf)
-MESSAGE_DEF(NAS_DOWNLINK_DATA_REJ,              MESSAGE_PRIORITY_MED,   nas_dl_data_rej_t,          nas_dl_data_rej)
-MESSAGE_DEF(NAS_RAB_ESTABLISHMENT_REQ,          MESSAGE_PRIORITY_MED,   nas_rab_est_req_t,          nas_rab_est_req)
-MESSAGE_DEF(NAS_RAB_ESTABLISHMENT_RESP,         MESSAGE_PRIORITY_MED,   nas_rab_est_rsp_t,          nas_rab_est_rsp)
-MESSAGE_DEF(NAS_RAB_RELEASE_REQ,                MESSAGE_PRIORITY_MED,   nas_rab_rel_req_t,          nas_rab_rel_req)
-
-/* NAS layer -> MME app messages */
-MESSAGE_DEF(NAS_AUTHENTICATION_PARAM_REQ,       MESSAGE_PRIORITY_MED,   nas_auth_param_req_t,       nas_auth_param_req)
-
-/* MME app -> NAS layer messages */
-MESSAGE_DEF(NAS_PDN_CONNECTIVITY_RSP,           MESSAGE_PRIORITY_MED,   nas_pdn_connectivity_rsp_t,  nas_pdn_connectivity_rsp)
-MESSAGE_DEF(NAS_PDN_CONNECTIVITY_FAIL,          MESSAGE_PRIORITY_MED,   nas_pdn_connectivity_fail_t, nas_pdn_connectivity_fail)
-MESSAGE_DEF(NAS_AUTHENTICATION_PARAM_RSP,       MESSAGE_PRIORITY_MED,   nas_auth_param_rsp_t,        nas_auth_param_rsp)
-MESSAGE_DEF(NAS_AUTHENTICATION_PARAM_FAIL,      MESSAGE_PRIORITY_MED,   nas_auth_param_fail_t,       nas_auth_param_fail)
-
diff --git a/openair3/COMMON/nas_messages_types.h b/openair3/COMMON/nas_messages_types.h
deleted file mode 100644
index 81a44fa4f4c42fe476822ca3d1f879f5468c4f6c..0000000000000000000000000000000000000000
--- a/openair3/COMMON/nas_messages_types.h
+++ /dev/null
@@ -1,329 +0,0 @@
-/*
- * 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 "as_message.h"
-#include "nas_message.h"
-
-#ifndef NAS_MESSAGES_TYPES_H_
-#define NAS_MESSAGES_TYPES_H_
-
-#define NAS_DL_EMM_RAW_MSG(mSGpTR)                  (mSGpTR)->ittiMsg.nas_dl_emm_raw_msg
-#define NAS_UL_EMM_RAW_MSG(mSGpTR)                  (mSGpTR)->ittiMsg.nas_ul_emm_raw_msg
-
-#define NAS_DL_EMM_PROTECTED_MSG(mSGpTR)            (mSGpTR)->ittiMsg.nas_dl_emm_protected_msg
-#define NAS_UL_EMM_PROTECTED_MSG(mSGpTR)            (mSGpTR)->ittiMsg.nas_ul_emm_protected_msg
-#define NAS_DL_EMM_PLAIN_MSG(mSGpTR)                (mSGpTR)->ittiMsg.nas_dl_emm_plain_msg
-#define NAS_UL_EMM_PLAIN_MSG(mSGpTR)                (mSGpTR)->ittiMsg.nas_ul_emm_plain_msg
-
-#define NAS_DL_ESM_RAW_MSG(mSGpTR)                  (mSGpTR)->ittiMsg.nas_dl_esm_raw_msg
-#define NAS_UL_ESM_RAW_MSG(mSGpTR)                  (mSGpTR)->ittiMsg.nas_ul_esm_raw_msg
-
-#define NAS_DL_ESM_PROTECTED_MSG(mSGpTR)            (mSGpTR)->ittiMsg.nas_dl_esm_protected_msg
-#define NAS_UL_ESM_PROTECTED_MSG(mSGpTR)            (mSGpTR)->ittiMsg.nas_ul_esm_protected_msg
-#define NAS_DL_ESM_PLAIN_MSG(mSGpTR)                (mSGpTR)->ittiMsg.nas_dl_esm_plain_msg
-#define NAS_UL_ESM_PLAIN_MSG(mSGpTR)                (mSGpTR)->ittiMsg.nas_ul_esm_plain_msg
-
-#define NAS_UL_DATA_IND(mSGpTR)                     (mSGpTR)->ittiMsg.nas_ul_data_ind
-#define NAS_DL_DATA_REQ(mSGpTR)                     (mSGpTR)->ittiMsg.nas_dl_data_req
-#define NAS_DL_DATA_CNF(mSGpTR)                     (mSGpTR)->ittiMsg.nas_dl_data_cnf
-#define NAS_DL_DATA_REJ(mSGpTR)                     (mSGpTR)->ittiMsg.nas_dl_data_rej
-#define NAS_PDN_CONNECTIVITY_REQ(mSGpTR)            (mSGpTR)->ittiMsg.nas_pdn_connectivity_req
-#define NAS_PDN_CONNECTIVITY_RSP(mSGpTR)            (mSGpTR)->ittiMsg.nas_pdn_connectivity_rsp
-#define NAS_PDN_CONNECTIVITY_FAIL(mSGpTR)           (mSGpTR)->ittiMsg.nas_pdn_connectivity_fail
-#define NAS_CONN_EST_IND(mSGpTR)                    (mSGpTR)->ittiMsg.nas_conn_est_ind
-#define NAS_CONNECTION_ESTABLISHMENT_CNF(mSGpTR)    (mSGpTR)->ittiMsg.nas_conn_est_cnf
-#define NAS_BEARER_PARAM(mSGpTR)                    (mSGpTR)->ittiMsg.nas_bearer_param
-#define NAS_AUTHENTICATION_REQ(mSGpTR)              (mSGpTR)->ittiMsg.nas_auth_req
-#define NAS_AUTHENTICATION_PARAM_REQ(mSGpTR)        (mSGpTR)->ittiMsg.nas_auth_param_req
-#define NAS_AUTHENTICATION_PARAM_RSP(mSGpTR)        (mSGpTR)->ittiMsg.nas_auth_param_rsp
-#define NAS_AUTHENTICATION_PARAM_FAIL(mSGpTR)       (mSGpTR)->ittiMsg.nas_auth_param_fail
-
-#define NAS_DATA_LENGHT_MAX     256
-
-
-
-typedef enum {
-  EMM_MSG_HEADER = 1,
-  EMM_MSG_ATTACH_REQUEST,
-  EMM_MSG_ATTACH_ACCEPT,
-  EMM_MSG_ATTACH_COMPLETE,
-  EMM_MSG_ATTACH_REJECT,
-  EMM_MSG_DETACH_REQUEST,
-  EMM_MSG_DETACH_ACCEPT,
-  EMM_MSG_TRACKING_AREA_UPDATE_REQUEST,
-  EMM_MSG_TRACKING_AREA_UPDATE_ACCEPT,
-  EMM_MSG_TRACKING_AREA_UPDATE_COMPLETE,
-  EMM_MSG_TRACKING_AREA_UPDATE_REJECT,
-  EMM_MSG_EXTENDED_SERVICE_REQUEST,
-  EMM_MSG_SERVICE_REQUEST,
-  EMM_MSG_SERVICE_REJECT,
-  EMM_MSG_GUTI_REALLOCATION_COMMAND,
-  EMM_MSG_GUTI_REALLOCATION_COMPLETE,
-  EMM_MSG_AUTHENTICATION_REQUEST,
-  EMM_MSG_AUTHENTICATION_RESPONSE,
-  EMM_MSG_AUTHENTICATION_REJECT,
-  EMM_MSG_AUTHENTICATION_FAILURE,
-  EMM_MSG_IDENTITY_REQUEST,
-  EMM_MSG_IDENTITY_RESPONSE,
-  EMM_MSG_SECURITY_MODE_COMMAND,
-  EMM_MSG_SECURITY_MODE_COMPLETE,
-  EMM_MSG_SECURITY_MODE_REJECT,
-  EMM_MSG_EMM_STATUS,
-  EMM_MSG_EMM_INFORMATION,
-  EMM_MSG_DOWNLINK_NAS_TRANSPORT,
-  EMM_MSG_UPLINK_NAS_TRANSPORT,
-  EMM_MSG_CS_SERVICE_NOTIFICATION,
-} emm_message_ids_t;
-
-
-
-typedef enum {
-  ESM_MSG_HEADER = 1,
-  ESM_MSG_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST,
-  ESM_MSG_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_ACCEPT,
-  ESM_MSG_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REJECT,
-  ESM_MSG_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_REQUEST,
-  ESM_MSG_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_ACCEPT,
-  ESM_MSG_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_REJECT,
-  ESM_MSG_MODIFY_EPS_BEARER_CONTEXT_REQUEST,
-  ESM_MSG_MODIFY_EPS_BEARER_CONTEXT_ACCEPT,
-  ESM_MSG_MODIFY_EPS_BEARER_CONTEXT_REJECT,
-  ESM_MSG_DEACTIVATE_EPS_BEARER_CONTEXT_REQUEST,
-  ESM_MSG_DEACTIVATE_EPS_BEARER_CONTEXT_ACCEPT,
-  ESM_MSG_PDN_CONNECTIVITY_REQUEST,
-  ESM_MSG_PDN_CONNECTIVITY_REJECT,
-  ESM_MSG_PDN_DISCONNECT_REQUEST,
-  ESM_MSG_PDN_DISCONNECT_REJECT,
-  ESM_MSG_BEARER_RESOURCE_ALLOCATION_REQUEST,
-  ESM_MSG_BEARER_RESOURCE_ALLOCATION_REJECT,
-  ESM_MSG_BEARER_RESOURCE_MODIFICATION_REQUEST,
-  ESM_MSG_BEARER_RESOURCE_MODIFICATION_REJECT,
-  ESM_MSG_ESM_INFORMATION_REQUEST,
-  ESM_MSG_ESM_INFORMATION_RESPONSE,
-  ESM_MSG_ESM_STATUS,
-} esm_message_ids_t;
-
-
-
-typedef struct nas_raw_msg_s {
-  uint32_t                        lenght;
-  uint8_t                         data[NAS_DATA_LENGHT_MAX];
-} nas_raw_msg_t;
-
-
-
-typedef struct nas_emm_plain_msg_s {
-  emm_message_ids_t               present;
-  EMM_msg                         choice;
-
-} nas_emm_plain_msg_t;
-
-
-
-typedef struct nas_emm_protected_msg_s {
-  nas_message_security_header_t   header;
-  emm_message_ids_t               present;
-  EMM_msg                         choice;
-} nas_emm_protected_msg_t;
-
-
-typedef struct nas_esm_plain_msg_s {
-  esm_message_ids_t               present;
-  ESM_msg                         choice;
-
-} nas_esm_plain_msg_t;
-
-
-typedef struct nas_esm_protected_msg_s {
-  nas_message_security_header_t   header;
-  esm_message_ids_t               present;
-  ESM_msg                         choice;
-} nas_esm_protected_msg_t;
-
-
-typedef struct nas_paging_ind_s {
-
-} nas_paging_ind_t;
-
-
-typedef struct nas_pdn_connectivity_req_s {
-  int                    pti;   // nas ref  Identity of the procedure transaction executed to activate the PDN connection entry
-  unsigned               ue_id; // nas ref
-  char                   imsi[16];
-  uint8_t                imsi_length;
-  network_qos_t          qos;
-  pco_flat_t             pco;
-  OctetString            apn;
-  OctetString            pdn_addr;
-  int                    pdn_type;
-  void                  *proc_data;
-  int                    request_type;
-} nas_pdn_connectivity_req_t;
-
-
-typedef struct nas_pdn_connectivity_rsp_s {
-  int                     pti;   // nas ref  Identity of the procedure transaction executed to activate the PDN connection entry
-  unsigned                ue_id; // nas ref
-  network_qos_t           qos;
-  pco_flat_t              pco;
-  OctetString             apn;
-  OctetString             pdn_addr;
-  int                     pdn_type;
-  void                   *proc_data;
-  int                     request_type;
-
-  unsigned                eNB_ue_s1ap_id:24;
-  uint32_t                mme_ue_s1ap_id;
-
-  /* Key eNB */
-  //uint8_t                 keNB[32];
-
-  ambr_t                  ambr;
-  ambr_t                  apn_ambr;
-
-  /* EPS bearer ID */
-  unsigned                ebi:4;
-
-  /* QoS */
-  qci_t                   qci;
-  priority_level_t        prio_level;
-  pre_emp_vulnerability_t pre_emp_vulnerability;
-  pre_emp_capability_t    pre_emp_capability;
-
-  /* S-GW TEID for user-plane */
-  Teid_t                  sgw_s1u_teid;
-  /* S-GW IP address for User-Plane */
-  ip_address_t            sgw_s1u_address;
-} nas_pdn_connectivity_rsp_t;
-
-
-typedef struct nas_pdn_connectivity_fail_s {
-  unsigned                ue_id; // nas ref
-} nas_pdn_connectivity_fail_t;
-
-
-typedef struct nas_conn_est_ind_s {
-  nas_establish_ind_t nas;
-
-  /* Transparent message from s1ap to be forwarded to MME_APP or
-   * to S1AP if connection establishment is rejected by NAS.
-   */
-  s1ap_initial_ue_message_t transparent;
-} nas_conn_est_ind_t;
-
-
-typedef nas_establish_rsp_t nas_conn_est_rej_t;
-
-
-typedef nas_establish_cnf_t nas_conn_est_cnf_t;
-
-
-typedef struct nas_conn_rel_ind_s {
-
-} nas_conn_rel_ind_t;
-
-typedef ul_info_transfer_ind_t nas_ul_data_ind_t;
-typedef dl_info_transfer_req_t nas_dl_data_req_t;
-typedef dl_info_transfer_cnf_t nas_dl_data_cnf_t;
-
-
-typedef struct nas_dl_data_rej_s {
-	uint32_t UEid;          /* UE lower layer identifier        */
-	  as_nas_info_t nasMsg;   /* Uplink NAS message           */
-} nas_dl_data_rej_t;
-
-typedef struct nas_rab_est_req_s {
-
-} nas_rab_est_req_t;
-
-
-typedef struct nas_rab_est_rsp_s {
-
-} nas_rab_est_rsp_t;
-
-
-typedef struct nas_rab_rel_req_s {
-
-} nas_rab_rel_req_t;
-
-
-typedef struct nas_attach_req_s {
-  /* TODO: Set the correct size */
-  char apn[100];
-  char imsi[16];
-#define INITIAL_REQUEST (0x1)
-  unsigned initial:1;
-  s1ap_initial_ue_message_t transparent;
-} nas_attach_req_t;
-
-
-typedef struct nas_auth_req_s {
-  /* UE imsi */
-  char imsi[16];
-
-#define NAS_FAILURE_OK  0x0
-#define NAS_FAILURE_IND 0x1
-  unsigned failure:1;
-  int cause;
-} nas_auth_req_t;
-
-
-typedef struct nas_auth_resp_s {
-  char imsi[16];
-} nas_auth_resp_t;
-
-typedef struct nas_auth_param_req_s {
-  /* UE identifier */
-  uint32_t ue_id;
-
-  /* Imsi of the UE (In case of initial request) */
-  char     imsi[16];
-  uint8_t  imsi_length;
-
-  /* Indicates whether the procedure corresponds to a new connection or not */
-  uint8_t  initial_req:1;
-
-  uint8_t  re_synchronization:1;
-  uint8_t  auts[14];
-} nas_auth_param_req_t;
-
-
-typedef struct nas_auth_param_rsp_s {
-  /* UE identifier */
-  uint32_t ue_id;
-
-  /* For future use: nb of vectors provided */
-  uint8_t nb_vectors;
-
-  /* Consider only one E-UTRAN vector for the moment... */
-  eutran_vector_t vector;
-} nas_auth_param_rsp_t;
-
-typedef struct nas_auth_param_fail_s {
-  /* UE identifier */
-  uint32_t    ue_id;
-
-  /* S6A mapped to NAS cause */
-  nas_cause_t cause;
-} nas_auth_param_fail_t;
-
-
-#endif /* NAS_MESSAGES_TYPES_H_ */
diff --git a/openair3/COMMON/s1ap_messages_def.h b/openair3/COMMON/s1ap_messages_def.h
deleted file mode 100644
index ffb9aa4236f5fdab4f711db12e4c5580953b433e..0000000000000000000000000000000000000000
--- a/openair3/COMMON/s1ap_messages_def.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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
- */
-
-//WARNING: Do not include this header directly. Use intertask_interface.h instead.
-
-/* Messages for S1AP logging */
-MESSAGE_DEF(S1AP_UPLINK_NAS_LOG            , MESSAGE_PRIORITY_MED, IttiMsgText                      , s1ap_uplink_nas_log)
-MESSAGE_DEF(S1AP_UE_CAPABILITY_IND_LOG     , MESSAGE_PRIORITY_MED, IttiMsgText                      , s1ap_ue_capability_ind_log)
-MESSAGE_DEF(S1AP_INITIAL_CONTEXT_SETUP_LOG , MESSAGE_PRIORITY_MED, IttiMsgText                      , s1ap_initial_context_setup_log)
-MESSAGE_DEF(S1AP_NAS_NON_DELIVERY_IND_LOG  , MESSAGE_PRIORITY_MED, IttiMsgText                      , s1ap_nas_non_delivery_ind_log)
-MESSAGE_DEF(S1AP_DOWNLINK_NAS_LOG          , MESSAGE_PRIORITY_MED, IttiMsgText                      , s1ap_downlink_nas_log)
-MESSAGE_DEF(S1AP_S1_SETUP_LOG              , MESSAGE_PRIORITY_MED, IttiMsgText                      , s1ap_s1_setup_log)
-MESSAGE_DEF(S1AP_INITIAL_UE_MESSAGE_LOG    , MESSAGE_PRIORITY_MED, IttiMsgText                      , s1ap_initial_ue_message_log)
-MESSAGE_DEF(S1AP_UE_CONTEXT_RELEASE_REQ_LOG, MESSAGE_PRIORITY_MED, IttiMsgText                      , s1ap_ue_context_release_req_log)
-MESSAGE_DEF(S1AP_UE_CONTEXT_RELEASE_COMMAND_LOG, MESSAGE_PRIORITY_MED, IttiMsgText                  , s1ap_ue_context_release_command_log)
-MESSAGE_DEF(S1AP_UE_CONTEXT_RELEASE_LOG    , MESSAGE_PRIORITY_MED, IttiMsgText                      , s1ap_ue_context_release_log)
-MESSAGE_DEF(S1AP_ERROR_INDICATION_LOG      , MESSAGE_PRIORITY_MED, IttiMsgText                      , s1ap_error_indication_log)
-
-MESSAGE_DEF(S1AP_UE_CAPABILITIES_IND       , MESSAGE_PRIORITY_MED, s1ap_ue_cap_ind_t                , s1ap_ue_cap_ind)
-MESSAGE_DEF(S1AP_ENB_DEREGISTERED_IND      , MESSAGE_PRIORITY_MED, s1ap_eNB_deregistered_ind_t      , s1ap_eNB_deregistered_ind)
-MESSAGE_DEF(S1AP_DEREGISTER_UE_REQ         , MESSAGE_PRIORITY_MED, s1ap_deregister_ue_req_t         , s1ap_deregister_ue_req)
-MESSAGE_DEF(S1AP_UE_CONTEXT_RELEASE_REQ    , MESSAGE_PRIORITY_MED, s1ap_ue_context_release_req_t    , s1ap_ue_context_release_req)
-MESSAGE_DEF(S1AP_UE_CONTEXT_RELEASE_COMMAND, MESSAGE_PRIORITY_MED, s1ap_ue_context_release_command_t, s1ap_ue_context_release_command)
-MESSAGE_DEF(S1AP_UE_CONTEXT_RELEASE_COMPLETE, MESSAGE_PRIORITY_MED, s1ap_ue_context_release_complete_t, s1ap_ue_context_release_complete)
diff --git a/openair3/COMMON/s1ap_messages_types.h b/openair3/COMMON/s1ap_messages_types.h
deleted file mode 100644
index e6c3bba504ae2c8f679b34710732561db7c79d52..0000000000000000000000000000000000000000
--- a/openair3/COMMON/s1ap_messages_types.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * 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 S1AP_MESSAGES_TYPES_H_
-#define S1AP_MESSAGES_TYPES_H_
-
-#define S1AP_ENB_DEREGISTERED_IND(mSGpTR)   (mSGpTR)->ittiMsg.s1ap_eNB_deregistered_ind
-#define S1AP_DEREGISTER_UE_REQ(mSGpTR)      (mSGpTR)->ittiMsg.s1ap_deregister_ue_req
-#define S1AP_UE_CONTEXT_RELEASE_REQ(mSGpTR) (mSGpTR)->ittiMsg.s1ap_ue_context_release_req
-#define S1AP_UE_CONTEXT_RELEASE_COMMAND(mSGpTR) (mSGpTR)->ittiMsg.s1ap_ue_context_release_command
-#define S1AP_UE_CONTEXT_RELEASE_COMPLETE(mSGpTR) (mSGpTR)->ittiMsg.s1ap_ue_context_release_complete
-
-typedef struct s1ap_initial_ue_message_s {
-  unsigned     eNB_ue_s1ap_id:24;
-  uint32_t     mme_ue_s1ap_id;
-  cgi_t        e_utran_cgi;
-} s1ap_initial_ue_message_t;
-
-typedef struct s1ap_initial_ctxt_setup_req_s {
-  unsigned                eNB_ue_s1ap_id:24;
-  uint32_t                mme_ue_s1ap_id;
-
-  /* Key eNB */
-  uint8_t                 keNB[32];
-
-  ambr_t                  ambr;
-  ambr_t                  apn_ambr;
-
-  /* EPS bearer ID */
-  unsigned                ebi:4;
-
-  /* QoS */
-  qci_t                   qci;
-  priority_level_t        prio_level;
-  pre_emp_vulnerability_t pre_emp_vulnerability;
-  pre_emp_capability_t    pre_emp_capability;
-
-  /* S-GW TEID for user-plane */
-  Teid_t                  teid;
-  /* S-GW IP address for User-Plane */
-  ip_address_t            s_gw_address;
-} s1ap_initial_ctxt_setup_req_t;
-
-typedef struct s1ap_ue_cap_ind_s {
-  unsigned  eNB_ue_s1ap_id:24;
-  uint32_t  mme_ue_s1ap_id;
-  uint8_t   radio_capabilities[100];
-  uint32_t  radio_capabilities_length;
-} s1ap_ue_cap_ind_t;
-
-#define S1AP_ITTI_UE_PER_DEREGISTER_MESSAGE 20
-typedef struct s1ap_eNB_deregistered_ind_s {
-  uint8_t  nb_ue_to_deregister;
-  uint32_t mme_ue_s1ap_id[S1AP_ITTI_UE_PER_DEREGISTER_MESSAGE];
-} s1ap_eNB_deregistered_ind_t;
-
-typedef struct s1ap_deregister_ue_req_s {
-  uint32_t mme_ue_s1ap_id;
-} s1ap_deregister_ue_req_t;
-
-typedef struct s1ap_ue_context_release_req_s {
-  uint32_t mme_ue_s1ap_id;
-} s1ap_ue_context_release_req_t;
-
-typedef struct s1ap_ue_context_release_command_s {
-  uint32_t mme_ue_s1ap_id;
-} s1ap_ue_context_release_command_t;
-
-typedef struct s1ap_ue_context_release_complete_s {
-  uint32_t mme_ue_s1ap_id;
-} s1ap_ue_context_release_complete_t;
-
-#endif /* S1AP_MESSAGES_TYPES_H_ */
diff --git a/openair3/COMMON/sctp_messages_def.h b/openair3/COMMON/sctp_messages_def.h
deleted file mode 100644
index c2d51c91eb8d85fed748615a0fcfd3382263b6af..0000000000000000000000000000000000000000
--- a/openair3/COMMON/sctp_messages_def.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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
- */
-
-//WARNING: Do not include this header directly. Use intertask_interface.h instead.
-
-MESSAGE_DEF(SCTP_INIT_MSG,          MESSAGE_PRIORITY_MED, SctpInit,                 sctpInit)
-MESSAGE_DEF(SCTP_DATA_REQ,          MESSAGE_PRIORITY_MED, sctp_data_req_t,          sctp_data_req)
-MESSAGE_DEF(SCTP_DATA_IND,          MESSAGE_PRIORITY_MED, sctp_data_ind_t,          sctp_data_ind)
-MESSAGE_DEF(SCTP_NEW_ASSOCIATION,   MESSAGE_PRIORITY_MAX, sctp_new_peer_t,          sctp_new_peer)
-MESSAGE_DEF(SCTP_CLOSE_ASSOCIATION, MESSAGE_PRIORITY_MAX, sctp_close_association_t, sctp_close_association)
diff --git a/openair3/COMMON/sctp_messages_types.h b/openair3/COMMON/sctp_messages_types.h
deleted file mode 100644
index 98a92c66b64b9c82cdd6b50b095dd1e7058152df..0000000000000000000000000000000000000000
--- a/openair3/COMMON/sctp_messages_types.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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 SCTP_MESSAGES_TYPES_H_
-#define SCTP_MESSAGES_TYPES_H_
-
-#define SCTP_DATA_IND(mSGpTR)           (mSGpTR)->ittiMsg.sctp_data_ind
-#define SCTP_DATA_REQ(mSGpTR)           (mSGpTR)->ittiMsg.sctp_data_req
-#define SCTP_INIT_MSG(mSGpTR)           (mSGpTR)->ittiMsg.sctpInit
-#define SCTP_CLOSE_ASSOCIATION(mSGpTR)  (mSGpTR)->ittiMsg.sctp_close_association
-
-typedef struct sctp_data_req_s {
-  uint8_t  *buffer;
-  uint32_t  bufLen;
-  uint32_t  assocId;
-  uint16_t  stream;
-} sctp_data_req_t;
-
-typedef struct sctp_data_ind_s {
-  uint8_t  *buffer;           ///< SCTP buffer
-  uint32_t  buf_length;       ///< SCTP buffer length
-  int32_t   assoc_id;         ///< SCTP physical association ID
-  uint8_t   stream;           ///< Stream number on which data had been received
-  uint16_t  instreams;        ///< Number of input streams for the SCTP connection between peers
-  uint16_t  outstreams;       ///< Number of output streams for the SCTP connection between peers
-} sctp_data_ind_t;
-
-typedef struct sctp_init_s {
-  /* Request usage of ipv4 */
-  unsigned  ipv4:1;
-  /* Request usage of ipv6 */
-  unsigned  ipv6:1;
-  uint8_t   nb_ipv4_addr;
-  uint32_t  ipv4_address[10];
-  uint8_t   nb_ipv6_addr;
-  char     *ipv6_address[10];
-  uint16_t  port;
-  uint32_t  ppid;
-} SctpInit;
-
-typedef struct sctp_close_association_s {
-  uint32_t  assoc_id;
-} sctp_close_association_t;
-
-typedef struct sctp_new_peer_s {
-  uint32_t instreams;
-  uint32_t outstreams;
-  uint32_t assoc_id;
-} sctp_new_peer_t;
-
-#endif /* SCTP_MESSAGES_TYPES_H_ */
diff --git a/openair3/COMMON/tasks_def.h b/openair3/COMMON/tasks_def.h
deleted file mode 100644
index d1b7b8d75608667beafcaff1bbfdcf5c67ab167e..0000000000000000000000000000000000000000
--- a/openair3/COMMON/tasks_def.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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
- */
-
-// This task is mandatory and must always be placed in first position
-TASK_DEF(TASK_TIMER,    TASK_PRIORITY_MED, 10)
-
-// Other possible tasks in the process
-
-/// GTPV1-U task
-TASK_DEF(TASK_GTPV1_U,  TASK_PRIORITY_MED, 200)
-/// FW_IP task
-TASK_DEF(TASK_FW_IP,    TASK_PRIORITY_MED, 200)
-/// MME Applicative task
-TASK_DEF(TASK_MME_APP,  TASK_PRIORITY_MED, 200)
-/// NAS task
-TASK_DEF(TASK_NAS_MME,  TASK_PRIORITY_MED, 200)
-/// S11 task
-TASK_DEF(TASK_S11,      TASK_PRIORITY_MED, 200)
-/// S1AP task
-TASK_DEF(TASK_S1AP,     TASK_PRIORITY_MED, 200)
-/// S6a task
-TASK_DEF(TASK_S6A,      TASK_PRIORITY_MED, 200)
-/// SCTP task
-TASK_DEF(TASK_SCTP,     TASK_PRIORITY_MED, 200)
-/// Serving and Proxy Gateway Application task
-TASK_DEF(TASK_SPGW_APP, TASK_PRIORITY_MED, 200)
-/// UDP task
-TASK_DEF(TASK_UDP,      TASK_PRIORITY_MED, 200)
-//MESSAGE GENERATOR TASK
-TASK_DEF(TASK_MSC,      TASK_PRIORITY_MED,          200)
diff --git a/openair3/COMMON/udp_messages_def.h b/openair3/COMMON/udp_messages_def.h
deleted file mode 100644
index 35322f2450cd270f417a66de1c170427dad75ea7..0000000000000000000000000000000000000000
--- a/openair3/COMMON/udp_messages_def.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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
- */
-
-MESSAGE_DEF(UDP_INIT,     MESSAGE_PRIORITY_MED, udp_init_t,     udp_init)
-MESSAGE_DEF(UDP_DATA_REQ, MESSAGE_PRIORITY_MED, udp_data_req_t, udp_data_req)
-MESSAGE_DEF(UDP_DATA_IND, MESSAGE_PRIORITY_MED, udp_data_ind_t, udp_data_ind)
diff --git a/openair3/COMMON/udp_messages_types.h b/openair3/COMMON/udp_messages_types.h
deleted file mode 100644
index 7825a924d1cb5e1fc2600aecbbcd97a8d7a46e80..0000000000000000000000000000000000000000
--- a/openair3/COMMON/udp_messages_types.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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 UDP_MESSAGES_TYPES_H_
-#define UDP_MESSAGES_TYPES_H_
-
-#define UDP_INIT(mSGpTR)    (mSGpTR)->ittiMsg.udp_init
-
-typedef struct {
-  uint32_t  port;
-  char     *address;
-} udp_init_t;
-
-typedef struct {
-  uint8_t  *buffer;
-  uint32_t  buffer_length;
-  uint32_t  buffer_offset;
-  uint32_t  peer_address;
-  uint32_t  peer_port;
-} udp_data_req_t;
-
-typedef struct {
-  uint8_t  *buffer;
-  uint32_t  buffer_length;
-  uint32_t  peer_address;
-  uint32_t  peer_port;
-} udp_data_ind_t;
-
-#endif /* UDP_MESSAGES_TYPES_H_ */
diff --git a/openair3/GTPV1-U/gtpv1u_eNB.c b/openair3/GTPV1-U/gtpv1u_eNB.c
index 0c43597b16e5c8ca31b362cbb98dd2d06d87049d..d904e90f228238971ab64917480dda48868f9aab 100644
--- a/openair3/GTPV1-U/gtpv1u_eNB.c
+++ b/openair3/GTPV1-U/gtpv1u_eNB.c
@@ -61,8 +61,7 @@ extern RAN_CONTEXT_t RC;
 static int           gtpv1u_dump_socket_g;
 
 //-----------------------------------------------------------------------------
-int gtpv1u_eNB_create_dump_socket(void)
-{
+int gtpv1u_eNB_create_dump_socket(void) {
   struct ifreq ifr;
   int          hdrincl=1;
 
@@ -92,8 +91,7 @@ int gtpv1u_eNB_create_dump_socket(void)
 }
 
 //-----------------------------------------------------------------------------
-static void gtpv1u_eNB_write_dump_socket(uint8_t *buffer_pP, uint32_t buffer_lengthP)
-{
+static void gtpv1u_eNB_write_dump_socket(uint8_t *buffer_pP, uint32_t buffer_lengthP) {
   struct sockaddr_in sin;
   memset(&sin, 0, sizeof(sin));
   sin.sin_family = AF_INET;
@@ -108,12 +106,10 @@ static void gtpv1u_eNB_write_dump_socket(uint8_t *buffer_pP, uint32_t buffer_len
 #endif
 
 //-----------------------------------------------------------------------------
-static int gtpv1u_eNB_send_init_udp(const Gtpv1uS1Req * req)
-{
+static int gtpv1u_eNB_send_init_udp(const Gtpv1uS1Req *req) {
   // Create and alloc new message
   MessageDef *message_p;
-  struct in_addr addr={0};
-
+  struct in_addr addr= {0};
   message_p = itti_alloc_new_message(TASK_GTPV1_U, UDP_INIT);
 
   if (message_p == NULL) {
@@ -124,21 +120,20 @@ static int gtpv1u_eNB_send_init_udp(const Gtpv1uS1Req * req)
   addr.s_addr = req->enb_ip_address_for_S1u_S12_S4_up;
   UDP_INIT(message_p).address = inet_ntoa(addr);
   LOG_I(GTPU, "Tx UDP_INIT IP addr %s (%x)\n", UDP_INIT(message_p).address,UDP_INIT(message_p).port);
-
   MSC_LOG_EVENT(
-	  MSC_GTPU_ENB,
-	  "0 UDP bind  %s:%u",
-	  UDP_INIT(message_p).address,
-	  UDP_INIT(message_p).port);
+    MSC_GTPU_ENB,
+    "0 UDP bind  %s:%u",
+    UDP_INIT(message_p).address,
+    UDP_INIT(message_p).port);
   return itti_send_msg_to_task(TASK_UDP, INSTANCE_DEFAULT, message_p);
 }
 
 static int gtpv1u_s1_req(
   const instance_t                             instanceP,
-  const Gtpv1uS1Req * const req) {
+  const Gtpv1uS1Req *const req) {
   memcpy(&RC.gtpv1u_data_g->enb_ip_address_for_S1u_S12_S4_up,
-	 &req->enb_ip_address_for_S1u_S12_S4_up,
-	 sizeof (req->enb_ip_address_for_S1u_S12_S4_up));
+         &req->enb_ip_address_for_S1u_S12_S4_up,
+         sizeof (req->enb_ip_address_for_S1u_S12_S4_up));
   gtpv1u_eNB_send_init_udp(req);
   return 0;
 }
@@ -148,8 +143,7 @@ NwGtpv1uRcT gtpv1u_eNB_log_request(NwGtpv1uLogMgrHandleT hLogMgr,
                                    uint32_t logLevel,
                                    NwCharT *file,
                                    uint32_t line,
-                                   NwCharT *logStr)
-{
+                                   NwCharT *logStr) {
   LOG_D(GTPU, "%s\n", logStr);
   return NW_GTPV1U_OK;
 }
@@ -161,12 +155,10 @@ NwGtpv1uRcT gtpv1u_eNB_send_udp_msg(
   uint32_t buffer_len,
   uint32_t buffer_offset,
   uint32_t peerIpAddr,
-  uint16_t peerPort)
-{
+  uint16_t peerPort) {
   // Create and alloc new message
   MessageDef     *message_p       = NULL;
   udp_data_req_t *udp_data_req_p  = NULL;
-
   message_p = itti_alloc_new_message(TASK_GTPV1_U, UDP_DATA_REQ);
 
   if (message_p) {
@@ -190,8 +182,7 @@ NwGtpv1uRcT gtpv1u_eNB_send_udp_msg(
 /* Callback called when a gtpv1u message arrived on UDP interface */
 NwGtpv1uRcT gtpv1u_eNB_process_stack_req(
   NwGtpv1uUlpHandleT hUlp,
-  NwGtpv1uUlpApiT   *pUlpApi)
-{
+  NwGtpv1uUlpApiT   *pUlpApi) {
   boolean_t           result             = FALSE;
   teid_t              teid               = 0;
   hashtable_rc_t      hash_rc            = HASH_TABLE_KEY_NOT_EXISTS;
@@ -204,94 +195,88 @@ NwGtpv1uRcT gtpv1u_eNB_process_stack_req(
      * - T-PDU
      * - END-MARKER
      */
-  case NW_GTPV1U_ULP_API_RECV_TPDU: {
-    uint8_t              buffer[4096];
-    uint32_t             buffer_len;
-    /* Nw-gptv1u stack has processed a PDU. we can schedule it to PDCP
-     * for transmission.
-     */
-    teid = pUlpApi->apiInfo.recvMsgInfo.teid;
-
-    if (NW_GTPV1U_OK != nwGtpv1uMsgGetTpdu(pUlpApi->apiInfo.recvMsgInfo.hMsg,
-                                           buffer, &buffer_len)) {
-      LOG_E(GTPU, "Error while retrieving T-PDU");
-    }
+    case NW_GTPV1U_ULP_API_RECV_TPDU: {
+      uint8_t              buffer[4096];
+      uint32_t             buffer_len;
+      /* Nw-gptv1u stack has processed a PDU. we can schedule it to PDCP
+       * for transmission.
+       */
+      teid = pUlpApi->apiInfo.recvMsgInfo.teid;
+
+      if (NW_GTPV1U_OK != nwGtpv1uMsgGetTpdu(pUlpApi->apiInfo.recvMsgInfo.hMsg,
+                                             buffer, &buffer_len)) {
+        LOG_E(GTPU, "Error while retrieving T-PDU");
+      }
 
-    itti_free(TASK_UDP, ((NwGtpv1uMsgT*)pUlpApi->apiInfo.recvMsgInfo.hMsg)->msgBuf);
+      itti_free(TASK_UDP, ((NwGtpv1uMsgT *)pUlpApi->apiInfo.recvMsgInfo.hMsg)->msgBuf);
 #if defined(GTP_DUMP_SOCKET) && GTP_DUMP_SOCKET > 0
-    gtpv1u_eNB_write_dump_socket(buffer,buffer_len);
+      gtpv1u_eNB_write_dump_socket(buffer,buffer_len);
 #endif
+      rc = nwGtpv1uMsgDelete(RC.gtpv1u_data_g->gtpv1u_stack,
+                             pUlpApi->apiInfo.recvMsgInfo.hMsg);
 
-    rc = nwGtpv1uMsgDelete(RC.gtpv1u_data_g->gtpv1u_stack,
-                           pUlpApi->apiInfo.recvMsgInfo.hMsg);
-    if (rc != NW_GTPV1U_OK) {
-      LOG_E(GTPU, "nwGtpv1uMsgDelete failed: 0x%x\n", rc);
-    }
+      if (rc != NW_GTPV1U_OK) {
+        LOG_E(GTPU, "nwGtpv1uMsgDelete failed: 0x%x\n", rc);
+      }
 
-    //-----------------------
-    // GTPV1U->PDCP mapping
-    //-----------------------
-    hash_rc = hashtable_get(RC.gtpv1u_data_g->teid_mapping, teid, (void**)&gtpv1u_teid_data_p);
+      //-----------------------
+      // GTPV1U->PDCP mapping
+      //-----------------------
+      hash_rc = hashtable_get(RC.gtpv1u_data_g->teid_mapping, teid, (void **)&gtpv1u_teid_data_p);
 
-    if (hash_rc == HASH_TABLE_OK) {
+      if (hash_rc == HASH_TABLE_OK) {
 #if defined(LOG_GTPU) && LOG_GTPU > 0
-      LOG_D(GTPU, "Received T-PDU from gtpv1u stack teid  %u size %d -> enb module id %u ue module id %u rab id %u\n",
-            teid,
-            buffer_len,
-            gtpv1u_teid_data_p->enb_id,
-            gtpv1u_teid_data_p->ue_id,
-            gtpv1u_teid_data_p->eps_bearer_id);
+        LOG_D(GTPU, "Received T-PDU from gtpv1u stack teid  %u size %d -> enb module id %u ue module id %u rab id %u\n",
+              teid,
+              buffer_len,
+              gtpv1u_teid_data_p->enb_id,
+              gtpv1u_teid_data_p->ue_id,
+              gtpv1u_teid_data_p->eps_bearer_id);
 #endif
-
-//#warning "LG eps bearer mapping to DRB id to do (offset -4)"
-      PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, gtpv1u_teid_data_p->enb_id, ENB_FLAG_YES,  gtpv1u_teid_data_p->ue_id, 0, 0,gtpv1u_teid_data_p->enb_id);
-      MSC_LOG_TX_MESSAGE(
-			 MSC_GTPU_ENB,
-			 MSC_PDCP_ENB,
-			 NULL,0,
-			 MSC_AS_TIME_FMT" DATA-REQ rb %u size %u",
-			 0,0,
-			 (gtpv1u_teid_data_p->eps_bearer_id) ? gtpv1u_teid_data_p->eps_bearer_id - 4: 5-4,
-			 buffer_len);
-      
-      result = pdcp_data_req(
-			     &ctxt,
-			     SRB_FLAG_NO,
-			     (gtpv1u_teid_data_p->eps_bearer_id) ? gtpv1u_teid_data_p->eps_bearer_id - 4: 5-4,
-			     0, // mui
-			     SDU_CONFIRM_NO, // confirm
-			     buffer_len,
-			     buffer,
-			     PDCP_TRANSMISSION_MODE_DATA
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-              ,NULL, NULL
+        //#warning "LG eps bearer mapping to DRB id to do (offset -4)"
+        PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, gtpv1u_teid_data_p->enb_id, ENB_FLAG_YES,  gtpv1u_teid_data_p->ue_id, 0, 0,gtpv1u_teid_data_p->enb_id);
+        MSC_LOG_TX_MESSAGE(
+          MSC_GTPU_ENB,
+          MSC_PDCP_ENB,
+          NULL,0,
+          MSC_AS_TIME_FMT" DATA-REQ rb %u size %u",
+          0,0,
+          (gtpv1u_teid_data_p->eps_bearer_id) ? gtpv1u_teid_data_p->eps_bearer_id - 4: 5-4,
+          buffer_len);
+        result = pdcp_data_req(
+                   &ctxt,
+                   SRB_FLAG_NO,
+                   (gtpv1u_teid_data_p->eps_bearer_id) ? gtpv1u_teid_data_p->eps_bearer_id - 4: 5-4,
+                   0, // mui
+                   SDU_CONFIRM_NO, // confirm
+                   buffer_len,
+                   buffer,
+                   PDCP_TRANSMISSION_MODE_DATA
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                   ,NULL, NULL
 #endif
-              );
-      
-      
-      if ( result == FALSE ) {
-	
-	if (ctxt.configured == FALSE )
-	  LOG_W(GTPU, "PDCP data request failed, cause: RB is not configured!\n") ;
-	else  
-	  LOG_W(GTPU, "PDCP data request failed\n");
-	
-	return NW_GTPV1U_FAILURE;
+                 );
+
+        if ( result == FALSE ) {
+          if (ctxt.configured == FALSE )
+            LOG_W(GTPU, "PDCP data request failed, cause: RB is not configured!\n") ;
+          else
+            LOG_W(GTPU, "PDCP data request failed\n");
+
+          return NW_GTPV1U_FAILURE;
+        }
+      } else {
+        LOG_W(GTPU, "Received T-PDU from gtpv1u stack teid %u unknown size %u", teid, buffer_len);
       }
-      
-    } else {
-      LOG_W(GTPU, "Received T-PDU from gtpv1u stack teid %u unknown size %u", teid, buffer_len);
     }
-  }
     break;
-    
-  default: {
-    LOG_E(GTPU, "Received undefined UlpApi (%02x) from gtpv1u stack!\n",
-          pUlpApi->apiType);
-  }
-  
-  } // end of switch 
-  
+
+    default: {
+      LOG_E(GTPU, "Received undefined UlpApi (%02x) from gtpv1u stack!\n",
+            pUlpApi->apiType);
+    }
+  } // end of switch
+
   return NW_GTPV1U_OK;
 }
 
@@ -301,8 +286,7 @@ int data_recv_callback(uint16_t  portP,
                        uint32_t  address,
                        uint8_t  *buffer,
                        uint32_t  length,
-                       void     *arg_p)
-{
+                       void     *arg_p) {
   gtpv1u_data_t        *gtpv1u_data_p;
 
   if (arg_p == NULL) {
@@ -310,7 +294,6 @@ int data_recv_callback(uint16_t  portP,
   }
 
   gtpv1u_data_p = (gtpv1u_data_t *)arg_p;
-
   return nwGtpv1uProcessUdpReq(gtpv1u_data_p->gtpv1u_stack,
                                buffer,
                                length,
@@ -421,9 +404,7 @@ static NwGtpv1uRcT gtpv1u_start_timer_wrapper(
   uint32_t                  timeoutUsec,
   uint32_t                  tmrType,
   void                   *timeoutArg,
-  NwGtpv1uTimerHandleT   *hTmr)
-{
-
+  NwGtpv1uTimerHandleT   *hTmr) {
   NwGtpv1uRcT rc = NW_GTPV1U_OK;
   long        timer_id;
 
@@ -453,11 +434,8 @@ static NwGtpv1uRcT gtpv1u_start_timer_wrapper(
 static NwGtpv1uRcT
 gtpv1u_stop_timer_wrapper(
   NwGtpv1uTimerMgrHandleT tmrMgrHandle,
-  NwGtpv1uTimerHandleT hTmr)
-{
-
+  NwGtpv1uTimerHandleT hTmr) {
   NwGtpv1uRcT rc = NW_GTPV1U_OK;
-
   return rc;
 }
 
@@ -468,18 +446,14 @@ gtpv1u_initial_req(
   gtpv1u_data_t *gtpv1u_data_pP,
   teid_t         teidP,
   tcp_udp_port_t portP,
-  uint32_t       address)
-{
+  uint32_t       address) {
   NwGtpv1uUlpApiT ulp_req;
   NwGtpv1uRcT     rc = NW_GTPV1U_FAILURE;
-
   memset(&ulp_req, 0, sizeof(NwGtpv1uUlpApiT));
-
   ulp_req.apiType = NW_GTPV1U_ULP_API_INITIAL_REQ;
   ulp_req.apiInfo.initialReqInfo.teid     = teidP;
   ulp_req.apiInfo.initialReqInfo.peerPort = portP;
   ulp_req.apiInfo.initialReqInfo.peerIp   = address;
-
   rc = nwGtpv1uProcessUlpReq(gtpv1u_data_pP->gtpv1u_stack, &ulp_req);
 
   if (rc == NW_GTPV1U_OK) {
@@ -500,9 +474,7 @@ gtpv1u_new_data_req(
   uint8_t *buffer_pP,
   uint32_t buf_lenP,
   uint32_t buf_offsetP
-)
-{
-
+) {
   NwGtpv1uUlpApiT          stack_req;
   NwGtpv1uRcT              rc            = NW_GTPV1U_FAILURE;
   struct gtpv1u_ue_data_s  ue;
@@ -510,17 +482,14 @@ gtpv1u_new_data_req(
   struct gtpv1u_bearer_s  *bearer_p      = NULL;
   hashtable_rc_t           hash_rc       = HASH_TABLE_KEY_NOT_EXISTS;;
   gtpv1u_data_t           *gtpv1u_data_p = NULL;
-
   memset(&ue, 0, sizeof(struct gtpv1u_ue_data_s));
   ue.ue_id = ue_rntiP;
-
   AssertFatal(enb_module_idP >=0, "Bad parameter enb module id %u\n", enb_module_idP);
   AssertFatal((rab_idP - GTPV1U_BEARER_OFFSET)< GTPV1U_MAX_BEARERS_ID, "Bad parameter rab id %u\n", rab_idP);
   AssertFatal((rab_idP - GTPV1U_BEARER_OFFSET) >= 0 , "Bad parameter rab id %u\n", rab_idP);
-
   gtpv1u_data_p = RC.gtpv1u_data_g;
   /* Check that UE context is present in ue map. */
-  hash_rc = hashtable_get(gtpv1u_data_p->ue_mapping, (uint64_t)ue_rntiP, (void**)&ue_inst_p);
+  hash_rc = hashtable_get(gtpv1u_data_p->ue_mapping, (uint64_t)ue_rntiP, (void **)&ue_inst_p);
 
   if (hash_rc ==  HASH_TABLE_KEY_NOT_EXISTS ) {
     LOG_E(GTPU, "[UE %d] Trying to send data on non-existing UE context\n", ue_rntiP);
@@ -536,18 +505,16 @@ gtpv1u_new_data_req(
   if (bearer_p->state != BEARER_UP) {
     LOG_W(GTPU, "Trying to send data over bearer with state(%u) != BEARER_UP\n",
           bearer_p->state);
-//#warning  LG: HACK WHILE WAITING FOR NAS, normally return -1
+    //#warning  LG: HACK WHILE WAITING FOR NAS, normally return -1
 
     if (bearer_p->state != BEARER_IN_CONFIG)
       return -1;
   }
 
   memset(&stack_req, 0, sizeof(NwGtpv1uUlpApiT));
-
   stack_req.apiType                   = NW_GTPV1U_ULP_API_SEND_TPDU;
   stack_req.apiInfo.sendtoInfo.teid   = bearer_p->teid_sgw;
   stack_req.apiInfo.sendtoInfo.ipAddr = bearer_p->sgw_ip_addr;
-
   LOG_D(GTPU, "TX TO TEID %u addr 0x%x\n",bearer_p->teid_sgw, bearer_p->sgw_ip_addr);
   rc = nwGtpv1uGpduMsgNew(gtpv1u_data_p->gtpv1u_stack,
                           bearer_p->teid_sgw,
@@ -587,10 +554,9 @@ gtpv1u_new_data_req(
 int
 gtpv1u_create_s1u_tunnel(
   const instance_t                              instanceP,
-  const gtpv1u_enb_create_tunnel_req_t * const  create_tunnel_req_pP,
-        gtpv1u_enb_create_tunnel_resp_t * const create_tunnel_resp_pP
-  )
-{
+  const gtpv1u_enb_create_tunnel_req_t *const  create_tunnel_req_pP,
+  gtpv1u_enb_create_tunnel_resp_t *const create_tunnel_resp_pP
+) {
   /* Create a new nw-gtpv1-u stack req using API */
   NwGtpv1uUlpApiT          stack_req;
   NwGtpv1uRcT              rc                   = NW_GTPV1U_FAILURE;
@@ -606,17 +572,14 @@ gtpv1u_create_s1u_tunnel(
   int                      ip_offset            = 0;
   in_addr_t                in_addr;
   int                      addrs_length_in_bytes= 0;
-
-
   MSC_LOG_RX_MESSAGE(
-		  MSC_GTPU_ENB,
-		  MSC_RRC_ENB,
-		  NULL,0,
-		  MSC_AS_TIME_FMT" CREATE_TUNNEL_REQ RNTI %"PRIx16" inst %u ntuns %u ebid %u sgw-s1u teid %u",
-		  0,0,create_tunnel_req_pP->rnti, instanceP,
-		  create_tunnel_req_pP->num_tunnels, create_tunnel_req_pP->eps_bearer_id[0],
-		  create_tunnel_req_pP->sgw_S1u_teid[0]);
-
+    MSC_GTPU_ENB,
+    MSC_RRC_ENB,
+    NULL,0,
+    MSC_AS_TIME_FMT" CREATE_TUNNEL_REQ RNTI %"PRIx16" inst %u ntuns %u ebid %u sgw-s1u teid %u",
+    0,0,create_tunnel_req_pP->rnti, instanceP,
+    create_tunnel_req_pP->num_tunnels, create_tunnel_req_pP->eps_bearer_id[0],
+    create_tunnel_req_pP->sgw_S1u_teid[0]);
   create_tunnel_resp_pP->rnti        = create_tunnel_req_pP->rnti;
   create_tunnel_resp_pP->status      = 0;
   create_tunnel_resp_pP->num_tunnels = 0;
@@ -627,7 +590,6 @@ gtpv1u_create_s1u_tunnel(
     LOG_D(GTPU, "Rx GTPV1U_ENB_CREATE_TUNNEL_REQ ue rnti %x eps bearer id %u\n",
           create_tunnel_req_pP->rnti, eps_bearer_id);
     memset(&stack_req, 0, sizeof(NwGtpv1uUlpApiT));
-
     stack_req.apiType = NW_GTPV1U_ULP_API_CREATE_TUNNEL_ENDPOINT;
 
     do {
@@ -636,7 +598,6 @@ gtpv1u_create_s1u_tunnel(
       stack_req.apiInfo.createTunnelEndPointInfo.teid          = s1u_teid;
       stack_req.apiInfo.createTunnelEndPointInfo.hUlpSession   = 0;
       stack_req.apiInfo.createTunnelEndPointInfo.hStackSession = 0;
-
       rc = nwGtpv1uProcessUlpReq(RC.gtpv1u_data_g->gtpv1u_stack, &stack_req);
       LOG_D(GTPU, ".\n");
     } while (rc != NW_GTPV1U_OK);
@@ -647,7 +608,6 @@ gtpv1u_create_s1u_tunnel(
     hash_rc = hashtable_get(RC.gtpv1u_data_g->ue_mapping, create_tunnel_req_pP->rnti, (void **)&gtpv1u_ue_data_p);
 
     if ((hash_rc == HASH_TABLE_KEY_NOT_EXISTS) || (hash_rc == HASH_TABLE_OK)) {
-
       if (hash_rc == HASH_TABLE_KEY_NOT_EXISTS) {
         gtpv1u_ue_data_p = calloc (1, sizeof(gtpv1u_ue_data_t));
         hash_rc = hashtable_insert(RC.gtpv1u_data_g->ue_mapping, create_tunnel_req_pP->rnti, gtpv1u_ue_data_p);
@@ -660,7 +620,6 @@ gtpv1u_create_s1u_tunnel(
              &RC.gtpv1u_data_g->enb_ip_address_for_S1u_S12_S4_up,
              sizeof (in_addr_t));
       create_tunnel_resp_pP->enb_addr.length = sizeof (in_addr_t);
-
       addrs_length_in_bytes = create_tunnel_req_pP->sgw_addr[i].length / 8;
       AssertFatal((addrs_length_in_bytes == 4) ||
                   (addrs_length_in_bytes == 16) ||
@@ -670,7 +629,7 @@ gtpv1u_create_s1u_tunnel(
 
       if ((addrs_length_in_bytes == 4) ||
           (addrs_length_in_bytes == 20)) {
-        in_addr = *((in_addr_t*)create_tunnel_req_pP->sgw_addr[i].buffer);
+        in_addr = *((in_addr_t *)create_tunnel_req_pP->sgw_addr[i].buffer);
         ip_offset = 4;
         gtpv1u_ue_data_p->bearers[eps_bearer_id - GTPV1U_BEARER_OFFSET].sgw_ip_addr = in_addr;
       }
@@ -688,7 +647,6 @@ gtpv1u_create_s1u_tunnel(
       gtpv1u_ue_data_p->bearers[eps_bearer_id - GTPV1U_BEARER_OFFSET].teid_sgw               = create_tunnel_req_pP->sgw_S1u_teid[i];
       gtpv1u_ue_data_p->num_bearers++;
       create_tunnel_resp_pP->enb_S1u_teid[i] = s1u_teid;
-
     } else {
       create_tunnel_resp_pP->enb_S1u_teid[i] = 0;
       create_tunnel_resp_pP->status         = 0xFF;
@@ -696,11 +654,10 @@ gtpv1u_create_s1u_tunnel(
 
     create_tunnel_resp_pP->eps_bearer_id[i] = eps_bearer_id;
     create_tunnel_resp_pP->num_tunnels      += 1;
-
     //-----------------------
     // GTPV1U->PDCP mapping
     //-----------------------
-    hash_rc = hashtable_get(RC.gtpv1u_data_g->teid_mapping, s1u_teid, (void**)&gtpv1u_teid_data_p);
+    hash_rc = hashtable_get(RC.gtpv1u_data_g->teid_mapping, s1u_teid, (void **)&gtpv1u_teid_data_p);
 
     if (hash_rc == HASH_TABLE_KEY_NOT_EXISTS) {
       gtpv1u_teid_data_p = calloc (1, sizeof(gtpv1u_teid_data_t));
@@ -714,14 +671,14 @@ gtpv1u_create_s1u_tunnel(
       create_tunnel_resp_pP->status         = 0xFF;
     }
   }
-  MSC_LOG_TX_MESSAGE(
-		  MSC_GTPU_ENB,
-		  MSC_RRC_ENB,
-		  NULL,0,
-		  "0 GTPV1U_ENB_CREATE_TUNNEL_RESP rnti %x teid %x",
-		  create_tunnel_resp_pP->rnti,
-		  s1u_teid);
 
+  MSC_LOG_TX_MESSAGE(
+    MSC_GTPU_ENB,
+    MSC_RRC_ENB,
+    NULL,0,
+    "0 GTPV1U_ENB_CREATE_TUNNEL_RESP rnti %x teid %x",
+    create_tunnel_resp_pP->rnti,
+    s1u_teid);
   LOG_D(GTPU, "Tx GTPV1U_ENB_CREATE_TUNNEL_RESP ue rnti %x status %d\n",
         create_tunnel_req_pP->rnti,
         create_tunnel_resp_pP->status);
@@ -729,12 +686,10 @@ gtpv1u_create_s1u_tunnel(
 }
 
 int gtpv1u_update_s1u_tunnel(
-    const instance_t                              instanceP,
-    const gtpv1u_enb_create_tunnel_req_t * const  create_tunnel_req_pP,
-    const rnti_t                                  prior_rnti
-    )
-{
-
+  const instance_t                              instanceP,
+  const gtpv1u_enb_create_tunnel_req_t *const  create_tunnel_req_pP,
+  const rnti_t                                  prior_rnti
+) {
   /* Local tunnel end-point identifier */
   teid_t                   s1u_teid             = 0;
   gtpv1u_teid_data_t      *gtpv1u_teid_data_p   = NULL;
@@ -744,12 +699,12 @@ int gtpv1u_update_s1u_tunnel(
   hashtable_rc_t           hash_rc              = HASH_TABLE_KEY_NOT_EXISTS;
   int                      i,j;
   uint8_t                  bearers_num = 0,bearers_total = 0;
-
   //-----------------------
   // PDCP->GTPV1U mapping
   //-----------------------
   hash_rc = hashtable_get(RC.gtpv1u_data_g->ue_mapping, prior_rnti, (void **)&gtpv1u_ue_data_p);
-  if(hash_rc != HASH_TABLE_OK){
+
+  if(hash_rc != HASH_TABLE_OK) {
     LOG_E(GTPU,"Error get ue_mapping(rnti=%x) from GTPV1U hashtable error\n", prior_rnti);
     return -1;
   }
@@ -757,65 +712,66 @@ int gtpv1u_update_s1u_tunnel(
   gtpv1u_ue_data_new_p = calloc (1, sizeof(gtpv1u_ue_data_t));
   memcpy(gtpv1u_ue_data_new_p,gtpv1u_ue_data_p,sizeof(gtpv1u_ue_data_t));
   gtpv1u_ue_data_new_p->ue_id       = create_tunnel_req_pP->rnti;
-
   hash_rc = hashtable_insert(RC.gtpv1u_data_g->ue_mapping, create_tunnel_req_pP->rnti, gtpv1u_ue_data_new_p);
   AssertFatal(hash_rc == HASH_TABLE_OK, "Error inserting ue_mapping in GTPV1U hashtable");
   LOG_I(GTPU, "inserting ue_mapping(rnti=%x) in GTPV1U hashtable\n",
-      create_tunnel_req_pP->rnti);
-
+        create_tunnel_req_pP->rnti);
   hash_rc = hashtable_remove(RC.gtpv1u_data_g->ue_mapping, prior_rnti);
   LOG_I(GTPU, "hashtable_remove ue_mapping(rnti=%x) in GTPV1U hashtable\n",
-		  prior_rnti);
+        prior_rnti);
   //-----------------------
   // GTPV1U->PDCP mapping
   //-----------------------
   bearers_total =gtpv1u_ue_data_new_p->num_bearers;
-  for(j = 0;j<GTPV1U_MAX_BEARERS_ID;j++){
 
+  for(j = 0; j<GTPV1U_MAX_BEARERS_ID; j++) {
     if(gtpv1u_ue_data_new_p->bearers[j].state != BEARER_IN_CONFIG)
       continue;
 
     bearers_num++;
+
     for (i = 0; i < create_tunnel_req_pP->num_tunnels; i++) {
       if(j == (create_tunnel_req_pP->eps_bearer_id[i]-GTPV1U_BEARER_OFFSET))
         break;
     }
-    if(i < create_tunnel_req_pP->num_tunnels){
+
+    if(i < create_tunnel_req_pP->num_tunnels) {
       s1u_teid = gtpv1u_ue_data_new_p->bearers[j].teid_eNB;
-      hash_rc = hashtable_get(RC.gtpv1u_data_g->teid_mapping, s1u_teid, (void**)&gtpv1u_teid_data_p);
+      hash_rc = hashtable_get(RC.gtpv1u_data_g->teid_mapping, s1u_teid, (void **)&gtpv1u_teid_data_p);
+
       if (hash_rc == HASH_TABLE_OK) {
         gtpv1u_teid_data_p->ue_id         = create_tunnel_req_pP->rnti;
         gtpv1u_teid_data_p->eps_bearer_id = create_tunnel_req_pP->eps_bearer_id[i];
-
         LOG_I(GTPU, "updata teid_mapping te_id %u (prior_rnti %x rnti %x) in GTPV1U hashtable\n",
               s1u_teid,prior_rnti,create_tunnel_req_pP->rnti);
-      }else{
+      } else {
         LOG_W(GTPU, "Error get teid mapping(s1u_teid=%u) from GTPV1U hashtable", s1u_teid);
       }
-    }else{
+    } else {
       s1u_teid = gtpv1u_ue_data_new_p->bearers[j].teid_eNB;
       hash_rc = hashtable_remove(RC.gtpv1u_data_g->teid_mapping, s1u_teid);
 
       if (hash_rc != HASH_TABLE_OK) {
         LOG_D(GTPU, "Removed user rnti %x , enb S1U teid %u not found\n", prior_rnti, s1u_teid);
       }
+
       gtpv1u_ue_data_new_p->bearers[j].state = BEARER_DOWN;
       gtpv1u_ue_data_new_p->num_bearers--;
       LOG_I(GTPU, "delete teid_mapping te_id %u (rnti%x) bearer_id %d in GTPV1U hashtable\n",
             s1u_teid,prior_rnti,j+GTPV1U_BEARER_OFFSET);;
     }
+
     if(bearers_num > bearers_total)
       break;
   }
-  return 0;
 
+  return 0;
 }
 
 //-----------------------------------------------------------------------------
-static int gtpv1u_delete_s1u_tunnel(
+int gtpv1u_delete_s1u_tunnel(
   const instance_t                             instanceP,
-  const gtpv1u_enb_delete_tunnel_req_t * const req_pP)
-{
+  const gtpv1u_enb_delete_tunnel_req_t *const req_pP) {
   NwGtpv1uUlpApiT          stack_req;
   NwGtpv1uRcT              rc                   = NW_GTPV1U_FAILURE;
   MessageDef              *message_p = NULL;
@@ -823,22 +779,16 @@ static int gtpv1u_delete_s1u_tunnel(
   hashtable_rc_t           hash_rc              = HASH_TABLE_KEY_NOT_EXISTS;
   teid_t                   teid_eNB             = 0;
   int                      erab_index           = 0;
-
   message_p = itti_alloc_new_message(TASK_GTPV1_U, GTPV1U_ENB_DELETE_TUNNEL_RESP);
-
   GTPV1U_ENB_DELETE_TUNNEL_RESP(message_p).rnti     = req_pP->rnti;
   GTPV1U_ENB_DELETE_TUNNEL_RESP(message_p).status       = 0;
-
-
-  hash_rc = hashtable_get(RC.gtpv1u_data_g->ue_mapping, req_pP->rnti, (void**)&gtpv1u_ue_data_p);
+  hash_rc = hashtable_get(RC.gtpv1u_data_g->ue_mapping, req_pP->rnti, (void **)&gtpv1u_ue_data_p);
 
   if (hash_rc == HASH_TABLE_OK) {
-
     for (erab_index = 0; erab_index < req_pP->num_erab; erab_index++) {
       teid_eNB = gtpv1u_ue_data_p->bearers[req_pP->eps_bearer_id[erab_index] - GTPV1U_BEARER_OFFSET].teid_eNB;
       LOG_D(GTPU, "Rx GTPV1U_ENB_DELETE_TUNNEL user rnti %x eNB S1U teid %u eps bearer id %u\n",
             req_pP->rnti, teid_eNB, req_pP->eps_bearer_id[erab_index]);
-
       {
         memset(&stack_req, 0, sizeof(NwGtpv1uUlpApiT));
         stack_req.apiType = NW_GTPV1U_ULP_API_DESTROY_TUNNEL_ENDPOINT;
@@ -846,7 +796,6 @@ static int gtpv1u_delete_s1u_tunnel(
               req_pP->eps_bearer_id[erab_index],
               teid_eNB);
         stack_req.apiInfo.destroyTunnelEndPointInfo.hStackSessionHandle   = gtpv1u_ue_data_p->bearers[req_pP->eps_bearer_id[erab_index] - GTPV1U_BEARER_OFFSET].teid_eNB_stack_session;
-
         rc = nwGtpv1uProcessUlpReq(RC.gtpv1u_data_g->gtpv1u_stack, &stack_req);
         LOG_D(GTPU, ".\n");
       }
@@ -881,36 +830,30 @@ static int gtpv1u_delete_s1u_tunnel(
     }
   }// else silently do nothing
 
-
   LOG_D(GTPU, "Tx GTPV1U_ENB_DELETE_TUNNEL_RESP user rnti %x eNB S1U teid %u status %u\n",
         GTPV1U_ENB_DELETE_TUNNEL_RESP(message_p).rnti,
         GTPV1U_ENB_DELETE_TUNNEL_RESP(message_p).enb_S1u_teid,
         GTPV1U_ENB_DELETE_TUNNEL_RESP(message_p).status);
-
   MSC_LOG_TX_MESSAGE(
-		  MSC_GTPU_ENB,
-		  MSC_RRC_ENB,
-		  NULL,0,
-		  "0 GTPV1U_ENB_DELETE_TUNNEL_RESP rnti %x teid %x",
-		  GTPV1U_ENB_DELETE_TUNNEL_RESP(message_p).rnti,
-		  teid_eNB);
-
+    MSC_GTPU_ENB,
+    MSC_RRC_ENB,
+    NULL,0,
+    "0 GTPV1U_ENB_DELETE_TUNNEL_RESP rnti %x teid %x",
+    GTPV1U_ENB_DELETE_TUNNEL_RESP(message_p).rnti,
+    teid_eNB);
   return itti_send_msg_to_task(TASK_RRC_ENB, instanceP, message_p);
 }
 
 
 //-----------------------------------------------------------------------------
-int gtpv1u_eNB_init(void)
-{
+int gtpv1u_eNB_init(void) {
   NwGtpv1uRcT             rc = NW_GTPV1U_FAILURE;
   NwGtpv1uUlpEntityT      ulp;
   NwGtpv1uUdpEntityT      udp;
   NwGtpv1uLogMgrEntityT   log;
   NwGtpv1uTimerMgrEntityT tmr;
-
   //  enb_properties_p = enb_config_get()->properties[0];
-  RC.gtpv1u_data_g = (gtpv1u_data_t*)calloc(sizeof(gtpv1u_data_t),1);
-
+  RC.gtpv1u_data_g = (gtpv1u_data_t *)calloc(sizeof(gtpv1u_data_t),1);
   LOG_I(GTPU, "Initializing GTPU stack %p\n",&RC.gtpv1u_data_g);
   //gtpv1u_data_g.gtpv1u_stack;
   /* Initialize UE hashtable */
@@ -918,8 +861,7 @@ int gtpv1u_eNB_init(void)
   AssertFatal(RC.gtpv1u_data_g->ue_mapping != NULL, " ERROR Initializing TASK_GTPV1_U task interface: in hashtable_create returned %p\n", RC.gtpv1u_data_g->ue_mapping);
   RC.gtpv1u_data_g->teid_mapping    = hashtable_create (256, NULL, NULL);
   AssertFatal(RC.gtpv1u_data_g->teid_mapping != NULL, " ERROR Initializing TASK_GTPV1_U task interface: in hashtable_create\n");
-//  RC.gtpv1u_data_g.enb_ip_address_for_S1u_S12_S4_up         = enb_properties_p->enb_ipv4_address_for_S1U;
-
+  //  RC.gtpv1u_data_g.enb_ip_address_for_S1u_S12_S4_up         = enb_properties_p->enb_ipv4_address_for_S1U;
   //gtpv1u_data_g.udp_data;
   RC.gtpv1u_data_g->seq_num         = 0;
   RC.gtpv1u_data_g->restart_counter = 0;
@@ -936,7 +878,6 @@ int gtpv1u_eNB_init(void)
     return -1;
   }
 
-
   /* Set the ULP API callback. Called once message have been processed by the
    * nw-gtpv1u stack.
    */
@@ -983,30 +924,26 @@ int gtpv1u_eNB_init(void)
   }
 
 #endif
-
   LOG_D(GTPU, "Initializing GTPV1U interface for eNB: DONE\n");
   return 0;
 }
 
 //-----------------------------------------------------------------------------
 void *gtpv1u_eNB_process_itti_msg(void *notUsed) {
-    /* Trying to fetch a message from the message queue.
-     * If the queue is empty, this function will block till a
-     * message is sent to the task.
-     */
-    instance_t  instance;
-    MessageDef *received_message_p = NULL;
-    int         rc = 0;
-
-    itti_receive_msg(TASK_GTPV1_U, &received_message_p);
-    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_GTPV1U_ENB_TASK, VCD_FUNCTION_IN);
-    DevAssert(received_message_p != NULL);
-
-    instance = ITTI_MSG_INSTANCE(received_message_p);
-    //msg_name_p = ITTI_MSG_NAME(received_message_p);
-
-    switch (ITTI_MSG_ID(received_message_p)) {
-
+  /* Trying to fetch a message from the message queue.
+   * If the queue is empty, this function will block till a
+   * message is sent to the task.
+   */
+  instance_t  instance;
+  MessageDef *received_message_p = NULL;
+  int         rc = 0;
+  itti_receive_msg(TASK_GTPV1_U, &received_message_p);
+  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_GTPV1U_ENB_TASK, VCD_FUNCTION_IN);
+  DevAssert(received_message_p != NULL);
+  instance = ITTI_MSG_INSTANCE(received_message_p);
+  //msg_name_p = ITTI_MSG_NAME(received_message_p);
+
+  switch (ITTI_MSG_ID(received_message_p)) {
     case GTPV1U_ENB_S1_REQ:
       gtpv1u_s1_req(instance, &received_message_p->ittiMsg.gtpv1uS1Req);
 
@@ -1037,28 +974,24 @@ void *gtpv1u_eNB_process_itti_msg(void *notUsed) {
       gtpv1u_ue_data_t             *gtpv1u_ue_data_p     = NULL;
       teid_t                        enb_s1u_teid         = 0;
       teid_t                        sgw_s1u_teid         = 0;
-
       VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_GTPV1U_PROCESS_TUNNEL_DATA_REQ, VCD_FUNCTION_IN);
       data_req_p = &GTPV1U_ENB_TUNNEL_DATA_REQ(received_message_p);
       //ipv4_send_data(ipv4_data_p->sd, data_ind_p->buffer, data_ind_p->length);
-
 #if defined(GTP_DUMP_SOCKET) && GTP_DUMP_SOCKET > 0
       gtpv1u_eNB_write_dump_socket(&data_req_p->buffer[data_req_p->offset],data_req_p->length);
 #endif
       memset(&stack_req, 0, sizeof(NwGtpv1uUlpApiT));
-
-      hash_rc = hashtable_get(RC.gtpv1u_data_g->ue_mapping, (uint64_t)data_req_p->rnti, (void**)&gtpv1u_ue_data_p);
+      hash_rc = hashtable_get(RC.gtpv1u_data_g->ue_mapping, (uint64_t)data_req_p->rnti, (void **)&gtpv1u_ue_data_p);
 
       if (hash_rc == HASH_TABLE_KEY_NOT_EXISTS) {
         LOG_E(GTPU, "nwGtpv1uProcessUlpReq failed: while getting ue rnti %x in hashtable ue_mapping\n", data_req_p->rnti);
       } else {
-        if ((data_req_p->rab_id >= GTPV1U_BEARER_OFFSET) && (data_req_p->rab_id <= max_val_DRB_Identity)) {
+        if ((data_req_p->rab_id >= GTPV1U_BEARER_OFFSET) && (data_req_p->rab_id <= max_val_LTE_DRB_Identity)) {
           enb_s1u_teid                        = gtpv1u_ue_data_p->bearers[data_req_p->rab_id - GTPV1U_BEARER_OFFSET].teid_eNB;
           sgw_s1u_teid                        = gtpv1u_ue_data_p->bearers[data_req_p->rab_id - GTPV1U_BEARER_OFFSET].teid_sgw;
           stack_req.apiType                   = NW_GTPV1U_ULP_API_SEND_TPDU;
           stack_req.apiInfo.sendtoInfo.teid   = sgw_s1u_teid;
           stack_req.apiInfo.sendtoInfo.ipAddr = gtpv1u_ue_data_p->bearers[data_req_p->rab_id - GTPV1U_BEARER_OFFSET].sgw_ip_addr;
-
           rc = nwGtpv1uGpduMsgNew(
                  RC.gtpv1u_data_g->gtpv1u_stack,
                  sgw_s1u_teid,
@@ -1072,7 +1005,7 @@ void *gtpv1u_eNB_process_itti_msg(void *notUsed) {
           if (rc != NW_GTPV1U_OK) {
             LOG_E(GTPU, "nwGtpv1uGpduMsgNew failed: 0x%x\n", rc);
             MSC_LOG_EVENT(MSC_GTPU_ENB,"0 Failed send G-PDU ltid %u rtid %u size %u",
-            		enb_s1u_teid,sgw_s1u_teid,data_req_p->length);
+                          enb_s1u_teid,sgw_s1u_teid,data_req_p->length);
             (void)enb_s1u_teid; /* avoid gcc warning "set but not used" */
           } else {
             rc = nwGtpv1uProcessUlpReq(RC.gtpv1u_data_g->gtpv1u_stack, &stack_req);
@@ -1080,19 +1013,18 @@ void *gtpv1u_eNB_process_itti_msg(void *notUsed) {
             if (rc != NW_GTPV1U_OK) {
               LOG_E(GTPU, "nwGtpv1uProcessUlpReq failed: 0x%x\n", rc);
               MSC_LOG_EVENT(MSC_GTPU_ENB,"0 Failed send G-PDU ltid %u rtid %u size %u",
-              		enb_s1u_teid,sgw_s1u_teid,data_req_p->length);
+                            enb_s1u_teid,sgw_s1u_teid,data_req_p->length);
             } else {
-            	  MSC_LOG_TX_MESSAGE(
-            			  MSC_GTPU_ENB,
-            			  MSC_GTPU_SGW,
-            			  NULL,
-            			  0,
-            			  MSC_AS_TIME_FMT" G-PDU ltid %u rtid %u size %u",
-            			  0,0,
-            			  enb_s1u_teid,
-            			  sgw_s1u_teid,
-            			  data_req_p->length);
-
+              MSC_LOG_TX_MESSAGE(
+                MSC_GTPU_ENB,
+                MSC_GTPU_SGW,
+                NULL,
+                0,
+                MSC_AS_TIME_FMT" G-PDU ltid %u rtid %u size %u",
+                0,0,
+                enb_s1u_teid,
+                sgw_s1u_teid,
+                data_req_p->length);
             }
 
             rc = nwGtpv1uMsgDelete(RC.gtpv1u_data_g->gtpv1u_stack,
@@ -1113,11 +1045,11 @@ void *gtpv1u_eNB_process_itti_msg(void *notUsed) {
 
     case TERMINATE_MESSAGE: {
       if (RC.gtpv1u_data_g->ue_mapping != NULL) {
-        hashtable_destroy (RC.gtpv1u_data_g->ue_mapping);
+        hashtable_destroy (&(RC.gtpv1u_data_g->ue_mapping));
       }
 
       if (RC.gtpv1u_data_g->teid_mapping != NULL) {
-        hashtable_destroy (RC.gtpv1u_data_g->teid_mapping);
+        hashtable_destroy (&(RC.gtpv1u_data_g->teid_mapping));
       }
 
       LOG_W(GTPU, " *** Exiting GTPU thread\n");
@@ -1135,21 +1067,18 @@ void *gtpv1u_eNB_process_itti_msg(void *notUsed) {
             ITTI_MSG_NAME(received_message_p));
     }
     break;
-    }
-
-    rc = itti_free(ITTI_MSG_ORIGIN_ID(received_message_p), received_message_p);
-    AssertFatal(rc == EXIT_SUCCESS, "Failed to free memory (%d)!\n", rc);
-    received_message_p = NULL;
-    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_GTPV1U_ENB_TASK, VCD_FUNCTION_OUT);
+  }
 
-    return NULL;
+  rc = itti_free(ITTI_MSG_ORIGIN_ID(received_message_p), received_message_p);
+  AssertFatal(rc == EXIT_SUCCESS, "Failed to free memory (%d)!\n", rc);
+  received_message_p = NULL;
+  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_GTPV1U_ENB_TASK, VCD_FUNCTION_OUT);
+  return NULL;
 }
 
 //-----------------------------------------------------------------------------
-void *gtpv1u_eNB_task(void *args)
-{
+void *gtpv1u_eNB_task(void *args) {
   int rc = 0;
-
   rc = gtpv1u_eNB_init();
   AssertFatal(rc == 0, "gtpv1u_eNB_init Failed");
   itti_mark_task_ready(TASK_GTPV1_U);
diff --git a/openair3/GTPV1-U/gtpv1u_eNB_defs.h b/openair3/GTPV1-U/gtpv1u_eNB_defs.h
index db928c4438d927cd333b59ac6caaef3b72513198..978a3c58bc01731a463bde048fcac72cb07a836a 100644
--- a/openair3/GTPV1-U/gtpv1u_eNB_defs.h
+++ b/openair3/GTPV1-U/gtpv1u_eNB_defs.h
@@ -28,7 +28,7 @@
  */
 
 #include "hashtable.h"
-#include "asn_constant.h"
+#include "LTE_asn_constant.h"
 
 #ifndef GTPV1U_ENB_DEFS_H_
 #define GTPV1U_ENB_DEFS_H_
@@ -38,7 +38,7 @@
 #define GTPV1U_UDP_PORT (2152)
 #define GTPV1U_BEARER_OFFSET 3
 
-#define GTPV1U_MAX_BEARERS_ID     (max_val_DRB_Identity - GTPV1U_BEARER_OFFSET)
+#define GTPV1U_MAX_BEARERS_ID     (max_val_LTE_DRB_Identity - GTPV1U_BEARER_OFFSET)
 
 typedef enum {
   BEARER_DOWN = 0,
diff --git a/openair3/GTPV1-U/gtpv1u_task.c b/openair3/GTPV1-U/gtpv1u_task.c
index e821885ab5198055484b183f12eef1411b243b9a..1339839cf971edd203f2e9100a769a7b4df9ac26 100644
--- a/openair3/GTPV1-U/gtpv1u_task.c
+++ b/openair3/GTPV1-U/gtpv1u_task.c
@@ -95,7 +95,7 @@ void gtpu_print_hex_octets(unsigned char* dataP, unsigned long sizeP)
   h = tv.tv_sec/3600/24;
   m = (tv.tv_sec / 60) % 60;
   s = tv.tv_sec % 60;
-  snprintf(timeofday, 64, "%02d:%02d:%02d.%06d", h,m,s,tv.tv_usec);
+  snprintf(timeofday, 64, "%02u:%02u:%02u.%06d", h,m,s,tv.tv_usec);
 
   GTPU_DEBUG("%s------+-------------------------------------------------|\n",timeofday);
   GTPU_DEBUG("%s      |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |\n",timeofday);
@@ -116,7 +116,7 @@ void gtpu_print_hex_octets(unsigned char* dataP, unsigned long sizeP)
         buffer_marker = 0;
       }
 
-      buffer_marker+=snprintf(&gtpu_2_print_buffer[buffer_marker], GTPU_2_PRINT_BUFFER_LEN - buffer_marker, " %04ld |", octet_index);
+      buffer_marker+=snprintf(&gtpu_2_print_buffer[buffer_marker], GTPU_2_PRINT_BUFFER_LEN - buffer_marker, " %04lu |", octet_index);
     }
 
     /*
diff --git a/openair3/GTPV1-U/nw-gtpv1u/src/NwGtpv1u.c b/openair3/GTPV1-U/nw-gtpv1u/src/NwGtpv1u.c
index eb27189a6133b6785b43c5539e11d09573d57ed8..3e8da5d015faa56051c35f48185908137d81afeb 100644
--- a/openair3/GTPV1-U/nw-gtpv1u/src/NwGtpv1u.c
+++ b/openair3/GTPV1-U/nw-gtpv1u/src/NwGtpv1u.c
@@ -689,9 +689,9 @@ nwGtpv1uInitialize( NW_INOUT NwGtpv1uStackHandleT *hGtpuStackHandle, uint32_t st
   NwGtpv1uStackT *thiz;
 
   thiz = (NwGtpv1uStackT *) malloc( sizeof(NwGtpv1uStackT));
-  memset(thiz, 0, sizeof(NwGtpv1uStackT));
 
   if(thiz) {
+    memset(thiz, 0, sizeof(NwGtpv1uStackT));
     thiz->id    = (NwPtrT)thiz;
     thiz->stackType = stackType;
     thiz->seq   = (uint16_t) ((uintptr_t)thiz) ; // FIXME interesting casts... don't know what this is good for...
@@ -892,6 +892,11 @@ nwGtpv1uProcessUdpReq( NW_IN NwGtpv1uStackHandleT hGtpuStackHandle,
     ret = nwGtpv1uProcessGpdu(thiz, udpData, udpDataLen, peerIp);
     break;
 
+  case NW_GTP_END_MARKER:
+    GTPU_DEBUG("NW_GTP_END_MARKER\n");
+    ret = NW_GTPV1U_OK;
+    break;
+
   default:
     ret = NW_GTPV1U_FAILURE;
     NW_ASSERT(0);
diff --git a/openair3/GTPV1-U/nw-gtpv1u/test-app/nw-helloworld/NwMiniLogMgrEntity.h b/openair3/GTPV1-U/nw-gtpv1u/test-app/nw-helloworld/NwMiniLogMgrEntity.h
index ffa9c0c85e7814932729a92baf2727472d804896..8f2908e52aa182f11d8067d4c005addf4f01f778 100644
--- a/openair3/GTPV1-U/nw-gtpv1u/test-app/nw-helloworld/NwMiniLogMgrEntity.h
+++ b/openair3/GTPV1-U/nw-gtpv1u/test-app/nw-helloworld/NwMiniLogMgrEntity.h
@@ -32,7 +32,7 @@ extern uint32_t g_log_level;
     {                                                                   \
       char _logStr[1024];                                               \
       snprintf(_logStr, 1024, __VA_ARGS__);                             \
-      printf("NWGTPv2U-APP  %s - %s <%s,%u>\n", gLogLevelStr[_logLevel], _logStr, basename(__FILE__), __LINE__);\
+      printf("NWGTPv2U-APP  %s - %s <%s,%d>\n", gLogLevelStr[_logLevel], _logStr, basename(__FILE__), __LINE__);\
     }                                                                   \
   } while(0)
 
diff --git a/openair3/GTPV1-U/nw-gtpv1u/test-app/nw-helloworld/NwMiniTmrMgrEntity.c b/openair3/GTPV1-U/nw-gtpv1u/test-app/nw-helloworld/NwMiniTmrMgrEntity.c
index f6102d52508057c7e9f24de0c3bc63bb2beba1d8..63ad59b23f82b5cd731305a8c1258b48efe5cd37 100644
--- a/openair3/GTPV1-U/nw-gtpv1u/test-app/nw-helloworld/NwMiniTmrMgrEntity.c
+++ b/openair3/GTPV1-U/nw-gtpv1u/test-app/nw-helloworld/NwMiniTmrMgrEntity.c
@@ -64,8 +64,8 @@ NwGtpv1uRcT nwTimerStart( NwGtpv1uTimerMgrHandleT tmrMgrHandle,
   struct timeval tv;
 
   NW_LOG(NW_LOG_LEVEL_INFO,
-         "Received start timer request from stack with timer type %u, arg %x, for %u sec and %u usec",
-         tmrType, timeoutArg, timeoutSec, timeoutUsec);
+         "Received start timer request from stack with timer type %d , arg %x, for %d sec and %d usec",
+         tmrType, (unsigned int)timeoutArg, timeoutSec, timeoutUsec);
 
   pTmr = (NwMiniTmrMgrEntityT *) malloc (sizeof(NwMiniTmrMgrEntityT));
 
@@ -90,7 +90,7 @@ NwGtpv1uRcT nwTimerStop( NwGtpv1uTimerMgrHandleT tmrMgrHandle,
                          NwGtpv1uTimerHandleT hTmr)
 {
   NW_LOG(NW_LOG_LEVEL_INFO,
-         "Received stop timer request from stack for timer handle %u", hTmr);
+         "Received stop timer request from stack for timer handle %d", hTmr);
   evtimer_del(&(((NwMiniTmrMgrEntityT *)hTmr)->ev));
   free((void *)hTmr);
   return NW_GTPV1U_OK;
diff --git a/openair3/NAS/COMMON/API/NETWORK/l2_message.h b/openair3/NAS/COMMON/API/NETWORK/l2_message.h
deleted file mode 100644
index 9cf65b7736db6c01c89ac0f8442e84114ab81916..0000000000000000000000000000000000000000
--- a/openair3/NAS/COMMON/API/NETWORK/l2_message.h
+++ /dev/null
@@ -1,310 +0,0 @@
-/*
- * 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
- */
-
-/*****************************************************************************
-
-Source    as_message.h
-
-Version   0.1
-
-Date    2012/10/18
-
-Product   NAS stack
-
-Subsystem Application Programming Interface
-
-Author    Frederic Maurel
-
-Description Defines the messages supported by the Access Stratum sublayer
-    protocol (usually RRC and S1AP for E-UTRAN) and functions used
-    to encode and decode
-
-*****************************************************************************/
-#ifndef __AS_MESSAGE_H__
-#define __AS_MESSAGE_H__
-
-#include "commonDef.h"
-#include "networkDef.h"
-
-/****************************************************************************/
-/*********************  G L O B A L    C O N S T A N T S  *******************/
-/****************************************************************************/
-
-/* Access Stratum Message types */
-#define AS_REQUEST  0x0100
-#define AS_RESPONSE 0x0200
-#define AS_INDICATION 0x0400
-#define AS_CONFIRM  0x0800
-
-/*
- * Access Stratum Message identifiers
- * ----------------------------------
- */
-
-/* Cell information relevant for cell selection processing */
-#define AS_CELL_INFO      0x01
-#define AS_CELL_INFO_REQ    (AS_CELL_INFO | AS_REQUEST)
-#define AS_CELL_INFO_RSP    (AS_CELL_INFO | AS_RESPONSE)
-#define AS_CELL_INFO_IND    (AS_CELL_INFO | AS_INDICATION)
-
-/* Security mode control */
-#define AS_SECURITY     0x02
-#define AS_SECURITY_REQ     (AS_SECURITY | AS_REQUEST)
-#define AS_SECURITY_RSP     (AS_SECURITY | AS_RESPONSE)
-
-/* Paging information */
-#define AS_PAGING     0x03
-#define AS_PAGING_IND     (AS_PAGING | AS_INDICATION)
-
-/* NAS signalling connection establishment */
-#define AS_NAS_ESTABLISH    0x04
-#define AS_NAS_ESTABLISH_REQ    (AS_NAS_ESTABLISH | AS_REQUEST)
-#define AS_NAS_ESTABLISH_RSP    (AS_NAS_ESTABLISH | AS_RESPONSE)
-
-/* NAS signalling connection release */
-#define AS_NAS_RELEASE      0x05
-#define AS_NAS_RELEASE_REQ    (AS_NAS_RELEASE | AS_REQUEST)
-#define AS_NAS_RELEASE_IND    (AS_NAS_RELEASE | AS_INDICATION)
-
-/* NAS information transfer */
-#define AS_INFO_TRANSFER    0x10
-#define AS_UL_INFO_TRANSFER   (AS_INFO_TRANSFER | AS_REQUEST)
-#define AS_DL_INFO_TRANSFER   (AS_INFO_TRANSFER | AS_INDICATION)
-
-/****************************************************************************/
-/************************  G L O B A L    T Y P E S  ************************/
-/****************************************************************************/
-
-/*
- * --------------------------------------------------------------------------
- *      Available PLMNs and cell Information
- * --------------------------------------------------------------------------
- */
-
-/* Radio access technologies supported by the network */
-#define AS_GSM        (1 << NET_ACCESS_GSM)
-#define AS_COMPACT      (1 << NET_ACCESS_COMPACT)
-#define AS_UTRAN      (1 << NET_ACCESS_UTRAN)
-#define AS_EGPRS      (1 << NET_ACCESS_EGPRS)
-#define AS_HSDPA      (1 << NET_ACCESS_HSDPA)
-#define AS_HSUPA      (1 << NET_ACCESS_HSUPA)
-#define AS_HSDUPA     (1 << NET_ACCESS_HSDUPA)
-#define AS_EUTRAN     (1 << NET_ACCESS_EUTRAN)
-
-/*
- * NAS->AS -K_eNB refresh request
- * NAS request AS to refresh its KeNB key
- */
-typedef struct kenb_refresh_req_s {
-  Byte_t kenb[32];
-} kenb_refresh_req_t;
-
-/*
- * NAS->AS - Cell Information request
- * NAS request AS to search for a suitable cell belonging to the selected
- * PLMN to camp on.
- */
-typedef struct {
-  plmn_t plmnID;  /* PLMN identifier         */
-  Byte_t rat;   /* Bitmap - set of radio access technologies   */
-} cell_info_req_t;
-
-/*
- * AS->NAS - Cell Information response
- * AS search for a suitable cell and respond to NAS. If found, the cell
- * is selected to camp on.
- */
-typedef struct {
-  plmn_t plmnID;  /* PLMN identifier          */
-  TAC_t tac;    /* identifies a tracking area the PLMN belongs to */
-  CI_t cellID;  /* identifies a cell within a PLMN      */
-  AcT_t rat;    /* radio access technology supported by the cell  */
-} cell_info_rsp_t;
-
-/*
- * AS->NAS - Cell Information indication
- * AS Reports available PLMNs with associated Radio Access Technologies
- * to NAS on request from NAS or autonomously.
- */
-typedef struct {
-#define PLMN_LIST_MAX_SIZE  6
-  PLMN_LIST_T(PLMN_LIST_MAX_SIZE) plmnIDs; /* List of PLMN identifiers */
-  Byte_t rat[PLMN_LIST_MAX_SIZE]; /* Radio access technologies   */
-  TAC_t tac; /* identifies a tracking area within a scope of PLMNs   */
-  CI_t cellID;  /* identifies a cell within a PLMN     */
-} cell_info_ind_t;
-
-/*
- * --------------------------------------------------------------------------
- *        Security mode control
- * --------------------------------------------------------------------------
- */
-
-/*
- * TODO: NAS->AS - Security command request
- */
-typedef struct {} security_req_t;
-
-
-/*
- * TODO: AS->NAS - Security command response
- */
-typedef struct {} security_rsp_t;
-
-
-/*
- * --------------------------------------------------------------------------
- *        Paging information
- * --------------------------------------------------------------------------
- */
-
-/*
- * TODO: AS->NAS - Paging Information indication
- */
-typedef struct {} paging_ind_t;
-
-/*
- * --------------------------------------------------------------------------
- *      NAS signalling connection establishment
- * --------------------------------------------------------------------------
- */
-
-/* Cause of RRC connection establishment */
-#define AS_CAUSE_EMERGENCY    (NET_ESTABLISH_CAUSE_EMERGENCY)
-#define AS_CAUSE_HIGH_PRIO    (NET_ESTABLISH_CAUSE_HIGH_PRIO)
-#define AS_CAUSE_MT_ACCESS    (NET_ESTABLISH_CAUSE_MT_ACCESS)
-#define AS_CAUSE_MO_SIGNAL    (NET_ESTABLISH_CAUSE_MO_SIGNAL)
-#define AS_CAUSE_MO_DATA    (NET_ESTABLISH_CAUSE_MO_DATA)
-#define AS_CAUSE_V1020      (NET_ESTABLISH_CAUSE_V1020)
-
-/* Type of the call associated to the RRC connection establishment */
-#define AS_TYPE_ORIGINATING_SIGNAL  (NET_ESTABLISH_TYPE_ORIGINATING_SIGNAL)
-#define AS_TYPE_EMERGENCY_CALLS   (NET_ESTABLISH_TYPE_EMERGENCY_CALLS)
-#define AS_TYPE_ORIGINATING_CALLS (NET_ESTABLISH_TYPE_ORIGINATING_CALLS)
-#define AS_TYPE_TERMINATING_CALLS (NET_ESTABLISH_TYPE_TERMINATING_CALLS)
-#define AS_TYPE_MO_CS_FALLBACK    (NET_ESTABLISH_TYPE_MO_CS_FALLBACK)
-
-
-/* Structure of the SAE Temporary Mobile Subscriber Identity */
-typedef struct {
-  uint8_t MMEcode;  /* MME code that allocated the GUTI   */
-  uint32_t m_tmsi;  /* M-Temporary Mobile Subscriber Identity */
-} as_stmsi_t;
-
-/* Structure of the dedicated NAS information */
-typedef struct {
-  uint32_t length;  /* Length of the NAS information data   */
-  Byte_t* data; /* Dedicated NAS information data container */
-} as_nas_info_t;
-
-/*
- * NAS->AS - NAS signalling connection establishment request
- * NAS request AS to perform the RRC connection establishment procedure
- * to transfer initial NAS message to the network while UE is in IDLE mode.
- */
-typedef struct {
-  uint8_t cause;    /* Connection establishment cause     */
-  uint8_t type;   /* Associated call type         */
-  plmn_t plmnID;    /* Identifier of the selected PLMN      */
-  as_stmsi_t s_tmsi;    /* SAE Temporary Mobile Subscriber Identity */
-  as_nas_info_t initialNasMsg;/* Initial NAS message to transfer      */
-} nas_establish_req_t;
-
-/*
- * TODO: AS->NAS - NAS signalling connection establishment response
- */
-typedef struct {} nas_establish_rsp_t;
-
-/*
- * --------------------------------------------------------------------------
- *      NAS signalling connection release
- * --------------------------------------------------------------------------
- */
-
-/*
- * TODO: NAS->AS - NAS signalling connection release request
- */
-typedef struct {} nas_release_req_t;
-
-/*
- * TODO: AS->NAS - NAS signalling connection release indication
- */
-typedef struct {} nas_release_ind_t;
-
-/*
- * --------------------------------------------------------------------------
- *        NAS information transfer
- * --------------------------------------------------------------------------
- */
-
-/*
- * AS->NAS - Downlink data transfer
- * AS notifies upper layer that NAS or non-3GPP dedicated downlink information
- * has to be transfered to NAS.
-*/
-typedef as_nas_info_t dl_info_transfer_t;
-
-/*
- * NAS->AS - Uplink data transfer request
- * NAS requests under layer to transfer NAS or non-3GPP dedicated uplink
- * information to AS.
- */
-typedef as_nas_info_t ul_info_transfer_t;
-
-/*
- * --------------------------------------------------------------------------
- *  Structure of the AS messages handled by the network sublayer
- * --------------------------------------------------------------------------
- */
-typedef struct {
-  uint16_t msgID;
-  union {
-    cell_info_req_t cell_info_req;
-    cell_info_rsp_t cell_info_rsp;
-    cell_info_ind_t cell_info_ind;
-    security_req_t security_req;
-    security_rsp_t security_rsp;
-    paging_ind_t paging_ind;
-    nas_establish_req_t nas_establish_req;
-    nas_establish_rsp_t nas_establish_rsp;
-    nas_release_req_t nas_release_req;
-    nas_release_ind_t nas_release_ind;
-    ul_info_transfer_t ul_info_transfer;
-    dl_info_transfer_t dl_info_transfer;
-  } __attribute__((__packed__)) msg;
-} as_message_t;
-
-/****************************************************************************/
-/********************  G L O B A L    V A R I A B L E S  ********************/
-/****************************************************************************/
-
-/****************************************************************************/
-/******************  E X P O R T E D    F U N C T I O N S  ******************/
-/****************************************************************************/
-
-int as_message_decode(const char* buffer, int length, as_message_t* msg);
-
-int as_message_encode(char* buffer, int length, const as_message_t* msg);
-
-/* Implemented in the network_api.c body file */
-int as_message_send(as_message_t* as_msg, const void* nas_msg);
-
-#endif /* __AS_MESSAGE_H__*/
diff --git a/openair3/NAS/COMMON/UTIL/tst/timer.c b/openair3/NAS/COMMON/UTIL/tst/timer.c
index 701c878f4de3f5cd728109d20c9d928de44e31c7..2215bcee2d1ff2241f50be34712072be4afecdee 100644
--- a/openair3/NAS/COMMON/UTIL/tst/timer.c
+++ b/openair3/NAS/COMMON/UTIL/tst/timer.c
@@ -96,7 +96,7 @@ int main (int argc, const char* argv[])
   /* Start NB_TIMERS_MAX timers to expire at time interval of 1s */
   for (int i=0; i < NB_TIMERS_MAX; i++) {
     if (_start(&timer[i], i) != RETURNok) {
-      printf("ERROR: timer_start(i=%u) failed\n", i);
+      printf("ERROR: timer_start(i=%d) failed\n", i);
     }
   }
 
diff --git a/openair3/NAS/TEST/NETWORK/network_simulator.c b/openair3/NAS/TEST/NETWORK/network_simulator.c
index 294241a3845fbf6d663daad85365a16d707d6c34..461f701f95181d08a1c8cd2cb4a6a6de7dc33f8e 100644
--- a/openair3/NAS/TEST/NETWORK/network_simulator.c
+++ b/openair3/NAS/TEST/NETWORK/network_simulator.c
@@ -319,7 +319,7 @@ int main (int argc, const char* argv[])
       _network_simulator_msg_sent += 1;
     }
 
-    printf("\nINFO\t: %d messages received, %d messages sent\n",
+    printf("\nINFO\t: %u messages received, %u messages sent\n",
            _network_simulator_msg_recv, _network_simulator_msg_sent);
   }
 
diff --git a/openair3/NAS/TEST/USER/user_simulator.c b/openair3/NAS/TEST/USER/user_simulator.c
index fa015df30af33599815c5341059ba2a831716964..1c429c3b8508c1b766d0c27a0d1289d3d2edb8a7 100644
--- a/openair3/NAS/TEST/USER/user_simulator.c
+++ b/openair3/NAS/TEST/USER/user_simulator.c
@@ -143,7 +143,7 @@ int main (int argc, const char* argv[])
     }
 
     printf("INFO\t: The User Simulator is now connected to %s (%d)\n",
-           devpath, USER_GETFD());
+           devpath, (int)USER_GETFD());
   } else {
     /* Initialize network socket handlers */
     _user_simulator_id.open  = socket_udp_open;
@@ -163,7 +163,7 @@ int main (int argc, const char* argv[])
     }
 
     printf("INFO\t: The User Simulator is now connected to %s/%s (%d)\n",
-           host, port, USER_GETFD());
+           host, port, (int)USER_GETFD());
   }
 
 
@@ -231,7 +231,7 @@ int main (int argc, const char* argv[])
   /*
    * Termination cleanup
    */
-  printf("INFO\t: Closing user endpoint descriptor %d\n", USER_GETFD());
+  printf("INFO\t: Closing user endpoint descriptor %d\n", (int)USER_GETFD());
   USER_CLOSE();
 
   printf("INFO\t: User simulator exited\n");
@@ -282,7 +282,7 @@ static int _set_signal_handler(int signal, void (handler)(int))
 static void _signal_handler(int signal_number)
 {
   printf("\nWARNING\t: Signal %d received\n", signal_number);
-  printf("INFO\t: Closing user socket %d\n", USER_GETFD());
+  printf("INFO\t: Closing user socket %d\n", (int)USER_GETFD());
   USER_CLOSE();
   printf("INFO\t: User simulator exited\n");
   exit(EXIT_SUCCESS);
diff --git a/openair3/NAS/TOOLS/network.h b/openair3/NAS/TOOLS/network.h
deleted file mode 100644
index cde82f4560cc6039f90ea85068e5d3f321af082a..0000000000000000000000000000000000000000
--- a/openair3/NAS/TOOLS/network.h
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * 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
- */
-
-/*****************************************************************************
-Source    network.h
-
-Version   0.1
-
-Date    2013/03/26
-
-Product   USIM data generator
-
-Subsystem PLMN network operators
-
-Author    Frederic Maurel
-
-Description Defines a list of PLMN network operators
-
-*****************************************************************************/
-#ifndef __NETWORK_H__
-#define __NETWORK_H__
-
-#include "commonDef.h"
-#include "networkDef.h"
-
-/****************************************************************************/
-/*********************  G L O B A L    C O N S T A N T S  *******************/
-/****************************************************************************/
-/*
- * PLMN network operator record index
- */
-#define TEST1 0
-#define SFR1  1
-#define SFR2  2
-#define SFR3  3
-#define OAI_LTEBOX 4
-#define TM1   5
-#define FCT1  6
-#define VDF1  7
-#define VDF2  8
-#define VDF3  9
-#define VDF4  10
-#define VDF5  11
-
-
-#define SELECTED_PLMN TEST1 //SFR1
-
-#define TEST_PLMN {0,0,0x0f,1,1,0}  // 00101
-#define SFR_PLMN_1  {0,2,0x0f,8,0,1}  // 20810
-#define SFR_PLMN_2  {0,2,0x0f,8,1,1}  // 20811
-#define SFR_PLMN_3  {0,2,0x0f,8,3,1}  // 20813
-#define OAI_LTEBOX_PLMN  {0,2,0x0f,8,3,9}  //20893
-#define TM_PLMN_1   {1,3,0,0,8,2}       // 310280
-#define FCT_PLMN_1  {1,3,8,0,2,0}       // 310028
-#define VDF_PLMN_1  {2,2,0x0f,2,0,1}  // 22210
-#define VDF_PLMN_2  {1,2,0x0f,4,0x0f,1} // 2141
-#define VDF_PLMN_3  {1,2,0x0f,4,0x0f,6} // 2146
-#define VDF_PLMN_4  {6,2,0x0f,2,0x0f,2} // 2622
-#define VDF_PLMN_5  {6,2,0x0f,2,0x0f,4} // 2624
-
-
-/****************************************************************************/
-/************************  G L O B A L    T Y P E S  ************************/
-/****************************************************************************/
-
-/*
- * PLMN network operator record
- */
-typedef struct {
-  unsigned int num;
-  plmn_t plmn;
-  char fullname[NET_FORMAT_LONG_SIZE + 1];
-  char shortname[NET_FORMAT_SHORT_SIZE + 1];
-  tac_t tac_start;
-  tac_t tac_end;
-} network_record_t;
-
-
-/****************************************************************************/
-/********************  G L O B A L    V A R I A B L E S  ********************/
-/****************************************************************************/
-
-/*
- * The list of PLMN network operator records
- */
-network_record_t network_records[] = {
-  {00101, TEST_PLMN, "Test network",     "OAI4G",     0x0001, 0xfffd},
-  {20810, SFR_PLMN_1, "SFR France",      "SFR",       0x0001, 0xfffd},
-  {20811, SFR_PLMN_2, "SFR France",      "SFR",       0x0001, 0xfffd},
-  {20813, SFR_PLMN_3, "SFR France",      "SFR",       0x0001, 0xfffd},
-  {20893, OAI_LTEBOX_PLMN, "OAI LTEBOX",   "OAIALU",  0x0001, 0xfffd},
-  {310280,TM_PLMN_1,  "T-Mobile USA",    "T-Mobile",  0x0001, 0xfffd},
-  {310028,FCT_PLMN_1, "FICTITIOUS USA",  "FICTITIO",  0x0001, 0xfffd},
-  {22210, VDF_PLMN_1, "Vodafone Italia", "VODAFONE",  0x0001, 0xfffd},
-  {2141,  VDF_PLMN_2, "Vodafone Spain",  "VODAFONE",  0x0001, 0xfffd},
-  {2146,  VDF_PLMN_3, "Vodafone Spain",  "VODAFONE",  0x0001, 0xfffd},
-  {2622,  VDF_PLMN_4, "Vodafone Germ",   "VODAFONE",  0x0001, 0xfffd},
-  {2624,  VDF_PLMN_5, "Vodafone Germ",   "VODAFONE",  0x0001, 0xfffd},
-};
-
-/****************************************************************************/
-/******************  E X P O R T E D    F U N C T I O N S  ******************/
-/****************************************************************************/
-
-#endif /* __NETWORK_H__*/
diff --git a/openair3/NAS/UE/API/USER/at_response.c b/openair3/NAS/UE/API/USER/at_response.c
index a488aa78d9f7c949564c3553150e040b36981fa8..859db90d7e0d5393045771260e30b35f968e7484 100644
--- a/openair3/NAS/UE/API/USER/at_response.c
+++ b/openair3/NAS/UE/API/USER/at_response.c
@@ -88,41 +88,41 @@ static int _at_response_encode_cgev   (char* buffer, const at_response_t* data);
 typedef int (*_at_response_encode_function_t) (char* buffer, const at_response_t*);
 
 static _at_response_encode_function_t _at_response_encode_function[AT_RESPONSE_ID_MAX] = {
-  NULL,
-  _at_response_encode_cgsn,   /* CGSN    */
-  _at_response_encode_cgmi,   /* CGMI    */
-  _at_response_encode_cgmm,   /* CGMM    */
-  _at_response_encode_cgmr,   /* CGMR    */
-  _at_response_encode_cimi,   /* CIMI    */
-  _at_response_encode_cfun,   /* CFUN    */
-  _at_response_encode_cpin,   /* CPIN    */
-  _at_response_encode_csq,    /* CSQ     */
-  _at_response_encode_cesq,   /* CESQ    */
-  _at_response_encode_clac,   /* CLAC    */
-  _at_response_encode_cmee,   /* CMEE    */
-  _at_response_encode_cnum,   /* CNUM    */
-  _at_response_encode_clck,   /* CLCK    */
-  _at_response_encode_cops,   /* COPS    */
-  _at_response_encode_creg,   /* CREG    */
-  _at_response_encode_cgatt,    /* CGATT   */
-  _at_response_encode_cgreg,    /* CGREG   */
-  _at_response_encode_cereg,    /* CEREG   */
-  _at_response_encode_cgdcont,  /* CGDCONT */
-  _at_response_encode_cgact,    /* CGACT   */
-  _at_response_encode_cgpaddr,  /* CGPADDR */
-  _at_response_encode_cgev,   /* CGEV: unsolicited result */
+    NULL,
+    _at_response_encode_cgsn,   /* CGSN    */
+    _at_response_encode_cgmi,   /* CGMI    */
+    _at_response_encode_cgmm,   /* CGMM    */
+    _at_response_encode_cgmr,   /* CGMR    */
+    _at_response_encode_cimi,   /* CIMI    */
+    _at_response_encode_cfun,   /* CFUN    */
+    _at_response_encode_cpin,   /* CPIN    */
+    _at_response_encode_csq,    /* CSQ     */
+    _at_response_encode_cesq,   /* CESQ    */
+    _at_response_encode_clac,   /* CLAC    */
+    _at_response_encode_cmee,   /* CMEE    */
+    _at_response_encode_cnum,   /* CNUM    */
+    _at_response_encode_clck,   /* CLCK    */
+    _at_response_encode_cops,   /* COPS    */
+    _at_response_encode_creg,   /* CREG    */
+    _at_response_encode_cgatt,    /* CGATT   */
+    _at_response_encode_cgreg,    /* CGREG   */
+    _at_response_encode_cereg,    /* CEREG   */
+    _at_response_encode_cgdcont,  /* CGDCONT */
+    _at_response_encode_cgact,    /* CGACT   */
+    _at_response_encode_cgpaddr,  /* CGPADDR */
+    _at_response_encode_cgev,   /* CGEV: unsolicited result */
 };
 
 /* String representation of Packet Domain events (cf. network_pdn_state_t) */
 static const char* _at_response_event_str[] = {
-  "UNKNOWN EVENT",
-  "ME PDN ACT",
-  "NW PDN DEACT",
-  "ME PDN DEACT",
-  "NW ACT",
-  "ME ACT",
-  "NW DEACT",
-  "ME DEACT",
+    "UNKNOWN EVENT",
+    "ME PDN ACT",
+    "NW PDN DEACT",
+    "ME PDN DEACT",
+    "NW ACT",
+    "ME ACT",
+    "NW DEACT",
+    "ME DEACT",
 };
 
 /****************************************************************************/
@@ -147,24 +147,24 @@ static const char* _at_response_event_str[] = {
  ***************************************************************************/
 int at_response_encode(char* buffer, const at_response_t* at_response)
 {
-  LOG_FUNC_IN;
+    LOG_FUNC_IN;
 
-  int bytes = RETURNerror;
-  _at_response_encode_function_t encode;
+    int bytes = RETURNerror;
+    _at_response_encode_function_t encode;
 
-  if (at_response->id < AT_RESPONSE_ID_MAX) {
-    /* Call encoding function applicable to the AT command response */
-    encode = _at_response_encode_function[at_response->id];
+    if (at_response->id < AT_RESPONSE_ID_MAX) {
+        /* Call encoding function applicable to the AT command response */
+        encode = _at_response_encode_function[at_response->id];
 
-    if (encode != NULL) {
-      bytes = (*encode)(buffer, at_response);
-    } else {
-      /* Generic encoding: OK, ERROR */
-      bytes = 0;
+        if (encode != NULL) {
+            bytes = (*encode)(buffer, at_response);
+        } else {
+            /* Generic encoding: OK, ERROR */
+            bytes = 0;
+        }
     }
-  }
 
-  LOG_FUNC_RETURN (bytes);
+    LOG_FUNC_RETURN (bytes);
 }
 
 /****************************************************************************/
@@ -188,21 +188,21 @@ int at_response_encode(char* buffer, const at_response_t* at_response)
  ***************************************************************************/
 static int _at_response_encode_cgsn(char* buffer, const at_response_t* data)
 {
-  LOG_FUNC_IN;
+    LOG_FUNC_IN;
 
-  int offset = 0;
+    int offset = 0;
 
-  if (data->type == AT_COMMAND_ACT) {
-    const at_cgsn_resp_t * cgsn = &(data->response.cgsn);
+    if (data->type == AT_COMMAND_ACT) {
+        const at_cgsn_resp_t * cgsn = &(data->response.cgsn);
 
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
-    }
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
 
-    offset += sprintf(buffer+offset, "+CGSN: %s\r\n", cgsn->sn);
-  }
+        offset += sprintf(buffer+offset, "+CGSN: %s\r\n", cgsn->sn);
+    }
 
-  LOG_FUNC_RETURN (offset);
+    LOG_FUNC_RETURN (offset);
 }
 
 /****************************************************************************
@@ -222,21 +222,21 @@ static int _at_response_encode_cgsn(char* buffer, const at_response_t* data)
  ***************************************************************************/
 static int _at_response_encode_cgmi(char* buffer, const at_response_t* data)
 {
-  LOG_FUNC_IN;
+    LOG_FUNC_IN;
 
-  int offset = 0;
+    int offset = 0;
 
-  if (data->type == AT_COMMAND_ACT) {
-    const at_cgmi_resp_t * cgmi = &(data->response.cgmi);
+    if (data->type == AT_COMMAND_ACT) {
+        const at_cgmi_resp_t * cgmi = &(data->response.cgmi);
 
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
-    }
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
 
-    offset += sprintf(buffer+offset, "+CGMI: %s\r\n", cgmi->manufacturer);
-  }
+        offset += sprintf(buffer+offset, "+CGMI: %s\r\n", cgmi->manufacturer);
+    }
 
-  LOG_FUNC_RETURN (offset);
+    LOG_FUNC_RETURN (offset);
 }
 
 /****************************************************************************
@@ -256,21 +256,21 @@ static int _at_response_encode_cgmi(char* buffer, const at_response_t* data)
  ***************************************************************************/
 static int _at_response_encode_cgmm(char* buffer, const at_response_t* data)
 {
-  LOG_FUNC_IN;
+    LOG_FUNC_IN;
 
-  int offset = 0;
+    int offset = 0;
 
-  if (data->type == AT_COMMAND_ACT) {
-    const at_cgmm_resp_t * cgmm = &(data->response.cgmm);
+    if (data->type == AT_COMMAND_ACT) {
+        const at_cgmm_resp_t * cgmm = &(data->response.cgmm);
 
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
-    }
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
 
-    offset += sprintf(buffer+offset, "+CGMM: %s\r\n", cgmm->model);
-  }
+        offset += sprintf(buffer+offset, "+CGMM: %s\r\n", cgmm->model);
+    }
 
-  LOG_FUNC_RETURN (offset);
+    LOG_FUNC_RETURN (offset);
 }
 
 /****************************************************************************
@@ -290,21 +290,21 @@ static int _at_response_encode_cgmm(char* buffer, const at_response_t* data)
  ***************************************************************************/
 static int _at_response_encode_cgmr(char* buffer, const at_response_t* data)
 {
-  LOG_FUNC_IN;
+    LOG_FUNC_IN;
 
-  int offset = 0;
+    int offset = 0;
 
-  if (data->type == AT_COMMAND_ACT) {
-    const at_cgmr_resp_t * cgmr = &(data->response.cgmr);
+    if (data->type == AT_COMMAND_ACT) {
+        const at_cgmr_resp_t * cgmr = &(data->response.cgmr);
 
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
-    }
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
 
-    offset += sprintf(buffer+offset, "+CGMR: %s\r\n", cgmr->revision);
-  }
+        offset += sprintf(buffer+offset, "+CGMR: %s\r\n", cgmr->revision);
+    }
 
-  LOG_FUNC_RETURN (offset);
+    LOG_FUNC_RETURN (offset);
 }
 
 /****************************************************************************
@@ -324,21 +324,21 @@ static int _at_response_encode_cgmr(char* buffer, const at_response_t* data)
  ***************************************************************************/
 static int _at_response_encode_cimi(char* buffer, const at_response_t* data)
 {
-  LOG_FUNC_IN;
+    LOG_FUNC_IN;
 
-  int offset = 0;
+    int offset = 0;
 
-  if (data->type == AT_COMMAND_ACT) {
-    const at_cimi_resp_t * cimi = &(data->response.cimi);
+    if (data->type == AT_COMMAND_ACT) {
+        const at_cimi_resp_t * cimi = &(data->response.cimi);
 
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
-    }
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
 
-    offset += sprintf(buffer+offset, "+CIMI: %s\r\n", cimi->IMSI);
-  }
+        offset += sprintf(buffer+offset, "+CIMI: %s\r\n", cimi->IMSI);
+    }
 
-  LOG_FUNC_RETURN (offset);
+    LOG_FUNC_RETURN (offset);
 }
 
 /****************************************************************************
@@ -358,27 +358,27 @@ static int _at_response_encode_cimi(char* buffer, const at_response_t* data)
  ***************************************************************************/
 static int _at_response_encode_cfun(char* buffer, const at_response_t* data)
 {
-  LOG_FUNC_IN;
+    LOG_FUNC_IN;
 
-  const at_cfun_resp_t * cfun = &(data->response.cfun);
-  int offset = 0;
+    const at_cfun_resp_t * cfun = &(data->response.cfun);
+    int offset = 0;
 
-  if (data->type == AT_COMMAND_GET) {
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
-    }
+    if (data->type == AT_COMMAND_GET) {
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
 
-    offset += sprintf(buffer+offset, "+CFUN: %d\r\n", cfun->fun);
-  } else if (data->type == AT_COMMAND_TST) {
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
-    }
+        offset += sprintf(buffer+offset, "+CFUN: %d\r\n", cfun->fun);
+    } else if (data->type == AT_COMMAND_TST) {
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
 
-    offset += sprintf(buffer+offset, "+CFUN: (%d-%d),(%d,%d)\r\n",
-                      AT_CFUN_MIN, AT_CFUN_MAX, AT_CFUN_NORST, AT_CFUN_RST);
-  }
+        offset += sprintf(buffer+offset, "+CFUN: (%d-%d),(%d,%d)\r\n",
+                          AT_CFUN_MIN, AT_CFUN_MAX, AT_CFUN_NORST, AT_CFUN_RST);
+    }
 
-  LOG_FUNC_RETURN (offset);
+    LOG_FUNC_RETURN (offset);
 }
 
 /****************************************************************************
@@ -398,21 +398,21 @@ static int _at_response_encode_cfun(char* buffer, const at_response_t* data)
  ***************************************************************************/
 static int _at_response_encode_cpin(char* buffer, const at_response_t* data)
 {
-  LOG_FUNC_IN;
+    LOG_FUNC_IN;
 
-  int offset = 0;
+    int offset = 0;
 
-  if (data->type == AT_COMMAND_GET) {
-    const at_cpin_resp_t * cpin = &(data->response.cpin);
+    if (data->type == AT_COMMAND_GET) {
+        const at_cpin_resp_t * cpin = &(data->response.cpin);
 
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
-    }
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
 
-    offset += sprintf(buffer+offset, "+CPIN: %s\r\n", cpin->code);
-  }
+        offset += sprintf(buffer+offset, "+CPIN: %s\r\n", cpin->code);
+    }
 
-  LOG_FUNC_RETURN (offset);
+    LOG_FUNC_RETURN (offset);
 }
 
 /****************************************************************************
@@ -432,29 +432,29 @@ static int _at_response_encode_cpin(char* buffer, const at_response_t* data)
  ***************************************************************************/
 static int _at_response_encode_csq(char* buffer, const at_response_t* data)
 {
-  LOG_FUNC_IN;
-
-  const at_csq_resp_t * csq = &(data->response.csq);
-  int offset = 0;
-
-  if (data->type == AT_COMMAND_ACT) {
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
+    LOG_FUNC_IN;
+
+    const at_csq_resp_t * csq = &(data->response.csq);
+    int offset = 0;
+
+    if (data->type == AT_COMMAND_ACT) {
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
+
+        offset += sprintf(buffer+offset, "+CSQ: %d,%d\r\n",
+                          csq->rssi, csq->ber);
+    } else if (data->type == AT_COMMAND_TST) {
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
+
+        offset += sprintf(buffer+offset, "+CSQ: (%d-%d),(%d-%d)\r\n",
+                          AT_CSQ_RSSI_0, AT_CSQ_RSSI_31,
+                          AT_CSQ_BER_0, AT_CSQ_BER_7);
     }
 
-    offset += sprintf(buffer+offset, "+CSQ: %d,%d\r\n",
-                      csq->rssi, csq->ber);
-  } else if (data->type == AT_COMMAND_TST) {
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
-    }
-
-    offset += sprintf(buffer+offset, "+CSQ: (%d-%d),(%d-%d)\r\n",
-                      AT_CSQ_RSSI_0, AT_CSQ_RSSI_31,
-                      AT_CSQ_BER_0, AT_CSQ_BER_7);
-  }
-
-  LOG_FUNC_RETURN (offset);
+    LOG_FUNC_RETURN (offset);
 }
 
 /****************************************************************************
@@ -474,35 +474,35 @@ static int _at_response_encode_csq(char* buffer, const at_response_t* data)
  ***************************************************************************/
 static int _at_response_encode_cesq(char* buffer, const at_response_t* data)
 {
-  LOG_FUNC_IN;
-
-  const at_cesq_resp_t * cesq = &(data->response.cesq);
-  int offset = 0;
-
-  if (data->type == AT_COMMAND_ACT) {
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
+    LOG_FUNC_IN;
+
+    const at_cesq_resp_t * cesq = &(data->response.cesq);
+    int offset = 0;
+
+    if (data->type == AT_COMMAND_ACT) {
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
+
+        offset += sprintf(buffer+offset, "+CESQ: %d,%d,%d,%d,%d,%d\r\n",
+                          cesq->rssi, cesq->ber, cesq->rscp,
+                          cesq->ecno, cesq->rsrq, cesq->rsrp);
+    } else if (data->type == AT_COMMAND_TST) {
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
+
+        offset += sprintf(buffer+offset, "+CESQ: (%d-%d),(%d-%d),(%d-%d),"
+                          "(%d-%d),(%d-%d),(%d-%d)\r\n",
+                          AT_CESQ_RSSI_0, AT_CESQ_RSSI_31,
+                          AT_CESQ_BER_0, AT_CESQ_BER_7,
+                          AT_CESQ_RSCP_0, AT_CESQ_RSCP_96,
+                          AT_CESQ_ECNO_0, AT_CESQ_ECNO_49,
+                          AT_CESQ_RSRQ_0, AT_CESQ_RSRQ_34,
+                          AT_CESQ_RSRP_0, AT_CESQ_RSRP_97);
     }
 
-    offset += sprintf(buffer+offset, "+CESQ: %d,%d,%d,%d,%d,%d\r\n",
-                      cesq->rssi, cesq->ber, cesq->rscp,
-                      cesq->ecno, cesq->rsrq, cesq->rsrp);
-  } else if (data->type == AT_COMMAND_TST) {
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
-    }
-
-    offset += sprintf(buffer+offset, "+CESQ: (%d-%d),(%d-%d),(%d-%d),"
-                      "(%d-%d),(%d-%d),(%d-%d)\r\n",
-                      AT_CESQ_RSSI_0, AT_CESQ_RSSI_31,
-                      AT_CESQ_BER_0, AT_CESQ_BER_7,
-                      AT_CESQ_RSCP_0, AT_CESQ_RSCP_96,
-                      AT_CESQ_ECNO_0, AT_CESQ_ECNO_49,
-                      AT_CESQ_RSRQ_0, AT_CESQ_RSRQ_34,
-                      AT_CESQ_RSRP_0, AT_CESQ_RSRP_97);
-  }
-
-  LOG_FUNC_RETURN (offset);
+    LOG_FUNC_RETURN (offset);
 }
 
 /****************************************************************************
@@ -522,27 +522,27 @@ static int _at_response_encode_cesq(char* buffer, const at_response_t* data)
  ***************************************************************************/
 static int _at_response_encode_clac(char* buffer, const at_response_t* data)
 {
-  LOG_FUNC_IN;
+    LOG_FUNC_IN;
 
-  const at_clac_resp_t * clac = &(data->response.clac);
-  int offset = 0;
-  int i;
+    const at_clac_resp_t * clac = &(data->response.clac);
+    int offset = 0;
+    int i;
 
-  if (data->type == AT_COMMAND_ACT) {
-    if (clac->n_acs > 0) {
-      if (at_response_format_v1) {
-        offset += sprintf(buffer, "\r\n");
-      }
+    if (data->type == AT_COMMAND_ACT) {
+        if (clac->n_acs > 0) {
+            if (at_response_format_v1) {
+                offset += sprintf(buffer, "\r\n");
+            }
 
-      offset += sprintf(buffer+offset, "%s", clac->ac[0]);
+            offset += sprintf(buffer+offset, "%s", clac->ac[0]);
 
-      for (i = 1; i < clac->n_acs; i++) {
-        offset += sprintf(buffer+offset, "\r\n%s", clac->ac[i]);
-      }
+            for (i = 1; i < clac->n_acs; i++) {
+                offset += sprintf(buffer+offset, "\r\n%s", clac->ac[i]);
+            }
+        }
     }
-  }
 
-  LOG_FUNC_RETURN (offset);
+    LOG_FUNC_RETURN (offset);
 }
 
 /****************************************************************************
@@ -562,22 +562,22 @@ static int _at_response_encode_clac(char* buffer, const at_response_t* data)
  ***************************************************************************/
 static int _at_response_encode_cnum(char* buffer, const at_response_t* data)
 {
-  LOG_FUNC_IN;
+    LOG_FUNC_IN;
 
-  int offset = 0;
+    int offset = 0;
 
-  if (data->type == AT_COMMAND_ACT) {
-    const at_cnum_resp_t * cnum = &(data->response.cnum);
+    if (data->type == AT_COMMAND_ACT) {
+        const at_cnum_resp_t * cnum = &(data->response.cnum);
 
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
-    }
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
 
-    offset += sprintf(buffer+offset, "+CNUM: ,%s,%u\r\n",
-                      cnum->number, cnum->type);
-  }
+        offset += sprintf(buffer+offset, "+CNUM: ,%s,%u\r\n",
+                          cnum->number, (unsigned int)cnum->type);
+    }
 
-  LOG_FUNC_RETURN (offset);
+    LOG_FUNC_RETURN (offset);
 }
 
 /****************************************************************************
@@ -597,26 +597,26 @@ static int _at_response_encode_cnum(char* buffer, const at_response_t* data)
  ***************************************************************************/
 static int _at_response_encode_clck(char* buffer, const at_response_t* data)
 {
-  LOG_FUNC_IN;
+    LOG_FUNC_IN;
 
-  const at_clck_resp_t * clck = &(data->response.clck);
-  int offset = 0;
+    const at_clck_resp_t * clck = &(data->response.clck);
+    int offset = 0;
 
-  if (data->type == AT_COMMAND_SET) {
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
-    }
+    if (data->type == AT_COMMAND_SET) {
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
 
-    offset += sprintf(buffer+offset, "+CLCK: %d\r\n", clck->status);
-  } else if (data->type == AT_COMMAND_TST) {
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
-    }
+        offset += sprintf(buffer+offset, "+CLCK: %d\r\n", clck->status);
+    } else if (data->type == AT_COMMAND_TST) {
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
 
-    offset += sprintf(buffer+offset, "+CLCK: %s\r\n", AT_CLCK_SC);
-  }
+        offset += sprintf(buffer+offset, "+CLCK: %s\r\n", AT_CLCK_SC);
+    }
 
-  LOG_FUNC_RETURN (offset);
+    LOG_FUNC_RETURN (offset);
 }
 
 /****************************************************************************
@@ -636,63 +636,63 @@ static int _at_response_encode_clck(char* buffer, const at_response_t* data)
  ***************************************************************************/
 static int _at_response_encode_cops(char* buffer, const at_response_t* data)
 {
-  LOG_FUNC_IN;
-
-  int offset = 0;
-
-  if (data->type == AT_COMMAND_GET) {
-    const at_cops_get_t * cops = &(data->response.cops.get);
-
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
-    }
-
-    offset += sprintf(buffer+offset, "+COPS: %d", cops->mode);
-
-    if (data->mask & AT_COPS_RESP_OPER_MASK) {
-      /* If <oper> is present <format> must be given */
-      assert(data->mask & AT_COPS_RESP_FORMAT_MASK);
-      offset += sprintf(buffer+offset, ",%d", cops->format);
-
-      if (cops->format == AT_COPS_LONG) {
-        offset += sprintf(buffer+offset, ",%s",
-                          (char*)cops->plmn.id.alpha_long);
-      } else if (cops->format == AT_COPS_SHORT) {
-        offset += sprintf(buffer+offset, ",%s",
-                          (char*)cops->plmn.id.alpha_short);
-      } else if (cops->format == AT_COPS_NUM) {
-        offset += sprintf(buffer+offset, ",%s",
-                          (char*)cops->plmn.id.num);
-      }
+    LOG_FUNC_IN;
+
+    int offset = 0;
+
+    if (data->type == AT_COMMAND_GET) {
+        const at_cops_get_t * cops = &(data->response.cops.get);
+
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
+
+        offset += sprintf(buffer+offset, "+COPS: %d", cops->mode);
+
+        if (data->mask & AT_COPS_RESP_OPER_MASK) {
+            /* If <oper> is present <format> must be given */
+            assert(data->mask & AT_COPS_RESP_FORMAT_MASK);
+            offset += sprintf(buffer+offset, ",%d", cops->format);
+
+            if (cops->format == AT_COPS_LONG) {
+                offset += sprintf(buffer+offset, ",%s",
+                                  (char*)cops->plmn.id.alpha_long);
+            } else if (cops->format == AT_COPS_SHORT) {
+                offset += sprintf(buffer+offset, ",%s",
+                                  (char*)cops->plmn.id.alpha_short);
+            } else if (cops->format == AT_COPS_NUM) {
+                offset += sprintf(buffer+offset, ",%s",
+                                  (char*)cops->plmn.id.num);
+            }
+        }
+
+        if (data->mask & AT_COPS_RESP_ACT_MASK) {
+            offset += sprintf(buffer+offset, ",%d", cops->AcT);
+        }
+
+        offset += sprintf(buffer+offset, "\r\n");
+    } else if (data->type == AT_COMMAND_TST) {
+        const at_cops_tst_t * cops = &(data->response.cops.tst);
+
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
+
+        offset += sprintf(buffer+offset, "+COPS: ");
+
+        /* Display the list of operators present in the network */
+        strncpy(buffer+offset, cops->data, cops->size);
+        offset += cops->size;
+
+        /* Display the list of supported network registration modes and
+         * supported representation formats of network operators */
+        //offset += sprintf(buffer+offset, ",,(%d-%d),(%d,%d,%d)",
+        //      AT_COPS_AUTO, AT_COPS_MANAUTO,
+        //      AT_COPS_LONG, AT_COPS_SHORT, AT_COPS_NUM);
+        offset += sprintf(buffer+offset, "\r\n");
     }
 
-    if (data->mask & AT_COPS_RESP_ACT_MASK) {
-      offset += sprintf(buffer+offset, ",%d", cops->AcT);
-    }
-
-    offset += sprintf(buffer+offset, "\r\n");
-  } else if (data->type == AT_COMMAND_TST) {
-    const at_cops_tst_t * cops = &(data->response.cops.tst);
-
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
-    }
-
-    offset += sprintf(buffer+offset, "+COPS: ");
-
-    /* Display the list of operators present in the network */
-    strncpy(buffer+offset, cops->data, cops->size);
-    offset += cops->size;
-
-    /* Display the list of supported network registration modes and
-     * supported representation formats of network operators */
-    //offset += sprintf(buffer+offset, ",,(%d-%d),(%d,%d,%d)",
-    //      AT_COPS_AUTO, AT_COPS_MANAUTO,
-    //      AT_COPS_LONG, AT_COPS_SHORT, AT_COPS_NUM);
-    offset += sprintf(buffer+offset, "\r\n");
-  }
-
-  LOG_FUNC_RETURN (offset);
+    LOG_FUNC_RETURN (offset);
 }
 
 /****************************************************************************
@@ -712,28 +712,28 @@ static int _at_response_encode_cops(char* buffer, const at_response_t* data)
  ***************************************************************************/
 static int _at_response_encode_cgatt(char* buffer, const at_response_t* data)
 {
-  LOG_FUNC_IN;
+    LOG_FUNC_IN;
 
-  int offset = 0;
+    int offset = 0;
 
-  if (data->type == AT_COMMAND_GET) {
-    const at_cgatt_resp_t * cgatt = &(data->response.cgatt);
+    if (data->type == AT_COMMAND_GET) {
+        const at_cgatt_resp_t * cgatt = &(data->response.cgatt);
 
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
-    }
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
 
-    offset += sprintf(buffer+offset, "+CGATT: %d\r\n", cgatt->state);
-  } else if (data->type == AT_COMMAND_TST) {
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
-    }
+        offset += sprintf(buffer+offset, "+CGATT: %d\r\n", cgatt->state);
+    } else if (data->type == AT_COMMAND_TST) {
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
 
-    offset += sprintf(buffer+offset, "+CGATT: (%d,%d)\r\n",
-                      AT_CGATT_STATE_MIN, AT_CGATT_STATE_MAX);
-  }
+        offset += sprintf(buffer+offset, "+CGATT: (%d,%d)\r\n",
+                          AT_CGATT_STATE_MIN, AT_CGATT_STATE_MAX);
+    }
 
-  LOG_FUNC_RETURN (offset);
+    LOG_FUNC_RETURN (offset);
 }
 
 /****************************************************************************
@@ -753,43 +753,43 @@ static int _at_response_encode_cgatt(char* buffer, const at_response_t* data)
  ***************************************************************************/
 static int _at_response_encode_creg(char* buffer, const at_response_t* data)
 {
-  LOG_FUNC_IN;
+    LOG_FUNC_IN;
 
-  int offset = 0;
+    int offset = 0;
 
-  if (data->type == AT_COMMAND_GET) {
-    const at_creg_resp_t * creg = &(data->response.creg);
+    if (data->type == AT_COMMAND_GET) {
+        const at_creg_resp_t * creg = &(data->response.creg);
 
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
-    }
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
 
-    offset += sprintf(buffer+offset, "+CREG: %d,%d",
-                      creg->n, creg->stat);
+        offset += sprintf(buffer+offset, "+CREG: %d,%d",
+                          creg->n, creg->stat);
 
-    if (data->mask & AT_CREG_RESP_LAC_MASK) {
-      offset += sprintf(buffer+offset, ",%s", creg->lac);
-    }
+        if (data->mask & AT_CREG_RESP_LAC_MASK) {
+            offset += sprintf(buffer+offset, ",%s", creg->lac);
+        }
 
-    if (data->mask & AT_CREG_RESP_CI_MASK) {
-      offset += sprintf(buffer+offset, ",%s", creg->ci);
-    }
+        if (data->mask & AT_CREG_RESP_CI_MASK) {
+            offset += sprintf(buffer+offset, ",%s", creg->ci);
+        }
 
-    if (data->mask & AT_CREG_RESP_ACT_MASK) {
-      offset += sprintf(buffer+offset, ",%d", creg->AcT);
-    }
+        if (data->mask & AT_CREG_RESP_ACT_MASK) {
+            offset += sprintf(buffer+offset, ",%d", creg->AcT);
+        }
 
-    offset += sprintf(buffer+offset, "\r\n");
-  } else if (data->type == AT_COMMAND_TST) {
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
-    }
+        offset += sprintf(buffer+offset, "\r\n");
+    } else if (data->type == AT_COMMAND_TST) {
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
 
-    offset += sprintf(buffer+offset, "+CREG: (%d-%d)\r\n",
-                      AT_CREG_N_MIN, AT_CREG_N_MAX);
-  }
+        offset += sprintf(buffer+offset, "+CREG: (%d-%d)\r\n",
+                          AT_CREG_N_MIN, AT_CREG_N_MAX);
+    }
 
-  LOG_FUNC_RETURN (offset);
+    LOG_FUNC_RETURN (offset);
 }
 
 /****************************************************************************
@@ -809,47 +809,47 @@ static int _at_response_encode_creg(char* buffer, const at_response_t* data)
  ***************************************************************************/
 static int _at_response_encode_cgreg(char* buffer, const at_response_t* data)
 {
-  LOG_FUNC_IN;
+    LOG_FUNC_IN;
 
-  int offset = 0;
+    int offset = 0;
 
-  if (data->type == AT_COMMAND_GET) {
-    const at_cgreg_resp_t * cgreg = &(data->response.cgreg);
+    if (data->type == AT_COMMAND_GET) {
+        const at_cgreg_resp_t * cgreg = &(data->response.cgreg);
 
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
-    }
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
 
-    offset += sprintf(buffer+offset, "+CGREG: %d,%d",
-                      cgreg->n, cgreg->stat);
+        offset += sprintf(buffer+offset, "+CGREG: %d,%d",
+                          cgreg->n, cgreg->stat);
 
-    if (data->mask & AT_CGREG_RESP_LAC_MASK) {
-      offset += sprintf(buffer+offset, ",%s", cgreg->lac);
-    }
+        if (data->mask & AT_CGREG_RESP_LAC_MASK) {
+            offset += sprintf(buffer+offset, ",%s", cgreg->lac);
+        }
 
-    if (data->mask & AT_CGREG_RESP_CI_MASK) {
-      offset += sprintf(buffer+offset, ",%s", cgreg->ci);
-    }
+        if (data->mask & AT_CGREG_RESP_CI_MASK) {
+            offset += sprintf(buffer+offset, ",%s", cgreg->ci);
+        }
 
-    if (data->mask & AT_CGREG_RESP_ACT_MASK) {
-      offset += sprintf(buffer+offset, ",%d", cgreg->AcT);
-    }
+        if (data->mask & AT_CGREG_RESP_ACT_MASK) {
+            offset += sprintf(buffer+offset, ",%d", cgreg->AcT);
+        }
 
-    if (data->mask & AT_CGREG_RESP_RAC_MASK) {
-      offset += sprintf(buffer+offset, ",%s", cgreg->rac);
-    }
+        if (data->mask & AT_CGREG_RESP_RAC_MASK) {
+            offset += sprintf(buffer+offset, ",%s", cgreg->rac);
+        }
 
-    offset += sprintf(buffer+offset, "\r\n");
-  } else if (data->type == AT_COMMAND_TST) {
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
-    }
+        offset += sprintf(buffer+offset, "\r\n");
+    } else if (data->type == AT_COMMAND_TST) {
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
 
-    offset += sprintf(buffer+offset, "+CGREG: (%d-%d)\r\n",
-                      AT_CGREG_N_MIN, AT_CGREG_N_MAX);
-  }
+        offset += sprintf(buffer+offset, "+CGREG: (%d-%d)\r\n",
+                          AT_CGREG_N_MIN, AT_CGREG_N_MAX);
+    }
 
-  LOG_FUNC_RETURN (offset);
+    LOG_FUNC_RETURN (offset);
 }
 
 /****************************************************************************
@@ -869,43 +869,43 @@ static int _at_response_encode_cgreg(char* buffer, const at_response_t* data)
  ***************************************************************************/
 static int _at_response_encode_cereg(char* buffer, const at_response_t* data)
 {
-  LOG_FUNC_IN;
+    LOG_FUNC_IN;
 
-  int offset = 0;
+    int offset = 0;
 
-  if (data->type == AT_COMMAND_GET) {
-    const at_cereg_resp_t * cereg = &(data->response.cereg);
+    if (data->type == AT_COMMAND_GET) {
+        const at_cereg_resp_t * cereg = &(data->response.cereg);
 
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
-    }
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
 
-    offset += sprintf(buffer+offset, "+CEREG: %d,%d",
-                      cereg->n, cereg->stat);
+        offset += sprintf(buffer+offset, "+CEREG: %d,%d",
+                          cereg->n, cereg->stat);
 
-    if (data->mask & AT_CEREG_RESP_TAC_MASK) {
-      offset += sprintf(buffer+offset, ",%s", cereg->tac);
-    }
+        if (data->mask & AT_CEREG_RESP_TAC_MASK) {
+            offset += sprintf(buffer+offset, ",%s", cereg->tac);
+        }
 
-    if (data->mask & AT_CEREG_RESP_CI_MASK) {
-      offset += sprintf(buffer+offset, ",%s", cereg->ci);
-    }
+        if (data->mask & AT_CEREG_RESP_CI_MASK) {
+            offset += sprintf(buffer+offset, ",%s", cereg->ci);
+        }
 
-    if (data->mask & AT_CEREG_RESP_ACT_MASK) {
-      offset += sprintf(buffer+offset, ",%d", cereg->AcT);
-    }
+        if (data->mask & AT_CEREG_RESP_ACT_MASK) {
+            offset += sprintf(buffer+offset, ",%d", cereg->AcT);
+        }
 
-    offset += sprintf(buffer+offset, "\r\n");
-  } else if (data->type == AT_COMMAND_TST) {
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
-    }
+        offset += sprintf(buffer+offset, "\r\n");
+    } else if (data->type == AT_COMMAND_TST) {
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
 
-    offset += sprintf(buffer+offset, "+CEREG: (%d-%d)\r\n",
-                      AT_CEREG_N_MIN, AT_CEREG_N_MAX);
-  }
+        offset += sprintf(buffer+offset, "+CEREG: (%d-%d)\r\n",
+                          AT_CEREG_N_MIN, AT_CEREG_N_MAX);
+    }
 
-  LOG_FUNC_RETURN (offset);
+    LOG_FUNC_RETURN (offset);
 }
 
 /****************************************************************************
@@ -925,65 +925,65 @@ static int _at_response_encode_cereg(char* buffer, const at_response_t* data)
  ***************************************************************************/
 static int _at_response_encode_cgdcont(char* buffer, const at_response_t* data)
 {
-  LOG_FUNC_IN;
-
-  int offset = 0;
-  int i;
-
-  if (data->type == AT_COMMAND_GET) {
-    const at_cgdcont_get_t * cgdcont = &(data->response.cgdcont.get);
-
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
+    LOG_FUNC_IN;
+
+    int offset = 0;
+    int i;
+
+    if (data->type == AT_COMMAND_GET) {
+        const at_cgdcont_get_t * cgdcont = &(data->response.cgdcont.get);
+
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
+
+        /* Display the list of defined PDN contexts */
+        for (i = 0; i < cgdcont->n_pdns; i++) {
+            offset += sprintf(buffer+offset, "+CGDCONT: %u", (unsigned int)cgdcont->cid[i]);
+
+            if (cgdcont->PDP_type[i] == NET_PDN_TYPE_IPV4) {
+                offset += sprintf(buffer+offset, ",IP");
+            } else if (cgdcont->PDP_type[i] == NET_PDN_TYPE_IPV6) {
+                offset += sprintf(buffer+offset, ",IPV6");
+            } else if (cgdcont->PDP_type[i] == NET_PDN_TYPE_IPV4V6) {
+                offset += sprintf(buffer+offset, ",IPV4V6");
+            }
+
+            offset += sprintf(buffer+offset, ",%s", cgdcont->APN[i]);
+            /* No data/header compression */
+            offset += sprintf(buffer+offset, ",%u,%u\r\n",
+                              (unsigned int)(AT_CGDCONT_D_COMP_OFF), (unsigned int)(AT_CGDCONT_H_COMP_OFF));
+        }
+    } else if (data->type == AT_COMMAND_TST) {
+        const at_cgdcont_tst_t * cgdcont = &(data->response.cgdcont.tst);
+
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
+
+        /* IPv4 PDN type */
+        offset += sprintf(buffer+offset, "+CGDCONT: ");
+        offset += sprintf(buffer+offset, "(1-%d),IP,,,(%d-%d),(%d-%d)",
+                          cgdcont->n_cid,
+                          AT_CGDCONT_D_COMP_MIN, AT_CGDCONT_D_COMP_MAX,
+                          AT_CGDCONT_H_COMP_MIN, AT_CGDCONT_H_COMP_MAX);
+        /* IPv6 PDN type */
+        offset += sprintf(buffer+offset, "\r\n+CGDCONT: ");
+        offset += sprintf(buffer+offset, "(1-%d),IPV6,,,(%d-%d),(%d-%d)",
+                          cgdcont->n_cid,
+                          AT_CGDCONT_D_COMP_MIN, AT_CGDCONT_D_COMP_MAX,
+                          AT_CGDCONT_H_COMP_MIN, AT_CGDCONT_H_COMP_MAX);
+        /* IPv4v6 PDN type */
+        offset += sprintf(buffer+offset, "\r\n+CGDCONT: ");
+        offset += sprintf(buffer+offset, "(1-%d),IPV4V6,,,(%d-%d),(%d-%d)",
+                          cgdcont->n_cid,
+                          AT_CGDCONT_D_COMP_MIN, AT_CGDCONT_D_COMP_MAX,
+                          AT_CGDCONT_H_COMP_MIN, AT_CGDCONT_H_COMP_MAX);
+
+        offset += sprintf(buffer+offset, "\r\n");
     }
 
-    /* Display the list of defined PDN contexts */
-    for (i = 0; i < cgdcont->n_pdns; i++) {
-      offset += sprintf(buffer+offset, "+CGDCONT: %u", cgdcont->cid[i]);
-
-      if (cgdcont->PDP_type[i] == NET_PDN_TYPE_IPV4) {
-        offset += sprintf(buffer+offset, ",IP");
-      } else if (cgdcont->PDP_type[i] == NET_PDN_TYPE_IPV6) {
-        offset += sprintf(buffer+offset, ",IPV6");
-      } else if (cgdcont->PDP_type[i] == NET_PDN_TYPE_IPV4V6) {
-        offset += sprintf(buffer+offset, ",IPV4V6");
-      }
-
-      offset += sprintf(buffer+offset, ",%s", cgdcont->APN[i]);
-      /* No data/header compression */
-      offset += sprintf(buffer+offset, ",%u,%u\r\n",
-                        AT_CGDCONT_D_COMP_OFF, AT_CGDCONT_H_COMP_OFF);
-    }
-  } else if (data->type == AT_COMMAND_TST) {
-    const at_cgdcont_tst_t * cgdcont = &(data->response.cgdcont.tst);
-
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
-    }
-
-    /* IPv4 PDN type */
-    offset += sprintf(buffer+offset, "+CGDCONT: ");
-    offset += sprintf(buffer+offset, "(1-%u),IP,,,(%u-%u),(%u-%u)",
-                      cgdcont->n_cid,
-                      AT_CGDCONT_D_COMP_MIN, AT_CGDCONT_D_COMP_MAX,
-                      AT_CGDCONT_H_COMP_MIN, AT_CGDCONT_H_COMP_MAX);
-    /* IPv6 PDN type */
-    offset += sprintf(buffer+offset, "\r\n+CGDCONT: ");
-    offset += sprintf(buffer+offset, "(1-%u),IPV6,,,(%u-%u),(%u-%u)",
-                      cgdcont->n_cid,
-                      AT_CGDCONT_D_COMP_MIN, AT_CGDCONT_D_COMP_MAX,
-                      AT_CGDCONT_H_COMP_MIN, AT_CGDCONT_H_COMP_MAX);
-    /* IPv4v6 PDN type */
-    offset += sprintf(buffer+offset, "\r\n+CGDCONT: ");
-    offset += sprintf(buffer+offset, "(1-%u),IPV4V6,,,(%u-%u),(%u-%u)",
-                      cgdcont->n_cid,
-                      AT_CGDCONT_D_COMP_MIN, AT_CGDCONT_D_COMP_MAX,
-                      AT_CGDCONT_H_COMP_MIN, AT_CGDCONT_H_COMP_MAX);
-
-    offset += sprintf(buffer+offset, "\r\n");
-  }
-
-  LOG_FUNC_RETURN (offset);
+    LOG_FUNC_RETURN (offset);
 }
 
 /****************************************************************************
@@ -1003,33 +1003,33 @@ static int _at_response_encode_cgdcont(char* buffer, const at_response_t* data)
  ***************************************************************************/
 static int _at_response_encode_cgact(char* buffer, const at_response_t* data)
 {
-  LOG_FUNC_IN;
-
-  int offset = 0;
-  int i;
-
-  if (data->type == AT_COMMAND_GET) {
-    const at_cgact_resp_t * cgact = &(data->response.cgact);
-
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
+    LOG_FUNC_IN;
+
+    int offset = 0;
+    int i;
+
+    if (data->type == AT_COMMAND_GET) {
+        const at_cgact_resp_t * cgact = &(data->response.cgact);
+
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
+
+        /* Display the list of defined PDN status */
+        for (i = 0; i < cgact->n_pdns; i++) {
+            offset += sprintf(buffer+offset, "+CGACT: %u,%u\r\n",
+                              (unsigned int)cgact->cid[i], (unsigned int)cgact->state[i]);
+        }
+    } else if (data->type == AT_COMMAND_TST) {
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
+
+        offset += sprintf(buffer+offset, "+CGACT: (%d,%d)\r\n",
+                          AT_CGACT_STATE_MIN, AT_CGACT_STATE_MAX);
     }
 
-    /* Display the list of defined PDN status */
-    for (i = 0; i < cgact->n_pdns; i++) {
-      offset += sprintf(buffer+offset, "+CGACT: %u,%u\r\n",
-                        cgact->cid[i], cgact->state[i]);
-    }
-  } else if (data->type == AT_COMMAND_TST) {
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
-    }
-
-    offset += sprintf(buffer+offset, "+CGACT: (%d,%d)\r\n",
-                      AT_CGACT_STATE_MIN, AT_CGACT_STATE_MAX);
-  }
-
-  LOG_FUNC_RETURN (offset);
+    LOG_FUNC_RETURN (offset);
 }
 
 /****************************************************************************
@@ -1049,69 +1049,72 @@ static int _at_response_encode_cgact(char* buffer, const at_response_t* data)
  ***************************************************************************/
 static int _at_response_encode_cgpaddr(char* buffer, const at_response_t* data)
 {
-  LOG_FUNC_IN;
-
-  int offset = 0;
-  const at_cgpaddr_resp_t * cgpaddr = &(data->response.cgpaddr);
-  int i;
-
-  if (data->type == AT_COMMAND_SET) {
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
-    }
-
-    /* Display the list of IP addresses assigned to each defined PDN
-     * connections */
-    for (i = 0; i < cgpaddr->n_pdns; i++) {
-      offset += sprintf(buffer+offset, "+CGPADDR: %u", cgpaddr->cid[i]);
-
-      if (cgpaddr->PDP_addr_1[i] != NULL) {
-        /* IPv4 address */
-        offset += sprintf(buffer+offset, ",%hhu.%hhu.%hhu.%hhu",
-                          cgpaddr->PDP_addr_1[i][0],
-                          cgpaddr->PDP_addr_1[i][1],
-                          cgpaddr->PDP_addr_1[i][2],
-                          cgpaddr->PDP_addr_1[i][3]);
-      }
-
-      if (cgpaddr->PDP_addr_2[i] != NULL) {
-        /* IPv6 Link-local address prefixe */
-        offset += sprintf(buffer+offset,
-                          ",%hhu.%hhu.%hhu.%hhu.%hhu.%hhu.%hhu.%hhu",
-                          0xfe, 0x80, 0, 0, 0, 0, 0, 0);
-        /* IPv6 Link-local address */
-        offset += sprintf(buffer+offset,
-                          ".%hhu.%hhu.%hhu.%hhu.%hhu.%hhu.%hhu.%hhu",
-                          cgpaddr->PDP_addr_2[i][0],
-                          cgpaddr->PDP_addr_2[i][1],
-                          cgpaddr->PDP_addr_2[i][2],
-                          cgpaddr->PDP_addr_2[i][3],
-                          cgpaddr->PDP_addr_2[i][4],
-                          cgpaddr->PDP_addr_2[i][5],
-                          cgpaddr->PDP_addr_2[i][6],
-                          cgpaddr->PDP_addr_2[i][7]);
-      }
-
-      offset += sprintf(buffer+offset, "\r\n");
+    LOG_FUNC_IN;
+
+    int offset = 0;
+    const at_cgpaddr_resp_t * cgpaddr = &(data->response.cgpaddr);
+    int i;
+
+    if (data->type == AT_COMMAND_SET) {
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
+
+        /* Display the list of IP addresses assigned to each defined PDN
+         * connections */
+        for (i = 0; i < cgpaddr->n_pdns; i++) {
+            offset += sprintf(buffer+offset, "+CGPADDR: %u", (unsigned int)cgpaddr->cid[i]);
+
+            if (cgpaddr->PDP_addr_1[i] != NULL) {
+                /* IPv4 address */
+                offset += sprintf(buffer+offset, ",%hhu.%hhu.%hhu.%hhu",
+                                  (unsigned int)cgpaddr->PDP_addr_1[i][0],
+                                  (unsigned int)cgpaddr->PDP_addr_1[i][1],
+                                  (unsigned int)cgpaddr->PDP_addr_1[i][2],
+                                  (unsigned int)cgpaddr->PDP_addr_1[i][3]);
+            }
+
+            if (cgpaddr->PDP_addr_2[i] != NULL) {
+                /* IPv6 Link-local address prefixe */
+                offset += sprintf(buffer+offset,
+                                  ",%hhu.%hhu.%hhu.%hhu.%hhu.%hhu.%hhu.%hhu",
+                                  (unsigned int)0xfe, (unsigned int)0x80,
+                                  (unsigned int)0, (unsigned int)0,
+                                  (unsigned int)0, (unsigned int)0,
+                                  (unsigned int)0, (unsigned int)0);
+                /* IPv6 Link-local address */
+                offset += sprintf(buffer+offset,
+                                  ".%hhu.%hhu.%hhu.%hhu.%hhu.%hhu.%hhu.%hhu",
+                                  (unsigned int)cgpaddr->PDP_addr_2[i][0],
+                                  (unsigned int)cgpaddr->PDP_addr_2[i][1],
+                                  (unsigned int)cgpaddr->PDP_addr_2[i][2],
+                                  (unsigned int)cgpaddr->PDP_addr_2[i][3],
+                                  (unsigned int)cgpaddr->PDP_addr_2[i][4],
+                                  (unsigned int)cgpaddr->PDP_addr_2[i][5],
+                                  (unsigned int)cgpaddr->PDP_addr_2[i][6],
+                                  (unsigned int)cgpaddr->PDP_addr_2[i][7]);
+            }
+
+            offset += sprintf(buffer+offset, "\r\n");
+        }
+    } else if (data->type == AT_COMMAND_TST) {
+        /* Display the list of defined PDN contexts */
+        if (cgpaddr->n_pdns > 0) {
+            if (at_response_format_v1) {
+                offset += sprintf(buffer, "\r\n");
+            }
+
+            offset += sprintf(buffer+offset, "+CGPADDR: %u", (unsigned int)cgpaddr->cid[0]);
+
+            for (i = 1; i < cgpaddr->n_pdns; i++) {
+                offset += sprintf(buffer+offset, ",%u", (unsigned int)cgpaddr->cid[i]);
+            }
+
+            offset += sprintf(buffer+offset, "\r\n");
+        }
     }
-  } else if (data->type == AT_COMMAND_TST) {
-    /* Display the list of defined PDN contexts */
-    if (cgpaddr->n_pdns > 0) {
-      if (at_response_format_v1) {
-        offset += sprintf(buffer, "\r\n");
-      }
 
-      offset += sprintf(buffer+offset, "+CGPADDR: %u", cgpaddr->cid[0]);
-
-      for (i = 1; i < cgpaddr->n_pdns; i++) {
-        offset += sprintf(buffer+offset, ",%u", cgpaddr->cid[i]);
-      }
-
-      offset += sprintf(buffer+offset, "\r\n");
-    }
-  }
-
-  LOG_FUNC_RETURN (offset);
+    LOG_FUNC_RETURN (offset);
 }
 
 /****************************************************************************
@@ -1131,28 +1134,28 @@ static int _at_response_encode_cgpaddr(char* buffer, const at_response_t* data)
  ***************************************************************************/
 static int _at_response_encode_cmee(char* buffer, const at_response_t* data)
 {
-  LOG_FUNC_IN;
+    LOG_FUNC_IN;
 
-  int offset = 0;
+    int offset = 0;
 
-  if (data->type == AT_COMMAND_GET) {
-    const at_cmee_resp_t * cmee = &(data->response.cmee);
+    if (data->type == AT_COMMAND_GET) {
+        const at_cmee_resp_t * cmee = &(data->response.cmee);
 
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
-    }
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
 
-    offset += sprintf(buffer+offset, "+CMEE: %d\r\n", cmee->n);
-  } else if (data->type == AT_COMMAND_TST) {
-    if (at_response_format_v1) {
-      offset += sprintf(buffer, "\r\n");
-    }
+        offset += sprintf(buffer+offset, "+CMEE: %d\r\n", cmee->n);
+    } else if (data->type == AT_COMMAND_TST) {
+        if (at_response_format_v1) {
+            offset += sprintf(buffer, "\r\n");
+        }
 
-    offset += sprintf(buffer+offset, "+CMEE: (%d,%d)\r\n",
-                      AT_CMEE_N_MIN, AT_CMEE_N_MAX);
-  }
+        offset += sprintf(buffer+offset, "+CMEE: (%d,%d)\r\n",
+                          AT_CMEE_N_MIN, AT_CMEE_N_MAX);
+    }
 
-  LOG_FUNC_RETURN (offset);
+    LOG_FUNC_RETURN (offset);
 }
 
 /****************************************************************************
@@ -1172,16 +1175,16 @@ static int _at_response_encode_cmee(char* buffer, const at_response_t* data)
  ***************************************************************************/
 static int _at_response_encode_cgev(char* buffer, const at_response_t* data)
 {
-  LOG_FUNC_IN;
+    LOG_FUNC_IN;
 
-  int offset = 0;
+    int offset = 0;
 
-  if (data->type == AT_COMMAND_GET) {
-    const at_cgev_resp_t * cgev = &(data->response.cgev);
-    offset += sprintf(buffer+offset, "+CGEV: %s %u\r\n",
-                      _at_response_event_str[cgev->code], cgev->cid);
-  }
+    if (data->type == AT_COMMAND_GET) {
+        const at_cgev_resp_t * cgev = &(data->response.cgev);
+        offset += sprintf(buffer+offset, "+CGEV: %s %u\r\n",
+                          _at_response_event_str[cgev->code], (unsigned int)cgev->cid);
+    }
 
-  LOG_FUNC_RETURN (offset);
+    LOG_FUNC_RETURN (offset);
 }
 
diff --git a/openair3/NAS/UE/EMM/Authentication.c b/openair3/NAS/UE/EMM/Authentication.c
index 5b10e608935da20a2e83710ae75f82cdf8376637..850f97150a7afb5e4c155d3a75c63f44d2a8d30b 100644
--- a/openair3/NAS/UE/EMM/Authentication.c
+++ b/openair3/NAS/UE/EMM/Authentication.c
@@ -68,14 +68,9 @@ Description Defines the authentication EMM procedure executed by the
 #include "usim_api.h"
 #include "secu_defs.h"
 #include "Authentication.h"
+#include "targets/RT/USER/lte-softmodem.h"
 
 
-/****************************************************************************/
-/****************  E X T E R N A L    D E F I N I T I O N S  ****************/
-/****************************************************************************/
-
-extern uint8_t usim_test;
-
 /****************************************************************************/
 /*******************  L O C A L    D E F I N I T I O N S  *******************/
 /****************************************************************************/
@@ -211,7 +206,7 @@ int emm_proc_authentication_request(nas_user_t *user, int native_ksi, int ksi,
        * of the core network by means of the received AUTN parameter and
        * request the USIM to compute RES, CK and IK for given RAND
        */
-      if(usim_test == 0)
+      if(get_softmodem_params()->usim_test == 0)
       {
         rc = usim_api_authenticate(&user->usim_data, rand, autn, &auts, &res, &ck, &ik);
       }
diff --git a/openair3/NAS/UE/EMM/SAP/EmmDeregisteredNormalService.c b/openair3/NAS/UE/EMM/SAP/EmmDeregisteredNormalService.c
index fe18a98d38fa4d2d96625055acca0e9844c4d4ed..f77c2921a319070eebc069f392ed13c27afcec26 100644
--- a/openair3/NAS/UE/EMM/SAP/EmmDeregisteredNormalService.c
+++ b/openair3/NAS/UE/EMM/SAP/EmmDeregisteredNormalService.c
@@ -47,7 +47,7 @@ Description Implements the EPS Mobility Management procedures executed
 #include "commonDef.h"
 #include "networkDef.h"
 #include "nas_log.h"
-
+#include "targets/RT/USER/lte-softmodem.h"
 #include "emm_proc.h"
 
 #include <assert.h>
@@ -55,7 +55,7 @@ Description Implements the EPS Mobility Management procedures executed
 /****************************************************************************/
 /****************  E X T E R N A L    D E F I N I T I O N S  ****************/
 /****************************************************************************/
-extern uint8_t usim_test;
+
 
 /****************************************************************************/
 /*******************  L O C A L    D E F I N I T I O N S  *******************/
@@ -110,7 +110,7 @@ int EmmDeregisteredNormalService(nas_user_t *user, const emm_reg_t *evt)
     /*
      * Initiate the attach procedure for EPS services
      */
-    if(usim_test == 0)
+    if(get_softmodem_params()->usim_test == 0)
     {
       rc = emm_proc_attach(user, EMM_ATTACH_TYPE_EPS);
     }
diff --git a/openair3/NAS/UE/ESM/PdnConnectivity.c b/openair3/NAS/UE/ESM/PdnConnectivity.c
index f0f4efa769f5180dc5b73f5c31ea04ada5e71a49..48730f2ca9d2f68e981f8268362d89b8af8bde1b 100644
--- a/openair3/NAS/UE/ESM/PdnConnectivity.c
+++ b/openair3/NAS/UE/ESM/PdnConnectivity.c
@@ -138,119 +138,119 @@ int esm_proc_pdn_connectivity(nas_user_t *user, int cid, int is_to_define,
                               const OctetString *apn, int is_emergency,
                               unsigned int *pti)
 {
-  LOG_FUNC_IN;
+    LOG_FUNC_IN;
 
-  int rc = RETURNerror;
-  int pid = cid - 1;
-  esm_data_t *esm_data = user-> esm_data;
-  esm_pt_data_t *esm_pt_data = user-> esm_pt_data;
+    int rc = RETURNerror;
+    int pid = cid - 1;
+    esm_data_t *esm_data = user-> esm_data;
+    esm_pt_data_t *esm_pt_data = user-> esm_pt_data;
 
-  if (!is_to_define) {
-    LOG_TRACE(INFO, "ESM-PROC  - Undefine PDN connection (cid=%d)", cid);
-    /* Delete the PDN connection entry */
-    int pti = _pdn_connectivity_delete(esm_data, pid);
+    if (!is_to_define) {
+        LOG_TRACE(INFO, "ESM-PROC  - Undefine PDN connection (cid=%d)", cid);
+        /* Delete the PDN connection entry */
+        int pti = _pdn_connectivity_delete(esm_data, pid);
 
-    if (pti != ESM_PT_UNASSIGNED) {
-      /* Release the procedure transaction data */
-      rc = esm_pt_release(esm_pt_data, pti);
-    }
+        if (pti != ESM_PT_UNASSIGNED) {
+            /* Release the procedure transaction data */
+            rc = esm_pt_release(esm_pt_data, pti);
+        }
 
-    LOG_FUNC_RETURN(rc);
-  } else if (pti != NULL) {
-    LOG_TRACE(INFO, "ESM-PROC  - Assign new procedure transaction identity "
-              "(cid=%d)", cid);
-    /* Assign new procedure transaction identity */
-    *pti = esm_pt_assign(esm_pt_data);
-
-    if (*pti == ESM_PT_UNASSIGNED) {
-      LOG_TRACE(WARNING, "ESM-PROC  - Failed to assign new procedure "
-                "transaction identity");
-      LOG_FUNC_RETURN (RETURNerror);
-    }
+        LOG_FUNC_RETURN(rc);
+    } else if (pti != NULL) {
+        LOG_TRACE(INFO, "ESM-PROC  - Assign new procedure transaction identity "
+                  "(cid=%d)", cid);
+        /* Assign new procedure transaction identity */
+        *pti = esm_pt_assign(esm_pt_data);
+
+        if (*pti == ESM_PT_UNASSIGNED) {
+            LOG_TRACE(WARNING, "ESM-PROC  - Failed to assign new procedure "
+                      "transaction identity");
+            LOG_FUNC_RETURN (RETURNerror);
+        }
 
-    /* Update the PDN connection data */
-    rc = _pdn_connectivity_set_pti(esm_data, pid, *pti);
+        /* Update the PDN connection data */
+        rc = _pdn_connectivity_set_pti(esm_data, pid, *pti);
 
-    if (rc != RETURNok) {
-      LOG_TRACE(WARNING, "ESM-PROC  - Failed to update PDN connection");
-    }
+        if (rc != RETURNok) {
+            LOG_TRACE(WARNING, "ESM-PROC  - Failed to update PDN connection");
+        }
 
-    LOG_FUNC_RETURN (rc);
-  }
-
-  LOG_TRACE(INFO,"ESM-PROC  - Define new %s PDN connection to APN %s (cid=%d)",
-            (pdn_type == ESM_PDN_TYPE_IPV4)? "IPv4" :
-            (pdn_type == ESM_PDN_TYPE_IPV6)? "IPv6" : "IPv4v6",
-            apn->value, cid);
-
-  if (is_emergency && esm_data->emergency) {
-    /* The UE shall not request additional PDN connection for
-     * emergency bearer services */
-    LOG_TRACE(WARNING, "ESM-PROC  - PDN connection for emergency bearer "
-              "services is already active");
-    LOG_FUNC_RETURN (RETURNerror);
-  } else if (pid < ESM_DATA_PDN_MAX) {
-    if ((pid == esm_data->pdn[pid].pid) && (esm_data->pdn[pid].is_active)) {
-      /* PDN connection with the specified identifier is active */
-      LOG_TRACE(WARNING, "ESM-PROC  - PDN connection is active");
-      LOG_FUNC_RETURN (RETURNerror);
+        LOG_FUNC_RETURN (rc);
     }
-  } else {
-    LOG_TRACE(WARNING, "ESM-PROC  - PDN connection identifier is not valid");
-    LOG_FUNC_RETURN (RETURNerror);
-  }
-
-  if (apn && apn->length > 0) {
-    /* The UE requested subsequent connectivity to additionnal PDNs */
-    int pid = _pdn_connectivity_find_apn(esm_data, apn);
-
-    if ( (pid >= 0) && esm_data->pdn[pid].is_active ) {
-      /* An active PDN connection to this APN already exists */
-      if ( (esm_data->pdn[pid].data->type != ESM_PDN_TYPE_IPV4V6) &&
-           (esm_data->pdn[pid].data->type != pdn_type) ) {
-        /* The UE is requesting PDN connection for other IP version
-         * than the one already activated */
-        if (!esm_data->pdn[pid].data->addr_realloc) {
-          /* The network does not allow PDN connectivity using
-           * IPv4 and IPv6 address versions to the same APN */
-          if (pdn_type != ESM_PDN_TYPE_IPV4V6) {
-            LOG_TRACE(WARNING, "ESM-PROC  - %s PDN connectivity to "
-                      "%s is not allowed by the network",
-                      (pdn_type != ESM_PDN_TYPE_IPV4)? "IPv6" :
-                      "IPv4", apn->value);
-          } else {
-            LOG_TRACE(WARNING, "ESM-PROC  - %s PDN connection to %s "
-                      "already exists",
-                      (esm_data->pdn[pid].data->type !=
-                       ESM_PDN_TYPE_IPV4)? "IPv6" : "IPv4",
-                      apn->value);
-          }
-
-          LOG_FUNC_RETURN (RETURNerror);
+
+    LOG_TRACE(INFO,"ESM-PROC  - Define new %s PDN connection to APN %s (cid=%d)",
+              (pdn_type == ESM_PDN_TYPE_IPV4)? "IPv4" :
+              (pdn_type == ESM_PDN_TYPE_IPV6)? "IPv6" : "IPv4v6",
+              (apn!=NULL)?apn->value:0, cid);
+
+    if (is_emergency && esm_data->emergency) {
+        /* The UE shall not request additional PDN connection for
+         * emergency bearer services */
+        LOG_TRACE(WARNING, "ESM-PROC  - PDN connection for emergency bearer "
+                  "services is already active");
+        LOG_FUNC_RETURN (RETURNerror);
+    } else if (pid < ESM_DATA_PDN_MAX) {
+        if ((pid == esm_data->pdn[pid].pid) && (esm_data->pdn[pid].is_active)) {
+            /* PDN connection with the specified identifier is active */
+            LOG_TRACE(WARNING, "ESM-PROC  - PDN connection is active");
+            LOG_FUNC_RETURN (RETURNerror);
         }
-      } else {
-        /* The UE is requesting PDN connection to this APN using the
-         * same IP version than the one already activated */
-        LOG_TRACE(WARNING, "ESM-PROC  - %s PDN connection to %s "
-                  "already exists",
-                  (esm_data->pdn[pid].data->type != ESM_PDN_TYPE_IPV4)?
-                  (esm_data->pdn[pid].data->type != ESM_PDN_TYPE_IPV6)?
-          "IPv4v6" : "IPv6" : "IPv4", apn->value);
+    } else {
+        LOG_TRACE(WARNING, "ESM-PROC  - PDN connection identifier is not valid");
         LOG_FUNC_RETURN (RETURNerror);
-      }
     }
-  }
-
-  /*
-   * New PDN context has to be defined to allow connectivity to an APN:
-   * The UE may attempt to attach to the network using the default APN,
-   * or request PDN connectivity to emergency bearer services. The UE
-   * may also subsequently request connectivity to additional PDNs if
-   * not already established, or may have been allowed to request PDN
-   * connectivity for other IP version than the one already activated
-   */
-  rc = _pdn_connectivity_create(esm_data, pid, apn, pdn_type, is_emergency);
-  LOG_FUNC_RETURN(rc);
+
+    if (apn && apn->length > 0) {
+        /* The UE requested subsequent connectivity to additionnal PDNs */
+        int pid = _pdn_connectivity_find_apn(esm_data, apn);
+
+        if ( (pid >= 0) && esm_data->pdn[pid].is_active ) {
+            /* An active PDN connection to this APN already exists */
+            if ( (esm_data->pdn[pid].data->type != ESM_PDN_TYPE_IPV4V6) &&
+                    (esm_data->pdn[pid].data->type != pdn_type) ) {
+                /* The UE is requesting PDN connection for other IP version
+                 * than the one already activated */
+                if (!esm_data->pdn[pid].data->addr_realloc) {
+                    /* The network does not allow PDN connectivity using
+                     * IPv4 and IPv6 address versions to the same APN */
+                    if (pdn_type != ESM_PDN_TYPE_IPV4V6) {
+                        LOG_TRACE(WARNING, "ESM-PROC  - %s PDN connectivity to "
+                                  "%s is not allowed by the network",
+                                  (pdn_type != ESM_PDN_TYPE_IPV4)? "IPv6" :
+                                  "IPv4", apn->value);
+                    } else {
+                        LOG_TRACE(WARNING, "ESM-PROC  - %s PDN connection to %s "
+                                  "already exists",
+                                  (esm_data->pdn[pid].data->type !=
+                                   ESM_PDN_TYPE_IPV4)? "IPv6" : "IPv4",
+                                  apn->value);
+                    }
+
+                    LOG_FUNC_RETURN (RETURNerror);
+                }
+            } else {
+                /* The UE is requesting PDN connection to this APN using the
+                 * same IP version than the one already activated */
+                LOG_TRACE(WARNING, "ESM-PROC  - %s PDN connection to %s "
+                          "already exists",
+                          (esm_data->pdn[pid].data->type != ESM_PDN_TYPE_IPV4)?
+                          (esm_data->pdn[pid].data->type != ESM_PDN_TYPE_IPV6)?
+                          "IPv4v6" : "IPv6" : "IPv4", apn->value);
+                LOG_FUNC_RETURN (RETURNerror);
+            }
+        }
+    }
+
+    /*
+     * New PDN context has to be defined to allow connectivity to an APN:
+     * The UE may attempt to attach to the network using the default APN,
+     * or request PDN connectivity to emergency bearer services. The UE
+     * may also subsequently request connectivity to additional PDNs if
+     * not already established, or may have been allowed to request PDN
+     * connectivity for other IP version than the one already activated
+     */
+    rc = _pdn_connectivity_create(esm_data, pid, apn, pdn_type, is_emergency);
+    LOG_FUNC_RETURN(rc);
 }
 
 /****************************************************************************
@@ -283,42 +283,42 @@ int esm_proc_pdn_connectivity(nas_user_t *user, int cid, int is_to_define,
 int esm_proc_pdn_connectivity_request(nas_user_t *user, int is_standalone, int pti,
                                       OctetString *msg, int sent_by_ue)
 {
-  LOG_FUNC_IN;
-  esm_pt_data_t *esm_pt_data = user->esm_pt_data;
-  int rc = RETURNok;
-
-  LOG_TRACE(INFO, "ESM-PROC  - Initiate PDN connectivity (pti=%d)", pti);
-
-  if (is_standalone) {
-    emm_sap_t emm_sap;
-    emm_esm_data_t *emm_esm = &emm_sap.u.emm_esm.u.data;
-    /*
-     * Notity EMM that ESM PDU has to be forwarded to lower layers
-     */
-    emm_sap.primitive = EMMESM_UNITDATA_REQ;
-    emm_sap.u.emm_esm.ueid = user->ueid;
-    emm_esm->msg.length = msg->length;
-    emm_esm->msg.value = msg->value;
-    rc = emm_sap_send(user, &emm_sap);
-
-    if (rc != RETURNerror) {
-      /* Start T3482 retransmission timer */
-      rc = esm_pt_start_timer(user, pti, msg, T3482_DEFAULT_VALUE,
-                              _pdn_connectivity_t3482_handler);
+    LOG_FUNC_IN;
+    esm_pt_data_t *esm_pt_data = user->esm_pt_data;
+    int rc = RETURNok;
+
+    LOG_TRACE(INFO, "ESM-PROC  - Initiate PDN connectivity (pti=%d)", pti);
+
+    if (is_standalone) {
+        emm_sap_t emm_sap;
+        emm_esm_data_t *emm_esm = &emm_sap.u.emm_esm.u.data;
+        /*
+         * Notity EMM that ESM PDU has to be forwarded to lower layers
+         */
+        emm_sap.primitive = EMMESM_UNITDATA_REQ;
+        emm_sap.u.emm_esm.ueid = user->ueid;
+        emm_esm->msg.length = msg->length;
+        emm_esm->msg.value = msg->value;
+        rc = emm_sap_send(user, &emm_sap);
+
+        if (rc != RETURNerror) {
+            /* Start T3482 retransmission timer */
+            rc = esm_pt_start_timer(user, pti, msg, T3482_DEFAULT_VALUE,
+                                    _pdn_connectivity_t3482_handler);
+        }
     }
-  }
 
-  if (rc != RETURNerror) {
-    /* Set the procedure transaction state to PENDING */
-    rc = esm_pt_set_status(esm_pt_data, pti, ESM_PT_PENDING);
+    if (rc != RETURNerror) {
+        /* Set the procedure transaction state to PENDING */
+        rc = esm_pt_set_status(esm_pt_data, pti, ESM_PT_PENDING);
 
-    if (rc != RETURNok) {
-      /* The procedure transaction was already in PENDING state */
-      LOG_TRACE(WARNING, "ESM-PROC  - PTI %d was already PENDING", pti);
+        if (rc != RETURNok) {
+            /* The procedure transaction was already in PENDING state */
+            LOG_TRACE(WARNING, "ESM-PROC  - PTI %d was already PENDING", pti);
+        }
     }
-  }
 
-  LOG_FUNC_RETURN(rc);
+    LOG_FUNC_RETURN(rc);
 }
 
 /****************************************************************************
@@ -351,73 +351,73 @@ int esm_proc_pdn_connectivity_accept(nas_user_t *user, int pti, esm_proc_pdn_typ
                                      const OctetString *pdn_addr,
                                      const OctetString *apn, int *esm_cause)
 {
-  LOG_FUNC_IN;
-  esm_data_t *esm_data  = user->esm_data;
-  esm_pt_data_t *esm_pt_data = user->esm_pt_data;
-  int     rc;
-  int     pid = RETURNerror;
-  char    apn_first_char[4];
-
-  LOG_VAR(char,    str[128]);
-
-  if (isprint(apn->value[0])) {
-    apn_first_char[0] = '\0';
-  } else {
-    sprintf (apn_first_char, "%02X", apn->value[0]);
-  }
-
-  LOG_TRACE(INFO, "ESM-PROC  - PDN connectivity accepted by the network "
-            "(pti=%d) APN = %s\"%s\", IP address = %s", pti, apn_first_char, isprint(apn->value[0]) ? &apn->value[0] : &apn->value[1],
-            (pdn_type == ESM_PDN_TYPE_IPV4)? esm_data_get_ipv4_addr(pdn_addr, str) :
-            (pdn_type == ESM_PDN_TYPE_IPV6)? esm_data_get_ipv6_addr(pdn_addr, str) :
-            esm_data_get_ipv4v6_addr(pdn_addr, str));
-
-  /* Stop T3482 timer if running */
-  esm_pt_stop_timer(esm_pt_data, pti);
-  /* Set the procedure transaction state to INACTIVE */
-  rc = esm_pt_set_status(esm_pt_data, pti, ESM_PT_INACTIVE);
-
-  if (rc != RETURNok) {
-    /* The procedure transaction was already in INACTIVE state
-     * as the request may have already been accepted; consider
-     * this request message with same PTI as a network re-
-     * transmission */
-    LOG_TRACE(WARNING, "ESM-PROC  - PTI %d network retransmission", pti);
-    *esm_cause = ESM_CAUSE_PTI_ALREADY_IN_USE;
-  } else {
-    /* XXX - 3GPP TS 24.301, section 6.5.1.3 and 7.3.1
-     * The UE should ensure that the procedure transaction identity
-     * (PTI) assigned to this procedure is not released immediately.
-     * While the PTI value is not released, the UE regards any received
-     * ACTIVATE DEFAULT EPS BEARER CONTEXT REQUEST message with the same
-     * PTI value as a network retransmission.
-     * The way to achieve this is implementation dependent.
-     */
+    LOG_FUNC_IN;
+    esm_data_t *esm_data  = user->esm_data;
+    esm_pt_data_t *esm_pt_data = user->esm_pt_data;
+    int     rc;
+    int     pid = RETURNerror;
+    char    apn_first_char[4];
 
-    /* Check whether a PDN connection exists to this APN */
-    pid = _pdn_connectivity_find_pdn(esm_data, apn, pdn_type);
+    LOG_VAR(char,    str[128]);
 
-    if (pid < 0) {
-      /* No any PDN connection has been defined to establish connectivity
-       * to this APN */
-      LOG_TRACE(WARNING, "ESM-PROC  - PDN connection entry for "
-                "APN \"%s\" (type=%d) not found", apn->value, pdn_type);
-      *esm_cause = ESM_CAUSE_UNKNOWN_ACCESS_POINT_NAME;
-      LOG_FUNC_RETURN(RETURNerror);
+    if (isprint(apn->value[0])) {
+        apn_first_char[0] = '\0';
+    } else {
+        sprintf (apn_first_char, "%02X", apn->value[0]);
     }
 
-    /* Update the PDN connection */
-    rc = _pdn_connectivity_update(esm_data, pid, apn, pdn_type, pdn_addr, *esm_cause);
+    LOG_TRACE(INFO, "ESM-PROC  - PDN connectivity accepted by the network "
+              "(pti=%d) APN = %s\"%s\", IP address = %s", pti, apn_first_char, isprint(apn->value[0]) ? &apn->value[0] : &apn->value[1],
+              (pdn_type == ESM_PDN_TYPE_IPV4)? esm_data_get_ipv4_addr(pdn_addr, str) :
+              (pdn_type == ESM_PDN_TYPE_IPV6)? esm_data_get_ipv6_addr(pdn_addr, str) :
+              esm_data_get_ipv4v6_addr(pdn_addr, str));
+
+    /* Stop T3482 timer if running */
+    esm_pt_stop_timer(esm_pt_data, pti);
+    /* Set the procedure transaction state to INACTIVE */
+    rc = esm_pt_set_status(esm_pt_data, pti, ESM_PT_INACTIVE);
 
     if (rc != RETURNok) {
-      LOG_TRACE(WARNING, "ESM-PROC  - Failed to update PDN connection "
-                "(pid=%d)", pid);
-      *esm_cause = ESM_CAUSE_REQUEST_REJECTED_UNSPECIFIED;
-      LOG_FUNC_RETURN(RETURNerror);
+        /* The procedure transaction was already in INACTIVE state
+         * as the request may have already been accepted; consider
+         * this request message with same PTI as a network re-
+         * transmission */
+        LOG_TRACE(WARNING, "ESM-PROC  - PTI %d network retransmission", pti);
+        *esm_cause = ESM_CAUSE_PTI_ALREADY_IN_USE;
+    } else {
+        /* XXX - 3GPP TS 24.301, section 6.5.1.3 and 7.3.1
+         * The UE should ensure that the procedure transaction identity
+         * (PTI) assigned to this procedure is not released immediately.
+         * While the PTI value is not released, the UE regards any received
+         * ACTIVATE DEFAULT EPS BEARER CONTEXT REQUEST message with the same
+         * PTI value as a network retransmission.
+         * The way to achieve this is implementation dependent.
+         */
+
+        /* Check whether a PDN connection exists to this APN */
+        pid = _pdn_connectivity_find_pdn(esm_data, apn, pdn_type);
+
+        if (pid < 0) {
+            /* No any PDN connection has been defined to establish connectivity
+             * to this APN */
+            LOG_TRACE(WARNING, "ESM-PROC  - PDN connection entry for "
+                      "APN \"%s\" (type=%d) not found", apn->value, pdn_type);
+            *esm_cause = ESM_CAUSE_UNKNOWN_ACCESS_POINT_NAME;
+            LOG_FUNC_RETURN(RETURNerror);
+        }
+
+        /* Update the PDN connection */
+        rc = _pdn_connectivity_update(esm_data, pid, apn, pdn_type, pdn_addr, *esm_cause);
+
+        if (rc != RETURNok) {
+            LOG_TRACE(WARNING, "ESM-PROC  - Failed to update PDN connection "
+                      "(pid=%d)", pid);
+            *esm_cause = ESM_CAUSE_REQUEST_REJECTED_UNSPECIFIED;
+            LOG_FUNC_RETURN(RETURNerror);
+        }
     }
-  }
 
-  LOG_FUNC_RETURN (pid);
+    LOG_FUNC_RETURN (pid);
 }
 
 /****************************************************************************
@@ -444,33 +444,33 @@ int esm_proc_pdn_connectivity_accept(nas_user_t *user, int pti, esm_proc_pdn_typ
  ***************************************************************************/
 int esm_proc_pdn_connectivity_reject(nas_user_t *user, int pti, int *esm_cause)
 {
-  LOG_FUNC_IN;
-  esm_pt_data_t *esm_pt_data = user->esm_pt_data;
-  int rc;
-
-  LOG_TRACE(WARNING, "ESM-PROC  - PDN connectivity rejected by "
-            "the network (pti=%d), ESM cause = %d", pti, *esm_cause);
-
-  /* Stop T3482 timer if running */
-  (void) esm_pt_stop_timer(esm_pt_data, pti);
-  /* Set the procedure transaction state to INACTIVE */
-  rc = esm_pt_set_status(esm_pt_data, pti, ESM_PT_INACTIVE);
-
-  if (rc != RETURNok) {
-    /* The procedure transaction was already in INACTIVE state */
-    LOG_TRACE(WARNING, "ESM-PROC  - PTI %d was already INACTIVE", pti);
-    *esm_cause = ESM_CAUSE_MESSAGE_TYPE_NOT_COMPATIBLE;
-  } else {
-    /* Release the procedure transaction identity */
-    rc = esm_pt_release(user->esm_pt_data, pti);
+    LOG_FUNC_IN;
+    esm_pt_data_t *esm_pt_data = user->esm_pt_data;
+    int rc;
+
+    LOG_TRACE(WARNING, "ESM-PROC  - PDN connectivity rejected by "
+              "the network (pti=%d), ESM cause = %d", pti, *esm_cause);
+
+    /* Stop T3482 timer if running */
+    (void) esm_pt_stop_timer(esm_pt_data, pti);
+    /* Set the procedure transaction state to INACTIVE */
+    rc = esm_pt_set_status(esm_pt_data, pti, ESM_PT_INACTIVE);
 
     if (rc != RETURNok) {
-      LOG_TRACE(WARNING, "ESM-PROC  - Failed to release PTI %d", pti);
-      *esm_cause = ESM_CAUSE_REQUEST_REJECTED_UNSPECIFIED;
+        /* The procedure transaction was already in INACTIVE state */
+        LOG_TRACE(WARNING, "ESM-PROC  - PTI %d was already INACTIVE", pti);
+        *esm_cause = ESM_CAUSE_MESSAGE_TYPE_NOT_COMPATIBLE;
+    } else {
+        /* Release the procedure transaction identity */
+        rc = esm_pt_release(user->esm_pt_data, pti);
+
+        if (rc != RETURNok) {
+            LOG_TRACE(WARNING, "ESM-PROC  - Failed to release PTI %d", pti);
+            *esm_cause = ESM_CAUSE_REQUEST_REJECTED_UNSPECIFIED;
+        }
     }
-  }
 
-  LOG_FUNC_RETURN(rc);
+    LOG_FUNC_RETURN(rc);
 }
 
 /****************************************************************************
@@ -495,22 +495,22 @@ int esm_proc_pdn_connectivity_reject(nas_user_t *user, int pti, int *esm_cause)
  ***************************************************************************/
 int esm_proc_pdn_connectivity_complete(nas_user_t *user)
 {
-  LOG_FUNC_IN;
-  esm_pt_data_t *esm_pt_data = user->esm_pt_data;
-  int rc = RETURNerror;
+    LOG_FUNC_IN;
+    esm_pt_data_t *esm_pt_data = user->esm_pt_data;
+    int rc = RETURNerror;
 
-  LOG_TRACE(INFO, "ESM-PROC  - PDN connectivity complete");
+    LOG_TRACE(INFO, "ESM-PROC  - PDN connectivity complete");
 
-  /* Get the procedure transaction identity assigned to the PDN connection
-   * entry which is still pending in the inactive state */
-  int pti = esm_pt_get_pending_pti(esm_pt_data, ESM_PT_INACTIVE);
+    /* Get the procedure transaction identity assigned to the PDN connection
+     * entry which is still pending in the inactive state */
+    int pti = esm_pt_get_pending_pti(esm_pt_data, ESM_PT_INACTIVE);
 
-  if (pti != ESM_PT_UNASSIGNED) {
-    /* Release the procedure transaction identity */
-    rc = esm_pt_release(esm_pt_data, pti);
-  }
+    if (pti != ESM_PT_UNASSIGNED) {
+        /* Release the procedure transaction identity */
+        rc = esm_pt_release(esm_pt_data, pti);
+    }
 
-  LOG_FUNC_RETURN(rc);
+    LOG_FUNC_RETURN(rc);
 }
 
 /****************************************************************************
@@ -536,40 +536,40 @@ int esm_proc_pdn_connectivity_complete(nas_user_t *user)
  ***************************************************************************/
 int esm_proc_pdn_connectivity_failure(nas_user_t *user, int is_pending)
 {
-  LOG_FUNC_IN;
-  esm_pt_data_t *esm_pt_data = user->esm_pt_data;
-  int rc;
-  int pti;
-
-  LOG_TRACE(WARNING, "ESM-PROC  - PDN connectivity failure in state %s",
-            (is_pending)? "PENDING" : "INACTIVE");
-
-  if (is_pending) {
-    /* Get the procedure transaction identity assigned to the pending PDN
-     * connection entry */
-    pti = esm_pt_get_pending_pti(esm_pt_data, ESM_PT_PENDING);
-
-    if (pti == ESM_PT_UNASSIGNED) {
-      LOG_TRACE(ERROR, "ESM-PROC  - No procedure transaction is PENDING");
-      return (RETURNerror);
-    }
+    LOG_FUNC_IN;
+    esm_pt_data_t *esm_pt_data = user->esm_pt_data;
+    int rc;
+    int pti;
+
+    LOG_TRACE(WARNING, "ESM-PROC  - PDN connectivity failure in state %s",
+              (is_pending)? "PENDING" : "INACTIVE");
+
+    if (is_pending) {
+        /* Get the procedure transaction identity assigned to the pending PDN
+         * connection entry */
+        pti = esm_pt_get_pending_pti(esm_pt_data, ESM_PT_PENDING);
+
+        if (pti == ESM_PT_UNASSIGNED) {
+            LOG_TRACE(ERROR, "ESM-PROC  - No procedure transaction is PENDING");
+            return (RETURNerror);
+        }
 
-    /* Set the procedure transaction state to INACTIVE */
-    (void) esm_pt_set_status(esm_pt_data, pti, ESM_PT_INACTIVE);
-  } else {
-    /* Get the procedure transaction identity assigned to the PDN
-     * connection entry which is still pending in the inactive state */
-    pti = esm_pt_get_pending_pti(esm_pt_data, ESM_PT_INACTIVE);
-  }
+        /* Set the procedure transaction state to INACTIVE */
+        (void) esm_pt_set_status(esm_pt_data, pti, ESM_PT_INACTIVE);
+    } else {
+        /* Get the procedure transaction identity assigned to the PDN
+         * connection entry which is still pending in the inactive state */
+        pti = esm_pt_get_pending_pti(esm_pt_data, ESM_PT_INACTIVE);
+    }
 
-  /* Release the procedure transaction identity */
-  rc = esm_pt_release(esm_pt_data, pti);
+    /* Release the procedure transaction identity */
+    rc = esm_pt_release(esm_pt_data, pti);
 
-  if (rc != RETURNok) {
-    LOG_TRACE(WARNING, "ESM-PROC  - Failed to release PTI %d", pti);
-  }
+    if (rc != RETURNok) {
+        LOG_TRACE(WARNING, "ESM-PROC  - Failed to release PTI %d", pti);
+    }
 
-  LOG_FUNC_RETURN(rc);
+    LOG_FUNC_RETURN(rc);
 }
 
 
@@ -607,62 +607,62 @@ int esm_proc_pdn_connectivity_failure(nas_user_t *user, int is_pending)
  **      Others:    None                                       **
  **                                                                        **
  ***************************************************************************/
-// FIXME 
+// FIXME
 static void *_pdn_connectivity_t3482_handler(void *args)
 {
-  LOG_FUNC_IN;
-
-  int rc;
-
-  /* Get retransmission timer parameters data */
-  esm_pt_timer_data_t *data = args;
-  nas_user_t *user = data->user;
-  esm_pt_data_t *esm_pt_data = user->esm_pt_data;
-
-  /* Increment the retransmission counter */
-  data->count += 1;
-
-  LOG_TRACE(WARNING, "ESM-PROC  - T3482 timer expired (pti=%d), "
-            "retransmission counter = %d", data->pti, data->count);
-
-  if (data->count < ESM_PDN_CONNECTIVITY_COUNTER_MAX) {
-    emm_sap_t emm_sap;
-    emm_esm_data_t *emm_esm = &emm_sap.u.emm_esm.u.data;
-    /*
-     * Notify EMM that the PDN connectivity request message
-     * has to be sent again
-     */
-    emm_sap.primitive = EMMESM_UNITDATA_REQ;
-    emm_sap.u.emm_esm.ueid = user->ueid;
-    emm_esm->msg.length = data->msg.length;
-    emm_esm->msg.value = data->msg.value;
-    rc = emm_sap_send(user, &emm_sap);
-
-    if (rc != RETURNerror) {
-      /* Restart the timer T3482 */
-      rc = esm_pt_start_timer(user, data->pti, &data->msg, T3482_DEFAULT_VALUE,
-                              _pdn_connectivity_t3482_handler);
-    }
-  } else {
-    /* Set the procedure transaction state to INACTIVE */
-    rc = esm_pt_set_status(esm_pt_data, data->pti, ESM_PT_INACTIVE);
-
-    if (rc != RETURNok) {
-      /* The procedure transaction was already in INACTIVE state */
-      LOG_TRACE(WARNING, "ESM-PROC  - PTI %d was already INACTIVE",
-                data->pti);
+    LOG_FUNC_IN;
+
+    int rc;
+
+    /* Get retransmission timer parameters data */
+    esm_pt_timer_data_t *data = args;
+    nas_user_t *user = data->user;
+    esm_pt_data_t *esm_pt_data = user->esm_pt_data;
+
+    /* Increment the retransmission counter */
+    data->count += 1;
+
+    LOG_TRACE(WARNING, "ESM-PROC  - T3482 timer expired (pti=%d), "
+              "retransmission counter = %d", data->pti, data->count);
+
+    if (data->count < ESM_PDN_CONNECTIVITY_COUNTER_MAX) {
+        emm_sap_t emm_sap;
+        emm_esm_data_t *emm_esm = &emm_sap.u.emm_esm.u.data;
+        /*
+         * Notify EMM that the PDN connectivity request message
+         * has to be sent again
+         */
+        emm_sap.primitive = EMMESM_UNITDATA_REQ;
+        emm_sap.u.emm_esm.ueid = user->ueid;
+        emm_esm->msg.length = data->msg.length;
+        emm_esm->msg.value = data->msg.value;
+        rc = emm_sap_send(user, &emm_sap);
+
+        if (rc != RETURNerror) {
+            /* Restart the timer T3482 */
+            rc = esm_pt_start_timer(user, data->pti, &data->msg, T3482_DEFAULT_VALUE,
+                                    _pdn_connectivity_t3482_handler);
+        }
     } else {
-      /* Release the transaction identity assigned to this procedure */
-      rc = esm_pt_release(esm_pt_data, data->pti);
-
-      if (rc != RETURNok) {
-        LOG_TRACE(WARNING, "ESM-PROC  - Failed to release PTI %d",
-                  data->pti);
-      }
+        /* Set the procedure transaction state to INACTIVE */
+        rc = esm_pt_set_status(esm_pt_data, data->pti, ESM_PT_INACTIVE);
+
+        if (rc != RETURNok) {
+            /* The procedure transaction was already in INACTIVE state */
+            LOG_TRACE(WARNING, "ESM-PROC  - PTI %d was already INACTIVE",
+                      data->pti);
+        } else {
+            /* Release the transaction identity assigned to this procedure */
+            rc = esm_pt_release(esm_pt_data, data->pti);
+
+            if (rc != RETURNok) {
+                LOG_TRACE(WARNING, "ESM-PROC  - Failed to release PTI %d",
+                          data->pti);
+            }
+        }
     }
-  }
 
-  LOG_FUNC_RETURN(NULL);
+    LOG_FUNC_RETURN(NULL);
 }
 
 /*
@@ -692,63 +692,63 @@ static int _pdn_connectivity_create(esm_data_t *esm_data, int pid, const OctetSt
                                     esm_proc_pdn_type_t pdn_type,
                                     int is_emergency)
 {
-  esm_pdn_t *pdn = NULL;
+    esm_pdn_t *pdn = NULL;
 
-  LOG_TRACE(INFO, "ESM-PROC  - Create new PDN connection (pid=%d)", pid);
+    LOG_TRACE(INFO, "ESM-PROC  - Create new PDN connection (pid=%d)", pid);
 
-  if (pid >= ESM_DATA_PDN_MAX) {
-    return (RETURNerror);
-  } else if (esm_data->pdn[pid].is_active) {
-    LOG_TRACE(ERROR, "ESM-PROC  - PDN connection is active");
-    return (RETURNerror);
-  }
-
-  if (esm_data->pdn[pid].data != NULL) {
-    /* Update existing non-active PDN connection */
-    pdn = esm_data->pdn[pid].data;
-  } else {
-    /* Create new PDN connection */
-    pdn = (esm_pdn_t *)malloc(sizeof(esm_pdn_t));
-
-    if (pdn == NULL) {
-      LOG_TRACE(WARNING, "ESM-PROC  - "
-                "Failed to create new PDN connection");
-      return (RETURNerror);
+    if (pid >= ESM_DATA_PDN_MAX) {
+        return (RETURNerror);
+    } else if (esm_data->pdn[pid].is_active) {
+        LOG_TRACE(ERROR, "ESM-PROC  - PDN connection is active");
+        return (RETURNerror);
     }
 
-    memset(pdn, 0, sizeof(esm_pdn_t));
-    /* Increment the number of PDN connections */
-    esm_data->n_pdns += 1;
-    /* Set the PDN connection identifier */
-    esm_data->pdn[pid].pid = pid;
-    /* Reset the PDN connection active indicator */
-    esm_data->pdn[pid].is_active = FALSE;
-    /* Setup the PDN connection data */
-    esm_data->pdn[pid].data = pdn;
-  }
-
-  /* Update the PDN connection data */
-  pdn->is_emergency = is_emergency;
-
-  if ( apn && (apn->length > 0) ) {
-    if (pdn->apn.length > 0) {
-      free(pdn->apn.value);
-      pdn->apn.length = 0;
+    if (esm_data->pdn[pid].data != NULL) {
+        /* Update existing non-active PDN connection */
+        pdn = esm_data->pdn[pid].data;
+    } else {
+        /* Create new PDN connection */
+        pdn = (esm_pdn_t *)malloc(sizeof(esm_pdn_t));
+
+        if (pdn == NULL) {
+            LOG_TRACE(WARNING, "ESM-PROC  - "
+                      "Failed to create new PDN connection");
+            return (RETURNerror);
+        }
+
+        memset(pdn, 0, sizeof(esm_pdn_t));
+        /* Increment the number of PDN connections */
+        esm_data->n_pdns += 1;
+        /* Set the PDN connection identifier */
+        esm_data->pdn[pid].pid = pid;
+        /* Reset the PDN connection active indicator */
+        esm_data->pdn[pid].is_active = FALSE;
+        /* Setup the PDN connection data */
+        esm_data->pdn[pid].data = pdn;
     }
 
-    pdn->apn.value = (uint8_t *)malloc(apn->length + 1);
+    /* Update the PDN connection data */
+    pdn->is_emergency = is_emergency;
+
+    if ( apn && (apn->length > 0) ) {
+        if (pdn->apn.length > 0) {
+            free(pdn->apn.value);
+            pdn->apn.length = 0;
+        }
+
+        pdn->apn.value = (uint8_t *)malloc(apn->length + 1);
 
-    if (pdn->apn.value) {
-      pdn->apn.length = apn->length;
-      memcpy(pdn->apn.value, apn->value, apn->length);
-      pdn->apn.value[pdn->apn.length] = '\0';
+        if (pdn->apn.value) {
+            pdn->apn.length = apn->length;
+            memcpy(pdn->apn.value, apn->value, apn->length);
+            pdn->apn.value[pdn->apn.length] = '\0';
+        }
     }
-  }
 
-  pdn->type = pdn_type;
-  pdn->addr_realloc = FALSE;
+    pdn->type = pdn_type;
+    pdn->addr_realloc = FALSE;
 
-  return (RETURNok);
+    return (RETURNok);
 }
 
 /****************************************************************************
@@ -772,75 +772,75 @@ static int _pdn_connectivity_update(esm_data_t *esm_data, int pid, const OctetSt
                                     const OctetString *pdn_addr,
                                     int esm_cause)
 {
-  LOG_TRACE(INFO, "ESM-PROC  - Update PDN connection (pid=%d)", pid);
+    LOG_TRACE(INFO, "ESM-PROC  - Update PDN connection (pid=%d)", pid);
 
-  if (pid >= ESM_DATA_PDN_MAX) {
-    return (RETURNerror);
-  } else if (pid != esm_data->pdn[pid].pid) {
-    LOG_TRACE(ERROR, "ESM-PROC  - PDN connection identifier is not valid");
-    return (RETURNerror);
-  } else if (esm_data->pdn[pid].data == NULL) {
-    LOG_TRACE(ERROR, "ESM-PROC  - PDN connection has not been allocated");
-    return (RETURNerror);
-  } else if (esm_data->pdn[pid].is_active) {
-    LOG_TRACE(WARNING, "ESM-PROC  - Active %s PDN connection to %s already "
-              "exists", (esm_data->pdn[pid].data->type != ESM_PDN_TYPE_IPV4)?
-              "IPv6" : "IPv4", esm_data->pdn[pid].data->apn.value);
-    return (RETURNerror);
-  }
+    if (pid >= ESM_DATA_PDN_MAX) {
+        return (RETURNerror);
+    } else if (pid != esm_data->pdn[pid].pid) {
+        LOG_TRACE(ERROR, "ESM-PROC  - PDN connection identifier is not valid");
+        return (RETURNerror);
+    } else if (esm_data->pdn[pid].data == NULL) {
+        LOG_TRACE(ERROR, "ESM-PROC  - PDN connection has not been allocated");
+        return (RETURNerror);
+    } else if (esm_data->pdn[pid].is_active) {
+        LOG_TRACE(WARNING, "ESM-PROC  - Active %s PDN connection to %s already "
+                  "exists", (esm_data->pdn[pid].data->type != ESM_PDN_TYPE_IPV4)?
+                  "IPv6" : "IPv4", esm_data->pdn[pid].data->apn.value);
+        return (RETURNerror);
+    }
 
-  /* Get the PDN connection */
-  esm_pdn_t *pdn = esm_data->pdn[pid].data;
+    /* Get the PDN connection */
+    esm_pdn_t *pdn = esm_data->pdn[pid].data;
 
-  /* Setup the Access Point Name value */
-  if ( apn && (apn->length > 0) ) {
-    if (pdn->apn.length > 0) {
-      free(pdn->apn.value);
-      pdn->apn.length = 0;
-    }
+    /* Setup the Access Point Name value */
+    if ( apn && (apn->length > 0) ) {
+        if (pdn->apn.length > 0) {
+            free(pdn->apn.value);
+            pdn->apn.length = 0;
+        }
 
-    pdn->apn.value = (uint8_t *)malloc(apn->length + 1);
+        pdn->apn.value = (uint8_t *)malloc(apn->length + 1);
 
-    if (pdn->apn.value) {
-      pdn->apn.length = apn->length;
-      memcpy(pdn->apn.value, apn->value, apn->length);
-      pdn->apn.value[pdn->apn.length] = '\0';
+        if (pdn->apn.value) {
+            pdn->apn.length = apn->length;
+            memcpy(pdn->apn.value, apn->value, apn->length);
+            pdn->apn.value[pdn->apn.length] = '\0';
+        }
     }
-  }
 
-  /* Setup the IP address allocated by the network */
-  if ( pdn_addr && (pdn_addr->length > 0) ) {
-    int length = ((pdn_addr->length < ESM_DATA_IP_ADDRESS_SIZE) ?
-                  pdn_addr->length : ESM_DATA_IP_ADDRESS_SIZE);
-    memcpy(pdn->ip_addr, pdn_addr->value, length);
-    pdn->type = pdn_type;
-  }
-
-  /*
-   * 3GPP TS 24.301, section 6.2.2
-   * Update the address re-allocation indicator
-   */
-  if (esm_cause == ESM_CAUSE_SINGLE_ADDRESS_BEARERS_ONLY_ALLOWED) {
-    /* The UE requested IPv4 or IPv6 address and the network allows
-     * single addressing per bearer:
-     * The UE should subsequently request another PDN connection for
-     * the other IP version using the UE requested PDN connectivity
-     * procedure to the same APN with a single address PDN type
-     * (IPv4 or IPv6) other than the one already activated */
-    pdn->addr_realloc = TRUE;
-  } else if ( (esm_cause == ESM_CAUSE_PDN_TYPE_IPV4_ONLY_ALLOWED) ||
-              (esm_cause == ESM_CAUSE_PDN_TYPE_IPV6_ONLY_ALLOWED) ) {
-    /* The UE requested IPv4 or IPv6 address and the network allows
-     * IPv4 or IPv6 PDN address only:
-     * The UE shall not subsequently initiate another UE requested
-     * PDN connectivity procedure to the same APN to obtain a PDN
-     * type different from the one allowed by the network */
-    pdn->addr_realloc = FALSE;
-  } else if (pdn_type != ESM_PDN_TYPE_IPV4V6) {
-    pdn->addr_realloc = TRUE;
-  }
+    /* Setup the IP address allocated by the network */
+    if ( pdn_addr && (pdn_addr->length > 0) ) {
+        int length = ((pdn_addr->length < ESM_DATA_IP_ADDRESS_SIZE) ?
+                      pdn_addr->length : ESM_DATA_IP_ADDRESS_SIZE);
+        memcpy(pdn->ip_addr, pdn_addr->value, length);
+        pdn->type = pdn_type;
+    }
+
+    /*
+     * 3GPP TS 24.301, section 6.2.2
+     * Update the address re-allocation indicator
+     */
+    if (esm_cause == ESM_CAUSE_SINGLE_ADDRESS_BEARERS_ONLY_ALLOWED) {
+        /* The UE requested IPv4 or IPv6 address and the network allows
+         * single addressing per bearer:
+         * The UE should subsequently request another PDN connection for
+         * the other IP version using the UE requested PDN connectivity
+         * procedure to the same APN with a single address PDN type
+         * (IPv4 or IPv6) other than the one already activated */
+        pdn->addr_realloc = TRUE;
+    } else if ( (esm_cause == ESM_CAUSE_PDN_TYPE_IPV4_ONLY_ALLOWED) ||
+                (esm_cause == ESM_CAUSE_PDN_TYPE_IPV6_ONLY_ALLOWED) ) {
+        /* The UE requested IPv4 or IPv6 address and the network allows
+         * IPv4 or IPv6 PDN address only:
+         * The UE shall not subsequently initiate another UE requested
+         * PDN connectivity procedure to the same APN to obtain a PDN
+         * type different from the one allowed by the network */
+        pdn->addr_realloc = FALSE;
+    } else if (pdn_type != ESM_PDN_TYPE_IPV4V6) {
+        pdn->addr_realloc = TRUE;
+    }
 
-  return (RETURNok);
+    return (RETURNok);
 }
 
 /****************************************************************************
@@ -861,42 +861,42 @@ static int _pdn_connectivity_update(esm_data_t *esm_data, int pid, const OctetSt
  ***************************************************************************/
 static int _pdn_connectivity_delete(esm_data_t *esm_data, int pid)
 {
-  int pti = ESM_PT_UNASSIGNED;
-
-  if (pid < ESM_DATA_PDN_MAX) {
-    if (pid != esm_data->pdn[pid].pid) {
-      LOG_TRACE(ERROR,
-                "ESM-PROC  - PDN connection identifier is not valid");
-    } else if (esm_data->pdn[pid].data == NULL) {
-      LOG_TRACE(ERROR,
-                "ESM-PROC  - PDN connection has not been allocated");
-    } else if (esm_data->pdn[pid].is_active) {
-      LOG_TRACE(ERROR, "ESM-PROC  - PDN connection is active");
-    } else {
-      /* Get the identity of the procedure transaction that created
-       * the PDN connection */
-      pti = esm_data->pdn[pid].data->pti;
+    int pti = ESM_PT_UNASSIGNED;
+
+    if (pid < ESM_DATA_PDN_MAX) {
+        if (pid != esm_data->pdn[pid].pid) {
+            LOG_TRACE(ERROR,
+                      "ESM-PROC  - PDN connection identifier is not valid");
+        } else if (esm_data->pdn[pid].data == NULL) {
+            LOG_TRACE(ERROR,
+                      "ESM-PROC  - PDN connection has not been allocated");
+        } else if (esm_data->pdn[pid].is_active) {
+            LOG_TRACE(ERROR, "ESM-PROC  - PDN connection is active");
+        } else {
+            /* Get the identity of the procedure transaction that created
+             * the PDN connection */
+            pti = esm_data->pdn[pid].data->pti;
+        }
     }
-  }
 
-  if (pti != ESM_PT_UNASSIGNED) {
-    /* Decrement the number of PDN connections */
-    esm_data->n_pdns -= 1;
-    /* Set the PDN connection as available */
-    esm_data->pdn[pid].pid = -1;
+    if (pti != ESM_PT_UNASSIGNED) {
+        /* Decrement the number of PDN connections */
+        esm_data->n_pdns -= 1;
+        /* Set the PDN connection as available */
+        esm_data->pdn[pid].pid = -1;
+
+        /* Release allocated PDN connection data */
+        if (esm_data->pdn[pid].data->apn.length > 0) {
+            free(esm_data->pdn[pid].data->apn.value);
+        }
 
-    /* Release allocated PDN connection data */
-    if (esm_data->pdn[pid].data->apn.length > 0) {
-      free(esm_data->pdn[pid].data->apn.value);
+        free(esm_data->pdn[pid].data);
+        esm_data->pdn[pid].data = NULL;
+        LOG_TRACE(WARNING, "ESM-PROC  - PDN connection %d released", pid);
     }
 
-    free(esm_data->pdn[pid].data);
-    esm_data->pdn[pid].data = NULL;
-    LOG_TRACE(WARNING, "ESM-PROC  - PDN connection %d released", pid);
-  }
-
-  /* Return the procedure transaction identity */
-  return (pti);
+    /* Return the procedure transaction identity */
+    return (pti);
 }
 
 /****************************************************************************
@@ -916,24 +916,24 @@ static int _pdn_connectivity_delete(esm_data_t *esm_data, int pid)
  ***************************************************************************/
 static int _pdn_connectivity_set_pti(esm_data_t *esm_data, int pid, int pti)
 {
-  if (pid < ESM_DATA_PDN_MAX) {
-    if (pid != esm_data->pdn[pid].pid) {
-      LOG_TRACE(ERROR,
-                "ESM-PROC  - PDN connection identifier is not valid");
-    } else if (esm_data->pdn[pid].data == NULL) {
-      LOG_TRACE(ERROR,
-                "ESM-PROC  - PDN connection has not been allocated");
-    } else if (esm_data->pdn[pid].is_active) {
-      LOG_TRACE(ERROR, "ESM-PROC  - PDN connection is active");
-    } else {
-      /* Update the identity of the procedure transaction assigned to
-       * the PDN connection */
-      esm_data->pdn[pid].data->pti = pti;
-      return (RETURNok);
+    if (pid < ESM_DATA_PDN_MAX) {
+        if (pid != esm_data->pdn[pid].pid) {
+            LOG_TRACE(ERROR,
+                      "ESM-PROC  - PDN connection identifier is not valid");
+        } else if (esm_data->pdn[pid].data == NULL) {
+            LOG_TRACE(ERROR,
+                      "ESM-PROC  - PDN connection has not been allocated");
+        } else if (esm_data->pdn[pid].is_active) {
+            LOG_TRACE(ERROR, "ESM-PROC  - PDN connection is active");
+        } else {
+            /* Update the identity of the procedure transaction assigned to
+             * the PDN connection */
+            esm_data->pdn[pid].data->pti = pti;
+            return (RETURNok);
+        }
     }
-  }
 
-  return (RETURNerror);
+    return (RETURNerror);
 }
 
 /****************************************************************************
@@ -953,26 +953,26 @@ static int _pdn_connectivity_set_pti(esm_data_t *esm_data, int pid, int pti)
  ***************************************************************************/
 static int _pdn_connectivity_find_apn(esm_data_t *esm_data, const OctetString *apn)
 {
-  int i;
+    int i;
 
-  for (i = 0; i < ESM_DATA_PDN_MAX; i++) {
-    if ( (esm_data->pdn[i].pid != -1) && esm_data->pdn[i].data ) {
-      if (esm_data->pdn[i].data->apn.length != apn->length) {
-        continue;
-      }
+    for (i = 0; i < ESM_DATA_PDN_MAX; i++) {
+        if ( (esm_data->pdn[i].pid != -1) && esm_data->pdn[i].data ) {
+            if (esm_data->pdn[i].data->apn.length != apn->length) {
+                continue;
+            }
 
-      if (memcmp(esm_data->pdn[i].data->apn.value,
-                 apn->value, apn->length) != 0) {
-        continue;
-      }
+            if (memcmp(esm_data->pdn[i].data->apn.value,
+                       apn->value, apn->length) != 0) {
+                continue;
+            }
 
-      /* PDN entry found */
-      break;
+            /* PDN entry found */
+            break;
+        }
     }
-  }
 
-  /* Return the identifier of the PDN connection */
-  return (esm_data->pdn[i].pid);
+    /* Return the identifier of the PDN connection */
+    return (esm_data->pdn[i].pid);
 }
 
 /****************************************************************************
@@ -994,35 +994,35 @@ static int _pdn_connectivity_find_apn(esm_data_t *esm_data, const OctetString *a
 static int _pdn_connectivity_find_pdn(esm_data_t *esm_data, const OctetString *apn,
                                       const esm_proc_pdn_type_t pdn_type)
 {
-  int i;
-
-  for (i = 0; i < ESM_DATA_PDN_MAX; i++) {
-    if ( (esm_data->pdn[i].pid != -1) && esm_data->pdn[i].data ) {
-      /* PDN connection established during initial network attachment */
-      if (esm_data->pdn[i].data->apn.length == 0) {
-        break;
-      }
-
-      /* Subsequent PDN connection established for the specified APN */
-      if (esm_data->pdn[i].data->apn.length != apn->length) {
-        continue;
-      }
-
-      if (memcmp(esm_data->pdn[i].data->apn.value,
-                 apn->value, apn->length) != 0) {
-        continue;
-      }
-
-      if (esm_data->pdn[i].data->type == ESM_PDN_TYPE_IPV4V6) {
-        break;
-      }
-
-      if (esm_data->pdn[i].data->type == pdn_type) {
-        break;
-      }
+    int i;
+
+    for (i = 0; i < ESM_DATA_PDN_MAX; i++) {
+        if ( (esm_data->pdn[i].pid != -1) && esm_data->pdn[i].data ) {
+            /* PDN connection established during initial network attachment */
+            if (esm_data->pdn[i].data->apn.length == 0) {
+                break;
+            }
+
+            /* Subsequent PDN connection established for the specified APN */
+            if (esm_data->pdn[i].data->apn.length != apn->length) {
+                continue;
+            }
+
+            if (memcmp(esm_data->pdn[i].data->apn.value,
+                       apn->value, apn->length) != 0) {
+                continue;
+            }
+
+            if (esm_data->pdn[i].data->type == ESM_PDN_TYPE_IPV4V6) {
+                break;
+            }
+
+            if (esm_data->pdn[i].data->type == pdn_type) {
+                break;
+            }
+        }
     }
-  }
 
-  /* Return the identifier of the PDN connection */
-  return (esm_data->pdn[i].pid);
+    /* Return the identifier of the PDN connection */
+    return (esm_data->pdn[i].pid);
 }
diff --git a/openair3/NAS/UE/ESM/esm_ebr_context.c b/openair3/NAS/UE/ESM/esm_ebr_context.c
index e2a327f4886c1fd4cf84c78d7901a1bb5bfcc307..7404cd8b8a83a751e21fad46eca07033e41afcac 100644
--- a/openair3/NAS/UE/ESM/esm_ebr_context.c
+++ b/openair3/NAS/UE/ESM/esm_ebr_context.c
@@ -57,7 +57,13 @@ Description Defines functions used to handle EPS bearer contexts.
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
-
+#ifdef PDCP_USE_NETLINK
+#ifdef UESIM_EXPANSION
+  #include "openairinterface5g_limits.h"
+  extern uint16_t inst_pdcp_list[NUMBER_OF_UE_MAX];
+#endif
+#endif
+extern uint8_t  nfapi_mode;
 
 /****************************************************************************/
 /****************  E X T E R N A L    D E F I N I T I O N S  ****************/
@@ -208,7 +214,7 @@ int esm_ebr_context_create(
            char           broadcast[INET_ADDRSTRLEN];
            struct in_addr in_addr;
            char           command_line[500];
-           int            res;
+           int            res = -1;
 
            switch (pdn->type) {
            case NET_PDN_TYPE_IPV4V6:
@@ -272,7 +278,38 @@ int esm_ebr_context_create(
                strcpy(broadcast, ipv4_addr);
              }
 
-             res = sprintf(command_line,
+             if(nfapi_mode ==3){
+                // this is for L2 FAPI simulator.
+                // change for multiple UE's like 256UEs.
+                // if it's made too many tables , OS may crush so we use one table.
+#ifdef PDCP_USE_NETLINK
+#ifdef UESIM_EXPANSION
+                uint16_t inst_nic = (pdn->ip_addr[3] & 0x000000FF) - 2;
+                res = sprintf(command_line,
+                           "ifconfig oip%d %s netmask %s broadcast %s up && "
+                           "ip rule add from %s/24 table %d && "
+                           "ip rule add to %s/24 table %d && "
+                           "ip route add default dev oip%d table %d",
+                           inst_nic + 1, ipv4_addr, netmask, broadcast,
+                           ipv4_addr, 201,
+                           ipv4_addr, 201,
+                           inst_nic + 1, 201);
+
+               inst_pdcp_list[inst_nic] = ueid;
+#else
+               res = sprintf(command_line,
+                          "ifconfig oip%d %s netmask %s broadcast %s up && "
+                          "ip rule add from %s/32 table %d && "
+                          "ip rule add to %s/32 table %d && "
+                          "ip route add default dev oip%d table %d",
+                          ueid + 1, ipv4_addr, netmask, broadcast,
+                          ipv4_addr, ueid + 201,
+                          ipv4_addr, ueid + 201,
+                          ueid + 1, ueid + 201);
+#endif
+#endif
+             } else {
+               res = sprintf(command_line,
                            "ifconfig oip%d %s netmask %s broadcast %s up && "
                            "ip rule add from %s/32 table %d && "
                            "ip rule add to %s/32 table %d && "
@@ -281,6 +318,7 @@ int esm_ebr_context_create(
                            ipv4_addr, ueid + 201,
                            ipv4_addr, ueid + 201,
                            ueid + 1, ueid + 201);
+             }
              if ( res<0 ) {
                 LOG_TRACE(WARNING, "ESM-PROC  - Failed to system command string");
              }
diff --git a/openair3/NAS/UE/nas_itti_messaging.c b/openair3/NAS/UE/nas_itti_messaging.c
index 0389106ec35e5a705a27352c4de8838efb74557a..0c5a2fec1fa67f828a1b13292d0d1473f1352e33 100644
--- a/openair3/NAS/UE/nas_itti_messaging.c
+++ b/openair3/NAS/UE/nas_itti_messaging.c
@@ -85,94 +85,13 @@ static const uint8_t esm_message_ids[] = {
   ESM_STATUS,
 };
 
-static int _nas_find_message_index(const uint8_t message_id, const uint8_t *message_ids, const int ids_number)
-{
-  int i;
 
-  for(i = 0; i < ids_number; i ++) {
-    if (message_id == message_ids[i]) {
-      return (2 + i);
-    }
-  }
-
-  return (1);
-}
-
-int nas_itti_plain_msg(const char *buffer, const nas_message_t *msg, const int length, const int down_link)
-{
-  MessageDef *message_p;
-  int data_length = length < NAS_DATA_LENGHT_MAX ? length : NAS_DATA_LENGHT_MAX;
-  int message_type = -1;
-  MessagesIds messageId_raw = -1;
-  MessagesIds messageId_plain = -1;
-
-  /* Define message ids */
-  if (msg->header.protocol_discriminator == EPS_MOBILITY_MANAGEMENT_MESSAGE) {
-    message_type    = 0;
-    messageId_raw   = down_link ? NAS_DL_EMM_RAW_MSG : NAS_UL_EMM_RAW_MSG;
-    messageId_plain = down_link ? NAS_DL_EMM_PLAIN_MSG : NAS_UL_EMM_PLAIN_MSG;
-  } else {
-    if (msg->header.protocol_discriminator == EPS_SESSION_MANAGEMENT_MESSAGE) {
-      message_type    = 1;
-      messageId_raw   = down_link ? NAS_DL_ESM_RAW_MSG : NAS_UL_ESM_RAW_MSG;
-      messageId_plain = down_link ? NAS_DL_ESM_PLAIN_MSG : NAS_UL_ESM_PLAIN_MSG;
-    }
-  }
-
-  if (message_type >= 0) {
-    /* Create and send the RAW message */
-    message_p = itti_alloc_new_message(TASK_ORIGIN, messageId_raw);
-
-    NAS_DL_EMM_RAW_MSG(message_p).lenght = length;
-    memset ((void *) &(NAS_DL_EMM_RAW_MSG(message_p).data), 0, NAS_DATA_LENGHT_MAX);
-    memcpy ((void *) &(NAS_DL_EMM_RAW_MSG(message_p).data), buffer, data_length);
-
-    itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
-
-    /* Create and send the plain message */
-    if (message_type == 0) {
-      message_p = itti_alloc_new_message(TASK_ORIGIN, messageId_plain);
-
-      NAS_DL_EMM_PLAIN_MSG(message_p).present = _nas_find_message_index(msg->plain.emm.header.message_type, emm_message_ids, sizeof(emm_message_ids) / sizeof(emm_message_ids[0]));
-      memcpy ((void *) &(NAS_DL_EMM_PLAIN_MSG(message_p).choice), &msg->plain.emm, sizeof (EMM_msg));
-    } else {
-      message_p = itti_alloc_new_message(TASK_ORIGIN, messageId_plain);
-
-      NAS_DL_ESM_PLAIN_MSG(message_p).present = _nas_find_message_index(msg->plain.esm.header.message_type, esm_message_ids, sizeof(esm_message_ids) / sizeof(esm_message_ids[0]));
-      memcpy ((void *) &(NAS_DL_ESM_PLAIN_MSG(message_p).choice), &msg->plain.esm, sizeof (ESM_msg));
-    }
-
-    return itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
-  }
-
-  return EXIT_FAILURE;
+int nas_itti_plain_msg(const char *buffer, const nas_message_t *msg, const int length, const int down_link) {
+  return 0;
 }
 
-int nas_itti_protected_msg(const char *buffer, const nas_message_t *msg, const int length, const int down_link)
-{
-  MessageDef *message_p = NULL;
-
-  if (msg->header.protocol_discriminator == EPS_MOBILITY_MANAGEMENT_MESSAGE) {
-    message_p = itti_alloc_new_message(TASK_ORIGIN, down_link ? NAS_DL_EMM_PROTECTED_MSG : NAS_UL_EMM_PROTECTED_MSG);
-
-    memcpy ((void *) &(NAS_DL_EMM_PROTECTED_MSG(message_p).header), &msg->header, sizeof (nas_message_security_header_t));
-    NAS_DL_EMM_PROTECTED_MSG(message_p).present = _nas_find_message_index(msg->security_protected.plain.emm.header.message_type, emm_message_ids, sizeof(emm_message_ids) / sizeof(emm_message_ids[0]));
-    memcpy ((void *) &(NAS_DL_EMM_PROTECTED_MSG(message_p).choice), &msg->security_protected.plain.emm, sizeof (EMM_msg));
-  } else {
-    if (msg->header.protocol_discriminator == EPS_SESSION_MANAGEMENT_MESSAGE) {
-      message_p = itti_alloc_new_message(TASK_ORIGIN, down_link ? NAS_DL_ESM_PROTECTED_MSG : NAS_UL_ESM_PROTECTED_MSG);
-
-      memcpy ((void *) &(NAS_DL_ESM_PROTECTED_MSG(message_p).header), &msg->header, sizeof (nas_message_security_header_t));
-      NAS_DL_ESM_PROTECTED_MSG(message_p).present =  _nas_find_message_index(msg->security_protected.plain.esm.header.message_type, esm_message_ids, sizeof(esm_message_ids) / sizeof(esm_message_ids[0]));
-      memcpy ((void *) &(NAS_DL_ESM_PROTECTED_MSG(message_p).choice), &msg->security_protected.plain.esm, sizeof (ESM_msg));
-    }
-  }
-
-  if (message_p != NULL) {
-    return itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
-  }
-
-  return EXIT_FAILURE;
+int nas_itti_protected_msg(const char *buffer, const nas_message_t *msg, const int length, const int down_link) {
+  return 0;
 }
 #endif
 
@@ -180,112 +99,89 @@ int nas_itti_protected_msg(const char *buffer, const nas_message_t *msg, const i
 
 extern unsigned char NB_eNB_INST;
 
-int nas_itti_kenb_refresh_req(const Byte_t kenb[32])
-{
+int nas_itti_kenb_refresh_req(const Byte_t kenb[32]) {
   MessageDef *message_p;
-
   message_p = itti_alloc_new_message(TASK_NAS_UE, NAS_KENB_REFRESH_REQ);
-
   memcpy(NAS_KENB_REFRESH_REQ(message_p).kenb, kenb, sizeof(NAS_KENB_REFRESH_REQ(message_p).kenb));
-
   MSC_LOG_TX_MESSAGE(
-      MSC_NAS_UE,
-      MSC_RRC_UE,
-      NULL,0,
-      "0 NAS_KENB_REFRESH_REQ KeNB "
-      "%02x%02x%02x%02x"
-      "%02x%02x%02x%02x"
-      "%02x%02x%02x%02x"
-      "%02x%02x%02x%02x"
-      "%02x%02x%02x%02x"
-      "%02x%02x%02x%02x"
-      "%02x%02x%02x%02x"
-      "%02x%02x%02x%02x",
-      kenb[0],  kenb[1],  kenb[2],  kenb[3],
-      kenb[4],  kenb[5],  kenb[6],  kenb[7],
-      kenb[8],  kenb[9],  kenb[10], kenb[11],
-      kenb[12], kenb[13], kenb[14], kenb[15],
-      kenb[16], kenb[17], kenb[18], kenb[19],
-      kenb[20], kenb[21], kenb[22], kenb[23],
-      kenb[24], kenb[25], kenb[26], kenb[27],
-      kenb[28], kenb[29], kenb[30], kenb[31]);
-
+    MSC_NAS_UE,
+    MSC_RRC_UE,
+    NULL,0,
+    "0 NAS_KENB_REFRESH_REQ KeNB "
+    "%02x%02x%02x%02x"
+    "%02x%02x%02x%02x"
+    "%02x%02x%02x%02x"
+    "%02x%02x%02x%02x"
+    "%02x%02x%02x%02x"
+    "%02x%02x%02x%02x"
+    "%02x%02x%02x%02x"
+    "%02x%02x%02x%02x",
+    kenb[0],  kenb[1],  kenb[2],  kenb[3],
+    kenb[4],  kenb[5],  kenb[6],  kenb[7],
+    kenb[8],  kenb[9],  kenb[10], kenb[11],
+    kenb[12], kenb[13], kenb[14], kenb[15],
+    kenb[16], kenb[17], kenb[18], kenb[19],
+    kenb[20], kenb[21], kenb[22], kenb[23],
+    kenb[24], kenb[25], kenb[26], kenb[27],
+    kenb[28], kenb[29], kenb[30], kenb[31]);
   return itti_send_msg_to_task(TASK_RRC_UE, NB_eNB_INST + 0 /* TODO to be virtualized */, message_p);
 }
 
-int nas_itti_cell_info_req(const plmn_t plmnID, const Byte_t rat, int user_id)
-{
+int nas_itti_cell_info_req(const plmn_t plmnID, const Byte_t rat, int user_id) {
   MessageDef *message_p;
-
   message_p = itti_alloc_new_message(TASK_NAS_UE, NAS_CELL_SELECTION_REQ);
-
   NAS_CELL_SELECTION_REQ(message_p).plmnID    = plmnID;
   NAS_CELL_SELECTION_REQ(message_p).rat       = rat;
-
   MSC_LOG_TX_MESSAGE(
-  	  MSC_NAS_UE,
-  	  MSC_RRC_UE,
-  	  NULL,0,
-  	  "0 NAS_CELL_SELECTION_REQ PLMN %X%X%X.%X%X%X",
-  	  plmnID.MCCdigit1, plmnID.MCCdigit2, plmnID.MCCdigit3,
-  	  plmnID.MNCdigit1, plmnID.MNCdigit2, plmnID.MNCdigit3);
-
+    MSC_NAS_UE,
+    MSC_RRC_UE,
+    NULL,0,
+    "0 NAS_CELL_SELECTION_REQ PLMN %X%X%X.%X%X%X",
+    plmnID.MCCdigit1, plmnID.MCCdigit2, plmnID.MCCdigit3,
+    plmnID.MNCdigit1, plmnID.MNCdigit2, plmnID.MNCdigit3);
   return itti_send_msg_to_task(TASK_RRC_UE, NB_eNB_INST + user_id, message_p);
 }
 
-int nas_itti_nas_establish_req(as_cause_t cause, as_call_type_t type, as_stmsi_t s_tmsi, plmn_t plmnID, Byte_t *data, uint32_t length, int user_id)
-{
+int nas_itti_nas_establish_req(as_cause_t cause, as_call_type_t type, as_stmsi_t s_tmsi, plmn_t plmnID, Byte_t *data, uint32_t length, int user_id) {
   MessageDef *message_p;
-
   message_p = itti_alloc_new_message(TASK_NAS_UE, NAS_CONN_ESTABLI_REQ);
-
   NAS_CONN_ESTABLI_REQ(message_p).cause                       = cause;
   NAS_CONN_ESTABLI_REQ(message_p).type                        = type;
   NAS_CONN_ESTABLI_REQ(message_p).s_tmsi                      = s_tmsi;
   NAS_CONN_ESTABLI_REQ(message_p).plmnID                      = plmnID;
   NAS_CONN_ESTABLI_REQ(message_p).initialNasMsg.data          = data;
   NAS_CONN_ESTABLI_REQ(message_p).initialNasMsg.length        = length;
-
   MSC_LOG_TX_MESSAGE(
-		  MSC_NAS_UE,
-		  MSC_RRC_UE,
-  	      NULL,0,
-  	     "0 NAS_CONN_ESTABLI_REQ MME code %u m-TMSI %u PLMN %X%X%X.%X%X%X",
-  	     s_tmsi.MMEcode, s_tmsi.m_tmsi,
-  	     plmnID.MCCdigit1, plmnID.MCCdigit2, plmnID.MCCdigit3,
-  	     plmnID.MNCdigit1, plmnID.MNCdigit2, plmnID.MNCdigit3);
-
+    MSC_NAS_UE,
+    MSC_RRC_UE,
+    NULL,0,
+    "0 NAS_CONN_ESTABLI_REQ MME code %u m-TMSI %u PLMN %X%X%X.%X%X%X",
+    s_tmsi.MMEcode, s_tmsi.m_tmsi,
+    plmnID.MCCdigit1, plmnID.MCCdigit2, plmnID.MCCdigit3,
+    plmnID.MNCdigit1, plmnID.MNCdigit2, plmnID.MNCdigit3);
   return itti_send_msg_to_task(TASK_RRC_UE, NB_eNB_INST + user_id, message_p);
 }
 
-int nas_itti_ul_data_req(const uint32_t ue_id, void *const data, const uint32_t length, int user_id)
-{
+int nas_itti_ul_data_req(const uint32_t ue_id, void *const data, const uint32_t length, int user_id) {
   MessageDef *message_p;
-
   message_p = itti_alloc_new_message(TASK_NAS_UE, NAS_UPLINK_DATA_REQ);
-
   NAS_UPLINK_DATA_REQ(message_p).UEid          = ue_id;
   NAS_UPLINK_DATA_REQ(message_p).nasMsg.data   = data;
   NAS_UPLINK_DATA_REQ(message_p).nasMsg.length = length;
-
   return itti_send_msg_to_task(TASK_RRC_UE, NB_eNB_INST + user_id, message_p);
 }
 
-int nas_itti_rab_establish_rsp(const as_stmsi_t s_tmsi, const as_rab_id_t rabID, const nas_error_code_t errCode, int user_id)
-{
+int nas_itti_rab_establish_rsp(const as_stmsi_t s_tmsi, const as_rab_id_t rabID, const nas_error_code_t errCode, int user_id) {
   MessageDef *message_p;
-
   message_p = itti_alloc_new_message(TASK_NAS_UE, NAS_RAB_ESTABLI_RSP);
-
   NAS_RAB_ESTABLI_RSP(message_p).s_tmsi       = s_tmsi;
   NAS_RAB_ESTABLI_RSP(message_p).rabID        = rabID;
   NAS_RAB_ESTABLI_RSP(message_p).errCode      = errCode;
-
   MSC_LOG_TX_MESSAGE(
-		  MSC_NAS_UE,
-		  MSC_RRC_UE,
-  	      NULL,0,
-  	     "0 NAS_RAB_ESTABLI_RSP MME code %u m-TMSI %u rb id %u status %u",
-  	     s_tmsi.MMEcode, s_tmsi.m_tmsi,rabID, errCode );
+    MSC_NAS_UE,
+    MSC_RRC_UE,
+    NULL,0,
+    "0 NAS_RAB_ESTABLI_RSP MME code %u m-TMSI %u rb id %u status %u",
+    s_tmsi.MMEcode, s_tmsi.m_tmsi,rabID, errCode );
   return itti_send_msg_to_task(TASK_RRC_UE, NB_eNB_INST + user_id, message_p);
 }
diff --git a/openair3/NAS/UE/nas_ue_task.c b/openair3/NAS/UE/nas_ue_task.c
index 529ac5e602b79a342932af73d3ec45a12cae06ab..6df66666389ce1c3f7f36163f51cccf0205b5249 100644
--- a/openair3/NAS/UE/nas_ue_task.c
+++ b/openair3/NAS/UE/nas_ue_task.c
@@ -40,7 +40,7 @@
 
 // FIXME review these externs
 extern unsigned char NB_eNB_INST;
-extern unsigned char NB_UE_INST;
+extern uint16_t NB_UE_INST;
 
 char *make_port_str_from_ueid(const char *base_port_str, int ueid);
 
diff --git a/openair3/S1AP/MESSAGES/ASN1/R10/s1ap-10.9.0.asn1 b/openair3/S1AP/MESSAGES/ASN1/R10/s1ap-10.9.0.asn1
old mode 100755
new mode 100644
diff --git a/openair3/S1AP/MESSAGES/ASN1/R11/s1ap-11.8.0.asn1 b/openair3/S1AP/MESSAGES/ASN1/R11/s1ap-11.8.0.asn1
old mode 100755
new mode 100644
diff --git a/openair3/S1AP/MESSAGES/ASN1/R12/s1ap-12.7.0.asn1 b/openair3/S1AP/MESSAGES/ASN1/R12/s1ap-12.7.0.asn1
old mode 100755
new mode 100644
diff --git a/openair3/S1AP/MESSAGES/ASN1/R13/s1ap-13.6.0.asn1 b/openair3/S1AP/MESSAGES/ASN1/R13/s1ap-13.6.0.asn1
old mode 100755
new mode 100644
diff --git a/openair3/S1AP/MESSAGES/ASN1/R14/s1ap-14.5.0.asn1 b/openair3/S1AP/MESSAGES/ASN1/R14/s1ap-14.5.0.asn1
old mode 100755
new mode 100644
diff --git a/openair3/S1AP/MESSAGES/ASN1/R14/s1ap-14.6.0.asn1 b/openair3/S1AP/MESSAGES/ASN1/R14/s1ap-14.6.0.asn1
old mode 100755
new mode 100644
diff --git a/openair3/S1AP/MESSAGES/ASN1/R15/s1ap-15.1.0.asn1 b/openair3/S1AP/MESSAGES/ASN1/R15/s1ap-15.1.0.asn1
old mode 100755
new mode 100644
diff --git a/openair3/S1AP/MESSAGES/ASN1/R15/s1ap-15.2.0.asn1 b/openair3/S1AP/MESSAGES/ASN1/R15/s1ap-15.2.0.asn1
old mode 100755
new mode 100644
diff --git a/openair3/S1AP/MESSAGES/ASN1/R8/s1ap-8.10.0.asn1 b/openair3/S1AP/MESSAGES/ASN1/R8/s1ap-8.10.0.asn1
old mode 100755
new mode 100644
diff --git a/openair3/S1AP/MESSAGES/ASN1/R9/s1ap-9.10.0.asn1 b/openair3/S1AP/MESSAGES/ASN1/R9/s1ap-9.10.0.asn1
old mode 100755
new mode 100644
diff --git a/openair3/S1AP/s1ap_common.h b/openair3/S1AP/s1ap_common.h
index 94b3e43bc65b8789e330f25179381e0d2de4ba47..fc872564c57d51a34936523c86833b107ef20996 100644
--- a/openair3/S1AP/s1ap_common.h
+++ b/openair3/S1AP/s1ap_common.h
@@ -90,6 +90,7 @@ extern int asn1_xer_print;
 # define S1AP_DEBUG(x, args...) do { fprintf(stdout, "[S1AP][D]"x, ##args); } while(0)
 #endif
 
+
 #define S1AP_FIND_PROTOCOLIE_BY_ID(IE_TYPE, ie, container, IE_ID, mandatory) \
   do {\
     IE_TYPE **ptr; \
@@ -102,15 +103,17 @@ extern int asn1_xer_print;
         break; \
       } \
     } \
-    if (mandatory) DevAssert(ie != NULL); \
+    if (ie == NULL ) { \
+      S1AP_ERROR("S1AP_FIND_PROTOCOLIE_BY_ID: %s %d: ie is NULL\n",__FILE__,__LINE__);\
+      if (mandatory)  _Assert_Exit_ \
+    } \
   } while(0)
-
 /** \brief Function callback prototype.
  **/
 typedef int (*s1ap_message_decoded_callback)(
-  uint32_t         assoc_id,
-  uint32_t         stream,
-  S1AP_S1AP_PDU_t *pdu
+    uint32_t         assoc_id,
+    uint32_t         stream,
+    S1AP_S1AP_PDU_t *pdu
 );
 
 /** \brief Handle criticality
diff --git a/openair3/S1AP/s1ap_eNB.c b/openair3/S1AP/s1ap_eNB.c
index ffdf5d235f521b43cbf9a51eab42b93c9d53fcec..282e7b5f60354cff5c80bfb2e6de7970be5e65dc 100644
--- a/openair3/S1AP/s1ap_eNB.c
+++ b/openair3/S1AP/s1ap_eNB.c
@@ -61,7 +61,7 @@
 #include "assertions.h"
 #include "conversions.h"
 #if defined(TEST_S1C_MME)
-#include "oaisim_mme_test_s1c.h"
+  #include "oaisim_mme_test_s1c.h"
 #endif
 
 s1ap_eNB_config_t s1ap_config;
@@ -74,22 +74,17 @@ void s1ap_eNB_handle_register_eNB(instance_t instance, s1ap_register_enb_req_t *
 
 void s1ap_eNB_handle_sctp_association_resp(instance_t instance, sctp_new_association_resp_t *sctp_new_association_resp);
 
-uint32_t s1ap_generate_eNB_id(void)
-{
+uint32_t s1ap_generate_eNB_id(void) {
   char    *out;
   char     hostname[50];
   int      ret;
   uint32_t eNB_id;
-
   /* Retrieve the host name */
   ret = gethostname(hostname, sizeof(hostname));
   DevAssert(ret == 0);
-
   out = crypt(hostname, "eurecom");
   DevAssert(out != NULL);
-
   eNB_id = ((out[0] << 24) | (out[1] << 16) | (out[2] << 8) | out[3]);
-
   return eNB_id;
 }
 
@@ -99,55 +94,42 @@ static void s1ap_eNB_register_mme(s1ap_eNB_instance_t *instance_p,
                                   uint16_t             in_streams,
                                   uint16_t             out_streams,
                                   uint8_t              broadcast_plmn_num,
-                                  uint8_t              broadcast_plmn_index[PLMN_LIST_MAX_SIZE])
-{
+                                  uint8_t              broadcast_plmn_index[PLMN_LIST_MAX_SIZE]) {
   MessageDef                 *message_p                   = NULL;
   sctp_new_association_req_t *sctp_new_association_req_p  = NULL;
   s1ap_eNB_mme_data_t        *s1ap_mme_data_p             = NULL;
   struct s1ap_eNB_mme_data_s *mme                         = NULL;
-
   DevAssert(instance_p != NULL);
   DevAssert(mme_ip_address != NULL);
-
   message_p = itti_alloc_new_message(TASK_S1AP, SCTP_NEW_ASSOCIATION_REQ);
-
   sctp_new_association_req_p = &message_p->ittiMsg.sctp_new_association_req;
-
   sctp_new_association_req_p->port = S1AP_PORT_NUMBER;
   sctp_new_association_req_p->ppid = S1AP_SCTP_PPID;
-
   sctp_new_association_req_p->in_streams  = in_streams;
   sctp_new_association_req_p->out_streams = out_streams;
-
   memcpy(&sctp_new_association_req_p->remote_address,
          mme_ip_address,
          sizeof(*mme_ip_address));
-
   memcpy(&sctp_new_association_req_p->local_address,
          local_ip_addr,
          sizeof(*local_ip_addr));
-
   S1AP_INFO("[eNB %d] check the mme registration state\n",instance_p->instance);
-
   mme = NULL;
 
   if ( mme == NULL ) {
-
     /* Create new MME descriptor */
     s1ap_mme_data_p = calloc(1, sizeof(*s1ap_mme_data_p));
     DevAssert(s1ap_mme_data_p != NULL);
-
     s1ap_mme_data_p->cnx_id                = s1ap_eNB_fetch_add_global_cnx_id();
     sctp_new_association_req_p->ulp_cnx_id = s1ap_mme_data_p->cnx_id;
-
     s1ap_mme_data_p->assoc_id          = -1;
     s1ap_mme_data_p->broadcast_plmn_num = broadcast_plmn_num;
+
     for (int i = 0; i < broadcast_plmn_num; ++i)
       s1ap_mme_data_p->broadcast_plmn_index[i] = broadcast_plmn_index[i];
-    s1ap_mme_data_p->s1ap_eNB_instance = instance_p;
 
+    s1ap_mme_data_p->s1ap_eNB_instance = instance_p;
     STAILQ_INIT(&s1ap_mme_data_p->served_gummei);
-
     /* Insert the new descriptor in list of known MME
      * but not yet associated.
      */
@@ -158,12 +140,10 @@ static void s1ap_eNB_register_mme(s1ap_eNB_instance_t *instance_p,
   } else if (mme->state == S1AP_ENB_STATE_WAITING) {
     instance_p->s1ap_mme_pending_nb ++;
     sctp_new_association_req_p->ulp_cnx_id = mme->cnx_id;
-
     S1AP_INFO("[eNB %d] MME already registered, retrive the data (state %d, cnx %d, mme_nb %d, mme_pending_nb %d)\n",
               instance_p->instance,
               mme->state, mme->cnx_id,
               instance_p->s1ap_mme_nb, instance_p->s1ap_mme_pending_nb);
-
     /*s1ap_mme_data_p->cnx_id                = mme->cnx_id;
     sctp_new_association_req_p->ulp_cnx_id = mme->cnx_id;
 
@@ -181,13 +161,10 @@ static void s1ap_eNB_register_mme(s1ap_eNB_instance_t *instance_p,
 }
 
 
-void s1ap_eNB_handle_register_eNB(instance_t instance, s1ap_register_enb_req_t *s1ap_register_eNB)
-{
+void s1ap_eNB_handle_register_eNB(instance_t instance, s1ap_register_enb_req_t *s1ap_register_eNB) {
   s1ap_eNB_instance_t *new_instance;
   uint8_t index;
-  
   DevAssert(s1ap_register_eNB != NULL);
-
   /* Look if the provided instance already exists */
   new_instance = s1ap_eNB_get_instance(instance);
 
@@ -197,38 +174,36 @@ void s1ap_eNB_handle_register_eNB(instance_t instance, s1ap_register_enb_req_t *
     DevCheck(new_instance->cell_type == s1ap_register_eNB->cell_type, new_instance->cell_type, s1ap_register_eNB->cell_type, 0);
     DevCheck(new_instance->num_plmn == s1ap_register_eNB->num_plmn, new_instance->num_plmn, s1ap_register_eNB->num_plmn, 0);
     DevCheck(new_instance->tac == s1ap_register_eNB->tac, new_instance->tac, s1ap_register_eNB->tac, 0);
-    for (int i = 0; i < new_instance->num_plmn; i++)
-    {
+
+    for (int i = 0; i < new_instance->num_plmn; i++) {
       DevCheck(new_instance->mcc[i] == s1ap_register_eNB->mcc[i], new_instance->mcc[i], s1ap_register_eNB->mcc[i], 0);
       DevCheck(new_instance->mnc[i] == s1ap_register_eNB->mnc[i], new_instance->mnc[i], s1ap_register_eNB->mnc[i], 0);
       DevCheck(new_instance->mnc_digit_length[i] == s1ap_register_eNB->mnc_digit_length[i], new_instance->mnc_digit_length[i], s1ap_register_eNB->mnc_digit_length[i], 0);
     }
+
     DevCheck(new_instance->default_drx == s1ap_register_eNB->default_drx, new_instance->default_drx, s1ap_register_eNB->default_drx, 0);
   } else {
     new_instance = calloc(1, sizeof(s1ap_eNB_instance_t));
     DevAssert(new_instance != NULL);
-
     RB_INIT(&new_instance->s1ap_ue_head);
     RB_INIT(&new_instance->s1ap_mme_head);
-
     /* Copy usefull parameters */
     new_instance->instance         = instance;
     new_instance->eNB_name         = s1ap_register_eNB->eNB_name;
     new_instance->eNB_id           = s1ap_register_eNB->eNB_id;
     new_instance->cell_type        = s1ap_register_eNB->cell_type;
     new_instance->tac              = s1ap_register_eNB->tac;
-    for (int i = 0; i < s1ap_register_eNB->num_plmn; i++)
-    {
+
+    for (int i = 0; i < s1ap_register_eNB->num_plmn; i++) {
       new_instance->mcc[i]              = s1ap_register_eNB->mcc[i];
       new_instance->mnc[i]              = s1ap_register_eNB->mnc[i];
       new_instance->mnc_digit_length[i] = s1ap_register_eNB->mnc_digit_length[i];
     }
+
     new_instance->num_plmn         = s1ap_register_eNB->num_plmn;
     new_instance->default_drx      = s1ap_register_eNB->default_drx;
-
     /* Add the new instance to the list of eNB (meaningfull in virtual mode) */
     s1ap_eNB_insert_new_instance(new_instance);
-
     S1AP_INFO("Registered new eNB[%d] and %s eNB id %u\n",
               instance,
               s1ap_register_eNB->cell_type == CELL_MACRO_ENB ? "macro" : "home",
@@ -250,16 +225,12 @@ void s1ap_eNB_handle_register_eNB(instance_t instance, s1ap_register_enb_req_t *
   }
 }
 
-void s1ap_eNB_handle_sctp_association_resp(instance_t instance, sctp_new_association_resp_t *sctp_new_association_resp)
-{
+void s1ap_eNB_handle_sctp_association_resp(instance_t instance, sctp_new_association_resp_t *sctp_new_association_resp) {
   s1ap_eNB_instance_t *instance_p;
   s1ap_eNB_mme_data_t *s1ap_mme_data_p;
-
   DevAssert(sctp_new_association_resp != NULL);
-
   instance_p = s1ap_eNB_get_instance(instance);
   DevAssert(instance_p != NULL);
-
   s1ap_mme_data_p = s1ap_eNB_get_MME(instance_p, -1,
                                      sctp_new_association_resp->ulp_cnx_id);
   DevAssert(s1ap_mme_data_p != NULL);
@@ -269,9 +240,7 @@ void s1ap_eNB_handle_sctp_association_resp(instance_t instance, sctp_new_associa
               sctp_new_association_resp->sctp_state,
               instance,
               sctp_new_association_resp->ulp_cnx_id);
-
     s1ap_handle_s1_setup_message(s1ap_mme_data_p, sctp_new_association_resp->sctp_state == SCTP_STATE_SHUTDOWN);
-
     return;
   }
 
@@ -279,20 +248,17 @@ void s1ap_eNB_handle_sctp_association_resp(instance_t instance, sctp_new_associa
   s1ap_mme_data_p->assoc_id    = sctp_new_association_resp->assoc_id;
   s1ap_mme_data_p->in_streams  = sctp_new_association_resp->in_streams;
   s1ap_mme_data_p->out_streams = sctp_new_association_resp->out_streams;
-
   /* Prepare new S1 Setup Request */
   s1ap_eNB_generate_s1_setup_request(instance_p, s1ap_mme_data_p);
 }
 
 static
-void s1ap_eNB_handle_sctp_data_ind(sctp_data_ind_t *sctp_data_ind)
-{
+void s1ap_eNB_handle_sctp_data_ind(sctp_data_ind_t *sctp_data_ind) {
   int result;
-
   DevAssert(sctp_data_ind != NULL);
 #if defined(TEST_S1C_MME)
   mme_test_s1_notify_sctp_data_ind(sctp_data_ind->assoc_id, sctp_data_ind->stream,
-          sctp_data_ind->buffer, sctp_data_ind->buffer_length);
+                                   sctp_data_ind->buffer, sctp_data_ind->buffer_length);
 #else
   s1ap_eNB_handle_message(sctp_data_ind->assoc_id, sctp_data_ind->stream,
                           sctp_data_ind->buffer, sctp_data_ind->buffer_length);
@@ -301,23 +267,19 @@ void s1ap_eNB_handle_sctp_data_ind(sctp_data_ind_t *sctp_data_ind)
   AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
 }
 
-void s1ap_eNB_init(void)
-{
+void s1ap_eNB_init(void) {
   S1AP_DEBUG("Starting S1AP layer\n");
-
   s1ap_eNB_prepare_internal_data();
-
   itti_mark_task_ready(TASK_S1AP);
   MSC_START_USE();
 }
 
-void *s1ap_eNB_process_itti_msg(void* notUsed)
-{
+void *s1ap_eNB_process_itti_msg(void *notUsed) {
   MessageDef *received_msg = NULL;
   int         result;
-    itti_receive_msg(TASK_S1AP, &received_msg);
+  itti_receive_msg(TASK_S1AP, &received_msg);
 
-    switch (ITTI_MSG_ID(received_msg)) {
+  switch (ITTI_MSG_ID(received_msg)) {
     case TERMINATE_MESSAGE:
       S1AP_WARN(" *** Exiting S1AP thread\n");
       itti_exit_task();
@@ -371,22 +333,28 @@ void *s1ap_eNB_process_itti_msg(void* notUsed)
 
     case S1AP_E_RAB_SETUP_RESP: {
       s1ap_eNB_e_rab_setup_resp(ITTI_MESSAGE_GET_INSTANCE(received_msg),
-				&S1AP_E_RAB_SETUP_RESP(received_msg));
+                                &S1AP_E_RAB_SETUP_RESP(received_msg));
     }
     break;
 
     case S1AP_E_RAB_MODIFY_RESP: {
       s1ap_eNB_e_rab_modify_resp(ITTI_MESSAGE_GET_INSTANCE(received_msg),
-        &S1AP_E_RAB_MODIFY_RESP(received_msg));
+                                 &S1AP_E_RAB_MODIFY_RESP(received_msg));
     }
     break;
-      
+
     case S1AP_NAS_NON_DELIVERY_IND: {
       s1ap_eNB_nas_non_delivery_ind(ITTI_MESSAGE_GET_INSTANCE(received_msg),
                                     &S1AP_NAS_NON_DELIVERY_IND(received_msg));
     }
     break;
 
+    case S1AP_PATH_SWITCH_REQ: {
+      s1ap_eNB_path_switch_req(ITTI_MESSAGE_GET_INSTANCE(received_msg),
+                               &S1AP_PATH_SWITCH_REQ(received_msg));
+    }
+    break;
+
     case S1AP_UE_CONTEXT_RELEASE_COMPLETE: {
       s1ap_ue_context_release_complete(ITTI_MESSAGE_GET_INSTANCE(received_msg),
                                        &S1AP_UE_CONTEXT_RELEASE_COMPLETE(received_msg));
@@ -396,11 +364,8 @@ void *s1ap_eNB_process_itti_msg(void* notUsed)
     case S1AP_UE_CONTEXT_RELEASE_REQ: {
       s1ap_eNB_instance_t               *s1ap_eNB_instance_p           = NULL; // test
       struct s1ap_eNB_ue_context_s      *ue_context_p                  = NULL; // test
-
       s1ap_ue_context_release_req(ITTI_MESSAGE_GET_INSTANCE(received_msg),
                                   &S1AP_UE_CONTEXT_RELEASE_REQ(received_msg));
-
-
       s1ap_eNB_instance_p = s1ap_eNB_get_instance(ITTI_MESSAGE_GET_INSTANCE(received_msg)); // test
       DevAssert(s1ap_eNB_instance_p != NULL); // test
 
@@ -413,9 +378,9 @@ void *s1ap_eNB_process_itti_msg(void* notUsed)
     }
     break;
 
-   case S1AP_E_RAB_RELEASE_RESPONSE: {
-        s1ap_eNB_e_rab_release_resp(ITTI_MESSAGE_GET_INSTANCE(received_msg),
-                                    &S1AP_E_RAB_RELEASE_RESPONSE(received_msg));
+    case S1AP_E_RAB_RELEASE_RESPONSE: {
+      s1ap_eNB_e_rab_release_resp(ITTI_MESSAGE_GET_INSTANCE(received_msg),
+                                  &S1AP_E_RAB_RELEASE_RESPONSE(received_msg));
     }
     break;
 
@@ -423,18 +388,16 @@ void *s1ap_eNB_process_itti_msg(void* notUsed)
       S1AP_ERROR("Received unhandled message: %d:%s\n",
                  ITTI_MSG_ID(received_msg), ITTI_MSG_NAME(received_msg));
       break;
-    }
-
-    result = itti_free (ITTI_MSG_ORIGIN_ID(received_msg), received_msg);
-    AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
+  }
 
-    received_msg = NULL;
-    return NULL;
+  result = itti_free (ITTI_MSG_ORIGIN_ID(received_msg), received_msg);
+  AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
+  received_msg = NULL;
+  return NULL;
 }
 
 
-void *s1ap_eNB_task(void *arg)
-{
+void *s1ap_eNB_task(void *arg) {
   s1ap_eNB_init();
 
   while (1) {
@@ -444,23 +407,26 @@ void *s1ap_eNB_task(void *arg)
   return NULL;
 }
 
+//-----------------------------------------------------------------------------
+/*
+* eNB generate a S1 setup request towards MME
+*/
 static int s1ap_eNB_generate_s1_setup_request(
-  s1ap_eNB_instance_t *instance_p, s1ap_eNB_mme_data_t *s1ap_mme_data_p)
+  s1ap_eNB_instance_t *instance_p,
+  s1ap_eNB_mme_data_t *s1ap_mme_data_p)
+//-----------------------------------------------------------------------------
 {
-  S1AP_S1AP_PDU_t                     pdu;
-  S1AP_S1SetupRequest_t              *out;
-  S1AP_S1SetupRequestIEs_t           *ie;
-  S1AP_SupportedTAs_Item_t           *ta;
-  S1AP_PLMNidentity_t                *plmn;
-  uint8_t  *buffer;
-  uint32_t  len;
+  S1AP_S1AP_PDU_t            pdu;
+  S1AP_S1SetupRequest_t     *out = NULL;
+  S1AP_S1SetupRequestIEs_t   *ie = NULL;
+  S1AP_SupportedTAs_Item_t   *ta = NULL;
+  S1AP_PLMNidentity_t      *plmn = NULL;
+  uint8_t  *buffer = NULL;
+  uint32_t  len = 0;
   int       ret = 0;
-
   DevAssert(instance_p != NULL);
   DevAssert(s1ap_mme_data_p != NULL);
-
   s1ap_mme_data_p->state = S1AP_ENB_STATE_WAITING;
-
   /* Prepare the S1AP message to encode */
   memset(&pdu, 0, sizeof(pdu));
   pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage;
@@ -468,7 +434,6 @@ static int s1ap_eNB_generate_s1_setup_request(
   pdu.choice.initiatingMessage.criticality = S1AP_Criticality_reject;
   pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_S1SetupRequest;
   out = &pdu.choice.initiatingMessage.value.choice.S1SetupRequest;
-
   /* mandatory */
   ie = (S1AP_S1SetupRequestIEs_t *)calloc(1, sizeof(S1AP_S1SetupRequestIEs_t));
   ie->id = S1AP_ProtocolIE_ID_id_Global_ENB_ID;
@@ -519,7 +484,6 @@ static int s1ap_eNB_generate_s1_setup_request(
     ASN_SEQUENCE_ADD(&ie->value.choice.SupportedTAs.list, ta);
   }
   ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
   /* mandatory */
   ie = (S1AP_S1SetupRequestIEs_t *)calloc(1, sizeof(S1AP_S1SetupRequestIEs_t));
   ie->id = S1AP_ProtocolIE_ID_id_DefaultPagingDRX;
@@ -540,6 +504,7 @@ static int s1ap_eNB_generate_s1_setup_request(
 
   /* optional */
 #if (S1AP_VERSION >= MAKE_VERSION(13, 0, 0))
+
   if (0) {
     ie = (S1AP_S1SetupRequestIEs_t *)calloc(1, sizeof(S1AP_S1SetupRequestIEs_t));
     ie->id = S1AP_ProtocolIE_ID_id_UE_RetentionInformation;
@@ -558,6 +523,7 @@ static int s1ap_eNB_generate_s1_setup_request(
     // ie->value.choice.NB_IoT_DefaultPagingDRX = ;
     ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
   }
+
 #endif /* #if (S1AP_VERSION >= MAKE_VERSION(14, 0, 0)) */
 
   if (s1ap_eNB_encode_pdu(&pdu, &buffer, &len) < 0) {
@@ -567,6 +533,5 @@ static int s1ap_eNB_generate_s1_setup_request(
 
   /* Non UE-Associated signalling -> stream = 0 */
   s1ap_eNB_itti_send_sctp_data_req(instance_p->instance, s1ap_mme_data_p->assoc_id, buffer, len, 0);
-
   return ret;
 }
diff --git a/openair3/S1AP/s1ap_eNB_decoder.c b/openair3/S1AP/s1ap_eNB_decoder.c
index c12374f7586397c832725dab601e09e027fb48e3..3eb182b159db73c3d981cd9078deebdf528f92e0 100644
--- a/openair3/S1AP/s1ap_eNB_decoder.c
+++ b/openair3/S1AP/s1ap_eNB_decoder.c
@@ -36,103 +36,52 @@
 #include "s1ap_common.h"
 #include "s1ap_eNB_decoder.h"
 
-static int s1ap_eNB_decode_initiating_message(S1AP_S1AP_PDU_t *pdu)
-{
-  MessageDef *message_p;
-  MessagesIds message_id;
+static int s1ap_eNB_decode_initiating_message(S1AP_S1AP_PDU_t *pdu) {
   asn_encode_to_new_buffer_result_t res = { NULL, {0, NULL, NULL} };
   DevAssert(pdu != NULL);
 
   switch(pdu->choice.initiatingMessage.procedureCode) {
     case S1AP_ProcedureCode_id_downlinkNASTransport:
       res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
-      message_id = S1AP_DOWNLINK_NAS_LOG;
-      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id,
-                  res.result.encoded + sizeof (IttiMsgText));
-      message_p->ittiMsg.s1ap_downlink_nas_log.size = res.result.encoded;
-      memcpy(&message_p->ittiMsg.s1ap_downlink_nas_log.text, res.buffer, res.result.encoded);
-      itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
       free(res.buffer);
       break;
 
     case S1AP_ProcedureCode_id_InitialContextSetup:
       res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
-      message_id = S1AP_INITIAL_CONTEXT_SETUP_LOG;
-      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id,
-                  res.result.encoded + sizeof (IttiMsgText));
-      message_p->ittiMsg.s1ap_initial_context_setup_log.size = res.result.encoded;
-      memcpy(&message_p->ittiMsg.s1ap_initial_context_setup_log.text, res.buffer, res.result.encoded);
-      itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
       free(res.buffer);
       break;
 
     case S1AP_ProcedureCode_id_UEContextRelease:
       res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
-      message_id = S1AP_UE_CONTEXT_RELEASE_COMMAND_LOG;
-      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id,
-                  res.result.encoded + sizeof (IttiMsgText));
-      message_p->ittiMsg.s1ap_ue_context_release_command_log.size = res.result.encoded;
-      memcpy(&message_p->ittiMsg.s1ap_ue_context_release_command_log.text, res.buffer, res.result.encoded);
-      itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
       free(res.buffer);
       break;
 
     case S1AP_ProcedureCode_id_Paging:
       res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
-      message_id = S1AP_PAGING_LOG;
-      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id,
-                  res.result.encoded + sizeof (IttiMsgText));
-      message_p->ittiMsg.s1ap_paging_log.size = res.result.encoded;
-      memcpy(&message_p->ittiMsg.s1ap_paging_log.text, res.buffer, res.result.encoded);
-      itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
       S1AP_INFO("Paging initiating message\n");
       free(res.buffer);
       break;
 
     case S1AP_ProcedureCode_id_E_RABSetup:
       res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
-      message_id = S1AP_E_RAB_SETUP_REQUEST_LOG;
-      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id,
-                  res.result.encoded + sizeof (IttiMsgText));
-      message_p->ittiMsg.s1ap_e_rab_setup_request_log.size = res.result.encoded;
-      memcpy(&message_p->ittiMsg.s1ap_e_rab_setup_request_log.text, res.buffer, res.result.encoded);
-      itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
       free(res.buffer);
       S1AP_INFO("E_RABSetup initiating message\n");
       break;
 
     case S1AP_ProcedureCode_id_E_RABModify:
       res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
-      message_id = S1AP_E_RAB_MODIFY_REQUEST_LOG;
-      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id,
-                  res.result.encoded + sizeof (IttiMsgText));
-      message_p->ittiMsg.s1ap_e_rab_modify_request_log.size = res.result.encoded;
-      memcpy(&message_p->ittiMsg.s1ap_e_rab_modify_request_log.text, res.buffer, res.result.encoded);
-      itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
       free(res.buffer);
       S1AP_INFO("E_RABModify initiating message\n");
       break;
 
     case S1AP_ProcedureCode_id_E_RABRelease:
       res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
-      message_id = S1AP_E_RAB_RELEASE_REQUEST_LOG;
-      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id,
-                  res.result.encoded + sizeof (IttiMsgText));
-      message_p->ittiMsg.s1ap_e_rab_release_request_log.size = res.result.encoded;
-      memcpy(&message_p->ittiMsg.s1ap_e_rab_release_request_log.text, res.buffer, res.result.encoded);
-      itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
       free(res.buffer);
       S1AP_INFO("TODO E_RABRelease initiating message\n");
       break;
 
     case S1AP_ProcedureCode_id_ErrorIndication:
       res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
-      message_id = S1AP_ERROR_INDICATION_LOG;
-      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id,
-                  res.result.encoded + sizeof (IttiMsgText));
-      message_p->ittiMsg.s1ap_error_indication_log.size = res.result.encoded;
-      memcpy(&message_p->ittiMsg.s1ap_error_indication_log.text, res.buffer, res.result.encoded);
-      itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
       free(res.buffer);
       S1AP_INFO("TODO ErrorIndication initiating message\n");
       break;
@@ -148,21 +97,18 @@ static int s1ap_eNB_decode_initiating_message(S1AP_S1AP_PDU_t *pdu)
   return 0;
 }
 
-static int s1ap_eNB_decode_successful_outcome(S1AP_S1AP_PDU_t *pdu)
-{
-  MessageDef *message_p;
-  MessagesIds message_id;
+static int s1ap_eNB_decode_successful_outcome(S1AP_S1AP_PDU_t *pdu) {
   asn_encode_to_new_buffer_result_t res = { NULL, {0, NULL, NULL} };
   DevAssert(pdu != NULL);
 
   switch(pdu->choice.successfulOutcome.procedureCode) {
     case S1AP_ProcedureCode_id_S1Setup:
       res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
-      message_id = S1AP_S1_SETUP_LOG;
-      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id, res.result.encoded + sizeof (IttiMsgText));
-      message_p->ittiMsg.s1ap_s1_setup_log.size = res.result.encoded;
-      memcpy(&message_p->ittiMsg.s1ap_s1_setup_log.text, res.buffer, res.result.encoded);
-      itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
+      free(res.buffer);
+      break;
+
+    case S1AP_ProcedureCode_id_PathSwitchRequest:
+      res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
       free(res.buffer);
       break;
 
@@ -175,21 +121,17 @@ static int s1ap_eNB_decode_successful_outcome(S1AP_S1AP_PDU_t *pdu)
   return 0;
 }
 
-static int s1ap_eNB_decode_unsuccessful_outcome(S1AP_S1AP_PDU_t *pdu)
-{
-  MessageDef *message_p;
-  MessagesIds message_id;
+static int s1ap_eNB_decode_unsuccessful_outcome(S1AP_S1AP_PDU_t *pdu) {
   asn_encode_to_new_buffer_result_t res = { NULL, {0, NULL, NULL} };
   DevAssert(pdu != NULL);
 
   switch(pdu->choice.unsuccessfulOutcome.procedureCode) {
     case S1AP_ProcedureCode_id_S1Setup:
       res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
-      message_id = S1AP_S1_SETUP_LOG;
-      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id, res.result.encoded + sizeof (IttiMsgText));
-      message_p->ittiMsg.s1ap_s1_setup_log.size = res.result.encoded;
-      memcpy(&message_p->ittiMsg.s1ap_s1_setup_log.text, res.buffer, res.result.encoded);
-      itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
+      free(res.buffer);
+      break;
+   case S1AP_ProcedureCode_id_PathSwitchRequest:
+      res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
       free(res.buffer);
       break;
 
@@ -203,13 +145,10 @@ static int s1ap_eNB_decode_unsuccessful_outcome(S1AP_S1AP_PDU_t *pdu)
 }
 
 int s1ap_eNB_decode_pdu(S1AP_S1AP_PDU_t *pdu, const uint8_t *const buffer,
-                        const uint32_t length)
-{
+                        const uint32_t length) {
   asn_dec_rval_t dec_ret;
-
   DevAssert(pdu != NULL);
   DevAssert(buffer != NULL);
-
   dec_ret = aper_decode(NULL,
                         &asn_DEF_S1AP_S1AP_PDU,
                         (void **)&pdu,
diff --git a/openair3/S1AP/s1ap_eNB_encoder.c b/openair3/S1AP/s1ap_eNB_encoder.c
index 39deb4999a7c3edacd7786dd21aa5d08e31e1cbd..0cd46214fc050997b06144af12deb77e4a2d3c39 100644
--- a/openair3/S1AP/s1ap_eNB_encoder.c
+++ b/openair3/S1AP/s1ap_eNB_encoder.c
@@ -47,8 +47,7 @@ static inline int s1ap_eNB_encode_successfull_outcome(S1AP_S1AP_PDU_t *pdu,
 static inline int s1ap_eNB_encode_unsuccessfull_outcome(S1AP_S1AP_PDU_t *pdu,
     uint8_t **buffer, uint32_t *len);
 
-int s1ap_eNB_encode_pdu(S1AP_S1AP_PDU_t *pdu, uint8_t **buffer, uint32_t *len)
-{
+int s1ap_eNB_encode_pdu(S1AP_S1AP_PDU_t *pdu, uint8_t **buffer, uint32_t *len) {
   int ret = -1;
   DevAssert(pdu != NULL);
   DevAssert(buffer != NULL);
@@ -79,71 +78,43 @@ int s1ap_eNB_encode_pdu(S1AP_S1AP_PDU_t *pdu, uint8_t **buffer, uint32_t *len)
 
 static inline
 int s1ap_eNB_encode_initiating(S1AP_S1AP_PDU_t *pdu,
-                               uint8_t **buffer, uint32_t *len)
-{
-  MessageDef *message_p;
-  MessagesIds message_id;
+                               uint8_t **buffer, uint32_t *len) {
   asn_encode_to_new_buffer_result_t res = { NULL, {0, NULL, NULL} };
   DevAssert(pdu != NULL);
 
   switch(pdu->choice.initiatingMessage.procedureCode) {
     case S1AP_ProcedureCode_id_S1Setup:
       res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
-      message_id = S1AP_S1_SETUP_LOG;
-      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id, res.result.encoded + sizeof (IttiMsgText));
-      message_p->ittiMsg.s1ap_s1_setup_log.size = res.result.encoded;
-      memcpy(&message_p->ittiMsg.s1ap_s1_setup_log.text, res.buffer, res.result.encoded);
-      itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
       free(res.buffer);
       break;
 
     case S1AP_ProcedureCode_id_uplinkNASTransport:
       res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
-      message_id = S1AP_UPLINK_NAS_LOG;
-      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id, res.result.encoded + sizeof (IttiMsgText));
-      message_p->ittiMsg.s1ap_uplink_nas_log.size = res.result.encoded;
-      memcpy(&message_p->ittiMsg.s1ap_uplink_nas_log.text, res.buffer, res.result.encoded);
-      itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
       free(res.buffer);
       break;
 
     case S1AP_ProcedureCode_id_UECapabilityInfoIndication:
       res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
-      message_id = S1AP_UE_CAPABILITY_IND_LOG;
-      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id, res.result.encoded + sizeof (IttiMsgText));
-      message_p->ittiMsg.s1ap_ue_capability_ind_log.size = res.result.encoded;
-      memcpy(&message_p->ittiMsg.s1ap_ue_capability_ind_log.text, res.buffer, res.result.encoded);
-      itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
       free(res.buffer);
       break;
 
     case S1AP_ProcedureCode_id_initialUEMessage:
       res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
-      message_id = S1AP_INITIAL_UE_MESSAGE_LOG;
-      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id, res.result.encoded + sizeof (IttiMsgText));
-      message_p->ittiMsg.s1ap_initial_ue_message_log.size = res.result.encoded;
-      memcpy(&message_p->ittiMsg.s1ap_initial_ue_message_log.text, res.buffer, res.result.encoded);
-      itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
       free(res.buffer);
       break;
 
     case S1AP_ProcedureCode_id_NASNonDeliveryIndication:
       res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
-      message_id = S1AP_NAS_NON_DELIVERY_IND_LOG;
-      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id, res.result.encoded + sizeof (IttiMsgText));
-      message_p->ittiMsg.s1ap_nas_non_delivery_ind_log.size = res.result.encoded;
-      memcpy(&message_p->ittiMsg.s1ap_nas_non_delivery_ind_log.text, res.buffer, res.result.encoded);
-      itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
       free(res.buffer);
       break;
 
     case S1AP_ProcedureCode_id_UEContextReleaseRequest:
       res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
-      message_id = S1AP_UE_CONTEXT_RELEASE_REQ_LOG;
-      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id, res.result.encoded + sizeof (IttiMsgText));
-      message_p->ittiMsg.s1ap_ue_context_release_req_log.size = res.result.encoded;
-      memcpy(&message_p->ittiMsg.s1ap_ue_context_release_req_log.text, res.buffer, res.result.encoded);
-      itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
+      free(res.buffer);
+      break;
+
+    case S1AP_ProcedureCode_id_PathSwitchRequest:
+      res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
       free(res.buffer);
       break;
 
@@ -166,78 +137,37 @@ int s1ap_eNB_encode_initiating(S1AP_S1AP_PDU_t *pdu,
 
 static inline
 int s1ap_eNB_encode_successfull_outcome(S1AP_S1AP_PDU_t *pdu,
-                                        uint8_t **buffer, uint32_t *len)
-{
-  MessageDef *message_p;
-  MessagesIds message_id;
+                                        uint8_t **buffer, uint32_t *len) {
   asn_encode_to_new_buffer_result_t res = { NULL, {0, NULL, NULL} };
   DevAssert(pdu != NULL);
 
   switch(pdu->choice.successfulOutcome.procedureCode) {
     case S1AP_ProcedureCode_id_InitialContextSetup:
       res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
-      if (res.result.encoded<=0) LOG_E(RRC,"S1AP_ProcedureCode_id_InitialContextSetup: res.result.encoded<=0\n");
-      else {
-        message_id = S1AP_INITIAL_CONTEXT_SETUP_LOG;
-        message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id, res.result.encoded + sizeof (IttiMsgText));
-        message_p->ittiMsg.s1ap_initial_context_setup_log.size = res.result.encoded;
-        memcpy(&message_p->ittiMsg.s1ap_initial_context_setup_log.text, res.buffer, res.result.encoded);
-        itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
-        free(res.buffer);
-      }
+      free(res.buffer);
       break;
 
     case S1AP_ProcedureCode_id_UEContextRelease:
       res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
-      if (res.result.encoded<=0) LOG_E(RRC,"S1AP_ProcedureCode_id_UEContextRelease: res.result.encoded<=0\n");
-      else {
-        message_id = S1AP_UE_CONTEXT_RELEASE_COMPLETE_LOG;
-        message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id, res.result.encoded + sizeof (IttiMsgText));
-        message_p->ittiMsg.s1ap_ue_context_release_complete_log.size = res.result.encoded;
-        memcpy(&message_p->ittiMsg.s1ap_ue_context_release_complete_log.text, res.buffer, res.result.encoded);
-        itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
-        free(res.buffer);
-      }
+      free(res.buffer);
       break;
 
     case S1AP_ProcedureCode_id_E_RABSetup:
       res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
-      AssertFatal(res.result.encoded>0,"res.result.encoded<=0\n");
-      message_id = S1AP_E_RAB_SETUP_RESPONSE_LOG;
-      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id, res.result.encoded + sizeof (IttiMsgText));
-      message_p->ittiMsg.s1ap_e_rab_setup_response_log.size = res.result.encoded;
-      memcpy(&message_p->ittiMsg.s1ap_e_rab_setup_response_log.text, res.buffer, res.result.encoded);
-      itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
       free(res.buffer);
       S1AP_INFO("E_RABSetup successful message\n");
       break;
 
     case S1AP_ProcedureCode_id_E_RABModify:
       res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
-      if (res.result.encoded<=0) LOG_E(RRC,"S1AP_ProcedureCode_id_E_RABModify: res.result.encoded<=0\n");
-      else {
-        message_id = S1AP_E_RAB_MODIFY_RESPONSE_LOG;
-        message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id, res.result.encoded + sizeof (IttiMsgText));
-        message_p->ittiMsg.s1ap_e_rab_modify_response_log.size = res.result.encoded;
-        memcpy(&message_p->ittiMsg.s1ap_e_rab_modify_response_log.text, res.buffer, res.result.encoded);
-        itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
-        free(res.buffer);
-        S1AP_INFO("E_RABModify successful message\n");
-      }
+      free(res.buffer);
+      S1AP_INFO("E_RABModify successful message\n");
       break;
 
     case S1AP_ProcedureCode_id_E_RABRelease:
       res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
-      if (res.result.encoded<=0) LOG_E(RRC,"S1AP_ProcedureCode_id_E_RABRelease: res.result.encoded<=0\n");
-      else {
-        message_id = S1AP_E_RAB_RELEASE_RESPONSE_LOG;
-        message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id, res.result.encoded + sizeof (IttiMsgText));
-        message_p->ittiMsg.s1ap_e_rab_release_response_log.size = res.result.encoded;
-        memcpy(&message_p->ittiMsg.s1ap_e_rab_release_response_log.text, res.buffer, res.result.encoded);
-        itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
-        free(res.buffer);
-        S1AP_INFO("E_RAB Release successful message\n");
-      }
+      free(res.buffer);
+      S1AP_INFO("E_RAB Release successful message\n");
       break;
 
     default:
@@ -259,21 +189,13 @@ int s1ap_eNB_encode_successfull_outcome(S1AP_S1AP_PDU_t *pdu,
 
 static inline
 int s1ap_eNB_encode_unsuccessfull_outcome(S1AP_S1AP_PDU_t *pdu,
-    uint8_t **buffer, uint32_t *len)
-{
-  MessageDef *message_p;
-  MessagesIds message_id;
+    uint8_t **buffer, uint32_t *len) {
   asn_encode_to_new_buffer_result_t res = { NULL, {0, NULL, NULL} };
   DevAssert(pdu != NULL);
 
   switch(pdu->choice.unsuccessfulOutcome.procedureCode) {
     case S1AP_ProcedureCode_id_InitialContextSetup:
       res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
-      message_id = S1AP_INITIAL_CONTEXT_SETUP_LOG;
-      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id, res.result.encoded + sizeof (IttiMsgText));
-      message_p->ittiMsg.s1ap_initial_context_setup_log.size = res.result.encoded;
-      memcpy(&message_p->ittiMsg.s1ap_initial_context_setup_log.text, res.buffer, res.result.encoded);
-      itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
       free(res.buffer);
       break;
 
diff --git a/openair3/S1AP/s1ap_eNB_handlers.c b/openair3/S1AP/s1ap_eNB_handlers.c
index 5c6b208b87336111216ec516b78448b47971aa94..98bdbeb54db898d154703c102d668975d2bb2c62 100644
--- a/openair3/S1AP/s1ap_eNB_handlers.c
+++ b/openair3/S1AP/s1ap_eNB_handlers.c
@@ -66,13 +66,13 @@ int s1ap_eNB_handle_error_indication(uint32_t               assoc_id,
 
 static
 int s1ap_eNB_handle_initial_context_request(uint32_t               assoc_id,
-                                            uint32_t               stream,
-                                            S1AP_S1AP_PDU_t       *pdu);
+    uint32_t               stream,
+    S1AP_S1AP_PDU_t       *pdu);
 
 static
 int s1ap_eNB_handle_ue_context_release_command(uint32_t               assoc_id,
-                                               uint32_t               stream,
-                                               S1AP_S1AP_PDU_t       *pdu);
+    uint32_t               stream,
+    S1AP_S1AP_PDU_t       *pdu);
 
 static
 int s1ap_eNB_handle_e_rab_setup_request(uint32_t               assoc_id,
@@ -86,20 +86,30 @@ int s1ap_eNB_handle_paging(uint32_t               assoc_id,
 
 static
 int s1ap_eNB_handle_e_rab_modify_request(uint32_t               assoc_id,
-                                         uint32_t               stream,
-                                         S1AP_S1AP_PDU_t       *pdu);
+    uint32_t               stream,
+    S1AP_S1AP_PDU_t       *pdu);
 
 static
 int s1ap_eNB_handle_e_rab_release_command(uint32_t               assoc_id,
-                                          uint32_t               stream,
-                                          S1AP_S1AP_PDU_t       *pdu);
+    uint32_t               stream,
+    S1AP_S1AP_PDU_t       *pdu);
+
+static
+int s1ap_eNB_handle_s1_path_switch_request_ack(uint32_t               assoc_id,
+    uint32_t               stream,
+    S1AP_S1AP_PDU_t       *pdu);
+
+static
+int s1ap_eNB_handle_s1_path_switch_request_failure(uint32_t               assoc_id,
+    uint32_t               stream,
+    S1AP_S1AP_PDU_t       *pdu);
 
 /* Handlers matrix. Only eNB related procedure present here */
 s1ap_message_decoded_callback messages_callback[][3] = {
   { 0, 0, 0 }, /* HandoverPreparation */
   { 0, 0, 0 }, /* HandoverResourceAllocation */
   { 0, 0, 0 }, /* HandoverNotification */
-  { 0, 0, 0 }, /* PathSwitchRequest */
+  { 0, s1ap_eNB_handle_s1_path_switch_request_ack, s1ap_eNB_handle_s1_path_switch_request_failure }, /* PathSwitchRequest */
   { 0, 0, 0 }, /* HandoverCancel */
   { s1ap_eNB_handle_e_rab_setup_request, 0, 0 }, /* E_RABSetup */
   { s1ap_eNB_handle_e_rab_modify_request, 0, 0 }, /* E_RABModify */
@@ -148,16 +158,15 @@ s1ap_message_decoded_callback messages_callback[][3] = {
 #endif /* #if (S1AP_VERSION >= MAKE_VERSION(9, 0, 0)) */
 };
 char *s1ap_direction2String(int s1ap_dir) {
-static char *s1ap_direction_String[] = {
-  "", /* Nothing */
-  "Originating message", /* originating message */
-  "Successfull outcome", /* successfull outcome */
-  "UnSuccessfull outcome", /* successfull outcome */
-};
-return(s1ap_direction_String[s1ap_dir]);
+  static char *s1ap_direction_String[] = {
+    "", /* Nothing */
+    "Originating message", /* originating message */
+    "Successfull outcome", /* successfull outcome */
+    "UnSuccessfull outcome", /* successfull outcome */
+  };
+  return(s1ap_direction_String[s1ap_dir]);
 }
-void s1ap_handle_s1_setup_message(s1ap_eNB_mme_data_t *mme_desc_p, int sctp_shutdown)
-{
+void s1ap_handle_s1_setup_message(s1ap_eNB_mme_data_t *mme_desc_p, int sctp_shutdown) {
   if (sctp_shutdown) {
     /* A previously connected MME has been shutdown */
 
@@ -173,7 +182,6 @@ void s1ap_handle_s1_setup_message(s1ap_eNB_mme_data_t *mme_desc_p, int sctp_shut
       /* If there are no more associated MME, inform eNB app */
       if (mme_desc_p->s1ap_eNB_instance->s1ap_mme_associated_nb == 0) {
         MessageDef                 *message_p;
-
         message_p = itti_alloc_new_message(TASK_S1AP, S1AP_DEREGISTERED_ENB_IND);
         S1AP_DEREGISTERED_ENB_IND(message_p).nb_mme = 0;
         itti_send_msg_to_task(TASK_ENB_APP, mme_desc_p->s1ap_eNB_instance->instance, message_p);
@@ -192,7 +200,6 @@ void s1ap_handle_s1_setup_message(s1ap_eNB_mme_data_t *mme_desc_p, int sctp_shut
     /* If there are no more pending messages, inform eNB app */
     if (mme_desc_p->s1ap_eNB_instance->s1ap_mme_pending_nb == 0) {
       MessageDef                 *message_p;
-
       message_p = itti_alloc_new_message(TASK_S1AP, S1AP_REGISTER_ENB_CNF);
       S1AP_REGISTER_ENB_CNF(message_p).nb_mme = mme_desc_p->s1ap_eNB_instance->s1ap_mme_associated_nb;
       itti_send_msg_to_task(TASK_ENB_APP, mme_desc_p->s1ap_eNB_instance->instance, message_p);
@@ -201,13 +208,10 @@ void s1ap_handle_s1_setup_message(s1ap_eNB_mme_data_t *mme_desc_p, int sctp_shut
 }
 
 int s1ap_eNB_handle_message(uint32_t assoc_id, int32_t stream,
-                            const uint8_t *const data, const uint32_t data_length)
-{
+                            const uint8_t *const data, const uint32_t data_length) {
   S1AP_S1AP_PDU_t pdu;
   int ret;
-
   DevAssert(data != NULL);
-
   memset(&pdu, 0, sizeof(pdu));
 
   if (s1ap_eNB_decode_pdu(&pdu, data, data_length) < 0) {
@@ -246,14 +250,11 @@ int s1ap_eNB_handle_message(uint32_t assoc_id, int32_t stream,
 static
 int s1ap_eNB_handle_s1_setup_failure(uint32_t               assoc_id,
                                      uint32_t               stream,
-                                     S1AP_S1AP_PDU_t       *pdu)
-{
+                                     S1AP_S1AP_PDU_t       *pdu) {
   S1AP_S1SetupFailure_t      *container;
   S1AP_S1SetupFailureIEs_t   *ie;
   s1ap_eNB_mme_data_t        *mme_desc_p;
-
   DevAssert(pdu != NULL);
-
   container = &pdu->choice.unsuccessfulOutcome.value.choice.S1SetupFailure;
 
   /* S1 Setup Failure == Non UE-related procedure -> stream 0 */
@@ -269,33 +270,33 @@ int s1ap_eNB_handle_s1_setup_failure(uint32_t               assoc_id,
   }
 
   S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_S1SetupFailureIEs_t, ie, container,
-                             S1AP_ProtocolIE_ID_id_Cause, true);
+                             S1AP_ProtocolIE_ID_id_Cause,true);
 
-  if ((ie->value.choice.Cause.present == S1AP_Cause_PR_misc) &&
-      (ie->value.choice.Cause.choice.misc == S1AP_CauseMisc_unspecified)) {
-    S1AP_WARN("Received s1 setup failure for MME... MME is not ready\n");
+  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
+    if ((ie->value.choice.Cause.present == S1AP_Cause_PR_misc) &&
+        (ie->value.choice.Cause.choice.misc == S1AP_CauseMisc_unspecified)) {
+      S1AP_WARN("Received s1 setup failure for MME... MME is not ready\n");
+    } else {
+      S1AP_ERROR("Received s1 setup failure for MME... please check your parameters\n");
+    }
   } else {
-    S1AP_ERROR("Received s1 setup failure for MME... please check your parameters\n");
+    return -1;
   }
 
   mme_desc_p->state = S1AP_ENB_STATE_WAITING;
   s1ap_handle_s1_setup_message(mme_desc_p, 0);
-
   return 0;
 }
 
 static
 int s1ap_eNB_handle_s1_setup_response(uint32_t               assoc_id,
                                       uint32_t               stream,
-                                      S1AP_S1AP_PDU_t       *pdu)
-{
+                                      S1AP_S1AP_PDU_t       *pdu) {
   S1AP_S1SetupResponse_t    *container;
   S1AP_S1SetupResponseIEs_t *ie;
   s1ap_eNB_mme_data_t       *mme_desc_p;
   int i;
-
   DevAssert(pdu != NULL);
-
   container = &pdu->choice.successfulOutcome.value.choice.S1SetupResponse;
 
   /* S1 Setup Response == Non UE-related procedure -> stream 0 */
@@ -313,73 +314,77 @@ int s1ap_eNB_handle_s1_setup_response(uint32_t               assoc_id,
 
   S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_S1SetupResponseIEs_t, ie, container,
                              S1AP_ProtocolIE_ID_id_ServedGUMMEIs, true);
+
   /* The list of served gummei can contain at most 8 elements.
    * LTE related gummei is the first element in the list, i.e with an id of 0.
    */
-  S1AP_DEBUG("servedGUMMEIs.list.count %d\n", ie->value.choice.ServedGUMMEIs.list.count);
-  DevAssert(ie->value.choice.ServedGUMMEIs.list.count > 0);
-  DevAssert(ie->value.choice.ServedGUMMEIs.list.count <= S1AP_maxnoofRATs);
-
-  for (i = 0; i < ie->value.choice.ServedGUMMEIs.list.count; i++) {
-    S1AP_ServedGUMMEIsItem_t *gummei_item_p;
-    struct served_gummei_s   *new_gummei_p;
-    int j;
-
-    gummei_item_p = ie->value.choice.ServedGUMMEIs.list.array[i];
-    new_gummei_p = calloc(1, sizeof(struct served_gummei_s));
-
-    STAILQ_INIT(&new_gummei_p->served_plmns);
-    STAILQ_INIT(&new_gummei_p->served_group_ids);
-    STAILQ_INIT(&new_gummei_p->mme_codes);
-
-    S1AP_DEBUG("servedPLMNs.list.count %d\n", gummei_item_p->servedPLMNs.list.count);
-
-    for (j = 0; j < gummei_item_p->servedPLMNs.list.count; j++) {
-      S1AP_PLMNidentity_t *plmn_identity_p;
-      struct plmn_identity_s *new_plmn_identity_p;
-
-      plmn_identity_p = gummei_item_p->servedPLMNs.list.array[j];
-      new_plmn_identity_p = calloc(1, sizeof(struct plmn_identity_s));
-      TBCD_TO_MCC_MNC(plmn_identity_p, new_plmn_identity_p->mcc,
-                      new_plmn_identity_p->mnc, new_plmn_identity_p->mnc_digit_length);
-      STAILQ_INSERT_TAIL(&new_gummei_p->served_plmns, new_plmn_identity_p, next);
-      new_gummei_p->nb_served_plmns++;
-    }
-
-    for (j = 0; j < gummei_item_p->servedGroupIDs.list.count; j++) {
-      S1AP_MME_Group_ID_t           *mme_group_id_p;
-      struct served_group_id_s *new_group_id_p;
-
-      mme_group_id_p = gummei_item_p->servedGroupIDs.list.array[j];
-      new_group_id_p = calloc(1, sizeof(struct served_group_id_s));
-      OCTET_STRING_TO_INT16(mme_group_id_p, new_group_id_p->mme_group_id);
-      STAILQ_INSERT_TAIL(&new_gummei_p->served_group_ids, new_group_id_p, next);
-      new_gummei_p->nb_group_id++;
-    }
+  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
+    S1AP_DEBUG("servedGUMMEIs.list.count %d\n", ie->value.choice.ServedGUMMEIs.list.count);
+    DevAssert(ie->value.choice.ServedGUMMEIs.list.count > 0);
+    DevAssert(ie->value.choice.ServedGUMMEIs.list.count <= S1AP_maxnoofRATs);
+
+    for (i = 0; i < ie->value.choice.ServedGUMMEIs.list.count; i++) {
+      S1AP_ServedGUMMEIsItem_t *gummei_item_p;
+      struct served_gummei_s   *new_gummei_p;
+      int j;
+      gummei_item_p = ie->value.choice.ServedGUMMEIs.list.array[i];
+      new_gummei_p = calloc(1, sizeof(struct served_gummei_s));
+      STAILQ_INIT(&new_gummei_p->served_plmns);
+      STAILQ_INIT(&new_gummei_p->served_group_ids);
+      STAILQ_INIT(&new_gummei_p->mme_codes);
+      S1AP_DEBUG("servedPLMNs.list.count %d\n", gummei_item_p->servedPLMNs.list.count);
+
+      for (j = 0; j < gummei_item_p->servedPLMNs.list.count; j++) {
+        S1AP_PLMNidentity_t *plmn_identity_p;
+        struct plmn_identity_s *new_plmn_identity_p;
+        plmn_identity_p = gummei_item_p->servedPLMNs.list.array[j];
+        new_plmn_identity_p = calloc(1, sizeof(struct plmn_identity_s));
+        TBCD_TO_MCC_MNC(plmn_identity_p, new_plmn_identity_p->mcc,
+                        new_plmn_identity_p->mnc, new_plmn_identity_p->mnc_digit_length);
+        STAILQ_INSERT_TAIL(&new_gummei_p->served_plmns, new_plmn_identity_p, next);
+        new_gummei_p->nb_served_plmns++;
+      }
 
-    for (j = 0; j < gummei_item_p->servedMMECs.list.count; j++) {
-      S1AP_MME_Code_t        *mme_code_p;
-      struct mme_code_s *new_mme_code_p;
+      for (j = 0; j < gummei_item_p->servedGroupIDs.list.count; j++) {
+        S1AP_MME_Group_ID_t       *mme_group_id_p;
+        struct served_group_id_s *new_group_id_p;
+        mme_group_id_p = gummei_item_p->servedGroupIDs.list.array[j];
+        new_group_id_p = calloc(1, sizeof(struct served_group_id_s));
+        OCTET_STRING_TO_INT16(mme_group_id_p, new_group_id_p->mme_group_id);
+        STAILQ_INSERT_TAIL(&new_gummei_p->served_group_ids, new_group_id_p, next);
+        new_gummei_p->nb_group_id++;
+      }
 
-      mme_code_p = gummei_item_p->servedMMECs.list.array[j];
-      new_mme_code_p = calloc(1, sizeof(struct mme_code_s));
+      for (j = 0; j < gummei_item_p->servedMMECs.list.count; j++) {
+        S1AP_MME_Code_t        *mme_code_p;
+        struct mme_code_s *new_mme_code_p;
+        mme_code_p = gummei_item_p->servedMMECs.list.array[j];
+        new_mme_code_p = calloc(1, sizeof(struct mme_code_s));
+        OCTET_STRING_TO_INT8(mme_code_p, new_mme_code_p->mme_code);
+        STAILQ_INSERT_TAIL(&new_gummei_p->mme_codes, new_mme_code_p, next);
+        new_gummei_p->nb_mme_code++;
+      }
 
-      OCTET_STRING_TO_INT8(mme_code_p, new_mme_code_p->mme_code);
-      STAILQ_INSERT_TAIL(&new_gummei_p->mme_codes, new_mme_code_p, next);
-      new_gummei_p->nb_mme_code++;
+      STAILQ_INSERT_TAIL(&mme_desc_p->served_gummei, new_gummei_p, next);
     }
-
-    STAILQ_INSERT_TAIL(&mme_desc_p->served_gummei, new_gummei_p, next);
+  } else {
+    return -1;
   }
 
   /* Set the capacity of this MME */
   S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_S1SetupResponseIEs_t, ie, container,
                              S1AP_ProtocolIE_ID_id_RelativeMMECapacity, true);
-  mme_desc_p->relative_mme_capacity = ie->value.choice.RelativeMMECapacity;
+
+  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
+    mme_desc_p->relative_mme_capacity = ie->value.choice.RelativeMMECapacity;
+  } else {
+    return -1;
+  }
 
   /* Optionaly set the mme name */
   S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_S1SetupResponseIEs_t, ie, container,
                              S1AP_ProtocolIE_ID_id_MMEname, false);
+
   if (ie) {
     mme_desc_p->mme_name = calloc(ie->value.choice.MMEname.size + 1, sizeof(char));
     memcpy(mme_desc_p->mme_name, ie->value.choice.MMEname.buf,
@@ -394,7 +399,6 @@ int s1ap_eNB_handle_s1_setup_response(uint32_t               assoc_id,
   mme_desc_p->state = S1AP_ENB_STATE_CONNECTED;
   mme_desc_p->s1ap_eNB_instance->s1ap_mme_associated_nb ++;
   s1ap_handle_s1_setup_message(mme_desc_p, 0);
-
   return 0;
 }
 
@@ -402,14 +406,11 @@ int s1ap_eNB_handle_s1_setup_response(uint32_t               assoc_id,
 static
 int s1ap_eNB_handle_error_indication(uint32_t         assoc_id,
                                      uint32_t         stream,
-                                     S1AP_S1AP_PDU_t *pdu)
-{
+                                     S1AP_S1AP_PDU_t *pdu) {
   S1AP_ErrorIndication_t    *container;
   S1AP_ErrorIndicationIEs_t *ie;
   s1ap_eNB_mme_data_t        *mme_desc_p;
-
   DevAssert(pdu != NULL);
-
   container = &pdu->choice.initiatingMessage.value.choice.ErrorIndication;
 
   /* S1 Setup Failure == Non UE-related procedure -> stream 0 */
@@ -428,7 +429,7 @@ int s1ap_eNB_handle_error_indication(uint32_t         assoc_id,
                              S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID, false);
 
   /* optional */
-  if (!ie) {
+  if (ie != NULL) {
     S1AP_WARN("Received S1 Error indication MME UE S1AP ID 0x%lx\n", ie->value.choice.MME_UE_S1AP_ID);
   }
 
@@ -436,7 +437,7 @@ int s1ap_eNB_handle_error_indication(uint32_t         assoc_id,
                              S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, false);
 
   /* optional */
-  if (!ie) {
+  if (ie != NULL) {
     S1AP_WARN("Received S1 Error indication eNB UE S1AP ID 0x%lx\n", ie->value.choice.ENB_UE_S1AP_ID);
   }
 
@@ -455,118 +456,156 @@ int s1ap_eNB_handle_error_indication(uint32_t         assoc_id,
           case S1AP_CauseRadioNetwork_unspecified:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_unspecified\n");
             break;
+
           case S1AP_CauseRadioNetwork_tx2relocoverall_expiry:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_tx2relocoverall_expiry\n");
             break;
+
           case S1AP_CauseRadioNetwork_successful_handover:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_successful_handover\n");
             break;
+
           case S1AP_CauseRadioNetwork_release_due_to_eutran_generated_reason:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_release_due_to_eutran_generated_reason\n");
             break;
+
           case S1AP_CauseRadioNetwork_handover_cancelled:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_handover_cancelled\n");
             break;
+
           case S1AP_CauseRadioNetwork_partial_handover:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_partial_handover\n");
             break;
+
           case S1AP_CauseRadioNetwork_ho_failure_in_target_EPC_eNB_or_target_system:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_ho_failure_in_target_EPC_eNB_or_target_system\n");
             break;
+
           case S1AP_CauseRadioNetwork_ho_target_not_allowed:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_ho_target_not_allowed\n");
             break;
+
           case S1AP_CauseRadioNetwork_tS1relocoverall_expiry:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_tS1relocoverall_expiry\n");
             break;
+
           case S1AP_CauseRadioNetwork_tS1relocprep_expiry:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_tS1relocprep_expiry\n");
             break;
+
           case S1AP_CauseRadioNetwork_cell_not_available:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_cell_not_available\n");
             break;
+
           case S1AP_CauseRadioNetwork_unknown_targetID:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_unknown_targetID\n");
             break;
+
           case S1AP_CauseRadioNetwork_no_radio_resources_available_in_target_cell:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_no_radio_resources_available_in_target_cell\n");
             break;
+
           case S1AP_CauseRadioNetwork_unknown_mme_ue_s1ap_id:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_unknown_mme_ue_s1ap_id\n");
             break;
+
           case S1AP_CauseRadioNetwork_unknown_enb_ue_s1ap_id:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_unknown_enb_ue_s1ap_id\n");
             break;
+
           case S1AP_CauseRadioNetwork_unknown_pair_ue_s1ap_id:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_unknown_pair_ue_s1ap_id\n");
             break;
+
           case S1AP_CauseRadioNetwork_handover_desirable_for_radio_reason:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_handover_desirable_for_radio_reason\n");
             break;
+
           case S1AP_CauseRadioNetwork_time_critical_handover:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_time_critical_handover\n");
             break;
+
           case S1AP_CauseRadioNetwork_resource_optimisation_handover:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_resource_optimisation_handover\n");
             break;
+
           case S1AP_CauseRadioNetwork_reduce_load_in_serving_cell:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_reduce_load_in_serving_cell\n");
             break;
+
           case S1AP_CauseRadioNetwork_user_inactivity:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_user_inactivity\n");
             break;
+
           case S1AP_CauseRadioNetwork_radio_connection_with_ue_lost:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_radio_connection_with_ue_lost\n");
             break;
+
           case S1AP_CauseRadioNetwork_load_balancing_tau_required:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_load_balancing_tau_required\n");
             break;
+
           case S1AP_CauseRadioNetwork_cs_fallback_triggered:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_cs_fallback_triggered\n");
             break;
+
           case S1AP_CauseRadioNetwork_ue_not_available_for_ps_service:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_ue_not_available_for_ps_service\n");
             break;
+
           case S1AP_CauseRadioNetwork_radio_resources_not_available:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_radio_resources_not_available\n");
             break;
+
           case S1AP_CauseRadioNetwork_failure_in_radio_interface_procedure:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_failure_in_radio_interface_procedure\n");
             break;
+
           case S1AP_CauseRadioNetwork_invalid_qos_combination:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_invals1ap_id_qos_combination\n");
             break;
+
           case S1AP_CauseRadioNetwork_interrat_redirection:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_interrat_redirection\n");
             break;
+
           case S1AP_CauseRadioNetwork_interaction_with_other_procedure:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_interaction_with_other_procedure\n");
             break;
+
           case S1AP_CauseRadioNetwork_unknown_E_RAB_ID:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_unknown_E_RAB_ID\n");
             break;
+
           case S1AP_CauseRadioNetwork_multiple_E_RAB_ID_instances:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_multiple_E_RAB_ID_instances\n");
             break;
+
           case S1AP_CauseRadioNetwork_encryption_and_or_integrity_protection_algorithms_not_supported:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_encryption_and_or_integrity_protection_algorithms_not_supported\n");
             break;
+
           case S1AP_CauseRadioNetwork_s1_intra_system_handover_triggered:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_s1_intra_system_handover_triggered\n");
             break;
+
           case S1AP_CauseRadioNetwork_s1_inter_system_handover_triggered:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_s1_inter_system_handover_triggered\n");
             break;
+
           case S1AP_CauseRadioNetwork_x2_handover_triggered:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_x2_handover_triggered\n");
             break;
+
           case S1AP_CauseRadioNetwork_redirection_towards_1xRTT:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_redirection_towards_1xRTT\n");
             break;
+
           case S1AP_CauseRadioNetwork_not_supported_QCI_value:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_not_supported_QCI_value\n");
             break;
 #if (S1AP_VERSION >= MAKE_VERSION(9, 0, 0))
+
           case S1AP_CauseRadioNetwork_invalid_CSG_Id:
             S1AP_WARN("Received S1 Error indication S1AP_CauseRadioNetwork_invals1ap_id_CSG_Id\n");
             break;
@@ -575,6 +614,7 @@ int s1ap_eNB_handle_error_indication(uint32_t         assoc_id,
           default:
             S1AP_WARN("Received S1 Error indication cause radio network case not handled\n");
         }
+
         break;
 
       case S1AP_Cause_PR_transport:
@@ -582,12 +622,15 @@ int s1ap_eNB_handle_error_indication(uint32_t         assoc_id,
           case S1AP_CauseTransport_transport_resource_unavailable:
             S1AP_WARN("Received S1 Error indication S1AP_CauseTransport_transport_resource_unavailable\n");
             break;
+
           case S1AP_CauseTransport_unspecified:
             S1AP_WARN("Received S1 Error indication S1AP_CauseTransport_unspecified\n");
             break;
+
           default:
             S1AP_WARN("Received S1 Error indication cause transport case not handled\n");
         }
+
         break;
 
       case S1AP_Cause_PR_nas:
@@ -595,20 +638,25 @@ int s1ap_eNB_handle_error_indication(uint32_t         assoc_id,
           case S1AP_CauseNas_normal_release:
             S1AP_WARN("Received S1 Error indication S1AP_CauseNas_normal_release\n");
             break;
+
           case S1AP_CauseNas_authentication_failure:
             S1AP_WARN("Received S1 Error indication S1AP_CauseNas_authentication_failure\n");
             break;
+
           case S1AP_CauseNas_detach:
             S1AP_WARN("Received S1 Error indication S1AP_CauseNas_detach\n");
             break;
+
           case S1AP_CauseNas_unspecified:
             S1AP_WARN("Received S1 Error indication S1AP_CauseNas_unspecified\n");
             break;
 #if (S1AP_VERSION >= MAKE_VERSION(9, 0, 0))
+
           case S1AP_CauseNas_csg_subscription_expiry:
             S1AP_WARN("Received S1 Error indication S1AP_CauseNas_csg_subscription_expiry\n");
             break;
 #endif /* #if (S1AP_VERSION >= MAKE_VERSION(9, 0, 0)) */
+
           default:
             S1AP_WARN("Received S1 Error indication cause nas case not handled\n");
         }
@@ -620,27 +668,35 @@ int s1ap_eNB_handle_error_indication(uint32_t         assoc_id,
           case S1AP_CauseProtocol_transfer_syntax_error:
             S1AP_WARN("Received S1 Error indication S1AP_CauseProtocol_transfer_syntax_error\n");
             break;
+
           case S1AP_CauseProtocol_abstract_syntax_error_reject:
             S1AP_WARN("Received S1 Error indication S1AP_CauseProtocol_abstract_syntax_error_reject\n");
             break;
+
           case S1AP_CauseProtocol_abstract_syntax_error_ignore_and_notify:
             S1AP_WARN("Received S1 Error indication S1AP_CauseProtocol_abstract_syntax_error_ignore_and_notify\n");
             break;
+
           case S1AP_CauseProtocol_message_not_compatible_with_receiver_state:
             S1AP_WARN("Received S1 Error indication S1AP_CauseProtocol_message_not_compatible_with_receiver_state\n");
             break;
+
           case S1AP_CauseProtocol_semantic_error:
             S1AP_WARN("Received S1 Error indication S1AP_CauseProtocol_semantic_error\n");
             break;
+
           case S1AP_CauseProtocol_abstract_syntax_error_falsely_constructed_message:
             S1AP_WARN("Received S1 Error indication S1AP_CauseProtocol_abstract_syntax_error_falsely_constructed_message\n");
             break;
+
           case S1AP_CauseProtocol_unspecified:
             S1AP_WARN("Received S1 Error indication S1AP_CauseProtocol_unspecified\n");
             break;
+
           default:
             S1AP_WARN("Received S1 Error indication cause protocol case not handled\n");
         }
+
         break;
 
       case S1AP_Cause_PR_misc:
@@ -648,24 +704,31 @@ int s1ap_eNB_handle_error_indication(uint32_t         assoc_id,
           case S1AP_CauseMisc_control_processing_overload:
             S1AP_WARN("Received S1 Error indication S1AP_CauseMisc_control_processing_overload\n");
             break;
+
           case S1AP_CauseMisc_not_enough_user_plane_processing_resources:
             S1AP_WARN("Received S1 Error indication S1AP_CauseMisc_not_enough_user_plane_processing_resources\n");
             break;
+
           case S1AP_CauseMisc_hardware_failure:
             S1AP_WARN("Received S1 Error indication S1AP_CauseMisc_hardware_failure\n");
             break;
+
           case S1AP_CauseMisc_om_intervention:
             S1AP_WARN("Received S1 Error indication S1AP_CauseMisc_om_intervention\n");
             break;
+
           case S1AP_CauseMisc_unspecified:
             S1AP_WARN("Received S1 Error indication S1AP_CauseMisc_unspecified\n");
             break;
+
           case S1AP_CauseMisc_unknown_PLMN:
             S1AP_WARN("Received S1 Error indication S1AP_CauseMisc_unknown_PLMN\n");
             break;
+
           default:
             S1AP_WARN("Received S1 Error indication cause misc case not handled\n");
         }
+
         break;
     }
   }
@@ -676,8 +739,8 @@ int s1ap_eNB_handle_error_indication(uint32_t         assoc_id,
   if (ie) {
     // TODO continue
   }
-  // TODO continue
 
+  // TODO continue
   return 0;
 }
 
@@ -685,8 +748,7 @@ int s1ap_eNB_handle_error_indication(uint32_t         assoc_id,
 static
 int s1ap_eNB_handle_initial_context_request(uint32_t   assoc_id,
     uint32_t               stream,
-    S1AP_S1AP_PDU_t       *pdu)
-{
+    S1AP_S1AP_PDU_t       *pdu) {
   int i;
   s1ap_eNB_mme_data_t   *mme_desc_p       = NULL;
   s1ap_eNB_ue_context_t *ue_desc_p        = NULL;
@@ -695,9 +757,7 @@ int s1ap_eNB_handle_initial_context_request(uint32_t   assoc_id,
   S1AP_InitialContextSetupRequestIEs_t *ie;
   S1AP_ENB_UE_S1AP_ID_t    enb_ue_s1ap_id;
   S1AP_MME_UE_S1AP_ID_t    mme_ue_s1ap_id;
-
   DevAssert(pdu != NULL);
-
   container = &pdu->choice.initiatingMessage.value.choice.InitialContextSetupRequest;
 
   if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) {
@@ -709,18 +769,28 @@ int s1ap_eNB_handle_initial_context_request(uint32_t   assoc_id,
   /* id-MME-UE-S1AP-ID */
   S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_InitialContextSetupRequestIEs_t, ie, container,
                              S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID, true);
-  mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID;
+
+  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
+    mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID;
+  } else {
+    return -1;
+  }
 
   /* id-eNB-UE-S1AP-ID */
   S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_InitialContextSetupRequestIEs_t, ie, container,
                              S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, true);
-  enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID;
 
-  if ((ue_desc_p = s1ap_eNB_get_ue_context(mme_desc_p->s1ap_eNB_instance,
-                                           enb_ue_s1ap_id)) == NULL) {
-    S1AP_ERROR("[SCTP %d] Received initial context setup request for non "
-               "existing UE context 0x%06lx\n", assoc_id,
-               enb_ue_s1ap_id);
+  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
+    enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID;
+
+    if ((ue_desc_p = s1ap_eNB_get_ue_context(mme_desc_p->s1ap_eNB_instance,
+                     enb_ue_s1ap_id)) == NULL) {
+      S1AP_ERROR("[SCTP %d] Received initial context setup request for non "
+                 "existing UE context 0x%06lx\n", assoc_id,
+                 enb_ue_s1ap_id);
+      return -1;
+    }
+  } else {
     return -1;
   }
 
@@ -732,86 +802,95 @@ int s1ap_eNB_handle_initial_context_request(uint32_t   assoc_id,
   }
 
   ue_desc_p->rx_stream = stream;
-
   ue_desc_p->mme_ue_s1ap_id = mme_ue_s1ap_id;
-
   message_p        = itti_alloc_new_message(TASK_S1AP, S1AP_INITIAL_CONTEXT_SETUP_REQ);
-
   S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).ue_initial_id  = ue_desc_p->ue_initial_id;
   ue_desc_p->ue_initial_id = 0;
-
   S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).eNB_ue_s1ap_id = ue_desc_p->eNB_ue_s1ap_id;
-
+  S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).mme_ue_s1ap_id = ue_desc_p->mme_ue_s1ap_id;
   /* id-uEaggregateMaximumBitrate */
   S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_InitialContextSetupRequestIEs_t, ie, container,
                              S1AP_ProtocolIE_ID_id_uEaggregateMaximumBitrate, true);
-  asn_INTEGER2ulong(&(ie->value.choice.UEAggregateMaximumBitrate.uEaggregateMaximumBitRateUL),
-                    &(S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).ue_ambr.br_ul));
-  asn_INTEGER2ulong(&(ie->value.choice.UEAggregateMaximumBitrate.uEaggregateMaximumBitRateDL),
-                    &(S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).ue_ambr.br_dl));
 
-  /* id-E-RABToBeSetupListCtxtSUReq */
+  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
+    asn_INTEGER2ulong(&(ie->value.choice.UEAggregateMaximumBitrate.uEaggregateMaximumBitRateUL),
+                      &(S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).ue_ambr.br_ul));
+    asn_INTEGER2ulong(&(ie->value.choice.UEAggregateMaximumBitrate.uEaggregateMaximumBitRateDL),
+                      &(S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).ue_ambr.br_dl));
+    /* id-E-RABToBeSetupListCtxtSUReq */
+  } else {
+    return -1;
+  }
+
   S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_InitialContextSetupRequestIEs_t, ie, container,
                              S1AP_ProtocolIE_ID_id_E_RABToBeSetupListCtxtSUReq, true);
 
-  S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).nb_of_e_rabs =
-    ie->value.choice.E_RABToBeSetupListCtxtSUReq.list.count;
-
-  for (i = 0; i < ie->value.choice.E_RABToBeSetupListCtxtSUReq.list.count; i++) {
-    S1AP_E_RABToBeSetupItemCtxtSUReq_t *item_p;
-    item_p = &(((S1AP_E_RABToBeSetupItemCtxtSUReqIEs_t *)ie->value.choice.E_RABToBeSetupListCtxtSUReq.list.array[i])->value.choice.E_RABToBeSetupItemCtxtSUReq);
-    S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].e_rab_id = item_p->e_RAB_ID;
-
-    if (item_p->nAS_PDU != NULL) {
-      /* Only copy NAS pdu if present */
-      S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.length = item_p->nAS_PDU->size;
-
-      S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.buffer =
-        malloc(sizeof(uint8_t) * item_p->nAS_PDU->size);
-
-      memcpy(S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.buffer,
-             item_p->nAS_PDU->buf, item_p->nAS_PDU->size);
-      S1AP_DEBUG("Received NAS message with the E_RAB setup procedure\n");
-    } else {
-      S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.length = 0;
-      S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.buffer = NULL;
-    }
-
-    /* Set the transport layer address */
-    memcpy(S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].sgw_addr.buffer,
-           item_p->transportLayerAddress.buf, item_p->transportLayerAddress.size);
-    S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].sgw_addr.length =
-      item_p->transportLayerAddress.size * 8 - item_p->transportLayerAddress.bits_unused;
-
-    /* GTP tunnel endpoint ID */
-    OCTET_STRING_TO_INT32(&item_p->gTP_TEID, S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].gtp_teid);
-
-    /* Set the QOS informations */
-    S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].qos.qci = item_p->e_RABlevelQoSParameters.qCI;
+  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
+    S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).nb_of_e_rabs =
+      ie->value.choice.E_RABToBeSetupListCtxtSUReq.list.count;
+
+    for (i = 0; i < ie->value.choice.E_RABToBeSetupListCtxtSUReq.list.count; i++) {
+      S1AP_E_RABToBeSetupItemCtxtSUReq_t *item_p;
+      item_p = &(((S1AP_E_RABToBeSetupItemCtxtSUReqIEs_t *)ie->value.choice.E_RABToBeSetupListCtxtSUReq.list.array[i])->value.choice.E_RABToBeSetupItemCtxtSUReq);
+      S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].e_rab_id = item_p->e_RAB_ID;
+
+      if (item_p->nAS_PDU != NULL) {
+        /* Only copy NAS pdu if present */
+        S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.length = item_p->nAS_PDU->size;
+        S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.buffer =
+          malloc(sizeof(uint8_t) * item_p->nAS_PDU->size);
+        memcpy(S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.buffer,
+               item_p->nAS_PDU->buf, item_p->nAS_PDU->size);
+        S1AP_DEBUG("Received NAS message with the E_RAB setup procedure\n");
+      } else {
+        S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.length = 0;
+        S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.buffer = NULL;
+      }
 
-    S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].qos.allocation_retention_priority.priority_level =
-      item_p->e_RABlevelQoSParameters.allocationRetentionPriority.priorityLevel;
-    S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].qos.allocation_retention_priority.pre_emp_capability =
-      item_p->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionCapability;
-    S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].qos.allocation_retention_priority.pre_emp_vulnerability =
-      item_p->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionVulnerability;
+      /* Set the transport layer address */
+      memcpy(S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].sgw_addr.buffer,
+             item_p->transportLayerAddress.buf, item_p->transportLayerAddress.size);
+      S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].sgw_addr.length =
+        item_p->transportLayerAddress.size * 8 - item_p->transportLayerAddress.bits_unused;
+      /* GTP tunnel endpoint ID */
+      OCTET_STRING_TO_INT32(&item_p->gTP_TEID, S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].gtp_teid);
+      /* Set the QOS informations */
+      S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].qos.qci = item_p->e_RABlevelQoSParameters.qCI;
+      S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].qos.allocation_retention_priority.priority_level =
+        item_p->e_RABlevelQoSParameters.allocationRetentionPriority.priorityLevel;
+      S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].qos.allocation_retention_priority.pre_emp_capability =
+        item_p->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionCapability;
+      S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].qos.allocation_retention_priority.pre_emp_vulnerability =
+        item_p->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionVulnerability;
+    } /* for i... */
+  } else {/* ie != NULL */
+    return -1;
   }
 
   /* id-UESecurityCapabilities */
   S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_InitialContextSetupRequestIEs_t, ie, container,
                              S1AP_ProtocolIE_ID_id_UESecurityCapabilities, true);
-  S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).security_capabilities.encryption_algorithms =
-    BIT_STRING_to_uint16(&ie->value.choice.UESecurityCapabilities.encryptionAlgorithms);
-  S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).security_capabilities.integrity_algorithms =
-    BIT_STRING_to_uint16(&ie->value.choice.UESecurityCapabilities.integrityProtectionAlgorithms);
 
-  /* id-SecurityKey : Copy the security key */
+  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
+    S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).security_capabilities.encryption_algorithms =
+      BIT_STRING_to_uint16(&ie->value.choice.UESecurityCapabilities.encryptionAlgorithms);
+    S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).security_capabilities.integrity_algorithms =
+      BIT_STRING_to_uint16(&ie->value.choice.UESecurityCapabilities.integrityProtectionAlgorithms);
+    /* id-SecurityKey : Copy the security key */
+  } else {/* ie != NULL */
+    return -1;
+  }
+
   S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_InitialContextSetupRequestIEs_t, ie, container,
                              S1AP_ProtocolIE_ID_id_SecurityKey, true);
-  memcpy(&S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).security_key,
-         ie->value.choice.SecurityKey.buf, ie->value.choice.SecurityKey.size);
 
-  itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p);
+  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
+    memcpy(&S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).security_key,
+           ie->value.choice.SecurityKey.buf, ie->value.choice.SecurityKey.size);
+    itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p);
+  } else {/* ie != NULL */
+    return -1;
+  }
 
   return 0;
 }
@@ -820,8 +899,7 @@ int s1ap_eNB_handle_initial_context_request(uint32_t   assoc_id,
 static
 int s1ap_eNB_handle_ue_context_release_command(uint32_t   assoc_id,
     uint32_t               stream,
-    S1AP_S1AP_PDU_t       *pdu)
-{
+    S1AP_S1AP_PDU_t       *pdu) {
   s1ap_eNB_mme_data_t   *mme_desc_p       = NULL;
   s1ap_eNB_ue_context_t *ue_desc_p        = NULL;
   MessageDef            *message_p        = NULL;
@@ -829,9 +907,7 @@ int s1ap_eNB_handle_ue_context_release_command(uint32_t   assoc_id,
   S1AP_ENB_UE_S1AP_ID_t  enb_ue_s1ap_id;
   S1AP_UEContextReleaseCommand_t     *container;
   S1AP_UEContextReleaseCommand_IEs_t *ie;
-
   DevAssert(pdu != NULL);
-
   container = &pdu->choice.initiatingMessage.value.choice.UEContextReleaseCommand;
 
   if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) {
@@ -843,58 +919,61 @@ int s1ap_eNB_handle_ue_context_release_command(uint32_t   assoc_id,
   S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_UEContextReleaseCommand_IEs_t, ie, container,
                              S1AP_ProtocolIE_ID_id_UE_S1AP_IDs, true);
 
-  switch (ie->value.choice.UE_S1AP_IDs.present) {
-    case S1AP_UE_S1AP_IDs_PR_uE_S1AP_ID_pair:
-      enb_ue_s1ap_id = ie->value.choice.UE_S1AP_IDs.choice.uE_S1AP_ID_pair.eNB_UE_S1AP_ID;
-      mme_ue_s1ap_id = ie->value.choice.UE_S1AP_IDs.choice.uE_S1AP_ID_pair.mME_UE_S1AP_ID;
-
-      MSC_LOG_RX_MESSAGE(
-        MSC_S1AP_ENB,
-        MSC_S1AP_MME,
-        NULL,0,
-        "0 UEContextRelease/%s eNB_ue_s1ap_id "S1AP_UE_ID_FMT" mme_ue_s1ap_id "S1AP_UE_ID_FMT" len %u",
-        s1ap_direction2String(pdu->present - 1),
-        enb_ue_s1ap_id,
-        mme_ue_s1ap_id);
-
-      if ((ue_desc_p = s1ap_eNB_get_ue_context(mme_desc_p->s1ap_eNB_instance,
-                                               enb_ue_s1ap_id)) == NULL) {
-        S1AP_ERROR("[SCTP %d] Received UE context release command for non "
-                   "existing UE context 0x%06lx\n",
-                   assoc_id,
-                   enb_ue_s1ap_id);
-        /*MessageDef *msg_complete_p;
-        msg_complete_p = itti_alloc_new_message(TASK_RRC_ENB, S1AP_UE_CONTEXT_RELEASE_COMPLETE);
-        S1AP_UE_CONTEXT_RELEASE_COMPLETE(msg_complete_p).eNB_ue_s1ap_id = enb_ue_s1ap_id;
-        itti_send_msg_to_task(TASK_S1AP, ue_desc_p->eNB_instance->instance <=> 0, msg_complete_p);
-        */
-        return -1;
-      } else {
-        MSC_LOG_TX_MESSAGE(
+  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
+    switch (ie->value.choice.UE_S1AP_IDs.present) {
+      case S1AP_UE_S1AP_IDs_PR_uE_S1AP_ID_pair:
+        enb_ue_s1ap_id = ie->value.choice.UE_S1AP_IDs.choice.uE_S1AP_ID_pair.eNB_UE_S1AP_ID;
+        mme_ue_s1ap_id = ie->value.choice.UE_S1AP_IDs.choice.uE_S1AP_ID_pair.mME_UE_S1AP_ID;
+        MSC_LOG_RX_MESSAGE(
           MSC_S1AP_ENB,
-          MSC_RRC_ENB,
+          MSC_S1AP_MME,
           NULL,0,
-          "0 S1AP_UE_CONTEXT_RELEASE_COMMAND/%d eNB_ue_s1ap_id "S1AP_UE_ID_FMT" ",
-          enb_ue_s1ap_id);
-        message_p        = itti_alloc_new_message(TASK_S1AP, S1AP_UE_CONTEXT_RELEASE_COMMAND);
-        S1AP_UE_CONTEXT_RELEASE_COMMAND(message_p).eNB_ue_s1ap_id = enb_ue_s1ap_id;
-        itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p);
-        return 0;
-      }
+          "0 UEContextRelease/%s eNB_ue_s1ap_id "S1AP_UE_ID_FMT" mme_ue_s1ap_id "S1AP_UE_ID_FMT" len %u",
+          s1ap_direction2String(pdu->present - 1),
+          enb_ue_s1ap_id,
+          mme_ue_s1ap_id);
+
+        if ((ue_desc_p = s1ap_eNB_get_ue_context(mme_desc_p->s1ap_eNB_instance,
+                         enb_ue_s1ap_id)) == NULL) {
+          S1AP_ERROR("[SCTP %d] Received UE context release command for non "
+                     "existing UE context 0x%06lx\n",
+                     assoc_id,
+                     enb_ue_s1ap_id);
+          return -1;
+        } else {
+          MSC_LOG_TX_MESSAGE(
+            MSC_S1AP_ENB,
+            MSC_RRC_ENB,
+            NULL,0,
+            "0 S1AP_UE_CONTEXT_RELEASE_COMMAND/%d eNB_ue_s1ap_id "S1AP_UE_ID_FMT" ",
+            enb_ue_s1ap_id);
+          message_p    = itti_alloc_new_message(TASK_S1AP, S1AP_UE_CONTEXT_RELEASE_COMMAND);
+
+          if (ue_desc_p->mme_ue_s1ap_id == 0) { // case of Detach Request and switch off from RRC_IDLE mode
+            ue_desc_p->mme_ue_s1ap_id = mme_ue_s1ap_id;
+          }
+
+          S1AP_UE_CONTEXT_RELEASE_COMMAND(message_p).eNB_ue_s1ap_id = enb_ue_s1ap_id;
+          itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p);
+          return 0;
+        }
 
-      break;
+        break;
 
-    //#warning "TODO mapping mme_ue_s1ap_id  enb_ue_s1ap_id?"
+      //#warning "TODO mapping mme_ue_s1ap_id  enb_ue_s1ap_id?"
 
-    case S1AP_UE_S1AP_IDs_PR_mME_UE_S1AP_ID:
-      mme_ue_s1ap_id = ie->value.choice.UE_S1AP_IDs.choice.uE_S1AP_ID_pair.mME_UE_S1AP_ID;
-      S1AP_ERROR("TO DO mapping mme_ue_s1ap_id  enb_ue_s1ap_id");
-      (void)mme_ue_s1ap_id; /* TODO: remove - it's to remove gcc warning about unused var */
+      case S1AP_UE_S1AP_IDs_PR_mME_UE_S1AP_ID:
+        mme_ue_s1ap_id = ie->value.choice.UE_S1AP_IDs.choice.uE_S1AP_ID_pair.mME_UE_S1AP_ID;
+        S1AP_ERROR("TO DO mapping mme_ue_s1ap_id  enb_ue_s1ap_id");
+        (void)mme_ue_s1ap_id; /* TODO: remove - it's to remove gcc warning about unused var */
 
-    case S1AP_UE_S1AP_IDs_PR_NOTHING:
-    default:
-      S1AP_ERROR("S1AP_UE_CONTEXT_RELEASE_COMMAND not processed, missing info elements");
-      return -1;
+      case S1AP_UE_S1AP_IDs_PR_NOTHING:
+      default:
+        S1AP_ERROR("S1AP_UE_CONTEXT_RELEASE_COMMAND not processed, missing info elements");
+        return -1;
+    }
+  } else {
+    return -1;
   }
 
   S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_UEContextReleaseCommand_IEs_t, ie, container,
@@ -905,8 +984,7 @@ int s1ap_eNB_handle_ue_context_release_command(uint32_t   assoc_id,
 static
 int s1ap_eNB_handle_e_rab_setup_request(uint32_t         assoc_id,
                                         uint32_t         stream,
-                                        S1AP_S1AP_PDU_t *pdu)
-{
+                                        S1AP_S1AP_PDU_t *pdu) {
   int i;
   S1AP_MME_UE_S1AP_ID_t         mme_ue_s1ap_id;
   S1AP_ENB_UE_S1AP_ID_t         enb_ue_s1ap_id;
@@ -915,9 +993,7 @@ int s1ap_eNB_handle_e_rab_setup_request(uint32_t         assoc_id,
   MessageDef                   *message_p        = NULL;
   S1AP_E_RABSetupRequest_t     *container;
   S1AP_E_RABSetupRequestIEs_t  *ie;
-
   DevAssert(pdu != NULL);
-
   container = &pdu->choice.initiatingMessage.value.choice.E_RABSetupRequest;
 
   if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) {
@@ -929,15 +1005,25 @@ int s1ap_eNB_handle_e_rab_setup_request(uint32_t         assoc_id,
   /* id-MME-UE-S1AP-ID */
   S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABSetupRequestIEs_t, ie, container,
                              S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID, true);
-  mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID;
+
+  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
+    mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID;
+  } else {
+    return -1;
+  }
 
   /* id-eNB-UE-S1AP-ID */
   S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABSetupRequestIEs_t, ie, container,
                              S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, true);
-  enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID;
+
+  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
+    enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID;
+  } else {
+    return -1;
+  }
 
   if ((ue_desc_p = s1ap_eNB_get_ue_context(mme_desc_p->s1ap_eNB_instance,
-                                           enb_ue_s1ap_id)) == NULL) {
+                   enb_ue_s1ap_id)) == NULL) {
     S1AP_ERROR("[SCTP %d] Received initial context setup request for non "
                "existing UE context 0x%06lx\n", assoc_id,
                enb_ue_s1ap_id);
@@ -959,92 +1045,82 @@ int s1ap_eNB_handle_e_rab_setup_request(uint32_t         assoc_id,
   }
 
   message_p        = itti_alloc_new_message(TASK_S1AP, S1AP_E_RAB_SETUP_REQ);
-
   S1AP_E_RAB_SETUP_REQ(message_p).ue_initial_id  = ue_desc_p->ue_initial_id;
   S1AP_E_RAB_SETUP_REQ(message_p).mme_ue_s1ap_id  = mme_ue_s1ap_id;
   S1AP_E_RAB_SETUP_REQ(message_p).eNB_ue_s1ap_id  = enb_ue_s1ap_id;
-
   S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABSetupRequestIEs_t, ie, container,
                              S1AP_ProtocolIE_ID_id_E_RABToBeSetupListBearerSUReq, true);
-  S1AP_E_RAB_SETUP_REQ(message_p).nb_e_rabs_tosetup =
-    ie->value.choice.E_RABToBeSetupListBearerSUReq.list.count;
-
-  for (i = 0; i < ie->value.choice.E_RABToBeSetupListBearerSUReq.list.count; i++) {
-    S1AP_E_RABToBeSetupItemBearerSUReq_t *item_p;
-
-    item_p = &(((S1AP_E_RABToBeSetupItemBearerSUReqIEs_t *)ie->value.choice.E_RABToBeSetupListBearerSUReq.list.array[i])->value.choice.E_RABToBeSetupItemBearerSUReq);
-
-    S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].e_rab_id = item_p->e_RAB_ID;
-
-    // check for the NAS PDU
-    if (item_p->nAS_PDU.size > 0 ) {
-      S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.length = item_p->nAS_PDU.size;
-
-      S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.buffer = malloc(sizeof(uint8_t) * item_p->nAS_PDU.size);
-
-      memcpy(S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.buffer,
-             item_p->nAS_PDU.buf, item_p->nAS_PDU.size);
-      // S1AP_INFO("received a NAS PDU with size %d (%02x.%02x)\n",S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.length, item_p->nAS_PDU.buf[0], item_p->nAS_PDU.buf[1]);
-    } else {
-      S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.length = 0;
-      S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.buffer = NULL;
-
-      S1AP_WARN("NAS PDU is not provided, generate a E_RAB_SETUP Failure (TBD) back to MME \n");
-      // return -1;
-    }
-
-    /* Set the transport layer address */
-    memcpy(S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].sgw_addr.buffer,
-           item_p->transportLayerAddress.buf, item_p->transportLayerAddress.size);
-    S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].sgw_addr.length =
-      item_p->transportLayerAddress.size * 8 - item_p->transportLayerAddress.bits_unused;
-
-    /* S1AP_INFO("sgw addr %s  len: %d (size %d, index %d)\n",
-                 S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].sgw_addr.buffer,
-                 S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].sgw_addr.length,
-                 item_p->transportLayerAddress.size, i);
-    */
-    /* GTP tunnel endpoint ID */
-    OCTET_STRING_TO_INT32(&item_p->gTP_TEID, S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].gtp_teid);
 
-    /* Set the QOS informations */
-    S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].qos.qci = item_p->e_RABlevelQoSParameters.qCI;
+  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
+    S1AP_E_RAB_SETUP_REQ(message_p).nb_e_rabs_tosetup =
+      ie->value.choice.E_RABToBeSetupListBearerSUReq.list.count;
+
+    for (i = 0; i < ie->value.choice.E_RABToBeSetupListBearerSUReq.list.count; i++) {
+      S1AP_E_RABToBeSetupItemBearerSUReq_t *item_p;
+      item_p = &(((S1AP_E_RABToBeSetupItemBearerSUReqIEs_t *)ie->value.choice.E_RABToBeSetupListBearerSUReq.list.array[i])->value.choice.E_RABToBeSetupItemBearerSUReq);
+      S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].e_rab_id = item_p->e_RAB_ID;
+
+      // check for the NAS PDU
+      if (item_p->nAS_PDU.size > 0 ) {
+        S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.length = item_p->nAS_PDU.size;
+        S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.buffer = malloc(sizeof(uint8_t) * item_p->nAS_PDU.size);
+        memcpy(S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.buffer,
+               item_p->nAS_PDU.buf, item_p->nAS_PDU.size);
+        // S1AP_INFO("received a NAS PDU with size %d (%02x.%02x)\n",S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.length, item_p->nAS_PDU.buf[0], item_p->nAS_PDU.buf[1]);
+      } else {
+        S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.length = 0;
+        S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.buffer = NULL;
+        S1AP_WARN("NAS PDU is not provided, generate a E_RAB_SETUP Failure (TBD) back to MME \n");
+      }
 
-    S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].qos.allocation_retention_priority.priority_level =
-      item_p->e_RABlevelQoSParameters.allocationRetentionPriority.priorityLevel;
-    S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].qos.allocation_retention_priority.pre_emp_capability =
-      item_p->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionCapability;
-    S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].qos.allocation_retention_priority.pre_emp_vulnerability =
-      item_p->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionVulnerability;
+      /* Set the transport layer address */
+      memcpy(S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].sgw_addr.buffer,
+             item_p->transportLayerAddress.buf, item_p->transportLayerAddress.size);
+      S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].sgw_addr.length =
+        item_p->transportLayerAddress.size * 8 - item_p->transportLayerAddress.bits_unused;
+      /* S1AP_INFO("sgw addr %s  len: %d (size %d, index %d)\n",
+                   S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].sgw_addr.buffer,
+                   S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].sgw_addr.length,
+                   item_p->transportLayerAddress.size, i);
+      */
+      /* GTP tunnel endpoint ID */
+      OCTET_STRING_TO_INT32(&item_p->gTP_TEID, S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].gtp_teid);
+      /* Set the QOS informations */
+      S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].qos.qci = item_p->e_RABlevelQoSParameters.qCI;
+      S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].qos.allocation_retention_priority.priority_level =
+        item_p->e_RABlevelQoSParameters.allocationRetentionPriority.priorityLevel;
+      S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].qos.allocation_retention_priority.pre_emp_capability =
+        item_p->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionCapability;
+      S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].qos.allocation_retention_priority.pre_emp_vulnerability =
+        item_p->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionVulnerability;
+    } /* for i... */
+
+    itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p);
+  } else {
+    return -1;
   }
 
-  itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p);
-
   return 0;
 }
 
 static
 int s1ap_eNB_handle_paging(uint32_t               assoc_id,
                            uint32_t               stream,
-                           S1AP_S1AP_PDU_t       *pdu)
-{
+                           S1AP_S1AP_PDU_t       *pdu) {
   s1ap_eNB_mme_data_t   *mme_desc_p        = NULL;
   s1ap_eNB_instance_t   *s1ap_eNB_instance = NULL;
   MessageDef            *message_p         = NULL;
   S1AP_Paging_t         *container;
   S1AP_PagingIEs_t      *ie;
-
   DevAssert(pdu != NULL);
-
   container = &pdu->choice.initiatingMessage.value.choice.Paging;
-
   // received Paging Message from MME
   S1AP_DEBUG("[SCTP %d] Received Paging Message From MME\n",assoc_id);
 
   /* Paging procedure -> stream != 0 */
   if (stream == 0) {
     LOG_W(S1AP,"[SCTP %d] Received Paging procedure on stream (%d)\n",
-               assoc_id, stream);
+          assoc_id, stream);
     return -1;
   }
 
@@ -1055,6 +1131,7 @@ int s1ap_eNB_handle_paging(uint32_t               assoc_id,
   }
 
   s1ap_eNB_instance = mme_desc_p->s1ap_eNB_instance;
+
   if (s1ap_eNB_instance == NULL) {
     S1AP_ERROR("[SCTP %d] Received Paging for non existing MME context : s1ap_eNB_instance is NULL\n",
                assoc_id);
@@ -1062,60 +1139,67 @@ int s1ap_eNB_handle_paging(uint32_t               assoc_id,
   }
 
   message_p = itti_alloc_new_message(TASK_S1AP, S1AP_PAGING_IND);
-
   /* convert S1AP_PagingIEs_t to s1ap_paging_ind_t */
   /* id-UEIdentityIndexValue : convert UE Identity Index value */
   S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PagingIEs_t, ie, container,
                              S1AP_ProtocolIE_ID_id_UEIdentityIndexValue, true);
-  S1AP_PAGING_IND(message_p).ue_index_value  = BIT_STRING_to_uint32(&ie->value.choice.UEIdentityIndexValue);
-  S1AP_DEBUG("[SCTP %d] Received Paging ue_index_value (%d)\n",
-             assoc_id,(uint32_t)S1AP_PAGING_IND(message_p).ue_index_value);
 
-  S1AP_PAGING_IND(message_p).ue_paging_identity.choice.s_tmsi.mme_code = 0;
-  S1AP_PAGING_IND(message_p).ue_paging_identity.choice.s_tmsi.m_tmsi = 0;
+  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
+    S1AP_PAGING_IND(message_p).ue_index_value  = BIT_STRING_to_uint32(&ie->value.choice.UEIdentityIndexValue);
+    S1AP_DEBUG("[SCTP %d] Received Paging ue_index_value (%d)\n",
+               assoc_id,(uint32_t)S1AP_PAGING_IND(message_p).ue_index_value);
+    S1AP_PAGING_IND(message_p).ue_paging_identity.choice.s_tmsi.mme_code = 0;
+    S1AP_PAGING_IND(message_p).ue_paging_identity.choice.s_tmsi.m_tmsi = 0;
+  } else {
+    return -1;
+  }
 
   /* id-UEPagingID */
   S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PagingIEs_t, ie, container,
                              S1AP_ProtocolIE_ID_id_UEPagingID, true);
-  /* convert UE Paging Identity */
-  if (ie->value.choice.UEPagingID.present == S1AP_UEPagingID_PR_s_TMSI) {
-    S1AP_PAGING_IND(message_p).ue_paging_identity.presenceMask = UE_PAGING_IDENTITY_s_tmsi;
-    OCTET_STRING_TO_INT8(&ie->value.choice.UEPagingID.choice.s_TMSI.mMEC, S1AP_PAGING_IND(message_p).ue_paging_identity.choice.s_tmsi.mme_code);
-    OCTET_STRING_TO_INT32(&ie->value.choice.UEPagingID.choice.s_TMSI.m_TMSI, S1AP_PAGING_IND(message_p).ue_paging_identity.choice.s_tmsi.m_tmsi);
-  } else if (ie->value.choice.UEPagingID.present == S1AP_UEPagingID_PR_iMSI) {
-    S1AP_PAGING_IND(message_p).ue_paging_identity.presenceMask = UE_PAGING_IDENTITY_imsi;
-    S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.length = 0;
-
-    for (int i = 0; i < ie->value.choice.UEPagingID.choice.iMSI.size; i++) {
-      S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2*i] = (uint8_t)(ie->value.choice.UEPagingID.choice.iMSI.buf[i] & 0x0F );
-      S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.length++;
-      S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2*i+1] = (uint8_t)((ie->value.choice.UEPagingID.choice.iMSI.buf[i]>>4) & 0x0F);
-      LOG_D(S1AP,"paging : i %d %d imsi %d %d \n",2*i,2*i+1,S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2*i], S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2*i+1]);
-
-      if (S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2*i+1] == 0x0F) {
-        if(i != ie->value.choice.UEPagingID.choice.iMSI.size - 1) {
-          /* invalid paging_p->uePagingID.choise.iMSI.buffer */
-          S1AP_ERROR("[SCTP %d] Received Paging : uePagingID.choise.iMSI error(i %d 0x0F)\n", assoc_id,i);
-          return -1;
-        }
-      } else {
+
+  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
+    /* convert UE Paging Identity */
+    if (ie->value.choice.UEPagingID.present == S1AP_UEPagingID_PR_s_TMSI) {
+      S1AP_PAGING_IND(message_p).ue_paging_identity.presenceMask = UE_PAGING_IDENTITY_s_tmsi;
+      OCTET_STRING_TO_INT8(&ie->value.choice.UEPagingID.choice.s_TMSI.mMEC, S1AP_PAGING_IND(message_p).ue_paging_identity.choice.s_tmsi.mme_code);
+      OCTET_STRING_TO_INT32(&ie->value.choice.UEPagingID.choice.s_TMSI.m_TMSI, S1AP_PAGING_IND(message_p).ue_paging_identity.choice.s_tmsi.m_tmsi);
+    } else if (ie->value.choice.UEPagingID.present == S1AP_UEPagingID_PR_iMSI) {
+      S1AP_PAGING_IND(message_p).ue_paging_identity.presenceMask = UE_PAGING_IDENTITY_imsi;
+      S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.length = 0;
+
+      for (int i = 0; i < ie->value.choice.UEPagingID.choice.iMSI.size; i++) {
+        S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2*i] = (uint8_t)(ie->value.choice.UEPagingID.choice.iMSI.buf[i] & 0x0F );
         S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.length++;
-      }
-    }
+        S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2*i+1] = (uint8_t)((ie->value.choice.UEPagingID.choice.iMSI.buf[i]>>4) & 0x0F);
+        LOG_D(S1AP,"paging : i %d %d imsi %d %d \n",2*i,2*i+1,S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2*i], S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2*i+1]);
+
+        if (S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2*i+1] == 0x0F) {
+          if(i != ie->value.choice.UEPagingID.choice.iMSI.size - 1) {
+            /* invalid paging_p->uePagingID.choise.iMSI.buffer */
+            S1AP_ERROR("[SCTP %d] Received Paging : uePagingID.choise.iMSI error(i %d 0x0F)\n", assoc_id,i);
+            return -1;
+          }
+        } else {
+          S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.length++;
+        }
+      } /* for i... */
 
-    if (S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.length >= S1AP_IMSI_LENGTH) {
-      /* invalid paging_p->uePagingID.choise.iMSI.size */
-      S1AP_ERROR("[SCTP %d] Received Paging : uePagingID.choise.iMSI.size(%d) is over IMSI length(%d)\n", assoc_id, S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.length, S1AP_IMSI_LENGTH);
+      if (S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.length >= S1AP_IMSI_LENGTH) {
+        /* invalid paging_p->uePagingID.choise.iMSI.size */
+        S1AP_ERROR("[SCTP %d] Received Paging : uePagingID.choise.iMSI.size(%d) is over IMSI length(%d)\n", assoc_id, S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.length, S1AP_IMSI_LENGTH);
+        return -1;
+      }
+    } else { /* of if (ie->value.choice.UEPagingID.present == S1AP_UEPagingID_PR_iMSI) */
+      /* invalid paging_p->uePagingID.present */
+      S1AP_ERROR("[SCTP %d] Received Paging : uePagingID.present(%d) is unknown\n", assoc_id, ie->value.choice.UEPagingID.present);
       return -1;
     }
-  } else {
-    /* invalid paging_p->uePagingID.present */
-    S1AP_ERROR("[SCTP %d] Received Paging : uePagingID.present(%d) is unknown\n", assoc_id, ie->value.choice.UEPagingID.present);
+  } else { /* of ie != NULL */
     return -1;
   }
 
   S1AP_PAGING_IND(message_p).paging_drx = PAGING_DRX_256;
-
   /* id-pagingDRX */
   S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PagingIEs_t, ie, container,
                              S1AP_ProtocolIE_ID_id_pagingDRX, false);
@@ -1131,41 +1215,48 @@ int s1ap_eNB_handle_paging(uint32_t               assoc_id,
   S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PagingIEs_t, ie, container,
                              S1AP_ProtocolIE_ID_id_CNDomain, true);
 
-  /* id-CNDomain : convert cnDomain */
-  if (ie->value.choice.CNDomain == S1AP_CNDomain_ps) {
-    S1AP_PAGING_IND(message_p).cn_domain = CN_DOMAIN_PS;
-  } else if (ie->value.choice.CNDomain == S1AP_CNDomain_cs) {
-    S1AP_PAGING_IND(message_p).cn_domain = CN_DOMAIN_CS;
+  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
+    /* id-CNDomain : convert cnDomain */
+    if (ie->value.choice.CNDomain == S1AP_CNDomain_ps) {
+      S1AP_PAGING_IND(message_p).cn_domain = CN_DOMAIN_PS;
+    } else if (ie->value.choice.CNDomain == S1AP_CNDomain_cs) {
+      S1AP_PAGING_IND(message_p).cn_domain = CN_DOMAIN_CS;
+    } else {
+      /* invalid paging_p->cnDomain */
+      S1AP_ERROR("[SCTP %d] Received Paging : cnDomain(%ld) is unknown\n", assoc_id, ie->value.choice.CNDomain);
+      return -1;
+    }
   } else {
-    /* invalid paging_p->cnDomain */
-    S1AP_ERROR("[SCTP %d] Received Paging : cnDomain(%ld) is unknown\n", assoc_id, ie->value.choice.CNDomain);
     return -1;
   }
 
   memset (&S1AP_PAGING_IND(message_p).plmn_identity[0], 0, sizeof(plmn_identity_t)*256);
   memset (&S1AP_PAGING_IND(message_p).tac[0], 0, sizeof(int16_t)*256);
   S1AP_PAGING_IND(message_p).tai_size = 0;
-
   /* id-TAIList */
   S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PagingIEs_t, ie, container,
                              S1AP_ProtocolIE_ID_id_TAIList, true);
-  S1AP_INFO("[SCTP %d] Received Paging taiList: count %d\n", assoc_id, ie->value.choice.TAIList.list.count);
 
-  for (int i = 0; i < ie->value.choice.TAIList.list.count; i++) {
-    S1AP_TAIItem_t *item_p;
-    item_p = &(((S1AP_TAIItemIEs_t *)ie->value.choice.TAIList.list.array[i])->value.choice.TAIItem);
-    TBCD_TO_MCC_MNC(&(item_p->tAI.pLMNidentity), S1AP_PAGING_IND(message_p).plmn_identity[i].mcc,
-                    S1AP_PAGING_IND(message_p).plmn_identity[i].mnc,
-                    S1AP_PAGING_IND(message_p).plmn_identity[i].mnc_digit_length);
-    OCTET_STRING_TO_INT16(&(item_p->tAI.tAC), S1AP_PAGING_IND(message_p).tac[i]);
-    S1AP_PAGING_IND(message_p).tai_size++;
-    S1AP_DEBUG("[SCTP %d] Received Paging: MCC %d, MNC %d, TAC %d\n", assoc_id,
-               S1AP_PAGING_IND(message_p).plmn_identity[i].mcc,
-               S1AP_PAGING_IND(message_p).plmn_identity[i].mnc,
-               S1AP_PAGING_IND(message_p).tac[i]);
+  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
+    S1AP_INFO("[SCTP %d] Received Paging taiList: count %d\n", assoc_id, ie->value.choice.TAIList.list.count);
+
+    for (int i = 0; i < ie->value.choice.TAIList.list.count; i++) {
+      S1AP_TAIItem_t *item_p;
+      item_p = &(((S1AP_TAIItemIEs_t *)ie->value.choice.TAIList.list.array[i])->value.choice.TAIItem);
+      TBCD_TO_MCC_MNC(&(item_p->tAI.pLMNidentity), S1AP_PAGING_IND(message_p).plmn_identity[i].mcc,
+                      S1AP_PAGING_IND(message_p).plmn_identity[i].mnc,
+                      S1AP_PAGING_IND(message_p).plmn_identity[i].mnc_digit_length);
+      OCTET_STRING_TO_INT16(&(item_p->tAI.tAC), S1AP_PAGING_IND(message_p).tac[i]);
+      S1AP_PAGING_IND(message_p).tai_size++;
+      S1AP_DEBUG("[SCTP %d] Received Paging: MCC %d, MNC %d, TAC %d\n", assoc_id,
+                 S1AP_PAGING_IND(message_p).plmn_identity[i].mcc,
+                 S1AP_PAGING_IND(message_p).plmn_identity[i].mnc,
+                 S1AP_PAGING_IND(message_p).tac[i]);
+    }
+  } else {
+    return -1;
   }
 
-
   //paging parameter values
   S1AP_DEBUG("[SCTP %d] Received Paging parameters: ue_index_value %d  cn_domain %d paging_drx %d paging_priority %d\n",assoc_id,
              S1AP_PAGING_IND(message_p).ue_index_value, S1AP_PAGING_IND(message_p).cn_domain,
@@ -1176,18 +1267,15 @@ int s1ap_eNB_handle_paging(uint32_t               assoc_id,
              S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[0], S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[1],
              S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2], S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[3],
              S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[4], S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[5]);
-
   /* send message to RRC */
   itti_send_msg_to_task(TASK_RRC_ENB, s1ap_eNB_instance->instance, message_p);
-
   return 0;
 }
 
 static
 int s1ap_eNB_handle_e_rab_modify_request(uint32_t               assoc_id,
-                                         uint32_t               stream,
-                                         S1AP_S1AP_PDU_t       *pdu)
-{
+    uint32_t               stream,
+    S1AP_S1AP_PDU_t       *pdu) {
   int i, nb_of_e_rabs_failed;
   s1ap_eNB_mme_data_t           *mme_desc_p       = NULL;
   s1ap_eNB_ue_context_t         *ue_desc_p        = NULL;
@@ -1196,9 +1284,7 @@ int s1ap_eNB_handle_e_rab_modify_request(uint32_t               assoc_id,
   S1AP_E_RABModifyRequestIEs_t  *ie;
   S1AP_ENB_UE_S1AP_ID_t         enb_ue_s1ap_id;
   S1AP_MME_UE_S1AP_ID_t         mme_ue_s1ap_id;
-
   DevAssert(pdu != NULL);
-
   container = &pdu->choice.initiatingMessage.value.choice.E_RABModifyRequest;
 
   if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) {
@@ -1210,15 +1296,25 @@ int s1ap_eNB_handle_e_rab_modify_request(uint32_t               assoc_id,
   /* id-MME-UE-S1AP-ID */
   S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABModifyRequestIEs_t, ie, container,
                              S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID, true);
-  mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID;
+
+  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
+    mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID;
+  } else {
+    return -1;
+  }
 
   /* id-eNB-UE-S1AP-ID */
   S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABModifyRequestIEs_t, ie, container,
                              S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, true);
-  enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID;
+
+  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
+    enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID;
+  } else {
+    return -1;
+  }
 
   if ((ue_desc_p = s1ap_eNB_get_ue_context(mme_desc_p->s1ap_eNB_instance,
-                                           enb_ue_s1ap_id)) == NULL) {
+                   enb_ue_s1ap_id)) == NULL) {
     S1AP_ERROR("[SCTP %d] Received E-RAB modify request for non "
                "existing UE context 0x%06lx\n", assoc_id,
                enb_ue_s1ap_id);
@@ -1238,83 +1334,81 @@ int s1ap_eNB_handle_e_rab_modify_request(uint32_t               assoc_id,
     S1AP_WARN("UE context mme_ue_s1ap_id is different form that of the message (%d != %ld)",
               ue_desc_p->mme_ue_s1ap_id, mme_ue_s1ap_id);
     message_p = itti_alloc_new_message (TASK_RRC_ENB, S1AP_E_RAB_MODIFY_RESP);
-
     S1AP_E_RAB_MODIFY_RESP (message_p).eNB_ue_s1ap_id = enb_ue_s1ap_id;
-
     S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABModifyRequestIEs_t, ie, container,
                                S1AP_ProtocolIE_ID_id_E_RABToBeModifiedListBearerModReq, true);
 
-    for(nb_of_e_rabs_failed = 0; nb_of_e_rabs_failed < ie->value.choice.E_RABToBeModifiedListBearerModReq.list.count; nb_of_e_rabs_failed++) {
-      S1AP_E_RABToBeModifiedItemBearerModReq_t *item_p;
-      item_p = &(((S1AP_E_RABToBeModifiedItemBearerModReqIEs_t *)
-                  ie->value.choice.E_RABToBeModifiedListBearerModReq.list.array[nb_of_e_rabs_failed])->value.choice.E_RABToBeModifiedItemBearerModReq);
-      S1AP_E_RAB_MODIFY_RESP(message_p).e_rabs_failed[nb_of_e_rabs_failed].e_rab_id = item_p->e_RAB_ID;
-      S1AP_E_RAB_MODIFY_RESP(message_p).e_rabs_failed[nb_of_e_rabs_failed].cause = S1AP_Cause_PR_radioNetwork;
-      S1AP_E_RAB_MODIFY_RESP(message_p).e_rabs_failed[nb_of_e_rabs_failed].cause_value = S1AP_CauseRadioNetwork_unknown_mme_ue_s1ap_id;
+    if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
+      for(nb_of_e_rabs_failed = 0; nb_of_e_rabs_failed < ie->value.choice.E_RABToBeModifiedListBearerModReq.list.count; nb_of_e_rabs_failed++) {
+        S1AP_E_RABToBeModifiedItemBearerModReq_t *item_p;
+        item_p = &(((S1AP_E_RABToBeModifiedItemBearerModReqIEs_t *)
+                    ie->value.choice.E_RABToBeModifiedListBearerModReq.list.array[nb_of_e_rabs_failed])->value.choice.E_RABToBeModifiedItemBearerModReq);
+        S1AP_E_RAB_MODIFY_RESP(message_p).e_rabs_failed[nb_of_e_rabs_failed].e_rab_id = item_p->e_RAB_ID;
+        S1AP_E_RAB_MODIFY_RESP(message_p).e_rabs_failed[nb_of_e_rabs_failed].cause = S1AP_Cause_PR_radioNetwork;
+        S1AP_E_RAB_MODIFY_RESP(message_p).e_rabs_failed[nb_of_e_rabs_failed].cause_value = S1AP_CauseRadioNetwork_unknown_mme_ue_s1ap_id;
+      }
+    } else {
+      return -1;
     }
-    S1AP_E_RAB_MODIFY_RESP(message_p).nb_of_e_rabs_failed = nb_of_e_rabs_failed;
 
+    S1AP_E_RAB_MODIFY_RESP(message_p).nb_of_e_rabs_failed = nb_of_e_rabs_failed;
     s1ap_eNB_e_rab_modify_resp(mme_desc_p->s1ap_eNB_instance->instance,
                                &S1AP_E_RAB_MODIFY_RESP(message_p));
-
     message_p = NULL;
     return -1;
   }
 
   message_p        = itti_alloc_new_message(TASK_S1AP, S1AP_E_RAB_MODIFY_REQ);
-
   S1AP_E_RAB_MODIFY_REQ(message_p).ue_initial_id  = ue_desc_p->ue_initial_id;
-
   S1AP_E_RAB_MODIFY_REQ(message_p).mme_ue_s1ap_id  = mme_ue_s1ap_id;
   S1AP_E_RAB_MODIFY_REQ(message_p).eNB_ue_s1ap_id  = enb_ue_s1ap_id;
-
   /* id-E-RABToBeModifiedListBearerModReq */
   S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABModifyRequestIEs_t, ie, container,
                              S1AP_ProtocolIE_ID_id_E_RABToBeModifiedListBearerModReq, true);
-  S1AP_E_RAB_MODIFY_REQ(message_p).nb_e_rabs_tomodify =
-    ie->value.choice.E_RABToBeModifiedListBearerModReq.list.count;
-
-  for (i = 0; i < ie->value.choice.E_RABToBeModifiedListBearerModReq.list.count; i++) {
-    S1AP_E_RABToBeModifiedItemBearerModReq_t *item_p;
-    item_p = &(((S1AP_E_RABToBeModifiedItemBearerModReqIEs_t *)ie->value.choice.E_RABToBeModifiedListBearerModReq.list.array[i])->value.choice.E_RABToBeModifiedItemBearerModReq);
-    S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].e_rab_id = item_p->e_RAB_ID;
 
-    // check for the NAS PDU
-    if (item_p->nAS_PDU.size > 0 ) {
-      S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].nas_pdu.length = item_p->nAS_PDU.size;
+  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
+    S1AP_E_RAB_MODIFY_REQ(message_p).nb_e_rabs_tomodify =
+      ie->value.choice.E_RABToBeModifiedListBearerModReq.list.count;
 
-      S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].nas_pdu.buffer = malloc(sizeof(uint8_t) * item_p->nAS_PDU.size);
+    for (i = 0; i < ie->value.choice.E_RABToBeModifiedListBearerModReq.list.count; i++) {
+      S1AP_E_RABToBeModifiedItemBearerModReq_t *item_p;
+      item_p = &(((S1AP_E_RABToBeModifiedItemBearerModReqIEs_t *)ie->value.choice.E_RABToBeModifiedListBearerModReq.list.array[i])->value.choice.E_RABToBeModifiedItemBearerModReq);
+      S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].e_rab_id = item_p->e_RAB_ID;
+
+      // check for the NAS PDU
+      if (item_p->nAS_PDU.size > 0 ) {
+        S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].nas_pdu.length = item_p->nAS_PDU.size;
+        S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].nas_pdu.buffer = malloc(sizeof(uint8_t) * item_p->nAS_PDU.size);
+        memcpy(S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].nas_pdu.buffer,
+               item_p->nAS_PDU.buf, item_p->nAS_PDU.size);
+      } else {
+        S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].nas_pdu.length = 0;
+        S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].nas_pdu.buffer = NULL;
+        continue;
+      }
 
-      memcpy(S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].nas_pdu.buffer,
-             item_p->nAS_PDU.buf, item_p->nAS_PDU.size);
-    } else {
-      S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].nas_pdu.length = 0;
-      S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].nas_pdu.buffer = NULL;
-      continue;
+      /* Set the QOS informations */
+      S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].qos.qci = item_p->e_RABLevelQoSParameters.qCI;
+      S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].qos.allocation_retention_priority.priority_level =
+        item_p->e_RABLevelQoSParameters.allocationRetentionPriority.priorityLevel;
+      S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].qos.allocation_retention_priority.pre_emp_capability =
+        item_p->e_RABLevelQoSParameters.allocationRetentionPriority.pre_emptionCapability;
+      S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].qos.allocation_retention_priority.pre_emp_vulnerability =
+        item_p->e_RABLevelQoSParameters.allocationRetentionPriority.pre_emptionVulnerability;
     }
 
-    /* Set the QOS informations */
-    S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].qos.qci = item_p->e_RABLevelQoSParameters.qCI;
-
-    S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].qos.allocation_retention_priority.priority_level =
-      item_p->e_RABLevelQoSParameters.allocationRetentionPriority.priorityLevel;
-    S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].qos.allocation_retention_priority.pre_emp_capability =
-      item_p->e_RABLevelQoSParameters.allocationRetentionPriority.pre_emptionCapability;
-    S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].qos.allocation_retention_priority.pre_emp_vulnerability =
-      item_p->e_RABLevelQoSParameters.allocationRetentionPriority.pre_emptionVulnerability;
-
+    itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p);
+  } else { /* of if (ie != NULL)*/
+    return -1;
   }
 
-  itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p);
-
   return 0;
 }
 // handle e-rab release command and send it to rrc_end
 static
 int s1ap_eNB_handle_e_rab_release_command(uint32_t               assoc_id,
-                                          uint32_t               stream,
-                                          S1AP_S1AP_PDU_t       *pdu)
-{
+    uint32_t               stream,
+    S1AP_S1AP_PDU_t       *pdu) {
   int i;
   s1ap_eNB_mme_data_t   *mme_desc_p       = NULL;
   s1ap_eNB_ue_context_t *ue_desc_p        = NULL;
@@ -1323,9 +1417,7 @@ int s1ap_eNB_handle_e_rab_release_command(uint32_t               assoc_id,
   S1AP_E_RABReleaseCommandIEs_t  *ie;
   S1AP_ENB_UE_S1AP_ID_t           enb_ue_s1ap_id;
   S1AP_MME_UE_S1AP_ID_t           mme_ue_s1ap_id;
-
   DevAssert(pdu != NULL);
-
   container = &pdu->choice.initiatingMessage.value.choice.E_RABReleaseCommand;
 
   if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) {
@@ -1336,15 +1428,25 @@ int s1ap_eNB_handle_e_rab_release_command(uint32_t               assoc_id,
   /* id-MME-UE-S1AP-ID */
   S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABReleaseCommandIEs_t, ie, container,
                              S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID, true);
-  mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID;
+
+  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
+    mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID;
+  } else {
+    return -1;
+  }
 
   /* id-eNB-UE-S1AP-ID */
   S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABReleaseCommandIEs_t, ie, container,
                              S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, true);
-  enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID;
+
+  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
+    enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID;
+  } else {
+    return -1;
+  }
 
   if ((ue_desc_p = s1ap_eNB_get_ue_context(mme_desc_p->s1ap_eNB_instance,
-                                           enb_ue_s1ap_id)) == NULL) {
+                   enb_ue_s1ap_id)) == NULL) {
     S1AP_ERROR("[SCTP %d] Received E-RAB release command for non existing UE context 0x%06lx\n", assoc_id,
                ie->value.choice.ENB_UE_S1AP_ID);
     return -1;
@@ -1366,14 +1468,13 @@ int s1ap_eNB_handle_e_rab_release_command(uint32_t               assoc_id,
 
   S1AP_DEBUG("[SCTP %d] Received E-RAB release command for eNB_UE_S1AP_ID %ld mme_ue_s1ap_id %ld\n",
              assoc_id, enb_ue_s1ap_id, mme_ue_s1ap_id);
-
   message_p = itti_alloc_new_message(TASK_S1AP, S1AP_E_RAB_RELEASE_COMMAND);
   S1AP_E_RAB_RELEASE_COMMAND(message_p).eNB_ue_s1ap_id = enb_ue_s1ap_id;
   S1AP_E_RAB_RELEASE_COMMAND(message_p).mme_ue_s1ap_id = mme_ue_s1ap_id;
-
   /* id-NAS-PDU */
   S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABReleaseCommandIEs_t, ie, container,
                              S1AP_ProtocolIE_ID_id_NAS_PDU, false);
+
   if(ie && ie->value.choice.NAS_PDU.size > 0) {
     S1AP_E_RAB_RELEASE_COMMAND(message_p).nas_pdu.length = ie->value.choice.NAS_PDU.size;
     S1AP_E_RAB_RELEASE_COMMAND(message_p).nas_pdu.buffer =
@@ -1389,16 +1490,251 @@ int s1ap_eNB_handle_e_rab_release_command(uint32_t               assoc_id,
   /* id-E-RABToBeReleasedList */
   S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABReleaseCommandIEs_t, ie, container,
                              S1AP_ProtocolIE_ID_id_E_RABToBeReleasedList, true);
-  S1AP_E_RAB_RELEASE_COMMAND(message_p).nb_e_rabs_torelease = ie->value.choice.E_RABList.list.count;
 
-  for (i = 0; i < ie->value.choice.E_RABList.list.count; i++) {
-    S1AP_E_RABItem_t *item_p;
-    item_p = &(((S1AP_E_RABItemIEs_t *)ie->value.choice.E_RABList.list.array[i])->value.choice.E_RABItem);
-    S1AP_E_RAB_RELEASE_COMMAND(message_p).e_rab_release_params[i].e_rab_id = item_p->e_RAB_ID;
-    S1AP_DEBUG("[SCTP] Received E-RAB release command for e-rab id %ld\n", item_p->e_RAB_ID);
+  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
+    S1AP_E_RAB_RELEASE_COMMAND(message_p).nb_e_rabs_torelease = ie->value.choice.E_RABList.list.count;
+
+    for (i = 0; i < ie->value.choice.E_RABList.list.count; i++) {
+      S1AP_E_RABItem_t *item_p;
+      item_p = &(((S1AP_E_RABItemIEs_t *)ie->value.choice.E_RABList.list.array[i])->value.choice.E_RABItem);
+      S1AP_E_RAB_RELEASE_COMMAND(message_p).e_rab_release_params[i].e_rab_id = item_p->e_RAB_ID;
+      S1AP_DEBUG("[SCTP] Received E-RAB release command for e-rab id %ld\n", item_p->e_RAB_ID);
+    }
+  } else {
+    return -1;
   }
 
   itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p);
+  return 0;
+}
+
+static
+int s1ap_eNB_handle_s1_path_switch_request_ack(uint32_t               assoc_id,
+    uint32_t               stream,
+    S1AP_S1AP_PDU_t       *pdu) {
+  s1ap_eNB_mme_data_t   *mme_desc_p       = NULL;
+  s1ap_eNB_ue_context_t *ue_desc_p        = NULL;
+  MessageDef            *message_p        = NULL;
+  S1AP_PathSwitchRequestAcknowledge_t *pathSwitchRequestAcknowledge;
+  S1AP_PathSwitchRequestAcknowledgeIEs_t *ie;
+  S1AP_E_RABToBeSwitchedULItemIEs_t *s1ap_E_RABToBeSwitchedULItemIEs;
+  S1AP_E_RABToBeSwitchedULItem_t *s1ap_E_RABToBeSwitchedULItem;
+  S1AP_E_RABItemIEs_t  *e_RABItemIEs;
+  S1AP_E_RABItem_t     *e_RABItem;
+  DevAssert(pdu != NULL);
+  pathSwitchRequestAcknowledge = &pdu->choice.successfulOutcome.value.choice.PathSwitchRequestAcknowledge;
+
+  /* Path Switch request == UE-related procedure -> stream !=0 */
+  if (stream == 0) {
+    S1AP_ERROR("[SCTP %d] Received s1 path switch request ack on stream (%d)\n",
+               assoc_id, stream);
+    return -1;
+  }
 
+  if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) {
+    S1AP_ERROR("[SCTP %d] Received S1 path switch request ack for non existing "
+               "MME context\n", assoc_id);
+    return -1;
+  }
+
+  // send a message to RRC
+  message_p        = itti_alloc_new_message(TASK_S1AP, S1AP_PATH_SWITCH_REQ_ACK);
+  /* mandatory */
+  S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PathSwitchRequestAcknowledgeIEs_t, ie, pathSwitchRequestAcknowledge,
+                             S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, true);
+  if (ie == NULL) {
+    S1AP_ERROR("[SCTP %d] Received path switch request ack for non "
+               "ie context is NULL\n", assoc_id);
+    return -1;
+  }
+
+  S1AP_PATH_SWITCH_REQ_ACK(message_p).eNB_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID;
+
+  if ((ue_desc_p = s1ap_eNB_get_ue_context(mme_desc_p->s1ap_eNB_instance,
+                   ie->value.choice.ENB_UE_S1AP_ID)) == NULL) {
+    S1AP_ERROR("[SCTP %d] Received path switch request ack for non "
+               "existing UE context 0x%06lx\n", assoc_id,
+               ie->value.choice.ENB_UE_S1AP_ID);
+    return -1;
+  }
+
+  S1AP_PATH_SWITCH_REQ_ACK(message_p).ue_initial_id  = ue_desc_p->ue_initial_id;
+  /* mandatory */
+  S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PathSwitchRequestAcknowledgeIEs_t, ie, pathSwitchRequestAcknowledge,
+                             S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID, true);
+
+  if (ie == NULL) {
+    S1AP_ERROR("[SCTP %d] Received path switch request ack for non "
+               "ie context is NULL\n", assoc_id);
+    return -1;
+  }
+
+  S1AP_PATH_SWITCH_REQ_ACK(message_p).mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID;
+
+  if ( ue_desc_p->mme_ue_s1ap_id != ie->value.choice.MME_UE_S1AP_ID) {
+    S1AP_WARN("UE context mme_ue_s1ap_id is different form that of the message (%d != %ld)",
+              ue_desc_p->mme_ue_s1ap_id, ie->value.choice.MME_UE_S1AP_ID);
+  }
+
+  /* mandatory */
+  S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PathSwitchRequestAcknowledgeIEs_t, ie, pathSwitchRequestAcknowledge,
+                             S1AP_ProtocolIE_ID_id_SecurityContext, true);
+
+  if (ie == NULL) {
+    S1AP_ERROR("[SCTP %d] Received path switch request ack for non "
+               "ie context is NULL\n", assoc_id);
+    return -1;
+  }
+
+  S1AP_PATH_SWITCH_REQ_ACK(message_p).next_hop_chain_count =
+    ie->value.choice.SecurityContext.nextHopChainingCount;
+  memcpy(&S1AP_PATH_SWITCH_REQ_ACK(message_p).next_security_key,
+         ie->value.choice.SecurityContext.nextHopParameter.buf,
+         ie->value.choice.SecurityContext.nextHopParameter.size);
+  /* optional */
+  S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PathSwitchRequestAcknowledgeIEs_t, ie, pathSwitchRequestAcknowledge,
+                             S1AP_ProtocolIE_ID_id_uEaggregateMaximumBitrate, false);
+
+  if (ie) {
+    OCTET_STRING_TO_INT32 (
+      &ie->value.choice.UEAggregateMaximumBitrate.uEaggregateMaximumBitRateUL,
+      S1AP_PATH_SWITCH_REQ_ACK(message_p).ue_ambr.br_ul
+    );
+    OCTET_STRING_TO_INT32 (
+      &ie->value.choice.UEAggregateMaximumBitrate.uEaggregateMaximumBitRateDL,
+      S1AP_PATH_SWITCH_REQ_ACK(message_p).ue_ambr.br_dl
+    );
+  } else {
+    S1AP_WARN("UEAggregateMaximumBitrate not supported\n");
+    S1AP_PATH_SWITCH_REQ_ACK(message_p).ue_ambr.br_ul = 0;
+    S1AP_PATH_SWITCH_REQ_ACK(message_p).ue_ambr.br_dl = 0;
+  }
+
+  /* optional */
+  S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PathSwitchRequestAcknowledgeIEs_t, ie, pathSwitchRequestAcknowledge,
+                             S1AP_ProtocolIE_ID_id_E_RABToBeSwitchedULList, false);
+
+  if (ie) {
+    S1AP_PATH_SWITCH_REQ_ACK(message_p).nb_e_rabs_tobeswitched = ie->value.choice.E_RABToBeSwitchedULList.list.count;
+
+    for (int i = 0; i < ie->value.choice.E_RABToBeSwitchedULList.list.count; i++) {
+      s1ap_E_RABToBeSwitchedULItemIEs = (S1AP_E_RABToBeSwitchedULItemIEs_t *)ie->value.choice.E_RABToBeSwitchedULList.list.array[i];
+      s1ap_E_RABToBeSwitchedULItem = &s1ap_E_RABToBeSwitchedULItemIEs->value.choice.E_RABToBeSwitchedULItem;
+      S1AP_PATH_SWITCH_REQ_ACK (message_p).e_rabs_tobeswitched[i].e_rab_id = s1ap_E_RABToBeSwitchedULItem->e_RAB_ID;
+      memcpy(S1AP_PATH_SWITCH_REQ_ACK (message_p).e_rabs_tobeswitched[i].sgw_addr.buffer,
+             s1ap_E_RABToBeSwitchedULItem->transportLayerAddress.buf, s1ap_E_RABToBeSwitchedULItem->transportLayerAddress.size);
+      S1AP_PATH_SWITCH_REQ_ACK (message_p).e_rabs_tobeswitched[i].sgw_addr.length =
+        s1ap_E_RABToBeSwitchedULItem->transportLayerAddress.size * 8 - s1ap_E_RABToBeSwitchedULItem->transportLayerAddress.bits_unused;
+      OCTET_STRING_TO_INT32(&s1ap_E_RABToBeSwitchedULItem->gTP_TEID,
+                            S1AP_PATH_SWITCH_REQ_ACK (message_p).e_rabs_tobeswitched[i].gtp_teid);
+    }
+  } else {
+    S1AP_WARN("E_RABToBeSwitchedULList not supported\n");
+    S1AP_PATH_SWITCH_REQ_ACK(message_p).nb_e_rabs_tobeswitched = 0;
+  }
+
+  /* optional */
+  S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PathSwitchRequestAcknowledgeIEs_t, ie, pathSwitchRequestAcknowledge,
+                             S1AP_ProtocolIE_ID_id_E_RABToBeReleasedList, false);
+
+  if (ie) {
+    S1AP_PATH_SWITCH_REQ_ACK(message_p).nb_e_rabs_tobereleased = ie->value.choice.E_RABList.list.count;
+
+    for (int i = 0; i < ie->value.choice.E_RABList.list.count; i++) {
+      e_RABItemIEs = (S1AP_E_RABItemIEs_t *)ie->value.choice.E_RABList.list.array[i];
+      e_RABItem =  &e_RABItemIEs->value.choice.E_RABItem;
+      S1AP_PATH_SWITCH_REQ_ACK (message_p).e_rabs_tobereleased[i].e_rab_id = e_RABItem->e_RAB_ID;
+    }
+  } else {
+    S1AP_WARN("E_RABToBeReleasedList not supported\n");
+    S1AP_PATH_SWITCH_REQ_ACK(message_p).nb_e_rabs_tobereleased = 0;
+  }
+
+  /* optional */
+  S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PathSwitchRequestAcknowledgeIEs_t, ie, pathSwitchRequestAcknowledge,
+                             S1AP_ProtocolIE_ID_id_CriticalityDiagnostics, false);
+
+  if(!ie) {
+    S1AP_WARN("Critical Diagnostic not supported\n");
+  }
+
+  /* optional */
+  S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PathSwitchRequestAcknowledgeIEs_t, ie, pathSwitchRequestAcknowledge,
+                             S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID_2, false);
+
+  if(!ie) {
+    S1AP_WARN("MME_UE_S1AP_ID_2 flag not supported\n");
+  }
+
+  // TODO continue
+  itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p);
+  return 0;
+}
+
+static
+int s1ap_eNB_handle_s1_path_switch_request_failure(uint32_t               assoc_id,
+    uint32_t               stream,
+    S1AP_S1AP_PDU_t       *pdu) {
+  s1ap_eNB_mme_data_t   *mme_desc_p       = NULL;
+  S1AP_PathSwitchRequestFailure_t    *pathSwitchRequestFailure;
+  S1AP_PathSwitchRequestFailureIEs_t *ie;
+  DevAssert(pdu != NULL);
+  pathSwitchRequestFailure = &pdu->choice.unsuccessfulOutcome.value.choice.PathSwitchRequestFailure;
+
+  if (stream != 0) {
+    S1AP_ERROR("[SCTP %d] Received s1 path switch request failure on stream != 0 (%d)\n",
+               assoc_id, stream);
+    return -1;
+  }
+
+  if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) {
+    S1AP_ERROR("[SCTP %d] Received S1 path switch request failure for non existing "
+               "MME context\n", assoc_id);
+    return -1;
+  }
+
+  S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PathSwitchRequestFailureIEs_t, ie, pathSwitchRequestFailure,
+                             S1AP_ProtocolIE_ID_id_Cause, true);
+
+  if (ie == NULL) {
+    S1AP_ERROR("[SCTP %d] Received S1 path switch request failure for non existing "
+               "ie context is NULL\n", assoc_id);
+    return -1;
+  }
+
+  switch(ie->value.choice.Cause.present) {
+    case S1AP_Cause_PR_NOTHING:
+      S1AP_WARN("Received S1 Error indication cause NOTHING\n");
+      break;
+
+    case S1AP_Cause_PR_radioNetwork:
+      S1AP_WARN("Radio Network Layer Cause Failure\n");
+      break;
+
+    case S1AP_Cause_PR_transport:
+      S1AP_WARN("Transport Layer Cause Failure\n");
+      break;
+
+    case S1AP_Cause_PR_nas:
+      S1AP_WARN("NAS Cause Failure\n");
+      break;
+
+    case S1AP_Cause_PR_misc:
+      S1AP_WARN("Miscelaneous Cause Failure\n");
+      break;
+
+    default:
+      S1AP_WARN("Received an unknown S1 Error indication cause\n");
+      break;
+  }
+
+  S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PathSwitchRequestFailureIEs_t, ie, pathSwitchRequestFailure,
+                             S1AP_ProtocolIE_ID_id_CriticalityDiagnostics, false);
+
+  if(!ie) {
+    S1AP_WARN("Critical Diagnostic not supported\n");
+  }
+
+  // TODO continue
   return 0;
 }
diff --git a/openair3/S1AP/s1ap_eNB_nas_procedures.c b/openair3/S1AP/s1ap_eNB_nas_procedures.c
index 80266a4d9ca5546766d0bcbfc81e702f8f6899f9..6652ca0447b10ea8a0f573e1cacd5e68beacc34f 100644
--- a/openair3/S1AP/s1ap_eNB_nas_procedures.c
+++ b/openair3/S1AP/s1ap_eNB_nas_procedures.c
@@ -50,426 +50,421 @@
 
 //------------------------------------------------------------------------------
 int s1ap_eNB_handle_nas_first_req(
-  instance_t instance, s1ap_nas_first_req_t *s1ap_nas_first_req_p)
+    instance_t instance, s1ap_nas_first_req_t *s1ap_nas_first_req_p)
 //------------------------------------------------------------------------------
 {
-  s1ap_eNB_instance_t          *instance_p = NULL;
-  struct s1ap_eNB_mme_data_s   *mme_desc_p = NULL;
-  struct s1ap_eNB_ue_context_s *ue_desc_p  = NULL;
-  S1AP_S1AP_PDU_t               pdu;
-  S1AP_InitialUEMessage_t      *out;
-  S1AP_InitialUEMessage_IEs_t  *ie;
-  uint8_t  *buffer = NULL;
-  uint32_t  length = 0;
-
-  DevAssert(s1ap_nas_first_req_p != NULL);
-
-  /* Retrieve the S1AP eNB instance associated with Mod_id */
-  instance_p = s1ap_eNB_get_instance(instance);
-  DevAssert(instance_p != NULL);
-
-  memset(&pdu, 0, sizeof(pdu));
-  pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage;
-  pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_initialUEMessage;
-  pdu.choice.initiatingMessage.criticality = S1AP_Criticality_ignore;
-  pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_InitialUEMessage;
-  out = &pdu.choice.initiatingMessage.value.choice.InitialUEMessage;
-
-  /* Select the MME corresponding to the provided GUMMEI. */
-  if (s1ap_nas_first_req_p->ue_identity.presenceMask & UE_IDENTITIES_gummei) {
-    mme_desc_p = s1ap_eNB_nnsf_select_mme_by_gummei(
-                   instance_p,
-                   s1ap_nas_first_req_p->establishment_cause,
-                   s1ap_nas_first_req_p->ue_identity.gummei);
-    if (mme_desc_p) {
-      S1AP_INFO("[eNB %d] Chose MME '%s' (assoc_id %d) through GUMMEI MCC %d MNC %d MMEGI %d MMEC %d\n",
-                instance,
-                mme_desc_p->mme_name,
-                mme_desc_p->assoc_id,
-                s1ap_nas_first_req_p->ue_identity.gummei.mcc,
-                s1ap_nas_first_req_p->ue_identity.gummei.mnc,
-                s1ap_nas_first_req_p->ue_identity.gummei.mme_group_id,
-                s1ap_nas_first_req_p->ue_identity.gummei.mme_code);
+    s1ap_eNB_instance_t          *instance_p = NULL;
+    struct s1ap_eNB_mme_data_s   *mme_desc_p = NULL;
+    struct s1ap_eNB_ue_context_s *ue_desc_p  = NULL;
+    S1AP_S1AP_PDU_t               pdu;
+    S1AP_InitialUEMessage_t      *out;
+    S1AP_InitialUEMessage_IEs_t  *ie;
+    uint8_t  *buffer = NULL;
+    uint32_t  length = 0;
+    DevAssert(s1ap_nas_first_req_p != NULL);
+    /* Retrieve the S1AP eNB instance associated with Mod_id */
+    instance_p = s1ap_eNB_get_instance(instance);
+    DevAssert(instance_p != NULL);
+    memset(&pdu, 0, sizeof(pdu));
+    pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage;
+    pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_initialUEMessage;
+    pdu.choice.initiatingMessage.criticality = S1AP_Criticality_ignore;
+    pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_InitialUEMessage;
+    out = &pdu.choice.initiatingMessage.value.choice.InitialUEMessage;
+
+    /* Select the MME corresponding to the provided GUMMEI. */
+    if (s1ap_nas_first_req_p->ue_identity.presenceMask & UE_IDENTITIES_gummei) {
+        mme_desc_p = s1ap_eNB_nnsf_select_mme_by_gummei(
+                         instance_p,
+                         s1ap_nas_first_req_p->establishment_cause,
+                         s1ap_nas_first_req_p->ue_identity.gummei);
+
+        if (mme_desc_p) {
+            S1AP_INFO("[eNB %d] Chose MME '%s' (assoc_id %d) through GUMMEI MCC %d MNC %d MMEGI %d MMEC %d\n",
+                      instance,
+                      mme_desc_p->mme_name,
+                      mme_desc_p->assoc_id,
+                      s1ap_nas_first_req_p->ue_identity.gummei.mcc,
+                      s1ap_nas_first_req_p->ue_identity.gummei.mnc,
+                      s1ap_nas_first_req_p->ue_identity.gummei.mme_group_id,
+                      s1ap_nas_first_req_p->ue_identity.gummei.mme_code);
+        }
     }
-  }
 
-  if (mme_desc_p == NULL) {
-    /* Select the MME corresponding to the provided s-TMSI. */
-    if (s1ap_nas_first_req_p->ue_identity.presenceMask & UE_IDENTITIES_s_tmsi) {
-      mme_desc_p = s1ap_eNB_nnsf_select_mme_by_mme_code(
-                     instance_p,
-                     s1ap_nas_first_req_p->establishment_cause,
-                     s1ap_nas_first_req_p->selected_plmn_identity,
-                     s1ap_nas_first_req_p->ue_identity.s_tmsi.mme_code);
-      if (mme_desc_p) {
-        S1AP_INFO("[eNB %d] Chose MME '%s' (assoc_id %d) through S-TMSI MMEC %d and selected PLMN Identity index %d MCC %d MNC %d\n",
-                  instance,
-                  mme_desc_p->mme_name,
-                  mme_desc_p->assoc_id,
-                  s1ap_nas_first_req_p->ue_identity.s_tmsi.mme_code,
-                  s1ap_nas_first_req_p->selected_plmn_identity,
-                  instance_p->mcc[s1ap_nas_first_req_p->selected_plmn_identity],
-                  instance_p->mnc[s1ap_nas_first_req_p->selected_plmn_identity]);
-      }
+    if (mme_desc_p == NULL) {
+        /* Select the MME corresponding to the provided s-TMSI. */
+        if (s1ap_nas_first_req_p->ue_identity.presenceMask & UE_IDENTITIES_s_tmsi) {
+            mme_desc_p = s1ap_eNB_nnsf_select_mme_by_mme_code(
+                             instance_p,
+                             s1ap_nas_first_req_p->establishment_cause,
+                             s1ap_nas_first_req_p->selected_plmn_identity,
+                             s1ap_nas_first_req_p->ue_identity.s_tmsi.mme_code);
+
+            if (mme_desc_p) {
+                S1AP_INFO("[eNB %d] Chose MME '%s' (assoc_id %d) through S-TMSI MMEC %d and selected PLMN Identity index %d MCC %d MNC %d\n",
+                          instance,
+                          mme_desc_p->mme_name,
+                          mme_desc_p->assoc_id,
+                          s1ap_nas_first_req_p->ue_identity.s_tmsi.mme_code,
+                          s1ap_nas_first_req_p->selected_plmn_identity,
+                          instance_p->mcc[s1ap_nas_first_req_p->selected_plmn_identity],
+                          instance_p->mnc[s1ap_nas_first_req_p->selected_plmn_identity]);
+            }
+        }
     }
-  }
 
-  if (mme_desc_p == NULL) {
-    /* Select MME based on the selected PLMN identity, received through RRC
-     * Connection Setup Complete */
-    mme_desc_p = s1ap_eNB_nnsf_select_mme_by_plmn_id(
-                   instance_p,
-                   s1ap_nas_first_req_p->establishment_cause,
-                   s1ap_nas_first_req_p->selected_plmn_identity);
-    if (mme_desc_p) {
-      S1AP_INFO("[eNB %d] Chose MME '%s' (assoc_id %d) through selected PLMN Identity index %d MCC %d MNC %d\n",
-                instance,
-                mme_desc_p->mme_name,
-                mme_desc_p->assoc_id,
-                s1ap_nas_first_req_p->selected_plmn_identity,
-                instance_p->mcc[s1ap_nas_first_req_p->selected_plmn_identity],
-                instance_p->mnc[s1ap_nas_first_req_p->selected_plmn_identity]);
+    if (mme_desc_p == NULL) {
+        /* Select MME based on the selected PLMN identity, received through RRC
+         * Connection Setup Complete */
+        mme_desc_p = s1ap_eNB_nnsf_select_mme_by_plmn_id(
+                         instance_p,
+                         s1ap_nas_first_req_p->establishment_cause,
+                         s1ap_nas_first_req_p->selected_plmn_identity);
+
+        if (mme_desc_p) {
+            S1AP_INFO("[eNB %d] Chose MME '%s' (assoc_id %d) through selected PLMN Identity index %d MCC %d MNC %d\n",
+                      instance,
+                      mme_desc_p->mme_name,
+                      mme_desc_p->assoc_id,
+                      s1ap_nas_first_req_p->selected_plmn_identity,
+                      instance_p->mcc[s1ap_nas_first_req_p->selected_plmn_identity],
+                      instance_p->mnc[s1ap_nas_first_req_p->selected_plmn_identity]);
+        }
     }
-  }
 
-  if (mme_desc_p == NULL) {
-    /*
-     * If no MME corresponds to the GUMMEI, the s-TMSI, or the selected PLMN
-     * identity, selects the MME with the highest capacity.
-     */
-    mme_desc_p = s1ap_eNB_nnsf_select_mme(
-                   instance_p,
-                   s1ap_nas_first_req_p->establishment_cause);
-    if (mme_desc_p) {
-      S1AP_INFO("[eNB %d] Chose MME '%s' (assoc_id %d) through highest relative capacity\n",
-                instance,
-                mme_desc_p->mme_name,
-                mme_desc_p->assoc_id);
+    if (mme_desc_p == NULL) {
+        /*
+         * If no MME corresponds to the GUMMEI, the s-TMSI, or the selected PLMN
+         * identity, selects the MME with the highest capacity.
+         */
+        mme_desc_p = s1ap_eNB_nnsf_select_mme(
+                         instance_p,
+                         s1ap_nas_first_req_p->establishment_cause);
+
+        if (mme_desc_p) {
+            S1AP_INFO("[eNB %d] Chose MME '%s' (assoc_id %d) through highest relative capacity\n",
+                      instance,
+                      mme_desc_p->mme_name,
+                      mme_desc_p->assoc_id);
+        }
     }
-  }
-
-  if (mme_desc_p == NULL) {
-    /*
-     * In case eNB has no MME associated, the eNB should inform RRC and discard
-     * this request.
-     */
-
-    S1AP_WARN("No MME is associated to the eNB\n");
-    // TODO: Inform RRC
-    return -1;
-  }
-
-  /* The eNB should allocate a unique eNB UE S1AP ID for this UE. The value
-   * will be used for the duration of the connectivity.
-   */
-  ue_desc_p = s1ap_eNB_allocate_new_UE_context();
-  DevAssert(ue_desc_p != NULL);
-
-  /* Keep a reference to the selected MME */
-  ue_desc_p->mme_ref       = mme_desc_p;
-  ue_desc_p->ue_initial_id = s1ap_nas_first_req_p->ue_initial_id;
-  ue_desc_p->eNB_instance  = instance_p;
-  ue_desc_p->selected_plmn_identity = s1ap_nas_first_req_p->selected_plmn_identity;
-
-  do {
-    struct s1ap_eNB_ue_context_s *collision_p;
 
-    /* Peek a random value for the eNB_ue_s1ap_id */
-    ue_desc_p->eNB_ue_s1ap_id = (random() + random()) & 0x00ffffff;
-
-    if ((collision_p = RB_INSERT(s1ap_ue_map, &instance_p->s1ap_ue_head, ue_desc_p))
-        == NULL) {
-      S1AP_DEBUG("Found usable eNB_ue_s1ap_id: 0x%06x %d(10)\n",
-                 ue_desc_p->eNB_ue_s1ap_id,
-                 ue_desc_p->eNB_ue_s1ap_id);
-      /* Break the loop as the id is not already used by another UE */
-      break;
+    if (mme_desc_p == NULL) {
+        /*
+         * In case eNB has no MME associated, the eNB should inform RRC and discard
+         * this request.
+         */
+        S1AP_WARN("No MME is associated to the eNB\n");
+        // TODO: Inform RRC
+        return -1;
     }
-  } while(1);
 
-  /* mandatory */
-  ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
-  ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID;
-  ie->criticality = S1AP_Criticality_reject;
-  ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_ENB_UE_S1AP_ID;
-  ie->value.choice.ENB_UE_S1AP_ID = ue_desc_p->eNB_ue_s1ap_id;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    /* The eNB should allocate a unique eNB UE S1AP ID for this UE. The value
+     * will be used for the duration of the connectivity.
+     */
+    ue_desc_p = s1ap_eNB_allocate_new_UE_context();
+    DevAssert(ue_desc_p != NULL);
+    /* Keep a reference to the selected MME */
+    ue_desc_p->mme_ref       = mme_desc_p;
+    ue_desc_p->ue_initial_id = s1ap_nas_first_req_p->ue_initial_id;
+    ue_desc_p->eNB_instance  = instance_p;
+    ue_desc_p->selected_plmn_identity = s1ap_nas_first_req_p->selected_plmn_identity;
+
+    do {
+        struct s1ap_eNB_ue_context_s *collision_p;
+        /* Peek a random value for the eNB_ue_s1ap_id */
+        ue_desc_p->eNB_ue_s1ap_id = (random() + random()) & 0x00ffffff;
+
+        if ((collision_p = RB_INSERT(s1ap_ue_map, &instance_p->s1ap_ue_head, ue_desc_p))
+                == NULL) {
+            S1AP_DEBUG("Found usable eNB_ue_s1ap_id: 0x%06x %u(10)\n",
+                       ue_desc_p->eNB_ue_s1ap_id,
+                       ue_desc_p->eNB_ue_s1ap_id);
+            /* Break the loop as the id is not already used by another UE */
+            break;
+        }
+    } while(1);
 
-  /* mandatory */
-  ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
-  ie->id = S1AP_ProtocolIE_ID_id_NAS_PDU;
-  ie->criticality = S1AP_Criticality_reject;
-  ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_NAS_PDU;
+    /* mandatory */
+    ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
+    ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID;
+    ie->criticality = S1AP_Criticality_reject;
+    ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_ENB_UE_S1AP_ID;
+    ie->value.choice.ENB_UE_S1AP_ID = ue_desc_p->eNB_ue_s1ap_id;
+    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    /* mandatory */
+    ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
+    ie->id = S1AP_ProtocolIE_ID_id_NAS_PDU;
+    ie->criticality = S1AP_Criticality_reject;
+    ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_NAS_PDU;
 #if 1
-  ie->value.choice.NAS_PDU.buf = s1ap_nas_first_req_p->nas_pdu.buffer;
+    ie->value.choice.NAS_PDU.buf = s1ap_nas_first_req_p->nas_pdu.buffer;
 #else
-  ie->value.choice.NAS_PDU.buf = malloc(s1ap_nas_first_req_p->nas_pdu.length);
-  memcpy(ie->value.choice.NAS_PDU.buf,
-         s1ap_nas_first_req_p->nas_pdu.buffer,
-         s1ap_nas_first_req_p->nas_pdu.length);
+    ie->value.choice.NAS_PDU.buf = malloc(s1ap_nas_first_req_p->nas_pdu.length);
+    memcpy(ie->value.choice.NAS_PDU.buf,
+           s1ap_nas_first_req_p->nas_pdu.buffer,
+           s1ap_nas_first_req_p->nas_pdu.length);
 #endif
-  ie->value.choice.NAS_PDU.size = s1ap_nas_first_req_p->nas_pdu.length;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
-  /* mandatory */
-  ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
-  ie->id = S1AP_ProtocolIE_ID_id_TAI;
-  ie->criticality = S1AP_Criticality_reject;
-  ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_TAI;
-  /* Assuming TAI is the TAI from the cell */
-  INT16_TO_OCTET_STRING(instance_p->tac, &ie->value.choice.TAI.tAC);
-  MCC_MNC_TO_PLMNID(instance_p->mcc[ue_desc_p->selected_plmn_identity],
-                    instance_p->mnc[ue_desc_p->selected_plmn_identity],
-                    instance_p->mnc_digit_length[ue_desc_p->selected_plmn_identity],
-                    &ie->value.choice.TAI.pLMNidentity);
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
-  /* mandatory */
-  ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
-  ie->id = S1AP_ProtocolIE_ID_id_EUTRAN_CGI;
-  ie->criticality = S1AP_Criticality_ignore;
-  ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_EUTRAN_CGI;
-  /* Set the EUTRAN CGI
-   * The cell identity is defined on 28 bits but as we use macro enb id,
-   * we have to pad.
-   */
-  //#warning "TODO get cell id from RRC"
-  MACRO_ENB_ID_TO_CELL_IDENTITY(instance_p->eNB_id,
-                                0, // Cell ID
-                                &ie->value.choice.EUTRAN_CGI.cell_ID);
-  MCC_MNC_TO_TBCD(instance_p->mcc[ue_desc_p->selected_plmn_identity],
-                  instance_p->mnc[ue_desc_p->selected_plmn_identity],
-                  instance_p->mnc_digit_length[ue_desc_p->selected_plmn_identity],
-                  &ie->value.choice.EUTRAN_CGI.pLMNidentity);
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
-  /* Set the establishment cause according to those provided by RRC */
-  DevCheck(s1ap_nas_first_req_p->establishment_cause < RRC_CAUSE_LAST,
-           s1ap_nas_first_req_p->establishment_cause, RRC_CAUSE_LAST, 0);
-
-  /* mandatory */
-  ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
-  ie->id = S1AP_ProtocolIE_ID_id_RRC_Establishment_Cause;
-  ie->criticality = S1AP_Criticality_ignore;
-  ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_RRC_Establishment_Cause;
-  ie->value.choice.RRC_Establishment_Cause = s1ap_nas_first_req_p->establishment_cause;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
-  /* optional */
-  if (s1ap_nas_first_req_p->ue_identity.presenceMask & UE_IDENTITIES_s_tmsi) {
-    S1AP_DEBUG("S_TMSI_PRESENT\n");
+    ie->value.choice.NAS_PDU.size = s1ap_nas_first_req_p->nas_pdu.length;
+    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    /* mandatory */
     ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_S_TMSI;
+    ie->id = S1AP_ProtocolIE_ID_id_TAI;
     ie->criticality = S1AP_Criticality_reject;
-    ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_S_TMSI;
-    MME_CODE_TO_OCTET_STRING(s1ap_nas_first_req_p->ue_identity.s_tmsi.mme_code,
-                             &ie->value.choice.S_TMSI.mMEC);
-    M_TMSI_TO_OCTET_STRING(s1ap_nas_first_req_p->ue_identity.s_tmsi.m_tmsi,
-                           &ie->value.choice.S_TMSI.m_TMSI);
+    ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_TAI;
+    /* Assuming TAI is the TAI from the cell */
+    INT16_TO_OCTET_STRING(instance_p->tac, &ie->value.choice.TAI.tAC);
+    MCC_MNC_TO_PLMNID(instance_p->mcc[ue_desc_p->selected_plmn_identity],
+                      instance_p->mnc[ue_desc_p->selected_plmn_identity],
+                      instance_p->mnc_digit_length[ue_desc_p->selected_plmn_identity],
+                      &ie->value.choice.TAI.pLMNidentity);
     ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
-
-  /* optional */
-  if (0) {
+    /* mandatory */
     ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_CSG_Id;
-    ie->criticality = S1AP_Criticality_reject;
-    ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_CSG_Id;
-    // ie->value.choice.CSG_Id = ;
+    ie->id = S1AP_ProtocolIE_ID_id_EUTRAN_CGI;
+    ie->criticality = S1AP_Criticality_ignore;
+    ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_EUTRAN_CGI;
+    /* Set the EUTRAN CGI
+     * The cell identity is defined on 28 bits but as we use macro enb id,
+     * we have to pad.
+     */
+    //#warning "TODO get cell id from RRC"
+    MACRO_ENB_ID_TO_CELL_IDENTITY(instance_p->eNB_id,
+                                  0, // Cell ID
+                                  &ie->value.choice.EUTRAN_CGI.cell_ID);
+    MCC_MNC_TO_TBCD(instance_p->mcc[ue_desc_p->selected_plmn_identity],
+                    instance_p->mnc[ue_desc_p->selected_plmn_identity],
+                    instance_p->mnc_digit_length[ue_desc_p->selected_plmn_identity],
+                    &ie->value.choice.EUTRAN_CGI.pLMNidentity);
     ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
-
-  /* optional */
-  if (s1ap_nas_first_req_p->ue_identity.presenceMask & UE_IDENTITIES_gummei) {
-    S1AP_DEBUG("GUMMEI_ID_PRESENT\n");
+    /* Set the establishment cause according to those provided by RRC */
+    DevCheck(s1ap_nas_first_req_p->establishment_cause < RRC_CAUSE_LAST,
+             s1ap_nas_first_req_p->establishment_cause, RRC_CAUSE_LAST, 0);
+    /* mandatory */
     ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_GUMMEI_ID;
-    ie->criticality = S1AP_Criticality_reject;
-    ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_GUMMEI;
-    MCC_MNC_TO_PLMNID(
-      s1ap_nas_first_req_p->ue_identity.gummei.mcc,
-      s1ap_nas_first_req_p->ue_identity.gummei.mnc,
-      s1ap_nas_first_req_p->ue_identity.gummei.mnc_len,
-      &ie->value.choice.GUMMEI.pLMN_Identity);
-    MME_GID_TO_OCTET_STRING(s1ap_nas_first_req_p->ue_identity.gummei.mme_group_id,
-                            &ie->value.choice.GUMMEI.mME_Group_ID);
-    MME_CODE_TO_OCTET_STRING(s1ap_nas_first_req_p->ue_identity.gummei.mme_code,
-                             &ie->value.choice.GUMMEI.mME_Code);
+    ie->id = S1AP_ProtocolIE_ID_id_RRC_Establishment_Cause;
+    ie->criticality = S1AP_Criticality_ignore;
+    ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_RRC_Establishment_Cause;
+    ie->value.choice.RRC_Establishment_Cause = s1ap_nas_first_req_p->establishment_cause;
     ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
 
-  /* optional */
+    /* optional */
+    if (s1ap_nas_first_req_p->ue_identity.presenceMask & UE_IDENTITIES_s_tmsi) {
+        S1AP_DEBUG("S_TMSI_PRESENT\n");
+        ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_S_TMSI;
+        ie->criticality = S1AP_Criticality_reject;
+        ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_S_TMSI;
+        MME_CODE_TO_OCTET_STRING(s1ap_nas_first_req_p->ue_identity.s_tmsi.mme_code,
+                                 &ie->value.choice.S_TMSI.mMEC);
+        M_TMSI_TO_OCTET_STRING(s1ap_nas_first_req_p->ue_identity.s_tmsi.m_tmsi,
+                               &ie->value.choice.S_TMSI.m_TMSI);
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    }
+
+    /* optional */
+    if (0) {
+        ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_CSG_Id;
+        ie->criticality = S1AP_Criticality_reject;
+        ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_CSG_Id;
+        // ie->value.choice.CSG_Id = ;
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    }
+
+    /* optional */
+    if (s1ap_nas_first_req_p->ue_identity.presenceMask & UE_IDENTITIES_gummei) {
+        S1AP_DEBUG("GUMMEI_ID_PRESENT\n");
+        ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_GUMMEI_ID;
+        ie->criticality = S1AP_Criticality_reject;
+        ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_GUMMEI;
+        MCC_MNC_TO_PLMNID(
+            s1ap_nas_first_req_p->ue_identity.gummei.mcc,
+            s1ap_nas_first_req_p->ue_identity.gummei.mnc,
+            s1ap_nas_first_req_p->ue_identity.gummei.mnc_len,
+            &ie->value.choice.GUMMEI.pLMN_Identity);
+        MME_GID_TO_OCTET_STRING(s1ap_nas_first_req_p->ue_identity.gummei.mme_group_id,
+                                &ie->value.choice.GUMMEI.mME_Group_ID);
+        MME_CODE_TO_OCTET_STRING(s1ap_nas_first_req_p->ue_identity.gummei.mme_code,
+                                 &ie->value.choice.GUMMEI.mME_Code);
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    }
+
+    /* optional */
 #if (S1AP_VERSION >= MAKE_VERSION(9, 0, 0))
-  if (0) {
-    ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_CellAccessMode;
-    ie->criticality = S1AP_Criticality_reject;
-    ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_CellAccessMode;
-    // ie->value.choice.CellAccessMode = ;
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
 
-  /* optional */
+    if (0) {
+        ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_CellAccessMode;
+        ie->criticality = S1AP_Criticality_reject;
+        ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_CellAccessMode;
+        // ie->value.choice.CellAccessMode = ;
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    }
+
+    /* optional */
 #if (S1AP_VERSION >= MAKE_VERSION(10, 0, 0))
-  if (0) {
-    ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_GW_TransportLayerAddress;
-    ie->criticality = S1AP_Criticality_reject;
-    ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_TransportLayerAddress;
-    // ie->value.choice.TransportLayerAddress =;
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
 
-  /* optional */
-  if (0) {
-    ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_RelayNode_Indicator;
-    ie->criticality = S1AP_Criticality_ignore;
-    ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_RelayNode_Indicator;
-    // ie->value.choice.RelayNode_Indicator =;
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
+    if (0) {
+        ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_GW_TransportLayerAddress;
+        ie->criticality = S1AP_Criticality_reject;
+        ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_TransportLayerAddress;
+        // ie->value.choice.TransportLayerAddress =;
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    }
+
+    /* optional */
+    if (0) {
+        ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_RelayNode_Indicator;
+        ie->criticality = S1AP_Criticality_ignore;
+        ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_RelayNode_Indicator;
+        // ie->value.choice.RelayNode_Indicator =;
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    }
 
 #if (S1AP_VERSION >= MAKE_VERSION(11, 0, 0))
-  /* optional */
-  if (0) {
-    ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_GUMMEIType;
-    ie->criticality = S1AP_Criticality_reject;
-    ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_GUMMEIType;
-    // ie->value.choice.GUMMEIType =;
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
 
-  /* optional */ /* release 11 */
-  if (0) {
-    ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_Tunnel_Information_for_BBF;
-    ie->criticality = S1AP_Criticality_ignore;
-    ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_TunnelInformation;
-    // ie->value.choice.TunnelInformation =;
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
+    /* optional */
+    if (0) {
+        ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_GUMMEIType;
+        ie->criticality = S1AP_Criticality_reject;
+        ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_GUMMEIType;
+        // ie->value.choice.GUMMEIType =;
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    }
 
-  /* optional */
-  if (0) {
-    ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_SIPTO_L_GW_TransportLayerAddress;
-    ie->criticality = S1AP_Criticality_ignore;
-    ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_TransportLayerAddress;
-    // ie->value.choice.TransportLayerAddress = ;
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
+    /* optional */ /* release 11 */
+    if (0) {
+        ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_Tunnel_Information_for_BBF;
+        ie->criticality = S1AP_Criticality_ignore;
+        ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_TunnelInformation;
+        // ie->value.choice.TunnelInformation =;
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    }
 
-  /* optional */
-  if (0) {
-    ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_LHN_ID;
-    ie->criticality = S1AP_Criticality_ignore;
-    ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_LHN_ID;
-    // ie->value.choice.LHN_ID = ue_release_req_p->eNB_ue_s1ap_id;
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
+    /* optional */
+    if (0) {
+        ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_SIPTO_L_GW_TransportLayerAddress;
+        ie->criticality = S1AP_Criticality_ignore;
+        ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_TransportLayerAddress;
+        // ie->value.choice.TransportLayerAddress = ;
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    }
+
+    /* optional */
+    if (0) {
+        ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_LHN_ID;
+        ie->criticality = S1AP_Criticality_ignore;
+        ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_LHN_ID;
+        // ie->value.choice.LHN_ID = ue_release_req_p->eNB_ue_s1ap_id;
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    }
 
 #if (S1AP_VERSION >= MAKE_VERSION(13, 0, 0))
-  /* optional */
-  if (0) {
-    ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_MME_Group_ID;
-    ie->criticality = S1AP_Criticality_ignore;
-    ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_MME_Group_ID;
-    // ie->value.choice.MME_Group_ID =;
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
 
-  /* optional */
-  if (0) {
-    ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_UE_Usage_Type;
-    ie->criticality = S1AP_Criticality_ignore;
-    ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_UE_Usage_Type;
-    // ie->value.choice.UE_Usage_Type =;
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
+    /* optional */
+    if (0) {
+        ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_MME_Group_ID;
+        ie->criticality = S1AP_Criticality_ignore;
+        ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_MME_Group_ID;
+        // ie->value.choice.MME_Group_ID =;
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    }
 
-  /* optional */
-  if (0) {
-    ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_CE_mode_B_SupportIndicator;
-    ie->criticality = S1AP_Criticality_ignore;
-    ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_CE_mode_B_SupportIndicator;
-    // ie->value.choice.CE_mode_B_SupportIndicator = ;
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
+    /* optional */
+    if (0) {
+        ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_UE_Usage_Type;
+        ie->criticality = S1AP_Criticality_ignore;
+        ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_UE_Usage_Type;
+        // ie->value.choice.UE_Usage_Type =;
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    }
+
+    /* optional */
+    if (0) {
+        ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_CE_mode_B_SupportIndicator;
+        ie->criticality = S1AP_Criticality_ignore;
+        ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_CE_mode_B_SupportIndicator;
+        // ie->value.choice.CE_mode_B_SupportIndicator = ;
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    }
 
 #if (S1AP_VERSION >= MAKE_VERSION(14, 0, 0))
-  /* optional */
-  if (0) {
-    ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_DCN_ID;
-    ie->criticality = S1AP_Criticality_ignore;
-    ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_DCN_ID;
-    // ie->value.choice.DCN_ID = ;
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
 
-  /* optional */
-  if (0) {
-    ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_Coverage_Level;
-    ie->criticality = S1AP_Criticality_ignore;
-    ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_Coverage_Level;
-    // ie->value.choice.Coverage_Level = ue_release_req_p->eNB_ue_s1ap_id;
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
+    /* optional */
+    if (0) {
+        ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_DCN_ID;
+        ie->criticality = S1AP_Criticality_ignore;
+        ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_DCN_ID;
+        // ie->value.choice.DCN_ID = ;
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    }
+
+    /* optional */
+    if (0) {
+        ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_Coverage_Level;
+        ie->criticality = S1AP_Criticality_ignore;
+        ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_Coverage_Level;
+        // ie->value.choice.Coverage_Level = ue_release_req_p->eNB_ue_s1ap_id;
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    }
+
 #endif /* #if (S1AP_VERSION >= MAKE_VERSION(14, 0, 0)) */
 #endif /* #if (S1AP_VERSION >= MAKE_VERSION(13, 0, 0)) */
 #endif /* #if (S1AP_VERSION >= MAKE_VERSION(11, 0, 0)) */
 #endif /* #if (S1AP_VERSION >= MAKE_VERSION(10, 0, 0)) */
 #endif /* #if (S1AP_VERSION >= MAKE_VERSION(9, 0, 0)) */
 
-  if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) {
-    /* Failed to encode message */
-    DevMessage("Failed to encode initial UE message\n");
-  }
-
-  /* Update the current S1AP UE state */
-  ue_desc_p->ue_state = S1AP_UE_WAITING_CSR;
-
-  /* Assign a stream for this UE :
-   * From 3GPP 36.412 7)Transport layers:
-   *  Within the SCTP association established between one MME and eNB pair:
-   *  - a single pair of stream identifiers shall be reserved for the sole use
-   *      of S1AP elementary procedures that utilize non UE-associated signalling.
-   *  - At least one pair of stream identifiers shall be reserved for the sole use
-   *      of S1AP elementary procedures that utilize UE-associated signallings.
-   *      However a few pairs (i.e. more than one) should be reserved.
-   *  - A single UE-associated signalling shall use one SCTP stream and
-   *      the stream should not be changed during the communication of the
-   *      UE-associated signalling.
-   */
-  mme_desc_p->nextstream = (mme_desc_p->nextstream + 1) % mme_desc_p->out_streams;
-
-  if ((mme_desc_p->nextstream == 0) && (mme_desc_p->out_streams > 1)) {
-    mme_desc_p->nextstream += 1;
-  }
-
-  ue_desc_p->tx_stream = mme_desc_p->nextstream;
+    if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) {
+        /* Failed to encode message */
+        DevMessage("Failed to encode initial UE message\n");
+    }
 
-  MSC_LOG_TX_MESSAGE(
-    MSC_S1AP_ENB,
-    MSC_S1AP_MME,
-    (const char *)NULL,
-    0,
-    MSC_AS_TIME_FMT" initialUEMessage initiatingMessage eNB_ue_s1ap_id %u",
-    0,0,//MSC_AS_TIME_ARGS(ctxt_pP),
-    ue_desc_p->eNB_ue_s1ap_id);
+    /* Update the current S1AP UE state */
+    ue_desc_p->ue_state = S1AP_UE_WAITING_CSR;
+    /* Assign a stream for this UE :
+     * From 3GPP 36.412 7)Transport layers:
+     *  Within the SCTP association established between one MME and eNB pair:
+     *  - a single pair of stream identifiers shall be reserved for the sole use
+     *      of S1AP elementary procedures that utilize non UE-associated signalling.
+     *  - At least one pair of stream identifiers shall be reserved for the sole use
+     *      of S1AP elementary procedures that utilize UE-associated signallings.
+     *      However a few pairs (i.e. more than one) should be reserved.
+     *  - A single UE-associated signalling shall use one SCTP stream and
+     *      the stream should not be changed during the communication of the
+     *      UE-associated signalling.
+     */
+    mme_desc_p->nextstream = (mme_desc_p->nextstream + 1) % mme_desc_p->out_streams;
 
-  /* Send encoded message over sctp */
-  s1ap_eNB_itti_send_sctp_data_req(instance_p->instance, mme_desc_p->assoc_id,
-                                   buffer, length, ue_desc_p->tx_stream);
+    if ((mme_desc_p->nextstream == 0) && (mme_desc_p->out_streams > 1)) {
+        mme_desc_p->nextstream += 1;
+    }
 
-  return 0;
+    ue_desc_p->tx_stream = mme_desc_p->nextstream;
+    MSC_LOG_TX_MESSAGE(
+        MSC_S1AP_ENB,
+        MSC_S1AP_MME,
+        (const char *)NULL,
+        0,
+        MSC_AS_TIME_FMT" initialUEMessage initiatingMessage eNB_ue_s1ap_id %u",
+        0,0,//MSC_AS_TIME_ARGS(ctxt_pP),
+        ue_desc_p->eNB_ue_s1ap_id);
+    /* Send encoded message over sctp */
+    s1ap_eNB_itti_send_sctp_data_req(instance_p->instance, mme_desc_p->assoc_id,
+                                     buffer, length, ue_desc_p->tx_stream);
+    return 0;
 }
 
 //------------------------------------------------------------------------------
@@ -478,261 +473,258 @@ int s1ap_eNB_handle_nas_downlink(uint32_t         assoc_id,
                                  S1AP_S1AP_PDU_t *pdu)
 //------------------------------------------------------------------------------
 {
-  s1ap_eNB_mme_data_t             *mme_desc_p        = NULL;
-  s1ap_eNB_ue_context_t           *ue_desc_p         = NULL;
-  s1ap_eNB_instance_t             *s1ap_eNB_instance = NULL;
-  S1AP_DownlinkNASTransport_t     *container;
-  S1AP_DownlinkNASTransport_IEs_t *ie;
-  S1AP_ENB_UE_S1AP_ID_t            enb_ue_s1ap_id;
-  S1AP_MME_UE_S1AP_ID_t            mme_ue_s1ap_id;
-  DevAssert(pdu != NULL);
-
-  /* UE-related procedure -> stream != 0 */
-  if (stream == 0) {
-    S1AP_ERROR("[SCTP %d] Received UE-related procedure on stream == 0\n",
-               assoc_id);
-    return -1;
-  }
-
-  if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) {
-    S1AP_ERROR(
-      "[SCTP %d] Received NAS downlink message for non existing MME context\n",
-      assoc_id);
-    return -1;
-  }
+    s1ap_eNB_mme_data_t             *mme_desc_p        = NULL;
+    s1ap_eNB_ue_context_t           *ue_desc_p         = NULL;
+    s1ap_eNB_instance_t             *s1ap_eNB_instance = NULL;
+    S1AP_DownlinkNASTransport_t     *container;
+    S1AP_DownlinkNASTransport_IEs_t *ie;
+    S1AP_ENB_UE_S1AP_ID_t            enb_ue_s1ap_id;
+    S1AP_MME_UE_S1AP_ID_t            mme_ue_s1ap_id;
+    DevAssert(pdu != NULL);
+
+    /* UE-related procedure -> stream != 0 */
+    if (stream == 0) {
+        S1AP_ERROR("[SCTP %d] Received UE-related procedure on stream == 0\n",
+                   assoc_id);
+        return -1;
+    }
 
-  s1ap_eNB_instance = mme_desc_p->s1ap_eNB_instance;
+    if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) {
+        S1AP_ERROR(
+            "[SCTP %d] Received NAS downlink message for non existing MME context\n",
+            assoc_id);
+        return -1;
+    }
 
-  /* Prepare the S1AP message to encode */
-  container = &pdu->choice.initiatingMessage.value.choice.DownlinkNASTransport;
-
-  S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_DownlinkNASTransport_IEs_t, ie, container,
-                             S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID, true);
-  mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID;
-
-  S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_DownlinkNASTransport_IEs_t, ie, container,
-                             S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, true);
-  enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID;
-
-  if ((ue_desc_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance,
-                                           enb_ue_s1ap_id)) == NULL) {
-    MSC_LOG_RX_DISCARDED_MESSAGE(
-      MSC_S1AP_ENB,
-      MSC_S1AP_MME,
-      NULL,
-      0,
-      MSC_AS_TIME_FMT" downlinkNASTransport  eNB_ue_s1ap_id %u mme_ue_s1ap_id %u",
-      enb_ue_s1ap_id,
-      mme_ue_s1ap_id);
-    S1AP_ERROR("[SCTP %d] Received NAS downlink message for non existing UE context eNB_UE_S1AP_ID: 0x%lx\n",
-               assoc_id,
-               enb_ue_s1ap_id);
-    return -1;
-  }
+    s1ap_eNB_instance = mme_desc_p->s1ap_eNB_instance;
+    /* Prepare the S1AP message to encode */
+    container = &pdu->choice.initiatingMessage.value.choice.DownlinkNASTransport;
+    S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_DownlinkNASTransport_IEs_t, ie, container,
+                               S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID, true);
+    if (ie == NULL) { /* checked by macro, but cppcheck doesn't see it */
+        return -1;
+    } else {
+        mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID;
+    }
+    S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_DownlinkNASTransport_IEs_t, ie, container,
+                               S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, true);
+    if (ie == NULL) { /* checked by macro, but cppcheck doesn't see it */
+        return -1;
+    } else {
+        enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID;
+    }
+    if ((ue_desc_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance,
+                     enb_ue_s1ap_id)) == NULL) {
+        MSC_LOG_RX_DISCARDED_MESSAGE(
+            MSC_S1AP_ENB,
+            MSC_S1AP_MME,
+            NULL,
+            0,
+            MSC_AS_TIME_FMT" downlinkNASTransport  eNB_ue_s1ap_id %u mme_ue_s1ap_id %u",
+            enb_ue_s1ap_id,
+            mme_ue_s1ap_id);
+        S1AP_ERROR("[SCTP %d] Received NAS downlink message for non existing UE context eNB_UE_S1AP_ID: 0x%lx\n",
+                   assoc_id,
+                   enb_ue_s1ap_id);
+        return -1;
+    }
 
-  if (0 == ue_desc_p->rx_stream) {
-    ue_desc_p->rx_stream = stream;
-  } else if (stream != ue_desc_p->rx_stream) {
-    S1AP_ERROR("[SCTP %d] Received UE-related procedure on stream %u, expecting %u\n",
-               assoc_id, stream, ue_desc_p->rx_stream);
-    return -1;
-  }
+    if (0 == ue_desc_p->rx_stream) {
+        ue_desc_p->rx_stream = stream;
+    } else if (stream != ue_desc_p->rx_stream) {
+        S1AP_ERROR("[SCTP %d] Received UE-related procedure on stream %u, expecting %u\n",
+                   assoc_id, stream, ue_desc_p->rx_stream);
+        return -1;
+    }
 
-  /* Is it the first outcome of the MME for this UE ? If so store the mme
-   * UE s1ap id.
-   */
-  if (ue_desc_p->mme_ue_s1ap_id == 0) {
-    ue_desc_p->mme_ue_s1ap_id = mme_ue_s1ap_id;
-  } else {
-    /* We already have a mme ue s1ap id check the received is the same */
-    if (ue_desc_p->mme_ue_s1ap_id != mme_ue_s1ap_id) {
-      S1AP_ERROR("[SCTP %d] Mismatch in MME UE S1AP ID (0x%lx != 0x%"PRIx32"\n",
-                 assoc_id,
-                 mme_ue_s1ap_id,
-                 ue_desc_p->mme_ue_s1ap_id
-                );
-      return -1;
+    /* Is it the first outcome of the MME for this UE ? If so store the mme
+     * UE s1ap id.
+     */
+    if (ue_desc_p->mme_ue_s1ap_id == 0) {
+        ue_desc_p->mme_ue_s1ap_id = mme_ue_s1ap_id;
+    } else {
+        /* We already have a mme ue s1ap id check the received is the same */
+        if (ue_desc_p->mme_ue_s1ap_id != mme_ue_s1ap_id) {
+            S1AP_ERROR("[SCTP %d] Mismatch in MME UE S1AP ID (0x%lx != 0x%"PRIx32"\n",
+                       assoc_id,
+                       mme_ue_s1ap_id,
+                       ue_desc_p->mme_ue_s1ap_id
+                      );
+            return -1;
+        }
     }
-  }
 
-  MSC_LOG_RX_MESSAGE(
-    MSC_S1AP_ENB,
-    MSC_S1AP_MME,
-    NULL,
-    0,
-    MSC_AS_TIME_FMT" downlinkNASTransport  eNB_ue_s1ap_id %u mme_ue_s1ap_id %u",
-    assoc_id,
-    mme_ue_s1ap_id);
-
-  S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_DownlinkNASTransport_IEs_t, ie, container,
-                             S1AP_ProtocolIE_ID_id_NAS_PDU, true);
-  /* Forward the NAS PDU to RRC */
-  s1ap_eNB_itti_send_nas_downlink_ind(s1ap_eNB_instance->instance,
-                                      ue_desc_p->ue_initial_id,
-                                      ue_desc_p->eNB_ue_s1ap_id,
-                                      ie->value.choice.NAS_PDU.buf,
-                                      ie->value.choice.NAS_PDU.size);
-
-  // LG: Why set to 0 ??
-  //ue_desc_p->ue_initial_id = 0;
-
-  return 0;
+    MSC_LOG_RX_MESSAGE(
+        MSC_S1AP_ENB,
+        MSC_S1AP_MME,
+        NULL,
+        0,
+        MSC_AS_TIME_FMT" downlinkNASTransport  eNB_ue_s1ap_id %u mme_ue_s1ap_id %u",
+        assoc_id,
+        mme_ue_s1ap_id);
+
+    S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_DownlinkNASTransport_IEs_t, ie, container,
+                               S1AP_ProtocolIE_ID_id_NAS_PDU, true);
+    /* Forward the NAS PDU to RRC */
+    if (ie != NULL) { /* checked by macro, but cppcheck doesn't see it */
+        s1ap_eNB_itti_send_nas_downlink_ind(s1ap_eNB_instance->instance,
+                                            ue_desc_p->ue_initial_id,
+                                            ue_desc_p->eNB_ue_s1ap_id,
+                                            ie->value.choice.NAS_PDU.buf,
+                                            ie->value.choice.NAS_PDU.size);
+    } else {
+        return -1;
+    }
+    return 0;
 }
 
 //------------------------------------------------------------------------------
 int s1ap_eNB_nas_uplink(instance_t instance, s1ap_uplink_nas_t *s1ap_uplink_nas_p)
 //------------------------------------------------------------------------------
 {
-  struct s1ap_eNB_ue_context_s  *ue_context_p;
-  s1ap_eNB_instance_t           *s1ap_eNB_instance_p;
-  S1AP_S1AP_PDU_t                pdu;
-  S1AP_UplinkNASTransport_t     *out;
-  S1AP_UplinkNASTransport_IEs_t *ie;
-  uint8_t  *buffer;
-  uint32_t  length;
+    struct s1ap_eNB_ue_context_s  *ue_context_p;
+    s1ap_eNB_instance_t           *s1ap_eNB_instance_p;
+    S1AP_S1AP_PDU_t                pdu;
+    S1AP_UplinkNASTransport_t     *out;
+    S1AP_UplinkNASTransport_IEs_t *ie;
+    uint8_t  *buffer;
+    uint32_t  length;
+    DevAssert(s1ap_uplink_nas_p != NULL);
+    /* Retrieve the S1AP eNB instance associated with Mod_id */
+    s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance);
+    DevAssert(s1ap_eNB_instance_p != NULL);
+
+    if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, s1ap_uplink_nas_p->eNB_ue_s1ap_id)) == NULL) {
+        /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */
+        S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: %06x\n",
+                  s1ap_uplink_nas_p->eNB_ue_s1ap_id);
+        return -1;
+    }
 
-  DevAssert(s1ap_uplink_nas_p != NULL);
+    /* Uplink NAS transport can occur either during an s1ap connected state
+     * or during initial attach (for example: NAS authentication).
+     */
+    if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED ||
+            ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) {
+        S1AP_WARN("You are attempting to send NAS data over non-connected "
+                  "eNB ue s1ap id: %u, current state: %d\n",
+                  s1ap_uplink_nas_p->eNB_ue_s1ap_id, ue_context_p->ue_state);
+        return -1;
+    }
 
-  /* Retrieve the S1AP eNB instance associated with Mod_id */
-  s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance);
-  DevAssert(s1ap_eNB_instance_p != NULL);
+    /* Prepare the S1AP message to encode */
+    memset(&pdu, 0, sizeof(pdu));
+    pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage;
+    pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_uplinkNASTransport;
+    pdu.choice.initiatingMessage.criticality = S1AP_Criticality_ignore;
+    pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_UplinkNASTransport;
+    out = &pdu.choice.initiatingMessage.value.choice.UplinkNASTransport;
+    /* mandatory */
+    ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t));
+    ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID;
+    ie->criticality = S1AP_Criticality_reject;
+    ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_MME_UE_S1AP_ID;
+    ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id;
+    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    /* mandatory */
+    ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t));
+    ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID;
+    ie->criticality = S1AP_Criticality_reject;
+    ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_ENB_UE_S1AP_ID;
+    ie->value.choice.ENB_UE_S1AP_ID = ue_context_p->eNB_ue_s1ap_id;
+    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    /* mandatory */
+    ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t));
+    ie->id = S1AP_ProtocolIE_ID_id_NAS_PDU;
+    ie->criticality = S1AP_Criticality_reject;
+    ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_NAS_PDU;
+    ie->value.choice.NAS_PDU.buf = s1ap_uplink_nas_p->nas_pdu.buffer;
+    ie->value.choice.NAS_PDU.size = s1ap_uplink_nas_p->nas_pdu.length;
+    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    /* mandatory */
+    ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t));
+    ie->id = S1AP_ProtocolIE_ID_id_EUTRAN_CGI;
+    ie->criticality = S1AP_Criticality_ignore;
+    ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_EUTRAN_CGI;
+    MCC_MNC_TO_PLMNID(
+        s1ap_eNB_instance_p->mcc[ue_context_p->selected_plmn_identity],
+        s1ap_eNB_instance_p->mnc[ue_context_p->selected_plmn_identity],
+        s1ap_eNB_instance_p->mnc_digit_length[ue_context_p->selected_plmn_identity],
+        &ie->value.choice.EUTRAN_CGI.pLMNidentity);
+    //#warning "TODO get cell id from RRC"
+    MACRO_ENB_ID_TO_CELL_IDENTITY(s1ap_eNB_instance_p->eNB_id,
+                                  0,
+                                  &ie->value.choice.EUTRAN_CGI.cell_ID);
+    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    /* mandatory */
+    ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t));
+    ie->id = S1AP_ProtocolIE_ID_id_TAI;
+    ie->criticality = S1AP_Criticality_ignore;
+    ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_TAI;
+    MCC_MNC_TO_PLMNID(
+        s1ap_eNB_instance_p->mcc[ue_context_p->selected_plmn_identity],
+        s1ap_eNB_instance_p->mnc[ue_context_p->selected_plmn_identity],
+        s1ap_eNB_instance_p->mnc_digit_length[ue_context_p->selected_plmn_identity],
+        &ie->value.choice.TAI.pLMNidentity);
+    TAC_TO_ASN1(s1ap_eNB_instance_p->tac, &ie->value.choice.TAI.tAC);
+    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    /* optional */
+#if (S1AP_VERSION >= MAKE_VERSION(10, 0, 0))
 
-  if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, s1ap_uplink_nas_p->eNB_ue_s1ap_id)) == NULL) {
-    /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */
-    S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: %06x\n",
-              s1ap_uplink_nas_p->eNB_ue_s1ap_id);
-    return -1;
-  }
-
-  /* Uplink NAS transport can occur either during an s1ap connected state
-   * or during initial attach (for example: NAS authentication).
-   */
-  if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED ||
-        ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) {
-    S1AP_WARN("You are attempting to send NAS data over non-connected "
-              "eNB ue s1ap id: %u, current state: %d\n",
-              s1ap_uplink_nas_p->eNB_ue_s1ap_id, ue_context_p->ue_state);
-    return -1;
-  }
-
-  /* Prepare the S1AP message to encode */
-  memset(&pdu, 0, sizeof(pdu));
-  pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage;
-  pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_uplinkNASTransport;
-  pdu.choice.initiatingMessage.criticality = S1AP_Criticality_ignore;
-  pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_UplinkNASTransport;
-  out = &pdu.choice.initiatingMessage.value.choice.UplinkNASTransport;
-
-  /* mandatory */
-  ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t));
-  ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID;
-  ie->criticality = S1AP_Criticality_reject;
-  ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_MME_UE_S1AP_ID;
-  ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
-  /* mandatory */
-  ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t));
-  ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID;
-  ie->criticality = S1AP_Criticality_reject;
-  ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_ENB_UE_S1AP_ID;
-  ie->value.choice.ENB_UE_S1AP_ID = ue_context_p->eNB_ue_s1ap_id;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
-  /* mandatory */
-  ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t));
-  ie->id = S1AP_ProtocolIE_ID_id_NAS_PDU;
-  ie->criticality = S1AP_Criticality_reject;
-  ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_NAS_PDU;
-  ie->value.choice.NAS_PDU.buf = s1ap_uplink_nas_p->nas_pdu.buffer;
-  ie->value.choice.NAS_PDU.size = s1ap_uplink_nas_p->nas_pdu.length;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
-  /* mandatory */
-  ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t));
-  ie->id = S1AP_ProtocolIE_ID_id_EUTRAN_CGI;
-  ie->criticality = S1AP_Criticality_ignore;
-  ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_EUTRAN_CGI;
-  MCC_MNC_TO_PLMNID(
-    s1ap_eNB_instance_p->mcc[ue_context_p->selected_plmn_identity],
-    s1ap_eNB_instance_p->mnc[ue_context_p->selected_plmn_identity],
-    s1ap_eNB_instance_p->mnc_digit_length[ue_context_p->selected_plmn_identity],
-    &ie->value.choice.EUTRAN_CGI.pLMNidentity);
-  //#warning "TODO get cell id from RRC"
-  MACRO_ENB_ID_TO_CELL_IDENTITY(s1ap_eNB_instance_p->eNB_id,
-                                0,
-                                &ie->value.choice.EUTRAN_CGI.cell_ID);
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    if (0) {
+        ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_GW_TransportLayerAddress;
+        ie->criticality = S1AP_Criticality_ignore;
+        ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_TransportLayerAddress;
+        // ie->value.choice.TransportLayerAddress = ;
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    }
 
-  /* mandatory */
-  ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t));
-  ie->id = S1AP_ProtocolIE_ID_id_TAI;
-  ie->criticality = S1AP_Criticality_ignore;
-  ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_TAI;
-  MCC_MNC_TO_PLMNID(
-    s1ap_eNB_instance_p->mcc[ue_context_p->selected_plmn_identity],
-    s1ap_eNB_instance_p->mnc[ue_context_p->selected_plmn_identity],
-    s1ap_eNB_instance_p->mnc_digit_length[ue_context_p->selected_plmn_identity],
-    &ie->value.choice.TAI.pLMNidentity);
-  TAC_TO_ASN1(s1ap_eNB_instance_p->tac, &ie->value.choice.TAI.tAC);
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    /* optional */
+#if (S1AP_VERSION >= MAKE_VERSION(14, 0, 0))
 
-  /* optional */
-#if (S1AP_VERSION >= MAKE_VERSION(10, 0, 0))
-  if (0) {
-    ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_GW_TransportLayerAddress;
-    ie->criticality = S1AP_Criticality_ignore;
-    ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_TransportLayerAddress;
-    // ie->value.choice.TransportLayerAddress = ;
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
+    if (0) {
+        ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_SIPTO_L_GW_TransportLayerAddress;
+        ie->criticality = S1AP_Criticality_ignore;
+        ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_TransportLayerAddress;
+        // ie->value.choice.TransportLayerAddress = ;
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    }
 
-  /* optional */
-#if (S1AP_VERSION >= MAKE_VERSION(14, 0, 0))
-  if (0) {
-    ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_SIPTO_L_GW_TransportLayerAddress;
-    ie->criticality = S1AP_Criticality_ignore;
-    ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_TransportLayerAddress;
-    // ie->value.choice.TransportLayerAddress = ;
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
+    /* optional */
+    if (0) {
+        ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_LHN_ID;
+        ie->criticality = S1AP_Criticality_ignore;
+        ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_LHN_ID;
+        // ie->value.choice.LHN_ID =;
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    }
 
-  /* optional */
-  if (0) {
-    ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_LHN_ID;
-    ie->criticality = S1AP_Criticality_ignore;
-    ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_LHN_ID;
-    // ie->value.choice.LHN_ID =;
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
 #endif /* #if (S1AP_VERSION >= MAKE_VERSION(14, 0, 0)) */
 #endif /* #if (S1AP_VERSION >= MAKE_VERSION(10, 0, 0)) */
 
-  if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) {
-    S1AP_ERROR("Failed to encode uplink NAS transport\n");
-    /* Encode procedure has failed... */
-    return -1;
-  }
-
-  MSC_LOG_TX_MESSAGE(
-    MSC_S1AP_ENB,
-    MSC_S1AP_MME,
-    (const char *)NULL,
-    0,
-    MSC_AS_TIME_FMT" uplinkNASTransport initiatingMessage eNB_ue_s1ap_id %u mme_ue_s1ap_id %u",
-    0,0,//MSC_AS_TIME_ARGS(ctxt_pP),
-    ue_context_p->eNB_ue_s1ap_id,
-    ue_context_p->mme_ue_s1ap_id);
-
-  /* UE associated signalling -> use the allocated stream */
-  s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance,
-                                   ue_context_p->mme_ref->assoc_id, buffer,
-                                   length, ue_context_p->tx_stream);
+    if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) {
+        S1AP_ERROR("Failed to encode uplink NAS transport\n");
+        /* Encode procedure has failed... */
+        return -1;
+    }
 
-  return 0;
+    MSC_LOG_TX_MESSAGE(
+        MSC_S1AP_ENB,
+        MSC_S1AP_MME,
+        (const char *)NULL,
+        0,
+        MSC_AS_TIME_FMT" uplinkNASTransport initiatingMessage eNB_ue_s1ap_id %u mme_ue_s1ap_id %u",
+        0,0,//MSC_AS_TIME_ARGS(ctxt_pP),
+        ue_context_p->eNB_ue_s1ap_id,
+        ue_context_p->mme_ue_s1ap_id);
+    /* UE associated signalling -> use the allocated stream */
+    s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance,
+                                     ue_context_p->mme_ref->assoc_id, buffer,
+                                     length, ue_context_p->tx_stream);
+    return 0;
 }
 
 
@@ -741,275 +733,264 @@ int s1ap_eNB_nas_non_delivery_ind(instance_t instance,
                                   s1ap_nas_non_delivery_ind_t *s1ap_nas_non_delivery_ind)
 //------------------------------------------------------------------------------
 {
-  struct s1ap_eNB_ue_context_s        *ue_context_p;
-  s1ap_eNB_instance_t                 *s1ap_eNB_instance_p;
-  S1AP_S1AP_PDU_t                      pdu;
-  S1AP_NASNonDeliveryIndication_t     *out;
-  S1AP_NASNonDeliveryIndication_IEs_t *ie;
-  uint8_t  *buffer;
-  uint32_t  length;
-
-  DevAssert(s1ap_nas_non_delivery_ind != NULL);
-
-  /* Retrieve the S1AP eNB instance associated with Mod_id */
-  s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance);
-  DevAssert(s1ap_eNB_instance_p != NULL);
-
-  if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, s1ap_nas_non_delivery_ind->eNB_ue_s1ap_id)) == NULL) {
-    /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */
-    S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: %06x\n",
-              s1ap_nas_non_delivery_ind->eNB_ue_s1ap_id);
-    MSC_LOG_EVENT(
-      MSC_S1AP_ENB,
-      MSC_AS_TIME_FMT" Sent of NAS_NON_DELIVERY_IND to MME failed, no context for eNB_ue_s1ap_id %06x",
-      s1ap_nas_non_delivery_ind->eNB_ue_s1ap_id);
-    return -1;
-  }
-
-  /* Prepare the S1AP message to encode */
-  memset(&pdu, 0, sizeof(pdu));
-  pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage;
-  pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_NASNonDeliveryIndication;
-  pdu.choice.initiatingMessage.criticality = S1AP_Criticality_ignore;
-  pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_NASNonDeliveryIndication;
-  out = &pdu.choice.initiatingMessage.value.choice.NASNonDeliveryIndication;
-
-  /* mandatory */
-  ie = (S1AP_NASNonDeliveryIndication_IEs_t *)calloc(1, sizeof(S1AP_NASNonDeliveryIndication_IEs_t));
-  ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID;
-  ie->criticality = S1AP_Criticality_reject;
-  ie->value.present = S1AP_NASNonDeliveryIndication_IEs__value_PR_MME_UE_S1AP_ID;
-  ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
-  /* mandatory */
-  ie = (S1AP_NASNonDeliveryIndication_IEs_t *)calloc(1, sizeof(S1AP_NASNonDeliveryIndication_IEs_t));
-  ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID;
-  ie->criticality = S1AP_Criticality_reject;
-  ie->value.present = S1AP_NASNonDeliveryIndication_IEs__value_PR_ENB_UE_S1AP_ID;
-  ie->value.choice.ENB_UE_S1AP_ID = ue_context_p->eNB_ue_s1ap_id;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
-  /* mandatory */
-  ie = (S1AP_NASNonDeliveryIndication_IEs_t *)calloc(1, sizeof(S1AP_NASNonDeliveryIndication_IEs_t));
-  ie->id = S1AP_ProtocolIE_ID_id_NAS_PDU;
-  ie->criticality = S1AP_Criticality_ignore;
-  ie->value.present = S1AP_NASNonDeliveryIndication_IEs__value_PR_NAS_PDU;
-  ie->value.choice.NAS_PDU.buf = s1ap_nas_non_delivery_ind->nas_pdu.buffer;
-  ie->value.choice.NAS_PDU.size = s1ap_nas_non_delivery_ind->nas_pdu.length;
-
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
-  /* mandatory */
-  ie = (S1AP_NASNonDeliveryIndication_IEs_t *)calloc(1, sizeof(S1AP_NASNonDeliveryIndication_IEs_t));
-  ie->id = S1AP_ProtocolIE_ID_id_Cause;
-  ie->criticality = S1AP_Criticality_ignore;
-  /* Send a dummy cause */
-  ie->value.present = S1AP_NASNonDeliveryIndication_IEs__value_PR_Cause;
-  ie->value.choice.Cause.present = S1AP_Cause_PR_radioNetwork;
-  ie->value.choice.Cause.choice.radioNetwork = S1AP_CauseRadioNetwork_radio_connection_with_ue_lost;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    struct s1ap_eNB_ue_context_s        *ue_context_p;
+    s1ap_eNB_instance_t                 *s1ap_eNB_instance_p;
+    S1AP_S1AP_PDU_t                      pdu;
+    S1AP_NASNonDeliveryIndication_t     *out;
+    S1AP_NASNonDeliveryIndication_IEs_t *ie;
+    uint8_t  *buffer;
+    uint32_t  length;
+    DevAssert(s1ap_nas_non_delivery_ind != NULL);
+    /* Retrieve the S1AP eNB instance associated with Mod_id */
+    s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance);
+    DevAssert(s1ap_eNB_instance_p != NULL);
+
+    if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, s1ap_nas_non_delivery_ind->eNB_ue_s1ap_id)) == NULL) {
+        /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */
+        S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: %06x\n",
+                  s1ap_nas_non_delivery_ind->eNB_ue_s1ap_id);
+        MSC_LOG_EVENT(
+            MSC_S1AP_ENB,
+            MSC_AS_TIME_FMT" Sent of NAS_NON_DELIVERY_IND to MME failed, no context for eNB_ue_s1ap_id %06x",
+            s1ap_nas_non_delivery_ind->eNB_ue_s1ap_id);
+        return -1;
+    }
 
-  if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) {
-    S1AP_ERROR("Failed to encode NAS NON delivery indication\n");
-    /* Encode procedure has failed... */
-    MSC_LOG_EVENT(
-      MSC_S1AP_ENB,
-      MSC_AS_TIME_FMT" Sent of NAS_NON_DELIVERY_IND to MME failed (encoding)");
-    return -1;
-  }
+    /* Prepare the S1AP message to encode */
+    memset(&pdu, 0, sizeof(pdu));
+    pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage;
+    pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_NASNonDeliveryIndication;
+    pdu.choice.initiatingMessage.criticality = S1AP_Criticality_ignore;
+    pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_NASNonDeliveryIndication;
+    out = &pdu.choice.initiatingMessage.value.choice.NASNonDeliveryIndication;
+    /* mandatory */
+    ie = (S1AP_NASNonDeliveryIndication_IEs_t *)calloc(1, sizeof(S1AP_NASNonDeliveryIndication_IEs_t));
+    ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID;
+    ie->criticality = S1AP_Criticality_reject;
+    ie->value.present = S1AP_NASNonDeliveryIndication_IEs__value_PR_MME_UE_S1AP_ID;
+    ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id;
+    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    /* mandatory */
+    ie = (S1AP_NASNonDeliveryIndication_IEs_t *)calloc(1, sizeof(S1AP_NASNonDeliveryIndication_IEs_t));
+    ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID;
+    ie->criticality = S1AP_Criticality_reject;
+    ie->value.present = S1AP_NASNonDeliveryIndication_IEs__value_PR_ENB_UE_S1AP_ID;
+    ie->value.choice.ENB_UE_S1AP_ID = ue_context_p->eNB_ue_s1ap_id;
+    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    /* mandatory */
+    ie = (S1AP_NASNonDeliveryIndication_IEs_t *)calloc(1, sizeof(S1AP_NASNonDeliveryIndication_IEs_t));
+    ie->id = S1AP_ProtocolIE_ID_id_NAS_PDU;
+    ie->criticality = S1AP_Criticality_ignore;
+    ie->value.present = S1AP_NASNonDeliveryIndication_IEs__value_PR_NAS_PDU;
+    ie->value.choice.NAS_PDU.buf = s1ap_nas_non_delivery_ind->nas_pdu.buffer;
+    ie->value.choice.NAS_PDU.size = s1ap_nas_non_delivery_ind->nas_pdu.length;
+    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    /* mandatory */
+    ie = (S1AP_NASNonDeliveryIndication_IEs_t *)calloc(1, sizeof(S1AP_NASNonDeliveryIndication_IEs_t));
+    ie->id = S1AP_ProtocolIE_ID_id_Cause;
+    ie->criticality = S1AP_Criticality_ignore;
+    /* Send a dummy cause */
+    ie->value.present = S1AP_NASNonDeliveryIndication_IEs__value_PR_Cause;
+    ie->value.choice.Cause.present = S1AP_Cause_PR_radioNetwork;
+    ie->value.choice.Cause.choice.radioNetwork = S1AP_CauseRadioNetwork_radio_connection_with_ue_lost;
+    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
 
-  MSC_LOG_TX_MESSAGE(
-    MSC_S1AP_ENB,
-    MSC_S1AP_MME,
-    (const char *)buffer,
-    length,
-    MSC_AS_TIME_FMT" NASNonDeliveryIndication initiatingMessage eNB_ue_s1ap_id %u mme_ue_s1ap_id %u",
-    0,0,//MSC_AS_TIME_ARGS(ctxt_pP),
-    ue_context_p->eNB_ue_s1ap_id,
-    ue_context_p->mme_ue_s1ap_id);
+    if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) {
+        S1AP_ERROR("Failed to encode NAS NON delivery indication\n");
+        /* Encode procedure has failed... */
+        MSC_LOG_EVENT(
+            MSC_S1AP_ENB,
+            MSC_AS_TIME_FMT" Sent of NAS_NON_DELIVERY_IND to MME failed (encoding)");
+        return -1;
+    }
 
-  /* UE associated signalling -> use the allocated stream */
-  s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance,
-                                   ue_context_p->mme_ref->assoc_id, buffer,
-                                   length, ue_context_p->tx_stream);
-  return 0;
+    MSC_LOG_TX_MESSAGE(
+        MSC_S1AP_ENB,
+        MSC_S1AP_MME,
+        (const char *)buffer,
+        length,
+        MSC_AS_TIME_FMT" NASNonDeliveryIndication initiatingMessage eNB_ue_s1ap_id %u mme_ue_s1ap_id %u",
+        0,0,//MSC_AS_TIME_ARGS(ctxt_pP),
+        ue_context_p->eNB_ue_s1ap_id,
+        ue_context_p->mme_ue_s1ap_id);
+    /* UE associated signalling -> use the allocated stream */
+    s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance,
+                                     ue_context_p->mme_ref->assoc_id, buffer,
+                                     length, ue_context_p->tx_stream);
+    return 0;
 }
 
 //------------------------------------------------------------------------------
 int s1ap_eNB_initial_ctxt_resp(
-  instance_t instance, s1ap_initial_context_setup_resp_t *initial_ctxt_resp_p)
+    instance_t instance, s1ap_initial_context_setup_resp_t *initial_ctxt_resp_p)
 //------------------------------------------------------------------------------
 {
-  s1ap_eNB_instance_t                   *s1ap_eNB_instance_p = NULL;
-  struct s1ap_eNB_ue_context_s          *ue_context_p        = NULL;
-  S1AP_S1AP_PDU_t                        pdu;
-  S1AP_InitialContextSetupResponse_t    *out;
-  S1AP_InitialContextSetupResponseIEs_t *ie;
-  uint8_t  *buffer = NULL;
-  uint32_t length;
-  int      i;
-
-  /* Retrieve the S1AP eNB instance associated with Mod_id */
-  s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance);
-
-  DevAssert(initial_ctxt_resp_p != NULL);
-  DevAssert(s1ap_eNB_instance_p != NULL);
-
-  if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p,
-                      initial_ctxt_resp_p->eNB_ue_s1ap_id)) == NULL) {
-    /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */
-    S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: 0x%06x\n",
-              initial_ctxt_resp_p->eNB_ue_s1ap_id);
-    return -1;
-  }
-
-  /* Uplink NAS transport can occur either during an s1ap connected state
-   * or during initial attach (for example: NAS authentication).
-   */
-  if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED ||
-        ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) {
-    S1AP_WARN("You are attempting to send NAS data over non-connected "
-              "eNB ue s1ap id: %06x, current state: %d\n",
-              initial_ctxt_resp_p->eNB_ue_s1ap_id, ue_context_p->ue_state);
-    return -1;
-  }
-
-  /* Prepare the S1AP message to encode */
-  memset(&pdu, 0, sizeof(pdu));
-  pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome;
-  pdu.choice.successfulOutcome.procedureCode = S1AP_ProcedureCode_id_InitialContextSetup;
-  pdu.choice.successfulOutcome.criticality = S1AP_Criticality_reject;
-  pdu.choice.successfulOutcome.value.present = S1AP_SuccessfulOutcome__value_PR_InitialContextSetupResponse;
-  out = &pdu.choice.successfulOutcome.value.choice.InitialContextSetupResponse;
-
-  /* mandatory */
-  ie = (S1AP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(S1AP_InitialContextSetupResponseIEs_t));
-  ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID;
-  ie->criticality = S1AP_Criticality_ignore;
-  ie->value.present = S1AP_InitialContextSetupResponseIEs__value_PR_MME_UE_S1AP_ID;
-  ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
-  /* mandatory */
-  ie = (S1AP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(S1AP_InitialContextSetupResponseIEs_t));
-  ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID;
-  ie->criticality = S1AP_Criticality_ignore;
-  ie->value.present = S1AP_InitialContextSetupResponseIEs__value_PR_ENB_UE_S1AP_ID;
-  ie->value.choice.ENB_UE_S1AP_ID = initial_ctxt_resp_p->eNB_ue_s1ap_id;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    s1ap_eNB_instance_t                   *s1ap_eNB_instance_p = NULL;
+    struct s1ap_eNB_ue_context_s          *ue_context_p        = NULL;
+    S1AP_S1AP_PDU_t                        pdu;
+    S1AP_InitialContextSetupResponse_t    *out;
+    S1AP_InitialContextSetupResponseIEs_t *ie;
+    uint8_t  *buffer = NULL;
+    uint32_t length;
+    int      i;
+    /* Retrieve the S1AP eNB instance associated with Mod_id */
+    s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance);
+    DevAssert(initial_ctxt_resp_p != NULL);
+    DevAssert(s1ap_eNB_instance_p != NULL);
+
+    if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p,
+                        initial_ctxt_resp_p->eNB_ue_s1ap_id)) == NULL) {
+        /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */
+        S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: 0x%06x\n",
+                  initial_ctxt_resp_p->eNB_ue_s1ap_id);
+        return -1;
+    }
 
-  /* mandatory */
-  ie = (S1AP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(S1AP_InitialContextSetupResponseIEs_t));
-  ie->id = S1AP_ProtocolIE_ID_id_E_RABSetupListCtxtSURes;
-  ie->criticality = S1AP_Criticality_ignore;
-  ie->value.present = S1AP_InitialContextSetupResponseIEs__value_PR_E_RABSetupListCtxtSURes;
+    /* Uplink NAS transport can occur either during an s1ap connected state
+     * or during initial attach (for example: NAS authentication).
+     */
+    if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED ||
+            ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) {
+        S1AP_WARN("You are attempting to send NAS data over non-connected "
+                  "eNB ue s1ap id: %06x, current state: %d\n",
+                  initial_ctxt_resp_p->eNB_ue_s1ap_id, ue_context_p->ue_state);
+        return -1;
+    }
 
-  for (i = 0; i < initial_ctxt_resp_p->nb_of_e_rabs; i++) {
-    S1AP_E_RABSetupItemCtxtSUResIEs_t *item;
+    /* Prepare the S1AP message to encode */
+    memset(&pdu, 0, sizeof(pdu));
+    pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome;
+    pdu.choice.successfulOutcome.procedureCode = S1AP_ProcedureCode_id_InitialContextSetup;
+    pdu.choice.successfulOutcome.criticality = S1AP_Criticality_reject;
+    pdu.choice.successfulOutcome.value.present = S1AP_SuccessfulOutcome__value_PR_InitialContextSetupResponse;
+    out = &pdu.choice.successfulOutcome.value.choice.InitialContextSetupResponse;
     /* mandatory */
-    item = (S1AP_E_RABSetupItemCtxtSUResIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupItemCtxtSUResIEs_t));
-    item->id = S1AP_ProtocolIE_ID_id_E_RABSetupItemCtxtSURes;
-    item->criticality = S1AP_Criticality_ignore;
-    item->value.present = S1AP_E_RABSetupItemCtxtSUResIEs__value_PR_E_RABSetupItemCtxtSURes;
-    item->value.choice.E_RABSetupItemCtxtSURes.e_RAB_ID = initial_ctxt_resp_p->e_rabs[i].e_rab_id;
-    GTP_TEID_TO_ASN1(initial_ctxt_resp_p->e_rabs[i].gtp_teid, &item->value.choice.E_RABSetupItemCtxtSURes.gTP_TEID);
-    item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf = malloc(initial_ctxt_resp_p->e_rabs[i].eNB_addr.length);
-    memcpy(item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf, 
-           initial_ctxt_resp_p->e_rabs[i].eNB_addr.buffer,
-           initial_ctxt_resp_p->e_rabs[i].eNB_addr.length);
-    item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.size = initial_ctxt_resp_p->e_rabs[i].eNB_addr.length;
-    item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.bits_unused = 0;
-    S1AP_DEBUG("initial_ctxt_resp_p: e_rab ID %ld, enb_addr %d.%d.%d.%d, SIZE %ld \n",
-               item->value.choice.E_RABSetupItemCtxtSURes.e_RAB_ID,
-               item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf[0],
-               item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf[1],
-               item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf[2],
-               item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf[3],
-               item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.size);
-    ASN_SEQUENCE_ADD(&ie->value.choice.E_RABSetupListCtxtSURes.list, item);
-  }
-
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
-  /* optional */
-  if (initial_ctxt_resp_p->nb_of_e_rabs_failed) {
     ie = (S1AP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(S1AP_InitialContextSetupResponseIEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_E_RABFailedToSetupListCtxtSURes;
+    ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID;
     ie->criticality = S1AP_Criticality_ignore;
-    ie->value.present = S1AP_InitialContextSetupResponseIEs__value_PR_E_RABList;
-
-    for (i = 0; i < initial_ctxt_resp_p->nb_of_e_rabs_failed; i++) {
-      S1AP_E_RABItemIEs_t *item;
-      /* mandatory */
-      item = (S1AP_E_RABItemIEs_t *)calloc(1, sizeof(S1AP_E_RABItemIEs_t));
-      item->id = S1AP_ProtocolIE_ID_id_E_RABItem;
-      item->criticality = S1AP_Criticality_ignore;
-      item->value.present = S1AP_E_RABItemIEs__value_PR_E_RABItem;
-      item->value.choice.E_RABItem.e_RAB_ID = initial_ctxt_resp_p->e_rabs_failed[i].e_rab_id;
-      item->value.choice.E_RABItem.cause.present = initial_ctxt_resp_p->e_rabs_failed[i].cause;
-
-      switch(item->value.choice.E_RABItem.cause.present)
-      {
-        case S1AP_Cause_PR_radioNetwork:
-          item->value.choice.E_RABItem.cause.choice.radioNetwork = initial_ctxt_resp_p->e_rabs_failed[i].cause_value;
-          break;
-        case S1AP_Cause_PR_transport:
-          item->value.choice.E_RABItem.cause.choice.transport = initial_ctxt_resp_p->e_rabs_failed[i].cause_value;
-          break;
-        case S1AP_Cause_PR_nas:
-          item->value.choice.E_RABItem.cause.choice.nas = initial_ctxt_resp_p->e_rabs_failed[i].cause_value;
-          break;
-        case S1AP_Cause_PR_protocol:
-          item->value.choice.E_RABItem.cause.choice.protocol = initial_ctxt_resp_p->e_rabs_failed[i].cause_value;
-          break;
-        case S1AP_Cause_PR_misc:
-          item->value.choice.E_RABItem.cause.choice.misc = initial_ctxt_resp_p->e_rabs_failed[i].cause_value;
-          break;
-        case S1AP_Cause_PR_NOTHING:
-        default:
-          break;
-      }
-
-      S1AP_DEBUG("initial context setup response: failed e_rab ID %ld\n", item->value.choice.E_RABItem.e_RAB_ID);
-      ASN_SEQUENCE_ADD(&ie->value.choice.E_RABList.list, item);
-    }
-
+    ie->value.present = S1AP_InitialContextSetupResponseIEs__value_PR_MME_UE_S1AP_ID;
+    ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id;
     ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
-
-  /* optional */
-  if (0) {
+    /* mandatory */
     ie = (S1AP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(S1AP_InitialContextSetupResponseIEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_CriticalityDiagnostics;
+    ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID;
     ie->criticality = S1AP_Criticality_ignore;
-    ie->value.present = S1AP_InitialContextSetupResponseIEs__value_PR_CriticalityDiagnostics;
-    // ie->value.choice.CriticalityDiagnostics =;
+    ie->value.present = S1AP_InitialContextSetupResponseIEs__value_PR_ENB_UE_S1AP_ID;
+    ie->value.choice.ENB_UE_S1AP_ID = initial_ctxt_resp_p->eNB_ue_s1ap_id;
     ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
+    /* mandatory */
+    ie = (S1AP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(S1AP_InitialContextSetupResponseIEs_t));
+    ie->id = S1AP_ProtocolIE_ID_id_E_RABSetupListCtxtSURes;
+    ie->criticality = S1AP_Criticality_ignore;
+    ie->value.present = S1AP_InitialContextSetupResponseIEs__value_PR_E_RABSetupListCtxtSURes;
+
+    for (i = 0; i < initial_ctxt_resp_p->nb_of_e_rabs; i++) {
+        S1AP_E_RABSetupItemCtxtSUResIEs_t *item;
+        /* mandatory */
+        item = (S1AP_E_RABSetupItemCtxtSUResIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupItemCtxtSUResIEs_t));
+        item->id = S1AP_ProtocolIE_ID_id_E_RABSetupItemCtxtSURes;
+        item->criticality = S1AP_Criticality_ignore;
+        item->value.present = S1AP_E_RABSetupItemCtxtSUResIEs__value_PR_E_RABSetupItemCtxtSURes;
+        item->value.choice.E_RABSetupItemCtxtSURes.e_RAB_ID = initial_ctxt_resp_p->e_rabs[i].e_rab_id;
+        GTP_TEID_TO_ASN1(initial_ctxt_resp_p->e_rabs[i].gtp_teid, &item->value.choice.E_RABSetupItemCtxtSURes.gTP_TEID);
+        item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf = malloc(initial_ctxt_resp_p->e_rabs[i].eNB_addr.length);
+        memcpy(item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf,
+               initial_ctxt_resp_p->e_rabs[i].eNB_addr.buffer,
+               initial_ctxt_resp_p->e_rabs[i].eNB_addr.length);
+        item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.size = initial_ctxt_resp_p->e_rabs[i].eNB_addr.length;
+        item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.bits_unused = 0;
+        S1AP_DEBUG("initial_ctxt_resp_p: e_rab ID %ld, enb_addr %d.%d.%d.%d, SIZE %ld \n",
+                   item->value.choice.E_RABSetupItemCtxtSURes.e_RAB_ID,
+                   item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf[0],
+                   item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf[1],
+                   item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf[2],
+                   item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf[3],
+                   item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.size);
+        ASN_SEQUENCE_ADD(&ie->value.choice.E_RABSetupListCtxtSURes.list, item);
+    }
 
-  if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) {
-    S1AP_ERROR("Failed to encode uplink NAS transport\n");
-    /* Encode procedure has failed... */
-    return -1;
-  }
+    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
 
-  MSC_LOG_TX_MESSAGE(
-    MSC_S1AP_ENB,
-    MSC_S1AP_MME,
-    (const char *)buffer,
-    length,
-    MSC_AS_TIME_FMT" InitialContextSetup successfulOutcome eNB_ue_s1ap_id %u mme_ue_s1ap_id %u",
-    0,0,//MSC_AS_TIME_ARGS(ctxt_pP),
-    initial_ctxt_resp_p->eNB_ue_s1ap_id,
-    ue_context_p->mme_ue_s1ap_id);
+    /* optional */
+    if (initial_ctxt_resp_p->nb_of_e_rabs_failed) {
+        ie = (S1AP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(S1AP_InitialContextSetupResponseIEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_E_RABFailedToSetupListCtxtSURes;
+        ie->criticality = S1AP_Criticality_ignore;
+        ie->value.present = S1AP_InitialContextSetupResponseIEs__value_PR_E_RABList;
+
+        for (i = 0; i < initial_ctxt_resp_p->nb_of_e_rabs_failed; i++) {
+            S1AP_E_RABItemIEs_t *item;
+            /* mandatory */
+            item = (S1AP_E_RABItemIEs_t *)calloc(1, sizeof(S1AP_E_RABItemIEs_t));
+            item->id = S1AP_ProtocolIE_ID_id_E_RABItem;
+            item->criticality = S1AP_Criticality_ignore;
+            item->value.present = S1AP_E_RABItemIEs__value_PR_E_RABItem;
+            item->value.choice.E_RABItem.e_RAB_ID = initial_ctxt_resp_p->e_rabs_failed[i].e_rab_id;
+            item->value.choice.E_RABItem.cause.present = initial_ctxt_resp_p->e_rabs_failed[i].cause;
+
+            switch(item->value.choice.E_RABItem.cause.present) {
+            case S1AP_Cause_PR_radioNetwork:
+                item->value.choice.E_RABItem.cause.choice.radioNetwork = initial_ctxt_resp_p->e_rabs_failed[i].cause_value;
+                break;
+
+            case S1AP_Cause_PR_transport:
+                item->value.choice.E_RABItem.cause.choice.transport = initial_ctxt_resp_p->e_rabs_failed[i].cause_value;
+                break;
+
+            case S1AP_Cause_PR_nas:
+                item->value.choice.E_RABItem.cause.choice.nas = initial_ctxt_resp_p->e_rabs_failed[i].cause_value;
+                break;
+
+            case S1AP_Cause_PR_protocol:
+                item->value.choice.E_RABItem.cause.choice.protocol = initial_ctxt_resp_p->e_rabs_failed[i].cause_value;
+                break;
+
+            case S1AP_Cause_PR_misc:
+                item->value.choice.E_RABItem.cause.choice.misc = initial_ctxt_resp_p->e_rabs_failed[i].cause_value;
+                break;
+
+            case S1AP_Cause_PR_NOTHING:
+            default:
+                break;
+            }
+
+            S1AP_DEBUG("initial context setup response: failed e_rab ID %ld\n", item->value.choice.E_RABItem.e_RAB_ID);
+            ASN_SEQUENCE_ADD(&ie->value.choice.E_RABList.list, item);
+        }
+
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    }
 
-  /* UE associated signalling -> use the allocated stream */
-  s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance,
-                                   ue_context_p->mme_ref->assoc_id, buffer,
-                                   length, ue_context_p->tx_stream);
+    /* optional */
+    if (0) {
+        ie = (S1AP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(S1AP_InitialContextSetupResponseIEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_CriticalityDiagnostics;
+        ie->criticality = S1AP_Criticality_ignore;
+        ie->value.present = S1AP_InitialContextSetupResponseIEs__value_PR_CriticalityDiagnostics;
+        // ie->value.choice.CriticalityDiagnostics =;
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    }
 
-  return 0;
+    if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) {
+        S1AP_ERROR("Failed to encode uplink NAS transport\n");
+        /* Encode procedure has failed... */
+        return -1;
+    }
+
+    MSC_LOG_TX_MESSAGE(
+        MSC_S1AP_ENB,
+        MSC_S1AP_MME,
+        (const char *)buffer,
+        length,
+        MSC_AS_TIME_FMT" InitialContextSetup successfulOutcome eNB_ue_s1ap_id %u mme_ue_s1ap_id %u",
+        0,0,//MSC_AS_TIME_ARGS(ctxt_pP),
+        initial_ctxt_resp_p->eNB_ue_s1ap_id,
+        ue_context_p->mme_ue_s1ap_id);
+    /* UE associated signalling -> use the allocated stream */
+    s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance,
+                                     ue_context_p->mme_ref->assoc_id, buffer,
+                                     length, ue_context_p->tx_stream);
+    return 0;
 }
 
 //------------------------------------------------------------------------------
@@ -1017,291 +998,284 @@ int s1ap_eNB_ue_capabilities(instance_t instance,
                              s1ap_ue_cap_info_ind_t *ue_cap_info_ind_p)
 //------------------------------------------------------------------------------
 {
-  s1ap_eNB_instance_t          *s1ap_eNB_instance_p;
-  struct s1ap_eNB_ue_context_s *ue_context_p;
-  S1AP_S1AP_PDU_t                       pdu;
-  S1AP_UECapabilityInfoIndication_t    *out;
-  S1AP_UECapabilityInfoIndicationIEs_t *ie;
-  uint8_t  *buffer;
-  uint32_t length;
-
-  /* Retrieve the S1AP eNB instance associated with Mod_id */
-  s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance);
-
-  DevAssert(ue_cap_info_ind_p != NULL);
-  DevAssert(s1ap_eNB_instance_p != NULL);
-
-  if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p,
-                      ue_cap_info_ind_p->eNB_ue_s1ap_id)) == NULL) {
-    /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */
-    S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: %u\n",
-              ue_cap_info_ind_p->eNB_ue_s1ap_id);
-    return -1;
-  }
-
-  /* UE capabilities message can occur either during an s1ap connected state
-   * or during initial attach (for example: NAS authentication).
-   */
-  if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED ||
-        ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) {
-    S1AP_WARN("You are attempting to send NAS data over non-connected "
-              "eNB ue s1ap id: %u, current state: %d\n",
-              ue_cap_info_ind_p->eNB_ue_s1ap_id, ue_context_p->ue_state);
-    return -1;
-  }
-
-  /* Prepare the S1AP message to encode */
-  memset(&pdu, 0, sizeof(pdu));
-  pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage;
-  pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_UECapabilityInfoIndication;
-  pdu.choice.initiatingMessage.criticality = S1AP_Criticality_ignore;
-  pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_UECapabilityInfoIndication;
-  out = &pdu.choice.initiatingMessage.value.choice.UECapabilityInfoIndication;
-
-  /* mandatory */
-  ie = (S1AP_UECapabilityInfoIndicationIEs_t *)calloc(1, sizeof(S1AP_UECapabilityInfoIndicationIEs_t));
-  ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID;
-  ie->criticality = S1AP_Criticality_reject;
-  ie->value.present = S1AP_UECapabilityInfoIndicationIEs__value_PR_MME_UE_S1AP_ID;
-  ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
-  /* mandatory */
-  ie = (S1AP_UECapabilityInfoIndicationIEs_t *)calloc(1, sizeof(S1AP_UECapabilityInfoIndicationIEs_t));
-  ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID;
-  ie->criticality = S1AP_Criticality_reject;
-  ie->value.present = S1AP_UECapabilityInfoIndicationIEs__value_PR_ENB_UE_S1AP_ID;
-  ie->value.choice.ENB_UE_S1AP_ID = ue_cap_info_ind_p->eNB_ue_s1ap_id;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    s1ap_eNB_instance_t          *s1ap_eNB_instance_p;
+    struct s1ap_eNB_ue_context_s *ue_context_p;
+    S1AP_S1AP_PDU_t                       pdu;
+    S1AP_UECapabilityInfoIndication_t    *out;
+    S1AP_UECapabilityInfoIndicationIEs_t *ie;
+    uint8_t  *buffer;
+    uint32_t length;
+    /* Retrieve the S1AP eNB instance associated with Mod_id */
+    s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance);
+    DevAssert(ue_cap_info_ind_p != NULL);
+    DevAssert(s1ap_eNB_instance_p != NULL);
+
+    if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p,
+                        ue_cap_info_ind_p->eNB_ue_s1ap_id)) == NULL) {
+        /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */
+        S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: %u\n",
+                  ue_cap_info_ind_p->eNB_ue_s1ap_id);
+        return -1;
+    }
 
-  /* mandatory */
-  ie = (S1AP_UECapabilityInfoIndicationIEs_t *)calloc(1, sizeof(S1AP_UECapabilityInfoIndicationIEs_t));
-  ie->id = S1AP_ProtocolIE_ID_id_UERadioCapability;
-  ie->criticality = S1AP_Criticality_reject;
-  ie->value.present = S1AP_UECapabilityInfoIndicationIEs__value_PR_UERadioCapability;
-  ie->value.choice.UERadioCapability.buf = ue_cap_info_ind_p->ue_radio_cap.buffer;
-  ie->value.choice.UERadioCapability.size = ue_cap_info_ind_p->ue_radio_cap.length;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    /* UE capabilities message can occur either during an s1ap connected state
+     * or during initial attach (for example: NAS authentication).
+     */
+    if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED ||
+            ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) {
+        S1AP_WARN("You are attempting to send NAS data over non-connected "
+                  "eNB ue s1ap id: %u, current state: %d\n",
+                  ue_cap_info_ind_p->eNB_ue_s1ap_id, ue_context_p->ue_state);
+        return -1;
+    }
 
-  /* optional */
-#if (S1AP_VERSION >= MAKE_VERSION(12, 0, 0))
-  if (0) {
+    /* Prepare the S1AP message to encode */
+    memset(&pdu, 0, sizeof(pdu));
+    pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage;
+    pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_UECapabilityInfoIndication;
+    pdu.choice.initiatingMessage.criticality = S1AP_Criticality_ignore;
+    pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_UECapabilityInfoIndication;
+    out = &pdu.choice.initiatingMessage.value.choice.UECapabilityInfoIndication;
+    /* mandatory */
     ie = (S1AP_UECapabilityInfoIndicationIEs_t *)calloc(1, sizeof(S1AP_UECapabilityInfoIndicationIEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_UERadioCapabilityForPaging;
-    ie->criticality = S1AP_Criticality_ignore;
-    ie->value.present = S1AP_UECapabilityInfoIndicationIEs__value_PR_UERadioCapabilityForPaging;
-    // ie->value.choice.UERadioCapabilityForPaging = ;
+    ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID;
+    ie->criticality = S1AP_Criticality_reject;
+    ie->value.present = S1AP_UECapabilityInfoIndicationIEs__value_PR_MME_UE_S1AP_ID;
+    ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id;
     ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
-#endif /* #if (S1AP_VERSION >= MAKE_VERSION(14, 0, 0)) */
-
-  if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) {
-    /* Encode procedure has failed... */
-    S1AP_ERROR("Failed to encode UE capabilities indication\n");
-    return -1;
-  }
-
-  MSC_LOG_TX_MESSAGE(
-    MSC_S1AP_ENB,
-    MSC_S1AP_MME,
-    (const char *)buffer,
-    length,
-    MSC_AS_TIME_FMT" UECapabilityInfoIndication initiatingMessage eNB_ue_s1ap_id %u mme_ue_s1ap_id %u",
-    0,0,//MSC_AS_TIME_ARGS(ctxt_pP),
-    ue_cap_info_ind_p->eNB_ue_s1ap_id,
-    ue_context_p->mme_ue_s1ap_id);
-
-  /* UE associated signalling -> use the allocated stream */
-  s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance,
-                                   ue_context_p->mme_ref->assoc_id, buffer,
-                                   length, ue_context_p->tx_stream);
-
-  return 0;
-}
-
-//------------------------------------------------------------------------------
-int s1ap_eNB_e_rab_setup_resp(instance_t instance,
-                              s1ap_e_rab_setup_resp_t *e_rab_setup_resp_p)
-//------------------------------------------------------------------------------
-{
-  s1ap_eNB_instance_t          *s1ap_eNB_instance_p = NULL;
-  struct s1ap_eNB_ue_context_s *ue_context_p        = NULL;
-  S1AP_S1AP_PDU_t               pdu;
-  S1AP_E_RABSetupResponse_t    *out;
-  S1AP_E_RABSetupResponseIEs_t *ie;
-  uint8_t  *buffer  = NULL;
-  uint32_t length;
-  int      i;
-
-  /* Retrieve the S1AP eNB instance associated with Mod_id */
-  s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance);
-
-  DevAssert(e_rab_setup_resp_p != NULL);
-  DevAssert(s1ap_eNB_instance_p != NULL);
-
-  if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p,
-                                              e_rab_setup_resp_p->eNB_ue_s1ap_id)) == NULL) {
-    /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */
-    S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: 0x%06x\n",
-              e_rab_setup_resp_p->eNB_ue_s1ap_id);
-    return -1;
-  }
+    /* mandatory */
+    ie = (S1AP_UECapabilityInfoIndicationIEs_t *)calloc(1, sizeof(S1AP_UECapabilityInfoIndicationIEs_t));
+    ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID;
+    ie->criticality = S1AP_Criticality_reject;
+    ie->value.present = S1AP_UECapabilityInfoIndicationIEs__value_PR_ENB_UE_S1AP_ID;
+    ie->value.choice.ENB_UE_S1AP_ID = ue_cap_info_ind_p->eNB_ue_s1ap_id;
+    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    /* mandatory */
+    ie = (S1AP_UECapabilityInfoIndicationIEs_t *)calloc(1, sizeof(S1AP_UECapabilityInfoIndicationIEs_t));
+    ie->id = S1AP_ProtocolIE_ID_id_UERadioCapability;
+    ie->criticality = S1AP_Criticality_reject;
+    ie->value.present = S1AP_UECapabilityInfoIndicationIEs__value_PR_UERadioCapability;
+    ie->value.choice.UERadioCapability.buf = ue_cap_info_ind_p->ue_radio_cap.buffer;
+    ie->value.choice.UERadioCapability.size = ue_cap_info_ind_p->ue_radio_cap.length;
+    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    /* optional */
+#if (S1AP_VERSION >= MAKE_VERSION(12, 0, 0))
 
-  /* Uplink NAS transport can occur either during an s1ap connected state
-   * or during initial attach (for example: NAS authentication).
-   */
-  if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED ||
-        ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) {
-    S1AP_WARN("You are attempting to send NAS data over non-connected "
-              "eNB ue s1ap id: %06x, current state: %d\n",
-              e_rab_setup_resp_p->eNB_ue_s1ap_id, ue_context_p->ue_state);
-    return -1;
-  }
+    if (0) {
+        ie = (S1AP_UECapabilityInfoIndicationIEs_t *)calloc(1, sizeof(S1AP_UECapabilityInfoIndicationIEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_UERadioCapabilityForPaging;
+        ie->criticality = S1AP_Criticality_ignore;
+        ie->value.present = S1AP_UECapabilityInfoIndicationIEs__value_PR_UERadioCapabilityForPaging;
+        // ie->value.choice.UERadioCapabilityForPaging = ;
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    }
 
-  /* Prepare the S1AP message to encode */
-  memset(&pdu, 0, sizeof(pdu));
-  pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome;
-  pdu.choice.successfulOutcome.procedureCode = S1AP_ProcedureCode_id_E_RABModify;
-  pdu.choice.successfulOutcome.criticality = S1AP_Criticality_reject;
-  pdu.choice.successfulOutcome.value.present = S1AP_SuccessfulOutcome__value_PR_E_RABSetupResponse;
-  out = &pdu.choice.successfulOutcome.value.choice.E_RABSetupResponse;
+#endif /* #if (S1AP_VERSION >= MAKE_VERSION(14, 0, 0)) */
 
-  /* mandatory */
-  ie = (S1AP_E_RABSetupResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupResponseIEs_t));
-  ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID;
-  ie->criticality = S1AP_Criticality_ignore;
-  ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_MME_UE_S1AP_ID;
-  ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) {
+        /* Encode procedure has failed... */
+        S1AP_ERROR("Failed to encode UE capabilities indication\n");
+        return -1;
+    }
 
-  /* mandatory */
-  ie = (S1AP_E_RABSetupResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupResponseIEs_t));
-  ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID;
-  ie->criticality = S1AP_Criticality_ignore;
-  ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_ENB_UE_S1AP_ID;
-  ie->value.choice.ENB_UE_S1AP_ID = e_rab_setup_resp_p->eNB_ue_s1ap_id;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    MSC_LOG_TX_MESSAGE(
+        MSC_S1AP_ENB,
+        MSC_S1AP_MME,
+        (const char *)buffer,
+        length,
+        MSC_AS_TIME_FMT" UECapabilityInfoIndication initiatingMessage eNB_ue_s1ap_id %u mme_ue_s1ap_id %u",
+        0,0,//MSC_AS_TIME_ARGS(ctxt_pP),
+        ue_cap_info_ind_p->eNB_ue_s1ap_id,
+        ue_context_p->mme_ue_s1ap_id);
+    /* UE associated signalling -> use the allocated stream */
+    s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance,
+                                     ue_context_p->mme_ref->assoc_id, buffer,
+                                     length, ue_context_p->tx_stream);
+    return 0;
+}
 
-  /* optional */
-  if (e_rab_setup_resp_p->nb_of_e_rabs > 0) {
-    ie = (S1AP_E_RABSetupResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupResponseIEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_E_RABSetupListBearerSURes;
-    ie->criticality = S1AP_Criticality_ignore;
-    ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_E_RABSetupListBearerSURes;
-
-    for (i = 0; i < e_rab_setup_resp_p->nb_of_e_rabs; i++) {
-      S1AP_E_RABSetupItemBearerSUResIEs_t *item;
-      /* mandatory */
-      item = (S1AP_E_RABSetupItemBearerSUResIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupItemBearerSUResIEs_t));
-      item->id = S1AP_ProtocolIE_ID_id_E_RABSetupItemBearerSURes;
-      item->criticality = S1AP_Criticality_ignore;
-      item->value.present = S1AP_E_RABSetupItemBearerSUResIEs__value_PR_E_RABSetupItemBearerSURes;
-      item->value.choice.E_RABSetupItemBearerSURes.e_RAB_ID = e_rab_setup_resp_p->e_rabs[i].e_rab_id;
-      GTP_TEID_TO_ASN1(e_rab_setup_resp_p->e_rabs[i].gtp_teid, &item->value.choice.E_RABSetupItemBearerSURes.gTP_TEID);
-      item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf = malloc(e_rab_setup_resp_p->e_rabs[i].eNB_addr.length);
-      memcpy(item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf,
-             e_rab_setup_resp_p->e_rabs[i].eNB_addr.buffer,
-             e_rab_setup_resp_p->e_rabs[i].eNB_addr.length);
-      item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.size = e_rab_setup_resp_p->e_rabs[i].eNB_addr.length;
-      item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.bits_unused = 0;
-      S1AP_DEBUG("e_rab_setup_resp: e_rab ID %ld, teid %u, enb_addr %d.%d.%d.%d, SIZE %ld\n",
-                 item->value.choice.E_RABSetupItemBearerSURes.e_RAB_ID,
-                 e_rab_setup_resp_p->e_rabs[i].gtp_teid,
-                 item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf[0],
-                 item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf[1],
-                 item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf[2],
-                 item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf[3],
-                 item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.size);
-      ASN_SEQUENCE_ADD(&ie->value.choice.E_RABSetupListBearerSURes.list, item);
+//------------------------------------------------------------------------------
+int s1ap_eNB_e_rab_setup_resp(instance_t instance,
+                              s1ap_e_rab_setup_resp_t *e_rab_setup_resp_p)
+//------------------------------------------------------------------------------
+{
+    s1ap_eNB_instance_t          *s1ap_eNB_instance_p = NULL;
+    struct s1ap_eNB_ue_context_s *ue_context_p        = NULL;
+    S1AP_S1AP_PDU_t               pdu;
+    S1AP_E_RABSetupResponse_t    *out;
+    S1AP_E_RABSetupResponseIEs_t *ie;
+    uint8_t  *buffer  = NULL;
+    uint32_t length;
+    int      i;
+    /* Retrieve the S1AP eNB instance associated with Mod_id */
+    s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance);
+    DevAssert(e_rab_setup_resp_p != NULL);
+    DevAssert(s1ap_eNB_instance_p != NULL);
+
+    if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p,
+                        e_rab_setup_resp_p->eNB_ue_s1ap_id)) == NULL) {
+        /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */
+        S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: 0x%06x\n",
+                  e_rab_setup_resp_p->eNB_ue_s1ap_id);
+        return -1;
     }
 
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
+    /* Uplink NAS transport can occur either during an s1ap connected state
+     * or during initial attach (for example: NAS authentication).
+     */
+    if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED ||
+            ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) {
+        S1AP_WARN("You are attempting to send NAS data over non-connected "
+                  "eNB ue s1ap id: %06x, current state: %d\n",
+                  e_rab_setup_resp_p->eNB_ue_s1ap_id, ue_context_p->ue_state);
+        return -1;
+    }
 
-  /* optional */
-  if (e_rab_setup_resp_p->nb_of_e_rabs_failed > 0) {
+    /* Prepare the S1AP message to encode */
+    memset(&pdu, 0, sizeof(pdu));
+    pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome;
+    pdu.choice.successfulOutcome.procedureCode = S1AP_ProcedureCode_id_E_RABModify;
+    pdu.choice.successfulOutcome.criticality = S1AP_Criticality_reject;
+    pdu.choice.successfulOutcome.value.present = S1AP_SuccessfulOutcome__value_PR_E_RABSetupResponse;
+    out = &pdu.choice.successfulOutcome.value.choice.E_RABSetupResponse;
+    /* mandatory */
     ie = (S1AP_E_RABSetupResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupResponseIEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_E_RABFailedToSetupListBearerSURes;
+    ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID;
     ie->criticality = S1AP_Criticality_ignore;
-    ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_E_RABList;
-
-    for (i = 0; i < e_rab_setup_resp_p->nb_of_e_rabs_failed; i++) {
-      S1AP_E_RABItemIEs_t *item;
-      item = (S1AP_E_RABItemIEs_t *)calloc(1, sizeof(S1AP_E_RABItemIEs_t));
-      item->id = S1AP_ProtocolIE_ID_id_E_RABItem;
-      item->criticality = S1AP_Criticality_ignore;
-      item->value.present = S1AP_E_RABItemIEs__value_PR_E_RABItem;
-      item->value.choice.E_RABItem.e_RAB_ID = e_rab_setup_resp_p->e_rabs_failed[i].e_rab_id;
-      item->value.choice.E_RABItem.cause.present = e_rab_setup_resp_p->e_rabs_failed[i].cause;
-
-      switch(item->value.choice.E_RABItem.cause.present)
-      {
-        case S1AP_Cause_PR_radioNetwork:
-          item->value.choice.E_RABItem.cause.choice.radioNetwork = e_rab_setup_resp_p->e_rabs_failed[i].cause_value;
-          break;
-        case S1AP_Cause_PR_transport:
-          item->value.choice.E_RABItem.cause.choice.transport = e_rab_setup_resp_p->e_rabs_failed[i].cause_value;
-          break;
-        case S1AP_Cause_PR_nas:
-          item->value.choice.E_RABItem.cause.choice.nas = e_rab_setup_resp_p->e_rabs_failed[i].cause_value;
-          break;
-        case S1AP_Cause_PR_protocol:
-          item->value.choice.E_RABItem.cause.choice.protocol = e_rab_setup_resp_p->e_rabs_failed[i].cause_value;
-          break;
-        case S1AP_Cause_PR_misc:
-          item->value.choice.E_RABItem.cause.choice.misc = e_rab_setup_resp_p->e_rabs_failed[i].cause_value;
-          break;
-        case S1AP_Cause_PR_NOTHING:
-        default:
-          break;
-      }
-
-      S1AP_DEBUG("e_rab_modify_resp: failed e_rab ID %ld\n", item->value.choice.E_RABItem.e_RAB_ID);
-      ASN_SEQUENCE_ADD(&ie->value.choice.E_RABList.list, item);
-    }
-
+    ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_MME_UE_S1AP_ID;
+    ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id;
     ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
-
-  /* optional */
-  if (0) {
+    /* mandatory */
     ie = (S1AP_E_RABSetupResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupResponseIEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_CriticalityDiagnostics;
+    ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID;
     ie->criticality = S1AP_Criticality_ignore;
-    ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_CriticalityDiagnostics;
-    // ie->value.choice.CriticalityDiagnostics = ;
+    ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_ENB_UE_S1AP_ID;
+    ie->value.choice.ENB_UE_S1AP_ID = e_rab_setup_resp_p->eNB_ue_s1ap_id;
     ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
 
-  /* S1AP_E_RABSetupListBearerSURes_t  e_RABSetupListBearerSURes;
-  memset(&e_RABSetupListBearerSURes, 0, sizeof(S1AP_E_RABSetupListBearerSURes_t));
-  if (s1ap_encode_s1ap_e_rabsetuplistbearersures(&e_RABSetupListBearerSURes, &initial_ies_p->e_RABSetupListBearerSURes.s1ap_E_RABSetupItemBearerSURes) < 0 )
-    return -1;
-  ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1AP_E_RABSetupListBearerSURes, &e_RABSetupListBearerSURes);
-  */
-  fprintf(stderr, "start encode\n");
-  if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) {
-    S1AP_ERROR("Failed to encode uplink transport\n");
-    /* Encode procedure has failed... */
-    return -1;
-  }
+    /* optional */
+    if (e_rab_setup_resp_p->nb_of_e_rabs > 0) {
+        ie = (S1AP_E_RABSetupResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupResponseIEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_E_RABSetupListBearerSURes;
+        ie->criticality = S1AP_Criticality_ignore;
+        ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_E_RABSetupListBearerSURes;
+
+        for (i = 0; i < e_rab_setup_resp_p->nb_of_e_rabs; i++) {
+            S1AP_E_RABSetupItemBearerSUResIEs_t *item;
+            /* mandatory */
+            item = (S1AP_E_RABSetupItemBearerSUResIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupItemBearerSUResIEs_t));
+            item->id = S1AP_ProtocolIE_ID_id_E_RABSetupItemBearerSURes;
+            item->criticality = S1AP_Criticality_ignore;
+            item->value.present = S1AP_E_RABSetupItemBearerSUResIEs__value_PR_E_RABSetupItemBearerSURes;
+            item->value.choice.E_RABSetupItemBearerSURes.e_RAB_ID = e_rab_setup_resp_p->e_rabs[i].e_rab_id;
+            GTP_TEID_TO_ASN1(e_rab_setup_resp_p->e_rabs[i].gtp_teid, &item->value.choice.E_RABSetupItemBearerSURes.gTP_TEID);
+            item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf = malloc(e_rab_setup_resp_p->e_rabs[i].eNB_addr.length);
+            memcpy(item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf,
+                   e_rab_setup_resp_p->e_rabs[i].eNB_addr.buffer,
+                   e_rab_setup_resp_p->e_rabs[i].eNB_addr.length);
+            item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.size = e_rab_setup_resp_p->e_rabs[i].eNB_addr.length;
+            item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.bits_unused = 0;
+            S1AP_DEBUG("e_rab_setup_resp: e_rab ID %ld, teid %u, enb_addr %d.%d.%d.%d, SIZE %ld\n",
+                       item->value.choice.E_RABSetupItemBearerSURes.e_RAB_ID,
+                       e_rab_setup_resp_p->e_rabs[i].gtp_teid,
+                       item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf[0],
+                       item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf[1],
+                       item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf[2],
+                       item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf[3],
+                       item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.size);
+            ASN_SEQUENCE_ADD(&ie->value.choice.E_RABSetupListBearerSURes.list, item);
+        }
+
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    }
 
-  MSC_LOG_TX_MESSAGE(
-    MSC_S1AP_ENB,
-    MSC_S1AP_MME,
-    (const char *)buffer,
-    length,
-    MSC_AS_TIME_FMT" E_RAN Setup successfulOutcome eNB_ue_s1ap_id %u mme_ue_s1ap_id %u",
-    0,0,//MSC_AS_TIME_ARGS(ctxt_pP),
-    e_rab_setup_resp_p->eNB_ue_s1ap_id,
-    ue_context_p->mme_ue_s1ap_id);
+    /* optional */
+    if (e_rab_setup_resp_p->nb_of_e_rabs_failed > 0) {
+        ie = (S1AP_E_RABSetupResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupResponseIEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_E_RABFailedToSetupListBearerSURes;
+        ie->criticality = S1AP_Criticality_ignore;
+        ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_E_RABList;
+
+        for (i = 0; i < e_rab_setup_resp_p->nb_of_e_rabs_failed; i++) {
+            S1AP_E_RABItemIEs_t *item;
+            item = (S1AP_E_RABItemIEs_t *)calloc(1, sizeof(S1AP_E_RABItemIEs_t));
+            item->id = S1AP_ProtocolIE_ID_id_E_RABItem;
+            item->criticality = S1AP_Criticality_ignore;
+            item->value.present = S1AP_E_RABItemIEs__value_PR_E_RABItem;
+            item->value.choice.E_RABItem.e_RAB_ID = e_rab_setup_resp_p->e_rabs_failed[i].e_rab_id;
+            item->value.choice.E_RABItem.cause.present = e_rab_setup_resp_p->e_rabs_failed[i].cause;
+
+            switch(item->value.choice.E_RABItem.cause.present) {
+            case S1AP_Cause_PR_radioNetwork:
+                item->value.choice.E_RABItem.cause.choice.radioNetwork = e_rab_setup_resp_p->e_rabs_failed[i].cause_value;
+                break;
+
+            case S1AP_Cause_PR_transport:
+                item->value.choice.E_RABItem.cause.choice.transport = e_rab_setup_resp_p->e_rabs_failed[i].cause_value;
+                break;
+
+            case S1AP_Cause_PR_nas:
+                item->value.choice.E_RABItem.cause.choice.nas = e_rab_setup_resp_p->e_rabs_failed[i].cause_value;
+                break;
+
+            case S1AP_Cause_PR_protocol:
+                item->value.choice.E_RABItem.cause.choice.protocol = e_rab_setup_resp_p->e_rabs_failed[i].cause_value;
+                break;
+
+            case S1AP_Cause_PR_misc:
+                item->value.choice.E_RABItem.cause.choice.misc = e_rab_setup_resp_p->e_rabs_failed[i].cause_value;
+                break;
+
+            case S1AP_Cause_PR_NOTHING:
+            default:
+                break;
+            }
+
+            S1AP_DEBUG("e_rab_modify_resp: failed e_rab ID %ld\n", item->value.choice.E_RABItem.e_RAB_ID);
+            ASN_SEQUENCE_ADD(&ie->value.choice.E_RABList.list, item);
+        }
+
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    }
 
-  /* UE associated signalling -> use the allocated stream */
-  s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance,
-                                   ue_context_p->mme_ref->assoc_id, buffer,
-                                   length, ue_context_p->tx_stream);
+    /* optional */
+    if (0) {
+        ie = (S1AP_E_RABSetupResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupResponseIEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_CriticalityDiagnostics;
+        ie->criticality = S1AP_Criticality_ignore;
+        ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_CriticalityDiagnostics;
+        // ie->value.choice.CriticalityDiagnostics = ;
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    }
+
+    /* S1AP_E_RABSetupListBearerSURes_t  e_RABSetupListBearerSURes;
+    memset(&e_RABSetupListBearerSURes, 0, sizeof(S1AP_E_RABSetupListBearerSURes_t));
+    if (s1ap_encode_s1ap_e_rabsetuplistbearersures(&e_RABSetupListBearerSURes, &initial_ies_p->e_RABSetupListBearerSURes.s1ap_E_RABSetupItemBearerSURes) < 0 )
+      return -1;
+    ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1AP_E_RABSetupListBearerSURes, &e_RABSetupListBearerSURes);
+    */
+    fprintf(stderr, "start encode\n");
+
+    if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) {
+        S1AP_ERROR("Failed to encode uplink transport\n");
+        /* Encode procedure has failed... */
+        return -1;
+    }
 
-  return 0;
+    MSC_LOG_TX_MESSAGE(
+        MSC_S1AP_ENB,
+        MSC_S1AP_MME,
+        (const char *)buffer,
+        length,
+        MSC_AS_TIME_FMT" E_RAN Setup successfulOutcome eNB_ue_s1ap_id %u mme_ue_s1ap_id %u",
+        0,0,//MSC_AS_TIME_ARGS(ctxt_pP),
+        e_rab_setup_resp_p->eNB_ue_s1ap_id,
+        ue_context_p->mme_ue_s1ap_id);
+    /* UE associated signalling -> use the allocated stream */
+    s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance,
+                                     ue_context_p->mme_ref->assoc_id, buffer,
+                                     length, ue_context_p->tx_stream);
+    return 0;
 }
 
 //------------------------------------------------------------------------------
@@ -1309,326 +1283,562 @@ int s1ap_eNB_e_rab_modify_resp(instance_t instance,
                                s1ap_e_rab_modify_resp_t *e_rab_modify_resp_p)
 //------------------------------------------------------------------------------
 {
-  s1ap_eNB_instance_t           *s1ap_eNB_instance_p = NULL;
-  struct s1ap_eNB_ue_context_s  *ue_context_p        = NULL;
-  S1AP_S1AP_PDU_t                pdu;
-  S1AP_E_RABModifyResponse_t    *out;
-  S1AP_E_RABModifyResponseIEs_t *ie;
+    s1ap_eNB_instance_t           *s1ap_eNB_instance_p = NULL;
+    struct s1ap_eNB_ue_context_s  *ue_context_p        = NULL;
+    S1AP_S1AP_PDU_t                pdu;
+    S1AP_E_RABModifyResponse_t    *out;
+    S1AP_E_RABModifyResponseIEs_t *ie;
+    uint8_t  *buffer  = NULL;
+    uint32_t length;
+    int      i;
+    /* Retrieve the S1AP eNB instance associated with Mod_id */
+    s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance);
+    DevAssert(e_rab_modify_resp_p != NULL);
+    DevAssert(s1ap_eNB_instance_p != NULL);
+
+    if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p,
+                        e_rab_modify_resp_p->eNB_ue_s1ap_id)) == NULL) {
+        /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */
+        S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: 0x%06x\n",
+                  e_rab_modify_resp_p->eNB_ue_s1ap_id);
+        return -1;
+    }
 
-  uint8_t  *buffer  = NULL;
-  uint32_t length;
-  int      i;
+    /* Uplink NAS transport can occur either during an s1ap connected state
+     * or during initial attach (for example: NAS authentication).
+     */
+    if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED ||
+            ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) {
+        S1AP_WARN("You are attempting to send NAS data over non-connected "
+                  "eNB ue s1ap id: %06x, current state: %d\n",
+                  e_rab_modify_resp_p->eNB_ue_s1ap_id, ue_context_p->ue_state);
+        return -1;
+    }
 
-  /* Retrieve the S1AP eNB instance associated with Mod_id */
-  s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance);
+    /* Prepare the S1AP message to encode */
+    memset(&pdu, 0, sizeof(pdu));
+    pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome;
+    pdu.choice.successfulOutcome.procedureCode = S1AP_ProcedureCode_id_E_RABModify;
+    pdu.choice.successfulOutcome.criticality = S1AP_Criticality_reject;
+    pdu.choice.successfulOutcome.value.present = S1AP_SuccessfulOutcome__value_PR_E_RABModifyResponse;
+    out = &pdu.choice.successfulOutcome.value.choice.E_RABModifyResponse;
+    /* mandatory */
+    ie = (S1AP_E_RABModifyResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyResponseIEs_t));
+    ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID;
+    ie->criticality = S1AP_Criticality_ignore;
+    ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_MME_UE_S1AP_ID;
+    ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id;
+    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    /* mandatory */
+    ie = (S1AP_E_RABModifyResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyResponseIEs_t));
+    ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID;
+    ie->criticality = S1AP_Criticality_ignore;
+    ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_ENB_UE_S1AP_ID;
+    ie->value.choice.ENB_UE_S1AP_ID = e_rab_modify_resp_p->eNB_ue_s1ap_id;
+    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
 
-  DevAssert(e_rab_modify_resp_p != NULL);
-  DevAssert(s1ap_eNB_instance_p != NULL);
+    /* optional */
+    if (e_rab_modify_resp_p->nb_of_e_rabs > 0) {
+        ie = (S1AP_E_RABModifyResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyResponseIEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_E_RABModifyListBearerModRes;
+        ie->criticality = S1AP_Criticality_ignore;
+        ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_E_RABModifyListBearerModRes;
+
+        for (i = 0; i < e_rab_modify_resp_p->nb_of_e_rabs; i++) {
+            S1AP_E_RABModifyItemBearerModResIEs_t *item;
+            item = (S1AP_E_RABModifyItemBearerModResIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyItemBearerModResIEs_t));
+            item->id = S1AP_ProtocolIE_ID_id_E_RABModifyItemBearerModRes;
+            item->criticality = S1AP_Criticality_ignore;
+            item->value.present = S1AP_E_RABModifyItemBearerModResIEs__value_PR_E_RABModifyItemBearerModRes;
+            item->value.choice.E_RABModifyItemBearerModRes.e_RAB_ID = e_rab_modify_resp_p->e_rabs[i].e_rab_id;
+            S1AP_DEBUG("e_rab_modify_resp: modified e_rab ID %ld\n", item->value.choice.E_RABModifyItemBearerModRes.e_RAB_ID);
+            ASN_SEQUENCE_ADD(&ie->value.choice.E_RABModifyListBearerModRes.list, item);
+        }
+
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    }
 
-  if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p,
-                                              e_rab_modify_resp_p->eNB_ue_s1ap_id)) == NULL) {
-    /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */
-    S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: 0x%06x\n",
-              e_rab_modify_resp_p->eNB_ue_s1ap_id);
-    return -1;
-  }
+    /* optional */
+    if (e_rab_modify_resp_p->nb_of_e_rabs_failed > 0) {
+        ie = (S1AP_E_RABModifyResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyResponseIEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_E_RABFailedToModifyList;
+        ie->criticality = S1AP_Criticality_ignore;
+        ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_E_RABList;
+
+        for (i = 0; i < e_rab_modify_resp_p->nb_of_e_rabs_failed; i++) {
+            S1AP_E_RABItemIEs_t *item;
+            item = (S1AP_E_RABItemIEs_t *)calloc(1, sizeof(S1AP_E_RABItemIEs_t));
+            item->id = S1AP_ProtocolIE_ID_id_E_RABItem;
+            item->criticality = S1AP_Criticality_ignore;
+            item->value.present = S1AP_E_RABItemIEs__value_PR_E_RABItem;
+            item->value.choice.E_RABItem.e_RAB_ID = e_rab_modify_resp_p->e_rabs_failed[i].e_rab_id;
+            item->value.choice.E_RABItem.cause.present = e_rab_modify_resp_p->e_rabs_failed[i].cause;
+
+            switch(item->value.choice.E_RABItem.cause.present) {
+            case S1AP_Cause_PR_radioNetwork:
+                item->value.choice.E_RABItem.cause.choice.radioNetwork = e_rab_modify_resp_p->e_rabs_failed[i].cause_value;
+                break;
+
+            case S1AP_Cause_PR_transport:
+                item->value.choice.E_RABItem.cause.choice.transport = e_rab_modify_resp_p->e_rabs_failed[i].cause_value;
+                break;
+
+            case S1AP_Cause_PR_nas:
+                item->value.choice.E_RABItem.cause.choice.nas = e_rab_modify_resp_p->e_rabs_failed[i].cause_value;
+                break;
+
+            case S1AP_Cause_PR_protocol:
+                item->value.choice.E_RABItem.cause.choice.protocol = e_rab_modify_resp_p->e_rabs_failed[i].cause_value;
+                break;
+
+            case S1AP_Cause_PR_misc:
+                item->value.choice.E_RABItem.cause.choice.misc = e_rab_modify_resp_p->e_rabs_failed[i].cause_value;
+                break;
+
+            case S1AP_Cause_PR_NOTHING:
+            default:
+                break;
+            }
+
+            S1AP_DEBUG("e_rab_modify_resp: failed e_rab ID %ld\n", item->value.choice.E_RABItem.e_RAB_ID);
+            ASN_SEQUENCE_ADD(&ie->value.choice.E_RABList.list, item);
+        }
+
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    }
 
-  /* Uplink NAS transport can occur either during an s1ap connected state
-   * or during initial attach (for example: NAS authentication).
-   */
-  if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED ||
-        ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) {
-    S1AP_WARN("You are attempting to send NAS data over non-connected "
-              "eNB ue s1ap id: %06x, current state: %d\n",
-              e_rab_modify_resp_p->eNB_ue_s1ap_id, ue_context_p->ue_state);
-    return -1;
-  }
+    /* optional */
+    if (0) {
+        ie = (S1AP_E_RABModifyResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyResponseIEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_CriticalityDiagnostics;
+        ie->criticality = S1AP_Criticality_ignore;
+        ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_CriticalityDiagnostics;
+        // ie->value.choice.CriticalityDiagnostics = ;
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    }
 
-  /* Prepare the S1AP message to encode */
-  memset(&pdu, 0, sizeof(pdu));
-  pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome;
-  pdu.choice.successfulOutcome.procedureCode = S1AP_ProcedureCode_id_E_RABModify;
-  pdu.choice.successfulOutcome.criticality = S1AP_Criticality_reject;
-  pdu.choice.successfulOutcome.value.present = S1AP_SuccessfulOutcome__value_PR_E_RABModifyResponse;
-  out = &pdu.choice.successfulOutcome.value.choice.E_RABModifyResponse;
+    fprintf(stderr, "start encode\n");
 
-  /* mandatory */
-  ie = (S1AP_E_RABModifyResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyResponseIEs_t));
-  ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID;
-  ie->criticality = S1AP_Criticality_ignore;
-  ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_MME_UE_S1AP_ID;
-  ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) {
+        S1AP_ERROR("Failed to encode uplink transport\n");
+        /* Encode procedure has failed... */
+        return -1;
+    }
 
-  /* mandatory */
-  ie = (S1AP_E_RABModifyResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyResponseIEs_t));
-  ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID;
-  ie->criticality = S1AP_Criticality_ignore;
-  ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_ENB_UE_S1AP_ID;
-  ie->value.choice.ENB_UE_S1AP_ID = e_rab_modify_resp_p->eNB_ue_s1ap_id;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    MSC_LOG_TX_MESSAGE(
+        MSC_S1AP_ENB,
+        MSC_S1AP_MME,
+        (const char *)buffer,
+        length,
+        MSC_AS_TIME_FMT" E_RAN Modify successful Outcome eNB_ue_s1ap_id %u mme_ue_s1ap_id %u",
+        0,0,//MSC_AS_TIME_ARGS(ctxt_pP),
+        e_rab_modify_resp_p->eNB_ue_s1ap_id,
+        ue_context_p->mme_ue_s1ap_id);
+    /* UE associated signalling -> use the allocated stream */
+    s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance,
+                                     ue_context_p->mme_ref->assoc_id, buffer,
+                                     length, ue_context_p->tx_stream);
+    return 0;
+}
+//------------------------------------------------------------------------------
+int s1ap_eNB_e_rab_release_resp(instance_t instance,
+                                s1ap_e_rab_release_resp_t *e_rab_release_resp_p)
+//------------------------------------------------------------------------------
+{
+    s1ap_eNB_instance_t            *s1ap_eNB_instance_p = NULL;
+    struct s1ap_eNB_ue_context_s   *ue_context_p        = NULL;
+    S1AP_S1AP_PDU_t                 pdu;
+    S1AP_E_RABReleaseResponse_t    *out;
+    S1AP_E_RABReleaseResponseIEs_t *ie;
+    uint8_t  *buffer  = NULL;
+    uint32_t length;
+    int      i;
+    /* Retrieve the S1AP eNB instance associated with Mod_id */
+    s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance);
+    DevAssert(e_rab_release_resp_p != NULL);
+    DevAssert(s1ap_eNB_instance_p != NULL);
+
+    if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p,
+                        e_rab_release_resp_p->eNB_ue_s1ap_id)) == NULL) {
+        /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */
+        S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: %u\n",
+                  e_rab_release_resp_p->eNB_ue_s1ap_id);
+        return -1;
+    }
 
-  /* optional */
-  if (e_rab_modify_resp_p->nb_of_e_rabs > 0) {
-    ie = (S1AP_E_RABModifyResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyResponseIEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_E_RABModifyListBearerModRes;
+    /* Prepare the S1AP message to encode */
+    memset(&pdu, 0, sizeof(pdu));
+    pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome;
+    pdu.choice.successfulOutcome.procedureCode = S1AP_ProcedureCode_id_E_RABRelease;
+    pdu.choice.successfulOutcome.criticality = S1AP_Criticality_reject;
+    pdu.choice.successfulOutcome.value.present = S1AP_SuccessfulOutcome__value_PR_E_RABReleaseResponse;
+    out = &pdu.choice.successfulOutcome.value.choice.E_RABReleaseResponse;
+    /* mandatory */
+    ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t));
+    ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID;
+    ie->criticality = S1AP_Criticality_ignore;
+    ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_MME_UE_S1AP_ID;
+    ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id;
+    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    /* mandatory */
+    ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t));
+    ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID;
     ie->criticality = S1AP_Criticality_ignore;
-    ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_E_RABModifyListBearerModRes;
+    ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_ENB_UE_S1AP_ID;
+    ie->value.choice.ENB_UE_S1AP_ID = e_rab_release_resp_p->eNB_ue_s1ap_id;
+    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
 
-    for (i = 0; i < e_rab_modify_resp_p->nb_of_e_rabs; i++) {
-      S1AP_E_RABModifyItemBearerModResIEs_t *item;
-      item = (S1AP_E_RABModifyItemBearerModResIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyItemBearerModResIEs_t));
-      item->id = S1AP_ProtocolIE_ID_id_E_RABModifyItemBearerModRes;
-      item->criticality = S1AP_Criticality_ignore;
-      item->value.present = S1AP_E_RABModifyItemBearerModResIEs__value_PR_E_RABModifyItemBearerModRes;
-      item->value.choice.E_RABModifyItemBearerModRes.e_RAB_ID = e_rab_modify_resp_p->e_rabs[i].e_rab_id;
-      S1AP_DEBUG("e_rab_modify_resp: modified e_rab ID %ld\n", item->value.choice.E_RABModifyItemBearerModRes.e_RAB_ID);
-      ASN_SEQUENCE_ADD(&ie->value.choice.E_RABModifyListBearerModRes.list, item);
+    /* optional */
+    if (e_rab_release_resp_p->nb_of_e_rabs_released > 0) {
+        ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_E_RABReleaseListBearerRelComp;
+        ie->criticality = S1AP_Criticality_ignore;
+        ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_E_RABReleaseListBearerRelComp;
+
+        for (i = 0; i < e_rab_release_resp_p->nb_of_e_rabs_released; i++) {
+            S1AP_E_RABReleaseItemBearerRelCompIEs_t *item;
+            item = (S1AP_E_RABReleaseItemBearerRelCompIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseItemBearerRelCompIEs_t));
+            item->id = S1AP_ProtocolIE_ID_id_E_RABReleaseItemBearerRelComp;
+            item->criticality = S1AP_Criticality_ignore;
+            item->value.present = S1AP_E_RABReleaseItemBearerRelCompIEs__value_PR_E_RABReleaseItemBearerRelComp;
+            item->value.choice.E_RABReleaseItemBearerRelComp.e_RAB_ID = e_rab_release_resp_p->e_rab_release[i].e_rab_id;
+            S1AP_DEBUG("e_rab_release_resp: e_rab ID %ld\n", item->value.choice.E_RABReleaseItemBearerRelComp.e_RAB_ID);
+            ASN_SEQUENCE_ADD(&ie->value.choice.E_RABReleaseListBearerRelComp.list, item);
+        }
+
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
     }
 
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
+    /* optional */
+    if (e_rab_release_resp_p->nb_of_e_rabs_failed > 0) {
+        ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_E_RABFailedToReleaseList;
+        ie->criticality = S1AP_Criticality_ignore;
+        ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_E_RABList;
+
+        for (i = 0; i < e_rab_release_resp_p->nb_of_e_rabs_failed; i++) {
+            S1AP_E_RABItemIEs_t *item;
+            item = (S1AP_E_RABItemIEs_t *)calloc(1, sizeof(S1AP_E_RABItemIEs_t));
+            item->id = S1AP_ProtocolIE_ID_id_E_RABItem;
+            item->criticality = S1AP_Criticality_ignore;
+            item->value.present = S1AP_E_RABItemIEs__value_PR_E_RABItem;
+            item->value.choice.E_RABItem.e_RAB_ID = e_rab_release_resp_p->e_rabs_failed[i].e_rab_id;
+            item->value.choice.E_RABItem.cause.present = e_rab_release_resp_p->e_rabs_failed[i].cause;
+
+            switch(item->value.choice.E_RABItem.cause.present) {
+            case S1AP_Cause_PR_radioNetwork:
+                item->value.choice.E_RABItem.cause.choice.radioNetwork = e_rab_release_resp_p->e_rabs_failed[i].cause_value;
+                break;
+
+            case S1AP_Cause_PR_transport:
+                item->value.choice.E_RABItem.cause.choice.transport = e_rab_release_resp_p->e_rabs_failed[i].cause_value;
+                break;
+
+            case S1AP_Cause_PR_nas:
+                item->value.choice.E_RABItem.cause.choice.nas = e_rab_release_resp_p->e_rabs_failed[i].cause_value;
+                break;
+
+            case S1AP_Cause_PR_protocol:
+                item->value.choice.E_RABItem.cause.choice.protocol = e_rab_release_resp_p->e_rabs_failed[i].cause_value;
+                break;
+
+            case S1AP_Cause_PR_misc:
+                item->value.choice.E_RABItem.cause.choice.misc = e_rab_release_resp_p->e_rabs_failed[i].cause_value;
+                break;
+
+            case S1AP_Cause_PR_NOTHING:
+            default:
+                break;
+            }
+
+            ASN_SEQUENCE_ADD(&ie->value.choice.E_RABList.list, item);
+        }
+
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    }
 
-  /* optional */
-  if (e_rab_modify_resp_p->nb_of_e_rabs_failed > 0) {
-    ie = (S1AP_E_RABModifyResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyResponseIEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_E_RABFailedToModifyList;
-    ie->criticality = S1AP_Criticality_ignore;
-    ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_E_RABList;
-
-    for (i = 0; i < e_rab_modify_resp_p->nb_of_e_rabs_failed; i++) {
-      S1AP_E_RABItemIEs_t *item;
-      item = (S1AP_E_RABItemIEs_t *)calloc(1, sizeof(S1AP_E_RABItemIEs_t));
-      item->id = S1AP_ProtocolIE_ID_id_E_RABItem;
-      item->criticality = S1AP_Criticality_ignore;
-      item->value.present = S1AP_E_RABItemIEs__value_PR_E_RABItem;
-      item->value.choice.E_RABItem.e_RAB_ID = e_rab_modify_resp_p->e_rabs_failed[i].e_rab_id;
-      item->value.choice.E_RABItem.cause.present = e_rab_modify_resp_p->e_rabs_failed[i].cause;
-
-      switch(item->value.choice.E_RABItem.cause.present)
-      {
-        case S1AP_Cause_PR_radioNetwork:
-          item->value.choice.E_RABItem.cause.choice.radioNetwork = e_rab_modify_resp_p->e_rabs_failed[i].cause_value;
-          break;
-        case S1AP_Cause_PR_transport:
-          item->value.choice.E_RABItem.cause.choice.transport = e_rab_modify_resp_p->e_rabs_failed[i].cause_value;
-          break;
-        case S1AP_Cause_PR_nas:
-          item->value.choice.E_RABItem.cause.choice.nas = e_rab_modify_resp_p->e_rabs_failed[i].cause_value;
-          break;
-        case S1AP_Cause_PR_protocol:
-          item->value.choice.E_RABItem.cause.choice.protocol = e_rab_modify_resp_p->e_rabs_failed[i].cause_value;
-          break;
-        case S1AP_Cause_PR_misc:
-          item->value.choice.E_RABItem.cause.choice.misc = e_rab_modify_resp_p->e_rabs_failed[i].cause_value;
-          break;
-        case S1AP_Cause_PR_NOTHING:
-        default:
-          break;
-      }
-
-      S1AP_DEBUG("e_rab_modify_resp: failed e_rab ID %ld\n", item->value.choice.E_RABItem.e_RAB_ID);
-      ASN_SEQUENCE_ADD(&ie->value.choice.E_RABList.list, item);
+    /* optional */
+    if (0) {
+        ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_CriticalityDiagnostics;
+        ie->criticality = S1AP_Criticality_ignore;
+        ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_CriticalityDiagnostics;
+        // ie->value.choice.CriticalityDiagnostics = ;
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
     }
 
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
+    /* optional */
+#if (S1AP_VERSION >= MAKE_VERSION(12, 0, 0))
 
-  /* optional */
-  if (0) {
-    ie = (S1AP_E_RABModifyResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyResponseIEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_CriticalityDiagnostics;
-    ie->criticality = S1AP_Criticality_ignore;
-    ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_CriticalityDiagnostics;
-    // ie->value.choice.CriticalityDiagnostics = ;
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
+    if(0) {
+        ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t));
+        ie->id = S1AP_ProtocolIE_ID_id_UserLocationInformation;
+        ie->criticality = S1AP_Criticality_ignore;
+        ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_UserLocationInformation;
+        // ie->value.choice.UserLocationInformation = ;
+        ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    }
 
-  fprintf(stderr, "start encode\n");
-  if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) {
-    S1AP_ERROR("Failed to encode uplink transport\n");
-    /* Encode procedure has failed... */
-    return -1;
-  }
+#endif /* #if (S1AP_VERSION >= MAKE_VERSION(14, 0, 0)) */
+    fprintf(stderr, "start encode\n");
 
-  MSC_LOG_TX_MESSAGE(
-    MSC_S1AP_ENB,
-    MSC_S1AP_MME,
-    (const char *)buffer,
-    length,
-    MSC_AS_TIME_FMT" E_RAN Modify successful Outcome eNB_ue_s1ap_id %u mme_ue_s1ap_id %u",
-    0,0,//MSC_AS_TIME_ARGS(ctxt_pP),
-    e_rab_modify_resp_p->eNB_ue_s1ap_id,
-    ue_context_p->mme_ue_s1ap_id);
+    if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) {
+        S1AP_ERROR("Failed to encode release response\n");
+        /* Encode procedure has failed... */
+        return -1;
+    }
 
-  /* UE associated signalling -> use the allocated stream */
-  s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance,
-                                   ue_context_p->mme_ref->assoc_id, buffer,
-                                   length, ue_context_p->tx_stream);
-  return 0;
+    MSC_LOG_TX_MESSAGE(
+        MSC_S1AP_ENB,
+        MSC_S1AP_MME,
+        (const char *)buffer,
+        length,
+        MSC_AS_TIME_FMT" E_RAN Release successfulOutcome eNB_ue_s1ap_id %u mme_ue_s1ap_id %u",
+        0,0,//MSC_AS_TIME_ARGS(ctxt_pP),
+        e_rab_release_resp_p->eNB_ue_s1ap_id,
+        ue_context_p->mme_ue_s1ap_id);
+    /* UE associated signalling -> use the allocated stream */
+    s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance,
+                                     ue_context_p->mme_ref->assoc_id, buffer,
+                                     length, ue_context_p->tx_stream);
+    S1AP_INFO("e_rab_release_response sended eNB_UE_S1AP_ID %d  mme_ue_s1ap_id %d nb_of_e_rabs_released %d nb_of_e_rabs_failed %d\n",
+              e_rab_release_resp_p->eNB_ue_s1ap_id, ue_context_p->mme_ue_s1ap_id,e_rab_release_resp_p->nb_of_e_rabs_released,e_rab_release_resp_p->nb_of_e_rabs_failed);
+    return 0;
 }
-//------------------------------------------------------------------------------
-int s1ap_eNB_e_rab_release_resp(instance_t instance,
-                                s1ap_e_rab_release_resp_t *e_rab_release_resp_p)
+
+int s1ap_eNB_path_switch_req(instance_t instance,
+                             s1ap_path_switch_req_t *path_switch_req_p)
 //------------------------------------------------------------------------------
 {
-  s1ap_eNB_instance_t            *s1ap_eNB_instance_p = NULL;
-  struct s1ap_eNB_ue_context_s   *ue_context_p        = NULL;
+  s1ap_eNB_instance_t          *s1ap_eNB_instance_p = NULL;
+  struct s1ap_eNB_ue_context_s *ue_context_p        = NULL;
+  struct s1ap_eNB_mme_data_s   *mme_desc_p = NULL;
+
   S1AP_S1AP_PDU_t                 pdu;
-  S1AP_E_RABReleaseResponse_t    *out;
-  S1AP_E_RABReleaseResponseIEs_t *ie;
-  uint8_t  *buffer  = NULL;
+  S1AP_PathSwitchRequest_t       *out;
+  S1AP_PathSwitchRequestIEs_t    *ie;
+
+  S1AP_E_RABToBeSwitchedDLItemIEs_t *e_RABToBeSwitchedDLItemIEs;
+  S1AP_E_RABToBeSwitchedDLItem_t    *e_RABToBeSwitchedDLItem;
+
+  uint8_t  *buffer = NULL;
   uint32_t length;
-  int      i;
+  int      ret = 0;//-1;
 
   /* Retrieve the S1AP eNB instance associated with Mod_id */
   s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance);
-  DevAssert(e_rab_release_resp_p != NULL);
+
+  DevAssert(path_switch_req_p != NULL);
   DevAssert(s1ap_eNB_instance_p != NULL);
 
-  if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p,
-                                              e_rab_release_resp_p->eNB_ue_s1ap_id)) == NULL) {
+  //if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p,
+    //                                          path_switch_req_p->eNB_ue_s1ap_id)) == NULL) {
     /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */
-    S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: %u\n",
-              e_rab_release_resp_p->eNB_ue_s1ap_id);
+    //S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: 0x%06x\n",
+      //        path_switch_req_p->eNB_ue_s1ap_id);
+    //return -1;
+  //}
+
+  /* Uplink NAS transport can occur either during an s1ap connected state
+   * or during initial attach (for example: NAS authentication).
+   */
+  //if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED ||
+       // ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) {
+    //S1AP_WARN("You are attempting to send NAS data over non-connected "
+        //      "eNB ue s1ap id: %06x, current state: %d\n",
+          //    path_switch_req_p->eNB_ue_s1ap_id, ue_context_p->ue_state);
+    //return -1;
+  //}
+
+  /* Select the MME corresponding to the provided GUMMEI. */
+  mme_desc_p = s1ap_eNB_nnsf_select_mme_by_gummei_no_cause(s1ap_eNB_instance_p, path_switch_req_p->ue_gummei);
+
+  if (mme_desc_p == NULL) {
+    /*
+     * In case eNB has no MME associated, the eNB should inform RRC and discard
+     * this request.
+     */
+
+    S1AP_WARN("No MME is associated to the eNB\n");
+    // TODO: Inform RRC
     return -1;
   }
 
+  /* The eNB should allocate a unique eNB UE S1AP ID for this UE. The value
+   * will be used for the duration of the connectivity.
+   */
+  ue_context_p = s1ap_eNB_allocate_new_UE_context();
+  DevAssert(ue_context_p != NULL);
+
+  /* Keep a reference to the selected MME */
+  ue_context_p->mme_ref       = mme_desc_p;
+  ue_context_p->ue_initial_id = path_switch_req_p->ue_initial_id;
+  ue_context_p->eNB_instance  = s1ap_eNB_instance_p;
+
+  do {
+    struct s1ap_eNB_ue_context_s *collision_p;
+
+    /* Peek a random value for the eNB_ue_s1ap_id */
+    ue_context_p->eNB_ue_s1ap_id = (random() + random()) & 0x00ffffff;
+
+    if ((collision_p = RB_INSERT(s1ap_ue_map, &s1ap_eNB_instance_p->s1ap_ue_head, ue_context_p))
+        == NULL) {
+      S1AP_DEBUG("Found usable eNB_ue_s1ap_id: 0x%06x %u(10)\n",
+                 ue_context_p->eNB_ue_s1ap_id,
+                 ue_context_p->eNB_ue_s1ap_id);
+      /* Break the loop as the id is not already used by another UE */
+      break;
+    }
+  } while(1);
+
+  ue_context_p->mme_ue_s1ap_id = path_switch_req_p->mme_ue_s1ap_id;
+
   /* Prepare the S1AP message to encode */
   memset(&pdu, 0, sizeof(pdu));
-  pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome;
-  pdu.choice.successfulOutcome.procedureCode = S1AP_ProcedureCode_id_E_RABRelease;
-  pdu.choice.successfulOutcome.criticality = S1AP_Criticality_reject;
-  pdu.choice.successfulOutcome.value.present = S1AP_SuccessfulOutcome__value_PR_E_RABReleaseResponse;
-  out = &pdu.choice.successfulOutcome.value.choice.E_RABReleaseResponse;
+  pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage;
+  pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_PathSwitchRequest;
+  pdu.choice.initiatingMessage.criticality = S1AP_Criticality_reject;
+  pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_PathSwitchRequest;
+  out = &pdu.choice.initiatingMessage.value.choice.PathSwitchRequest;
 
   /* mandatory */
-  ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t));
-  ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID;
-  ie->criticality = S1AP_Criticality_ignore;
-  ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_MME_UE_S1AP_ID;
-  ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id;
+  ie = (S1AP_PathSwitchRequestIEs_t *)calloc(1, sizeof(S1AP_PathSwitchRequestIEs_t));
+  ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID;
+  ie->criticality = S1AP_Criticality_reject;
+  ie->value.present = S1AP_PathSwitchRequestIEs__value_PR_ENB_UE_S1AP_ID;
+  ie->value.choice.ENB_UE_S1AP_ID = ue_context_p->eNB_ue_s1ap_id;
   ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
 
   /* mandatory */
-  ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t));
-  ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID;
-  ie->criticality = S1AP_Criticality_ignore;
-  ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_ENB_UE_S1AP_ID;
-  ie->value.choice.ENB_UE_S1AP_ID = e_rab_release_resp_p->eNB_ue_s1ap_id;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+  if (path_switch_req_p->nb_of_e_rabs > 0) {
+    ie = (S1AP_PathSwitchRequestIEs_t *)calloc(1, sizeof(S1AP_PathSwitchRequestIEs_t));
+    ie->id = S1AP_ProtocolIE_ID_id_E_RABToBeSwitchedDLList;
+    ie->criticality = S1AP_Criticality_reject;
+    ie->value.present = S1AP_PathSwitchRequestIEs__value_PR_E_RABToBeSwitchedDLList;
 
-  /* optional */
-  if (e_rab_release_resp_p->nb_of_e_rabs_released > 0) {
-    ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_E_RABReleaseListBearerRelComp;
-    ie->criticality = S1AP_Criticality_ignore;
-    ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_E_RABReleaseListBearerRelComp;
+    for (int i = 0; i < path_switch_req_p->nb_of_e_rabs; i++) {
+      e_RABToBeSwitchedDLItemIEs = (S1AP_E_RABToBeSwitchedDLItemIEs_t *)calloc(1, sizeof(S1AP_E_RABToBeSwitchedDLItemIEs_t));
+      e_RABToBeSwitchedDLItemIEs->id = S1AP_ProtocolIE_ID_id_E_RABToBeSwitchedDLItem;
+      e_RABToBeSwitchedDLItemIEs->criticality = S1AP_Criticality_reject;
+      e_RABToBeSwitchedDLItemIEs->value.present = S1AP_E_RABToBeSwitchedDLItemIEs__value_PR_E_RABToBeSwitchedDLItem;
 
-    for (i = 0; i < e_rab_release_resp_p->nb_of_e_rabs_released; i++) {
-      S1AP_E_RABReleaseItemBearerRelCompIEs_t *item;
-      item = (S1AP_E_RABReleaseItemBearerRelCompIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseItemBearerRelCompIEs_t));
-      item->id = S1AP_ProtocolIE_ID_id_E_RABReleaseItemBearerRelComp;
-      item->criticality = S1AP_Criticality_ignore;
-      item->value.present = S1AP_E_RABReleaseItemBearerRelCompIEs__value_PR_E_RABReleaseItemBearerRelComp;
-      item->value.choice.E_RABReleaseItemBearerRelComp.e_RAB_ID = e_rab_release_resp_p->e_rab_release[i].e_rab_id;
-      S1AP_DEBUG("e_rab_release_resp: e_rab ID %ld\n", item->value.choice.E_RABReleaseItemBearerRelComp.e_RAB_ID);
-      ASN_SEQUENCE_ADD(&ie->value.choice.E_RABReleaseListBearerRelComp.list, item);
-    }
+      e_RABToBeSwitchedDLItem = &e_RABToBeSwitchedDLItemIEs->value.choice.E_RABToBeSwitchedDLItem;
+      e_RABToBeSwitchedDLItem->e_RAB_ID = path_switch_req_p->e_rabs_tobeswitched[i].e_rab_id;
+      INT32_TO_OCTET_STRING(path_switch_req_p->e_rabs_tobeswitched[i].gtp_teid, &e_RABToBeSwitchedDLItem->gTP_TEID);
 
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
+      e_RABToBeSwitchedDLItem->transportLayerAddress.size  = path_switch_req_p->e_rabs_tobeswitched[i].eNB_addr.length;
+      e_RABToBeSwitchedDLItem->transportLayerAddress.bits_unused = 0;
 
-  /* optional */
-  if (e_rab_release_resp_p->nb_of_e_rabs_failed > 0) {
-    ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_E_RABFailedToReleaseList;
-    ie->criticality = S1AP_Criticality_ignore;
-    ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_E_RABList;
-
-    for (i = 0; i < e_rab_release_resp_p->nb_of_e_rabs_failed; i++) {
-      S1AP_E_RABItemIEs_t *item;
-      item = (S1AP_E_RABItemIEs_t *)calloc(1, sizeof(S1AP_E_RABItemIEs_t));
-      item->id = S1AP_ProtocolIE_ID_id_E_RABItem;
-      item->criticality = S1AP_Criticality_ignore;
-      item->value.present = S1AP_E_RABItemIEs__value_PR_E_RABItem;
-      item->value.choice.E_RABItem.e_RAB_ID = e_rab_release_resp_p->e_rabs_failed[i].e_rab_id;
-      item->value.choice.E_RABItem.cause.present = e_rab_release_resp_p->e_rabs_failed[i].cause;
-
-      switch(item->value.choice.E_RABItem.cause.present)
-      {
-        case S1AP_Cause_PR_radioNetwork:
-          item->value.choice.E_RABItem.cause.choice.radioNetwork = e_rab_release_resp_p->e_rabs_failed[i].cause_value;
-          break;
-        case S1AP_Cause_PR_transport:
-          item->value.choice.E_RABItem.cause.choice.transport = e_rab_release_resp_p->e_rabs_failed[i].cause_value;
-          break;
-        case S1AP_Cause_PR_nas:
-          item->value.choice.E_RABItem.cause.choice.nas = e_rab_release_resp_p->e_rabs_failed[i].cause_value;
-          break;
-        case S1AP_Cause_PR_protocol:
-          item->value.choice.E_RABItem.cause.choice.protocol = e_rab_release_resp_p->e_rabs_failed[i].cause_value;
-          break;
-        case S1AP_Cause_PR_misc:
-          item->value.choice.E_RABItem.cause.choice.misc = e_rab_release_resp_p->e_rabs_failed[i].cause_value;
-          break;
-        case S1AP_Cause_PR_NOTHING:
-        default:
-          break;
-      }
-
-      ASN_SEQUENCE_ADD(&ie->value.choice.E_RABList.list, item);
+      e_RABToBeSwitchedDLItem->transportLayerAddress.buf = calloc(1,e_RABToBeSwitchedDLItem->transportLayerAddress.size);
+
+      memcpy (e_RABToBeSwitchedDLItem->transportLayerAddress.buf,
+                path_switch_req_p->e_rabs_tobeswitched[i].eNB_addr.buffer,
+                path_switch_req_p->e_rabs_tobeswitched[i].eNB_addr.length);
+
+      S1AP_DEBUG("path_switch_req: e_rab ID %ld, teid %u, enb_addr %d.%d.%d.%d, SIZE %zu\n",
+               e_RABToBeSwitchedDLItem->e_RAB_ID,
+               path_switch_req_p->e_rabs_tobeswitched[i].gtp_teid,
+               e_RABToBeSwitchedDLItem->transportLayerAddress.buf[0],
+               e_RABToBeSwitchedDLItem->transportLayerAddress.buf[1],
+               e_RABToBeSwitchedDLItem->transportLayerAddress.buf[2],
+               e_RABToBeSwitchedDLItem->transportLayerAddress.buf[3],
+               e_RABToBeSwitchedDLItem->transportLayerAddress.size);
+
+      ASN_SEQUENCE_ADD(&ie->value.choice.E_RABToBeSwitchedDLList.list, e_RABToBeSwitchedDLItemIEs);
     }
 
     ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
   }
 
-  /* optional */
-  if (0) {
-    ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_CriticalityDiagnostics;
-    ie->criticality = S1AP_Criticality_ignore;
-    ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_CriticalityDiagnostics;
-    // ie->value.choice.CriticalityDiagnostics = ;
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
+  /* mandatory */
+  ie = (S1AP_PathSwitchRequestIEs_t *)calloc(1, sizeof(S1AP_PathSwitchRequestIEs_t));
+  ie->id = S1AP_ProtocolIE_ID_id_SourceMME_UE_S1AP_ID;
+  ie->criticality = S1AP_Criticality_reject;
+  ie->value.present = S1AP_PathSwitchRequestIEs__value_PR_MME_UE_S1AP_ID;
+  ie->value.choice.MME_UE_S1AP_ID = path_switch_req_p->mme_ue_s1ap_id;
+  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
 
-  /* optional */
-#if (S1AP_VERSION >= MAKE_VERSION(12, 0, 0))
-  if(0) {
-    ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t));
-    ie->id = S1AP_ProtocolIE_ID_id_UserLocationInformation;
-    ie->criticality = S1AP_Criticality_ignore;
-    ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_UserLocationInformation;
-    // ie->value.choice.UserLocationInformation = ;
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
-#endif /* #if (S1AP_VERSION >= MAKE_VERSION(14, 0, 0)) */
+  /* mandatory */
+  ie = (S1AP_PathSwitchRequestIEs_t *)calloc(1, sizeof(S1AP_PathSwitchRequestIEs_t));
+  ie->id = S1AP_ProtocolIE_ID_id_EUTRAN_CGI;
+  ie->criticality = S1AP_Criticality_ignore;
+  ie->value.present = S1AP_PathSwitchRequestIEs__value_PR_EUTRAN_CGI;
+  MACRO_ENB_ID_TO_CELL_IDENTITY(s1ap_eNB_instance_p->eNB_id,
+                                0,
+                                &ie->value.choice.EUTRAN_CGI.cell_ID);
+  MCC_MNC_TO_TBCD(s1ap_eNB_instance_p->mcc[0],
+                  s1ap_eNB_instance_p->mnc[0],
+                  s1ap_eNB_instance_p->mnc_digit_length[0],
+                  &ie->value.choice.EUTRAN_CGI.pLMNidentity);
+  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+
+  /* mandatory */
+  ie = (S1AP_PathSwitchRequestIEs_t *)calloc(1, sizeof(S1AP_PathSwitchRequestIEs_t));
+  ie->id = S1AP_ProtocolIE_ID_id_TAI;
+  ie->criticality = S1AP_Criticality_ignore;
+  ie->value.present = S1AP_PathSwitchRequestIEs__value_PR_TAI;
+  /* Assuming TAI is the TAI from the cell */
+  INT16_TO_OCTET_STRING(s1ap_eNB_instance_p->tac, &ie->value.choice.TAI.tAC);
+  MCC_MNC_TO_PLMNID(s1ap_eNB_instance_p->mcc[0],
+                    s1ap_eNB_instance_p->mnc[0],
+                    s1ap_eNB_instance_p->mnc_digit_length[0],
+                    &ie->value.choice.TAI.pLMNidentity);
+  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+
+  /* mandatory */
+  ie = (S1AP_PathSwitchRequestIEs_t *)calloc(1, sizeof(S1AP_PathSwitchRequestIEs_t));
+  ie->id = S1AP_ProtocolIE_ID_id_UESecurityCapabilities;
+  ie->criticality = S1AP_Criticality_ignore;
+  ie->value.present = S1AP_PathSwitchRequestIEs__value_PR_UESecurityCapabilities;
+  ENCRALG_TO_BIT_STRING(path_switch_req_p->security_capabilities.encryption_algorithms,
+              &ie->value.choice.UESecurityCapabilities.encryptionAlgorithms);
+  INTPROTALG_TO_BIT_STRING(path_switch_req_p->security_capabilities.integrity_algorithms,
+              &ie->value.choice.UESecurityCapabilities.integrityProtectionAlgorithms);
+  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
 
-  fprintf(stderr, "start encode\n");
   if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) {
-    S1AP_ERROR("Failed to encode release response\n");
+    S1AP_ERROR("Failed to encode Path Switch Req \n");
     /* Encode procedure has failed... */
     return -1;
   }
 
+  /* Update the current S1AP UE state */
+  ue_context_p->ue_state = S1AP_UE_WAITING_CSR;
+
+  /* Assign a stream for this UE :
+   * From 3GPP 36.412 7)Transport layers:
+   *  Within the SCTP association established between one MME and eNB pair:
+   *  - a single pair of stream identifiers shall be reserved for the sole use
+   *      of S1AP elementary procedures that utilize non UE-associated signalling.
+   *  - At least one pair of stream identifiers shall be reserved for the sole use
+   *      of S1AP elementary procedures that utilize UE-associated signallings.
+   *      However a few pairs (i.e. more than one) should be reserved.
+   *  - A single UE-associated signalling shall use one SCTP stream and
+   *      the stream should not be changed during the communication of the
+   *      UE-associated signalling.
+   */
+  mme_desc_p->nextstream = (mme_desc_p->nextstream + 1) % mme_desc_p->out_streams;
+
+  if ((mme_desc_p->nextstream == 0) && (mme_desc_p->out_streams > 1)) {
+    mme_desc_p->nextstream += 1;
+  }
+
+  ue_context_p->tx_stream = mme_desc_p->nextstream;
+
   MSC_LOG_TX_MESSAGE(
     MSC_S1AP_ENB,
     MSC_S1AP_MME,
     (const char *)buffer,
     length,
-    MSC_AS_TIME_FMT" E_RAN Release successfulOutcome eNB_ue_s1ap_id %u mme_ue_s1ap_id %u",
+    MSC_AS_TIME_FMT" E_RAN Setup successfulOutcome eNB_ue_s1ap_id %u mme_ue_s1ap_id %u",
     0,0,//MSC_AS_TIME_ARGS(ctxt_pP),
-    e_rab_release_resp_p->eNB_ue_s1ap_id,
-    ue_context_p->mme_ue_s1ap_id);
+    ue_context_p->eNB_ue_s1ap_id,
+    path_switch_req_p->mme_ue_s1ap_id);
 
   /* UE associated signalling -> use the allocated stream */
   s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance,
-                                   ue_context_p->mme_ref->assoc_id, buffer,
+                                   mme_desc_p->assoc_id, buffer,
                                    length, ue_context_p->tx_stream);
 
-  S1AP_INFO("e_rab_release_response sended eNB_UE_S1AP_ID %d  mme_ue_s1ap_id %d nb_of_e_rabs_released %d nb_of_e_rabs_failed %d\n",
-            e_rab_release_resp_p->eNB_ue_s1ap_id, ue_context_p->mme_ue_s1ap_id,e_rab_release_resp_p->nb_of_e_rabs_released,e_rab_release_resp_p->nb_of_e_rabs_failed);
-
-  return 0;
+  return ret;
 }
diff --git a/openair3/S1AP/s1ap_eNB_nas_procedures.h b/openair3/S1AP/s1ap_eNB_nas_procedures.h
index a7f144c0ca3653ab0a2665f8d1be619a1fe9d1a5..c4257198727a042cfacd7eeafac65e1dfc36a232 100644
--- a/openair3/S1AP/s1ap_eNB_nas_procedures.h
+++ b/openair3/S1AP/s1ap_eNB_nas_procedures.h
@@ -49,4 +49,7 @@ int s1ap_eNB_e_rab_modify_resp(instance_t instance,
 
 int s1ap_eNB_e_rab_release_resp(instance_t instance,
                                 s1ap_e_rab_release_resp_t *e_rab_release_resp_p);
+
+int s1ap_eNB_path_switch_req(instance_t instance,
+                             s1ap_path_switch_req_t *path_switch_req_p);
 #endif /* S1AP_ENB_NAS_PROCEDURES_H_ */
diff --git a/openair3/S1AP/s1ap_eNB_nnsf.c b/openair3/S1AP/s1ap_eNB_nnsf.c
index 63dc92b5e260e33c82a3dd076788b4761b1d763c..6319f6e054d878fb19087e0c3f3fa8e946a6d602 100644
--- a/openair3/S1AP/s1ap_eNB_nnsf.c
+++ b/openair3/S1AP/s1ap_eNB_nnsf.c
@@ -321,3 +321,79 @@ s1ap_eNB_nnsf_select_mme_by_gummei(s1ap_eNB_instance_t       *instance_p,
    * connectivity. */
   return NULL;
 }
+
+
+struct s1ap_eNB_mme_data_s *
+s1ap_eNB_nnsf_select_mme_by_gummei_no_cause(s1ap_eNB_instance_t       *instance_p,
+                                            s1ap_gummei_t                   gummei)
+{
+  struct s1ap_eNB_mme_data_s *mme_data_p             = NULL;
+  struct s1ap_eNB_mme_data_s *mme_highest_capacity_p = NULL;
+  uint8_t                     current_capacity       = 0;
+
+  RB_FOREACH(mme_data_p, s1ap_mme_map, &instance_p->s1ap_mme_head) {
+    struct served_gummei_s *gummei_p = NULL;
+
+    if (mme_data_p->state != S1AP_ENB_STATE_CONNECTED) {
+      /* The association between MME and eNB is not ready for the moment,
+       * go to the next known MME.
+       */
+      if (mme_data_p->state == S1AP_ENB_OVERLOAD) {
+        /* MME is overloaded. We have to check the RRC establishment
+         * cause and take decision to the select this MME depending on
+         * the overload state.
+         */
+    } else {
+        /* The MME is not overloaded, association is simply not ready. */
+        continue;
+      }
+    }
+
+    if (current_capacity < mme_data_p->relative_mme_capacity) {
+      /* We find a better MME, keep a reference to it */
+      current_capacity = mme_data_p->relative_mme_capacity;
+      mme_highest_capacity_p = mme_data_p;
+    }
+
+    /* Looking for MME gummei matching the one provided by NAS */
+    STAILQ_FOREACH(gummei_p, &mme_data_p->served_gummei, next) {
+      struct served_group_id_s *group_id_p = NULL;
+      struct mme_code_s        *mme_code_p = NULL;
+      struct plmn_identity_s   *served_plmn_p = NULL;
+
+      STAILQ_FOREACH(served_plmn_p, &gummei_p->served_plmns, next) {
+        if ((served_plmn_p->mcc == gummei.mcc) &&
+            (served_plmn_p->mnc == gummei.mnc)) {
+          break;
+        }
+      }
+      STAILQ_FOREACH(mme_code_p, &gummei_p->mme_codes, next) {
+        if (mme_code_p->mme_code == gummei.mme_code) {
+          break;
+        }
+      }
+      STAILQ_FOREACH(group_id_p, &gummei_p->served_group_ids, next) {
+        if (group_id_p->mme_group_id == gummei.mme_group_id) {
+          break;
+        }
+      }
+
+      /* The MME matches the parameters provided by the NAS layer ->
+      * the MME is knwown and the association is ready.
+      * Return the reference to the MME to use it for this UE.
+      */
+      if ((group_id_p != NULL) &&
+          (mme_code_p != NULL) &&
+          (served_plmn_p != NULL)) {
+        return mme_data_p;
+      }
+    }
+  }
+
+  /* At this point no MME matches the provided GUMMEI. Select the one with the
+   * highest relative capacity.
+   * In case the list of known MME is empty, simply return NULL, that way the RRC
+   * layer should know about it and reject RRC connectivity.
+   */
+  return mme_highest_capacity_p;
+}
diff --git a/openair3/S1AP/s1ap_eNB_nnsf.h b/openair3/S1AP/s1ap_eNB_nnsf.h
index 706f3ada6ff8380bf7e94d6a541817eb83064e07..d5f080649b0e6563ea138420fb35b7481cba2727 100644
--- a/openair3/S1AP/s1ap_eNB_nnsf.h
+++ b/openair3/S1AP/s1ap_eNB_nnsf.h
@@ -42,4 +42,8 @@ s1ap_eNB_nnsf_select_mme_by_gummei(s1ap_eNB_instance_t       *instance_p,
                                    rrc_establishment_cause_t  cause,
                                    s1ap_gummei_t                   gummei);
 
+struct s1ap_eNB_mme_data_s*
+s1ap_eNB_nnsf_select_mme_by_gummei_no_cause(s1ap_eNB_instance_t       *instance_p,
+                                   s1ap_gummei_t                   gummei);
+
 #endif /* S1AP_ENB_NNSF_H_ */
diff --git a/openair3/S1AP/s1ap_eNB_overload.c b/openair3/S1AP/s1ap_eNB_overload.c
index cf208fc16e3e47dfaa2d63d64842bed52caa9397..9358ae62bdb6286873240f3194af9e609921172f 100644
--- a/openair3/S1AP/s1ap_eNB_overload.c
+++ b/openair3/S1AP/s1ap_eNB_overload.c
@@ -47,60 +47,60 @@ int s1ap_eNB_handle_overload_start(uint32_t         assoc_id,
                                    uint32_t         stream,
                                    S1AP_S1AP_PDU_t *pdu)
 {
-  s1ap_eNB_mme_data_t     *mme_desc_p;
-  S1AP_OverloadStart_t    *container;
-  S1AP_OverloadStartIEs_t *ie;
-
-  DevAssert(pdu != NULL);
-
-  container = &pdu->choice.initiatingMessage.value.choice.OverloadStart;
-
-  S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_OverloadStartIEs_t, ie, container,
-                             S1AP_ProtocolIE_ID_id_OverloadResponse, true);
-
-  DevCheck(ie->value.choice.OverloadResponse.present ==
-           S1AP_OverloadResponse_PR_overloadAction,
-           S1AP_OverloadResponse_PR_overloadAction, 0, 0);
-
-  /* Non UE-associated signalling -> stream 0 */
-  DevCheck(stream == 0, stream, 0, 0);
-
-  if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) {
-    /* No MME context associated */
-    return -1;
-  }
-
-  /* Mark the MME as overloaded and set the overload state according to
-   * the value received.
-   */
-  mme_desc_p->state = S1AP_ENB_OVERLOAD;
-  mme_desc_p->overload_state =
-    ie->value.choice.OverloadResponse.choice.overloadAction;
-
-  return 0;
+    s1ap_eNB_mme_data_t     *mme_desc_p;
+    S1AP_OverloadStart_t    *container;
+    S1AP_OverloadStartIEs_t *ie;
+
+    DevAssert(pdu != NULL);
+
+    container = &pdu->choice.initiatingMessage.value.choice.OverloadStart;
+
+    S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_OverloadStartIEs_t, ie, container,
+                               S1AP_ProtocolIE_ID_id_OverloadResponse, true);
+    if (ie != NULL) {
+        DevCheck(ie->value.choice.OverloadResponse.present ==
+                 S1AP_OverloadResponse_PR_overloadAction,
+                 S1AP_OverloadResponse_PR_overloadAction, 0, 0);
+    }
+    /* Non UE-associated signalling -> stream 0 */
+    DevCheck(stream == 0, stream, 0, 0);
+
+    if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) {
+        /* No MME context associated */
+        return -1;
+    }
+
+    /* Mark the MME as overloaded and set the overload state according to
+     * the value received.
+     */
+    mme_desc_p->state = S1AP_ENB_OVERLOAD;
+    mme_desc_p->overload_state =
+        ie->value.choice.OverloadResponse.choice.overloadAction;
+
+    return 0;
 }
 
 int s1ap_eNB_handle_overload_stop(uint32_t         assoc_id,
                                   uint32_t         stream,
                                   S1AP_S1AP_PDU_t *pdu)
 {
-  /* We received Overload stop message, meaning that the MME is no more
-   * overloaded. This is an empty message, with only message header and no
-   * Information Element.
-   */
-  DevAssert(pdu != NULL);
+    /* We received Overload stop message, meaning that the MME is no more
+     * overloaded. This is an empty message, with only message header and no
+     * Information Element.
+     */
+    DevAssert(pdu != NULL);
 
-  s1ap_eNB_mme_data_t *mme_desc_p;
+    s1ap_eNB_mme_data_t *mme_desc_p;
 
-  /* Non UE-associated signalling -> stream 0 */
-  DevCheck(stream == 0, stream, 0, 0);
+    /* Non UE-associated signalling -> stream 0 */
+    DevCheck(stream == 0, stream, 0, 0);
 
-  if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) {
-    /* No MME context associated */
-    return -1;
-  }
+    if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) {
+        /* No MME context associated */
+        return -1;
+    }
 
-  mme_desc_p->state = S1AP_ENB_STATE_CONNECTED;
-  mme_desc_p->overload_state = S1AP_NO_OVERLOAD;
-  return 0;
+    mme_desc_p->state = S1AP_ENB_STATE_CONNECTED;
+    mme_desc_p->overload_state = S1AP_NO_OVERLOAD;
+    return 0;
 }
diff --git a/openair3/S1AP/s1ap_eNB_trace.c b/openair3/S1AP/s1ap_eNB_trace.c
index 653aa98ccdd1390c965e11c018cc9d9b7db18616..0f572e83626c8afcf1efbdbb9da31fdb026ac6a6 100644
--- a/openair3/S1AP/s1ap_eNB_trace.c
+++ b/openair3/S1AP/s1ap_eNB_trace.c
@@ -42,107 +42,109 @@ void s1ap_eNB_generate_trace_failure(struct s1ap_eNB_ue_context_s *ue_desc_p,
                                      S1AP_E_UTRAN_Trace_ID_t      *trace_id,
                                      S1AP_Cause_t                 *cause_p)
 {
-  S1AP_S1AP_PDU_t                     pdu;
-  S1AP_TraceFailureIndication_t      *out;
-  S1AP_TraceFailureIndicationIEs_t   *ie;
-  uint8_t                            *buffer = NULL;
-  uint32_t                            length;
-
-  DevAssert(ue_desc_p != NULL);
-  DevAssert(trace_id  != NULL);
-  DevAssert(cause_p   != NULL);
-
-  /* Prepare the S1AP message to encode */
-  memset(&pdu, 0, sizeof(pdu));
-  pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage;
-  pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_TraceFailureIndication;
-  pdu.choice.initiatingMessage.criticality = S1AP_Criticality_ignore;
-  pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_TraceFailureIndication;
-  out = &pdu.choice.initiatingMessage.value.choice.TraceFailureIndication;
-
-  /* mandatory */
-  ie = (S1AP_TraceFailureIndicationIEs_t *)calloc(1, sizeof(S1AP_TraceFailureIndicationIEs_t));
-  ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID;
-  ie->criticality = S1AP_Criticality_reject;
-  ie->value.present = S1AP_TraceFailureIndicationIEs__value_PR_MME_UE_S1AP_ID;
-  ie->value.choice.MME_UE_S1AP_ID = ue_desc_p->mme_ue_s1ap_id;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
-  /* mandatory */
-  ie = (S1AP_TraceFailureIndicationIEs_t *)calloc(1, sizeof(S1AP_TraceFailureIndicationIEs_t));
-  ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID;
-  ie->criticality = S1AP_Criticality_reject;
-  ie->value.present = S1AP_TraceFailureIndicationIEs__value_PR_ENB_UE_S1AP_ID;
-  ie->value.choice.ENB_UE_S1AP_ID = ue_desc_p->eNB_ue_s1ap_id;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
-  /* mandatory */
-  ie = (S1AP_TraceFailureIndicationIEs_t *)calloc(1, sizeof(S1AP_TraceFailureIndicationIEs_t));
-  ie->id = S1AP_ProtocolIE_ID_id_E_UTRAN_Trace_ID;
-  ie->criticality = S1AP_Criticality_ignore;
-  ie->value.present = S1AP_TraceFailureIndicationIEs__value_PR_E_UTRAN_Trace_ID;
-  memcpy(&ie->value.choice.E_UTRAN_Trace_ID, trace_id, sizeof(S1AP_E_UTRAN_Trace_ID_t));
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
-  /* mandatory */
-  ie = (S1AP_TraceFailureIndicationIEs_t *)calloc(1, sizeof(S1AP_TraceFailureIndicationIEs_t));
-  ie->id = S1AP_ProtocolIE_ID_id_Cause;
-  ie->criticality = S1AP_Criticality_ignore;
-  ie->value.present = S1AP_TraceFailureIndicationIEs__value_PR_Cause;
-  memcpy(&ie->value.choice.Cause, cause_p, sizeof(S1AP_Cause_t));
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
-  if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) {
-    return;
-  }
-
-  s1ap_eNB_itti_send_sctp_data_req(ue_desc_p->mme_ref->s1ap_eNB_instance->instance,
-                                   ue_desc_p->mme_ref->assoc_id, buffer,
-                                   length, ue_desc_p->tx_stream);
+    S1AP_S1AP_PDU_t                     pdu;
+    S1AP_TraceFailureIndication_t      *out;
+    S1AP_TraceFailureIndicationIEs_t   *ie;
+    uint8_t                            *buffer = NULL;
+    uint32_t                            length;
+
+    DevAssert(ue_desc_p != NULL);
+    DevAssert(trace_id  != NULL);
+    DevAssert(cause_p   != NULL);
+
+    /* Prepare the S1AP message to encode */
+    memset(&pdu, 0, sizeof(pdu));
+    pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage;
+    pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_TraceFailureIndication;
+    pdu.choice.initiatingMessage.criticality = S1AP_Criticality_ignore;
+    pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_TraceFailureIndication;
+    out = &pdu.choice.initiatingMessage.value.choice.TraceFailureIndication;
+
+    /* mandatory */
+    ie = (S1AP_TraceFailureIndicationIEs_t *)calloc(1, sizeof(S1AP_TraceFailureIndicationIEs_t));
+    ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID;
+    ie->criticality = S1AP_Criticality_reject;
+    ie->value.present = S1AP_TraceFailureIndicationIEs__value_PR_MME_UE_S1AP_ID;
+    ie->value.choice.MME_UE_S1AP_ID = ue_desc_p->mme_ue_s1ap_id;
+    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+
+    /* mandatory */
+    ie = (S1AP_TraceFailureIndicationIEs_t *)calloc(1, sizeof(S1AP_TraceFailureIndicationIEs_t));
+    ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID;
+    ie->criticality = S1AP_Criticality_reject;
+    ie->value.present = S1AP_TraceFailureIndicationIEs__value_PR_ENB_UE_S1AP_ID;
+    ie->value.choice.ENB_UE_S1AP_ID = ue_desc_p->eNB_ue_s1ap_id;
+    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+
+    /* mandatory */
+    ie = (S1AP_TraceFailureIndicationIEs_t *)calloc(1, sizeof(S1AP_TraceFailureIndicationIEs_t));
+    ie->id = S1AP_ProtocolIE_ID_id_E_UTRAN_Trace_ID;
+    ie->criticality = S1AP_Criticality_ignore;
+    ie->value.present = S1AP_TraceFailureIndicationIEs__value_PR_E_UTRAN_Trace_ID;
+    memcpy(&ie->value.choice.E_UTRAN_Trace_ID, trace_id, sizeof(S1AP_E_UTRAN_Trace_ID_t));
+    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+
+    /* mandatory */
+    ie = (S1AP_TraceFailureIndicationIEs_t *)calloc(1, sizeof(S1AP_TraceFailureIndicationIEs_t));
+    ie->id = S1AP_ProtocolIE_ID_id_Cause;
+    ie->criticality = S1AP_Criticality_ignore;
+    ie->value.present = S1AP_TraceFailureIndicationIEs__value_PR_Cause;
+    memcpy(&ie->value.choice.Cause, cause_p, sizeof(S1AP_Cause_t));
+    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+
+    if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) {
+        return;
+    }
+
+    s1ap_eNB_itti_send_sctp_data_req(ue_desc_p->mme_ref->s1ap_eNB_instance->instance,
+                                     ue_desc_p->mme_ref->assoc_id, buffer,
+                                     length, ue_desc_p->tx_stream);
 }
 
 int s1ap_eNB_handle_trace_start(uint32_t         assoc_id,
                                 uint32_t         stream,
                                 S1AP_S1AP_PDU_t *pdu)
 {
-  S1AP_TraceStart_t            *container;
-  S1AP_TraceStartIEs_t         *ie;
-  struct s1ap_eNB_ue_context_s *ue_desc_p;
-  struct s1ap_eNB_mme_data_s   *mme_ref_p;
-
-  DevAssert(pdu != NULL);
-
-  container = &pdu->choice.initiatingMessage.value.choice.TraceStart;
-
-  S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_TraceStartIEs_t, ie, container,
-                             S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, TRUE);
-  mme_ref_p = s1ap_eNB_get_MME(NULL, assoc_id, 0);
-  DevAssert(mme_ref_p != NULL);
-
-  if ((ue_desc_p = s1ap_eNB_get_ue_context(mme_ref_p->s1ap_eNB_instance,
-                                           ie->value.choice.ENB_UE_S1AP_ID)) == NULL) {
-    /* Could not find context associated with this eNB_ue_s1ap_id -> generate
-     * trace failure indication.
-     */
-    S1AP_E_UTRAN_Trace_ID_t trace_id;
-    S1AP_Cause_t cause;
-    memset(&trace_id, 0, sizeof(S1AP_E_UTRAN_Trace_ID_t));
-    memset(&cause, 0, sizeof(S1AP_Cause_t));
-    cause.present = S1AP_Cause_PR_radioNetwork;
-    cause.choice.radioNetwork = S1AP_CauseRadioNetwork_unknown_pair_ue_s1ap_id;
-    s1ap_eNB_generate_trace_failure(ue_desc_p, &trace_id, &cause);
+    S1AP_TraceStart_t            *container;
+    S1AP_TraceStartIEs_t         *ie;
+    struct s1ap_eNB_ue_context_s *ue_desc_p;
+    struct s1ap_eNB_mme_data_s   *mme_ref_p;
+
+    DevAssert(pdu != NULL);
+
+    container = &pdu->choice.initiatingMessage.value.choice.TraceStart;
+
+    S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_TraceStartIEs_t, ie, container,
+                               S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, TRUE);
+    mme_ref_p = s1ap_eNB_get_MME(NULL, assoc_id, 0);
+    DevAssert(mme_ref_p != NULL);
+  if (ie != NULL) {
+    ue_desc_p = s1ap_eNB_get_ue_context(mme_ref_p->s1ap_eNB_instance,
+                                        ie->value.choice.ENB_UE_S1AP_ID);
   }
-
-  return 0;
+    if (ue_desc_p == NULL) {
+        /* Could not find context associated with this eNB_ue_s1ap_id -> generate
+         * trace failure indication.
+         */
+        S1AP_E_UTRAN_Trace_ID_t trace_id;
+        S1AP_Cause_t cause;
+        memset(&trace_id, 0, sizeof(S1AP_E_UTRAN_Trace_ID_t));
+        memset(&cause, 0, sizeof(S1AP_Cause_t));
+        cause.present = S1AP_Cause_PR_radioNetwork;
+        cause.choice.radioNetwork = S1AP_CauseRadioNetwork_unknown_pair_ue_s1ap_id;
+        s1ap_eNB_generate_trace_failure(NULL, &trace_id, &cause);
+    }
+
+    return 0;
 }
 
 int s1ap_eNB_handle_deactivate_trace(uint32_t         assoc_id,
                                      uint32_t         stream,
                                      S1AP_S1AP_PDU_t *message_p)
 {
-  //     S1AP_DeactivateTraceIEs_t *deactivate_trace_p;
-  //
-  //     deactivate_trace_p = &message_p->msg.deactivateTraceIEs;
+    //     S1AP_DeactivateTraceIEs_t *deactivate_trace_p;
+    //
+    //     deactivate_trace_p = &message_p->msg.deactivateTraceIEs;
 
-  return 0;
+    return 0;
 }
diff --git a/openair3/SCTP/sctp_eNB_task.c b/openair3/SCTP/sctp_eNB_task.c
index 4a44dfa2cf814db97c59d31154f5fa5af4b48de2..3fea17cc6fd8e0323d2077d0debec531c517f69c 100644
--- a/openair3/SCTP/sctp_eNB_task.c
+++ b/openair3/SCTP/sctp_eNB_task.c
@@ -59,33 +59,33 @@
 
 
 enum sctp_connection_type_e {
-  SCTP_TYPE_CLIENT,
-  SCTP_TYPE_SERVER,
-  SCTP_TYPE_MULTI_SERVER,
-  SCTP_TYPE_MAX
+    SCTP_TYPE_CLIENT,
+    SCTP_TYPE_SERVER,
+    SCTP_TYPE_MULTI_SERVER,
+    SCTP_TYPE_MAX
 };
 
 typedef struct sctp_cnx_list_elm_s {
-  STAILQ_ENTRY(sctp_cnx_list_elm_s) entries;
-
-  /* Type of this association
-   */
-  enum sctp_connection_type_e connection_type;
-
-  int        sd;              ///< Socket descriptor of connection */
-  uint16_t   local_port;
-  uint16_t   in_streams;      ///< Number of input streams negociated for this connection
-  uint16_t   out_streams;     ///< Number of output streams negotiated for this connection
-  uint16_t   ppid;            ///< Payload protocol Identifier
-  int32_t    assoc_id;        ///< SCTP association id for the connection     (note4debug host byte order)
-  uint32_t   messages_recv;   ///< Number of messages received on this connection
-  uint32_t   messages_sent;   ///< Number of messages sent on this connection
-  task_id_t  task_id;         ///< Task id of the task who asked for this connection
-  instance_t instance;        ///< Instance
-  uint16_t   cnx_id;          ///< Upper layer identifier
-
-  struct   sockaddr *peer_addresses;///< A list of peer addresses for server socket
-  int      nb_peer_addresses; ///< For server socket
+    STAILQ_ENTRY(sctp_cnx_list_elm_s) entries;
+
+    /* Type of this association
+     */
+    enum sctp_connection_type_e connection_type;
+
+    int        sd;              ///< Socket descriptor of connection */
+    uint16_t   local_port;
+    uint16_t   in_streams;      ///< Number of input streams negociated for this connection
+    uint16_t   out_streams;     ///< Number of output streams negotiated for this connection
+    uint16_t   ppid;            ///< Payload protocol Identifier
+    int32_t    assoc_id;        ///< SCTP association id for the connection     (note4debug host byte order)
+    uint32_t   messages_recv;   ///< Number of messages received on this connection
+    uint32_t   messages_sent;   ///< Number of messages sent on this connection
+    task_id_t  task_id;         ///< Task id of the task who asked for this connection
+    instance_t instance;        ///< Instance
+    uint16_t   cnx_id;          ///< Upper layer identifier
+
+    struct   sockaddr *peer_addresses;///< A list of peer addresses for server socket
+    int      nb_peer_addresses; ///< For server socket
 } sctp_cnx_list_elm_t;
 
 
@@ -95,960 +95,963 @@ static uint16_t sctp_nb_cnx = 0;
 //------------------------------------------------------------------------------
 struct sctp_cnx_list_elm_s *sctp_get_cnx(int32_t assoc_id, int sd)
 {
-  struct sctp_cnx_list_elm_s *elm;
+    struct sctp_cnx_list_elm_s *elm;
 
-  STAILQ_FOREACH(elm, &sctp_cnx_list, entries) {
-    if (assoc_id != -1) {
-      if (elm->assoc_id == assoc_id) {
-        return elm;
-      }
-    } else {
-      if (elm->sd == sd) {
-        return elm;
-      }
+    STAILQ_FOREACH(elm, &sctp_cnx_list, entries) {
+        if (assoc_id != -1) {
+            if (elm->assoc_id == assoc_id) {
+                return elm;
+            }
+        } else {
+            if (elm->sd == sd) {
+                return elm;
+            }
+        }
     }
-  }
 
-  return NULL;
+    return NULL;
 }
 
 //------------------------------------------------------------------------------
 static inline
 void
 sctp_eNB_accept_associations_multi(
-  struct sctp_cnx_list_elm_s *sctp_cnx)
+    struct sctp_cnx_list_elm_s *sctp_cnx)
 {
-  int                    ns;
-  int                    n;
-  int                    flags = 0;
-  socklen_t              from_len;
-  struct sctp_sndrcvinfo sinfo;
+    int                    ns;
+    int                    n;
+    int                    flags = 0;
+    socklen_t              from_len;
+    struct sctp_sndrcvinfo sinfo;
 
-  struct sockaddr_in addr;
-  uint8_t buffer[SCTP_RECV_BUFFER_SIZE];
+    struct sockaddr_in addr;
+    uint8_t buffer[SCTP_RECV_BUFFER_SIZE];
 
-  DevAssert(sctp_cnx != NULL);
+    DevAssert(sctp_cnx != NULL);
 
-  memset((void *)&addr, 0, sizeof(struct sockaddr_in));
-  from_len = (socklen_t)sizeof(struct sockaddr_in);
-  memset((void *)&sinfo, 0, sizeof(struct sctp_sndrcvinfo));
+    memset((void *)&addr, 0, sizeof(struct sockaddr_in));
+    from_len = (socklen_t)sizeof(struct sockaddr_in);
+    memset((void *)&sinfo, 0, sizeof(struct sctp_sndrcvinfo));
 
-  n = sctp_recvmsg(sctp_cnx->sd, (void *)buffer, SCTP_RECV_BUFFER_SIZE,
-                   (struct sockaddr *)&addr, &from_len,
-                   &sinfo, &flags);
+    n = sctp_recvmsg(sctp_cnx->sd, (void *)buffer, SCTP_RECV_BUFFER_SIZE,
+                     (struct sockaddr *)&addr, &from_len,
+                     &sinfo, &flags);
 
-  if (n < 0) {
-    if (errno == ENOTCONN) {
-      SCTP_DEBUG("Received not connected for sd %d\n", sctp_cnx->sd);
-      close(sctp_cnx->sd);
-    } else {
-      SCTP_DEBUG("An error occured during read\n");
-      SCTP_ERROR("sctp_recvmsg (fd %d, len %d ): %s:%d\n", sctp_cnx->sd, n, strerror(errno), errno);
+    if (n < 0) {
+        if (errno == ENOTCONN) {
+            SCTP_DEBUG("Received not connected for sd %d\n", sctp_cnx->sd);
+            close(sctp_cnx->sd);
+        } else {
+            SCTP_DEBUG("An error occured during read\n");
+            SCTP_ERROR("sctp_recvmsg (fd %d, len %d ): %s:%d\n", sctp_cnx->sd, n, strerror(errno), errno);
+        }
+        return;
     }
-    return;
-  }
 
-  if (flags & MSG_NOTIFICATION) {
-    union sctp_notification *snp;
-    snp = (union sctp_notification *)buffer;
+    if (flags & MSG_NOTIFICATION) {
+        union sctp_notification *snp;
+        snp = (union sctp_notification *)buffer;
 
-    SCTP_DEBUG("Received notification for sd %d, type %u\n",
-               sctp_cnx->sd, snp->sn_header.sn_type);
+        SCTP_DEBUG("Received notification for sd %d, type %u\n",
+                   sctp_cnx->sd, snp->sn_header.sn_type);
 
-    /* Association has changed. */
-    if (SCTP_ASSOC_CHANGE == snp->sn_header.sn_type) {
-      struct sctp_assoc_change *sctp_assoc_changed;
-      sctp_assoc_changed = &snp->sn_assoc_change;
+        /* Association has changed. */
+        if (SCTP_ASSOC_CHANGE == snp->sn_header.sn_type) {
+            struct sctp_assoc_change *sctp_assoc_changed;
+            sctp_assoc_changed = &snp->sn_assoc_change;
 
-      SCTP_DEBUG("Client association changed: %d\n", sctp_assoc_changed->sac_state);
+            SCTP_DEBUG("Client association changed: %d\n", sctp_assoc_changed->sac_state);
 
-      /* New physical association requested by a peer */
-      switch (sctp_assoc_changed->sac_state) {
-      case SCTP_COMM_UP: {
-        SCTP_DEBUG("Comm up notified for sd %d, assigned assoc_id %d\n",
-                   sctp_cnx->sd, sctp_assoc_changed->sac_assoc_id);
-          struct sctp_cnx_list_elm_s *new_cnx;
+            /* New physical association requested by a peer */
+            switch (sctp_assoc_changed->sac_state) {
+            case SCTP_COMM_UP: {
+                SCTP_DEBUG("Comm up notified for sd %d, assigned assoc_id %d\n",
+                           sctp_cnx->sd, sctp_assoc_changed->sac_assoc_id);
+                struct sctp_cnx_list_elm_s *new_cnx;
 
-          new_cnx = calloc(1, sizeof(*sctp_cnx));
+                new_cnx = calloc(1, sizeof(*sctp_cnx));
 
-	  DevAssert(new_cnx != NULL);
+                DevAssert(new_cnx != NULL);
 
-	  new_cnx->connection_type = SCTP_TYPE_CLIENT;
+                new_cnx->connection_type = SCTP_TYPE_CLIENT;
 
-          ns = sctp_peeloff(sctp_cnx->sd, sctp_assoc_changed->sac_assoc_id);
+                ns = sctp_peeloff(sctp_cnx->sd, sctp_assoc_changed->sac_assoc_id);
 
-	  new_cnx->sd         = ns;
-	  new_cnx->task_id    = sctp_cnx->task_id;
-          new_cnx->cnx_id     = 0;
-	  new_cnx->ppid       = sctp_cnx->ppid;
-	  new_cnx->instance   = sctp_cnx->instance;
-	  new_cnx->local_port = sctp_cnx->local_port;
-          new_cnx->assoc_id   = sctp_assoc_changed->sac_assoc_id;
+                new_cnx->sd         = ns;
+                new_cnx->task_id    = sctp_cnx->task_id;
+                new_cnx->cnx_id     = 0;
+                new_cnx->ppid       = sctp_cnx->ppid;
+                new_cnx->instance   = sctp_cnx->instance;
+                new_cnx->local_port = sctp_cnx->local_port;
+                new_cnx->assoc_id   = sctp_assoc_changed->sac_assoc_id;
 
-          if (sctp_get_sockinfo(ns, &new_cnx->in_streams, &new_cnx->out_streams,
-                                &new_cnx->assoc_id) != 0) {
-            SCTP_ERROR("sctp_get_sockinfo failed\n");
-            close(ns);
-            free(new_cnx);
-            return;
-          }
+                if (sctp_get_sockinfo(ns, &new_cnx->in_streams, &new_cnx->out_streams,
+                                      &new_cnx->assoc_id) != 0) {
+                    SCTP_ERROR("sctp_get_sockinfo failed\n");
+                    close(ns);
+                    free(new_cnx);
+                    return;
+                }
 
-	  /* Insert new element at end of list */
-	  STAILQ_INSERT_TAIL(&sctp_cnx_list, new_cnx, entries);
-          sctp_nb_cnx++;
+                /* Insert new element at end of list */
+                STAILQ_INSERT_TAIL(&sctp_cnx_list, new_cnx, entries);
+                sctp_nb_cnx++;
 
-	  /* Add the socket to list of fd monitored by ITTI */
-	  itti_subscribe_event_fd(TASK_SCTP, ns);
+                /* Add the socket to list of fd monitored by ITTI */
+                itti_subscribe_event_fd(TASK_SCTP, ns);
 
-	  sctp_itti_send_association_ind(new_cnx->task_id, new_cnx->instance,
-                                          new_cnx->assoc_id, new_cnx->local_port,
-                                          new_cnx->out_streams, new_cnx->in_streams);
-      }
-      break;
+                sctp_itti_send_association_ind(new_cnx->task_id, new_cnx->instance,
+                                               new_cnx->assoc_id, new_cnx->local_port,
+                                               new_cnx->out_streams, new_cnx->in_streams);
+            }
+            break;
 
-      default:
-        break;
-      }
+            default:
+                break;
+            }
+        }
+    } else {
+        SCTP_DEBUG("No notification from SCTP\n");
     }
-  } else {
-       SCTP_DEBUG("No notification from SCTP\n");
-  }
 }
 
 //------------------------------------------------------------------------------
 void
 sctp_handle_new_association_req_multi(
-  const instance_t instance,
-  const task_id_t requestor,
-  const sctp_new_association_req_multi_t * const sctp_new_association_req_p)
+    const instance_t instance,
+    const task_id_t requestor,
+    const sctp_new_association_req_multi_t * const sctp_new_association_req_p)
 {
-  int                           ns;
-  int sd;
+    int                           ns;
+    int sd;
 
-  int32_t                       assoc_id = 0;
+    int32_t                       assoc_id = 0;
 
-  struct sctp_cnx_list_elm_s   *sctp_cnx = NULL;
-  enum sctp_connection_type_e   connection_type = SCTP_TYPE_CLIENT;
+    struct sctp_cnx_list_elm_s   *sctp_cnx = NULL;
+    enum sctp_connection_type_e   connection_type = SCTP_TYPE_CLIENT;
 
-  /* Prepare a new SCTP association as requested by upper layer and try to connect
-   * to remote host.
-   */
-  DevAssert(sctp_new_association_req_p != NULL);
+    /* Prepare a new SCTP association as requested by upper layer and try to connect
+     * to remote host.
+     */
+    DevAssert(sctp_new_association_req_p != NULL);
 
-  sd = sctp_new_association_req_p->multi_sd;
+    sd = sctp_new_association_req_p->multi_sd;
 
-  /* Create new socket with IPv6 affinity */
+    /* Create new socket with IPv6 affinity */
 //#warning "SCTP may Force IPv4 only, here"
 
-  /* Mark the socket as non-blocking */
-  //if (fcntl(sd, F_SETFL, O_NONBLOCK) < 0) {
+    /* Mark the socket as non-blocking */
+    //if (fcntl(sd, F_SETFL, O_NONBLOCK) < 0) {
     //SCTP_ERROR("fcntl F_SETFL O_NONBLOCK failed: %s\n",
-      //         strerror(errno));
+    //         strerror(errno));
     //close(sd);
     //return;
-  //}
-
-  /* SOCK_STREAM socket type requires an explicit connect to the remote host
-   * address and port.
-   * Only use IPv4 for the first connection attempt
-   */
-  if ((sctp_new_association_req_p->remote_address.ipv6 != 0) ||
-      (sctp_new_association_req_p->remote_address.ipv4 != 0)) {
-    uint8_t address_index = 0;
-    uint8_t used_address  = sctp_new_association_req_p->remote_address.ipv6 +
-                            sctp_new_association_req_p->remote_address.ipv4;
-    struct sockaddr_in addr[used_address];
-
-    memset(addr, 0, used_address * sizeof(struct sockaddr_in));
-
-    if (sctp_new_association_req_p->remote_address.ipv6 == 1) {
-      if (inet_pton(AF_INET6, sctp_new_association_req_p->remote_address.ipv6_address,
-                    &addr[address_index].sin_addr.s_addr) != 1) {
-        SCTP_ERROR("Failed to convert ipv6 address %*s to network type\n",
-                   (int)strlen(sctp_new_association_req_p->remote_address.ipv6_address),
-                   sctp_new_association_req_p->remote_address.ipv6_address);
-        //close(sd);
-        //return;
-        exit(1);
-      }
-
-      SCTP_DEBUG("Converted ipv6 address %*s to network type\n",
-                 (int)strlen(sctp_new_association_req_p->remote_address.ipv6_address),
-                 sctp_new_association_req_p->remote_address.ipv6_address);
-
-      addr[address_index].sin_family = AF_INET6;
-      addr[address_index].sin_port   = htons(sctp_new_association_req_p->port);
-      address_index++;
-    }
+    //}
 
-    if (sctp_new_association_req_p->remote_address.ipv4 == 1) {
-      if (inet_pton(AF_INET, sctp_new_association_req_p->remote_address.ipv4_address,
-                    &addr[address_index].sin_addr.s_addr) != 1) {
-        SCTP_ERROR("Failed to convert ipv4 address %*s to network type\n",
-                   (int)strlen(sctp_new_association_req_p->remote_address.ipv4_address),
-                   sctp_new_association_req_p->remote_address.ipv4_address);
-        //close(sd);
-        //return;
-        exit(1);
-      }
-
-      SCTP_DEBUG("Converted ipv4 address %*s to network type\n",
-                 (int)strlen(sctp_new_association_req_p->remote_address.ipv4_address),
-                 sctp_new_association_req_p->remote_address.ipv4_address);
-
-      addr[address_index].sin_family = AF_INET;
-      addr[address_index].sin_port   = htons(sctp_new_association_req_p->port);
-      address_index++;
-    }
+    /* SOCK_STREAM socket type requires an explicit connect to the remote host
+     * address and port.
+     * Only use IPv4 for the first connection attempt
+     */
+    if ((sctp_new_association_req_p->remote_address.ipv6 != 0) ||
+            (sctp_new_association_req_p->remote_address.ipv4 != 0)) {
+        uint8_t address_index = 0;
+        uint8_t used_address  = sctp_new_association_req_p->remote_address.ipv6 +
+                                sctp_new_association_req_p->remote_address.ipv4;
+        struct sockaddr_in addr[used_address];
+
+        memset(addr, 0, used_address * sizeof(struct sockaddr_in));
+
+        if (sctp_new_association_req_p->remote_address.ipv6 == 1) {
+            if (inet_pton(AF_INET6, sctp_new_association_req_p->remote_address.ipv6_address,
+                          &addr[address_index].sin_addr.s_addr) != 1) {
+                SCTP_ERROR("Failed to convert ipv6 address %*s to network type\n",
+                           (int)strlen(sctp_new_association_req_p->remote_address.ipv6_address),
+                           sctp_new_association_req_p->remote_address.ipv6_address);
+                //close(sd);
+                //return;
+                exit(1);
+            }
+
+            SCTP_DEBUG("Converted ipv6 address %*s to network type\n",
+                       (int)strlen(sctp_new_association_req_p->remote_address.ipv6_address),
+                       sctp_new_association_req_p->remote_address.ipv6_address);
+
+            addr[address_index].sin_family = AF_INET6;
+            addr[address_index].sin_port   = htons(sctp_new_association_req_p->port);
+            address_index++;
+        }
 
-    /* Connect to remote host and port */
-    if (sctp_connectx(sd, (struct sockaddr *)addr, 1, &assoc_id) < 0) {
-      /* sctp_connectx on non-blocking socket return EINPROGRESS */
-      if (errno != EINPROGRESS) {
-        SCTP_ERROR("Connect failed: %s\n", strerror(errno));
-        sctp_itti_send_association_resp(
-          requestor, instance, -1, sctp_new_association_req_p->ulp_cnx_id,
-          SCTP_STATE_UNREACHABLE, 0, 0);
-        /* Add the socket to list of fd monitored by ITTI */
-        //itti_unsubscribe_event_fd(TASK_SCTP, sd);
-        //close(sd);
-        return;
-      } else {
-        SCTP_DEBUG("connectx assoc_id  %d in progress..., used %d addresses\n",
-                   assoc_id, used_address);
-      }
-    } else {
-      SCTP_DEBUG("sctp_connectx SUCCESS, used %d addresses assoc_id %d\n",
-                 used_address,
-                 assoc_id);
+        if (sctp_new_association_req_p->remote_address.ipv4 == 1) {
+            if (inet_pton(AF_INET, sctp_new_association_req_p->remote_address.ipv4_address,
+                          &addr[address_index].sin_addr.s_addr) != 1) {
+                SCTP_ERROR("Failed to convert ipv4 address %*s to network type\n",
+                           (int)strlen(sctp_new_association_req_p->remote_address.ipv4_address),
+                           sctp_new_association_req_p->remote_address.ipv4_address);
+                //close(sd);
+                //return;
+                exit(1);
+            }
+
+            SCTP_DEBUG("Converted ipv4 address %*s to network type\n",
+                       (int)strlen(sctp_new_association_req_p->remote_address.ipv4_address),
+                       sctp_new_association_req_p->remote_address.ipv4_address);
+
+            addr[address_index].sin_family = AF_INET;
+            addr[address_index].sin_port   = htons(sctp_new_association_req_p->port);
+            address_index++;
+        }
+
+        /* Connect to remote host and port */
+        if (sctp_connectx(sd, (struct sockaddr *)addr, 1, &assoc_id) < 0) {
+            /* sctp_connectx on non-blocking socket return EINPROGRESS */
+            if (errno != EINPROGRESS) {
+                SCTP_ERROR("Connect failed: %s\n", strerror(errno));
+                sctp_itti_send_association_resp(
+                    requestor, instance, -1, sctp_new_association_req_p->ulp_cnx_id,
+                    SCTP_STATE_UNREACHABLE, 0, 0);
+                /* Add the socket to list of fd monitored by ITTI */
+                //itti_unsubscribe_event_fd(TASK_SCTP, sd);
+                //close(sd);
+                return;
+            } else {
+                SCTP_DEBUG("connectx assoc_id  %d in progress..., used %d addresses\n",
+                           assoc_id, used_address);
+            }
+        } else {
+            SCTP_DEBUG("sctp_connectx SUCCESS, used %d addresses assoc_id %d\n",
+                       used_address,
+                       assoc_id);
+        }
     }
-  }
 
-  ns = sctp_peeloff(sd,assoc_id);
+    ns = sctp_peeloff(sd,assoc_id);
 
-  sctp_cnx = calloc(1, sizeof(*sctp_cnx));
+    sctp_cnx = calloc(1, sizeof(*sctp_cnx));
 
-  sctp_cnx->connection_type = connection_type;
+    sctp_cnx->connection_type = connection_type;
 
-  sctp_cnx->sd       = ns;
-  sctp_cnx->task_id  = requestor;
-  sctp_cnx->cnx_id   = sctp_new_association_req_p->ulp_cnx_id;
-  sctp_cnx->ppid     = sctp_new_association_req_p->ppid;
-  sctp_cnx->instance = instance;
-  sctp_cnx->assoc_id = assoc_id;
+    sctp_cnx->sd       = ns;
+    sctp_cnx->task_id  = requestor;
+    sctp_cnx->cnx_id   = sctp_new_association_req_p->ulp_cnx_id;
+    sctp_cnx->ppid     = sctp_new_association_req_p->ppid;
+    sctp_cnx->instance = instance;
+    sctp_cnx->assoc_id = assoc_id;
 
-  /* Add the socket to list of fd monitored by ITTI */
-  itti_subscribe_event_fd(TASK_SCTP, ns);
+    /* Add the socket to list of fd monitored by ITTI */
+    itti_subscribe_event_fd(TASK_SCTP, ns);
 
-  /* Insert new element at end of list */
-  STAILQ_INSERT_TAIL(&sctp_cnx_list, sctp_cnx, entries);
-  sctp_nb_cnx++;
+    /* Insert new element at end of list */
+    STAILQ_INSERT_TAIL(&sctp_cnx_list, sctp_cnx, entries);
+    sctp_nb_cnx++;
 
-  SCTP_DEBUG("Inserted new descriptor for sd %d in list, nb elements %u, assoc_id %d\n",
-             ns, sctp_nb_cnx, assoc_id);
+    SCTP_DEBUG("Inserted new descriptor for sd %d in list, nb elements %u, assoc_id %d\n",
+               ns, sctp_nb_cnx, assoc_id);
 }
 
 //------------------------------------------------------------------------------
 void
 sctp_handle_new_association_req(
-  const instance_t instance,
-  const task_id_t requestor,
-  const sctp_new_association_req_t * const sctp_new_association_req_p)
+    const instance_t instance,
+    const task_id_t requestor,
+    const sctp_new_association_req_t * const sctp_new_association_req_p)
 {
-  int                           sd       = 0;
-  int32_t                       assoc_id = 0;
-
-  struct sctp_event_subscribe   events;
-
-  struct sctp_cnx_list_elm_s   *sctp_cnx = NULL;
-  enum sctp_connection_type_e   connection_type = SCTP_TYPE_CLIENT;
-
-  struct ifreq                  ifr;
-  struct ifaddrs               *ifaddr = NULL;
-  struct ifaddrs               *ifa    = NULL;
-  int                           family = 0;
-  int                           s = 0;
-  struct in_addr                in;
-  struct in6_addr               in6;
-  /* Prepare a new SCTP association as requested by upper layer and try to connect
-   * to remote host.
-   */
-  DevAssert(sctp_new_association_req_p != NULL);
-
-  /* Create new socket with IPv6 affinity */
+    int                           sd       = 0;
+    int32_t                       assoc_id = 0;
+
+    struct sctp_event_subscribe   events;
+
+    struct sctp_cnx_list_elm_s   *sctp_cnx = NULL;
+    enum sctp_connection_type_e   connection_type = SCTP_TYPE_CLIENT;
+
+    struct ifreq                  ifr;
+    struct ifaddrs               *ifaddr = NULL;
+    struct ifaddrs               *ifa    = NULL;
+    int                           family = 0;
+    int                           s = 0;
+    struct in_addr                in;
+    struct in6_addr               in6;
+    /* Prepare a new SCTP association as requested by upper layer and try to connect
+     * to remote host.
+     */
+    DevAssert(sctp_new_association_req_p != NULL);
+
+    /* Create new socket with IPv6 affinity */
 //#warning "SCTP may Force IPv4 only, here"
 #ifdef NO_VIRTUAL_MACHINE
 
-  // in init chunk appears a list of host addresses, IPv4 and IPv4 in an arbitrary (unsorted) order
-  // SCTP hearbeats starts with first ipv4 addresses then stop triyng with other ipv4 addresses
-  // if it encounters an IPv6 address in list, so we can force the building of IPv4 addresses only
-  // with AF_INET (the working IPv4 address can be the last in the list...)
-  if ((sd = socket(AF_INET6, SOCK_STREAM, IPPROTO_SCTP)) < 0) {
+    // in init chunk appears a list of host addresses, IPv4 and IPv4 in an arbitrary (unsorted) order
+    // SCTP hearbeats starts with first ipv4 addresses then stop triyng with other ipv4 addresses
+    // if it encounters an IPv6 address in list, so we can force the building of IPv4 addresses only
+    // with AF_INET (the working IPv4 address can be the last in the list...)
+    if ((sd = socket(AF_INET6, SOCK_STREAM, IPPROTO_SCTP)) < 0) {
 #else
 
-  if ((sd = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP)) < 0) {
+    if ((sd = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP)) < 0) {
 #endif
-    SCTP_ERROR("Socket creation failed: %s\n", strerror(errno));
-    return;
-  }
-
-  /* Add the socket to list of fd monitored by ITTI */
-  itti_subscribe_event_fd(TASK_SCTP, sd);
-
-  if (sctp_set_init_opt(sd,
-		  sctp_new_association_req_p->in_streams,
-		  sctp_new_association_req_p->out_streams,
-		  SCTP_MAX_ATTEMPTS, SCTP_TIMEOUT) != 0) {
-    SCTP_ERROR("Setsockopt IPPROTO_SCTP_INITMSG failed: %s\n",
-               strerror(errno));
-    itti_unsubscribe_event_fd(TASK_SCTP, sd);
-    close(sd);
-    return;
-  }
-
-  /* Subscribe to all events */
-  memset((void *)&events, 1, sizeof(struct sctp_event_subscribe));
-
-  if (setsockopt(sd, IPPROTO_SCTP, SCTP_EVENTS, &events,
-                 sizeof(struct sctp_event_subscribe)) < 0) {
-    SCTP_ERROR("Setsockopt IPPROTO_SCTP_EVENTS failed: %s\n",
-               strerror(errno));
-    close(sd);
-    return;
-  }
-
-  // Bind to device ... or we could bind to address also
-  if (getifaddrs(&ifaddr) == -1) {
-    SCTP_ERROR("getifaddrs failed: %s\n", strerror(errno));
-    close(sd);
-  }
-
-  /* Walk through linked list, maintaining head pointer so we
-     can free list later */
-  for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
-    if (ifa->ifa_addr == NULL)
-      continue;
-
-    family = ifa->ifa_addr->sa_family;
-
-    /* For an AF_INET* interface address, display the address */
-    if (sctp_new_association_req_p->local_address.ipv4 && family == AF_INET) {
-      // compare address
-      s = inet_aton(sctp_new_association_req_p->local_address.ipv4_address,
-                    &in);
-
-      if (s > 0 ) {
-        if (((struct sockaddr_in*)ifa->ifa_addr)->sin_addr.s_addr == in.s_addr) {
-          struct sockaddr_in locaddr;
-          locaddr.sin_family = AF_INET;
-          locaddr.sin_port = htons(sctp_new_association_req_p->port);
-          locaddr.sin_addr.s_addr = in.s_addr;
-
-          if (sctp_bindx(sd, (struct sockaddr*)&locaddr, 1, SCTP_BINDX_ADD_ADDR) < 0) {
-            SCTP_ERROR("sctp_bindx SCTP_BINDX_ADD_ADDR failed: %s\n",
-                       strerror(errno));
-          } else {
-            SCTP_DEBUG("sctp_bindx SCTP_BINDX_ADD_ADDR socket bound to : %s\n",
-                       inet_ntoa(locaddr.sin_addr));
-          }
-          break;
-
-        }
-      }
-    } else if (sctp_new_association_req_p->local_address.ipv6 && family == AF_INET6) {
-      // compare address
-      s = inet_pton(AF_INET6,
-                    sctp_new_association_req_p->local_address.ipv6_address,
-                    &in6);
-
-      if (s == 1 ) {
-        if (memcmp(&((struct sockaddr_in6*)ifa->ifa_addr)->sin6_addr,
-                   &in6, sizeof(in6)) == 0) {
-          memset(&ifr, 0, sizeof(ifr));
-          snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", ifa->ifa_name);
-
-          if (setsockopt(sd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(ifr)) < 0) {
-            SCTP_ERROR("Setsockopt SOL_SOCKET failed: %s\n",
-                       strerror(errno));
-          } else {
-            SCTP_DEBUG("Setsockopt SOL_SOCKET socket bound to : %s\n",
-                       ifa->ifa_name);
-          }
-
-          break;
-        }
-      }
+        SCTP_ERROR("Socket creation failed: %s\n", strerror(errno));
+        return;
     }
-  }
-
-  freeifaddrs(ifaddr);
-
-  /* Mark the socket as non-blocking */
-  if (fcntl(sd, F_SETFL, O_NONBLOCK) < 0) {
-    SCTP_ERROR("fcntl F_SETFL O_NONBLOCK failed: %s\n",
-               strerror(errno));
-    close(sd);
-    return;
-  }
-
-  /* SOCK_STREAM socket type requires an explicit connect to the remote host
-   * address and port.
-   * Only use IPv4 for the first connection attempt
-   */
-  if ((sctp_new_association_req_p->remote_address.ipv6 != 0) ||
-      (sctp_new_association_req_p->remote_address.ipv4 != 0)) {
-    uint8_t address_index = 0;
-    uint8_t used_address  = sctp_new_association_req_p->remote_address.ipv6 +
-                            sctp_new_association_req_p->remote_address.ipv4;
-    struct sockaddr_in addr[used_address];
-
-    memset(addr, 0, used_address * sizeof(struct sockaddr_in));
-
-    if (sctp_new_association_req_p->remote_address.ipv6 == 1) {
-      if (inet_pton(AF_INET6, sctp_new_association_req_p->remote_address.ipv6_address,
-                    &addr[address_index].sin_addr.s_addr) != 1) {
-        SCTP_ERROR("Failed to convert ipv6 address %*s to network type\n",
-                   (int)strlen(sctp_new_association_req_p->remote_address.ipv6_address),
-                   sctp_new_association_req_p->remote_address.ipv6_address);
+
+    /* Add the socket to list of fd monitored by ITTI */
+    itti_subscribe_event_fd(TASK_SCTP, sd);
+
+    if (sctp_set_init_opt(sd,
+                          sctp_new_association_req_p->in_streams,
+                          sctp_new_association_req_p->out_streams,
+                          SCTP_MAX_ATTEMPTS, SCTP_TIMEOUT) != 0) {
+        SCTP_ERROR("Setsockopt IPPROTO_SCTP_INITMSG failed: %s\n",
+                   strerror(errno));
+        itti_unsubscribe_event_fd(TASK_SCTP, sd);
         close(sd);
         return;
-      }
-
-      SCTP_DEBUG("Converted ipv6 address %*s to network type\n",
-                 (int)strlen(sctp_new_association_req_p->remote_address.ipv6_address),
-                 sctp_new_association_req_p->remote_address.ipv6_address);
-
-      addr[address_index].sin_family = AF_INET6;
-      addr[address_index].sin_port   = htons(sctp_new_association_req_p->port);
-      address_index++;
     }
 
-    if (sctp_new_association_req_p->remote_address.ipv4 == 1) {
-      if (inet_pton(AF_INET, sctp_new_association_req_p->remote_address.ipv4_address,
-                    &addr[address_index].sin_addr.s_addr) != 1) {
-        SCTP_ERROR("Failed to convert ipv4 address %*s to network type\n",
-                   (int)strlen(sctp_new_association_req_p->remote_address.ipv4_address),
-                   sctp_new_association_req_p->remote_address.ipv4_address);
+    /* Subscribe to all events */
+    memset((void *)&events, 1, sizeof(struct sctp_event_subscribe));
+
+    if (setsockopt(sd, IPPROTO_SCTP, SCTP_EVENTS, &events,
+                   sizeof(struct sctp_event_subscribe)) < 0) {
+        SCTP_ERROR("Setsockopt IPPROTO_SCTP_EVENTS failed: %s\n",
+                   strerror(errno));
         close(sd);
         return;
-      }
+    }
 
-      SCTP_DEBUG("Converted ipv4 address %*s to network type\n",
-                 (int)strlen(sctp_new_association_req_p->remote_address.ipv4_address),
-                 sctp_new_association_req_p->remote_address.ipv4_address);
+    // Bind to device ... or we could bind to address also
+    if (getifaddrs(&ifaddr) == -1) {
+        SCTP_ERROR("getifaddrs failed: %s\n", strerror(errno));
+        close(sd);
+    }
 
-      addr[address_index].sin_family = AF_INET;
-      addr[address_index].sin_port   = htons(sctp_new_association_req_p->port);
-      address_index++;
+    /* Walk through linked list, maintaining head pointer so we
+       can free list later */
+    for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
+        if (ifa->ifa_addr == NULL)
+            continue;
+
+        family = ifa->ifa_addr->sa_family;
+
+        /* For an AF_INET* interface address, display the address */
+        if (sctp_new_association_req_p->local_address.ipv4 && family == AF_INET) {
+            // compare address
+            s = inet_aton(sctp_new_association_req_p->local_address.ipv4_address,
+                          &in);
+
+            if (s > 0 ) {
+                if (((struct sockaddr_in*)ifa->ifa_addr)->sin_addr.s_addr == in.s_addr) {
+                    struct sockaddr_in locaddr;
+                    locaddr.sin_family = AF_INET;
+                    locaddr.sin_port = htons(sctp_new_association_req_p->port);
+                    locaddr.sin_addr.s_addr = in.s_addr;
+
+                    if (sctp_bindx(sd, (struct sockaddr*)&locaddr, 1, SCTP_BINDX_ADD_ADDR) < 0) {
+                        SCTP_ERROR("sctp_bindx SCTP_BINDX_ADD_ADDR failed: %s\n",
+                                   strerror(errno));
+                    } else {
+                        SCTP_DEBUG("sctp_bindx SCTP_BINDX_ADD_ADDR socket bound to : %s\n",
+                                   inet_ntoa(locaddr.sin_addr));
+                    }
+                    break;
+
+                }
+            }
+        } else if (sctp_new_association_req_p->local_address.ipv6 && family == AF_INET6) {
+            // compare address
+            s = inet_pton(AF_INET6,
+                          sctp_new_association_req_p->local_address.ipv6_address,
+                          &in6);
+
+            if (s == 1 ) {
+                if (memcmp(&((struct sockaddr_in6*)ifa->ifa_addr)->sin6_addr,
+                           &in6, sizeof(in6)) == 0) {
+                    memset(&ifr, 0, sizeof(ifr));
+                    snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", ifa->ifa_name);
+
+                    if (setsockopt(sd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(ifr)) < 0) {
+                        SCTP_ERROR("Setsockopt SOL_SOCKET failed: %s\n",
+                                   strerror(errno));
+                    } else {
+                        SCTP_DEBUG("Setsockopt SOL_SOCKET socket bound to : %s\n",
+                                   ifa->ifa_name);
+                    }
+
+                    break;
+                }
+            }
+        }
     }
 
-    /* Connect to remote host and port */
-    if (sctp_connectx(sd, (struct sockaddr *)addr, 1, &assoc_id) < 0) {
-      /* sctp_connectx on non-blocking socket return EINPROGRESS */
-      if (errno != EINPROGRESS) {
-        SCTP_ERROR("Connect failed: %s\n", strerror(errno));
-        sctp_itti_send_association_resp(
-          requestor, instance, -1, sctp_new_association_req_p->ulp_cnx_id,
-          SCTP_STATE_UNREACHABLE, 0, 0);
-        /* Add the socket to list of fd monitored by ITTI */
-        itti_unsubscribe_event_fd(TASK_SCTP, sd);
+    freeifaddrs(ifaddr);
+
+    /* Mark the socket as non-blocking */
+    if (fcntl(sd, F_SETFL, O_NONBLOCK) < 0) {
+        SCTP_ERROR("fcntl F_SETFL O_NONBLOCK failed: %s\n",
+                   strerror(errno));
         close(sd);
         return;
-      } else {
-        SCTP_DEBUG("connectx assoc_id  %d in progress..., used %d addresses\n",
-                   assoc_id, used_address);
-      }
-    } else {
-      SCTP_DEBUG("sctp_connectx SUCCESS, used %d addresses assoc_id %d\n",
-                 used_address,
-                 assoc_id);
     }
-  } else {
-    /* No remote address provided -> only bind the socket for now.
-     * Connection will be accepted in the main event loop
+
+    /* SOCK_STREAM socket type requires an explicit connect to the remote host
+     * address and port.
+     * Only use IPv4 for the first connection attempt
      */
-    struct sockaddr_in6 addr6;
+    if ((sctp_new_association_req_p->remote_address.ipv6 != 0) ||
+            (sctp_new_association_req_p->remote_address.ipv4 != 0)) {
+        uint8_t address_index = 0;
+        uint8_t used_address  = sctp_new_association_req_p->remote_address.ipv6 +
+                                sctp_new_association_req_p->remote_address.ipv4;
+        struct sockaddr_in addr[used_address];
+
+        memset(addr, 0, used_address * sizeof(struct sockaddr_in));
+
+        if (sctp_new_association_req_p->remote_address.ipv6 == 1) {
+            if (inet_pton(AF_INET6, sctp_new_association_req_p->remote_address.ipv6_address,
+                          &addr[address_index].sin_addr.s_addr) != 1) {
+                SCTP_ERROR("Failed to convert ipv6 address %*s to network type\n",
+                           (int)strlen(sctp_new_association_req_p->remote_address.ipv6_address),
+                           sctp_new_association_req_p->remote_address.ipv6_address);
+                close(sd);
+                return;
+            }
+
+            SCTP_DEBUG("Converted ipv6 address %*s to network type\n",
+                       (int)strlen(sctp_new_association_req_p->remote_address.ipv6_address),
+                       sctp_new_association_req_p->remote_address.ipv6_address);
+
+            addr[address_index].sin_family = AF_INET6;
+            addr[address_index].sin_port   = htons(sctp_new_association_req_p->port);
+            address_index++;
+        }
 
-    connection_type = SCTP_TYPE_SERVER;
+        if (sctp_new_association_req_p->remote_address.ipv4 == 1) {
+            if (inet_pton(AF_INET, sctp_new_association_req_p->remote_address.ipv4_address,
+                          &addr[address_index].sin_addr.s_addr) != 1) {
+                SCTP_ERROR("Failed to convert ipv4 address %*s to network type\n",
+                           (int)strlen(sctp_new_association_req_p->remote_address.ipv4_address),
+                           sctp_new_association_req_p->remote_address.ipv4_address);
+                close(sd);
+                return;
+            }
+
+            SCTP_DEBUG("Converted ipv4 address %*s to network type\n",
+                       (int)strlen(sctp_new_association_req_p->remote_address.ipv4_address),
+                       sctp_new_association_req_p->remote_address.ipv4_address);
+
+            addr[address_index].sin_family = AF_INET;
+            addr[address_index].sin_port   = htons(sctp_new_association_req_p->port);
+            address_index++;
+        }
+
+        /* Connect to remote host and port */
+        if (sctp_connectx(sd, (struct sockaddr *)addr, 1, &assoc_id) < 0) {
+            /* sctp_connectx on non-blocking socket return EINPROGRESS */
+            if (errno != EINPROGRESS) {
+                SCTP_ERROR("Connect failed: %s\n", strerror(errno));
+                sctp_itti_send_association_resp(
+                    requestor, instance, -1, sctp_new_association_req_p->ulp_cnx_id,
+                    SCTP_STATE_UNREACHABLE, 0, 0);
+                /* Add the socket to list of fd monitored by ITTI */
+                itti_unsubscribe_event_fd(TASK_SCTP, sd);
+                close(sd);
+                return;
+            } else {
+                SCTP_DEBUG("connectx assoc_id  %d in progress..., used %d addresses\n",
+                           assoc_id, used_address);
+            }
+        } else {
+            SCTP_DEBUG("sctp_connectx SUCCESS, used %d addresses assoc_id %d\n",
+                       used_address,
+                       assoc_id);
+        }
+    } else {
+        /* No remote address provided -> only bind the socket for now.
+         * Connection will be accepted in the main event loop
+         */
+        struct sockaddr_in6 addr6;
+
+        connection_type = SCTP_TYPE_SERVER;
 
-    /* For now bind to any interface */
-    addr6.sin6_family = AF_INET6;
-    addr6.sin6_addr = in6addr_any;
-    addr6.sin6_port = htons(sctp_new_association_req_p->port);
+        /* For now bind to any interface */
+        addr6.sin6_family = AF_INET6;
+        addr6.sin6_addr = in6addr_any;
+        addr6.sin6_port = htons(sctp_new_association_req_p->port);
 
-    if (bind(sd, (struct sockaddr*)&addr6, sizeof(addr6)) < 0) {
-      SCTP_ERROR("Failed to bind the socket to address any (v4/v6): %s\n",
-                 strerror(errno));
-      close(sd);
-      return;
+        if (bind(sd, (struct sockaddr*)&addr6, sizeof(addr6)) < 0) {
+            SCTP_ERROR("Failed to bind the socket to address any (v4/v6): %s\n",
+                       strerror(errno));
+            close(sd);
+            return;
+        }
     }
-  }
 
-  sctp_cnx = calloc(1, sizeof(*sctp_cnx));
+    sctp_cnx = calloc(1, sizeof(*sctp_cnx));
 
-  sctp_cnx->connection_type = connection_type;
+    sctp_cnx->connection_type = connection_type;
 
-  sctp_cnx->sd       = sd;
-  sctp_cnx->task_id  = requestor;
-  sctp_cnx->cnx_id   = sctp_new_association_req_p->ulp_cnx_id;
-  sctp_cnx->ppid     = sctp_new_association_req_p->ppid;
-  sctp_cnx->instance = instance;
-  sctp_cnx->assoc_id = assoc_id;
+    sctp_cnx->sd       = sd;
+    sctp_cnx->task_id  = requestor;
+    sctp_cnx->cnx_id   = sctp_new_association_req_p->ulp_cnx_id;
+    sctp_cnx->ppid     = sctp_new_association_req_p->ppid;
+    sctp_cnx->instance = instance;
+    sctp_cnx->assoc_id = assoc_id;
 
-  /* Insert new element at end of list */
-  STAILQ_INSERT_TAIL(&sctp_cnx_list, sctp_cnx, entries);
-  sctp_nb_cnx++;
+    /* Insert new element at end of list */
+    STAILQ_INSERT_TAIL(&sctp_cnx_list, sctp_cnx, entries);
+    sctp_nb_cnx++;
 
-  SCTP_DEBUG("Inserted new descriptor for sd %d in list, nb elements %u, assoc_id %d\n",
-             sd, sctp_nb_cnx, assoc_id);
+    SCTP_DEBUG("Inserted new descriptor for sd %d in list, nb elements %u, assoc_id %d\n",
+               sd, sctp_nb_cnx, assoc_id);
 }
 
-  //------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
 void sctp_send_data(
-  instance_t       instance,
-  task_id_t        task_id,
-  sctp_data_req_t *sctp_data_req_p)
+    instance_t       instance,
+    task_id_t        task_id,
+    sctp_data_req_t *sctp_data_req_p)
 {
-  struct sctp_cnx_list_elm_s *sctp_cnx = NULL;
-
-  DevAssert(sctp_data_req_p != NULL);
-  DevAssert(sctp_data_req_p->buffer != NULL);
-  DevAssert(sctp_data_req_p->buffer_length > 0);
-
-  sctp_cnx = sctp_get_cnx(sctp_data_req_p->assoc_id, 0);
-
-  if (sctp_cnx == NULL) {
-    SCTP_ERROR("Failed to find SCTP description for assoc_id %d\n",
-               sctp_data_req_p->assoc_id);
-    /* TODO: notify upper layer */
-    return;
-  }
-
-  if (sctp_data_req_p->stream >= sctp_cnx->out_streams) {
-    SCTP_ERROR("Requested stream (%"PRIu16") >= nb out streams (%"PRIu16")\n",
-               sctp_data_req_p->stream, sctp_cnx->out_streams);
-    return;
-  }
-
-  /* Send message on specified stream of the sd association
-   * NOTE: PPID should be defined in network order
-   */
-  if (sctp_sendmsg(sctp_cnx->sd, sctp_data_req_p->buffer,
-                   sctp_data_req_p->buffer_length, NULL, 0,
-                   htonl(sctp_cnx->ppid), 0, sctp_data_req_p->stream, 0, 0) < 0) {
-    SCTP_ERROR("Sctp_sendmsg failed: %s\n", strerror(errno));
-    /* TODO: notify upper layer */
-    return;
-  }
-
-  SCTP_DEBUG("Successfully sent %u bytes on stream %d for assoc_id %u\n",
-             sctp_data_req_p->buffer_length, sctp_data_req_p->stream,
-             sctp_cnx->assoc_id);
+    struct sctp_cnx_list_elm_s *sctp_cnx = NULL;
+
+    DevAssert(sctp_data_req_p != NULL);
+    DevAssert(sctp_data_req_p->buffer != NULL);
+    DevAssert(sctp_data_req_p->buffer_length > 0);
+
+    sctp_cnx = sctp_get_cnx(sctp_data_req_p->assoc_id, 0);
+
+    if (sctp_cnx == NULL) {
+        SCTP_ERROR("Failed to find SCTP description for assoc_id %d\n",
+                   sctp_data_req_p->assoc_id);
+        /* TODO: notify upper layer */
+        return;
+    }
+
+    if (sctp_data_req_p->stream >= sctp_cnx->out_streams) {
+        SCTP_ERROR("Requested stream (%"PRIu16") >= nb out streams (%"PRIu16")\n",
+                   sctp_data_req_p->stream, sctp_cnx->out_streams);
+        return;
+    }
+
+    /* Send message on specified stream of the sd association
+     * NOTE: PPID should be defined in network order
+     */
+    if (sctp_sendmsg(sctp_cnx->sd, sctp_data_req_p->buffer,
+                     sctp_data_req_p->buffer_length, NULL, 0,
+                     htonl(sctp_cnx->ppid), 0, sctp_data_req_p->stream, 0, 0) < 0) {
+        SCTP_ERROR("Sctp_sendmsg failed: %s\n", strerror(errno));
+        /* TODO: notify upper layer */
+        return;
+    }
+
+    SCTP_DEBUG("Successfully sent %u bytes on stream %d for assoc_id %u\n",
+               sctp_data_req_p->buffer_length, sctp_data_req_p->stream,
+               sctp_cnx->assoc_id);
 }
 
 //------------------------------------------------------------------------------
 static int sctp_close_association(
-  const instance_t instance,
-  const task_id_t  requestor,
-  sctp_close_association_t     *close_association_p)
+    const instance_t instance,
+    const task_id_t  requestor,
+    sctp_close_association_t     *close_association_p)
 {
 
-  struct sctp_cnx_list_elm_s *sctp_cnx = NULL;
+    struct sctp_cnx_list_elm_s *sctp_cnx = NULL;
 
-  DevAssert(close_association_p != NULL);
-  sctp_cnx = sctp_get_cnx(close_association_p->assoc_id, 0);
+    DevAssert(close_association_p != NULL);
+    sctp_cnx = sctp_get_cnx(close_association_p->assoc_id, 0);
 
-  if (sctp_cnx == NULL) {
-    SCTP_ERROR("Failed to find SCTP description for assoc_id %d\n",
-               close_association_p->assoc_id);
-    /* TODO: notify upper layer */
-    return -1;
-  } else {
-    close(sctp_cnx->sd);
-    STAILQ_REMOVE(&sctp_cnx_list, sctp_cnx, sctp_cnx_list_elm_s, entries);
-    SCTP_DEBUG("Removed assoc_id %u (closed socket %u)\n",
-               sctp_cnx->assoc_id, sctp_cnx->sd);
-  }
-
-  return 0;
+    if (sctp_cnx == NULL) {
+        SCTP_ERROR("Failed to find SCTP description for assoc_id %d\n",
+                   close_association_p->assoc_id);
+        /* TODO: notify upper layer */
+        return -1;
+    } else {
+        close(sctp_cnx->sd);
+        STAILQ_REMOVE(&sctp_cnx_list, sctp_cnx, sctp_cnx_list_elm_s, entries);
+        SCTP_DEBUG("Removed assoc_id %u (closed socket %u)\n",
+                   sctp_cnx->assoc_id, (unsigned int)sctp_cnx->sd);
+    }
+
+    return 0;
 }
 
 //------------------------------------------------------------------------------
 static int sctp_create_new_listener(
-  const instance_t instance,
-  const task_id_t  requestor,
-  sctp_init_t     *init_p,
-  int server_type)
+    const instance_t instance,
+    const task_id_t  requestor,
+    sctp_init_t     *init_p,
+    int server_type)
 {
-  struct sctp_event_subscribe   event;
-  struct sockaddr              *addr      = NULL;
-  struct sctp_cnx_list_elm_s   *sctp_cnx  = NULL;
-  uint16_t                      i  = 0, j = 0;
-  int                           sd = 0;
-  int                           used_addresses = 0;
-
-  DevAssert(init_p != NULL);
-
-  if (init_p->ipv4 == 0 && init_p->ipv6 == 0) {
-    SCTP_ERROR("Illegal IP configuration upper layer should request at"
-               "least ipv4 and/or ipv6 config\n");
-    return -1;
-  }
+    struct sctp_event_subscribe   event;
+    struct sockaddr              *addr      = NULL;
+    struct sctp_cnx_list_elm_s   *sctp_cnx  = NULL;
+    uint16_t                      i  = 0, j = 0;
+    int                           sd = 0;
+    int                           used_addresses = 0;
+
+    DevAssert(init_p != NULL);
+
+    if (init_p->ipv4 == 0 && init_p->ipv6 == 0) {
+        SCTP_ERROR("Illegal IP configuration upper layer should request at"
+                   "least ipv4 and/or ipv6 config\n");
+        return -1;
+    }
 
-  if ((used_addresses = init_p->nb_ipv4_addr + init_p->nb_ipv6_addr) == 0) {
-    SCTP_WARN("No address provided...\n");
-    return -1;
-  }
+    if ((used_addresses = init_p->nb_ipv4_addr + init_p->nb_ipv6_addr) == 0) {
+        SCTP_WARN("No address provided...\n");
+        return -1;
+    }
 
-  addr = calloc(used_addresses, sizeof(struct sockaddr));
+    addr = calloc(used_addresses, sizeof(struct sockaddr));
 
-  SCTP_DEBUG("Creating new listen socket on port %u with\n", init_p->port);
+    SCTP_DEBUG("Creating new listen socket on port %u with\n", init_p->port);
 
-  if (init_p->ipv4 == 1) {
-    struct sockaddr_in *ip4_addr;
+    if (init_p->ipv4 == 1) {
+        struct sockaddr_in *ip4_addr;
 
-    SCTP_DEBUG("ipv4 addresses:\n");
+        SCTP_DEBUG("ipv4 addresses:\n");
 
-    for (i = 0; i < init_p->nb_ipv4_addr; i++) {
-      SCTP_DEBUG("\t- "IPV4_ADDR"\n",
-                 IPV4_ADDR_FORMAT(init_p->ipv4_address[i]));
-      ip4_addr = (struct sockaddr_in *)&addr[i];
-      ip4_addr->sin_family = AF_INET;
-      ip4_addr->sin_port   = htons(init_p->port);
-      ip4_addr->sin_addr.s_addr = init_p->ipv4_address[i];
+        for (i = 0; i < init_p->nb_ipv4_addr; i++) {
+            SCTP_DEBUG("\t- "IPV4_ADDR"\n",
+                       IPV4_ADDR_FORMAT(init_p->ipv4_address[i]));
+            ip4_addr = (struct sockaddr_in *)&addr[i];
+            ip4_addr->sin_family = AF_INET;
+            ip4_addr->sin_port   = htons(init_p->port);
+            ip4_addr->sin_addr.s_addr = init_p->ipv4_address[i];
+        }
     }
-  }
 
-  if (init_p->ipv6 == 1) {
-    struct sockaddr_in6 *ip6_addr;
+    if (init_p->ipv6 == 1) {
+        struct sockaddr_in6 *ip6_addr;
 
-    SCTP_DEBUG("ipv6 addresses:\n");
+        SCTP_DEBUG("ipv6 addresses:\n");
 
-    for (j = 0; j < init_p->nb_ipv6_addr; j++) {
-      SCTP_DEBUG("\t- %s\n", init_p->ipv6_address[j]);
-      ip6_addr = (struct sockaddr_in6 *)&addr[i + j];
-      ip6_addr->sin6_family = AF_INET6;
-      ip6_addr->sin6_port  = htons(init_p->port);
+        for (j = 0; j < init_p->nb_ipv6_addr; j++) {
+            SCTP_DEBUG("\t- %s\n", init_p->ipv6_address[j]);
+            ip6_addr = (struct sockaddr_in6 *)&addr[i + j];
+            ip6_addr->sin6_family = AF_INET6;
+            ip6_addr->sin6_port  = htons(init_p->port);
 
-      if (inet_pton(AF_INET6, init_p->ipv6_address[j],
-                    ip6_addr->sin6_addr.s6_addr) <= 0) {
-        SCTP_WARN("Provided ipv6 address %s is not valid\n",
-                  init_p->ipv6_address[j]);
-      }
+            if (inet_pton(AF_INET6, init_p->ipv6_address[j],
+                          ip6_addr->sin6_addr.s6_addr) <= 0) {
+                SCTP_WARN("Provided ipv6 address %s is not valid\n",
+                          init_p->ipv6_address[j]);
+            }
+        }
     }
-  }
 
-  if (server_type) {
-    if ((sd = socket(PF_INET, SOCK_SEQPACKET, IPPROTO_SCTP)) < 0) {
-      SCTP_ERROR("socket: %s:%d\n", strerror(errno), errno);
-      return -1;
+    if (server_type) {
+        if ((sd = socket(PF_INET, SOCK_SEQPACKET, IPPROTO_SCTP)) < 0) {
+            SCTP_ERROR("socket: %s:%d\n", strerror(errno), errno);
+            free(addr);
+            return -1;
+        }
     }
-  }
-  else {
-    if ((sd = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP)) < 0) {
-      SCTP_ERROR("socket: %s:%d\n", strerror(errno), errno);
-      return -1;
+    else {
+        if ((sd = socket(AF_INET6, SOCK_STREAM, IPPROTO_SCTP)) < 0) {
+            SCTP_ERROR("socket: %s:%d\n", strerror(errno), errno);
+            free(addr);
+            return -1;
+        }
     }
-  }
 
-  memset((void *)&event, 1, sizeof(struct sctp_event_subscribe));
+    memset((void *)&event, 1, sizeof(struct sctp_event_subscribe));
 
-  if (setsockopt(sd, IPPROTO_SCTP, SCTP_EVENTS, &event,
-                 sizeof(struct sctp_event_subscribe)) < 0) {
-    SCTP_ERROR("setsockopt: %s:%d\n", strerror(errno), errno);
-    return -1;
-  }
-
-  sctp_cnx = calloc(1, sizeof(*sctp_cnx));
-
-  if (server_type) {
-    sctp_cnx->connection_type = SCTP_TYPE_MULTI_SERVER;
-  }
-  else {
-    sctp_cnx->connection_type = SCTP_TYPE_SERVER;
-  }
-
-  sctp_cnx->sd              = sd;
-  sctp_cnx->local_port      = init_p->port;
-  sctp_cnx->in_streams      = 32;
-  sctp_cnx->out_streams     = 32;
-  sctp_cnx->ppid            = init_p->ppid;
-  sctp_cnx->task_id         = requestor;
-  sctp_cnx->instance        = instance;
-
-  /* Some pre-bind socket configuration */
-  if (sctp_set_init_opt(sd,
-                        sctp_cnx->in_streams,
-                        sctp_cnx->out_streams,
-                        0,
-                        0) < 0) {
-    goto err;
-  }
-
-  if (sctp_bindx(sd, addr, used_addresses, SCTP_BINDX_ADD_ADDR) != 0) {
-    SCTP_ERROR("sctp_bindx: %s:%d\n", strerror(errno), errno);
-    return -1;
-  }
+    if (setsockopt(sd, IPPROTO_SCTP, SCTP_EVENTS, &event,
+                   sizeof(struct sctp_event_subscribe)) < 0) {
+        SCTP_ERROR("setsockopt: %s:%d\n", strerror(errno), errno);
+        free(addr);
+        return -1;
+    }
 
-  if (listen(sd, 5) < 0) {
-    SCTP_ERROR("listen: %s:%d\n", strerror(errno), errno);
-    return -1;
-  }
+    sctp_cnx = calloc(1, sizeof(*sctp_cnx));
 
-  /* Insert new element at end of list */
-  STAILQ_INSERT_TAIL(&sctp_cnx_list, sctp_cnx, entries);
-  sctp_nb_cnx++;
+    if (server_type) {
+        sctp_cnx->connection_type = SCTP_TYPE_MULTI_SERVER;
+    }
+    else {
+        sctp_cnx->connection_type = SCTP_TYPE_SERVER;
+    }
 
-  /* Add the socket to list of fd monitored by ITTI */
-  itti_subscribe_event_fd(TASK_SCTP, sd);
+    sctp_cnx->sd              = sd;
+    sctp_cnx->local_port      = init_p->port;
+    sctp_cnx->in_streams      = 32;
+    sctp_cnx->out_streams     = 32;
+    sctp_cnx->ppid            = init_p->ppid;
+    sctp_cnx->task_id         = requestor;
+    sctp_cnx->instance        = instance;
+
+    /* Some pre-bind socket configuration */
+    if (sctp_set_init_opt(sd,
+                          sctp_cnx->in_streams,
+                          sctp_cnx->out_streams,
+                          0,
+                          0) < 0) {
+        goto err;
+    }
+
+    if (sctp_bindx(sd, addr, used_addresses, SCTP_BINDX_ADD_ADDR) != 0) {
+        SCTP_ERROR("sctp_bindx: %s:%d\n", strerror(errno), errno);
+        return -1;
+    }
+
+    if (listen(sd, 5) < 0) {
+        SCTP_ERROR("listen: %s:%d\n", strerror(errno), errno);
+        return -1;
+    }
+
+    /* Insert new element at end of list */
+    STAILQ_INSERT_TAIL(&sctp_cnx_list, sctp_cnx, entries);
+    sctp_nb_cnx++;
 
-  return sd;
+    /* Add the socket to list of fd monitored by ITTI */
+    itti_subscribe_event_fd(TASK_SCTP, sd);
+
+    return sd;
 err:
 
-  if (sd != -1) {
-    close(sd);
-    sd = -1;
-  }
+    if (sd != -1) {
+        close(sd);
+        sd = -1;
+    }
 
-  return -1;
+    return -1;
 }
 
 //------------------------------------------------------------------------------
 static inline
 void
 sctp_eNB_accept_associations(
-  struct sctp_cnx_list_elm_s *sctp_cnx)
+    struct sctp_cnx_list_elm_s *sctp_cnx)
 {
-  int             client_sd;
-  struct sockaddr saddr;
-  socklen_t       saddr_size;
-
-  DevAssert(sctp_cnx != NULL);
-
-  saddr_size = sizeof(saddr);
-
-  /* There is a new client connecting. Accept it...
-   */
-  if ((client_sd = accept(sctp_cnx->sd, &saddr, &saddr_size)) < 0) {
-    SCTP_ERROR("[%d] accept failed: %s:%d\n", sctp_cnx->sd, strerror(errno), errno);
-  } else {
-    struct sctp_cnx_list_elm_s *new_cnx;
-    uint16_t port;
-
-    /* This is an ipv6 socket */
-    port = ((struct sockaddr_in6*)&saddr)->sin6_port;
-
-    /* Contrary to BSD, client socket does not inherit O_NONBLOCK option */
-    if (fcntl(client_sd, F_SETFL, O_NONBLOCK) < 0) {
-      SCTP_ERROR("fcntl F_SETFL O_NONBLOCK failed: %s\n",
-                 strerror(errno));
-      close(client_sd);
-      return;
-    }
+    int             client_sd;
+    struct sockaddr saddr;
+    socklen_t       saddr_size;
 
-    new_cnx = calloc(1, sizeof(*sctp_cnx));
+    DevAssert(sctp_cnx != NULL);
 
-    DevAssert(new_cnx != NULL);
+    saddr_size = sizeof(saddr);
 
-    new_cnx->connection_type = SCTP_TYPE_CLIENT;
+    /* There is a new client connecting. Accept it...
+     */
+    if ((client_sd = accept(sctp_cnx->sd, &saddr, &saddr_size)) < 0) {
+        SCTP_ERROR("[%d] accept failed: %s:%d\n", sctp_cnx->sd, strerror(errno), errno);
+    } else {
+        struct sctp_cnx_list_elm_s *new_cnx;
+        uint16_t port;
 
-    new_cnx->sd         = client_sd;
-    new_cnx->task_id    = sctp_cnx->task_id;
-    new_cnx->cnx_id     = 0;
-    new_cnx->ppid       = sctp_cnx->ppid;
-    new_cnx->instance   = sctp_cnx->instance;
-    new_cnx->local_port = sctp_cnx->local_port;
+        /* This is an ipv6 socket */
+        port = ((struct sockaddr_in6*)&saddr)->sin6_port;
 
-    if (sctp_get_sockinfo(client_sd, &new_cnx->in_streams, &new_cnx->out_streams,
-                          &new_cnx->assoc_id) != 0) {
-      SCTP_ERROR("sctp_get_sockinfo failed\n");
-      close(client_sd);
-      free(new_cnx);
-      return;
-    }
+        /* Contrary to BSD, client socket does not inherit O_NONBLOCK option */
+        if (fcntl(client_sd, F_SETFL, O_NONBLOCK) < 0) {
+            SCTP_ERROR("fcntl F_SETFL O_NONBLOCK failed: %s\n",
+                       strerror(errno));
+            close(client_sd);
+            return;
+        }
 
-    /* Insert new element at end of list */
-    STAILQ_INSERT_TAIL(&sctp_cnx_list, new_cnx, entries);
-    sctp_nb_cnx++;
+        new_cnx = calloc(1, sizeof(*sctp_cnx));
 
-    /* Add the socket to list of fd monitored by ITTI */
-    itti_subscribe_event_fd(TASK_SCTP, client_sd);
+        DevAssert(new_cnx != NULL);
+
+        new_cnx->connection_type = SCTP_TYPE_CLIENT;
+
+        new_cnx->sd         = client_sd;
+        new_cnx->task_id    = sctp_cnx->task_id;
+        new_cnx->cnx_id     = 0;
+        new_cnx->ppid       = sctp_cnx->ppid;
+        new_cnx->instance   = sctp_cnx->instance;
+        new_cnx->local_port = sctp_cnx->local_port;
+
+        if (sctp_get_sockinfo(client_sd, &new_cnx->in_streams, &new_cnx->out_streams,
+                              &new_cnx->assoc_id) != 0) {
+            SCTP_ERROR("sctp_get_sockinfo failed\n");
+            close(client_sd);
+            free(new_cnx);
+            return;
+        }
 
-    sctp_itti_send_association_ind(new_cnx->task_id, new_cnx->instance,
-                                   new_cnx->assoc_id, port,
-                                   new_cnx->out_streams, new_cnx->in_streams);
-  }
+        /* Insert new element at end of list */
+        STAILQ_INSERT_TAIL(&sctp_cnx_list, new_cnx, entries);
+        sctp_nb_cnx++;
+
+        /* Add the socket to list of fd monitored by ITTI */
+        itti_subscribe_event_fd(TASK_SCTP, client_sd);
+
+        sctp_itti_send_association_ind(new_cnx->task_id, new_cnx->instance,
+                                       new_cnx->assoc_id, port,
+                                       new_cnx->out_streams, new_cnx->in_streams);
+    }
 }
 
 //------------------------------------------------------------------------------
 static inline
 void
 sctp_eNB_read_from_socket(
-  struct sctp_cnx_list_elm_s *sctp_cnx)
+    struct sctp_cnx_list_elm_s *sctp_cnx)
 {
-  int                    flags = 0, n;
-  socklen_t              from_len;
-  struct sctp_sndrcvinfo sinfo;
+    int                    flags = 0, n;
+    socklen_t              from_len;
+    struct sctp_sndrcvinfo sinfo;
 
-  struct sockaddr_in addr;
-  uint8_t buffer[SCTP_RECV_BUFFER_SIZE];
+    struct sockaddr_in addr;
+    uint8_t buffer[SCTP_RECV_BUFFER_SIZE];
 
-  DevAssert(sctp_cnx != NULL);
+    DevAssert(sctp_cnx != NULL);
 
-  memset((void *)&addr, 0, sizeof(struct sockaddr_in));
-  from_len = (socklen_t)sizeof(struct sockaddr_in);
-  memset((void *)&sinfo, 0, sizeof(struct sctp_sndrcvinfo));
+    memset((void *)&addr, 0, sizeof(struct sockaddr_in));
+    from_len = (socklen_t)sizeof(struct sockaddr_in);
+    memset((void *)&sinfo, 0, sizeof(struct sctp_sndrcvinfo));
 
-  n = sctp_recvmsg(sctp_cnx->sd, (void *)buffer, SCTP_RECV_BUFFER_SIZE,
-                   (struct sockaddr *)&addr, &from_len,
-                   &sinfo, &flags);
+    n = sctp_recvmsg(sctp_cnx->sd, (void *)buffer, SCTP_RECV_BUFFER_SIZE,
+                     (struct sockaddr *)&addr, &from_len,
+                     &sinfo, &flags);
 
-  if (n < 0) {
-    if (errno == ENOTCONN) {
-      itti_unsubscribe_event_fd(TASK_SCTP, sctp_cnx->sd);
+    if (n < 0) {
+        if (errno == ENOTCONN) {
+            itti_unsubscribe_event_fd(TASK_SCTP, sctp_cnx->sd);
 
-      SCTP_DEBUG("Received not connected for sd %d\n", sctp_cnx->sd);
+            SCTP_DEBUG("Received not connected for sd %d\n", sctp_cnx->sd);
 
-      sctp_itti_send_association_resp(
-        sctp_cnx->task_id, sctp_cnx->instance, -1,
-        sctp_cnx->cnx_id, SCTP_STATE_UNREACHABLE, 0, 0);
+            sctp_itti_send_association_resp(
+                sctp_cnx->task_id, sctp_cnx->instance, -1,
+                sctp_cnx->cnx_id, SCTP_STATE_UNREACHABLE, 0, 0);
 
-      close(sctp_cnx->sd);
-      STAILQ_REMOVE(&sctp_cnx_list, sctp_cnx, sctp_cnx_list_elm_s, entries);
-      sctp_nb_cnx--;
-      free(sctp_cnx);
-    } else {
-      SCTP_DEBUG("An error occured during read\n");
-      SCTP_ERROR("sctp_recvmsg (fd %d, len %d ): %s:%d\n", sctp_cnx->sd, n, strerror(errno), errno);
-    }
+            close(sctp_cnx->sd);
+            STAILQ_REMOVE(&sctp_cnx_list, sctp_cnx, sctp_cnx_list_elm_s, entries);
+            sctp_nb_cnx--;
+            free(sctp_cnx);
+        } else {
+            SCTP_DEBUG("An error occured during read\n");
+            SCTP_ERROR("sctp_recvmsg (fd %d, len %d ): %s:%d\n", sctp_cnx->sd, n, strerror(errno), errno);
+        }
 
-    return;
-  } else if (n == 0) {
-    SCTP_DEBUG("return of sctp_recvmsg is 0...\n");
-    return;
-  }
+        return;
+    } else if (n == 0) {
+        SCTP_DEBUG("return of sctp_recvmsg is 0...\n");
+        return;
+    }
 
-  if (flags & MSG_NOTIFICATION) {
-    union sctp_notification *snp;
-    snp = (union sctp_notification *)buffer;
+    if (flags & MSG_NOTIFICATION) {
+        union sctp_notification *snp;
+        snp = (union sctp_notification *)buffer;
 
-    SCTP_DEBUG("Received notification for sd %d, type %u\n",
-               sctp_cnx->sd, snp->sn_header.sn_type);
+        SCTP_DEBUG("Received notification for sd %d, type %u\n",
+                   sctp_cnx->sd, snp->sn_header.sn_type);
 
-    /* Client deconnection */
-    if (SCTP_SHUTDOWN_EVENT == snp->sn_header.sn_type) {
-      itti_unsubscribe_event_fd(TASK_SCTP, sctp_cnx->sd);
+        /* Client deconnection */
+        if (SCTP_SHUTDOWN_EVENT == snp->sn_header.sn_type) {
+            itti_unsubscribe_event_fd(TASK_SCTP, sctp_cnx->sd);
 
-      close(sctp_cnx->sd);
+            close(sctp_cnx->sd);
 
-      sctp_itti_send_association_resp(
-        sctp_cnx->task_id, sctp_cnx->instance, sctp_cnx->assoc_id,
-        sctp_cnx->cnx_id, SCTP_STATE_SHUTDOWN,
-        0, 0);
+            sctp_itti_send_association_resp(
+                sctp_cnx->task_id, sctp_cnx->instance, sctp_cnx->assoc_id,
+                sctp_cnx->cnx_id, SCTP_STATE_SHUTDOWN,
+                0, 0);
 
-      STAILQ_REMOVE(&sctp_cnx_list, sctp_cnx, sctp_cnx_list_elm_s, entries);
-      sctp_nb_cnx--;
+            STAILQ_REMOVE(&sctp_cnx_list, sctp_cnx, sctp_cnx_list_elm_s, entries);
+            sctp_nb_cnx--;
 
-      free(sctp_cnx);
-    }
-    /* Association has changed. */
-    else if (SCTP_ASSOC_CHANGE == snp->sn_header.sn_type) {
-      struct sctp_assoc_change *sctp_assoc_changed;
-      sctp_assoc_changed = &snp->sn_assoc_change;
-
-      SCTP_DEBUG("Client association changed: %d\n", sctp_assoc_changed->sac_state);
-
-      /* New physical association requested by a peer */
-      switch (sctp_assoc_changed->sac_state) {
-      case SCTP_COMM_UP: {
-        if (sctp_get_peeraddresses(sctp_cnx->sd, NULL, NULL) != 0) {
-          /* TODO Failure -> notify upper layer */
-        } else {
-          sctp_get_sockinfo(sctp_cnx->sd, &sctp_cnx->in_streams,
-                            &sctp_cnx->out_streams, &sctp_cnx->assoc_id);
+            free(sctp_cnx);
+        }
+        /* Association has changed. */
+        else if (SCTP_ASSOC_CHANGE == snp->sn_header.sn_type) {
+            struct sctp_assoc_change *sctp_assoc_changed;
+            sctp_assoc_changed = &snp->sn_assoc_change;
+
+            SCTP_DEBUG("Client association changed: %d\n", sctp_assoc_changed->sac_state);
+
+            /* New physical association requested by a peer */
+            switch (sctp_assoc_changed->sac_state) {
+            case SCTP_COMM_UP: {
+                if (sctp_get_peeraddresses(sctp_cnx->sd, NULL, NULL) != 0) {
+                    /* TODO Failure -> notify upper layer */
+                } else {
+                    sctp_get_sockinfo(sctp_cnx->sd, &sctp_cnx->in_streams,
+                                      &sctp_cnx->out_streams, &sctp_cnx->assoc_id);
+                }
+
+                SCTP_DEBUG("Comm up notified for sd %d, assigned assoc_id %d\n",
+                           sctp_cnx->sd, sctp_cnx->assoc_id);
+
+                sctp_itti_send_association_resp(
+                    sctp_cnx->task_id, sctp_cnx->instance, sctp_cnx->assoc_id,
+                    sctp_cnx->cnx_id, SCTP_STATE_ESTABLISHED,
+                    sctp_cnx->out_streams, sctp_cnx->in_streams);
+
+            }
+            break;
+
+            default:
+                SCTP_WARN("unhandled: SCTP_ASSOC_CHANGE to %d\n", sctp_assoc_changed->sac_state);
+                break;
+            }
+        }
+    } else {
+        sctp_cnx->messages_recv++;
+
+        if (ntohl(sinfo.sinfo_ppid) != sctp_cnx->ppid) {
+            /* Mismatch in Payload Protocol Identifier,
+             * may be we received unsollicited traffic from stack other than S1AP.
+             */
+            SCTP_ERROR("Received data from peer with unsollicited PPID %d, expecting %d\n",
+                       ntohl(sinfo.sinfo_ppid),
+                       sctp_cnx->ppid);
         }
 
-        SCTP_DEBUG("Comm up notified for sd %d, assigned assoc_id %d\n",
-                   sctp_cnx->sd, sctp_cnx->assoc_id);
-
-        sctp_itti_send_association_resp(
-          sctp_cnx->task_id, sctp_cnx->instance, sctp_cnx->assoc_id,
-          sctp_cnx->cnx_id, SCTP_STATE_ESTABLISHED,
-          sctp_cnx->out_streams, sctp_cnx->in_streams);
-
-      }
-      break;
+        SCTP_DEBUG("[%d][%d] Msg of length %d received from port %u, on stream %d, PPID %d\n",
+                   sinfo.sinfo_assoc_id, sctp_cnx->sd, n, ntohs(addr.sin_port),
+                   sinfo.sinfo_stream, ntohl(sinfo.sinfo_ppid));
 
-      default:
-        SCTP_WARN("unhandled: SCTP_ASSOC_CHANGE to %d\n", sctp_assoc_changed->sac_state);
-        break;
-      }
-    }
-  } else {
-    sctp_cnx->messages_recv++;
-
-    if (ntohl(sinfo.sinfo_ppid) != sctp_cnx->ppid) {
-      /* Mismatch in Payload Protocol Identifier,
-       * may be we received unsollicited traffic from stack other than S1AP.
-       */
-      SCTP_ERROR("Received data from peer with unsollicited PPID %d, expecting %d\n",
-                 ntohl(sinfo.sinfo_ppid),
-                 sctp_cnx->ppid);
+        sctp_itti_send_new_message_ind(sctp_cnx->task_id,
+                                       sctp_cnx->instance,
+                                       sinfo.sinfo_assoc_id,
+                                       buffer, n, sinfo.sinfo_stream);
     }
-
-    SCTP_DEBUG("[%d][%d] Msg of length %d received from port %u, on stream %d, PPID %d\n",
-               sinfo.sinfo_assoc_id, sctp_cnx->sd, n, ntohs(addr.sin_port),
-               sinfo.sinfo_stream, ntohl(sinfo.sinfo_ppid));
-
-    sctp_itti_send_new_message_ind(sctp_cnx->task_id,
-                                   sctp_cnx->instance,
-                                   sinfo.sinfo_assoc_id,
-                                   buffer, n, sinfo.sinfo_stream);
-  }
 }
 
 //------------------------------------------------------------------------------
 void
 sctp_eNB_flush_sockets(
-  struct epoll_event *events, int nb_events)
+    struct epoll_event *events, int nb_events)
 {
-  int i;
-  struct sctp_cnx_list_elm_s *sctp_cnx = NULL;
+    int i;
+    struct sctp_cnx_list_elm_s *sctp_cnx = NULL;
 
-  if (events == NULL) {
-    return;
-  }
+    if (events == NULL) {
+        return;
+    }
 
-  for (i = 0; i < nb_events; i++) {
-    sctp_cnx = sctp_get_cnx(-1, events[i].data.fd);
+    for (i = 0; i < nb_events; i++) {
+        sctp_cnx = sctp_get_cnx(-1, events[i].data.fd);
 
-    if (sctp_cnx == NULL) {
-      continue;
-    }
+        if (sctp_cnx == NULL) {
+            continue;
+        }
 
-    SCTP_DEBUG("Found data for descriptor %d\n", events[i].data.fd);
+        SCTP_DEBUG("Found data for descriptor %d\n", events[i].data.fd);
 
-    if (sctp_cnx->connection_type == SCTP_TYPE_CLIENT) {
-      sctp_eNB_read_from_socket(sctp_cnx);
-    }
-    else if (sctp_cnx->connection_type == SCTP_TYPE_MULTI_SERVER) {
-      sctp_eNB_accept_associations_multi(sctp_cnx);
-    }
-    else {
-      sctp_eNB_accept_associations(sctp_cnx);
+        if (sctp_cnx->connection_type == SCTP_TYPE_CLIENT) {
+            sctp_eNB_read_from_socket(sctp_cnx);
+        }
+        else if (sctp_cnx->connection_type == SCTP_TYPE_MULTI_SERVER) {
+            sctp_eNB_accept_associations_multi(sctp_cnx);
+        }
+        else {
+            sctp_eNB_accept_associations(sctp_cnx);
+        }
     }
-  }
 }
 
 //------------------------------------------------------------------------------
 void sctp_eNB_init(void)
 {
-  SCTP_DEBUG("Starting SCTP layer\n");
+    SCTP_DEBUG("Starting SCTP layer\n");
 
-  STAILQ_INIT(&sctp_cnx_list);
+    STAILQ_INIT(&sctp_cnx_list);
 
-  itti_mark_task_ready(TASK_SCTP);
-  MSC_START_USE();
+    itti_mark_task_ready(TASK_SCTP);
+    MSC_START_USE();
 
 }
 
@@ -1064,83 +1067,83 @@ void *sctp_eNB_process_itti_msg(void *notUsed)
 
     /* Check if there is a packet to handle */
     if (received_msg != NULL) {
-      switch (ITTI_MSG_ID(received_msg)) {
-      case SCTP_INIT_MSG: {
-        SCTP_DEBUG("Received SCTP_INIT_MSG\n");
-
-        /* We received a new connection request */
-        if (sctp_create_new_listener(
-              ITTI_MESSAGE_GET_INSTANCE(received_msg),
-              ITTI_MSG_ORIGIN_ID(received_msg),
-              &received_msg->ittiMsg.sctp_init,0) < 0) {
-          /* SCTP socket creation or bind failed... */
-          SCTP_ERROR("Failed to create new SCTP listener\n");
-        }
-      }
-      break;
-
-      case SCTP_INIT_MSG_MULTI_REQ: {
-        int multi_sd;
-
-        SCTP_DEBUG("Received SCTP_INIT_MSG_MULTI_REQ\n");
-
-        multi_sd = sctp_create_new_listener(
-              ITTI_MESSAGE_GET_INSTANCE(received_msg),
-              ITTI_MSG_ORIGIN_ID(received_msg),
-              &received_msg->ittiMsg.sctp_init_multi,1);
-        /* We received a new connection request */
-         if (multi_sd < 0) {
-          /* SCTP socket creation or bind failed... */
-          SCTP_ERROR("Failed to create new SCTP listener\n");
+        switch (ITTI_MSG_ID(received_msg)) {
+        case SCTP_INIT_MSG: {
+            SCTP_DEBUG("Received SCTP_INIT_MSG\n");
+
+            /* We received a new connection request */
+            if (sctp_create_new_listener(
+                        ITTI_MESSAGE_GET_INSTANCE(received_msg),
+                        ITTI_MSG_ORIGIN_ID(received_msg),
+                        &received_msg->ittiMsg.sctp_init,0) < 0) {
+                /* SCTP socket creation or bind failed... */
+                SCTP_ERROR("Failed to create new SCTP listener\n");
+            }
         }
-        sctp_itti_send_init_msg_multi_cnf(
+        break;
+
+        case SCTP_INIT_MSG_MULTI_REQ: {
+            int multi_sd;
+
+            SCTP_DEBUG("Received SCTP_INIT_MSG_MULTI_REQ\n");
+
+            multi_sd = sctp_create_new_listener(
+                           ITTI_MESSAGE_GET_INSTANCE(received_msg),
+                           ITTI_MSG_ORIGIN_ID(received_msg),
+                           &received_msg->ittiMsg.sctp_init_multi,1);
+            /* We received a new connection request */
+            if (multi_sd < 0) {
+                /* SCTP socket creation or bind failed... */
+                SCTP_ERROR("Failed to create new SCTP listener\n");
+            }
+            sctp_itti_send_init_msg_multi_cnf(
                 ITTI_MSG_ORIGIN_ID(received_msg),
                 ITTI_MESSAGE_GET_INSTANCE(received_msg),
                 multi_sd);
-      }
-      break;
-
-      case SCTP_NEW_ASSOCIATION_REQ: {
-        sctp_handle_new_association_req(ITTI_MESSAGE_GET_INSTANCE(received_msg),
-                                        ITTI_MSG_ORIGIN_ID(received_msg),
-                                        &received_msg->ittiMsg.sctp_new_association_req);
-      }
-      break;
-
-      case SCTP_NEW_ASSOCIATION_REQ_MULTI: {
-        sctp_handle_new_association_req_multi(ITTI_MESSAGE_GET_INSTANCE(received_msg),
-                                        ITTI_MSG_ORIGIN_ID(received_msg),
-                                        &received_msg->ittiMsg.sctp_new_association_req_multi);
-      }
-      break;
-
-      case SCTP_CLOSE_ASSOCIATION:
-        sctp_close_association(ITTI_MESSAGE_GET_INSTANCE(received_msg),
-                               ITTI_MSG_ORIGIN_ID(received_msg),
-                               &received_msg->ittiMsg.sctp_close_association);
+        }
         break;
 
-      case TERMINATE_MESSAGE:
-        SCTP_WARN("*** Exiting SCTP thread\n");
-        itti_exit_task();
+        case SCTP_NEW_ASSOCIATION_REQ: {
+            sctp_handle_new_association_req(ITTI_MESSAGE_GET_INSTANCE(received_msg),
+                                            ITTI_MSG_ORIGIN_ID(received_msg),
+                                            &received_msg->ittiMsg.sctp_new_association_req);
+        }
         break;
 
-      case SCTP_DATA_REQ: {
-        sctp_send_data(ITTI_MESSAGE_GET_INSTANCE(received_msg),
-                       ITTI_MSG_ORIGIN_ID(received_msg),
-                       &received_msg->ittiMsg.sctp_data_req);
-      }
-      break;
+        case SCTP_NEW_ASSOCIATION_REQ_MULTI: {
+            sctp_handle_new_association_req_multi(ITTI_MESSAGE_GET_INSTANCE(received_msg),
+                                                  ITTI_MSG_ORIGIN_ID(received_msg),
+                                                  &received_msg->ittiMsg.sctp_new_association_req_multi);
+        }
+        break;
 
-      default:
-        SCTP_ERROR("Received unhandled message %d:%s\n",
-                   ITTI_MSG_ID(received_msg), ITTI_MSG_NAME(received_msg));
+        case SCTP_CLOSE_ASSOCIATION:
+            sctp_close_association(ITTI_MESSAGE_GET_INSTANCE(received_msg),
+                                   ITTI_MSG_ORIGIN_ID(received_msg),
+                                   &received_msg->ittiMsg.sctp_close_association);
+            break;
+
+        case TERMINATE_MESSAGE:
+            SCTP_WARN("*** Exiting SCTP thread\n");
+            itti_exit_task();
+            break;
+
+        case SCTP_DATA_REQ: {
+            sctp_send_data(ITTI_MESSAGE_GET_INSTANCE(received_msg),
+                           ITTI_MSG_ORIGIN_ID(received_msg),
+                           &received_msg->ittiMsg.sctp_data_req);
+        }
         break;
-      }
 
-      result = itti_free(ITTI_MSG_ORIGIN_ID(received_msg), received_msg);
-      AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
-      received_msg = NULL;
+        default:
+            SCTP_ERROR("Received unhandled message %d:%s\n",
+                       ITTI_MSG_ID(received_msg), ITTI_MSG_NAME(received_msg));
+            break;
+        }
+
+        result = itti_free(ITTI_MSG_ORIGIN_ID(received_msg), received_msg);
+        AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
+        received_msg = NULL;
     }
 
     nb_events = itti_get_events(TASK_SCTP, &events);
@@ -1153,11 +1156,11 @@ void *sctp_eNB_process_itti_msg(void *notUsed)
 //------------------------------------------------------------------------------
 void *sctp_eNB_task(void *arg)
 {
-  sctp_eNB_init();
+    sctp_eNB_init();
 
-  while (1) {
-    (void) sctp_eNB_process_itti_msg(NULL);
-  }
+    while (1) {
+        (void) sctp_eNB_process_itti_msg(NULL);
+    }
 
-  return NULL;
+    return NULL;
 }
diff --git a/openair3/SECU/key_nas_encryption.c b/openair3/SECU/key_nas_encryption.c
deleted file mode 100644
index aa641137efbf987111fceb5cf016319209c83679..0000000000000000000000000000000000000000
--- a/openair3/SECU/key_nas_encryption.c
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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 <string.h>
-#include "secu_defs.h"
-
-/*!
- * Derive the kNASenc from kasme and perform truncate on the generated key to
- * reduce his size to 128 bits. Definition of the derivation function can
- * be found in 3GPP TS.33401 #A.7
- * @param[in] nas_alg_type NAS algorithm distinguisher
- * @param[in] nas_enc_alg_id NAS encryption/integrity algorithm identifier.
- * Possible values are:
- *      - 0 for EIA0 algorithm (Null Integrity Protection algorithm)
- *      - 1 for 128-EIA1 SNOW 3G
- *      - 2 for 128-EIA2 AES
- * @param[in] kasme Key for MME as provided by AUC
- * @param[out] knas Truncated ouput key as derived by KDF
- */
-
-/*int derive_key_nas(algorithm_type_dist_t nas_alg_type, uint8_t nas_enc_alg_id,
-               const uint8_t kasme[32], uint8_t** knas)
-{
-    uint8_t s[7];
-    uint8_t knas_temp[32];
-
-    // FC
-    s[0] = 0x15;
-
-    // P0 = algorithm type distinguisher
-    s[1] = nas_alg_type & 0xFF;
-
-    // L0 = length(P0) = 1
-    s[2] = 0x00;
-    s[3] = 0x01;
-
-    // P1
-    s[4] = nas_enc_alg_id;
-
-    // L1 = length(P1) = 1
-    s[5] = 0x00;
-    s[6] = 0x01;
-
-    kdf((uint8_t*)kasme, 32, s, 7, (uint8_t**)&knas_temp, 32);
-
-    // Truncate the generate key to 128 bits
-    memcpy(knas, knas_temp, 16);
-
-    return 0;
-}
-*/
diff --git a/openair3/TEST/EPC_TEST/TEST_1MME_1ENB_1UE_ATTACH_GUTI/enb1.conf b/openair3/TEST/EPC_TEST/TEST_1MME_1ENB_1UE_ATTACH_GUTI/enb1.conf
old mode 100755
new mode 100644
diff --git a/openair3/TEST/EPC_TEST/generate_scenario.h b/openair3/TEST/EPC_TEST/generate_scenario.h
index 0f240f483d293b13a09ea48e87d74631d729c3e2..b2042a894cd54b7e96ce4169373429896e538d76 100644
--- a/openair3/TEST/EPC_TEST/generate_scenario.h
+++ b/openair3/TEST/EPC_TEST/generate_scenario.h
@@ -38,11 +38,7 @@
 #include "platform_constants.h"
 #include "PHY/impl_defs_lte.h"
 #include "s1ap_messages_types.h"
-#ifdef CMAKER
 #include "SystemInformationBlockType2.h"
-#else
-#include "RRC/LTE/MESSAGES/SystemInformationBlockType2.h"
-#endif
 
 #define IPV4_STR_ADDR_TO_INT_NWBO(AdDr_StR,NwBo,MeSsAgE ) do {\
             struct in_addr inp;\
diff --git a/openair3/TEST/EPC_TEST/play_scenario.c b/openair3/TEST/EPC_TEST/play_scenario.c
index 546878e57692061c502ac17d56f08fd7a5f336d1..5928ab017f5f2370cd671fd9347c40a580a596e2 100644
--- a/openair3/TEST/EPC_TEST/play_scenario.c
+++ b/openair3/TEST/EPC_TEST/play_scenario.c
@@ -249,7 +249,7 @@ int et_hex2data(unsigned char * const data, const unsigned char * const hexstrin
   char *endptr = NULL;
   size_t count = 0;
 
-  fprintf(stdout, "%s(%s,%d)\n", __FUNCTION__, hexstring, len);
+  fprintf(stdout, "%s(%s,%u)\n", __FUNCTION__, hexstring, len);
 
   if ((len > 1) && (strlen((const char*)hexstring) % 2)) {
     //or hexstring has an odd length
@@ -1103,7 +1103,7 @@ et_config_parse_opt_line (
             fprintf(stderr, "Please provide a valid -D/--delay-on-exit argument, %s is not a valid value\n", delay_on_exit);
             exit(1);
           }
-          printf("Delay on exit is %d\n", delay_on_exit);
+          printf("Delay on exit is %u\n", delay_on_exit);
         }
         break;
 
diff --git a/openair3/TEST/EPC_TEST/play_scenario.h b/openair3/TEST/EPC_TEST/play_scenario.h
index f9601fe9044aca63d522b3e4085220bec52b8d18..db399a23f1010604a647326123859cc8238b687b 100644
--- a/openair3/TEST/EPC_TEST/play_scenario.h
+++ b/openair3/TEST/EPC_TEST/play_scenario.h
@@ -398,7 +398,7 @@ typedef struct et_event_s {
   } u;
 } et_event_t;
 
-inline void et_free_pointer(void *p) {if (NULL != p) {free(p); p=NULL;}};
+inline void et_free_pointer(void *p) {if (NULL != p) {free(p);}};
 
 //-------------------------
 void et_free_packet(et_packet_t* packet);
diff --git a/openair3/TEST/EPC_TEST/play_scenario_display.c b/openair3/TEST/EPC_TEST/play_scenario_display.c
index e10cbdf9bf1b285d6965dcb77c3f4db80b284c84..dd5b6edbd3c679d03a71e4222f3f98040f809271 100644
--- a/openair3/TEST/EPC_TEST/play_scenario_display.c
+++ b/openair3/TEST/EPC_TEST/play_scenario_display.c
@@ -54,7 +54,7 @@ void et_print_hex_octets(const unsigned char * const byte_stream, const unsigned
         fprintf(stdout, " |\n");
       }
 
-      fprintf(stdout, " %04ld |", octet_index);
+      fprintf(stdout, " %04lu |", octet_index);
     }
 
     /*
diff --git a/openair3/TEST/EPC_TEST/play_scenario_parse.c b/openair3/TEST/EPC_TEST/play_scenario_parse.c
index 040db30398495f51f3faf25b5bf6fb2a18604806..d24fddddec342acc284a01f5233e16ed4b4a3560 100644
--- a/openair3/TEST/EPC_TEST/play_scenario_parse.c
+++ b/openair3/TEST/EPC_TEST/play_scenario_parse.c
@@ -94,7 +94,7 @@ void et_parse_s1ap(xmlDocPtr doc, const xmlNode const *s1ap_node, et_s1ap_t * co
             xml_char = xmlGetProp((xmlNode *)cur_node, (const xmlChar *)"value");
             if (NULL != xml_char) {
               xml_char2 = xmlGetProp((xmlNode *)cur_node, (const xmlChar *)"name");
-              fprintf(stdout, "s1ap %p field name %s  size %d value %s\n",s1ap, xml_char2, size, xml_char);
+              fprintf(stdout, "s1ap %p field name %s  size %u value %s\n",s1ap, xml_char2, size, xml_char);
               xmlFree(xml_char2);
               // if success to get value, do not parse children
               //AssertFatal ((xmlStrlen(xml_char) == size), "ERROR %s() mismatch in size %d and strlen %d\n", __FUNCTION__, size, xmlStrlen(xml_char));
diff --git a/openair3/UTILS/conversions.h b/openair3/UTILS/conversions.h
index 4763352af737648c8806ba251c141f316d3a4b7f..71d57cc87d9d2bda784c2e421050f0fabf117f1d 100644
--- a/openair3/UTILS/conversions.h
+++ b/openair3/UTILS/conversions.h
@@ -131,6 +131,54 @@ do {                                            \
 #define M_TMSI_TO_OCTET_STRING   INT32_TO_OCTET_STRING
 #define MME_GID_TO_OCTET_STRING  INT16_TO_OCTET_STRING
 
+#define ENCRALG_TO_BIT_STRING(encralg, bitstring)    \
+    do {                        \
+    (bitstring)->size=2;                \
+    (bitstring)->bits_unused=0;            \
+    (bitstring)->buf=calloc (1, sizeof (uint8_t));    \
+    (bitstring)->buf[0] = (encralg) >> 8;         \
+    (bitstring)->buf[1] = (encralg);        \
+    }while(0)
+
+#define INTPROTALG_TO_BIT_STRING(intprotalg, bitstring)    \
+do {                                \
+    (bitstring)->size=2;                    \
+    (bitstring)->bits_unused=0;                \
+    (bitstring)->buf=calloc (2, sizeof (uint8_t));        \
+    (bitstring)->buf[0] = (intprotalg) >> 8;         \
+    (bitstring)->buf[1] = (intprotalg);            \
+}while(0)
+
+#define KENB_STAR_TO_BIT_STRING(kenbstar, bitstring)    \
+do {                            \
+    (bitstring)->size=32;                \
+    (bitstring)->bits_unused=0;            \
+    (bitstring)->buf= calloc (32, sizeof (uint8_t));\
+    memcpy((bitstring)->buf, kenbstar, 32*sizeof(uint8_t));            \
+}while(0)
+
+#define UEAGMAXBITRTD_TO_ASN_PRIMITIVES(uegmaxbitrtd, asnprimitives)        \
+do {                                         \
+    (asnprimitives)->size=5;                        \
+    (asnprimitives)->buf=calloc (5, sizeof (uint8_t));            \
+    (asnprimitives)->buf[0] = (uegmaxbitrtd) >> 32;                \
+    (asnprimitives)->buf[1] = (uegmaxbitrtd) >> 24;                \
+    (asnprimitives)->buf[2] = (uegmaxbitrtd) >> 16;                \
+    (asnprimitives)->buf[3] = (uegmaxbitrtd) >> 8;                \
+    (asnprimitives)->buf[4] = (uegmaxbitrtd);                \
+ }while(0)
+
+#define UEAGMAXBITRTU_TO_ASN_PRIMITIVES(uegmaxbitrtu, asnprimitives)        \
+do {                                         \
+    (asnprimitives)->size=5;                        \
+    (asnprimitives)->buf=calloc (5, sizeof (uint8_t));            \
+    (asnprimitives)->buf[0] = (uegmaxbitrtu) >> 32;                \
+    (asnprimitives)->buf[1] = (uegmaxbitrtu) >> 24;                \
+    (asnprimitives)->buf[2] = (uegmaxbitrtu) >> 16;                \
+    (asnprimitives)->buf[3] = (uegmaxbitrtu) >> 8;                \
+    (asnprimitives)->buf[4] = (uegmaxbitrtu);                \
+ }while(0)
+
 #define OCTET_STRING_TO_INT8(aSN, x)    \
 do {                                    \
     DevCheck((aSN)->size == 1, (aSN)->size, 0, 0);           \
diff --git a/openair3/UTILS/mme_config.c b/openair3/UTILS/mme_config.c
deleted file mode 100644
index d2c25af10a25e5230cb69ac46e1ed9e3a5c0ea4d..0000000000000000000000000000000000000000
--- a/openair3/UTILS/mme_config.c
+++ /dev/null
@@ -1,716 +0,0 @@
-/*
- * 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
- */
-
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include <libconfig.h>
-
-#include <arpa/inet.h> /* To provide inet_addr */
-
-#include "intertask_interface.h"
-#include "assertions.h"
-#include "msc.h"
-#include "mme_config.h"
-#include "spgw_config.h"
-#include "intertask_interface_conf.h"
-
-mme_config_t mme_config;
-
-int mme_config_find_mnc_length(const char mcc_digit1P,
-                               const char mcc_digit2P,
-                               const char mcc_digit3P,
-                               const char mnc_digit1P,
-                               const char mnc_digit2P,
-                               const char mnc_digit3P)
-{
-
-  uint16_t mcc = 100*mcc_digit1P + 10*mcc_digit2P + mcc_digit3P;
-  uint16_t mnc3= 100*mnc_digit1P + 10*mnc_digit2P + mnc_digit3P;
-  uint16_t mnc2=                   10*mnc_digit1P + mnc_digit2P;
-  int  plmn_index = 0;
-
-  AssertFatal((mcc_digit1P >= 0) && (mcc_digit1P <= 9)
-              && (mcc_digit2P >= 0) && (mcc_digit2P <= 9)
-              && (mcc_digit3P >= 0) && (mcc_digit3P <= 9) ,
-              "BAD MCC PARAMETER (%d%d%d)!\n",
-              mcc_digit1P, mcc_digit2P, mcc_digit3P);
-
-  AssertFatal((mnc_digit2P >= 0) && (mnc_digit2P <= 9)
-              && (mnc_digit1P >= 0) && (mnc_digit1P <= 9) ,
-              "BAD MNC PARAMETER (%d.%d.%d)!\n",
-              mnc_digit1P, mnc_digit2P, mnc_digit3P);
-
-
-  while (plmn_index < mme_config.gummei.nb_plmns) {
-    if (mme_config.gummei.plmn_mcc[plmn_index] == mcc) {
-      if ((mme_config.gummei.plmn_mnc[plmn_index] == mnc2) &&
-          (mme_config.gummei.plmn_mnc_len[plmn_index] == 2)) {
-        return 2;
-      } else if ((mme_config.gummei.plmn_mnc[plmn_index] == mnc3) &&
-                 (mme_config.gummei.plmn_mnc_len[plmn_index] == 3)) {
-        return 3;
-      }
-    }
-
-    plmn_index += 1;
-  }
-
-  return 0;
-}
-
-
-static
-void mme_config_init(mme_config_t *mme_config_p)
-{
-  memset(mme_config_p, 0, sizeof(mme_config_t));
-
-  pthread_rwlock_init(&mme_config_p->rw_lock, NULL);
-
-  mme_config_p->verbosity_level            = 0;
-  mme_config_p->config_file                = NULL;
-  mme_config_p->max_eNBs                   = MAX_NUMBER_OF_ENB;
-  mme_config_p->max_ues                    = MAX_NUMBER_OF_UE;
-
-  mme_config_p->emergency_attach_supported     = 0;
-  mme_config_p->unauthenticated_imsi_supported = 0;
-
-  /* Timer configuration */
-  mme_config_p->gtpv1u_config.port_number = GTPV1_U_PORT_NUMBER;
-  mme_config_p->s1ap_config.port_number   = S1AP_PORT_NUMBER;
-  /* IP configuration */
-  mme_config_p->ipv4.sgw_ip_address_for_S1u_S12_S4_up     = inet_addr(DEFAULT_SGW_IP_ADDRESS_FOR_S1U_S12_S4_UP);
-
-  mme_config_p->ipv4.mme_interface_name_for_S1_MME        = DEFAULT_MME_INTERFACE_NAME_FOR_S1_MME;
-  mme_config_p->ipv4.mme_ip_address_for_S1_MME            = inet_addr(DEFAULT_MME_IP_ADDRESS_FOR_S1_MME);
-
-  mme_config_p->ipv4.mme_interface_name_for_S11           = DEFAULT_MME_INTERFACE_NAME_FOR_S11;
-  mme_config_p->ipv4.mme_ip_address_for_S11               = inet_addr(DEFAULT_MME_IP_ADDRESS_FOR_S11);
-
-  mme_config_p->ipv4.sgw_ip_address_for_S11               = inet_addr(DEFAULT_SGW_IP_ADDRESS_FOR_S11);
-
-  mme_config_p->s6a_config.conf_file    = S6A_CONF_FILE;
-
-  mme_config_p->itti_config.queue_size  = ITTI_QUEUE_MAX_ELEMENTS;
-  mme_config_p->itti_config.log_file    = NULL;
-
-  mme_config_p->sctp_config.in_streams  = SCTP_IN_STREAMS;
-  mme_config_p->sctp_config.out_streams = SCTP_OUT_STREAMS;
-
-  mme_config_p->relative_capacity = RELATIVE_CAPACITY;
-
-  mme_config_p->mme_statistic_timer = MME_STATISTIC_TIMER_S;
-
-  mme_config_p->gummei.nb_mme_gid = 1;
-  mme_config_p->gummei.mme_gid    = calloc(1, sizeof(*mme_config_p->gummei.mme_gid));
-  mme_config_p->gummei.mme_gid[0] = MMEGID;
-  mme_config_p->gummei.nb_mmec    = 1;
-  mme_config_p->gummei.mmec       = calloc(1, sizeof(*mme_config_p->gummei.mmec));
-  mme_config_p->gummei.mmec[0]    = MMEC;
-
-  /* Set the TAI */
-  mme_config_p->gummei.nb_plmns   = 1;
-  mme_config_p->gummei.plmn_mcc   = calloc(1, sizeof(*mme_config_p->gummei.plmn_mcc));
-  mme_config_p->gummei.plmn_mnc   = calloc(1, sizeof(*mme_config_p->gummei.plmn_mnc));
-  mme_config_p->gummei.plmn_mnc_len   = calloc(1, sizeof(*mme_config_p->gummei.plmn_mnc_len));
-  mme_config_p->gummei.plmn_tac   = calloc(1, sizeof(*mme_config_p->gummei.plmn_tac));
-
-
-  mme_config_p->gummei.plmn_mcc[0]     = PLMN_MCC;
-  mme_config_p->gummei.plmn_mnc[0]     = PLMN_MNC;
-  mme_config_p->gummei.plmn_mnc_len[0] = PLMN_MNC_LEN;
-  mme_config_p->gummei.plmn_tac[0]     = PLMN_TAC;
-
-  mme_config_p->s1ap_config.outcome_drop_timer_sec = S1AP_OUTCOME_TIMER_DEFAULT;
-}
-
-int mme_system(char *command_pP, int abort_on_errorP)
-{
-  int ret = -1;
-
-  if (command_pP) {
-    fprintf(stdout, "system command: %s\n",command_pP);
-    ret = system(command_pP);
-
-    if (ret < 0) {
-      fprintf(stderr, "ERROR in system command %s: %d\n",
-              command_pP,ret);
-
-      if (abort_on_errorP) {
-        exit(-1); // may be not exit
-      }
-    }
-  }
-
-  return ret;
-}
-
-
-static int config_parse_file(mme_config_t *mme_config_p)
-{
-  config_t          cfg;
-  config_setting_t *setting_mme                      = NULL;
-  config_setting_t *setting                          = NULL;
-  config_setting_t *subsetting                       = NULL;
-  config_setting_t *sub2setting                      = NULL;
-
-  long int         alongint;
-  int              i, num;
-  char             *astring                          = NULL;
-  char             *address                          = NULL;
-  char             *cidr                             = NULL;
-
-  const char*       tac                              = NULL;
-  const char*       mcc                              = NULL;
-  const char*       mnc                              = NULL;
-
-  char             *sgw_ip_address_for_S1u_S12_S4_up = NULL;
-  char             *mme_interface_name_for_S1_MME    = NULL;
-  char             *mme_ip_address_for_S1_MME        = NULL;
-  char             *mme_interface_name_for_S11       = NULL;
-  char             *mme_ip_address_for_S11           = NULL;
-  char             *sgw_ip_address_for_S11           = NULL;
-  char                system_cmd[256];
-
-  config_init(&cfg);
-
-  if(mme_config_p->config_file != NULL) {
-    /* Read the file. If there is an error, report it and exit. */
-    if(! config_read_file(&cfg, mme_config_p->config_file)) {
-      fprintf(stdout, "ERROR: %s:%d - %s\n", mme_config_p->config_file, config_error_line(&cfg), config_error_text(&cfg));
-      config_destroy(&cfg);
-      AssertFatal (1 == 0, "Failed to parse MME configuration file %s!\n", mme_config_p->config_file);
-    }
-  } else {
-    fprintf(stdout, "ERROR No MME configuration file provided!\n");
-    config_destroy(&cfg);
-    AssertFatal (0, "No MME configuration file provided!\n");
-  }
-
-  setting_mme = config_lookup(&cfg, MME_CONFIG_STRING_MME_CONFIG);
-
-  if(setting_mme != NULL) {
-    // GENERAL MME SETTINGS
-    if(  (config_setting_lookup_string( setting_mme, MME_CONFIG_STRING_REALM, (const char **)&astring) )) {
-      mme_config_p->realm = strdup(astring);
-      mme_config_p->realm_length = strlen(mme_config_p->realm);
-    }
-
-    if(  (config_setting_lookup_int( setting_mme, MME_CONFIG_STRING_MAXENB, &alongint) )) {
-      mme_config_p->max_eNBs = (uint32_t)alongint;
-    }
-
-    if(  (config_setting_lookup_int( setting_mme, MME_CONFIG_STRING_MAXUE, &alongint) )) {
-      mme_config_p->max_ues = (uint32_t)alongint;
-    }
-
-    if(  (config_setting_lookup_int( setting_mme, MME_CONFIG_STRING_RELATIVE_CAPACITY, &alongint) )) {
-      mme_config_p->relative_capacity = (uint8_t)alongint;
-    }
-
-    if(  (config_setting_lookup_int( setting_mme, MME_CONFIG_STRING_STATISTIC_TIMER, &alongint) )) {
-      mme_config_p->mme_statistic_timer = (uint32_t)alongint;
-    }
-
-    if(  (config_setting_lookup_string( setting_mme, MME_CONFIG_STRING_EMERGENCY_ATTACH_SUPPORTED, (const char **)&astring) )) {
-      if (strcasecmp(astring , "yes") == 0)
-        mme_config_p->emergency_attach_supported = 1;
-      else
-        mme_config_p->emergency_attach_supported = 0;
-    }
-
-    if(  (config_setting_lookup_string( setting_mme, MME_CONFIG_STRING_UNAUTHENTICATED_IMSI_SUPPORTED, (const char **)&astring) )) {
-      if (strcasecmp(astring , "yes") == 0)
-        mme_config_p->unauthenticated_imsi_supported = 1;
-      else
-        mme_config_p->unauthenticated_imsi_supported = 0;
-    }
-
-    if(  (config_setting_lookup_string( setting_mme, MME_CONFIG_STRING_ASN1_VERBOSITY, (const char **)&astring) )) {
-      if (strcasecmp(astring , MME_CONFIG_STRING_ASN1_VERBOSITY_NONE) == 0)
-        mme_config_p->verbosity_level = 0;
-      else if (strcasecmp(astring , MME_CONFIG_STRING_ASN1_VERBOSITY_ANNOYING) == 0)
-        mme_config_p->verbosity_level = 2;
-      else if (strcasecmp(astring , MME_CONFIG_STRING_ASN1_VERBOSITY_INFO) == 0)
-        mme_config_p->verbosity_level = 1;
-      else
-        mme_config_p->verbosity_level = 0;
-    }
-
-    // ITTI SETTING
-    setting = config_setting_get_member (setting_mme, MME_CONFIG_STRING_INTERTASK_INTERFACE_CONFIG);
-
-    if (setting != NULL) {
-      if(  (config_setting_lookup_int( setting, MME_CONFIG_STRING_INTERTASK_INTERFACE_QUEUE_SIZE, &alongint) )) {
-        mme_config_p->itti_config.queue_size = (uint32_t)alongint;
-      }
-    }
-
-    // S6A SETTING
-    setting = config_setting_get_member (setting_mme, MME_CONFIG_STRING_S6A_CONFIG);
-
-    if (setting != NULL) {
-      if(  (config_setting_lookup_string( setting, MME_CONFIG_STRING_S6A_CONF_FILE_PATH, (const char **)&astring) )) {
-        if (astring != NULL)
-          mme_config_p->s6a_config.conf_file = strdup(astring);
-      }
-
-      if(  (config_setting_lookup_string( setting, MME_CONFIG_STRING_S6A_HSS_HOSTNAME, (const char **)&astring) )) {
-        if (astring != NULL)
-          mme_config_p->s6a_config.hss_host_name  = strdup(astring);
-        else
-          AssertFatal (1 == 0,
-                       "You have to provide a valid HSS hostname %s=...\n",
-                       MME_CONFIG_STRING_S6A_HSS_HOSTNAME);
-      }
-    }
-
-    // SCTP SETTING
-    setting = config_setting_get_member (setting_mme, MME_CONFIG_STRING_SCTP_CONFIG);
-
-    if (setting != NULL) {
-      if(  (config_setting_lookup_int( setting, MME_CONFIG_STRING_SCTP_INSTREAMS, &alongint) )) {
-        mme_config_p->sctp_config.in_streams = (uint16_t)alongint;
-      }
-
-      if(  (config_setting_lookup_int( setting, MME_CONFIG_STRING_SCTP_OUTSTREAMS, &alongint) )) {
-        mme_config_p->sctp_config.out_streams = (uint16_t)alongint;
-      }
-    }
-
-    // S1AP SETTING
-    setting = config_setting_get_member (setting_mme, MME_CONFIG_STRING_S1AP_CONFIG);
-
-    if (setting != NULL) {
-      if(  (config_setting_lookup_int( setting, MME_CONFIG_STRING_S1AP_OUTCOME_TIMER, &alongint) )) {
-        mme_config_p->s1ap_config.outcome_drop_timer_sec = (uint8_t)alongint;
-      }
-
-      if(  (config_setting_lookup_int( setting, MME_CONFIG_STRING_S1AP_PORT, &alongint) )) {
-        mme_config_p->s1ap_config.port_number = (uint16_t)alongint;
-      }
-    }
-
-    // GUMMEI SETTING
-    setting = config_setting_get_member (setting_mme, MME_CONFIG_STRING_GUMMEI_CONFIG);
-
-    if (setting != NULL) {
-      subsetting = config_setting_get_member (setting, MME_CONFIG_STRING_MME_CODE);
-
-      if (subsetting != NULL) {
-        num     = config_setting_length(subsetting);
-
-        if (mme_config_p->gummei.nb_mmec != num) {
-          if (mme_config_p->gummei.mmec != NULL) {
-            free(mme_config_p->gummei.mmec);
-          }
-
-          mme_config_p->gummei.mmec = calloc(num, sizeof(*mme_config_p->gummei.mmec));
-        }
-
-        mme_config_p->gummei.nb_mmec = num;
-
-        for (i = 0; i < num; i++) {
-          mme_config_p->gummei.mmec[i] = config_setting_get_int_elem(subsetting, i);
-        }
-      }
-
-      subsetting = config_setting_get_member (setting, MME_CONFIG_STRING_MME_GID);
-
-      if (subsetting != NULL) {
-        num     = config_setting_length(subsetting);
-
-        if (mme_config_p->gummei.nb_mme_gid != num) {
-          if (mme_config_p->gummei.mme_gid != NULL) {
-            free(mme_config_p->gummei.mme_gid);
-          }
-
-          mme_config_p->gummei.mme_gid = calloc(num, sizeof(*mme_config_p->gummei.mme_gid));
-        }
-
-        mme_config_p->gummei.nb_mme_gid = num;
-
-        for (i = 0; i < num; i++) {
-          mme_config_p->gummei.mme_gid[i] = config_setting_get_int_elem(subsetting, i);
-        }
-      }
-
-      subsetting = config_setting_get_member (setting, MME_CONFIG_STRING_TAI_LIST);
-
-      if (subsetting != NULL) {
-        num     = config_setting_length(subsetting);
-
-        if (mme_config_p->gummei.nb_plmns != num) {
-          if (mme_config_p->gummei.plmn_mcc != NULL)     free(mme_config_p->gummei.plmn_mcc);
-
-          if (mme_config_p->gummei.plmn_mnc != NULL)     free(mme_config_p->gummei.plmn_mnc);
-
-          if (mme_config_p->gummei.plmn_mnc_len != NULL) free(mme_config_p->gummei.plmn_mnc_len);
-
-          if (mme_config_p->gummei.plmn_tac != NULL)     free(mme_config_p->gummei.plmn_tac);
-
-          mme_config_p->gummei.plmn_mcc     = calloc(num, sizeof(*mme_config_p->gummei.plmn_mcc));
-          mme_config_p->gummei.plmn_mnc     = calloc(num, sizeof(*mme_config_p->gummei.plmn_mnc));
-          mme_config_p->gummei.plmn_mnc_len = calloc(num, sizeof(*mme_config_p->gummei.plmn_mnc_len));
-          mme_config_p->gummei.plmn_tac     = calloc(num, sizeof(*mme_config_p->gummei.plmn_tac));
-        }
-
-        mme_config_p->gummei.nb_plmns = num;
-
-        for (i = 0; i < num; i++) {
-          sub2setting =  config_setting_get_elem(subsetting, i);
-
-          if (sub2setting != NULL) {
-            if(  (config_setting_lookup_string( sub2setting, MME_CONFIG_STRING_MCC, &mcc) )) {
-              mme_config_p->gummei.plmn_mcc[i] = (uint16_t)atoi(mcc);
-            }
-
-            if(  (config_setting_lookup_string( sub2setting, MME_CONFIG_STRING_MNC, &mnc) )) {
-              mme_config_p->gummei.plmn_mnc[i] = (uint16_t)atoi(mnc);
-              mme_config_p->gummei.plmn_mnc_len[i] = strlen(mnc);
-              AssertFatal((mme_config_p->gummei.plmn_mnc_len[i] == 2) || (mme_config_p->gummei.plmn_mnc_len[i] == 3),
-                          "Bad MNC length %u, must be 2 or 3", mme_config_p->gummei.plmn_mnc_len[i]);
-            }
-
-            if(  (config_setting_lookup_string( sub2setting, MME_CONFIG_STRING_TAC, &tac) )) {
-              mme_config_p->gummei.plmn_tac[i] = (uint16_t)atoi(tac);
-              AssertFatal(mme_config_p->gummei.plmn_tac[i] != 0,
-                          "TAC must not be 0");
-            }
-          }
-        }
-      }
-    }
-
-    // NETWORK INTERFACE SETTING
-    setting = config_setting_get_member (setting_mme, MME_CONFIG_STRING_NETWORK_INTERFACES_CONFIG);
-
-    if(setting != NULL) {
-      if(  (
-             config_setting_lookup_string( setting, MME_CONFIG_STRING_INTERFACE_NAME_FOR_S1_MME,
-                                           (const char **)&mme_interface_name_for_S1_MME)
-             && config_setting_lookup_string( setting, MME_CONFIG_STRING_IPV4_ADDRESS_FOR_S1_MME,
-                                              (const char **)&mme_ip_address_for_S1_MME)
-             && config_setting_lookup_string( setting, MME_CONFIG_STRING_INTERFACE_NAME_FOR_S11_MME,
-                                              (const char **)&mme_interface_name_for_S11)
-             && config_setting_lookup_string( setting, MME_CONFIG_STRING_IPV4_ADDRESS_FOR_S11_MME,
-                                              (const char **)&mme_ip_address_for_S11)
-           )
-        ) {
-        mme_config_p->ipv4.mme_interface_name_for_S1_MME = strdup(mme_interface_name_for_S1_MME);
-        cidr = strdup(mme_ip_address_for_S1_MME);
-        address = strtok(cidr, "/");
-        IPV4_STR_ADDR_TO_INT_NWBO ( address, mme_config_p->ipv4.mme_ip_address_for_S1_MME, "BAD IP ADDRESS FORMAT FOR MME S1_MME !\n" )
-        free(cidr);
-
-        mme_config_p->ipv4.mme_interface_name_for_S11 = strdup(mme_interface_name_for_S11);
-        cidr = strdup(mme_ip_address_for_S11);
-        address = strtok(cidr, "/");
-        IPV4_STR_ADDR_TO_INT_NWBO ( address, mme_config_p->ipv4.mme_ip_address_for_S11, "BAD IP ADDRESS FORMAT FOR MME S11 !\n" )
-        free(cidr);
-
-        if (strncasecmp("tun",mme_config_p->ipv4.mme_interface_name_for_S1_MME, strlen("tun")) == 0) {
-          if (snprintf(system_cmd, 256,
-                       "ip link set %s down ;openvpn --rmtun --dev %s",
-                       mme_config_p->ipv4.mme_interface_name_for_S1_MME,
-                       mme_config_p->ipv4.mme_interface_name_for_S1_MME
-                      ) > 0) {
-            mme_system(system_cmd, 1);
-          } else {
-            fprintf(stderr, "Del %s\n", mme_config_p->ipv4.mme_interface_name_for_S1_MME);
-          }
-
-          if (snprintf(system_cmd, 256,
-                       "openvpn --mktun --dev %s;sync;ifconfig  %s up;sync",
-                       mme_config_p->ipv4.mme_interface_name_for_S1_MME,
-                       mme_config_p->ipv4.mme_interface_name_for_S1_MME) > 0) {
-            mme_system(system_cmd, 1);
-          } else {
-            fprintf(stderr, "Create %s\n", mme_config_p->ipv4.mme_interface_name_for_S1_MME);
-          }
-
-          if (snprintf(system_cmd, 256,
-                       "ip -4 addr add %s  dev %s",
-                       mme_ip_address_for_S1_MME,
-                       mme_config_p->ipv4.mme_interface_name_for_S1_MME) > 0) {
-            mme_system(system_cmd, 1);
-          } else {
-            fprintf(stderr, "Set IPv4 address on %s\n", mme_config_p->ipv4.mme_interface_name_for_S1_MME);
-          }
-        }
-
-      }
-    }
-
-    // NAS SETTING
-    setting = config_setting_get_member (setting_mme, MME_CONFIG_STRING_NAS_CONFIG);
-
-    if (setting != NULL) {
-      subsetting = config_setting_get_member (setting, MME_CONFIG_STRING_NAS_SUPPORTED_INTEGRITY_ALGORITHM_LIST);
-
-      if (subsetting != NULL) {
-        num     = config_setting_length(subsetting);
-
-        if (num <= 8) {
-          for (i = 0; i < num; i++) {
-            astring = config_setting_get_string_elem(subsetting, i);
-
-            if (strcmp("EIA0", astring) == 0) mme_config_p->nas_config.prefered_integrity_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EIA0;
-            else if (strcmp("EIA1", astring) == 0) mme_config_p->nas_config.prefered_integrity_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EIA1;
-            else if (strcmp("EIA2", astring) == 0) mme_config_p->nas_config.prefered_integrity_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EIA2;
-            else if (strcmp("EIA3", astring) == 0) mme_config_p->nas_config.prefered_integrity_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EIA0;
-            else if (strcmp("EIA4", astring) == 0) mme_config_p->nas_config.prefered_integrity_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EIA0;
-            else if (strcmp("EIA5", astring) == 0) mme_config_p->nas_config.prefered_integrity_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EIA0;
-            else if (strcmp("EIA6", astring) == 0) mme_config_p->nas_config.prefered_integrity_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EIA0;
-            else if (strcmp("EIA7", astring) == 0) mme_config_p->nas_config.prefered_integrity_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EIA0;
-          }
-
-          for (i = num; i < 8; i++) {
-            mme_config_p->nas_config.prefered_integrity_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EIA0;
-          }
-        }
-      }
-
-      subsetting = config_setting_get_member (setting, MME_CONFIG_STRING_NAS_SUPPORTED_CIPHERING_ALGORITHM_LIST);
-
-      if (subsetting != NULL) {
-        num     = config_setting_length(subsetting);
-
-        if (num <= 8) {
-          for (i = 0; i < num; i++) {
-            astring = config_setting_get_string_elem(subsetting, i);
-
-            if (strcmp("EEA0", astring) == 0) mme_config_p->nas_config.prefered_ciphering_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EEA0;
-            else if (strcmp("EEA1", astring) == 0) mme_config_p->nas_config.prefered_ciphering_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EEA1;
-            else if (strcmp("EEA2", astring) == 0) mme_config_p->nas_config.prefered_ciphering_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EEA2;
-            else if (strcmp("EEA3", astring) == 0) mme_config_p->nas_config.prefered_ciphering_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EEA0;
-            else if (strcmp("EEA4", astring) == 0) mme_config_p->nas_config.prefered_ciphering_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EEA0;
-            else if (strcmp("EEA5", astring) == 0) mme_config_p->nas_config.prefered_ciphering_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EEA0;
-            else if (strcmp("EEA6", astring) == 0) mme_config_p->nas_config.prefered_ciphering_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EEA0;
-            else if (strcmp("EEA7", astring) == 0) mme_config_p->nas_config.prefered_ciphering_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EEA0;
-          }
-
-          for (i = num; i < 8; i++) {
-            mme_config_p->nas_config.prefered_ciphering_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EEA0;
-          }
-        }
-      }
-
-    }
-  }
-
-  setting = config_lookup(&cfg, SGW_CONFIG_STRING_SGW_CONFIG);
-
-  if(setting != NULL) {
-    subsetting = config_setting_get_member (setting, SGW_CONFIG_STRING_NETWORK_INTERFACES_CONFIG);
-
-    if(subsetting != NULL) {
-      if(  (
-             config_setting_lookup_string( subsetting, SGW_CONFIG_STRING_SGW_IPV4_ADDRESS_FOR_S1U_S12_S4_UP,
-                                           (const char **)&sgw_ip_address_for_S1u_S12_S4_up)
-             && config_setting_lookup_string( subsetting, SGW_CONFIG_STRING_SGW_IPV4_ADDRESS_FOR_S11,
-                                              (const char **)&sgw_ip_address_for_S11)
-             && config_setting_lookup_int( subsetting, SGW_CONFIG_STRING_SGW_PORT_FOR_S1U_S12_S4_UP, &alongint)
-           )
-        ) {
-        cidr = strdup(sgw_ip_address_for_S1u_S12_S4_up);
-        address = strtok(cidr, "/");
-        IPV4_STR_ADDR_TO_INT_NWBO ( address, mme_config_p->ipv4.sgw_ip_address_for_S1u_S12_S4_up, "BAD IP ADDRESS FORMAT FOR SGW S1u_S12_S4 !\n" )
-        free(cidr);
-
-        cidr = strdup(sgw_ip_address_for_S11);
-        address = strtok(cidr, "/");
-        IPV4_STR_ADDR_TO_INT_NWBO ( address, mme_config_p->ipv4.sgw_ip_address_for_S11, "BAD IP ADDRESS FORMAT FOR SGW S11 !\n" )
-        free(cidr);
-
-        mme_config_p->gtpv1u_config.port_number = (uint16_t) alongint;
-      }
-    }
-  }
-
-  return 0;
-}
-
-#define DISPLAY_ARRAY(size, format, args...)                        \
-do {                                                                \
-    int i;                                                          \
-    for (i = 0; i < size; i++) {                                    \
-        fprintf(stdout, format, args);                              \
-        if ((i != (size - 1)) && ((i + 1) % 10 == 0))               \
-        {                                                           \
-            fprintf(stdout, "\n        ");                          \
-        }                                                           \
-    }                                                               \
-    if (i > 0)                                                      \
-        fprintf(stdout, "\n");                                      \
-} while(0)
-
-static void config_display(mme_config_t *mme_config_p)
-{
-  int j;
-
-  fprintf(stdout, "==== EURECOM %s v%s ====\n", PACKAGE_NAME, PACKAGE_VERSION);
-  fprintf(stdout, "Configuration:\n");
-  fprintf(stdout, "- File ...............: %s\n", mme_config_p->config_file);
-  fprintf(stdout, "- Verbosity level ....: %d\n", mme_config_p->verbosity_level);
-  fprintf(stdout, "- Realm ..............: %s\n", mme_config_p->realm);
-  fprintf(stdout, "- Max eNBs ...........: %u\n", mme_config_p->max_eNBs);
-  fprintf(stdout, "- Max UEs ............: %u\n", mme_config_p->max_ues);
-  fprintf(stdout, "- Emergency support ..: %s\n", mme_config_p->emergency_attach_supported == 0 ? "FALSE" : "TRUE");
-  fprintf(stdout, "- Unauth IMSI support : %s\n", mme_config_p->unauthenticated_imsi_supported == 0 ? "FALSE" : "TRUE");
-  fprintf(stdout, "- Relative capa ......: %u\n\n", mme_config_p->relative_capacity);
-  fprintf(stdout, "- Statistics timer ...: %u (seconds)\n\n", mme_config_p->mme_statistic_timer);
-  fprintf(stdout, "- S1-U:\n");
-  fprintf(stdout, "    port number ......: %d\n", mme_config_p->gtpv1u_config.port_number);
-  fprintf(stdout, "- S1-MME:\n");
-  fprintf(stdout, "    port number ......: %d\n", mme_config_p->s1ap_config.port_number);
-  fprintf(stdout, "- IP:\n");
-  //fprintf(stdout, "    s1-u iface .......: %s\n", mme_config_p->ipv4.sgw_interface_name_for_S1u_S12_S4_up);
-  fprintf(stdout, "    s1-u ip ..........: %s\n",
-          inet_ntoa(*((struct in_addr *)&mme_config_p->ipv4.sgw_ip_address_for_S1u_S12_S4_up)));
-  //fprintf(stdout, "    sgi iface ........: %s\n", mme_config_p->ipv4.pgw_interface_name_for_SGI);
-  //fprintf(stdout, "    sgi ip ...........: %s/%d\n",
-  //        inet_ntoa(*((struct in_addr *)&mme_config_p->ipv4.pgw_ip_addr_for_SGI)),
-  //        mme_config_p->ipv4.pgw_ip_netmask_for_SGI);
-  fprintf(stdout, "    s1-MME iface .....: %s\n", mme_config_p->ipv4.mme_interface_name_for_S1_MME);
-  fprintf(stdout, "    s1-MME ip ........: %s\n",
-          inet_ntoa(*((struct in_addr *)&mme_config_p->ipv4.mme_ip_address_for_S1_MME)));
-  //fprintf(stdout, "    s11 S-GW iface ...: %s\n", mme_config_p->ipv4.sgw_interface_name_for_S11);
-  //fprintf(stdout, "    s11 S-GW ip ......: %s/%d\n",
-  //        inet_ntoa(*((struct in_addr *)&mme_config_p->ipv4.sgw_ip_address_for_S11)),
-  //        mme_config_p->ipv4.sgw_ip_netmask_for_S11);
-  fprintf(stdout, "    s11 MME iface ....: %s\n", mme_config_p->ipv4.mme_interface_name_for_S11);
-  fprintf(stdout, "    s11 S-GW ip ......: %s\n",
-          inet_ntoa(*((struct in_addr *)&mme_config_p->ipv4.mme_ip_address_for_S11)));
-  fprintf(stdout, "- ITTI:\n");
-  fprintf(stdout, "    queue size .......: %u (bytes)\n", mme_config_p->itti_config.queue_size);
-  fprintf(stdout, "    log file .........: %s\n", mme_config_p->itti_config.log_file);
-  fprintf(stdout, "- SCTP:\n");
-  fprintf(stdout, "    in streams .......: %u\n", mme_config_p->sctp_config.in_streams);
-  fprintf(stdout, "    out streams ......: %u\n", mme_config_p->sctp_config.out_streams);
-  fprintf(stdout, "- GUMMEI:\n");
-  fprintf(stdout, "    mme group ids ....:\n        ");
-  DISPLAY_ARRAY(mme_config_p->gummei.nb_mme_gid, "| %u ", mme_config_p->gummei.mme_gid[i]);
-  fprintf(stdout, "    mme codes ........:\n        ");
-  DISPLAY_ARRAY(mme_config_p->gummei.nb_mmec, "| %u ", mme_config_p->gummei.mmec[i]);
-  fprintf(stdout, "    plmns ............: (mcc.mnc:tac)\n");
-
-  for (j= 0; j < mme_config_p->gummei.nb_plmns; j++) {
-    if (mme_config_p->gummei.plmn_mnc_len[j] ==2 ) {
-      fprintf(stdout, "            %3u.%3u:%u\n",
-              mme_config_p->gummei.plmn_mcc[j],
-              mme_config_p->gummei.plmn_mnc[j],
-              mme_config_p->gummei.plmn_tac[j]);
-    } else {
-      fprintf(stdout, "            %3u.%03u:%u\n",
-              mme_config_p->gummei.plmn_mcc[j],
-              mme_config_p->gummei.plmn_mnc[j],
-              mme_config_p->gummei.plmn_tac[j]);
-    }
-  }
-
-  fprintf(stdout, "- S6A:\n");
-  fprintf(stdout, "    conf file ........: %s\n", mme_config_p->s6a_config.conf_file);
-}
-
-static void usage(void)
-{
-  fprintf(stdout, "==== EURECOM %s v%s ====\n", PACKAGE_NAME, PACKAGE_VERSION);
-  fprintf(stdout, "Please report any bug to: %s\n\n", PACKAGE_BUGREPORT);
-  fprintf(stdout, "Usage: oaisim_mme [options]\n\n");
-  fprintf(stdout, "Available options:\n");
-  fprintf(stdout, "-h      Print this help and return\n");
-  fprintf(stdout, "-c<path>\n");
-  fprintf(stdout, "        Set the configuration file for mme\n");
-  fprintf(stdout, "        See template in UTILS/CONF\n");
-  fprintf(stdout, "-K<file>\n");
-  fprintf(stdout, "        Output intertask messages to provided file\n");
-  fprintf(stdout, "-V      Print %s version and return\n", PACKAGE_NAME);
-  fprintf(stdout, "-v[1-2] Debug level:\n");
-  fprintf(stdout, "            1 -> ASN1 XER printf on and ASN1 debug off\n");
-  fprintf(stdout, "            2 -> ASN1 XER printf on and ASN1 debug on\n");
-}
-
-extern void
-nwGtpv1uDisplayBanner(void);
-
-int config_parse_opt_line(int argc, char *argv[], mme_config_t *mme_config_p)
-{
-  int c;
-  mme_config_init(mme_config_p);
-
-  /* Parsing command line */
-  while ((c = getopt (argc, argv, "O:c:hi:K:v:V")) != -1) {
-    switch (c) {
-    case 'O':
-    case 'c': {
-      /* Store the given configuration file. If no file is given,
-       * then the default values will be used.
-       */
-      int config_file_len = 0;
-      config_file_len = strlen(optarg);
-      mme_config_p->config_file = malloc(sizeof(char) * (config_file_len + 1));
-      memcpy(mme_config_p->config_file, optarg, config_file_len);
-      mme_config_p->config_file[config_file_len] = '\0';
-    }
-    break;
-
-    case 'v': {
-      mme_config_p->verbosity_level = atoi(optarg);
-    }
-    break;
-
-    case 'V': {
-      fprintf(stdout, "==== EURECOM %s v%s ====\n"
-              "Please report any bug to: %s\n", PACKAGE_NAME, PACKAGE_VERSION,
-              PACKAGE_BUGREPORT);
-      exit(0);
-      nwGtpv1uDisplayBanner();
-    }
-    break;
-
-    case 'K':
-      mme_config_p->itti_config.log_file = strdup(optarg);
-      break;
-
-    case 'h': /* Fall through */
-    default:
-      usage();
-      exit(0);
-    }
-  }
-
-  /* Parse the configuration file using libconfig */
-  if (config_parse_file(mme_config_p) != 0) {
-    return -1;
-  }
-
-  /* Display the configuration */
-  config_display(mme_config_p);
-  return 0;
-}
diff --git a/openair3/valgrind.sh b/openair3/valgrind.sh
old mode 100644
new mode 100755
diff --git a/svn2git/git-author-rewrite.sh b/svn2git/git-author-rewrite.sh
old mode 100644
new mode 100755
diff --git a/targets/ARCH/BLADERF/README b/targets/ARCH/BLADERF/README
new file mode 100644
index 0000000000000000000000000000000000000000..c93c938bafcde213308ca785e48a391489fd2d1c
--- /dev/null
+++ b/targets/ARCH/BLADERF/README
@@ -0,0 +1,138 @@
+BladeRF documentation
+=====================
+
+As of 2018-11-06, the bladeRF support is not fully automatic and requires
+some manual settings before use. This documentation is the ultimate source
+of information. If something described in this file does not work or does
+not correspond to the reality, then contact us so we can fix the problems
+and update this documentation.
+
+1. Install bladeRF 2.0 libraries.
+
+    As of now, it's better to install from source.
+    So, do not run: ./build_oai -I -w BLADERF
+    (That is: do not include '-w BLADERF'.)
+
+    Instead, follow the instructions at: https://github.com/Nuand/bladeRF
+
+    If you already had some bladeRF software installed using automatic
+    methods, first remove it by hand ('apt-get purge bladeRF' or something
+    similar, you can get the list of installed bladeRF packages by running
+    'dpkg -l|grep -i blade', remove them all).
+
+2. Update the device.
+
+    Download the latest FX3 firmware and FPGA images from Nuand's website.
+    As of writing, this is:
+
+        https://github.com/Nuand/bladeRF/wiki
+
+    That points to the following pages.
+    For FX3:
+
+        http://www.nuand.com/fx3_images/
+
+    For FPGA:
+
+        http://www.nuand.com/fpga_images/
+
+    Install FX3 firmware:
+
+        sudo bladeRF-cli -f bladeRF_fw_latest.img
+
+    Install FPGA image (this is for BladeRF x40):
+
+        sudo bladeRF-cli -L hostedx40-latest.rbf
+
+    Retrieve calibration information:
+
+        sudo bladeRF-cli -i
+        info
+
+    That outputs the serial number of your device.
+
+    Go to:
+
+        https://www.nuand.com/calibration
+
+    And enter your serial number.
+    The website tells you to run something like:
+
+        sudo bladeRF-cli -i
+        flash_init_cal 40 0x9271
+
+    Actual values depend on your device and serial number.
+
+3. Calibrate the bladeRF device.
+
+    We will work with band 7 on 2.68GHz with a bandwidth of 5 MHz (25 RBs).
+
+    Plug the bladeRF device, then run:
+
+        sudo bladeRF-cli -i
+        set frequency tx 2680000000
+        set frequency rx 2560000000
+        set gain rx 60
+        set gain tx 60
+        set bandwidth 5000000
+        set samplerate 7680000
+        cal lms
+        cal lms
+        cal lms
+        cal dc rxtx
+        cal dc rxtx
+        cal dc rxtx
+
+4. Tune the RX gain using the enb tracer.
+
+    Run the softmodem and the 'enb' tracer. For instructions, see:
+
+        https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/T/basic
+
+    In the enb window, check the 'input signal'. You should see some blue
+    signal as seen at:
+
+        https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/T/enb
+
+    (the 'Time signal power' plot).
+
+    The level should be around 30.
+
+    If it's not around 30 then edit your configuration file and modify
+    the value 'max_rxgain' in the section 'RUs'.
+
+    The configuration file to use is:
+
+        configuration/bladeRF/enb-band7-5mhz.conf
+
+    In the configuration file, you also need to set the correct values for:
+
+        - tracking_area_code
+        - plmn_list: mcc, mnc, mnc_length
+        - mme_ip_address: this is the IP address used by the computer running
+          the softmodem to connect to the EPC
+        - NETWORK_INTERFACES: all the ENB*ADDRESS* variables have to point
+          to the IP address of the EPC machine
+
+5. You're good to go.
+
+    You can now connect a UE and pass some traffic. If everything is well
+    configured you can expect more than 16 Mb/s of throughput in the downlink
+    using iperf and more than 8 Mb/s in the uplink. Looking at the logs, you
+    should find lines containing 'PHR 40' and 'CQI 15'. If your values are
+    lower then your setup may need some adjustments.
+
+6. In case of problems.
+
+    If the performance of the softmodem is very bad, you can stop it and
+    run the calibration again, without setting the parameters (frequencies,
+    gains, etc.). Just run:
+
+        sudo bladeRF-cli -i
+        cal lms
+        cal dc rxtx
+
+    That may help.
+
+    Be sure to use proper radio equipment (duplexer, antennas, clean
+    environment without interferences).
diff --git a/targets/ARCH/BLADERF/USERSPACE/LIB/bladerf_lib.c b/targets/ARCH/BLADERF/USERSPACE/LIB/bladerf_lib.c
index 75a7825669d2320c062ded059aa1ced9c05987bf..3ced5ca833a972d1e8f021733dbf1c2ab71cdb16 100644
--- a/targets/ARCH/BLADERF/USERSPACE/LIB/bladerf_lib.c
+++ b/targets/ARCH/BLADERF/USERSPACE/LIB/bladerf_lib.c
@@ -35,18 +35,18 @@
  * @{
  */
 
-//! Number of BladeRF devices 
+//! Number of BladeRF devices
 #ifdef __SSE4_1__
 #  include <smmintrin.h>
 #endif
- 
+
 #ifdef __AVX2__
 #  include <immintrin.h>
 #endif
 
 int num_devices=0;
 
-/*These items configure the underlying asynch stream used by the the sync interface. 
+/*These items configure the underlying asynch stream used by the the sync interface.
  */
 
 /*! \brief BladeRF Init function (not used at the moment)
@@ -54,128 +54,119 @@ int num_devices=0;
  * \returns 0 on success
  */
 int trx_brf_init(openair0_device *device) {
-   return 0;
+    return 0;
 }
 
 /*! \brief get current timestamp
- *\param device the hardware to use 
+ *\param device the hardware to use
  *\param module the bladeRf module
  *\returns timestamp of BladeRF
  */
- 
+
 openair0_timestamp trx_get_timestamp(openair0_device *device, bladerf_module module) {
-  int status;
-  struct bladerf_metadata meta;
-  brf_state_t *brf = (brf_state_t*)device->priv;
-  memset(&meta, 0, sizeof(meta));
-  
-  if ((status=bladerf_get_timestamp(brf->dev, module, &meta.timestamp)) != 0) {
-    fprintf(stderr,"Failed to get current %s timestamp: %s\n",(module == BLADERF_MODULE_RX ) ? "RX" : "TX", bladerf_strerror(status));
-    return -1; 
-  } // else {printf("Current RX timestampe  0x%016"PRIx64"\n", meta.timestamp); }
-
-  return meta.timestamp;
+    int status;
+    struct bladerf_metadata meta;
+    brf_state_t *brf = (brf_state_t*)device->priv;
+    memset(&meta, 0, sizeof(meta));
+
+    if ((status=bladerf_get_timestamp(brf->dev, module, &meta.timestamp)) != 0) {
+        fprintf(stderr,"Failed to get current %s timestamp: %s\n",(module == BLADERF_MODULE_RX ) ? "RX" : "TX", bladerf_strerror(status));
+        return -1;
+    } // else {printf("Current RX timestampe  0x%016"PRIx64"\n", meta.timestamp); }
+
+    return meta.timestamp;
 }
 
 /*! \brief Start BladeRF
- * \param device the hardware to use 
+ * \param device the hardware to use
  * \returns 0 on success
  */
 int trx_brf_start(openair0_device *device) {
-  brf_state_t *brf = (brf_state_t*)device->priv;
-  int status;
-
-  brf->meta_tx.flags = 0;
-
-  if ((status = bladerf_sync_config(brf->dev,
-          BLADERF_MODULE_TX,
-          BLADERF_FORMAT_SC16_Q11_META,
-          brf->num_buffers,
-          brf->buffer_size,
-          brf->num_transfers,
-          100/*brf->tx_timeout_ms*/)) != 0 ) {
-    fprintf(stderr,"Failed to configure TX sync interface: %s\n", bladerf_strerror(status));
-    abort();
-  }
-  if ((status = bladerf_sync_config(brf->dev,
-          BLADERF_MODULE_RX,
-          BLADERF_FORMAT_SC16_Q11_META,
-          brf->num_buffers,
-          brf->buffer_size,
-          brf->num_transfers,
-          100/*brf->rx_timeout_ms*/)) != 0 ) {
-    fprintf(stderr,"Failed to configure RX sync interface: %s\n", bladerf_strerror(status));
-    abort();
-  }
-  if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_TX, true)) != 0) {
-    fprintf(stderr,"Failed to enable TX module: %s\n", bladerf_strerror(status));
-    abort();
-  }
-  if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_RX, true)) != 0) {
-    fprintf(stderr,"Failed to enable RX module: %s\n", bladerf_strerror(status));
-    abort();
-  }
-
-  if ((status=bladerf_calibrate_dc(brf->dev, BLADERF_MODULE_TX)) != 0) {
-    fprintf(stderr,"Failed to calibrate TX DC: %s\n", bladerf_strerror(status));
-    abort();
-  }
-  if ((status=bladerf_calibrate_dc(brf->dev, BLADERF_MODULE_RX)) != 0) {
-    fprintf(stderr,"Failed to calibrate RX DC: %s\n", bladerf_strerror(status));
-    abort();
-  }
-
-  return 0;
+    brf_state_t *brf = (brf_state_t*)device->priv;
+    int status;
+
+    brf->meta_tx.flags = 0;
+
+    if ((status = bladerf_sync_config(brf->dev,
+                                      BLADERF_MODULE_TX,
+                                      BLADERF_FORMAT_SC16_Q11_META,
+                                      brf->num_buffers,
+                                      brf->buffer_size,
+                                      brf->num_transfers,
+                                      100/*brf->tx_timeout_ms*/)) != 0 ) {
+        fprintf(stderr,"Failed to configure TX sync interface: %s\n", bladerf_strerror(status));
+        abort();
+    }
+    if ((status = bladerf_sync_config(brf->dev,
+                                      BLADERF_MODULE_RX,
+                                      BLADERF_FORMAT_SC16_Q11_META,
+                                      brf->num_buffers,
+                                      brf->buffer_size,
+                                      brf->num_transfers,
+                                      100/*brf->rx_timeout_ms*/)) != 0 ) {
+        fprintf(stderr,"Failed to configure RX sync interface: %s\n", bladerf_strerror(status));
+        abort();
+    }
+    if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_TX, true)) != 0) {
+        fprintf(stderr,"Failed to enable TX module: %s\n", bladerf_strerror(status));
+        abort();
+    }
+    if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_RX, true)) != 0) {
+        fprintf(stderr,"Failed to enable RX module: %s\n", bladerf_strerror(status));
+        abort();
+    }
+
+    return 0;
 }
 
 /*! \brief Called to send samples to the BladeRF RF target
       \param device pointer to the device structure specific to the RF hardware target
-      \param timestamp The timestamp at whicch the first sample MUST be sent 
+      \param timestamp The timestamp at whicch the first sample MUST be sent
       \param buff Buffer which holds the samples
       \param nsamps number of samples to be sent
       \param cc index of the component carrier
       \param flags Ignored for the moment
       \returns 0 on success
-*/ 
+*/
 static int trx_brf_write(openair0_device *device,openair0_timestamp ptimestamp, void **buff, int nsamps, int cc, int flags) {
-  
-  int status;
-  brf_state_t *brf = (brf_state_t*)device->priv;
-  /* BRF has only 1 rx/tx chaine : is it correct? */
-  int16_t *samples = (int16_t*)buff[0];
-  
-  //memset(&brf->meta_tx, 0, sizeof(brf->meta_tx));
-  // When  BLADERF_META_FLAG_TX_NOW is used the timestamp is not used, so one can't schedule a tx 
-  if (brf->meta_tx.flags == 0 ) 
-    brf->meta_tx.flags = (BLADERF_META_FLAG_TX_BURST_START);// | BLADERF_META_FLAG_TX_BURST_END);// |  BLADERF_META_FLAG_TX_NOW);
-  
-  
-  brf->meta_tx.timestamp= (uint64_t) (ptimestamp); 
-  status = bladerf_sync_tx(brf->dev, samples, (unsigned int) nsamps, &brf->meta_tx, 2*brf->tx_timeout_ms);
- 
-  if (brf->meta_tx.flags == BLADERF_META_FLAG_TX_BURST_START) 
-    brf->meta_tx.flags =  BLADERF_META_FLAG_TX_UPDATE_TIMESTAMP;
-  
-
-  if (status != 0) {
-    //fprintf(stderr,"Failed to TX sample: %s\n", bladerf_strerror(status));
-    brf->num_tx_errors++;
-    brf_error(status);
-  } else if (brf->meta_tx.status & BLADERF_META_STATUS_UNDERRUN){
-    /* libbladeRF does not report this status. It is here for future use. */ 
-    fprintf(stderr, "TX Underrun detected. %u valid samples were read.\n",  brf->meta_tx.actual_count);
-    brf->num_underflows++;
-  } 
-  //printf("Provided TX timestampe  %u, meta timestame %u\n", ptimestamp,brf->meta_tx.timestamp);
-  
-  //    printf("tx status %d \n",brf->meta_tx.status);
-  brf->tx_current_ts=brf->meta_tx.timestamp;
-  brf->tx_actual_nsamps+=brf->meta_tx.actual_count;
-  brf->tx_nsamps+=nsamps;
-  brf->tx_count++;
-  
-
-  return nsamps; //brf->meta_tx.actual_count;
+
+    int status;
+    brf_state_t *brf = (brf_state_t*)device->priv;
+    /* BRF has only 1 rx/tx chaine : is it correct? */
+    int16_t *samples = (int16_t*)buff[0];
+
+    //memset(&brf->meta_tx, 0, sizeof(brf->meta_tx));
+    // When  BLADERF_META_FLAG_TX_NOW is used the timestamp is not used, so one can't schedule a tx
+    if (brf->meta_tx.flags == 0 )
+        brf->meta_tx.flags = (BLADERF_META_FLAG_TX_BURST_START);// | BLADERF_META_FLAG_TX_BURST_END);// |  BLADERF_META_FLAG_TX_NOW);
+
+
+    brf->meta_tx.timestamp= (uint64_t) (ptimestamp);
+    status = bladerf_sync_tx(brf->dev, samples, (unsigned int) nsamps, &brf->meta_tx, 2*brf->tx_timeout_ms);
+
+    if (brf->meta_tx.flags == BLADERF_META_FLAG_TX_BURST_START)
+        brf->meta_tx.flags =  BLADERF_META_FLAG_TX_UPDATE_TIMESTAMP;
+
+
+    if (status != 0) {
+        //fprintf(stderr,"Failed to TX sample: %s\n", bladerf_strerror(status));
+        brf->num_tx_errors++;
+        brf_error(status);
+    } else if (brf->meta_tx.status & BLADERF_META_STATUS_UNDERRUN) {
+        /* libbladeRF does not report this status. It is here for future use. */
+        fprintf(stderr, "TX Underrun detected. %u valid samples were read.\n",  brf->meta_tx.actual_count);
+        brf->num_underflows++;
+    }
+    //printf("Provided TX timestampe  %u, meta timestame %u\n", ptimestamp,brf->meta_tx.timestamp);
+
+    //    printf("tx status %d \n",brf->meta_tx.status);
+    brf->tx_current_ts=brf->meta_tx.timestamp;
+    brf->tx_actual_nsamps+=brf->meta_tx.actual_count;
+    brf->tx_nsamps+=nsamps;
+    brf->tx_count++;
+
+
+    return nsamps; //brf->meta_tx.actual_count;
 }
 
 /*! \brief Receive samples from hardware.
@@ -191,91 +182,90 @@ static int trx_brf_write(openair0_device *device,openair0_timestamp ptimestamp,
 */
 static int trx_brf_read(openair0_device *device, openair0_timestamp *ptimestamp, void **buff, int nsamps, int cc) {
 
-  int status=0;
-  brf_state_t *brf = (brf_state_t*)device->priv;
-  
-  // BRF has only one rx/tx chain
-  int16_t *samples = (int16_t*)buff[0];
-  
-  brf->meta_rx.actual_count = 0;
-  brf->meta_rx.flags = BLADERF_META_FLAG_RX_NOW;
-  status = bladerf_sync_rx(brf->dev, samples, (unsigned int) nsamps, &brf->meta_rx, 2*brf->rx_timeout_ms);
-  
-  //  printf("Current RX timestampe  %u, nsamps %u, actual %u, cc %d\n",  brf->meta_rx.timestamp, nsamps, brf->meta_rx.actual_count, cc);
-   
-  if (status != 0) {
-    fprintf(stderr, "RX failed: %s\n", bladerf_strerror(status)); 
-    //    printf("RX failed: %s\n", bladerf_strerror(status)); 
-    brf->num_rx_errors++;
-  } else if ( brf->meta_rx.status & BLADERF_META_STATUS_OVERRUN) {
-    brf->num_overflows++;
-    printf("RX overrun (%d) is detected. t=" "%" PRIu64 "Got %u samples. nsymps %d\n", 
-	   brf->num_overflows,brf->meta_rx.timestamp,  brf->meta_rx.actual_count, nsamps);
-  } 
-
-  if (brf->meta_rx.actual_count != nsamps) {
-    printf("RX bad samples count, wanted %d, got %d\n", nsamps, brf->meta_rx.actual_count);
-  }
-
-  //printf("Current RX timestampe  %u\n",  brf->meta_rx.timestamp);
-  //printf("[BRF] (buff %p) ts=0x%"PRIu64" %s\n",samples, brf->meta_rx.timestamp,bladerf_strerror(status));
-  brf->rx_current_ts=brf->meta_rx.timestamp;
-  brf->rx_actual_nsamps+=brf->meta_rx.actual_count;
-  brf->rx_nsamps+=nsamps;
-  brf->rx_count++;
-  
-  
-  *ptimestamp = brf->meta_rx.timestamp;
- 
-  return nsamps; //brf->meta_rx.actual_count;
+    int status=0;
+    brf_state_t *brf = (brf_state_t*)device->priv;
+
+    // BRF has only one rx/tx chain
+    int16_t *samples = (int16_t*)buff[0];
+
+    brf->meta_rx.actual_count = 0;
+    brf->meta_rx.flags = BLADERF_META_FLAG_RX_NOW;
+    status = bladerf_sync_rx(brf->dev, samples, (unsigned int) nsamps, &brf->meta_rx, 2*brf->rx_timeout_ms);
+
+    //  printf("Current RX timestampe  %u, nsamps %u, actual %u, cc %d\n",  brf->meta_rx.timestamp, nsamps, brf->meta_rx.actual_count, cc);
+
+    if (status != 0) {
+        fprintf(stderr, "RX failed: %s\n", bladerf_strerror(status));
+        //    printf("RX failed: %s\n", bladerf_strerror(status));
+        brf->num_rx_errors++;
+    } else if ( brf->meta_rx.status & BLADERF_META_STATUS_OVERRUN) {
+        brf->num_overflows++;
+        printf("RX overrun (%d) is detected. t=" "%" PRIu64 "Got %u samples. nsymps %d\n",
+               brf->num_overflows,brf->meta_rx.timestamp,  brf->meta_rx.actual_count, nsamps);
+    }
+
+    if (brf->meta_rx.actual_count != nsamps) {
+        printf("RX bad samples count, wanted %d, got %d\n", nsamps, brf->meta_rx.actual_count);
+    }
+
+    //printf("Current RX timestampe  %u\n",  brf->meta_rx.timestamp);
+    //printf("[BRF] (buff %p) ts=0x%"PRIu64" %s\n",samples, brf->meta_rx.timestamp,bladerf_strerror(status));
+    brf->rx_current_ts=brf->meta_rx.timestamp;
+    brf->rx_actual_nsamps+=brf->meta_rx.actual_count;
+    brf->rx_nsamps+=nsamps;
+    brf->rx_count++;
+
+
+    *ptimestamp = brf->meta_rx.timestamp;
+
+    return nsamps; //brf->meta_rx.actual_count;
 
 }
 
-/*! \brief Terminate operation of the BladeRF transceiver -- free all associated resources 
+/*! \brief Terminate operation of the BladeRF transceiver -- free all associated resources
  * \param device the hardware to use
  */
 void trx_brf_end(openair0_device *device) {
-abort();
-
-  int status;
-  brf_state_t *brf = (brf_state_t*)device->priv;
-  // Disable RX module, shutting down our underlying RX stream
-  if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_RX, false))  != 0) {
-    fprintf(stderr, "Failed to disable RX module: %s\n", bladerf_strerror(status));
-  }
-  if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_TX, false))  != 0) {
-    fprintf(stderr, "Failed to disable TX module: %s\n",  bladerf_strerror(status));
-  }
-  bladerf_close(brf->dev);
+    int status;
+    brf_state_t *brf = (brf_state_t*)device->priv;
+    // Disable RX module, shutting down our underlying RX stream
+    if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_RX, false))  != 0) {
+        fprintf(stderr, "Failed to disable RX module: %s\n", bladerf_strerror(status));
+    }
+    if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_TX, false))  != 0) {
+        fprintf(stderr, "Failed to disable TX module: %s\n",  bladerf_strerror(status));
+    }
+    bladerf_close(brf->dev);
+    exit(1);
 }
 
-/*! \brief print the BladeRF statistics  
+/*! \brief print the BladeRF statistics
 * \param device the hardware to use
 * \returns  0 on success
 */
 int trx_brf_get_stats(openair0_device* device) {
 
-  return(0);
+    return(0);
 
 }
 
-/*! \brief Reset the BladeRF statistics  
+/*! \brief Reset the BladeRF statistics
 * \param device the hardware to use
 * \returns  0 on success
 */
 int trx_brf_reset_stats(openair0_device* device) {
 
-  return(0);
+    return(0);
 
 }
 
 /*! \brief Stop BladeRF
  * \param card the hardware to use
- * \returns 0 in success 
+ * \returns 0 in success
  */
 int trx_brf_stop(openair0_device* device) {
 
-  return(0);
+    return(0);
 
 }
 
@@ -283,39 +273,39 @@ int trx_brf_stop(openair0_device* device) {
  * \param device the hardware to use
  * \param openair0_cfg1 openair0 Config structure (ignored. It is there to comply with RF common API)
  * \param exmimo_dump_config (ignored)
- * \returns 0 in success 
+ * \returns 0 in success
  */
 int trx_brf_set_freq(openair0_device* device, openair0_config_t *openair0_cfg1,int exmimo_dump_config) {
 
-  int status;
-  brf_state_t *brf = (brf_state_t *)device->priv;
-  openair0_config_t *openair0_cfg = (openair0_config_t *)device->openair0_cfg;
+    int status;
+    brf_state_t *brf = (brf_state_t *)device->priv;
+    openair0_config_t *openair0_cfg = (openair0_config_t *)device->openair0_cfg;
 
 
-  if ((status=bladerf_set_frequency(brf->dev, BLADERF_MODULE_TX, (unsigned int) openair0_cfg->tx_freq[0])) != 0){
-    fprintf(stderr,"Failed to set TX frequency: %s\n",bladerf_strerror(status));
-    brf_error(status);
-  }else 
-    printf("[BRF] set TX Frequency to %u\n", (unsigned int) openair0_cfg->tx_freq[0]);
+    if ((status=bladerf_set_frequency(brf->dev, BLADERF_MODULE_TX, (unsigned int) openair0_cfg->tx_freq[0])) != 0) {
+        fprintf(stderr,"Failed to set TX frequency: %s\n",bladerf_strerror(status));
+        brf_error(status);
+    } else
+        printf("[BRF] set TX Frequency to %u\n", (unsigned int) openair0_cfg->tx_freq[0]);
 
-  if ((status=bladerf_set_frequency(brf->dev, BLADERF_MODULE_RX, (unsigned int) openair0_cfg->rx_freq[0])) != 0){
-    fprintf(stderr,"Failed to set RX frequency: %s\n",bladerf_strerror(status));
-    brf_error(status);
-  } else 
-    printf("[BRF] set RX frequency to %u\n",(unsigned int)openair0_cfg->rx_freq[0]);
+    if ((status=bladerf_set_frequency(brf->dev, BLADERF_MODULE_RX, (unsigned int) openair0_cfg->rx_freq[0])) != 0) {
+        fprintf(stderr,"Failed to set RX frequency: %s\n",bladerf_strerror(status));
+        brf_error(status);
+    } else
+        printf("[BRF] set RX frequency to %u\n",(unsigned int)openair0_cfg->rx_freq[0]);
 
-  return(0);
+    return(0);
 
 }
 
 /*! \brief Set Gains (TX/RX)
  * \param device the hardware to use
  * \param openair0_cfg openair0 Config structure
- * \returns 0 in success 
+ * \returns 0 in success
  */
 int trx_brf_set_gains(openair0_device* device, openair0_config_t *openair0_cfg) {
 
-  return(0);
+    return(0);
 
 }
 
@@ -327,10 +317,11 @@ int16_t cos_3fsover8[8] = {2047,  -1448,      0,   1447,  -2047,   1447,     0,
 
 /*! \brief calibration table for BladeRF */
 rx_gain_calib_table_t calib_table_fx4[] = {
-  {2300000000.0,53.5},
-  {1880000000.0,57.0},
-  {816000000.0,73.0},
-  {-1,0}};
+    {2300000000.0,53.5},
+    {1880000000.0,57.0},
+    {816000000.0,73.0},
+    {-1,0}
+};
 
 /*! \brief set RX gain offset from calibration table
  * \param openair0_cfg RF frontend parameters set by application
@@ -338,817 +329,822 @@ rx_gain_calib_table_t calib_table_fx4[] = {
  */
 void set_rx_gain_offset(openair0_config_t *openair0_cfg, int chain_index) {
 
-  int i=0;
-  // loop through calibration table to find best adjustment factor for RX frequency
-  double min_diff = 6e9,diff;
-  
-  while (openair0_cfg->rx_gain_calib_table[i].freq>0) {
-    diff = fabs(openair0_cfg->rx_freq[chain_index] - openair0_cfg->rx_gain_calib_table[i].freq);
-    printf("cal %d: freq %f, offset %f, diff %f\n",
-	   i,
-	   openair0_cfg->rx_gain_calib_table[i].freq,
-	   openair0_cfg->rx_gain_calib_table[i].offset,diff);
-    if (min_diff > diff) {
-      min_diff = diff;
-      openair0_cfg->rx_gain_offset[chain_index] = openair0_cfg->rx_gain_calib_table[i].offset;
+    int i=0;
+    // loop through calibration table to find best adjustment factor for RX frequency
+    double min_diff = 6e9,diff;
+
+    while (openair0_cfg->rx_gain_calib_table[i].freq>0) {
+        diff = fabs(openair0_cfg->rx_freq[chain_index] - openair0_cfg->rx_gain_calib_table[i].freq);
+        printf("cal %d: freq %f, offset %f, diff %f\n",
+               i,
+               openair0_cfg->rx_gain_calib_table[i].freq,
+               openair0_cfg->rx_gain_calib_table[i].offset,diff);
+        if (min_diff > diff) {
+            min_diff = diff;
+            openair0_cfg->rx_gain_offset[chain_index] = openair0_cfg->rx_gain_calib_table[i].offset;
+        }
+        i++;
     }
-    i++;
-  }
-  
+
 }
 
-/*! \brief Calibrate LMSSDR RF 
+/*! \brief Calibrate LMSSDR RF
  * \param device the hardware to use
  */
 void calibrate_rf(openair0_device *device) {
 
-
-  brf_state_t *brf = (brf_state_t *)device->priv;
-  openair0_timestamp ptimestamp;
-  int16_t *calib_buffp,*calib_tx_buffp;
-  int16_t calib_buff[2*RXDCLENGTH];
-  int16_t calib_tx_buff[2*RXDCLENGTH];
-  int i,j,offI,offQ,offIold,offQold,offInew,offQnew,offphase,offphaseold,offphasenew,offgain,offgainold,offgainnew;
-  int32_t meanI,meanQ,meanIold,meanQold;
-  int cnt=0,loop;
-
-  // put TX on a far-away frequency to avoid interference in RX band
-  bladerf_set_frequency(brf->dev,BLADERF_MODULE_TX, (unsigned int) device->openair0_cfg->rx_freq[0] + 200e6);  
-  // Set gains to close to max
-  bladerf_set_gain(brf->dev, BLADERF_MODULE_RX, 60);
-  bladerf_set_gain(brf->dev, BLADERF_MODULE_TX, 60);
-
-  // fill TX buffer with fs/8 complex sinusoid
-  j=0;
-  for (i=0;i<RXDCLENGTH;i++) {
-    calib_tx_buff[j++] = cos_fsover8[i&7];
-    calib_tx_buff[j++] = cos_fsover8[(i+6)&7];  // sin
-  }
-  calib_buffp = &calib_buff[0];
-  calib_tx_buffp = &calib_tx_buff[0];
-  // Calibrate RX DC offset
-
-  offIold=offQold=2048;
-  bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_I,offIold);
-  bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_Q,offQold);
-  for (i=0;i<10;i++)
-    trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
-  
-  for (meanIold=meanQold=i=j=0;i<RXDCLENGTH;i++) {
-    meanIold+=calib_buff[j++];
-    meanQold+=calib_buff[j++];
-  }
-  meanIold/=RXDCLENGTH;
-  meanQold/=RXDCLENGTH;
-  printf("[BRF] RX DC: (%d,%d) => (%d,%d)\n",offIold,offQold,meanIold,meanQold);
-
-  offI=offQ=-2048;
-  bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_I,offI);
-  bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_Q,offQ);
-  for (i=0;i<10;i++)
-    trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
-  
-  for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) {
-    meanI+=calib_buff[j++];
-    meanQ+=calib_buff[j++];
-  }
-  meanI/=RXDCLENGTH;
-  meanQ/=RXDCLENGTH;
-  //  printf("[BRF] RX DC: (%d,%d) => (%d,%d)\n",offI,offQ,meanI,meanQ);
-
-  while (cnt++ < 12) {
-
-    offInew=(offIold+offI)>>1;
-    offQnew=(offQold+offQ)>>1;
-
-    if (meanI*meanI < meanIold*meanIold) {
-      meanIold = meanI;
-      offIold = offI;
-      printf("[BRF] *** RX DC: offI %d => %d\n",offIold,meanI);
+    /* TODO: this function does not seem to work. Disabled until fixed. */
+    return;
+
+    brf_state_t *brf = (brf_state_t *)device->priv;
+    openair0_timestamp ptimestamp;
+    int16_t *calib_buffp,*calib_tx_buffp;
+    int16_t calib_buff[2*RXDCLENGTH];
+    int16_t calib_tx_buff[2*RXDCLENGTH];
+    int i,j,offI,offQ,offIold,offQold,offInew,offQnew,offphase,offphaseold,offphasenew,offgain,offgainold,offgainnew;
+    int32_t meanI,meanQ,meanIold,meanQold;
+    int cnt=0,loop;
+
+    // put TX on a far-away frequency to avoid interference in RX band
+    bladerf_set_frequency(brf->dev,BLADERF_MODULE_TX, (unsigned int) device->openair0_cfg->rx_freq[0] + 200e6);
+    // Set gains to close to max
+    bladerf_set_gain(brf->dev, BLADERF_MODULE_RX, 60);
+    bladerf_set_gain(brf->dev, BLADERF_MODULE_TX, 60);
+
+    // fill TX buffer with fs/8 complex sinusoid
+    j=0;
+    for (i=0; i<RXDCLENGTH; i++) {
+        calib_tx_buff[j++] = cos_fsover8[i&7];
+        calib_tx_buff[j++] = cos_fsover8[(i+6)&7];  // sin
     }
-    if (meanQ*meanQ < meanQold*meanQold) {
-      meanQold = meanQ;
-      offQold = offQ;
-      printf("[BRF] *** RX DC: offQ %d => %d\n",offQold,meanQ);
+    calib_buffp = &calib_buff[0];
+    calib_tx_buffp = &calib_tx_buff[0];
+    // Calibrate RX DC offset
+
+    offIold=offQold=2048;
+    bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_I,offIold);
+    bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_Q,offQold);
+    for (i=0; i<10; i++)
+        trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
+
+    for (meanIold=meanQold=i=j=0; i<RXDCLENGTH; i++) {
+        meanIold+=calib_buff[j++];
+        meanQold+=calib_buff[j++];
     }
-    offI = offInew;
-    offQ = offQnew;
+    meanIold/=RXDCLENGTH;
+    meanQold/=RXDCLENGTH;
+    printf("[BRF] RX DC: (%d,%d) => (%d,%d)\n",offIold,offQold,meanIold,meanQold);
+
+    offI=offQ=-2048;
     bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_I,offI);
     bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_Q,offQ);
+    for (i=0; i<10; i++)
+        trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
 
-    for (i=0;i<10;i++)
-      trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
-    
-    for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) {
-      meanI+=calib_buff[j++];
-      meanQ+=calib_buff[j++];
+    for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) {
+        meanI+=calib_buff[j++];
+        meanQ+=calib_buff[j++];
     }
     meanI/=RXDCLENGTH;
     meanQ/=RXDCLENGTH;
-    printf("[BRF] RX DC: (%d,%d) => (%d,%d)\n",offI,offQ,meanI,meanQ);
-  }
-
-  printf("[BRF] RX DC: (%d,%d) => (%d,%d)\n",offIold,offQold,meanIold,meanQold);
-  bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_I,offIold);
-  bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_Q,offQold);
-
-  // TX DC offset
-  // PUT TX as f_RX + fs/4
-  // loop back BLADERF_LB_RF_LNA1
-  bladerf_set_frequency(brf->dev,BLADERF_MODULE_TX, (unsigned int) device->openair0_cfg->rx_freq[0] + (unsigned int) device->openair0_cfg->sample_rate/4);  
-  bladerf_set_loopback (brf->dev,BLADERF_LB_RF_LNA1);
-
-  offIold=2048;
-  bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_I,offIold);
-  for (i=0;i<10;i++) {
-    trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
-    trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
-  }
-  for (meanIold=meanQold=i=j=0;i<RXDCLENGTH;i++) {
-    switch (i&3) {
-    case 0:
-      meanIold+=calib_buff[j++];
-      break;
-    case 1:
-      meanQold+=calib_buff[j++];
-      break;
-    case 2:
-      meanIold-=calib_buff[j++];
-      break;
-    case 3:
-      meanQold-=calib_buff[j++];
-      break;
+    //  printf("[BRF] RX DC: (%d,%d) => (%d,%d)\n",offI,offQ,meanI,meanQ);
+
+    while (cnt++ < 12) {
+
+        offInew=(offIold+offI)>>1;
+        offQnew=(offQold+offQ)>>1;
+
+        if (meanI*meanI < meanIold*meanIold) {
+            meanIold = meanI;
+            offIold = offI;
+            printf("[BRF] *** RX DC: offI %d => %d\n",offIold,meanI);
+        }
+        if (meanQ*meanQ < meanQold*meanQold) {
+            meanQold = meanQ;
+            offQold = offQ;
+            printf("[BRF] *** RX DC: offQ %d => %d\n",offQold,meanQ);
+        }
+        offI = offInew;
+        offQ = offQnew;
+        bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_I,offI);
+        bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_Q,offQ);
+
+        for (i=0; i<10; i++)
+            trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
+
+        for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) {
+            meanI+=calib_buff[j++];
+            meanQ+=calib_buff[j++];
+        }
+        meanI/=RXDCLENGTH;
+        meanQ/=RXDCLENGTH;
+        printf("[BRF] RX DC: (%d,%d) => (%d,%d)\n",offI,offQ,meanI,meanQ);
     }
-  }
-  //  meanIold/=RXDCLENGTH;
-  //  meanQold/=RXDCLENGTH;
-  printf("[BRF] TX DC (offI): %d => (%d,%d)\n",offIold,meanIold,meanQold);
-
-  offI=-2048;
-  bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_I,offI);
-  for (i=0;i<10;i++) {
-    trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
-    trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
-  }
-  for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) {
-    switch (i&3) {
-    case 0:
-      meanI+=calib_buff[j++];
-      break;
-    case 1:
-      meanQ+=calib_buff[j++];
-      break;
-    case 2:
-      meanI-=calib_buff[j++];
-      break;
-    case 3:
-      meanQ-=calib_buff[j++];
-      break;
+
+    printf("[BRF] RX DC: (%d,%d) => (%d,%d)\n",offIold,offQold,meanIold,meanQold);
+    bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_I,offIold);
+    bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_Q,offQold);
+
+    // TX DC offset
+    // PUT TX as f_RX + fs/4
+    // loop back BLADERF_LB_RF_LNA1
+    bladerf_set_frequency(brf->dev,BLADERF_MODULE_TX, (unsigned int) device->openair0_cfg->rx_freq[0] + (unsigned int) device->openair0_cfg->sample_rate/4);
+    bladerf_set_loopback (brf->dev,BLADERF_LB_RF_LNA1);
+
+    offIold=2048;
+    bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_I,offIold);
+    for (i=0; i<10; i++) {
+        trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
+        trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
     }
-  }
-  //  meanI/=RXDCLENGTH;
-  //  meanQ/=RXDCLENGTH;
-  printf("[BRF] TX DC (offI): %d => (%d,%d)\n",offI,meanI,meanQ);
-  cnt = 0;
-  while (cnt++ < 12) {
-
-    offInew=(offIold+offI)>>1;
-    if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) {
-      printf("[BRF] TX DC (offI): ([%d,%d]) => %d : %d\n",offIold,offI,offInew,meanI*meanI+meanQ*meanQ);
-      meanIold = meanI;
-      meanQold = meanQ;
-      offIold = offI;
+    for (meanIold=meanQold=i=j=0; i<RXDCLENGTH; i++) {
+        switch (i&3) {
+        case 0:
+            meanIold+=calib_buff[j++];
+            break;
+        case 1:
+            meanQold+=calib_buff[j++];
+            break;
+        case 2:
+            meanIold-=calib_buff[j++];
+            break;
+        case 3:
+            meanQold-=calib_buff[j++];
+            break;
+        }
     }
-    offI = offInew;
-    bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_I,offI);
+    //  meanIold/=RXDCLENGTH;
+    //  meanQold/=RXDCLENGTH;
+    printf("[BRF] TX DC (offI): %d => (%d,%d)\n",offIold,meanIold,meanQold);
 
-    for (i=0;i<10;i++) {
-      trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
-      trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
-    }
-    for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) {
-      switch (i&3) {
-      case 0:
-	meanI+=calib_buff[j++];
-	break;
-      case 1:
-	meanQ+=calib_buff[j++];
-	break;
-      case 2:
-	meanI-=calib_buff[j++];
-	break;
-      case 3:
-	meanQ-=calib_buff[j++];
-	break;
-      }
+    offI=-2048;
+    bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_I,offI);
+    for (i=0; i<10; i++) {
+        trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
+        trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
     }
-    //    meanI/=RXDCLENGTH;
-    //   meanQ/=RXDCLENGTH;
-    //    printf("[BRF] TX DC (offI): %d => (%d,%d)\n",offI,meanI,meanQ);
-  }
-
-  bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_I,offIold);
-
-  offQold=2048;
-  bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_Q,offQold);
-  for (i=0;i<10;i++) {
-    trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
-    trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
-  }
-  // project on fs/4
-  for (meanIold=meanQold=i=j=0;i<RXDCLENGTH;i++) {
-    switch (i&3) {
-    case 0:
-      meanIold+=calib_buff[j++];
-      break;
-    case 1:
-      meanQold+=calib_buff[j++];
-      break;
-    case 2:
-      meanIold-=calib_buff[j++];
-      break;
-    case 3:
-      meanQold-=calib_buff[j++];
-      break;
+    for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) {
+        switch (i&3) {
+        case 0:
+            meanI+=calib_buff[j++];
+            break;
+        case 1:
+            meanQ+=calib_buff[j++];
+            break;
+        case 2:
+            meanI-=calib_buff[j++];
+            break;
+        case 3:
+            meanQ-=calib_buff[j++];
+            break;
+        }
     }
-  }
-  //  meanIold/=RXDCLENGTH;
-  //  meanQold/=RXDCLENGTH;
-  printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQold,meanIold,meanQold);
-
-  offQ=-2048;
-  bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_Q,offQ);
-  for (i=0;i<10;i++) {
-    trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
-    trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
-  }
-  for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) {
-    switch (i&3) {
-    case 0:
-      meanI+=calib_buff[j++];
-      break;
-    case 1:
-      meanQ+=calib_buff[j++];
-      break;
-    case 2:
-      meanI-=calib_buff[j++];
-      break;
-    case 3:
-      meanQ-=calib_buff[j++];
-      break;
+    //  meanI/=RXDCLENGTH;
+    //  meanQ/=RXDCLENGTH;
+    printf("[BRF] TX DC (offI): %d => (%d,%d)\n",offI,meanI,meanQ);
+    cnt = 0;
+    while (cnt++ < 12) {
+
+        offInew=(offIold+offI)>>1;
+        if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) {
+            printf("[BRF] TX DC (offI): ([%d,%d]) => %d : %d\n",offIold,offI,offInew,meanI*meanI+meanQ*meanQ);
+            meanIold = meanI;
+            meanQold = meanQ;
+            offIold = offI;
+        }
+        offI = offInew;
+        bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_I,offI);
+
+        for (i=0; i<10; i++) {
+            trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
+            trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
+        }
+        for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) {
+            switch (i&3) {
+            case 0:
+                meanI+=calib_buff[j++];
+                break;
+            case 1:
+                meanQ+=calib_buff[j++];
+                break;
+            case 2:
+                meanI-=calib_buff[j++];
+                break;
+            case 3:
+                meanQ-=calib_buff[j++];
+                break;
+            }
+        }
+        //    meanI/=RXDCLENGTH;
+        //   meanQ/=RXDCLENGTH;
+        //    printf("[BRF] TX DC (offI): %d => (%d,%d)\n",offI,meanI,meanQ);
     }
-  }
-  //  meanI/=RXDCLENGTH;
-  //  meanQ/=RXDCLENGTH;
-  printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ);
-
-  cnt=0;
-  while (cnt++ < 12) {
 
-    offQnew=(offQold+offQ)>>1;
-    if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) {
-      printf("[BRF] TX DC (offQ): ([%d,%d]) => %d : %d\n",offQold,offQ,offQnew,meanI*meanI+meanQ*meanQ);
+    bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_I,offIold);
 
-      meanIold = meanI;
-      meanQold = meanQ;
-      offQold = offQ;
-    }
-    offQ = offQnew;
-    bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_Q,offQ);
-
-    for (i=0;i<10;i++) {
-      trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
-      trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
-    }
-    for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) {
-      switch (i&3) {
-      case 0:
-	meanI+=calib_buff[j++];
-	break;
-      case 1:
-	meanQ+=calib_buff[j++];
-	break;
-      case 2:
-	meanI-=calib_buff[j++];
-	break;
-      case 3:
-	meanQ-=calib_buff[j++];
-	break;
-      }
-    }
-    //    meanI/=RXDCLENGTH;
-    //   meanQ/=RXDCLENGTH;
-    //    printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ);
-  }
-
-  printf("[BRF] TX DC: (%d,%d) => (%d,%d)\n",offIold,offQold,meanIold,meanQold);
-
-  bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_Q,offQold);
-
-  // TX IQ imbalance
-  for (loop=0;loop<2;loop++) {
-    offphaseold=4096;
-    bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_PHASE,offphaseold);
-    for (i=0;i<10;i++) {
-      trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
-      trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
-    }
-    // project on fs/8 (Image of TX signal in +ve frequencies)
-    for (meanIold=meanQold=i=j=0;i<RXDCLENGTH;i++) {
-      meanIold+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11;
-      meanQold+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11;
-      j+=2;
+    offQold=2048;
+    bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_Q,offQold);
+    for (i=0; i<10; i++) {
+        trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
+        trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
     }
-    
-    meanIold/=RXDCLENGTH;
-    meanQold/=RXDCLENGTH;
-    printf("[BRF] TX IQ (offphase): %d => (%d,%d)\n",offphaseold,meanIold,meanQold);
-    
-    offphase=-4096;
-    bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_PHASE,offphase);
-    for (i=0;i<10;i++) {
-      trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
-      trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
-    }
-    // project on fs/8 (Image of TX signal in +ve frequencies)
-    for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) {
-      meanI+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11;
-      meanQ+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11;
-      j+=2;
-    }
-    
-    meanI/=RXDCLENGTH;
-    meanQ/=RXDCLENGTH;
-    printf("[BRF] TX IQ (offphase): %d => (%d,%d)\n",offphase,meanI,meanQ);
-    
-    cnt=0;
-    while (cnt++ < 13) {
-      
-      offphasenew=(offphaseold+offphase)>>1;
-      printf("[BRF] TX IQ (offphase): ([%d,%d]) => %d : %d\n",offphaseold,offphase,offphasenew,meanI*meanI+meanQ*meanQ);
-      if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) {
-
-	
-	meanIold = meanI;
-	meanQold = meanQ;
-	offphaseold = offphase;
-      }
-      offphase = offphasenew;
-      bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_PHASE,offphase);
-      
-      for (i=0;i<10;i++) {
-	trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
-	trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
-      }
-      // project on fs/8 (Image of TX signal in +ve frequencies)
-      for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) {
-	meanI+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11;
-	meanQ+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11;
-	j+=2;
-      }
-      meanI/=RXDCLENGTH;
-      meanQ/=RXDCLENGTH;
-      
-      //    printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ);
-    }
-    
-    printf("[BRF] TX IQ offphase: %d => (%d,%d)\n",offphaseold,meanIold,meanQold);
-    
-    bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_PHASE,offphaseold);
-    
-    offgainold=4096;
-    bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_GAIN,offgainold);
-    for (i=0;i<10;i++) {
-      trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
-      trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
-    }
-    // project on fs/8 (Image of TX signal in +ve frequencies)
-    for (meanIold=meanQold=i=j=0;i<RXDCLENGTH;i++) {
-      meanIold+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11;
-      meanQold+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11;
-      j+=2;
-    }
-    
-    meanIold/=RXDCLENGTH;
-    meanQold/=RXDCLENGTH;
-    printf("[BRF] TX IQ (offgain): %d => (%d,%d)\n",offgainold,meanIold,meanQold);
-    
-    offgain=-4096;
-    bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_GAIN,offgain);
-    for (i=0;i<10;i++) {
-      trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
-      trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
-    }
-    // project on fs/8 (Image of TX signal in +ve frequencies)
-    for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) {
-      meanI+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11;
-      meanQ+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11;
-      j+=2;
+    // project on fs/4
+    for (meanIold=meanQold=i=j=0; i<RXDCLENGTH; i++) {
+        switch (i&3) {
+        case 0:
+            meanIold+=calib_buff[j++];
+            break;
+        case 1:
+            meanQold+=calib_buff[j++];
+            break;
+        case 2:
+            meanIold-=calib_buff[j++];
+            break;
+        case 3:
+            meanQold-=calib_buff[j++];
+            break;
+        }
     }
-    
-    meanI/=RXDCLENGTH;
-    meanQ/=RXDCLENGTH;
-    printf("[BRF] TX IQ (offgain): %d => (%d,%d)\n",offgain,meanI,meanQ);
-    
-    cnt=0;
-    while (cnt++ < 13) {
-      
-      offgainnew=(offgainold+offgain)>>1;
-      if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) {
-	printf("[BRF] TX IQ (offgain): ([%d,%d]) => %d : %d\n",offgainold,offgain,offgainnew,meanI*meanI+meanQ*meanQ);
-	
-	meanIold = meanI;
-	meanQold = meanQ;
-	offgainold = offgain;
-      }
-      offgain = offgainnew;
-      bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_GAIN,offgain);
-      
-      for (i=0;i<10;i++) {
-	trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
-	trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
-      }
-      // project on fs/8 (Image of TX signal in +ve frequencies)
-      for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) {
-	meanI+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11;
-	meanQ+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11;
-	j+=2;
-      }
-      meanI/=RXDCLENGTH;
-      meanQ/=RXDCLENGTH;
-      
-      //    printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ);
-    }
-    
-    printf("[BRF] TX IQ offgain: %d => (%d,%d)\n",offgainold,meanIold,meanQold);
-    
-    bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_GAIN,offgainold);
-  }
-
-  // RX IQ imbalance
-  for (loop=0;loop<2;loop++) {
-    offphaseold=4096;
-    bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_PHASE,offphaseold);
-    for (i=0;i<10;i++) {
-      trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
-      trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
-    }
-    // project on -3fs/8 (Image of TX signal in -ve frequencies)
-    for (meanIold=meanQold=i=j=0;i<RXDCLENGTH;i++) {
-      meanIold+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11;
-      meanQold+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11;
-      j+=2;
-    }
-    
-    meanIold/=RXDCLENGTH;
-    meanQold/=RXDCLENGTH;
-    printf("[BRF] RX IQ (offphase): %d => (%d,%d)\n",offphaseold,meanIold,meanQold);
-    
-    offphase=-4096;
-    bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_PHASE,offphase);
-    for (i=0;i<10;i++) {
-      trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
-      trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
+    //  meanIold/=RXDCLENGTH;
+    //  meanQold/=RXDCLENGTH;
+    printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQold,meanIold,meanQold);
+
+    offQ=-2048;
+    bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_Q,offQ);
+    for (i=0; i<10; i++) {
+        trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
+        trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
     }
-    // project on -3fs/8 (Image of TX signal in -ve frequencies)
-    for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) {
-      meanI+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11;
-      meanQ+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11;
-      j+=2;
+    for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) {
+        switch (i&3) {
+        case 0:
+            meanI+=calib_buff[j++];
+            break;
+        case 1:
+            meanQ+=calib_buff[j++];
+            break;
+        case 2:
+            meanI-=calib_buff[j++];
+            break;
+        case 3:
+            meanQ-=calib_buff[j++];
+            break;
+        }
     }
-    
-    meanI/=RXDCLENGTH;
-    meanQ/=RXDCLENGTH;
-    printf("[BRF] RX IQ (offphase): %d => (%d,%d)\n",offphase,meanI,meanQ);
-    
+    //  meanI/=RXDCLENGTH;
+    //  meanQ/=RXDCLENGTH;
+    printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ);
+
     cnt=0;
-    while (cnt++ < 13) {
-      
-      offphasenew=(offphaseold+offphase)>>1;
-      printf("[BRF] RX IQ (offphase): ([%d,%d]) => %d : %d\n",offphaseold,offphase,offphasenew,meanI*meanI+meanQ*meanQ);
-      if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) {
-
-	
-	meanIold = meanI;
-	meanQold = meanQ;
-	offphaseold = offphase;
-      }
-      offphase = offphasenew;
-      bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_PHASE,offphase);
-      
-      for (i=0;i<10;i++) {
-	trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
-	trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
-      }
-      // project on -3fs/8 (Image of TX signal in -ve frequencies)
-      for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) {
-	meanI+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11;
-	meanQ+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11;
-	j+=2;
-      }
-      meanI/=RXDCLENGTH;
-      meanQ/=RXDCLENGTH;
-      
-      //    printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ);
+    while (cnt++ < 12) {
+
+        offQnew=(offQold+offQ)>>1;
+        if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) {
+            printf("[BRF] TX DC (offQ): ([%d,%d]) => %d : %d\n",offQold,offQ,offQnew,meanI*meanI+meanQ*meanQ);
+
+            meanIold = meanI;
+            meanQold = meanQ;
+            offQold = offQ;
+        }
+        offQ = offQnew;
+        bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_Q,offQ);
+
+        for (i=0; i<10; i++) {
+            trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
+            trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
+        }
+        for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) {
+            switch (i&3) {
+            case 0:
+                meanI+=calib_buff[j++];
+                break;
+            case 1:
+                meanQ+=calib_buff[j++];
+                break;
+            case 2:
+                meanI-=calib_buff[j++];
+                break;
+            case 3:
+                meanQ-=calib_buff[j++];
+                break;
+            }
+        }
+        //    meanI/=RXDCLENGTH;
+        //   meanQ/=RXDCLENGTH;
+        //    printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ);
     }
-    
-    printf("[BRF] RX IQ offphase: %d => (%d,%d)\n",offphaseold,meanIold,meanQold);
-    
-    bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_PHASE,offphaseold);
-    
-    offgainold=4096;
-    bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_GAIN,offgainold);
-    for (i=0;i<10;i++) {
-      trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
-      trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0,0);
-    }
-    // project on -3fs/8 (Image of TX signal in +ve frequencies)
-    for (meanIold=meanQold=i=j=0;i<RXDCLENGTH;i++) {
-      meanIold+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11;
-      meanQold+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11;
-      j+=2;
-    }
-    
-    meanIold/=RXDCLENGTH;
-    meanQold/=RXDCLENGTH;
-    printf("[BRF] RX IQ (offgain): %d => (%d,%d)\n",offgainold,meanIold,meanQold);
-    
-    offgain=-4096;
-    bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_GAIN,offgain);
-    for (i=0;i<10;i++) {
-      trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
-      trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
-    }
-    // project on 3fs/8 (Image of TX signal in -ve frequencies)
-    for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) {
-      meanI+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11;
-      meanQ+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11;
-      j+=2;
+
+    printf("[BRF] TX DC: (%d,%d) => (%d,%d)\n",offIold,offQold,meanIold,meanQold);
+
+    bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_Q,offQold);
+
+    // TX IQ imbalance
+    for (loop=0; loop<2; loop++) {
+        offphaseold=4096;
+        bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_PHASE,offphaseold);
+        for (i=0; i<10; i++) {
+            trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
+            trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
+        }
+        // project on fs/8 (Image of TX signal in +ve frequencies)
+        for (meanIold=meanQold=i=j=0; i<RXDCLENGTH; i++) {
+            meanIold+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11;
+            meanQold+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11;
+            j+=2;
+        }
+
+        meanIold/=RXDCLENGTH;
+        meanQold/=RXDCLENGTH;
+        printf("[BRF] TX IQ (offphase): %d => (%d,%d)\n",offphaseold,meanIold,meanQold);
+
+        offphase=-4096;
+        bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_PHASE,offphase);
+        for (i=0; i<10; i++) {
+            trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
+            trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
+        }
+        // project on fs/8 (Image of TX signal in +ve frequencies)
+        for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) {
+            meanI+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11;
+            meanQ+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11;
+            j+=2;
+        }
+
+        meanI/=RXDCLENGTH;
+        meanQ/=RXDCLENGTH;
+        printf("[BRF] TX IQ (offphase): %d => (%d,%d)\n",offphase,meanI,meanQ);
+
+        cnt=0;
+        while (cnt++ < 13) {
+
+            offphasenew=(offphaseold+offphase)>>1;
+            printf("[BRF] TX IQ (offphase): ([%d,%d]) => %d : %d\n",offphaseold,offphase,offphasenew,meanI*meanI+meanQ*meanQ);
+            if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) {
+
+
+                meanIold = meanI;
+                meanQold = meanQ;
+                offphaseold = offphase;
+            }
+            offphase = offphasenew;
+            bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_PHASE,offphase);
+
+            for (i=0; i<10; i++) {
+                trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
+                trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
+            }
+            // project on fs/8 (Image of TX signal in +ve frequencies)
+            for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) {
+                meanI+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11;
+                meanQ+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11;
+                j+=2;
+            }
+            meanI/=RXDCLENGTH;
+            meanQ/=RXDCLENGTH;
+
+            //    printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ);
+        }
+
+        printf("[BRF] TX IQ offphase: %d => (%d,%d)\n",offphaseold,meanIold,meanQold);
+
+        bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_PHASE,offphaseold);
+
+        offgainold=4096;
+        bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_GAIN,offgainold);
+        for (i=0; i<10; i++) {
+            trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
+            trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
+        }
+        // project on fs/8 (Image of TX signal in +ve frequencies)
+        for (meanIold=meanQold=i=j=0; i<RXDCLENGTH; i++) {
+            meanIold+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11;
+            meanQold+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11;
+            j+=2;
+        }
+
+        meanIold/=RXDCLENGTH;
+        meanQold/=RXDCLENGTH;
+        printf("[BRF] TX IQ (offgain): %d => (%d,%d)\n",offgainold,meanIold,meanQold);
+
+        offgain=-4096;
+        bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_GAIN,offgain);
+        for (i=0; i<10; i++) {
+            trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
+            trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
+        }
+        // project on fs/8 (Image of TX signal in +ve frequencies)
+        for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) {
+            meanI+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11;
+            meanQ+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11;
+            j+=2;
+        }
+
+        meanI/=RXDCLENGTH;
+        meanQ/=RXDCLENGTH;
+        printf("[BRF] TX IQ (offgain): %d => (%d,%d)\n",offgain,meanI,meanQ);
+
+        cnt=0;
+        while (cnt++ < 13) {
+
+            offgainnew=(offgainold+offgain)>>1;
+            if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) {
+                printf("[BRF] TX IQ (offgain): ([%d,%d]) => %d : %d\n",offgainold,offgain,offgainnew,meanI*meanI+meanQ*meanQ);
+
+                meanIold = meanI;
+                meanQold = meanQ;
+                offgainold = offgain;
+            }
+            offgain = offgainnew;
+            bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_GAIN,offgain);
+
+            for (i=0; i<10; i++) {
+                trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
+                trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
+            }
+            // project on fs/8 (Image of TX signal in +ve frequencies)
+            for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) {
+                meanI+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11;
+                meanQ+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11;
+                j+=2;
+            }
+            meanI/=RXDCLENGTH;
+            meanQ/=RXDCLENGTH;
+
+            //    printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ);
+        }
+
+        printf("[BRF] TX IQ offgain: %d => (%d,%d)\n",offgainold,meanIold,meanQold);
+
+        bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_GAIN,offgainold);
     }
-    
-    meanI/=RXDCLENGTH;
-    meanQ/=RXDCLENGTH;
-    printf("[BRF] RX IQ (offgain): %d => (%d,%d)\n",offgain,meanI,meanQ);
-    
-    cnt=0;
-    while (cnt++ < 13) {
-      
-      offgainnew=(offgainold+offgain)>>1;
-      if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) {
-	printf("[BRF] RX IQ (offgain): ([%d,%d]) => %d : %d\n",offgainold,offgain,offgainnew,meanI*meanI+meanQ*meanQ);
-	
-	meanIold = meanI;
-	meanQold = meanQ;
-	offgainold = offgain;
-      }
-      offgain = offgainnew;
-      bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_GAIN,offgain);
-      
-      for (i=0;i<10;i++) {
-	trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
-	trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
-      }
-      // project on -3fs/8 (Image of TX signal in -ve frequencies)
-      for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) {
-	meanI+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11;
-	meanQ+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11;
-	j+=2;
-      }
-      meanI/=RXDCLENGTH;
-      meanQ/=RXDCLENGTH;
-      
-      //    printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ);
+
+    // RX IQ imbalance
+    for (loop=0; loop<2; loop++) {
+        offphaseold=4096;
+        bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_PHASE,offphaseold);
+        for (i=0; i<10; i++) {
+            trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
+            trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
+        }
+        // project on -3fs/8 (Image of TX signal in -ve frequencies)
+        for (meanIold=meanQold=i=j=0; i<RXDCLENGTH; i++) {
+            meanIold+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11;
+            meanQold+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11;
+            j+=2;
+        }
+
+        meanIold/=RXDCLENGTH;
+        meanQold/=RXDCLENGTH;
+        printf("[BRF] RX IQ (offphase): %d => (%d,%d)\n",offphaseold,meanIold,meanQold);
+
+        offphase=-4096;
+        bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_PHASE,offphase);
+        for (i=0; i<10; i++) {
+            trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
+            trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
+        }
+        // project on -3fs/8 (Image of TX signal in -ve frequencies)
+        for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) {
+            meanI+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11;
+            meanQ+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11;
+            j+=2;
+        }
+
+        meanI/=RXDCLENGTH;
+        meanQ/=RXDCLENGTH;
+        printf("[BRF] RX IQ (offphase): %d => (%d,%d)\n",offphase,meanI,meanQ);
+
+        cnt=0;
+        while (cnt++ < 13) {
+
+            offphasenew=(offphaseold+offphase)>>1;
+            printf("[BRF] RX IQ (offphase): ([%d,%d]) => %d : %d\n",offphaseold,offphase,offphasenew,meanI*meanI+meanQ*meanQ);
+            if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) {
+
+
+                meanIold = meanI;
+                meanQold = meanQ;
+                offphaseold = offphase;
+            }
+            offphase = offphasenew;
+            bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_PHASE,offphase);
+
+            for (i=0; i<10; i++) {
+                trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
+                trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
+            }
+            // project on -3fs/8 (Image of TX signal in -ve frequencies)
+            for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) {
+                meanI+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11;
+                meanQ+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11;
+                j+=2;
+            }
+            meanI/=RXDCLENGTH;
+            meanQ/=RXDCLENGTH;
+
+            //    printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ);
+        }
+
+        printf("[BRF] RX IQ offphase: %d => (%d,%d)\n",offphaseold,meanIold,meanQold);
+
+        bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_PHASE,offphaseold);
+
+        offgainold=4096;
+        bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_GAIN,offgainold);
+        for (i=0; i<10; i++) {
+            trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
+            trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0,0);
+        }
+        // project on -3fs/8 (Image of TX signal in +ve frequencies)
+        for (meanIold=meanQold=i=j=0; i<RXDCLENGTH; i++) {
+            meanIold+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11;
+            meanQold+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11;
+            j+=2;
+        }
+
+        meanIold/=RXDCLENGTH;
+        meanQold/=RXDCLENGTH;
+        printf("[BRF] RX IQ (offgain): %d => (%d,%d)\n",offgainold,meanIold,meanQold);
+
+        offgain=-4096;
+        bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_GAIN,offgain);
+        for (i=0; i<10; i++) {
+            trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
+            trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
+        }
+        // project on 3fs/8 (Image of TX signal in -ve frequencies)
+        for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) {
+            meanI+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11;
+            meanQ+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11;
+            j+=2;
+        }
+
+        meanI/=RXDCLENGTH;
+        meanQ/=RXDCLENGTH;
+        printf("[BRF] RX IQ (offgain): %d => (%d,%d)\n",offgain,meanI,meanQ);
+
+        cnt=0;
+        while (cnt++ < 13) {
+
+            offgainnew=(offgainold+offgain)>>1;
+            if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) {
+                printf("[BRF] RX IQ (offgain): ([%d,%d]) => %d : %d\n",offgainold,offgain,offgainnew,meanI*meanI+meanQ*meanQ);
+
+                meanIold = meanI;
+                meanQold = meanQ;
+                offgainold = offgain;
+            }
+            offgain = offgainnew;
+            bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_GAIN,offgain);
+
+            for (i=0; i<10; i++) {
+                trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0);
+                trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0);
+            }
+            // project on -3fs/8 (Image of TX signal in -ve frequencies)
+            for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) {
+                meanI+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11;
+                meanQ+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11;
+                j+=2;
+            }
+            meanI/=RXDCLENGTH;
+            meanQ/=RXDCLENGTH;
+
+            //    printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ);
+        }
+
+        printf("[BRF] RX IQ offgain: %d => (%d,%d)\n",offgainold,meanIold,meanQold);
+
+        bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_GAIN,offgainold);
     }
-    
-    printf("[BRF] RX IQ offgain: %d => (%d,%d)\n",offgainold,meanIold,meanQold);
-    
-    bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_GAIN,offgainold);
-  }
-
-  bladerf_set_frequency(brf->dev,BLADERF_MODULE_TX, (unsigned int) device->openair0_cfg->tx_freq[0]);  
-  bladerf_set_loopback(brf->dev,BLADERF_LB_NONE);
-  bladerf_set_gain(brf->dev, BLADERF_MODULE_RX, (unsigned int) device->openair0_cfg->rx_gain[0]-device->openair0_cfg[0].rx_gain_offset[0]);
-  bladerf_set_gain(brf->dev, BLADERF_MODULE_TX, (unsigned int) device->openair0_cfg->tx_gain[0]);
-  //  LOG_M("blade_rf_test.m","rxs",calib_buff,RXDCLENGTH,1,1);
+
+    bladerf_set_frequency(brf->dev,BLADERF_MODULE_TX, (unsigned int) device->openair0_cfg->tx_freq[0]);
+    bladerf_set_loopback(brf->dev,BLADERF_LB_NONE);
+    bladerf_set_gain(brf->dev, BLADERF_MODULE_RX, (unsigned int) device->openair0_cfg->rx_gain[0]-device->openair0_cfg[0].rx_gain_offset[0]);
+    bladerf_set_gain(brf->dev, BLADERF_MODULE_TX, (unsigned int) device->openair0_cfg->tx_gain[0]);
+    //  LOG_M("blade_rf_test.m","rxs",calib_buff,RXDCLENGTH,1,1);
 }
 
-/*! \brief Initialize Openair BLADERF target. It returns 0 if OK 
+/*! \brief Initialize Openair BLADERF target. It returns 0 if OK
  * \param device the hardware to use
  * \param openair0_cfg RF frontend parameters set by application
  * \returns 0 on success
  */
 int device_init(openair0_device *device, openair0_config_t *openair0_cfg) {
-  int status;
-  brf_state_t *brf = (brf_state_t*)malloc(sizeof(brf_state_t));
-  memset(brf, 0, sizeof(brf_state_t));
-  /* device specific */
-  //openair0_cfg->txlaunch_wait = 1;//manage when TX processing is triggered
-  //openair0_cfg->txlaunch_wait_slotcount = 1; //manage when TX processing is triggered
-  openair0_cfg->iq_txshift = 0;// shift
-  openair0_cfg->iq_rxrescale = 15;//rescale iqs
-  
-  // init required params
-  switch ((int)openair0_cfg->sample_rate) {
-  case 30720000:
-    openair0_cfg->samples_per_packet    = 2048;
-    openair0_cfg->tx_sample_advance     = 0;
-    break;
-  case 15360000:
-    openair0_cfg->samples_per_packet    = 2048;
-    openair0_cfg->tx_sample_advance     = 0;
-    break;
-  case 7680000:
-    openair0_cfg->samples_per_packet    = 1024;
-    openair0_cfg->tx_sample_advance     = 0;
-    break;
-  case 1920000:
-    openair0_cfg->samples_per_packet    = 256;
-    openair0_cfg->tx_sample_advance     = 50;
-    break;
-  default:
-    printf("Error: unknown sampling rate %f\n",openair0_cfg->sample_rate);
-    exit(-1);
-    break;
-  }
-  openair0_cfg->iq_txshift= 0;
-  openair0_cfg->iq_rxrescale = 15; /*not sure*/
-  openair0_cfg->rx_gain_calib_table = calib_table_fx4;
-
-  //  The number of buffers to use in the underlying data stream
-  brf->num_buffers   = 128;
-  // the size of the underlying stream buffers, in samples
-  brf->buffer_size   = (unsigned int) openair0_cfg->samples_per_packet;//*sizeof(int32_t); // buffer size = 4096 for sample_len of 1024
-  brf->num_transfers = 16;
-  brf->rx_timeout_ms = 0;  
-  brf->tx_timeout_ms = 0;
-  brf->sample_rate=(unsigned int)openair0_cfg->sample_rate;
-
-  memset(&brf->meta_rx, 0, sizeof(brf->meta_rx));
-  memset(&brf->meta_tx, 0, sizeof(brf->meta_tx));
-
-  printf("\n[BRF] sampling_rate %d, num_buffers %d,  buffer_size %d, num transfer %d, timeout_ms (rx %d, tx %d)\n", 
-	 brf->sample_rate, brf->num_buffers, brf->buffer_size,brf->num_transfers, brf->rx_timeout_ms, brf->tx_timeout_ms);
-  
-  if ((status=bladerf_open(&brf->dev, "")) != 0 ) {
-    fprintf(stderr,"Failed to open brf device: %s\n",bladerf_strerror(status));
-    brf_error(status);
-  }
-  printf("[BRF] init dev %p\n", brf->dev);
-  switch(bladerf_device_speed(brf->dev)){
-  case BLADERF_DEVICE_SPEED_SUPER:
-    printf("[BRF] Device operates at max speed\n");
-    break;
-  default:
-    printf("[BRF] Device does not operates at max speed, change the USB port\n");
-    brf_error(BLADERF_ERR_UNSUPPORTED);
-  }
-  // RX  
-  // Example of CLI output: RX Frequency: 2539999999Hz
-  
-  if ((status=bladerf_set_frequency(brf->dev, BLADERF_MODULE_RX, (unsigned int) openair0_cfg->rx_freq[0])) != 0){
-    fprintf(stderr,"Failed to set RX frequency: %s\n",bladerf_strerror(status));
-    brf_error(status);
-  } else 
-    printf("[BRF] set RX frequency to %u\n",(unsigned int)openair0_cfg->rx_freq[0]);
-  
-
-
-  unsigned int actual_value=0;
-  if ((status=bladerf_set_sample_rate(brf->dev, BLADERF_MODULE_RX, (unsigned int) openair0_cfg->sample_rate, &actual_value)) != 0){
-    fprintf(stderr,"Failed to set RX sample rate: %s\n", bladerf_strerror(status));
-    brf_error(status);
-  }else  
-    printf("[BRF] set RX sample rate to %u, %u\n", (unsigned int) openair0_cfg->sample_rate, actual_value);
- 
-
-  if ((status=bladerf_set_bandwidth(brf->dev, BLADERF_MODULE_RX, (unsigned int) openair0_cfg->rx_bw*2, &actual_value)) != 0){
-    fprintf(stderr,"Failed to set RX bandwidth: %s\n", bladerf_strerror(status));
-    brf_error(status);
-  }else 
-    printf("[BRF] set RX bandwidth to %u, %u\n",(unsigned int)openair0_cfg->rx_bw*2, actual_value);
- 
-  set_rx_gain_offset(&openair0_cfg[0],0);
-  if ((status=bladerf_set_gain(brf->dev, BLADERF_MODULE_RX, (int) openair0_cfg->rx_gain[0]-openair0_cfg[0].rx_gain_offset[0])) != 0) {
-    fprintf(stderr,"Failed to set RX gain: %s\n",bladerf_strerror(status));
-    brf_error(status);
-  } else 
-    printf("[BRF] set RX gain to %d (%d)\n",(int)(openair0_cfg->rx_gain[0]-openair0_cfg[0].rx_gain_offset[0]),(int)openair0_cfg[0].rx_gain_offset[0]);
-
-  // TX
-  
-  if ((status=bladerf_set_frequency(brf->dev, BLADERF_MODULE_TX, (unsigned int) openair0_cfg->tx_freq[0])) != 0){
-    fprintf(stderr,"Failed to set TX frequency: %s\n",bladerf_strerror(status));
-    brf_error(status);
-  }else 
-    printf("[BRF] set TX Frequency to %u\n", (unsigned int) openair0_cfg->tx_freq[0]);
-
-  if ((status=bladerf_set_sample_rate(brf->dev, BLADERF_MODULE_TX, (unsigned int) openair0_cfg->sample_rate, NULL)) != 0){
-    fprintf(stderr,"Failed to set TX sample rate: %s\n", bladerf_strerror(status));
-    brf_error(status);
-  }else 
-    printf("[BRF] set TX sampling rate to %u \n", (unsigned int) openair0_cfg->sample_rate);
-
-  if ((status=bladerf_set_bandwidth(brf->dev, BLADERF_MODULE_TX,(unsigned int)openair0_cfg->tx_bw*2, NULL)) != 0){
-    fprintf(stderr, "Failed to set TX bandwidth: %s\n", bladerf_strerror(status));
-    brf_error(status);
-  }else 
-    printf("[BRF] set TX bandwidth to %u \n", (unsigned int) openair0_cfg->tx_bw*2);
-
-  if ((status=bladerf_set_gain(brf->dev, BLADERF_MODULE_TX, (int) openair0_cfg->tx_gain[0])) != 0) {
-    fprintf(stderr,"Failed to set TX gain: %s\n",bladerf_strerror(status));
-    brf_error(status);
-  }else 
-    printf("[BRF] set the TX gain to %d\n", (int)openair0_cfg->tx_gain[0]);
-  
-
- /* Configure the device's TX module for use with the sync interface.
-   * SC16 Q11 samples *with* metadata are used. */
-  if ((status=bladerf_sync_config(brf->dev, BLADERF_MODULE_TX,BLADERF_FORMAT_SC16_Q11_META,brf->num_buffers,brf->buffer_size,brf->num_transfers,brf->tx_timeout_ms)) != 0 ) {
-    fprintf(stderr,"Failed to configure TX sync interface: %s\n", bladerf_strerror(status));
-     brf_error(status);
-  }else 
-    printf("[BRF] configured TX  sync interface \n");
-
-/* Configure the device's RX module for use with the sync interface.
-   * SC16 Q11 samples *with* metadata are used. */
-  if ((status=bladerf_sync_config(brf->dev, BLADERF_MODULE_RX, BLADERF_FORMAT_SC16_Q11_META,brf->num_buffers,brf->buffer_size,brf->num_transfers,brf->rx_timeout_ms)) != 0 ) {
-    fprintf(stderr,"Failed to configure RX sync interface: %s\n", bladerf_strerror(status));
-    brf_error(status);
-  }else 
-    printf("[BRF] configured Rx sync interface \n");
-
-
-   /* We must always enable the TX module after calling bladerf_sync_config(), and 
-    * before  attempting to TX samples via  bladerf_sync_tx(). */
-  if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_TX, true)) != 0) {
-    fprintf(stderr,"Failed to enable TX module: %s\n", bladerf_strerror(status));
-    brf_error(status);
-  } else 
-    printf("[BRF] TX module enabled \n");
- 
- /* We must always enable the RX module after calling bladerf_sync_config(), and 
-    * before  attempting to RX samples via  bladerf_sync_rx(). */
-  if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_RX, true)) != 0) {
-    fprintf(stderr,"Failed to enable RX module: %s\n", bladerf_strerror(status));
-    brf_error(status);
-  }else 
-    printf("[BRF] RX module enabled \n");
-
-  // calibrate 
-    
- if ((status=bladerf_calibrate_dc(brf->dev, BLADERF_MODULE_TX)) != 0) {
-    fprintf(stderr,"Failed to calibrate TX DC: %s\n", bladerf_strerror(status));
-    brf_error(status);
-  } else 
-    printf("[BRF] TX module calibrated DC \n");
- 
-  if ((status=bladerf_calibrate_dc(brf->dev, BLADERF_MODULE_RX)) != 0) {
-    fprintf(stderr,"Failed to calibrate RX DC: %s\n", bladerf_strerror(status));
-    brf_error(status);
-  }else 
-    printf("[BRF] RX module calibrated DC \n");
-  
-  bladerf_log_set_verbosity(get_brf_log_level(openair0_cfg->log_level));
-  
-  printf("BLADERF: Initializing openair0_device\n");
-  device->Mod_id         = num_devices++;
-  device->type             = BLADERF_DEV; 
-  device->trx_start_func = trx_brf_start;
-  device->trx_end_func   = trx_brf_end;
-  device->trx_read_func  = trx_brf_read;
-  device->trx_write_func = trx_brf_write;
-  device->trx_get_stats_func   = trx_brf_get_stats;
-  device->trx_reset_stats_func = trx_brf_reset_stats;
-  device->trx_stop_func        = trx_brf_stop;
-  device->trx_set_freq_func    = trx_brf_set_freq;
-  device->trx_set_gains_func   = trx_brf_set_gains;
-  device->openair0_cfg = openair0_cfg;
-  device->priv = (void *)brf;
-
-  calibrate_rf(device);
-
-  //  memcpy((void*)&device->openair0_cfg,(void*)&openair0_cfg[0],sizeof(openair0_config_t));
-
-  if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_TX, false)) != 0) {
-    fprintf(stderr,"Failed to enable TX module: %s\n", bladerf_strerror(status));
-    abort();
-  }
-  if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_RX, false)) != 0) {
-    fprintf(stderr,"Failed to enable RX module: %s\n", bladerf_strerror(status));
-    abort();
-  }
-
-  return 0;
+    int status;
+    brf_state_t *brf = (brf_state_t*)malloc(sizeof(brf_state_t));
+    memset(brf, 0, sizeof(brf_state_t));
+    /* device specific */
+    //openair0_cfg->txlaunch_wait = 1;//manage when TX processing is triggered
+    //openair0_cfg->txlaunch_wait_slotcount = 1; //manage when TX processing is triggered
+    openair0_cfg->iq_txshift = 0;// shift
+    openair0_cfg->iq_rxrescale = 15;//rescale iqs
+
+    // init required params
+    switch ((int)openair0_cfg->sample_rate) {
+    case 30720000:
+        openair0_cfg->samples_per_packet    = 2048;
+        openair0_cfg->tx_sample_advance     = 0;
+        break;
+    case 15360000:
+        openair0_cfg->samples_per_packet    = 2048;
+        openair0_cfg->tx_sample_advance     = 0;
+        break;
+    case 7680000:
+        openair0_cfg->samples_per_packet    = 1024;
+        openair0_cfg->tx_sample_advance     = 0;
+        break;
+    case 1920000:
+        openair0_cfg->samples_per_packet    = 256;
+        openair0_cfg->tx_sample_advance     = 50;
+        break;
+    default:
+        printf("Error: unknown sampling rate %f\n",openair0_cfg->sample_rate);
+        exit(-1);
+        break;
+    }
+    openair0_cfg->iq_txshift= 0;
+    openair0_cfg->iq_rxrescale = 15; /*not sure*/
+    openair0_cfg->rx_gain_calib_table = calib_table_fx4;
+
+    //  The number of buffers to use in the underlying data stream
+    brf->num_buffers   = 128;
+    // the size of the underlying stream buffers, in samples
+    brf->buffer_size   = (unsigned int) openair0_cfg->samples_per_packet;//*sizeof(int32_t); // buffer size = 4096 for sample_len of 1024
+    brf->num_transfers = 16;
+    brf->rx_timeout_ms = 0;
+    brf->tx_timeout_ms = 0;
+    brf->sample_rate=(unsigned int)openair0_cfg->sample_rate;
+
+    memset(&brf->meta_rx, 0, sizeof(brf->meta_rx));
+    memset(&brf->meta_tx, 0, sizeof(brf->meta_tx));
+
+    printf("\n[BRF] sampling_rate %u, num_buffers %u,  buffer_size %u, num transfer %u, timeout_ms (rx %u, tx %u)\n",
+           brf->sample_rate, brf->num_buffers, brf->buffer_size,brf->num_transfers, brf->rx_timeout_ms, brf->tx_timeout_ms);
+
+    if ((status=bladerf_open(&brf->dev, "")) != 0 ) {
+        fprintf(stderr,"Failed to open brf device: %s\n",bladerf_strerror(status));
+        brf_error(status);
+    }
+    printf("[BRF] init dev %p\n", brf->dev);
+    switch(bladerf_device_speed(brf->dev)) {
+    case BLADERF_DEVICE_SPEED_SUPER:
+        printf("[BRF] Device operates at max speed\n");
+        break;
+    default:
+        printf("[BRF] Device does not operates at max speed, change the USB port\n");
+        brf_error(BLADERF_ERR_UNSUPPORTED);
+    }
+    // RX
+    // Example of CLI output: RX Frequency: 2539999999Hz
+
+
+    if ((status=bladerf_set_gain_mode(brf->dev, BLADERF_MODULE_RX, BLADERF_GAIN_MGC))) {
+        fprintf(stderr, "[BRF] Failed to disable AGC\n");
+        brf_error(status);
+    }
+
+    if ((status=bladerf_set_frequency(brf->dev, BLADERF_MODULE_RX, (unsigned int) openair0_cfg->rx_freq[0])) != 0) {
+        fprintf(stderr,"Failed to set RX frequency: %s\n",bladerf_strerror(status));
+        brf_error(status);
+    } else
+        printf("[BRF] set RX frequency to %u\n",(unsigned int)openair0_cfg->rx_freq[0]);
+
+
+
+    unsigned int actual_value=0;
+    if ((status=bladerf_set_sample_rate(brf->dev, BLADERF_MODULE_RX, (unsigned int) openair0_cfg->sample_rate, &actual_value)) != 0) {
+        fprintf(stderr,"Failed to set RX sample rate: %s\n", bladerf_strerror(status));
+        brf_error(status);
+    } else
+        printf("[BRF] set RX sample rate to %u, %u\n", (unsigned int) openair0_cfg->sample_rate, actual_value);
+
+
+    if ((status=bladerf_set_bandwidth(brf->dev, BLADERF_MODULE_RX, (unsigned int) openair0_cfg->rx_bw*2, &actual_value)) != 0) {
+        fprintf(stderr,"Failed to set RX bandwidth: %s\n", bladerf_strerror(status));
+        brf_error(status);
+    } else
+        printf("[BRF] set RX bandwidth to %u, %u\n",(unsigned int)openair0_cfg->rx_bw*2, actual_value);
+
+    set_rx_gain_offset(&openair0_cfg[0],0);
+    if ((status=bladerf_set_gain(brf->dev, BLADERF_MODULE_RX, (int) openair0_cfg->rx_gain[0]-openair0_cfg[0].rx_gain_offset[0])) != 0) {
+        fprintf(stderr,"Failed to set RX gain: %s\n",bladerf_strerror(status));
+        brf_error(status);
+    } else
+        printf("[BRF] set RX gain to %d (%d)\n",(int)(openair0_cfg->rx_gain[0]-openair0_cfg[0].rx_gain_offset[0]),(int)openair0_cfg[0].rx_gain_offset[0]);
+
+    // TX
+
+    if ((status=bladerf_set_frequency(brf->dev, BLADERF_MODULE_TX, (unsigned int) openair0_cfg->tx_freq[0])) != 0) {
+        fprintf(stderr,"Failed to set TX frequency: %s\n",bladerf_strerror(status));
+        brf_error(status);
+    } else
+        printf("[BRF] set TX Frequency to %u\n", (unsigned int) openair0_cfg->tx_freq[0]);
+
+    if ((status=bladerf_set_sample_rate(brf->dev, BLADERF_MODULE_TX, (unsigned int) openair0_cfg->sample_rate, NULL)) != 0) {
+        fprintf(stderr,"Failed to set TX sample rate: %s\n", bladerf_strerror(status));
+        brf_error(status);
+    } else
+        printf("[BRF] set TX sampling rate to %u \n", (unsigned int) openair0_cfg->sample_rate);
+
+    if ((status=bladerf_set_bandwidth(brf->dev, BLADERF_MODULE_TX,(unsigned int)openair0_cfg->tx_bw*2, NULL)) != 0) {
+        fprintf(stderr, "Failed to set TX bandwidth: %s\n", bladerf_strerror(status));
+        brf_error(status);
+    } else
+        printf("[BRF] set TX bandwidth to %u \n", (unsigned int) openair0_cfg->tx_bw*2);
+
+    if ((status=bladerf_set_gain(brf->dev, BLADERF_MODULE_TX, (int) openair0_cfg->tx_gain[0])) != 0) {
+        fprintf(stderr,"Failed to set TX gain: %s\n",bladerf_strerror(status));
+        brf_error(status);
+    } else
+        printf("[BRF] set the TX gain to %d\n", (int)openair0_cfg->tx_gain[0]);
+
+
+    /* Configure the device's TX module for use with the sync interface.
+      * SC16 Q11 samples *with* metadata are used. */
+    if ((status=bladerf_sync_config(brf->dev, BLADERF_MODULE_TX,BLADERF_FORMAT_SC16_Q11_META,brf->num_buffers,brf->buffer_size,brf->num_transfers,brf->tx_timeout_ms)) != 0 ) {
+        fprintf(stderr,"Failed to configure TX sync interface: %s\n", bladerf_strerror(status));
+        brf_error(status);
+    } else
+        printf("[BRF] configured TX  sync interface \n");
+
+    /* Configure the device's RX module for use with the sync interface.
+       * SC16 Q11 samples *with* metadata are used. */
+    if ((status=bladerf_sync_config(brf->dev, BLADERF_MODULE_RX, BLADERF_FORMAT_SC16_Q11_META,brf->num_buffers,brf->buffer_size,brf->num_transfers,brf->rx_timeout_ms)) != 0 ) {
+        fprintf(stderr,"Failed to configure RX sync interface: %s\n", bladerf_strerror(status));
+        brf_error(status);
+    } else
+        printf("[BRF] configured Rx sync interface \n");
+
+
+    /* We must always enable the TX module after calling bladerf_sync_config(), and
+     * before  attempting to TX samples via  bladerf_sync_tx(). */
+    if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_TX, true)) != 0) {
+        fprintf(stderr,"Failed to enable TX module: %s\n", bladerf_strerror(status));
+        brf_error(status);
+    } else
+        printf("[BRF] TX module enabled \n");
+
+    /* We must always enable the RX module after calling bladerf_sync_config(), and
+       * before  attempting to RX samples via  bladerf_sync_rx(). */
+    if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_RX, true)) != 0) {
+        fprintf(stderr,"Failed to enable RX module: %s\n", bladerf_strerror(status));
+        brf_error(status);
+    } else
+        printf("[BRF] RX module enabled \n");
+
+    // calibrate
+
+    if ((status=bladerf_calibrate_dc(brf->dev, BLADERF_DC_CAL_LPF_TUNING)) != 0 ||
+            (status=bladerf_calibrate_dc(brf->dev, BLADERF_DC_CAL_TX_LPF)) != 0 ||
+            (status=bladerf_calibrate_dc(brf->dev, BLADERF_DC_CAL_RX_LPF)) != 0 ||
+            (status=bladerf_calibrate_dc(brf->dev, BLADERF_DC_CAL_RXVGA2)) != 0) {
+        fprintf(stderr, "[BRF] error calibrating\n");
+        brf_error(status);
+    } else
+        printf("[BRF] calibration OK\n");
+
+    bladerf_log_set_verbosity(get_brf_log_level(openair0_cfg->log_level));
+
+    printf("BLADERF: Initializing openair0_device\n");
+    device->Mod_id         = num_devices++;
+    device->type             = BLADERF_DEV;
+    device->trx_start_func = trx_brf_start;
+    device->trx_end_func   = trx_brf_end;
+    device->trx_read_func  = trx_brf_read;
+    device->trx_write_func = trx_brf_write;
+    device->trx_get_stats_func   = trx_brf_get_stats;
+    device->trx_reset_stats_func = trx_brf_reset_stats;
+    device->trx_stop_func        = trx_brf_stop;
+    device->trx_set_freq_func    = trx_brf_set_freq;
+    device->trx_set_gains_func   = trx_brf_set_gains;
+    device->openair0_cfg = openair0_cfg;
+    device->priv = (void *)brf;
+
+    calibrate_rf(device);
+
+    //  memcpy((void*)&device->openair0_cfg,(void*)&openair0_cfg[0],sizeof(openair0_config_t));
+
+    if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_TX, false)) != 0) {
+        fprintf(stderr,"Failed to enable TX module: %s\n", bladerf_strerror(status));
+        abort();
+    }
+    if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_RX, false)) != 0) {
+        fprintf(stderr,"Failed to enable RX module: %s\n", bladerf_strerror(status));
+        abort();
+    }
+
+    return 0;
 }
 
-/*! \brief bladeRF error report 
- * \param status 
+/*! \brief bladeRF error report
+ * \param status
  * \returns 0 on success
  */
 int brf_error(int status) {
-  
-  //exit(-1);
-  return status; // or status error code
+    fprintf(stderr, "[BRF] brf_error: %s\n", bladerf_strerror(status));
+    exit(-1);
+    return status; // or status error code
 }
 
 
@@ -1158,61 +1154,61 @@ int brf_error(int status) {
  */
 struct bladerf * open_bladerf_from_serial(const char *serial) {
 
-  int status;
-  struct bladerf *dev;
-  struct bladerf_devinfo info;
-  /* Initialize all fields to "don't care" wildcard values.
-   *
-   * Immediately passing this to bladerf_open_with_devinfo() would cause
-   * libbladeRF to open any device on any available backend. */
-  bladerf_init_devinfo(&info);
-  /* Specify the desired device's serial number, while leaving all other
-   * fields in the info structure wildcard values */
-  strncpy(info.serial, serial, BLADERF_SERIAL_LENGTH - 1);
-  info.serial[BLADERF_SERIAL_LENGTH - 1] = '\0';
-  status = bladerf_open_with_devinfo(&dev, &info);
-  
-  if (status == BLADERF_ERR_NODEV) {
-    printf("No devices available with serial=%s\n", serial);
-    return NULL;
-  } else if (status != 0) {
-    fprintf(stderr, "Failed to open device with serial=%s (%s)\n", serial, bladerf_strerror(status));
-    return NULL;
-  } else {
-    return dev;
-  }
+    int status;
+    struct bladerf *dev;
+    struct bladerf_devinfo info;
+    /* Initialize all fields to "don't care" wildcard values.
+     *
+     * Immediately passing this to bladerf_open_with_devinfo() would cause
+     * libbladeRF to open any device on any available backend. */
+    bladerf_init_devinfo(&info);
+    /* Specify the desired device's serial number, while leaving all other
+     * fields in the info structure wildcard values */
+    strncpy(info.serial, serial, BLADERF_SERIAL_LENGTH - 1);
+    info.serial[BLADERF_SERIAL_LENGTH - 1] = '\0';
+    status = bladerf_open_with_devinfo(&dev, &info);
+
+    if (status == BLADERF_ERR_NODEV) {
+        printf("No devices available with serial=%s\n", serial);
+        return NULL;
+    } else if (status != 0) {
+        fprintf(stderr, "Failed to open device with serial=%s (%s)\n", serial, bladerf_strerror(status));
+        return NULL;
+    } else {
+        return dev;
+    }
 }
 
 /*! \brief Get BladeRF log level
  * \param log_level log level
  * \returns log level of BLADERF device
  */
-int get_brf_log_level(int log_level){
-
-  int level=BLADERF_LOG_LEVEL_INFO;
-  return  BLADERF_LOG_LEVEL_DEBUG; // BLADERF_LOG_LEVEL_VERBOSE;// BLADERF_LOG_LEVEL_DEBUG; //
-  switch(log_level) {
-  case LOG_DEBUG:
-    level=BLADERF_LOG_LEVEL_DEBUG;
-    break;
-  case LOG_INFO:
-    level= BLADERF_LOG_LEVEL_INFO;
-    break;
-  case LOG_WARNING:
-    level=BLADERF_LOG_LEVEL_WARNING;
-    break;
-  case LOG_ERR:
-    level=BLADERF_LOG_LEVEL_ERROR;
-    break;
-  case LOG_CRIT:
-    level=BLADERF_LOG_LEVEL_CRITICAL;
-    break;
-  case LOG_EMERG:
-    level = BLADERF_LOG_LEVEL_SILENT;
-    break;
-  default:
-    break;
-  }
-  return level;
+int get_brf_log_level(int log_level) {
+
+    int level=BLADERF_LOG_LEVEL_INFO;
+    return  BLADERF_LOG_LEVEL_INFO;
+    switch(log_level) {
+    case LOG_DEBUG:
+        level=BLADERF_LOG_LEVEL_DEBUG;
+        break;
+    case LOG_INFO:
+        level= BLADERF_LOG_LEVEL_INFO;
+        break;
+    case LOG_WARNING:
+        level=BLADERF_LOG_LEVEL_WARNING;
+        break;
+    case LOG_ERR:
+        level=BLADERF_LOG_LEVEL_ERROR;
+        break;
+    case LOG_CRIT:
+        level=BLADERF_LOG_LEVEL_CRITICAL;
+        break;
+    case LOG_EMERG:
+        level = BLADERF_LOG_LEVEL_SILENT;
+        break;
+    default:
+        break;
+    }
+    return level;
 }
 /*@}*/
diff --git a/targets/ARCH/COMMON/common_lib.c b/targets/ARCH/COMMON/common_lib.c
index d25826e82e7c060ae75c90c8e51bb9f86941e1cf..94bffa0520822664b602bfbef3aea14f8c205689 100644
--- a/targets/ARCH/COMMON/common_lib.c
+++ b/targets/ARCH/COMMON/common_lib.c
@@ -48,7 +48,7 @@ int set_device(openair0_device *device) {
   case USRP_B200_DEV:
     printf("[%s] has loaded USRP B200 device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU")); 
     break;
-case USRP_X300_DEV:
+  case USRP_X300_DEV:
     printf("[%s] has loaded USRP X300 device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU")); 
     break;
   case BLADERF_DEV:
@@ -57,6 +57,9 @@ case USRP_X300_DEV:
   case LMSSDR_DEV:
     printf("[%s] has loaded LMSSDR device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU")); 
     break;
+  case IRIS_DEV:
+    printf("[%s] has loaded Iris device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU"));
+    break;
   case NONE_DEV:
     printf("[%s] has not loaded a HW device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU"));
     break;    
diff --git a/targets/ARCH/COMMON/common_lib.h b/targets/ARCH/COMMON/common_lib.h
index 0ef3cd233f57433e6ca3dad9ad399d630206d7d7..084ef9fcd9fbc629e6381f2d4a5ef025696f06ec 100644
--- a/targets/ARCH/COMMON/common_lib.h
+++ b/targets/ARCH/COMMON/common_lib.h
@@ -95,6 +95,8 @@ typedef enum {
   BLADERF_DEV,
   /*!\brief device is LMSSDR (SoDeRa)*/
   LMSSDR_DEV,
+  /*!\brief device is Iris */
+  IRIS_DEV,
   /*!\brief device is NONE*/
   NONE_DEV,
   MAX_RF_DEV_TYPE
diff --git a/targets/ARCH/ETHERNET/USERSPACE/LIB/eth_udp.c b/targets/ARCH/ETHERNET/USERSPACE/LIB/eth_udp.c
index 8cf14b4ca8753ddfcdb886e505fd6415a9ae936e..11ad12bfec69652438ba2ccbeafd07d03329b274 100644
--- a/targets/ARCH/ETHERNET/USERSPACE/LIB/eth_udp.c
+++ b/targets/ARCH/ETHERNET/USERSPACE/LIB/eth_udp.c
@@ -244,7 +244,6 @@ int trx_eth_write_udp_IF4p5(openair0_device *device, openair0_timestamp timestam
   }
    
   eth->tx_nsamps = nblocks;
-  //  printf("Sending %d bytes to %s:%d\n",packet_size,str,ntohs(eth->local_addrd.sin_port));
 
   bytes_sent = sendto(eth->sockfdd,
 		      buff[0], 
diff --git a/targets/ARCH/ETHERNET/USERSPACE/LIB/ethernet_lib.c b/targets/ARCH/ETHERNET/USERSPACE/LIB/ethernet_lib.c
index 108c4ca069e07ee71c7b3625cb5b5b8f5c9740ad..392cad2ee7af364e0a4189d8c473c75d814fac37 100644
--- a/targets/ARCH/ETHERNET/USERSPACE/LIB/ethernet_lib.c
+++ b/targets/ARCH/ETHERNET/USERSPACE/LIB/ethernet_lib.c
@@ -19,7 +19,7 @@
  *      contact@openairinterface.org
  */
 
-/*! \file ethernet_lib.c 
+/*! \file ethernet_lib.c
  * \brief API to stream I/Q samples over standard ethernet
  * \author  add alcatel Katerina Trilyraki, Navid Nikaein, Pedro Dinis, Lucio Ferreira, Raymond Knopp
  * \date 2015
@@ -55,113 +55,113 @@ int dest_addr_len[MAX_INST];
 
 int trx_eth_start(openair0_device *device) {
 
-  eth_state_t *eth = (eth_state_t*)device->priv;
-  
-  /* initialize socket */
-  if (eth->flags == ETH_RAW_MODE) {     
-    printf("Setting ETHERNET to ETH_RAW_IF5_MODE\n");
-    if (eth_socket_init_raw(device)!=0)   return -1;
-    /* RRU gets device configuration - RAU sets device configuration*/
+    eth_state_t *eth = (eth_state_t*)device->priv;
 
-    printf("Setting Timenout to 999999 usecs\n");
-    if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0)  return -1;
+    /* initialize socket */
+    if (eth->flags == ETH_RAW_MODE) {
+        printf("Setting ETHERNET to ETH_RAW_IF5_MODE\n");
+        if (eth_socket_init_raw(device)!=0)   return -1;
+        /* RRU gets device configuration - RAU sets device configuration*/
 
-    /*
-    if (device->host_type == RAU_HOST) {
-      if(eth_set_dev_conf_raw(device)!=0)  return -1;
-    } else {
-      if(eth_get_dev_conf_raw(device)!=0)  return -1;
-      }*/
+        printf("Setting Timenout to 999999 usecs\n");
+        if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0)  return -1;
 
-    /* adjust MTU wrt number of samples per packet */
-    if(eth->compression == ALAW_COMPRESS) {
-      if(ethernet_tune (device,MTU_SIZE,RAW_PACKET_SIZE_BYTES_ALAW(device->openair0_cfg->samples_per_packet))!=0)  return -1;
-    } else {
-      if(ethernet_tune (device,MTU_SIZE,RAW_PACKET_SIZE_BYTES(device->openair0_cfg->samples_per_packet))!=0)  return -1;
-    }
-    if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0)  return -1;
-  } else if (eth->flags == ETH_RAW_IF4p5_MODE) {
+        /*
+        if (device->host_type == RAU_HOST) {
+          if(eth_set_dev_conf_raw(device)!=0)  return -1;
+        } else {
+          if(eth_get_dev_conf_raw(device)!=0)  return -1;
+          }*/
 
-    printf("Setting ETHERNET to ETH_RAW_IF4p5_MODE\n");
-    if (eth_socket_init_raw(device)!=0)   return -1;
+        /* adjust MTU wrt number of samples per packet */
+        if(eth->compression == ALAW_COMPRESS) {
+            if(ethernet_tune (device,MTU_SIZE,RAW_PACKET_SIZE_BYTES_ALAW(device->openair0_cfg->samples_per_packet))!=0)  return -1;
+        } else {
+            if(ethernet_tune (device,MTU_SIZE,RAW_PACKET_SIZE_BYTES(device->openair0_cfg->samples_per_packet))!=0)  return -1;
+        }
+        if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0)  return -1;
+    } else if (eth->flags == ETH_RAW_IF4p5_MODE) {
 
-    printf("Setting Timenout to 999999 usecs\n");
-    if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0)  return -1;
+        printf("Setting ETHERNET to ETH_RAW_IF4p5_MODE\n");
+        if (eth_socket_init_raw(device)!=0)   return -1;
 
-    /*
-    if (device->host_type == RAU_HOST) {
-      if(eth_set_dev_conf_raw_IF4p5(device)!=0)  return -1;
-    } else {
-      if(eth_get_dev_conf_raw_IF4p5(device)!=0)  return -1;
-    }
-    */
+        printf("Setting Timenout to 999999 usecs\n");
+        if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0)  return -1;
 
-    /* adjust MTU wrt number of samples per packet */
-    if(ethernet_tune (device,MTU_SIZE,RAW_IF4p5_PRACH_SIZE_BYTES)!=0)  return -1;
+        /*
+        if (device->host_type == RAU_HOST) {
+          if(eth_set_dev_conf_raw_IF4p5(device)!=0)  return -1;
+        } else {
+          if(eth_get_dev_conf_raw_IF4p5(device)!=0)  return -1;
+        }
+        */
 
-    if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0)  return -1;
-  } else if (eth->flags == ETH_UDP_IF4p5_MODE) {
-    printf("Setting ETHERNET to UDP_IF4p5_MODE\n");
-    if (eth_socket_init_udp(device)!=0)   return -1;
+        /* adjust MTU wrt number of samples per packet */
+        if(ethernet_tune (device,MTU_SIZE,RAW_IF4p5_PRACH_SIZE_BYTES)!=0)  return -1;
 
-    printf("Setting Timeout to 999999 usecs\n");
-    if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0)  return -1;
+        if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0)  return -1;
+    } else if (eth->flags == ETH_UDP_IF4p5_MODE) {
+        printf("Setting ETHERNET to UDP_IF4p5_MODE\n");
+        if (eth_socket_init_udp(device)!=0)   return -1;
 
-    /*
-    if (device->host_type == RAU_HOST) {
-      if(eth_set_dev_conf_udp(device)!=0)  return -1;
-    } else {
-      if(eth_get_dev_conf_udp(device)!=0)  return -1;
-    }
-    */
+        printf("Setting Timeout to 999999 usecs\n");
+        if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0)  return -1;
 
-    /* adjust MTU wrt number of samples per packet */
-    if(ethernet_tune (device,MTU_SIZE,UDP_IF4p5_PRACH_SIZE_BYTES)!=0)  return -1;
-     
+        /*
+        if (device->host_type == RAU_HOST) {
+          if(eth_set_dev_conf_udp(device)!=0)  return -1;
+        } else {
+          if(eth_get_dev_conf_udp(device)!=0)  return -1;
+        }
+        */
 
+        /* adjust MTU wrt number of samples per packet */
+        if(ethernet_tune (device,MTU_SIZE,UDP_IF4p5_PRACH_SIZE_BYTES)!=0)  return -1;
 
-    
-  } else if (eth->flags == ETH_RAW_IF5_MOBIPASS) {
-    printf("Setting ETHERNET to RAW_IF5_MODE\n");
-    if (eth_socket_init_raw(device)!=0)   return -1;
-    if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0)  return -1;
 
-  } else {
-    printf("Setting ETHERNET to UDP_IF5_MODE\n");
-    if (eth_socket_init_udp(device)!=0)   return -1;
 
-    /*
-    if (device->host_type == RAU_HOST) {
-      if(eth_set_dev_conf_udp(device)!=0)  return -1;
+
+    } else if (eth->flags == ETH_RAW_IF5_MOBIPASS) {
+        printf("Setting ETHERNET to RAW_IF5_MODE\n");
+        if (eth_socket_init_raw(device)!=0)   return -1;
+        if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0)  return -1;
+
     } else {
-      if(eth_get_dev_conf_udp(device)!=0)  return -1;
-      }*/
+        printf("Setting ETHERNET to UDP_IF5_MODE\n");
+        if (eth_socket_init_udp(device)!=0)   return -1;
+
+        /*
+        if (device->host_type == RAU_HOST) {
+          if(eth_set_dev_conf_udp(device)!=0)  return -1;
+        } else {
+          if(eth_get_dev_conf_udp(device)!=0)  return -1;
+          }*/
+
+        /* adjust MTU wrt number of samples per packet */
+        if(ethernet_tune (device,MTU_SIZE,UDP_IF4p5_PRACH_SIZE_BYTES)!=0)  return -1;
+
+        if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0)  return -1;
+    }
+    /* apply additional configuration */
+    if(ethernet_tune (device, SND_BUF_SIZE,2000000000)!=0)  return -1;
+    if(ethernet_tune (device, RCV_BUF_SIZE,2000000000)!=0)  return -1;
+    if(ethernet_tune (device, KERNEL_SND_BUF_MAX_SIZE, 200000000)!=0)  return -1;
+    if(ethernet_tune (device, KERNEL_RCV_BUF_MAX_SIZE, 200000000)!=0)  return -1;
 
-    /* adjust MTU wrt number of samples per packet */
-    if(ethernet_tune (device,MTU_SIZE,UDP_IF4p5_PRACH_SIZE_BYTES)!=0)  return -1;
-    
-    if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0)  return -1;
-  }
-  /* apply additional configuration */
-  if(ethernet_tune (device, SND_BUF_SIZE,2000000000)!=0)  return -1;
-  if(ethernet_tune (device, RCV_BUF_SIZE,2000000000)!=0)  return -1;
-  if(ethernet_tune (device, KERNEL_SND_BUF_MAX_SIZE, 200000000)!=0)  return -1;
-  if(ethernet_tune (device, KERNEL_RCV_BUF_MAX_SIZE, 200000000)!=0)  return -1;
-
-  return 0;
+    return 0;
 }
 
 
 void trx_eth_end(openair0_device *device) {
 
-  eth_state_t *eth = (eth_state_t*)device->priv;
-  /* destroys socket only for the processes that call the eth_end fuction-- shutdown() for beaking the pipe */
-  if ( close(eth->sockfdd) <0 ) {
-    perror("ETHERNET: Failed to close socket");
-    exit(0);
-   } else {
-    printf("[%s] socket has been successfully closed.\n",(device->host_type == RAU_HOST)? "RAU":"RRU");
-   }
+    eth_state_t *eth = (eth_state_t*)device->priv;
+    /* destroys socket only for the processes that call the eth_end fuction-- shutdown() for beaking the pipe */
+    if ( close(eth->sockfdd) <0 ) {
+        perror("ETHERNET: Failed to close socket");
+        exit(0);
+    } else {
+        printf("[%s] socket has been successfully closed.\n",(device->host_type == RAU_HOST)? "RAU":"RRU");
+    }
 }
 
 
@@ -187,282 +187,282 @@ int trx_eth_reset_stats(openair0_device* device) {
 
 
 int ethernet_tune(openair0_device *device, unsigned int option, int value) {
-  
-  eth_state_t *eth = (eth_state_t*)device->priv;
-  struct timeval timeout;
-  struct ifreq ifr;   
-  char system_cmd[256];
-  int rname[] = { CTL_NET, NET_CORE, NET_CORE_RMEM_MAX };
-  int wname[] = { CTL_NET, NET_CORE, NET_CORE_WMEM_MAX };
-  int namelen=3;
-  int newval[1];
-  int newlen=sizeof(newval);
-  int ret=0;
-  //  int i=0;
-  
-  /****************** socket level options ************************/  
-  switch(option) {
-  case SND_BUF_SIZE:  /* transmit socket buffer size */   
-    if (setsockopt(eth->sockfdd,  
-		   SOL_SOCKET,  
-		   SO_SNDBUF,  
-		   &value,sizeof(value))) {
-      perror("[ETHERNET] setsockopt()");
-    } else {
-      printf("send buffer size= %d bytes\n",value); 
-    }   
-    break;
-    
-  case RCV_BUF_SIZE:   /* receive socket buffer size */   
-    if (setsockopt(eth->sockfdd,  
-		   SOL_SOCKET,  
-		   SO_RCVBUF,  
-		   &value,sizeof(value))) {
-      perror("[ETHERNET] setsockopt()");
-    } else {     
-      printf("receive bufffer size= %d bytes\n",value);    
-    }
-    break;
-    
-  case RCV_TIMEOUT:
-    timeout.tv_sec = value/1000000;
-    timeout.tv_usec = value%1000000;//less than rt_period?
-    if (setsockopt(eth->sockfdc,  
-		   SOL_SOCKET,  
-		   SO_RCVTIMEO,  
-		   (char *)&timeout,sizeof(timeout))) {
-      perror("[ETHERNET] setsockopt()");  
-    } else {   
-      printf( "receive timeout= %u usec\n",(unsigned int)timeout.tv_usec);  
-    }  
-    if (setsockopt(eth->sockfdd,  
-		   SOL_SOCKET,  
-		   SO_RCVTIMEO,  
-		   (char *)&timeout,sizeof(timeout))) {
-      perror("[ETHERNET] setsockopt()");  
-    } else {   
-      printf( "receive timeout= %u usec\n",(unsigned int)timeout.tv_usec);  
-    }  
-    break;
-    
-  case SND_TIMEOUT:
-    timeout.tv_sec = value/1000000000;
-    timeout.tv_usec = value%1000000000;//less than rt_period?
-    if (setsockopt(eth->sockfdc,  
-		   SOL_SOCKET,  
-		   SO_SNDTIMEO,  
-		   (char *)&timeout,sizeof(timeout))) {
-      perror("[ETHERNET] setsockopt()");     
-    } else {
-      printf( "send timeout= %d,%d sec\n",(int)timeout.tv_sec,(int)timeout.tv_usec);    
-    }
-    if (setsockopt(eth->sockfdd,  
-		   SOL_SOCKET,  
-		   SO_SNDTIMEO,  
-		   (char *)&timeout,sizeof(timeout))) {
-      perror("[ETHERNET] setsockopt()");     
-    } else {
-      printf( "send timeout= %d,%d sec\n",(int)timeout.tv_sec,(int)timeout.tv_usec);    
-    }
-    break;
-    
-    
+
+    eth_state_t *eth = (eth_state_t*)device->priv;
+    struct timeval timeout;
+    struct ifreq ifr;
+    char system_cmd[256];
+    int rname[] = { CTL_NET, NET_CORE, NET_CORE_RMEM_MAX };
+    int wname[] = { CTL_NET, NET_CORE, NET_CORE_WMEM_MAX };
+    int namelen=3;
+    int newval[1];
+    int newlen=sizeof(newval);
+    int ret=0;
+    //  int i=0;
+
+    /****************** socket level options ************************/
+    switch(option) {
+    case SND_BUF_SIZE:  /* transmit socket buffer size */
+        if (setsockopt(eth->sockfdd,
+                       SOL_SOCKET,
+                       SO_SNDBUF,
+                       &value,sizeof(value))) {
+            perror("[ETHERNET] setsockopt()");
+        } else {
+            printf("send buffer size= %d bytes\n",value);
+        }
+        break;
+
+    case RCV_BUF_SIZE:   /* receive socket buffer size */
+        if (setsockopt(eth->sockfdd,
+                       SOL_SOCKET,
+                       SO_RCVBUF,
+                       &value,sizeof(value))) {
+            perror("[ETHERNET] setsockopt()");
+        } else {
+            printf("receive bufffer size= %d bytes\n",value);
+        }
+        break;
+
+    case RCV_TIMEOUT:
+        timeout.tv_sec = value/1000000;
+        timeout.tv_usec = value%1000000;//less than rt_period?
+        if (setsockopt(eth->sockfdc,
+                       SOL_SOCKET,
+                       SO_RCVTIMEO,
+                       (char *)&timeout,sizeof(timeout))) {
+            perror("[ETHERNET] setsockopt()");
+        } else {
+            printf( "receive timeout= %u usec\n",(unsigned int)timeout.tv_usec);
+        }
+        if (setsockopt(eth->sockfdd,
+                       SOL_SOCKET,
+                       SO_RCVTIMEO,
+                       (char *)&timeout,sizeof(timeout))) {
+            perror("[ETHERNET] setsockopt()");
+        } else {
+            printf( "receive timeout= %u usec\n",(unsigned int)timeout.tv_usec);
+        }
+        break;
+
+    case SND_TIMEOUT:
+        timeout.tv_sec = value/1000000000;
+        timeout.tv_usec = value%1000000000;//less than rt_period?
+        if (setsockopt(eth->sockfdc,
+                       SOL_SOCKET,
+                       SO_SNDTIMEO,
+                       (char *)&timeout,sizeof(timeout))) {
+            perror("[ETHERNET] setsockopt()");
+        } else {
+            printf( "send timeout= %d,%d sec\n",(int)timeout.tv_sec,(int)timeout.tv_usec);
+        }
+        if (setsockopt(eth->sockfdd,
+                       SOL_SOCKET,
+                       SO_SNDTIMEO,
+                       (char *)&timeout,sizeof(timeout))) {
+            perror("[ETHERNET] setsockopt()");
+        } else {
+            printf( "send timeout= %d,%d sec\n",(int)timeout.tv_sec,(int)timeout.tv_usec);
+        }
+        break;
+
+
     /******************* interface level options  *************************/
-  case MTU_SIZE: /* change  MTU of the eth interface */ 
-    ifr.ifr_addr.sa_family = AF_INET;
-    strncpy(ifr.ifr_name,eth->if_name, sizeof(ifr.ifr_name));
-    ifr.ifr_mtu =value;
-    if (ioctl(eth->sockfdd,SIOCSIFMTU,(caddr_t)&ifr) < 0 )
-      perror ("[ETHERNET] Can't set the MTU");
-    else 
-      printf("[ETHERNET] %s MTU size has changed to %d\n",eth->if_name,ifr.ifr_mtu);
-    break;
-    
-  case TX_Q_LEN:  /* change TX queue length of eth interface */ 
-    ifr.ifr_addr.sa_family = AF_INET;
-    strncpy(ifr.ifr_name,eth->if_name, sizeof(ifr.ifr_name));
-    ifr.ifr_qlen =value;
-    if (ioctl(eth->sockfdd,SIOCSIFTXQLEN,(caddr_t)&ifr) < 0 )
-      perror ("[ETHERNET] Can't set the txqueuelen");
-    else 
-      printf("[ETHERNET] %s txqueuelen size has changed to %d\n",eth->if_name,ifr.ifr_qlen);
-    break;
-    
+    case MTU_SIZE: /* change  MTU of the eth interface */
+        ifr.ifr_addr.sa_family = AF_INET;
+        strncpy(ifr.ifr_name,eth->if_name, sizeof(ifr.ifr_name));
+        ifr.ifr_mtu =value;
+        if (ioctl(eth->sockfdd,SIOCSIFMTU,(caddr_t)&ifr) < 0 )
+            perror ("[ETHERNET] Can't set the MTU");
+        else
+            printf("[ETHERNET] %s MTU size has changed to %d\n",eth->if_name,ifr.ifr_mtu);
+        break;
+
+    case TX_Q_LEN:  /* change TX queue length of eth interface */
+        ifr.ifr_addr.sa_family = AF_INET;
+        strncpy(ifr.ifr_name,eth->if_name, sizeof(ifr.ifr_name));
+        ifr.ifr_qlen =value;
+        if (ioctl(eth->sockfdd,SIOCSIFTXQLEN,(caddr_t)&ifr) < 0 )
+            perror ("[ETHERNET] Can't set the txqueuelen");
+        else
+            printf("[ETHERNET] %s txqueuelen size has changed to %d\n",eth->if_name,ifr.ifr_qlen);
+        break;
+
     /******************* device level options  *************************/
-  case COALESCE_PAR:
-    ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -C %s rx-usecs %d",eth->if_name,value);
-    if (ret > 0) {
-      ret=system(system_cmd);
-      if (ret == -1) {
-	fprintf (stderr,"[ETHERNET] Can't start shell to execute %s %s",system_cmd, strerror(errno));
-      } else {
-	printf ("[ETHERNET] status of %s is %d\n", system_cmd, WEXITSTATUS(ret));
-      }
-      printf("[ETHERNET] Coalesce parameters %s\n",system_cmd);
-    } else {
-      perror("[ETHERNET] Can't set coalesce parameters\n");
+    case COALESCE_PAR:
+        ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -C %s rx-usecs %d",eth->if_name,value);
+        if (ret > 0) {
+            ret=system(system_cmd);
+            if (ret == -1) {
+                fprintf (stderr,"[ETHERNET] Can't start shell to execute %s %s",system_cmd, strerror(errno));
+            } else {
+                printf ("[ETHERNET] status of %s is %d\n", system_cmd, WEXITSTATUS(ret));
+            }
+            printf("[ETHERNET] Coalesce parameters %s\n",system_cmd);
+        } else {
+            perror("[ETHERNET] Can't set coalesce parameters\n");
+        }
+        break;
+
+    case PAUSE_PAR:
+        if (value==1) ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -A %s autoneg off rx off tx off",eth->if_name);
+        else if (value==0) ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -A %s autoneg on rx on tx on",eth->if_name);
+        else break;
+        if (ret > 0) {
+            ret=system(system_cmd);
+            if (ret == -1) {
+                fprintf (stderr,"[ETHERNET] Can't start shell to execute %s %s",system_cmd, strerror(errno));
+            } else {
+                printf ("[ETHERNET] status of %s is %d\n", system_cmd, WEXITSTATUS(ret));
+            }
+            printf("[ETHERNET] Pause parameters %s\n",system_cmd);
+        } else {
+            perror("[ETHERNET] Can't set pause parameters\n");
+        }
+        break;
+
+    case RING_PAR:
+        ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -G %s val %d",eth->if_name,value);
+        if (ret > 0) {
+            ret=system(system_cmd);
+            if (ret == -1) {
+                fprintf (stderr,"[ETHERNET] Can't start shell to execute %s %s",system_cmd, strerror(errno));
+            } else {
+                printf ("[ETHERNET] status of %s is %d\n", system_cmd, WEXITSTATUS(ret));
+            }
+            printf("[ETHERNET] Ring parameters %s\n",system_cmd);
+        } else {
+            perror("[ETHERNET] Can't set ring parameters\n");
+        }
+        break;
+    case KERNEL_RCV_BUF_MAX_SIZE:
+        newval[0] = value;
+        ret=sysctl(rname, namelen, NULL, 0, newval, newlen);
+        if (ret) {
+            fprintf(stderr,"[ETHERNET] Error using sysctl():%s\n",strerror(errno));
+        } else {
+            printf("[ETHERNET] Kernel network receive buffer max size is set to %u\n",(unsigned int)newval[0]);
+        }
+        break;
+    case KERNEL_SND_BUF_MAX_SIZE:
+        newval[0] = value;
+        ret=sysctl(wname, namelen, NULL, 0, newval, newlen);
+        if (ret) {
+            fprintf(stderr,"[ETHERNET] Error using sysctl():%s\n",strerror(errno));
+        } else {
+            printf("[ETHERNET] Kernel network send buffer max size is set to %u\n",(unsigned int)newval[0]);
+        }
+        break;
+
+    default:
+        break;
     }
-    break;
-    
-  case PAUSE_PAR:
-    if (value==1) ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -A %s autoneg off rx off tx off",eth->if_name);
-    else if (value==0) ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -A %s autoneg on rx on tx on",eth->if_name);
-    else break;
-    if (ret > 0) {
-      ret=system(system_cmd);
-      if (ret == -1) {
-	fprintf (stderr,"[ETHERNET] Can't start shell to execute %s %s",system_cmd, strerror(errno));
-      } else {
-	printf ("[ETHERNET] status of %s is %d\n", system_cmd, WEXITSTATUS(ret));
-      }
-      printf("[ETHERNET] Pause parameters %s\n",system_cmd);
+
+    return 0;
+}
+
+
+int transport_init(openair0_device *device, openair0_config_t *openair0_cfg, eth_params_t * eth_params ) {
+
+    eth_state_t *eth = (eth_state_t*)malloc(sizeof(eth_state_t));
+    memset(eth, 0, sizeof(eth_state_t));
+
+    if (eth_params->transp_preference == 1) {
+        eth->flags = ETH_RAW_MODE;
+    } else if (eth_params->transp_preference == 0) {
+        eth->flags = ETH_UDP_MODE;
+    } else if (eth_params->transp_preference == 3) {
+        eth->flags = ETH_RAW_IF4p5_MODE;
+    } else if (eth_params->transp_preference == 2) {
+        eth->flags = ETH_UDP_IF4p5_MODE;
+    } else if (eth_params->transp_preference == 4) {
+        eth->flags = ETH_RAW_IF5_MOBIPASS;
     } else {
-      perror("[ETHERNET] Can't set pause parameters\n");
+        printf("transport_init: Unknown transport preference %d - default to RAW", eth_params->transp_preference);
+        eth->flags = ETH_RAW_MODE;
     }
-    break;
-    
-  case RING_PAR:
-    ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -G %s val %d",eth->if_name,value);
-    if (ret > 0) {
-      ret=system(system_cmd);
-      if (ret == -1) {
-        fprintf (stderr,"[ETHERNET] Can't start shell to execute %s %s",system_cmd, strerror(errno));
-      } else {
-        printf ("[ETHERNET] status of %s is %d\n", system_cmd, WEXITSTATUS(ret));
-      }            
-      printf("[ETHERNET] Ring parameters %s\n",system_cmd);
+
+    if (eth_params->if_compress == 0) {
+        eth->compression = NO_COMPRESS;
+    } else if (eth_params->if_compress == 1) {
+        eth->compression = ALAW_COMPRESS;
     } else {
-      perror("[ETHERNET] Can't set ring parameters\n");
-    }
-    break;
-  case KERNEL_RCV_BUF_MAX_SIZE:
-    newval[0] = value;
-    ret=sysctl(rname, namelen, NULL, 0, newval, newlen);
-    if (ret) {
-      fprintf(stderr,"[ETHERNET] Error using sysctl():%s\n",strerror(errno));
-    } else{
-      printf("[ETHERNET] Kernel network receive buffer max size is set to %u\n",newval[0]);
+        printf("transport_init: Unknown compression scheme %d - default to ALAW", eth_params->if_compress);
+        eth->compression = ALAW_COMPRESS;
     }
-    break;
-  case KERNEL_SND_BUF_MAX_SIZE:
-    newval[0] = value;
-    ret=sysctl(wname, namelen, NULL, 0, newval, newlen);
-    if (ret) {
-      fprintf(stderr,"[ETHERNET] Error using sysctl():%s\n",strerror(errno));
-    } else{
-      printf("[ETHERNET] Kernel network send buffer max size is set to %u\n",newval[0]);
+
+    printf("[ETHERNET]: Initializing openair0_device for %s ...\n", ((device->host_type == RAU_HOST) ? "RAU": "RRU"));
+    device->Mod_id           = 0;//num_devices_eth++;
+    device->transp_type      = ETHERNET_TP;
+    device->trx_start_func   = trx_eth_start;
+    device->trx_get_stats_func   = trx_eth_get_stats;
+    device->trx_reset_stats_func = trx_eth_reset_stats;
+    device->trx_end_func         = trx_eth_end;
+    device->trx_stop_func        = trx_eth_stop;
+    device->trx_set_freq_func = trx_eth_set_freq;
+    device->trx_set_gains_func = trx_eth_set_gains;
+
+    if (eth->flags == ETH_RAW_MODE) {
+        device->trx_write_func   = trx_eth_write_raw;
+        device->trx_read_func    = trx_eth_read_raw;
+    } else if (eth->flags == ETH_UDP_MODE) {
+        device->trx_write_func   = trx_eth_write_udp;
+        device->trx_read_func    = trx_eth_read_udp;
+        device->trx_ctlsend_func = trx_eth_ctlsend_udp;
+        device->trx_ctlrecv_func = trx_eth_ctlrecv_udp;
+    } else if (eth->flags == ETH_RAW_IF4p5_MODE) {
+        device->trx_write_func   = trx_eth_write_raw_IF4p5;
+        device->trx_read_func    = trx_eth_read_raw_IF4p5;
+    } else if (eth->flags == ETH_UDP_IF4p5_MODE) {
+        device->trx_write_func   = trx_eth_write_udp_IF4p5;
+        device->trx_read_func    = trx_eth_read_udp_IF4p5;
+        device->trx_ctlsend_func = trx_eth_ctlsend_udp;
+        device->trx_ctlrecv_func = trx_eth_ctlrecv_udp;
+    } else if (eth->flags == ETH_RAW_IF5_MOBIPASS) {
+        device->trx_write_func   = trx_eth_write_raw_IF4p5;
+        device->trx_read_func    = trx_eth_read_raw_IF5_mobipass;
+    } else {
+        //device->trx_write_func   = trx_eth_write_udp_IF4p5;
+        //device->trx_read_func    = trx_eth_read_udp_IF4p5;
     }
-    break;
-    
-  default:
-    break;
-  }
-  
-  return 0;
-}
 
+    eth->if_name = eth_params->local_if_name;
+    device->priv = eth;
 
-int transport_init(openair0_device *device, openair0_config_t *openair0_cfg, eth_params_t * eth_params ) {
+    /* device specific */
+    //  openair0_cfg[0].iq_rxrescale = 15;//rescale iqs
+    //  openair0_cfg[0].iq_txshift = eth_params->iq_txshift;// shift
+    //  openair0_cfg[0].tx_sample_advance = eth_params->tx_sample_advance;
 
-  eth_state_t *eth = (eth_state_t*)malloc(sizeof(eth_state_t));
-  memset(eth, 0, sizeof(eth_state_t));
-  
-  if (eth_params->transp_preference == 1) {
-    eth->flags = ETH_RAW_MODE;
-  } else if (eth_params->transp_preference == 0) {
-    eth->flags = ETH_UDP_MODE;
-  } else if (eth_params->transp_preference == 3) {
-    eth->flags = ETH_RAW_IF4p5_MODE;
-  } else if (eth_params->transp_preference == 2) {
-    eth->flags = ETH_UDP_IF4p5_MODE;
-  } else if (eth_params->transp_preference == 4) {
-    eth->flags = ETH_RAW_IF5_MOBIPASS;
-  } else {
-    printf("transport_init: Unknown transport preference %d - default to RAW", eth_params->transp_preference);
-    eth->flags = ETH_RAW_MODE;
-  }
-
-  if (eth_params->if_compress == 0) {
-    eth->compression = NO_COMPRESS;
-  } else if (eth_params->if_compress == 1) {
-    eth->compression = ALAW_COMPRESS;
-  } else {
-    printf("transport_init: Unknown compression scheme %d - default to ALAW", eth_params->if_compress);
-    eth->compression = ALAW_COMPRESS;
-  }
-  
-  printf("[ETHERNET]: Initializing openair0_device for %s ...\n", ((device->host_type == RAU_HOST) ? "RAU": "RRU"));
-  device->Mod_id           = 0;//num_devices_eth++;
-  device->transp_type      = ETHERNET_TP;
-  device->trx_start_func   = trx_eth_start;
-  device->trx_get_stats_func   = trx_eth_get_stats;
-  device->trx_reset_stats_func = trx_eth_reset_stats;
-  device->trx_end_func         = trx_eth_end;
-  device->trx_stop_func        = trx_eth_stop;
-  device->trx_set_freq_func = trx_eth_set_freq;
-  device->trx_set_gains_func = trx_eth_set_gains;
-  
-  if (eth->flags == ETH_RAW_MODE) {
-    device->trx_write_func   = trx_eth_write_raw;
-    device->trx_read_func    = trx_eth_read_raw;     
-  } else if (eth->flags == ETH_UDP_MODE) {
-    device->trx_write_func   = trx_eth_write_udp;
-    device->trx_read_func    = trx_eth_read_udp;
-    device->trx_ctlsend_func = trx_eth_ctlsend_udp;
-    device->trx_ctlrecv_func = trx_eth_ctlrecv_udp;
-  } else if (eth->flags == ETH_RAW_IF4p5_MODE) {
-    device->trx_write_func   = trx_eth_write_raw_IF4p5;
-    device->trx_read_func    = trx_eth_read_raw_IF4p5;     
-  } else if (eth->flags == ETH_UDP_IF4p5_MODE) {
-    device->trx_write_func   = trx_eth_write_udp_IF4p5;
-    device->trx_read_func    = trx_eth_read_udp_IF4p5;
-    device->trx_ctlsend_func = trx_eth_ctlsend_udp;
-    device->trx_ctlrecv_func = trx_eth_ctlrecv_udp;
-  } else if (eth->flags == ETH_RAW_IF5_MOBIPASS) {
-    device->trx_write_func   = trx_eth_write_raw_IF4p5;
-    device->trx_read_func    = trx_eth_read_raw_IF5_mobipass;   
-  } else {
-    //device->trx_write_func   = trx_eth_write_udp_IF4p5;
-    //device->trx_read_func    = trx_eth_read_udp_IF4p5;     
-  }
-  
-  eth->if_name = eth_params->local_if_name;
-  device->priv = eth;
- 	
-  /* device specific */
-  //  openair0_cfg[0].iq_rxrescale = 15;//rescale iqs
-  //  openair0_cfg[0].iq_txshift = eth_params->iq_txshift;// shift
-  //  openair0_cfg[0].tx_sample_advance = eth_params->tx_sample_advance;
-
-  /* RRU does not have any information to make this configuration atm */
-  /*
-  if (device->host_type == RAU_HOST) {
-   
-    switch ((int)openair0_cfg[0].sample_rate) {
-    case 30720000:
-      openair0_cfg[0].samples_per_packet    = 3840;     
-      break;
-    case 23040000:     
-      openair0_cfg[0].samples_per_packet    = 2880;
-      break;
-    case 15360000:
-      openair0_cfg[0].samples_per_packet    = 1920;      
-      break;
-    case 7680000:
-      openair0_cfg[0].samples_per_packet    = 960;     
-      break;
-    case 1920000:
-      openair0_cfg[0].samples_per_packet    = 240;     
-      break;
-    default:
-      printf("Error: unknown sampling rate %f\n",openair0_cfg[0].sample_rate);
-      exit(-1);
-      break;
-    }
-    }*/
+    /* RRU does not have any information to make this configuration atm */
+    /*
+    if (device->host_type == RAU_HOST) {
+
+      switch ((int)openair0_cfg[0].sample_rate) {
+      case 30720000:
+        openair0_cfg[0].samples_per_packet    = 3840;
+        break;
+      case 23040000:
+        openair0_cfg[0].samples_per_packet    = 2880;
+        break;
+      case 15360000:
+        openair0_cfg[0].samples_per_packet    = 1920;
+        break;
+      case 7680000:
+        openair0_cfg[0].samples_per_packet    = 960;
+        break;
+      case 1920000:
+        openair0_cfg[0].samples_per_packet    = 240;
+        break;
+      default:
+        printf("Error: unknown sampling rate %f\n",openair0_cfg[0].sample_rate);
+        exit(-1);
+        break;
+      }
+      }*/
 
-  device->openair0_cfg=&openair0_cfg[0];
-  return 0;
+    device->openair0_cfg=&openair0_cfg[0];
+    return 0;
 }
 
 
diff --git a/targets/ARCH/EXMIMO/DRIVER/eurecom/Makefile b/targets/ARCH/EXMIMO/DRIVER/eurecom/Makefile
old mode 100755
new mode 100644
diff --git a/targets/ARCH/EXMIMO/DRIVER/exmimo3/Makefile b/targets/ARCH/EXMIMO/DRIVER/exmimo3/Makefile
old mode 100755
new mode 100644
diff --git a/targets/ARCH/EXMIMO/USERSPACE/LIB/openair0_lib.c b/targets/ARCH/EXMIMO/USERSPACE/LIB/openair0_lib.c
index 7d23cdeb8929391659e668f60c4edf118cd01891..f12af629b7f08924e818de904c3b88346e5452ee 100644
--- a/targets/ARCH/EXMIMO/USERSPACE/LIB/openair0_lib.c
+++ b/targets/ARCH/EXMIMO/USERSPACE/LIB/openair0_lib.c
@@ -444,7 +444,7 @@ static void *watchdog_thread(void *arg) {
 	  (diff > 16)&&
 	  (first_acquisition==0))  {// we're too late so exit
 	exm->watchdog_exit = 1;
-        printf("exiting, too late to keep up - diff = %d\n", diff);
+        printf("exiting, too late to keep up - diff = %u\n", diff);
       }
       first_acquisition=0;
 
@@ -625,7 +625,7 @@ int trx_exmimo_read(openair0_device *device, openair0_timestamp *ptimestamp, voi
     if (cfg->mmapped_dma == 0) {  // if buff is not the dma buffer, do a memcpy, otherwise do nothing
       for (i=0;i<cc;i++) {
 #ifdef DEBUG_EXMIMO
-	printf("copying to %p (%lu), from %llu\n",buff[i]+(ntot*sizeof(int)),ntot*sizeof(int),(exm->last_ts_rx % exm->samples_per_frame));
+	printf("copying to %p (%zu), from %llu\n",buff[i]+(ntot*sizeof(int)),ntot*sizeof(int),(exm->last_ts_rx % exm->samples_per_frame));
 #endif
 	if ((n+(exm->last_ts_rx%exm->samples_per_frame))<exm->samples_per_frame) {
 	  memcpy(buff[i]+(ntot*sizeof(int)),
@@ -733,7 +733,7 @@ int device_init(openair0_device *device, openair0_config_t *openair0_cfg) {
 
     if (ret == -3)
       printf("Error mapping RX or TX buffer");
-
+    free(exm);
     return(ret);
   }
 
@@ -752,6 +752,7 @@ int device_init(openair0_device *device, openair0_config_t *openair0_cfg) {
     // check if the software matches firmware
     if (p_exmimo_id->board_swrev!=BOARD_SWREV_CNTL2) {
       printf("Software revision %d and firmware revision %d do not match. Please update either the firmware or the software!\n",BOARD_SWREV_CNTL2,p_exmimo_id->board_swrev);
+      free(exm);
       return(-1);
     }
   }
@@ -905,7 +906,7 @@ int openair0_config(openair0_config_t *openair0_cfg, int UE_flag)
 	    p_exmimo_config->rf.rx_gain[ant][0] = 30 - (rxg_max[ant] - (int)openair0_cfg[card].rx_gain[ant]); //was measured at rxgain=30;
 	  }
 	  else {
-	    printf("openair0: RX RF gain too high, reduce by %d dB\n", (int)openair0_cfg[card].rx_gain[ant]-rxg_max[ant]);
+	    printf("openair0: RX RF gain too high, reduce by %u dB\n", (int)openair0_cfg[card].rx_gain[ant]-rxg_max[ant]);
 	    exit(-1);
 	  }
           break;
@@ -916,7 +917,7 @@ int openair0_config(openair0_config_t *openair0_cfg, int UE_flag)
 	    p_exmimo_config->rf.rx_gain[ant][0] = 30 - (rxg_med[ant] - (int)openair0_cfg[card].rx_gain[ant]); //was measured at rxgain=30;
 	  }
 	  else {
-	    printf("openair0: RX RF gain too high, reduce by %d dB\n", (int)openair0_cfg[card].rx_gain[ant]-rxg_med[ant]);
+	    printf("openair0: RX RF gain too high, reduce by %u dB\n", (int)openair0_cfg[card].rx_gain[ant]-rxg_med[ant]);
 	    exit(-1);
 	  }
           break;
@@ -927,7 +928,7 @@ int openair0_config(openair0_config_t *openair0_cfg, int UE_flag)
 	    p_exmimo_config->rf.rx_gain[ant][0] = 30 - (rxg_byp[ant] - (int)openair0_cfg[card].rx_gain[ant]); //was measured at rxgain=30;
 	  }
 	  else {
-	    printf("openair0: RX RF gain too high, reduce by %d dB\n", (int)openair0_cfg[card].rx_gain[ant]-rxg_byp[ant]);
+	    printf("openair0: RX RF gain too high, reduce by %u dB\n", (int)openair0_cfg[card].rx_gain[ant]-rxg_byp[ant]);
 	    exit(-1);
 	  }
           break;
diff --git a/targets/ARCH/EXMIMO/USERSPACE/OAI_FW_INIT/updatefw.c b/targets/ARCH/EXMIMO/USERSPACE/OAI_FW_INIT/updatefw.c
index 1b2445fa72e512cb290a12ab3ebf80c97c3ab138..febf221c5be715a6be12a7d89cbf0f98c737e94f 100644
--- a/targets/ARCH/EXMIMO/USERSPACE/OAI_FW_INIT/updatefw.c
+++ b/targets/ARCH/EXMIMO/USERSPACE/OAI_FW_INIT/updatefw.c
@@ -211,22 +211,25 @@ void find_and_transfer_section(char* section_name, unsigned int verboselevel) {
   int nbread;
   unsigned int secnb = 0;
 
+  if(p_elfimage == NULL) {
+    fprintf(stderr, "%s %d:Error, firmware file not opened\n",__FILE__,__LINE__);
+  }
   for (secnb = 0 ; secnb < elf_Ehdr.e_shnum; secnb++) {
     get_elf_section_header(&elf_Shdr, p_elfimage, secnb);
 
     if (!strcmp(SecNameStnTable + elf_Shdr.sh_name, section_name)) {
       if (verboselevel >= VERBOSE_LEVEL_SECTION_DETAILS)
-        printf("Info: ok, found section %s (as section nb. %d)\n", SecNameStnTable + elf_Shdr.sh_name, secnb);
+        printf("Info: ok, found section %s (as section nb. %u)\n", SecNameStnTable + elf_Shdr.sh_name, secnb);
 
       /* Check that section size is a multiple of 4 bytes. */
       if (elf_Shdr.sh_size % 4) {
-        fprintf(stderr, "Error: section %s has a non-multiple-of-4-bytes size (%d).\n",
-                SecNameStnTable + elf_Shdr.sh_name, elf_Shdr.sh_size);
+        fprintf(stderr, "Error: section %s has a non-multiple-of-4-bytes size (%lu).\n",
+                SecNameStnTable + elf_Shdr.sh_name, (unsigned long)elf_Shdr.sh_size);
         fclose(p_elfimage);
         exit(-1);
       } else if (verboselevel >= VERBOSE_LEVEL_SECTION_DETAILS) {
-        printf("Info: ok, section %s has size %d bytes (multiple of 4 bytes).\n",
-               SecNameStnTable + elf_Shdr.sh_name, elf_Shdr.sh_size);
+        printf("Info: ok, section %s has size %lu bytes (multiple of 4 bytes).\n",
+               SecNameStnTable + elf_Shdr.sh_name, (unsigned long)elf_Shdr.sh_size);
       }
 
       /* Dynamically allocate a chunk of memory to store the section into. */
@@ -245,13 +248,13 @@ void find_and_transfer_section(char* section_name, unsigned int verboselevel) {
       }
 
       if (!section_content) {
-        fprintf(stderr, "Error: could not dynamically allocate %d bytes for section %s.\n",
-                elf_Shdr.sh_size, SecNameStnTable + elf_Shdr.sh_name);
+        fprintf(stderr, "Error: could not dynamically allocate %lu bytes for section %s.\n",
+                (unsigned long)elf_Shdr.sh_size, (SecNameStnTable + elf_Shdr.sh_name));
         fclose(p_elfimage);
         exit(-1);
       } else if (verboselevel >= VERBOSE_LEVEL_IOCTL) {
-        printf("Info: ok, dynamically allocated a %d bytes buffer for section %s.\n",
-               elf_Shdr.sh_size, SecNameStnTable + elf_Shdr.sh_name);
+        printf("Info: ok, dynamically allocated a %lu bytes buffer for section %s.\n",
+               (unsigned long)elf_Shdr.sh_size, SecNameStnTable + elf_Shdr.sh_name);
       }
 
       /* Position the file cursor at the begining of proper section. */
@@ -260,13 +263,13 @@ void find_and_transfer_section(char* section_name, unsigned int verboselevel) {
       nbread = fread(section_content, elf_Shdr.sh_size, 1, p_elfimage);
 
       if (nbread != 1) {
-        fprintf(stderr, "Error: could not read %d bytes from ELF file into dynamic buffer.\n", elf_Shdr.sh_size);
+        fprintf(stderr, "Error: could not read %lu bytes from ELF file into dynamic buffer.\n", (unsigned long)elf_Shdr.sh_size);
         free(section_content);
         fclose(p_elfimage);
         exit(-1);
       } else if (verboselevel >= VERBOSE_LEVEL_IOCTL) {
-        printf("Info: ok, copied content of section %s into dynamic buffer (%d bytes copied).\n",
-               SecNameStnTable + elf_Shdr.sh_name, elf_Shdr.sh_size);
+        printf("Info: ok, copied content of section %s into dynamic buffer (%lu bytes copied).\n",
+               SecNameStnTable + elf_Shdr.sh_name, (unsigned long)elf_Shdr.sh_size);
       }
 
       /* Open the special device file. */
@@ -324,12 +327,15 @@ void find_and_clear_section_bss(unsigned int verboselevel) {
   int ifile;
   unsigned int secnb = 0;
 
+  if(p_elfimage == NULL) {
+    fprintf(stderr, "%s %d:Error, firmware file not opened\n",__FILE__,__LINE__);
+  }
   for (secnb = 0 ; secnb < elf_Ehdr.e_shnum; secnb++) {
     get_elf_section_header(&elf_Shdr, p_elfimage, secnb);
 
     if (!strcmp(SecNameStnTable + elf_Shdr.sh_name, ".bss")) {
       if (verboselevel >= VERBOSE_LEVEL_SECTION_DETAILS)
-        printf("Info: ok, found section %s (as section nb. %d)\n", SecNameStnTable + elf_Shdr.sh_name, secnb);
+        printf("Info: ok, found section %s (as section nb. %u)\n", SecNameStnTable + elf_Shdr.sh_name, secnb);
 
       /* Open the special device file. */
       if (!pflag) {
@@ -491,6 +497,10 @@ int main(int argc, char** argv) {
 
   /* Open firmware file in READ_ONLY mode. */
   filename = p_str_fwn;
+  if (filename == NULL) {
+     fprintf(stderr, "%s %d: No filename specified\n", __FILE__, __LINE__);
+     exit(-1);
+  }
   p_elfimage = fopen(filename, READ_FILE_MODE);
 
   if (p_elfimage == NULL) {
@@ -505,6 +515,7 @@ int main(int argc, char** argv) {
   /* Get informations from header file */
   if (!(get_elf_header(&elf_Ehdr, p_elfimage))) {
     fprintf(stderr, "Error : file doesn't match expected format.\n");
+    fclose(p_elfimage);
     exit(-1);
   }
 
@@ -522,9 +533,10 @@ int main(int argc, char** argv) {
 
   /* copy the string table into global variable */
   if (StringSec_size > MAX_SIZE_STRING_TABLE) {
-    fprintf(stderr, "Error: section name string table too big (%d > %d);"
+    fprintf(stderr, "Error: section name string table too big (%ld > %d);"
             " increase max. allowed value in source code and recompile\n",
             StringSec_size, MAX_SIZE_STRING_TABLE);
+    fclose(p_elfimage);
     exit(-1);
   }
 
@@ -626,7 +638,7 @@ int main(int argc, char** argv) {
   if (verboselevel >= VERBOSE_LEVEL_MAIN_STEPS) printf("Info: entering action #5 (Jump to firmware/set stack-pointer).\n");
 
   if (verboselevel >= VERBOSE_LEVEL_SECTION_DETAILS)
-    printf("Info: Firmware entry point = 0x%08x, setting stack pointer = 0x%08x.\n", elf_Ehdr.e_entry, stackpointer);
+    printf("Info: Firmware entry point = 0x%08x, setting stack pointer = 0x%08x.\n", (unsigned int)elf_Ehdr.e_entry, stackpointer);
 
   /* Open the special device file. */
   if (!pflag) {
diff --git a/targets/ARCH/EXMIMO/USERSPACE/OCTAVE/OFDM_TX.m b/targets/ARCH/EXMIMO/USERSPACE/OCTAVE/OFDM_TX.m
old mode 100755
new mode 100644
diff --git a/targets/ARCH/EXMIMO/USERSPACE/OCTAVE/OFDM_TX_FRAME.m b/targets/ARCH/EXMIMO/USERSPACE/OCTAVE/OFDM_TX_FRAME.m
old mode 100755
new mode 100644
diff --git a/targets/ARCH/EXMIMO/USERSPACE/OCTAVE/QAM_MOD.m b/targets/ARCH/EXMIMO/USERSPACE/OCTAVE/QAM_MOD.m
old mode 100755
new mode 100644
diff --git a/targets/ARCH/EXMIMO/USERSPACE/OCTAVE/exmimo_test_tx_rx.m b/targets/ARCH/EXMIMO/USERSPACE/OCTAVE/exmimo_test_tx_rx.m
old mode 100755
new mode 100644
diff --git a/targets/ARCH/EXMIMO/USERSPACE/OCTAVE/oarf_send_frame.cc b/targets/ARCH/EXMIMO/USERSPACE/OCTAVE/oarf_send_frame.cc
index 1ebe3aeb4e306784f25d5d5f9430f2a495d9628c..8874b22c5ee4d57509c8213da293359d92d485eb 100644
--- a/targets/ARCH/EXMIMO/USERSPACE/OCTAVE/oarf_send_frame.cc
+++ b/targets/ARCH/EXMIMO/USERSPACE/OCTAVE/oarf_send_frame.cc
@@ -116,7 +116,7 @@ DEFUN_DLD (oarf_send_frame, args, nargout,"Send frame")
     
     for (i=0;i<4;i++) {
       resampling_factor[i] = (openair0_exmimo_pci[card].exmimo_config_ptr)->framing.resampling_factor[i];
-      printf("card %d, ant %d, resampling %d\n",card,i,resampling_factor[i]);
+      printf("card %d, ant %d, resampling %u\n",card,i,resampling_factor[i]);
     }
     
     for (i=0;i<numcols;i++){
diff --git a/targets/ARCH/EXMIMO/USERSPACE/OCTAVE/rx_calibration_exmimo_freq.m b/targets/ARCH/EXMIMO/USERSPACE/OCTAVE/rx_calibration_exmimo_freq.m
old mode 100755
new mode 100644
diff --git a/targets/ARCH/EXMIMO/USERSPACE/OCTAVE/rx_spec.m b/targets/ARCH/EXMIMO/USERSPACE/OCTAVE/rx_spec.m
old mode 100755
new mode 100644
diff --git a/targets/ARCH/EXMIMO/USERSPACE/OCTAVE/rx_spec_multicard_sync.m b/targets/ARCH/EXMIMO/USERSPACE/OCTAVE/rx_spec_multicard_sync.m
old mode 100755
new mode 100644
diff --git a/targets/ARCH/IRIS/USERSPACE/LIB/Makefile.inc b/targets/ARCH/IRIS/USERSPACE/LIB/Makefile.inc
new file mode 100644
index 0000000000000000000000000000000000000000..b79e3cec746031f7e72e56af734d170bb0ce7da7
--- /dev/null
+++ b/targets/ARCH/IRIS/USERSPACE/LIB/Makefile.inc
@@ -0,0 +1,3 @@
+IRIS_OBJ += $(OPENAIR_TARGETS)/ARCH/IRIS/USERSPACE/LIB/iris_lib.o
+IRIS_FILE_OBJ += $(OPENAIR_TARGETS)/ARCH/IRIS/USERSPACE/LIB/iris_lib.cpp
+IRIS_CFLAGS += -I$(OPENAIR_TARGETS)/ARCH/COMMON -I$(OPENAIR_TARGETS)/ARCH/IRIS/USERSPACE/LIB/ -I$(OPENAIR_TARGETS)/COMMON
diff --git a/targets/ARCH/IRIS/USERSPACE/LIB/iris_lib.cpp b/targets/ARCH/IRIS/USERSPACE/LIB/iris_lib.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..5b20d8a8c71be4ba9ea850ff25474e1d8798abd8
--- /dev/null
+++ b/targets/ARCH/IRIS/USERSPACE/LIB/iris_lib.cpp
@@ -0,0 +1,850 @@
+
+/** iris_lib.cpp
+ *
+ * \authors: Rahman Doost-Mohammady : doost@rice.edu
+ * 	    Clay Shepard : cws@rice.edu
+ */
+
+#include <string.h>
+#include <pthread.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <SoapySDR/Device.hpp>
+#include <SoapySDR/Formats.hpp>
+#include <SoapySDR/Time.hpp>
+//#include <boost/format.hpp>
+#include <iostream>
+#include <complex>
+#include <fstream>
+#include <cmath>
+#include <time.h>
+#include <limits>
+#include "common/utils/LOG/log_extern.h"
+#include "common_lib.h"
+#include <chrono>
+
+#ifdef __SSE4_1__
+#  include <smmintrin.h>
+#endif
+
+#ifdef __AVX2__
+#  include <immintrin.h>
+#endif
+
+#define MOVE_DC
+#define SAMPLE_RATE_DOWN 1
+
+/*! \brief Iris Configuration */
+extern "C" {
+  typedef struct {
+
+    // --------------------------------
+    // variables for Iris configuration
+    // --------------------------------
+    //! Iris device pointer
+    std::vector<SoapySDR::Device *> iris;
+    int device_num;
+    int rx_num_channels;
+    int tx_num_channels;
+    //create a send streamer and a receive streamer
+    //! Iris TX Stream
+    std::vector<SoapySDR::Stream *> txStream;
+    //! Iris RX Stream
+    std::vector<SoapySDR::Stream *> rxStream;
+
+    //! Sampling rate
+    double sample_rate;
+
+    //! time offset between transmiter timestamp and receiver timestamp;
+    double tdiff;
+
+    //! TX forward samples.
+    int tx_forward_nsamps; //166 for 20Mhz
+
+
+    // --------------------------------
+    // Debug and output control
+    // --------------------------------
+    //! Number of underflows
+    int num_underflows;
+    //! Number of overflows
+    int num_overflows;
+
+    //! Number of sequential errors
+    int num_seq_errors;
+    //! tx count
+    int64_t tx_count;
+    //! rx count
+    int64_t rx_count;
+    //! timestamp of RX packet
+    openair0_timestamp rx_timestamp;
+
+  } iris_state_t;
+}
+/*! \brief Called to start the Iris lime transceiver. Return 0 if OK, < 0 if error
+    @param device pointer to the device structure specific to the RF hardware target
+*/
+static int trx_iris_start(openair0_device *device) {
+    iris_state_t *s = (iris_state_t *) device->priv;
+
+    long long timeNs = s->iris[0]->getHardwareTime("") + 500000;
+    int flags = 0;
+    //flags |= SOAPY_SDR_HAS_TIME;
+    int r;
+    for (r = 0; r < s->device_num; r++) {
+        int ret = s->iris[r]->activateStream(s->rxStream[r], flags, timeNs, 0);
+        int ret2 = s->iris[r]->activateStream(s->txStream[r]);
+        if (ret < 0 | ret2 < 0)
+            return -1;
+    }
+    return 0;
+}
+
+/*! \brief Stop Iris
+ * \param card refers to the hardware index to use
+ */
+int trx_iris_stop(openair0_device *device) {
+    iris_state_t *s = (iris_state_t *) device->priv;
+    int r;
+    for (r = 0; r < s->device_num; r++) {
+        s->iris[r]->deactivateStream(s->txStream[r]);
+        s->iris[r]->deactivateStream(s->rxStream[r]);
+    }
+    return (0);
+}
+
+/*! \brief Terminate operation of the Iris lime transceiver -- free all associated resources
+ * \param device the hardware to use
+ */
+static void trx_iris_end(openair0_device *device) {
+    LOG_I(HW, "Closing Iris device.\n");
+    trx_iris_stop(device);
+    iris_state_t *s = (iris_state_t *) device->priv;
+    int r;
+    for (r = 0; r < s->device_num; r++) {
+        s->iris[r]->closeStream(s->txStream[r]);
+        s->iris[r]->closeStream(s->rxStream[r]);
+        SoapySDR::Device::unmake(s->iris[r]);
+    }
+}
+
+/*! \brief Called to send samples to the Iris RF target
+      @param device pointer to the device structure specific to the RF hardware target
+      @param timestamp The timestamp at whicch the first sample MUST be sent
+      @param buff Buffer which holds the samples
+      @param nsamps number of samples to be sent
+      @param antenna_id index of the antenna if the device has multiple anteannas
+      @param flags flags must be set to TRUE if timestamp parameter needs to be applied
+*/
+
+
+static int
+trx_iris_write(openair0_device *device, openair0_timestamp timestamp, void **buff, int nsamps, int cc, int flags) {
+    using namespace std::chrono;
+    static long long int loop = 0;
+    static long time_min = 0, time_max = 0, time_avg = 0;
+    struct timespec tp_start, tp_end;
+    long time_diff;
+
+    int ret = 0, ret_i = 0;
+    int flag = 0;
+
+    iris_state_t *s = (iris_state_t *) device->priv;
+    int nsamps2;  // aligned to upper 32 or 16 byte boundary
+#if defined(__x86_64) || defined(__i386__)
+  #ifdef __AVX2__
+    nsamps2 = (nsamps+7)>>3;
+    __m256i buff_tx[2][nsamps2];
+  #else
+    nsamps2 = (nsamps+3)>>2;
+    __m128i buff_tx[2][nsamps2];
+  #endif
+#else
+  #error unsupported CPU architecture, iris device cannot be built
+#endif
+
+    // bring RX data into 12 LSBs for softmodem RX
+    for (int i=0; i<cc; i++) {
+      for (int j=0; j<nsamps2; j++) {
+#if defined(__x86_64__) || defined(__i386__)
+#ifdef __AVX2__
+        buff_tx[i][j] = _mm256_slli_epi16(((__m256i *)buff[i])[j],4);
+#else
+        buff_tx[i][j] = _mm_slli_epi16(((__m128i *)buff[i])[j],4);
+#endif
+#endif
+      }
+    }
+
+    clock_gettime(CLOCK_MONOTONIC_RAW, &tp_start);
+
+    // This hack was added by cws to help keep packets flowing
+
+    if (flags)
+        flag |= SOAPY_SDR_HAS_TIME;
+    else {
+        long long tempHack = s->iris[0]->getHardwareTime("");
+        return nsamps;
+    }
+
+    if (flags == 2 || flags == 1) { // start of burst
+
+    } else if (flags == 3 | flags == 4) {
+        flag |= SOAPY_SDR_END_BURST;
+    }
+
+
+    long long timeNs = SoapySDR::ticksToTimeNs(timestamp, s->sample_rate / SAMPLE_RATE_DOWN);
+    uint32_t *samps[2]; //= (uint32_t **)buff;
+    int r;
+    int m = s->tx_num_channels;
+    for (r = 0; r < s->device_num; r++) {
+        int samples_sent = 0;
+        samps[0] = (uint32_t *) buff_tx[m * r];
+
+        if (cc % 2 == 0)
+            samps[1] = (uint32_t *) buff_tx[m * r + 1]; //cws: it seems another thread can clobber these, so we need to save them locally.
+#ifdef IRIS_DEBUG
+        int i;
+        for (i = 200; i < 216; i++)
+            printf("%d, ",((int16_t)(samps[0][i]>>16))>>4);
+        printf("\n");
+        //printf("\nHardware time before write: %lld, tx_time_stamp: %lld\n", s->iris[0]->getHardwareTime(""), timeNs);
+#endif
+        ret = s->iris[r]->writeStream(s->txStream[r], (void **) samps, (size_t)(nsamps), flag, timeNs, 1000000);
+
+        if (ret < 0)
+            printf("Unable to write stream!\n");
+        else
+            samples_sent = ret;
+
+
+        if (samples_sent != nsamps)
+            printf("[xmit] tx samples %d != %d\n", samples_sent, nsamps);
+
+    }
+
+    return nsamps;
+}
+
+/*! \brief Receive samples from hardware.
+ * Read \ref nsamps samples from each channel to buffers. buff[0] is the array for
+ * the first channel. *ptimestamp is the time at which the first sample
+ * was received.
+ * \param device the hardware to use
+ * \param[out] ptimestamp the time at which the first sample was received.
+ * \param[out] buff An array of pointers to buffers for received samples. The buffers must be large enough to hold the number of samples \ref nsamps.
+ * \param nsamps Number of samples. One sample is 2 byte I + 2 byte Q => 4 byte.
+ * \param antenna_id Index of antenna for which to receive samples
+ * \returns the number of sample read
+*/
+static int trx_iris_read(openair0_device *device, openair0_timestamp *ptimestamp, void **buff, int nsamps, int cc) {
+    int ret = 0;
+    static long long nextTime;
+    static bool nextTimeValid = false;
+    iris_state_t *s = (iris_state_t *) device->priv;
+    bool time_set = false;
+    long long timeNs = 0;
+    int flags;
+    int samples_received;
+    uint32_t *samps[2]; //= (uint32_t **)buff;
+
+    int r;
+    int m = s->rx_num_channels;
+    int nsamps2;  // aligned to upper 32 or 16 byte boundary
+#if defined(__x86_64) || defined(__i386__)
+#ifdef __AVX2__
+    nsamps2 = (nsamps+7)>>3;
+    __m256i buff_tmp[2][nsamps2];
+#else
+    nsamps2 = (nsamps+3)>>2;
+    __m128i buff_tmp[2][nsamps2];
+#endif
+#endif
+
+    for (r = 0; r < s->device_num; r++) {
+        flags = 0;
+        samples_received = 0;
+        samps[0] = (uint32_t *) buff_tmp[m * r];
+        if (cc % 2 == 0)
+            samps[1] = (uint32_t *) buff_tmp[m * r + 1];
+
+        flags = 0;
+        ret = s->iris[r]->readStream(s->rxStream[r], (void **) samps, (size_t)(nsamps), flags,
+                                     timeNs, 1000000);
+        if (ret < 0) {
+            if (ret == SOAPY_SDR_TIME_ERROR)
+                printf("[recv] Time Error in tx stream!\n");
+            else if (ret == SOAPY_SDR_OVERFLOW | (flags & SOAPY_SDR_END_ABRUPT))
+                printf("[recv] Overflow occured!\n");
+            else if (ret == SOAPY_SDR_TIMEOUT)
+                printf("[recv] Timeout occured!\n");
+            else if (ret == SOAPY_SDR_STREAM_ERROR)
+                printf("[recv] Stream (tx) error occured!\n");
+            else if (ret == SOAPY_SDR_CORRUPTION)
+                printf("[recv] Bad packet occured!\n");
+            break;
+        } else
+            samples_received = ret;
+
+
+        if (r == 0) {
+            if (samples_received == ret) // first batch
+            {
+                if (flags & SOAPY_SDR_HAS_TIME) {
+                    s->rx_timestamp = SoapySDR::timeNsToTicks(timeNs, s->sample_rate / SAMPLE_RATE_DOWN);
+                    *ptimestamp = s->rx_timestamp;
+                    nextTime = timeNs;
+                    nextTimeValid = true;
+                    time_set = true;
+                    //printf("1) time set %llu \n", *ptimestamp);
+                }
+            }
+        }
+
+        if (r == 0) {
+            if (samples_received == nsamps) {
+
+                if (flags & SOAPY_SDR_HAS_TIME) {
+                    s->rx_timestamp = SoapySDR::timeNsToTicks(nextTime, s->sample_rate / SAMPLE_RATE_DOWN);
+                    *ptimestamp = s->rx_timestamp;
+                    nextTime = timeNs;
+                    nextTimeValid = true;
+                    time_set = true;
+                }
+            } else if (samples_received < nsamps)
+                printf("[recv] received %d samples out of %d\n", samples_received, nsamps);
+
+            s->rx_count += samples_received;
+
+            if (s->sample_rate != 0 && nextTimeValid) {
+                if (!time_set) {
+                    s->rx_timestamp = SoapySDR::timeNsToTicks(nextTime, s->sample_rate / SAMPLE_RATE_DOWN);
+                    *ptimestamp = s->rx_timestamp;
+                    //printf("2) time set %llu, nextTime will be %llu \n", *ptimestamp, nextTime);
+                }
+                nextTime += SoapySDR::ticksToTimeNs(samples_received, s->sample_rate / SAMPLE_RATE_DOWN);
+            }
+        }
+
+        // bring RX data into 12 LSBs for softmodem RX
+        for (int i=0; i<cc; i++) {
+          for (int j=0; j<nsamps2; j++) {
+#if defined(__x86_64__) || defined(__i386__)
+#ifdef   __AVX2__
+            ((__m256i *)buff[i])[j] = _mm256_srai_epi16(buff_tmp[i][j],4);
+#else
+            ((__m128i *)buff[i])[j] = _mm_srai_epi16(buff_tmp[i][j],4);
+#endif
+#endif
+          }
+        }
+    }
+    return samples_received;
+}
+
+/*! \brief Get current timestamp of Iris
+ * \param device the hardware to use
+*/
+openair0_timestamp get_iris_time(openair0_device *device) {
+    iris_state_t *s = (iris_state_t *) device->priv;
+    return SoapySDR::timeNsToTicks(s->iris[0]->getHardwareTime(""), s->sample_rate);
+}
+
+/*! \brief Compares two variables within precision
+ * \param a first variable
+ * \param b second variable
+*/
+static bool is_equal(double a, double b) {
+    return std::fabs(a - b) < std::numeric_limits<double>::epsilon();
+}
+
+void *set_freq_thread(void *arg) {
+
+    openair0_device *device = (openair0_device *) arg;
+    iris_state_t *s = (iris_state_t *) device->priv;
+    int r, i;
+    printf("Setting Iris TX Freq %f, RX Freq %f\n", device->openair0_cfg[0].tx_freq[0],
+           device->openair0_cfg[0].rx_freq[0]);
+    // add check for the number of channels in the cfg
+    for (r = 0; r < s->device_num; r++) {
+        for (i = 0; i < s->iris[r]->getNumChannels(SOAPY_SDR_RX); i++) {
+            if (i < s->rx_num_channels)
+                s->iris[r]->setFrequency(SOAPY_SDR_RX, i, "RF", device->openair0_cfg[0].rx_freq[i]);
+        }
+        for (i = 0; i < s->iris[r]->getNumChannels(SOAPY_SDR_TX); i++) {
+            if (i < s->tx_num_channels)
+                s->iris[r]->setFrequency(SOAPY_SDR_TX, i, "RF", device->openair0_cfg[0].tx_freq[i]);
+        }
+    }
+}
+
+/*! \brief Set frequencies (TX/RX)
+ * \param device the hardware to use
+ * \param openair0_cfg RF frontend parameters set by application
+ * \param dummy dummy variable not used
+ * \returns 0 in success
+ */
+int trx_iris_set_freq(openair0_device *device, openair0_config_t *openair0_cfg, int dont_block) {
+    iris_state_t *s = (iris_state_t *) device->priv;
+    pthread_t f_thread;
+    if (dont_block)
+        pthread_create(&f_thread, NULL, set_freq_thread, (void *) device);
+    else {
+        int r, i;
+        for (r = 0; r < s->device_num; r++) {
+            printf("Setting Iris TX Freq %f, RX Freq %f\n", openair0_cfg[0].tx_freq[0], openair0_cfg[0].rx_freq[0]);
+            for (i = 0; i < s->iris[r]->getNumChannels(SOAPY_SDR_RX); i++) {
+                if (i < s->rx_num_channels) {
+                    s->iris[r]->setFrequency(SOAPY_SDR_RX, i, "RF", openair0_cfg[0].rx_freq[i]);
+                }
+            }
+            for (i = 0; i < s->iris[r]->getNumChannels(SOAPY_SDR_TX); i++) {
+                if (i < s->tx_num_channels) {
+                    s->iris[r]->setFrequency(SOAPY_SDR_TX, i, "RF", openair0_cfg[0].tx_freq[i]);
+                }
+            }
+        }
+    }
+    return (0);
+}
+
+
+/*! \brief Set Gains (TX/RX)
+ * \param device the hardware to use
+ * \param openair0_cfg RF frontend parameters set by application
+ * \returns 0 in success
+ */
+int trx_iris_set_gains(openair0_device *device,
+                       openair0_config_t *openair0_cfg) {
+    iris_state_t *s = (iris_state_t *) device->priv;
+    int r;
+    for (r = 0; r < s->device_num; r++) {
+        s->iris[r]->setGain(SOAPY_SDR_RX, 0, openair0_cfg[0].rx_gain[0]);
+        s->iris[r]->setGain(SOAPY_SDR_TX, 0, openair0_cfg[0].tx_gain[0]);
+        s->iris[r]->setGain(SOAPY_SDR_RX, 1, openair0_cfg[0].rx_gain[1]);
+        s->iris[r]->setGain(SOAPY_SDR_TX, 1, openair0_cfg[0].tx_gain[1]);
+    }
+    return (0);
+}
+
+/*! \brief Iris RX calibration table */
+rx_gain_calib_table_t calib_table_iris[] = {
+        {3500000000.0, 83},
+        {2660000000.0, 83},
+        {2580000000.0, 83},
+        {2300000000.0, 83},
+        {1880000000.0, 83},
+        {816000000.0,  83},
+        {-1,           0}};
+
+
+/*! \brief Set RX gain offset
+ * \param openair0_cfg RF frontend parameters set by application
+ * \param chain_index RF chain to apply settings to
+ * \returns 0 in success
+ */
+void set_rx_gain_offset(openair0_config_t *openair0_cfg, int chain_index, int bw_gain_adjust) {
+
+    int i = 0;
+    // loop through calibration table to find best adjustment factor for RX frequency
+    double min_diff = 6e9, diff, gain_adj = 0.0;
+    if (bw_gain_adjust == 1) {
+        switch ((int) openair0_cfg[0].sample_rate) {
+            case 30720000:
+                break;
+            case 23040000:
+                gain_adj = 1.25;
+                break;
+            case 15360000:
+                gain_adj = 3.0;
+                break;
+            case 7680000:
+                gain_adj = 6.0;
+                break;
+            case 3840000:
+                gain_adj = 9.0;
+                break;
+            case 1920000:
+                gain_adj = 12.0;
+                break;
+            default:
+                printf("unknown sampling rate %d\n", (int) openair0_cfg[0].sample_rate);
+                exit(-1);
+                break;
+        }
+    }
+
+    while (openair0_cfg->rx_gain_calib_table[i].freq > 0) {
+        diff = fabs(openair0_cfg->rx_freq[chain_index] - openair0_cfg->rx_gain_calib_table[i].freq);
+        printf("cal %d: freq %f, offset %f, diff %f\n",
+               i,
+               openair0_cfg->rx_gain_calib_table[i].freq,
+               openair0_cfg->rx_gain_calib_table[i].offset, diff);
+        if (min_diff > diff) {
+            min_diff = diff;
+            openair0_cfg->rx_gain_offset[chain_index] = openair0_cfg->rx_gain_calib_table[i].offset + gain_adj;
+        }
+        i++;
+    }
+
+}
+
+/*! \brief print the Iris statistics
+* \param device the hardware to use
+* \returns  0 on success
+*/
+int trx_iris_get_stats(openair0_device *device) {
+
+    return (0);
+
+}
+
+/*! \brief Reset the Iris statistics
+* \param device the hardware to use
+* \returns  0 on success
+*/
+int trx_iris_reset_stats(openair0_device *device) {
+
+    return (0);
+
+}
+
+
+extern "C" {
+/*! \brief Initialize Openair Iris target. It returns 0 if OK
+* \param device the hardware to use
+* \param openair0_cfg RF frontend parameters set by application
+*/
+int device_init(openair0_device *device, openair0_config_t *openair0_cfg) {
+
+    size_t i, r, card;
+    int bw_gain_adjust = 0;
+    openair0_cfg[0].rx_gain_calib_table = calib_table_iris;
+    iris_state_t *s = (iris_state_t *) malloc(sizeof(iris_state_t));
+    memset(s, 0, sizeof(iris_state_t));
+
+    std::string devFE("DEV");
+    std::string cbrsFE("CBRS");
+    std::string wireFormat("WIRE");
+
+    // Initialize Iris device
+    device->openair0_cfg = openair0_cfg;
+    SoapySDR::Kwargs args;
+    args["driver"] = "iris";
+    char *iris_addrs = device->openair0_cfg[0].sdr_addrs;
+    if (iris_addrs == NULL)
+    {
+        s->iris.push_back(SoapySDR::Device::make(args));
+    }
+    else
+    {
+        char *serial = strtok(iris_addrs, ",");
+        while (serial != NULL) {
+            LOG_I(HW, "Attempting to open Iris device %s\n", serial);
+            args["serial"] = serial;
+            s->iris.push_back(SoapySDR::Device::make(args));
+            serial = strtok(NULL, ",");
+        }
+    }
+
+    s->device_num = s->iris.size();
+    device->type = IRIS_DEV;
+
+
+    switch ((int) openair0_cfg[0].sample_rate) {
+        case 30720000:
+            //openair0_cfg[0].samples_per_packet    = 1024;
+            openair0_cfg[0].tx_sample_advance = 115;
+            openair0_cfg[0].tx_bw = 20e6;
+            openair0_cfg[0].rx_bw = 20e6;
+            break;
+        case 23040000:
+            //openair0_cfg[0].samples_per_packet    = 1024;
+            openair0_cfg[0].tx_sample_advance = 113;
+            openair0_cfg[0].tx_bw = 15e6;
+            openair0_cfg[0].rx_bw = 15e6;
+            break;
+        case 15360000:
+            //openair0_cfg[0].samples_per_packet    = 1024;
+            openair0_cfg[0].tx_sample_advance = 60;
+            openair0_cfg[0].tx_bw = 10e6;
+            openair0_cfg[0].rx_bw = 10e6;
+            break;
+        case 7680000:
+            //openair0_cfg[0].samples_per_packet    = 1024;
+            openair0_cfg[0].tx_sample_advance = 30;
+            openair0_cfg[0].tx_bw = 5e6;
+            openair0_cfg[0].rx_bw = 5e6;
+            break;
+        case 1920000:
+            //openair0_cfg[0].samples_per_packet    = 1024;
+            openair0_cfg[0].tx_sample_advance = 20;
+            openair0_cfg[0].tx_bw = 1.4e6;
+            openair0_cfg[0].rx_bw = 1.4e6;
+            break;
+        default:
+            printf("Error: unknown sampling rate %f\n", openair0_cfg[0].sample_rate);
+            exit(-1);
+            break;
+    }
+
+    printf("tx_sample_advance %d\n", openair0_cfg[0].tx_sample_advance);
+    s->rx_num_channels = openair0_cfg[0].rx_num_channels;
+    s->tx_num_channels = openair0_cfg[0].tx_num_channels;
+    if ((s->rx_num_channels == 1 || s->rx_num_channels == 2) && (s->tx_num_channels == 1 || s->tx_num_channels == 2))
+        printf("Enabling %d rx and %d tx channel(s) on each device...\n", s->rx_num_channels, s->tx_num_channels);
+    else {
+        printf("Invalid rx or tx number of channels (%d, %d)\n", s->rx_num_channels, s->tx_num_channels);
+        exit(-1);
+    }
+
+    for (r = 0; r < s->device_num; r++) {
+        //this is unnecessary -- it will set the correct master clock based on sample rate
+        /*switch ((int) openair0_cfg[0].sample_rate) {
+            case 1920000:
+                s->iris[r]->setMasterClockRate(256 * openair0_cfg[0].sample_rate);
+                break;
+            case 3840000:
+                s->iris[r]->setMasterClockRate(128 * openair0_cfg[0].sample_rate);
+                break;
+            case 7680000:
+                s->iris[r]->setMasterClockRate(64 * openair0_cfg[0].sample_rate);
+                break;
+            case 15360000:
+                s->iris[r]->setMasterClockRate(32 * openair0_cfg[0].sample_rate);
+                break;
+            case 30720000:
+                s->iris[r]->setMasterClockRate(16 * openair0_cfg[0].sample_rate);
+                break;
+            default:
+                printf("Error: unknown sampling rate %f\n", openair0_cfg[0].sample_rate);
+                exit(-1);
+                break;
+        }*/
+
+        for (i = 0; i < s->iris[r]->getNumChannels(SOAPY_SDR_RX); i++) {
+            if (i < s->rx_num_channels) {
+                s->iris[r]->setSampleRate(SOAPY_SDR_RX, i, openair0_cfg[0].sample_rate / SAMPLE_RATE_DOWN);
+#ifdef MOVE_DC
+                printf("Moving DC out of main carrier for rx...\n");
+                s->iris[r]->setFrequency(SOAPY_SDR_RX, i, "RF", openair0_cfg[0].rx_freq[i]-.75*openair0_cfg[0].sample_rate);
+                s->iris[r]->setFrequency(SOAPY_SDR_RX, i, "BB", .75*openair0_cfg[0].sample_rate);
+#else
+                s->iris[r]->setFrequency(SOAPY_SDR_RX, i, "RF", openair0_cfg[0].rx_freq[i]);
+#endif
+
+                set_rx_gain_offset(&openair0_cfg[0], i, bw_gain_adjust);
+                //s->iris[r]->setGain(SOAPY_SDR_RX, i, openair0_cfg[0].rx_gain[i] - openair0_cfg[0].rx_gain_offset[i]);
+                printf("rx gain offset: %f, rx_gain: %f, tx_tgain: %f\n", openair0_cfg[0].rx_gain_offset[i], openair0_cfg[0].rx_gain[i], openair0_cfg[0].tx_gain[i]);
+                if (s->iris[r]->getHardwareInfo()["frontend"].compare(devFE) != 0) {
+                    s->iris[r]->setGain(SOAPY_SDR_RX, i, "LNA", openair0_cfg[0].rx_gain[i] - openair0_cfg[0].rx_gain_offset[i]);
+                    //s->iris[r]->setGain(SOAPY_SDR_RX, i, "LNA", 0);
+                    s->iris[r]->setGain(SOAPY_SDR_RX, i, "LNA1", 30);
+                    s->iris[r]->setGain(SOAPY_SDR_RX, i, "LNA2", 17);
+                    s->iris[r]->setGain(SOAPY_SDR_RX, i, "TIA", 7);
+                    s->iris[r]->setGain(SOAPY_SDR_RX, i, "PGA", 18);
+                    s->iris[r]->setGain(SOAPY_SDR_RX, i, "ATTN", 0);
+                } else {
+                    s->iris[r]->setGain(SOAPY_SDR_RX, i, "LNA", openair0_cfg[0].rx_gain[i] - openair0_cfg[0].rx_gain_offset[i]); //  [0,30]
+                    s->iris[r]->setGain(SOAPY_SDR_RX, i, "TIA", 7);  // [0,12,6]
+                    s->iris[r]->setGain(SOAPY_SDR_RX, i, "PGA", 18);  // [-12,19,1]
+                    //s->iris[r]->setGain(SOAPY_SDR_RX, i, 50);    // [-12,19,1]
+
+                }
+
+                s->iris[r]->setDCOffsetMode(SOAPY_SDR_RX, i, true); // move somewhere else
+            }
+        }
+        for (i = 0; i < s->iris[r]->getNumChannels(SOAPY_SDR_TX); i++) {
+            if (i < s->tx_num_channels) {
+                s->iris[r]->setSampleRate(SOAPY_SDR_TX, i, openair0_cfg[0].sample_rate / SAMPLE_RATE_DOWN);
+#ifdef MOVE_DC
+                printf("Moving DC out of main carrier for tx...\n");
+                s->iris[r]->setFrequency(SOAPY_SDR_TX, i, "RF", openair0_cfg[0].tx_freq[i]-.75*openair0_cfg[0].sample_rate);
+                s->iris[r]->setFrequency(SOAPY_SDR_TX, i, "BB", .75*openair0_cfg[0].sample_rate);
+#else
+                s->iris[r]->setFrequency(SOAPY_SDR_TX, i, "RF", openair0_cfg[0].tx_freq[i]);
+#endif
+
+                if (s->iris[r]->getHardwareInfo()["frontend"].compare(devFE) == 0) {
+                    s->iris[r]->setGain(SOAPY_SDR_TX, i, "PAD", openair0_cfg[0].tx_gain[i]);
+                    //s->iris[r]->setGain(SOAPY_SDR_TX, i, "PAD", 50);
+                    s->iris[r]->setGain(SOAPY_SDR_TX, i, "IAMP", 12);
+                    //s->iris[r]->writeSetting("TX_ENABLE_DELAY", "0");
+                    //s->iris[r]->writeSetting("TX_DISABLE_DELAY", "100");
+                } else {
+                    s->iris[r]->setGain(SOAPY_SDR_TX, i, "PAD", openair0_cfg[0].tx_gain[i]);
+                    s->iris[r]->setGain(SOAPY_SDR_TX, i, "ATTN", 0); // [-18, 0, 6] dB
+                    s->iris[r]->setGain(SOAPY_SDR_TX, i, "IAMP", 6); // [-12, 12, 1] dB
+                    //s->iris[r]->setGain(SOAPY_SDR_TX, i, "PAD", 44); //openair0_cfg[0].tx_gain[i]);
+                    //s->iris[r]->setGain(SOAPY_SDR_TX, i, "PAD", 35); // [0, 52, 1] dB
+                    //s->iris[r]->setGain(SOAPY_SDR_TX, i, "PA1", 17); // 17 ??? dB
+                    s->iris[r]->setGain(SOAPY_SDR_TX, i, "PA2", 0); // [0, 17, 17] dB
+                    //s->iris[r]->setGain(SOAPY_SDR_TX, i, "PA3", 20); // 33 ??? dB
+                    s->iris[r]->writeSetting("TX_ENABLE_DELAY", "0");
+                    s->iris[r]->writeSetting("TX_DISABLE_DELAY", "100");
+                }
+
+//                if (openair0_cfg[0].duplex_mode == 0) {
+//                    printf("\nFDD: Enable TX antenna override\n");
+//                    s->iris[r]->writeSetting(SOAPY_SDR_TX, i, "TX_ENB_OVERRIDE",
+//                                             "true"); // From Josh: forces tx switching to be on always transmit regardless of bursts
+//                }
+            }
+        }
+
+
+
+        printf("Actual master clock: %fMHz...\n", (s->iris[r]->getMasterClockRate() / 1e6));
+
+        int tx_filt_bw = openair0_cfg[0].tx_bw;
+        int rx_filt_bw = openair0_cfg[0].rx_bw;
+#ifdef MOVE_DC  //the filter is centered around the carrier, so we have to expand it if we have moved the DC tone.
+        tx_filt_bw *= 3;
+        rx_filt_bw *= 3;
+#endif
+        /* Setting TX/RX BW */
+        for (i = 0; i < s->tx_num_channels; i++) {
+            if (i < s->iris[r]->getNumChannels(SOAPY_SDR_TX)) {
+                s->iris[r]->setBandwidth(SOAPY_SDR_TX, i, tx_filt_bw);
+                printf("Setting tx bandwidth on channel %zu/%lu: BW %f (readback %f)\n", i,
+                       s->iris[r]->getNumChannels(SOAPY_SDR_TX), tx_filt_bw / 1e6,
+                       s->iris[r]->getBandwidth(SOAPY_SDR_TX, i) / 1e6);
+            }
+        }
+        for (i = 0; i < s->rx_num_channels; i++) {
+            if (i < s->iris[r]->getNumChannels(SOAPY_SDR_RX)) {
+                s->iris[r]->setBandwidth(SOAPY_SDR_RX, i, rx_filt_bw);
+                printf("Setting rx bandwidth on channel %zu/%lu : BW %f (readback %f)\n", i,
+                       s->iris[r]->getNumChannels(SOAPY_SDR_RX), rx_filt_bw / 1e6,
+                       s->iris[r]->getBandwidth(SOAPY_SDR_RX, i) / 1e6);
+            }
+        }
+
+        for (i = 0; i < s->iris[r]->getNumChannels(SOAPY_SDR_TX); i++) {
+            if (i < s->tx_num_channels) {
+                printf("\nUsing SKLK calibration...\n");
+                s->iris[r]->writeSetting(SOAPY_SDR_TX, i, "CALIBRATE", "SKLK");
+
+            }
+
+        }
+
+        for (i = 0; i < s->iris[r]->getNumChannels(SOAPY_SDR_RX); i++) {
+            if (i < s->rx_num_channels) {
+                printf("\nUsing SKLK calibration...\n");
+                s->iris[r]->writeSetting(SOAPY_SDR_RX, i, "CALIBRATE", "SKLK");
+
+            }
+
+        }
+
+        if (s->iris[r]->getHardwareInfo()["frontend"].compare(devFE) == 0) {
+            for (i = 0; i < s->iris[r]->getNumChannels(SOAPY_SDR_RX); i++) {
+                if (openair0_cfg[0].duplex_mode == 0) {
+                    printf("\nFDD: Setting receive antenna to %s\n", s->iris[r]->listAntennas(SOAPY_SDR_RX, i)[1].c_str());
+                    if (i < s->rx_num_channels)
+                        s->iris[r]->setAntenna(SOAPY_SDR_RX, i, "RX");
+                } else {
+                    printf("\nTDD: Setting receive antenna to %s\n", s->iris[r]->listAntennas(SOAPY_SDR_RX, i)[0].c_str());
+                    if (i < s->rx_num_channels)
+                        s->iris[r]->setAntenna(SOAPY_SDR_RX, i, "TRX");
+                }
+            }
+        }
+
+
+        //s->iris[r]->writeSetting("TX_SW_DELAY", std::to_string(
+        //        -openair0_cfg[0].tx_sample_advance)); //should offset switching to compensate for RF path (Lime) delay -- this will eventually be automated
+
+        // create tx & rx streamer
+        //const SoapySDR::Kwargs &arg = SoapySDR::Kwargs();
+        std::map <std::string, std::string> rxStreamArgs;
+        rxStreamArgs["WIRE"] = SOAPY_SDR_CS16;
+
+        std::vector <size_t> channels;
+        for (i = 0; i < s->rx_num_channels; i++)
+            if (i < s->iris[r]->getNumChannels(SOAPY_SDR_RX))
+                channels.push_back(i);
+        s->rxStream.push_back(s->iris[r]->setupStream(SOAPY_SDR_RX, SOAPY_SDR_CS16, channels));//, rxStreamArgs));
+
+        std::vector <size_t> tx_channels = {};
+        for (i = 0; i < s->tx_num_channels; i++)
+            if (i < s->iris[r]->getNumChannels(SOAPY_SDR_TX))
+                tx_channels.push_back(i);
+        s->txStream.push_back(s->iris[r]->setupStream(SOAPY_SDR_TX, SOAPY_SDR_CS16, tx_channels)); //, arg));
+        //s->iris[r]->setHardwareTime(0, "");
+
+        std::cout << "Front end detected: " << s->iris[r]->getHardwareInfo()["frontend"] << "\n";
+        for (i = 0; i < s->rx_num_channels; i++) {
+            if (i < s->iris[r]->getNumChannels(SOAPY_SDR_RX)) {
+                printf("RX Channel %zu\n", i);
+                printf("Actual RX sample rate: %fMSps...\n", (s->iris[r]->getSampleRate(SOAPY_SDR_RX, i) / 1e6));
+                printf("Actual RX frequency: %fGHz...\n", (s->iris[r]->getFrequency(SOAPY_SDR_RX, i) / 1e9));
+                printf("Actual RX gain: %f...\n", (s->iris[r]->getGain(SOAPY_SDR_RX, i)));
+                printf("Actual RX LNA gain: %f...\n", (s->iris[r]->getGain(SOAPY_SDR_RX, i, "LNA")));
+                printf("Actual RX PGA gain: %f...\n", (s->iris[r]->getGain(SOAPY_SDR_RX, i, "PGA")));
+                printf("Actual RX TIA gain: %f...\n", (s->iris[r]->getGain(SOAPY_SDR_RX, i, "TIA")));
+                if (s->iris[r]->getHardwareInfo()["frontend"].compare(devFE) != 0) {
+                    printf("Actual RX LNA1 gain: %f...\n", (s->iris[r]->getGain(SOAPY_SDR_RX, i, "LNA1")));
+                    printf("Actual RX LNA2 gain: %f...\n", (s->iris[r]->getGain(SOAPY_SDR_RX, i, "LNA2")));
+                }
+                printf("Actual RX bandwidth: %fM...\n", (s->iris[r]->getBandwidth(SOAPY_SDR_RX, i) / 1e6));
+                printf("Actual RX antenna: %s...\n", (s->iris[r]->getAntenna(SOAPY_SDR_RX, i).c_str()));
+            }
+        }
+
+        for (i = 0; i < s->tx_num_channels; i++) {
+            if (i < s->iris[r]->getNumChannels(SOAPY_SDR_TX)) {
+                printf("TX Channel %zu\n", i);
+                printf("Actual TX sample rate: %fMSps...\n", (s->iris[r]->getSampleRate(SOAPY_SDR_TX, i) / 1e6));
+                printf("Actual TX frequency: %fGHz...\n", (s->iris[r]->getFrequency(SOAPY_SDR_TX, i) / 1e9));
+                printf("Actual TX gain: %f...\n", (s->iris[r]->getGain(SOAPY_SDR_TX, i)));
+                printf("Actual TX PAD gain: %f...\n", (s->iris[r]->getGain(SOAPY_SDR_TX, i, "PAD")));
+                printf("Actual TX IAMP gain: %f...\n", (s->iris[r]->getGain(SOAPY_SDR_TX, i, "IAMP")));
+                if (s->iris[r]->getHardwareInfo()["frontend"].compare(devFE) != 0) {
+                    printf("Actual TX PA1 gain: %f...\n", (s->iris[r]->getGain(SOAPY_SDR_TX, i, "PA1")));
+                    printf("Actual TX PA2 gain: %f...\n", (s->iris[r]->getGain(SOAPY_SDR_TX, i, "PA2")));
+                    printf("Actual TX PA3 gain: %f...\n", (s->iris[r]->getGain(SOAPY_SDR_TX, i, "PA3")));
+                }
+                printf("Actual TX bandwidth: %fM...\n", (s->iris[r]->getBandwidth(SOAPY_SDR_TX, i) / 1e6));
+                printf("Actual TX antenna: %s...\n", (s->iris[r]->getAntenna(SOAPY_SDR_TX, i).c_str()));
+            }
+        }
+    }
+    s->iris[0]->writeSetting("SYNC_DELAYS", "");
+    for (r = 0; r < s->device_num; r++)
+        s->iris[r]->setHardwareTime(0, "TRIGGER");
+    s->iris[0]->writeSetting("TRIGGER_GEN", "");
+    for (r = 0; r < s->device_num; r++)
+        printf("Device timestamp: %f...\n", (s->iris[r]->getHardwareTime("TRIGGER") / 1e9));
+
+    device->priv = s;
+    device->trx_start_func = trx_iris_start;
+    device->trx_write_func = trx_iris_write;
+    device->trx_read_func = trx_iris_read;
+    device->trx_get_stats_func = trx_iris_get_stats;
+    device->trx_reset_stats_func = trx_iris_reset_stats;
+    device->trx_end_func = trx_iris_end;
+    device->trx_stop_func = trx_iris_stop;
+    device->trx_set_freq_func = trx_iris_set_freq;
+    device->trx_set_gains_func = trx_iris_set_gains;
+    device->openair0_cfg = openair0_cfg;
+
+    s->sample_rate = openair0_cfg[0].sample_rate;
+    // TODO:
+    // init tx_forward_nsamps based iris_time_offset ex
+    if (is_equal(s->sample_rate, (double) 30.72e6))
+        s->tx_forward_nsamps = 176;
+    if (is_equal(s->sample_rate, (double) 15.36e6))
+        s->tx_forward_nsamps = 90;
+    if (is_equal(s->sample_rate, (double) 7.68e6))
+        s->tx_forward_nsamps = 50;
+
+    LOG_I(HW, "Finished initializing %d Iris device(s).\n", s->device_num);
+    fflush(stdout);
+    return 0;
+}
+}
+/*@}*/
diff --git a/targets/ARCH/LMSSDR/LimeSDR_above_1p8GHz.ini b/targets/ARCH/LMSSDR/LimeSDR_above_1p8GHz.ini
old mode 100755
new mode 100644
diff --git a/targets/ARCH/LMSSDR/LimeSDR_above_1p8GHz_1v4.ini b/targets/ARCH/LMSSDR/LimeSDR_above_1p8GHz_1v4.ini
old mode 100755
new mode 100644
diff --git a/targets/ARCH/LMSSDR/LimeSDR_below_1p8GHz.ini b/targets/ARCH/LMSSDR/LimeSDR_below_1p8GHz.ini
old mode 100755
new mode 100644
diff --git a/targets/ARCH/LMSSDR/LimeSDR_below_1p8GHz_1v4.ini b/targets/ARCH/LMSSDR/LimeSDR_below_1p8GHz_1v4.ini
old mode 100755
new mode 100644
diff --git a/targets/ARCH/LMSSDR/USERSPACE/LIB/lms_lib.cpp b/targets/ARCH/LMSSDR/USERSPACE/LIB/lms_lib.cpp
index e1a1b768b27cb1413a67cbe6fb54fdea4753d098..1f0d78aba597575278293c9f4d70e17090c8f932 100644
--- a/targets/ARCH/LMSSDR/USERSPACE/LIB/lms_lib.cpp
+++ b/targets/ARCH/LMSSDR/USERSPACE/LIB/lms_lib.cpp
@@ -193,7 +193,7 @@ int trx_lms_start(openair0_device *device){
         LMS_EnableChannel(lms_device,LMS_CH_RX,1,true);
         LMS_EnableChannel(lms_device,LMS_CH_TX,1,true);
     } */
-    LMS_VCTCXOWrite(lms_device,129);
+    LMS_VCTCXOWrite(lms_device,129, true);
 
     if (LMS_SetSampleRate(lms_device,device->openair0_cfg->sample_rate,2)!=0)
     {
diff --git a/targets/ARCH/USRP/USERSPACE/LIB/Makefile.inc b/targets/ARCH/USRP/USERSPACE/LIB/Makefile.inc
deleted file mode 100644
index 631f2162bdb545a125e689dfe7c90773ea91d8d8..0000000000000000000000000000000000000000
--- a/targets/ARCH/USRP/USERSPACE/LIB/Makefile.inc
+++ /dev/null
@@ -1,4 +0,0 @@
-USRP_OBJ += $(OPENAIR_TARGETS)/ARCH/USRP/USERSPACE/LIB/usrp_lib.o
-USRP_FILE_OBJ += $(OPENAIR_TARGETS)/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp
-USRP_CFLAGS += -I$(OPENAIR_TARGETS)/ARCH/COMMON -I$(OPENAIR_TARGETS)/ARCH/USRP/USERSPACE/LIB/ -I$(OPENAIR_TARGETS)/COMMON
-
diff --git a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp
index c591cc6c0f31f2f324e2b3f09ad899313b7ab46f..b222ad4d2d2867f281ed5e45598006496628829a 100644
--- a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp
+++ b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp
@@ -346,6 +346,7 @@ static void trx_usrp_end(openair0_device *device) {
 
   done = 1;
 
+
   if (u_sf_mode != 2) { // not subframes replay
 #endif
     usrp_state_t *s = (usrp_state_t *)device->priv;
@@ -435,17 +436,20 @@ static int trx_usrp_write(openair0_device *device, openair0_timestamp timestamp,
 #endif
     usrp_state_t *s = (usrp_state_t *)device->priv;
     int nsamps2;  // aligned to upper 32 or 16 byte boundary
+
 #if defined(__x86_64) || defined(__i386__)
-#ifdef __AVX2__
-    nsamps2 = (nsamps+7)>>3;
-    __m256i buff_tx[2][nsamps2];
-#else
+  #ifdef __AVX2__
+      nsamps2 = (nsamps+7)>>3;
+      __m256i buff_tx[2][nsamps2];
+  #else
     nsamps2 = (nsamps+3)>>2;
     __m128i buff_tx[2][nsamps2];
-#endif
+  #endif
 #elif defined(__arm__)
     nsamps2 = (nsamps+3)>>2;
     int16x8_t buff_tx[2][nsamps2];
+#else
+    #error Unsupported CPU architecture, USRP device cannot be built
 #endif
 
     // bring RX data into 12 LSBs for softmodem RX
diff --git a/targets/ARCH/tcp_bridge/tcp_bridge_oai.c b/targets/ARCH/tcp_bridge/tcp_bridge_oai.c
index 32fddb9c2dcffcb811fdbe4136c3da45fa5e0be0..a7bb8c00bfaeb50ab737c150c3f78092b70752b8 100644
--- a/targets/ARCH/tcp_bridge/tcp_bridge_oai.c
+++ b/targets/ARCH/tcp_bridge/tcp_bridge_oai.c
@@ -8,33 +8,47 @@
 #include <unistd.h>
 #include <errno.h>
 
-int fullread(int fd, void *_buf, int count)
-{
+const int port = 4043;
+#define helpTxt "\
+\x1b[31m\
+tcp_bridge: error: you have to run one UE and one eNB\n\
+For this, export TCPBRIDGE=enb (eNB case) or \n\
+                 TCPBRIDGE=<an ip address> (UE case)\n\
+\x1b[m"
+
+int fullread(int fd, void *_buf, int count) {
   char *buf = _buf;
   int ret = 0;
   int l;
+
   while (count) {
     l = read(fd, buf, count);
+
     if (l <= 0) return -1;
+
     count -= l;
     buf += l;
     ret += l;
   }
+
   return ret;
 }
 
-int fullwrite(int fd, void *_buf, int count)
-{
+int fullwrite(int fd, void *_buf, int count) {
   char *buf = _buf;
   int ret = 0;
   int l;
+
   while (count) {
     l = write(fd, buf, count);
+
     if (l <= 0) return -1;
+
     count -= l;
     buf += l;
     ret += l;
   }
+
   return ret;
 }
 
@@ -46,155 +60,208 @@ typedef struct {
   uint64_t timestamp;
   uint64_t next_tx_timestamp;
   int is_enb;
+  char *ip;
 } tcp_bridge_state_t;
 
-void verify_connection(int fd, int is_enb)
-{
+void verify_connection(int fd, int is_enb) {
   char c = is_enb;
+
   if (fullwrite(fd, &c, 1) != 1) exit(1);
+
   if (fullread(fd, &c, 1) != 1) exit(1);
+
   if (c == is_enb) {
-    printf("\x1b[31mtcp_bridge: error: you have to run one UE and one eNB"
-           " (did you run 'export ENODEB=1' in the eNB terminal?)\x1b[m\n");
+    printf(helpTxt);
     exit(1);
   }
 }
 
-int tcp_bridge_start(openair0_device *device)
-{
-  int port = 4043;
-  tcp_bridge_state_t *tcp_bridge = device->priv;
-  int try;
-  int max_try = 5;
-
-  int sock = socket(AF_INET, SOCK_STREAM, 0);
-  if (sock == -1) { perror("tcp_bridge: socket"); exit(1); }
-
-  int enable = 1;
-  if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)))
-    { perror("tcp_bridge: SO_REUSEADDR"); exit(1); }
 
+int start_enb(tcp_bridge_state_t *tcp_bridge) {
   struct sockaddr_in addr = {
-    sin_family: AF_INET,
-    sin_port: htons(port),
-    sin_addr: { s_addr: INADDR_ANY }
+sin_family:
+    AF_INET,
+sin_port:
+    htons(port),
+sin_addr:
+    { s_addr: INADDR_ANY }
   };
 
-  if (bind(sock, (struct sockaddr *)&addr, sizeof(addr))) {
-    if (errno == EADDRINUSE) goto client_mode;
-    { perror("tcp_bridge: bind"); exit(1); }
+  if (bind(tcp_bridge->sock, (struct sockaddr *)&addr, sizeof(addr))) {
+    perror("tcp_bridge: bind");
+    exit(1);
   }
 
-  if (listen(sock, 5))
-    { perror("tcp_bridge: listen"); exit(1); }
+  if (listen(tcp_bridge->sock, 5)) {
+    perror("tcp_bridge: listen");
+    exit(1);
+  }
 
   printf("tcp_bridge: wait for connection on port %d\n", port);
-
   socklen_t len = sizeof(addr);
-  int sock2 = accept(sock, (struct sockaddr *)&addr, &len);
-  if (sock2 == -1)
-    { perror("tcp_bridge: accept"); exit(1); }
+  int sockServ = accept(tcp_bridge->sock, (struct sockaddr *)&addr, &len);
 
-  close(sock);
-
-  tcp_bridge->sock = sock2;
+  if ( sockServ == -1) {
+    perror("tcp_bridge: accept");
+    exit(1);
+  }
 
+  verify_connection(sockServ, tcp_bridge->is_enb);
   printf("tcp_bridge: connection established\n");
-
-  verify_connection(sock2, tcp_bridge->is_enb);
-
+  close(tcp_bridge->sock);
+  tcp_bridge->sock=sockServ;
   return 0;
+}
 
-client_mode:
-  addr.sin_addr.s_addr = inet_addr("127.0.0.1");
-
-  for (try = 0; try < max_try; try++) {
-    if (try != 0) sleep(1);
+int start_ue(tcp_bridge_state_t *tcp_bridge) {
+struct sockaddr_in addr = {sin_family:
+    AF_INET,
+sin_port:
+    htons(port),
+sin_addr:
+    { s_addr: INADDR_ANY }
+  };
+  addr.sin_addr.s_addr = inet_addr(tcp_bridge->ip);
 
-    printf("tcp_bridge: trying to connect to 127.0.0.1:%d (attempt %d/%d)\n",
-           port, try+1, max_try);
+  while(1) {
+    printf("tcp_bridge: trying to connect to %s:%d\n", tcp_bridge->ip, port);
 
-    if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) == 0) {
+    if (connect(tcp_bridge->sock, (struct sockaddr *)&addr, sizeof(addr)) == 0) {
+      verify_connection(tcp_bridge->sock, tcp_bridge->is_enb);
       printf("tcp_bridge: connection established\n");
-      tcp_bridge->sock = sock;
-      verify_connection(sock, tcp_bridge->is_enb);
       return 0;
     }
 
     perror("tcp_bridge");
+    sleep(1);
   }
 
-  printf("tcp_bridge: connection failed\n");
+  return 0;
+}
 
-  exit(1);
+int tcp_bridge_start(openair0_device *device) {
+  tcp_bridge_state_t *tcp_bridge = device->priv;
+  tcp_bridge->sock = socket(AF_INET, SOCK_STREAM, 0);
+
+  if (tcp_bridge->sock == -1) {
+    perror("tcp_bridge: socket");
+    exit(1);
+  }
+
+  int enable = 1;
+
+  if (setsockopt(tcp_bridge->sock, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int))) {
+    perror("tcp_bridge: SO_REUSEADDR");
+    exit(1);
+  }
+
+  if ( tcp_bridge->is_enb )
+    return start_enb(tcp_bridge);
+  else
+    return start_ue(tcp_bridge);
 }
 
-int tcp_bridge_request(openair0_device *device, void *msg, ssize_t msg_len) { abort(); return 0; }
-int tcp_bridge_reply(openair0_device *device, void *msg, ssize_t msg_len) { abort(); return 0; }
-int tcp_bridge_get_stats(openair0_device* device) { return 0; }
-int tcp_bridge_reset_stats(openair0_device* device) { return 0; }
+int tcp_bridge_request(openair0_device *device, void *msg, ssize_t msg_len) {
+  abort();
+  return 0;
+}
+int tcp_bridge_reply(openair0_device *device, void *msg, ssize_t msg_len) {
+  abort();
+  return 0;
+}
+int tcp_bridge_get_stats(openair0_device *device) {
+  return 0;
+}
+int tcp_bridge_reset_stats(openair0_device *device) {
+  return 0;
+}
 void tcp_bridge_end(openair0_device *device) {}
-int tcp_bridge_stop(openair0_device *device) { return 0; }
-int tcp_bridge_set_freq(openair0_device* device, openair0_config_t *openair0_cfg,int exmimo_dump_config) { return 0; }
-int tcp_bridge_set_gains(openair0_device* device, openair0_config_t *openair0_cfg) { return 0; }
+int tcp_bridge_stop(openair0_device *device) {
+  return 0;
+}
+int tcp_bridge_set_freq(openair0_device *device, openair0_config_t *openair0_cfg,int exmimo_dump_config) {
+  return 0;
+}
+int tcp_bridge_set_gains(openair0_device *device, openair0_config_t *openair0_cfg) {
+  return 0;
+}
+
+int tcp_bridge_write(openair0_device *device, openair0_timestamp timestamp, void **buff, int nsamps, int cc, int flags) {
+  if (cc != 1) {
+    printf("tcp_bridge: only 1 antenna supported\n");
+    exit(1);
+  }
 
-int tcp_bridge_write(openair0_device *device, openair0_timestamp timestamp, void **buff, int nsamps, int cc, int flags)
-{
-  if (cc != 1) { printf("tcp_bridge: only 1 antenna supported\n"); exit(1); }
   tcp_bridge_state_t *t = device->priv;
+
   /* deal with discontinuities in output (think: eNB in TDD mode) */
   if (t->next_tx_timestamp && timestamp != t->next_tx_timestamp) {
     uint32_t b[4096];
     uint64_t to_send = timestamp - t->next_tx_timestamp;
     memset(b, 0, 4096 * sizeof(uint32_t));
+
     while (to_send) {
       int len = to_send > 4096 ? 4096 : to_send;
       int n = fullwrite(t->sock, b, len * 4);
+
       if (n != len * 4) {
         printf("tcp_bridge: write error ret %d error %s\n", n, strerror(errno));
         abort();
       }
+
       to_send -= len;
     }
   }
+
   int n = fullwrite(t->sock, buff[0], nsamps * 4);
+
   if (n != nsamps * 4) {
     printf("tcp_bridge: write error ret %d (wanted %d) error %s\n", n, nsamps*4, strerror(errno));
     abort();
   }
+
   t->next_tx_timestamp = timestamp + nsamps;
   return nsamps;
 }
 
-int tcp_bridge_read(openair0_device *device, openair0_timestamp *timestamp, void **buff, int nsamps, int cc)
-{
-  if (cc != 1) { printf("tcp_bridge: only 1 antenna supported\n"); exit(1); }
+int tcp_bridge_read(openair0_device *device, openair0_timestamp *timestamp, void **buff, int nsamps, int cc) {
+  if (cc != 1) {
+    printf("tcp_bridge: only 1 antenna supported\n");
+    exit(1);
+  }
+
   tcp_bridge_state_t *t = device->priv;
   int n = fullread(t->sock, buff[0], nsamps * 4);
+
   if (n != nsamps * 4) {
     printf("tcp_bridge: read error ret %d nsamps*4 %d error %s\n", n, nsamps * 4, strerror(errno));
     abort();
   }
+
   *timestamp = t->timestamp;
   t->timestamp += nsamps;
   return nsamps;
 }
 
-int tcp_bridge_read_ue(openair0_device *device, openair0_timestamp *timestamp, void **buff, int nsamps, int cc)
-{
-  if (cc != 1) { printf("tcp_bridge: only 1 antenna supported\n"); exit(1); }
+int tcp_bridge_read_ue(openair0_device *device, openair0_timestamp *timestamp, void **buff, int nsamps, int cc) {
+  if (cc != 1) {
+    printf("tcp_bridge: only 1 antenna supported\n");
+    exit(1);
+  }
+
   tcp_bridge_state_t *t = device->priv;
   int n;
 
   /* In synch mode, UE does not write, but we need to
-   * send something to the eNodeB.
-   * We know that UE is in synch mode when it reads
-   * 10 subframes at a time.
-   */
+     send something to the eNodeB.
+     We know that UE is in synch mode when it reads
+     10 subframes at a time.
+  */
   if (nsamps == t->samples_per_subframe * 10) {
     uint32_t b[nsamps];
     memset(b, 0, nsamps * 4);
     n = fullwrite(t->sock, b, nsamps * 4);
+
     if (n != nsamps * 4) {
       printf("tcp_bridge: write error ret %d error %s\n", n, strerror(errno));
       abort();
@@ -205,96 +272,129 @@ int tcp_bridge_read_ue(openair0_device *device, openair0_timestamp *timestamp, v
 }
 
 /* To startup proper communcation between eNB and UE,
- * we need to understand that:
- * - eNodeB starts reading subframe 0
- * - then eNodeB starts sending subframe 4
- * and then repeats read/write for each subframe.
- * The UE:
- * - reads 10 subframes at a time until it is synchronized
- * - then reads subframe n and writes subframe n+2
- * We also want to enforce that the subframe 0 is read
- * at the beginning of the UE RX buffer, not in the middle
- * of it.
- * So it means:
- * - for the eNodeB: let it run as in normal mode (as with a B210)
- * - for the UE, on its very first read:
- *   - we want this read to get data from subframe 0
- *     but the first write of eNodeB is subframe 4
- *     so we first need to read and ignore 6 subframes
- *   - the UE will start its TX only at the subframe 2
- *     corresponding to the subframe 0 it just read,
- *     so we need to write 12 subframes before anything
- *     (the function tcp_bridge_read_ue takes care to
- *     insert dummy TX data during the synch phase)
- *
- * Here is a drawing of the beginning of things to make
- * this logic clearer.
- *
- * We see that eNB starts RX at subframe 0, starts TX at subfram 4,
- * and that UE starts RX at subframe 10 and TX at subframe 12.
- *
- * We understand that the UE has to transmit 12 empty
- * subframes for the eNodeB to start its processing.
- *
- * And because the eNodeB starts its TX at subframe 4 and we
- * want the UE to start its RX at subframe 10, we need to
- * read and ignore 6 subframes in the UE.
- *
- *          -------------------------------------------------------------------------
- * eNB RX:  | *0* | 1 | 2 | 3 |  4  | 5 | 6 | 7 | 8 | 9 |  10  | 11 |  12  | 13 | 14 ...
- *          -------------------------------------------------------------------------
- *
- *          -------------------------------------------------------------------------
- * eNB TX:  |  0  | 1 | 2 | 3 | *4* | 5 | 6 | 7 | 8 | 9 |  10  | 11 |  12  | 13 | 14 ...
- *          -------------------------------------------------------------------------
- *
- *          -------------------------------------------------------------------------
- * UE RX:   |  0  | 1 | 2 | 3 |  4  | 5 | 6 | 7 | 8 | 9 | *10* | 11 |  12  | 13 | 14 ...
- *          -------------------------------------------------------------------------
- *
- *          -------------------------------------------------------------------------
- * UE TX:   |  0  | 1 | 2 | 3 |  4  | 5 | 6 | 7 | 8 | 9 |  10  | 11 | *12* | 13 | 14 ...
- *          -------------------------------------------------------------------------
- *
- * As a final note, we do TX before RX to ensure that the eNB will
- * get some data and send us something so there is no deadlock
- * at the beginning of things. Hopefully the kernel buffers for
- * the sockets are big enough so that the first (big) TX can
- * return to user mode before the buffers are full. If this
- * is wrong in some environment, we will need to work by smaller
- * units of data at a time.
- */
-int tcp_bridge_ue_first_read(openair0_device *device, openair0_timestamp *timestamp, void **buff, int nsamps, int cc)
-{
-  if (cc != 1) { printf("tcp_bridge: only 1 antenna supported\n"); exit(1); }
-  tcp_bridge_state_t *t = device->priv;
+   we need to understand that:
+   - eNodeB starts reading subframe 0
+   - then eNodeB starts sending subframe 4
+   and then repeats read/write for each subframe.
+   The UE:
+   - reads 10 subframes at a time until it is synchronized
+   - then reads subframe n and writes subframe n+2
+   We also want to enforce that the subframe 0 is read
+   at the beginning of the UE RX buffer, not in the middle
+   of it.
+   So it means:
+   - for the eNodeB: let it run as in normal mode (as with a B210)
+   - for the UE, on its very first read:
+     - we want this read to get data from subframe 0
+       but the first write of eNodeB is subframe 4
+       so we first need to read and ignore 6 subframes
+     - the UE will start its TX only at the subframe 2
+       corresponding to the subframe 0 it just read,
+       so we need to write 12 subframes before anything
+       (the function tcp_bridge_read_ue takes care to
+       insert dummy TX data during the synch phase)
+
+   Here is a drawing of the beginning of things to make
+   this logic clearer.
+
+   We see that eNB starts RX at subframe 0, starts TX at subfram 4,
+   and that UE starts RX at subframe 10 and TX at subframe 12.
+
+   We understand that the UE has to transmit 12 empty
+   subframes for the eNodeB to start its processing.
+
+   And because the eNodeB starts its TX at subframe 4 and we
+   want the UE to start its RX at subframe 10, we need to
+   read and ignore 6 subframes in the UE.
+
+            -------------------------------------------------------------------------
+   eNB RX:  | *0* | 1 | 2 | 3 |  4  | 5 | 6 | 7 | 8 | 9 |  10  | 11 |  12  | 13 | 14 ...
+            -------------------------------------------------------------------------
+
+            -------------------------------------------------------------------------
+   eNB TX:  |  0  | 1 | 2 | 3 | *4* | 5 | 6 | 7 | 8 | 9 |  10  | 11 |  12  | 13 | 14 ...
+            -------------------------------------------------------------------------
+
+            -------------------------------------------------------------------------
+   UE RX:   |  0  | 1 | 2 | 3 |  4  | 5 | 6 | 7 | 8 | 9 | *10* | 11 |  12  | 13 | 14 ...
+            -------------------------------------------------------------------------
+
+            -------------------------------------------------------------------------
+   UE TX:   |  0  | 1 | 2 | 3 |  4  | 5 | 6 | 7 | 8 | 9 |  10  | 11 | *12* | 13 | 14 ...
+            -------------------------------------------------------------------------
+
+   As a final note, we do TX before RX to ensure that the eNB will
+   get some data and send us something so there is no deadlock
+   at the beginning of things. Hopefully the kernel buffers for
+   the sockets are big enough so that the first (big) TX can
+   return to user mode before the buffers are full. If this
+   is wrong in some environment, we will need to work by smaller
+   units of data at a time.
+*/
+int tcp_bridge_ue_first_read(openair0_device *device, openair0_timestamp *timestamp, void **buff, int nsamps, int cc) {
+  if (cc != 1) {
+    printf("tcp_bridge: only 1 antenna supported\n");
+    exit(1);
+  }
 
+  tcp_bridge_state_t *t = device->priv;
   uint32_t b[t->samples_per_subframe * 12];
   memset(b, 0, t->samples_per_subframe * 12 * 4);
   int n = fullwrite(t->sock, b, t->samples_per_subframe * 12 * 4);
+
   if (n != t->samples_per_subframe * 12 * 4) {
     printf("tcp_bridge: write error ret %d error %s\n", n, strerror(errno));
     abort();
   }
+
   n = fullread(t->sock, b, t->samples_per_subframe * 6 * 4);
+
   if (n != t->samples_per_subframe * 6 * 4) {
     printf("tcp_bridge: read error ret %d error %s\n", n, strerror(errno));
     abort();
   }
 
-  device->trx_read_func = tcp_bridge_read_ue;
+  /* Due to some unknown bug in the eNB (or UE, or both), the first frames
+   * are not correctly generated (or handled), which leads to a bad behavior
+   * of the simulator in some cases (seen with 100 RBs: the UE reads a bad
+   * MIB and switches to 25 RBs, which results in a deadlock in this driver).
+   * Let's skip 10 frames to avoid this issue.
+   */
+  for (int i = 0; i < 10 * 10; i++) {
+    memset(b, 0, t->samples_per_subframe * 4);
+    n = fullwrite(t->sock, b, t->samples_per_subframe * 4);
+
+    if (n != t->samples_per_subframe * 4) {
+      printf("tcp_bridge: write error ret %d error %s\n", n, strerror(errno));
+      abort();
+    }
+
+    n = fullread(t->sock, b, t->samples_per_subframe * 4);
 
+    if (n != t->samples_per_subframe * 4) {
+      printf("tcp_bridge: read error ret %d error %s\n", n, strerror(errno));
+      abort();
+    }
+  }
+
+  device->trx_read_func = tcp_bridge_read_ue;
   return tcp_bridge_read_ue(device, timestamp, buff, nsamps, cc);
 }
 
 __attribute__((__visibility__("default")))
-int device_init(openair0_device* device, openair0_config_t *openair0_cfg)
-{
-  tcp_bridge_state_t *tcp_bridge = (tcp_bridge_state_t*)malloc(sizeof(tcp_bridge_state_t));
-  memset(tcp_bridge, 0, sizeof(tcp_bridge_state_t));
-
-  tcp_bridge->is_enb = getenv("ENODEB") != NULL;
+int device_init(openair0_device *device, openair0_config_t *openair0_cfg) {
+  tcp_bridge_state_t *tcp_bridge = (tcp_bridge_state_t *)calloc(sizeof(tcp_bridge_state_t),1);
+
+  if ((tcp_bridge->ip=getenv("TCPBRIDGE")) == NULL ) {
+    /* for compatibility, we test the ENB environment variable */
+    if ((tcp_bridge->ip=getenv("ENODEB")) != NULL ) {
+      tcp_bridge->ip=strdup("enb");
+    } else {
+      tcp_bridge->ip=strdup("127.0.0.1");
+    }
+  }
 
+  tcp_bridge->is_enb = strncasecmp(tcp_bridge->ip,"enb",3) == 0;
   printf("tcp_bridge: running as %s\n", tcp_bridge->is_enb ? "eNB" : "UE");
 
   /* only 25, 50 or 100 PRBs handled for the moment */
@@ -323,15 +423,21 @@ int device_init(openair0_device* device, openair0_config_t *openair0_cfg)
   device->priv = tcp_bridge;
 
   switch ((int)openair0_cfg[0].sample_rate) {
-  case 30720000: tcp_bridge->samples_per_subframe = 30720; break;
-  case 15360000: tcp_bridge->samples_per_subframe = 15360; break;
-  case 7680000:  tcp_bridge->samples_per_subframe = 7680; break;
+    case 30720000:
+      tcp_bridge->samples_per_subframe = 30720;
+      break;
+
+    case 15360000:
+      tcp_bridge->samples_per_subframe = 15360;
+      break;
+
+    case 7680000:
+      tcp_bridge->samples_per_subframe = 7680;
+      break;
   }
 
   /* let's pretend to be a b2x0 */
   device->type = USRP_B200_DEV;
-
   device->openair0_cfg=&openair0_cfg[0];
-
   return 0;
 }
diff --git a/targets/COMMON/create_tasks.c b/targets/COMMON/create_tasks.c
index 094fbfce827c0507ebdd26713fbcc4f77099b31f..7da21a5f5ea21a35bde5ff9c5eefd386d565a6b1 100644
--- a/targets/COMMON/create_tasks.c
+++ b/targets/COMMON/create_tasks.c
@@ -23,34 +23,41 @@
 # include "intertask_interface.h"
 # include "create_tasks.h"
 # include "common/utils/LOG/log.h"
+# include "targets/RT/USER/lte-softmodem.h"
 # include "common/ran_context.h"
 
-# ifdef OPENAIR2
-#   if defined(ENABLE_USE_MME)
-#     include "sctp_eNB_task.h"
-#     include "x2ap_eNB.h"
-#     include "s1ap_eNB.h"
-#     include "nas_ue_task.h"
-#     include "udp_eNB_task.h"
-#     include "gtpv1u_eNB_task.h"
-#   else
-#     define EPC_MODE_ENABLED 0
-#   endif
-#   include "RRC/LTE/rrc_defs.h"
-# endif
-# include "sctp_eNB_task.h"
+#ifdef OPENAIR2
+  #if defined(ENABLE_USE_MME)
+    #include "sctp_eNB_task.h"
+    #include "x2ap_eNB.h"
+    #include "s1ap_eNB.h"
+    #include "nas_ue_task.h"
+    #include "udp_eNB_task.h"
+    #include "gtpv1u_eNB_task.h"
+    /* temporary warning removale while implementing noS1 */
+    /* as config option                                   */
+  #else
+    #ifdef EPC_MODE_ENABLED
+      #undef  EPC_MODE_ENABLED
+    #endif
+    #define EPC_MODE_ENABLED 0
+  #endif
+  #if ENABLE_RAL
+    #include "lteRALue.h"
+    #include "lteRALenb.h"
+  #endif
+  #include "RRC/LTE/rrc_defs.h"
+#endif
 # include "f1ap_cu_task.h"
 # include "f1ap_du_task.h"
 # include "enb_app.h"
 
 extern RAN_CONTEXT_t RC;
-extern int emulate_rf;
 
-int create_tasks(uint32_t enb_nb)
-{
+int create_tasks(uint32_t enb_nb) {
+  LOG_D(ENB_APP, "%s(enb_nb:%d\n", __FUNCTION__, enb_nb);
   ngran_node_t type = RC.rrc[0]->node_type;
   int rc;
-
   itti_wait_ready(1);
 
   if (enb_nb > 0) {
@@ -66,7 +73,7 @@ int create_tasks(uint32_t enb_nb)
     }
   }
 
-  if (enb_nb > 0) {
+  if (EPC_MODE_ENABLED && enb_nb > 0) {
     /* this task needs not be started if:
      * * there is no CU/DU split
      * * ENABLE_USE_MME is not defined
@@ -87,29 +94,23 @@ int create_tasks(uint32_t enb_nb)
     if (enb_nb > 0) {
       rc = itti_create_task(TASK_CU_F1, F1AP_CU_task, NULL);
       AssertFatal(rc >= 0, "Create task for CU F1AP failed\n");
-      //RS/BK: Fix me!
-      rc = itti_create_task (TASK_L2L1, l2l1_task, NULL);
-      AssertFatal(rc >= 0, "Create task for L2L1 failed\n");
-
     }
     /* fall through */
   case ngran_eNB:
   case ngran_ng_eNB:
   case ngran_gNB:
 #if defined(ENABLE_USE_MME)
-    if (enb_nb > 0) {
+    if (EPC_MODE_ENABLED && enb_nb > 0) {
       rc = itti_create_task(TASK_S1AP, s1ap_eNB_task, NULL);
       AssertFatal(rc >= 0, "Create task for S1AP failed\n");
-      if (!emulate_rf){
+      if (!(get_softmodem_params()->emulate_rf)){
         rc = itti_create_task(TASK_UDP, udp_eNB_task, NULL);
         AssertFatal(rc >= 0, "Create task for UDP failed\n");
       }
       rc = itti_create_task(TASK_GTPV1_U, gtpv1u_eNB_task, NULL);
       AssertFatal(rc >= 0, "Create task for GTPV1U failed\n");
-      if (EPC_MODE_ENABLED) {
-        rc = itti_create_task(TASK_X2AP, x2ap_task, NULL);
-        AssertFatal(rc >= 0, "Create task for X2AP failed\n");
-      }
+      rc = itti_create_task(TASK_X2AP, x2ap_task, NULL);
+      AssertFatal(rc >= 0, "Create task for X2AP failed\n");
     }
 #endif
     break;
@@ -117,23 +118,10 @@ int create_tasks(uint32_t enb_nb)
     /* intentionally left blank */
     break;
   }
-  switch (type) {
-  case ngran_eNB_DU:
-  case ngran_gNB_DU:
-    if (enb_nb > 0) {
-      rc = itti_create_task(TASK_DU_F1, F1AP_DU_task, NULL);
-      AssertFatal(rc >= 0, "Create task for DU F1AP failed\n");
-    }
-    /* fall through */
-  case ngran_eNB:
-  case ngran_ng_eNB:
-  case ngran_gNB:
-    rc = itti_create_task (TASK_L2L1, l2l1_task, NULL);
-    AssertFatal(rc >= 0, "Create task for L2L1 failed\n");
-    break;
-  default:
-    /* intentioally left blank */
-    break;
+
+  if ((type == ngran_eNB_DU || type == ngran_gNB_DU) && (enb_nb > 0)) {
+    rc = itti_create_task(TASK_DU_F1, F1AP_DU_task, NULL);
+    AssertFatal(rc >= 0, "Create task for DU F1AP failed\n");
   }
 
   itti_wait_ready(0);
diff --git a/targets/COMMON/create_tasks_ue.c b/targets/COMMON/create_tasks_ue.c
index c1faa8d40625c7487adbb75733c6b5f6b07b6be7..1b94ad4dd6ee52f18af74c6fda3cf49fbe0b48d6 100644
--- a/targets/COMMON/create_tasks_ue.c
+++ b/targets/COMMON/create_tasks_ue.c
@@ -24,57 +24,52 @@
 # include "create_tasks.h"
 # include "common/utils/LOG/log.h"
 
-# ifdef OPENAIR2
-#   if defined(ENABLE_USE_MME)
-#     include "sctp_eNB_task.h"
-#     include "s1ap_eNB.h"
-#     include "nas_ue_task.h"
-#     include "udp_eNB_task.h"
-#     include "gtpv1u_eNB_task.h"
-#   endif
-#   if ENABLE_RAL
-#     include "lteRALue.h"
-#     include "lteRALenb.h"
-#   endif
-#   include "RRC/LTE/rrc_defs.h"
-# endif
+#ifdef OPENAIR2
+  #if defined(ENABLE_USE_MME)
+    #include "sctp_eNB_task.h"
+    #include "s1ap_eNB.h"
+    #include "nas_ue_task.h"
+    #include "udp_eNB_task.h"
+    #include "gtpv1u_eNB_task.h"
+  #endif
+  #if ENABLE_RAL
+    #include "lteRALue.h"
+    #include "lteRALenb.h"
+  #endif
+  #include "RRC/LTE/rrc_defs.h"
+#endif
 # include "enb_app.h"
 
-int create_tasks_ue(uint32_t ue_nb)
-{
+int create_tasks_ue(uint32_t ue_nb) {
   LOG_D(ENB_APP, "%s(ue_nb:%d)\n", __FUNCTION__, ue_nb);
-
   itti_wait_ready(1);
-  if (itti_create_task (TASK_L2L1, l2l1_task, NULL) < 0) {
-    LOG_E(PDCP, "Create task for L2L1 failed\n");
-    return -1;
-  }
-
 #      if defined(ENABLE_USE_MME)
 #      if defined(NAS_BUILT_IN_UE)
-      if (ue_nb > 0) {
-        nas_user_container_t *users = calloc(1, sizeof(*users));
-        if (users == NULL) abort();
-        users->count = ue_nb;
-        if (itti_create_task (TASK_NAS_UE, nas_ue_task, users) < 0) {
-          LOG_E(NAS, "Create task for NAS UE failed\n");
-          return -1;
-        }
-      }
-#      endif
-#      endif
 
-    if (ue_nb > 0) {
-      if (itti_create_task (TASK_RRC_UE, rrc_ue_task, NULL) < 0) {
-        LOG_E(RRC, "Create task for RRC UE failed\n");
-        return -1;
-      }
+  if (ue_nb > 0) {
+    nas_user_container_t *users = calloc(1, sizeof(*users));
+
+    if (users == NULL) abort();
+
+    users->count = ue_nb;
 
+    if (itti_create_task (TASK_NAS_UE, nas_ue_task, users) < 0) {
+      LOG_E(NAS, "Create task for NAS UE failed\n");
+      return -1;
     }
+  }
 
+#      endif
+#      endif
 
-  itti_wait_ready(0);
+  if (ue_nb > 0) {
+    if (itti_create_task (TASK_RRC_UE, rrc_ue_task, NULL) < 0) {
+      LOG_E(RRC, "Create task for RRC UE failed\n");
+      return -1;
+    }
+  }
 
+  itti_wait_ready(0);
   return 0;
 }
 #endif
\ No newline at end of file
diff --git a/targets/COMMON/openairinterface5g_limits.h b/targets/COMMON/openairinterface5g_limits.h
index 1c27f655851f12b0d58eab503ca6e4e52346fc4a..644952ca794a041a046d86efdf054ccaff1b7c39 100644
--- a/targets/COMMON/openairinterface5g_limits.h
+++ b/targets/COMMON/openairinterface5g_limits.h
@@ -5,8 +5,18 @@
 #        define NUMBER_OF_eNB_MAX 1
 #        define NUMBER_OF_RU_MAX 2
 #        ifndef UE_EXPANSION
+// TODO:L2 FAPI simulator.
+// UESIM_EXPANSION is used to be same value of NUMBER_OF_UE_MAX
+// in eNB and UE.
+// now , if we use --mu option in UE, compiling error will occur.
+// This problem will be fixed in the future.
+#            ifndef UESIM_EXPANSION
 #                define NUMBER_OF_UE_MAX 16
 #                define NUMBER_OF_CONNECTED_eNB_MAX 3
+#            else
+#                define NUMBER_OF_UE_MAX 256
+#                define NUMBER_OF_CONNECTED_eNB_MAX 1
+#            endif
 #        else
 #                define NUMBER_OF_UE_MAX 256
 #                define NUMBER_OF_CONNECTED_eNB_MAX 1
@@ -15,8 +25,18 @@
 #        define NUMBER_OF_eNB_MAX 7
 #        define NUMBER_OF_RU_MAX 32
 #        ifndef UE_EXPANSION
-#                define NUMBER_OF_UE_MAX 20
+/* if the value of MAX_MOBILES_PER_ENB and NUMBER_OF_UE_MAX is different,
+eNB process will exit because unexpected access happens.
+Now some parts are using NUMBER_OF_UE_MAX
+and the other are using MAX_MOBILES_PER_ENB in for-loop.
+*/
+#            ifndef UESIM_EXPANSION
+#                define NUMBER_OF_UE_MAX 16
 #                define NUMBER_OF_CONNECTED_eNB_MAX 3
+#            else
+#                define NUMBER_OF_UE_MAX 256
+#                define NUMBER_OF_CONNECTED_eNB_MAX 1
+#            endif
 #        else
 #                define NUMBER_OF_UE_MAX 256
 #                define NUMBER_OF_CONNECTED_eNB_MAX 1
diff --git a/targets/DOCS/E-UTRAN_User_Guide.docx b/targets/DOCS/E-UTRAN_User_Guide.docx
old mode 100755
new mode 100644
diff --git a/targets/DOCS/E-UTRAN_User_Guide.pdf b/targets/DOCS/E-UTRAN_User_Guide.pdf
old mode 100755
new mode 100644
diff --git a/targets/DOCS/api_icic.xml b/targets/DOCS/api_icic.xml
deleted file mode 100644
index 80984fb2363927c6a3002c2af9220367215bdb6d..0000000000000000000000000000000000000000
--- a/targets/DOCS/api_icic.xml
+++ /dev/null
@@ -1,95 +0,0 @@
-
-
-<ICIC_API>
-	<SRUCTURE>
-		<STRUCTNAME>SBMAP_CONF</STRUCTNAME>
-		<PATH>openair2/LAYER2/MAC/defs.h</PATH>
-		<FIELD>
-			<FIELDNAME>sbmap[13]</FIELDNAME>
-			<FIELDTYPE>unsigned char</FIELDTYPE>
-			<DESC>subband map indicates to scheduler allowed SB for eNB</DESC>  
-		</FIELD>
-		<FIELD>
-			<FIELDNAME>periodicity</FIELDNAME>
-			<FIELDTYPE>unsigned char</FIELDTYPE>
-			<DESC>in millisecond indicate update instant</DESC>  
-		</FIELD>
-		<FIELD>
-			<FIELDNAME>first_subframe</FIELDNAME>
-			<FIELDTYPE>unsigned char</FIELDTYPE>
-			<DESC>...</DESC>  
-		</FIELD>
-		<FIELD>
-			<FIELDNAME>sb_size</FIELDNAME>
-			<FIELDTYPE>unsigned char</FIELDTYPE>
-			<DESC>number of PRB in this subband</DESC>  
-		</FIELD>
-		<FIELD>
-			<FIELDNAME>nb_active_sb</FIELDNAME>
-			<FIELDTYPE>unsigned char</FIELDTYPE>
-			<DESC>indicates the number of set subbands</DESC>  
-		</FIELD>
-	</SRUCTURE>
-	
-	<SRUCTURE>
-		<STRUCTNAME>eNB_MAC_INST</STRUCTNAME>
-		<PATH>openair2/LAYER2/MAC/defs.h</PATH>
-		<FIELD>
-			...			 
-		</FIELD>
-		<FIELD>
-			<FIELDNAME>sbmap_conf</FIELDNAME>
-			<FIELDTYPE>SBMAP_CONF</FIELDTYPE>
-			<DESC>subband map configuration for each eNB</DESC>  
-		</FIELD>		
-		<INITPATH>openair2/LAYER2/MAC/main.c</INITPATH>
-		<INITFUNC>mac_top_init</INITFUNC>	
-	</SRUCTURE>
-	
-	<SRUCTURE>
-		<STRUCTNAME>MAC_xface</STRUCTNAME>
-		<PATH>openair2/PHY_INTERFACE/defs.h</PATH>
-		<FIELD>
-			...			 
-		</FIELD>
-		<FIELD>
-			<FIELDNAME>(*get_SB_size)(unsigned char)</FIELDNAME>
-			<FIELDTYPE>function pointer n</FIELDTYPE>
-			<DESC>return the number of PRB supported in a subband configuration</DESC>  
-		</FIELD>		
-		<INITPATH>openair2/LAYER2/MAC/main.c</INITPATH>
-		<INITFUNC>l2_init</INITFUNC>	
-	</SRUCTURE>
-	
-	<FUNCTION>
-		<FUNCNAME>Get_Cell_SBMap</FUNCNAME>
-		<PARAMS>unsigned char Mod_id</PARAMS> 
-		<RETURN>void</RETURN>
-		<PROTOPATH>openair2/LAYER2/MAC/defs.h</PROTOPATH>
-		<IMPLPATH>openair2/LAYER2/MAC/eNB_scheduler.c</IMPLPATH>
-		<DESC>imlements ICIC algo</DESC> 
-	</FUNCTION>
-	<FUNCTION>
-		<FUNCNAME>Get_SB_size</FUNCNAME>
-		<PARAMS>unsigned char n_rb_dl</PARAMS> 
-		<RETURN>unsigned char </RETURN>
-		<PROTOPATH>openair1/PHY/LTE_TRANSPORT/proto.h</PROTOPATH>
-		<IMPLPATH>openair1/PHY/LTE_TRANSPORT/lte_mcs.c</IMPLPATH>
-		<DESC>return the number of PRB supported in a subband configuration.</DESC> 
-	</FUNCTION>
-</ICIC_API>
-
-
-	
-	
-		
-		
-		
-		
-		
-			
-			
-			
-			
-		
-		
\ No newline at end of file
diff --git a/targets/DOCS/oai_L1_L2_procedures.ipe b/targets/DOCS/oai_L1_L2_procedures.ipe
old mode 100755
new mode 100644
diff --git a/targets/DOCS/oaiemu.doc b/targets/DOCS/oaiemu.doc
deleted file mode 100644
index 13433a5f35d916480a21aaeb5ce9cc6315539a60..0000000000000000000000000000000000000000
Binary files a/targets/DOCS/oaiemu.doc and /dev/null differ
diff --git a/targets/DOCS/oaisim_walkthrough.pdf b/targets/DOCS/oaisim_walkthrough.pdf
deleted file mode 100644
index b6d766e7f6dd825202526e18b13308766b65f3a9..0000000000000000000000000000000000000000
Binary files a/targets/DOCS/oaisim_walkthrough.pdf and /dev/null differ
diff --git a/targets/DOCS/openair_header.tex b/targets/DOCS/openair_header.tex
deleted file mode 100755
index 14e1baee5aa95cc29c8f2bab58ac9f7e490be938..0000000000000000000000000000000000000000
--- a/targets/DOCS/openair_header.tex
+++ /dev/null
@@ -1,47 +0,0 @@
-\documentclass[a4paper]{book}
-\usepackage{a4wide}
-\usepackage{makeidx}
-\usepackage{fancyhdr}
-\usepackage{graphicx}
-\usepackage{multicol}
-\usepackage{float}
-\usepackage{textcomp}
-\usepackage{alltt}
-\usepackage{amsmath}
-\usepackage{amssymb}
-\ifx\pdfoutput\undefined
-\usepackage[ps2pdf,
-            pagebackref=true,
-            colorlinks=true,
-            linkcolor=blue
-           ]{hyperref}
-\usepackage{pspicture}
-\else
-\usepackage[pdftex,
-            pagebackref=true,
-            colorlinks=true,
-            linkcolor=blue
-           ]{hyperref}
-\fi
-\usepackage{doxygen}
-\usepackage{times}
-\makeindex
-\setcounter{tocdepth}{1}
-\renewcommand{\footrulewidth}{0.4pt}
-\begin{document}
-\begin{titlepage}
-\vspace*{7cm}
-\begin{center}
-{\Large openair Specifications }\\
-Phyiscal, Medium-Access, Radio-link Control, Packet Data Convergence Protocol and Radio Resource Control Layers\\
-\vspace*{1cm}
-{\large Generated by Doxygen 1.3.8}\\
-\vspace*{0.5cm}
-{\small Sun Oct 31 19:27:37 2004}\\
-\end{center}
-\end{titlepage}
-\clearemptydoublepage
-\pagenumbering{roman}
-\tableofcontents
-\clearemptydoublepage
-\pagenumbering{arabic}
diff --git a/targets/DOCS/path_loss_oaisim.xlsx b/targets/DOCS/path_loss_oaisim.xlsx
deleted file mode 100644
index 2ba25b466bb99c3886046669fe8d86348f8ce389..0000000000000000000000000000000000000000
Binary files a/targets/DOCS/path_loss_oaisim.xlsx and /dev/null differ
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
old mode 100755
new mode 100644
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
old mode 100755
new mode 100644
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
old mode 100755
new mode 100644
diff --git a/targets/PROJECTS/E-MBMS/enb.conf b/targets/PROJECTS/E-MBMS/enb.conf
old mode 100755
new mode 100644
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
new file mode 100644
index 0000000000000000000000000000000000000000..df98111cfc0f1fd613ad94521c612e69a32a6350
--- /dev/null
+++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band13.tm1.50PRB.emtc.conf
@@ -0,0 +1,444 @@
+Active_eNBs = ( "eNB_Eurecom_LTEBox");
+# Asn1_verbosity, choice in: none, info, annoying
+Asn1_verbosity = "none";
+
+eNBs =
+(
+ {
+    ////////// Identification parameters:
+    eNB_ID    =  0xe00;
+
+    cell_type =  "CELL_MACRO_ENB";
+
+    eNB_name  =  "eNB_Eurecom_LTEBox";
+
+    // Tracking area code, 0x0000 and 0xfffe are reserved values
+    tracking_area_code  =  "1";
+
+    plmn_list = ( { mcc = 208; mnc = 93; mnc_length = 2;} );
+
+    tr_s_preference     = "local_mac"
+
+    ////////// Physical parameters:
+
+    component_carriers = (
+    {
+      node_function                             = "3GPP_eNodeB";
+      node_timing                               = "synch_to_ext_device";
+      node_synch_ref                            = 0;
+      frame_type                                = "FDD";
+      tdd_config                                = 3;
+      tdd_config_s                              = 0;
+      prefix_type                               = "NORMAL";
+      eutra_band                                = 13;
+      downlink_frequency                        = 751000000L;
+      uplink_frequency_offset                   = 31000000;
+      Nid_cell                                  = 0;
+      N_RB_DL                                   = 50;
+      Nid_cell_mbsfn                            = 0;
+      nb_antenna_ports                          = 1;
+      nb_antennas_tx                            = 1;
+      nb_antennas_rx                            = 1;
+      tx_gain                                   = 90;
+      rx_gain                                   = 110;
+      pbch_repetition                           = "FALSE";
+      prach_root                                = 0;
+      prach_config_index                        = 0;
+      prach_high_speed                          = "DISABLE";
+      prach_zero_correlation                    = 1;
+      prach_freq_offset                         = 1;
+      pucch_delta_shift                         = 1;
+      pucch_nRB_CQI                             = 1;
+      pucch_nCS_AN                              = 0;
+      pucch_n1_AN                               = 32;
+      pdsch_referenceSignalPower                = -27;
+      pdsch_p_b                                 = 0;
+      pusch_n_SB                                = 1;
+      pusch_enable64QAM                         = "DISABLE";
+      pusch_hoppingMode                         = "interSubFrame";
+      pusch_hoppingOffset                       = 0;
+      pusch_groupHoppingEnabled                 = "ENABLE";
+      pusch_groupAssignment                     = 0;
+      pusch_sequenceHoppingEnabled              = "DISABLE";
+      pusch_nDMRS1                              = 1;
+      phich_duration                            = "NORMAL";
+      phich_resource                            = "ONESIXTH";
+      srs_enable                                = "DISABLE";
+      /*  srs_BandwidthConfig                   =;
+      srs_SubframeConfig                        =;
+      srs_ackNackST                             =;
+      srs_MaxUpPts                              =;*/
+
+      pusch_p0_Nominal                          = -96;
+      pusch_alpha                               = "AL1";
+      pucch_p0_Nominal                          = -104;
+      msg3_delta_Preamble                       = 6;
+      pucch_deltaF_Format1                      = "deltaF2";
+      pucch_deltaF_Format1b                     = "deltaF3";
+      pucch_deltaF_Format2                      = "deltaF0";
+      pucch_deltaF_Format2a                     = "deltaF0";
+      pucch_deltaF_Format2b                     = "deltaF0";
+
+      rach_numberOfRA_Preambles                 = "n64"; #64
+      rach_preamblesGroupAConfig                = "DISABLE";
+      /*
+      rach_sizeOfRA_PreamblesGroupA             = ;
+      rach_messageSizeGroupA                    = ;
+      rach_messagePowerOffsetGroupB             = ;
+      */
+      rach_powerRampingStep                     = 4;
+      rach_preambleInitialReceivedTargetPower   = -108;
+      rach_preambleTransMax                     = 10;
+      rach_raResponseWindowSize                 = 10;
+      rach_macContentionResolutionTimer         = 48;
+      rach_maxHARQ_Msg3Tx                       = 4;
+
+      pcch_default_PagingCycle                  = "rf128"; #128
+      pcch_nB                                   = "oneT";
+      bcch_modificationPeriodCoeff              = 2;
+      ue_TimersAndConstants_t300                = "ms1000";
+      ue_TimersAndConstants_t301                = "ms1000";
+      ue_TimersAndConstants_t310                = "ms1000";
+      ue_TimersAndConstants_t311                = "ms10000";
+      ue_TimersAndConstants_n310                = "n20";
+      ue_TimersAndConstants_n311                = "n1";
+      ue_TransmissionMode                       = "tm1";
+
+      # eMTC Parameters
+      emtc_parameters :
+      {
+          eMTC_configured                       = 1;
+          #hyperSFN_r13                               = 0;
+          #eDRX_Allowed_r13                           = 0;
+          #q_QualMinRSRQ_CE_r13                       = ;
+
+          #SIB1
+          schedulingInfoSIB1_BR_r13                   = 4;
+
+          #system_info_value_tag_SI =
+          #(
+          #    {
+          #        systemInfoValueTagSi_r13 = 0;
+          #    }
+          #);
+
+          cellSelectionInfoCE_r13                     = "ENABLE";
+          q_RxLevMinCE_r13                            = -70;
+          bandwidthReducedAccessRelatedInfo_r13       = "ENABLE"
+          si_WindowLength_BR_r13                      = "ms20";    #0
+          si_RepetitionPattern_r13                    = "everyRF"; #0
+
+          scheduling_info_br =
+          (
+              {
+                  si_Narrowband_r13 = 8;
+                  si_TBS_r13        = 5;
+              }
+         );
+
+          fdd_DownlinkOrTddSubframeBitmapBR_r13     = "subframePattern40-r13";
+          fdd_DownlinkOrTddSubframeBitmapBR_val_r13 = 0xFFFFFFFFFF;
+          startSymbolBR_r13                           = 2;
+          si_HoppingConfigCommon_r13                  = "off"; #1; # Note: 1==OFF !
+          si_ValidityTime_r13                         = "true"; #0
+
+          freqHoppingParametersDL_r13                 = "DISABLE"
+          mpdcch_pdsch_HoppingNB_r13                  = "nb2"; #0
+          interval_DLHoppingConfigCommonModeA_r13     = "interval-FDD-r13"
+          interval_DLHoppingConfigCommonModeA_r13_val = 0;
+          interval_DLHoppingConfigCommonModeB_r13     = "interval-FDD-r13"
+          interval_DLHoppingConfigCommonModeB_r13_val = 0;
+          mpdcch_pdsch_HoppingOffset_r13              = 1;
+
+
+          # SIB23
+          frame_type                                = "FDD";
+          preambleTransMax_CE_r13                   = 10; #6
+
+          rach_numberOfRA_Preambles                 = 60; #14
+          rach_powerRampingStep                     = 4;
+          rach_preambleInitialReceivedTargetPower   = -110;
+          rach_preambleTransMax                     = 10;
+          rach_raResponseWindowSize                 = 10;
+          rach_macContentionResolutionTimer         = 64;
+          rach_maxHARQ_Msg3Tx                       = 4;
+
+          # max size for this array is 4
+          rach_CE_LevelInfoList_r13 =
+          (
+              {
+                  firstPreamble_r13                 = 60;
+                  lastPreamble_r13                  = 63;
+                  ra_ResponseWindowSize_r13         = 20; #0
+                  mac_ContentionResolutionTimer_r13 = 80; #0
+                  rar_HoppingConfig_r13             = "off";  #1;
+              }
+          );
+
+          # BCCH CONFIG
+          bcch_modificationPeriodCoeff              = 2;
+
+          #PCCH Config
+          pcch_default_PagingCycle                  = "rf128"; #128
+          pcch_nB                                   = "oneT";
+
+          #PRACH Config
+          prach_root                                = 89;
+          prach_config_index                        = 0;
+          prach_high_speed                          = "DISABLE";
+          prach_zero_correlation                    = 1;
+          prach_freq_offset                         = 1;
+
+          #PDSCH Config Common
+          pdsch_referenceSignalPower                = -27
+          pdsch_p_b                                 = 0;
+
+
+          # PUSCH Config Common
+          pusch_n_SB                                = 1;
+          pusch_hoppingMode                         = "interSubFrame";
+          pusch_hoppingOffset                       = 0;
+          pusch_enable64QAM                         = "DISABLE";
+          pusch_groupHoppingEnabled                 = "ENABLE";
+          pusch_groupAssignment                     = 0;
+          pusch_sequenceHoppingEnabled              = "DISABLE";
+          pusch_nDMRS1                              = 1;
+
+          # PUCCH Config Common
+          pucch_delta_shift                         = 1;
+          pucch_nRB_CQI                             = 0;
+          pucch_nCS_AN                              = 0;
+          pucch_n1_AN                               = 32;
+
+          pusch_p0_Nominal                          = -96;
+          pusch_alpha                               = "AL1";
+          pucch_p0_Nominal                          = -104;
+          pucch_deltaF_Format1                      = "deltaF0";
+          pucch_deltaF_Format1b                     = "deltaF3";
+          pucch_deltaF_Format2                      = "deltaF0";
+          pucch_deltaF_Format2a                     = "deltaF0";
+          pucch_deltaF_Format2b                     = "deltaF0";
+
+          msg3_delta_Preamble                       = 6;
+
+
+          prach_ConfigCommon_v1310                  = "ENABLE";
+
+          mpdcch_startSF_CSS_RA_r13                 = "fdd-r13";
+          mpdcch_startSF_CSS_RA_r13_val             = "v1"; #0
+          prach_HoppingOffset_r13                   = 0;
+
+
+          pdsch_maxNumRepetitionCEmodeA_r13         = "r16"; #0
+          #pdsch_maxNumRepetitionCEmodeB_r13         = "r384"; # NULL - 2
+
+          pusch_maxNumRepetitionCEmodeA_r13         = "r8"; #0
+          #pusch_maxNumRepetitionCEmodeB_r13         = "r768"; #4 #NULL
+          #pusch_HoppingOffset_v1310                 = 5; #NULL
+
+          # max size for this array is 3
+          rsrp_range_list =
+          (
+              {
+                  rsrp_range_br = 0;
+              }
+          );
+
+          # max size for this array is 4
+          prach_parameters_ce_r13 =
+          (
+              {
+                  prach_config_index_br                     = 3;
+                  prach_freq_offset_br                      = 2;
+                  prach_StartingSubframe_r13                = 2;
+                  maxNumPreambleAttemptCE_r13               = 10; #6
+                  numRepetitionPerPreambleAttempt_r13       = 1;  #0
+                  mpdcch_NumRepetition_RA_r13               = 1;  #0
+                  prach_HoppingConfig_r13                   = 0;  #1
+                  max_available_narrow_band                 = [3];
+             }
+          );
+
+          n1PUCCH_AN_InfoList_r13 =
+          (
+              {
+                  pucch_info_value = 0;
+              }
+          );
+
+
+          ue_TimersAndConstants_t300                = "ms1000";
+          ue_TimersAndConstants_t301                = "ms400";
+          ue_TimersAndConstants_t310                = "ms50";
+          ue_TimersAndConstants_t311                = "ms30000";
+          ue_TimersAndConstants_n310                = "n1";
+          ue_TimersAndConstants_n311                = "n10";
+          ue_TransmissionMode                       = "tm1";
+
+          pcch_config_v1310 :
+          {
+              paging_narrowbands_r13           = 1;
+              mpdcch_numrepetition_paging_r13  = "r1";         #0
+              #nb_v1310                        = "one256thT";  #2
+          }
+
+
+          pucch_NumRepetitionCE_Msg4_Level0_r13      = "n1";  #0
+          #pucch_NumRepetitionCE_Msg4_Level1_r13     = "n2";  #1
+          #pucch_NumRepetitionCE_Msg4_Level2_r13     = "n16"; #2
+          #pucch_NumRepetitionCE_Msg4_Level3_r13     = "n32"; #3
+
+          sib2_freq_hoppingParameters_r13 :
+          {
+             #sib2_mpdcch_pdsch_hoppingNB_r13                   = "nb2"; #0
+             #sib2_interval_DLHoppingConfigCommonModeA_r13      = "FDD"; # choice -> (0, FDD) (1, TDD)
+             #sib2_interval_DLHoppingConfigCommonModeA_r13_val  = "int1";
+             #sib2_interval_DLHoppingConfigCommonModeB_r13      = "FDD"; # choice -> (0, FDD) (1, TDD)
+             #sib2_interval_DLHoppingConfigCommonModeB_r13_val  = "int2";
+
+             sib2_interval_ULHoppingConfigCommonModeA_r13      = "FDD";  # choice -> (0, FDD) (1, TDD)
+             sib2_interval_ULHoppingConfigCommonModeA_r13_val  = "int4"; #2
+#            sib2_interval_ULHoppingConfigCommonModeB_r13      = "FDD";  # choice -> (0, FDD) (1, TDD)
+#            sib2_interval_ULHoppingConfigCommonModeB_r13_val  = "int2"; #0
+
+#             sib2_mpdcch_pdsch_hoppingOffset_r13               = 1;
+          }
+
+          rach_preamblesGroupAConfig                = "DISABLE";
+
+          phich_duration                            = "NORMAL";
+          phich_resource                            = "ONESIXTH";
+          srs_enable                                = "DISABLE";
+
+      }
+
+
+
+}
+
+
+
+
+    );
+
+
+    srb1_parameters :
+    {
+        # timer_poll_retransmit = (ms) [5, 10, 15, 20,... 250, 300, 350, ... 500]
+        timer_poll_retransmit    = 80;
+
+        # timer_reordering = (ms) [0,5, ... 100, 110, 120, ... ,200]
+        timer_reordering         = 35;
+
+        # timer_reordering = (ms) [0,5, ... 250, 300, 350, ... ,500]
+        timer_status_prohibit    = 0;
+
+        # poll_pdu = [4, 8, 16, 32 , 64, 128, 256, infinity(>10000)]
+        poll_pdu                 =  4;
+
+        # poll_byte = (kB) [25,50,75,100,125,250,375,500,750,1000,1250,1500,2000,3000,infinity(>10000)]
+        poll_byte                =  99999;
+
+        # max_retx_threshold = [1, 2, 3, 4 , 6, 8, 16, 32]
+        max_retx_threshold       =  4;
+    }
+
+    # ------- SCTP definitions
+    SCTP :
+    {
+        # Number of streams to use in input/output
+        SCTP_INSTREAMS  = 2;
+        SCTP_OUTSTREAMS = 2;
+    };
+
+
+    ////////// MME parameters:
+    mme_ip_address      = ( { ipv4       = "127.0.0.3";
+                              ipv6       = "192:168:30::17";
+                              active     = "yes";
+                              preference = "ipv4";
+                            }
+                          );
+
+    NETWORK_INTERFACES :
+    {
+
+        ENB_INTERFACE_NAME_FOR_S1_MME            = "lo";
+        ENB_IPV4_ADDRESS_FOR_S1_MME              = "127.0.0.2/24";
+        ENB_INTERFACE_NAME_FOR_S1U               = "lo";
+        ENB_IPV4_ADDRESS_FOR_S1U                 = "127.0.0.4/24";
+        ENB_PORT_FOR_S1U                         = 2152; # Spec 2152
+
+        ENB_IPV4_ADDRESS_FOR_X2C                 = "127.0.0.2/24";
+        ENB_PORT_FOR_X2C                         = 36422; # Spec 36422
+    };
+
+    log_config :
+    {
+      global_log_level                      ="info";
+      global_log_verbosity                  ="medium";
+      hw_log_level                          ="info";
+      hw_log_verbosity                      ="medium";
+      phy_log_level                         ="info";
+      phy_log_verbosity                     ="medium";
+      mac_log_level                         ="info";
+      mac_log_verbosity                     ="high";
+      rlc_log_level                         ="info";
+      rlc_log_verbosity                     ="medium";
+      pdcp_log_level                        ="info";
+      pdcp_log_verbosity                    ="medium";
+      rrc_log_level                         ="info";
+      rrc_log_verbosity                     ="medium";
+   };
+  }
+);
+
+MACRLCs = (
+        {
+        num_cc	 = 1;
+        tr_s_preference = "local_L1";
+        tr_n_preference = "local_RRC";
+	phy_test_mode = 0;
+        puSch10xSnr     =  200;
+        puCch10xSnr     =  200;
+        }
+);
+
+L1s = (
+      {
+      num_cc = 1;
+      tr_n_preference = "local_mac";
+      }
+);
+
+RUs = (
+    {
+        local_rf       = "yes"
+        nb_tx          = 1
+        nb_rx          = 1
+        att_tx         = 0
+        att_rx         = 0;
+        bands          = [13];
+        max_pdschReferenceSignalPower = -27;
+        max_rxgain                    = 125;
+        eNB_instances  = [0];
+    }
+);
+
+log_config :
+     {
+       global_log_level                      ="info";
+       global_log_verbosity                  ="medium";
+       hw_log_level                          ="info";
+       hw_log_verbosity                      ="medium";
+       phy_log_level                         ="info";
+       phy_log_verbosity                     ="medium";
+       mac_log_level                         ="info";
+       mac_log_verbosity                     ="high";
+       rlc_log_level                         ="info";
+       rlc_log_verbosity                     ="medium";
+       pdcp_log_level                        ="info";
+       pdcp_log_verbosity                    ="medium";
+       rrc_log_level                         ="info";
+       rrc_log_verbosity                     ="medium";
+    };
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
new file mode 100644
index 0000000000000000000000000000000000000000..05d3135b8ab5b50714726dce4c8c7e3f7eec0f94
--- /dev/null
+++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band38.tm1.25PRB.iris030.conf
@@ -0,0 +1,263 @@
+Active_eNBs = ( "eNB_Eurecom_LTEBox");
+# Asn1_verbosity, choice in: none, info, annoying
+Asn1_verbosity = "none";
+
+eNBs =
+(
+ {
+    ////////// Identification parameters:
+    eNB_ID    =  0xe00;
+
+    cell_type =  "CELL_MACRO_ENB";
+
+    eNB_name  =  "eNB_Eurecom_LTEBox";
+
+    // Tracking area code, 0x0000 and 0xfffe are reserved values
+    tracking_area_code  =  1;
+
+    plmn_list = ( { mcc = 208; mnc = 92; mnc_length = 2; } );
+
+    tr_s_preference     = "local_mac"
+
+       ////////// Physical parameters:
+
+    component_carriers = (
+      {
+        node_function                                         = "eNodeB_3GPP";
+        node_timing                                           = "synch_to_ext_device";
+        node_synch_ref                                        = 0;
+        frame_type                                            = "TDD";
+        tdd_config                                            = 3;
+        tdd_config_s                                          = 0;
+        prefix_type                                           = "NORMAL";
+        eutra_band                                            = 38;
+        downlink_frequency                                    = 2580000000L;
+        uplink_frequency_offset                               = 0;
+        Nid_cell                                              = 10;
+        N_RB_DL                                               = 25;
+        Nid_cell_mbsfn                                        = 0;
+        nb_antenna_ports                                      = 1;
+        nb_antennas_tx                                        = 1;
+        nb_antennas_rx                                        = 1;
+        tx_gain                                               = 52;  # [~50 for DEV-FE, ~30 for CBRS-FE]
+        rx_gain                                               = 115; # [115 for DEV-FE, 90 for CBRS-FE]
+        pbch_repetition                                       = "FALSE";
+        prach_root                                            = 0;
+        prach_config_index                                    = 0;
+        prach_high_speed                                      = "DISABLE";
+        prach_zero_correlation                                = 1;
+        prach_freq_offset                                     = 2;
+        pucch_delta_shift                                     = 1;
+        pucch_nRB_CQI                                         = 1;
+        pucch_nCS_AN                                          = 0;
+        pucch_n1_AN                                           = 32;
+        pdsch_referenceSignalPower                            = -30;
+        pdsch_p_b                                             = 0;
+        pusch_n_SB                                            = 1;
+        pusch_enable64QAM                                     = "DISABLE";
+        pusch_hoppingMode                                     = "interSubFrame";
+        pusch_hoppingOffset                                   = 0;
+        pusch_groupHoppingEnabled                             = "ENABLE";
+        pusch_groupAssignment                                 = 0;
+        pusch_sequenceHoppingEnabled                          = "DISABLE";
+        pusch_nDMRS1                                          = 1;
+        phich_duration                                        = "NORMAL";
+        phich_resource                                        = "ONESIXTH";
+        srs_enable                                            = "DISABLE";
+        /*  srs_BandwidthConfig                               =;
+        srs_SubframeConfig                                    =;
+        srs_ackNackST                                         =;
+        srs_MaxUpPts                                          =;*/
+
+        pusch_p0_Nominal                                      = -70;
+        pusch_alpha                                           = "AL1";
+        pucch_p0_Nominal                                      = -96;
+        msg3_delta_Preamble                                   = 6;
+        pucch_deltaF_Format1                                  = "deltaF2";
+        pucch_deltaF_Format1b                                 = "deltaF3";
+        pucch_deltaF_Format2                                  = "deltaF0";
+        pucch_deltaF_Format2a                                 = "deltaF0";
+        pucch_deltaF_Format2b                                 = "deltaF0";
+
+        rach_numberOfRA_Preambles                             = 64;
+        rach_preamblesGroupAConfig                            = "DISABLE";
+        /*
+        rach_sizeOfRA_PreamblesGroupA                         = ;
+        rach_messageSizeGroupA                                = ;
+        rach_messagePowerOffsetGroupB                         = ;
+        */
+        rach_powerRampingStep                                 = 4;
+        rach_preambleInitialReceivedTargetPower               = -96;
+        rach_preambleTransMax                                 = 10;
+        rach_raResponseWindowSize                             = 10;
+        rach_macContentionResolutionTimer                     = 48;
+        rach_maxHARQ_Msg3Tx                                   = 4;
+
+        pcch_default_PagingCycle                              = 128;
+        pcch_nB                                               = "oneT";
+        bcch_modificationPeriodCoeff                          = 2;
+        ue_TimersAndConstants_t300                            = 1000;
+        ue_TimersAndConstants_t301                            = 1000;
+        ue_TimersAndConstants_t310                            = 1000;
+        ue_TimersAndConstants_t311                            = 10000;
+        ue_TimersAndConstants_n310                            = 20;
+        ue_TimersAndConstants_n311                            = 1;
+        ue_TransmissionMode                                   = 1;
+
+      //Parameters for SIB18
+      rxPool_sc_CP_Len                                        = "normal";
+      rxPool_sc_Period                                        = "sf40";
+      rxPool_data_CP_Len                                      = "normal";
+      rxPool_ResourceConfig_prb_Num                           = 20;
+      rxPool_ResourceConfig_prb_Start                         = 5;
+      rxPool_ResourceConfig_prb_End                           = 44;
+      rxPool_ResourceConfig_offsetIndicator_present           = "prSmall";
+      rxPool_ResourceConfig_offsetIndicator_choice            = 0;
+      rxPool_ResourceConfig_subframeBitmap_present            = "prBs40";
+      rxPool_ResourceConfig_subframeBitmap_choice_bs_buf              = "00000000000000000000";
+      rxPool_ResourceConfig_subframeBitmap_choice_bs_size             = 5;
+      rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused      = 0;
+/*    rxPool_dataHoppingConfig_hoppingParameter                       = 0;
+      rxPool_dataHoppingConfig_numSubbands                            = "ns1";
+      rxPool_dataHoppingConfig_rbOffset                               = 0;
+      rxPool_commTxResourceUC-ReqAllowed                              = "TRUE";
+*/
+      // Parameters for SIB19
+      discRxPool_cp_Len                                               = "normal"
+      discRxPool_discPeriod                                           = "rf32"
+      discRxPool_numRetx                                              = 1;
+      discRxPool_numRepetition                                        = 2;
+      discRxPool_ResourceConfig_prb_Num                               = 5;
+      discRxPool_ResourceConfig_prb_Start                             = 3;
+      discRxPool_ResourceConfig_prb_End                               = 21;
+      discRxPool_ResourceConfig_offsetIndicator_present               = "prSmall";
+      discRxPool_ResourceConfig_offsetIndicator_choice                = 0;
+      discRxPool_ResourceConfig_subframeBitmap_present                = "prBs40";
+      discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf          = "f0ffffffff";
+      discRxPool_ResourceConfig_subframeBitmap_choice_bs_size         = 5;
+      discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused  = 0;
+
+      }
+    );
+
+    srb1_parameters :
+    {
+        # timer_poll_retransmit = (ms) [5, 10, 15, 20,... 250, 300, 350, ... 500]
+        timer_poll_retransmit    = 80;
+
+        # timer_reordering = (ms) [0,5, ... 100, 110, 120, ... ,200]
+        timer_reordering         = 35;
+
+        # timer_reordering = (ms) [0,5, ... 250, 300, 350, ... ,500]
+        timer_status_prohibit    = 0;
+
+        # poll_pdu = [4, 8, 16, 32 , 64, 128, 256, infinity(>10000)]
+        poll_pdu                 =  4;
+
+        # poll_byte = (kB) [25,50,75,100,125,250,375,500,750,1000,1250,1500,2000,3000,infinity(>10000)]
+        poll_byte                =  99999;
+
+        # max_retx_threshold = [1, 2, 3, 4 , 6, 8, 16, 32]
+        max_retx_threshold       =  4;
+    }
+
+    # ------- SCTP definitions
+    SCTP :
+    {
+        # Number of streams to use in input/output
+        SCTP_INSTREAMS  = 2;
+        SCTP_OUTSTREAMS = 2;
+    };
+
+
+    ////////// MME parameters:
+    mme_ip_address      = ( { ipv4       = "127.0.0.20";
+                              ipv6       = "fe80::d65d:dfff:fe1d:f4d4";
+                              active     = "yes";
+                              preference = "ipv4";
+                            }
+                          );
+
+    NETWORK_INTERFACES :
+    {
+        ENB_INTERFACE_NAME_FOR_S1_MME            = "eno1";
+        ENB_IPV4_ADDRESS_FOR_S1_MME              = "127.0.0.10/8";
+        ENB_INTERFACE_NAME_FOR_S1U               = "enp5s0";
+        ENB_IPV4_ADDRESS_FOR_S1U                 = "127.0.0.10/8";
+        ENB_PORT_FOR_S1U                         = 2152; # Spec 2152
+
+        ENB_IPV4_ADDRESS_FOR_X2C                 = "127.0.0.10/8";
+        ENB_PORT_FOR_X2C                         = 36422; # Spec 36422
+    };
+  }
+);
+
+MACRLCs = (
+        {
+        num_cc = 1;
+        tr_s_preference = "local_L1";
+        tr_n_preference = "local_RRC";
+        phy_test_mode = 0;
+        puSch10xSnr     =  200;
+        puCch10xSnr     =  200;
+        }
+);
+
+L1s = (
+            {
+        num_cc = 1;
+        tr_n_preference = "local_mac";
+        }
+);
+
+RUs = (
+    {
+       local_rf       = "yes"
+         nb_tx          = 1
+         nb_rx          = 1
+         att_tx         = 0
+         att_rx         = 0;
+         bands          = [7];
+         max_pdschReferenceSignalPower = -27;
+         max_rxgain                    = 125;
+         eNB_instances  = [0];
+         #sdr_addrs = "RF3C000025";
+    }
+);
+
+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";
+};
+
+THREAD_STRUCT = (
+  {
+    #three config for level of parallelism "PARALLEL_SINGLE_THREAD", "PARALLEL_RU_L1_SPLIT", or "PARALLEL_RU_L1_TRX_SPLIT"
+    parallel_config    = "PARALLEL_RU_L1_TRX_SPLIT";
+    #two option for worker "WORKER_DISABLE" or "WORKER_ENABLE"
+    worker_config      = "WORKER_ENABLE";
+  }
+);
+
+     log_config :
+     {
+       global_log_level                      ="info";
+       global_log_verbosity                  ="medium";
+       hw_log_level                          ="info";
+       hw_log_verbosity                      ="medium";
+       phy_log_level                         ="info";
+       phy_log_verbosity                     ="medium";
+       mac_log_level                         ="info";
+       mac_log_verbosity                     ="high";
+       rlc_log_level                         ="info";
+       rlc_log_verbosity                     ="medium";
+       pdcp_log_level                        ="info";
+       pdcp_log_verbosity                    ="medium";
+       rrc_log_level                         ="info";
+       rrc_log_verbosity                     ="medium";
+    };
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
new file mode 100644
index 0000000000000000000000000000000000000000..44778f7a12c1b18ed2a332c190c615cb5e7757a6
--- /dev/null
+++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band42.tm1.25PRB.iris030.conf
@@ -0,0 +1,263 @@
+Active_eNBs = ( "eNB_Eurecom_LTEBox");
+# Asn1_verbosity, choice in: none, info, annoying
+Asn1_verbosity = "none";
+
+eNBs =
+(
+ {
+    ////////// Identification parameters:
+    eNB_ID    =  0xe00;
+
+    cell_type =  "CELL_MACRO_ENB";
+
+    eNB_name  =  "eNB_Eurecom_LTEBox";
+
+    // Tracking area code, 0x0000 and 0xfffe are reserved values
+    tracking_area_code  =  1;
+
+    plmn_list = ( { mcc = 208; mnc = 92; mnc_length = 2; } );
+
+    tr_s_preference     = "local_mac"
+
+       ////////// Physical parameters:
+
+    component_carriers = (
+      {
+        node_function                                         = "eNodeB_3GPP";
+	node_timing                                           = "synch_to_ext_device";
+	node_synch_ref                                        = 0;
+        frame_type					      = "TDD";
+        tdd_config 					      = 1;
+        tdd_config_s            			      = 0;
+        prefix_type             			      = "NORMAL";
+        eutra_band              			      = 42;
+        downlink_frequency      			      = 3500000000L;
+        uplink_frequency_offset 			      = 0;
+        Nid_cell					      = 10;
+        N_RB_DL                 			      = 25;
+        Nid_cell_mbsfn          			      = 0;
+        nb_antenna_ports          			      = 1;
+        nb_antennas_tx          			      = 1;
+        nb_antennas_rx          			      = 1;
+        tx_gain                                               = 48;  # [~50 for DEV-FE, ~30 for CBRS-FE]
+        rx_gain                                               = 80; # [115 for DEV-FE, 90 for CBRS-FE]
+        pbch_repetition                                       = "FALSE";
+        prach_root              			      = 0;
+        prach_config_index      			      = 0;
+        prach_high_speed        			      = "DISABLE";
+        prach_zero_correlation  			      = 1;
+        prach_freq_offset       			      = 2;
+        pucch_delta_shift       			      = 1;
+        pucch_nRB_CQI           			      = 1;
+        pucch_nCS_AN            			      = 0;
+        pucch_n1_AN             			      = 32;
+        pdsch_referenceSignalPower 			      = -30;
+        pdsch_p_b                  			      = 0;
+        pusch_n_SB                 			      = 1;
+        pusch_enable64QAM          			      = "DISABLE";
+        pusch_hoppingMode                                     = "interSubFrame";
+        pusch_hoppingOffset                                   = 0;
+        pusch_groupHoppingEnabled  			      = "ENABLE";
+        pusch_groupAssignment      			      = 0;
+        pusch_sequenceHoppingEnabled		   	      = "DISABLE";
+        pusch_nDMRS1                                          = 1;
+        phich_duration                                        = "NORMAL";
+        phich_resource                                        = "ONESIXTH";
+        srs_enable                                            = "DISABLE";
+        /*  srs_BandwidthConfig                               =;
+        srs_SubframeConfig                                    =;
+        srs_ackNackST                                         =;
+        srs_MaxUpPts                                          =;*/
+
+        pusch_p0_Nominal                                   = -70;
+        pusch_alpha                                        = "AL1";
+        pucch_p0_Nominal                                   = -96;
+        msg3_delta_Preamble                                = 6;
+        pucch_deltaF_Format1                               = "deltaF2";
+        pucch_deltaF_Format1b                              = "deltaF3";
+        pucch_deltaF_Format2                               = "deltaF0";
+        pucch_deltaF_Format2a                              = "deltaF0";
+        pucch_deltaF_Format2b		    	           = "deltaF0";
+
+        rach_numberOfRA_Preambles                          = 64;
+        rach_preamblesGroupAConfig                         = "DISABLE";
+        /*
+        rach_sizeOfRA_PreamblesGroupA                      = ;
+        rach_messageSizeGroupA                             = ;
+        rach_messagePowerOffsetGroupB                      = ;
+        */
+        rach_powerRampingStep                              = 4;
+        rach_preambleInitialReceivedTargetPower            = -96;
+        rach_preambleTransMax                              = 10;
+        rach_raResponseWindowSize                          = 10;
+        rach_macContentionResolutionTimer                  = 48;
+        rach_maxHARQ_Msg3Tx                                = 4;
+
+        pcch_default_PagingCycle                           = 128;
+        pcch_nB                                            = "oneT";
+        bcch_modificationPeriodCoeff			      = 2;
+        ue_TimersAndConstants_t300			      = 1000;
+        ue_TimersAndConstants_t301			      = 1000;
+        ue_TimersAndConstants_t310			      = 1000;
+        ue_TimersAndConstants_t311			      = 10000;
+        ue_TimersAndConstants_n310			      = 20;
+        ue_TimersAndConstants_n311			      = 1;
+	ue_TransmissionMode				      = 1;
+
+      //Parameters for SIB18
+      rxPool_sc_CP_Len                                       = "normal";
+      rxPool_sc_Period                                       = "sf40";
+      rxPool_data_CP_Len                                     = "normal";
+      rxPool_ResourceConfig_prb_Num                          = 20;
+      rxPool_ResourceConfig_prb_Start                        = 5;
+      rxPool_ResourceConfig_prb_End                          = 44;
+      rxPool_ResourceConfig_offsetIndicator_present          = "prSmall";
+      rxPool_ResourceConfig_offsetIndicator_choice           = 0;
+      rxPool_ResourceConfig_subframeBitmap_present           = "prBs40";
+      rxPool_ResourceConfig_subframeBitmap_choice_bs_buf              = "00000000000000000000";
+      rxPool_ResourceConfig_subframeBitmap_choice_bs_size             = 5;
+      rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused      = 0;
+/*    rxPool_dataHoppingConfig_hoppingParameter                       = 0;
+      rxPool_dataHoppingConfig_numSubbands                            = "ns1";
+      rxPool_dataHoppingConfig_rbOffset                               = 0;
+      rxPool_commTxResourceUC-ReqAllowed                              = "TRUE";
+*/
+      // Parameters for SIB19
+      discRxPool_cp_Len                                               = "normal"
+      discRxPool_discPeriod                                           = "rf32"
+      discRxPool_numRetx                                              = 1;
+      discRxPool_numRepetition                                        = 2;
+      discRxPool_ResourceConfig_prb_Num                               = 5;
+      discRxPool_ResourceConfig_prb_Start                             = 3;
+      discRxPool_ResourceConfig_prb_End                               = 21;
+      discRxPool_ResourceConfig_offsetIndicator_present               = "prSmall";
+      discRxPool_ResourceConfig_offsetIndicator_choice                = 0;
+      discRxPool_ResourceConfig_subframeBitmap_present                = "prBs40";
+      discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf          = "f0ffffffff";
+      discRxPool_ResourceConfig_subframeBitmap_choice_bs_size         = 5;
+      discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused  = 0;
+
+      }
+    );
+
+    srb1_parameters :
+    {
+        # timer_poll_retransmit = (ms) [5, 10, 15, 20,... 250, 300, 350, ... 500]
+        timer_poll_retransmit    = 80;
+
+        # timer_reordering = (ms) [0,5, ... 100, 110, 120, ... ,200]
+        timer_reordering         = 35;
+
+        # timer_reordering = (ms) [0,5, ... 250, 300, 350, ... ,500]
+        timer_status_prohibit    = 0;
+
+        # poll_pdu = [4, 8, 16, 32 , 64, 128, 256, infinity(>10000)]
+        poll_pdu                 =  4;
+
+        # poll_byte = (kB) [25,50,75,100,125,250,375,500,750,1000,1250,1500,2000,3000,infinity(>10000)]
+        poll_byte                =  99999;
+
+        # max_retx_threshold = [1, 2, 3, 4 , 6, 8, 16, 32]
+        max_retx_threshold       =  4;
+    }
+
+    # ------- SCTP definitions
+    SCTP :
+    {
+        # Number of streams to use in input/output
+        SCTP_INSTREAMS  = 2;
+        SCTP_OUTSTREAMS = 2;
+    };
+
+
+    ////////// MME parameters:
+    mme_ip_address      = ( { ipv4       = "127.0.0.20";
+                              ipv6       = "fe80::d65d:dfff:fe1d:f4d4";
+                              active     = "yes";
+                              preference = "ipv4";
+                            }
+                          );
+
+    NETWORK_INTERFACES :
+    {
+        ENB_INTERFACE_NAME_FOR_S1_MME            = "eno1";
+        ENB_IPV4_ADDRESS_FOR_S1_MME              = "127.0.0.10/8";
+        ENB_INTERFACE_NAME_FOR_S1U               = "enp5s0";
+        ENB_IPV4_ADDRESS_FOR_S1U                 = "127.0.0.10/8";
+        ENB_PORT_FOR_S1U                         = 2152; # Spec 2152
+
+        ENB_IPV4_ADDRESS_FOR_X2C                 = "127.0.0.10/8";
+        ENB_PORT_FOR_X2C                         = 36422; # Spec 36422
+    };
+  }
+);
+
+MACRLCs = (
+	{
+	num_cc = 1;
+	tr_s_preference = "local_L1";
+	tr_n_preference = "local_RRC";
+	phy_test_mode = 0;
+        puSch10xSnr     =  200;
+        puCch10xSnr     =  200;
+        }
+);
+
+L1s = (
+      {
+	num_cc = 1;
+	tr_n_preference = "local_mac";
+        }
+);
+
+RUs = (
+    {
+       local_rf       = "yes"
+         nb_tx          = 1;
+         nb_rx          = 1;
+         att_tx         = 44;  #apparently this is being used as tx_gain...
+         att_rx         = 0;  #apparently max_rxgain - att_rx -83 is what is used for rx_gain (at least for 5 MHz)
+         bands          = [7];
+         max_pdschReferenceSignalPower = -27;
+         max_rxgain                    = 107;
+         eNB_instances  = [0];
+         #sdr_addrs = "RF3E000025";
+    }
+);
+
+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";
+};
+
+THREAD_STRUCT = (
+  {
+    #three config for level of parallelism "PARALLEL_SINGLE_THREAD", "PARALLEL_RU_L1_SPLIT", or "PARALLEL_RU_L1_TRX_SPLIT"
+    parallel_config    = "PARALLEL_RU_L1_TRX_SPLIT";
+    #two option for worker "WORKER_DISABLE" or "WORKER_ENABLE"
+    worker_config      = "WORKER_ENABLE";
+  }
+);
+
+     log_config :
+     {
+       global_log_level                      ="info";
+       global_log_verbosity                  ="medium";
+       hw_log_level                          ="info";
+       hw_log_verbosity                      ="medium";
+       phy_log_level                         ="info";
+       phy_log_verbosity                     ="medium";
+       mac_log_level                         ="info";
+       mac_log_verbosity                     ="high";
+       rlc_log_level                         ="info";
+       rlc_log_verbosity                     ="medium";
+       pdcp_log_level                        ="info";
+       pdcp_log_verbosity                    ="medium";
+       rrc_log_level                         ="info";
+       rrc_log_verbosity                     ="medium";
+    };
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 60b47c5c493e62a245dbbcb8d50a5267a21b9ed8..728492ee835aaf2607ea6aefd09eb5a7be2cc880 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
@@ -15,7 +15,7 @@ eNBs =
     // Tracking area code, 0x0000 and 0xfffe are reserved values
     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"
 
@@ -138,7 +138,7 @@ eNBs =
 
 
     ////////// MME parameters:
-    mme_ip_address      = ( { ipv4       = "192.168.12.26";
+    mme_ip_address      = ( { ipv4       = "192.168.12.148";
                               ipv6       = "192:168:30::17";
                               active     = "yes";
                               preference = "ipv4";
@@ -187,7 +187,7 @@ RUs = (
          max_pdschReferenceSignalPower = -27;
          max_rxgain                    = 116;
          eNB_instances  = [0];
-
+       sdr_addrs      = "type=x300";
     }
 );  
 
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
new file mode 100644
index 0000000000000000000000000000000000000000..4fb6a34a8be3957c77e941bef3ec656a38b31757
--- /dev/null
+++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.25PRB.iris030.conf
@@ -0,0 +1,263 @@
+Active_eNBs = ( "eNB_Eurecom_LTEBox");
+# Asn1_verbosity, choice in: none, info, annoying
+Asn1_verbosity = "none";
+
+eNBs =
+(
+ {
+    ////////// Identification parameters:
+    eNB_ID    =  0xe00;
+
+    cell_type =  "CELL_MACRO_ENB";
+
+    eNB_name  =  "eNB_Eurecom_LTEBox";
+
+    // Tracking area code, 0x0000 and 0xfffe are reserved values
+    tracking_area_code  =  1;
+
+    plmn_list = ( { mcc = 208; mnc = 92; mnc_length = 2; } );
+
+    tr_s_preference     = "local_mac"
+
+       ////////// Physical parameters:
+
+    component_carriers = (
+      {
+        node_function                                         = "eNodeB_3GPP";
+        node_timing                                           = "synch_to_ext_device";
+        node_synch_ref                                        = 0;
+        frame_type                                            = "FDD";
+        tdd_config                                            = 3;
+        tdd_config_s                                          = 0;
+        prefix_type                                           = "NORMAL";
+        eutra_band                                            = 7;
+        downlink_frequency                                    = 2660000000L;
+        uplink_frequency_offset                               = -120000000;
+        Nid_cell                                              = 10;
+        N_RB_DL                                               = 25;
+        Nid_cell_mbsfn                                        = 0;
+        nb_antenna_ports                                      = 1;
+        nb_antennas_tx                                        = 1;
+        nb_antennas_rx                                        = 1;
+        tx_gain                                               = 52;  # [~50 for DEV-FE, ~30 for CBRS-FE]
+        rx_gain                                               = 115; # [115 for DEV-FE, 90 for CBRS-FE]
+        pbch_repetition                                       = "FALSE";
+        prach_root                                            = 0;
+        prach_config_index                                    = 0;
+        prach_high_speed                                      = "DISABLE";
+        prach_zero_correlation                                = 1;
+        prach_freq_offset                                     = 2;
+        pucch_delta_shift                                     = 1;
+        pucch_nRB_CQI                                         = 1;
+        pucch_nCS_AN                                          = 0;
+        pucch_n1_AN                                           = 32;
+        pdsch_referenceSignalPower                            = -30;
+        pdsch_p_b                                             = 0;
+        pusch_n_SB                                            = 1;
+        pusch_enable64QAM                                     = "DISABLE";
+        pusch_hoppingMode                                     = "interSubFrame";
+        pusch_hoppingOffset                                   = 0;
+        pusch_groupHoppingEnabled                             = "ENABLE";
+        pusch_groupAssignment                                 = 0;
+        pusch_sequenceHoppingEnabled                          = "DISABLE";
+        pusch_nDMRS1                                          = 1;
+        phich_duration                                        = "NORMAL";
+        phich_resource                                        = "ONESIXTH";
+        srs_enable                                            = "DISABLE";
+        /*  srs_BandwidthConfig                                =;
+        srs_SubframeConfig                                    =;
+        srs_ackNackST                                         =;
+        srs_MaxUpPts                                          =;*/
+
+        pusch_p0_Nominal                                      = -70;
+        pusch_alpha                                           = "AL1";
+        pucch_p0_Nominal                                      = -96;
+        msg3_delta_Preamble                                   = 6;
+        pucch_deltaF_Format1                                  = "deltaF2";
+        pucch_deltaF_Format1b                                 = "deltaF3";
+        pucch_deltaF_Format2                                  = "deltaF0";
+        pucch_deltaF_Format2a                                 = "deltaF0";
+        pucch_deltaF_Format2b                                 = "deltaF0";
+
+        rach_numberOfRA_Preambles                             = 64;
+        rach_preamblesGroupAConfig                            = "DISABLE";
+        /*
+        rach_sizeOfRA_PreamblesGroupA                         = ;
+        rach_messageSizeGroupA                                = ;
+        rach_messagePowerOffsetGroupB                         = ;
+        */
+        rach_powerRampingStep                                 = 4;
+        rach_preambleInitialReceivedTargetPower               = -96;
+        rach_preambleTransMax                                 = 10;
+        rach_raResponseWindowSize                             = 10;
+        rach_macContentionResolutionTimer                     = 48;
+        rach_maxHARQ_Msg3Tx                                   = 4;
+
+        pcch_default_PagingCycle                              = 128;
+        pcch_nB                                               = "oneT";
+        bcch_modificationPeriodCoeff                          = 2;
+        ue_TimersAndConstants_t300                            = 1000;
+        ue_TimersAndConstants_t301                            = 1000;
+        ue_TimersAndConstants_t310                            = 1000;
+        ue_TimersAndConstants_t311                            = 10000;
+        ue_TimersAndConstants_n310                            = 20;
+        ue_TimersAndConstants_n311                            = 1;
+        ue_TransmissionMode                                   = 1;
+
+      //Parameters for SIB18
+      rxPool_sc_CP_Len                                        = "normal";
+      rxPool_sc_Period                                        = "sf40";
+      rxPool_data_CP_Len                                      = "normal";
+      rxPool_ResourceConfig_prb_Num                           = 20;
+      rxPool_ResourceConfig_prb_Start                         = 5;
+      rxPool_ResourceConfig_prb_End                           = 44;
+      rxPool_ResourceConfig_offsetIndicator_present           = "prSmall";
+      rxPool_ResourceConfig_offsetIndicator_choice            = 0;
+      rxPool_ResourceConfig_subframeBitmap_present            = "prBs40";
+      rxPool_ResourceConfig_subframeBitmap_choice_bs_buf              = "00000000000000000000";
+      rxPool_ResourceConfig_subframeBitmap_choice_bs_size             = 5;
+      rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused      = 0;
+/*    rxPool_dataHoppingConfig_hoppingParameter                       = 0;
+      rxPool_dataHoppingConfig_numSubbands                            = "ns1";
+      rxPool_dataHoppingConfig_rbOffset                               = 0;
+      rxPool_commTxResourceUC-ReqAllowed                              = "TRUE";
+*/
+      // Parameters for SIB19
+      discRxPool_cp_Len                                               = "normal"
+      discRxPool_discPeriod                                           = "rf32"
+      discRxPool_numRetx                                              = 1;
+      discRxPool_numRepetition                                        = 2;
+      discRxPool_ResourceConfig_prb_Num                               = 5;
+      discRxPool_ResourceConfig_prb_Start                             = 3;
+      discRxPool_ResourceConfig_prb_End                               = 21;
+      discRxPool_ResourceConfig_offsetIndicator_present               = "prSmall";
+      discRxPool_ResourceConfig_offsetIndicator_choice                = 0;
+      discRxPool_ResourceConfig_subframeBitmap_present                = "prBs40";
+      discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf          = "f0ffffffff";
+      discRxPool_ResourceConfig_subframeBitmap_choice_bs_size         = 5;
+      discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused  = 0;
+
+      }
+    );
+
+    srb1_parameters :
+    {
+        # timer_poll_retransmit = (ms) [5, 10, 15, 20,... 250, 300, 350, ... 500]
+        timer_poll_retransmit    = 80;
+
+        # timer_reordering = (ms) [0,5, ... 100, 110, 120, ... ,200]
+        timer_reordering         = 35;
+
+        # timer_reordering = (ms) [0,5, ... 250, 300, 350, ... ,500]
+        timer_status_prohibit    = 0;
+
+        # poll_pdu = [4, 8, 16, 32 , 64, 128, 256, infinity(>10000)]
+        poll_pdu                 =  4;
+
+        # poll_byte = (kB) [25,50,75,100,125,250,375,500,750,1000,1250,1500,2000,3000,infinity(>10000)]
+        poll_byte                =  99999;
+
+        # max_retx_threshold = [1, 2, 3, 4 , 6, 8, 16, 32]
+        max_retx_threshold       =  4;
+    }
+
+    # ------- SCTP definitions
+    SCTP :
+    {
+        # Number of streams to use in input/output
+        SCTP_INSTREAMS  = 2;
+        SCTP_OUTSTREAMS = 2;
+    };
+
+
+    ////////// MME parameters:
+    mme_ip_address      = ( { ipv4       = "127.0.0.20";
+                              ipv6       = "fe80::d65d:dfff:fe1d:f4d4";
+                              active     = "yes";
+                              preference = "ipv4";
+                            }
+                          );
+
+    NETWORK_INTERFACES :
+    {
+        ENB_INTERFACE_NAME_FOR_S1_MME            = "lo";
+        ENB_IPV4_ADDRESS_FOR_S1_MME              = "127.0.0.10/8";
+        ENB_INTERFACE_NAME_FOR_S1U               = "lo";
+        ENB_IPV4_ADDRESS_FOR_S1U                 = "127.0.0.10/8";
+        ENB_PORT_FOR_S1U                         = 2152; # Spec 2152
+
+        ENB_IPV4_ADDRESS_FOR_X2C                 = "127.0.0.10/8";
+        ENB_PORT_FOR_X2C                         = 36422; # Spec 36422
+    };
+  }
+);
+
+MACRLCs = (
+        {
+        num_cc = 1;
+        tr_s_preference = "local_L1";
+        tr_n_preference = "local_RRC";
+        phy_test_mode = 0;
+        puSch10xSnr     =  200;
+        puCch10xSnr     =  200;
+        }
+);
+
+L1s = (
+            {
+        num_cc = 1;
+        tr_n_preference = "local_mac";
+        }
+);
+
+RUs = (
+    {
+       local_rf       = "yes"
+         nb_tx          = 1
+         nb_rx          = 1
+         att_tx         = 0
+         att_rx         = 0;
+         bands          = [7];
+         max_pdschReferenceSignalPower = -27;
+         max_rxgain                    = 125;
+         eNB_instances  = [0];
+         sdr_addrs = "RF3E000028";
+    }
+);
+
+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";
+};
+
+THREAD_STRUCT = (
+  {
+    #three config for level of parallelism "PARALLEL_SINGLE_THREAD", "PARALLEL_RU_L1_SPLIT", or "PARALLEL_RU_L1_TRX_SPLIT"
+    parallel_config    = "PARALLEL_RU_L1_TRX_SPLIT";
+    #two option for worker "WORKER_DISABLE" or "WORKER_ENABLE"
+    worker_config      = "WORKER_ENABLE";
+  }
+);
+
+     log_config :
+     {
+       global_log_level                      ="info";
+       global_log_verbosity                  ="medium";
+       hw_log_level                          ="info";
+       hw_log_verbosity                      ="medium";
+       phy_log_level                         ="info";
+       phy_log_verbosity                     ="medium";
+       mac_log_level                         ="info";
+       mac_log_verbosity                     ="high";
+       rlc_log_level                         ="info";
+       rlc_log_verbosity                     ="medium";
+       pdcp_log_level                        ="info";
+       pdcp_log_verbosity                    ="medium";
+       rrc_log_level                         ="info";
+       rrc_log_verbosity                     ="medium";
+    };
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 ced031163d242aef51b065bf8a73cdc5142547cc..4d98280b3f25cba9b2eb41ae9a75ce6167259e66 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
@@ -172,7 +172,7 @@ eNBs =
 
 
     ////////// MME parameters:
-    mme_ip_address      = ( { ipv4       = "127.0.0.3";
+    mme_ip_address      = ( { ipv4       = "192.168.12.26";
                               ipv6       = "192:168:30::17";
                               active     = "yes";
                               preference = "ipv4";
@@ -181,14 +181,24 @@ eNBs =
 
     NETWORK_INTERFACES :
     {
-        ENB_INTERFACE_NAME_FOR_S1_MME            = "lo";
-        ENB_IPV4_ADDRESS_FOR_S1_MME              = "127.0.0.2/24";
-        ENB_INTERFACE_NAME_FOR_S1U               = "lo";
-        ENB_IPV4_ADDRESS_FOR_S1U                 = "127.0.0.5/24";
+        #ENB_INTERFACE_NAME_FOR_S1_MME            = "lo";
+        #ENB_IPV4_ADDRESS_FOR_S1_MME              = "127.0.0.2/24";
+        #ENB_INTERFACE_NAME_FOR_S1U               = "lo";
+        #ENB_IPV4_ADDRESS_FOR_S1U                 = "127.0.0.5/24";
+        #ENB_PORT_FOR_S1U                         = 2152; # Spec 2152
+
+        #ENB_IPV4_ADDRESS_FOR_X2C                 = "127.0.0.2/24";
+        #ENB_PORT_FOR_X2C                         = 36422; # Spec 36422
+
+        ENB_INTERFACE_NAME_FOR_S1_MME            = "enp0s31f6";
+        ENB_IPV4_ADDRESS_FOR_S1_MME              = "192.168.12.188/24";
+        ENB_INTERFACE_NAME_FOR_S1U               = "enp0s31f6";
+        ENB_IPV4_ADDRESS_FOR_S1U                 = "192.168.12.188/24";
         ENB_PORT_FOR_S1U                         = 2152; # Spec 2152
 
-        ENB_IPV4_ADDRESS_FOR_X2C                 = "127.0.0.2/24";
+        ENB_IPV4_ADDRESS_FOR_X2C                 = "192.168.12.188/24";
         ENB_PORT_FOR_X2C                         = 36422; # Spec 36422
+
     };
   }
 );
@@ -196,7 +206,7 @@ eNBs =
 MACRLCs = (
 	{
 	num_cc = 1;
-      	local_s_if_name  = "lo";			  
+        local_s_if_name  = "lo:";
       	remote_s_address = "127.0.0.1";
     	local_s_address  = "127.0.0.2"; 
     	local_s_portc    = 50001;	
diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rru.oaisim.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rru.oaisim.conf
index 4cf026ff942b34d70eb529a981ef676c54e6c33e..750936cfea4a8b7ca72c391e8b8d1307992f757e 100644
--- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rru.oaisim.conf
+++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rru.oaisim.conf
@@ -31,7 +31,7 @@ log_config = {
       global_log_verbosity                  ="medium";
       hw_log_level                          ="info";
       hw_log_verbosity                      ="medium";
-      phy_log_level                         ="info`";
+      phy_log_level                         ="info";
       phy_log_verbosity                     ="medium";
       mac_log_level                         ="info";
       mac_log_verbosity                     ="high";
diff --git a/targets/RT/USER/.ue.nvram b/targets/RT/USER/.ue.nvram
deleted file mode 100644
index 17469c87add15bffcfe07e54a19cd93743f18818..0000000000000000000000000000000000000000
Binary files a/targets/RT/USER/.ue.nvram and /dev/null differ
diff --git a/targets/RT/USER/.ue_emm.nvram b/targets/RT/USER/.ue_emm.nvram
deleted file mode 100644
index e858ba8cce57931e7fdf05ce434c22cd6bb6daa5..0000000000000000000000000000000000000000
Binary files a/targets/RT/USER/.ue_emm.nvram and /dev/null differ
diff --git a/targets/RT/USER/.usim.nvram b/targets/RT/USER/.usim.nvram
deleted file mode 100644
index 4e9adcd0d341f8826310a2c6a95a7f518dc14d97..0000000000000000000000000000000000000000
Binary files a/targets/RT/USER/.usim.nvram and /dev/null differ
diff --git a/targets/RT/USER/lte-enb.c b/targets/RT/USER/lte-enb.c
index 2e70a57f4d16a679c0397e4276dfd3303271399c..293462cc020aed36b7e6629122881fbb68dc7a87 100644
--- a/targets/RT/USER/lte-enb.c
+++ b/targets/RT/USER/lte-enb.c
@@ -77,16 +77,16 @@
 
 
 #ifndef OPENAIR2
-#include "UTIL/OTG/otg_extern.h"
+  #include "UTIL/OTG/otg_extern.h"
 #endif
 
 #if defined(ENABLE_ITTI)
-# if defined(ENABLE_USE_MME)
-#   include "s1ap_eNB.h"
-#ifdef PDCP_USE_NETLINK
-#   include "SIMULATION/ETH_TRANSPORT/proto.h"
-#endif
-# endif
+  #if defined(ENABLE_USE_MME)
+    #include "s1ap_eNB.h"
+    #ifdef PDCP_USE_NETLINK
+      #include "SIMULATION/ETH_TRANSPORT/proto.h"
+    #endif
+  #endif
 #endif
 
 #include "T.h"
@@ -106,8 +106,8 @@ struct timing_info_t {
 
 
 #if defined(ENABLE_ITTI)
-extern volatile int             start_eNB;
-extern volatile int             start_UE;
+  extern volatile int             start_eNB;
+  extern volatile int             start_UE;
 #endif
 extern volatile int                    oai_exit;
 
@@ -143,14 +143,12 @@ extern double cpuf;
 void init_eNB(int,int);
 void stop_eNB(int nb_inst);
 
-int wakeup_tx(PHY_VARS_eNB *eNB,RU_proc_t *ru_proc);
-int wakeup_txfh(eNB_rxtx_proc_t *proc,RU_proc_t *ru_proc);
+int wakeup_tx(PHY_VARS_eNB *eNB);
+int wakeup_txfh(L1_rxtx_proc_t *proc,PHY_VARS_eNB *eNB);
 void wakeup_prach_eNB(PHY_VARS_eNB *eNB,RU_t *ru,int frame,int subframe);
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-void wakeup_prach_eNB_br(PHY_VARS_eNB *eNB,RU_t *ru,int frame,int subframe);
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  void wakeup_prach_eNB_br(PHY_VARS_eNB *eNB,RU_t *ru,int frame,int subframe);
 #endif
-extern PARALLEL_CONF_t get_thread_parallel_conf(void);
-extern WORKER_CONF_t   get_thread_worker_conf(void);
 
 extern uint8_t nfapi_mode;
 extern void oai_subframe_ind(uint16_t sfn, uint16_t sf);
@@ -160,19 +158,24 @@ extern void add_subframe(uint16_t *frameP, uint16_t *subframeP, int offset);
 #define TICK_TO_US(ts) (ts.trials==0?0:ts.diff/ts.trials)
 
 
-static inline int rxtx(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc, char *thread_name) {
+static inline int rxtx(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc, char *thread_name) {
   start_meas(&softmodem_stats_rxtx_sf);
+  //L1_rxtx_proc_t *L1_proc_tx = &eNB->proc.L1_proc_tx;
 
   // *******************************************************************
 
+#if defined(PRE_SCD_THREAD)
+    RU_t *ru = RC.ru[0];
+#endif
+  if (eNB ==NULL) {
+      LOG_D(PHY,"%s:%d: rxtx invalid argument, eNB pointer is NULL",__FILE__,__LINE__);
+      return -1;
+  }
   if (nfapi_mode == 1) {
-
     // I am a PNF and I need to let nFAPI know that we have a (sub)frame tick
     uint16_t frame = proc->frame_rx;
     uint16_t subframe = proc->subframe_rx;
-
     //add_subframe(&frame, &subframe, 4);
-
     //oai_subframe_ind(proc->frame_tx, proc->subframe_tx);
     //LOG_D(PHY, "oai_subframe_ind(frame:%u, subframe:%d) - NOT CALLED ********\n", frame, subframe);
     start_meas(&nfapi_meas);
@@ -185,14 +188,14 @@ static inline int rxtx(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc, char *thread_nam
         eNB->UL_INFO.rach_ind.rach_indication_body.number_of_preambles ||
         eNB->UL_INFO.cqi_ind.number_of_cqis
        ) {
-      LOG_D(PHY, "UL_info[rx_ind:%05d:%d harqs:%05d:%d crcs:%05d:%d preambles:%05d:%d cqis:%d] RX:%04d%d TX:%04d%d num_pdcch_symbols:%d\n", 
-          NFAPI_SFNSF2DEC(eNB->UL_INFO.rx_ind.sfn_sf),   eNB->UL_INFO.rx_ind.rx_indication_body.number_of_pdus, 
-          NFAPI_SFNSF2DEC(eNB->UL_INFO.harq_ind.sfn_sf), eNB->UL_INFO.harq_ind.harq_indication_body.number_of_harqs, 
-          NFAPI_SFNSF2DEC(eNB->UL_INFO.crc_ind.sfn_sf),  eNB->UL_INFO.crc_ind.crc_indication_body.number_of_crcs, 
-          NFAPI_SFNSF2DEC(eNB->UL_INFO.rach_ind.sfn_sf), eNB->UL_INFO.rach_ind.rach_indication_body.number_of_preambles,
-          eNB->UL_INFO.cqi_ind.number_of_cqis, 
-          proc->frame_rx, proc->subframe_rx, 
-      proc->frame_tx, proc->subframe_tx, eNB->pdcch_vars[proc->subframe_tx&1].num_pdcch_symbols);
+      LOG_D(PHY, "UL_info[rx_ind:%05d:%d harqs:%05d:%d crcs:%05d:%d preambles:%05d:%d cqis:%d] RX:%04d%d TX:%04d%d num_pdcch_symbols:%d\n",
+            NFAPI_SFNSF2DEC(eNB->UL_INFO.rx_ind.sfn_sf),   eNB->UL_INFO.rx_ind.rx_indication_body.number_of_pdus,
+            NFAPI_SFNSF2DEC(eNB->UL_INFO.harq_ind.sfn_sf), eNB->UL_INFO.harq_ind.harq_indication_body.number_of_harqs,
+            NFAPI_SFNSF2DEC(eNB->UL_INFO.crc_ind.sfn_sf),  eNB->UL_INFO.crc_ind.crc_indication_body.number_of_crcs,
+            NFAPI_SFNSF2DEC(eNB->UL_INFO.rach_ind.sfn_sf), eNB->UL_INFO.rach_ind.rach_indication_body.number_of_preambles,
+            eNB->UL_INFO.cqi_ind.number_of_cqis,
+            proc->frame_rx, proc->subframe_rx,
+            proc->frame_tx, proc->subframe_tx, eNB->pdcch_vars[proc->subframe_tx&1].num_pdcch_symbols);
     }
   }
 
@@ -203,13 +206,12 @@ static inline int rxtx(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc, char *thread_nam
 
   // ****************************************
   // Common RX procedures subframe n
-
   T(T_ENB_PHY_DL_TICK, T_INT(eNB->Mod_id), T_INT(proc->frame_tx), T_INT(proc->subframe_tx));
 
   // if this is IF5 or 3GPP_eNB
-  if (eNB && eNB->RU_list && eNB->RU_list[0] && eNB->RU_list[0]->function < NGFI_RAU_IF4p5) {
+  if (eNB->RU_list && eNB->RU_list[0] && eNB->RU_list[0]->function < NGFI_RAU_IF4p5) {
     wakeup_prach_eNB(eNB,NULL,proc->frame_rx,proc->subframe_rx);
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
     wakeup_prach_eNB_br(eNB,NULL,proc->frame_rx,proc->subframe_rx);
 #endif
   }
@@ -220,104 +222,123 @@ static inline int rxtx(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc, char *thread_nam
   if (nfapi_mode == 0 || nfapi_mode == 1) {
     phy_procedures_eNB_uespec_RX(eNB, proc);
   }
-  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ULSCH_SCHEDULER , 1 );
 
-  if(get_thread_parallel_conf() == PARALLEL_RU_L1_TRX_SPLIT){
-    if(wait_on_condition(&proc[1].mutex_rxtx,&proc[1].cond_rxtx,&proc[1].pipe_ready,"wakeup_tx")<0) {
-      LOG_E(PHY,"Frame %d, subframe %d: TX1 not ready\n",proc[1].frame_rx,proc[1].subframe_rx);
-      return(-1);
+  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ULSCH_SCHEDULER, 1 );
+
+#if defined(PRE_SCD_THREAD)
+    if (nfapi_mode == 2){
+      new_dlsch_ue_select_tbl_in_use = dlsch_ue_select_tbl_in_use;
+      dlsch_ue_select_tbl_in_use = !dlsch_ue_select_tbl_in_use;
+
+// L2-emulator can work only one eNB.
+//      memcpy(&pre_scd_eNB_UE_stats,&RC.mac[ru->eNB_list[0]->Mod_id]->UE_list.eNB_UE_stats, sizeof(eNB_UE_STATS)*MAX_NUM_CCs*NUMBER_OF_UE_MAX);
+//      memcpy(&pre_scd_activeUE, &RC.mac[ru->eNB_list[0]->Mod_id]->UE_list.active, sizeof(boolean_t)*NUMBER_OF_UE_MAX);
+      memcpy(&pre_scd_eNB_UE_stats,&RC.mac[0]->UE_list.eNB_UE_stats, sizeof(eNB_UE_STATS)*MAX_NUM_CCs*NUMBER_OF_UE_MAX);
+      memcpy(&pre_scd_activeUE, &RC.mac[0]->UE_list.active, sizeof(boolean_t)*NUMBER_OF_UE_MAX);
+
+      if (pthread_mutex_lock(&ru->proc.mutex_pre_scd)!= 0) {
+          LOG_E( PHY, "[eNB] error locking proc mutex for eNB pre scd\n");
+          exit_fun("error locking mutex_time");
+      }
+
+      ru->proc.instance_pre_scd++;
+
+      if (ru->proc.instance_pre_scd == 0) {
+          if (pthread_cond_signal(&ru->proc.cond_pre_scd) != 0) {
+              LOG_E( PHY, "[eNB] ERROR pthread_cond_signal for eNB pre scd\n" );
+              exit_fun( "ERROR pthread_cond_signal cond_pre_scd" );
+          }
+      }else{
+          LOG_E( PHY, "[eNB] frame %d subframe %d rxtx busy instance_pre_scd %d\n",
+                 proc->frame_rx,proc->subframe_rx,ru->proc.instance_pre_scd );
+      }
+
+      if (pthread_mutex_unlock(&ru->proc.mutex_pre_scd)!= 0) {
+          LOG_E( PHY, "[eNB] error unlocking mutex_pre_scd mutex for eNB pre scd\n");
+          exit_fun("error unlocking mutex_pre_scd");
+      }
     }
-    if (release_thread(&proc[1].mutex_rxtx,&proc[1].pipe_ready,"wakeup_tx")<0)  return(-1);
-  }
+#endif
 
   pthread_mutex_lock(&eNB->UL_INFO_mutex);
-
   eNB->UL_INFO.frame     = proc->frame_rx;
   eNB->UL_INFO.subframe  = proc->subframe_rx;
   eNB->UL_INFO.module_id = eNB->Mod_id;
   eNB->UL_INFO.CC_id     = eNB->CC_id;
-
   eNB->if_inst->UL_indication(&eNB->UL_INFO);
-
   pthread_mutex_unlock(&eNB->UL_INFO_mutex);
   /* this conflict resolution may be totally wrong, to be tested */
   /* CONFLICT RESOLUTION: BEGIN */
-  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ULSCH_SCHEDULER , 0 );
+  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ULSCH_SCHEDULER, 0 );
+
   if(oai_exit) return(-1);
-  if(get_thread_parallel_conf() == PARALLEL_SINGLE_THREAD){
+
+  if(get_thread_parallel_conf() == PARALLEL_SINGLE_THREAD) {
 #ifndef PHY_TX_THREAD
     phy_procedures_eNB_TX(eNB, proc, 1);
 #endif
   }
+
   /* CONFLICT RESOLUTION: what about this release_thread call, has it to be done? if yes, where? */
   //if (release_thread(&proc->mutex_rxtx,&proc->instance_cnt_rxtx,thread_name)<0) return(-1);
   /* CONFLICT RESOLUTION: END */
-
   stop_meas( &softmodem_stats_rxtx_sf );
-
   LOG_D(PHY,"%s() Exit proc[rx:%d%d tx:%d%d]\n", __FUNCTION__, proc->frame_rx, proc->subframe_rx, proc->frame_tx, proc->subframe_tx);
-
-  LOG_D(PHY, "rxtx:%lld nfapi:%lld phy:%lld tx:%lld rx:%lld prach:%lld ofdm:%lld ",
-      softmodem_stats_rxtx_sf.p_time, nfapi_meas.p_time,
-      TICK_TO_US(eNB->phy_proc),
-      TICK_TO_US(eNB->phy_proc_tx),
-      TICK_TO_US(eNB->phy_proc_rx),
-      TICK_TO_US(eNB->rx_prach),
-      TICK_TO_US(eNB->ofdm_mod_stats)
-      );
+  LOG_D(PHY, "rxtx:%lld nfapi:%lld tx:%lld rx:%lld prach:%lld ofdm:%lld ",
+        softmodem_stats_rxtx_sf.p_time, nfapi_meas.p_time,
+        TICK_TO_US(eNB->phy_proc_tx),
+        TICK_TO_US(eNB->phy_proc_rx),
+        TICK_TO_US(eNB->rx_prach),
+        TICK_TO_US(eNB->ofdm_mod_stats)
+       );
   LOG_D(PHY,
-    "dlsch[enc:%lld mod:%lld scr:%lld rm:%lld t:%lld i:%lld] rx_dft:%lld ",
-      TICK_TO_US(eNB->dlsch_encoding_stats),
-      TICK_TO_US(eNB->dlsch_modulation_stats),
-      TICK_TO_US(eNB->dlsch_scrambling_stats),
-      TICK_TO_US(eNB->dlsch_rate_matching_stats),
-      TICK_TO_US(eNB->dlsch_turbo_encoding_stats),
-      TICK_TO_US(eNB->dlsch_interleaving_stats),
-      TICK_TO_US(eNB->rx_dft_stats));
-
+        "dlsch[enc:%lld mod:%lld scr:%lld rm:%lld t:%lld i:%lld] rx_dft:%lld ",
+        TICK_TO_US(eNB->dlsch_encoding_stats),
+        TICK_TO_US(eNB->dlsch_modulation_stats),
+        TICK_TO_US(eNB->dlsch_scrambling_stats),
+        TICK_TO_US(eNB->dlsch_rate_matching_stats),
+        TICK_TO_US(eNB->dlsch_turbo_encoding_stats),
+        TICK_TO_US(eNB->dlsch_interleaving_stats),
+        TICK_TO_US(eNB->rx_dft_stats));
   LOG_D(PHY," ulsch[ch:%lld freq:%lld dec:%lld demod:%lld ru:%lld ",
-      TICK_TO_US(eNB->ulsch_channel_estimation_stats),
-      TICK_TO_US(eNB->ulsch_freq_offset_estimation_stats),
-      TICK_TO_US(eNB->ulsch_decoding_stats),
-      TICK_TO_US(eNB->ulsch_demodulation_stats),
-      TICK_TO_US(eNB->ulsch_rate_unmatching_stats));
-
+        TICK_TO_US(eNB->ulsch_channel_estimation_stats),
+        TICK_TO_US(eNB->ulsch_freq_offset_estimation_stats),
+        TICK_TO_US(eNB->ulsch_decoding_stats),
+        TICK_TO_US(eNB->ulsch_demodulation_stats),
+        TICK_TO_US(eNB->ulsch_rate_unmatching_stats));
   LOG_D(PHY, "td:%lld dei:%lld dem:%lld llr:%lld tci:%lld ",
-      TICK_TO_US(eNB->ulsch_turbo_decoding_stats),
-      TICK_TO_US(eNB->ulsch_deinterleaving_stats),
-      TICK_TO_US(eNB->ulsch_demultiplexing_stats),
-      TICK_TO_US(eNB->ulsch_llr_stats),
-      TICK_TO_US(eNB->ulsch_tc_init_stats));
-  LOG_D(PHY, "tca:%lld tcb:%lld tcg:%lld tce:%lld l1:%lld l2:%lld]\n\n", 
-      TICK_TO_US(eNB->ulsch_tc_alpha_stats),
-      TICK_TO_US(eNB->ulsch_tc_beta_stats),
-      TICK_TO_US(eNB->ulsch_tc_gamma_stats),
-      TICK_TO_US(eNB->ulsch_tc_ext_stats),
-      TICK_TO_US(eNB->ulsch_tc_intl1_stats),
-      TICK_TO_US(eNB->ulsch_tc_intl2_stats)
-      );
-  
+        TICK_TO_US(eNB->ulsch_turbo_decoding_stats),
+        TICK_TO_US(eNB->ulsch_deinterleaving_stats),
+        TICK_TO_US(eNB->ulsch_demultiplexing_stats),
+        TICK_TO_US(eNB->ulsch_llr_stats),
+        TICK_TO_US(eNB->ulsch_tc_init_stats));
+  LOG_D(PHY, "tca:%lld tcb:%lld tcg:%lld tce:%lld l1:%lld l2:%lld]\n\n",
+        TICK_TO_US(eNB->ulsch_tc_alpha_stats),
+        TICK_TO_US(eNB->ulsch_tc_beta_stats),
+        TICK_TO_US(eNB->ulsch_tc_gamma_stats),
+        TICK_TO_US(eNB->ulsch_tc_ext_stats),
+        TICK_TO_US(eNB->ulsch_tc_intl1_stats),
+        TICK_TO_US(eNB->ulsch_tc_intl2_stats)
+       );
   return(0);
 }
 
 
-static void* tx_thread(void* param) {
+static void* L1_thread_tx(void* param) {
 
-  eNB_proc_t *eNB_proc  = (eNB_proc_t*)param;
-  eNB_rxtx_proc_t *proc = &eNB_proc->proc_rxtx[1];
+  L1_proc_t *eNB_proc  = (L1_proc_t*)param;
+  L1_rxtx_proc_t *proc = &eNB_proc->L1_proc_tx;
   PHY_VARS_eNB *eNB = RC.eNB[0][proc->CC_id];
-  
   char thread_name[100];
-  sprintf(thread_name,"TXnp4_%d\n",&eNB->proc.proc_rxtx[0] == proc ? 0 : 1);
+  sprintf(thread_name,"TXnp4_%d\n",&eNB->proc.L1_proc == proc ? 0 : 1);
   thread_top_init(thread_name,1,470000,500000,500000);
-  
+
   //wait_sync("tx_thread");
-  
+
   while (!oai_exit) {
-    
+    if (wait_on_condition(&proc->mutex,&proc->cond,&proc->instance_cnt,thread_name)<0) break;
+    if (oai_exit) break;
 
-    if (wait_on_condition(&proc->mutex_rxtx,&proc->cond_rxtx,&proc->instance_cnt_rxtx,thread_name)<0) break;
-    if (oai_exit) break;    
     // *****************************************
     // TX processing for subframe n+4
     // run PHY TX procedures the one after the other for all CCs to avoid race conditions
@@ -327,19 +348,19 @@ static void* tx_thread(void* param) {
     VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_SUBFRAME_NUMBER_RX1_ENB,proc->subframe_rx);
     VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_FRAME_NUMBER_TX1_ENB,proc->frame_tx);
     VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_FRAME_NUMBER_RX1_ENB,proc->frame_rx);
-    
     phy_procedures_eNB_TX(eNB, proc, 1);
-    if (release_thread(&proc->mutex_rxtx,&proc->instance_cnt_rxtx,thread_name)<0) break;
-	
-    pthread_mutex_lock( &proc->mutex_rxtx );
-    proc->pipe_ready++;
+
+
+    pthread_mutex_lock( &proc->mutex );
+    proc->instance_cnt = -1;
+
     // the thread can now be woken up
-    if (pthread_cond_signal(&proc->cond_rxtx) != 0) {
+    if (pthread_cond_signal(&proc->cond) != 0) {
       LOG_E( PHY, "[eNB] ERROR pthread_cond_signal for eNB TXnp4 thread\n");
       exit_fun( "ERROR pthread_cond_signal" );
     }
-    pthread_mutex_unlock( &proc->mutex_rxtx );
-    wakeup_txfh(proc,eNB_proc->ru_proc);
+    pthread_mutex_unlock( &proc->mutex );
+    wakeup_txfh(proc,eNB);
   }
 
   return 0;
@@ -347,171 +368,154 @@ static void* tx_thread(void* param) {
 
 /*!
  * \brief The RX UE-specific and TX thread of eNB.
- * \param param is a \ref eNB_proc_t structure which contains the info what to process.
+ * \param param is a \ref L1_proc_t structure which contains the info what to process.
  * \returns a pointer to an int. The storage is not on the heap and must not be freed.
  */
 
-static void* eNB_thread_rxtx( void* param ) {
+static void* L1_thread( void* param ) {
 
   static int eNB_thread_rxtx_status;
-  //eNB_proc_t *eNB_proc  = (eNB_proc_t*)param;
-  eNB_rxtx_proc_t *proc;
+  //L1_proc_t *eNB_proc  = (L1_proc_t*)param;
+  L1_rxtx_proc_t *proc;
 
   // Working
   if(nfapi_mode ==2){
-	  proc = (eNB_rxtx_proc_t*)param;
+    proc = (L1_rxtx_proc_t*)param;
   }
   else{
-	  eNB_proc_t *eNB_proc  = (eNB_proc_t*)param;
-	  proc = &eNB_proc->proc_rxtx[0];
+    L1_proc_t *eNB_proc  = (L1_proc_t*)param;
+    proc = &eNB_proc->L1_proc;
   }
 
-
   PHY_VARS_eNB *eNB = RC.eNB[0][proc->CC_id];
-  //RU_proc_t *ru_proc = NULL;
 
   char thread_name[100];
-
   cpu_set_t cpuset;
   CPU_ZERO(&cpuset);
-
   // set default return value
   eNB_thread_rxtx_status = 0;
 
-
-  sprintf(thread_name,"RXn_TXnp4_%d\n",&eNB->proc.proc_rxtx[0] == proc ? 0 : 1);
+  sprintf(thread_name,"RXn_TXnp4_%d\n",&eNB->proc.L1_proc == proc ? 0 : 1);
   thread_top_init(thread_name,1,470000,500000,500000);
   pthread_setname_np( pthread_self(),"rxtx processing");
   LOG_I(PHY,"thread rxtx created id=%ld\n", syscall(__NR_gettid));
 
-
-
   while (!oai_exit) {
-    
-    
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_eNB_PROC_RXTX0+(proc->subframe_rx&1), 0 );
     T(T_ENB_MASTER_TICK, T_INT(0), T_INT(proc->frame_rx), T_INT(proc->subframe_rx));
 
-    if (wait_on_condition(&proc->mutex_rxtx,&proc->cond_rxtx,&proc->instance_cnt_rxtx,thread_name)<0) break;
+    if (wait_on_condition(&proc->mutex,&proc->cond,&proc->instance_cnt,thread_name)<0) break;
 
     VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_CPUID_ENB_THREAD_RXTX,sched_getcpu());
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_eNB_PROC_RXTX0+(proc->subframe_rx&1), 1 );
-   
     VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_SUBFRAME_NUMBER_TX0_ENB,proc->subframe_tx);
     VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_SUBFRAME_NUMBER_RX0_ENB,proc->subframe_rx);
     VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_FRAME_NUMBER_TX0_ENB,proc->frame_tx);
     VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_FRAME_NUMBER_RX0_ENB,proc->frame_rx);
- 
 
     if (oai_exit) break;
 
-    if (eNB->CC_id==0)
-    {
+    if (eNB->CC_id==0) {
       if (rxtx(eNB,proc,thread_name) < 0) break;
     }
 
-    if (release_thread(&proc->mutex_rxtx,&proc->instance_cnt_rxtx,thread_name)<0) break;
-    pthread_mutex_lock( &proc->mutex_rxtx );
-    proc->pipe_ready++;
-    // the thread can now be woken up
-    if (pthread_cond_signal(&proc->cond_rxtx) != 0) {
-      LOG_E( PHY, "[eNB] ERROR pthread_cond_signal for eNB TXnp4 thread\n");
-      exit_fun( "ERROR pthread_cond_signal" );
-    }
-    pthread_mutex_unlock( &proc->mutex_rxtx );
+    if(get_thread_parallel_conf() == PARALLEL_RU_L1_SPLIT)              phy_procedures_eNB_TX(eNB, proc, 1);
+    if (release_thread(&proc->mutex,&proc->instance_cnt,thread_name)<0) break;
     if (nfapi_mode!=2){
-      if(get_thread_parallel_conf() == PARALLEL_RU_L1_TRX_SPLIT)      wakeup_tx(eNB,eNB->proc.ru_proc);
-      else if(get_thread_parallel_conf() == PARALLEL_RU_L1_SPLIT)
-    	{
-    		phy_procedures_eNB_TX(eNB, proc, 1);
-    		wakeup_txfh(proc,eNB->proc.ru_proc);
-    	}
+      if(get_thread_parallel_conf() == PARALLEL_RU_L1_TRX_SPLIT)      wakeup_tx(eNB);
+      else if(get_thread_parallel_conf() == PARALLEL_RU_L1_SPLIT)     wakeup_txfh(proc,eNB);
     }
-
   } // while !oai_exit
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_eNB_PROC_RXTX0+(proc->subframe_rx&1), 0 );
-
   LOG_D(PHY, " *** Exiting eNB thread RXn_TXnp4\n");
-
   eNB_thread_rxtx_status = 0;
   return &eNB_thread_rxtx_status;
 }
 
 void eNB_top(PHY_VARS_eNB *eNB, int frame_rx, int subframe_rx, char *string,RU_t *ru)
 {
-  eNB_proc_t *proc           = &eNB->proc;
-  eNB_rxtx_proc_t *proc_rxtx = &proc->proc_rxtx[0];
+  L1_proc_t *proc           = &eNB->proc;
+  L1_rxtx_proc_t *L1_proc = &proc->L1_proc;
   LTE_DL_FRAME_PARMS *fp = &ru->frame_parms;
   RU_proc_t *ru_proc=&ru->proc;
-
   proc->frame_rx    = frame_rx;
   proc->subframe_rx = subframe_rx;
 
   if (!oai_exit) {
     T(T_ENB_MASTER_TICK, T_INT(0), T_INT(proc->frame_rx), T_INT(proc->subframe_rx));
 
-    proc_rxtx->timestamp_tx = ru_proc->timestamp_rx + (sf_ahead*fp->samples_per_tti);
-    proc_rxtx->frame_rx     = ru_proc->frame_rx;
-    proc_rxtx->subframe_rx  = ru_proc->subframe_rx;
-    proc_rxtx->frame_tx     = (proc_rxtx->subframe_rx > (9-sf_ahead)) ? (proc_rxtx->frame_rx+1)&1023 : proc_rxtx->frame_rx;
-    proc_rxtx->subframe_tx  = (proc_rxtx->subframe_rx + sf_ahead)%10;
+    L1_proc->timestamp_tx = ru_proc->timestamp_rx + (sf_ahead*fp->samples_per_tti);
+    L1_proc->frame_rx     = ru_proc->frame_rx;
+    L1_proc->subframe_rx  = ru_proc->subframe_rx;
+    L1_proc->frame_tx     = (L1_proc->subframe_rx > (9-sf_ahead)) ? (L1_proc->frame_rx+1)&1023 : L1_proc->frame_rx;
+    L1_proc->subframe_tx  = (L1_proc->subframe_rx + sf_ahead)%10;
 
-    if (rxtx(eNB,proc_rxtx,string) < 0) LOG_E(PHY,"eNB %d CC_id %d failed during execution\n",eNB->Mod_id,eNB->CC_id);
-    ru_proc->timestamp_tx = proc_rxtx->timestamp_tx;
-    ru_proc->subframe_tx  = proc_rxtx->subframe_tx;
-    ru_proc->frame_tx     = proc_rxtx->frame_tx;
+    if (rxtx(eNB,L1_proc,string) < 0) LOG_E(PHY,"eNB %d CC_id %d failed during execution\n",eNB->Mod_id,eNB->CC_id);
+    ru_proc->timestamp_tx = L1_proc->timestamp_tx;
+    ru_proc->subframe_tx  = L1_proc->subframe_tx;
+    ru_proc->frame_tx     = L1_proc->frame_tx;
   }
 }
 
-int wakeup_txfh(eNB_rxtx_proc_t *proc,RU_proc_t *ru_proc) {
-  
-	if(ru_proc == NULL)
-		return(0);
+int wakeup_txfh(L1_rxtx_proc_t *proc,PHY_VARS_eNB *eNB) {
+
+  RU_t *ru;
+  RU_proc_t *ru_proc;
+
+
   struct timespec wait;
   wait.tv_sec=0;
   wait.tv_nsec=5000000L;
 
-  
-  if(wait_on_condition(&ru_proc->mutex_eNBs,&ru_proc->cond_eNBs,&ru_proc->ru_tx_ready,"wakeup_txfh")<0) {
-    LOG_E(PHY,"Frame %d, subframe %d: TX FH not ready\n", ru_proc->frame_tx, ru_proc->subframe_tx);
-    return(-1);
-  }
-  if (release_thread(&ru_proc->mutex_eNBs,&ru_proc->ru_tx_ready,"wakeup_txfh")<0) return(-1);
-  
-  if (ru_proc->instance_cnt_eNBs == 0) {
-    LOG_E(PHY,"Frame %d, subframe %d: TX FH thread busy, dropping Frame %d, subframe %d\n", ru_proc->frame_tx, ru_proc->subframe_tx, proc->frame_rx, proc->subframe_rx);
-    return(-1);
-  }
-  if (pthread_mutex_timedlock(&ru_proc->mutex_eNBs,&wait) != 0) {
-    LOG_E( PHY, "[eNB] ERROR pthread_mutex_lock for eNB TX1 thread %d (IC %d)\n", ru_proc->subframe_rx&1,ru_proc->instance_cnt_eNBs );
-    exit_fun( "error locking mutex_eNB" );
+  if(wait_on_condition(&proc->mutex_RUs,&proc->cond_RUs,&proc->instance_cnt_RUs,"wakeup_txfh")<0) {
+    LOG_E(PHY,"Frame %d, subframe %d: TX FH not ready\n", proc->frame_tx, proc->subframe_tx);
     return(-1);
   }
+  pthread_mutex_lock(&eNB->proc.mutex_RU_tx);
+  eNB->proc.RU_mask_tx = 0;
+  pthread_mutex_unlock(&eNB->proc.mutex_RU_tx);
+  if (release_thread(&proc->mutex_RUs,&proc->instance_cnt_RUs,"wakeup_txfh")<0) return(-1);
+
+  for(int i=0; i<eNB->num_RU; i++)
+  {
+    ru      = eNB->RU_list[i];
+    ru_proc = &ru->proc;
+    if (ru_proc->instance_cnt_eNBs == 0) {
+      LOG_E(PHY,"Frame %d, subframe %d: TX FH thread busy, dropping Frame %d, subframe %d\n", ru_proc->frame_tx, ru_proc->subframe_tx, proc->frame_rx, proc->subframe_rx);
+      return(-1);
+    }
+    if (pthread_mutex_timedlock(&ru_proc->mutex_eNBs,&wait) != 0) {
+      LOG_E( PHY, "[eNB] ERROR pthread_mutex_lock for eNB TX1 thread %d (IC %d)\n", ru_proc->subframe_rx&1,ru_proc->instance_cnt_eNBs );
+      exit_fun( "error locking mutex_eNB" );
+      return(-1);
+    }
 
-    ++ru_proc->instance_cnt_eNBs;
+    ru_proc->instance_cnt_eNBs = 0;
     ru_proc->timestamp_tx = proc->timestamp_tx;
     ru_proc->subframe_tx  = proc->subframe_tx;
     ru_proc->frame_tx     = proc->frame_tx;
+
   
-  // the thread can now be woken up
-  if (pthread_cond_signal(&ru_proc->cond_eNBs) != 0) {
-    LOG_E( PHY, "[eNB] ERROR pthread_cond_signal for eNB TXnp4 thread\n");
-    exit_fun( "ERROR pthread_cond_signal" );
-    return(-1);
-  }
+    // the thread can now be woken up
+    if (pthread_cond_signal(&ru_proc->cond_eNBs) != 0) {
+      LOG_E( PHY, "[eNB] ERROR pthread_cond_signal for eNB TXnp4 thread\n");
+      exit_fun( "ERROR pthread_cond_signal" );
+      return(-1);
+    }
   
-  pthread_mutex_unlock( &ru_proc->mutex_eNBs );
+    pthread_mutex_unlock( &ru_proc->mutex_eNBs );
+  }
 
   return(0);
 }
 
-int wakeup_tx(PHY_VARS_eNB *eNB,RU_proc_t *ru_proc) {
+int wakeup_tx(PHY_VARS_eNB *eNB) {
 
-  eNB_proc_t *proc=&eNB->proc;
+  L1_proc_t *proc=&eNB->proc;
 
-  eNB_rxtx_proc_t *proc_rxtx1=&proc->proc_rxtx[1];//*proc_rxtx=&proc->proc_rxtx[proc->frame_rx&1];
-  eNB_rxtx_proc_t *proc_rxtx0=&proc->proc_rxtx[0];
+  L1_rxtx_proc_t *L1_proc_tx = &proc->L1_proc_tx;
+  L1_rxtx_proc_t *L1_proc    = &proc->L1_proc;
 
   
   struct timespec wait;
@@ -519,321 +523,298 @@ int wakeup_tx(PHY_VARS_eNB *eNB,RU_proc_t *ru_proc) {
   wait.tv_nsec=5000000L;
   
   
-  
-  if (proc_rxtx1->instance_cnt_rxtx == 0) {
-    LOG_E(PHY,"Frame %d, subframe %d: TX1 thread busy, dropping\n",proc_rxtx1->frame_rx,proc_rxtx1->subframe_rx);
+  if (pthread_mutex_timedlock(&L1_proc_tx->mutex,&wait) != 0) {
+    LOG_E(PHY, "[SCHED][eNB] ERROR locking mutex for eNB L1_thread_tx\n");
+    exit_fun("ERROR pthread_lock");
     return(-1);
   }
-  
-  if (pthread_mutex_timedlock(&proc_rxtx1->mutex_rxtx,&wait) != 0) {
-    LOG_E( PHY, "[eNB] ERROR pthread_mutex_lock for eNB TX1 thread %d (IC %d)\n", proc_rxtx1->subframe_rx&1,proc_rxtx1->instance_cnt_rxtx );
-    exit_fun( "error locking mutex_tx" );
-    return(-1);
+  while(L1_proc_tx->instance_cnt == 0){
+    pthread_cond_wait(&L1_proc_tx->cond,&L1_proc_tx->mutex);
   }
 
-  ++proc_rxtx1->instance_cnt_rxtx;
+  L1_proc_tx->instance_cnt = 0;
 
   
-  proc_rxtx1->subframe_rx   = proc_rxtx0->subframe_rx;
-  proc_rxtx1->frame_rx      = proc_rxtx0->frame_rx;
-  proc_rxtx1->subframe_tx   = proc_rxtx0->subframe_tx;
-  proc_rxtx1->frame_tx      = proc_rxtx0->frame_tx;
-  proc_rxtx1->timestamp_tx  = proc_rxtx0->timestamp_tx;
-  
+  L1_proc_tx->subframe_rx   = L1_proc->subframe_rx;
+  L1_proc_tx->frame_rx      = L1_proc->frame_rx;
+  L1_proc_tx->subframe_tx   = L1_proc->subframe_tx;
+  L1_proc_tx->frame_tx      = L1_proc->frame_tx;
+  L1_proc_tx->timestamp_tx  = L1_proc->timestamp_tx;
+
   // the thread can now be woken up
-  if (pthread_cond_signal(&proc_rxtx1->cond_rxtx) != 0) {
+  if (pthread_cond_signal(&L1_proc_tx->cond) != 0) {
     LOG_E( PHY, "[eNB] ERROR pthread_cond_signal for eNB TXnp4 thread\n");
     exit_fun( "ERROR pthread_cond_signal" );
     return(-1);
   }
   
-  pthread_mutex_unlock( &proc_rxtx1->mutex_rxtx );
-
+  pthread_mutex_unlock( &L1_proc_tx->mutex);
   return(0);
 }
 
 int wakeup_rxtx(PHY_VARS_eNB *eNB,RU_t *ru) {
 
-  eNB_proc_t *proc=&eNB->proc;
+  L1_proc_t *proc=&eNB->proc;
   RU_proc_t *ru_proc=&ru->proc;
 
-  eNB_rxtx_proc_t *proc_rxtx0=&proc->proc_rxtx[0];
-  //eNB_rxtx_proc_t *proc_rxtx1=&proc->proc_rxtx[1];
+  L1_rxtx_proc_t *L1_proc=&proc->L1_proc;
   
-
   LTE_DL_FRAME_PARMS *fp = &eNB->frame_parms;
-
   int i;
   struct timespec wait;
-  
   pthread_mutex_lock(&proc->mutex_RU);
-  for (i=0;i<eNB->num_RU;i++) {
+
+  for (i=0; i<eNB->num_RU; i++) {
     if (ru == eNB->RU_list[i]) {
       if ((proc->RU_mask&(1<<i)) > 0)
-	LOG_E(PHY,"eNB %d frame %d, subframe %d : previous information from RU %d (num_RU %d,mask %x) has not been served yet!\n",
-	      eNB->Mod_id,proc->frame_rx,proc->subframe_rx,ru->idx,eNB->num_RU,proc->RU_mask);
+        LOG_E(PHY,"eNB %d frame %d, subframe %d : previous information from RU %d (num_RU %d,mask %x) has not been served yet!\n",
+              eNB->Mod_id,proc->frame_rx,proc->subframe_rx,ru->idx,eNB->num_RU,proc->RU_mask);
+
       proc->RU_mask |= (1<<i);
     }
   }
+
   if (proc->RU_mask != (1<<eNB->num_RU)-1) {  // not all RUs have provided their information so return
     LOG_E(PHY,"Not all RUs have provided their info\n");
     pthread_mutex_unlock(&proc->mutex_RU);
     return(0);
-  }
-  else { // all RUs have provided their information so continue on and wakeup eNB processing
+  } else { // all RUs have provided their information so continue on and wakeup eNB processing
     proc->RU_mask = 0;
     pthread_mutex_unlock(&proc->mutex_RU);
   }
 
-
-
-
   wait.tv_sec=0;
   wait.tv_nsec=5000000L;
 
-  
-  if(wait_on_condition(&proc_rxtx0->mutex_rxtx,&proc_rxtx0->cond_rxtx,&proc_rxtx0->pipe_ready,"wakeup_rxtx")<0) {
-    LOG_E(PHY,"Frame %d, subframe %d: RXTX0 not ready\n",proc_rxtx0->frame_rx,proc_rxtx0->subframe_rx);
-    return(-1);
-  }
-  if (release_thread(&proc_rxtx0->mutex_rxtx,&proc_rxtx0->pipe_ready,"wakeup_rxtx")<0) return(-1);
-  
-  if (proc_rxtx0->instance_cnt_rxtx == 0) {
-    LOG_E(PHY,"Frame %d, subframe %d: RXTX0 thread busy, dropping\n",proc_rxtx0->frame_rx,proc_rxtx0->subframe_rx);
+
+  if (L1_proc->instance_cnt == 0) {
+    LOG_E(PHY,"Frame %d, subframe %d: RXTX0 thread busy, dropping\n",L1_proc->frame_rx,L1_proc->subframe_rx);
     return(-1);
   }
 
   // wake up TX for subframe n+sf_ahead
   // lock the TX mutex and make sure the thread is ready
-  if (pthread_mutex_timedlock(&proc_rxtx0->mutex_rxtx,&wait) != 0) {
-    LOG_E( PHY, "[eNB] ERROR pthread_mutex_lock for eNB RXTX thread %d (IC %d)\n", proc_rxtx0->subframe_rx&1,proc_rxtx0->instance_cnt_rxtx );
+  if (pthread_mutex_timedlock(&L1_proc->mutex,&wait) != 0) {
+    LOG_E( PHY, "[eNB] ERROR pthread_mutex_lock for eNB RXTX thread %d (IC %d)\n", L1_proc->subframe_rx&1,L1_proc->instance_cnt );
     exit_fun( "error locking mutex_rxtx" );
     return(-1);
   }
-  
 
-  ++proc_rxtx0->instance_cnt_rxtx;
+  ++L1_proc->instance_cnt;
   
   // We have just received and processed the common part of a subframe, say n. 
   // TS_rx is the last received timestamp (start of 1st slot), TS_tx is the desired 
   // transmitted timestamp of the next TX slot (first).
-  // The last (TS_rx mod samples_per_frame) was n*samples_per_tti, 
+  // The last (TS_rx mod samples_per_frame) was n*samples_per_tti,
   // we want to generate subframe (n+sf_ahead), so TS_tx = TX_rx+sf_ahead*samples_per_tti,
   // and proc->subframe_tx = proc->subframe_rx+sf_ahead
-  proc_rxtx0->timestamp_tx = ru_proc->timestamp_rx + (sf_ahead*fp->samples_per_tti);
-  proc_rxtx0->frame_rx     = ru_proc->frame_rx;
-  proc_rxtx0->subframe_rx  = ru_proc->subframe_rx;
-  proc_rxtx0->frame_tx     = (proc_rxtx0->subframe_rx > (9-sf_ahead)) ? (proc_rxtx0->frame_rx+1)&1023 : proc_rxtx0->frame_rx;
-  proc_rxtx0->subframe_tx  = (proc_rxtx0->subframe_rx + sf_ahead)%10;
+  L1_proc->timestamp_tx = ru_proc->timestamp_rx + (sf_ahead*fp->samples_per_tti);
+  L1_proc->frame_rx     = ru_proc->frame_rx;
+  L1_proc->subframe_rx  = ru_proc->subframe_rx;
+  L1_proc->frame_tx     = (L1_proc->subframe_rx > (9-sf_ahead)) ? (L1_proc->frame_rx+1)&1023 : L1_proc->frame_rx;
+  L1_proc->subframe_tx  = (L1_proc->subframe_rx + sf_ahead)%10;
 
   // the thread can now be woken up
-  if (pthread_cond_signal(&proc_rxtx0->cond_rxtx) != 0) {
+  if (pthread_cond_signal(&L1_proc->cond) != 0) {
     LOG_E( PHY, "[eNB] ERROR pthread_cond_signal for eNB RXn-TXnp4 thread\n");
     exit_fun( "ERROR pthread_cond_signal" );
     return(-1);
   }
-  
-  pthread_mutex_unlock( &proc_rxtx0->mutex_rxtx );
 
+  pthread_mutex_unlock( &L1_proc->mutex);
   return(0);
 }
 
 void wakeup_prach_eNB(PHY_VARS_eNB *eNB,RU_t *ru,int frame,int subframe) {
 
-  eNB_proc_t *proc = &eNB->proc;
+  L1_proc_t *proc = &eNB->proc;
   LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
   int i;
 
   if (ru!=NULL) {
     pthread_mutex_lock(&proc->mutex_RU_PRACH);
-    for (i=0;i<eNB->num_RU;i++) {
+
+    for (i=0; i<eNB->num_RU; i++) {
       if (ru == eNB->RU_list[i]) {
-	LOG_D(PHY,"frame %d, subframe %d: RU %d for eNB %d signals PRACH (mask %x, num_RU %d)\n",frame,subframe,i,eNB->Mod_id,proc->RU_mask_prach,eNB->num_RU);
-	if ((proc->RU_mask_prach&(1<<i)) > 0)
-	  LOG_E(PHY,"eNB %d frame %d, subframe %d : previous information (PRACH) from RU %d (num_RU %d, mask %x) has not been served yet!\n",
-		eNB->Mod_id,frame,subframe,ru->idx,eNB->num_RU,proc->RU_mask_prach);
-	proc->RU_mask_prach |= (1<<i);
+        LOG_D(PHY,"frame %d, subframe %d: RU %d for eNB %d signals PRACH (mask %x, num_RU %d)\n",frame,subframe,i,eNB->Mod_id,proc->RU_mask_prach,eNB->num_RU);
+
+        if ((proc->RU_mask_prach&(1<<i)) > 0)
+          LOG_E(PHY,"eNB %d frame %d, subframe %d : previous information (PRACH) from RU %d (num_RU %d, mask %x) has not been served yet!\n",
+                eNB->Mod_id,frame,subframe,ru->idx,eNB->num_RU,proc->RU_mask_prach);
+
+        proc->RU_mask_prach |= (1<<i);
       }
     }
+
     if (proc->RU_mask_prach != (1<<eNB->num_RU)-1) {  // not all RUs have provided their information so return
       pthread_mutex_unlock(&proc->mutex_RU_PRACH);
       return;
-    }
-    else { // all RUs have provided their information so continue on and wakeup eNB processing
+    } else { // all RUs have provided their information so continue on and wakeup eNB processing
       proc->RU_mask_prach = 0;
       pthread_mutex_unlock(&proc->mutex_RU_PRACH);
     }
   }
-    
+
   // check if we have to detect PRACH first
-  if (is_prach_subframe(fp,frame,subframe)>0) { 
+  if (is_prach_subframe(fp,frame,subframe)>0) {
     LOG_D(PHY,"Triggering prach processing, frame %d, subframe %d\n",frame,subframe);
+
     if (proc->instance_cnt_prach == 0) {
       LOG_W(PHY,"[eNB] Frame %d Subframe %d, dropping PRACH\n", frame,subframe);
       return;
     }
-    
+
     // wake up thread for PRACH RX
     if (pthread_mutex_lock(&proc->mutex_prach) != 0) {
       LOG_E( PHY, "[eNB] ERROR pthread_mutex_lock for eNB PRACH thread %d (IC %d)\n", proc->thread_index, proc->instance_cnt_prach);
       exit_fun( "error locking mutex_prach" );
       return;
     }
-    
+
     ++proc->instance_cnt_prach;
     // set timing for prach thread
     proc->frame_prach = frame;
     proc->subframe_prach = subframe;
-    
+
     // the thread can now be woken up
     if (pthread_cond_signal(&proc->cond_prach) != 0) {
       LOG_E( PHY, "[eNB] ERROR pthread_cond_signal for eNB PRACH thread %d\n", proc->thread_index);
       exit_fun( "ERROR pthread_cond_signal" );
       return;
     }
-    
+
     pthread_mutex_unlock( &proc->mutex_prach );
   }
-
 }
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 void wakeup_prach_eNB_br(PHY_VARS_eNB *eNB,RU_t *ru,int frame,int subframe) {
 
-  eNB_proc_t *proc = &eNB->proc;
+  L1_proc_t *proc = &eNB->proc;
   LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
   int i;
 
   if (ru!=NULL) {
     pthread_mutex_lock(&proc->mutex_RU_PRACH_br);
-    for (i=0;i<eNB->num_RU;i++) {
+
+    for (i=0; i<eNB->num_RU; i++) {
       if (ru == eNB->RU_list[i]) {
-	LOG_D(PHY,"frame %d, subframe %d: RU %d for eNB %d signals PRACH BR (mask %x, num_RU %d)\n",frame,subframe,i,eNB->Mod_id,proc->RU_mask_prach_br,eNB->num_RU);
-	if ((proc->RU_mask_prach_br&(1<<i)) > 0)
-	  LOG_E(PHY,"eNB %d frame %d, subframe %d : previous information (PRACH BR) from RU %d (num_RU %d, mask %x) has not been served yet!\n",
-		eNB->Mod_id,frame,subframe,ru->idx,eNB->num_RU,proc->RU_mask_prach_br);
-	proc->RU_mask_prach_br |= (1<<i);
+        LOG_D(PHY,"frame %d, subframe %d: RU %d for eNB %d signals PRACH BR (mask %x, num_RU %d)\n",frame,subframe,i,eNB->Mod_id,proc->RU_mask_prach_br,eNB->num_RU);
+
+        if ((proc->RU_mask_prach_br&(1<<i)) > 0)
+          LOG_E(PHY,"eNB %d frame %d, subframe %d : previous information (PRACH BR) from RU %d (num_RU %d, mask %x) has not been served yet!\n",
+                eNB->Mod_id,frame,subframe,ru->idx,eNB->num_RU,proc->RU_mask_prach_br);
+
+        proc->RU_mask_prach_br |= (1<<i);
       }
     }
+
     if (proc->RU_mask_prach_br != (1<<eNB->num_RU)-1) {  // not all RUs have provided their information so return
       pthread_mutex_unlock(&proc->mutex_RU_PRACH_br);
       return;
-    }
-    else { // all RUs have provided their information so continue on and wakeup eNB processing
+    } else { // all RUs have provided their information so continue on and wakeup eNB processing
       proc->RU_mask_prach_br = 0;
       pthread_mutex_unlock(&proc->mutex_RU_PRACH_br);
     }
   }
-    
+
   // check if we have to detect PRACH first
-  if (is_prach_subframe(fp,frame,subframe)>0) { 
+  if (is_prach_subframe(fp,frame,subframe)>0) {
     LOG_D(PHY,"Triggering prach br processing, frame %d, subframe %d\n",frame,subframe);
+
     if (proc->instance_cnt_prach_br == 0) {
       LOG_W(PHY,"[eNB] Frame %d Subframe %d, dropping PRACH BR\n", frame,subframe);
       return;
     }
-    
+
     // wake up thread for PRACH RX
     if (pthread_mutex_lock(&proc->mutex_prach_br) != 0) {
       LOG_E( PHY, "[eNB] ERROR pthread_mutex_lock for eNB PRACH thread %d (IC %d)\n", proc->thread_index, proc->instance_cnt_prach_br);
       exit_fun( "error locking mutex_prach" );
       return;
     }
-    
+
     ++proc->instance_cnt_prach_br;
     // set timing for prach thread
     proc->frame_prach_br = frame;
     proc->subframe_prach_br = subframe;
-    
+
     // the thread can now be woken up
     if (pthread_cond_signal(&proc->cond_prach_br) != 0) {
       LOG_E( PHY, "[eNB] ERROR pthread_cond_signal for eNB PRACH BR thread %d\n", proc->thread_index);
       exit_fun( "ERROR pthread_cond_signal" );
       return;
     }
-    
+
     pthread_mutex_unlock( &proc->mutex_prach_br );
   }
-
 }
 #endif
 
 
 /*!
  * \brief The prach receive thread of eNB.
- * \param param is a \ref eNB_proc_t structure which contains the info what to process.
+ * \param param is a \ref L1_proc_t structure which contains the info what to process.
  * \returns a pointer to an int. The storage is not on the heap and must not be freed.
  */
-static void* eNB_thread_prach( void* param ) {
+static void *eNB_thread_prach( void *param ) {
   static int eNB_thread_prach_status;
-
-
   PHY_VARS_eNB *eNB= (PHY_VARS_eNB *)param;
-  eNB_proc_t *proc = &eNB->proc;
+  L1_proc_t *proc = &eNB->proc;
 
   // set default return value
   eNB_thread_prach_status = 0;
-
   thread_top_init("eNB_thread_prach",1,500000,1000000,20000000);
 
   //wait_sync("eNB_thread_prach");
 
   while (!oai_exit) {
-    
-
-    
     if (wait_on_condition(&proc->mutex_prach,&proc->cond_prach,&proc->instance_cnt_prach,"eNB_prach_thread") < 0) break;
+
     if (oai_exit) break;
 
     LOG_D(PHY,"Running eNB prach procedures\n");
     prach_procedures(eNB
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-		     ,0
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+                     ,0
 #endif
-		     );
-    
+                    );
+
     if (release_thread(&proc->mutex_prach,&proc->instance_cnt_prach,"eNB_prach_thread") < 0) break;
   }
 
   LOG_I(PHY, "Exiting eNB thread PRACH\n");
-
   eNB_thread_prach_status = 0;
   return &eNB_thread_prach_status;
 }
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 /*!
  * \brief The prach receive thread of eNB for BL/CE UEs.
- * \param param is a \ref eNB_proc_t structure which contains the info what to process.
+ * \param param is a \ref L1_proc_t structure which contains the info what to process.
  * \returns a pointer to an int. The storage is not on the heap and must not be freed.
  */
-static void* eNB_thread_prach_br( void* param ) {
+static void *eNB_thread_prach_br( void *param ) {
   static int eNB_thread_prach_status;
-
-
   PHY_VARS_eNB *eNB= (PHY_VARS_eNB *)param;
-  eNB_proc_t *proc = &eNB->proc;
+  L1_proc_t *proc = &eNB->proc;
 
   // set default return value
   eNB_thread_prach_status = 0;
-
   thread_top_init("eNB_thread_prach_br",1,500000,1000000,20000000);
 
   while (!oai_exit) {
-    
-    
-
     if (wait_on_condition(&proc->mutex_prach_br,&proc->cond_prach_br,&proc->instance_cnt_prach_br,"eNB_prach_thread_br") < 0) break;
+
     if (oai_exit) break;
 
     LOG_D(PHY,"Running eNB prach procedures for BL/CE UEs\n");
     prach_procedures(eNB,1);
-    
+
     if (release_thread(&proc->mutex_prach_br,&proc->instance_cnt_prach_br,"eNB_prach_thread_br") < 0) break;
   }
 
   LOG_I(PHY, "Exiting eNB thread PRACH BR\n");
-
   eNB_thread_prach_status = 0;
   return &eNB_thread_prach_status;
 }
@@ -847,49 +828,49 @@ extern void init_te_thread(PHY_VARS_eNB *);
 extern void kill_td_thread(PHY_VARS_eNB *);
 extern void kill_te_thread(PHY_VARS_eNB *);
 
-static void* process_stats_thread(void* param) {
-
-  PHY_VARS_eNB     *eNB      = (PHY_VARS_eNB*)param;
-
+static void *process_stats_thread(void *param) {
+  PHY_VARS_eNB     *eNB      = (PHY_VARS_eNB *)param;
   wait_sync("process_stats_thread");
 
   while (!oai_exit) {
     sleep(1);
-      if (opp_enabled == 1) {
-        if (eNB->td) print_meas(&eNB->ulsch_decoding_stats,"ulsch_decoding",NULL,NULL);
-        if (eNB->te)
-        {
-          print_meas(&eNB->dlsch_turbo_encoding_preperation_stats,"dlsch_coding_crc",NULL,NULL);
-          print_meas(&eNB->dlsch_turbo_encoding_segmentation_stats,"dlsch_segmentation",NULL,NULL);
-          print_meas(&eNB->dlsch_encoding_stats,"dlsch_encoding",NULL,NULL);
-          print_meas(&eNB->dlsch_turbo_encoding_signal_stats,"coding_signal",NULL,NULL);
-          print_meas(&eNB->dlsch_turbo_encoding_main_stats,"coding_main",NULL,NULL);
-          print_meas(&eNB->dlsch_turbo_encoding_stats,"turbo_encoding",NULL,NULL);
-          print_meas(&eNB->dlsch_interleaving_stats,"turbo_interleaving",NULL,NULL);
-          print_meas(&eNB->dlsch_rate_matching_stats,"turbo_rate_matching",NULL,NULL);
-          print_meas(&eNB->dlsch_turbo_encoding_waiting_stats,"coding_wait",NULL,NULL);
-          print_meas(&eNB->dlsch_turbo_encoding_wakeup_stats0,"coding_worker_0",NULL,NULL);
-          print_meas(&eNB->dlsch_turbo_encoding_wakeup_stats1,"coding_worker_1",NULL,NULL);
-       }
-       print_meas(&eNB->dlsch_modulation_stats,"dlsch_modulation",NULL,NULL);
-     }
+
+    if (opp_enabled == 1) {
+      if ( eNB->ulsch_decoding_stats.trials>0)
+        print_meas(&eNB->ulsch_decoding_stats,"ulsch_decoding",NULL,NULL);
+
+      if (eNB->dlsch_encoding_stats.trials >0) {
+        print_meas(&eNB->dlsch_turbo_encoding_preperation_stats,"dlsch_coding_crc",NULL,NULL);
+        print_meas(&eNB->dlsch_turbo_encoding_segmentation_stats,"dlsch_segmentation",NULL,NULL);
+        print_meas(&eNB->dlsch_encoding_stats,"dlsch_encoding",NULL,NULL);
+        print_meas(&eNB->dlsch_turbo_encoding_signal_stats,"coding_signal",NULL,NULL);
+        print_meas(&eNB->dlsch_turbo_encoding_main_stats,"coding_main",NULL,NULL);
+        print_meas(&eNB->dlsch_turbo_encoding_stats,"turbo_encoding",NULL,NULL);
+        print_meas(&eNB->dlsch_interleaving_stats,"turbo_interleaving",NULL,NULL);
+        print_meas(&eNB->dlsch_rate_matching_stats,"turbo_rate_matching",NULL,NULL);
+        print_meas(&eNB->dlsch_turbo_encoding_waiting_stats,"coding_wait",NULL,NULL);
+        print_meas(&eNB->dlsch_turbo_encoding_wakeup_stats0,"coding_worker_0",NULL,NULL);
+        print_meas(&eNB->dlsch_turbo_encoding_wakeup_stats1,"coding_worker_1",NULL,NULL);
+      }
+
+      print_meas(&eNB->dlsch_modulation_stats,"dlsch_modulation",NULL,NULL);
+    }
   }
+
   return(NULL);
 }
 
 
 void init_eNB_proc(int inst) {
-  
   /*int i=0;*/
   int CC_id;
   PHY_VARS_eNB *eNB;
-  eNB_proc_t *proc;
-  eNB_rxtx_proc_t *proc_rxtx;
+  L1_proc_t *proc;
+  L1_rxtx_proc_t *L1_proc, *L1_proc_tx;
   pthread_attr_t *attr0=NULL,*attr1=NULL,*attr_prach=NULL;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   pthread_attr_t *attr_prach_br=NULL;
 #endif
-
   LOG_I(PHY,"%s(inst:%d) RC.nb_CC[inst]:%d \n",__FUNCTION__,inst,RC.nb_CC[inst]);
 
   for (CC_id=0; CC_id<RC.nb_CC[inst]; CC_id++) {
@@ -899,40 +880,45 @@ void init_eNB_proc(int inst) {
 #endif
     proc = &eNB->proc;
 
-    proc_rxtx                      = proc->proc_rxtx;
-    proc_rxtx[0].instance_cnt_rxtx = -1;
-    proc_rxtx[1].instance_cnt_rxtx = -1;
-    proc_rxtx[0].pipe_ready        = 0;
-    proc_rxtx[1].pipe_ready        = 0;
+    L1_proc                        = &proc->L1_proc;
+    L1_proc_tx                     = &proc->L1_proc_tx;
+    L1_proc->instance_cnt          = -1;
+    L1_proc_tx->instance_cnt       = -1;
+    L1_proc->instance_cnt_RUs      = 0;
+    L1_proc_tx->instance_cnt_RUs   = 0;
     proc->instance_cnt_prach       = -1;
     proc->instance_cnt_asynch_rxtx = -1;
     proc->instance_cnt_synch       = -1;
     proc->CC_id                    = CC_id;    
 
-    proc->first_rx=1;
-    proc->first_tx=1;
-    proc->RU_mask=0;
-    proc->RU_mask_prach=0;
+    proc->first_rx                 =1;
+    proc->first_tx                 =1;
+    proc->RU_mask_tx               = (1<<eNB->num_RU)-1;
+    proc->RU_mask                  =0;
+    proc->RU_mask_prach            =0;
 
     pthread_mutex_init( &eNB->UL_INFO_mutex, NULL);
-    pthread_mutex_init( &proc_rxtx[0].mutex_rxtx, NULL);
-    pthread_mutex_init( &proc_rxtx[1].mutex_rxtx, NULL);
-    pthread_cond_init( &proc_rxtx[0].cond_rxtx, NULL);
-    pthread_cond_init( &proc_rxtx[1].cond_rxtx, NULL);
+    pthread_mutex_init( &L1_proc->mutex, NULL);
+    pthread_mutex_init( &L1_proc_tx->mutex, NULL);
+    pthread_cond_init( &L1_proc->cond, NULL);
+    pthread_cond_init( &L1_proc_tx->cond, NULL);
+    pthread_mutex_init( &L1_proc->mutex_RUs, NULL);
+    pthread_mutex_init( &L1_proc_tx->mutex_RUs, NULL);
+    pthread_cond_init( &L1_proc->cond_RUs, NULL);
+    pthread_cond_init( &L1_proc_tx->cond_RUs, NULL);
 
     pthread_mutex_init( &proc->mutex_prach, NULL);
     pthread_mutex_init( &proc->mutex_asynch_rxtx, NULL);
     pthread_mutex_init( &proc->mutex_RU,NULL);
+    pthread_mutex_init( &proc->mutex_RU_tx,NULL);
     pthread_mutex_init( &proc->mutex_RU_PRACH,NULL);
-
     pthread_cond_init( &proc->cond_prach, NULL);
     pthread_cond_init( &proc->cond_asynch_rxtx, NULL);
-
     pthread_attr_init( &proc->attr_prach);
     pthread_attr_init( &proc->attr_asynch_rxtx);
-    pthread_attr_init( &proc_rxtx[0].attr_rxtx);
-    pthread_attr_init( &proc_rxtx[1].attr_rxtx);
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+    pthread_attr_init( &L1_proc->attr);
+    pthread_attr_init( &L1_proc_tx->attr);
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
     proc->instance_cnt_prach_br    = -1;
     proc->RU_mask_prach_br=0;
     pthread_mutex_init( &proc->mutex_prach_br, NULL);
@@ -941,58 +927,52 @@ void init_eNB_proc(int inst) {
     pthread_attr_init( &proc->attr_prach_br);
 #endif
 #ifndef DEADLINE_SCHEDULER
-    attr0       = &proc_rxtx[0].attr_rxtx;
-    attr1       = &proc_rxtx[1].attr_rxtx;
+    attr0       = &L1_proc->attr;
+    attr1       = &L1_proc_tx->attr;
     attr_prach  = &proc->attr_prach;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
     attr_prach_br  = &proc->attr_prach_br;
 #endif
-
     //    attr_td     = &proc->attr_td;
-    //    attr_te     = &proc->attr_te; 
+    //    attr_te     = &proc->attr_te;
 #endif
 
-    if(get_thread_worker_conf() == WORKER_ENABLE)
-    {
+    if(get_thread_worker_conf() == WORKER_ENABLE) {
       init_te_thread(eNB);
       init_td_thread(eNB);
     }
 
-
     LOG_I(PHY,"eNB->single_thread_flag:%d\n", eNB->single_thread_flag);
 
     if ((get_thread_parallel_conf() == PARALLEL_RU_L1_SPLIT || get_thread_parallel_conf() == PARALLEL_RU_L1_TRX_SPLIT) && nfapi_mode!=2) {
-      pthread_create( &proc_rxtx[0].pthread_rxtx, attr0, eNB_thread_rxtx, proc );
-      pthread_create( &proc_rxtx[1].pthread_rxtx, attr1, tx_thread, proc);
+      pthread_create( &L1_proc->pthread, attr0, L1_thread, proc );
+      pthread_create( &L1_proc_tx->pthread, attr1, L1_thread_tx, proc);
+    } else if (nfapi_mode == 2) { // this is neccesary in VNF or L2 FAPI simulator.
+      // Original Code from Fujitsu w/ old structure/field name
+      //pthread_create( &proc_rxtx[0].pthread_rxtx, attr0, eNB_thread_rxtx, &proc_rxtx[0] );
+      //pthread_create( &proc_rxtx[1].pthread_rxtx, attr1, eNB_thread_rxtx, &proc_rxtx[1] );
+      pthread_create( &L1_proc->pthread, attr0, L1_thread, L1_proc );
+      pthread_create( &L1_proc_tx->pthread, attr1, L1_thread, L1_proc_tx);
     }
+
     pthread_create( &proc->pthread_prach, attr_prach, eNB_thread_prach, eNB );
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
     pthread_create( &proc->pthread_prach_br, attr_prach_br, eNB_thread_prach_br, eNB );
 #endif
-    /*char name[16];
-    if (eNB->single_thread_flag==0) {
-      snprintf( name, sizeof(name), "RXTX0 %d", i );
-      pthread_setname_np( proc_rxtx[0].pthread_rxtx, name );
-      snprintf( name, sizeof(name), "RXTX1 %d", i );
-      pthread_setname_np( proc_rxtx[1].pthread_rxtx, name );
-    }*/
 
     AssertFatal(proc->instance_cnt_prach == -1,"instance_cnt_prach = %d\n",proc->instance_cnt_prach);
-	
 
-    if (opp_enabled == 1) pthread_create(&proc->process_stats_thread,NULL,process_stats_thread,(void*)eNB);
-
-    
+    if (opp_enabled == 1) pthread_create(&proc->process_stats_thread,NULL,process_stats_thread,(void *)eNB);
   }
 
   //for multiple CCs: setup master and slaves
-  /* 
+  /*
      for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
      eNB = PHY_vars_eNB_g[inst][CC_id];
 
      if (eNB->node_timing == synch_to_ext_device) { //master
      eNB->proc.num_slaves = MAX_NUM_CCs-1;
-     eNB->proc.slave_proc = (eNB_proc_t**)malloc(eNB->proc.num_slaves*sizeof(eNB_proc_t*));
+     eNB->proc.slave_proc = (L1_proc_t**)malloc(eNB->proc.num_slaves*sizeof(L1_proc_t*));
 
      for (i=0; i< eNB->proc.num_slaves; i++) {
      if (i < CC_id)  eNB->proc.slave_proc[i] = &(PHY_vars_eNB_g[inst][i]->proc);
@@ -1001,13 +981,10 @@ void init_eNB_proc(int inst) {
      }
      }
   */
-
   /* setup PHY proc TX sync mechanism */
   pthread_mutex_init(&sync_phy_proc.mutex_phy_proc_tx, NULL);
   pthread_cond_init(&sync_phy_proc.cond_phy_proc_tx, NULL);
   sync_phy_proc.phy_proc_CC_id = 0;
-  
-  
 }
 
 
@@ -1016,70 +993,83 @@ void init_eNB_proc(int inst) {
  * \brief Terminate eNB TX and RX threads.
  */
 void kill_eNB_proc(int inst) {
-
   int *status;
   PHY_VARS_eNB *eNB;
-  eNB_proc_t *proc;
-  eNB_rxtx_proc_t *proc_rxtx;
-  int i;
+  L1_proc_t *proc;
+  L1_rxtx_proc_t *L1_proc, *L1_proc_tx;
+
   for (int CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
     eNB=RC.eNB[inst][CC_id];
     
-    proc = &eNB->proc;
-    proc_rxtx = &proc->proc_rxtx[0];
+    proc        = &eNB->proc;
+    L1_proc     = &proc->L1_proc;
+    L1_proc_tx  = &proc->L1_proc_tx;
 
     if(get_thread_worker_conf() == WORKER_ENABLE) {
       kill_td_thread(eNB);
       kill_te_thread(eNB);
     }
+
     LOG_I(PHY, "Killing TX CC_id %d inst %d\n", CC_id, inst );
-    for (i=0; i<2; i++) {
-      pthread_mutex_lock(&proc_rxtx[i].mutex_rxtx);
-      proc_rxtx[i].instance_cnt_rxtx = 0;
-      proc_rxtx[i].pipe_ready = 0;
-      pthread_cond_signal(&proc_rxtx[i].cond_rxtx);
-      pthread_mutex_unlock(&proc_rxtx[i].mutex_rxtx);
+
+    if ((get_thread_parallel_conf() == PARALLEL_RU_L1_SPLIT || get_thread_parallel_conf() == PARALLEL_RU_L1_TRX_SPLIT) && nfapi_mode!=2) {
+      pthread_mutex_lock(&L1_proc->mutex);
+      L1_proc->instance_cnt = 0;
+      pthread_cond_signal(&L1_proc->cond);
+      pthread_mutex_unlock(&L1_proc->mutex);
+
+      pthread_mutex_lock(&L1_proc_tx->mutex);
+      L1_proc_tx->instance_cnt = 0;
+      pthread_cond_signal(&L1_proc_tx->cond);
+      pthread_mutex_unlock(&L1_proc_tx->mutex);
     }
+
     pthread_mutex_lock(&proc->mutex_prach);
     proc->instance_cnt_prach = 0;
     pthread_cond_signal( &proc->cond_prach );
     pthread_mutex_unlock(&proc->mutex_prach);
-
     pthread_cond_signal( &proc->cond_asynch_rxtx );
     pthread_cond_broadcast(&sync_phy_proc.cond_phy_proc_tx);
-
     LOG_D(PHY, "joining pthread_prach\n");
-    pthread_join( proc->pthread_prach, (void**)&status );    
-
+    pthread_join( proc->pthread_prach, (void **)&status );
     LOG_I(PHY, "Destroying prach mutex/cond\n");
     pthread_mutex_destroy( &proc->mutex_prach );
     pthread_cond_destroy( &proc->cond_prach );
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
     proc->instance_cnt_prach_br = 0;
     pthread_cond_signal( &proc->cond_prach_br );
-    pthread_join( proc->pthread_prach_br, (void**)&status );    
+    pthread_join( proc->pthread_prach_br, (void **)&status );
     pthread_mutex_destroy( &proc->mutex_prach_br );
     pthread_cond_destroy( &proc->cond_prach_br );
 #endif
     LOG_I(PHY, "Destroying UL_INFO mutex\n");
     pthread_mutex_destroy(&eNB->UL_INFO_mutex);
-    for (i=0;i<2;i++) {
-      LOG_I(PHY, "Joining rxtx[%d] mutex/cond\n",i);
-      pthread_join( proc_rxtx[i].pthread_rxtx, (void**)&status );
-      LOG_I(PHY, "Destroying rxtx[%d] mutex/cond\n",i);
-      pthread_mutex_destroy( &proc_rxtx[i].mutex_rxtx );
-      pthread_cond_destroy( &proc_rxtx[i].cond_rxtx );
+
+    if ((get_thread_parallel_conf() == PARALLEL_RU_L1_SPLIT || get_thread_parallel_conf() == PARALLEL_RU_L1_TRX_SPLIT) && nfapi_mode!=2) {
+      LOG_I(PHY, "Joining L1_proc mutex/cond\n");
+      pthread_join( L1_proc->pthread, (void**)&status );
+      LOG_I(PHY, "Joining L1_proc_tx mutex/cond\n");
+      pthread_join( L1_proc_tx->pthread, (void**)&status );
     }
+    LOG_I(PHY, "Destroying L1_proc mutex/cond\n");
+    pthread_mutex_destroy( &L1_proc->mutex );
+    pthread_cond_destroy( &L1_proc->cond );
+    pthread_mutex_destroy( &L1_proc->mutex_RUs );
+    pthread_cond_destroy( &L1_proc->cond_RUs );
+    LOG_I(PHY, "Destroying L1_proc_tx mutex/cond\n");
+    pthread_mutex_destroy( &L1_proc_tx->mutex );
+    pthread_cond_destroy( &L1_proc_tx->cond );
+    pthread_mutex_destroy( &L1_proc_tx->mutex_RUs );
+    pthread_cond_destroy( &L1_proc_tx->cond_RUs );
 
     pthread_attr_destroy(&proc->attr_prach);
     pthread_attr_destroy(&proc->attr_asynch_rxtx);
-    pthread_attr_destroy(&proc_rxtx[0].attr_rxtx);
-    pthread_attr_destroy(&proc_rxtx[1].attr_rxtx);
-#ifdef Rel14
+    pthread_attr_destroy(&L1_proc->attr);
+    pthread_attr_destroy(&L1_proc_tx->attr);
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
     pthread_mutex_destroy(&proc->mutex_RU_PRACH_br);
     pthread_attr_destroy(&proc->attr_prach_br);
 #endif
-
   }
 }
 
@@ -1087,11 +1077,10 @@ void kill_eNB_proc(int inst) {
 
 
 void reset_opp_meas(void) {
-
   int sfn;
   reset_meas(&softmodem_stats_mt);
   reset_meas(&softmodem_stats_hw);
-  
+
   for (sfn=0; sfn < 10; sfn++) {
     reset_meas(&softmodem_stats_rxtx_sf);
     reset_meas(&softmodem_stats_rx_sf);
@@ -1100,197 +1089,177 @@ void reset_opp_meas(void) {
 
 
 void print_opp_meas(void) {
-
   int sfn=0;
   print_meas(&softmodem_stats_mt, "Main ENB Thread", NULL, NULL);
   print_meas(&softmodem_stats_hw, "HW Acquisation", NULL, NULL);
-  
+
   for (sfn=0; sfn < 10; sfn++) {
     print_meas(&softmodem_stats_rxtx_sf,"[eNB][total_phy_proc_rxtx]",NULL, NULL);
     print_meas(&softmodem_stats_rx_sf,"[eNB][total_phy_proc_rx]",NULL,NULL);
   }
 }
 
-void free_transport(PHY_VARS_eNB *eNB)
-{
+void free_transport(PHY_VARS_eNB *eNB) {
   int i;
   int j;
 
   for (i=0; i<NUMBER_OF_UE_MAX; i++) {
     LOG_D(PHY, "Freeing Transport Channel Buffers for DLSCH, UE %d\n",i);
+
     for (j=0; j<2; j++) free_eNB_dlsch(eNB->dlsch[i][j]);
 
     LOG_D(PHY, "Freeing Transport Channel Buffer for ULSCH, UE %d\n",i);
     free_eNB_ulsch(eNB->ulsch[1+i]);
   }
+
   free_eNB_ulsch(eNB->ulsch[0]);
 }
 
 void init_transport(PHY_VARS_eNB *eNB) {
-
   int i;
   int j;
   LTE_DL_FRAME_PARMS *fp = &eNB->frame_parms;
-
   LOG_I(PHY, "Initialise transport\n");
 
   for (i=0; i<NUMBER_OF_UE_MAX; i++) {
     LOG_D(PHY,"Allocating Transport Channel Buffers for DLSCH, UE %d\n",i);
+
     for (j=0; j<2; j++) {
       eNB->dlsch[i][j] = new_eNB_dlsch(1,8,NSOFT,fp->N_RB_DL,0,fp);
+
       if (!eNB->dlsch[i][j]) {
-	LOG_E(PHY,"Can't get eNB dlsch structures for UE %d \n", i);
-	exit(-1);
+        LOG_E(PHY,"Can't get eNB dlsch structures for UE %d \n", i);
+        exit(-1);
       } else {
-	eNB->dlsch[i][j]->rnti=0;
-	LOG_D(PHY,"dlsch[%d][%d] => %p rnti:%d\n",i,j,eNB->dlsch[i][j], eNB->dlsch[i][j]->rnti);
+        eNB->dlsch[i][j]->rnti=0;
+        LOG_D(PHY,"dlsch[%d][%d] => %p rnti:%d\n",i,j,eNB->dlsch[i][j], eNB->dlsch[i][j]->rnti);
       }
     }
-    
+
     LOG_D(PHY,"Allocating Transport Channel Buffer for ULSCH, UE %d\n",i);
     eNB->ulsch[1+i] = new_eNB_ulsch(MAX_TURBO_ITERATIONS,fp->N_RB_UL, 0);
-    
+
     if (!eNB->ulsch[1+i]) {
       LOG_E(PHY,"Can't get eNB ulsch structures\n");
       exit(-1);
     }
-    
+
     // this is the transmission mode for the signalling channels
     // this will be overwritten with the real transmission mode by the RRC once the UE is connected
     eNB->transmission_mode[i] = fp->nb_antenna_ports_eNB==1 ? 1 : 2;
   }
+
   // ULSCH for RA
   eNB->ulsch[0] = new_eNB_ulsch(MAX_TURBO_ITERATIONS, fp->N_RB_UL, 0);
-  
+
   if (!eNB->ulsch[0]) {
     LOG_E(PHY,"Can't get eNB ulsch structures\n");
     exit(-1);
   }
+
   eNB->dlsch_SI  = new_eNB_dlsch(1,8,NSOFT,fp->N_RB_DL, 0, fp);
   LOG_D(PHY,"eNB %d.%d : SI %p\n",eNB->Mod_id,eNB->CC_id,eNB->dlsch_SI);
   eNB->dlsch_ra  = new_eNB_dlsch(1,8,NSOFT,fp->N_RB_DL, 0, fp);
   LOG_D(PHY,"eNB %d.%d : RA %p\n",eNB->Mod_id,eNB->CC_id,eNB->dlsch_ra);
   eNB->dlsch_MCH = new_eNB_dlsch(1,8,NSOFT,fp->N_RB_DL, 0, fp);
   LOG_D(PHY,"eNB %d.%d : MCH %p\n",eNB->Mod_id,eNB->CC_id,eNB->dlsch_MCH);
-  
-  
   eNB->rx_total_gain_dB=130;
-  
+
   for(i=0; i<NUMBER_OF_UE_MAX; i++)
     eNB->mu_mimo_mode[i].dl_pow_off = 2;
-  
+
   eNB->check_for_total_transmissions = 0;
-  
   eNB->check_for_MUMIMO_transmissions = 0;
-  
   eNB->FULL_MUMIMO_transmissions = 0;
-  
   eNB->check_for_SUMIMO_transmissions = 0;
-  
   fp->pucch_config_common.deltaPUCCH_Shift = 1;
-    
-} 
+}
 
 void init_eNB_afterRU(void) {
-
   int inst,CC_id,ru_id,i,aa;
   PHY_VARS_eNB *eNB;
-
   LOG_I(PHY,"%s() RC.nb_inst:%d\n", __FUNCTION__, RC.nb_inst);
 
-  for (inst=0;inst<RC.nb_inst;inst++) {
+  for (inst=0; inst<RC.nb_inst; inst++) {
     LOG_I(PHY,"RC.nb_CC[inst]:%d\n", RC.nb_CC[inst]);
-    for (CC_id=0;CC_id<RC.nb_CC[inst];CC_id++) {
 
+    for (CC_id=0; CC_id<RC.nb_CC[inst]; CC_id++) {
       LOG_I(PHY,"RC.nb_CC[inst:%d][CC_id:%d]:%p\n", inst, CC_id, RC.eNB[inst][CC_id]);
-
       eNB                                  =  RC.eNB[inst][CC_id];
       phy_init_lte_eNB(eNB,0,0);
+
       // map antennas and PRACH signals to eNB RX
       if (0) AssertFatal(eNB->num_RU>0,"Number of RU attached to eNB %d is zero\n",eNB->Mod_id);
+
       LOG_I(PHY,"Mapping RX ports from %d RUs to eNB %d\n",eNB->num_RU,eNB->Mod_id);
       eNB->frame_parms.nb_antennas_rx       = 0;
-
       LOG_I(PHY,"Overwriting eNB->prach_vars.rxsigF[0]:%p\n", eNB->prach_vars.rxsigF[0]);
+      eNB->prach_vars.rxsigF[0] = (int16_t **)malloc16(64*sizeof(int16_t *));
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 
-      eNB->prach_vars.rxsigF[0] = (int16_t**)malloc16(64*sizeof(int16_t*));
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-      for (int ce_level=0;ce_level<4;ce_level++) {
+      for (int ce_level=0; ce_level<4; ce_level++) {
         LOG_I(PHY,"Overwriting eNB->prach_vars_br.rxsigF.rxsigF[0]:%p\n", eNB->prach_vars_br.rxsigF[ce_level]);
-        eNB->prach_vars_br.rxsigF[ce_level] = (int16_t**)malloc16(64*sizeof(int16_t*));
+        eNB->prach_vars_br.rxsigF[ce_level] = (int16_t **)malloc16(64*sizeof(int16_t *));
       }
-#endif
 
+#endif
       LOG_I(PHY,"eNB->num_RU:%d\n", eNB->num_RU);
 
-      for (ru_id=0,aa=0;ru_id<eNB->num_RU;ru_id++) {
-	eNB->frame_parms.nb_antennas_rx    += eNB->RU_list[ru_id]->nb_rx;
+      for (ru_id=0,aa=0; ru_id<eNB->num_RU; ru_id++) {
+        eNB->frame_parms.nb_antennas_rx    += eNB->RU_list[ru_id]->nb_rx;
+        AssertFatal(eNB->RU_list[ru_id]->common.rxdataF!=NULL,
+                    "RU %d : common.rxdataF is NULL\n",
+                    eNB->RU_list[ru_id]->idx);
+        AssertFatal(eNB->RU_list[ru_id]->prach_rxsigF!=NULL,
+                    "RU %d : prach_rxsigF is NULL\n",
+                    eNB->RU_list[ru_id]->idx);
 
-	AssertFatal(eNB->RU_list[ru_id]->common.rxdataF!=NULL,
-		    "RU %d : common.rxdataF is NULL\n",
-		    eNB->RU_list[ru_id]->idx);
+        for (i=0; i<eNB->RU_list[ru_id]->nb_rx; aa++,i++) {
+          LOG_I(PHY,"Attaching RU %d antenna %d to eNB antenna %d\n",eNB->RU_list[ru_id]->idx,i,aa);
+          eNB->prach_vars.rxsigF[0][aa]    =  eNB->RU_list[ru_id]->prach_rxsigF[i];
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 
-	AssertFatal(eNB->RU_list[ru_id]->prach_rxsigF!=NULL,
-		    "RU %d : prach_rxsigF is NULL\n",
-		    eNB->RU_list[ru_id]->idx);
+          for (int ce_level=0; ce_level<4; ce_level++)
+            eNB->prach_vars_br.rxsigF[ce_level][aa] = eNB->RU_list[ru_id]->prach_rxsigF_br[ce_level][i];
 
-	for (i=0;i<eNB->RU_list[ru_id]->nb_rx;aa++,i++) { 
-	  LOG_I(PHY,"Attaching RU %d antenna %d to eNB antenna %d\n",eNB->RU_list[ru_id]->idx,i,aa);
-	  eNB->prach_vars.rxsigF[0][aa]    =  eNB->RU_list[ru_id]->prach_rxsigF[i];
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-	  for (int ce_level=0;ce_level<4;ce_level++)
-	    eNB->prach_vars_br.rxsigF[ce_level][aa] = eNB->RU_list[ru_id]->prach_rxsigF_br[ce_level][i];
 #endif
-	  eNB->common_vars.rxdataF[aa]     =  eNB->RU_list[ru_id]->common.rxdataF[i];
-	}
+          eNB->common_vars.rxdataF[aa]     =  eNB->RU_list[ru_id]->common.rxdataF[i];
+        }
       }
 
-
-
       /* TODO: review this code, there is something wrong.
        * In monolithic mode, we come here with nb_antennas_rx == 0
        * (not tested in other modes).
        */
-      if (eNB->frame_parms.nb_antennas_rx < 1)
-      {
+      if (eNB->frame_parms.nb_antennas_rx < 1) {
         LOG_I(PHY, "%s() ************* DJP ***** eNB->frame_parms.nb_antennas_rx:%d - GOING TO HARD CODE TO 1", __FUNCTION__, eNB->frame_parms.nb_antennas_rx);
         eNB->frame_parms.nb_antennas_rx = 1;
-      }
-      else
-      {
+      } else {
         //LOG_I(PHY," Delete code\n");
       }
 
-      if (eNB->frame_parms.nb_antennas_tx < 1)
-      {
+      if (eNB->frame_parms.nb_antennas_tx < 1) {
         LOG_I(PHY, "%s() ************* DJP ***** eNB->frame_parms.nb_antennas_tx:%d - GOING TO HARD CODE TO 1", __FUNCTION__, eNB->frame_parms.nb_antennas_tx);
         eNB->frame_parms.nb_antennas_tx = 1;
-      }
-      else
-      {
+      } else {
         //LOG_I(PHY," Delete code\n");
       }
 
-
-
-
       AssertFatal(eNB->frame_parms.nb_antennas_rx >0,
-		  "inst %d, CC_id %d : nb_antennas_rx %d\n",inst,CC_id,eNB->frame_parms.nb_antennas_rx);
+                  "inst %d, CC_id %d : nb_antennas_rx %d\n",inst,CC_id,eNB->frame_parms.nb_antennas_rx);
       LOG_I(PHY,"inst %d, CC_id %d : nb_antennas_rx %d\n",inst,CC_id,eNB->frame_parms.nb_antennas_rx);
-
       init_transport(eNB);
       //init_precoding_weights(RC.eNB[inst][CC_id]);
     }
+
     init_eNB_proc(inst);
   }
 
-  for (ru_id=0;ru_id<RC.nb_RU;ru_id++) {
-
+  for (ru_id=0; ru_id<RC.nb_RU; ru_id++) {
     AssertFatal(RC.ru[ru_id]!=NULL,"ru_id %d is null\n",ru_id);
-    
     RC.ru[ru_id]->wakeup_rxtx         = wakeup_rxtx;
     RC.ru[ru_id]->wakeup_prach_eNB    = wakeup_prach_eNB;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
     RC.ru[ru_id]->wakeup_prach_eNB_br = wakeup_prach_eNB_br;
 #endif
     RC.ru[ru_id]->eNB_top             = eNB_top;
@@ -1298,40 +1267,34 @@ void init_eNB_afterRU(void) {
 }
 
 void init_eNB(int single_thread_flag,int wait_for_sync) {
-  
   int CC_id;
   int inst;
   PHY_VARS_eNB *eNB;
-
   LOG_I(PHY,"[lte-softmodem.c] eNB structure about to allocated RC.nb_L1_inst:%d RC.nb_L1_CC[0]:%d\n",RC.nb_L1_inst,RC.nb_L1_CC[0]);
 
-  if (RC.eNB == NULL) RC.eNB = (PHY_VARS_eNB***) malloc(RC.nb_L1_inst*sizeof(PHY_VARS_eNB **));
+  if (RC.eNB == NULL) RC.eNB = (PHY_VARS_eNB ** *) malloc(RC.nb_L1_inst*sizeof(PHY_VARS_eNB **));
+
   LOG_I(PHY,"[lte-softmodem.c] eNB structure RC.eNB allocated\n");
-  for (inst=0;inst<RC.nb_L1_inst;inst++) {
-    if (RC.eNB[inst] == NULL) RC.eNB[inst] = (PHY_VARS_eNB**) malloc(RC.nb_CC[inst]*sizeof(PHY_VARS_eNB *));
-    for (CC_id=0;CC_id<RC.nb_L1_CC[inst];CC_id++) {
-      if (RC.eNB[inst][CC_id] == NULL) RC.eNB[inst][CC_id] = (PHY_VARS_eNB*) malloc(sizeof(PHY_VARS_eNB));
-      eNB                     = RC.eNB[inst][CC_id]; 
-      eNB->abstraction_flag   = 0;
-      eNB->single_thread_flag = single_thread_flag;
 
+  for (inst=0; inst<RC.nb_L1_inst; inst++) {
+    if (RC.eNB[inst] == NULL) RC.eNB[inst] = (PHY_VARS_eNB **) malloc(RC.nb_CC[inst]*sizeof(PHY_VARS_eNB *));
 
+    for (CC_id=0; CC_id<RC.nb_L1_CC[inst]; CC_id++) {
+      if (RC.eNB[inst][CC_id] == NULL) RC.eNB[inst][CC_id] = (PHY_VARS_eNB *) malloc(sizeof(PHY_VARS_eNB));
+
+      eNB                     = RC.eNB[inst][CC_id];
+      eNB->abstraction_flag   = 0;
+      eNB->single_thread_flag = single_thread_flag;
       LOG_I(PHY,"Initializing eNB %d CC_id %d single_thread_flag:%d\n",inst,CC_id,single_thread_flag);
 #ifndef OCP_FRAMEWORK
       LOG_I(PHY,"Initializing eNB %d CC_id %d\n",inst,CC_id);
 #endif
-
-
-      eNB->td                   = ulsch_decoding_data_all;
-      eNB->te                   = dlsch_encoding_all;
-
-      
       LOG_I(PHY,"Registering with MAC interface module\n");
       AssertFatal((eNB->if_inst         = IF_Module_init(inst))!=NULL,"Cannot register interface");
       eNB->if_inst->schedule_response   = schedule_response;
       eNB->if_inst->PHY_config_req      = phy_config_request;
-      memset((void*)&eNB->UL_INFO,0,sizeof(eNB->UL_INFO));
-      memset((void*)&eNB->Sched_INFO,0,sizeof(eNB->Sched_INFO));
+      memset((void *)&eNB->UL_INFO,0,sizeof(eNB->UL_INFO));
+      memset((void *)&eNB->Sched_INFO,0,sizeof(eNB->Sched_INFO));
       LOG_I(PHY,"Setting indication lists\n");
       eNB->UL_INFO.rx_ind.rx_indication_body.rx_pdu_list   = eNB->rx_pdu_list;
       eNB->UL_INFO.crc_ind.crc_indication_body.crc_pdu_list = eNB->crc_pdu_list;
@@ -1341,7 +1304,6 @@ void init_eNB(int single_thread_flag,int wait_for_sync) {
       eNB->UL_INFO.cqi_ind.cqi_raw_pdu_list = eNB->cqi_raw_pdu_list;
       eNB->prach_energy_counter = 0;
     }
-
   }
 
   LOG_I(PHY,"[lte-softmodem.c] eNB structure allocated\n");
@@ -1349,8 +1311,7 @@ void init_eNB(int single_thread_flag,int wait_for_sync) {
 
 
 void stop_eNB(int nb_inst) {
-
-  for (int inst=0;inst<nb_inst;inst++) {
+  for (int inst=0; inst<nb_inst; inst++) {
     LOG_I(PHY,"Killing eNB %d processing threads\n",inst);
     kill_eNB_proc(inst);
   }
diff --git a/targets/RT/USER/lte-ru.c b/targets/RT/USER/lte-ru.c
index f4c0d14ae4d5a15205ea7c76baf16bfb148f074d..ad0cb65e7c726a0a8717a01f157fc01c6706e4b7 100644
--- a/targets/RT/USER/lte-ru.c
+++ b/targets/RT/USER/lte-ru.c
@@ -90,6 +90,7 @@
 #include "common/utils/LOG/vcd_signal_dumper.h"
 #include "UTIL/OPT/opt.h"
 #include "enb_config.h"
+#include "targets/RT/USER/lte-softmodem.h"
 //#include "PHY/TOOLS/time_meas.h"
 
 /* these variables have to be defined before including ENB_APP/enb_paramdef.h */
@@ -120,13 +121,15 @@ extern volatile int                    oai_exit;
 extern int emulate_rf;
 extern int numerology;
 extern clock_source_t clock_source;
+extern uint8_t dlsch_ue_select_tbl_in_use;
+extern uint8_t nfapi_mode;
 
 extern PARALLEL_CONF_t get_thread_parallel_conf(void);
 extern WORKER_CONF_t   get_thread_worker_conf(void);
 extern void  phy_init_RU(RU_t*);
 extern void  phy_free_RU(RU_t*);
 
-void init_RU(char*);
+
 void stop_RU(int nb_ru);
 void do_ru_sync(RU_t *ru);
 
@@ -142,6 +145,11 @@ int connect_rau(RU_t *ru);
 
 extern uint16_t sf_ahead;
 
+#if defined(PRE_SCD_THREAD)
+void init_ru_vnf(void);
+#endif
+
+
 /*************************************************************/
 /* Functions to attach and configure RRU                     */
 
@@ -526,7 +534,7 @@ void fh_if4p5_south_asynch_in(RU_t *ru,int *frame,int *subframe) {
     }
     if      (packet_type == IF4p5_PULFFT)       symbol_mask &= (~(1<<symbol_number));
     else if (packet_type == IF4p5_PRACH)        prach_rx    &= (~0x1);
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
     else if (packet_type == IF4p5_PRACH_BR_CE0) prach_rx    &= (~0x2);
     else if (packet_type == IF4p5_PRACH_BR_CE1) prach_rx    &= (~0x4);
     else if (packet_type == IF4p5_PRACH_BR_CE2) prach_rx    &= (~0x8);
@@ -699,6 +707,7 @@ static void* emulatedRF_thread(void* param) {
   RU_proc_t *proc = (RU_proc_t *) param;
   int microsec = 500; // length of time to sleep, in miliseconds
   struct timespec req = {0};
+  int numerology = get_softmodem_params()->numerology;
   req.tv_sec = 0;
   req.tv_nsec = (numerology>0)? ((microsec * 1000L)/numerology):(microsec * 1000L)*2;
   cpu_set_t cpuset;
@@ -743,7 +752,7 @@ void rx_rf(RU_t *ru,int *frame,int *subframe) {
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_READ, 1 );
 
   old_ts = proc->timestamp_rx;
-  if(emulate_rf){
+  if(get_softmodem_params()->emulate_rf){
     wait_on_condition(&proc->mutex_emulateRF,&proc->cond_emulateRF,&proc->instance_cnt_emulateRF,"emulatedRF_thread");
     release_thread(&proc->mutex_emulateRF,&proc->instance_cnt_emulateRF,"emulatedRF_thread");
     rxs = fp->samples_per_tti;
@@ -761,9 +770,9 @@ void rx_rf(RU_t *ru,int *frame,int *subframe) {
   proc->timestamp_rx = ts-ru->ts_offset;
 
 //  AssertFatal(rxs == fp->samples_per_tti,
-//	      "rx_rf: Asked for %d samples, got %d from USRP\n",fp->samples_per_tti,rxs);
+//	      "rx_rf: Asked for %d samples, got %d from SDR\n",fp->samples_per_tti,rxs);
   if(rxs != fp->samples_per_tti){
-    LOG_E(PHY,"rx_rf: Asked for %d samples, got %d from USRP\n",fp->samples_per_tti,rxs);
+    LOG_E(PHY,"rx_rf: Asked for %d samples, got %d from SDR\n",fp->samples_per_tti,rxs);
     late_control=STATE_BURST_TERMINATE;
   }
 
@@ -956,7 +965,7 @@ void tx_rf(RU_t *ru) {
 /*!
  * \brief The Asynchronous RX/TX FH thread of RAU/RCC/eNB/RRU.
  * This handles the RX FH for an asynchronous RRU/UE
- * \param param is a \ref eNB_proc_t structure which contains the info what to process.
+ * \param param is a \ref L1_proc_t structure which contains the info what to process.
  * \returns a pointer to an int. The storage is not on the heap and must not be freed.
  */
 static void* ru_thread_asynch_rxtx( void* param ) {
@@ -1086,7 +1095,7 @@ static void* ru_thread_prach( void* param ) {
     if (ru->eNB_list[0]){
       prach_procedures(
         ru->eNB_list[0]
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
         ,0
 #endif
         );
@@ -1099,7 +1108,7 @@ static void* ru_thread_prach( void* param ) {
                 NULL,
                 proc->frame_prach,
                 0
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 	        ,0
 #endif
 	        );
@@ -1114,7 +1123,7 @@ static void* ru_thread_prach( void* param ) {
   return &ru_thread_prach_status;
 }
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 static void* ru_thread_prach_br( void* param ) {
 
   static int ru_thread_prach_status;
@@ -1249,12 +1258,12 @@ void do_ru_synch(RU_t *ru) {
 
 
 
-void wakeup_eNBs(RU_t *ru) {
+void wakeup_L1s(RU_t *ru) {
 
   int i;
   PHY_VARS_eNB **eNB_list = ru->eNB_list;
 
-  LOG_D(PHY,"wakeup_eNBs (num %d) for RU %d ru->eNB_top:%p\n",ru->num_eNB,ru->idx, ru->eNB_top);
+  LOG_D(PHY,"wakeup_L1s (num %d) for RU %d ru->eNB_top:%p\n",ru->num_eNB,ru->idx, ru->eNB_top);
 
 
   if (ru->num_eNB==1 && ru->eNB_top!=0 && get_thread_parallel_conf() == PARALLEL_SINGLE_THREAD) {
@@ -1273,7 +1282,6 @@ void wakeup_eNBs(RU_t *ru) {
     for (i=0;i<ru->num_eNB;i++)
     {
       LOG_D(PHY,"ru->wakeup_rxtx:%p\n", ru->wakeup_rxtx);
-      eNB_list[i]->proc.ru_proc = &ru->proc;
       if (ru->wakeup_rxtx!=0 && ru->wakeup_rxtx(eNB_list[i],ru) < 0)
       {
         LOG_E(PHY,"could not wakeup eNB rxtx process for subframe %d\n", ru->proc.subframe_rx);
@@ -1315,7 +1323,7 @@ static inline int wakeup_prach_ru(RU_t *ru) {
   return(0);
 }
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 static inline int wakeup_prach_ru_br(RU_t *ru) {
 
   struct timespec wait;
@@ -1352,7 +1360,7 @@ void fill_rf_config(RU_t *ru, char *rf_config_file) {
   LTE_DL_FRAME_PARMS *fp   = &ru->frame_parms;
   openair0_config_t *cfg   = &ru->openair0_cfg;
   //printf("////////////////numerology in config = %d\n",numerology);
-
+  int numerology = get_softmodem_params()->numerology;
   if(fp->N_RB_DL == 100) {
     if(numerology == 0){
       if (fp->threequarter_fs) {
@@ -1411,7 +1419,7 @@ void fill_rf_config(RU_t *ru, char *rf_config_file) {
   cfg->num_rb_dl=fp->N_RB_DL;
   cfg->tx_num_channels=ru->nb_tx;
   cfg->rx_num_channels=ru->nb_rx;
-  cfg->clock_source=clock_source;
+  cfg->clock_source=get_softmodem_params()->clock_source;
 
   for (i=0; i<ru->nb_tx; i++) {
     
@@ -1421,6 +1429,7 @@ void fill_rf_config(RU_t *ru, char *rf_config_file) {
     cfg->tx_gain[i] = (double)ru->att_tx;
     cfg->rx_gain[i] = ru->max_rxgain-(double)ru->att_rx;
 
+
     cfg->configFilename = rf_config_file;
     printf("channel %d, Setting tx_gain offset %f, rx_gain offset %f, tx_freq %f, rx_freq %f\n",
 	   i, cfg->tx_gain[i],
@@ -1447,7 +1456,7 @@ int setup_RU_buffers(RU_t *ru) {
     frame_parms = &ru->frame_parms;
     printf("setup_RU_buffers: frame_parms = %p\n",frame_parms);
   } else {
-    printf("RU[%d] not initialized\n", ru->idx);
+    printf("RU not initialized (NULL pointer)\n");
     return(-1);
   }
   
@@ -1529,8 +1538,12 @@ volatile int16_t phy_tx_end;
 #endif
 
 static void* ru_thread_tx( void* param ) {
-  RU_t *ru         = (RU_t*)param;
-  RU_proc_t *proc  = &ru->proc;
+  RU_t *ru              = (RU_t*)param;
+  RU_proc_t *proc       = &ru->proc;
+  PHY_VARS_eNB *eNB;
+  L1_proc_t *eNB_proc;
+  L1_rxtx_proc_t *L1_proc;
+
   cpu_set_t cpuset;
   CPU_ZERO(&cpuset);
 
@@ -1551,8 +1564,8 @@ static void* ru_thread_tx( void* param ) {
     if (oai_exit) break;   
 
 
-	LOG_D(PHY,"ru_thread_tx: Waiting for TX processing\n");
-	// wait until eNBs are finished subframe RX n and TX n+4
+    LOG_D(PHY,"ru_thread_tx: Waiting for TX processing\n");
+    // wait until eNBs are finished subframe RX n and TX n+4
     wait_on_condition(&proc->mutex_eNBs,&proc->cond_eNBs,&proc->instance_cnt_eNBs,"ru_thread_tx");
     if (oai_exit) break;
   	       
@@ -1561,22 +1574,44 @@ static void* ru_thread_tx( void* param ) {
   	  
     // do OFDM if needed
     if ((ru->fh_north_asynch_in == NULL) && (ru->feptx_ofdm)) ru->feptx_ofdm(ru);
-    if(!emulate_rf){    
+    if(!(get_softmodem_params()->emulate_rf)){
       // do outgoing fronthaul (south) if needed
       if ((ru->fh_north_asynch_in == NULL) && (ru->fh_south_out)) ru->fh_south_out(ru);
   	      
       if (ru->fh_north_out) ru->fh_north_out(ru);
 	}
     release_thread(&proc->mutex_eNBs,&proc->instance_cnt_eNBs,"ru_thread_tx");
-    
-    pthread_mutex_lock( &proc->mutex_eNBs );
-    proc->ru_tx_ready++;
-    // the thread can now be woken up
-    if (pthread_cond_signal(&proc->cond_eNBs) != 0) {
-      LOG_E( PHY, "[eNB] ERROR pthread_cond_signal for eNB TXnp4 thread\n");
-      exit_fun( "ERROR pthread_cond_signal" );
+    for(int i = 0; i<ru->num_eNB; i++)
+    {
+      eNB       = ru->eNB_list[i];
+      eNB_proc  = &eNB->proc;
+      L1_proc   = (get_thread_parallel_conf() == PARALLEL_RU_L1_TRX_SPLIT)? &eNB_proc->L1_proc_tx : &eNB_proc->L1_proc;
+      pthread_mutex_lock(&eNB_proc->mutex_RU_tx);
+      for (int j=0;j<eNB->num_RU;j++) {
+        if (ru == eNB->RU_list[j]) {
+          if ((eNB_proc->RU_mask_tx&(1<<j)) > 0)
+            LOG_E(PHY,"eNB %d frame %d, subframe %d : previous information from RU tx %d (num_RU %d,mask %x) has not been served yet!\n",
+	      eNB->Mod_id,eNB_proc->frame_rx,eNB_proc->subframe_rx,ru->idx,eNB->num_RU,eNB_proc->RU_mask_tx);
+          eNB_proc->RU_mask_tx |= (1<<j);
+        }
+      }
+      if (eNB_proc->RU_mask_tx != (1<<eNB->num_RU)-1) {  // not all RUs have provided their information so return
+        pthread_mutex_unlock(&eNB_proc->mutex_RU_tx);
+      }
+      else { // all RUs TX are finished so send the ready signal to eNB processing
+        eNB_proc->RU_mask_tx = 0;
+        pthread_mutex_unlock(&eNB_proc->mutex_RU_tx);
+
+        pthread_mutex_lock( &L1_proc->mutex_RUs);
+        L1_proc->instance_cnt_RUs = 0;
+        // the thread can now be woken up
+        if (pthread_cond_signal(&L1_proc->cond_RUs) != 0) {
+          LOG_E( PHY, "[eNB] ERROR pthread_cond_signal for eNB TXnp4 thread\n");
+          exit_fun( "ERROR pthread_cond_signal" );
+        }
+        pthread_mutex_unlock( &L1_proc->mutex_RUs );
+      }
     }
-    pthread_mutex_unlock( &proc->mutex_eNBs );
   }
   release_thread(&proc->mutex_FH1,&proc->instance_cnt_FH1,"ru_thread_tx");
   return 0;
@@ -1613,7 +1648,7 @@ static void* ru_thread( void* param ) {
 
   LOG_I(PHY,"Starting RU %d (%s,%s),\n",ru->idx,eNB_functions[ru->function],eNB_timing[ru->if_timing]);
 
-  if(emulate_rf){
+  if(get_softmodem_params()->emulate_rf){
     fill_rf_config(ru,ru->rf_config_file);
     init_frame_parms(&ru->frame_parms,1);
     phy_init_RU(ru);
@@ -1659,7 +1694,7 @@ static void* ru_thread( void* param ) {
 
   wait_sync("ru_thread");
 
-  if(!emulate_rf){
+  if(!(get_softmodem_params()->emulate_rf)){
     // Start RF device if any
     if (ru->start_rf) {
       if (ru->start_rf(ru) != 0)
@@ -1739,7 +1774,7 @@ static void* ru_thread( void* param ) {
     if ((ru->do_prach>0) && (is_prach_subframe(fp, proc->frame_rx, proc->subframe_rx)==1)) {
       wakeup_prach_ru(ru);
     }
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
     else if ((ru->do_prach>0) && (is_prach_subframe(fp, proc->frame_rx, proc->subframe_rx)>1)) {
       wakeup_prach_ru_br(ru);
     }
@@ -1785,7 +1820,7 @@ static void* ru_thread( void* param ) {
 #endif
 
     // wakeup all eNB processes waiting for this RU
-    if (ru->num_eNB>0) wakeup_eNBs(ru);
+    if (ru->num_eNB>0) wakeup_L1s(ru);
     
 #ifndef PHY_TX_THREAD
     if(get_thread_parallel_conf() == PARALLEL_SINGLE_THREAD || ru->num_eNB==0){
@@ -1794,7 +1829,7 @@ static void* ru_thread( void* param ) {
       
       // do OFDM if needed
       if ((ru->fh_north_asynch_in == NULL) && (ru->feptx_ofdm)) ru->feptx_ofdm(ru);
-      if(!emulate_rf){
+      if(!(get_softmodem_params()->emulate_rf)){
         // do outgoing fronthaul (south) if needed
         if ((ru->fh_north_asynch_in == NULL) && (ru->fh_south_out)) ru->fh_south_out(ru);
         
@@ -1817,7 +1852,7 @@ static void* ru_thread( void* param ) {
 
   printf( "Exiting ru_thread \n");
 
-  if (!emulate_rf){
+  if (!(get_softmodem_params()->emulate_rf)){
     if (ru->stop_rf != NULL) {
       if (ru->stop_rf(ru) != 0)
         LOG_E(HW,"Could not stop the RF device\n");
@@ -1917,7 +1952,12 @@ void* pre_scd_thread( void* param ){
     int                     CC_id;
     int                     Mod_id;
     RU_t               *ru      = (RU_t*)param;
-    Mod_id = ru->eNB_list[0]->Mod_id;
+
+    // L2-emulator can work only one eNB
+    if( nfapi_mode == 2)
+       Mod_id = 0;
+    else
+       Mod_id = ru->eNB_list[0]->Mod_id;
 
     frame = 0;
     subframe = 4;
@@ -1963,7 +2003,7 @@ void* pre_scd_thread( void* param ){
 #ifdef PHY_TX_THREAD
 /*!
  * \brief The phy tx thread of eNB.
- * \param param is a \ref eNB_proc_t structure which contains the info what to process.
+ * \param param is a \ref L1_proc_t structure which contains the info what to process.
  * \returns a pointer to an int. The storage is not on the heap and must not be freed.
  */
 static void* eNB_thread_phy_tx( void* param ) {
@@ -1974,7 +2014,7 @@ static void* eNB_thread_phy_tx( void* param ) {
   RU_proc_t *proc = &ru->proc;
   PHY_VARS_eNB **eNB_list = ru->eNB_list;
 
-  eNB_rxtx_proc_t proc_rxtx;
+  L1_rxtx_proc_t L1_proc;
 
   // set default return value
   eNB_thread_phy_tx_status = 0;
@@ -1991,9 +2031,9 @@ static void* eNB_thread_phy_tx( void* param ) {
 
     LOG_D(PHY,"Running eNB phy tx procedures\n");
     if(ru->num_eNB == 1){
-       proc_rxtx.subframe_tx = proc->subframe_phy_tx;
-       proc_rxtx.frame_tx = proc->frame_phy_tx;
-       phy_procedures_eNB_TX(eNB_list[0], &proc_rxtx, 1);
+       L1_proc.subframe_tx = proc->subframe_phy_tx;
+       L1_proc.frame_tx = proc->frame_phy_tx;
+       phy_procedures_eNB_TX(eNB_list[0], &L1_proc, 1);
        phy_tx_txdataF_end = 1;
        if(pthread_mutex_lock(&ru->proc.mutex_rf_tx) != 0){
           LOG_E( PHY, "[RU] ERROR pthread_mutex_lock for rf tx thread (IC %d)\n", ru->proc.instance_cnt_rf_tx);
@@ -2101,7 +2141,7 @@ void init_RU_proc(RU_t *ru) {
   RU_proc_t *proc;
   pthread_attr_t *attr_FH=NULL,*attr_FH1=NULL,*attr_prach=NULL,*attr_asynch=NULL,*attr_synch=NULL,*attr_emulateRF=NULL;
   //pthread_attr_t *attr_fep=NULL;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   pthread_attr_t *attr_prach_br=NULL;
 #endif
   char name[100];
@@ -2125,8 +2165,6 @@ void init_RU_proc(RU_t *ru) {
   proc->frame_offset             = 0;
   proc->num_slaves               = 0;
   proc->frame_tx_unwrap          = 0;
-  proc->ru_rx_ready              = 0;
-  proc->ru_tx_ready              = 0;
 
   for (i=0;i<10;i++) proc->symbol_mask[i]=0;
   
@@ -2154,7 +2192,7 @@ void init_RU_proc(RU_t *ru) {
   pthread_attr_init( &proc->attr_asynch_rxtx);
   pthread_attr_init( &proc->attr_fep);
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   proc->instance_cnt_prach_br       = -1;
   pthread_mutex_init( &proc->mutex_prach_br, NULL);
   pthread_cond_init( &proc->cond_prach_br, NULL);
@@ -2177,7 +2215,7 @@ void init_RU_proc(RU_t *ru) {
   attr_synch     = &proc->attr_synch;
   attr_asynch    = &proc->attr_asynch_rxtx;
   attr_emulateRF = &proc->attr_emulateRF;
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   attr_prach_br  = &proc->attr_prach_br;
 #endif
 #endif
@@ -2198,7 +2236,7 @@ void init_RU_proc(RU_t *ru) {
     pthread_create( &proc->pthread_rf_tx, NULL, rf_tx, (void*)ru );
 #endif
 
-  if(emulate_rf)
+  if(get_softmodem_params()->emulate_rf)
     pthread_create( &proc->pthread_emulateRF, attr_emulateRF, emulatedRF_thread, (void*)proc );
 
   if (get_thread_parallel_conf() == PARALLEL_RU_L1_SPLIT || get_thread_parallel_conf() == PARALLEL_RU_L1_TRX_SPLIT)
@@ -2206,7 +2244,7 @@ void init_RU_proc(RU_t *ru) {
 
   if (ru->function == NGFI_RRU_IF4p5) {
     pthread_create( &proc->pthread_prach, attr_prach, ru_thread_prach, (void*)ru );
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))  
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
     pthread_create( &proc->pthread_prach_br, attr_prach_br, ru_thread_prach_br, (void*)ru );
 #endif
     if (ru->is_slave == 1) pthread_create( &proc->pthread_synch, attr_synch, ru_thread_synch, (void*)ru);
@@ -2288,7 +2326,7 @@ void kill_RU_proc(RU_t *ru)
   pthread_cond_signal(&proc->cond_prach);
   pthread_mutex_unlock(&proc->mutex_prach);
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   pthread_mutex_lock(&proc->mutex_prach_br);
   proc->instance_cnt_prach_br = 0;
   pthread_cond_signal(&proc->cond_prach_br);
@@ -2301,7 +2339,6 @@ void kill_RU_proc(RU_t *ru)
   pthread_mutex_unlock(&proc->mutex_synch);
 
   pthread_mutex_lock(&proc->mutex_eNBs);
-  proc->ru_tx_ready = 0;
   proc->instance_cnt_eNBs = 1;
   // cond_eNBs is used by both ru_thread and ru_thread_tx, so we need to send
   // a broadcast to wake up both threads
@@ -2322,7 +2359,7 @@ void kill_RU_proc(RU_t *ru)
   if (ru->function == NGFI_RRU_IF4p5) {
     LOG_D(PHY, "Joining pthread_prach\n");
     pthread_join(proc->pthread_prach, NULL);
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
     LOG_D(PHY, "Joining pthread_prach_br\n");
     pthread_join(proc->pthread_prach_br, NULL);
 #endif
@@ -2364,7 +2401,7 @@ void kill_RU_proc(RU_t *ru)
   pthread_attr_destroy(&proc->attr_asynch_rxtx);
   pthread_attr_destroy(&proc->attr_fep);
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   pthread_mutex_destroy(&proc->mutex_prach_br);
   pthread_cond_destroy(&proc->cond_prach_br);
   pthread_attr_destroy(&proc->attr_prach_br);
@@ -2432,8 +2469,8 @@ void configure_ru(int idx,
 
 
   if (capabilities->FH_fmt < MAX_FH_FMTs) LOG_I(PHY, "RU FH options %s\n",rru_format_options[capabilities->FH_fmt]);
-
-  AssertFatal((ret=check_capabilities(ru,capabilities)) == 0,
+  ret=check_capabilities(ru,capabilities);
+  AssertFatal((ret == 0),
 	      "Cannot configure RRU %d, check_capabilities returned %d\n", idx,ret);
   // take antenna capabilities of RRU
   ru->nb_tx                      = capabilities->nb_tx[0];
@@ -2460,7 +2497,7 @@ void configure_ru(int idx,
     LOG_I(PHY,"REMOTE_IF4p5: prach_FrequOffset %d, prach_ConfigIndex %d\n",
 	  config->prach_FreqOffset[0],config->prach_ConfigIndex[0]);
     
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
     int i;
     for (i=0;i<4;i++) {
       config->emtc_prach_CElevel_enable[0][i]  = ru->frame_parms.prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[i];
@@ -2504,7 +2541,7 @@ void configure_rru(int idx,
 	  config->prach_FreqOffset[0],config->prach_ConfigIndex[0],ru->att_tx,ru->att_rx);
     ru->frame_parms.prach_config_common.prach_ConfigInfo.prach_FreqOffset  = config->prach_FreqOffset[0]; 
     ru->frame_parms.prach_config_common.prach_ConfigInfo.prach_ConfigIndex = config->prach_ConfigIndex[0]; 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
     for (int i=0;i<4;i++) {
       ru->frame_parms.prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[i] = config->emtc_prach_CElevel_enable[0][i];
       ru->frame_parms.prach_emtc_config_common.prach_ConfigInfo.prach_FreqOffset[i]     = config->emtc_prach_FreqOffset[0][i];
@@ -2736,6 +2773,7 @@ void init_RU(char *rf_config_file) {
     // use eNB_list[0] as a reference for RU frame parameters
     // NOTE: multiple CC_id are not handled here yet!
 
+
     if (ru->num_eNB > 0) {
       LOG_D(PHY, "%s() RC.ru[%d].num_eNB:%d ru->eNB_list[0]:%p RC.eNB[0][0]:%p rf_config_file:%s\n", __FUNCTION__, ru_id, ru->num_eNB, ru->eNB_list[0], RC.eNB[0][0], ru->rf_config_file);
 
@@ -2747,6 +2785,7 @@ void init_RU(char *rf_config_file) {
       //
       // DJP - feptx_prec() / feptx_ofdm() parses the eNB_list (based on num_eNB) and copies the txdata_F to txdata in RU
       //
+
       }
       else
       {
@@ -2798,6 +2837,114 @@ void stop_RU(int nb_ru)
   }
 }
 
+//Some of the member of ru pointer is used in pre_scd.
+//This funtion is for initializing ru pointer for L2 FAPI simulator.
+#if defined(PRE_SCD_THREAD)
+void init_ru_vnf(void) {
+
+  int ru_id;
+  RU_t *ru;
+  RU_proc_t *proc;
+//  PHY_VARS_eNB *eNB0= (PHY_VARS_eNB *)NULL;
+  int i;
+  int CC_id;
+
+
+  dlsch_ue_select_tbl_in_use = 1;
+
+
+  // create status mask
+  RC.ru_mask = 0;
+  pthread_mutex_init(&RC.ru_mutex,NULL);
+  pthread_cond_init(&RC.ru_cond,NULL);
+
+  // read in configuration file)
+  printf("configuring RU from file\n");
+  RCconfig_RU();
+  LOG_I(PHY,"number of L1 instances %d, number of RU %d, number of CPU cores %d\n",RC.nb_L1_inst,RC.nb_RU,get_nprocs());
+
+  if (RC.nb_CC != 0)
+    for (i=0;i<RC.nb_L1_inst;i++)
+      for (CC_id=0;CC_id<RC.nb_CC[i];CC_id++) RC.eNB[i][CC_id]->num_RU=0;
+
+  LOG_D(PHY,"Process RUs RC.nb_RU:%d\n",RC.nb_RU);
+  for (ru_id=0;ru_id<RC.nb_RU;ru_id++) {
+    LOG_D(PHY,"Process RC.ru[%d]\n",ru_id);
+    ru               = RC.ru[ru_id];
+//    ru->rf_config_file = rf_config_file;
+    ru->idx          = ru_id;
+    ru->ts_offset    = 0;
+    // use eNB_list[0] as a reference for RU frame parameters
+    // NOTE: multiple CC_id are not handled here yet!
+
+    if (ru->num_eNB > 0) {
+//      LOG_D(PHY, "%s() RC.ru[%d].num_eNB:%d ru->eNB_list[0]:%p RC.eNB[0][0]:%p rf_config_file:%s\n", __FUNCTION__, ru_id, ru->num_eNB, ru->eNB_list[0], RC.eNB[0][0], ru->rf_config_file);
+
+      if (ru->eNB_list[0] == 0)
+      {
+        LOG_E(PHY,"%s() DJP - ru->eNB_list ru->num_eNB are not initialized - so do it manually\n", __FUNCTION__);
+        ru->eNB_list[0] = RC.eNB[0][0];
+        ru->num_eNB=1;
+      //
+      // DJP - feptx_prec() / feptx_ofdm() parses the eNB_list (based on num_eNB) and copies the txdata_F to txdata in RU
+      //
+      }
+      else
+      {
+        LOG_E(PHY,"DJP - delete code above this %s:%d\n", __FILE__, __LINE__);
+      }
+    }
+
+// frame_parms is not used in L2 FAPI simulator
+/*
+    eNB0             = ru->eNB_list[0];
+    LOG_D(PHY, "RU FUnction:%d ru->if_south:%d\n", ru->function, ru->if_south);
+    LOG_D(PHY, "eNB0:%p\n", eNB0);
+    if (eNB0)
+    {
+      if ((ru->function != NGFI_RRU_IF5) && (ru->function != NGFI_RRU_IF4p5))
+        AssertFatal(eNB0!=NULL,"eNB0 is null!\n");
+
+      if (eNB0) {
+        LOG_I(PHY,"Copying frame parms from eNB %d to ru %d\n",eNB0->Mod_id,ru->idx);
+        memcpy((void*)&ru->frame_parms,(void*)&eNB0->frame_parms,sizeof(LTE_DL_FRAME_PARMS));
+
+        // attach all RU to all eNBs in its list/
+        LOG_D(PHY,"ru->num_eNB:%d eNB0->num_RU:%d\n", ru->num_eNB, eNB0->num_RU);
+        for (i=0;i<ru->num_eNB;i++) {
+          eNB0 = ru->eNB_list[i];
+          eNB0->RU_list[eNB0->num_RU++] = ru;
+        }
+      }
+    }
+*/
+    LOG_I(PHY,"Initializing RRU descriptor %d : (%s,%s,%d)\n",ru_id,ru_if_types[ru->if_south],eNB_timing[ru->if_timing],ru->function);
+
+//    set_function_spec_param(ru);
+    LOG_I(PHY,"Starting ru_thread %d\n",ru_id);
+
+//    init_RU_proc(ru);
+
+    proc = &ru->proc;
+    memset((void*)proc,0,sizeof(RU_proc_t));
+
+    proc->instance_pre_scd = -1;
+    pthread_mutex_init( &proc->mutex_pre_scd, NULL);
+    pthread_cond_init( &proc->cond_pre_scd, NULL);
+    pthread_create(&proc->pthread_pre_scd, NULL, pre_scd_thread, (void*)ru);
+    pthread_setname_np(proc->pthread_pre_scd, "pre_scd_thread");
+
+  } // for ru_id
+
+
+
+  //  sleep(1);
+  LOG_D(HW,"[lte-softmodem.c] RU threads created\n");
+
+
+}
+#endif
+
 
 /* --------------------------------------------------------*/
 /* from here function to use configuration module          */
diff --git a/targets/RT/USER/lte-softmodem-common.c b/targets/RT/USER/lte-softmodem-common.c
new file mode 100644
index 0000000000000000000000000000000000000000..814800ccfcb6bb1572197d856fba2cd79cc841d6
--- /dev/null
+++ b/targets/RT/USER/lte-softmodem-common.c
@@ -0,0 +1,96 @@
+/*
+ * 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
+ */
+
+/*! \file lte-softmodem-common.c
+ * \brief Top-level threads for eNodeB
+ * \author Nokia BellLabs France, francois Taburet
+ * \date 2012
+ * \version 0.1
+ * \company Eurecom
+ * \email: francois.taburet@nokia-bell-labs.com
+ * \note
+ * \warning
+ */
+
+#include "lte-softmodem.h"
+#include "UTIL/OPT/opt.h"
+#include "common/config/config_userapi.h"
+#include "common/utils/load_module_shlib.h"
+static softmodem_params_t softmodem_params;
+char *parallel_config=NULL;
+char *worker_config=NULL;
+
+uint64_t get_softmodem_optmask(void) {
+  return softmodem_params.optmask;
+}
+
+uint64_t set_softmodem_optmask(uint64_t bitmask) {
+  softmodem_params.optmask = softmodem_params.optmask | bitmask;
+  return softmodem_params.optmask;
+}
+
+softmodem_params_t *get_softmodem_params(void) {
+  return &softmodem_params;
+}
+
+void get_common_options(void) {
+  uint32_t online_log_messages;
+  uint32_t glog_level ;
+  uint32_t start_telnetsrv;
+  uint32_t noS1;
+  uint32_t nokrnmod;
+  uint32_t nonbiot;
+  paramdef_t cmdline_params[] =CMDLINE_PARAMS_DESC ;
+  paramdef_t cmdline_logparams[] =CMDLINE_LOGPARAMS_DESC ;
+  checkedparam_t cmdline_log_CheckParams[] = CMDLINE_LOGPARAMS_CHECK_DESC;
+  config_get( cmdline_params,sizeof(cmdline_params)/sizeof(paramdef_t),NULL);
+  config_set_checkfunctions(cmdline_logparams, cmdline_log_CheckParams,
+                            sizeof(cmdline_logparams)/sizeof(paramdef_t));
+  config_get( cmdline_logparams,sizeof(cmdline_logparams)/sizeof(paramdef_t),NULL);
+
+  if(config_isparamset(cmdline_logparams,CMDLINE_ONLINELOG_IDX)) {
+    set_glog_onlinelog(online_log_messages);
+  }
+
+  if(config_isparamset(cmdline_logparams,CMDLINE_GLOGLEVEL_IDX)) {
+    set_glog(glog_level);
+  }
+
+  if (start_telnetsrv) {
+    load_module_shlib("telnetsrv",NULL,0,NULL);
+  }
+
+  if (noS1) {
+    set_softmodem_optmask(SOFTMODEM_NOS1_BIT);
+  }
+
+  if (nokrnmod) {
+    set_softmodem_optmask(SOFTMODEM_NOKRNMOD_BIT);
+  }
+
+  if (nonbiot) {
+    set_softmodem_optmask(SOFTMODEM_NONBIOT_BIT);
+  }
+
+  if(parallel_config != NULL) set_parallel_conf(parallel_config);
+
+  if(worker_config != NULL)   set_worker_conf(worker_config);
+}
diff --git a/targets/RT/USER/lte-softmodem.c b/targets/RT/USER/lte-softmodem.c
index d8a799584ab2af761b6c3ae5cee9d088d4078c44..72a9d8a79eb3fe254dc5c65aa0a265601a7c7307 100644
--- a/targets/RT/USER/lte-softmodem.c
+++ b/targets/RT/USER/lte-softmodem.c
@@ -19,7 +19,7 @@
  *      contact@openairinterface.org
  */
 
-/*! \file lte-enb.c
+/*! \file lte-softmodem.c
  * \brief Top-level threads for eNodeB
  * \author R. Knopp, F. Kaltenberger, Navid Nikaein
  * \date 2012
@@ -79,11 +79,11 @@ unsigned short config_frames[4] = {2,9,11,13};
 //#include "PHY/TOOLS/time_meas.h"
 
 #ifndef OPENAIR2
-#include "UTIL/OTG/otg_vars.h"
+  #include "UTIL/OTG/otg_vars.h"
 #endif
 
 #if defined(ENABLE_ITTI)
-#include "create_tasks.h"
+  #include "create_tasks.h"
 #endif
 
 #include "PHY/INIT/phy_init.h"
@@ -91,24 +91,24 @@ unsigned short config_frames[4] = {2,9,11,13};
 #include "system.h"
 
 #ifdef XFORMS
-#include "PHY/TOOLS/lte_phy_scope.h"
-#include "stats.h"
+  #include "PHY/TOOLS/lte_phy_scope.h"
+  #include "stats.h"
 #endif
 #include "lte-softmodem.h"
 #include "NB_IoT_interface.h"
 #ifdef XFORMS
-// current status is that every UE has a DL scope for a SINGLE eNB (eNB_id=0)
-// at eNB 0, an UL scope for every UE
-FD_lte_phy_scope_ue  *form_ue[NUMBER_OF_UE_MAX];
-FD_lte_phy_scope_enb *form_enb[MAX_NUM_CCs][NUMBER_OF_UE_MAX];
-FD_stats_form                  *form_stats=NULL,*form_stats_l2=NULL;
-char title[255];
-unsigned char                   scope_enb_num_ue = 2;
-static pthread_t                forms_thread; //xforms
+  // current status is that every UE has a DL scope for a SINGLE eNB (eNB_id=0)
+  // at eNB 0, an UL scope for every UE
+  FD_lte_phy_scope_ue  *form_ue[NUMBER_OF_UE_MAX];
+  FD_lte_phy_scope_enb *form_enb[MAX_NUM_CCs][NUMBER_OF_UE_MAX];
+  FD_stats_form                  *form_stats=NULL,*form_stats_l2=NULL;
+  char title[255];
+  unsigned char                   scope_enb_num_ue = 2;
+  static pthread_t                forms_thread; //xforms
 #endif //XFORMS
 
 #ifndef ENABLE_USE_MME
-#define EPC_MODE_ENABLED 0
+  #define EPC_MODE_ENABLED 0
 #endif
 
 pthread_cond_t nfapi_sync_cond;
@@ -127,32 +127,16 @@ int config_sync_var=-1;
 uint16_t runtime_phy_rx[29][6]; // SISO [MCS 0-28][RBs 0-5 : 6, 15, 25, 50, 75, 100]
 uint16_t runtime_phy_tx[29][6]; // SISO [MCS 0-28][RBs 0-5 : 6, 15, 25, 50, 75, 100]
 
-#if defined(ENABLE_ITTI)
-volatile int             start_eNB = 0;
-volatile int             start_UE = 0;
-#endif
-volatile int             oai_exit = 0;
-
-clock_source_t clock_source = internal;
-static int wait_for_sync = 0;
 
-unsigned int                    mmapped_dma=0;
-int                             single_thread_flag = 0;
-
-static int8_t                     threequarter_fs=0;
+volatile int             oai_exit = 0;
 
 uint32_t                 downlink_frequency[MAX_NUM_CCs][4];
 int32_t                  uplink_frequency_offset[MAX_NUM_CCs][4];
 
-
-// This is a dummy declaration (dlsch_demodulation.c is no longer compiled for eNodeB)
-int16_t dlsch_demod_shift = 0;
-
 int UE_scan = 1;
 int UE_scan_carrier = 0;
 runmode_t mode = normal_txrx;
 int simL1flag;
-int snr_dB;
 FILE *input_fd=NULL;
 
 
@@ -171,11 +155,6 @@ double rx_gain_off = 0.0;
 double sample_rate=30.72e6;
 double bw = 10.0e6;
 
-char   rf_config_file[1024];
-
-int chain_offset=0;
-int phy_test = 0;
-uint8_t usim_test = 0;
 
 uint8_t dci_Format = 0;
 uint8_t agregation_Level =0xFF;
@@ -189,17 +168,13 @@ char channels[128] = "0";
 int                      rx_input_level_dBm;
 
 #ifdef XFORMS
-extern int                      otg_enabled;
-static char                     do_forms=0;
+  extern int                      otg_enabled;
 #else
-int                             otg_enabled;
+  int                             otg_enabled;
 #endif
 //int                             number_of_cards =   1;
 
 
-uint32_t target_dl_mcs = 28; //maximum allowed mcs
-uint32_t target_ul_mcs = 20;
-uint32_t timing_advance = 0;
 uint8_t exit_missed_slots=1;
 uint64_t num_missed_slots=0; // counter for the number of missed slots
 
@@ -207,58 +182,20 @@ uint64_t num_missed_slots=0; // counter for the number of missed slots
 extern void reset_opp_meas(void);
 extern void print_opp_meas(void);
 
-extern PHY_VARS_UE* init_ue_vars(LTE_DL_FRAME_PARMS *frame_parms,
-			  uint8_t UE_id,
-			  uint8_t abstraction_flag);
 
 extern void init_eNB_afterRU(void);
 
 int transmission_mode=1;
 int emulate_rf = 0;
 int numerology = 0;
-char *parallel_config = NULL;
-char *worker_config = NULL;
-
-static THREAD_STRUCT thread_struct;
-void set_parallel_conf(char *parallel_conf)
-{
-  if(strcmp(parallel_conf,"PARALLEL_SINGLE_THREAD")==0)           thread_struct.parallel_conf = PARALLEL_SINGLE_THREAD;
-  else if(strcmp(parallel_conf,"PARALLEL_RU_L1_SPLIT")==0)        thread_struct.parallel_conf = PARALLEL_RU_L1_SPLIT;
-  else if(strcmp(parallel_conf,"PARALLEL_RU_L1_TRX_SPLIT")==0)    thread_struct.parallel_conf = PARALLEL_RU_L1_TRX_SPLIT;
-  printf("[CONFIG] parallel conf is set to %d\n",thread_struct.parallel_conf);
-}
-void set_worker_conf(char *worker_conf)
-{
-  if(strcmp(worker_conf,"WORKER_DISABLE")==0)                     thread_struct.worker_conf = WORKER_DISABLE;
-  else if(strcmp(worker_conf,"WORKER_ENABLE")==0)                 thread_struct.worker_conf = WORKER_ENABLE;
-  printf("[CONFIG] worker conf is set to %d\n",thread_struct.worker_conf);
-}
-PARALLEL_CONF_t get_thread_parallel_conf(void)
-{
-  return thread_struct.parallel_conf;
-}
-WORKER_CONF_t get_thread_worker_conf(void)
-{
-  return thread_struct.worker_conf;
-}
-
-
 
+THREAD_STRUCT thread_struct;
 /* struct for ethernet specific parameters given in eNB conf file */
 eth_params_t *eth_params;
 
 double cpuf;
 
-extern char uecap_xer[1024];
-char uecap_xer_in=0;
 
-int oaisim_flag=0;
-threads_t threads= {-1,-1,-1,-1,-1,-1,-1};
-
-/* see file openair2/LAYER2/MAC/main.c for why abstraction_flag is needed
- * this is very hackish - find a proper solution
- */
-uint8_t abstraction_flag=0;
 
 /* forward declarations */
 void set_default_frame_parms(LTE_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]);
@@ -270,6 +207,7 @@ struct timespec max_diff_time = { .tv_sec = 0, .tv_nsec = 0 };
 
 struct timespec clock_difftime(struct timespec start, struct timespec end) {
   struct timespec temp;
+
   if ((end.tv_nsec-start.tv_nsec)<0) {
     temp.tv_sec = end.tv_sec-start.tv_sec-1;
     temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec;
@@ -277,6 +215,7 @@ struct timespec clock_difftime(struct timespec start, struct timespec end) {
     temp.tv_sec = end.tv_sec-start.tv_sec;
     temp.tv_nsec = end.tv_nsec-start.tv_nsec;
   }
+
   return temp;
 }
 
@@ -292,16 +231,21 @@ void update_difftimes(struct timespec start, struct timespec end) {
   struct timespec diff_time = { .tv_sec = 0, .tv_nsec = 0 };
   int             changed = 0;
   diff_time = clock_difftime(start, end);
+
   if ((min_diff_time.tv_nsec == 0) || (diff_time.tv_nsec < min_diff_time.tv_nsec)) {
     min_diff_time.tv_nsec = diff_time.tv_nsec;
     changed = 1;
   }
+
   if ((max_diff_time.tv_nsec == 0) || (diff_time.tv_nsec > max_diff_time.tv_nsec)) {
     max_diff_time.tv_nsec = diff_time.tv_nsec;
     changed = 1;
   }
+
 #if 1
+
   if (changed) print_difftimes();
+
 #endif
 }
 
@@ -314,7 +258,7 @@ unsigned int build_rfdc(int dcoff_i_rxfe, int dcoff_q_rxfe) {
   return (dcoff_i_rxfe + (dcoff_q_rxfe<<8));
 }
 
-#if !defined(ENABLE_ITTI)
+
 void signal_handler(int sig) {
   void *array[10];
   size_t size;
@@ -322,36 +266,18 @@ void signal_handler(int sig) {
   if (sig==SIGSEGV) {
     // get void*'s for all entries on the stack
     size = backtrace(array, 10);
-
     // print out all the frames to stderr
     fprintf(stderr, "Error: signal %d:\n", sig);
     backtrace_symbols_fd(array, size, 2);
     exit(-1);
   } else {
-    printf("trying to exit gracefully...\n");
-    oai_exit = 1;
+    printf("Linux signal %s...\n",strsignal(sig));
+    exit_function(__FILE__, __FUNCTION__, __LINE__,"softmodem starting exit procedure\n");
   }
 }
-#endif
-#define KNRM  "\x1B[0m"
-#define KRED  "\x1B[31m"
-#define KGRN  "\x1B[32m"
-#define KBLU  "\x1B[34m"
-#define RESET "\033[0m"
-
-#if defined(ENABLE_ITTI)
-void signal_handler_itti(int sig) {
-  // Call exit function
-  char msg[256];
-  memset(msg, 0, 256);
-  sprintf(msg, "caught signal %s\n", strsignal(sig));
-  exit_function(__FILE__, __FUNCTION__, __LINE__, msg);
-}
-#endif
 
-void exit_function(const char* file, const char* function, const int line, const char* s)
-{
 
+void exit_function(const char *file, const char *function, const int line, const char *s) {
   int ru_id;
 
   if (s != NULL) {
@@ -360,50 +286,43 @@ void exit_function(const char* file, const char* function, const int line, const
 
   oai_exit = 1;
 
+  if (RC.ru == NULL)
+    exit(-1); // likely init not completed, prevent crash or hang, exit now...
 
-    if (RC.ru == NULL)
-        exit(-1); // likely init not completed, prevent crash or hang, exit now...
-    for (ru_id=0; ru_id<RC.nb_RU;ru_id++) {
-      if (RC.ru[ru_id] && RC.ru[ru_id]->rfdevice.trx_end_func) {
-	RC.ru[ru_id]->rfdevice.trx_end_func(&RC.ru[ru_id]->rfdevice);
-        RC.ru[ru_id]->rfdevice.trx_end_func = NULL;
-      }
-      if (RC.ru[ru_id] && RC.ru[ru_id]->ifdevice.trx_end_func) {
-	RC.ru[ru_id]->ifdevice.trx_end_func(&RC.ru[ru_id]->ifdevice);  
-        RC.ru[ru_id]->ifdevice.trx_end_func = NULL;
-      }
+  for (ru_id=0; ru_id<RC.nb_RU; ru_id++) {
+    if (RC.ru[ru_id] && RC.ru[ru_id]->rfdevice.trx_end_func) {
+      RC.ru[ru_id]->rfdevice.trx_end_func(&RC.ru[ru_id]->rfdevice);
+      RC.ru[ru_id]->rfdevice.trx_end_func = NULL;
     }
 
+    if (RC.ru[ru_id] && RC.ru[ru_id]->ifdevice.trx_end_func) {
+      RC.ru[ru_id]->ifdevice.trx_end_func(&RC.ru[ru_id]->ifdevice);
+      RC.ru[ru_id]->ifdevice.trx_end_func = NULL;
+    }
+  }
 
-    sleep(1); //allow lte-softmodem threads to exit first
-#if defined(ENABLE_ITTI)
-    itti_terminate_tasks (TASK_UNKNOWN);
-#endif
-   exit(1);
-
+  sleep(1); //allow lte-softmodem threads to exit first
+  exit(1);
 }
 
 #ifdef XFORMS
 
 
-void reset_stats(FL_OBJECT *button, long arg)
-{
+void reset_stats(FL_OBJECT *button, long arg) {
   int i,j,k;
   PHY_VARS_eNB *phy_vars_eNB = RC.eNB[0][0];
 
   for (i=0; i<NUMBER_OF_UE_MAX; i++) {
     for (k=0; k<8; k++) { //harq_processes
       for (j=0; j<phy_vars_eNB->dlsch[i][0]->Mlimit; j++) {
-	phy_vars_eNB->UE_stats[i].dlsch_NAK[k][j]=0;
-	phy_vars_eNB->UE_stats[i].dlsch_ACK[k][j]=0;
-	phy_vars_eNB->UE_stats[i].dlsch_trials[k][j]=0;
+        phy_vars_eNB->UE_stats[i].dlsch_NAK[k][j]=0;
+        phy_vars_eNB->UE_stats[i].dlsch_ACK[k][j]=0;
+        phy_vars_eNB->UE_stats[i].dlsch_trials[k][j]=0;
       }
 
       phy_vars_eNB->UE_stats[i].dlsch_l2_errors[k]=0;
       phy_vars_eNB->UE_stats[i].ulsch_errors[k]=0;
       phy_vars_eNB->UE_stats[i].ulsch_consecutive_errors=0;
-
-
       phy_vars_eNB->UE_stats[i].dlsch_sliding_cnt=0;
       phy_vars_eNB->UE_stats[i].dlsch_NAK_round0=0;
       phy_vars_eNB->UE_stats[i].dlsch_mcs_offset=0;
@@ -412,168 +331,72 @@ void reset_stats(FL_OBJECT *button, long arg)
 }
 
 static void *scope_thread(void *arg) {
- 
 # ifdef ENABLE_XFORMS_WRITE_STATS
   FILE *eNB_stats;
 # endif
   struct sched_param sched_param;
   int UE_id, CC_id;
   int ue_cnt=0;
-
   sched_param.sched_priority = sched_get_priority_min(SCHED_FIFO)+1;
   sched_setscheduler(0, SCHED_FIFO,&sched_param);
-
   printf("Scope thread has priority %d\n",sched_param.sched_priority);
-
 # ifdef ENABLE_XFORMS_WRITE_STATS
-
   eNB_stats = fopen("eNB_stats.txt", "w");
-
 #endif
 
   while (!oai_exit) {
+    ue_cnt=0;
+
+    for(UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++) {
+      for(CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
+        if ((ue_cnt<scope_enb_num_ue)) {
+          phy_scope_eNB(form_enb[CC_id][ue_cnt],
+                        RC.eNB[0][CC_id],
+                        UE_id);
+          ue_cnt++;
+        }
+      }
+    }
 
-      ue_cnt=0;
-      for(UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++) {
-	for(CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
-	  if ((ue_cnt<scope_enb_num_ue)) {
-	    phy_scope_eNB(form_enb[CC_id][ue_cnt],
-			  RC.eNB[0][CC_id],
-			  UE_id);
-	    ue_cnt++;
-	  }
-	}
-      }	
     sleep(1);
   }
 
   //  printf("%s",stats_buffer);
-
 # ifdef ENABLE_XFORMS_WRITE_STATS
 
-    if (eNB_stats) {
-      rewind (eNB_stats);
-      fwrite (stats_buffer, 1, len, eNB_stats);
-      fclose (eNB_stats);
-    }
+  if (eNB_stats) {
+    rewind (eNB_stats);
+    fwrite (stats_buffer, 1, len, eNB_stats);
+    fclose (eNB_stats);
+  }
 
 # endif
-
-  pthread_exit((void*)arg);
+  pthread_exit((void *)arg);
 }
 #endif
 
 
-
-
-#if defined(ENABLE_ITTI)
-void *l2l1_task(void *arg) {
-  MessageDef *message_p = NULL;
-  int         result;
-
-  itti_set_task_real_time(TASK_L2L1);
-  itti_mark_task_ready(TASK_L2L1);
-
-  /* Wait for the initialize message */
-  printf("Wait for the ITTI initialize message\n");
-  while (1) {
-    itti_receive_msg (TASK_L2L1, &message_p);
-
-    switch (ITTI_MSG_ID(message_p)) {
-    case INITIALIZE_MESSAGE:
-      /* Start eNB thread */
-      LOG_D(PHY, "L2L1 TASK received %s\n", ITTI_MSG_NAME(message_p));
-      start_eNB = 1;
-      break;
-
-    case TERMINATE_MESSAGE:
-      LOG_W(PHY, " *** Exiting L2L1 thread\n");
-      oai_exit=1;
-      start_eNB = 0;
-      itti_exit_task ();
-      break;
-
-    case ACTIVATE_MESSAGE:
-      start_UE = 1;
-      break;
-
-    case DEACTIVATE_MESSAGE:
-      start_UE = 0;
-      break;
-
-    case MESSAGE_TEST:
-      printf("Received %s\n", ITTI_MSG_NAME(message_p));
-      break;
-
-    default:
-      printf("Received unexpected message %s\n", ITTI_MSG_NAME(message_p));
-      break;
-    }
-
-    result = itti_free (ITTI_MSG_ORIGIN_ID(message_p), message_p);
-    AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
-    message_p = NULL;
-  };
-
-  return NULL;
-}
-#endif
-
-
-static void get_options(unsigned int *start_msc) {
- 
-  int tddflag, nonbiotflag;
- 
-  
-  uint32_t online_log_messages;
-  uint32_t glog_level ;
-  uint32_t start_telnetsrv;
-
-  paramdef_t cmdline_params[] =CMDLINE_PARAMS_DESC ;
-  paramdef_t cmdline_logparams[] =CMDLINE_LOGPARAMS_DESC ;
+static void get_options(void) {
   CONFIG_SETRTFLAG(CONFIG_NOEXITONHELP);
-  config_process_cmdline( cmdline_params,sizeof(cmdline_params)/sizeof(paramdef_t),NULL); 
-
-  if (strlen(in_path) > 0) {
-      opt_type = OPT_PCAP;
-      opt_enabled=1;
-      printf("Enabling OPT for PCAP  with the following file %s \n",in_path);
-  }
-  if (strlen(in_ip) > 0) {
-      opt_enabled=1;
-      opt_type = OPT_WIRESHARK;
-      printf("Enabling OPT for wireshark for local interface");
-  }
+  get_common_options();
   CONFIG_CLEARRTFLAG(CONFIG_NOEXITONHELP);
-  config_process_cmdline( cmdline_logparams,sizeof(cmdline_logparams)/sizeof(paramdef_t),NULL);
-
-  if(config_isparamset(cmdline_logparams,CMDLINE_ONLINELOG_IDX)) {
-      set_glog_onlinelog(online_log_messages);
-  }
-  if(config_isparamset(cmdline_logparams,CMDLINE_GLOGLEVEL_IDX)) {
-      set_glog(glog_level);
-  }
-  if (start_telnetsrv) {
-     load_module_shlib("telnetsrv",NULL,0,NULL);
-  }
 
   if ( !(CONFIG_ISFLAGSET(CONFIG_ABORT)) ) {
-      memset((void*)&RC,0,sizeof(RC));
-      /* Read RC configuration file */
-      RCConfig();
-      NB_eNB_INST = RC.nb_inst;
-      printf("Configuration: nb_rrc_inst %d, nb_L1_inst %d, nb_ru %d\n",NB_eNB_INST,RC.nb_L1_inst,RC.nb_RU);
-      if (nonbiotflag <= 0) {
-         load_NB_IoT();
-         printf("               nb_nbiot_rrc_inst %d, nb_nbiot_L1_inst %d, nb_nbiot_macrlc_inst %d\n",
-                RC.nb_nb_iot_rrc_inst, RC.nb_nb_iot_L1_inst, RC.nb_nb_iot_macrlc_inst);
-      } else {
-         printf("All Nb-IoT instances disabled\n");
-         RC.nb_nb_iot_rrc_inst=RC.nb_nb_iot_L1_inst=RC.nb_nb_iot_macrlc_inst=0;
-      }
-   }
-  if(parallel_config != NULL) set_parallel_conf(parallel_config);
-  if(worker_config != NULL)   set_worker_conf(worker_config);
+    memset((void *)&RC,0,sizeof(RC));
+    /* Read RC configuration file */
+    RCConfig();
+    NB_eNB_INST = RC.nb_inst;
+    printf("Configuration: nb_rrc_inst %d, nb_L1_inst %d, nb_ru %d\n",NB_eNB_INST,RC.nb_L1_inst,RC.nb_RU);
+
+    if (!IS_SOFTMODEM_NONBIOT) {
+      load_NB_IoT();
+      printf("               nb_nbiot_rrc_inst %d, nb_nbiot_L1_inst %d, nb_nbiot_macrlc_inst %d\n",
+             RC.nb_nb_iot_rrc_inst, RC.nb_nb_iot_L1_inst, RC.nb_nb_iot_macrlc_inst);
+    } else {
+      printf("All Nb-IoT instances disabled\n");
+      RC.nb_nb_iot_rrc_inst=RC.nb_nb_iot_L1_inst=RC.nb_nb_iot_macrlc_inst=0;
+    }
+  }
 }
 
 
@@ -581,11 +404,10 @@ static void get_options(unsigned int *start_msc) {
 
 
 void set_default_frame_parms(LTE_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]) {
-
   int CC_id;
 
   for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
-    frame_parms[CC_id] = (LTE_DL_FRAME_PARMS*) malloc(sizeof(LTE_DL_FRAME_PARMS));
+    frame_parms[CC_id] = (LTE_DL_FRAME_PARMS *) malloc(sizeof(LTE_DL_FRAME_PARMS));
     /* Set some default values that may be overwritten while reading options */
     frame_parms[CC_id]->frame_type          = FDD;
     frame_parms[CC_id]->tdd_config          = 3;
@@ -599,9 +421,7 @@ void set_default_frame_parms(LTE_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]) {
     frame_parms[CC_id]->nb_antenna_ports_eNB  = 1;
     frame_parms[CC_id]->nb_antennas_tx      = 1;
     frame_parms[CC_id]->nb_antennas_rx      = 1;
-
     frame_parms[CC_id]->nushift             = 0;
-
     frame_parms[CC_id]->phich_config_common.phich_resource = oneSixth;
     frame_parms[CC_id]->phich_config_common.phich_duration = normal;
     // UL RS Config
@@ -609,61 +429,56 @@ void set_default_frame_parms(LTE_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]) {
     frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.groupHoppingEnabled = 0;
     frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled = 0;
     frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH = 0;
-
     frame_parms[CC_id]->prach_config_common.rootSequenceIndex=22;
     frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig=1;
     frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.prach_ConfigIndex=0;
     frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.highSpeedFlag=0;
     frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.prach_FreqOffset=0;
-
-//    downlink_frequency[CC_id][0] = 2680000000; // Use float to avoid issue with frequency over 2^31.
-//    downlink_frequency[CC_id][1] = downlink_frequency[CC_id][0];
-//    downlink_frequency[CC_id][2] = downlink_frequency[CC_id][0];
-//    downlink_frequency[CC_id][3] = downlink_frequency[CC_id][0];
+    //    downlink_frequency[CC_id][0] = 2680000000; // Use float to avoid issue with frequency over 2^31.
+    //    downlink_frequency[CC_id][1] = downlink_frequency[CC_id][0];
+    //    downlink_frequency[CC_id][2] = downlink_frequency[CC_id][0];
+    //    downlink_frequency[CC_id][3] = downlink_frequency[CC_id][0];
     //printf("Downlink for CC_id %d frequency set to %u\n", CC_id, downlink_frequency[CC_id][0]);
     frame_parms[CC_id]->dl_CarrierFreq=downlink_frequency[CC_id][0];
-
   }
-
 }
 
 void wait_RUs(void) {
-
-  LOG_I(PHY,"Waiting for RUs to be configured ... RC.ru_mask:%02lx\n", RC.ru_mask);
-
+  /* do not modify the following LOG_UI message, which is used by CI */
+  LOG_UI(ENB_APP,"Waiting for RUs to be configured ... RC.ru_mask:%02lx\n", RC.ru_mask);
   // wait for all RUs to be configured over fronthaul
   pthread_mutex_lock(&RC.ru_mutex);
+
   while (RC.ru_mask>0) {
     pthread_cond_wait(&RC.ru_cond,&RC.ru_mutex);
     printf("RC.ru_mask:%02lx\n", RC.ru_mask);
   }
-  pthread_mutex_unlock(&RC.ru_mutex);
 
+  pthread_mutex_unlock(&RC.ru_mutex);
   LOG_I(PHY,"RUs configured\n");
 }
 
 void wait_eNBs(void) {
-
   int i,j;
   int waiting=1;
 
-
   while (waiting==1) {
     printf("Waiting for eNB L1 instances to all get configured ... sleeping 50ms (nb_L1_inst %d)\n",RC.nb_L1_inst);
     usleep(50*1000);
     waiting=0;
-    for (i=0;i<RC.nb_L1_inst;i++) {
 
+    for (i=0; i<RC.nb_L1_inst; i++) {
       printf("RC.nb_L1_CC[%d]:%d\n", i, RC.nb_L1_CC[i]);
 
-      for (j=0;j<RC.nb_L1_CC[i];j++) {
-	if (RC.eNB[i][j]->configured==0) {
-	  waiting=1;
-	  break;
-        } 
+      for (j=0; j<RC.nb_L1_CC[i]; j++) {
+        if (RC.eNB[i][j]->configured==0) {
+          waiting=1;
+          break;
+        }
       }
     }
   }
+
   printf("eNB L1 are configured\n");
 }
 
@@ -671,20 +486,18 @@ void wait_eNBs(void) {
 /*
  * helper function to terminate a certain ITTI task
  */
-void terminate_task(module_id_t mod_id, task_id_t from, task_id_t to)
-{
+void terminate_task(module_id_t mod_id, task_id_t from, task_id_t to) {
   LOG_I(ENB_APP, "sending TERMINATE_MESSAGE from task %s (%d) to task %s (%d)\n",
-      itti_get_task_name(from), from, itti_get_task_name(to), to);
+        itti_get_task_name(from), from, itti_get_task_name(to), to);
   MessageDef *msg;
   msg = itti_alloc_new_message (from, TERMINATE_MESSAGE);
   itti_send_msg_to_task (to, ENB_MODULE_ID_TO_INSTANCE(mod_id), msg);
 }
 
 extern void  free_transport(PHY_VARS_eNB *);
-extern void  phy_free_RU(RU_t*);
+extern void  phy_free_RU(RU_t *);
 
-int stop_L1L2(module_id_t enb_id)
-{
+int stop_L1L2(module_id_t enb_id) {
   LOG_W(ENB_APP, "stopping lte-softmodem\n");
 
   if (!RC.ru) {
@@ -694,17 +507,18 @@ int stop_L1L2(module_id_t enb_id)
 
   /* these tasks need to pick up new configuration */
   terminate_task(enb_id, TASK_ENB_APP, TASK_RRC_ENB);
-  terminate_task(enb_id, TASK_ENB_APP, TASK_L2L1);
   oai_exit = 1;
   LOG_I(ENB_APP, "calling kill_RU_proc() for instance %d\n", enb_id);
   kill_RU_proc(RC.ru[enb_id]);
   LOG_I(ENB_APP, "calling kill_eNB_proc() for instance %d\n", enb_id);
   kill_eNB_proc(enb_id);
   oai_exit = 0;
+
   for (int cc_id = 0; cc_id < RC.nb_CC[enb_id]; cc_id++) {
     free_transport(RC.eNB[enb_id][cc_id]);
     phy_free_lte_eNB(RC.eNB[enb_id][cc_id]);
   }
+
   phy_free_RU(RC.ru[enb_id]);
   free_lte_top();
   return 0;
@@ -713,14 +527,11 @@ int stop_L1L2(module_id_t enb_id)
 /*
  * Restart the lte-softmodem after it has been soft-stopped with stop_L1L2()
  */
-int restart_L1L2(module_id_t enb_id)
-{
+int restart_L1L2(module_id_t enb_id) {
   RU_t *ru = RC.ru[enb_id];
   int cc_id;
   MessageDef *msg_p = NULL;
-
   LOG_W(ENB_APP, "restarting lte-softmodem\n");
-
   /* block threads */
   pthread_mutex_lock(&sync_mutex);
   sync_var = -1;
@@ -738,20 +549,14 @@ int restart_L1L2(module_id_t enb_id)
   /* reset the list of connected UEs in the MAC, since in this process with
    * loose all UEs (have to reconnect) */
   init_UE_list(&RC.mac[enb_id]->UE_list);
-
   LOG_I(ENB_APP, "attempting to create ITTI tasks\n");
+
   if (itti_create_task (TASK_RRC_ENB, rrc_enb_task, NULL) < 0) {
     LOG_E(RRC, "Create task for RRC eNB failed\n");
     return -1;
   } else {
     LOG_I(RRC, "Re-created task for RRC eNB successfully\n");
   }
-  if (itti_create_task (TASK_L2L1, l2l1_task, NULL) < 0) {
-    LOG_E(PDCP, "Create task for L2L1 failed\n");
-    return -1;
-  } else {
-    LOG_I(PDCP, "Re-created task for L2L1 successfully\n");
-  }
 
   /* pass a reconfiguration request which will configure everything down to
    * RC.eNB[i][j]->frame_parms, too */
@@ -760,162 +565,133 @@ int restart_L1L2(module_id_t enb_id)
   itti_send_msg_to_task(TASK_RRC_ENB, ENB_MODULE_ID_TO_INSTANCE(enb_id), msg_p);
   /* TODO XForms might need to be restarted, but it is currently (09/02/18)
    * broken, so we cannot test it */
-
   wait_eNBs();
   init_RU_proc(ru);
   ru->rf_map.card = 0;
   ru->rf_map.chain = 0; /* CC_id + chain_offset;*/
   wait_RUs();
   init_eNB_afterRU();
-
   printf("Sending sync to all threads\n");
   pthread_mutex_lock(&sync_mutex);
   sync_var=0;
   pthread_cond_broadcast(&sync_cond);
   pthread_mutex_unlock(&sync_mutex);
-
   return 0;
 }
 #endif
 
 static  void wait_nfapi_init(char *thread_name) {
-
   printf( "waiting for NFAPI PNF connection and population of global structure (%s)\n",thread_name);
   pthread_mutex_lock( &nfapi_sync_mutex );
-  
+
   while (nfapi_sync_var<0)
     pthread_cond_wait( &nfapi_sync_cond, &nfapi_sync_mutex );
-  
+
   pthread_mutex_unlock(&nfapi_sync_mutex);
-  
   printf( "NFAPI: got sync (%s)\n", thread_name);
 }
 
-int main( int argc, char **argv )
-{
+int main( int argc, char **argv ) {
   int i;
 #if defined (XFORMS)
   void *status;
 #endif
-
   int CC_id;
   int ru_id;
 #if defined (XFORMS)
   int ret;
 #endif
-  unsigned int start_msc=0;
 
-  if ( load_configmodule(argc,argv) == NULL) {
+  if ( load_configmodule(argc,argv,0) == NULL) {
     exit_fun("[SOFTMODEM] Error, configuration module init failed\n");
-  } 
-      
+  }
 
   mode = normal_txrx;
-
   set_latency_target();
-
   logInit();
-
   printf("Reading in command-line options\n");
+  get_options ();
 
-  get_options (&start_msc);
   if (CONFIG_ISFLAGSET(CONFIG_ABORT) ) {
-      fprintf(stderr,"Getting configuration failed\n");
-      exit(-1);
+    fprintf(stderr,"Getting configuration failed\n");
+    exit(-1);
   }
 
-
 #if T_TRACER
   T_Config_Init();
 #endif
-
-
-
   //randominit (0);
   set_taus_seed (0);
-
   printf("configuring for RAU/RRU\n");
 
   if (opp_enabled ==1) {
     reset_opp_meas();
   }
-  cpuf=get_cpu_freq_GHz();
 
+  cpuf=get_cpu_freq_GHz();
 #if defined(ENABLE_ITTI)
-
   printf("ITTI init, useMME: %i\n" ,EPC_MODE_ENABLED);
-
   itti_init(TASK_MAX, THREAD_MAX, MESSAGES_ID_MAX, tasks_info, messages_info);
 
   // initialize mscgen log after ITTI
-  if (start_msc) {
-     load_module_shlib("msc",NULL,0,&msc_interface);
+  if (get_softmodem_params()->start_msc) {
+    load_module_shlib("msc",NULL,0,&msc_interface);
   }
+
   MSC_INIT(MSC_E_UTRAN, THREAD_MAX+TASK_MAX);
 #endif
-
-  if (opt_type != OPT_NONE) {
-    if (init_opt(in_path, in_ip) == -1)
-      LOG_E(OPT,"failed to run OPT \n");
-  }
-
-#if !defined(ENABLE_ITTI)
+  init_opt();
+#ifdef PDCP_USE_NETLINK
+  printf("PDCP netlink\n");
+  netlink_init();
+#if defined(PDCP_USE_NETLINK_QUEUES)
+  pdcp_netlink_init();
+#endif
+#endif
   // to make a graceful exit when ctrl-c is pressed
   signal(SIGSEGV, signal_handler);
   signal(SIGINT, signal_handler);
-#endif
-
-#if defined(ENABLE_ITTI)
-  signal(SIGINT, signal_handler_itti);
-  signal(SIGTERM, signal_handler_itti);
-  signal(SIGABRT, signal_handler_itti);
-#endif
-
+  signal(SIGTERM, signal_handler);
+  signal(SIGABRT, signal_handler);
   check_clock();
-
 #ifndef PACKAGE_VERSION
 #  define PACKAGE_VERSION "UNKNOWN-EXPERIMENTAL"
 #endif
-
   LOG_I(HW, "Version: %s\n", PACKAGE_VERSION);
-
-
-
-  
-  printf("Before CC \n");
-  
   printf("Runtime table\n");
   fill_modeled_runtime_table(runtime_phy_rx,runtime_phy_tx);
-  
-    
 #ifndef DEADLINE_SCHEDULER
-  
   printf("NO deadline scheduler\n");
   /* Currently we set affinity for UHD to CPU 0 for eNB/UE and only if number of CPUS >2 */
-  
   cpu_set_t cpuset;
   int s;
   char cpu_affinity[1024];
   CPU_ZERO(&cpuset);
 #ifdef CPU_AFFINITY
+
   if (get_nprocs() > 2) {
     CPU_SET(0, &cpuset);
     s = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
+
     if (s != 0) {
       perror( "pthread_setaffinity_np");
       exit_fun("Error setting processor affinity");
     }
+
     LOG_I(HW, "Setting the affinity of main function to CPU 0, for device library to use CPU 0 only!\n");
   }
+
 #endif
-  
   /* Check the actual affinity mask assigned to the thread */
   s = pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
+
   if (s != 0) {
     perror( "pthread_getaffinity_np");
     exit_fun("Error getting processor affinity ");
   }
+
   memset(cpu_affinity, 0 , sizeof(cpu_affinity));
+
   for (int j = 0; j < CPU_SETSIZE; j++) {
     if (CPU_ISSET(j, &cpuset)) {
       char temp[1024];
@@ -923,6 +699,7 @@ int main( int argc, char **argv )
       strcat(cpu_affinity, temp);
     }
   }
+
   LOG_I(HW, "CPU Affinity of main() function is... %s\n", cpu_affinity);
 #endif
 
@@ -947,23 +724,12 @@ int main( int argc, char **argv )
       MessageDef *msg_p = itti_alloc_new_message (TASK_ENB_APP, RRC_CONFIGURATION_REQ);
       itti_send_msg_to_task (TASK_RRC_ENB, ENB_MODULE_ID_TO_INSTANCE(enb_id), msg_p);
     }
-
-    if (RC.rrc[0]->node_type != ngran_eNB_DU) {
-#ifdef PDCP_USE_NETLINK
-      printf("PDCP netlink\n");
-      netlink_init();
-#if defined(PDCP_USE_NETLINK_QUEUES)
-      pdcp_netlink_init();
-#endif
-#endif
-    }
   }
   else {
     printf("No ITTI, Initializing L1\n");
     RCconfig_L1();
   }
 
-
   if (RC.rrc[0]->node_type == ngran_eNB_CU || RC.rrc[0]->node_type == ngran_ng_eNB_CU) {
     protocol_ctxt_t ctxt;
     ctxt.module_id = 0 ;
@@ -976,117 +742,122 @@ int main( int argc, char **argv )
   /* start threads if only L1 or not a CU */
   if (RC.nb_inst == 0 ||
       !(RC.rrc[0]->node_type == ngran_eNB_CU || RC.rrc[0]->node_type == ngran_ng_eNB_CU)) {
-      // init UE_PF_PO and mutex lock
+    // init UE_PF_PO and mutex lock
     pthread_mutex_init(&ue_pf_po_mutex, NULL);
     memset (&UE_PF_PO[0][0], 0, sizeof(UE_PF_PO_t)*MAX_MOBILES_PER_ENB*MAX_NUM_CCs);
-    
     mlockall(MCL_CURRENT | MCL_FUTURE);
-    
     pthread_cond_init(&sync_cond,NULL);
     pthread_mutex_init(&sync_mutex, NULL);
     
 #ifdef XFORMS
     int UE_id;
-    
     printf("XFORMS\n");
-    
-    if (do_forms==1) {
+
+    if (get_softmodem_params()->do_forms==1) {
       fl_initialize (&argc, argv, NULL, 0, 0);
-      
       form_stats_l2 = create_form_stats_form();
       fl_show_form (form_stats_l2->stats_form, FL_PLACE_HOTSPOT, FL_FULLBORDER, "l2 stats");
       form_stats = create_form_stats_form();
       fl_show_form (form_stats->stats_form, FL_PLACE_HOTSPOT, FL_FULLBORDER, "stats");
-      
+
       for(UE_id=0; UE_id<scope_enb_num_ue; UE_id++) {
-	for(CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
-	  form_enb[CC_id][UE_id] = create_lte_phy_scope_enb();
-	  sprintf (title, "LTE UL SCOPE eNB for CC_id %d, UE %d",CC_id,UE_id);
-	  fl_show_form (form_enb[CC_id][UE_id]->lte_phy_scope_enb, FL_PLACE_HOTSPOT, FL_FULLBORDER, title);
-	  
-	  if (otg_enabled) {
-	    fl_set_button(form_enb[CC_id][UE_id]->button_0,1);
-	    fl_set_object_label(form_enb[CC_id][UE_id]->button_0,"DL Traffic ON");
-	  } else {
-	    fl_set_button(form_enb[CC_id][UE_id]->button_0,0);
-	    fl_set_object_label(form_enb[CC_id][UE_id]->button_0,"DL Traffic OFF");
-	  }
-	} // CC_id
+        for(CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
+          form_enb[CC_id][UE_id] = create_lte_phy_scope_enb();
+          sprintf (title, "LTE UL SCOPE eNB for CC_id %d, UE %d",CC_id,UE_id);
+          fl_show_form (form_enb[CC_id][UE_id]->lte_phy_scope_enb, FL_PLACE_HOTSPOT, FL_FULLBORDER, title);
+
+          if (otg_enabled) {
+            fl_set_button(form_enb[CC_id][UE_id]->button_0,1);
+            fl_set_object_label(form_enb[CC_id][UE_id]->button_0,"DL Traffic ON");
+          } else {
+            fl_set_button(form_enb[CC_id][UE_id]->button_0,0);
+            fl_set_object_label(form_enb[CC_id][UE_id]->button_0,"DL Traffic OFF");
+          }
+        } // CC_id
       } // UE_id
-      
+
       ret = pthread_create(&forms_thread, NULL, scope_thread, NULL);
-      
+
       if (ret == 0)
-	pthread_setname_np( forms_thread, "xforms" );
-      
+        pthread_setname_np( forms_thread, "xforms" );
+
       printf("Scope thread created, ret=%d\n",ret);
     }
-    
 #endif
     
     rt_sleep_ns(10*100000000ULL);
-    
-    if (nfapi_mode)
-      {
-	printf("NFAPI*** - mutex and cond created - will block shortly for completion of PNF connection\n");
-	pthread_cond_init(&sync_cond,NULL);
-	pthread_mutex_init(&sync_mutex, NULL);
-      }
-    
+
+    if (nfapi_mode) {
+      printf("NFAPI*** - mutex and cond created - will block shortly for completion of PNF connection\n");
+      pthread_cond_init(&sync_cond,NULL);
+      pthread_mutex_init(&sync_mutex, NULL);
+    }
+
     const char *nfapi_mode_str = "<UNKNOWN>";
     
     switch(nfapi_mode) {
     case 0:
       nfapi_mode_str = "MONOLITHIC";
       break;
+
     case 1:
       nfapi_mode_str = "PNF";
       break;
+
     case 2:
       nfapi_mode_str = "VNF";
       break;
+
     default:
       nfapi_mode_str = "<UNKNOWN NFAPI MODE>";
       break;
     }
-    printf("NFAPI MODE:%s\n", nfapi_mode_str);
-    
-    if (nfapi_mode==2) // VNF
+  printf("NFAPI MODE:%s\n", nfapi_mode_str);
+
+
+    if (nfapi_mode==2) {// VNF
+#if defined(PRE_SCD_THREAD)
+      init_ru_vnf();  // ru pointer is necessary for pre_scd.
+#endif
       wait_nfapi_init("main?");
-    
-    
+    }
+
+
     printf("START MAIN THREADS\n");
-    
     // start the main threads
-    
-    number_of_cards = 1;    
+    number_of_cards = 1;
     printf("RC.nb_L1_inst:%d\n", RC.nb_L1_inst);
+
     if (RC.nb_L1_inst > 0) {
-      printf("Initializing eNB threads single_thread_flag:%d wait_for_sync:%d\n", single_thread_flag,wait_for_sync);
-      init_eNB(single_thread_flag,wait_for_sync);
+      printf("Initializing eNB threads single_thread_flag:%d wait_for_sync:%d\n", get_softmodem_params()->single_thread_flag,get_softmodem_params()->wait_for_sync);
+      init_eNB(get_softmodem_params()->single_thread_flag,get_softmodem_params()->wait_for_sync);
       //      for (inst=0;inst<RC.nb_L1_inst;inst++)
-      //	for (CC_id=0;CC_id<RC.nb_L1_CC[inst];CC_id++) phy_init_lte_eNB(RC.eNB[inst][CC_id],0,0);
+      //  for (CC_id=0;CC_id<RC.nb_L1_CC[inst];CC_id++) phy_init_lte_eNB(RC.eNB[inst][CC_id],0,0);
     }
-    
+
     printf("wait_eNBs()\n");
     wait_eNBs();
-    
+
     printf("About to Init RU threads RC.nb_RU:%d\n", RC.nb_RU);
-    if (RC.nb_RU >0) {
+
+    // RU thread and some L1 procedure aren't necessary in VNF or L2 FAPI simulator.
+    // but RU thread deals with pre_scd and this is necessary in VNF and simulator.
+    // some initialization is necessary and init_ru_vnf do this.
+    if (RC.nb_RU >0 && nfapi_mode != 2) {
       printf("Initializing RU threads\n");
-      init_RU(rf_config_file);
+      init_RU(get_softmodem_params()->rf_config_file);
       for (ru_id=0;ru_id<RC.nb_RU;ru_id++) {
-	RC.ru[ru_id]->rf_map.card=0;
-	RC.ru[ru_id]->rf_map.chain=CC_id+chain_offset;
+        RC.ru[ru_id]->rf_map.card=0;
+        RC.ru[ru_id]->rf_map.chain=CC_id+(get_softmodem_params()->chain_offset);
       }
     }
-    
+
     config_sync_var=0;
-    
+
     if (nfapi_mode==1) { // PNF
       wait_nfapi_init("main?");
     }
-    
+
     printf("wait RUs\n");
     fflush(stdout);
     fflush(stderr);
@@ -1095,36 +866,28 @@ int main( int argc, char **argv )
     printf("RC.nb_RU:%d\n", RC.nb_RU);
     // once all RUs are ready intiailize the rest of the eNBs ((dependence on final RU parameters after configuration)
     printf("ALL RUs ready - init eNBs\n");
-    
-    if (nfapi_mode != 1 && nfapi_mode != 2)
-      {
-	printf("Not NFAPI mode - call init_eNB_afterRU()\n");
-	init_eNB_afterRU();
-      }
-    else
-      {
-	printf("NFAPI mode - DO NOT call init_eNB_afterRU()\n");
-      }
-    
+
+    if (nfapi_mode != 1 && nfapi_mode != 2) {
+      printf("Not NFAPI mode - call init_eNB_afterRU()\n");
+      init_eNB_afterRU();
+    } else {
+      printf("NFAPI mode - DO NOT call init_eNB_afterRU()\n");
+    }
+
     printf("ALL RUs ready - ALL eNBs ready\n");
-    
-    
     // connect the TX/RX buffers
- 
     sleep(1); /* wait for thread activation */
-    
     printf("Sending sync to all threads\n");
-    
     pthread_mutex_lock(&sync_mutex);
     sync_var=0;
     pthread_cond_broadcast(&sync_cond);
     pthread_mutex_unlock(&sync_mutex);
+    config_check_unknown_cmdlineopt(CONFIG_CHECKALLSECTIONS);
   }
 
-    // wait for end of program
+  // wait for end of program
   printf("TYPE <CTRL-C> TO TERMINATE\n");
   //getchar();
-
 #if defined(ENABLE_ITTI)
   printf("Entering ITTI signals handler\n");
   itti_wait_tasks_end();
@@ -1135,10 +898,9 @@ int main( int argc, char **argv )
 
   while (oai_exit==0)
     rt_sleep_ns(100000000ULL);
-  printf("Terminating application - oai_exit=%d\n",oai_exit);
 
+  printf("Terminating application - oai_exit=%d\n",oai_exit);
 #endif
-
   // stop threads
 
 
@@ -1147,23 +909,21 @@ int main( int argc, char **argv )
     int UE_id;
 #ifdef XFORMS
     printf("waiting for XFORMS thread\n");
-    
-    if (do_forms==1) {
+
+    if (get_softmodem_params()->do_forms==1) {
       pthread_join(forms_thread,&status);
       fl_hide_form(form_stats->stats_form);
       fl_free_form(form_stats->stats_form);
-      
       fl_hide_form(form_stats_l2->stats_form);
       fl_free_form(form_stats_l2->stats_form);
-      
+
       for(UE_id=0; UE_id<scope_enb_num_ue; UE_id++) {
-	for(CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
-	  fl_hide_form(form_enb[CC_id][UE_id]->lte_phy_scope_enb);
-	  fl_free_form(form_enb[CC_id][UE_id]->lte_phy_scope_enb);
-	}
+        for(CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
+          fl_hide_form(form_enb[CC_id][UE_id]->lte_phy_scope_enb);
+          fl_free_form(form_enb[CC_id][UE_id]->lte_phy_scope_enb);
+        }
       }
     }
-    
 #endif
 
     printf("stopping MODEM threads\n");
@@ -1182,22 +942,13 @@ int main( int argc, char **argv )
       phy_free_RU(RC.ru[inst]);
     }
     free_lte_top();
-
-    printf("About to call end_configmodule() from %s() %s:%d\n", __FUNCTION__, __FILE__, __LINE__);
     end_configmodule();
-    printf("Called end_configmodule() from %s() %s:%d\n", __FUNCTION__, __FILE__, __LINE__);
-
     pthread_cond_destroy(&sync_cond);
     pthread_mutex_destroy(&sync_mutex);
-
     pthread_cond_destroy(&nfapi_sync_cond);
     pthread_mutex_destroy(&nfapi_sync_mutex);
-
     pthread_mutex_destroy(&ue_pf_po_mutex);
     
-    // *** Handle per CC_id openair0
-    
-    
     for(ru_id=0; ru_id<RC.nb_RU; ru_id++) {
       if (RC.ru[ru_id]->rfdevice.trx_end_func) {
         RC.ru[ru_id]->rfdevice.trx_end_func(&RC.ru[ru_id]->rfdevice);
@@ -1210,17 +961,11 @@ int main( int argc, char **argv )
     }
   }
 
-  printf("About to call end_configmodule() from %s() %s:%d\n", __FUNCTION__, __FILE__, __LINE__);
-  end_configmodule();
-  printf("Called end_configmodule() from %s() %s:%d\n", __FUNCTION__, __FILE__, __LINE__);
-
   
   if (opt_enabled == 1)
     terminate_opt();
   
   logClean();
-
   printf("Bye.\n");
-  
   return 0;
 }
diff --git a/targets/RT/USER/lte-softmodem.h b/targets/RT/USER/lte-softmodem.h
index 96ab799c3d11c5e1e2c2b0ce02710b50bf453873..85ee4765f09b283577845ec4e9a7e6a0355d263c 100644
--- a/targets/RT/USER/lte-softmodem.h
+++ b/targets/RT/USER/lte-softmodem.h
@@ -35,12 +35,12 @@
 #include "flexran_agent.h"
 
 #if defined(ENABLE_ITTI)
-#if defined(ENABLE_USE_MME)
-#include "s1ap_eNB.h"
-#ifdef PDCP_USE_NETLINK
-#include "SIMULATION/ETH_TRANSPORT/proto.h"
-#endif
-#endif
+  #if defined(ENABLE_USE_MME)
+    #include "s1ap_eNB.h"
+    #ifdef PDCP_USE_NETLINK
+      #include "SIMULATION/ETH_TRANSPORT/proto.h"
+    #endif
+  #endif
 #endif
 
 /* help strings definition for command line options, used in CMDLINE_XXX_DESC macros and printed when -h option is used */
@@ -60,14 +60,14 @@
 #define CONFIG_HLP_UENANTR       "set UE number of rx antennas\n"
 #define CONFIG_HLP_UENANTT       "set UE number of tx antennas\n"
 #define CONFIG_HLP_UESCAN        "set UE to scan around carrier\n"
-#define CONFIG_HLP_DUMPFRAME     "dump UE received frame to rxsig_frame0.dat and exit\n" 
+#define CONFIG_HLP_DUMPFRAME     "dump UE received frame to rxsig_frame0.dat and exit\n"
 #define CONFIG_HLP_DLSHIFT       "dynamic shift for LLR compuation for TM3/4 (default 0)\n"
 #define CONFIG_HLP_UELOOP        "get softmodem (UE) to loop through memory instead of acquiring from HW\n"
 #define CONFIG_HLP_PHYTST        "test UE phy layer, mac disabled\n"
-#define CONFIG_HLP_DMAMAP        "sets flag for improved EXMIMO UE performance\n"  
+#define CONFIG_HLP_DMAMAP        "sets flag for improved EXMIMO UE performance\n"
 #define CONFIG_HLP_CLK           "tells hardware to use a clock reference (0:internal, 1:external, 2:gpsdo)\n"
-#define CONFIG_HLP_USIM          "use XOR autentication algo in case of test usim mode\n" 
-#define CONFIG_HLP_NOSNGLT       "Disables single-thread mode in lte-softmodem\n" 
+#define CONFIG_HLP_USIM          "use XOR autentication algo in case of test usim mode\n"
+#define CONFIG_HLP_NOSNGLT       "Disables single-thread mode in lte-softmodem\n"
 #define CONFIG_HLP_TADV          "Set timing_advance\n"
 #define CONFIG_HLP_DLF           "Set the downlink frequency for all component carriers\n"
 #define CONFIG_HLP_CHOFF         "Channel id offset\n"
@@ -76,16 +76,14 @@
 #define CONFIG_HLP_ITTIL         "Generate ITTI analyzser logs (similar to wireshark logs but with more details)\n"
 #define CONFIG_HLP_DLMCS         "Set the maximum downlink MCS\n"
 #define CONFIG_HLP_STMON         "Enable processing timing measurement of lte softmodem on per subframe basis \n"
-#define CONFIG_HLP_PRB           "Set the PRB, valid values: 6, 25, 50, 100  \n"    
+#define CONFIG_HLP_PRB           "Set the PRB, valid values: 6, 25, 50, 100  \n"
 #define CONFIG_HLP_EMULIFACE     "Set the interface name for the multicast transport for emulation mode (e.g. eth0, lo, etc.)  \n"
-//#define CONFIG_HLP_NUMUES		 "Set the number of UEs for the emulation"
-#define CONFIG_HLP_MSLOTS        "Skip the missed slots/subframes \n"    
+//#define CONFIG_HLP_NUMUES    "Set the number of UEs for the emulation"
+#define CONFIG_HLP_MSLOTS        "Skip the missed slots/subframes \n"
 #define CONFIG_HLP_ULMCS         "Set the maximum uplink MCS\n"
 #define CONFIG_HLP_TDD           "Set hardware to TDD mode (default: FDD). Used only with -U (otherwise set in config file).\n"
 #define CONFIG_HLP_SNR           "Set average SNR in dB (for --siml1 option)\n"
 #define CONFIG_HLP_UE            "Set the lte softmodem as a UE\n"
-#define CONFIG_HLP_L2MONW        "Enable L2 wireshark messages on localhost \n"
-#define CONFIG_HLP_L2MONP        "Enable L2 pcap  messages on localhost \n"
 #define CONFIG_HLP_TQFS          "Apply three-quarter of sampling frequency, 23.04 Msps to reduce the data rate on USB/PCIe transfers (only valid for 20 MHz)\n"
 #define CONFIG_HLP_TPORT         "tracer port\n"
 #define CONFIG_HLP_NOTWAIT       "don't wait for tracer, start immediately\n"
@@ -95,14 +93,15 @@
 #define CONFIG_HLP_EMULATE_RF    "Emulated RF enabled(disable by defult)\n"
 #define CONFIG_HLP_PARALLEL_CMD  "three config for level of parallelism 'PARALLEL_SINGLE_THREAD', 'PARALLEL_RU_L1_SPLIT', or 'PARALLEL_RU_L1_TRX_SPLIT'\n"
 #define CONFIG_HLP_WORKER_CMD    "two option for worker 'WORKER_DISABLE' or 'WORKER_ENABLE'\n"
-
+#define CONFIG_HLP_NOS1          "Disable s1 interface\n"
+#define CONFIG_HLP_NOKRNMOD      "(noS1 only): Use tun instead of namesh module \n"
 #define CONFIG_HLP_DISABLNBIOT   "disable nb-iot, even if defined in config\n"
 
 #define CONFIG_HLP_USRP_ARGS                "set the arguments to identify USRP (same syntax as in UHD)\n"
 #define CONFIG_HLP_USRP_CLK_SRC              "USRP clock source: 'internal' or 'external'\n"
 
 /***************************************************************************************************************************************/
-/* command line options definitions, CMDLINE_XXXX_DESC macros are used to initialize paramdef_t arrays which are then used as argument 
+/* command line options definitions, CMDLINE_XXXX_DESC macros are used to initialize paramdef_t arrays which are then used as argument
    when calling config_get or config_getlist functions                                                                                 */
 
 
@@ -111,15 +110,15 @@
 /*   optname                     helpstr                paramflags                      XXXptr        defXXXval         type       numelt   */
 /*------------------------------------------------------------------------------------------------------------------------------------------*/
 #define CMDLINE_UEMODEPARAMS_DESC {  \
-{"calib-ue-rx",                 CONFIG_HLP_CALUER,     0,		 iptr:&rx_input_level_dBm,   defintval:0,	 TYPE_INT,   0},    \
-{"calib-ue-rx-med",             CONFIG_HLP_CALUERM,    0,		 iptr:&rx_input_level_dBm,   defintval:0,	 TYPE_INT,   0},    \
-{"calib-ue-rx-byp",             CONFIG_HLP_CALUERB,    0,		 iptr:&rx_input_level_dBm,   defintval:0,	 TYPE_INT,   0},    \
-{"debug-ue-prach",              CONFIG_HLP_DBGUEPR,    PARAMFLAG_BOOL,   uptr:NULL,		     defuintval:1,	 TYPE_INT,   0},    \
-{"no-L2-connect",               CONFIG_HLP_NOL2CN,     PARAMFLAG_BOOL,   uptr:NULL,		     defuintval:1,	 TYPE_INT,   0},    \
-{"calib-prach-tx",              CONFIG_HLP_CALPRACH,   PARAMFLAG_BOOL,   uptr:NULL,		     defuintval:1,	 TYPE_INT,   0},    \
-{"loop-memory",                 CONFIG_HLP_UELOOP,     0,		 strptr:&loopfile,	     defstrval:"iqs.in", TYPE_STRING,0},    \
-{"ue-dump-frame",               CONFIG_HLP_DUMPFRAME,  PARAMFLAG_BOOL,   iptr:&dumpframe,	     defintval:0,	 TYPE_INT,   0},    \
-}  
+    {"calib-ue-rx",                 CONFIG_HLP_CALUER,     0,    iptr:&rx_input_level_dBm,   defintval:0,  TYPE_INT,   0},    \
+    {"calib-ue-rx-med",             CONFIG_HLP_CALUERM,    0,    iptr:&rx_input_level_dBm,   defintval:0,  TYPE_INT,   0},    \
+    {"calib-ue-rx-byp",             CONFIG_HLP_CALUERB,    0,    iptr:&rx_input_level_dBm,   defintval:0,  TYPE_INT,   0},    \
+    {"debug-ue-prach",              CONFIG_HLP_DBGUEPR,    PARAMFLAG_BOOL,   uptr:NULL,        defuintval:1,   TYPE_INT,   0},    \
+    {"no-L2-connect",               CONFIG_HLP_NOL2CN,     PARAMFLAG_BOOL,   uptr:NULL,        defuintval:1,   TYPE_INT,   0},    \
+    {"calib-prach-tx",              CONFIG_HLP_CALPRACH,   PARAMFLAG_BOOL,   uptr:NULL,        defuintval:1,   TYPE_INT,   0},    \
+    {"loop-memory",                 CONFIG_HLP_UELOOP,     0,    strptr:&loopfile,       defstrval:"iqs.in", TYPE_STRING,0},    \
+    {"ue-dump-frame",               CONFIG_HLP_DUMPFRAME,  PARAMFLAG_BOOL,   iptr:&dumpframe,      defintval:0,  TYPE_INT,   0},    \
+  }
 #define CMDLINE_CALIBUERX_IDX                   0
 #define CMDLINE_CALIBUERXMED_IDX                1
 #define CMDLINE_CALIBUERXBYP_IDX                2
@@ -130,28 +129,48 @@
 #define CMDLINE_DUMPMEMORY_IDX                  7
 /*------------------------------------------------------------------------------------------------------------------------------------------*/
 
+#define START_MSC          softmodem_params.start_msc
+/*-------------------------------------------------------------------------------------------------------------------------------------------------------*/
+/*                                            command line parameters specific to UE                                                                     */
+/*   optname                     helpstr             paramflags                      XXXptr                  defXXXval            type          numelt   */
+/*-------------------------------------------------------------------------------------------------------------------------------------------------------*/
 
-/*--------------------------------------------------------------------------------------------------------------------------------------------------*/
-/*                                            command line parameters specific to UE                                                                */
-/*   optname                     helpstr             paramflags                      XXXptr                  defXXXval       type          numelt   */
-/*--------------------------------------------------------------------------------------------------------------------------------------------------*/
 #define CMDLINE_UEPARAMS_DESC {  \
-{"siml1",                      CONFIG_HLP_SIML1,      PARAMFLAG_BOOL,   iptr:&simL1flag,                    defintval:0,    TYPE_INT,      0}, \
-{"U",			       CONFIG_HLP_NUMUE,      0,                u8ptr:&NB_UE_INST,                   defuintval:1,    TYPE_UINT,      0}, \
-{"ue-rxgain",        	       CONFIG_HLP_UERXG,      0,		dblptr:&(rx_gain[0][0]),	    defdblval:130,    TYPE_DOUBLE,   0},     \
-{"ue-rxgain-off",    	       CONFIG_HLP_UERXGOFF,   0,		dblptr:&rx_gain_off,		    defdblval:0,    TYPE_DOUBLE,   0},     \
-{"ue-txgain",        	       CONFIG_HLP_UETXG,      0,		dblptr:&(tx_gain[0][0]),	    defdblval:0,    TYPE_DOUBLE,   0},     \
-{"ue-nb-ant-rx",     	       CONFIG_HLP_UENANTR,    0,		u8ptr:&nb_antenna_rx,		    defuintval:1,   TYPE_UINT8,    0},     \
-{"ue-nb-ant-tx",     	       CONFIG_HLP_UENANTT,    0,		u8ptr:&nb_antenna_tx,		    defuintval:1,   TYPE_UINT8,    0},     \
-{"ue-scan-carrier",  	       CONFIG_HLP_UESCAN,     PARAMFLAG_BOOL,	iptr:&UE_scan_carrier,  	    defintval:0,    TYPE_INT,	   0},     \
-{"ue-max-power",     	       NULL,		      0,		iptr:&(tx_max_power[0]),	    defintval:23,   TYPE_INT,	   0},     \
-{"emul-iface",                 CONFIG_HLP_EMULIFACE,  0,                strptr:&emul_iface,                 defstrval:"lo", TYPE_STRING,   100},   \
-{"L2-emul",                    NULL,  		      0,                u8ptr:&nfapi_mode,                  defuintval:3, TYPE_UINT8,   0}, \
-{"num-ues",     	       		   NULL,		      	  0,				u8ptr:&(NB_UE_INST),	    defuintval:1,   	TYPE_UINT8,	   0},     \
-{"r"  ,                        CONFIG_HLP_PRB,        0,                u8ptr:&(frame_parms[0]->N_RB_DL),   defintval:25,   TYPE_UINT8,    0},     \
-{"dlsch-demod-shift",     	 CONFIG_HLP_DLSHIFT,	0,		  iptr:(int32_t *)&dlsch_demod_shift,	defintval:0,			   TYPE_INT,	  0},			   \
-{"usrp-args",               CONFIG_HLP_USRP_ARGS,   0,                      strptr:(char **)&usrp_args,         defstrval:"type=b200",          TYPE_STRING,    0},                     \
-{"usrp-clksrc",             CONFIG_HLP_USRP_CLK_SRC,0,                      strptr:(char **)&usrp_clksrc,       defstrval:"internal",           TYPE_STRING,    0}                     \
+    {"siml1",                      CONFIG_HLP_SIML1,       PARAMFLAG_BOOL,  iptr:&simL1flag,                    defintval:0,          TYPE_INT,      0},   \
+    {"U",            CONFIG_HLP_NUMUE,       0,               u16ptr:&NB_UE_INST,                  defuintval:1,         TYPE_UINT16,     0},   \
+    {"ue-rxgain",                CONFIG_HLP_UERXG,       0,   dblptr:&(rx_gain[0][0]),      defdblval:130,        TYPE_DOUBLE,   0},   \
+    {"ue-rxgain-off",            CONFIG_HLP_UERXGOFF,    0,   dblptr:&rx_gain_off,        defdblval:0,          TYPE_DOUBLE,   0},   \
+    {"ue-txgain",                CONFIG_HLP_UETXG,       0,   dblptr:&(tx_gain[0][0]),      defdblval:0,          TYPE_DOUBLE,   0},   \
+    {"ue-nb-ant-rx",             CONFIG_HLP_UENANTR,     0,   u8ptr:&nb_antenna_rx,       defuintval:1,         TYPE_UINT8,    0},   \
+    {"ue-nb-ant-tx",             CONFIG_HLP_UENANTT,     0,   u8ptr:&nb_antenna_tx,       defuintval:1,         TYPE_UINT8,    0},   \
+    {"ue-scan-carrier",          CONFIG_HLP_UESCAN,      PARAMFLAG_BOOL,  iptr:&UE_scan_carrier,        defintval:0,          TYPE_INT,  0},   \
+    {"ue-max-power",             NULL,           0,   iptr:&(tx_max_power[0]),      defintval:23,         TYPE_INT,  0},   \
+    {"emul-iface",                 CONFIG_HLP_EMULIFACE,   0,               strptr:&emul_iface,       defstrval:"lo",       TYPE_STRING,   100}, \
+    {"L2-emul",                    NULL,             0,               u8ptr:&nfapi_mode,        defuintval:3,         TYPE_UINT8,  0},   \
+    {"num-ues",              NULL,                   0,               u16ptr:&(NB_UE_INST),        defuintval:1,         TYPE_UINT16,  0},   \
+    {"nums_ue_thread",             NULL,                   0,               u16ptr:&(NB_THREAD_INST),           defuintval:1,         TYPE_UINT16,   0},   \
+    {"r"  ,                        CONFIG_HLP_PRB,         0,               u8ptr:&(frame_parms[0]->N_RB_DL),   defintval:25,         TYPE_UINT8,    0},   \
+    {"dlsch-demod-shift",          CONFIG_HLP_DLSHIFT,     0,   iptr:(int32_t *)&dlsch_demod_shift, defintval:0,          TYPE_INT,  0},   \
+    {"usrp-args",                  CONFIG_HLP_USRP_ARGS,   0,               strptr:(char **)&usrp_args,         defstrval:"type=b200",TYPE_STRING,   0},   \
+    {"usrp-clksrc",                CONFIG_HLP_USRP_CLK_SRC,0,               strptr:(char **)&usrp_clksrc,       defstrval:"internal", TYPE_STRING,   0},   \
+    {"mmapped-dma",                CONFIG_HLP_DMAMAP,      PARAMFLAG_BOOL,  uptr:&mmapped_dma,                  defintval:0,          TYPE_INT,      0},   \
+    {"clock",                      CONFIG_HLP_CLK,         0,               uptr:&clock_source,                 defintval:0,          TYPE_UINT,     0},   \
+    {"s" ,                         CONFIG_HLP_SNR,         0,               iptr:&snr_dB,                       defintval:25,         TYPE_INT,      0},   \
+    {"T" ,                         CONFIG_HLP_TDD,         PARAMFLAG_BOOL,  iptr:&tddflag,                      defintval:0,          TYPE_INT,      0},   \
+    {"A",                          CONFIG_HLP_TADV,        0,               iptr:&(timingadv),                  defintval:0,          TYPE_INT,      0}    \
+  }
+
+/*-------------------------------------------------------------------------------------------------------------------------------------------------------*/
+/*                                            command line parameters specific to UE threads                                                             */
+/*   optname                     helpstr             paramflags                      XXXptr                  defXXXval            type          numelt   */
+/*-------------------------------------------------------------------------------------------------------------------------------------------------------*/
+#define CMDLINE_UETHREADSPARAMS_DESC {  \
+    {"threadIQ",                NULL,                   0,                      iptr:&(threads.iq),                 defintval:1,                    TYPE_INT,       0},                     \
+    {"threadOneSubframe",       NULL,                   0,                      iptr:&(threads.one),                defintval:1,                    TYPE_INT,       0},                     \
+    {"threadTwoSubframe",       NULL,                   0,                      iptr:&(threads.two),                defintval:1,                    TYPE_INT,       0},                     \
+    {"threadThreeSubframe",     NULL,                   0,                      iptr:&(threads.three),              defintval:1,                    TYPE_INT,       0},                     \
+    {"threadSlot1ProcOne",      NULL,                   0,                      iptr:&(threads.slot1_proc_one),     defintval:1,                    TYPE_INT,       0},                     \
+    {"threadSlot1ProcTwo",      NULL,                   0,                      iptr:&(threads.slot1_proc_two),     defintval:1,                    TYPE_INT,       0},                     \
   }
 
 #define DEFAULT_DLF 2680000000
@@ -160,41 +179,37 @@
 /*                                            command line parameters common to eNodeB and UE                                                                                */
 /*   optname                     helpstr                paramflags                      XXXptr                  defXXXval                            type           numelt   */
 /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
+#define RF_CONFIG_FILE      softmodem_params.rf_config_file
+#define PHY_TEST            softmodem_params.phy_test
+#define WAIT_FOR_SYNC       softmodem_params.wait_for_sync
+#define SINGLE_THREAD_FLAG  softmodem_params.single_thread_flag
+#define CHAIN_OFFSET        softmodem_params.chain_offset
+#define DO_FORMS            softmodem_params.do_forms
+#define NUMEROLOGY          softmodem_params.numerology
+#define EMULATE_RF          softmodem_params.emulate_rf
+#define CLOCK_SOURCE        softmodem_params.clock_source
+#define USIM_TEST           softmodem_params.usim_test
 #define CMDLINE_PARAMS_DESC {  \
-{"rf-config-file",          CONFIG_HLP_RFCFGF,      0,                      strptr:(char **)&rf_config_file,    defstrval:NULL,                 TYPE_STRING,    sizeof(rf_config_file)}, \
-{"ulsch-max-errors",        CONFIG_HLP_ULMAXE,      0,                      uptr:&ULSCH_max_consecutive_errors, defuintval:0,                   TYPE_UINT,      0},                     \
-{"phy-test",                CONFIG_HLP_PHYTST,      PARAMFLAG_BOOL,         iptr:&phy_test,                     defintval:0,                    TYPE_INT,       0},                     \
-{"usim-test",               CONFIG_HLP_USIM,        PARAMFLAG_BOOL,         u8ptr:&usim_test,                   defintval:0,                    TYPE_UINT8,     0},                     \
-{"mmapped-dma",             CONFIG_HLP_DMAMAP,      PARAMFLAG_BOOL,         uptr:&mmapped_dma,                  defintval:0,                    TYPE_INT,       0},                     \
-{"clock",                   CONFIG_HLP_CLK,         0,                      uptr:&clock_source,                 defintval:0,                    TYPE_UINT,      0},                     \
-{"wait-for-sync",           NULL,                   PARAMFLAG_BOOL,         iptr:&wait_for_sync,                defintval:0,                    TYPE_INT,       0},                     \
-{"single-thread-enable",    CONFIG_HLP_NOSNGLT,     PARAMFLAG_BOOL,         iptr:&single_thread_flag,           defintval:0,                    TYPE_INT,       0},                     \
-{"threadIQ",                NULL,                   0,                      iptr:&(threads.iq),                 defintval:1,                    TYPE_INT,       0},                     \
-{"threadOneSubframe",       NULL,                   0,                      iptr:&(threads.one),                defintval:1,                    TYPE_INT,       0},                     \
-{"threadTwoSubframe",       NULL,                   0,                      iptr:&(threads.two),                defintval:1,                    TYPE_INT,       0},                     \
-{"threadThreeSubframe",     NULL,                   0,                      iptr:&(threads.three),              defintval:1,                    TYPE_INT,       0},                     \
-{"threadSlot1ProcOne",      NULL,                   0,                      iptr:&(threads.slot1_proc_one),     defintval:1,                    TYPE_INT,       0},                     \
-{"threadSlot1ProcTwo",      NULL,                   0,                      iptr:&(threads.slot1_proc_two),     defintval:1,                    TYPE_INT,       0},                     \
-{"dlsch-demod-shift",       CONFIG_HLP_DLSHIFT,     0,                      iptr:(int32_t *)&dlsch_demod_shift, defintval:0,                    TYPE_INT,       0},                     \
-{"A" ,                      CONFIG_HLP_TADV,        0,                      uptr:&timing_advance,               defintval:0,                    TYPE_UINT,      0},                     \
-{"C" ,                      CONFIG_HLP_DLF,         0,                      uptr:&(downlink_frequency[0][0]),   defuintval:2680000000,          TYPE_UINT,      0},                     \
-{"a" ,                      CONFIG_HLP_CHOFF,       0,                      iptr:&chain_offset,                 defintval:0,                    TYPE_INT,       0},                     \
-{"d" ,                      CONFIG_HLP_SOFTS,       PARAMFLAG_BOOL,         uptr:(uint32_t *)&do_forms,         defintval:0,                    TYPE_INT8,      0},                     \
-{"E" ,                      CONFIG_HLP_TQFS,        PARAMFLAG_BOOL,         i8ptr:&threequarter_fs,             defintval:0,                    TYPE_INT8,      0},                     \
-{"m" ,                      CONFIG_HLP_DLMCS,       0,                      uptr:&target_dl_mcs,                defintval:0,                    TYPE_UINT,      0},                     \
-{"t" ,                      CONFIG_HLP_ULMCS,       0,                      uptr:&target_ul_mcs,                defintval:0,                    TYPE_UINT,      0},                     \
-{"W" ,                      CONFIG_HLP_L2MONW,      0,                      strptr:(char **)&in_ip,             defstrval:"127.0.0.1",          TYPE_STRING,    sizeof(in_ip)},         \
-{"P" ,                      CONFIG_HLP_L2MONP,      0,                      strptr:(char **)&in_path,           defstrval:"/tmp/oai_opt.pcap",  TYPE_STRING,    sizeof(in_path)},       \
-{"q" ,                      CONFIG_HLP_STMON,       PARAMFLAG_BOOL,         iptr:&opp_enabled,                  defintval:0,                    TYPE_INT,       0},                     \
-{"S" ,                      CONFIG_HLP_MSLOTS,      PARAMFLAG_BOOL,         u8ptr:&exit_missed_slots,           defintval:1,                    TYPE_UINT8,     0},                     \
-{"T" ,                      CONFIG_HLP_TDD,         PARAMFLAG_BOOL,         iptr:&tddflag,                      defintval:0,                    TYPE_INT,       0},                     \
-{"s" ,                      CONFIG_HLP_SNR,         0,                      iptr:&snr_dB,                       defintval:25,                   TYPE_INT,       0},                     \
-{"numerology" ,             CONFIG_HLP_NUMEROLOGY,  PARAMFLAG_BOOL,         iptr:&numerology,                   defintval:0,                    TYPE_INT,       0},                     \
-{"emulate-rf" ,             CONFIG_HLP_EMULATE_RF,  PARAMFLAG_BOOL,         iptr:&emulate_rf,                   defintval:0,                    TYPE_INT,       0},                     \
-{"parallel-config",         CONFIG_HLP_PARALLEL_CMD,0,                      strptr:(char **)&parallel_config,   defstrval:NULL,                 TYPE_STRING,    0},                     \
-{"worker-config",           CONFIG_HLP_WORKER_CMD,  0,                      strptr:(char **)&worker_config,     defstrval:NULL,                 TYPE_STRING,    0},                     \
-{"nbiot-disable",           CONFIG_HLP_DISABLNBIOT, PARAMFLAG_BOOL,         iptr:&nonbiotflag,			defintval:0,                    TYPE_INT,       0}                      \
-}
+    {"rf-config-file",          CONFIG_HLP_RFCFGF,      0,                      strptr:(char **)&RF_CONFIG_FILE,    defstrval:NULL,                 TYPE_STRING,    sizeof(RF_CONFIG_FILE)}, \
+    {"ulsch-max-errors",        CONFIG_HLP_ULMAXE,      0,                      uptr:&ULSCH_max_consecutive_errors, defuintval:0,                   TYPE_UINT,      0},                     \
+    {"phy-test",                CONFIG_HLP_PHYTST,      PARAMFLAG_BOOL,         iptr:&PHY_TEST,                     defintval:0,                    TYPE_INT,       0},                     \
+    {"usim-test",               CONFIG_HLP_USIM,        PARAMFLAG_BOOL,         u8ptr:&USIM_TEST,                   defintval:0,                    TYPE_UINT8,     0},                     \
+    {"emulate-rf" ,             CONFIG_HLP_EMULATE_RF,  PARAMFLAG_BOOL,         iptr:&EMULATE_RF,                   defintval:0,                    TYPE_INT,       0},                     \
+    {"clock",                   CONFIG_HLP_CLK,         0,                      uptr:&CLOCK_SOURCE,                 defintval:0,                    TYPE_UINT,      0},                     \
+    {"wait-for-sync",           NULL,                   PARAMFLAG_BOOL,         iptr:&WAIT_FOR_SYNC,                defintval:0,                    TYPE_INT,       0},                     \
+    {"single-thread-enable",    CONFIG_HLP_NOSNGLT,     PARAMFLAG_BOOL,         iptr:&SINGLE_THREAD_FLAG,           defintval:0,                    TYPE_INT,       0},                     \
+    {"C" ,                      CONFIG_HLP_DLF,         0,                      uptr:&(downlink_frequency[0][0]),   defuintval:2680000000,          TYPE_UINT,      0},                     \
+    {"a" ,                      CONFIG_HLP_CHOFF,       0,                      iptr:&CHAIN_OFFSET,                 defintval:0,                    TYPE_INT,       0},                     \
+    {"d" ,                      CONFIG_HLP_SOFTS,       PARAMFLAG_BOOL,         uptr:(uint32_t *)&DO_FORMS,         defintval:0,                    TYPE_INT8,      0},                     \
+    {"q" ,                      CONFIG_HLP_STMON,       PARAMFLAG_BOOL,         iptr:&opp_enabled,                  defintval:0,                    TYPE_INT,       0},                     \
+    {"S" ,                      CONFIG_HLP_MSLOTS,      PARAMFLAG_BOOL,         u8ptr:&exit_missed_slots,           defintval:1,                    TYPE_UINT8,     0},                     \
+    {"numerology" ,             CONFIG_HLP_NUMEROLOGY,  PARAMFLAG_BOOL,         iptr:&NUMEROLOGY,                   defintval:0,                    TYPE_INT,       0},                     \
+    {"parallel-config",         CONFIG_HLP_PARALLEL_CMD,0,                      strptr:(char **)&parallel_config,   defstrval:NULL,                 TYPE_STRING,    0},                     \
+    {"worker-config",           CONFIG_HLP_WORKER_CMD,  0,                      strptr:(char **)&worker_config,     defstrval:NULL,                 TYPE_STRING,    0},                     \
+    {"noS1",                    CONFIG_HLP_NOS1,        PARAMFLAG_BOOL,         uptr:&noS1,             defintval:0,      TYPE_INT, 0},                     \
+    {"nokrnmod",                CONFIG_HLP_NOKRNMOD,    PARAMFLAG_BOOL,         uptr:&nokrnmod,     defintval:0,      TYPE_INT, 0},                     \
+    {"nbiot-disable",           CONFIG_HLP_DISABLNBIOT, PARAMFLAG_BOOL,         uptr:&nonbiot,      defuintval:0,                   TYPE_INT,       0},                     \
+  }
 
 #define CONFIG_HLP_FLOG          "Enable online log \n"
 #define CONFIG_HLP_LOGL          "Set the global log level, valide options: (4:trace, 3:debug, 2:info, 1:warn, (0:error))\n"
@@ -204,19 +219,58 @@
 /*                                            command line parameters for LOG utility                                                                                        */
 /*   optname                     helpstr                paramflags                      XXXptr                  defXXXval                            type           numelt   */
 /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
+#define START_MSC          softmodem_params.start_msc
 #define CMDLINE_LOGPARAMS_DESC {  \
-{"R" ,  		  	 CONFIG_HLP_FLOG,	0,                uptr:&online_log_messages,		defintval:1,			   TYPE_INT,	  0},			   \
-{"g" ,  		  	 CONFIG_HLP_LOGL,	0,		  uptr:&glog_level,			defintval:0,			   TYPE_UINT,     0},			   \
-{"telnetsrv",    		 CONFIG_HLP_TELN,	PARAMFLAG_BOOL,	  uptr:&start_telnetsrv,		defintval:0,			   TYPE_UINT,     0},			   \
-{"msc",    		         CONFIG_HLP_MSC,	PARAMFLAG_BOOL,	  uptr:start_msc,		        defintval:0,			   TYPE_UINT,     0},	                   \
-}
-#define CMDLINE_ONLINELOG_IDX     0 
+    {"R" ,           CONFIG_HLP_FLOG, 0,                uptr:&online_log_messages,    defintval:1,         TYPE_INT,    0},        \
+    {"g" ,           CONFIG_HLP_LOGL, 0,      uptr:&glog_level,     defintval:0,         TYPE_UINT,     0},        \
+    {"telnetsrv",        CONFIG_HLP_TELN, PARAMFLAG_BOOL,   uptr:&start_telnetsrv,    defintval:0,         TYPE_UINT,     0},        \
+    {"msc",                CONFIG_HLP_MSC,  PARAMFLAG_BOOL,   uptr:&START_MSC,            defintval:0,         TYPE_UINT,     0},                    \
+  }
+#define CMDLINE_ONLINELOG_IDX     0
 #define CMDLINE_GLOGLEVEL_IDX     1
 #define CMDLINE_STARTTELN_IDX     2
 
+/* check function for global log level */
+#define CMDLINE_LOGPARAMS_CHECK_DESC { \
+    { .s5= {NULL }} ,                                                 \
+    { .s2=  { config_check_intrange,           {0,4}}},               \
+    { .s5= {NULL }} ,                   \
+    { .s5= {NULL }} ,                   \
+  }
 
-/***************************************************************************************************************************************/  
+/***************************************************************************************************************************************/
 /*  */
+#include "threads_t.h"
+
+#define SOFTMODEM_NOS1_BIT            (1<<0)
+#define SOFTMODEM_NOKRNMOD_BIT        (1<<1)
+#define SOFTMODEM_NONBIOT_BIT         (1<<2)
+typedef struct {
+  uint64_t       optmask;
+  THREAD_STRUCT  thread_struct;
+  char           rf_config_file[1024];
+  int            phy_test;
+  uint8_t        usim_test;
+  int            emulate_rf;
+  int            wait_for_sync; //eNodeB only
+  int            single_thread_flag; //eNodeB only
+  int            chain_offset;
+  uint32_t       do_forms;
+  int            numerology;
+  unsigned int   start_msc;
+  uint32_t       clock_source;
+  int            hw_timing_advance;
+} softmodem_params_t;
+
+#define IS_SOFTMODEM_NOS1            ( get_softmodem_optmask() & SOFTMODEM_NOS1_BIT)
+#define IS_SOFTMODEM_NOKRNMOD        ( get_softmodem_optmask() & SOFTMODEM_NOKRNMOD_BIT)
+#define IS_SOFTMODEM_NONBIOT         ( get_softmodem_optmask() & SOFTMODEM_NONBIOT_BIT)
+extern uint64_t get_softmodem_optmask(void);
+extern uint64_t set_softmodem_optmask(uint64_t bitmask);
+extern void get_common_options(void);
+extern softmodem_params_t *get_softmodem_params(void);
+
+uint64_t get_pdcp_optmask(void);
 extern pthread_cond_t sync_cond;
 extern pthread_mutex_t sync_mutex;
 extern int sync_var;
@@ -239,22 +293,15 @@ extern int sync_var;
 extern int transmission_mode;
 extern double cpuf;
 
-#if defined(ENABLE_ITTI)
-extern volatile int             start_eNB;
-extern volatile int             start_UE;
-#endif
-
-#include "threads_t.h"
-extern threads_t threads;
-
 // In lte-enb.c
 extern void init_eNB(int single_thread_flag,int wait_for_sync);
 extern void stop_eNB(int);
 extern void kill_eNB_proc(int inst);
 
 // In lte-ru.c
-extern void init_RU(const char*);
+extern void init_RU(char *);
 extern void stop_ru(RU_t *ru);
+extern void init_ru_vnf(void);
 extern void init_RU_proc(RU_t *ru);
 extern void stop_RU(int nb_ru);
 extern void kill_RU_proc(RU_t *ru);
@@ -264,13 +311,14 @@ extern void set_function_spec_param(RU_t *ru);
 extern int setup_ue_buffers(PHY_VARS_UE **phy_vars_ue, openair0_config_t *openair0_cfg);
 extern void fill_ue_band_info(void);
 
-extern void init_UE(int nb_inst,int eMBMS_active, int uecap_xer_in, int timing_correction, int phy_test, int UE_scan, int UE_scan_carrier, runmode_t mode,int rxgain,int txpowermax, LTE_DL_FRAME_PARMS *fp);
-extern void init_thread(int sched_runtime, int sched_deadline, int sched_fifo, cpu_set_t *cpuset, char * name);
+extern void init_UE(int nb_inst,int eMBMS_active, int uecap_xer_in, int timing_correction, int phy_test, int UE_scan, int UE_scan_carrier, runmode_t mode,int rxgain,int txpowermax,
+                    LTE_DL_FRAME_PARMS *fp);
+extern void init_thread(int sched_runtime, int sched_deadline, int sched_fifo, cpu_set_t *cpuset, char *name);
 
 extern void reset_opp_meas(void);
 extern void print_opp_meas(void);
 
-extern void init_fep_thread(PHY_VARS_eNB *, pthread_attr_t *);
+
 extern void init_td_thread(PHY_VARS_eNB *);
 extern void init_te_thread(PHY_VARS_eNB *);
 extern void kill_td_thread(PHY_VARS_eNB *);
@@ -280,7 +328,7 @@ extern void RCConfig_sim(void);
 extern void init_ocm(double,double);
 extern void init_ue_devices(PHY_VARS_UE *);
 
-PHY_VARS_UE* init_ue_vars(LTE_DL_FRAME_PARMS *frame_parms,
+PHY_VARS_UE *init_ue_vars(LTE_DL_FRAME_PARMS *frame_parms,
                           uint8_t UE_id,
                           uint8_t abstraction_flag);
 void init_eNB_afterRU(void);
@@ -295,8 +343,8 @@ extern int restart_L1L2(module_id_t enb_id);
 
 extern void init_UE_stub_single_thread(int nb_inst,int eMBMS_active, int uecap_xer_in, char *emul_iface);
 
-extern PHY_VARS_UE* init_ue_vars(LTE_DL_FRAME_PARMS *frame_parms,
-                          uint8_t UE_id,
-                          uint8_t abstraction_flag);
+extern PHY_VARS_UE *init_ue_vars(LTE_DL_FRAME_PARMS *frame_parms,
+                                 uint8_t UE_id,
+                                 uint8_t abstraction_flag);
 
 #endif
diff --git a/targets/RT/USER/lte-ue.c b/targets/RT/USER/lte-ue.c
index c49a54b98ac32c59f4e18e17f990209989f784ca..1e68c06d2659e37e96ddbb6b7356d7bed235a55f 100644
--- a/targets/RT/USER/lte-ue.c
+++ b/targets/RT/USER/lte-ue.c
@@ -58,8 +58,8 @@
 #include "UTIL/MATH/oml.h"
 #include "common/utils/LOG/vcd_signal_dumper.h"
 #include "UTIL/OPT/opt.h"
-
-
+#include "lte-softmodem.h"
+#include "common/config/config_userapi.h"
 #include "T.h"
 
 extern double cpuf;
@@ -94,7 +94,7 @@ extern int oai_nfapi_rx_ind(nfapi_rx_indication_t *ind);
 extern int multicast_link_write_sock(int groupP, char *dataP, uint32_t sizeP);
 
 extern int simL1flag;
-
+extern uint16_t sf_ahead;
 //extern int tx_req_UE_MAC1();
 
 void ue_stub_rx_handler(unsigned int, char *);
@@ -102,9 +102,11 @@ void ue_stub_rx_handler(unsigned int, char *);
 int32_t **rxdata;
 int32_t **txdata;
 
-int timer_subframe;
-int timer_frame;
-SF_ticking *phy_stub_ticking;
+int timer_subframe = 0;
+int timer_frame = 0;
+SF_ticking *phy_stub_ticking = NULL;
+int next_ra_frame = 0;
+module_id_t next_Mod_id = 0;
 
 #define KHz (1000UL)
 #define MHz (1000*KHz)
@@ -158,12 +160,21 @@ static const eutra_band_t eutra_bands[] = {
 };
 
 
-
+threads_t threads= {-1,-1,-1,-1,-1,-1,-1};
 
 pthread_t                       main_ue_thread;
 pthread_attr_t                  attr_UE_thread;
 struct sched_param              sched_param_UE_thread;
 
+
+void get_uethreads_params(void) {
+  paramdef_t cmdline_threadsparams[] =CMDLINE_UETHREADSPARAMS_DESC;
+
+
+  config_process_cmdline( cmdline_threadsparams,sizeof(cmdline_threadsparams)/sizeof(paramdef_t),NULL);
+}
+
+
 void phy_init_lte_ue_transport(PHY_VARS_UE *ue,int absraction_flag);
 
 PHY_VARS_UE* init_ue_vars(LTE_DL_FRAME_PARMS *frame_parms,
@@ -179,7 +190,7 @@ PHY_VARS_UE* init_ue_vars(LTE_DL_FRAME_PARMS *frame_parms,
     memcpy(&(ue->frame_parms), frame_parms, sizeof(LTE_DL_FRAME_PARMS));
   }
 
-
+  ue->hw_timing_advance=get_softmodem_params()->hw_timing_advance;
   ue->Mod_id      = UE_id;
   ue->mac_enabled = 1;
 
@@ -377,7 +388,7 @@ void init_UE_stub_single_thread(int nb_inst,int eMBMS_active, int uecap_xer_in,
   for (inst=0;inst<nb_inst;inst++) {
 
     LOG_I(PHY,"Initializing memory for UE instance %d (%p)\n",inst,PHY_vars_UE_g[inst]);
-    PHY_vars_UE_g[inst][0] = init_ue_vars(NULL,inst,0);
+    // PHY_vars_UE_g[inst][0] = init_ue_vars(NULL,inst,0);
   }
   init_timer_thread();
   init_UE_single_thread_stub(nb_inst);
@@ -954,31 +965,60 @@ static void *UE_phy_stub_single_thread_rxn_txnp4(void *arg) {
 
 	thread_top_init("UE_phy_stub_thread_rxn_txnp4",1,870000L,1000000L,1000000L);
 
-	module_id_t Mod_id = 0;
+	// for multipule UE's L2-emulator
+	//module_id_t Mod_id = 0;
+
 	//int init_ra_UE = -1; // This counter is used to initiate the RA of each UE in different SFrames
   static __thread int UE_thread_rxtx_retval;
   struct rx_tx_thread_data *rtd = arg;
+  if (rtd == NULL) {
+      LOG_E( MAC, "[SCHED][UE] rx_tx_thread_data *rtd: NULL pointer\n" );
+      exit_fun("nothing to add");
+  }
   UE_rxtx_proc_t *proc = rtd->proc;
 
-  // Initializations for nfapi-L2-emulator mode
-  dl_config_req = NULL;
-  ul_config_req = NULL;
-  hi_dci0_req	= NULL;
-  tx_request_pdu_list = NULL;
-
-  PHY_VARS_UE    *UE;   //= rtd->UE;
+  // settings for nfapi-L2-emulator mode
+  module_id_t ue_thread_id = rtd->ue_thread_id;
+  uint16_t     ue_index = 0;
+  uint16_t     ue_num = NB_UE_INST/NB_THREAD_INST+((NB_UE_INST%NB_THREAD_INST > ue_thread_id) ? 1 :0);
+  module_id_t ue_Mod_id;
+  PHY_VARS_UE    *UE = NULL;
   int ret;
+  uint8_t   end_flag;
+  proc = &PHY_vars_UE_g[0][0]->proc.proc_rxtx[0];
+  phy_stub_ticking->num_single_thread[ue_thread_id] = -1;
+
+  UE = rtd->UE;
+
+
+  if(ue_thread_id == 0){
+    phy_stub_ticking->ticking_var = -1;
+    proc->subframe_rx=proc->sub_frame_start;
+    // Initializations for nfapi-L2-emulator mode
+    dl_config_req = NULL;
+    ul_config_req = NULL;
+    hi_dci0_req        = NULL;
+    tx_request_pdu_list = NULL;
+
+    // waiting for all UE's threads set phy_stub_ticking->num_single_thread[ue_thread_id] = -1.
+    do{
+      end_flag = 1;
+      for(uint16_t i = 0;i< NB_THREAD_INST;i++){
+        if(phy_stub_ticking->num_single_thread[i] == 0){
+          end_flag = 0;
+        }
+      }
+   }while(end_flag == 0);
 
-
-  phy_stub_ticking->ticking_var = -1;
-  proc->subframe_rx=proc->sub_frame_start;
+    sync_var=0;
+  }
 
 
   //PANOS: CAREFUL HERE!
   wait_sync("UE_phy_stub_single_thread_rxn_txnp4");
 
   while (!oai_exit) {
-
+    if(ue_thread_id == 0){
     if (pthread_mutex_lock(&phy_stub_ticking->mutex_ticking) != 0) {
       LOG_E( MAC, "[SCHED][UE] error locking mutex for UE RXTX\n" );
       exit_fun("nothing to add");
@@ -997,12 +1037,24 @@ static void *UE_phy_stub_single_thread_rxn_txnp4(void *arg) {
 
     proc->subframe_rx=timer_subframe;
     proc->frame_rx = timer_frame;
-    proc->subframe_tx=(timer_subframe+4)%10;
-    proc->frame_tx = proc->frame_rx + (proc->subframe_rx>5?1:0);
-    //oai_subframe_ind(proc->frame_rx, proc->subframe_rx);
 
+    // FDD and TDD tx timing settings.
+    // XXX:It is the result of timing adjustment in debug.
+    // It is necessary to investigate why this will work in the future.
+    proc->subframe_tx=(timer_subframe+sf_ahead)%10;
+    proc->frame_tx = proc->frame_rx + (proc->subframe_rx>(9-sf_ahead)?1:0);
+    //oai_subframe_ind(proc->frame_rx, proc->subframe_rx);
 
-    oai_subframe_ind(timer_frame, timer_subframe);
+    if (UE != NULL) {
+      if (UE->frame_parms.frame_type == FDD) {
+        oai_subframe_ind(proc->frame_rx, proc->subframe_rx);
+      } else {
+        oai_subframe_ind(proc->frame_tx, proc->subframe_tx);
+      }
+    } else {
+      // Default will be FDD
+      oai_subframe_ind(proc->frame_rx, proc->subframe_rx);
+    }
 
     //Guessing that the next 4 lines are not needed for the phy_stub mode.
     /*initRefTimes(t2);
@@ -1026,14 +1078,45 @@ static void *UE_phy_stub_single_thread_rxn_txnp4(void *arg) {
     	UL_INFO->harq_ind.harq_indication_body.number_of_harqs = 0;
 
     	UL_INFO->sr_ind.sr_indication_body.sr_pdu_list = (nfapi_sr_indication_pdu_t*)malloc(NB_UE_INST*sizeof(nfapi_sr_indication_pdu_t));
-    	UL_INFO->sr_ind.sr_indication_body.number_of_srs = 0;
-
-
-
+      UL_INFO->sr_ind.sr_indication_body.number_of_srs = 0;
+
+        UL_INFO->cqi_ind.cqi_pdu_list =  (nfapi_cqi_indication_pdu_t*)malloc(NB_UE_INST*sizeof(nfapi_cqi_indication_pdu_t));
+        UL_INFO->cqi_ind.cqi_raw_pdu_list = (nfapi_cqi_indication_raw_pdu_t*)malloc(NB_UE_INST*sizeof(nfapi_cqi_indication_raw_pdu_t));
+        UL_INFO->cqi_ind.number_of_cqis = 0;
+
+        if (pthread_mutex_lock(&phy_stub_ticking->mutex_single_thread) != 0) {
+          LOG_E( MAC, "[SCHED][UE] error locking mutex for ue_thread_id %d (mutex_single_thread)\n",ue_thread_id);
+          exit_fun("nothing to add");
+        }
+        memset(&phy_stub_ticking->num_single_thread[0],0,sizeof(int)*NB_THREAD_INST);
+        pthread_cond_broadcast(&phy_stub_ticking->cond_single_thread);
+
+        if (pthread_mutex_unlock(&phy_stub_ticking->mutex_single_thread) != 0) {
+          LOG_E( MAC, "[SCHED][UE] error unlocking mutex for ue_thread_id %d (mutex_single_thread)\n",ue_thread_id);
+          exit_fun("nothing to add");
+        }
+    }else{
+        if (pthread_mutex_lock(&phy_stub_ticking->mutex_single_thread) != 0) {
+          LOG_E( MAC, "[SCHED][UE] error locking mutex for ue_thread_id %d (mutex_single_thread)\n",ue_thread_id);
+           exit_fun("nothing to add");
+        }
+        while (phy_stub_ticking->num_single_thread[ue_thread_id] < 0) {
+          // most of the time, the thread is waiting here
+          LOG_D(MAC,"Waiting for single_thread (ue_thread_id %d)\n",ue_thread_id);
+          pthread_cond_wait( &phy_stub_ticking->cond_single_thread, &phy_stub_ticking->mutex_single_thread);
+        }
+        if (pthread_mutex_unlock(&phy_stub_ticking->mutex_single_thread) != 0) {
+          LOG_E( MAC, "[SCHED][UE] error unlocking mutex for ue_thread_id %d (mutex_single_thread)\n",ue_thread_id);
+          exit_fun("nothing to add");
+        }
+    }
 
-    for (Mod_id=0; Mod_id<NB_UE_INST; Mod_id++) {
-    	//LOG_D(MAC, "UE_phy_stub_single_thread_rxn_txnp4, NB_UE_INST:%d, Mod_id:%d \n", NB_UE_INST, Mod_id);
-    	UE = PHY_vars_UE_g[Mod_id][0];
+    //for (Mod_id=0; Mod_id<NB_UE_INST; Mod_id++) {
+    for (ue_index=0; ue_index < ue_num; ue_index++) {
+    ue_Mod_id = ue_thread_id + NB_THREAD_INST*ue_index;
+    UE = PHY_vars_UE_g[ue_Mod_id][0];
+    //LOG_D(MAC, "UE_phy_stub_single_thread_rxn_txnp4, NB_UE_INST:%d, Mod_id:%d \n", NB_UE_INST, Mod_id);
+    //UE = PHY_vars_UE_g[Mod_id][0];
     lte_subframe_t sf_type = subframe_select( &UE->frame_parms, proc->subframe_rx);
     if ((sf_type == SF_DL) ||
 	(UE->frame_parms.frame_type == FDD) ||
@@ -1059,12 +1142,12 @@ static void *UE_phy_stub_single_thread_rxn_txnp4(void *arg) {
 
       if (dl_config_req!=NULL && tx_request_pdu_list!=NULL){
     	  //if(dl_config_req!= NULL) {
-    	  dl_config_req_UE_MAC(dl_config_req, Mod_id);
+        dl_config_req_UE_MAC(dl_config_req, ue_Mod_id);
 
       }
 
       if (hi_dci0_req!=NULL && hi_dci0_req->hi_dci0_request_body.hi_dci0_pdu_list!=NULL){
-    	  hi_dci0_req_UE_MAC(hi_dci0_req, Mod_id);
+        hi_dci0_req_UE_MAC(hi_dci0_req, ue_Mod_id);
       }
 
       if(nfapi_mode!=3)
@@ -1078,7 +1161,7 @@ static void *UE_phy_stub_single_thread_rxn_txnp4(void *arg) {
 
     if (UE->mac_enabled==1) {
 
-      ret = ue_scheduler(UE->Mod_id,
+      ret = ue_scheduler(ue_Mod_id,
 			 proc->frame_rx,
 			 proc->subframe_rx,
 			 proc->frame_tx,
@@ -1104,34 +1187,37 @@ static void *UE_phy_stub_single_thread_rxn_txnp4(void *arg) {
 
     // We make the start of RA between consecutive UEs differ by 20 frames
 	//if ((UE_mac_inst[Mod_id].UE_mode[0] == PRACH  && Mod_id == 0) || (UE_mac_inst[Mod_id].UE_mode[0] == PRACH && Mod_id>0 && proc->frame_rx >= UE_mac_inst[Mod_id-1].ra_frame + 20) ) {
-	if (UE_mac_inst[Mod_id].UE_mode[0] == PRACH  && Mod_id == next_Mod_id && proc->frame_rx >= next_ra_frame) {
-
+	if (UE_mac_inst[ue_Mod_id].UE_mode[0] == PRACH  && ue_Mod_id == next_Mod_id) {
+          next_ra_frame++;
+          if(next_ra_frame > 200){
 	  // check if we have PRACH opportunity
 
-	  if (is_prach_subframe(&UE->frame_parms,proc->frame_tx, proc->subframe_tx) &&  UE_mac_inst[Mod_id].SI_Decoded == 1) {
+	  if (is_prach_subframe(&UE->frame_parms,proc->frame_tx, proc->subframe_tx) &&  UE_mac_inst[ue_Mod_id].SI_Decoded == 1) {
 
 	  // The one working strangely...
       //if (is_prach_subframe(&UE->frame_parms,proc->frame_tx, proc->subframe_tx && Mod_id == (module_id_t) init_ra_UE) ) {
 
-	    PRACH_RESOURCES_t *prach_resources = ue_get_rach(Mod_id, 0, proc->frame_tx, 0, proc->subframe_tx);
+	    PRACH_RESOURCES_t *prach_resources = ue_get_rach(ue_Mod_id, 0, proc->frame_tx, 0, proc->subframe_tx);
 	    if(prach_resources!=NULL ) {
-	    	UE_mac_inst[Mod_id].ra_frame = proc->frame_rx;
-	      LOG_D(MAC, "UE_phy_stub_thread_rxn_txnp4 before RACH, Mod_id: %d \n", Mod_id );
-	      fill_rach_indication_UE_MAC(Mod_id, proc->frame_tx ,proc->subframe_tx, UL_INFO, prach_resources->ra_PreambleIndex, prach_resources->ra_RNTI);
-	      Msg1_transmitted(Mod_id, 0, proc->frame_tx, 0);
-	      UE_mac_inst[Mod_id].UE_mode[0] = RA_RESPONSE;
-	      next_Mod_id = Mod_id + 1;
-	      next_ra_frame = (proc->frame_rx + 20)%1000;
+        UE_mac_inst[ue_Mod_id].ra_frame = proc->frame_rx;
+	      LOG_D(MAC, "UE_phy_stub_thread_rxn_txnp4 before RACH, Mod_id: %d frame %d subframe %d\n", ue_Mod_id ,proc->frame_tx, proc->subframe_tx);
+	      fill_rach_indication_UE_MAC(ue_Mod_id, proc->frame_tx ,proc->subframe_tx, UL_INFO, prach_resources->ra_PreambleIndex, prach_resources->ra_RNTI);
+	      Msg1_transmitted(ue_Mod_id, 0, proc->frame_tx, 0);
+	      UE_mac_inst[ue_Mod_id].UE_mode[0] = RA_RESPONSE;
+	      next_Mod_id = ue_Mod_id + 1;
+	      //next_ra_frame = (proc->frame_rx + 20)%1000;
+              next_ra_frame = 0;
 	    }
 
 	    //ue_prach_procedures(ue,proc,eNB_id,abstraction_flag,mode);
 	  }
+          }
 	} // mode is PRACH
 	// Substitute call to phy_procedures Tx with call to phy_stub functions in order to trigger
 	// UE Tx procedures directly at the MAC layer, based on the received ul_config requests from the vnf (eNB).
 	// Generate UL_indications which correspond to UL traffic.
 	if(ul_config_req!=NULL){ //&& UE_mac_inst[Mod_id].ul_config_req->ul_config_request_body.ul_config_pdu_list != NULL){
-		ul_config_req_UE_MAC(ul_config_req, timer_frame, timer_subframe, Mod_id);
+		ul_config_req_UE_MAC(ul_config_req, timer_frame, timer_subframe, ue_Mod_id);
 	}
       }
 
@@ -1140,6 +1226,19 @@ static void *UE_phy_stub_single_thread_rxn_txnp4(void *arg) {
 
     } //for (Mod_id=0; Mod_id<NB_UE_INST; Mod_id++)
 
+    phy_stub_ticking->num_single_thread[ue_thread_id] = -1;
+
+    // waiting for all UE's threads set phy_stub_ticking->num_single_thread[ue_thread_id] = -1.
+    if(ue_thread_id == 0){
+      do{
+        end_flag = 1;
+        for(uint16_t i = 0;i< NB_THREAD_INST;i++){
+          if(phy_stub_ticking->num_single_thread[i] == 0){
+             end_flag = 0;
+          }
+        }
+      }while(end_flag == 0);
+
 
     if (UL_INFO->crc_ind.crc_indication_body.number_of_crcs>0)
       {
@@ -1154,6 +1253,9 @@ static void *UE_phy_stub_single_thread_rxn_txnp4(void *arg) {
     	  //LOG_D(PHY,"UL_info->rx_ind.number_of_pdus:%d RX_IND:SFN/SF:%d\n", UL_info->rx_ind.rx_indication_body.number_of_pdus, NFAPI_SFNSF2DEC(UL_info->rx_ind.sfn_sf));
     	  //LOG_I(MAC, "ul_config_req_UE_MAC 2.3, SFN/SF of PNF counter:%d.%d, number_of_pdus: %d \n", timer_frame, timer_subframe, UL_INFO->rx_ind.rx_indication_body.number_of_pdus);
     	  oai_nfapi_rx_ind(&UL_INFO->rx_ind);
+          for(uint8_t num_pdu = 0;num_pdu < UL_INFO->rx_ind.rx_indication_body.number_of_pdus;num_pdu++){
+            free(UL_INFO->rx_ind.rx_indication_body.rx_pdu_list[num_pdu].data);
+          }
     	  //LOG_I(MAC, "ul_config_req_UE_MAC 2.31 \n");
     	  UL_INFO->rx_ind.rx_indication_body.number_of_pdus = 0;
       }
@@ -1190,14 +1292,19 @@ static void *UE_phy_stub_single_thread_rxn_txnp4(void *arg) {
     	  free(UL_INFO->sr_ind.sr_indication_body.sr_pdu_list);
     	  UL_INFO->sr_ind.sr_indication_body.sr_pdu_list = NULL;
       //}
-
+      free(UL_INFO->cqi_ind.cqi_pdu_list);
+      UL_INFO->cqi_ind.cqi_pdu_list = NULL;
+      free(UL_INFO->cqi_ind.cqi_raw_pdu_list);
+      UL_INFO->cqi_ind.cqi_raw_pdu_list = NULL;
       free(UL_INFO);
       UL_INFO = NULL;
 
       // De-allocate memory of nfapi requests copies before next subframe round
       if(dl_config_req!=NULL){
-    	  if(dl_config_req->vendor_extension)
-    		  free(dl_config_req->vendor_extension);
+        if(dl_config_req->vendor_extension!=NULL){
+            free(dl_config_req->vendor_extension);
+            dl_config_req->vendor_extension = NULL;
+          }
     	  if(dl_config_req->dl_config_request_body.dl_config_pdu_list!=NULL){
     		  free(dl_config_req->dl_config_request_body.dl_config_pdu_list);
     		  dl_config_req->dl_config_request_body.dl_config_pdu_list = NULL;
@@ -1227,7 +1334,7 @@ static void *UE_phy_stub_single_thread_rxn_txnp4(void *arg) {
     	  hi_dci0_req = NULL;
       }
 
-
+    }
 
   }
   // thread finished
@@ -1771,6 +1878,13 @@ void init_UE_single_thread_stub(int nb_inst) {
 	  AssertFatal(PHY_vars_UE_g!=NULL,"PHY_vars_UE_g is NULL\n");
 	  AssertFatal(PHY_vars_UE_g[i]!=NULL,"PHY_vars_UE_g[inst] is NULL\n");
 	  AssertFatal(PHY_vars_UE_g[i][0]!=NULL,"PHY_vars_UE_g[inst][0] is NULL\n");
+	  if(nfapi_mode == 3){
+#ifdef NAS_UE
+          MessageDef *message_p;
+          message_p = itti_alloc_new_message(TASK_NAS_UE, INITIALIZE_MESSAGE);
+         itti_send_msg_to_task (TASK_NAS_UE, i + NB_eNB_INST, message_p);
+#endif
+	  }
   }
   UE = PHY_vars_UE_g[0][0];
 
@@ -1785,19 +1899,22 @@ void init_UE_single_thread_stub(int nb_inst) {
   // In phy_stub_UE mode due to less heavy processing operations we don't need two threads
   //int nb_threads=RX_NB_TH;
   int nb_threads=1;
-  for (int i=0; i<nb_threads; i++) {
-    rtd = calloc(1, sizeof(struct rx_tx_thread_data));
-    if (rtd == NULL) abort();
-    rtd->UE = UE;
-    rtd->proc = &UE->proc.proc_rxtx[i];
-
-    pthread_mutex_init(&UE->proc.proc_rxtx[i].mutex_rxtx,NULL);
-    pthread_cond_init(&UE->proc.proc_rxtx[i].cond_rxtx,NULL);
-    UE->proc.proc_rxtx[i].sub_frame_start=i;
-    UE->proc.proc_rxtx[i].sub_frame_step=nb_threads;
-    printf("Init_UE_threads rtd %d proc %d nb_threads %d i %d\n",rtd->proc->sub_frame_start, UE->proc.proc_rxtx[i].sub_frame_start,nb_threads, i);
-    pthread_create(&UE->proc.proc_rxtx[i].pthread_rxtx, NULL, UE_phy_stub_single_thread_rxn_txnp4, rtd);
-
+  for(uint16_t ue_thread_id = 0;ue_thread_id < NB_THREAD_INST;ue_thread_id++){
+    UE = PHY_vars_UE_g[ue_thread_id][0];
+    for (int i=0; i<nb_threads; i++) {
+      rtd = calloc(1, sizeof(struct rx_tx_thread_data));
+      if (rtd == NULL) abort();
+      rtd->UE = UE;
+      rtd->proc = &UE->proc.proc_rxtx[i];
+      rtd->ue_thread_id = ue_thread_id;
+
+      pthread_mutex_init(&UE->proc.proc_rxtx[i].mutex_rxtx,NULL);
+      pthread_cond_init(&UE->proc.proc_rxtx[i].cond_rxtx,NULL);
+      UE->proc.proc_rxtx[i].sub_frame_start=i;
+      UE->proc.proc_rxtx[i].sub_frame_step=nb_threads;
+      printf("Init_UE_threads rtd %d proc %d nb_threads %d i %d\n",rtd->proc->sub_frame_start, UE->proc.proc_rxtx[i].sub_frame_start,nb_threads, i);
+      pthread_create(&UE->proc.proc_rxtx[i].pthread_rxtx, NULL, UE_phy_stub_single_thread_rxn_txnp4, rtd);
+    }
   }
   // Remove thread for UE_sync in phy_stub_UE mode.
   //pthread_create(&UE->proc.pthread_synch,NULL,UE_thread_synch,(void*)UE);
@@ -1862,7 +1979,7 @@ void init_UE_threads_stub(int inst) {
 #ifdef OPENAIR2
 void fill_ue_band_info(void) {
 
-  UE_EUTRA_Capability_t *UE_EUTRA_Capability = UE_rrc_inst[0].UECap->UE_EUTRA_Capability;
+  LTE_UE_EUTRA_Capability_t *UE_EUTRA_Capability = UE_rrc_inst[0].UECap->UE_EUTRA_Capability;
   int i,j;
 
   bands_to_scan.nbands = UE_EUTRA_Capability->rf_Parameters.supportedBandListEUTRA.list.count;
@@ -2067,8 +2184,11 @@ int init_timer_thread(void) {
   pthread_mutex_init(&UE->timer_mutex,NULL);
   pthread_cond_init(&UE->timer_cond,NULL);
   UE->instance_cnt_timer = -1;
+  memset(&phy_stub_ticking->num_single_thread[0],0,sizeof(int)*NB_THREAD_INST);
   pthread_mutex_init(&phy_stub_ticking->mutex_ticking,NULL);
   pthread_cond_init(&phy_stub_ticking->cond_ticking,NULL);
+  pthread_mutex_init(&phy_stub_ticking->mutex_single_thread,NULL);
+  pthread_cond_init(&phy_stub_ticking->cond_single_thread,NULL);
   pthread_create(&phy_stub_ticking->pthread_timer, NULL, &timer_thread, NULL);
   return 0;
 }
diff --git a/targets/RT/USER/lte-uesoftmodem.c b/targets/RT/USER/lte-uesoftmodem.c
index 3dce2b642638761974960d5b902c7bb11058e034..812ce2956814c74e996c25829aee70aac61764cd 100644
--- a/targets/RT/USER/lte-uesoftmodem.c
+++ b/targets/RT/USER/lte-uesoftmodem.c
@@ -19,7 +19,7 @@
  *      contact@openairinterface.org
  */
 
-/*! \file lte-enb.c
+/*! \file lte-uesoftmodem.c
  * \brief Top-level threads for eNodeB
  * \author R. Knopp, F. Kaltenberger, Navid Nikaein
  * \date 2012
@@ -34,9 +34,6 @@
 #define _GNU_SOURCE             /* See feature_test_macros(7) */
 #include <sched.h>
 
-
-#include "T.h"
-
 #include "rt_wrapper.h"
 
 
@@ -76,38 +73,36 @@
 #include "UTIL/MATH/oml.h"
 #include "common/utils/LOG/vcd_signal_dumper.h"
 #include "UTIL/OPT/opt.h"
-#include "enb_config.h"
-//#include "PHY/TOOLS/time_meas.h"
 
 #ifndef OPENAIR2
-#include "UTIL/OTG/otg_vars.h"
+  #include "UTIL/OTG/otg_vars.h"
 #endif
 
 #if defined(ENABLE_ITTI)
-#include "create_tasks.h"
+  #include "create_tasks.h"
 #endif
 
 #include "system.h"
 
 #ifdef XFORMS
-#include "PHY/TOOLS/lte_phy_scope.h"
-#include "stats.h"
+  #include "PHY/TOOLS/lte_phy_scope.h"
+  #include "stats.h"
 #endif
 #include "lte-softmodem.h"
 
-RAN_CONTEXT_t RC;
+
 
 /* temporary compilation wokaround (UE/eNB split */
 uint16_t sf_ahead;
 #ifdef XFORMS
-// current status is that every UE has a DL scope for a SINGLE eNB (eNB_id=0)
-// at eNB 0, an UL scope for every UE
-FD_lte_phy_scope_ue  *form_ue[NUMBER_OF_UE_MAX];
-FD_lte_phy_scope_enb *form_enb[MAX_NUM_CCs][NUMBER_OF_UE_MAX];
-FD_stats_form                  *form_stats=NULL,*form_stats_l2=NULL;
-char title[255];
-unsigned char                   scope_enb_num_ue = 2;
-static pthread_t                forms_thread; //xforms
+  // current status is that every UE has a DL scope for a SINGLE eNB (eNB_id=0)
+  // at eNB 0, an UL scope for every UE
+  FD_lte_phy_scope_ue  *form_ue[NUMBER_OF_UE_MAX];
+  FD_lte_phy_scope_enb *form_enb[MAX_NUM_CCs][NUMBER_OF_UE_MAX];
+  FD_stats_form                  *form_stats=NULL,*form_stats_l2=NULL;
+  char title[255];
+  unsigned char                   scope_enb_num_ue = 2;
+  static pthread_t                forms_thread; //xforms
 #endif //XFORMS
 
 pthread_cond_t nfapi_sync_cond;
@@ -115,9 +110,13 @@ pthread_mutex_t nfapi_sync_mutex;
 int nfapi_sync_var=-1; //!< protected by mutex \ref nfapi_sync_mutex
 
 uint8_t nfapi_mode = 0;
-
+#ifdef PDCP_USE_NETLINK
+#ifdef UESIM_EXPANSION
+uint16_t inst_pdcp_list[NUMBER_OF_UE_MAX];
+#endif
+#endif
 uint16_t sf_ahead=2;
-
+int tddflag;
 char *emul_iface;
 
 
@@ -129,19 +128,13 @@ int config_sync_var=-1;
 uint16_t runtime_phy_rx[29][6]; // SISO [MCS 0-28][RBs 0-5 : 6, 15, 25, 50, 75, 100]
 uint16_t runtime_phy_tx[29][6]; // SISO [MCS 0-28][RBs 0-5 : 6, 15, 25, 50, 75, 100]
 
-#if defined(ENABLE_ITTI)
-volatile int             start_eNB = 0;
-volatile int             start_UE = 0;
-#endif
 volatile int             oai_exit = 0;
 
 clock_source_t clock_source = internal;
-static int wait_for_sync = 0;
+
 
 unsigned int                    mmapped_dma=0;
-int                             single_thread_flag=1;
 
-static int8_t                     threequarter_fs=0;
 
 uint32_t                 downlink_frequency[MAX_NUM_CCs][4];
 int32_t                  uplink_frequency_offset[MAX_NUM_CCs][4];
@@ -175,11 +168,6 @@ double bw = 10.0e6;
 
 static int                      tx_max_power[MAX_NUM_CCs]; /* =  {0,0}*/;
 
-char   rf_config_file[1024];
-
-int chain_offset=0;
-int phy_test = 0;
-uint8_t usim_test = 0;
 
 uint8_t dci_Format = 0;
 uint8_t agregation_Level =0xFF;
@@ -193,62 +181,33 @@ char channels[128] = "0";
 int                      rx_input_level_dBm;
 
 #ifdef XFORMS
-extern int                      otg_enabled;
-static char                     do_forms=0;
-#else
-int                             otg_enabled;
+  extern int                      otg_enabled;
 #endif
 //int                             number_of_cards =   1;
 
 
 static LTE_DL_FRAME_PARMS      *frame_parms[MAX_NUM_CCs];
-uint32_t target_dl_mcs = 28; //maximum allowed mcs
-uint32_t target_ul_mcs = 20;
-uint32_t timing_advance = 0;
+
 uint8_t exit_missed_slots=1;
 uint64_t num_missed_slots=0; // counter for the number of missed slots
 
-
+/* prototypes from function implemented in lte-ue.c, probably should be elsewhere in a include
+   file */
 extern void init_UE_stub_single_thread(int nb_inst,int eMBMS_active, int uecap_xer_in, char *emul_iface);
 
-extern PHY_VARS_UE* init_ue_vars(LTE_DL_FRAME_PARMS *frame_parms,
-			  uint8_t UE_id,
-			  uint8_t abstraction_flag);
+extern PHY_VARS_UE *init_ue_vars(LTE_DL_FRAME_PARMS *frame_parms,
+                                 uint8_t UE_id,
+                                 uint8_t abstraction_flag);
 
+extern void get_uethreads_params(void);
 
 int transmission_mode=1;
 
-int emulate_rf = 0;
-int numerology = 0;
-char *parallel_config = NULL;
-char *worker_config = NULL;
-
-char* usrp_args=NULL;
-char* usrp_clksrc=NULL;
-
-static THREAD_STRUCT thread_struct;
-void set_parallel_conf(char *parallel_conf)
-{
-  if(strcmp(parallel_conf,"PARALLEL_SINGLE_THREAD")==0)           thread_struct.parallel_conf = PARALLEL_SINGLE_THREAD;
-  else if(strcmp(parallel_conf,"PARALLEL_RU_L1_SPLIT")==0)        thread_struct.parallel_conf = PARALLEL_RU_L1_SPLIT;
-  else if(strcmp(parallel_conf,"PARALLEL_RU_L1_TRX_SPLIT")==0)    thread_struct.parallel_conf = PARALLEL_RU_L1_TRX_SPLIT;
-  printf("[CONFIG] parallel conf is set to %d\n",thread_struct.parallel_conf);
-}
-void set_worker_conf(char *worker_conf)
-{
-  if(strcmp(worker_conf,"WORKER_DISABLE")==0)                     thread_struct.worker_conf = WORKER_DISABLE;
-  else if(strcmp(worker_conf,"WORKER_ENABLE")==0)                 thread_struct.worker_conf = WORKER_ENABLE;
-  printf("[CONFIG] worker conf is set to %d\n",thread_struct.worker_conf);
-}
-PARALLEL_CONF_t get_thread_parallel_conf(void)
-{
-  return thread_struct.parallel_conf;
-}
-WORKER_CONF_t get_thread_worker_conf(void)
-{
-  return thread_struct.worker_conf;
-}
 
+char *usrp_args=NULL;
+char *usrp_clksrc=NULL;
+
+THREAD_STRUCT thread_struct;
 /* struct for ethernet specific parameters given in eNB conf file */
 eth_params_t *eth_params;
 
@@ -260,7 +219,7 @@ extern char uecap_xer[1024];
 char uecap_xer_in=0;
 
 int oaisim_flag=0;
-threads_t threads= {-1,-1,-1,-1,-1,-1,-1};
+
 
 /* see file openair2/LAYER2/MAC/main.c for why abstraction_flag is needed
  * this is very hackish - find a proper solution
@@ -277,6 +236,7 @@ struct timespec max_diff_time = { .tv_sec = 0, .tv_nsec = 0 };
 
 struct timespec clock_difftime(struct timespec start, struct timespec end) {
   struct timespec temp;
+
   if ((end.tv_nsec-start.tv_nsec)<0) {
     temp.tv_sec = end.tv_sec-start.tv_sec-1;
     temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec;
@@ -284,6 +244,7 @@ struct timespec clock_difftime(struct timespec start, struct timespec end) {
     temp.tv_sec = end.tv_sec-start.tv_sec;
     temp.tv_nsec = end.tv_nsec-start.tv_nsec;
   }
+
   return temp;
 }
 
@@ -299,16 +260,21 @@ void update_difftimes(struct timespec start, struct timespec end) {
   struct timespec diff_time = { .tv_sec = 0, .tv_nsec = 0 };
   int             changed = 0;
   diff_time = clock_difftime(start, end);
+
   if ((min_diff_time.tv_nsec == 0) || (diff_time.tv_nsec < min_diff_time.tv_nsec)) {
     min_diff_time.tv_nsec = diff_time.tv_nsec;
     changed = 1;
   }
+
   if ((max_diff_time.tv_nsec == 0) || (diff_time.tv_nsec > max_diff_time.tv_nsec)) {
     max_diff_time.tv_nsec = diff_time.tv_nsec;
     changed = 1;
   }
+
 #if 1
+
   if (changed) print_difftimes();
+
 #endif
 }
 
@@ -321,7 +287,8 @@ unsigned int build_rfdc(int dcoff_i_rxfe, int dcoff_q_rxfe) {
   return (dcoff_i_rxfe + (dcoff_q_rxfe<<8));
 }
 
-#if !defined(ENABLE_ITTI)
+
+
 void signal_handler(int sig) {
   void *array[10];
   size_t size;
@@ -329,47 +296,38 @@ void signal_handler(int sig) {
   if (sig==SIGSEGV) {
     // get void*'s for all entries on the stack
     size = backtrace(array, 10);
-
     // print out all the frames to stderr
     fprintf(stderr, "Error: signal %d:\n", sig);
     backtrace_symbols_fd(array, size, 2);
     exit(-1);
   } else {
-    printf("trying to exit gracefully...\n");
-    oai_exit = 1;
+    char msg[64];
+    sprintf(msg,"Received linux signal %s...\n",strsignal(sig));
+    exit_function(__FILE__, __FUNCTION__, __LINE__,msg);
   }
 }
-#endif
-#define KNRM  "\x1B[0m"
-#define KRED  "\x1B[31m"
-#define KGRN  "\x1B[32m"
-#define KBLU  "\x1B[34m"
-#define RESET "\033[0m"
-
 
 
-void exit_function(const char* file, const char* function, const int line, const char* s)
-{
+void exit_function(const char *file, const char *function, const int line, const char *s) {
   int CC_id;
-
   logClean();
-  if (s != NULL) {
-    printf("%s:%d %s() Exiting OAI softmodem: %s\n",file,line, function, s);
-  }
-
+  printf("%s:%d %s() Exiting OAI softmodem: %s\n",file,line, function, ((s==NULL)?"":s));
   oai_exit = 1;
 
   for(CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
-     if (PHY_vars_UE_g)
+    if (PHY_vars_UE_g)
       if (PHY_vars_UE_g[0])
-         if (PHY_vars_UE_g[0][CC_id])
-	    if (PHY_vars_UE_g[0][CC_id]->rfdevice.trx_end_func)
-	        PHY_vars_UE_g[0][CC_id]->rfdevice.trx_end_func(&PHY_vars_UE_g[0][CC_id]->rfdevice);
-    }
+        if (PHY_vars_UE_g[0][CC_id])
+          if (PHY_vars_UE_g[0][CC_id]->rfdevice.trx_end_func)
+            PHY_vars_UE_g[0][CC_id]->rfdevice.trx_end_func(&PHY_vars_UE_g[0][CC_id]->rfdevice);
+  }
 
-    sleep(1); //allow lte-softmodem threads to exit first
+  sleep(1); //allow lte-softmodem threads to exit first
 #if defined(ENABLE_ITTI)
+
+  if(PHY_vars_UE_g != NULL )
     itti_terminate_tasks (TASK_UNKNOWN);
+
 #endif
   exit(1);
 }
@@ -377,24 +335,21 @@ void exit_function(const char* file, const char* function, const int line, const
 #ifdef XFORMS
 
 
-void reset_stats(FL_OBJECT *button, long arg)
-{
+void reset_stats(FL_OBJECT *button, long arg) {
   int i,j,k;
   PHY_VARS_eNB *phy_vars_eNB = RC.eNB[0][0];
 
   for (i=0; i<NUMBER_OF_UE_MAX; i++) {
     for (k=0; k<8; k++) { //harq_processes
       for (j=0; j<phy_vars_eNB->dlsch[i][0]->Mlimit; j++) {
-	phy_vars_eNB->UE_stats[i].dlsch_NAK[k][j]=0;
-	phy_vars_eNB->UE_stats[i].dlsch_ACK[k][j]=0;
-	phy_vars_eNB->UE_stats[i].dlsch_trials[k][j]=0;
+        phy_vars_eNB->UE_stats[i].dlsch_NAK[k][j]=0;
+        phy_vars_eNB->UE_stats[i].dlsch_ACK[k][j]=0;
+        phy_vars_eNB->UE_stats[i].dlsch_trials[k][j]=0;
       }
 
       phy_vars_eNB->UE_stats[i].dlsch_l2_errors[k]=0;
       phy_vars_eNB->UE_stats[i].ulsch_errors[k]=0;
       phy_vars_eNB->UE_stats[i].ulsch_consecutive_errors=0;
-
-
       phy_vars_eNB->UE_stats[i].dlsch_sliding_cnt=0;
       phy_vars_eNB->UE_stats[i].dlsch_NAK_round0=0;
       phy_vars_eNB->UE_stats[i].dlsch_mcs_offset=0;
@@ -408,196 +363,131 @@ static void *scope_thread(void *arg) {
   FILE *UE_stats, *eNB_stats;
 # endif
   struct sched_param sched_param;
-
-
   sched_param.sched_priority = sched_get_priority_min(SCHED_FIFO)+1;
   sched_setscheduler(0, SCHED_FIFO,&sched_param);
-
   printf("Scope thread has priority %d\n",sched_param.sched_priority);
-
 # ifdef ENABLE_XFORMS_WRITE_STATS
-
   UE_stats  = fopen("UE_stats.txt", "w");
-
 #endif
 
   while (!oai_exit) {
     //      dump_ue_stats (PHY_vars_UE_g[0][0], &PHY_vars_UE_g[0][0]->proc.proc_rxtx[0],stats_buffer, 0, mode,rx_input_level_dBm);
-      //fl_set_object_label(form_stats->stats_text, stats_buffer);
-      fl_clear_browser(form_stats->stats_text);
-      fl_add_browser_line(form_stats->stats_text, stats_buffer);
-
-      phy_scope_UE(form_ue[0],
-		   PHY_vars_UE_g[0][0],
-		   0,
-		   0,7);
+    //fl_set_object_label(form_stats->stats_text, stats_buffer);
+    fl_clear_browser(form_stats->stats_text);
+    fl_add_browser_line(form_stats->stats_text, stats_buffer);
+    phy_scope_UE(form_ue[0],
+                 PHY_vars_UE_g[0][0],
+                 0,
+                 0,7);
+    //  printf("%s",stats_buffer);
+  }
 
-  //  printf("%s",stats_buffer);
-    }
 # ifdef ENABLE_XFORMS_WRITE_STATS
 
-    if (UE_stats) {
-      rewind (UE_stats);
-      fwrite (stats_buffer, 1, len, UE_stats);
-      fclose (UE_stats);
-    }
+  if (UE_stats) {
+    rewind (UE_stats);
+    fwrite (stats_buffer, 1, len, UE_stats);
+    fclose (UE_stats);
+  }
 
 # endif
-  
-  pthread_exit((void*)arg);
+  pthread_exit((void *)arg);
 }
 #endif
 
 
 
-#if defined(ENABLE_ITTI)
-void *l2l1_task(void *arg) {
-  MessageDef *message_p = NULL;
-  int         result;
-
-  itti_set_task_real_time(TASK_L2L1);
-  itti_mark_task_ready(TASK_L2L1);
-
-
-  do {
-    // Wait for a message
-    itti_receive_msg (TASK_L2L1, &message_p);
-
-    switch (ITTI_MSG_ID(message_p)) {
-    case TERMINATE_MESSAGE:
-      oai_exit=1;
-      itti_exit_task ();
-      break;
-
-    case ACTIVATE_MESSAGE:
-      start_UE = 1;
-      break;
-
-    case DEACTIVATE_MESSAGE:
-      start_UE = 0;
-      break;
-
-    case MESSAGE_TEST:
-      LOG_I(SIM, "Received %s\n", ITTI_MSG_NAME(message_p));
-      break;
-
-    default:
-      LOG_E(SIM, "Received unexpected message %s\n", ITTI_MSG_NAME(message_p));
-      break;
-    }
-
-    result = itti_free (ITTI_MSG_ORIGIN_ID(message_p), message_p);
-    AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
-  } while(!oai_exit);
-
-  return NULL;
-}
-#endif
-
 extern int16_t dlsch_demod_shift;
 
-static void get_options(unsigned int *start_msc) {
+static void get_options(void) {
   int CC_id;
-  int tddflag, nonbiotflag;
+  int tddflag;
   char *loopfile=NULL;
   int dumpframe;
-  uint32_t online_log_messages;
-  uint32_t glog_level;
-  uint32_t start_telnetsrv;
-
-  paramdef_t cmdline_params[] =CMDLINE_PARAMS_DESC ;
-  paramdef_t cmdline_logparams[] =CMDLINE_LOGPARAMS_DESC ;
-
+  int timingadv;
   set_default_frame_parms(frame_parms);
   CONFIG_SETRTFLAG(CONFIG_NOEXITONHELP);
-  config_process_cmdline( cmdline_params,sizeof(cmdline_params)/sizeof(paramdef_t),NULL); 
-
-  if (strlen(in_path) > 0) {
-      opt_type = OPT_PCAP;
-      opt_enabled=1;
-      printf("Enabling OPT for PCAP  with the following file %s \n",in_path);
-  }
-  if (strlen(in_ip) > 0) {
-      opt_enabled=1;
-      opt_type = OPT_WIRESHARK;
-      printf("Enabling OPT for wireshark for local interface");
-  }
-
-  config_process_cmdline( cmdline_logparams,sizeof(cmdline_logparams)/sizeof(paramdef_t),NULL);
-  if(config_isparamset(cmdline_logparams,CMDLINE_ONLINELOG_IDX)) {
-      set_glog_onlinelog(online_log_messages);
-  }
-  if(config_isparamset(cmdline_logparams,CMDLINE_GLOGLEVEL_IDX)) {
-      set_glog(glog_level);
-  }
-  if (start_telnetsrv) {
-     load_module_shlib("telnetsrv",NULL,0,NULL);
-  }
-
+  /* unknown parameters on command line will be checked in main
+     after all init have been performed                         */
+  get_common_options();
+  get_uethreads_params();
   paramdef_t cmdline_uemodeparams[] =CMDLINE_UEMODEPARAMS_DESC;
   paramdef_t cmdline_ueparams[] =CMDLINE_UEPARAMS_DESC;
-
-
   config_process_cmdline( cmdline_uemodeparams,sizeof(cmdline_uemodeparams)/sizeof(paramdef_t),NULL);
-  CONFIG_CLEARRTFLAG(CONFIG_NOEXITONHELP);
   config_process_cmdline( cmdline_ueparams,sizeof(cmdline_ueparams)/sizeof(paramdef_t),NULL);
+
   if (loopfile != NULL) {
-      printf("Input file for hardware emulation: %s",loopfile);
-      mode=loop_through_memory;
-      input_fd = fopen(loopfile,"r");
-      AssertFatal(input_fd != NULL,"Please provide a valid input file\n");
+    printf("Input file for hardware emulation: %s",loopfile);
+    mode=loop_through_memory;
+    input_fd = fopen(loopfile,"r");
+    AssertFatal(input_fd != NULL,"Please provide a valid input file\n");
   }
 
+  get_softmodem_params()->hw_timing_advance = timingadv;
+
   if ( (cmdline_uemodeparams[CMDLINE_CALIBUERX_IDX].paramflags &  PARAMFLAG_PARAMSET) != 0) mode = rx_calib_ue;
+
   if ( (cmdline_uemodeparams[CMDLINE_CALIBUERXMED_IDX].paramflags &  PARAMFLAG_PARAMSET) != 0) mode = rx_calib_ue_med;
+
   if ( (cmdline_uemodeparams[CMDLINE_CALIBUERXBYP_IDX].paramflags &  PARAMFLAG_PARAMSET) != 0) mode = rx_calib_ue_byp;
+
   if (cmdline_uemodeparams[CMDLINE_DEBUGUEPRACH_IDX].uptr)
-      if ( *(cmdline_uemodeparams[CMDLINE_DEBUGUEPRACH_IDX].uptr) > 0) mode = debug_prach;
+    if ( *(cmdline_uemodeparams[CMDLINE_DEBUGUEPRACH_IDX].uptr) > 0) mode = debug_prach;
+
   if (cmdline_uemodeparams[CMDLINE_NOL2CONNECT_IDX].uptr)
-      if ( *(cmdline_uemodeparams[CMDLINE_NOL2CONNECT_IDX].uptr) > 0)  mode = no_L2_connect;
-  if (cmdline_uemodeparams[CMDLINE_CALIBPRACHTX_IDX].uptr) 
-      if ( *(cmdline_uemodeparams[CMDLINE_CALIBPRACHTX_IDX].uptr) > 0) mode = calib_prach_tx; 
+    if ( *(cmdline_uemodeparams[CMDLINE_NOL2CONNECT_IDX].uptr) > 0)  mode = no_L2_connect;
+
+  if (cmdline_uemodeparams[CMDLINE_CALIBPRACHTX_IDX].uptr)
+    if ( *(cmdline_uemodeparams[CMDLINE_CALIBPRACHTX_IDX].uptr) > 0) mode = calib_prach_tx;
+
   if (dumpframe  > 0)  mode = rx_dump_frame;
-  
+
   for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
     frame_parms[CC_id]->dl_CarrierFreq = downlink_frequency[0][0];
   }
+
   UE_scan=0;
    
-    if (tddflag > 0) {
-     for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) 
-    	 frame_parms[CC_id]->frame_type = TDD;
+  if (tddflag > 0) {
+    for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
+      frame_parms[CC_id]->frame_type = TDD;
+      frame_parms[CC_id]->tdd_config = tddflag;
+    }
   }
 
   if (frame_parms[0]->N_RB_DL !=0) {
-      if ( frame_parms[0]->N_RB_DL < 6 ) {
-    	 frame_parms[0]->N_RB_DL = 6;
-    	 printf ( "%i: Invalid number of ressource blocks, adjusted to 6\n",frame_parms[0]->N_RB_DL);
-      }
-      if ( frame_parms[0]->N_RB_DL > 100 ) {
-    	 frame_parms[0]->N_RB_DL = 100;
-    	 printf ( "%i: Invalid number of ressource blocks, adjusted to 100\n",frame_parms[0]->N_RB_DL);
-      }
-      if ( frame_parms[0]->N_RB_DL > 50 && frame_parms[0]->N_RB_DL < 100 ) {
-    	 frame_parms[0]->N_RB_DL = 50;
-    	 printf ( "%i: Invalid number of ressource blocks, adjusted to 50\n",frame_parms[0]->N_RB_DL);
-      }
-      if ( frame_parms[0]->N_RB_DL > 25 && frame_parms[0]->N_RB_DL < 50 ) {
-    	 frame_parms[0]->N_RB_DL = 25;
-    	 printf ( "%i: Invalid number of ressource blocks, adjusted to 25\n",frame_parms[0]->N_RB_DL);
-      }
-      UE_scan = 0;
-      frame_parms[0]->N_RB_UL=frame_parms[0]->N_RB_DL;
-      for (CC_id=1; CC_id<MAX_NUM_CCs; CC_id++) {
-    	  frame_parms[CC_id]->N_RB_DL=frame_parms[0]->N_RB_DL;
-    	  frame_parms[CC_id]->N_RB_UL=frame_parms[0]->N_RB_UL;
-      }
-  }
+    if ( frame_parms[0]->N_RB_DL < 6 ) {
+      frame_parms[0]->N_RB_DL = 6;
+      printf ( "%i: Invalid number of ressource blocks, adjusted to 6\n",frame_parms[0]->N_RB_DL);
+    }
 
+    if ( frame_parms[0]->N_RB_DL > 100 ) {
+      frame_parms[0]->N_RB_DL = 100;
+      printf ( "%i: Invalid number of ressource blocks, adjusted to 100\n",frame_parms[0]->N_RB_DL);
+    }
 
-  for (CC_id=1;CC_id<MAX_NUM_CCs;CC_id++) {
-    	rx_gain[0][CC_id] = rx_gain[0][0];
-    	tx_gain[0][CC_id] = tx_gain[0][0];
+    if ( frame_parms[0]->N_RB_DL > 50 && frame_parms[0]->N_RB_DL < 100 ) {
+      frame_parms[0]->N_RB_DL = 50;
+      printf ( "%i: Invalid number of ressource blocks, adjusted to 50\n",frame_parms[0]->N_RB_DL);
+    }
+
+    if ( frame_parms[0]->N_RB_DL > 25 && frame_parms[0]->N_RB_DL < 50 ) {
+      frame_parms[0]->N_RB_DL = 25;
+      printf ( "%i: Invalid number of ressource blocks, adjusted to 25\n",frame_parms[0]->N_RB_DL);
+    }
+
+    UE_scan = 0;
+    frame_parms[0]->N_RB_UL=frame_parms[0]->N_RB_DL;
+
+    for (CC_id=1; CC_id<MAX_NUM_CCs; CC_id++) {
+      frame_parms[CC_id]->N_RB_DL=frame_parms[0]->N_RB_DL;
+      frame_parms[CC_id]->N_RB_UL=frame_parms[0]->N_RB_UL;
+    }
+  }
+
+  for (CC_id=1; CC_id<MAX_NUM_CCs; CC_id++) {
+    rx_gain[0][CC_id] = rx_gain[0][0];
+    tx_gain[0][CC_id] = tx_gain[0][0];
   }
 
   /*
@@ -607,19 +497,16 @@ static void get_options(unsigned int *start_msc) {
     sprintf(uecap_xer,"%stargets/PROJECTS/GENERIC-LTE-EPC/CONF/UE_config.xml",getenv("OPENAIR_HOME"));
     printf("%s\n",uecap_xer);
     if(nfapi_mode!=3)
-    	uecap_xer_in=1;
-	} *//* UE with config file  */
-  if(parallel_config != NULL) set_parallel_conf(parallel_config);
-  if(worker_config != NULL)   set_worker_conf(worker_config);
+      uecap_xer_in=1;
+  } *//* UE with config file  */
 }
 
 
 void set_default_frame_parms(LTE_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]) {
-
   int CC_id;
 
   for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
-    frame_parms[CC_id] = (LTE_DL_FRAME_PARMS*) malloc(sizeof(LTE_DL_FRAME_PARMS));
+    frame_parms[CC_id] = (LTE_DL_FRAME_PARMS *) malloc(sizeof(LTE_DL_FRAME_PARMS));
     /* Set some default values that may be overwritten while reading options */
     frame_parms[CC_id]->frame_type          = FDD;
     frame_parms[CC_id]->tdd_config          = 3;
@@ -633,9 +520,7 @@ void set_default_frame_parms(LTE_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]) {
     frame_parms[CC_id]->nb_antenna_ports_eNB  = 1;
     frame_parms[CC_id]->nb_antennas_tx      = 1;
     frame_parms[CC_id]->nb_antennas_rx      = 1;
-
     frame_parms[CC_id]->nushift             = 0;
-
     frame_parms[CC_id]->phich_config_common.phich_resource = oneSixth;
     frame_parms[CC_id]->phich_config_common.phich_duration = normal;
     // UL RS Config
@@ -643,45 +528,38 @@ void set_default_frame_parms(LTE_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]) {
     frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.groupHoppingEnabled = 0;
     frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled = 0;
     frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH = 0;
-
     frame_parms[CC_id]->prach_config_common.rootSequenceIndex=22;
     frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig=1;
     frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.prach_ConfigIndex=0;
     frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.highSpeedFlag=0;
     frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.prach_FreqOffset=0;
-
     downlink_frequency[CC_id][0] = DEFAULT_DLF; // Use float to avoid issue with frequency over 2^31.
     downlink_frequency[CC_id][1] = downlink_frequency[CC_id][0];
     downlink_frequency[CC_id][2] = downlink_frequency[CC_id][0];
     downlink_frequency[CC_id][3] = downlink_frequency[CC_id][0];
-
     frame_parms[CC_id]->dl_CarrierFreq=downlink_frequency[CC_id][0];
-
   }
-
 }
 
 void init_openair0(LTE_DL_FRAME_PARMS *frame_parms,int rxgain) {
-
   int card;
   int i;
 
   for (card=0; card<MAX_CARDS; card++) {
-
     openair0_cfg[card].mmapped_dma=mmapped_dma;
     openair0_cfg[card].configFilename = NULL;
 
     if(frame_parms->N_RB_DL == 100) {
       if (frame_parms->threequarter_fs) {
-	openair0_cfg[card].sample_rate=23.04e6;
-	openair0_cfg[card].samples_per_frame = 230400;
-	openair0_cfg[card].tx_bw = 10e6;
-	openair0_cfg[card].rx_bw = 10e6;
+        openair0_cfg[card].sample_rate=23.04e6;
+        openair0_cfg[card].samples_per_frame = 230400;
+        openair0_cfg[card].tx_bw = 10e6;
+        openair0_cfg[card].rx_bw = 10e6;
       } else {
-	openair0_cfg[card].sample_rate=30.72e6;
-	openair0_cfg[card].samples_per_frame = 307200;
-	openair0_cfg[card].tx_bw = 10e6;
-	openair0_cfg[card].rx_bw = 10e6;
+        openair0_cfg[card].sample_rate=30.72e6;
+        openair0_cfg[card].samples_per_frame = 307200;
+        openair0_cfg[card].tx_bw = 10e6;
+        openair0_cfg[card].rx_bw = 10e6;
       }
     } else if(frame_parms->N_RB_DL == 50) {
       openair0_cfg[card].sample_rate=15.36e6;
@@ -700,63 +578,54 @@ void init_openair0(LTE_DL_FRAME_PARMS *frame_parms,int rxgain) {
       openair0_cfg[card].rx_bw = 1.5e6;
     }
 
-
-
-
     if (frame_parms->frame_type==TDD)
       openair0_cfg[card].duplex_mode = duplex_mode_TDD;
     else //FDD
       openair0_cfg[card].duplex_mode = duplex_mode_FDD;
 
     openair0_cfg[card].Mod_id = 0;
-
     openair0_cfg[card].num_rb_dl=frame_parms->N_RB_DL;
-
     openair0_cfg[card].clock_source = clock_source;
-
-
     openair0_cfg[card].tx_num_channels=min(2,frame_parms->nb_antennas_tx);
     openair0_cfg[card].rx_num_channels=min(2,frame_parms->nb_antennas_rx);
 
     for (i=0; i<4; i++) {
-
       if (i<openair0_cfg[card].tx_num_channels)
-	openair0_cfg[card].tx_freq[i] = downlink_frequency[0][i]+uplink_frequency_offset[0][i];
+        openair0_cfg[card].tx_freq[i] = downlink_frequency[0][i]+uplink_frequency_offset[0][i];
       else
-	openair0_cfg[card].tx_freq[i]=0.0;
+        openair0_cfg[card].tx_freq[i]=0.0;
 
       if (i<openair0_cfg[card].rx_num_channels)
-	openair0_cfg[card].rx_freq[i] = downlink_frequency[0][i];
+        openair0_cfg[card].rx_freq[i] = downlink_frequency[0][i];
       else
-	openair0_cfg[card].rx_freq[i]=0.0;
+        openair0_cfg[card].rx_freq[i]=0.0;
 
       openair0_cfg[card].autocal[i] = 1;
       openair0_cfg[card].tx_gain[i] = tx_gain[0][i];
       openair0_cfg[card].rx_gain[i] = rxgain - rx_gain_off;
-     
-
-      openair0_cfg[card].configFilename = rf_config_file;
+      openair0_cfg[card].configFilename = get_softmodem_params()->rf_config_file;
       printf("Card %d, channel %d, Setting tx_gain %f, rx_gain %f, tx_freq %f, rx_freq %f\n",
-	     card,i, openair0_cfg[card].tx_gain[i],
-	     openair0_cfg[card].rx_gain[i],
-	     openair0_cfg[card].tx_freq[i],
-	     openair0_cfg[card].rx_freq[i]);
+             card,i, openair0_cfg[card].tx_gain[i],
+             openair0_cfg[card].rx_gain[i],
+             openair0_cfg[card].tx_freq[i],
+             openair0_cfg[card].rx_freq[i]);
     }
 
     if (usrp_args) openair0_cfg[card].sdr_addrs = usrp_args;
+
     if (usrp_clksrc) {
       if (strcmp(usrp_clksrc, "internal") == 0) {
-	openair0_cfg[card].clock_source = internal;
-	LOG_D(PHY, "USRP clock source set as internal\n");
+        openair0_cfg[card].clock_source = internal;
+        LOG_D(PHY, "USRP clock source set as internal\n");
       } else if (strcmp(usrp_clksrc, "external") == 0) {
-	openair0_cfg[card].clock_source = external;
-	LOG_D(PHY, "USRP clock source set as external\n");
+        openair0_cfg[card].clock_source = external;
+        LOG_D(PHY, "USRP clock source set as external\n");
       } else if (strcmp(usrp_clksrc, "gpsdo") == 0) {
-	openair0_cfg[card].clock_source = gpsdo;
-	LOG_D(PHY, "USRP clock source set as gpsdo\n");
+        openair0_cfg[card].clock_source = gpsdo;
+        LOG_D(PHY, "USRP clock source set as gpsdo\n");
       } else {
-	openair0_cfg[card].clock_source = internal;
-	LOG_I(PHY, "USRP clock source unknown ('%s'). defaulting to internal\n", usrp_clksrc);
+        openair0_cfg[card].clock_source = internal;
+        LOG_I(PHY, "USRP clock source unknown ('%s'). defaulting to internal\n", usrp_clksrc);
       }
     } else {
       openair0_cfg[card].clock_source = internal;
@@ -772,8 +641,7 @@ void init_openair0(LTE_DL_FRAME_PARMS *frame_parms,int rxgain) {
 /*
  * helper function to terminate a certain ITTI task
  */
-void terminate_task(task_id_t task_id, module_id_t mod_id)
-{
+void terminate_task(task_id_t task_id, module_id_t mod_id) {
   LOG_I(ENB_APP, "sending TERMINATE_MESSAGE to task %s (%d)\n", itti_get_task_name(task_id), task_id);
   MessageDef *msg;
   msg = itti_alloc_new_message (ENB_APP, TERMINATE_MESSAGE);
@@ -787,7 +655,6 @@ void terminate_task(task_id_t task_id, module_id_t mod_id)
 
 
 static inline void wait_nfapi_init(char *thread_name) {
-
   printf( "waiting for NFAPI PNF connection and population of global structure (%s)\n",thread_name);
   pthread_mutex_lock( &nfapi_sync_mutex );
 
@@ -795,70 +662,74 @@ static inline void wait_nfapi_init(char *thread_name) {
     pthread_cond_wait( &nfapi_sync_cond, &nfapi_sync_mutex );
 
   pthread_mutex_unlock(&nfapi_sync_mutex);
-
   printf( "NFAPI: got sync (%s)\n", thread_name);
 }
 
-int stop_L1L2(module_id_t enb_id)
-{
-	return 0;
+int stop_L1L2(module_id_t enb_id) {
+  return 0;
 }
 
 
-int restart_L1L2(module_id_t enb_id)
-{
-	return 0;
+int restart_L1L2(module_id_t enb_id) {
+  return 0;
 }
 
-int main( int argc, char **argv )
-{
+int main( int argc, char **argv ) {
 #if defined (XFORMS)
   void *status;
 #endif
-
   int CC_id;
   uint8_t  abstraction_flag=0;
-  unsigned int start_msc=0;
-
+#ifdef PDCP_USE_NETLINK
+#ifdef UESIM_EXPANSION
+  memset(inst_pdcp_list, 0, sizeof(inst_pdcp_list));
+#endif
+#endif
   // Default value for the number of UEs. It will hold,
   // if not changed from the command line option --num-ues
   NB_UE_INST=1;
-
+  NB_THREAD_INST=1;
 #if defined (XFORMS)
   int ret;
 #endif
+  configmodule_interface_t *config_mod;
 
   start_background_system();
-  if ( load_configmodule(argc,argv) == NULL) {
-    exit_fun("[SOFTMODEM] Error, configuration module init failed\n");
-  } 
-      
 
+  config_mod = load_configmodule(argc, argv, CONFIG_ENABLECMDLINEONLY);
+
+  if (config_mod == NULL) {
+    exit_fun("[SOFTMODEM] Error, configuration module init failed\n");
+  }
 
   mode = normal_txrx;
   memset(&openair0_cfg[0],0,sizeof(openair0_config_t)*MAX_CARDS);
-
-
   set_latency_target();
-
   logInit();
-
   printf("Reading in command-line options\n");
 
-  for (int i=0;i<MAX_NUM_CCs;i++) tx_max_power[i]=23; 
-  get_options (&start_msc);
-
-printf("~~~~~~~~~~~~~~~~~~~~successfully get the parallel config[%d], worker config [%d] \n", get_thread_parallel_conf(), get_thread_worker_conf());
-
+  for (int i=0; i<MAX_NUM_CCs; i++) tx_max_power[i]=23;
 
+  get_options ();
   printf("Running with %d UE instances\n",NB_UE_INST);
-  if (NB_UE_INST > 1 && simL1flag != 1) {
+
+  if (NB_UE_INST > 1 && simL1flag != 1 && nfapi_mode != 3) {
     printf("Running with more than 1 UE instance and simL1 is not active, this will result in undefined behaviour for now, exiting.\n");
     abort();
   }
 
   printf("NFAPI_MODE value: %d \n", nfapi_mode);
 
+  // Checking option of nums_ue_thread.
+  if(NB_THREAD_INST < 1){
+    printf("Running with 0 UE rxtx thread, exiting.\n");
+    abort();
+  }
+  // Checking option's relation between nums_ue_thread and num-ues
+  if(NB_UE_INST <NB_THREAD_INST ){
+    printf("Number of UEs < number of UE rxtx threads, exiting.\n");
+    abort();
+  }
   // Not sure if the following is needed here
   /*if (CONFIG_ISFLAGSET(CONFIG_ABORT)) {
       if (UE_flag == 0) {
@@ -875,36 +746,23 @@ printf("~~~~~~~~~~~~~~~~~~~~successfully get the parallel config[%d], worker con
 #if T_TRACER
   T_Config_Init();
 #endif
-
-
-
   //randominit (0);
   set_taus_seed (0);
-
   cpuf=get_cpu_freq_GHz();
-
   pthread_cond_init(&sync_cond,NULL);
   pthread_mutex_init(&sync_mutex, NULL);
-
 #if defined(ENABLE_ITTI)
-
-
-
   printf("ITTI init\n");
   itti_init(TASK_MAX, THREAD_MAX, MESSAGES_ID_MAX, tasks_info, messages_info);
 
   // initialize mscgen log after ITTI
-  if (start_msc) {
-     load_module_shlib("msc",NULL,0,&msc_interface);
+  if (get_softmodem_params()->start_msc) {
+    load_module_shlib("msc",NULL,0,&msc_interface);
   }
+
   MSC_INIT(MSC_E_UTRAN, THREAD_MAX+TASK_MAX);
 #endif
-
-  if (opt_type != OPT_NONE) {
-    if (init_opt(in_path, in_ip) == -1)
-      LOG_E(OPT,"failed to run OPT \n");
-  }
-
+  init_opt();
 #ifdef PDCP_USE_NETLINK
   printf("PDCP netlink\n");
   netlink_init();
@@ -912,129 +770,118 @@ printf("~~~~~~~~~~~~~~~~~~~~successfully get the parallel config[%d], worker con
   pdcp_netlink_init();
 #endif
 #endif
-
-//TTN for D2D
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  //TTN for D2D
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   printf ("RRC control socket\n");
   rrc_control_socket_init();
   printf ("PDCP PC5S socket\n");
   pdcp_pc5_socket_init();
 #endif
-
-#if !defined(ENABLE_ITTI)
   // to make a graceful exit when ctrl-c is pressed
   signal(SIGSEGV, signal_handler);
   signal(SIGINT, signal_handler);
-#endif
-
-
+  signal(SIGTERM, signal_handler);
+  signal(SIGABRT, signal_handler);
   check_clock();
-
 #ifndef PACKAGE_VERSION
 #  define PACKAGE_VERSION "UNKNOWN-EXPERIMENTAL"
 #endif
-
   LOG_I(HW, "Version: %s\n", PACKAGE_VERSION);
 
   // init the parameters
   for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
-      frame_parms[CC_id]->nb_antennas_tx     = nb_antenna_tx;
-      frame_parms[CC_id]->nb_antennas_rx     = nb_antenna_rx;
-      frame_parms[CC_id]->nb_antenna_ports_eNB = 1; //initial value overwritten by initial sync later
+    frame_parms[CC_id]->nb_antennas_tx     = nb_antenna_tx;
+    frame_parms[CC_id]->nb_antennas_rx     = nb_antenna_rx;
+    frame_parms[CC_id]->nb_antenna_ports_eNB = 1; //initial value overwritten by initial sync later
   }
 
+  NB_INST=1;
 
+  if(nfapi_mode == 3) {
+    PHY_vars_UE_g = malloc(sizeof(PHY_VARS_UE **)*NB_UE_INST);
 
-  NB_INST=1;
-  if(nfapi_mode == 3){
-	  PHY_vars_UE_g = malloc(sizeof(PHY_VARS_UE**)*NB_UE_INST);
-	  	  for (int i=0; i<NB_UE_INST; i++) {
-	  		  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
-	  			PHY_vars_UE_g[i] = malloc(sizeof(PHY_VARS_UE*)*MAX_NUM_CCs);
-	  			PHY_vars_UE_g[i][CC_id] = init_ue_vars(frame_parms[CC_id], i,abstraction_flag);
-
-
-	  			if (phy_test==1)
-	  				PHY_vars_UE_g[i][CC_id]->mac_enabled = 0;
-	  			else
-	  				PHY_vars_UE_g[i][CC_id]->mac_enabled = 1;
-	  		}
-	  	  }
-  }
-  else init_openair0(frame_parms[0],(int)rx_gain[0][0]);
+    for (int i=0; i<NB_UE_INST; i++) {
+      for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
+        PHY_vars_UE_g[i] = malloc(sizeof(PHY_VARS_UE *)*MAX_NUM_CCs);
+        PHY_vars_UE_g[i][CC_id] = init_ue_vars(frame_parms[CC_id], i,abstraction_flag);
 
+        if (get_softmodem_params()->phy_test==1)
+          PHY_vars_UE_g[i][CC_id]->mac_enabled = 0;
+        else
+          PHY_vars_UE_g[i][CC_id]->mac_enabled = 1;
+      }
+    }
+  } else init_openair0(frame_parms[0],(int)rx_gain[0][0]);
 
   if (simL1flag==1) {
-    AssertFatal(NULL!=load_configmodule(argc,argv),
-                "[SOFTMODEM] Error, configuration module init failed\n");
-
     RCConfig_sim();
   }
 
+// source code written in below moved to later to avoid keeping waiting for nfapi_sync_cond in wait_nfapi_init.
+/*
   // start the main UE threads
   int eMBMS_active = 0;
 
-  if (nfapi_mode==3) // UE-STUB-PNF
-  {
-      config_sync_var=0;
-      wait_nfapi_init("main?");
-      //Panos: Temporarily we will be using single set of threads for multiple UEs.
-      //init_UE_stub(1,eMBMS_active,uecap_xer_in,emul_iface);
-      init_UE_stub_single_thread(NB_UE_INST,eMBMS_active,uecap_xer_in,emul_iface);
-  }
-  else {
-      init_UE(NB_UE_INST,eMBMS_active,uecap_xer_in,0,phy_test,UE_scan,UE_scan_carrier,mode,(int)rx_gain[0][0],tx_max_power[0],
-              frame_parms[0]);
+  if (nfapi_mode==3) { // UE-STUB-PNF
+    config_sync_var=0;
+    wait_nfapi_init("main?");
+    //Panos: Temporarily we will be using single set of threads for multiple UEs.
+    //init_UE_stub(1,eMBMS_active,uecap_xer_in,emul_iface);
+    init_UE_stub_single_thread(NB_UE_INST,eMBMS_active,uecap_xer_in,emul_iface);
+  } else {
+    init_UE(NB_UE_INST,eMBMS_active,uecap_xer_in,0,get_softmodem_params()->phy_test,UE_scan,UE_scan_carrier,mode,(int)rx_gain[0][0],tx_max_power[0],
+            frame_parms[0]);
   }
 
-
-  if (phy_test==0) {
+  if (get_softmodem_params()->phy_test==0) {
     printf("Filling UE band info\n");
     fill_ue_band_info();
     dl_phy_sync_success (0, 0, 0, 1);
   }
 
-  if (nfapi_mode!=3){
-      number_of_cards = 1;
-      for(CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
-              PHY_vars_UE_g[0][CC_id]->rf_map.card=0;
-              PHY_vars_UE_g[0][CC_id]->rf_map.chain=CC_id+chain_offset;
-      }
-  }
+  if (nfapi_mode!=3) {
+    number_of_cards = 1;
 
+    for(CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
+      PHY_vars_UE_g[0][CC_id]->rf_map.card=0;
+      PHY_vars_UE_g[0][CC_id]->rf_map.chain=CC_id+(get_softmodem_params()->chain_offset);
+    }
+  }
+*/
   
   cpuf=get_cpu_freq_GHz();
-  
-  
-  
 #ifndef DEADLINE_SCHEDULER
-  
   printf("NO deadline scheduler\n");
   /* Currently we set affinity for UHD to CPU 0 for eNB/UE and only if number of CPUS >2 */
-  
   cpu_set_t cpuset;
   int s;
   char cpu_affinity[1024];
   CPU_ZERO(&cpuset);
 #ifdef CPU_AFFINITY
+
   if (get_nprocs() > 2) {
     CPU_SET(0, &cpuset);
     s = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
+
     if (s != 0) {
       perror( "pthread_setaffinity_np");
       exit_fun("Error setting processor affinity");
     }
+
     LOG_I(HW, "Setting the affinity of main function to CPU 0, for device library to use CPU 0 only!\n");
   }
+
 #endif
-  
   /* Check the actual affinity mask assigned to the thread */
   s = pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
+
   if (s != 0) {
     perror( "pthread_getaffinity_np");
     exit_fun("Error getting processor affinity ");
   }
+
   memset(cpu_affinity, 0 , sizeof(cpu_affinity));
+
   for (int j = 0; j < CPU_SETSIZE; j++) {
     if (CPU_ISSET(j, &cpuset)) {
       char temp[1024];
@@ -1042,141 +889,156 @@ printf("~~~~~~~~~~~~~~~~~~~~successfully get the parallel config[%d], worker con
       strcat(cpu_affinity, temp);
     }
   }
+
   LOG_I(HW, "CPU Affinity of main() function is... %s\n", cpu_affinity);
 #endif
-  
-
-  
-  
 #if defined(ENABLE_ITTI)
-    if (create_tasks_ue(1) < 0) {
-      printf("cannot create ITTI tasks\n");
-      exit(-1); // need a softer mode
-    }
-    if(nfapi_mode==3){ // Here we should add another nfapi_mode for the case of Supervised LTE-D2D
-    	UE_config_stub_pnf();
-    }
-    printf("ITTI tasks created\n");
-#endif
+  if (create_tasks_ue(NB_UE_INST) < 0) {
+    printf("cannot create ITTI tasks\n");
+    exit(-1); // need a softer mode
+  }
 
-  
+  if(nfapi_mode==3) { // Here we should add another nfapi_mode for the case of Supervised LTE-D2D
+    UE_config_stub_pnf();
+  }
+
+  printf("ITTI tasks created\n");
+#endif
   mlockall(MCL_CURRENT | MCL_FUTURE);
-  
- 
   rt_sleep_ns(10*100000000ULL);
-
   const char *nfapi_mode_str = "<UNKNOWN>";
+  // start the main UE threads
+  int eMBMS_active = 0;
 
-    switch(nfapi_mode)
-    {
-      case 0:
-        nfapi_mode_str = "MONOLITHIC";
-        break;
-      case 1:
-        nfapi_mode_str = "PNF";
-        break;
-      case 2:
-        nfapi_mode_str = "VNF";
-        break;
-      case 3:
-        nfapi_mode_str = "UE_STUB_PNF";
-        break;
-      case 4:
-        nfapi_mode_str = "UE_STUB_OFFNET";
-        break;
-      default:
-        nfapi_mode_str = "<UNKNOWN NFAPI MODE>";
-        break;
-    }
-    printf("NFAPI MODE:%s\n", nfapi_mode_str);
+  switch(nfapi_mode) {
+    case 0:
+      nfapi_mode_str = "MONOLITHIC";
+      break;
+
+    case 1:
+      nfapi_mode_str = "PNF";
+      break;
+
+    case 2:
+      nfapi_mode_str = "VNF";
+      break;
+
+    case 3:
+      nfapi_mode_str = "UE_STUB_PNF";
+      break;
 
+    case 4:
+      nfapi_mode_str = "UE_STUB_OFFNET";
+      break;
+
+    default:
+      nfapi_mode_str = "<UNKNOWN NFAPI MODE>";
+      break;
+  }
+
+  printf("NFAPI MODE:%s\n", nfapi_mode_str);
+
+  if (nfapi_mode==3) // UE-STUB-PNF
+  {
+      config_sync_var=0;
+      wait_nfapi_init("main?");
+      //Panos: Temporarily we will be using single set of threads for multiple UEs.
+      //init_UE_stub(1,eMBMS_active,uecap_xer_in,emul_iface);
+      init_UE_stub_single_thread(NB_UE_INST,eMBMS_active,uecap_xer_in,emul_iface);
+  }
+  else {
+      init_UE(NB_UE_INST,eMBMS_active,uecap_xer_in,0,get_softmodem_params()->phy_test,UE_scan,UE_scan_carrier,mode,(int)rx_gain[0][0],tx_max_power[0],
+              frame_parms[0]);
+  }
+
+
+  if (get_softmodem_params()->phy_test==0) {
+    printf("Filling UE band info\n");
+    fill_ue_band_info();
+    dl_phy_sync_success (0, 0, 0, 1);
+  }
 
+  if (nfapi_mode!=3){
+      number_of_cards = 1;
+      for(CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
+              PHY_vars_UE_g[0][CC_id]->rf_map.card=0;
+              PHY_vars_UE_g[0][CC_id]->rf_map.chain=CC_id+(get_softmodem_params()->chain_offset);
+      }
+  }
   // connect the TX/RX buffers
 
-      
-    /*  
-    if(nfapi_mode!=3) {
-    	if (setup_ue_buffers(PHY_vars_UE_g[0],&openair0_cfg[0])!=0) {
-    		printf("Error setting up eNB buffer\n");
-    		exit(-1);
-    	}
-    }
-   */ 
-    
-    
-
-    if (input_fd) {
-      printf("Reading in from file to antenna buffer %d\n",0);
-      if (fread(PHY_vars_UE_g[0][0]->common_vars.rxdata[0],
-		sizeof(int32_t),
-		frame_parms[0]->samples_per_tti*10,
-		input_fd) != frame_parms[0]->samples_per_tti*10)
-	printf("error reading from file\n");
+  /*
+  if(nfapi_mode!=3) {
+    if (setup_ue_buffers(PHY_vars_UE_g[0],&openair0_cfg[0])!=0) {
+      printf("Error setting up eNB buffer\n");
+      exit(-1);
     }
-    //p_exmimo_config->framing.tdd_config = TXRXSWITCH_TESTRX;
+  }
+  */
 
- 
-  if (simL1flag==1)  {
-     init_ocm((double)snr_dB,0);
-     PHY_vars_UE_g[0][0]->no_timing_correction = 1;
+  if (input_fd) {
+    printf("Reading in from file to antenna buffer %d\n",0);
+
+    if (fread(PHY_vars_UE_g[0][0]->common_vars.rxdata[0],
+              sizeof(int32_t),
+              frame_parms[0]->samples_per_tti*10,
+              input_fd) != frame_parms[0]->samples_per_tti*10)
+      printf("error reading from file\n");
   }
- 
 
+  //p_exmimo_config->framing.tdd_config = TXRXSWITCH_TESTRX;
+
+  if (simL1flag==1)  {
+    init_ocm((double)snr_dB,0);
+    PHY_vars_UE_g[0][0]->no_timing_correction = 1;
+  }
 
 #ifdef XFORMS
   int UE_id;
-  
   printf("XFORMS\n");
 
-  if (do_forms==1) {
+  if (get_softmodem_params()->do_forms==1) {
     fl_initialize (&argc, argv, NULL, 0, 0);
-    
-      form_stats = create_form_stats_form();
-      fl_show_form (form_stats->stats_form, FL_PLACE_HOTSPOT, FL_FULLBORDER, "stats");
-      UE_id = 0;
-      form_ue[UE_id] = create_lte_phy_scope_ue();
-      sprintf (title, "LTE DL SCOPE UE");
-      fl_show_form (form_ue[UE_id]->lte_phy_scope_ue, FL_PLACE_HOTSPOT, FL_FULLBORDER, title);
-      
-      /*
-	if (openair_daq_vars.use_ia_receiver) {
-	fl_set_button(form_ue[UE_id]->button_0,1);
-	fl_set_object_label(form_ue[UE_id]->button_0, "IA Receiver ON");
-	} else {
-	fl_set_button(form_ue[UE_id]->button_0,0);
-	fl_set_object_label(form_ue[UE_id]->button_0, "IA Receiver OFF");
-	}*/
-      fl_set_button(form_ue[UE_id]->button_0,0);
-      fl_set_object_label(form_ue[UE_id]->button_0, "IA Receiver OFF");
+    form_stats = create_form_stats_form();
+    fl_show_form (form_stats->stats_form, FL_PLACE_HOTSPOT, FL_FULLBORDER, "stats");
+    UE_id = 0;
+    form_ue[UE_id] = create_lte_phy_scope_ue();
+    sprintf (title, "LTE DL SCOPE UE");
+    fl_show_form (form_ue[UE_id]->lte_phy_scope_ue, FL_PLACE_HOTSPOT, FL_FULLBORDER, title);
+    /*
+    if (openair_daq_vars.use_ia_receiver) {
+    fl_set_button(form_ue[UE_id]->button_0,1);
+    fl_set_object_label(form_ue[UE_id]->button_0, "IA Receiver ON");
+    } else {
+    fl_set_button(form_ue[UE_id]->button_0,0);
+    fl_set_object_label(form_ue[UE_id]->button_0, "IA Receiver OFF");
+    }*/
+    fl_set_button(form_ue[UE_id]->button_0,0);
+    fl_set_object_label(form_ue[UE_id]->button_0, "IA Receiver OFF");
     ret = pthread_create(&forms_thread, NULL, scope_thread, NULL);
-    
+
     if (ret == 0)
       pthread_setname_np( forms_thread, "xforms" );
-    
+
     printf("Scope thread created, ret=%d\n",ret);
   }
-  
+
 #endif
-  
+  config_check_unknown_cmdlineopt(CONFIG_CHECKALLSECTIONS);
   printf("Sending sync to all threads (%p,%p,%p)\n",&sync_var,&sync_cond,&sync_mutex);
-
-  
   pthread_mutex_lock(&sync_mutex);
   sync_var=0;
   pthread_cond_broadcast(&sync_cond);
   pthread_mutex_unlock(&sync_mutex);
-
   printf("sync sent\n");
-/*
-  printf("About to call end_configmodule() from %s() %s:%d\n", __FUNCTION__, __FILE__, __LINE__);
-  end_configmodule();
-  printf("Called end_configmodule() from %s() %s:%d\n", __FUNCTION__, __FILE__, __LINE__);
-*/
+  /*
+    printf("About to call end_configmodule() from %s() %s:%d\n", __FUNCTION__, __FILE__, __LINE__);
+    end_configmodule();
+    printf("Called end_configmodule() from %s() %s:%d\n", __FUNCTION__, __FILE__, __LINE__);
+  */
   // wait for end of program
   printf("TYPE <CTRL-C> TO TERMINATE\n");
   //getchar();
-
-
 #if defined(ENABLE_ITTI)
   printf("Entering ITTI signals handler\n");
   itti_wait_tasks_end();
@@ -1185,17 +1047,16 @@ printf("~~~~~~~~~~~~~~~~~~~~successfully get the parallel config[%d], worker con
   printf("oai_exit=%d\n",oai_exit);
 #else
 
-    while (oai_exit==0)
-      rt_sleep_ns(100000000ULL);
-    printf("Terminating application - oai_exit=%d\n",oai_exit);
+  while (oai_exit==0)
+    rt_sleep_ns(100000000ULL);
 
+  printf("Terminating application - oai_exit=%d\n",oai_exit);
 #endif
-
   // stop threads
 #ifdef XFORMS
   printf("waiting for XFORMS thread\n");
 
-  if (do_forms==1) {
+  if (get_softmodem_params()->do_forms==1) {
     pthread_join(forms_thread,&status);
     fl_hide_form(form_stats->stats_form);
     fl_free_form(form_stats->stats_form);
@@ -1204,9 +1065,7 @@ printf("~~~~~~~~~~~~~~~~~~~~successfully get the parallel config[%d], worker con
   }
 
 #endif
-
   printf("stopping MODEM threads\n");
-
   pthread_cond_destroy(&sync_cond);
   pthread_mutex_destroy(&sync_mutex);
 
@@ -1215,13 +1074,9 @@ printf("~~~~~~~~~~~~~~~~~~~~successfully get the parallel config[%d], worker con
   // *** Handle per CC_id openair0
   if (PHY_vars_UE_g[0][0]->rfdevice.trx_end_func)
     PHY_vars_UE_g[0][0]->rfdevice.trx_end_func(&PHY_vars_UE_g[0][0]->rfdevice);
-  
-  if (opt_enabled == 1)
-    terminate_opt();
-  
-  logClean();
 
+  terminate_opt();
+  logClean();
   printf("Bye.\n");
-  
   return 0;
 }
diff --git a/targets/RT/USER/rfsim.c b/targets/RT/USER/rfsim.c
index cdf8f1ad0d52be2a83ec4745fc0a87ee1c2fdb95..37ce9f92ea153ffff7ab55f3112527332ce9d43a 100644
--- a/targets/RT/USER/rfsim.c
+++ b/targets/RT/USER/rfsim.c
@@ -62,7 +62,6 @@ sim_t sim;
 
 
 void init_ru_devices(void);
-void init_RU(const char*);
 void *rfsim_top(void *n_frames);
 
 void wait_RUs(void)
diff --git a/targets/RT/USER/rfsim.h b/targets/RT/USER/rfsim.h
index 1ac4d29d3963231b461de6ac4472eb4881c98204..f263b1067c82014b70585843324f8bea1c8a56a7 100644
--- a/targets/RT/USER/rfsim.h
+++ b/targets/RT/USER/rfsim.h
@@ -31,16 +31,10 @@ void init_ocm(double snr_dB,double sinr_dB);
 
 void update_ocm(double snr_dB,double sinr_dB);
 
-extern pthread_mutex_t async_server_lock;
-extern pthread_cond_t async_server_notify;
-extern int async_server_shutdown;
+//extern pthread_mutex_t async_server_lock;
+//extern pthread_cond_t async_server_notify;
+//extern int async_server_shutdown;
 
-#if !defined(LOG_NO_THREAD)
-extern LOG_params log_list[2000];
-extern pthread_mutex_t log_lock;
-extern pthread_cond_t log_notify;
-extern int log_shutdown;
-#endif
 void init_channel_vars(void);
 
 #endif 
diff --git a/targets/RT/USER/rt_wrapper.c b/targets/RT/USER/rt_wrapper.c
index 443d183068e634ab97e751d7ed5f448edd820732..b55bafed1b00727416d7b94a30cbebd91ef084ef 100644
--- a/targets/RT/USER/rt_wrapper.c
+++ b/targets/RT/USER/rt_wrapper.c
@@ -125,7 +125,7 @@ void check_clock(void)
   if (clock_getres(clock_id, &res)) {
     printf("clock_getres failed");
   } else {
-    printf("reported resolution = %llu ns\n", (long long int) ((int) 1e9 * res.tv_sec) + (long long int) res.tv_nsec);
+    printf("reported resolution = %lld ns\n", (long long int) ((int) 1e9 * res.tv_sec) + (long long int) res.tv_nsec);
   }
 }
 
diff --git a/targets/TEST/AT_COMMANDS/Makefile b/targets/TEST/AT_COMMANDS/Makefile
old mode 100755
new mode 100644
diff --git a/targets/TEST/PACKET_TRACER/Makefile b/targets/TEST/PACKET_TRACER/Makefile
old mode 100755
new mode 100644
diff --git a/targets/TEST/PACKET_TRACER/pt.c b/targets/TEST/PACKET_TRACER/pt.c
index 030b63ab907319283059e4b8bdd74a2ceb4814cc..510865d33e5ab3a802544522ecdd36fbe444e564 100644
--- a/targets/TEST/PACKET_TRACER/pt.c
+++ b/targets/TEST/PACKET_TRACER/pt.c
@@ -166,7 +166,8 @@ int input_text(char *file,char *sdu)
     printf("byte %d: %x (%s%s)\n",b_ind,byte,binary_table[byte>>4],binary_table[byte&0xf]);
     b_ind++;
   }
-
+  if (fd)
+    fclose(fd);
   return(b_ind);
 }
 
@@ -220,14 +221,14 @@ int parse_args(int argc, char** argv, args_t* args)
     case 'I':
       strcpy(args->input1_file,optarg);
       args->input1_sdu_len = input_text(args->input1_file,args->input1_sdu);
-      printf("Got sdu1 of length %d bytes\n",args->input1_sdu_len);
+      printf("Got sdu1 of length %u bytes\n",args->input1_sdu_len);
       args->input1_sdu_flag=1;
       break;
 
     case 'J':
       strcpy(args->input2_file,optarg);
       args->input2_sdu_len = input_text(args->input2_file,args->input2_sdu);
-      printf("Got sdu2 of length %d bytes\n",args->input2_sdu_len);
+      printf("Got sdu2 of length %u bytes\n",args->input2_sdu_len);
       args->input2_sdu_flag=1;
       break;
 
@@ -530,7 +531,8 @@ int main (int argc, char **argv)
   if (args.input_sib == 0) {
     openair_rrc_lite_eNB_init(0);
   } else {
-    printf("Got SI from files (%d,%d,%d,%d,%d)\n",args.input_sib,args.input1_sdu_flag,args.input2_sdu_flag);
+    printf("Got SI from files (%d,%d,%d)\n",
+            args.input_sib,args.input1_sdu_flag,args.input2_sdu_flag);
   }
 
   openair_rrc_on(0,0);
diff --git a/targets/TEST/PDCP/Makefile b/targets/TEST/PDCP/Makefile
old mode 100755
new mode 100644
diff --git a/targets/TEST/PDCP/test_pdcp.c b/targets/TEST/PDCP/test_pdcp.c
index a999bb254dfcbd80184740ebb694ad907b0fcd85..b62edf1215410921f3c9e27fbe7d4c55b9400fd3 100644
--- a/targets/TEST/PDCP/test_pdcp.c
+++ b/targets/TEST/PDCP/test_pdcp.c
@@ -249,7 +249,7 @@ BOOL test_pdcp_data_req(void)
        * information if we pass mem_block_ts via a linked list?
        */
 
-      if (pdcp_test_pdu_buffer_size == 0 || pdcp_test_pdu_buffer == NULL) {
+      if (pdcp_test_pdu_buffer_size == 0 ) {
         msg("[TEST] PDU created by pdcp_data_req() is invalid!\n");
         return FALSE;
       }
diff --git a/targets/TEST/PDCP/with_rlc/Makefile.data_bearer b/targets/TEST/PDCP/with_rlc/Makefile.data_bearer
old mode 100755
new mode 100644
diff --git a/targets/TEST/PDCP/with_rlc/readme_test_pdcp_rlc.txt b/targets/TEST/PDCP/with_rlc/readme_test_pdcp_rlc.txt
old mode 100755
new mode 100644
diff --git a/targets/TEST/PDCP/with_rlc/test_pdcp_rlc.c b/targets/TEST/PDCP/with_rlc/test_pdcp_rlc.c
index d3efbe139f1293b330383249a81c8890fcecdd86..9f28fd7c78a6c3182fec9f763676e2e68ecd6dac 100644
--- a/targets/TEST/PDCP/with_rlc/test_pdcp_rlc.c
+++ b/targets/TEST/PDCP/with_rlc/test_pdcp_rlc.c
@@ -125,7 +125,7 @@ void pdcp_rlc_test_mac_rlc_loop (struct mac_data_ind *data_indP,  struct mac_dat
 
     if (tb_src != NULL) {
       tb_size = ((struct mac_tb_req *) (tb_src->data))->tb_size_in_bits >> 3;
-      printf("[RLC-LOOP] FOUND TB SIZE IN BITS %d IN BYTES %d sizeof (mac_rlc_max_rx_header_size_t) %d\n",
+      printf("[RLC-LOOP] FOUND TB SIZE IN BITS %d IN BYTES %u sizeof (mac_rlc_max_rx_header_size_t) %d\n",
              ((struct mac_tb_req *) (tb_src->data))->tb_size_in_bits,
              tb_size, sizeof (mac_rlc_max_rx_header_size_t));
 
diff --git a/targets/TEST/RLC_AM_V9.3.0/Makefile b/targets/TEST/RLC_AM_V9.3.0/Makefile
old mode 100755
new mode 100644
diff --git a/targets/TEST/RLC_UM_V9.3.0/Makefile b/targets/TEST/RLC_UM_V9.3.0/Makefile
old mode 100755
new mode 100644